@tanstack/table-core 9.0.0-alpha.41 → 9.0.0-alpha.42

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 (57) 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/constructReactivityBindings.cjs +19 -0
  6. package/dist/core/reactivity/constructReactivityBindings.cjs.map +1 -0
  7. package/dist/core/reactivity/constructReactivityBindings.d.cts +7 -0
  8. package/dist/core/reactivity/constructReactivityBindings.d.ts +7 -0
  9. package/dist/core/reactivity/constructReactivityBindings.js +19 -0
  10. package/dist/core/reactivity/constructReactivityBindings.js.map +1 -0
  11. package/dist/core/reactivity/coreReactivityFeature.types.d.cts +37 -0
  12. package/dist/core/reactivity/coreReactivityFeature.types.d.ts +37 -0
  13. package/dist/core/reactivity/coreReactivityFeature.utils.cjs +19 -0
  14. package/dist/core/reactivity/coreReactivityFeature.utils.cjs.map +1 -0
  15. package/dist/core/reactivity/coreReactivityFeature.utils.d.cts +14 -0
  16. package/dist/core/reactivity/coreReactivityFeature.utils.d.ts +14 -0
  17. package/dist/core/reactivity/coreReactivityFeature.utils.js +18 -0
  18. package/dist/core/reactivity/coreReactivityFeature.utils.js.map +1 -0
  19. package/dist/core/table/constructTable.cjs +18 -15
  20. package/dist/core/table/constructTable.cjs.map +1 -1
  21. package/dist/core/table/constructTable.js +18 -15
  22. package/dist/core/table/constructTable.js.map +1 -1
  23. package/dist/core/table/coreTablesFeature.types.d.cts +29 -24
  24. package/dist/core/table/coreTablesFeature.types.d.ts +29 -24
  25. package/dist/core/table/coreTablesFeature.utils.cjs +2 -3
  26. package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
  27. package/dist/core/table/coreTablesFeature.utils.js +2 -3
  28. package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
  29. package/dist/index.cjs +0 -2
  30. package/dist/index.d.cts +1 -2
  31. package/dist/index.d.ts +1 -2
  32. package/dist/index.js +1 -2
  33. package/dist/reactivity.cjs +6 -0
  34. package/dist/reactivity.d.cts +4 -0
  35. package/dist/reactivity.d.ts +4 -0
  36. package/dist/reactivity.js +4 -0
  37. package/dist/types/TableFeatures.d.cts +1 -1
  38. package/dist/types/TableFeatures.d.ts +1 -1
  39. package/package.json +5 -1
  40. package/src/core/coreFeatures.ts +2 -0
  41. package/src/core/reactivity/constructReactivityBindings.ts +19 -0
  42. package/src/core/reactivity/coreReactivityFeature.types.ts +40 -0
  43. package/src/core/reactivity/coreReactivityFeature.utils.ts +29 -0
  44. package/src/core/table/constructTable.ts +44 -28
  45. package/src/core/table/coreTablesFeature.types.ts +29 -24
  46. package/src/core/table/coreTablesFeature.utils.ts +2 -3
  47. package/src/index.ts +0 -3
  48. package/src/reactivity.ts +3 -0
  49. package/src/types/Table.ts +1 -1
  50. package/src/types/TableFeatures.ts +7 -7
  51. package/dist/features/table-reactivity/tableReactivityFeature.cjs +0 -46
  52. package/dist/features/table-reactivity/tableReactivityFeature.cjs.map +0 -1
  53. package/dist/features/table-reactivity/tableReactivityFeature.d.cts +0 -12
  54. package/dist/features/table-reactivity/tableReactivityFeature.d.ts +0 -12
  55. package/dist/features/table-reactivity/tableReactivityFeature.js +0 -45
  56. package/dist/features/table-reactivity/tableReactivityFeature.js.map +0 -1
  57. package/src/features/table-reactivity/tableReactivityFeature.ts +0 -92
@@ -1,6 +1,6 @@
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
4
  import type { RowData } from '../../types/type-utils'
5
5
  import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
6
6
  import type { Table, Table_Internal } from '../../types/Table'
