@flowgram.ai/document 0.1.28 → 0.1.30

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/index.d.mts CHANGED
@@ -119,7 +119,7 @@ interface FlowDocumentOptions {
119
119
  */
120
120
  allNodesDefaultExpanded?: boolean;
121
121
  toNodeJSON?(node: FlowNodeEntity): FlowNodeJSON;
122
- fromNodeJSON?(node: FlowNodeEntity, json: FlowNodeJSON): void;
122
+ fromNodeJSON?(node: FlowNodeEntity, json: FlowNodeJSON, isFirstCreate: boolean): void;
123
123
  constants?: Record<string, any>;
124
124
  formatNodeLines?: (node: FlowNodeEntity, lines: FlowTransitionLine[]) => FlowTransitionLine[];
125
125
  formatNodeLabels?: (node: FlowNodeEntity, lines: FlowTransitionLabel[]) => FlowTransitionLabel[];
@@ -217,11 +217,21 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
217
217
  protected currentLayoutKey: string;
218
218
  protected onNodeUpdateEmitter: Emitter<{
219
219
  node: FlowNodeEntity;
220
+ /**
221
+ * use 'json' instead
222
+ * @deprecated
223
+ */
220
224
  data: FlowNodeJSON;
225
+ json: FlowNodeJSON;
221
226
  }>;
222
227
  protected onNodeCreateEmitter: Emitter<{
223
228
  node: FlowNodeEntity;
229
+ /**
230
+ * use 'json' instead
231
+ * @deprecated
232
+ */
224
233
  data: FlowNodeJSON;
234
+ json: FlowNodeJSON;
225
235
  }>;
226
236
  protected onNodeDisposeEmitter: Emitter<{
227
237
  node: FlowNodeEntity;
@@ -229,16 +239,27 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
229
239
  protected onLayoutChangeEmitter: Emitter<FlowLayout>;
230
240
  readonly onNodeUpdate: _flowgram_ai_utils.Event<{
231
241
  node: FlowNodeEntity;
242
+ /**
243
+ * use 'json' instead
244
+ * @deprecated
245
+ */
232
246
  data: FlowNodeJSON;
247
+ json: FlowNodeJSON;
233
248
  }>;
234
249
  readonly onNodeCreate: _flowgram_ai_utils.Event<{
235
250
  node: FlowNodeEntity;
251
+ /**
252
+ * use 'json' instead
253
+ * @deprecated
254
+ */
236
255
  data: FlowNodeJSON;
256
+ json: FlowNodeJSON;
237
257
  }>;
238
258
  readonly onNodeDispose: _flowgram_ai_utils.Event<{
239
259
  node: FlowNodeEntity;
240
260
  }>;
241
261
  readonly onLayoutChange: _flowgram_ai_utils.Event<FlowLayout>;
262
+ private _disposed;
242
263
  root: FlowNodeEntity;
243
264
  /**
244
265
  * 原始的 tree 结构
@@ -253,6 +274,10 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
253
274
  * 渲染后的 tree 结构
254
275
  */
255
276
  renderTree: FlowRenderTree<FlowNodeEntity>;
277
+ /**
278
+ *
279
+ */
280
+ get disposed(): boolean;
256
281
  init(): void;
257
282
  /**
258
283
  * 从数据初始化 O(n)
@@ -283,7 +308,7 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
283
308
  * @param data
284
309
  * @param addedNodes
285
310
  */
286
- addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateEvent?: boolean): FlowNodeEntity;
311
+ addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
287
312
  addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
288
313
  /**
289
314
  * block 格式:
@@ -1137,8 +1162,13 @@ declare enum FlowNodeBaseType {
1137
1162
  BLOCK_ORDER_ICON = "blockOrderIcon",
1138
1163
  GROUP = "group",
1139
1164
  END = "end",
1165
+ BREAK = "break",
1140
1166
  CONDITION = "condition",
1141
- SUB_CANVAS = "subCanvas"
1167
+ SUB_CANVAS = "subCanvas",
1168
+ MULTI_INPUTS = "multiInputs",
1169
+ MULTI_OUTPUTS = "multiOutputs",
1170
+ INPUT = "input",
1171
+ OUTPUT = "output"
1142
1172
  }
1143
1173
  declare enum FlowNodeSplitType {
1144
1174
  SIMPLE_SPLIT = "simpleSplit",
package/dist/index.d.ts CHANGED
@@ -119,7 +119,7 @@ interface FlowDocumentOptions {
119
119
  */
120
120
  allNodesDefaultExpanded?: boolean;
121
121
  toNodeJSON?(node: FlowNodeEntity): FlowNodeJSON;
122
- fromNodeJSON?(node: FlowNodeEntity, json: FlowNodeJSON): void;
122
+ fromNodeJSON?(node: FlowNodeEntity, json: FlowNodeJSON, isFirstCreate: boolean): void;
123
123
  constants?: Record<string, any>;
124
124
  formatNodeLines?: (node: FlowNodeEntity, lines: FlowTransitionLine[]) => FlowTransitionLine[];
125
125
  formatNodeLabels?: (node: FlowNodeEntity, lines: FlowTransitionLabel[]) => FlowTransitionLabel[];
@@ -217,11 +217,21 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
217
217
  protected currentLayoutKey: string;
218
218
  protected onNodeUpdateEmitter: Emitter<{
219
219
  node: FlowNodeEntity;
220
+ /**
221
+ * use 'json' instead
222
+ * @deprecated
223
+ */
220
224
  data: FlowNodeJSON;
225
+ json: FlowNodeJSON;
221
226
  }>;
222
227
  protected onNodeCreateEmitter: Emitter<{
223
228
  node: FlowNodeEntity;
229
+ /**
230
+ * use 'json' instead
231
+ * @deprecated
232
+ */
224
233
  data: FlowNodeJSON;
234
+ json: FlowNodeJSON;
225
235
  }>;
226
236
  protected onNodeDisposeEmitter: Emitter<{
227
237
  node: FlowNodeEntity;
@@ -229,16 +239,27 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
229
239
  protected onLayoutChangeEmitter: Emitter<FlowLayout>;
230
240
  readonly onNodeUpdate: _flowgram_ai_utils.Event<{
231
241
  node: FlowNodeEntity;
242
+ /**
243
+ * use 'json' instead
244
+ * @deprecated
245
+ */
232
246
  data: FlowNodeJSON;
247
+ json: FlowNodeJSON;
233
248
  }>;
234
249
  readonly onNodeCreate: _flowgram_ai_utils.Event<{
235
250
  node: FlowNodeEntity;
251
+ /**
252
+ * use 'json' instead
253
+ * @deprecated
254
+ */
236
255
  data: FlowNodeJSON;
256
+ json: FlowNodeJSON;
237
257
  }>;
238
258
  readonly onNodeDispose: _flowgram_ai_utils.Event<{
239
259
  node: FlowNodeEntity;
240
260
  }>;
241
261
  readonly onLayoutChange: _flowgram_ai_utils.Event<FlowLayout>;
262
+ private _disposed;
242
263
  root: FlowNodeEntity;
243
264
  /**
244
265
  * 原始的 tree 结构
@@ -253,6 +274,10 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
253
274
  * 渲染后的 tree 结构
254
275
  */
255
276
  renderTree: FlowRenderTree<FlowNodeEntity>;
277
+ /**
278
+ *
279
+ */
280
+ get disposed(): boolean;
256
281
  init(): void;
257
282
  /**
258
283
  * 从数据初始化 O(n)
@@ -283,7 +308,7 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
283
308
  * @param data
284
309
  * @param addedNodes
285
310
  */
286
- addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateEvent?: boolean): FlowNodeEntity;
311
+ addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
287
312
  addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
288
313
  /**
289
314
  * block 格式:
@@ -1137,8 +1162,13 @@ declare enum FlowNodeBaseType {
1137
1162
  BLOCK_ORDER_ICON = "blockOrderIcon",
1138
1163
  GROUP = "group",
1139
1164
  END = "end",
1165
+ BREAK = "break",
1140
1166
  CONDITION = "condition",
1141
- SUB_CANVAS = "subCanvas"
1167
+ SUB_CANVAS = "subCanvas",
1168
+ MULTI_INPUTS = "multiInputs",
1169
+ MULTI_OUTPUTS = "multiOutputs",
1170
+ INPUT = "input",
1171
+ OUTPUT = "output"
1142
1172
  }
1143
1173
  declare enum FlowNodeSplitType {
1144
1174
  SIMPLE_SPLIT = "simpleSplit",
package/dist/index.js CHANGED
@@ -85,8 +85,13 @@ var FlowNodeBaseType = /* @__PURE__ */ ((FlowNodeBaseType2) => {
85
85
  FlowNodeBaseType2["BLOCK_ORDER_ICON"] = "blockOrderIcon";
86
86
  FlowNodeBaseType2["GROUP"] = "group";
87
87
  FlowNodeBaseType2["END"] = "end";
88
+ FlowNodeBaseType2["BREAK"] = "break";
88
89
  FlowNodeBaseType2["CONDITION"] = "condition";
89
90
  FlowNodeBaseType2["SUB_CANVAS"] = "subCanvas";
91
+ FlowNodeBaseType2["MULTI_INPUTS"] = "multiInputs";
92
+ FlowNodeBaseType2["MULTI_OUTPUTS"] = "multiOutputs";
93
+ FlowNodeBaseType2["INPUT"] = "input";
94
+ FlowNodeBaseType2["OUTPUT"] = "output";
90
95
  return FlowNodeBaseType2;
91
96
  })(FlowNodeBaseType || {});
92
97
  var FlowNodeSplitType = /* @__PURE__ */ ((FlowNodeSplitType2) => {
@@ -1721,6 +1726,13 @@ var FlowDocument = class {
1721
1726
  this.onNodeCreate = this.onNodeCreateEmitter.event;
1722
1727
  this.onNodeDispose = this.onNodeDisposeEmitter.event;
1723
1728
  this.onLayoutChange = this.onLayoutChangeEmitter.event;
1729
+ this._disposed = false;
1730
+ }
1731
+ /**
1732
+ *
1733
+ */
1734
+ get disposed() {
1735
+ return this._disposed;
1724
1736
  }
1725
1737
  init() {
1726
1738
  if (!this.options) this.options = FlowDocumentOptionsDefault;
@@ -1746,6 +1758,7 @@ var FlowDocument = class {
1746
1758
  * @param fireRender 是否要触发渲染,默认 true
1747
1759
  */
1748
1760
  fromJSON(json, fireRender = true) {
1761
+ if (this._disposed) return;
1749
1762
  this.originTree.clear();
1750
1763
  this.renderTree.clear();
1751
1764
  this.entityManager.changeEntityLocked = true;
@@ -1814,7 +1827,7 @@ var FlowDocument = class {
1814
1827
  * @param data
1815
1828
  * @param addedNodes
1816
1829
  */
1817
- addNode(data, addedNodes, ignoreCreateEvent) {
1830
+ addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
1818
1831
  const { id, type = "block", originParent, parent, meta, hidden, index } = data;
1819
1832
  let node = this.getNode(id);
1820
1833
  let isNew = false;
@@ -1835,10 +1848,10 @@ var FlowDocument = class {
1835
1848
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
1836
1849
  node.addInitializeData(datas);
1837
1850
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
1838
- if (this.options.fromNodeJSON) {
1839
- this.options.fromNodeJSON(node, data);
1840
- }
1851
+ this.options.fromNodeJSON?.(node, data, true);
1841
1852
  isNew = true;
1853
+ } else {
1854
+ this.options.fromNodeJSON?.(node, data, false);
1842
1855
  }
1843
1856
  node.initData({
1844
1857
  originParent,
@@ -1850,7 +1863,6 @@ var FlowDocument = class {
1850
1863
  if (node.isStart) {
1851
1864
  this.root.addChild(node);
1852
1865
  }
1853
- this.onNodeUpdateEmitter.fire({ node, data });
1854
1866
  addedNodes?.push(node);
1855
1867
  if (register.onCreate) {
1856
1868
  const extendNodes = register.onCreate(node, data);
@@ -1864,11 +1876,16 @@ var FlowDocument = class {
1864
1876
  this.addBlocksAsChildren(node, data.blocks, addedNodes);
1865
1877
  }
1866
1878
  }
1867
- if (isNew && !ignoreCreateEvent) {
1868
- this.onNodeCreateEmitter.fire({
1869
- node,
1870
- data
1871
- });
1879
+ if (!ignoreCreateAndUpdateEvent) {
1880
+ if (isNew) {
1881
+ this.onNodeCreateEmitter.fire({
1882
+ node,
1883
+ data,
1884
+ json: data
1885
+ });
1886
+ } else {
1887
+ this.onNodeUpdateEmitter.fire({ node, data, json: data });
1888
+ }
1872
1889
  }
1873
1890
  return node;
1874
1891
  }
@@ -2007,6 +2024,7 @@ var FlowDocument = class {
2007
2024
  const customDefaultRegistry = this.options.getNodeDefaultRegistry?.(type);
2008
2025
  let register = this.registers.get(type) || { type };
2009
2026
  const extendRegisters = [];
2027
+ const extendKey = register.extend;
2010
2028
  if (register.extend && this.registers.has(register.extend)) {
2011
2029
  register = FlowNodeRegistry.merge(
2012
2030
  this.getNodeRegistry(register.extend),
@@ -2037,6 +2055,9 @@ var FlowDocument = class {
2037
2055
  ...register.meta
2038
2056
  }
2039
2057
  };
2058
+ if (extendKey) {
2059
+ res.extend = extendKey;
2060
+ }
2040
2061
  this.nodeRegistryCache.set(typeKey, res);
2041
2062
  return res;
2042
2063
  }
@@ -2183,6 +2204,7 @@ var FlowDocument = class {
2183
2204
  );
2184
2205
  }
2185
2206
  dispose() {
2207
+ if (this._disposed) return;
2186
2208
  this.registers.clear();
2187
2209
  this.nodeRegistryCache.clear();
2188
2210
  this.originTree.dispose();
@@ -2191,6 +2213,7 @@ var FlowDocument = class {
2191
2213
  this.onNodeCreateEmitter.dispose();
2192
2214
  this.onNodeDisposeEmitter.dispose();
2193
2215
  this.onLayoutChangeEmitter.dispose();
2216
+ this._disposed = true;
2194
2217
  }
2195
2218
  };
2196
2219
  __decorateClass([