@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.
@@ -1193,25 +1193,25 @@ function rebaseUndoStack(items, remote) {
1193
1193
  let dropped = 0;
1194
1194
  for (let i = items.length - 1; i >= 0; i--) {
1195
1195
  const item = items[i];
1196
- let ok2 = true;
1196
+ let ok3 = true;
1197
1197
  for (const list of [item.undoMutations, item.redoMutations]) {
1198
1198
  for (const m of list ?? []) {
1199
1199
  if (m.id !== RICH_TEXT_EDITING) continue;
1200
1200
  try {
1201
1201
  if (touchesPageSetup(m.params.actions) && touchesPageSetup(remote)) throw new Error("page setup");
1202
1202
  const r = transformDocsOp(m.params.actions, remote, "left");
1203
- if (isNoopDocsOp(r.op)) ok2 = false;
1203
+ if (isNoopDocsOp(r.op)) ok3 = false;
1204
1204
  else {
1205
1205
  m.params = { ...m.params, actions: r.op };
1206
1206
  delete m.params.textRanges;
1207
1207
  delete m.params.layoutState;
1208
1208
  }
1209
1209
  } catch {
1210
- ok2 = false;
1210
+ ok3 = false;
1211
1211
  }
1212
1212
  }
1213
1213
  }
1214
- if (!ok2) {
1214
+ if (!ok3) {
1215
1215
  items.splice(i, 1);
1216
1216
  dropped++;
1217
1217
  }
@@ -1766,6 +1766,8 @@ var SHEET_MUTATIONS = {
1766
1766
  "sheet.mutation.insert-sheet": covered("sheet", "index", "sheet"),
1767
1767
  "sheet.mutation.remove-sheet": covered("sheet", "sheetIndex", "sheetsLeft"),
1768
1768
  "sheet.mutation.set-worksheet-order": covered("sheet", "fromOrder", "toOrder"),
1769
+ // ── covered (C9): our own cell comment anchors (comment-anchor-transform.ts; not emitted by Univer) ──────
1770
+ "matrx.mutation.set-comment-anchor": covered("anchor", "anchorId", "cell"),
1769
1771
  "sheet.mutation.reorder-range": covered("sort", "range", "order"),
1770
1772
  // ── never travels ────────────────────────────────────────────────────────────────────────────────
1771
1773
  "formula.mutation.set-formula-calculation-start": never(FORMULA_RESULT),
@@ -2208,6 +2210,74 @@ function refSheetsFor(texts, sheets) {
2208
2210
  return Object.keys(out).length ? out : void 0;
2209
2211
  }
2210
2212
 
2213
+ // src/collab/sheets/comment-anchor-transform.ts
2214
+ var SET_SHEET_COMMENT_ANCHOR = "matrx.mutation.set-comment-anchor";
2215
+ var REMOVE_SHEET = "sheet.mutation.remove-sheet";
2216
+ function structuralAxisOp(id, params) {
2217
+ const p = params;
2218
+ switch (id) {
2219
+ case "sheet.mutation.insert-row":
2220
+ return p.range ? { axis: "row", op: { kind: "insert", at: p.range.startRow, count: p.range.endRow - p.range.startRow + 1 } } : null;
2221
+ case "sheet.mutation.remove-rows":
2222
+ return p.range ? { axis: "row", op: { kind: "remove", start: p.range.startRow, count: p.range.endRow - p.range.startRow + 1 } } : null;
2223
+ case "sheet.mutation.insert-col":
2224
+ return p.range ? { axis: "col", op: { kind: "insert", at: p.range.startColumn, count: p.range.endColumn - p.range.startColumn + 1 } } : null;
2225
+ case "sheet.mutation.remove-col":
2226
+ return p.range ? { axis: "col", op: { kind: "remove", start: p.range.startColumn, count: p.range.endColumn - p.range.startColumn + 1 } } : null;
2227
+ case "sheet.mutation.move-rows":
2228
+ 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;
2229
+ case "sheet.mutation.move-columns":
2230
+ return p.sourceRange && p.targetRange ? {
2231
+ axis: "col",
2232
+ op: { kind: "move", from: p.sourceRange.startColumn, count: p.sourceRange.endColumn - p.sourceRange.startColumn + 1, to: p.targetRange.startColumn }
2233
+ } : null;
2234
+ default:
2235
+ return null;
2236
+ }
2237
+ }
2238
+ function moveSheetAnchorCell(cell, sheet, id, params) {
2239
+ if (String(params.subUnitId ?? "") !== sheet) return cell;
2240
+ if (id === REMOVE_SHEET) return null;
2241
+ const s = structuralAxisOp(id, params);
2242
+ if (!s) return cell;
2243
+ if (s.axis === "row") {
2244
+ const row = mapIndex(s.op, cell.row);
2245
+ return row === null ? null : row === cell.row ? cell : { row, col: cell.col };
2246
+ }
2247
+ const col = mapIndex(s.op, cell.col);
2248
+ return col === null ? null : col === cell.col ? cell : { row: cell.row, col };
2249
+ }
2250
+ function colName(c) {
2251
+ let s = "";
2252
+ for (let n = c + 1; n > 0; n = Math.floor((n - 1) / 26)) s = String.fromCharCode(65 + (n - 1) % 26) + s;
2253
+ return s;
2254
+ }
2255
+ var sheetCellName = (cell) => `${colName(cell.col)}${cell.row + 1}`;
2256
+ function cellOf(m) {
2257
+ const c = m.params.cell;
2258
+ return c && typeof c.row === "number" && typeof c.col === "number" ? c : null;
2259
+ }
2260
+ var ok = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2261
+ var label = (m) => {
2262
+ const c = cellOf(m);
2263
+ return `${String(m.params.subUnitId ?? "")}!${c ? sheetCellName(c) : "?"} comment`;
2264
+ };
2265
+ function transformCommentAnchor(x, y, side) {
2266
+ const xa = x.id === SET_SHEET_COMMENT_ANCHOR;
2267
+ const ya = y.id === SET_SHEET_COMMENT_ANCHOR;
2268
+ if (!xa && !ya) return null;
2269
+ if (!xa) return ok([x]);
2270
+ if (ya) {
2271
+ if (x.params.anchorId !== y.params.anchorId || x.params.subUnitId !== y.params.subUnitId) return ok([x]);
2272
+ return side === "left" ? ok([x], [label(y)]) : ok([], [], [label(x)]);
2273
+ }
2274
+ const cell = cellOf(x);
2275
+ if (!cell) return ok([x]);
2276
+ const moved = moveSheetAnchorCell(cell, String(x.params.subUnitId ?? ""), y.id, y.params);
2277
+ if (!moved) return ok([], [], [label(x)]);
2278
+ return ok([moved === cell ? x : { id: x.id, params: { ...x.params, cell: moved } }]);
2279
+ }
2280
+
2211
2281
  // src/collab/sheets/transform/transform.ts
2212
2282
  var SHEET_TRANSFORMER_VERSION = "c5c-1";
2213
2283
  var ID = {
@@ -2239,16 +2309,16 @@ var ID = {
2239
2309
  var PAIR_BARRIERS = {};
2240
2310
  var pairKey = (a, b) => a < b ? `${a}|${b}` : `${b}|${a}`;
2241
2311
  var barrier2 = (reason) => ({ barrier: true, reason });
2242
- var ok = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2312
+ var ok2 = (op, lost = [], dropped = []) => ({ op, lost, dropped });
2243
2313
  var flip = (side) => side === "left" ? "right" : "left";
2244
2314
  var sheetOf = (m) => String(m.params.subUnitId ?? "");
2245
- function colName(c) {
2315
+ function colName2(c) {
2246
2316
  let s = "";
2247
2317
  for (let n = c + 1; n > 0; n = Math.floor((n - 1) / 26)) s = String.fromCharCode(65 + (n - 1) % 26) + s;
2248
2318
  return s;
2249
2319
  }
2250
- var cellRef = (sheet, row, col) => `${sheet}!${colName(col)}${row + 1}`;
2251
- var rangeRef = (sheet, r) => `${sheet}!${colName(r.startColumn)}${r.startRow + 1}:${colName(r.endColumn)}${r.endRow + 1}`;
2320
+ var cellRef = (sheet, row, col) => `${sheet}!${colName2(col)}${row + 1}`;
2321
+ var rangeRef = (sheet, r) => `${sheet}!${colName2(r.startColumn)}${r.startRow + 1}:${colName2(r.endColumn)}${r.endRow + 1}`;
2252
2322
  function structuralOf(m) {
2253
2323
  const p = m.params;
2254
2324
  switch (m.id) {
@@ -2503,9 +2573,9 @@ function transformCell(X, Y4, side) {
2503
2573
  return { entries: Object.keys(out).length ? [out, ...tail] : tail, xLost, yLost };
2504
2574
  }
2505
2575
  function transformCellsOverCells(x, y, side) {
2506
- if (sheetOf(x) !== sheetOf(y)) return ok([x]);
2576
+ if (sheetOf(x) !== sheetOf(y)) return ok2([x]);
2507
2577
  const ycells = cellsOf(y);
2508
- if (!cellsOverlap(cellsOf(x), ycells)) return ok([x]);
2578
+ if (!cellsOverlap(cellsOf(x), ycells)) return ok2([x]);
2509
2579
  const xd = isDerived(x);
2510
2580
  const yd = isDerived(y);
2511
2581
  const eff = derivedSide(x, y, side);
@@ -2531,7 +2601,7 @@ function transformCellsOverCells(x, y, side) {
2531
2601
  });
2532
2602
  if (why) return barrier2(why);
2533
2603
  const op = passes.filter((p) => !isEmptyMatrix(p)).map((p) => cellsMutation(x, p));
2534
- return ok(op, lost, dropped);
2604
+ return ok2(op, lost, dropped);
2535
2605
  }
2536
2606
  var SIDE_CAR_PARAMS = ["refSheets", "previousName", "derived", "sheetIndex", "sheetsLeft"];
2537
2607
  var isDerived = (m) => m.params.derived === true;
@@ -2602,7 +2672,7 @@ function cellThrough(sheet, change, r, c) {
2602
2672
  return nr === null || nc === null ? null : [nr, nc];
2603
2673
  }
2604
2674
  function cellsOverChange(x, change) {
2605
- if (!hasFormula(x) && (change.kind !== "axis" || change.sheet !== sheetOf(x))) return ok([x]);
2675
+ if (!hasFormula(x) && (change.kind !== "axis" || change.sheet !== sheetOf(x))) return ok2([x]);
2606
2676
  const ctx = formulaCtx(x);
2607
2677
  const out = {};
2608
2678
  const dropped = [];
@@ -2631,9 +2701,9 @@ function cellsOverChange(x, change) {
2631
2701
  });
2632
2702
  if (why) return barrier2(why);
2633
2703
  const rsAfter = refSheetsAfter(ctx.refSheets, change);
2634
- if (!changed && JSON.stringify(rsAfter ?? null) === JSON.stringify(ctx.refSheets ?? null)) return ok([x]);
2704
+ if (!changed && JSON.stringify(rsAfter ?? null) === JSON.stringify(ctx.refSheets ?? null)) return ok2([x]);
2635
2705
  const params = { ...withRefSheets(x.params, rsAfter), cellValue: out };
2636
- return ok(isEmptyMatrix(out) ? [] : [{ id: x.id, params }], [], dropped);
2706
+ return ok2(isEmptyMatrix(out) ? [] : [{ id: x.id, params }], [], dropped);
2637
2707
  }
2638
2708
  function rewritesOf(y, change) {
2639
2709
  if (!hasFormula(y)) return null;
@@ -2680,36 +2750,36 @@ function formulaPair(x, y, side) {
2680
2750
  const fy = familyOf(y.id);
2681
2751
  const SET_NAME_BARRIER = "set-defined-name without previousName (capture must record the name it replaces) against formula text";
2682
2752
  if (fx === "defname" && fy === "defname") {
2683
- if (String(x.params.id) !== String(y.params.id)) return ok([x]);
2753
+ if (String(x.params.id) !== String(y.params.id)) return ok2([x]);
2684
2754
  const eff = derivedSide(x, y, side);
2685
- if (eff === "left") return ok([x], isDerived(y) ? [] : [`defined name "${String(y.params.name)}"`]);
2686
- return ok([], [], isDerived(x) ? [] : [`defined name "${String(x.params.name)}"`]);
2755
+ if (eff === "left") return ok2([x], isDerived(y) ? [] : [`defined name "${String(y.params.name)}"`]);
2756
+ return ok2([], [], isDerived(x) ? [] : [`defined name "${String(x.params.name)}"`]);
2687
2757
  }
2688
2758
  if (fx === "defname") {
2689
2759
  if (fy === "cell") {
2690
2760
  if (setNameWithoutPrevious(x) && hasFormula(y)) return barrier2(SET_NAME_BARRIER);
2691
2761
  const ch2 = refChangeOf(x);
2692
- if (!ch2) return ok([x]);
2762
+ if (!ch2) return ok2([x]);
2693
2763
  const add = rewritesOf(y, ch2);
2694
2764
  if (typeof add === "string") return barrier2(add);
2695
- return ok(add ? [x, add] : [x]);
2765
+ return ok2(add ? [x, add] : [x]);
2696
2766
  }
2697
2767
  const ch = refChangeOf(y);
2698
- if (!ch) return ok([x]);
2768
+ if (!ch) return ok2([x]);
2699
2769
  const r = definedNameThrough(x, ch);
2700
- return typeof r === "string" ? barrier2(r) : ok([r.op]);
2770
+ return typeof r === "string" ? barrier2(r) : ok2([r.op]);
2701
2771
  }
2702
2772
  if (fy === "defname") {
2703
2773
  if (fx === "cell") {
2704
2774
  if (setNameWithoutPrevious(y) && hasFormula(x)) return barrier2(SET_NAME_BARRIER);
2705
2775
  const ch2 = refChangeOf(y);
2706
- return ch2 ? cellsOverChange(x, ch2) : ok([x]);
2776
+ return ch2 ? cellsOverChange(x, ch2) : ok2([x]);
2707
2777
  }
2708
2778
  const ch = refChangeOf(x);
2709
- if (!ch) return ok([x]);
2779
+ if (!ch) return ok2([x]);
2710
2780
  const r = definedNameThrough(y, ch);
2711
2781
  if (typeof r === "string") return barrier2(r);
2712
- return ok(r.changed ? [x, asDerived(r.op)] : [x]);
2782
+ return ok2(r.changed ? [x, asDerived(r.op)] : [x]);
2713
2783
  }
2714
2784
  if (fx === "cell") {
2715
2785
  const ch = refChangeOf(y);
@@ -2724,7 +2794,7 @@ function formulaPair(x, y, side) {
2724
2794
  });
2725
2795
  const add = rewritesOf(y, ch);
2726
2796
  if (typeof add === "string") return barrier2(add);
2727
- return ok(add ? [x, add] : [x], lost);
2797
+ return ok2(add ? [x, add] : [x], lost);
2728
2798
  }
2729
2799
  return null;
2730
2800
  }
@@ -2872,20 +2942,20 @@ function numfmtPair(x, y, side, sx, sy) {
2872
2942
  const nx = isNumfmt(x);
2873
2943
  const ny = isNumfmt(y);
2874
2944
  if (!nx && !ny) return null;
2875
- if (nx && sy) return ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsThrough(sy, p.ranges) }))));
2876
- if (ny && sx) return ok([x]);
2945
+ if (nx && sy) return ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsThrough(sy, p.ranges) }))));
2946
+ if (ny && sx) return ok2([x]);
2877
2947
  if (nx && ny) {
2878
- if (side === "left") return ok([x]);
2948
+ if (side === "left") return ok2([x]);
2879
2949
  const ys = nfParts(y).flatMap((p) => p.ranges);
2880
- return ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) }))));
2950
+ return ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) }))));
2881
2951
  }
