@rowsncolumns/spreadsheet-state 29.1.15 → 29.1.17

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.
@@ -635,6 +635,16 @@ export var useCalculation = function (_a) {
635
635
  reclaimed.push(node);
636
636
  return node;
637
637
  };
638
+ // A dependency-parser range is a bare `CellCoordinateRange`, not a
639
+ // `CellRangeNode` (which carries it under `position`) — compare the
640
+ // bounds directly.
641
+ var isWithinDependencyRange = function (position, range) {
642
+ return position.sheetId === range.sheetId &&
643
+ position.rowIndex >= range.startRowIndex &&
644
+ position.rowIndex <= range.endRowIndex &&
645
+ position.columnIndex >= range.startColumnIndex &&
646
+ position.columnIndex <= range.endColumnIndex;
647
+ };
638
648
  var reclaimDeferredNodesInRange = function (range) {
639
649
  var sheetOperations = deferredOperationsBySheetRef.current.get(range.sheetId);
640
650
  if (!(sheetOperations === null || sheetOperations === void 0 ? void 0 : sheetOperations.size)) {
@@ -643,7 +653,7 @@ export var useCalculation = function (_a) {
643
653
  var positions = [];
644
654
  sheetOperations.forEach(function (operation) {
645
655
  if (!cellNodeByKey.has(makeKey(operation.position)) &&
646
- isCellCoordinateWithinCellRange(operation.position, range)) {
656
+ isWithinDependencyRange(operation.position, range)) {
647
657
  positions.push(operation.position);
648
658
  }
649
659
  });
@@ -659,7 +669,11 @@ export var useCalculation = function (_a) {
659
669
  continue;
660
670
  }
661
671
  var formulaValue = String(userEnteredValue).slice(1);
662
- var dependencies = getCalculator().dependencies(formulaValue, current.position);
672
+ // The formula text names the static precedents; an `INDIRECT` /
673
+ // `OFFSET` target is known only from the cell's last evaluation
674
+ // (#1210) — without it the walk stops at the dynamic cell and its
675
+ // deferred precedent stays stale.
676
+ var dependencies = __spreadArray(__spreadArray([], __read(getCalculator().dependencies(formulaValue, current.position)), false), __read(getCalculator().getDynamicPrecedents(current.position)), false);
663
677
  try {
664
678
  for (var dependencies_1 = (e_13 = void 0, __values(dependencies)), dependencies_1_1 = dependencies_1.next(); !dependencies_1_1.done; dependencies_1_1 = dependencies_1.next()) {
665
679
  var dependency = dependencies_1_1.value;
@@ -689,9 +703,8 @@ export var useCalculation = function (_a) {
689
703
  if (includedKeys.has(candidate.key)) {
690
704
  continue;
691
705
  }
692
- if (isCellRangeNode(dependency) &&
693
- !isDerivedCellPosition(candidate.position) &&
694
- isCellCoordinateWithinCellRange(candidate.position, dependency)) {
706
+ if (!isDerivedCellPosition(candidate.position) &&
707
+ isWithinDependencyRange(candidate.position, dependency)) {
695
708
  includedKeys.add(candidate.key);
696
709
  stack.push(candidate);
697
710
  }
@@ -1084,7 +1097,7 @@ export var useCalculation = function (_a) {
1084
1097
  args_1[_i] = arguments[_i];
1085
1098
  }
1086
1099
  return __awaiter(void 0, __spreadArray([], __read(args_1), false), void 0, function (initialResults, recalculatedPosition) {
1087
- var runCellBatch_1, dirtyCells, _loop_1, err_1, MAX_RESCHEDULE;
1100
+ var runCellBatch_1, dirtyCells, dynamicRequeued, _loop_1, err_1, MAX_RESCHEDULE;
1088
1101
  if (initialResults === void 0) { initialResults = new Map(); }
1089
1102
  return __generator(this, function (_a) {
1090
1103
  switch (_a.label) {
@@ -1149,11 +1162,12 @@ export var useCalculation = function (_a) {
1149
1162
  });
1150
1163
  }); };
1151
1164
  dirtyCells = [];
1165
+ dynamicRequeued = new Set();
1152
1166
  _loop_1 = function () {
1153
- var calc, pendingCells, flushPending, dirtyCells_1, dirtyCells_1_1, node, e_21_1;
1154
- var e_21, _b;
1155
- return __generator(this, function (_c) {
1156
- switch (_c.label) {
1167
+ var calc, pendingCells, flushPending, dirtyCells_1, dirtyCells_1_1, node, e_21_1, _b, _c, position, key;
1168
+ var e_21, _d, e_22, _e;
1169
+ return __generator(this, function (_f) {
1170
+ switch (_f.label) {
1157
1171
  case 0:
1158
1172
  calc = getCalculator();
1159
1173
  pendingCells = [];
@@ -1173,26 +1187,26 @@ export var useCalculation = function (_a) {
1173
1187
  }
1174
1188
  });
1175
1189
  }); };
1176
- _c.label = 1;
1190
+ _f.label = 1;
1177
1191
  case 1:
1178
- _c.trys.push([1, 10, 11, 12]);
1192
+ _f.trys.push([1, 10, 11, 12]);
1179
1193
  dirtyCells_1 = (e_21 = void 0, __values(dirtyCells)), dirtyCells_1_1 = dirtyCells_1.next();
1180
- _c.label = 2;
1194
+ _f.label = 2;
1181
1195
  case 2:
1182
1196
  if (!!dirtyCells_1_1.done) return [3 /*break*/, 9];
1183
1197
  node = dirtyCells_1_1.value;
1184
1198
  if (!!node.position) return [3 /*break*/, 7];
1185
1199
  return [4 /*yield*/, flushPending()];
1186
1200
  case 3:
1187
- _c.sent();
1201
+ _f.sent();
1188
1202
  if (!calc.isNamedRangeNodeKey(node.key)) return [3 /*break*/, 5];
1189
1203
  return [4 /*yield*/, calc.evaluateNamedRangeNodeKey(node.key)];
1190
1204
  case 4:
1191
- _c.sent();
1205
+ _f.sent();
1192
1206
  return [3 /*break*/, 6];
1193
1207
  case 5:
1194
1208
  publishStaticCells(node);
1195
- _c.label = 6;
1209
+ _f.label = 6;
1196
1210
  case 6: return [3 /*break*/, 8];
1197
1211
  case 7:
1198
1212
  if (isCellCoordinate(node.position)) {
@@ -1200,24 +1214,41 @@ export var useCalculation = function (_a) {
1200
1214
  // reflects the shape the guard just confirmed (a cell-coordinate node).
1201
1215
  pendingCells.push(node);
1202
1216
  }
1203
- _c.label = 8;
1217
+ _f.label = 8;
1204
1218
  case 8:
1205
1219
  dirtyCells_1_1 = dirtyCells_1.next();
1206
1220
  return [3 /*break*/, 2];
1207
1221
  case 9: return [3 /*break*/, 12];
1208
1222
  case 10:
1209
- e_21_1 = _c.sent();
1223
+ e_21_1 = _f.sent();
1210
1224
  e_21 = { error: e_21_1 };
1211
1225
  return [3 /*break*/, 12];
1212
1226
  case 11:
1213
1227
  try {
1214
- if (dirtyCells_1_1 && !dirtyCells_1_1.done && (_b = dirtyCells_1.return)) _b.call(dirtyCells_1);
1228
+ if (dirtyCells_1_1 && !dirtyCells_1_1.done && (_d = dirtyCells_1.return)) _d.call(dirtyCells_1);
1215
1229
  }
1216
1230
  finally { if (e_21) throw e_21.error; }
1217
1231
  return [7 /*endfinally*/];
1218
1232
  case 12: return [4 /*yield*/, flushPending()];
1219
1233
  case 13:
1220
- _c.sent();
1234
+ _f.sent();
1235
+ try {
1236
+ for (_b = (e_22 = void 0, __values(calc.takeDynamicPrecedentChanges())), _c = _b.next(); !_c.done; _c = _b.next()) {
1237
+ position = _c.value;
1238
+ key = makeKey(position);
1239
+ if (dynamicRequeued.has(key))
1240
+ continue;
1241
+ dynamicRequeued.add(key);
1242
+ calc.markAsDirty(position);
1243
+ }
1244
+ }
1245
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1246
+ finally {
1247
+ try {
1248
+ if (_c && !_c.done && (_e = _b.return)) _e.call(_b);
1249
+ }
1250
+ finally { if (e_22) throw e_22.error; }
1251
+ }
1221
1252
  return [2 /*return*/];
1222
1253
  }
1223
1254
  });
@@ -1274,8 +1305,8 @@ export var useCalculation = function (_a) {
1274
1305
  // Process async
1275
1306
  function processCells(cells, recalculatedPosition) {
1276
1307
  return __awaiter(this, void 0, void 0, function () {
1277
- var cellMap, cells_5, cells_5_1, cell, adjacency, getDependencies, hasSelfReference, indices, lowlinks, stack, onStack, iterativeGroups, index, strongConnect, cells_6, cells_6_1, cell, key, cells_7, cells_7_1, cell, key, iterativeKeys, iterativeGroups_1, iterativeGroups_1_1, group, group_1, group_1_1, cell, nonIterativeCells, maxIterations, maxChange, iterativeGroups_2, iterativeGroups_2_1, group, group_2, group_2_1, cell, effectiveValue, previousValues, converged, iteration, currentValues, group_3, group_3_1, cell, userEnteredValue, result, key, err_2, error_1, e_22_1, maxDelta, currentValues_1, currentValues_1_1, _a, key, value, delta, finalValues, results, group_4, group_4_1, cell, key, value, _b, arrayErrors, recomputeOperations, arrayErrors_1, arrayErrors_1_1, _c, errorKey, errorValue, _d, collides, recomputeOperations, e_23_1, followUpCells, iterativeGroups_3, iterativeGroups_3_1, group, group_5, group_5_1, cell, dependents, dependents_1, dependents_1_1, dependent, cellDep, depKey;
1278
- var e_24, _e, e_25, _f, e_26, _g, e_27, _h, e_28, _j, e_23, _k, e_29, _l, e_22, _m, e_30, _o, e_31, _p, e_32, _q, e_33, _r, e_34, _s, e_35, _t;
1308
+ var cellMap, cells_5, cells_5_1, cell, adjacency, getDependencies, hasSelfReference, indices, lowlinks, stack, onStack, iterativeGroups, index, strongConnect, cells_6, cells_6_1, cell, key, cells_7, cells_7_1, cell, key, iterativeKeys, iterativeGroups_1, iterativeGroups_1_1, group, group_1, group_1_1, cell, nonIterativeCells, maxIterations, maxChange, iterativeGroups_2, iterativeGroups_2_1, group, group_2, group_2_1, cell, effectiveValue, previousValues, converged, iteration, currentValues, group_3, group_3_1, cell, userEnteredValue, result, key, err_2, error_1, e_23_1, maxDelta, currentValues_1, currentValues_1_1, _a, key, value, delta, finalValues, results, group_4, group_4_1, cell, key, value, _b, arrayErrors, recomputeOperations, arrayErrors_1, arrayErrors_1_1, _c, errorKey, errorValue, _d, collides, recomputeOperations, e_24_1, followUpCells, iterativeGroups_3, iterativeGroups_3_1, group, group_5, group_5_1, cell, dependents, dependents_1, dependents_1_1, dependent, cellDep, depKey;
1309
+ var e_25, _e, e_26, _f, e_27, _g, e_28, _h, e_29, _j, e_24, _k, e_30, _l, e_23, _m, e_31, _o, e_32, _p, e_33, _q, e_34, _r, e_35, _s, e_36, _t;
1279
1310
  var _u, _v, _w, _x, _y, _z, _0;
1280
1311
  return __generator(this, function (_1) {
1281
1312
  switch (_1.label) {
@@ -1290,16 +1321,16 @@ export var useCalculation = function (_a) {
1290
1321
  cellMap.set(makeKey(cell.position), cell);
1291
1322
  }
1292
1323
  }
1293
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
1324
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
1294
1325
  finally {
1295
1326
  try {
1296
1327
  if (cells_5_1 && !cells_5_1.done && (_e = cells_5.return)) _e.call(cells_5);
1297
1328
  }
1298
- finally { if (e_24) throw e_24.error; }
1329
+ finally { if (e_25) throw e_25.error; }
1299
1330
  }
1300
1331
  adjacency = new Map();
1301
1332
  getDependencies = function (cell) {
1302
- var e_36, _a, e_37, _b;
1333
+ var e_37, _a, e_38, _b;
1303
1334
  var deps = getCalculator().getPrecedents(cell.position);
1304
1335
  var depKeys = new Set();
1305
1336
  try {
@@ -1315,7 +1346,7 @@ export var useCalculation = function (_a) {
1315
1346
  if (isCellRangeNode(dep)) {
1316
1347
  var rangeDep = dep;
1317
1348
  try {
1318
- for (var cells_8 = (e_37 = void 0, __values(cells)), cells_8_1 = cells_8.next(); !cells_8_1.done; cells_8_1 = cells_8.next()) {
1349
+ for (var cells_8 = (e_38 = void 0, __values(cells)), cells_8_1 = cells_8.next(); !cells_8_1.done; cells_8_1 = cells_8.next()) {
1319
1350
  var candidate = cells_8_1.value;
1320
1351
  if (!isDerivedCellPosition(candidate.position) &&
1321
1352
  isCellCoordinateWithinCellRange(candidate.position, rangeDep)) {
@@ -1323,22 +1354,22 @@ export var useCalculation = function (_a) {
1323
1354
  }
1324
1355
  }
1325
1356
  }
1326
- catch (e_37_1) { e_37 = { error: e_37_1 }; }
1357
+ catch (e_38_1) { e_38 = { error: e_38_1 }; }
1327
1358
  finally {
1328
1359
  try {
1329
1360
  if (cells_8_1 && !cells_8_1.done && (_b = cells_8.return)) _b.call(cells_8);
1330
1361
  }
1331
- finally { if (e_37) throw e_37.error; }
1362
+ finally { if (e_38) throw e_38.error; }
1332
1363
  }
1333
1364
  }
1334
1365
  }
1335
1366
  }
1336
- catch (e_36_1) { e_36 = { error: e_36_1 }; }
1367
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
1337
1368
  finally {
1338
1369
  try {
1339
1370
  if (deps_1_1 && !deps_1_1.done && (_a = deps_1.return)) _a.call(deps_1);
1340
1371
  }
1341
- finally { if (e_36) throw e_36.error; }
1372
+ finally { if (e_37) throw e_37.error; }
1342
1373
  }
1343
1374
  return depKeys;
1344
1375
  };
@@ -1375,7 +1406,7 @@ export var useCalculation = function (_a) {
1375
1406
  iterativeGroups = [];
1376
1407
  index = 0;
1377
1408
  strongConnect = function (key) {
1378
- var e_38, _a;
1409
+ var e_39, _a;
1379
1410
  var _b;
1380
1411
  indices.set(key, index);
1381
1412
  lowlinks.set(key, index);
@@ -1395,12 +1426,12 @@ export var useCalculation = function (_a) {
1395
1426
  }
1396
1427
  }
1397
1428
  }
1398
- catch (e_38_1) { e_38 = { error: e_38_1 }; }
1429
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
1399
1430
  finally {
1400
1431
  try {
1401
1432
  if (deps_2_1 && !deps_2_1.done && (_a = deps_2.return)) _a.call(deps_2);
1402
1433
  }
1403
- finally { if (e_38) throw e_38.error; }
1434
+ finally { if (e_39) throw e_39.error; }
1404
1435
  }
1405
1436
  if (lowlinks.get(key) === indices.get(key)) {
1406
1437
  var componentKeys = [];
@@ -1435,12 +1466,12 @@ export var useCalculation = function (_a) {
1435
1466
  }
1436
1467
  }
1437
1468
  }
1438
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
1469
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1439
1470
  finally {
1440
1471
  try {
1441
1472
  if (cells_6_1 && !cells_6_1.done && (_f = cells_6.return)) _f.call(cells_6);
1442
1473
  }
1443
- finally { if (e_25) throw e_25.error; }
1474
+ finally { if (e_26) throw e_26.error; }
1444
1475
  }
1445
1476
  try {
1446
1477
  for (cells_7 = __values(cells), cells_7_1 = cells_7.next(); !cells_7_1.done; cells_7_1 = cells_7.next()) {
@@ -1451,12 +1482,12 @@ export var useCalculation = function (_a) {
1451
1482
  }
1452
1483
  }
1453
1484
  }
1454
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
1485
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
1455
1486
  finally {
1456
1487
  try {
1457
1488
  if (cells_7_1 && !cells_7_1.done && (_g = cells_7.return)) _g.call(cells_7);
1458
1489
  }
1459
- finally { if (e_26) throw e_26.error; }
1490
+ finally { if (e_27) throw e_27.error; }
1460
1491
  }
1461
1492
  if (!iterativeGroups.length) {
1462
1493
  return [2 /*return*/, processCellsInParallel(cells, recalculatedPosition)];
@@ -1466,26 +1497,26 @@ export var useCalculation = function (_a) {
1466
1497
  for (iterativeGroups_1 = __values(iterativeGroups), iterativeGroups_1_1 = iterativeGroups_1.next(); !iterativeGroups_1_1.done; iterativeGroups_1_1 = iterativeGroups_1.next()) {
1467
1498
  group = iterativeGroups_1_1.value;
1468
1499
  try {
1469
- for (group_1 = (e_28 = void 0, __values(group)), group_1_1 = group_1.next(); !group_1_1.done; group_1_1 = group_1.next()) {
1500
+ for (group_1 = (e_29 = void 0, __values(group)), group_1_1 = group_1.next(); !group_1_1.done; group_1_1 = group_1.next()) {
1470
1501
  cell = group_1_1.value;
1471
1502
  iterativeKeys.add(makeKey(cell.position));
1472
1503
  }
1473
1504
  }
1474
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
1505
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1475
1506
  finally {
1476
1507
  try {
1477
1508
  if (group_1_1 && !group_1_1.done && (_j = group_1.return)) _j.call(group_1);
1478
1509
  }
1479
- finally { if (e_28) throw e_28.error; }
1510
+ finally { if (e_29) throw e_29.error; }
1480
1511
  }
1481
1512
  }
1482
1513
  }
1483
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
1514
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
1484
1515
  finally {
1485
1516
  try {
1486
1517
  if (iterativeGroups_1_1 && !iterativeGroups_1_1.done && (_h = iterativeGroups_1.return)) _h.call(iterativeGroups_1);
1487
1518
  }
1488
- finally { if (e_27) throw e_27.error; }
1519
+ finally { if (e_28) throw e_28.error; }
1489
1520
  }
1490
1521
  nonIterativeCells = cells.filter(function (cell) { return !iterativeKeys.has(makeKey(cell.position)); });
1491
1522
  if (!nonIterativeCells.length) return [3 /*break*/, 2];
@@ -1505,7 +1536,7 @@ export var useCalculation = function (_a) {
1505
1536
  if (!!iterativeGroups_2_1.done) return [3 /*break*/, 21];
1506
1537
  group = iterativeGroups_2_1.value;
1507
1538
  try {
1508
- for (group_2 = (e_29 = void 0, __values(group)), group_2_1 = group_2.next(); !group_2_1.done; group_2_1 = group_2.next()) {
1539
+ for (group_2 = (e_30 = void 0, __values(group)), group_2_1 = group_2.next(); !group_2_1.done; group_2_1 = group_2.next()) {
1509
1540
  cell = group_2_1.value;
1510
1541
  effectiveValue = getEffectiveValue === null || getEffectiveValue === void 0 ? void 0 : getEffectiveValue(cell.position.sheetId, cell.position.rowIndex, cell.position.columnIndex);
1511
1542
  if (isErrorResult(effectiveValue)) {
@@ -1513,12 +1544,12 @@ export var useCalculation = function (_a) {
1513
1544
  }
1514
1545
  }
1515
1546
  }
1516
- catch (e_29_1) { e_29 = { error: e_29_1 }; }
1547
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
1517
1548
  finally {
1518
1549
  try {
1519
1550
  if (group_2_1 && !group_2_1.done && (_l = group_2.return)) _l.call(group_2);
1520
1551
  }
1521
- finally { if (e_29) throw e_29.error; }
1552
+ finally { if (e_30) throw e_30.error; }
1522
1553
  }
1523
1554
  previousValues = null;
1524
1555
  converged = false;
@@ -1530,7 +1561,7 @@ export var useCalculation = function (_a) {
1530
1561
  _1.label = 6;
1531
1562
  case 6:
1532
1563
  _1.trys.push([6, 15, 16, 17]);
1533
- group_3 = (e_22 = void 0, __values(group)), group_3_1 = group_3.next();
1564
+ group_3 = (e_23 = void 0, __values(group)), group_3_1 = group_3.next();
1534
1565
  _1.label = 7;
1535
1566
  case 7:
1536
1567
  if (!!group_3_1.done) return [3 /*break*/, 14];
@@ -1574,20 +1605,20 @@ export var useCalculation = function (_a) {
1574
1605
  return [3 /*break*/, 7];
1575
1606
  case 14: return [3 /*break*/, 17];
1576
1607
  case 15:
1577
- e_22_1 = _1.sent();
1578
- e_22 = { error: e_22_1 };
1608
+ e_23_1 = _1.sent();
1609
+ e_23 = { error: e_23_1 };
1579
1610
  return [3 /*break*/, 17];
1580
1611
  case 16:
1581
1612
  try {
1582
1613
  if (group_3_1 && !group_3_1.done && (_m = group_3.return)) _m.call(group_3);
1583
1614
  }
1584
- finally { if (e_22) throw e_22.error; }
1615
+ finally { if (e_23) throw e_23.error; }
1585
1616
  return [7 /*endfinally*/];
1586
1617
  case 17:
1587
1618
  if (previousValues) {
1588
1619
  maxDelta = 0;
1589
1620
  try {
1590
- for (currentValues_1 = (e_30 = void 0, __values(currentValues)), currentValues_1_1 = currentValues_1.next(); !currentValues_1_1.done; currentValues_1_1 = currentValues_1.next()) {
1621
+ for (currentValues_1 = (e_31 = void 0, __values(currentValues)), currentValues_1_1 = currentValues_1.next(); !currentValues_1_1.done; currentValues_1_1 = currentValues_1.next()) {
1591
1622
  _a = __read(currentValues_1_1.value, 2), key = _a[0], value = _a[1];
1592
1623
  delta = computeDelta(previousValues.get(key), value);
1593
1624
  if (delta > maxDelta) {
@@ -1595,12 +1626,12 @@ export var useCalculation = function (_a) {
1595
1626
  }
1596
1627
  }
1597
1628
  }
1598
- catch (e_30_1) { e_30 = { error: e_30_1 }; }
1629
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
1599
1630
  finally {
1600
1631
  try {
1601
1632
  if (currentValues_1_1 && !currentValues_1_1.done && (_o = currentValues_1.return)) _o.call(currentValues_1);
1602
1633
  }
1603
- finally { if (e_30) throw e_30.error; }
1634
+ finally { if (e_31) throw e_31.error; }
1604
1635
  }
1605
1636
  previousValues = currentValues;
1606
1637
  if (maxDelta <= maxChange) {
@@ -1619,7 +1650,7 @@ export var useCalculation = function (_a) {
1619
1650
  finalValues = previousValues !== null && previousValues !== void 0 ? previousValues : new Map();
1620
1651
  results = new Map();
1621
1652
  try {
1622
- for (group_4 = (e_31 = void 0, __values(group)), group_4_1 = group_4.next(); !group_4_1.done; group_4_1 = group_4.next()) {
1653
+ for (group_4 = (e_32 = void 0, __values(group)), group_4_1 = group_4.next(); !group_4_1.done; group_4_1 = group_4.next()) {
1623
1654
  cell = group_4_1.value;
1624
1655
  key = makeKey(cell.position);
1625
1656
  value = finalValues.get(key);
@@ -1632,17 +1663,17 @@ export var useCalculation = function (_a) {
1632
1663
  enqueueCalculations(recomputeOperations);
1633
1664
  results.set(key, [cell.position, value]);
1634
1665
  try {
1635
- for (arrayErrors_1 = (e_32 = void 0, __values(arrayErrors)), arrayErrors_1_1 = arrayErrors_1.next(); !arrayErrors_1_1.done; arrayErrors_1_1 = arrayErrors_1.next()) {
1666
+ for (arrayErrors_1 = (e_33 = void 0, __values(arrayErrors)), arrayErrors_1_1 = arrayErrors_1.next(); !arrayErrors_1_1.done; arrayErrors_1_1 = arrayErrors_1.next()) {
1636
1667
  _c = __read(arrayErrors_1_1.value, 2), errorKey = _c[0], errorValue = _c[1];
1637
1668
  results.set(errorKey, errorValue);
1638
1669
  }
1639
1670
  }
1640
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
1671
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
1641
1672
  finally {
1642
1673
  try {
1643
1674
  if (arrayErrors_1_1 && !arrayErrors_1_1.done && (_q = arrayErrors_1.return)) _q.call(arrayErrors_1);
1644
1675
  }
1645
- finally { if (e_32) throw e_32.error; }
1676
+ finally { if (e_33) throw e_33.error; }
1646
1677
  }
1647
1678
  continue;
1648
1679
  }
@@ -1659,12 +1690,12 @@ export var useCalculation = function (_a) {
1659
1690
  }
1660
1691
  }
1661
1692
  }
1662
- catch (e_31_1) { e_31 = { error: e_31_1 }; }
1693
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
1663
1694
  finally {
1664
1695
  try {
1665
1696
  if (group_4_1 && !group_4_1.done && (_p = group_4.return)) _p.call(group_4);
1666
1697
  }
1667
- finally { if (e_31) throw e_31.error; }
1698
+ finally { if (e_32) throw e_32.error; }
1668
1699
  }
1669
1700
  publishResults(results.values());
1670
1701
  _1.label = 20;
@@ -1673,14 +1704,14 @@ export var useCalculation = function (_a) {
1673
1704
  return [3 /*break*/, 4];
1674
1705
  case 21: return [3 /*break*/, 24];
1675
1706
  case 22:
1676
- e_23_1 = _1.sent();
1677
- e_23 = { error: e_23_1 };
1707
+ e_24_1 = _1.sent();
1708
+ e_24 = { error: e_24_1 };
1678
1709
  return [3 /*break*/, 24];
1679
1710
  case 23:
1680
1711
  try {
1681
1712
  if (iterativeGroups_2_1 && !iterativeGroups_2_1.done && (_k = iterativeGroups_2.return)) _k.call(iterativeGroups_2);
1682
1713
  }
1683
- finally { if (e_23) throw e_23.error; }
1714
+ finally { if (e_24) throw e_24.error; }
1684
1715
  return [7 /*endfinally*/];
1685
1716
  case 24:
1686
1717
  followUpCells = new Map();
@@ -1688,11 +1719,11 @@ export var useCalculation = function (_a) {
1688
1719
  for (iterativeGroups_3 = __values(iterativeGroups), iterativeGroups_3_1 = iterativeGroups_3.next(); !iterativeGroups_3_1.done; iterativeGroups_3_1 = iterativeGroups_3.next()) {
1689
1720
  group = iterativeGroups_3_1.value;
1690
1721
  try {
1691
- for (group_5 = (e_34 = void 0, __values(group)), group_5_1 = group_5.next(); !group_5_1.done; group_5_1 = group_5.next()) {
1722
+ for (group_5 = (e_35 = void 0, __values(group)), group_5_1 = group_5.next(); !group_5_1.done; group_5_1 = group_5.next()) {
1692
1723
  cell = group_5_1.value;
1693
1724
  dependents = getDependents(cell.position);
1694
1725
  try {
1695
- for (dependents_1 = (e_35 = void 0, __values(dependents)), dependents_1_1 = dependents_1.next(); !dependents_1_1.done; dependents_1_1 = dependents_1.next()) {
1726
+ for (dependents_1 = (e_36 = void 0, __values(dependents)), dependents_1_1 = dependents_1.next(); !dependents_1_1.done; dependents_1_1 = dependents_1.next()) {
1696
1727
  dependent = dependents_1_1.value;
1697
1728
  if (isCellNode(dependent)) {
1698
1729
  cellDep = dependent;
@@ -1703,30 +1734,30 @@ export var useCalculation = function (_a) {
1703
1734
  }
1704
1735
  }
1705
1736
  }
1706
- catch (e_35_1) { e_35 = { error: e_35_1 }; }
1737
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
1707
1738
  finally {
1708
1739
  try {
1709
1740
  if (dependents_1_1 && !dependents_1_1.done && (_t = dependents_1.return)) _t.call(dependents_1);
1710
1741
  }
1711
- finally { if (e_35) throw e_35.error; }
1742
+ finally { if (e_36) throw e_36.error; }
1712
1743
  }
1713
1744
  }
1714
1745
  }
1715
- catch (e_34_1) { e_34 = { error: e_34_1 }; }
1746
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
1716
1747
  finally {
1717
1748
  try {
1718
1749
  if (group_5_1 && !group_5_1.done && (_s = group_5.return)) _s.call(group_5);
1719
1750
  }
1720
- finally { if (e_34) throw e_34.error; }
1751
+ finally { if (e_35) throw e_35.error; }
1721
1752
  }
1722
1753
  }
1723
1754
  }
1724
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
1755
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
1725
1756
  finally {
1726
1757
  try {
1727
1758
  if (iterativeGroups_3_1 && !iterativeGroups_3_1.done && (_r = iterativeGroups_3.return)) _r.call(iterativeGroups_3);
1728
1759
  }
1729
- finally { if (e_33) throw e_33.error; }
1760
+ finally { if (e_34) throw e_34.error; }
1730
1761
  }
1731
1762
  if (!followUpCells.size) return [3 /*break*/, 26];
1732
1763
  return [4 /*yield*/, processCellsInParallel(Array.from(followUpCells.values()), recalculatedPosition)];
@@ -1743,7 +1774,7 @@ export var useCalculation = function (_a) {
1743
1774
  function processCellWithDependencies(cell) {
1744
1775
  return __awaiter(this, void 0, void 0, function () {
1745
1776
  var cellKey, controller_1, dependencies, cellDependencies, rangeDependencies, rangeDependencies_1, rangeDependencies_1_1, dep, cells_9, cells_9_1, cell_1, dependencyPromises_1, cellPromise;
1746
- var e_39, _a, e_40, _b;
1777
+ var e_40, _a, e_41, _b;
1747
1778
  var _this = this;
1748
1779
  return __generator(this, function (_c) {
1749
1780
  switch (_c.label) {
@@ -1772,7 +1803,7 @@ export var useCalculation = function (_a) {
1772
1803
  for (rangeDependencies_1 = __values(rangeDependencies), rangeDependencies_1_1 = rangeDependencies_1.next(); !rangeDependencies_1_1.done; rangeDependencies_1_1 = rangeDependencies_1.next()) {
1773
1804
  dep = rangeDependencies_1_1.value;
1774
1805
  try {
1775
- for (cells_9 = (e_40 = void 0, __values(cells)), cells_9_1 = cells_9.next(); !cells_9_1.done; cells_9_1 = cells_9.next()) {
1806
+ for (cells_9 = (e_41 = void 0, __values(cells)), cells_9_1 = cells_9.next(); !cells_9_1.done; cells_9_1 = cells_9.next()) {
1776
1807
  cell_1 = cells_9_1.value;
1777
1808
  if (!isDerivedCellPosition(cell_1.position) &&
1778
1809
  isCellCoordinateWithinCellRange(cell_1.position, dep)) {
@@ -1780,21 +1811,21 @@ export var useCalculation = function (_a) {
1780
1811
  }
1781
1812
  }
1782
1813
  }
1783
- catch (e_40_1) { e_40 = { error: e_40_1 }; }
1814
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
1784
1815
  finally {
1785
1816
  try {
1786
1817
  if (cells_9_1 && !cells_9_1.done && (_b = cells_9.return)) _b.call(cells_9);
1787
1818
  }
1788
- finally { if (e_40) throw e_40.error; }
1819
+ finally { if (e_41) throw e_41.error; }
1789
1820
  }
1790
1821
  }
1791
1822
  }
1792
- catch (e_39_1) { e_39 = { error: e_39_1 }; }
1823
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
1793
1824
  finally {
1794
1825
  try {
1795
1826
  if (rangeDependencies_1_1 && !rangeDependencies_1_1.done && (_a = rangeDependencies_1.return)) _a.call(rangeDependencies_1);
1796
1827
  }
1797
- finally { if (e_39) throw e_39.error; }
1828
+ finally { if (e_40) throw e_40.error; }
1798
1829
  }
1799
1830
  dependencyPromises_1 = cellDependencies.map(function (dep) {
1800
1831
  return processCellWithDependencies(dep);
@@ -1854,7 +1885,7 @@ export var useCalculation = function (_a) {
1854
1885
  return 1;
1855
1886
  };
1856
1887
  chunkCells = function () {
1857
- var e_41, _a;
1888
+ var e_42, _a;
1858
1889
  if (!cells.length) {
1859
1890
  return [];
1860
1891
  }
@@ -1883,12 +1914,12 @@ export var useCalculation = function (_a) {
1883
1914
  }
1884
1915
  }
1885
1916
  }
1886
- catch (e_41_1) { e_41 = { error: e_41_1 }; }
1917
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
1887
1918
  finally {
1888
1919
  try {
1889
1920
  if (cells_10_1 && !cells_10_1.done && (_a = cells_10.return)) _a.call(cells_10);
1890
1921
  }
1891
- finally { if (e_41) throw e_41.error; }
1922
+ finally { if (e_42) throw e_42.error; }
1892
1923
  }
1893
1924
  flush();
1894
1925
  return chunks.length ? chunks : [cells];
@@ -1925,7 +1956,7 @@ export var useCalculation = function (_a) {
1925
1956
  // Process a single dirty cell
1926
1957
  var processCell = function (dirtyCell, recalculatedPosition) { return __awaiter(void 0, void 0, void 0, function () {
1927
1958
  var results, position, key, userEnteredValue, isFormula, onDemandMap, rafTimer, isCellNode_1, result, _a, collides, recomputeOperations, err_3, error_2, _b, arrayErrors, recomputeOperations, arrayErrors_2, arrayErrors_2_1, _c, key_1, value;
1928
- var e_42, _d;
1959
+ var e_43, _d;
1929
1960
  return __generator(this, function (_e) {
1930
1961
  switch (_e.label) {
1931
1962
  case 0:
@@ -2042,12 +2073,12 @@ export var useCalculation = function (_a) {
2042
2073
  results.set(key_1, value);
2043
2074
  }
2044
2075
  }
2045
- catch (e_42_1) { e_42 = { error: e_42_1 }; }
2076
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
2046
2077
  finally {
2047
2078
  try {
2048
2079
  if (arrayErrors_2_1 && !arrayErrors_2_1.done && (_d = arrayErrors_2.return)) _d.call(arrayErrors_2);
2049
2080
  }
2050
- finally { if (e_42) throw e_42.error; }
2081
+ finally { if (e_43) throw e_43.error; }
2051
2082
  }
2052
2083
  }
2053
2084
  return [3 /*break*/, 6];
@@ -2106,7 +2137,7 @@ export var useCalculation = function (_a) {
2106
2137
  * Publish results back to the
2107
2138
  */
2108
2139
  var publishResults = useCallback(function (item, circularReferences) {
2109
- var e_43, _a, e_44, _b;
2140
+ var e_44, _a, e_45, _b;
2110
2141
  try {
2111
2142
  for (var item_1 = __values(item), item_1_1 = item_1.next(); !item_1_1.done; item_1_1 = item_1.next()) {
2112
2143
  var entry = item_1_1.value;
@@ -2114,12 +2145,12 @@ export var useCalculation = function (_a) {
2114
2145
  resultsQueueRef.current.set(makeKey(key), entry);
2115
2146
  }
2116
2147
  }
2117
- catch (e_43_1) { e_43 = { error: e_43_1 }; }
2148
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
2118
2149
  finally {
2119
2150
  try {
2120
2151
  if (item_1_1 && !item_1_1.done && (_a = item_1.return)) _a.call(item_1);
2121
2152
  }
2122
- finally { if (e_43) throw e_43.error; }
2153
+ finally { if (e_44) throw e_44.error; }
2123
2154
  }
2124
2155
  try {
2125
2156
  for (var _d = __values(circularReferences !== null && circularReferences !== void 0 ? circularReferences : []), _e = _d.next(); !_e.done; _e = _d.next()) {
@@ -2127,12 +2158,12 @@ export var useCalculation = function (_a) {
2127
2158
  circularReferencesQueueRef.current.set(makeKey(position), position);
2128
2159
  }
2129
2160
  }
2130
- catch (e_44_1) { e_44 = { error: e_44_1 }; }
2161
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
2131
2162
  finally {
2132
2163
  try {
2133
2164
  if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
2134
2165
  }
2135
- finally { if (e_44) throw e_44.error; }
2166
+ finally { if (e_45) throw e_45.error; }
2136
2167
  }
2137
2168
  if (resultsQueueRef.current.size === 0) {
2138
2169
  return;
@@ -2382,7 +2413,7 @@ export var useCalculation = function (_a) {
2382
2413
  // Get precedents from formula string
2383
2414
  // Does not check with DAG
2384
2415
  var getPrecedentsFromFormulaString = useCallback(function (value, source) {
2385
- var e_45, _a;
2416
+ var e_46, _a;
2386
2417
  var dependencies = getCalculator().dependencies(value, source);
2387
2418
  var nodes = [];
2388
2419
  try {
@@ -2401,12 +2432,12 @@ export var useCalculation = function (_a) {
2401
2432
  }
2402
2433
  }
2403
2434
  }
2404
- catch (e_45_1) { e_45 = { error: e_45_1 }; }
2435
+ catch (e_46_1) { e_46 = { error: e_46_1 }; }
2405
2436
  finally {
2406
2437
  try {
2407
2438
  if (dependencies_2_1 && !dependencies_2_1.done && (_a = dependencies_2.return)) _a.call(dependencies_2);
2408
2439
  }
2409
- finally { if (e_45) throw e_45.error; }
2440
+ finally { if (e_46) throw e_46.error; }
2410
2441
  }
2411
2442
  return nodes;
2412
2443
  }, []);
@@ -2468,7 +2499,7 @@ export var useCalculation = function (_a) {
2468
2499
  * via the enqueue logic.
2469
2500
  */
2470
2501
  var processOperationQueue = useCallback(function () {
2471
- var e_46, _a, e_47, _b, e_48, _c, e_49, _d;
2502
+ var e_47, _a, e_48, _b, e_49, _c, e_50, _d;
2472
2503
  // Swap queue with empty array - O(1) operation
2473
2504
  var operations = operationQueue.current;
2474
2505
  if (operations.length === 0)
@@ -2496,7 +2527,7 @@ export var useCalculation = function (_a) {
2496
2527
  if (operation.type !== "dirty" && isArrayFormula(operation.position)) {
2497
2528
  var parentCandidates = new Map();
2498
2529
  try {
2499
- for (var _e = (e_46 = void 0, __values(createArraySideEffectsAndGetResults({
2530
+ for (var _e = (e_47 = void 0, __values(createArraySideEffectsAndGetResults({
2500
2531
  position: operation.position,
2501
2532
  getDependents: getDependents,
2502
2533
  }))), _f = _e.next(); !_f.done; _f = _e.next()) {
@@ -2511,29 +2542,29 @@ export var useCalculation = function (_a) {
2511
2542
  }
2512
2543
  }
2513
2544
  }
2514
- catch (e_46_1) { e_46 = { error: e_46_1 }; }
2545
+ catch (e_47_1) { e_47 = { error: e_47_1 }; }
2515
2546
  finally {
2516
2547
  try {
2517
2548
  if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
2518
2549
  }
2519
- finally { if (e_46) throw e_46.error; }
2550
+ finally { if (e_47) throw e_47.error; }
2520
2551
  }
2521
2552
  try {
2522
- for (var _j = (e_47 = void 0, __values(parentCandidates.values())), _k = _j.next(); !_k.done; _k = _j.next()) {
2553
+ for (var _j = (e_48 = void 0, __values(parentCandidates.values())), _k = _j.next(); !_k.done; _k = _j.next()) {
2523
2554
  var parent_2 = _k.value;
2524
2555
  getCalculator().markAsDirty(parent_2);
2525
2556
  }
2526
2557
  }
2527
- catch (e_47_1) { e_47 = { error: e_47_1 }; }
2558
+ catch (e_48_1) { e_48 = { error: e_48_1 }; }
2528
2559
  finally {
2529
2560
  try {
2530
2561
  if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
2531
2562
  }
2532
- finally { if (e_47) throw e_47.error; }
2563
+ finally { if (e_48) throw e_48.error; }
2533
2564
  }
2534
2565
  if (clearedArrayRange) {
2535
2566
  try {
2536
- for (var _l = (e_48 = void 0, __values(getCalculator().arrayRangeMap)), _m = _l.next(); !_m.done; _m = _l.next()) {
2567
+ for (var _l = (e_49 = void 0, __values(getCalculator().arrayRangeMap)), _m = _l.next(); !_m.done; _m = _l.next()) {
2537
2568
  var _o = __read(_m.value, 2), key = _o[0], range = _o[1];
2538
2569
  if (!rangesOverlap(range, clearedArrayRange)) {
2539
2570
  continue;
@@ -2544,19 +2575,19 @@ export var useCalculation = function (_a) {
2544
2575
  }
2545
2576
  }
2546
2577
  }
2547
- catch (e_48_1) { e_48 = { error: e_48_1 }; }
2578
+ catch (e_49_1) { e_49 = { error: e_49_1 }; }
2548
2579
  finally {
2549
2580
  try {
2550
2581
  if (_m && !_m.done && (_c = _l.return)) _c.call(_l);
2551
2582
  }
2552
- finally { if (e_48) throw e_48.error; }
2583
+ finally { if (e_49) throw e_49.error; }
2553
2584
  }
2554
2585
  }
2555
2586
  }
2556
2587
  var arrayParent = getCalculator().getClosestArrayParentCell(operation.position);
2557
2588
  if (arrayParent && !isEqualPosition(arrayParent, operation.position)) {
2558
2589
  try {
2559
- for (var _p = (e_49 = void 0, __values(createArraySideEffectsAndGetResults({
2590
+ for (var _p = (e_50 = void 0, __values(createArraySideEffectsAndGetResults({
2560
2591
  position: arrayParent,
2561
2592
  shouldRemoveArrayReference: false,
2562
2593
  getDependents: getDependents,
@@ -2565,12 +2596,12 @@ export var useCalculation = function (_a) {
2565
2596
  initialArrayResults.current.set(key, value);
2566
2597
  }
2567
2598
  }
2568
- catch (e_49_1) { e_49 = { error: e_49_1 }; }
2599
+ catch (e_50_1) { e_50 = { error: e_50_1 }; }
2569
2600
  finally {
2570
2601
  try {
2571
2602
  if (_q && !_q.done && (_d = _p.return)) _d.call(_p);
2572
2603
  }
2573
- finally { if (e_49) throw e_49.error; }
2604
+ finally { if (e_50) throw e_50.error; }
2574
2605
  }
2575
2606
  }
2576
2607
  // Backend driven