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.
Files changed (49) hide show
  1. package/@types/middleware/index.d.ts +44 -124
  2. package/@types/middleware/with-schemas/index.d.ts +44 -147
  3. package/@types/ui-react-dom/index.d.ts +6 -4
  4. package/@types/ui-react-dom/with-schemas/index.d.ts +6 -4
  5. package/index.js +100 -69
  6. package/mergeable-store/index.js +99 -48
  7. package/mergeable-store/with-schemas/index.js +99 -48
  8. package/middleware/index.js +1 -39
  9. package/middleware/with-schemas/index.js +1 -39
  10. package/min/index.js +1 -1
  11. package/min/index.js.gz +0 -0
  12. package/min/mergeable-store/index.js +1 -1
  13. package/min/mergeable-store/index.js.gz +0 -0
  14. package/min/mergeable-store/with-schemas/index.js +1 -1
  15. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  16. package/min/middleware/index.js +1 -1
  17. package/min/middleware/index.js.gz +0 -0
  18. package/min/middleware/with-schemas/index.js +1 -1
  19. package/min/middleware/with-schemas/index.js.gz +0 -0
  20. package/min/omni/index.js +1 -1
  21. package/min/omni/index.js.gz +0 -0
  22. package/min/omni/with-schemas/index.js +1 -1
  23. package/min/omni/with-schemas/index.js.gz +0 -0
  24. package/min/store/index.js +1 -1
  25. package/min/store/index.js.gz +0 -0
  26. package/min/store/with-schemas/index.js +1 -1
  27. package/min/store/with-schemas/index.js.gz +0 -0
  28. package/min/ui-react-dom/index.js +1 -1
  29. package/min/ui-react-dom/index.js.gz +0 -0
  30. package/min/ui-react-dom/with-schemas/index.js +1 -1
  31. package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
  32. package/min/ui-react-inspector/index.js +1 -1
  33. package/min/ui-react-inspector/index.js.gz +0 -0
  34. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  35. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  36. package/min/with-schemas/index.js +1 -1
  37. package/min/with-schemas/index.js.gz +0 -0
  38. package/omni/index.js +156 -102
  39. package/omni/with-schemas/index.js +156 -102
  40. package/package.json +6 -6
  41. package/readme.md +3 -3
  42. package/releases.md +39 -4
  43. package/store/index.js +99 -48
  44. package/store/with-schemas/index.js +99 -48
  45. package/ui-react-dom/index.js +56 -34
  46. package/ui-react-dom/with-schemas/index.js +56 -34
  47. package/ui-react-inspector/index.js +155 -82
  48. package/ui-react-inspector/with-schemas/index.js +155 -82
  49. package/with-schemas/index.js +100 -69
package/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 = (tableId, rowId, cellId, cell, skipMiddleware) =>
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(tableId, rowId, cellId, cell, skipMiddleware);
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 = (tableId, rowId, cellId, cell, skipMiddleware) =>
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
- setCellIntoNewRow(
2281
- tableId2,
2282
- getOrCreateTable(tableId2),
2283
- rowId2,
2284
- cellId2,
2285
- validCell,
2286
- skipMiddleware,
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(tableId, rowId, cellId, cell),
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
- didSetRow,
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
- didSetRow,
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
- didSetRow,
3759
+ () => willSetRowCallbacks.length > 0,
3729
3760
  );
3730
3761
  return middleware;
3731
3762
  });
@@ -96,7 +96,6 @@ const isObject = (obj) =>
96
96
  const objIds = object.keys;
97
97
  const objFreeze = object.freeze;
98
98
  const objNew = (entries = []) => object.fromEntries(entries);
99
- const objMerge = (...objs) => object.assign({}, ...objs);
100
99
  const objHas = (obj, id) => id in obj;
