@ai-matrx/office 0.8.17 → 0.8.19

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.
@@ -252,19 +252,14 @@ declare function invertDocsOp(op: DocsOp, preDoc: unknown): DocsOp;
252
252
  /** Part of `proto` (§6.4): Univer 1.0.4 + this transformer, rules R1–R6. */
253
253
  declare const DOCS_TRANSFORM_VERSION = "univer-1.0.4+docs-ot-r6";
254
254
 
255
- /**
256
- * The canonical Docs state hash (COLLAB-DESIGN §7.2; C0 item 6, `spikes/c0-collab/lib.mjs`).
257
- *
258
- * SHA-256 of the canonical snapshot: keys sorted, empty values dropped, the unit id and seat-local fields
259
- * removed (revision counter, collab stamps, layout state, selections), adjacent equal text runs merged, split
260
- * pieces of one custom range or decoration folded, and `paragraphId` dropped (Univer's TextX.apply mints a
261
- * random one per seat, C0 surprise 3). Header, footer and note bodies get the same rules.
262
- *
263
- * Two seats with equal content hash equal; one character more hashes differently. Browser and Node: the
264
- * digest is Web Crypto's.
265
- */
266
255
  /** Never content: the collab stamps, revision counters, seat-local view state. */
267
256
  declare const DOC_LOCAL_KEYS: string[];
257
+ /**
258
+ * The snapshot as a seat holds it after loading it: what `DocumentModel` / the editor mount do (deterministic
259
+ * ids, `sanitizeUniverDocSnapshot`), then Univer's own model normalisation (`createDocumentSnapshot` inside
260
+ * `DocumentDataModel`). Idempotent: a snapshot a seat saved comes back unchanged in content.
261
+ */
262
+ declare function asLoadedDocsSnapshot(snapshot: unknown): Record<string, unknown>;
268
263
  /** The canonical Docs snapshot: content only, keys sorted, runs normalized, local fields removed. */
269
264
  declare function canonicalDocsSnapshot(snapshot: unknown): unknown;
270
265
  /** The canonical form as the string the hash digests (tests compare these directly). */
@@ -856,4 +851,4 @@ declare function startWorkbookOtRoom(port: SheetsOtPort & {
856
851
  dispose?: () => void;
857
852
  }, o: WorkbookOtRoomOptions): Promise<WorkbookOtRoomHandle>;
858
853
 
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 };
854
+ 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, asLoadedDocsSnapshot, 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 };
@@ -252,19 +252,14 @@ declare function invertDocsOp(op: DocsOp, preDoc: unknown): DocsOp;
252
252
  /** Part of `proto` (§6.4): Univer 1.0.4 + this transformer, rules R1–R6. */
253
253
  declare const DOCS_TRANSFORM_VERSION = "univer-1.0.4+docs-ot-r6";
254
254
 
255
- /**
256
- * The canonical Docs state hash (COLLAB-DESIGN §7.2; C0 item 6, `spikes/c0-collab/lib.mjs`).
257
- *
258
- * SHA-256 of the canonical snapshot: keys sorted, empty values dropped, the unit id and seat-local fields
259
- * removed (revision counter, collab stamps, layout state, selections), adjacent equal text runs merged, split
260
- * pieces of one custom range or decoration folded, and `paragraphId` dropped (Univer's TextX.apply mints a
261
- * random one per seat, C0 surprise 3). Header, footer and note bodies get the same rules.
262
- *
263
- * Two seats with equal content hash equal; one character more hashes differently. Browser and Node: the
264
- * digest is Web Crypto's.
265
- */
266
255
  /** Never content: the collab stamps, revision counters, seat-local view state. */
267
256
  declare const DOC_LOCAL_KEYS: string[];
