@ai-matrx/office 0.8.22 → 0.8.23

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.
@@ -1113,25 +1113,25 @@ function rebaseUndoStack(items, remote) {
1113
1113
  let dropped = 0;
1114
1114
  for (let i = items.length - 1; i >= 0; i--) {
1115
1115
  const item = items[i];
1116
- let ok2 = true;
1116
+ let ok3 = true;
1117
1117
  for (const list of [item.undoMutations, item.redoMutations]) {
1118
1118
  for (const m of list ?? []) {
1119
1119
  if (m.id !== RICH_TEXT_EDITING) continue;
1120
1120
  try {
1121
1121
  if (touchesPageSetup(m.params.actions) && touchesPageSetup(remote)) throw new Error("page setup");
1122
1122
  const r = transformDocsOp(m.params.actions, remote, "left");
1123
- if (isNoopDocsOp(r.op)) ok2 = false;
1123
+ if (isNoopDocsOp(r.op)) ok3 = false;
1124
1124
  else {
1125
1125
  m.params = { ...m.params, actions: r.op };
1126
1126
  delete m.params.textRanges;
1127
1127
  delete m.params.layoutState;
1128
1128
  }
1129
1129
  } catch {
1130
- ok2 = false;
1130
+ ok3 = false;
1131
1131
  }
1132
1132
  }
1133
1133
  }
1134
- if (!ok2) {
1134
+ if (!ok3) {
1135
1135
  items.splice(i, 1);
1136
1136
  dropped++;
1137
1137
  }
@@ -1693,6 +1693,8 @@ var SHEET_MUTATIONS = {
1693
1693
  "sheet.mutation.insert-sheet": covered("sheet", "index", "sheet"),
1694
1694
  "sheet.mutation.remove-sheet": covered("sheet", "sheetIndex", "sheetsLeft"),
1695
1695
  "sheet.mutation.set-worksheet-order": covered("sheet", "fromOrder", "toOrder"),
1696
+ // ── covered (C9): our own cell comment anchors (comment-anchor-transform.ts; not emitted by Univer) ──────
1697
+ "matrx.mutation.set-comment-anchor": covered("anchor", "anchorId", "cell"),
1696
1698
  "sheet.mutation.reorder-range": covered("sort", "range", "order"),
1697
1699
  // ── never travels ────────────────────────────────────────────────────────────────────────────────
1698
1700
  "formula.mutation.set-formula-calculation-start": never(FORMULA_RESULT),
@@ -2144,6 +2146,74 @@ function refSheetsFor(texts, sheets) {
2144
2146
  return Object.keys(out).length ? out : void 0;
2145
2147
  }
2146
2148
 
2149
+ // src/collab/sheets/comment-anchor-transform.ts
2150
+ var SET_SHEET_COMMENT_ANCHOR = "matrx.mutation.set-comment-anchor";
2151
+ var REMOVE_SHEET = "sheet.mutation.remove-sheet";
2152
+ function structuralAxisOp(id, params) {
2153
+ const p = params;
2154
+ switch (id) {
2155
+ case "sheet.mutation.insert-row":
2156
+ return p.range ? { axis: "row", op: { kind: "insert", at: p.range.startRow, count: p.range.endRow - p.range.startRow + 1 } } : null;
2157
+ case "sheet.mutation.remove-rows":
2158
+ return p.range ? { axis: "row", op: { kind: "remove", start: p.range.startRow, count: p.range.endRow - p.range.startRow + 1 } } : null;
2159
+ case "sheet.mutation.insert-col":
2160
+ return p.range ? { axis: "col", op: { kind: "insert", at: p.range.startColumn, count: p.range.endColumn - p.range.startColumn + 1 } } : null;
2161
+ case "sheet.mutation.remove-col":
2162
+ return p.range ? { axis: "col", op: { kind: "remove", start: p.range.startColumn, count: p.range.endColumn - p.range.startColumn + 1 } } : null;
2163
+ case "sheet.mutation.move-rows":
2164
+ return p.sourceRange && p.targetRange ? { axis: "row", op: { kind: "move", from: p.sourceRange.startRow, count: p.sourceRange.endRow - p.sourceRange.startRow + 1, to: p.targetRange.startRow } } : null;
2165
+ case "sheet.mutation.move-columns":
2166
+ return p.sourceRange && p.targetRange ? {
2167
+ axis: "col",
2168
+ op: { kind: "move", from: p.sourceRange.startColumn, count: p.sourceRange.endColumn - p.sourceRange.startColumn + 1, to: p.targetRange.startColumn }
2169
+ } : null;
2170
+ default:
2171
+ return null;
2172
+ }
2173
+ }
2174
+ function moveSheetAnchorCell(cell, sheet, id, params) {
2175
+ if (String(params.subUnitId ?? "") !== sheet) return cell;
2176
+ if (id === REMOVE_SHEET) return null;
2177
+ const s = structuralAxisOp(id, params);
2178
+ if (!s) return cell;
2179
+ if (s.axis === "row") {
2180
+ const row = mapIndex(s.op, cell.row);
2181
+ return row === null ? null : row === cell.row ? cell : { row, col: cell.col };
2182
+ }
2183
+ const col = mapIndex(s.op, cell.col);
2184
+ return col === null ? null : col === cell.col ? cell : { row: cell.row, col };
2185
+ }
2186
+ function colName(c) {
2187
+ let s = "";
2188
+ for (let n = c + 1; n > 0; n = Math.floor((n - 1) / 26)) s = String.fromCharCode(65 + (n - 1) % 26) + s;
2189
+ return s;
2190
+ }
2191
+ var sheetCellName = (cell) => `${colName(cell.col)}${cell.row + 1}`;
2192
+ function cellOf(m) {
2193
+ const c = m.params.cell;
2194
+ return c && typeof c.row === "number" && typeof c.col === "number" ? c : null;
2195
+ }
2196
+ var ok = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2197
+ var label = (m) => {
2198
+ const c = cellOf(m);
2199
+ return `${String(m.params.subUnitId ?? "")}!${c ? sheetCellName(c) : "?"} comment`;
2200
+ };
2201
+ function transformCommentAnchor(x, y, side) {
2202
+ const xa = x.id === SET_SHEET_COMMENT_ANCHOR;
2203
+ const ya = y.id === SET_SHEET_COMMENT_ANCHOR;
2204
+ if (!xa && !ya) return null;
2205
+ if (!xa) return ok([x]);
2206
+ if (ya) {
2207
+ if (x.params.anchorId !== y.params.anchorId || x.params.subUnitId !== y.params.subUnitId) return ok([x]);
2208
+ return side === "left" ? ok([x], [label(y)]) : ok([], [], [label(x)]);
2209
+ }
2210
+ const cell = cellOf(x);
2211
+ if (!cell) return ok([x]);
2212
+ const moved = moveSheetAnchorCell(cell, String(x.params.subUnitId ?? ""), y.id, y.params);
2213
+ if (!moved) return ok([], [], [label(x)]);
2214
+ return ok([moved === cell ? x : { id: x.id, params: { ...x.params, cell: moved } }]);
2215
+ }
2216
+
2147
2217
  // src/collab/sheets/transform/transform.ts
2148
2218
  var SHEET_TRANSFORMER_VERSION = "c5c-1";
2149
2219
  var ID = {
@@ -2175,16 +2245,16 @@ var ID = {
2175
2245
  var PAIR_BARRIERS = {};
2176
2246
  var pairKey = (a, b) => a < b ? `${a}|${b}` : `${b}|${a}`;
2177
2247
  var barrier2 = (reason) => ({ barrier: true, reason });
2178
- var ok = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2248
+ var ok2 = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2179
2249
  var flip = (side) => side === "left" ? "right" : "left";
2180
2250
  var sheetOf = (m) => String(m.params.subUnitId ?? "");
2181
- function colName(c) {
2251
+ function colName2(c) {
2182
2252
  let s = "";
2183
2253
  for (let n = c + 1; n > 0; n = Math.floor((n - 1) / 26)) s = String.fromCharCode(65 + (n - 1) % 26) + s;
2184
2254
  return s;
2185
2255
  }
2186
- var cellRef = (sheet, row, col) => `${sheet}!${colName(col)}${row + 1}`;
2187
- var rangeRef = (sheet, r) => `${sheet}!${colName(r.startColumn)}${r.startRow + 1}:${colName(r.endColumn)}${r.endRow + 1}`;
2256
+ var cellRef = (sheet, row, col) => `${sheet}!${colName2(col)}${row + 1}`;
2257
+ var rangeRef = (sheet, r) => `${sheet}!${colName2(r.startColumn)}${r.startRow + 1}:${colName2(r.endColumn)}${r.endRow + 1}`;
2188
2258
  function structuralOf(m) {
2189
2259
  const p = m.params;
2190
2260
  switch (m.id) {
@@ -2439,9 +2509,9 @@ function transformCell(X, Y4, side) {
2439
2509
  return { entries: Object.keys(out).length ? [out, ...tail] : tail, xLost, yLost };
2440
2510
  }
2441
2511
  function transformCellsOverCells(x, y, side) {
2442
- if (sheetOf(x) !== sheetOf(y)) return ok([x]);
2512
+ if (sheetOf(x) !== sheetOf(y)) return ok2([x]);
2443
2513
  const ycells = cellsOf(y);
2444
- if (!cellsOverlap(cellsOf(x), ycells)) return ok([x]);
2514
+ if (!cellsOverlap(cellsOf(x), ycells)) return ok2([x]);
2445
2515
  const xd = isDerived(x);
2446
2516
  const yd = isDerived(y);
2447
2517
  const eff = derivedSide(x, y, side);
@@ -2467,7 +2537,7 @@ function transformCellsOverCells(x, y, side) {
2467
2537
  });
2468
2538
  if (why) return barrier2(why);
2469
2539
  const op = passes.filter((p) => !isEmptyMatrix(p)).map((p) => cellsMutation(x, p));
2470
- return ok(op, lost, dropped);
2540
+ return ok2(op, lost, dropped);
2471
2541
  }
2472
2542
  var SIDE_CAR_PARAMS = ["refSheets", "previousName", "derived", "sheetIndex", "sheetsLeft"];
2473
2543
  var isDerived = (m) => m.params.derived === true;
@@ -2538,7 +2608,7 @@ function cellThrough(sheet, change, r, c) {
2538
2608
  return nr === null || nc === null ? null : [nr, nc];
2539
2609
  }
2540
2610
  function cellsOverChange(x, change) {
2541
- if (!hasFormula(x) && (change.kind !== "axis" || change.sheet !== sheetOf(x))) return ok([x]);
2611
+ if (!hasFormula(x) && (change.kind !== "axis" || change.sheet !== sheetOf(x))) return ok2([x]);
2542
2612
  const ctx = formulaCtx(x);
2543
2613
  const out = {};
2544
2614
  const dropped = [];
@@ -2567,9 +2637,9 @@ function cellsOverChange(x, change) {
2567
2637
  });
2568
2638
  if (why) return barrier2(why);
2569
2639
  const rsAfter = refSheetsAfter(ctx.refSheets, change);
2570
- if (!changed && JSON.stringify(rsAfter ?? null) === JSON.stringify(ctx.refSheets ?? null)) return ok([x]);
2640
+ if (!changed && JSON.stringify(rsAfter ?? null) === JSON.stringify(ctx.refSheets ?? null)) return ok2([x]);
2571
2641
  const params = { ...withRefSheets(x.params, rsAfter), cellValue: out };
2572
- return ok(isEmptyMatrix(out) ? [] : [{ id: x.id, params }], [], dropped);
2642
+ return ok2(isEmptyMatrix(out) ? [] : [{ id: x.id, params }], [], dropped);
2573
2643
  }
2574
2644
  function rewritesOf(y, change) {
2575
2645
  if (!hasFormula(y)) return null;
@@ -2616,36 +2686,36 @@ function formulaPair(x, y, side) {
2616
2686
  const fy = familyOf(y.id);
2617
2687
  const SET_NAME_BARRIER = "set-defined-name without previousName (capture must record the name it replaces) against formula text";
2618
2688
  if (fx === "defname" && fy === "defname") {
2619
- if (String(x.params.id) !== String(y.params.id)) return ok([x]);
2689
+ if (String(x.params.id) !== String(y.params.id)) return ok2([x]);
2620
2690
  const eff = derivedSide(x, y, side);
2621
- if (eff === "left") return ok([x], isDerived(y) ? [] : [`defined name "${String(y.params.name)}"`]);
2622
- return ok([], [], isDerived(x) ? [] : [`defined name "${String(x.params.name)}"`]);
2691
+ if (eff === "left") return ok2([x], isDerived(y) ? [] : [`defined name "${String(y.params.name)}"`]);
2692
+ return ok2([], [], isDerived(x) ? [] : [`defined name "${String(x.params.name)}"`]);
2623
2693
  }
2624
2694
  if (fx === "defname") {
2625
2695
  if (fy === "cell") {
2626
2696
  if (setNameWithoutPrevious(x) && hasFormula(y)) return barrier2(SET_NAME_BARRIER);
2627
2697
  const ch2 = refChangeOf(x);
2628
- if (!ch2) return ok([x]);
2698
+ if (!ch2) return ok2([x]);
2629
2699
  const add = rewritesOf(y, ch2);
2630
2700
  if (typeof add === "string") return barrier2(add);
2631
- return ok(add ? [x, add] : [x]);
2701
+ return ok2(add ? [x, add] : [x]);
2632
2702
  }
2633
2703
  const ch = refChangeOf(y);
2634
- if (!ch) return ok([x]);
2704
+ if (!ch) return ok2([x]);
2635
2705
  const r = definedNameThrough(x, ch);
2636
- return typeof r === "string" ? barrier2(r) : ok([r.op]);
2706
+ return typeof r === "string" ? barrier2(r) : ok2([r.op]);
2637
2707
  }
2638
2708
  if (fy === "defname") {
2639
2709
  if (fx === "cell") {
2640
2710
  if (setNameWithoutPrevious(y) && hasFormula(x)) return barrier2(SET_NAME_BARRIER);
2641
2711
  const ch2 = refChangeOf(y);
2642
- return ch2 ? cellsOverChange(x, ch2) : ok([x]);
2712
+ return ch2 ? cellsOverChange(x, ch2) : ok2([x]);
2643
2713
  }
2644
2714
  const ch = refChangeOf(x);
2645
- if (!ch) return ok([x]);
2715
+ if (!ch) return ok2([x]);
2646
2716
  const r = definedNameThrough(y, ch);
2647
2717
  if (typeof r === "string") return barrier2(r);
2648
- return ok(r.changed ? [x, asDerived(r.op)] : [x]);
2718
+ return ok2(r.changed ? [x, asDerived(r.op)] : [x]);
2649
2719
  }
2650
2720
  if (fx === "cell") {
2651
2721
  const ch = refChangeOf(y);
@@ -2660,7 +2730,7 @@ function formulaPair(x, y, side) {
2660
2730
  });
2661
2731
  const add = rewritesOf(y, ch);
2662
2732
  if (typeof add === "string") return barrier2(add);
2663
- return ok(add ? [x, add] : [x], lost);
2733
+ return ok2(add ? [x, add] : [x], lost);
2664
2734
  }
2665
2735
  return null;
2666
2736
  }
@@ -2808,20 +2878,20 @@ function numfmtPair(x, y, side, sx, sy) {
2808
2878
  const nx = isNumfmt(x);
2809
2879
  const ny = isNumfmt(y);
2810
2880
  if (!nx && !ny) return null;
2811
- if (nx && sy) return ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsThrough(sy, p.ranges) }))));
2812
- if (ny && sx) return ok([x]);
2881
+ if (nx && sy) return ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsThrough(sy, p.ranges) }))));
2882
+ if (ny && sx) return ok2([x]);
2813
2883
  if (nx && ny) {
2814
- if (side === "left") return ok([x]);
2884
+ if (side === "left") return ok2([x]);
2815
2885
  const ys = nfParts(y).flatMap((p) => p.ranges);
2816
- return ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) }))));
2886
+ return ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) }))));
2817
2887
  }
