@ai-matrx/office 0.8.15 → 0.8.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -736,6 +736,8 @@ interface SheetsCommandService {
736
736
  interface SheetsWorksheetLike {
737
737
  getSheetId(): string;
738
738
  getName(): string;
739
+ getMaxRows?(): number;
740
+ getMaxColumns?(): number;
739
741
  getCellRaw(row: number, col: number): Obj | null | undefined;
740
742
  getMergeData(): SheetRange[];
741
743
  }
@@ -760,13 +762,44 @@ interface UniverSheetsOtPortOptions {
760
762
  saveUnit?(unitId: string): unknown | null;
761
763
  /** Univer's undo/redo service. */
762
764
  undoRedo?(): unknown | null;
765
+ /**
766
+ * This seat's selections on the active sheet (`SheetsSelectionsService`). A remote row/column insert, remove or
767
+ * move carries this seat's selection with it, and a selection a remote remove took away is clamped to the
768
+ * sheet: a selection left past the sheet's edge breaks every reader of the active range.
769
+ */
770
+ selections?: {
771
+ sheetId(): string | null;
772
+ get(): SheetSelection[] | null | undefined;
773
+ set(selections: SheetSelection[]): void;
774
+ };
763
775
  /** Replace the workbook's whole content, keeping its unit id. */
764
776
  load(snapshot: unknown): void;
765
777
  markDirty(): void;
766
778
  }
779
+ /** One selection as `SheetsSelectionsService` holds it (range, primary cell, style). */
780
+ interface SheetSelection {
781
+ range: SheetRange & {
782
+ rangeType?: number;
783
+ };
784
+ primary?: (Record<string, unknown> & {
785
+ startRow?: number;
786
+ endRow?: number;
787
+ startColumn?: number;
788
+ endColumn?: number;
789
+ actualRow?: number;
790
+ actualColumn?: number;
791
+ }) | null;
792
+ style?: unknown;
793
+ }
767
794
  declare function univerSheetsOtPort(o: UniverSheetsOtPortOptions): SheetsOtPort & {
768
795
  dispose(): void;
796
+ running(): string[];
769
797
  };
798
+ /**
799
+ * This seat's selections after a remote structural op: indices move with their rows/columns; one the op removed
800
+ * lands on the first surviving index; everything is clamped to the sheet; whole-row/column ranges span the sheet.
801
+ */
802
+ declare function moveSelectionsThrough(selections: SheetSelection[], m: SheetMutation, maxRows: number, maxCols: number): SheetSelection[];
770
803
 
771
804
  /**
772
805
  * The canonical Sheets state hash (COLLAB-DESIGN §7.2, C0 item 6, §21.3): two seats holding the same workbook
@@ -823,4 +856,4 @@ declare function startWorkbookOtRoom(port: SheetsOtPort & {
823
856
  dispose?: () => void;
824
857
  }, o: WorkbookOtRoomOptions): Promise<WorkbookOtRoomHandle>;
825
858
 
826
- export { COLLAB_COVERED_KEY, type CollabBase, type CollabMutationInfo, type CollabProviderLike, type CommandServiceLike, DOCS_COLLAB_PROTO, DOCS_TRANSFORM_VERSION, DOC_LOCAL_KEYS, type DocsLocalMutation, type DocsLost, type DocsOp, type DocsOtNotice, type DocsOtPort, type DocsOtRoom, type DocsTransformResult, type DocumentOtFactoryOptions, type DocumentRestoreDeps, type DocumentRestoreResult, type OpenDocsOtRoomOptions, type OpenSheetsOtRoomOptions, type OtRoomsKnob, RICH_TEXT_EDITING, SENDER_VIEW_PARAMS, SHEETS_COLLAB_PROTO, SHEETS_EDIT_GROUP, type SheetOp, type SheetsCommandService, type SheetsLocalEvent, type SheetsLocalGroup, type SheetsNotShared, type SheetsOtAdapter, type SheetsOtAdapterHooks, type SheetsOtNotice, type SheetsOtPort, type SheetsOtRoom, type SheetsWorkbookLike, type SheetsWorksheetLike, type UniverSheetsOtPortOptions, WorkbookCollabSession, type WorkbookCollabSessionOptions, type WorkbookOtRoomHandle, type WorkbookOtRoomOptions, type WorkbookOtRoomsKnob, applyDocsOp, canonicalDocsSnapshot, canonicalDocsString, canonicalKeys, canonicalSheet, canonicalSheetString, composeDocsOps, createSheetsOtAdapter, decodeSheetOp, docsStateHash, documentOtFactory, documentUsesOrderedRoom, dropEmptyStyleRetains, encodeSheetOp, invertDocsOp, isCellEditorScratch, isNoopDocsOp, normalizeDocsOp, openDocsOtRoom, openSheetsOtRoom, rebaseSheetUndoStack, rebaseUndoStack, restoreDocumentSnapshot, sheetsStateHash, stampCovered, stampDeterministicIds, startWorkbookOtRoom, stripSenderView, takeCovered, transformDocsOp, transformSheetOp, transformTextX, undoStacksOf, univerSheetsOtPort, workbookUsesOrderedRoom };
859
+ export { COLLAB_COVERED_KEY, type CollabBase, type CollabMutationInfo, type CollabProviderLike, type CommandServiceLike, DOCS_COLLAB_PROTO, DOCS_TRANSFORM_VERSION, DOC_LOCAL_KEYS, type DocsLocalMutation, type DocsLost, type DocsOp, type DocsOtNotice, type DocsOtPort, type DocsOtRoom, type DocsTransformResult, type DocumentOtFactoryOptions, type DocumentRestoreDeps, type DocumentRestoreResult, type OpenDocsOtRoomOptions, type OpenSheetsOtRoomOptions, type OtRoomsKnob, RICH_TEXT_EDITING, SENDER_VIEW_PARAMS, SHEETS_COLLAB_PROTO, SHEETS_EDIT_GROUP, type SheetOp, type SheetSelection, type SheetsCommandService, type SheetsLocalEvent, type SheetsLocalGroup, type SheetsNotShared, type SheetsOtAdapter, type SheetsOtAdapterHooks, type SheetsOtNotice, type SheetsOtPort, type SheetsOtRoom, type SheetsWorkbookLike, type SheetsWorksheetLike, type UniverSheetsOtPortOptions, WorkbookCollabSession, type WorkbookCollabSessionOptions, type WorkbookOtRoomHandle, type WorkbookOtRoomOptions, type WorkbookOtRoomsKnob, applyDocsOp, canonicalDocsSnapshot, canonicalDocsString, canonicalKeys, canonicalSheet, canonicalSheetString, composeDocsOps, createSheetsOtAdapter, decodeSheetOp, docsStateHash, documentOtFactory, documentUsesOrderedRoom, dropEmptyStyleRetains, encodeSheetOp, invertDocsOp, isCellEditorScratch, isNoopDocsOp, moveSelectionsThrough, normalizeDocsOp, openDocsOtRoom, openSheetsOtRoom, rebaseSheetUndoStack, rebaseUndoStack, restoreDocumentSnapshot, sheetsStateHash, stampCovered, stampDeterministicIds, startWorkbookOtRoom, stripSenderView, takeCovered, transformDocsOp, transformSheetOp, transformTextX, undoStacksOf, univerSheetsOtPort, workbookUsesOrderedRoom };
@@ -736,6 +736,8 @@ interface SheetsCommandService {
736
736
  interface SheetsWorksheetLike {
737
737
  getSheetId(): string;
738
738
  getName(): string;
739
+ getMaxRows?(): number;
740
+ getMaxColumns?(): number;
739
741
  getCellRaw(row: number, col: number): Obj | null | undefined;
740
742
  getMergeData(): SheetRange[];
741
743
  }
@@ -760,13 +762,44 @@ interface UniverSheetsOtPortOptions {
760
762
  saveUnit?(unitId: string): unknown | null;
761
763
  /** Univer's undo/redo service. */
762
764
  undoRedo?(): unknown | null;
765
+ /**
766
+ * This seat's selections on the active sheet (`SheetsSelectionsService`). A remote row/column insert, remove or
767
+ * move carries this seat's selection with it, and a selection a remote remove took away is clamped to the
768
+ * sheet: a selection left past the sheet's edge breaks every reader of the active range.
769
+ */
770
+ selections?: {
771
+ sheetId(): string | null;
772
+ get(): SheetSelection[] | null | undefined;
773
+ set(selections: SheetSelection[]): void;
774
+ };
763
775
  /** Replace the workbook's whole content, keeping its unit id. */
764
776
  load(snapshot: unknown): void;
765
777
  markDirty(): void;
766
778
  }
