@flowgram.ai/document 0.1.0

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