@flowgram.ai/variable-layout 0.1.0-alpha.2 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +387 -110
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +313 -37
- package/dist/index.d.ts +313 -37
- package/dist/index.js +395 -116
- package/dist/index.js.map +1 -1
- package/package.json +10 -12
package/dist/esm/index.js
CHANGED
|
@@ -33,9 +33,15 @@ var FlowNodeVariableData = class extends EntityData {
|
|
|
33
33
|
});
|
|
34
34
|
this.toDispose.push(this._public);
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The private scope of the node.
|
|
38
|
+
*/
|
|
36
39
|
get private() {
|
|
37
40
|
return this._private;
|
|
38
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The public scope of the node.
|
|
44
|
+
*/
|
|
39
45
|
get public() {
|
|
40
46
|
return this._public;
|
|
41
47
|
}
|
|
@@ -93,6 +99,9 @@ var FlowNodeVariableData = class extends EntityData {
|
|
|
93
99
|
clearPrivateVar(key = "outputs") {
|
|
94
100
|
return this.private?.ast.remove(key);
|
|
95
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* An array containing all scopes (public and private) of the node.
|
|
104
|
+
*/
|
|
96
105
|
get allScopes() {
|
|
97
106
|
const res = [];
|
|
98
107
|
if (this._public) {
|
|
@@ -106,106 +115,296 @@ var FlowNodeVariableData = class extends EntityData {
|
|
|
106
115
|
getDefaultData() {
|
|
107
116
|
return {};
|
|
108
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Initializes and returns the private scope for the node.
|
|
120
|
+
* If the private scope already exists, it returns the existing one.
|
|
121
|
+
* @returns The private scope of the node.
|
|
122
|
+
*/
|
|
109
123
|
initPrivate() {
|
|
110
124
|
if (!this._private) {
|
|
111
125
|
this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {
|
|
112
126
|
node: this.entity,
|
|
113
127
|
type: "private" /* private */
|
|
114
128
|
});
|
|
115
|
-
this.
|
|
116
|
-
_scope.refreshDeps();
|
|
117
|
-
});
|
|
118
|
-
this._private.depScopes.forEach((_scope) => {
|
|
119
|
-
_scope.refreshCovers();
|
|
120
|
-
});
|
|
121
|
-
this._private.available.refresh();
|
|
129
|
+
this.variableEngine.chain.refreshAllChange();
|
|
122
130
|
this.toDispose.push(this._private);
|
|
123
131
|
}
|
|
124
132
|
return this._private;
|
|
125
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Find a variable field by key path in the public scope by scope chain.
|
|
136
|
+
* @param keyPath - The key path of the variable field.
|
|
137
|
+
* @returns The variable field, or undefined if not found.
|
|
138
|
+
*/
|
|
139
|
+
getByKeyPath(keyPath) {
|
|
140
|
+
return this.public.available.getByKeyPath(keyPath);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Find a variable field by key path in the private scope by scope chain.
|
|
144
|
+
* @param keyPath - The key path of the variable field.
|
|
145
|
+
* @returns The variable field, or undefined if not found.
|
|
146
|
+
*/
|
|
147
|
+
getByKeyPathInPrivate(keyPath) {
|
|
148
|
+
return this.private?.available.getByKeyPath(keyPath);
|
|
149
|
+
}
|
|
126
150
|
};
|
|
127
151
|
FlowNodeVariableData.type = "FlowNodeVariableData";
|
|
128
152
|
|
|
129
|
-
// src/free-layout-scope-chain.ts
|
|
130
|
-
import { inject, optional, postConstruct } from "inversify";
|
|
153
|
+
// src/chains/free-layout-scope-chain.ts
|
|
154
|
+
import { inject as inject2, optional as optional2, postConstruct } from "inversify";
|
|
131
155
|
import { ScopeChain } from "@flowgram.ai/variable-core";
|
|
132
|
-
import { FlowDocument } from "@flowgram.ai/document";
|
|
133
|
-
import { EntityManager } from "@flowgram.ai/core";
|
|
134
156
|
import { WorkflowNodeLinesData } from "@flowgram.ai/free-layout-core";
|
|
157
|
+
import {
|
|
158
|
+
FlowDocument as FlowDocument2,
|
|
159
|
+
FlowNodeBaseType
|
|
160
|
+
} from "@flowgram.ai/document";
|
|
161
|
+
import { EntityManager } from "@flowgram.ai/core";
|
|
135
162
|
|
|
136
|
-
// src/variable-
|
|
137
|
-
var
|
|
163
|
+
// src/variable-chain-config.ts
|
|
164
|
+
var VariableChainConfig = Symbol("VariableChainConfig");
|
|
138
165
|
|
|
139
|
-
// src/
|
|
166
|
+
// src/services/scope-chain-transform-service.ts
|
|
167
|
+
import { inject, injectable, optional } from "inversify";
|
|
168
|
+
import { VariableEngine } from "@flowgram.ai/variable-core";
|
|
169
|
+
import { FlowDocument } from "@flowgram.ai/document";
|
|
170
|
+
import { lazyInject } from "@flowgram.ai/core";
|
|
171
|
+
var passthrough = (scopes, ctx) => scopes;
|
|
172
|
+
var ScopeChainTransformService = class {
|
|
173
|
+
constructor(configs) {
|
|
174
|
+
this.configs = configs;
|
|
175
|
+
this.transformerMap = /* @__PURE__ */ new Map();
|
|
176
|
+
if (this.configs?.transformDeps || this.configs?.transformCovers) {
|
|
177
|
+
this.transformerMap.set("VARIABLE_LAYOUT_CONFIG", {
|
|
178
|
+
transformDeps: this.configs.transformDeps || passthrough,
|
|
179
|
+
transformCovers: this.configs.transformCovers || passthrough
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* check if transformer registered
|
|
185
|
+
* @param transformerId used to identify transformer, prevent duplicated
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
188
|
+
hasTransformer(transformerId) {
|
|
189
|
+
return this.transformerMap.has(transformerId);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* register new transform function
|
|
193
|
+
* @param transformerId used to identify transformer, prevent duplicated transformer
|
|
194
|
+
* @param transformer The transformer to register.
|
|
195
|
+
*/
|
|
196
|
+
registerTransformer(transformerId, transformer) {
|
|
197
|
+
this.transformerMap.set(transformerId, transformer);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Transforms the dependency scopes.
|
|
201
|
+
* @param scopes The array of scopes to transform.
|
|
202
|
+
* @param param1 The context for the transformation.
|
|
203
|
+
* @returns The transformed array of scopes.
|
|
204
|
+
*/
|
|
205
|
+
transformDeps(scopes, { scope }) {
|
|
206
|
+
return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
|
|
207
|
+
if (!transformer.transformDeps) {
|
|
208
|
+
return scopes2;
|
|
209
|
+
}
|
|
210
|
+
scopes2 = transformer.transformDeps(scopes2, {
|
|
211
|
+
scope,
|
|
212
|
+
document: this.document,
|
|
213
|
+
variableEngine: this.variableEngine
|
|
214
|
+
});
|
|
215
|
+
return scopes2;
|
|
216
|
+
}, scopes);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Transforms the cover scopes.
|
|
220
|
+
* @param scopes The array of scopes to transform.
|
|
221
|
+
* @param param1 The context for the transformation.
|
|
222
|
+
* @returns The transformed array of scopes.
|
|
223
|
+
*/
|
|
224
|
+
transformCovers(scopes, { scope }) {
|
|
225
|
+
return Array.from(this.transformerMap.values()).reduce((scopes2, transformer) => {
|
|
226
|
+
if (!transformer.transformCovers) {
|
|
227
|
+
return scopes2;
|
|
228
|
+
}
|
|
229
|
+
scopes2 = transformer.transformCovers(scopes2, {
|
|
230
|
+
scope,
|
|
231
|
+
document: this.document,
|
|
232
|
+
variableEngine: this.variableEngine
|
|
233
|
+
});
|
|
234
|
+
return scopes2;
|
|
235
|
+
}, scopes);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
__decorateClass([
|
|
239
|
+
lazyInject(FlowDocument)
|
|
240
|
+
], ScopeChainTransformService.prototype, "document", 2);
|
|
241
|
+
__decorateClass([
|
|
242
|
+
lazyInject(VariableEngine)
|
|
243
|
+
], ScopeChainTransformService.prototype, "variableEngine", 2);
|
|
244
|
+
ScopeChainTransformService = __decorateClass([
|
|
245
|
+
injectable(),
|
|
246
|
+
__decorateParam(0, optional()),
|
|
247
|
+
__decorateParam(0, inject(VariableChainConfig))
|
|
248
|
+
], ScopeChainTransformService);
|
|
249
|
+
|
|
250
|
+
// src/scopes/global-scope.ts
|
|
251
|
+
import { injectable as injectable2 } from "inversify";
|
|
252
|
+
import { Scope as Scope2, VariableEngine as VariableEngine2 } from "@flowgram.ai/variable-core";
|
|
253
|
+
var GlobalScope = class extends Scope2 {
|
|
254
|
+
/**
|
|
255
|
+
* Check if the scope is Global Scope.
|
|
256
|
+
* @param scope
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
259
|
+
static is(scope) {
|
|
260
|
+
return scope.id === GlobalScope.ID;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
GlobalScope.ID = Symbol("GlobalScope");
|
|
264
|
+
GlobalScope = __decorateClass([
|
|
265
|
+
injectable2()
|
|
266
|
+
], GlobalScope);
|
|
267
|
+
var bindGlobalScope = (bind) => {
|
|
268
|
+
bind(GlobalScope).toDynamicValue((ctx) => {
|
|
269
|
+
const variableEngine = ctx.container.get(VariableEngine2);
|
|
270
|
+
let scope = variableEngine.getScopeById(GlobalScope.ID);
|
|
271
|
+
if (!scope) {
|
|
272
|
+
scope = variableEngine.createScope(
|
|
273
|
+
GlobalScope.ID,
|
|
274
|
+
{},
|
|
275
|
+
{ ScopeConstructor: GlobalScope }
|
|
276
|
+
);
|
|
277
|
+
variableEngine.chain.refreshAllChange();
|
|
278
|
+
}
|
|
279
|
+
return scope;
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/chains/free-layout-scope-chain.ts
|
|
140
284
|
var FreeLayoutScopeChain = class extends ScopeChain {
|
|
285
|
+
/**
|
|
286
|
+
* The virtual tree of the flow document.
|
|
287
|
+
*/
|
|
141
288
|
get tree() {
|
|
142
289
|
return this.flowDocument.originTree;
|
|
143
290
|
}
|
|
144
291
|
onInit() {
|
|
145
292
|
this.toDispose.pushAll([
|
|
146
|
-
//
|
|
293
|
+
// When the line changes, the scope chain will be updated
|
|
147
294
|
this.entityManager.onEntityDataChange(({ entityDataType }) => {
|
|
148
295
|
if (entityDataType === WorkflowNodeLinesData.type) {
|
|
149
296
|
this.refreshAllChange();
|
|
150
297
|
}
|
|
151
298
|
}),
|
|
152
|
-
//
|
|
299
|
+
// Refresh the scope when the tree changes
|
|
153
300
|
this.tree.onTreeChange(() => {
|
|
154
301
|
this.refreshAllChange();
|
|
155
302
|
})
|
|
156
303
|
]);
|
|
157
304
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
305
|
+
/**
|
|
306
|
+
* Gets all input layer nodes for a given node in the same layer, sorted by distance.
|
|
307
|
+
* @param node The node to get input layer nodes for.
|
|
308
|
+
* @returns An array of input layer nodes.
|
|
309
|
+
*/
|
|
310
|
+
getAllInputLayerNodes(node) {
|
|
311
|
+
const currParent = this.getNodeParent(node);
|
|
312
|
+
const result = /* @__PURE__ */ new Set();
|
|
313
|
+
const queue = [node];
|
|
314
|
+
while (queue.length) {
|
|
315
|
+
const curr = queue.shift();
|
|
316
|
+
(curr.lines?.inputNodes || []).forEach((inputNode) => {
|
|
317
|
+
if (this.getNodeParent(inputNode) === currParent) {
|
|
318
|
+
if (result.has(inputNode)) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
queue.push(inputNode);
|
|
322
|
+
result.add(inputNode);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return Array.from(result).reverse();
|
|
163
327
|
}
|
|
164
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Gets all output layer nodes for a given node in the same layer.
|
|
330
|
+
* @param curr The node to get output layer nodes for.
|
|
331
|
+
* @returns An array of output layer nodes.
|
|
332
|
+
*/
|
|
165
333
|
getAllOutputLayerNodes(curr) {
|
|
166
|
-
|
|
167
|
-
|
|
334
|
+
const currParent = this.getNodeParent(curr);
|
|
335
|
+
return (curr.lines?.allOutputNodes || []).filter(
|
|
336
|
+
(_node) => this.getNodeParent(_node) === currParent
|
|
168
337
|
);
|
|
169
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Gets the dependency scopes for a given scope.
|
|
341
|
+
* @param scope The scope to get dependencies for.
|
|
342
|
+
* @returns An array of dependency scopes.
|
|
343
|
+
*/
|
|
170
344
|
getDeps(scope) {
|
|
171
345
|
const { node } = scope.meta || {};
|
|
172
346
|
if (!node) {
|
|
173
|
-
return this.transformDeps([], { scope });
|
|
347
|
+
return this.transformService.transformDeps([], { scope });
|
|
174
348
|
}
|
|
175
|
-
const
|
|
349
|
+
const deps = [];
|
|
176
350
|
let curr = node;
|
|
177
351
|
while (curr) {
|
|
178
|
-
const allInputNodes = this.getAllInputLayerNodes(curr);
|
|
179
|
-
scopes.push(
|
|
180
|
-
...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
|
|
181
|
-
);
|
|
182
352
|
const currVarData = curr.getData(FlowNodeVariableData);
|
|
183
353
|
if (currVarData?.private && scope !== currVarData.private) {
|
|
184
|
-
|
|
354
|
+
deps.unshift(currVarData.private);
|
|
185
355
|
}
|
|
186
|
-
|
|
356
|
+
const allInputNodes = this.getAllInputLayerNodes(curr);
|
|
357
|
+
deps.unshift(
|
|
358
|
+
...allInputNodes.map((_node) => [
|
|
359
|
+
_node.getData(FlowNodeVariableData).public,
|
|
360
|
+
// 4. all public children of inputNodes
|
|
361
|
+
...this.getAllPublicChildScopes(_node)
|
|
362
|
+
]).flat().filter(Boolean)
|
|
363
|
+
);
|
|
364
|
+
curr = this.getNodeParent(curr);
|
|
187
365
|
}
|
|
188
|
-
const
|
|
189
|
-
|
|
366
|
+
const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
|
|
367
|
+
if (globalScope) {
|
|
368
|
+
deps.unshift(globalScope);
|
|
369
|
+
}
|
|
370
|
+
const uniqDeps = Array.from(new Set(deps));
|
|
371
|
+
return this.transformService.transformDeps(uniqDeps, { scope });
|
|
190
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Gets the covering scopes for a given scope.
|
|
375
|
+
* @param scope The scope to get covering scopes for.
|
|
376
|
+
* @returns An array of covering scopes.
|
|
377
|
+
*/
|
|
191
378
|
getCovers(scope) {
|
|
379
|
+
if (GlobalScope.is(scope)) {
|
|
380
|
+
const scopes2 = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
|
|
381
|
+
return this.transformService.transformCovers(scopes2, { scope });
|
|
382
|
+
}
|
|
192
383
|
const { node } = scope.meta || {};
|
|
193
384
|
if (!node) {
|
|
194
|
-
return this.transformCovers([], { scope });
|
|
385
|
+
return this.transformService.transformCovers([], { scope });
|
|
195
386
|
}
|
|
196
387
|
const isPrivate = scope.meta.type === "private" /* private */;
|
|
197
388
|
const queue = [];
|
|
198
389
|
if (isPrivate) {
|
|
199
|
-
queue.push(...this.
|
|
390
|
+
queue.push(...this.getNodeChildren(node));
|
|
200
391
|
} else {
|
|
201
392
|
queue.push(...this.getAllOutputLayerNodes(node) || []);
|
|
393
|
+
let parent = this.getNodeParent(node);
|
|
394
|
+
while (parent) {
|
|
395
|
+
if (this.isNodeChildrenPrivate(parent)) {
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
queue.push(...this.getAllOutputLayerNodes(parent));
|
|
399
|
+
parent = this.getNodeParent(parent);
|
|
400
|
+
}
|
|
202
401
|
}
|
|
203
402
|
const scopes = [];
|
|
204
403
|
while (queue.length) {
|
|
205
404
|
const _node = queue.shift();
|
|
206
405
|
const variableData = _node.getData(FlowNodeVariableData);
|
|
207
406
|
scopes.push(...variableData.allScopes);
|
|
208
|
-
const children = _node && this.
|
|
407
|
+
const children = _node && this.getNodeChildren(_node);
|
|
209
408
|
if (children?.length) {
|
|
210
409
|
queue.push(...children);
|
|
211
410
|
}
|
|
@@ -215,25 +414,16 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
215
414
|
scopes.push(currentVariableData.public);
|
|
216
415
|
}
|
|
217
416
|
const uniqScopes = Array.from(new Set(scopes));
|
|
218
|
-
return this.transformCovers(uniqScopes, { scope });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
229
|
-
scope,
|
|
230
|
-
document: this.flowDocument,
|
|
231
|
-
variableEngine: this.variableEngine
|
|
232
|
-
}) : deps;
|
|
233
|
-
}
|
|
234
|
-
getChildren(node) {
|
|
235
|
-
if (this.configs?.getFreeChildren) {
|
|
236
|
-
return this.configs.getFreeChildren?.(node);
|
|
417
|
+
return this.transformService.transformCovers(uniqScopes, { scope });
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Gets the children of a node.
|
|
421
|
+
* @param node The node to get children for.
|
|
422
|
+
* @returns An array of child nodes.
|
|
423
|
+
*/
|
|
424
|
+
getNodeChildren(node) {
|
|
425
|
+
if (this.configs?.getNodeChildren) {
|
|
426
|
+
return this.configs.getNodeChildren?.(node);
|
|
237
427
|
}
|
|
238
428
|
const nodeMeta = node.getNodeMeta();
|
|
239
429
|
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
@@ -246,44 +436,85 @@ var FreeLayoutScopeChain = class extends ScopeChain {
|
|
|
246
436
|
}
|
|
247
437
|
return this.tree.getChildren(node);
|
|
248
438
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
439
|
+
/**
|
|
440
|
+
* Get All children of nodes
|
|
441
|
+
* @param node
|
|
442
|
+
* @returns
|
|
443
|
+
*/
|
|
444
|
+
getAllPublicChildScopes(node) {
|
|
445
|
+
if (this.isNodeChildrenPrivate(node)) {
|
|
446
|
+
return [];
|
|
252
447
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
448
|
+
return this.getNodeChildren(node).map((_node) => [
|
|
449
|
+
_node.getData(FlowNodeVariableData).public,
|
|
450
|
+
...this.getAllPublicChildScopes(_node)
|
|
451
|
+
]).flat();
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Gets the parent of a node.
|
|
455
|
+
* @param node The node to get the parent for.
|
|
456
|
+
* @returns The parent node or `undefined` if not found.
|
|
457
|
+
*/
|
|
458
|
+
getNodeParent(node) {
|
|
459
|
+
if (this.configs?.getNodeParent) {
|
|
460
|
+
return this.configs.getNodeParent(node);
|
|
461
|
+
}
|
|
462
|
+
let parent = node.document.originTree.getParent(node);
|
|
463
|
+
while (parent?.flowNodeType === FlowNodeBaseType.GROUP) {
|
|
464
|
+
parent = parent.parent;
|
|
465
|
+
}
|
|
466
|
+
if (!parent) {
|
|
467
|
+
return parent;
|
|
256
468
|
}
|
|
257
|
-
const nodeMeta =
|
|
258
|
-
const subCanvas = nodeMeta.subCanvas?.(
|
|
469
|
+
const nodeMeta = parent.getNodeMeta();
|
|
470
|
+
const subCanvas = nodeMeta.subCanvas?.(parent);
|
|
259
471
|
if (subCanvas?.isCanvas) {
|
|
260
472
|
return subCanvas.parentNode;
|
|
261
473
|
}
|
|
262
|
-
return
|
|
474
|
+
return parent;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Checks if the children of a node are private and cannot be accessed by subsequent nodes.
|
|
478
|
+
* @param node The node to check.
|
|
479
|
+
* @returns `true` if the children are private, `false` otherwise.
|
|
480
|
+
*/
|
|
481
|
+
isNodeChildrenPrivate(node) {
|
|
482
|
+
if (this.configs?.isNodeChildrenPrivate) {
|
|
483
|
+
return node ? this.configs?.isNodeChildrenPrivate(node) : false;
|
|
484
|
+
}
|
|
485
|
+
const isSystemNode = node?.id.startsWith("$");
|
|
486
|
+
return !isSystemNode && node?.flowNodeType !== FlowNodeBaseType.GROUP;
|
|
263
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Sorts all scopes in the scope chain.
|
|
490
|
+
* @returns An empty array, as this method is not implemented.
|
|
491
|
+
*/
|
|
264
492
|
sortAll() {
|
|
265
493
|
console.warn("FreeLayoutScopeChain.sortAll is not implemented");
|
|
266
494
|
return [];
|
|
267
495
|
}
|
|
268
496
|
};
|
|
269
497
|
__decorateClass([
|
|
270
|
-
|
|
498
|
+
inject2(EntityManager)
|
|
271
499
|
], FreeLayoutScopeChain.prototype, "entityManager", 2);
|
|
272
500
|
__decorateClass([
|
|
273
|
-
|
|
501
|
+
inject2(FlowDocument2)
|
|
274
502
|
], FreeLayoutScopeChain.prototype, "flowDocument", 2);
|
|
275
503
|
__decorateClass([
|
|
276
|
-
|
|
277
|
-
|
|
504
|
+
optional2(),
|
|
505
|
+
inject2(VariableChainConfig)
|
|
278
506
|
], FreeLayoutScopeChain.prototype, "configs", 2);
|
|
507
|
+
__decorateClass([
|
|
508
|
+
inject2(ScopeChainTransformService)
|
|
509
|
+
], FreeLayoutScopeChain.prototype, "transformService", 2);
|
|
279
510
|
__decorateClass([
|
|
280
511
|
postConstruct()
|
|
281
512
|
], FreeLayoutScopeChain.prototype, "onInit", 1);
|
|
282
513
|
|
|
283
|
-
// src/fixed-layout-scope-chain.ts
|
|
284
|
-
import { inject as
|
|
514
|
+
// src/chains/fixed-layout-scope-chain.ts
|
|
515
|
+
import { inject as inject3, optional as optional3 } from "inversify";
|
|
285
516
|
import { ScopeChain as ScopeChain2 } from "@flowgram.ai/variable-core";
|
|
286
|
-
import { FlowDocument as
|
|
517
|
+
import { FlowDocument as FlowDocument3 } from "@flowgram.ai/document";
|
|
287
518
|
var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
288
519
|
constructor(flowDocument, configs) {
|
|
289
520
|
super();
|
|
@@ -291,24 +522,31 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
291
522
|
this.configs = configs;
|
|
292
523
|
this.bindTree(flowDocument.originTree);
|
|
293
524
|
this.toDispose.push(
|
|
294
|
-
// REFRACTOR: onTreeChange
|
|
525
|
+
// REFRACTOR: onTreeChange trigger timing needs to be refined
|
|
295
526
|
flowDocument.originTree.onTreeChange(() => {
|
|
296
527
|
this.refreshAllChange();
|
|
297
528
|
})
|
|
298
529
|
);
|
|
299
530
|
}
|
|
300
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Binds the scope chain to a `FlowVirtualTree`.
|
|
533
|
+
* @param tree The `FlowVirtualTree` to bind to.
|
|
534
|
+
*/
|
|
301
535
|
bindTree(tree) {
|
|
302
536
|
this.tree = tree;
|
|
303
537
|
}
|
|
304
|
-
|
|
538
|
+
/**
|
|
539
|
+
* Gets the dependency scopes for a given scope.
|
|
540
|
+
* @param scope The scope to get dependencies for.
|
|
541
|
+
* @returns An array of dependency scopes.
|
|
542
|
+
*/
|
|
305
543
|
getDeps(scope) {
|
|
306
544
|
if (!this.tree) {
|
|
307
|
-
return this.transformDeps([], { scope });
|
|
545
|
+
return this.transformService.transformDeps([], { scope });
|
|
308
546
|
}
|
|
309
547
|
const node = scope.meta.node;
|
|
310
548
|
if (!node) {
|
|
311
|
-
return this.transformDeps([], { scope });
|
|
549
|
+
return this.transformService.transformDeps([], { scope });
|
|
312
550
|
}
|
|
313
551
|
const deps = [];
|
|
314
552
|
let curr = node;
|
|
@@ -352,25 +590,37 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
352
590
|
}
|
|
353
591
|
curr = void 0;
|
|
354
592
|
}
|
|
355
|
-
|
|
593
|
+
const globalScope = this.variableEngine.getScopeById(GlobalScope.ID);
|
|
594
|
+
if (globalScope) {
|
|
595
|
+
deps.unshift(globalScope);
|
|
596
|
+
}
|
|
597
|
+
return this.transformService.transformDeps(deps, { scope });
|
|
356
598
|
}
|
|
357
|
-
|
|
599
|
+
/**
|
|
600
|
+
* Gets the covering scopes for a given scope.
|
|
601
|
+
* @param scope The scope to get covering scopes for.
|
|
602
|
+
* @returns An array of covering scopes.
|
|
603
|
+
*/
|
|
358
604
|
getCovers(scope) {
|
|
359
605
|
if (!this.tree) {
|
|
360
|
-
return this.transformCovers([], { scope });
|
|
606
|
+
return this.transformService.transformCovers([], { scope });
|
|
607
|
+
}
|
|
608
|
+
if (GlobalScope.is(scope)) {
|
|
609
|
+
const scopes = this.variableEngine.getAllScopes({ sort: true }).filter((_scope) => !GlobalScope.is(_scope));
|
|
610
|
+
return this.transformService.transformCovers(scopes, { scope });
|
|
361
611
|
}
|
|
362
612
|
const node = scope.meta.node;
|
|
363
613
|
if (!node) {
|
|
364
|
-
return this.transformCovers([], { scope });
|
|
614
|
+
return this.transformService.transformCovers([], { scope });
|
|
365
615
|
}
|
|
366
616
|
const covers = [];
|
|
367
617
|
if (scope.meta.type === "private" /* private */) {
|
|
368
618
|
covers.push(
|
|
369
619
|
...this.getAllSortedChildScope(node, {
|
|
370
620
|
addNodePrivateScope: true
|
|
371
|
-
})
|
|
621
|
+
}).filter((_scope) => _scope !== scope)
|
|
372
622
|
);
|
|
373
|
-
return this.transformCovers(covers, { scope });
|
|
623
|
+
return this.transformService.transformCovers(covers, { scope });
|
|
374
624
|
}
|
|
375
625
|
let curr = node;
|
|
376
626
|
while (curr) {
|
|
@@ -396,7 +646,7 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
396
646
|
let currParentNext = this.tree.getNext(currParent);
|
|
397
647
|
while (currParent) {
|
|
398
648
|
if (this.isNodeChildrenPrivate(currParent)) {
|
|
399
|
-
return this.transformCovers(covers, { scope });
|
|
649
|
+
return this.transformService.transformCovers(covers, { scope });
|
|
400
650
|
}
|
|
401
651
|
if (currParentNext) {
|
|
402
652
|
break;
|
|
@@ -412,33 +662,30 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
412
662
|
}
|
|
413
663
|
curr = void 0;
|
|
414
664
|
}
|
|
415
|
-
return this.transformCovers(covers, { scope });
|
|
665
|
+
return this.transformService.transformCovers(covers, { scope });
|
|
416
666
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
variableEngine: this.variableEngine
|
|
422
|
-
}) : covers;
|
|
423
|
-
}
|
|
424
|
-
transformDeps(deps, { scope }) {
|
|
425
|
-
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
426
|
-
scope,
|
|
427
|
-
document: this.flowDocument,
|
|
428
|
-
variableEngine: this.variableEngine
|
|
429
|
-
}) : deps;
|
|
430
|
-
}
|
|
431
|
-
// 排序所有作用域
|
|
667
|
+
/**
|
|
668
|
+
* Sorts all scopes in the scope chain.
|
|
669
|
+
* @returns A sorted array of all scopes.
|
|
670
|
+
*/
|
|
432
671
|
sortAll() {
|
|
433
|
-
const
|
|
434
|
-
const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
|
|
672
|
+
const startNode = this.flowDocument.getAllNodes().find((_node) => _node.isStart);
|
|
435
673
|
if (!startNode) {
|
|
436
674
|
return [];
|
|
437
675
|
}
|
|
438
676
|
const startVariableData = startNode.getData(FlowNodeVariableData);
|
|
439
|
-
|
|
677
|
+
const startPublicScope = startVariableData.public;
|
|
678
|
+
const deps = this.getDeps(startPublicScope);
|
|
679
|
+
const covers = this.getCovers(startPublicScope).filter(
|
|
680
|
+
(_scope) => !deps.includes(_scope) && _scope !== startPublicScope
|
|
681
|
+
);
|
|
682
|
+
return [...deps, startPublicScope, ...covers];
|
|
440
683
|
}
|
|
441
|
-
|
|
684
|
+
/**
|
|
685
|
+
* Gets the `FlowNodeVariableData` for a given `ScopeChainNode`.
|
|
686
|
+
* @param node The `ScopeChainNode` to get data for.
|
|
687
|
+
* @returns The `FlowNodeVariableData` or `undefined` if not found.
|
|
688
|
+
*/
|
|
442
689
|
getVariableData(node) {
|
|
443
690
|
if (node.flowNodeType === "virtualNode") {
|
|
444
691
|
return;
|
|
@@ -448,7 +695,11 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
448
695
|
}
|
|
449
696
|
return node.getData(FlowNodeVariableData);
|
|
450
697
|
}
|
|
451
|
-
|
|
698
|
+
/**
|
|
699
|
+
* Checks if the children of a node are private.
|
|
700
|
+
* @param node The node to check.
|
|
701
|
+
* @returns `true` if the children are private, `false` otherwise.
|
|
702
|
+
*/
|
|
452
703
|
isNodeChildrenPrivate(node) {
|
|
453
704
|
if (this.configs?.isNodeChildrenPrivate) {
|
|
454
705
|
return node ? this.configs?.isNodeChildrenPrivate(node) : false;
|
|
@@ -456,10 +707,20 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
456
707
|
const isSystemNode = node?.id.startsWith("$");
|
|
457
708
|
return !isSystemNode && this.hasChildren(node);
|
|
458
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Checks if a node has children.
|
|
712
|
+
* @param node The node to check.
|
|
713
|
+
* @returns `true` if the node has children, `false` otherwise.
|
|
714
|
+
*/
|
|
459
715
|
hasChildren(node) {
|
|
460
716
|
return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);
|
|
461
717
|
}
|
|
462
|
-
|
|
718
|
+
/**
|
|
719
|
+
* Gets all sorted child scopes of a node.
|
|
720
|
+
* @param node The node to get child scopes for.
|
|
721
|
+
* @param options Options for getting child scopes.
|
|
722
|
+
* @returns An array of sorted child scopes.
|
|
723
|
+
*/
|
|
463
724
|
getAllSortedChildScope(node, {
|
|
464
725
|
ignoreNodeChildrenPrivate,
|
|
465
726
|
addNodePrivateScope
|
|
@@ -484,16 +745,32 @@ var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
|
484
745
|
return scopes;
|
|
485
746
|
}
|
|
486
747
|
};
|
|
748
|
+
__decorateClass([
|
|
749
|
+
inject3(ScopeChainTransformService)
|
|
750
|
+
], FixedLayoutScopeChain.prototype, "transformService", 2);
|
|
487
751
|
FixedLayoutScopeChain = __decorateClass([
|
|
488
|
-
__decorateParam(0,
|
|
489
|
-
__decorateParam(1,
|
|
490
|
-
__decorateParam(1,
|
|
752
|
+
__decorateParam(0, inject3(FlowDocument3)),
|
|
753
|
+
__decorateParam(1, optional3()),
|
|
754
|
+
__decorateParam(1, inject3(VariableChainConfig))
|
|
491
755
|
], FixedLayoutScopeChain);
|
|
756
|
+
|
|
757
|
+
// src/utils.ts
|
|
758
|
+
function getNodeScope(node) {
|
|
759
|
+
return node.getData(FlowNodeVariableData).public;
|
|
760
|
+
}
|
|
761
|
+
function getNodePrivateScope(node) {
|
|
762
|
+
return node.getData(FlowNodeVariableData).initPrivate();
|
|
763
|
+
}
|
|
492
764
|
export {
|
|
493
765
|
FixedLayoutScopeChain,
|
|
494
766
|
FlowNodeScopeTypeEnum as FlowNodeScopeType,
|
|
495
767
|
FlowNodeVariableData,
|
|
496
768
|
FreeLayoutScopeChain,
|
|
497
|
-
|
|
769
|
+
GlobalScope,
|
|
770
|
+
ScopeChainTransformService,
|
|
771
|
+
VariableChainConfig,
|
|
772
|
+
bindGlobalScope,
|
|
773
|
+
getNodePrivateScope,
|
|
774
|
+
getNodeScope
|
|
498
775
|
};
|
|
499
776
|
//# sourceMappingURL=index.js.map
|