779
+ /** One selection as `SheetsSelectionsService` holds it (range, primary cell, style). */
780
+ interface SheetSelection {
781
+ range: SheetRange & {
782
+ rangeType?: number;
783
+ };
784
+ primary?: (Record<string, unknown> & {
785
+ startRow?: number;
786
+ endRow?: number;
787
+ startColumn?: number;
788
+ endColumn?: number;
789
+ actualRow?: number;
790
+ actualColumn?: number;
791
+ }) | null;
792
+ style?: unknown;
793
+ }
767
794
  declare function univerSheetsOtPort(o: UniverSheetsOtPortOptions): SheetsOtPort & {
768
795
  dispose(): void;
796
+ running(): string[];
769
797
  };
798
+ /**
799
+ * This seat's selections after a remote structural op: indices move with their rows/columns; one the op removed
800
+ * lands on the first surviving index; everything is clamped to the sheet; whole-row/column ranges span the sheet.
801
+ */
802
+ declare function moveSelectionsThrough(selections: SheetSelection[], m: SheetMutation, maxRows: number, maxCols: number): SheetSelection[];
770
803
 
771
804
  /**
772
805
  * The canonical Sheets state hash (COLLAB-DESIGN §7.2, C0 item 6, §21.3): two seats holding the same workbook
@@ -823,4 +856,4 @@ declare function startWorkbookOtRoom(port: SheetsOtPort & {
823
856
  dispose?: () => void;
824
857
  }, o: WorkbookOtRoomOptions): Promise<WorkbookOtRoomHandle>;
825
858
 
826
- export { COLLAB_COVERED_KEY, type CollabBase, type CollabMutationInfo, type CollabProviderLike, type CommandServiceLike, DOCS_COLLAB_PROTO, DOCS_TRANSFORM_VERSION, DOC_LOCAL_KEYS, type DocsLocalMutation, type DocsLost, type DocsOp, type DocsOtNotice, type DocsOtPort, type DocsOtRoom, type DocsTransformResult, type DocumentOtFactoryOptions, type DocumentRestoreDeps, type DocumentRestoreResult, type OpenDocsOtRoomOptions, type OpenSheetsOtRoomOptions, type OtRoomsKnob, RICH_TEXT_EDITING, SENDER_VIEW_PARAMS, SHEETS_COLLAB_PROTO, SHEETS_EDIT_GROUP, type SheetOp, type SheetsCommandService, type SheetsLocalEvent, type SheetsLocalGroup, type SheetsNotShared, type SheetsOtAdapter, type SheetsOtAdapterHooks, type SheetsOtNotice, type SheetsOtPort, type SheetsOtRoom, type SheetsWorkbookLike, type SheetsWorksheetLike, type UniverSheetsOtPortOptions, WorkbookCollabSession, type WorkbookCollabSessionOptions, type WorkbookOtRoomHandle, type WorkbookOtRoomOptions, type WorkbookOtRoomsKnob, applyDocsOp, canonicalDocsSnapshot, canonicalDocsString, canonicalKeys, canonicalSheet, canonicalSheetString, composeDocsOps, createSheetsOtAdapter, decodeSheetOp, docsStateHash, documentOtFactory, documentUsesOrderedRoom, dropEmptyStyleRetains, encodeSheetOp, invertDocsOp, isCellEditorScratch, isNoopDocsOp, normalizeDocsOp, openDocsOtRoom, openSheetsOtRoom, rebaseSheetUndoStack, rebaseUndoStack, restoreDocumentSnapshot, sheetsStateHash, stampCovered, stampDeterministicIds, startWorkbookOtRoom, stripSenderView, takeCovered, transformDocsOp, transformSheetOp, transformTextX, undoStacksOf, univerSheetsOtPort, workbookUsesOrderedRoom };
859
+ export { COLLAB_COVERED_KEY, type CollabBase, type CollabMutationInfo, type CollabProviderLike, type CommandServiceLike, DOCS_COLLAB_PROTO, DOCS_TRANSFORM_VERSION, DOC_LOCAL_KEYS, type DocsLocalMutation, type DocsLost, type DocsOp, type DocsOtNotice, type DocsOtPort, type DocsOtRoom, type DocsTransformResult, type DocumentOtFactoryOptions, type DocumentRestoreDeps, type DocumentRestoreResult, type OpenDocsOtRoomOptions, type OpenSheetsOtRoomOptions, type OtRoomsKnob, RICH_TEXT_EDITING, SENDER_VIEW_PARAMS, SHEETS_COLLAB_PROTO, SHEETS_EDIT_GROUP, type SheetOp, type SheetSelection, type SheetsCommandService, type SheetsLocalEvent, type SheetsLocalGroup, type SheetsNotShared, type SheetsOtAdapter, type SheetsOtAdapterHooks, type SheetsOtNotice, type SheetsOtPort, type SheetsOtRoom, type SheetsWorkbookLike, type SheetsWorksheetLike, type UniverSheetsOtPortOptions, WorkbookCollabSession, type WorkbookCollabSessionOptions, type WorkbookOtRoomHandle, type WorkbookOtRoomOptions, type WorkbookOtRoomsKnob, applyDocsOp, canonicalDocsSnapshot, canonicalDocsString, canonicalKeys, canonicalSheet, canonicalSheetString, composeDocsOps, createSheetsOtAdapter, decodeSheetOp, docsStateHash, documentOtFactory, documentUsesOrderedRoom, dropEmptyStyleRetains, encodeSheetOp, invertDocsOp, isCellEditorScratch, isNoopDocsOp, moveSelectionsThrough, normalizeDocsOp, openDocsOtRoom, openSheetsOtRoom, rebaseSheetUndoStack, rebaseUndoStack, restoreDocumentSnapshot, sheetsStateHash, stampCovered, stampDeterministicIds, startWorkbookOtRoom, stripSenderView, takeCovered, transformDocsOp, transformSheetOp, transformTextX, undoStacksOf, univerSheetsOtPort, workbookUsesOrderedRoom };
@@ -1220,37 +1220,8 @@ import {
1220
1220
  supabaseOpTransport
1221
1221
  } from "@ai-matrx/data/realtime/collab";
1222
1222
 
1223
- // src/docs/document-model.ts
1224
- import { TextX as TextX2 } from "@univerjs/core";
1225
-
1226
- // src/univer/openEditorContent.ts
1227
- var replacers = /* @__PURE__ */ new Map();
1228
- var keyOf = (kind, recordId) => `${kind}:${recordId}`;
1229
- function hasOpenEditorContent(kind, recordId) {
1230
- return replacers.has(keyOf(kind, recordId));
1231
- }
1232
- async function showSavedSnapshot(kind, recordId, row) {
1233
- const replace = replacers.get(keyOf(kind, recordId));
1234
- if (!replace) return false;
1235
- await replace(row);
1236
- return true;
1237
- }
1238
-
1239
- // src/docs/document-model.ts
1240
- function moveRangesThroughBodyEdit(ranges, actions) {
1241
- const a = actions;
1242
- if (!Array.isArray(a) || a[0] !== "body") return null;
1243
- const sub = a[1];
1244
- if (!sub || sub.et !== "text-x" || !Array.isArray(sub.e)) return null;
1245
- const e = sub.e;
1246
- return ranges.map((r) => {
1247
- const collapsed = r.startOffset === r.endOffset;
1248
- const startOffset = TextX2.transformPosition(e, r.startOffset, collapsed);
1249
- return { startOffset, endOffset: collapsed ? startOffset : TextX2.transformPosition(e, r.endOffset, true) };
1250
- });
1251
- }
1252
-
1253
1223
  // src/docs/remote-carets.ts
