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.cjs.js
CHANGED
|
@@ -4,7 +4,6 @@ const xmlJs = require("xml-js");
|
|
|
4
4
|
const Y = require("yjs");
|
|
5
5
|
const lodashEs = require("lodash-es");
|
|
6
6
|
const colord = require("colord");
|
|
7
|
-
const iframeBridge = require("@y-mxgraph/iframe-bridge");
|
|
8
7
|
function _interopNamespaceDefault(e) {
|
|
9
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
9
|
if (e) {
|
|
@@ -23,21 +22,18 @@ function _interopNamespaceDefault(e) {
|
|
|
23
22
|
}
|
|
24
23
|
const Y__namespace = /* @__PURE__ */ _interopNamespaceDefault(Y);
|
|
25
24
|
function deepProcess(node) {
|
|
26
|
-
if (node == null)
|
|
27
|
-
return;
|
|
25
|
+
if (node == null) return;
|
|
28
26
|
if (Array.isArray(node)) {
|
|
29
27
|
for (const item of node) {
|
|
30
28
|
deepProcess(item);
|
|
31
29
|
}
|
|
32
30
|
return;
|
|
33
31
|
}
|
|
34
|
-
if (typeof node !== "object")
|
|
35
|
-
return;
|
|
32
|
+
if (typeof node !== "object") return;
|
|
36
33
|
const obj = node;
|
|
37
34
|
const keys = Object.keys(obj);
|
|
38
35
|
for (const key2 of keys) {
|
|
39
|
-
if (key2 === "_attributes")
|
|
40
|
-
continue;
|
|
36
|
+
if (key2 === "_attributes") continue;
|
|
41
37
|
let value = obj[key2];
|
|
42
38
|
const keyLower = key2.toLowerCase();
|
|
43
39
|
if ((keyLower === "diagram" || keyLower === "mxcell") && value !== void 0 && !Array.isArray(value)) {
|
|
@@ -45,8 +41,7 @@ function deepProcess(node) {
|
|
|
45
41
|
value = obj[key2];
|
|
46
42
|
}
|
|
47
43
|
if (Array.isArray(value)) {
|
|
48
|
-
for (const v of value)
|
|
49
|
-
deepProcess(v);
|
|
44
|
+
for (const v of value) deepProcess(v);
|
|
50
45
|
} else if (value && typeof value === "object") {
|
|
51
46
|
deepProcess(value);
|
|
52
47
|
}
|
|
@@ -218,18 +213,15 @@ const docSnapshots = /* @__PURE__ */ new WeakMap();
|
|
|
218
213
|
function insertAfterUnique(orderArr, id, previous, fallbackToEnd = false) {
|
|
219
214
|
const currentIds = orderArr.toArray();
|
|
220
215
|
let anchorPos = previous ? currentIds.indexOf(previous) : -1;
|
|
221
|
-
if (anchorPos === -1 && fallbackToEnd)
|
|
222
|
-
anchorPos = currentIds.length - 1;
|
|
216
|
+
if (anchorPos === -1 && fallbackToEnd) anchorPos = currentIds.length - 1;
|
|
223
217
|
let targetIndex = anchorPos + 1;
|
|
224
218
|
const existingIndex = currentIds.indexOf(id);
|
|
225
219
|
if (existingIndex === -1) {
|
|
226
220
|
orderArr.insert(targetIndex, [id]);
|
|
227
221
|
return;
|
|
228
222
|
}
|
|
229
|
-
if (existingIndex === targetIndex)
|
|
230
|
-
|
|
231
|
-
if (existingIndex < targetIndex)
|
|
232
|
-
targetIndex -= 1;
|
|
223
|
+
if (existingIndex === targetIndex) return;
|
|
224
|
+
if (existingIndex < targetIndex) targetIndex -= 1;
|
|
233
225
|
orderArr.delete(existingIndex, 1);
|
|
234
226
|
orderArr.insert(targetIndex, [id]);
|
|
235
227
|
}
|
|
@@ -239,12 +231,9 @@ function ensureUniqueOrder(orderArr) {
|
|
|
239
231
|
const dupIdx = [];
|
|
240
232
|
for (let i = 0; i < arr.length; i++) {
|
|
241
233
|
const id = arr[i];
|
|
242
|
-
if (!id)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
dupIdx.push(i);
|
|
246
|
-
else
|
|
247
|
-
seen.add(id);
|
|
234
|
+
if (!id) continue;
|
|
235
|
+
if (seen.has(id)) dupIdx.push(i);
|
|
236
|
+
else seen.add(id);
|
|
248
237
|
}
|
|
249
238
|
if (dupIdx.length) {
|
|
250
239
|
dupIdx.sort((a, b) => b - a).forEach((idx) => orderArr.delete(idx, 1));
|
|
@@ -327,10 +316,8 @@ function applyFilePatch(doc, patch, options) {
|
|
|
327
316
|
enriched.sort((a, b) => {
|
|
328
317
|
const aIdx = a.anchorId ? existingIndex.get(a.anchorId) : -1;
|
|
329
318
|
const bIdx = b.anchorId ? existingIndex.get(b.anchorId) : -1;
|
|
330
|
-
if (aIdx !== bIdx)
|
|
331
|
-
|
|
332
|
-
if (a.depth !== b.depth)
|
|
333
|
-
return b.depth - a.depth;
|
|
319
|
+
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
320
|
+
if (a.depth !== b.depth) return b.depth - a.depth;
|
|
334
321
|
return b.order - a.order;
|
|
335
322
|
});
|
|
336
323
|
for (const item of enriched) {
|
|
@@ -354,12 +341,10 @@ function applyFilePatch(doc, patch, options) {
|
|
|
354
341
|
}
|
|
355
342
|
if (update.cells) {
|
|
356
343
|
const yMxGraphModel = diagram.get(key$2);
|
|
357
|
-
if (!yMxGraphModel)
|
|
358
|
-
return;
|
|
344
|
+
if (!yMxGraphModel) return;
|
|
359
345
|
const cellsMap = yMxGraphModel.get(key$3);
|
|
360
346
|
const orderArr = yMxGraphModel.get(mxCellOrderKey);
|
|
361
|
-
if (!cellsMap || !orderArr)
|
|
362
|
-
return;
|
|
347
|
+
if (!cellsMap || !orderArr) return;
|
|
363
348
|
ensureUniqueOrder(orderArr);
|
|
364
349
|
if (update.cells[DIFF_REMOVE] && update.cells[DIFF_REMOVE].length) {
|
|
365
350
|
const orderIds = orderArr.toArray();
|
|
@@ -372,12 +357,10 @@ function applyFilePatch(doc, patch, options) {
|
|
|
372
357
|
if (update.cells[DIFF_INSERT] && update.cells[DIFF_INSERT].length) {
|
|
373
358
|
for (const item of update.cells[DIFF_INSERT]) {
|
|
374
359
|
const id2 = item["id"];
|
|
375
|
-
if (!id2)
|
|
376
|
-
continue;
|
|
360
|
+
if (!id2) continue;
|
|
377
361
|
const xmlElement = new Y__namespace.XmlElement("mxCell");
|
|
378
362
|
Object.keys(item).forEach((key2) => {
|
|
379
|
-
if (key2 === "previous")
|
|
380
|
-
return;
|
|
363
|
+
if (key2 === "previous") return;
|
|
381
364
|
xmlElement.setAttribute(key2, item[key2]);
|
|
382
365
|
});
|
|
383
366
|
cellsMap.set(id2, xmlElement);
|
|
@@ -416,8 +399,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
416
399
|
const cell = cellsMap.get(cid);
|
|
417
400
|
if (cell) {
|
|
418
401
|
Object.keys(updateObj).forEach((k) => {
|
|
419
|
-
if (k === "previous")
|
|
420
|
-
return;
|
|
402
|
+
if (k === "previous") return;
|
|
421
403
|
cell.setAttribute(k, updateObj[k]);
|
|
422
404
|
});
|
|
423
405
|
}
|
|
@@ -426,8 +408,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
426
408
|
const updateObj = update.cells[DIFF_UPDATE][cellId];
|
|
427
409
|
const hasPrev = "previous" in updateObj;
|
|
428
410
|
const hasParent = "parent" in updateObj;
|
|
429
|
-
if (!hasPrev && !hasParent)
|
|
430
|
-
return;
|
|
411
|
+
if (!hasPrev && !hasParent) return;
|
|
431
412
|
const prevVal = hasPrev ? updateObj.previous : void 0;
|
|
432
413
|
const parentVal = hasParent ? updateObj.parent : void 0;
|
|
433
414
|
let anchorId = null;
|
|
@@ -457,8 +438,7 @@ function applyFilePatch(doc, patch, options) {
|
|
|
457
438
|
newCell = new Y__namespace.XmlElement("mxCell");
|
|
458
439
|
newCell.setAttribute("id", cellId);
|
|
459
440
|
Object.keys(updateObj).forEach((k) => {
|
|
460
|
-
if (k === "previous")
|
|
461
|
-
return;
|
|
441
|
+
if (k === "previous") return;
|
|
462
442
|
newCell.setAttribute(k, updateObj[k]);
|
|
463
443
|
});
|
|
464
444
|
cellsMap.set(cellId, newCell);
|
|
@@ -509,8 +489,7 @@ function initDocSnapshot(doc, resetSnapshot = false) {
|
|
|
509
489
|
const diagrams = diagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
|
|
510
490
|
for (const d of diagrams) {
|
|
511
491
|
const did = d.get("id") || "";
|
|
512
|
-
if (!did)
|
|
513
|
-
continue;
|
|
492
|
+
if (!did) continue;
|
|
514
493
|
const gm = d.get(key$2);
|
|
515
494
|
if (gm) {
|
|
516
495
|
const order = gm.get(mxCellOrderKey);
|
|
@@ -543,11 +522,9 @@ function initDocSnapshot(doc, resetSnapshot = false) {
|
|
|
543
522
|
function generatePatch(events, explicitDoc) {
|
|
544
523
|
var _a, _b;
|
|
545
524
|
const patch = {};
|
|
546
|
-
const doc =
|
|
547
|
-
if (!doc)
|
|
548
|
-
|
|
549
|
-
if (!explicitDoc && (!events || events.length === 0))
|
|
550
|
-
return patch;
|
|
525
|
+
const doc = (_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc;
|
|
526
|
+
if (!doc) return patch;
|
|
527
|
+
if (!events || events.length === 0) return patch;
|
|
551
528
|
const mxfile = doc.getMap(key);
|
|
552
529
|
const diagramsMap = mxfile.get(key$1);
|
|
553
530
|
const orderArr = mxfile.get(diagramOrderKey);
|
|
@@ -573,7 +550,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
573
550
|
u.cells = u.cells || {};
|
|
574
551
|
return u.cells;
|
|
575
552
|
};
|
|
576
|
-
const orderIds = orderArr.toArray();
|
|
553
|
+
const orderIds = (orderArr == null ? void 0 : orderArr.toArray()) ?? [];
|
|
577
554
|
const currDiagramOrder = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
|
|
578
555
|
const diagramsList = currDiagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
|
|
579
556
|
const currCellsOrder = /* @__PURE__ */ new Map();
|
|
@@ -609,8 +586,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
609
586
|
const removed = prevDiagramOrder.filter(
|
|
610
587
|
(id) => !currSet.has(id) && id
|
|
611
588
|
);
|
|
612
|
-
if (removed.length)
|
|
613
|
-
patch[DIFF_REMOVE] = removed;
|
|
589
|
+
if (removed.length) patch[DIFF_REMOVE] = removed;
|
|
614
590
|
const removedDiagramSet = new Set(removed);
|
|
615
591
|
const inserted = currDiagramOrder.filter(
|
|
616
592
|
(id) => !prevSet.has(id) && id
|
|
@@ -621,8 +597,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
621
597
|
const index = currDiagramOrder.indexOf(id);
|
|
622
598
|
const previous = index <= 0 ? "" : currDiagramOrder[index - 1];
|
|
623
599
|
const yDiagram = diagramsMap.get(id);
|
|
624
|
-
if (!yDiagram)
|
|
625
|
-
continue;
|
|
600
|
+
if (!yDiagram) continue;
|
|
626
601
|
const data = serializer$1({ diagram: serialize(yDiagram) });
|
|
627
602
|
patch[DIFF_INSERT].push({ id, previous, data });
|
|
628
603
|
insertedDiagramIdGlobal.add(id);
|
|
@@ -637,8 +612,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
637
612
|
const prevP = prevNeighbor(prevDiagramOrder, id);
|
|
638
613
|
const currP = prevNeighbor(currDiagramOrder, id);
|
|
639
614
|
if (prevP !== currP) {
|
|
640
|
-
if (prevP && removedDiagramSet.has(prevP))
|
|
641
|
-
continue;
|
|
615
|
+
if (prevP && removedDiagramSet.has(prevP)) continue;
|
|
642
616
|
const u = ensureUpdate(id);
|
|
643
617
|
u.previous = currP;
|
|
644
618
|
}
|
|
@@ -649,12 +623,10 @@ function generatePatch(events, explicitDoc) {
|
|
|
649
623
|
...currDiagramOrder
|
|
650
624
|
]);
|
|
651
625
|
for (const did of allDiagramIds) {
|
|
652
|
-
if (!did)
|
|
653
|
-
continue;
|
|
626
|
+
if (!did) continue;
|
|
654
627
|
const prevCells = prevCellsOrder.get(did) || [];
|
|
655
628
|
const currCells = currCellsOrder.get(did) || [];
|
|
656
|
-
if (!prevCells.length && !currCells.length)
|
|
657
|
-
continue;
|
|
629
|
+
if (!prevCells.length && !currCells.length) continue;
|
|
658
630
|
const prevSet = new Set(prevCells);
|
|
659
631
|
const currSet = new Set(currCells);
|
|
660
632
|
const removed = prevCells.filter((cid) => !currSet.has(cid) && cid);
|
|
@@ -690,8 +662,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
690
662
|
const prevP = prevNeighbor(prevCells, cid);
|
|
691
663
|
const currP = prevNeighbor(currCells, cid);
|
|
692
664
|
if (prevP !== currP) {
|
|
693
|
-
if (prevP && removedCellSet.has(prevP))
|
|
694
|
-
continue;
|
|
665
|
+
if (prevP && removedCellSet.has(prevP)) continue;
|
|
695
666
|
const cells = ensureCellSection(did);
|
|
696
667
|
cells[DIFF_UPDATE] = cells[DIFF_UPDATE] || {};
|
|
697
668
|
const cellUpdate = cells[DIFF_UPDATE][cid] = cells[DIFF_UPDATE][cid] || {};
|
|
@@ -705,16 +676,12 @@ function generatePatch(events, explicitDoc) {
|
|
|
705
676
|
);
|
|
706
677
|
for (const ev of events) {
|
|
707
678
|
const target = ev.target;
|
|
708
|
-
if (!(target instanceof Y__namespace.Map))
|
|
709
|
-
|
|
710
|
-
if (!diagramSet.has(target))
|
|
711
|
-
continue;
|
|
679
|
+
if (!(target instanceof Y__namespace.Map)) continue;
|
|
680
|
+
if (!diagramSet.has(target)) continue;
|
|
712
681
|
const changed = ev.keysChanged || /* @__PURE__ */ new Set();
|
|
713
|
-
if (!changed || !changed.has("name"))
|
|
714
|
-
continue;
|
|
682
|
+
if (!changed || !changed.has("name")) continue;
|
|
715
683
|
const did = target.get("id") || "";
|
|
716
|
-
if (!did || insertedDiagramIdGlobal.has(did))
|
|
717
|
-
continue;
|
|
684
|
+
if (!did || insertedDiagramIdGlobal.has(did)) continue;
|
|
718
685
|
const u = ensureUpdate(did);
|
|
719
686
|
u.name = target.get("name") || "";
|
|
720
687
|
}
|
|
@@ -722,25 +689,20 @@ function generatePatch(events, explicitDoc) {
|
|
|
722
689
|
if (!prevDiagramOrder) {
|
|
723
690
|
for (const d of diagramsList) {
|
|
724
691
|
const did = d.get("id") || "";
|
|
725
|
-
if (!did)
|
|
726
|
-
continue;
|
|
692
|
+
if (!did) continue;
|
|
727
693
|
const u = ensureUpdate(did);
|
|
728
694
|
u.name = d.get("name") || "";
|
|
729
695
|
}
|
|
730
696
|
}
|
|
731
697
|
for (const ev of events) {
|
|
732
698
|
const target = ev.target;
|
|
733
|
-
if (!(target instanceof Y__namespace.XmlElement))
|
|
734
|
-
continue;
|
|
699
|
+
if (!(target instanceof Y__namespace.XmlElement)) continue;
|
|
735
700
|
const el = target;
|
|
736
|
-
if (el.nodeName !== "mxCell")
|
|
737
|
-
continue;
|
|
701
|
+
if (el.nodeName !== "mxCell") continue;
|
|
738
702
|
const changed = ev.attributesChanged || ev.keysChanged || /* @__PURE__ */ new Set();
|
|
739
|
-
if (!changed || changed.size === 0)
|
|
740
|
-
continue;
|
|
703
|
+
if (!changed || changed.size === 0) continue;
|
|
741
704
|
const cellId = el.getAttribute("id");
|
|
742
|
-
if (!cellId || insertedCellIdGlobal.has(cellId))
|
|
743
|
-
continue;
|
|
705
|
+
if (!cellId || insertedCellIdGlobal.has(cellId)) continue;
|
|
744
706
|
const idsEntries = Array.from(currCellsOrder.entries());
|
|
745
707
|
let diagramId = "";
|
|
746
708
|
for (const [did, ids] of idsEntries) {
|
|
@@ -749,8 +711,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
749
711
|
break;
|
|
750
712
|
}
|
|
751
713
|
}
|
|
752
|
-
if (!diagramId)
|
|
753
|
-
continue;
|
|
714
|
+
if (!diagramId) continue;
|
|
754
715
|
const cellsPatch = ensureCellSection(diagramId);
|
|
755
716
|
cellsPatch[DIFF_UPDATE] = cellsPatch[DIFF_UPDATE] || {};
|
|
756
717
|
const cellUpdate = cellsPatch[DIFF_UPDATE][cellId] = cellsPatch[DIFF_UPDATE][cellId] || {};
|
|
@@ -766,8 +727,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
766
727
|
const updateBucket = cellsPatch[DIFF_UPDATE];
|
|
767
728
|
const currCells = currAttrsMap.keys();
|
|
768
729
|
for (const cid of currCells) {
|
|
769
|
-
if (insertedCellIdGlobal.has(cid))
|
|
770
|
-
continue;
|
|
730
|
+
if (insertedCellIdGlobal.has(cid)) continue;
|
|
771
731
|
const prevAttrs = prevAttrsMap.get(cid) || {};
|
|
772
732
|
const currAttrs = currAttrsMap.get(cid) || {};
|
|
773
733
|
const keys = /* @__PURE__ */ new Set([
|
|
@@ -810,7 +770,7 @@ function generatePatch(events, explicitDoc) {
|
|
|
810
770
|
docSnapshots.set(doc, snap);
|
|
811
771
|
return patch;
|
|
812
772
|
}
|
|
813
|
-
function
|
|
773
|
+
function xml2ydoc(xml, doc) {
|
|
814
774
|
const object = parse$4(xml);
|
|
815
775
|
const mxfile = object.mxfile;
|
|
816
776
|
const mxGraphModel = object.mxGraphModel;
|
|
@@ -827,7 +787,7 @@ function xml2doc(xml, doc) {
|
|
|
827
787
|
}
|
|
828
788
|
return doc;
|
|
829
789
|
}
|
|
830
|
-
function
|
|
790
|
+
function ydoc2xml(doc, spaces = 0) {
|
|
831
791
|
if (doc.share.has(key)) {
|
|
832
792
|
return serializer$1(
|
|
833
793
|
{
|
|
@@ -904,10 +864,8 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
904
864
|
if (typeof this._y.clear === "function") {
|
|
905
865
|
this._y.clear();
|
|
906
866
|
} else {
|
|
907
|
-
while (this._y.canUndo && this._y.canUndo())
|
|
908
|
-
|
|
909
|
-
while (this._y.canRedo && this._y.canRedo())
|
|
910
|
-
this._y.redo();
|
|
867
|
+
while (this._y.canUndo && this._y.canUndo()) this._y.undo();
|
|
868
|
+
while (this._y.canRedo && this._y.canRedo()) this._y.redo();
|
|
911
869
|
}
|
|
912
870
|
this.history = [];
|
|
913
871
|
this.indexOfNextAdd = 0;
|
|
@@ -963,8 +921,7 @@ function bindUndoManager(doc, file, yUndo) {
|
|
|
963
921
|
const poppedHandler = (e) => {
|
|
964
922
|
const t = e && (e.type || e.reason || e.kind);
|
|
965
923
|
if (t === "undo") {
|
|
966
|
-
if (mxLike.indexOfNextAdd > 0)
|
|
967
|
-
mxLike.indexOfNextAdd--;
|
|
924
|
+
if (mxLike.indexOfNextAdd > 0) mxLike.indexOfNextAdd--;
|
|
968
925
|
const evt = createMxEventObject("undo", { edit: { changes: [] } });
|
|
969
926
|
mxLike.fireEvent(evt);
|
|
970
927
|
} else if (t === "redo") {
|
|
@@ -1006,27 +963,23 @@ function getAwarenessStateValue(awareness, key2, clientId) {
|
|
|
1006
963
|
const states = awareness.getStates();
|
|
1007
964
|
const id = clientId != null ? Number(clientId) : awareness.clientID;
|
|
1008
965
|
const clientState = states.get(id);
|
|
1009
|
-
if (!clientState)
|
|
1010
|
-
|
|
1011
|
-
if (!key2)
|
|
1012
|
-
return clientState;
|
|
966
|
+
if (!clientState) return null;
|
|
967
|
+
if (!key2) return clientState;
|
|
1013
968
|
return getByPath(clientState, key2);
|
|
1014
969
|
}
|
|
1015
970
|
function getByPath(obj, path) {
|
|
1016
971
|
const parts = path.split(".");
|
|
1017
972
|
let cur = obj;
|
|
1018
973
|
for (const part of parts) {
|
|
1019
|
-
if (cur == null)
|
|
1020
|
-
return null;
|
|
974
|
+
if (cur == null) return null;
|
|
1021
975
|
const key2 = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
|
|
1022
976
|
cur = cur == null ? void 0 : cur[key2];
|
|
1023
977
|
}
|
|
1024
978
|
return cur;
|
|
1025
979
|
}
|
|
1026
980
|
function setAwarenessStateValue(awareness, key2, value, clientId) {
|
|
1027
|
-
const id =
|
|
1028
|
-
if (id !== awareness.clientID)
|
|
1029
|
-
return false;
|
|
981
|
+
const id = awareness.clientID;
|
|
982
|
+
if (id !== awareness.clientID) return false;
|
|
1030
983
|
if (!key2) {
|
|
1031
984
|
awareness.setLocalState(value);
|
|
1032
985
|
return true;
|
|
@@ -1099,18 +1052,12 @@ function hslToHex(h, s, l) {
|
|
|
1099
1052
|
const hp = h / 60;
|
|
1100
1053
|
const x = c * (1 - Math.abs(hp % 2 - 1));
|
|
1101
1054
|
let r1 = 0, g1 = 0, b1 = 0;
|
|
1102
|
-
if (hp >= 0 && hp < 1)
|
|
1103
|
-
|
|
1104
|
-
else if (hp >=
|
|
1105
|
-
|
|
1106
|
-
else if (hp >=
|
|
1107
|
-
|
|
1108
|
-
else if (hp >= 3 && hp < 4)
|
|
1109
|
-
[r1, g1, b1] = [0, x, c];
|
|
1110
|
-
else if (hp >= 4 && hp < 5)
|
|
1111
|
-
[r1, g1, b1] = [x, 0, c];
|
|
1112
|
-
else
|
|
1113
|
-
[r1, g1, b1] = [c, 0, x];
|
|
1055
|
+
if (hp >= 0 && hp < 1) [r1, g1, b1] = [c, x, 0];
|
|
1056
|
+
else if (hp >= 1 && hp < 2) [r1, g1, b1] = [x, c, 0];
|
|
1057
|
+
else if (hp >= 2 && hp < 3) [r1, g1, b1] = [0, c, x];
|
|
1058
|
+
else if (hp >= 3 && hp < 4) [r1, g1, b1] = [0, x, c];
|
|
1059
|
+
else if (hp >= 4 && hp < 5) [r1, g1, b1] = [x, 0, c];
|
|
1060
|
+
else [r1, g1, b1] = [c, 0, x];
|
|
1114
1061
|
const m = l - c / 2;
|
|
1115
1062
|
const r = Math.round((r1 + m) * 255);
|
|
1116
1063
|
const g = Math.round((g1 + m) * 255);
|
|
@@ -1218,8 +1165,7 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1218
1165
|
const otherPageRemotes = [];
|
|
1219
1166
|
const leaveRemotesIds = /* @__PURE__ */ new Set();
|
|
1220
1167
|
Array.from(cache.keys()).forEach((clientId) => {
|
|
1221
|
-
if (!remotes.has(clientId))
|
|
1222
|
-
leaveRemotesIds.add(clientId);
|
|
1168
|
+
if (!remotes.has(clientId)) leaveRemotesIds.add(clientId);
|
|
1223
1169
|
});
|
|
1224
1170
|
Array.from(remotes.values()).forEach((remote) => {
|
|
1225
1171
|
var _a2;
|
|
@@ -1232,24 +1178,20 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1232
1178
|
leaveRemotesIds.forEach((clientId) => {
|
|
1233
1179
|
const el = cache.get(clientId);
|
|
1234
1180
|
cache.delete(clientId);
|
|
1235
|
-
if (!el)
|
|
1236
|
-
return;
|
|
1181
|
+
if (!el) return;
|
|
1237
1182
|
el.remove();
|
|
1238
1183
|
});
|
|
1239
1184
|
otherPageRemotes.forEach(({ clientId }) => {
|
|
1240
1185
|
const el = cache.get(clientId);
|
|
1241
|
-
if (!el)
|
|
1242
|
-
return;
|
|
1186
|
+
if (!el) return;
|
|
1243
1187
|
el.remove();
|
|
1244
1188
|
});
|
|
1245
|
-
if (!currentPageRemotes.length)
|
|
1246
|
-
return;
|
|
1189
|
+
if (!currentPageRemotes.length) return;
|
|
1247
1190
|
const graph = ui.editor.graph;
|
|
1248
1191
|
const { translate, scale } = graph.view;
|
|
1249
1192
|
currentPageRemotes.forEach(
|
|
1250
1193
|
({ clientId, cursorState, userColor, userName }) => {
|
|
1251
|
-
if (!cursorState)
|
|
1252
|
-
return;
|
|
1194
|
+
if (!cursorState) return;
|
|
1253
1195
|
let el = cache.get(clientId);
|
|
1254
1196
|
if (cursorState.hide) {
|
|
1255
1197
|
if (el) {
|
|
@@ -1286,8 +1228,7 @@ function renderRemoteCursors(ui, remotes) {
|
|
|
1286
1228
|
);
|
|
1287
1229
|
}
|
|
1288
1230
|
function getId(item) {
|
|
1289
|
-
if (item.id)
|
|
1290
|
-
return item.id;
|
|
1231
|
+
if (item.id) return item.id;
|
|
1291
1232
|
return null;
|
|
1292
1233
|
}
|
|
1293
1234
|
const SELECTION_OPACITY = 70;
|
|
@@ -1326,8 +1267,7 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1326
1267
|
const otherPageRemotes = [];
|
|
1327
1268
|
const leaveRemotesIds = /* @__PURE__ */ new Set();
|
|
1328
1269
|
Array.from(cache.keys()).forEach((clientId) => {
|
|
1329
|
-
if (!remotes.has(clientId))
|
|
1330
|
-
leaveRemotesIds.add(clientId);
|
|
1270
|
+
if (!remotes.has(clientId)) leaveRemotesIds.add(clientId);
|
|
1331
1271
|
});
|
|
1332
1272
|
Array.from(remotes.values()).forEach((remote) => {
|
|
1333
1273
|
var _a2;
|
|
@@ -1340,20 +1280,17 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1340
1280
|
leaveRemotesIds.forEach((clientId) => {
|
|
1341
1281
|
const highlightCellMap = cache.get(clientId);
|
|
1342
1282
|
cache.delete(clientId);
|
|
1343
|
-
if (!highlightCellMap)
|
|
1344
|
-
return;
|
|
1283
|
+
if (!highlightCellMap) return;
|
|
1345
1284
|
Array.from(highlightCellMap.values()).forEach((h) => h.destroy());
|
|
1346
1285
|
highlightCellMap.clear();
|
|
1347
1286
|
});
|
|
1348
1287
|
otherPageRemotes.forEach(({ clientId }) => {
|
|
1349
1288
|
const highlightCellMap = cache.get(clientId);
|
|
1350
|
-
if (!highlightCellMap)
|
|
1351
|
-
return;
|
|
1289
|
+
if (!highlightCellMap) return;
|
|
1352
1290
|
Array.from(highlightCellMap.values()).forEach((h) => h.destroy());
|
|
1353
1291
|
highlightCellMap.clear();
|
|
1354
1292
|
});
|
|
1355
|
-
if (!currentPageRemotes.length)
|
|
1356
|
-
return;
|
|
1293
|
+
if (!currentPageRemotes.length) return;
|
|
1357
1294
|
const graph = ui.editor.graph;
|
|
1358
1295
|
currentPageRemotes.forEach(({ clientId, selectionState, userColor }) => {
|
|
1359
1296
|
let highlightCellMap = cache.get(clientId);
|
|
@@ -1370,8 +1307,7 @@ function renderRemoteSelections(ui, remotes) {
|
|
|
1370
1307
|
}
|
|
1371
1308
|
});
|
|
1372
1309
|
currentIds.forEach((id) => {
|
|
1373
|
-
if (highlightCellMap.has(id))
|
|
1374
|
-
return;
|
|
1310
|
+
if (highlightCellMap.has(id)) return;
|
|
1375
1311
|
const cell = graph.model.getCell(id);
|
|
1376
1312
|
if (cell) {
|
|
1377
1313
|
const highlightCell = graph.highlightCell(
|
|
@@ -1422,10 +1358,8 @@ function bindCollaborator(file, options) {
|
|
|
1422
1358
|
const remotes = /* @__PURE__ */ new Map();
|
|
1423
1359
|
const changedClientIds = /* @__PURE__ */ new Set([...update.added, ...update.updated]);
|
|
1424
1360
|
for (const [clientId] of states.entries()) {
|
|
1425
|
-
if (clientId === awareness.clientID)
|
|
1426
|
-
|
|
1427
|
-
if (!changedClientIds.has(clientId))
|
|
1428
|
-
continue;
|
|
1361
|
+
if (clientId === awareness.clientID) continue;
|
|
1362
|
+
if (!changedClientIds.has(clientId)) continue;
|
|
1429
1363
|
const name = getAwarenessStateValue(awareness, userNameKey, clientId) || clientId + "";
|
|
1430
1364
|
const color = getAwarenessStateValue(awareness, userColorKey, clientId) || "#000000";
|
|
1431
1365
|
remotes.set(clientId, {
|
|
@@ -1488,8 +1422,7 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
|
|
|
1488
1422
|
var _a;
|
|
1489
1423
|
for (const diagram of mxfileObj.diagram) {
|
|
1490
1424
|
const id = ((_a = diagram._attributes) == null ? void 0 : _a.id) || "";
|
|
1491
|
-
if (!id)
|
|
1492
|
-
continue;
|
|
1425
|
+
if (!id) continue;
|
|
1493
1426
|
const docHas = diagramMap.has(id);
|
|
1494
1427
|
if (docHas && strategy === "merge-remote") {
|
|
1495
1428
|
continue;
|
|
@@ -1512,7 +1445,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1512
1445
|
const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
|
|
1513
1446
|
if (strategy === "replace") {
|
|
1514
1447
|
if (docHasData) {
|
|
1515
|
-
const xml2 =
|
|
1448
|
+
const xml2 = ydoc2xml(doc);
|
|
1516
1449
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1517
1450
|
applyFileData(file, xml2);
|
|
1518
1451
|
} else if (!fileHasAnyData) {
|
|
@@ -1532,12 +1465,12 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1532
1465
|
if (!docHasData && fileHasDiagrams) {
|
|
1533
1466
|
try {
|
|
1534
1467
|
doc.transact(() => {
|
|
1535
|
-
|
|
1468
|
+
xml2ydoc(file.data, doc);
|
|
1536
1469
|
});
|
|
1537
1470
|
return true;
|
|
1538
1471
|
} catch (err) {
|
|
1539
1472
|
console.warn(
|
|
1540
|
-
"[y-mxgraph] merge 模式下
|
|
1473
|
+
"[y-mxgraph] merge 模式下 xml2ydoc 失败,回退 replace:",
|
|
1541
1474
|
err
|
|
1542
1475
|
);
|
|
1543
1476
|
applyFileData(file, Binding.generateFileTemplate("diagram-0"));
|
|
@@ -1545,7 +1478,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1545
1478
|
}
|
|
1546
1479
|
}
|
|
1547
1480
|
if (docHasData && !fileHasDiagrams) {
|
|
1548
|
-
const xml2 =
|
|
1481
|
+
const xml2 = ydoc2xml(doc);
|
|
1549
1482
|
if (xml2 && xml2.includes("<diagram")) {
|
|
1550
1483
|
applyFileData(file, xml2);
|
|
1551
1484
|
} else if (!fileHasAnyData) {
|
|
@@ -1555,14 +1488,12 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
|
|
|
1555
1488
|
}
|
|
1556
1489
|
const ok = mergeFileIntoDoc(doc, file.data, strategy);
|
|
1557
1490
|
if (!ok) {
|
|
1558
|
-
const xml2 =
|
|
1559
|
-
if (xml2 && xml2.includes("<diagram"))
|
|
1560
|
-
applyFileData(file, xml2);
|
|
1491
|
+
const xml2 = ydoc2xml(doc);
|
|
1492
|
+
if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
|
|
1561
1493
|
return mxfileMap.size > 0;
|
|
1562
1494
|
}
|
|
1563
|
-
const xml =
|
|
1564
|
-
if (xml && xml.includes("<diagram"))
|
|
1565
|
-
applyFileData(file, xml);
|
|
1495
|
+
const xml = ydoc2xml(doc);
|
|
1496
|
+
if (xml && xml.includes("<diagram")) applyFileData(file, xml);
|
|
1566
1497
|
return true;
|
|
1567
1498
|
}
|
|
1568
1499
|
class Binding {
|
|
@@ -1581,6 +1512,7 @@ class Binding {
|
|
|
1581
1512
|
disableBeforeUnload = true
|
|
1582
1513
|
} = options;
|
|
1583
1514
|
this.doc = doc;
|
|
1515
|
+
this.file = file;
|
|
1584
1516
|
this.initialContentStrategy = initialContent;
|
|
1585
1517
|
const ui = file.getUi();
|
|
1586
1518
|
const graph = ui.editor.graph;
|
|
@@ -1605,18 +1537,16 @@ class Binding {
|
|
|
1605
1537
|
}
|
|
1606
1538
|
file.setShadowPages(file.ui.clonePages(file.ui.pages));
|
|
1607
1539
|
this.mxListener = () => {
|
|
1608
|
-
if (this.suppressLocalApply)
|
|
1609
|
-
return;
|
|
1540
|
+
if (this.suppressLocalApply) return;
|
|
1610
1541
|
const patch = file.ui.diffPages(
|
|
1611
1542
|
file.shadowPages,
|
|
1612
1543
|
file.ui.pages
|
|
1613
1544
|
);
|
|
1614
1545
|
const patchKeys = Object.keys(patch);
|
|
1615
|
-
if (patchKeys.length === 0)
|
|
1616
|
-
return;
|
|
1546
|
+
if (patchKeys.length === 0) return;
|
|
1617
1547
|
if (!this.docInitialized) {
|
|
1618
1548
|
doc.transact(() => {
|
|
1619
|
-
|
|
1549
|
+
xml2ydoc(file.data, doc);
|
|
1620
1550
|
initDocSnapshot(doc, false);
|
|
1621
1551
|
});
|
|
1622
1552
|
this.docInitialized = true;
|
|
@@ -1635,7 +1565,7 @@ class Binding {
|
|
|
1635
1565
|
const mxfileMap = doc.getMap(key);
|
|
1636
1566
|
const diagramMap = mxfileMap.get(key$1);
|
|
1637
1567
|
if (diagramMap && diagramMap.size > 0) {
|
|
1638
|
-
const xml =
|
|
1568
|
+
const xml = ydoc2xml(doc);
|
|
1639
1569
|
if (xml && xml.includes("<diagram")) {
|
|
1640
1570
|
this.suppressLocalApply = true;
|
|
1641
1571
|
try {
|
|
@@ -1655,8 +1585,7 @@ class Binding {
|
|
|
1655
1585
|
this.docInitialized = true;
|
|
1656
1586
|
}
|
|
1657
1587
|
const patch = generatePatch(events);
|
|
1658
|
-
if (Object.keys(patch).length === 0)
|
|
1659
|
-
return;
|
|
1588
|
+
if (Object.keys(patch).length === 0) return;
|
|
1660
1589
|
this.suppressLocalApply = true;
|
|
1661
1590
|
try {
|
|
1662
1591
|
file.patch([patch]);
|
|
@@ -1689,8 +1618,7 @@ class Binding {
|
|
|
1689
1618
|
*/
|
|
1690
1619
|
resetEditorStatus() {
|
|
1691
1620
|
var _a;
|
|
1692
|
-
if (!this.ui)
|
|
1693
|
-
return;
|
|
1621
|
+
if (!this.ui) return;
|
|
1694
1622
|
this.ui.editor.setModified(false);
|
|
1695
1623
|
this.ui.editor.setStatus("");
|
|
1696
1624
|
(_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
|
|
@@ -1743,18 +1671,10 @@ class Binding {
|
|
|
1743
1671
|
return new Binding(file, options);
|
|
1744
1672
|
}
|
|
1745
1673
|
}
|
|
1746
|
-
Object.defineProperty(exports, "createIframeBridgeProvider", {
|
|
1747
|
-
enumerable: true,
|
|
1748
|
-
get: () => iframeBridge.createIframeBridgeProvider
|
|
1749
|
-
});
|
|
1750
|
-
Object.defineProperty(exports, "createIframeBridgeServer", {
|
|
1751
|
-
enumerable: true,
|
|
1752
|
-
get: () => iframeBridge.createIframeBridgeServer
|
|
1753
|
-
});
|
|
1754
1674
|
exports.Binding = Binding;
|
|
1755
1675
|
exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
|
|
1756
1676
|
exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;
|
|
1757
1677
|
exports.LOCAL_ORIGIN = LOCAL_ORIGIN;
|
|
1758
|
-
exports.
|
|
1759
|
-
exports.
|
|
1678
|
+
exports.xml2ydoc = xml2ydoc;
|
|
1679
|
+
exports.ydoc2xml = ydoc2xml;
|
|
1760
1680
|
//# sourceMappingURL=y-mxgraph.cjs.js.map
|