2818
2888
  if (nx && y.id === ID.values) {
2819
- if (side === "left") return ok([x]);
2889
+ if (side === "left") return ok2([x]);
2820
2890
  const ys = nWrites(y);
2821
- return ys.length ? ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) })))) : ok([x]);
2891
+ return ys.length ? ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) })))) : ok2([x]);
2822
2892
  }
2823
2893
  if (ny && x.id === ID.values) {
2824
- if (side === "left") return ok([x]);
2894
+ if (side === "left") return ok2([x]);
2825
2895
  const out = {};
2826
2896
  const tail = {};
2827
2897
  let touched = false;
@@ -2847,31 +2917,31 @@ function numfmtPair(x, y, side, sx, sy) {
2847
2917
  }
2848
2918
  putCell(out, r, c, v);
2849
2919
  });
2850
- if (!touched) return ok([x]);
2920
+ if (!touched) return ok2([x]);
2851
2921
  const ops = [];
2852
2922
  if (!isEmptyMatrix(out)) ops.push(cellsMutation(x, out));
2853
2923
  if (!isEmptyMatrix(tail)) ops.push({ id: ID.values, params: { subUnitId: sheetOf(x), cellValue: tail } });
2854
- return ok(ops);
2924
+ return ok2(ops);
2855
2925
  }
