@flowgram.ai/variable-layout 0.1.0-alpha.2 → 0.1.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -27,15 +27,20 @@ var __decorateClass = (decorators, target, key, kind) => {
27
27
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
28
 
29
29
  // src/index.ts
30
- var src_exports = {};
31
- __export(src_exports, {
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
32
  FixedLayoutScopeChain: () => FixedLayoutScopeChain,
33
33
  FlowNodeScopeType: () => FlowNodeScopeTypeEnum,
34
34
  FlowNodeVariableData: () => FlowNodeVariableData,
35
35
  FreeLayoutScopeChain: () => FreeLayoutScopeChain,
36
- VariableLayoutConfig: () => VariableLayoutConfig
36
+ GlobalScope: () => GlobalScope,
37
+ ScopeChainTransformService: () => ScopeChainTransformService,
38
+ VariableChainConfig: () => VariableChainConfig,
39
+ bindGlobalScope: () => bindGlobalScope,
40
+ getNodePrivateScope: () => getNodePrivateScope,
41
+ getNodeScope: () => getNodeScope
37
42
  });
38
- module.exports = __toCommonJS(src_exports);
43
+ module.exports = __toCommonJS(index_exports);
39
44
 
40
45
  // src/flow-node-variable-data.ts
41
46
  var import_core = require("@flowgram.ai/core");
@@ -60,9 +65,15 @@ var FlowNodeVariableData = class extends import_core.EntityData {
60
65
  });
61
66
  this.toDispose.push(this._public);
62
67
  }
68
+ /**
69
+ * The private scope of the node.
70
+ */
63
71
  get private() {
64
72
  return this._private;
65
73
  }
74
+ /**
75
+ * The public scope of the node.
76
+ */
66
77
  get public() {
67
78
  return this._public;
68
79
  }
