@ai-matrx/office 0.8.18 → 0.8.20
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.
- package/CHANGELOG.md +10 -0
- package/dist/univer-collab.cjs +29 -37
- package/dist/univer-collab.cjs.map +1 -1
- package/dist/univer-collab.d.cts +1 -0
- package/dist/univer-collab.d.ts +1 -0
- package/dist/univer-collab.js +33 -40
- package/dist/univer-collab.js.map +1 -1
- package/package.json +3 -3
package/dist/univer-collab.d.cts
CHANGED
|
@@ -128,6 +128,7 @@ declare class WorkbookCollabSession {
|
|
|
128
128
|
private muted;
|
|
129
129
|
private started;
|
|
130
130
|
private disposed;
|
|
131
|
+
private stopColor;
|
|
131
132
|
/** Room entries this seat holds in its content: applied from a peer, or made here. */
|
|
132
133
|
private readonly applied;
|
|
133
134
|
/** Entries without an id (a peer on an older build) are applied once, by identity. */
|
package/dist/univer-collab.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ declare class WorkbookCollabSession {
|
|
|
128
128
|
private muted;
|
|
129
129
|
private started;
|
|
130
130
|
private disposed;
|
|
131
|
+
private stopColor;
|
|
131
132
|
/** Room entries this seat holds in its content: applied from a peer, or made here. */
|
|
132
133
|
private readonly applied;
|
|
133
134
|
/** Entries without an id (a peer on an older build) are applied once, by identity. */
|
package/dist/univer-collab.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/univer/collab/WorkbookCollabSession.ts
|
|
4
4
|
import * as Y from "yjs";
|
|
5
5
|
import { Awareness } from "y-protocols/awareness";
|
|
6
|
-
import { electCollabHost, remoteOriginOf, REMOTE_PARAM_TAG } from "@ai-matrx/data/realtime/collab";
|
|
6
|
+
import { claimCollaboratorColor, electCollabHost, remoteOriginOf, REMOTE_PARAM_TAG } from "@ai-matrx/data/realtime/collab";
|
|
7
7
|
|
|
8
8
|
// src/univer/collab/covered.ts
|
|
9
9
|
var COLLAB_COVERED_KEY = "__matrxCollabCovered";
|
|
@@ -39,6 +39,7 @@ var WorkbookCollabSession = class {
|
|
|
39
39
|
muted = 0;
|
|
40
40
|
started = false;
|
|
41
41
|
disposed = false;
|
|
42
|
+
stopColor = null;
|
|
42
43
|
/** Room entries this seat holds in its content: applied from a peer, or made here. */
|
|
43
44
|
applied = /* @__PURE__ */ new Set();
|
|
44
45
|
/** Entries without an id (a peer on an older build) are applied once, by identity. */
|
|
@@ -60,12 +61,12 @@ var WorkbookCollabSession = class {
|
|
|
60
61
|
uid: this.options.uid,
|
|
61
62
|
clientId: this.options.clientId,
|
|
62
63
|
name: this.options.uid.slice(0, 8),
|
|
63
|
-
color: pickColor(this.options.uid),
|
|
64
64
|
sheetId: null,
|
|
65
65
|
row: null,
|
|
66
66
|
col: null,
|
|
67
67
|
ts: Date.now()
|
|
68
68
|
});
|
|
69
|
+
this.stopColor = claimCollaboratorColor(this.awareness, { uid: this.options.uid, clientId: this.options.clientId });
|
|
69
70
|
this.provider = this.options.makeProvider({
|
|
70
71
|
workbookId: this.options.workbookId,
|
|
71
72
|
clientId: this.options.clientId,
|
|
@@ -126,6 +127,8 @@ var WorkbookCollabSession = class {
|
|
|
126
127
|
this.awareness.off("change", this.awarenessObserver);
|
|
127
128
|
this.awarenessObserver = null;
|
|
128
129
|
}
|
|
130
|
+
this.stopColor?.();
|
|
131
|
+
this.stopColor = null;
|
|
129
132
|
this.provider?.disconnect();
|
|
130
133
|
this.provider = null;
|
|
131
134
|
if (this.awareness) {
|
|
@@ -332,32 +335,6 @@ function stripSenderView(params) {
|
|
|
332
335
|
function isCellEditorScratch(info) {
|
|
333
336
|
return typeof info.id === "string" && info.id.startsWith("doc.mutation.");
|
|
334
337
|
}
|
|
335
|
-
var CURSOR_PALETTE = [
|
|
336
|
-
"#3b82f6",
|
|
337
|
-
// blue
|
|
338
|
-
"#10b981",
|
|
339
|
-
// emerald
|
|
340
|
-
"#f59e0b",
|
|
341
|
-
// amber
|
|
342
|
-
"#ef4444",
|
|
343
|
-
// red
|
|
344
|
-
"#8b5cf6",
|
|
345
|
-
// violet
|
|
346
|
-
"#06b6d4",
|
|
347
|
-
// cyan
|
|
348
|
-
"#ec4899",
|
|
349
|
-
// pink
|
|
350
|
-
"#84cc16"
|
|
351
|
-
// lime
|
|
352
|
-
];
|
|
353
|
-
function pickColor(uid) {
|
|
354
|
-
let h = 2166136261;
|
|
355
|
-
for (let i = 0; i < uid.length; i++) {
|
|
356
|
-
h ^= uid.charCodeAt(i);
|
|
357
|
-
h = Math.imul(h, 16777619);
|
|
358
|
-
}
|
|
359
|
-
return CURSOR_PALETTE[Math.abs(h) % CURSOR_PALETTE.length] ?? "#ec4899";
|
|
360
|
-
}
|
|
361
338
|
|
|
362
339
|
// src/univer/collab/docs-ot/transform.ts
|
|
363
340
|
import { JSONX, TextX, getBodySliceForSplitTextXAction, normalizeTextRuns, merge as univerMerge } from "@univerjs/core";
|
|
@@ -1054,9 +1031,32 @@ function asLoadedDocsSnapshot(snapshot) {
|
|
|
1054
1031
|
model.dispose();
|
|
1055
1032
|
}
|
|
1056
1033
|
}
|
|
1034
|
+
var isEmptyDeep = (v) => v == null || v === "" || (Array.isArray(v) ? v.every(isEmptyDeep) : typeof v === "object" ? Object.values(v).every(isEmptyDeep) : false);
|
|
1035
|
+
function canonicalResources(resources) {
|
|
1036
|
+
if (!Array.isArray(resources)) return [];
|
|
1037
|
+
const out = [];
|
|
1038
|
+
for (const r of resources) {
|
|
1039
|
+
if (!r || typeof r.name !== "string") continue;
|
|
1040
|
+
let data = r.data;
|
|
1041
|
+
if (typeof data === "string" && data !== "") {
|
|
1042
|
+
try {
|
|
1043
|
+
data = JSON.parse(data);
|
|
1044
|
+
} catch {
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (isEmptyDeep(data)) continue;
|
|
1048
|
+
out.push({ name: r.name, data: sortDeep(data) });
|
|
1049
|
+
}
|
|
1050
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
1051
|
+
}
|
|
1057
1052
|
function canonicalDocsSnapshot(snapshot) {
|
|
1058
1053
|
const s = asLoadedDocsSnapshot(snapshot);
|
|
1059
1054
|
delete s.id;
|
|
1055
|
+
s.resources = canonicalResources(s.resources);
|
|
1056
|
+
if (s.settings && typeof s.settings === "object") {
|
|
1057
|
+
s.settings = { ...s.settings };
|
|
1058
|
+
delete s.settings.zoomRatio;
|
|
1059
|
+
}
|
|
1060
1060
|
for (const k of DOC_LOCAL_KEYS) delete s[k];
|
|
1061
1061
|
s.body = canonicalBody(s.body);
|
|
1062
1062
|
for (const seg of ["headers", "footers", "notes"]) {
|
|
@@ -1328,7 +1328,7 @@ import * as Y2 from "yjs";
|
|
|
1328
1328
|
import { Awareness as Awareness2 } from "y-protocols/awareness";
|
|
1329
1329
|
import {
|
|
1330
1330
|
awarenessOpPresence,
|
|
1331
|
-
claimCollaboratorColor,
|
|
1331
|
+
claimCollaboratorColor as claimCollaboratorColor2,
|
|
1332
1332
|
collabReplace,
|
|
1333
1333
|
collabRoomExists,
|
|
1334
1334
|
SupabaseYjsProvider,
|
|
@@ -1507,7 +1507,7 @@ function documentOtFactory(o) {
|
|
|
1507
1507
|
const doc = new Y2.Doc();
|
|
1508
1508
|
const awareness = new Awareness2(doc);
|
|
1509
1509
|
awareness.setLocalState({ uid: o.uid, clientId: o.clientId, name: o.displayName ?? o.uid.slice(0, 8), ts: Date.now() });
|
|
1510
|
-
const stopColor =
|
|
1510
|
+
const stopColor = claimCollaboratorColor2(awareness, { uid: o.uid, clientId: o.clientId });
|
|
1511
1511
|
const carets = new RemoteCaretBook(awareness.clientID);
|
|
1512
1512
|
const emit = () => onAwareness({ states: new Map(awareness.getStates()), selfUid: o.uid, carets: carets.list() });
|
|
1513
1513
|
const publishAwareness = () => {
|
|
@@ -3493,6 +3493,7 @@ import * as Y3 from "yjs";
|
|
|
3493
3493
|
import { Awareness as Awareness3 } from "y-protocols/awareness";
|
|
3494
3494
|
import {
|
|
3495
3495
|
awarenessOpPresence as awarenessOpPresence2,
|
|
3496
|
+
claimCollaboratorColor as claimCollaboratorColor3,
|
|
3496
3497
|
collabReplace as collabReplace3,
|
|
3497
3498
|
collabRoomExists as collabRoomExists3,
|
|
3498
3499
|
SupabaseYjsProvider as SupabaseYjsProvider2,
|
|
@@ -3562,15 +3563,6 @@ async function workbookUsesOrderedRoom(workbookId, knob, isNewWorkbook) {
|
|
|
3562
3563
|
if (knob === "new") return isNewWorkbook();
|
|
3563
3564
|
return false;
|
|
3564
3565
|
}
|
|
3565
|
-
function pickColor2(uid) {
|
|
3566
|
-
const palette = ["#ef4444", "#f59e0b", "#10b981", "#3b82f6", "#8b5cf6", "#ec4899", "#14b8a6", "#f97316"];
|
|
3567
|
-
let h = 2166136261;
|
|
3568
|
-
for (let i = 0; i < uid.length; i++) {
|
|
3569
|
-
h ^= uid.charCodeAt(i);
|
|
3570
|
-
h = Math.imul(h, 16777619);
|
|
3571
|
-
}
|
|
3572
|
-
return palette[Math.abs(h) % palette.length] ?? "#ec4899";
|
|
3573
|
-
}
|
|
3574
3566
|
async function startWorkbookOtRoom(port, o) {
|
|
3575
3567
|
const latest = await getLatestSnapshot(o.workbookId);
|
|
3576
3568
|
if (!latest.success) throw new Error(latest.error);
|
|
@@ -3587,12 +3579,12 @@ async function startWorkbookOtRoom(port, o) {
|
|
|
3587
3579
|
uid: o.uid,
|
|
3588
3580
|
clientId: o.clientId,
|
|
3589
3581
|
name: o.displayName ?? o.uid.slice(0, 8),
|
|
3590
|
-
color: pickColor2(o.uid),
|
|
3591
3582
|
sheetId: null,
|
|
3592
3583
|
row: null,
|
|
3593
3584
|
col: null,
|
|
3594
3585
|
ts: Date.now()
|
|
3595
3586
|
});
|
|
3587
|
+
const stopColor = claimCollaboratorColor3(awareness, { uid: o.uid, clientId: o.clientId });
|
|
3596
3588
|
const publishAwareness = () => o.onAwareness?.(new Map(awareness.getStates()));
|
|
3597
3589
|
awareness.on("change", publishAwareness);
|
|
3598
3590
|
const provider = new SupabaseYjsProvider2({
|
|
@@ -3638,6 +3630,7 @@ async function startWorkbookOtRoom(port, o) {
|
|
|
3638
3630
|
awareness.setLocalState({ ...current, sheetId: c.sheetId, row: c.row, col: c.col, ts: Date.now() });
|
|
3639
3631
|
},
|
|
3640
3632
|
stop() {
|
|
3633
|
+
stopColor();
|
|
3641
3634
|
room.stop();
|
|
3642
3635
|
port.dispose?.();
|
|
3643
3636
|
awareness.off("change", publishAwareness);
|