y-mxgraph 0.3.0 → 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
@@ -1550,6 +1550,7 @@ class Binding {
1550
1550
  constructor(file, options) {
1551
1551
  this.suppressLocalApply = false;
1552
1552
  this.docInitialized = false;
1553
+ this.ui = null;
1553
1554
  const {
1554
1555
  doc,
1555
1556
  awareness,
@@ -1557,13 +1558,18 @@ class Binding {
1557
1558
  mouseMoveThrottle,
1558
1559
  cursor,
1559
1560
  initialContent = "replace",
1560
- applyFileData = defaultApplyFileData
1561
+ applyFileData = defaultApplyFileData,
1562
+ disableBeforeUnload = true
1561
1563
  } = options;
1562
1564
  this.doc = doc;
1563
1565
  this.initialContentStrategy = initialContent;
1564
1566
  const ui = file.getUi();
1565
1567
  const graph = ui.editor.graph;
1566
1568
  this.mxGraphModel = graph.model;
1569
+ this.ui = ui;
1570
+ if (disableBeforeUnload) {
1571
+ ui.onBeforeUnload = () => null;
1572
+ }
1567
1573
  this.suppressLocalApply = true;
1568
1574
  try {
1569
1575
  this.docInitialized = reconcileInitialContent(
@@ -1598,6 +1604,7 @@ class Binding {
1598
1604
  }
1599
1605
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1600
1606
  applyFilePatch(doc, patch, { origin: LOCAL_ORIGIN });
1607
+ this.resetEditorStatus();
1601
1608
  };
1602
1609
  this.mxGraphModel.addListener("change", this.mxListener);
1603
1610
  this.docObserver = (events, transaction) => {
@@ -1616,10 +1623,7 @@ class Binding {
1616
1623
  applyFileData(file, xml);
1617
1624
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1618
1625
  initDocSnapshot(doc, false);
1619
- const ui2 = file.getUi();
1620
- const editor = ui2.editor;
1621
- editor.setStatus("");
1622
- editor.setModified(false);
1626
+ this.resetEditorStatus();
1623
1627
  } finally {
1624
1628
  this.suppressLocalApply = false;
1625
1629
  }
@@ -1638,6 +1642,7 @@ class Binding {
1638
1642
  try {
1639
1643
  file.patch([patch]);
1640
1644
  file.setShadowPages(file.ui.clonePages(file.ui.pages));
1645
+ this.resetEditorStatus();
1641
1646
  } finally {
1642
1647
  this.suppressLocalApply = false;
1643
1648
  }
@@ -1659,6 +1664,18 @@ class Binding {
1659
1664
  get shouldReplaceWhenDocHasData() {
1660
1665
  return this.initialContentStrategy === "replace" && !this.docInitialized;
1661
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
+ }
1662
1679
  /**
1663
1680
  * 销毁绑定,解除所有监听器
1664
1681
  * @param deep - 是否深度清理(包括 awareness/undoManager),默认 false