257
+ /**
258
+ * The snapshot as a seat holds it after loading it: what `DocumentModel` / the editor mount do (deterministic
259
+ * ids, `sanitizeUniverDocSnapshot`), then Univer's own model normalisation (`createDocumentSnapshot` inside
260
+ * `DocumentDataModel`). Idempotent: a snapshot a seat saved comes back unchanged in content.
261
+ */
262
+ declare function asLoadedDocsSnapshot(snapshot: unknown): Record<string, unknown>;
268
263
  /** The canonical Docs snapshot: content only, keys sorted, runs normalized, local fields removed. */
269
264
  declare function canonicalDocsSnapshot(snapshot: unknown): unknown;
270
265
  /** The canonical form as the string the hash digests (tests compare these directly). */
@@ -856,4 +851,4 @@ declare function startWorkbookOtRoom(port: SheetsOtPort & {
856
851
  dispose?: () => void;
857
852
  }, o: WorkbookOtRoomOptions): Promise<WorkbookOtRoomHandle>;
858
853
 
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 };
854
+ 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, asLoadedDocsSnapshot, 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 };
@@ -870,6 +870,104 @@ function invertDocsOp(op, preDoc) {
870
870
  }
871
871
  var DOCS_TRANSFORM_VERSION = "univer-1.0.4+docs-ot-r6";
872
872
 
