@univerjs/sheets-formula 0.15.4 → 0.15.5

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/lib/index.js CHANGED
@@ -12,16 +12,16 @@ const Ti = {
12
12
  handler: async (a, e) => {
13
13
  const { list: n, listOfRangeHasNumber: i } = e, r = a.get(ue), o = new V();
14
14
  n.forEach((m) => {
15
- const { range: f, primary: c, formula: l } = m, { row: L, column: E } = c, p = la(6);
16
- o.setValue(L, E, {
15
+ const { range: f, primary: c, formula: l } = m, { row: p, column: E } = c, L = la(6);
16
+ o.setValue(p, E, {
17
17
  f: l,
18
- si: p
18
+ si: L
19
19
  });
20
20
  const { startRow: S, startColumn: A, endRow: I, endColumn: d } = f;
21
21
  for (let R = S; R <= I; R++)
22
22
  for (let N = A; N <= d; N++)
23
- (R !== L || N !== E) && o.setValue(R, N, {
24
- si: p
23
+ (R !== p || N !== E) && o.setValue(R, N, {
24
+ si: L
25
25
  });
26
26
  }), i && i.length > 0 && i.forEach((m) => {
27
27
  const { primary: f, formula: c } = m;
@@ -58,29 +58,29 @@ const Ti = {
58
58
  endColumn: f.endColumn
59
59
  }, u);
60
60
  if (!fe.equals(l, f))
61
- for (const p of u.iterateByColumn(l))
62
- (!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, {
61
+ for (const L of u.iterateByColumn(l))
62
+ (!L.value || !u.cellHasValue(L.value)) && c.setValue(L.row, L.col, {
63
63
  f: `=SUM(${Se({
64
- startColumn: p.col,
65
- endColumn: p.col,
64
+ startColumn: L.col,
65
+ endColumn: L.col,
66
66
  startRow: f.startRow,
67
- endRow: p.row - 1
67
+ endRow: L.row - 1
68
68
  })})`
69
69
  });
70
- const L = It({
70
+ const p = It({
71
71
  startRow: f.startRow,
72
72
  startColumn: f.endColumn,
73
73
  endRow: f.endRow,
74
74
  endColumn: f.endColumn
75
75
  }, u);
76
- if (!fe.equals(L, f))
77
- for (const p of u.iterateByRow(L))
78
- (!p.value || !u.cellHasValue(p.value)) && c.setValue(p.row, p.col, {
76
+ if (!fe.equals(p, f))
77
+ for (const L of u.iterateByRow(p))
78
+ (!L.value || !u.cellHasValue(L.value)) && c.setValue(L.row, L.col, {
79
79
  f: `=SUM(${Se({
80
80
  startColumn: f.startColumn,
81
- endColumn: p.col - 1,
82
- startRow: p.row,
83
- endRow: p.row
81
+ endColumn: L.col - 1,
82
+ startRow: L.row,
83
+ endRow: L.row
84
84
  })})`
85
85
  });
86
86
  const E = a.get(ue);
@@ -139,8 +139,8 @@ let Ze = class extends ee {
139
139
  i.map((u) => this._getImageNatureSize(u))
140
140
  ), o = {};
141
141
  r.forEach((u) => {
142
- const { unitId: m, sheetId: f, row: c, column: l, ...L } = u;
143
- o[m] || (o[m] = {}), o[m][f] || (o[m][f] = new V()), o[m][f].setValue(c, l, L);
142
+ const { unitId: m, sheetId: f, row: c, column: l, ...p } = u;
143
+ o[m] || (o[m] = {}), o[m][f] || (o[m][f] = new V()), o[m][f].setValue(c, l, p);
144
144
  }), this._formulaDataModel.mergeUnitImageFormulaData(o), this._refreshRender();
145
145
  }
146
146
  })
@@ -162,15 +162,15 @@ let Ze = class extends ee {
162
162
  source: l,
163
163
  // altText,
164
164
  // sizing,
165
- height: L,
165
+ height: p,
166
166
  width: E,
167
- isErrorImage: p,
167
+ isErrorImage: L,
168
168
  imageNaturalWidth: S,
169
169
  imageNaturalHeight: A
170
170
  } = c;
171
- if (p)
171
+ if (L)
172
172
  return i(this._errorValueCell);
173
- const I = E || S, d = L || A, R = Qa("", {}), N = {
173
+ const I = E || S, d = p || A, R = Qa("", {}), N = {
174
174
  unitId: r,
175
175
  subUnitId: o,
176
176
  drawingId: la(),
@@ -357,8 +357,8 @@ let xe = class extends ee {
357
357
  const l = this._activeDirtyManagerService.get(c.id);
358
358
  if (l == null)
359
359
  continue;
360
- const L = l.getDirtyData(c), { dirtyRanges: E, dirtyNameMap: p, dirtyDefinedNameMap: S, dirtyUnitFeatureMap: A, dirtyUnitOtherFormulaMap: I, clearDependencyTreeCache: d, forceCalculation: R = !1 } = L;
361
- E != null && this._mergeDirtyRanges(n, E), p != null && this._mergeDirtyNameMap(i, p), S != null && this._mergeDirtyNameMap(r, S), A != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(o, A), I != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(u, I), d != null && this._mergeDirtyNameMap(m, d), f = f || R;
360
+ const p = l.getDirtyData(c), { dirtyRanges: E, dirtyNameMap: L, dirtyDefinedNameMap: S, dirtyUnitFeatureMap: A, dirtyUnitOtherFormulaMap: I, clearDependencyTreeCache: d, forceCalculation: R = !1 } = p;
361
+ E != null && this._mergeDirtyRanges(n, E), L != null && this._mergeDirtyNameMap(i, L), S != null && this._mergeDirtyNameMap(r, S), A != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(o, A), I != null && this._mergeDirtyUnitFeatureOrOtherFormulaMap(u, I), d != null && this._mergeDirtyNameMap(m, d), f = f || R;
362
362
  }
363
363
  return {
364
364
  dirtyRanges: n,
@@ -395,8 +395,8 @@ let xe = class extends ee {
395
395
  let r = !1;
396
396
  for (const o of e)
397
397
  if (i.unitId === o.unitId && i.sheetId === o.sheetId) {
398
- const { startRow: u, startColumn: m, endRow: f, endColumn: c } = i.range, { startRow: l, startColumn: L, endRow: E, endColumn: p } = o.range;
399
- if (u === l && m === L && f === E && c === p) {
398
+ const { startRow: u, startColumn: m, endRow: f, endColumn: c } = i.range, { startRow: l, startColumn: p, endRow: E, endColumn: L } = o.range;
399
+ if (u === l && m === p && f === E && c === L) {
400
400
  r = !0;
401
401
  break;
402
402
  }
@@ -554,27 +554,27 @@ function Oi(a, e) {
554
554
  if (o == null || u == null)
555
555
  return !0;
556
556
  Object.keys(o).forEach((m) => {
557
- const f = new V(o[m] || {}), c = new V(u[m] || {}), l = new V(), L = new V();
557
+ const f = new V(o[m] || {}), c = new V(u[m] || {}), l = new V(), p = new V();
558
558
  if (f.forValue((I, d, R) => {
559
559
  if (R == null)
560
560
  return !0;
561
561
  const N = _e(R);
562
- N !== null && (l.setValue(I, d, N), L.setValue(I, d, c.getValue(I, d)));
562
+ N !== null && (l.setValue(I, d, N), p.setValue(I, d, c.getValue(I, d)));
563
563
  }), l.getSizeOf() === 0)
564
564
  return;
565
565
  const E = {
566
566
  subUnitId: m,
567
567
  unitId: r,
568
568
  cellValue: l.getMatrix()
569
- }, p = {
569
+ }, L = {
570
570
  id: j.id,
571
571
  params: E
572
572
  };
573
- i.push(p);
573
+ i.push(L);
574
574
  const S = {
575
575
  subUnitId: m,
576
576
  unitId: r,
577
- cellValue: L.getMatrix()
577
+ cellValue: p.getMatrix()
578
578
  }, A = {
579
579
  id: j.id,
580
580
  params: S
@@ -631,10 +631,10 @@ function xi(a, e, n) {
631
631
  ...Object.keys(e[f] || {})
632
632
  ])).forEach((l) => {
633
633
  var R, N;
634
- const L = (R = a[f]) == null ? void 0 : R[l], E = (N = e[f]) == null ? void 0 : N[l], p = new V(L || {}), S = new V(E || {});
634
+ const p = (R = a[f]) == null ? void 0 : R[l], E = (N = e[f]) == null ? void 0 : N[l], L = new V(p || {}), S = new V(E || {});
635
635
  let A = [];
636
- f !== o || l !== u ? A = yi(S) : A = _i(p, S, n);
637
- const I = Wi(A, p, S), d = Ki(A, p);
636
+ f !== o || l !== u ? A = yi(S) : A = _i(L, S, n);
637
+ const I = Wi(A, L, S), d = Ki(A, L);
638
638
  i[f] || (i[f] = {}), r[f] || (r[f] = {}), i[f][l] = {
639
639
  ...i[f][l],
640
640
  ...I
@@ -652,22 +652,22 @@ function _i(a, e, n) {
652
652
  const { type: i, from: r, to: o, range: u } = n, m = [];
653
653
  return a.forValue((f, c, l) => {
654
654
  if (l == null || !va(l)) return !0;
655
- const L = da(f, c);
656
- let E = null, p = !1;
655
+ const p = da(f, c);
656
+ let E = null, L = !1;
657
657
  if ([
658
658
  0,
659
659
  1,
660
660
  2
661
661
  /* MoveCols */
662
662
  ].includes(i))
663
- E = gi(i, r, o, L);
663
+ E = gi(i, r, o, p);
664
664
  else if (u != null) {
665
- const S = qi(L, n);
666
- E = S.newCell, p = S.isReverse;
665
+ const S = qi(p, n);
666
+ E = S.newCell, L = S.isReverse;
667
667
  }
668
- if (Xe.diffValue(L, E) && !e.getValue(f, c))
668
+ if (Xe.diffValue(p, E) && !e.getValue(f, c))
669
669
  return !0;
670
- p ? m.unshift({ oldCell: L, newCell: E }) : m.push({ oldCell: L, newCell: E });
670
+ L ? m.unshift({ oldCell: p, newCell: E }) : m.push({ oldCell: p, newCell: E });
671
671
  }), m;
672
672
  }
673
673
  function yi(a) {
@@ -840,8 +840,8 @@ function Wi(a, e, n) {
840
840
  for (let m = 0; m < a.length; m++) {
841
841
  const { oldCell: f, newCell: c } = a[m];
842
842
  if ((r = i.getValue(f.startRow, f.startColumn)) != null && r.f || (o = i.getValue(f.startRow, f.startColumn)) != null && o.si || i.setValue(f.startRow, f.startColumn, { f: null, si: null }), c) {
843
- const l = (u = n.getValue(f.startRow, f.startColumn)) != null ? u : e.getValue(f.startRow, f.startColumn), L = _e(l);
844
- i.setValue(c.startRow, c.startColumn, L);
843
+ const l = (u = n.getValue(f.startRow, f.startColumn)) != null ? u : e.getValue(f.startRow, f.startColumn), p = _e(l);
844
+ i.setValue(c.startRow, c.startColumn, p);
845
845
  }
846
846
  }
847
847
  return i.getMatrix();
@@ -902,13 +902,13 @@ function Ga(a, e, n = 0, i = 0) {
902
902
  r.push(m);
903
903
  continue;
904
904
  }
905
- const { token: f } = m, c = Pe(f), { range: l, sheetName: L, unitId: E } = c, p = fe.moveOffset(l, n, i);
905
+ const { token: f } = m, c = Pe(f), { range: l, sheetName: p, unitId: E } = c, L = fe.moveOffset(l, n, i);
906
906
  r.push({
907
907
  ...m,
908
908
  token: st({
909
- range: p,
909
+ range: L,
910
910
  unitId: E,
911
- sheetName: L
911
+ sheetName: p
912
912
  })
913
913
  });
914
914
  }
@@ -916,9 +916,9 @@ function Ga(a, e, n = 0, i = 0) {
916
916
  }
917
917
  function Ha(a, e, n, i) {
918
918
  const { type: r, unitId: o, sheetId: u, range: m, from: f, to: c, rangeFilteredRows: l } = e, {
919
- range: L,
919
+ range: p,
920
920
  sheetId: E,
921
- unitId: p,
921
+ unitId: L,
922
922
  sheetName: S,
923
923
  refOffsetX: A,
924
924
  refOffsetY: I
@@ -928,11 +928,11 @@ function Ha(a, e, n, i) {
928
928
  u,
929
929
  n,
930
930
  i,
931
- p,
931
+ L,
932
932
  E
933
933
  ))
934
934
  return;
935
- const d = fe.moveOffset(L, A, I);
935
+ const d = fe.moveOffset(p, A, I);
936
936
  let R = null;
937
937
  if (r === y.MoveRange) {
938
938
  if (f == null || c == null)
@@ -1110,14 +1110,14 @@ function Ha(a, e, n, i) {
1110
1110
  return st({
1111
1111
  range: R,
1112
1112
  sheetName: S,
1113
- unitId: p
1113
+ unitId: L
1114
1114
  });
1115
1115
  }
1116
1116
  function Dt(a, e, n, i, r, o) {
1117
1117
  const { startRow: u, endRow: m, startColumn: f, endColumn: c, rangeType: l } = Oe(e), {
1118
- startRow: L,
1118
+ startRow: p,
1119
1119
  startColumn: E,
1120
- endRow: p,
1120
+ endRow: L,
1121
1121
  endColumn: S,
1122
1122
  rangeType: A = X.NORMAL
1123
1123
  } = Oe(n), { startRow: I, startColumn: d, endRow: R, endColumn: N } = Oe(i), {
@@ -1143,7 +1143,7 @@ function Dt(a, e, n, i, r, o) {
1143
1143
  if (u < h)
1144
1144
  O.startRow = u;
1145
1145
  else if (u >= x)
1146
- O.endRow -= p + 1 - h;
1146
+ O.endRow -= L + 1 - h;
1147
1147
  else
1148
1148
  return;
1149
1149
  else
@@ -1153,7 +1153,7 @@ function Dt(a, e, n, i, r, o) {
1153
1153
  if (m > x)
1154
1154
  O.endRow = m;
1155
1155
  else if (m <= h)
1156
- O.startRow += x - L + 1;
1156
+ O.startRow += x - p + 1;
1157
1157
  else
1158
1158
  return;
1159
1159
  else
@@ -1178,7 +1178,7 @@ function Dt(a, e, n, i, r, o) {
1178
1178
  return;
1179
1179
  else
1180
1180
  return;
1181
- else a === 4 ? (O.startRow = u, O.startColumn = f, O.endRow = m, O.endColumn = c) : E <= F && S >= B || A === X.ROW && ae === X.ROW ? n.endRow < h ? (I >= h && (O.startRow -= p - L + 1), I >= x && (O.endRow -= p - L + 1)) : n.startRow > x ? (R <= x && (O.endRow += p - L + 1), R <= h && (O.startRow += p - L + 1)) : n.startRow >= h && n.endRow <= x && (I <= h ? O.startRow += p - L + 1 : I >= x && (O.endRow -= p - L + 1)) : L <= h && p >= x || A === X.COLUMN && ae === X.COLUMN ? n.endColumn < F ? (d >= F && (O.startColumn -= S - E + 1), d >= B && (O.endColumn -= S - E + 1)) : n.startColumn > B ? (N <= B && (O.endColumn += S - E + 1), N <= F && (O.startColumn += S - E + 1)) : n.startColumn >= F && n.endColumn <= B && (d <= F ? O.startColumn += S - E + 1 : d >= B && (O.endColumn -= S - E + 1)) : ((d <= U + 1 && N >= B || d <= F && N >= M - 1) && I <= h && R >= x || (I <= q + 1 && R >= x || I <= h && R >= P - 1) && d <= F && N >= B, O.startRow = u, O.startColumn = f, O.endRow = m, O.endColumn = c);
1181
+ else a === 4 ? (O.startRow = u, O.startColumn = f, O.endRow = m, O.endColumn = c) : E <= F && S >= B || A === X.ROW && ae === X.ROW ? n.endRow < h ? (I >= h && (O.startRow -= L - p + 1), I >= x && (O.endRow -= L - p + 1)) : n.startRow > x ? (R <= x && (O.endRow += L - p + 1), R <= h && (O.startRow += L - p + 1)) : n.startRow >= h && n.endRow <= x && (I <= h ? O.startRow += L - p + 1 : I >= x && (O.endRow -= L - p + 1)) : p <= h && L >= x || A === X.COLUMN && ae === X.COLUMN ? n.endColumn < F ? (d >= F && (O.startColumn -= S - E + 1), d >= B && (O.endColumn -= S - E + 1)) : n.startColumn > B ? (N <= B && (O.endColumn += S - E + 1), N <= F && (O.startColumn += S - E + 1)) : n.startColumn >= F && n.endColumn <= B && (d <= F ? O.startColumn += S - E + 1 : d >= B && (O.endColumn -= S - E + 1)) : ((d <= U + 1 && N >= B || d <= F && N >= M - 1) && I <= h && R >= x || (I <= q + 1 && R >= x || I <= h && R >= P - 1) && d <= F && N >= B, O.startRow = u, O.startColumn = f, O.endRow = m, O.endColumn = c);
1182
1182
  return O;
1183
1183
  }
1184
1184
  function bt(a, e) {
@@ -1186,13 +1186,13 @@ function bt(a, e) {
1186
1186
  function l() {
1187
1187
  return a.rangeType === X.COLUMN && e.rangeType === X.COLUMN ? !0 : n >= u && i <= m;
1188
1188
  }
1189
- function L() {
1189
+ function p() {
1190
1190
  return a.rangeType === X.ROW && e.rangeType === X.ROW ? !0 : r >= f && o <= c;
1191
1191
  }
1192
1192
  function E() {
1193
1193
  return a.rangeType === X.ALL && e.rangeType === X.ALL;
1194
1194
  }
1195
- return l() && L() || E() ? 4 : L() && n >= u && n <= m && i > m ? 0 : L() && i >= u && i <= m && n < u ? 1 : l() && r >= f && r <= c && o > c ? 2 : l() && o >= f && o <= c && r < f ? 3 : null;
1195
+ return l() && p() || E() ? 4 : p() && n >= u && n <= m && i > m ? 0 : p() && i >= u && i <= m && n < u ? 1 : l() && r >= f && r <= c && o > c ? 2 : l() && o >= f && o <= c && r < f ? 3 : null;
1196
1196
  }
1197
1197
  function Ne(a) {
1198
1198
  return isNaN(a) ? -1 / 0 : a;
@@ -1298,7 +1298,7 @@ function ji(a, e) {
1298
1298
  endRow: r,
1299
1299
  endColumn: f.getColumnCount() - 1,
1300
1300
  rangeType: X.ROW
1301
- }, L = {
1301
+ }, p = {
1302
1302
  startRow: o,
1303
1303
  startColumn: 0,
1304
1304
  endRow: u,
@@ -1308,7 +1308,7 @@ function ji(a, e) {
1308
1308
  return {
1309
1309
  type: y.MoveRows,
1310
1310
  from: l,
1311
- to: L,
1311
+ to: p,
1312
1312
  unitId: m,
1313
1313
  sheetId: c
1314
1314
  };
@@ -1327,7 +1327,7 @@ function $i(a, e) {
1327
1327
  endRow: f.getRowCount() - 1,
1328
1328
  endColumn: r,
1329
1329
  rangeType: X.COLUMN
1330
- }, L = {
1330
+ }, p = {
1331
1331
  startRow: 0,
1332
1332
  startColumn: o,
1333
1333
  endRow: f.getRowCount() - 1,
@@ -1337,7 +1337,7 @@ function $i(a, e) {
1337
1337
  return {
1338
1338
  type: y.MoveCols,
1339
1339
  from: l,
1340
- to: L,
1340
+ to: p,
1341
1341
  unitId: m,
1342
1342
  sheetId: c
1343
1343
  };
@@ -1527,7 +1527,7 @@ let Je = class extends ee {
1527
1527
  const { formulaOrRefString: c } = f, l = this._lexerTreeBuilder.sequenceNodesBuilder(c);
1528
1528
  if (l == null)
1529
1529
  return !0;
1530
- let L = !1;
1530
+ let p = !1;
1531
1531
  const E = [];
1532
1532
  for (let d = 0, R = l.length; d < R; d++) {
1533
1533
  const N = l[d];
@@ -1566,16 +1566,16 @@ let Je = class extends ee {
1566
1566
  B != null && (l[d] = {
1567
1567
  ...N,
1568
1568
  token: B
1569
- }, L = !0, E.push(d));
1569
+ }, p = !0, E.push(d));
1570
1570
  }
1571
- if (!L)
1571
+ if (!p)
1572
1572
  return !0;
1573
- const p = $e(Ga(l, E)), S = {
1573
+ const L = $e(Ga(l, E)), S = {
1574
1574
  id: Ae.id,
1575
1575
  params: {
1576
1576
  unitId: i,
1577
1577
  ...f,
1578
- formulaOrRefString: p
1578
+ formulaOrRefString: L
1579
1579
  }
1580
1580
  };
1581
1581
  u.push(S);
@@ -1716,9 +1716,9 @@ let et = class extends ee {
1716
1716
  var f;
1717
1717
  const e = {}, n = a.getUnitId(), i = { [n]: {} };
1718
1718
  a.getSheets().forEach((c) => {
1719
- var p;
1720
- const l = c.getCellMatrix(), L = c.getSheetId(), E = na(e, n, L, l);
1721
- i[n][L] = (p = E[n]) == null ? void 0 : p[L];
1719
+ var L;
1720
+ const l = c.getCellMatrix(), p = c.getSheetId(), E = na(e, n, p, l);
1721
+ i[n][p] = (L = E[n]) == null ? void 0 : L[p];
1722
1722
  }), this._commandService.executeCommand(ve.id, { formulaData: i }, { onlyLocal: !0 });
1723
1723
  const o = this._configService.getConfig(ge), u = (f = o == null ? void 0 : o.initialFormulaComputing) != null ? f : Te.WHEN_EMPTY, m = this._getDirtyDataByCalculationMode(u);
1724
1724
  this._commandService.executeCommand(je.id, m, { onlyLocal: !0 });
@@ -1772,8 +1772,8 @@ let et = class extends ee {
1772
1772
  const f = Object.keys(m);
1773
1773
  Xe.isDefine(r[u]) || (r[u] = {}), Xe.isDefine(o[u]) || (o[u] = {});
1774
1774
  for (const c of f) {
1775
- const l = new V(m[c] || {}), L = new V(), E = [];
1776
- l.forValue((p, S, A) => {
1775
+ const l = new V(m[c] || {}), p = new V(), E = [];
1776
+ l.forValue((L, S, A) => {
1777
1777
  var F;
1778
1778
  if (!A) return !0;
1779
1779
  const { f: I, x: d, y: R, si: N } = A, P = this._lexerTreeBuilder.sequenceNodesBuilder(I);
@@ -1854,17 +1854,17 @@ let et = class extends ee {
1854
1854
  }
1855
1855
  if (!q)
1856
1856
  if (N && [y.MoveRows, y.MoveCols, y.MoveRange].includes(U)) {
1857
- if (h && h.startRow <= p && p <= h.endRow && h.startColumn <= S && S <= h.endColumn)
1857
+ if (h && h.startRow <= L && L <= h.endRow && h.startColumn <= S && S <= h.endColumn)
1858
1858
  (d != null ? d : 0) === 0 && (R != null ? R : 0) === 0 && E.push(N);
1859
1859
  else if (!E.includes(N))
1860
1860
  return !0;
1861
1861
  } else
1862
1862
  return !0;
1863
1863
  const x = Ga(P, M, d, R);
1864
- L.setValue(p, S, {
1864
+ p.setValue(L, S, {
1865
1865
  f: `=${$e(x)}`
1866
1866
  });
1867
- }), o[u] && (o[u][c] = L.getData());
1867
+ }), o[u] && (o[u][c] = p.getData());
1868
1868
  }
1869
1869
  }
1870
1870
  return { newFormulaData: o };
@@ -2109,15 +2109,15 @@ let tt = class extends ee {
2109
2109
  _getRemoveRowOrColumnMutation(a, e = !0) {
2110
2110
  const { subUnitId: n, unitId: i, range: r } = a, o = [], u = this._univerInstanceService.getUniverSheetInstance(i), m = u == null ? void 0 : u.getSheetBySheetId(n), f = (m == null ? void 0 : m.getRowCount()) || 0, c = (m == null ? void 0 : m.getColumnCount()) || 0;
2111
2111
  let l = null;
2112
- const { startRow: L, endRow: E, startColumn: p, endColumn: S } = r;
2112
+ const { startRow: p, endRow: E, startColumn: L, endColumn: S } = r;
2113
2113
  e === !0 ? l = this._rangeToMatrix({
2114
- startRow: L,
2114
+ startRow: p,
2115
2115
  startColumn: 0,
2116
2116
  endRow: E,
2117
2117
  endColumn: c - 1
2118
2118
  }) : l = this._rangeToMatrix({
2119
2119
  startRow: 0,
2120
- startColumn: p,
2120
+ startColumn: L,
2121
2121
  endRow: f,
2122
2122
  endColumn: S
2123
2123
  });
@@ -2165,10 +2165,10 @@ let tt = class extends ee {
2165
2165
  if ((u = o == null ? void 0 : o[a]) != null && u[e]) {
2166
2166
  const f = new V((m = o == null ? void 0 : o[a]) == null ? void 0 : m[e]);
2167
2167
  r.forValue((c, l) => {
2168
- f.forValue((L, E, p) => {
2169
- if (p == null)
2168
+ f.forValue((p, E, L) => {
2169
+ if (L == null)
2170
2170
  return !0;
2171
- const { startRow: S, startColumn: A, endRow: I, endColumn: d } = p;
2171
+ const { startRow: S, startColumn: A, endRow: I, endColumn: d } = L;
2172
2172
  c >= S && c <= I && l >= A && l <= d && i.push({
2173
2173
  unitId: a,
2174
2174
  sheetId: e,
@@ -2244,16 +2244,16 @@ let at = class extends ee {
2244
2244
  return;
2245
2245
  const u = new V();
2246
2246
  new V(o).forValue((f, c, l) => {
2247
- const L = l == null ? void 0 : l.f;
2248
- if ((l == null ? void 0 : l.x) != null || !L || L.length === 0)
2247
+ const p = l == null ? void 0 : l.f;
2248
+ if ((l == null ? void 0 : l.x) != null || !p || p.length === 0)
2249
2249
  return;
2250
- if (e.has(L)) {
2251
- const p = e.get(L);
2252
- u.setValue(f, c, { xf: p });
2250
+ if (e.has(p)) {
2251
+ const L = e.get(p);
2252
+ u.setValue(f, c, { xf: L });
2253
2253
  return;
2254
2254
  }
2255
- const E = this._lexerTreeBuilder.getNewFormulaWithPrefix(L, this._functionService.hasExecutor.bind(this._functionService));
2256
- E && (u.setValue(f, c, { xf: E }), e.set(L, E));
2255
+ const E = this._lexerTreeBuilder.getNewFormulaWithPrefix(p, this._functionService.hasExecutor.bind(this._functionService));
2256
+ E && (u.setValue(f, c, { xf: E }), e.set(p, E));
2257
2257
  }), this._commandService.executeCommand(j.id, {
2258
2258
  unitId: n,
2259
2259
  subUnitId: r,
@@ -2269,8 +2269,8 @@ let at = class extends ee {
2269
2269
  a && Object.entries(a).forEach(([i, r]) => {
2270
2270
  r && Array.from(Object.entries(r)).forEach(([o, u]) => {
2271
2271
  const m = new V();
2272
- new V(u).forValue((c, l, L) => {
2273
- m.setValue(c, l, { ref: Se(L) });
2272
+ new V(u).forValue((c, l, p) => {
2273
+ m.setValue(c, l, { ref: Se(p) });
2274
2274
  }), this._commandService.executeCommand(j.id, {
2275
2275
  unitId: i,
2276
2276
  subUnitId: o,
@@ -2284,8 +2284,8 @@ let at = class extends ee {
2284
2284
  r && Array.from(Object.entries(r)).forEach(([o, u]) => {
2285
2285
  const m = new V();
2286
2286
  new V(u).forValue((c, l) => {
2287
- var E, p, S;
2288
- (S = (p = (E = a == null ? void 0 : a[i]) == null ? void 0 : E[o]) == null ? void 0 : p[c]) != null && S[l] || m.setValue(c, l, {
2287
+ var E, L, S;
2288
+ (S = (L = (E = a == null ? void 0 : a[i]) == null ? void 0 : E[o]) == null ? void 0 : L[c]) != null && S[l] || m.setValue(c, l, {
2289
2289
  ref: Se({
2290
2290
  startRow: c,
2291
2291
  endRow: c,
@@ -2321,9 +2321,9 @@ let at = class extends ee {
2321
2321
  priority: 100,
2322
2322
  effect: _t.Value,
2323
2323
  handler: (a, e, n) => {
2324
- var l, L, E;
2324
+ var l, p, E;
2325
2325
  let i = a;
2326
- const { unitId: r, subUnitId: o, row: u, col: m } = e, f = this._formulaDataModel.getArrayFormulaCellData(), c = (E = (L = (l = f == null ? void 0 : f[r]) == null ? void 0 : l[o]) == null ? void 0 : L[u]) == null ? void 0 : E[m];
2326
+ const { unitId: r, subUnitId: o, row: u, col: m } = e, f = this._formulaDataModel.getArrayFormulaCellData(), c = (E = (p = (l = f == null ? void 0 : f[r]) == null ? void 0 : l[o]) == null ? void 0 : p[u]) == null ? void 0 : E[m];
2327
2327
  return c == null ? n(i) : ((!i || i === e.rawData) && (i = { ...e.rawData }), c.v == null && c.t == null ? (i.v = 0, i.t = xt.NUMBER, n(i)) : (i == null ? void 0 : i.t) === xt.NUMBER && i.v !== void 0 && i.v !== null && rn(i.v) ? (i.v = vn(Number(i.v)), n(i)) : (i.v = c.v, i.t = c.t, n(i)));
2328
2328
  }
2329
2329
  })
@@ -16067,12 +16067,12 @@ function fa(a, e, n, i) {
16067
16067
  const f = r[u];
16068
16068
  if (typeof f == "string" || f.nodeType !== ie.REFERENCE)
16069
16069
  continue;
16070
- const { token: c } = f, l = Pe(c), { sheetName: L, unitId: E } = l;
16071
- let p = l.range;
16072
- p.startAbsoluteRefType === Qe.ALL && p.endAbsoluteRefType === Qe.ALL || (p = yt(p, n, i), o.push({
16070
+ const { token: c } = f, l = Pe(c), { sheetName: p, unitId: E } = l;
16071
+ let L = l.range;
16072
+ L.startAbsoluteRefType === Qe.ALL && L.endAbsoluteRefType === Qe.ALL || (L = yt(L, n, i), o.push({
16073
16073
  unitId: E,
16074
- sheetName: L,
16075
- range: p
16074
+ sheetName: p,
16075
+ range: L
16076
16076
  }));
16077
16077
  }
16078
16078
  return o.map((u) => `${u.unitId}!${u.sheetName}!${u.range.startRow}!${u.range.endRow}!${u.range.startColumn}!${u.range.endColumn}`).join("|");
@@ -16084,7 +16084,7 @@ let vt = class extends ee {
16084
16084
  transformFormulaByEffectCommand(a, e, n, i) {
16085
16085
  const r = this._lexerTreeBuilder.sequenceNodesBuilder(n), o = this._univerInstanceService.getCurrentUnitForType(k.UNIVER_SHEET), u = o.getActiveSheet(), m = o.getUnitId(), f = u.getSheetId(), c = r == null ? void 0 : r.map((l) => {
16086
16086
  if (typeof l == "object" && l.nodeType === ie.REFERENCE) {
16087
- const L = Pe(l.token), { range: E, unitId: p, sheetName: S } = L, A = this._univerInstanceService.getUnit(p || a), I = S ? A == null ? void 0 : A.getSheetBySheetName(S) : A == null ? void 0 : A.getSheetBySheetId(e);
16087
+ const p = Pe(l.token), { range: E, unitId: L, sheetName: S } = p, A = this._univerInstanceService.getUnit(L || a), I = S ? A == null ? void 0 : A.getSheetBySheetName(S) : A == null ? void 0 : A.getSheetBySheetId(e);
16088
16088
  if (!I)
16089
16089
  throw new Error("Sheet not found");
16090
16090
  const d = A.getUnitId(), R = I.getSheetId();
@@ -16094,7 +16094,7 @@ let vt = class extends ee {
16094
16094
  let P = "";
16095
16095
  if (N) {
16096
16096
  const q = N.startColumn - E.startColumn, M = N.startRow - E.startRow, U = yt(E, q, M);
16097
- p && S ? P = ra(p, S, U) : S ? P = ze(S, U) : P = Se(U);
16097
+ L && S ? P = ra(L, S, U) : S ? P = ze(S, U) : P = Se(U);
16098
16098
  } else
16099
16099
  P = Q.REF;
16100
16100
  return {
@@ -16108,10 +16108,10 @@ let vt = class extends ee {
16108
16108
  }
16109
16109
  registerFormula(a, e, n, i) {
16110
16110
  const r = /* @__PURE__ */ new Map(), o = this._lexerTreeBuilder.sequenceNodesBuilder(n), u = new ke(), m = (f) => {
16111
- const c = this._univerInstanceService.getCurrentUnitForType(k.UNIVER_SHEET), l = c.getActiveSheet(), L = c.getUnitId(), E = l.getSheetId(), p = o == null ? void 0 : o.map((A) => {
16111
+ const c = this._univerInstanceService.getCurrentUnitForType(k.UNIVER_SHEET), l = c.getActiveSheet(), p = c.getUnitId(), E = l.getSheetId(), L = o == null ? void 0 : o.map((A) => {
16112
16112
  if (typeof A == "object" && A.nodeType === ie.REFERENCE) {
16113
16113
  const I = r.get(A.token);
16114
- if (I.unitId !== L || I.subUnitId !== E)
16114
+ if (I.unitId !== p || I.subUnitId !== E)
16115
16115
  return A;
16116
16116
  const d = ta(I.range, f);
16117
16117
  let R = "";
@@ -16126,15 +16126,15 @@ let vt = class extends ee {
16126
16126
  };
16127
16127
  } else
16128
16128
  return A;
16129
- }), S = p && $e(p);
16129
+ }), S = L && $e(L);
16130
16130
  return i(`=${S}`);
16131
16131
  };
16132
16132
  return o == null || o.forEach((f) => {
16133
16133
  if (typeof f == "object" && f.nodeType === ie.REFERENCE) {
16134
- const c = Pe(f.token), { range: l, unitId: L, sheetName: E } = c, p = this._univerInstanceService.getUnit(L || a), S = E ? p == null ? void 0 : p.getSheetBySheetName(E) : p == null ? void 0 : p.getSheetBySheetId(e);
16134
+ const c = Pe(f.token), { range: l, unitId: p, sheetName: E } = c, L = this._univerInstanceService.getUnit(p || a), S = E ? L == null ? void 0 : L.getSheetBySheetName(E) : L == null ? void 0 : L.getSheetBySheetId(e);
16135
16135
  if (!S)
16136
16136
  return;
16137
- const A = p.getUnitId(), I = S.getSheetId(), d = {
16137
+ const A = L.getUnitId(), I = S.getSheetId(), d = {
16138
16138
  unitId: A,
16139
16139
  subUnitId: I,
16140
16140
  range: l,
@@ -16151,17 +16151,17 @@ let vt = class extends ee {
16151
16151
  const m = Pe(u.token), { range: f, unitId: c, sheetName: l } = m;
16152
16152
  if (f.startAbsoluteRefType === Qe.ALL && f.endAbsoluteRefType === Qe.ALL)
16153
16153
  return;
16154
- const L = this._univerInstanceService.getUnit(c || a), E = l ? L == null ? void 0 : L.getSheetBySheetName(l) : L == null ? void 0 : L.getSheetBySheetId(e);
16154
+ const p = this._univerInstanceService.getUnit(c || a), E = l ? p == null ? void 0 : p.getSheetBySheetName(l) : p == null ? void 0 : p.getSheetBySheetId(e);
16155
16155
  if (!E)
16156
16156
  return;
16157
- const p = L.getUnitId(), S = E.getSheetId(), A = i[0].startRow, I = i[0].startColumn, d = f.startRow, R = f.startColumn, N = i.map((P) => ({
16157
+ const L = p.getUnitId(), S = E.getSheetId(), A = i[0].startRow, I = i[0].startColumn, d = f.startRow, R = f.startColumn, N = i.map((P) => ({
16158
16158
  startRow: P.startRow - A + d,
16159
16159
  endRow: P.endRow - A + d,
16160
16160
  startColumn: P.startColumn - I + R,
16161
16161
  endColumn: P.endColumn - I + R
16162
16162
  }));
16163
16163
  o.push({
16164
- unitId: p,
16164
+ unitId: L,
16165
16165
  subUnitId: S,
16166
16166
  ranges: N
16167
16167
  });
@@ -16171,15 +16171,21 @@ let vt = class extends ee {
16171
16171
  // eslint-disable-next-line max-lines-per-function
16172
16172
  registerRangeFormula(a, e, n, i, r) {
16173
16173
  const o = new ke(), u = i.map((f) => this._getFormulaDependcy(a, e, f, n)), m = (f) => {
16174
- const c = n[0].startRow, l = n[0].startColumn, L = [{ unitId: a, subUnitId: e, ranges: n }, ...u.flat()], E = [], p = Mn(this._injector, f);
16175
- for (const { unitId: S, subUnitId: A, ranges: I } of L)
16176
- if (S === p.unitId && A === p.subUnitId) {
16177
- const d = [], R = I[0].startRow, N = I[0].startColumn, P = R - c, q = N - l;
16178
- for (const M of p.ranges) {
16174
+ const c = Mn(this._injector, f);
16175
+ if (!c)
16176
+ return {
16177
+ undos: [],
16178
+ redos: []
16179
+ };
16180
+ const l = n[0].startRow, p = n[0].startColumn, E = [{ unitId: a, subUnitId: e, ranges: n }, ...u.flat()], L = [];
16181
+ for (const { unitId: S, subUnitId: A, ranges: I } of E)
16182
+ if (S === c.unitId && A === c.subUnitId) {
16183
+ const d = [], R = I[0].startRow, N = I[0].startColumn, P = R - l, q = N - p;
16184
+ for (const M of c.ranges) {
16179
16185
  const U = I.map((h) => We(M, h)).filter(Boolean);
16180
16186
  U.length > 0 && d.push(...U);
16181
16187
  }
16182
- d.length > 0 && E.push(
16188
+ d.length > 0 && L.push(
16183
16189
  d.map((M) => ({
16184
16190
  startRow: M.startRow - P,
16185
16191
  endRow: M.endRow - P,
@@ -16188,15 +16194,15 @@ let vt = class extends ee {
16188
16194
  }))
16189
16195
  );
16190
16196
  }
16191
- if (E.length > 0) {
16192
- const S = fe.splitIntoGrid([...E.flat()]), A = fe.subtractMulti(n, S);
16197
+ if (L.length > 0) {
16198
+ const S = fe.splitIntoGrid([...L.flat()]), A = fe.subtractMulti(n, S);
16193
16199
  A.sort((P, q) => P.startRow - q.startRow || P.startColumn - q.startColumn);
16194
16200
  const I = /* @__PURE__ */ new Map();
16195
16201
  for (let P = 0; P < S.length; P++) {
16196
- const q = S[P], M = q.startRow, U = q.startColumn, h = M - c, x = U - l, F = xn(q, f).sort((z, re) => z.startRow - re.startRow || z.startColumn - re.startColumn);
16202
+ const q = S[P], M = q.startRow, U = q.startColumn, h = M - l, x = U - p, F = xn(q, f).sort((z, re) => z.startRow - re.startRow || z.startColumn - re.startColumn);
16197
16203
  if (!F.length)
16198
16204
  continue;
16199
- const B = F[0].startRow, ae = F[0].startColumn, O = B - c, ce = ae - l, ne = [];
16205
+ const B = F[0].startRow, ae = F[0].startColumn, O = B - l, ce = ae - p, ne = [];
16200
16206
  for (let z = 0; z < i.length; z++) {
16201
16207
  const re = i[z], oe = Me(re), qe = oe ? this._lexerTreeBuilder.moveFormulaRefOffset(re, x, h) : re, Z = oe ? this.transformFormulaByEffectCommand(a, e, qe, f) : qe, Et = fa(this._lexerTreeBuilder, Z, -ce, -O);
16202
16208
  ne.push({
@@ -16217,7 +16223,7 @@ let vt = class extends ee {
16217
16223
  for (let h = 0; h < i.length; h++) {
16218
16224
  const x = i[h];
16219
16225
  M.push({
16220
- newFormula: Me(x) ? this._lexerTreeBuilder.moveFormulaRefOffset(x, q - l, P - c) : x,
16226
+ newFormula: Me(x) ? this._lexerTreeBuilder.moveFormulaRefOffset(x, q - p, P - l) : x,
16221
16227
  orginFormula: x
16222
16228
  });
16223
16229
  }
@@ -16250,8 +16256,8 @@ let vt = class extends ee {
16250
16256
  const c = this._refRangeService.registerRefRange(f, m, a, e);
16251
16257
  o.add(c);
16252
16258
  }), [...u.flat()].forEach(({ unitId: f, subUnitId: c, ranges: l }) => {
16253
- l.forEach((L) => {
16254
- const E = this._refRangeService.registerRefRange(L, m, f, c);
16259
+ l.forEach((p) => {
16260
+ const E = this._refRangeService.registerRefRange(p, m, f, c);
16255
16261
  o.add(E);
16256
16262
  });
16257
16263
  }), o;