@logicflow/core 2.2.1 → 2.2.3

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 (127) hide show
  1. package/README.md +32 -0
  2. package/dist/docs/api/logicflow-constructor/index.en.md +106 -0
  3. package/dist/docs/api/logicflow-constructor/index.zh.md +106 -0
  4. package/dist/docs/api/logicflow-constructor/use.en.md +61 -0
  5. package/dist/docs/api/logicflow-constructor/use.zh.md +61 -0
  6. package/dist/docs/api/logicflow-instance/canvas.en.md +197 -0
  7. package/dist/docs/api/logicflow-instance/canvas.zh.md +199 -0
  8. package/dist/docs/api/logicflow-instance/edge.en.md +273 -0
  9. package/dist/docs/api/logicflow-instance/edge.zh.md +273 -0
  10. package/dist/docs/api/logicflow-instance/edit-config.en.md +59 -0
  11. package/dist/docs/api/logicflow-instance/edit-config.zh.md +59 -0
  12. package/dist/docs/api/logicflow-instance/element.en.md +375 -0
  13. package/dist/docs/api/logicflow-instance/element.zh.md +379 -0
  14. package/dist/docs/api/logicflow-instance/event.en.md +326 -0
  15. package/dist/docs/api/logicflow-instance/event.zh.md +406 -0
  16. package/dist/docs/api/logicflow-instance/history.en.md +38 -0
  17. package/dist/docs/api/logicflow-instance/history.zh.md +38 -0
  18. package/dist/docs/api/logicflow-instance/index.en.md +41 -0
  19. package/dist/docs/api/logicflow-instance/index.zh.md +41 -0
  20. package/dist/docs/api/logicflow-instance/node.en.md +308 -0
  21. package/dist/docs/api/logicflow-instance/node.zh.md +308 -0
  22. package/dist/docs/api/logicflow-instance/register.en.md +76 -0
  23. package/dist/docs/api/logicflow-instance/register.zh.md +76 -0
  24. package/dist/docs/api/logicflow-instance/render-and-data.en.md +179 -0
  25. package/dist/docs/api/logicflow-instance/render-and-data.zh.md +181 -0
  26. package/dist/docs/api/logicflow-instance/text.en.md +60 -0
  27. package/dist/docs/api/logicflow-instance/text.zh.md +60 -0
  28. package/dist/docs/api/logicflow-instance/theme.en.md +179 -0
  29. package/dist/docs/api/logicflow-instance/theme.zh.md +179 -0
  30. package/dist/docs/api/runtime-model/edgeModel.en.md +29 -0
  31. package/dist/docs/api/runtime-model/edgeModel.zh.md +325 -0
  32. package/dist/docs/api/runtime-model/graphModel.en.md +275 -0
  33. package/dist/docs/api/runtime-model/graphModel.zh.md +1153 -0
  34. package/dist/docs/api/runtime-model/nodeModel.en.md +37 -0
  35. package/dist/docs/api/runtime-model/nodeModel.zh.md +644 -0
  36. package/dist/docs/api/type/MainTypes.en.md +598 -0
  37. package/dist/docs/api/type/MainTypes.zh.md +867 -0
  38. package/dist/docs/api/type/Theme.en.md +187 -0
  39. package/dist/docs/api/type/Theme.zh.md +187 -0
  40. package/dist/docs/api/type/canvas-types.en.md +25 -0
  41. package/dist/docs/api/type/canvas-types.zh.md +25 -0
  42. package/dist/docs/api/type/index.en.md +96 -0
  43. package/dist/docs/api/type/index.zh.md +99 -0
  44. package/dist/docs/api/type/node-types.en.md +21 -0
  45. package/dist/docs/api/type/node-types.zh.md +21 -0
  46. package/dist/docs/api/type/plugin-types.en.md +24 -0
  47. package/dist/docs/api/type/plugin-types.zh.md +24 -0
  48. package/dist/docs/index.md +11 -0
  49. package/dist/docs/tutorial/about.en.md +38 -0
  50. package/dist/docs/tutorial/about.zh.md +65 -0
  51. package/dist/docs/tutorial/advanced/dnd.en.md +62 -0
  52. package/dist/docs/tutorial/advanced/dnd.zh.md +52 -0
  53. package/dist/docs/tutorial/advanced/edge.en.md +64 -0
  54. package/dist/docs/tutorial/advanced/edge.zh.md +66 -0
  55. package/dist/docs/tutorial/advanced/keyboard.en.md +70 -0
  56. package/dist/docs/tutorial/advanced/keyboard.zh.md +67 -0
  57. package/dist/docs/tutorial/advanced/node.en.md +338 -0
  58. package/dist/docs/tutorial/advanced/node.zh.md +338 -0
  59. package/dist/docs/tutorial/advanced/react.en.md +106 -0
  60. package/dist/docs/tutorial/advanced/react.zh.md +114 -0
  61. package/dist/docs/tutorial/advanced/silent-mode.en.md +75 -0
  62. package/dist/docs/tutorial/advanced/silent-mode.zh.md +71 -0
  63. package/dist/docs/tutorial/advanced/snapline.en.md +54 -0
  64. package/dist/docs/tutorial/advanced/vue.en.md +249 -0
  65. package/dist/docs/tutorial/advanced/vue.zh.md +248 -0
  66. package/dist/docs/tutorial/ai.en.md +64 -0
  67. package/dist/docs/tutorial/ai.zh.md +64 -0
  68. package/dist/docs/tutorial/basic/background.en.md +50 -0
  69. package/dist/docs/tutorial/basic/canvas.en.md +164 -0
  70. package/dist/docs/tutorial/basic/canvas.zh.md +183 -0
  71. package/dist/docs/tutorial/basic/class.en.md +106 -0
  72. package/dist/docs/tutorial/basic/class.zh.md +103 -0
  73. package/dist/docs/tutorial/basic/edge.en.md +151 -0
  74. package/dist/docs/tutorial/basic/edge.zh.md +152 -0
  75. package/dist/docs/tutorial/basic/event.en.md +70 -0
  76. package/dist/docs/tutorial/basic/event.zh.md +66 -0
  77. package/dist/docs/tutorial/basic/grid.en.md +77 -0
  78. package/dist/docs/tutorial/basic/node.en.md +358 -0
  79. package/dist/docs/tutorial/basic/node.zh.md +318 -0
  80. package/dist/docs/tutorial/basic/theme.en.md +154 -0
  81. package/dist/docs/tutorial/basic/theme.zh.md +157 -0
  82. package/dist/docs/tutorial/extension/adapter.en.md +446 -0
  83. package/dist/docs/tutorial/extension/adapter.zh.md +429 -0
  84. package/dist/docs/tutorial/extension/bpmn-element.en.md +1427 -0
  85. package/dist/docs/tutorial/extension/bpmn-element.zh.md +1472 -0
  86. package/dist/docs/tutorial/extension/control.en.md +117 -0
  87. package/dist/docs/tutorial/extension/control.zh.md +118 -0
  88. package/dist/docs/tutorial/extension/curved-edge.en.md +46 -0
  89. package/dist/docs/tutorial/extension/curved-edge.zh.md +46 -0
  90. package/dist/docs/tutorial/extension/custom.en.md +142 -0
  91. package/dist/docs/tutorial/extension/custom.zh.md +138 -0
  92. package/dist/docs/tutorial/extension/dnd-panel.en.md +109 -0
  93. package/dist/docs/tutorial/extension/dnd-panel.zh.md +109 -0
  94. package/dist/docs/tutorial/extension/dynamic-group.en.md +606 -0
  95. package/dist/docs/tutorial/extension/dynamic-group.zh.md +606 -0
  96. package/dist/docs/tutorial/extension/group.en.md +217 -0
  97. package/dist/docs/tutorial/extension/group.zh.md +209 -0
  98. package/dist/docs/tutorial/extension/highlight.en.md +50 -0
  99. package/dist/docs/tutorial/extension/highlight.zh.md +50 -0
  100. package/dist/docs/tutorial/extension/insert-node-in-polyline.en.md +52 -0
  101. package/dist/docs/tutorial/extension/insert-node-in-polyline.zh.md +47 -0
  102. package/dist/docs/tutorial/extension/intro.en.md +72 -0
  103. package/dist/docs/tutorial/extension/intro.zh.md +95 -0
  104. package/dist/docs/tutorial/extension/label.en.md +136 -0
  105. package/dist/docs/tutorial/extension/label.zh.md +135 -0
  106. package/dist/docs/tutorial/extension/layout.en.md +156 -0
  107. package/dist/docs/tutorial/extension/layout.zh.md +156 -0
  108. package/dist/docs/tutorial/extension/menu.en.md +319 -0
  109. package/dist/docs/tutorial/extension/menu.zh.md +377 -0
  110. package/dist/docs/tutorial/extension/minimap.en.md +164 -0
  111. package/dist/docs/tutorial/extension/minimap.zh.md +180 -0
  112. package/dist/docs/tutorial/extension/node-resize.en.md +199 -0
  113. package/dist/docs/tutorial/extension/node-resize.zh.md +221 -0
  114. package/dist/docs/tutorial/extension/pool.en.md +227 -0
  115. package/dist/docs/tutorial/extension/pool.zh.md +227 -0
  116. package/dist/docs/tutorial/extension/proximity-connect.en.md +104 -0
  117. package/dist/docs/tutorial/extension/proximity-connect.zh.md +107 -0
  118. package/dist/docs/tutorial/extension/selection.en.md +166 -0
  119. package/dist/docs/tutorial/extension/selection.zh.md +150 -0
  120. package/dist/docs/tutorial/extension/snapshot.en.md +276 -0
  121. package/dist/docs/tutorial/extension/snapshot.zh.md +276 -0
  122. package/dist/docs/tutorial/get-started.en.md +501 -0
  123. package/dist/docs/tutorial/get-started.zh.md +139 -0
  124. package/dist/docs/tutorial/update.en.md +213 -0
  125. package/dist/docs/tutorial/update.zh.md +212 -0
  126. package/package.json +5 -3
  127. package/scripts/postinstall-ai-prompt.js +67 -0