@@ -120,6 +131,9 @@ var FlowNodeVariableData = class extends import_core.EntityData {
120
131
  clearPrivateVar(key = "outputs") {
121
132
  return this.private?.ast.remove(key);
122
133
  }
134
+ /**
135
+ * An array containing all scopes (public and private) of the node.
136
+ */
123
137
  get allScopes() {
124
138
  const res = [];
125
139
  if (this._public) {
@@ -133,106 +147,293 @@ var FlowNodeVariableData = class extends import_core.EntityData {
133
147
  getDefaultData() {
134
148
  return {};
135
149
  }
150
+ /**
151
+ * Initializes and returns the private scope for the node.
152
+ * If the private scope already exists, it returns the existing one.
153
+ * @returns The private scope of the node.
154
+ */
136
155
  initPrivate() {
137
156
  if (!this._private) {
138
157
  this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {
139
158
  node: this.entity,
140
159
  type: "private" /* private */
141
160
  });
142
- this._private.coverScopes.forEach((_scope) => {
143
- _scope.refreshDeps();
144
- });
145
- this._private.depScopes.forEach((_scope) => {
146
- _scope.refreshCovers();
147
- });
148
- this._private.available.refresh();
161
+ this.variableEngine.chain.refreshAllChange();
149
162
  this.toDispose.push(this._private);
150
163
  }
151
164
  return this._private;
152
165
  }
166
+ /**
167
+ * Find a variable field by key path in the public scope by scope chain.
168
+ * @param keyPath - The key path of the variable field.
169
+ * @returns The variable field, or undefined if not found.
170
+ */
171
+ getByKeyPath(keyPath) {
172
+ return this.public.available.getByKeyPath(keyPath);
173
+ }
174
+ /**
175
+ * Find a variable field by key path in the private scope by scope chain.
176
+ * @param keyPath - The key path of the variable field.
177
+ * @returns The variable field, or undefined if not found.
178
+ */
179
+ getByKeyPathInPrivate(keyPath) {
180
+ return this.private?.available.getByKeyPath(keyPath);
181
+ }
153
182
  };
154
183
  FlowNodeVariableData.type = "FlowNodeVariableData";
155
184
 
156
- // src/free-layout-scope-chain.ts
185
+ // src/chains/free-layout-scope-chain.ts
186
+ var import_inversify3 = require("inversify");
187
+ var import_variable_core3 = require("@flowgram.ai/variable-core");
188
+ var import_free_layout_core = require("@flowgram.ai/free-layout-core");
189
+ var import_document2 = require("@flowgram.ai/document");
190
+ var import_core3 = require("@flowgram.ai/core");
191
+
192
+ // src/variable-chain-config.ts
193
+ var VariableChainConfig = Symbol("VariableChainConfig");
194
+
195
+ // src/services/scope-chain-transform-service.ts
157
196
  var import_inversify = require("inversify");
158
197
  var import_variable_core = require("@flowgram.ai/variable-core");
159
198
  var import_document = require("@flowgram.ai/document");
160
199
  var import_core2 = require("@flowgram.ai/core");
161
- var import_free_layout_core = require("@flowgram.ai/free-layout-core");
200
+ var passthrough = (scopes, ctx) => scopes;
201
+ var ScopeChainTransformService = class {
202
+ constructor(configs) {
203
+ this.configs = configs;
204
+ this.transformerMap = /* @__PURE__ */ new Map();
205
+ if (this.configs?.transformDeps || this.configs?.transformCovers) {
206
+ this.transformerMap.set("VARIABLE_LAYOUT_CONFIG", {
207
+ transformDeps: this.configs.transformDeps || passthrough,
208
+ transformCovers: this.configs.transformCovers || passthrough
209
+ });
210
+ }
211
+ }
212
+ /**
213
+ * check if transformer registered
214
+ * @param transformerId used to identify transformer, prevent duplicated
215
+ * @returns
216
+ */
217
+ hasTransformer(transformerId) {
218
+ return this.transformerMap.has(transformerId);
219
+ }
220
+ /**
221
+ * register new transform function
222
+ * @param transformerId used to identify transformer, prevent duplicated transformer
223
+ * @param transformer The transformer to register.
224
+ */
225
+ registerTransformer(transformerId, transformer) {
226
+ this.transformerMap.set(transformerId, transformer);
227
+ }
228
+ /**
229
+ * Transforms the dependency scopes.
230
+ * @param scopes The array of scopes to transform.
231
+ * @param param1 The context for the transformation.
232
+ * @returns The transformed array of scopes.
233
+ */
234
+ transformDeps(scopes, { scope }) {
235
+ return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
236
+ if (!transformer.transformDeps) {
237
+ return scopes2;
238
+ }
239
+ scopes2 = transformer.transformDeps(scopes2, {
240
+ scope,
241
+ document: this.document,
242
+ variableEngine: this.variableEngine
243
+ });
244
+ return scopes2;
245
+ }, scopes);
246
+ }
247
+ /**
248
+ * Transforms the cover scopes.
249
+ * @param scopes The array of scopes to transform.
250
+ * @param param1 The context for the transformation.
251
+ * @returns The transformed array of scopes.
252
+ */
253
+ transformCovers(scopes, { scope }) {
254
+ return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
255
+ if (!transformer.transformCovers) {
256
+ return scopes2;
257
+ }
258
+ scopes2 = transformer.transformCovers(scopes2, {
259
+ scope,
260
+ document: this.document,
261
+ variableEngine: this.variableEngine
262
+ });
263
+ return scopes2;
264
+ }, scopes);
265
+ }
266
+ };
267
+ __decorateClass([
268
+ (0, import_core2.lazyInject)(import_document.FlowDocument)
269
+ ], ScopeChainTransformService.prototype, "document", 2);
270
+ __decorateClass([
271
+ (0, import_core2.lazyInject)(import_variable_core.VariableEngine)
272
+ ], ScopeChainTransformService.prototype, "variableEngine", 2);
273
+ ScopeChainTransformService = __decorateClass([
274
+ (0, import_inversify.injectable)(),
275
+ __decorateParam(0, (0, import_inversify.optional)()),
276
+ __decorateParam(0, (0, import_inversify.inject)(VariableChainConfig))
277
+ ], ScopeChainTransformService);
162
278
 