2856
- return ok([x]);
2926
+ return ok2([x]);
2857
2927
  }
2858
2928
  var isCount = (m) => m.id === ID.rowCount || m.id === ID.colCount;
2859
2929
  var countAxis = (m) => m.id === ID.rowCount ? "row" : "col";
2860
2930
  var countKey = (m) => m.id === ID.rowCount ? "rowCount" : "columnCount";
2861
2931
  function countPair(x, y, sy) {
2862
- if (!isCount(x)) return isCount(y) ? ok([x]) : null;
2932
+ if (!isCount(x)) return isCount(y) ? ok2([x]) : null;
2863
2933
  const k = countKey(x);
2864
2934
  const v = Number(x.params[k]);
2865
2935
  if (sy) {
2866
- if (sy.axis !== countAxis(x) || sy.op.kind === "move") return ok([x]);
2936
+ if (sy.axis !== countAxis(x) || sy.op.kind === "move") return ok2([x]);
2867
2937
  const d = sy.op.kind === "insert" ? sy.op.count : -sy.op.count;
2868
- return ok([{ id: x.id, params: { ...x.params, [k]: Math.max(1, v + d) } }]);
2938
+ return ok2([{ id: x.id, params: { ...x.params, [k]: Math.max(1, v + d) } }]);
2869
2939
  }
2870
2940
  if (isCount(y) && y.id === x.id) {
2871
2941
  const w = Number(y.params[k]);
2872
- return ok([w > v ? { id: x.id, params: { ...x.params, [k]: w } } : x]);
2942
+ return ok2([w > v ? { id: x.id, params: { ...x.params, [k]: w } } : x]);
2873
2943
  }
2874
- return ok([x]);
2944
+ return ok2([x]);
2875
2945
  }