2882
2952
  if (nx && y.id === ID.values) {
2883
- if (side === "left") return ok([x]);
2953
+ if (side === "left") return ok2([x]);
2884
2954
  const ys = nWrites(y);
2885
- return ys.length ? ok(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) })))) : ok([x]);
2955
+ return ys.length ? ok2(nfBuild(x, nfParts(x).map((p) => ({ ...p, ranges: rectsMinus(p.ranges, ys) })))) : ok2([x]);
2886
2956
  }
2887
2957
  if (ny && x.id === ID.values) {
2888
- if (side === "left") return ok([x]);
2958
+ if (side === "left") return ok2([x]);
2889
2959
  const out = {};
2890
2960
  const tail = {};
2891
2961
  let touched = false;
@@ -2911,31 +2981,31 @@ function numfmtPair(x, y, side, sx, sy) {
2911
2981
  }
2912
2982
  putCell(out, r, c, v);
2913
2983
  });
2914
- if (!touched) return ok([x]);
2984
+ if (!touched) return ok2([x]);
2915
2985
  const ops = [];
2916
2986
  if (!isEmptyMatrix(out)) ops.push(cellsMutation(x, out));
2917
2987
  if (!isEmptyMatrix(tail)) ops.push({ id: ID.values, params: { subUnitId: sheetOf(x), cellValue: tail } });