101
100
  const objDel = (obj, id) => {
102
101
  delete obj[id];
@@ -799,10 +798,24 @@ const createStore = () => {
799
798
  );
800
799
  const setOrDelTables = (tables) =>
801
800
  objIsEmpty(tables) ? delTables() : setTables(tables);
802
- const setOrDelCell = (tableId, rowId, cellId, cell, skipMiddleware) =>
801
+ const setOrDelCell = (
802
+ tableId,
803
+ rowId,
804
+ cellId,
805
+ cell,
806
+ skipMiddleware,
807
+ skipRowMiddleware,
808
+ ) =>
803
809
  isUndefined(cell)
804
810
  ? delCell(tableId, rowId, cellId, true, skipMiddleware)
805
- : setCell(tableId, rowId, cellId, cell, skipMiddleware);
811
+ : setCell(
812
+ tableId,
813
+ rowId,
814
+ cellId,
815
+ cell,
816
+ skipMiddleware,
817
+ skipRowMiddleware,
818
+ );
806
819
  const setOrDelValues = (values) =>
807
820
  objIsEmpty(values) ? delValues() : setValues(values);
808
821
  const setOrDelValue = (valueId, value, skipMiddleware) =>
@@ -902,6 +915,30 @@ const createStore = () => {
902
915
  ),
903
916
  objIsEqual,
904
917
  );
918
+ const applyRowDirectly = (tableId, tableMap, rowId, row, skipMiddleware) => {
919
+ mapMatch(
920
+ mapEnsure(tableMap, rowId, () => {
921
+ rowIdsChanged(tableId, rowId, 1);
922
+ return mapNew();
923
+ }),
924
+ row,
925
+ (rowMap, cellId, cell) =>
926
+ ifNotUndefined(
927
+ getValidatedCell(tableId, rowId, cellId, cell),
928
+ (validCell) =>
929
+ setValidCell(
930
+ tableId,
931
+ rowId,
932
+ rowMap,
933
+ cellId,
934
+ validCell,
935
+ skipMiddleware,
936
+ ),
937
+ ),
938
+ (rowMap, cellId) =>
939
+ delValidCell(tableId, tableMap, rowId, rowMap, cellId, true),
940
+ );
941
+ };
905
942
  const setValidCell = (tableId, rowId, rowMap, cellId, cell, skipMiddleware) =>