873
+ // src/univer/collab/docs-ot/state-hash.ts
874
+ import { DocumentDataModel } from "@univerjs/core";
875
+
876
+ // src/docs/sanitize-univer-doc-snapshot.ts
877
+ import { NamedStyleType } from "@univerjs/core";
878
+
879
+ // src/core/document-page-style.ts
880
+ var TRADITIONAL = 1;
881
+ var PORTRAIT = 0;
882
+ var PX_PER_INCH = 96;
883
+ var DEFAULT_DOCUMENT_PAGE_STYLE = {
884
+ pageSize: { width: 816, height: 1056 },
885
+ documentFlavor: TRADITIONAL,
886
+ pageOrient: PORTRAIT,
887
+ marginTop: PX_PER_INCH,
888
+ marginBottom: PX_PER_INCH,
889
+ marginLeft: PX_PER_INCH,
890
+ marginRight: PX_PER_INCH,
891
+ // Univer applies no paragraph spacing to a paginated page by itself; without this every paragraph
892
+ // runs into the next (Google Docs' own default: 1.15 lines, 10px after).
893
+ defaultParagraphStyle: { spaceAbove: { v: 0 }, spaceBelow: { v: 10 }, lineSpacing: 1.15 }
894
+ };
895
+ function defaultDocumentPageStyle() {
896
+ return {
897
+ ...DEFAULT_DOCUMENT_PAGE_STYLE,
898
+ pageSize: { ...DEFAULT_DOCUMENT_PAGE_STYLE.pageSize },
899
+ defaultParagraphStyle: { ...DEFAULT_DOCUMENT_PAGE_STYLE.defaultParagraphStyle }
900
+ };
901
+ }
902
+ function isLegacySqueezedPageStyle(style) {
903
+ const size = style?.pageSize;
904
+ return !!size && size.width === 595 && size.height === 842 && style?.marginLeft === 90 && style?.marginRight === 90 && style?.marginTop === 72 && style?.marginBottom === 72;
905
+ }
906
+ var PAGE_COLORS = ["#ffffff", "#fff8e7", "#f3f3f3", "#e8f0fe", "#e6f4ea", "#fef7e0"];
907
+ var DEFAULT_PAGE_COLOR = PAGE_COLORS[0];
908
+
909
+ // src/docs/sanitize-univer-doc-snapshot.ts
910
+ var NAMED_STYLE_STRING_TO_NUMBER = Object.fromEntries(
911
+ Object.entries(NamedStyleType).filter(([key, val]) => typeof val === "number" && isNaN(Number(key))).map(([key, val]) => [key, val])
912
+ );
913
+ function sanitizeUniverDocSnapshot(snapshot, docId, opts = {}) {
914
+ restorePageStyle(snapshot, docId, opts.quiet === true);
915
+ ensureTextRuns(snapshot);
916
+ const paragraphs = snapshot?.body?.paragraphs;
917
+ if (!Array.isArray(paragraphs)) return snapshot;
918
+ let fixed = 0;
919
+ for (const paragraph of paragraphs) {
920
+ const style = paragraph?.paragraphStyle;
921
+ const value = style?.namedStyleType;
922
+ if (typeof value === "string") {
923
+ const numeric = NAMED_STYLE_STRING_TO_NUMBER[value];
924
+ if (numeric !== void 0) {
925
+ style.namedStyleType = numeric;
926
+ fixed += 1;
927
+ } else {
928
+ delete style.namedStyleType;
929
+ fixed += 1;
930
+ }
931
+ }
932
+ }
933
+ if (fixed > 0 && opts.quiet !== true) {
934
+ console.warn(
935
+ `[data-tables] RECOVERY: sanitized ${fixed} string namedStyleType value(s) to numeric NamedStyleType in document snapshot${docId ? ` ${docId}` : ""}. The snapshot was written with the wrong enum encoding (string instead of number) and would have crashed Univer's <ParagraphMenu>. Fix the snapshot writer to emit numeric NamedStyleType values.`
936
+ );
937
+ }
938
+ return snapshot;
939
+ }
940
+ function restorePageStyle(snapshot, docId, quiet = false) {
941
+ if (!snapshot || typeof snapshot !== "object") return;
942
+ const style = snapshot.documentStyle;
943
+ if (style?.pageSize?.width && isLegacySqueezedPageStyle(style)) {
944
+ const page = defaultDocumentPageStyle();
945
+ snapshot.documentStyle = { ...style, ...page, defaultParagraphStyle: style.defaultParagraphStyle ?? page.defaultParagraphStyle };
946
+ return;
947
+ }
948
+ if (style?.pageSize?.width) {
949
+ if (!style.documentFlavor) {
950
+ const page = defaultDocumentPageStyle();
951
+ Object.assign(style, { documentFlavor: page.documentFlavor });
952
+ if (page.defaultParagraphStyle) style.defaultParagraphStyle ??= page.defaultParagraphStyle;
953
+ }
954
+ return;
955
+ }
956
+ snapshot.documentStyle = {
957
+ ...defaultDocumentPageStyle(),
958
+ ...snapshot.documentStyle ?? {},
959
+ pageSize: defaultDocumentPageStyle().pageSize
960
+ };
961
+ if (quiet) return;
962
+ console.warn(
963
+ `[data-tables] RECOVERY: document snapshot${docId ? ` ${docId}` : ""} had no documentStyle.pageSize \u2014 restored the default Letter page geometry. Without a page box Univer lays the body out unbounded: text does not wrap and the viewport has no scrollable extent, so the document appears frozen. Fix the snapshot writer (agent/markdown converters must stamp DEFAULT_DOCUMENT_PAGE_STYLE).`
964
+ );
965
+ }
966
+ function ensureTextRuns(snapshot) {
967
+ const body = snapshot?.body;
968
+ if (body && typeof body === "object" && !Array.isArray(body.textRuns)) body.textRuns = [];
969
+ }
970
+
873
971
  // src/univer/collab/docs-ot/state-hash.ts
874
972
  var DOC_LOCAL_KEYS = ["rev", "__matrxCollabCovered", "__collab", "disabled", "layoutState", "textRanges", "selections"];
