@flowgram-vue/document 0.2.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.
Files changed (42) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +3233 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1728 -0
  5. package/dist/index.js +3199 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +61 -0
  8. package/src/datas/flow-node-render-data.ts +227 -0
  9. package/src/datas/flow-node-transform-data.ts +337 -0
  10. package/src/datas/flow-node-transition-data.ts +182 -0
  11. package/src/datas/index.ts +8 -0
  12. package/src/entities/flow-document-transformer-entity.ts +125 -0
  13. package/src/entities/flow-node-entity.ts +415 -0
  14. package/src/entities/flow-renderer-state-entity.ts +127 -0
  15. package/src/entities/index.ts +8 -0
  16. package/src/flow-document-config.ts +42 -0
  17. package/src/flow-document-container-module.ts +33 -0
  18. package/src/flow-document-contribution.ts +22 -0
  19. package/src/flow-document-options.ts +79 -0
  20. package/src/flow-document.ts +766 -0
  21. package/src/flow-render-tree.ts +236 -0
  22. package/src/flow-virtual-tree.ts +244 -0
  23. package/src/index.ts +16 -0
  24. package/src/layout/horizontal-fixed-layout.ts +198 -0
  25. package/src/layout/index.ts +7 -0
  26. package/src/layout/vertical-fixed-layout.ts +198 -0
  27. package/src/services/flow-drag-service.ts +211 -0
  28. package/src/services/flow-group-service/flow-group-controller.ts +120 -0
  29. package/src/services/flow-group-service/flow-group-service.ts +107 -0
  30. package/src/services/flow-group-service/flow-group-utils.ts +104 -0
  31. package/src/services/flow-group-service/index.ts +7 -0
  32. package/src/services/flow-operation-base-service.ts +333 -0
  33. package/src/services/index.ts +8 -0
  34. package/src/typings/flow-group.ts +8 -0
  35. package/src/typings/flow-layout.ts +72 -0
  36. package/src/typings/flow-node-register.ts +356 -0
  37. package/src/typings/flow-operation.ts +312 -0
  38. package/src/typings/flow-transition.ts +104 -0
  39. package/src/typings/flow.ts +70 -0
  40. package/src/typings/index.ts +11 -0
  41. package/src/utils/get-default-spacing.ts +21 -0
  42. package/src/utils/index.ts +6 -0