163
- // src/variable-layout-config.ts
164
- var VariableLayoutConfig = Symbol("VariableLayoutConfig");
279
+ // src/scopes/global-scope.ts
280
+ var import_inversify2 = require("inversify");
281
+ var import_variable_core2 = require("@flowgram.ai/variable-core");
282
+ var GlobalScope = class extends import_variable_core2.Scope {
283
+ /**
284
+ * Check if the scope is Global Scope.
285
+ * @param scope
286
+ * @returns
287
+ */
288
+ static is(scope) {
289
+ return scope.id === GlobalScope.ID;
290
+ }
291
+ };
292
+ GlobalScope.ID = Symbol("GlobalScope");
293
+ GlobalScope = __decorateClass([
294
+ (0, import_inversify2.injectable)()
295
+ ], GlobalScope);
296
+ var bindGlobalScope = (bind) => {
297
+ bind(GlobalScope).toDynamicValue((ctx) => {
298
+ const variableEngine = ctx.container.get(import_variable_core2.VariableEngine);
299
+ let scope = variableEngine.getScopeById(GlobalScope.ID);
300
+ if (!scope) {
301
+ scope = variableEngine.createScope(
302
+ GlobalScope.ID,
303
+ {},
304
+ { ScopeConstructor: GlobalScope }
305
+ );
306
+ variableEngine.chain.refreshAllChange();
307
+ }
308
+ return scope;
309
+ });
310
+ };
165
311
 