2876
2946
  var isSheetOp = (m) => m.id === ID.insertSheet || m.id === ID.removeSheet || m.id === ID.sheetOrder;
2877
2947
  var sheetIdOf = (m) => m.id === ID.insertSheet ? String(m.params.sheet?.id ?? "") : sheetOf(m);
@@ -2904,31 +2974,31 @@ function sheetPair(x, y, side) {
2904
2974
  const b = sheetAxisOf(y);
2905
2975
  if (!a || !b) return barrier2("a sheet add or remove without its index (capture must call annotateSheetOps)");
2906
2976
  if (x.id === ID.insertSheet && y.id === ID.insertSheet && sheetIdOf(x) === sheetIdOf(y)) {
2907
- return JSON.stringify(x.params) === JSON.stringify(y.params) ? ok([]) : barrier2("the same sheet id added twice with different content");
2977
+ return JSON.stringify(x.params) === JSON.stringify(y.params) ? ok2([]) : barrier2("the same sheet id added twice with different content");
2908
2978
  }
2909
2979
  if (x.id === ID.removeSheet && typeof x.params.sheetsLeft === "number" && sheetIdOf(x) !== sheetIdOf(y) && (y.id === ID.removeSheet || y.id === ID.insertSheet)) {
2910
2980
  const left = x.params.sheetsLeft + (y.id === ID.insertSheet ? 1 : -1);
2911
2981
  if (left < 1) return barrier2("concurrent sheet removes would leave the workbook without a sheet");
2912
2982
  const out2 = transformAxis(a, b, side);
2913
2983
  if (!out2) return barrier2("sheet order: no transform");
2914
- return ok(out2.map((o) => buildSheetOp({ id: x.id, params: { ...x.params, sheetsLeft: left } }, o)));
2984
+ return ok2(out2.map((o) => buildSheetOp({ id: x.id, params: { ...x.params, sheetsLeft: left } }, o)));
2915
2985
  }
2916
2986
  const out = transformAxis(a, b, side);
2917
2987
  if (!out) return barrier2("sheet order: no transform");
2918
- return ok(out.map((o) => buildSheetOp(x, o)), [], out.length === 0 && x.id === ID.sheetOrder ? [`${sheetIdOf(x)}: sheet order`] : []);
2988
+ return ok2(out.map((o) => buildSheetOp(x, o)), [], out.length === 0 && x.id === ID.sheetOrder ? [`${sheetIdOf(x)}: sheet order`] : []);
2919
2989
  }
