y-mxgraph 0.2.0 → 0.2.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.umd.js CHANGED
@@ -1576,6 +1576,7 @@
1576
1576
  applyFileData = defaultApplyFileData
1577
1577
  } = options;
1578
1578
  this.doc = doc;
1579
+ this.initialContentStrategy = initialContent;
1579
1580
  const ui = file.getUi();
1580
1581
  const graph = ui.editor.graph;
1581
1582
  this.mxGraphModel = graph.model;
@@ -1616,13 +1617,36 @@
1616
1617
  };
1617
1618
  this.mxGraphModel.addListener("change", this.mxListener);
1618
1619
  this.docObserver = (events, transaction) => {
1619
- if (!this.docInitialized) {
1620
- this.docInitialized = true;
1621
- }
1622
1620
  if (transaction.local && transaction.origin === LOCAL_ORIGIN) {
1623
1621
  generatePatch(events);
1624
1622
  return;
1625
1623
  }
1624
+ if (this.shouldReplaceWhenDocHasData) {
1625
+ const mxfileMap = doc.getMap(key);
1626
+ const diagramMap = mxfileMap.get(key$1);
1627
+ if (diagramMap && diagramMap.size > 0) {
1628
+ const xml = doc2xml(doc);
1629
+ if (xml && xml.includes("<diagram")) {
1630
+ this.suppressLocalApply = true;
1631
+ try {
1632
+ applyFileData(file, xml);
1633
+ file.setShadowPages(file.ui.clonePages(file.ui.pages));
1634
+ initDocSnapshot(doc, false);
1635
+ const ui2 = file.getUi();
1636
+ const editor = ui2.editor;
1637
+ editor.setStatus("");
1638
+ editor.setModified(false);
1639
+ } finally {
1640
+ this.suppressLocalApply = false;
1641
+ }
1642
+ this.docInitialized = true;
1643
+ return;
1644
+ }
1645
+ }
1646
+ }
1647
+ if (!this.docInitialized) {
1648
+ this.docInitialized = true;
1649
+ }
1626
1650
  const patch = generatePatch(events);
1627
1651
  if (Object.keys(patch).length === 0)
1628
1652
  return;
@@ -1647,6 +1671,10 @@
1647
1671
  this.cleanupUndoManager = bindUndoManager(doc, file, undoManager);
1648
1672
  }
1649
1673
  }
1674
+ /** replace 策略下,构造时 doc 为空,现在 doc 有数据时需要强制替换 */
1675
+ get shouldReplaceWhenDocHasData() {
1676
+ return this.initialContentStrategy === "replace" && !this.docInitialized;
1677
+ }
1650
1678
  /**
1651
1679
  * 销毁绑定,解除所有监听器
1652
1680
  * @param deep - 是否深度清理(包括 awareness/undoManager),默认 false