1224
+ import { TextX as TextX2 } from "@univerjs/core";
1254
1225
  var CARET_HEARTBEAT_MS = 2e3;
1255
1226
  var CARET_STALE_MS = 12e3;
1256
1227
  var CARET_MAX_RANGES = 4;
@@ -1260,6 +1231,18 @@ function publishedCaretFromSelection(sel, now) {
1260
1231
  const ranges = sel.slice(0, CARET_MAX_RANGES).map((r) => ({ start: Math.min(r.startOffset, r.endOffset), end: Math.max(r.startOffset, r.endOffset) }));
1261
1232
  return { ranges, at: now };
1262
1233
  }
1234
+ function movePeerRangesThroughBodyEdit(ranges, actions) {
1235
+ const a = actions;
1236
+ if (!Array.isArray(a) || a[0] !== "body") return null;
1237
+ const sub = a[1];
1238
+ if (!sub || sub.et !== "text-x" || !Array.isArray(sub.e)) return null;
1239
+ const e = sub.e;
1240
+ return ranges.map((r) => {
1241
+ const collapsed = r.start === r.end;
1242
+ const start = TextX2.transformPosition(e, r.start, false);
1243
+ return { start, end: collapsed ? start : TextX2.transformPosition(e, r.end, true) };
1244
+ });
1245
+ }
1263
1246
  var sameRanges = (a, b) => a.length === b.length && a.every((r, i) => r.start === b[i].start && r.end === b[i].end);
