<commit_before>// TypeScript Version: 3.5

import { ReactNode, ComponentType, MouseEvent } from 'react'

/**
 * The empty definitions of below provides a base definition for the parts used by useTable, that can then be extended in the users code.
 *
 * @example
 *  export interface TableOptions<D extends object = {}}>
 *    extends
 *      UseExpandedOptions<D>,
 *      UseFiltersOptions<D> {}
 */
export interface TableOptions<D extends object> extends UseTableOptions<D> {}

export interface TableInstance<D extends object = {}>
  extends Omit<TableOptions<D>, 'columns' | 'state'>,
    UseTableInstanceProps<D> {}

export interface TableState<
  D extends object = {}
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface

export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}

export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}

export interface Column<D extends object = {}>
  extends UseTableColumnOptions<D> {}

export interface ColumnInstance<D extends object = {}>
  extends Omit<Column<D>, 'id'>,
    UseTableColumnProps<D> {}

export interface HeaderGroup<D extends object = {}>
  extends ColumnInstance<D>,
    UseTableHeaderGroupProps<D> {}

export interface Row<D extends object = {}> extends UseTableRowProps<D> {}

/* #region useTable */
export function useTable<D extends object = {}>(
  options: TableOptions<D>,
  ...plugins: Array<PluginHook<D>>
): TableInstance<D>

/**
 * NOTE: To use custom options, use "Interface Merging" to add the custom options
 */
export type UseTableOptions<D extends object> = {
  columns: Array<Column<D>>
  data: D[]
} & Partial<{
  initialState: Partial<TableState<D>>
  state: Partial<TableState<D>>
  reducer: (
    oldState: TableState<D>,
    newState: TableState<D>,
    type: string
  ) => TableState<D>
  defaultColumn: Partial<Column<D>>
  initialRowStateKey: IdType<D>
  getSubRows: (row: Row<D>, relativeIndex: number) => Array<Row<D>>
  getRowID: (row: Row<D>, relativeIndex: number) => string
  debug: boolean
}>

export interface UseTableHooks<D extends object> {
  columnsBeforeHeaderGroups: Array<
    (
      flatColumns: Array<Column<D>>,
      instance: TableInstance<D>
    ) => Array<Column<D>>
  >
  columnsBeforeHeaderGroupsDeps: Array<
    (deps: any[], instance: TableInstance<D>) => any[]
  >
  useMain: Array<(instance: TableInstance<D>) => TableInstance<D>>
  useRows: Array<
    (rows: Array<Row<D>>, instance: TableInstance<D>) => Array<Row<D>>
  >
  prepareRow: Array<(row: Row<D>, instance: TableInstance<D>) => Row<D>>

  // Prop Hooks
  getTableProps: Array<(instance: TableInstance<D>) => object>
  getTableBodyProps: Array<(instance: TableInstance<D>) => object>
  getRowProps: Array<(row: Row<D>, instance: TableInstance<D>) => object>
  getHeaderGroupProps: Array<
    (headerGroup: HeaderGroup<D>, instance: TableInstance<D>) => object
  >
  getHeaderProps: Array<
    (column: Column<D>, instance: TableInstance<D>) => object
  >
  getCellProps: Array<(cell: Cell<D>, instance: TableInstance<D>) => object>
}

export interface UseTableColumnOptions<D extends object>
  extends Accessor<D>,
    Partial<{
      columns: Array<Column<D>>
      show: boolean | ((instance: TableInstance<D>) => boolean)
      Header: Renderer<HeaderProps<D>>
      Cell: Renderer<CellProps<D>>
      width?: number
      minWidth?: number
      maxWidth?: number
    }> {}

export interface UseTableInstanceProps<D extends object> {
  columns: Array<ColumnInstance<D>>
  flatColumns: Array<ColumnInstance<D>>
  headerGroups: Array<HeaderGroup<D>>
  headers: Array<ColumnInstance<D>>
  flatHeaders: Array<ColumnInstance<D>>
  rows: Array<Row<D>>
  getTableProps: (props?: object) => object
  getTableBodyProps: (props?: object) => object
  prepareRow: (row: Row<D>) => void
  rowPaths: string[]
  flatRows: Array<Row<D>>
  state: TableState<D>
  setState: SetState<D>
  totalColumnsWidth: number
}

