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.
@@ -57,6 +57,10 @@ export declare class Binding {
57
57
  private cleanupCollaborator?;
58
58
  /** UndoManager 绑定清理函数 */
59
59
  private cleanupUndoManager?;
60
+ /** 初始内容策略 */
61
+ private initialContentStrategy;
62
+ /** replace 策略下,构造时 doc 为空,现在 doc 有数据时需要强制替换 */
63
+ private get shouldReplaceWhenDocHasData();
60
64
  constructor(file: DrawioFile, options: BindDrawioFileOptions);
61
65
  /**
62
66
  * 销毁绑定,解除所有监听器
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/binding/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAiBvD,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,cAAc,GACd,cAAc,CAAC;AAEnB,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EACH,OAAO,GACP;QACE,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACN;;OAEG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD;AA0KD;;;;;;;GAOG;AACH,qBA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yjs binding for draw.io (mxGraph) documents",
5
5
  "keywords": [
6
6
  "yjs",
package/y-mxgraph.cjs.js CHANGED
@@ -1578,6 +1578,7 @@ class Binding {
1578
1578
  applyFileData = defaultApplyFileData
1579
1579
  } = options;
1580
1580
  this.doc = doc;
1581
+ this.initialContentStrategy = initialContent;
1581
1582
  const ui = file.getUi();
1582
1583
  const graph = ui.editor.graph;
1583
1584
  this.mxGraphModel = graph.model;
@@ -1618,13 +1619,36 @@ class Binding {
1618
1619
  };
1619
1620
  this.mxGraphModel.addListener("change", this.mxListener);
1620
1621
  this.docObserver = (events, transaction) => {
1621
- if (!this.docInitialized) {
1622
- this.docInitialized = true;
1623
- }
1624
1622
  if (transaction.local && transaction.origin === LOCAL_ORIGIN) {
1625
1623
  generatePatch(events);
1626
1624
  return;
1627
1625
  }
1626
+ if (this.shouldReplaceWhenDocHasData) {
1627
+ const mxfileMap = doc.getMap(key);
1628
+ const diagramMap = mxfileMap.get(key$1);
1629
+ if (diagramMap && diagramMap.size > 0) {
1630
+ const xml = doc2xml(doc);
1631
+ if (xml && xml.includes("<diagram")) {
1632
+ this.suppressLocalApply = true;
1633
+ try {
1634
+ applyFileData(file, xml);
1635
+ file.setShadowPages(file.ui.clonePages(file.ui.pages));
1636
+ initDocSnapshot(doc, false);
1637
+ const ui2 = file.getUi();
1638
+ const editor = ui2.editor;
1639
+ editor.setStatus("");
1640
+ editor.setModified(false);
1641
+ } finally {
1642
+ this.suppressLocalApply = false;
1643
+ }
1644
+ this.docInitialized = true;
1645
+ return;
1646
+ }
1647
+ }
1648
+ }
1649
+ if (!this.docInitialized) {
1650
+ this.docInitialized = true;
1651
+ }
1628
1652
  const patch = generatePatch(events);
1629
1653
  if (Object.keys(patch).length === 0)
1630
1654
  return;
@@ -1649,6 +1673,10 @@ class Binding {
1649
1673
  this.cleanupUndoManager = bindUndoManager(doc, file, undoManager);
1650
1674
  }
1651
1675
  }
1676
+ /** replace 策略下,构造时 doc 为空,现在 doc 有数据时需要强制替换 */
1677
+ get shouldReplaceWhenDocHasData() {
1678
+ return this.initialContentStrategy === "replace" && !this.docInitialized;
1679
+ }
1652
1680
  /**
1653
1681
  * 销毁绑定,解除所有监听器
1654
1682
  * @param deep - 是否深度清理(包括 awareness/undoManager),默认 false