@tanstack/react-table 9.0.0-alpha.33 → 9.0.0-alpha.34
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/Subscribe.cjs +1 -26
- package/dist/Subscribe.cjs.map +1 -1
- package/dist/Subscribe.d.cts +69 -15
- package/dist/Subscribe.d.ts +69 -15
- package/dist/Subscribe.js +1 -26
- package/dist/Subscribe.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- 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 +31 -5
- package/dist/useLegacyTable.cjs.map +1 -1
- package/dist/useLegacyTable.d.cts +21 -1
- package/dist/useLegacyTable.d.ts +21 -1
- package/dist/useLegacyTable.js +32 -6
- package/dist/useLegacyTable.js.map +1 -1
- package/dist/useTable.cjs +2 -2
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.d.cts +41 -10
- package/dist/useTable.d.ts +41 -10
- package/dist/useTable.js +2 -2
- package/dist/useTable.js.map +1 -1
- package/package.json +6 -2
- package/src/Subscribe.ts +136 -20
- package/src/static-functions.ts +1 -0
- package/src/useLegacyTable.ts +58 -6
- package/src/useTable.ts +51 -16
package/src/useLegacyTable.ts
CHANGED
|
@@ -15,18 +15,21 @@ import {
|
|
|
15
15
|
sortFns,
|
|
16
16
|
stockFeatures,
|
|
17
17
|
} from '@tanstack/table-core'
|
|
18
|
-
import { useMemo } from 'react'
|
|
18
|
+
import { useCallback, useMemo } from 'react'
|
|
19
19
|
import { useTable } from './useTable'
|
|
20
20
|
import type {
|
|
21
|
+
AggregationFns,
|
|
21
22
|
Cell,
|
|
22
23
|
Column,
|
|
23
24
|
ColumnDef,
|
|
24
25
|
CreateRowModels_All,
|
|
26
|
+
FilterFns,
|
|
25
27
|
Header,
|
|
26
28
|
HeaderGroup,
|
|
27
29
|
Row,
|
|
28
30
|
RowData,
|
|
29
31
|
RowModel,
|
|
32
|
+
SortFns,
|
|
30
33
|
StockFeatures,
|
|
31
34
|
Table,
|
|
32
35
|
TableOptions,
|
|
@@ -233,6 +236,21 @@ export interface LegacyRowModelOptions<TData extends RowData> {
|
|
|
233
236
|
* @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.
|
|
234
237
|
*/
|
|
235
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
|
|
236
254
|
}
|
|
237
255
|
|
|
238
256
|
/**
|
|
@@ -264,6 +282,11 @@ export type LegacyReactTable<TData extends RowData> = ReactTable<
|
|
|
264
282
|
* @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.
|
|
265
283
|
*/
|
|
266
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
|
|
267
290
|
}
|
|
268
291
|
|
|
269
292
|
// =============================================================================
|
|
@@ -386,11 +409,17 @@ export function useLegacyTable<TData extends RowData>(
|
|
|
386
409
|
// Note: getCoreRowModel is handled automatically in v9, so we ignore it
|
|
387
410
|
|
|
388
411
|
if (getFilteredRowModel) {
|
|
389
|
-
_rowModels.filteredRowModel = createFilteredRowModel(
|
|
412
|
+
_rowModels.filteredRowModel = createFilteredRowModel({
|
|
413
|
+
...filterFns,
|
|
414
|
+
...options.filterFns,
|
|
415
|
+
})
|
|
390
416
|
}
|
|
391
417
|
|
|
392
418
|
if (getSortedRowModel) {
|
|
393
|
-
_rowModels.sortedRowModel = createSortedRowModel(
|
|
419
|
+
_rowModels.sortedRowModel = createSortedRowModel({
|
|
420
|
+
...sortFns,
|
|
421
|
+
...options.sortFns,
|
|
422
|
+
})
|
|
394
423
|
}
|
|
395
424
|
|
|
396
425
|
if (getPaginationRowModel) {
|
|
@@ -402,7 +431,10 @@ export function useLegacyTable<TData extends RowData>(
|
|
|
402
431
|
}
|
|
403
432
|
|
|
404
433
|
if (getGroupedRowModel) {
|
|
405
|
-
_rowModels.groupedRowModel = createGroupedRowModel(
|
|
434
|
+
_rowModels.groupedRowModel = createGroupedRowModel({
|
|
435
|
+
...aggregationFns,
|
|
436
|
+
...options.aggregationFns,
|
|
437
|
+
})
|
|
406
438
|
}
|
|
407
439
|
|
|
408
440
|
if (getFacetedRowModel) {
|
|
@@ -427,12 +459,32 @@ export function useLegacyTable<TData extends RowData>(
|
|
|
427
459
|
(state) => state,
|
|
428
460
|
)
|
|
429
461
|
|
|
462
|
+
const getState = useCallback(() => {
|
|
463
|
+
// all state except for columns and data
|
|
464
|
+
return {
|
|
465
|
+
...table.state,
|
|
466
|
+
columns: undefined,
|
|
467
|
+
data: undefined,
|
|
468
|
+
}
|
|
469
|
+
}, [table])
|
|
470
|
+
|
|
471
|
+
const setState = useCallback(
|
|
472
|
+
(state: TableState<StockFeatures>) => {
|
|
473
|
+
Object.entries(state).forEach(([key, value]) => {
|
|
474
|
+
// @ts-expect-error - baseAtoms is indexed by dynamic string keys
|
|
475
|
+
table.baseAtoms[key].set(value)
|
|
476
|
+
})
|
|
477
|
+
},
|
|
478
|
+
[table],
|
|
479
|
+
)
|
|
480
|
+
|
|
430
481
|
return useMemo(
|
|
431
482
|
() =>
|
|
432
483
|
({
|
|
433
484
|
...table,
|
|
434
|
-
getState
|
|
485
|
+
getState,
|
|
486
|
+
setState,
|
|
435
487
|
}) as LegacyReactTable<TData>,
|
|
436
|
-
[table],
|
|
488
|
+
[table, getState, setState],
|
|
437
489
|
)
|
|
438
490
|
}
|
package/src/useTable.ts
CHANGED
|
@@ -7,16 +7,16 @@ import { FlexRender } from './FlexRender'
|
|
|
7
7
|
import { Subscribe } from './Subscribe'
|
|
8
8
|
import type {
|
|
9
9
|
CellData,
|
|
10
|
-
NoInfer,
|
|
11
10
|
RowData,
|
|
12
11
|
Table,
|
|
13
12
|
TableFeatures,
|
|
14
13
|
TableOptions,
|
|
15
14
|
TableState,
|
|
16
15
|
} from '@tanstack/table-core'
|
|
16
|
+
import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
|
|
17
17
|
import type { FunctionComponent, ReactNode } from 'react'
|
|
18
18
|
import type { FlexRenderProps } from './FlexRender'
|
|
19
|
-
import type {
|
|
19
|
+
import type { SubscribePropsWithStore } from './Subscribe'
|
|
20
20
|
|
|
21
21
|
export type ReactTable<
|
|
22
22
|
TFeatures extends TableFeatures,
|
|
@@ -28,19 +28,53 @@ export type ReactTable<
|
|
|
28
28
|
*
|
|
29
29
|
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
30
30
|
*
|
|
31
|
+
* Pass `atom` to subscribe to a single slice atom instead of the full `table.store`.
|
|
32
|
+
*
|
|
31
33
|
* @example
|
|
32
34
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
33
|
-
* {({ rowSelection }) => (
|
|
34
|
-
* <tr key={row.id}>
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* {({ rowSelection }) => (
|
|
36
|
+
* <tr key={row.id}>...</tr>
|
|
37
|
+
* )}
|
|
38
|
+
* </table.Subscribe>
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* <table.Subscribe atom={table.atoms.rowSelection}>
|
|
42
|
+
* {(rowSelection) => <div>...</div>}
|
|
43
|
+
* </table.Subscribe>
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* <table.Subscribe atom={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
|
|
47
|
+
* {() => <tr key={row.id}>...</tr>}
|
|
38
48
|
* </table.Subscribe>
|
|
39
49
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Overloads (not a single union) so `selector` callbacks get correct contextual
|
|
52
|
+
* types in JSX; a union of two `selector` signatures degrades to implicit `any`.
|
|
53
|
+
*
|
|
54
|
+
* Atom **without** `selector` is a separate overload so children receive `TAtomValue`
|
|
55
|
+
* (identity projection). If `selector` were optional on one overload, `TSubSelected`
|
|
56
|
+
* would default to `unknown` instead of inferring from the atom.
|
|
57
|
+
*
|
|
58
|
+
* The **atom** overloads are listed first so `TAtomValue` is inferred from `atom`.
|
|
59
|
+
*/
|
|
60
|
+
Subscribe: {
|
|
61
|
+
<TAtomValue>(props: {
|
|
62
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>
|
|
63
|
+
selector?: undefined
|
|
64
|
+
children: ((state: TAtomValue) => ReactNode) | ReactNode
|
|
65
|
+
}): ReturnType<FunctionComponent>
|
|
66
|
+
<TAtomValue, TSubSelected>(props: {
|
|
67
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>
|
|
68
|
+
selector: (state: TAtomValue) => TSubSelected
|
|
69
|
+
children: ((state: TSubSelected) => ReactNode) | ReactNode
|
|
70
|
+
}): ReturnType<FunctionComponent>
|
|
71
|
+
<TSubSelected>(
|
|
72
|
+
props: Omit<
|
|
73
|
+
SubscribePropsWithStore<TFeatures, TData, TSubSelected>,
|
|
74
|
+
'table'
|
|
75
|
+
>,
|
|
76
|
+
): ReturnType<FunctionComponent>
|
|
77
|
+
}
|
|
44
78
|
/**
|
|
45
79
|
* A React component that renders headers, cells, or footers with custom markup.
|
|
46
80
|
* Use this utility component instead of manually calling flexRender.
|
|
@@ -92,11 +126,12 @@ export function useTable<
|
|
|
92
126
|
TSelected
|
|
93
127
|
>
|
|
94
128
|
|
|
95
|
-
tableInstance.Subscribe =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
129
|
+
tableInstance.Subscribe = ((props: any) => {
|
|
130
|
+
return Subscribe({
|
|
131
|
+
...props,
|
|
132
|
+
table: tableInstance,
|
|
133
|
+
})
|
|
134
|
+
}) as ReactTable<TFeatures, TData, TSelected>['Subscribe']
|
|
100
135
|
|
|
101
136
|
tableInstance.FlexRender = FlexRender
|
|
102
137
|
|