2920
2990
  if (ys) {
2921
- if (y.id !== ID.removeSheet) return ok([x]);
2991
+ if (y.id !== ID.removeSheet) return ok2([x]);
2922
2992
  const gone2 = sheetOf(y);
2923
2993
  if (namesSheet(x, gone2)) return barrier2("a formula names a sheet removed at the same time");
2924
2994
  if (sheetOf(x) === gone2 && x.id !== ID.setName && x.id !== ID.removeName)
2925
- return ok([], [], isDerived(x) ? [] : [`${gone2}: the sheet was removed`]);
2926
- return ok([x]);
2995
+ return ok2([], [], isDerived(x) ? [] : [`${gone2}: the sheet was removed`]);
2996
+ return ok2([x]);
2927
2997
  }
2928
- if (x.id !== ID.removeSheet) return ok([x]);
2998
+ if (x.id !== ID.removeSheet) return ok2([x]);
2929
2999
  const gone = sheetOf(x);
2930
3000
  if (namesSheet(y, gone)) return barrier2("a formula names a sheet removed at the same time");
2931
- return ok([x], sheetOf(y) === gone && !isDerived(y) && y.id !== ID.setName && y.id !== ID.removeName ? [`${gone}: the sheet was removed`] : []);
3001
+ return ok2([x], sheetOf(y) === gone && !isDerived(y) && y.id !== ID.setName && y.id !== ID.removeName ? [`${gone}: the sheet was removed`] : []);
2932
3002
  }