export interface UseTableHeaderGroupProps<D extends object> {
  headers: Array<ColumnInstance<D>>
  getHeaderGroupProps: (props?: object) => object
  totalHeaderCount: number
}

export interface UseTableColumnProps<D extends object> {
  id: IdType<D>
  isVisible: boolean
  render: (type: 'Header' | string, props?: object) => ReactNode
  getHeaderProps: (props?: object) => object
  parent: ColumnInstance<D>
  depth: number
  index: number
}

export interface UseTableRowProps<D extends object> {
  cells: Array<Cell<D>>
  values: Record<IdType<D>, CellValue>
  getRowProps: (props?: object) => object
  index: number
  original: D
  path: Array<IdType<D>>
  subRows: Array<Row<D>>
}

export interface UseTableCellProps<D extends object> {
  column: ColumnInstance<D>
  row: Row<D>
  value: CellValue
  getCellProps: (props?: object) => object
  render: (type: 'Cell' | string, userProps?: object) => ReactNode
}

export type HeaderProps<D extends object> = TableInstance<D> & {
  column: ColumnInstance<D>
} & Record<string, any>
export type CellProps<D extends object> = TableInstance<D> & {
  column: ColumnInstance<D>
  row: Row<D>
  cell: Cell<D>
} & Record<string, any>

// NOTE: At least one of (id | accessor | Header as string) required
export interface Accessor<D extends object> {
  accessor?:
    | IdType<D>
    | ((
        originalRow: D,
        index: number,
        sub: {
          subRows: D[]
          depth: number
          data: D[]
        }
      ) => CellValue)
  id?: IdType<D>
}
/* #endregion */

// Plugins

/* #region useColumnOrder */
export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void
export namespace useColumnOrder {
  const pluginName = 'useColumnOrder'
}
<commit_msg>remove Record from HeaderProps and CellProps (#1601)<commit_after>// TypeScript Version: 3.5

import { ReactNode, ComponentType, MouseEvent } from 'react'

/**
 * The empty definitions of below provides a base definition for the parts used by useTable, that can then be extended in the users code.
 *
 * @example
 *  export interface TableOptions<D extends object = {}}>
 *    extends
 *      UseExpandedOptions<D>,
 *      UseFiltersOptions<D> {}
 */
export interface TableOptions<D extends object> extends UseTableOptions<D> {}

export interface TableInstance<D extends object = {}>
  extends Omit<TableOptions<D>, 'columns' | 'state'>,
    UseTableInstanceProps<D> {}

export interface TableState<
  D extends object = {}
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface

export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}

export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}

export interface Column<D extends object = {}>
  extends UseTableColumnOptions<D> {}

export interface ColumnInstance<D extends object = {}>
  extends Omit<Column<D>, 'id'>,
    UseTableColumnProps<D> {}

export interface HeaderGroup<D extends object = {}>
  extends ColumnInstance<D>,
    UseTableHeaderGroupProps<D> {}

export interface Row<D extends object = {}> extends UseTableRowProps<D> {}

/* #region useTable */
export function useTable<D extends object = {}>(
  options: TableOptions<D>,
  ...plugins: Array<PluginHook<D>>
): TableInstance<D>

/**
 * NOTE: To use custom options, use "Interface Merging" to add the custom options
 */
export type UseTableOptions<D extends object> = {
  columns: Array<Column<D>>
  data: D[]
} & Partial<{
  initialState: Partial<TableState<D>>
  state: Partial<TableState<D>>
  reducer: (
    oldState: TableState<D>,
    newState: TableState<D>,
    type: string
  ) => TableState<D>
  defaultColumn: Partial<Column<D>>
  initialRowStateKey: IdType<D>
  getSubRows: (row: Row<D>, relativeIndex: number) => Array<Row<D>>
  getRowID: (row: Row<D>, relativeIndex: number) => string
  debug: boolean
}>

