y-mxgraph 0.3.1 → 0.4.0
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.zh-CN.md +2 -2
- package/binding/index.d.ts +9 -1
- package/binding/index.d.ts.map +1 -1
- package/iframe-bridge/index.d.ts +2 -0
- package/iframe-bridge/index.d.ts.map +1 -0
- package/iframe-bridge/provider.cjs.js +246 -0
- package/iframe-bridge/provider.cjs.js.map +1 -0
- package/iframe-bridge/provider.es.js +229 -0
- package/iframe-bridge/provider.es.js.map +1 -0
- package/iframe-bridge/server.cjs.js +139 -0
- package/iframe-bridge/server.cjs.js.map +1 -0
- package/iframe-bridge/server.es.js +122 -0
- package/iframe-bridge/server.es.js.map +1 -0
- package/index.d.ts +1 -3
- package/index.d.ts.map +1 -1
- package/package.json +11 -3
- package/transformer/index.d.ts +2 -2
- package/transformer/index.d.ts.map +1 -1
- package/y-mxgraph.cjs.js +88 -168
- package/y-mxgraph.cjs.js.map +1 -1
- package/y-mxgraph.es.js +88 -162
- package/y-mxgraph.es.js.map +1 -1
- package/y-mxgraph.iife.js +0 -1758
- package/y-mxgraph.iife.js.map +0 -1
- package/y-mxgraph.umd.js +0 -1759
- package/y-mxgraph.umd.js.map +0 -1
package/y-mxgraph.es.js
CHANGED
|
@@ -2,23 +2,19 @@ import { xml2js, js2xml } 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);
|
|
@@ -554,7 +531,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
554
531
|
u.cells = u.cells || {};
|
|
555
532
|
return u.cells;
|
|
556
533
|
};
|
|
557
|
-
const orderIds = orderArr.toArray();
|
|
534
|
+
const orderIds = (orderArr == null ? void 0 : orderArr.toArray()) ?? [];
|
|
558
535
|
const currDiagramOrder = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
|
|
559
536
|
const diagramsList = currDiagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
|
|
560
537
|
const currCellsOrder = /* @__PURE__ */ new Map();
|
|
@@ -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([
|
|
@@ -791,7 +751,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
791
751
|
docSnapshots.set(doc, snap);
|
|
792
752
|
return patch;
|
|
793
753
|
}
|
|
794
|
-
function
|
|
754
|
+
function xml2ydoc(xml, doc) {
|
|
795
755
|
const object = parse$4(xml);
|
|
796
756
|
const mxfile = object.mxfile;
|
|
797
757
|
const mxGraphModel = object.mxGraphModel;
|
|
@@ -808,7 +768,7 @@ function xml2doc(xml, doc) {
|
|
|
808
768
|
}
|
|
809
769
|
return doc;
|
|
810
770
|
}
|
|
811
|
-
function
|
|
771
|
+
function ydoc2xml(doc, spaces = 0) {
|
|
812
772
|
if (doc.share.has(key)) {
|
|
813
773
|
return serializer$1(
|
|
814
774
|
{
|
|
@@ -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;
|
|
@@ -1493,7 +1426,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1493
1426
|
const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
|
|
1494
1427
|
if (strategy === "replace") {
|
|
1495
1428
|
if (docHasData) {
|
|
1496
|
-
const xml2 =
|
|
1429
|
+
const xml2 = ydoc2xml(doc);
|
|
1497
1430
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1498
1431
|
applyFileData(file, xml2);
|
|
1499
1432
|
} else if (!fileHasAnyData) {
|
|
@@ -1513,12 +1446,12 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1513
1446
|
if (!docHasData && fileHasDiagrams) {
|
|
1514
1447
|
try {
|
|
1515
1448
|
doc.transact(() => {
|
|
1516
|
-
|
|
1449
|
+
xml2ydoc(file.data, doc);
|
|
1517
1450
|
});
|
|
1518
1451
|
return true;
|
|
1519
1452
|
} catch (err) {
|
|
1520
1453
|
console.warn(
|
|
1521
|
-
"[y-mxgraph] merge 模式下
|
|
1454
|
+
"[y-mxgraph] merge 模式下 xml2ydoc 失败,回退 replace:",
|
|
1522
1455
|
err
|
|
1523
1456
|
);
|
|
1524
1457
|
applyFileData(file, Binding.generateFileTemplate("diagram-0"));
|
|
@@ -1526,7 +1459,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1526
1459
|
}
|
|
1527
1460
|
}
|
|
1528
1461
|
if (docHasData && !fileHasDiagrams) {
|
|
1529
|
-
const xml2 =
|
|
1462
|
+
const xml2 = ydoc2xml(doc);
|
|
1530
1463
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1531
1464
|
applyFileData(file, xml2);
|
|
1532
1465
|
} else if (!fileHasAnyData) {
|
|
@@ -1536,14 +1469,12 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1536
1469
|
}
|
|
1537
1470
|
const ok = mergeFileIntoDoc(doc, file.data, strategy);
|
|
1538
1471
|
if (!ok) {
|
|
1539
|
-
const xml2 =
|
|
1540
|
-
if (xml2 && xml2.includes("<diagram"))
|
|
1541
|
-
applyFileData(file, xml2);
|
|
1472
|
+
const xml2 = ydoc2xml(doc);
|
|
1473
|
+
if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
|
|
1542
1474
|
return mxfileMap.size > 0;
|
|
1543
1475
|
}
|
|
1544
|
-
const xml =
|
|
1545
|
-
if (xml && xml.includes("<diagram"))
|
|
1546
|
-
applyFileData(file, xml);
|
|
1476
|
+
const xml = ydoc2xml(doc);
|
|
1477
|
+
if (xml && xml.includes("<diagram")) applyFileData(file, xml);
|
|
1547
1478
|
return true;
|
|
1548
1479
|
}
|
|
1549
1480
|
class Binding {
|
|
@@ -1562,6 +1493,7 @@ class Binding {
|
|
|
1562
1493
|
disableBeforeUnload = true
|
|
1563
1494
|
} = options;
|
|
1564
1495
|
this.doc = doc;
|
|
1496
|
+
this.file = file;
|
|
1565
1497
|
this.initialContentStrategy = initialContent;
|
|
1566
1498
|
const ui = file.getUi();
|
|
1567
1499
|
const graph = ui.editor.graph;
|
|
@@ -1586,18 +1518,16 @@ class Binding {
|
|
|
1586
1518
|
}
|
|
1587
1519
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1588
1520
|
this.mxListener = () => {
|
|
1589
|
-
if (this.suppressLocalApply)
|
|
1590
|
-
return;
|
|
1521
|
+
if (this.suppressLocalApply) return;
|
|
1591
1522
|
const patch = file.ui.diffPages(
|
|
1592
1523
|
file.shadowPages,
|
|
1593
1524
|
file.ui.pages
|
|
1594
1525
|
);
|
|
1595
1526
|
const patchKeys = Object.keys(patch);
|
|
1596
|
-
if (patchKeys.length === 0)
|
|
1597
|
-
return;
|
|
1527
|
+
if (patchKeys.length === 0) return;
|
|
1598
1528
|
if (!this.docInitialized) {
|
|
1599
1529
|
doc.transact(() => {
|
|
1600
|
-
|
|
1530
|
+
xml2ydoc(file.data, doc);
|
|
1601
1531
|
initDocSnapshot(doc, false);
|
|
1602
1532
|
});
|
|
1603
1533
|
this.docInitialized = true;
|
|
@@ -1616,7 +1546,7 @@ class Binding {
|
|
|
1616
1546
|
const mxfileMap = doc.getMap(key);
|
|
1617
1547
|
const diagramMap = mxfileMap.get(key$1);
|
|
1618
1548
|
if (diagramMap && diagramMap.size > 0) {
|
|
1619
|
-
const xml =
|
|
1549
|
+
const xml = ydoc2xml(doc);
|
|
1620
1550
|
if (xml && xml.includes("<diagram")) {
|
|
1621
1551
|
this.suppressLocalApply = true;
|
|
1622
1552
|
try {
|
|
@@ -1636,8 +1566,7 @@ class Binding {
|
|
|
1636
1566
|
this.docInitialized = true;
|
|
1637
1567
|
}
|
|
1638
1568
|
const patch = generatePatch(events);
|
|
1639
|
-
if (Object.keys(patch).length === 0)
|
|
1640
|
-
return;
|
|
1569
|
+
if (Object.keys(patch).length === 0) return;
|
|
1641
1570
|
this.suppressLocalApply = true;
|
|
1642
1571
|
try {
|
|
1643
1572
|
file.patch([patch]);
|
|
@@ -1670,8 +1599,7 @@ class Binding {
|
|
|
1670
1599
|
*/
|
|
1671
1600
|
resetEditorStatus() {
|
|
1672
1601
|
var _a;
|
|
1673
|
-
if (!this.ui)
|
|
1674
|
-
return;
|
|
1602
|
+
if (!this.ui) return;
|
|
1675
1603
|
this.ui.editor.setModified(false);
|
|
1676
1604
|
this.ui.editor.setStatus("");
|
|
1677
1605
|
(_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
|
|
@@ -1729,9 +1657,7 @@ export {
|
|
|
1729
1657
|
DEFAULT_USER_COLOR_KEY,
|
|
1730
1658
|
DEFAULT_USER_NAME_KEY,
|
|
1731
1659
|
LOCAL_ORIGIN,
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
doc2xml,
|
|
1735
|
-
xml2doc
|
|
1660
|
+
xml2ydoc,
|
|
1661
|
+
ydoc2xml
|
|
1736
1662
|
};
|
|
1737
1663
|
//# sourceMappingURL=y-mxgraph.es.js.map
|