2933
3003
  function annotateSheetOps(group, sheetOrder) {
2934
3004
  const order = [...sheetOrder];
@@ -3026,22 +3096,22 @@ function sortPair(x, y, sx, sy) {
3026
3096
  const a = sortOf(x).range;
3027
3097
  const b = sortOf(y).range;
3028
3098
  const overlap = a.startRow <= b.endRow && b.startRow <= a.endRow && a.startColumn <= b.endColumn && b.startColumn <= a.endColumn;
3029
- return overlap ? barrier2("two sorts of overlapping ranges at once") : ok([x]);
3099
+ return overlap ? barrier2("two sorts of overlapping ranges at once") : ok2([x]);
3030
3100
  }
3031
3101
  if (xs) {
3032
3102
  if (sy) {
3033
3103
  const t = sortThrough(sortOf(x), sy);
3034
- return t ? ok(buildSort(x, t)) : barrier2("a row or column move through a sorted range");
3104
+ return t ? ok2(buildSort(x, t)) : barrier2("a row or column move through a sorted range");
3035
3105
  }
3036
- return ok([x]);
3106
+ return ok2([x]);
3037
3107
  }
3038
3108
  const o = sortOf(y);
3039
3109
  const Q = sortQ(o);
3040
3110
  const moved = (r) => r >= o.range.startRow && r <= o.range.endRow && Q.has(r);
3041
3111
  if (sx) {
3042
- if (sx.axis === "col") return sx.op.kind === "move" && !sortThrough(o, sx) ? barrier2("a column move through a sorted range") : ok([x]);
3043
- if (sx.op.kind === "insert") return ok([x]);
3044
- if (sx.op.kind === "move") return sortThrough(o, sx) ? ok([x]) : barrier2("a row move through a sorted range");
3112
+ if (sx.axis === "col") return sx.op.kind === "move" && !sortThrough(o, sx) ? barrier2("a column move through a sorted range") : ok2([x]);
3113
+ if (sx.op.kind === "insert") return ok2([x]);
3114
+ if (sx.op.kind === "move") return sortThrough(o, sx) ? ok2([x]) : barrier2("a row move through a sorted range");
3045
3115
  const rows = [];
3046
3116
  let partial = false;
3047
3117
  for (let i = sx.op.start; i < sx.op.start + sx.op.count; i++) {
@@ -3049,7 +3119,7 @@ function sortPair(x, y, sx, sy) {
3049
3119
  rows.push(Q.get(i) ?? i);
3050
3120
  }
3051
3121
  if (partial) return barrier2("a row remove against a concurrent sort of those rows");
3052
- return ok([x]);
3122
+ return ok2([x]);
3053
3123
  }
3054
3124
  if (x.id === ID.values) {
3055
3125
  const out = {};
@@ -3060,7 +3130,7 @@ function sortPair(x, y, sx, sy) {
3060
3130
  changed = true;
3061
3131
  } else putCell(out, r, c, v);
3062
3132
  });
3063
- return changed ? ok([cellsMutation(x, out)]) : ok([x]);
3133
+ return changed ? ok2([cellsMutation(x, out)]) : ok2([x]);
3064
3134
  }
3065
3135
  if (isNumfmt(x)) {
3066
3136
  const parts = nfParts(x).map((p) => {
@@ -3076,9 +3146,9 @@ function sortPair(x, y, sx, sy) {
3076
3146
  }
3077
3147
  return { ...p, ranges };
3078
3148
  });
3079
- return ok(nfBuild(x, parts));
3149
+ return ok2(nfBuild(x, parts));
3080
3150
  }
3081
- return ok([x]);
3151
+ return ok2([x]);
3082
3152
  }
3083
3153
  function familyOf(id) {
3084
3154
  const e = SHEET_MUTATIONS[id];
@@ -3094,13 +3164,15 @@ function transformMutation(x, y, side) {
3094
3164
  if (why) return barrier2(why);
3095
3165
  }
3096
3166
  }
3167
+ const ca = transformCommentAnchor(x, y, side);
3168
+ if (ca) return ca;
3097
3169
  const pb = PAIR_BARRIERS[pairKey(x.id, y.id)];
3098
3170
  if (pb) return barrier2(`${x.id} \xD7 ${y.id}: ${pb.reason}${pb.seed === null ? "" : ` (fuzz seed ${pb.seed})`}`);
3099
3171
  const sp = sheetPair(x, y, side);
3100
3172
  if (sp) return sp;
3101
3173
  const fp = formulaPair(x, y, side);
3102
3174
  if (fp) return fp;
3103
- if (sheetOf(x) !== sheetOf(y)) return ok([x]);
3175
+ if (sheetOf(x) !== sheetOf(y)) return ok2([x]);
3104
3176
  const fx = familyOf(x.id);
3105
3177
  const fy = familyOf(y.id);
3106
3178
  const sy = structuralOf(y);
@@ -3112,11 +3184,11 @@ function transformMutation(x, y, side) {
3112
3184
  const np = numfmtPair(x, y, side, sx, sy);
3113
3185
  if (np) return np;
3114
3186
  if (sx && sy) {
3115
- if (sx.axis !== sy.axis) return ok([x]);
3187
+ if (sx.axis !== sy.axis) return ok2([x]);
3116
3188
  const out = transformAxis(sx.op, sy.op, side);
3117
3189
  if (!out) return barrier2(`${x.id} over ${y.id}: moved blocks overlap in part, or the block would split`);
3118
3190
  const dropped = out.length === 0 && sx.op.kind === "move" ? [`${sheetOf(x)}: moved ${sx.axis}s`] : [];
3119
- return ok(out.map((o) => buildStructural(x, sx.axis, o)), [], dropped);
3191
+ return ok2(out.map((o) => buildStructural(x, sx.axis, o)), [], dropped);
3120
3192
  }
3121
3193
  if (sy) {
3122
3194
  if (fx === "merge") {
@@ -3127,23 +3199,23 @@ function transformMutation(x, y, side) {
3127
3199
  if (t) kept.push(t);
3128
3200
  else dropped.push(rangeRef(sheetOf(x), r));
3129
3201
  }
3130
- return ok(kept.length ? [withRanges(x, kept)] : [], [], x.id === ID.addMerge ? dropped : []);
3202
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], x.id === ID.addMerge ? dropped : []);
3131
3203
  }