2918
- return ok(ops);
2988
+ return ok2(ops);
2919
2989
  }
2920
- return ok([x]);
2990
+ return ok2([x]);
2921
2991
  }
2922
2992
  var isCount = (m) => m.id === ID.rowCount || m.id === ID.colCount;
2923
2993
  var countAxis = (m) => m.id === ID.rowCount ? "row" : "col";
2924
2994
  var countKey = (m) => m.id === ID.rowCount ? "rowCount" : "columnCount";
2925
2995
  function countPair(x, y, sy) {
2926
- if (!isCount(x)) return isCount(y) ? ok([x]) : null;
2996
+ if (!isCount(x)) return isCount(y) ? ok2([x]) : null;
2927
2997
  const k = countKey(x);
2928
2998
  const v = Number(x.params[k]);
2929
2999
  if (sy) {
2930
- if (sy.axis !== countAxis(x) || sy.op.kind === "move") return ok([x]);
3000
+ if (sy.axis !== countAxis(x) || sy.op.kind === "move") return ok2([x]);
2931
3001
  const d = sy.op.kind === "insert" ? sy.op.count : -sy.op.count;
2932
- return ok([{ id: x.id, params: { ...x.params, [k]: Math.max(1, v + d) } }]);
3002
+ return ok2([{ id: x.id, params: { ...x.params, [k]: Math.max(1, v + d) } }]);
2933
3003
  }
2934
3004
  if (isCount(y) && y.id === x.id) {
2935
3005
  const w = Number(y.params[k]);
2936
- return ok([w > v ? { id: x.id, params: { ...x.params, [k]: w } } : x]);
3006
+ return ok2([w > v ? { id: x.id, params: { ...x.params, [k]: w } } : x]);
2937
3007
  }
2938
- return ok([x]);
3008
+ return ok2([x]);
2939
3009
  }