875
973
  function sortDeep(v) {
@@ -929,6 +1027,7 @@ function canonicalBody(body) {
929
1027
  const b = { ...body };
930
1028
  b.textRuns = canonicalRuns(b.textRuns);
931
1029
  if (Array.isArray(b.paragraphs)) b.paragraphs = b.paragraphs.map(({ paragraphId: _p, ...p }) => p);
1030
+ if (Array.isArray(b.sectionBreaks)) b.sectionBreaks = b.sectionBreaks.map(({ sectionId: _s, ...x }) => x);
932
1031
  b.customRanges = foldPieces(b.customRanges, (r) => JSON.stringify([rootId(r.rangeId), r.rangeType, sortDeep(r.properties ?? {})])).map((r) => ({
933
1032
  ...r,
934
1033
  rangeId: rootId(r.rangeId)
@@ -943,9 +1042,44 @@ function canonicalBody(body) {
943
1042
  }
944
1043
  return b;
945
1044
  }
1045
+ function asLoadedDocsSnapshot(snapshot) {
1046
+ const s = stampDeterministicIds(structuredClone(snapshot ?? {}));
1047
+ delete s.id;
1048
+ for (const k of DOC_LOCAL_KEYS) delete s[k];
1049
+ sanitizeUniverDocSnapshot(s, void 0, { quiet: true });
1050
+ const model = new DocumentDataModel(s);
1051
+ try {
1052
+ return structuredClone(model.getSnapshot());
1053
+ } finally {
1054
+ model.dispose();
1055
+ }
1056
+ }
1057
+ var isEmptyDeep = (v) => v == null || v === "" || (Array.isArray(v) ? v.every(isEmptyDeep) : typeof v === "object" ? Object.values(v).every(isEmptyDeep) : false);
1058
+ function canonicalResources(resources) {
1059
+ if (!Array.isArray(resources)) return [];
1060
+ const out = [];
1061
+ for (const r of resources) {
1062
+ if (!r || typeof r.name !== "string") continue;
1063
+ let data = r.data;
1064
+ if (typeof data === "string" && data !== "") {
1065
+ try {
1066
+ data = JSON.parse(data);
1067
+ } catch {
1068
+ }
1069
+ }
1070
+ if (isEmptyDeep(data)) continue;
1071
+ out.push({ name: r.name, data: sortDeep(data) });
1072
+ }
1073
+ return out.sort((a, b) => a.name.localeCompare(b.name));
1074
+ }
946
1075
  function canonicalDocsSnapshot(snapshot) {
947
- const s = structuredClone(snapshot ?? {});
1076
+ const s = asLoadedDocsSnapshot(snapshot);
948
1077
  delete s.id;
1078
+ s.resources = canonicalResources(s.resources);
1079
+ if (s.settings && typeof s.settings === "object") {
1080
+ s.settings = { ...s.settings };
1081
+ delete s.settings.zoomRatio;
1082
+ }
949
1083
  for (const k of DOC_LOCAL_KEYS) delete s[k];
950
1084
  s.body = canonicalBody(s.body);
951
1085
  for (const seg of ["headers", "footers", "notes"]) {
@@ -1153,7 +1287,10 @@ function openDocsOtRoom(o) {
1153
1287
  queue = next.filter((q) => !isNoopDocsOp(q));
1154
1288
  if (isNoopDocsOp(op)) return;
1155
1289
  }
1156
- if (!session.local(op, { ...inverse !== void 0 ? { inverse } : {}, label: m.cmd ?? RICH_TEXT_EDITING })) notice({ kind: "not_live" });
1290
+ if (!session.local(op, { ...inverse !== void 0 ? { inverse } : {}, label: m.cmd ?? RICH_TEXT_EDITING })) {
1291
+ notice({ kind: "not_live" });
1292
+ session.rebuild("not_live");
1293
+ }
1157
1294
  };
1158
1295
  const unsubLocal = port.onLocal(onLocal);
1159
1296
  const target = o.compositionTarget === void 0 ? typeof document !== "undefined" ? document : null : o.compositionTarget;
@@ -1214,6 +1351,7 @@ import * as Y2 from "yjs";
1214
1351
  import { Awareness as Awareness2 } from "y-protocols/awareness";
1215
1352
  import {
1216
1353
  awarenessOpPresence,
1354
+ claimCollaboratorColor,
1217
1355
  collabReplace,
1218
1356
  collabRoomExists,
1219
1357
  SupabaseYjsProvider,
@@ -1378,15 +1516,6 @@ async function documentUsesOrderedRoom(documentId, knob, isNewDocument) {
1378
1516
  if (knob === "new") return isNewDocument();
1379
1517
  return false;
1380
1518
  }
1381
- function pickColor2(uid) {
1382
- const palette = ["#ef4444", "#f59e0b", "#10b981", "#3b82f6", "#8b5cf6", "#ec4899", "#14b8a6", "#f97316"];
1383
- let h = 2166136261;
1384
- for (let i = 0; i < uid.length; i++) {
1385
- h ^= uid.charCodeAt(i);
1386
- h = Math.imul(h, 16777619);
1387
- }
1388
- return palette[Math.abs(h) % palette.length] ?? "#ec4899";
1389
- }
1390
1519
  function documentOtFactory(o) {
1391
1520
  return async (basePort, onAwareness) => {
1392
1521
  const latest = await getLatestDocumentSnapshot(o.documentId);
@@ -1400,7 +1529,8 @@ function documentOtFactory(o) {
1400
1529
  }
1401
1530
  const doc = new Y2.Doc();
1402
1531
  const awareness = new Awareness2(doc);
1403
- awareness.setLocalState({ uid: o.uid, clientId: o.clientId, name: o.displayName ?? o.uid.slice(0, 8), color: pickColor2(o.uid), ts: Date.now() });
1532
+ awareness.setLocalState({ uid: o.uid, clientId: o.clientId, name: o.displayName ?? o.uid.slice(0, 8), ts: Date.now() });
1533
+ const stopColor = claimCollaboratorColor(awareness, { uid: o.uid, clientId: o.clientId });
1404
1534
  const carets = new RemoteCaretBook(awareness.clientID);
1405
1535
  const emit = () => onAwareness({ states: new Map(awareness.getStates()), selfUid: o.uid, carets: carets.list() });
1406
1536
  const publishAwareness = () => {
@@ -1486,6 +1616,7 @@ function documentOtFactory(o) {
1486
1616
  replace: (snapshot) => room.replace(snapshot),
1487
1617
  stop: () => {
1488
1618
  clearInterval(caretTimer);
1619
+ stopColor();
1489
1620
  room.stop();
1490
1621
  awareness.off("change", publishAwareness);
1491
1622
  provider.disconnect();
@@ -3274,7 +3405,7 @@ function univerSheetsOtPort(o) {
3274
3405
  const a = forApply(m);
3275
3406
  applying = true;
3276
3407
  try {
3277
- const ok2 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { onlyLocal: true, fromCollab: true });
3408
+ const ok2 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
3278
3409
  if (ok2 === false) throw new Error(`"${m.id}" was refused by the editor`);
3279
3410
  } finally {
3280
3411
  applying = false;
@@ -3454,7 +3585,7 @@ async function workbookUsesOrderedRoom(workbookId, knob, isNewWorkbook) {
3454
3585
  if (knob === "new") return isNewWorkbook();
3455
3586
  return false;
3456
3587
  }
3457
- function pickColor3(uid) {
3588
+ function pickColor2(uid) {
3458
3589
  const palette = ["#ef4444", "#f59e0b", "#10b981", "#3b82f6", "#8b5cf6", "#ec4899", "#14b8a6", "#f97316"];
3459
3590
  let h = 2166136261;
3460
3591
  for (let i = 0; i < uid.length; i++) {
@@ -3479,7 +3610,7 @@ async function startWorkbookOtRoom(port, o) {
3479
3610
  uid: o.uid,
3480
3611
  clientId: o.clientId,
3481
3612
  name: o.displayName ?? o.uid.slice(0, 8),
3482
- color: pickColor3(o.uid),
3613
+ color: pickColor2(o.uid),
3483
3614
  sheetId: null,
3484
3615
  row: null,
3485
3616
  col: null,
@@ -3550,6 +3681,7 @@ export {
3550
3681
  SHEETS_EDIT_GROUP,
3551
3682
  WorkbookCollabSession,
3552
3683
  applyDocsOp,
3684
+ asLoadedDocsSnapshot,
3553
3685
  canonicalDocsSnapshot,
3554
3686
  canonicalDocsString,
3555
3687
  canonicalKeys,