@gridkitjs/core 0.0.0-dev-20261112193051 → 0.0.0-dev-20261112193732
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/index.d.ts +12 -4
- package/dist/index.js +24 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -95,9 +95,11 @@ interface GridController<Row, Node = string> {
|
|
|
95
95
|
* A slice that throws stops the restore there, after the slices before it
|
|
96
96
|
* are shown, reported and announced as above.
|
|
97
97
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* ids as the
|
|
98
|
+
* Saved state is read by its `version`. One without a version, saved
|
|
99
|
+
* before the field existed, still restores: a `groupExpansion` saved as a
|
|
100
|
+
* bare list of group ids, as GridKit saved it before the slice carried a
|
|
101
|
+
* mode, restores as `allExpanded` with those ids as the exceptions. A
|
|
102
|
+
* version newer than this release reads throws before any slice is set.
|
|
101
103
|
*/
|
|
102
104
|
readonly restoreState: (saved: Partial<GridState<Row>> | Partial<SerializedGridState<Row>>) => void;
|
|
103
105
|
/**
|
|
@@ -2957,6 +2959,11 @@ interface GridState<Row> {
|
|
|
2957
2959
|
* `JSON.stringify` and back, and to hand straight to `restoreState`.
|
|
2958
2960
|
*/
|
|
2959
2961
|
interface SerializedGridState<Row> extends Omit<GridState<Row>, "filter"> {
|
|
2962
|
+
/**
|
|
2963
|
+
* The shape the state was saved in, so `restoreState` can read a layout
|
|
2964
|
+
* saved by an earlier release. A saved state without one predates it.
|
|
2965
|
+
*/
|
|
2966
|
+
readonly version: 1;
|
|
2960
2967
|
readonly filter: SerializedFilterState<Row>;
|
|
2961
2968
|
}
|
|
2962
2969
|
/**
|
|
@@ -4166,7 +4173,8 @@ declare function resolveGridView<Row, Node = string>(input: GridViewInput<Row, N
|
|
|
4166
4173
|
* it to `restoreState` later. Every slice is plain data already except the
|
|
4167
4174
|
* filter: a `Date` value or operand is written as its ISO string, and a
|
|
4168
4175
|
* predicate entry, being a function, cannot be written at all and is left
|
|
4169
|
-
* out with a `console.error` naming its column.
|
|
4176
|
+
* out with a `console.error` naming its column. The result carries the
|
|
4177
|
+
* `version` of its shape, which `restoreState` reads it by.
|
|
4170
4178
|
*/
|
|
4171
4179
|
declare function serializeGridState<Row>(state: GridState<Row>): SerializedGridState<Row>;
|
|
4172
4180
|
|
package/dist/index.js
CHANGED
|
@@ -922,8 +922,28 @@ function serializeEntry(entry) {
|
|
|
922
922
|
function serializeFilter(filter) {
|
|
923
923
|
return filter.map((entry) => serializeEntry(entry)).filter((entry) => entry !== void 0);
|
|
924
924
|
}
|
|
925
|
+
var SAVED_STATE_VERSION = 1;
|
|
925
926
|
function serializeGridState(state) {
|
|
926
|
-
return {
|
|
927
|
+
return {
|
|
928
|
+
version: SAVED_STATE_VERSION,
|
|
929
|
+
...state,
|
|
930
|
+
filter: serializeFilter(state.filter)
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
function migrateSavedState(saved) {
|
|
934
|
+
const { version, ...state } = saved;
|
|
935
|
+
if (version === void 0) {
|
|
936
|
+
return isStringList(state.groupExpansion) ? {
|
|
937
|
+
...state,
|
|
938
|
+
groupExpansion: { mode: "allExpanded", except: state.groupExpansion }
|
|
939
|
+
} : state;
|
|
940
|
+
}
|
|
941
|
+
if (version === SAVED_STATE_VERSION) {
|
|
942
|
+
return state;
|
|
943
|
+
}
|
|
944
|
+
throw new TypeError(
|
|
945
|
+
`GridKit: a saved state has \`version\` ${JSON.stringify(version)}, and this release reads saved state up to version ${String(SAVED_STATE_VERSION)}.`
|
|
946
|
+
);
|
|
927
947
|
}
|
|
928
948
|
function reviveScalar(scalar, type) {
|
|
929
949
|
return isDateType(type) && typeof scalar === "string" ? toDate(scalar) ?? scalar : scalar;
|
|
@@ -995,14 +1015,11 @@ function isGroupExpansion(value) {
|
|
|
995
1015
|
return typeof value === "object" && value !== null && "mode" in value && (value.mode === "allExpanded" || value.mode === "allCollapsed") && "except" in value && isStringList(value.except);
|
|
996
1016
|
}
|
|
997
1017
|
function reviveGroupExpansion(saved) {
|
|
998
|
-
if (isStringList(saved)) {
|
|
999
|
-
return { mode: "allExpanded", except: saved };
|
|
1000
|
-
}
|
|
1001
1018
|
if (isGroupExpansion(saved)) {
|
|
1002
1019
|
return saved;
|
|
1003
1020
|
}
|
|
1004
1021
|
throw new TypeError(
|
|
1005
|
-
"GridKit: a saved `groupExpansion` is
|
|
1022
|
+
"GridKit: a saved `groupExpansion` is not `{ mode, except }`."
|
|
1006
1023
|
);
|
|
1007
1024
|
}
|
|
1008
1025
|
|
|
@@ -2159,8 +2176,9 @@ function createGridController(initial) {
|
|
|
2159
2176
|
getState: () => state,
|
|
2160
2177
|
getView,
|
|
2161
2178
|
restoreState(saved) {
|
|
2179
|
+
const current = migrateSavedState(saved);
|
|
2162
2180
|
transaction(() => {
|
|
2163
|
-
restoreSlices(
|
|
2181
|
+
restoreSlices(current);
|
|
2164
2182
|
});
|
|
2165
2183
|
},
|
|
2166
2184
|
subscribe(listener) {
|