@flowgram.ai/document 0.1.27 → 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 +25 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +25 -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 格式:
|
|
@@ -1141,6 +1166,7 @@ declare enum FlowNodeBaseType {
|
|
|
1141
1166
|
SUB_CANVAS = "subCanvas"
|
|
1142
1167
|
}
|
|
1143
1168
|
declare enum FlowNodeSplitType {
|
|
1169
|
+
SIMPLE_SPLIT = "simpleSplit",
|
|
1144
1170
|
DYNAMIC_SPLIT = "dynamicSplit",
|
|
1145
1171
|
STATIC_SPLIT = "staticSplit"
|
|
1146
1172
|
}
|
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 格式:
|
|
@@ -1141,6 +1166,7 @@ declare enum FlowNodeBaseType {
|
|
|
1141
1166
|
SUB_CANVAS = "subCanvas"
|
|
1142
1167
|
}
|
|
1143
1168
|
declare enum FlowNodeSplitType {
|
|
1169
|
+
SIMPLE_SPLIT = "simpleSplit",
|
|
1144
1170
|
DYNAMIC_SPLIT = "dynamicSplit",
|
|
1145
1171
|
STATIC_SPLIT = "staticSplit"
|
|
1146
1172
|
}
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ var FlowNodeBaseType = /* @__PURE__ */ ((FlowNodeBaseType2) => {
|
|
|
90
90
|
return FlowNodeBaseType2;
|
|
91
91
|
})(FlowNodeBaseType || {});
|
|
92
92
|
var FlowNodeSplitType = /* @__PURE__ */ ((FlowNodeSplitType2) => {
|
|
93
|
+
FlowNodeSplitType2["SIMPLE_SPLIT"] = "simpleSplit";
|
|
93
94
|
FlowNodeSplitType2["DYNAMIC_SPLIT"] = "dynamicSplit";
|
|
94
95
|
FlowNodeSplitType2["STATIC_SPLIT"] = "staticSplit";
|
|
95
96
|
return FlowNodeSplitType2;
|
|
@@ -1720,6 +1721,13 @@ var FlowDocument = class {
|
|
|
1720
1721
|
this.onNodeCreate = this.onNodeCreateEmitter.event;
|
|
1721
1722
|
this.onNodeDispose = this.onNodeDisposeEmitter.event;
|
|
1722
1723
|
this.onLayoutChange = this.onLayoutChangeEmitter.event;
|
|
1724
|
+
this._disposed = false;
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
*
|
|
1728
|
+
*/
|
|
1729
|
+
get disposed() {
|
|
1730
|
+
return this._disposed;
|
|
1723
1731
|
}
|
|
1724
1732
|
init() {
|
|
1725
1733
|
if (!this.options) this.options = FlowDocumentOptionsDefault;
|
|
@@ -1745,6 +1753,7 @@ var FlowDocument = class {
|
|
|
1745
1753
|
* @param fireRender 是否要触发渲染,默认 true
|
|
1746
1754
|
*/
|
|
1747
1755
|
fromJSON(json, fireRender = true) {
|
|
1756
|
+
if (this._disposed) return;
|
|
1748
1757
|
this.originTree.clear();
|
|
1749
1758
|
this.renderTree.clear();
|
|
1750
1759
|
this.entityManager.changeEntityLocked = true;
|
|
@@ -1813,7 +1822,7 @@ var FlowDocument = class {
|
|
|
1813
1822
|
* @param data
|
|
1814
1823
|
* @param addedNodes
|
|
1815
1824
|
*/
|
|
1816
|
-
addNode(data, addedNodes,
|
|
1825
|
+
addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
|
|
1817
1826
|
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1818
1827
|
let node = this.getNode(id);
|
|
1819
1828
|
let isNew = false;
|
|
@@ -1834,10 +1843,10 @@ var FlowDocument = class {
|
|
|
1834
1843
|
const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
|
|
1835
1844
|
node.addInitializeData(datas);
|
|
1836
1845
|
node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
|
|
1837
|
-
|
|
1838
|
-
this.options.fromNodeJSON(node, data);
|
|
1839
|
-
}
|
|
1846
|
+
this.options.fromNodeJSON?.(node, data, true);
|
|
1840
1847
|
isNew = true;
|
|
1848
|
+
} else {
|
|
1849
|
+
this.options.fromNodeJSON?.(node, data, false);
|
|
1841
1850
|
}
|
|
1842
1851
|
node.initData({
|
|
1843
1852
|
originParent,
|
|
@@ -1849,7 +1858,6 @@ var FlowDocument = class {
|
|
|
1849
1858
|
if (node.isStart) {
|
|
1850
1859
|
this.root.addChild(node);
|
|
1851
1860
|
}
|
|
1852
|
-
this.onNodeUpdateEmitter.fire({ node, data });
|
|
1853
1861
|
addedNodes?.push(node);
|
|
1854
1862
|
if (register.onCreate) {
|
|
1855
1863
|
const extendNodes = register.onCreate(node, data);
|
|
@@ -1863,11 +1871,16 @@ var FlowDocument = class {
|
|
|
1863
1871
|
this.addBlocksAsChildren(node, data.blocks, addedNodes);
|
|
1864
1872
|
}
|
|
1865
1873
|
}
|
|
1866
|
-
if (
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
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
|
+
}
|
|
1871
1884
|
}
|
|
1872
1885
|
return node;
|
|
1873
1886
|
}
|
|
@@ -2182,6 +2195,7 @@ var FlowDocument = class {
|
|
|
2182
2195
|
);
|
|
2183
2196
|
}
|
|
2184
2197
|
dispose() {
|
|
2198
|
+
if (this._disposed) return;
|
|
2185
2199
|
this.registers.clear();
|
|
2186
2200
|
this.nodeRegistryCache.clear();
|
|
2187
2201
|
this.originTree.dispose();
|
|
@@ -2190,6 +2204,7 @@ var FlowDocument = class {
|
|
|
2190
2204
|
this.onNodeCreateEmitter.dispose();
|
|
2191
2205
|
this.onNodeDisposeEmitter.dispose();
|
|
2192
2206
|
this.onLayoutChangeEmitter.dispose();
|
|
2207
|
+
this._disposed = true;
|
|
2193
2208
|
}
|
|
2194
2209
|
};
|
|
2195
2210
|
__decorateClass([
|