@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/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[],
|
|
311
|
+
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
|
|
287
312
|
addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
|
|
288
313
|
/**
|
|
289
314
|
* block 格式:
|
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[],
|
|
311
|
+
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
|
|
287
312
|
addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
|
|
288
313
|
/**
|
|
289
314
|
* block 格式:
|
package/dist/index.js
CHANGED
|
@@ -1721,6 +1721,13 @@ var FlowDocument = class {
|
|
|
1721
1721
|
this.onNodeCreate = this.onNodeCreateEmitter.event;
|
|
1722
1722
|
this.onNodeDispose = this.onNodeDisposeEmitter.event;
|
|
1723
1723
|
this.onLayoutChange = this.onLayoutChangeEmitter.event;
|
|
1724
|
+
this._disposed = false;
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
*
|
|
1728
|
+
*/
|
|
1729
|
+
get disposed() {
|
|
1730
|
+
return this._disposed;
|
|
1724
1731
|
}
|
|
1725
1732
|
init() {
|
|
1726
1733
|
if (!this.options) this.options = FlowDocumentOptionsDefault;
|
|
@@ -1746,6 +1753,7 @@ var FlowDocument = class {
|
|
|
1746
1753
|
* @param fireRender 是否要触发渲染,默认 true
|
|
1747
1754
|
*/
|
|
1748
1755
|
fromJSON(json, fireRender = true) {
|
|
1756
|
+
if (this._disposed) return;
|
|
1749
1757
|
this.originTree.clear();
|
|
1750
1758
|
this.renderTree.clear();
|
|
1751
1759
|
this.entityManager.changeEntityLocked = true;
|
|
@@ -1814,7 +1822,7 @@ var FlowDocument = class {
|
|
|
1814
1822
|
* @param data
|
|
1815
1823
|
* @param addedNodes
|
|
1816
1824
|
*/
|
|
1817
|
-
addNode(data, addedNodes,
|
|
1825
|
+
addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
|
|
1818
1826
|
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1819
1827
|
let node = this.getNode(id);
|
|
1820
1828
|
let isNew = false;
|
|
@@ -1835,10 +1843,10 @@ var FlowDocument = class {
|
|
|
1835
1843
|
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
1836
1844
|
node.addInitializeData(datas);
|
|
1837
1845
|
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
1838
|
-
|
|
1839
|
-
this.options.fromNodeJSON(node, data);
|
|
1840
|
-
}
|
|
1846
|
+
this.options.fromNodeJSON?.(node, data, true);
|
|
1841
1847
|
isNew = true;
|
|
1848
|
+
} else {
|
|
1849
|
+
this.options.fromNodeJSON?.(node, data, false);
|
|
1842
1850
|
}
|
|
1843
1851
|
node.initData({
|
|
1844
1852
|
originParent,
|
|
@@ -1850,7 +1858,6 @@ var FlowDocument = class {
|
|
|
1850
1858
|
if (node.isStart) {
|
|
1851
1859
|
this.root.addChild(node);
|
|
1852
1860
|
}
|
|
1853
|
-
this.onNodeUpdateEmitter.fire({ node, data });
|
|
1854
1861
|
addedNodes?.push(node);
|
|
1855
1862
|
if (register.onCreate) {
|
|
1856
1863
|
const extendNodes = register.onCreate(node, data);
|
|
@@ -1864,11 +1871,16 @@ var FlowDocument = class {
|
|
|
1864
1871
|
this.addBlocksAsChildren(node, data.blocks, addedNodes);
|
|
1865
1872
|
}
|
|
1866
1873
|
}
|
|
1867
|
-
if (
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1874
|
+
if (!ignoreCreateAndUpdateEvent) {
|
|
1875
|
+
if (isNew) {
|
|
1876
|
+
this.onNodeCreateEmitter.fire({
|
|
1877
|
+
node,
|
|
1878
|
+
data,
|
|
1879
|
+
json: data
|
|
1880
|
+
});
|
|
1881
|
+
} else {
|
|
1882
|
+
this.onNodeUpdateEmitter.fire({ node, data, json: data });
|
|
1883
|
+
}
|
|
1872
1884
|
}
|
|
1873
1885
|
return node;
|
|
1874
1886
|
}
|
|
@@ -2183,6 +2195,7 @@ var FlowDocument = class {
|
|
|
2183
2195
|
);
|
|
2184
2196
|
}
|
|
2185
2197
|
dispose() {
|
|
2198
|
+
if (this._disposed) return;
|
|
2186
2199
|
this.registers.clear();
|
|
2187
2200
|
this.nodeRegistryCache.clear();
|
|
2188
2201
|
this.originTree.dispose();
|
|
@@ -2191,6 +2204,7 @@ var FlowDocument = class {
|
|
|
2191
2204
|
this.onNodeCreateEmitter.dispose();
|
|
2192
2205
|
this.onNodeDisposeEmitter.dispose();
|
|
2193
2206
|
this.onLayoutChangeEmitter.dispose();
|
|
2207
|
+
this._disposed = true;
|
|
2194
2208
|
}
|
|
2195
2209
|
};
|
|
2196
2210
|
__decorateClass([
|