@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.
Files changed (62) hide show
  1. package/dist/core/coreFeatures.cjs.map +1 -1
  2. package/dist/core/coreFeatures.d.cts +2 -1
  3. package/dist/core/coreFeatures.d.ts +2 -1
  4. package/dist/core/coreFeatures.js.map +1 -1
  5. package/dist/core/reactivity/coreReactivityFeature.types.d.cts +38 -0
  6. package/dist/core/reactivity/coreReactivityFeature.types.d.ts +38 -0
  7. package/dist/core/reactivity/coreReactivityFeature.utils.cjs +19 -0
  8. package/dist/core/reactivity/coreReactivityFeature.utils.cjs.map +1 -0
  9. package/dist/core/reactivity/coreReactivityFeature.utils.d.cts +14 -0
  10. package/dist/core/reactivity/coreReactivityFeature.utils.d.ts +14 -0
  11. package/dist/core/reactivity/coreReactivityFeature.utils.js +18 -0
  12. package/dist/core/reactivity/coreReactivityFeature.utils.js.map +1 -0
  13. package/dist/core/table/constructTable.cjs +28 -20
  14. package/dist/core/table/constructTable.cjs.map +1 -1
  15. package/dist/core/table/constructTable.js +28 -20
  16. package/dist/core/table/constructTable.js.map +1 -1
  17. package/dist/core/table/coreTablesFeature.types.d.cts +32 -24
  18. package/dist/core/table/coreTablesFeature.types.d.ts +32 -24
  19. package/dist/core/table/coreTablesFeature.utils.cjs +17 -3
  20. package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
  21. package/dist/core/table/coreTablesFeature.utils.d.cts +2 -1
  22. package/dist/core/table/coreTablesFeature.utils.d.ts +2 -1
  23. package/dist/core/table/coreTablesFeature.utils.js +17 -4
  24. package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
  25. package/dist/index.cjs +0 -2
  26. package/dist/index.d.cts +1 -2
  27. package/dist/index.d.ts +1 -2
  28. package/dist/index.js +1 -2
  29. package/dist/reactivity.cjs +4 -0
  30. package/dist/reactivity.d.cts +3 -0
  31. package/dist/reactivity.d.ts +3 -0
  32. package/dist/reactivity.js +3 -0
  33. package/dist/static-functions.cjs +1 -0
  34. package/dist/static-functions.d.cts +2 -2
  35. package/dist/static-functions.d.ts +2 -2
  36. package/dist/static-functions.js +2 -2
  37. package/dist/store-reactivity-bindings.cjs +36 -0
  38. package/dist/store-reactivity-bindings.cjs.map +1 -0
  39. package/dist/store-reactivity-bindings.d.cts +22 -0
  40. package/dist/store-reactivity-bindings.d.ts +22 -0
  41. package/dist/store-reactivity-bindings.js +35 -0
  42. package/dist/store-reactivity-bindings.js.map +1 -0
  43. package/dist/types/TableFeatures.d.cts +1 -1
  44. package/dist/types/TableFeatures.d.ts +1 -1
  45. package/package.json +9 -1
  46. package/src/core/coreFeatures.ts +2 -0
  47. package/src/core/reactivity/coreReactivityFeature.types.ts +41 -0
  48. package/src/core/reactivity/coreReactivityFeature.utils.ts +29 -0
  49. package/src/core/table/constructTable.ts +59 -35
  50. package/src/core/table/coreTablesFeature.types.ts +32 -24
  51. package/src/core/table/coreTablesFeature.utils.ts +31 -3
  52. package/src/index.ts +0 -3
  53. package/src/reactivity.ts +2 -0
  54. package/src/store-reactivity-bindings.ts +35 -0
  55. package/src/types/TableFeatures.ts +7 -7
  56. package/dist/features/table-reactivity/tableReactivityFeature.cjs +0 -46
  57. package/dist/features/table-reactivity/tableReactivityFeature.cjs.map +0 -1
  58. package/dist/features/table-reactivity/tableReactivityFeature.d.cts +0 -12
  59. package/dist/features/table-reactivity/tableReactivityFeature.d.ts +0 -12
  60. package/dist/features/table-reactivity/tableReactivityFeature.js +0 -45
  61. package/dist/features/table-reactivity/tableReactivityFeature.js.map +0 -1
  62. package/src/features/table-reactivity/tableReactivityFeature.ts +0 -92
