@flowgram-vue/document 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +3233 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1728 -0
  5. package/dist/index.js +3199 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +61 -0
  8. package/src/datas/flow-node-render-data.ts +227 -0
  9. package/src/datas/flow-node-transform-data.ts +337 -0
  10. package/src/datas/flow-node-transition-data.ts +182 -0
  11. package/src/datas/index.ts +8 -0
  12. package/src/entities/flow-document-transformer-entity.ts +125 -0
  13. package/src/entities/flow-node-entity.ts +415 -0
  14. package/src/entities/flow-renderer-state-entity.ts +127 -0
  15. package/src/entities/index.ts +8 -0
  16. package/src/flow-document-config.ts +42 -0
  17. package/src/flow-document-container-module.ts +33 -0
  18. package/src/flow-document-contribution.ts +22 -0
  19. package/src/flow-document-options.ts +79 -0
  20. package/src/flow-document.ts +766 -0
  21. package/src/flow-render-tree.ts +236 -0
  22. package/src/flow-virtual-tree.ts +244 -0
  23. package/src/index.ts +16 -0
  24. package/src/layout/horizontal-fixed-layout.ts +198 -0
  25. package/src/layout/index.ts +7 -0
  26. package/src/layout/vertical-fixed-layout.ts +198 -0
  27. package/src/services/flow-drag-service.ts +211 -0
  28. package/src/services/flow-group-service/flow-group-controller.ts +120 -0
  29. package/src/services/flow-group-service/flow-group-service.ts +107 -0
  30. package/src/services/flow-group-service/flow-group-utils.ts +104 -0
  31. package/src/services/flow-group-service/index.ts +7 -0
  32. package/src/services/flow-operation-base-service.ts +333 -0
  33. package/src/services/index.ts +8 -0
  34. package/src/typings/flow-group.ts +8 -0
  35. package/src/typings/flow-layout.ts +72 -0
  36. package/src/typings/flow-node-register.ts +356 -0
  37. package/src/typings/flow-operation.ts +312 -0
  38. package/src/typings/flow-transition.ts +104 -0
  39. package/src/typings/flow.ts +70 -0
  40. package/src/typings/index.ts +11 -0
  41. package/src/utils/get-default-spacing.ts +21 -0
  42. package/src/utils/index.ts +6 -0
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { type IPoint } from '@flowgram-vue/utils';
7
+
8
+ import { type FlowNodeEntity } from '../entities';
9
+ import { type LABEL_SIDE_TYPE } from './flow-node-register';
10
+
11
+ // 内置几种线条
12
+ export enum FlowTransitionLineEnum {
13
+ STRAIGHT_LINE, // 直线
14
+ DIVERGE_LINE, // 分支线 (一种 ROUNDED_LINE)
15
+ MERGE_LINE, // 汇聚线 (一种 ROUNDED_LINE)
16
+ ROUNDED_LINE, // 自定义圆角转弯线
17
+ CUSTOM_LINE, // 自定义,用于处理循环节点等自定义线条
18
+ DRAGGING_LINE, // 分支拖拽场景渲染的线条
19
+ }
20
+
21
+ export interface Vertex extends IPoint {
22
+ radiusX?: number;
23
+ radiusY?: number;
24
+ // 圆弧出入点位置移动
25
+ moveX?: number;
26
+ moveY?: number;
27
+ /**
28
+ * Strategy for handling arc curvature when space is insufficient, defaults to compress
29
+ */
30
+ radiusOverflow?: 'compress' | 'truncate';
31
+ }
32
+
33
+ export interface FlowTransitionLine {
34
+ type: FlowTransitionLineEnum;
35
+ from: IPoint;
36
+ to: IPoint;
37
+ vertices?: Vertex[]; // 自定义圆角转弯线需要转弯的拐点
38
+ arrow?: boolean; // 是否有箭头
39
+ renderKey?: string; // 只有自定义线条需要
40
+ isHorizontal?: boolean; // 是否为水平布局
41
+ isDraggingLine?: boolean; // 是否是拖拽线条
42
+ activated?: boolean; // 是否激活态
43
+ side?: LABEL_SIDE_TYPE; // 区分是否分支前缀线条
44
+ style?: Record<string, string | number | undefined>;
45
+ lineId?: string;
46
+ }
47
+
48
+ // 内置几种标签
49
+ export enum FlowTransitionLabelEnum {
50
+ ADDER_LABEL, // 添加按钮
51
+ TEXT_LABEL, // 文本标签
52
+ COLLAPSE_LABEL, // 复合节点收起的展开标签
53
+ COLLAPSE_ADDER_LABEL, // 复合节点收起 + 加号复合标签
54
+ CUSTOM_LABEL, // 自定义,用于处理循环节点等自定义标签
55
+ BRANCH_DRAGGING_LABEL, // 分支拖拽场景下的 label
56
+ }
57
+
58
+ export interface FlowTransitionLabel {
59
+ type: FlowTransitionLabelEnum;
60
+ // type === 'CUSTOM_LABEL'需要配置的数据
61
+ renderKey?: string;
62
+ offset: IPoint; // 位置
63
+ width?: number; // 宽度
64
+ rotate?: string; // 循环, 如 '60deg'
65
+ /**
66
+ * Anchor point for positioning, relative to the label's bounding box
67
+ * 重心偏移量,相对于标签边界框
68
+ *
69
+ * Format: [x, y] / 格式:[x, y]
70
+ * Default Value: [0.5, 0.5] indicates center / 默认值:[0.5, 0.5] 表示居中
71
+ */
72
+ origin?: [number, number];
73
+ props?: Record<string, any>;
74
+ labelId?: string;
75
+ }
76
+
77
+ export interface AdderProps {
78
+ node: FlowNodeEntity; // 实际挂载 label 的节点
79
+ from: FlowNodeEntity; // 边起始点在哪个节点
80
+ to: FlowNodeEntity; // 边终点在哪个节点
81
+ renderTo: FlowNodeEntity; // 实际渲染(renderTree)边终点在哪个节点
82
+ [key: string]: any;
83
+ }
84
+
85
+ export interface CollapseProps {
86
+ node: FlowNodeEntity; // 实际挂载 label 的节点
87
+ collapseNode: FlowNodeEntity; // 要展开收起的节点,默认为 node
88
+ activateNode?: FlowNodeEntity; // 设置获取 label 激活状态的节点
89
+ forceVisible?: boolean; // 是否强制显示
90
+ [key: string]: any;
91
+ }
92
+
93
+ export interface CustomLabelProps {
94
+ node: FlowNodeEntity; // 实际挂载 label 的节点
95
+ [key: string]: any;
96
+ }
97
+
98
+ export interface CollapseAdderProps extends AdderProps, CollapseProps {
99
+ [key: string]: any;
100
+ }
101
+
102
+ export interface DragNodeProps {
103
+ node: FlowNodeEntity; // 实际挂载 label 的节点
104
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { FlowNodeEntity } from '../entities';
7
+ import { type FlowNodeMeta } from './flow-node-register';
8
+
9
+ export type FlowNodeType = string | number;
10
+
11
+ /**
12
+ * Flow node json data
13
+ */
14
+ export interface FlowNodeJSON {
15
+ id: string;
16
+ type?: FlowNodeBaseType | FlowNodeSplitType | FlowNodeType; // 如果缺省 则 为 block
17
+ data?: Record<string, any>; // 节点额外扩展的内容
18
+ meta?: FlowNodeMeta;
19
+ blocks?: FlowNodeJSON[]; // 子节点
20
+ }
21
+
22
+ export type FlowDocumentJSON = {
23
+ nodes: FlowNodeJSON[];
24
+ };
25
+
26
+ export enum FlowNodeBaseType {
27
+ START = 'start', // 开始节点
28
+ DEFAULT = 'default', // 默认节点类型
29
+ ROOT = 'root', // 根节点
30
+ EMPTY = 'empty', // 空节点,宽和高为 0
31
+ INLINE_BLOCKS = 'inlineBlocks', // 所有块合并为 InlineBlocks
32
+ BLOCK_ICON = 'blockIcon', // 图标节点,如条件分支的头部的 菱形图标
33
+ BLOCK = 'block', // 块节点
34
+ BLOCK_ORDER_ICON = 'blockOrderIcon', // 带顺序的图标节点,一般为 block 第一个分支节点
35
+ GROUP = 'group', // 分组节点
36
+ END = 'end', // 结束节点
37
+ BREAK = 'break', // 分支结束
38
+ CONDITION = 'condition', // 可以连接多条线的条件判断节点,目前只支持横向布局
39
+ SUB_CANVAS = 'subCanvas', // 自由布局子画布
40
+ MULTI_INPUTS = 'multiInputs', // 多输入
41
+ MULTI_OUTPUTS = 'multiOutputs', // 多输出
42
+ INPUT = 'input', // 输入节点
43
+ OUTPUT = 'output', // 输出节点
44
+ SLOT = 'slot', // 插槽节点
45
+ SLOT_BLOCK = 'slotBlock', // 插槽子节点
46
+ }
47
+
48
+ export enum FlowNodeSplitType {
49
+ SIMPLE_SPLIT = 'simpleSplit', // 无 BlockOrderIcon
50
+ DYNAMIC_SPLIT = 'dynamicSplit', // 动态分支
51
+ STATIC_SPLIT = 'staticSplit', // 静态分支
52
+ }
53
+
54
+ export enum FlowDocumentConfigEnum {
55
+ // 结束节点拖拽分支逻辑
56
+ END_NODES_REFINE_BRANCH = 'END_NODES_REFINE_BRANCH',
57
+ }
58
+
59
+ export const FLOW_DEFAULT_HIDDEN_TYPES: FlowNodeType[] = [
60
+ FlowNodeBaseType.ROOT,
61
+ FlowNodeBaseType.INLINE_BLOCKS,
62
+ FlowNodeBaseType.BLOCK,
63
+ ];
64
+
65
+ export type AddNodeData = FlowNodeJSON & {
66
+ originParent?: FlowNodeEntity;
67
+ parent?: FlowNodeEntity;
68
+ hidden?: boolean;
69
+ index?: number;
70
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export * from './flow';
7
+ export * from './flow-layout';
8
+ export * from './flow-transition';
9
+ export * from './flow-node-register';
10
+ export * from './flow-operation';
11
+ export * from './flow-group';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { DEFAULT_SPACING } from '../typings';
7
+ import { FlowDocumentOptions } from '../flow-document-options';
8
+ import { FlowNodeEntity } from '../entities/flow-node-entity';
9
+
10
+ /**
11
+ *
12
+ * @param node 节点 entity
13
+ * @param key 从 DocumentOptions 里获取 constants 的 key
14
+ * @param defaultSpacing 默认从 DEFAULT_SPACING 获取 spacing,也可以外部传入默认值
15
+ * @returns
16
+ */
17
+ export const getDefaultSpacing = (node: FlowNodeEntity, key: string, defaultSpacing?: number) => {
18
+ const flowDocumentOptions = node.getService<FlowDocumentOptions>(FlowDocumentOptions);
19
+ const spacing = flowDocumentOptions?.constants?.[key] || defaultSpacing || DEFAULT_SPACING[key];
20
+ return spacing;
21
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { getDefaultSpacing } from './get-default-spacing';