2940
3010
  var isSheetOp = (m) => m.id === ID.insertSheet || m.id === ID.removeSheet || m.id === ID.sheetOrder;
2941
3011
  var sheetIdOf = (m) => m.id === ID.insertSheet ? String(m.params.sheet?.id ?? "") : sheetOf(m);
@@ -2968,31 +3038,31 @@ function sheetPair(x, y, side) {
2968
3038
  const b = sheetAxisOf(y);
2969
3039
  if (!a || !b) return barrier2("a sheet add or remove without its index (capture must call annotateSheetOps)");
2970
3040
  if (x.id === ID.insertSheet && y.id === ID.insertSheet && sheetIdOf(x) === sheetIdOf(y)) {
2971
- return JSON.stringify(x.params) === JSON.stringify(y.params) ? ok([]) : barrier2("the same sheet id added twice with different content");
3041
+ return JSON.stringify(x.params) === JSON.stringify(y.params) ? ok2([]) : barrier2("the same sheet id added twice with different content");
2972
3042
  }
2973
3043
  if (x.id === ID.removeSheet && typeof x.params.sheetsLeft === "number" && sheetIdOf(x) !== sheetIdOf(y) && (y.id === ID.removeSheet || y.id === ID.insertSheet)) {
2974
3044
  const left = x.params.sheetsLeft + (y.id === ID.insertSheet ? 1 : -1);
2975
3045
  if (left < 1) return barrier2("concurrent sheet removes would leave the workbook without a sheet");
2976
3046
  const out2 = transformAxis(a, b, side);
2977
3047
  if (!out2) return barrier2("sheet order: no transform");
2978
- return ok(out2.map((o) => buildSheetOp({ id: x.id, params: { ...x.params, sheetsLeft: left } }, o)));
3048
+ return ok2(out2.map((o) => buildSheetOp({ id: x.id, params: { ...x.params, sheetsLeft: left } }, o)));
2979
3049
  }
2980
3050
  const out = transformAxis(a, b, side);
2981
3051
  if (!out) return barrier2("sheet order: no transform");
2982
- return ok(out.map((o) => buildSheetOp(x, o)), [], out.length === 0 && x.id === ID.sheetOrder ? [`${sheetIdOf(x)}: sheet order`] : []);
3052
+ return ok2(out.map((o) => buildSheetOp(x, o)), [], out.length === 0 && x.id === ID.sheetOrder ? [`${sheetIdOf(x)}: sheet order`] : []);
2983
3053
  }
