y-mxgraph 0.3.0 → 0.3.2
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/README.md +4 -1
- package/README.zh-CN.md +4 -2
- package/binding/index.d.ts +19 -0
- package/binding/index.d.ts.map +1 -1
- package/iframe-bridge/provider.cjs.js +134 -0
- package/iframe-bridge/provider.cjs.js.map +1 -0
- package/iframe-bridge/provider.es.js +117 -0
- package/iframe-bridge/provider.es.js.map +1 -0
- package/iframe-bridge/server.cjs.js +111 -0
- package/iframe-bridge/server.cjs.js.map +1 -0
- package/iframe-bridge/server.es.js +94 -0
- package/iframe-bridge/server.es.js.map +1 -0
- package/index.d.ts +0 -2
- package/index.d.ts.map +1 -1
- package/package.json +11 -3
- package/types/drawio.d.ts +5 -0
- package/types/drawio.d.ts.map +1 -1
- package/y-mxgraph.cjs.js +94 -158
- package/y-mxgraph.cjs.js.map +1 -1
- package/y-mxgraph.es.js +95 -153
- package/y-mxgraph.es.js.map +1 -1
- package/y-mxgraph.iife.js +0 -1741
- package/y-mxgraph.iife.js.map +0 -1
- package/y-mxgraph.umd.js +0 -1742
- package/y-mxgraph.umd.js.map +0 -1
package/y-mxgraph.es.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { js2xml, xml2js } from "xml-js";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
3
|
import { throttle } from "lodash-es";
|
|
4
4
|
import { colord } from "colord";
|
|
5
|
-
import { createIframeBridgeProvider, createIframeBridgeServer } from "@y-mxgraph/iframe-bridge";
|
|
6
5
|
function deepProcess(node) {
|
|
7
|
-
if (node == null)
|
|
8
|
-
return;
|
|
6
|
+
if (node == null) return;
|
|
9
7
|
if (Array.isArray(node)) {
|
|
10
8
|
for (const item of node) {
|
|
11
9
|
deepProcess(item);
|
|
12
10
|
}
|
|
13
11
|
return;
|
|
14
12
|
}
|
|
15
|
-
if (typeof node !== "object")
|
|
16
|
-
return;
|
|
13
|
+
if (typeof node !== "object") return;
|
|
17
14
|
const obj = node;
|
|
18
15
|
const keys = Object.keys(obj);
|
|
19
16
|
for (const key2 of keys) {
|
|
20
|
-
if (key2 === "_attributes")
|
|
21
|
-
continue;
|
|
17
|
+
if (key2 === "_attributes") continue;
|
|
22
18
|
let value = obj[key2];
|
|
23
19
|
const keyLower = key2.toLowerCase();
|
|
24
20
|
if ((keyLower === "diagram" || keyLower === "mxcell") && value !== void 0 && !Array.isArray(value)) {
|
|
@@ -26,8 +22,7 @@ function deepProcess(node) {
|
|
|
26
22
|
value = obj[key2];
|
|
27
23
|
}
|
|
28
24
|
if (Array.isArray(value)) {
|
|
29
|
-
for (const v of value)
|
|
30
|
-
deepProcess(v);
|
|
25
|
+
for (const v of value) deepProcess(v);
|
|
31
26
|
} else if (value && typeof value === "object") {
|
|
32
27
|
deepProcess(value);
|
|
33
28
|
}
|
|
@@ -199,18 +194,15 @@ const docSnapshots = /* @__PURE__ */ new WeakMap();
|
|
|
199
194
|
function insertAfterUnique(orderArr, id, previous, fallbackToEnd = false) {
|
|
200
195
|
const currentIds = orderArr.toArray();
|
|
201
196
|
let anchorPos = previous ? currentIds.indexOf(previous) : -1;
|
|
202
|
-
if (anchorPos === -1 && fallbackToEnd)
|
|
203
|
-
anchorPos = currentIds.length - 1;
|
|
197
|
+
if (anchorPos === -1 && fallbackToEnd) anchorPos = currentIds.length - 1;
|
|
204
198
|
let targetIndex = anchorPos + 1;
|
|
205
199
|
const existingIndex = currentIds.indexOf(id);
|
|
206
200
|
if (existingIndex === -1) {
|
|
207
201
|
orderArr.insert(targetIndex, [id]);
|
|
208
202
|
return;
|
|
209
203
|
}
|
|
210
|
-
if (existingIndex === targetIndex)
|
|
211
|
-
|
|
212
|
-
if (existingIndex < targetIndex)
|
|
213
|
-
targetIndex -= 1;
|
|
204
|
+
if (existingIndex === targetIndex) return;
|
|
205
|
+
if (existingIndex < targetIndex) targetIndex -= 1;
|
|
214
206
|
orderArr.delete(existingIndex, 1);
|
|
215
207
|
orderArr.insert(targetIndex, [id]);
|
|
216
208
|
}
|
|
@@ -220,12 +212,9 @@ function ensureUniqueOrder(orderArr) {
|
|
|
220
212
|
const dupIdx = [];
|
|
221
213
|
for (let i = 0; i < arr.length; i++) {
|
|
222
214
|
const id = arr[i];
|
|
223
|
-
if (!id)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
dupIdx.push(i);
|
|
227
|
-
else
|
|
228
|
-
seen.add(id);
|
|
215
|
+
if (!id) continue;
|
|
216
|
+
if (seen.has(id)) dupIdx.push(i);
|
|
217
|
+
else seen.add(id);
|
|
229
218
|
}
|
|
230
219
|
if (dupIdx.length) {
|
|
231
220
|
dupIdx.sort((a, b) => b - a).forEach((idx) => orderArr.delete(idx, 1));
|
|
@@ -308,10 +297,8 @@ function applyFilePatch(doc, patch, options) {
|
|
|
308
297
|
enriched.sort((a, b) => {
|
|
309
298
|
const aIdx = a.anchorId ? existingIndex.get(a.anchorId) : -1;
|
|
310
299
|
const bIdx = b.anchorId ? existingIndex.get(b.anchorId) : -1;
|
|
311
|
-
if (aIdx !== bIdx)
|
|
312
|
-
|
|
313
|
-
if (a.depth !== b.depth)
|
|
314
|
-
return b.depth - a.depth;
|
|
300
|
+
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
301
|
+
if (a.depth !== b.depth) return b.depth - a.depth;
|
|
315
302
|
return b.order - a.order;
|
|
316
303
|
});
|
|
317
304
|
for (const item of enriched) {
|
|
@@ -335,12 +322,10 @@ function applyFilePatch(doc, patch, options) {
|
|
|
335
322
|
}
|
|
336
323
|
if (update.cells) {
|
|
337
324
|
const yMxGraphModel = diagram.get(key$2);
|
|
338
|
-
if (!yMxGraphModel)
|
|
339
|
-
return;
|
|
325
|
+
if (!yMxGraphModel) return;
|
|
340
326
|
const cellsMap = yMxGraphModel.get(key$3);
|
|
341
327
|
const orderArr = yMxGraphModel.get(mxCellOrderKey);
|
|
342
|
-
if (!cellsMap || !orderArr)
|
|
343
|
-
return;
|
|
328
|
+
if (!cellsMap || !orderArr) return;
|
|
344
329
|
ensureUniqueOrder(orderArr);
|
|
345
330
|
if (update.cells[DIFF_REMOVE] && update.cells[DIFF_REMOVE].length) {
|
|
346
331
|
const orderIds = orderArr.toArray();
|
|
@@ -353,12 +338,10 @@ function applyFilePatch(doc, patch, options) {
|
|
|
353
338
|
if (update.cells[DIFF_INSERT] && update.cells[DIFF_INSERT].length) {
|
|
354
339
|
for (const item of update.cells[DIFF_INSERT]) {
|
|
355
340
|
const id2 = item["id"];
|
|
356
|
-
if (!id2)
|
|
357
|
-
continue;
|
|
341
|
+
if (!id2) continue;
|
|
358
342
|
const xmlElement = new Y.XmlElement("mxCell");
|
|
359
343
|
Object.keys(item).forEach((key2) => {
|
|
360
|
-
if (key2 === "previous")
|
|
361
|
-
return;
|
|
344
|
+
if (key2 === "previous") return;
|
|
362
345
|
xmlElement.setAttribute(key2, item[key2]);
|
|
363
346
|
});
|
|
364
347
|
cellsMap.set(id2, xmlElement);
|
|
@@ -397,8 +380,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
397
380
|
const cell = cellsMap.get(cid);
|
|
398
381
|
if (cell) {
|
|
399
382
|
Object.keys(updateObj).forEach((k) => {
|
|
400
|
-
if (k === "previous")
|
|
401
|
-
return;
|
|
383
|
+
if (k === "previous") return;
|
|
402
384
|
cell.setAttribute(k, updateObj[k]);
|
|
403
385
|
});
|
|
404
386
|
}
|
|
@@ -407,8 +389,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
407
389
|
const updateObj = update.cells[DIFF_UPDATE][cellId];
|
|
408
390
|
const hasPrev = "previous" in updateObj;
|
|
409
391
|
const hasParent = "parent" in updateObj;
|
|
410
|
-
if (!hasPrev && !hasParent)
|
|
411
|
-
return;
|
|
392
|
+
if (!hasPrev && !hasParent) return;
|
|
412
393
|
const prevVal = hasPrev ? updateObj.previous : void 0;
|
|
413
394
|
const parentVal = hasParent ? updateObj.parent : void 0;
|
|
414
395
|
let anchorId = null;
|
|
@@ -438,8 +419,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
438
419
|
newCell = new Y.XmlElement("mxCell");
|
|
439
420
|
newCell.setAttribute("id", cellId);
|
|
440
421
|
Object.keys(updateObj).forEach((k) => {
|
|
441
|
-
if (k === "previous")
|
|
442
|
-
return;
|
|
422
|
+
if (k === "previous") return;
|
|
443
423
|
newCell.setAttribute(k, updateObj[k]);
|
|
444
424
|
});
|
|
445
425
|
cellsMap.set(cellId, newCell);
|
|
@@ -490,8 +470,7 @@ function initDocSnapshot(doc, resetSnapshot = false) {
|
|
|
490
470
|
const diagrams = diagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
|
|
491
471
|
for (const d of diagrams) {
|
|
492
472
|
const did = d.get("id") || "";
|
|
493
|
-
if (!did)
|
|
494
|
-
continue;
|
|
473
|
+
if (!did) continue;
|
|
495
474
|
const gm = d.get(key$2);
|
|
496
475
|
if (gm) {
|
|
497
476
|
const order = gm.get(mxCellOrderKey);
|
|
@@ -524,11 +503,9 @@ function initDocSnapshot(doc, resetSnapshot = false) {
|
|
|
524
503
|
function generatePatch(events, explicitDoc) {
|
|
525
504
|
var _a, _b;
|
|
526
505
|
const patch = {};
|
|
527
|
-
const doc =
|
|
528
|
-
if (!doc)
|
|
529
|
-
|
|
530
|
-
if (!explicitDoc && (!events || events.length === 0))
|
|
531
|
-
return patch;
|
|
506
|
+
const doc = (_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc;
|
|
507
|
+
if (!doc) return patch;
|
|
508
|
+
if (!events || events.length === 0) return patch;
|
|
532
509
|
const mxfile = doc.getMap(key);
|
|
533
510
|
const diagramsMap = mxfile.get(key$1);
|
|
534
511
|
const orderArr = mxfile.get(diagramOrderKey);
|
|
@@ -590,8 +567,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
590
567
|
const removed = prevDiagramOrder.filter(
|
|
591
568
|
(id) => !currSet.has(id) && id
|
|
592
569
|
);
|
|
593
|
-
if (removed.length)
|
|
594
|
-
patch[DIFF_REMOVE] = removed;
|
|
570
|
+
if (removed.length) patch[DIFF_REMOVE] = removed;
|
|
595
571
|
const removedDiagramSet = new Set(removed);
|
|
596
572
|
const inserted = currDiagramOrder.filter(
|
|
597
573
|
(id) => !prevSet.has(id) && id
|
|
@@ -602,8 +578,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
602
578
|
const index = currDiagramOrder.indexOf(id);
|
|
603
579
|
const previous = index <= 0 ? "" : currDiagramOrder[index - 1];
|
|
604
580
|
const yDiagram = diagramsMap.get(id);
|
|
605
|
-
if (!yDiagram)
|
|
606
|
-
continue;
|
|
581
|
+
if (!yDiagram) continue;
|
|
607
582
|
const data = serializer$1({ diagram: serialize(yDiagram) });
|
|
608
583
|
patch[DIFF_INSERT].push({ id, previous, data });
|
|
609
584
|
insertedDiagramIdGlobal.add(id);
|
|
@@ -618,8 +593,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
618
593
|
const prevP = prevNeighbor(prevDiagramOrder, id);
|
|
619
594
|
const currP = prevNeighbor(currDiagramOrder, id);
|
|
620
595
|
if (prevP !== currP) {
|
|
621
|
-
if (prevP && removedDiagramSet.has(prevP))
|
|
622
|
-
continue;
|
|
596
|
+
if (prevP && removedDiagramSet.has(prevP)) continue;
|
|
623
597
|
const u = ensureUpdate(id);
|
|
624
598
|
u.previous = currP;
|
|
625
599
|
}
|
|
@@ -630,12 +604,10 @@ function generatePatch(events, explicitDoc) {
|
|
|
630
604
|
...currDiagramOrder
|
|
631
605
|
]);
|
|
632
606
|
for (const did of allDiagramIds) {
|
|
633
|
-
if (!did)
|
|
634
|
-
continue;
|
|
607
|
+
if (!did) continue;
|
|
635
608
|
const prevCells = prevCellsOrder.get(did) || [];
|
|
636
609
|
const currCells = currCellsOrder.get(did) || [];
|
|
637
|
-
if (!prevCells.length && !currCells.length)
|
|
638
|
-
continue;
|
|
610
|
+
if (!prevCells.length && !currCells.length) continue;
|
|
639
611
|
const prevSet = new Set(prevCells);
|
|
640
612
|
const currSet = new Set(currCells);
|
|
641
613
|
const removed = prevCells.filter((cid) => !currSet.has(cid) && cid);
|
|
@@ -671,8 +643,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
671
643
|
const prevP = prevNeighbor(prevCells, cid);
|
|
672
644
|
const currP = prevNeighbor(currCells, cid);
|
|
673
645
|
if (prevP !== currP) {
|
|
674
|
-
if (prevP && removedCellSet.has(prevP))
|
|
675
|
-
continue;
|
|
646
|
+
if (prevP && removedCellSet.has(prevP)) continue;
|
|
676
647
|
const cells = ensureCellSection(did);
|
|
677
648
|
cells[DIFF_UPDATE] = cells[DIFF_UPDATE] || {};
|
|
678
649
|
const cellUpdate = cells[DIFF_UPDATE][cid] = cells[DIFF_UPDATE][cid] || {};
|
|
@@ -686,16 +657,12 @@ function generatePatch(events, explicitDoc) {
|
|
|
686
657
|
);
|
|
687
658
|
for (const ev of events) {
|
|
688
659
|
const target = ev.target;
|
|
689
|
-
if (!(target instanceof Y.Map))
|
|
690
|
-
|
|
691
|
-
if (!diagramSet.has(target))
|
|
692
|
-
continue;
|
|
660
|
+
if (!(target instanceof Y.Map)) continue;
|
|
661
|
+
if (!diagramSet.has(target)) continue;
|
|
693
662
|
const changed = ev.keysChanged || /* @__PURE__ */ new Set();
|
|
694
|
-
if (!changed || !changed.has("name"))
|
|
695
|
-
continue;
|
|
663
|
+
if (!changed || !changed.has("name")) continue;
|
|
696
664
|
const did = target.get("id") || "";
|
|
697
|
-
if (!did || insertedDiagramIdGlobal.has(did))
|
|
698
|
-
continue;
|
|
665
|
+
if (!did || insertedDiagramIdGlobal.has(did)) continue;
|
|
699
666
|
const u = ensureUpdate(did);
|
|
700
667
|
u.name = target.get("name") || "";
|
|
701
668
|
}
|
|
@@ -703,25 +670,20 @@ function generatePatch(events, explicitDoc) {
|
|
|
703
670
|
if (!prevDiagramOrder) {
|
|
704
671
|
for (const d of diagramsList) {
|
|
705
672
|
const did = d.get("id") || "";
|
|
706
|
-
if (!did)
|
|
707
|
-
continue;
|
|
673
|
+
if (!did) continue;
|
|
708
674
|
const u = ensureUpdate(did);
|
|
709
675
|
u.name = d.get("name") || "";
|
|
710
676
|
}
|
|
711
677
|
}
|
|
712
678
|
for (const ev of events) {
|
|
713
679
|
const target = ev.target;
|
|
714
|
-
if (!(target instanceof Y.XmlElement))
|
|
715
|
-
continue;
|
|
680
|
+
if (!(target instanceof Y.XmlElement)) continue;
|
|
716
681
|
const el = target;
|
|
717
|
-
if (el.nodeName !== "mxCell")
|
|
718
|
-
continue;
|
|
682
|
+
if (el.nodeName !== "mxCell") continue;
|
|
719
683
|
const changed = ev.attributesChanged || ev.keysChanged || /* @__PURE__ */ new Set();
|
|
720
|
-
if (!changed || changed.size === 0)
|
|
721
|
-
continue;
|
|
684
|
+
if (!changed || changed.size === 0) continue;
|
|
722
685
|
const cellId = el.getAttribute("id");
|
|
723
|
-
if (!cellId || insertedCellIdGlobal.has(cellId))
|
|
724
|
-
continue;
|
|
686
|
+
if (!cellId || insertedCellIdGlobal.has(cellId)) continue;
|
|
725
687
|
const idsEntries = Array.from(currCellsOrder.entries());
|
|
726
688
|
let diagramId = "";
|
|
727
689
|
for (const [did, ids] of idsEntries) {
|
|
@@ -730,8 +692,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
730
692
|
break;
|
|
731
693
|
}
|
|
732
694
|
}
|
|
733
|
-
if (!diagramId)
|
|
734
|
-
continue;
|
|
695
|
+
if (!diagramId) continue;
|
|
735
696
|
const cellsPatch = ensureCellSection(diagramId);
|
|
736
697
|
cellsPatch[DIFF_UPDATE] = cellsPatch[DIFF_UPDATE] || {};
|
|
737
698
|
const cellUpdate = cellsPatch[DIFF_UPDATE][cellId] = cellsPatch[DIFF_UPDATE][cellId] || {};
|
|
@@ -747,8 +708,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
747
708
|
const updateBucket = cellsPatch[DIFF_UPDATE];
|
|
748
709
|
const currCells = currAttrsMap.keys();
|
|
749
710
|
for (const cid of currCells) {
|
|
750
|
-
if (insertedCellIdGlobal.has(cid))
|
|
751
|
-
continue;
|
|
711
|
+
if (insertedCellIdGlobal.has(cid)) continue;
|
|
752
712
|
const prevAttrs = prevAttrsMap.get(cid) || {};
|
|
753
713
|
const currAttrs = currAttrsMap.get(cid) || {};
|
|
754
714
|
const keys = /* @__PURE__ */ new Set([
|
|
@@ -885,10 +845,8 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
885
845
|
if (typeof this._y.clear === "function") {
|
|
886
846
|
this._y.clear();
|
|
887
847
|
} else {
|
|
888
|
-
while (this._y.canUndo && this._y.canUndo())
|
|
889
|
-
|
|
890
|
-
while (this._y.canRedo && this._y.canRedo())
|
|
891
|
-
this._y.redo();
|
|
848
|
+
while (this._y.canUndo && this._y.canUndo()) this._y.undo();
|
|
849
|
+
while (this._y.canRedo && this._y.canRedo()) this._y.redo();
|
|
892
850
|
}
|
|
893
851
|
this.history = [];
|
|
894
852
|
this.indexOfNextAdd = 0;
|
|
@@ -944,8 +902,7 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
944
902
|
const poppedHandler = (e) => {
|
|
945
903
|
const t = e && (e.type || e.reason || e.kind);
|
|
946
904
|
if (t === "undo") {
|
|
947
|
-
if (mxLike.indexOfNextAdd > 0)
|
|
948
|
-
mxLike.indexOfNextAdd--;
|
|
905
|
+
if (mxLike.indexOfNextAdd > 0) mxLike.indexOfNextAdd--;
|
|
949
906
|
const evt = createMxEventObject("undo", { edit: { changes: [] } });
|
|
950
907
|
mxLike.fireEvent(evt);
|
|
951
908
|
} else if (t === "redo") {
|
|
@@ -987,27 +944,23 @@ function getAwarenessStateValue(awareness, key2, clientId) {
|
|
|
987
944
|
const states = awareness.getStates();
|
|
988
945
|
const id = clientId != null ? Number(clientId) : awareness.clientID;
|
|
989
946
|
const clientState = states.get(id);
|
|
990
|
-
if (!clientState)
|
|
991
|
-
|
|
992
|
-
if (!key2)
|
|
993
|
-
return clientState;
|
|
947
|
+
if (!clientState) return null;
|
|
948
|
+
if (!key2) return clientState;
|
|
994
949
|
return getByPath(clientState, key2);
|
|
995
950
|
}
|
|
996
951
|
function getByPath(obj, path) {
|
|
997
952
|
const parts = path.split(".");
|
|
998
953
|
let cur = obj;
|
|
999
954
|
for (const part of parts) {
|
|
1000
|
-
if (cur == null)
|
|
1001
|
-
return null;
|
|
955
|
+
if (cur == null) return null;
|
|
1002
956
|
const key2 = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
|
|
1003
957
|
cur = cur == null ? void 0 : cur[key2];
|
|
1004
958
|
}
|
|
1005
959
|
return cur;
|
|
1006
960
|
}
|
|
1007
961
|
function setAwarenessStateValue(awareness, key2, value, clientId) {
|
|
1008
|
-
const id =
|
|
1009
|
-
if (id !== awareness.clientID)
|
|
1010
|
-
return false;
|
|
962
|
+
const id = awareness.clientID;
|
|
963
|
+
if (id !== awareness.clientID) return false;
|
|
1011
964
|
if (!key2) {
|
|
1012
965
|
awareness.setLocalState(value);
|
|
1013
966
|
return true;
|
|
@@ -1080,18 +1033,12 @@ function hslToHex(h, s, l) {
|
|
|
1080
1033
|
const hp = h / 60;
|
|
1081
1034
|
const x = c * (1 - Math.abs(hp % 2 - 1));
|
|
1082
1035
|
let r1 = 0, g1 = 0, b1 = 0;
|
|
1083
|
-
if (hp >= 0 && hp < 1)
|
|
1084
|
-
|
|
1085
|
-
else if (hp >=
|
|
1086
|
-
|
|
1087
|
-
else if (hp >=
|
|
1088
|
-
|
|
1089
|
-
else if (hp >= 3 && hp < 4)
|
|
1090
|
-
[r1, g1, b1] = [0, x, c];
|
|
1091
|
-
else if (hp >= 4 && hp < 5)
|
|
1092
|
-
[r1, g1, b1] = [x, 0, c];
|
|
1093
|
-
else
|
|
1094
|
-
[r1, g1, b1] = [c, 0, x];
|
|
1036
|
+
if (hp >= 0 && hp < 1) [r1, g1, b1] = [c, x, 0];
|
|
1037
|
+
else if (hp >= 1 && hp < 2) [r1, g1, b1] = [x, c, 0];
|
|
1038
|
+
else if (hp >= 2 && hp < 3) [r1, g1, b1] = [0, c, x];
|
|
1039
|
+
else if (hp >= 3 && hp < 4) [r1, g1, b1] = [0, x, c];
|
|
1040
|
+
else if (hp >= 4 && hp < 5) [r1, g1, b1] = [x, 0, c];
|
|
1041
|
+
else [r1, g1, b1] = [c, 0, x];
|
|
1095
1042
|
const m = l - c / 2;
|
|
1096
1043
|
const r = Math.round((r1 + m) * 255);
|
|
1097
1044
|
const g = Math.round((g1 + m) * 255);
|
|
@@ -1199,8 +1146,7 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1199
1146
|
const otherPageRemotes = [];
|
|
1200
1147
|
const leaveRemotesIds = /* @__PURE__ */ new Set();
|
|
1201
1148
|
Array.from(cache.keys()).forEach((clientId) => {
|
|
1202
|
-
if (!remotes.has(clientId))
|
|
1203
|
-
leaveRemotesIds.add(clientId);
|
|
1149
|
+
if (!remotes.has(clientId)) leaveRemotesIds.add(clientId);
|
|
1204
1150
|
});
|
|
1205
1151
|
Array.from(remotes.values()).forEach((remote) => {
|
|
1206
1152
|
var _a2;
|
|
@@ -1213,24 +1159,20 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1213
1159
|
leaveRemotesIds.forEach((clientId) => {
|
|
1214
1160
|
const el = cache.get(clientId);
|
|
1215
1161
|
cache.delete(clientId);
|
|
1216
|
-
if (!el)
|
|
1217
|
-
return;
|
|
1162
|
+
if (!el) return;
|
|
1218
1163
|
el.remove();
|
|
1219
1164
|
});
|
|
1220
1165
|
otherPageRemotes.forEach(({ clientId }) => {
|
|
1221
1166
|
const el = cache.get(clientId);
|
|
1222
|
-
if (!el)
|
|
1223
|
-
return;
|
|
1167
|
+
if (!el) return;
|
|
1224
1168
|
el.remove();
|
|
1225
1169
|
});
|
|
1226
|
-
if (!currentPageRemotes.length)
|
|
1227
|
-
return;
|
|
1170
|
+
if (!currentPageRemotes.length) return;
|
|
1228
1171
|
const graph = ui.editor.graph;
|
|
1229
1172
|
const { translate, scale } = graph.view;
|
|
1230
1173
|
currentPageRemotes.forEach(
|
|
1231
1174
|
({ clientId, cursorState, userColor, userName }) => {
|
|
1232
|
-
if (!cursorState)
|
|
1233
|
-
return;
|
|
1175
|
+
if (!cursorState) return;
|
|
1234
1176
|
let el = cache.get(clientId);
|
|
1235
1177
|
if (cursorState.hide) {
|
|
1236
1178
|
if (el) {
|
|
@@ -1267,8 +1209,7 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1267
1209
|
);
|
|
1268
1210
|
}
|
|
1269
1211
|
function getId(item) {
|
|
1270
|
-
if (item.id)
|
|
1271
|
-
return item.id;
|
|
1212
|
+
if (item.id) return item.id;
|
|
1272
1213
|
return null;
|
|
1273
1214
|
}
|
|
1274
1215
|
const SELECTION_OPACITY = 70;
|
|
@@ -1307,8 +1248,7 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1307
1248
|
const otherPageRemotes = [];
|
|
1308
1249
|
const leaveRemotesIds = /* @__PURE__ */ new Set();
|
|
1309
1250
|
Array.from(cache.keys()).forEach((clientId) => {
|
|
1310
|
-
if (!remotes.has(clientId))
|
|
1311
|
-
leaveRemotesIds.add(clientId);
|
|
1251
|
+
if (!remotes.has(clientId)) leaveRemotesIds.add(clientId);
|
|
1312
1252
|
});
|
|
1313
1253
|
Array.from(remotes.values()).forEach((remote) => {
|
|
1314
1254
|
var _a2;
|
|
@@ -1321,20 +1261,17 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1321
1261
|
leaveRemotesIds.forEach((clientId) => {
|
|
1322
1262
|
const highlightCellMap = cache.get(clientId);
|
|
1323
1263
|
cache.delete(clientId);
|
|
1324
|
-
if (!highlightCellMap)
|
|
1325
|
-
return;
|
|
1264
|
+
if (!highlightCellMap) return;
|
|
1326
1265
|
Array.from(highlightCellMap.values()).forEach((h) => h.destroy());
|
|
1327
1266
|
highlightCellMap.clear();
|
|
1328
1267
|
});
|
|
1329
1268
|
otherPageRemotes.forEach(({ clientId }) => {
|
|
1330
1269
|
const highlightCellMap = cache.get(clientId);
|
|
1331
|
-
if (!highlightCellMap)
|
|
1332
|
-
return;
|
|
1270
|
+
if (!highlightCellMap) return;
|
|
1333
1271
|
Array.from(highlightCellMap.values()).forEach((h) => h.destroy());
|
|
1334
1272
|
highlightCellMap.clear();
|
|
1335
1273
|
});
|
|
1336
|
-
if (!currentPageRemotes.length)
|
|
1337
|
-
return;
|
|
1274
|
+
if (!currentPageRemotes.length) return;
|
|
1338
1275
|
const graph = ui.editor.graph;
|
|
1339
1276
|
currentPageRemotes.forEach(({ clientId, selectionState, userColor }) => {
|
|
1340
1277
|
let highlightCellMap = cache.get(clientId);
|
|
@@ -1351,8 +1288,7 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1351
1288
|
}
|
|
1352
1289
|
});
|
|
1353
1290
|
currentIds.forEach((id) => {
|
|
1354
|
-
if (highlightCellMap.has(id))
|
|
1355
|
-
return;
|
|
1291
|
+
if (highlightCellMap.has(id)) return;
|
|
1356
1292
|
const cell = graph.model.getCell(id);
|
|
1357
1293
|
if (cell) {
|
|
1358
1294
|
const highlightCell = graph.highlightCell(
|
|
@@ -1403,10 +1339,8 @@ function bindCollaborator(file, options) {
|
|
|
1403
1339
|
const remotes = /* @__PURE__ */ new Map();
|
|
1404
1340
|
const changedClientIds = /* @__PURE__ */ new Set([...update.added, ...update.updated]);
|
|
1405
1341
|
for (const [clientId] of states.entries()) {
|
|
1406
|
-
if (clientId === awareness.clientID)
|
|
1407
|
-
|
|
1408
|
-
if (!changedClientIds.has(clientId))
|
|
1409
|
-
continue;
|
|
1342
|
+
if (clientId === awareness.clientID) continue;
|
|
1343
|
+
if (!changedClientIds.has(clientId)) continue;
|
|
1410
1344
|
const name = getAwarenessStateValue(awareness, userNameKey, clientId) || clientId + "";
|
|
1411
1345
|
const color = getAwarenessStateValue(awareness, userColorKey, clientId) || "#000000";
|
|
1412
1346
|
remotes.set(clientId, {
|
|
@@ -1469,8 +1403,7 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
|
1469
1403
|
var _a;
|
|
1470
1404
|
for (const diagram of mxfileObj.diagram) {
|
|
1471
1405
|
const id = ((_a = diagram._attributes) == null ? void 0 : _a.id) || "";
|
|
1472
|
-
if (!id)
|
|
1473
|
-
continue;
|
|
1406
|
+
if (!id) continue;
|
|
1474
1407
|
const docHas = diagramMap.has(id);
|
|
1475
1408
|
if (docHas && strategy === "merge-remote") {
|
|
1476
1409
|
continue;
|
|
@@ -1537,19 +1470,18 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1537
1470
|
const ok = mergeFileIntoDoc(doc, file.data, strategy);
|
|
1538
1471
|
if (!ok) {
|
|
1539
1472
|
const xml2 = doc2xml(doc);
|
|
1540
|
-
if (xml2 && xml2.includes("<diagram"))
|
|
1541
|
-
applyFileData(file, xml2);
|
|
1473
|
+
if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
|
|
1542
1474
|
return mxfileMap.size > 0;
|
|
1543
1475
|
}
|
|
1544
1476
|
const xml = doc2xml(doc);
|
|
1545
|
-
if (xml && xml.includes("<diagram"))
|
|
1546
|
-
applyFileData(file, xml);
|
|
1477
|
+
if (xml && xml.includes("<diagram")) applyFileData(file, xml);
|
|
1547
1478
|
return true;
|
|
1548
1479
|
}
|
|
1549
1480
|
class Binding {
|
|
1550
1481
|
constructor(file, options) {
|
|
1551
1482
|
this.suppressLocalApply = false;
|
|
1552
1483
|
this.docInitialized = false;
|
|
1484
|
+
this.ui = null;
|
|
1553
1485
|
const {
|
|
1554
1486
|
doc,
|
|
1555
1487
|
awareness,
|
|
@@ -1557,13 +1489,18 @@ class Binding {
|
|
|
1557
1489
|
mouseMoveThrottle,
|
|
1558
1490
|
cursor,
|
|
1559
1491
|
initialContent = "replace",
|
|
1560
|
-
applyFileData = defaultApplyFileData
|
|
1492
|
+
applyFileData = defaultApplyFileData,
|
|
1493
|
+
disableBeforeUnload = true
|
|
1561
1494
|
} = options;
|
|
1562
1495
|
this.doc = doc;
|
|
1563
1496
|
this.initialContentStrategy = initialContent;
|
|
1564
1497
|
const ui = file.getUi();
|
|
1565
1498
|
const graph = ui.editor.graph;
|
|
1566
1499
|
this.mxGraphModel = graph.model;
|
|
1500
|
+
this.ui = ui;
|
|
1501
|
+
if (disableBeforeUnload) {
|
|
1502
|
+
ui.onBeforeUnload = () => null;
|
|
1503
|
+
}
|
|
1567
1504
|
this.suppressLocalApply = true;
|
|
1568
1505
|
try {
|
|
1569
1506
|
this.docInitialized = reconcileInitialContent(
|
|
@@ -1580,15 +1517,13 @@ class Binding {
|
|
|
1580
1517
|
}
|
|
1581
1518
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1582
1519
|
this.mxListener = () => {
|
|
1583
|
-
if (this.suppressLocalApply)
|
|
1584
|
-
return;
|
|
1520
|
+
if (this.suppressLocalApply) return;
|
|
1585
1521
|
const patch = file.ui.diffPages(
|
|
1586
1522
|
file.shadowPages,
|
|
1587
1523
|
file.ui.pages
|
|
1588
1524
|
);
|
|
1589
1525
|
const patchKeys = Object.keys(patch);
|
|
1590
|
-
if (patchKeys.length === 0)
|
|
1591
|
-
return;
|
|
1526
|
+
if (patchKeys.length === 0) return;
|
|
1592
1527
|
if (!this.docInitialized) {
|
|
1593
1528
|
doc.transact(() => {
|
|
1594
1529
|
xml2doc(file.data, doc);
|
|
@@ -1598,6 +1533,7 @@ class Binding {
|
|
|
1598
1533
|
}
|
|
1599
1534
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1600
1535
|
applyFilePatch(doc, patch, { origin: LOCAL_ORIGIN });
|
|
1536
|
+
this.resetEditorStatus();
|
|
1601
1537
|
};
|
|
1602
1538
|
this.mxGraphModel.addListener("change", this.mxListener);
|
|
1603
1539
|
this.docObserver = (events, transaction) => {
|
|
@@ -1616,10 +1552,7 @@ class Binding {
|
|
|
1616
1552
|
applyFileData(file, xml);
|
|
1617
1553
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1618
1554
|
initDocSnapshot(doc, false);
|
|
1619
|
-
|
|
1620
|
-
const editor = ui2.editor;
|
|
1621
|
-
editor.setStatus("");
|
|
1622
|
-
editor.setModified(false);
|
|
1555
|
+
this.resetEditorStatus();
|
|
1623
1556
|
} finally {
|
|
1624
1557
|
this.suppressLocalApply = false;
|
|
1625
1558
|
}
|
|
@@ -1632,12 +1565,12 @@ class Binding {
|
|
|
1632
1565
|
this.docInitialized = true;
|
|
1633
1566
|
}
|
|
1634
1567
|
const patch = generatePatch(events);
|
|
1635
|
-
if (Object.keys(patch).length === 0)
|
|
1636
|
-
return;
|
|
1568
|
+
if (Object.keys(patch).length === 0) return;
|
|
1637
1569
|
this.suppressLocalApply = true;
|
|
1638
1570
|
try {
|
|
1639
1571
|
file.patch([patch]);
|
|
1640
1572
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1573
|
+
this.resetEditorStatus();
|
|
1641
1574
|
} finally {
|
|
1642
1575
|
this.suppressLocalApply = false;
|
|
1643
1576
|
}
|
|
@@ -1659,6 +1592,17 @@ class Binding {
|
|
|
1659
1592
|
get shouldReplaceWhenDocHasData() {
|
|
1660
1593
|
return this.initialContentStrategy === "replace" && !this.docInitialized;
|
|
1661
1594
|
}
|
|
1595
|
+
/**
|
|
1596
|
+
* 重置 editor 和 file 的 modified 状态及状态栏。
|
|
1597
|
+
* Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
|
|
1598
|
+
*/
|
|
1599
|
+
resetEditorStatus() {
|
|
1600
|
+
var _a;
|
|
1601
|
+
if (!this.ui) return;
|
|
1602
|
+
this.ui.editor.setModified(false);
|
|
1603
|
+
this.ui.editor.setStatus("");
|
|
1604
|
+
(_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
|
|
1605
|
+
}
|
|
1662
1606
|
/**
|
|
1663
1607
|
* 销毁绑定,解除所有监听器
|
|
1664
1608
|
* @param deep - 是否深度清理(包括 awareness/undoManager),默认 false
|
|
@@ -1712,8 +1656,6 @@ export {
|
|
|
1712
1656
|
DEFAULT_USER_COLOR_KEY,
|
|
1713
1657
|
DEFAULT_USER_NAME_KEY,
|
|
1714
1658
|
LOCAL_ORIGIN,
|
|
1715
|
-
createIframeBridgeProvider,
|
|
1716
|
-
createIframeBridgeServer,
|
|
1717
1659
|
doc2xml,
|
|
1718
1660
|
xml2doc
|
|
1719
1661
|
};
|