@@ -1 +1 @@
1
- {"version":3,"file":"coreFeatures.cjs","names":[],"sources":["../../src/core/coreFeatures.ts"],"sourcesContent":["import { coreCellsFeature } from './cells/coreCellsFeature'\nimport { coreColumnsFeature } from './columns/coreColumnsFeature'\nimport { coreHeadersFeature } from './headers/coreHeadersFeature'\nimport { coreRowModelsFeature } from './row-models/coreRowModelsFeature'\nimport { coreRowsFeature } from './rows/coreRowsFeature'\nimport { coreTablesFeature } from './table/coreTablesFeature'\n\nexport interface CoreFeatures {\n coreCellsFeature: typeof coreCellsFeature\n coreColumnsFeature: typeof coreColumnsFeature\n coreHeadersFeature: typeof coreHeadersFeature\n coreRowModelsFeature: typeof coreRowModelsFeature\n coreRowsFeature: typeof coreRowsFeature\n coreTablesFeature: typeof coreTablesFeature\n}\n\nexport const coreFeatures: CoreFeatures = {\n coreCellsFeature,\n coreColumnsFeature,\n coreHeadersFeature,\n coreRowModelsFeature,\n coreRowsFeature,\n coreTablesFeature,\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,eAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"coreFeatures.cjs","names":[],"sources":["../../src/core/coreFeatures.ts"],"sourcesContent":["import { coreCellsFeature } from './cells/coreCellsFeature'\nimport { coreColumnsFeature } from './columns/coreColumnsFeature'\nimport { coreHeadersFeature } from './headers/coreHeadersFeature'\nimport { coreRowModelsFeature } from './row-models/coreRowModelsFeature'\nimport { coreRowsFeature } from './rows/coreRowsFeature'\nimport { coreTablesFeature } from './table/coreTablesFeature'\nimport type { TableReactivityBindings } from '../reactivity'\n\nexport interface CoreFeatures {\n coreReativityFeature?: TableReactivityBindings\n coreCellsFeature: typeof coreCellsFeature\n coreColumnsFeature: typeof coreColumnsFeature\n coreHeadersFeature: typeof coreHeadersFeature\n coreRowModelsFeature: typeof coreRowModelsFeature\n coreRowsFeature: typeof coreRowsFeature\n coreTablesFeature: typeof coreTablesFeature\n}\n\nexport const coreFeatures: CoreFeatures = {\n coreCellsFeature,\n coreColumnsFeature,\n coreHeadersFeature,\n coreRowModelsFeature,\n coreRowsFeature,\n coreTablesFeature,\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,eAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -4,9 +4,10 @@ import { coreHeadersFeature } from "./headers/coreHeadersFeature.cjs";
4
4
  import { coreRowModelsFeature } from "./row-models/coreRowModelsFeature.cjs";
5
5
  import { coreRowsFeature } from "./rows/coreRowsFeature.cjs";
6
6
  import { coreTablesFeature } from "./table/coreTablesFeature.cjs";
7
-
7
+ import { TableReactivityBindings } from "./reactivity/coreReactivityFeature.types.cjs";
8
8
  //#region src/core/coreFeatures.d.ts
9
9
  interface CoreFeatures {
10
+ coreReativityFeature?: TableReactivityBindings;
10
11
  coreCellsFeature: typeof coreCellsFeature;
11
12
  coreColumnsFeature: typeof coreColumnsFeature;
12
13
  coreHeadersFeature: typeof coreHeadersFeature;
@@ -4,9 +4,10 @@ import { coreHeadersFeature } from "./headers/coreHeadersFeature.js";
4
4
  import { coreRowModelsFeature } from "./row-models/coreRowModelsFeature.js";
5
5
  import { coreRowsFeature } from "./rows/coreRowsFeature.js";
6
6
  import { coreTablesFeature } from "./table/coreTablesFeature.js";
7
-
7
+ import { TableReactivityBindings } from "./reactivity/coreReactivityFeature.types.js";
8
8
  //#region src/core/coreFeatures.d.ts
9
9
  interface CoreFeatures {
10
+ coreReativityFeature?: TableReactivityBindings;
10
11
  coreCellsFeature: typeof coreCellsFeature;
11
12
  coreColumnsFeature: typeof coreColumnsFeature;
12
13
  coreHeadersFeature: typeof coreHeadersFeature;
@@ -1 +1 @@
1
- {"version":3,"file":"coreFeatures.js","names":[],"sources":["../../src/core/coreFeatures.ts"],"sourcesContent":["import { coreCellsFeature } from './cells/coreCellsFeature'\nimport { coreColumnsFeature } from './columns/coreColumnsFeature'\nimport { coreHeadersFeature } from './headers/coreHeadersFeature'\nimport { coreRowModelsFeature } from './row-models/coreRowModelsFeature'\nimport { coreRowsFeature } from './rows/coreRowsFeature'\nimport { coreTablesFeature } from './table/coreTablesFeature'\n\nexport interface CoreFeatures {\n coreCellsFeature: typeof coreCellsFeature\n coreColumnsFeature: typeof coreColumnsFeature\n coreHeadersFeature: typeof coreHeadersFeature\n coreRowModelsFeature: typeof coreRowModelsFeature\n coreRowsFeature: typeof coreRowsFeature\n coreTablesFeature: typeof coreTablesFeature\n}\n\nexport const coreFeatures: CoreFeatures = {\n coreCellsFeature,\n coreColumnsFeature,\n coreHeadersFeature,\n coreRowModelsFeature,\n coreRowsFeature,\n coreTablesFeature,\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,eAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACD"}
1
+ {"version":3,"file":"coreFeatures.js","names":[],"sources":["../../src/core/coreFeatures.ts"],"sourcesContent":["import { coreCellsFeature } from './cells/coreCellsFeature'\nimport { coreColumnsFeature } from './columns/coreColumnsFeature'\nimport { coreHeadersFeature } from './headers/coreHeadersFeature'\nimport { coreRowModelsFeature } from './row-models/coreRowModelsFeature'\nimport { coreRowsFeature } from './rows/coreRowsFeature'\nimport { coreTablesFeature } from './table/coreTablesFeature'\nimport type { TableReactivityBindings } from '../reactivity'\n\nexport interface CoreFeatures {\n coreReativityFeature?: TableReactivityBindings\n coreCellsFeature: typeof coreCellsFeature\n coreColumnsFeature: typeof coreColumnsFeature\n coreHeadersFeature: typeof coreHeadersFeature\n coreRowModelsFeature: typeof coreRowModelsFeature\n coreRowsFeature: typeof coreRowsFeature\n coreTablesFeature: typeof coreTablesFeature\n}\n\nexport const coreFeatures: CoreFeatures = {\n coreCellsFeature,\n coreColumnsFeature,\n coreHeadersFeature,\n coreRowModelsFeature,\n coreRowsFeature,\n coreTablesFeature,\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,eAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -0,0 +1,38 @@
1
+ import { Atom, AtomOptions, ReadonlyAtom } from "@tanstack/store";
2
+
3
+ //#region src/core/reactivity/coreReactivityFeature.types.d.ts
4
+ interface TableAtomOptions<T> extends AtomOptions<T> {
5
+ /**
6
+ * A debug name for the atom, useful for debugging.
7
+ */
8
+ debugName: string;
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
+ interface TableReactivityBindings {
18
+ createOptionsStore: boolean;
19
+ /**
20
+ * Creates a writable atom with an initial value.
21
+ */
22
+ createWritableAtom: <T>(initialValue: T, options?: TableAtomOptions<T>) => Atom<T>;
23
+ /**
24
+ * Creates a readonly/derived atom from a compute function.
25
+ */
26
+ createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => ReadonlyAtom<T>;
27
+ /**
28
+ * Evaluates a function without tracking reactive dependencies.
29
+ */
30
+ untrack: <T>(fn: () => T) => T;
31
+ /**
32
+ * Batches reactive updates to avoid intermediate recomputation.
33
+ */
34
+ batch: (fn: () => void) => void;
35
+ }
36
+ //#endregion
37
+ export { TableAtomOptions, TableReactivityBindings };
38
+ //# sourceMappingURL=coreReactivityFeature.types.d.cts.map
@@ -0,0 +1,38 @@
1
+ import { Atom, AtomOptions, ReadonlyAtom } from "@tanstack/store";
2
+
3
+ //#region src/core/reactivity/coreReactivityFeature.types.d.ts
4
+ interface TableAtomOptions<T> extends AtomOptions<T> {
5
+ /**
6
+ * A debug name for the atom, useful for debugging.
7
+ */
8
+ debugName: string;
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
+ interface TableReactivityBindings {
18
+ createOptionsStore: boolean;
19
+ /**
20
+ * Creates a writable atom with an initial value.
21
+ */
22
+ createWritableAtom: <T>(initialValue: T, options?: TableAtomOptions<T>) => Atom<T>;
23
+ /**
24
+ * Creates a readonly/derived atom from a compute function.
25
+ */
26
+ createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => ReadonlyAtom<T>;
27
+ /**
28
+ * Evaluates a function without tracking reactive dependencies.
29
+ */
30
+ untrack: <T>(fn: () => T) => T;
31
+ /**
32
+ * Batches reactive updates to avoid intermediate recomputation.
33
+ */
34
+ batch: (fn: () => void) => void;
35
+ }
36
+ //#endregion
37
+ export { TableAtomOptions, TableReactivityBindings };
38
+ //# sourceMappingURL=coreReactivityFeature.types.d.ts.map
@@ -0,0 +1,19 @@
1
+
2
+ //#region src/core/reactivity/coreReactivityFeature.utils.ts
3
+ /**
4
+ * Bridges atom instances to the `Store`/`ReadonlyStore` API by exposing
5
+ * a `state` getter backed by `atom.get()`, and wiring `setState` for
6
+ * writable atoms.
7
+ */
8
+ function atomToStore(atom) {
9
+ const store = atom;
10
+ Object.defineProperty(atom, "state", { get() {
11
+ return atom.get();
12
+ } });
13
+ if ("set" in atom) store.setState = atom.set.bind(atom);
14
+ return store;
15
+ }
16
+
17
+ //#endregion
18
+ exports.atomToStore = atomToStore;
19
+ //# sourceMappingURL=coreReactivityFeature.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreReactivityFeature.utils.cjs","names":[],"sources":["../../../src/core/reactivity/coreReactivityFeature.utils.ts"],"sourcesContent":["import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/store'\n\n/**\n * Converts a writable atom to the store-compatible shape expected by core.\n */\nexport function atomToStore<T>(atom: Atom<T>): Store<T>\n/**\n * Converts a readonly atom to a readonly store-compatible shape.\n */\nexport function atomToStore<T>(atom: ReadonlyAtom<T>): ReadonlyStore<T>\n/**\n * Bridges atom instances to the `Store`/`ReadonlyStore` API by exposing\n * a `state` getter backed by `atom.get()`, and wiring `setState` for\n * writable atoms.\n */\nexport function atomToStore<T>(\n atom: Atom<T> | ReadonlyAtom<T>,\n): Store<T> | ReadonlyStore<T> {\n const store: Store<T> = atom as Store<T>\n Object.defineProperty(atom, 'state', {\n get() {\n return atom.get()\n },\n })\n if ('set' in atom) {\n store.setState = atom.set.bind(atom)\n }\n return store\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,YACd,MAC6B;CAC7B,MAAM,QAAkB;AACxB,QAAO,eAAe,MAAM,SAAS,EACnC,MAAM;AACJ,SAAO,KAAK,KAAK;IAEpB,CAAC;AACF,KAAI,SAAS,KACX,OAAM,WAAW,KAAK,IAAI,KAAK,KAAK;AAEtC,QAAO"}
@@ -0,0 +1,14 @@
1
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/store";
2
+
3
+ //#region src/core/reactivity/coreReactivityFeature.utils.d.ts
4
+ /**
5
+ * Converts a writable atom to the store-compatible shape expected by core.
6
+ */
7
+ declare function atomToStore<T>(atom: Atom<T>): Store<T>;
8
+ /**
9
+ * Converts a readonly atom to a readonly store-compatible shape.
10
+ */
11
+ declare function atomToStore<T>(atom: ReadonlyAtom<T>): ReadonlyStore<T>;
12
+ //#endregion
13
+ export { atomToStore };
14
+ //# sourceMappingURL=coreReactivityFeature.utils.d.cts.map
@@ -0,0 +1,14 @@
1
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/store";
2
+
3
+ //#region src/core/reactivity/coreReactivityFeature.utils.d.ts
4
+ /**
5
+ * Converts a writable atom to the store-compatible shape expected by core.
6
+ */
7
+ declare function atomToStore<T>(atom: Atom<T>): Store<T>;
8
+ /**
9
+ * Converts a readonly atom to a readonly store-compatible shape.
10
+ */
11
+ declare function atomToStore<T>(atom: ReadonlyAtom<T>): ReadonlyStore<T>;
12
+ //#endregion
13
+ export { atomToStore };
14
+ //# sourceMappingURL=coreReactivityFeature.utils.d.ts.map
@@ -0,0 +1,18 @@
1
+ //#region src/core/reactivity/coreReactivityFeature.utils.ts
2
+ /**
3
+ * Bridges atom instances to the `Store`/`ReadonlyStore` API by exposing
4
+ * a `state` getter backed by `atom.get()`, and wiring `setState` for
5
+ * writable atoms.
6
+ */
7
+ function atomToStore(atom) {
8
+ const store = atom;
9
+ Object.defineProperty(atom, "state", { get() {
10
+ return atom.get();
11
+ } });
12
+ if ("set" in atom) store.setState = atom.set.bind(atom);
13
+ return store;
14
+ }
15
+
16
+ //#endregion
17
+ export { atomToStore };
18
+ //# sourceMappingURL=coreReactivityFeature.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreReactivityFeature.utils.js","names":[],"sources":["../../../src/core/reactivity/coreReactivityFeature.utils.ts"],"sourcesContent":["import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/store'\n\n/**\n * Converts a writable atom to the store-compatible shape expected by core.\n */\nexport function atomToStore<T>(atom: Atom<T>): Store<T>\n/**\n * Converts a readonly atom to a readonly store-compatible shape.\n */\nexport function atomToStore<T>(atom: ReadonlyAtom<T>): ReadonlyStore<T>\n/**\n * Bridges atom instances to the `Store`/`ReadonlyStore` API by exposing\n * a `state` getter backed by `atom.get()`, and wiring `setState` for\n * writable atoms.\n */\nexport function atomToStore<T>(\n atom: Atom<T> | ReadonlyAtom<T>,\n): Store<T> | ReadonlyStore<T> {\n const store: Store<T> = atom as Store<T>\n Object.defineProperty(atom, 'state', {\n get() {\n return atom.get()\n },\n })\n if ('set' in atom) {\n store.setState = atom.set.bind(atom)\n }\n return store\n}\n"],"mappings":";;;;;;AAeA,SAAgB,YACd,MAC6B;CAC7B,MAAM,QAAkB;AACxB,QAAO,eAAe,MAAM,SAAS,EACnC,MAAM;AACJ,SAAO,KAAK,KAAK;IAEpB,CAAC;AACF,KAAI,SAAS,KACX,OAAM,WAAW,KAAK,IAAI,KAAK,KAAK;AAEtC,QAAO"}
@@ -1,6 +1,7 @@
1
1
  const require_utils = require('../../utils.cjs');
2
+ const require_coreTablesFeature_utils = require('./coreTablesFeature.utils.cjs');
2
3
  const require_coreFeatures = require('../coreFeatures.cjs');
3
- let _tanstack_store = require("@tanstack/store");
4
+ const require_coreReactivityFeature_utils = require('../reactivity/coreReactivityFeature.utils.cjs');
4
5
 
5
6
  //#region src/core/table/constructTable.ts
6
7
  function getInitialTableState(features, initialState = {}) {
@@ -11,49 +12,56 @@ function getInitialTableState(features, initialState = {}) {
11
12
  return require_utils.cloneState(initialState);
12
13
  }
13
14
  function constructTable(tableOptions) {
15
+ const _reactivity = tableOptions._features.coreReativityFeature;
14
16
  const table = {
17
+ _reactivity,
15
18
  _features: {
16
19
  ...require_coreFeatures.coreFeatures,
17
20
  ...tableOptions._features
18
21
  },
19
22
  _rowModels: {},
20
23
  _rowModelFns: {},
21
- get options() {
22
- return this.optionsStore.state;
23
- },
24
- set options(value) {
25
- this.optionsStore.setState(() => value);
26
- },
27
24
  baseAtoms: {},
28
25
  atoms: {}
29
26
  };
30
27
  const featuresList = Object.values(table._features);
31
- table.optionsStore = (0, _tanstack_store.createStore)({
28
+ const mergedOptions = {
32
29
  ...featuresList.reduce((obj, feature) => {
33
30
  var _feature$getDefaultTa;
34
31
  return Object.assign(obj, (_feature$getDefaultTa = feature.getDefaultTableOptions) === null || _feature$getDefaultTa === void 0 ? void 0 : _feature$getDefaultTa.call(feature, table));
35
32
  }, {}),
36
33
  ...tableOptions
37
- });
34
+ };
35
+ if (_reactivity.createOptionsStore) {
36
+ table.optionsStore = _reactivity.createWritableAtom(mergedOptions, { debugName: "table/optionsStore" });
37
+ Object.defineProperty(table, "options", {
38
+ configurable: true,
39
+ enumerable: true,
40
+ get() {
41
+ return table.optionsStore.get();
42
+ },
43
+ set(value) {
44
+ table.optionsStore.set(() => value);
45
+ }
46
+ });
47
+ } else table.options = mergedOptions;
38
48
  table.initialState = getInitialTableState(table._features, table.options.initialState);
39
49
  const stateKeys = Object.keys(table.initialState);
40
50
  for (const key of stateKeys) {
41
- table.baseAtoms[key] = (0, _tanstack_store.createAtom)(table.initialState[key]);
42
- table.atoms[key] = (0, _tanstack_store.createAtom)(() => {
43
- var _opts$atoms;
44
- const opts = table.optionsStore.state;
45
- const state = opts.state;
46
- if (key in (state ?? {})) return state[key];
47
- const externalAtom = (_opts$atoms = opts.atoms) === null || _opts$atoms === void 0 ? void 0 : _opts$atoms[key];
51
+ table.baseAtoms[key] = _reactivity.createWritableAtom(table.initialState[key], { debugName: `table/baseAtoms/${key}` });
52
+ table.atoms[key] = _reactivity.createReadonlyAtom(() => {
53
+ var _table$options$atoms;
54
+ const externalAtom = (_table$options$atoms = table.options.atoms) === null || _table$options$atoms === void 0 ? void 0 : _table$options$atoms[key];
48
55
  if (externalAtom) return externalAtom.get();
49
56
  return table.baseAtoms[key].get();
50
- });
57
+ }, { debugName: `table/atoms/${key}` });
51
58
  }
52
- table.store = (0, _tanstack_store.createStore)(() => {
59
+ require_coreTablesFeature_utils.table_syncExternalStateToBaseAtoms(table);
60
+ table.store = require_coreReactivityFeature_utils.atomToStore(_reactivity.createReadonlyAtom(() => {
53
61
  const snapshot = {};
54
62
  for (const key of stateKeys) snapshot[key] = table.atoms[key].get();
55
63
  return snapshot;
56
- });
64
+ }, { debugName: "table/store" }));
57
65
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
58
66
  const features = Object.keys(table._features);
59
67
  const rowModels = Object.keys(table.options._rowModels || {});
@@ -64,7 +72,7 @@ function constructTable(tableOptions) {
64
72
 
65
73
  Row Models: ${rowModels.length ? rowModels.join("\n ") : "(none)"}
66
74
 
67
- States: ${states.join("\n ")}`);
75
+ States: ${states.join("\n ")}\n`, { table });
68
76
  }
69
77
  for (const feature of featuresList) {
70
78
  var _feature$constructTab;
@@ -1 +1 @@
1
- {"version":3,"file":"constructTable.cjs","names":["cloneState","coreFeatures"],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { createAtom, createStore } from '@tanstack/store'\nimport { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const table = {\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n get options() {\n return this.optionsStore.state\n },\n set options(value) {\n this.optionsStore.setState(() => value)\n },\n baseAtoms: {},\n atoms: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n table.optionsStore = createStore({\n ...defaultOptions,\n ...tableOptions,\n })\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState<TFeatures>\n >\n\n for (const key of stateKeys) {\n // create writable base atom\n table.baseAtoms[key] = createAtom(table.initialState[key]) as any\n\n // create readonly derived atom: on each get(), read current options (state, then external atom, then base)\n ;(table.atoms as any)[key] = createAtom(() => {\n // Reading optionsStore.state keeps this reactive to setOptions\n const opts = table.optionsStore.state\n const state = opts.state\n if (key in (state ?? {})) {\n return state![key]\n }\n const externalAtom = opts.atoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key].get()\n })\n }\n\n table.store = createStore(() => {\n const snapshot = {} as TableState<TFeatures>\n for (const key of stateKeys) {\n snapshot[key] = table.atoms[key].get()\n }\n return snapshot\n })\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}`,\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"mappings":";;;;;AASA,SAAgB,qBACd,UACA,eAA2D,EAAE,EACtC;AACvB,QAAO,OAAO,SAAS,CAAC,SAAS,YAAY;;AAC3C,2CAAe,QAAQ,6GAAkB,aAAa,KAAI;GAC1D;AACF,QAAOA,yBAAW,aAAa;;AAGjC,SAAgB,eAGd,cAAuE;CACvE,MAAM,QAAQ;EACZ,WAAW;GAAE,GAAGC;GAAc,GAAG,aAAa;GAAW;EACzD,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,IAAI,UAAU;AACZ,UAAO,KAAK,aAAa;;EAE3B,IAAI,QAAQ,OAAO;AACjB,QAAK,aAAa,eAAe,MAAM;;EAEzC,WAAW,EAAE;EACb,OAAO,EAAE;EACV;CAED,MAAM,eAAwC,OAAO,OAAO,MAAM,UAAU;AAM5E,OAAM,gDAA2B;EAC/B,GALqB,aAAa,QAAQ,KAAK,YAAY;;AAC3D,UAAO,OAAO,OAAO,8BAAK,QAAQ,oHAAyB,MAAM,CAAC;KACjE,EAAE,CAGc;EACjB,GAAG;EACJ,CAAC;AAEF,OAAM,eAAe,qBACnB,MAAM,WACN,MAAM,QAAQ,aACf;CAED,MAAM,YAAY,OAAO,KAAK,MAAM,aAAa;AAIjD,MAAK,MAAM,OAAO,WAAW;AAE3B,QAAM,UAAU,uCAAkB,MAAM,aAAa,KAAK;AAGzD,EAAC,MAAM,MAAc,6CAAwB;;GAE5C,MAAM,OAAO,MAAM,aAAa;GAChC,MAAM,QAAQ,KAAK;AACnB,OAAI,QAAQ,SAAS,EAAE,EACrB,QAAO,MAAO;GAEhB,MAAM,8BAAe,KAAK,iEAAQ;AAClC,OAAI,aACF,QAAO,aAAa,KAAK;AAE3B,UAAO,MAAM,UAAU,KAAK,KAAK;IACjC;;AAGJ,OAAM,+CAA0B;EAC9B,MAAM,WAAW,EAAE;AACnB,OAAK,MAAM,OAAO,UAChB,UAAS,OAAO,MAAM,MAAM,KAAK,KAAK;AAExC,SAAO;GACP;AAEF,KACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;EACA,MAAM,WAAW,OAAO,KAAK,MAAM,UAAU;EAC7C,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE,CAAC;EAC7D,MAAM,SAAS,OAAO,KAAK,MAAM,aAAa;AAE9C,UAAQ,IACN;;gBAEU,SAAS,KAAK,mBAAmB,CAAC;;gBAElC,UAAU,SAAS,UAAU,KAAK,mBAAmB,GAAG,SAAS;;gBAEjE,OAAO,KAAK,mBAAmB,GAC1C;;AAGH,MAAK,MAAM,WAAW,cAAc;;AAClC,mCAAQ,wGAAqB,MAAM;;AAGrC,QAAO"}
1
+ {"version":3,"file":"constructTable.cjs","names":["cloneState","coreFeatures","atomToStore"],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport { atomToStore } from '../reactivity/coreReactivityFeature.utils'\nimport { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const _reactivity = tableOptions._features.coreReativityFeature!\n\n const table = {\n _reactivity,\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n baseAtoms: {},\n atoms: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n const mergedOptions = { ...defaultOptions, ...tableOptions }\n\n if (_reactivity.createOptionsStore) {\n // @ts-ignore - direct set\n table.optionsStore = _reactivity.createWritableAtom<\n TableOptions<TFeatures, TData>\n >(mergedOptions, { debugName: 'table/optionsStore' })\n Object.defineProperty(table, 'options', {\n configurable: true,\n enumerable: true,\n get() {\n return table.optionsStore!.get()\n },\n set(value) {\n table.optionsStore!.set(() => value) // or your real update shape\n },\n })\n } else {\n table.options = mergedOptions\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState<TFeatures>\n >\n\n for (const key of stateKeys) {\n // create writable base atom\n table.baseAtoms[key] = _reactivity.createWritableAtom(\n table.initialState[key],\n {\n debugName: `table/baseAtoms/${key}`,\n },\n ) as any\n\n // create readonly derived atom: on each get(), read either external atom or base atom\n ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(\n () => {\n const externalAtom = table.options.atoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key].get()\n },\n { debugName: `table/atoms/${key}` },\n )\n }\n\n table_syncExternalStateToBaseAtoms(table)\n\n table.store = atomToStore(\n _reactivity.createReadonlyAtom(\n () => {\n const snapshot = {} as TableState<TFeatures>\n for (const key of stateKeys) {\n snapshot[key] = table.atoms[key].get()\n }\n return snapshot\n },\n { debugName: 'table/store' },\n ),\n )\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}\\n`,\n { table },\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"mappings":";;;;;;AAUA,SAAgB,qBACd,UACA,eAA2D,EAAE,EACtC;AACvB,QAAO,OAAO,SAAS,CAAC,SAAS,YAAY;;AAC3C,2CAAe,QAAQ,6GAAkB,aAAa,KAAI;GAC1D;AACF,QAAOA,yBAAW,aAAa;;AAGjC,SAAgB,eAGd,cAAuE;CACvE,MAAM,cAAc,aAAa,UAAU;CAE3C,MAAM,QAAQ;EACZ;EACA,WAAW;GAAE,GAAGC;GAAc,GAAG,aAAa;GAAW;EACzD,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,WAAW,EAAE;EACb,OAAO,EAAE;EACV;CAED,MAAM,eAAwC,OAAO,OAAO,MAAM,UAAU;CAM5E,MAAM,gBAAgB;EAAE,GAJD,aAAa,QAAQ,KAAK,YAAY;;AAC3D,UAAO,OAAO,OAAO,8BAAK,QAAQ,oHAAyB,MAAM,CAAC;KACjE,EAAE,CAEoC;EAAE,GAAG;EAAc;AAE5D,KAAI,YAAY,oBAAoB;AAElC,QAAM,eAAe,YAAY,mBAE/B,eAAe,EAAE,WAAW,sBAAsB,CAAC;AACrD,SAAO,eAAe,OAAO,WAAW;GACtC,cAAc;GACd,YAAY;GACZ,MAAM;AACJ,WAAO,MAAM,aAAc,KAAK;;GAElC,IAAI,OAAO;AACT,UAAM,aAAc,UAAU,MAAM;;GAEvC,CAAC;OAEF,OAAM,UAAU;AAGlB,OAAM,eAAe,qBACnB,MAAM,WACN,MAAM,QAAQ,aACf;CAED,MAAM,YAAY,OAAO,KAAK,MAAM,aAAa;AAIjD,MAAK,MAAM,OAAO,WAAW;AAE3B,QAAM,UAAU,OAAO,YAAY,mBACjC,MAAM,aAAa,MACnB,EACE,WAAW,mBAAmB,OAC/B,CACF;AAGA,EAAC,MAAM,MAAc,OAAO,YAAY,yBACjC;;GACJ,MAAM,uCAAe,MAAM,QAAQ,mFAAQ;AAC3C,OAAI,aACF,QAAO,aAAa,KAAK;AAE3B,UAAO,MAAM,UAAU,KAAK,KAAK;KAEnC,EAAE,WAAW,eAAe,OAAO,CACpC;;AAGH,oEAAmC,MAAM;AAEzC,OAAM,QAAQC,gDACZ,YAAY,yBACJ;EACJ,MAAM,WAAW,EAAE;AACnB,OAAK,MAAM,OAAO,UAChB,UAAS,OAAO,MAAM,MAAM,KAAK,KAAK;AAExC,SAAO;IAET,EAAE,WAAW,eAAe,CAC7B,CACF;AAED,KACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;EACA,MAAM,WAAW,OAAO,KAAK,MAAM,UAAU;EAC7C,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE,CAAC;EAC7D,MAAM,SAAS,OAAO,KAAK,MAAM,aAAa;AAE9C,UAAQ,IACN;;gBAEU,SAAS,KAAK,mBAAmB,CAAC;;gBAElC,UAAU,SAAS,UAAU,KAAK,mBAAmB,GAAG,SAAS;;gBAEjE,OAAO,KAAK,mBAAmB,CAAC,KAC1C,EAAE,OAAO,CACV;;AAGH,MAAK,MAAM,WAAW,cAAc;;AAClC,mCAAQ,wGAAqB,MAAM;;AAGrC,QAAO"}
@@ -1,6 +1,7 @@
1
1
  import { cloneState } from "../../utils.js";
2
+ import { table_syncExternalStateToBaseAtoms } from "./coreTablesFeature.utils.js";
2
3
  import { coreFeatures } from "../coreFeatures.js";
3
- import { createAtom, createStore } from "@tanstack/store";
4
+ import { atomToStore } from "../reactivity/coreReactivityFeature.utils.js";
4
5
 
5
6
  //#region src/core/table/constructTable.ts
6
7
  function getInitialTableState(features, initialState = {}) {
@@ -11,49 +12,56 @@ function getInitialTableState(features, initialState = {}) {
11
12
  return cloneState(initialState);
12
13
  }
13
14
  function constructTable(tableOptions) {
15
+ const _reactivity = tableOptions._features.coreReativityFeature;
14
16
  const table = {
17
+ _reactivity,
15
18
  _features: {
16
19
  ...coreFeatures,
17
20
  ...tableOptions._features
18
21
  },
19
22
  _rowModels: {},
20
23
  _rowModelFns: {},
21
- get options() {
22
- return this.optionsStore.state;
23
- },
24
- set options(value) {
25
- this.optionsStore.setState(() => value);
26
- },
27
24
  baseAtoms: {},
28
25
  atoms: {}
29
26
  };
30
27
  const featuresList = Object.values(table._features);
31
- table.optionsStore = createStore({
28
+ const mergedOptions = {
32
29
  ...featuresList.reduce((obj, feature) => {
33
30
  var _feature$getDefaultTa;
34
31
  return Object.assign(obj, (_feature$getDefaultTa = feature.getDefaultTableOptions) === null || _feature$getDefaultTa === void 0 ? void 0 : _feature$getDefaultTa.call(feature, table));
35
32
  }, {}),
36
33
  ...tableOptions
37
- });
34
+ };
35
+ if (_reactivity.createOptionsStore) {
36
+ table.optionsStore = _reactivity.createWritableAtom(mergedOptions, { debugName: "table/optionsStore" });
37
+ Object.defineProperty(table, "options", {
38
+ configurable: true,
39
+ enumerable: true,
40
+ get() {
41
+ return table.optionsStore.get();
42
+ },
43
+ set(value) {
44
+ table.optionsStore.set(() => value);
45
+ }
46
+ });
47
+ } else table.options = mergedOptions;
38
48
  table.initialState = getInitialTableState(table._features, table.options.initialState);
39
49
  const stateKeys = Object.keys(table.initialState);
40
50
  for (const key of stateKeys) {
41
- table.baseAtoms[key] = createAtom(table.initialState[key]);
42
- table.atoms[key] = createAtom(() => {
43
- var _opts$atoms;
44
- const opts = table.optionsStore.state;
45
- const state = opts.state;
46
- if (key in (state ?? {})) return state[key];
47
- const externalAtom = (_opts$atoms = opts.atoms) === null || _opts$atoms === void 0 ? void 0 : _opts$atoms[key];
51
+ table.baseAtoms[key] = _reactivity.createWritableAtom(table.initialState[key], { debugName: `table/baseAtoms/${key}` });
52
+ table.atoms[key] = _reactivity.createReadonlyAtom(() => {
53
+ var _table$options$atoms;
54
+ const externalAtom = (_table$options$atoms = table.options.atoms) === null || _table$options$atoms === void 0 ? void 0 : _table$options$atoms[key];
48
55
  if (externalAtom) return externalAtom.get();
49
56
  return table.baseAtoms[key].get();
50
- });
57
+ }, { debugName: `table/atoms/${key}` });
51
58
  }
52
- table.store = createStore(() => {
59
+ table_syncExternalStateToBaseAtoms(table);
60
+ table.store = atomToStore(_reactivity.createReadonlyAtom(() => {
53
61
  const snapshot = {};
54
62
  for (const key of stateKeys) snapshot[key] = table.atoms[key].get();
55
63
  return snapshot;
56
- });
64
+ }, { debugName: "table/store" }));
57
65
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
58
66
  const features = Object.keys(table._features);
59
67
  const rowModels = Object.keys(table.options._rowModels || {});
@@ -64,7 +72,7 @@ function constructTable(tableOptions) {
64
72
 
65
73
  Row Models: ${rowModels.length ? rowModels.join("\n ") : "(none)"}
66
74
 
67
- States: ${states.join("\n ")}`);
75
+ States: ${states.join("\n ")}\n`, { table });
68
76
  }
69
77
  for (const feature of featuresList) {
70
78
  var _feature$constructTab;
@@ -1 +1 @@
1
- {"version":3,"file":"constructTable.js","names":[],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { createAtom, createStore } from '@tanstack/store'\nimport { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const table = {\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n get options() {\n return this.optionsStore.state\n },\n set options(value) {\n this.optionsStore.setState(() => value)\n },\n baseAtoms: {},\n atoms: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n table.optionsStore = createStore({\n ...defaultOptions,\n ...tableOptions,\n })\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState<TFeatures>\n >\n\n for (const key of stateKeys) {\n // create writable base atom\n table.baseAtoms[key] = createAtom(table.initialState[key]) as any\n\n // create readonly derived atom: on each get(), read current options (state, then external atom, then base)\n ;(table.atoms as any)[key] = createAtom(() => {\n // Reading optionsStore.state keeps this reactive to setOptions\n const opts = table.optionsStore.state\n const state = opts.state\n if (key in (state ?? {})) {\n return state![key]\n }\n const externalAtom = opts.atoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key].get()\n })\n }\n\n table.store = createStore(() => {\n const snapshot = {} as TableState<TFeatures>\n for (const key of stateKeys) {\n snapshot[key] = table.atoms[key].get()\n }\n return snapshot\n })\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}`,\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"mappings":";;;;;AASA,SAAgB,qBACd,UACA,eAA2D,EAAE,EACtC;AACvB,QAAO,OAAO,SAAS,CAAC,SAAS,YAAY;;AAC3C,2CAAe,QAAQ,6GAAkB,aAAa,KAAI;GAC1D;AACF,QAAO,WAAW,aAAa;;AAGjC,SAAgB,eAGd,cAAuE;CACvE,MAAM,QAAQ;EACZ,WAAW;GAAE,GAAG;GAAc,GAAG,aAAa;GAAW;EACzD,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,IAAI,UAAU;AACZ,UAAO,KAAK,aAAa;;EAE3B,IAAI,QAAQ,OAAO;AACjB,QAAK,aAAa,eAAe,MAAM;;EAEzC,WAAW,EAAE;EACb,OAAO,EAAE;EACV;CAED,MAAM,eAAwC,OAAO,OAAO,MAAM,UAAU;AAM5E,OAAM,eAAe,YAAY;EAC/B,GALqB,aAAa,QAAQ,KAAK,YAAY;;AAC3D,UAAO,OAAO,OAAO,8BAAK,QAAQ,oHAAyB,MAAM,CAAC;KACjE,EAAE,CAGc;EACjB,GAAG;EACJ,CAAC;AAEF,OAAM,eAAe,qBACnB,MAAM,WACN,MAAM,QAAQ,aACf;CAED,MAAM,YAAY,OAAO,KAAK,MAAM,aAAa;AAIjD,MAAK,MAAM,OAAO,WAAW;AAE3B,QAAM,UAAU,OAAO,WAAW,MAAM,aAAa,KAAK;AAGzD,EAAC,MAAM,MAAc,OAAO,iBAAiB;;GAE5C,MAAM,OAAO,MAAM,aAAa;GAChC,MAAM,QAAQ,KAAK;AACnB,OAAI,QAAQ,SAAS,EAAE,EACrB,QAAO,MAAO;GAEhB,MAAM,8BAAe,KAAK,iEAAQ;AAClC,OAAI,aACF,QAAO,aAAa,KAAK;AAE3B,UAAO,MAAM,UAAU,KAAK,KAAK;IACjC;;AAGJ,OAAM,QAAQ,kBAAkB;EAC9B,MAAM,WAAW,EAAE;AACnB,OAAK,MAAM,OAAO,UAChB,UAAS,OAAO,MAAM,MAAM,KAAK,KAAK;AAExC,SAAO;GACP;AAEF,KACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;EACA,MAAM,WAAW,OAAO,KAAK,MAAM,UAAU;EAC7C,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE,CAAC;EAC7D,MAAM,SAAS,OAAO,KAAK,MAAM,aAAa;AAE9C,UAAQ,IACN;;gBAEU,SAAS,KAAK,mBAAmB,CAAC;;gBAElC,UAAU,SAAS,UAAU,KAAK,mBAAmB,GAAG,SAAS;;gBAEjE,OAAO,KAAK,mBAAmB,GAC1C;;AAGH,MAAK,MAAM,WAAW,cAAc;;AAClC,mCAAQ,wGAAqB,MAAM;;AAGrC,QAAO"}
1
+ {"version":3,"file":"constructTable.js","names":[],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport { atomToStore } from '../reactivity/coreReactivityFeature.utils'\nimport { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState } from '../../types/TableState'\n\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const _reactivity = tableOptions._features.coreReativityFeature!\n\n const table = {\n _reactivity,\n _features: { ...coreFeatures, ...tableOptions._features },\n _rowModels: {},\n _rowModelFns: {},\n baseAtoms: {},\n atoms: {},\n } as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature<{}>> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n const mergedOptions = { ...defaultOptions, ...tableOptions }\n\n if (_reactivity.createOptionsStore) {\n // @ts-ignore - direct set\n table.optionsStore = _reactivity.createWritableAtom<\n TableOptions<TFeatures, TData>\n >(mergedOptions, { debugName: 'table/optionsStore' })\n Object.defineProperty(table, 'options', {\n configurable: true,\n enumerable: true,\n get() {\n return table.optionsStore!.get()\n },\n set(value) {\n table.optionsStore!.set(() => value) // or your real update shape\n },\n })\n } else {\n table.options = mergedOptions\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState<TFeatures>\n >\n\n for (const key of stateKeys) {\n // create writable base atom\n table.baseAtoms[key] = _reactivity.createWritableAtom(\n table.initialState[key],\n {\n debugName: `table/baseAtoms/${key}`,\n },\n ) as any\n\n // create readonly derived atom: on each get(), read either external atom or base atom\n ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(\n () => {\n const externalAtom = table.options.atoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key].get()\n },\n { debugName: `table/atoms/${key}` },\n )\n }\n\n table_syncExternalStateToBaseAtoms(table)\n\n table.store = atomToStore(\n _reactivity.createReadonlyAtom(\n () => {\n const snapshot = {} as TableState<TFeatures>\n for (const key of stateKeys) {\n snapshot[key] = table.atoms[key].get()\n }\n return snapshot\n },\n { debugName: 'table/store' },\n ),\n )\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.keys(table.options._rowModels || {})\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}\\n`,\n { table },\n )\n }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"mappings":";;;;;;AAUA,SAAgB,qBACd,UACA,eAA2D,EAAE,EACtC;AACvB,QAAO,OAAO,SAAS,CAAC,SAAS,YAAY;;AAC3C,2CAAe,QAAQ,6GAAkB,aAAa,KAAI;GAC1D;AACF,QAAO,WAAW,aAAa;;AAGjC,SAAgB,eAGd,cAAuE;CACvE,MAAM,cAAc,aAAa,UAAU;CAE3C,MAAM,QAAQ;EACZ;EACA,WAAW;GAAE,GAAG;GAAc,GAAG,aAAa;GAAW;EACzD,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,WAAW,EAAE;EACb,OAAO,EAAE;EACV;CAED,MAAM,eAAwC,OAAO,OAAO,MAAM,UAAU;CAM5E,MAAM,gBAAgB;EAAE,GAJD,aAAa,QAAQ,KAAK,YAAY;;AAC3D,UAAO,OAAO,OAAO,8BAAK,QAAQ,oHAAyB,MAAM,CAAC;KACjE,EAAE,CAEoC;EAAE,GAAG;EAAc;AAE5D,KAAI,YAAY,oBAAoB;AAElC,QAAM,eAAe,YAAY,mBAE/B,eAAe,EAAE,WAAW,sBAAsB,CAAC;AACrD,SAAO,eAAe,OAAO,WAAW;GACtC,cAAc;GACd,YAAY;GACZ,MAAM;AACJ,WAAO,MAAM,aAAc,KAAK;;GAElC,IAAI,OAAO;AACT,UAAM,aAAc,UAAU,MAAM;;GAEvC,CAAC;OAEF,OAAM,UAAU;AAGlB,OAAM,eAAe,qBACnB,MAAM,WACN,MAAM,QAAQ,aACf;CAED,MAAM,YAAY,OAAO,KAAK,MAAM,aAAa;AAIjD,MAAK,MAAM,OAAO,WAAW;AAE3B,QAAM,UAAU,OAAO,YAAY,mBACjC,MAAM,aAAa,MACnB,EACE,WAAW,mBAAmB,OAC/B,CACF;AAGA,EAAC,MAAM,MAAc,OAAO,YAAY,yBACjC;;GACJ,MAAM,uCAAe,MAAM,QAAQ,mFAAQ;AAC3C,OAAI,aACF,QAAO,aAAa,KAAK;AAE3B,UAAO,MAAM,UAAU,KAAK,KAAK;KAEnC,EAAE,WAAW,eAAe,OAAO,CACpC;;AAGH,oCAAmC,MAAM;AAEzC,OAAM,QAAQ,YACZ,YAAY,yBACJ;EACJ,MAAM,WAAW,EAAE;AACnB,OAAK,MAAM,OAAO,UAChB,UAAS,OAAO,MAAM,MAAM,KAAK,KAAK;AAExC,SAAO;IAET,EAAE,WAAW,eAAe,CAC7B,CACF;AAED,KACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;EACA,MAAM,WAAW,OAAO,KAAK,MAAM,UAAU;EAC7C,MAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE,CAAC;EAC7D,MAAM,SAAS,OAAO,KAAK,MAAM,aAAa;AAE9C,UAAQ,IACN;;gBAEU,SAAS,KAAK,mBAAmB,CAAC;;gBAElC,UAAU,SAAS,UAAU,KAAK,mBAAmB,GAAG,SAAS;;gBAEjE,OAAO,KAAK,mBAAmB,CAAC,KAC1C,EAAE,OAAO,CACV;;AAGH,MAAK,MAAM,WAAW,cAAc;;AAClC,mCAAQ,wGAAqB,MAAM;;AAGrC,QAAO"}
@@ -1,11 +1,12 @@
1
1
  import { RowData, Updater } from "../../types/type-utils.cjs";
2
+ import { TableReactivityBindings } from "../reactivity/coreReactivityFeature.types.cjs";
2
3
  import { CoreFeatures } from "../coreFeatures.cjs";
3
4
  import { RowModelFns } from "../../types/RowModelFns.cjs";
4
5
  import { CachedRowModels, CreateRowModels_All } from "../../types/RowModel.cjs";
5
6
  import { TableState, TableState_All } from "../../types/TableState.cjs";
6
7
  import { TableOptions } from "../../types/TableOptions.cjs";
7
8
  import { TableFeatures } from "../../types/TableFeatures.cjs";
8
- import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/store";
9
+ import { Atom, ReadonlyAtom, ReadonlyStore } from "@tanstack/store";
9
10
 
10
11
  //#region src/core/table/coreTablesFeature.types.d.ts
11
12
  interface TableMeta<TFeatures extends TableFeatures, TData extends RowData> {}
@@ -45,11 +46,11 @@ interface TableOptions_Table<TFeatures extends TableFeatures, TData extends RowD
45
46
  /**
46
47
  * The features that you want to enable for the table.
47
48
  */
48
- _features: TFeatures;
49
+ readonly _features: TFeatures;
49
50
  /**
50
51
  * The row model options that you want to enable for the table.
51
52
  */
52
- _rowModels?: CreateRowModels_All<TFeatures, TData>;
53
+ readonly _rowModels?: CreateRowModels_All<TFeatures, TData>;
53
54
  /**
54
55
  * Optionally, provide your own external writable atoms for individual state slices.
55
56
  * When an atom is provided for a given slice, it takes precedence over `options.state[key]`
@@ -57,38 +58,38 @@ interface TableOptions_Table<TFeatures extends TableFeatures, TData extends RowD
57
58
  * still routed through the internal base atom; consumers are responsible for
58
59
  * mirroring changes back to their external atom via the corresponding `onXChange` callback.
59
60
  */
60
- atoms?: ExternalAtoms<TFeatures>;
61
+ readonly atoms?: ExternalAtoms<TFeatures>;
61
62
  /**
62
63
  * Set this option to override any of the `autoReset...` feature options.
63
64
  */
64
- autoResetAll?: boolean;
65
+ readonly autoResetAll?: boolean;
65
66
  /**
66
67
  * The data for the table to display. When the `data` option changes reference, the table will reprocess the data.
67
68
  */
68
- data: ReadonlyArray<TData>;
69
+ readonly data: ReadonlyArray<TData>;
69
70
  /**
70
71
  * 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.
71
72
  * Table state will not be reset when this object changes, which also means that the initial state object does not need to be stable.
72
73
  */
73
- initialState?: Partial<TableState<TFeatures>>;
74
+ readonly initialState?: Partial<TableState<TFeatures>>;
74
75
  /**
75
76
  * This option is used to optionally implement the merging of table options.
76
77
  */
77
- mergeOptions?: (defaultOptions: TableOptions<TFeatures, TData>, options: Partial<TableOptions<TFeatures, TData>>) => TableOptions<TFeatures, TData>;
78
+ readonly mergeOptions?: (defaultOptions: TableOptions<TFeatures, TData>, options: Partial<TableOptions<TFeatures, TData>>) => TableOptions<TFeatures, TData>;
78
79
  /**
79
80
  * You can pass any object to `options.meta` and access it anywhere the `table` is available via `table.options.meta`.
80
81
  */
81
- meta?: TableMeta<TFeatures, TData>;
82
+ readonly meta?: TableMeta<TFeatures, TData>;
82
83
  /**
83
84
  * Pass in individual self-managed state to the table.
84
85
  */
85
- state?: Partial<TableState<TFeatures>>;
86
+ readonly state?: Partial<TableState<TFeatures>>;
86
87
  }
87
88
  interface Table_CoreProperties<TFeatures extends TableFeatures, TData extends RowData> {
88
89
  /**
89
- * The features that are enabled for the table.
90
+ * Table reactivity bindings for interacting with TanStack Store.
90
91
  */
91
- _features: Partial<CoreFeatures> & TFeatures;
92
+ readonly _reactivity: TableReactivityBindings;
92
93
  /**
93
94
  * Prototype cache for Cell objects - shared by all cells in this table
94
95
  */
@@ -97,6 +98,10 @@ interface Table_CoreProperties<TFeatures extends TableFeatures, TData extends Ro
97
98
  * Prototype cache for Column objects - shared by all columns in this table
98
99
  */
99
100
  _columnPrototype?: object;
101
+ /**
102
+ * The features that are enabled for the table.
103
+ */
104
+ readonly _features: Partial<CoreFeatures> & TFeatures;
100
105
  /**
101
106
  * Prototype cache for Header objects - shared by all headers in this table
102
107
  */
@@ -104,43 +109,46 @@ interface Table_CoreProperties<TFeatures extends TableFeatures, TData extends Ro
104
109
  /**
105
110
  * The row model processing functions that are used to process the data by features.
106
111
  */
107
- _rowModelFns: RowModelFns<TFeatures, TData>;
112
+ readonly _rowModelFns: RowModelFns<TFeatures, TData>;
108
113
  /**
109
114
  * The row models that are enabled for the table.
110
115
  */
111
- _rowModels: CachedRowModels<TFeatures, TData>;
116
+ readonly _rowModels: CachedRowModels<TFeatures, TData>;
112
117
  /**
113
118
  * Prototype cache for Row objects - shared by all rows in this table
114
119
  */
115
120
  _rowPrototype?: object;
116
- /**
117
- * The internal writable atoms for each `TableState` slice. This is the library's
118
- * single write surface — all state mutations from features land here.
119
- */
120
- baseAtoms: BaseAtoms<TFeatures>;
121
121
  /**
122
122
  * The readonly derived atoms for each `TableState` slice. Each derives from
123
123
  * its corresponding `baseAtom` plus, optionally, a per-slice external atom or
124
124
  * external state value (precedence: external atom > external state > base atom).
125
125
  */
126
- atoms: Atoms<TFeatures>;
126
+ readonly atoms: Atoms<TFeatures>;
127
127
  /**
128
- * The base store for the table options.
128
+ * The internal writable atoms for each `TableState` slice. This is the library's
129
+ * single write surface — all state mutations from features land here.
129
130
  */
130
- optionsStore: Store<TableOptions<TFeatures, TData>>;
131
+ readonly baseAtoms: BaseAtoms<TFeatures>;
131
132
  /**
132
133
  * This is the resolved initial state of the table.
133
134
  */
134
- initialState: TableState<TFeatures>;
135
+ readonly initialState: TableState<TFeatures>;
135
136
  /**
136
137
  * A read-only reference to the table's current options.
137
138
  */
138
139
  readonly options: TableOptions<TFeatures, TData>;
140
+ /**
141
+ * Writable atom for table options. Only created when `createOptionsStore` is true
142
+ * on `coreReativityFeature` (e.g. Lit, Vue, Solid). React/Preact use `createOptionsStore: false`:
143
+ * options are held as plain data with a lightweight revision + subscribe source; there is
144
+ * no writable atom backing the full options object. Use {@link getTableOptionsStore} to subscribe.
145
+ */
146
+ readonly optionsStore?: Atom<TableOptions<TFeatures, TData>> | undefined;
139
147
  /**
140
148
  * The readonly flat store for the table state. Derives from `table.atoms`
141
149
  * only; never reads external state directly.
142
150
  */
143
- store: ReadonlyStore<TableState<TFeatures>>;
151
+ readonly store: ReadonlyStore<TableState<TFeatures>>;
144
152
  }
145
153
  interface Table_Table<TFeatures extends TableFeatures, TData extends RowData> extends Table_CoreProperties<TFeatures, TData> {
146
154
  /**