3132
3204
  if (fx === "size") {
3133
3205
  const size = sizeOf(x);
3134
- if (size.axis !== sy.axis) return ok([x]);
3206
+ if (size.axis !== sy.axis) return ok2([x]);
3135
3207
  const next = /* @__PURE__ */ new Map();
3136
3208
  for (const [i, v] of size.values) {
3137
3209
  const m = mapIndex(sy.op, i);
3138
3210
  if (m !== null) next.set(m, v);
3139
3211
  }
3140
3212
  const built = buildSize(x, next);
3141
- return ok(built ? [built] : []);
3213
+ return ok2(built ? [built] : []);
3142
3214
  }
3143
- return ok([x]);
3215
+ return ok2([x]);
3144
3216
  }
3145
3217
  if (sx) {
3146
- if (fy !== "merge" || y.id !== ID.addMerge) return ok([x]);
3218
+ if (fy !== "merge" || y.id !== ID.addMerge) return ok2([x]);
3147
3219
  const remove = [];
3148
3220
  const add = [];
3149
3221
  for (const r of mergeRanges(y)) {
@@ -3153,11 +3225,11 @@ function transformMutation(x, y, side) {
3153
3225
  if (t.range) add.push(t.range);
3154
3226
  }
3155
3227
  const lostMerges = mergeRanges(y).filter((r) => mergeThrough(sx, r).range === null).map((r) => rangeRef(sheetOf(y), r));
3156
- if (!remove.length) return ok([x], lostMerges);
3228
+ if (!remove.length) return ok2([x], lostMerges);
3157
3229
  const sheet = sheetOf(x);
3158
3230
  const pre = sx.op.kind === "insert" ? [] : [mergeMutation(ID.removeMerge, sheet, remove)];
3159
3231
  const mid = sx.op.kind === "insert" ? [mergeMutation(ID.removeMerge, sheet, remove)] : [];
3160
- return ok([...pre, x, ...mid, ...add.length ? [mergeMutation(ID.addMerge, sheet, add)] : []], lostMerges);
3232
+ return ok2([...pre, x, ...mid, ...add.length ? [mergeMutation(ID.addMerge, sheet, add)] : []], lostMerges);
3161
3233
  }
3162
3234
  if (fx === "cell" && fy === "cell") return transformCellsOverCells(x, y, side);
3163
3235
  if (fx === "merge" && fy === "merge") {
@@ -3166,45 +3238,45 @@ function transformMutation(x, y, side) {
3166
3238
  const hit = (r) => yr.some((q) => intersects(r, q));
3167
3239
  const sheet = sheetOf(x);
3168
3240
  if (x.id === ID.addMerge && y.id === ID.addMerge) {
3169
- if (!xr.some(hit)) return ok([x]);
3241
+ if (!xr.some(hit)) return ok2([x]);
3170
3242
  if (side === "left") {
3171
3243
  const lost = yr.filter((q) => xr.some((r) => intersects(r, q))).map((q) => rangeRef(sheet, q));
3172
- return ok([mergeMutation(ID.removeMerge, sheet, xr.filter(hit)), x], lost);
3244
+ return ok2([mergeMutation(ID.removeMerge, sheet, xr.filter(hit)), x], lost);
3173
3245
  }
3174
3246
  const kept = xr.filter((r) => !hit(r));
3175
- return ok(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3247
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3176
3248
  }
3177
3249
  if (x.id === ID.addMerge && y.id === ID.removeMerge) {
3178
- if (side === "left" || !xr.some(hit)) return ok([x], side === "left" && xr.some(hit) ? yr.filter((q) => xr.some((r) => intersects(r, q))).map((q) => rangeRef(sheet, q)) : []);
3250
+ if (side === "left" || !xr.some(hit)) return ok2([x], side === "left" && xr.some(hit) ? yr.filter((q) => xr.some((r) => intersects(r, q))).map((q) => rangeRef(sheet, q)) : []);
3179
3251
  const kept = xr.filter((r) => !hit(r));
3180
- return ok(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3252
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3181
3253
  }
3182
3254
  if (x.id === ID.removeMerge && y.id === ID.addMerge) {
3183
3255
  const touched = yr.filter((q) => xr.some((r) => intersects(r, q)));
3184
- if (!touched.length) return ok([x]);
3185
- if (side === "left") return ok([x], touched.map((q) => rangeRef(sheet, q)));
3186
- return ok([x, mergeMutation(ID.addMerge, sheet, touched)], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3256
+ if (!touched.length) return ok2([x]);
3257
+ if (side === "left") return ok2([x], touched.map((q) => rangeRef(sheet, q)));
3258
+ return ok2([x, mergeMutation(ID.addMerge, sheet, touched)], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3187
3259
  }
3188
- return ok([x]);
3260
+ return ok2([x]);
3189
3261
  }
3190
3262
  if (fx === "size" && fy === "size") {
3191
3263
  const a = sizeOf(x);
3192
3264
  const b = sizeOf(y);
3193
- if (a.axis !== b.axis || a.attr !== b.attr) return ok([x]);
3265
+ if (a.axis !== b.axis || a.attr !== b.attr) return ok2([x]);
3194
3266
  if (side === "left") {
3195
3267
  const lost = [...a.values.keys()].filter((i) => b.values.has(i)).map((i) => `${sheetOf(x)}: ${a.axis} ${i + 1} ${a.attr}`);
3196
- return ok([x], lost);
3268
+ return ok2([x], lost);
3197
3269
  }
3198
3270
  const next = new Map([...a.values].filter(([i]) => !b.values.has(i)));
3199
3271
  const built = buildSize(x, next);
3200
3272
  const dropped = [...a.values.keys()].filter((i) => b.values.has(i)).map((i) => `${sheetOf(x)}: ${a.axis} ${i + 1} ${a.attr}`);
3201
- return ok(built ? [built] : [], [], dropped);
3273
+ return ok2(built ? [built] : [], [], dropped);
3202
3274
  }
3203
3275
  if (fx === "name" && fy === "name") {
3204
- if (side === "left") return ok([x], [`${sheetOf(x)}: name "${String(y.params.name)}"`]);
3205
- return ok([], [], [`${sheetOf(x)}: name "${String(x.params.name)}"`]);
3276
+ if (side === "left") return ok2([x], [`${sheetOf(x)}: name "${String(y.params.name)}"`]);
3277
+ return ok2([], [], [`${sheetOf(x)}: name "${String(x.params.name)}"`]);
3206
3278
  }
3207
- return ok([x]);
3279
+ return ok2([x]);
3208
3280
  }
3209
3281
  var blocked = (p) => !Array.isArray(p);
3210
3282
  function tSeq(xs, ys, side, acc) {
@@ -3383,10 +3455,10 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3383
3455
  let dropped = 0;
3384
3456
  for (let i = items.length - 1; i >= 0; i--) {
3385
3457
  const item = items[i];
3386
- let ok2 = true;
3458
+ let ok3 = true;
3387
3459
  for (const key of ["undoMutations", "redoMutations"]) {
3388
3460
  const list = item[key];
3389
- if (!ok2 || !list?.length) continue;
3461
+ if (!ok3 || !list?.length) continue;
3390
3462
  const isOperation = (id) => !SHEET_MUTATIONS[id] && id.includes(".operation.");
3391
3463
  const operations = list.filter((m) => isOperation(m.id));
3392
3464
  let shaped = cachedShape(list);
@@ -3395,14 +3467,14 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3395
3467
  shapedLists.set(list, { src: list.slice(), shaped });
3396
3468
  }
3397
3469
  if (shaped.some((m) => m === null)) {
3398
- ok2 = false;
3470
+ ok3 = false;
3399
3471
  continue;
3400
3472
  }
3401
3473
  if (!shaped.length) continue;
3402
3474
  try {
3403
3475
  const r = transformGroup(shaped, remote, "left");
3404
3476
  if (isBarrier(r) || r.op.length === 0) {
3405
- ok2 = false;
3477
+ ok3 = false;
3406
3478
  continue;
3407
3479
  }
3408
3480
  if (r.op.length === shaped.length && r.op.every((m, i2) => m === shaped[i2])) continue;
@@ -3410,10 +3482,10 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3410
3482
  shapedLists.set(next, { src: next.slice(), shaped: r.op });
3411
3483
  item[key] = next;
3412
3484
  } catch {
3413
- ok2 = false;
3485
+ ok3 = false;
3414
3486
  }
3415
3487
  }
3416
- if (!ok2) {
3488
+ if (!ok3) {
3417
3489
  items.splice(i, 1);
3418
3490
  dropped++;
3419
3491
  }
@@ -3634,7 +3706,7 @@ function univerSheetsOtPort(o) {
3634
3706
  return out;
3635
3707
  };
3636
3708
  const sheetOrder = () => (o.workbook()?.getSheets() ?? []).map((ws) => ws.getSheetId());
3637
- const openGroup = (label) => ({ label, order: sheetOrder(), sheets: sheetNames(), names: definedNames(), mutations: [], inverses: [], notShared: null });
3709
+ const openGroup = (label2) => ({ label: label2, order: sheetOrder(), sheets: sheetNames(), names: definedNames(), mutations: [], inverses: [], notShared: null });
3638
3710
  const emit = (e) => {
3639
3711
  for (const l of [...listeners]) {
3640
3712
  try {
@@ -3890,8 +3962,8 @@ function univerSheetsOtPort(o) {
3890
3962
  const a = forApply(m);
3891
3963
  applying = true;
3892
3964
  try {
3893
- const ok2 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
3894
- if (ok2 === false) throw new Error(`"${m.id}" was refused by the editor`);
3965
+ const ok3 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
3966
+ if (ok3 === false) throw new Error(`"${m.id}" was refused by the editor`);
3895
3967
  } finally {
3896
3968
  applying = false;
3897
3969
  }