@flowgram.ai/document 0.1.28 → 0.1.29
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/dist/esm/index.js +24 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +24 -10
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/esm/index.js
CHANGED
|
@@ -1662,6 +1662,13 @@ var FlowDocument = class {
|
|
|
1662
1662
|
this.onNodeCreate = this.onNodeCreateEmitter.event;
|
|
1663
1663
|
this.onNodeDispose = this.onNodeDisposeEmitter.event;
|
|
1664
1664
|
this.onLayoutChange = this.onLayoutChangeEmitter.event;
|
|
1665
|
+
this._disposed = false;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
*
|
|
1669
|
+
*/
|
|
1670
|
+
get disposed() {
|
|
1671
|
+
return this._disposed;
|
|
1665
1672
|
}
|
|
1666
1673
|
init() {
|
|
1667
1674
|
if (!this.options) this.options = FlowDocumentOptionsDefault;
|
|
@@ -1687,6 +1694,7 @@ var FlowDocument = class {
|
|
|
1687
1694
|
* @param fireRender 是否要触发渲染,默认 true
|
|
1688
1695
|
*/
|
|
1689
1696
|
fromJSON(json, fireRender = true) {
|
|
1697
|
+
if (this._disposed) return;
|
|
1690
1698
|
this.originTree.clear();
|
|
1691
1699
|
this.renderTree.clear();
|
|
1692
1700
|
this.entityManager.changeEntityLocked = true;
|
|
@@ -1755,7 +1763,7 @@ var FlowDocument = class {
|
|
|
1755
1763
|
* @param data
|
|
1756
1764
|
* @param addedNodes
|
|
1757
1765
|
*/
|
|
1758
|
-
addNode(data, addedNodes,
|
|
1766
|
+
addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
|
|
1759
1767
|
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1760
1768
|
let node = this.getNode(id);
|
|
1761
1769
|
let isNew = false;
|
|
@@ -1776,10 +1784,10 @@ var FlowDocument = class {
|
|
|
1776
1784
|
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
1777
1785
|
node.addInitializeData(datas);
|
|
1778
1786
|
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
1779
|
-
|
|
1780
|
-
this.options.fromNodeJSON(node, data);
|
|
1781
|
-
}
|
|
1787
|
+
this.options.fromNodeJSON?.(node, data, true);
|
|
1782
1788
|
isNew = true;
|
|
1789
|
+
} else {
|
|
1790
|
+
this.options.fromNodeJSON?.(node, data, false);
|
|
1783
1791
|
}
|
|
1784
1792
|
node.initData({
|
|
1785
1793
|
originParent,
|
|
@@ -1791,7 +1799,6 @@ var FlowDocument = class {
|
|
|
1791
1799
|
if (node.isStart) {
|
|
1792
1800
|
this.root.addChild(node);
|
|
1793
1801
|
}
|
|
1794
|
-
this.onNodeUpdateEmitter.fire({ node, data });
|
|
1795
1802
|
addedNodes?.push(node);
|
|
1796
1803
|
if (register.onCreate) {
|
|
1797
1804
|
const extendNodes = register.onCreate(node, data);
|
|
@@ -1805,11 +1812,16 @@ var FlowDocument = class {
|
|
|
1805
1812
|
this.addBlocksAsChildren(node, data.blocks, addedNodes);
|
|
1806
1813
|
}
|
|
1807
1814
|
}
|
|
1808
|
-
if (
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1815
|
+
if (!ignoreCreateAndUpdateEvent) {
|
|
1816
|
+
if (isNew) {
|
|
1817
|
+
this.onNodeCreateEmitter.fire({
|
|
1818
|
+
node,
|
|
1819
|
+
data,
|
|
1820
|
+
json: data
|
|
1821
|
+
});
|
|
1822
|
+
} else {
|
|
1823
|
+
this.onNodeUpdateEmitter.fire({ node, data, json: data });
|
|
1824
|
+
}
|
|
1813
1825
|
}
|
|
1814
1826
|
return node;
|
|
1815
1827
|
}
|
|
@@ -2124,6 +2136,7 @@ var FlowDocument = class {
|
|
|
2124
2136
|
);
|
|
2125
2137
|
}
|
|
2126
2138
|
dispose() {
|
|
2139
|
+
if (this._disposed) return;
|
|
2127
2140
|
this.registers.clear();
|
|
2128
2141
|
this.nodeRegistryCache.clear();
|
|
2129
2142
|
this.originTree.dispose();
|
|
@@ -2132,6 +2145,7 @@ var FlowDocument = class {
|
|
|
2132
2145
|
this.onNodeCreateEmitter.dispose();
|
|
2133
2146
|
this.onNodeDisposeEmitter.dispose();
|
|
2134
2147
|
this.onLayoutChangeEmitter.dispose();
|
|
2148
|
+
this._disposed = true;
|
|
2135
2149
|
}
|
|
2136
2150
|
};
|
|
2137
2151
|
__decorateClass([
|