2984
3054
  if (ys) {
2985
- if (y.id !== ID.removeSheet) return ok([x]);
3055
+ if (y.id !== ID.removeSheet) return ok2([x]);
2986
3056
  const gone2 = sheetOf(y);
2987
3057
  if (namesSheet(x, gone2)) return barrier2("a formula names a sheet removed at the same time");
2988
3058
  if (sheetOf(x) === gone2 && x.id !== ID.setName && x.id !== ID.removeName)
2989
- return ok([], [], isDerived(x) ? [] : [`${gone2}: the sheet was removed`]);
2990
- return ok([x]);
3059
+ return ok2([], [], isDerived(x) ? [] : [`${gone2}: the sheet was removed`]);
3060
+ return ok2([x]);
2991
3061
  }
2992
- if (x.id !== ID.removeSheet) return ok([x]);
3062
+ if (x.id !== ID.removeSheet) return ok2([x]);
2993
3063
  const gone = sheetOf(x);
2994
3064
  if (namesSheet(y, gone)) return barrier2("a formula names a sheet removed at the same time");
2995
- return ok([x], sheetOf(y) === gone && !isDerived(y) && y.id !== ID.setName && y.id !== ID.removeName ? [`${gone}: the sheet was removed`] : []);
3065
+ return ok2([x], sheetOf(y) === gone && !isDerived(y) && y.id !== ID.setName && y.id !== ID.removeName ? [`${gone}: the sheet was removed`] : []);
2996
3066
  }
