@knotx/plugins-connection-line 0.4.12 → 0.4.13
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/README.en.md +287 -0
- package/README.md +287 -0
- package/package.json +12 -12
package/README.en.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# @knotx/plugins-connection-line
|
|
2
|
+
|
|
3
|
+
Connection line plugin that provides drag-and-drop connection functionality between nodes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-connection-line
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-connection-line` is a connection line plugin for the KnotX framework that provides drag-and-drop connection functionality between nodes. Users can drag connection lines from node connection points to connect to other nodes or create new nodes in blank areas. It supports multi-selection simultaneous connections, custom connection line styles, and node creators.
|
|
14
|
+
|
|
15
|
+
## Implementation Principles
|
|
16
|
+
|
|
17
|
+
The plugin implements drag interaction through InteractJS:
|
|
18
|
+
|
|
19
|
+
1. **Connection Point Recognition**: Automatically recognizes connection points (source/target) on nodes
|
|
20
|
+
2. **Drag Handling**: Handles connection line drag interactions and visual feedback
|
|
21
|
+
3. **Connection Creation**: Supports connecting to other nodes or creating new nodes in blank areas
|
|
22
|
+
4. **Multi-selection Support**: Supports dragging connection lines from multiple selected nodes simultaneously
|
|
23
|
+
5. **Custom Creators**: Supports registering custom node and edge creators
|
|
24
|
+
|
|
25
|
+
## Dependencies
|
|
26
|
+
|
|
27
|
+
This plugin depends on the following packages:
|
|
28
|
+
|
|
29
|
+
- `@knotx/core` - Core functionality
|
|
30
|
+
- `@knotx/decorators` - Decorator support
|
|
31
|
+
- `@knotx/plugins-canvas` - Canvas plugin (peer dependency)
|
|
32
|
+
- `@knotx/plugins-selection` - Selection plugin (peer dependency)
|
|
33
|
+
- `@knotx/jsx` - JSX support (peer dependency)
|
|
34
|
+
- `interactjs` - Interaction library (peer dependency)
|
|
35
|
+
- `lodash-es` - Utility library
|
|
36
|
+
- `rxjs` - Reactive programming
|
|
37
|
+
|
|
38
|
+
## API Usage
|
|
39
|
+
|
|
40
|
+
### Basic Usage
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { ConnectionLine } from '@knotx/plugins-connection-line'
|
|
44
|
+
|
|
45
|
+
// Create connection line plugin instance
|
|
46
|
+
const connectionLine = new ConnectionLine()
|
|
47
|
+
|
|
48
|
+
// Register plugin in engine
|
|
49
|
+
engine.use(connectionLine)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Configuration Options
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const connectionLine = new ConnectionLine().init({
|
|
56
|
+
allowCreateNodeOnBlankArea: true,
|
|
57
|
+
edgeType: 'bezier',
|
|
58
|
+
connectionLineClassName: 'custom-connection-line',
|
|
59
|
+
connectionLineSVGAttributes: {
|
|
60
|
+
stroke: '#2563eb',
|
|
61
|
+
strokeWidth: '2',
|
|
62
|
+
strokeDasharray: '5,5'
|
|
63
|
+
},
|
|
64
|
+
allowMultiDrag: true
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Connection Point Attributes
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// Add connection points to nodes
|
|
72
|
+
function ConnectableNode({ node }) {
|
|
73
|
+
const { getConnectHandleAttributes } = useKnotX().connectionLine
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<div>{node.data.label}</div>
|
|
78
|
+
<div
|
|
79
|
+
{...getConnectHandleAttributes({
|
|
80
|
+
nodeId: node.id,
|
|
81
|
+
type: 'source',
|
|
82
|
+
index: 0,
|
|
83
|
+
className: 'my-connect-handle'
|
|
84
|
+
})}
|
|
85
|
+
style={{
|
|
86
|
+
position: 'absolute',
|
|
87
|
+
right: -5,
|
|
88
|
+
top: '50%',
|
|
89
|
+
transform: 'translateY(-50%)',
|
|
90
|
+
width: 10,
|
|
91
|
+
height: 10,
|
|
92
|
+
borderRadius: '50%',
|
|
93
|
+
backgroundColor: '#2563eb'
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
<div
|
|
97
|
+
{...getConnectHandleAttributes({
|
|
98
|
+
nodeId: node.id,
|
|
99
|
+
type: 'target',
|
|
100
|
+
index: 0
|
|
101
|
+
})}
|
|
102
|
+
style={{
|
|
103
|
+
position: 'absolute',
|
|
104
|
+
left: -5,
|
|
105
|
+
top: '50%',
|
|
106
|
+
transform: 'translateY(-50%)',
|
|
107
|
+
width: 10,
|
|
108
|
+
height: 10,
|
|
109
|
+
borderRadius: '50%',
|
|
110
|
+
backgroundColor: '#dc2626'
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Register Custom Creator
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// Register custom node and edge creator
|
|
122
|
+
const unregister = connectionLine.registerCreator(({ sourceNodeIds, targetPosition }) => {
|
|
123
|
+
if (targetPosition) {
|
|
124
|
+
// Create new node in blank area
|
|
125
|
+
const newNode = {
|
|
126
|
+
id: generateId(),
|
|
127
|
+
type: 'default',
|
|
128
|
+
position: targetPosition,
|
|
129
|
+
data: { label: 'New Node' }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const newEdges = sourceNodeIds.map(sourceId => ({
|
|
133
|
+
id: generateId(),
|
|
134
|
+
type: 'bezier',
|
|
135
|
+
source: sourceId,
|
|
136
|
+
target: newNode.id
|
|
137
|
+
}))
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
nodes: [newNode],
|
|
141
|
+
edges: newEdges
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Return undefined to use default creation logic
|
|
146
|
+
return undefined
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// Unregister
|
|
150
|
+
unregister()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Complete Example
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { Engine } from '@knotx/core'
|
|
157
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
158
|
+
import { ConnectionLine } from '@knotx/plugins-connection-line'
|
|
159
|
+
import { Selection } from '@knotx/plugins-selection'
|
|
160
|
+
|
|
161
|
+
const engine = new Engine()
|
|
162
|
+
|
|
163
|
+
// Register dependency plugins
|
|
164
|
+
engine.use(new Canvas())
|
|
165
|
+
engine.use(new Selection())
|
|
166
|
+
|
|
167
|
+
// Register connection line plugin
|
|
168
|
+
engine.use(new ConnectionLine().init({
|
|
169
|
+
allowCreateNodeOnBlankArea: true,
|
|
170
|
+
edgeType: 'bezier',
|
|
171
|
+
connectionLineClassName: 'custom-connection-line',
|
|
172
|
+
connectionLineSVGAttributes: {
|
|
173
|
+
stroke: '#2563eb',
|
|
174
|
+
strokeWidth: '2',
|
|
175
|
+
strokeDasharray: '5,5',
|
|
176
|
+
markerEnd: 'url(#arrowhead)'
|
|
177
|
+
},
|
|
178
|
+
allowMultiDrag: true
|
|
179
|
+
}))
|
|
180
|
+
|
|
181
|
+
// Register custom creator
|
|
182
|
+
const connectionLinePlugin = engine.getPlugin('connectionLine')
|
|
183
|
+
connectionLinePlugin.registerCreator(({ sourceNodeIds, targetPosition }) => {
|
|
184
|
+
// Custom creation logic
|
|
185
|
+
return {
|
|
186
|
+
nodes: [/* new nodes */],
|
|
187
|
+
edges: [/* new edges */]
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Configuration Interface
|
|
193
|
+
|
|
194
|
+
### ConnectionLineConfig
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
interface ConnectionLineConfig {
|
|
198
|
+
/**
|
|
199
|
+
* Whether to allow connecting to blank canvas area and create new nodes
|
|
200
|
+
* @default false
|
|
201
|
+
*/
|
|
202
|
+
allowCreateNodeOnBlankArea?: boolean
|
|
203
|
+
/**
|
|
204
|
+
* Type of newly created edges
|
|
205
|
+
* @default 'bezier'
|
|
206
|
+
*/
|
|
207
|
+
edgeType?: string
|
|
208
|
+
/**
|
|
209
|
+
* Class name for temporary connection line
|
|
210
|
+
*/
|
|
211
|
+
connectionLineClassName?: string
|
|
212
|
+
/**
|
|
213
|
+
* SVG attributes for temporary connection line
|
|
214
|
+
*/
|
|
215
|
+
connectionLineSVGAttributes?: Record<string, string>
|
|
216
|
+
/**
|
|
217
|
+
* Whether to support dragging connection lines from multiple selected nodes simultaneously
|
|
218
|
+
* @default true
|
|
219
|
+
*/
|
|
220
|
+
allowMultiDrag?: boolean
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Plugin Data Interface
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
declare module '@knotx/core' {
|
|
228
|
+
interface PluginData {
|
|
229
|
+
connectionLine: {
|
|
230
|
+
isDragging: boolean
|
|
231
|
+
registerCreator: (creator: (params: {
|
|
232
|
+
sourceNodeIds: string[]
|
|
233
|
+
targetPosition: { x: number, y: number } | undefined
|
|
234
|
+
}) => ({
|
|
235
|
+
nodes: Node[]
|
|
236
|
+
edges: Edge[]
|
|
237
|
+
}) | undefined | false) => () => void
|
|
238
|
+
getConnectHandleAttributes: (params: {
|
|
239
|
+
nodeId: string
|
|
240
|
+
type: 'source' | 'target'
|
|
241
|
+
index?: number
|
|
242
|
+
className?: string
|
|
243
|
+
}) => Record<string, string>
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Interactive Features
|
|
250
|
+
|
|
251
|
+
### Connection Line Dragging
|
|
252
|
+
|
|
253
|
+
- Start dragging from node connection points
|
|
254
|
+
- Real-time connection line preview
|
|
255
|
+
- Support for multi-selection simultaneous connections
|
|
256
|
+
- Automatic edge scrolling
|
|
257
|
+
|
|
258
|
+
### Connection Target Recognition
|
|
259
|
+
|
|
260
|
+
- Automatically recognizes valid connection targets
|
|
261
|
+
- Connection point highlighting
|
|
262
|
+
- Support for connecting to blank areas to create new nodes
|
|
263
|
+
|
|
264
|
+
### Connection Line Styling
|
|
265
|
+
|
|
266
|
+
- Support for custom connection line styles
|
|
267
|
+
- Support for SVG attribute configuration
|
|
268
|
+
- Support for custom CSS class names
|
|
269
|
+
|
|
270
|
+
## File Directory Structure
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
packages/plugins-connection-line/
|
|
274
|
+
├── src/
|
|
275
|
+
│ ├── connection-line.tsx # Connection line plugin main file
|
|
276
|
+
│ └── index.ts # Export file
|
|
277
|
+
├── dist/ # Build output directory
|
|
278
|
+
├── CHANGELOG.md # Change log
|
|
279
|
+
├── package.json # Package configuration
|
|
280
|
+
├── build.config.ts # Build configuration
|
|
281
|
+
├── eslint.config.mjs # ESLint configuration
|
|
282
|
+
└── tsconfig.json # TypeScript configuration
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## License
|
|
286
|
+
|
|
287
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# @knotx/plugins-connection-line
|
|
2
|
+
|
|
3
|
+
连接线插件,为节点间连接提供拖拽式连接线功能。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-connection-line
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 基本概述
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-connection-line` 是 KnotX 框架的连接线插件,提供节点间的拖拽式连接功能。用户可以从节点的连接点拖拽出连接线,连接到其他节点或空白区域创建新节点。支持多选节点同时连接、自定义连接线样式和节点创建器。
|
|
14
|
+
|
|
15
|
+
## 实现原理
|
|
16
|
+
|
|
17
|
+
该插件通过 InteractJS 实现拖拽交互:
|
|
18
|
+
|
|
19
|
+
1. **连接点识别**:自动识别节点上的连接点(source/target)
|
|
20
|
+
2. **拖拽处理**:处理连接线的拖拽交互和视觉反馈
|
|
21
|
+
3. **连接创建**:支持连接到其他节点或空白区域创建新节点
|
|
22
|
+
4. **多选支持**:支持从多个选中节点同时拖拽连接线
|
|
23
|
+
5. **自定义创建器**:支持注册自定义的节点和边创建器
|
|
24
|
+
|
|
25
|
+
## 依赖插件
|
|
26
|
+
|
|
27
|
+
该插件依赖以下包:
|
|
28
|
+
|
|
29
|
+
- `@knotx/core` - 核心功能
|
|
30
|
+
- `@knotx/decorators` - 装饰器支持
|
|
31
|
+
- `@knotx/plugins-canvas` - 画布插件(peer dependency)
|
|
32
|
+
- `@knotx/plugins-selection` - 选择插件(peer dependency)
|
|
33
|
+
- `@knotx/jsx` - JSX 支持(peer dependency)
|
|
34
|
+
- `interactjs` - 交互库(peer dependency)
|
|
35
|
+
- `lodash-es` - 工具库
|
|
36
|
+
- `rxjs` - 响应式编程
|
|
37
|
+
|
|
38
|
+
## API 使用
|
|
39
|
+
|
|
40
|
+
### 基本使用
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { ConnectionLine } from '@knotx/plugins-connection-line'
|
|
44
|
+
|
|
45
|
+
// 创建连接线插件实例
|
|
46
|
+
const connectionLine = new ConnectionLine()
|
|
47
|
+
|
|
48
|
+
// 在引擎中注册插件
|
|
49
|
+
engine.use(connectionLine)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 配置选项
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const connectionLine = new ConnectionLine().init({
|
|
56
|
+
allowCreateNodeOnBlankArea: true,
|
|
57
|
+
edgeType: 'bezier',
|
|
58
|
+
connectionLineClassName: 'custom-connection-line',
|
|
59
|
+
connectionLineSVGAttributes: {
|
|
60
|
+
stroke: '#2563eb',
|
|
61
|
+
strokeWidth: '2',
|
|
62
|
+
strokeDasharray: '5,5'
|
|
63
|
+
},
|
|
64
|
+
allowMultiDrag: true
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 连接点属性
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// 为节点添加连接点
|
|
72
|
+
function ConnectableNode({ node }) {
|
|
73
|
+
const { getConnectHandleAttributes } = useKnotX().connectionLine
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<div>{node.data.label}</div>
|
|
78
|
+
<div
|
|
79
|
+
{...getConnectHandleAttributes({
|
|
80
|
+
nodeId: node.id,
|
|
81
|
+
type: 'source',
|
|
82
|
+
index: 0,
|
|
83
|
+
className: 'my-connect-handle'
|
|
84
|
+
})}
|
|
85
|
+
style={{
|
|
86
|
+
position: 'absolute',
|
|
87
|
+
right: -5,
|
|
88
|
+
top: '50%',
|
|
89
|
+
transform: 'translateY(-50%)',
|
|
90
|
+
width: 10,
|
|
91
|
+
height: 10,
|
|
92
|
+
borderRadius: '50%',
|
|
93
|
+
backgroundColor: '#2563eb'
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
<div
|
|
97
|
+
{...getConnectHandleAttributes({
|
|
98
|
+
nodeId: node.id,
|
|
99
|
+
type: 'target',
|
|
100
|
+
index: 0
|
|
101
|
+
})}
|
|
102
|
+
style={{
|
|
103
|
+
position: 'absolute',
|
|
104
|
+
left: -5,
|
|
105
|
+
top: '50%',
|
|
106
|
+
transform: 'translateY(-50%)',
|
|
107
|
+
width: 10,
|
|
108
|
+
height: 10,
|
|
109
|
+
borderRadius: '50%',
|
|
110
|
+
backgroundColor: '#dc2626'
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 注册自定义创建器
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// 注册自定义节点和边创建器
|
|
122
|
+
const unregister = connectionLine.registerCreator(({ sourceNodeIds, targetPosition }) => {
|
|
123
|
+
if (targetPosition) {
|
|
124
|
+
// 在空白区域创建新节点
|
|
125
|
+
const newNode = {
|
|
126
|
+
id: generateId(),
|
|
127
|
+
type: 'default',
|
|
128
|
+
position: targetPosition,
|
|
129
|
+
data: { label: '新节点' }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const newEdges = sourceNodeIds.map(sourceId => ({
|
|
133
|
+
id: generateId(),
|
|
134
|
+
type: 'bezier',
|
|
135
|
+
source: sourceId,
|
|
136
|
+
target: newNode.id
|
|
137
|
+
}))
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
nodes: [newNode],
|
|
141
|
+
edges: newEdges
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 返回 undefined 使用默认创建逻辑
|
|
146
|
+
return undefined
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// 取消注册
|
|
150
|
+
unregister()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 完整示例
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { Engine } from '@knotx/core'
|
|
157
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
158
|
+
import { ConnectionLine } from '@knotx/plugins-connection-line'
|
|
159
|
+
import { Selection } from '@knotx/plugins-selection'
|
|
160
|
+
|
|
161
|
+
const engine = new Engine()
|
|
162
|
+
|
|
163
|
+
// 注册依赖插件
|
|
164
|
+
engine.use(new Canvas())
|
|
165
|
+
engine.use(new Selection())
|
|
166
|
+
|
|
167
|
+
// 注册连接线插件
|
|
168
|
+
engine.use(new ConnectionLine().init({
|
|
169
|
+
allowCreateNodeOnBlankArea: true,
|
|
170
|
+
edgeType: 'bezier',
|
|
171
|
+
connectionLineClassName: 'custom-connection-line',
|
|
172
|
+
connectionLineSVGAttributes: {
|
|
173
|
+
stroke: '#2563eb',
|
|
174
|
+
strokeWidth: '2',
|
|
175
|
+
strokeDasharray: '5,5',
|
|
176
|
+
markerEnd: 'url(#arrowhead)'
|
|
177
|
+
},
|
|
178
|
+
allowMultiDrag: true
|
|
179
|
+
}))
|
|
180
|
+
|
|
181
|
+
// 注册自定义创建器
|
|
182
|
+
const connectionLinePlugin = engine.getPlugin('connectionLine')
|
|
183
|
+
connectionLinePlugin.registerCreator(({ sourceNodeIds, targetPosition }) => {
|
|
184
|
+
// 自定义创建逻辑
|
|
185
|
+
return {
|
|
186
|
+
nodes: [/* 新节点 */],
|
|
187
|
+
edges: [/* 新边 */]
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 配置接口
|
|
193
|
+
|
|
194
|
+
### ConnectionLineConfig
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
interface ConnectionLineConfig {
|
|
198
|
+
/**
|
|
199
|
+
* 是否允许连接到画布空白处并创建新节点
|
|
200
|
+
* @default false
|
|
201
|
+
*/
|
|
202
|
+
allowCreateNodeOnBlankArea?: boolean
|
|
203
|
+
/**
|
|
204
|
+
* 新创建的边的类型
|
|
205
|
+
* @default 'bezier'
|
|
206
|
+
*/
|
|
207
|
+
edgeType?: string
|
|
208
|
+
/**
|
|
209
|
+
* 临时连接线的类名
|
|
210
|
+
*/
|
|
211
|
+
connectionLineClassName?: string
|
|
212
|
+
/**
|
|
213
|
+
* 临时连接线的SVG属性
|
|
214
|
+
*/
|
|
215
|
+
connectionLineSVGAttributes?: Record<string, string>
|
|
216
|
+
/**
|
|
217
|
+
* 是否支持从多个选中节点同时拖拽连接线
|
|
218
|
+
* @default true
|
|
219
|
+
*/
|
|
220
|
+
allowMultiDrag?: boolean
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 插件数据接口
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
declare module '@knotx/core' {
|
|
228
|
+
interface PluginData {
|
|
229
|
+
connectionLine: {
|
|
230
|
+
isDragging: boolean
|
|
231
|
+
registerCreator: (creator: (params: {
|
|
232
|
+
sourceNodeIds: string[]
|
|
233
|
+
targetPosition: { x: number, y: number } | undefined
|
|
234
|
+
}) => ({
|
|
235
|
+
nodes: Node[]
|
|
236
|
+
edges: Edge[]
|
|
237
|
+
}) | undefined | false) => () => void
|
|
238
|
+
getConnectHandleAttributes: (params: {
|
|
239
|
+
nodeId: string
|
|
240
|
+
type: 'source' | 'target'
|
|
241
|
+
index?: number
|
|
242
|
+
className?: string
|
|
243
|
+
}) => Record<string, string>
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## 交互功能
|
|
250
|
+
|
|
251
|
+
### 连接线拖拽
|
|
252
|
+
|
|
253
|
+
- 从节点连接点开始拖拽
|
|
254
|
+
- 实时显示连接线预览
|
|
255
|
+
- 支持多选节点同时连接
|
|
256
|
+
- 自动边缘滚动
|
|
257
|
+
|
|
258
|
+
### 连接目标识别
|
|
259
|
+
|
|
260
|
+
- 自动识别有效的连接目标
|
|
261
|
+
- 连接点高亮显示
|
|
262
|
+
- 支持连接到空白区域创建新节点
|
|
263
|
+
|
|
264
|
+
### 连接线样式
|
|
265
|
+
|
|
266
|
+
- 支持自定义连接线样式
|
|
267
|
+
- 支持 SVG 属性配置
|
|
268
|
+
- 支持自定义 CSS 类名
|
|
269
|
+
|
|
270
|
+
## 文件目录结构
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
packages/plugins-connection-line/
|
|
274
|
+
├── src/
|
|
275
|
+
│ ├── connection-line.tsx # 连接线插件主文件
|
|
276
|
+
│ └── index.ts # 导出文件
|
|
277
|
+
├── dist/ # 编译输出目录
|
|
278
|
+
├── CHANGELOG.md # 变更日志
|
|
279
|
+
├── package.json # 包配置
|
|
280
|
+
├── build.config.ts # 构建配置
|
|
281
|
+
├── eslint.config.mjs # ESLint 配置
|
|
282
|
+
└── tsconfig.json # TypeScript 配置
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 许可证
|
|
286
|
+
|
|
287
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-connection-line",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Connectionline Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"@interactjs/modifiers": "^1.10.27",
|
|
34
34
|
"@interactjs/types": "^1.10.27",
|
|
35
35
|
"interactjs": "^1.10.27",
|
|
36
|
-
"@knotx/jsx": "0.4.
|
|
37
|
-
"@knotx/plugins-canvas": "0.4.
|
|
38
|
-
"@knotx/plugins-selection": "0.4.
|
|
36
|
+
"@knotx/jsx": "0.4.13",
|
|
37
|
+
"@knotx/plugins-canvas": "0.4.13",
|
|
38
|
+
"@knotx/plugins-selection": "0.4.13"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"lodash-es": "^4.17.21",
|
|
42
42
|
"rxjs": "^7.8.1",
|
|
43
|
-
"@knotx/core": "0.4.
|
|
44
|
-
"@knotx/decorators": "0.4.
|
|
43
|
+
"@knotx/core": "0.4.13",
|
|
44
|
+
"@knotx/decorators": "0.4.13"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@interactjs/actions": "^1.10.27",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@interactjs/types": "^1.10.27",
|
|
51
51
|
"@types/lodash-es": "^4.17.12",
|
|
52
52
|
"interactjs": "^1.10.27",
|
|
53
|
-
"@knotx/build-config": "0.4.
|
|
54
|
-
"@knotx/eslint-config": "0.4.
|
|
55
|
-
"@knotx/jsx": "0.4.
|
|
56
|
-
"@knotx/plugins-canvas": "0.4.
|
|
57
|
-
"@knotx/plugins-selection": "0.4.
|
|
58
|
-
"@knotx/typescript-config": "0.4.
|
|
53
|
+
"@knotx/build-config": "0.4.13",
|
|
54
|
+
"@knotx/eslint-config": "0.4.13",
|
|
55
|
+
"@knotx/jsx": "0.4.13",
|
|
56
|
+
"@knotx/plugins-canvas": "0.4.13",
|
|
57
|
+
"@knotx/plugins-selection": "0.4.13",
|
|
58
|
+
"@knotx/typescript-config": "0.4.13"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|