166
- // src/free-layout-scope-chain.ts
167
- var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
312
+ // src/chains/free-layout-scope-chain.ts
313
+ var FreeLayoutScopeChain = class extends import_variable_core3.ScopeChain {
314
+ /**
315
+ * The virtual tree of the flow document.
316
+ */
168
317
  get tree() {
169
318
  return this.flowDocument.originTree;
170
319
  }
171
320
  onInit() {
172
321
  this.toDispose.pushAll([
173
- // 线条发生变化时,会触发作用域链的更新
322
+ // When the line changes, the scope chain will be updated
174
323
  this.entityManager.onEntityDataChange(({ entityDataType }) => {
175
324
  if (entityDataType === import_free_layout_core.WorkflowNodeLinesData.type) {
176
325
  this.refreshAllChange();
177
326
  }
178
327
  }),
179
- // 树变化时候刷新作用域
328
+ // Refresh the scope when the tree changes
180
329
  this.tree.onTreeChange(() => {
181
330
  this.refreshAllChange();
182
331
  })
183
332
  ]);
184
333
  }
185
- // 获取同一层级所有输入节点
186
- getAllInputLayerNodes(curr) {
187
- return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allInputNodes || []).filter(
188
- (_node) => _node.parent === curr.parent
189
- );
334
+ /**
335
+ * Gets all input layer nodes for a given node in the same layer, sorted by distance.
336
+ * @param node The node to get input layer nodes for.
337
+ * @returns An array of input layer nodes.
338
+ */
339
+ getAllInputLayerNodes(node) {
340
+ const currParent = this.getNodeParent(node);
341
+ const result = /* @__PURE__ */ new Set();
342
+ const queue = [node];
343
+ while (queue.length) {
344
+ const curr = queue.shift();
345
+ (curr.lines?.inputNodes || []).forEach((inputNode) => {
346
+ if (this.getNodeParent(inputNode) === currParent) {
347
+ if (result.has(inputNode)) {
348
+ return;
349
+ }
350
+ queue.push(inputNode);
351
+ result.add(inputNode);
352
+ }
353
+ });
354
+ }
355
+ return Array.from(result).reverse();
190
356
  }
191
- // 获取同一层级所有输出节点
357
+ /**
358
+ * Gets all output layer nodes for a given node in the same layer.
359
+ * @param curr The node to get output layer nodes for.
360
+ * @returns An array of output layer nodes.
361
+ */
192
362
  getAllOutputLayerNodes(curr) {
193
- return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allOutputNodes || []).filter(
194
- (_node) => _node.parent === curr.parent
363
+ const currParent = this.getNodeParent(curr);
364
+ return (curr.lines?.allOutputNodes || []).filter(
365
+ (_node) => this.getNodeParent(_node) === currParent
195
366
  );
196
367
  }
368
+ /**
369
+ * Gets the dependency scopes for a given scope.
370
+ * @param scope The scope to get dependencies for.
371
+ * @returns An array of dependency scopes.
372
+ */
197
373
  getDeps(scope) {
198
374
  const { node } = scope.meta || {};
199
375
  if (!node) {
200
- return this.transformDeps([], { scope });
376
+ return this.transformService.transformDeps([], { scope });
201
377
  }
202
- const scopes = [];
378
+ const deps = [];
203
379
  let curr = node;
204
380
  while (curr) {
205
- const allInputNodes = this.getAllInputLayerNodes(curr);
206
- scopes.push(
207
- ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
208
- );
209
381
  const currVarData = curr.getData(FlowNodeVariableData);
210
382
  if (currVarData?.private && scope !== currVarData.private) {
211
- scopes.push(currVarData.private);
383
+ deps.unshift(currVarData.private);
212
384
  }
213
- curr = this.getParent(curr);
385
+ const allInputNodes = this.getAllInputLayerNodes(curr);
386
+ deps.unshift(
387
+ ...allInputNodes.map((_node) => [
388
+ _node.getData(FlowNodeVariableData).public,
389
+ // 4. all public children of inputNodes
390
+ ...this.getAllPublicChildScopes(_node)
391
+ ]).flat().filter(Boolean)
392
+ );
393
+ curr = this.getNodeParent(curr);
214
394
  }
215
- const uniqScopes = Array.from(new Set(scopes));
216
- return this.transformDeps(uniqScopes, { scope });
395
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
396
+ if (globalScope) {
397
+ deps.unshift(globalScope);
398
+ }
399
+ const uniqDeps = Array.from(new Set(deps));
400
+ return this.transformService.transformDeps(uniqDeps, { scope });
217
401
  }
402
+ /**
403
+ * Gets the covering scopes for a given scope.
404
+ * @param scope The scope to get covering scopes for.
405
+ * @returns An array of covering scopes.
406
+ */
218
407
  getCovers(scope) {
408
+ if (GlobalScope.is(scope)) {
409
+ const scopes2 = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
410
+ return this.transformService.transformCovers(scopes2, { scope });
411
+ }
219
412
  const { node } = scope.meta || {};
220
413
  if (!node) {
221
- return this.transformCovers([], { scope });
414
+ return this.transformService.transformCovers([], { scope });
222
415
  }
223
416
  const isPrivate = scope.meta.type === "private" /* private */;
224
417
  const queue = [];
225
418
  if (isPrivate) {
226
- queue.push(...this.getChildren(node));
419
+ queue.push(...this.getNodeChildren(node));
227
420
  } else {
228
421
  queue.push(...this.getAllOutputLayerNodes(node) || []);
422
+ let parent = this.getNodeParent(node);
423
+ while (parent) {
424
+ if (this.isNodeChildrenPrivate(parent)) {
425
+ break;
426
+ }
427
+ queue.push(...this.getAllOutputLayerNodes(parent));
428
+ parent = this.getNodeParent(parent);
429
+ }
229
430
  }
230
431
  const scopes = [];
231
432
  while (queue.length) {
232
433
  const _node = queue.shift();
233
434
  const variableData = _node.getData(FlowNodeVariableData);
234
435
  scopes.push(...variableData.allScopes);
235
- const children = _node && this.getChildren(_node);
436
+ const children = _node && this.getNodeChildren(_node);
236
437
  if (children?.length) {
237
438
  queue.push(...children);
238
439
  }
@@ -242,25 +443,16 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
242
443
  scopes.push(currentVariableData.public);
243
444
  }
244
445
  const uniqScopes = Array.from(new Set(scopes));
245
- return this.transformCovers(uniqScopes, { scope });
246
- }
247
- transformCovers(covers, { scope }) {
248
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
249
- scope,
250
- document: this.flowDocument,
251
- variableEngine: this.variableEngine
252
- }) : covers;
253
- }
254
- transformDeps(deps, { scope }) {
255
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
256
- scope,
257
- document: this.flowDocument,
258
- variableEngine: this.variableEngine
259
- }) : deps;
260
- }
261
- getChildren(node) {
262
- if (this.configs?.getFreeChildren) {
263
- return this.configs.getFreeChildren?.(node);
446
+ return this.transformService.transformCovers(uniqScopes, { scope });
447
+ }
448
+ /**
449
+ * Gets the children of a node.
450
+ * @param node The node to get children for.
451
+ * @returns An array of child nodes.
452
+ */
453
+ getNodeChildren(node) {
454
+ if (this.configs?.getNodeChildren) {
455
+ return this.configs.getNodeChildren?.(node);
264
456
  }
265
457
  const nodeMeta = node.getNodeMeta();
266
458
  const subCanvas = nodeMeta.subCanvas?.(node);
@@ -273,69 +465,117 @@ var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
273
465
  }
274
466
  return this.tree.getChildren(node);
275
467
  }
