@flowgram.ai/variable-layout 0.1.0-alpha.10

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 ADDED
@@ -0,0 +1,689 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
+
29
+ // src/index.ts
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ FixedLayoutScopeChain: () => FixedLayoutScopeChain,
33
+ FlowNodeScopeType: () => FlowNodeScopeTypeEnum,
34
+ FlowNodeVariableData: () => FlowNodeVariableData,
35
+ FreeLayoutScopeChain: () => FreeLayoutScopeChain,
36
+ GlobalScope: () => GlobalScope,
37
+ ScopeChainTransformService: () => ScopeChainTransformService,
38
+ VariableChainConfig: () => VariableChainConfig,
39
+ bindGlobalScope: () => bindGlobalScope,
40
+ getNodePrivateScope: () => getNodePrivateScope,
41
+ getNodeScope: () => getNodeScope
42
+ });
43
+ module.exports = __toCommonJS(src_exports);
44
+
45
+ // src/flow-node-variable-data.ts
46
+ var import_core = require("@flowgram.ai/core");
47
+
48
+ // src/types.ts
49
+ var FlowNodeScopeTypeEnum = /* @__PURE__ */ ((FlowNodeScopeTypeEnum2) => {
50
+ FlowNodeScopeTypeEnum2["public"] = "public";
51
+ FlowNodeScopeTypeEnum2["private"] = "private";
52
+ return FlowNodeScopeTypeEnum2;
53
+ })(FlowNodeScopeTypeEnum || {});
54
+
55
+ // src/flow-node-variable-data.ts
56
+ var FlowNodeVariableData = class extends import_core.EntityData {
57
+ constructor(entity, opts) {
58
+ super(entity);
59
+ this.opts = opts;
60
+ const { variableEngine } = opts || {};
61
+ this.variableEngine = variableEngine;
62
+ this._public = this.variableEngine.createScope(this.entity.id, {
63
+ node: this.entity,
64
+ type: "public" /* public */
65
+ });
66
+ this.toDispose.push(this._public);
67
+ }
68
+ get private() {
69
+ return this._private;
70
+ }
71
+ get public() {
72
+ return this._public;
73
+ }
74
+ setVar(arg1, arg2) {
75
+ if (typeof arg1 === "string" && arg2 !== void 0) {
76
+ return this.public.ast.set(arg1, arg2);
77
+ }
78
+ if (typeof arg1 === "object" && arg2 === void 0) {
79
+ return this.public.ast.set("outputs", arg1);
80
+ }
81
+ throw new Error("Invalid arguments");
82
+ }
83
+ /**
84
+ * Retrieves a variable from the public AST (Abstract Syntax Tree) by key.
85
+ *
86
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
87
+ * @returns The value of the variable, or undefined if not found.
88
+ */
89
+ getVar(key = "outputs") {
90
+ return this.public.ast.get(key);
91
+ }
92
+ /**
93
+ * Clears a variable from the public AST (Abstract Syntax Tree) by key.
94
+ *
95
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
96
+ * @returns The updated AST node.
97
+ */
98
+ clearVar(key = "outputs") {
99
+ return this.public.ast.remove(key);
100
+ }
101
+ setPrivateVar(arg1, arg2) {
102
+ if (typeof arg1 === "string" && arg2 !== void 0) {
103
+ return this.initPrivate().ast.set(arg1, arg2);
104
+ }
105
+ if (typeof arg1 === "object" && arg2 === void 0) {
106
+ return this.initPrivate().ast.set("outputs", arg1);
107
+ }
108
+ throw new Error("Invalid arguments");
109
+ }
110
+ /**
111
+ * Retrieves a variable from the private AST (Abstract Syntax Tree) by key.
112
+ *
113
+ * @param key - The key of the variable to retrieve. Defaults to 'outputs'.
114
+ * @returns The value of the variable, or undefined if not found.
115
+ */
116
+ getPrivateVar(key = "outputs") {
117
+ return this.private?.ast.get(key);
118
+ }
119
+ /**
120
+ * Clears a variable from the private AST (Abstract Syntax Tree) by key.
121
+ *
122
+ * @param key - The key of the variable to clear. Defaults to 'outputs'.
123
+ * @returns The updated AST node.
124
+ */
125
+ clearPrivateVar(key = "outputs") {
126
+ return this.private?.ast.remove(key);
127
+ }
128
+ get allScopes() {
129
+ const res = [];
130
+ if (this._public) {
131
+ res.push(this._public);
132
+ }
133
+ if (this._private) {
134
+ res.push(this._private);
135
+ }
136
+ return res;
137
+ }
138
+ getDefaultData() {
139
+ return {};
140
+ }
141
+ initPrivate() {
142
+ if (!this._private) {
143
+ this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {
144
+ node: this.entity,
145
+ type: "private" /* private */
146
+ });
147
+ this.variableEngine.chain.refreshAllChange();
148
+ this.toDispose.push(this._private);
149
+ }
150
+ return this._private;
151
+ }
152
+ /**
153
+ * Find a variable field by key path in the public scope by scope chain.
154
+ * @param keyPath - The key path of the variable field.
155
+ * @returns The variable field, or undefined if not found.
156
+ */
157
+ getByKeyPath(keyPath) {
158
+ return this.public.available.getByKeyPath(keyPath);
159
+ }
160
+ /**
161
+ * Find a variable field by key path in the private scope by scope chain.
162
+ * @param keyPath - The key path of the variable field.
163
+ * @returns The variable field, or undefined if not found.
164
+ */
165
+ getByKeyPathInPrivate(keyPath) {
166
+ return this.private?.available.getByKeyPath(keyPath);
167
+ }
168
+ };
169
+ FlowNodeVariableData.type = "FlowNodeVariableData";
170
+
171
+ // src/chains/free-layout-scope-chain.ts
172
+ var import_inversify3 = require("inversify");
173
+ var import_variable_core3 = require("@flowgram.ai/variable-core");
174
+ var import_free_layout_core = require("@flowgram.ai/free-layout-core");
175
+ var import_document2 = require("@flowgram.ai/document");
176
+ var import_core3 = require("@flowgram.ai/core");
177
+
178
+ // src/variable-chain-config.ts
179
+ var VariableChainConfig = Symbol("VariableChainConfig");
180
+
181
+ // src/services/scope-chain-transform-service.ts
182
+ var import_inversify = require("inversify");
183
+ var import_variable_core = require("@flowgram.ai/variable-core");
184
+ var import_document = require("@flowgram.ai/document");
185
+ var import_core2 = require("@flowgram.ai/core");
186
+ var passthrough = (scopes, ctx) => scopes;
187
+ var ScopeChainTransformService = class {
188
+ constructor(configs) {
189
+ this.configs = configs;
190
+ this.transformerMap = /* @__PURE__ */ new Map();
191
+ if (this.configs?.transformDeps || this.configs?.transformCovers) {
192
+ this.transformerMap.set("VARIABLE_LAYOUT_CONFIG", {
193
+ transformDeps: this.configs.transformDeps || passthrough,
194
+ transformCovers: this.configs.transformCovers || passthrough
195
+ });
196
+ }
197
+ }
198
+ /**
199
+ * check if transformer registered
200
+ * @param transformerId used to identify transformer, prevent duplicated
201
+ * @returns
202
+ */
203
+ hasTransformer(transformerId) {
204
+ return this.transformerMap.has(transformerId);
205
+ }
206
+ /**
207
+ * register new transform function
208
+ * @param transformerId used to identify transformer, prevent duplicated transformer
209
+ * @param transformer
210
+ */
211
+ registerTransformer(transformerId, transformer) {
212
+ this.transformerMap.set(transformerId, transformer);
213
+ }
214
+ transformDeps(scopes, { scope }) {
215
+ return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
216
+ if (!transformer.transformDeps) {
217
+ return scopes2;
218
+ }
219
+ scopes2 = transformer.transformDeps(scopes2, {
220
+ scope,
221
+ document: this.document,
222
+ variableEngine: this.variableEngine
223
+ });
224
+ return scopes2;
225
+ }, scopes);
226
+ }
227
+ transformCovers(scopes, { scope }) {
228
+ return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
229
+ if (!transformer.transformCovers) {
230
+ return scopes2;
231
+ }
232
+ scopes2 = transformer.transformCovers(scopes2, {
233
+ scope,
234
+ document: this.document,
235
+ variableEngine: this.variableEngine
236
+ });
237
+ return scopes2;
238
+ }, scopes);
239
+ }
240
+ };
241
+ __decorateClass([
242
+ (0, import_core2.lazyInject)(import_document.FlowDocument)
243
+ ], ScopeChainTransformService.prototype, "document", 2);
244
+ __decorateClass([
245
+ (0, import_core2.lazyInject)(import_variable_core.VariableEngine)
246
+ ], ScopeChainTransformService.prototype, "variableEngine", 2);
247
+ ScopeChainTransformService = __decorateClass([
248
+ (0, import_inversify.injectable)(),
249
+ __decorateParam(0, (0, import_inversify.optional)()),
250
+ __decorateParam(0, (0, import_inversify.inject)(VariableChainConfig))
251
+ ], ScopeChainTransformService);
252
+
253
+ // src/scopes/global-scope.ts
254
+ var import_inversify2 = require("inversify");
255
+ var import_variable_core2 = require("@flowgram.ai/variable-core");
256
+ var GlobalScope = class extends import_variable_core2.Scope {
257
+ static is(scope) {
258
+ return scope.id === GlobalScope.ID;
259
+ }
260
+ };
261
+ GlobalScope.ID = Symbol("GlobalScope");
262
+ GlobalScope = __decorateClass([
263
+ (0, import_inversify2.injectable)()
264
+ ], GlobalScope);
265
+ var bindGlobalScope = (bind) => {
266
+ bind(GlobalScope).toDynamicValue((ctx) => {
267
+ const variableEngine = ctx.container.get(import_variable_core2.VariableEngine);
268
+ let scope = variableEngine.getScopeById(GlobalScope.ID);
269
+ if (!scope) {
270
+ scope = variableEngine.createScope(
271
+ GlobalScope.ID,
272
+ {},
273
+ { ScopeConstructor: GlobalScope }
274
+ );
275
+ variableEngine.chain.refreshAllChange();
276
+ }
277
+ return scope;
278
+ });
279
+ };
280
+
281
+ // src/chains/free-layout-scope-chain.ts
282
+ var FreeLayoutScopeChain = class extends import_variable_core3.ScopeChain {
283
+ get tree() {
284
+ return this.flowDocument.originTree;
285
+ }
286
+ onInit() {
287
+ this.toDispose.pushAll([
288
+ // 线条发生变化时,会触发作用域链的更新
289
+ this.entityManager.onEntityDataChange(({ entityDataType }) => {
290
+ if (entityDataType === import_free_layout_core.WorkflowNodeLinesData.type) {
291
+ this.refreshAllChange();
292
+ }
293
+ }),
294
+ // 树变化时候刷新作用域
295
+ this.tree.onTreeChange(() => {
296
+ this.refreshAllChange();
297
+ })
298
+ ]);
299
+ }
300
+ // 获取同一层级所有输入节点
301
+ getAllInputLayerNodes(curr) {
302
+ const currParent = this.getNodeParent(curr);
303
+ return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allInputNodes || []).filter(
304
+ (_node) => this.getNodeParent(_node) === currParent
305
+ );
306
+ }
307
+ // 获取同一层级所有输出节点
308
+ getAllOutputLayerNodes(curr) {
309
+ const currParent = this.getNodeParent(curr);
310
+ return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allOutputNodes || []).filter(
311
+ (_node) => this.getNodeParent(_node) === currParent
312
+ );
313
+ }
314
+ getDeps(scope) {
315
+ const { node } = scope.meta || {};
316
+ if (!node) {
317
+ return this.transformService.transformDeps([], { scope });
318
+ }
319
+ const deps = [];
320
+ let curr = node;
321
+ while (curr) {
322
+ const allInputNodes = this.getAllInputLayerNodes(curr);
323
+ deps.push(
324
+ ...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
325
+ );
326
+ deps.push(...allInputNodes.map((_node) => this.getAllPublicChildScopes(_node)).flat());
327
+ const currVarData = curr.getData(FlowNodeVariableData);
328
+ if (currVarData?.private && scope !== currVarData.private) {
329
+ deps.push(currVarData.private);
330
+ }
331
+ curr = this.getNodeParent(curr);
332
+ }
333
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
334
+ if (globalScope) {
335
+ deps.unshift(globalScope);
336
+ }
337
+ const uniqDeps = Array.from(new Set(deps));
338
+ return this.transformService.transformDeps(uniqDeps, { scope });
339
+ }
340
+ getCovers(scope) {
341
+ if (GlobalScope.is(scope)) {
342
+ const scopes2 = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
343
+ return this.transformService.transformCovers(scopes2, { scope });
344
+ }
345
+ const { node } = scope.meta || {};
346
+ if (!node) {
347
+ return this.transformService.transformCovers([], { scope });
348
+ }
349
+ const isPrivate = scope.meta.type === "private" /* private */;
350
+ const queue = [];
351
+ if (isPrivate) {
352
+ queue.push(...this.getNodeChildren(node));
353
+ } else {
354
+ queue.push(...this.getAllOutputLayerNodes(node) || []);
355
+ let parent = this.getNodeParent(node);
356
+ while (parent) {
357
+ if (this.isNodeChildrenPrivate(parent)) {
358
+ break;
359
+ }
360
+ queue.push(...this.getAllOutputLayerNodes(parent));
361
+ parent = this.getNodeParent(parent);
362
+ }
363
+ }
364
+ const scopes = [];
365
+ while (queue.length) {
366
+ const _node = queue.shift();
367
+ const variableData = _node.getData(FlowNodeVariableData);
368
+ scopes.push(...variableData.allScopes);
369
+ const children = _node && this.getNodeChildren(_node);
370
+ if (children?.length) {
371
+ queue.push(...children);
372
+ }
373
+ }
374
+ const currentVariableData = node.getData(FlowNodeVariableData);
375
+ if (isPrivate && currentVariableData.public) {
376
+ scopes.push(currentVariableData.public);
377
+ }
378
+ const uniqScopes = Array.from(new Set(scopes));
379
+ return this.transformService.transformCovers(uniqScopes, { scope });
380
+ }
381
+ getNodeChildren(node) {
382
+ if (this.configs?.getNodeChildren) {
383
+ return this.configs.getNodeChildren?.(node);
384
+ }
385
+ const nodeMeta = node.getNodeMeta();
386
+ const subCanvas = nodeMeta.subCanvas?.(node);
387
+ if (subCanvas) {
388
+ if (subCanvas.isCanvas) {
389
+ return [];
390
+ } else {
391
+ return subCanvas.canvasNode.collapsedChildren;
392
+ }
393
+ }
394
+ return this.tree.getChildren(node);
395
+ }
396
+ /**
397
+ * Get All children of nodes
398
+ * @param node
399
+ * @returns
400
+ */
401
+ getAllPublicChildScopes(node) {
402
+ if (this.isNodeChildrenPrivate(node)) {
403
+ return [];
404
+ }
405
+ return this.getNodeChildren(node).map((_node) => [
406
+ _node.getData(FlowNodeVariableData).public,
407
+ ...this.getAllPublicChildScopes(_node)
408
+ ]).flat();
409
+ }
410
+ getNodeParent(node) {
411
+ if (this.configs?.getNodeParent) {
412
+ return this.configs.getNodeParent(node);
413
+ }
414
+ let parent = node.document.originTree.getParent(node);
415
+ while (parent?.flowNodeType === import_document2.FlowNodeBaseType.GROUP) {
416
+ parent = parent.parent;
417
+ }
418
+ if (!parent) {
419
+ return parent;
420
+ }
421
+ const nodeMeta = parent.getNodeMeta();
422
+ const subCanvas = nodeMeta.subCanvas?.(parent);
423
+ if (subCanvas?.isCanvas) {
424
+ return subCanvas.parentNode;
425
+ }
426
+ return parent;
427
+ }
428
+ // Child nodes can not be accessed
429
+ isNodeChildrenPrivate(node) {
430
+ if (this.configs?.isNodeChildrenPrivate) {
431
+ return node ? this.configs?.isNodeChildrenPrivate(node) : false;
432
+ }
433
+ const isSystemNode = node?.id.startsWith("$");
434
+ return !isSystemNode && node?.flowNodeType !== import_document2.FlowNodeBaseType.GROUP;
435
+ }
436
+ sortAll() {
437
+ console.warn("FreeLayoutScopeChain.sortAll is not implemented");
438
+ return [];
439
+ }
440
+ };
441
+ __decorateClass([
442
+ (0, import_inversify3.inject)(import_core3.EntityManager)
443
+ ], FreeLayoutScopeChain.prototype, "entityManager", 2);
444
+ __decorateClass([
445
+ (0, import_inversify3.inject)(import_document2.FlowDocument)
446
+ ], FreeLayoutScopeChain.prototype, "flowDocument", 2);
447
+ __decorateClass([
448
+ (0, import_inversify3.optional)(),
449
+ (0, import_inversify3.inject)(VariableChainConfig)
450
+ ], FreeLayoutScopeChain.prototype, "configs", 2);
451
+ __decorateClass([
452
+ (0, import_inversify3.inject)(ScopeChainTransformService)
453
+ ], FreeLayoutScopeChain.prototype, "transformService", 2);
454
+ __decorateClass([
455
+ (0, import_inversify3.postConstruct)()
456
+ ], FreeLayoutScopeChain.prototype, "onInit", 1);
457
+
458
+ // src/chains/fixed-layout-scope-chain.ts
459
+ var import_inversify4 = require("inversify");
460
+ var import_variable_core4 = require("@flowgram.ai/variable-core");
461
+ var import_document3 = require("@flowgram.ai/document");
462
+ var FixedLayoutScopeChain = class extends import_variable_core4.ScopeChain {
463
+ constructor(flowDocument, configs) {
464
+ super();
465
+ this.flowDocument = flowDocument;
466
+ this.configs = configs;
467
+ this.bindTree(flowDocument.originTree);
468
+ this.toDispose.push(
469
+ // REFRACTOR: onTreeChange 触发时机精细化
470
+ flowDocument.originTree.onTreeChange(() => {
471
+ this.refreshAllChange();
472
+ })
473
+ );
474
+ }
475
+ // 绑定树
476
+ bindTree(tree) {
477
+ this.tree = tree;
478
+ }
479
+ // 获取依赖作用域
480
+ getDeps(scope) {
481
+ if (!this.tree) {
482
+ return this.transformService.transformDeps([], { scope });
483
+ }
484
+ const node = scope.meta.node;
485
+ if (!node) {
486
+ return this.transformService.transformDeps([], { scope });
487
+ }
488
+ const deps = [];
489
+ let curr = node;
490
+ while (curr) {
491
+ const { parent, pre } = this.tree.getInfo(curr);
492
+ const currData = this.getVariableData(curr);
493
+ if (curr === node) {
494
+ if (scope.meta.type === "public" /* public */ && currData?.private) {
495
+ deps.unshift(currData.private);
496
+ }
497
+ } else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {
498
+ deps.unshift(
499
+ ...this.getAllSortedChildScope(curr, {
500
+ ignoreNodeChildrenPrivate: true
501
+ })
502
+ );
503
+ }
504
+ if (currData && curr !== node) {
505
+ deps.unshift(currData.public);
506
+ }
507
+ if (pre) {
508
+ curr = pre;
509
+ continue;
510
+ }
511
+ if (parent) {
512
+ let currParent = parent;
513
+ let currParentPre = this.tree.getPre(currParent);
514
+ while (currParent) {
515
+ const currParentData = this.getVariableData(currParent);
516
+ if (currParentData) {
517
+ deps.unshift(...currParentData.allScopes);
518
+ }
519
+ if (currParentPre) {
520
+ break;
521
+ }
522
+ currParent = this.tree.getParent(currParent);
523
+ currParentPre = currParent ? this.tree.getPre(currParent) : void 0;
524
+ }
525
+ curr = currParentPre;
526
+ continue;
527
+ }
528
+ curr = void 0;
529
+ }
530
+ const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
531
+ if (globalScope) {
532
+ deps.unshift(globalScope);
533
+ }
534
+ return this.transformService.transformDeps(deps, { scope });
535
+ }
536
+ // 获取覆盖作用域
537
+ getCovers(scope) {
538
+ if (!this.tree) {
539
+ return this.transformService.transformCovers([], { scope });
540
+ }
541
+ if (GlobalScope.is(scope)) {
542
+ const scopes = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
543
+ return this.transformService.transformCovers(scopes, { scope });
544
+ }
545
+ const node = scope.meta.node;
546
+ if (!node) {
547
+ return this.transformService.transformCovers([], { scope });
548
+ }
549
+ const covers = [];
550
+ if (scope.meta.type === "private" /* private */) {
551
+ covers.push(
552
+ ...this.getAllSortedChildScope(node, {
553
+ addNodePrivateScope: true
554
+ }).filter((_scope) => _scope !== scope)
555
+ );
556
+ return this.transformService.transformCovers(covers, { scope });
557
+ }
558
+ let curr = node;
559
+ while (curr) {
560
+ const { next, parent } = this.tree.getInfo(curr);
561
+ const currData = this.getVariableData(curr);
562
+ if (curr !== node) {
563
+ if (this.hasChildren(curr)) {
564
+ covers.push(
565
+ ...this.getAllSortedChildScope(curr, {
566
+ addNodePrivateScope: true
567
+ })
568
+ );
569
+ } else if (currData) {
570
+ covers.push(...currData.allScopes);
571
+ }
572
+ }
573
+ if (next) {
574
+ curr = next;
575
+ continue;
576
+ }
577
+ if (parent) {
578
+ let currParent = parent;
579
+ let currParentNext = this.tree.getNext(currParent);
580
+ while (currParent) {
581
+ if (this.isNodeChildrenPrivate(currParent)) {
582
+ return this.transformService.transformCovers(covers, { scope });
583
+ }
584
+ if (currParentNext) {
585
+ break;
586
+ }
587
+ currParent = this.tree.getParent(currParent);
588
+ currParentNext = currParent ? this.tree.getNext(currParent) : void 0;
589
+ }
590
+ if (!currParentNext && currParent) {
591
+ break;
592
+ }
593
+ curr = currParentNext;
594
+ continue;
595
+ }
596
+ curr = void 0;
597
+ }
598
+ return this.transformService.transformCovers(covers, { scope });
599
+ }
600
+ // 排序所有作用域
601
+ sortAll() {
602
+ const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);
603
+ if (!startNode) {
604
+ return [];
605
+ }
606
+ const startVariableData = startNode.getData(FlowNodeVariableData);
607
+ const startPublicScope = startVariableData.public;
608
+ const deps = this.getDeps(startPublicScope);
609
+ const covers = this.getCovers(startPublicScope).filter(
610
+ (_scope) => !deps.includes(_scope) && _scope !== startPublicScope
611
+ );
612
+ return [...deps, startPublicScope, ...covers];
613
+ }
614
+ // 获取变量 Data 数据
615
+ getVariableData(node) {
616
+ if (node.flowNodeType === "virtualNode") {
617
+ return;
618
+ }
619
+ if (node.id.startsWith("$")) {
620
+ return;
621
+ }
622
+ return node.getData(FlowNodeVariableData);
623
+ }
624
+ // 子节点不可以被后续节点访问
625
+ isNodeChildrenPrivate(node) {
626
+ if (this.configs?.isNodeChildrenPrivate) {
627
+ return node ? this.configs?.isNodeChildrenPrivate(node) : false;
628
+ }
629
+ const isSystemNode = node?.id.startsWith("$");
630
+ return !isSystemNode && this.hasChildren(node);
631
+ }
632
+ hasChildren(node) {
633
+ return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);
634
+ }
635
+ // 子节点按照顺序进行排序(含自身)
636
+ getAllSortedChildScope(node, {
637
+ ignoreNodeChildrenPrivate,
638
+ addNodePrivateScope
639
+ } = {}) {
640
+ const scopes = [];
641
+ const variableData = this.getVariableData(node);
642
+ if (variableData) {
643
+ scopes.push(variableData.public);
644
+ }
645
+ if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {
646
+ return scopes;
647
+ }
648
+ if (addNodePrivateScope && variableData?.private) {
649
+ scopes.push(variableData.private);
650
+ }
651
+ const children = this.tree?.getChildren(node) || [];
652
+ scopes.push(
653
+ ...children.map(
654
+ (child) => this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })
655
+ ).flat()
656
+ );
657
+ return scopes;
658
+ }
659
+ };
660
+ __decorateClass([
661
+ (0, import_inversify4.inject)(ScopeChainTransformService)
662
+ ], FixedLayoutScopeChain.prototype, "transformService", 2);
663
+ FixedLayoutScopeChain = __decorateClass([
664
+ __decorateParam(0, (0, import_inversify4.inject)(import_document3.FlowDocument)),
665
+ __decorateParam(1, (0, import_inversify4.optional)()),
666
+ __decorateParam(1, (0, import_inversify4.inject)(VariableChainConfig))
667
+ ], FixedLayoutScopeChain);
668
+
669
+ // src/utils.ts
670
+ function getNodeScope(node) {
671
+ return node.getData(FlowNodeVariableData).public;
672
+ }
673
+ function getNodePrivateScope(node) {
674
+ return node.getData(FlowNodeVariableData).initPrivate();
675
+ }
676
+ // Annotate the CommonJS export names for ESM import in node:
677
+ 0 && (module.exports = {
678
+ FixedLayoutScopeChain,
679
+ FlowNodeScopeType,
680
+ FlowNodeVariableData,
681
+ FreeLayoutScopeChain,
682
+ GlobalScope,
683
+ ScopeChainTransformService,
684
+ VariableChainConfig,
685
+ bindGlobalScope,
686
+ getNodePrivateScope,
687
+ getNodeScope
688
+ });
689
+ //# sourceMappingURL=index.js.map