diff --git a/examples/react/basic-table-helper/src/main.tsx b/examples/react/basic-table-helper/src/main.tsx index 129be15b26..3f273c2cdc 100644 --- a/examples/react/basic-table-helper/src/main.tsx +++ b/examples/react/basic-table-helper/src/main.tsx @@ -1,6 +1,7 @@ import * as React from 'react' import ReactDOM from 'react-dom/client' import { createTableHelper, flexRender } from '@tanstack/react-table' +import type { ColumnDef } from '@tanstack/react-table' import './index.css' // This example uses the new `createTableHelper` method to create a re-usable table helper object instead of independently using the standalone `useTable` hook and `createColumnHelper` method. You can choose to use either way. @@ -94,7 +95,7 @@ const columns = [ header: 'Profile Progress', footer: (info) => info.column.id, }), -] +] as Array> function App() { // 6. Store data with a stable reference diff --git a/examples/react/basic/src/main.tsx b/examples/react/basic/src/main.tsx index e5d09a9c01..3d1ccbd1fa 100644 --- a/examples/react/basic/src/main.tsx +++ b/examples/react/basic/src/main.tsx @@ -110,8 +110,6 @@ function App() { // add additional table options here }) - console.log('table', table) - // 7. Render your table markup from the table instance APIs return (
diff --git a/packages/react-table/src/tableHelper.ts b/packages/react-table/src/tableHelper.ts index 10026e41cd..9c2f03f5aa 100644 --- a/packages/react-table/src/tableHelper.ts +++ b/packages/react-table/src/tableHelper.ts @@ -1,6 +1,7 @@ import { constructTableHelper } from '@tanstack/table-core' import { useTable } from './useTable' import type { + ColumnDef, RowData, Table, TableFeatures, @@ -36,27 +37,27 @@ export function createTableHelper< // test -// type Person = { -// firstName: string -// lastName: string -// age: number -// } - -// const tableHelper = createTableHelper({ -// _features: { RowSelection: {} }, -// TData: {} as Person, -// }) - -// const columns = [ -// tableHelper.columnHelper.accessor('firstName', { header: 'First Name' }), -// tableHelper.columnHelper.accessor('lastName', { header: 'Last Name' }), -// tableHelper.columnHelper.accessor('age', { header: 'Age' }), -// tableHelper.columnHelper.display({ header: 'Actions', id: 'actions' }), -// ] - -// const data: Array = [] - -// tableHelper.useTable({ -// columns, -// data, -// }) +type Person = { + firstName: string + lastName: string + age: number +} + +const tableHelper = createTableHelper({ + _features: { RowSelection: {} }, + TData: {} as Person, +}) + +const columns = [ + tableHelper.columnHelper.accessor('firstName', { header: 'First Name' }), + tableHelper.columnHelper.accessor('lastName', { header: 'Last Name' }), + tableHelper.columnHelper.accessor('age', { header: 'Age' }), + tableHelper.columnHelper.display({ header: 'Actions', id: 'actions' }), +] as Array> + +const data: Array = [] + +tableHelper.useTable({ + columns, + data, +}) diff --git a/packages/table-core/src/core/table/Tables.utils.ts b/packages/table-core/src/core/table/Tables.utils.ts index 608dba1433..b3499b0b44 100644 --- a/packages/table-core/src/core/table/Tables.utils.ts +++ b/packages/table-core/src/core/table/Tables.utils.ts @@ -4,21 +4,24 @@ import { createCoreRowModel } from './createCoreRowModel' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { TableOptions } from '../../types/TableOptions' import type { TableState } from '../../types/TableState' export function table_reset< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): void { +>(table: Table_Internal): void { table_setState(table, table.initialState) } export function table_mergeOptions< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table, newOptions: TableOptions) { +>( + table: Table_Internal, + newOptions: TableOptions, +) { if (table.options.mergeOptions) { return table.options.mergeOptions(table.options, newOptions) } @@ -33,7 +36,7 @@ export function table_setOptions< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table, + table: Table_Internal, updater: Updater>, ): void { const newOptions = functionalUpdate(updater, table.options) @@ -43,14 +46,14 @@ export function table_setOptions< export function table_getInitialState< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): TableState { +>(table: Table_Internal): TableState { return structuredClone(table.initialState) } export function table_getState< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): TableState { +>(table: Table_Internal): TableState { return table.options.state as TableState } @@ -58,7 +61,7 @@ export function table_setState< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table, + table: Table_Internal, updater: Updater>, ): void { table.options.onStateChange?.(updater) @@ -67,7 +70,7 @@ export function table_setState< export function table_getCoreRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Core) { table._rowModels.Core = table.options._rowModels?.Core?.(table) ?? @@ -80,6 +83,6 @@ export function table_getCoreRowModel< export function table_getRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): RowModel { +>(table: Table_Internal): RowModel { return table_getPaginatedRowModel(table) } diff --git a/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts b/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts index 37330ba98f..8107511983 100644 --- a/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts +++ b/packages/table-core/src/features/column-faceting/ColumnFaceting.utils.ts @@ -2,7 +2,7 @@ import { table_getPreFilteredRowModel } from '../column-filtering/ColumnFilterin import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' export function column_getFacetedMinMaxValues< @@ -11,7 +11,7 @@ export function column_getFacetedMinMaxValues< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, ): () => [number, number] | undefined { return ( table.options._rowModels?.FacetedMinMax?.(table, column.id) ?? @@ -25,7 +25,7 @@ export function column_getFacetedRowModel< TValue extends CellData = CellData, >( column: Column | undefined, - table: Table, + table: Table_Internal, ): () => RowModel { return ( table.options._rowModels?.Faceted?.(table, column?.id ?? '') ?? @@ -39,7 +39,7 @@ export function column_getFacetedUniqueValues< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, ): () => Map { return ( table.options._rowModels?.FacetedUnique?.(table, column.id) ?? diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts index b3728ddad4..352e73fda4 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.utils.ts @@ -9,20 +9,22 @@ import type { BuiltInFilterFn } from '../../fns/filterFns' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { ColumnDef_ColumnFiltering, ColumnFiltersState, FilterFn, - TableOptions_ColumnFiltering, } from './ColumnFiltering.types' export function column_getAutoFilterFn< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column, table: Table) { +>( + column: Column, + table: Table_Internal, +) { const firstRow = table_getCoreRowModel(table).flatRows[0] const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined @@ -58,9 +60,7 @@ export function column_getFilterFn< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, ): FilterFn | undefined { return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn @@ -78,9 +78,7 @@ export function column_getCanFilter< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, ) { return ( (column.columnDef.enableColumnFilter ?? true) && @@ -98,9 +96,7 @@ export function column_getIsFiltered< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, ) { return column_getFilterIndex(column, table) > -1 } @@ -113,9 +109,7 @@ export function column_getFilterValue< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, ) { return table_getState(table).columnFilters?.find((d) => d.id === column.id) ?.value @@ -129,9 +123,7 @@ export function column_getFilterIndex< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, ): number { return ( table_getState(table).columnFilters?.findIndex((d) => d.id === column.id) ?? @@ -147,9 +139,7 @@ export function column_setFilterValue< column: Column & { columnDef: ColumnDef_ColumnFiltering }, - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, value: any, ) { table_setColumnFilters(table, (old) => { @@ -188,9 +178,7 @@ export function table_setColumnFilters< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: TableOptions_ColumnFiltering - }, + table: Table_Internal, updater: Updater, ) { const leafColumns = table.getAllLeafColumns() @@ -217,12 +205,7 @@ export function table_setColumnFilters< export function table_resetColumnFilters< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: TableOptions_ColumnFiltering - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnFilters( table, defaultState ? [] : table.initialState.columnFilters ?? [], @@ -232,22 +215,14 @@ export function table_resetColumnFilters< export function table_getPreFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: TableOptions_ColumnFiltering - }, -) { +>(table: Table_Internal) { return table_getCoreRowModel(table) } export function table_getFilteredRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: TableOptions_ColumnFiltering - }, -): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Filtered) { table._rowModels.Filtered = table.options._rowModels?.Filtered?.(table) } diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts index f30398fa0d..188e3d4781 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.utils.ts @@ -10,7 +10,7 @@ import type { BuiltInAggregationFn } from '../../fns/aggregationFns' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' import type { Cell } from '../../types/Cell' import type { Column } from '../../types/Column' @@ -18,14 +18,16 @@ import type { ColumnDef_ColumnGrouping, GroupingState, Row_ColumnGrouping, - TableOptions_ColumnGrouping, } from './ColumnGrouping.types' export function column_toggleGrouping< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column, table: Table) { +>( + column: Column, + table: Table_Internal, +) { table_setGrouping(table, (old) => { // Find any existing grouping for this column if (old.includes(column.id)) { @@ -44,9 +46,7 @@ export function column_getCanGroup< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { return ( (column.columnDef.enableGrouping ?? true) && @@ -63,9 +63,7 @@ export function column_getIsGrouped< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): boolean { return !!table_getState(table).grouping?.includes(column.id) } @@ -78,9 +76,7 @@ export function column_getGroupedIndex< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): number { return table_getState(table).grouping?.indexOf(column.id) ?? -1 } @@ -93,9 +89,7 @@ export function column_getToggleGroupingHandler< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { const canGroup = column_getCanGroup(column, table) @@ -113,9 +107,7 @@ export function column_getAutoAggregationFn< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { const firstRow = table.getCoreRowModel().flatRows[0] @@ -138,9 +130,7 @@ export function column_getAggregationFn< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn @@ -155,24 +145,14 @@ export function column_getAggregationFn< export function table_setGrouping< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table.options.onGroupingChange?.(updater) } export function table_resetGrouping< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setGrouping( table, defaultState ? [] : table_getInitialState(table).grouping ?? [], @@ -182,22 +162,14 @@ export function table_resetGrouping< export function table_getPreGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { return table_getFilteredRowModel(table) } export function table_getGroupedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Grouped) { table._rowModels.Grouped = table.options._rowModels?.Grouped?.(table) } @@ -221,9 +193,7 @@ export function row_getGroupingValue< TData extends RowData, >( row: Row & Partial, - table: Table & { - options: TableOptions_ColumnGrouping - }, + table: Table_Internal, columnId: string, ) { if (row._groupingValuesCache?.hasOwnProperty(columnId)) { @@ -255,9 +225,7 @@ export function cell_getIsGrouped< TValue extends CellData = CellData, >( cell: Cell, - table: Table & { - options: TableOptions_ColumnGrouping - }, + table: Table_Internal, ) { const row = cell.row as Row & Row_ColumnGrouping return ( @@ -272,9 +240,7 @@ export function cell_getIsPlaceholder< TValue extends CellData = CellData, >( cell: Cell, - table: Table & { - options: TableOptions_ColumnGrouping - }, + table: Table_Internal, ) { return ( !cell_getIsGrouped(cell, table) && column_getIsGrouped(cell.column, table) @@ -287,9 +253,7 @@ export function cell_getIsAggregated< TValue extends CellData = CellData, >( cell: Cell, - table: Table & { - options: TableOptions_ColumnGrouping - }, + table: Table_Internal, ) { return ( !cell_getIsGrouped(cell, table) && diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts index 433b2e370d..2f8ecf08ca 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.utils.ts @@ -3,16 +3,12 @@ import { table_getInitialState, table_getState, } from '../../core/table/Tables.utils' -import type { TableOptions_ColumnGrouping } from '../column-grouping/ColumnGrouping.types' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { ColumnPinningPosition } from '../column-pinning/ColumnPinning.types' -import type { - ColumnOrderState, - TableOptions_ColumnOrdering, -} from './ColumnOrdering.types' +import type { ColumnOrderState } from './ColumnOrdering.types' export function column_getIndex< TFeatures extends TableFeatures, @@ -20,7 +16,7 @@ export function column_getIndex< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, position?: ColumnPinningPosition | 'center', ) { const columns = column_getVisibleLeafColumns(table, position) @@ -33,7 +29,7 @@ export function column_getIsFirstColumn< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, position?: ColumnPinningPosition | 'center', ) { const columns = column_getVisibleLeafColumns(table, position) @@ -46,7 +42,7 @@ export function column_getIsLastColumn< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, position?: ColumnPinningPosition | 'center', ) { const columns = column_getVisibleLeafColumns(table, position) @@ -56,19 +52,14 @@ export function column_getIsLastColumn< export function table_setColumnOrder< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table.options.onColumnOrderChange?.(updater) } export function table_resetColumnOrder< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table, defaultState?: boolean) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnOrder( table, defaultState ? [] : table_getInitialState(table).columnOrder ?? [], @@ -78,7 +69,7 @@ export function table_resetColumnOrder< export function table_getOrderColumnsFn< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const { columnOrder = [] } = table_getState(table) return (columns: Array>) => { @@ -118,12 +109,7 @@ export function orderColumns< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial< - TableOptions_ColumnOrdering & - TableOptions_ColumnGrouping - > - }, + table: Table_Internal, leafColumns: Array>, ) { const { grouping = [] } = table_getState(table) diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts index 2e440f799d..fdbee379ca 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.utils.ts @@ -12,14 +12,13 @@ import { buildHeaderGroups } from '../../core/headers/buildHeaderGroups' import type { Row } from '../../types/Row' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Cell } from '../../types/Cell' import type { Column } from '../../types/Column' import type { ColumnDef_ColumnPinning, ColumnPinningPosition, ColumnPinningState, - TableOptions_ColumnPinning, } from './ColumnPinning.types' // State @@ -37,7 +36,7 @@ export function column_pin< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, position: ColumnPinningPosition, ) { const columnIds = column @@ -78,7 +77,7 @@ export function column_getCanPin< column: Column & { columnDef: ColumnDef_ColumnPinning }, - table: Table & { options: TableOptions_ColumnPinning }, + table: Table_Internal, ) { const leafColumns = column.getLeafColumns() as Array< Column & { columnDef: ColumnDef_ColumnPinning } @@ -97,7 +96,7 @@ export function column_getIsPinned< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, ): ColumnPinningPosition | false { const leafColumnIds = column.getLeafColumns().map((d) => d.id) @@ -114,7 +113,10 @@ export function column_getPinnedIndex< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column, table: Table) { +>( + column: Column, + table: Table_Internal, +) { const position = column_getIsPinned(column, table) return position @@ -125,7 +127,7 @@ export function column_getPinnedIndex< export function row_getCenterVisibleCells< TFeatures extends TableFeatures, TData extends RowData, ->(row: Row, table: Table) { +>(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { left, right } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() @@ -136,7 +138,7 @@ export function row_getCenterVisibleCells< export function row_getLeftVisibleCells< TFeatures extends TableFeatures, TData extends RowData, ->(row: Row, table: Table) { +>(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { left } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() @@ -151,7 +153,7 @@ export function row_getLeftVisibleCells< export function row_getRightVisibleCells< TFeatures extends TableFeatures, TData extends RowData, ->(row: Row, table: Table) { +>(row: Row, table: Table_Internal) { const allCells = row_getAllVisibleCells(row, table) const { right } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() @@ -169,7 +171,7 @@ export function table_setColumnPinning< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { options: TableOptions_ColumnPinning }, + table: Table_Internal, updater: Updater, ) { table.options.onColumnPinningChange?.(updater) @@ -178,10 +180,7 @@ export function table_setColumnPinning< export function table_resetColumnPinning< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { options: TableOptions_ColumnPinning }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnPinning( table, defaultState @@ -194,7 +193,7 @@ export function table_resetColumnPinning< export function table_getIsSomeColumnsPinned< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table, position?: ColumnPinningPosition) { +>(table: Table_Internal, position?: ColumnPinningPosition) { const pinningState = table_getState(table).columnPinning if (!position) { @@ -208,7 +207,7 @@ export function table_getIsSomeColumnsPinned< export function table_getLeftHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const allColumns = table_getAllColumns(table) const leafColumns = table_getVisibleLeafColumns(table) const { left } = @@ -224,7 +223,7 @@ export function table_getLeftHeaderGroups< export function table_getRightHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const allColumns = table_getAllColumns(table) const leafColumns = table_getVisibleLeafColumns(table) const { right } = @@ -240,7 +239,7 @@ export function table_getRightHeaderGroups< export function table_getCenterHeaderGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const allColumns = table_getAllColumns(table) let leafColumns = table_getVisibleLeafColumns(table) const { left, right } = @@ -258,7 +257,7 @@ export function table_getCenterHeaderGroups< export function table_getLeftFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const headerGroups = table_getLeftHeaderGroups(table) return [...headerGroups].reverse() } @@ -266,7 +265,7 @@ export function table_getLeftFooterGroups< export function table_getRightFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const headerGroups = table_getRightHeaderGroups(table) return [...headerGroups].reverse() } @@ -274,7 +273,7 @@ export function table_getRightFooterGroups< export function table_getCenterFooterGroups< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const headerGroups = table_getCenterHeaderGroups(table) return [...headerGroups].reverse() } @@ -284,7 +283,7 @@ export function table_getCenterFooterGroups< export function table_getLeftFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const leftHeaderGroups = table_getLeftHeaderGroups(table) return leftHeaderGroups .map((headerGroup) => { @@ -296,7 +295,7 @@ export function table_getLeftFlatHeaders< export function table_getRightFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const rightHeaderGroups = table_getRightHeaderGroups(table) return rightHeaderGroups .map((headerGroup) => { @@ -308,7 +307,7 @@ export function table_getRightFlatHeaders< export function table_getCenterFlatHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const centerHeaderGroups = table_getCenterHeaderGroups(table) return centerHeaderGroups .map((headerGroup) => { @@ -322,7 +321,7 @@ export function table_getCenterFlatHeaders< export function table_getLeftLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getLeftFlatHeaders(table).filter( (header) => !header.subHeaders.length, ) @@ -331,7 +330,7 @@ export function table_getLeftLeafHeaders< export function table_getRightLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getRightFlatHeaders(table).filter( (header) => !header.subHeaders.length, ) @@ -340,7 +339,7 @@ export function table_getRightLeafHeaders< export function table_getCenterLeafHeaders< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getCenterFlatHeaders(table).filter( (header) => !header.subHeaders.length, ) @@ -351,7 +350,7 @@ export function table_getCenterLeafHeaders< export function table_getLeftLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const { left } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() return left @@ -365,7 +364,7 @@ export function table_getLeftLeafColumns< export function table_getRightLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const { right } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() return right @@ -379,7 +378,7 @@ export function table_getRightLeafColumns< export function table_getCenterLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const { left, right } = table_getState(table).columnPinning ?? getDefaultColumnPinningState() const leftAndRight: Array = [...left, ...right] @@ -391,7 +390,7 @@ export function table_getCenterLeafColumns< export function table_getLeftVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getLeftLeafColumns(table).filter((column) => column_getIsVisible(column, table), ) @@ -400,7 +399,7 @@ export function table_getLeftVisibleLeafColumns< export function table_getRightVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getRightLeafColumns(table).filter((column) => column_getIsVisible(column, table), ) @@ -409,7 +408,7 @@ export function table_getRightVisibleLeafColumns< export function table_getCenterVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return table_getCenterLeafColumns(table).filter((column) => column_getIsVisible(column, table), ) diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts index f8787ae2fd..af24bd8432 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts @@ -48,7 +48,7 @@ export interface TableOptions_ColumnResizing { * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#oncolumnResizingchange) * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) */ - oncolumnResizingChange?: OnChangeFn + onColumnResizingChange?: OnChangeFn } export interface TableOptions_ColumnResizing_Unavailable { @@ -72,7 +72,7 @@ export interface TableOptions_ColumnResizing_Unavailable { export type ColumnResizingDefaultOptions = Pick< TableOptions_ColumnResizing, - 'columnResizeMode' | 'oncolumnResizingChange' | 'columnResizeDirection' + 'columnResizeMode' | 'onColumnResizingChange' | 'columnResizeDirection' > export interface Table_ColumnResizing { diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts index f81d6d516b..571147e28f 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts @@ -10,13 +10,12 @@ import { } from '../../core/table/Tables.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Header } from '../../types/Header' import type { Column } from '../../types/Column' import type { ColumnSizingState } from '../column-sizing/ColumnSizing.types' import type { ColumnDef_ColumnResizing, - TableOptions_ColumnResizing, columnResizingState, } from './ColumnResizing.types' @@ -39,9 +38,7 @@ export function column_getCanResize< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, ) { return ( (column.columnDef.enableResizing ?? true) && @@ -57,9 +54,7 @@ export function column_getIsResizing< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, ) { return table_getState(table).columnResizing?.isResizingColumn === column.id } @@ -70,9 +65,7 @@ export function header_getResizeHandler< TValue extends CellData = CellData, >( header: Header, - table: Table & { - options: Partial - }, + table: Table_Internal, _contextDocument?: Document, ) { const column = table_getColumn(table, header.column.id)! @@ -245,23 +238,16 @@ export function table_setColumnResizing< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial - }, + table: Table_Internal, updater: Updater, ) { - table.options.oncolumnResizingChange?.(updater) + table.options.onColumnResizingChange?.(updater) } export function table_resetHeaderSizeInfo< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnResizing( table, defaultState diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts index 10a1125a75..a589f8eb3a 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.utils.ts @@ -12,13 +12,12 @@ import { column_getIndex } from '../column-ordering/ColumnOrdering.utils' import { column_getVisibleLeafColumns } from '../column-visibility/ColumnVisibility.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Header } from '../../types/Header' import type { Column } from '../../types/Column' import type { ColumnDef_ColumnSizing, ColumnSizingState, - TableOptions_ColumnSizing, } from './ColumnSizing.types' export function getDefaultColumnSizingState() { @@ -37,7 +36,7 @@ export function column_getSize< column: Column & { columnDef: ColumnDef_ColumnSizing }, - table: Table & { options: TableOptions_ColumnSizing }, + table: Table_Internal, ): number { const defaultSizes = getDefaultColumnSizingState() const columnSize = table_getState(table).columnSizing?.[column.id] @@ -59,7 +58,7 @@ export function column_getStart< column: Column & { columnDef: ColumnDef_ColumnSizing }, - table: Table & { options: TableOptions_ColumnSizing }, + table: Table_Internal, position?: false | 'left' | 'right' | 'center', ): number { return column_getVisibleLeafColumns(table, position) @@ -73,7 +72,7 @@ export function column_getAfter< TValue extends CellData = CellData, >( column: Column, - table: Table, + table: Table_Internal, position?: false | 'left' | 'right' | 'center', ): number { return column_getVisibleLeafColumns(table, position) @@ -85,7 +84,10 @@ export function column_resetSize< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(table: Table, column: Column) { +>( + table: Table_Internal, + column: Column, +) { table_setColumnSizing(table, ({ [column.id]: _, ...rest }) => { return rest }) @@ -95,7 +97,10 @@ export function header_getSize< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(header: Header, table: Table) { +>( + header: Header, + table: Table_Internal, +) { let sum = 0 const recurse = (h: Header) => { @@ -117,7 +122,7 @@ export function header_getStart< TValue extends CellData = CellData, >( header: Header, - table: Table, + table: Table_Internal, ): number { if (header.index > 0) { const prevSiblingHeader = header.headerGroup?.headers[header.index - 1] @@ -136,7 +141,7 @@ export function table_setColumnSizing< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { options: TableOptions_ColumnSizing }, + table: Table_Internal, updater: Updater, ) { table.options.onColumnSizingChange?.(updater) @@ -145,7 +150,7 @@ export function table_setColumnSizing< export function table_resetColumnSizing< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table, defaultState?: boolean) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnSizing( table, defaultState ? {} : table_getInitialState(table).columnSizing ?? {}, @@ -155,7 +160,7 @@ export function table_resetColumnSizing< export function table_getTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return ( table_getHeaderGroups(table)[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header, table) @@ -166,7 +171,7 @@ export function table_getTotalSize< export function table_getLeftTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return ( table_getLeftHeaderGroups(table)[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header, table) @@ -177,7 +182,7 @@ export function table_getLeftTotalSize< export function table_getCenterTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return ( table_getCenterHeaderGroups(table)[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header, table) @@ -188,7 +193,7 @@ export function table_getCenterTotalSize< export function table_getRightTotalSize< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { return ( table_getRightHeaderGroups(table)[0]?.headers.reduce((sum, header) => { return sum + header_getSize(header, table) diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts index 75ea100f89..c0ee398a13 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.utils.ts @@ -14,14 +14,13 @@ import { } from '../column-pinning/ColumnPinning.utils' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Cell } from '../../types/Cell' import type { Column } from '../../types/Column' import type { ColumnPinningPosition } from '../column-pinning/ColumnPinning.types' import type { ColumnDef_ColumnVisibility, ColumnVisibilityState, - TableOptions_ColumnVisibility, } from './ColumnVisibility.types' import type { Row } from '../../types/Row' @@ -33,9 +32,7 @@ export function column_toggleVisibility< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, visible?: boolean, ): void { if (column_getCanHide(column, table)) { @@ -54,9 +51,7 @@ export function column_getIsVisible< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, ): boolean { const childColumns = column.columns return ( @@ -74,9 +69,7 @@ export function column_getCanHide< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, ) { return ( (column.columnDef.enableHiding ?? true) && @@ -92,9 +85,7 @@ export function column_getToggleVisibilityHandler< column: Column & { columnDef: Partial }, - table: Table & { - options: Partial - }, + table: Table_Internal, ) { return (e: unknown) => { column_toggleVisibility( @@ -109,9 +100,7 @@ export function column_getVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial - }, + table: Table_Internal, position?: ColumnPinningPosition | 'center', ) { return !position @@ -126,12 +115,7 @@ export function column_getVisibleLeafColumns< export function row_getAllVisibleCells< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial - }, -) { +>(row: Row, table: Table_Internal) { return row_getAllCells(row, table).filter((cell) => column_getIsVisible(cell.column, table), ) @@ -151,11 +135,7 @@ export function row_getVisibleCells< export function table_getVisibleFlatColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_getAllFlatColumns(table).filter((column) => column_getIsVisible(column, table), ) @@ -164,11 +144,7 @@ export function table_getVisibleFlatColumns< export function table_getVisibleLeafColumns< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_getAllLeafColumns(table).filter((column) => column_getIsVisible(column, table), ) @@ -178,9 +154,7 @@ export function table_setColumnVisibility< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial - }, + table: Table_Internal, updater: Updater, ) { table.options.onColumnVisibilityChange?.(updater) @@ -189,12 +163,7 @@ export function table_setColumnVisibility< export function table_resetColumnVisibility< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setColumnVisibility( table, defaultState ? {} : table_getInitialState(table).columnVisibility ?? {}, @@ -204,12 +173,7 @@ export function table_resetColumnVisibility< export function table_toggleAllColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - value?: boolean, -) { +>(table: Table_Internal, value?: boolean) { value = value ?? !table_getIsAllColumnsVisible(table) table_setColumnVisibility( @@ -227,11 +191,7 @@ export function table_toggleAllColumnsVisible< export function table_getIsAllColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return !table .getAllLeafColumns() .some((column) => !column_getIsVisible(column, table)) @@ -240,11 +200,7 @@ export function table_getIsAllColumnsVisible< export function table_getIsSomeColumnsVisible< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table .getAllLeafColumns() .some((column) => column_getIsVisible(column, table)) @@ -253,11 +209,7 @@ export function table_getIsSomeColumnsVisible< export function table_getToggleAllColumnsVisibilityHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return (e: unknown) => { table_toggleAllColumnsVisible( table, diff --git a/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts b/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts index 5fb4ce50f3..f2d2c7bef3 100644 --- a/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts +++ b/packages/table-core/src/features/global-faceting/GlobalFaceting.utils.ts @@ -2,7 +2,7 @@ import { table_getPreFilteredRowModel } from '../column-filtering/ColumnFilterin import type { RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' /** * @@ -12,7 +12,7 @@ import type { Table } from '../../types/Table' export function table_getGlobalFacetedMinMaxValues< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): () => undefined | [number, number] { +>(table: Table_Internal): () => undefined | [number, number] { return ( table.options._rowModels?.FacetedMinMax?.(table, '__global__') ?? (() => undefined) @@ -27,7 +27,7 @@ export function table_getGlobalFacetedMinMaxValues< export function table_getGlobalFacetedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): () => RowModel { +>(table: Table_Internal): () => RowModel { return ( table.options._rowModels?.Faceted?.(table, '__global__') ?? (() => table_getPreFilteredRowModel(table)) @@ -42,7 +42,7 @@ export function table_getGlobalFacetedRowModel< export function table_getGlobalFacetedUniqueValues< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): () => Map { +>(table: Table_Internal): () => Map { return ( table.options._rowModels?.FacetedUnique?.(table, '__global__') ?? (() => new Map()) diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts index 03e3650d6a..9b865181ca 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.utils.ts @@ -2,14 +2,10 @@ import { filterFns } from '../../fns/filterFns' import { isFunction } from '../../utils' import { table_getInitialState } from '../../core/table/Tables.utils' import type { ColumnDefBase_All } from '../../types/ColumnDef' -import type { TableOptions_GlobalFiltering } from './GlobalFiltering.types' -import type { - FilterFn, - TableOptions_ColumnFiltering, -} from '../column-filtering/ColumnFiltering.types' +import type { FilterFn } from '../column-filtering/ColumnFiltering.types' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table, Table_Internal } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { BuiltInFilterFn } from '../../fns/filterFns' diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts index 6288784c8e..f748d53a15 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.utils.ts @@ -9,13 +9,9 @@ import { import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' -import type { - ExpandedState, - ExpandedStateList, - TableOptions_RowExpanding, -} from './RowExpanding.types' +import type { ExpandedState, ExpandedStateList } from './RowExpanding.types' /** * @@ -28,9 +24,7 @@ export function table_autoResetExpanded< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, registered?: boolean, queued?: boolean, ) { @@ -63,12 +57,7 @@ export function table_autoResetExpanded< export function table_setExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table.options.onExpandedChange?.(updater) } @@ -80,12 +69,7 @@ export function table_setExpanded< export function table_toggleAllRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - expanded?: boolean, -) { +>(table: Table_Internal, expanded?: boolean) { if (expanded ?? !table_getIsAllRowsExpanded(table)) { table_setExpanded(table, true) } else { @@ -101,12 +85,7 @@ export function table_toggleAllRowsExpanded< export function table_resetExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setExpanded( table, defaultState ? {} : table_getInitialState(table).expanded ?? {}, @@ -121,11 +100,7 @@ export function table_resetExpanded< export function table_getCanSomeRowsExpand< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { return table_getPrePaginationRowModel(table).flatRows.some((row) => row_getCanExpand(row, table), ) @@ -139,11 +114,7 @@ export function table_getCanSomeRowsExpand< export function table_getToggleAllRowsExpandedHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { return (e: unknown) => { ;(e as any).persist?.() table_toggleAllRowsExpanded(table) @@ -158,11 +129,7 @@ export function table_getToggleAllRowsExpandedHandler< export function table_getIsSomeRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const expanded = table_getState(table).expanded ?? {} return expanded === true || Object.values(expanded).some(Boolean) } @@ -175,11 +142,7 @@ export function table_getIsSomeRowsExpanded< export function table_getIsAllRowsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const expanded = table_getState(table).expanded ?? {} // If expanded is true, save some cycles and return true @@ -212,11 +175,7 @@ export function table_getIsAllRowsExpanded< export function table_getExpandedDepth< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { let maxDepth = 0 const rowIds = @@ -240,11 +199,7 @@ export function table_getExpandedDepth< export function table_getPreExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { return table_getSortedRowModel(table) } @@ -256,11 +211,7 @@ export function table_getPreExpandedRowModel< export function table_getExpandedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Expanded) { table._rowModels.Expanded = table.options._rowModels?.Expanded?.(table) } @@ -283,9 +234,7 @@ export function row_toggleExpanded< TData extends RowData, >( row: Row, - table: Table & { - options: Partial> - }, + table: Table_Internal, expanded?: boolean, ) { table_setExpanded(table, (old) => { @@ -328,12 +277,7 @@ export function row_toggleExpanded< export function row_getIsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const expanded = table_getState(table).expanded ?? {} return !!( @@ -351,12 +295,7 @@ export function row_getIsExpanded< export function row_getCanExpand< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { return ( table.options.getRowCanExpand?.(row) ?? ((table.options.enableExpanding ?? true) && !!row.subRows.length) @@ -372,12 +311,7 @@ export function row_getCanExpand< export function row_getIsAllParentsExpanded< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { let isFullyExpanded = true let currentRow = row @@ -398,12 +332,7 @@ export function row_getIsAllParentsExpanded< export function row_getToggleExpandedHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const canExpand = row_getCanExpand(row, table) return () => { diff --git a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts index c171f0ed25..54677751a9 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.utils.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.utils.ts @@ -7,11 +7,8 @@ import { import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' -import type { - PaginationState, - TableOptions_RowPagination, -} from './RowPagination.types' +import type { Table_Internal } from '../../types/Table' +import type { PaginationState } from './RowPagination.types' const defaultPageIndex = 0 const defaultPageSize = 10 @@ -38,9 +35,7 @@ export function table_autoResetPageIndex< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial - }, + table: Table_Internal, registered?: boolean, queued?: boolean, ) { @@ -74,12 +69,7 @@ export function table_autoResetPageIndex< export function table_setPagination< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { const safeUpdater: Updater = (old) => { const newState = functionalUpdate(updater, old) @@ -97,12 +87,7 @@ export function table_setPagination< export function table_resetPagination< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setPagination( table, defaultState @@ -119,12 +104,7 @@ export function table_resetPagination< export function table_setPageIndex< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table_setPagination(table, (old) => { let pageIndex = functionalUpdate(updater, old.pageIndex) @@ -151,12 +131,7 @@ export function table_setPageIndex< export function table_resetPageIndex< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setPageIndex( table, defaultState @@ -173,12 +148,7 @@ export function table_resetPageIndex< export function table_resetPageSize< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setPageSize( table, defaultState @@ -195,12 +165,7 @@ export function table_resetPageSize< export function table_setPageSize< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table_setPagination(table, (old) => { const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize)) const topRowIndex = old.pageSize * old.pageIndex @@ -222,7 +187,7 @@ export function table_setPageSize< export function table_getPageOptions< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table) { +>(table: Table_Internal) { const pageCount = table_getPageCount(table) let pageOptions: Array = [] if (pageCount && pageCount > 0) { @@ -239,11 +204,7 @@ export function table_getPageOptions< export function table_getCanPreviousPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return (table_getState(table).pagination?.pageIndex ?? 0) > 0 } @@ -255,11 +216,7 @@ export function table_getCanPreviousPage< export function table_getCanNextPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { const pageIndex = table_getState(table).pagination?.pageIndex ?? defaultPageIndex @@ -284,11 +241,7 @@ export function table_getCanNextPage< export function table_previousPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_setPageIndex(table, (old) => old - 1) } @@ -300,11 +253,7 @@ export function table_previousPage< export function table_nextPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_setPageIndex(table, (old) => { return old + 1 }) @@ -318,11 +267,7 @@ export function table_nextPage< export function table_firstPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_setPageIndex(table, 0) } @@ -334,11 +279,7 @@ export function table_firstPage< export function table_lastPage< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return table_setPageIndex(table, table_getPageCount(table) - 1) } @@ -350,11 +291,7 @@ export function table_lastPage< export function table_getPrePaginationRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -): RowModel { +>(table: Table_Internal): RowModel { return table_getExpandedRowModel(table) } @@ -366,11 +303,7 @@ export function table_getPrePaginationRowModel< export function table_getPaginatedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Paginated) { table._rowModels.Paginated = table.options._rowModels?.Paginated?.(table) } @@ -390,11 +323,7 @@ export function table_getPaginatedRowModel< export function table_getPageCount< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return ( table.options.pageCount ?? Math.ceil( @@ -412,11 +341,7 @@ export function table_getPageCount< export function table_getRowCount< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial - }, -) { +>(table: Table_Internal) { return ( table.options.rowCount ?? table_getPrePaginationRowModel(table).rows.length ) diff --git a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts index 1510cdb6b0..19f0a25933 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.utils.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.utils.ts @@ -10,13 +10,9 @@ import { } from '../../core/table/Tables.utils' import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' -import type { - RowPinningPosition, - RowPinningState, - TableOptions_RowPinning, -} from './RowPinning.types' +import type { RowPinningPosition, RowPinningState } from './RowPinning.types' // State Utils @@ -40,9 +36,7 @@ export function table_setRowPinning< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, updater: Updater, ): void { table.options.onRowPinningChange?.(updater) @@ -56,12 +50,7 @@ export function table_setRowPinning< export function table_resetRowPinning< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - defaultState?: boolean, -): void { +>(table: Table_Internal, defaultState?: boolean): void { table_setRowPinning( table, defaultState @@ -82,9 +71,7 @@ export function table_getIsSomeRowsPinned< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, position?: RowPinningPosition, ): boolean { const rowPinning = table_getState(table).rowPinning @@ -105,9 +92,7 @@ function table_getPinnedRows< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, position: 'top' | 'bottom', ): Array> { const visibleRows = table.getRowModel().rows @@ -139,11 +124,7 @@ function table_getPinnedRows< export function table_getTopRows< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): Array> { +>(table: Table_Internal): Array> { return table_getPinnedRows(table, 'top') } @@ -155,11 +136,7 @@ export function table_getTopRows< export function table_getBottomRows< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): Array> { +>(table: Table_Internal): Array> { return table_getPinnedRows(table, 'bottom') } @@ -171,11 +148,7 @@ export function table_getBottomRows< export function table_getCenterRows< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): Array> { +>(table: Table_Internal): Array> { const { top, bottom } = table_getState(table).rowPinning ?? getDefaultRowPinningState() const allRows = table.getRowModel().rows @@ -197,9 +170,7 @@ export function row_getCanPin< TData extends RowData, >( row: Row, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): boolean { const { enableRowPinning } = table.options if (typeof enableRowPinning === 'function') { @@ -219,9 +190,7 @@ export function row_getIsPinned< TData extends RowData, >( row: Row, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): RowPinningPosition { const { top, bottom } = table_getState(table).rowPinning ?? getDefaultRowPinningState() @@ -242,12 +211,7 @@ export function row_getIsPinned< export function row_getPinnedIndex< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -): number { +>(row: Row, table: Table_Internal): number { const position = row_getIsPinned(row, table) if (!position) return -1 @@ -268,9 +232,7 @@ export function row_getPinnedIndex< */ export function row_pin( row: Row, - table: Table & { - options: Partial> - }, + table: Table_Internal, position: RowPinningPosition, includeLeafRows?: boolean, includeParentRows?: boolean, diff --git a/packages/table-core/src/features/row-selection/RowSelection.utils.ts b/packages/table-core/src/features/row-selection/RowSelection.utils.ts index 31237f83e6..0a942a8fda 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.utils.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.utils.ts @@ -11,12 +11,9 @@ import { import type { RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Row } from '../../types/Row' -import type { - RowSelectionState, - TableOptions_RowSelection, -} from './RowSelection.types' +import type { RowSelectionState } from './RowSelection.types' // State utils @@ -29,9 +26,7 @@ export function table_setRowSelection< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, updater: Updater, ) { table.options.onRowSelectionChange?.(updater) @@ -45,12 +40,7 @@ export function table_setRowSelection< export function table_resetRowSelection< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setRowSelection( table, defaultState ? {} : table_getInitialState(table).rowSelection ?? {}, @@ -67,12 +57,7 @@ export function table_resetRowSelection< export function table_toggleAllRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - value?: boolean, -) { +>(table: Table_Internal, value?: boolean) { table_setRowSelection(table, (old) => { value = typeof value !== 'undefined' ? value : !table_getIsAllRowsSelected(table) @@ -108,12 +93,7 @@ export function table_toggleAllRowsSelected< export function table_toggleAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - value?: boolean, -) { +>(table: Table_Internal, value?: boolean) { table_setRowSelection(table, (old) => { const resolvedValue = typeof value !== 'undefined' @@ -138,11 +118,7 @@ export function table_toggleAllPageRowsSelected< export function table_getPreSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { return table_getCoreRowModel(table) } @@ -154,11 +130,7 @@ export function table_getPreSelectedRowModel< export function table_getSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const rowModel = table_getCoreRowModel(table) if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { @@ -180,11 +152,7 @@ export function table_getSelectedRowModel< export function table_getFilteredSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const rowModel = table_getCoreRowModel(table) if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { @@ -206,11 +174,7 @@ export function table_getFilteredSelectedRowModel< export function table_getGroupedSelectedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const rowModel = table_getCoreRowModel(table) if (!Object.keys(table_getState(table).rowSelection ?? {}).length) { @@ -232,11 +196,7 @@ export function table_getGroupedSelectedRowModel< export function table_getIsAllRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const preGroupedFlatRows = table_getFilteredRowModel(table).flatRows const rowSelection = table_getState(table).rowSelection ?? {} @@ -265,11 +225,7 @@ export function table_getIsAllRowsSelected< export function table_getIsAllPageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const paginationFlatRows = table_getPaginatedRowModel(table).flatRows.filter( (row) => row_getCanSelect(row, table), ) @@ -295,11 +251,7 @@ export function table_getIsAllPageRowsSelected< export function table_getIsSomeRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const totalSelected = Object.keys( table_getState(table).rowSelection ?? {}, ).length @@ -317,11 +269,7 @@ export function table_getIsSomeRowsSelected< export function table_getIsSomePageRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { const paginationFlatRows = table_getPaginatedRowModel(table).flatRows return table_getIsAllPageRowsSelected(table) ? false @@ -341,11 +289,7 @@ export function table_getIsSomePageRowsSelected< export function table_getToggleAllRowsSelectedHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { return (e: unknown) => { table_toggleAllRowsSelected( table, @@ -362,11 +306,7 @@ export function table_getToggleAllRowsSelectedHandler< export function table_getToggleAllPageRowsSelectedHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -) { +>(table: Table_Internal) { return (e: unknown) => { table_toggleAllPageRowsSelected( table, @@ -387,9 +327,7 @@ export function row_toggleSelected< TData extends RowData, >( row: Row, - table: Table & { - options: Partial> - }, + table: Table_Internal, value?: boolean, opts?: { selectChildren?: boolean @@ -429,12 +367,7 @@ export function row_toggleSelected< export function row_getIsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const rowSelection = table_getState(table).rowSelection ?? {} return isRowSelected(row, rowSelection) } @@ -448,12 +381,7 @@ export function row_getIsSelected< export function row_getIsSomeSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const rowSelection = table_getState(table).rowSelection ?? {} return isSubRowSelected(row, rowSelection, table) === 'some' } @@ -467,12 +395,7 @@ export function row_getIsSomeSelected< export function row_getIsAllSubRowsSelected< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const rowSelection = table_getState(table).rowSelection ?? {} return isSubRowSelected(row, rowSelection, table) === 'all' } @@ -486,12 +409,7 @@ export function row_getIsAllSubRowsSelected< export function row_getCanSelect< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { if (typeof table.options.enableRowSelection === 'function') { return table.options.enableRowSelection(row) } @@ -508,12 +426,7 @@ export function row_getCanSelect< export function row_getCanSelectSubRows< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { if (typeof table.options.enableSubRowSelection === 'function') { return table.options.enableSubRowSelection(row) } @@ -530,12 +443,7 @@ export function row_getCanSelectSubRows< export function row_getCanMultiSelect< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { if (typeof table.options.enableMultiRowSelection === 'function') { return table.options.enableMultiRowSelection(row) } @@ -552,12 +460,7 @@ export function row_getCanMultiSelect< export function row_getToggleSelectedHandler< TFeatures extends TableFeatures, TData extends RowData, ->( - row: Row, - table: Table & { - options: Partial> - }, -) { +>(row: Row, table: Table_Internal) { const canSelect = row_getCanSelect(row, table) return (e: unknown) => { @@ -586,9 +489,7 @@ const mutateRowIsSelected = < rowId: string, value: boolean, includeChildren: boolean, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) => { const row = table_getRow(table, rowId, true) @@ -631,9 +532,7 @@ export function selectRowsFn< TFeatures extends TableFeatures, TData extends RowData, >( - table: Table & { - options: Partial> - }, + table: Table_Internal, rowModel: RowModel, ): RowModel { const rowSelection = table_getState(table).rowSelection ?? {} @@ -695,9 +594,7 @@ export function isSubRowSelected< >( row: Row, selection: Record, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): boolean | 'some' | 'all' { if (!row.subRows.length) return false diff --git a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts index 218f35ef4c..124a5f1534 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.utils.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.utils.ts @@ -11,7 +11,7 @@ import type { BuiltInSortingFn } from '../../fns/sortingFns' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' import type { RowModel } from '../../types/RowModel' -import type { Table } from '../../types/Table' +import type { Table_Internal } from '../../types/Table' import type { Column } from '../../types/Column' import type { ColumnDef_RowSorting, @@ -30,12 +30,7 @@ import type { export function table_setSorting< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - updater: Updater, -) { +>(table: Table_Internal, updater: Updater) { table.options.onSortingChange?.(updater) } @@ -47,12 +42,7 @@ export function table_setSorting< export function table_resetSorting< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, - defaultState?: boolean, -) { +>(table: Table_Internal, defaultState?: boolean) { table_setSorting( table, defaultState ? [] : table_getInitialState(table).sorting ?? [], @@ -75,9 +65,7 @@ export function column_getAutoSortingFn< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { const firstRows = table_getFilteredRowModel(table).flatRows.slice(10) @@ -116,7 +104,10 @@ export function column_getAutoSortDir< TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData, ->(column: Column, table: Table) { +>( + column: Column, + table: Table_Internal, +) { const firstRow = table_getFilteredRowModel(table).flatRows[0] const value = firstRow ? row_getValue(firstRow, table, column.id) : undefined @@ -142,9 +133,7 @@ export function column_getSortingFn< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { return isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn @@ -169,9 +158,7 @@ export function column_toggleSorting< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, desc?: boolean, multi?: boolean, ) { @@ -282,9 +269,7 @@ export function column_getFirstSortDir< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { const sortDescFirst = column.columnDef.sortDescFirst ?? @@ -308,9 +293,7 @@ export function column_getNextSortingOrder< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, multi?: boolean, ) { const firstSortDirection = column_getFirstSortDir(column, table) @@ -344,9 +327,7 @@ export function column_getCanSort< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { return ( (column.columnDef.enableSorting ?? true) && @@ -369,9 +350,7 @@ export function column_getCanMultiSort< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): boolean { return ( column.columnDef.enableMultiSort ?? @@ -394,9 +373,7 @@ export function column_getIsSorted< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): false | SortDirection { const columnSort = table_getState(table).sorting?.find( (d) => d.id === column.id, @@ -418,9 +395,7 @@ export function column_getSortIndex< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ): number { return ( table_getState(table).sorting?.findIndex((d) => d.id === column.id) ?? -1 @@ -440,9 +415,7 @@ export function column_clearSorting< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { // clear sorting for just 1 column table_setSorting(table, (old) => @@ -464,9 +437,7 @@ export function column_getToggleSortingHandler< column: Column & { columnDef: Partial> }, - table: Table & { - options: Partial> - }, + table: Table_Internal, ) { const canSort = column_getCanSort(column, table) @@ -494,18 +465,14 @@ export function column_getToggleSortingHandler< export function table_getPreSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->(table: Table): RowModel { +>(table: Table_Internal): RowModel { return table_getGroupedRowModel(table) } export function table_getSortedRowModel< TFeatures extends TableFeatures, TData extends RowData, ->( - table: Table & { - options: Partial> - }, -): RowModel { +>(table: Table_Internal): RowModel { if (!table._rowModels.Sorted) { table._rowModels.Sorted = table.options._rowModels?.Sorted?.(table) } diff --git a/packages/table-core/src/helpers/tableFeatures.ts b/packages/table-core/src/helpers/tableFeatures.ts index 3c7d87db7b..b3f1007197 100644 --- a/packages/table-core/src/helpers/tableFeatures.ts +++ b/packages/table-core/src/helpers/tableFeatures.ts @@ -9,6 +9,7 @@ import type { TableFeatures } from '../types/TableFeatures' * * @example ```tsx * import { tableFeatures, ColumnVisibility, RowPinning } from '@tanstack/react-table' + * * const _features = tableFeatures({ ColumnVisibility, RowPinning }); * * const table = useTable({ _features, rowModels: {}, columns, data }); diff --git a/packages/table-core/src/helpers/tableHelper.ts b/packages/table-core/src/helpers/tableHelper.ts index 7230257319..7277722b80 100644 --- a/packages/table-core/src/helpers/tableHelper.ts +++ b/packages/table-core/src/helpers/tableHelper.ts @@ -47,19 +47,22 @@ export function constructTableHelper< ) => Table, tableHelperOptions: TableHelperOptions, ): TableHelper_Core { + const { TData: _TData, ..._tableHelperOptions } = tableHelperOptions return { columnHelper: createColumnHelper(), - features: tableHelperOptions._features as TFeatures, - options: tableHelperOptions, + features: tableHelperOptions._features, + options: _tableHelperOptions as any, tableCreator: (tableOptions) => - tableCreator({ ...tableHelperOptions, ...tableOptions }), + tableCreator({ ...(_tableHelperOptions as any), ...tableOptions }), } } // test // // eslint-disable-next-line import/first, import/order -// import { constructTable } from '../core/table/createTable' +// import { constructTable } from '../core/table/constructTable' +// // eslint-disable-next-line import/first, import/order +// import { type ColumnDef } from '../types/ColumnDef' // type Person = { // firstName: string @@ -74,11 +77,14 @@ export function constructTableHelper< // }) // const columns = [ -// tableHelper.columnHelper.accessor('firstName', { header: 'First Name' }), +// tableHelper.columnHelper.accessor('firstName', { +// header: 'First Name', +// cell: (info) => info.getValue(), +// }), // tableHelper.columnHelper.accessor('lastName', { header: 'Last Name' }), // tableHelper.columnHelper.accessor('age', { header: 'Age' }), // tableHelper.columnHelper.display({ header: 'Actions', id: 'actions' }), -// ] +// ] as Array> // const data: Array = [] diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index a048d1c712..60c134774d 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -84,7 +84,7 @@ export type Table< export type Table_Internal< TFeatures extends TableFeatures, TData extends RowData, -> = Omit, 'getState' | 'options'> & { +> = Table & { getState: () => TableState_All options: TableOptions_All }