@ai-matrx/office 0.8.15 → 0.8.16

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.
@@ -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
  }