2997
3067
  function annotateSheetOps(group, sheetOrder) {
2998
3068
  const order = [...sheetOrder];
@@ -3090,22 +3160,22 @@ function sortPair(x, y, sx, sy) {
3090
3160
  const a = sortOf(x).range;
3091
3161
  const b = sortOf(y).range;
3092
3162
  const overlap = a.startRow <= b.endRow && b.startRow <= a.endRow && a.startColumn <= b.endColumn && b.startColumn <= a.endColumn;
3093
- return overlap ? barrier2("two sorts of overlapping ranges at once") : ok([x]);
3163
+ return overlap ? barrier2("two sorts of overlapping ranges at once") : ok2([x]);
3094
3164
  }
3095
3165
  if (xs) {
3096
3166
  if (sy) {
3097
3167
  const t = sortThrough(sortOf(x), sy);
3098
- return t ? ok(buildSort(x, t)) : barrier2("a row or column move through a sorted range");
3168
+ return t ? ok2(buildSort(x, t)) : barrier2("a row or column move through a sorted range");
3099
3169
  }
3100
- return ok([x]);
3170
+ return ok2([x]);
3101
3171
  }
3102
3172
  const o = sortOf(y);
3103
3173
  const Q = sortQ(o);
3104
3174
  const moved = (r) => r >= o.range.startRow && r <= o.range.endRow && Q.has(r);
3105
3175
  if (sx) {
3106
- if (sx.axis === "col") return sx.op.kind === "move" && !sortThrough(o, sx) ? barrier2("a column move through a sorted range") : ok([x]);
3107
- if (sx.op.kind === "insert") return ok([x]);
3108
- if (sx.op.kind === "move") return sortThrough(o, sx) ? ok([x]) : barrier2("a row move through a sorted range");
3176
+ if (sx.axis === "col") return sx.op.kind === "move" && !sortThrough(o, sx) ? barrier2("a column move through a sorted range") : ok2([x]);
3177
+ if (sx.op.kind === "insert") return ok2([x]);
3178
+ if (sx.op.kind === "move") return sortThrough(o, sx) ? ok2([x]) : barrier2("a row move through a sorted range");
3109
3179
  const rows = [];
3110
3180
  let partial = false;
3111
3181
  for (let i = sx.op.start; i < sx.op.start + sx.op.count; i++) {
@@ -3113,7 +3183,7 @@ function sortPair(x, y, sx, sy) {
3113
3183
  rows.push(Q.get(i) ?? i);
3114
3184
  }
3115
3185
  if (partial) return barrier2("a row remove against a concurrent sort of those rows");
3116
- return ok([x]);
3186
+ return ok2([x]);
3117
3187
  }
3118
3188
  if (x.id === ID.values) {
3119
3189
  const out = {};
@@ -3124,7 +3194,7 @@ function sortPair(x, y, sx, sy) {
3124
3194
  changed = true;
3125
3195
  } else putCell(out, r, c, v);
3126
3196
  });
3127
- return changed ? ok([cellsMutation(x, out)]) : ok([x]);
3197
+ return changed ? ok2([cellsMutation(x, out)]) : ok2([x]);
3128
3198
  }
3129
3199
  if (isNumfmt(x)) {
3130
3200
  const parts = nfParts(x).map((p) => {
@@ -3140,9 +3210,9 @@ function sortPair(x, y, sx, sy) {
3140
3210
  }
3141
3211
  return { ...p, ranges };
3142
3212
  });
3143
- return ok(nfBuild(x, parts));
3213
+ return ok2(nfBuild(x, parts));
3144
3214
  }
3145
- return ok([x]);
3215
+ return ok2([x]);
3146
3216
  }
3147
3217
  function familyOf(id) {
3148
3218
  const e = SHEET_MUTATIONS[id];
@@ -3158,13 +3228,15 @@ function transformMutation(x, y, side) {
3158
3228
  if (why) return barrier2(why);
3159
3229
  }
3160
3230
  }
3231
+ const ca = transformCommentAnchor(x, y, side);
3232
+ if (ca) return ca;
3161
3233
  const pb = PAIR_BARRIERS[pairKey(x.id, y.id)];
3162
3234
  if (pb) return barrier2(`${x.id} \xD7 ${y.id}: ${pb.reason}${pb.seed === null ? "" : ` (fuzz seed ${pb.seed})`}`);
3163
3235
  const sp = sheetPair(x, y, side);
3164
3236
  if (sp) return sp;
3165
3237
  const fp = formulaPair(x, y, side);
3166
3238
  if (fp) return fp;
3167
- if (sheetOf(x) !== sheetOf(y)) return ok([x]);
3239
+ if (sheetOf(x) !== sheetOf(y)) return ok2([x]);
3168
3240
  const fx = familyOf(x.id);
3169
3241
  const fy = familyOf(y.id);
3170
3242
  const sy = structuralOf(y);
@@ -3176,11 +3248,11 @@ function transformMutation(x, y, side) {
3176
3248
  const np = numfmtPair(x, y, side, sx, sy);
3177
3249
  if (np) return np;
3178
3250
  if (sx && sy) {
3179
- if (sx.axis !== sy.axis) return ok([x]);
3251
+ if (sx.axis !== sy.axis) return ok2([x]);
3180
3252
  const out = transformAxis(sx.op, sy.op, side);
3181
3253
  if (!out) return barrier2(`${x.id} over ${y.id}: moved blocks overlap in part, or the block would split`);
3182
3254
  const dropped = out.length === 0 && sx.op.kind === "move" ? [`${sheetOf(x)}: moved ${sx.axis}s`] : [];
3183
- return ok(out.map((o) => buildStructural(x, sx.axis, o)), [], dropped);
3255
+ return ok2(out.map((o) => buildStructural(x, sx.axis, o)), [], dropped);
3184
3256
  }
3185
3257
  if (sy) {
3186
3258
  if (fx === "merge") {
@@ -3191,23 +3263,23 @@ function transformMutation(x, y, side) {
3191
3263
  if (t) kept.push(t);
3192
3264
  else dropped.push(rangeRef(sheetOf(x), r));
3193
3265
  }
3194
- return ok(kept.length ? [withRanges(x, kept)] : [], [], x.id === ID.addMerge ? dropped : []);
3266
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], x.id === ID.addMerge ? dropped : []);
3195
3267
  }
