@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/dist/Subscribe.cjs
CHANGED
|
@@ -4,33 +4,8 @@ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
|
4
4
|
let _tanstack_react_store = require("@tanstack/react-store");
|
|
5
5
|
|
|
6
6
|
//#region src/Subscribe.ts
|
|
7
|
-
/**
|
|
8
|
-
* A React component that allows you to subscribe to the table state.
|
|
9
|
-
*
|
|
10
|
-
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* // As a standalone component
|
|
15
|
-
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
16
|
-
* {({ rowSelection }) => (
|
|
17
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
18
|
-
* )}
|
|
19
|
-
* </Subscribe>
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* // As table.Subscribe (table instance method)
|
|
25
|
-
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
26
|
-
* {({ rowSelection }) => (
|
|
27
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
28
|
-
* )}
|
|
29
|
-
* </table.Subscribe>
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
7
|
function Subscribe(props) {
|
|
33
|
-
const selected = (0, _tanstack_react_store.useSelector)(props.table.store, props.selector, { compare: _tanstack_react_store.shallow });
|
|
8
|
+
const selected = (0, _tanstack_react_store.useSelector)("atom" in props ? props.atom : props.table.store, "atom" in props ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_react_store.shallow });
|
|
34
9
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
35
10
|
}
|
|
36
11
|
|
package/dist/Subscribe.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Subscribe.cjs","names":["shallow"],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"Subscribe.cjs","names":["shallow"],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to the full value of a slice atom (e.g. `table.atoms.rowSelection`).\n * Omitting `selector` is equivalent to the identity selector — children receive\n * `TAtomValue`.\n */\nexport type SubscribePropsWithAtomIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n> = {\n table: Table<TFeatures, TData>\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector?: undefined\n children: ((state: TAtomValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a slice atom. The selector receives the\n * atom value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithAtomWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector: (state: TAtomValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single slice atom (identity or projected). Prefer\n * {@link SubscribePropsWithAtomIdentity} or {@link SubscribePropsWithAtomWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithAtom<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected = TAtomValue,\n> =\n | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>\n | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TAtomValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>\n | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>\n\n/**\n * A React 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 * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX\n * contextual typing works. This standalone component uses a union `props` type.\n *\n * @example\n * ```tsx\n * // As a standalone component — full store\n * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Entire slice atom (no selector)\n * <Subscribe table={table} atom={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project atom value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * atom={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection?.[row.id]}\n * >\n * {(selected) => <tr data-selected={!!selected}>...</tr>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // As table.Subscribe (table instance method)\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </table.Subscribe>\n * ```\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n>(\n props: SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected,\n>(\n props: SubscribePropsWithAtomWithSelector<\n TFeatures,\n TData,\n TAtomValue,\n TSelected\n >,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TAtomValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TAtomValue>,\n): ReturnType<FunctionComponent> {\n const source = 'atom' in props ? props.atom : props.table.store\n const selectFn =\n 'atom' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n source,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ReactNode)(selected)\n : props.children\n}\n"],"mappings":";;;;;;AAoKA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,kDAJS,UAAU,QAAQ,MAAM,OAAO,MAAM,MAAM,OAExD,UAAU,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMlE,EACE,SAASA,+BACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|
package/dist/Subscribe.d.cts
CHANGED
|
@@ -1,31 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
2
2
|
import { FunctionComponent, ReactNode } from "react";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
3
4
|
|
|
4
5
|
//#region src/Subscribe.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to `table.store` (full table state). The selector receives the full
|
|
8
|
+
* {@link TableState}.
|
|
9
|
+
*/
|
|
10
|
+
type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
|
|
10
11
|
table: Table<TFeatures, TData>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* The children to render. Can be a function that receives the selected state, or a React node.
|
|
13
|
+
* Select from full table state. Re-renders when the selected value changes
|
|
14
|
+
* (shallow compare).
|
|
15
|
+
*
|
|
16
|
+
* Required in store mode so you never accidentally subscribe to the whole
|
|
17
|
+
* store without an explicit projection.
|
|
18
18
|
*/
|
|
19
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
20
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to the full value of a slice atom (e.g. `table.atoms.rowSelection`).
|
|
24
|
+
* Omitting `selector` is equivalent to the identity selector — children receive
|
|
25
|
+
* `TAtomValue`.
|
|
26
|
+
*/
|
|
27
|
+
type SubscribePropsWithAtomIdentity<TFeatures extends TableFeatures, TData extends RowData, TAtomValue> = {
|
|
28
|
+
table: Table<TFeatures, TData>;
|
|
29
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
|
|
30
|
+
selector?: undefined;
|
|
31
|
+
children: ((state: TAtomValue) => ReactNode) | ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to a projected value from a slice atom. The selector receives the
|
|
35
|
+
* atom value; children receive the projected `TSelected`.
|
|
36
|
+
*/
|
|
37
|
+
type SubscribePropsWithAtomWithSelector<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected> = {
|
|
38
|
+
table: Table<TFeatures, TData>;
|
|
39
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
|
|
40
|
+
selector: (state: TAtomValue) => TSelected;
|
|
19
41
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
20
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to a single slice atom (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithAtomIdentity} or {@link SubscribePropsWithAtomWithSelector}
|
|
46
|
+
* for clearer inference when `selector` is omitted.
|
|
47
|
+
*/
|
|
48
|
+
type SubscribePropsWithAtom<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected = TAtomValue> = SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue> | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TAtomValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue> | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>;
|
|
21
50
|
/**
|
|
22
51
|
* A React component that allows you to subscribe to the table state.
|
|
23
52
|
*
|
|
24
53
|
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
25
54
|
*
|
|
55
|
+
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
|
|
56
|
+
* contextual typing works. This standalone component uses a union `props` type.
|
|
57
|
+
*
|
|
26
58
|
* @example
|
|
27
59
|
* ```tsx
|
|
28
|
-
* // As a standalone component
|
|
60
|
+
* // As a standalone component — full store
|
|
29
61
|
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
30
62
|
* {({ rowSelection }) => (
|
|
31
63
|
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
@@ -35,6 +67,26 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
35
67
|
*
|
|
36
68
|
* @example
|
|
37
69
|
* ```tsx
|
|
70
|
+
* // Entire slice atom (no selector)
|
|
71
|
+
* <Subscribe table={table} atom={table.atoms.rowSelection}>
|
|
72
|
+
* {(rowSelection) => <div>...</div>}
|
|
73
|
+
* </Subscribe>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // Project atom value (e.g. one row’s selection)
|
|
79
|
+
* <Subscribe
|
|
80
|
+
* table={table}
|
|
81
|
+
* atom={table.atoms.rowSelection}
|
|
82
|
+
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
|
+
* >
|
|
84
|
+
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
85
|
+
* </Subscribe>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
38
90
|
* // As table.Subscribe (table instance method)
|
|
39
91
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
40
92
|
* {({ rowSelection }) => (
|
|
@@ -43,7 +95,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
43
95
|
* </table.Subscribe>
|
|
44
96
|
* ```
|
|
45
97
|
*/
|
|
46
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TAtomValue>(props: SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected>(props: SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
47
101
|
//#endregion
|
|
48
|
-
export { Subscribe, SubscribeProps };
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore };
|
|
49
103
|
//# sourceMappingURL=Subscribe.d.cts.map
|
package/dist/Subscribe.d.ts
CHANGED
|
@@ -1,31 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
2
2
|
import { FunctionComponent, ReactNode } from "react";
|
|
3
|
+
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
3
4
|
|
|
4
5
|
//#region src/Subscribe.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to `table.store` (full table state). The selector receives the full
|
|
8
|
+
* {@link TableState}.
|
|
9
|
+
*/
|
|
10
|
+
type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
|
|
10
11
|
table: Table<TFeatures, TData>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* The children to render. Can be a function that receives the selected state, or a React node.
|
|
13
|
+
* Select from full table state. Re-renders when the selected value changes
|
|
14
|
+
* (shallow compare).
|
|
15
|
+
*
|
|
16
|
+
* Required in store mode so you never accidentally subscribe to the whole
|
|
17
|
+
* store without an explicit projection.
|
|
18
18
|
*/
|
|
19
|
+
selector: (state: TableState<TFeatures>) => TSelected;
|
|
20
|
+
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to the full value of a slice atom (e.g. `table.atoms.rowSelection`).
|
|
24
|
+
* Omitting `selector` is equivalent to the identity selector — children receive
|
|
25
|
+
* `TAtomValue`.
|
|
26
|
+
*/
|
|
27
|
+
type SubscribePropsWithAtomIdentity<TFeatures extends TableFeatures, TData extends RowData, TAtomValue> = {
|
|
28
|
+
table: Table<TFeatures, TData>;
|
|
29
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
|
|
30
|
+
selector?: undefined;
|
|
31
|
+
children: ((state: TAtomValue) => ReactNode) | ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Subscribe to a projected value from a slice atom. The selector receives the
|
|
35
|
+
* atom value; children receive the projected `TSelected`.
|
|
36
|
+
*/
|
|
37
|
+
type SubscribePropsWithAtomWithSelector<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected> = {
|
|
38
|
+
table: Table<TFeatures, TData>;
|
|
39
|
+
atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
|
|
40
|
+
selector: (state: TAtomValue) => TSelected;
|
|
19
41
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
20
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to a single slice atom (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithAtomIdentity} or {@link SubscribePropsWithAtomWithSelector}
|
|
46
|
+
* for clearer inference when `selector` is omitted.
|
|
47
|
+
*/
|
|
48
|
+
type SubscribePropsWithAtom<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected = TAtomValue> = SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue> | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TAtomValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue> | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>;
|
|
21
50
|
/**
|
|
22
51
|
* A React component that allows you to subscribe to the table state.
|
|
23
52
|
*
|
|
24
53
|
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
25
54
|
*
|
|
55
|
+
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
|
|
56
|
+
* contextual typing works. This standalone component uses a union `props` type.
|
|
57
|
+
*
|
|
26
58
|
* @example
|
|
27
59
|
* ```tsx
|
|
28
|
-
* // As a standalone component
|
|
60
|
+
* // As a standalone component — full store
|
|
29
61
|
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
30
62
|
* {({ rowSelection }) => (
|
|
31
63
|
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
@@ -35,6 +67,26 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
35
67
|
*
|
|
36
68
|
* @example
|
|
37
69
|
* ```tsx
|
|
70
|
+
* // Entire slice atom (no selector)
|
|
71
|
+
* <Subscribe table={table} atom={table.atoms.rowSelection}>
|
|
72
|
+
* {(rowSelection) => <div>...</div>}
|
|
73
|
+
* </Subscribe>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // Project atom value (e.g. one row’s selection)
|
|
79
|
+
* <Subscribe
|
|
80
|
+
* table={table}
|
|
81
|
+
* atom={table.atoms.rowSelection}
|
|
82
|
+
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
|
+
* >
|
|
84
|
+
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
85
|
+
* </Subscribe>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
38
90
|
* // As table.Subscribe (table instance method)
|
|
39
91
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
40
92
|
* {({ rowSelection }) => (
|
|
@@ -43,7 +95,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
43
95
|
* </table.Subscribe>
|
|
44
96
|
* ```
|
|
45
97
|
*/
|
|
46
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TAtomValue>(props: SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TAtomValue, TSelected>(props: SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
47
101
|
//#endregion
|
|
48
|
-
export { Subscribe, SubscribeProps };
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore };
|
|
49
103
|
//# sourceMappingURL=Subscribe.d.ts.map
|
package/dist/Subscribe.js
CHANGED
|
@@ -3,33 +3,8 @@
|
|
|
3
3
|
import { shallow, useSelector } from "@tanstack/react-store";
|
|
4
4
|
|
|
5
5
|
//#region src/Subscribe.ts
|
|
6
|
-
/**
|
|
7
|
-
* A React component that allows you to subscribe to the table state.
|
|
8
|
-
*
|
|
9
|
-
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* // As a standalone component
|
|
14
|
-
* <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
15
|
-
* {({ rowSelection }) => (
|
|
16
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
17
|
-
* )}
|
|
18
|
-
* </Subscribe>
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* // As table.Subscribe (table instance method)
|
|
24
|
-
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
25
|
-
* {({ rowSelection }) => (
|
|
26
|
-
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
27
|
-
* )}
|
|
28
|
-
* </table.Subscribe>
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
6
|
function Subscribe(props) {
|
|
32
|
-
const selected = useSelector(props.table.store, props.selector, { compare: shallow });
|
|
7
|
+
const selected = useSelector("atom" in props ? props.atom : props.table.store, "atom" in props ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
|
|
33
8
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
34
9
|
}
|
|
35
10
|
|
package/dist/Subscribe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to the full value of a slice atom (e.g. `table.atoms.rowSelection`).\n * Omitting `selector` is equivalent to the identity selector — children receive\n * `TAtomValue`.\n */\nexport type SubscribePropsWithAtomIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n> = {\n table: Table<TFeatures, TData>\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector?: undefined\n children: ((state: TAtomValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a slice atom. The selector receives the\n * atom value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithAtomWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector: (state: TAtomValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single slice atom (identity or projected). Prefer\n * {@link SubscribePropsWithAtomIdentity} or {@link SubscribePropsWithAtomWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithAtom<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected = TAtomValue,\n> =\n | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>\n | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TAtomValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>\n | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>\n\n/**\n * A React 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 * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX\n * contextual typing works. This standalone component uses a union `props` type.\n *\n * @example\n * ```tsx\n * // As a standalone component — full store\n * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Entire slice atom (no selector)\n * <Subscribe table={table} atom={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project atom value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * atom={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection?.[row.id]}\n * >\n * {(selected) => <tr data-selected={!!selected}>...</tr>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // As table.Subscribe (table instance method)\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </table.Subscribe>\n * ```\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n>(\n props: SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TAtomValue,\n TSelected,\n>(\n props: SubscribePropsWithAtomWithSelector<\n TFeatures,\n TData,\n TAtomValue,\n TSelected\n >,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TAtomValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TAtomValue>,\n): ReturnType<FunctionComponent> {\n const source = 'atom' in props ? props.atom : props.table.store\n const selectFn =\n 'atom' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n source,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ReactNode)(selected)\n : props.children\n}\n"],"mappings":";;;;;AAoKA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,WAAW,YAJF,UAAU,QAAQ,MAAM,OAAO,MAAM,MAAM,OAExD,UAAU,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMlE,EACE,SAAS,SACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FlexRender, FlexRenderProps, Renderable, flexRender } from "./FlexRender.cjs";
|
|
2
|
-
import { Subscribe, SubscribeProps } from "./Subscribe.cjs";
|
|
2
|
+
import { Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore } from "./Subscribe.cjs";
|
|
3
3
|
import { ReactTable, useTable } from "./useTable.cjs";
|
|
4
4
|
import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, createTableHook } from "./createTableHook.cjs";
|
|
5
5
|
export * from "@tanstack/table-core";
|
|
6
|
-
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, createTableHook, flexRender, useTable };
|
|
6
|
+
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FlexRender, FlexRenderProps, Renderable, flexRender } from "./FlexRender.js";
|
|
2
|
-
import { Subscribe, SubscribeProps } from "./Subscribe.js";
|
|
2
|
+
import { Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore } from "./Subscribe.js";
|
|
3
3
|
import { ReactTable, useTable } from "./useTable.js";
|
|
4
4
|
import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, createTableHook } from "./createTableHook.js";
|
|
5
5
|
export * from "@tanstack/table-core";
|
|
6
|
-
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, createTableHook, flexRender, useTable };
|
|
6
|
+
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithAtom, SubscribePropsWithAtomIdentity, SubscribePropsWithAtomWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
var _tanstack_table_core_static_functions = require("@tanstack/table-core/static-functions");
|
|
4
|
+
Object.keys(_tanstack_table_core_static_functions).forEach(function (k) {
|
|
5
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function () { return _tanstack_table_core_static_functions[k]; }
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@tanstack/table-core/static-functions";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@tanstack/table-core/static-functions";
|
package/dist/useLegacyTable.cjs
CHANGED
|
@@ -133,11 +133,20 @@ function legacyCreateColumnHelper() {
|
|
|
133
133
|
function useLegacyTable(options) {
|
|
134
134
|
const { getCoreRowModel: _getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, getExpandedRowModel, getGroupedRowModel, getFacetedRowModel, getFacetedMinMaxValues, getFacetedUniqueValues, ...restOptions } = options;
|
|
135
135
|
const _rowModels = {};
|
|
136
|
-
if (getFilteredRowModel) _rowModels.filteredRowModel = (0, _tanstack_table_core.createFilteredRowModel)(
|
|
137
|
-
|
|
136
|
+
if (getFilteredRowModel) _rowModels.filteredRowModel = (0, _tanstack_table_core.createFilteredRowModel)({
|
|
137
|
+
..._tanstack_table_core.filterFns,
|
|
138
|
+
...options.filterFns
|
|
139
|
+
});
|
|
140
|
+
if (getSortedRowModel) _rowModels.sortedRowModel = (0, _tanstack_table_core.createSortedRowModel)({
|
|
141
|
+
..._tanstack_table_core.sortFns,
|
|
142
|
+
...options.sortFns
|
|
143
|
+
});
|
|
138
144
|
if (getPaginationRowModel) _rowModels.paginatedRowModel = (0, _tanstack_table_core.createPaginatedRowModel)();
|
|
139
145
|
if (getExpandedRowModel) _rowModels.expandedRowModel = (0, _tanstack_table_core.createExpandedRowModel)();
|
|
140
|
-
if (getGroupedRowModel) _rowModels.groupedRowModel = (0, _tanstack_table_core.createGroupedRowModel)(
|
|
146
|
+
if (getGroupedRowModel) _rowModels.groupedRowModel = (0, _tanstack_table_core.createGroupedRowModel)({
|
|
147
|
+
..._tanstack_table_core.aggregationFns,
|
|
148
|
+
...options.aggregationFns
|
|
149
|
+
});
|
|
141
150
|
if (getFacetedRowModel) _rowModels.facetedRowModel = (0, _tanstack_table_core.createFacetedRowModel)();
|
|
142
151
|
if (getFacetedMinMaxValues) _rowModels.facetedMinMaxValues = (0, _tanstack_table_core.createFacetedMinMaxValues)();
|
|
143
152
|
if (getFacetedUniqueValues) _rowModels.facetedUniqueValues = (0, _tanstack_table_core.createFacetedUniqueValues)();
|
|
@@ -146,10 +155,27 @@ function useLegacyTable(options) {
|
|
|
146
155
|
_features: _tanstack_table_core.stockFeatures,
|
|
147
156
|
_rowModels
|
|
148
157
|
}, (state) => state);
|
|
158
|
+
const getState = (0, react.useCallback)(() => {
|
|
159
|
+
return {
|
|
160
|
+
...table.state,
|
|
161
|
+
columns: void 0,
|
|
162
|
+
data: void 0
|
|
163
|
+
};
|
|
164
|
+
}, [table]);
|
|
165
|
+
const setState = (0, react.useCallback)((state) => {
|
|
166
|
+
Object.entries(state).forEach(([key, value]) => {
|
|
167
|
+
table.baseAtoms[key].set(value);
|
|
168
|
+
});
|
|
169
|
+
}, [table]);
|
|
149
170
|
return (0, react.useMemo)(() => ({
|
|
150
171
|
...table,
|
|
151
|
-
getState
|
|
152
|
-
|
|
172
|
+
getState,
|
|
173
|
+
setState
|
|
174
|
+
}), [
|
|
175
|
+
table,
|
|
176
|
+
getState,
|
|
177
|
+
setState
|
|
178
|
+
]);
|
|
153
179
|
}
|
|
154
180
|
|
|
155
181
|
//#endregion
|
|
@@ -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 { useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\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) as unknown as FacetedMinMaxValuesFactory<TData>\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()) as unknown as FacetedUniqueValuesFactory<TData>\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 */\ntype 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 */\ntype 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 */\ntype 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 */\ntype 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\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\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(filterFns)\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel(sortFns)\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(aggregationFns)\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 } as TableOptions<StockFeatures, TData>,\n (state) => state,\n )\n\n return useMemo(\n () =>\n ({\n ...table,\n getState: () => table.state,\n }) as LegacyReactTable<TData>,\n [table],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAiDA,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,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qCAAoB,IAAI,KAAK;;;;;;;;AAS/B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AA6KtB,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,oEAA0CA,+BAAU;AAGjE,KAAI,kBACF,YAAW,gEAAsCC,6BAAQ;AAG3D,KAAI,sBACF,YAAW,uEAA6C;AAG1D,KAAI,oBACF,YAAW,qEAA2C;AAGxD,KAAI,mBACF,YAAW,kEAAwCC,oCAAe;AAGpE,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;AAED,kCAEK;EACC,GAAG;EACH,gBAAgB,MAAM;EACvB,GACH,CAAC,MAAM,CACR"}
|
|
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) as unknown as FacetedMinMaxValuesFactory<TData>\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()) as unknown as FacetedUniqueValuesFactory<TData>\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 */\ntype 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 */\ntype 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 */\ntype 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 */\ntype 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 } as TableOptions<StockFeatures, TData>,\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 ({\n ...table,\n getState,\n setState,\n }) as LegacyReactTable<TData>,\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,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qCAAoB,IAAI,KAAK;;;;;;;;AAS/B,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,kCAEK;EACC,GAAG;EACH;EACA;EACD,GACH;EAAC;EAAO;EAAU;EAAS,CAC5B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactTable } from "./useTable.cjs";
|
|
2
2
|
import * as _$_tanstack_table_core0 from "@tanstack/table-core";
|
|
3
|
-
import { Cell, Column, ColumnDef, Header, HeaderGroup, Row, RowData, RowModel, StockFeatures, Table, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { AggregationFns, Cell, Column, ColumnDef, FilterFns, Header, HeaderGroup, Row, RowData, RowModel, SortFns, StockFeatures, Table, TableOptions, TableState } from "@tanstack/table-core";
|
|
4
4
|
|
|
5
5
|
//#region src/useLegacyTable.d.ts
|
|
6
6
|
/**
|
|
@@ -131,6 +131,21 @@ interface LegacyRowModelOptions<TData extends RowData> {
|
|
|
131
131
|
* @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.
|
|
132
132
|
*/
|
|
133
133
|
getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>;
|
|
134
|
+
/**
|
|
135
|
+
* Additional filter functions to apply to the table.
|
|
136
|
+
* @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.
|
|
137
|
+
*/
|
|
138
|
+
filterFns?: FilterFns;
|
|
139
|
+
/**
|
|
140
|
+
* Additional sort functions to apply to the table.
|
|
141
|
+
* @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.
|
|
142
|
+
*/
|
|
143
|
+
sortFns?: SortFns;
|
|
144
|
+
/**
|
|
145
|
+
* Additional aggregation functions to apply to the table.
|
|
146
|
+
* @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.
|
|
147
|
+
*/
|
|
148
|
+
aggregationFns?: AggregationFns;
|
|
134
149
|
}
|
|
135
150
|
/**
|
|
136
151
|
* Legacy v8-style table options that work with useLegacyTable.
|
|
@@ -152,6 +167,11 @@ type LegacyReactTable<TData extends RowData> = ReactTable<StockFeatures, TData,
|
|
|
152
167
|
* @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.
|
|
153
168
|
*/
|
|
154
169
|
getState: () => TableState<StockFeatures>;
|
|
170
|
+
/**
|
|
171
|
+
* Sets the current table state.
|
|
172
|
+
* @deprecated In v9, access state directly via `table.baseAtoms`
|
|
173
|
+
*/
|
|
174
|
+
setState: (state: TableState<StockFeatures>) => void;
|
|
155
175
|
};
|
|
156
176
|
/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */
|
|
157
177
|
type LegacyColumn<TData extends RowData, TValue = unknown> = Column<StockFeatures, TData, TValue>;
|
package/dist/useLegacyTable.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactTable } from "./useTable.js";
|
|
2
2
|
import * as _$_tanstack_table_core0 from "@tanstack/table-core";
|
|
3
|
-
import { Cell, Column, ColumnDef, Header, HeaderGroup, Row, RowData, RowModel, StockFeatures, Table, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
import { AggregationFns, Cell, Column, ColumnDef, FilterFns, Header, HeaderGroup, Row, RowData, RowModel, SortFns, StockFeatures, Table, TableOptions, TableState } from "@tanstack/table-core";
|
|
4
4
|
|
|
5
5
|
//#region src/useLegacyTable.d.ts
|
|
6
6
|
/**
|
|
@@ -131,6 +131,21 @@ interface LegacyRowModelOptions<TData extends RowData> {
|
|
|
131
131
|
* @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.
|
|
132
132
|
*/
|
|
133
133
|
getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>;
|
|
134
|
+
/**
|
|
135
|
+
* Additional filter functions to apply to the table.
|
|
136
|
+
* @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.
|
|
137
|
+
*/
|
|
138
|
+
filterFns?: FilterFns;
|
|
139
|
+
/**
|
|
140
|
+
* Additional sort functions to apply to the table.
|
|
141
|
+
* @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.
|
|
142
|
+
*/
|
|
143
|
+
sortFns?: SortFns;
|
|
144
|
+
/**
|
|
145
|
+
* Additional aggregation functions to apply to the table.
|
|
146
|
+
* @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.
|
|
147
|
+
*/
|
|
148
|
+
aggregationFns?: AggregationFns;
|
|
134
149
|
}
|
|
135
150
|
/**
|
|
136
151
|
* Legacy v8-style table options that work with useLegacyTable.
|
|
@@ -152,6 +167,11 @@ type LegacyReactTable<TData extends RowData> = ReactTable<StockFeatures, TData,
|
|
|
152
167
|
* @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.
|
|
153
168
|
*/
|
|
154
169
|
getState: () => TableState<StockFeatures>;
|
|
170
|
+
/**
|
|
171
|
+
* Sets the current table state.
|
|
172
|
+
* @deprecated In v9, access state directly via `table.baseAtoms`
|
|
173
|
+
*/
|
|
174
|
+
setState: (state: TableState<StockFeatures>) => void;
|
|
155
175
|
};
|
|
156
176
|
/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */
|
|
157
177
|
type LegacyColumn<TData extends RowData, TValue = unknown> = Column<StockFeatures, TData, TValue>;
|