package/dist/index.js ADDED
@@ -0,0 +1,3199 @@
1
+ import { EntityManager, EntityData, TransformData, Bounds, Entity, ConfigEntity } from '@flowgram-vue/core';
2
+ import { Emitter, Disposable, Compare, domUtils, Rectangle, Point, DisposableCollection } from '@flowgram-vue/utils';
3
+ import { debounce, omit } from 'lodash-es';
4
+ import { injectable, inject, optional, multiInject, postConstruct, ContainerModule } from 'inversify';
5
+ import { nanoid } from 'nanoid';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __decorateClass = (decorators, target, key, kind) => {
10
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
11
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
12
+ if (decorator = decorators[i])
13
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
14
+ if (kind && result) __defProp(target, key, result);
15
+ return result;
16
+ };
17
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
18
+
19
+ // src/typings/flow.ts
20
+ var FlowNodeBaseType = /* @__PURE__ */ ((FlowNodeBaseType2) => {
21
+ FlowNodeBaseType2["START"] = "start";
22
+ FlowNodeBaseType2["DEFAULT"] = "default";
23
+ FlowNodeBaseType2["ROOT"] = "root";
24
+ FlowNodeBaseType2["EMPTY"] = "empty";
25
+ FlowNodeBaseType2["INLINE_BLOCKS"] = "inlineBlocks";
26
+ FlowNodeBaseType2["BLOCK_ICON"] = "blockIcon";
27
+ FlowNodeBaseType2["BLOCK"] = "block";
28
+ FlowNodeBaseType2["BLOCK_ORDER_ICON"] = "blockOrderIcon";
29
+ FlowNodeBaseType2["GROUP"] = "group";
30
+ FlowNodeBaseType2["END"] = "end";
31
+ FlowNodeBaseType2["BREAK"] = "break";
32
+ FlowNodeBaseType2["CONDITION"] = "condition";
33
+ FlowNodeBaseType2["SUB_CANVAS"] = "subCanvas";
34
+ FlowNodeBaseType2["MULTI_INPUTS"] = "multiInputs";
35
+ FlowNodeBaseType2["MULTI_OUTPUTS"] = "multiOutputs";
36
+ FlowNodeBaseType2["INPUT"] = "input";
37
+ FlowNodeBaseType2["OUTPUT"] = "output";
38
+ FlowNodeBaseType2["SLOT"] = "slot";
39
+ FlowNodeBaseType2["SLOT_BLOCK"] = "slotBlock";
40
+ return FlowNodeBaseType2;
41
+ })(FlowNodeBaseType || {});
42
+ var FlowNodeSplitType = /* @__PURE__ */ ((FlowNodeSplitType2) => {
43
+ FlowNodeSplitType2["SIMPLE_SPLIT"] = "simpleSplit";
44
+ FlowNodeSplitType2["DYNAMIC_SPLIT"] = "dynamicSplit";
45
+ FlowNodeSplitType2["STATIC_SPLIT"] = "staticSplit";
46
+ return FlowNodeSplitType2;
47
+ })(FlowNodeSplitType || {});
48
+ var FlowDocumentConfigEnum = /* @__PURE__ */ ((FlowDocumentConfigEnum2) => {
49
+ FlowDocumentConfigEnum2["END_NODES_REFINE_BRANCH"] = "END_NODES_REFINE_BRANCH";
50
+ return FlowDocumentConfigEnum2;
51
+ })(FlowDocumentConfigEnum || {});
52
+ var FLOW_DEFAULT_HIDDEN_TYPES = [
53
+ "root" /* ROOT */,
54
+ "inlineBlocks" /* INLINE_BLOCKS */,
55
+ "block" /* BLOCK */
56
+ ];
57
+
58
+ // src/typings/flow-layout.ts
59
+ var FlowLayout = /* @__PURE__ */ Symbol("FlowLayout");
60
+ var FlowLayoutContribution = /* @__PURE__ */ Symbol("FlowLayoutContribution");
61
+ var FlowLayoutDefault = /* @__PURE__ */ ((FlowLayoutDefault2) => {
62
+ FlowLayoutDefault2["VERTICAL_FIXED_LAYOUT"] = "vertical-fixed-layout";
63
+ FlowLayoutDefault2["HORIZONTAL_FIXED_LAYOUT"] = "horizontal-fixed-layout";
64
+ return FlowLayoutDefault2;
65
+ })(FlowLayoutDefault || {});
66
+ ((FlowLayoutDefault2) => {
67
+ function isVertical(layout) {
68
+ return layout.name === "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
69
+ }
70
+ FlowLayoutDefault2.isVertical = isVertical;
71
+ })(FlowLayoutDefault || (FlowLayoutDefault = {}));
72
+
73
+ // src/typings/flow-transition.ts
74
+ var FlowTransitionLineEnum = /* @__PURE__ */ ((FlowTransitionLineEnum2) => {
75
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["STRAIGHT_LINE"] = 0] = "STRAIGHT_LINE";
76
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["DIVERGE_LINE"] = 1] = "DIVERGE_LINE";
77
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["MERGE_LINE"] = 2] = "MERGE_LINE";
78
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["ROUNDED_LINE"] = 3] = "ROUNDED_LINE";
79
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["CUSTOM_LINE"] = 4] = "CUSTOM_LINE";
80
+ FlowTransitionLineEnum2[FlowTransitionLineEnum2["DRAGGING_LINE"] = 5] = "DRAGGING_LINE";
81
+ return FlowTransitionLineEnum2;
82
+ })(FlowTransitionLineEnum || {});
83
+ var FlowTransitionLabelEnum = /* @__PURE__ */ ((FlowTransitionLabelEnum2) => {
84
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["ADDER_LABEL"] = 0] = "ADDER_LABEL";
85
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["TEXT_LABEL"] = 1] = "TEXT_LABEL";
86
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["COLLAPSE_LABEL"] = 2] = "COLLAPSE_LABEL";
87
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["COLLAPSE_ADDER_LABEL"] = 3] = "COLLAPSE_ADDER_LABEL";
88
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["CUSTOM_LABEL"] = 4] = "CUSTOM_LABEL";
89
+ FlowTransitionLabelEnum2[FlowTransitionLabelEnum2["BRANCH_DRAGGING_LABEL"] = 5] = "BRANCH_DRAGGING_LABEL";
90
+ return FlowTransitionLabelEnum2;
91
+ })(FlowTransitionLabelEnum || {});
92
+
93
+ // src/typings/flow-node-register.ts
94
+ var DefaultSpacingKey = {
95
+ /**
96
+ * 普通节点间距。垂直 / 水平
97
+ */
98
+ NODE_SPACING: "SPACING",
99
+ /**
100
+ * 分支节点间距
101
+ */
102
+ BRANCH_SPACING: "BRANCH_SPACING",
103
+ /**
104
+ * 圆弧线条拐角 radius
105
+ */
106
+ ROUNDED_LINE_RADIUS: "ROUNDED_LINE_RADIUS",
107
+ /**
108
+ * 圆弧线条 x radius
109
+ */
110
+ ROUNDED_LINE_X_RADIUS: "ROUNDED_LINE_X_RADIUS",
111
+ /**
112
+ * 圆弧线条 y radius
113
+ */
114
+ ROUNDED_LINE_Y_RADIUS: "ROUNDED_LINE_Y_RADIUS",
115
+ /**
116
+ * dynamicSplit block list 下部留白间距,因为有两个拐弯,所以翻一倍
117
+ */
118
+ INLINE_BLOCKS_PADDING_BOTTOM: "INLINE_BLOCKS_PADDING_BOTTOM",
119
+ /**
120
+ * 复合节点距离上个节点的距离
121
+ * 条件分支菱形下边和分支的距离
122
+ */
123
+ COLLAPSED_SPACING: "COLLAPSED_SPACING",
124
+ /**
125
+ * width of hover area
126
+ */
127
+ HOVER_AREA_WIDTH: "HOVER_AREA_WIDTH"
128
+ };
129
+ var DEFAULT_SPACING = {
130
+ NULL: 0,
131
+ [DefaultSpacingKey.NODE_SPACING]: 32,
132
+ // 普通节点间距。垂直 / 水平
133
+ [DefaultSpacingKey.BRANCH_SPACING]: 20,
134
+ // 分支节点间距
135
+ /**
136
+ * @deprecated use 'BRANCH_SPACING' instead
137
+ */
138
+ MARGIN_RIGHT: 20,
139
+ // 分支节点右边间距
140
+ INLINE_BLOCK_PADDING_BOTTOM: 16,
141
+ // block 底部留白
142
+ INLINE_BLOCKS_PADDING_TOP: 30,
143
+ // block list 上部留白间距
144
+ // JS 浮点数有误差,1046.6 -1006.6 = 39.9999999,会导致 间距/20 < 2 导致布局计算问题,因此需要额外增加 0.1 像素
145
+ [DefaultSpacingKey.INLINE_BLOCKS_PADDING_BOTTOM]: 40.1,
146
+ // block lit 下部留白间距,因为有两个拐弯,所以翻一倍
147
+ MIN_INLINE_BLOCK_SPACING: 200,
148
+ // 分支间最小边距 (垂直布局)
149
+ MIN_INLINE_BLOCK_SPACING_HORIZONTAL: 80,
150
+ // 分支间最小边距 (水平布局)
151
+ [DefaultSpacingKey.COLLAPSED_SPACING]: 12,
152
+ // 复合节点距离上个节点的距离
153
+ [DefaultSpacingKey.ROUNDED_LINE_RADIUS]: 16,
154
+ // 圆弧线条拐角 radius
155
+ [DefaultSpacingKey.ROUNDED_LINE_X_RADIUS]: 16,
156
+ // 圆弧线条 x radius
157
+ [DefaultSpacingKey.ROUNDED_LINE_Y_RADIUS]: 20,
158
+ // 圆弧线条 y radius
159
+ [DefaultSpacingKey.HOVER_AREA_WIDTH]: 20
160
+ // width of hover area
161
+ };
162
+ var DRAGGING_TYPE = /* @__PURE__ */ ((DRAGGING_TYPE2) => {
163
+ DRAGGING_TYPE2["NODE"] = "node";
164
+ DRAGGING_TYPE2["BRANCH"] = "branch";
165
+ return DRAGGING_TYPE2;
166
+ })(DRAGGING_TYPE || {});
167
+ var LABEL_SIDE_TYPE = /* @__PURE__ */ ((LABEL_SIDE_TYPE2) => {
168
+ LABEL_SIDE_TYPE2["PRE_BRANCH"] = "pre_branch";
169
+ LABEL_SIDE_TYPE2["NORMAL_BRANCH"] = "normal_branch";
170
+ return LABEL_SIDE_TYPE2;
171
+ })(LABEL_SIDE_TYPE || {});
172
+ var DEFAULT_SIZE = {
173
+ width: 280,
174
+ height: 60
175
+ };
176
+ var DEFAULT_FLOW_NODE_META = (nodeType, document) => {
177
+ const hidden = FLOW_DEFAULT_HIDDEN_TYPES.includes(nodeType);
178
+ return {
179
+ isStart: nodeType === "start",
180
+ hidden,
181
+ defaultExpanded: document.options.allNodesDefaultExpanded,
182
+ size: DEFAULT_SIZE,
183
+ origin: document.layout.getDefaultNodeOrigin(),
184
+ isInlineBlocks: nodeType === "inlineBlocks" /* INLINE_BLOCKS */,
185
+ // miniSize: { width: 200, height: 40 },
186
+ spacing: DEFAULT_SPACING.SPACING,
187
+ inlineSpacingPre: 0,
188
+ inlineSpacingAfter: 0,
189
+ expandable: true,
190
+ draggable: true,
191
+ selectable: true,
192
+ renderKey: "",
193
+ minInlineBlockSpacing: () => {
194
+ const isVertical = FlowLayoutDefault.isVertical(document.layout);
195
+ return isVertical ? DEFAULT_SPACING.MIN_INLINE_BLOCK_SPACING : DEFAULT_SPACING.MIN_INLINE_BLOCK_SPACING_HORIZONTAL;
196
+ }
197
+ };
198
+ };
199
+ var FlowNodeRegistry;
200
+ ((FlowNodeRegistry4) => {
201
+ function mergeChildRegistries(r1 = [], r2 = []) {
202
+ if (r1.length === 0 || r2.length === 0) {
203
+ return [...r1, ...r2];
204
+ }
205
+ const r1Filter = r1.map((r1Current) => {
206
+ const r2Current = r2.find((n) => n.type === r1Current.type);
207
+ if (r2Current) {
208
+ return merge(r1Current, r2Current, r1Current.type);
209
+ }
210
+ return r1Current;
211
+ });
212
+ const r2Filter = r2.filter((n) => !r1.some((r) => r.type === n.type));
213
+ return [...r1Filter, ...r2Filter];
214
+ }
215
+ FlowNodeRegistry4.mergeChildRegistries = mergeChildRegistries;
216
+ function merge(registry1, registry2, finalType) {
217
+ const extendKeys = registry1.__extends__ ? registry1.__extends__.slice() : [];
218
+ if (registry1.type !== registry2.type) {
219
+ extendKeys.unshift(registry1.type);
220
+ }
221
+ return {
222
+ ...registry1,
223
+ ...registry2,
224
+ extendChildRegistries: mergeChildRegistries(
225
+ registry1.extendChildRegistries,
226
+ registry2.extendChildRegistries
227
+ ),
228
+ meta: { ...registry1.meta, ...registry2.meta },
229
+ extend: void 0,
230
+ type: finalType,
231
+ __extends__: extendKeys
232
+ };
233
+ }
234
+ FlowNodeRegistry4.merge = merge;
235
+ function extend(registry, extendRegistries) {
236
+ if (!extendRegistries.length) return registry;
237
+ return extendRegistries.reduce((res, ext) => merge(res, ext, registry.type), registry);
238
+ }
239
+ FlowNodeRegistry4.extend = extend;
240
+ })(FlowNodeRegistry || (FlowNodeRegistry = {}));
241
+
242
+ // src/typings/flow-operation.ts
243
+ var OperationType = /* @__PURE__ */ ((OperationType2) => {
244
+ OperationType2["addFromNode"] = "addFromNode";
245
+ OperationType2["deleteFromNode"] = "deleteFromNode";
246
+ OperationType2["addBlock"] = "addBlock";
247
+ OperationType2["deleteBlock"] = "deleteBlock";
248
+ OperationType2["createGroup"] = "createGroup";
249
+ OperationType2["ungroup"] = "ungroup";
250
+ OperationType2["moveNodes"] = "moveNodes";
251
+ OperationType2["moveBlock"] = "moveBlock";
252
+ OperationType2["moveChildNodes"] = "moveChildNodes";
253
+ OperationType2["addNodes"] = "addNodes";
254
+ OperationType2["deleteNodes"] = "deleteNodes";
255
+ OperationType2["addChildNode"] = "addChildNode";
256
+ OperationType2["deleteChildNode"] = "deleteChildNode";
257
+ OperationType2["addNode"] = "addNode";
258
+ OperationType2["deleteNode"] = "deleteNode";
259
+ return OperationType2;
260
+ })(OperationType || {});
261
+ var FlowOperationBaseService = /* @__PURE__ */ Symbol("FlowOperationBaseService");
262
+ var _FlowNodeRenderData = class _FlowNodeRenderData extends EntityData {
263
+ constructor(entity) {
264
+ super(entity);
265
+ this.onExtInfoChangeEmitter = new Emitter();
266
+ this.onExtInfoChange = this.onExtInfoChangeEmitter.event;
267
+ this.toDispose.push(
268
+ Disposable.create(() => {
269
+ if (this._node) this._node.remove();
270
+ })
271
+ );
272
+ }
273
+ get key() {
274
+ return this.entity.id;
275
+ }
276
+ getDefaultData() {
277
+ const { addable, expandable, defaultExpanded } = this.entity.getNodeMeta();
278
+ return {
279
+ addable,
280
+ expandable,
281
+ expanded: defaultExpanded || false,
282
+ activated: false,
283
+ hovered: false,
284
+ dragging: false,
285
+ stackIndex: 0
286
+ };
287
+ }
288
+ updateExtInfo(info, fullUpdate) {
289
+ const oldInfo = this.data.extInfo;
290
+ const newInfo = fullUpdate ? info : { ...oldInfo, ...info };
291
+ if (Compare.isChanged(oldInfo, newInfo)) {
292
+ this.update({
293
+ extInfo: newInfo
294
+ });
295
+ this.onExtInfoChangeEmitter.fire({ oldInfo, newInfo });
296
+ }
297
+ }
298
+ getExtInfo() {
299
+ return this.data.extInfo;
300
+ }
301
+ get addable() {
302
+ return this.data.addable;
303
+ }
304
+ get expandable() {
305
+ return this.data.expandable;
306
+ }
307
+ get draggable() {
308
+ const { draggable } = this.entity.getNodeMeta();
309
+ if (typeof draggable === "function") {
310
+ return draggable(this.entity);
311
+ }
312
+ return draggable;
313
+ }
314
+ get expanded() {
315
+ return this.data.expanded;
316
+ }
317
+ set expanded(expanded) {
318
+ if (this.expandable && this.data.expanded !== expanded) {
319
+ this.data.expanded = expanded;
320
+ this.fireChange();
321
+ }
322
+ }
323
+ toggleExpand() {
324
+ this.expanded = !this.expanded;
325
+ }
326
+ toggleMouseEnter(silent = false) {
327
+ this.entity.document.renderState.setNodeHovered(this.entity);
328
+ if (silent) return;
329
+ const transform = this.entity.getData(FlowNodeTransformData);
330
+ if (transform.renderState.hidden) {
331
+ return;
332
+ }
333
+ if (this.mouseLeaveTimeout) {
334
+ clearTimeout(this.mouseLeaveTimeout);
335
+ this.mouseLeaveTimeout = void 0;
336
+ }
337
+ transform.renderState.hovered = true;
338
+ if (this.entity.isFirst && this.entity.parent?.id !== "root") {
339
+ transform.parent.renderState.activated = true;
340
+ } else {
341
+ transform.renderState.activated = true;
342
+ }
343
+ }
344
+ toggleMouseLeave(silent = false) {
345
+ this.entity.document.renderState.setNodeHovered(void 0);
346
+ if (silent) return;
347
+ const transform = this.entity.getData(FlowNodeTransformData);
348
+ this.mouseLeaveTimeout = setTimeout(() => {
349
+ transform.renderState.hovered = false;
350
+ if (this.entity.isFirst && this.entity.parent?.id !== "root") {
351
+ transform.parent.renderState.activated = false;
352
+ }
353
+ transform.renderState.activated = false;
354
+ }, 200);
355
+ }
356
+ get hidden() {
357
+ return this.entity.hidden;
358
+ }
359
+ set hovered(hovered) {
360
+ this.data.hovered = hovered;
361
+ this.fireChange();
362
+ }
363
+ get hovered() {
364
+ return this.data.hovered;
365
+ }
366
+ get dragging() {
367
+ return this.data.dragging;
368
+ }
369
+ set dragging(dragging) {
370
+ if (this.data.dragging !== dragging) {
371
+ this.data.dragging = dragging;
372
+ this.fireChange();
373
+ }
374
+ }
375
+ set activated(activated) {
376
+ if (this.entity.flowNodeType === "blockIcon" /* BLOCK_ICON */ && this.entity.parent) {
377
+ this.entity.parent.getData(_FlowNodeRenderData).activated = activated;
378
+ return;
379
+ }
380
+ if (this.data.activated !== activated) {
381
+ this.data.activated = activated;
382
+ this.fireChange();
383
+ }
384
+ }
385
+ get activated() {
386
+ const { entity } = this;
387
+ if (entity.parent && entity.parent.getData(_FlowNodeRenderData).activated) {
388
+ return true;
389
+ }
390
+ return this.data.activated;
391
+ }
392
+ get stackIndex() {
393
+ return this.data.stackIndex;
394
+ }
395
+ set stackIndex(index) {
396
+ this.data.stackIndex = index;
397
+ }
398
+ get lineActivated() {
399
+ const { activated } = this;
400
+ if (!activated) return false;
401
+ return Boolean(
402
+ this.entity.parent?.getData(_FlowNodeRenderData)?.activated || this.entity.isInlineBlock || this.entity.next?.getData(_FlowNodeRenderData).activated
403
+ );
404
+ }
405
+ get node() {
406
+ if (this._node) return this._node;
407
+ this._node = domUtils.createDivWithClass("gedit-flow-activity-node");
408
+ this._node.dataset.testid = "sdk.workflow.canvas.node";
409
+ this._node.dataset.nodeId = this.entity.id;
410
+ return this._node;
411
+ }
412
+ dispose() {
413
+ super.dispose();
414
+ this.onExtInfoChangeEmitter.dispose();
415
+ }
416
+ };
417
+ _FlowNodeRenderData.type = "FlowNodeRenderData";
418
+ var FlowNodeRenderData = _FlowNodeRenderData;
419
+
420
+ // src/datas/flow-node-transform-data.ts
421
+ var _FlowNodeTransformData = class _FlowNodeTransformData extends EntityData {
422
+ constructor(entity) {
423
+ super(entity);
424
+ this.localDirty = true;
425
+ const { origin } = this.entity.getNodeMeta();
426
+ this.transform = this.entity.addData(TransformData);
427
+ this.transform.changeLocked = true;
428
+ this.transform.update({ origin: { ...origin } });
429
+ this.transform.changeLocked = false;
430
+ this.renderState = this.entity.addData(FlowNodeRenderData);
431
+ this.bindChange(this.transform);
432
+ this.toDispose.push(
433
+ Disposable.create(() => {
434
+ const { next, parent } = this;
435
+ if (next) next.localDirty = true;
436
+ if (parent) parent.localDirty = true;
437
+ })
438
+ );
439
+ }
440
+ get origin() {
441
+ return this.transform.origin;
442
+ }
443
+ get key() {
444
+ return this.entity.id;
445
+ }
446
+ getDefaultData() {
447
+ const { size, hidden } = this.entity.getNodeMeta();
448
+ return {
449
+ size: !hidden ? { ...size } : { width: 0, height: 0 }
450
+ };
451
+ }
452
+ /**
453
+ * 获取节点是否展开
454
+ */
455
+ get collapsed() {
456
+ return this.entity.collapsed;
457
+ }
458
+ set collapsed(collapsed) {
459
+ this.entity.collapsed = collapsed;
460
+ this.localDirty = true;
461
+ if (this.firstChild) this.firstChild.localDirty = true;
462
+ this.fireChange();
463
+ }
464
+ /**
465
+ * 获取节点的大小
466
+ */
467
+ get size() {
468
+ return this.entity.memoGlobal("size", () => {
469
+ if (this.isContainer) return this.transform.localSize;
470
+ return this.data.size;
471
+ });
472
+ }
473
+ get position() {
474
+ const { position } = this.transform;
475
+ return {
476
+ x: position.x,
477
+ y: position.y
478
+ };
479
+ }
480
+ set position(position) {
481
+ this.transform.update({
482
+ position
483
+ });
484
+ }
485
+ set size(size) {
486
+ const { width, height } = this.data.size;
487
+ if (this.isContainer) return;
488
+ if (size.width !== width || size.height !== height) {
489
+ this._data.size = { ...size };
490
+ this.localDirty = true;
491
+ this.fireChange();
492
+ }
493
+ }
494
+ get inputPoint() {
495
+ return this.entity.memoGlobal("inputPoint", () => {
496
+ const { getInputPoint } = this.entity.getNodeRegistry();
497
+ return getInputPoint ? getInputPoint(this, this.entity.document.layout) : this.defaultInputPoint;
498
+ });
499
+ }
500
+ get defaultInputPoint() {
501
+ return this.entity.memoGlobal(
502
+ "defaultInputPoint",
503
+ () => this.entity.document.layout.getDefaultInputPoint(this.entity)
504
+ );
505
+ }
506
+ get defaultOutputPoint() {
507
+ return this.entity.memoGlobal(
508
+ "defaultOutputPoint",
509
+ () => this.entity.document.layout.getDefaultOutputPoint(this.entity)
510
+ );
511
+ }
512
+ get outputPoint() {
513
+ return this.entity.memoGlobal("outputPoint", () => {
514
+ const { getOutputPoint } = this.entity.getNodeRegistry();
515
+ return getOutputPoint ? getOutputPoint(this, this.entity.document.layout) : this.defaultOutputPoint;
516
+ });
517
+ }
518
+ /**
519
+ * 原点的最左偏移
520
+ */
521
+ get originDeltaX() {
522
+ return this.entity.memoLocal("originDeltaX", () => {
523
+ const { children } = this;
524
+ const { getOriginDeltaX } = this.entity.getNodeRegistry();
525
+ if (getOriginDeltaX) return getOriginDeltaX(this, this.entity.document.layout);
526
+ if (children.length === 0) {
527
+ return -this.size.width * this.origin.x;
528
+ }
529
+ if (children.length === 1) return children[0].originDeltaX;
530
+ if (this.entity.isInlineBlocks && children.length > 1) {
531
+ return children[0].originDeltaX + this.transform.position.x;
532
+ }
533
+ return children.reduce((res, child) => {
534
+ const deltaX = child.originDeltaX;
535
+ return res === void 0 || deltaX < res ? deltaX : res;
536
+ }, void 0);
537
+ });
538
+ }
539
+ /**
540
+ * 原点 y 轴偏移
541
+ */
542
+ get originDeltaY() {
543
+ return this.entity.memoLocal("originDeltaY", () => {
544
+ const { children } = this;
545
+ const { getOriginDeltaY } = this.entity.getNodeRegistry();
546
+ if (getOriginDeltaY) return getOriginDeltaY(this, this.entity.document.layout);
547
+ if (children.length === 0) {
548
+ return -this.size.height * this.origin.y;
549
+ }
550
+ if (children.length === 1) return children[0].originDeltaY;
551
+ if (this.entity.isInlineBlocks && children.length > 1) {
552
+ return children[0].originDeltaY + this.transform.position.y;
553
+ }
554
+ return children.reduce((res, child) => {
555
+ const deltaY = child.originDeltaY;
556
+ return res === void 0 || deltaY < res ? deltaY : res;
557
+ }, void 0);
558
+ });
559
+ }
560
+ /**
561
+ * 绝对坐标 bbox, 不包含自身的 spacing(marginBottom), 但是包含 inlineSpacing 和 子节点的 spacing
562
+ */
563
+ get bounds() {
564
+ return this.entity.memoGlobal("bounds", () => {
565
+ const { transform } = this;
566
+ if (this.isContainer) {
567
+ const childrenRects = transform.children.map(
568
+ (c) => c.entity.getData(_FlowNodeTransformData).boundsWithPadding
569
+ );
570
+ return Rectangle.enlarge(childrenRects).withPadding(this.padding);
571
+ }
572
+ return transform.bounds;
573
+ });
574
+ }
575
+ get boundsWithPadding() {
576
+ return this.entity.memoGlobal("boundsWithPadding", () => {
577
+ const { transform } = this;
578
+ if (this.isContainer) {
579
+ const childrenRects = transform.children.map(
580
+ (c) => c.entity.getData(_FlowNodeTransformData).boundsWithPadding
581
+ );
582
+ return Rectangle.enlarge(childrenRects).withPadding(this.padding);
583
+ }
584
+ return transform.bounds.clone().withPadding(this.padding);
585
+ });
586
+ }
587
+ get isContainer() {
588
+ return this.transform.isContainer;
589
+ }
590
+ /**
591
+ * 相对坐标 bbox, 这里的 localBounds 会加入 padding 一起算
592
+ */
593
+ get localBounds() {
594
+ return this.entity.memoLocal("localBounds", () => {
595
+ const { transform } = this;
596
+ if (this.isContainer) {
597
+ const childrenRects = transform.children.map(
598
+ (c) => c.entity.getData(_FlowNodeTransformData).localBounds
599
+ );
600
+ const childrenBounds = Rectangle.enlarge(childrenRects).withPadding(this.padding);
601
+ return Bounds.applyMatrix(childrenBounds, transform.localTransform);
602
+ }
603
+ return transform.localBounds.clone().withPadding(this.padding);
604
+ });
605
+ }
606
+ get padding() {
607
+ return this.entity.document.layout.getPadding(this.entity);
608
+ }
609
+ setParentTransform(transform) {
610
+ if (this.transform.parent !== transform?.transform) {
611
+ this.localDirty = true;
612
+ }
613
+ this.transform.setParent(transform?.transform);
614
+ }
615
+ get spacing() {
616
+ const { spacing } = this.entity.getNodeMeta();
617
+ return typeof spacing === "function" ? spacing(this) : spacing;
618
+ }
619
+ get inlineSpacingPre() {
620
+ const { inlineSpacingPre } = this.entity.getNodeMeta();
621
+ return typeof inlineSpacingPre === "function" ? inlineSpacingPre(this) : inlineSpacingPre;
622
+ }
623
+ get inlineSpacingAfter() {
624
+ const { inlineSpacingAfter } = this.entity.getNodeMeta();
625
+ return typeof inlineSpacingAfter === "function" ? inlineSpacingAfter(this) : inlineSpacingAfter;
626
+ }
627
+ get minInlineBlockSpacing() {
628
+ const { minInlineBlockSpacing } = this.entity.getNodeMeta();
629
+ return typeof minInlineBlockSpacing === "function" ? minInlineBlockSpacing(this) : minInlineBlockSpacing;
630
+ }
631
+ get children() {
632
+ return this.entity.children.map(
633
+ (child) => child.getData(_FlowNodeTransformData)
634
+ );
635
+ }
636
+ /**
637
+ * 上一个节点的 transform 数据
638
+ */
639
+ get pre() {
640
+ return this.entity.pre?.getData(_FlowNodeTransformData);
641
+ }
642
+ get originParent() {
643
+ return this.entity.originParent?.getData(_FlowNodeTransformData);
644
+ }
645
+ get isFirst() {
646
+ return this.entity.isFirst;
647
+ }
648
+ get isLast() {
649
+ return this.entity.isLast;
650
+ }
651
+ get lastChild() {
652
+ return this.entity.lastChild?.getData(_FlowNodeTransformData);
653
+ }
654
+ get firstChild() {
655
+ return this.entity.firstChild?.getData(_FlowNodeTransformData);
656
+ }
657
+ /**
658
+ * 下一个节点的 transform 数据
659
+ */
660
+ get next() {
661
+ return this.entity.next?.getData(_FlowNodeTransformData);
662
+ }
663
+ /**
664
+ * parent 节点的 transform 数据
665
+ */
666
+ get parent() {
667
+ return this.entity.parent?.getData(_FlowNodeTransformData);
668
+ }
669
+ };
670
+ _FlowNodeTransformData.type = "FlowNodeTransformData";
671
+ var FlowNodeTransformData = _FlowNodeTransformData;
672
+ var drawLineToNext = (transition) => {
673
+ const { transform } = transition;
674
+ const currentOutput = transform.outputPoint;
675
+ if (transform.next) {
676
+ return [
677
+ {
678
+ type: 0 /* STRAIGHT_LINE */,
679
+ from: currentOutput,
680
+ to: transform.next.inputPoint
681
+ }
682
+ ];
683
+ }
684
+ return [];
685
+ };
686
+ var drawLineToBottom = (transition) => {
687
+ const { transform } = transition;
688
+ const currentOutput = transform.outputPoint;
689
+ const isParentRoot = transform.parent?.entity.flowNodeType === "root" /* ROOT */;
690
+ const parentOutput = transform.parent?.outputPoint;
691
+ if (!isParentRoot && !transform.next && parentOutput && !new Point().copyFrom(currentOutput).equals(parentOutput) && !transition.isNodeEnd) {
692
+ return [
693
+ {
694
+ type: 0 /* STRAIGHT_LINE */,
695
+ from: currentOutput,
696
+ to: parentOutput
697
+ }
698
+ ];
699
+ }
700
+ return [];
701
+ };
702
+ var FlowNodeTransitionData = class extends EntityData {
703
+ getDefaultData() {
704
+ return {};
705
+ }
706
+ formatLines(lines) {
707
+ if (this.entity.document.options?.formatNodeLines) {
708
+ return this.entity.document.options?.formatNodeLines?.(this.entity, lines);
709
+ }
710
+ return lines;
711
+ }
712
+ formatLabels(labels) {
713
+ if (this.entity.document.options.formatNodeLabels) {
714
+ return this.entity.document.options?.formatNodeLabels?.(this.entity, labels);
715
+ }
716
+ return labels;
717
+ }
718
+ get lines() {
719
+ return this.entity.memoGlobal("lines", () => {
720
+ const { getChildLines } = this.entity.parent?.getNodeRegistry() || {};
721
+ if (getChildLines) {
722
+ return this.formatLines(getChildLines(this, this.entity.document.layout));
723
+ }
724
+ const { getLines } = this.entity.getNodeRegistry();
725
+ if (getLines) {
726
+ return this.formatLines(getLines(this, this.entity.document.layout));
727
+ }
728
+ if (this.transform.entity.isInlineBlock) {
729
+ return [];
730
+ }
731
+ return this.formatLines([...drawLineToNext(this), ...drawLineToBottom(this)]);
732
+ });
733
+ }
734
+ get labels() {
735
+ return this.entity.memoGlobal("labels", () => {
736
+ const { getChildLabels } = this.entity.parent?.getNodeRegistry() || {};
737
+ if (getChildLabels) {
738
+ return this.formatLabels(getChildLabels(this, this.entity.document.layout));
739
+ }
740
+ const { getLabels } = this.entity.getNodeRegistry();
741
+ if (getLabels) {
742
+ return this.formatLabels(getLabels(this, this.entity.document.layout));
743
+ }
744
+ if (this.transform.entity.isInlineBlock) {
745
+ return [];
746
+ }
747
+ const currentOutput = this.transform.outputPoint;
748
+ if (this.transform.next) {
749
+ return this.formatLabels([
750
+ {
751
+ offset: Point.getMiddlePoint(currentOutput, this.transform.next.inputPoint),
752
+ type: 0 /* ADDER_LABEL */
753
+ }
754
+ ]);
755
+ }
756
+ const parentOutput = this.transform.parent?.outputPoint;
757
+ if (parentOutput && !new Point().copyFrom(currentOutput).equals(parentOutput) && !this.isNodeEnd) {
758
+ return this.formatLabels([
759
+ {
760
+ offset: parentOutput,
761
+ type: 0 /* ADDER_LABEL */
762
+ }
763
+ ]);
764
+ }
765
+ return [];
766
+ });
767
+ }
768
+ constructor(entity) {
769
+ super(entity);
770
+ this.transform = this.entity.addData(FlowNodeTransformData);
771
+ this.renderData = this.entity.addData(FlowNodeRenderData);
772
+ this.bindChange(this.transform);
773
+ this.bindChange(this.renderData);
774
+ }
775
+ get collapsed() {
776
+ return this.entity.collapsed;
777
+ }
778
+ get isNodeEnd() {
779
+ return this.entity.isNodeEnd;
780
+ }
781
+ };
782
+ FlowNodeTransitionData.type = "FlowNodeTransitionData";
783
+
784
+ // src/entities/flow-node-entity.ts
785
+ var FlowNodeEntity = class extends Entity {
786
+ constructor(conf) {
787
+ super(conf);
788
+ this._memoLocalCache = /* @__PURE__ */ new Map();
789
+ this._memoGlobalCache = /* @__PURE__ */ new Map();
790
+ this.flowNodeType = "unknown";
791
+ // 流程类型
792
+ /**
793
+ * 是否隐藏
794
+ */
795
+ this._hidden = false;
796
+ this.index = -1;
797
+ this.document = conf.document;
798
+ this.flowNodeType = conf.flowNodeType;
799
+ this.originParent = conf.originParent;
800
+ this.metaFromJSON = conf.meta;
801
+ this.onDispose(() => {
802
+ this.document.originTree.getChildren(this).slice().forEach((child) => {
803
+ child.dispose();
804
+ });
805
+ this.document.originTree.remove(this, false);
806
+ this.originParent = void 0;
807
+ });
808
+ }
809
+ initData(initConf) {
810
+ if (initConf.originParent !== this.originParent) {
811
+ this.originParent = initConf.originParent;
812
+ this._registerCache = void 0;
813
+ }
814
+ if (initConf.parent) {
815
+ initConf.parent.addChild(this, initConf.index);
816
+ }
817
+ if (initConf.meta !== this.metaFromJSON) {
818
+ this._metaCache = void 0;
819
+ this.metaFromJSON = initConf.meta;
820
+ }
821
+ this._hidden = !!(this.getNodeMeta().hidden || initConf.hidden);
822
+ }
823
+ get isStart() {
824
+ return this.getNodeMeta().isStart;
825
+ }
826
+ get isFirst() {
827
+ return !this.pre;
828
+ }
829
+ get isLast() {
830
+ return !this.next;
831
+ }
832
+ /**
833
+ * 子节点采用水平布局
834
+ */
835
+ get isInlineBlocks() {
836
+ const originIsInlineBlocks = this.getNodeMeta().isInlineBlocks;
837
+ return typeof originIsInlineBlocks === "function" ? originIsInlineBlocks(this) : originIsInlineBlocks;
838
+ }
839
+ /**
840
+ * 水平节点
841
+ */
842
+ get isInlineBlock() {
843
+ const parent = this.document.renderTree.getParent(this);
844
+ return !!(parent && parent.isInlineBlocks);
845
+ }
846
+ /**
847
+ * 节点结束标记
848
+ * - 当前节点是结束节点
849
+ * - 当前节点最后一个节点包含结束标记
850
+ * - 当前节点为 inlineBlock,每一个 block 包含结束标记
851
+ *
852
+ * 由子元素确定,因此使用 memoLocal
853
+ */
854
+ get isNodeEnd() {
855
+ return this.memoLocal("isNodeEnd", () => {
856
+ if (this.getNodeMeta().isNodeEnd) {
857
+ return true;
858
+ }
859
+ if (this.isInlineBlocks && this.collapsedChildren.length) {
860
+ return this.collapsedChildren.every((child) => child.isNodeEnd);
861
+ }
862
+ if (this.lastCollapsedChild) {
863
+ return this.lastCollapsedChild.isNodeEnd;
864
+ }
865
+ return false;
866
+ });
867
+ }
868
+ /**
869
+ * 添加 子节点
870
+ *
871
+ * @param child 插入节点
872
+ */
873
+ addChild(child, index) {
874
+ if (child.parent === this) return;
875
+ this.document.originTree.addChild(this, child, index);
876
+ }
877
+ get hasChild() {
878
+ return this.children.length > 0;
879
+ }
880
+ get pre() {
881
+ return this.document.renderTree.getPre(this);
882
+ }
883
+ get next() {
884
+ return this.document.renderTree.getNext(this);
885
+ }
886
+ get parent() {
887
+ return this.document.renderTree.getParent(this);
888
+ }
889
+ getNodeRegistry() {
890
+ if (this._registerCache) return this._registerCache;
891
+ this._registerCache = this.document.getNodeRegistry(this.flowNodeType, this.originParent);
892
+ return this._registerCache;
893
+ }
894
+ /**
895
+ * @deprecated
896
+ * use getNodeRegistry instead
897
+ */
898
+ getNodeRegister() {
899
+ return this.getNodeRegistry();
900
+ }
901
+ getNodeMeta() {
902
+ if (this._metaCache) return this._metaCache;
903
+ if (this.metaFromJSON) {
904
+ this._metaCache = {
905
+ ...this.getNodeRegistry().meta,
906
+ ...this.metaFromJSON
907
+ };
908
+ } else {
909
+ this._metaCache = this.getNodeRegistry().meta;
910
+ }
911
+ return this._metaCache;
912
+ }
913
+ /**
914
+ * 获取所有子节点,包含 child 及其所有兄弟节点
915
+ */
916
+ get allChildren() {
917
+ const children = [];
918
+ for (const child of this.children) {
919
+ children.push(child);
920
+ children.push(...child.allChildren);
921
+ }
922
+ return children;
923
+ }
924
+ /**
925
+ * 获取所有收起的子节点,包含 child 及其所有兄弟节点
926
+ */
927
+ get allCollapsedChildren() {
928
+ const children = [];
929
+ for (const child of this.collapsedChildren) {
930
+ children.push(child);
931
+ children.push(...child.allCollapsedChildren);
932
+ }
933
+ return children;
934
+ }
935
+ /**
936
+ *
937
+ * Get child blocks
938
+ *
939
+ * use `blocks` instead
940
+ * @deprecated
941
+ */
942
+ get collapsedChildren() {
943
+ return this.document.renderTree.getCollapsedChildren(this);
944
+ }
945
+ /**
946
+ * Get child blocks
947
+ */
948
+ get blocks() {
949
+ return this.collapsedChildren;
950
+ }
951
+ /**
952
+ * Get last block
953
+ */
954
+ get lastBlock() {
955
+ return this.lastCollapsedChild;
956
+ }
957
+ /**
958
+ * use `lastBlock` instead
959
+ */
960
+ get lastCollapsedChild() {
961
+ const { collapsedChildren } = this;
962
+ return collapsedChildren[collapsedChildren.length - 1];
963
+ }
964
+ /**
965
+ * 获取子节点,如果子节点收起来,则会返回 空数组
966
+ */
967
+ get children() {
968
+ return this.document.renderTree.getChildren(this);
969
+ }
970
+ get lastChild() {
971
+ const { children } = this;
972
+ return children[children.length - 1];
973
+ }
974
+ get firstChild() {
975
+ return this.children[0];
976
+ }
977
+ memoLocal(key, fn) {
978
+ if (this._memoLocalCache.has(key)) {
979
+ return this._memoLocalCache.get(key);
980
+ }
981
+ const data = fn();
982
+ this._memoLocalCache.set(key, data);
983
+ return data;
984
+ }
985
+ memoGlobal(key, fn) {
986
+ if (this._memoGlobalCache.has(key)) {
987
+ return this._memoGlobalCache.get(key);
988
+ }
989
+ const data = fn();
990
+ this._memoGlobalCache.set(key, data);
991
+ return data;
992
+ }
993
+ clearMemoGlobal() {
994
+ this._memoGlobalCache.clear();
995
+ }
996
+ clearMemoLocal() {
997
+ this._memoLocalCache.clear();
998
+ }
999
+ get childrenLength() {
1000
+ return this.children.length;
1001
+ }
1002
+ get collapsed() {
1003
+ if (this.document.renderTree.isCollapsed(this)) return true;
1004
+ return !!this.parent?.collapsed;
1005
+ }
1006
+ set collapsed(collapsed) {
1007
+ this.document.renderTree.setCollapsed(this, collapsed);
1008
+ this.clearMemoGlobal();
1009
+ this.clearMemoLocal();
1010
+ }
1011
+ get hidden() {
1012
+ return this._hidden;
1013
+ }
1014
+ // 展开该节点
1015
+ openInsideCollapsed() {
1016
+ this.document.renderTree.openNodeInsideCollapsed(this);
1017
+ }
1018
+ /**
1019
+ * 可以重载
1020
+ */
1021
+ getJSONData() {
1022
+ return this.getExtInfo();
1023
+ }
1024
+ /**
1025
+ * 生成 JSON
1026
+ * @param newId
1027
+ */
1028
+ toJSON() {
1029
+ return this.document.toNodeJSON(this);
1030
+ }
1031
+ get isVertical() {
1032
+ return this.document.layout.name === "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
1033
+ }
1034
+ /**
1035
+ * 修改节点扩展信息
1036
+ * @param info
1037
+ */
1038
+ updateExtInfo(extInfo, fullUpdate) {
1039
+ this.getData(FlowNodeRenderData).updateExtInfo(extInfo, fullUpdate);
1040
+ }
1041
+ /**
1042
+ * 获取节点扩展信息
1043
+ */
1044
+ getExtInfo() {
1045
+ return this.getData(FlowNodeRenderData).getExtInfo();
1046
+ }
1047
+ get onExtInfoChange() {
1048
+ return this.renderData.onExtInfoChange;
1049
+ }
1050
+ /**
1051
+ * 获取渲染数据
1052
+ */
1053
+ get renderData() {
1054
+ return this.getData(FlowNodeRenderData);
1055
+ }
1056
+ /**
1057
+ * 获取位置大小数据
1058
+ */
1059
+ get transform() {
1060
+ return this.getData(FlowNodeTransformData);
1061
+ }
1062
+ /**
1063
+ * 获取节点的位置及大小矩形
1064
+ */
1065
+ get bounds() {
1066
+ return this.transform.bounds;
1067
+ }
1068
+ /**
1069
+ * Check node extend type
1070
+ */
1071
+ isExtend(parentType) {
1072
+ return this.document.isExtend(this.flowNodeType, parentType);
1073
+ }
1074
+ /**
1075
+ * Check node type
1076
+ * @param parentType
1077
+ */
1078
+ isTypeOrExtendType(parentType) {
1079
+ return this.document.isTypeOrExtendType(this.flowNodeType, parentType);
1080
+ }
1081
+ };
1082
+ FlowNodeEntity.type = "FlowNodeEntity";
1083
+ ((FlowNodeEntity2) => {
1084
+ function is(obj) {
1085
+ return obj instanceof FlowNodeEntity2;
1086
+ }
1087
+ FlowNodeEntity2.is = is;
1088
+ })(FlowNodeEntity || (FlowNodeEntity = {}));
1089
+ var FlowDocumentTransformerEntity = class extends ConfigEntity {
1090
+ constructor(conf) {
1091
+ super(conf);
1092
+ this.onRefreshEmitter = new Emitter();
1093
+ this.lastTransformVersion = -1;
1094
+ this.lastTreeVersion = -1;
1095
+ this.onRefresh = this.onRefreshEmitter.event;
1096
+ this.document = conf.document;
1097
+ this.toDispose.push(
1098
+ this.document.originTree.onTreeChange(() => {
1099
+ this.config.treeVersion += 1;
1100
+ this.fireChange();
1101
+ })
1102
+ );
1103
+ this.toDispose.push(this.onRefreshEmitter);
1104
+ }
1105
+ getDefaultConfig() {
1106
+ return {
1107
+ loading: true,
1108
+ treeVersion: 0
1109
+ };
1110
+ }
1111
+ get loading() {
1112
+ return this.config.loading;
1113
+ }
1114
+ set loading(loading) {
1115
+ if (this.config.loading !== loading) {
1116
+ this.config.loading = loading;
1117
+ this.fireChange();
1118
+ }
1119
+ }
1120
+ /**
1121
+ * 更新矩阵结构 (这个只有在树结构变化时候才会触发,如:添加节点、删除节点、改变位置节点)
1122
+ */
1123
+ updateTransformsTree() {
1124
+ this.document.renderTree.traverse((node, depth, index) => {
1125
+ const transform = node.getData(FlowNodeTransformData);
1126
+ if (transform.collapsed) {
1127
+ transform.transform.clearChildren();
1128
+ }
1129
+ if (node.parent) {
1130
+ transform.setParentTransform(node.parent.getData(FlowNodeTransformData));
1131
+ }
1132
+ node.index = index;
1133
+ });
1134
+ }
1135
+ clear() {
1136
+ this.lastTreeVersion = -1;
1137
+ this.lastTransformVersion = -1;
1138
+ }
1139
+ isTreeDirty() {
1140
+ const transformVersion = this.entityManager.getEntityDataVersion(FlowNodeTransformData);
1141
+ const isTreeVersionChanged = this.lastTreeVersion !== this.config.treeVersion;
1142
+ const isTransformVersionChanged = this.lastTransformVersion !== transformVersion;
1143
+ return isTreeVersionChanged || isTransformVersionChanged;
1144
+ }
1145
+ /**
1146
+ * 刷新节点的相对偏移
1147
+ */
1148
+ refresh() {
1149
+ const transformVersion = this.entityManager.getEntityDataVersion(FlowNodeTransformData);
1150
+ const isTreeVersionChanged = this.lastTreeVersion !== this.config.treeVersion;
1151
+ const isTransformVersionChanged = this.lastTransformVersion !== transformVersion;
1152
+ this.entityManager.changeEntityLocked = true;
1153
+ if (isTreeVersionChanged) {
1154
+ this.document.renderTree.updateRenderStruct();
1155
+ this.updateTransformsTree();
1156
+ this.lastTreeVersion = this.config.treeVersion;
1157
+ }
1158
+ if (isTreeVersionChanged || isTransformVersionChanged) {
1159
+ this.document.layout.update();
1160
+ this.lastTransformVersion = this.entityManager.getEntityDataVersion(FlowNodeTransformData);
1161
+ this.lastTreeVersion = this.config.treeVersion;
1162
+ this.onRefreshEmitter.fire();
1163
+ }
1164
+ this.entityManager.changeEntityLocked = false;
1165
+ }
1166
+ };
1167
+ FlowDocumentTransformerEntity.type = "FlowDocumentTransformerEntity";
1168
+ var FlowRendererStateEntity = class extends ConfigEntity {
1169
+ getDefaultConfig() {
1170
+ return {};
1171
+ }
1172
+ constructor(conf) {
1173
+ super(conf);
1174
+ }
1175
+ getNodeHovered() {
1176
+ return this.config.nodeHoveredId ? this.entityManager.getEntityById(this.config.nodeHoveredId) : void 0;
1177
+ }
1178
+ setNodeHovered(node) {
1179
+ this.updateConfig({
1180
+ nodeHoveredId: node?.id
1181
+ });
1182
+ }
1183
+ get dragging() {
1184
+ return this.config.dragging;
1185
+ }
1186
+ setDragging(dragging) {
1187
+ this.updateConfig({
1188
+ dragging
1189
+ });
1190
+ }
1191
+ get isBranch() {
1192
+ return this.config.isBranch;
1193
+ }
1194
+ setIsBranch(isBranch) {
1195
+ this.updateConfig({
1196
+ isBranch
1197
+ });
1198
+ }
1199
+ getDragLabelSide() {
1200
+ return this.config.dragLabelSide;
1201
+ }
1202
+ setDragLabelSide(dragLabelSide) {
1203
+ this.updateConfig({
1204
+ dragLabelSide
1205
+ });
1206
+ }
1207
+ getNodeDroppingId() {
1208
+ return this.config.nodeDroppingId;
1209
+ }
1210
+ setNodeDroppingId(nodeDroppingId) {
1211
+ this.updateConfig({
1212
+ nodeDroppingId
1213
+ });
1214
+ }
1215
+ getDragStartEntity() {
1216
+ const { nodeDragStartId } = this.config;
1217
+ return this.entityManager.getEntityById(nodeDragStartId);
1218
+ }
1219
+ setDragStartEntity(node) {
1220
+ this.updateConfig({
1221
+ nodeDragStartId: node?.id
1222
+ });
1223
+ }
1224
+ // 拖拽多个节点时
1225
+ getDragEntities() {
1226
+ const { nodeDragIds } = this.config;
1227
+ return (nodeDragIds || []).map((_id) => this.entityManager.getEntityById(_id));
1228
+ }
1229
+ // 设置拖拽的节点
1230
+ setDragEntities(nodes) {
1231
+ this.updateConfig({
1232
+ nodeDragIds: nodes.map((_node) => _node.id),
1233
+ nodeDragIdsWithChildren: nodes.map((_node) => [_node.id, ..._node.allCollapsedChildren.map((_n) => _n.id)]).flat()
1234
+ });
1235
+ }
1236
+ onNodeHoveredChange(fn, debounceTime = 100) {
1237
+ return this.onConfigChanged(debounce(() => fn(this.getNodeHovered()), debounceTime));
1238
+ }
1239
+ };
1240
+ FlowRendererStateEntity.type = "FlowRendererStateEntity";
1241
+ var FlowVirtualTree = class _FlowVirtualTree {
1242
+ constructor(root) {
1243
+ this.root = root;
1244
+ this.onTreeChangeEmitter = new Emitter();
1245
+ /**
1246
+ * tree 结构变化时候触发
1247
+ */
1248
+ this.onTreeChange = this.onTreeChangeEmitter.event;
1249
+ this.map = /* @__PURE__ */ new Map();
1250
+ }
1251
+ dispose() {
1252
+ this.map.clear();
1253
+ this.onTreeChangeEmitter.dispose();
1254
+ }
1255
+ getInfo(node) {
1256
+ let res = this.map.get(node);
1257
+ if (!res) {
1258
+ res = { children: [] };
1259
+ this.map.set(node, res);
1260
+ }
1261
+ return res;
1262
+ }
1263
+ clear() {
1264
+ this.map.clear();
1265
+ }
1266
+ cloneMap() {
1267
+ const newMap = /* @__PURE__ */ new Map();
1268
+ for (const [key, value] of this.map) {
1269
+ newMap.set(key, {
1270
+ ...value,
1271
+ children: value.children.slice()
1272
+ });
1273
+ }
1274
+ return newMap;
1275
+ }
1276
+ clone() {
1277
+ const newTree = new _FlowVirtualTree(this.root);
1278
+ newTree.map = this.cloneMap();
1279
+ return newTree;
1280
+ }
1281
+ remove(node, withChildren = true) {
1282
+ this.removeParent(node);
1283
+ if (withChildren) {
1284
+ this._removeChildren(node);
1285
+ }
1286
+ this.map.delete(node);
1287
+ this.fireTreeChange();
1288
+ }
1289
+ addChild(parent, child, index) {
1290
+ const parentInfo = this.getInfo(parent);
1291
+ const childInfo = this.getInfo(child);
1292
+ if (childInfo.parent) {
1293
+ if (childInfo.parent === parent) return child;
1294
+ if (childInfo.parent !== parent) {
1295
+ this.removeParent(child);
1296
+ }
1297
+ }
1298
+ const len = parentInfo.children.length;
1299
+ const idx = typeof index === "undefined" ? len - 1 : index - 1;
1300
+ const lastChild = parentInfo.children[idx];
1301
+ const nextChild = parentInfo.children[idx + 1];
1302
+ if (lastChild) this.getInfo(lastChild).next = child;
1303
+ if (nextChild) this.getInfo(nextChild).pre = child;
1304
+ childInfo.pre = lastChild;
1305
+ childInfo.next = nextChild;
1306
+ parentInfo.children.splice(idx + 1, 0, child);
1307
+ childInfo.parent = parent;
1308
+ this.fireTreeChange();
1309
+ return child;
1310
+ }
1311
+ moveChilds(parent, childs, index) {
1312
+ const parentInfo = this.getInfo(parent);
1313
+ const len = parentInfo.children.length;
1314
+ let childIndex = index ?? len;
1315
+ childs.forEach((child) => {
1316
+ const childInfo = this.getInfo(child);
1317
+ if (childInfo.parent) {
1318
+ this.removeParent(child);
1319
+ }
1320
+ });
1321
+ childs.forEach((child) => {
1322
+ const childInfo = this.getInfo(child);
1323
+ let lastChild = parentInfo.children[childIndex - 1];
1324
+ let nextChild = parentInfo.children[childIndex];
1325
+ if (lastChild) this.getInfo(lastChild).next = child;
1326
+ if (nextChild) this.getInfo(nextChild).pre = child;
1327
+ childInfo.pre = lastChild;
1328
+ childInfo.next = nextChild;
1329
+ parentInfo.children.splice(childIndex, 0, child);
1330
+ childInfo.parent = parent;
1331
+ childIndex++;
1332
+ });
1333
+ this.fireTreeChange();
1334
+ return childs;
1335
+ }
1336
+ getById(id) {
1337
+ for (const node of this.map.keys()) {
1338
+ if (node.id === id) return node;
1339
+ }
1340
+ }
1341
+ /**
1342
+ * 插入节点到后边
1343
+ * @param before
1344
+ * @param after
1345
+ */
1346
+ insertAfter(before, after) {
1347
+ const beforeInfo = this.getInfo(before);
1348
+ const afterInfo = this.getInfo(after);
1349
+ this.removeParent(after);
1350
+ if (beforeInfo.parent) {
1351
+ const parentInfo = this.getInfo(beforeInfo.parent);
1352
+ parentInfo.children.splice(parentInfo.children.indexOf(before) + 1, 0, after);
1353
+ const { next } = beforeInfo;
1354
+ if (next) {
1355
+ this.getInfo(next).pre = after;
1356
+ }
1357
+ afterInfo.next = next;
1358
+ beforeInfo.next = after;
1359
+ afterInfo.pre = before;
1360
+ afterInfo.parent = beforeInfo.parent;
1361
+ }
1362
+ this.fireTreeChange();
1363
+ }
1364
+ removeParent(node) {
1365
+ const info = this.getInfo(node);
1366
+ if (!info.parent) return;
1367
+ const parentInfo = this.getInfo(info.parent);
1368
+ const index = parentInfo.children.indexOf(node);
1369
+ parentInfo.children.splice(index, 1);
1370
+ const { pre, next } = info;
1371
+ if (pre) this.getInfo(pre).next = next;
1372
+ if (next) this.getInfo(next).pre = pre;
1373
+ this.fireTreeChange();
1374
+ }
1375
+ _removeChildren(node) {
1376
+ const children = this.getChildren(node);
1377
+ if (children.length > 0) {
1378
+ children.forEach((child) => {
1379
+ this._removeChildren(child);
1380
+ this.map.delete(child);
1381
+ });
1382
+ }
1383
+ }
1384
+ getParent(node) {
1385
+ return this.getInfo(node).parent;
1386
+ }
1387
+ getPre(node) {
1388
+ return this.getInfo(node).pre;
1389
+ }
1390
+ getNext(node) {
1391
+ return this.getInfo(node).next;
1392
+ }
1393
+ getChildren(node) {
1394
+ return this.getInfo(node).children;
1395
+ }
1396
+ traverse(fn, node = this.root, depth = 0, index = 0) {
1397
+ const breaked = fn(node, depth, index);
1398
+ if (breaked) return true;
1399
+ const info = this.getInfo(node);
1400
+ const shouldBreak = info.children.find((child, i) => this.traverse(fn, child, depth + 1, i));
1401
+ if (shouldBreak) return true;
1402
+ }
1403
+ /**
1404
+ * 通知文档树结构更新
1405
+ */
1406
+ fireTreeChange() {
1407
+ this.onTreeChangeEmitter.fire();
1408
+ }
1409
+ get size() {
1410
+ return this.map.size;
1411
+ }
1412
+ toString(showType) {
1413
+ const ret = [];
1414
+ this.traverse((node, depth) => {
1415
+ if (depth === 0) {
1416
+ ret.push(node.id);
1417
+ } else {
1418
+ ret.push(
1419
+ `|${new Array(depth).fill("--").join("")} ${showType ? `${node.flowNodeType}(${node.id})` : node.id}`
1420
+ );
1421
+ }
1422
+ });
1423
+ return `${ret.join("\n")}`;
1424
+ }
1425
+ };
1426
+
1427
+ // src/flow-render-tree.ts
1428
+ var FlowRenderTree = class extends FlowVirtualTree {
1429
+ constructor(root, originTree, document) {
1430
+ super(root);
1431
+ this.root = root;
1432
+ /**
1433
+ * 折叠的节点
1434
+ * @protected
1435
+ */
1436
+ this.nodesCollapsed = /* @__PURE__ */ new Set();
1437
+ this.originTree = originTree;
1438
+ this.onTreeChange = this.originTree.onTreeChange;
1439
+ this.document = document;
1440
+ }
1441
+ isCollapsed(node) {
1442
+ return this.nodesCollapsed.has(node);
1443
+ }
1444
+ get collapsedNodeList() {
1445
+ return Array.from(this.nodesCollapsed);
1446
+ }
1447
+ /**
1448
+ * 折叠元素
1449
+ * @param node
1450
+ * @param collapsed
1451
+ */
1452
+ setCollapsed(node, collapsed) {
1453
+ if (collapsed) {
1454
+ this.nodesCollapsed.add(node);
1455
+ } else {
1456
+ this.nodesCollapsed.delete(node);
1457
+ }
1458
+ this.originTree.fireTreeChange();
1459
+ }
1460
+ /**
1461
+ *
1462
+ */
1463
+ openNodeInsideCollapsed(node) {
1464
+ let curr = this.originTree.getInfo(node)?.parent;
1465
+ while (curr) {
1466
+ if (this.nodesCollapsed.has(curr)) {
1467
+ this.nodesCollapsed.delete(curr);
1468
+ }
1469
+ const { parent } = this.originTree.getInfo(curr) || {};
1470
+ curr = parent;
1471
+ }
1472
+ this.originTree.fireTreeChange();
1473
+ }
1474
+ /**
1475
+ * 更新结束节点等位置信息,分支里如果全是结束节点则要做相应的偏移
1476
+ */
1477
+ updateRenderStruct() {
1478
+ this.map = this.originTree.cloneMap();
1479
+ if (this.document.config.get("END_NODES_REFINE_BRANCH" /* END_NODES_REFINE_BRANCH */)) {
1480
+ this.refineBranch(this.root);
1481
+ }
1482
+ this.hideCollapsed();
1483
+ }
1484
+ /**
1485
+ * 隐藏收起节点
1486
+ */
1487
+ hideCollapsed() {
1488
+ this.nodesCollapsed.forEach((collapsedNode) => {
1489
+ const collapsedNodeInfo = this.getInfo(collapsedNode);
1490
+ if (!collapsedNodeInfo) {
1491
+ this.nodesCollapsed.delete(collapsedNode);
1492
+ return;
1493
+ }
1494
+ const iconChild = collapsedNodeInfo.children.find(
1495
+ (_child) => _child.flowNodeType === "blockIcon" /* BLOCK_ICON */ || _child.flowNodeType === "blockOrderIcon" /* BLOCK_ORDER_ICON */
1496
+ );
1497
+ if (iconChild) {
1498
+ const iconInfo = this.getInfo(iconChild);
1499
+ iconInfo.next = void 0;
1500
+ iconInfo.pre = void 0;
1501
+ collapsedNodeInfo.children = [iconChild];
1502
+ return;
1503
+ }
1504
+ collapsedNodeInfo.children = [];
1505
+ });
1506
+ }
1507
+ // 节点是否为结束节点
1508
+ isNodeEnd(node) {
1509
+ if (node.getNodeMeta().isNodeEnd) {
1510
+ return true;
1511
+ }
1512
+ const { children } = this.getInfo(node);
1513
+ if (children.length > 0 && node.isInlineBlocks) {
1514
+ return children.every((child) => this.isNodeEnd(child));
1515
+ }
1516
+ if (node.isInlineBlock) {
1517
+ return this.isNodeEnd(children[children.length - 1]);
1518
+ }
1519
+ return false;
1520
+ }
1521
+ /**
1522
+ * 优化精简分支线
1523
+ * - 结束节点拉直分支线
1524
+ */
1525
+ refineBranch(block) {
1526
+ let curr = this.getInfo(block).children[0];
1527
+ while (curr) {
1528
+ if (curr.flowNodeType === "dynamicSplit" /* DYNAMIC_SPLIT */ || curr.flowNodeType === "staticSplit" /* STATIC_SPLIT */) {
1529
+ const { next, children: branchChildren } = this.getInfo(curr);
1530
+ const { children } = this.getInfo(branchChildren[1]);
1531
+ const passBlocks = (children || []).filter((child) => !this.isNodeEnd(child));
1532
+ const shouldDragAllNextNodes = passBlocks.length === 1;
1533
+ if (shouldDragAllNextNodes && next) {
1534
+ this.dragNextNodesToBlock(passBlocks[0], next);
1535
+ }
1536
+ children?.forEach((child) => {
1537
+ this.refineBranch(child);
1538
+ });
1539
+ if (shouldDragAllNextNodes) {
1540
+ break;
1541
+ }
1542
+ }
1543
+ curr = curr.next;
1544
+ }
1545
+ }
1546
+ // 结束节点拽分支,将后续节点拽到对应分支内
1547
+ dragNextNodesToBlock(toBlock, next) {
1548
+ const toBlockInfo = this.getInfo(toBlock);
1549
+ const nextInfo = this.getInfo(next);
1550
+ const toBlockLastChild = toBlockInfo.children[toBlock.children.length - 1];
1551
+ if (nextInfo.parent) {
1552
+ const nextParentInfo = this.getInfo(nextInfo.parent);
1553
+ if (nextInfo.pre) {
1554
+ this.getInfo(nextInfo.pre).next = void 0;
1555
+ }
1556
+ if (toBlockLastChild) {
1557
+ const lastChildInfo = this.getInfo(toBlockLastChild);
1558
+ lastChildInfo.next = next;
1559
+ nextInfo.pre = toBlockLastChild;
1560
+ }
1561
+ const nextNodeIndex = nextParentInfo.children.indexOf(next);
1562
+ const allNextNodes = nextParentInfo.children.slice(nextNodeIndex);
1563
+ nextParentInfo.children = nextParentInfo.children.slice(0, nextNodeIndex);
1564
+ for (const node of allNextNodes) {
1565
+ const nodeInfo = this.getInfo(node);
1566
+ toBlockInfo.children.push(node);
1567
+ nodeInfo.parent = toBlock;
1568
+ }
1569
+ }
1570
+ }
1571
+ getInfo(node) {
1572
+ const info = this.map.get(node) || this.originTree.getInfo(node);
1573
+ return info;
1574
+ }
1575
+ // 或者originTree节点的信息
1576
+ getOriginInfo(node) {
1577
+ return this.originTree.getInfo(node);
1578
+ }
1579
+ // 获取收起的隐藏节点
1580
+ getCollapsedChildren(node) {
1581
+ return this.getOriginInfo(node).children || [];
1582
+ }
1583
+ remove() {
1584
+ throw new Error("Render Tree cannot use remove node");
1585
+ }
1586
+ addChild() {
1587
+ throw new Error("Render tree cannot use add child");
1588
+ }
1589
+ insertAfter() {
1590
+ throw new Error("Render tree cannot use insert after");
1591
+ }
1592
+ removeParent() {
1593
+ throw new Error("Render tree cannot use remove parent");
1594
+ }
1595
+ };
1596
+
1597
+ // src/flow-document-options.ts
1598
+ var FlowDocumentOptions = /* @__PURE__ */ Symbol("FlowDocumentOptions");
1599
+ var FlowDocumentOptionsDefault = {
1600
+ allNodesDefaultExpanded: false
1601
+ };
1602
+ var ConstantKeys = {
1603
+ ...DefaultSpacingKey,
1604
+ /**
1605
+ * loop 底部留白
1606
+ */
1607
+ INLINE_SPACING_BOTTOM: "INLINE_SPACING_BOTTOM",
1608
+ /**
1609
+ * inlineBlocks 的 inlineTop
1610
+ * loop 循环线条上边距
1611
+ */
1612
+ INLINE_BLOCKS_INLINE_SPACING_TOP: "INLINE_BLOCKS_INLINE_SPACING_TOP",
1613
+ /**
1614
+ * inlineBlocks 的 inlineBottom
1615
+ * loop 循环线条的下边距
1616
+ *
1617
+ */
1618
+ INLINE_BLOCKS_INLINE_SPACING_BOTTOM: "INLINE_BLOCKS_INLINE_SPACING_BOTTOM",
1619
+ /***
1620
+ * 线条、label 默认颜色
1621
+ */
1622
+ BASE_COLOR: "BASE_COLOR",
1623
+ /***
1624
+ * 线条、label 激活后的颜色
1625
+ */
1626
+ BASE_ACTIVATED_COLOR: "BASE_ACTIVATED_COLOR",
1627
+ /**
1628
+ * Branch bottom margin
1629
+ * 分支下边距
1630
+ */
1631
+ INLINE_BLOCKS_PADDING_TOP: "INLINE_BLOCKS_PADDING_TOP"
1632
+ };
1633
+
1634
+ // src/flow-document-contribution.ts
1635
+ var FlowDocumentContribution = /* @__PURE__ */ Symbol("FlowDocumentContribution");
1636
+ var FlowDocumentConfigDefaultData = /* @__PURE__ */ Symbol("FlowDocumentConfigDefaultData");
1637
+ var FlowDocumentConfig = class {
1638
+ constructor(_data = {}) {
1639
+ this._data = _data;
1640
+ this.onDataChangeEmitter = new Emitter();
1641
+ this.onChange = this.onDataChangeEmitter.event;
1642
+ }
1643
+ get(key) {
1644
+ return this._data[key];
1645
+ }
1646
+ set(key, value) {
1647
+ if (this.get(key) !== value) {
1648
+ this._data[key] = value;
1649
+ this.onDataChangeEmitter.fire(key);
1650
+ }
1651
+ }
1652
+ registerConfigs(config) {
1653
+ Object.keys(config).forEach((key) => {
1654
+ this.set(key, config[key]);
1655
+ });
1656
+ }
1657
+ };
1658
+ FlowDocumentConfig = __decorateClass([
1659
+ injectable(),
1660
+ __decorateParam(0, inject(FlowDocumentConfigDefaultData)),
1661
+ __decorateParam(0, optional())
1662
+ ], FlowDocumentConfig);
1663
+
1664
+ // src/flow-document.ts
1665
+ var FlowDocumentProvider = /* @__PURE__ */ Symbol("FlowDocumentProvider");
1666
+ var FlowDocument = class {
1667
+ constructor() {
1668
+ this.contributions = [];
1669
+ this.registers = /* @__PURE__ */ new Map();
1670
+ this.nodeRegistryCache = /* @__PURE__ */ new Map();
1671
+ this.nodeDataRegistries = [];
1672
+ this.layouts = [];
1673
+ this.currentLayoutKey = "";
1674
+ this.onNodeUpdateEmitter = new Emitter();
1675
+ this.onNodeCreateEmitter = new Emitter();
1676
+ this.onNodeDisposeEmitter = new Emitter();
1677
+ this.onLayoutChangeEmitter = new Emitter();
1678
+ this.onNodeUpdate = this.onNodeUpdateEmitter.event;
1679
+ this.onNodeCreate = this.onNodeCreateEmitter.event;
1680
+ this.onNodeDispose = this.onNodeDisposeEmitter.event;
1681
+ this.onLayoutChange = this.onLayoutChangeEmitter.event;
1682
+ this._disposed = false;
1683
+ }
1684
+ /**
1685
+ *
1686
+ */
1687
+ get disposed() {
1688
+ return this._disposed;
1689
+ }
1690
+ init() {
1691
+ if (!this.options) this.options = FlowDocumentOptionsDefault;
1692
+ this.currentLayoutKey = this.options.defaultLayout || "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
1693
+ this.contributions.forEach((contrib) => contrib.registerDocument?.(this));
1694
+ this.root = this.addNode({ id: "root", type: "root" /* ROOT */ });
1695
+ this.originTree = new FlowVirtualTree(this.root);
1696
+ this.transformer = this.entityManager.createEntity(
1697
+ FlowDocumentTransformerEntity,
1698
+ { document: this }
1699
+ );
1700
+ this.renderState = this.entityManager.createEntity(FlowRendererStateEntity);
1701
+ this.renderTree = new FlowRenderTree(this.root, this.originTree, this);
1702
+ this.layout.reload?.();
1703
+ }
1704
+ /**
1705
+ * 从数据初始化 O(n)
1706
+ * @param json
1707
+ */
1708
+ /**
1709
+ * 加载数据,可以被重载
1710
+ * @param json 文档数据更新
1711
+ * @param fireRender 是否要触发渲染,默认 true
1712
+ */
1713
+ fromJSON(json, fireRender = true) {
1714
+ if (this._disposed) return;
1715
+ this.originTree.clear();
1716
+ this.renderTree.clear();
1717
+ this.entityManager.changeEntityLocked = true;
1718
+ const oldNodes = this.entityManager.getEntities(FlowNodeEntity);
1719
+ const newNodes = [this.root];
1720
+ this.addBlocksAsChildren(this.root, json.nodes || [], newNodes);
1721
+ oldNodes.forEach((node) => {
1722
+ if (!newNodes.includes(node)) {
1723
+ node.dispose();
1724
+ }
1725
+ });
1726
+ this.entityManager.changeEntityLocked = false;
1727
+ this.transformer.loading = false;
1728
+ if (fireRender) this.fireRender();
1729
+ }
1730
+ get layout() {
1731
+ const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
1732
+ if (!layout) {
1733
+ throw new Error(`Unknown flow layout: ${this.currentLayoutKey}`);
1734
+ }
1735
+ return layout;
1736
+ }
1737
+ async load() {
1738
+ await Promise.all(this.contributions.map((c) => c.loadDocument?.(this)));
1739
+ }
1740
+ get loading() {
1741
+ return this.transformer.loading;
1742
+ }
1743
+ /**
1744
+ * 触发 render
1745
+ */
1746
+ fireRender() {
1747
+ if (this.transformer.isTreeDirty()) {
1748
+ this.entityManager.fireEntityChanged(FlowNodeEntity.type);
1749
+ this.entityManager.fireEntityChanged(FlowDocumentTransformerEntity.type);
1750
+ }
1751
+ }
1752
+ /**
1753
+ * 从指定节点的下一个节点新增
1754
+ * @param fromNode
1755
+ * @param json
1756
+ */
1757
+ addFromNode(fromNode, json) {
1758
+ const node = typeof fromNode === "string" ? this.getNode(fromNode) : fromNode;
1759
+ this.entityManager.changeEntityLocked = true;
1760
+ const { parent } = node;
1761
+ const result = this.addNode({
1762
+ ...json,
1763
+ parent
1764
+ // originParent,
1765
+ });
1766
+ this.originTree.insertAfter(node, result);
1767
+ this.entityManager.changeEntityLocked = false;
1768
+ this.entityManager.fireEntityChanged(FlowNodeEntity.type);
1769
+ return result;
1770
+ }
1771
+ removeNode(node) {
1772
+ if (typeof node === "string") {
1773
+ this.getNode(node)?.dispose();
1774
+ } else {
1775
+ node.dispose();
1776
+ }
1777
+ }
1778
+ /**
1779
+ * 添加节点,如果节点已经存在则不会重复创建
1780
+ * @param data
1781
+ * @param addedNodes
1782
+ */
1783
+ addNode(data, addedNodes) {
1784
+ const { id, type = "block", originParent, parent, meta, hidden, index } = data;
1785
+ let node = this.getNode(id);
1786
+ let isNew = false;
1787
+ const register = this.getNodeRegistry(type, data.originParent);
1788
+ if (node && node.flowNodeType !== data.type) {
1789
+ node.dispose();
1790
+ node = void 0;
1791
+ }
1792
+ if (!node) {
1793
+ const { dataRegistries } = register;
1794
+ node = this.entityManager.createEntity(FlowNodeEntity, {
1795
+ id,
1796
+ document: this,
1797
+ flowNodeType: type,
1798
+ originParent,
1799
+ meta
1800
+ });
1801
+ this.options.preNodeCreate?.(node);
1802
+ const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
1803
+ node.addInitializeData(datas);
1804
+ node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
1805
+ this.options.fromNodeJSON?.(node, data, true);
1806
+ isNew = true;
1807
+ } else {
1808
+ this.options.fromNodeJSON?.(node, data, false);
1809
+ }
1810
+ node.initData({
1811
+ originParent,
1812
+ parent,
1813
+ meta,
1814
+ hidden,
1815
+ index
1816
+ });
1817
+ if (node.isStart) {
1818
+ this.root.addChild(node);
1819
+ }
1820
+ addedNodes?.push(node);
1821
+ if (register.onCreate) {
1822
+ const extendNodes = register.onCreate(node, data);
1823
+ if (extendNodes && addedNodes) {
1824
+ addedNodes.push(...extendNodes);
1825
+ }
1826
+ } else if (data.blocks && data.blocks.length > 0) {
1827
+ if (!data.blocks[0].type) {
1828
+ this.addInlineBlocks(node, data.blocks, addedNodes);
1829
+ } else {
1830
+ this.addBlocksAsChildren(node, data.blocks, addedNodes);
1831
+ }
1832
+ }
1833
+ if (isNew) {
1834
+ this.onNodeCreateEmitter.fire({
1835
+ node,
1836
+ data,
1837
+ json: data
1838
+ });
1839
+ } else {
1840
+ this.onNodeUpdateEmitter.fire({ node, data, json: data });
1841
+ }
1842
+ return node;
1843
+ }
1844
+ addBlocksAsChildren(parent, blocks, addedNodes) {
1845
+ for (const block of blocks) {
1846
+ this.addNode(
1847
+ {
1848
+ ...block,
1849
+ parent
1850
+ },
1851
+ addedNodes
1852
+ );
1853
+ }
1854
+ }
1855
+ /**
1856
+ * block 格式:
1857
+ * node: (最原始的 id)
1858
+ * blockIcon
1859
+ * inlineBlocks
1860
+ * block
1861
+ * blockOrderIcon
1862
+ * block
1863
+ * blockOrderIcon
1864
+ * @param node
1865
+ * @param blocks
1866
+ * @param addedNodes
1867
+ */
1868
+ addInlineBlocks(node, blocks, addedNodes = []) {
1869
+ const blockIconNode = this.addNode({
1870
+ id: `$blockIcon$${node.id}`,
1871
+ type: "blockIcon" /* BLOCK_ICON */,
1872
+ originParent: node,
1873
+ parent: node
1874
+ });
1875
+ addedNodes.push(blockIconNode);
1876
+ const inlineBlocksNode = this.addNode({
1877
+ id: `$inlineBlocks$${node.id}`,
1878
+ type: "inlineBlocks" /* INLINE_BLOCKS */,
1879
+ originParent: node,
1880
+ parent: node
1881
+ });
1882
+ addedNodes.push(inlineBlocksNode);
1883
+ blocks.forEach((blockData) => {
1884
+ this.addBlock(node, blockData, addedNodes);
1885
+ });
1886
+ return addedNodes;
1887
+ }
1888
+ /**
1889
+ * 添加单个 block
1890
+ * @param target
1891
+ * @param blockData
1892
+ * @param addedNodes
1893
+ * @param parent 默认去找 $inlineBlocks$
1894
+ */
1895
+ addBlock(target, blockData, addedNodes, parent, index) {
1896
+ const node = typeof target === "string" ? this.getNode(target) : target;
1897
+ const { onBlockChildCreate } = node.getNodeRegistry();
1898
+ if (onBlockChildCreate) {
1899
+ return onBlockChildCreate(node, blockData, addedNodes);
1900
+ }
1901
+ parent = parent || this.getNode(`$inlineBlocks$${node.id}`);
1902
+ const block = this.addNode({
1903
+ ...omit(blockData, "blocks"),
1904
+ type: blockData.type || "block" /* BLOCK */,
1905
+ originParent: node,
1906
+ parent,
1907
+ index
1908
+ });
1909
+ if (blockData.meta?.defaultCollapsed) {
1910
+ block.collapsed = true;
1911
+ }
1912
+ const blockOrderIcon = this.addNode({
1913
+ id: `$blockOrderIcon$${blockData.id}`,
1914
+ type: "blockOrderIcon" /* BLOCK_ORDER_ICON */,
1915
+ originParent: node,
1916
+ meta: blockData.meta,
1917
+ data: blockData.data,
1918
+ parent: block
1919
+ });
1920
+ addedNodes?.push(block, blockOrderIcon);
1921
+ if (blockData.blocks) {
1922
+ this.addBlocksAsChildren(block, blockData.blocks, addedNodes);
1923
+ }
1924
+ return block;
1925
+ }
1926
+ /**
1927
+ * 根据 id 获取节点
1928
+ * @param id
1929
+ */
1930
+ getNode(id) {
1931
+ if (!id) return void 0;
1932
+ return this.entityManager.getEntityById(id);
1933
+ }
1934
+ /**
1935
+ * 注册节点
1936
+ * @param registries
1937
+ */
1938
+ registerFlowNodes(...registries) {
1939
+ registries.forEach((newRegistry) => {
1940
+ if (!newRegistry) {
1941
+ throw new Error("[FlowDocument] registerFlowNodes parameters get undefined registry.");
1942
+ }
1943
+ const preRegistry = this.registers.get(newRegistry.type);
1944
+ this.registers.set(newRegistry.type, {
1945
+ ...preRegistry,
1946
+ ...newRegistry,
1947
+ meta: {
1948
+ ...preRegistry?.meta,
1949
+ ...newRegistry?.meta
1950
+ },
1951
+ extendChildRegistries: FlowNodeRegistry.mergeChildRegistries(
1952
+ preRegistry?.extendChildRegistries,
1953
+ newRegistry?.extendChildRegistries
1954
+ )
1955
+ });
1956
+ });
1957
+ }
1958
+ /**
1959
+ * Check node extend
1960
+ * @param currentType
1961
+ * @param extendType
1962
+ */
1963
+ isExtend(currentType, extendType) {
1964
+ return (this.getNodeRegistry(currentType).__extends__ || []).includes(extendType);
1965
+ }
1966
+ /**
1967
+ * Check node type
1968
+ * @param currentType
1969
+ * @param extendType
1970
+ */
1971
+ isTypeOrExtendType(currentType, extendType) {
1972
+ return currentType === extendType || this.isExtend(currentType, extendType);
1973
+ }
1974
+ /**
1975
+ * 导出数据,可以重载
1976
+ */
1977
+ toJSON() {
1978
+ if (this.disposed) {
1979
+ throw new Error(
1980
+ "The FlowDocument has been disposed and it is no longer possible to call toJSON."
1981
+ );
1982
+ }
1983
+ return {
1984
+ nodes: this.root.toJSON().blocks
1985
+ };
1986
+ }
1987
+ /**
1988
+ * @deprecated
1989
+ * use `getNodeRegistry` instead
1990
+ */
1991
+ getNodeRegister(type, originParent) {
1992
+ return this.getNodeRegistry(type, originParent);
1993
+ }
1994
+ getNodeRegistry(type, originParent) {
1995
+ const typeKey = `${type}_${originParent?.flowNodeType || ""}`;
1996
+ if (this.nodeRegistryCache.has(typeKey)) {
1997
+ return this.nodeRegistryCache.get(typeKey);
1998
+ }
1999
+ const customDefaultRegistry = this.options.getNodeDefaultRegistry?.(type);
2000
+ let register = this.registers.get(type) || { type };
2001
+ const extendRegisters = [];
2002
+ const extendKey = register.extend;
2003
+ if (register.extend && this.registers.has(register.extend)) {
2004
+ register = FlowNodeRegistry.merge(
2005
+ this.getNodeRegistry(register.extend),
2006
+ register,
2007
+ register.type
2008
+ );
2009
+ }
2010
+ if (originParent) {
2011
+ const extendRegister = this.getNodeRegistry(
2012
+ originParent.flowNodeType
2013
+ ).extendChildRegistries?.find((r) => r.type === type);
2014
+ if (extendRegister) {
2015
+ if (extendRegister.extend && this.registers.has(extendRegister.extend)) {
2016
+ extendRegisters.push(this.registers.get(extendRegister.extend));
2017
+ }
2018
+ extendRegisters.push(extendRegister);
2019
+ }
2020
+ }
2021
+ register = FlowNodeRegistry.extend(register, extendRegisters);
2022
+ const defaultNodeMeta = DEFAULT_FLOW_NODE_META(type, this);
2023
+ defaultNodeMeta.spacing = this.options?.constants?.[ConstantKeys.NODE_SPACING] || defaultNodeMeta.spacing;
2024
+ const res = {
2025
+ ...customDefaultRegistry,
2026
+ ...register,
2027
+ meta: {
2028
+ ...defaultNodeMeta,
2029
+ ...customDefaultRegistry?.meta,
2030
+ ...register.meta
2031
+ }
2032
+ };
2033
+ if (extendKey) {
2034
+ res.extend = extendKey;
2035
+ }
2036
+ this.nodeRegistryCache.set(typeKey, res);
2037
+ return res;
2038
+ }
2039
+ /**
2040
+ * 节点注入数据
2041
+ * @param nodeDatas
2042
+ */
2043
+ registerNodeDatas(...nodeDatas) {
2044
+ this.nodeDataRegistries.push(...nodeDatas);
2045
+ }
2046
+ /**
2047
+ * traverse all nodes, O(n)
2048
+ * R
2049
+ * |
2050
+ * +---1
2051
+ * | |
2052
+ * | +---1.1
2053
+ * | |
2054
+ * | +---1.2
2055
+ * | |
2056
+ * | +---1.3
2057
+ * | | |
2058
+ * | | +---1.3.1
2059
+ * | | |
2060
+ * | | +---1.3.2
2061
+ * | |
2062
+ * | +---1.4
2063
+ * |
2064
+ * +---2
2065
+ * |
2066
+ * +---2.1
2067
+ *
2068
+ * sort: [1, 1.1, 1.2, 1.3, 1.3.1, 1.3.2, 1.4, 2, 2.1]
2069
+ * @param fn
2070
+ * @param node
2071
+ * @param depth
2072
+ * @return isBreak
2073
+ */
2074
+ traverse(fn, node = this.root, depth = 0) {
2075
+ return this.originTree.traverse(fn, node, depth);
2076
+ }
2077
+ get size() {
2078
+ return this.getAllNodes().length;
2079
+ }
2080
+ hasNode(nodeId) {
2081
+ return !!this.entityManager.getEntityById(nodeId);
2082
+ }
2083
+ getAllNodes() {
2084
+ return this.entityManager.getEntities(FlowNodeEntity);
2085
+ }
2086
+ toString(showType) {
2087
+ return this.originTree.toString(showType);
2088
+ }
2089
+ /**
2090
+ * 返回需要渲染的数据
2091
+ */
2092
+ getRenderDatas(dataRegistry, containHiddenNodes = true) {
2093
+ const result = [];
2094
+ this.renderTree.traverse((node) => {
2095
+ if (!containHiddenNodes && node.hidden) return;
2096
+ result.push(node.getData(dataRegistry));
2097
+ });
2098
+ return result;
2099
+ }
2100
+ toNodeJSON(node) {
2101
+ if (this.options.toNodeJSON) {
2102
+ return this.options.toNodeJSON(node);
2103
+ }
2104
+ const nodesMap = {};
2105
+ let startNodeJSON;
2106
+ this.traverse((node2) => {
2107
+ const isSystemNode = node2.id.startsWith("$");
2108
+ if (isSystemNode) return;
2109
+ const nodeJSONData = node2.getJSONData();
2110
+ const nodeJSON = {
2111
+ id: node2.id,
2112
+ type: node2.flowNodeType
2113
+ };
2114
+ if (nodeJSONData !== void 0) {
2115
+ nodeJSON.data = nodeJSONData;
2116
+ }
2117
+ if (!startNodeJSON) startNodeJSON = nodeJSON;
2118
+ let { parent } = node2;
2119
+ if (parent && parent.id.startsWith("$")) {
2120
+ parent = parent.originParent;
2121
+ }
2122
+ const parentJSON = parent ? nodesMap[parent.id] : void 0;
2123
+ if (parentJSON) {
2124
+ if (!parentJSON.blocks) {
2125
+ parentJSON.blocks = [];
2126
+ }
2127
+ parentJSON.blocks.push(nodeJSON);
2128
+ }
2129
+ nodesMap[node2.id] = nodeJSON;
2130
+ }, node);
2131
+ return startNodeJSON;
2132
+ }
2133
+ /**
2134
+ * 移动节点
2135
+ * @param param0
2136
+ * @returns
2137
+ */
2138
+ moveNodes({
2139
+ dropNodeId,
2140
+ sortNodeIds,
2141
+ inside = false
2142
+ }) {
2143
+ const dropEntity = this.getNode(dropNodeId);
2144
+ if (!dropEntity) {
2145
+ return;
2146
+ }
2147
+ const sortNodes = sortNodeIds.map((id) => this.getNode(id));
2148
+ this.entityManager.changeEntityLocked = true;
2149
+ for (const node of sortNodes.reverse()) {
2150
+ if (inside) {
2151
+ this.originTree.addChild(dropEntity, node, 0);
2152
+ } else {
2153
+ this.originTree.insertAfter(dropEntity, node);
2154
+ }
2155
+ }
2156
+ this.entityManager.changeEntityLocked = false;
2157
+ this.fireRender();
2158
+ }
2159
+ /**
2160
+ * 移动子节点
2161
+ * @param param0
2162
+ * @returns
2163
+ */
2164
+ moveChildNodes({
2165
+ toParentId,
2166
+ toIndex,
2167
+ nodeIds
2168
+ }) {
2169
+ if (nodeIds.length === 0) {
2170
+ return;
2171
+ }
2172
+ const toParent = this.getNode(toParentId);
2173
+ if (!toParent) {
2174
+ return;
2175
+ }
2176
+ this.entityManager.changeEntityLocked = true;
2177
+ this.originTree.moveChilds(
2178
+ toParent,
2179
+ nodeIds.map((nodeId) => this.getNode(nodeId)),
2180
+ toIndex
2181
+ );
2182
+ this.entityManager.changeEntityLocked = false;
2183
+ this.fireRender();
2184
+ }
2185
+ /**
2186
+ * 注册布局
2187
+ * @param layout
2188
+ */
2189
+ registerLayout(layout) {
2190
+ this.layouts.push(layout);
2191
+ }
2192
+ /**
2193
+ * 更新布局
2194
+ * @param layoutKey
2195
+ */
2196
+ setLayout(layoutKey) {
2197
+ if (this.currentLayoutKey === layoutKey) return;
2198
+ const layout = this.layouts.find((layout2) => layout2.name === layoutKey);
2199
+ if (!layout) return;
2200
+ this.currentLayoutKey = layoutKey;
2201
+ this.transformer.clear();
2202
+ layout.reload?.();
2203
+ this.fireRender();
2204
+ this.onLayoutChangeEmitter.fire(this.layout);
2205
+ }
2206
+ /**
2207
+ * 切换垂直或水平布局
2208
+ */
2209
+ toggleFixedLayout() {
2210
+ this.setLayout(
2211
+ this.layout.name === "horizontal-fixed-layout" /* HORIZONTAL_FIXED_LAYOUT */ ? "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */ : "horizontal-fixed-layout" /* HORIZONTAL_FIXED_LAYOUT */
2212
+ );
2213
+ }
2214
+ dispose() {
2215
+ if (this._disposed) return;
2216
+ this.registers.clear();
2217
+ this.nodeRegistryCache.clear();
2218
+ this.originTree.dispose();
2219
+ this.renderTree.dispose();
2220
+ this.onNodeUpdateEmitter.dispose();
2221
+ this.onNodeCreateEmitter.dispose();
2222
+ this.onNodeDisposeEmitter.dispose();
2223
+ this.onLayoutChangeEmitter.dispose();
2224
+ this._disposed = true;
2225
+ }
2226
+ };
2227
+ __decorateClass([
2228
+ inject(EntityManager)
2229
+ ], FlowDocument.prototype, "entityManager", 2);
2230
+ __decorateClass([
2231
+ inject(FlowDocumentConfig)
2232
+ ], FlowDocument.prototype, "config", 2);
2233
+ __decorateClass([
2234
+ inject(FlowDocumentOptions),
2235
+ optional()
2236
+ ], FlowDocument.prototype, "options", 2);
2237
+ __decorateClass([
2238
+ multiInject(FlowDocumentContribution),
2239
+ optional()
2240
+ ], FlowDocument.prototype, "contributions", 2);
2241
+ __decorateClass([
2242
+ postConstruct()
2243
+ ], FlowDocument.prototype, "init", 1);
2244
+ FlowDocument = __decorateClass([
2245
+ injectable()
2246
+ ], FlowDocument);
2247
+
2248
+ // src/services/flow-group-service/flow-group-controller.ts
2249
+ var FlowGroupController = class _FlowGroupController {
2250
+ constructor(groupNode) {
2251
+ this.groupNode = groupNode;
2252
+ }
2253
+ get nodes() {
2254
+ return this.groupNode.collapsedChildren || [];
2255
+ }
2256
+ get collapsed() {
2257
+ const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2258
+ return groupTransformData.collapsed;
2259
+ }
2260
+ collapse() {
2261
+ this.collapsed = true;
2262
+ }
2263
+ expand() {
2264
+ this.collapsed = false;
2265
+ }
2266
+ /** 获取分组外围的最大边框 */
2267
+ get bounds() {
2268
+ const groupNodeBounds = this.groupNode.getData(FlowNodeTransformData).bounds;
2269
+ return groupNodeBounds;
2270
+ }
2271
+ /** 是否是开始节点 */
2272
+ isStartNode(node) {
2273
+ if (!node) {
2274
+ return false;
2275
+ }
2276
+ const nodes = this.nodes;
2277
+ if (!nodes[0]) {
2278
+ return false;
2279
+ }
2280
+ return node.id === nodes[0].id;
2281
+ }
2282
+ /** 是否是结束节点 */
2283
+ isEndNode(node) {
2284
+ if (!node) {
2285
+ return false;
2286
+ }
2287
+ const nodes = this.nodes;
2288
+ if (!nodes[nodes.length - 1]) {
2289
+ return false;
2290
+ }
2291
+ return node.id === nodes[nodes.length - 1].id;
2292
+ }
2293
+ set note(note) {
2294
+ this.groupNode.getNodeMeta().note = note;
2295
+ }
2296
+ get note() {
2297
+ return this.groupNode.getNodeMeta().note || "";
2298
+ }
2299
+ set noteHeight(height) {
2300
+ this.groupNode.getNodeMeta().noteHeight = height;
2301
+ }
2302
+ get noteHeight() {
2303
+ return this.groupNode.getNodeMeta().noteHeight || 0;
2304
+ }
2305
+ get positionConfig() {
2306
+ return this.groupNode.getNodeMeta().positionConfig;
2307
+ }
2308
+ set collapsed(collapsed) {
2309
+ const groupTransformData = this.groupNode.getData(FlowNodeTransformData);
2310
+ groupTransformData.collapsed = collapsed;
2311
+ groupTransformData.localDirty = true;
2312
+ if (groupTransformData.parent) groupTransformData.parent.localDirty = true;
2313
+ if (groupTransformData.parent?.firstChild)
2314
+ groupTransformData.parent.firstChild.localDirty = true;
2315
+ }
2316
+ set hovered(hovered) {
2317
+ const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2318
+ if (hovered) {
2319
+ groupRenderData.toggleMouseEnter();
2320
+ } else {
2321
+ groupRenderData.toggleMouseLeave();
2322
+ }
2323
+ if (groupRenderData.hovered === hovered) {
2324
+ return;
2325
+ }
2326
+ groupRenderData.hovered = hovered;
2327
+ }
2328
+ get hovered() {
2329
+ const groupRenderData = this.groupNode.getData(FlowNodeRenderData);
2330
+ return groupRenderData.hovered;
2331
+ }
2332
+ static create(groupNode) {
2333
+ if (!groupNode) {
2334
+ return;
2335
+ }
2336
+ if (!FlowGroupUtils.isGroupNode(groupNode)) {
2337
+ return;
2338
+ }
2339
+ return new _FlowGroupController(groupNode);
2340
+ }
2341
+ };
2342
+
2343
+ // src/services/flow-group-service/flow-group-utils.ts
2344
+ var FlowGroupUtils;
2345
+ ((FlowGroupUtils2) => {
2346
+ const findNodeParents = (node) => {
2347
+ const parents = [];
2348
+ let parent = node.parent;
2349
+ while (parent) {
2350
+ parents.push(parent);
2351
+ parent = parent.parent;
2352
+ }
2353
+ return parents;
2354
+ };
2355
+ const isNodeInGroup = (node) => {
2356
+ if (node?.parent?.flowNodeType === "group" /* GROUP */) {
2357
+ return true;
2358
+ }
2359
+ return false;
2360
+ };
2361
+ FlowGroupUtils2.validate = (nodes) => {
2362
+ if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
2363
+ return false;
2364
+ }
2365
+ const isGroupRelatedNode = nodes.some((node) => (0, FlowGroupUtils2.isGroupNode)(node));
2366
+ if (isGroupRelatedNode) return false;
2367
+ const hasGroup = nodes.some((node) => node && isNodeInGroup(node));
2368
+ if (hasGroup) return false;
2369
+ const parent = nodes[0].parent;
2370
+ const isSameParent = nodes.every((node) => node.parent === parent);
2371
+ if (!isSameParent) return false;
2372
+ const indexes = nodes.map((node) => node.index).sort((a, b) => a - b);
2373
+ const isIndexContinuous = indexes.every((index, i, arr) => {
2374
+ if (i === 0) {
2375
+ return true;
2376
+ }
2377
+ return index === arr[i - 1] + 1;
2378
+ });
2379
+ if (!isIndexContinuous) return false;
2380
+ const parents = findNodeParents(nodes[0]);
2381
+ const parentsInGroup = parents.some((parent2) => isNodeInGroup(parent2));
2382
+ if (parentsInGroup) return false;
2383
+ return true;
2384
+ };
2385
+ FlowGroupUtils2.getNodeGroupController = (node) => {
2386
+ if (!node) {
2387
+ return;
2388
+ }
2389
+ if (!isNodeInGroup(node)) {
2390
+ return;
2391
+ }
2392
+ const groupNode = node?.parent;
2393
+ return FlowGroupController.create(groupNode);
2394
+ };
2395
+ FlowGroupUtils2.getNodeRecursionGroupController = (node) => {
2396
+ if (!node) {
2397
+ return;
2398
+ }
2399
+ const group = (0, FlowGroupUtils2.getNodeGroupController)(node);
2400
+ if (group) {
2401
+ return group;
2402
+ }
2403
+ if (node.parent) {
2404
+ return (0, FlowGroupUtils2.getNodeRecursionGroupController)(node.parent);
2405
+ }
2406
+ return;
2407
+ };
2408
+ FlowGroupUtils2.isGroupNode = (group) => group.flowNodeType === "group" /* GROUP */;
2409
+ })(FlowGroupUtils || (FlowGroupUtils = {}));
2410
+
2411
+ // src/services/flow-drag-service.ts
2412
+ var FlowDragService = class {
2413
+ constructor() {
2414
+ this.onDropEmitter = new Emitter();
2415
+ this.onDrop = this.onDropEmitter.event;
2416
+ }
2417
+ get renderState() {
2418
+ return this.document.renderState;
2419
+ }
2420
+ // 拖拽所有节点中的首个节点
2421
+ get dragStartNode() {
2422
+ return this.renderState.getDragStartEntity();
2423
+ }
2424
+ // 拖拽的所有节点
2425
+ get dragNodes() {
2426
+ return this.renderState.getDragEntities();
2427
+ }
2428
+ // 放置的区域
2429
+ get dropNodeId() {
2430
+ return this.renderState.getNodeDroppingId();
2431
+ }
2432
+ // 是否在拖拽分支
2433
+ get isDragBranch() {
2434
+ return this.renderState.isBranch || this.dragStartNode?.isInlineBlock;
2435
+ }
2436
+ // 拖拽的所有节点及其自节点
2437
+ get nodeDragIdsWithChildren() {
2438
+ return this.renderState.config.nodeDragIdsWithChildren || [];
2439
+ }
2440
+ get dragging() {
2441
+ return !!this.renderState.dragging;
2442
+ }
2443
+ get labelSide() {
2444
+ return this.renderState.config.dragLabelSide;
2445
+ }
2446
+ /**
2447
+ * 放置到目标分支
2448
+ */
2449
+ dropBranch() {
2450
+ this.dropNode();
2451
+ }
2452
+ /**
2453
+ * 移动并且创建节点
2454
+ * Move and create node
2455
+ */
2456
+ async dropCreateNode(json, onCreateNode) {
2457
+ const dropEntity = this.document.getNode(this.dropNodeId);
2458
+ if (!dropEntity) {
2459
+ return;
2460
+ }
2461
+ if (json) {
2462
+ const dragNodes = await onCreateNode?.(json, dropEntity);
2463
+ this.onDropEmitter.fire({
2464
+ dropNode: dropEntity,
2465
+ dragNodes: dragNodes ? [dragNodes] : [],
2466
+ dragJSON: json
2467
+ });
2468
+ }
2469
+ }
2470
+ /**
2471
+ * 移动到目标节点
2472
+ */
2473
+ dropNode() {
2474
+ const dropEntity = this.document.getNode(this.dropNodeId);
2475
+ if (!dropEntity) {
2476
+ return;
2477
+ }
2478
+ const sortNodes = [];
2479
+ let curr = this.dragStartNode;
2480
+ while (curr && this.dragNodes.includes(curr)) {
2481
+ sortNodes.push(curr);
2482
+ curr = curr.next;
2483
+ }
2484
+ this.operationService.dragNodes({
2485
+ dropNode: dropEntity,
2486
+ nodes: sortNodes
2487
+ });
2488
+ if (sortNodes.length > 0) {
2489
+ this.onDropEmitter.fire({
2490
+ dropNode: dropEntity,
2491
+ dragNodes: sortNodes
2492
+ });
2493
+ }
2494
+ }
2495
+ /**
2496
+ * 拖拽是否可以释放在该节点后面
2497
+ */
2498
+ isDroppableNode(node) {
2499
+ if (!this.dragging || this.isDragBranch) {
2500
+ return false;
2501
+ }
2502
+ if (this.nodeDragIdsWithChildren.includes(node.id) || node.next && this.nodeDragIdsWithChildren.includes(node.next.id)) {
2503
+ return false;
2504
+ }
2505
+ if (node.isInlineBlocks || node.isInlineBlock) {
2506
+ return false;
2507
+ }
2508
+ const hasGroupNode = this.dragNodes.some(
2509
+ (node2) => node2.flowNodeType === "group" /* GROUP */
2510
+ );
2511
+ if (hasGroupNode) {
2512
+ const group = FlowGroupUtils.getNodeRecursionGroupController(node);
2513
+ if (group) {
2514
+ return false;
2515
+ }
2516
+ }
2517
+ return true;
2518
+ }
2519
+ /**
2520
+ * 拖拽分支是否可以释放在该分支
2521
+ * @param node 拖拽的分支节点
2522
+ * @param side 分支的前面还是后面
2523
+ */
2524
+ isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
2525
+ if (this.renderState.isBranch) {
2526
+ return true;
2527
+ }
2528
+ if (this.isDragBranch) {
2529
+ if (
2530
+ // 拖拽到分支
2531
+ !node.isInlineBlock || // 只能在同一分支条件下
2532
+ node.parent !== this.dragStartNode.parent || // 自己不能拖拽给自己
2533
+ node === this.dragStartNode
2534
+ ) {
2535
+ return false;
2536
+ }
2537
+ if (side === "normal_branch" /* NORMAL_BRANCH */ && node.next !== this.dragStartNode) {
2538
+ return true;
2539
+ }
2540
+ if (side === "pre_branch" /* PRE_BRANCH */ && node.pre !== this.dragStartNode) {
2541
+ return true;
2542
+ }
2543
+ }
2544
+ return false;
2545
+ }
2546
+ };
2547
+ __decorateClass([
2548
+ inject(FlowDocument)
2549
+ ], FlowDragService.prototype, "document", 2);
2550
+ __decorateClass([
2551
+ inject(FlowOperationBaseService)
2552
+ ], FlowDragService.prototype, "operationService", 2);
2553
+ __decorateClass([
2554
+ inject(EntityManager)
2555
+ ], FlowDragService.prototype, "entityManager", 2);
2556
+ FlowDragService = __decorateClass([
2557
+ injectable()
2558
+ ], FlowDragService);
2559
+ var FlowOperationBaseServiceImpl = class {
2560
+ constructor() {
2561
+ this.onNodeAddEmitter = new Emitter();
2562
+ this.onNodeAdd = this.onNodeAddEmitter.event;
2563
+ this.toDispose = new DisposableCollection();
2564
+ this.onNodeMoveEmitter = new Emitter();
2565
+ this.onNodeMove = this.onNodeMoveEmitter.event;
2566
+ }
2567
+ init() {
2568
+ this.toDispose.pushAll([this.onNodeAddEmitter, this.onNodeMoveEmitter]);
2569
+ }
2570
+ addNode(nodeJSON, config = {}) {
2571
+ const { parent, index, hidden } = config;
2572
+ let parentEntity;
2573
+ if (parent) {
2574
+ parentEntity = this.toNodeEntity(parent);
2575
+ }
2576
+ let register;
2577
+ if (parentEntity) {
2578
+ register = parentEntity.getNodeRegistry();
2579
+ }
2580
+ const addJSON = {
2581
+ ...nodeJSON,
2582
+ type: nodeJSON.type || "block" /* BLOCK */
2583
+ };
2584
+ const addNodeData = {
2585
+ ...addJSON,
2586
+ parent: parentEntity,
2587
+ index,
2588
+ hidden
2589
+ };
2590
+ let added;
2591
+ if (parentEntity && register?.addChild) {
2592
+ added = register.addChild(parentEntity, addJSON, {
2593
+ index,
2594
+ hidden
2595
+ });
2596
+ } else {
2597
+ added = this.document.addNode(addNodeData);
2598
+ }
2599
+ this.onNodeAddEmitter.fire({
2600
+ node: added,
2601
+ data: addNodeData
2602
+ });
2603
+ return added;
2604
+ }
2605
+ addFromNode(fromNode, nodeJSON) {
2606
+ return this.document.addFromNode(fromNode, nodeJSON);
2607
+ }
2608
+ deleteNode(node) {
2609
+ this.document.removeNode(node);
2610
+ }
2611
+ deleteNodes(nodes) {
2612
+ (nodes || []).forEach((node) => {
2613
+ this.deleteNode(node);
2614
+ });
2615
+ }
2616
+ addBlock(target, blockJSON, config = {}) {
2617
+ const { parent, index } = config;
2618
+ return this.document.addBlock(target, blockJSON, void 0, parent, index);
2619
+ }
2620
+ moveNode(node, config = {}) {
2621
+ const { parent: newParent, index } = config;
2622
+ const entity = this.toNodeEntity(node);
2623
+ const parent = entity?.parent;
2624
+ if (!parent) {
2625
+ return;
2626
+ }
2627
+ const newParentEntity = newParent ? this.toNodeEntity(newParent) : parent;
2628
+ if (!newParentEntity) {
2629
+ console.warn("no new parent found", newParent);
2630
+ return;
2631
+ }
2632
+ let toIndex = typeof index === "undefined" ? newParentEntity.collapsedChildren.length : index;
2633
+ return this.doMoveNode(entity, newParentEntity, toIndex);
2634
+ }
2635
+ /**
2636
+ * 拖拽节点
2637
+ * @param param0
2638
+ * @returns
2639
+ */
2640
+ dragNodes({ dropNode, nodes }) {
2641
+ if (nodes.length === 0) {
2642
+ return;
2643
+ }
2644
+ const startNode = nodes[0];
2645
+ const fromParent = startNode.parent;
2646
+ const toParent = dropNode.parent;
2647
+ if (!fromParent || !toParent) {
2648
+ return;
2649
+ }
2650
+ const fromIndex = fromParent.children.findIndex((child) => child === startNode);
2651
+ const dropIndex = toParent.children.findIndex((child) => child === dropNode);
2652
+ let toIndex = dropIndex + 1;
2653
+ if (fromParent === toParent && fromIndex < dropIndex) {
2654
+ toIndex = toIndex - nodes.length;
2655
+ }
2656
+ const value = {
2657
+ nodeIds: nodes.map((node) => node.id),
2658
+ fromParentId: fromParent.id,
2659
+ toParentId: toParent.id,
2660
+ fromIndex,
2661
+ toIndex
2662
+ };
2663
+ return this.apply({
2664
+ type: "moveChildNodes" /* moveChildNodes */,
2665
+ value
2666
+ });
2667
+ }
2668
+ /**
2669
+ * 执行操作
2670
+ * @param operation 可序列化的操作
2671
+ * @returns 操作返回
2672
+ */
2673
+ apply(operation) {
2674
+ const document = this.document;
2675
+ switch (operation.type) {
2676
+ case "addFromNode" /* addFromNode */:
2677
+ return document.addFromNode(operation.value.fromId, operation.value.data);
2678
+ case "deleteFromNode" /* deleteFromNode */:
2679
+ return document.getNode(operation.value?.data?.id)?.dispose();
2680
+ case "addBlock" /* addBlock */: {
2681
+ let parent;
2682
+ if (operation.value.parentId) {
2683
+ parent = document.getNode(operation.value.parentId);
2684
+ }
2685
+ return document.addBlock(
2686
+ operation.value.targetId,
2687
+ operation.value.blockData,
2688
+ void 0,
2689
+ parent,
2690
+ operation.value.index
2691
+ );
2692
+ }
2693
+ case "deleteBlock" /* deleteBlock */: {
2694
+ const entity = document.getNode(operation.value?.blockData.id);
2695
+ return entity?.dispose();
2696
+ }
2697
+ case "createGroup" /* createGroup */: {
2698
+ const groupNode = document.addFromNode(operation.value.targetId, {
2699
+ id: operation.value.groupId,
2700
+ type: "group" /* GROUP */
2701
+ });
2702
+ document.moveNodes({
2703
+ dropNodeId: operation.value.groupId,
2704
+ sortNodeIds: operation.value.nodeIds,
2705
+ inside: true
2706
+ });
2707
+ return groupNode;
2708
+ }
2709
+ case "ungroup" /* ungroup */: {
2710
+ document.moveNodes({
2711
+ dropNodeId: operation.value.groupId,
2712
+ sortNodeIds: operation.value.nodeIds
2713
+ });
2714
+ return document.getNode(operation.value.groupId)?.dispose();
2715
+ }
2716
+ case "moveNodes" /* moveNodes */: {
2717
+ return document.moveNodes({
2718
+ dropNodeId: operation.value.toId,
2719
+ sortNodeIds: operation.value.nodeIds
2720
+ });
2721
+ }
2722
+ case "moveBlock" /* moveBlock */: {
2723
+ return document.moveChildNodes({
2724
+ ...operation.value,
2725
+ nodeIds: [operation.value.nodeId]
2726
+ });
2727
+ }
2728
+ case "addNodes" /* addNodes */: {
2729
+ let fromId = operation.value.fromId;
2730
+ (operation.value.nodes || []).forEach((node) => {
2731
+ const added = document.addFromNode(fromId, node);
2732
+ fromId = added.id;
2733
+ });
2734
+ break;
2735
+ }
2736
+ case "deleteNodes" /* deleteNodes */: {
2737
+ (operation.value.nodes || []).forEach((node) => {
2738
+ const entity = document.getNode(node.id);
2739
+ entity?.dispose();
2740
+ });
2741
+ break;
2742
+ }
2743
+ case "addChildNode" /* addChildNode */: {
2744
+ return document.addNode({
2745
+ ...operation.value.data,
2746
+ parent: operation.value.parentId ? document.getNode(operation.value.parentId) : void 0,
2747
+ originParent: operation.value.originParentId ? document.getNode(operation.value.originParentId) : void 0,
2748
+ index: operation.value.index,
2749
+ hidden: operation.value.hidden
2750
+ });
2751
+ }
2752
+ case "deleteChildNode" /* deleteChildNode */:
2753
+ return document.getNode(operation.value.data.id)?.dispose();
2754
+ case "moveChildNodes" /* moveChildNodes */:
2755
+ return document.moveChildNodes(operation.value);
2756
+ default:
2757
+ throw new Error(`unknown operation type`);
2758
+ }
2759
+ }
2760
+ /**
2761
+ * 事务执行
2762
+ * @param transaction
2763
+ */
2764
+ transact(transaction) {
2765
+ transaction();
2766
+ }
2767
+ dispose() {
2768
+ this.toDispose.dispose();
2769
+ }
2770
+ toId(node) {
2771
+ return typeof node === "string" ? node : node.id;
2772
+ }
2773
+ toNodeEntity(node) {
2774
+ return typeof node === "string" ? this.document.getNode(node) : node;
2775
+ }
2776
+ getNodeIndex(node) {
2777
+ const entity = this.toNodeEntity(node);
2778
+ const parent = entity?.parent;
2779
+ if (!parent) {
2780
+ return -1;
2781
+ }
2782
+ return parent.children.findIndex((child) => child === entity);
2783
+ }
2784
+ doMoveNode(node, newParent, index) {
2785
+ if (!node.parent) {
2786
+ throw new Error("root node cannot move");
2787
+ }
2788
+ const event = {
2789
+ node,
2790
+ fromParent: node.parent,
2791
+ toParent: newParent,
2792
+ fromIndex: this.getNodeIndex(node),
2793
+ toIndex: index
2794
+ };
2795
+ this.document.moveChildNodes({
2796
+ nodeIds: [this.toId(node)],
2797
+ toParentId: this.toId(newParent),
2798
+ toIndex: index
2799
+ });
2800
+ this.onNodeMoveEmitter.fire(event);
2801
+ }
2802
+ };
2803
+ __decorateClass([
2804
+ inject(EntityManager)
2805
+ ], FlowOperationBaseServiceImpl.prototype, "entityManager", 2);
2806
+ __decorateClass([
2807
+ inject(FlowDocument)
2808
+ ], FlowOperationBaseServiceImpl.prototype, "document", 2);
2809
+ __decorateClass([
2810
+ postConstruct()
2811
+ ], FlowOperationBaseServiceImpl.prototype, "init", 1);
2812
+ FlowOperationBaseServiceImpl = __decorateClass([
2813
+ injectable()
2814
+ ], FlowOperationBaseServiceImpl);
2815
+ var FlowGroupService = class {
2816
+ /** 创建分组节点 */
2817
+ createGroup(nodes) {
2818
+ if (!nodes || !Array.isArray(nodes) || nodes.length === 0) {
2819
+ return;
2820
+ }
2821
+ if (!FlowGroupUtils.validate(nodes)) {
2822
+ return;
2823
+ }
2824
+ const sortedNodes = nodes.sort((a, b) => a.index - b.index);
2825
+ const fromNode = sortedNodes[0];
2826
+ const groupId = `group_${nanoid(5)}`;
2827
+ this.operationService.apply({
2828
+ type: "createGroup" /* createGroup */,
2829
+ value: {
2830
+ targetId: fromNode.id,
2831
+ groupId,
2832
+ nodeIds: nodes.map((node) => node.id)
2833
+ }
2834
+ });
2835
+ const groupNode = this.entityManager.getEntityById(groupId);
2836
+ if (!groupNode) {
2837
+ return;
2838
+ }
2839
+ const group = this.groupController(groupNode);
2840
+ if (!group) {
2841
+ return;
2842
+ }
2843
+ group.expand();
2844
+ return groupNode;
2845
+ }
2846
+ /** 删除分组 */
2847
+ deleteGroup(groupNode) {
2848
+ const json = groupNode.toJSON();
2849
+ if (!groupNode.pre || !json) {
2850
+ return;
2851
+ }
2852
+ this.operationService.apply({
2853
+ type: "deleteNodes" /* deleteNodes */,
2854
+ value: {
2855
+ fromId: groupNode.pre.id,
2856
+ nodes: [json]
2857
+ }
2858
+ });
2859
+ }
2860
+ /** 取消分组 */
2861
+ ungroup(groupNode) {
2862
+ const group = this.groupController(groupNode);
2863
+ if (!group) {
2864
+ return;
2865
+ }
2866
+ const nodes = group.nodes;
2867
+ if (!groupNode.pre) {
2868
+ return;
2869
+ }
2870
+ group.collapse();
2871
+ this.operationService.apply({
2872
+ type: "ungroup" /* ungroup */,
2873
+ value: {
2874
+ groupId: groupNode.id,
2875
+ targetId: groupNode.pre.id,
2876
+ nodeIds: nodes.map((node) => node.id)
2877
+ }
2878
+ });
2879
+ }
2880
+ /** 返回所有分组节点 */
2881
+ getAllGroups() {
2882
+ const allNodes = this.entityManager.getEntities(FlowNodeEntity);
2883
+ const groupNodes = allNodes.filter((node) => node.flowNodeType === "group" /* GROUP */);
2884
+ return groupNodes.map((node) => this.groupController(node)).filter(Boolean);
2885
+ }
2886
+ /** 获取分组控制器*/
2887
+ groupController(group) {
2888
+ return FlowGroupController.create(group);
2889
+ }
2890
+ static validate(nodes) {
2891
+ return FlowGroupUtils.validate(nodes);
2892
+ }
2893
+ };
2894
+ __decorateClass([
2895
+ inject(EntityManager)
2896
+ ], FlowGroupService.prototype, "entityManager", 2);
2897
+ __decorateClass([
2898
+ inject(FlowOperationBaseService)
2899
+ ], FlowGroupService.prototype, "operationService", 2);
2900
+ FlowGroupService = __decorateClass([
2901
+ injectable()
2902
+ ], FlowGroupService);
2903
+ var DEFAULT_SCROLL = -36;
2904
+ function isStructDataEqual(struct1, struct2) {
2905
+ return struct1.childrenLength === struct2.childrenLength && struct1.index === struct2.index;
2906
+ }
2907
+ var VerticalFixedLayout = class {
2908
+ constructor() {
2909
+ this.name = "vertical-fixed-layout" /* VERTICAL_FIXED_LAYOUT */;
2910
+ this.structDataMap = /* @__PURE__ */ new WeakMap();
2911
+ }
2912
+ get document() {
2913
+ return this.documentProvider();
2914
+ }
2915
+ reload() {
2916
+ this.structDataMap = /* @__PURE__ */ new WeakMap();
2917
+ }
2918
+ /**
2919
+ * 更新布局
2920
+ */
2921
+ update() {
2922
+ this.updateLocalTransform(this.document.root);
2923
+ }
2924
+ /**
2925
+ * 更新节点的偏移
2926
+ * @param node
2927
+ * @param forceChange
2928
+ */
2929
+ updateLocalTransform(node, forceChange = false) {
2930
+ const { children, parent, isInlineBlock } = node;
2931
+ const transform = node.getData(FlowNodeTransformData);
2932
+ const { getDelta, getOrigin } = node.getNodeRegistry();
2933
+ const lastStructData = this.structDataMap.get(node) || {
2934
+ childrenLength: 0,
2935
+ index: -1
2936
+ };
2937
+ node.clearMemoGlobal();
2938
+ let localDirty = transform.localDirty || forceChange;
2939
+ const newStructData = {
2940
+ index: node.index,
2941
+ childrenLength: node.children.length
2942
+ };
2943
+ if (!isStructDataEqual(lastStructData, newStructData)) {
2944
+ localDirty = true;
2945
+ this.structDataMap.set(node, newStructData);
2946
+ }
2947
+ let siblingDirty = false;
2948
+ if (children.length > 0) {
2949
+ for (const child of children) {
2950
+ const childDirty = this.updateLocalTransform(child, siblingDirty);
2951
+ if (childDirty) {
2952
+ siblingDirty = true;
2953
+ localDirty = true;
2954
+ }
2955
+ }
2956
+ }
2957
+ if (!localDirty) return false;
2958
+ node.clearMemoLocal();
2959
+ transform.transform.update({
2960
+ origin: getOrigin ? getOrigin(transform, this) : this.getDefaultNodeOrigin()
2961
+ });
2962
+ const preTransform = transform.pre;
2963
+ const delta = getDelta?.(transform, this) || { x: 0, y: 0 };
2964
+ const inlineSpacingPre = isInlineBlock && transform.parent?.inlineSpacingPre ? transform.parent?.inlineSpacingPre : 0;
2965
+ const fromParentDelta = parent?.getNodeRegistry().getChildDelta?.(transform, this) || {
2966
+ x: 0,
2967
+ y: 0
2968
+ };
2969
+ delta.x += fromParentDelta.x;
2970
+ delta.y += fromParentDelta.y;
2971
+ const position = { x: delta.x, y: delta.y };
2972
+ if (isInlineBlock) {
2973
+ position.y += inlineSpacingPre;
2974
+ } else {
2975
+ position.y += preTransform?.localBounds.bottom || 0;
2976
+ position.y += preTransform?.spacing || 0;
2977
+ }
2978
+ transform.transform.update({
2979
+ size: transform.data.size,
2980
+ position
2981
+ });
2982
+ this.onAfterUpdateLocalTransform(transform);
2983
+ transform.localDirty = false;
2984
+ return true;
2985
+ }
2986
+ onAfterUpdateLocalTransform(transform) {
2987
+ const { onAfterUpdateLocalTransform } = transform.entity.getNodeRegistry();
2988
+ onAfterUpdateLocalTransform?.(transform, this);
2989
+ this.contribs?.forEach((_contrib) => {
2990
+ _contrib?.onAfterUpdateLocalTransform?.(transform, this);
2991
+ });
2992
+ }
2993
+ getNodeTransform(node) {
2994
+ return node.getData(FlowNodeTransformData);
2995
+ }
2996
+ getPadding(node) {
2997
+ const { inlineSpacingPre, inlineSpacingAfter, padding } = node.getNodeMeta();
2998
+ const transform = this.getNodeTransform(node);
2999
+ if (padding) {
3000
+ return typeof padding === "function" ? padding(transform) : padding;
3001
+ }
3002
+ const paddingPre = typeof inlineSpacingPre === "function" ? inlineSpacingPre(transform) : inlineSpacingPre;
3003
+ const paddingAfter = typeof inlineSpacingAfter === "function" ? inlineSpacingAfter(transform) : inlineSpacingAfter;
3004
+ return {
3005
+ left: 0,
3006
+ top: paddingPre,
3007
+ right: 0,
3008
+ bottom: paddingAfter
3009
+ };
3010
+ }
3011
+ getInitScroll(contentSize) {
3012
+ return {
3013
+ scrollX: -contentSize.width / 2,
3014
+ scrollY: DEFAULT_SCROLL
3015
+ };
3016
+ }
3017
+ getDefaultInputPoint(node) {
3018
+ return this.getNodeTransform(node).bounds.topCenter;
3019
+ }
3020
+ getDefaultOutputPoint(node) {
3021
+ return this.getNodeTransform(node).bounds.bottomCenter;
3022
+ }
3023
+ getDefaultNodeOrigin() {
3024
+ return { x: 0.5, y: 0 };
3025
+ }
3026
+ };
3027
+ __decorateClass([
3028
+ inject(FlowDocumentProvider)
3029
+ ], VerticalFixedLayout.prototype, "documentProvider", 2);
3030
+ __decorateClass([
3031
+ multiInject(FlowLayoutContribution),
3032
+ optional()
3033
+ ], VerticalFixedLayout.prototype, "contribs", 2);
3034
+ VerticalFixedLayout = __decorateClass([
3035
+ injectable()
3036
+ ], VerticalFixedLayout);
3037
+ var DEFAULT_SCROLL2 = -36;
3038
+ function isStructDataEqual2(struct1, struct2) {
3039
+ return struct1.childrenLength === struct2.childrenLength && struct1.index === struct2.index;
3040
+ }
3041
+ var HorizontalFixedLayout = class {
3042
+ constructor() {
3043
+ this.name = "horizontal-fixed-layout" /* HORIZONTAL_FIXED_LAYOUT */;
3044
+ this.structDataMap = /* @__PURE__ */ new WeakMap();
3045
+ }
3046
+ get document() {
3047
+ return this.documentProvider();
3048
+ }
3049
+ reload() {
3050
+ this.structDataMap = /* @__PURE__ */ new WeakMap();
3051
+ }
3052
+ /**
3053
+ * 更新布局
3054
+ */
3055
+ update() {
3056
+ this.updateLocalTransform(this.document.root);
3057
+ }
3058
+ /**
3059
+ * 更新节点的偏移
3060
+ * @param node
3061
+ * @param forceChange
3062
+ */
3063
+ updateLocalTransform(node, forceChange = false) {
3064
+ const { children, parent, isInlineBlock } = node;
3065
+ const transform = node.getData(FlowNodeTransformData);
3066
+ const { getDelta, getOrigin } = node.getNodeRegistry();
3067
+ const lastStructData = this.structDataMap.get(node) || {
3068
+ childrenLength: 0,
3069
+ index: -1
3070
+ };
3071
+ node.clearMemoGlobal();
3072
+ let localDirty = transform.localDirty || forceChange;
3073
+ const newStructData = {
3074
+ index: node.index,
3075
+ childrenLength: node.children.length
3076
+ };
3077
+ if (!isStructDataEqual2(lastStructData, newStructData)) {
3078
+ localDirty = true;
3079
+ this.structDataMap.set(node, newStructData);
3080
+ }
3081
+ let siblingDirty = false;
3082
+ if (children.length > 0) {
3083
+ for (const child of children) {
3084
+ const childDirty = this.updateLocalTransform(child, siblingDirty);
3085
+ if (childDirty) {
3086
+ siblingDirty = true;
3087
+ localDirty = true;
3088
+ }
3089
+ }
3090
+ }
3091
+ if (!localDirty) return false;
3092
+ node.clearMemoLocal();
3093
+ transform.transform.update({
3094
+ origin: getOrigin ? getOrigin(transform, this) : this.getDefaultNodeOrigin()
3095
+ });
3096
+ const preTransform = transform.pre;
3097
+ const delta = getDelta?.(transform, this) || { x: 0, y: 0 };
3098
+ const inlineSpacingPre = isInlineBlock && transform.parent?.inlineSpacingPre ? transform.parent?.inlineSpacingPre : 0;
3099
+ const fromParentDelta = parent?.getNodeRegistry().getChildDelta?.(transform, this) || {
3100
+ x: 0,
3101
+ y: 0
3102
+ };
3103
+ delta.x += fromParentDelta.x;
3104
+ delta.y += fromParentDelta.y;
3105
+ const position = { x: delta.x, y: delta.y };
3106
+ if (isInlineBlock) {
3107
+ position.x += inlineSpacingPre;
3108
+ } else {
3109
+ position.x += preTransform?.localBounds.right || 0;
3110
+ position.x += preTransform?.spacing || 0;
3111
+ }
3112
+ transform.transform.update({
3113
+ size: transform.data.size,
3114
+ position
3115
+ });
3116
+ this.onAfterUpdateLocalTransform(transform);
3117
+ transform.localDirty = false;
3118
+ return true;
3119
+ }
3120
+ onAfterUpdateLocalTransform(transform) {
3121
+ const { onAfterUpdateLocalTransform } = transform.entity.getNodeRegistry();
3122
+ onAfterUpdateLocalTransform?.(transform, this);
3123
+ this.contribs?.forEach((_contrib) => {
3124
+ _contrib?.onAfterUpdateLocalTransform?.(transform, this);
3125
+ });
3126
+ }
3127
+ getNodeTransform(node) {
3128
+ return node.getData(FlowNodeTransformData);
3129
+ }
3130
+ getPadding(node) {
3131
+ const { inlineSpacingPre, inlineSpacingAfter, padding } = node.getNodeMeta();
3132
+ const transform = this.getNodeTransform(node);
3133
+ if (padding) {
3134
+ return typeof padding === "function" ? padding(transform) : padding;
3135
+ }
3136
+ const paddingPre = typeof inlineSpacingPre === "function" ? inlineSpacingPre(transform) : inlineSpacingPre;
3137
+ const paddingAfter = typeof inlineSpacingAfter === "function" ? inlineSpacingAfter(transform) : inlineSpacingAfter;
3138
+ return {
3139
+ left: paddingPre,
3140
+ top: 0,
3141
+ right: paddingAfter,
3142
+ bottom: 0
3143
+ };
3144
+ }
3145
+ getInitScroll(contentSize) {
3146
+ return {
3147
+ scrollX: DEFAULT_SCROLL2,
3148
+ scrollY: -contentSize.height / 2
3149
+ };
3150
+ }
3151
+ getDefaultInputPoint(node) {
3152
+ return this.getNodeTransform(node).bounds.leftCenter;
3153
+ }
3154
+ getDefaultOutputPoint(node) {
3155
+ return this.getNodeTransform(node).bounds.rightCenter;
3156
+ }
3157
+ getDefaultNodeOrigin() {
3158
+ return { x: 0, y: 0.5 };
3159
+ }
3160
+ };
3161
+ __decorateClass([
3162
+ inject(FlowDocumentProvider)
3163
+ ], HorizontalFixedLayout.prototype, "documentProvider", 2);
3164
+ __decorateClass([
3165
+ multiInject(FlowLayoutContribution),
3166
+ optional()
3167
+ ], HorizontalFixedLayout.prototype, "contribs", 2);
3168
+ HorizontalFixedLayout = __decorateClass([
3169
+ injectable()
3170
+ ], HorizontalFixedLayout);
3171
+
3172
+ // src/flow-document-container-module.ts
3173
+ var FlowDocumentContainerModule = new ContainerModule((bind) => {
3174
+ bind(FlowDocument).toSelf().inSingletonScope();
3175
+ bind(FlowDocumentProvider).toDynamicValue((ctx) => () => ctx.container.get(FlowDocument)).inSingletonScope();
3176
+ bind(FlowDocumentConfig).toSelf().inSingletonScope();
3177
+ bind(VerticalFixedLayout).toSelf().inSingletonScope();
3178
+ bind(HorizontalFixedLayout).toSelf().inSingletonScope();
3179
+ bind(FlowDragService).toSelf().inSingletonScope();
3180
+ bind(FlowOperationBaseService).to(FlowOperationBaseServiceImpl).inSingletonScope();
3181
+ bind(FlowGroupService).toSelf().inSingletonScope();
3182
+ bind(FlowDocumentContribution).toDynamicValue((ctx) => ({
3183
+ registerDocument: (document) => {
3184
+ document.registerLayout(ctx.container.get(VerticalFixedLayout));
3185
+ document.registerLayout(ctx.container.get(HorizontalFixedLayout));
3186
+ }
3187
+ }));
3188
+ });
3189
+
3190
+ // src/utils/get-default-spacing.ts
3191
+ var getDefaultSpacing = (node, key, defaultSpacing) => {
3192
+ const flowDocumentOptions = node.getService(FlowDocumentOptions);
3193
+ const spacing = flowDocumentOptions?.constants?.[key] || defaultSpacing || DEFAULT_SPACING[key];
3194
+ return spacing;
3195
+ };
3196
+
3197
+ export { ConstantKeys, DEFAULT_FLOW_NODE_META, DEFAULT_SIZE, DEFAULT_SPACING, DRAGGING_TYPE, DefaultSpacingKey, FLOW_DEFAULT_HIDDEN_TYPES, FlowDocument, FlowDocumentConfig, FlowDocumentConfigDefaultData, FlowDocumentConfigEnum, FlowDocumentContainerModule, FlowDocumentContribution, FlowDocumentOptions, FlowDocumentOptionsDefault, FlowDocumentProvider, FlowDocumentTransformerEntity, FlowDragService, FlowGroupController, FlowGroupService, FlowLayout, FlowLayoutContribution, FlowLayoutDefault, FlowNodeBaseType, FlowNodeEntity, FlowNodeRegistry, FlowNodeRenderData, FlowNodeSplitType, FlowNodeTransformData, FlowNodeTransitionData, FlowOperationBaseService, FlowOperationBaseServiceImpl, FlowRendererStateEntity, FlowTransitionLabelEnum, FlowTransitionLineEnum, FlowVirtualTree, LABEL_SIDE_TYPE, OperationType, drawLineToBottom, drawLineToNext, getDefaultSpacing };
3198
+ //# sourceMappingURL=index.js.map
3199
+ //# sourceMappingURL=index.js.map