@tanstack/table-core 9.0.0-beta.12 → 9.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/table/coreTablesFeature.utils.cjs +33 -11
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +3 -1
- package/dist/core/table/coreTablesFeature.utils.d.ts +3 -1
- package/dist/core/table/coreTablesFeature.utils.js +33 -11
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/core/table/coreTablesFeature.utils.ts +47 -18
|
@@ -49,7 +49,9 @@ function table_reset(table) {
|
|
|
49
49
|
* Merges new table options with the current resolved options.
|
|
50
50
|
*
|
|
51
51
|
* If `options.mergeOptions` is provided, it owns the merge behavior; otherwise
|
|
52
|
-
* options are shallow-merged.
|
|
52
|
+
* options are shallow-merged. Static options that should never change after
|
|
53
|
+
* initialization are restored on a fresh object so framework merge helpers may
|
|
54
|
+
* return readonly getter/proxy objects.
|
|
53
55
|
*
|
|
54
56
|
* @example
|
|
55
57
|
* ```ts
|
|
@@ -57,11 +59,37 @@ function table_reset(table) {
|
|
|
57
59
|
* ```
|
|
58
60
|
*/
|
|
59
61
|
function table_mergeOptions(table, newOptions) {
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
+
const { features, atoms, initialState } = table.options;
|
|
63
|
+
if (!table.options.mergeOptions) return {
|
|
62
64
|
...table.options,
|
|
63
|
-
...newOptions
|
|
65
|
+
...newOptions,
|
|
66
|
+
features,
|
|
67
|
+
atoms,
|
|
68
|
+
initialState
|
|
64
69
|
};
|
|
70
|
+
const mergedOptions = table.options.mergeOptions(table.options, newOptions);
|
|
71
|
+
const descriptors = { ...Object.getOwnPropertyDescriptors(mergedOptions) };
|
|
72
|
+
return Object.defineProperties(Object.create(Object.getPrototypeOf(mergedOptions)), {
|
|
73
|
+
...descriptors,
|
|
74
|
+
features: {
|
|
75
|
+
value: features,
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true
|
|
79
|
+
},
|
|
80
|
+
atoms: {
|
|
81
|
+
value: atoms,
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true
|
|
85
|
+
},
|
|
86
|
+
initialState: {
|
|
87
|
+
value: initialState,
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true
|
|
91
|
+
}
|
|
92
|
+
});
|
|
65
93
|
}
|
|
66
94
|
/**
|
|
67
95
|
* Updates the table options object.
|
|
@@ -75,13 +103,7 @@ function table_mergeOptions(table, newOptions) {
|
|
|
75
103
|
* ```
|
|
76
104
|
*/
|
|
77
105
|
function table_setOptions(table, updater) {
|
|
78
|
-
const
|
|
79
|
-
const { features, atoms, initialState } = table.options;
|
|
80
|
-
const mergedOptions = Object.assign(table_mergeOptions(table, newOptions), {
|
|
81
|
-
features,
|
|
82
|
-
atoms,
|
|
83
|
-
initialState
|
|
84
|
-
});
|
|
106
|
+
const mergedOptions = table_mergeOptions(table, require_utils.functionalUpdate(updater, table.options));
|
|
85
107
|
if (table.optionsStore) table.optionsStore.set(() => mergedOptions);
|
|
86
108
|
else table.options = mergedOptions;
|
|
87
109
|
table_syncExternalStateToBaseAtoms(table);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreTablesFeature.utils.cjs","names":["cloneState","functionalUpdate"],"sources":["../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { cloneState, 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\n/**\n * Synchronizes externally controlled state slices into the table's base atoms.\n *\n * This keeps legacy `options.state` values reflected in the atom graph so\n * derived atoms, stores, and table APIs read a consistent snapshot.\n *\n * @example\n * ```ts\n * table_syncExternalStateToBaseAtoms(table)\n * ```\n */\nexport function table_syncExternalStateToBaseAtoms<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const state = table.options.state\n if (!state) {\n return\n }\n\n table._reactivity.batch(() => {\n for (const key in state) {\n const baseAtom = (table.baseAtoms as Record<string, any>)[key]\n if (!baseAtom) {\n continue\n }\n\n const externalState = state[key as keyof typeof state]\n if (externalState !== baseAtom.get()) {\n baseAtom.set(() => externalState)\n }\n }\n })\n}\n\n/**\n * Resets all internal table base atoms to `table.initialState`.\n *\n * This resets internally owned state slices in a single reactivity batch. Use\n * feature-specific reset APIs when a slice may be externally owned.\n *\n * @example\n * ```ts\n * table_reset(table)\n * ```\n */\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const snap = cloneState(table.initialState)\n table._reactivity.batch(() => {\n const keys = Object.keys(snap) as Array<keyof typeof snap>\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n ;(table.baseAtoms as any)[key].set(snap[key])\n }\n })\n}\n\n/**\n * Merges new table options with the current resolved options.\n *\n * If `options.mergeOptions` is provided, it owns the merge behavior; otherwise\n * options are shallow-merged.\n *\n * @example\n * ```ts\n * const options = table_mergeOptions(table, nextOptions)\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(\n
|
|
1
|
+
{"version":3,"file":"coreTablesFeature.utils.cjs","names":["cloneState","functionalUpdate"],"sources":["../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { cloneState, 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\n/**\n * Synchronizes externally controlled state slices into the table's base atoms.\n *\n * This keeps legacy `options.state` values reflected in the atom graph so\n * derived atoms, stores, and table APIs read a consistent snapshot.\n *\n * @example\n * ```ts\n * table_syncExternalStateToBaseAtoms(table)\n * ```\n */\nexport function table_syncExternalStateToBaseAtoms<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const state = table.options.state\n if (!state) {\n return\n }\n\n table._reactivity.batch(() => {\n for (const key in state) {\n const baseAtom = (table.baseAtoms as Record<string, any>)[key]\n if (!baseAtom) {\n continue\n }\n\n const externalState = state[key as keyof typeof state]\n if (externalState !== baseAtom.get()) {\n baseAtom.set(() => externalState)\n }\n }\n })\n}\n\n/**\n * Resets all internal table base atoms to `table.initialState`.\n *\n * This resets internally owned state slices in a single reactivity batch. Use\n * feature-specific reset APIs when a slice may be externally owned.\n *\n * @example\n * ```ts\n * table_reset(table)\n * ```\n */\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const snap = cloneState(table.initialState)\n table._reactivity.batch(() => {\n const keys = Object.keys(snap) as Array<keyof typeof snap>\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n ;(table.baseAtoms as any)[key].set(snap[key])\n }\n })\n}\n\n/**\n * Merges new table options with the current resolved options.\n *\n * If `options.mergeOptions` is provided, it owns the merge behavior; otherwise\n * options are shallow-merged. Static options that should never change after\n * initialization are restored on a fresh object so framework merge helpers may\n * return readonly getter/proxy objects.\n *\n * @example\n * ```ts\n * const options = table_mergeOptions(table, nextOptions)\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 const { features, atoms, initialState } = table.options\n\n // simple merge if no mergeOptions is provided - performant\n if (!table.options.mergeOptions) {\n return {\n ...table.options,\n ...newOptions,\n features,\n atoms,\n initialState,\n }\n }\n\n // else use the mergeOptions function and preserve getters/setters\n const mergedOptions = table.options.mergeOptions(\n table.options as TableOptions<TFeatures, TData>,\n newOptions,\n )\n const descriptors: PropertyDescriptorMap = {\n ...Object.getOwnPropertyDescriptors(mergedOptions),\n }\n\n return Object.defineProperties(\n Object.create(Object.getPrototypeOf(mergedOptions)),\n {\n ...descriptors,\n features: {\n value: features,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n atoms: {\n value: atoms,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n initialState: {\n value: initialState,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n },\n ) as TableOptions<TFeatures, TData>\n}\n\n/**\n * Updates the table options object.\n *\n * The updater receives the current resolved options and the merged result is\n * immediately assigned to the table instance.\n *\n * @example\n * ```ts\n * table_setOptions(table, (old) => old)\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(\n updater,\n table.options as TableOptions<TFeatures, TData>,\n )\n const mergedOptions = table_mergeOptions(table, newOptions)\n\n if (table.optionsStore) {\n table.optionsStore.set(() => mergedOptions)\n } else {\n table.options = mergedOptions\n }\n table_syncExternalStateToBaseAtoms(table)\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,mCAGd,OAA+C;CAC/C,MAAM,QAAQ,MAAM,QAAQ;CAC5B,IAAI,CAAC,OACH;CAGF,MAAM,YAAY,YAAY;EAC5B,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,WAAY,MAAM,UAAkC;GAC1D,IAAI,CAAC,UACH;GAGF,MAAM,gBAAgB,MAAM;GAC5B,IAAI,kBAAkB,SAAS,IAAI,GACjC,SAAS,UAAU,aAAa;EAEpC;CACF,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,YAGd,OAA+C;CAC/C,MAAM,OAAOA,yBAAW,MAAM,YAAY;CAC1C,MAAM,YAAY,YAAY;EAC5B,MAAM,OAAO,OAAO,KAAK,IAAI;EAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GAChB,AAAC,MAAM,UAAkB,IAAI,CAAC,IAAI,KAAK,IAAI;EAC9C;CACF,CAAC;AACH;;;;;;;;;;;;;;AAeA,SAAgB,mBAId,OACA,YACA;CACA,MAAM,EAAE,UAAU,OAAO,iBAAiB,MAAM;CAGhD,IAAI,CAAC,MAAM,QAAQ,cACjB,OAAO;EACL,GAAG,MAAM;EACT,GAAG;EACH;EACA;EACA;CACF;CAIF,MAAM,gBAAgB,MAAM,QAAQ,aAClC,MAAM,SACN,UACF;CACA,MAAM,cAAqC,EACzC,GAAG,OAAO,0BAA0B,aAAa,EACnD;CAEA,OAAO,OAAO,iBACZ,OAAO,OAAO,OAAO,eAAe,aAAa,CAAC,GAClD;EACE,GAAG;EACH,UAAU;GACR,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;EACA,OAAO;GACL,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;EACA,cAAc;GACZ,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;CACF,CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,iBAId,OACA,SACM;CAKN,MAAM,gBAAgB,mBAAmB,OAJtBC,+BACjB,SACA,MAAM,OAEiD,CAAC;CAE1D,IAAI,MAAM,cACR,MAAM,aAAa,UAAU,aAAa;MAE1C,MAAM,UAAU;CAElB,mCAAmC,KAAK;AAC1C"}
|
|
@@ -32,7 +32,9 @@ declare function table_reset<TFeatures extends TableFeatures, TData extends RowD
|
|
|
32
32
|
* Merges new table options with the current resolved options.
|
|
33
33
|
*
|
|
34
34
|
* If `options.mergeOptions` is provided, it owns the merge behavior; otherwise
|
|
35
|
-
* options are shallow-merged.
|
|
35
|
+
* options are shallow-merged. Static options that should never change after
|
|
36
|
+
* initialization are restored on a fresh object so framework merge helpers may
|
|
37
|
+
* return readonly getter/proxy objects.
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
@@ -32,7 +32,9 @@ declare function table_reset<TFeatures extends TableFeatures, TData extends RowD
|
|
|
32
32
|
* Merges new table options with the current resolved options.
|
|
33
33
|
*
|
|
34
34
|
* If `options.mergeOptions` is provided, it owns the merge behavior; otherwise
|
|
35
|
-
* options are shallow-merged.
|
|
35
|
+
* options are shallow-merged. Static options that should never change after
|
|
36
|
+
* initialization are restored on a fresh object so framework merge helpers may
|
|
37
|
+
* return readonly getter/proxy objects.
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
@@ -49,7 +49,9 @@ function table_reset(table) {
|
|
|
49
49
|
* Merges new table options with the current resolved options.
|
|
50
50
|
*
|
|
51
51
|
* If `options.mergeOptions` is provided, it owns the merge behavior; otherwise
|
|
52
|
-
* options are shallow-merged.
|
|
52
|
+
* options are shallow-merged. Static options that should never change after
|
|
53
|
+
* initialization are restored on a fresh object so framework merge helpers may
|
|
54
|
+
* return readonly getter/proxy objects.
|
|
53
55
|
*
|
|
54
56
|
* @example
|
|
55
57
|
* ```ts
|
|
@@ -57,11 +59,37 @@ function table_reset(table) {
|
|
|
57
59
|
* ```
|
|
58
60
|
*/
|
|
59
61
|
function table_mergeOptions(table, newOptions) {
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
+
const { features, atoms, initialState } = table.options;
|
|
63
|
+
if (!table.options.mergeOptions) return {
|
|
62
64
|
...table.options,
|
|
63
|
-
...newOptions
|
|
65
|
+
...newOptions,
|
|
66
|
+
features,
|
|
67
|
+
atoms,
|
|
68
|
+
initialState
|
|
64
69
|
};
|
|
70
|
+
const mergedOptions = table.options.mergeOptions(table.options, newOptions);
|
|
71
|
+
const descriptors = { ...Object.getOwnPropertyDescriptors(mergedOptions) };
|
|
72
|
+
return Object.defineProperties(Object.create(Object.getPrototypeOf(mergedOptions)), {
|
|
73
|
+
...descriptors,
|
|
74
|
+
features: {
|
|
75
|
+
value: features,
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true
|
|
79
|
+
},
|
|
80
|
+
atoms: {
|
|
81
|
+
value: atoms,
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true
|
|
85
|
+
},
|
|
86
|
+
initialState: {
|
|
87
|
+
value: initialState,
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true
|
|
91
|
+
}
|
|
92
|
+
});
|
|
65
93
|
}
|
|
66
94
|
/**
|
|
67
95
|
* Updates the table options object.
|
|
@@ -75,13 +103,7 @@ function table_mergeOptions(table, newOptions) {
|
|
|
75
103
|
* ```
|
|
76
104
|
*/
|
|
77
105
|
function table_setOptions(table, updater) {
|
|
78
|
-
const
|
|
79
|
-
const { features, atoms, initialState } = table.options;
|
|
80
|
-
const mergedOptions = Object.assign(table_mergeOptions(table, newOptions), {
|
|
81
|
-
features,
|
|
82
|
-
atoms,
|
|
83
|
-
initialState
|
|
84
|
-
});
|
|
106
|
+
const mergedOptions = table_mergeOptions(table, functionalUpdate(updater, table.options));
|
|
85
107
|
if (table.optionsStore) table.optionsStore.set(() => mergedOptions);
|
|
86
108
|
else table.options = mergedOptions;
|
|
87
109
|
table_syncExternalStateToBaseAtoms(table);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreTablesFeature.utils.js","names":[],"sources":["../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { cloneState, 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\n/**\n * Synchronizes externally controlled state slices into the table's base atoms.\n *\n * This keeps legacy `options.state` values reflected in the atom graph so\n * derived atoms, stores, and table APIs read a consistent snapshot.\n *\n * @example\n * ```ts\n * table_syncExternalStateToBaseAtoms(table)\n * ```\n */\nexport function table_syncExternalStateToBaseAtoms<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const state = table.options.state\n if (!state) {\n return\n }\n\n table._reactivity.batch(() => {\n for (const key in state) {\n const baseAtom = (table.baseAtoms as Record<string, any>)[key]\n if (!baseAtom) {\n continue\n }\n\n const externalState = state[key as keyof typeof state]\n if (externalState !== baseAtom.get()) {\n baseAtom.set(() => externalState)\n }\n }\n })\n}\n\n/**\n * Resets all internal table base atoms to `table.initialState`.\n *\n * This resets internally owned state slices in a single reactivity batch. Use\n * feature-specific reset APIs when a slice may be externally owned.\n *\n * @example\n * ```ts\n * table_reset(table)\n * ```\n */\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const snap = cloneState(table.initialState)\n table._reactivity.batch(() => {\n const keys = Object.keys(snap) as Array<keyof typeof snap>\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n ;(table.baseAtoms as any)[key].set(snap[key])\n }\n })\n}\n\n/**\n * Merges new table options with the current resolved options.\n *\n * If `options.mergeOptions` is provided, it owns the merge behavior; otherwise\n * options are shallow-merged.\n *\n * @example\n * ```ts\n * const options = table_mergeOptions(table, nextOptions)\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(\n
|
|
1
|
+
{"version":3,"file":"coreTablesFeature.utils.js","names":[],"sources":["../../../src/core/table/coreTablesFeature.utils.ts"],"sourcesContent":["import { cloneState, 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\n/**\n * Synchronizes externally controlled state slices into the table's base atoms.\n *\n * This keeps legacy `options.state` values reflected in the atom graph so\n * derived atoms, stores, and table APIs read a consistent snapshot.\n *\n * @example\n * ```ts\n * table_syncExternalStateToBaseAtoms(table)\n * ```\n */\nexport function table_syncExternalStateToBaseAtoms<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const state = table.options.state\n if (!state) {\n return\n }\n\n table._reactivity.batch(() => {\n for (const key in state) {\n const baseAtom = (table.baseAtoms as Record<string, any>)[key]\n if (!baseAtom) {\n continue\n }\n\n const externalState = state[key as keyof typeof state]\n if (externalState !== baseAtom.get()) {\n baseAtom.set(() => externalState)\n }\n }\n })\n}\n\n/**\n * Resets all internal table base atoms to `table.initialState`.\n *\n * This resets internally owned state slices in a single reactivity batch. Use\n * feature-specific reset APIs when a slice may be externally owned.\n *\n * @example\n * ```ts\n * table_reset(table)\n * ```\n */\nexport function table_reset<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): void {\n const snap = cloneState(table.initialState)\n table._reactivity.batch(() => {\n const keys = Object.keys(snap) as Array<keyof typeof snap>\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n ;(table.baseAtoms as any)[key].set(snap[key])\n }\n })\n}\n\n/**\n * Merges new table options with the current resolved options.\n *\n * If `options.mergeOptions` is provided, it owns the merge behavior; otherwise\n * options are shallow-merged. Static options that should never change after\n * initialization are restored on a fresh object so framework merge helpers may\n * return readonly getter/proxy objects.\n *\n * @example\n * ```ts\n * const options = table_mergeOptions(table, nextOptions)\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 const { features, atoms, initialState } = table.options\n\n // simple merge if no mergeOptions is provided - performant\n if (!table.options.mergeOptions) {\n return {\n ...table.options,\n ...newOptions,\n features,\n atoms,\n initialState,\n }\n }\n\n // else use the mergeOptions function and preserve getters/setters\n const mergedOptions = table.options.mergeOptions(\n table.options as TableOptions<TFeatures, TData>,\n newOptions,\n )\n const descriptors: PropertyDescriptorMap = {\n ...Object.getOwnPropertyDescriptors(mergedOptions),\n }\n\n return Object.defineProperties(\n Object.create(Object.getPrototypeOf(mergedOptions)),\n {\n ...descriptors,\n features: {\n value: features,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n atoms: {\n value: atoms,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n initialState: {\n value: initialState,\n enumerable: true,\n configurable: true,\n writable: true,\n },\n },\n ) as TableOptions<TFeatures, TData>\n}\n\n/**\n * Updates the table options object.\n *\n * The updater receives the current resolved options and the merged result is\n * immediately assigned to the table instance.\n *\n * @example\n * ```ts\n * table_setOptions(table, (old) => old)\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(\n updater,\n table.options as TableOptions<TFeatures, TData>,\n )\n const mergedOptions = table_mergeOptions(table, newOptions)\n\n if (table.optionsStore) {\n table.optionsStore.set(() => mergedOptions)\n } else {\n table.options = mergedOptions\n }\n table_syncExternalStateToBaseAtoms(table)\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,mCAGd,OAA+C;CAC/C,MAAM,QAAQ,MAAM,QAAQ;CAC5B,IAAI,CAAC,OACH;CAGF,MAAM,YAAY,YAAY;EAC5B,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,WAAY,MAAM,UAAkC;GAC1D,IAAI,CAAC,UACH;GAGF,MAAM,gBAAgB,MAAM;GAC5B,IAAI,kBAAkB,SAAS,IAAI,GACjC,SAAS,UAAU,aAAa;EAEpC;CACF,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,YAGd,OAA+C;CAC/C,MAAM,OAAO,WAAW,MAAM,YAAY;CAC1C,MAAM,YAAY,YAAY;EAC5B,MAAM,OAAO,OAAO,KAAK,IAAI;EAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GAChB,AAAC,MAAM,UAAkB,IAAI,CAAC,IAAI,KAAK,IAAI;EAC9C;CACF,CAAC;AACH;;;;;;;;;;;;;;AAeA,SAAgB,mBAId,OACA,YACA;CACA,MAAM,EAAE,UAAU,OAAO,iBAAiB,MAAM;CAGhD,IAAI,CAAC,MAAM,QAAQ,cACjB,OAAO;EACL,GAAG,MAAM;EACT,GAAG;EACH;EACA;EACA;CACF;CAIF,MAAM,gBAAgB,MAAM,QAAQ,aAClC,MAAM,SACN,UACF;CACA,MAAM,cAAqC,EACzC,GAAG,OAAO,0BAA0B,aAAa,EACnD;CAEA,OAAO,OAAO,iBACZ,OAAO,OAAO,OAAO,eAAe,aAAa,CAAC,GAClD;EACE,GAAG;EACH,UAAU;GACR,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;EACA,OAAO;GACL,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;EACA,cAAc;GACZ,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ;CACF,CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,iBAId,OACA,SACM;CAKN,MAAM,gBAAgB,mBAAmB,OAJtB,iBACjB,SACA,MAAM,OAEiD,CAAC;CAE1D,IAAI,MAAM,cACR,MAAM,aAAa,UAAU,aAAa;MAE1C,MAAM,UAAU;CAElB,mCAAmC,KAAK;AAC1C"}
|
package/package.json
CHANGED
|
@@ -68,7 +68,9 @@ export function table_reset<
|
|
|
68
68
|
* Merges new table options with the current resolved options.
|
|
69
69
|
*
|
|
70
70
|
* If `options.mergeOptions` is provided, it owns the merge behavior; otherwise
|
|
71
|
-
* options are shallow-merged.
|
|
71
|
+
* options are shallow-merged. Static options that should never change after
|
|
72
|
+
* initialization are restored on a fresh object so framework merge helpers may
|
|
73
|
+
* return readonly getter/proxy objects.
|
|
72
74
|
*
|
|
73
75
|
* @example
|
|
74
76
|
* ```ts
|
|
@@ -82,17 +84,52 @@ export function table_mergeOptions<
|
|
|
82
84
|
table: Table_Internal<TFeatures, TData>,
|
|
83
85
|
newOptions: TableOptions<TFeatures, TData>,
|
|
84
86
|
) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const { features, atoms, initialState } = table.options
|
|
88
|
+
|
|
89
|
+
// simple merge if no mergeOptions is provided - performant
|
|
90
|
+
if (!table.options.mergeOptions) {
|
|
91
|
+
return {
|
|
92
|
+
...table.options,
|
|
93
|
+
...newOptions,
|
|
94
|
+
features,
|
|
95
|
+
atoms,
|
|
96
|
+
initialState,
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
// else use the mergeOptions function and preserve getters/setters
|
|
101
|
+
const mergedOptions = table.options.mergeOptions(
|
|
102
|
+
table.options as TableOptions<TFeatures, TData>,
|
|
103
|
+
newOptions,
|
|
104
|
+
)
|
|
105
|
+
const descriptors: PropertyDescriptorMap = {
|
|
106
|
+
...Object.getOwnPropertyDescriptors(mergedOptions),
|
|
95
107
|
}
|
|
108
|
+
|
|
109
|
+
return Object.defineProperties(
|
|
110
|
+
Object.create(Object.getPrototypeOf(mergedOptions)),
|
|
111
|
+
{
|
|
112
|
+
...descriptors,
|
|
113
|
+
features: {
|
|
114
|
+
value: features,
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
},
|
|
119
|
+
atoms: {
|
|
120
|
+
value: atoms,
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
},
|
|
125
|
+
initialState: {
|
|
126
|
+
value: initialState,
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
) as TableOptions<TFeatures, TData>
|
|
96
133
|
}
|
|
97
134
|
|
|
98
135
|
/**
|
|
@@ -117,15 +154,7 @@ export function table_setOptions<
|
|
|
117
154
|
updater,
|
|
118
155
|
table.options as TableOptions<TFeatures, TData>,
|
|
119
156
|
)
|
|
120
|
-
|
|
121
|
-
const { features, atoms, initialState } = table.options
|
|
122
|
-
const mergedOptions = Object.assign(table_mergeOptions(table, newOptions), {
|
|
123
|
-
// Once the table instance is created those properties should never change after initialization,
|
|
124
|
-
// so we assign them back preserving the `table_mergeOptions` object reference
|
|
125
|
-
features,
|
|
126
|
-
atoms,
|
|
127
|
-
initialState,
|
|
128
|
-
})
|
|
157
|
+
const mergedOptions = table_mergeOptions(table, newOptions)
|
|
129
158
|
|
|
130
159
|
if (table.optionsStore) {
|
|
131
160
|
table.optionsStore.set(() => mergedOptions)
|