@ai-matrx/office 0.8.35 → 0.8.37

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.
@@ -45,7 +45,7 @@ interface SheetRange {
45
45
  * column width, worksheet name. C5b: formula text in cells (`f`, array `ref`) and defined names. Shared
46
46
  * formulas (`si`) stay barriers (see transform.ts cellBarrier); ranged resources are C5c.
47
47
  */
48
- type SheetFamily = "cell" | "structure" | "merge" | "size" | "name" | "defname" | "numfmt" | "count" | "sheet" | "sort" | "anchor" | "cf" | "dv" | "filter";
48
+ type SheetFamily = "cell" | "structure" | "merge" | "size" | "name" | "defname" | "numfmt" | "count" | "sheet" | "sort" | "anchor" | "cf" | "dv" | "filter" | "note";
49
49
  interface CoveredEntry {
50
50
  readonly kind: "covered";
51
51
  readonly family: SheetFamily;
@@ -103,7 +103,7 @@ declare function mapIndex(op: AxisOp, i: number): number | null;
103
103
  */
104
104
  declare function transformAxis(x: AxisOp, y: AxisOp, side: Side): AxisOp[] | null;
105
105
 
106
- declare const SHEET_TRANSFORMER_VERSION = "c5d-1";
106
+ declare const SHEET_TRANSFORMER_VERSION = "c5f-1";
107
107
  /**
108
108
  * Pairs the fuzz proved divergent (or that have no transform yet), as unordered mutation-id pairs, with the
109
109
  * failing seed. Each returns a Barrier until it has its own correct transform under a new proto.
@@ -45,7 +45,7 @@ interface SheetRange {
45
45
  * column width, worksheet name. C5b: formula text in cells (`f`, array `ref`) and defined names. Shared
46
46
  * formulas (`si`) stay barriers (see transform.ts cellBarrier); ranged resources are C5c.
47
47
  */
48
- type SheetFamily = "cell" | "structure" | "merge" | "size" | "name" | "defname" | "numfmt" | "count" | "sheet" | "sort" | "anchor" | "cf" | "dv" | "filter";
48
+ type SheetFamily = "cell" | "structure" | "merge" | "size" | "name" | "defname" | "numfmt" | "count" | "sheet" | "sort" | "anchor" | "cf" | "dv" | "filter" | "note";
49
49
  interface CoveredEntry {
50
50
  readonly kind: "covered";
51
51
  readonly family: SheetFamily;
@@ -103,7 +103,7 @@ declare function mapIndex(op: AxisOp, i: number): number | null;
103
103
  */
104
104
  declare function transformAxis(x: AxisOp, y: AxisOp, side: Side): AxisOp[] | null;
105
105
 
106
- declare const SHEET_TRANSFORMER_VERSION = "c5d-1";
106
+ declare const SHEET_TRANSFORMER_VERSION = "c5f-1";
107
107
  /**
108
108
  * Pairs the fuzz proved divergent (or that have no transform yet), as unordered mutation-id pairs, with the
109
109
  * failing seed. Each returns a Barrier until it has its own correct transform under a new proto.
@@ -110,6 +110,13 @@ var SHEET_MUTATIONS = {
110
110
  "data-validation.mutation.updateRule": covered("dv", "ruleId", "payload", "source", "derived"),
111
111
  "data-validation.mutation.removeRule": covered("dv", "ruleId", "source", "derived"),
112
112
  "sheet.mutation.set-filter-range": covered("filter", "range", "derived"),
113
+ // C5f: Univer's cell notes. Their transform is built (comment-anchor-transform.ts `transformCellNote`, pairwise and
114
+ // chained fuzz green) but the session fuzz still diverges on note cells (seed 1015, 6 seats: a note at column 5 on
115
+ // one seat, 8 on another), so they stay barriers until that seed is green. Covered form, for the next lane:
116
+ // covered("note", "sheetId", "row", "col", "note" | "noteId", "newPosition", "silent", "derived")
117
+ "sheet.mutation.update-note": barrier("C5c", "cell note: the session fuzz diverges on note cells (seed 1015)"),
118
+ "sheet.mutation.remove-note": barrier("C5c", "cell note: the session fuzz diverges on note cells (seed 1015)"),
119
+ "sheet.mutation.update-note-position": barrier("C5c", "cell note: the session fuzz diverges on note cells (seed 1015)"),
113
120
  "sheet.mutation.set-filter-criteria": covered("filter", "col", "criteria", "reCalc", "derived"),
114
121
  "sheet.mutation.remove-filter": covered("filter", "derived"),
115
122
  "sheet.mutation.add-table": barrier("C5c", RESOURCE),
@@ -122,9 +129,6 @@ var SHEET_MUTATIONS = {
122
129
  "sheets.mutation.update-hyper-link": barrier("C5c", RESOURCE),
123
130
  "sheets.mutation.update-hyper-link-ref": barrier("C5c", RESOURCE),
124
131
  "sheets.mutation.update-rich-hyper-link": barrier("C5c", RESOURCE),
125
- "sheet.mutation.update-note": barrier("C5c", RESOURCE),
126
- "sheet.mutation.remove-note": barrier("C5c", RESOURCE),
127
- "sheet.mutation.update-note-position": barrier("C5c", RESOURCE),
128
132
  "sheet.mutation.set-drawing-apply": barrier("C5c", RESOURCE),
129
133
  "sheet.mutation.set-worksheet-background-image": barrier("C5c", RESOURCE),
130
134
  "sheet.mutation.add-range-theme": barrier("C5c", RESOURCE),
@@ -545,7 +549,88 @@ var label = (m) => {
545
549
  const c = cellOf(m);
546
550
  return `${String(m.params.subUnitId ?? "")}!${c ? sheetCellName(c) : "?"} comment`;
547
551
  };
552
+ var UPDATE_NOTE = "sheet.mutation.update-note";
553
+ var REMOVE_NOTE = "sheet.mutation.remove-note";
554
+ var UPDATE_NOTE_POSITION = "sheet.mutation.update-note-position";
555
+ var NOTE_IDS = /* @__PURE__ */ new Set([UPDATE_NOTE, REMOVE_NOTE, UPDATE_NOTE_POSITION]);
556
+ var isNoteMutation = (id) => NOTE_IDS.has(id);
557
+ var cellAt = (row, col) => typeof row === "number" && typeof col === "number" ? { row, col } : null;
558
+ function noteRef(m) {
559
+ const p = m.params;
560
+ const sheet = String(p.sheetId ?? "");
561
+ if (m.id === UPDATE_NOTE) return { role: "write", sheet, id: p.note?.id ? String(p.note.id) : null, cell: cellAt(p.row, p.col) };
562
+ if (m.id === UPDATE_NOTE_POSITION) return { role: "move", sheet, id: p.noteId ? String(p.noteId) : null, cell: cellAt(p.newPosition?.row, p.newPosition?.col) };
563
+ return { role: "remove", sheet, id: p.noteId ? String(p.noteId) : null, cell: p.noteId ? null : cellAt(p.row, p.col) };
564
+ }
565
+ var noteDerived = (m) => m.params.derived === true;
566
+ var noteLabel = (n) => `${n.sheet}!${n.cell ? sheetCellName(n.cell) : "?"} note`;
567
+ var tellNote = (m, n) => noteDerived(m) ? [] : [noteLabel(n)];
568
+ var noteBarrier = (reason) => ({ barrier: true, reason: `note: ${reason}` });
569
+ var removeNoteOf = (sheet, id) => ({ id: REMOVE_NOTE, params: { sheetId: sheet, noteId: id, derived: true } });
570
+ var moveNoteTo = (sheet, id, cell) => ({
571
+ id: UPDATE_NOTE_POSITION,
572
+ params: { sheetId: sheet, noteId: id, newPosition: { row: cell.row, col: cell.col }, derived: true }
573
+ });
574
+ var onSheet = (m, sheet) => String(m.params.subUnitId ?? "") === sheet;
575
+ function transformCellNote(x, y, side) {
576
+ const xn = isNoteMutation(x.id);
577
+ const yn = isNoteMutation(y.id);
578
+ if (!xn && !yn) return null;
579
+ if (!xn) {
580
+ const n2 = noteRef(y);
581
+ if (n2.role === "remove" || !n2.cell || !onSheet(x, n2.sheet)) return ok([x]);
582
+ if (x.id === REMOVE_SHEET) return n2.id ? ok([removeNoteOf(n2.sheet, n2.id), x]) : ok([x]);
583
+ if (!structuralAxisOp(x.id, x.params)) return ok([x]);
584
+ if (!n2.id) return noteBarrier("a note without an id against a row or column change");
585
+ const moved = moveSheetAnchorCell(n2.cell, n2.sheet, x.id, x.params);
586
+ if (!moved) return ok([x, removeNoteOf(n2.sheet, n2.id)]);
587
+ return moved === n2.cell ? ok([x]) : ok([x, moveNoteTo(n2.sheet, n2.id, moved)]);
588
+ }
589
+ const n = noteRef(x);
590
+ if (!yn) {
591
+ if (!onSheet(y, n.sheet)) return ok([x]);
592
+ if (y.id === REMOVE_SHEET) return ok([], [], tellNote(x, n));
593
+ if (!structuralAxisOp(y.id, y.params)) return ok([x]);
594
+ if (n.role === "write" && !n.id) return noteBarrier("a note without an id against a row or column change");
595
+ const p = x.params;
596
+ const from = cellAt(p.row, p.col);
597
+ const fromMoved = from ? moveSheetAnchorCell(from, n.sheet, y.id, y.params) : null;
598
+ if (n.role === "remove") {
599
+ if (n.id) return ok([x]);
600
+ return fromMoved ? ok([{ id: x.id, params: { ...p, row: fromMoved.row, col: fromMoved.col } }]) : ok([]);
601
+ }
602
+ const moved = n.cell ? moveSheetAnchorCell(n.cell, n.sheet, y.id, y.params) : null;
603
+ if (n.role === "write") {
604
+ if (!moved) return ok([], [], tellNote(x, n));
605
+ return ok([moved === n.cell ? x : { id: x.id, params: { ...p, row: moved.row, col: moved.col } }]);
606
+ }
607
+ if (!moved) return n.id ? ok([removeNoteOf(n.sheet, n.id)], [], tellNote(x, n)) : ok([], [], tellNote(x, n));
608
+ const params = { ...p, newPosition: { ...p.newPosition, row: moved.row, col: moved.col } };
609
+ if (fromMoved) Object.assign(params, { row: fromMoved.row, col: fromMoved.col });
610
+ return ok([{ id: x.id, params }]);
611
+ }
612
+ const m = noteRef(y);
613
+ if (n.sheet !== m.sheet) return ok([x]);
614
+ if (!n.id || !m.id) return noteBarrier("a note change addressed by cell against another note change on its sheet");
615
+ if (n.id !== m.id) {
616
+ const sameCell = n.cell && m.cell && n.cell.row === m.cell.row && n.cell.col === m.cell.col;
617
+ return sameCell ? noteBarrier("two notes written to one cell at once") : ok([x]);
618
+ }
619
+ if (n.role === "remove") return ok([x]);
620
+ if (m.role === "remove") return ok([], [], tellNote(x, n));
621
+ if (n.role === "write" && m.role === "move") {
622
+ return m.cell ? ok([{ id: x.id, params: { ...x.params, row: m.cell.row, col: m.cell.col } }]) : ok([x]);
623
+ }
624
+ if (n.role === "move" && m.role === "write") return ok([x]);
625
+ const dx = noteDerived(x);
626
+ const dy = noteDerived(y);
627
+ if (dx && dy) return ok([x]);
628
+ const xWins = dx !== dy ? !dx : side === "left";
629
+ return xWins ? ok([x], tellNote(y, m)) : ok([], [], tellNote(x, n));
630
+ }
548
631
  function transformCommentAnchor(x, y, side) {
632
+ const note = transformCellNote(x, y, side);
633
+ if (note) return note;
549
634
  const xa = x.id === SET_SHEET_COMMENT_ANCHOR;
550
635
  const ya = y.id === SET_SHEET_COMMENT_ANCHOR;
551
636
  if (!xa && !ya) return null;
@@ -666,7 +751,7 @@ registerRangedResource({
666
751
  });
667
752
 
668
753
  // src/collab/sheets/transform/transform.ts
669
- var SHEET_TRANSFORMER_VERSION = "c5d-1";
754
+ var SHEET_TRANSFORMER_VERSION = "c5f-1";
670
755
  var ID = {
671
756
  values: "sheet.mutation.set-range-values",
672
757
  insertRow: "sheet.mutation.insert-row",
@@ -755,6 +840,21 @@ function buildStructural(template, axis, op) {
755
840
  const start = op.kind === "insert" ? op.at : op.start;
756
841
  return { id: template.id, params: { ...p, range: { ...p.range, [a0]: start, [a1]: start + op.count - 1 } } };
757
842
  }
843
+ function crossThrough(x, sy) {
844
+ const [a0, a1] = S(sy.axis);
845
+ const p = x.params;
846
+ const params = { ...p };
847
+ for (const k of ["range", "sourceRange", "targetRange"]) {
848
+ const r = p[k];
849
+ if (!r || typeof r[a0] !== "number" || typeof r[a1] !== "number") continue;
850
+ const spans = spanThrough(sy.op, r[a0], r[a1]);
851
+ if (!spans.length) continue;
852
+ const lo = r[a0] === 0 ? 0 : Math.min(...spans.map(([l]) => l));
853
+ const hi = Math.max(...spans.map(([, h]) => h));
854
+ params[k] = { ...r, [a0]: lo, [a1]: hi };
855
+ }
856
+ return { id: x.id, params };
857
+ }
758
858
  function univerMutationInfo(axis, op) {
759
859
  const FULL2 = { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER };
760
860
  const start = op.kind === "insert" ? op.at : op.start;
@@ -1478,7 +1578,7 @@ function annotateSheetOpsInOrder(group, sheetOrder) {
1478
1578
  let structural = false;
1479
1579
  return group.map((m0) => {
1480
1580
  if (structuralOf(m0)) structural = true;
1481
- const m = structural && rangedSpecOf(m0.id) && !isDerived(m0) ? { id: m0.id, params: { ...m0.params, derived: true } } : m0;
1581
+ const m = structural && (rangedSpecOf(m0.id) || isNoteMutation(m0.id)) && !isDerived(m0) ? { id: m0.id, params: { ...m0.params, derived: true } } : m0;
1482
1582
  if (m.id === ID.insertSheet) {
1483
1583
  const index = typeof m.params.index === "number" ? Math.min(m.params.index, order.length) : order.length;
1484
1584
  order.splice(index, 0, sheetIdOf(m));
@@ -1725,7 +1825,7 @@ function transformMutation(x, y, side) {
1725
1825
  const np = numfmtPair(x, y, side, sx, sy);
1726
1826
  if (np) return np;
1727
1827
  if (sx && sy) {
1728
- if (sx.axis !== sy.axis) return ok2([x]);
1828
+ if (sx.axis !== sy.axis) return ok2([crossThrough(x, sy)]);
1729
1829
  const out = transformAxis(sx.op, sy.op, side);
1730
1830
  if (!out) return barrier2(`${x.id} over ${y.id}: moved blocks overlap in part, or the block would split`);
1731
1831
  const dropped = out.length === 0 && sx.op.kind === "move" ? [`${sheetOf(x)}: moved ${sx.axis}s`] : [];