3196
3268
  if (fx === "size") {
3197
3269
  const size = sizeOf(x);
3198
- if (size.axis !== sy.axis) return ok([x]);
3270
+ if (size.axis !== sy.axis) return ok2([x]);
3199
3271
  const next = /* @__PURE__ */ new Map();
3200
3272
  for (const [i, v] of size.values) {
3201
3273
  const m = mapIndex(sy.op, i);
3202
3274
  if (m !== null) next.set(m, v);
3203
3275
  }
3204
3276
  const built = buildSize(x, next);
3205
- return ok(built ? [built] : []);
3277
+ return ok2(built ? [built] : []);
3206
3278
  }
3207
- return ok([x]);
3279
+ return ok2([x]);
3208
3280
  }
3209
3281
  if (sx) {
3210
- if (fy !== "merge" || y.id !== ID.addMerge) return ok([x]);
3282
+ if (fy !== "merge" || y.id !== ID.addMerge) return ok2([x]);
3211
3283
  const remove = [];
3212
3284
  const add = [];
3213
3285
  for (const r of mergeRanges(y)) {
@@ -3217,11 +3289,11 @@ function transformMutation(x, y, side) {
3217
3289
  if (t.range) add.push(t.range);
3218
3290
  }
3219
3291
  const lostMerges = mergeRanges(y).filter((r) => mergeThrough(sx, r).range === null).map((r) => rangeRef(sheetOf(y), r));
3220
- if (!remove.length) return ok([x], lostMerges);
3292
+ if (!remove.length) return ok2([x], lostMerges);
3221
3293
  const sheet = sheetOf(x);
3222
3294
  const pre = sx.op.kind === "insert" ? [] : [mergeMutation(ID.removeMerge, sheet, remove)];
3223
3295
  const mid = sx.op.kind === "insert" ? [mergeMutation(ID.removeMerge, sheet, remove)] : [];
3224
- return ok([...pre, x, ...mid, ...add.length ? [mergeMutation(ID.addMerge, sheet, add)] : []], lostMerges);
3296
+ return ok2([...pre, x, ...mid, ...add.length ? [mergeMutation(ID.addMerge, sheet, add)] : []], lostMerges);
3225
3297
  }
3226
3298
  if (fx === "cell" && fy === "cell") return transformCellsOverCells(x, y, side);
3227
3299
  if (fx === "merge" && fy === "merge") {
@@ -3230,45 +3302,45 @@ function transformMutation(x, y, side) {
3230
3302
  const hit = (r) => yr.some((q) => intersects(r, q));
3231
3303
  const sheet = sheetOf(x);
3232
3304
  if (x.id === ID.addMerge && y.id === ID.addMerge) {
3233
- if (!xr.some(hit)) return ok([x]);
3305
+ if (!xr.some(hit)) return ok2([x]);
3234
3306
  if (side === "left") {
3235
3307
  const lost = yr.filter((q) => xr.some((r) => intersects(r, q))).map((q) => rangeRef(sheet, q));
3236
- return ok([mergeMutation(ID.removeMerge, sheet, xr.filter(hit)), x], lost);
3308
+ return ok2([mergeMutation(ID.removeMerge, sheet, xr.filter(hit)), x], lost);
3237
3309
  }
3238
3310
  const kept = xr.filter((r) => !hit(r));
3239
- return ok(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3311
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3240
3312
  }
3241
3313
  if (x.id === ID.addMerge && y.id === ID.removeMerge) {
3242
- 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)) : []);
3314
+ 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)) : []);
3243
3315
  const kept = xr.filter((r) => !hit(r));
