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