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