906
943
  ifTransformed(
907
944
  cell,
@@ -1578,7 +1615,14 @@ const createStore = () => {
1578
1615
  tableId,
1579
1616
  rowId,
1580
1617
  );
1581
- const setCell = (tableId, rowId, cellId, cell, skipMiddleware) =>
1618
+ const setCell = (
1619
+ tableId,
1620
+ rowId,
1621
+ cellId,
1622
+ cell,
1623
+ skipMiddleware,
1624
+ skipRowMiddleware,
1625
+ ) =>
1582
1626
  fluentTransaction(
1583
1627
  (tableId2, rowId2, cellId2) =>
1584
1628
  ifNotUndefined(
@@ -1588,15 +1632,47 @@ const createStore = () => {
1588
1632
  cellId2,
1589
1633
  isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
1590
1634
  ),
1591
- (validCell) =>
1592
- setCellIntoNewRow(
1593
- tableId2,
1594
- getOrCreateTable(tableId2),
1595
- rowId2,
1596
- cellId2,
1597
- validCell,
1598
- skipMiddleware,
1599
- ),
1635
+ (validCell) => {
1636
+ const tableMap = getOrCreateTable(tableId2);
1637
+ ifNotUndefined(
1638
+ skipMiddleware || skipRowMiddleware || !middleware[14]?.()
1639
+ ? void 0
1640
+ : middleware[3],
1641
+ (willSetRow) => {
1642
+ const existingRowMap = mapGet(tableMap, rowId2);
1643
+ const prospectiveRow = {
1644
+ ...(existingRowMap ? mapToObj(existingRowMap) : {}),
1645
+ [cellId2]: validCell,
1646
+ };
1647
+ ifNotUndefined(
1648
+ whileMutating(() =>
1649
+ willSetRow(
1650
+ tableId2,
1651
+ rowId2,
1652
+ structuredClone(prospectiveRow),
1653
+ ),
1654
+ ),
1655
+ (row) =>
1656
+ applyRowDirectly(
1657
+ tableId2,
1658
+ tableMap,
1659
+ rowId2,
1660
+ row,
1661
+ skipMiddleware,
1662
+ ),
1663
+ );
1664
+ },
1665
+ () =>
1666
+ setCellIntoNewRow(
1667
+ tableId2,
1668
+ tableMap,
1669
+ rowId2,
1670
+ cellId2,
1671
+ validCell,
1672
+ skipMiddleware,
1673
+ ),
1674
+ );
1675
+ },
1600
1676
  ),
1601
1677
  tableId,
1602
1678
  rowId,
@@ -1645,7 +1721,14 @@ const createStore = () => {
1645
1721
  isUndefined(row)
1646
1722
  ? delRow(tableId, rowId)
1647
1723
  : objMap(row, (cell, cellId) =>
1648
- setOrDelCell(tableId, rowId, cellId, cell),
1724
+ setOrDelCell(
1725
+ tableId,
1726
+ rowId,
1727
+ cellId,
1728
+ cell,
1729
+ void 0,
1730
+ true,
1731
+ ),
1649
1732
  ),
1650
1733
  ),
1651
1734
  );
@@ -1808,37 +1891,6 @@ const createStore = () => {
1808
1891
  mapToObj3(changedCellIds),
1809
1892
  mapToObj(changedValueIds),
1810
1893
  ];
1811
- const doDidSetRows = () => {
1812
- if (middleware[14]) {
1813
- const changedCells2 = clonedChangedCells(changedCells);
1814
- collForEach(changedCells2, (rows, tableId) =>
1815
- collForEach(rows, (cells, rowId) => {
1816
- if (
1817
- !arrayEvery(
1818
- collValues(cells),
1819
- ([oldCell, newCell]) => oldCell === newCell,
1820
- )
1821
- ) {
1822
- const newRow = getRow(tableId, rowId);
1823
- const oldRow = objMerge(newRow);
1824
- collForEach(cells, ([oldCell], cellId) =>
1825
- isUndefined(oldCell)
1826
- ? objDel(oldRow, cellId)
1827
- : (oldRow[cellId] = oldCell),
1828
- );
1829
- const didSetRow = middleware[14](tableId, rowId, oldRow, newRow);
1830
- if (!objIsEqual(didSetRow, newRow)) {
1831
- const setOrDelRow = objMap(newRow, () => void 0);
1832
- objMap(didSetRow, (cell, cellId) => (setOrDelRow[cellId] = cell));
1833
- objMap(setOrDelRow, (cell, cellId) =>
1834
- setOrDelCell(tableId, rowId, cellId, cell, true),
1835
- );
1836
- }
1837
- }
1838
- }),
1839
- );
1840
- }
1841
- };
1842
1894
  const finishTransaction = (doRollback) => {
1843
1895
  if (transactions > 0) {
1844
1896
  transactions--;
@@ -1848,7 +1900,6 @@ const createStore = () => {
1848
1900
  callInvalidCellListeners(1);
1849
1901
  if (!collIsEmpty(changedCells)) {
1850
1902
  callTabularListenersForChanges(1);
1851
- doDidSetRows();
1852
1903
  }
1853
1904
  callInvalidValueListeners(1);
1854
1905
  if (!collIsEmpty(changedValues)) {
@@ -2019,7 +2070,7 @@ const createStore = () => {
2019
2070
  willDelValues,
2020
2071
  willDelValue,
2021
2072
  willApplyChanges,
2022
- didSetRow,
2073
+ hasWillSetRowCallbacks,
2023
2074
  ) =>
2024
2075
  (middleware = [
2025
2076
  willSetContent,
@@ -2036,7 +2087,7 @@ const createStore = () => {
2036
2087
  willDelValues,
2037
2088
  willDelValue,
2038
2089
  willApplyChanges,
2039
- didSetRow,
2090
+ hasWillSetRowCallbacks,
2040
2091
  ]);
2041
2092
  const setInternalListeners = (
2042
2093
  preStartTransaction,
@@ -96,7 +96,6 @@ const isObject = (obj) =>
96
96
  const objIds = object.keys;
97
97
  const objFreeze = object.freeze;
98
98
  const objNew = (entries = []) => object.fromEntries(entries);
99
- const objMerge = (...objs) => object.assign({}, ...objs);
100
99
  const objHas = (obj, id) => id in obj;
101
100
  const objDel = (obj, id) => {
102
101
  delete obj[id];
@@ -799,10 +798,24 @@ const createStore = () => {
799
798
  );
800
799
  const setOrDelTables = (tables) =>
801
800
  objIsEmpty(tables) ? delTables() : setTables(tables);
802
- const setOrDelCell = (tableId, rowId, cellId, cell, skipMiddleware) =>
801
+ const setOrDelCell = (
802
+ tableId,
803
+ rowId,
804
+ cellId,
805
+ cell,
806
+ skipMiddleware,
807
+ skipRowMiddleware,
808
+ ) =>
803
809
  isUndefined(cell)
804
810
  ? delCell(tableId, rowId, cellId, true, skipMiddleware)
805
- : setCell(tableId, rowId, cellId, cell, skipMiddleware);
811
+ : setCell(
812
+ tableId,
813
+ rowId,
814
+ cellId,
815
+ cell,
816
+ skipMiddleware,
817
+ skipRowMiddleware,
818
+ );
806
819
  const setOrDelValues = (values) =>
807
820
  objIsEmpty(values) ? delValues() : setValues(values);
808
821
  const setOrDelValue = (valueId, value, skipMiddleware) =>
@@ -902,6 +915,30 @@ const createStore = () => {
902
915
  ),
903
916
  objIsEqual,
904
917
  );
918
+ const applyRowDirectly = (tableId, tableMap, rowId, row, skipMiddleware) => {
919
+ mapMatch(
920
+ mapEnsure(tableMap, rowId, () => {
921
+ rowIdsChanged(tableId, rowId, 1);
922
+ return mapNew();
923
+ }),
924
+ row,
925
+ (rowMap, cellId, cell) =>
926
+ ifNotUndefined(
927
+ getValidatedCell(tableId, rowId, cellId, cell),
928
+ (validCell) =>
929
+ setValidCell(
930
+ tableId,
931
+ rowId,
932
+ rowMap,
933
+ cellId,
934
+ validCell,
935
+ skipMiddleware,
936
+ ),
937
+ ),
938
+ (rowMap, cellId) =>
939
+ delValidCell(tableId, tableMap, rowId, rowMap, cellId, true),
940
+ );
941
+ };
905
942
  const setValidCell = (tableId, rowId, rowMap, cellId, cell, skipMiddleware) =>
906
943
  ifTransformed(
907
944
  cell,
@@ -1578,7 +1615,14 @@ const createStore = () => {
1578
1615
  tableId,
1579
1616
  rowId,
1580
1617
  );
1581
- const setCell = (tableId, rowId, cellId, cell, skipMiddleware) =>
1618
+ const setCell = (
1619
+ tableId,
1620
+ rowId,
1621
+ cellId,
1622
+ cell,
1623
+ skipMiddleware,
1624
+ skipRowMiddleware,
1625
+ ) =>
1582
1626
  fluentTransaction(
1583
1627
  (tableId2, rowId2, cellId2) =>
1584
1628
  ifNotUndefined(
@@ -1588,15 +1632,47 @@ const createStore = () => {
1588
1632
  cellId2,
1589
1633
  isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
1590
1634
  ),
1591
- (validCell) =>
1592
- setCellIntoNewRow(
1593
- tableId2,
1594
- getOrCreateTable(tableId2),
1595
- rowId2,
1596
- cellId2,
1597
- validCell,
1598
- skipMiddleware,
1599
- ),
1635
+ (validCell) => {
1636
+ const tableMap = getOrCreateTable(tableId2);
1637
+ ifNotUndefined(
1638
+ skipMiddleware || skipRowMiddleware || !middleware[14]?.()
1639
+ ? void 0
1640
+ : middleware[3],
1641
+ (willSetRow) => {
1642
+ const existingRowMap = mapGet(tableMap, rowId2);
1643
+ const prospectiveRow = {
1644
+ ...(existingRowMap ? mapToObj(existingRowMap) : {}),
1645
+ [cellId2]: validCell,
1646
+ };
1647
+ ifNotUndefined(
1648
+ whileMutating(() =>
1649
+ willSetRow(
1650
+ tableId2,
1651
+ rowId2,
1652
+ structuredClone(prospectiveRow),
1653
+ ),
1654
+ ),
1655
+ (row) =>
1656
+ applyRowDirectly(
1657
+ tableId2,
1658
+ tableMap,
1659
+ rowId2,
1660
+ row,
1661
+ skipMiddleware,
1662
+ ),
1663
+ );
1664
+ },
1665
+ () =>
1666
+ setCellIntoNewRow(
1667
+ tableId2,
1668
+ tableMap,
1669
+ rowId2,
1670
+ cellId2,
1671
+ validCell,
1672
+ skipMiddleware,
1673
+ ),
1674
+ );
1675
+ },
1600
1676
  ),
1601
1677
  tableId,
1602
1678
  rowId,
@@ -1645,7 +1721,14 @@ const createStore = () => {
1645
1721
  isUndefined(row)
1646
1722
  ? delRow(tableId, rowId)
1647
1723
  : objMap(row, (cell, cellId) =>
1648
- setOrDelCell(tableId, rowId, cellId, cell),
1724
+ setOrDelCell(
1725
+ tableId,
1726
+ rowId,
1727
+ cellId,
1728
+ cell,
1729
+ void 0,
1730
+ true,
1731
+ ),
1649
1732
  ),
1650
1733
  ),
1651
1734
  );
@@ -1808,37 +1891,6 @@ const createStore = () => {
1808
1891
  mapToObj3(changedCellIds),
1809
1892
  mapToObj(changedValueIds),
1810
1893
  ];
1811
- const doDidSetRows = () => {
1812
- if (middleware[14]) {
1813
- const changedCells2 = clonedChangedCells(changedCells);
1814
- collForEach(changedCells2, (rows, tableId) =>
1815
- collForEach(rows, (cells, rowId) => {
1816
- if (
1817
- !arrayEvery(
1818
- collValues(cells),
1819
- ([oldCell, newCell]) => oldCell === newCell,
1820
- )
1821
- ) {
1822
- const newRow = getRow(tableId, rowId);
1823
- const oldRow = objMerge(newRow);
1824
- collForEach(cells, ([oldCell], cellId) =>
1825
- isUndefined(oldCell)
1826
- ? objDel(oldRow, cellId)
1827
- : (oldRow[cellId] = oldCell),
1828
- );
1829
- const didSetRow = middleware[14](tableId, rowId, oldRow, newRow);
1830
- if (!objIsEqual(didSetRow, newRow)) {
1831
- const setOrDelRow = objMap(newRow, () => void 0);
1832
- objMap(didSetRow, (cell, cellId) => (setOrDelRow[cellId] = cell));
1833
- objMap(setOrDelRow, (cell, cellId) =>
1834
- setOrDelCell(tableId, rowId, cellId, cell, true),
1835
- );
1836
- }
1837
- }
1838
- }),
1839
- );
1840
- }
1841
- };
1842
1894
  const finishTransaction = (doRollback) => {
1843
1895
  if (transactions > 0) {
1844
1896
  transactions--;
@@ -1848,7 +1900,6 @@ const createStore = () => {
1848
1900
  callInvalidCellListeners(1);
1849
1901
  if (!collIsEmpty(changedCells)) {
1850
1902
  callTabularListenersForChanges(1);
1851
- doDidSetRows();
1852
1903
  }
1853
1904
  callInvalidValueListeners(1);
1854
1905
  if (!collIsEmpty(changedValues)) {
@@ -2019,7 +2070,7 @@ const createStore = () => {
2019
2070
  willDelValues,
2020
2071
  willDelValue,
2021
2072
  willApplyChanges,
2022
- didSetRow,
2073
+ hasWillSetRowCallbacks,
2023
2074
  ) =>
2024
2075
  (middleware = [
2025
2076
  willSetContent,
@@ -2036,7 +2087,7 @@ const createStore = () => {
2036
2087
  willDelValues,
2037
2088
  willDelValue,
2038
2089
  willApplyChanges,
2039
- didSetRow,
2090
+ hasWillSetRowCallbacks,
2040
2091
  ]);
2041
2092
  const setInternalListeners = (
2042
2093
  preStartTransaction,