1264
1247
  function readCaret(raw) {
1265
1248
  const c = raw?.caret;
@@ -1311,9 +1294,8 @@ var RemoteCaretBook = class {
1311
1294
  shiftThrough(actions) {
1312
1295
  let moved = false;
1313
1296
  for (const c of this.carets.values()) {
1314
- const next = moveRangesThroughBodyEdit(c.ranges.map((r) => ({ startOffset: r.start, endOffset: r.end })), actions);
1315
- if (!next) return false;
1316
- const ranges = next.map((r) => ({ start: r.startOffset, end: r.endOffset }));
1297
+ const ranges = movePeerRangesThroughBodyEdit(c.ranges, actions);
1298
+ if (!ranges) return false;
1317
1299
  if (!sameRanges(ranges, c.ranges)) {
1318
1300
  c.ranges = ranges;
1319
1301
  moved = true;
@@ -1516,6 +1498,21 @@ function documentOtFactory(o) {
1516
1498
 
1517
1499
  // src/docs/document-restore.ts
1518
1500
  import { collabReplace as collabReplace2, collabRoomExists as collabRoomExists2 } from "@ai-matrx/data/realtime/collab";
1501
+
1502
+ // src/univer/openEditorContent.ts
1503
+ var replacers = /* @__PURE__ */ new Map();
1504
+ var keyOf = (kind, recordId) => `${kind}:${recordId}`;
1505
+ function hasOpenEditorContent(kind, recordId) {
1506
+ return replacers.has(keyOf(kind, recordId));
1507
+ }
1508
+ async function showSavedSnapshot(kind, recordId, row) {
1509
+ const replace = replacers.get(keyOf(kind, recordId));
1510
+ if (!replace) return false;
1511
+ await replace(row);
1512
+ return true;
1513
+ }
1514
+
1515
+ // src/docs/document-restore.ts
1519
1516
  var defaultDeps = {
1520
1517
  client: () => getDocsHost().getSupabase(),
1521
1518
  roomExists: collabRoomExists2,
@@ -3124,21 +3121,36 @@ function univerSheetsOtPort(o) {
3124
3121
  settle();
3125
3122
  });
3126
3123
  const guarded = cs;
3127
- if (!guarded[DEPTH_GUARD] && typeof cs.executeCommand === "function") {
3124
+ if (!guarded[DEPTH_GUARD]) {
3128
3125
  const trackers = /* @__PURE__ */ new Set();
3129
3126
  guarded[DEPTH_GUARD] = trackers;
3130
- const original = cs.executeCommand.bind(cs);
3131
- cs.executeCommand = async (id, params, options) => {
3132
- const depths = new Map([...trackers].map((t) => [t, t.stack.length]));
3127
+ const restore = (depths) => {
3128
+ for (const [t, d] of depths) {
3129
+ if (t.stack.length > d) {
3130
+ t.stack.length = d;
3131
+ t.settle();
3132
+ }
3133
+ }
3134
+ };
3135
+ const depthsNow = () => new Map([...trackers].map((t) => [t, t.stack.length]));
3136
+ if (typeof cs.executeCommand === "function") {
3137
+ const original = cs.executeCommand.bind(cs);
3138
+ cs.executeCommand = async (id, params, options) => {
3139
+ const depths = depthsNow();
3140
+ try {
3141
+ return await original(id, params, options);
3142
+ } finally {
3143
+ restore(depths);
3144
+ }
3145
+ };
3146
+ }
3147
+ const originalSync = cs.syncExecuteCommand.bind(cs);
3148
+ cs.syncExecuteCommand = (id, params, options) => {
3149
+ const depths = depthsNow();
3133
3150
  try {
3134
- return await original(id, params, options);
3151
+ return originalSync(id, params, options);
3135
3152
  } finally {
3136
- for (const [t, d] of depths) {
3137
- if (t.stack.length > d) {
3138
- t.stack.length = d;
3139
- t.settle();
3140
- }
3141
- }
3153
+ restore(depths);
3142
3154
  }
3143
3155
  };
3144
3156
  }
@@ -3228,12 +3240,30 @@ function univerSheetsOtPort(o) {
3228
3240
  }
3229
3241
  if (lone && tracker.stack.length === 0) settle();
3230
3242
  });
3243
+ const followSelection = (m) => {
3244
+ const sel = o.selections;
3245
+ if (!sel || !axisOpOf(m)) return;
3246
+ try {
3247
+ const sheet = String(m.params.subUnitId ?? "");
3248
+ if (sel.sheetId() !== sheet) return;
3249
+ const ws = o.workbook()?.getSheetBySheetId(sheet);
3250
+ const current = sel.get();
3251
+ if (!ws || !current?.length) return;
3252
+ const rows = ws.getMaxRows?.() ?? Number.MAX_SAFE_INTEGER;
3253
+ const cols = ws.getMaxColumns?.() ?? Number.MAX_SAFE_INTEGER;
3254
+ sel.set(moveSelectionsThrough(json(current), m, rows, cols));
3255
+ } catch (err) {
3256
+ console.warn("[sheets-ot] could not move this seat's selection past a collaborator's row or column change", err);
3257
+ }
3258
+ };
3231
3259
  return {
3232
3260
  onLocal(listener) {
3233
3261
  listeners.add(listener);
3234
3262
  return () => void listeners.delete(listener);
3235
3263
  },
3236
3264
  busy: () => tracker.stack.length > 0 || group !== null,
3265
+ /** The outermost commands still running here (why the port is busy), for logs. */
3266
+ running: () => [...tracker.stack, ...group && tracker.stack.length === 0 ? ["(group)"] : []],
3237
3267
  whenIdle(fn) {
3238
3268
  if (tracker.stack.length === 0 && !group) fn();
3239
3269
  else idle.push(fn);
@@ -3249,6 +3279,7 @@ function univerSheetsOtPort(o) {
3249
3279
  } finally {
3250
3280
  applying = false;
3251
3281
  }
3282
+ followSelection(m);
3252
3283
  },
3253
3284
  snapshot() {
3254
3285
  const wb = o.workbook();
@@ -3286,6 +3317,68 @@ function fullContent(cell) {
3286
3317
  if (out.v === null) delete out.t;
3287
3318
  return out;
3288
3319
  }
3320
+ function axisOpOf(m) {
3321
+ const p = m.params;
3322
+ const span = (r, axis) => axis === "row" ? [r.startRow, r.endRow - r.startRow + 1] : [r.startColumn, r.endColumn - r.startColumn + 1];
3323
+ switch (m.id) {
3324
+ case "sheet.mutation.insert-row": {
3325
+ const [at, count] = span(p.range, "row");
3326
+ return { axis: "row", op: { kind: "insert", at, count } };
3327
+ }
3328
+ case "sheet.mutation.insert-col": {
3329
+ const [at, count] = span(p.range, "col");
3330
+ return { axis: "col", op: { kind: "insert", at, count } };
3331
+ }
3332
+ case "sheet.mutation.remove-rows": {
3333
+ const [start, count] = span(p.range, "row");
3334
+ return { axis: "row", op: { kind: "remove", start, count } };
3335
+ }
3336
+ case "sheet.mutation.remove-col": {
3337
+ const [start, count] = span(p.range, "col");
3338
+ return { axis: "col", op: { kind: "remove", start, count } };
3339
+ }
3340
+ case "sheet.mutation.move-rows": {
3341
+ const [from, count] = span(p.sourceRange, "row");
3342
+ return { axis: "row", op: { kind: "move", from, count, to: p.targetRange.startRow } };
3343
+ }
3344
+ case "sheet.mutation.move-columns": {
3345
+ const [from, count] = span(p.sourceRange, "col");
3346
+ return { axis: "col", op: { kind: "move", from, count, to: p.targetRange.startColumn } };
3347
+ }
3348
+ default:
3349
+ return null;
3350
+ }
3351
+ }
3352
+ function moveSelectionsThrough(selections, m, maxRows, maxCols) {
3353
+ const a = axisOpOf(m);
3354
+ const clamp = (v, max) => Math.max(0, Math.min(v, Math.max(0, max - 1)));
3355
+ const through = (i, axis) => {
3356
+ if (typeof i !== "number") return i;
3357
+ let next = i;
3358
+ if (a && a.axis === axis) {
3359
+ const mapped = mapIndex(a.op, i);
3360
+ next = mapped ?? (a.op.kind === "remove" ? a.op.start : i);
3361
+ }
3362
+ return clamp(next, axis === "row" ? maxRows : maxCols);
3363
+ };
3364
+ const box = (r, rangeType) => {
3365
+ const out = { ...r };
3366
+ for (const k of ["startRow", "endRow", "actualRow"]) if (k in out) out[k] = through(out[k], "row");
3367
+ for (const k of ["startColumn", "endColumn", "actualColumn"]) if (k in out) out[k] = through(out[k], "col");
3368
+ if (typeof out.startRow === "number" && typeof out.endRow === "number" && out.endRow < out.startRow) out.endRow = out.startRow;
3369
+ if (typeof out.startColumn === "number" && typeof out.endColumn === "number" && out.endColumn < out.startColumn) out.endColumn = out.startColumn;
3370
+ if (rangeType === 1 || rangeType === 3) {
3371
+ out.startColumn = 0;
3372
+ out.endColumn = Math.max(0, maxCols - 1);
3373
+ }
3374
+ if (rangeType === 2 || rangeType === 3) {
3375
+ out.startRow = 0;
3376
+ out.endRow = Math.max(0, maxRows - 1);
3377
+ }
3378
+ return out;
3379
+ };
3380
+ return selections.map((s) => ({ ...s, range: box(s.range, s.range.rangeType), ...s.primary ? { primary: box(s.primary) } : {} }));
3381
+ }
3289
3382
 
3290
3383
  // src/sheets/workbook-ot-room.ts
3291
3384
  import * as Y3 from "yjs";
@@ -3473,6 +3566,7 @@ export {
3473
3566
  invertDocsOp,
3474
3567
  isCellEditorScratch,
3475
3568
  isNoopDocsOp,
3569
+ moveSelectionsThrough,
3476
3570
  normalizeDocsOp,
3477
3571
  openDocsOtRoom,
3478
3572
  openSheetsOtRoom,