@flowgram.ai/fixed-layout-core 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,1554 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
12
+ // src/fixed-layout-container-module.ts
13
+ import { ContainerModule } from "inversify";
14
+ import { FlowRendererContribution } from "@flowgram.ai/renderer";
15
+ import { FlowDocumentContribution } from "@flowgram.ai/document";
16
+ import { PlaygroundContribution } from "@flowgram.ai/core";
17
+ import { bindContributions } from "@flowgram.ai/utils";
18
+
19
+ // src/flow-registers.ts
20
+ import { injectable } from "inversify";
21
+ import {
22
+ FlowLabelsLayer,
23
+ FlowLinesLayer,
24
+ FlowNodesContentLayer,
25
+ FlowNodesTransformLayer,
26
+ FlowScrollBarLayer,
27
+ FlowScrollLimitLayer
28
+ } from "@flowgram.ai/renderer";
29
+ import {
30
+ FlowNodeRenderData as FlowNodeRenderData3,
31
+ FlowNodeTransformData as FlowNodeTransformData3,
32
+ FlowNodeTransitionData
33
+ } from "@flowgram.ai/document";
34
+ import { PlaygroundLayer } from "@flowgram.ai/core";
35
+
36
+ // src/activities/end.ts
37
+ import { FlowNodeBaseType } from "@flowgram.ai/document";
38
+ var EndRegistry = {
39
+ type: FlowNodeBaseType.END,
40
+ meta: {
41
+ draggable: false,
42
+ isNodeEnd: true,
43
+ selectable: false,
44
+ copyDisable: true
45
+ },
46
+ // 结束节点没有出边和 label
47
+ getLines() {
48
+ return [];
49
+ },
50
+ getLabels() {
51
+ return [];
52
+ }
53
+ };
54
+
55
+ // src/activities/dynamic-split.ts
56
+ import {
57
+ FlowLayoutDefault,
58
+ FlowNodeSplitType,
59
+ FlowTransitionLabelEnum,
60
+ ConstantKeys,
61
+ getDefaultSpacing
62
+ } from "@flowgram.ai/document";
63
+ var DynamicSplitRegistry = {
64
+ type: FlowNodeSplitType.DYNAMIC_SPLIT,
65
+ meta: {
66
+ hidden: true,
67
+ inlineSpacingAfter: (node) => node.collapsed && node.entity.collapsedChildren.length > 1 ? 21 : 0,
68
+ // 判断是否有分支节点
69
+ spacing: (node) => {
70
+ const spacing = getDefaultSpacing(node.entity, ConstantKeys.NODE_SPACING);
71
+ return node.children.length === 1 ? spacing : spacing / 2;
72
+ }
73
+ },
74
+ getLabels(transition) {
75
+ if (transition.isNodeEnd) {
76
+ return [];
77
+ }
78
+ return [
79
+ {
80
+ type: FlowTransitionLabelEnum.ADDER_LABEL,
81
+ offset: transition.transform.outputPoint
82
+ }
83
+ ];
84
+ },
85
+ onCreate(node, json) {
86
+ return node.document.addInlineBlocks(node, json.blocks || []);
87
+ },
88
+ getInputPoint(transform) {
89
+ return transform.firstChild?.inputPoint || transform.defaultInputPoint;
90
+ },
91
+ getOutputPoint(transform, layout) {
92
+ const isVertical = FlowLayoutDefault.isVertical(layout);
93
+ const noInlineBlocks = transform.children.length === 1;
94
+ const lastChildOutput = transform.lastChild?.outputPoint;
95
+ const spacing = getDefaultSpacing(transform.entity, ConstantKeys.NODE_SPACING);
96
+ if (isVertical) {
97
+ return {
98
+ x: lastChildOutput ? lastChildOutput.x : transform.bounds.center.x,
99
+ y: transform.bounds.bottom + (noInlineBlocks ? spacing / 2 : 0)
100
+ };
101
+ }
102
+ return {
103
+ x: transform.bounds.right + (noInlineBlocks ? spacing / 2 : 0),
104
+ y: lastChildOutput ? lastChildOutput.y : transform.bounds.center.y
105
+ };
106
+ },
107
+ addChild(node, json, options = {}) {
108
+ const { index } = options;
109
+ const document = node.document;
110
+ const parentId = `$inlineBlocks$${node.id}`;
111
+ let parent = document.getNode(parentId);
112
+ if (!parent) {
113
+ parent = document.addNode({
114
+ id: parentId,
115
+ type: "inlineBlocks",
116
+ originParent: node,
117
+ parent: node
118
+ });
119
+ }
120
+ return document.addBlock(node, json, void 0, void 0, index);
121
+ }
122
+ };
123
+
124
+ // src/activities/static-split.ts
125
+ import { FlowNodeBaseType as FlowNodeBaseType2, FlowNodeSplitType as FlowNodeSplitType2 } from "@flowgram.ai/document";
126
+ var StaticSplitRegistry = {
127
+ extend: FlowNodeSplitType2.DYNAMIC_SPLIT,
128
+ type: FlowNodeSplitType2.STATIC_SPLIT,
129
+ extendChildRegistries: [
130
+ {
131
+ type: FlowNodeBaseType2.INLINE_BLOCKS,
132
+ getLabels() {
133
+ return [];
134
+ }
135
+ }
136
+ ]
137
+ };
138
+
139
+ // src/activities/block.ts
140
+ import {
141
+ DEFAULT_SPACING,
142
+ FlowLayoutDefault as FlowLayoutDefault2,
143
+ FlowNodeBaseType as FlowNodeBaseType3,
144
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum2,
145
+ FlowTransitionLineEnum,
146
+ LABEL_SIDE_TYPE
147
+ } from "@flowgram.ai/document";
148
+ var BlockRegistry = {
149
+ type: FlowNodeBaseType3.BLOCK,
150
+ meta: {
151
+ spacing: DEFAULT_SPACING.NULL,
152
+ inlineSpacingAfter: DEFAULT_SPACING.INLINE_BLOCK_PADDING_BOTTOM,
153
+ hidden: true
154
+ },
155
+ getLines(transition) {
156
+ const currentTransform = transition.transform;
157
+ const { isVertical } = transition.entity;
158
+ const lines = [
159
+ {
160
+ type: FlowTransitionLineEnum.DIVERGE_LINE,
161
+ from: currentTransform.parent.inputPoint,
162
+ to: currentTransform.inputPoint,
163
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
164
+ }
165
+ ];
166
+ const hasBranchDraggingAdder = currentTransform && currentTransform.entity.isInlineBlock && transition.renderData.draggable;
167
+ if (hasBranchDraggingAdder) {
168
+ if (isVertical) {
169
+ const currentOffsetRightX = currentTransform.firstChild?.bounds?.right || 0;
170
+ const nextOffsetLeftX = currentTransform.next?.firstChild?.bounds?.left || 0;
171
+ const currentInputPointY = currentTransform.inputPoint.y;
172
+ if (currentTransform?.next) {
173
+ lines.push({
174
+ type: FlowTransitionLineEnum.DRAGGING_LINE,
175
+ from: currentTransform.parent.inputPoint,
176
+ to: {
177
+ x: (currentOffsetRightX + nextOffsetLeftX) / 2,
178
+ y: currentInputPointY
179
+ },
180
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
181
+ });
182
+ }
183
+ } else {
184
+ const currentOffsetRightY = currentTransform.firstChild?.bounds?.bottom || 0;
185
+ const nextOffsetLeftY = currentTransform.next?.firstChild?.bounds?.top || 0;
186
+ const currentInputPointX = currentTransform.inputPoint.x;
187
+ if (currentTransform?.next) {
188
+ lines.push({
189
+ type: FlowTransitionLineEnum.DRAGGING_LINE,
190
+ from: currentTransform.parent.inputPoint,
191
+ to: {
192
+ x: currentInputPointX,
193
+ y: (currentOffsetRightY + nextOffsetLeftY) / 2
194
+ },
195
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
196
+ });
197
+ }
198
+ }
199
+ }
200
+ if (!transition.isNodeEnd) {
201
+ lines.push({
202
+ type: FlowTransitionLineEnum.MERGE_LINE,
203
+ from: currentTransform.outputPoint,
204
+ to: currentTransform.parent.outputPoint,
205
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
206
+ });
207
+ }
208
+ return lines;
209
+ },
210
+ getInputPoint(trans) {
211
+ const child = trans.firstChild;
212
+ return child ? child.inputPoint : trans.defaultInputPoint;
213
+ },
214
+ getOutputPoint(trans, layout) {
215
+ const isVertical = FlowLayoutDefault2.isVertical(layout);
216
+ const child = trans.lastChild;
217
+ if (isVertical) {
218
+ return {
219
+ x: child ? child.outputPoint.x : trans.bounds.bottomCenter.x,
220
+ y: trans.bounds.bottom
221
+ };
222
+ }
223
+ return {
224
+ x: trans.bounds.right,
225
+ y: child ? child.outputPoint.y : trans.bounds.rightCenter.y
226
+ };
227
+ },
228
+ getLabels(transition) {
229
+ const currentTransform = transition.transform;
230
+ const { isVertical } = transition.entity;
231
+ const draggingLabel = [];
232
+ const hasBranchDraggingAdder = currentTransform && currentTransform.entity.isInlineBlock && transition.renderData.draggable;
233
+ if (hasBranchDraggingAdder) {
234
+ if (isVertical) {
235
+ const currentOffsetRightX = currentTransform.firstChild?.bounds?.right || 0;
236
+ const nextOffsetLeftX = currentTransform.next?.firstChild?.bounds?.left || 0;
237
+ const currentInputPointY = currentTransform.inputPoint.y;
238
+ if (currentTransform?.next) {
239
+ draggingLabel.push({
240
+ offset: {
241
+ x: (currentOffsetRightX + nextOffsetLeftX) / 2,
242
+ y: currentInputPointY
243
+ },
244
+ type: FlowTransitionLabelEnum2.BRANCH_DRAGGING_LABEL,
245
+ width: nextOffsetLeftX - currentOffsetRightX,
246
+ props: {
247
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
248
+ }
249
+ });
250
+ }
251
+ } else {
252
+ const currentOffsetRightY = currentTransform.firstChild?.bounds?.bottom || 0;
253
+ const nextOffsetLeftY = currentTransform.next?.firstChild?.bounds?.top || 0;
254
+ const currentInputPointX = currentTransform.inputPoint.x;
255
+ if (currentTransform?.next) {
256
+ draggingLabel.push({
257
+ offset: {
258
+ x: currentInputPointX,
259
+ y: (currentOffsetRightY + nextOffsetLeftY) / 2
260
+ },
261
+ type: FlowTransitionLabelEnum2.BRANCH_DRAGGING_LABEL,
262
+ width: nextOffsetLeftY - currentOffsetRightY,
263
+ props: {
264
+ side: LABEL_SIDE_TYPE.NORMAL_BRANCH
265
+ }
266
+ });
267
+ }
268
+ }
269
+ }
270
+ return [...draggingLabel];
271
+ },
272
+ addChild(node, json, options = {}) {
273
+ const { index } = options;
274
+ const document = node.document;
275
+ return document.addNode({
276
+ ...json,
277
+ ...options,
278
+ parent: node,
279
+ index: typeof index === "number" ? index + 1 : void 0
280
+ });
281
+ }
282
+ };
283
+
284
+ // src/activities/inline-blocks.ts
285
+ import { Point } from "@flowgram.ai/utils";
286
+ import { FlowRendererKey } from "@flowgram.ai/renderer";
287
+ import {
288
+ DEFAULT_SPACING as DEFAULT_SPACING2,
289
+ FlowNodeBaseType as FlowNodeBaseType4,
290
+ FlowNodeRenderData,
291
+ FlowNodeTransformData,
292
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum3,
293
+ FlowLayoutDefault as FlowLayoutDefault3,
294
+ ConstantKeys as ConstantKeys2,
295
+ getDefaultSpacing as getDefaultSpacing2
296
+ } from "@flowgram.ai/document";
297
+ var InlineBlocksRegistry = {
298
+ type: FlowNodeBaseType4.INLINE_BLOCKS,
299
+ meta: {
300
+ hidden: true,
301
+ spacing: (node) => getDefaultSpacing2(node.entity, ConstantKeys2.NODE_SPACING),
302
+ isInlineBlocks: true,
303
+ inlineSpacingPre: DEFAULT_SPACING2.INLINE_BLOCKS_PADDING_TOP,
304
+ inlineSpacingAfter: (node) => getDefaultSpacing2(node.entity, ConstantKeys2.INLINE_BLOCKS_PADDING_BOTTOM)
305
+ },
306
+ /**
307
+ * 控制子分支的间距
308
+ * @param child
309
+ */
310
+ getChildDelta(child, layout) {
311
+ const isVertical = FlowLayoutDefault3.isVertical(layout);
312
+ const preTransform = child.entity.pre?.getData(FlowNodeTransformData);
313
+ if (preTransform) {
314
+ const { localBounds: preBounds } = preTransform;
315
+ if (isVertical) {
316
+ const leftSpacing = preTransform.size.width + preTransform.originDeltaX;
317
+ const delta = Math.max(
318
+ child.parent.minInlineBlockSpacing - leftSpacing,
319
+ DEFAULT_SPACING2.MARGIN_RIGHT - child.originDeltaX
320
+ );
321
+ return {
322
+ // 这里需要加上原点的偏移量,并加上水平间距
323
+ x: preBounds.right + delta,
324
+ y: 0
325
+ };
326
+ } else {
327
+ const bottomSpacing = preTransform.size.height + preTransform.originDeltaY;
328
+ const delta = Math.max(
329
+ child.parent.minInlineBlockSpacing - bottomSpacing,
330
+ DEFAULT_SPACING2.MARGIN_RIGHT - child.originDeltaY
331
+ );
332
+ return {
333
+ x: 0,
334
+ // 这里需要加上原点的偏移量,并加上垂直间距
335
+ y: preBounds.bottom + delta
336
+ };
337
+ }
338
+ }
339
+ return {
340
+ x: 0,
341
+ y: 0
342
+ };
343
+ },
344
+ /**
345
+ * 控制条件分支居中布局
346
+ * @param trans
347
+ */
348
+ getDelta(trans, layout) {
349
+ const isVertical = FlowLayoutDefault3.isVertical(layout);
350
+ const { pre, collapsed } = trans;
351
+ if (collapsed) {
352
+ return { x: 0, y: 0 };
353
+ }
354
+ if (isVertical) {
355
+ const preCenter2 = pre.localBounds.center.x;
356
+ const firstBlockX = trans.firstChild?.transform.position.x || 0;
357
+ const lastBlockX = trans.lastChild?.transform.position.x || 0;
358
+ const currentCenter2 = (lastBlockX - firstBlockX) / 2;
359
+ return {
360
+ x: preCenter2 - currentCenter2,
361
+ y: 0
362
+ };
363
+ }
364
+ const preCenter = pre.localBounds.center.y;
365
+ const firstBlockY = trans.firstChild?.transform.position.y || 0;
366
+ const lastBlockY = trans.lastChild?.transform.position.y || 0;
367
+ const currentCenter = (lastBlockY - firstBlockY) / 2;
368
+ return {
369
+ x: 0,
370
+ y: preCenter - currentCenter
371
+ };
372
+ },
373
+ getLabels(transition) {
374
+ return getBranchAdderLabel(transition);
375
+ },
376
+ getLines() {
377
+ return [];
378
+ },
379
+ // 和前序节点对齐
380
+ getInputPoint(transform, layout) {
381
+ const isVertical = FlowLayoutDefault3.isVertical(layout);
382
+ if (isVertical) {
383
+ return {
384
+ x: transform.pre?.outputPoint.x || 0,
385
+ y: transform.bounds.top
386
+ };
387
+ }
388
+ return {
389
+ x: transform.bounds.left,
390
+ y: transform.pre?.outputPoint.y || 0
391
+ };
392
+ },
393
+ getOutputPoint(transform, layout) {
394
+ const isVertical = FlowLayoutDefault3.isVertical(layout);
395
+ if (transform.collapsed) {
396
+ return transform.inputPoint;
397
+ }
398
+ if (isVertical) {
399
+ return {
400
+ x: transform.pre?.outputPoint.x || 0,
401
+ y: transform.bounds.bottom
402
+ };
403
+ }
404
+ return {
405
+ x: transform.bounds.right,
406
+ y: transform.pre?.outputPoint.y || 0
407
+ };
408
+ }
409
+ };
410
+ function getBranchAdderLabel(transition) {
411
+ const { isVertical } = transition.entity;
412
+ const currentTransform = transition.transform;
413
+ if (currentTransform.collapsed) {
414
+ return [
415
+ {
416
+ type: FlowTransitionLabelEnum3.COLLAPSE_LABEL,
417
+ offset: Point.move(currentTransform.inputPoint, isVertical ? { y: 10 } : { x: 10 }),
418
+ props: {
419
+ activateNode: transition.entity.pre
420
+ }
421
+ }
422
+ ];
423
+ }
424
+ return [
425
+ {
426
+ type: FlowTransitionLabelEnum3.CUSTOM_LABEL,
427
+ renderKey: FlowRendererKey.BRANCH_ADDER,
428
+ offset: Point.move(currentTransform.inputPoint, isVertical ? { y: 10 } : { x: 10 }),
429
+ props: {
430
+ // 激活状态
431
+ activated: transition.entity.getData(FlowNodeRenderData).activated,
432
+ transform: currentTransform,
433
+ // 传给外部使用的 node 信息
434
+ node: currentTransform.originParent?.entity
435
+ }
436
+ }
437
+ ];
438
+ }
439
+
440
+ // src/activities/block-icon.ts
441
+ import { Point as Point2 } from "@flowgram.ai/utils";
442
+ import { DefaultSpacingKey, getDefaultSpacing as getDefaultSpacing3 } from "@flowgram.ai/document";
443
+ import {
444
+ FlowNodeBaseType as FlowNodeBaseType5,
445
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum4
446
+ } from "@flowgram.ai/document";
447
+ var BlockIconRegistry = {
448
+ type: FlowNodeBaseType5.BLOCK_ICON,
449
+ meta: {
450
+ spacing: 20,
451
+ // 占位节点下边偏小
452
+ // 条件分支 icon 默认的高度比较高,在流程里下边有文字
453
+ size: { width: 250, height: 84 }
454
+ },
455
+ /**
456
+ * 是一个占位节点,后续要加上 label 展开收起的图标
457
+ */
458
+ getLabels(transition) {
459
+ const currentTransform = transition.transform;
460
+ const { isVertical } = transition.entity;
461
+ if (transition.entity.parent.collapsedChildren.length <= 1) {
462
+ return [];
463
+ }
464
+ const collapsedSpacing = getDefaultSpacing3(
465
+ transition.entity,
466
+ DefaultSpacingKey.COLLAPSED_SPACING
467
+ );
468
+ return [
469
+ {
470
+ type: FlowTransitionLabelEnum4.COLLAPSE_LABEL,
471
+ offset: Point2.move(
472
+ currentTransform.outputPoint,
473
+ isVertical ? { y: collapsedSpacing } : { x: collapsedSpacing }
474
+ ),
475
+ props: {
476
+ collapseNode: transition.entity.parent,
477
+ activateNode: transition.entity
478
+ }
479
+ }
480
+ ];
481
+ }
482
+ };
483
+
484
+ // src/activities/block-order-icon.ts
485
+ import { Point as Point3 } from "@flowgram.ai/utils";
486
+ import { DefaultSpacingKey as DefaultSpacingKey2, getDefaultSpacing as getDefaultSpacing4 } from "@flowgram.ai/document";
487
+ import {
488
+ FlowNodeBaseType as FlowNodeBaseType6,
489
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum5
490
+ } from "@flowgram.ai/document";
491
+ var BlockOrderIconRegistry = {
492
+ type: FlowNodeBaseType6.BLOCK_ORDER_ICON,
493
+ meta: {
494
+ spacing: 40
495
+ },
496
+ getLabels(transition) {
497
+ const currentTransform = transition.transform;
498
+ const { isVertical } = transition.entity;
499
+ const currentOutput = currentTransform.outputPoint;
500
+ const nextTransform = currentTransform.next;
501
+ const parentTransform = currentTransform.parent;
502
+ if (transition.entity.parent.collapsedChildren.length <= 1) {
503
+ const parentOutput = parentTransform?.outputPoint;
504
+ return [
505
+ {
506
+ offset: parentOutput,
507
+ type: FlowTransitionLabelEnum5.ADDER_LABEL
508
+ }
509
+ ];
510
+ }
511
+ const collapsedSpacing = getDefaultSpacing4(
512
+ transition.entity,
513
+ DefaultSpacingKey2.COLLAPSED_SPACING
514
+ );
515
+ return [
516
+ {
517
+ offset: nextTransform ? Point3.getMiddlePoint(currentOutput, nextTransform.inputPoint) : Point3.move(
518
+ currentOutput,
519
+ isVertical ? { y: collapsedSpacing } : { x: collapsedSpacing }
520
+ ),
521
+ // 收起展开复合按钮
522
+ type: FlowTransitionLabelEnum5.COLLAPSE_ADDER_LABEL,
523
+ props: {
524
+ activateNode: transition.entity,
525
+ collapseNode: transition.entity.parent
526
+ }
527
+ }
528
+ ];
529
+ }
530
+ };
531
+
532
+ // src/activities/start.ts
533
+ import { FlowNodeBaseType as FlowNodeBaseType7 } from "@flowgram.ai/document";
534
+ var StartRegistry = {
535
+ type: FlowNodeBaseType7.START,
536
+ meta: {
537
+ isStart: true,
538
+ draggable: false,
539
+ selectable: false,
540
+ // 触发器等开始节点不能被框选
541
+ deleteDisable: true,
542
+ // 禁止删除
543
+ copyDisable: true,
544
+ // 禁止copy
545
+ addDisable: true
546
+ // 禁止添加
547
+ }
548
+ };
549
+
550
+ // src/activities/try-catch.ts
551
+ import {
552
+ FlowLayoutDefault as FlowLayoutDefault6,
553
+ FlowNodeBaseType as FlowNodeBaseType13
554
+ } from "@flowgram.ai/document";
555
+
556
+ // src/activities/try-catch-extends/catch-block.ts
557
+ import {
558
+ DEFAULT_SPACING as DEFAULT_SPACING3,
559
+ FlowNodeBaseType as FlowNodeBaseType8,
560
+ FlowTransitionLineEnum as FlowTransitionLineEnum2
561
+ } from "@flowgram.ai/document";
562
+ var CatchBlockRegistry = {
563
+ extend: FlowNodeBaseType8.BLOCK,
564
+ type: "catchBlock" /* CATCH_BLOCK */,
565
+ meta: {
566
+ hidden: true,
567
+ spacing: DEFAULT_SPACING3.NULL
568
+ },
569
+ getLines(transition) {
570
+ const { transform } = transition;
571
+ const { isVertical } = transition.entity;
572
+ const parentPoint = transform.parent;
573
+ const { inputPoint, outputPoint } = transform;
574
+ let parentInputPoint;
575
+ if (isVertical) {
576
+ parentInputPoint = {
577
+ x: parentPoint.inputPoint.x,
578
+ y: parentPoint.inputPoint.y - 20 /* CATCH_INLINE_SPACING */
579
+ };
580
+ } else {
581
+ parentInputPoint = {
582
+ x: parentPoint.inputPoint.x - 20 /* CATCH_INLINE_SPACING */,
583
+ y: parentPoint.inputPoint.y
584
+ };
585
+ }
586
+ const lines = [
587
+ {
588
+ type: FlowTransitionLineEnum2.DIVERGE_LINE,
589
+ from: parentInputPoint,
590
+ to: inputPoint
591
+ }
592
+ ];
593
+ if (!transition.isNodeEnd) {
594
+ let mergePoint;
595
+ if (isVertical) {
596
+ mergePoint = {
597
+ x: parentPoint.outputPoint.x,
598
+ y: parentPoint.bounds.bottom
599
+ };
600
+ } else {
601
+ mergePoint = {
602
+ x: parentPoint.bounds.right,
603
+ y: parentPoint.outputPoint.y
604
+ };
605
+ }
606
+ lines.push({
607
+ type: FlowTransitionLineEnum2.MERGE_LINE,
608
+ from: outputPoint,
609
+ to: mergePoint
610
+ });
611
+ }
612
+ return lines;
613
+ },
614
+ getLabels() {
615
+ return [];
616
+ }
617
+ };
618
+
619
+ // src/activities/try-catch-extends/catch-inline-blocks.ts
620
+ import { FlowRendererKey as FlowRendererKey2 } from "@flowgram.ai/renderer";
621
+ import {
622
+ DEFAULT_SPACING as DEFAULT_SPACING4,
623
+ FlowNodeBaseType as FlowNodeBaseType9,
624
+ FlowNodeRenderData as FlowNodeRenderData2,
625
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum6,
626
+ FlowTransitionLineEnum as FlowTransitionLineEnum3,
627
+ FlowLayoutDefault as FlowLayoutDefault4
628
+ } from "@flowgram.ai/document";
629
+ var CatchInlineBlocksRegistry = {
630
+ extend: FlowNodeBaseType9.INLINE_BLOCKS,
631
+ type: "catchInlineBlocks" /* CATCH_INLINE_BLOCKS */,
632
+ meta: {
633
+ spacing: DEFAULT_SPACING4.NULL,
634
+ inlineSpacingPre: DEFAULT_SPACING4.NULL
635
+ // inlineSpacingAfter: DEFAULT_SPACING.NULL,
636
+ },
637
+ getDelta() {
638
+ return void 0;
639
+ },
640
+ getLines(transition) {
641
+ const { transform } = transition;
642
+ const mainInlineBlocks = transform.parent;
643
+ const lines = [
644
+ {
645
+ type: FlowTransitionLineEnum3.DIVERGE_LINE,
646
+ from: mainInlineBlocks.pre.outputPoint,
647
+ to: transform.inputPoint
648
+ }
649
+ ];
650
+ if (!transform.entity.isNodeEnd) {
651
+ lines.push({
652
+ type: FlowTransitionLineEnum3.MERGE_LINE,
653
+ from: transform.outputPoint,
654
+ to: mainInlineBlocks.outputPoint
655
+ });
656
+ }
657
+ return lines;
658
+ },
659
+ getOriginDeltaX(transform) {
660
+ const { firstChild } = transform;
661
+ if (!firstChild) return 0;
662
+ return firstChild.originDeltaX;
663
+ },
664
+ getLabels(transition) {
665
+ const { inputPoint } = transition.transform;
666
+ const { isVertical } = transition.entity;
667
+ const currentTransform = transition.transform;
668
+ const actualInputPoint = {
669
+ x: isVertical ? inputPoint.x : inputPoint.x - 20 /* CATCH_INLINE_SPACING */,
670
+ y: isVertical ? inputPoint.y - 20 /* CATCH_INLINE_SPACING */ : inputPoint.y
671
+ };
672
+ if (currentTransform.collapsed) {
673
+ return [];
674
+ }
675
+ return [
676
+ {
677
+ type: FlowTransitionLabelEnum6.CUSTOM_LABEL,
678
+ renderKey: FlowRendererKey2.BRANCH_ADDER,
679
+ offset: actualInputPoint,
680
+ props: {
681
+ // 激活状态
682
+ activated: transition.entity.getData(FlowNodeRenderData2).activated,
683
+ transform: currentTransform,
684
+ // 传给外部使用的 node 信息
685
+ node: currentTransform.originParent?.entity
686
+ }
687
+ }
688
+ ];
689
+ },
690
+ getInputPoint(transform, layout) {
691
+ const isVertical = FlowLayoutDefault4.isVertical(layout);
692
+ const firstCatchBlock = transform.firstChild;
693
+ if (firstCatchBlock) {
694
+ return firstCatchBlock.inputPoint;
695
+ }
696
+ return isVertical ? transform.bounds.topCenter : transform.bounds.rightCenter;
697
+ },
698
+ getOutputPoint(transform, layout) {
699
+ const isVertical = FlowLayoutDefault4.isVertical(layout);
700
+ if (transform.collapsed) {
701
+ return transform.inputPoint;
702
+ }
703
+ const firstCatchBlock = transform.firstChild;
704
+ if (firstCatchBlock) {
705
+ return isVertical ? {
706
+ x: firstCatchBlock.outputPoint?.x,
707
+ y: transform.bounds.bottom
708
+ } : {
709
+ x: transform.bounds.right,
710
+ y: firstCatchBlock.outputPoint?.y
711
+ };
712
+ }
713
+ return isVertical ? transform.bounds.bottomCenter : transform.bounds.rightCenter;
714
+ }
715
+ };
716
+
717
+ // src/activities/try-catch-extends/main-inline-blocks.ts
718
+ import { FlowRendererKey as FlowRendererKey3, FlowTextKey } from "@flowgram.ai/renderer";
719
+ import {
720
+ DEFAULT_SPACING as DEFAULT_SPACING5,
721
+ FlowNodeBaseType as FlowNodeBaseType10,
722
+ FlowNodeTransformData as FlowNodeTransformData2,
723
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum7,
724
+ FlowTransitionLineEnum as FlowTransitionLineEnum4,
725
+ FlowLayoutDefault as FlowLayoutDefault5
726
+ } from "@flowgram.ai/document";
727
+ var MainInlineBlocksRegistry = {
728
+ extend: FlowNodeBaseType10.INLINE_BLOCKS,
729
+ type: "mainInlineBlocks" /* MAIN_INLINE_BLOCKS */,
730
+ meta: {
731
+ inlineSpacingPre: 20 /* MAIN_INLINE_SPACING_TOP */,
732
+ inlineSpacingAfter: 40 /* MAIN_INLINE_SPACING_BOTTOM */
733
+ },
734
+ getLines(transition) {
735
+ const { transform } = transition;
736
+ const tryBranch = transform.firstChild;
737
+ const lines = [
738
+ {
739
+ type: FlowTransitionLineEnum4.STRAIGHT_LINE,
740
+ from: tryBranch.outputPoint,
741
+ to: transform.originParent.outputPoint
742
+ }
743
+ ];
744
+ return lines;
745
+ },
746
+ getLabels(transition) {
747
+ const { transform } = transition;
748
+ const { isVertical } = transition.entity;
749
+ const catchInlineBlocks = transform.children[1];
750
+ const errLabelX = isVertical ? (transform.parent.outputPoint.x + catchInlineBlocks.inputPoint.x) / 2 : transform.inputPoint.x - 54 /* INLINE_SPACING_TOP */;
751
+ const errLabelY = isVertical ? transform.inputPoint.y - 54 /* INLINE_SPACING_TOP */ : (transform.parent.outputPoint.y + catchInlineBlocks.inputPoint.y) / 2;
752
+ const errorLabelX = errLabelX;
753
+ const errorLabelY = errLabelY;
754
+ return [
755
+ {
756
+ type: FlowTransitionLabelEnum7.TEXT_LABEL,
757
+ renderKey: FlowTextKey.TRY_START_TEXT,
758
+ offset: {
759
+ x: isVertical ? transform.inputPoint.x : transform.inputPoint.x + -20 /* TRY_START_LABEL_DELTA */,
760
+ y: isVertical ? transform.inputPoint.y + -20 /* TRY_START_LABEL_DELTA */ : transform.inputPoint.y
761
+ }
762
+ },
763
+ {
764
+ type: FlowTransitionLabelEnum7.TEXT_LABEL,
765
+ renderKey: FlowTextKey.TRY_END_TEXT,
766
+ offset: {
767
+ x: isVertical ? transform.inputPoint.x : transform.originParent.outputPoint.x + -20 /* TRY_END_LABEL_DELTA */,
768
+ y: isVertical ? transform.originParent.outputPoint.y + -20 /* TRY_END_LABEL_DELTA */ : transform.inputPoint.y
769
+ }
770
+ },
771
+ // 错误分支收起
772
+ {
773
+ type: FlowTransitionLabelEnum7.CUSTOM_LABEL,
774
+ renderKey: FlowRendererKey3.TRY_CATCH_COLLAPSE,
775
+ offset: {
776
+ x: errorLabelX,
777
+ y: errorLabelY
778
+ },
779
+ props: {
780
+ node: transform.lastChild?.entity
781
+ }
782
+ }
783
+ ];
784
+ },
785
+ getInputPoint(transform) {
786
+ const tryBlock = transform.firstChild;
787
+ return tryBlock.inputPoint;
788
+ },
789
+ getOutputPoint(transform, layout) {
790
+ const tryBlock = transform.firstChild;
791
+ const isVertical = FlowLayoutDefault5.isVertical(layout);
792
+ if (isVertical) {
793
+ return {
794
+ x: tryBlock.outputPoint.x,
795
+ y: transform.bounds.bottom + 20 /* CATCH_INLINE_SPACING */
796
+ };
797
+ }
798
+ return {
799
+ x: transform.bounds.right + 20 /* CATCH_INLINE_SPACING */,
800
+ y: tryBlock.outputPoint.y
801
+ };
802
+ },
803
+ getDelta() {
804
+ return void 0;
805
+ },
806
+ getChildDelta(child, layout) {
807
+ const preTransform = child.entity.pre?.getData(FlowNodeTransformData2);
808
+ const isVertical = FlowLayoutDefault5.isVertical(layout);
809
+ if (preTransform) {
810
+ const { localBounds: preBounds } = preTransform;
811
+ let delta = 0;
812
+ if (isVertical) {
813
+ delta = Math.max(
814
+ child.parent.minInlineBlockSpacing,
815
+ -child.originDeltaX + DEFAULT_SPACING5.MARGIN_RIGHT
816
+ );
817
+ } else {
818
+ delta = Math.max(
819
+ child.parent.minInlineBlockSpacing,
820
+ -child.originDeltaY + DEFAULT_SPACING5.MARGIN_RIGHT
821
+ );
822
+ }
823
+ return {
824
+ // 分支只有两个所以这里可以写死间隔宽度
825
+ x: isVertical ? preBounds.right + delta : 0,
826
+ y: isVertical ? 0 : preBounds.bottom + delta
827
+ };
828
+ }
829
+ return {
830
+ x: 0,
831
+ y: 0
832
+ };
833
+ }
834
+ };
835
+
836
+ // src/activities/try-catch-extends/try-block.ts
837
+ import { DEFAULT_SPACING as DEFAULT_SPACING6, FlowNodeBaseType as FlowNodeBaseType11 } from "@flowgram.ai/document";
838
+ var TryBlockRegistry = {
839
+ extend: FlowNodeBaseType11.BLOCK,
840
+ type: "tryBlock" /* TRY_BLOCK */,
841
+ meta: {
842
+ hidden: true,
843
+ spacing: DEFAULT_SPACING6.NULL
844
+ },
845
+ getLines() {
846
+ return [];
847
+ },
848
+ getLabels() {
849
+ return [];
850
+ }
851
+ };
852
+
853
+ // src/activities/try-catch-extends/try-slot.ts
854
+ import { FlowNodeBaseType as FlowNodeBaseType12 } from "@flowgram.ai/document";
855
+ var TrySlotRegistry = {
856
+ extend: FlowNodeBaseType12.EMPTY,
857
+ type: "trySlot" /* TRY_SLOT */
858
+ // getLabels() {
859
+ // return []
860
+ // },
861
+ };
862
+
863
+ // src/activities/try-catch.ts
864
+ var TryCatchRegistry = {
865
+ type: "tryCatch",
866
+ meta: {
867
+ hidden: true,
868
+ inlineSpacingAfter: 0 /* INLINE_SPACING_BOTTOM */
869
+ },
870
+ /**
871
+ * 结构
872
+ * tryCatch
873
+ * - tryCatchIcon
874
+ * - mainInlineBlocks
875
+ * - tryBlock // try 分支
876
+ * - trySlot // 空节点用来占位,try 分支一开始没有节点
877
+ * - catchInlineBlocks
878
+ * - catchBlock // catch 分支 1
879
+ * - blockOrderIcon
880
+ * - node1
881
+ * - catchBlock // catch 分支 2
882
+ * - blockOrderIcon
883
+ * - node 2
884
+ * @param node
885
+ * @param json
886
+ */
887
+ onCreate(node, json) {
888
+ const { document } = node;
889
+ const [tryBlock, ...catchBlocks] = json.blocks || [];
890
+ const addedNodes = [];
891
+ const tryCatchIconNode = document.addNode({
892
+ id: `$tryCatchIcon$${node.id}`,
893
+ type: FlowNodeBaseType13.BLOCK_ICON,
894
+ originParent: node,
895
+ parent: node
896
+ });
897
+ const mainBlockNode = document.addNode({
898
+ id: `$mainInlineBlocks$${node.id}`,
899
+ type: "mainInlineBlocks" /* MAIN_INLINE_BLOCKS */,
900
+ originParent: node,
901
+ parent: node
902
+ });
903
+ const tryBlockNode = document.addNode({
904
+ id: `$tryBlock$${tryBlock.id}`,
905
+ type: "tryBlock" /* TRY_BLOCK */,
906
+ originParent: node,
907
+ parent: mainBlockNode
908
+ });
909
+ const trySlotNode = document.addNode({
910
+ id: tryBlock.id,
911
+ type: "trySlot" /* TRY_SLOT */,
912
+ // 占位节点
913
+ originParent: node,
914
+ parent: tryBlockNode
915
+ });
916
+ const catchInlineBlocksNode = document.addNode({
917
+ id: `$catchInlineBlocks$${node.id}`,
918
+ type: "catchInlineBlocks" /* CATCH_INLINE_BLOCKS */,
919
+ originParent: node,
920
+ parent: mainBlockNode
921
+ });
922
+ addedNodes.push(
923
+ tryCatchIconNode,
924
+ mainBlockNode,
925
+ tryBlockNode,
926
+ trySlotNode,
927
+ catchInlineBlocksNode
928
+ );
929
+ catchBlocks.forEach((blockData) => {
930
+ node.document.addBlock(node, blockData, addedNodes);
931
+ });
932
+ return addedNodes;
933
+ },
934
+ /**
935
+ * 添加 catch 分支
936
+ * @param node
937
+ * @param blockData
938
+ * @param addedNodes
939
+ */
940
+ onBlockChildCreate(node, blockData, addedNodes) {
941
+ const parent = node.document.getNode(`$catchInlineBlocks$${node.id}`);
942
+ const block = node.document.addNode({
943
+ id: blockData.id,
944
+ type: "catchBlock" /* CATCH_BLOCK */,
945
+ originParent: node,
946
+ parent
947
+ });
948
+ const blockOrderIcon = node.document.addNode({
949
+ id: `$blockOrderIcon$${blockData.id}`,
950
+ type: FlowNodeBaseType13.BLOCK_ORDER_ICON,
951
+ originParent: node,
952
+ parent: block
953
+ });
954
+ if (blockData.blocks) {
955
+ node.document.addBlocksAsChildren(block, blockData.blocks || [], addedNodes);
956
+ }
957
+ addedNodes?.push(block, blockOrderIcon);
958
+ return block;
959
+ },
960
+ getInputPoint(transform) {
961
+ const tryCatchIcon = transform.firstChild;
962
+ return tryCatchIcon.inputPoint;
963
+ },
964
+ getOutputPoint(transform, layout) {
965
+ const isVertical = FlowLayoutDefault6.isVertical(layout);
966
+ const tryCatchIcon = transform.firstChild;
967
+ if (isVertical) {
968
+ return {
969
+ x: tryCatchIcon.inputPoint.x,
970
+ y: transform.bounds.bottom
971
+ };
972
+ }
973
+ return {
974
+ x: transform.bounds.right,
975
+ y: tryCatchIcon.inputPoint.y
976
+ };
977
+ },
978
+ /**
979
+ * tryCatch 子节点配置
980
+ */
981
+ extendChildRegistries: [
982
+ /**
983
+ * icon 节点
984
+ */
985
+ {
986
+ type: FlowNodeBaseType13.BLOCK_ICON,
987
+ meta: {
988
+ spacing: 54 /* INLINE_SPACING_TOP */
989
+ },
990
+ getLabels() {
991
+ return [];
992
+ }
993
+ },
994
+ MainInlineBlocksRegistry,
995
+ CatchInlineBlocksRegistry,
996
+ TryBlockRegistry,
997
+ CatchBlockRegistry,
998
+ TrySlotRegistry
999
+ ]
1000
+ };
1001
+
1002
+ // src/activities/loop.ts
1003
+ import { Point as Point5 } from "@flowgram.ai/utils";
1004
+ import { FlowTextKey as FlowTextKey3 } from "@flowgram.ai/renderer";
1005
+ import {
1006
+ FlowNodeBaseType as FlowNodeBaseType15,
1007
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum10,
1008
+ getDefaultSpacing as getDefaultSpacing6,
1009
+ ConstantKeys as ConstantKeys5
1010
+ } from "@flowgram.ai/document";
1011
+
1012
+ // src/activities/loop-extends/constants.ts
1013
+ import { ConstantKeys as ConstantKeys3 } from "@flowgram.ai/document";
1014
+ var LoopSpacings = {
1015
+ SPACING: 16,
1016
+ // 距离下面节点距离
1017
+ COLLAPSE_INLINE_SPACING_BOTTOM: 60,
1018
+ // 距离下面节点距离
1019
+ [ConstantKeys3.INLINE_SPACING_BOTTOM]: 48,
1020
+ // 下边空白
1021
+ MIN_INLINE_BLOCK_SPACING: 280,
1022
+ // 最小循环圈宽度
1023
+ HORIZONTAL_MIN_INLINE_BLOCK_SPACING: 180,
1024
+ // 水平布局下的最小循环圈高度
1025
+ LEFT_EMPTY_BLOCK_WIDTH: 80,
1026
+ // 左边空分支宽度
1027
+ EMPTY_BRANCH_SPACING: 20,
1028
+ // 左边空分支宽度
1029
+ LOOP_BLOCK_ICON_SPACING: 13,
1030
+ // inlineBlocks 的 inlineBottom
1031
+ [ConstantKeys3.INLINE_BLOCKS_INLINE_SPACING_BOTTOM]: 23,
1032
+ // inlineBlocks 的 inlineBottom
1033
+ INLINE_BLOCKS_INLINE_SPACING_TOP: 30
1034
+ // inlineBlocks 的 inlineTop
1035
+ };
1036
+
1037
+ // src/activities/loop-extends/loop-left-empty-block.ts
1038
+ var LoopLeftEmptyBlockRegistry = {
1039
+ type: "loopLeftEmptyBlock" /* LOOP_LEFT_EMPTY_BLOCK */,
1040
+ meta: {
1041
+ inlineSpacingAfter: 0,
1042
+ spacing: 0,
1043
+ size: {
1044
+ width: LoopSpacings.LEFT_EMPTY_BLOCK_WIDTH,
1045
+ height: 0
1046
+ }
1047
+ },
1048
+ onAfterUpdateLocalTransform(transform) {
1049
+ if (transform.entity.isVertical) {
1050
+ transform.data.size = {
1051
+ width: LoopSpacings.LEFT_EMPTY_BLOCK_WIDTH,
1052
+ height: 0
1053
+ };
1054
+ } else {
1055
+ transform.data.size = {
1056
+ width: 0,
1057
+ height: LoopSpacings.LEFT_EMPTY_BLOCK_WIDTH
1058
+ };
1059
+ }
1060
+ transform.transform.update({
1061
+ size: transform.data.size
1062
+ });
1063
+ },
1064
+ getLines() {
1065
+ return [];
1066
+ },
1067
+ getLabels() {
1068
+ return [];
1069
+ }
1070
+ };
1071
+
1072
+ // src/activities/loop-extends/loop-right-empty-block.ts
1073
+ var LoopRightEmptyBlockRegistry = {
1074
+ ...BlockRegistry,
1075
+ type: "loopRightEmptyBlock" /* LOOP_RIGHT_EMPTY_BLOCK */,
1076
+ meta: {
1077
+ ...BlockRegistry.meta,
1078
+ inlineSpacingAfter: 0
1079
+ }
1080
+ };
1081
+
1082
+ // src/activities/loop-extends/loop-empty-branch.ts
1083
+ import { FlowTransitionLabelEnum as FlowTransitionLabelEnum8 } from "@flowgram.ai/document";
1084
+ var LoopEmptyBranchRegistry = {
1085
+ type: "loopEmptyBranch" /* LOOP_EMPTY_BRANCH */,
1086
+ meta: {
1087
+ inlineSpacingAfter: 0,
1088
+ spacing: LoopSpacings.EMPTY_BRANCH_SPACING,
1089
+ size: {
1090
+ width: 100,
1091
+ height: 0
1092
+ }
1093
+ },
1094
+ getLabels(transition) {
1095
+ const { isVertical } = transition.entity;
1096
+ const currentTransform = transition.transform;
1097
+ if (isVertical) {
1098
+ return [
1099
+ {
1100
+ type: FlowTransitionLabelEnum8.ADDER_LABEL,
1101
+ offset: {
1102
+ x: currentTransform.inputPoint.x,
1103
+ y: currentTransform.bounds.center.y + 8
1104
+ // 右边空节点
1105
+ }
1106
+ }
1107
+ ];
1108
+ }
1109
+ return [
1110
+ {
1111
+ type: FlowTransitionLabelEnum8.ADDER_LABEL,
1112
+ offset: {
1113
+ x: currentTransform.bounds.center.x + 8,
1114
+ y: currentTransform.inputPoint.y
1115
+ }
1116
+ }
1117
+ ];
1118
+ },
1119
+ onAfterUpdateLocalTransform(transform) {
1120
+ if (transform.entity.isVertical) {
1121
+ transform.data.size = {
1122
+ width: 100,
1123
+ height: 0
1124
+ };
1125
+ } else {
1126
+ transform.data.size = {
1127
+ width: 0,
1128
+ height: 100
1129
+ };
1130
+ }
1131
+ transform.transform.update({
1132
+ size: transform.data.size
1133
+ });
1134
+ }
1135
+ };
1136
+
1137
+ // src/activities/loop-extends/loop-inline-blocks.ts
1138
+ import { Point as Point4 } from "@flowgram.ai/utils";
1139
+ import { FlowTextKey as FlowTextKey2 } from "@flowgram.ai/renderer";
1140
+ import {
1141
+ FlowNodeBaseType as FlowNodeBaseType14,
1142
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum9,
1143
+ FlowTransitionLineEnum as FlowTransitionLineEnum5,
1144
+ getDefaultSpacing as getDefaultSpacing5,
1145
+ ConstantKeys as ConstantKeys4
1146
+ } from "@flowgram.ai/document";
1147
+ var LoopInlineBlocksNodeRegistry = {
1148
+ type: FlowNodeBaseType14.INLINE_BLOCKS,
1149
+ meta: {
1150
+ inlineSpacingPre: (node) => {
1151
+ const inlineBlocksInlineSpacingTop = getDefaultSpacing5(
1152
+ node.entity,
1153
+ ConstantKeys4.INLINE_BLOCKS_INLINE_SPACING_TOP,
1154
+ LoopSpacings.INLINE_BLOCKS_INLINE_SPACING_TOP
1155
+ );
1156
+ return inlineBlocksInlineSpacingTop;
1157
+ },
1158
+ inlineSpacingAfter: (node) => {
1159
+ const inlineBlocksInlineSpacingBottom = getDefaultSpacing5(
1160
+ node.entity,
1161
+ ConstantKeys4.INLINE_BLOCKS_INLINE_SPACING_BOTTOM,
1162
+ LoopSpacings.INLINE_BLOCKS_INLINE_SPACING_BOTTOM
1163
+ );
1164
+ return inlineBlocksInlineSpacingBottom;
1165
+ },
1166
+ minInlineBlockSpacing: (node) => node.entity.isVertical ? LoopSpacings.MIN_INLINE_BLOCK_SPACING : LoopSpacings.HORIZONTAL_MIN_INLINE_BLOCK_SPACING
1167
+ },
1168
+ getLines(transition) {
1169
+ const currentTransform = transition.transform;
1170
+ const parentTransform = currentTransform.parent;
1171
+ const { isVertical } = transition.entity;
1172
+ const lines = [
1173
+ // 循环结束线
1174
+ {
1175
+ type: FlowTransitionLineEnum5.STRAIGHT_LINE,
1176
+ from: currentTransform.outputPoint,
1177
+ to: parentTransform.outputPoint
1178
+ }
1179
+ ];
1180
+ if (currentTransform.collapsed) {
1181
+ return lines;
1182
+ }
1183
+ const [leftBlockTransform] = currentTransform.children;
1184
+ return [
1185
+ ...lines,
1186
+ // 循环回撤线 - 1 分成两段可以被 viewport 识别出矩阵区域
1187
+ {
1188
+ type: FlowTransitionLineEnum5.ROUNDED_LINE,
1189
+ from: currentTransform.outputPoint,
1190
+ to: leftBlockTransform.outputPoint,
1191
+ vertices: [
1192
+ isVertical ? { x: leftBlockTransform.inputPoint.x, y: currentTransform.bounds.bottom } : { x: currentTransform.bounds.right, y: leftBlockTransform.inputPoint.y }
1193
+ ]
1194
+ },
1195
+ // 循环回撤线 - 2
1196
+ {
1197
+ type: FlowTransitionLineEnum5.ROUNDED_LINE,
1198
+ from: leftBlockTransform.outputPoint,
1199
+ to: Point4.move(
1200
+ currentTransform.inputPoint,
1201
+ isVertical ? { x: -12, y: 10 } : { x: 10, y: -12 }
1202
+ ),
1203
+ vertices: [
1204
+ isVertical ? { x: leftBlockTransform.inputPoint.x, y: currentTransform.bounds.top + 10 } : { x: currentTransform.bounds.left + 10, y: leftBlockTransform.inputPoint.y }
1205
+ ],
1206
+ arrow: true
1207
+ }
1208
+ ];
1209
+ },
1210
+ getLabels(transition) {
1211
+ const currentTransform = transition.transform;
1212
+ const { isVertical } = transition.entity;
1213
+ const labels = [];
1214
+ if (currentTransform.collapsed) {
1215
+ return labels;
1216
+ }
1217
+ const leftBlockTransform = currentTransform.children[0];
1218
+ const rightBlockTransform = currentTransform.children[1];
1219
+ if (transition.entity.originParent?.id.startsWith("while_")) {
1220
+ labels.push({
1221
+ type: FlowTransitionLabelEnum9.TEXT_LABEL,
1222
+ renderKey: FlowTextKey2.LOOP_WHILE_TEXT,
1223
+ rotate: isVertical ? "" : "-90deg",
1224
+ offset: isVertical ? {
1225
+ x: (currentTransform.inputPoint.x + rightBlockTransform.inputPoint.x) / 2,
1226
+ y: currentTransform.inputPoint.y + 10
1227
+ } : {
1228
+ x: currentTransform.inputPoint.x + 10,
1229
+ y: (currentTransform.inputPoint.y + rightBlockTransform.inputPoint.y) / 2
1230
+ }
1231
+ });
1232
+ } else {
1233
+ labels.push({
1234
+ type: FlowTransitionLabelEnum9.TEXT_LABEL,
1235
+ renderKey: FlowTextKey2.LOOP_TRAVERSE_TEXT,
1236
+ // rotate: isVertical ? '' : '-90deg',
1237
+ offset: isVertical ? { x: leftBlockTransform.inputPoint.x, y: currentTransform.bounds.center.y + 5 } : { x: currentTransform.bounds.center.x + 5, y: leftBlockTransform.inputPoint.y }
1238
+ });
1239
+ }
1240
+ return labels;
1241
+ }
1242
+ };
1243
+
1244
+ // src/activities/loop.ts
1245
+ var LoopRegistry = {
1246
+ type: "loop",
1247
+ meta: {
1248
+ hidden: true,
1249
+ inlineSpacingAfter: (node) => {
1250
+ if (node.collapsed) {
1251
+ return LoopSpacings.COLLAPSE_INLINE_SPACING_BOTTOM;
1252
+ }
1253
+ const inlineSpacingBottom = getDefaultSpacing6(
1254
+ node.entity,
1255
+ ConstantKeys5.INLINE_SPACING_BOTTOM,
1256
+ LoopSpacings.INLINE_SPACING_BOTTOM
1257
+ );
1258
+ return inlineSpacingBottom;
1259
+ },
1260
+ spacing: LoopSpacings.SPACING
1261
+ },
1262
+ /**
1263
+ * - loopNode
1264
+ * - loopBlockIcon
1265
+ * - loopInlineBlocks
1266
+ * - loopEmptyBlock 左侧占位区域
1267
+ * - loopBlock
1268
+ * - xxx
1269
+ * - xxx
1270
+ * @param node
1271
+ * @param json
1272
+ */
1273
+ onCreate(node, json) {
1274
+ const { document } = node;
1275
+ const loopBlocks = json.blocks || [];
1276
+ const loopIconNode = document.addNode({
1277
+ id: `$blockIcon$${node.id}`,
1278
+ type: FlowNodeBaseType15.BLOCK_ICON,
1279
+ originParent: node,
1280
+ parent: node
1281
+ });
1282
+ const loopInlineBlocks = document.addNode({
1283
+ id: `$inlineBlocks$${node.id}`,
1284
+ hidden: true,
1285
+ type: FlowNodeBaseType15.INLINE_BLOCKS,
1286
+ originParent: node,
1287
+ parent: node
1288
+ });
1289
+ const loopEmptyBlockNode = document.addNode({
1290
+ id: `$loopLeftEmpty$${node.id}`,
1291
+ hidden: true,
1292
+ type: "loopLeftEmptyBlock" /* LOOP_LEFT_EMPTY_BLOCK */,
1293
+ originParent: node,
1294
+ parent: loopInlineBlocks
1295
+ });
1296
+ const loopBlockNode = document.addNode({
1297
+ id: `$block$${node.id}`,
1298
+ hidden: true,
1299
+ type: FlowNodeBaseType15.BLOCK,
1300
+ // : LoopTypeEnum.LOOP_RIGHT_EMPTY_BLOCK,
1301
+ originParent: node,
1302
+ parent: loopInlineBlocks
1303
+ });
1304
+ const loopBranch = document.addNode({
1305
+ id: `$loopRightEmpty$${node.id}`,
1306
+ hidden: true,
1307
+ type: "loopEmptyBranch" /* LOOP_EMPTY_BRANCH */,
1308
+ originParent: node,
1309
+ parent: loopBlockNode
1310
+ });
1311
+ const otherNodes = [];
1312
+ loopBlocks.forEach(
1313
+ (b) => document.addNode(
1314
+ {
1315
+ ...b,
1316
+ type: b.type,
1317
+ parent: loopBlockNode
1318
+ },
1319
+ otherNodes
1320
+ )
1321
+ );
1322
+ return [
1323
+ loopIconNode,
1324
+ loopEmptyBlockNode,
1325
+ loopInlineBlocks,
1326
+ loopBlockNode,
1327
+ loopBranch,
1328
+ ...otherNodes
1329
+ ];
1330
+ },
1331
+ getLabels(transition) {
1332
+ const currentTransform = transition.transform;
1333
+ const { isVertical } = transition.entity;
1334
+ return [
1335
+ // 循环结束
1336
+ {
1337
+ type: FlowTransitionLabelEnum10.TEXT_LABEL,
1338
+ renderKey: FlowTextKey3.LOOP_END_TEXT,
1339
+ // 循环 label 垂直样式展示,而非 rotate 旋转文案
1340
+ props: isVertical ? void 0 : {
1341
+ style: {
1342
+ maxWidth: "20px",
1343
+ lineHeight: "12px",
1344
+ whiteSpace: "pre-wrap"
1345
+ }
1346
+ },
1347
+ offset: Point5.move(currentTransform.outputPoint, isVertical ? { y: -26 } : { x: -26 })
1348
+ },
1349
+ {
1350
+ type: FlowTransitionLabelEnum10.ADDER_LABEL,
1351
+ offset: currentTransform.outputPoint
1352
+ }
1353
+ ];
1354
+ },
1355
+ // 和前序节点对齐
1356
+ getInputPoint(transform) {
1357
+ const { isVertical } = transform.entity;
1358
+ if (isVertical) {
1359
+ return {
1360
+ x: transform.pre?.outputPoint.x || transform.firstChild?.outputPoint.x || 0,
1361
+ y: transform.bounds.top
1362
+ };
1363
+ }
1364
+ return {
1365
+ x: transform.bounds.left,
1366
+ y: transform.pre?.outputPoint.y || transform.firstChild?.outputPoint.y || 0
1367
+ };
1368
+ },
1369
+ getOutputPoint(transform) {
1370
+ const { isVertical } = transform.entity;
1371
+ if (isVertical) {
1372
+ return {
1373
+ x: transform.pre?.outputPoint.x || transform.firstChild?.outputPoint.x || 0,
1374
+ y: transform.bounds.bottom
1375
+ };
1376
+ }
1377
+ return {
1378
+ x: transform.bounds.right,
1379
+ y: transform.pre?.outputPoint.y || transform.firstChild?.outputPoint.y || 0
1380
+ };
1381
+ },
1382
+ extendChildRegistries: [
1383
+ {
1384
+ type: FlowNodeBaseType15.BLOCK_ICON,
1385
+ meta: {
1386
+ spacing: LoopSpacings.LOOP_BLOCK_ICON_SPACING
1387
+ }
1388
+ },
1389
+ LoopLeftEmptyBlockRegistry,
1390
+ LoopEmptyBranchRegistry,
1391
+ LoopRightEmptyBlockRegistry,
1392
+ LoopInlineBlocksNodeRegistry
1393
+ ],
1394
+ addChild(node, json, options = {}) {
1395
+ const { index } = options;
1396
+ const document = node.document;
1397
+ return document.addNode({
1398
+ ...json,
1399
+ ...options,
1400
+ parent: document.getNode(`$block$${node.id}`),
1401
+ index: typeof index === "number" ? index + 1 : void 0
1402
+ });
1403
+ }
1404
+ };
1405
+
1406
+ // src/activities/root.ts
1407
+ import { DEFAULT_SPACING as DEFAULT_SPACING7, FlowNodeBaseType as FlowNodeBaseType16 } from "@flowgram.ai/document";
1408
+ var RootRegistry = {
1409
+ type: FlowNodeBaseType16.ROOT,
1410
+ meta: {
1411
+ spacing: DEFAULT_SPACING7.NULL,
1412
+ hidden: true
1413
+ },
1414
+ getInputPoint(transform) {
1415
+ return transform.firstChild?.inputPoint || transform.bounds.topCenter;
1416
+ },
1417
+ getOutputPoint(transform) {
1418
+ return transform.firstChild?.outputPoint || transform.bounds.bottomCenter;
1419
+ }
1420
+ };
1421
+
1422
+ // src/activities/empty.ts
1423
+ import {
1424
+ FlowNodeBaseType as FlowNodeBaseType17,
1425
+ FlowTransitionLabelEnum as FlowTransitionLabelEnum11,
1426
+ ConstantKeys as ConstantKeys6,
1427
+ getDefaultSpacing as getDefaultSpacing7
1428
+ } from "@flowgram.ai/document";
1429
+ var EmptyRegistry = {
1430
+ type: FlowNodeBaseType17.EMPTY,
1431
+ meta: {
1432
+ spacing: (node) => {
1433
+ const spacing = getDefaultSpacing7(node.entity, ConstantKeys6.NODE_SPACING);
1434
+ return spacing / 2;
1435
+ },
1436
+ size: { width: 0, height: 0 },
1437
+ hidden: true
1438
+ },
1439
+ getLabels(transition) {
1440
+ return [
1441
+ {
1442
+ offset: transition.transform.bounds,
1443
+ type: FlowTransitionLabelEnum11.ADDER_LABEL
1444
+ }
1445
+ ];
1446
+ }
1447
+ };
1448
+
1449
+ // src/flow-registers.ts
1450
+ var FlowRegisters = class {
1451
+ /**
1452
+ * 注册数据层
1453
+ * @param document
1454
+ */
1455
+ registerDocument(document) {
1456
+ document.registerFlowNodes(
1457
+ RootRegistry,
1458
+ // 根节点
1459
+ StartRegistry,
1460
+ // 开始节点
1461
+ DynamicSplitRegistry,
1462
+ // 动态分支(并行、排他)
1463
+ StaticSplitRegistry,
1464
+ // 静态分支(审批)
1465
+ BlockRegistry,
1466
+ // 单条 block 注册
1467
+ InlineBlocksRegistry,
1468
+ // 多个 block 组成的 block 列表
1469
+ BlockIconRegistry,
1470
+ // icon 节点,如条件分支的菱形图标
1471
+ BlockOrderIconRegistry,
1472
+ // 带顺序的图标节点,一般为 block 第一个分支节点
1473
+ TryCatchRegistry,
1474
+ // TryCatch
1475
+ EndRegistry,
1476
+ // 结束节点
1477
+ LoopRegistry,
1478
+ // 循环节点
1479
+ EmptyRegistry
1480
+ // 占位节点
1481
+ );
1482
+ document.registerNodeDatas(
1483
+ FlowNodeRenderData3,
1484
+ // 渲染节点相关数据
1485
+ FlowNodeTransitionData,
1486
+ // 线条绘制数据
1487
+ FlowNodeTransformData3
1488
+ // 坐标计算数据
1489
+ );
1490
+ }
1491
+ /**
1492
+ * 注册渲染层
1493
+ * @param renderer
1494
+ */
1495
+ registerRenderer(renderer) {
1496
+ renderer.registerLayers(
1497
+ FlowNodesTransformLayer,
1498
+ // 节点位置渲染
1499
+ FlowNodesContentLayer,
1500
+ // 节点内容渲染
1501
+ FlowLinesLayer,
1502
+ // 线条渲染
1503
+ FlowLabelsLayer,
1504
+ // Label 渲染
1505
+ PlaygroundLayer,
1506
+ // 画布基础层,提供缩放、手势等能力
1507
+ FlowScrollLimitLayer,
1508
+ // 控制滚动范围
1509
+ FlowScrollBarLayer
1510
+ // 滚动条
1511
+ );
1512
+ }
1513
+ /**
1514
+ * 画布开始渲染 (hook)
1515
+ */
1516
+ onReady() {
1517
+ }
1518
+ /**
1519
+ * 画布销毁 (hook)
1520
+ */
1521
+ onDispose() {
1522
+ }
1523
+ };
1524
+ FlowRegisters = __decorateClass([
1525
+ injectable()
1526
+ ], FlowRegisters);
1527
+
1528
+ // src/fixed-layout-container-module.ts
1529
+ var FixedLayoutContainerModule = new ContainerModule((bind) => {
1530
+ bindContributions(bind, FlowRegisters, [
1531
+ FlowDocumentContribution,
1532
+ FlowRendererContribution,
1533
+ PlaygroundContribution
1534
+ ]);
1535
+ });
1536
+
1537
+ // src/index.ts
1538
+ var FixedLayoutRegistries = {
1539
+ BlockIconRegistry,
1540
+ BlockOrderIconRegistry,
1541
+ BlockRegistry,
1542
+ DynamicSplitRegistry,
1543
+ EmptyRegistry,
1544
+ LoopRegistry,
1545
+ StaticSplitRegistry,
1546
+ TryCatchRegistry,
1547
+ StartRegistry,
1548
+ RootRegistry
1549
+ };
1550
+ export {
1551
+ FixedLayoutContainerModule,
1552
+ FixedLayoutRegistries
1553
+ };
1554
+ //# sourceMappingURL=index.js.map