@tanstack/table-core 9.0.0-alpha.13 → 9.0.0-alpha.16

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.
@@ -13,16 +13,22 @@ function constructTable(tableOptions) {
13
13
  const table = {
14
14
  _features: { ...coreFeatures, ...tableOptions._features },
15
15
  _rowModels: {},
16
- _rowModelFns: {}
16
+ _rowModelFns: {},
17
+ get options() {
18
+ return this.optionsStore.state;
19
+ },
20
+ set options(value) {
21
+ this.optionsStore.setState(() => value);
22
+ }
17
23
  };
18
24
  const featuresList = Object.values(table._features);
19
25
  const defaultOptions = featuresList.reduce((obj, feature) => {
20
26
  return Object.assign(obj, feature.getDefaultTableOptions?.(table));
21
27
  }, {});
22
- table.options = {
28
+ table.optionsStore = createStore({
23
29
  ...defaultOptions,
24
30
  ...tableOptions
25
- };
31
+ });
26
32
  table.initialState = getInitialTableState(
27
33
  table._features,
28
34
  table.options.initialState
@@ -32,7 +38,7 @@ function constructTable(tableOptions) {
32
38
  const state = table.baseStore.state;
33
39
  return {
34
40
  ...state,
35
- ...table.options.state ?? {}
41
+ ...table.optionsStore.state.state ?? {}
36
42
  };
37
43
  });
38
44
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
@@ -1 +1 @@
1
- {"version":3,"file":"constructTable.js","sources":["../../../../src/core/table/constructTable.ts"],"sourcesContent":["import { createStore } from '@tanstack/store'\nimport { coreFeatures } from '../coreFeatures'\nimport type { Store } from '@tanstack/store'\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 =\n feature.getInitialState?.(initialState as TableState<TFeatures>) ??\n initialState\n })\n return structuredClone(initialState) as TableState<TFeatures>\n}\n\nexport function createTableStore<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): Store<TableState<TFeatures>> {\n return createStore(getInitialTableState(features, initialState))\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 } 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.options = {\n ...defaultOptions,\n ...tableOptions,\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n table.baseStore = table.options.store ?? createStore(table.initialState)\n\n table.store = createStore(() => {\n const state = table.baseStore.state\n return {\n ...state,\n ...(table.options.state ?? {}),\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 }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"names":[],"mappings":";;AASO,SAAS,qBACd,UACA,eAA2D,IACpC;AACvB,SAAO,OAAO,QAAQ,EAAE,QAAQ,CAAC,YAAY;AAC3C,mBACE,QAAQ,kBAAkB,YAAqC,KAC/D;AAAA,EACJ,CAAC;AACD,SAAO,gBAAgB,YAAY;AACrC;AAEO,SAAS,iB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AqB,KAAK;AAAA,EACpC;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"constructTable.js","sources":["../../../../src/core/table/constructTable.ts"],"sourcesContent":["import { createStore } from '@tanstack/store'\nimport { coreFeatures } from '../coreFeatures'\nimport type { Store } from '@tanstack/store'\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 =\n feature.getInitialState?.(initialState as TableState<TFeatures>) ??\n initialState\n })\n return structuredClone(initialState) as TableState<TFeatures>\n}\n\nexport function createTableStore<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): Store<TableState<TFeatures>> {\n return createStore(getInitialTableState(features, initialState))\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 } 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 table.baseStore = table.options.store ?? createStore(table.initialState)\n\n table.store = createStore(() => {\n const state = table.baseStore.state\n return {\n ...state,\n ...(table.optionsStore.state.state ?? {}),\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 }\n\n for (const feature of featuresList) {\n feature.constructTableAPIs?.(table)\n }\n\n return table\n}\n"],"names":[],"mappings":";;AASO,SAAS,qBACd,UACA,eAA2D,IACpC;AACvB,SAAO,OAAO,QAAQ,EAAE,QAAQ,CAAC,YAAY;AAC3C,mBACE,QAAQ,kBAAkB,YAAqC,KAC/D;AAAA,EACJ,CAAC;AACD,SAAO,gBAAgB,YAAY;AACrC;AAEO,SAAS,iBACd,UACA,eAA2D,IAC7B;AAC9B,SAAO,YAAY,qBAAqB,UAAU,YAAY,CAAC;AACjE;AAEO,SAAS,eAGd,cAAuE;AACvE,QAAM,QAAQ;AAAA,IACZ,WAAW,EAAE,GAAG,cAAc,GAAG,aAAa,UAAA;AAAA,IAC9C,YAAY,CAAA;AAAA,IACZ,cAAc,CAAA;AAAA,IACd,IAAI,UAAU;AACZ,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IACA,IAAI,QAAQ,OAAO;AACjB,WAAK,aAAa,SAAS,MAAM,KAAK;AAAA,IACxC;AAAA,EAAA;AAGF,QAAM,eAAwC,OAAO,OAAO,MAAM,SAAS;AAE3E,QAAM,iBAAiB,aAAa,OAAO,CAAC,KAAK,YAAY;AAC3D,WAAO,OAAO,OAAO,KAAK,QAAQ,yBAAyB,KAAK,CAAC;AAAA,EACnE,GAAG,CAAA,CAAE;AAEL,QAAM,eAAe,YAAY;AAAA,IAC/B,GAAG;AAAA,IACH,GAAG;AAAA,EAAA,CACJ;AAED,QAAM,eAAe;AAAA,IACnB,MAAM;AAAA,IACN,MAAM,QAAQ;AAAA,EAAA;AAGhB,QAAM,YAAY,MAAM,QAAQ,SAAS,YAAY,MAAM,YAAY;AAEvE,QAAM,QAAQ,YAAY,MAAM;AAC9B,UAAM,QAAQ,MAAM,UAAU;AAC9B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,MAAM,aAAa,MAAM,SAAS,CAAA;AAAA,IAAC;AAAA,EAE3C,CAAC;AAED,MACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;AACA,UAAM,WAAW,OAAO,KAAK,MAAM,SAAS;AAC5C,UAAM,YAAY,OAAO,KAAK,MAAM,QAAQ,cAAc,EAAE;AAC5D,UAAM,SAAS,OAAO,KAAK,MAAM,YAAY;AAE7C,YAAQ;AAAA,MACN;AAAA;AAAA,gBAEU,SAAS,KAAK,kBAAkB,CAAC;AAAA;AAAA,gBAEjC,UAAU,SAAS,UAAU,KAAK,kBAAkB,IAAI,QAAQ;AAAA;AAAA,gBAEhE,OAAO,KAAK,kBAAkB,CAAC;AAAA,IAAA;AAAA,EAE7C;AAEA,aAAW,WAAW,cAAc;AAClC,YAAQ,qBAAqB,KAAK;AAAA,EACpC;AAEA,SAAO;AACT;"}
@@ -80,6 +80,10 @@ export interface Table_CoreProperties<TFeatures extends TableFeatures, TData ext
80
80
  * The base store for the table. This can be used to write to the table state.
81
81
  */
82
82
  baseStore: Store<TableState<TFeatures>>;
83
+ /**
84
+ * The base store for the table options.
85
+ */
86
+ optionsStore: Store<TableOptions<TFeatures, TData>>;
83
87
  /**
84
88
  * This is the resolved initial state of the table.
85
89
  */
@@ -87,7 +91,7 @@ export interface Table_CoreProperties<TFeatures extends TableFeatures, TData ext
87
91
  /**
88
92
  * A read-only reference to the table's current options.
89
93
  */
90
- options: TableOptions<TFeatures, TData>;
94
+ readonly options: TableOptions<TFeatures, TData>;
91
95
  /**
92
96
  * Where the table state is stored.
93
97
  */
@@ -13,7 +13,8 @@ function table_mergeOptions(table, newOptions) {
13
13
  }
14
14
  function table_setOptions(table, updater) {
15
15
  const newOptions = functionalUpdate(updater, table.options);
16
- table.options = table_mergeOptions(table, newOptions);
16
+ const mergedOptions = table_mergeOptions(table, newOptions);
17
+ table.optionsStore.setState(() => mergedOptions);
17
18
  }
18
19
  export {
19
20
  table_mergeOptions,
@@ -1 +1 @@
1
- {"version":3,"file":"coreTablesFeature.utils.js","sources":["../../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { functionalUpdate } from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\n\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n table.baseStore.setState(() => structuredClone(table.initialState))\n}\n\nexport function table_mergeOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n newOptions: TableOptions<TFeatures, TData>,\n) {\n if (table.options.mergeOptions) {\n return table.options.mergeOptions(table.options, newOptions)\n }\n\n return {\n ...table.options,\n ...newOptions,\n }\n}\n\nexport function table_setOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<TableOptions<TFeatures, TData>>,\n): void {\n const newOptions = functionalUpdate(updater, table.options)\n table.options = table_mergeOptions(table, newOptions)\n}\n"],"names":[],"mappings":";AAMO,SAAS,YAGd,OAA+C;AAC/C,QAAM,UAAU,SAAS,MAAM,gBAAgB,MAAM,YAAY,CAAC;AACpE;AAEO,SAAS,mBAId,OACA,YACA;AACA,MAAI,MAAM,QAAQ,cAAc;AAC9B,WAAO,MAAM,QAAQ,aAAa,MAAM,SAAS,UAAU;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,iBAId,OACA,SACM;AACN,QAAM,aAAa,iBAAiB,SAAS,MAAM,OAAO;AAC1D,QAAM,UAAU,mBAAmB,OAAO,UAAU;AACtD;"}
1
+ {"version":3,"file":"coreTablesFeature.utils.js","sources":["../../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { functionalUpdate } from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\n\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n table.baseStore.setState(() => structuredClone(table.initialState))\n}\n\nexport function table_mergeOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n newOptions: TableOptions<TFeatures, TData>,\n) {\n if (table.options.mergeOptions) {\n return table.options.mergeOptions(table.options, newOptions)\n }\n\n return {\n ...table.options,\n ...newOptions,\n }\n}\n\nexport function table_setOptions<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<TableOptions<TFeatures, TData>>,\n): void {\n const newOptions = functionalUpdate(updater, table.options)\n const mergedOptions = table_mergeOptions(table, newOptions)\n table.optionsStore.setState(() => mergedOptions)\n}\n"],"names":[],"mappings":";AAMO,SAAS,YAGd,OAA+C;AAC/C,QAAM,UAAU,SAAS,MAAM,gBAAgB,MAAM,YAAY,CAAC;AACpE;AAEO,SAAS,mBAId,OACA,YACA;AACA,MAAI,MAAM,QAAQ,cAAc;AAC9B,WAAO,MAAM,QAAQ,aAAa,MAAM,SAAS,UAAU;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,EAAA;AAEP;AAEO,SAAS,iBAId,OACA,SACM;AACN,QAAM,aAAa,iBAAiB,SAAS,MAAM,OAAO;AAC1D,QAAM,gBAAgB,mBAAmB,OAAO,UAAU;AAC1D,QAAM,aAAa,SAAS,MAAM,aAAa;AACjD;"}
@@ -0,0 +1,9 @@
1
+ import { TableFeature, TableFeatures } from '../../types/TableFeatures.js';
2
+ import { RowData } from '../../types/type-utils.js';
3
+ interface TableReactivityFeatureConstructors<TFeatures extends TableFeatures, TData extends RowData> {
4
+ }
5
+ export declare function constructReactivityFeature<TFeatures extends TableFeatures, TData extends RowData>(bindings: {
6
+ stateNotifier?: () => unknown;
7
+ optionsNotifier?: () => unknown;
8
+ }): TableFeature<TableReactivityFeatureConstructors<TFeatures, TData>>;
9
+ export {};
@@ -0,0 +1,30 @@
1
+ function constructReactivityFeature(bindings) {
2
+ return {
3
+ constructTableAPIs: (table) => {
4
+ table.store = bindStore(table.store, bindings.stateNotifier);
5
+ table.optionsStore = bindStore(
6
+ table.optionsStore,
7
+ bindings.optionsNotifier
8
+ );
9
+ }
10
+ };
11
+ }
12
+ const bindStore = (store, notifier) => {
13
+ const stateDescriptor = Object.getOwnPropertyDescriptor(
14
+ Object.getPrototypeOf(store),
15
+ "state"
16
+ );
17
+ Object.defineProperty(store, "state", {
18
+ configurable: true,
19
+ enumerable: true,
20
+ get() {
21
+ notifier?.();
22
+ return stateDescriptor.get.call(store);
23
+ }
24
+ });
25
+ return store;
26
+ };
27
+ export {
28
+ constructReactivityFeature
29
+ };
30
+ //# sourceMappingURL=tableReactivityFeature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableReactivityFeature.js","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\ninterface 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.store = bindStore(table.store, bindings.stateNotifier)\n table.optionsStore = bindStore(\n table.optionsStore,\n bindings.optionsNotifier,\n )\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"],"names":[],"mappings":"AASO,SAAS,2BAGd,UAGqE;AACrE,SAAO;AAAA,IACL,oBAAoB,CAAC,UAAU;AAC7B,YAAM,QAAQ,UAAU,MAAM,OAAO,SAAS,aAAa;AAC3D,YAAM,eAAe;AAAA,QACnB,MAAM;AAAA,QACN,SAAS;AAAA,MAAA;AAAA,IAEb;AAAA,EAAA;AAEJ;AAEA,MAAM,YAAY,CAChB,OACA,aACM;AACN,QAAM,kBAAkB,OAAO;AAAA,IAC7B,OAAO,eAAe,KAAK;AAAA,IAC3B;AAAA,EAAA;AAGF,SAAO,eAAe,OAAO,SAAS;AAAA,IACpC,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,MAAM;AACJ,iBAAA;AACA,aAAO,gBAAgB,IAAK,KAAK,KAAK;AAAA,IACxC;AAAA,EAAA,CACD;AAED,SAAO;AACT;"}
@@ -58,6 +58,7 @@ export * from './fns/sortFns.js';
58
58
  * Features
59
59
  */
60
60
  export * from './features/stockFeatures.js';
61
+ export * from './features/table-reactivity/tableReactivityFeature.js';
61
62
  export * from './features/column-faceting/columnFacetingFeature.js';
62
63
  export * from './features/column-faceting/columnFacetingFeature.types';
63
64
  export * from './features/column-faceting/columnFacetingFeature.utils';
package/dist/esm/index.js CHANGED
@@ -27,6 +27,7 @@ import { aggregationFn_count, aggregationFn_extent, aggregationFn_max, aggregati
27
27
  import { filterFn_arrHas, filterFn_arrIncludes, filterFn_arrIncludesAll, filterFn_arrIncludesSome, filterFn_equals, filterFn_equalsString, filterFn_equalsStringSensitive, filterFn_greaterThan, filterFn_greaterThanOrEqualTo, filterFn_inNumberRange, filterFn_includesString, filterFn_includesStringSensitive, filterFn_lessThan, filterFn_lessThanOrEqualTo, filterFn_weakEquals, filterFns } from "./fns/filterFns.js";
28
28
  import { reSplitAlphaNumeric, sortFn_alphanumeric, sortFn_alphanumericCaseSensitive, sortFn_basic, sortFn_datetime, sortFn_text, sortFn_textCaseSensitive, sortFns } from "./fns/sortFns.js";
29
29
  import { stockFeatures } from "./features/stockFeatures.js";
30
+ import { constructReactivityFeature } from "./features/table-reactivity/tableReactivityFeature.js";
30
31
  import { columnFacetingFeature, constructColumnFacetingFeature } from "./features/column-faceting/columnFacetingFeature.js";
31
32
  import { column_getFacetedMinMaxValues, column_getFacetedRowModel, column_getFacetedUniqueValues, table_getGlobalFacetedMinMaxValues, table_getGlobalFacetedRowModel, table_getGlobalFacetedUniqueValues } from "./features/column-faceting/columnFacetingFeature.utils.js";
32
33
  import { createFacetedMinMaxValues } from "./features/column-faceting/createFacetedMinMaxValues.js";
@@ -160,6 +161,7 @@ export {
160
161
  constructCoreTablesFeature,
161
162
  constructGlobalFilteringFeature,
162
163
  constructHeader,
164
+ constructReactivityFeature,
163
165
  constructRow,
164
166
  constructRowExpandingFeature,
165
167
  constructRowPaginationFeature,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type { Table, Table_Internal } from './types/Table'\nimport type { NoInfer, RowData, Updater } from './types/type-utils'\nimport type { TableFeatures } from './types/TableFeatures'\nimport type { TableState, TableState_All } from './types/TableState'\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (i: T) => T)(input)\n : updater\n}\n\nexport function noop() {}\n\nexport function makeStateUpdater<\n TFeatures extends TableFeatures,\n K extends (string & {}) | keyof TableState_All | keyof TableState<TFeatures>,\n>(key: K, instance: Table<TFeatures, any>) {\n return (updater: Updater<TableState<any>[K & keyof TableState<any>]>) => {\n ;(instance as Table_Internal<any, any>).baseStore.setState(\n <TTableState extends TableState_All>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n },\n )\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is Array<number> {\n return Array.isArray(d) && d.every((val) => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: Array<TNode>,\n getChildren: (item: TNode) => Array<TNode>,\n) {\n const flat: Array<TNode> = []\n\n const recurse = (subArr: Array<TNode>) => {\n subArr.forEach((item) => {\n flat.push(item)\n const children = getChildren(item)\n if (children.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport const $internalMemoFnMeta = Symbol('memoFnMeta')\nexport type MemoFnMeta = { originalArgsLength?: number }\n\n/**\n * @internal\n */\nfunction setMemoFnMeta(fn: Function, meta: MemoFnMeta) {\n Object.defineProperty(fn, $internalMemoFnMeta, { value: meta })\n}\n\n/**\n * @internal\n */\nexport function getMemoFnMeta(fn: any): MemoFnMeta | null {\n return (typeof fn === 'function' && fn[$internalMemoFnMeta]) ?? null\n}\n\ninterface MemoOptions<TDeps extends ReadonlyArray<any>, TDepArgs, TResult> {\n fn: (...args: NoInfer<TDeps>) => TResult\n memoDeps?: (depArgs?: TDepArgs) => [...TDeps] | undefined\n onAfterCompare?: (depsChanged: boolean) => void\n onAfterUpdate?: (result: TResult) => void\n onBeforeCompare?: () => void\n onBeforeUpdate?: () => void\n}\n\nexport const memo = <TDeps extends ReadonlyArray<any>, TDepArgs, TResult>({\n fn,\n memoDeps,\n onAfterCompare,\n onAfterUpdate,\n onBeforeCompare,\n onBeforeUpdate,\n}: MemoOptions<TDeps, TDepArgs, TResult>): ((\n depArgs?: TDepArgs,\n) => TResult) => {\n let deps: Array<any> | undefined = []\n let result: TResult | undefined\n\n const memoizedFn = (depArgs?: TDepArgs): TResult => {\n onBeforeCompare?.()\n const newDeps = memoDeps?.(depArgs)\n const depsChanged =\n !newDeps ||\n newDeps.length !== deps?.length ||\n newDeps.some((dep: any, index: number) => deps?.[index] !== dep)\n onAfterCompare?.(depsChanged)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n onBeforeUpdate?.()\n result = fn(...(newDeps ?? ([] as any)))\n onAfterUpdate?.(result)\n\n return result\n }\n\n setMemoFnMeta(memoizedFn, { originalArgsLength: fn.length })\n\n return memoizedFn\n}\n\ninterface TableMemoOptions<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n> extends MemoOptions<TDeps, TDepArgs, TResult> {\n feature?: keyof TFeatures & string\n fnName: string\n objectId?: string\n onAfterUpdate?: () => void\n table: Table_Internal<TFeatures, any>\n}\n\nconst pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n}\n\nexport function tableMemo<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n>({\n feature,\n fnName,\n objectId,\n onAfterUpdate,\n table,\n ...memoOptions\n}: TableMemoOptions<TFeatures, TDeps, TDepArgs, TResult>) {\n let beforeCompareTime: number\n let afterCompareTime: number\n let startCalcTime: number\n let endCalcTime: number\n let runCount = 0\n let debug: boolean | undefined\n let debugCache: boolean | undefined\n\n if (process.env.NODE_ENV === 'development') {\n const { debugCache: _debugCache, debugAll } = table.options\n debugCache = _debugCache\n const { parentName } = getFunctionNameInfo(fnName, '.')\n\n const debugByParent =\n // @ts-expect-error\n table.options[\n `debug${(parentName != 'table' ? parentName + 's' : parentName).replace(\n parentName,\n parentName.charAt(0).toUpperCase() + parentName.slice(1),\n )}`\n ]\n const debugByFeature = feature\n ? // @ts-expect-error\n table.options[\n `debug${feature.charAt(0).toUpperCase() + feature.slice(1)}`\n ]\n : false\n\n debug = debugAll || debugByParent || debugByFeature\n }\n\n function logTime(time: number, depsChanged: boolean) {\n const runType =\n runCount === 0\n ? '(1st run)'\n : depsChanged\n ? '(rerun #' + runCount + ')'\n : '(cache)'\n runCount++\n\n console.groupCollapsed(\n `%c⏱ ${pad(`${time.toFixed(1)} ms`, 12)} %c${runType}%c ${fnName}%c ${objectId ? `(${fnName.split('.')[0]}Id: ${objectId})` : ''}`,\n `font-size: .6rem; font-weight: bold; ${\n depsChanged\n ? `color: hsl(\n ${Math.max(0, Math.min(120 - Math.log10(time) * 60, 120))}deg 100% 31%);`\n : ''\n } `,\n `color: ${runCount < 2 ? '#FF00FF' : '#FF1493'}`,\n 'color: #666',\n 'color: #87CEEB',\n )\n console.info({\n feature,\n state: table.store.state,\n deps: memoOptions.memoDeps?.toString(),\n })\n console.trace()\n console.groupEnd()\n }\n\n const debugOptions =\n process.env.NODE_ENV === 'development'\n ? {\n onBeforeCompare: () => {\n if (debugCache) {\n beforeCompareTime = performance.now()\n }\n },\n onAfterCompare: (depsChanged: boolean) => {\n if (debugCache) {\n afterCompareTime = performance.now()\n const compareTime =\n Math.round((afterCompareTime - beforeCompareTime) * 100) / 100\n if (!depsChanged) {\n logTime(compareTime, depsChanged)\n }\n }\n },\n onBeforeUpdate: () => {\n if (debug) {\n startCalcTime = performance.now()\n }\n },\n onAfterUpdate: () => {\n if (debug) {\n endCalcTime = performance.now()\n const executionTime =\n Math.round((endCalcTime - startCalcTime) * 100) / 100\n logTime(executionTime, true)\n }\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n : {\n onAfterUpdate: () => {\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n\n return memo({\n ...memoOptions,\n ...debugOptions,\n })\n}\n\nexport interface API<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (...args: any) => any\n memoDeps?: (depArgs?: any) => [...any] | undefined\n}\n\nexport type APIObject<TDeps extends ReadonlyArray<any>, TDepArgs> = Record<\n string,\n API<TDeps, TDepArgs>\n>\n\n/**\n * Assumes that a function name is in the format of `parentName_fnKey` and returns the `fnKey` and `fnName` in the format of `parentName.fnKey`.\n */\nexport function getFunctionNameInfo(\n staticFnName: string,\n splitBy: '_' | '.' = '_',\n) {\n const [parentName, fnKey] = staticFnName.split(splitBy)\n const fnName = `${parentName}.${fnKey}`\n return { fnKey, fnName, parentName } as {\n fnKey: string\n fnName: string\n parentName: string\n }\n}\n\n/**\n * Assigns Table API methods directly to the table instance.\n * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.\n */\nexport function assignTableAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n table: Table_Internal<TFeatures, TData>,\n apis: APIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n ;(table as Record<string, any>)[fnKey] = memoDeps\n ? tableMemo({\n memoDeps,\n fn,\n fnName,\n table,\n feature,\n })\n : fn\n }\n}\n\nexport interface PrototypeAPI<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (self: any, ...args: any) => any\n memoDeps?: (self: any, depArgs?: any) => [...any] | undefined\n}\n\nexport type PrototypeAPIObject<\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n> = Record<string, PrototypeAPI<TDeps, TDepArgs>>\n\n/**\n * Assigns API methods to a prototype object for memory-efficient method sharing.\n * All instances created with this prototype will share the same method references.\n *\n * For memoized methods, the memo state is lazily created and stored on each instance.\n * This provides the best of both worlds: shared method code + per-instance caching.\n */\nexport function assignPrototypeAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n prototype: Record<string, any>,\n table: Table_Internal<TFeatures, TData>,\n apis: PrototypeAPIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n if (memoDeps) {\n // For memoized methods, create a function that lazily initializes\n // the memo on first access and stores it on the instance\n const memoKey = `_memo_${fnKey}`\n\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n // Lazily create memo on first access for this instance\n if (!this[memoKey]) {\n const self = this\n this[memoKey] = tableMemo({\n memoDeps: () => memoDeps(self),\n fn: (...deps) => fn(self, ...deps),\n fnName,\n objectId: self.id,\n table,\n feature,\n })\n }\n return this[memoKey](...args)\n }\n } else {\n // Non-memoized methods just call the static function with `this`\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n return fn(this, ...args)\n }\n }\n\n setMemoFnMeta(prototype[fnKey], { originalArgsLength: fn.length })\n }\n}\n\n/**\n * Looks to run the memoized function with the builder pattern on the object if it exists, otherwise fallback to the static method passed in.\n */\nexport function callMemoOrStaticFn<\n TObject extends Record<string, any>,\n TStaticFn extends AnyFunction,\n>(\n obj: TObject,\n fnKey: string,\n staticFn: TStaticFn,\n ...args: Parameters<TStaticFn> extends [any, ...infer Rest] ? Rest : never\n): ReturnType<TStaticFn> {\n return (\n (obj[fnKey] as Function | undefined)?.(...args) ?? staticFn(obj, ...args)\n )\n}\n"],"names":[],"mappings":"AAKO,SAAS,iBAAoB,SAAqB,OAAa;AACpE,SAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;AAEO,SAAS,OAAO;AAAC;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AAEA,kBAAc,UAAU,KAAK,GAAG,EAAE,oBAAoB,GAAG,QAAQ;AAAA,EACnE;AACF;AAKO,SAAS,mBAId,KACA,OACA,aACG,MACoB;AACvB,SACG,IAAI,KAAK,IAA6B,GAAG,IAAI,KAAK,SAAS,KAAK,GAAG,IAAI;AAE5E;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type { Table, Table_Internal } from './types/Table'\nimport type { NoInfer, RowData, Updater } from './types/type-utils'\nimport type { TableFeatures } from './types/TableFeatures'\nimport type { TableState, TableState_All } from './types/TableState'\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (i: T) => T)(input)\n : updater\n}\n\nexport function noop() {}\n\nexport function makeStateUpdater<\n TFeatures extends TableFeatures,\n K extends (string & {}) | keyof TableState_All | keyof TableState<TFeatures>,\n>(key: K, instance: Table<TFeatures, any>) {\n return (updater: Updater<TableState<any>[K & keyof TableState<any>]>) => {\n instance.baseStore.setState(\n <TTableState extends TableState_All>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n },\n )\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is Array<number> {\n return Array.isArray(d) && d.every((val) => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: Array<TNode>,\n getChildren: (item: TNode) => Array<TNode>,\n) {\n const flat: Array<TNode> = []\n\n const recurse = (subArr: Array<TNode>) => {\n subArr.forEach((item) => {\n flat.push(item)\n const children = getChildren(item)\n if (children.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport const $internalMemoFnMeta = Symbol('memoFnMeta')\nexport type MemoFnMeta = { originalArgsLength?: number }\n\n/**\n * @internal\n */\nfunction setMemoFnMeta(fn: Function, meta: MemoFnMeta) {\n Object.defineProperty(fn, $internalMemoFnMeta, { value: meta })\n}\n\n/**\n * @internal\n */\nexport function getMemoFnMeta(fn: any): MemoFnMeta | null {\n return (typeof fn === 'function' && fn[$internalMemoFnMeta]) ?? null\n}\n\ninterface MemoOptions<TDeps extends ReadonlyArray<any>, TDepArgs, TResult> {\n fn: (...args: NoInfer<TDeps>) => TResult\n memoDeps?: (depArgs?: TDepArgs) => [...TDeps] | undefined\n onAfterCompare?: (depsChanged: boolean) => void\n onAfterUpdate?: (result: TResult) => void\n onBeforeCompare?: () => void\n onBeforeUpdate?: () => void\n}\n\nexport const memo = <TDeps extends ReadonlyArray<any>, TDepArgs, TResult>({\n fn,\n memoDeps,\n onAfterCompare,\n onAfterUpdate,\n onBeforeCompare,\n onBeforeUpdate,\n}: MemoOptions<TDeps, TDepArgs, TResult>): ((\n depArgs?: TDepArgs,\n) => TResult) => {\n let deps: Array<any> | undefined = []\n let result: TResult | undefined\n\n const memoizedFn = (depArgs?: TDepArgs): TResult => {\n onBeforeCompare?.()\n const newDeps = memoDeps?.(depArgs)\n const depsChanged =\n !newDeps ||\n newDeps.length !== deps?.length ||\n newDeps.some((dep: any, index: number) => deps?.[index] !== dep)\n onAfterCompare?.(depsChanged)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n onBeforeUpdate?.()\n result = fn(...(newDeps ?? ([] as any)))\n onAfterUpdate?.(result)\n\n return result\n }\n\n setMemoFnMeta(memoizedFn, { originalArgsLength: fn.length })\n\n return memoizedFn\n}\n\ninterface TableMemoOptions<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n> extends MemoOptions<TDeps, TDepArgs, TResult> {\n feature?: keyof TFeatures & string\n fnName: string\n objectId?: string\n onAfterUpdate?: () => void\n table: Table_Internal<TFeatures, any>\n}\n\nconst pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n}\n\nexport function tableMemo<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n>({\n feature,\n fnName,\n objectId,\n onAfterUpdate,\n table,\n ...memoOptions\n}: TableMemoOptions<TFeatures, TDeps, TDepArgs, TResult>) {\n let beforeCompareTime: number\n let afterCompareTime: number\n let startCalcTime: number\n let endCalcTime: number\n let runCount = 0\n let debug: boolean | undefined\n let debugCache: boolean | undefined\n\n if (process.env.NODE_ENV === 'development') {\n const { debugCache: _debugCache, debugAll } = table.options\n debugCache = _debugCache\n const { parentName } = getFunctionNameInfo(fnName, '.')\n\n const debugByParent =\n // @ts-expect-error\n table.options[\n `debug${(parentName != 'table' ? parentName + 's' : parentName).replace(\n parentName,\n parentName.charAt(0).toUpperCase() + parentName.slice(1),\n )}`\n ]\n const debugByFeature = feature\n ? // @ts-expect-error\n table.options[\n `debug${feature.charAt(0).toUpperCase() + feature.slice(1)}`\n ]\n : false\n\n debug = debugAll || debugByParent || debugByFeature\n }\n\n function logTime(time: number, depsChanged: boolean) {\n const runType =\n runCount === 0\n ? '(1st run)'\n : depsChanged\n ? '(rerun #' + runCount + ')'\n : '(cache)'\n runCount++\n\n console.groupCollapsed(\n `%c⏱ ${pad(`${time.toFixed(1)} ms`, 12)} %c${runType}%c ${fnName}%c ${objectId ? `(${fnName.split('.')[0]}Id: ${objectId})` : ''}`,\n `font-size: .6rem; font-weight: bold; ${\n depsChanged\n ? `color: hsl(\n ${Math.max(0, Math.min(120 - Math.log10(time) * 60, 120))}deg 100% 31%);`\n : ''\n } `,\n `color: ${runCount < 2 ? '#FF00FF' : '#FF1493'}`,\n 'color: #666',\n 'color: #87CEEB',\n )\n console.info({\n feature,\n state: table.store.state,\n deps: memoOptions.memoDeps?.toString(),\n })\n console.trace()\n console.groupEnd()\n }\n\n const debugOptions =\n process.env.NODE_ENV === 'development'\n ? {\n onBeforeCompare: () => {\n if (debugCache) {\n beforeCompareTime = performance.now()\n }\n },\n onAfterCompare: (depsChanged: boolean) => {\n if (debugCache) {\n afterCompareTime = performance.now()\n const compareTime =\n Math.round((afterCompareTime - beforeCompareTime) * 100) / 100\n if (!depsChanged) {\n logTime(compareTime, depsChanged)\n }\n }\n },\n onBeforeUpdate: () => {\n if (debug) {\n startCalcTime = performance.now()\n }\n },\n onAfterUpdate: () => {\n if (debug) {\n endCalcTime = performance.now()\n const executionTime =\n Math.round((endCalcTime - startCalcTime) * 100) / 100\n logTime(executionTime, true)\n }\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n : {\n onAfterUpdate: () => {\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n\n return memo({\n ...memoOptions,\n ...debugOptions,\n })\n}\n\nexport interface API<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (...args: any) => any\n memoDeps?: (depArgs?: any) => [...any] | undefined\n}\n\nexport type APIObject<TDeps extends ReadonlyArray<any>, TDepArgs> = Record<\n string,\n API<TDeps, TDepArgs>\n>\n\n/**\n * Assumes that a function name is in the format of `parentName_fnKey` and returns the `fnKey` and `fnName` in the format of `parentName.fnKey`.\n */\nexport function getFunctionNameInfo(\n staticFnName: string,\n splitBy: '_' | '.' = '_',\n) {\n const [parentName, fnKey] = staticFnName.split(splitBy)\n const fnName = `${parentName}.${fnKey}`\n return { fnKey, fnName, parentName } as {\n fnKey: string\n fnName: string\n parentName: string\n }\n}\n\n/**\n * Assigns Table API methods directly to the table instance.\n * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.\n */\nexport function assignTableAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n table: Table_Internal<TFeatures, TData>,\n apis: APIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n ;(table as Record<string, any>)[fnKey] = memoDeps\n ? tableMemo({\n memoDeps,\n fn,\n fnName,\n table,\n feature,\n })\n : fn\n }\n}\n\nexport interface PrototypeAPI<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (self: any, ...args: any) => any\n memoDeps?: (self: any, depArgs?: any) => [...any] | undefined\n}\n\nexport type PrototypeAPIObject<\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n> = Record<string, PrototypeAPI<TDeps, TDepArgs>>\n\n/**\n * Assigns API methods to a prototype object for memory-efficient method sharing.\n * All instances created with this prototype will share the same method references.\n *\n * For memoized methods, the memo state is lazily created and stored on each instance.\n * This provides the best of both worlds: shared method code + per-instance caching.\n */\nexport function assignPrototypeAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n prototype: Record<string, any>,\n table: Table_Internal<TFeatures, TData>,\n apis: PrototypeAPIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n if (memoDeps) {\n // For memoized methods, create a function that lazily initializes\n // the memo on first access and stores it on the instance\n const memoKey = `_memo_${fnKey}`\n\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n // Lazily create memo on first access for this instance\n if (!this[memoKey]) {\n const self = this\n this[memoKey] = tableMemo({\n memoDeps: () => memoDeps(self),\n fn: (...deps) => fn(self, ...deps),\n fnName,\n objectId: self.id,\n table,\n feature,\n })\n }\n return this[memoKey](...args)\n }\n } else {\n // Non-memoized methods just call the static function with `this`\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n return fn(this, ...args)\n }\n }\n\n setMemoFnMeta(prototype[fnKey], { originalArgsLength: fn.length })\n }\n}\n\n/**\n * Looks to run the memoized function with the builder pattern on the object if it exists, otherwise fallback to the static method passed in.\n */\nexport function callMemoOrStaticFn<\n TObject extends Record<string, any>,\n TStaticFn extends AnyFunction,\n>(\n obj: TObject,\n fnKey: string,\n staticFn: TStaticFn,\n ...args: Parameters<TStaticFn> extends [any, ...infer Rest] ? Rest : never\n): ReturnType<TStaticFn> {\n return (\n (obj[fnKey] as Function | undefined)?.(...args) ?? staticFn(obj, ...args)\n )\n}\n"],"names":[],"mappings":"AAKO,SAAS,iBAAoB,SAAqB,OAAa;AACpE,SAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;AAEO,SAAS,OAAO;AAAC;AAEjB,SAAS,iBAGd,KAAQ,UAAiC;AACzC,SAAO,CAAC,YAAiE;AACvE,aAAS,UAAU;AAAA,MACjB,CAAqC,QAAqB;AACxD,eAAO;AAAA,UACL,GAAG;AAAA,UACH,CAAC,GAAG,GAAG,iBAAiB,SAAU,IAAY,GAAG,CAAC;AAAA,QAAA;AAAA,MAEtD;AAAA,IAAA;AAAA,EAEJ;AACF;AAIO,SAAS,WAAkC,GAAgB;AAChE,SAAO,aAAa;AACtB;AAEO,SAAS,cAAc,GAA4B;AACxD,SAAO,MAAM,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,OAAO,QAAQ,QAAQ;AACrE;AAEO,SAAS,UACd,KACA,aACA;AACA,QAAM,OAAqB,CAAA;AAE3B,QAAM,UAAU,CAAC,WAAyB;AACxC,WAAO,QAAQ,CAAC,SAAS;AACvB,WAAK,KAAK,IAAI;AACd,YAAM,WAAW,YAAY,IAAI;AACjC,UAAI,SAAS,QAAQ;AACnB,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,UAAQ,GAAG;AAEX,SAAO;AACT;AAEO,MAAM,6CAA6B,YAAY;AAMtD,SAAS,cAAc,IAAc,MAAkB;AACrD,SAAO,eAAe,IAAI,qBAAqB,EAAE,OAAO,MAAM;AAChE;AAKO,SAAS,cAAc,IAA4B;AACxD,UAAQ,OAAO,OAAO,cAAc,GAAG,mBAAmB,MAAM;AAClE;AAWO,MAAM,OAAO,CAAsD;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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jC;AAAA,YACA,UAAU,KAAK;AAAA,YACf;AAAA,YACA;AAAA,UAAA,CACD;AAAA,QACH;AACA,eAAO,KAAK,OAAO,EAAE,GAAG,IAAI;AAAA,MAC9B;AAAA,IACF,OAAO;AAEL,gBAAU,KAAK,IAAI,YAAwB,MAAkB;AAC3D,eAAO,GAAG,MAAM,GAAG,IAAI;AAAA,MACzB;AAAA,IACF;AAEA,kBAAc,UAAU,KAAK,GAAG,EAAE,oBAAoB,GAAG,QAAQ;AAAA,EACnE;AACF;AAKO,SAAS,mBAId,KACA,OACA,aACG,MACoB;AACvB,SACG,IAAI,KAAK,IAA6B,GAAG,IAAI,KAAK,SAAS,KAAK,GAAG,IAAI;AAE5E;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "9.0.0-alpha.13",
3
+ "version": "9.0.0-alpha.16",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "src"
46
46
  ],
47
47
  "dependencies": {
48
- "@tanstack/store": "^0.9.1"
48
+ "@tanstack/store": "^0.9.2"
49
49
  },
50
50
  "scripts": {
51
51
  "clean": "rimraf ./build && rimraf ./dist",
@@ -34,6 +34,12 @@ export function constructTable<
34
34
  _features: { ...coreFeatures, ...tableOptions._features },
35
35
  _rowModels: {},
36
36
  _rowModelFns: {},
37
+ get options() {
38
+ return this.optionsStore.state
39
+ },
40
+ set options(value) {
41
+ this.optionsStore.setState(() => value)
42
+ },
37
43
  } as Table_Internal<TFeatures, TData>
38
44
 
39
45
  const featuresList: Array<TableFeature<{}>> = Object.values(table._features)
@@ -42,10 +48,10 @@ export function constructTable<
42
48
  return Object.assign(obj, feature.getDefaultTableOptions?.(table))
43
49
  }, {}) as TableOptions<TFeatures, TData>
44
50
 
45
- table.options = {
51
+ table.optionsStore = createStore({
46
52
  ...defaultOptions,
47
53
  ...tableOptions,
48
- }
54
+ })
49
55
 
50
56
  table.initialState = getInitialTableState(
51
57
  table._features,
@@ -58,7 +64,7 @@ export function constructTable<
58
64
  const state = table.baseStore.state
59
65
  return {
60
66
  ...state,
61
- ...(table.options.state ?? {}),
67
+ ...(table.optionsStore.state.state ?? {}),
62
68
  }
63
69
  })
64
70
 
@@ -94,6 +94,10 @@ export interface Table_CoreProperties<
94
94
  * The base store for the table. This can be used to write to the table state.
95
95
  */
96
96
  baseStore: Store<TableState<TFeatures>>
97
+ /**
98
+ * The base store for the table options.
99
+ */
100
+ optionsStore: Store<TableOptions<TFeatures, TData>>
97
101
  /**
98
102
  * This is the resolved initial state of the table.
99
103
  */
@@ -101,7 +105,7 @@ export interface Table_CoreProperties<
101
105
  /**
102
106
  * A read-only reference to the table's current options.
103
107
  */
104
- options: TableOptions<TFeatures, TData>
108
+ readonly options: TableOptions<TFeatures, TData>
105
109
  /**
106
110
  * Where the table state is stored.
107
111
  */
@@ -36,5 +36,6 @@ export function table_setOptions<
36
36
  updater: Updater<TableOptions<TFeatures, TData>>,
37
37
  ): void {
38
38
  const newOptions = functionalUpdate(updater, table.options)
39
- table.options = table_mergeOptions(table, newOptions)
39
+ const mergedOptions = table_mergeOptions(table, newOptions)
40
+ table.optionsStore.setState(() => mergedOptions)
40
41
  }
@@ -0,0 +1,47 @@
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
+ 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.store = bindStore(table.store, bindings.stateNotifier)
20
+ table.optionsStore = bindStore(
21
+ table.optionsStore,
22
+ bindings.optionsNotifier,
23
+ )
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
+ }
package/src/index.ts CHANGED
@@ -78,6 +78,9 @@ export * from './fns/sortFns'
78
78
 
79
79
  export * from './features/stockFeatures'
80
80
 
81
+ // tableReactivityFeature
82
+ export * from './features/table-reactivity/tableReactivityFeature'
83
+
81
84
  // columnFacetingFeature
82
85
  export * from './features/column-faceting/columnFacetingFeature'
83
86
  export * from './features/column-faceting/columnFacetingFeature.types'
package/src/utils.ts CHANGED
@@ -16,7 +16,7 @@ export function makeStateUpdater<
16
16
  K extends (string & {}) | keyof TableState_All | keyof TableState<TFeatures>,
17
17
  >(key: K, instance: Table<TFeatures, any>) {
18
18
  return (updater: Updater<TableState<any>[K & keyof TableState<any>]>) => {
19
- ;(instance as Table_Internal<any, any>).baseStore.setState(
19
+ instance.baseStore.setState(
20
20
  <TTableState extends TableState_All>(old: TTableState) => {
21
21
  return {
22
22
  ...old,