@tanstack/react-table 9.0.0-alpha.9 → 9.0.0-beta.2
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/README.md +127 -0
- package/dist/FlexRender.cjs +61 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +51 -0
- package/dist/FlexRender.d.ts +51 -0
- package/dist/FlexRender.js +58 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/Subscribe.cjs +13 -0
- package/dist/Subscribe.cjs.map +1 -0
- package/dist/Subscribe.d.cts +101 -0
- package/dist/Subscribe.d.ts +101 -0
- package/dist/Subscribe.js +13 -0
- package/dist/Subscribe.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/createTableHook.cjs +313 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +358 -0
- package/dist/createTableHook.d.ts +358 -0
- package/dist/createTableHook.js +311 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/flex-render.cjs +5 -0
- package/dist/flex-render.d.cts +2 -0
- package/dist/flex-render.d.ts +2 -0
- package/dist/flex-render.js +3 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/legacy.cjs +14 -0
- package/dist/legacy.d.cts +2 -0
- package/dist/legacy.d.ts +2 -0
- package/dist/legacy.js +3 -0
- package/dist/reactivity.cjs +34 -0
- package/dist/reactivity.cjs.map +1 -0
- package/dist/reactivity.js +34 -0
- package/dist/reactivity.js.map +1 -0
- package/dist/static-functions.cjs +9 -0
- package/dist/static-functions.d.cts +1 -0
- package/dist/static-functions.d.ts +1 -0
- package/dist/static-functions.js +3 -0
- package/dist/useLegacyTable.cjs +191 -0
- package/dist/useLegacyTable.cjs.map +1 -0
- package/dist/useLegacyTable.d.cts +233 -0
- package/dist/useLegacyTable.d.ts +233 -0
- package/dist/useLegacyTable.js +181 -0
- package/dist/useLegacyTable.js.map +1 -0
- package/dist/useTable.cjs +72 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +122 -0
- package/dist/useTable.d.ts +122 -0
- package/dist/useTable.js +72 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +41 -22
- package/skills/react/client-to-server/SKILL.md +377 -0
- package/skills/react/compose-with-tanstack-form/SKILL.md +363 -0
- package/skills/react/compose-with-tanstack-pacer/SKILL.md +287 -0
- package/skills/react/compose-with-tanstack-query/SKILL.md +467 -0
- package/skills/react/compose-with-tanstack-store/SKILL.md +347 -0
- package/skills/react/compose-with-tanstack-virtual/SKILL.md +388 -0
- package/skills/react/compose-with-tanstack-virtual/references/column-virtualization-and-infinite-scroll.md +136 -0
- package/skills/react/getting-started/SKILL.md +388 -0
- package/skills/react/migrate-v8-to-v9/SKILL.md +488 -0
- package/skills/react/production-readiness/SKILL.md +341 -0
- package/skills/react/react-subscribe-compiler-compat/SKILL.md +269 -0
- package/skills/react/table-state/SKILL.md +432 -0
- package/src/FlexRender.tsx +136 -0
- package/src/Subscribe.ts +153 -0
- package/src/createTableHook.tsx +1121 -0
- package/src/flex-render.ts +1 -0
- package/src/index.ts +6 -0
- package/src/legacy.ts +3 -0
- package/src/reactivity.ts +41 -0
- package/src/static-functions.ts +1 -0
- package/src/useLegacyTable.ts +487 -0
- package/src/useTable.ts +191 -0
- package/dist/cjs/index.cjs +0 -77
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -9
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.js +0 -55
- package/dist/esm/index.js.map +0 -1
- package/src/index.tsx +0 -92
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FlexRender'
|
package/src/index.ts
ADDED
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { batch, createAtom } from '@tanstack/react-store'
|
|
2
|
+
import type {
|
|
3
|
+
TableAtomOptions,
|
|
4
|
+
TableReactivityBindings,
|
|
5
|
+
} from '@tanstack/table-core/reactivity'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates the table-core reactivity bindings used by the React adapter.
|
|
9
|
+
*
|
|
10
|
+
* React stores table state in TanStack Store atoms and leaves options as plain
|
|
11
|
+
* resolved data because `useTable` synchronizes options during render.
|
|
12
|
+
*/
|
|
13
|
+
export function reactReactivity(): TableReactivityBindings {
|
|
14
|
+
return {
|
|
15
|
+
createOptionsStore: false,
|
|
16
|
+
wrapExternalAtoms: false,
|
|
17
|
+
addSubscription: () => {
|
|
18
|
+
throw new Error(
|
|
19
|
+
'Feature not supported in current reactivity implementation',
|
|
20
|
+
)
|
|
21
|
+
},
|
|
22
|
+
unmount: () => {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Feature not supported in current reactivity implementation',
|
|
25
|
+
)
|
|
26
|
+
},
|
|
27
|
+
schedule: (fn) => queueMicrotask(fn),
|
|
28
|
+
batch,
|
|
29
|
+
untrack: (fn) => fn(),
|
|
30
|
+
createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {
|
|
31
|
+
return createAtom(() => fn(), {
|
|
32
|
+
compare: options?.compare,
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {
|
|
36
|
+
return createAtom(value, {
|
|
37
|
+
compare: options?.compare,
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/static-functions'
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
aggregationFns,
|
|
5
|
+
createColumnHelper,
|
|
6
|
+
createExpandedRowModel,
|
|
7
|
+
createFacetedMinMaxValues,
|
|
8
|
+
createFacetedRowModel,
|
|
9
|
+
createFacetedUniqueValues,
|
|
10
|
+
createFilteredRowModel,
|
|
11
|
+
createGroupedRowModel,
|
|
12
|
+
createPaginatedRowModel,
|
|
13
|
+
createSortedRowModel,
|
|
14
|
+
filterFns,
|
|
15
|
+
sortFns,
|
|
16
|
+
stockFeatures,
|
|
17
|
+
} from '@tanstack/table-core'
|
|
18
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
19
|
+
import { useTable } from './useTable'
|
|
20
|
+
import type {
|
|
21
|
+
AggregationFns,
|
|
22
|
+
Cell,
|
|
23
|
+
Column,
|
|
24
|
+
ColumnDef,
|
|
25
|
+
CreateRowModels_All,
|
|
26
|
+
FilterFns,
|
|
27
|
+
Header,
|
|
28
|
+
HeaderGroup,
|
|
29
|
+
Row,
|
|
30
|
+
RowData,
|
|
31
|
+
RowModel,
|
|
32
|
+
SortFns,
|
|
33
|
+
StockFeatures,
|
|
34
|
+
Table,
|
|
35
|
+
TableOptions,
|
|
36
|
+
TableState,
|
|
37
|
+
} from '@tanstack/table-core'
|
|
38
|
+
import type { ReactTable } from './useTable'
|
|
39
|
+
|
|
40
|
+
// =============================================================================
|
|
41
|
+
// V8-style row model factory functions
|
|
42
|
+
// These are stub functions that act as markers for useLegacyTable to know
|
|
43
|
+
// which row models to enable. They don't actually do anything - the real
|
|
44
|
+
// implementation is handled by useLegacyTable internally.
|
|
45
|
+
// =============================================================================
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.
|
|
49
|
+
*
|
|
50
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
51
|
+
* It acts as a marker to enable the filtered row model.
|
|
52
|
+
*/
|
|
53
|
+
export function getFilteredRowModel<
|
|
54
|
+
TData extends RowData,
|
|
55
|
+
>(): RowModelFactory<TData> {
|
|
56
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.
|
|
61
|
+
*
|
|
62
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
63
|
+
* It acts as a marker to enable the sorted row model.
|
|
64
|
+
*/
|
|
65
|
+
export function getSortedRowModel<
|
|
66
|
+
TData extends RowData,
|
|
67
|
+
>(): RowModelFactory<TData> {
|
|
68
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.
|
|
73
|
+
*
|
|
74
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
75
|
+
* It acts as a marker to enable the paginated row model.
|
|
76
|
+
*/
|
|
77
|
+
export function getPaginationRowModel<
|
|
78
|
+
TData extends RowData,
|
|
79
|
+
>(): RowModelFactory<TData> {
|
|
80
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.
|
|
85
|
+
*
|
|
86
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
87
|
+
* It acts as a marker to enable the expanded row model.
|
|
88
|
+
*/
|
|
89
|
+
export function getExpandedRowModel<
|
|
90
|
+
TData extends RowData,
|
|
91
|
+
>(): RowModelFactory<TData> {
|
|
92
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.
|
|
97
|
+
*
|
|
98
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
99
|
+
* It acts as a marker to enable the grouped row model.
|
|
100
|
+
*/
|
|
101
|
+
export function getGroupedRowModel<
|
|
102
|
+
TData extends RowData,
|
|
103
|
+
>(): RowModelFactory<TData> {
|
|
104
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.
|
|
109
|
+
*
|
|
110
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
111
|
+
* It acts as a marker to enable the faceted row model.
|
|
112
|
+
*/
|
|
113
|
+
export function getFacetedRowModel<
|
|
114
|
+
TData extends RowData,
|
|
115
|
+
>(): FacetedRowModelFactory<TData> {
|
|
116
|
+
return (() => () => {}) as unknown as FacetedRowModelFactory<TData>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.
|
|
121
|
+
*
|
|
122
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
123
|
+
* It acts as a marker to enable the faceted min/max values.
|
|
124
|
+
*/
|
|
125
|
+
export function getFacetedMinMaxValues<
|
|
126
|
+
TData extends RowData,
|
|
127
|
+
>(): FacetedMinMaxValuesFactory<TData> {
|
|
128
|
+
return () => () => undefined
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.
|
|
133
|
+
*
|
|
134
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
135
|
+
* It acts as a marker to enable the faceted unique values.
|
|
136
|
+
*/
|
|
137
|
+
export function getFacetedUniqueValues<
|
|
138
|
+
TData extends RowData,
|
|
139
|
+
>(): FacetedUniqueValuesFactory<TData> {
|
|
140
|
+
return () => () => new Map()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated The core row model is always created automatically in v9.
|
|
145
|
+
*
|
|
146
|
+
* This is a stub function for v8 API compatibility with `useLegacyTable`.
|
|
147
|
+
* It does nothing - the core row model is always available.
|
|
148
|
+
*/
|
|
149
|
+
export function getCoreRowModel<
|
|
150
|
+
TData extends RowData,
|
|
151
|
+
>(): RowModelFactory<TData> {
|
|
152
|
+
return (() => () => {}) as unknown as RowModelFactory<TData>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Type definitions
|
|
157
|
+
// =============================================================================
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Row model factory function type from v8 API
|
|
161
|
+
*/
|
|
162
|
+
export type RowModelFactory<TData extends RowData> = (
|
|
163
|
+
table: Table<StockFeatures, TData>,
|
|
164
|
+
) => () => RowModel<StockFeatures, TData>
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Faceted row model factory function type from v8 API
|
|
168
|
+
*/
|
|
169
|
+
export type FacetedRowModelFactory<TData extends RowData> = (
|
|
170
|
+
table: Table<StockFeatures, TData>,
|
|
171
|
+
columnId: string,
|
|
172
|
+
) => () => RowModel<StockFeatures, TData>
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Faceted min/max values factory function type from v8 API
|
|
176
|
+
*/
|
|
177
|
+
export type FacetedMinMaxValuesFactory<TData extends RowData> = (
|
|
178
|
+
table: Table<StockFeatures, TData>,
|
|
179
|
+
columnId: string,
|
|
180
|
+
) => () => undefined | [number, number]
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Faceted unique values factory function type from v8 API
|
|
184
|
+
*/
|
|
185
|
+
export type FacetedUniqueValuesFactory<TData extends RowData> = (
|
|
186
|
+
table: Table<StockFeatures, TData>,
|
|
187
|
+
columnId: string,
|
|
188
|
+
) => () => Map<any, number>
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Legacy v8-style row model options
|
|
192
|
+
*/
|
|
193
|
+
export interface LegacyRowModelOptions<TData extends RowData> {
|
|
194
|
+
/**
|
|
195
|
+
* Returns the core row model for the table.
|
|
196
|
+
* @deprecated This option is no longer needed in v9. The core row model is always created automatically.
|
|
197
|
+
*/
|
|
198
|
+
getCoreRowModel?: RowModelFactory<TData>
|
|
199
|
+
/**
|
|
200
|
+
* Returns the filtered row model for the table.
|
|
201
|
+
* @deprecated Use `rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.
|
|
202
|
+
*/
|
|
203
|
+
getFilteredRowModel?: RowModelFactory<TData>
|
|
204
|
+
/**
|
|
205
|
+
* Returns the sorted row model for the table.
|
|
206
|
+
* @deprecated Use `rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.
|
|
207
|
+
*/
|
|
208
|
+
getSortedRowModel?: RowModelFactory<TData>
|
|
209
|
+
/**
|
|
210
|
+
* Returns the paginated row model for the table.
|
|
211
|
+
* @deprecated Use `rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.
|
|
212
|
+
*/
|
|
213
|
+
getPaginationRowModel?: RowModelFactory<TData>
|
|
214
|
+
/**
|
|
215
|
+
* Returns the expanded row model for the table.
|
|
216
|
+
* @deprecated Use `rowModels.expandedRowModel` with `createExpandedRowModel()` instead.
|
|
217
|
+
*/
|
|
218
|
+
getExpandedRowModel?: RowModelFactory<TData>
|
|
219
|
+
/**
|
|
220
|
+
* Returns the grouped row model for the table.
|
|
221
|
+
* @deprecated Use `rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.
|
|
222
|
+
*/
|
|
223
|
+
getGroupedRowModel?: RowModelFactory<TData>
|
|
224
|
+
/**
|
|
225
|
+
* Returns the faceted row model for a column.
|
|
226
|
+
* @deprecated Use `rowModels.facetedRowModel` with `createFacetedRowModel()` instead.
|
|
227
|
+
*/
|
|
228
|
+
getFacetedRowModel?: FacetedRowModelFactory<TData>
|
|
229
|
+
/**
|
|
230
|
+
* Returns the faceted min/max values for a column.
|
|
231
|
+
* @deprecated Use `rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.
|
|
232
|
+
*/
|
|
233
|
+
getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>
|
|
234
|
+
/**
|
|
235
|
+
* Returns the faceted unique values for a column.
|
|
236
|
+
* @deprecated Use `rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.
|
|
237
|
+
*/
|
|
238
|
+
getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>
|
|
239
|
+
/**
|
|
240
|
+
* Additional filter functions to apply to the table.
|
|
241
|
+
* @deprecated Use `rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.
|
|
242
|
+
*/
|
|
243
|
+
filterFns?: FilterFns
|
|
244
|
+
/**
|
|
245
|
+
* Additional sort functions to apply to the table.
|
|
246
|
+
* @deprecated Use `rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.
|
|
247
|
+
*/
|
|
248
|
+
sortFns?: SortFns
|
|
249
|
+
/**
|
|
250
|
+
* Additional aggregation functions to apply to the table.
|
|
251
|
+
* @deprecated Use `rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.
|
|
252
|
+
*/
|
|
253
|
+
aggregationFns?: AggregationFns
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Legacy v8-style table options that work with useLegacyTable.
|
|
258
|
+
*
|
|
259
|
+
* This type omits `features` and `rowModels` and instead accepts the v8-style
|
|
260
|
+
* `get*RowModel` function options.
|
|
261
|
+
*
|
|
262
|
+
* @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `features` and `rowModels` instead.
|
|
263
|
+
*/
|
|
264
|
+
export type LegacyTableOptions<TData extends RowData> = Omit<
|
|
265
|
+
TableOptions<StockFeatures, TData>,
|
|
266
|
+
'features' | 'rowModels'
|
|
267
|
+
> &
|
|
268
|
+
LegacyRowModelOptions<TData>
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Legacy table instance type that includes the v8-style `getState()` method.
|
|
272
|
+
*
|
|
273
|
+
* @deprecated Use `useTable` with explicit state selection instead.
|
|
274
|
+
*/
|
|
275
|
+
export type LegacyReactTable<TData extends RowData> = ReactTable<
|
|
276
|
+
StockFeatures,
|
|
277
|
+
TData,
|
|
278
|
+
TableState<StockFeatures>
|
|
279
|
+
> & {
|
|
280
|
+
/**
|
|
281
|
+
* Returns the current table state.
|
|
282
|
+
* @deprecated In v9, access state directly via `table.state` or use `table.state` for the full state.
|
|
283
|
+
*/
|
|
284
|
+
getState: () => TableState<StockFeatures>
|
|
285
|
+
/**
|
|
286
|
+
* Sets the current table state.
|
|
287
|
+
* @deprecated In v9, access state directly via `table.baseAtoms`
|
|
288
|
+
*/
|
|
289
|
+
setState: (state: TableState<StockFeatures>) => void
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// =============================================================================
|
|
293
|
+
// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable
|
|
294
|
+
// =============================================================================
|
|
295
|
+
|
|
296
|
+
/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */
|
|
297
|
+
export type LegacyColumn<TData extends RowData, TValue = unknown> = Column<
|
|
298
|
+
StockFeatures,
|
|
299
|
+
TData,
|
|
300
|
+
TValue
|
|
301
|
+
>
|
|
302
|
+
|
|
303
|
+
/** @deprecated Use Row<TFeatures, TData> with useTable instead. */
|
|
304
|
+
export type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>
|
|
305
|
+
|
|
306
|
+
/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */
|
|
307
|
+
export type LegacyCell<TData extends RowData, TValue = unknown> = Cell<
|
|
308
|
+
StockFeatures,
|
|
309
|
+
TData,
|
|
310
|
+
TValue
|
|
311
|
+
>
|
|
312
|
+
|
|
313
|
+
/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */
|
|
314
|
+
export type LegacyHeader<TData extends RowData, TValue = unknown> = Header<
|
|
315
|
+
StockFeatures,
|
|
316
|
+
TData,
|
|
317
|
+
TValue
|
|
318
|
+
>
|
|
319
|
+
|
|
320
|
+
/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */
|
|
321
|
+
export type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<
|
|
322
|
+
StockFeatures,
|
|
323
|
+
TData
|
|
324
|
+
>
|
|
325
|
+
|
|
326
|
+
/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */
|
|
327
|
+
export type LegacyColumnDef<
|
|
328
|
+
TData extends RowData,
|
|
329
|
+
TValue = unknown,
|
|
330
|
+
> = ColumnDef<StockFeatures, TData, TValue>
|
|
331
|
+
|
|
332
|
+
/** @deprecated Use Table<TFeatures, TData> with useTable instead. */
|
|
333
|
+
export type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>
|
|
334
|
+
|
|
335
|
+
// =============================================================================
|
|
336
|
+
// Legacy column helper - StockFeatures hardcoded
|
|
337
|
+
// =============================================================================
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.
|
|
341
|
+
*
|
|
342
|
+
* A column helper with StockFeatures pre-bound for use with useLegacyTable.
|
|
343
|
+
* Only requires TData—no need to specify TFeatures.
|
|
344
|
+
*/
|
|
345
|
+
export function legacyCreateColumnHelper<TData extends RowData>() {
|
|
346
|
+
return createColumnHelper<StockFeatures, TData>()
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// =============================================================================
|
|
350
|
+
// useLegacyTable hook
|
|
351
|
+
// =============================================================================
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.
|
|
355
|
+
*
|
|
356
|
+
* Use the new `useTable` hook instead with explicit `features` and `rowModels`:
|
|
357
|
+
*
|
|
358
|
+
* ```tsx
|
|
359
|
+
* // New v9 API
|
|
360
|
+
* const features = tableFeatures({
|
|
361
|
+
* columnFilteringFeature,
|
|
362
|
+
* rowSortingFeature,
|
|
363
|
+
* rowPaginationFeature,
|
|
364
|
+
* })
|
|
365
|
+
*
|
|
366
|
+
* const table = useTable({
|
|
367
|
+
* features,
|
|
368
|
+
* rowModels: {
|
|
369
|
+
* filteredRowModel: createFilteredRowModel(filterFns),
|
|
370
|
+
* sortedRowModel: createSortedRowModel(sortFns),
|
|
371
|
+
* paginatedRowModel: createPaginatedRowModel(),
|
|
372
|
+
* },
|
|
373
|
+
* columns,
|
|
374
|
+
* data,
|
|
375
|
+
* })
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* Key differences from v8:
|
|
379
|
+
* - Features are tree-shakeable - only import what you use
|
|
380
|
+
* - Row models are explicitly passed via `rowModels`
|
|
381
|
+
* - Use `table.Subscribe` for fine-grained re-renders
|
|
382
|
+
* - State is accessed via `table.state` after selecting with the 2nd argument
|
|
383
|
+
*
|
|
384
|
+
* @param options - Legacy v8-style table options
|
|
385
|
+
* @returns A table instance with the full state subscribed and a `getState()` method
|
|
386
|
+
*/
|
|
387
|
+
export function useLegacyTable<TData extends RowData>(
|
|
388
|
+
options: LegacyTableOptions<TData>,
|
|
389
|
+
): LegacyReactTable<TData> {
|
|
390
|
+
const {
|
|
391
|
+
// Extract legacy row model options
|
|
392
|
+
getCoreRowModel: _getCoreRowModel,
|
|
393
|
+
getFilteredRowModel,
|
|
394
|
+
getSortedRowModel,
|
|
395
|
+
getPaginationRowModel,
|
|
396
|
+
getExpandedRowModel,
|
|
397
|
+
getGroupedRowModel,
|
|
398
|
+
getFacetedRowModel,
|
|
399
|
+
getFacetedMinMaxValues,
|
|
400
|
+
getFacetedUniqueValues,
|
|
401
|
+
// Rest of the options
|
|
402
|
+
...restOptions
|
|
403
|
+
} = options
|
|
404
|
+
|
|
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
|
+
})
|
|
454
|
+
|
|
455
|
+
// Call useTable with the v9 API, subscribing to all state changes
|
|
456
|
+
const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(
|
|
457
|
+
{
|
|
458
|
+
...restOptions,
|
|
459
|
+
features: stockFeatures,
|
|
460
|
+
rowModels,
|
|
461
|
+
},
|
|
462
|
+
(state) => state,
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
const getState = useCallback(() => {
|
|
466
|
+
return table.state
|
|
467
|
+
}, [table])
|
|
468
|
+
|
|
469
|
+
const setState = useCallback(
|
|
470
|
+
(state: TableState<StockFeatures>) => {
|
|
471
|
+
Object.entries(state).forEach(([key, value]) => {
|
|
472
|
+
// @ts-expect-error - baseAtoms is indexed by dynamic string keys
|
|
473
|
+
table.baseAtoms[key].set(value)
|
|
474
|
+
})
|
|
475
|
+
},
|
|
476
|
+
[table],
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
return useMemo(
|
|
480
|
+
() => ({
|
|
481
|
+
...table,
|
|
482
|
+
getState,
|
|
483
|
+
setState,
|
|
484
|
+
}),
|
|
485
|
+
[table, getState, setState],
|
|
486
|
+
)
|
|
487
|
+
}
|