276
- getParent(node) {
277
- if (this.configs?.getFreeParent) {
278
- return this.configs.getFreeParent(node);
468
+ /**
469
+ * Get All children of nodes
470
+ * @param node
471
+ * @returns
472
+ */
473
+ getAllPublicChildScopes(node) {
474
+ if (this.isNodeChildrenPrivate(node)) {
475
+ return [];
476
+ }
477
+ return this.getNodeChildren(node).map((_node) => [
478
+ _node.getData(FlowNodeVariableData).public,
479
+ ...this.getAllPublicChildScopes(_node)
480
+ ]).flat();
481
+ }
482
+ /**
483
+ * Gets the parent of a node.
484
+ * @param node The node to get the parent for.
485
+ * @returns The parent node or `undefined` if not found.
486
+ */
487
+ getNodeParent(node) {
488
+ if (this.configs?.getNodeParent) {
489
+ return this.configs.getNodeParent(node);
279
490
  }
280
- const initParent = node.document.originTree.getParent(node);
281
- if (!initParent) {
282
- return initParent;
491
+ let parent = node.document.originTree.getParent(node);
492
+ while (parent?.flowNodeType === import_document2.FlowNodeBaseType.GROUP) {
493
+ parent = parent.parent;
283
494
  }
284
- const nodeMeta = initParent.getNodeMeta();
285
- const subCanvas = nodeMeta.subCanvas?.(initParent);
495
+ if (!parent) {
496
+ return parent;
497
+ }
498
+ const nodeMeta = parent.getNodeMeta();
499
+ const subCanvas = nodeMeta.subCanvas?.(parent);
286
500
  if (subCanvas?.isCanvas) {
287
501
  return subCanvas.parentNode;
288
502
  }
289
- return initParent;
503
+ return parent;
504
+ }
505
+ /**
506
+ * Checks if the children of a node are private and cannot be accessed by subsequent nodes.
507
+ * @param node The node to check.
508
+ * @returns `true` if the children are private, `false` otherwise.
509
+ */
510
+ isNodeChildrenPrivate(node) {
511
+ if (this.configs?.isNodeChildrenPrivate) {
512
+ return node ? this.configs?.isNodeChildrenPrivate(node) : false;
513
+ }
514
+ const isSystemNode = node?.id.startsWith("$");
515
+ return !isSystemNode && node?.flowNodeType !== import_document2.FlowNodeBaseType.GROUP;
290
516
  }
517
+ /**
518
+ * Sorts all scopes in the scope chain.
519
+ * @returns An empty array, as this method is not implemented.
520
+ */
291
521
  sortAll() {
292
522
  console.warn("FreeLayoutScopeChain.sortAll is not implemented");
293
523
  return [];
294
524
  }
295
525
  };
296
526
  __decorateClass([
297
- (0, import_inversify.inject)(import_core2.EntityManager)
527
+ (0, import_inversify3.inject)(import_core3.EntityManager)
298
528
  ], FreeLayoutScopeChain.prototype, "entityManager", 2);
299
529
  __decorateClass([
300
- (0, import_inversify.inject)(import_document.FlowDocument)
530
+ (0, import_inversify3.inject)(import_document2.FlowDocument)
301
531
  ], FreeLayoutScopeChain.prototype, "flowDocument", 2);
302
532
  __decorateClass([
303
- (0, import_inversify.optional)(),
304
- (0, import_inversify.inject)(VariableLayoutConfig)
533
+ (0, import_inversify3.optional)(),
534
+ (0, import_inversify3.inject)(VariableChainConfig)
305
535
  ], FreeLayoutScopeChain.prototype, "configs", 2);
306
536
  __decorateClass([
307
- (0, import_inversify.postConstruct)()
537
+ (0, import_inversify3.inject)(ScopeChainTransformService)
538
+ ], FreeLayoutScopeChain.prototype, "transformService", 2);
539
+ __decorateClass([
540
+ (0, import_inversify3.postConstruct)()
308
541
  ], FreeLayoutScopeChain.prototype, "onInit", 1);
309
542
 
310
- // src/fixed-layout-scope-chain.ts
311
- var import_inversify2 = require("inversify");
312
- var import_variable_core2 = require("@flowgram.ai/variable-core");
313
- var import_document2 = require("@flowgram.ai/document");
314
- var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
543
+ // src/chains/fixed-layout-scope-chain.ts
544
+ var import_inversify4 = require("inversify");
545
+ var import_variable_core4 = require("@flowgram.ai/variable-core");
546
+ var import_document3 = require("@flowgram.ai/document");
547
+ var FixedLayoutScopeChain = class extends import_variable_core4.ScopeChain {
315
548
  constructor(flowDocument, configs) {
316
549
  super();
317
550
  this.flowDocument = flowDocument;
318
551
  this.configs = configs;
319
552
  this.bindTree(flowDocument.originTree);
320
553
  this.toDispose.push(
321
- // REFRACTOR: onTreeChange 触发时机精细化
554
+ // REFRACTOR: onTreeChange trigger timing needs to be refined
322
555
  flowDocument.originTree.onTreeChange(() => {
323
556
  this.refreshAllChange();
324
557
  })
325
558
  );
326
559
  }
327
- // 绑定树
560
+ /**
561
+ * Binds the scope chain to a `FlowVirtualTree`.
562
+ * @param tree The `FlowVirtualTree` to bind to.
563
+ */
328
564
  bindTree(tree) {
329
565
  this.tree = tree;
330
566
  }
331
- // 获取依赖作用域
567
+ /**
568
+ * Gets the dependency scopes for a given scope.
569
+ * @param scope The scope to get dependencies for.
570
+ * @returns An array of dependency scopes.
571
+ */
332
572
  getDeps(scope) {
333
573
  if (!this.tree) {
334
- return this.transformDeps([], { scope });
574
+ return this.transformService.transformDeps([], { scope });
335
575
  }
336
576
  const node = scope.meta.node;
337
577
  if (!node) {
338
- return this.transformDeps([], { scope });
578
+ return this.transformService.transformDeps([], { scope });
339
579
  }
340
580
  const deps = [];
341
581
  let curr = node;
@@ -379,25 +619,37 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
379
619
  }
380
620
  curr = void 0;
381
621
  }
382
- return this.transformDeps(deps, { scope });
622
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
623
+ if (globalScope) {
624
+ deps.unshift(globalScope);
625
+ }
626
+ return this.transformService.transformDeps(deps, { scope });
383
627
  }
384
- // 获取覆盖作用域
628
+ /**
629
+ * Gets the covering scopes for a given scope.
630
+ * @param scope The scope to get covering scopes for.
631
+ * @returns An array of covering scopes.
632
+ */
385
633
  getCovers(scope) {
386
634
  if (!this.tree) {
387
- return this.transformCovers([], { scope });
635
+ return this.transformService.transformCovers([], { scope });
636
+ }
637
+ if (GlobalScope.is(scope)) {
638
+ const scopes = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
639
+ return this.transformService.transformCovers(scopes, { scope });
388
640
  }
389
641
  const node = scope.meta.node;
390
642
  if (!node) {
391
- return this.transformCovers([], { scope });
643
+ return this.transformService.transformCovers([], { scope });
392
644
  }
393
645
  const covers = [];
394
646
  if (scope.meta.type === "private" /* private */) {
395
647
  covers.push(
396
648
  ...this.getAllSortedChildScope(node, {
397
649
  addNodePrivateScope: true
398
- })
650
+ }).filter((_scope) => _scope !== scope)
399
651
  );
400
- return this.transformCovers(covers, { scope });
652
+ return this.transformService.transformCovers(covers, { scope });
401
653
  }
