@tanstack/react-table 9.0.0-alpha.40 → 9.0.0-alpha.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useLegacyTable.cjs +21 -22
- package/dist/useLegacyTable.cjs.map +1 -1
- package/dist/useLegacyTable.js +22 -23
- package/dist/useLegacyTable.js.map +1 -1
- package/dist/useTable.cjs +17 -7
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.js +18 -8
- package/dist/useTable.js.map +1 -1
- package/package.json +3 -3
- package/src/useLegacyTable.ts +51 -53
- package/src/useTable.ts +23 -16
package/dist/useLegacyTable.cjs
CHANGED
|
@@ -132,35 +132,34 @@ function legacyCreateColumnHelper() {
|
|
|
132
132
|
*/
|
|
133
133
|
function useLegacyTable(options) {
|
|
134
134
|
const { getCoreRowModel: _getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, getExpandedRowModel, getGroupedRowModel, getFacetedRowModel, getFacetedMinMaxValues, getFacetedUniqueValues, ...restOptions } = options;
|
|
135
|
-
const _rowModels = {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
const [_rowModels] = (0, react.useState)(() => {
|
|
136
|
+
const rowModels = {};
|
|
137
|
+
if (getFilteredRowModel) rowModels.filteredRowModel = (0, _tanstack_table_core.createFilteredRowModel)({
|
|
138
|
+
..._tanstack_table_core.filterFns,
|
|
139
|
+
...options.filterFns
|
|
140
|
+
});
|
|
141
|
+
if (getSortedRowModel) rowModels.sortedRowModel = (0, _tanstack_table_core.createSortedRowModel)({
|
|
142
|
+
..._tanstack_table_core.sortFns,
|
|
143
|
+
...options.sortFns
|
|
144
|
+
});
|
|
145
|
+
if (getPaginationRowModel) rowModels.paginatedRowModel = (0, _tanstack_table_core.createPaginatedRowModel)();
|
|
146
|
+
if (getExpandedRowModel) rowModels.expandedRowModel = (0, _tanstack_table_core.createExpandedRowModel)();
|
|
147
|
+
if (getGroupedRowModel) rowModels.groupedRowModel = (0, _tanstack_table_core.createGroupedRowModel)({
|
|
148
|
+
..._tanstack_table_core.aggregationFns,
|
|
149
|
+
...options.aggregationFns
|
|
150
|
+
});
|
|
151
|
+
if (getFacetedRowModel) rowModels.facetedRowModel = (0, _tanstack_table_core.createFacetedRowModel)();
|
|
152
|
+
if (getFacetedMinMaxValues) rowModels.facetedMinMaxValues = (0, _tanstack_table_core.createFacetedMinMaxValues)();
|
|
153
|
+
if (getFacetedUniqueValues) rowModels.facetedUniqueValues = (0, _tanstack_table_core.createFacetedUniqueValues)();
|
|
154
|
+
return rowModels;
|
|
149
155
|
});
|
|
150
|
-
if (getFacetedRowModel) _rowModels.facetedRowModel = (0, _tanstack_table_core.createFacetedRowModel)();
|
|
151
|
-
if (getFacetedMinMaxValues) _rowModels.facetedMinMaxValues = (0, _tanstack_table_core.createFacetedMinMaxValues)();
|
|
152
|
-
if (getFacetedUniqueValues) _rowModels.facetedUniqueValues = (0, _tanstack_table_core.createFacetedUniqueValues)();
|
|
153
156
|
const table = require_useTable.useTable({
|
|
154
157
|
...restOptions,
|
|
155
158
|
_features: _tanstack_table_core.stockFeatures,
|
|
156
159
|
_rowModels
|
|
157
160
|
}, (state) => state);
|
|
158
161
|
const getState = (0, react.useCallback)(() => {
|
|
159
|
-
return
|
|
160
|
-
...table.state,
|
|
161
|
-
columns: void 0,
|
|
162
|
-
data: void 0
|
|
163
|
-
};
|
|
162
|
+
return table.state;
|
|
164
163
|
}, [table]);
|
|
165
164
|
const setState = (0, react.useCallback)((state) => {
|
|
166
165
|
Object.entries(state).forEach(([key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLegacyTable.cjs","names":["filterFns","sortFns","aggregationFns","useTable","stockFeatures"],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return () => () => undefined\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return () => () => new Map()\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\nexport type RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\nexport type FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\nexport type FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\nexport type FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n // Build the _rowModels object based on which legacy options were provided\n const _rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Map v8 row model factories to v9 _rowModels\n // Note: getCoreRowModel is handled automatically in v9, so we ignore it\n\n if (getFilteredRowModel) {\n _rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n _rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n _rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n _rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n _rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n _rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n _rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n },\n (state) => state,\n )\n\n const getState = useCallback(() => {\n // all state except for columns and data\n return {\n ...table.state,\n columns: undefined,\n data: undefined,\n }\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () => ({\n ...table,\n getState,\n setState,\n }),\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,oBAAmB;;;;;;;;AASrB,SAAgB,yBAEuB;AACrC,oCAAmB,IAAI,KAAK;;;;;;;;AAS9B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,sDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAGJ,MAAM,aAAwD,EAAE;AAKhE,KAAI,oBACF,YAAW,oEAA0C;EACnD,GAAGA;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,kBACF,YAAW,gEAAsC;EAC/C,GAAGC;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,sBACF,YAAW,uEAA6C;AAG1D,KAAI,oBACF,YAAW,qEAA2C;AAGxD,KAAI,mBACF,YAAW,kEAAwC;EACjD,GAAGC;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,mBACF,YAAW,mEAAyC;AAGtD,KAAI,uBACF,YAAW,2EAAiD;AAG9D,KAAI,uBACF,YAAW,2EAAiD;CAI9D,MAAM,QAAQC,0BACZ;EACE,GAAG;EACH,WAAWC;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,wCAA6B;AAEjC,SAAO;GACL,GAAG,MAAM;GACT,SAAS;GACT,MAAM;GACP;IACA,CAAC,MAAM,CAAC;CAEX,MAAM,mCACH,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,kCACS;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAU;EAAS,CAC5B"}
|
|
1
|
+
{"version":3,"file":"useLegacyTable.cjs","names":["filterFns","sortFns","aggregationFns","useTable","stockFeatures"],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return () => () => undefined\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return () => () => new Map()\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\nexport type RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\nexport type FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\nexport type FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\nexport type FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n const [_rowModels] = useState(() => {\n const rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Legacy row model options are setup-only. Capture the first render's\n // marker options to match the table instance lifecycle.\n\n if (getFilteredRowModel) {\n rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n return rowModels\n })\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n },\n (state) => state,\n )\n\n const getState = useCallback(() => {\n return table.state\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () => ({\n ...table,\n getState,\n setState,\n }),\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,oBAAmB;;;;;;;;AASrB,SAAgB,yBAEuB;AACrC,oCAAmB,IAAI,KAAK;;;;;;;;AAS9B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,sDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAEJ,MAAM,CAAC,wCAA6B;EAClC,MAAM,YAAuD,EAAE;AAK/D,MAAI,oBACF,WAAU,oEAA0C;GAClD,GAAGA;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,kBACF,WAAU,gEAAsC;GAC9C,GAAGC;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,sBACF,WAAU,uEAA6C;AAGzD,MAAI,oBACF,WAAU,qEAA2C;AAGvD,MAAI,mBACF,WAAU,kEAAwC;GAChD,GAAGC;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,mBACF,WAAU,mEAAyC;AAGrD,MAAI,uBACF,WAAU,2EAAiD;AAG7D,MAAI,uBACF,WAAU,2EAAiD;AAG7D,SAAO;GACP;CAGF,MAAM,QAAQC,0BACZ;EACE,GAAG;EACH,WAAWC;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,wCAA6B;AACjC,SAAO,MAAM;IACZ,CAAC,MAAM,CAAC;CAEX,MAAM,mCACH,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,kCACS;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAU;EAAS,CAC5B"}
|
package/dist/useLegacyTable.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useTable } from "./useTable.js";
|
|
4
4
|
import { aggregationFns, createColumnHelper, createExpandedRowModel, createFacetedMinMaxValues, createFacetedRowModel, createFacetedUniqueValues, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, filterFns, sortFns, stockFeatures } from "@tanstack/table-core";
|
|
5
|
-
import { useCallback, useMemo } from "react";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
6
6
|
|
|
7
7
|
//#region src/useLegacyTable.ts
|
|
8
8
|
/**
|
|
@@ -131,35 +131,34 @@ function legacyCreateColumnHelper() {
|
|
|
131
131
|
*/
|
|
132
132
|
function useLegacyTable(options) {
|
|
133
133
|
const { getCoreRowModel: _getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, getExpandedRowModel, getGroupedRowModel, getFacetedRowModel, getFacetedMinMaxValues, getFacetedUniqueValues, ...restOptions } = options;
|
|
134
|
-
const _rowModels = {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
134
|
+
const [_rowModels] = useState(() => {
|
|
135
|
+
const rowModels = {};
|
|
136
|
+
if (getFilteredRowModel) rowModels.filteredRowModel = createFilteredRowModel({
|
|
137
|
+
...filterFns,
|
|
138
|
+
...options.filterFns
|
|
139
|
+
});
|
|
140
|
+
if (getSortedRowModel) rowModels.sortedRowModel = createSortedRowModel({
|
|
141
|
+
...sortFns,
|
|
142
|
+
...options.sortFns
|
|
143
|
+
});
|
|
144
|
+
if (getPaginationRowModel) rowModels.paginatedRowModel = createPaginatedRowModel();
|
|
145
|
+
if (getExpandedRowModel) rowModels.expandedRowModel = createExpandedRowModel();
|
|
146
|
+
if (getGroupedRowModel) rowModels.groupedRowModel = createGroupedRowModel({
|
|
147
|
+
...aggregationFns,
|
|
148
|
+
...options.aggregationFns
|
|
149
|
+
});
|
|
150
|
+
if (getFacetedRowModel) rowModels.facetedRowModel = createFacetedRowModel();
|
|
151
|
+
if (getFacetedMinMaxValues) rowModels.facetedMinMaxValues = createFacetedMinMaxValues();
|
|
152
|
+
if (getFacetedUniqueValues) rowModels.facetedUniqueValues = createFacetedUniqueValues();
|
|
153
|
+
return rowModels;
|
|
148
154
|
});
|
|
149
|
-
if (getFacetedRowModel) _rowModels.facetedRowModel = createFacetedRowModel();
|
|
150
|
-
if (getFacetedMinMaxValues) _rowModels.facetedMinMaxValues = createFacetedMinMaxValues();
|
|
151
|
-
if (getFacetedUniqueValues) _rowModels.facetedUniqueValues = createFacetedUniqueValues();
|
|
152
155
|
const table = useTable({
|
|
153
156
|
...restOptions,
|
|
154
157
|
_features: stockFeatures,
|
|
155
158
|
_rowModels
|
|
156
159
|
}, (state) => state);
|
|
157
160
|
const getState = useCallback(() => {
|
|
158
|
-
return
|
|
159
|
-
...table.state,
|
|
160
|
-
columns: void 0,
|
|
161
|
-
data: void 0
|
|
162
|
-
};
|
|
161
|
+
return table.state;
|
|
163
162
|
}, [table]);
|
|
164
163
|
const setState = useCallback((state) => {
|
|
165
164
|
Object.entries(state).forEach(([key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLegacyTable.js","names":[],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return () => () => undefined\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return () => () => new Map()\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\nexport type RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\nexport type FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\nexport type FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\nexport type FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n // Build the _rowModels object based on which legacy options were provided\n const _rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Map v8 row model factories to v9 _rowModels\n // Note: getCoreRowModel is handled automatically in v9, so we ignore it\n\n if (getFilteredRowModel) {\n _rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n _rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n _rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n _rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n _rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n _rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n _rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n },\n (state) => state,\n )\n\n const getState = useCallback(() => {\n // all state except for columns and data\n return {\n ...table.state,\n columns: undefined,\n data: undefined,\n }\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () => ({\n ...table,\n getState,\n setState,\n }),\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,oBAAmB;;;;;;;;AASrB,SAAgB,yBAEuB;AACrC,oCAAmB,IAAI,KAAK;;;;;;;;AAS9B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,QAAO,oBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAGJ,MAAM,aAAwD,EAAE;AAKhE,KAAI,oBACF,YAAW,mBAAmB,uBAAuB;EACnD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,kBACF,YAAW,iBAAiB,qBAAqB;EAC/C,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,sBACF,YAAW,oBAAoB,yBAAyB;AAG1D,KAAI,oBACF,YAAW,mBAAmB,wBAAwB;AAGxD,KAAI,mBACF,YAAW,kBAAkB,sBAAsB;EACjD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,mBACF,YAAW,kBAAkB,uBAAuB;AAGtD,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;AAG9D,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;CAI9D,MAAM,QAAQ,SACZ;EACE,GAAG;EACH,WAAW;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,WAAW,kBAAkB;AAEjC,SAAO;GACL,GAAG,MAAM;GACT,SAAS;GACT,MAAM;GACP;IACA,CAAC,MAAM,CAAC;CAEX,MAAM,WAAW,aACd,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,QAAO,eACE;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAU;EAAS,CAC5B"}
|
|
1
|
+
{"version":3,"file":"useLegacyTable.js","names":[],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return () => () => undefined\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return () => () => new Map()\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\nexport type RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\nexport type FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\nexport type FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\nexport type FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n const [_rowModels] = useState(() => {\n const rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Legacy row model options are setup-only. Capture the first render's\n // marker options to match the table instance lifecycle.\n\n if (getFilteredRowModel) {\n rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n return rowModels\n })\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n },\n (state) => state,\n )\n\n const getState = useCallback(() => {\n return table.state\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () => ({\n ...table,\n getState,\n setState,\n }),\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,oBAAmB;;;;;;;;AASrB,SAAgB,yBAEuB;AACrC,oCAAmB,IAAI,KAAK;;;;;;;;AAS9B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,QAAO,oBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAEJ,MAAM,CAAC,cAAc,eAAe;EAClC,MAAM,YAAuD,EAAE;AAK/D,MAAI,oBACF,WAAU,mBAAmB,uBAAuB;GAClD,GAAG;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,kBACF,WAAU,iBAAiB,qBAAqB;GAC9C,GAAG;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,sBACF,WAAU,oBAAoB,yBAAyB;AAGzD,MAAI,oBACF,WAAU,mBAAmB,wBAAwB;AAGvD,MAAI,mBACF,WAAU,kBAAkB,sBAAsB;GAChD,GAAG;GACH,GAAG,QAAQ;GACZ,CAAC;AAGJ,MAAI,mBACF,WAAU,kBAAkB,uBAAuB;AAGrD,MAAI,uBACF,WAAU,sBAAsB,2BAA2B;AAG7D,MAAI,uBACF,WAAU,sBAAsB,2BAA2B;AAG7D,SAAO;GACP;CAGF,MAAM,QAAQ,SACZ;EACE,GAAG;EACH,WAAW;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,WAAW,kBAAkB;AACjC,SAAO,MAAM;IACZ,CAAC,MAAM,CAAC;CAEX,MAAM,WAAW,aACd,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,QAAO,eACE;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAU;EAAS,CAC5B"}
|
package/dist/useTable.cjs
CHANGED
|
@@ -6,11 +6,18 @@ const require_Subscribe = require('./Subscribe.cjs');
|
|
|
6
6
|
let _tanstack_table_core = require("@tanstack/table-core");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
let _tanstack_react_store = require("@tanstack/react-store");
|
|
9
|
+
let _tanstack_table_core_reactivity = require("@tanstack/table-core/reactivity");
|
|
9
10
|
|
|
10
11
|
//#region src/useTable.ts
|
|
11
12
|
function useTable(tableOptions, selector = () => ({})) {
|
|
12
13
|
const [table] = (0, react.useState)(() => {
|
|
13
|
-
const tableInstance = (0, _tanstack_table_core.constructTable)(
|
|
14
|
+
const tableInstance = (0, _tanstack_table_core.constructTable)({
|
|
15
|
+
...tableOptions,
|
|
16
|
+
_features: {
|
|
17
|
+
coreReativityFeature: (0, _tanstack_table_core_reactivity.constructReactivityBindings)(),
|
|
18
|
+
...tableOptions._features
|
|
19
|
+
}
|
|
20
|
+
});
|
|
14
21
|
tableInstance.Subscribe = ((props) => {
|
|
15
22
|
return require_Subscribe.Subscribe({
|
|
16
23
|
...props,
|
|
@@ -20,18 +27,21 @@ function useTable(tableOptions, selector = () => ({})) {
|
|
|
20
27
|
tableInstance.FlexRender = require_FlexRender.FlexRender;
|
|
21
28
|
return tableInstance;
|
|
22
29
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
(0, react.useEffect)(() => {
|
|
31
|
+
table.setOptions((prev) => ({
|
|
32
|
+
...prev,
|
|
33
|
+
...tableOptions
|
|
34
|
+
}));
|
|
35
|
+
}, [table, tableOptions]);
|
|
27
36
|
const state = (0, _tanstack_react_store.useSelector)(table.store, selector, { compare: _tanstack_react_store.shallow });
|
|
37
|
+
const options = (0, _tanstack_react_store.useSelector)(table.optionsStore, (options) => options, { compare: _tanstack_react_store.shallow });
|
|
28
38
|
return (0, react.useMemo)(() => ({
|
|
29
39
|
...table,
|
|
30
|
-
options
|
|
40
|
+
options,
|
|
31
41
|
state
|
|
32
42
|
}), [
|
|
33
43
|
table,
|
|
34
|
-
|
|
44
|
+
options,
|
|
35
45
|
state
|
|
36
46
|
]);
|
|
37
47
|
}
|
package/dist/useTable.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport {
|
|
1
|
+
{"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { constructReactivityBindings } from '@tanstack/table-core/reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: constructReactivityBindings(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n useEffect(() => {\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n }, [table, tableOptions])\n\n const state = useSelector(table.store, selector, { compare: shallow })\n const options = useSelector(table.optionsStore, (options) => options, {\n compare: shallow,\n })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options,\n state,\n }),\n [table, options, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;;AAkHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B;GACnC,GAAG;GACH,WAAW;IACT,wFAAmD;IACnD,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAOA,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAEF,4BAAgB;AACd,QAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;GACJ,EAAE;IACF,CAAC,OAAO,aAAa,CAAC;CAEzB,MAAM,+CAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,+BAAS,CAAC;CACtE,MAAM,iDAAsB,MAAM,eAAe,YAAY,SAAS,EACpE,SAASA,+BACV,CAAC;AAIF,kCACS;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAS;EAAM,CACxB"}
|
package/dist/useTable.js
CHANGED
|
@@ -3,13 +3,20 @@
|
|
|
3
3
|
import { FlexRender } from "./FlexRender.js";
|
|
4
4
|
import { Subscribe } from "./Subscribe.js";
|
|
5
5
|
import { constructTable } from "@tanstack/table-core";
|
|
6
|
-
import { useMemo, useState } from "react";
|
|
6
|
+
import { useEffect, useMemo, useState } from "react";
|
|
7
7
|
import { shallow, useSelector } from "@tanstack/react-store";
|
|
8
|
+
import { constructReactivityBindings } from "@tanstack/table-core/reactivity";
|
|
8
9
|
|
|
9
10
|
//#region src/useTable.ts
|
|
10
11
|
function useTable(tableOptions, selector = () => ({})) {
|
|
11
12
|
const [table] = useState(() => {
|
|
12
|
-
const tableInstance = constructTable(
|
|
13
|
+
const tableInstance = constructTable({
|
|
14
|
+
...tableOptions,
|
|
15
|
+
_features: {
|
|
16
|
+
coreReativityFeature: constructReactivityBindings(),
|
|
17
|
+
...tableOptions._features
|
|
18
|
+
}
|
|
19
|
+
});
|
|
13
20
|
tableInstance.Subscribe = ((props) => {
|
|
14
21
|
return Subscribe({
|
|
15
22
|
...props,
|
|
@@ -19,18 +26,21 @@ function useTable(tableOptions, selector = () => ({})) {
|
|
|
19
26
|
tableInstance.FlexRender = FlexRender;
|
|
20
27
|
return tableInstance;
|
|
21
28
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
table.setOptions((prev) => ({
|
|
31
|
+
...prev,
|
|
32
|
+
...tableOptions
|
|
33
|
+
}));
|
|
34
|
+
}, [table, tableOptions]);
|
|
26
35
|
const state = useSelector(table.store, selector, { compare: shallow });
|
|
36
|
+
const options = useSelector(table.optionsStore, (options) => options, { compare: shallow });
|
|
27
37
|
return useMemo(() => ({
|
|
28
38
|
...table,
|
|
29
|
-
options
|
|
39
|
+
options,
|
|
30
40
|
state
|
|
31
41
|
}), [
|
|
32
42
|
table,
|
|
33
|
-
|
|
43
|
+
options,
|
|
34
44
|
state
|
|
35
45
|
]);
|
|
36
46
|
}
|
package/dist/useTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport {
|
|
1
|
+
{"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { constructReactivityBindings } from '@tanstack/table-core/reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: constructReactivityBindings(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n useEffect(() => {\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n }, [table, tableOptions])\n\n const state = useSelector(table.store, selector, { compare: shallow })\n const options = useSelector(table.optionsStore, (options) => options, {\n compare: shallow,\n })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options,\n state,\n }),\n [table, options, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AAkHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe;GACnC,GAAG;GACH,WAAW;IACT,sBAAsB,6BAA6B;IACnD,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAEF,iBAAgB;AACd,QAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;GACJ,EAAE;IACF,CAAC,OAAO,aAAa,CAAC;CAEzB,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CACtE,MAAM,UAAU,YAAY,MAAM,eAAe,YAAY,SAAS,EACpE,SAAS,SACV,CAAC;AAIF,QAAO,eACE;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAS;EAAM,CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.42",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for React.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@tanstack/react-store": "^0.11.0",
|
|
56
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
56
|
+
"@tanstack/table-core": "9.0.0-alpha.42"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@eslint-react/eslint-plugin": "^
|
|
59
|
+
"@eslint-react/eslint-plugin": "^5.7.0",
|
|
60
60
|
"@types/react": "^19.2.14",
|
|
61
61
|
"@vitejs/plugin-react": "^6.0.1",
|
|
62
62
|
"eslint-plugin-react-compiler": "19.1.0-rc.2",
|
package/src/useLegacyTable.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
sortFns,
|
|
16
16
|
stockFeatures,
|
|
17
17
|
} from '@tanstack/table-core'
|
|
18
|
-
import { useCallback, useMemo } from 'react'
|
|
18
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
19
19
|
import { useTable } from './useTable'
|
|
20
20
|
import type {
|
|
21
21
|
AggregationFns,
|
|
@@ -402,52 +402,55 @@ export function useLegacyTable<TData extends RowData>(
|
|
|
402
402
|
...restOptions
|
|
403
403
|
} = options
|
|
404
404
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
405
|
+
const [_rowModels] = useState(() => {
|
|
406
|
+
const rowModels: CreateRowModels_All<StockFeatures, TData> = {}
|
|
407
|
+
|
|
408
|
+
// Legacy row model options are setup-only. Capture the first render's
|
|
409
|
+
// marker options to match the table instance lifecycle.
|
|
410
|
+
|
|
411
|
+
if (getFilteredRowModel) {
|
|
412
|
+
rowModels.filteredRowModel = createFilteredRowModel({
|
|
413
|
+
...filterFns,
|
|
414
|
+
...options.filterFns,
|
|
415
|
+
})
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (getSortedRowModel) {
|
|
419
|
+
rowModels.sortedRowModel = createSortedRowModel({
|
|
420
|
+
...sortFns,
|
|
421
|
+
...options.sortFns,
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (getPaginationRowModel) {
|
|
426
|
+
rowModels.paginatedRowModel = createPaginatedRowModel()
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (getExpandedRowModel) {
|
|
430
|
+
rowModels.expandedRowModel = createExpandedRowModel()
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (getGroupedRowModel) {
|
|
434
|
+
rowModels.groupedRowModel = createGroupedRowModel({
|
|
435
|
+
...aggregationFns,
|
|
436
|
+
...options.aggregationFns,
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (getFacetedRowModel) {
|
|
441
|
+
rowModels.facetedRowModel = createFacetedRowModel()
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (getFacetedMinMaxValues) {
|
|
445
|
+
rowModels.facetedMinMaxValues = createFacetedMinMaxValues()
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (getFacetedUniqueValues) {
|
|
449
|
+
rowModels.facetedUniqueValues = createFacetedUniqueValues()
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return rowModels
|
|
453
|
+
})
|
|
451
454
|
|
|
452
455
|
// Call useTable with the v9 API, subscribing to all state changes
|
|
453
456
|
const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(
|
|
@@ -460,12 +463,7 @@ export function useLegacyTable<TData extends RowData>(
|
|
|
460
463
|
)
|
|
461
464
|
|
|
462
465
|
const getState = useCallback(() => {
|
|
463
|
-
|
|
464
|
-
return {
|
|
465
|
-
...table.state,
|
|
466
|
-
columns: undefined,
|
|
467
|
-
data: undefined,
|
|
468
|
-
}
|
|
466
|
+
return table.state
|
|
469
467
|
}, [table])
|
|
470
468
|
|
|
471
469
|
const setState = useCallback(
|
package/src/useTable.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useMemo, useState } from 'react'
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
4
4
|
import { constructTable } from '@tanstack/table-core'
|
|
5
5
|
import { shallow, useSelector } from '@tanstack/react-store'
|
|
6
|
+
import { constructReactivityBindings } from '@tanstack/table-core/reactivity'
|
|
6
7
|
import { FlexRender } from './FlexRender'
|
|
7
8
|
import { Subscribe } from './Subscribe'
|
|
9
|
+
import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
|
|
10
|
+
import type { FlexRenderProps } from './FlexRender'
|
|
11
|
+
import type { SubscribePropsWithStore } from './Subscribe'
|
|
8
12
|
import type {
|
|
9
13
|
CellData,
|
|
10
14
|
RowData,
|
|
@@ -13,10 +17,7 @@ import type {
|
|
|
13
17
|
TableOptions,
|
|
14
18
|
TableState,
|
|
15
19
|
} from '@tanstack/table-core'
|
|
16
|
-
import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
|
|
17
20
|
import type { FunctionComponent, ReactNode } from 'react'
|
|
18
|
-
import type { FlexRenderProps } from './FlexRender'
|
|
19
|
-
import type { SubscribePropsWithStore } from './Subscribe'
|
|
20
21
|
|
|
21
22
|
export type ReactTable<
|
|
22
23
|
TFeatures extends TableFeatures,
|
|
@@ -121,11 +122,13 @@ export function useTable<
|
|
|
121
122
|
({}) as TSelected,
|
|
122
123
|
): ReactTable<TFeatures, TData, TSelected> {
|
|
123
124
|
const [table] = useState(() => {
|
|
124
|
-
const tableInstance = constructTable(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
const tableInstance = constructTable({
|
|
126
|
+
...tableOptions,
|
|
127
|
+
_features: {
|
|
128
|
+
coreReativityFeature: constructReactivityBindings(),
|
|
129
|
+
...tableOptions._features,
|
|
130
|
+
},
|
|
131
|
+
}) as ReactTable<TFeatures, TData, TSelected>
|
|
129
132
|
|
|
130
133
|
tableInstance.Subscribe = ((props: any) => {
|
|
131
134
|
return Subscribe({
|
|
@@ -139,22 +142,26 @@ export function useTable<
|
|
|
139
142
|
return tableInstance
|
|
140
143
|
})
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
table.setOptions((prev) => ({
|
|
147
|
+
...prev,
|
|
148
|
+
...tableOptions,
|
|
149
|
+
}))
|
|
150
|
+
}, [table, tableOptions])
|
|
147
151
|
|
|
148
152
|
const state = useSelector(table.store, selector, { compare: shallow })
|
|
153
|
+
const options = useSelector(table.optionsStore, (options) => options, {
|
|
154
|
+
compare: shallow,
|
|
155
|
+
})
|
|
149
156
|
|
|
150
157
|
// we know this is not the most efficient way to return the table,
|
|
151
158
|
// but it is required for the react compiler to work
|
|
152
159
|
return useMemo(
|
|
153
160
|
() => ({
|
|
154
161
|
...table,
|
|
155
|
-
options
|
|
162
|
+
options,
|
|
156
163
|
state,
|
|
157
164
|
}),
|
|
158
|
-
[table,
|
|
165
|
+
[table, options, state],
|
|
159
166
|
) as ReactTable<TFeatures, TData, TSelected>
|
|
160
167
|
}
|