@tanstack/table-core 9.0.0-alpha.11 → 9.0.0-alpha.12
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/esm/core/table/constructTable.js +12 -15
- package/dist/esm/core/table/constructTable.js.map +1 -1
- package/dist/esm/core/table/coreTablesFeature.types.d.ts +2 -2
- package/dist/esm/core/table/coreTablesFeature.utils.js +1 -1
- package/dist/esm/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/esm/types/Table.d.ts +2 -2
- package/package.json +2 -2
- package/src/core/table/constructTable.ts +14 -20
- package/src/core/table/coreTablesFeature.types.ts +2 -2
- package/src/core/table/coreTablesFeature.utils.ts +1 -1
- package/src/types/Table.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStore } from "@tanstack/store";
|
|
2
2
|
import { coreFeatures } from "../coreFeatures.js";
|
|
3
3
|
function getInitialTableState(features, initialState = {}) {
|
|
4
4
|
Object.values(features).forEach((feature) => {
|
|
@@ -7,7 +7,7 @@ function getInitialTableState(features, initialState = {}) {
|
|
|
7
7
|
return structuredClone(initialState);
|
|
8
8
|
}
|
|
9
9
|
function createTableStore(features, initialState = {}) {
|
|
10
|
-
return
|
|
10
|
+
return createStore(getInitialTableState(features, initialState));
|
|
11
11
|
}
|
|
12
12
|
function constructTable(tableOptions) {
|
|
13
13
|
const table = {
|
|
@@ -27,16 +27,13 @@ function constructTable(tableOptions) {
|
|
|
27
27
|
table._features,
|
|
28
28
|
table.options.initialState
|
|
29
29
|
);
|
|
30
|
-
table.baseStore = table.options.store ??
|
|
31
|
-
table.store =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...table.options.state ?? {}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
30
|
+
table.baseStore = table.options.store ?? createStore(table.initialState);
|
|
31
|
+
table.store = createStore(() => {
|
|
32
|
+
const state = table.baseStore.state;
|
|
33
|
+
return {
|
|
34
|
+
...state,
|
|
35
|
+
...table.options.state ?? {}
|
|
36
|
+
};
|
|
40
37
|
});
|
|
41
38
|
if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
|
|
42
39
|
const features = Object.keys(table._features);
|
|
@@ -44,11 +41,11 @@ function constructTable(tableOptions) {
|
|
|
44
41
|
const states = Object.keys(table.initialState);
|
|
45
42
|
console.log(
|
|
46
43
|
`Constructing Table Instance
|
|
47
|
-
|
|
44
|
+
|
|
48
45
|
Features: ${features.join("\n ")}
|
|
49
|
-
|
|
46
|
+
|
|
50
47
|
Row Models: ${rowModels.length ? rowModels.join("\n ") : "(none)"}
|
|
51
|
-
|
|
48
|
+
|
|
52
49
|
States: ${states.join("\n ")}`
|
|
53
50
|
);
|
|
54
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructTable.js","sources":["../../../../src/core/table/constructTable.ts"],"sourcesContent":["import {
|
|
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,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,IAC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owModelFns } from '../../types/RowModelFns.js';
|
|
4
4
|
import { RowData, Updater } from '../../types/type-utils.js';
|
|
@@ -91,7 +91,7 @@ export interface Table_CoreProperties<TFeatures extends TableFeatures, TData ext
|
|
|
91
91
|
/**
|
|
92
92
|
* Where the table state is stored.
|
|
93
93
|
*/
|
|
94
|
-
store:
|
|
94
|
+
store: ReadonlyStore<TableState<TFeatures>>;
|
|
95
95
|
}
|
|
96
96
|
export interface Table_Table<TFeatures extends TableFeatures, TData extends RowData> extends Table_CoreProperties<TFeatures, TData> {
|
|
97
97
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { functionalUpdate } from "../../utils.js";
|
|
2
2
|
function table_reset(table) {
|
|
3
|
-
table.baseStore.setState(structuredClone(table.initialState));
|
|
3
|
+
table.baseStore.setState(() => structuredClone(table.initialState));
|
|
4
4
|
}
|
|
5
5
|
function table_mergeOptions(table, newOptions) {
|
|
6
6
|
if (table.options.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,gBAAgB,MAAM,YAAY,CAAC;
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReadonlyStore, Store } from '@tanstack/store';
|
|
2
2
|
import { Table_ColumnFaceting } from '../features/column-faceting/columnFacetingFeature.types';
|
|
3
3
|
import { Table_ColumnResizing } from '../features/column-resizing/columnResizingFeature.types';
|
|
4
4
|
import { Table_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types';
|
|
@@ -49,5 +49,5 @@ export type Table_Internal<TFeatures extends TableFeatures, TData extends RowDat
|
|
|
49
49
|
};
|
|
50
50
|
initialState: TableState_All;
|
|
51
51
|
baseStore: Store<TableState_All>;
|
|
52
|
-
store:
|
|
52
|
+
store: ReadonlyStore<TableState_All>;
|
|
53
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.12",
|
|
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.
|
|
48
|
+
"@tanstack/store": "^0.9.1"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"clean": "rimraf ./build && rimraf ./dist",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {} from '../../utils'
|
|
1
|
+
import { createStore } from '@tanstack/store'
|
|
3
2
|
import { coreFeatures } from '../coreFeatures'
|
|
3
|
+
import type { Store } from '@tanstack/store'
|
|
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'
|
|
@@ -23,7 +23,7 @@ export function createTableStore<TFeatures extends TableFeatures>(
|
|
|
23
23
|
features: TFeatures,
|
|
24
24
|
initialState: Partial<TableState<TFeatures>> | undefined = {},
|
|
25
25
|
): Store<TableState<TFeatures>> {
|
|
26
|
-
return
|
|
26
|
+
return createStore(getInitialTableState(features, initialState))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function constructTable<
|
|
@@ -52,20 +52,14 @@ export function constructTable<
|
|
|
52
52
|
table.options.initialState,
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
table.baseStore =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Merge base state with user-provided external state (table.options.state takes precedence)
|
|
64
|
-
return {
|
|
65
|
-
...baseState,
|
|
66
|
-
...(table.options.state ?? {}),
|
|
67
|
-
} as TableState<TFeatures>
|
|
68
|
-
},
|
|
55
|
+
table.baseStore = table.options.store ?? createStore(table.initialState)
|
|
56
|
+
|
|
57
|
+
table.store = createStore(() => {
|
|
58
|
+
const state = table.baseStore.state
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
...(table.options.state ?? {}),
|
|
62
|
+
}
|
|
69
63
|
})
|
|
70
64
|
|
|
71
65
|
if (
|
|
@@ -78,11 +72,11 @@ export function constructTable<
|
|
|
78
72
|
|
|
79
73
|
console.log(
|
|
80
74
|
`Constructing Table Instance
|
|
81
|
-
|
|
75
|
+
|
|
82
76
|
Features: ${features.join('\n ')}
|
|
83
|
-
|
|
77
|
+
|
|
84
78
|
Row Models: ${rowModels.length ? rowModels.join('\n ') : '(none)'}
|
|
85
|
-
|
|
79
|
+
|
|
86
80
|
States: ${states.join('\n ')}`,
|
|
87
81
|
)
|
|
88
82
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadonlyStore, Store } from '@tanstack/store'
|
|
2
2
|
import type { CoreFeatures } from '../coreFeatures'
|
|
3
3
|
import type { RowModelFns } from '../../types/RowModelFns'
|
|
4
4
|
import type { RowData, Updater } from '../../types/type-utils'
|
|
@@ -105,7 +105,7 @@ export interface Table_CoreProperties<
|
|
|
105
105
|
/**
|
|
106
106
|
* Where the table state is stored.
|
|
107
107
|
*/
|
|
108
|
-
store:
|
|
108
|
+
store: ReadonlyStore<TableState<TFeatures>>
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export interface Table_Table<
|
|
@@ -8,7 +8,7 @@ export function table_reset<
|
|
|
8
8
|
TFeatures extends TableFeatures,
|
|
9
9
|
TData extends RowData,
|
|
10
10
|
>(table: Table_Internal<TFeatures, TData>): void {
|
|
11
|
-
table.baseStore.setState(structuredClone(table.initialState))
|
|
11
|
+
table.baseStore.setState(() => structuredClone(table.initialState))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function table_mergeOptions<
|
package/src/types/Table.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadonlyStore, Store } 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'
|
|
@@ -121,5 +121,5 @@ export type Table_Internal<
|
|
|
121
121
|
}
|
|
122
122
|
initialState: TableState_All
|
|
123
123
|
baseStore: Store<TableState_All>
|
|
124
|
-
store:
|
|
124
|
+
store: ReadonlyStore<TableState_All>
|
|
125
125
|
}
|