y-mxgraph 0.2.2 → 0.3.1

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/y-mxgraph.es.js CHANGED
@@ -2,6 +2,7 @@ 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";
5
6
  function deepProcess(node) {
6
7
  if (node == null)
7
8
  return;
@@ -1549,6 +1550,7 @@ class Binding {
1549
1550
  constructor(file, options) {
1550
1551
  this.suppressLocalApply = false;
1551
1552
  this.docInitialized = false;
1553
+ this.ui = null;
1552
1554
  const {
1553
1555
  doc,
1554
1556
  awareness,
@@ -1556,13 +1558,18 @@ class Binding {
1556
1558
  mouseMoveThrottle,
1557
1559
  cursor,
1558
1560
  initialContent = "replace",
1559
- applyFileData = defaultApplyFileData
1561
+ applyFileData = defaultApplyFileData,
1562
+ disableBeforeUnload = true
1560
1563
  } = options;
1561
1564
  this.doc = doc;
1562
1565
  this.initialContentStrategy = initialContent;
1563
1566
  const ui = file.getUi();
1564
1567
  const graph = ui.editor.graph;
1565
1568
  this.mxGraphModel = graph.model;
1569
+ this.ui = ui;
1570
+ if (disableBeforeUnload) {
1571
+ ui.onBeforeUnload = () => null;
1572
+ }
1566
1573
  this.suppressLocalApply = true;
1567
1574
  try {
1568
1575
  this.docInitialized = reconcileInitialContent(
@@ -1597,6 +1604,7 @@ class Binding {
1597
1604
  }
1598
1605
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1599
1606
  applyFilePatch(doc, patch, { origin: LOCAL_ORIGIN });
1607
+ this.resetEditorStatus();
1600
1608
  };
1601
1609
  this.mxGraphModel.addListener("change", this.mxListener);
1602
1610
  this.docObserver = (events, transaction) => {
@@ -1615,10 +1623,7 @@ class Binding {
1615
1623
  applyFileData(file, xml);
1616
1624
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1617
1625
  initDocSnapshot(doc, false);
1618
- const ui2 = file.getUi();
1619
- const editor = ui2.editor;
1620
- editor.setStatus("");
1621
- editor.setModified(false);
1626
+ this.resetEditorStatus();
1622
1627
  } finally {
1623
1628
  this.suppressLocalApply = false;
1624
1629
  }
@@ -1637,6 +1642,7 @@ class Binding {
1637
1642
  try {
1638
1643
  file.patch([patch]);
1639
1644
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1645
+ this.resetEditorStatus();
1640
1646
  } finally {
1641
1647
  this.suppressLocalApply = false;
1642
1648
  }
@@ -1658,6 +1664,18 @@ class Binding {
1658
1664
  get shouldReplaceWhenDocHasData() {
1659
1665
  return this.initialContentStrategy === "replace" && !this.docInitialized;
1660
1666
  }
1667
+ /**
1668
+ * 重置 editor 和 file 的 modified 状态及状态栏。
1669
+ * Yjs 接管持久化后,draw.io 的原生保存状态不再有意义。
1670
+ */
1671
+ resetEditorStatus() {
1672
+ var _a;
1673
+ if (!this.ui)
1674
+ return;
1675
+ this.ui.editor.setModified(false);
1676
+ this.ui.editor.setStatus("");
1677
+ (_a = this.ui.currentFile) == null ? void 0 : _a.setModified(false);
1678
+ }
1661
1679
  /**
1662
1680
  * 销毁绑定,解除所有监听器
1663
1681
  * @param deep - 是否深度清理(包括 awareness/undoManager),默认 false
@@ -1711,6 +1729,8 @@ export {
1711
1729
  DEFAULT_USER_COLOR_KEY,
1712
1730
  DEFAULT_USER_NAME_KEY,
1713
1731
  LOCAL_ORIGIN,
1732
+ createIframeBridgeProvider,
1733
+ createIframeBridgeServer,
1714
1734
  doc2xml,
1715
1735
  xml2doc
1716
1736
  };