From d7fc3ec9c4cbaafae72da02bd315b2d98ab1483c Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Sat, 24 Aug 2024 17:51:41 -0500 Subject: [PATCH] fix _getInitialState bugs --- examples/lit/column-sizing/src/main.ts | 2 +- .../column-resizing-performant/src/main.tsx | 4 +- examples/react/column-sizing/src/main.tsx | 8 +- examples/react/row-pinning/src/main.tsx | 37 +++++---- .../table-core/src/core/table/Tables.types.ts | 2 +- .../column-filtering/ColumnFiltering.ts | 9 +-- .../column-filtering/ColumnFiltering.types.ts | 12 +-- .../column-grouping/ColumnGrouping.ts | 5 +- .../column-grouping/ColumnGrouping.types.ts | 12 +-- .../column-ordering/ColumnOrdering.ts | 23 +----- .../column-ordering/ColumnOrdering.types.ts | 10 +-- .../features/column-pinning/ColumnPinning.ts | 9 +-- .../column-pinning/ColumnPinning.types.ts | 12 +-- .../column-resizing/ColumnResizing.ts | 27 ++++--- .../column-resizing/ColumnResizing.types.ts | 22 +++--- .../column-resizing/ColumnResizing.utils.ts | 26 +++---- .../features/column-sizing/ColumnSizing.ts | 5 +- .../column-sizing/ColumnSizing.types.ts | 2 +- .../column-visibility/ColumnVisibility.ts | 5 +- .../ColumnVisibility.types.ts | 2 +- .../global-filtering/GlobalFiltering.ts | 5 +- .../global-filtering/GlobalFiltering.types.ts | 2 +- .../features/row-expanding/RowExpanding.ts | 38 +--------- .../row-expanding/RowExpanding.types.ts | 2 +- .../features/row-pagination/RowPagination.ts | 49 ++---------- .../row-pagination/RowPagination.types.ts | 2 +- .../src/features/row-pinning/RowPinning.ts | 5 +- .../features/row-pinning/RowPinning.types.ts | 2 +- .../features/row-selection/RowSelection.ts | 75 +------------------ .../row-selection/RowSelection.types.ts | 2 +- .../src/features/row-sorting/RowSorting.ts | 37 +-------- .../features/row-sorting/RowSorting.types.ts | 2 +- .../table-core/src/types/TableFeatures.ts | 2 +- packages/table-core/src/types/TableOptions.ts | 28 ++----- packages/table-core/src/types/TableState.ts | 30 ++++---- 35 files changed, 150 insertions(+), 365 deletions(-) diff --git a/examples/lit/column-sizing/src/main.ts b/examples/lit/column-sizing/src/main.ts index 78f33c2fb4..65423d6aed 100644 --- a/examples/lit/column-sizing/src/main.ts +++ b/examples/lit/column-sizing/src/main.ts @@ -132,7 +132,7 @@ class LitTableExample extends LitElement { ${JSON.stringify( { columnSizing: table.getState().columnSizing, - columnSizingInfo: table.getState().columnSizingInfo, + columnResizing: table.getState().columnResizing, }, null, 2, diff --git a/examples/react/column-resizing-performant/src/main.tsx b/examples/react/column-resizing-performant/src/main.tsx index 1593aa9a3f..88b8e750a2 100644 --- a/examples/react/column-resizing-performant/src/main.tsx +++ b/examples/react/column-resizing-performant/src/main.tsx @@ -106,7 +106,7 @@ function App() { colSizes[`--col-${header.column.id}-size`] = header.column.getSize() } return colSizes - }, [table.getState().columnSizingInfo, table.getState().columnSizing]) + }, [table.getState().columnResizing, table.getState().columnSizing]) //demo purposes const [enableMemo, setEnableMemo] = React.useState(true) @@ -191,7 +191,7 @@ function App() { ))} {/* When resizing any column we will render this special memoized version of our table body */} - {table.getState().columnSizingInfo.isResizingColumn && enableMemo ? ( + {table.getState().columnResizing.isResizingColumn && enableMemo ? ( ) : ( diff --git a/examples/react/column-sizing/src/main.tsx b/examples/react/column-sizing/src/main.tsx index 50e7e60795..7e161082c1 100644 --- a/examples/react/column-sizing/src/main.tsx +++ b/examples/react/column-sizing/src/main.tsx @@ -201,7 +201,7 @@ function App() { 'rtl' ? -1 : 1) * - (table.getState().columnSizingInfo + (table.getState().columnResizing .deltaOffset ?? 0) }px)` : '', @@ -290,7 +290,7 @@ function App() { 'rtl' ? -1 : 1) * - (table.getState().columnSizingInfo + (table.getState().columnResizing .deltaOffset ?? 0) }px)` : '', @@ -394,7 +394,7 @@ function App() { 'rtl' ? -1 : 1) * - (table.getState().columnSizingInfo + (table.getState().columnResizing .deltaOffset ?? 0) }px)` : '', @@ -453,7 +453,7 @@ function App() { {JSON.stringify( { columnSizing: table.getState().columnSizing, - columnSizingInfo: table.getState().columnSizingInfo, + columnResizing: table.getState().columnResizing, }, null, 2, diff --git a/examples/react/row-pinning/src/main.tsx b/examples/react/row-pinning/src/main.tsx index 304ea8f14a..625bb551b6 100644 --- a/examples/react/row-pinning/src/main.tsx +++ b/examples/react/row-pinning/src/main.tsx @@ -1,8 +1,5 @@ -import React, { useEffect } from 'react' +import React from 'react' import ReactDOM from 'react-dom/client' - -import './index.css' - import { ColumnFiltering, RowExpanding, @@ -13,11 +10,11 @@ import { createFilteredRowModel, createPaginatedRowModel, flexRender, + tableFeatures, useTable, } from '@tanstack/react-table' import { makeData } from './makeData' import type { Person } from './makeData' - import type { Column, ColumnDef, @@ -26,6 +23,14 @@ import type { RowPinningState, Table, } from '@tanstack/react-table' +import './index.css' + +const _features = tableFeatures({ + RowPinning, + RowExpanding, + ColumnFiltering, + RowPagination, +}) function App() { const rerender = React.useReducer(() => ({}), {})[1] @@ -43,7 +48,7 @@ function App() { const [includeParentRows, setIncludeParentRows] = React.useState(false) const [copyPinnedRows, setCopyPinnedRows] = React.useState(false) - const columns = React.useMemo>>( + const columns = React.useMemo>>( () => [ { id: 'pin', @@ -150,7 +155,7 @@ function App() { const refreshData = () => setData(() => makeData(1000, 2, 2)) const table = useTable({ - _features: { RowPinning, RowExpanding, ColumnFiltering, RowPagination }, + _features, _rowModels: { Core: createCoreRowModel(), Filtered: createFilteredRowModel(), @@ -172,9 +177,9 @@ function App() { }) // console.log(table.getBottomRows) - useEffect(() => { - console.log(table.getBottomRows()) - }, [table.getBottomRows()]) + // React.useEffect(() => { + // console.log(table.getBottomRows()) + // }, [table.getBottomRows()]) return (
@@ -216,7 +221,7 @@ function App() { ).map((row) => { return ( - {row.getVisibleCells().map((cell) => { + {row.getAllCells().map((cell) => { return ( {flexRender( @@ -363,8 +368,8 @@ function PinnedRow({ row, table, }: { - row: Row - table: Table + row: Row + table: Table }) { return ( - {row.getVisibleCells().map((cell) => { + {row.getAllCells().map((cell) => { return ( {flexRender(cell.column.columnDef.cell, cell.getContext())} @@ -398,8 +403,8 @@ function Filter({ column, table, }: { - column: Column - table: Table + column: Column + table: Table }) { const firstValue = table .getPreFilteredRowModel() diff --git a/packages/table-core/src/core/table/Tables.types.ts b/packages/table-core/src/core/table/Tables.types.ts index f664978128..c1ea35041c 100644 --- a/packages/table-core/src/core/table/Tables.types.ts +++ b/packages/table-core/src/core/table/Tables.types.ts @@ -106,7 +106,7 @@ export interface Table_CoreProperties< * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#initialstate) * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables) */ - initialState: Partial> + initialState: TableState /** * A read-only reference to the table's current options. * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#options) diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.ts index e925e64b26..16da468336 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.ts @@ -12,6 +12,7 @@ import { table_resetColumnFilters, table_setColumnFilters, } from './ColumnFiltering.utils' +import type { TableState } from '../../types/TableState' import type { CellData, RowData, Updater } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -35,7 +36,9 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering) */ export const ColumnFiltering: TableFeature = { - _getInitialState: (state): TableState_ColumnFiltering => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnFiltering => { return { columnFilters: [], ...state, @@ -72,8 +75,6 @@ export const ColumnFiltering: TableFeature = { table: Table & Partial>, ): void => { - - assignAPIs(column, table, [ { fn: () => column_getAutoFilterFn(column, table), @@ -110,8 +111,6 @@ export const ColumnFiltering: TableFeature = { table: Table & Partial>, ): void => { - - assignAPIs(table, table, [ { fn: (updater: Updater) => diff --git a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts index 9669006191..2fffc4b6fa 100644 --- a/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts +++ b/packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts @@ -213,7 +213,7 @@ type ResolvedFilterFns< filterFns?: Record> } : { - filterFns: Record> + filterFns: Record> } export interface TableOptions_ColumnFiltering< @@ -222,16 +222,6 @@ export interface TableOptions_ColumnFiltering< > extends ColumnFiltersOptionsBase, ResolvedFilterFns {} -export interface TableOptions_ColumnFiltering_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> extends ColumnFiltersOptionsBase, - ResolvedFilterFns { - /** - * @description Allows `any`. - */ -} - export interface Table_ColumnFiltering< TFeatures extends TableFeatures, TData extends RowData, diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts index dee3388049..8c3161f816 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.ts @@ -17,6 +17,7 @@ import { table_resetGrouping, table_setGrouping, } from './ColumnGrouping.utils' +import type { TableState } from '../../types/TableState' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -39,7 +40,9 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-grouping) */ export const ColumnGrouping: TableFeature = { - _getInitialState: (state): TableState_ColumnGrouping => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnGrouping => { return { grouping: [], ...state, diff --git a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts index 218f4c4ab8..e040f495c5 100644 --- a/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts +++ b/packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts @@ -19,7 +19,7 @@ export interface TableState_ColumnGrouping { export interface TableState_ColumnGrouping_Unavailable { /** - * @deprecated Import the `GroupingState` feature to use the column grouping APIs. + * @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs. */ grouping: GroupingState } @@ -231,16 +231,6 @@ export interface TableOptions_ColumnGrouping< > extends GroupingOptionsBase, ResolvedAggregationFns {} -export interface TableOptions_ColumnGrouping_Unavailable< - TFeatures extends TableFeatures, - TData extends RowData, -> extends GroupingOptionsBase, - ResolvedAggregationFns { - /** - * @description Allows `any`. - */ -} - export type GroupingColumnMode = false | 'reorder' | 'remove' export interface Table_ColumnGrouping< diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.ts index 69dfba4967..18ef827d64 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.ts @@ -7,6 +7,7 @@ import { table_resetColumnOrder, table_setColumnOrder, } from './ColumnOrdering.utils' +import type { TableState } from '../../types/TableState' import type { ColumnOrderDefaultOptions, Column_ColumnOrdering, @@ -24,7 +25,9 @@ import type { Column } from '../../types/Column' * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-ordering) */ export const ColumnOrdering: TableFeature = { - _getInitialState: (state): TableState_ColumnOrdering => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnOrdering => { return { columnOrder: [], ...state, @@ -49,22 +52,7 @@ export const ColumnOrdering: TableFeature = { table: Table & Partial>, ): void => { - // column.getIndex = memo( - // (position) => [ - // position, - // _table_getState(table).columnOrder, - // _table_getState(table).columnPinning, - // _table_getState(table).grouping, - // ], - // (position) => column_getIndex(column, table, position), - // getMemoOptions(table.options, 'debugColumns', 'getIndex'), - // ) - // column.getIsFirstColumn = (position) => - // column_getIsFirstColumn(column, table, position) - - // column.getIsLastColumn = (position) => - // column_getIsLastColumn(column, table, position) assignAPIs(column, table, [ { @@ -89,10 +77,7 @@ export const ColumnOrdering: TableFeature = { table: Table & Partial>, ): void => { - // table.setColumnOrder = (updater) => table_setColumnOrder(table, updater) - // table.resetColumnOrder = (defaultState) => - // table_resetColumnOrder(table, defaultState) assignAPIs(table, table, [ { diff --git a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts index 6c4a709a5d..2f6a91de84 100644 --- a/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts +++ b/packages/table-core/src/features/column-ordering/ColumnOrdering.types.ts @@ -1,6 +1,5 @@ import type { OnChangeFn, RowData, Updater } from '../../types/type-utils' import type { TableFeatures } from '../../types/TableFeatures' -import type { Column } from '../../types/Column' import type { ColumnPinningPosition } from '../column-pinning/ColumnPinning.types' export type ColumnOrderState = Array @@ -11,7 +10,7 @@ export interface TableState_ColumnOrdering { export interface TableState_ColumnOrdering_Unavailable { /** - * @deprecated Import the `ColumnOrderState` feature to use the column ordering APIs. + * @deprecated Import the `ColumnOrdering` feature to use the column ordering APIs. */ columnOrder: ColumnOrderState } @@ -25,13 +24,6 @@ export interface TableOptions_ColumnOrdering { onColumnOrderChange?: OnChangeFn } -export interface TableOptions_ColumnOrdering_Unavailable { - /** - * @deprecated Import the `OnChangeFn` feature to use the table options column ordering APIs. - */ - onColumnOrderChange?: OnChangeFn -} - export interface Column_ColumnOrdering { /** * Returns the index of the column in the order of the visible columns. Optionally pass a `position` parameter to get the index of the column in a sub-section of the table diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.ts index a43c797185..bf7ced534e 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.ts @@ -35,6 +35,7 @@ import { table_resetColumnPinning, table_setColumnPinning, } from './ColumnPinning.utils' +import type { TableState } from '../../types/TableState' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -54,7 +55,9 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning) */ export const ColumnPinning: TableFeature = { - _getInitialState: (state): TableState_ColumnPinning => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnPinning => { return { columnPinning: getDefaultColumnPinningState(), ...state, @@ -79,7 +82,6 @@ export const ColumnPinning: TableFeature = { table: Table & Partial>, ): void => { - assignAPIs(column, table, [ { fn: (position) => column_pin(column, table, position), @@ -101,7 +103,6 @@ export const ColumnPinning: TableFeature = { table: Table & Partial>, ): void => { - assignAPIs(row, table, [ { fn: () => row_getCenterVisibleCells(row, table), @@ -134,8 +135,6 @@ export const ColumnPinning: TableFeature = { table: Table & Partial>, ): void => { - - assignAPIs(table, table, [ { fn: (updater) => table_setColumnPinning(table, updater), diff --git a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts index f8064d25bb..353799cca0 100644 --- a/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts +++ b/packages/table-core/src/features/column-pinning/ColumnPinning.types.ts @@ -18,7 +18,7 @@ export interface TableState_ColumnPinning { export interface TableState_ColumnPinning_Unavailable { /** - * @deprecated Import the `ColumnPinningState` feature to use the column pinning APIs. + * @deprecated Import the `ColumnPinning` feature to use the column pinning APIs. */ columnPinning: ColumnPinningState } @@ -38,16 +38,6 @@ export interface TableOptions_ColumnPinning { onColumnPinningChange?: OnChangeFn } -export interface TableOptions_ColumnPinning_Unavailable { - /** - * @deprecated Use `enableColumnPinning` or `enableRowPinning` instead. - * Enables/disables all pinning for the table. Defaults to `true`. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-pinning#enablepinning) - * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-pinning) - */ - enablePinning?: boolean -} - export interface ColumnPinningDefaultOptions { onColumnPinningChange: OnChangeFn } diff --git a/packages/table-core/src/features/column-resizing/ColumnResizing.ts b/packages/table-core/src/features/column-resizing/ColumnResizing.ts index ed579aa94f..1a1927bb90 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.ts @@ -2,11 +2,12 @@ import { assignAPIs, makeStateUpdater } from '../../utils' import { column_getCanResize, column_getIsResizing, - getDefaultColumnSizingInfoState, + getDefaultColumnResizingState, header_getResizeHandler, table_resetHeaderSizeInfo, - table_setColumnSizingInfo, + table_setcolumnResizing, } from './ColumnResizing.utils' +import type { TableState } from '../../types/TableState' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -28,9 +29,11 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-resizing) */ export const ColumnResizing: TableFeature = { - _getInitialState: (state): TableState_ColumnResizing => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnResizing => { return { - columnSizingInfo: getDefaultColumnSizingInfoState(), + columnResizing: getDefaultColumnResizingState(), ...state, } }, @@ -41,7 +44,7 @@ export const ColumnResizing: TableFeature = { return { columnResizeMode: 'onEnd', columnResizeDirection: 'ltr', - onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table), + oncolumnResizingChange: makeStateUpdater('columnResizing', table), } }, @@ -53,13 +56,14 @@ export const ColumnResizing: TableFeature = { column: Column & Partial, table: Table & Partial, ): void => { - // column.getCanResize = () => column_getCanResize(column, table) - // column.getIsResizing = () => column_getIsResizing(column, table) assignAPIs(column, table, [ { fn: () => column_getCanResize(column, table), }, + { + fn: () => column_getIsResizing(column, table), + }, ]) }, @@ -71,8 +75,7 @@ export const ColumnResizing: TableFeature = { header: Header & Partial, table: Table & Partial, ): void => { - // header.getResizeHandler = (_contextDocument) => - // header_getResizeHandler(header, table, _contextDocument) + assignAPIs(header, table, [ { fn: (_contextDocument) => @@ -84,15 +87,11 @@ export const ColumnResizing: TableFeature = { _createTable: ( table: Table & Partial, ): void => { - // table.setColumnSizingInfo = (updater) => - // table_setColumnSizingInfo(table, updater) - // table.resetHeaderSizeInfo = (defaultState) => - // table_resetHeaderSizeInfo(table, defaultState) assignAPIs(table, table, [ { - fn: (updater) => table_setColumnSizingInfo(table, updater), + fn: (updater) => table_setcolumnResizing(table, updater), }, { fn: (defaultState) => table_resetHeaderSizeInfo(table, defaultState), 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 fe5f2fe69e..a3ab828eb9 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.types.ts @@ -1,17 +1,17 @@ import type { OnChangeFn, Updater } from '../../types/type-utils' export interface TableState_ColumnResizing { - columnSizingInfo: ColumnResizingInfoState + columnResizing: columnResizingState } export interface TableState_ColumnResizing_Unavailable { /** - * @deprecated Import the `ColumnResizingInfoState` feature to use the column resizing information APIs. + * @deprecated Import the `ColumnResizing` feature to use the column resizing APIs. */ - columnSizingInfo: ColumnResizingInfoState + columnResizing: columnResizingState } -export interface ColumnResizingInfoState { +export interface columnResizingState { columnSizingStart: Array<[string, number]> deltaOffset: null | number deltaPercentage: null | number @@ -44,16 +44,16 @@ export interface TableOptions_ColumnResizing { */ columnResizeDirection?: ColumnResizeDirection /** - * If provided, this function will be called with an `updaterFn` when `state.columnSizingInfo` changes. This overrides the default internal state management, so you will also need to supply `state.columnSizingInfo` from your own managed state. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#oncolumnsizinginfochange) + * If provided, this function will be called with an `updaterFn` when `state.columnResizing` changes. This overrides the default internal state management, so you will also need to supply `state.columnResizing` from your own managed state. + * @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) */ - onColumnSizingInfoChange?: OnChangeFn + oncolumnResizingChange?: OnChangeFn } export type ColumnResizingDefaultOptions = Pick< TableOptions_ColumnResizing, - 'columnResizeMode' | 'onColumnSizingInfoChange' | 'columnResizeDirection' + 'columnResizeMode' | 'oncolumnResizingChange' | 'columnResizeDirection' > export interface Table_ColumnResizing { @@ -64,11 +64,11 @@ export interface Table_ColumnResizing { */ resetHeaderSizeInfo: (defaultState?: boolean) => void /** - * Sets the column sizing info state using an updater function or a value. This will trigger the underlying `onColumnSizingInfoChange` function if one is passed to the table options, otherwise the state will be managed automatically by the table. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#setcolumnsizinginfo) + * Sets the column sizing info state using an updater function or a value. This will trigger the underlying `oncolumnResizingChange` function if one is passed to the table options, otherwise the state will be managed automatically by the table. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#setcolumnResizing) * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) */ - setColumnSizingInfo: (updater: Updater) => void + setcolumnResizing: (updater: Updater) => void } export interface ColumnDef_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 88fcc11f56..465da61d01 100644 --- a/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts +++ b/packages/table-core/src/features/column-resizing/ColumnResizing.utils.ts @@ -16,11 +16,11 @@ import type { Column } from '../../types/Column' import type { ColumnSizingState } from '../column-sizing/ColumnSizing.types' import type { ColumnDef_ColumnResizing, - ColumnResizingInfoState, TableOptions_ColumnResizing, + columnResizingState, } from './ColumnResizing.types' -export function getDefaultColumnSizingInfoState(): ColumnResizingInfoState { +export function getDefaultColumnResizingState(): columnResizingState { return structuredClone({ startOffset: null, startSize: null, @@ -61,7 +61,7 @@ export function column_getIsResizing< options: Partial }, ) { - return _table_getState(table).columnSizingInfo?.isResizingColumn === column.id + return _table_getState(table).columnResizing?.isResizingColumn === column.id } export function header_getResizeHandler< @@ -112,7 +112,7 @@ export function header_getResizeHandler< return } - table_setColumnSizingInfo(table, (old) => { + table_setcolumnResizing(table, (old) => { const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1 const deltaOffset = @@ -152,7 +152,7 @@ export function header_getResizeHandler< const onEnd = (clientXPos?: number) => { updateOffset('end', clientXPos) - table_setColumnSizingInfo(table, (old) => ({ + table_setcolumnResizing(table, (old) => ({ ...old, isResizingColumn: false, startOffset: null, @@ -229,7 +229,7 @@ export function header_getResizeHandler< ) } - table_setColumnSizingInfo(table, (old) => ({ + table_setcolumnResizing(table, (old) => ({ ...old, startOffset: clientX, startSize, @@ -241,16 +241,16 @@ export function header_getResizeHandler< } } -export function table_setColumnSizingInfo< +export function table_setcolumnResizing< TFeatures extends TableFeatures, TData extends RowData, >( table: Table & { options: Partial }, - updater: Updater, + updater: Updater, ) { - table.options.onColumnSizingInfoChange?.(updater) + table.options.oncolumnResizingChange?.(updater) } export function table_resetHeaderSizeInfo< @@ -262,12 +262,12 @@ export function table_resetHeaderSizeInfo< }, defaultState?: boolean, ) { - table_setColumnSizingInfo( + table_setcolumnResizing( table, defaultState - ? getDefaultColumnSizingInfoState() - : _table_getInitialState(table).columnSizingInfo ?? - getDefaultColumnSizingInfoState(), + ? getDefaultColumnResizingState() + : _table_getInitialState(table).columnResizing ?? + getDefaultColumnResizingState(), ) } diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.ts index fe44404c6b..4bd9393f41 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.ts @@ -16,6 +16,7 @@ import { table_resetColumnSizing, table_setColumnSizing, } from './ColumnSizing.utils' +import type { TableState } from '../../types/TableState' import type { ColumnDef_ColumnSizing, ColumnSizingDefaultOptions, @@ -38,7 +39,9 @@ import type { Column } from '../../types/Column' * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) */ export const ColumnSizing: TableFeature = { - _getInitialState: (state): TableState_ColumnSizing => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnSizing => { return { columnSizing: {}, ...state, diff --git a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts index a79e79feeb..589cedf9eb 100644 --- a/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts +++ b/packages/table-core/src/features/column-sizing/ColumnSizing.types.ts @@ -7,7 +7,7 @@ export interface TableState_ColumnSizing { export interface TableState_ColumnSizing_Unavailable { /** - * @deprecated Import the `ColumnSizingState` feature to use the column sizing APIs. + * @deprecated Import the `ColumnSizing` feature to use the column sizing APIs. */ columnSizing: ColumnSizingState } diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.ts index 361b813ec6..bc276f4a7b 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.ts @@ -22,6 +22,7 @@ import { table_setColumnVisibility, table_toggleAllColumnsVisible, } from './ColumnVisibility.utils' +import type { TableState } from '../../types/TableState' import type { CellData, RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -40,7 +41,9 @@ import type { * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-visibility) */ export const ColumnVisibility: TableFeature = { - _getInitialState: (state): TableState_ColumnVisibility => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_ColumnVisibility => { return { columnVisibility: {}, ...state, diff --git a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts index 52ccbcf523..3e0a29fdb2 100644 --- a/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts +++ b/packages/table-core/src/features/column-visibility/ColumnVisibility.types.ts @@ -11,7 +11,7 @@ export interface TableState_ColumnVisibility { export interface TableState_ColumnVisibility_Unavailable { /** - * @deprecated Import the `ColumnVisibilityState` feature to use the column visibility APIs. + * @deprecated Import the `ColumnVisibility` feature to use the column visibility APIs. */ columnVisibility: ColumnVisibilityState } diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.ts index 5cba33f5d6..be928bf17c 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.ts @@ -28,9 +28,8 @@ import type { */ export const GlobalFiltering: TableFeature = { _getInitialState: ( - state: Partial> & - Partial = {}, - ): TableState_GlobalFiltering => { + state: TableState, + ): TableState & TableState_GlobalFiltering => { return { globalFilter: undefined, ...state, diff --git a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts index efadbbfe27..d20db859b9 100644 --- a/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts +++ b/packages/table-core/src/features/global-filtering/GlobalFiltering.types.ts @@ -17,7 +17,7 @@ export interface TableState_GlobalFiltering { export interface TableState_GlobalFiltering_Unavailable { /** - * @deprecated Import the `GlobalFilteringState` feature to use the global filtering APIs. + * @deprecated Import the `GlobalFiltering` feature to use the global filtering APIs. */ globalFilter: any } diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.ts b/packages/table-core/src/features/row-expanding/RowExpanding.ts index 77e9afb902..0f8c7505ed 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.ts @@ -17,6 +17,7 @@ import { table_setExpanded, table_toggleAllRowsExpanded, } from './RowExpanding.utils' +import type { TableState } from '../../types/TableState' import type { RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -34,7 +35,9 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-expanding) */ export const RowExpanding: TableFeature = { - _getInitialState: (state): TableState_RowExpanding => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_RowExpanding => { return { expanded: {}, ...state, @@ -56,16 +59,7 @@ export const RowExpanding: TableFeature = { table: Table & Partial>, ): void => { - // row.toggleExpanded = (expanded) => row_toggleExpanded(row, table, expanded) - // row.getIsExpanded = () => row_getIsExpanded(row, table) - - // row.getCanExpand = () => row_getCanExpand(row, table) - - // row.getIsAllParentsExpanded = () => row_getIsAllParentsExpanded(row, table) - - // row.getToggleExpandedHandler = () => - // row_getToggleExpandedHandler(row, table) assignAPIs(row, table, [ { @@ -90,31 +84,7 @@ export const RowExpanding: TableFeature = { table: Table & Partial>, ): void => { - // table.autoResetExpanded = () => - // table_autoResetExpanded(table) - - // table.setExpanded = (updater) => table_setExpanded(table, updater) - - // table.toggleAllRowsExpanded = (expanded) => - // table_toggleAllRowsExpanded(table, expanded) - - // table.resetExpanded = (defaultState) => - // table_resetExpanded(table, defaultState) - - // table.getCanSomeRowsExpand = () => table_getCanSomeRowsExpand(table) - - // table.getToggleAllRowsExpandedHandler = () => - // table_getToggleAllRowsExpandedHandler(table) - - // table.getIsSomeRowsExpanded = () => table_getIsSomeRowsExpanded(table) - - // table.getIsAllRowsExpanded = () => table_getIsAllRowsExpanded(table) - - // table.getExpandedDepth = () => table_getExpandedDepth(table) - - // table.getPreExpandedRowModel = () => table_getPreExpandedRowModel(table) - // table.getExpandedRowModel = () => table_getExpandedRowModel(table) assignAPIs(table, table, [ { diff --git a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts index 527e517c2a..db6f44c2c7 100644 --- a/packages/table-core/src/features/row-expanding/RowExpanding.types.ts +++ b/packages/table-core/src/features/row-expanding/RowExpanding.types.ts @@ -12,7 +12,7 @@ export interface TableState_RowExpanding { export interface TableState_RowExpanding_Unavailable { /** - * @deprecated Import the `ExpandedState` feature to use the row expansion APIs. + * @deprecated Import the `RowExpanding` feature to use the row expansion APIs. */ expanded: ExpandedState } diff --git a/packages/table-core/src/features/row-pagination/RowPagination.ts b/packages/table-core/src/features/row-pagination/RowPagination.ts index 712e7a714d..3dad67bb53 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.ts @@ -20,6 +20,7 @@ import { table_setPageSize, table_setPagination, } from './RowPagination.utils' +import type { TableState } from '../../types/TableState' import type { PaginationDefaultOptions, TableState_RowPagination, @@ -35,12 +36,14 @@ import type { Table } from '../../types/Table' * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination) */ export const RowPagination: TableFeature = { - _getInitialState: (state): TableState_RowPagination => { + _getInitialState: ( + state: TableState & Partial, + ): TableState & TableState_RowPagination => { return { ...state, pagination: { ...getDefaultPaginationState(), - ...state?.pagination, + ...state.pagination, }, } }, @@ -58,49 +61,7 @@ export const RowPagination: TableFeature = { table: Table & Partial>, ): void => { - // table.autoResetPageIndex = () => - // table_autoResetPageIndex(table) - // table.setPagination = (updater) => table_setPagination(table, updater) - - // table.resetPagination = (defaultState) => - // table_resetPagination(table, defaultState) - - // table.setPageIndex = (updater) => table_setPageIndex(table, updater) - - // table.resetPageIndex = (defaultState) => - // table_resetPageIndex(table, defaultState) - - // table.resetPageSize = (defaultState) => - // table_resetPageSize(table, defaultState) - - // table.setPageSize = (updater) => table_setPageSize(table, updater) - - // table.getPageOptions = memo( - // () => [table_getPageCount(table)], - // () => table_getPageOptions(table), - // getMemoOptions(table.options, 'debugTable', 'getPageOptions'), - // ) - - // table.getCanPreviousPage = () => table_getCanPreviousPage(table) - - // table.getCanNextPage = () => table_getCanNextPage(table) - - // table.previousPage = () => table_previousPage(table) - - // table.nextPage = () => table_nextPage(table) - - // table.firstPage = () => table_firstPage(table) - - // table.lastPage = () => table_lastPage(table) - - // table.getPrePaginationRowModel = () => table_getPrePaginationRowModel(table) - - // table.getPaginatedRowModel = () => table_getPaginatedRowModel(table) - - // table.getPageCount = () => table_getPageCount(table) - - // table.getRowCount = () => table_getRowCount(table) assignAPIs(table, table, [ { diff --git a/packages/table-core/src/features/row-pagination/RowPagination.types.ts b/packages/table-core/src/features/row-pagination/RowPagination.types.ts index b343748ddd..446c6b1d4c 100644 --- a/packages/table-core/src/features/row-pagination/RowPagination.types.ts +++ b/packages/table-core/src/features/row-pagination/RowPagination.types.ts @@ -12,7 +12,7 @@ export interface TableState_RowPagination { } export interface TableState_RowPagination_Unavailable { /** - * @deprecated Import the `PaginationState` feature to use the row pagination APIs. + * @deprecated Import the `RowPagination` feature to use the row pagination APIs. */ pagination: PaginationState } diff --git a/packages/table-core/src/features/row-pinning/RowPinning.ts b/packages/table-core/src/features/row-pinning/RowPinning.ts index 549d7d0463..159b6cfd81 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.ts @@ -13,6 +13,7 @@ import { table_resetRowPinning, table_setRowPinning, } from './RowPinning.utils' +import type { TableState } from '../../types/TableState' import type { RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -30,7 +31,9 @@ import type { * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning) */ export const RowPinning: TableFeature = { - _getInitialState: (state): TableState_RowPinning => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_RowPinning => { return { rowPinning: getDefaultRowPinningState(), ...state, diff --git a/packages/table-core/src/features/row-pinning/RowPinning.types.ts b/packages/table-core/src/features/row-pinning/RowPinning.types.ts index 7a377dd2c3..0fac7aef6f 100644 --- a/packages/table-core/src/features/row-pinning/RowPinning.types.ts +++ b/packages/table-core/src/features/row-pinning/RowPinning.types.ts @@ -16,7 +16,7 @@ export interface TableState_RowPinning { export interface TableState_RowPinning_Unavailable { /** - * @deprecated Import the `RowPinningState` feature to use the row pinning APIs. + * @deprecated Import the `RowPinning` feature to use the row pinning APIs. */ rowPinning: RowPinningState } diff --git a/packages/table-core/src/features/row-selection/RowSelection.ts b/packages/table-core/src/features/row-selection/RowSelection.ts index c8ebf23e1c..e451ff8696 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.ts @@ -26,6 +26,7 @@ import { table_toggleAllPageRowsSelected, table_toggleAllRowsSelected, } from './RowSelection.utils' +import type { TableState } from '../../types/TableState' import type { RowData } from '../../types/type-utils' import type { TableFeature, TableFeatures } from '../../types/TableFeatures' import type { Table } from '../../types/Table' @@ -44,7 +45,9 @@ import type { */ export const RowSelection: TableFeature = { - _getInitialState: (state): TableState_RowSelection => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_RowSelection => { return { rowSelection: {}, ...state, @@ -71,23 +74,7 @@ export const RowSelection: TableFeature = { table: Table & Partial>, ): void => { - // row.toggleSelected = (value, opts) => - // row_toggleSelected(row, table, value, opts) - // row.getIsSelected = () => row_getIsSelected(row, table) - - // row.getIsSomeSelected = () => row_getIsSomeSelected(row, table) - - // row.getIsAllSubRowsSelected = () => row_getIsAllSubRowsSelected(row, table) - - // row.getCanSelect = () => row_getCanSelect(row, table) - - // row.getCanSelectSubRows = () => row_getCanSelectSubRows(row, table) - - // row.getCanMultiSelect = () => row_getCanMultiSelect(row, table) - - // row.getToggleSelectedHandler = () => - // row_getToggleSelectedHandler(row, table) assignAPIs(row, table, [ { @@ -121,61 +108,7 @@ export const RowSelection: TableFeature = { table: Table & Partial>, ): void => { - // table.setRowSelection = (updater) => table_setRowSelection(table, updater) - - // table.resetRowSelection = (defaultState) => - // table_resetRowSelection(table, defaultState) - - // table.toggleAllRowsSelected = (value) => - // table_toggleAllRowsSelected(table, value) - - // table.toggleAllPageRowsSelected = (value) => - // table_toggleAllPageRowsSelected(table, value) - - // table.getPreSelectedRowModel = () => table_getPreSelectedRowModel(table) - - // table.getSelectedRowModel = memo( - // () => [_table_getState(table).rowSelection, table.getCoreRowModel()], - // () => table_getSelectedRowModel(table), - // getMemoOptions(table.options, 'debugTable', 'getSelectedRowModel'), - // ) - - // table.getFilteredSelectedRowModel = memo( - // () => [ - // _table_getState(table).rowSelection, - // table_getFilteredRowModel(table), - // ], - // () => table_getFilteredSelectedRowModel(table), - // getMemoOptions( - // table.options, - // 'debugTable', - // 'getFilteredSelectedRowModel', - // ), - // ) - - // table.getGroupedSelectedRowModel = memo( - // () => [ - // _table_getState(table).rowSelection, - // table_getSortedRowModel(table), - // ], - // () => table_getGroupedSelectedRowModel(table), - // getMemoOptions(table.options, 'debugTable', 'getGroupedSelectedRowModel'), - // ) - - // table.getIsAllRowsSelected = () => table_getIsAllRowsSelected(table) - - // table.getIsAllPageRowsSelected = () => table_getIsAllPageRowsSelected(table) - - // table.getIsSomeRowsSelected = () => table_getIsSomeRowsSelected(table) - - // table.getIsSomePageRowsSelected = () => - // table_getIsSomePageRowsSelected(table) - - // table.getToggleAllRowsSelectedHandler = () => - // table_getToggleAllRowsSelectedHandler(table) - // table.getToggleAllPageRowsSelectedHandler = () => - // table_getToggleAllPageRowsSelectedHandler(table) assignAPIs(table, table, [ { diff --git a/packages/table-core/src/features/row-selection/RowSelection.types.ts b/packages/table-core/src/features/row-selection/RowSelection.types.ts index 55c21e4071..f7249bb9c2 100644 --- a/packages/table-core/src/features/row-selection/RowSelection.types.ts +++ b/packages/table-core/src/features/row-selection/RowSelection.types.ts @@ -11,7 +11,7 @@ export interface TableState_RowSelection { export interface TableState_RowSelection_Unavailable { /** - * @deprecated Import the `RowSelectionState` feature to use the row selection APIs. + * @deprecated Import the `RowSelection` feature to use the row selection APIs. */ rowSelection: RowSelectionState } diff --git a/packages/table-core/src/features/row-sorting/RowSorting.ts b/packages/table-core/src/features/row-sorting/RowSorting.ts index 1545b26968..cb1ac6ce3c 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.ts @@ -17,6 +17,7 @@ import { table_resetSorting, table_setSorting, } from './RowSorting.utils' +import type { TableState } from '../../types/TableState' import type { ColumnDef_RowSorting, Column_RowSorting, @@ -35,7 +36,9 @@ import type { Column } from '../../types/Column' * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting) */ export const RowSorting: TableFeature = { - _getInitialState: (state): TableState_RowSorting => { + _getInitialState: ( + state: TableState, + ): TableState & TableState_RowSorting => { return { sorting: [], ...state, @@ -74,32 +77,7 @@ export const RowSorting: TableFeature = { table: Table & Partial>, ): void => { - // column.getAutoSortingFn = () => column_getAutoSortingFn(column, table) - // column.getAutoSortDir = () => column_getAutoSortDir(column, table) - - // column.getSortingFn = () => column_getSortingFn(column, table) - - // column.toggleSorting = (desc, multi) => - // column_toggleSorting(column, table, desc, multi) - - // column.getFirstSortDir = () => column_getFirstSortDir(column, table) - - // column.getNextSortingOrder = (multi?: boolean) => - // column_getNextSortingOrder(column, table, multi) - - // column.getCanSort = () => column_getCanSort(column, table) - - // column.getCanMultiSort = () => column_getCanMultiSort(column, table) - - // column.getIsSorted = () => column_getIsSorted(column, table) - - // column.getSortIndex = () => column_getSortIndex(column, table) - - // column.clearSorting = () => column_clearSorting(column, table) - - // column.getToggleSortingHandler = () => - // column_getToggleSortingHandler(column, table) assignAPIs(column, table, [ { @@ -145,14 +123,7 @@ export const RowSorting: TableFeature = { table: Table & Partial>, ): void => { - // table.setSorting = (updater) => table_setSorting(table, updater) - - // table.resetSorting = (defaultState) => - // table_resetSorting(table, defaultState) - - // table.getPreSortedRowModel = () => table_getPreSortedRowModel(table) - // table.getSortedRowModel = () => table_getSortedRowModel(table) assignAPIs(table, table, [ { diff --git a/packages/table-core/src/features/row-sorting/RowSorting.types.ts b/packages/table-core/src/features/row-sorting/RowSorting.types.ts index fdc315509e..1e1bff5135 100644 --- a/packages/table-core/src/features/row-sorting/RowSorting.types.ts +++ b/packages/table-core/src/features/row-sorting/RowSorting.types.ts @@ -23,7 +23,7 @@ export interface TableState_RowSorting { export interface TableState_RowSorting_Unavailable { /** - * @deprecated Import the `SortingState` feature to use the row sorting APIs. + * @deprecated Import the `RowSorting` feature to use the row sorting APIs. */ sorting: SortingState } diff --git a/packages/table-core/src/types/TableFeatures.ts b/packages/table-core/src/types/TableFeatures.ts index 3a0f018c70..4d76f1a8ab 100644 --- a/packages/table-core/src/types/TableFeatures.ts +++ b/packages/table-core/src/types/TableFeatures.ts @@ -49,7 +49,7 @@ export interface TableFeature { table: Table, ) => Partial> _getInitialState?: ( - initialState?: Partial>, + initialState: TableState, ) => Partial> } diff --git a/packages/table-core/src/types/TableOptions.ts b/packages/table-core/src/types/TableOptions.ts index 5feeaa41d3..3e0ab42cf8 100644 --- a/packages/table-core/src/types/TableOptions.ts +++ b/packages/table-core/src/types/TableOptions.ts @@ -3,22 +3,10 @@ import type { TableOptions_Columns } from '../core/columns/Columns.types' import type { TableOptions_Headers } from '../core/headers/Headers.types' import type { TableOptions_Rows } from '../core/rows/Rows.types' import type { TableOptions_Table } from '../core/table/Tables.types' -import type { - TableOptions_ColumnFiltering, - TableOptions_ColumnFiltering_Unavailable, -} from '../features/column-filtering/ColumnFiltering.types' -import type { - TableOptions_ColumnGrouping, - TableOptions_ColumnGrouping_Unavailable, -} from '../features/column-grouping/ColumnGrouping.types' -import type { - TableOptions_ColumnOrdering, - TableOptions_ColumnOrdering_Unavailable, -} from '../features/column-ordering/ColumnOrdering.types' -import type { - TableOptions_ColumnPinning, - TableOptions_ColumnPinning_Unavailable, -} from '../features/column-pinning/ColumnPinning.types' +import type { TableOptions_ColumnFiltering } from '../features/column-filtering/ColumnFiltering.types' +import type { TableOptions_ColumnGrouping } from '../features/column-grouping/ColumnGrouping.types' +import type { TableOptions_ColumnOrdering } from '../features/column-ordering/ColumnOrdering.types' +import type { TableOptions_ColumnPinning } from '../features/column-pinning/ColumnPinning.types' import type { TableOptions_ColumnResizing } from '../features/column-resizing/ColumnResizing.types' import type { TableOptions_ColumnSizing } from '../features/column-sizing/ColumnSizing.types' import type { TableOptions_ColumnVisibility } from '../features/column-visibility/ColumnVisibility.types' @@ -47,16 +35,16 @@ export type TableOptions< UnionToIntersection< | ('ColumnFiltering' extends keyof TFeatures ? TableOptions_ColumnFiltering - : TableOptions_ColumnFiltering_Unavailable) + : never) | ('ColumnGrouping' extends keyof TFeatures ? TableOptions_ColumnGrouping - : TableOptions_ColumnGrouping_Unavailable) + : never) | ('ColumnOrdering' extends keyof TFeatures ? TableOptions_ColumnOrdering - : TableOptions_ColumnOrdering_Unavailable) + : never) | ('ColumnPinning' extends keyof TFeatures ? TableOptions_ColumnPinning - : TableOptions_ColumnPinning_Unavailable) + : never) | ('ColumnResizing' extends keyof TFeatures ? TableOptions_ColumnResizing : never) diff --git a/packages/table-core/src/types/TableState.ts b/packages/table-core/src/types/TableState.ts index 5b7f5de21e..0a745e1d60 100644 --- a/packages/table-core/src/types/TableState.ts +++ b/packages/table-core/src/types/TableState.ts @@ -53,44 +53,46 @@ import type { import type { UnionToIntersection } from './type-utils' import type { TableFeatures } from './TableFeatures' -export type TableState = UnionToIntersection< +export type TableState = { + _: never +} & UnionToIntersection< | ('ColumnFiltering' extends keyof TFeatures ? TableState_ColumnFiltering - : TableState_ColumnFiltering_Unavailable) + : Partial) | ('ColumnGrouping' extends keyof TFeatures ? TableState_ColumnGrouping - : TableState_ColumnGrouping_Unavailable) + : Partial) | ('ColumnOrdering' extends keyof TFeatures ? TableState_ColumnOrdering - : TableState_ColumnOrdering_Unavailable) + : Partial) | ('ColumnPinning' extends keyof TFeatures ? TableState_ColumnPinning - : TableState_ColumnPinning_Unavailable) + : Partial) | ('ColumnResizing' extends keyof TFeatures ? TableState_ColumnResizing - : TableState_ColumnResizing_Unavailable) + : Partial) | ('ColumnSizing' extends keyof TFeatures ? TableState_ColumnSizing - : TableState_ColumnSizing_Unavailable) + : Partial) | ('ColumnVisibility' extends keyof TFeatures ? TableState_ColumnVisibility - : TableState_ColumnVisibility_Unavailable) + : Partial) | ('GlobalFiltering' extends keyof TFeatures ? TableState_GlobalFiltering - : TableState_GlobalFiltering_Unavailable) + : Partial) | ('RowExpanding' extends keyof TFeatures ? TableState_RowExpanding - : TableState_RowExpanding_Unavailable) + : Partial) | ('RowPagination' extends keyof TFeatures ? TableState_RowPagination - : TableState_RowPagination_Unavailable) + : Partial) | ('RowPinning' extends keyof TFeatures ? TableState_RowPinning - : TableState_RowPinning_Unavailable) + : Partial) | ('RowSelection' extends keyof TFeatures ? TableState_RowSelection - : TableState_RowSelection_Unavailable) + : Partial) | ('RowSorting' extends keyof TFeatures ? TableState_RowSorting - : TableState_RowSorting_Unavailable) + : Partial) >