@flowgram.ai/variable-layout 0.2.16 → 0.2.18
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 +81 -64
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +80 -44
- package/dist/index.d.ts +80 -44
- package/dist/index.js +84 -65
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/esm/index.js
CHANGED
|
@@ -123,6 +123,22 @@ var FlowNodeVariableData = class extends EntityData {
|
|
|
123
123
|
}
|
|
124
124
|
return this._private;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Find a variable field by key path in the public scope by scope chain.
|
|
128
|
+
* @param keyPath - The key path of the variable field.
|
|
129
|
+
* @returns The variable field, or undefined if not found.
|
|
130
|
+
*/
|
|
131
|
+
getByKeyPath(keyPath) {
|
|
132
|
+
return this.public.available.getByKeyPath(keyPath);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Find a variable field by key path in the private scope by scope chain.
|
|
136
|
+
* @param keyPath - The key path of the variable field.
|
|
137
|
+
* @returns The variable field, or undefined if not found.
|
|
138
|
+
*/
|
|
139
|
+
getByKeyPathInPrivate(keyPath) {
|
|
140
|
+
return this.private?.available.getByKeyPath(keyPath);
|
|
141
|
+
}
|
|
126
142
|
};
|
|
127
143
|
FlowNodeVariableData.type = "FlowNodeVariableData";
|
|
128
144
|
|
|
@@ -144,43 +160,59 @@ import { inject, injectable, optional } from "inversify";
|
|
|
144
160
|
import { VariableEngine } from "@flowgram.ai/variable-core";
|
|
145
161
|
import { FlowDocument } from "@flowgram.ai/document";
|
|
146
162
|
import { lazyInject } from "@flowgram.ai/core";
|
|
163
|
+
var passthrough = (scopes, ctx) => scopes;
|
|
147
164
|
var ScopeChainTransformService = class {
|
|
148
165
|
constructor(configs) {
|
|
149
166
|
this.configs = configs;
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.transformCoversFns.push(this.configs.transformCovers);
|
|
167
|
+
this.transformerMap = /* @__PURE__ */ new Map();
|
|
168
|
+
if (this.configs?.transformDeps || this.configs?.transformCovers) {
|
|
169
|
+
this.transformerMap.set("VARIABLE_LAYOUT_CONFIG", {
|
|
170
|
+
transformDeps: this.configs.transformDeps || passthrough,
|
|
171
|
+
transformCovers: this.configs.transformCovers || passthrough
|
|
172
|
+
});
|
|
157
173
|
}
|
|
158
174
|
}
|
|
159
|
-
|
|
160
|
-
|
|
175
|
+
/**
|
|
176
|
+
* check if transformer registered
|
|
177
|
+
* @param transformerId used to identify transformer, prevent duplicated
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
hasTransformer(transformerId) {
|
|
181
|
+
return this.transformerMap.has(transformerId);
|
|
161
182
|
}
|
|
162
|
-
|
|
163
|
-
|
|
183
|
+
/**
|
|
184
|
+
* register new transform function
|
|
185
|
+
* @param transformerId used to identify transformer, prevent duplicated transformer
|
|
186
|
+
* @param transformer
|
|
187
|
+
*/
|
|
188
|
+
registerTransformer(transformerId, transformer) {
|
|
189
|
+
this.transformerMap.set(transformerId, transformer);
|
|
164
190
|
}
|
|
165
191
|
transformDeps(scopes, { scope }) {
|
|
166
|
-
return this.
|
|
167
|
-
(
|
|
192
|
+
return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
|
|
193
|
+
if (!transformer.transformDeps) {
|
|
194
|
+
return scopes2;
|
|
195
|
+
}
|
|
196
|
+
scopes2 = transformer.transformDeps(scopes2, {
|
|
168
197
|
scope,
|
|
169
198
|
document: this.document,
|
|
170
199
|
variableEngine: this.variableEngine
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
);
|
|
200
|
+
});
|
|
201
|
+
return scopes2;
|
|
202
|
+
}, scopes);
|
|
174
203
|
}
|
|
175
204
|
transformCovers(scopes, { scope }) {
|
|
176
|
-
return this.
|
|
177
|
-
(
|
|
205
|
+
return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
|
|
206
|
+
if (!transformer.transformCovers) {
|
|
207
|
+
return scopes2;
|
|
208
|
+
}
|
|
209
|
+
scopes2 = transformer.transformCovers(scopes2, {
|
|
178
210
|
scope,
|
|
179
211
|
document: this.document,
|
|
180
212
|
variableEngine: this.variableEngine
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
);
|
|
213
|
+
});
|
|
214
|
+
return scopes2;
|
|
215
|
+
}, scopes);
|
|
184
216
|
}
|
|
185
217
|
};
|
|
186
218
|
__decorateClass([
|
|
@@ -202,33 +234,6 @@ var GlobalScope = class extends Scope2 {
|
|
|
202
234
|
static is(scope) {
|
|
203
235
|
return scope.id === GlobalScope.ID;
|
|
204
236
|
}
|
|
205
|
-
setVar(arg1, arg2) {
|
|
206
|
-
if (typeof arg1 === "string" && arg2 !== void 0) {
|
|
207
|
-
return this.ast.set(arg1, arg2);
|
|
208
|
-
}
|
|
209
|
-
if (typeof arg1 === "object" && arg2 === void 0) {
|
|
210
|
-
return this.ast.set("outputs", arg1);
|
|
211
|
-
}
|
|
212
|
-
throw new Error("Invalid arguments");
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Retrieves a variable from the Global Scope by key.
|
|
216
|
-
*
|
|
217
|
-
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
218
|
-
* @returns The value of the variable, or undefined if not found.
|
|
219
|
-
*/
|
|
220
|
-
getVar(key = "outputs") {
|
|
221
|
-
return this.ast.get(key);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Clears a variable from the Global Scope by key.
|
|
225
|
-
*
|
|
226
|
-
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
227
|
-
* @returns The updated AST node.
|
|
228
|
-
*/
|
|
229
|
-
clearVar(key = "outputs") {
|
|
230
|
-
return this.ast.remove(key);
|
|
231
|
-
}
|
|
232
237
|
};
|
|
233
238
|
GlobalScope.ID = Symbol("GlobalScope");
|
|
234
239
|
GlobalScope = __decorateClass([
|
|
@@ -271,16 +276,16 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
271
276
|
}
|
|
272
277
|
// 获取同一层级所有输入节点
|
|
273
278
|
getAllInputLayerNodes(curr) {
|
|
274
|
-
const currParent = this.
|
|
279
|
+
const currParent = this.getNodeParent(curr);
|
|
275
280
|
return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(
|
|
276
|
-
(_node) => this.
|
|
281
|
+
(_node) => this.getNodeParent(_node) === currParent
|
|
277
282
|
);
|
|
278
283
|
}
|
|
279
284
|
// 获取同一层级所有输出节点
|
|
280
285
|
getAllOutputLayerNodes(curr) {
|
|
281
|
-
const currParent = this.
|
|
286
|
+
const currParent = this.getNodeParent(curr);
|
|
282
287
|
return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(
|
|
283
|
-
(_node) => this.
|
|
288
|
+
(_node) => this.getNodeParent(_node) === currParent
|
|
284
289
|
);
|
|
285
290
|
}
|
|
286
291
|
getDeps(scope) {
|
|
@@ -299,7 +304,7 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
299
304
|
if (currVarData?.private && scope !== currVarData.private) {
|
|
300
305
|
deps.push(currVarData.private);
|
|
301
306
|
}
|
|
302
|
-
curr = this.
|
|
307
|
+
curr = this.getNodeParent(curr);
|
|
303
308
|
}
|
|
304
309
|
const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
|
|
305
310
|
if (globalScope) {
|
|
@@ -310,7 +315,8 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
310
315
|
}
|
|
311
316
|
getCovers(scope) {
|
|
312
317
|
if (GlobalScope.is(scope)) {
|
|
313
|
-
|
|
318
|
+
const scopes2 = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
|
|
319
|
+
return this.transformService.transformCovers(scopes2, { scope });
|
|
314
320
|
}
|
|
315
321
|
const { node } = scope.meta || {};
|
|
316
322
|
if (!node) {
|
|
@@ -319,7 +325,7 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
319
325
|
const isPrivate = scope.meta.type === "private" /* private */;
|
|
320
326
|
const queue = [];
|
|
321
327
|
if (isPrivate) {
|
|
322
|
-
queue.push(...this.
|
|
328
|
+
queue.push(...this.getNodeChildren(node));
|
|
323
329
|
} else {
|
|
324
330
|
queue.push(...this.getAllOutputLayerNodes(node) || []);
|
|
325
331
|
}
|
|
@@ -328,7 +334,7 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
328
334
|
const _node = queue.shift();
|
|
329
335
|
const variableData = _node.getData(FlowNodeVariableData);
|
|
330
336
|
scopes.push(...variableData.allScopes);
|
|
331
|
-
const children = _node && this.
|
|
337
|
+
const children = _node && this.getNodeChildren(_node);
|
|
332
338
|
if (children?.length) {
|
|
333
339
|
queue.push(...children);
|
|
334
340
|
}
|
|
@@ -340,9 +346,9 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
340
346
|
const uniqScopes = Array.from(new Set(scopes));
|
|
341
347
|
return this.transformService.transformCovers(uniqScopes, { scope });
|
|
342
348
|
}
|
|
343
|
-
|
|
344
|
-
if (this.configs?.
|
|
345
|
-
return this.configs.
|
|
349
|
+
getNodeChildren(node) {
|
|
350
|
+
if (this.configs?.getNodeChildren) {
|
|
351
|
+
return this.configs.getNodeChildren?.(node);
|
|
346
352
|
}
|
|
347
353
|
const nodeMeta = node.getNodeMeta();
|
|
348
354
|
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
@@ -355,9 +361,9 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
355
361
|
}
|
|
356
362
|
return this.tree.getChildren(node);
|
|
357
363
|
}
|
|
358
|
-
|
|
359
|
-
if (this.configs?.
|
|
360
|
-
return this.configs.
|
|
364
|
+
getNodeParent(node) {
|
|
365
|
+
if (this.configs?.getNodeParent) {
|
|
366
|
+
return this.configs.getNodeParent(node);
|
|
361
367
|
}
|
|
362
368
|
let parent = node.document.originTree.getParent(node);
|
|
363
369
|
while (parent?.flowNodeType === FlowNodeBaseType.GROUP) {
|
|
@@ -479,7 +485,8 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
479
485
|
return this.transformService.transformCovers([], { scope });
|
|
480
486
|
}
|
|
481
487
|
if (GlobalScope.is(scope)) {
|
|
482
|
-
|
|
488
|
+
const scopes = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
|
|
489
|
+
return this.transformService.transformCovers(scopes, { scope });
|
|
483
490
|
}
|
|
484
491
|
const node = scope.meta.node;
|
|
485
492
|
if (!node) {
|
|
@@ -604,6 +611,14 @@ FixedLayoutScopeChain = __decorateClass([
|
|
|
604
611
|
__decorateParam(1, optional3()),
|
|
605
612
|
__decorateParam(1, inject3(VariableLayoutConfig))
|
|
606
613
|
], FixedLayoutScopeChain);
|
|
614
|
+
|
|
615
|
+
// src/utils.ts
|
|
616
|
+
function getNodeScope(node) {
|
|
617
|
+
return node.getData(FlowNodeVariableData).public;
|
|
618
|
+
}
|
|
619
|
+
function getNodePrivateScope(node) {
|
|
620
|
+
return node.getData(FlowNodeVariableData).initPrivate();
|
|
621
|
+
}
|
|
607
622
|
export {
|
|
608
623
|
FixedLayoutScopeChain,
|
|
609
624
|
FlowNodeScopeTypeEnum as FlowNodeScopeType,
|
|
@@ -612,6 +627,8 @@ export {
|
|
|
612
627
|
GlobalScope,
|
|
613
628
|
ScopeChainTransformService,
|
|
614
629
|
VariableLayoutConfig,
|
|
615
|
-
bindGlobalScope
|
|
630
|
+
bindGlobalScope,
|
|
631
|
+
getNodePrivateScope,
|
|
632
|
+
getNodeScope
|
|
616
633
|
};
|
|
617
634
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/flow-node-variable-data.ts","../../src/types.ts","../../src/chains/free-layout-scope-chain.ts","../../src/variable-layout-config.ts","../../src/services/scope-chain-transform-service.ts","../../src/scopes/global-scope.ts","../../src/chains/fixed-layout-scope-chain.ts"],"sourcesContent":["import { VariableEngine } from '@flowgram.ai/variable-core';\nimport { type ASTNode, ASTNodeJSON } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\nimport { EntityData } from '@flowgram.ai/core';\n\nimport { FlowNodeScope, FlowNodeScopeMeta, FlowNodeScopeTypeEnum } from './types';\n\ninterface Options {\n variableEngine: VariableEngine;\n}\n\nexport class FlowNodeVariableData extends EntityData {\n static type: string = 'FlowNodeVariableData';\n\n declare entity: FlowNodeEntity;\n\n readonly variableEngine: VariableEngine;\n\n /**\n * Private variables can be accessed by public ones, but not the other way around.\n */\n protected _private?: FlowNodeScope;\n\n protected _public: FlowNodeScope;\n\n get private() {\n return this._private;\n }\n\n get public() {\n return this._public;\n }\n\n /**\n * Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.\n *\n * @param key - The key under which the variable will be stored.\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(key: string, json: ASTNodeJSON): ASTNode;\n\n /**\n * Sets a variable in the public AST (Abstract Syntax Tree) with the default key 'outputs'.\n *\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(json: ASTNodeJSON): ASTNode;\n\n public setVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {\n if (typeof arg1 === 'string' && arg2 !== undefined) {\n return this.public.ast.set(arg1, arg2);\n }\n\n if (typeof arg1 === 'object' && arg2 === undefined) {\n return this.public.ast.set('outputs', arg1);\n }\n\n throw new Error('Invalid arguments');\n }\n\n /**\n * Retrieves a variable from the public AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to retrieve. Defaults to 'outputs'.\n * @returns The value of the variable, or undefined if not found.\n */\n public getVar(key: string = 'outputs') {\n return this.public.ast.get(key);\n }\n\n /**\n * Clears a variable from the public AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to clear. Defaults to 'outputs'.\n * @returns The updated AST node.\n */\n public clearVar(key: string = 'outputs') {\n return this.public.ast.remove(key);\n }\n\n /**\n * Sets a variable in the private AST (Abstract Syntax Tree) with the given key and JSON value.\n *\n * @param key - The key under which the variable will be stored.\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setPrivateVar(key: string, json: ASTNodeJSON): ASTNode;\n\n /**\n * Sets a variable in the private AST (Abstract Syntax Tree) with the default key 'outputs'.\n *\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setPrivateVar(json: ASTNodeJSON): ASTNode;\n\n public setPrivateVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {\n if (typeof arg1 === 'string' && arg2 !== undefined) {\n return this.initPrivate().ast.set(arg1, arg2);\n }\n\n if (typeof arg1 === 'object' && arg2 === undefined) {\n return this.initPrivate().ast.set('outputs', arg1);\n }\n\n throw new Error('Invalid arguments');\n }\n\n /**\n * Retrieves a variable from the private AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to retrieve. Defaults to 'outputs'.\n * @returns The value of the variable, or undefined if not found.\n */\n public getPrivateVar(key: string = 'outputs') {\n return this.private?.ast.get(key);\n }\n\n /**\n * Clears a variable from the private AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to clear. Defaults to 'outputs'.\n * @returns The updated AST node.\n */\n public clearPrivateVar(key: string = 'outputs') {\n return this.private?.ast.remove(key);\n }\n\n get allScopes(): FlowNodeScope[] {\n const res = [];\n\n if (this._public) {\n res.push(this._public);\n }\n if (this._private) {\n res.push(this._private);\n }\n\n return res;\n }\n\n getDefaultData() {\n return {};\n }\n\n constructor(entity: FlowNodeEntity, readonly opts: Options) {\n super(entity);\n\n const { variableEngine } = opts || {};\n this.variableEngine = variableEngine;\n this._public = this.variableEngine.createScope(this.entity.id, {\n node: this.entity,\n type: FlowNodeScopeTypeEnum.public,\n } as FlowNodeScopeMeta);\n this.toDispose.push(this._public);\n }\n\n initPrivate(): FlowNodeScope {\n if (!this._private) {\n this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {\n node: this.entity,\n type: FlowNodeScopeTypeEnum.private,\n } as FlowNodeScopeMeta);\n // 1. Notify the covering scopes of private to update dependencies\n this._private.coverScopes.forEach((_scope) => {\n _scope.refreshDeps();\n });\n // 2. Notify the dependent scopes of private to update their covers\n this._private.depScopes.forEach((_scope) => {\n _scope.refreshCovers();\n });\n // 3. The private scope itself needs to refresh its dependencies\n this._private.available.refresh();\n\n this.toDispose.push(this._private);\n }\n return this._private;\n }\n}\n","import { Scope } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nexport enum FlowNodeScopeTypeEnum {\n public = 'public',\n private = 'private',\n}\n\nexport interface FlowNodeScopeMeta {\n node?: FlowNodeEntity;\n type?: FlowNodeScopeTypeEnum;\n}\n\nexport interface ScopeVirtualNode {\n id: string;\n flowNodeType: 'virtualNode';\n}\n\nexport type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;\n\n// 节点内部的作用域\nexport type FlowNodeScope = Scope<FlowNodeScopeMeta>;\n","import { inject, optional, postConstruct } from 'inversify';\nimport { Scope, ScopeChain } from '@flowgram.ai/variable-core';\nimport { WorkflowNodeLinesData, WorkflowNodeMeta } from '@flowgram.ai/free-layout-core';\nimport {\n FlowNodeEntity,\n FlowDocument,\n FlowVirtualTree,\n FlowNodeBaseType,\n} from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from '../types';\nimport { ScopeChainTransformService } from '../services/scope-chain-transform-service';\nimport { GlobalScope } from '../scopes/global-scope';\nimport { FlowNodeVariableData } from '../flow-node-variable-data';\n\n/**\n * 自由布局作用域链实现\n */\nexport class FreeLayoutScopeChain extends ScopeChain {\n @inject(EntityManager) entityManager: EntityManager;\n\n @inject(FlowDocument)\n protected flowDocument: FlowDocument;\n\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig;\n\n @inject(ScopeChainTransformService)\n protected transformService: ScopeChainTransformService;\n\n get tree(): FlowVirtualTree<FlowNodeEntity> {\n return this.flowDocument.originTree;\n }\n\n @postConstruct()\n onInit() {\n this.toDispose.pushAll([\n // 线条发生变化时,会触发作用域链的更新\n this.entityManager.onEntityDataChange(({ entityDataType }) => {\n if (entityDataType === WorkflowNodeLinesData.type) {\n this.refreshAllChange();\n }\n }),\n // 树变化时候刷新作用域\n this.tree.onTreeChange(() => {\n this.refreshAllChange();\n }),\n ]);\n }\n\n // 获取同一层级所有输入节点\n protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n const currParent = this.getParent(curr);\n\n return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n (_node) => this.getParent(_node) === currParent\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n const currParent = this.getParent(curr);\n\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n (_node) => this.getParent(_node) === currParent\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const deps: FlowNodeScope[] = [];\n\n // 1. 找到依赖的节点\n let curr: FlowNodeEntity | undefined = node;\n\n while (curr) {\n const allInputNodes: FlowNodeEntity[] = this.getAllInputLayerNodes(curr);\n\n // 2. 获取所有依赖节点的 public 作用域\n deps.push(\n ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)\n );\n\n // 父节点的 private 也可以访问\n const currVarData: FlowNodeVariableData = curr.getData(FlowNodeVariableData);\n if (currVarData?.private && scope !== currVarData.private) {\n deps.push(currVarData.private);\n }\n\n curr = this.getParent(curr);\n }\n\n // If scope is GlobalScope, add globalScope to deps\n const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);\n if (globalScope) {\n deps.unshift(globalScope);\n }\n\n const uniqDeps = Array.from(new Set(deps));\n return this.transformService.transformDeps(uniqDeps, { scope });\n }\n\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n // If scope is GlobalScope, return all scopes except GlobalScope\n if (GlobalScope.is(scope)) {\n return this.variableEngine\n .getAllScopes({ sort: true })\n .filter((_scope) => !GlobalScope.is(_scope));\n }\n\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformService.transformCovers([], { scope });\n }\n\n const isPrivate = scope.meta.type === FlowNodeScopeTypeEnum.private;\n\n // 1. BFS 找到所有覆盖的节点\n const queue: FlowNodeEntity[] = [];\n\n if (isPrivate) {\n // private 只能覆盖其子节点\n queue.push(...this.getChildren(node));\n } else {\n // 否则覆盖其所有输出线的节点\n queue.push(...(this.getAllOutputLayerNodes(node) || []));\n }\n\n // 2. 获取所有覆盖节点的 public、private 作用域\n const scopes: FlowNodeScope[] = [];\n\n while (queue.length) {\n const _node = queue.shift()!;\n const variableData: FlowNodeVariableData = _node.getData(FlowNodeVariableData);\n scopes.push(...variableData.allScopes);\n const children = _node && this.getChildren(_node);\n\n if (children?.length) {\n queue.push(...children);\n }\n }\n\n // 3. 如果当前 scope 是 private,则当前节点的 public 也可覆盖\n const currentVariableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n if (isPrivate && currentVariableData.public) {\n scopes.push(currentVariableData.public);\n }\n\n const uniqScopes = Array.from(new Set(scopes));\n\n return this.transformService.transformCovers(uniqScopes, { scope });\n }\n\n getChildren(node: FlowNodeEntity): FlowNodeEntity[] {\n if (this.configs?.getFreeChildren) {\n return this.configs.getFreeChildren?.(node);\n }\n const nodeMeta = node.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(node);\n\n if (subCanvas) {\n // 子画布本身不存在 children\n if (subCanvas.isCanvas) {\n return [];\n } else {\n return subCanvas.canvasNode.collapsedChildren;\n }\n }\n\n // 部分场景通过连线来表达父子关系,因此需要上层配置\n return this.tree.getChildren(node);\n }\n\n getParent(node: FlowNodeEntity): FlowNodeEntity | undefined {\n // 部分场景通过连线来表达父子关系,因此需要上层配置\n if (this.configs?.getFreeParent) {\n return this.configs.getFreeParent(node);\n }\n let parent = node.document.originTree.getParent(node);\n\n // If currentParent is Group, get the parent of parent\n while (parent?.flowNodeType === FlowNodeBaseType.GROUP) {\n parent = parent.parent;\n }\n\n if (!parent) {\n return parent;\n }\n\n const nodeMeta = parent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(parent);\n if (subCanvas?.isCanvas) {\n // Get real parent node by subCanvas Configuration\n return subCanvas.parentNode;\n }\n\n return parent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","import { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { type ScopeChainNode } from './types';\nimport { IScopeTransformer } from './services/scope-chain-transform-service';\n\nexport interface VariableLayoutConfig {\n /**\n * 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景\n * @param node\n * @returns\n */\n isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;\n\n /**\n * 用于自由画布场景,部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需要可配置化\n */\n getFreeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];\n getFreeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;\n\n /**\n * @deprecated\n * 对依赖作用域进行微调\n */\n transformDeps?: IScopeTransformer;\n\n /**\n * @deprecated\n * 对依赖作用域进行微调\n */\n transformCovers?: IScopeTransformer;\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\n","import { inject, injectable, optional } from 'inversify';\nimport { Scope, VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowDocument } from '@flowgram.ai/document';\nimport { lazyInject } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope } from '../types';\n\nexport interface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\n\nexport type IScopeTransformer = (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\n@injectable()\nexport class ScopeChainTransformService {\n protected transformDepsFns: IScopeTransformer[] = [];\n\n protected transformCoversFns: IScopeTransformer[] = [];\n\n @lazyInject(FlowDocument) document: FlowDocument;\n\n @lazyInject(VariableEngine) variableEngine: VariableEngine;\n\n constructor(\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig\n ) {\n if (this.configs?.transformDeps) {\n this.transformDepsFns.push(this.configs.transformDeps);\n }\n if (this.configs?.transformCovers) {\n this.transformCoversFns.push(this.configs.transformCovers);\n }\n }\n\n registerTransformDeps(transformer: IScopeTransformer) {\n this.transformDepsFns.push(transformer);\n }\n\n registerTransformCovers(transformer: IScopeTransformer) {\n this.transformCoversFns.push(transformer);\n }\n\n transformDeps(scopes: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.transformDepsFns.reduce(\n (scopes, transformer) =>\n transformer(scopes, {\n scope,\n document: this.document,\n variableEngine: this.variableEngine,\n }),\n scopes\n );\n }\n\n transformCovers(scopes: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.transformCoversFns.reduce(\n (scopes, transformer) =>\n transformer(scopes, {\n scope,\n document: this.document,\n variableEngine: this.variableEngine,\n }),\n scopes\n );\n }\n}\n","import { injectable, interfaces } from 'inversify';\nimport { ASTNode, ASTNodeJSON, Scope, VariableEngine } from '@flowgram.ai/variable-core';\n\n@injectable()\nexport class GlobalScope extends Scope {\n static readonly ID = Symbol('GlobalScope');\n\n static is(scope: Scope): scope is GlobalScope {\n return scope.id === GlobalScope.ID;\n }\n\n /**\n * Sets a variable in the Global Scope with the given key and JSON value.\n *\n * @param key - The key under which the variable will be stored.\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(key: string, json: ASTNodeJSON): ASTNode;\n\n /**\n * Sets a variable in the Global Scope with the default key 'outputs'.\n *\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(json: ASTNodeJSON): ASTNode;\n\n public setVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {\n if (typeof arg1 === 'string' && arg2 !== undefined) {\n return this.ast.set(arg1, arg2);\n }\n\n if (typeof arg1 === 'object' && arg2 === undefined) {\n return this.ast.set('outputs', arg1);\n }\n\n throw new Error('Invalid arguments');\n }\n\n /**\n * Retrieves a variable from the Global Scope by key.\n *\n * @param key - The key of the variable to retrieve. Defaults to 'outputs'.\n * @returns The value of the variable, or undefined if not found.\n */\n public getVar(key: string = 'outputs') {\n return this.ast.get(key);\n }\n\n /**\n * Clears a variable from the Global Scope by key.\n *\n * @param key - The key of the variable to clear. Defaults to 'outputs'.\n * @returns The updated AST node.\n */\n public clearVar(key: string = 'outputs') {\n return this.ast.remove(key);\n }\n}\n\nexport const bindGlobalScope = (bind: interfaces.Bind) => {\n bind(GlobalScope).toDynamicValue((ctx) => {\n const variableEngine = ctx.container.get(VariableEngine);\n let scope = variableEngine.getScopeById(GlobalScope.ID) as GlobalScope;\n\n if (!scope) {\n scope = variableEngine.createScope(\n GlobalScope.ID,\n {},\n { ScopeConstructor: GlobalScope }\n ) as GlobalScope;\n variableEngine.chain.refreshAllChange();\n }\n\n return scope;\n });\n};\n","import { inject, optional } from 'inversify';\nimport { Scope, ScopeChain } from '@flowgram.ai/variable-core';\nimport { FlowDocument, type FlowVirtualTree } from '@flowgram.ai/document';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum, ScopeChainNode } from '../types';\nimport { ScopeChainTransformService } from '../services/scope-chain-transform-service';\nimport { GlobalScope } from '../scopes/global-scope';\nimport { FlowNodeVariableData } from '../flow-node-variable-data';\n\n/**\n * 基于 FlowVirtualTree 的 ScopeOrder 实现\n */\nexport class FixedLayoutScopeChain extends ScopeChain {\n // 增加 { id: string } 使得可以灵活添加自定义虚拟节点\n tree: FlowVirtualTree<ScopeChainNode> | undefined;\n\n @inject(ScopeChainTransformService)\n protected transformService: ScopeChainTransformService;\n\n constructor(\n @inject(FlowDocument)\n protected flowDocument: FlowDocument,\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig\n ) {\n super();\n\n // 绑定 flowDocument 里面的树\n this.bindTree(flowDocument.originTree);\n\n // originTree 发生变化时,触发依赖关系的变化\n this.toDispose.push(\n // REFRACTOR: onTreeChange 触发时机精细化\n flowDocument.originTree.onTreeChange(() => {\n this.refreshAllChange();\n })\n );\n }\n\n // 绑定树\n bindTree(tree: FlowVirtualTree<ScopeChainNode>): void {\n this.tree = tree;\n }\n\n // 获取依赖作用域\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const deps: FlowNodeScope[] = [];\n\n let curr: ScopeChainNode | undefined = node;\n\n while (curr) {\n const { parent, pre } = this.tree.getInfo(curr);\n const currData = this.getVariableData(curr);\n\n // 包含子节点,且不是私有作用域\n\n if (curr === node) {\n // public 可以依赖 private\n if (scope.meta.type === FlowNodeScopeTypeEnum.public && currData?.private) {\n deps.unshift(currData.private);\n }\n } else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {\n // 有子元素的节点,则将子元素纳入依赖作用域\n deps.unshift(\n ...this.getAllSortedChildScope(curr, {\n ignoreNodeChildrenPrivate: true,\n })\n );\n }\n\n // 节点的 public 都可以被访问\n if (currData && curr !== node) {\n deps.unshift(currData.public);\n }\n\n // 上个节点处理\n if (pre) {\n curr = pre;\n continue;\n }\n\n // 父节点处理\n if (parent) {\n let currParent: ScopeChainNode | undefined = parent;\n let currParentPre: ScopeChainNode | undefined = this.tree.getPre(currParent);\n\n while (currParent) {\n // 父节点的 private 和 public 都能被子节点访问\n const currParentData = this.getVariableData(currParent);\n if (currParentData) {\n deps.unshift(...currParentData.allScopes);\n }\n\n // 当前 parent 有 pre 节点,则停止向上查找\n if (currParentPre) {\n break;\n }\n\n currParent = this.tree.getParent(currParent);\n currParentPre = currParent ? this.tree.getPre(currParent) : undefined;\n }\n curr = currParentPre;\n continue;\n }\n\n // next 和 parent 都没有,直接结束循环\n curr = undefined;\n }\n\n // If scope is GlobalScope, add globalScope to deps\n const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);\n if (globalScope) {\n deps.unshift(globalScope);\n }\n\n return this.transformService.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformService.transformCovers([], { scope });\n }\n\n // If scope is GlobalScope, return all scopes except GlobalScope\n if (GlobalScope.is(scope)) {\n return this.variableEngine\n .getAllScopes({ sort: true })\n .filter((_scope) => !GlobalScope.is(_scope));\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.transformService.transformCovers([], { scope });\n }\n\n const covers: FlowNodeScope[] = [];\n\n // 如果是 private 作用域,则只能子节点访问\n if (scope.meta.type === FlowNodeScopeTypeEnum.private) {\n covers.push(\n ...this.getAllSortedChildScope(node, {\n addNodePrivateScope: true,\n })\n );\n return this.transformService.transformCovers(covers, { scope });\n }\n\n let curr: ScopeChainNode | undefined = node;\n\n while (curr) {\n const { next, parent } = this.tree.getInfo(curr);\n const currData = this.getVariableData(curr);\n\n // 有子元素的节点,则将子元素纳入覆盖作用域\n if (curr !== node) {\n if (this.hasChildren(curr)) {\n covers.push(\n ...this.getAllSortedChildScope(curr, {\n addNodePrivateScope: true,\n })\n );\n } else if (currData) {\n covers.push(...currData.allScopes);\n }\n }\n\n // 下个节点处理\n if (next) {\n curr = next;\n continue;\n }\n\n if (parent) {\n let currParent: ScopeChainNode | undefined = parent;\n let currParentNext: ScopeChainNode | undefined = this.tree.getNext(currParent);\n\n while (currParent) {\n // 私有作用域不能被后续节点访问\n if (this.isNodeChildrenPrivate(currParent)) {\n return this.transformService.transformCovers(covers, { scope });\n }\n\n // 当前 parent 有 next 节点,则停止向上查找\n if (currParentNext) {\n break;\n }\n\n currParent = this.tree.getParent(currParent);\n currParentNext = currParent ? this.tree.getNext(currParent) : undefined;\n }\n if (!currParentNext && currParent) {\n break;\n }\n\n curr = currParentNext;\n continue;\n }\n\n // next 和 parent 都没有,直接结束循环\n curr = undefined;\n }\n\n return this.transformService.transformCovers(covers, { scope });\n }\n\n // 排序所有作用域\n sortAll(): Scope[] {\n const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);\n if (!startNode) {\n return [];\n }\n\n const startVariableData = startNode.getData(FlowNodeVariableData);\n const startPublicScope = startVariableData.public;\n const deps = this.getDeps(startPublicScope);\n\n const covers = this.getCovers(startPublicScope).filter(\n (_scope) => !deps.includes(_scope) && _scope !== startPublicScope\n );\n\n return [...deps, startPublicScope, ...covers];\n }\n\n // 获取变量 Data 数据\n private getVariableData(node: ScopeChainNode): FlowNodeVariableData | undefined {\n if (node.flowNodeType === 'virtualNode') {\n return;\n }\n // TODO 包含 $ 的节点不注册 variableData\n if (node.id.startsWith('$')) {\n return;\n }\n\n return (node as FlowNodeEntity).getData(FlowNodeVariableData);\n }\n\n // privateScope:子节点不可以被后续节点访问\n private isNodeChildrenPrivate(node?: ScopeChainNode): boolean {\n if (this.configs?.isNodeChildrenPrivate) {\n return node ? this.configs?.isNodeChildrenPrivate(node) : false;\n }\n\n const isSystemNode = node?.id.startsWith('$');\n // 兜底:有子节点(节点 id 没有 $ 开头)的全部为私有作用域\n return !isSystemNode && this.hasChildren(node);\n }\n\n private hasChildren(node?: ScopeChainNode): boolean {\n return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);\n }\n\n // 子节点按照顺序进行排序(含自身)\n private getAllSortedChildScope(\n node: ScopeChainNode,\n {\n ignoreNodeChildrenPrivate,\n addNodePrivateScope,\n }: { ignoreNodeChildrenPrivate?: boolean; addNodePrivateScope?: boolean } = {}\n ): FlowNodeScope[] {\n const scopes: FlowNodeScope[] = [];\n\n const variableData = this.getVariableData(node);\n\n if (variableData) {\n scopes.push(variableData.public);\n }\n\n // 私有作用域,子节点的变量不对外输出\n //(父节点如果存在 public 变量则对外输出)\n if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {\n return scopes;\n }\n\n if (addNodePrivateScope && variableData?.private) {\n scopes.push(variableData.private);\n }\n\n const children = this.tree?.getChildren(node) || [];\n scopes.push(\n ...children\n .map((child) =>\n this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })\n )\n .flat()\n );\n\n return scopes;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,SAAS,kBAAkB;;;ACApB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,YAAS;AACT,EAAAA,uBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;;;ADQL,IAAM,uBAAN,cAAmC,WAAW;AAAA,EAyInD,YAAY,QAAiC,MAAe;AAC1D,UAAM,MAAM;AAD+B;AAG3C,UAAM,EAAE,eAAe,IAAI,QAAQ,CAAC;AACpC,SAAK,iBAAiB;AACtB,SAAK,UAAU,KAAK,eAAe,YAAY,KAAK,OAAO,IAAI;AAAA,MAC7D,MAAM,KAAK;AAAA,MACX;AAAA,IACF,CAAsB;AACtB,SAAK,UAAU,KAAK,KAAK,OAAO;AAAA,EAClC;AAAA,EArIA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAS;AACX,WAAO,KAAK;AAAA,EACd;AAAA,EAmBO,OAAO,MAA4B,MAA6B;AACrE,QAAI,OAAO,SAAS,YAAY,SAAS,QAAW;AAClD,aAAO,KAAK,OAAO,IAAI,IAAI,MAAM,IAAI;AAAA,IACvC;AAEA,QAAI,OAAO,SAAS,YAAY,SAAS,QAAW;AAClD,aAAO,KAAK,OAAO,IA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KAAK,YAAY,IAAI,EAAE,SAAS,CAAC;AAAA,EAC5E;AAAA;AAAA,EAGQ,uBACN,MACA;AAAA,IACE;AAAA,IACA;AAAA,EACF,IAA4E,CAAC,GAC5D;AACjB,UAAM,SAA0B,CAAC;AAEjC,UAAM,eAAe,KAAK,gBAAgB,IAAI;AAE9C,QAAI,cAAc;AAChB,aAAO,KAAK,aAAa,MAAM;AAAA,IACjC;AAIA,QAAI,6BAA6B,KAAK,sBAAsB,IAAI,GAAG;AACjE,aAAO;AAAA,IACT;AAEA,QAAI,uBAAuB,cAAc,SAAS;AAChD,aAAO,KAAK,aAAa,OAAO;AAAA,IAClC;AAEA,UAAM,WAAW,KAAK,MAAM,YAAY,IAAI,KAAK,CAAC;AAClD,WAAO;AAAA,MACL,GAAG,SACA;AAAA,QAAI,CAAC,UACJ,KAAK,uBAAuB,OAAO,EAAE,2BAA2B,oBAAoB,CAAC;AAAA,MACvF,EACC,KAAK;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;AA1RY;AAAA,EADTC,QAAO,0BAA0B;AAAA,GAJvB,sBAKD;AALC,wBAAN;AAAA,EAQF,mBAAAA,QAAOC,aAAY;AAAA,EAEnB,mBAAAC,UAAS;AAAA,EACT,mBAAAF,QAAO,oBAAoB;AAAA,GAXnB;","names":["FlowNodeScopeTypeEnum","inject","optional","FlowDocument","scopes","injectable","Scope","VariableEngine","Scope","injectable","VariableEngine","inject","FlowDocument","optional","inject","optional","ScopeChain","FlowDocument","ScopeChain","inject","FlowDocument","optional"]}
|
|
1
|
+
{"version":3,"sources":["../../src/flow-node-variable-data.ts","../../src/types.ts","../../src/chains/free-layout-scope-chain.ts","../../src/variable-layout-config.ts","../../src/services/scope-chain-transform-service.ts","../../src/scopes/global-scope.ts","../../src/chains/fixed-layout-scope-chain.ts","../../src/utils.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { BaseVariableField, VariableEngine } from '@flowgram.ai/variable-core';\nimport { type ASTNode, ASTNodeJSON } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\nimport { EntityData } from '@flowgram.ai/core';\n\nimport { FlowNodeScope, FlowNodeScopeMeta, FlowNodeScopeTypeEnum } from './types';\n\ninterface Options {\n variableEngine: VariableEngine;\n}\n\nexport class FlowNodeVariableData extends EntityData {\n static type: string = 'FlowNodeVariableData';\n\n declare entity: FlowNodeEntity;\n\n readonly variableEngine: VariableEngine;\n\n /**\n * Private variables can be accessed by public ones, but not the other way around.\n */\n protected _private?: FlowNodeScope;\n\n protected _public: FlowNodeScope;\n\n get private() {\n return this._private;\n }\n\n get public() {\n return this._public;\n }\n\n /**\n * Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.\n *\n * @param key - The key under which the variable will be stored.\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(key: string, json: ASTNodeJSON): ASTNode;\n\n /**\n * Sets a variable in the public AST (Abstract Syntax Tree) with the default key 'outputs'.\n *\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setVar(json: ASTNodeJSON): ASTNode;\n\n public setVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {\n if (typeof arg1 === 'string' && arg2 !== undefined) {\n return this.public.ast.set(arg1, arg2);\n }\n\n if (typeof arg1 === 'object' && arg2 === undefined) {\n return this.public.ast.set('outputs', arg1);\n }\n\n throw new Error('Invalid arguments');\n }\n\n /**\n * Retrieves a variable from the public AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to retrieve. Defaults to 'outputs'.\n * @returns The value of the variable, or undefined if not found.\n */\n public getVar(key: string = 'outputs') {\n return this.public.ast.get(key);\n }\n\n /**\n * Clears a variable from the public AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to clear. Defaults to 'outputs'.\n * @returns The updated AST node.\n */\n public clearVar(key: string = 'outputs') {\n return this.public.ast.remove(key);\n }\n\n /**\n * Sets a variable in the private AST (Abstract Syntax Tree) with the given key and JSON value.\n *\n * @param key - The key under which the variable will be stored.\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setPrivateVar(key: string, json: ASTNodeJSON): ASTNode;\n\n /**\n * Sets a variable in the private AST (Abstract Syntax Tree) with the default key 'outputs'.\n *\n * @param json - The JSON value to store.\n * @returns The updated AST node.\n */\n public setPrivateVar(json: ASTNodeJSON): ASTNode;\n\n public setPrivateVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {\n if (typeof arg1 === 'string' && arg2 !== undefined) {\n return this.initPrivate().ast.set(arg1, arg2);\n }\n\n if (typeof arg1 === 'object' && arg2 === undefined) {\n return this.initPrivate().ast.set('outputs', arg1);\n }\n\n throw new Error('Invalid arguments');\n }\n\n /**\n * Retrieves a variable from the private AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to retrieve. Defaults to 'outputs'.\n * @returns The value of the variable, or undefined if not found.\n */\n public getPrivateVar(key: string = 'outputs') {\n return this.private?.ast.get(key);\n }\n\n /**\n * Clears a variable from the private AST (Abstract Syntax Tree) by key.\n *\n * @param key - The key of the variable to clear. Defaults to 'outputs'.\n * @returns The updated AST node.\n */\n public clearPrivateVar(key: string = 'outputs') {\n return this.private?.ast.remove(key);\n }\n\n get allScopes(): FlowNodeScope[] {\n const res = [];\n\n if (this._public) {\n res.push(this._public);\n }\n if (this._private) {\n res.push(this._private);\n }\n\n return res;\n }\n\n getDefaultData() {\n return {};\n }\n\n constructor(entity: FlowNodeEntity, readonly opts: Options) {\n super(entity);\n\n const { variableEngine } = opts || {};\n this.variableEngine = variableEngine;\n this._public = this.variableEngine.createScope(this.entity.id, {\n node: this.entity,\n type: FlowNodeScopeTypeEnum.public,\n } as FlowNodeScopeMeta);\n this.toDispose.push(this._public);\n }\n\n initPrivate(): FlowNodeScope {\n if (!this._private) {\n this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {\n node: this.entity,\n type: FlowNodeScopeTypeEnum.private,\n } as FlowNodeScopeMeta);\n // 1. Notify the covering scopes of private to update dependencies\n this._private.coverScopes.forEach((_scope) => {\n _scope.refreshDeps();\n });\n // 2. Notify the dependent scopes of private to update their covers\n this._private.depScopes.forEach((_scope) => {\n _scope.refreshCovers();\n });\n // 3. The private scope itself needs to refresh its dependencies\n this._private.available.refresh();\n\n this.toDispose.push(this._private);\n }\n return this._private;\n }\n\n /**\n * Find a variable field by key path in the public scope by scope chain.\n * @param keyPath - The key path of the variable field.\n * @returns The variable field, or undefined if not found.\n */\n getByKeyPath(keyPath: string[]): BaseVariableField | undefined {\n return this.public.available.getByKeyPath(keyPath);\n }\n\n /**\n * Find a variable field by key path in the private scope by scope chain.\n * @param keyPath - The key path of the variable field.\n * @returns The variable field, or undefined if not found.\n */\n getByKeyPathInPrivate(keyPath: string[]): BaseVariableField | undefined {\n return this.private?.available.getByKeyPath(keyPath);\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { Scope } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nexport enum FlowNodeScopeTypeEnum {\n public = 'public',\n private = 'private',\n}\n\nexport interface FlowNodeScopeMeta {\n node?: FlowNodeEntity;\n type?: FlowNodeScopeTypeEnum;\n}\n\nexport interface ScopeVirtualNode {\n id: string;\n flowNodeType: 'virtualNode';\n}\n\nexport type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;\n\n// 节点内部的作用域\nexport interface FlowNodeScope extends Scope<FlowNodeScopeMeta> {}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, optional, postConstruct } from 'inversify';\nimport { Scope, ScopeChain } from '@flowgram.ai/variable-core';\nimport { WorkflowNodeLinesData, WorkflowNodeMeta } from '@flowgram.ai/free-layout-core';\nimport {\n FlowNodeEntity,\n FlowDocument,\n FlowVirtualTree,\n FlowNodeBaseType,\n} from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from '../types';\nimport { ScopeChainTransformService } from '../services/scope-chain-transform-service';\nimport { GlobalScope } from '../scopes/global-scope';\nimport { FlowNodeVariableData } from '../flow-node-variable-data';\n\n/**\n * 自由布局作用域链实现\n */\nexport class FreeLayoutScopeChain extends ScopeChain {\n @inject(EntityManager) entityManager: EntityManager;\n\n @inject(FlowDocument)\n protected flowDocument: FlowDocument;\n\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig;\n\n @inject(ScopeChainTransformService)\n protected transformService: ScopeChainTransformService;\n\n get tree(): FlowVirtualTree<FlowNodeEntity> {\n return this.flowDocument.originTree;\n }\n\n @postConstruct()\n onInit() {\n this.toDispose.pushAll([\n // 线条发生变化时,会触发作用域链的更新\n this.entityManager.onEntityDataChange(({ entityDataType }) => {\n if (entityDataType === WorkflowNodeLinesData.type) {\n this.refreshAllChange();\n }\n }),\n // 树变化时候刷新作用域\n this.tree.onTreeChange(() => {\n this.refreshAllChange();\n }),\n ]);\n }\n\n // 获取同一层级所有输入节点\n protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n const currParent = this.getNodeParent(curr);\n\n return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n (_node) => this.getNodeParent(_node) === currParent\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n const currParent = this.getNodeParent(curr);\n\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n (_node) => this.getNodeParent(_node) === currParent\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const deps: FlowNodeScope[] = [];\n\n // 1. 找到依赖的节点\n let curr: FlowNodeEntity | undefined = node;\n\n while (curr) {\n const allInputNodes: FlowNodeEntity[] = this.getAllInputLayerNodes(curr);\n\n // 2. 获取所有依赖节点的 public 作用域\n deps.push(\n ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)\n );\n\n // 父节点的 private 也可以访问\n const currVarData: FlowNodeVariableData = curr.getData(FlowNodeVariableData);\n if (currVarData?.private && scope !== currVarData.private) {\n deps.push(currVarData.private);\n }\n\n curr = this.getNodeParent(curr);\n }\n\n // If scope is GlobalScope, add globalScope to deps\n const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);\n if (globalScope) {\n deps.unshift(globalScope);\n }\n\n const uniqDeps = Array.from(new Set(deps));\n return this.transformService.transformDeps(uniqDeps, { scope });\n }\n\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n // If scope is GlobalScope, return all scopes except GlobalScope\n if (GlobalScope.is(scope)) {\n const scopes = this.variableEngine\n .getAllScopes({ sort: true })\n .filter((_scope) => !GlobalScope.is(_scope));\n\n return this.transformService.transformCovers(scopes, { scope });\n }\n\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformService.transformCovers([], { scope });\n }\n\n const isPrivate = scope.meta.type === FlowNodeScopeTypeEnum.private;\n\n // 1. BFS 找到所有覆盖的节点\n const queue: FlowNodeEntity[] = [];\n\n if (isPrivate) {\n // private 只能覆盖其子节点\n queue.push(...this.getNodeChildren(node));\n } else {\n // 否则覆盖其所有输出线的节点\n queue.push(...(this.getAllOutputLayerNodes(node) || []));\n }\n\n // 2. 获取所有覆盖节点的 public、private 作用域\n const scopes: FlowNodeScope[] = [];\n\n while (queue.length) {\n const _node = queue.shift()!;\n const variableData: FlowNodeVariableData = _node.getData(FlowNodeVariableData);\n scopes.push(...variableData.allScopes);\n const children = _node && this.getNodeChildren(_node);\n\n if (children?.length) {\n queue.push(...children);\n }\n }\n\n // 3. 如果当前 scope 是 private,则当前节点的 public 也可覆盖\n const currentVariableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n if (isPrivate && currentVariableData.public) {\n scopes.push(currentVariableData.public);\n }\n\n const uniqScopes = Array.from(new Set(scopes));\n\n return this.transformService.transformCovers(uniqScopes, { scope });\n }\n\n getNodeChildren(node: FlowNodeEntity): FlowNodeEntity[] {\n if (this.configs?.getNodeChildren) {\n return this.configs.getNodeChildren?.(node);\n }\n const nodeMeta = node.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(node);\n\n if (subCanvas) {\n // 子画布本身不存在 children\n if (subCanvas.isCanvas) {\n return [];\n } else {\n return subCanvas.canvasNode.collapsedChildren;\n }\n }\n\n // 部分场景通过连线来表达父子关系,因此需要上层配置\n return this.tree.getChildren(node);\n }\n\n getNodeParent(node: FlowNodeEntity): FlowNodeEntity | undefined {\n // 部分场景通过连线来表达父子关系,因此需要上层配置\n if (this.configs?.getNodeParent) {\n return this.configs.getNodeParent(node);\n }\n let parent = node.document.originTree.getParent(node);\n\n // If currentParent is Group, get the parent of parent\n while (parent?.flowNodeType === FlowNodeBaseType.GROUP) {\n parent = parent.parent;\n }\n\n if (!parent) {\n return parent;\n }\n\n const nodeMeta = parent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(parent);\n if (subCanvas?.isCanvas) {\n // Get real parent node by subCanvas Configuration\n return subCanvas.parentNode;\n }\n\n return parent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { type ScopeChainNode } from './types';\nimport { IScopeTransformer } from './services/scope-chain-transform-service';\n\nexport interface VariableLayoutConfig {\n /**\n * 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景\n * @param node\n * @returns\n */\n isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;\n\n /**\n * 用于固定布局场景时:父子中间存在大量无用节点(如 inlineBlocks 等,需要配置化略过)\n * 用于自由画布场景时:部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需可配置化\n */\n getNodeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];\n getNodeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;\n\n /**\n * 对依赖作用域进行微调\n */\n transformDeps?: IScopeTransformer;\n\n /**\n * 对依赖作用域进行微调\n */\n transformCovers?: IScopeTransformer;\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, injectable, optional } from 'inversify';\nimport { Scope, VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowDocument } from '@flowgram.ai/document';\nimport { lazyInject } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope } from '../types';\n\nexport interface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\n\nexport type IScopeTransformer = (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\nconst passthrough: IScopeTransformer = (scopes, ctx) => scopes;\n\n@injectable()\nexport class ScopeChainTransformService {\n protected transformerMap: Map<\n string,\n { transformDeps: IScopeTransformer; transformCovers: IScopeTransformer }\n > = new Map();\n\n @lazyInject(FlowDocument) document: FlowDocument;\n\n @lazyInject(VariableEngine) variableEngine: VariableEngine;\n\n constructor(\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig\n ) {\n if (this.configs?.transformDeps || this.configs?.transformCovers) {\n this.transformerMap.set('VARIABLE_LAYOUT_CONFIG', {\n transformDeps: this.configs.transformDeps || passthrough,\n transformCovers: this.configs.transformCovers || passthrough,\n });\n }\n }\n\n /**\n * check if transformer registered\n * @param transformerId used to identify transformer, prevent duplicated\n * @returns\n */\n hasTransformer(transformerId: string) {\n return this.transformerMap.has(transformerId);\n }\n\n /**\n * register new transform function\n * @param transformerId used to identify transformer, prevent duplicated transformer\n * @param transformer\n */\n registerTransformer(\n transformerId: string,\n transformer: {\n transformDeps: IScopeTransformer;\n transformCovers: IScopeTransformer;\n }\n ) {\n this.transformerMap.set(transformerId, transformer);\n }\n\n transformDeps(scopes: Scope[], { scope }: { scope: Scope }): Scope[] {\n return Array.from(this.transformerMap.values()).reduce((scopes, transformer) => {\n if (!transformer.transformDeps) {\n return scopes;\n }\n\n scopes = transformer.transformDeps(scopes, {\n scope,\n document: this.document,\n variableEngine: this.variableEngine,\n });\n return scopes;\n }, scopes);\n }\n\n transformCovers(scopes: Scope[], { scope }: { scope: Scope }): Scope[] {\n return Array.from(this.transformerMap.values()).reduce((scopes, transformer) => {\n if (!transformer.transformCovers) {\n return scopes;\n }\n\n scopes = transformer.transformCovers(scopes, {\n scope,\n document: this.document,\n variableEngine: this.variableEngine,\n });\n return scopes;\n }, scopes);\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { injectable, interfaces } from 'inversify';\nimport { Scope, VariableEngine } from '@flowgram.ai/variable-core';\n\n@injectable()\nexport class GlobalScope extends Scope {\n static readonly ID = Symbol('GlobalScope');\n\n static is(scope: Scope) {\n return scope.id === GlobalScope.ID;\n }\n}\n\nexport const bindGlobalScope = (bind: interfaces.Bind) => {\n bind(GlobalScope).toDynamicValue((ctx) => {\n const variableEngine = ctx.container.get(VariableEngine);\n let scope = variableEngine.getScopeById(GlobalScope.ID) as GlobalScope;\n\n if (!scope) {\n scope = variableEngine.createScope(\n GlobalScope.ID,\n {},\n { ScopeConstructor: GlobalScope }\n ) as GlobalScope;\n variableEngine.chain.refreshAllChange();\n }\n\n return scope;\n });\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, optional } from 'inversify';\nimport { Scope, ScopeChain } from '@flowgram.ai/variable-core';\nimport { FlowDocument, type FlowVirtualTree } from '@flowgram.ai/document';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum, ScopeChainNode } from '../types';\nimport { ScopeChainTransformService } from '../services/scope-chain-transform-service';\nimport { GlobalScope } from '../scopes/global-scope';\nimport { FlowNodeVariableData } from '../flow-node-variable-data';\n\n/**\n * 基于 FlowVirtualTree 的 ScopeOrder 实现\n */\nexport class FixedLayoutScopeChain extends ScopeChain {\n // 增加 { id: string } 使得可以灵活添加自定义虚拟节点\n tree: FlowVirtualTree<ScopeChainNode> | undefined;\n\n @inject(ScopeChainTransformService)\n protected transformService: ScopeChainTransformService;\n\n constructor(\n @inject(FlowDocument)\n protected flowDocument: FlowDocument,\n @optional()\n @inject(VariableLayoutConfig)\n protected configs?: VariableLayoutConfig\n ) {\n super();\n\n // 绑定 flowDocument 里面的树\n this.bindTree(flowDocument.originTree);\n\n // originTree 发生变化时,触发依赖关系的变化\n this.toDispose.push(\n // REFRACTOR: onTreeChange 触发时机精细化\n flowDocument.originTree.onTreeChange(() => {\n this.refreshAllChange();\n })\n );\n }\n\n // 绑定树\n bindTree(tree: FlowVirtualTree<ScopeChainNode>): void {\n this.tree = tree;\n }\n\n // 获取依赖作用域\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.transformService.transformDeps([], { scope });\n }\n\n const deps: FlowNodeScope[] = [];\n\n let curr: ScopeChainNode | undefined = node;\n\n while (curr) {\n const { parent, pre } = this.tree.getInfo(curr);\n const currData = this.getVariableData(curr);\n\n // 包含子节点,且不是私有作用域\n\n if (curr === node) {\n // public 可以依赖 private\n if (scope.meta.type === FlowNodeScopeTypeEnum.public && currData?.private) {\n deps.unshift(currData.private);\n }\n } else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {\n // 有子元素的节点,则将子元素纳入依赖作用域\n deps.unshift(\n ...this.getAllSortedChildScope(curr, {\n ignoreNodeChildrenPrivate: true,\n })\n );\n }\n\n // 节点的 public 都可以被访问\n if (currData && curr !== node) {\n deps.unshift(currData.public);\n }\n\n // 上个节点处理\n if (pre) {\n curr = pre;\n continue;\n }\n\n // 父节点处理\n if (parent) {\n let currParent: ScopeChainNode | undefined = parent;\n let currParentPre: ScopeChainNode | undefined = this.tree.getPre(currParent);\n\n while (currParent) {\n // 父节点的 private 和 public 都能被子节点访问\n const currParentData = this.getVariableData(currParent);\n if (currParentData) {\n deps.unshift(...currParentData.allScopes);\n }\n\n // 当前 parent 有 pre 节点,则停止向上查找\n if (currParentPre) {\n break;\n }\n\n currParent = this.tree.getParent(currParent);\n currParentPre = currParent ? this.tree.getPre(currParent) : undefined;\n }\n curr = currParentPre;\n continue;\n }\n\n // next 和 parent 都没有,直接结束循环\n curr = undefined;\n }\n\n // If scope is GlobalScope, add globalScope to deps\n const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);\n if (globalScope) {\n deps.unshift(globalScope);\n }\n\n return this.transformService.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformService.transformCovers([], { scope });\n }\n\n // If scope is GlobalScope, return all scopes except GlobalScope\n if (GlobalScope.is(scope)) {\n const scopes = this.variableEngine\n .getAllScopes({ sort: true })\n .filter((_scope) => !GlobalScope.is(_scope));\n\n return this.transformService.transformCovers(scopes, { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.transformService.transformCovers([], { scope });\n }\n\n const covers: FlowNodeScope[] = [];\n\n // 如果是 private 作用域,则只能子节点访问\n if (scope.meta.type === FlowNodeScopeTypeEnum.private) {\n covers.push(\n ...this.getAllSortedChildScope(node, {\n addNodePrivateScope: true,\n })\n );\n return this.transformService.transformCovers(covers, { scope });\n }\n\n let curr: ScopeChainNode | undefined = node;\n\n while (curr) {\n const { next, parent } = this.tree.getInfo(curr);\n const currData = this.getVariableData(curr);\n\n // 有子元素的节点,则将子元素纳入覆盖作用域\n if (curr !== node) {\n if (this.hasChildren(curr)) {\n covers.push(\n ...this.getAllSortedChildScope(curr, {\n addNodePrivateScope: true,\n })\n );\n } else if (currData) {\n covers.push(...currData.allScopes);\n }\n }\n\n // 下个节点处理\n if (next) {\n curr = next;\n continue;\n }\n\n if (parent) {\n let currParent: ScopeChainNode | undefined = parent;\n let currParentNext: ScopeChainNode | undefined = this.tree.getNext(currParent);\n\n while (currParent) {\n // 私有作用域不能被后续节点访问\n if (this.isNodeChildrenPrivate(currParent)) {\n return this.transformService.transformCovers(covers, { scope });\n }\n\n // 当前 parent 有 next 节点,则停止向上查找\n if (currParentNext) {\n break;\n }\n\n currParent = this.tree.getParent(currParent);\n currParentNext = currParent ? this.tree.getNext(currParent) : undefined;\n }\n if (!currParentNext && currParent) {\n break;\n }\n\n curr = currParentNext;\n continue;\n }\n\n // next 和 parent 都没有,直接结束循环\n curr = undefined;\n }\n\n return this.transformService.transformCovers(covers, { scope });\n }\n\n // 排序所有作用域\n sortAll(): Scope[] {\n const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);\n if (!startNode) {\n return [];\n }\n\n const startVariableData = startNode.getData(FlowNodeVariableData);\n const startPublicScope = startVariableData.public;\n const deps = this.getDeps(startPublicScope);\n\n const covers = this.getCovers(startPublicScope).filter(\n (_scope) => !deps.includes(_scope) && _scope !== startPublicScope\n );\n\n return [...deps, startPublicScope, ...covers];\n }\n\n // 获取变量 Data 数据\n private getVariableData(node: ScopeChainNode): FlowNodeVariableData | undefined {\n if (node.flowNodeType === 'virtualNode') {\n return;\n }\n // TODO 包含 $ 的节点不注册 variableData\n if (node.id.startsWith('$')) {\n return;\n }\n\n return (node as FlowNodeEntity).getData(FlowNodeVariableData);\n }\n\n // privateScope:子节点不可以被后续节点访问\n private isNodeChildrenPrivate(node?: ScopeChainNode): boolean {\n if (this.configs?.isNodeChildrenPrivate) {\n return node ? this.configs?.isNodeChildrenPrivate(node) : false;\n }\n\n const isSystemNode = node?.id.startsWith('$');\n // 兜底:有子节点(节点 id 没有 $ 开头)的全部为私有作用域\n return !isSystemNode && this.hasChildren(node);\n }\n\n private hasChildren(node?: ScopeChainNode): boolean {\n return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);\n }\n\n // 子节点按照顺序进行排序(含自身)\n private getAllSortedChildScope(\n node: ScopeChainNode,\n {\n ignoreNodeChildrenPrivate,\n addNodePrivateScope,\n }: { ignoreNodeChildrenPrivate?: boolean; addNodePrivateScope?: boolean } = {}\n ): FlowNodeScope[] {\n const scopes: FlowNodeScope[] = [];\n\n const variableData = this.getVariableData(node);\n\n if (variableData) {\n scopes.push(variableData.public);\n }\n\n // 私有作用域,子节点的变量不对外输出\n //(父节点如果存在 public 变量则对外输出)\n if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {\n return scopes;\n }\n\n if (addNodePrivateScope && variableData?.private) {\n scopes.push(variableData.private);\n }\n\n const children = this.tree?.getChildren(node) || [];\n scopes.push(\n ...children\n .map((child) =>\n this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })\n )\n .flat()\n );\n\n return scopes;\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { FlowNodeVariableData } from './flow-node-variable-data';\n\nexport function getNodeScope(node: FlowNodeEntity) {\n return node.getData(FlowNodeVariableData).public;\n}\n\nexport function getNodePrivateScope(node: FlowNodeEntity) {\n return node.getData(FlowNodeVariableData).initPrivate();\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,kBAAkB;;;ACApB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,YAAS;AACT,EAAAA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AAO,KAAK,aAAa,OAAO;AAAA,IAClC;AAEA,UAAM,WAAW,KAAK,MAAM,YAAY,IAAI,KAAK,CAAC;AAClD,WAAO;AAAA,MACL,GAAG,SACA;AAAA,QAAI,CAAC,UACJ,KAAK,uBAAuB,OAAO,EAAE,2BAA2B,oBAAoB,CAAC;AAAA,MACvF,EACC,KAAK;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;AA5RY;AAAA,EADTC,QAAO,0BAA0B;AAAA,GAJvB,sBAKD;AALC,wBAAN;AAAA,EAQF,mBAAAA,QAAOC,aAAY;AAAA,EAEnB,mBAAAC,UAAS;AAAA,EACT,mBAAAF,QAAO,oBAAoB;AAAA,GAXnB;;;ACVN,SAAS,aAAa,MAAsB;AACjD,SAAO,KAAK,QAAQ,oBAAoB,EAAE;AAC5C;AAEO,SAAS,oBAAoB,MAAsB;AACxD,SAAO,KAAK,QAAQ,oBAAoB,EAAE,YAAY;AACxD;","names":["FlowNodeScopeTypeEnum","inject","optional","FlowDocument","scopes","injectable","Scope","VariableEngine","Scope","injectable","VariableEngine","scopes","inject","FlowDocument","optional","inject","optional","ScopeChain","FlowDocument","ScopeChain","inject","FlowDocument","optional"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
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
4
|
import { interfaces } from 'inversify';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
*/
|
|
10
|
+
|
|
6
11
|
declare enum FlowNodeScopeTypeEnum {
|
|
7
12
|
public = "public",
|
|
8
13
|
private = "private"
|
|
@@ -16,7 +21,13 @@ interface ScopeVirtualNode {
|
|
|
16
21
|
flowNodeType: 'virtualNode';
|
|
17
22
|
}
|
|
18
23
|
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
19
|
-
|
|
24
|
+
interface FlowNodeScope extends Scope<FlowNodeScopeMeta> {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
29
|
+
* SPDX-License-Identifier: MIT
|
|
30
|
+
*/
|
|
20
31
|
|
|
21
32
|
interface Options {
|
|
22
33
|
variableEngine: VariableEngine;
|
|
@@ -95,8 +106,25 @@ declare class FlowNodeVariableData extends EntityData {
|
|
|
95
106
|
getDefaultData(): {};
|
|
96
107
|
constructor(entity: FlowNodeEntity, opts: Options);
|
|
97
108
|
initPrivate(): FlowNodeScope;
|
|
109
|
+
/**
|
|
110
|
+
* Find a variable field by key path in the public scope by scope chain.
|
|
111
|
+
* @param keyPath - The key path of the variable field.
|
|
112
|
+
* @returns The variable field, or undefined if not found.
|
|
113
|
+
*/
|
|
114
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Find a variable field by key path in the private scope by scope chain.
|
|
117
|
+
* @param keyPath - The key path of the variable field.
|
|
118
|
+
* @returns The variable field, or undefined if not found.
|
|
119
|
+
*/
|
|
120
|
+
getByKeyPathInPrivate(keyPath: string[]): BaseVariableField | undefined;
|
|
98
121
|
}
|
|
99
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
125
|
+
* SPDX-License-Identifier: MIT
|
|
126
|
+
*/
|
|
127
|
+
|
|
100
128
|
interface TransformerContext {
|
|
101
129
|
scope: FlowNodeScope;
|
|
102
130
|
document: FlowDocument;
|
|
@@ -105,13 +133,28 @@ interface TransformerContext {
|
|
|
105
133
|
type IScopeTransformer = (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
106
134
|
declare class ScopeChainTransformService {
|
|
107
135
|
protected configs?: VariableLayoutConfig | undefined;
|
|
108
|
-
protected
|
|
109
|
-
|
|
136
|
+
protected transformerMap: Map<string, {
|
|
137
|
+
transformDeps: IScopeTransformer;
|
|
138
|
+
transformCovers: IScopeTransformer;
|
|
139
|
+
}>;
|
|
110
140
|
document: FlowDocument;
|
|
111
141
|
variableEngine: VariableEngine;
|
|
112
142
|
constructor(configs?: VariableLayoutConfig | undefined);
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
/**
|
|
144
|
+
* check if transformer registered
|
|
145
|
+
* @param transformerId used to identify transformer, prevent duplicated
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
hasTransformer(transformerId: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* register new transform function
|
|
151
|
+
* @param transformerId used to identify transformer, prevent duplicated transformer
|
|
152
|
+
* @param transformer
|
|
153
|
+
*/
|
|
154
|
+
registerTransformer(transformerId: string, transformer: {
|
|
155
|
+
transformDeps: IScopeTransformer;
|
|
156
|
+
transformCovers: IScopeTransformer;
|
|
157
|
+
}): void;
|
|
115
158
|
transformDeps(scopes: Scope[], { scope }: {
|
|
116
159
|
scope: Scope;
|
|
117
160
|
}): Scope[];
|
|
@@ -120,6 +163,11 @@ declare class ScopeChainTransformService {
|
|
|
120
163
|
}): Scope[];
|
|
121
164
|
}
|
|
122
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
168
|
+
* SPDX-License-Identifier: MIT
|
|
169
|
+
*/
|
|
170
|
+
|
|
123
171
|
interface VariableLayoutConfig {
|
|
124
172
|
/**
|
|
125
173
|
* 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
|
|
@@ -128,23 +176,27 @@ interface VariableLayoutConfig {
|
|
|
128
176
|
*/
|
|
129
177
|
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
130
178
|
/**
|
|
131
|
-
*
|
|
179
|
+
* 用于固定布局场景时:父子中间存在大量无用节点(如 inlineBlocks 等,需要配置化略过)
|
|
180
|
+
* 用于自由画布场景时:部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需可配置化
|
|
132
181
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
182
|
+
getNodeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
183
|
+
getNodeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
135
184
|
/**
|
|
136
|
-
* @deprecated
|
|
137
185
|
* 对依赖作用域进行微调
|
|
138
186
|
*/
|
|
139
187
|
transformDeps?: IScopeTransformer;
|
|
140
188
|
/**
|
|
141
|
-
* @deprecated
|
|
142
189
|
* 对依赖作用域进行微调
|
|
143
190
|
*/
|
|
144
191
|
transformCovers?: IScopeTransformer;
|
|
145
192
|
}
|
|
146
193
|
declare const VariableLayoutConfig: unique symbol;
|
|
147
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
197
|
+
* SPDX-License-Identifier: MIT
|
|
198
|
+
*/
|
|
199
|
+
|
|
148
200
|
/**
|
|
149
201
|
* 自由布局作用域链实现
|
|
150
202
|
*/
|
|
@@ -159,11 +211,16 @@ declare class FreeLayoutScopeChain extends ScopeChain {
|
|
|
159
211
|
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
160
212
|
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
161
213
|
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
162
|
-
|
|
163
|
-
|
|
214
|
+
getNodeChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
215
|
+
getNodeParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
164
216
|
sortAll(): Scope[];
|
|
165
217
|
}
|
|
166
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
221
|
+
* SPDX-License-Identifier: MIT
|
|
222
|
+
*/
|
|
223
|
+
|
|
167
224
|
/**
|
|
168
225
|
* 基于 FlowVirtualTree 的 ScopeOrder 实现
|
|
169
226
|
*/
|
|
@@ -183,39 +240,18 @@ declare class FixedLayoutScopeChain extends ScopeChain {
|
|
|
183
240
|
private getAllSortedChildScope;
|
|
184
241
|
}
|
|
185
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
245
|
+
* SPDX-License-Identifier: MIT
|
|
246
|
+
*/
|
|
247
|
+
|
|
186
248
|
declare class GlobalScope extends Scope {
|
|
187
249
|
static readonly ID: unique symbol;
|
|
188
|
-
static is(scope: Scope):
|
|
189
|
-
/**
|
|
190
|
-
* Sets a variable in the Global Scope with the given key and JSON value.
|
|
191
|
-
*
|
|
192
|
-
* @param key - The key under which the variable will be stored.
|
|
193
|
-
* @param json - The JSON value to store.
|
|
194
|
-
* @returns The updated AST node.
|
|
195
|
-
*/
|
|
196
|
-
setVar(key: string, json: ASTNodeJSON): ASTNode;
|
|
197
|
-
/**
|
|
198
|
-
* Sets a variable in the Global Scope with the default key 'outputs'.
|
|
199
|
-
*
|
|
200
|
-
* @param json - The JSON value to store.
|
|
201
|
-
* @returns The updated AST node.
|
|
202
|
-
*/
|
|
203
|
-
setVar(json: ASTNodeJSON): ASTNode;
|
|
204
|
-
/**
|
|
205
|
-
* Retrieves a variable from the Global Scope by key.
|
|
206
|
-
*
|
|
207
|
-
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
|
208
|
-
* @returns The value of the variable, or undefined if not found.
|
|
209
|
-
*/
|
|
210
|
-
getVar(key?: string): ASTNode<any, any> | undefined;
|
|
211
|
-
/**
|
|
212
|
-
* Clears a variable from the Global Scope by key.
|
|
213
|
-
*
|
|
214
|
-
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
|
215
|
-
* @returns The updated AST node.
|
|
216
|
-
*/
|
|
217
|
-
clearVar(key?: string): void;
|
|
250
|
+
static is(scope: Scope): boolean;
|
|
218
251
|
}
|
|
219
252
|
declare const bindGlobalScope: (bind: interfaces.Bind) => void;
|
|
220
253
|
|
|
221
|
-
|
|
254
|
+
declare function getNodeScope(node: FlowNodeEntity): FlowNodeScope;
|
|
255
|
+
declare function getNodePrivateScope(node: FlowNodeEntity): FlowNodeScope;
|
|
256
|
+
|
|
257
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, GlobalScope, ScopeChainTransformService, VariableLayoutConfig, bindGlobalScope, getNodePrivateScope, getNodeScope };
|