@flowgram.ai/variable-layout 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +387 -110
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +313 -37
- package/dist/index.d.ts +313 -37
- package/dist/index.js +395 -116
- package/dist/index.js.map +1 -1
- package/package.json +10 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,73 @@
|
|
|
1
|
-
import { Scope, VariableEngine, ASTNodeJSON, ASTNode, ScopeChain } from '@flowgram.ai/variable-core';
|
|
1
|
+
import { Scope, VariableEngine, ASTNodeJSON, ASTNode, BaseVariableField, ScopeChain } from '@flowgram.ai/variable-core';
|
|
2
2
|
import { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';
|
|
3
3
|
import { EntityData, EntityManager } from '@flowgram.ai/core';
|
|
4
|
+
import { interfaces } from 'inversify';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Enum for flow node scope types.
|
|
13
|
+
*/
|
|
5
14
|
declare enum FlowNodeScopeTypeEnum {
|
|
15
|
+
/**
|
|
16
|
+
* Public scope.
|
|
17
|
+
*/
|
|
6
18
|
public = "public",
|
|
19
|
+
/**
|
|
20
|
+
* Private scope.
|
|
21
|
+
*/
|
|
7
22
|
private = "private"
|
|
8
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Metadata for a flow node scope.
|
|
26
|
+
*/
|
|
9
27
|
interface FlowNodeScopeMeta {
|
|
28
|
+
/**
|
|
29
|
+
* The flow node entity associated with the scope.
|
|
30
|
+
*/
|
|
10
31
|
node?: FlowNodeEntity;
|
|
32
|
+
/**
|
|
33
|
+
* The type of the scope.
|
|
34
|
+
*/
|
|
11
35
|
type?: FlowNodeScopeTypeEnum;
|
|
12
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Represents a virtual node in the scope chain.
|
|
39
|
+
*/
|
|
13
40
|
interface ScopeVirtualNode {
|
|
41
|
+
/**
|
|
42
|
+
* The ID of the virtual node.
|
|
43
|
+
*/
|
|
14
44
|
id: string;
|
|
45
|
+
/**
|
|
46
|
+
* The type of the flow node.
|
|
47
|
+
*/
|
|
15
48
|
flowNodeType: 'virtualNode';
|
|
16
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents a node in the scope chain, which can be either a flow node entity or a virtual node.
|
|
52
|
+
*/
|
|
17
53
|
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
18
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Represents a scope associated with a flow node.
|
|
56
|
+
*/
|
|
57
|
+
interface FlowNodeScope extends Scope<FlowNodeScopeMeta> {
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
62
|
+
* SPDX-License-Identifier: MIT
|
|
63
|
+
*/
|
|
19
64
|
|
|
20
65
|
interface Options {
|
|
21
66
|
variableEngine: VariableEngine;
|
|
22
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Manages variable data for a flow node, including public and private scopes.
|
|
70
|
+
*/
|
|
23
71
|
declare class FlowNodeVariableData extends EntityData {
|
|
24
72
|
readonly opts: Options;
|
|
25
73
|
static type: string;
|
|
@@ -30,7 +78,13 @@ declare class FlowNodeVariableData extends EntityData {
|
|
|
30
78
|
*/
|
|
31
79
|
protected _private?: FlowNodeScope;
|
|
32
80
|
protected _public: FlowNodeScope;
|
|
81
|
+
/**
|
|
82
|
+
* The private scope of the node.
|
|
83
|
+
*/
|
|
33
84
|
get private(): FlowNodeScope | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The public scope of the node.
|
|
87
|
+
*/
|
|
34
88
|
get public(): FlowNodeScope;
|
|
35
89
|
/**
|
|
36
90
|
* Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.
|
|
@@ -53,7 +107,7 @@ declare class FlowNodeVariableData extends EntityData {
|
|
|
53
107
|
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
54
108
|
* @returns The value of the variable, or undefined if not found.
|
|
55
109
|
*/
|
|
56
|
-
getVar(key?: string): ASTNode<any
|
|
110
|
+
getVar(key?: string): ASTNode<any> | undefined;
|
|
57
111
|
/**
|
|
58
112
|
* Clears a variable from the public AST (Abstract Syntax Tree) by key.
|
|
59
113
|
*
|
|
@@ -82,7 +136,7 @@ declare class FlowNodeVariableData extends EntityData {
|
|
|
82
136
|
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
83
137
|
* @returns The value of the variable, or undefined if not found.
|
|
84
138
|
*/
|
|
85
|
-
getPrivateVar(key?: string): ASTNode<any
|
|
139
|
+
getPrivateVar(key?: string): ASTNode<any> | undefined;
|
|
86
140
|
/**
|
|
87
141
|
* Clears a variable from the private AST (Abstract Syntax Tree) by key.
|
|
88
142
|
*
|
|
@@ -90,90 +144,312 @@ declare class FlowNodeVariableData extends EntityData {
|
|
|
90
144
|
* @returns The updated AST node.
|
|
91
145
|
*/
|
|
92
146
|
clearPrivateVar(key?: string): void | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* An array containing all scopes (public and private) of the node.
|
|
149
|
+
*/
|
|
93
150
|
get allScopes(): FlowNodeScope[];
|
|
94
151
|
getDefaultData(): {};
|
|
95
152
|
constructor(entity: FlowNodeEntity, opts: Options);
|
|
153
|
+
/**
|
|
154
|
+
* Initializes and returns the private scope for the node.
|
|
155
|
+
* If the private scope already exists, it returns the existing one.
|
|
156
|
+
* @returns The private scope of the node.
|
|
157
|
+
*/
|
|
96
158
|
initPrivate(): FlowNodeScope;
|
|
159
|
+
/**
|
|
160
|
+
* Find a variable field by key path in the public scope by scope chain.
|
|
161
|
+
* @param keyPath - The key path of the variable field.
|
|
162
|
+
* @returns The variable field, or undefined if not found.
|
|
163
|
+
*/
|
|
164
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Find a variable field by key path in the private scope by scope chain.
|
|
167
|
+
* @param keyPath - The key path of the variable field.
|
|
168
|
+
* @returns The variable field, or undefined if not found.
|
|
169
|
+
*/
|
|
170
|
+
getByKeyPathInPrivate(keyPath: string[]): BaseVariableField | undefined;
|
|
97
171
|
}
|
|
98
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
175
|
+
* SPDX-License-Identifier: MIT
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Context for scope transformers.
|
|
180
|
+
*/
|
|
99
181
|
interface TransformerContext {
|
|
182
|
+
/**
|
|
183
|
+
* The current scope
|
|
184
|
+
*/
|
|
100
185
|
scope: FlowNodeScope;
|
|
186
|
+
/**
|
|
187
|
+
* The flow document.
|
|
188
|
+
*/
|
|
101
189
|
document: FlowDocument;
|
|
190
|
+
/**
|
|
191
|
+
* The variable engine.
|
|
192
|
+
*/
|
|
102
193
|
variableEngine: VariableEngine;
|
|
103
194
|
}
|
|
104
|
-
|
|
195
|
+
/**
|
|
196
|
+
* A function that transforms an array of scopes.
|
|
197
|
+
* @param scopes The array of scopes to transform.
|
|
198
|
+
* @param ctx The transformer context.
|
|
199
|
+
* @returns The transformed array of scopes.
|
|
200
|
+
*/
|
|
201
|
+
type IScopeTransformer = (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
202
|
+
/**
|
|
203
|
+
* A service for transforming scope chains.
|
|
204
|
+
*/
|
|
205
|
+
declare class ScopeChainTransformService {
|
|
206
|
+
protected configs?: VariableChainConfig | undefined;
|
|
207
|
+
protected transformerMap: Map<string, {
|
|
208
|
+
transformDeps: IScopeTransformer;
|
|
209
|
+
transformCovers: IScopeTransformer;
|
|
210
|
+
}>;
|
|
211
|
+
document: FlowDocument;
|
|
212
|
+
variableEngine: VariableEngine;
|
|
213
|
+
constructor(configs?: VariableChainConfig | undefined);
|
|
214
|
+
/**
|
|
215
|
+
* check if transformer registered
|
|
216
|
+
* @param transformerId used to identify transformer, prevent duplicated
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
hasTransformer(transformerId: string): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* register new transform function
|
|
222
|
+
* @param transformerId used to identify transformer, prevent duplicated transformer
|
|
223
|
+
* @param transformer The transformer to register.
|
|
224
|
+
*/
|
|
225
|
+
registerTransformer(transformerId: string, transformer: {
|
|
226
|
+
transformDeps: IScopeTransformer;
|
|
227
|
+
transformCovers: IScopeTransformer;
|
|
228
|
+
}): void;
|
|
229
|
+
/**
|
|
230
|
+
* Transforms the dependency scopes.
|
|
231
|
+
* @param scopes The array of scopes to transform.
|
|
232
|
+
* @param param1 The context for the transformation.
|
|
233
|
+
* @returns The transformed array of scopes.
|
|
234
|
+
*/
|
|
235
|
+
transformDeps(scopes: Scope[], { scope }: {
|
|
236
|
+
scope: Scope;
|
|
237
|
+
}): Scope[];
|
|
105
238
|
/**
|
|
106
|
-
*
|
|
239
|
+
* Transforms the cover scopes.
|
|
240
|
+
* @param scopes The array of scopes to transform.
|
|
241
|
+
* @param param1 The context for the transformation.
|
|
242
|
+
* @returns The transformed array of scopes.
|
|
107
243
|
*/
|
|
108
|
-
|
|
244
|
+
transformCovers(scopes: Scope[], { scope }: {
|
|
245
|
+
scope: Scope;
|
|
246
|
+
}): Scope[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
251
|
+
* SPDX-License-Identifier: MIT
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Configuration for the variable chain.
|
|
256
|
+
*/
|
|
257
|
+
interface VariableChainConfig {
|
|
109
258
|
/**
|
|
110
|
-
*
|
|
259
|
+
* The output variables of a node's children cannot be accessed by subsequent nodes.
|
|
260
|
+
*
|
|
111
261
|
* @param node
|
|
112
262
|
* @returns
|
|
113
263
|
*/
|
|
114
264
|
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
115
265
|
/**
|
|
116
|
-
*
|
|
266
|
+
* For fixed layout scenarios: there are a large number of useless nodes between parent and child (such as inlineBlocks, etc., which need to be configured to be skipped)
|
|
267
|
+
* For free canvas scenarios: in some scenarios, the parent-child relationship between nodes is expressed through connections or other interactive forms, which needs to be configurable
|
|
117
268
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
269
|
+
getNodeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
270
|
+
getNodeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
120
271
|
/**
|
|
121
|
-
*
|
|
272
|
+
* Fine-tune the dependency scope.
|
|
122
273
|
*/
|
|
123
|
-
transformDeps?:
|
|
274
|
+
transformDeps?: IScopeTransformer;
|
|
124
275
|
/**
|
|
125
|
-
*
|
|
276
|
+
* Fine-tune the cover scope.
|
|
126
277
|
*/
|
|
127
|
-
transformCovers?:
|
|
278
|
+
transformCovers?: IScopeTransformer;
|
|
128
279
|
}
|
|
129
|
-
declare const
|
|
280
|
+
declare const VariableChainConfig: unique symbol;
|
|
130
281
|
|
|
131
282
|
/**
|
|
132
|
-
*
|
|
283
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
284
|
+
* SPDX-License-Identifier: MIT
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Scope chain implementation for free layout.
|
|
133
289
|
*/
|
|
134
290
|
declare class FreeLayoutScopeChain extends ScopeChain {
|
|
135
291
|
entityManager: EntityManager;
|
|
136
292
|
protected flowDocument: FlowDocument;
|
|
137
|
-
protected configs?:
|
|
293
|
+
protected configs?: VariableChainConfig;
|
|
294
|
+
protected transformService: ScopeChainTransformService;
|
|
295
|
+
/**
|
|
296
|
+
* The virtual tree of the flow document.
|
|
297
|
+
*/
|
|
138
298
|
get tree(): FlowVirtualTree<FlowNodeEntity>;
|
|
139
299
|
onInit(): void;
|
|
140
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Gets all input layer nodes for a given node in the same layer, sorted by distance.
|
|
302
|
+
* @param node The node to get input layer nodes for.
|
|
303
|
+
* @returns An array of input layer nodes.
|
|
304
|
+
*/
|
|
305
|
+
protected getAllInputLayerNodes(node: FlowNodeEntity): FlowNodeEntity[];
|
|
306
|
+
/**
|
|
307
|
+
* Gets all output layer nodes for a given node in the same layer.
|
|
308
|
+
* @param curr The node to get output layer nodes for.
|
|
309
|
+
* @returns An array of output layer nodes.
|
|
310
|
+
*/
|
|
141
311
|
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
312
|
+
/**
|
|
313
|
+
* Gets the dependency scopes for a given scope.
|
|
314
|
+
* @param scope The scope to get dependencies for.
|
|
315
|
+
* @returns An array of dependency scopes.
|
|
316
|
+
*/
|
|
142
317
|
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
318
|
+
/**
|
|
319
|
+
* Gets the covering scopes for a given scope.
|
|
320
|
+
* @param scope The scope to get covering scopes for.
|
|
321
|
+
* @returns An array of covering scopes.
|
|
322
|
+
*/
|
|
143
323
|
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Gets the children of a node.
|
|
326
|
+
* @param node The node to get children for.
|
|
327
|
+
* @returns An array of child nodes.
|
|
328
|
+
*/
|
|
329
|
+
getNodeChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
330
|
+
/**
|
|
331
|
+
* Get All children of nodes
|
|
332
|
+
* @param node
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
335
|
+
getAllPublicChildScopes(node: FlowNodeEntity): Scope[];
|
|
336
|
+
/**
|
|
337
|
+
* Gets the parent of a node.
|
|
338
|
+
* @param node The node to get the parent for.
|
|
339
|
+
* @returns The parent node or `undefined` if not found.
|
|
340
|
+
*/
|
|
341
|
+
getNodeParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Checks if the children of a node are private and cannot be accessed by subsequent nodes.
|
|
344
|
+
* @param node The node to check.
|
|
345
|
+
* @returns `true` if the children are private, `false` otherwise.
|
|
346
|
+
*/
|
|
347
|
+
protected isNodeChildrenPrivate(node?: FlowNodeEntity): boolean;
|
|
348
|
+
/**
|
|
349
|
+
* Sorts all scopes in the scope chain.
|
|
350
|
+
* @returns An empty array, as this method is not implemented.
|
|
351
|
+
*/
|
|
152
352
|
sortAll(): Scope[];
|
|
153
353
|
}
|
|
154
354
|
|
|
155
355
|
/**
|
|
156
|
-
*
|
|
356
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
357
|
+
* SPDX-License-Identifier: MIT
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Scope chain implementation based on `FlowVirtualTree`.
|
|
157
362
|
*/
|
|
158
363
|
declare class FixedLayoutScopeChain extends ScopeChain {
|
|
159
364
|
protected flowDocument: FlowDocument;
|
|
160
|
-
protected configs?:
|
|
365
|
+
protected configs?: VariableChainConfig | undefined;
|
|
161
366
|
tree: FlowVirtualTree<ScopeChainNode> | undefined;
|
|
162
|
-
|
|
367
|
+
protected transformService: ScopeChainTransformService;
|
|
368
|
+
constructor(flowDocument: FlowDocument, configs?: VariableChainConfig | undefined);
|
|
369
|
+
/**
|
|
370
|
+
* Binds the scope chain to a `FlowVirtualTree`.
|
|
371
|
+
* @param tree The `FlowVirtualTree` to bind to.
|
|
372
|
+
*/
|
|
163
373
|
bindTree(tree: FlowVirtualTree<ScopeChainNode>): void;
|
|
374
|
+
/**
|
|
375
|
+
* Gets the dependency scopes for a given scope.
|
|
376
|
+
* @param scope The scope to get dependencies for.
|
|
377
|
+
* @returns An array of dependency scopes.
|
|
378
|
+
*/
|
|
164
379
|
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
380
|
+
/**
|
|
381
|
+
* Gets the covering scopes for a given scope.
|
|
382
|
+
* @param scope The scope to get covering scopes for.
|
|
383
|
+
* @returns An array of covering scopes.
|
|
384
|
+
*/
|
|
165
385
|
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
scope: Scope;
|
|
171
|
-
}): Scope[];
|
|
386
|
+
/**
|
|
387
|
+
* Sorts all scopes in the scope chain.
|
|
388
|
+
* @returns A sorted array of all scopes.
|
|
389
|
+
*/
|
|
172
390
|
sortAll(): Scope[];
|
|
391
|
+
/**
|
|
392
|
+
* Gets the `FlowNodeVariableData` for a given `ScopeChainNode`.
|
|
393
|
+
* @param node The `ScopeChainNode` to get data for.
|
|
394
|
+
* @returns The `FlowNodeVariableData` or `undefined` if not found.
|
|
395
|
+
*/
|
|
173
396
|
private getVariableData;
|
|
397
|
+
/**
|
|
398
|
+
* Checks if the children of a node are private.
|
|
399
|
+
* @param node The node to check.
|
|
400
|
+
* @returns `true` if the children are private, `false` otherwise.
|
|
401
|
+
*/
|
|
174
402
|
private isNodeChildrenPrivate;
|
|
403
|
+
/**
|
|
404
|
+
* Checks if a node has children.
|
|
405
|
+
* @param node The node to check.
|
|
406
|
+
* @returns `true` if the node has children, `false` otherwise.
|
|
407
|
+
*/
|
|
175
408
|
private hasChildren;
|
|
409
|
+
/**
|
|
410
|
+
* Gets all sorted child scopes of a node.
|
|
411
|
+
* @param node The node to get child scopes for.
|
|
412
|
+
* @param options Options for getting child scopes.
|
|
413
|
+
* @returns An array of sorted child scopes.
|
|
414
|
+
*/
|
|
176
415
|
private getAllSortedChildScope;
|
|
177
416
|
}
|
|
178
417
|
|
|
179
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
420
|
+
* SPDX-License-Identifier: MIT
|
|
421
|
+
*/
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Global Scope stores all variables that are not scoped to any node.
|
|
425
|
+
*
|
|
426
|
+
* - Variables in Global Scope can be accessed by any node.
|
|
427
|
+
* - Any other scope's variables can not be accessed by Global Scope.
|
|
428
|
+
*/
|
|
429
|
+
declare class GlobalScope extends Scope {
|
|
430
|
+
static readonly ID: unique symbol;
|
|
431
|
+
/**
|
|
432
|
+
* Check if the scope is Global Scope.
|
|
433
|
+
* @param scope
|
|
434
|
+
* @returns
|
|
435
|
+
*/
|
|
436
|
+
static is(scope: Scope): boolean;
|
|
437
|
+
}
|
|
438
|
+
declare const bindGlobalScope: (bind: interfaces.Bind) => void;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Use `node.scope` instead.
|
|
442
|
+
* @deprecated
|
|
443
|
+
* @param node The flow node entity.
|
|
444
|
+
* @returns The public scope of the node.
|
|
445
|
+
*/
|
|
446
|
+
declare function getNodeScope(node: FlowNodeEntity): FlowNodeScope;
|
|
447
|
+
/**
|
|
448
|
+
* Use `node.privateScope` instead.
|
|
449
|
+
* @deprecated
|
|
450
|
+
* @param node The flow node entity.
|
|
451
|
+
* @returns The private scope of the node.
|
|
452
|
+
*/
|
|
453
|
+
declare function getNodePrivateScope(node: FlowNodeEntity): FlowNodeScope;
|
|
454
|
+
|
|
455
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, GlobalScope, ScopeChainTransformService, VariableChainConfig, bindGlobalScope, getNodePrivateScope, getNodeScope };
|