@@ -21,15 +21,18 @@ export function constructTable<
21
21
  TFeatures extends TableFeatures,
22
22
  TData extends RowData,
23
23
  >(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {
24
+ const _reactivity = tableOptions._features.coreReativityFeature!
25
+
24
26
  const table = {
27
+ _reactivity,
25
28
  _features: { ...coreFeatures, ...tableOptions._features },
26
29
  _rowModels: {},
27
30
  _rowModelFns: {},
28
31
  get options() {
29
- return this.optionsStore.state
32
+ return this.optionsStore.get()
30
33
  },
31
34
  set options(value) {
32
- this.optionsStore.setState(() => value)
35
+ this.optionsStore.set(() => value)
33
36
  },
34
37
  baseAtoms: {},
35
38
  atoms: {},
@@ -41,10 +44,10 @@ export function constructTable<
41
44
  return Object.assign(obj, feature.getDefaultTableOptions?.(table))
42
45
  }, {}) as TableOptions<TFeatures, TData>
43
46
 
44
- table.optionsStore = createStore({
45
- ...defaultOptions,
46
- ...tableOptions,
47
- })
47
+ // @ts-ignore - direct set
48
+ table.optionsStore = _reactivity.createWritableAtom<
49
+ TableOptions<TFeatures, TData>
50
+ >({ ...defaultOptions, ...tableOptions }, { debugName: 'table/optionsStore' })
48
51
 
49
52
  table.initialState = getInitialTableState(
50
53
  table._features,
@@ -57,31 +60,44 @@ export function constructTable<
57
60
 
58
61
  for (const key of stateKeys) {
59
62
  // create writable base atom
60
- table.baseAtoms[key] = createAtom(table.initialState[key]) as any
63
+ table.baseAtoms[key] = _reactivity.createWritableAtom(
64
+ table.initialState[key],
65
+ {
66
+ debugName: `table/baseAtoms/${key}`,
67
+ },
68
+ ) as any
61
69
 
62
70
  // create readonly derived atom: on each get(), read current options (state, then external atom, then base)
63
- ;(table.atoms as any)[key] = createAtom(() => {
64
- // Reading optionsStore.state keeps this reactive to setOptions
65
- const opts = table.optionsStore.state
66
- const state = opts.state
67
- if (key in (state ?? {})) {
68
- return state![key]
69
- }
70
- const externalAtom = opts.atoms?.[key]
71
- if (externalAtom) {
72
- return externalAtom.get()
73
- }
74
- return table.baseAtoms[key].get()
75
- })
71
+ ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(
72
+ () => {
73
+ // Reading optionsStore.get() keeps this reactive to setOptions
74
+ const opts = table.optionsStore.get()
75
+ const state = opts.state
76
+ if (key in (state ?? {})) {
77
+ return state![key]
78
+ }
79
+ const externalAtom = opts.atoms?.[key]
80
+ if (externalAtom) {
81
+ return externalAtom.get()
82
+ }
83
+ return table.baseAtoms[key].get()
84
+ },
85
+ { debugName: `table/atoms/${key}` },
86
+ )
76
87
  }
77
88
 
78
- table.store = createStore(() => {
79
- const snapshot = {} as TableState<TFeatures>
80
- for (const key of stateKeys) {
81
- snapshot[key] = table.atoms[key].get()
82
- }
83
- return snapshot
84
- })
89
+ table.store = atomToStore(
90
+ _reactivity.createReadonlyAtom(
91
+ () => {
92
+ const snapshot = {} as TableState<TFeatures>
93
+ for (const key of stateKeys) {
94
+ snapshot[key] = table.atoms[key].get()
95
+ }
96
+ return snapshot
97
+ },
98
+ { debugName: 'table/store' },
99
+ ),
100
+ )
85
101
 
86
102
  if (
87
103
  process.env.NODE_ENV === 'development' &&
@@ -1,4 +1,5 @@
1
- import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/store'
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
- * The features that are enabled for the table.
119
+ * Table reactivity bindings for interacting with TanStack Store.
119
120
  */
120
- _features: Partial<CoreFeatures> & TFeatures
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,43 @@ 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 base store for the table options.
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
- optionsStore: Store<TableOptions<TFeatures, TData>>
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
+ * The base store for the table options.
171
+ */
172
+ readonly optionsStore: Atom<TableOptions<TFeatures, TData>>
168
173
  /**
169
174
  * The readonly flat store for the table state. Derives from `table.atoms`
170
175
  * only; never reads external state directly.
171
176
  */
172
- store: ReadonlyStore<TableState<TFeatures>>
177
+ readonly store: ReadonlyStore<TableState<TFeatures>>
173
178
  }
174
179
 
175
180
  export interface Table_Table<
@@ -1,4 +1,3 @@
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'
@@ -10,7 +9,7 @@ export function table_reset<
10
9
  TData extends RowData,
11
10
  >(table: Table_Internal<TFeatures, TData>): void {
12
11
  const snap = cloneState(table.initialState)
13
- batch(() => {
12
+ table._reactivity.batch(() => {
14
13
  for (const key of Object.keys(snap) as Array<keyof typeof snap>) {
15
14
  ;(table.baseAtoms as any)[key].set(snap[key] as any)
16
15
  }
@@ -43,5 +42,5 @@ export function table_setOptions<
43
42
  ): void {
44
43
  const newOptions = functionalUpdate(updater, table.options)
45
44
  const mergedOptions = table_mergeOptions(table, newOptions)
46
- table.optionsStore.setState(() => mergedOptions)
45
+ table.optionsStore.set(() => mergedOptions)
47
46
  }
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,3 @@
1
+ export * from './core/reactivity/coreReactivityFeature.types'
2
+ export * from './core/reactivity/constructReactivityBindings'
3
+ export * from './core/reactivity/coreReactivityFeature.utils'
@@ -1,4 +1,4 @@
1
- import type { ReadonlyStore } from '@tanstack/store'
1
+ import type { ReadonlyAtom, ReadonlyStore } from '@tanstack/store'
2
2
  import type { Table_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types'
3
3
  import type { Table_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types'
4
4
  import type { Table_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
@@ -12,13 +12,13 @@ export type ExtractFeatureTypes<
12
12
  TFeatures extends TableFeatures,
13
13
  > = UnionToIntersection<
14
14
  {
15
- [K in keyof TFeatures]: TFeatures[K] extends TableFeature<
16
- infer FeatureConstructorOptions
17
- >
18
- ? TKey extends keyof FeatureConstructorOptions
19
- ? FeatureConstructorOptions[TKey]
20
- : never
21
- : any
15
+ [K in keyof TFeatures]: K extends 'coreReativityFeature'
16
+ ? never
17
+ : TFeatures[K] extends TableFeature<infer FeatureConstructorOptions>
18
+ ? TKey extends keyof FeatureConstructorOptions
19
+ ? FeatureConstructorOptions[TKey]
20
+ : never
21
+ : any
22
22
  }[keyof TFeatures]
23
23
  >
24
24
 
@@ -1,46 +0,0 @@
1
-
2
- //#region src/features/table-reactivity/tableReactivityFeature.ts
3
- function constructReactivityFeature(bindings) {
4
- return { constructTableAPIs: (table) => {
5
- table.optionsStore = bindStore(table.optionsStore, bindings.optionsNotifier);
6
- table.atoms = bindAtoms(table.atoms, bindings.stateNotifier);
7
- } };
8
- }
9
- const bindStore = (store, notifier) => {
10
- const stateDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(store), "state");
11
- Object.defineProperty(store, "state", {
12
- configurable: true,
13
- enumerable: true,
14
- get() {
15
- notifier === null || notifier === void 0 || notifier();
16
- return stateDescriptor.get.call(store);
17
- }
18
- });
19
- return store;
20
- };
21
- const bindAtoms = (atoms, notifier) => {
22
- if (!notifier) return atoms;
23
- const wrappedCache = /* @__PURE__ */ new Map();
24
- return new Proxy(atoms, { get(target, prop, receiver) {
25
- const atom = Reflect.get(target, prop, receiver);
26
- if (!atom || typeof prop !== "string" || !isAtomLike(atom)) return atom;
27
- if (wrappedCache.has(prop)) return wrappedCache.get(prop);
28
- const originalGet = atom.get.bind(atom);
29
- const wrapped = new Proxy(atom, { get(atomTarget, atomProp, atomReceiver) {
30
- if (atomProp === "get") return () => {
31
- notifier();
32
- return originalGet();
33
- };
34
- return Reflect.get(atomTarget, atomProp, atomReceiver);
35
- } });
36
- wrappedCache.set(prop, wrapped);
37
- return wrapped;
38
- } });
39
- };
40
- function isAtomLike(value) {
41
- return typeof value === "object" && value !== null && typeof value.get === "function";
42
- }
43
-
44
- //#endregion
45
- exports.constructReactivityFeature = constructReactivityFeature;
46
- //# sourceMappingURL=tableReactivityFeature.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tableReactivityFeature.cjs","names":[],"sources":["../../../src/features/table-reactivity/tableReactivityFeature.ts"],"sourcesContent":["import type { ReadonlyStore, Store } from '@tanstack/store'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\nexport interface TableReactivityFeatureConstructors<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {}\n\nexport function constructReactivityFeature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(bindings: {\n stateNotifier?: () => unknown\n optionsNotifier?: () => unknown\n}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {\n return {\n constructTableAPIs: (table) => {\n table.optionsStore = bindStore(\n table.optionsStore,\n bindings.optionsNotifier,\n )\n table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)\n },\n }\n}\n\nconst bindStore = <T extends Store<any> | ReadonlyStore<any>>(\n store: T,\n notifier?: () => unknown,\n): T => {\n const stateDescriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(store),\n 'state',\n )!\n\n Object.defineProperty(store, 'state', {\n configurable: true,\n enumerable: true,\n get() {\n notifier?.()\n return stateDescriptor.get!.call(store)\n },\n })\n\n return store\n}\n\n// Wraps an atoms/baseAtoms map so that `.get()` on any individual atom\n// calls the framework notifier first — matching how `bindStore` wraps\n// `store.state`. The proxy also transparently forwards missing slices\n// (atoms for features not registered on this table) as `undefined`.\nconst bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {\n if (!notifier) return atoms\n // Cache wrapped atoms so referential identity is stable per slice.\n const wrappedCache = new Map<PropertyKey, any>()\n return new Proxy(atoms, {\n get(target, prop, receiver) {\n const atom = Reflect.get(target, prop, receiver) as unknown\n if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {\n return atom\n }\n if (wrappedCache.has(prop)) return wrappedCache.get(prop)\n const originalGet = atom.get.bind(atom)\n const wrapped = new Proxy(atom, {\n get(atomTarget, atomProp, atomReceiver) {\n if (atomProp === 'get') {\n return () => {\n notifier()\n return originalGet()\n }\n }\n return Reflect.get(atomTarget, atomProp, atomReceiver)\n },\n })\n wrappedCache.set(prop, wrapped)\n return wrapped\n },\n })\n}\n\ninterface AtomLike {\n get: () => unknown\n}\n\nfunction isAtomLike(value: unknown): value is AtomLike {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function'\n )\n}\n"],"mappings":";;AASA,SAAgB,2BAGd,UAGqE;AACrE,QAAO,EACL,qBAAqB,UAAU;AAC7B,QAAM,eAAe,UACnB,MAAM,cACN,SAAS,gBACV;AACD,QAAM,QAAQ,UAAU,MAAM,OAAO,SAAS,cAAc;IAE/D;;AAGH,MAAM,aACJ,OACA,aACM;CACN,MAAM,kBAAkB,OAAO,yBAC7B,OAAO,eAAe,MAAM,EAC5B,QACD;AAED,QAAO,eAAe,OAAO,SAAS;EACpC,cAAc;EACd,YAAY;EACZ,MAAM;AACJ,yDAAY;AACZ,UAAO,gBAAgB,IAAK,KAAK,MAAM;;EAE1C,CAAC;AAEF,QAAO;;AAOT,MAAM,aAA+B,OAAU,aAAgC;AAC7E,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,+BAAe,IAAI,KAAuB;AAChD,QAAO,IAAI,MAAM,OAAO,EACtB,IAAI,QAAQ,MAAM,UAAU;EAC1B,MAAM,OAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAChD,MAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,CAAC,WAAW,KAAK,CACxD,QAAO;AAET,MAAI,aAAa,IAAI,KAAK,CAAE,QAAO,aAAa,IAAI,KAAK;EACzD,MAAM,cAAc,KAAK,IAAI,KAAK,KAAK;EACvC,MAAM,UAAU,IAAI,MAAM,MAAM,EAC9B,IAAI,YAAY,UAAU,cAAc;AACtC,OAAI,aAAa,MACf,cAAa;AACX,cAAU;AACV,WAAO,aAAa;;AAGxB,UAAO,QAAQ,IAAI,YAAY,UAAU,aAAa;KAEzD,CAAC;AACF,eAAa,IAAI,MAAM,QAAQ;AAC/B,SAAO;IAEV,CAAC;;AAOJ,SAAS,WAAW,OAAmC;AACrD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ"}
@@ -1,12 +0,0 @@
1
- import { RowData } from "../../types/type-utils.cjs";
2
- import { TableFeature, TableFeatures } from "../../types/TableFeatures.cjs";
3
-
4
- //#region src/features/table-reactivity/tableReactivityFeature.d.ts
5
- interface TableReactivityFeatureConstructors<TFeatures extends TableFeatures, TData extends RowData> {}
6
- declare function constructReactivityFeature<TFeatures extends TableFeatures, TData extends RowData>(bindings: {
7
- stateNotifier?: () => unknown;
8
- optionsNotifier?: () => unknown;
9
- }): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>>;
10
- //#endregion
11
- export { TableReactivityFeatureConstructors, constructReactivityFeature };
12
- //# sourceMappingURL=tableReactivityFeature.d.cts.map
@@ -1,12 +0,0 @@
1
- import { RowData } from "../../types/type-utils.js";
2
- import { TableFeature, TableFeatures } from "../../types/TableFeatures.js";
3
-
4
- //#region src/features/table-reactivity/tableReactivityFeature.d.ts
5
- interface TableReactivityFeatureConstructors<TFeatures extends TableFeatures, TData extends RowData> {}
6
- declare function constructReactivityFeature<TFeatures extends TableFeatures, TData extends RowData>(bindings: {
7
- stateNotifier?: () => unknown;
8
- optionsNotifier?: () => unknown;
9
- }): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>>;
10
- //#endregion
11
- export { TableReactivityFeatureConstructors, constructReactivityFeature };
12
- //# sourceMappingURL=tableReactivityFeature.d.ts.map
@@ -1,45 +0,0 @@
1
- //#region src/features/table-reactivity/tableReactivityFeature.ts
2
- function constructReactivityFeature(bindings) {
3
- return { constructTableAPIs: (table) => {
4
- table.optionsStore = bindStore(table.optionsStore, bindings.optionsNotifier);
5
- table.atoms = bindAtoms(table.atoms, bindings.stateNotifier);
6
- } };
7
- }
8
- const bindStore = (store, notifier) => {
9
- const stateDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(store), "state");
10
- Object.defineProperty(store, "state", {
11
- configurable: true,
12
- enumerable: true,
13
- get() {
14
- notifier === null || notifier === void 0 || notifier();
15
- return stateDescriptor.get.call(store);
16
- }
17
- });
18
- return store;
19
- };
20
- const bindAtoms = (atoms, notifier) => {
21
- if (!notifier) return atoms;
22
- const wrappedCache = /* @__PURE__ */ new Map();
23
- return new Proxy(atoms, { get(target, prop, receiver) {
24
- const atom = Reflect.get(target, prop, receiver);
25
- if (!atom || typeof prop !== "string" || !isAtomLike(atom)) return atom;
26
- if (wrappedCache.has(prop)) return wrappedCache.get(prop);
27
- const originalGet = atom.get.bind(atom);
28
- const wrapped = new Proxy(atom, { get(atomTarget, atomProp, atomReceiver) {
29
- if (atomProp === "get") return () => {
30
- notifier();
31
- return originalGet();
32
- };
33
- return Reflect.get(atomTarget, atomProp, atomReceiver);
34
- } });
35
- wrappedCache.set(prop, wrapped);
36
- return wrapped;
37
- } });
38
- };
39
- function isAtomLike(value) {
40
- return typeof value === "object" && value !== null && typeof value.get === "function";
41
- }
42
-
43
- //#endregion
44
- export { constructReactivityFeature };
45
- //# sourceMappingURL=tableReactivityFeature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tableReactivityFeature.js","names":[],"sources":["../../../src/features/table-reactivity/tableReactivityFeature.ts"],"sourcesContent":["import type { ReadonlyStore, Store } from '@tanstack/store'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\nexport interface TableReactivityFeatureConstructors<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {}\n\nexport function constructReactivityFeature<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(bindings: {\n stateNotifier?: () => unknown\n optionsNotifier?: () => unknown\n}): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {\n return {\n constructTableAPIs: (table) => {\n table.optionsStore = bindStore(\n table.optionsStore,\n bindings.optionsNotifier,\n )\n table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)\n },\n }\n}\n\nconst bindStore = <T extends Store<any> | ReadonlyStore<any>>(\n store: T,\n notifier?: () => unknown,\n): T => {\n const stateDescriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(store),\n 'state',\n )!\n\n Object.defineProperty(store, 'state', {\n configurable: true,\n enumerable: true,\n get() {\n notifier?.()\n return stateDescriptor.get!.call(store)\n },\n })\n\n return store\n}\n\n// Wraps an atoms/baseAtoms map so that `.get()` on any individual atom\n// calls the framework notifier first — matching how `bindStore` wraps\n// `store.state`. The proxy also transparently forwards missing slices\n// (atoms for features not registered on this table) as `undefined`.\nconst bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {\n if (!notifier) return atoms\n // Cache wrapped atoms so referential identity is stable per slice.\n const wrappedCache = new Map<PropertyKey, any>()\n return new Proxy(atoms, {\n get(target, prop, receiver) {\n const atom = Reflect.get(target, prop, receiver) as unknown\n if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {\n return atom\n }\n if (wrappedCache.has(prop)) return wrappedCache.get(prop)\n const originalGet = atom.get.bind(atom)\n const wrapped = new Proxy(atom, {\n get(atomTarget, atomProp, atomReceiver) {\n if (atomProp === 'get') {\n return () => {\n notifier()\n return originalGet()\n }\n }\n return Reflect.get(atomTarget, atomProp, atomReceiver)\n },\n })\n wrappedCache.set(prop, wrapped)\n return wrapped\n },\n })\n}\n\ninterface AtomLike {\n get: () => unknown\n}\n\nfunction isAtomLike(value: unknown): value is AtomLike {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function'\n )\n}\n"],"mappings":";AASA,SAAgB,2BAGd,UAGqE;AACrE,QAAO,EACL,qBAAqB,UAAU;AAC7B,QAAM,eAAe,UACnB,MAAM,cACN,SAAS,gBACV;AACD,QAAM,QAAQ,UAAU,MAAM,OAAO,SAAS,cAAc;IAE/D;;AAGH,MAAM,aACJ,OACA,aACM;CACN,MAAM,kBAAkB,OAAO,yBAC7B,OAAO,eAAe,MAAM,EAC5B,QACD;AAED,QAAO,eAAe,OAAO,SAAS;EACpC,cAAc;EACd,YAAY;EACZ,MAAM;AACJ,yDAAY;AACZ,UAAO,gBAAgB,IAAK,KAAK,MAAM;;EAE1C,CAAC;AAEF,QAAO;;AAOT,MAAM,aAA+B,OAAU,aAAgC;AAC7E,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,+BAAe,IAAI,KAAuB;AAChD,QAAO,IAAI,MAAM,OAAO,EACtB,IAAI,QAAQ,MAAM,UAAU;EAC1B,MAAM,OAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAChD,MAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,CAAC,WAAW,KAAK,CACxD,QAAO;AAET,MAAI,aAAa,IAAI,KAAK,CAAE,QAAO,aAAa,IAAI,KAAK;EACzD,MAAM,cAAc,KAAK,IAAI,KAAK,KAAK;EACvC,MAAM,UAAU,IAAI,MAAM,MAAM,EAC9B,IAAI,YAAY,UAAU,cAAc;AACtC,OAAI,aAAa,MACf,cAAa;AACX,cAAU;AACV,WAAO,aAAa;;AAGxB,UAAO,QAAQ,IAAI,YAAY,UAAU,aAAa;KAEzD,CAAC;AACF,eAAa,IAAI,MAAM,QAAQ;AAC/B,SAAO;IAEV,CAAC;;AAOJ,SAAS,WAAW,OAAmC;AACrD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ"}
@@ -1,92 +0,0 @@
1
- import type { ReadonlyStore, Store } from '@tanstack/store'
2
- import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
3
- import type { RowData } from '../../types/type-utils'
4
-
5
- export interface TableReactivityFeatureConstructors<
6
- TFeatures extends TableFeatures,
7
- TData extends RowData,
8
- > {}
9
-
10
- export function constructReactivityFeature<
11
- TFeatures extends TableFeatures,
12
- TData extends RowData,
13
- >(bindings: {
14
- stateNotifier?: () => unknown
15
- optionsNotifier?: () => unknown
16
- }): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>> {
17
- return {
18
- constructTableAPIs: (table) => {
19
- table.optionsStore = bindStore(
20
- table.optionsStore,
21
- bindings.optionsNotifier,
22
- )
23
- table.atoms = bindAtoms(table.atoms, bindings.stateNotifier)
24
- },
25
- }
26
- }
27
-
28
- const bindStore = <T extends Store<any> | ReadonlyStore<any>>(
29
- store: T,
30
- notifier?: () => unknown,
31
- ): T => {
32
- const stateDescriptor = Object.getOwnPropertyDescriptor(
33
- Object.getPrototypeOf(store),
34
- 'state',
35
- )!
36
-
37
- Object.defineProperty(store, 'state', {
38
- configurable: true,
39
- enumerable: true,
40
- get() {
41
- notifier?.()
42
- return stateDescriptor.get!.call(store)
43
- },
44
- })
45
-
46
- return store
47
- }
48
-
49
- // Wraps an atoms/baseAtoms map so that `.get()` on any individual atom
50
- // calls the framework notifier first — matching how `bindStore` wraps
51
- // `store.state`. The proxy also transparently forwards missing slices
52
- // (atoms for features not registered on this table) as `undefined`.
53
- const bindAtoms = <T extends object>(atoms: T, notifier?: () => unknown): T => {
54
- if (!notifier) return atoms
55
- // Cache wrapped atoms so referential identity is stable per slice.
56
- const wrappedCache = new Map<PropertyKey, any>()
57
- return new Proxy(atoms, {
58
- get(target, prop, receiver) {
59
- const atom = Reflect.get(target, prop, receiver) as unknown
60
- if (!atom || typeof prop !== 'string' || !isAtomLike(atom)) {
61
- return atom
62
- }
63
- if (wrappedCache.has(prop)) return wrappedCache.get(prop)
64
- const originalGet = atom.get.bind(atom)
65
- const wrapped = new Proxy(atom, {
66
- get(atomTarget, atomProp, atomReceiver) {
67
- if (atomProp === 'get') {
68
- return () => {
69
- notifier()
70
- return originalGet()
71
- }
72
- }
73
- return Reflect.get(atomTarget, atomProp, atomReceiver)
74
- },
75
- })
76
- wrappedCache.set(prop, wrapped)
77
- return wrapped
78
- },
79
- })
80
- }
81
-
82
- interface AtomLike {
83
- get: () => unknown
84
- }
85
-
86
- function isAtomLike(value: unknown): value is AtomLike {
87
- return (
88
- typeof value === 'object' &&
89
- value !== null &&
90
- typeof (value as { get?: unknown }).get === 'function'
91
- )
92
- }