@tanstack/table-core 9.0.0-alpha.41 → 9.0.0-alpha.43
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/core/coreFeatures.cjs.map +1 -1
- package/dist/core/coreFeatures.d.cts +2 -1
- package/dist/core/coreFeatures.d.ts +2 -1
- package/dist/core/coreFeatures.js.map +1 -1
- package/dist/core/reactivity/coreReactivityFeature.types.d.cts +38 -0
- package/dist/core/reactivity/coreReactivityFeature.types.d.ts +38 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.cjs +19 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.cjs.map +1 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.d.cts +14 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.d.ts +14 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.js +18 -0
- package/dist/core/reactivity/coreReactivityFeature.utils.js.map +1 -0
- package/dist/core/table/constructTable.cjs +28 -20
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +28 -20
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/core/table/coreTablesFeature.types.d.cts +32 -24
- package/dist/core/table/coreTablesFeature.types.d.ts +32 -24
- package/dist/core/table/coreTablesFeature.utils.cjs +17 -3
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +2 -1
- package/dist/core/table/coreTablesFeature.utils.d.ts +2 -1
- package/dist/core/table/coreTablesFeature.utils.js +17 -4
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/reactivity.cjs +4 -0
- package/dist/reactivity.d.cts +3 -0
- package/dist/reactivity.d.ts +3 -0
- package/dist/reactivity.js +3 -0
- package/dist/static-functions.cjs +1 -0
- package/dist/static-functions.d.cts +2 -2
- package/dist/static-functions.d.ts +2 -2
- package/dist/static-functions.js +2 -2
- package/dist/store-reactivity-bindings.cjs +36 -0
- package/dist/store-reactivity-bindings.cjs.map +1 -0
- package/dist/store-reactivity-bindings.d.cts +22 -0
- package/dist/store-reactivity-bindings.d.ts +22 -0
- package/dist/store-reactivity-bindings.js +35 -0
- package/dist/store-reactivity-bindings.js.map +1 -0
- package/dist/types/TableFeatures.d.cts +1 -1
- package/dist/types/TableFeatures.d.ts +1 -1
- package/package.json +9 -1
- package/src/core/coreFeatures.ts +2 -0
- package/src/core/reactivity/coreReactivityFeature.types.ts +41 -0
- package/src/core/reactivity/coreReactivityFeature.utils.ts +29 -0
- package/src/core/table/constructTable.ts +59 -35
- package/src/core/table/coreTablesFeature.types.ts +32 -24
- package/src/core/table/coreTablesFeature.utils.ts +31 -3
- package/src/index.ts +0 -3
- package/src/reactivity.ts +2 -0
- package/src/store-reactivity-bindings.ts +35 -0
- package/src/types/TableFeatures.ts +7 -7
- package/dist/features/table-reactivity/tableReactivityFeature.cjs +0 -46
- package/dist/features/table-reactivity/tableReactivityFeature.cjs.map +0 -1
- package/dist/features/table-reactivity/tableReactivityFeature.d.cts +0 -12
- package/dist/features/table-reactivity/tableReactivityFeature.d.ts +0 -12
- package/dist/features/table-reactivity/tableReactivityFeature.js +0 -45
- package/dist/features/table-reactivity/tableReactivityFeature.js.map +0 -1
- package/src/features/table-reactivity/tableReactivityFeature.ts +0 -92
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _tanstack_store = require("@tanstack/store");
|
|
3
|
+
|
|
4
|
+
//#region src/store-reactivity-bindings.ts
|
|
5
|
+
/**
|
|
6
|
+
* TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,
|
|
7
|
+
* with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { constructTable, tableFeatures } from '@tanstack/table-core'
|
|
12
|
+
* import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'
|
|
13
|
+
*
|
|
14
|
+
* const table = constructTable({
|
|
15
|
+
* _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),
|
|
16
|
+
* // ...
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function storeReactivityBindings() {
|
|
21
|
+
return {
|
|
22
|
+
createOptionsStore: true,
|
|
23
|
+
batch: _tanstack_store.batch,
|
|
24
|
+
untrack: (fn) => fn(),
|
|
25
|
+
createReadonlyAtom: (fn, options) => {
|
|
26
|
+
return (0, _tanstack_store.createAtom)(() => fn(), { compare: options === null || options === void 0 ? void 0 : options.compare });
|
|
27
|
+
},
|
|
28
|
+
createWritableAtom: (value, options) => {
|
|
29
|
+
return (0, _tanstack_store.createAtom)(value, { compare: options === null || options === void 0 ? void 0 : options.compare });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.storeReactivityBindings = storeReactivityBindings;
|
|
36
|
+
//# sourceMappingURL=store-reactivity-bindings.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-reactivity-bindings.cjs","names":[],"sources":["../src/store-reactivity-bindings.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/store'\nimport type { TableReactivityBindings } from './core/reactivity/coreReactivityFeature.types'\n\n/**\n * TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,\n * with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.\n *\n * @example\n * ```ts\n * import { constructTable, tableFeatures } from '@tanstack/table-core'\n * import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'\n *\n * const table = constructTable({\n * _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),\n * // ...\n * })\n * ```\n */\nexport function storeReactivityBindings(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: (fn, options) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: (value, options) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,0BAAmD;AACjE,QAAO;EACL,oBAAoB;EACpB;EACA,UAAU,OAAO,IAAI;EACrB,qBAAqB,IAAI,YAAY;AACnC,gDAAwB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAqB,OAAO,YAAY;AACtC,0CAAkB,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TableReactivityBindings } from "./core/reactivity/coreReactivityFeature.types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/store-reactivity-bindings.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,
|
|
6
|
+
* with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { constructTable, tableFeatures } from '@tanstack/table-core'
|
|
11
|
+
* import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'
|
|
12
|
+
*
|
|
13
|
+
* const table = constructTable({
|
|
14
|
+
* _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),
|
|
15
|
+
* // ...
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function storeReactivityBindings(): TableReactivityBindings;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { storeReactivityBindings };
|
|
22
|
+
//# sourceMappingURL=store-reactivity-bindings.d.cts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TableReactivityBindings } from "./core/reactivity/coreReactivityFeature.types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/store-reactivity-bindings.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,
|
|
6
|
+
* with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { constructTable, tableFeatures } from '@tanstack/table-core'
|
|
11
|
+
* import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'
|
|
12
|
+
*
|
|
13
|
+
* const table = constructTable({
|
|
14
|
+
* _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),
|
|
15
|
+
* // ...
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function storeReactivityBindings(): TableReactivityBindings;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { storeReactivityBindings };
|
|
22
|
+
//# sourceMappingURL=store-reactivity-bindings.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { batch, createAtom } from "@tanstack/store";
|
|
2
|
+
|
|
3
|
+
//#region src/store-reactivity-bindings.ts
|
|
4
|
+
/**
|
|
5
|
+
* TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,
|
|
6
|
+
* with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { constructTable, tableFeatures } from '@tanstack/table-core'
|
|
11
|
+
* import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'
|
|
12
|
+
*
|
|
13
|
+
* const table = constructTable({
|
|
14
|
+
* _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),
|
|
15
|
+
* // ...
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function storeReactivityBindings() {
|
|
20
|
+
return {
|
|
21
|
+
createOptionsStore: true,
|
|
22
|
+
batch,
|
|
23
|
+
untrack: (fn) => fn(),
|
|
24
|
+
createReadonlyAtom: (fn, options) => {
|
|
25
|
+
return createAtom(() => fn(), { compare: options === null || options === void 0 ? void 0 : options.compare });
|
|
26
|
+
},
|
|
27
|
+
createWritableAtom: (value, options) => {
|
|
28
|
+
return createAtom(value, { compare: options === null || options === void 0 ? void 0 : options.compare });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { storeReactivityBindings };
|
|
35
|
+
//# sourceMappingURL=store-reactivity-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-reactivity-bindings.js","names":[],"sources":["../src/store-reactivity-bindings.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/store'\nimport type { TableReactivityBindings } from './core/reactivity/coreReactivityFeature.types'\n\n/**\n * TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,\n * with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.\n *\n * @example\n * ```ts\n * import { constructTable, tableFeatures } from '@tanstack/table-core'\n * import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'\n *\n * const table = constructTable({\n * _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),\n * // ...\n * })\n * ```\n */\nexport function storeReactivityBindings(): TableReactivityBindings {\n return {\n createOptionsStore: true,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: (fn, options) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: (value, options) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,0BAAmD;AACjE,QAAO;EACL,oBAAoB;EACpB;EACA,UAAU,OAAO,IAAI;EACrB,qBAAqB,IAAI,YAAY;AACnC,UAAO,iBAAiB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAqB,OAAO,YAAY;AACtC,UAAO,WAAW,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
|
|
@@ -8,7 +8,7 @@ import { StockFeatures } from "../features/stockFeatures.cjs";
|
|
|
8
8
|
import { Table_Internal } from "./Table.cjs";
|
|
9
9
|
|
|
10
10
|
//#region src/types/TableFeatures.d.ts
|
|
11
|
-
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
11
|
+
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: K extends 'coreReativityFeature' ? never : TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
12
12
|
interface FeatureConstructors {
|
|
13
13
|
CachedRowModel?: any;
|
|
14
14
|
Cell?: any;
|
|
@@ -8,7 +8,7 @@ import { StockFeatures } from "../features/stockFeatures.js";
|
|
|
8
8
|
import { Table_Internal } from "./Table.js";
|
|
9
9
|
|
|
10
10
|
//#region src/types/TableFeatures.d.ts
|
|
11
|
-
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
11
|
+
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: K extends 'coreReativityFeature' ? never : TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
12
12
|
interface FeatureConstructors {
|
|
13
13
|
CachedRowModel?: any;
|
|
14
14
|
Cell?: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.43",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,10 +38,18 @@
|
|
|
38
38
|
"import": "./dist/flex-render.js",
|
|
39
39
|
"require": "./dist/flex-render.cjs"
|
|
40
40
|
},
|
|
41
|
+
"./reactivity": {
|
|
42
|
+
"import": "./dist/reactivity.js",
|
|
43
|
+
"require": "./dist/reactivity.cjs"
|
|
44
|
+
},
|
|
41
45
|
"./static-functions": {
|
|
42
46
|
"import": "./dist/static-functions.js",
|
|
43
47
|
"require": "./dist/static-functions.cjs"
|
|
44
48
|
},
|
|
49
|
+
"./store-reactivity-bindings": {
|
|
50
|
+
"import": "./dist/store-reactivity-bindings.js",
|
|
51
|
+
"require": "./dist/store-reactivity-bindings.cjs"
|
|
52
|
+
},
|
|
45
53
|
"./package.json": "./package.json"
|
|
46
54
|
},
|
|
47
55
|
"sideEffects": false,
|
package/src/core/coreFeatures.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { coreHeadersFeature } from './headers/coreHeadersFeature'
|
|
|
4
4
|
import { coreRowModelsFeature } from './row-models/coreRowModelsFeature'
|
|
5
5
|
import { coreRowsFeature } from './rows/coreRowsFeature'
|
|
6
6
|
import { coreTablesFeature } from './table/coreTablesFeature'
|
|
7
|
+
import type { TableReactivityBindings } from '../reactivity'
|
|
7
8
|
|
|
8
9
|
export interface CoreFeatures {
|
|
10
|
+
coreReativityFeature?: TableReactivityBindings
|
|
9
11
|
coreCellsFeature: typeof coreCellsFeature
|
|
10
12
|
coreColumnsFeature: typeof coreColumnsFeature
|
|
11
13
|
coreHeadersFeature: typeof coreHeadersFeature
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Atom, AtomOptions, ReadonlyAtom } from '@tanstack/store'
|
|
2
|
+
|
|
3
|
+
export interface TableAtomOptions<T> extends AtomOptions<T> {
|
|
4
|
+
/**
|
|
5
|
+
* A debug name for the atom, useful for debugging.
|
|
6
|
+
*/
|
|
7
|
+
debugName: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Framework reactivity bindings used by table-core.
|
|
12
|
+
*
|
|
13
|
+
* Adapters (React, Solid, Vue, etc.) provide concrete implementations so
|
|
14
|
+
* core features can create derived/writable atoms and integrate with their
|
|
15
|
+
* scheduling primitives.
|
|
16
|
+
*/
|
|
17
|
+
export interface TableReactivityBindings {
|
|
18
|
+
createOptionsStore: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Creates a writable atom with an initial value.
|
|
21
|
+
*/
|
|
22
|
+
createWritableAtom: <T>(
|
|
23
|
+
initialValue: T,
|
|
24
|
+
options?: TableAtomOptions<T>,
|
|
25
|
+
) => Atom<T>
|
|
26
|
+
/**
|
|
27
|
+
* Creates a readonly/derived atom from a compute function.
|
|
28
|
+
*/
|
|
29
|
+
createReadonlyAtom: <T>(
|
|
30
|
+
fn: () => T,
|
|
31
|
+
options?: TableAtomOptions<T>,
|
|
32
|
+
) => ReadonlyAtom<T>
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates a function without tracking reactive dependencies.
|
|
35
|
+
*/
|
|
36
|
+
untrack: <T>(fn: () => T) => T
|
|
37
|
+
/**
|
|
38
|
+
* Batches reactive updates to avoid intermediate recomputation.
|
|
39
|
+
*/
|
|
40
|
+
batch: (fn: () => void) => void
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/store'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a writable atom to the store-compatible shape expected by core.
|
|
5
|
+
*/
|
|
6
|
+
export function atomToStore<T>(atom: Atom<T>): Store<T>
|
|
7
|
+
/**
|
|
8
|
+
* Converts a readonly atom to a readonly store-compatible shape.
|
|
9
|
+
*/
|
|
10
|
+
export function atomToStore<T>(atom: ReadonlyAtom<T>): ReadonlyStore<T>
|
|
11
|
+
/**
|
|
12
|
+
* Bridges atom instances to the `Store`/`ReadonlyStore` API by exposing
|
|
13
|
+
* a `state` getter backed by `atom.get()`, and wiring `setState` for
|
|
14
|
+
* writable atoms.
|
|
15
|
+
*/
|
|
16
|
+
export function atomToStore<T>(
|
|
17
|
+
atom: Atom<T> | ReadonlyAtom<T>,
|
|
18
|
+
): Store<T> | ReadonlyStore<T> {
|
|
19
|
+
const store: Store<T> = atom as Store<T>
|
|
20
|
+
Object.defineProperty(atom, 'state', {
|
|
21
|
+
get() {
|
|
22
|
+
return atom.get()
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
if ('set' in atom) {
|
|
26
|
+
store.setState = atom.set.bind(atom)
|
|
27
|
+
}
|
|
28
|
+
return store
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createAtom, createStore } from '@tanstack/store'
|
|
2
1
|
import { coreFeatures } from '../coreFeatures'
|
|
3
2
|
import { cloneState } from '../../utils'
|
|
3
|
+
import { atomToStore } from '../reactivity/coreReactivityFeature.utils'
|
|
4
|
+
import { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils'
|
|
4
5
|
import type { RowData } from '../../types/type-utils'
|
|
5
6
|
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
|
|
6
7
|
import type { Table, Table_Internal } from '../../types/Table'
|
|
@@ -21,16 +22,13 @@ export function constructTable<
|
|
|
21
22
|
TFeatures extends TableFeatures,
|
|
22
23
|
TData extends RowData,
|
|
23
24
|
>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {
|
|
25
|
+
const _reactivity = tableOptions._features.coreReativityFeature!
|
|
26
|
+
|
|
24
27
|
const table = {
|
|
28
|
+
_reactivity,
|
|
25
29
|
_features: { ...coreFeatures, ...tableOptions._features },
|
|
26
30
|
_rowModels: {},
|
|
27
31
|
_rowModelFns: {},
|
|
28
|
-
get options() {
|
|
29
|
-
return this.optionsStore.state
|
|
30
|
-
},
|
|
31
|
-
set options(value) {
|
|
32
|
-
this.optionsStore.setState(() => value)
|
|
33
|
-
},
|
|
34
32
|
baseAtoms: {},
|
|
35
33
|
atoms: {},
|
|
36
34
|
} as Table_Internal<TFeatures, TData>
|
|
@@ -41,10 +39,26 @@ export function constructTable<
|
|
|
41
39
|
return Object.assign(obj, feature.getDefaultTableOptions?.(table))
|
|
42
40
|
}, {}) as TableOptions<TFeatures, TData>
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
const mergedOptions = { ...defaultOptions, ...tableOptions }
|
|
43
|
+
|
|
44
|
+
if (_reactivity.createOptionsStore) {
|
|
45
|
+
// @ts-ignore - direct set
|
|
46
|
+
table.optionsStore = _reactivity.createWritableAtom<
|
|
47
|
+
TableOptions<TFeatures, TData>
|
|
48
|
+
>(mergedOptions, { debugName: 'table/optionsStore' })
|
|
49
|
+
Object.defineProperty(table, 'options', {
|
|
50
|
+
configurable: true,
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get() {
|
|
53
|
+
return table.optionsStore!.get()
|
|
54
|
+
},
|
|
55
|
+
set(value) {
|
|
56
|
+
table.optionsStore!.set(() => value) // or your real update shape
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
} else {
|
|
60
|
+
table.options = mergedOptions
|
|
61
|
+
}
|
|
48
62
|
|
|
49
63
|
table.initialState = getInitialTableState(
|
|
50
64
|
table._features,
|
|
@@ -57,31 +71,40 @@ export function constructTable<
|
|
|
57
71
|
|
|
58
72
|
for (const key of stateKeys) {
|
|
59
73
|
// create writable base atom
|
|
60
|
-
table.baseAtoms[key] =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
table.baseAtoms[key] = _reactivity.createWritableAtom(
|
|
75
|
+
table.initialState[key],
|
|
76
|
+
{
|
|
77
|
+
debugName: `table/baseAtoms/${key}`,
|
|
78
|
+
},
|
|
79
|
+
) as any
|
|
80
|
+
|
|
81
|
+
// create readonly derived atom: on each get(), read either external atom or base atom
|
|
82
|
+
;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(
|
|
83
|
+
() => {
|
|
84
|
+
const externalAtom = table.options.atoms?.[key]
|
|
85
|
+
if (externalAtom) {
|
|
86
|
+
return externalAtom.get()
|
|
87
|
+
}
|
|
88
|
+
return table.baseAtoms[key].get()
|
|
89
|
+
},
|
|
90
|
+
{ debugName: `table/atoms/${key}` },
|
|
91
|
+
)
|
|
76
92
|
}
|
|
77
93
|
|
|
78
|
-
table
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
table_syncExternalStateToBaseAtoms(table)
|
|
95
|
+
|
|
96
|
+
table.store = atomToStore(
|
|
97
|
+
_reactivity.createReadonlyAtom(
|
|
98
|
+
() => {
|
|
99
|
+
const snapshot = {} as TableState<TFeatures>
|
|
100
|
+
for (const key of stateKeys) {
|
|
101
|
+
snapshot[key] = table.atoms[key].get()
|
|
102
|
+
}
|
|
103
|
+
return snapshot
|
|
104
|
+
},
|
|
105
|
+
{ debugName: 'table/store' },
|
|
106
|
+
),
|
|
107
|
+
)
|
|
85
108
|
|
|
86
109
|
if (
|
|
87
110
|
process.env.NODE_ENV === 'development' &&
|
|
@@ -98,7 +121,8 @@ export function constructTable<
|
|
|
98
121
|
|
|
99
122
|
Row Models: ${rowModels.length ? rowModels.join('\n ') : '(none)'}
|
|
100
123
|
|
|
101
|
-
States: ${states.join('\n ')}`,
|
|
124
|
+
States: ${states.join('\n ')}\n`,
|
|
125
|
+
{ table },
|
|
102
126
|
)
|
|
103
127
|
}
|
|
104
128
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableReactivityBindings } from '../reactivity/coreReactivityFeature.types'
|
|
2
|
+
import type { Atom, ReadonlyAtom, ReadonlyStore } from '@tanstack/store'
|
|
2
3
|
import type { CoreFeatures } from '../coreFeatures'
|
|
3
4
|
import type { RowModelFns } from '../../types/RowModelFns'
|
|
4
5
|
import type { RowData, Updater } from '../../types/type-utils'
|
|
@@ -67,11 +68,11 @@ export interface TableOptions_Table<
|
|
|
67
68
|
/**
|
|
68
69
|
* The features that you want to enable for the table.
|
|
69
70
|
*/
|
|
70
|
-
_features: TFeatures
|
|
71
|
+
readonly _features: TFeatures
|
|
71
72
|
/**
|
|
72
73
|
* The row model options that you want to enable for the table.
|
|
73
74
|
*/
|
|
74
|
-
_rowModels?: CreateRowModels_All<TFeatures, TData>
|
|
75
|
+
readonly _rowModels?: CreateRowModels_All<TFeatures, TData>
|
|
75
76
|
/**
|
|
76
77
|
* Optionally, provide your own external writable atoms for individual state slices.
|
|
77
78
|
* When an atom is provided for a given slice, it takes precedence over `options.state[key]`
|
|
@@ -79,35 +80,35 @@ export interface TableOptions_Table<
|
|
|
79
80
|
* still routed through the internal base atom; consumers are responsible for
|
|
80
81
|
* mirroring changes back to their external atom via the corresponding `onXChange` callback.
|
|
81
82
|
*/
|
|
82
|
-
atoms?: ExternalAtoms<TFeatures>
|
|
83
|
+
readonly atoms?: ExternalAtoms<TFeatures>
|
|
83
84
|
/**
|
|
84
85
|
* Set this option to override any of the `autoReset...` feature options.
|
|
85
86
|
*/
|
|
86
|
-
autoResetAll?: boolean
|
|
87
|
+
readonly autoResetAll?: boolean
|
|
87
88
|
/**
|
|
88
89
|
* The data for the table to display. When the `data` option changes reference, the table will reprocess the data.
|
|
89
90
|
*/
|
|
90
|
-
data: ReadonlyArray<TData>
|
|
91
|
+
readonly data: ReadonlyArray<TData>
|
|
91
92
|
/**
|
|
92
93
|
* Use this option to optionally pass initial state to the table. This state will be used when resetting various table states either automatically by the table (eg. `options.autoResetPageIndex`) or via functions like `table.resetRowSelection()`. Most reset function allow you optionally pass a flag to reset to a blank/default state instead of the initial state.
|
|
93
94
|
* Table state will not be reset when this object changes, which also means that the initial state object does not need to be stable.
|
|
94
95
|
*/
|
|
95
|
-
initialState?: Partial<TableState<TFeatures>>
|
|
96
|
+
readonly initialState?: Partial<TableState<TFeatures>>
|
|
96
97
|
/**
|
|
97
98
|
* This option is used to optionally implement the merging of table options.
|
|
98
99
|
*/
|
|
99
|
-
mergeOptions?: (
|
|
100
|
+
readonly mergeOptions?: (
|
|
100
101
|
defaultOptions: TableOptions<TFeatures, TData>,
|
|
101
102
|
options: Partial<TableOptions<TFeatures, TData>>,
|
|
102
103
|
) => TableOptions<TFeatures, TData>
|
|
103
104
|
/**
|
|
104
105
|
* You can pass any object to `options.meta` and access it anywhere the `table` is available via `table.options.meta`.
|
|
105
106
|
*/
|
|
106
|
-
meta?: TableMeta<TFeatures, TData>
|
|
107
|
+
readonly meta?: TableMeta<TFeatures, TData>
|
|
107
108
|
/**
|
|
108
109
|
* Pass in individual self-managed state to the table.
|
|
109
110
|
*/
|
|
110
|
-
state?: Partial<TableState<TFeatures>>
|
|
111
|
+
readonly state?: Partial<TableState<TFeatures>>
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
export interface Table_CoreProperties<
|
|
@@ -115,9 +116,9 @@ export interface Table_CoreProperties<
|
|
|
115
116
|
TData extends RowData,
|
|
116
117
|
> {
|
|
117
118
|
/**
|
|
118
|
-
*
|
|
119
|
+
* Table reactivity bindings for interacting with TanStack Store.
|
|
119
120
|
*/
|
|
120
|
-
|
|
121
|
+
readonly _reactivity: TableReactivityBindings
|
|
121
122
|
/**
|
|
122
123
|
* Prototype cache for Cell objects - shared by all cells in this table
|
|
123
124
|
*/
|
|
@@ -126,6 +127,10 @@ export interface Table_CoreProperties<
|
|
|
126
127
|
* Prototype cache for Column objects - shared by all columns in this table
|
|
127
128
|
*/
|
|
128
129
|
_columnPrototype?: object
|
|
130
|
+
/**
|
|
131
|
+
* The features that are enabled for the table.
|
|
132
|
+
*/
|
|
133
|
+
readonly _features: Partial<CoreFeatures> & TFeatures
|
|
129
134
|
/**
|
|
130
135
|
* Prototype cache for Header objects - shared by all headers in this table
|
|
131
136
|
*/
|
|
@@ -133,43 +138,46 @@ export interface Table_CoreProperties<
|
|
|
133
138
|
/**
|
|
134
139
|
* The row model processing functions that are used to process the data by features.
|
|
135
140
|
*/
|
|
136
|
-
_rowModelFns: RowModelFns<TFeatures, TData>
|
|
141
|
+
readonly _rowModelFns: RowModelFns<TFeatures, TData>
|
|
137
142
|
/**
|
|
138
143
|
* The row models that are enabled for the table.
|
|
139
144
|
*/
|
|
140
|
-
_rowModels: CachedRowModels<TFeatures, TData>
|
|
145
|
+
readonly _rowModels: CachedRowModels<TFeatures, TData>
|
|
141
146
|
/**
|
|
142
147
|
* Prototype cache for Row objects - shared by all rows in this table
|
|
143
148
|
*/
|
|
144
149
|
_rowPrototype?: object
|
|
145
|
-
/**
|
|
146
|
-
* The internal writable atoms for each `TableState` slice. This is the library's
|
|
147
|
-
* single write surface — all state mutations from features land here.
|
|
148
|
-
*/
|
|
149
|
-
baseAtoms: BaseAtoms<TFeatures>
|
|
150
150
|
/**
|
|
151
151
|
* The readonly derived atoms for each `TableState` slice. Each derives from
|
|
152
152
|
* its corresponding `baseAtom` plus, optionally, a per-slice external atom or
|
|
153
153
|
* external state value (precedence: external atom > external state > base atom).
|
|
154
154
|
*/
|
|
155
|
-
atoms: Atoms<TFeatures>
|
|
155
|
+
readonly atoms: Atoms<TFeatures>
|
|
156
156
|
/**
|
|
157
|
-
* The
|
|
157
|
+
* The internal writable atoms for each `TableState` slice. This is the library's
|
|
158
|
+
* single write surface — all state mutations from features land here.
|
|
158
159
|
*/
|
|
159
|
-
|
|
160
|
+
readonly baseAtoms: BaseAtoms<TFeatures>
|
|
160
161
|
/**
|
|
161
162
|
* This is the resolved initial state of the table.
|
|
162
163
|
*/
|
|
163
|
-
initialState: TableState<TFeatures>
|
|
164
|
+
readonly initialState: TableState<TFeatures>
|
|
164
165
|
/**
|
|
165
166
|
* A read-only reference to the table's current options.
|
|
166
167
|
*/
|
|
167
168
|
readonly options: TableOptions<TFeatures, TData>
|
|
169
|
+
/**
|
|
170
|
+
* Writable atom for table options. Only created when `createOptionsStore` is true
|
|
171
|
+
* on `coreReativityFeature` (e.g. Lit, Vue, Solid). React/Preact use `createOptionsStore: false`:
|
|
172
|
+
* options are held as plain data with a lightweight revision + subscribe source; there is
|
|
173
|
+
* no writable atom backing the full options object. Use {@link getTableOptionsStore} to subscribe.
|
|
174
|
+
*/
|
|
175
|
+
readonly optionsStore?: Atom<TableOptions<TFeatures, TData>> | undefined
|
|
168
176
|
/**
|
|
169
177
|
* The readonly flat store for the table state. Derives from `table.atoms`
|
|
170
178
|
* only; never reads external state directly.
|
|
171
179
|
*/
|
|
172
|
-
store: ReadonlyStore<TableState<TFeatures>>
|
|
180
|
+
readonly store: ReadonlyStore<TableState<TFeatures>>
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
export interface Table_Table<
|
|
@@ -1,16 +1,39 @@
|
|
|
1
|
-
import { batch } from '@tanstack/store'
|
|
2
1
|
import { cloneState, functionalUpdate } from '../../utils'
|
|
3
2
|
import type { RowData, Updater } from '../../types/type-utils'
|
|
4
3
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
5
4
|
import type { Table_Internal } from '../../types/Table'
|
|
6
5
|
import type { TableOptions } from '../../types/TableOptions'
|
|
7
6
|
|
|
7
|
+
export function table_syncExternalStateToBaseAtoms<
|
|
8
|
+
TFeatures extends TableFeatures,
|
|
9
|
+
TData extends RowData,
|
|
10
|
+
>(table: Table_Internal<TFeatures, TData>): void {
|
|
11
|
+
const state = table.options.state
|
|
12
|
+
if (!state) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
table._reactivity.batch(() => {
|
|
17
|
+
for (const key in state) {
|
|
18
|
+
const baseAtom = (table.baseAtoms as Record<string, any>)[key]
|
|
19
|
+
if (!baseAtom) {
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const externalState = state[key as keyof typeof state]
|
|
24
|
+
if (externalState !== baseAtom.get()) {
|
|
25
|
+
baseAtom.set(() => externalState)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
export function table_reset<
|
|
9
32
|
TFeatures extends TableFeatures,
|
|
10
33
|
TData extends RowData,
|
|
11
34
|
>(table: Table_Internal<TFeatures, TData>): void {
|
|
12
35
|
const snap = cloneState(table.initialState)
|
|
13
|
-
batch(() => {
|
|
36
|
+
table._reactivity.batch(() => {
|
|
14
37
|
for (const key of Object.keys(snap) as Array<keyof typeof snap>) {
|
|
15
38
|
;(table.baseAtoms as any)[key].set(snap[key] as any)
|
|
16
39
|
}
|
|
@@ -43,5 +66,10 @@ export function table_setOptions<
|
|
|
43
66
|
): void {
|
|
44
67
|
const newOptions = functionalUpdate(updater, table.options)
|
|
45
68
|
const mergedOptions = table_mergeOptions(table, newOptions)
|
|
46
|
-
table.optionsStore
|
|
69
|
+
if (table.optionsStore) {
|
|
70
|
+
table.optionsStore.set(() => mergedOptions)
|
|
71
|
+
} else {
|
|
72
|
+
table.options = mergedOptions
|
|
73
|
+
}
|
|
74
|
+
table_syncExternalStateToBaseAtoms(table)
|
|
47
75
|
}
|
package/src/index.ts
CHANGED
|
@@ -71,9 +71,6 @@ export * from './fns/sortFns'
|
|
|
71
71
|
|
|
72
72
|
export * from './features/stockFeatures'
|
|
73
73
|
|
|
74
|
-
// tableReactivityFeature
|
|
75
|
-
export * from './features/table-reactivity/tableReactivityFeature'
|
|
76
|
-
|
|
77
74
|
// columnFacetingFeature
|
|
78
75
|
export * from './features/column-faceting/columnFacetingFeature'
|
|
79
76
|
export * from './features/column-faceting/columnFacetingFeature.types'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { batch, createAtom } from '@tanstack/store'
|
|
2
|
+
import type { TableReactivityBindings } from './core/reactivity/coreReactivityFeature.types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TanStack Store–based reactivity for vanilla / non-framework use of `constructTable`,
|
|
6
|
+
* with `createOptionsStore: true` so `table.optionsStore` is available for subscriptions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { constructTable, tableFeatures } from '@tanstack/table-core'
|
|
11
|
+
* import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'
|
|
12
|
+
*
|
|
13
|
+
* const table = constructTable({
|
|
14
|
+
* _features: tableFeatures({ coreReativityFeature: storeReactivityBindings() }),
|
|
15
|
+
* // ...
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function storeReactivityBindings(): TableReactivityBindings {
|
|
20
|
+
return {
|
|
21
|
+
createOptionsStore: true,
|
|
22
|
+
batch,
|
|
23
|
+
untrack: (fn) => fn(),
|
|
24
|
+
createReadonlyAtom: (fn, options) => {
|
|
25
|
+
return createAtom(() => fn(), {
|
|
26
|
+
compare: options?.compare,
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
createWritableAtom: (value, options) => {
|
|
30
|
+
return createAtom(value, {
|
|
31
|
+
compare: options?.compare,
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|