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/types/drawio.d.ts CHANGED
@@ -41,6 +41,8 @@ export interface MxGraph {
41
41
  /** draw.io 编辑器 */
42
42
  export interface DrawioEditor {
43
43
  graph: MxGraph;
44
+ setStatus(status: string): void;
45
+ setModified(modified: boolean): void;
44
46
  undoManager?: {
45
47
  eventListeners?: unknown[];
46
48
  undoListener?: (...args: unknown[]) => void;
@@ -51,6 +53,7 @@ export interface DrawioEditor {
51
53
  /** draw.io UI */
52
54
  export interface DrawioUi {
53
55
  editor: DrawioEditor;
56
+ currentFile: DrawioFile | null;
54
57
  currentPage?: DrawioPage | null;
55
58
  diagramContainer: HTMLElement;
56
59
  pages: unknown[];
@@ -75,6 +78,8 @@ export interface DrawioFile {
75
78
  patch(patches: unknown[]): void;
76
79
  /** 仅赋值 this.data = xml,不触发 UI 重绘 */
77
80
  setData(data: string): void;
81
+ isModified(): boolean;
82
+ setModified(modified: boolean): void;
78
83
  }
79
84
  /** draw.io App(demo 中通过 iframe 访问) */
80
85
  export interface DrawioApp {
@@ -1 +1 @@
1
- {"version":3,"file":"drawio.d.ts","sourceRoot":"","sources":["../../src/types/drawio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iBAAiB;AACjB,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,MAAM,CAAC;CACjB;AAED,iBAAiB;AACjB,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,iBAAiB;AACjB,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IACnE,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AAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC;AAED,mBAAmB;AACnB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,EAAE,EAAE,QAAQ,CAAC;IACb,KAAK,IAAI,QAAQ,CAAC;IAClB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,oCAAoC;IACpC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,IAAI,OAAO,CAAC;IACtB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;CACtC;AAED,sCAAsC;AACtC,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;CACtB"}
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
- return;
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
- continue;
244
- if (seen.has(id))
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
- return aIdx - bIdx;
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 = explicitDoc ?? ((_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc);
547
- if (!doc)
548
- return patch;
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);
@@ -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
- continue;
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([
@@ -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
- this._y.undo();
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
- return null;
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 = clientId != null ? Number(clientId) : awareness.clientID;
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
- [r1, g1, b1] = [c, x, 0];
1104
- else if (hp >= 1 && hp < 2)
1105
- [r1, g1, b1] = [x, c, 0];
1106
- else if (hp >= 2 && hp < 3)
1107
- [r1, g1, b1] = [0, c, x];
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
- continue;
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;
@@ -1556,19 +1489,18 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1556
1489
  const ok = mergeFileIntoDoc(doc, file.data, strategy);
1557
1490
  if (!ok) {
1558
1491
  const xml2 = doc2xml(doc);
1559
- if (xml2 && xml2.includes("<diagram"))
1560
- applyFileData(file, xml2);
1492
+ if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
1561
1493
  return mxfileMap.size > 0;
1562
1494
  }
1563
1495
  const xml = doc2xml(doc);
1564
- if (xml && xml.includes("<diagram"))
1565
- applyFileData(file, xml);
1496
+ if (xml && xml.includes("<diagram")) applyFileData(file, xml);
1566
1497
  return true;
1567
1498
  }
1568
1499
  class Binding {
1569
1500
  constructor(file, options) {
1570
1501
  this.suppressLocalApply = false;
1571
1502
  this.docInitialized = false;
1503
+ this.ui = null;
1572
1504
  const {
1573
1505
  doc,
1574
1506
  awareness,
@@ -1576,13 +1508,18 @@ class Binding {
1576
1508
  mouseMoveThrottle,
1577
1509
  cursor,
1578
1510
  initialContent = "replace",
1579
- applyFileData = defaultApplyFileData
1511
+ applyFileData = defaultApplyFileData,
1512
+ disableBeforeUnload = true
1580
1513
  } = options;
1581
1514
  this.doc = doc;
1582
1515
  this.initialContentStrategy = initialContent;
1583
1516
  const ui = file.getUi();
1584
1517
  const graph = ui.editor.graph;
1585
1518
  this.mxGraphModel = graph.model;
1519
+ this.ui = ui;
1520
+ if (disableBeforeUnload) {
1521
+ ui.onBeforeUnload = () => null;
1522
+ }
1586
1523
  this.suppressLocalApply = true;
1587
1524
  try {
1588
1525
  this.docInitialized = reconcileInitialContent(
@@ -1599,15 +1536,13 @@ class Binding {
1599
1536
  }
1600
1537
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1601
1538
  this.mxListener = () => {
1602
- if (this.suppressLocalApply)
1603
- return;
1539
+ if (this.suppressLocalApply) return;
1604
1540
  const patch = file.ui.diffPages(
1605
1541
  file.shadowPages,
1606
1542
  file.ui.pages
1607
1543
  );
1608
1544
  const patchKeys = Object.keys(patch);
1609
- if (patchKeys.length === 0)
1610
- return;
1545
+ if (patchKeys.length === 0) return;
1611
1546
  if (!this.docInitialized) {
1612
1547
  doc.transact(() => {
1613
1548
  xml2doc(file.data, doc);
@@ -1617,6 +1552,7 @@ class Binding {
1617
1552
  }
1618
1553
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1619
1554
  applyFilePatch(doc, patch, { origin: LOCAL_ORIGIN });
1555
+ this.resetEditorStatus();
1620
1556
  };
1621
1557
  this.mxGraphModel.addListener("change", this.mxListener);
1622
1558
  this.docObserver = (events, transaction) => {
@@ -1635,10 +1571,7 @@ class Binding {
1635
1571
  applyFileData(file, xml);
1636
1572
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1637
1573
  initDocSnapshot(doc, false);
1638
- const ui2 = file.getUi();
1639
- const editor = ui2.editor;
1640
- editor.setStatus("");
1641
- editor.setModified(false);
1574
+ this.resetEditorStatus();
1642
1575
  } finally {
1643
1576
  this.suppressLocalApply = false;
1644
1577
  }
@@ -1651,12 +1584,12 @@ class Binding {
1651
1584
  this.docInitialized = true;
1652
1585
  }
1653
1586
  const patch = generatePatch(events);
1654
- if (Object.keys(patch).length === 0)
1655
- return;
1587
+ if (Object.keys(patch).length === 0) return;
1656
1588
  this.suppressLocalApply = true;
1657
1589
  try {
1658
1590
  file.patch([patch]);
1659
1591
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1592
+ this.resetEditorStatus();
1660
1593
  } finally {
1661
1594
  this.suppressLocalApply = false;
1662
1595
  }
@@ -1678,6 +1611,17 @@ class Binding {
1678
1611
  get shouldReplaceWhenDocHasData() {
1679
1612
  return this.initialContentStrategy === "replace" && !this.docInitialized;
1680
1613
  }
1614
+ /**
1615
+ * 重置 editor 和 file 的 modified 状态及状态栏。
1616
+ * Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
1617
+ */
1618
+ resetEditorStatus() {
1619
+ var _a;
1620
+ if (!this.ui) return;
1621
+ this.ui.editor.setModified(false);
1622
+ this.ui.editor.setStatus("");
1623
+ (_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
1624
+ }
1681
1625
  /**
1682
1626
  * 销毁绑定,解除所有监听器
1683
1627
  * @param deep - 是否深度清理(包括 awareness/undoManager),默认 false
@@ -1726,14 +1670,6 @@ class Binding {
1726
1670
  return new Binding(file, options);
1727
1671
  }
1728
1672
  }
1729
- Object.defineProperty(exports, "createIframeBridgeProvider", {
1730
- enumerable: true,
1731
- get: () => iframeBridge.createIframeBridgeProvider
1732
- });
1733
- Object.defineProperty(exports, "createIframeBridgeServer", {
1734
- enumerable: true,
1735
- get: () => iframeBridge.createIframeBridgeServer
1736
- });
1737
1673
  exports.Binding = Binding;
1738
1674
  exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
1739
1675
  exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;