@flowgram.ai/free-stack-plugin 0.1.0
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 +415 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +443 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,415 @@
|
|
|
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
|
+
|
|
12
|
+
// src/create-free-stack-plugin.ts
|
|
13
|
+
import { definePluginCreator } from "@flowgram.ai/core";
|
|
14
|
+
|
|
15
|
+
// src/manager.ts
|
|
16
|
+
import { debounce } from "lodash";
|
|
17
|
+
import { inject, injectable } from "inversify";
|
|
18
|
+
import { FlowNodeRenderData as FlowNodeRenderData2 } from "@flowgram.ai/document";
|
|
19
|
+
import { EntityManager, PipelineRegistry, PipelineRenderer } from "@flowgram.ai/core";
|
|
20
|
+
import {
|
|
21
|
+
WorkflowHoverService,
|
|
22
|
+
WorkflowNodeEntity as WorkflowNodeEntity2,
|
|
23
|
+
WorkflowSelectService
|
|
24
|
+
} from "@flowgram.ai/free-layout-core";
|
|
25
|
+
import { WorkflowLineEntity } from "@flowgram.ai/free-layout-core";
|
|
26
|
+
import { WorkflowDocument } from "@flowgram.ai/free-layout-core";
|
|
27
|
+
import { domUtils } from "@flowgram.ai/utils";
|
|
28
|
+
|
|
29
|
+
// src/stacking-computing.ts
|
|
30
|
+
import { FlowNodeBaseType } from "@flowgram.ai/document";
|
|
31
|
+
import { WorkflowNodeLinesData } from "@flowgram.ai/free-layout-core";
|
|
32
|
+
var StackingComputing = class {
|
|
33
|
+
compute(params) {
|
|
34
|
+
this.clearCache();
|
|
35
|
+
const { root, nodes, context } = params;
|
|
36
|
+
this.context = context;
|
|
37
|
+
this.nodeIndexes = this.computeNodeIndexesMap(nodes);
|
|
38
|
+
this.topLevel = this.computeTopLevel(nodes);
|
|
39
|
+
this.maxLevel = this.topLevel * 2;
|
|
40
|
+
this.layerHandler(root.collapsedChildren);
|
|
41
|
+
return {
|
|
42
|
+
nodeLevel: this.nodeLevel,
|
|
43
|
+
lineLevel: this.lineLevel,
|
|
44
|
+
topLevel: this.topLevel,
|
|
45
|
+
maxLevel: this.maxLevel
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
clearCache() {
|
|
49
|
+
this.currentLevel = 0;
|
|
50
|
+
this.topLevel = 0;
|
|
51
|
+
this.maxLevel = 0;
|
|
52
|
+
this.nodeIndexes = /* @__PURE__ */ new Map();
|
|
53
|
+
this.nodeLevel = /* @__PURE__ */ new Map();
|
|
54
|
+
this.lineLevel = /* @__PURE__ */ new Map();
|
|
55
|
+
}
|
|
56
|
+
computeNodeIndexesMap(nodes) {
|
|
57
|
+
const nodeIndexMap = /* @__PURE__ */ new Map();
|
|
58
|
+
nodes.forEach((node, index) => {
|
|
59
|
+
nodeIndexMap.set(node.id, index);
|
|
60
|
+
});
|
|
61
|
+
return nodeIndexMap;
|
|
62
|
+
}
|
|
63
|
+
computeTopLevel(nodes) {
|
|
64
|
+
const nodesWithoutRoot = nodes.filter((node) => node.id !== FlowNodeBaseType.ROOT);
|
|
65
|
+
const nodeHasChildren = nodesWithoutRoot.reduce((count, node) => {
|
|
66
|
+
if (node.collapsedChildren.length > 0) {
|
|
67
|
+
return count + 1;
|
|
68
|
+
} else {
|
|
69
|
+
return count;
|
|
70
|
+
}
|
|
71
|
+
}, 0);
|
|
72
|
+
return nodesWithoutRoot.length + nodeHasChildren + 1;
|
|
73
|
+
}
|
|
74
|
+
layerHandler(nodes, pinTop = false) {
|
|
75
|
+
const sortedNodes = nodes.sort((a, b) => {
|
|
76
|
+
const aIndex = this.nodeIndexes.get(a.id);
|
|
77
|
+
const bIndex = this.nodeIndexes.get(b.id);
|
|
78
|
+
if (aIndex === void 0 || bIndex === void 0) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
return aIndex - bIndex;
|
|
82
|
+
});
|
|
83
|
+
const lines = nodes.map((node) => {
|
|
84
|
+
const linesData = node.getData(WorkflowNodeLinesData);
|
|
85
|
+
const outputLines = linesData.outputLines.filter(Boolean);
|
|
86
|
+
const inputLines = linesData.inputLines.filter(Boolean);
|
|
87
|
+
return [...outputLines, ...inputLines];
|
|
88
|
+
}).flat();
|
|
89
|
+
lines.forEach((line) => {
|
|
90
|
+
if (line.isDrawing || // 正在绘制
|
|
91
|
+
this.context.hoveredEntityID === line.id || // hover
|
|
92
|
+
this.context.selectedIDs.includes(line.id)) {
|
|
93
|
+
this.lineLevel.set(line.id, this.maxLevel);
|
|
94
|
+
} else {
|
|
95
|
+
this.lineLevel.set(line.id, this.getLevel(pinTop));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.levelIncrease();
|
|
99
|
+
sortedNodes.forEach((node) => {
|
|
100
|
+
const selected = this.context.selectedIDs.includes(node.id);
|
|
101
|
+
if (selected) {
|
|
102
|
+
this.nodeLevel.set(node.id, this.topLevel);
|
|
103
|
+
} else {
|
|
104
|
+
this.nodeLevel.set(node.id, this.getLevel(pinTop));
|
|
105
|
+
}
|
|
106
|
+
this.levelIncrease();
|
|
107
|
+
if (node.collapsedChildren.length > 0) {
|
|
108
|
+
this.layerHandler(node.collapsedChildren, pinTop || selected);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getLevel(pinTop) {
|
|
113
|
+
if (pinTop) {
|
|
114
|
+
return this.topLevel + this.currentLevel;
|
|
115
|
+
}
|
|
116
|
+
return this.currentLevel;
|
|
117
|
+
}
|
|
118
|
+
levelIncrease() {
|
|
119
|
+
this.currentLevel += 1;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/layers-computing.ts
|
|
124
|
+
import { FlowNodeRenderData } from "@flowgram.ai/document";
|
|
125
|
+
|
|
126
|
+
// src/constant.ts
|
|
127
|
+
var StackingItem = /* @__PURE__ */ ((StackingItem2) => {
|
|
128
|
+
StackingItem2["Line"] = "line";
|
|
129
|
+
StackingItem2["Node"] = "node";
|
|
130
|
+
return StackingItem2;
|
|
131
|
+
})(StackingItem || {});
|
|
132
|
+
var StackingType = /* @__PURE__ */ ((StackingType2) => {
|
|
133
|
+
StackingType2["Line"] = "line" /* Line */;
|
|
134
|
+
StackingType2["Node"] = "node" /* Node */;
|
|
135
|
+
return StackingType2;
|
|
136
|
+
})(StackingType || {});
|
|
137
|
+
var StackingBaseIndex = {
|
|
138
|
+
["line" /* Line */]: 0,
|
|
139
|
+
["node" /* Node */]: 1
|
|
140
|
+
};
|
|
141
|
+
var startIndex = 8;
|
|
142
|
+
var allowLevel = 2;
|
|
143
|
+
var levelIndexStep = Object.keys(StackingType).length;
|
|
144
|
+
var maxLevel = allowLevel * 2;
|
|
145
|
+
var maxIndex = startIndex + maxLevel * levelIndexStep;
|
|
146
|
+
var StackingConfig = {
|
|
147
|
+
/** index 起始值 */
|
|
148
|
+
startIndex,
|
|
149
|
+
/** 允许存在的层级 */
|
|
150
|
+
allowLevel,
|
|
151
|
+
/** 每层 index 跨度 */
|
|
152
|
+
levelIndexStep,
|
|
153
|
+
/** 叠加计算后出现的最深层级 */
|
|
154
|
+
maxLevel,
|
|
155
|
+
/** 最大 index */
|
|
156
|
+
maxIndex
|
|
157
|
+
};
|
|
158
|
+
var StackingComputeMode = /* @__PURE__ */ ((StackingComputeMode2) => {
|
|
159
|
+
StackingComputeMode2["Stacking"] = "stacking";
|
|
160
|
+
StackingComputeMode2["Layers"] = "layers";
|
|
161
|
+
return StackingComputeMode2;
|
|
162
|
+
})(StackingComputeMode || {});
|
|
163
|
+
|
|
164
|
+
// src/layers-computing.ts
|
|
165
|
+
var NodeComputing;
|
|
166
|
+
((NodeComputing2) => {
|
|
167
|
+
NodeComputing2.compute = (node, context) => {
|
|
168
|
+
const zIndex = nodeZIndex(node, context);
|
|
169
|
+
const element = nodeElement(node);
|
|
170
|
+
element.style.position = "absolute";
|
|
171
|
+
element.style.zIndex = (0, NodeComputing2.zIndexStringify)(zIndex);
|
|
172
|
+
};
|
|
173
|
+
NodeComputing2.stackingIndex = (stackingType, level) => {
|
|
174
|
+
if (level < 1) {
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
const baseZIndex = StackingBaseIndex[stackingType];
|
|
178
|
+
const zIndex = StackingConfig.startIndex + StackingConfig.levelIndexStep * (level - 1) + baseZIndex;
|
|
179
|
+
return zIndex;
|
|
180
|
+
};
|
|
181
|
+
NodeComputing2.nodeStackingLevel = (node, context, disableTopLevel = false) => {
|
|
182
|
+
const unReversedLinage = [];
|
|
183
|
+
let currentNode = node;
|
|
184
|
+
while (currentNode) {
|
|
185
|
+
unReversedLinage.push(currentNode);
|
|
186
|
+
currentNode = currentNode.parent;
|
|
187
|
+
}
|
|
188
|
+
const linage = unReversedLinage.reverse();
|
|
189
|
+
const nodeLevel = linage.length - 1;
|
|
190
|
+
const topLevelIndex = linage.findIndex((node2) => {
|
|
191
|
+
if (context.selectedIDs.includes(node2.id)) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
});
|
|
196
|
+
const topLevel = StackingConfig.allowLevel + (linage.length - topLevelIndex);
|
|
197
|
+
if (!disableTopLevel && topLevelIndex !== -1) {
|
|
198
|
+
return topLevel;
|
|
199
|
+
}
|
|
200
|
+
return nodeLevel;
|
|
201
|
+
};
|
|
202
|
+
NodeComputing2.zIndexStringify = (zIndex) => {
|
|
203
|
+
if (zIndex === void 0) {
|
|
204
|
+
return "auto";
|
|
205
|
+
}
|
|
206
|
+
return zIndex.toString();
|
|
207
|
+
};
|
|
208
|
+
const nodeZIndex = (node, context) => {
|
|
209
|
+
const level = (0, NodeComputing2.nodeStackingLevel)(node, context);
|
|
210
|
+
const zIndex = (0, NodeComputing2.stackingIndex)("node" /* Node */, level);
|
|
211
|
+
return zIndex;
|
|
212
|
+
};
|
|
213
|
+
const nodeElement = (node) => {
|
|
214
|
+
const nodeRenderData = node.getData(FlowNodeRenderData);
|
|
215
|
+
return nodeRenderData.node;
|
|
216
|
+
};
|
|
217
|
+
})(NodeComputing || (NodeComputing = {}));
|
|
218
|
+
var LineComputing;
|
|
219
|
+
((LineComputing2) => {
|
|
220
|
+
LineComputing2.compute = (line, context) => {
|
|
221
|
+
const zIndex = lineZIndex(line, context);
|
|
222
|
+
const element = line.node;
|
|
223
|
+
element.style.position = "absolute";
|
|
224
|
+
element.style.zIndex = NodeComputing.zIndexStringify(zIndex);
|
|
225
|
+
};
|
|
226
|
+
const lineStackingLevel = (line, context) => {
|
|
227
|
+
if (line.isDrawing || // 正在绘制
|
|
228
|
+
context.hoveredEntityID === line.id || // hover
|
|
229
|
+
context.selectedIDs.includes(line.id)) {
|
|
230
|
+
return StackingConfig.maxLevel + 1;
|
|
231
|
+
}
|
|
232
|
+
const fromLevel = NodeComputing.nodeStackingLevel(line.from, context, true);
|
|
233
|
+
if (!line.to) {
|
|
234
|
+
return fromLevel;
|
|
235
|
+
}
|
|
236
|
+
const toLevel = NodeComputing.nodeStackingLevel(line.to, context, true);
|
|
237
|
+
const level = Math.min(fromLevel, toLevel);
|
|
238
|
+
return level;
|
|
239
|
+
};
|
|
240
|
+
const lineZIndex = (line, context) => {
|
|
241
|
+
const level = lineStackingLevel(line, context);
|
|
242
|
+
const zIndex = NodeComputing.stackingIndex("line" /* Line */, level);
|
|
243
|
+
return zIndex;
|
|
244
|
+
};
|
|
245
|
+
})(LineComputing || (LineComputing = {}));
|
|
246
|
+
var layersComputing = (params) => {
|
|
247
|
+
const { nodes, lines, context } = params;
|
|
248
|
+
nodes.forEach((node) => {
|
|
249
|
+
NodeComputing.compute(node, context);
|
|
250
|
+
});
|
|
251
|
+
lines.forEach((line) => {
|
|
252
|
+
LineComputing.compute(line, context);
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/manager.ts
|
|
257
|
+
var StackingContextManager = class {
|
|
258
|
+
constructor() {
|
|
259
|
+
this.node = domUtils.createDivWithClass(
|
|
260
|
+
"gedit-playground-layer gedit-flow-render-layer"
|
|
261
|
+
);
|
|
262
|
+
this.disposers = [];
|
|
263
|
+
this.mode = "stacking" /* Stacking */;
|
|
264
|
+
/**
|
|
265
|
+
* 触发计算
|
|
266
|
+
* 10ms内仅计算一次
|
|
267
|
+
*/
|
|
268
|
+
this.compute = debounce(this._compute, 10);
|
|
269
|
+
}
|
|
270
|
+
init(mode) {
|
|
271
|
+
if (mode) this.mode = mode;
|
|
272
|
+
this.pipelineRenderer.node.appendChild(this.node);
|
|
273
|
+
this.mountListener();
|
|
274
|
+
}
|
|
275
|
+
ready() {
|
|
276
|
+
this.compute();
|
|
277
|
+
}
|
|
278
|
+
dispose() {
|
|
279
|
+
this.disposers.forEach((disposer) => disposer.dispose());
|
|
280
|
+
}
|
|
281
|
+
_compute() {
|
|
282
|
+
if (this.mode === "stacking" /* Stacking */) {
|
|
283
|
+
return this.stackingCompute();
|
|
284
|
+
} else {
|
|
285
|
+
return layersComputing({
|
|
286
|
+
nodes: this.nodes,
|
|
287
|
+
lines: this.lines,
|
|
288
|
+
context: this.context
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
stackingCompute() {
|
|
293
|
+
const context = this.context;
|
|
294
|
+
const stackingComputing = new StackingComputing();
|
|
295
|
+
const { nodeLevel, lineLevel } = stackingComputing.compute({
|
|
296
|
+
root: this.document.root,
|
|
297
|
+
nodes: this.nodes,
|
|
298
|
+
context
|
|
299
|
+
});
|
|
300
|
+
this.nodes.forEach((node) => {
|
|
301
|
+
const level = nodeLevel.get(node.id);
|
|
302
|
+
const nodeRenderData = node.getData(FlowNodeRenderData2);
|
|
303
|
+
const element = nodeRenderData.node;
|
|
304
|
+
element.style.position = "absolute";
|
|
305
|
+
if (!level) {
|
|
306
|
+
element.style.zIndex = "auto";
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
element.style.zIndex = String(StackingConfig.startIndex + level);
|
|
310
|
+
});
|
|
311
|
+
this.lines.forEach((line) => {
|
|
312
|
+
const level = lineLevel.get(line.id);
|
|
313
|
+
const element = line.node;
|
|
314
|
+
element.style.position = "absolute";
|
|
315
|
+
if (!level) {
|
|
316
|
+
element.style.zIndex = "auto";
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
element.style.zIndex = String(StackingConfig.startIndex + level);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
get nodes() {
|
|
323
|
+
return this.entityManager.getEntities(WorkflowNodeEntity2);
|
|
324
|
+
}
|
|
325
|
+
get lines() {
|
|
326
|
+
return this.entityManager.getEntities(WorkflowLineEntity);
|
|
327
|
+
}
|
|
328
|
+
get context() {
|
|
329
|
+
return {
|
|
330
|
+
hoveredEntity: this.hoverService.hoveredNode,
|
|
331
|
+
hoveredEntityID: this.hoverService.hoveredNode?.id,
|
|
332
|
+
selectedEntities: this.selectService.selection,
|
|
333
|
+
selectedIDs: this.selectService.selection.map((entity) => entity.id)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
mountListener() {
|
|
337
|
+
const entityChangeDisposer = this.onEntityChange();
|
|
338
|
+
const zoomDisposer = this.onZoom();
|
|
339
|
+
const hoverDisposer = this.onHover();
|
|
340
|
+
const selectDisposer = this.onSelect();
|
|
341
|
+
this.disposers = [entityChangeDisposer, zoomDisposer, hoverDisposer, selectDisposer];
|
|
342
|
+
}
|
|
343
|
+
onZoom() {
|
|
344
|
+
return this.pipelineRegistry.onZoom((scale) => {
|
|
345
|
+
this.node.style.transform = `scale(${scale})`;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
onHover() {
|
|
349
|
+
return this.hoverService.onHoveredChange(() => {
|
|
350
|
+
this.compute();
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
onEntityChange() {
|
|
354
|
+
return this.entityManager.onEntityChange(() => {
|
|
355
|
+
this.compute();
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
onSelect() {
|
|
359
|
+
return this.selectService.onSelectionChanged(() => {
|
|
360
|
+
this.compute();
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
__decorateClass([
|
|
365
|
+
inject(WorkflowDocument)
|
|
366
|
+
], StackingContextManager.prototype, "document", 2);
|
|
367
|
+
__decorateClass([
|
|
368
|
+
inject(EntityManager)
|
|
369
|
+
], StackingContextManager.prototype, "entityManager", 2);
|
|
370
|
+
__decorateClass([
|
|
371
|
+
inject(PipelineRenderer)
|
|
372
|
+
], StackingContextManager.prototype, "pipelineRenderer", 2);
|
|
373
|
+
__decorateClass([
|
|
374
|
+
inject(PipelineRegistry)
|
|
375
|
+
], StackingContextManager.prototype, "pipelineRegistry", 2);
|
|
376
|
+
__decorateClass([
|
|
377
|
+
inject(WorkflowHoverService)
|
|
378
|
+
], StackingContextManager.prototype, "hoverService", 2);
|
|
379
|
+
__decorateClass([
|
|
380
|
+
inject(WorkflowSelectService)
|
|
381
|
+
], StackingContextManager.prototype, "selectService", 2);
|
|
382
|
+
StackingContextManager = __decorateClass([
|
|
383
|
+
injectable()
|
|
384
|
+
], StackingContextManager);
|
|
385
|
+
|
|
386
|
+
// src/create-free-stack-plugin.ts
|
|
387
|
+
var createFreeStackPlugin = definePluginCreator({
|
|
388
|
+
onBind({ bind }) {
|
|
389
|
+
bind(StackingContextManager).toSelf().inSingletonScope();
|
|
390
|
+
},
|
|
391
|
+
onInit(ctx, opts) {
|
|
392
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
393
|
+
stackingContextManager.init(opts?.mode);
|
|
394
|
+
},
|
|
395
|
+
onReady(ctx) {
|
|
396
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
397
|
+
stackingContextManager.ready();
|
|
398
|
+
},
|
|
399
|
+
onDispose(ctx) {
|
|
400
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
401
|
+
stackingContextManager.dispose();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
export {
|
|
405
|
+
StackingBaseIndex,
|
|
406
|
+
StackingComputeMode,
|
|
407
|
+
StackingComputing,
|
|
408
|
+
StackingConfig,
|
|
409
|
+
StackingContextManager,
|
|
410
|
+
StackingItem,
|
|
411
|
+
StackingType,
|
|
412
|
+
createFreeStackPlugin,
|
|
413
|
+
layersComputing
|
|
414
|
+
};
|
|
415
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/create-free-stack-plugin.ts","../../src/manager.ts","../../src/stacking-computing.ts","../../src/layers-computing.ts","../../src/constant.ts"],"sourcesContent":["import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { StackingContextManager } from './manager';\nimport { StackingComputeMode } from './constant';\n\nexport const createFreeStackPlugin = definePluginCreator<{\n mode?: StackingComputeMode;\n}>({\n onBind({ bind }) {\n bind(StackingContextManager).toSelf().inSingletonScope();\n },\n onInit(ctx, opts) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.init(opts?.mode);\n },\n onReady(ctx) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.ready();\n },\n onDispose(ctx) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.dispose();\n },\n});\n","import { debounce } from 'lodash';\nimport { inject, injectable } from 'inversify';\nimport { FlowNodeRenderData } from '@flowgram.ai/document';\nimport { EntityManager, PipelineRegistry, PipelineRenderer } from '@flowgram.ai/core';\nimport {\n WorkflowHoverService,\n WorkflowNodeEntity,\n WorkflowSelectService,\n} from '@flowgram.ai/free-layout-core';\nimport { WorkflowLineEntity } from '@flowgram.ai/free-layout-core';\nimport { WorkflowDocument } from '@flowgram.ai/free-layout-core';\nimport { domUtils } from '@flowgram.ai/utils';\nimport { Disposable } from '@flowgram.ai/utils';\n\nimport type { StackingContext } from './type';\nimport { StackingComputing } from './stacking-computing';\nimport { layersComputing } from './layers-computing';\nimport { StackingComputeMode, StackingConfig } from './constant';\n\n@injectable()\nexport class StackingContextManager {\n @inject(WorkflowDocument) private readonly document: WorkflowDocument;\n\n @inject(EntityManager) private readonly entityManager: EntityManager;\n\n @inject(PipelineRenderer)\n private readonly pipelineRenderer: PipelineRenderer;\n\n @inject(PipelineRegistry)\n private readonly pipelineRegistry: PipelineRegistry;\n\n @inject(WorkflowHoverService)\n private readonly hoverService: WorkflowHoverService;\n\n @inject(WorkflowSelectService)\n private readonly selectService: WorkflowSelectService;\n\n public readonly node = domUtils.createDivWithClass(\n 'gedit-playground-layer gedit-flow-render-layer',\n );\n\n private disposers: Disposable[] = [];\n\n private mode: StackingComputeMode = StackingComputeMode.Stacking;\n\n constructor() {}\n\n public init(mode?: StackingComputeMode): void {\n if (mode) this.mode = mode;\n this.pipelineRenderer.node.appendChild(this.node);\n this.mountListener();\n }\n\n public ready(): void {\n this.compute();\n }\n\n public dispose(): void {\n this.disposers.forEach(disposer => disposer.dispose());\n }\n\n /**\n * 触发计算\n * 10ms内仅计算一次\n */\n private compute = debounce(this._compute, 10);\n\n private _compute(): void {\n if (this.mode === StackingComputeMode.Stacking) {\n return this.stackingCompute();\n } else {\n return layersComputing({\n nodes: this.nodes,\n lines: this.lines,\n context: this.context,\n });\n }\n }\n\n private stackingCompute(): void {\n const context = this.context;\n const stackingComputing = new StackingComputing();\n const { nodeLevel, lineLevel } = stackingComputing.compute({\n root: this.document.root,\n nodes: this.nodes,\n context,\n });\n this.nodes.forEach(node => {\n const level = nodeLevel.get(node.id);\n const nodeRenderData = node.getData<FlowNodeRenderData>(FlowNodeRenderData);\n const element = nodeRenderData.node;\n element.style.position = 'absolute';\n if (!level) {\n element.style.zIndex = 'auto';\n return;\n }\n element.style.zIndex = String(StackingConfig.startIndex + level);\n });\n this.lines.forEach(line => {\n const level = lineLevel.get(line.id);\n const element = line.node;\n element.style.position = 'absolute';\n if (!level) {\n element.style.zIndex = 'auto';\n return;\n }\n element.style.zIndex = String(StackingConfig.startIndex + level);\n });\n }\n\n private get nodes(): WorkflowNodeEntity[] {\n return this.entityManager.getEntities<WorkflowNodeEntity>(WorkflowNodeEntity);\n }\n\n private get lines(): WorkflowLineEntity[] {\n return this.entityManager.getEntities<WorkflowLineEntity>(WorkflowLineEntity);\n }\n\n private get context(): StackingContext {\n return {\n hoveredEntity: this.hoverService.hoveredNode,\n hoveredEntityID: this.hoverService.hoveredNode?.id,\n selectedEntities: this.selectService.selection,\n selectedIDs: this.selectService.selection.map(entity => entity.id),\n };\n }\n\n private mountListener(): void {\n const entityChangeDisposer = this.onEntityChange();\n const zoomDisposer = this.onZoom();\n const hoverDisposer = this.onHover();\n const selectDisposer = this.onSelect();\n this.disposers = [entityChangeDisposer, zoomDisposer, hoverDisposer, selectDisposer];\n }\n\n private onZoom(): Disposable {\n return this.pipelineRegistry.onZoom((scale: number) => {\n this.node.style.transform = `scale(${scale})`;\n });\n }\n\n private onHover(): Disposable {\n return this.hoverService.onHoveredChange(() => {\n this.compute();\n });\n }\n\n private onEntityChange(): Disposable {\n return this.entityManager.onEntityChange(() => {\n this.compute();\n });\n }\n\n private onSelect(): Disposable {\n return this.selectService.onSelectionChanged(() => {\n this.compute();\n });\n }\n}\n","import { FlowNodeBaseType } from '@flowgram.ai/document';\nimport { WorkflowNodeEntity, WorkflowNodeLinesData } from '@flowgram.ai/free-layout-core';\n\nimport type { StackingContext } from './type';\n\nexport class StackingComputing {\n private currentLevel: number;\n\n private topLevel: number;\n\n private maxLevel: number;\n\n private nodeIndexes: Map<string, number>;\n\n private nodeLevel: Map<string, number>;\n\n private lineLevel: Map<string, number>;\n\n private context: StackingContext;\n\n public compute(params: {\n root: WorkflowNodeEntity;\n nodes: WorkflowNodeEntity[];\n context: StackingContext;\n }): {\n /** 节点层级 */\n nodeLevel: Map<string, number>;\n /** 线条层级 */\n lineLevel: Map<string, number>;\n /** 正常渲染的最高层级 */\n topLevel: number;\n /** 选中计算叠加后可能计算出的最高层级 */\n maxLevel: number;\n } {\n this.clearCache();\n const { root, nodes, context } = params;\n this.context = context;\n this.nodeIndexes = this.computeNodeIndexesMap(nodes);\n this.topLevel = this.computeTopLevel(nodes);\n this.maxLevel = this.topLevel * 2;\n this.layerHandler(root.collapsedChildren);\n return {\n nodeLevel: this.nodeLevel,\n lineLevel: this.lineLevel,\n topLevel: this.topLevel,\n maxLevel: this.maxLevel,\n };\n }\n\n private clearCache(): void {\n this.currentLevel = 0;\n this.topLevel = 0;\n this.maxLevel = 0;\n this.nodeIndexes = new Map();\n this.nodeLevel = new Map();\n this.lineLevel = new Map();\n }\n\n private computeNodeIndexesMap(nodes: WorkflowNodeEntity[]): Map<string, number> {\n const nodeIndexMap = new Map<string, number>();\n nodes.forEach((node, index) => {\n nodeIndexMap.set(node.id, index);\n });\n return nodeIndexMap;\n }\n\n private computeTopLevel(nodes: WorkflowNodeEntity[]): number {\n const nodesWithoutRoot = nodes.filter(node => node.id !== FlowNodeBaseType.ROOT);\n const nodeHasChildren = nodesWithoutRoot.reduce((count, node) => {\n if (node.collapsedChildren.length > 0) {\n return count + 1;\n } else {\n return count;\n }\n }, 0);\n // 最高层数 = 节点个数 + 容器节点个数(线条单独占一层) + 抬高一层\n return nodesWithoutRoot.length + nodeHasChildren + 1;\n }\n\n private layerHandler(nodes: WorkflowNodeEntity[], pinTop: boolean = false): void {\n const sortedNodes = nodes.sort((a, b) => {\n const aIndex = this.nodeIndexes.get(a.id);\n const bIndex = this.nodeIndexes.get(b.id);\n if (aIndex === undefined || bIndex === undefined) {\n return 0;\n }\n return aIndex - bIndex;\n });\n\n const lines = nodes\n .map(node => {\n const linesData = node.getData<WorkflowNodeLinesData>(WorkflowNodeLinesData);\n const outputLines = linesData.outputLines.filter(Boolean);\n const inputLines = linesData.inputLines.filter(Boolean);\n // 前后线条会有重复,下面 Map 会通过线条 ID 过滤掉\n return [...outputLines, ...inputLines];\n })\n .flat();\n\n // 线条统一设为当前层级最低\n lines.forEach(line => {\n if (\n line.isDrawing || // 正在绘制\n this.context.hoveredEntityID === line.id || // hover\n this.context.selectedIDs.includes(line.id) // 选中\n ) {\n // 线条置顶条件:正在绘制 / hover / 选中\n this.lineLevel.set(line.id, this.maxLevel);\n } else {\n this.lineLevel.set(line.id, this.getLevel(pinTop));\n }\n });\n this.levelIncrease();\n sortedNodes.forEach(node => {\n const selected = this.context.selectedIDs.includes(node.id);\n if (selected) {\n // 节点置顶条件:选中\n this.nodeLevel.set(node.id, this.topLevel);\n } else {\n this.nodeLevel.set(node.id, this.getLevel(pinTop));\n }\n // 节点层级逐层增高\n this.levelIncrease();\n if (node.collapsedChildren.length > 0) {\n // 子节点层级需低于后续兄弟节点,因此需要先进行计算\n this.layerHandler(node.collapsedChildren, pinTop || selected);\n }\n });\n }\n\n private getLevel(pinTop: boolean): number {\n if (pinTop) {\n return this.topLevel + this.currentLevel;\n }\n return this.currentLevel;\n }\n\n private levelIncrease(): void {\n this.currentLevel += 1;\n }\n}\n","import { FlowNodeRenderData } from '@flowgram.ai/document';\nimport type { WorkflowNodeEntity } from '@flowgram.ai/free-layout-core';\nimport type { WorkflowLineEntity } from '@flowgram.ai/free-layout-core';\n\nimport type { StackingContext } from './type';\nimport { StackingBaseIndex, StackingConfig, StackingType } from './constant';\n\nnamespace NodeComputing {\n export const compute = (node: WorkflowNodeEntity, context: StackingContext): void => {\n const zIndex = nodeZIndex(node, context);\n const element = nodeElement(node);\n element.style.position = 'absolute';\n element.style.zIndex = zIndexStringify(zIndex);\n };\n\n export const stackingIndex = (stackingType: StackingType, level: number): number | undefined => {\n if (level < 1) {\n // root节点\n return undefined;\n }\n const baseZIndex = StackingBaseIndex[stackingType];\n const zIndex =\n StackingConfig.startIndex + StackingConfig.levelIndexStep * (level - 1) + baseZIndex;\n return zIndex;\n };\n\n export const nodeStackingLevel = (\n node: WorkflowNodeEntity,\n context: StackingContext,\n disableTopLevel = false,\n ): number => {\n // TODO 后续支持多层级时这个计算逻辑应该去掉,level信息应该直接由 FlowNodeEntity 缓存给出\n // 多层时这里的计算会有 O(logN) 时间复杂度,并且在多层级联同计算时会有BUG,本次需求不处理这种情况\n const unReversedLinage: WorkflowNodeEntity[] = [];\n let currentNode: WorkflowNodeEntity | undefined = node;\n while (currentNode) {\n unReversedLinage.push(currentNode);\n currentNode = currentNode.parent;\n }\n const linage = unReversedLinage.reverse();\n const nodeLevel = linage.length - 1;\n\n const topLevelIndex = linage.findIndex((node: WorkflowNodeEntity) => {\n if (context.selectedIDs.includes(node.id)) {\n // 存在被选中的父级或自身被选中,直接置顶\n return true;\n }\n return false;\n });\n const topLevel = StackingConfig.allowLevel + (linage.length - topLevelIndex);\n\n if (!disableTopLevel && topLevelIndex !== -1) {\n // 置顶\n return topLevel;\n }\n\n return nodeLevel;\n };\n\n export const zIndexStringify = (zIndex?: number): string => {\n if (zIndex === undefined) {\n return 'auto';\n }\n return zIndex.toString();\n };\n\n const nodeZIndex = (node: WorkflowNodeEntity, context: StackingContext): number | undefined => {\n const level = nodeStackingLevel(node, context);\n const zIndex = stackingIndex(StackingType.Node, level);\n return zIndex;\n };\n\n const nodeElement = (node: WorkflowNodeEntity): HTMLDivElement => {\n const nodeRenderData = node.getData<FlowNodeRenderData>(FlowNodeRenderData);\n return nodeRenderData.node;\n };\n}\n\nnamespace LineComputing {\n export const compute = (line: WorkflowLineEntity, context: StackingContext): void => {\n const zIndex = lineZIndex(line, context);\n const element = line.node;\n element.style.position = 'absolute';\n element.style.zIndex = NodeComputing.zIndexStringify(zIndex);\n };\n\n const lineStackingLevel = (line: WorkflowLineEntity, context: StackingContext): number => {\n if (\n line.isDrawing || // 正在绘制\n context.hoveredEntityID === line.id || // hover\n context.selectedIDs.includes(line.id) // 选中\n ) {\n // 线条置顶条件:正在绘制 / hover / 选中\n return StackingConfig.maxLevel + 1;\n }\n const fromLevel = NodeComputing.nodeStackingLevel(line.from, context, true);\n if (!line.to) {\n // 还处于连线中\n return fromLevel;\n }\n const toLevel = NodeComputing.nodeStackingLevel(line.to, context, true);\n const level = Math.min(fromLevel, toLevel);\n return level;\n };\n\n const lineZIndex = (line: WorkflowLineEntity, context: StackingContext): number | undefined => {\n const level = lineStackingLevel(line, context);\n const zIndex = NodeComputing.stackingIndex(StackingType.Line, level);\n return zIndex;\n };\n}\n\nexport const layersComputing = (params: {\n nodes: WorkflowNodeEntity[];\n lines: WorkflowLineEntity[];\n context: StackingContext;\n}) => {\n const { nodes, lines, context } = params;\n nodes.forEach(node => {\n NodeComputing.compute(node, context);\n });\n lines.forEach(line => {\n LineComputing.compute(line, context);\n });\n};\n","export enum StackingItem {\n Line = 'line',\n Node = 'node',\n}\n\nexport enum StackingType {\n Line = StackingItem.Line,\n Node = StackingItem.Node,\n}\n\nexport const StackingBaseIndex: Record<StackingType, number> = {\n [StackingType.Line]: 0,\n [StackingType.Node]: 1,\n};\n\n// 常量\nconst startIndex = 8;\nconst allowLevel = 2;\n\n// 计算值\nconst levelIndexStep = Object.keys(StackingType).length;\nconst maxLevel = allowLevel * 2;\nconst maxIndex = startIndex + maxLevel * levelIndexStep;\n\nexport const StackingConfig = {\n /** index 起始值 */\n startIndex,\n /** 允许存在的层级 */\n allowLevel,\n /** 每层 index 跨度 */\n levelIndexStep,\n /** 叠加计算后出现的最深层级 */\n maxLevel,\n /** 最大 index */\n maxIndex,\n};\n\nexport enum StackingComputeMode {\n /** 层叠计算模式 */\n Stacking = 'stacking',\n /** 层级计算模式 */\n Layers = 'layers',\n}\n"],"mappings":";;;;;;;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,EADhB,OAAO,oBAAoB;AAAA,GAXjB,uBAYM;AAGA;AAAA,EADhB,OAAO,qBAAqB;AAAA,GAdlB,uBAeM;AAfN,yBAAN;AAAA,EADN,WAAW;AAAA,GACC;;;ADfN,IAAM,wBAAwB,oBAElC;AAAA,EACD,OAAO,EAAE,KAAK,GAAG;AACf,SAAK,sBAAsB,EAAE,OAAO,EAAE,iBAAiB;AAAA,EACzD;AAAA,EACA,OAAO,KAAK,MAAM;AAChB,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,KAAK,MAAM,IAAI;AAAA,EACxC;AAAA,EACA,QAAQ,KAAK;AACX,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,MAAM;AAAA,EAC/B;AAAA,EACA,UAAU,KAAK;AACb,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,QAAQ;AAAA,EACjC;AACF,CAAC;","names":["FlowNodeRenderData","WorkflowNodeEntity","StackingItem","StackingType","StackingComputeMode","NodeComputing","node","LineComputing","FlowNodeRenderData","WorkflowNodeEntity"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { Entity } from '@flowgram.ai/core';
|
|
3
|
+
import { WorkfloEntityHoverable, WorkflowNodeEntity, WorkflowLineEntity } from '@flowgram.ai/free-layout-core';
|
|
4
|
+
|
|
5
|
+
declare enum StackingItem {
|
|
6
|
+
Line = "line",
|
|
7
|
+
Node = "node"
|
|
8
|
+
}
|
|
9
|
+
declare enum StackingType {
|
|
10
|
+
Line = "line",
|
|
11
|
+
Node = "node"
|
|
12
|
+
}
|
|
13
|
+
declare const StackingBaseIndex: Record<StackingType, number>;
|
|
14
|
+
declare const StackingConfig: {
|
|
15
|
+
/** index 起始值 */
|
|
16
|
+
startIndex: number;
|
|
17
|
+
/** 允许存在的层级 */
|
|
18
|
+
allowLevel: number;
|
|
19
|
+
/** 每层 index 跨度 */
|
|
20
|
+
levelIndexStep: number;
|
|
21
|
+
/** 叠加计算后出现的最深层级 */
|
|
22
|
+
maxLevel: number;
|
|
23
|
+
/** 最大 index */
|
|
24
|
+
maxIndex: number;
|
|
25
|
+
};
|
|
26
|
+
declare enum StackingComputeMode {
|
|
27
|
+
/** 层叠计算模式 */
|
|
28
|
+
Stacking = "stacking",
|
|
29
|
+
/** 层级计算模式 */
|
|
30
|
+
Layers = "layers"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare const createFreeStackPlugin: _flowgram_ai_core.PluginCreator<{
|
|
34
|
+
mode?: StackingComputeMode | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
declare class StackingContextManager {
|
|
38
|
+
private readonly document;
|
|
39
|
+
private readonly entityManager;
|
|
40
|
+
private readonly pipelineRenderer;
|
|
41
|
+
private readonly pipelineRegistry;
|
|
42
|
+
private readonly hoverService;
|
|
43
|
+
private readonly selectService;
|
|
44
|
+
readonly node: HTMLDivElement;
|
|
45
|
+
private disposers;
|
|
46
|
+
private mode;
|
|
47
|
+
constructor();
|
|
48
|
+
init(mode?: StackingComputeMode): void;
|
|
49
|
+
ready(): void;
|
|
50
|
+
dispose(): void;
|
|
51
|
+
/**
|
|
52
|
+
* 触发计算
|
|
53
|
+
* 10ms内仅计算一次
|
|
54
|
+
*/
|
|
55
|
+
private compute;
|
|
56
|
+
private _compute;
|
|
57
|
+
private stackingCompute;
|
|
58
|
+
private get nodes();
|
|
59
|
+
private get lines();
|
|
60
|
+
private get context();
|
|
61
|
+
private mountListener;
|
|
62
|
+
private onZoom;
|
|
63
|
+
private onHover;
|
|
64
|
+
private onEntityChange;
|
|
65
|
+
private onSelect;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type StackingContext = {
|
|
69
|
+
hoveredEntity?: WorkfloEntityHoverable;
|
|
70
|
+
hoveredEntityID?: string;
|
|
71
|
+
selectedEntities: Entity[];
|
|
72
|
+
selectedIDs: string[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
declare const layersComputing: (params: {
|
|
76
|
+
nodes: WorkflowNodeEntity[];
|
|
77
|
+
lines: WorkflowLineEntity[];
|
|
78
|
+
context: StackingContext;
|
|
79
|
+
}) => void;
|
|
80
|
+
|
|
81
|
+
declare class StackingComputing {
|
|
82
|
+
private currentLevel;
|
|
83
|
+
private topLevel;
|
|
84
|
+
private maxLevel;
|
|
85
|
+
private nodeIndexes;
|
|
86
|
+
private nodeLevel;
|
|
87
|
+
private lineLevel;
|
|
88
|
+
private context;
|
|
89
|
+
compute(params: {
|
|
90
|
+
root: WorkflowNodeEntity;
|
|
91
|
+
nodes: WorkflowNodeEntity[];
|
|
92
|
+
context: StackingContext;
|
|
93
|
+
}): {
|
|
94
|
+
/** 节点层级 */
|
|
95
|
+
nodeLevel: Map<string, number>;
|
|
96
|
+
/** 线条层级 */
|
|
97
|
+
lineLevel: Map<string, number>;
|
|
98
|
+
/** 正常渲染的最高层级 */
|
|
99
|
+
topLevel: number;
|
|
100
|
+
/** 选中计算叠加后可能计算出的最高层级 */
|
|
101
|
+
maxLevel: number;
|
|
102
|
+
};
|
|
103
|
+
private clearCache;
|
|
104
|
+
private computeNodeIndexesMap;
|
|
105
|
+
private computeTopLevel;
|
|
106
|
+
private layerHandler;
|
|
107
|
+
private getLevel;
|
|
108
|
+
private levelIncrease;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { StackingBaseIndex, StackingComputeMode, StackingComputing, StackingConfig, type StackingContext, StackingContextManager, StackingItem, StackingType, createFreeStackPlugin, layersComputing };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { Entity } from '@flowgram.ai/core';
|
|
3
|
+
import { WorkfloEntityHoverable, WorkflowNodeEntity, WorkflowLineEntity } from '@flowgram.ai/free-layout-core';
|
|
4
|
+
|
|
5
|
+
declare enum StackingItem {
|
|
6
|
+
Line = "line",
|
|
7
|
+
Node = "node"
|
|
8
|
+
}
|
|
9
|
+
declare enum StackingType {
|
|
10
|
+
Line = "line",
|
|
11
|
+
Node = "node"
|
|
12
|
+
}
|
|
13
|
+
declare const StackingBaseIndex: Record<StackingType, number>;
|
|
14
|
+
declare const StackingConfig: {
|
|
15
|
+
/** index 起始值 */
|
|
16
|
+
startIndex: number;
|
|
17
|
+
/** 允许存在的层级 */
|
|
18
|
+
allowLevel: number;
|
|
19
|
+
/** 每层 index 跨度 */
|
|
20
|
+
levelIndexStep: number;
|
|
21
|
+
/** 叠加计算后出现的最深层级 */
|
|
22
|
+
maxLevel: number;
|
|
23
|
+
/** 最大 index */
|
|
24
|
+
maxIndex: number;
|
|
25
|
+
};
|
|
26
|
+
declare enum StackingComputeMode {
|
|
27
|
+
/** 层叠计算模式 */
|
|
28
|
+
Stacking = "stacking",
|
|
29
|
+
/** 层级计算模式 */
|
|
30
|
+
Layers = "layers"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare const createFreeStackPlugin: _flowgram_ai_core.PluginCreator<{
|
|
34
|
+
mode?: StackingComputeMode | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
declare class StackingContextManager {
|
|
38
|
+
private readonly document;
|
|
39
|
+
private readonly entityManager;
|
|
40
|
+
private readonly pipelineRenderer;
|
|
41
|
+
private readonly pipelineRegistry;
|
|
42
|
+
private readonly hoverService;
|
|
43
|
+
private readonly selectService;
|
|
44
|
+
readonly node: HTMLDivElement;
|
|
45
|
+
private disposers;
|
|
46
|
+
private mode;
|
|
47
|
+
constructor();
|
|
48
|
+
init(mode?: StackingComputeMode): void;
|
|
49
|
+
ready(): void;
|
|
50
|
+
dispose(): void;
|
|
51
|
+
/**
|
|
52
|
+
* 触发计算
|
|
53
|
+
* 10ms内仅计算一次
|
|
54
|
+
*/
|
|
55
|
+
private compute;
|
|
56
|
+
private _compute;
|
|
57
|
+
private stackingCompute;
|
|
58
|
+
private get nodes();
|
|
59
|
+
private get lines();
|
|
60
|
+
private get context();
|
|
61
|
+
private mountListener;
|
|
62
|
+
private onZoom;
|
|
63
|
+
private onHover;
|
|
64
|
+
private onEntityChange;
|
|
65
|
+
private onSelect;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type StackingContext = {
|
|
69
|
+
hoveredEntity?: WorkfloEntityHoverable;
|
|
70
|
+
hoveredEntityID?: string;
|
|
71
|
+
selectedEntities: Entity[];
|
|
72
|
+
selectedIDs: string[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
declare const layersComputing: (params: {
|
|
76
|
+
nodes: WorkflowNodeEntity[];
|
|
77
|
+
lines: WorkflowLineEntity[];
|
|
78
|
+
context: StackingContext;
|
|
79
|
+
}) => void;
|
|
80
|
+
|
|
81
|
+
declare class StackingComputing {
|
|
82
|
+
private currentLevel;
|
|
83
|
+
private topLevel;
|
|
84
|
+
private maxLevel;
|
|
85
|
+
private nodeIndexes;
|
|
86
|
+
private nodeLevel;
|
|
87
|
+
private lineLevel;
|
|
88
|
+
private context;
|
|
89
|
+
compute(params: {
|
|
90
|
+
root: WorkflowNodeEntity;
|
|
91
|
+
nodes: WorkflowNodeEntity[];
|
|
92
|
+
context: StackingContext;
|
|
93
|
+
}): {
|
|
94
|
+
/** 节点层级 */
|
|
95
|
+
nodeLevel: Map<string, number>;
|
|
96
|
+
/** 线条层级 */
|
|
97
|
+
lineLevel: Map<string, number>;
|
|
98
|
+
/** 正常渲染的最高层级 */
|
|
99
|
+
topLevel: number;
|
|
100
|
+
/** 选中计算叠加后可能计算出的最高层级 */
|
|
101
|
+
maxLevel: number;
|
|
102
|
+
};
|
|
103
|
+
private clearCache;
|
|
104
|
+
private computeNodeIndexesMap;
|
|
105
|
+
private computeTopLevel;
|
|
106
|
+
private layerHandler;
|
|
107
|
+
private getLevel;
|
|
108
|
+
private levelIncrease;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { StackingBaseIndex, StackingComputeMode, StackingComputing, StackingConfig, type StackingContext, StackingContextManager, StackingItem, StackingType, createFreeStackPlugin, layersComputing };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
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
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
StackingBaseIndex: () => StackingBaseIndex,
|
|
32
|
+
StackingComputeMode: () => StackingComputeMode,
|
|
33
|
+
StackingComputing: () => StackingComputing,
|
|
34
|
+
StackingConfig: () => StackingConfig,
|
|
35
|
+
StackingContextManager: () => StackingContextManager,
|
|
36
|
+
StackingItem: () => StackingItem,
|
|
37
|
+
StackingType: () => StackingType,
|
|
38
|
+
createFreeStackPlugin: () => createFreeStackPlugin,
|
|
39
|
+
layersComputing: () => layersComputing
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(src_exports);
|
|
42
|
+
|
|
43
|
+
// src/create-free-stack-plugin.ts
|
|
44
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
45
|
+
|
|
46
|
+
// src/manager.ts
|
|
47
|
+
var import_lodash = require("lodash");
|
|
48
|
+
var import_inversify = require("inversify");
|
|
49
|
+
var import_document3 = require("@flowgram.ai/document");
|
|
50
|
+
var import_core = require("@flowgram.ai/core");
|
|
51
|
+
var import_free_layout_core2 = require("@flowgram.ai/free-layout-core");
|
|
52
|
+
var import_free_layout_core3 = require("@flowgram.ai/free-layout-core");
|
|
53
|
+
var import_free_layout_core4 = require("@flowgram.ai/free-layout-core");
|
|
54
|
+
var import_utils = require("@flowgram.ai/utils");
|
|
55
|
+
|
|
56
|
+
// src/stacking-computing.ts
|
|
57
|
+
var import_document = require("@flowgram.ai/document");
|
|
58
|
+
var import_free_layout_core = require("@flowgram.ai/free-layout-core");
|
|
59
|
+
var StackingComputing = class {
|
|
60
|
+
compute(params) {
|
|
61
|
+
this.clearCache();
|
|
62
|
+
const { root, nodes, context } = params;
|
|
63
|
+
this.context = context;
|
|
64
|
+
this.nodeIndexes = this.computeNodeIndexesMap(nodes);
|
|
65
|
+
this.topLevel = this.computeTopLevel(nodes);
|
|
66
|
+
this.maxLevel = this.topLevel * 2;
|
|
67
|
+
this.layerHandler(root.collapsedChildren);
|
|
68
|
+
return {
|
|
69
|
+
nodeLevel: this.nodeLevel,
|
|
70
|
+
lineLevel: this.lineLevel,
|
|
71
|
+
topLevel: this.topLevel,
|
|
72
|
+
maxLevel: this.maxLevel
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
clearCache() {
|
|
76
|
+
this.currentLevel = 0;
|
|
77
|
+
this.topLevel = 0;
|
|
78
|
+
this.maxLevel = 0;
|
|
79
|
+
this.nodeIndexes = /* @__PURE__ */ new Map();
|
|
80
|
+
this.nodeLevel = /* @__PURE__ */ new Map();
|
|
81
|
+
this.lineLevel = /* @__PURE__ */ new Map();
|
|
82
|
+
}
|
|
83
|
+
computeNodeIndexesMap(nodes) {
|
|
84
|
+
const nodeIndexMap = /* @__PURE__ */ new Map();
|
|
85
|
+
nodes.forEach((node, index) => {
|
|
86
|
+
nodeIndexMap.set(node.id, index);
|
|
87
|
+
});
|
|
88
|
+
return nodeIndexMap;
|
|
89
|
+
}
|
|
90
|
+
computeTopLevel(nodes) {
|
|
91
|
+
const nodesWithoutRoot = nodes.filter((node) => node.id !== import_document.FlowNodeBaseType.ROOT);
|
|
92
|
+
const nodeHasChildren = nodesWithoutRoot.reduce((count, node) => {
|
|
93
|
+
if (node.collapsedChildren.length > 0) {
|
|
94
|
+
return count + 1;
|
|
95
|
+
} else {
|
|
96
|
+
return count;
|
|
97
|
+
}
|
|
98
|
+
}, 0);
|
|
99
|
+
return nodesWithoutRoot.length + nodeHasChildren + 1;
|
|
100
|
+
}
|
|
101
|
+
layerHandler(nodes, pinTop = false) {
|
|
102
|
+
const sortedNodes = nodes.sort((a, b) => {
|
|
103
|
+
const aIndex = this.nodeIndexes.get(a.id);
|
|
104
|
+
const bIndex = this.nodeIndexes.get(b.id);
|
|
105
|
+
if (aIndex === void 0 || bIndex === void 0) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
return aIndex - bIndex;
|
|
109
|
+
});
|
|
110
|
+
const lines = nodes.map((node) => {
|
|
111
|
+
const linesData = node.getData(import_free_layout_core.WorkflowNodeLinesData);
|
|
112
|
+
const outputLines = linesData.outputLines.filter(Boolean);
|
|
113
|
+
const inputLines = linesData.inputLines.filter(Boolean);
|
|
114
|
+
return [...outputLines, ...inputLines];
|
|
115
|
+
}).flat();
|
|
116
|
+
lines.forEach((line) => {
|
|
117
|
+
if (line.isDrawing || // 正在绘制
|
|
118
|
+
this.context.hoveredEntityID === line.id || // hover
|
|
119
|
+
this.context.selectedIDs.includes(line.id)) {
|
|
120
|
+
this.lineLevel.set(line.id, this.maxLevel);
|
|
121
|
+
} else {
|
|
122
|
+
this.lineLevel.set(line.id, this.getLevel(pinTop));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.levelIncrease();
|
|
126
|
+
sortedNodes.forEach((node) => {
|
|
127
|
+
const selected = this.context.selectedIDs.includes(node.id);
|
|
128
|
+
if (selected) {
|
|
129
|
+
this.nodeLevel.set(node.id, this.topLevel);
|
|
130
|
+
} else {
|
|
131
|
+
this.nodeLevel.set(node.id, this.getLevel(pinTop));
|
|
132
|
+
}
|
|
133
|
+
this.levelIncrease();
|
|
134
|
+
if (node.collapsedChildren.length > 0) {
|
|
135
|
+
this.layerHandler(node.collapsedChildren, pinTop || selected);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getLevel(pinTop) {
|
|
140
|
+
if (pinTop) {
|
|
141
|
+
return this.topLevel + this.currentLevel;
|
|
142
|
+
}
|
|
143
|
+
return this.currentLevel;
|
|
144
|
+
}
|
|
145
|
+
levelIncrease() {
|
|
146
|
+
this.currentLevel += 1;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/layers-computing.ts
|
|
151
|
+
var import_document2 = require("@flowgram.ai/document");
|
|
152
|
+
|
|
153
|
+
// src/constant.ts
|
|
154
|
+
var StackingItem = /* @__PURE__ */ ((StackingItem2) => {
|
|
155
|
+
StackingItem2["Line"] = "line";
|
|
156
|
+
StackingItem2["Node"] = "node";
|
|
157
|
+
return StackingItem2;
|
|
158
|
+
})(StackingItem || {});
|
|
159
|
+
var StackingType = /* @__PURE__ */ ((StackingType2) => {
|
|
160
|
+
StackingType2["Line"] = "line" /* Line */;
|
|
161
|
+
StackingType2["Node"] = "node" /* Node */;
|
|
162
|
+
return StackingType2;
|
|
163
|
+
})(StackingType || {});
|
|
164
|
+
var StackingBaseIndex = {
|
|
165
|
+
["line" /* Line */]: 0,
|
|
166
|
+
["node" /* Node */]: 1
|
|
167
|
+
};
|
|
168
|
+
var startIndex = 8;
|
|
169
|
+
var allowLevel = 2;
|
|
170
|
+
var levelIndexStep = Object.keys(StackingType).length;
|
|
171
|
+
var maxLevel = allowLevel * 2;
|
|
172
|
+
var maxIndex = startIndex + maxLevel * levelIndexStep;
|
|
173
|
+
var StackingConfig = {
|
|
174
|
+
/** index 起始值 */
|
|
175
|
+
startIndex,
|
|
176
|
+
/** 允许存在的层级 */
|
|
177
|
+
allowLevel,
|
|
178
|
+
/** 每层 index 跨度 */
|
|
179
|
+
levelIndexStep,
|
|
180
|
+
/** 叠加计算后出现的最深层级 */
|
|
181
|
+
maxLevel,
|
|
182
|
+
/** 最大 index */
|
|
183
|
+
maxIndex
|
|
184
|
+
};
|
|
185
|
+
var StackingComputeMode = /* @__PURE__ */ ((StackingComputeMode2) => {
|
|
186
|
+
StackingComputeMode2["Stacking"] = "stacking";
|
|
187
|
+
StackingComputeMode2["Layers"] = "layers";
|
|
188
|
+
return StackingComputeMode2;
|
|
189
|
+
})(StackingComputeMode || {});
|
|
190
|
+
|
|
191
|
+
// src/layers-computing.ts
|
|
192
|
+
var NodeComputing;
|
|
193
|
+
((NodeComputing2) => {
|
|
194
|
+
NodeComputing2.compute = (node, context) => {
|
|
195
|
+
const zIndex = nodeZIndex(node, context);
|
|
196
|
+
const element = nodeElement(node);
|
|
197
|
+
element.style.position = "absolute";
|
|
198
|
+
element.style.zIndex = (0, NodeComputing2.zIndexStringify)(zIndex);
|
|
199
|
+
};
|
|
200
|
+
NodeComputing2.stackingIndex = (stackingType, level) => {
|
|
201
|
+
if (level < 1) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
const baseZIndex = StackingBaseIndex[stackingType];
|
|
205
|
+
const zIndex = StackingConfig.startIndex + StackingConfig.levelIndexStep * (level - 1) + baseZIndex;
|
|
206
|
+
return zIndex;
|
|
207
|
+
};
|
|
208
|
+
NodeComputing2.nodeStackingLevel = (node, context, disableTopLevel = false) => {
|
|
209
|
+
const unReversedLinage = [];
|
|
210
|
+
let currentNode = node;
|
|
211
|
+
while (currentNode) {
|
|
212
|
+
unReversedLinage.push(currentNode);
|
|
213
|
+
currentNode = currentNode.parent;
|
|
214
|
+
}
|
|
215
|
+
const linage = unReversedLinage.reverse();
|
|
216
|
+
const nodeLevel = linage.length - 1;
|
|
217
|
+
const topLevelIndex = linage.findIndex((node2) => {
|
|
218
|
+
if (context.selectedIDs.includes(node2.id)) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
});
|
|
223
|
+
const topLevel = StackingConfig.allowLevel + (linage.length - topLevelIndex);
|
|
224
|
+
if (!disableTopLevel && topLevelIndex !== -1) {
|
|
225
|
+
return topLevel;
|
|
226
|
+
}
|
|
227
|
+
return nodeLevel;
|
|
228
|
+
};
|
|
229
|
+
NodeComputing2.zIndexStringify = (zIndex) => {
|
|
230
|
+
if (zIndex === void 0) {
|
|
231
|
+
return "auto";
|
|
232
|
+
}
|
|
233
|
+
return zIndex.toString();
|
|
234
|
+
};
|
|
235
|
+
const nodeZIndex = (node, context) => {
|
|
236
|
+
const level = (0, NodeComputing2.nodeStackingLevel)(node, context);
|
|
237
|
+
const zIndex = (0, NodeComputing2.stackingIndex)("node" /* Node */, level);
|
|
238
|
+
return zIndex;
|
|
239
|
+
};
|
|
240
|
+
const nodeElement = (node) => {
|
|
241
|
+
const nodeRenderData = node.getData(import_document2.FlowNodeRenderData);
|
|
242
|
+
return nodeRenderData.node;
|
|
243
|
+
};
|
|
244
|
+
})(NodeComputing || (NodeComputing = {}));
|
|
245
|
+
var LineComputing;
|
|
246
|
+
((LineComputing2) => {
|
|
247
|
+
LineComputing2.compute = (line, context) => {
|
|
248
|
+
const zIndex = lineZIndex(line, context);
|
|
249
|
+
const element = line.node;
|
|
250
|
+
element.style.position = "absolute";
|
|
251
|
+
element.style.zIndex = NodeComputing.zIndexStringify(zIndex);
|
|
252
|
+
};
|
|
253
|
+
const lineStackingLevel = (line, context) => {
|
|
254
|
+
if (line.isDrawing || // 正在绘制
|
|
255
|
+
context.hoveredEntityID === line.id || // hover
|
|
256
|
+
context.selectedIDs.includes(line.id)) {
|
|
257
|
+
return StackingConfig.maxLevel + 1;
|
|
258
|
+
}
|
|
259
|
+
const fromLevel = NodeComputing.nodeStackingLevel(line.from, context, true);
|
|
260
|
+
if (!line.to) {
|
|
261
|
+
return fromLevel;
|
|
262
|
+
}
|
|
263
|
+
const toLevel = NodeComputing.nodeStackingLevel(line.to, context, true);
|
|
264
|
+
const level = Math.min(fromLevel, toLevel);
|
|
265
|
+
return level;
|
|
266
|
+
};
|
|
267
|
+
const lineZIndex = (line, context) => {
|
|
268
|
+
const level = lineStackingLevel(line, context);
|
|
269
|
+
const zIndex = NodeComputing.stackingIndex("line" /* Line */, level);
|
|
270
|
+
return zIndex;
|
|
271
|
+
};
|
|
272
|
+
})(LineComputing || (LineComputing = {}));
|
|
273
|
+
var layersComputing = (params) => {
|
|
274
|
+
const { nodes, lines, context } = params;
|
|
275
|
+
nodes.forEach((node) => {
|
|
276
|
+
NodeComputing.compute(node, context);
|
|
277
|
+
});
|
|
278
|
+
lines.forEach((line) => {
|
|
279
|
+
LineComputing.compute(line, context);
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/manager.ts
|
|
284
|
+
var StackingContextManager = class {
|
|
285
|
+
constructor() {
|
|
286
|
+
this.node = import_utils.domUtils.createDivWithClass(
|
|
287
|
+
"gedit-playground-layer gedit-flow-render-layer"
|
|
288
|
+
);
|
|
289
|
+
this.disposers = [];
|
|
290
|
+
this.mode = "stacking" /* Stacking */;
|
|
291
|
+
/**
|
|
292
|
+
* 触发计算
|
|
293
|
+
* 10ms内仅计算一次
|
|
294
|
+
*/
|
|
295
|
+
this.compute = (0, import_lodash.debounce)(this._compute, 10);
|
|
296
|
+
}
|
|
297
|
+
init(mode) {
|
|
298
|
+
if (mode) this.mode = mode;
|
|
299
|
+
this.pipelineRenderer.node.appendChild(this.node);
|
|
300
|
+
this.mountListener();
|
|
301
|
+
}
|
|
302
|
+
ready() {
|
|
303
|
+
this.compute();
|
|
304
|
+
}
|
|
305
|
+
dispose() {
|
|
306
|
+
this.disposers.forEach((disposer) => disposer.dispose());
|
|
307
|
+
}
|
|
308
|
+
_compute() {
|
|
309
|
+
if (this.mode === "stacking" /* Stacking */) {
|
|
310
|
+
return this.stackingCompute();
|
|
311
|
+
} else {
|
|
312
|
+
return layersComputing({
|
|
313
|
+
nodes: this.nodes,
|
|
314
|
+
lines: this.lines,
|
|
315
|
+
context: this.context
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
stackingCompute() {
|
|
320
|
+
const context = this.context;
|
|
321
|
+
const stackingComputing = new StackingComputing();
|
|
322
|
+
const { nodeLevel, lineLevel } = stackingComputing.compute({
|
|
323
|
+
root: this.document.root,
|
|
324
|
+
nodes: this.nodes,
|
|
325
|
+
context
|
|
326
|
+
});
|
|
327
|
+
this.nodes.forEach((node) => {
|
|
328
|
+
const level = nodeLevel.get(node.id);
|
|
329
|
+
const nodeRenderData = node.getData(import_document3.FlowNodeRenderData);
|
|
330
|
+
const element = nodeRenderData.node;
|
|
331
|
+
element.style.position = "absolute";
|
|
332
|
+
if (!level) {
|
|
333
|
+
element.style.zIndex = "auto";
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
element.style.zIndex = String(StackingConfig.startIndex + level);
|
|
337
|
+
});
|
|
338
|
+
this.lines.forEach((line) => {
|
|
339
|
+
const level = lineLevel.get(line.id);
|
|
340
|
+
const element = line.node;
|
|
341
|
+
element.style.position = "absolute";
|
|
342
|
+
if (!level) {
|
|
343
|
+
element.style.zIndex = "auto";
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
element.style.zIndex = String(StackingConfig.startIndex + level);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
get nodes() {
|
|
350
|
+
return this.entityManager.getEntities(import_free_layout_core2.WorkflowNodeEntity);
|
|
351
|
+
}
|
|
352
|
+
get lines() {
|
|
353
|
+
return this.entityManager.getEntities(import_free_layout_core3.WorkflowLineEntity);
|
|
354
|
+
}
|
|
355
|
+
get context() {
|
|
356
|
+
return {
|
|
357
|
+
hoveredEntity: this.hoverService.hoveredNode,
|
|
358
|
+
hoveredEntityID: this.hoverService.hoveredNode?.id,
|
|
359
|
+
selectedEntities: this.selectService.selection,
|
|
360
|
+
selectedIDs: this.selectService.selection.map((entity) => entity.id)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
mountListener() {
|
|
364
|
+
const entityChangeDisposer = this.onEntityChange();
|
|
365
|
+
const zoomDisposer = this.onZoom();
|
|
366
|
+
const hoverDisposer = this.onHover();
|
|
367
|
+
const selectDisposer = this.onSelect();
|
|
368
|
+
this.disposers = [entityChangeDisposer, zoomDisposer, hoverDisposer, selectDisposer];
|
|
369
|
+
}
|
|
370
|
+
onZoom() {
|
|
371
|
+
return this.pipelineRegistry.onZoom((scale) => {
|
|
372
|
+
this.node.style.transform = `scale(${scale})`;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
onHover() {
|
|
376
|
+
return this.hoverService.onHoveredChange(() => {
|
|
377
|
+
this.compute();
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
onEntityChange() {
|
|
381
|
+
return this.entityManager.onEntityChange(() => {
|
|
382
|
+
this.compute();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
onSelect() {
|
|
386
|
+
return this.selectService.onSelectionChanged(() => {
|
|
387
|
+
this.compute();
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
__decorateClass([
|
|
392
|
+
(0, import_inversify.inject)(import_free_layout_core4.WorkflowDocument)
|
|
393
|
+
], StackingContextManager.prototype, "document", 2);
|
|
394
|
+
__decorateClass([
|
|
395
|
+
(0, import_inversify.inject)(import_core.EntityManager)
|
|
396
|
+
], StackingContextManager.prototype, "entityManager", 2);
|
|
397
|
+
__decorateClass([
|
|
398
|
+
(0, import_inversify.inject)(import_core.PipelineRenderer)
|
|
399
|
+
], StackingContextManager.prototype, "pipelineRenderer", 2);
|
|
400
|
+
__decorateClass([
|
|
401
|
+
(0, import_inversify.inject)(import_core.PipelineRegistry)
|
|
402
|
+
], StackingContextManager.prototype, "pipelineRegistry", 2);
|
|
403
|
+
__decorateClass([
|
|
404
|
+
(0, import_inversify.inject)(import_free_layout_core2.WorkflowHoverService)
|
|
405
|
+
], StackingContextManager.prototype, "hoverService", 2);
|
|
406
|
+
__decorateClass([
|
|
407
|
+
(0, import_inversify.inject)(import_free_layout_core2.WorkflowSelectService)
|
|
408
|
+
], StackingContextManager.prototype, "selectService", 2);
|
|
409
|
+
StackingContextManager = __decorateClass([
|
|
410
|
+
(0, import_inversify.injectable)()
|
|
411
|
+
], StackingContextManager);
|
|
412
|
+
|
|
413
|
+
// src/create-free-stack-plugin.ts
|
|
414
|
+
var createFreeStackPlugin = (0, import_core2.definePluginCreator)({
|
|
415
|
+
onBind({ bind }) {
|
|
416
|
+
bind(StackingContextManager).toSelf().inSingletonScope();
|
|
417
|
+
},
|
|
418
|
+
onInit(ctx, opts) {
|
|
419
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
420
|
+
stackingContextManager.init(opts?.mode);
|
|
421
|
+
},
|
|
422
|
+
onReady(ctx) {
|
|
423
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
424
|
+
stackingContextManager.ready();
|
|
425
|
+
},
|
|
426
|
+
onDispose(ctx) {
|
|
427
|
+
const stackingContextManager = ctx.get(StackingContextManager);
|
|
428
|
+
stackingContextManager.dispose();
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
432
|
+
0 && (module.exports = {
|
|
433
|
+
StackingBaseIndex,
|
|
434
|
+
StackingComputeMode,
|
|
435
|
+
StackingComputing,
|
|
436
|
+
StackingConfig,
|
|
437
|
+
StackingContextManager,
|
|
438
|
+
StackingItem,
|
|
439
|
+
StackingType,
|
|
440
|
+
createFreeStackPlugin,
|
|
441
|
+
layersComputing
|
|
442
|
+
});
|
|
443
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-free-stack-plugin.ts","../src/manager.ts","../src/stacking-computing.ts","../src/layers-computing.ts","../src/constant.ts"],"sourcesContent":["export * from './create-free-stack-plugin';\nexport * from './manager';\nexport * from './constant';\nexport * from './layers-computing';\nexport * from './stacking-computing';\nexport * from './type';\n","import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { StackingContextManager } from './manager';\nimport { StackingComputeMode } from './constant';\n\nexport const createFreeStackPlugin = definePluginCreator<{\n mode?: StackingComputeMode;\n}>({\n onBind({ bind }) {\n bind(StackingContextManager).toSelf().inSingletonScope();\n },\n onInit(ctx, opts) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.init(opts?.mode);\n },\n onReady(ctx) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.ready();\n },\n onDispose(ctx) {\n const stackingContextManager = ctx.get<StackingContextManager>(StackingContextManager);\n stackingContextManager.dispose();\n },\n});\n","import { debounce } from 'lodash';\nimport { inject, injectable } from 'inversify';\nimport { FlowNodeRenderData } from '@flowgram.ai/document';\nimport { EntityManager, PipelineRegistry, PipelineRenderer } from '@flowgram.ai/core';\nimport {\n WorkflowHoverService,\n WorkflowNodeEntity,\n WorkflowSelectService,\n} from '@flowgram.ai/free-layout-core';\nimport { WorkflowLineEntity } from '@flowgram.ai/free-layout-core';\nimport { WorkflowDocument } from '@flowgram.ai/free-layout-core';\nimport { domUtils } from '@flowgram.ai/utils';\nimport { Disposable } from '@flowgram.ai/utils';\n\nimport type { StackingContext } from './type';\nimport { StackingComputing } from './stacking-computing';\nimport { layersComputing } from './layers-computing';\nimport { StackingComputeMode, StackingConfig } from './constant';\n\n@injectable()\nexport class StackingContextManager {\n @inject(WorkflowDocument) private readonly document: WorkflowDocument;\n\n @inject(EntityManager) private readonly entityManager: EntityManager;\n\n @inject(PipelineRenderer)\n private readonly pipelineRenderer: PipelineRenderer;\n\n @inject(PipelineRegistry)\n private readonly pipelineRegistry: PipelineRegistry;\n\n @inject(WorkflowHoverService)\n private readonly hoverService: WorkflowHoverService;\n\n @inject(WorkflowSelectService)\n private readonly selectService: WorkflowSelectService;\n\n public readonly node = domUtils.createDivWithClass(\n 'gedit-playground-layer gedit-flow-render-layer',\n );\n\n private disposers: Disposable[] = [];\n\n private mode: StackingComputeMode = StackingComputeMode.Stacking;\n\n constructor() {}\n\n public init(mode?: StackingComputeMode): void {\n if (mode) this.mode = mode;\n this.pipelineRenderer.node.appendChild(this.node);\n this.mountListener();\n }\n\n public ready(): void {\n this.compute();\n }\n\n public dispose(): void {\n this.disposers.forEach(disposer => disposer.dispose());\n }\n\n /**\n * 触发计算\n * 10ms内仅计算一次\n */\n private compute = debounce(this._compute, 10);\n\n private _compute(): void {\n if (this.mode === StackingComputeMode.Stacking) {\n return this.stackingCompute();\n } else {\n return layersComputing({\n nodes: this.nodes,\n lines: this.lines,\n context: this.context,\n });\n }\n }\n\n private stackingCompute(): void {\n const context = this.context;\n const stackingComputing = new StackingComputing();\n const { nodeLevel, lineLevel } = stackingComputing.compute({\n root: this.document.root,\n nodes: this.nodes,\n context,\n });\n this.nodes.forEach(node => {\n const level = nodeLevel.get(node.id);\n const nodeRenderData = node.getData<FlowNodeRenderData>(FlowNodeRenderData);\n const element = nodeRenderData.node;\n element.style.position = 'absolute';\n if (!level) {\n element.style.zIndex = 'auto';\n return;\n }\n element.style.zIndex = String(StackingConfig.startIndex + level);\n });\n this.lines.forEach(line => {\n const level = lineLevel.get(line.id);\n const element = line.node;\n element.style.position = 'absolute';\n if (!level) {\n element.style.zIndex = 'auto';\n return;\n }\n element.style.zIndex = String(StackingConfig.startIndex + level);\n });\n }\n\n private get nodes(): WorkflowNodeEntity[] {\n return this.entityManager.getEntities<WorkflowNodeEntity>(WorkflowNodeEntity);\n }\n\n private get lines(): WorkflowLineEntity[] {\n return this.entityManager.getEntities<WorkflowLineEntity>(WorkflowLineEntity);\n }\n\n private get context(): StackingContext {\n return {\n hoveredEntity: this.hoverService.hoveredNode,\n hoveredEntityID: this.hoverService.hoveredNode?.id,\n selectedEntities: this.selectService.selection,\n selectedIDs: this.selectService.selection.map(entity => entity.id),\n };\n }\n\n private mountListener(): void {\n const entityChangeDisposer = this.onEntityChange();\n const zoomDisposer = this.onZoom();\n const hoverDisposer = this.onHover();\n const selectDisposer = this.onSelect();\n this.disposers = [entityChangeDisposer, zoomDisposer, hoverDisposer, selectDisposer];\n }\n\n private onZoom(): Disposable {\n return this.pipelineRegistry.onZoom((scale: number) => {\n this.node.style.transform = `scale(${scale})`;\n });\n }\n\n private onHover(): Disposable {\n return this.hoverService.onHoveredChange(() => {\n this.compute();\n });\n }\n\n private onEntityChange(): Disposable {\n return this.entityManager.onEntityChange(() => {\n this.compute();\n });\n }\n\n private onSelect(): Disposable {\n return this.selectService.onSelectionChanged(() => {\n this.compute();\n });\n }\n}\n","import { FlowNodeBaseType } from '@flowgram.ai/document';\nimport { WorkflowNodeEntity, WorkflowNodeLinesData } from '@flowgram.ai/free-layout-core';\n\nimport type { StackingContext } from './type';\n\nexport class StackingComputing {\n private currentLevel: number;\n\n private topLevel: number;\n\n private maxLevel: number;\n\n private nodeIndexes: Map<string, number>;\n\n private nodeLevel: Map<string, number>;\n\n private lineLevel: Map<string, number>;\n\n private context: StackingContext;\n\n public compute(params: {\n root: WorkflowNodeEntity;\n nodes: WorkflowNodeEntity[];\n context: StackingContext;\n }): {\n /** 节点层级 */\n nodeLevel: Map<string, number>;\n /** 线条层级 */\n lineLevel: Map<string, number>;\n /** 正常渲染的最高层级 */\n topLevel: number;\n /** 选中计算叠加后可能计算出的最高层级 */\n maxLevel: number;\n } {\n this.clearCache();\n const { root, nodes, context } = params;\n this.context = context;\n this.nodeIndexes = this.computeNodeIndexesMap(nodes);\n this.topLevel = this.computeTopLevel(nodes);\n this.maxLevel = this.topLevel * 2;\n this.layerHandler(root.collapsedChildren);\n return {\n nodeLevel: this.nodeLevel,\n lineLevel: this.lineLevel,\n topLevel: this.topLevel,\n maxLevel: this.maxLevel,\n };\n }\n\n private clearCache(): void {\n this.currentLevel = 0;\n this.topLevel = 0;\n this.maxLevel = 0;\n this.nodeIndexes = new Map();\n this.nodeLevel = new Map();\n this.lineLevel = new Map();\n }\n\n private computeNodeIndexesMap(nodes: WorkflowNodeEntity[]): Map<string, number> {\n const nodeIndexMap = new Map<string, number>();\n nodes.forEach((node, index) => {\n nodeIndexMap.set(node.id, index);\n });\n return nodeIndexMap;\n }\n\n private computeTopLevel(nodes: WorkflowNodeEntity[]): number {\n const nodesWithoutRoot = nodes.filter(node => node.id !== FlowNodeBaseType.ROOT);\n const nodeHasChildren = nodesWithoutRoot.reduce((count, node) => {\n if (node.collapsedChildren.length > 0) {\n return count + 1;\n } else {\n return count;\n }\n }, 0);\n // 最高层数 = 节点个数 + 容器节点个数(线条单独占一层) + 抬高一层\n return nodesWithoutRoot.length + nodeHasChildren + 1;\n }\n\n private layerHandler(nodes: WorkflowNodeEntity[], pinTop: boolean = false): void {\n const sortedNodes = nodes.sort((a, b) => {\n const aIndex = this.nodeIndexes.get(a.id);\n const bIndex = this.nodeIndexes.get(b.id);\n if (aIndex === undefined || bIndex === undefined) {\n return 0;\n }\n return aIndex - bIndex;\n });\n\n const lines = nodes\n .map(node => {\n const linesData = node.getData<WorkflowNodeLinesData>(WorkflowNodeLinesData);\n const outputLines = linesData.outputLines.filter(Boolean);\n const inputLines = linesData.inputLines.filter(Boolean);\n // 前后线条会有重复,下面 Map 会通过线条 ID 过滤掉\n return [...outputLines, ...inputLines];\n })\n .flat();\n\n // 线条统一设为当前层级最低\n lines.forEach(line => {\n if (\n line.isDrawing || // 正在绘制\n this.context.hoveredEntityID === line.id || // hover\n this.context.selectedIDs.includes(line.id) // 选中\n ) {\n // 线条置顶条件:正在绘制 / hover / 选中\n this.lineLevel.set(line.id, this.maxLevel);\n } else {\n this.lineLevel.set(line.id, this.getLevel(pinTop));\n }\n });\n this.levelIncrease();\n sortedNodes.forEach(node => {\n const selected = this.context.selectedIDs.includes(node.id);\n if (selected) {\n // 节点置顶条件:选中\n this.nodeLevel.set(node.id, this.topLevel);\n } else {\n this.nodeLevel.set(node.id, this.getLevel(pinTop));\n }\n // 节点层级逐层增高\n this.levelIncrease();\n if (node.collapsedChildren.length > 0) {\n // 子节点层级需低于后续兄弟节点,因此需要先进行计算\n this.layerHandler(node.collapsedChildren, pinTop || selected);\n }\n });\n }\n\n private getLevel(pinTop: boolean): number {\n if (pinTop) {\n return this.topLevel + this.currentLevel;\n }\n return this.currentLevel;\n }\n\n private levelIncrease(): void {\n this.currentLevel += 1;\n }\n}\n","import { FlowNodeRenderData } from '@flowgram.ai/document';\nimport type { WorkflowNodeEntity } from '@flowgram.ai/free-layout-core';\nimport type { WorkflowLineEntity } from '@flowgram.ai/free-layout-core';\n\nimport type { StackingContext } from './type';\nimport { StackingBaseIndex, StackingConfig, StackingType } from './constant';\n\nnamespace NodeComputing {\n export const compute = (node: WorkflowNodeEntity, context: StackingContext): void => {\n const zIndex = nodeZIndex(node, context);\n const element = nodeElement(node);\n element.style.position = 'absolute';\n element.style.zIndex = zIndexStringify(zIndex);\n };\n\n export const stackingIndex = (stackingType: StackingType, level: number): number | undefined => {\n if (level < 1) {\n // root节点\n return undefined;\n }\n const baseZIndex = StackingBaseIndex[stackingType];\n const zIndex =\n StackingConfig.startIndex + StackingConfig.levelIndexStep * (level - 1) + baseZIndex;\n return zIndex;\n };\n\n export const nodeStackingLevel = (\n node: WorkflowNodeEntity,\n context: StackingContext,\n disableTopLevel = false,\n ): number => {\n // TODO 后续支持多层级时这个计算逻辑应该去掉,level信息应该直接由 FlowNodeEntity 缓存给出\n // 多层时这里的计算会有 O(logN) 时间复杂度,并且在多层级联同计算时会有BUG,本次需求不处理这种情况\n const unReversedLinage: WorkflowNodeEntity[] = [];\n let currentNode: WorkflowNodeEntity | undefined = node;\n while (currentNode) {\n unReversedLinage.push(currentNode);\n currentNode = currentNode.parent;\n }\n const linage = unReversedLinage.reverse();\n const nodeLevel = linage.length - 1;\n\n const topLevelIndex = linage.findIndex((node: WorkflowNodeEntity) => {\n if (context.selectedIDs.includes(node.id)) {\n // 存在被选中的父级或自身被选中,直接置顶\n return true;\n }\n return false;\n });\n const topLevel = StackingConfig.allowLevel + (linage.length - topLevelIndex);\n\n if (!disableTopLevel && topLevelIndex !== -1) {\n // 置顶\n return topLevel;\n }\n\n return nodeLevel;\n };\n\n export const zIndexStringify = (zIndex?: number): string => {\n if (zIndex === undefined) {\n return 'auto';\n }\n return zIndex.toString();\n };\n\n const nodeZIndex = (node: WorkflowNodeEntity, context: StackingContext): number | undefined => {\n const level = nodeStackingLevel(node, context);\n const zIndex = stackingIndex(StackingType.Node, level);\n return zIndex;\n };\n\n const nodeElement = (node: WorkflowNodeEntity): HTMLDivElement => {\n const nodeRenderData = node.getData<FlowNodeRenderData>(FlowNodeRenderData);\n return nodeRenderData.node;\n };\n}\n\nnamespace LineComputing {\n export const compute = (line: WorkflowLineEntity, context: StackingContext): void => {\n const zIndex = lineZIndex(line, context);\n const element = line.node;\n element.style.position = 'absolute';\n element.style.zIndex = NodeComputing.zIndexStringify(zIndex);\n };\n\n const lineStackingLevel = (line: WorkflowLineEntity, context: StackingContext): number => {\n if (\n line.isDrawing || // 正在绘制\n context.hoveredEntityID === line.id || // hover\n context.selectedIDs.includes(line.id) // 选中\n ) {\n // 线条置顶条件:正在绘制 / hover / 选中\n return StackingConfig.maxLevel + 1;\n }\n const fromLevel = NodeComputing.nodeStackingLevel(line.from, context, true);\n if (!line.to) {\n // 还处于连线中\n return fromLevel;\n }\n const toLevel = NodeComputing.nodeStackingLevel(line.to, context, true);\n const level = Math.min(fromLevel, toLevel);\n return level;\n };\n\n const lineZIndex = (line: WorkflowLineEntity, context: StackingContext): number | undefined => {\n const level = lineStackingLevel(line, context);\n const zIndex = NodeComputing.stackingIndex(StackingType.Line, level);\n return zIndex;\n };\n}\n\nexport const layersComputing = (params: {\n nodes: WorkflowNodeEntity[];\n lines: WorkflowLineEntity[];\n context: StackingContext;\n}) => {\n const { nodes, lines, context } = params;\n nodes.forEach(node => {\n NodeComputing.compute(node, context);\n });\n lines.forEach(line => {\n LineComputing.compute(line, context);\n });\n};\n","export enum StackingItem {\n Line = 'line',\n Node = 'node',\n}\n\nexport enum StackingType {\n Line = StackingItem.Line,\n Node = StackingItem.Node,\n}\n\nexport const StackingBaseIndex: Record<StackingType, number> = {\n [StackingType.Line]: 0,\n [StackingType.Node]: 1,\n};\n\n// 常量\nconst startIndex = 8;\nconst allowLevel = 2;\n\n// 计算值\nconst levelIndexStep = Object.keys(StackingType).length;\nconst maxLevel = allowLevel * 2;\nconst maxIndex = startIndex + maxLevel * levelIndexStep;\n\nexport const StackingConfig = {\n /** index 起始值 */\n startIndex,\n /** 允许存在的层级 */\n allowLevel,\n /** 每层 index 跨度 */\n levelIndexStep,\n /** 叠加计算后出现的最深层级 */\n maxLevel,\n /** 最大 index */\n maxIndex,\n};\n\nexport enum StackingComputeMode {\n /** 层叠计算模式 */\n Stacking = 'stacking',\n /** 层级计算模式 */\n Layers = 'layers',\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAAoC;;;ACApC,oBAAyB;AACzB,uBAAmC;AACnC,IAAAC,mBAAmC;AACnC,kBAAkE;AAClE,IAAAC,2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G;AACf,SAAK,sBAAsB,EAAE,OAAO,EAAE,iBAAiB;AAAA,EACzD;AAAA,EACA,OAAO,KAAK,MAAM;AAChB,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,KAAK,MAAM,IAAI;AAAA,EACxC;AAAA,EACA,QAAQ,KAAK;AACX,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,MAAM;AAAA,EAC/B;AAAA,EACA,UAAU,KAAK;AACb,UAAM,yBAAyB,IAAI,IAA4B,sBAAsB;AACrF,2BAAuB,QAAQ;AAAA,EACjC;AACF,CAAC;","names":["import_core","import_document","import_free_layout_core","import_document","StackingItem","StackingType","StackingComputeMode","NodeComputing","node","LineComputing"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/free-stack-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
"import": "./dist/esm/index.js",
|
|
7
|
+
"require": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/esm/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"inversify": "^6.0.1",
|
|
17
|
+
"lodash": "^4.17.21",
|
|
18
|
+
"@flowgram.ai/document": "0.1.0",
|
|
19
|
+
"@flowgram.ai/utils": "0.1.0",
|
|
20
|
+
"@flowgram.ai/core": "0.1.0",
|
|
21
|
+
"@flowgram.ai/free-layout-core": "0.1.0",
|
|
22
|
+
"@flowgram.ai/renderer": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/bezier-js": "4.1.3",
|
|
26
|
+
"@types/lodash": "^4.14.137",
|
|
27
|
+
"@types/react": "^18",
|
|
28
|
+
"@types/react-dom": "^18",
|
|
29
|
+
"@types/styled-components": "^5",
|
|
30
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
31
|
+
"eslint": "^8.54.0",
|
|
32
|
+
"react": "^18",
|
|
33
|
+
"react-dom": "^18",
|
|
34
|
+
"reflect-metadata": "^0.1.13",
|
|
35
|
+
"styled-components": "^5",
|
|
36
|
+
"tsup": "^8.0.1",
|
|
37
|
+
"typescript": "^5.0.4",
|
|
38
|
+
"vitest": "^0.34.6",
|
|
39
|
+
"@flowgram.ai/eslint-config": "0.1.0",
|
|
40
|
+
"@flowgram.ai/ts-config": "0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=17",
|
|
44
|
+
"react-dom": ">=17",
|
|
45
|
+
"styled-components": ">=4"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
49
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
50
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
51
|
+
"clean": "rimraf dist",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:cov": "vitest run --coverage",
|
|
54
|
+
"ts-check": "tsc --noEmit",
|
|
55
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
56
|
+
}
|
|
57
|
+
}
|