@tanstack/react-table 9.0.0-alpha.34 → 9.0.0-alpha.36
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/FlexRender.d.cts +1 -1
- package/dist/Subscribe.cjs +1 -1
- package/dist/Subscribe.cjs.map +1 -1
- package/dist/Subscribe.d.cts +23 -23
- package/dist/Subscribe.d.ts +22 -22
- package/dist/Subscribe.js +1 -1
- package/dist/Subscribe.js.map +1 -1
- package/dist/createTableHook.d.cts +1 -1
- 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.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.d.cts +14 -13
- package/dist/useTable.d.ts +13 -12
- package/dist/useTable.js.map +1 -1
- package/package.json +6 -2
- package/src/Subscribe.ts +46 -36
- package/src/flex-render.ts +1 -0
- package/src/useTable.ts +13 -12
package/dist/FlexRender.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Cell, CellData, Header, RowData, TableFeatures } from "@tanstack/table-core";
|
|
2
1
|
import React, { ComponentType, JSX, ReactNode } from "react";
|
|
2
|
+
import { Cell, CellData, Header, RowData, TableFeatures } from "@tanstack/table-core";
|
|
3
3
|
|
|
4
4
|
//#region src/FlexRender.d.ts
|
|
5
5
|
type Renderable<TProps> = ReactNode | ComponentType<TProps>;
|
package/dist/Subscribe.cjs
CHANGED
|
@@ -5,7 +5,7 @@ let _tanstack_react_store = require("@tanstack/react-store");
|
|
|
5
5
|
|
|
6
6
|
//#region src/Subscribe.ts
|
|
7
7
|
function Subscribe(props) {
|
|
8
|
-
const selected = (0, _tanstack_react_store.useSelector)("
|
|
8
|
+
const selected = (0, _tanstack_react_store.useSelector)("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_react_store.shallow });
|
|
9
9
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
10
10
|
}
|
|
11
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 { 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
|
|
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 source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store). The selector\n * receives the source value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected). Prefer\n * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\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 source (atom or store) — no selector\n * <Subscribe table={table} source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project source value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * source={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 TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\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 TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' 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":";;;;;;AA8KA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,kDAJS,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMpE,EACE,SAASA,+BACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|
package/dist/Subscribe.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
2
1
|
import { FunctionComponent, ReactNode } from "react";
|
|
2
|
+
import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
|
|
3
3
|
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
4
4
|
|
|
5
5
|
//#region src/Subscribe.d.ts
|
|
@@ -20,33 +20,33 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
|
|
|
20
20
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* Subscribe to the full value of a
|
|
24
|
-
* Omitting `selector` is equivalent to the identity
|
|
25
|
-
* `
|
|
23
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
24
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
25
|
+
* selector — children receive `TSourceValue`.
|
|
26
26
|
*/
|
|
27
|
-
type
|
|
27
|
+
type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
|
|
28
28
|
table: Table<TFeatures, TData>;
|
|
29
|
-
|
|
29
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
30
30
|
selector?: undefined;
|
|
31
|
-
children: ((state:
|
|
31
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Subscribe to a projected value from a
|
|
35
|
-
*
|
|
34
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
35
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
36
36
|
*/
|
|
37
|
-
type
|
|
37
|
+
type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
|
|
38
38
|
table: Table<TFeatures, TData>;
|
|
39
|
-
|
|
40
|
-
selector: (state:
|
|
39
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
40
|
+
selector: (state: TSourceValue) => TSelected;
|
|
41
41
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
|
-
* Subscribe to a single
|
|
45
|
-
* {@link
|
|
44
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
46
46
|
* for clearer inference when `selector` is omitted.
|
|
47
47
|
*/
|
|
48
|
-
type
|
|
49
|
-
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown,
|
|
48
|
+
type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
50
50
|
/**
|
|
51
51
|
* A React component that allows you to subscribe to the table state.
|
|
52
52
|
*
|
|
@@ -67,18 +67,18 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
69
|
* ```tsx
|
|
70
|
-
* // Entire
|
|
71
|
-
* <Subscribe table={table}
|
|
70
|
+
* // Entire source (atom or store) — no selector
|
|
71
|
+
* <Subscribe table={table} source={table.atoms.rowSelection}>
|
|
72
72
|
* {(rowSelection) => <div>...</div>}
|
|
73
73
|
* </Subscribe>
|
|
74
74
|
* ```
|
|
75
75
|
*
|
|
76
76
|
* @example
|
|
77
77
|
* ```tsx
|
|
78
|
-
* // Project
|
|
78
|
+
* // Project source value (e.g. one row’s selection)
|
|
79
79
|
* <Subscribe
|
|
80
80
|
* table={table}
|
|
81
|
-
*
|
|
81
|
+
* source={table.atoms.rowSelection}
|
|
82
82
|
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
83
|
* >
|
|
84
84
|
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
@@ -95,9 +95,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
95
95
|
* </table.Subscribe>
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
99
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
100
|
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
101
101
|
//#endregion
|
|
102
|
-
export { Subscribe, SubscribeProps,
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
|
|
103
103
|
//# sourceMappingURL=Subscribe.d.cts.map
|
package/dist/Subscribe.d.ts
CHANGED
|
@@ -20,33 +20,33 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
|
|
|
20
20
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* Subscribe to the full value of a
|
|
24
|
-
* Omitting `selector` is equivalent to the identity
|
|
25
|
-
* `
|
|
23
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
24
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
25
|
+
* selector — children receive `TSourceValue`.
|
|
26
26
|
*/
|
|
27
|
-
type
|
|
27
|
+
type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
|
|
28
28
|
table: Table<TFeatures, TData>;
|
|
29
|
-
|
|
29
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
30
30
|
selector?: undefined;
|
|
31
|
-
children: ((state:
|
|
31
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Subscribe to a projected value from a
|
|
35
|
-
*
|
|
34
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
35
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
36
36
|
*/
|
|
37
|
-
type
|
|
37
|
+
type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
|
|
38
38
|
table: Table<TFeatures, TData>;
|
|
39
|
-
|
|
40
|
-
selector: (state:
|
|
39
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
40
|
+
selector: (state: TSourceValue) => TSelected;
|
|
41
41
|
children: ((state: TSelected) => ReactNode) | ReactNode;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
|
-
* Subscribe to a single
|
|
45
|
-
* {@link
|
|
44
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
45
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
46
46
|
* for clearer inference when `selector` is omitted.
|
|
47
47
|
*/
|
|
48
|
-
type
|
|
49
|
-
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown,
|
|
48
|
+
type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
49
|
+
type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
|
|
50
50
|
/**
|
|
51
51
|
* A React component that allows you to subscribe to the table state.
|
|
52
52
|
*
|
|
@@ -67,18 +67,18 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
69
|
* ```tsx
|
|
70
|
-
* // Entire
|
|
71
|
-
* <Subscribe table={table}
|
|
70
|
+
* // Entire source (atom or store) — no selector
|
|
71
|
+
* <Subscribe table={table} source={table.atoms.rowSelection}>
|
|
72
72
|
* {(rowSelection) => <div>...</div>}
|
|
73
73
|
* </Subscribe>
|
|
74
74
|
* ```
|
|
75
75
|
*
|
|
76
76
|
* @example
|
|
77
77
|
* ```tsx
|
|
78
|
-
* // Project
|
|
78
|
+
* // Project source value (e.g. one row’s selection)
|
|
79
79
|
* <Subscribe
|
|
80
80
|
* table={table}
|
|
81
|
-
*
|
|
81
|
+
* source={table.atoms.rowSelection}
|
|
82
82
|
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
83
83
|
* >
|
|
84
84
|
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
@@ -95,9 +95,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
|
|
|
95
95
|
* </table.Subscribe>
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
99
|
-
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData,
|
|
98
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ReturnType<FunctionComponent>;
|
|
99
|
+
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ReturnType<FunctionComponent>;
|
|
100
100
|
declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
|
|
101
101
|
//#endregion
|
|
102
|
-
export { Subscribe, SubscribeProps,
|
|
102
|
+
export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
|
|
103
103
|
//# sourceMappingURL=Subscribe.d.ts.map
|
package/dist/Subscribe.js
CHANGED
|
@@ -4,7 +4,7 @@ import { shallow, useSelector } from "@tanstack/react-store";
|
|
|
4
4
|
|
|
5
5
|
//#region src/Subscribe.ts
|
|
6
6
|
function Subscribe(props) {
|
|
7
|
-
const selected = useSelector("
|
|
7
|
+
const selected = useSelector("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
|
|
8
8
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
9
9
|
}
|
|
10
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 { 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
|
|
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 source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store). The selector\n * receives the source value; children receive the projected `TSelected`.\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected). Prefer\n * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}\n * for clearer inference when `selector` is omitted.\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\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 source (atom or store) — no selector\n * <Subscribe table={table} source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * // Project source value (e.g. one row’s selection)\n * <Subscribe\n * table={table}\n * source={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 TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\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 TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' 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":";;;;;AA8KA,SAAgB,UAMd,OAC+B;CAK/B,MAAM,WAAW,YAJF,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAMpE,EACE,SAAS,SACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactTable } from "./useTable.cjs";
|
|
2
|
-
import { AccessorFn, AccessorFnColumnDef, AccessorKeyColumnDef, Cell, CellContext, CellData, Column, ColumnDef, DeepKeys, DeepValue, DisplayColumnDef, GroupColumnDef, Header, IdentifiedColumnDef, NoInfer, Row, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
2
|
import { ComponentType, ReactNode } from "react";
|
|
3
|
+
import { AccessorFn, AccessorFnColumnDef, AccessorKeyColumnDef, Cell, CellContext, CellData, Column, ColumnDef, DeepKeys, DeepValue, DisplayColumnDef, GroupColumnDef, Header, IdentifiedColumnDef, NoInfer, Row, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
4
4
|
|
|
5
5
|
//#region src/createTableHook.d.ts
|
|
6
6
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FlexRender, FlexRenderProps, Renderable, flexRender } from "./FlexRender.cjs";
|
|
2
|
-
import { Subscribe, SubscribeProps,
|
|
2
|
+
import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, 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,
|
|
6
|
+
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, 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,
|
|
2
|
+
import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, 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,
|
|
6
|
+
export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnHelper, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
|
package/dist/useTable.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `
|
|
1
|
+
{"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AAiHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAOA,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,+CAAoB,MAAM,OAAO,4BAA4B,EACjE,SAASC,+BACV,CAAC;AAEF,kCACS;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
|
package/dist/useTable.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlexRenderProps } from "./FlexRender.cjs";
|
|
2
2
|
import { SubscribePropsWithStore } from "./Subscribe.cjs";
|
|
3
|
-
import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
4
3
|
import { FunctionComponent, ReactNode } from "react";
|
|
4
|
+
import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
5
5
|
import { Atom, ReadonlyAtom } from "@tanstack/react-store";
|
|
6
6
|
|
|
7
7
|
//#region src/useTable.d.ts
|
|
@@ -11,7 +11,8 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
11
11
|
*
|
|
12
12
|
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
13
13
|
*
|
|
14
|
-
* Pass `
|
|
14
|
+
* Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
|
|
15
|
+
* or `table.optionsStore`) instead of the full `table.store`.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
@@ -21,12 +22,12 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
21
22
|
* </table.Subscribe>
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
|
-
* <table.Subscribe
|
|
25
|
+
* <table.Subscribe source={table.atoms.rowSelection}>
|
|
25
26
|
* {(rowSelection) => <div>...</div>}
|
|
26
27
|
* </table.Subscribe>
|
|
27
28
|
*
|
|
28
29
|
* @example
|
|
29
|
-
* <table.Subscribe
|
|
30
|
+
* <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
|
|
30
31
|
* {() => <tr key={row.id}>...</tr>}
|
|
31
32
|
* </table.Subscribe>
|
|
32
33
|
*/
|
|
@@ -34,21 +35,21 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
34
35
|
* Overloads (not a single union) so `selector` callbacks get correct contextual
|
|
35
36
|
* types in JSX; a union of two `selector` signatures degrades to implicit `any`.
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
+
* Source **without** `selector` is a separate overload so children receive `TSourceValue`
|
|
38
39
|
* (identity projection). If `selector` were optional on one overload, `TSubSelected`
|
|
39
|
-
* would default to `unknown` instead of inferring from the
|
|
40
|
+
* would default to `unknown` instead of inferring from the source.
|
|
40
41
|
*
|
|
41
|
-
* The **
|
|
42
|
+
* The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
|
|
42
43
|
*/
|
|
43
44
|
Subscribe: {
|
|
44
|
-
<
|
|
45
|
-
|
|
45
|
+
<TSourceValue>(props: {
|
|
46
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
46
47
|
selector?: undefined;
|
|
47
|
-
children: ((state:
|
|
48
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
48
49
|
}): ReturnType<FunctionComponent>;
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
selector: (state:
|
|
50
|
+
<TSourceValue, TSubSelected>(props: {
|
|
51
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
52
|
+
selector: (state: TSourceValue) => TSubSelected;
|
|
52
53
|
children: ((state: TSubSelected) => ReactNode) | ReactNode;
|
|
53
54
|
}): ReturnType<FunctionComponent>;
|
|
54
55
|
<TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
|
package/dist/useTable.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
11
11
|
*
|
|
12
12
|
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
13
13
|
*
|
|
14
|
-
* Pass `
|
|
14
|
+
* Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
|
|
15
|
+
* or `table.optionsStore`) instead of the full `table.store`.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
@@ -21,12 +22,12 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
21
22
|
* </table.Subscribe>
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
|
-
* <table.Subscribe
|
|
25
|
+
* <table.Subscribe source={table.atoms.rowSelection}>
|
|
25
26
|
* {(rowSelection) => <div>...</div>}
|
|
26
27
|
* </table.Subscribe>
|
|
27
28
|
*
|
|
28
29
|
* @example
|
|
29
|
-
* <table.Subscribe
|
|
30
|
+
* <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
|
|
30
31
|
* {() => <tr key={row.id}>...</tr>}
|
|
31
32
|
* </table.Subscribe>
|
|
32
33
|
*/
|
|
@@ -34,21 +35,21 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
|
|
|
34
35
|
* Overloads (not a single union) so `selector` callbacks get correct contextual
|
|
35
36
|
* types in JSX; a union of two `selector` signatures degrades to implicit `any`.
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
+
* Source **without** `selector` is a separate overload so children receive `TSourceValue`
|
|
38
39
|
* (identity projection). If `selector` were optional on one overload, `TSubSelected`
|
|
39
|
-
* would default to `unknown` instead of inferring from the
|
|
40
|
+
* would default to `unknown` instead of inferring from the source.
|
|
40
41
|
*
|
|
41
|
-
* The **
|
|
42
|
+
* The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
|
|
42
43
|
*/
|
|
43
44
|
Subscribe: {
|
|
44
|
-
<
|
|
45
|
-
|
|
45
|
+
<TSourceValue>(props: {
|
|
46
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
46
47
|
selector?: undefined;
|
|
47
|
-
children: ((state:
|
|
48
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode;
|
|
48
49
|
}): ReturnType<FunctionComponent>;
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
selector: (state:
|
|
50
|
+
<TSourceValue, TSubSelected>(props: {
|
|
51
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
|
|
52
|
+
selector: (state: TSourceValue) => TSubSelected;
|
|
52
53
|
children: ((state: TSubSelected) => ReactNode) | ReactNode;
|
|
53
54
|
}): ReturnType<FunctionComponent>;
|
|
54
55
|
<TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
|
package/dist/useTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `
|
|
1
|
+
{"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;AAiHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,QAAQ,YAAY,MAAM,OAAO,4BAA4B,EACjE,SAAS,SACV,CAAC;AAEF,QAAO,eACE;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-table",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.36",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for React.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"import": "./dist/index.js",
|
|
30
30
|
"require": "./dist/index.cjs"
|
|
31
31
|
},
|
|
32
|
+
"./flex-render": {
|
|
33
|
+
"import": "./dist/flex-render.js",
|
|
34
|
+
"require": "./dist/flex-render.cjs"
|
|
35
|
+
},
|
|
32
36
|
"./legacy": {
|
|
33
37
|
"import": "./dist/legacy.js",
|
|
34
38
|
"require": "./dist/legacy.cjs"
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
],
|
|
50
54
|
"dependencies": {
|
|
51
55
|
"@tanstack/react-store": "^0.11.0",
|
|
52
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
56
|
+
"@tanstack/table-core": "9.0.0-alpha.36"
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
55
59
|
"@eslint-react/eslint-plugin": "^4.2.3",
|
package/src/Subscribe.ts
CHANGED
|
@@ -32,60 +32,70 @@ export type SubscribePropsWithStore<
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Subscribe to the full value of a
|
|
36
|
-
* Omitting `selector` is equivalent to the identity
|
|
37
|
-
* `
|
|
35
|
+
* Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or
|
|
36
|
+
* `table.optionsStore`). Omitting `selector` is equivalent to the identity
|
|
37
|
+
* selector — children receive `TSourceValue`.
|
|
38
38
|
*/
|
|
39
|
-
export type
|
|
39
|
+
export type SubscribePropsWithSourceIdentity<
|
|
40
40
|
TFeatures extends TableFeatures,
|
|
41
41
|
TData extends RowData,
|
|
42
|
-
|
|
42
|
+
TSourceValue,
|
|
43
43
|
> = {
|
|
44
44
|
table: Table<TFeatures, TData>
|
|
45
|
-
|
|
45
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
|
|
46
46
|
selector?: undefined
|
|
47
|
-
children: ((state:
|
|
47
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* Subscribe to a projected value from a
|
|
52
|
-
*
|
|
51
|
+
* Subscribe to a projected value from a source (atom or store). The selector
|
|
52
|
+
* receives the source value; children receive the projected `TSelected`.
|
|
53
53
|
*/
|
|
54
|
-
export type
|
|
54
|
+
export type SubscribePropsWithSourceWithSelector<
|
|
55
55
|
TFeatures extends TableFeatures,
|
|
56
56
|
TData extends RowData,
|
|
57
|
-
|
|
57
|
+
TSourceValue,
|
|
58
58
|
TSelected,
|
|
59
59
|
> = {
|
|
60
60
|
table: Table<TFeatures, TData>
|
|
61
|
-
|
|
62
|
-
selector: (state:
|
|
61
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
|
|
62
|
+
selector: (state: TSourceValue) => TSelected
|
|
63
63
|
children: ((state: TSelected) => ReactNode) | ReactNode
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Subscribe to a single
|
|
68
|
-
* {@link
|
|
67
|
+
* Subscribe to a single source — atom or store (identity or projected). Prefer
|
|
68
|
+
* {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
|
|
69
69
|
* for clearer inference when `selector` is omitted.
|
|
70
70
|
*/
|
|
71
|
-
export type
|
|
71
|
+
export type SubscribePropsWithSource<
|
|
72
72
|
TFeatures extends TableFeatures,
|
|
73
73
|
TData extends RowData,
|
|
74
|
-
|
|
75
|
-
TSelected =
|
|
74
|
+
TSourceValue,
|
|
75
|
+
TSelected = TSourceValue,
|
|
76
76
|
> =
|
|
77
|
-
|
|
|
78
|
-
|
|
|
77
|
+
| SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
|
|
78
|
+
| SubscribePropsWithSourceWithSelector<
|
|
79
|
+
TFeatures,
|
|
80
|
+
TData,
|
|
81
|
+
TSourceValue,
|
|
82
|
+
TSelected
|
|
83
|
+
>
|
|
79
84
|
|
|
80
85
|
export type SubscribeProps<
|
|
81
86
|
TFeatures extends TableFeatures,
|
|
82
87
|
TData extends RowData,
|
|
83
88
|
TSelected = unknown,
|
|
84
|
-
|
|
89
|
+
TSourceValue = unknown,
|
|
85
90
|
> =
|
|
86
91
|
| SubscribePropsWithStore<TFeatures, TData, TSelected>
|
|
87
|
-
|
|
|
88
|
-
|
|
|
92
|
+
| SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
|
|
93
|
+
| SubscribePropsWithSourceWithSelector<
|
|
94
|
+
TFeatures,
|
|
95
|
+
TData,
|
|
96
|
+
TSourceValue,
|
|
97
|
+
TSelected
|
|
98
|
+
>
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
101
|
* A React component that allows you to subscribe to the table state.
|
|
@@ -107,18 +117,18 @@ export type SubscribeProps<
|
|
|
107
117
|
*
|
|
108
118
|
* @example
|
|
109
119
|
* ```tsx
|
|
110
|
-
* // Entire
|
|
111
|
-
* <Subscribe table={table}
|
|
120
|
+
* // Entire source (atom or store) — no selector
|
|
121
|
+
* <Subscribe table={table} source={table.atoms.rowSelection}>
|
|
112
122
|
* {(rowSelection) => <div>...</div>}
|
|
113
123
|
* </Subscribe>
|
|
114
124
|
* ```
|
|
115
125
|
*
|
|
116
126
|
* @example
|
|
117
127
|
* ```tsx
|
|
118
|
-
* // Project
|
|
128
|
+
* // Project source value (e.g. one row’s selection)
|
|
119
129
|
* <Subscribe
|
|
120
130
|
* table={table}
|
|
121
|
-
*
|
|
131
|
+
* source={table.atoms.rowSelection}
|
|
122
132
|
* selector={(rowSelection) => rowSelection?.[row.id]}
|
|
123
133
|
* >
|
|
124
134
|
* {(selected) => <tr data-selected={!!selected}>...</tr>}
|
|
@@ -138,20 +148,20 @@ export type SubscribeProps<
|
|
|
138
148
|
export function Subscribe<
|
|
139
149
|
TFeatures extends TableFeatures,
|
|
140
150
|
TData extends RowData,
|
|
141
|
-
|
|
151
|
+
TSourceValue,
|
|
142
152
|
>(
|
|
143
|
-
props:
|
|
153
|
+
props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,
|
|
144
154
|
): ReturnType<FunctionComponent>
|
|
145
155
|
export function Subscribe<
|
|
146
156
|
TFeatures extends TableFeatures,
|
|
147
157
|
TData extends RowData,
|
|
148
|
-
|
|
158
|
+
TSourceValue,
|
|
149
159
|
TSelected,
|
|
150
160
|
>(
|
|
151
|
-
props:
|
|
161
|
+
props: SubscribePropsWithSourceWithSelector<
|
|
152
162
|
TFeatures,
|
|
153
163
|
TData,
|
|
154
|
-
|
|
164
|
+
TSourceValue,
|
|
155
165
|
TSelected
|
|
156
166
|
>,
|
|
157
167
|
): ReturnType<FunctionComponent>
|
|
@@ -166,13 +176,13 @@ export function Subscribe<
|
|
|
166
176
|
TFeatures extends TableFeatures,
|
|
167
177
|
TData extends RowData,
|
|
168
178
|
TSelected,
|
|
169
|
-
|
|
179
|
+
TSourceValue,
|
|
170
180
|
>(
|
|
171
|
-
props: SubscribeProps<TFeatures, TData, TSelected,
|
|
181
|
+
props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,
|
|
172
182
|
): ReturnType<FunctionComponent> {
|
|
173
|
-
const source = '
|
|
183
|
+
const source = 'source' in props ? props.source : props.table.store
|
|
174
184
|
const selectFn =
|
|
175
|
-
'
|
|
185
|
+
'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector
|
|
176
186
|
|
|
177
187
|
const selected = useSelector(
|
|
178
188
|
// Atom and store share the same selection protocol; union args need a widen for TS.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FlexRender'
|
package/src/useTable.ts
CHANGED
|
@@ -28,7 +28,8 @@ 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 `
|
|
31
|
+
* Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`
|
|
32
|
+
* or `table.optionsStore`) instead of the full `table.store`.
|
|
32
33
|
*
|
|
33
34
|
* @example
|
|
34
35
|
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
@@ -38,12 +39,12 @@ export type ReactTable<
|
|
|
38
39
|
* </table.Subscribe>
|
|
39
40
|
*
|
|
40
41
|
* @example
|
|
41
|
-
* <table.Subscribe
|
|
42
|
+
* <table.Subscribe source={table.atoms.rowSelection}>
|
|
42
43
|
* {(rowSelection) => <div>...</div>}
|
|
43
44
|
* </table.Subscribe>
|
|
44
45
|
*
|
|
45
46
|
* @example
|
|
46
|
-
* <table.Subscribe
|
|
47
|
+
* <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
|
|
47
48
|
* {() => <tr key={row.id}>...</tr>}
|
|
48
49
|
* </table.Subscribe>
|
|
49
50
|
*/
|
|
@@ -51,21 +52,21 @@ export type ReactTable<
|
|
|
51
52
|
* Overloads (not a single union) so `selector` callbacks get correct contextual
|
|
52
53
|
* types in JSX; a union of two `selector` signatures degrades to implicit `any`.
|
|
53
54
|
*
|
|
54
|
-
*
|
|
55
|
+
* Source **without** `selector` is a separate overload so children receive `TSourceValue`
|
|
55
56
|
* (identity projection). If `selector` were optional on one overload, `TSubSelected`
|
|
56
|
-
* would default to `unknown` instead of inferring from the
|
|
57
|
+
* would default to `unknown` instead of inferring from the source.
|
|
57
58
|
*
|
|
58
|
-
* The **
|
|
59
|
+
* The **source** overloads are listed first so `TSourceValue` is inferred from `source`.
|
|
59
60
|
*/
|
|
60
61
|
Subscribe: {
|
|
61
|
-
<
|
|
62
|
-
|
|
62
|
+
<TSourceValue>(props: {
|
|
63
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
|
|
63
64
|
selector?: undefined
|
|
64
|
-
children: ((state:
|
|
65
|
+
children: ((state: TSourceValue) => ReactNode) | ReactNode
|
|
65
66
|
}): ReturnType<FunctionComponent>
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
selector: (state:
|
|
67
|
+
<TSourceValue, TSubSelected>(props: {
|
|
68
|
+
source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
|
|
69
|
+
selector: (state: TSourceValue) => TSubSelected
|
|
69
70
|
children: ((state: TSubSelected) => ReactNode) | ReactNode
|
|
70
71
|
}): ReturnType<FunctionComponent>
|
|
71
72
|
<TSubSelected>(
|