402
654
  let curr = node;
403
655
  while (curr) {
@@ -423,7 +675,7 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
423
675
  let currParentNext = this.tree.getNext(currParent);
424
676
  while (currParent) {
425
677
  if (this.isNodeChildrenPrivate(currParent)) {
426
- return this.transformCovers(covers, { scope });
678
+ return this.transformService.transformCovers(covers, { scope });
427
679
  }
428
680
  if (currParentNext) {
429
681
  break;
@@ -439,33 +691,30 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
439
691
  }
440
692
  curr = void 0;
441
693
  }
442
- return this.transformCovers(covers, { scope });
443
- }
444
- transformCovers(covers, { scope }) {
445
- return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
446
- scope,
447
- document: this.flowDocument,
448
- variableEngine: this.variableEngine
449
- }) : covers;
694
+ return this.transformService.transformCovers(covers, { scope });
450
695
  }
451
- transformDeps(deps, { scope }) {
452
- return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
453
- scope,
454
- document: this.flowDocument,
455
- variableEngine: this.variableEngine
456
- }) : deps;
457
- }
458
- // 排序所有作用域
696
+ /**
697
+ * Sorts all scopes in the scope chain.
698
+ * @returns A sorted array of all scopes.
699
+ */
459
700
  sortAll() {
460
- const { startNodeId } = this.configs || {};
461
- const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
701
+ const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);
462
702
  if (!startNode) {
463
703
  return [];
464
704
  }
