@flowgram.ai/variable-layout 0.1.0-alpha.7 → 0.1.0-alpha.8

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 CHANGED
@@ -82,7 +82,8 @@ var FlowNodeVariableData = class extends EntityData {
82
82
  * @returns The value of the variable, or undefined if not found.
83
83
  */
84
84
  getPrivateVar(key = "outputs") {
85
- return this.private?.ast.get(key);
85
+ var _a;
86
+ return (_a = this.private) == null ? void 0 : _a.ast.get(key);
86
87
  }
87
88
  /**
88
89
  * Clears a variable from the private AST (Abstract Syntax Tree) by key.
@@ -91,7 +92,8 @@ var FlowNodeVariableData = class extends EntityData {
91
92
  * @returns The updated AST node.
92
93
  */
93
94
  clearPrivateVar(key = "outputs") {
94
- return this.private?.ast.remove(key);
95
+ var _a;
96
+ return (_a = this.private) == null ? void 0 : _a.ast.remove(key);
95
97
  }
96
98
  get allScopes() {
97
99
  const res = [];
@@ -126,17 +128,72 @@ var FlowNodeVariableData = class extends EntityData {
126
128
  };
127
129
  FlowNodeVariableData.type = "FlowNodeVariableData";
128
130
 
129
- // src/free-layout-scope-chain.ts
131
+ // src/chains/free-layout-scope-chain.ts
130
132
  import { inject, optional, postConstruct } from "inversify";
131
133
  import { ScopeChain } from "@flowgram.ai/variable-core";
134
+ import { WorkflowNodeLinesData } from "@flowgram.ai/free-layout-core";
132
135
  import { FlowDocument } from "@flowgram.ai/document";
133
136
  import { EntityManager } from "@flowgram.ai/core";
134
- import { WorkflowNodeLinesData } from "@flowgram.ai/free-layout-core";
135
137
 
136
138
  // src/variable-layout-config.ts
137
139
  var VariableLayoutConfig = Symbol("VariableLayoutConfig");
138
140
 
139
- // src/free-layout-scope-chain.ts
141
+ // src/scopes/global-scope.ts
142
+ import { injectable } from "inversify";
143
+ import { Scope, VariableEngine } from "@flowgram.ai/variable-core";
144
+ var GlobalScope = class extends Scope {
145
+ static is(scope) {
146
+ return scope.id === GlobalScope.ID;
147
+ }
148
+ setVar(arg1, arg2) {
149
+ if (typeof arg1 === "string" && arg2 !== void 0) {
150
+ return this.ast.set(arg1, arg2);
151
+ }
152
+ if (typeof arg1 === "object" && arg2 === void 0) {
153
+ return this.ast.set("outputs", arg1);
154
+ }
155
+ throw new Error("Invalid arguments");
156
+ }
157
+ /**
158
+ * Retrieves a variable from the Global Scope by key.
159
+ *
160
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
161
+ * @returns The value of the variable, or undefined if not found.
162
+ */
163
+ getVar(key = "outputs") {
164
+ return this.ast.get(key);
165
+ }
166
+ /**
167
+ * Clears a variable from the Global Scope by key.
168
+ *
169
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
170
+ * @returns The updated AST node.
171
+ */
172
+ clearVar(key = "outputs") {
173
+ return this.ast.remove(key);
174
+ }
175
+ };
176
+ GlobalScope.ID = Symbol("GlobalScope");
177
+ GlobalScope = __decorateClass([
178
+ injectable()
179
+ ], GlobalScope);
180
+ var bindGlobalScope = (bind) => {
181
+ bind(GlobalScope).toDynamicValue((ctx) => {
182
+ const variableEngine = ctx.container.get(VariableEngine);
183
+ let scope = variableEngine.getScopeById(GlobalScope.ID);
184
+ if (!scope) {
185
+ scope = variableEngine.createScope(
186
+ GlobalScope.ID,
187
+ {},
188
+ { ScopeConstructor: GlobalScope }
189
+ );
190
+ variableEngine.chain.refreshAllChange();
191
+ }
192
+ return scope;
193
+ });
194
+ };
195
+
196
+ // src/chains/free-layout-scope-chain.ts
140
197
  var FreeLayoutScopeChain = class extends ScopeChain {
141
198
  get tree() {
142
199
  return this.flowDocument.originTree;
@@ -157,13 +214,15 @@ var FreeLayoutScopeChain = class extends ScopeChain {
157
214
  }
158
215
  // 获取同一层级所有输入节点
159
216
  getAllInputLayerNodes(curr) {
160
- return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(
217
+ var _a;
218
+ return (((_a = curr.getData(WorkflowNodeLinesData)) == null ? void 0 : _a.allInputNodes) || []).filter(
161
219
  (_node) => _node.parent === curr.parent
162
220
  );
163
221
  }
164
222
  // 获取同一层级所有输出节点
165
223
  getAllOutputLayerNodes(curr) {
166
- return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(
224
+ var _a;
225
+ return (((_a = curr.getData(WorkflowNodeLinesData)) == null ? void 0 : _a.allOutputNodes) || []).filter(
167
226
  (_node) => _node.parent === curr.parent
168
227
  );
169
228
  }
@@ -172,23 +231,30 @@ var FreeLayoutScopeChain = class extends ScopeChain {
172
231
  if (!node) {
173
232
  return this.transformDeps([], { scope });
174
233
  }
175
- const scopes = [];
234
+ const deps = [];
176
235
  let curr = node;
177
236
  while (curr) {
178
237
  const allInputNodes = this.getAllInputLayerNodes(curr);
179
- scopes.push(
238
+ deps.push(
180
239
  ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
181
240
  );
182
241
  const currVarData = curr.getData(FlowNodeVariableData);
183
- if (currVarData?.private && scope !== currVarData.private) {
184
- scopes.push(currVarData.private);
242
+ if ((currVarData == null ? void 0 : currVarData.private) && scope !== currVarData.private) {
243
+ deps.push(currVarData.private);
185
244
  }
186
245
  curr = this.getParent(curr);
187
246
  }
188
- const uniqScopes = Array.from(new Set(scopes));
189
- return this.transformDeps(uniqScopes, { scope });
247
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
248
+ if (globalScope) {
249
+ deps.unshift(globalScope);
250
+ }
251
+ const uniqDeps = Array.from(new Set(deps));
252
+ return this.transformDeps(uniqDeps, { scope });
190
253
  }
191
254
  getCovers(scope) {
255
+ if (GlobalScope.is(scope)) {
256
+ return this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
257
+ }
192
258
  const { node } = scope.meta || {};
193
259
  if (!node) {
194
260
  return this.transformCovers([], { scope });
@@ -206,7 +272,7 @@ var FreeLayoutScopeChain = class extends ScopeChain {
206
272
  const variableData = _node.getData(FlowNodeVariableData);
207
273
  scopes.push(...variableData.allScopes);
208
274
  const children = _node && this.getChildren(_node);
209
- if (children?.length) {
275
+ if (children == null ? void 0 : children.length) {
210
276
  queue.push(...children);
211
277
  }
212
278
  }
@@ -218,25 +284,28 @@ var FreeLayoutScopeChain = class extends ScopeChain {
218
284
  return this.transformCovers(uniqScopes, { scope });
219
285
  }
220
286
  transformCovers(covers, { scope }) {
221
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
287
+ var _a;
288
+ return ((_a = this.configs) == null ? void 0 : _a.transformCovers) ? this.configs.transformCovers(covers, {
222
289
  scope,
223
290
  document: this.flowDocument,
224
291
  variableEngine: this.variableEngine
225
292
  }) : covers;
226
293
  }
227
294
  transformDeps(deps, { scope }) {
228
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
295
+ var _a;
296
+ return ((_a = this.configs) == null ? void 0 : _a.transformDeps) ? this.configs.transformDeps(deps, {
229
297
  scope,
230
298
  document: this.flowDocument,
231
299
  variableEngine: this.variableEngine
232
300
  }) : deps;
233
301
  }
234
302
  getChildren(node) {
235
- if (this.configs?.getFreeChildren) {
236
- return this.configs.getFreeChildren?.(node);
303
+ var _a, _b, _c, _d;
304
+ if ((_a = this.configs) == null ? void 0 : _a.getFreeChildren) {
305
+ return (_c = (_b = this.configs).getFreeChildren) == null ? void 0 : _c.call(_b, node);
237
306
  }
238
307
  const nodeMeta = node.getNodeMeta();
239
- const subCanvas = nodeMeta.subCanvas?.(node);
308
+ const subCanvas = (_d = nodeMeta.subCanvas) == null ? void 0 : _d.call(nodeMeta, node);
240
309
  if (subCanvas) {
241
310
  if (subCanvas.isCanvas) {
242
311
  return [];
@@ -247,7 +316,8 @@ var FreeLayoutScopeChain = class extends ScopeChain {
247
316
  return this.tree.getChildren(node);
248
317
  }
249
318
  getParent(node) {
250
- if (this.configs?.getFreeParent) {
319
+ var _a, _b;
320
+ if ((_a = this.configs) == null ? void 0 : _a.getFreeParent) {
251
321
  return this.configs.getFreeParent(node);
252
322
  }
253
323
  const initParent = node.document.originTree.getParent(node);
@@ -255,8 +325,8 @@ var FreeLayoutScopeChain = class extends ScopeChain {
255
325
  return initParent;
256
326
  }
257
327
  const nodeMeta = initParent.getNodeMeta();
258
- const subCanvas = nodeMeta.subCanvas?.(initParent);
259
- if (subCanvas?.isCanvas) {
328
+ const subCanvas = (_b = nodeMeta.subCanvas) == null ? void 0 : _b.call(nodeMeta, initParent);
329
+ if (subCanvas == null ? void 0 : subCanvas.isCanvas) {
260
330
  return subCanvas.parentNode;
261
331
  }
262
332
  return initParent;
@@ -280,7 +350,7 @@ __decorateClass([
280
350
  postConstruct()
281
351
  ], FreeLayoutScopeChain.prototype, "onInit", 1);
282
352
 
283
- // src/fixed-layout-scope-chain.ts
353
+ // src/chains/fixed-layout-scope-chain.ts
284
354
  import { inject as inject2, optional as optional2 } from "inversify";
285
355
  import { ScopeChain as ScopeChain2 } from "@flowgram.ai/variable-core";
286
356
  import { FlowDocument as FlowDocument2 } from "@flowgram.ai/document";
@@ -316,7 +386,7 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
316
386
  const { parent, pre } = this.tree.getInfo(curr);
317
387
  const currData = this.getVariableData(curr);
318
388
  if (curr === node) {
319
- if (scope.meta.type === "public" /* public */ && currData?.private) {
389
+ if (scope.meta.type === "public" /* public */ && (currData == null ? void 0 : currData.private)) {
320
390
  deps.unshift(currData.private);
321
391
  }
322
392
  } else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {
@@ -352,6 +422,10 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
352
422
  }
353
423
  curr = void 0;
354
424
  }
425
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
426
+ if (globalScope) {
427
+ deps.unshift(globalScope);
428
+ }
355
429
  return this.transformDeps(deps, { scope });
356
430
  }
357
431
  // 获取覆盖作用域
@@ -359,6 +433,9 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
359
433
  if (!this.tree) {
360
434
  return this.transformCovers([], { scope });
361
435
  }
436
+ if (GlobalScope.is(scope)) {
437
+ return this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
438
+ }
362
439
  const node = scope.meta.node;
363
440
  if (!node) {
364
441
  return this.transformCovers([], { scope });
@@ -415,14 +492,16 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
415
492
  return this.transformCovers(covers, { scope });
416
493
  }
417
494
  transformCovers(covers, { scope }) {
418
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
495
+ var _a;
496
+ return ((_a = this.configs) == null ? void 0 : _a.transformCovers) ? this.configs.transformCovers(covers, {
419
497
  scope,
420
498
  document: this.flowDocument,
421
499
  variableEngine: this.variableEngine
422
500
  }) : covers;
423
501
  }
424
502
  transformDeps(deps, { scope }) {
425
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
503
+ var _a;
504
+ return ((_a = this.configs) == null ? void 0 : _a.transformDeps) ? this.configs.transformDeps(deps, {
426
505
  scope,
427
506
  document: this.flowDocument,
428
507
  variableEngine: this.variableEngine
@@ -430,13 +509,17 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
430
509
  }
431
510
  // 排序所有作用域
432
511
  sortAll() {
433
- const { startNodeId } = this.configs || {};
434
- const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
512
+ const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);
435
513
  if (!startNode) {
436
514
  return [];
437
515
  }
438
516
  const startVariableData = startNode.getData(FlowNodeVariableData);
439
- return [startVariableData.public, ...this.getCovers(startVariableData.public)];
517
+ const startPublicScope = startVariableData.public;
518
+ const deps = this.getDeps(startPublicScope);
519
+ const covers = this.getCovers(startPublicScope).filter(
520
+ (_scope) => !deps.includes(_scope) && _scope !== startPublicScope
521
+ );
522
+ return [...deps, startPublicScope, ...covers];
440
523
  }
441
524
  // 获取变量 Data 数据
442
525
  getVariableData(node) {
@@ -450,10 +533,11 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
450
533
  }
451
534
  // privateScope:子节点不可以被后续节点访问
452
535
  isNodeChildrenPrivate(node) {
453
- if (this.configs?.isNodeChildrenPrivate) {
454
- return node ? this.configs?.isNodeChildrenPrivate(node) : false;
536
+ var _a, _b;
537
+ if ((_a = this.configs) == null ? void 0 : _a.isNodeChildrenPrivate) {
538
+ return node ? (_b = this.configs) == null ? void 0 : _b.isNodeChildrenPrivate(node) : false;
455
539
  }
456
- const isSystemNode = node?.id.startsWith("$");
540
+ const isSystemNode = node == null ? void 0 : node.id.startsWith("$");
457
541
  return !isSystemNode && this.hasChildren(node);
458
542
  }
459
543
  hasChildren(node) {
@@ -464,6 +548,7 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
464
548
  ignoreNodeChildrenPrivate,
465
549
  addNodePrivateScope
466
550
  } = {}) {
551
+ var _a;
467
552
  const scopes = [];
468
553
  const variableData = this.getVariableData(node);
469
554
  if (variableData) {
@@ -472,10 +557,10 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
472
557
  if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {
473
558
  return scopes;
474
559
  }
475
- if (addNodePrivateScope && variableData?.private) {
560
+ if (addNodePrivateScope && (variableData == null ? void 0 : variableData.private)) {
476
561
  scopes.push(variableData.private);
477
562
  }
478
- const children = this.tree?.getChildren(node) || [];
563
+ const children = ((_a = this.tree) == null ? void 0 : _a.getChildren(node)) || [];
479
564
  scopes.push(
480
565
  ...children.map(
481
566
  (child) => this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })
@@ -494,6 +579,8 @@ export {
494
579
  FlowNodeScopeTypeEnum as FlowNodeScopeType,
495
580
  FlowNodeVariableData,
496
581
  FreeLayoutScopeChain,
497
- VariableLayoutConfig
582
+ GlobalScope,
583
+ VariableLayoutConfig,
584
+ bindGlobalScope
498
585
  };
499
586
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow-node-variable-data.ts","../../src/types.ts","../../src/free-layout-scope-chain.ts","../../src/variable-layout-config.ts","../../src/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 { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\nimport { WorkflowNodeLinesData, WorkflowNodeMeta } from '@flowgram.ai/free-layout-core';\n\nimport { VariableLayoutConfig } from './variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from './types';\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 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 return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n _node => _node.parent === curr.parent,\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n _node => _node.parent === curr.parent,\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformDeps([], { scope });\n }\n\n const scopes: 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 scopes.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 scopes.push(currVarData.private);\n }\n\n curr = this.getParent(curr);\n }\n\n const uniqScopes = Array.from(new Set(scopes));\n return this.transformDeps(uniqScopes, { scope });\n }\n\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.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.transformCovers(uniqScopes, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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 const initParent = node.document.originTree.getParent(node);\n\n if (!initParent) {\n return initParent;\n }\n\n const nodeMeta = initParent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(initParent);\n if (subCanvas?.isCanvas) {\n return subCanvas.parentNode;\n }\n\n return initParent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","import { Scope } from '@flowgram.ai/variable-core';\nimport { VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity, FlowDocument } from '@flowgram.ai/document';\n\nimport { type FlowNodeScope, type ScopeChainNode } from './types';\n\ninterface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\n\nexport interface VariableLayoutConfig {\n /**\n * 开始节点的节点 Id\n */\n startNodeId?: string;\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 * 对依赖作用域进行微调\n */\n transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\n /**\n * 对依赖作用域进行微调\n */\n transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\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 { 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 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.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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 return this.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformCovers([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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.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.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.transformCovers(covers, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\n }\n\n // 排序所有作用域\n sortAll(): Scope[] {\n const { startNodeId } = this.configs || {};\n\n const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : undefined;\n if (!startNode) {\n return [];\n }\n const startVariableData = startNode.getData(FlowNodeVariableData);\n\n return [startVariableData.public, ...this.getCovers(startVariableData.public)];\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,IAAI,IAAI,WAAW,IAAI;AAAA,IAC5C;AAEA,UAAM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,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,WACH,KAAK,uBAAuB,OAAO,EAAE,2BAA2B,oBAAoB,CAAC;AAAA,MACvF,EACC,KAAK;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;AA9Ra,wBAAN;AAAA,EAKF,mBAAAC,QAAOC,aAAY;AAAA,EAEnB,mBAAAC,UAAS;AAAA,EACT,mBAAAF,QAAO,oBAAoB;AAAA,GARnB;","names":["FlowNodeScopeTypeEnum","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/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 { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from '../types';\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 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 return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n (_node) => _node.parent === curr.parent\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n (_node) => _node.parent === curr.parent\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.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.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.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.transformCovers(uniqScopes, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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 const initParent = node.document.originTree.getParent(node);\n\n if (!initParent) {\n return initParent;\n }\n\n const nodeMeta = initParent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(initParent);\n if (subCanvas?.isCanvas) {\n return subCanvas.parentNode;\n }\n\n return initParent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","import { Scope } from '@flowgram.ai/variable-core';\nimport { VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity, FlowDocument } from '@flowgram.ai/document';\n\nimport { type FlowNodeScope, type ScopeChainNode } from './types';\n\ninterface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\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 * 对依赖作用域进行微调\n */\n transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\n /**\n * 对依赖作用域进行微调\n */\n transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\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 { 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 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.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.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.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.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.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.transformCovers(covers, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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,IAAI,IAAI,WAAW,IAAI;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wBAAN;AAAA,EAKF,mBAAAC,QAAOC,aAAY;AAAA,EAEnB,mBAAAC,UAAS;AAAA,EACT,mBAAAF,QAAO,oBAAoB;AAAA,GARnB;","names":["FlowNodeScopeTypeEnum","inject","optional","ScopeChain","FlowDocument","ScopeChain","inject","FlowDocument","optional"]}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Scope, VariableEngine, ASTNodeJSON, ASTNode, 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
 
5
6
  declare enum FlowNodeScopeTypeEnum {
6
7
  public = "public",
@@ -102,10 +103,6 @@ interface TransformerContext {
102
103
  variableEngine: VariableEngine;
103
104
  }
104
105
  interface VariableLayoutConfig {
105
- /**
106
- * 开始节点的节点 Id
107
- */
108
- startNodeId?: string;
109
106
  /**
110
107
  * 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
111
108
  * @param node
@@ -176,4 +173,39 @@ declare class FixedLayoutScopeChain extends ScopeChain {
176
173
  private getAllSortedChildScope;
177
174
  }
178
175
 
179
- export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
176
+ declare class GlobalScope extends Scope {
177
+ static readonly ID: unique symbol;
178
+ static is(scope: Scope): scope is GlobalScope;
179
+ /**
180
+ * Sets a variable in the Global Scope with the given key and JSON value.
181
+ *
182
+ * @param key - The key under which the variable will be stored.
183
+ * @param json - The JSON value to store.
184
+ * @returns The updated AST node.
185
+ */
186
+ setVar(key: string, json: ASTNodeJSON): ASTNode;
187
+ /**
188
+ * Sets a variable in the Global Scope with the default key 'outputs'.
189
+ *
190
+ * @param json - The JSON value to store.
191
+ * @returns The updated AST node.
192
+ */
193
+ setVar(json: ASTNodeJSON): ASTNode;
194
+ /**
195
+ * Retrieves a variable from the Global Scope by key.
196
+ *
197
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
198
+ * @returns The value of the variable, or undefined if not found.
199
+ */
200
+ getVar(key?: string): ASTNode<any, any> | undefined;
201
+ /**
202
+ * Clears a variable from the Global Scope by key.
203
+ *
204
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
205
+ * @returns The updated AST node.
206
+ */
207
+ clearVar(key?: string): void;
208
+ }
209
+ declare const bindGlobalScope: (bind: interfaces.Bind) => void;
210
+
211
+ export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, GlobalScope, VariableLayoutConfig, bindGlobalScope };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Scope, VariableEngine, ASTNodeJSON, ASTNode, 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
 
5
6
  declare enum FlowNodeScopeTypeEnum {
6
7
  public = "public",
@@ -102,10 +103,6 @@ interface TransformerContext {
102
103
  variableEngine: VariableEngine;
103
104
  }
104
105
  interface VariableLayoutConfig {
105
- /**
106
- * 开始节点的节点 Id
107
- */
108
- startNodeId?: string;
109
106
  /**
110
107
  * 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
111
108
  * @param node
@@ -176,4 +173,39 @@ declare class FixedLayoutScopeChain extends ScopeChain {
176
173
  private getAllSortedChildScope;
177
174
  }
178
175
 
179
- export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
176
+ declare class GlobalScope extends Scope {
177
+ static readonly ID: unique symbol;
178
+ static is(scope: Scope): scope is GlobalScope;
179
+ /**
180
+ * Sets a variable in the Global Scope with the given key and JSON value.
181
+ *
182
+ * @param key - The key under which the variable will be stored.
183
+ * @param json - The JSON value to store.
184
+ * @returns The updated AST node.
185
+ */
186
+ setVar(key: string, json: ASTNodeJSON): ASTNode;
187
+ /**
188
+ * Sets a variable in the Global Scope with the default key 'outputs'.
189
+ *
190
+ * @param json - The JSON value to store.
191
+ * @returns The updated AST node.
192
+ */
193
+ setVar(json: ASTNodeJSON): ASTNode;
194
+ /**
195
+ * Retrieves a variable from the Global Scope by key.
196
+ *
197
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
198
+ * @returns The value of the variable, or undefined if not found.
199
+ */
200
+ getVar(key?: string): ASTNode<any, any> | undefined;
201
+ /**
202
+ * Clears a variable from the Global Scope by key.
203
+ *
204
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
205
+ * @returns The updated AST node.
206
+ */
207
+ clearVar(key?: string): void;
208
+ }
209
+ declare const bindGlobalScope: (bind: interfaces.Bind) => void;
210
+
211
+ export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, GlobalScope, VariableLayoutConfig, bindGlobalScope };
package/dist/index.js CHANGED
@@ -33,7 +33,9 @@ __export(src_exports, {
33
33
  FlowNodeScopeType: () => FlowNodeScopeTypeEnum,
34
34
  FlowNodeVariableData: () => FlowNodeVariableData,
35
35
  FreeLayoutScopeChain: () => FreeLayoutScopeChain,
36
- VariableLayoutConfig: () => VariableLayoutConfig
36
+ GlobalScope: () => GlobalScope,
37
+ VariableLayoutConfig: () => VariableLayoutConfig,
38
+ bindGlobalScope: () => bindGlobalScope
37
39
  });
38
40
  module.exports = __toCommonJS(src_exports);
39
41
 
@@ -109,7 +111,8 @@ var FlowNodeVariableData = class extends import_core.EntityData {
109
111
  * @returns The value of the variable, or undefined if not found.
110
112
  */
111
113
  getPrivateVar(key = "outputs") {
112
- return this.private?.ast.get(key);
114
+ var _a;
115
+ return (_a = this.private) == null ? void 0 : _a.ast.get(key);
113
116
  }
114
117
  /**
115
118
  * Clears a variable from the private AST (Abstract Syntax Tree) by key.
@@ -118,7 +121,8 @@ var FlowNodeVariableData = class extends import_core.EntityData {
118
121
  * @returns The updated AST node.
119
122
  */
120
123
  clearPrivateVar(key = "outputs") {
121
- return this.private?.ast.remove(key);
124
+ var _a;
125
+ return (_a = this.private) == null ? void 0 : _a.ast.remove(key);
122
126
  }
123
127
  get allScopes() {
124
128
  const res = [];
@@ -153,18 +157,73 @@ var FlowNodeVariableData = class extends import_core.EntityData {
153
157
  };
154
158
  FlowNodeVariableData.type = "FlowNodeVariableData";
155
159
 
156
- // src/free-layout-scope-chain.ts
157
- var import_inversify = require("inversify");
158
- var import_variable_core = require("@flowgram.ai/variable-core");
160
+ // src/chains/free-layout-scope-chain.ts
161
+ var import_inversify2 = require("inversify");
162
+ var import_variable_core2 = require("@flowgram.ai/variable-core");
163
+ var import_free_layout_core = require("@flowgram.ai/free-layout-core");
159
164
  var import_document = require("@flowgram.ai/document");
160
165
  var import_core2 = require("@flowgram.ai/core");
161
- var import_free_layout_core = require("@flowgram.ai/free-layout-core");
162
166
 
163
167
  // src/variable-layout-config.ts
164
168
  var VariableLayoutConfig = Symbol("VariableLayoutConfig");
165
169
 
166
- // src/free-layout-scope-chain.ts
167
- var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
170
+ // src/scopes/global-scope.ts
171
+ var import_inversify = require("inversify");
172
+ var import_variable_core = require("@flowgram.ai/variable-core");
173
+ var GlobalScope = class extends import_variable_core.Scope {
174
+ static is(scope) {
175
+ return scope.id === GlobalScope.ID;
176
+ }
177
+ setVar(arg1, arg2) {
178
+ if (typeof arg1 === "string" && arg2 !== void 0) {
179
+ return this.ast.set(arg1, arg2);
180
+ }
181
+ if (typeof arg1 === "object" && arg2 === void 0) {
182
+ return this.ast.set("outputs", arg1);
183
+ }
184
+ throw new Error("Invalid arguments");
185
+ }
186
+ /**
187
+ * Retrieves a variable from the Global Scope by key.
188
+ *
189
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
190
+ * @returns The value of the variable, or undefined if not found.
191
+ */
192
+ getVar(key = "outputs") {
193
+ return this.ast.get(key);
194
+ }
195
+ /**
196
+ * Clears a variable from the Global Scope by key.
197
+ *
198
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
199
+ * @returns The updated AST node.
200
+ */
201
+ clearVar(key = "outputs") {
202
+ return this.ast.remove(key);
203
+ }
204
+ };
205
+ GlobalScope.ID = Symbol("GlobalScope");
206
+ GlobalScope = __decorateClass([
207
+ (0, import_inversify.injectable)()
208
+ ], GlobalScope);
209
+ var bindGlobalScope = (bind) => {
210
+ bind(GlobalScope).toDynamicValue((ctx) => {
211
+ const variableEngine = ctx.container.get(import_variable_core.VariableEngine);
212
+ let scope = variableEngine.getScopeById(GlobalScope.ID);
213
+ if (!scope) {
214
+ scope = variableEngine.createScope(
215
+ GlobalScope.ID,
216
+ {},
217
+ { ScopeConstructor: GlobalScope }
218
+ );
219
+ variableEngine.chain.refreshAllChange();
220
+ }
221
+ return scope;
222
+ });
223
+ };
224
+
225
+ // src/chains/free-layout-scope-chain.ts
226
+ var FreeLayoutScopeChain = class extends import_variable_core2.ScopeChain {
168
227
  get tree() {
169
228
  return this.flowDocument.originTree;
170
229
  }
@@ -184,13 +243,15 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
184
243
  }
185
244
  // 获取同一层级所有输入节点
186
245
  getAllInputLayerNodes(curr) {
187
- return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allInputNodes || []).filter(
246
+ var _a;
247
+ return (((_a = curr.getData(import_free_layout_core.WorkflowNodeLinesData)) == null ? void 0 : _a.allInputNodes) || []).filter(
188
248
  (_node) => _node.parent === curr.parent
189
249
  );
190
250
  }
191
251
  // 获取同一层级所有输出节点
192
252
  getAllOutputLayerNodes(curr) {
193
- return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allOutputNodes || []).filter(
253
+ var _a;
254
+ return (((_a = curr.getData(import_free_layout_core.WorkflowNodeLinesData)) == null ? void 0 : _a.allOutputNodes) || []).filter(
194
255
  (_node) => _node.parent === curr.parent
195
256
  );
196
257
  }
@@ -199,23 +260,30 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
199
260
  if (!node) {
200
261
  return this.transformDeps([], { scope });
201
262
  }
202
- const scopes = [];
263
+ const deps = [];
203
264
  let curr = node;
204
265
  while (curr) {
205
266
  const allInputNodes = this.getAllInputLayerNodes(curr);
206
- scopes.push(
267
+ deps.push(
207
268
  ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
208
269
  );
209
270
  const currVarData = curr.getData(FlowNodeVariableData);
210
- if (currVarData?.private && scope !== currVarData.private) {
211
- scopes.push(currVarData.private);
271
+ if ((currVarData == null ? void 0 : currVarData.private) && scope !== currVarData.private) {
272
+ deps.push(currVarData.private);
212
273
  }
213
274
  curr = this.getParent(curr);
214
275
  }
215
- const uniqScopes = Array.from(new Set(scopes));
216
- return this.transformDeps(uniqScopes, { scope });
276
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
277
+ if (globalScope) {
278
+ deps.unshift(globalScope);
279
+ }
280
+ const uniqDeps = Array.from(new Set(deps));
281
+ return this.transformDeps(uniqDeps, { scope });
217
282
  }
218
283
  getCovers(scope) {
284
+ if (GlobalScope.is(scope)) {
285
+ return this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
286
+ }
219
287
  const { node } = scope.meta || {};
220
288
  if (!node) {
221
289
  return this.transformCovers([], { scope });
@@ -233,7 +301,7 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
233
301
  const variableData = _node.getData(FlowNodeVariableData);
234
302
  scopes.push(...variableData.allScopes);
235
303
  const children = _node && this.getChildren(_node);
236
- if (children?.length) {
304
+ if (children == null ? void 0 : children.length) {
237
305
  queue.push(...children);
238
306
  }
239
307
  }
@@ -245,25 +313,28 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
245
313
  return this.transformCovers(uniqScopes, { scope });
246
314
  }
247
315
  transformCovers(covers, { scope }) {
248
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
316
+ var _a;
317
+ return ((_a = this.configs) == null ? void 0 : _a.transformCovers) ? this.configs.transformCovers(covers, {
249
318
  scope,
250
319
  document: this.flowDocument,
251
320
  variableEngine: this.variableEngine
252
321
  }) : covers;
253
322
  }
254
323
  transformDeps(deps, { scope }) {
255
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
324
+ var _a;
325
+ return ((_a = this.configs) == null ? void 0 : _a.transformDeps) ? this.configs.transformDeps(deps, {
256
326
  scope,
257
327
  document: this.flowDocument,
258
328
  variableEngine: this.variableEngine
259
329
  }) : deps;
260
330
  }
261
331
  getChildren(node) {
262
- if (this.configs?.getFreeChildren) {
263
- return this.configs.getFreeChildren?.(node);
332
+ var _a, _b, _c, _d;
333
+ if ((_a = this.configs) == null ? void 0 : _a.getFreeChildren) {
334
+ return (_c = (_b = this.configs).getFreeChildren) == null ? void 0 : _c.call(_b, node);
264
335
  }
265
336
  const nodeMeta = node.getNodeMeta();
266
- const subCanvas = nodeMeta.subCanvas?.(node);
337
+ const subCanvas = (_d = nodeMeta.subCanvas) == null ? void 0 : _d.call(nodeMeta, node);
267
338
  if (subCanvas) {
268
339
  if (subCanvas.isCanvas) {
269
340
  return [];
@@ -274,7 +345,8 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
274
345
  return this.tree.getChildren(node);
275
346
  }
276
347
  getParent(node) {
277
- if (this.configs?.getFreeParent) {
348
+ var _a, _b;
349
+ if ((_a = this.configs) == null ? void 0 : _a.getFreeParent) {
278
350
  return this.configs.getFreeParent(node);
279
351
  }
280
352
  const initParent = node.document.originTree.getParent(node);
@@ -282,8 +354,8 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
282
354
  return initParent;
283
355
  }
284
356
  const nodeMeta = initParent.getNodeMeta();
285
- const subCanvas = nodeMeta.subCanvas?.(initParent);
286
- if (subCanvas?.isCanvas) {
357
+ const subCanvas = (_b = nodeMeta.subCanvas) == null ? void 0 : _b.call(nodeMeta, initParent);
358
+ if (subCanvas == null ? void 0 : subCanvas.isCanvas) {
287
359
  return subCanvas.parentNode;
288
360
  }
289
361
  return initParent;
@@ -294,24 +366,24 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
294
366
  }
295
367
  };
296
368
  __decorateClass([
297
- (0, import_inversify.inject)(import_core2.EntityManager)
369
+ (0, import_inversify2.inject)(import_core2.EntityManager)
298
370
  ], FreeLayoutScopeChain.prototype, "entityManager", 2);
299
371
  __decorateClass([
300
- (0, import_inversify.inject)(import_document.FlowDocument)
372
+ (0, import_inversify2.inject)(import_document.FlowDocument)
301
373
  ], FreeLayoutScopeChain.prototype, "flowDocument", 2);
302
374
  __decorateClass([
303
- (0, import_inversify.optional)(),
304
- (0, import_inversify.inject)(VariableLayoutConfig)
375
+ (0, import_inversify2.optional)(),
376
+ (0, import_inversify2.inject)(VariableLayoutConfig)
305
377
  ], FreeLayoutScopeChain.prototype, "configs", 2);
306
378
  __decorateClass([
307
- (0, import_inversify.postConstruct)()
379
+ (0, import_inversify2.postConstruct)()
308
380
  ], FreeLayoutScopeChain.prototype, "onInit", 1);
309
381
 
310
- // src/fixed-layout-scope-chain.ts
311
- var import_inversify2 = require("inversify");
312
- var import_variable_core2 = require("@flowgram.ai/variable-core");
382
+ // src/chains/fixed-layout-scope-chain.ts
383
+ var import_inversify3 = require("inversify");
384
+ var import_variable_core3 = require("@flowgram.ai/variable-core");
313
385
  var import_document2 = require("@flowgram.ai/document");
314
- var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
386
+ var FixedLayoutScopeChain = class extends import_variable_core3.ScopeChain {
315
387
  constructor(flowDocument, configs) {
316
388
  super();
317
389
  this.flowDocument = flowDocument;
@@ -343,7 +415,7 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
343
415
  const { parent, pre } = this.tree.getInfo(curr);
344
416
  const currData = this.getVariableData(curr);
345
417
  if (curr === node) {
346
- if (scope.meta.type === "public" /* public */ && currData?.private) {
418
+ if (scope.meta.type === "public" /* public */ && (currData == null ? void 0 : currData.private)) {
347
419
  deps.unshift(currData.private);
348
420
  }
349
421
  } else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {
@@ -379,6 +451,10 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
379
451
  }
380
452
  curr = void 0;
381
453
  }
454
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
455
+ if (globalScope) {
456
+ deps.unshift(globalScope);
457
+ }
382
458
  return this.transformDeps(deps, { scope });
383
459
  }
384
460
  // 获取覆盖作用域
@@ -386,6 +462,9 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
386
462
  if (!this.tree) {
387
463
  return this.transformCovers([], { scope });
388
464
  }
465
+ if (GlobalScope.is(scope)) {
466
+ return this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
467
+ }
389
468
  const node = scope.meta.node;
390
469
  if (!node) {
391
470
  return this.transformCovers([], { scope });
@@ -442,14 +521,16 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
442
521
  return this.transformCovers(covers, { scope });
443
522
  }
444
523
  transformCovers(covers, { scope }) {
445
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
524
+ var _a;
525
+ return ((_a = this.configs) == null ? void 0 : _a.transformCovers) ? this.configs.transformCovers(covers, {
446
526
  scope,
447
527
  document: this.flowDocument,
448
528
  variableEngine: this.variableEngine
449
529
  }) : covers;
450
530
  }
451
531
  transformDeps(deps, { scope }) {
452
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
532
+ var _a;
533
+ return ((_a = this.configs) == null ? void 0 : _a.transformDeps) ? this.configs.transformDeps(deps, {
453
534
  scope,
454
535
  document: this.flowDocument,
455
536
  variableEngine: this.variableEngine
@@ -457,13 +538,17 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
457
538
  }
458
539
  // 排序所有作用域
459
540
  sortAll() {
460
- const { startNodeId } = this.configs || {};
461
- const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
541
+ const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);
462
542
  if (!startNode) {
463
543
  return [];
464
544
  }
465
545
  const startVariableData = startNode.getData(FlowNodeVariableData);
466
- return [startVariableData.public, ...this.getCovers(startVariableData.public)];
546
+ const startPublicScope = startVariableData.public;
547
+ const deps = this.getDeps(startPublicScope);
548
+ const covers = this.getCovers(startPublicScope).filter(
549
+ (_scope) => !deps.includes(_scope) && _scope !== startPublicScope
550
+ );
551
+ return [...deps, startPublicScope, ...covers];
467
552
  }
468
553
  // 获取变量 Data 数据
469
554
  getVariableData(node) {
@@ -477,10 +562,11 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
477
562
  }
478
563
  // privateScope:子节点不可以被后续节点访问
479
564
  isNodeChildrenPrivate(node) {
480
- if (this.configs?.isNodeChildrenPrivate) {
481
- return node ? this.configs?.isNodeChildrenPrivate(node) : false;
565
+ var _a, _b;
566
+ if ((_a = this.configs) == null ? void 0 : _a.isNodeChildrenPrivate) {
567
+ return node ? (_b = this.configs) == null ? void 0 : _b.isNodeChildrenPrivate(node) : false;
482
568
  }
483
- const isSystemNode = node?.id.startsWith("$");
569
+ const isSystemNode = node == null ? void 0 : node.id.startsWith("$");
484
570
  return !isSystemNode && this.hasChildren(node);
485
571
  }
486
572
  hasChildren(node) {
@@ -491,6 +577,7 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
491
577
  ignoreNodeChildrenPrivate,
492
578
  addNodePrivateScope
493
579
  } = {}) {
580
+ var _a;
494
581
  const scopes = [];
495
582
  const variableData = this.getVariableData(node);
496
583
  if (variableData) {
@@ -499,10 +586,10 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
499
586
  if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {
500
587
  return scopes;
501
588
  }
502
- if (addNodePrivateScope && variableData?.private) {
589
+ if (addNodePrivateScope && (variableData == null ? void 0 : variableData.private)) {
503
590
  scopes.push(variableData.private);
504
591
  }
505
- const children = this.tree?.getChildren(node) || [];
592
+ const children = ((_a = this.tree) == null ? void 0 : _a.getChildren(node)) || [];
506
593
  scopes.push(
507
594
  ...children.map(
508
595
  (child) => this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })
@@ -512,9 +599,9 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
512
599
  }
513
600
  };
514
601
  FixedLayoutScopeChain = __decorateClass([
515
- __decorateParam(0, (0, import_inversify2.inject)(import_document2.FlowDocument)),
516
- __decorateParam(1, (0, import_inversify2.optional)()),
517
- __decorateParam(1, (0, import_inversify2.inject)(VariableLayoutConfig))
602
+ __decorateParam(0, (0, import_inversify3.inject)(import_document2.FlowDocument)),
603
+ __decorateParam(1, (0, import_inversify3.optional)()),
604
+ __decorateParam(1, (0, import_inversify3.inject)(VariableLayoutConfig))
518
605
  ], FixedLayoutScopeChain);
519
606
  // Annotate the CommonJS export names for ESM import in node:
520
607
  0 && (module.exports = {
@@ -522,6 +609,8 @@ FixedLayoutScopeChain = __decorateClass([
522
609
  FlowNodeScopeType,
523
610
  FlowNodeVariableData,
524
611
  FreeLayoutScopeChain,
525
- VariableLayoutConfig
612
+ GlobalScope,
613
+ VariableLayoutConfig,
614
+ bindGlobalScope
526
615
  });
527
616
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/flow-node-variable-data.ts","../src/types.ts","../src/free-layout-scope-chain.ts","../src/variable-layout-config.ts","../src/fixed-layout-scope-chain.ts"],"sourcesContent":["export { FlowNodeVariableData } from './flow-node-variable-data';\nexport { FreeLayoutScopeChain } from './free-layout-scope-chain';\nexport { VariableLayoutConfig } from './variable-layout-config';\nexport { FixedLayoutScopeChain } from './fixed-layout-scope-chain';\nexport {\n type FlowNodeScopeMeta,\n type FlowNodeScope,\n FlowNodeScopeTypeEnum as FlowNodeScopeType,\n} from './types';\n","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 { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\nimport { WorkflowNodeLinesData, WorkflowNodeMeta } from '@flowgram.ai/free-layout-core';\n\nimport { VariableLayoutConfig } from './variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from './types';\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 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 return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n _node => _node.parent === curr.parent,\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n _node => _node.parent === curr.parent,\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.transformDeps([], { scope });\n }\n\n const scopes: 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 scopes.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 scopes.push(currVarData.private);\n }\n\n curr = this.getParent(curr);\n }\n\n const uniqScopes = Array.from(new Set(scopes));\n return this.transformDeps(uniqScopes, { scope });\n }\n\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.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.transformCovers(uniqScopes, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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 const initParent = node.document.originTree.getParent(node);\n\n if (!initParent) {\n return initParent;\n }\n\n const nodeMeta = initParent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(initParent);\n if (subCanvas?.isCanvas) {\n return subCanvas.parentNode;\n }\n\n return initParent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","import { Scope } from '@flowgram.ai/variable-core';\nimport { VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity, FlowDocument } from '@flowgram.ai/document';\n\nimport { type FlowNodeScope, type ScopeChainNode } from './types';\n\ninterface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\n\nexport interface VariableLayoutConfig {\n /**\n * 开始节点的节点 Id\n */\n startNodeId?: string;\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 * 对依赖作用域进行微调\n */\n transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\n /**\n * 对依赖作用域进行微调\n */\n transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\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 { 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 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.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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 return this.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.transformCovers([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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.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.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.transformCovers(covers, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\n }\n\n // 排序所有作用域\n sortAll(): Scope[] {\n const { startNodeId } = this.configs || {};\n\n const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : undefined;\n if (!startNode) {\n return [];\n }\n const startVariableData = startNode.getData(FlowNodeVariableData);\n\n return [startVariableData.public, ...this.getCovers(startVariableData.public)];\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,kBAA2B;;;ACApB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,YAAS;AACT,EAAAA,uBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;;;ADQL,IAAM,uBAAN,cAAmC,uBAAW;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,WAA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,MAAgC;AAClD,WAAO,QAAQ,KAAK,QAAQ,QAAQ,KAAK,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,WACH,KAAK,uBAAuB,OAAO,EAAE,2BAA2B,oBAAoB,CAAC;AAAA,MACvF,EACC,KAAK;AAAA,IACV;AAEA,WAAO;AAAA,EACT;AACF;AA9Ra,wBAAN;AAAA,EAKF,iDAAO,6BAAY;AAAA,EAEnB,mDAAS;AAAA,EACT,iDAAO,oBAAoB;AAAA,GARnB;","names":["FlowNodeScopeTypeEnum","import_core","import_inversify","import_variable_core","import_document"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/flow-node-variable-data.ts","../src/types.ts","../src/chains/free-layout-scope-chain.ts","../src/variable-layout-config.ts","../src/scopes/global-scope.ts","../src/chains/fixed-layout-scope-chain.ts"],"sourcesContent":["export { FlowNodeVariableData } from './flow-node-variable-data';\nexport { FreeLayoutScopeChain } from './chains/free-layout-scope-chain';\nexport { VariableLayoutConfig } from './variable-layout-config';\nexport { FixedLayoutScopeChain } from './chains/fixed-layout-scope-chain';\nexport {\n type FlowNodeScopeMeta,\n type FlowNodeScope,\n FlowNodeScopeTypeEnum as FlowNodeScopeType,\n} from './types';\nexport { GlobalScope, bindGlobalScope } from './scopes/global-scope';\n","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 { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { VariableLayoutConfig } from '../variable-layout-config';\nimport { FlowNodeScope, FlowNodeScopeTypeEnum } from '../types';\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 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 return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(\n (_node) => _node.parent === curr.parent\n );\n }\n\n // 获取同一层级所有输出节点\n protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[] {\n return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(\n (_node) => _node.parent === curr.parent\n );\n }\n\n getDeps(scope: FlowNodeScope): FlowNodeScope[] {\n const { node } = scope.meta || {};\n if (!node) {\n return this.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.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.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.transformCovers(uniqScopes, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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 const initParent = node.document.originTree.getParent(node);\n\n if (!initParent) {\n return initParent;\n }\n\n const nodeMeta = initParent.getNodeMeta<WorkflowNodeMeta>();\n const subCanvas = nodeMeta.subCanvas?.(initParent);\n if (subCanvas?.isCanvas) {\n return subCanvas.parentNode;\n }\n\n return initParent;\n }\n\n sortAll(): Scope[] {\n // 暂未实现\n console.warn('FreeLayoutScopeChain.sortAll is not implemented');\n return [];\n }\n}\n","import { Scope } from '@flowgram.ai/variable-core';\nimport { VariableEngine } from '@flowgram.ai/variable-core';\nimport { FlowNodeEntity, FlowDocument } from '@flowgram.ai/document';\n\nimport { type FlowNodeScope, type ScopeChainNode } from './types';\n\ninterface TransformerContext {\n scope: FlowNodeScope;\n document: FlowDocument;\n variableEngine: VariableEngine;\n}\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 * 对依赖作用域进行微调\n */\n transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n\n /**\n * 对依赖作用域进行微调\n */\n transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];\n}\n\nexport const VariableLayoutConfig = Symbol('VariableLayoutConfig');\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 { 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 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.transformDeps([], { scope });\n }\n\n const node = scope.meta.node;\n if (!node) {\n return this.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.transformDeps(deps, { scope });\n }\n\n // 获取覆盖作用域\n getCovers(scope: FlowNodeScope): FlowNodeScope[] {\n if (!this.tree) {\n return this.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.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.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.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.transformCovers(covers, { scope });\n }\n\n protected transformCovers(covers: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformCovers\n ? this.configs.transformCovers(covers, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : covers;\n }\n\n protected transformDeps(deps: Scope[], { scope }: { scope: Scope }): Scope[] {\n return this.configs?.transformDeps\n ? this.configs.transformDeps(deps, {\n scope,\n document: this.flowDocument,\n variableEngine: this.variableEngine,\n })\n : deps;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,kBAA2B;;;ACApB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,YAAS;AACT,EAAAA,uBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;;;ADQL,IAAM,uBAAN,cAAmC,uBAAW;AAAA,EAyInD,YAAY,QAAiC,MAAe;AAC1D,UAAM,MAAM;AAD+B;AAG3C,UAAM,EAAE,eAAe,IAAI,QAAQ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AAgB,IAAI;AAE9C,QAAI,cAAc;AAChB,aAAO,KAAK,aAAa,MAAM;AAAA,IACjC;AAIA,QAAI,6BAA6B,KAAK,sBAAsB,IAAI,GAAG;AACjE,aAAO;AAAA,IACT;AAEA,QAAI,wBAAuB,6CAAc,UAAS;AAChD,aAAO,KAAK,aAAa,OAAO;AAAA,IAClC;AAEA,UAAM,aAAW,UAAK,SAAL,mBAAW,YAAY,UAAS,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;AAhTa,wBAAN;AAAA,EAKF,iDAAO,6BAAY;AAAA,EAEnB,mDAAS;AAAA,EACT,iDAAO,oBAAoB;AAAA,GARnB;","names":["FlowNodeScopeTypeEnum","import_inversify","import_variable_core","import_core","import_inversify","import_variable_core","import_document"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowgram.ai/variable-layout",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "homepage": "https://flowgram.ai/",
5
5
  "repository": "https://github.com/bytedance/flowgram.ai",
6
6
  "license": "MIT",
@@ -19,11 +19,11 @@
19
19
  "inversify": "^6.0.1",
20
20
  "reflect-metadata": "~0.2.2",
21
21
  "styled-components": "^5",
22
- "@flowgram.ai/document": "0.1.0-alpha.7",
23
- "@flowgram.ai/core": "0.1.0-alpha.7",
24
- "@flowgram.ai/free-layout-core": "0.1.0-alpha.7",
25
- "@flowgram.ai/utils": "0.1.0-alpha.7",
26
- "@flowgram.ai/variable-core": "0.1.0-alpha.7"
22
+ "@flowgram.ai/core": "0.1.0-alpha.8",
23
+ "@flowgram.ai/document": "0.1.0-alpha.8",
24
+ "@flowgram.ai/free-layout-core": "0.1.0-alpha.8",
25
+ "@flowgram.ai/utils": "0.1.0-alpha.8",
26
+ "@flowgram.ai/variable-core": "0.1.0-alpha.8"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@vitest/coverage-v8": "^0.32.0",
@@ -31,8 +31,8 @@
31
31
  "tsup": "^8.0.1",
32
32
  "typescript": "^5.0.4",
33
33
  "vitest": "^0.34.6",
34
- "@flowgram.ai/eslint-config": "0.1.0-alpha.7",
35
- "@flowgram.ai/ts-config": "0.1.0-alpha.7"
34
+ "@flowgram.ai/ts-config": "0.1.0-alpha.8",
35
+ "@flowgram.ai/eslint-config": "0.1.0-alpha.8"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public",