export interface UseTableHooks<D extends object> {
  columnsBeforeHeaderGroups: Array<
    (
      flatColumns: Array<Column<D>>,
      instance: TableInstance<D>
    ) => Array<Column<D>>
  >
  columnsBeforeHeaderGroupsDeps: Array<
    (deps: any[], instance: TableInstance<D>) => any[]
  >
  useMain: Array<(instance: TableInstance<D>) => TableInstance<D>>
  useRows: Array<
    (rows: Array<Row<D>>, instance: TableInstance<D>) => Array<Row<D>>
  >
  prepareRow: Array<(row: Row<D>, instance: TableInstance<D>) => Row<D>>

  // Prop Hooks
  getTableProps: Array<(instance: TableInstance<D>) => object>
  getTableBodyProps: Array<(instance: TableInstance<D>) => object>
  getRowProps: Array<(row: Row<D>, instance: TableInstance<D>) => object>
  getHeaderGroupProps: Array<
    (headerGroup: HeaderGroup<D>, instance: TableInstance<D>) => object
  >
  getHeaderProps: Array<
    (column: Column<D>, instance: TableInstance<D>) => object
  >
  getCellProps: Array<(cell: Cell<D>, instance: TableInstance<D>) => object>
}

export interface UseTableColumnOptions<D extends object>
  extends Accessor<D>,
    Partial<{
      columns: Array<Column<D>>
      show: boolean | ((instance: TableInstance<D>) => boolean)
      Header: Renderer<HeaderProps<D>>
      Cell: Renderer<CellProps<D>>
      width?: number
      minWidth?: number
      maxWidth?: number
    }> {}

export interface UseTableInstanceProps<D extends object> {
  columns: Array<ColumnInstance<D>>
  flatColumns: Array<ColumnInstance<D>>
  headerGroups: Array<HeaderGroup<D>>
  headers: Array<ColumnInstance<D>>
  flatHeaders: Array<ColumnInstance<D>>
  rows: Array<Row<D>>
  getTableProps: (props?: object) => object
  getTableBodyProps: (props?: object) => object
  prepareRow: (row: Row<D>) => void
  rowPaths: string[]
  flatRows: Array<Row<D>>
  state: TableState<D>
  setState: SetState<D>
  totalColumnsWidth: number
}

export interface UseTableHeaderGroupProps<D extends object> {
  headers: Array<ColumnInstance<D>>
  getHeaderGroupProps: (props?: object) => object
  totalHeaderCount: number
}

export interface UseTableColumnProps<D extends object> {
  id: IdType<D>
  isVisible: boolean
  render: (type: 'Header' | string, props?: object) => ReactNode
  getHeaderProps: (props?: object) => object
  parent: ColumnInstance<D>
  depth: number
  index: number
}

export interface UseTableRowProps<D extends object> {
  cells: Array<Cell<D>>
  values: Record<IdType<D>, CellValue>
  getRowProps: (props?: object) => object
  index: number
  original: D
  path: Array<IdType<D>>
  subRows: Array<Row<D>>
}

export interface UseTableCellProps<D extends object> {
  column: ColumnInstance<D>
  row: Row<D>
  value: CellValue
  getCellProps: (props?: object) => object
  render: (type: 'Cell' | string, userProps?: object) => ReactNode
}

export type HeaderProps<D extends object> = TableInstance<D> & {
  column: ColumnInstance<D>
}

export type CellProps<D extends object> = TableInstance<D> & {
  column: ColumnInstance<D>
  row: Row<D>
  cell: Cell<D>
}

// NOTE: At least one of (id | accessor | Header as string) required
export interface Accessor<D extends object> {
  accessor?:
    | IdType<D>
    | ((
        originalRow: D,
        index: number,
        sub: {
          subRows: D[]
          depth: number
          data: D[]
        }
      ) => CellValue)
  id?: IdType<D>
}
/* #endregion */

// Plugins

/* #region useColumnOrder */
export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void
export namespace useColumnOrder {
  const pluginName = 'useColumnOrder'
}

{'fraction_non_alphanumeric': 0.13415702769015073, 'fraction_numerical': 0.0007010164738871364, 'mean_word_length': 4.481748318924112, 'pattern_counts': {'":': 0, '<': 295, '<?xml version=': 0, '>': 345, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6106081', 'n_tokens_mistral': 3548, 'n_tokens_neox': 3559, 'n_words': 948}