@@ -0,0 +1,95 @@
1
+ ---
2
+ nav: 指南
3
+ group:
4
+ title: 插件功能
5
+ order: 3
6
+ title: 插件简介
7
+ order: 0
8
+ toc: content
9
+ ---
10
+
11
+ > LogicFlow最初的目标就是支持一个扩展性强的流程绘制工具,用来满足各种业务需求。为了让LogicFlow的拓展性足够强,LogicFlow将所有的非核心功能都使用插件的方式开发。
12
+ >
13
+ > 常见产品功能通常由 `@logicflow/extension` 提供,自动布局能力由 `@logicflow/layout` 提供。两类能力的使用文档都放在插件教程分组中。
14
+
15
+ ::::info{title=这页适合谁读}
16
+ - 你已经知道如何创建 `LogicFlow` 实例,现在想按目标挑选现成插件
17
+ - 你想知道全局安装插件和实例级安装插件有什么区别
18
+
19
+ 如果你还没有跑通过最小示例,建议先看 [快速上手](../get-started.zh.md)。
20
+ ::::
21
+
22
+ ## 插件地图
23
+
24
+ 可以先按目标选择,而不是逐个翻插件文件:
25
+
26
+ - 编辑体验增强:控制面板、右键菜单、选区、多选等
27
+ - 节点/边能力增强:节点缩放、分组、泳道、曲线边等
28
+ - 数据导入导出:adapter、BPMN 相关能力
29
+ - 布局与导出:自动布局、画布辅助能力
30
+ - 领域方案:BPMN 元素和配套能力
31
+
32
+ ## 使用指南
33
+
34
+ `@logicflow/extension`包中提供一些开箱即用的组件,快速支持产品中常见的功能,如控制面板、右键菜单等。
35
+
36
+ ```tsx | pure
37
+ import LogicFlow from '@logicflow/core'
38
+ import { Control, Menu, DndPanel } from '@logicflow/extension'
39
+ import '@logicflow/extension/lib/style/index.css'
40
+
41
+ LogicFlow.use(Control) // 控制面板
42
+ LogicFlow.use(Menu) // 右键菜单
43
+ LogicFlow.use(DndPanel) // 拖拽面板
44
+ ```
45
+
46
+ ### 安装全局插件
47
+
48
+ npm方式
49
+
50
+ ```tsx | pure
51
+ import { BpmnElement } from '@logicflow/extension';
52
+
53
+ LogicFlow.use(BpmnElement);
54
+ ```
55
+
56
+ cdn方式
57
+
58
+ ```tsx
59
+ <!--LogicFlow core包css-->
60
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/style/index.css" />
61
+ <!--LogicFlow extension包css-->
62
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/style/index.css" />
63
+ <!--LogicFlow core包js-->
64
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/logic-flow.js"></script>
65
+ <!--LogicFlow的插件支持单个引入,这里以菜单插件为例-->
66
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/Menu.js"></script>
67
+ <script>
68
+ LogicFlow.use(Menu); </script>
69
+ ```
70
+
71
+ ### 安装插件到实例上
72
+
73
+ `v1.0.7` 新增
74
+
75
+ 当一个单页面应用存在多个使用LogicFlow的页面时,不同的页面使用的插件可能不一样。LogicFlow初始化的时候,将插件作为参数传入到构造函数中,此时插件会覆盖全局的插件。
76
+
77
+ ```tsx | pure
78
+ import LogicFlow from "@logicflow/core";
79
+ import { DndPanel, SelectionSelect } from "@logicflow/extension";
80
+ import "@logicflow/core/lib/style/index.css";
81
+ // import "@logicflow/core/dist/style/index.css"; // 2.0版本前的引入方式
82
+ import "@logicflow/extension/lib/style/index.css";
83
+
84
+ const lf = new LogicFlow({
85
+ container: document.querySelector("#app"),
86
+ grid: true,
87
+ plugins: [DndPanel, SelectionSelect]
88
+ });
89
+ ```
90
+
91
+ ## 下一步阅读
92
+
93
+ 1. 已经知道要用哪个插件:直接进入对应插件页面
94
+ 2. 想先理解实例和插件关系:查看 [API 导览](../../api/logicflow-instance/index.zh.md) 中的“插件系统”
95
+ 3. 想继续自定义节点或边:回到 [进阶节点](../advanced/node.zh.md) / [进阶-边](../advanced/edge.zh.md)
@@ -0,0 +1,136 @@
1
+ ---
2
+ nav: Guide
3
+ group:
4
+ title: Plug-in functionality
5
+ order: 3
6
+ title: Label
7
+ order: 7
8
+ toc: content
9
+ ---
10
+
11
+ LogicFlow provides built-in node text and text editing capabilities, but sometimes we need richer text content, such as multi-line text or rich text. In such cases, you can use the `Label` plugin.
12
+
13
+ ## Demonstration
14
+
15
+ <code id="react-portal" src="@/src/tutorial/extension/label"></code>
16
+
17
+ ## Using the Plugin
18
+
19
+ ```tsx | pure
20
+ import LogicFlow from "@logicflow/core";
21
+ import { Label } from "@logicflow/extension";
22
+ import "@logicflow/extension/lib/style/index.css";
23
+
24
+ // Two ways to use the plugin
25
+ // Register the plugin using the use method
26
+ LogicFlow.use(Label);
27
+
28
+ // Or enable the plugin via configuration (you can configure plugin properties)
29
+ const lf = new LogicFlow({
30
+ container: document.querySelector('#app'),
31
+ plugins: [Label],
32
+ pluginsOptions: {
33
+ label: {
34
+ // ...labelOptions
35
+ },
36
+ },
37
+ });
38
+ ```
39
+
40
+ ## Configuration Options
41
+
42
+ ### Plugin-Level
43
+
44
+ Each feature in the menu can be represented by a single configuration. The specific fields are as follows:
45
+
46
+ | Field | Type | Default Value | Required | Description |
47
+ | ---------------- | ------------------------------------------------------- | ------------- | -------- | ----------------------------------------------------------------------------- |
48
+ | isMultiple | boolean | `true` | | Whether a node or edge can have multiple Labels. |
49
+ | maxCount | number | `Infinity` | | When multiple Labels are allowed, the maximum number of Labels. |
50
+ | labelWidth | number | - | | The width of each Label, can be uniformly set and used with textOverflowMode. |
51
+ | textOverflowMode | 'ellipsis' \| 'wrap' \| 'clip' \| 'nowrap' \| 'default' | `default` | | Text overflow display mode, consistent with CSS configuration. |
52
+
53
+ ### Element-Level
54
+
55
+ When the Label plugin is enabled, you can also configure properties at the element level in two scenarios:
56
+
57
+ 1. By default, the Label is used for text rendering. During initialization, the `text` property in NodeConfig or EdgeConfig is used as the Label's text content.
58
+ ```ts
59
+ const nodeConfig = {
60
+ id: '2',
61
+ type: 'circle',
62
+ x: 350,
63
+ y: 100,
64
+ properties: {},
65
+ text: {
66
+ x: 350,
67
+ y: 100,
68
+ value: 'Circle',
69
+ },
70
+ }
71
+ ```
72
+ 2. Users can also initialize Labels directly with Label configuration.
73
+ ```ts
74
+ export interface NodeConfig<P extends PropertiesType = PropertiesType> {
75
+ id?: string
76
+ type: string
77
+ x: number
78
+ y: number
79
+ text?: TextConfig | string
80
+ zIndex?: number
81
+ properties?: P
82
+ virtual?: boolean // Whether the node is virtual
83
+ rotate?: number
84
+
85
+ rotatable?: boolean // Whether the node is rotatable
86
+ resizable?: boolean // Whether the node is resizable
87
+
88
+ [key: string]: any
89
+ }
90
+
91
+ export type LabelConfig = {
92
+ id?: string // Unique identifier for the label
93
+ x: number
94
+ y: number
95
+ content?: string // Rich text content
96
+ value: string // Plain text content
97
+ rotate?: number // Rotation angle
98
+ // Style properties
99
+ style?: h.JSX.CSSProperties // Custom style for the label
100
+
101
+ // Edit state properties
102
+ editable?: boolean
103
+ draggable?: boolean
104
+ labelWidth?: number
105
+ textOverflowMode?: 'ellipsis' | 'wrap' | 'clip' | 'nowrap' | 'default'
106
+ }
107
+
108
+ export type LabelOption = {
109
+ // Whether multiple labels are supported
110
+ isMultiple: boolean
111
+ // Maximum number of labels allowed when multiple labels are supported
112
+ maxCount?: number
113
+ }
114
+
115
+ export type LabelNodeConfig = NodeConfig<{
116
+ _label?: string | LabelConfig | LabelConfig[]
117
+ _labelOptions?: LabelOption
118
+ }>
119
+ ```
120
+ In other words, by adding `_label` and `_labelOptions` fields in the properties of Node or Edge initialization data, you can configure the content and attributes of a single Label.
121
+
122
+ :::info{title=Note:Plugin-includes-rich-text-editing-mode-by-default}
123
+ - When double-clicking the text to enter edit mode, the selected text will display a rich text editor, allowing users to edit rich text content.
124
+ - A switch will be added in the future to allow users to customize whether to enable rich text editing mode.
125
+ :::
126
+
127
+ ## API
128
+
129
+ ### lf.extension.label.updateTextMode(mode)
130
+
131
+ Updates whether to use Text or Label for displaying text.
132
+
133
+ ```ts
134
+ // Update Label text display mode
135
+ updateTextMode = (textMode: 'text' | 'label'): void => {}
136
+ ```
@@ -0,0 +1,135 @@
1
+ ---
2
+ nav: 指南
3
+ group:
4
+ title: 插件功能
5
+ order: 3
6
+ title: 富文本标签 (Label)
7
+ order: 7
8
+ toc: content
9
+ ---
10
+
11
+ LogicFlow
12
+ 内部提供了节点文本以及文本编辑能力,但是有时候我们需要更加丰富的文本内容,比如支持多行文本、富文本等。这时候我们可以选择使用`Label`
13
+ 插件。
14
+
15
+ ## 演示
16
+
17
+ <code id="react-portal" src="@/src/tutorial/extension/label"></code>
18
+
19
+ ## 使用插件
20
+
21
+ ```tsx | pure
22
+ import LogicFlow from "@logicflow/core";
23
+ import { Label } from "@logicflow/extension";
24
+ import "@logicflow/extension/lib/style/index.css";
25
+
26
+ // 两种使用方式
27
+ // 通过 use 方法引入插件
28
+ LogicFlow.use(Label);
29
+
30
+ // 或者通过配置项启用插件(可以配置插件属性)
31
+ const lf = new LogicFlow({
32
+ container: document.querySelector('#app'),
33
+ plugins: [Label],
34
+ pluginsOptions: {
35
+ label: {
36
+ // ...labelOptions
37
+ },
38
+ },
39
+ });
40
+ ```
41
+
42
+ ## 配置项
43
+
44
+ ### 插件级
45
+
46
+ Label插件支持一些初始化属性。具体字段如下:
47
+
48
+ | 字段 | 类型 | 默认值 | 是否必须 | 描述 |
49
+ | ---------------- | ------------------------------------------------------- | ---------- | -------- | ------------------------------------------------------------ |
50
+ | isMultiple | boolean | `true` | | 是否允许一个节点或边拥有多个 Label |
51
+ | maxCount | number | `Infinity` | | 当允许多个 Label 时,限制 Label 的最大数量 |
52
+ | labelWidth | number | - | | 每个 Label 的宽度,可以统一设置配合 textOverflowMode 使用 |
53
+ | textOverflowMode | 'ellipsis' \| 'wrap' \| 'clip' \| 'nowrap' \| 'default' | `default` | | 文本溢出显示模式,配合 CSS 样式实现,与 CSS 配置项表现一致。 |
54
+
55
+ ### 元素级
56
+
57
+ 如果启用了 Label 插件,我们同时也支持元素级别的属性配置,有两种场景:
58
+ 1. 默认以 Label 为文本渲染模式,初始化时,使用 NodeConfig or EdgeConfig 中的 text 属性作为 Label 的文本内容。
59
+ ```ts
60
+ const nodeConfig = {
61
+ id: '2',
62
+ type: 'circle',
63
+ x: 350,
64
+ y: 100,
65
+ properties: {},
66
+ text: {
67
+ x: 350,
68
+ y: 100,
69
+ value: '圆形',
70
+ },
71
+ }
72
+ ```
73
+ 2. 我们也支持用户直接用 Label 配置初始化 Label
74
+ ```ts
75
+ export interface NodeConfig<P extends PropertiesType = PropertiesType> {
76
+ id?: string
77
+ type: string
78
+ x: number
79
+ y: number
80
+ text?: TextConfig | string
81
+ zIndex?: number
82
+ properties?: P
83
+ virtual?: boolean // 是否虚拟节点
84
+ rotate?: number
85
+
86
+ rotatable?: boolean // 节点是否可旋转
87
+ resizable?: boolean // 节点是否可缩放
88
+
89
+ [key: string]: any
90
+ }
91
+
92
+ export type LabelConfig = {
93
+ id?: string // label唯一标识
94
+ x: number
95
+ y: number
96
+ content?: string // 富文本内容
97
+ value: string // 纯文本内容
98
+ rotate?: number // 旋转角度
99
+ // 样式属性
100
+ style?: h.JSX.CSSProperties // label自定义样式
101
+
102
+ // 编辑状态属性
103
+ editable?: boolean
104
+ draggable?: boolean
105
+ labelWidth?: number
106
+ textOverflowMode?: 'ellipsis' | 'wrap' | 'clip' | 'nowrap' | 'default'
107
+ }
108
+
109
+ export type LabelOption = {
110
+ // 是否支持多个 label
111
+ isMultiple: boolean
112
+ // 允许设置多个 label 时最大个数
113
+ maxCount?: number
114
+ }
115
+
116
+ export type LabelNodeConfig = NodeConfig<{
117
+ _label?: string | LabelConfig | LabelConfig[]
118
+ _labelOptions?: LabelOption
119
+ }>
120
+ ```
121
+ 也就是说,在初始化 Node 或 Edge 的数据 properties 中添加 _label 和 _labelOptions 字段,即可配置单个 Label 的内容和属性。
122
+
123
+ :::info{title=注意,插件默认内置了富文本编辑模式}
124
+ - 双击文本进入编辑状态时,选中文本会弹出富文本编辑器,支持用户编辑富文本内容
125
+ - 后续我们会增加开关,支持用户自定义是否启用富文本编辑模式
126
+ :::
127
+
128
+ ## API
129
+ ### lf.extension.label.updateTextMode(mode)
130
+ 用于更新当前使用 Text 还是 Label 显示文本
131
+
132
+ ```ts
133
+ // 更新 Label 文本显示模式
134
+ updateTextMode = (textMode: 'text' | 'label'): void => {}
135
+ ```
@@ -0,0 +1,156 @@
1
+ ---
2
+ nav: Guide
3
+ group:
4
+ title: Plug-in functionality
5
+ order: 3
6
+ title: Automatic Layout
7
+ order: 7
8
+ toc: content
9
+ tag: Enhancement
10
+ ---
11
+
12
+ In complex flowcharts, manually placing nodes and adjusting edges is time-consuming and often messy.
13
+
14
+ The auto layout plugin can:
15
+ - Automatically compute node positions and rank order from edge relationships
16
+ - Support layout directions (LR/TB/BT/RL) and alignment
17
+ - Configure node spacing, rank spacing, edge spacing, and canvas margins
18
+ - Plan edge routes to reduce crossings and keep a consistent overall flow
19
+ - Optionally adjust edge endpoints based on default anchors
20
+
21
+ It typically produces a structured layout with clear hierarchy, consistent spacing, and fewer edge crossings, making it ideal for an initial layout that you can fine-tune.
22
+
23
+ The Layout plugin is currently based on Dagre, and its scope is:
24
+ - Covered: automatic calculation of node positions, hierarchy, spacing, and basic edge routing
25
+ - Not covered: business rule validation, node/edge styling, and complex interaction logic (handled separately)
26
+
27
+ ## Live Demonstration
28
+
29
+ ### Default Anchors
30
+
31
+ If nodes use LogicFlow's default anchors (i.e., top, bottom, left, and right anchors), and anchor information doesn't carry business meaning, you can set isDefaultAnchor to true to adjust connection start and end anchor positions during layout.
32
+
33
+ <code id="react-portal-1" src="@/src/tutorial/extension/layout"></code>
34
+
35
+ ### Custom Anchors
36
+
37
+ If nodes use custom anchors, or if anchors have actual business meaning, isDefaultAnchor is false by default, which means the layout will not adjust the connection's start and end anchors.
38
+
39
+ <code id="react-portal-2" src="@/src/tutorial/extension/layout/custom"></code>
40
+
41
+ ## Installation
42
+
43
+ ```shell
44
+ # npm
45
+ npm install @logicflow/layout
46
+
47
+ # yarn
48
+ yarn add @logicflow/layout
49
+
50
+ # pnpm
51
+ pnpm add @logicflow/layout
52
+ ```
53
+
54
+ ### UMD Usage
55
+
56
+ You can also use the UMD bundle directly via CDN:
57
+
58
+ ```html
59
+ <!-- Include LogicFlow Core UMD -->
60
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/index.min.js"></script>
61
+ <link href="https://cdn.jsdelivr.net/npm/@logicflow/core/lib/style/index.min.css" rel="stylesheet">
62
+ <!-- Include Layout UMD -->
63
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/layout/dist/index.min.js"></script>
64
+
65
+ <script>
66
+ // Access Dagre plugin through global variable Layout
67
+ const { Dagre } = Layout;
68
+
69
+ // Create LogicFlow instance and register plugin
70
+ const lf = new LogicFlow.default({
71
+ container: document.getElementById('container'),
72
+ plugins: [Dagre]
73
+ });
74
+
75
+ // Use layout functionality
76
+ lf.dagre.layout({
77
+ rankdir: 'LR',
78
+ nodesep: 50,
79
+ ranksep: 100
80
+ });
81
+ </script>
82
+ ```
83
+
84
+ ## Basic Usage
85
+
86
+ ### Register the Plugin
87
+
88
+ Like other LogicFlow plugins, Layout supports both global and local registration:
89
+
90
+ ```tsx | pure
91
+ import LogicFlow from "@logicflow/core";
92
+ import { Dagre } from "@logicflow/layout";
93
+
94
+ // Global registration
95
+ LogicFlow.use(Dagre);
96
+
97
+ // Local registration
98
+ const lf = new LogicFlow({
99
+ container: document.getElementById('app'),
100
+ plugins: [Dagre]
101
+ });
102
+ ```
103
+
104
+ ### Apply Layout
105
+
106
+ After registration, you can access the dagre plugin through the LogicFlow instance's extension property:
107
+
108
+ ```tsx | pure
109
+ // Use default configuration
110
+ lf.extension.dagre.layout();
111
+
112
+ // Use custom configuration
113
+ lf.extension.dagre.layout({
114
+ rankdir: 'TB', // Top-to-bottom layout direction
115
+ align: 'UL', // Upper-left alignment
116
+ nodesep: 60, // Node spacing
117
+ ranksep: 70 // Rank spacing
118
+ });
119
+ ```
120
+
121
+ ## Layout Configuration Options
122
+
123
+ You can customize the appearance and behavior of the layout through various options:
124
+
125
+ | Parameter | Type | Default | Description |
126
+ |-----------|------|---------|-------------|
127
+ | rankdir | string | 'LR' | Layout direction: 'LR'(left to right), 'TB'(top to bottom), 'BT'(bottom to top), 'RL'(right to left) |
128
+ | align | string | 'UL' | Node alignment: 'UL'(upper left), 'UR'(upper right), 'DL'(down left), 'DR'(down right) |
129
+ | nodesep | number | 100 | Horizontal spacing between nodes (pixels) |
130
+ | ranksep | number | 150 | Vertical spacing between ranks (pixels) |
131
+ | marginx | number | 120 | Horizontal margin of the graph (pixels) |
132
+ | marginy | number | 120 | Vertical margin of the graph (pixels) |
133
+ | ranker | string | 'tight-tree' | Ranking algorithm: 'network-simplex', 'tight-tree', 'longest-path' |
134
+ | edgesep | number | 10 | Horizontal spacing between edges (pixels) |
135
+ | acyclicer | string | undefined | If set to 'greedy', uses a greedy heuristic for finding a feedback arc set for making the graph acyclic |
136
+ | isDefaultAnchor | boolean | false | Whether to use default anchors: when true, automatically adjusts edge anchors and calculates edge paths based on layout direction |
137
+
138
+ ## Advanced Features
139
+
140
+ ### Auto-fit View After Layout
141
+
142
+ After adjusting the layout, you may need to adjust the view to show all nodes:
143
+
144
+ ```tsx | pure
145
+ // First apply the layout
146
+ lf.extension.dagre.layout();
147
+ // Then fit the view
148
+ lf.fitView();
149
+ ```
150
+
151
+ ## Usage Recommendations
152
+
153
+ 1. **Complex Graphs**: For large or complex flowcharts, use automatic layout to generate an initial arrangement, then make manual adjustments
154
+ 2. **Dynamic Updates**: Apply layout after adding/removing nodes to keep the graph tidy
155
+ 3. **Direction Selection**: Choose a suitable layout direction based on the actual meaning of your business process
156
+ 4. **Parameter Adjustment**: Find the layout that best suits your diagram by adjusting node spacing and rank spacing
@@ -0,0 +1,156 @@
1
+ ---
2
+ nav: 指南
3
+ group:
4
+ title: 插件功能
5
+ order: 3
6
+ title: 自动布局 (Layout)
7
+ order: 7
8
+ toc: content
9
+ ---
10
+
11
+ 在复杂流程图中,手动摆放节点与调整连线既耗时又容易混乱。
12
+
13
+ 自动布局插件可以:
14
+ - 根据连线关系自动计算节点位置与层级顺序
15
+ - 支持布局方向(LR/TB/BT/RL)与对齐方式
16
+ - 支持节点间距、层级间距、边间距与画布边距配置
17
+ - 规划连线路径,减少交叉并保持整体走向一致
18
+ - 可选使用默认锚点自动调整连线起终点位置
19
+
20
+ 使用后通常能获得层级清晰、间距统一、连线更少交叉的结构化布局,适合作为初始排版,再进行少量手动微调。
21
+
22
+ 当前 Layout 插件基于 Dagre,能力范围如下:
23
+ - 会处理的内容:节点位置、层级与间距的自动计算,连线走向的基础规划
24
+ - 不会处理的内容:业务规则校验、节点/边样式、复杂交互逻辑(需自行处理)
25
+
26
+ ## 效果演示
27
+
28
+ ### 默认锚点
29
+
30
+ 如果节点是LogicFlow的默认锚点(即上下左右4个锚点),且锚点信息并不具备业务含义。那么通过设置isDefaultAnchor 为true,就可以在布局中调整连线起终点锚点的位置。
31
+
32
+ <code id="react-portal-1" src="@/src/tutorial/extension/layout"></code>
33
+
34
+ ### 自定义锚点
35
+
36
+ 如果节点的锚点是自定义的,或者锚点是具备实际业务含义的,isDefaultAnchor 默认为false,那么布局中就不会调整连线的起终点锚点。
37
+
38
+ <code id="react-portal-2" src="@/src/tutorial/extension/layout/custom"></code>
39
+
40
+ ## 安装
41
+
42
+ ```shell
43
+ # npm
44
+ npm install @logicflow/layout
45
+
46
+ # yarn
47
+ yarn add @logicflow/layout
48
+
49
+ # pnpm
50
+ pnpm add @logicflow/layout
51
+ ```
52
+
53
+ ### UMD 方式使用
54
+
55
+ 您也可以通过 CDN 直接引入 UMD 包:
56
+
57
+ ```html
58
+ <!-- 引入 LogicFlow Core UMD -->
59
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/index.min.js"></script>
60
+ <link href="https://cdn.jsdelivr.net/npm/@logicflow/core/lib/style/index.min.css" rel="stylesheet">
61
+ <!-- 引入 Layout UMD -->
62
+ <script src="https://cdn.jsdelivr.net/npm/@logicflow/layout/dist/index.min.js"></script>
63
+
64
+ <script>
65
+ // 通过全局变量 Layout 访问 Dagre 插件
66
+ const { Dagre } = Layout;
67
+
68
+ // 创建 LogicFlow 实例并注册插件
69
+ const lf = new LogicFlow.default({
70
+ container: document.getElementById('container'),
71
+ plugins: [Dagre]
72
+ });
73
+
74
+ // 使用布局功能
75
+ lf.dagre.layout({
76
+ rankdir: 'LR',
77
+ nodesep: 50,
78
+ ranksep: 100
79
+ });
80
+ </script>
81
+ ```
82
+
83
+ ## 基本使用
84
+
85
+ ### 注册插件
86
+
87
+ 与其他 LogicFlow 插件一样,Layout 支持全局和局部两种注册方式:
88
+
89
+ ```tsx | pure
90
+ import LogicFlow from "@logicflow/core";
91
+ import { Dagre } from "@logicflow/layout";
92
+
93
+ // 全局注册
94
+ LogicFlow.use(Dagre);
95
+
96
+ // 局部注册
97
+ const lf = new LogicFlow({
98
+ container: document.getElementById('app'),
99
+ plugins: [Dagre]
100
+ });
101
+ ```
102
+
103
+ ### 应用布局
104
+
105
+ 注册完成后,您可以通过 LogicFlow 实例的 extension 属性访问 dagre 插件:
106
+
107
+ ```tsx | pure
108
+ // 使用默认配置
109
+ lf.extension.dagre.layout();
110
+
111
+ // 使用自定义配置
112
+ lf.extension.dagre.layout({
113
+ rankdir: 'TB', // 从上到下的布局方向
114
+ align: 'UL', // 上左对齐
115
+ nodesep: 60, // 节点间距
116
+ ranksep: 70 // 层级间距
117
+ });
118
+ ```
119
+
120
+ ## 布局配置选项
121
+
122
+ 通过配置不同的选项,您可以自定义布局的外观和行为。以下是支持的选项:
123
+
124
+ | 参数名 | 类型 | 默认值 | 说明 |
125
+ | --------------- | ------- | ------------ | ---------------------------------------------------------------------- |
126
+ | rankdir | string | 'LR' | 布局方向,'LR'(左到右), 'TB'(上到下), 'BT'(下到上), 'RL'(右到左) |
127
+ | align | string | 'UL' | 节点对齐方式,'UL'(上左), 'UR'(上右), 'DL'(下左), 'DR'(下右) |
128
+ | nodesep | number | 100 | 节点间的水平间距(像素) |
129
+ | ranksep | number | 150 | 层级间的垂直间距(像素) |
130
+ | marginx | number | 120 | 图的水平边距(像素) |
131
+ | marginy | number | 120 | 图的垂直边距(像素) |
132
+ | ranker | string | 'tight-tree' | 排名算法,'network-simplex', 'tight-tree', 'longest-path' |
133
+ | edgesep | number | 10 | 边之间的水平间距(像素) |
134
+ | acyclicer | string | undefined | 如果设置为'greedy',使用贪心算法查找反馈弧集,用于使图变为无环图 |
135
+ | isDefaultAnchor | boolean | false | 是否使用默认锚点:true表示会自动调整连线锚点,根据布局方向计算边的路径 |
136
+
137
+ ## 高级功能
138
+
139
+ ### 应用布局后自动适配视图
140
+
141
+ 布局调整后,您可能需要调整视图以显示所有节点:
142
+
143
+ ```tsx | pure
144
+ // 先应用布局
145
+ lf.extension.dagre.layout();
146
+ // 然后适配视图
147
+ lf.fitView();
148
+ ```
149
+
150
+
151
+ ## 使用建议
152
+
153
+ 1. **复杂图形**:对于大型或复杂的流程图,先使用自动布局生成初始排列,然后进行手动微调
154
+ 2. **动态更新**:在添加/删除节点后应用布局,使图形保持整洁
155
+ 3. **方向选择**:根据业务流程的实际含义选择合适的布局方向
156
+ 4. **参数调整**:通过调整节点间距和层级间距,找到最适合您图表的布局