tinybase 8.0.0-beta.3 → 8.0.0
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/@types/middleware/index.d.ts +44 -124
- package/@types/middleware/with-schemas/index.d.ts +44 -147
- package/@types/ui-react-dom/index.d.ts +6 -4
- package/@types/ui-react-dom/with-schemas/index.d.ts +6 -4
- package/index.js +100 -69
- package/mergeable-store/index.js +99 -48
- package/mergeable-store/with-schemas/index.js +99 -48
- package/middleware/index.js +1 -39
- package/middleware/with-schemas/index.js +1 -39
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/middleware/index.js +1 -1
- package/min/middleware/index.js.gz +0 -0
- package/min/middleware/with-schemas/index.js +1 -1
- package/min/middleware/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +156 -102
- package/omni/with-schemas/index.js +156 -102
- package/package.json +6 -6
- package/readme.md +3 -3
- package/releases.md +39 -4
- package/store/index.js +99 -48
- package/store/with-schemas/index.js +99 -48
- package/ui-react-dom/index.js +56 -34
- package/ui-react-dom/with-schemas/index.js +56 -34
- package/ui-react-inspector/index.js +155 -82
- package/ui-react-inspector/with-schemas/index.js +155 -82
- package/with-schemas/index.js +100 -69
|
@@ -108,6 +108,14 @@ const structuredClone = GLOBAL.structuredClone;
|
|
|
108
108
|
const errorNew = (message) => {
|
|
109
109
|
throw new Error(message);
|
|
110
110
|
};
|
|
111
|
+
const tryReturn = (tryF, catchReturn) => {
|
|
112
|
+
try {
|
|
113
|
+
return tryF();
|
|
114
|
+
} catch {
|
|
115
|
+
/* istanbul ignore next */
|
|
116
|
+
return catchReturn;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
111
119
|
const tryCatch = async (action, then1, then2) => {
|
|
112
120
|
try {
|
|
113
121
|
return await action();
|
|
@@ -155,7 +163,6 @@ const isObject = (obj) =>
|
|
|
155
163
|
const objIds = object.keys;
|
|
156
164
|
const objFreeze = object.freeze;
|
|
157
165
|
const objNew = (entries = []) => object.fromEntries(entries);
|
|
158
|
-
const objMerge = (...objs) => object.assign({}, ...objs);
|
|
159
166
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
160
167
|
const objHas = (obj, id) => id in obj;
|
|
161
168
|
const objDel = (obj, id) => {
|
|
@@ -1019,10 +1026,24 @@ const createStore = () => {
|
|
|
1019
1026
|
);
|
|
1020
1027
|
const setOrDelTables = (tables) =>
|
|
1021
1028
|
objIsEmpty(tables) ? delTables() : setTables(tables);
|
|
1022
|
-
const setOrDelCell = (
|
|
1029
|
+
const setOrDelCell = (
|
|
1030
|
+
tableId,
|
|
1031
|
+
rowId,
|
|
1032
|
+
cellId,
|
|
1033
|
+
cell,
|
|
1034
|
+
skipMiddleware,
|
|
1035
|
+
skipRowMiddleware,
|
|
1036
|
+
) =>
|
|
1023
1037
|
isUndefined(cell)
|
|
1024
1038
|
? delCell(tableId, rowId, cellId, true, skipMiddleware)
|
|
1025
|
-
: setCell(
|
|
1039
|
+
: setCell(
|
|
1040
|
+
tableId,
|
|
1041
|
+
rowId,
|
|
1042
|
+
cellId,
|
|
1043
|
+
cell,
|
|
1044
|
+
skipMiddleware,
|
|
1045
|
+
skipRowMiddleware,
|
|
1046
|
+
);
|
|
1026
1047
|
const setOrDelValues = (values) =>
|
|
1027
1048
|
objIsEmpty(values) ? delValues() : setValues(values);
|
|
1028
1049
|
const setOrDelValue = (valueId, value, skipMiddleware) =>
|
|
@@ -1122,6 +1143,30 @@ const createStore = () => {
|
|
|
1122
1143
|
),
|
|
1123
1144
|
objIsEqual,
|
|
1124
1145
|
);
|
|
1146
|
+
const applyRowDirectly = (tableId, tableMap, rowId, row, skipMiddleware) => {
|
|
1147
|
+
mapMatch(
|
|
1148
|
+
mapEnsure(tableMap, rowId, () => {
|
|
1149
|
+
rowIdsChanged(tableId, rowId, 1);
|
|
1150
|
+
return mapNew();
|
|
1151
|
+
}),
|
|
1152
|
+
row,
|
|
1153
|
+
(rowMap, cellId, cell) =>
|
|
1154
|
+
ifNotUndefined(
|
|
1155
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1156
|
+
(validCell) =>
|
|
1157
|
+
setValidCell(
|
|
1158
|
+
tableId,
|
|
1159
|
+
rowId,
|
|
1160
|
+
rowMap,
|
|
1161
|
+
cellId,
|
|
1162
|
+
validCell,
|
|
1163
|
+
skipMiddleware,
|
|
1164
|
+
),
|
|
1165
|
+
),
|
|
1166
|
+
(rowMap, cellId) =>
|
|
1167
|
+
delValidCell(tableId, tableMap, rowId, rowMap, cellId, true),
|
|
1168
|
+
);
|
|
1169
|
+
};
|
|
1125
1170
|
const setValidCell = (tableId, rowId, rowMap, cellId, cell, skipMiddleware) =>
|
|
1126
1171
|
ifTransformed(
|
|
1127
1172
|
cell,
|
|
@@ -1798,7 +1843,14 @@ const createStore = () => {
|
|
|
1798
1843
|
tableId,
|
|
1799
1844
|
rowId,
|
|
1800
1845
|
);
|
|
1801
|
-
const setCell = (
|
|
1846
|
+
const setCell = (
|
|
1847
|
+
tableId,
|
|
1848
|
+
rowId,
|
|
1849
|
+
cellId,
|
|
1850
|
+
cell,
|
|
1851
|
+
skipMiddleware,
|
|
1852
|
+
skipRowMiddleware,
|
|
1853
|
+
) =>
|
|
1802
1854
|
fluentTransaction(
|
|
1803
1855
|
(tableId2, rowId2, cellId2) =>
|
|
1804
1856
|
ifNotUndefined(
|
|
@@ -1808,15 +1860,47 @@ const createStore = () => {
|
|
|
1808
1860
|
cellId2,
|
|
1809
1861
|
isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
|
|
1810
1862
|
),
|
|
1811
|
-
(validCell) =>
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1863
|
+
(validCell) => {
|
|
1864
|
+
const tableMap = getOrCreateTable(tableId2);
|
|
1865
|
+
ifNotUndefined(
|
|
1866
|
+
skipMiddleware || skipRowMiddleware || !middleware[14]?.()
|
|
1867
|
+
? void 0
|
|
1868
|
+
: middleware[3],
|
|
1869
|
+
(willSetRow) => {
|
|
1870
|
+
const existingRowMap = mapGet(tableMap, rowId2);
|
|
1871
|
+
const prospectiveRow = {
|
|
1872
|
+
...(existingRowMap ? mapToObj(existingRowMap) : {}),
|
|
1873
|
+
[cellId2]: validCell,
|
|
1874
|
+
};
|
|
1875
|
+
ifNotUndefined(
|
|
1876
|
+
whileMutating(() =>
|
|
1877
|
+
willSetRow(
|
|
1878
|
+
tableId2,
|
|
1879
|
+
rowId2,
|
|
1880
|
+
structuredClone(prospectiveRow),
|
|
1881
|
+
),
|
|
1882
|
+
),
|
|
1883
|
+
(row) =>
|
|
1884
|
+
applyRowDirectly(
|
|
1885
|
+
tableId2,
|
|
1886
|
+
tableMap,
|
|
1887
|
+
rowId2,
|
|
1888
|
+
row,
|
|
1889
|
+
skipMiddleware,
|
|
1890
|
+
),
|
|
1891
|
+
);
|
|
1892
|
+
},
|
|
1893
|
+
() =>
|
|
1894
|
+
setCellIntoNewRow(
|
|
1895
|
+
tableId2,
|
|
1896
|
+
tableMap,
|
|
1897
|
+
rowId2,
|
|
1898
|
+
cellId2,
|
|
1899
|
+
validCell,
|
|
1900
|
+
skipMiddleware,
|
|
1901
|
+
),
|
|
1902
|
+
);
|
|
1903
|
+
},
|
|
1820
1904
|
),
|
|
1821
1905
|
tableId,
|
|
1822
1906
|
rowId,
|
|
@@ -1865,7 +1949,14 @@ const createStore = () => {
|
|
|
1865
1949
|
isUndefined(row)
|
|
1866
1950
|
? delRow(tableId, rowId)
|
|
1867
1951
|
: objMap(row, (cell, cellId) =>
|
|
1868
|
-
setOrDelCell(
|
|
1952
|
+
setOrDelCell(
|
|
1953
|
+
tableId,
|
|
1954
|
+
rowId,
|
|
1955
|
+
cellId,
|
|
1956
|
+
cell,
|
|
1957
|
+
void 0,
|
|
1958
|
+
true,
|
|
1959
|
+
),
|
|
1869
1960
|
),
|
|
1870
1961
|
),
|
|
1871
1962
|
);
|
|
@@ -2028,37 +2119,6 @@ const createStore = () => {
|
|
|
2028
2119
|
mapToObj3(changedCellIds),
|
|
2029
2120
|
mapToObj(changedValueIds),
|
|
2030
2121
|
];
|
|
2031
|
-
const doDidSetRows = () => {
|
|
2032
|
-
if (middleware[14]) {
|
|
2033
|
-
const changedCells2 = clonedChangedCells(changedCells);
|
|
2034
|
-
collForEach(changedCells2, (rows, tableId) =>
|
|
2035
|
-
collForEach(rows, (cells, rowId) => {
|
|
2036
|
-
if (
|
|
2037
|
-
!arrayEvery(
|
|
2038
|
-
collValues(cells),
|
|
2039
|
-
([oldCell, newCell]) => oldCell === newCell,
|
|
2040
|
-
)
|
|
2041
|
-
) {
|
|
2042
|
-
const newRow = getRow(tableId, rowId);
|
|
2043
|
-
const oldRow = objMerge(newRow);
|
|
2044
|
-
collForEach(cells, ([oldCell], cellId) =>
|
|
2045
|
-
isUndefined(oldCell)
|
|
2046
|
-
? objDel(oldRow, cellId)
|
|
2047
|
-
: (oldRow[cellId] = oldCell),
|
|
2048
|
-
);
|
|
2049
|
-
const didSetRow = middleware[14](tableId, rowId, oldRow, newRow);
|
|
2050
|
-
if (!objIsEqual(didSetRow, newRow)) {
|
|
2051
|
-
const setOrDelRow = objMap(newRow, () => void 0);
|
|
2052
|
-
objMap(didSetRow, (cell, cellId) => (setOrDelRow[cellId] = cell));
|
|
2053
|
-
objMap(setOrDelRow, (cell, cellId) =>
|
|
2054
|
-
setOrDelCell(tableId, rowId, cellId, cell, true),
|
|
2055
|
-
);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
}),
|
|
2059
|
-
);
|
|
2060
|
-
}
|
|
2061
|
-
};
|
|
2062
2122
|
const finishTransaction = (doRollback) => {
|
|
2063
2123
|
if (transactions > 0) {
|
|
2064
2124
|
transactions--;
|
|
@@ -2068,7 +2128,6 @@ const createStore = () => {
|
|
|
2068
2128
|
callInvalidCellListeners(1);
|
|
2069
2129
|
if (!collIsEmpty(changedCells)) {
|
|
2070
2130
|
callTabularListenersForChanges(1);
|
|
2071
|
-
doDidSetRows();
|
|
2072
2131
|
}
|
|
2073
2132
|
callInvalidValueListeners(1);
|
|
2074
2133
|
if (!collIsEmpty(changedValues)) {
|
|
@@ -2239,7 +2298,7 @@ const createStore = () => {
|
|
|
2239
2298
|
willDelValues,
|
|
2240
2299
|
willDelValue,
|
|
2241
2300
|
willApplyChanges,
|
|
2242
|
-
|
|
2301
|
+
hasWillSetRowCallbacks,
|
|
2243
2302
|
) =>
|
|
2244
2303
|
(middleware = [
|
|
2245
2304
|
willSetContent,
|
|
@@ -2256,7 +2315,7 @@ const createStore = () => {
|
|
|
2256
2315
|
willDelValues,
|
|
2257
2316
|
willDelValue,
|
|
2258
2317
|
willApplyChanges,
|
|
2259
|
-
|
|
2318
|
+
hasWillSetRowCallbacks,
|
|
2260
2319
|
]);
|
|
2261
2320
|
const setInternalListeners = (
|
|
2262
2321
|
preStartTransaction,
|
|
@@ -3078,15 +3137,17 @@ const EditableThing = ({
|
|
|
3078
3137
|
const [stringThing, setStringThing] = useState();
|
|
3079
3138
|
const [numberThing, setNumberThing] = useState();
|
|
3080
3139
|
const [booleanThing, setBooleanThing] = useState();
|
|
3081
|
-
const [
|
|
3082
|
-
const [
|
|
3140
|
+
const [objectThing, setObjectThing] = useState('{}');
|
|
3141
|
+
const [arrayThing, setArrayThing] = useState('[]');
|
|
3142
|
+
const [objectClassName, setObjectClassName] = useState('');
|
|
3143
|
+
const [arrayClassName, setArrayClassName] = useState('');
|
|
3083
3144
|
if (currentThing !== thing) {
|
|
3084
3145
|
setThingType(getCellOrValueType(thing));
|
|
3085
3146
|
setCurrentThing(thing);
|
|
3086
3147
|
if (isObject(thing)) {
|
|
3087
|
-
|
|
3148
|
+
setObjectThing(jsonString(thing));
|
|
3088
3149
|
} else if (isArray(thing)) {
|
|
3089
|
-
|
|
3150
|
+
setArrayThing(jsonString(thing));
|
|
3090
3151
|
} else {
|
|
3091
3152
|
setStringThing(String(thing));
|
|
3092
3153
|
setNumberThing(Number(thing) || 0);
|
|
@@ -3101,6 +3162,22 @@ const EditableThing = ({
|
|
|
3101
3162
|
},
|
|
3102
3163
|
[onThingChange],
|
|
3103
3164
|
);
|
|
3165
|
+
const handleJsonThingChange = useCallback(
|
|
3166
|
+
(value, setTypedThing, isThing, setTypedClassName) => {
|
|
3167
|
+
setTypedThing(value);
|
|
3168
|
+
try {
|
|
3169
|
+
const object = jsonParse(value);
|
|
3170
|
+
if (isThing(object)) {
|
|
3171
|
+
setCurrentThing(object);
|
|
3172
|
+
onThingChange(object);
|
|
3173
|
+
setTypedClassName('');
|
|
3174
|
+
}
|
|
3175
|
+
} catch {
|
|
3176
|
+
setTypedClassName('invalid');
|
|
3177
|
+
}
|
|
3178
|
+
},
|
|
3179
|
+
[onThingChange],
|
|
3180
|
+
);
|
|
3104
3181
|
const handleTypeChange = useCallback(() => {
|
|
3105
3182
|
if (!hasSchema?.()) {
|
|
3106
3183
|
const nextType = getTypeCase(
|
|
@@ -3116,8 +3193,8 @@ const EditableThing = ({
|
|
|
3116
3193
|
stringThing,
|
|
3117
3194
|
numberThing,
|
|
3118
3195
|
booleanThing,
|
|
3119
|
-
|
|
3120
|
-
|
|
3196
|
+
tryReturn(() => jsonParse(objectThing), {}),
|
|
3197
|
+
tryReturn(() => jsonParse(arrayThing), []),
|
|
3121
3198
|
);
|
|
3122
3199
|
setThingType(nextType);
|
|
3123
3200
|
setCurrentThing(thing2);
|
|
@@ -3129,8 +3206,8 @@ const EditableThing = ({
|
|
|
3129
3206
|
stringThing,
|
|
3130
3207
|
numberThing,
|
|
3131
3208
|
booleanThing,
|
|
3132
|
-
|
|
3133
|
-
|
|
3209
|
+
objectThing,
|
|
3210
|
+
arrayThing,
|
|
3134
3211
|
thingType,
|
|
3135
3212
|
]);
|
|
3136
3213
|
const widget = getTypeCase(
|
|
@@ -3183,41 +3260,37 @@ const EditableThing = ({
|
|
|
3183
3260
|
thingType,
|
|
3184
3261
|
),
|
|
3185
3262
|
/* @__PURE__ */ jsx(
|
|
3186
|
-
'
|
|
3263
|
+
'input',
|
|
3187
3264
|
{
|
|
3188
|
-
value:
|
|
3265
|
+
value: objectThing,
|
|
3266
|
+
className: objectClassName,
|
|
3189
3267
|
onChange: useCallback(
|
|
3190
|
-
(event) =>
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
} catch {}
|
|
3199
|
-
},
|
|
3200
|
-
[onThingChange],
|
|
3268
|
+
(event) =>
|
|
3269
|
+
handleJsonThingChange(
|
|
3270
|
+
event[CURRENT_TARGET][_VALUE],
|
|
3271
|
+
setObjectThing,
|
|
3272
|
+
isObject,
|
|
3273
|
+
setObjectClassName,
|
|
3274
|
+
),
|
|
3275
|
+
[handleJsonThingChange],
|
|
3201
3276
|
),
|
|
3202
3277
|
},
|
|
3203
3278
|
thingType,
|
|
3204
3279
|
),
|
|
3205
3280
|
/* @__PURE__ */ jsx(
|
|
3206
|
-
'
|
|
3281
|
+
'input',
|
|
3207
3282
|
{
|
|
3208
|
-
value:
|
|
3283
|
+
value: arrayThing,
|
|
3284
|
+
className: arrayClassName,
|
|
3209
3285
|
onChange: useCallback(
|
|
3210
|
-
(event) =>
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
} catch {}
|
|
3219
|
-
},
|
|
3220
|
-
[onThingChange],
|
|
3286
|
+
(event) =>
|
|
3287
|
+
handleJsonThingChange(
|
|
3288
|
+
event[CURRENT_TARGET][_VALUE],
|
|
3289
|
+
setArrayThing,
|
|
3290
|
+
isArray,
|
|
3291
|
+
setArrayClassName,
|
|
3292
|
+
),
|
|
3293
|
+
[handleJsonThingChange],
|
|
3221
3294
|
),
|
|
3222
3295
|
},
|
|
3223
3296
|
thingType,
|
package/with-schemas/index.js
CHANGED
|
@@ -134,7 +134,6 @@ const isObject = (obj) =>
|
|
|
134
134
|
const objIds = object.keys;
|
|
135
135
|
const objFreeze = object.freeze;
|
|
136
136
|
const objNew = (entries = []) => object.fromEntries(entries);
|
|
137
|
-
const objMerge = (...objs) => object.assign({}, ...objs);
|
|
138
137
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
139
138
|
const objHas = (obj, id) => id in obj;
|
|
140
139
|
const objDel = (obj, id) => {
|
|
@@ -1487,10 +1486,24 @@ const createStore = () => {
|
|
|
1487
1486
|
);
|
|
1488
1487
|
const setOrDelTables = (tables) =>
|
|
1489
1488
|
objIsEmpty(tables) ? delTables() : setTables(tables);
|
|
1490
|
-
const setOrDelCell = (
|
|
1489
|
+
const setOrDelCell = (
|
|
1490
|
+
tableId,
|
|
1491
|
+
rowId,
|
|
1492
|
+
cellId,
|
|
1493
|
+
cell,
|
|
1494
|
+
skipMiddleware,
|
|
1495
|
+
skipRowMiddleware,
|
|
1496
|
+
) =>
|
|
1491
1497
|
isUndefined(cell)
|
|
1492
1498
|
? delCell(tableId, rowId, cellId, true, skipMiddleware)
|
|
1493
|
-
: setCell(
|
|
1499
|
+
: setCell(
|
|
1500
|
+
tableId,
|
|
1501
|
+
rowId,
|
|
1502
|
+
cellId,
|
|
1503
|
+
cell,
|
|
1504
|
+
skipMiddleware,
|
|
1505
|
+
skipRowMiddleware,
|
|
1506
|
+
);
|
|
1494
1507
|
const setOrDelValues = (values) =>
|
|
1495
1508
|
objIsEmpty(values) ? delValues() : setValues(values);
|
|
1496
1509
|
const setOrDelValue = (valueId, value, skipMiddleware) =>
|
|
@@ -1590,6 +1603,30 @@ const createStore = () => {
|
|
|
1590
1603
|
),
|
|
1591
1604
|
objIsEqual,
|
|
1592
1605
|
);
|
|
1606
|
+
const applyRowDirectly = (tableId, tableMap, rowId, row, skipMiddleware) => {
|
|
1607
|
+
mapMatch(
|
|
1608
|
+
mapEnsure(tableMap, rowId, () => {
|
|
1609
|
+
rowIdsChanged(tableId, rowId, 1);
|
|
1610
|
+
return mapNew();
|
|
1611
|
+
}),
|
|
1612
|
+
row,
|
|
1613
|
+
(rowMap, cellId, cell) =>
|
|
1614
|
+
ifNotUndefined(
|
|
1615
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1616
|
+
(validCell) =>
|
|
1617
|
+
setValidCell(
|
|
1618
|
+
tableId,
|
|
1619
|
+
rowId,
|
|
1620
|
+
rowMap,
|
|
1621
|
+
cellId,
|
|
1622
|
+
validCell,
|
|
1623
|
+
skipMiddleware,
|
|
1624
|
+
),
|
|
1625
|
+
),
|
|
1626
|
+
(rowMap, cellId) =>
|
|
1627
|
+
delValidCell(tableId, tableMap, rowId, rowMap, cellId, true),
|
|
1628
|
+
);
|
|
1629
|
+
};
|
|
1593
1630
|
const setValidCell = (tableId, rowId, rowMap, cellId, cell, skipMiddleware) =>
|
|
1594
1631
|
ifTransformed(
|
|
1595
1632
|
cell,
|
|
@@ -2266,7 +2303,14 @@ const createStore = () => {
|
|
|
2266
2303
|
tableId,
|
|
2267
2304
|
rowId,
|
|
2268
2305
|
);
|
|
2269
|
-
const setCell = (
|
|
2306
|
+
const setCell = (
|
|
2307
|
+
tableId,
|
|
2308
|
+
rowId,
|
|
2309
|
+
cellId,
|
|
2310
|
+
cell,
|
|
2311
|
+
skipMiddleware,
|
|
2312
|
+
skipRowMiddleware,
|
|
2313
|
+
) =>
|
|
2270
2314
|
fluentTransaction(
|
|
2271
2315
|
(tableId2, rowId2, cellId2) =>
|
|
2272
2316
|
ifNotUndefined(
|
|
@@ -2276,15 +2320,47 @@ const createStore = () => {
|
|
|
2276
2320
|
cellId2,
|
|
2277
2321
|
isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
|
|
2278
2322
|
),
|
|
2279
|
-
(validCell) =>
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2323
|
+
(validCell) => {
|
|
2324
|
+
const tableMap = getOrCreateTable(tableId2);
|
|
2325
|
+
ifNotUndefined(
|
|
2326
|
+
skipMiddleware || skipRowMiddleware || !middleware[14]?.()
|
|
2327
|
+
? void 0
|
|
2328
|
+
: middleware[3],
|
|
2329
|
+
(willSetRow) => {
|
|
2330
|
+
const existingRowMap = mapGet(tableMap, rowId2);
|
|
2331
|
+
const prospectiveRow = {
|
|
2332
|
+
...(existingRowMap ? mapToObj(existingRowMap) : {}),
|
|
2333
|
+
[cellId2]: validCell,
|
|
2334
|
+
};
|
|
2335
|
+
ifNotUndefined(
|
|
2336
|
+
whileMutating(() =>
|
|
2337
|
+
willSetRow(
|
|
2338
|
+
tableId2,
|
|
2339
|
+
rowId2,
|
|
2340
|
+
structuredClone(prospectiveRow),
|
|
2341
|
+
),
|
|
2342
|
+
),
|
|
2343
|
+
(row) =>
|
|
2344
|
+
applyRowDirectly(
|
|
2345
|
+
tableId2,
|
|
2346
|
+
tableMap,
|
|
2347
|
+
rowId2,
|
|
2348
|
+
row,
|
|
2349
|
+
skipMiddleware,
|
|
2350
|
+
),
|
|
2351
|
+
);
|
|
2352
|
+
},
|
|
2353
|
+
() =>
|
|
2354
|
+
setCellIntoNewRow(
|
|
2355
|
+
tableId2,
|
|
2356
|
+
tableMap,
|
|
2357
|
+
rowId2,
|
|
2358
|
+
cellId2,
|
|
2359
|
+
validCell,
|
|
2360
|
+
skipMiddleware,
|
|
2361
|
+
),
|
|
2362
|
+
);
|
|
2363
|
+
},
|
|
2288
2364
|
),
|
|
2289
2365
|
tableId,
|
|
2290
2366
|
rowId,
|
|
@@ -2333,7 +2409,14 @@ const createStore = () => {
|
|
|
2333
2409
|
isUndefined(row)
|
|
2334
2410
|
? delRow(tableId, rowId)
|
|
2335
2411
|
: objMap(row, (cell, cellId) =>
|
|
2336
|
-
setOrDelCell(
|
|
2412
|
+
setOrDelCell(
|
|
2413
|
+
tableId,
|
|
2414
|
+
rowId,
|
|
2415
|
+
cellId,
|
|
2416
|
+
cell,
|
|
2417
|
+
void 0,
|
|
2418
|
+
true,
|
|
2419
|
+
),
|
|
2337
2420
|
),
|
|
2338
2421
|
),
|
|
2339
2422
|
);
|
|
@@ -2496,37 +2579,6 @@ const createStore = () => {
|
|
|
2496
2579
|
mapToObj3(changedCellIds),
|
|
2497
2580
|
mapToObj(changedValueIds),
|
|
2498
2581
|
];
|
|
2499
|
-
const doDidSetRows = () => {
|
|
2500
|
-
if (middleware[14]) {
|
|
2501
|
-
const changedCells2 = clonedChangedCells(changedCells);
|
|
2502
|
-
collForEach(changedCells2, (rows, tableId) =>
|
|
2503
|
-
collForEach(rows, (cells, rowId) => {
|
|
2504
|
-
if (
|
|
2505
|
-
!arrayEvery(
|
|
2506
|
-
collValues(cells),
|
|
2507
|
-
([oldCell, newCell]) => oldCell === newCell,
|
|
2508
|
-
)
|
|
2509
|
-
) {
|
|
2510
|
-
const newRow = getRow(tableId, rowId);
|
|
2511
|
-
const oldRow = objMerge(newRow);
|
|
2512
|
-
collForEach(cells, ([oldCell], cellId) =>
|
|
2513
|
-
isUndefined(oldCell)
|
|
2514
|
-
? objDel(oldRow, cellId)
|
|
2515
|
-
: (oldRow[cellId] = oldCell),
|
|
2516
|
-
);
|
|
2517
|
-
const didSetRow = middleware[14](tableId, rowId, oldRow, newRow);
|
|
2518
|
-
if (!objIsEqual(didSetRow, newRow)) {
|
|
2519
|
-
const setOrDelRow = objMap(newRow, () => void 0);
|
|
2520
|
-
objMap(didSetRow, (cell, cellId) => (setOrDelRow[cellId] = cell));
|
|
2521
|
-
objMap(setOrDelRow, (cell, cellId) =>
|
|
2522
|
-
setOrDelCell(tableId, rowId, cellId, cell, true),
|
|
2523
|
-
);
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
}),
|
|
2527
|
-
);
|
|
2528
|
-
}
|
|
2529
|
-
};
|
|
2530
2582
|
const finishTransaction = (doRollback) => {
|
|
2531
2583
|
if (transactions > 0) {
|
|
2532
2584
|
transactions--;
|
|
@@ -2536,7 +2588,6 @@ const createStore = () => {
|
|
|
2536
2588
|
callInvalidCellListeners(1);
|
|
2537
2589
|
if (!collIsEmpty(changedCells)) {
|
|
2538
2590
|
callTabularListenersForChanges(1);
|
|
2539
|
-
doDidSetRows();
|
|
2540
2591
|
}
|
|
2541
2592
|
callInvalidValueListeners(1);
|
|
2542
2593
|
if (!collIsEmpty(changedValues)) {
|
|
@@ -2707,7 +2758,7 @@ const createStore = () => {
|
|
|
2707
2758
|
willDelValues,
|
|
2708
2759
|
willDelValue,
|
|
2709
2760
|
willApplyChanges,
|
|
2710
|
-
|
|
2761
|
+
hasWillSetRowCallbacks,
|
|
2711
2762
|
) =>
|
|
2712
2763
|
(middleware = [
|
|
2713
2764
|
willSetContent,
|
|
@@ -2724,7 +2775,7 @@ const createStore = () => {
|
|
|
2724
2775
|
willDelValues,
|
|
2725
2776
|
willDelValue,
|
|
2726
2777
|
willApplyChanges,
|
|
2727
|
-
|
|
2778
|
+
hasWillSetRowCallbacks,
|
|
2728
2779
|
]);
|
|
2729
2780
|
const setInternalListeners = (
|
|
2730
2781
|
preStartTransaction,
|
|
@@ -3630,7 +3681,6 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3630
3681
|
const willDelValuesCallbacks = [];
|
|
3631
3682
|
const willDelValueCallbacks = [];
|
|
3632
3683
|
const willApplyChangesCallbacks = [];
|
|
3633
|
-
const didSetRowCallbacksMap = mapNew();
|
|
3634
3684
|
const willSetContent = (content) =>
|
|
3635
3685
|
reduceCallbacks(willSetContentCallbacks, content);
|
|
3636
3686
|
const willSetTables = (tables) =>
|
|
@@ -3657,17 +3707,6 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3657
3707
|
everyCallback(willDelValueCallbacks, valueId);
|
|
3658
3708
|
const willApplyChanges = (changes) =>
|
|
3659
3709
|
reduceCallbacks(willApplyChangesCallbacks, changes);
|
|
3660
|
-
const didSetRow = (tableId, rowId, oldRow, newRow) =>
|
|
3661
|
-
ifNotUndefined(
|
|
3662
|
-
mapGet(didSetRowCallbacksMap, tableId),
|
|
3663
|
-
(callbacks) =>
|
|
3664
|
-
arrayReduce(
|
|
3665
|
-
callbacks,
|
|
3666
|
-
(current, callback) => callback(tableId, rowId, oldRow, current),
|
|
3667
|
-
newRow,
|
|
3668
|
-
),
|
|
3669
|
-
() => newRow,
|
|
3670
|
-
);
|
|
3671
3710
|
const getStore = () => store;
|
|
3672
3711
|
const addWillSetContentCallback = addCallback(willSetContentCallbacks);
|
|
3673
3712
|
const addWillSetTablesCallback = addCallback(willSetTablesCallbacks);
|
|
@@ -3683,13 +3722,6 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3683
3722
|
const addWillDelValuesCallback = addCallback(willDelValuesCallbacks);
|
|
3684
3723
|
const addWillDelValueCallback = addCallback(willDelValueCallbacks);
|
|
3685
3724
|
const addWillApplyChangesCallback = addCallback(willApplyChangesCallbacks);
|
|
3686
|
-
const addDidSetRowCallback = (tableId, callback) =>
|
|
3687
|
-
fluent(() =>
|
|
3688
|
-
arrayPush(
|
|
3689
|
-
mapEnsure(didSetRowCallbacksMap, tableId, () => []),
|
|
3690
|
-
callback,
|
|
3691
|
-
),
|
|
3692
|
-
);
|
|
3693
3725
|
const destroy = () => {};
|
|
3694
3726
|
const middleware = objFreeze({
|
|
3695
3727
|
getStore,
|
|
@@ -3707,7 +3739,6 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3707
3739
|
addWillDelValuesCallback,
|
|
3708
3740
|
addWillDelValueCallback,
|
|
3709
3741
|
addWillApplyChangesCallback,
|
|
3710
|
-
addDidSetRowCallback,
|
|
3711
3742
|
destroy,
|
|
3712
3743
|
});
|
|
3713
3744
|
store._[4](
|
|
@@ -3725,7 +3756,7 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3725
3756
|
willDelValues,
|
|
3726
3757
|
willDelValue,
|
|
3727
3758
|
willApplyChanges,
|
|
3728
|
-
|
|
3759
|
+
() => willSetRowCallbacks.length > 0,
|
|
3729
3760
|
);
|
|
3730
3761
|
return middleware;
|
|
3731
3762
|
});
|