3244
- return ok(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3316
+ return ok2(kept.length ? [withRanges(x, kept)] : [], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3245
3317
  }
3246
3318
  if (x.id === ID.removeMerge && y.id === ID.addMerge) {
3247
3319
  const touched = yr.filter((q) => xr.some((r) => intersects(r, q)));
3248
- if (!touched.length) return ok([x]);
3249
- if (side === "left") return ok([x], touched.map((q) => rangeRef(sheet, q)));
3250
- return ok([x, mergeMutation(ID.addMerge, sheet, touched)], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3320
+ if (!touched.length) return ok2([x]);
3321
+ if (side === "left") return ok2([x], touched.map((q) => rangeRef(sheet, q)));
3322
+ return ok2([x, mergeMutation(ID.addMerge, sheet, touched)], [], xr.filter(hit).map((r) => rangeRef(sheet, r)));
3251
3323
  }
3252
- return ok([x]);
3324
+ return ok2([x]);
3253
3325
  }
3254
3326
  if (fx === "size" && fy === "size") {
3255
3327
  const a = sizeOf(x);
3256
3328
  const b = sizeOf(y);
3257
- if (a.axis !== b.axis || a.attr !== b.attr) return ok([x]);
3329
+ if (a.axis !== b.axis || a.attr !== b.attr) return ok2([x]);
3258
3330
  if (side === "left") {
3259
3331
  const lost = [...a.values.keys()].filter((i) => b.values.has(i)).map((i) => `${sheetOf(x)}: ${a.axis} ${i + 1} ${a.attr}`);
3260
- return ok([x], lost);
3332
+ return ok2([x], lost);
3261
3333
  }
3262
3334
  const next = new Map([...a.values].filter(([i]) => !b.values.has(i)));
3263
3335
  const built = buildSize(x, next);
3264
3336
  const dropped = [...a.values.keys()].filter((i) => b.values.has(i)).map((i) => `${sheetOf(x)}: ${a.axis} ${i + 1} ${a.attr}`);
3265
- return ok(built ? [built] : [], [], dropped);
3337
+ return ok2(built ? [built] : [], [], dropped);
3266
3338
  }
3267
3339
  if (fx === "name" && fy === "name") {
3268
- if (side === "left") return ok([x], [`${sheetOf(x)}: name "${String(y.params.name)}"`]);
3269
- return ok([], [], [`${sheetOf(x)}: name "${String(x.params.name)}"`]);
3340
+ if (side === "left") return ok2([x], [`${sheetOf(x)}: name "${String(y.params.name)}"`]);
3341
+ return ok2([], [], [`${sheetOf(x)}: name "${String(x.params.name)}"`]);
3270
3342
  }
3271
- return ok([x]);
3343
+ return ok2([x]);
3272
3344
  }
3273
3345
  var blocked = (p) => !Array.isArray(p);
3274
3346
  function tSeq(xs, ys, side, acc) {
@@ -3447,10 +3519,10 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3447
3519
  let dropped = 0;
3448
3520
  for (let i = items.length - 1; i >= 0; i--) {
3449
3521
  const item = items[i];
3450
- let ok2 = true;
3522
+ let ok3 = true;
3451
3523
  for (const key of ["undoMutations", "redoMutations"]) {
3452
3524
  const list = item[key];
3453
- if (!ok2 || !list?.length) continue;
3525
+ if (!ok3 || !list?.length) continue;
3454
3526
  const isOperation = (id) => !SHEET_MUTATIONS[id] && id.includes(".operation.");
3455
3527
  const operations = list.filter((m) => isOperation(m.id));
3456
3528
  let shaped = cachedShape(list);
@@ -3459,14 +3531,14 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3459
3531
  shapedLists.set(list, { src: list.slice(), shaped });
3460
3532
  }
3461
3533
  if (shaped.some((m) => m === null)) {
3462
- ok2 = false;
3534
+ ok3 = false;
3463
3535
  continue;
3464
3536
  }
3465
3537
  if (!shaped.length) continue;
3466
3538
  try {
3467
3539
  const r = transformGroup(shaped, remote, "left");
3468
3540
  if (isBarrier(r) || r.op.length === 0) {
3469
- ok2 = false;
3541
+ ok3 = false;
3470
3542
  continue;
3471
3543
  }
3472
3544
  if (r.op.length === shaped.length && r.op.every((m, i2) => m === shaped[i2])) continue;
@@ -3474,10 +3546,10 @@ function rebaseSheetUndoStack(items, remote, unitId) {
3474
3546
  shapedLists.set(next, { src: next.slice(), shaped: r.op });
3475
3547
  item[key] = next;
3476
3548
  } catch {
3477
- ok2 = false;
3549
+ ok3 = false;
3478
3550
  }
3479
3551
  }
3480
- if (!ok2) {
3552
+ if (!ok3) {
3481
3553
  items.splice(i, 1);
3482
3554
  dropped++;
3483
3555
  }
@@ -3698,7 +3770,7 @@ function univerSheetsOtPort(o) {
3698
3770
  return out;
3699
3771
  };
3700
3772
  const sheetOrder = () => (o.workbook()?.getSheets() ?? []).map((ws) => ws.getSheetId());
3701
- const openGroup = (label) => ({ label, order: sheetOrder(), sheets: sheetNames(), names: definedNames(), mutations: [], inverses: [], notShared: null });
3773
+ const openGroup = (label2) => ({ label: label2, order: sheetOrder(), sheets: sheetNames(), names: definedNames(), mutations: [], inverses: [], notShared: null });
3702
3774
  const emit = (e) => {
3703
3775
  for (const l of [...listeners]) {
3704
3776
  try {
@@ -3954,8 +4026,8 @@ function univerSheetsOtPort(o) {
3954
4026
  const a = forApply(m);
3955
4027
  applying = true;
3956
4028
  try {
3957
- const ok2 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
3958
- if (ok2 === false) throw new Error(`"${m.id}" was refused by the editor`);
4029
+ const ok3 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
4030
+ if (ok3 === false) throw new Error(`"${m.id}" was refused by the editor`);
3959
4031
  } finally {
3960
4032
  applying = false;
3961
4033
  }