@tanstack/react-table 9.0.0-alpha.42 → 9.0.0-alpha.44

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.
@@ -5,7 +5,8 @@ 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)("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_react_store.shallow });
8
+ const selectFn = props.selector ?? ((x) => x);
9
+ const selected = (0, _tanstack_react_store.useSelector)(props.source, selectFn, { compare: _tanstack_react_store.shallow });
9
10
  return typeof props.children === "function" ? props.children(selected) : props.children;
10
11
  }
11
12
 
@@ -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 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"}
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 Atom,\n ReadonlyAtom,\n ReadonlyStore,\n Store,\n} from '@tanstack/react-store'\nimport type { TableFeatures, TableState } from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type SubscribeSource<TValue> =\n | Atom<TValue>\n | ReadonlyAtom<TValue>\n | Store<TValue>\n | ReadonlyStore<TValue>\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 TSelected,\n> = {\n source: SubscribeSource<TableState<TFeatures>>\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<TSourceValue> = {\n source: SubscribeSource<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<TSourceValue, TSelected> = {\n source: SubscribeSource<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<TSourceValue, TSelected = TSourceValue> =\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TSelected>\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, 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 source={table.store} 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 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 * 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<TSourceValue>(\n props: SubscribePropsWithSourceIdentity<TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<TSourceValue, TSelected>(\n props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<TFeatures extends TableFeatures, TSelected>(\n props: SubscribePropsWithStore<TFeatures, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const selectFn = props.selector ?? ((x: unknown) => x)\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n props.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":";;;;;;AAqIA,SAAgB,UAKd,OAC+B;CAC/B,MAAM,WAAW,MAAM,cAAc,MAAe;CAEpD,MAAM,kDAEJ,MAAM,QACN,UACA,EACE,SAASA,+BACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAA6C,SAAS,GAC7D,MAAM"}
@@ -1,14 +1,15 @@
1
1
  import { FunctionComponent, ReactNode } from "react";
2
- import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
3
- import { Atom, ReadonlyAtom } from "@tanstack/react-store";
2
+ import { TableFeatures, TableState } from "@tanstack/table-core";
3
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/react-store";
4
4
 
5
5
  //#region src/Subscribe.d.ts
6
+ type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
6
7
  /**
7
8
  * Subscribe to `table.store` (full table state). The selector receives the full
8
9
  * {@link TableState}.
9
10
  */
10
- type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
11
- table: Table<TFeatures, TData>;
11
+ type SubscribePropsWithStore<TFeatures extends TableFeatures, TSelected> = {
12
+ source: SubscribeSource<TableState<TFeatures>>;
12
13
  /**
13
14
  * Select from full table state. Re-renders when the selected value changes
14
15
  * (shallow compare).
@@ -24,9 +25,8 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
24
25
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
25
26
  * selector — children receive `TSourceValue`.
26
27
  */
27
- type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
28
- table: Table<TFeatures, TData>;
29
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
28
+ type SubscribePropsWithSourceIdentity<TSourceValue> = {
29
+ source: SubscribeSource<TSourceValue>;
30
30
  selector?: undefined;
31
31
  children: ((state: TSourceValue) => ReactNode) | ReactNode;
32
32
  };
@@ -34,9 +34,8 @@ type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData ext
34
34
  * Subscribe to a projected value from a source (atom or store). The selector
35
35
  * receives the source value; children receive the projected `TSelected`.
36
36
  */
37
- type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
38
- table: Table<TFeatures, TData>;
39
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
37
+ type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
38
+ source: SubscribeSource<TSourceValue>;
40
39
  selector: (state: TSourceValue) => TSelected;
41
40
  children: ((state: TSelected) => ReactNode) | ReactNode;
42
41
  };
@@ -45,8 +44,8 @@ type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData
45
44
  * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
46
45
  * for clearer inference when `selector` is omitted.
47
46
  */
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>;
47
+ type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
48
+ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TSelected> | SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
50
49
  /**
51
50
  * A React component that allows you to subscribe to the table state.
52
51
  *
@@ -58,7 +57,7 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
58
57
  * @example
59
58
  * ```tsx
60
59
  * // As a standalone component — full store
61
- * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
60
+ * <Subscribe source={table.store} selector={(state) => ({ rowSelection: state.rowSelection })}>
62
61
  * {({ rowSelection }) => (
63
62
  * <div>Selected rows: {Object.keys(rowSelection).length}</div>
64
63
  * )}
@@ -68,7 +67,7 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
68
67
  * @example
69
68
  * ```tsx
70
69
  * // Entire source (atom or store) — no selector
71
- * <Subscribe table={table} source={table.atoms.rowSelection}>
70
+ * <Subscribe source={table.atoms.rowSelection}>
72
71
  * {(rowSelection) => <div>...</div>}
73
72
  * </Subscribe>
74
73
  * ```
@@ -77,7 +76,6 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
77
76
  * ```tsx
78
77
  * // Project source value (e.g. one row’s selection)
79
78
  * <Subscribe
80
- * table={table}
81
79
  * source={table.atoms.rowSelection}
82
80
  * selector={(rowSelection) => rowSelection?.[row.id]}
83
81
  * >
@@ -95,9 +93,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
95
93
  * </table.Subscribe>
96
94
  * ```
97
95
  */
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
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
96
+ declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ReturnType<FunctionComponent>;
97
+ declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ReturnType<FunctionComponent>;
98
+ declare function Subscribe<TFeatures extends TableFeatures, TSelected>(props: SubscribePropsWithStore<TFeatures, TSelected>): ReturnType<FunctionComponent>;
101
99
  //#endregion
102
- export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
100
+ export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource };
103
101
  //# sourceMappingURL=Subscribe.d.cts.map
@@ -1,14 +1,15 @@
1
- import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
1
+ import { TableFeatures, TableState } from "@tanstack/table-core";
2
2
  import { FunctionComponent, ReactNode } from "react";
3
- import { Atom, ReadonlyAtom } from "@tanstack/react-store";
3
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/react-store";
4
4
 
5
5
  //#region src/Subscribe.d.ts
6
+ type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
6
7
  /**
7
8
  * Subscribe to `table.store` (full table state). The selector receives the full
8
9
  * {@link TableState}.
9
10
  */
10
- type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
11
- table: Table<TFeatures, TData>;
11
+ type SubscribePropsWithStore<TFeatures extends TableFeatures, TSelected> = {
12
+ source: SubscribeSource<TableState<TFeatures>>;
12
13
  /**
13
14
  * Select from full table state. Re-renders when the selected value changes
14
15
  * (shallow compare).
@@ -24,9 +25,8 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
24
25
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
25
26
  * selector — children receive `TSourceValue`.
26
27
  */
27
- type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
28
- table: Table<TFeatures, TData>;
29
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
28
+ type SubscribePropsWithSourceIdentity<TSourceValue> = {
29
+ source: SubscribeSource<TSourceValue>;
30
30
  selector?: undefined;
31
31
  children: ((state: TSourceValue) => ReactNode) | ReactNode;
32
32
  };
@@ -34,9 +34,8 @@ type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData ext
34
34
  * Subscribe to a projected value from a source (atom or store). The selector
35
35
  * receives the source value; children receive the projected `TSelected`.
36
36
  */
37
- type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
38
- table: Table<TFeatures, TData>;
39
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
37
+ type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
38
+ source: SubscribeSource<TSourceValue>;
40
39
  selector: (state: TSourceValue) => TSelected;
41
40
  children: ((state: TSelected) => ReactNode) | ReactNode;
42
41
  };
@@ -45,8 +44,8 @@ type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData
45
44
  * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
46
45
  * for clearer inference when `selector` is omitted.
47
46
  */
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>;
47
+ type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
48
+ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TSelected> | SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
50
49
  /**
51
50
  * A React component that allows you to subscribe to the table state.
52
51
  *
@@ -58,7 +57,7 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
58
57
  * @example
59
58
  * ```tsx
60
59
  * // As a standalone component — full store
61
- * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
60
+ * <Subscribe source={table.store} selector={(state) => ({ rowSelection: state.rowSelection })}>
62
61
  * {({ rowSelection }) => (
63
62
  * <div>Selected rows: {Object.keys(rowSelection).length}</div>
64
63
  * )}
@@ -68,7 +67,7 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
68
67
  * @example
69
68
  * ```tsx
70
69
  * // Entire source (atom or store) — no selector
71
- * <Subscribe table={table} source={table.atoms.rowSelection}>
70
+ * <Subscribe source={table.atoms.rowSelection}>
72
71
  * {(rowSelection) => <div>...</div>}
73
72
  * </Subscribe>
74
73
  * ```
@@ -77,7 +76,6 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
77
76
  * ```tsx
78
77
  * // Project source value (e.g. one row’s selection)
79
78
  * <Subscribe
80
- * table={table}
81
79
  * source={table.atoms.rowSelection}
82
80
  * selector={(rowSelection) => rowSelection?.[row.id]}
83
81
  * >
@@ -95,9 +93,9 @@ type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSel
95
93
  * </table.Subscribe>
96
94
  * ```
97
95
  */
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
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ReturnType<FunctionComponent>;
96
+ declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ReturnType<FunctionComponent>;
97
+ declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ReturnType<FunctionComponent>;
98
+ declare function Subscribe<TFeatures extends TableFeatures, TSelected>(props: SubscribePropsWithStore<TFeatures, TSelected>): ReturnType<FunctionComponent>;
101
99
  //#endregion
102
- export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
100
+ export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource };
103
101
  //# sourceMappingURL=Subscribe.d.ts.map
package/dist/Subscribe.js CHANGED
@@ -4,7 +4,8 @@ import { shallow, useSelector } from "@tanstack/react-store";
4
4
 
5
5
  //#region src/Subscribe.ts
6
6
  function Subscribe(props) {
7
- const selected = useSelector("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
7
+ const selectFn = props.selector ?? ((x) => x);
8
+ const selected = useSelector(props.source, selectFn, { compare: shallow });
8
9
  return typeof props.children === "function" ? props.children(selected) : props.children;
9
10
  }
10
11
 
@@ -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 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
+ {"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["'use client'\n\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport type {\n Atom,\n ReadonlyAtom,\n ReadonlyStore,\n Store,\n} from '@tanstack/react-store'\nimport type { TableFeatures, TableState } from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type SubscribeSource<TValue> =\n | Atom<TValue>\n | ReadonlyAtom<TValue>\n | Store<TValue>\n | ReadonlyStore<TValue>\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 TSelected,\n> = {\n source: SubscribeSource<TableState<TFeatures>>\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<TSourceValue> = {\n source: SubscribeSource<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<TSourceValue, TSelected> = {\n source: SubscribeSource<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<TSourceValue, TSelected = TSourceValue> =\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TSelected>\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, 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 source={table.store} 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 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 * 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<TSourceValue>(\n props: SubscribePropsWithSourceIdentity<TSourceValue>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<TSourceValue, TSelected>(\n props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<TFeatures extends TableFeatures, TSelected>(\n props: SubscribePropsWithStore<TFeatures, TSelected>,\n): ReturnType<FunctionComponent>\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TSelected, TSourceValue>,\n): ReturnType<FunctionComponent> {\n const selectFn = props.selector ?? ((x: unknown) => x)\n\n const selected = useSelector(\n // Atom and store share the same selection protocol; union args need a widen for TS.\n props.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":";;;;;AAqIA,SAAgB,UAKd,OAC+B;CAC/B,MAAM,WAAW,MAAM,cAAc,MAAe;CAEpD,MAAM,WAAW,YAEf,MAAM,QACN,UACA,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, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore } from "./Subscribe.cjs";
2
+ import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource } from "./Subscribe.cjs";
3
3
  import { ReactTable, useTable } from "./useTable.cjs";
4
4
  import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, 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, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
6
+ export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource, 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, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore } from "./Subscribe.js";
2
+ import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource } from "./Subscribe.js";
3
3
  import { ReactTable, useTable } from "./useTable.js";
4
4
  import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, 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, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
6
+ export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppReactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, ReactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource, createTableHook, flexRender, useTable };
@@ -0,0 +1,21 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let _tanstack_react_store = require("@tanstack/react-store");
3
+
4
+ //#region src/reactivity.ts
5
+ function reactReactivity() {
6
+ return {
7
+ createOptionsStore: false,
8
+ batch: _tanstack_react_store.batch,
9
+ untrack: (fn) => fn(),
10
+ createReadonlyAtom: (fn, options) => {
11
+ return (0, _tanstack_react_store.createAtom)(() => fn(), { compare: options === null || options === void 0 ? void 0 : options.compare });
12
+ },
13
+ createWritableAtom: (value, options) => {
14
+ return (0, _tanstack_react_store.createAtom)(value, { compare: options === null || options === void 0 ? void 0 : options.compare });
15
+ }
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ exports.reactReactivity = reactReactivity;
21
+ //# sourceMappingURL=reactivity.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactivity.cjs","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/react-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\nexport function reactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,kBAA2C;AACzD,QAAO;EACL,oBAAoB;EACpB;EACA,UAAU,OAAO,IAAI;EACrB,qBAAwB,IAAa,YAAkC;AACrE,sDAAwB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAwB,OAAU,YAAkC;AAClE,gDAAkB,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
@@ -0,0 +1,20 @@
1
+ import { batch, createAtom } from "@tanstack/react-store";
2
+
3
+ //#region src/reactivity.ts
4
+ function reactReactivity() {
5
+ return {
6
+ createOptionsStore: false,
7
+ batch,
8
+ untrack: (fn) => fn(),
9
+ createReadonlyAtom: (fn, options) => {
10
+ return createAtom(() => fn(), { compare: options === null || options === void 0 ? void 0 : options.compare });
11
+ },
12
+ createWritableAtom: (value, options) => {
13
+ return createAtom(value, { compare: options === null || options === void 0 ? void 0 : options.compare });
14
+ }
15
+ };
16
+ }
17
+
18
+ //#endregion
19
+ export { reactReactivity };
20
+ //# sourceMappingURL=reactivity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactivity.js","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/react-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\nexport function reactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n"],"mappings":";;;AAMA,SAAgB,kBAA2C;AACzD,QAAO;EACL,oBAAoB;EACpB;EACA,UAAU,OAAO,IAAI;EACrB,qBAAwB,IAAa,YAAkC;AACrE,UAAO,iBAAiB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAwB,OAAU,YAAkC;AAClE,UAAO,WAAW,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
package/dist/useTable.cjs CHANGED
@@ -3,10 +3,10 @@
3
3
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
4
4
  const require_FlexRender = require('./FlexRender.cjs');
5
5
  const require_Subscribe = require('./Subscribe.cjs');
6
+ const require_reactivity = require('./reactivity.cjs');
6
7
  let _tanstack_table_core = require("@tanstack/table-core");
7
8
  let react = require("react");
8
9
  let _tanstack_react_store = require("@tanstack/react-store");
9
- let _tanstack_table_core_reactivity = require("@tanstack/table-core/reactivity");
10
10
 
11
11
  //#region src/useTable.ts
12
12
  function useTable(tableOptions, selector = () => ({})) {
@@ -14,34 +14,32 @@ function useTable(tableOptions, selector = () => ({})) {
14
14
  const tableInstance = (0, _tanstack_table_core.constructTable)({
15
15
  ...tableOptions,
16
16
  _features: {
17
- coreReativityFeature: (0, _tanstack_table_core_reactivity.constructReactivityBindings)(),
17
+ coreReativityFeature: require_reactivity.reactReactivity(),
18
18
  ...tableOptions._features
19
19
  }
20
20
  });
21
21
  tableInstance.Subscribe = ((props) => {
22
+ const source = props.source ?? tableInstance.store;
22
23
  return require_Subscribe.Subscribe({
23
24
  ...props,
24
- table: tableInstance
25
+ source
25
26
  });
26
27
  });
27
28
  tableInstance.FlexRender = require_FlexRender.FlexRender;
28
29
  return tableInstance;
29
30
  });
30
- (0, react.useEffect)(() => {
31
- table.setOptions((prev) => ({
32
- ...prev,
33
- ...tableOptions
34
- }));
35
- }, [table, tableOptions]);
31
+ table.setOptions((prev) => ({
32
+ ...prev,
33
+ ...tableOptions
34
+ }));
36
35
  const state = (0, _tanstack_react_store.useSelector)(table.store, selector, { compare: _tanstack_react_store.shallow });
37
- const options = (0, _tanstack_react_store.useSelector)(table.optionsStore, (options) => options, { compare: _tanstack_react_store.shallow });
38
36
  return (0, react.useMemo)(() => ({
39
37
  ...table,
40
- options,
38
+ options: tableOptions,
41
39
  state
42
40
  }), [
43
41
  table,
44
- options,
42
+ tableOptions,
45
43
  state
46
44
  ]);
47
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { constructReactivityBindings } from '@tanstack/table-core/reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: constructReactivityBindings(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n useEffect(() => {\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n }, [table, tableOptions])\n\n const state = useSelector(table.store, selector, { compare: shallow })\n const options = useSelector(table.optionsStore, (options) => options, {\n compare: shallow,\n })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options,\n state,\n }),\n [table, options, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;;AAkHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B;GACnC,GAAG;GACH,WAAW;IACT,wFAAmD;IACnD,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAOA,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAEF,4BAAgB;AACd,QAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;GACJ,EAAE;IACF,CAAC,OAAO,aAAa,CAAC;CAEzB,MAAM,+CAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,+BAAS,CAAC;CACtE,MAAM,iDAAsB,MAAM,eAAe,YAAY,SAAS,EACpE,SAASA,+BACV,CAAC;AAIF,kCACS;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAS;EAAM,CACxB"}
1
+ {"version":3,"file":"useTable.cjs","names":["reactReactivity","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 { reactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,\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}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: reactReactivity(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n const source = props.source ?? tableInstance.store\n\n return Subscribe({\n ...props,\n source,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;;;;AA2GA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B;GACnC,GAAG;GACH,WAAW;IACT,sBAAsBA,oCAAiB;IACvC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;AAE7C,UAAOC,4BAAU;IACf,GAAG;IACH;IACD,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,+CAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,+BAAS,CAAC;AAItE,kCACS;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
@@ -1,8 +1,7 @@
1
1
  import { FlexRenderProps } from "./FlexRender.cjs";
2
- import { SubscribePropsWithStore } from "./Subscribe.cjs";
2
+ import { SubscribePropsWithStore, SubscribeSource } from "./Subscribe.cjs";
3
3
  import { FunctionComponent, ReactNode } from "react";
4
4
  import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
5
- import { Atom, ReadonlyAtom } from "@tanstack/react-store";
6
5
 
7
6
  //#region src/useTable.d.ts
8
7
  type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
@@ -43,16 +42,16 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
43
42
  */
44
43
  Subscribe: {
45
44
  <TSourceValue>(props: {
46
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
45
+ source: SubscribeSource<TSourceValue>;
47
46
  selector?: undefined;
48
47
  children: ((state: TSourceValue) => ReactNode) | ReactNode;
49
48
  }): ReturnType<FunctionComponent>;
50
49
  <TSourceValue, TSubSelected>(props: {
51
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
50
+ source: SubscribeSource<TSourceValue>;
52
51
  selector: (state: TSourceValue) => TSubSelected;
53
52
  children: ((state: TSubSelected) => ReactNode) | ReactNode;
54
53
  }): ReturnType<FunctionComponent>;
55
- <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
54
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>): ReturnType<FunctionComponent>;
56
55
  };
57
56
  /**
58
57
  * A React component that renders headers, cells, or footers with custom markup.
@@ -81,10 +80,7 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
81
80
  *
82
81
  * console.log(table.state.globalFilter)
83
82
  */
84
- readonly state: Readonly<TSelected> & {
85
- columns: TableOptions<TFeatures, TData>['columns'];
86
- data: TableOptions<TFeatures, TData>['data'];
87
- };
83
+ readonly state: Readonly<TSelected>;
88
84
  };
89
85
  declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): ReactTable<TFeatures, TData, TSelected>;
90
86
  //#endregion
@@ -1,8 +1,7 @@
1
1
  import { FlexRenderProps } from "./FlexRender.js";
2
- import { SubscribePropsWithStore } from "./Subscribe.js";
2
+ import { SubscribePropsWithStore, SubscribeSource } from "./Subscribe.js";
3
3
  import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
4
4
  import { FunctionComponent, ReactNode } from "react";
5
- import { Atom, ReadonlyAtom } from "@tanstack/react-store";
6
5
 
7
6
  //#region src/useTable.d.ts
8
7
  type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
@@ -43,16 +42,16 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
43
42
  */
44
43
  Subscribe: {
45
44
  <TSourceValue>(props: {
46
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
45
+ source: SubscribeSource<TSourceValue>;
47
46
  selector?: undefined;
48
47
  children: ((state: TSourceValue) => ReactNode) | ReactNode;
49
48
  }): ReturnType<FunctionComponent>;
50
49
  <TSourceValue, TSubSelected>(props: {
51
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
50
+ source: SubscribeSource<TSourceValue>;
52
51
  selector: (state: TSourceValue) => TSubSelected;
53
52
  children: ((state: TSubSelected) => ReactNode) | ReactNode;
54
53
  }): ReturnType<FunctionComponent>;
55
- <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
54
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>): ReturnType<FunctionComponent>;
56
55
  };
57
56
  /**
58
57
  * A React component that renders headers, cells, or footers with custom markup.
@@ -81,10 +80,7 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
81
80
  *
82
81
  * console.log(table.state.globalFilter)
83
82
  */
84
- readonly state: Readonly<TSelected> & {
85
- columns: TableOptions<TFeatures, TData>['columns'];
86
- data: TableOptions<TFeatures, TData>['data'];
87
- };
83
+ readonly state: Readonly<TSelected>;
88
84
  };
89
85
  declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): ReactTable<TFeatures, TData, TSelected>;
90
86
  //#endregion
package/dist/useTable.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  import { FlexRender } from "./FlexRender.js";
4
4
  import { Subscribe } from "./Subscribe.js";
5
+ import { reactReactivity } from "./reactivity.js";
5
6
  import { constructTable } from "@tanstack/table-core";
6
- import { useEffect, useMemo, useState } from "react";
7
+ import { useMemo, useState } from "react";
7
8
  import { shallow, useSelector } from "@tanstack/react-store";
8
- import { constructReactivityBindings } from "@tanstack/table-core/reactivity";
9
9
 
10
10
  //#region src/useTable.ts
11
11
  function useTable(tableOptions, selector = () => ({})) {
@@ -13,34 +13,32 @@ function useTable(tableOptions, selector = () => ({})) {
13
13
  const tableInstance = constructTable({
14
14
  ...tableOptions,
15
15
  _features: {
16
- coreReativityFeature: constructReactivityBindings(),
16
+ coreReativityFeature: reactReactivity(),
17
17
  ...tableOptions._features
18
18
  }
19
19
  });
20
20
  tableInstance.Subscribe = ((props) => {
21
+ const source = props.source ?? tableInstance.store;
21
22
  return Subscribe({
22
23
  ...props,
23
- table: tableInstance
24
+ source
24
25
  });
25
26
  });
26
27
  tableInstance.FlexRender = FlexRender;
27
28
  return tableInstance;
28
29
  });
29
- useEffect(() => {
30
- table.setOptions((prev) => ({
31
- ...prev,
32
- ...tableOptions
33
- }));
34
- }, [table, tableOptions]);
30
+ table.setOptions((prev) => ({
31
+ ...prev,
32
+ ...tableOptions
33
+ }));
35
34
  const state = useSelector(table.store, selector, { compare: shallow });
36
- const options = useSelector(table.optionsStore, (options) => options, { compare: shallow });
37
35
  return useMemo(() => ({
38
36
  ...table,
39
- options,
37
+ options: tableOptions,
40
38
  state
41
39
  }), [
42
40
  table,
43
- options,
41
+ tableOptions,
44
42
  state
45
43
  ]);
46
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { constructReactivityBindings } from '@tanstack/table-core/reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: constructReactivityBindings(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n useEffect(() => {\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n }, [table, tableOptions])\n\n const state = useSelector(table.store, selector, { compare: shallow })\n const options = useSelector(table.optionsStore, (options) => options, {\n compare: shallow,\n })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options,\n state,\n }),\n [table, options, state],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AAkHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe;GACnC,GAAG;GACH,WAAW;IACT,sBAAsB,6BAA6B;IACnD,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAEF,iBAAgB;AACd,QAAM,YAAY,UAAU;GAC1B,GAAG;GACH,GAAG;GACJ,EAAE;IACF,CAAC,OAAO,aAAa,CAAC;CAEzB,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CACtE,MAAM,UAAU,YAAY,MAAM,eAAe,YAAY,SAAS,EACpE,SAAS,SACV,CAAC;AAIF,QAAO,eACE;EACL,GAAG;EACH;EACA;EACD,GACD;EAAC;EAAO;EAAS;EAAM,CACxB"}
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 { reactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Source **without** `selector` is a separate overload so children receive `TSourceValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the source.\n *\n * The **source** overloads are listed first so `TSourceValue` is inferred from `source`.\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSourceValue, TSubSelected>(props: {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,\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}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: reactReactivity(),\n ...tableOptions._features,\n },\n }) as ReactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n const source = props.source ?? tableInstance.store\n\n return Subscribe({\n ...props,\n source,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n // we know this is not the most efficient way to return the table,\n // but it is required for the react compiler to work\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;;;AA2GA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe;GACnC,GAAG;GACH,WAAW;IACT,sBAAsB,iBAAiB;IACvC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;AAE7C,UAAO,UAAU;IACf,GAAG;IACH;IACD,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAItE,QAAO,eACE;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
- "version": "9.0.0-alpha.42",
3
+ "version": "9.0.0-alpha.44",
4
4
  "description": "Headless UI for building powerful tables & datagrids for React.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "@tanstack/react-store": "^0.11.0",
56
- "@tanstack/table-core": "9.0.0-alpha.42"
56
+ "@tanstack/table-core": "9.0.0-alpha.43"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@eslint-react/eslint-plugin": "^5.7.0",
package/src/Subscribe.ts CHANGED
@@ -1,25 +1,30 @@
1
1
  'use client'
2
2
 
3
3
  import { shallow, useSelector } from '@tanstack/react-store'
4
- import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
5
4
  import type {
6
- RowData,
7
- Table,
8
- TableFeatures,
9
- TableState,
10
- } from '@tanstack/table-core'
5
+ Atom,
6
+ ReadonlyAtom,
7
+ ReadonlyStore,
8
+ Store,
9
+ } from '@tanstack/react-store'
10
+ import type { TableFeatures, TableState } from '@tanstack/table-core'
11
11
  import type { FunctionComponent, ReactNode } from 'react'
12
12
 
13
+ export type SubscribeSource<TValue> =
14
+ | Atom<TValue>
15
+ | ReadonlyAtom<TValue>
16
+ | Store<TValue>
17
+ | ReadonlyStore<TValue>
18
+
13
19
  /**
14
20
  * Subscribe to `table.store` (full table state). The selector receives the full
15
21
  * {@link TableState}.
16
22
  */
17
23
  export type SubscribePropsWithStore<
18
24
  TFeatures extends TableFeatures,
19
- TData extends RowData,
20
25
  TSelected,
21
26
  > = {
22
- table: Table<TFeatures, TData>
27
+ source: SubscribeSource<TableState<TFeatures>>
23
28
  /**
24
29
  * Select from full table state. Re-renders when the selected value changes
25
30
  * (shallow compare).
@@ -36,13 +41,8 @@ export type SubscribePropsWithStore<
36
41
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
37
42
  * selector — children receive `TSourceValue`.
38
43
  */
39
- export type SubscribePropsWithSourceIdentity<
40
- TFeatures extends TableFeatures,
41
- TData extends RowData,
42
- TSourceValue,
43
- > = {
44
- table: Table<TFeatures, TData>
45
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
44
+ export type SubscribePropsWithSourceIdentity<TSourceValue> = {
45
+ source: SubscribeSource<TSourceValue>
46
46
  selector?: undefined
47
47
  children: ((state: TSourceValue) => ReactNode) | ReactNode
48
48
  }
@@ -51,14 +51,8 @@ export type SubscribePropsWithSourceIdentity<
51
51
  * Subscribe to a projected value from a source (atom or store). The selector
52
52
  * receives the source value; children receive the projected `TSelected`.
53
53
  */
54
- export type SubscribePropsWithSourceWithSelector<
55
- TFeatures extends TableFeatures,
56
- TData extends RowData,
57
- TSourceValue,
58
- TSelected,
59
- > = {
60
- table: Table<TFeatures, TData>
61
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
54
+ export type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
55
+ source: SubscribeSource<TSourceValue>
62
56
  selector: (state: TSourceValue) => TSelected
63
57
  children: ((state: TSelected) => ReactNode) | ReactNode
64
58
  }
@@ -68,34 +62,18 @@ export type SubscribePropsWithSourceWithSelector<
68
62
  * {@link SubscribePropsWithSourceIdentity} or {@link SubscribePropsWithSourceWithSelector}
69
63
  * for clearer inference when `selector` is omitted.
70
64
  */
71
- export type SubscribePropsWithSource<
72
- TFeatures extends TableFeatures,
73
- TData extends RowData,
74
- TSourceValue,
75
- TSelected = TSourceValue,
76
- > =
77
- | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
78
- | SubscribePropsWithSourceWithSelector<
79
- TFeatures,
80
- TData,
81
- TSourceValue,
82
- TSelected
83
- >
65
+ export type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> =
66
+ | SubscribePropsWithSourceIdentity<TSourceValue>
67
+ | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
84
68
 
85
69
  export type SubscribeProps<
86
70
  TFeatures extends TableFeatures,
87
- TData extends RowData,
88
71
  TSelected = unknown,
89
72
  TSourceValue = unknown,
90
73
  > =
91
- | SubscribePropsWithStore<TFeatures, TData, TSelected>
92
- | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
93
- | SubscribePropsWithSourceWithSelector<
94
- TFeatures,
95
- TData,
96
- TSourceValue,
97
- TSelected
98
- >
74
+ | SubscribePropsWithStore<TFeatures, TSelected>
75
+ | SubscribePropsWithSourceIdentity<TSourceValue>
76
+ | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
99
77
 
100
78
  /**
101
79
  * A React component that allows you to subscribe to the table state.
@@ -108,7 +86,7 @@ export type SubscribeProps<
108
86
  * @example
109
87
  * ```tsx
110
88
  * // As a standalone component — full store
111
- * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
89
+ * <Subscribe source={table.store} selector={(state) => ({ rowSelection: state.rowSelection })}>
112
90
  * {({ rowSelection }) => (
113
91
  * <div>Selected rows: {Object.keys(rowSelection).length}</div>
114
92
  * )}
@@ -118,7 +96,7 @@ export type SubscribeProps<
118
96
  * @example
119
97
  * ```tsx
120
98
  * // Entire source (atom or store) — no selector
121
- * <Subscribe table={table} source={table.atoms.rowSelection}>
99
+ * <Subscribe source={table.atoms.rowSelection}>
122
100
  * {(rowSelection) => <div>...</div>}
123
101
  * </Subscribe>
124
102
  * ```
@@ -127,7 +105,6 @@ export type SubscribeProps<
127
105
  * ```tsx
128
106
  * // Project source value (e.g. one row’s selection)
129
107
  * <Subscribe
130
- * table={table}
131
108
  * source={table.atoms.rowSelection}
132
109
  * selector={(rowSelection) => rowSelection?.[row.id]}
133
110
  * >
@@ -145,48 +122,27 @@ export type SubscribeProps<
145
122
  * </table.Subscribe>
146
123
  * ```
147
124
  */
148
- export function Subscribe<
149
- TFeatures extends TableFeatures,
150
- TData extends RowData,
151
- TSourceValue,
152
- >(
153
- props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,
125
+ export function Subscribe<TSourceValue>(
126
+ props: SubscribePropsWithSourceIdentity<TSourceValue>,
154
127
  ): ReturnType<FunctionComponent>
155
- export function Subscribe<
156
- TFeatures extends TableFeatures,
157
- TData extends RowData,
158
- TSourceValue,
159
- TSelected,
160
- >(
161
- props: SubscribePropsWithSourceWithSelector<
162
- TFeatures,
163
- TData,
164
- TSourceValue,
165
- TSelected
166
- >,
128
+ export function Subscribe<TSourceValue, TSelected>(
129
+ props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,
167
130
  ): ReturnType<FunctionComponent>
168
- export function Subscribe<
169
- TFeatures extends TableFeatures,
170
- TData extends RowData,
171
- TSelected,
172
- >(
173
- props: SubscribePropsWithStore<TFeatures, TData, TSelected>,
131
+ export function Subscribe<TFeatures extends TableFeatures, TSelected>(
132
+ props: SubscribePropsWithStore<TFeatures, TSelected>,
174
133
  ): ReturnType<FunctionComponent>
175
134
  export function Subscribe<
176
135
  TFeatures extends TableFeatures,
177
- TData extends RowData,
178
136
  TSelected,
179
137
  TSourceValue,
180
138
  >(
181
- props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,
139
+ props: SubscribeProps<TFeatures, TSelected, TSourceValue>,
182
140
  ): ReturnType<FunctionComponent> {
183
- const source = 'source' in props ? props.source : props.table.store
184
- const selectFn =
185
- 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector
141
+ const selectFn = props.selector ?? ((x: unknown) => x)
186
142
 
187
143
  const selected = useSelector(
188
144
  // Atom and store share the same selection protocol; union args need a widen for TS.
189
- source,
145
+ props.source,
190
146
  selectFn as Parameters<typeof useSelector>[1],
191
147
  {
192
148
  compare: shallow,
@@ -0,0 +1,23 @@
1
+ import { batch, createAtom } from '@tanstack/react-store'
2
+ import type {
3
+ TableAtomOptions,
4
+ TableReactivityBindings,
5
+ } from '@tanstack/table-core/reactivity'
6
+
7
+ export function reactReactivity(): TableReactivityBindings {
8
+ return {
9
+ createOptionsStore: false,
10
+ batch,
11
+ untrack: (fn) => fn(),
12
+ createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {
13
+ return createAtom(() => fn(), {
14
+ compare: options?.compare,
15
+ })
16
+ },
17
+ createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {
18
+ return createAtom(value, {
19
+ compare: options?.compare,
20
+ })
21
+ },
22
+ }
23
+ }
package/src/useTable.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  'use client'
2
2
 
3
- import { useEffect, useMemo, useState } from 'react'
3
+ import { useMemo, useState } from 'react'
4
4
  import { constructTable } from '@tanstack/table-core'
5
5
  import { shallow, useSelector } from '@tanstack/react-store'
6
- import { constructReactivityBindings } from '@tanstack/table-core/reactivity'
6
+ import { reactReactivity } from './reactivity'
7
7
  import { FlexRender } from './FlexRender'
8
8
  import { Subscribe } from './Subscribe'
9
- import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
10
9
  import type { FlexRenderProps } from './FlexRender'
11
- import type { SubscribePropsWithStore } from './Subscribe'
10
+ import type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'
12
11
  import type {
13
12
  CellData,
14
13
  RowData,
@@ -61,20 +60,17 @@ export type ReactTable<
61
60
  */
62
61
  Subscribe: {
63
62
  <TSourceValue>(props: {
64
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
63
+ source: SubscribeSource<TSourceValue>
65
64
  selector?: undefined
66
65
  children: ((state: TSourceValue) => ReactNode) | ReactNode
67
66
  }): ReturnType<FunctionComponent>
68
67
  <TSourceValue, TSubSelected>(props: {
69
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
68
+ source: SubscribeSource<TSourceValue>
70
69
  selector: (state: TSourceValue) => TSubSelected
71
70
  children: ((state: TSubSelected) => ReactNode) | ReactNode
72
71
  }): ReturnType<FunctionComponent>
73
72
  <TSubSelected>(
74
- props: Omit<
75
- SubscribePropsWithStore<TFeatures, TData, TSubSelected>,
76
- 'table'
77
- >,
73
+ props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,
78
74
  ): ReturnType<FunctionComponent>
79
75
  }
80
76
  /**
@@ -106,10 +102,7 @@ export type ReactTable<
106
102
  *
107
103
  * console.log(table.state.globalFilter)
108
104
  */
109
- readonly state: Readonly<TSelected> & {
110
- columns: TableOptions<TFeatures, TData>['columns']
111
- data: TableOptions<TFeatures, TData>['data']
112
- }
105
+ readonly state: Readonly<TSelected>
113
106
  }
114
107
 
115
108
  export function useTable<
@@ -125,15 +118,17 @@ export function useTable<
125
118
  const tableInstance = constructTable({
126
119
  ...tableOptions,
127
120
  _features: {
128
- coreReativityFeature: constructReactivityBindings(),
121
+ coreReativityFeature: reactReactivity(),
129
122
  ...tableOptions._features,
130
123
  },
131
124
  }) as ReactTable<TFeatures, TData, TSelected>
132
125
 
133
126
  tableInstance.Subscribe = ((props: any) => {
127
+ const source = props.source ?? tableInstance.store
128
+
134
129
  return Subscribe({
135
130
  ...props,
136
- table: tableInstance,
131
+ source,
137
132
  })
138
133
  }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']
139
134
 
@@ -142,26 +137,22 @@ export function useTable<
142
137
  return tableInstance
143
138
  })
144
139
 
145
- useEffect(() => {
146
- table.setOptions((prev) => ({
147
- ...prev,
148
- ...tableOptions,
149
- }))
150
- }, [table, tableOptions])
140
+ // sync options on every render
141
+ table.setOptions((prev) => ({
142
+ ...prev,
143
+ ...tableOptions,
144
+ }))
151
145
 
152
146
  const state = useSelector(table.store, selector, { compare: shallow })
153
- const options = useSelector(table.optionsStore, (options) => options, {
154
- compare: shallow,
155
- })
156
147
 
157
148
  // we know this is not the most efficient way to return the table,
158
149
  // but it is required for the react compiler to work
159
150
  return useMemo(
160
151
  () => ({
161
152
  ...table,
162
- options,
153
+ options: tableOptions,
163
154
  state,
164
155
  }),
165
- [table, options, state],
166
- ) as ReactTable<TFeatures, TData, TSelected>
156
+ [table, tableOptions, state],
157
+ )
167
158
  }