465
705
  const startVariableData = startNode.getData(FlowNodeVariableData);
466
- return [startVariableData.public, ...this.getCovers(startVariableData.public)];
706
+ const startPublicScope = startVariableData.public;
707
+ const deps = this.getDeps(startPublicScope);
708
+ const covers = this.getCovers(startPublicScope).filter(
709
+ (_scope) => !deps.includes(_scope) && _scope !== startPublicScope
710
+ );
711
+ return [...deps, startPublicScope, ...covers];
467
712
  }
468
- // 获取变量 Data 数据
713
+ /**
714
+ * Gets the `FlowNodeVariableData` for a given `ScopeChainNode`.
715
+ * @param node The `ScopeChainNode` to get data for.
716
+ * @returns The `FlowNodeVariableData` or `undefined` if not found.
717
+ */
469
718
  getVariableData(node) {
470
719
  if (node.flowNodeType === "virtualNode") {
471
720
  return;
@@ -475,7 +724,11 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
475
724
  }
476
725
  return node.getData(FlowNodeVariableData);
477
726
  }
478
- // privateScope:子节点不可以被后续节点访问
727
+ /**
728
+ * Checks if the children of a node are private.
729
+ * @param node The node to check.
730
+ * @returns `true` if the children are private, `false` otherwise.
731
+ */
479
732
  isNodeChildrenPrivate(node) {
480
733
  if (this.configs?.isNodeChildrenPrivate) {
481
734
  return node ? this.configs?.isNodeChildrenPrivate(node) : false;
@@ -483,10 +736,20 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
483
736
  const isSystemNode = node?.id.startsWith("$");
484
737
  return !isSystemNode && this.hasChildren(node);
485
738
  }
739
+ /**
740
+ * Checks if a node has children.
741
+ * @param node The node to check.
742
+ * @returns `true` if the node has children, `false` otherwise.
743
+ */
486
744
  hasChildren(node) {
487
745
  return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);
488
746
  }
489
- // 子节点按照顺序进行排序(含自身)
747
+ /**
748
+ * Gets all sorted child scopes of a node.
749
+ * @param node The node to get child scopes for.
750
+ * @param options Options for getting child scopes.
751
+ * @returns An array of sorted child scopes.
752
+ */
490
753
  getAllSortedChildScope(node, {
491
754
  ignoreNodeChildrenPrivate,
492
755
  addNodePrivateScope
@@ -511,17 +774,33 @@ var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
511
774
  return scopes;
512
775
  }
513
776
  };
777
+ __decorateClass([
778
+ (0, import_inversify4.inject)(ScopeChainTransformService)
779
+ ], FixedLayoutScopeChain.prototype, "transformService", 2);
514
780
  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))
781
+ __decorateParam(0, (0, import_inversify4.inject)(import_document3.FlowDocument)),
782
+ __decorateParam(1, (0, import_inversify4.optional)()),
783
+ __decorateParam(1, (0, import_inversify4.inject)(VariableChainConfig))
518
784
  ], FixedLayoutScopeChain);
785
+
786
+ // src/utils.ts
787
+ function getNodeScope(node) {
788
+ return node.getData(FlowNodeVariableData).public;
789
+ }
790
+ function getNodePrivateScope(node) {
791
+ return node.getData(FlowNodeVariableData).initPrivate();
792
+ }
519
793
  // Annotate the CommonJS export names for ESM import in node:
520
794
  0 && (module.exports = {
521
795
  FixedLayoutScopeChain,
522
796
  FlowNodeScopeType,
523
797
  FlowNodeVariableData,
524
798
  FreeLayoutScopeChain,
525
- VariableLayoutConfig
799
+ GlobalScope,
800
+ ScopeChainTransformService,
801
+ VariableChainConfig,
802
+ bindGlobalScope,
803
+ getNodePrivateScope,
804
+ getNodeScope
526
805
  });
527
806
  //# sourceMappingURL=index.js.map