@flowgram.ai/variable-layout 0.1.1
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 +445 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
|
|
13
|
+
// src/flow-node-variable-data.ts
|
|
14
|
+
import { EntityData } from "@flowgram.ai/core";
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var FlowNodeScopeTypeEnum = /* @__PURE__ */ ((FlowNodeScopeTypeEnum2) => {
|
|
18
|
+
FlowNodeScopeTypeEnum2["public"] = "public";
|
|
19
|
+
FlowNodeScopeTypeEnum2["private"] = "private";
|
|
20
|
+
return FlowNodeScopeTypeEnum2;
|
|
21
|
+
})(FlowNodeScopeTypeEnum || {});
|
|
22
|
+
|
|
23
|
+
// src/flow-node-variable-data.ts
|
|
24
|
+
var FlowNodeVariableData = class extends EntityData {
|
|
25
|
+
constructor(entity, opts) {
|
|
26
|
+
super(entity);
|
|
27
|
+
this.opts = opts;
|
|
28
|
+
const { variableEngine } = opts || {};
|
|
29
|
+
this.variableEngine = variableEngine;
|
|
30
|
+
this._public = this.variableEngine.createScope(this.entity.id, {
|
|
31
|
+
node: this.entity,
|
|
32
|
+
type: "public" /* public */
|
|
33
|
+
});
|
|
34
|
+
this.toDispose.push(this._public);
|
|
35
|
+
}
|
|
36
|
+
get private() {
|
|
37
|
+
return this._private;
|
|
38
|
+
}
|
|
39
|
+
get public() {
|
|
40
|
+
return this._public;
|
|
41
|
+
}
|
|
42
|
+
get allScopes() {
|
|
43
|
+
const res = [];
|
|
44
|
+
if (this._public) {
|
|
45
|
+
res.push(this._public);
|
|
46
|
+
}
|
|
47
|
+
if (this._private) {
|
|
48
|
+
res.push(this._private);
|
|
49
|
+
}
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
getDefaultData() {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
initPrivate() {
|
|
56
|
+
if (!this._private) {
|
|
57
|
+
this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {
|
|
58
|
+
node: this.entity,
|
|
59
|
+
type: "private" /* private */
|
|
60
|
+
});
|
|
61
|
+
this._private.coverScopes.forEach((_scope) => {
|
|
62
|
+
_scope.refreshDeps();
|
|
63
|
+
});
|
|
64
|
+
this._private.depScopes.forEach((_scope) => {
|
|
65
|
+
_scope.refreshCovers();
|
|
66
|
+
});
|
|
67
|
+
this._private.available.refresh();
|
|
68
|
+
this.toDispose.push(this._private);
|
|
69
|
+
}
|
|
70
|
+
return this._private;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
FlowNodeVariableData.type = "FlowNodeVariableData";
|
|
74
|
+
|
|
75
|
+
// src/free-layout-scope-chain.ts
|
|
76
|
+
import { inject, optional, postConstruct } from "inversify";
|
|
77
|
+
import { ScopeChain } from "@flowgram.ai/variable-core";
|
|
78
|
+
import { FlowDocument } from "@flowgram.ai/document";
|
|
79
|
+
import { EntityManager } from "@flowgram.ai/core";
|
|
80
|
+
import { WorkflowNodeLinesData } from "@flowgram.ai/free-layout-core";
|
|
81
|
+
|
|
82
|
+
// src/variable-layout-config.ts
|
|
83
|
+
var VariableLayoutConfig = Symbol("VariableLayoutConfig");
|
|
84
|
+
|
|
85
|
+
// src/free-layout-scope-chain.ts
|
|
86
|
+
var FreeLayoutScopeChain = class extends ScopeChain {
|
|
87
|
+
get tree() {
|
|
88
|
+
return this.flowDocument.originTree;
|
|
89
|
+
}
|
|
90
|
+
onInit() {
|
|
91
|
+
this.toDispose.pushAll([
|
|
92
|
+
// 线条发生变化时,会触发作用域链的更新
|
|
93
|
+
this.entityManager.onEntityDataChange(({ entityDataType }) => {
|
|
94
|
+
if (entityDataType === WorkflowNodeLinesData.type) {
|
|
95
|
+
this.refreshAllChange();
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
// 树变化时候刷新作用域
|
|
99
|
+
this.tree.onTreeChange(() => {
|
|
100
|
+
this.refreshAllChange();
|
|
101
|
+
})
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
// 获取同一层级所有输入节点
|
|
105
|
+
getAllInputLayerNodes(curr) {
|
|
106
|
+
return (curr.getData(WorkflowNodeLinesData)?.allInputNodes || []).filter(
|
|
107
|
+
(_node) => _node.parent === curr.parent
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
// 获取同一层级所有输出节点
|
|
111
|
+
getAllOutputLayerNodes(curr) {
|
|
112
|
+
return (curr.getData(WorkflowNodeLinesData)?.allOutputNodes || []).filter(
|
|
113
|
+
(_node) => _node.parent === curr.parent
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
getDeps(scope) {
|
|
117
|
+
const { node } = scope.meta || {};
|
|
118
|
+
if (!node) {
|
|
119
|
+
return this.transformDeps([], { scope });
|
|
120
|
+
}
|
|
121
|
+
const scopes = [];
|
|
122
|
+
let curr = node;
|
|
123
|
+
while (curr) {
|
|
124
|
+
const allInputNodes = this.getAllInputLayerNodes(curr);
|
|
125
|
+
scopes.push(
|
|
126
|
+
...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
|
|
127
|
+
);
|
|
128
|
+
const currVarData = curr.getData(FlowNodeVariableData);
|
|
129
|
+
if (currVarData?.private && scope !== currVarData.private) {
|
|
130
|
+
scopes.push(currVarData.private);
|
|
131
|
+
}
|
|
132
|
+
curr = this.getParent(curr);
|
|
133
|
+
}
|
|
134
|
+
const uniqScopes = Array.from(new Set(scopes));
|
|
135
|
+
return this.transformDeps(uniqScopes, { scope });
|
|
136
|
+
}
|
|
137
|
+
getCovers(scope) {
|
|
138
|
+
const { node } = scope.meta || {};
|
|
139
|
+
if (!node) {
|
|
140
|
+
return this.transformCovers([], { scope });
|
|
141
|
+
}
|
|
142
|
+
const isPrivate = scope.meta.type === "private" /* private */;
|
|
143
|
+
const queue = [];
|
|
144
|
+
if (isPrivate) {
|
|
145
|
+
queue.push(...this.getChildren(node));
|
|
146
|
+
} else {
|
|
147
|
+
queue.push(...this.getAllOutputLayerNodes(node) || []);
|
|
148
|
+
}
|
|
149
|
+
const scopes = [];
|
|
150
|
+
while (queue.length) {
|
|
151
|
+
const _node = queue.shift();
|
|
152
|
+
const variableData = _node.getData(FlowNodeVariableData);
|
|
153
|
+
scopes.push(...variableData.allScopes);
|
|
154
|
+
const children = _node && this.getChildren(_node);
|
|
155
|
+
if (children?.length) {
|
|
156
|
+
queue.push(...children);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const currentVariableData = node.getData(FlowNodeVariableData);
|
|
160
|
+
if (isPrivate && currentVariableData.public) {
|
|
161
|
+
scopes.push(currentVariableData.public);
|
|
162
|
+
}
|
|
163
|
+
const uniqScopes = Array.from(new Set(scopes));
|
|
164
|
+
return this.transformCovers(uniqScopes, { scope });
|
|
165
|
+
}
|
|
166
|
+
transformCovers(covers, { scope }) {
|
|
167
|
+
return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
|
|
168
|
+
scope,
|
|
169
|
+
document: this.flowDocument,
|
|
170
|
+
variableEngine: this.variableEngine
|
|
171
|
+
}) : covers;
|
|
172
|
+
}
|
|
173
|
+
transformDeps(deps, { scope }) {
|
|
174
|
+
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
175
|
+
scope,
|
|
176
|
+
document: this.flowDocument,
|
|
177
|
+
variableEngine: this.variableEngine
|
|
178
|
+
}) : deps;
|
|
179
|
+
}
|
|
180
|
+
getChildren(node) {
|
|
181
|
+
if (this.configs?.getFreeChildren) {
|
|
182
|
+
return this.configs.getFreeChildren?.(node);
|
|
183
|
+
}
|
|
184
|
+
const nodeMeta = node.getNodeMeta();
|
|
185
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
186
|
+
if (subCanvas) {
|
|
187
|
+
if (subCanvas.isCanvas) {
|
|
188
|
+
return [];
|
|
189
|
+
} else {
|
|
190
|
+
return subCanvas.canvasNode.collapsedChildren;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return this.tree.getChildren(node);
|
|
194
|
+
}
|
|
195
|
+
getParent(node) {
|
|
196
|
+
if (this.configs?.getFreeParent) {
|
|
197
|
+
return this.configs.getFreeParent(node);
|
|
198
|
+
}
|
|
199
|
+
const initParent = node.document.originTree.getParent(node);
|
|
200
|
+
if (!initParent) {
|
|
201
|
+
return initParent;
|
|
202
|
+
}
|
|
203
|
+
const nodeMeta = initParent.getNodeMeta();
|
|
204
|
+
const subCanvas = nodeMeta.subCanvas?.(initParent);
|
|
205
|
+
if (subCanvas?.isCanvas) {
|
|
206
|
+
return subCanvas.parentNode;
|
|
207
|
+
}
|
|
208
|
+
return initParent;
|
|
209
|
+
}
|
|
210
|
+
sortAll() {
|
|
211
|
+
console.warn("FreeLayoutScopeChain.sortAll is not implemented");
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
__decorateClass([
|
|
216
|
+
inject(EntityManager)
|
|
217
|
+
], FreeLayoutScopeChain.prototype, "entityManager", 2);
|
|
218
|
+
__decorateClass([
|
|
219
|
+
inject(FlowDocument)
|
|
220
|
+
], FreeLayoutScopeChain.prototype, "flowDocument", 2);
|
|
221
|
+
__decorateClass([
|
|
222
|
+
optional(),
|
|
223
|
+
inject(VariableLayoutConfig)
|
|
224
|
+
], FreeLayoutScopeChain.prototype, "configs", 2);
|
|
225
|
+
__decorateClass([
|
|
226
|
+
postConstruct()
|
|
227
|
+
], FreeLayoutScopeChain.prototype, "onInit", 1);
|
|
228
|
+
|
|
229
|
+
// src/fixed-layout-scope-chain.ts
|
|
230
|
+
import { inject as inject2, optional as optional2 } from "inversify";
|
|
231
|
+
import { ScopeChain as ScopeChain2 } from "@flowgram.ai/variable-core";
|
|
232
|
+
import { FlowDocument as FlowDocument2 } from "@flowgram.ai/document";
|
|
233
|
+
var FixedLayoutScopeChain = class extends ScopeChain2 {
|
|
234
|
+
constructor(flowDocument, configs) {
|
|
235
|
+
super();
|
|
236
|
+
this.flowDocument = flowDocument;
|
|
237
|
+
this.configs = configs;
|
|
238
|
+
this.bindTree(flowDocument.originTree);
|
|
239
|
+
this.toDispose.push(
|
|
240
|
+
// REFRACTOR: onTreeChange 触发时机精细化
|
|
241
|
+
flowDocument.originTree.onTreeChange(() => {
|
|
242
|
+
this.refreshAllChange();
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
// 绑定树
|
|
247
|
+
bindTree(tree) {
|
|
248
|
+
this.tree = tree;
|
|
249
|
+
}
|
|
250
|
+
// 获取依赖作用域
|
|
251
|
+
getDeps(scope) {
|
|
252
|
+
if (!this.tree) {
|
|
253
|
+
return this.transformDeps([], { scope });
|
|
254
|
+
}
|
|
255
|
+
const node = scope.meta.node;
|
|
256
|
+
if (!node) {
|
|
257
|
+
return this.transformDeps([], { scope });
|
|
258
|
+
}
|
|
259
|
+
const deps = [];
|
|
260
|
+
let curr = node;
|
|
261
|
+
while (curr) {
|
|
262
|
+
const { parent, pre } = this.tree.getInfo(curr);
|
|
263
|
+
const currData = this.getVariableData(curr);
|
|
264
|
+
if (curr === node) {
|
|
265
|
+
if (scope.meta.type === "public" /* public */ && currData?.private) {
|
|
266
|
+
deps.unshift(currData.private);
|
|
267
|
+
}
|
|
268
|
+
} else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {
|
|
269
|
+
deps.unshift(
|
|
270
|
+
...this.getAllSortedChildScope(curr, {
|
|
271
|
+
ignoreNodeChildrenPrivate: true
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (currData && curr !== node) {
|
|
276
|
+
deps.unshift(currData.public);
|
|
277
|
+
}
|
|
278
|
+
if (pre) {
|
|
279
|
+
curr = pre;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (parent) {
|
|
283
|
+
let currParent = parent;
|
|
284
|
+
let currParentPre = this.tree.getPre(currParent);
|
|
285
|
+
while (currParent) {
|
|
286
|
+
const currParentData = this.getVariableData(currParent);
|
|
287
|
+
if (currParentData) {
|
|
288
|
+
deps.unshift(...currParentData.allScopes);
|
|
289
|
+
}
|
|
290
|
+
if (currParentPre) {
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
currParent = this.tree.getParent(currParent);
|
|
294
|
+
currParentPre = currParent ? this.tree.getPre(currParent) : void 0;
|
|
295
|
+
}
|
|
296
|
+
curr = currParentPre;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
curr = void 0;
|
|
300
|
+
}
|
|
301
|
+
return this.transformDeps(deps, { scope });
|
|
302
|
+
}
|
|
303
|
+
// 获取覆盖作用域
|
|
304
|
+
getCovers(scope) {
|
|
305
|
+
if (!this.tree) {
|
|
306
|
+
return this.transformCovers([], { scope });
|
|
307
|
+
}
|
|
308
|
+
const node = scope.meta.node;
|
|
309
|
+
if (!node) {
|
|
310
|
+
return this.transformCovers([], { scope });
|
|
311
|
+
}
|
|
312
|
+
const covers = [];
|
|
313
|
+
if (scope.meta.type === "private" /* private */) {
|
|
314
|
+
covers.push(
|
|
315
|
+
...this.getAllSortedChildScope(node, {
|
|
316
|
+
addNodePrivateScope: true
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
return this.transformCovers(covers, { scope });
|
|
320
|
+
}
|
|
321
|
+
let curr = node;
|
|
322
|
+
while (curr) {
|
|
323
|
+
const { next, parent } = this.tree.getInfo(curr);
|
|
324
|
+
const currData = this.getVariableData(curr);
|
|
325
|
+
if (curr !== node) {
|
|
326
|
+
if (this.hasChildren(curr)) {
|
|
327
|
+
covers.push(
|
|
328
|
+
...this.getAllSortedChildScope(curr, {
|
|
329
|
+
addNodePrivateScope: true
|
|
330
|
+
})
|
|
331
|
+
);
|
|
332
|
+
} else if (currData) {
|
|
333
|
+
covers.push(...currData.allScopes);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (next) {
|
|
337
|
+
curr = next;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (parent) {
|
|
341
|
+
let currParent = parent;
|
|
342
|
+
let currParentNext = this.tree.getNext(currParent);
|
|
343
|
+
while (currParent) {
|
|
344
|
+
if (this.isNodeChildrenPrivate(currParent)) {
|
|
345
|
+
return this.transformCovers(covers, { scope });
|
|
346
|
+
}
|
|
347
|
+
if (currParentNext) {
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
currParent = this.tree.getParent(currParent);
|
|
351
|
+
currParentNext = currParent ? this.tree.getNext(currParent) : void 0;
|
|
352
|
+
}
|
|
353
|
+
if (!currParentNext && currParent) {
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
curr = currParentNext;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
curr = void 0;
|
|
360
|
+
}
|
|
361
|
+
return this.transformCovers(covers, { scope });
|
|
362
|
+
}
|
|
363
|
+
transformCovers(covers, { scope }) {
|
|
364
|
+
return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
|
|
365
|
+
scope,
|
|
366
|
+
document: this.flowDocument,
|
|
367
|
+
variableEngine: this.variableEngine
|
|
368
|
+
}) : covers;
|
|
369
|
+
}
|
|
370
|
+
transformDeps(deps, { scope }) {
|
|
371
|
+
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
372
|
+
scope,
|
|
373
|
+
document: this.flowDocument,
|
|
374
|
+
variableEngine: this.variableEngine
|
|
375
|
+
}) : deps;
|
|
376
|
+
}
|
|
377
|
+
// 排序所有作用域
|
|
378
|
+
sortAll() {
|
|
379
|
+
const { startNodeId } = this.configs || {};
|
|
380
|
+
const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
|
|
381
|
+
if (!startNode) {
|
|
382
|
+
return [];
|
|
383
|
+
}
|
|
384
|
+
const startVariableData = startNode.getData(FlowNodeVariableData);
|
|
385
|
+
return [startVariableData.public, ...this.getCovers(startVariableData.public)];
|
|
386
|
+
}
|
|
387
|
+
// 获取变量 Data 数据
|
|
388
|
+
getVariableData(node) {
|
|
389
|
+
if (node.flowNodeType === "virtualNode") {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (node.id.startsWith("$")) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
return node.getData(FlowNodeVariableData);
|
|
396
|
+
}
|
|
397
|
+
// privateScope:子节点不可以被后续节点访问
|
|
398
|
+
isNodeChildrenPrivate(node) {
|
|
399
|
+
if (this.configs?.isNodeChildrenPrivate) {
|
|
400
|
+
return node ? this.configs?.isNodeChildrenPrivate(node) : false;
|
|
401
|
+
}
|
|
402
|
+
const isSystemNode = node?.id.startsWith("$");
|
|
403
|
+
return !isSystemNode && this.hasChildren(node);
|
|
404
|
+
}
|
|
405
|
+
hasChildren(node) {
|
|
406
|
+
return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);
|
|
407
|
+
}
|
|
408
|
+
// 子节点按照顺序进行排序(含自身)
|
|
409
|
+
getAllSortedChildScope(node, {
|
|
410
|
+
ignoreNodeChildrenPrivate,
|
|
411
|
+
addNodePrivateScope
|
|
412
|
+
} = {}) {
|
|
413
|
+
const scopes = [];
|
|
414
|
+
const variableData = this.getVariableData(node);
|
|
415
|
+
if (variableData) {
|
|
416
|
+
scopes.push(variableData.public);
|
|
417
|
+
}
|
|
418
|
+
if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {
|
|
419
|
+
return scopes;
|
|
420
|
+
}
|
|
421
|
+
if (addNodePrivateScope && variableData?.private) {
|
|
422
|
+
scopes.push(variableData.private);
|
|
423
|
+
}
|
|
424
|
+
const children = this.tree?.getChildren(node) || [];
|
|
425
|
+
scopes.push(
|
|
426
|
+
...children.map(
|
|
427
|
+
(child) => this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })
|
|
428
|
+
).flat()
|
|
429
|
+
);
|
|
430
|
+
return scopes;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
FixedLayoutScopeChain = __decorateClass([
|
|
434
|
+
__decorateParam(0, inject2(FlowDocument2)),
|
|
435
|
+
__decorateParam(1, optional2()),
|
|
436
|
+
__decorateParam(1, inject2(VariableLayoutConfig))
|
|
437
|
+
], FixedLayoutScopeChain);
|
|
438
|
+
export {
|
|
439
|
+
FixedLayoutScopeChain,
|
|
440
|
+
FlowNodeScopeTypeEnum as FlowNodeScopeType,
|
|
441
|
+
FlowNodeVariableData,
|
|
442
|
+
FreeLayoutScopeChain,
|
|
443
|
+
VariableLayoutConfig
|
|
444
|
+
};
|
|
445
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 { 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 的变量可以被 public 所访问,反之则不行\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 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. 通知 private 的覆盖作用域更新依赖\n this._private.coverScopes.forEach(_scope => {\n _scope.refreshDeps();\n });\n // 2. 通知 private 的依赖作用域更新覆盖\n this._private.depScopes.forEach(_scope => {\n _scope.refreshCovers();\n });\n // 3. private 自身需要刷新依赖\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":";;;;;;;;;;;;;AAEA,SAAS,kBAAkB;;;ACCpB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,YAAS;AACT,EAAAA,uBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;;;ADOL,IAAM,uBAAN,cAAmC,WAAW;AAAA,EAuCnD,YAAY,QAAiC,MAAe;AAC1D,UAAM,MAAM;AAD+B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,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
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Scope, VariableEngine, ScopeChain } from '@flowgram.ai/variable-core';
|
|
2
|
+
import { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';
|
|
3
|
+
import { EntityData, EntityManager } from '@flowgram.ai/core';
|
|
4
|
+
|
|
5
|
+
declare enum FlowNodeScopeTypeEnum {
|
|
6
|
+
public = "public",
|
|
7
|
+
private = "private"
|
|
8
|
+
}
|
|
9
|
+
interface FlowNodeScopeMeta {
|
|
10
|
+
node?: FlowNodeEntity;
|
|
11
|
+
type?: FlowNodeScopeTypeEnum;
|
|
12
|
+
}
|
|
13
|
+
interface ScopeVirtualNode {
|
|
14
|
+
id: string;
|
|
15
|
+
flowNodeType: 'virtualNode';
|
|
16
|
+
}
|
|
17
|
+
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
18
|
+
type FlowNodeScope = Scope<FlowNodeScopeMeta>;
|
|
19
|
+
|
|
20
|
+
interface Options {
|
|
21
|
+
variableEngine: VariableEngine;
|
|
22
|
+
}
|
|
23
|
+
declare class FlowNodeVariableData extends EntityData {
|
|
24
|
+
readonly opts: Options;
|
|
25
|
+
static type: string;
|
|
26
|
+
entity: FlowNodeEntity;
|
|
27
|
+
readonly variableEngine: VariableEngine;
|
|
28
|
+
/**
|
|
29
|
+
* private 的变量可以被 public 所访问,反之则不行
|
|
30
|
+
*/
|
|
31
|
+
protected _private?: FlowNodeScope;
|
|
32
|
+
protected _public: FlowNodeScope;
|
|
33
|
+
get private(): FlowNodeScope | undefined;
|
|
34
|
+
get public(): FlowNodeScope;
|
|
35
|
+
get allScopes(): FlowNodeScope[];
|
|
36
|
+
getDefaultData(): {};
|
|
37
|
+
constructor(entity: FlowNodeEntity, opts: Options);
|
|
38
|
+
initPrivate(): FlowNodeScope;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface TransformerContext {
|
|
42
|
+
scope: FlowNodeScope;
|
|
43
|
+
document: FlowDocument;
|
|
44
|
+
variableEngine: VariableEngine;
|
|
45
|
+
}
|
|
46
|
+
interface VariableLayoutConfig {
|
|
47
|
+
/**
|
|
48
|
+
* 开始节点的节点 Id
|
|
49
|
+
*/
|
|
50
|
+
startNodeId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
|
|
53
|
+
* @param node
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 用于自由画布场景,部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需要可配置化
|
|
59
|
+
*/
|
|
60
|
+
getFreeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
61
|
+
getFreeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* 对依赖作用域进行微调
|
|
64
|
+
*/
|
|
65
|
+
transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
66
|
+
/**
|
|
67
|
+
* 对依赖作用域进行微调
|
|
68
|
+
*/
|
|
69
|
+
transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
70
|
+
}
|
|
71
|
+
declare const VariableLayoutConfig: unique symbol;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 自由布局作用域链实现
|
|
75
|
+
*/
|
|
76
|
+
declare class FreeLayoutScopeChain extends ScopeChain {
|
|
77
|
+
entityManager: EntityManager;
|
|
78
|
+
protected flowDocument: FlowDocument;
|
|
79
|
+
protected configs?: VariableLayoutConfig;
|
|
80
|
+
get tree(): FlowVirtualTree<FlowNodeEntity>;
|
|
81
|
+
onInit(): void;
|
|
82
|
+
protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
83
|
+
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
84
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
85
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
86
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
87
|
+
scope: Scope;
|
|
88
|
+
}): Scope[];
|
|
89
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
90
|
+
scope: Scope;
|
|
91
|
+
}): Scope[];
|
|
92
|
+
getChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
93
|
+
getParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
94
|
+
sortAll(): Scope[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 基于 FlowVirtualTree 的 ScopeOrder 实现
|
|
99
|
+
*/
|
|
100
|
+
declare class FixedLayoutScopeChain extends ScopeChain {
|
|
101
|
+
protected flowDocument: FlowDocument;
|
|
102
|
+
protected configs?: VariableLayoutConfig | undefined;
|
|
103
|
+
tree: FlowVirtualTree<ScopeChainNode> | undefined;
|
|
104
|
+
constructor(flowDocument: FlowDocument, configs?: VariableLayoutConfig | undefined);
|
|
105
|
+
bindTree(tree: FlowVirtualTree<ScopeChainNode>): void;
|
|
106
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
107
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
108
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
109
|
+
scope: Scope;
|
|
110
|
+
}): Scope[];
|
|
111
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
112
|
+
scope: Scope;
|
|
113
|
+
}): Scope[];
|
|
114
|
+
sortAll(): Scope[];
|
|
115
|
+
private getVariableData;
|
|
116
|
+
private isNodeChildrenPrivate;
|
|
117
|
+
private hasChildren;
|
|
118
|
+
private getAllSortedChildScope;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Scope, VariableEngine, ScopeChain } from '@flowgram.ai/variable-core';
|
|
2
|
+
import { FlowNodeEntity, FlowDocument, FlowVirtualTree } from '@flowgram.ai/document';
|
|
3
|
+
import { EntityData, EntityManager } from '@flowgram.ai/core';
|
|
4
|
+
|
|
5
|
+
declare enum FlowNodeScopeTypeEnum {
|
|
6
|
+
public = "public",
|
|
7
|
+
private = "private"
|
|
8
|
+
}
|
|
9
|
+
interface FlowNodeScopeMeta {
|
|
10
|
+
node?: FlowNodeEntity;
|
|
11
|
+
type?: FlowNodeScopeTypeEnum;
|
|
12
|
+
}
|
|
13
|
+
interface ScopeVirtualNode {
|
|
14
|
+
id: string;
|
|
15
|
+
flowNodeType: 'virtualNode';
|
|
16
|
+
}
|
|
17
|
+
type ScopeChainNode = FlowNodeEntity | ScopeVirtualNode;
|
|
18
|
+
type FlowNodeScope = Scope<FlowNodeScopeMeta>;
|
|
19
|
+
|
|
20
|
+
interface Options {
|
|
21
|
+
variableEngine: VariableEngine;
|
|
22
|
+
}
|
|
23
|
+
declare class FlowNodeVariableData extends EntityData {
|
|
24
|
+
readonly opts: Options;
|
|
25
|
+
static type: string;
|
|
26
|
+
entity: FlowNodeEntity;
|
|
27
|
+
readonly variableEngine: VariableEngine;
|
|
28
|
+
/**
|
|
29
|
+
* private 的变量可以被 public 所访问,反之则不行
|
|
30
|
+
*/
|
|
31
|
+
protected _private?: FlowNodeScope;
|
|
32
|
+
protected _public: FlowNodeScope;
|
|
33
|
+
get private(): FlowNodeScope | undefined;
|
|
34
|
+
get public(): FlowNodeScope;
|
|
35
|
+
get allScopes(): FlowNodeScope[];
|
|
36
|
+
getDefaultData(): {};
|
|
37
|
+
constructor(entity: FlowNodeEntity, opts: Options);
|
|
38
|
+
initPrivate(): FlowNodeScope;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface TransformerContext {
|
|
42
|
+
scope: FlowNodeScope;
|
|
43
|
+
document: FlowDocument;
|
|
44
|
+
variableEngine: VariableEngine;
|
|
45
|
+
}
|
|
46
|
+
interface VariableLayoutConfig {
|
|
47
|
+
/**
|
|
48
|
+
* 开始节点的节点 Id
|
|
49
|
+
*/
|
|
50
|
+
startNodeId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 节点的子节点输出变量,不能被后续节点所访问,用于固定布局场景
|
|
53
|
+
* @param node
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
isNodeChildrenPrivate?: (node: ScopeChainNode) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 用于自由画布场景,部分场景通过连线或者其他交互形式来表达节点之间的父子关系,需要可配置化
|
|
59
|
+
*/
|
|
60
|
+
getFreeChildren?: (node: FlowNodeEntity) => FlowNodeEntity[];
|
|
61
|
+
getFreeParent?: (node: FlowNodeEntity) => FlowNodeEntity | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* 对依赖作用域进行微调
|
|
64
|
+
*/
|
|
65
|
+
transformDeps?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
66
|
+
/**
|
|
67
|
+
* 对依赖作用域进行微调
|
|
68
|
+
*/
|
|
69
|
+
transformCovers?: (scopes: Scope[], ctx: TransformerContext) => Scope[];
|
|
70
|
+
}
|
|
71
|
+
declare const VariableLayoutConfig: unique symbol;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 自由布局作用域链实现
|
|
75
|
+
*/
|
|
76
|
+
declare class FreeLayoutScopeChain extends ScopeChain {
|
|
77
|
+
entityManager: EntityManager;
|
|
78
|
+
protected flowDocument: FlowDocument;
|
|
79
|
+
protected configs?: VariableLayoutConfig;
|
|
80
|
+
get tree(): FlowVirtualTree<FlowNodeEntity>;
|
|
81
|
+
onInit(): void;
|
|
82
|
+
protected getAllInputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
83
|
+
protected getAllOutputLayerNodes(curr: FlowNodeEntity): FlowNodeEntity[];
|
|
84
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
85
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
86
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
87
|
+
scope: Scope;
|
|
88
|
+
}): Scope[];
|
|
89
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
90
|
+
scope: Scope;
|
|
91
|
+
}): Scope[];
|
|
92
|
+
getChildren(node: FlowNodeEntity): FlowNodeEntity[];
|
|
93
|
+
getParent(node: FlowNodeEntity): FlowNodeEntity | undefined;
|
|
94
|
+
sortAll(): Scope[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 基于 FlowVirtualTree 的 ScopeOrder 实现
|
|
99
|
+
*/
|
|
100
|
+
declare class FixedLayoutScopeChain extends ScopeChain {
|
|
101
|
+
protected flowDocument: FlowDocument;
|
|
102
|
+
protected configs?: VariableLayoutConfig | undefined;
|
|
103
|
+
tree: FlowVirtualTree<ScopeChainNode> | undefined;
|
|
104
|
+
constructor(flowDocument: FlowDocument, configs?: VariableLayoutConfig | undefined);
|
|
105
|
+
bindTree(tree: FlowVirtualTree<ScopeChainNode>): void;
|
|
106
|
+
getDeps(scope: FlowNodeScope): FlowNodeScope[];
|
|
107
|
+
getCovers(scope: FlowNodeScope): FlowNodeScope[];
|
|
108
|
+
protected transformCovers(covers: Scope[], { scope }: {
|
|
109
|
+
scope: Scope;
|
|
110
|
+
}): Scope[];
|
|
111
|
+
protected transformDeps(deps: Scope[], { scope }: {
|
|
112
|
+
scope: Scope;
|
|
113
|
+
}): Scope[];
|
|
114
|
+
sortAll(): Scope[];
|
|
115
|
+
private getVariableData;
|
|
116
|
+
private isNodeChildrenPrivate;
|
|
117
|
+
private hasChildren;
|
|
118
|
+
private getAllSortedChildScope;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { FixedLayoutScopeChain, type FlowNodeScope, type FlowNodeScopeMeta, FlowNodeScopeTypeEnum as FlowNodeScopeType, FlowNodeVariableData, FreeLayoutScopeChain, VariableLayoutConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
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
|
+
VariableLayoutConfig: () => VariableLayoutConfig
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
|
|
40
|
+
// src/flow-node-variable-data.ts
|
|
41
|
+
var import_core = require("@flowgram.ai/core");
|
|
42
|
+
|
|
43
|
+
// src/types.ts
|
|
44
|
+
var FlowNodeScopeTypeEnum = /* @__PURE__ */ ((FlowNodeScopeTypeEnum2) => {
|
|
45
|
+
FlowNodeScopeTypeEnum2["public"] = "public";
|
|
46
|
+
FlowNodeScopeTypeEnum2["private"] = "private";
|
|
47
|
+
return FlowNodeScopeTypeEnum2;
|
|
48
|
+
})(FlowNodeScopeTypeEnum || {});
|
|
49
|
+
|
|
50
|
+
// src/flow-node-variable-data.ts
|
|
51
|
+
var FlowNodeVariableData = class extends import_core.EntityData {
|
|
52
|
+
constructor(entity, opts) {
|
|
53
|
+
super(entity);
|
|
54
|
+
this.opts = opts;
|
|
55
|
+
const { variableEngine } = opts || {};
|
|
56
|
+
this.variableEngine = variableEngine;
|
|
57
|
+
this._public = this.variableEngine.createScope(this.entity.id, {
|
|
58
|
+
node: this.entity,
|
|
59
|
+
type: "public" /* public */
|
|
60
|
+
});
|
|
61
|
+
this.toDispose.push(this._public);
|
|
62
|
+
}
|
|
63
|
+
get private() {
|
|
64
|
+
return this._private;
|
|
65
|
+
}
|
|
66
|
+
get public() {
|
|
67
|
+
return this._public;
|
|
68
|
+
}
|
|
69
|
+
get allScopes() {
|
|
70
|
+
const res = [];
|
|
71
|
+
if (this._public) {
|
|
72
|
+
res.push(this._public);
|
|
73
|
+
}
|
|
74
|
+
if (this._private) {
|
|
75
|
+
res.push(this._private);
|
|
76
|
+
}
|
|
77
|
+
return res;
|
|
78
|
+
}
|
|
79
|
+
getDefaultData() {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
initPrivate() {
|
|
83
|
+
if (!this._private) {
|
|
84
|
+
this._private = this.variableEngine.createScope(`${this.entity.id}_private`, {
|
|
85
|
+
node: this.entity,
|
|
86
|
+
type: "private" /* private */
|
|
87
|
+
});
|
|
88
|
+
this._private.coverScopes.forEach((_scope) => {
|
|
89
|
+
_scope.refreshDeps();
|
|
90
|
+
});
|
|
91
|
+
this._private.depScopes.forEach((_scope) => {
|
|
92
|
+
_scope.refreshCovers();
|
|
93
|
+
});
|
|
94
|
+
this._private.available.refresh();
|
|
95
|
+
this.toDispose.push(this._private);
|
|
96
|
+
}
|
|
97
|
+
return this._private;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
FlowNodeVariableData.type = "FlowNodeVariableData";
|
|
101
|
+
|
|
102
|
+
// src/free-layout-scope-chain.ts
|
|
103
|
+
var import_inversify = require("inversify");
|
|
104
|
+
var import_variable_core = require("@flowgram.ai/variable-core");
|
|
105
|
+
var import_document = require("@flowgram.ai/document");
|
|
106
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
107
|
+
var import_free_layout_core = require("@flowgram.ai/free-layout-core");
|
|
108
|
+
|
|
109
|
+
// src/variable-layout-config.ts
|
|
110
|
+
var VariableLayoutConfig = Symbol("VariableLayoutConfig");
|
|
111
|
+
|
|
112
|
+
// src/free-layout-scope-chain.ts
|
|
113
|
+
var FreeLayoutScopeChain = class extends import_variable_core.ScopeChain {
|
|
114
|
+
get tree() {
|
|
115
|
+
return this.flowDocument.originTree;
|
|
116
|
+
}
|
|
117
|
+
onInit() {
|
|
118
|
+
this.toDispose.pushAll([
|
|
119
|
+
// 线条发生变化时,会触发作用域链的更新
|
|
120
|
+
this.entityManager.onEntityDataChange(({ entityDataType }) => {
|
|
121
|
+
if (entityDataType === import_free_layout_core.WorkflowNodeLinesData.type) {
|
|
122
|
+
this.refreshAllChange();
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
// 树变化时候刷新作用域
|
|
126
|
+
this.tree.onTreeChange(() => {
|
|
127
|
+
this.refreshAllChange();
|
|
128
|
+
})
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
// 获取同一层级所有输入节点
|
|
132
|
+
getAllInputLayerNodes(curr) {
|
|
133
|
+
return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allInputNodes || []).filter(
|
|
134
|
+
(_node) => _node.parent === curr.parent
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
// 获取同一层级所有输出节点
|
|
138
|
+
getAllOutputLayerNodes(curr) {
|
|
139
|
+
return (curr.getData(import_free_layout_core.WorkflowNodeLinesData)?.allOutputNodes || []).filter(
|
|
140
|
+
(_node) => _node.parent === curr.parent
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
getDeps(scope) {
|
|
144
|
+
const { node } = scope.meta || {};
|
|
145
|
+
if (!node) {
|
|
146
|
+
return this.transformDeps([], { scope });
|
|
147
|
+
}
|
|
148
|
+
const scopes = [];
|
|
149
|
+
let curr = node;
|
|
150
|
+
while (curr) {
|
|
151
|
+
const allInputNodes = this.getAllInputLayerNodes(curr);
|
|
152
|
+
scopes.push(
|
|
153
|
+
...allInputNodes.map((_node) => _node.getData(FlowNodeVariableData).public).filter(Boolean)
|
|
154
|
+
);
|
|
155
|
+
const currVarData = curr.getData(FlowNodeVariableData);
|
|
156
|
+
if (currVarData?.private && scope !== currVarData.private) {
|
|
157
|
+
scopes.push(currVarData.private);
|
|
158
|
+
}
|
|
159
|
+
curr = this.getParent(curr);
|
|
160
|
+
}
|
|
161
|
+
const uniqScopes = Array.from(new Set(scopes));
|
|
162
|
+
return this.transformDeps(uniqScopes, { scope });
|
|
163
|
+
}
|
|
164
|
+
getCovers(scope) {
|
|
165
|
+
const { node } = scope.meta || {};
|
|
166
|
+
if (!node) {
|
|
167
|
+
return this.transformCovers([], { scope });
|
|
168
|
+
}
|
|
169
|
+
const isPrivate = scope.meta.type === "private" /* private */;
|
|
170
|
+
const queue = [];
|
|
171
|
+
if (isPrivate) {
|
|
172
|
+
queue.push(...this.getChildren(node));
|
|
173
|
+
} else {
|
|
174
|
+
queue.push(...this.getAllOutputLayerNodes(node) || []);
|
|
175
|
+
}
|
|
176
|
+
const scopes = [];
|
|
177
|
+
while (queue.length) {
|
|
178
|
+
const _node = queue.shift();
|
|
179
|
+
const variableData = _node.getData(FlowNodeVariableData);
|
|
180
|
+
scopes.push(...variableData.allScopes);
|
|
181
|
+
const children = _node && this.getChildren(_node);
|
|
182
|
+
if (children?.length) {
|
|
183
|
+
queue.push(...children);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const currentVariableData = node.getData(FlowNodeVariableData);
|
|
187
|
+
if (isPrivate && currentVariableData.public) {
|
|
188
|
+
scopes.push(currentVariableData.public);
|
|
189
|
+
}
|
|
190
|
+
const uniqScopes = Array.from(new Set(scopes));
|
|
191
|
+
return this.transformCovers(uniqScopes, { scope });
|
|
192
|
+
}
|
|
193
|
+
transformCovers(covers, { scope }) {
|
|
194
|
+
return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
|
|
195
|
+
scope,
|
|
196
|
+
document: this.flowDocument,
|
|
197
|
+
variableEngine: this.variableEngine
|
|
198
|
+
}) : covers;
|
|
199
|
+
}
|
|
200
|
+
transformDeps(deps, { scope }) {
|
|
201
|
+
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
202
|
+
scope,
|
|
203
|
+
document: this.flowDocument,
|
|
204
|
+
variableEngine: this.variableEngine
|
|
205
|
+
}) : deps;
|
|
206
|
+
}
|
|
207
|
+
getChildren(node) {
|
|
208
|
+
if (this.configs?.getFreeChildren) {
|
|
209
|
+
return this.configs.getFreeChildren?.(node);
|
|
210
|
+
}
|
|
211
|
+
const nodeMeta = node.getNodeMeta();
|
|
212
|
+
const subCanvas = nodeMeta.subCanvas?.(node);
|
|
213
|
+
if (subCanvas) {
|
|
214
|
+
if (subCanvas.isCanvas) {
|
|
215
|
+
return [];
|
|
216
|
+
} else {
|
|
217
|
+
return subCanvas.canvasNode.collapsedChildren;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return this.tree.getChildren(node);
|
|
221
|
+
}
|
|
222
|
+
getParent(node) {
|
|
223
|
+
if (this.configs?.getFreeParent) {
|
|
224
|
+
return this.configs.getFreeParent(node);
|
|
225
|
+
}
|
|
226
|
+
const initParent = node.document.originTree.getParent(node);
|
|
227
|
+
if (!initParent) {
|
|
228
|
+
return initParent;
|
|
229
|
+
}
|
|
230
|
+
const nodeMeta = initParent.getNodeMeta();
|
|
231
|
+
const subCanvas = nodeMeta.subCanvas?.(initParent);
|
|
232
|
+
if (subCanvas?.isCanvas) {
|
|
233
|
+
return subCanvas.parentNode;
|
|
234
|
+
}
|
|
235
|
+
return initParent;
|
|
236
|
+
}
|
|
237
|
+
sortAll() {
|
|
238
|
+
console.warn("FreeLayoutScopeChain.sortAll is not implemented");
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
__decorateClass([
|
|
243
|
+
(0, import_inversify.inject)(import_core2.EntityManager)
|
|
244
|
+
], FreeLayoutScopeChain.prototype, "entityManager", 2);
|
|
245
|
+
__decorateClass([
|
|
246
|
+
(0, import_inversify.inject)(import_document.FlowDocument)
|
|
247
|
+
], FreeLayoutScopeChain.prototype, "flowDocument", 2);
|
|
248
|
+
__decorateClass([
|
|
249
|
+
(0, import_inversify.optional)(),
|
|
250
|
+
(0, import_inversify.inject)(VariableLayoutConfig)
|
|
251
|
+
], FreeLayoutScopeChain.prototype, "configs", 2);
|
|
252
|
+
__decorateClass([
|
|
253
|
+
(0, import_inversify.postConstruct)()
|
|
254
|
+
], FreeLayoutScopeChain.prototype, "onInit", 1);
|
|
255
|
+
|
|
256
|
+
// src/fixed-layout-scope-chain.ts
|
|
257
|
+
var import_inversify2 = require("inversify");
|
|
258
|
+
var import_variable_core2 = require("@flowgram.ai/variable-core");
|
|
259
|
+
var import_document2 = require("@flowgram.ai/document");
|
|
260
|
+
var FixedLayoutScopeChain = class extends import_variable_core2.ScopeChain {
|
|
261
|
+
constructor(flowDocument, configs) {
|
|
262
|
+
super();
|
|
263
|
+
this.flowDocument = flowDocument;
|
|
264
|
+
this.configs = configs;
|
|
265
|
+
this.bindTree(flowDocument.originTree);
|
|
266
|
+
this.toDispose.push(
|
|
267
|
+
// REFRACTOR: onTreeChange 触发时机精细化
|
|
268
|
+
flowDocument.originTree.onTreeChange(() => {
|
|
269
|
+
this.refreshAllChange();
|
|
270
|
+
})
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
// 绑定树
|
|
274
|
+
bindTree(tree) {
|
|
275
|
+
this.tree = tree;
|
|
276
|
+
}
|
|
277
|
+
// 获取依赖作用域
|
|
278
|
+
getDeps(scope) {
|
|
279
|
+
if (!this.tree) {
|
|
280
|
+
return this.transformDeps([], { scope });
|
|
281
|
+
}
|
|
282
|
+
const node = scope.meta.node;
|
|
283
|
+
if (!node) {
|
|
284
|
+
return this.transformDeps([], { scope });
|
|
285
|
+
}
|
|
286
|
+
const deps = [];
|
|
287
|
+
let curr = node;
|
|
288
|
+
while (curr) {
|
|
289
|
+
const { parent, pre } = this.tree.getInfo(curr);
|
|
290
|
+
const currData = this.getVariableData(curr);
|
|
291
|
+
if (curr === node) {
|
|
292
|
+
if (scope.meta.type === "public" /* public */ && currData?.private) {
|
|
293
|
+
deps.unshift(currData.private);
|
|
294
|
+
}
|
|
295
|
+
} else if (this.hasChildren(curr) && !this.isNodeChildrenPrivate(curr)) {
|
|
296
|
+
deps.unshift(
|
|
297
|
+
...this.getAllSortedChildScope(curr, {
|
|
298
|
+
ignoreNodeChildrenPrivate: true
|
|
299
|
+
})
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (currData && curr !== node) {
|
|
303
|
+
deps.unshift(currData.public);
|
|
304
|
+
}
|
|
305
|
+
if (pre) {
|
|
306
|
+
curr = pre;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (parent) {
|
|
310
|
+
let currParent = parent;
|
|
311
|
+
let currParentPre = this.tree.getPre(currParent);
|
|
312
|
+
while (currParent) {
|
|
313
|
+
const currParentData = this.getVariableData(currParent);
|
|
314
|
+
if (currParentData) {
|
|
315
|
+
deps.unshift(...currParentData.allScopes);
|
|
316
|
+
}
|
|
317
|
+
if (currParentPre) {
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
currParent = this.tree.getParent(currParent);
|
|
321
|
+
currParentPre = currParent ? this.tree.getPre(currParent) : void 0;
|
|
322
|
+
}
|
|
323
|
+
curr = currParentPre;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
curr = void 0;
|
|
327
|
+
}
|
|
328
|
+
return this.transformDeps(deps, { scope });
|
|
329
|
+
}
|
|
330
|
+
// 获取覆盖作用域
|
|
331
|
+
getCovers(scope) {
|
|
332
|
+
if (!this.tree) {
|
|
333
|
+
return this.transformCovers([], { scope });
|
|
334
|
+
}
|
|
335
|
+
const node = scope.meta.node;
|
|
336
|
+
if (!node) {
|
|
337
|
+
return this.transformCovers([], { scope });
|
|
338
|
+
}
|
|
339
|
+
const covers = [];
|
|
340
|
+
if (scope.meta.type === "private" /* private */) {
|
|
341
|
+
covers.push(
|
|
342
|
+
...this.getAllSortedChildScope(node, {
|
|
343
|
+
addNodePrivateScope: true
|
|
344
|
+
})
|
|
345
|
+
);
|
|
346
|
+
return this.transformCovers(covers, { scope });
|
|
347
|
+
}
|
|
348
|
+
let curr = node;
|
|
349
|
+
while (curr) {
|
|
350
|
+
const { next, parent } = this.tree.getInfo(curr);
|
|
351
|
+
const currData = this.getVariableData(curr);
|
|
352
|
+
if (curr !== node) {
|
|
353
|
+
if (this.hasChildren(curr)) {
|
|
354
|
+
covers.push(
|
|
355
|
+
...this.getAllSortedChildScope(curr, {
|
|
356
|
+
addNodePrivateScope: true
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
} else if (currData) {
|
|
360
|
+
covers.push(...currData.allScopes);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (next) {
|
|
364
|
+
curr = next;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (parent) {
|
|
368
|
+
let currParent = parent;
|
|
369
|
+
let currParentNext = this.tree.getNext(currParent);
|
|
370
|
+
while (currParent) {
|
|
371
|
+
if (this.isNodeChildrenPrivate(currParent)) {
|
|
372
|
+
return this.transformCovers(covers, { scope });
|
|
373
|
+
}
|
|
374
|
+
if (currParentNext) {
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
currParent = this.tree.getParent(currParent);
|
|
378
|
+
currParentNext = currParent ? this.tree.getNext(currParent) : void 0;
|
|
379
|
+
}
|
|
380
|
+
if (!currParentNext && currParent) {
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
curr = currParentNext;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
curr = void 0;
|
|
387
|
+
}
|
|
388
|
+
return this.transformCovers(covers, { scope });
|
|
389
|
+
}
|
|
390
|
+
transformCovers(covers, { scope }) {
|
|
391
|
+
return this.configs?.transformCovers ? this.configs.transformCovers(covers, {
|
|
392
|
+
scope,
|
|
393
|
+
document: this.flowDocument,
|
|
394
|
+
variableEngine: this.variableEngine
|
|
395
|
+
}) : covers;
|
|
396
|
+
}
|
|
397
|
+
transformDeps(deps, { scope }) {
|
|
398
|
+
return this.configs?.transformDeps ? this.configs.transformDeps(deps, {
|
|
399
|
+
scope,
|
|
400
|
+
document: this.flowDocument,
|
|
401
|
+
variableEngine: this.variableEngine
|
|
402
|
+
}) : deps;
|
|
403
|
+
}
|
|
404
|
+
// 排序所有作用域
|
|
405
|
+
sortAll() {
|
|
406
|
+
const { startNodeId } = this.configs || {};
|
|
407
|
+
const startNode = startNodeId ? this.flowDocument?.getNode(startNodeId) : void 0;
|
|
408
|
+
if (!startNode) {
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
const startVariableData = startNode.getData(FlowNodeVariableData);
|
|
412
|
+
return [startVariableData.public, ...this.getCovers(startVariableData.public)];
|
|
413
|
+
}
|
|
414
|
+
// 获取变量 Data 数据
|
|
415
|
+
getVariableData(node) {
|
|
416
|
+
if (node.flowNodeType === "virtualNode") {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (node.id.startsWith("$")) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
return node.getData(FlowNodeVariableData);
|
|
423
|
+
}
|
|
424
|
+
// privateScope:子节点不可以被后续节点访问
|
|
425
|
+
isNodeChildrenPrivate(node) {
|
|
426
|
+
if (this.configs?.isNodeChildrenPrivate) {
|
|
427
|
+
return node ? this.configs?.isNodeChildrenPrivate(node) : false;
|
|
428
|
+
}
|
|
429
|
+
const isSystemNode = node?.id.startsWith("$");
|
|
430
|
+
return !isSystemNode && this.hasChildren(node);
|
|
431
|
+
}
|
|
432
|
+
hasChildren(node) {
|
|
433
|
+
return Boolean(this.tree && node && this.tree.getChildren(node).length > 0);
|
|
434
|
+
}
|
|
435
|
+
// 子节点按照顺序进行排序(含自身)
|
|
436
|
+
getAllSortedChildScope(node, {
|
|
437
|
+
ignoreNodeChildrenPrivate,
|
|
438
|
+
addNodePrivateScope
|
|
439
|
+
} = {}) {
|
|
440
|
+
const scopes = [];
|
|
441
|
+
const variableData = this.getVariableData(node);
|
|
442
|
+
if (variableData) {
|
|
443
|
+
scopes.push(variableData.public);
|
|
444
|
+
}
|
|
445
|
+
if (ignoreNodeChildrenPrivate && this.isNodeChildrenPrivate(node)) {
|
|
446
|
+
return scopes;
|
|
447
|
+
}
|
|
448
|
+
if (addNodePrivateScope && variableData?.private) {
|
|
449
|
+
scopes.push(variableData.private);
|
|
450
|
+
}
|
|
451
|
+
const children = this.tree?.getChildren(node) || [];
|
|
452
|
+
scopes.push(
|
|
453
|
+
...children.map(
|
|
454
|
+
(child) => this.getAllSortedChildScope(child, { ignoreNodeChildrenPrivate, addNodePrivateScope })
|
|
455
|
+
).flat()
|
|
456
|
+
);
|
|
457
|
+
return scopes;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
FixedLayoutScopeChain = __decorateClass([
|
|
461
|
+
__decorateParam(0, (0, import_inversify2.inject)(import_document2.FlowDocument)),
|
|
462
|
+
__decorateParam(1, (0, import_inversify2.optional)()),
|
|
463
|
+
__decorateParam(1, (0, import_inversify2.inject)(VariableLayoutConfig))
|
|
464
|
+
], FixedLayoutScopeChain);
|
|
465
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
466
|
+
0 && (module.exports = {
|
|
467
|
+
FixedLayoutScopeChain,
|
|
468
|
+
FlowNodeScopeType,
|
|
469
|
+
FlowNodeVariableData,
|
|
470
|
+
FreeLayoutScopeChain,
|
|
471
|
+
VariableLayoutConfig
|
|
472
|
+
});
|
|
473
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 { 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 的变量可以被 public 所访问,反之则不行\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 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. 通知 private 的覆盖作用域更新依赖\n this._private.coverScopes.forEach(_scope => {\n _scope.refreshDeps();\n });\n // 2. 通知 private 的依赖作用域更新覆盖\n this._private.depScopes.forEach(_scope => {\n _scope.refreshCovers();\n });\n // 3. private 自身需要刷新依赖\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;;;ACEA,kBAA2B;;;ACCpB,IAAK,wBAAL,kBAAKA,2BAAL;AACL,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AAC;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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/variable-layout",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"import": "./dist/esm/index.js",
|
|
8
|
+
"require": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/esm/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"inversify": "^6.0.1",
|
|
18
|
+
"reflect-metadata": "^0.1.13",
|
|
19
|
+
"styled-components": "^5",
|
|
20
|
+
"@flowgram.ai/core": "0.1.1",
|
|
21
|
+
"@flowgram.ai/utils": "0.1.1",
|
|
22
|
+
"@flowgram.ai/variable-core": "0.1.1",
|
|
23
|
+
"@flowgram.ai/document": "0.1.1",
|
|
24
|
+
"@flowgram.ai/free-layout-core": "0.1.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
28
|
+
"eslint": "^8.54.0",
|
|
29
|
+
"tsup": "^8.0.1",
|
|
30
|
+
"typescript": "^5.0.4",
|
|
31
|
+
"vitest": "^0.34.6",
|
|
32
|
+
"@flowgram.ai/eslint-config": "0.1.1",
|
|
33
|
+
"@flowgram.ai/ts-config": "0.1.1"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org/"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
41
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
42
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:cov": "vitest run --coverage",
|
|
46
|
+
"ts-check": "tsc --noEmit",
|
|
47
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
48
|
+
}
|
|
49
|
+
}
|