@knotx/plugins-bounding 0.4.11 → 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 +375 -0
- package/README.md +375 -0
- package/package.json +11 -11
package/README.en.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# @knotx/plugins-bounding
|
|
2
|
+
|
|
3
|
+
Bounding plugin that provides resize and connection point functionality for nodes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-bounding
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-bounding` is a bounding plugin for the KnotX framework that provides resize and connection point functionality for nodes. It supports multiple resize handle positions, custom styles, minimum size constraints, and inertia effects.
|
|
14
|
+
|
|
15
|
+
## Implementation Principles
|
|
16
|
+
|
|
17
|
+
The plugin implements interactive functionality through InteractJS:
|
|
18
|
+
|
|
19
|
+
1. **Resize Handles**: Provides draggable resize handles around nodes
|
|
20
|
+
2. **Connection Points**: Provides connection points at node edges for inter-node connections
|
|
21
|
+
3. **Bounding Box**: Shows bounding box for selected nodes
|
|
22
|
+
4. **Interaction Handling**: Handles resize and connection drag interactions
|
|
23
|
+
|
|
24
|
+
## Dependencies
|
|
25
|
+
|
|
26
|
+
This plugin depends on the following packages:
|
|
27
|
+
|
|
28
|
+
- `@knotx/core` - Core functionality
|
|
29
|
+
- `@knotx/decorators` - Decorator support
|
|
30
|
+
- `@knotx/plugins-canvas` - Canvas plugin (peer dependency)
|
|
31
|
+
- `@knotx/jsx` - JSX support (peer dependency)
|
|
32
|
+
- `@knotx/render` - Rendering utilities
|
|
33
|
+
- `interactjs` - Interaction library
|
|
34
|
+
- `rxjs` - Reactive programming
|
|
35
|
+
|
|
36
|
+
## API Usage
|
|
37
|
+
|
|
38
|
+
### Basic Usage
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Bounding } from '@knotx/plugins-bounding'
|
|
42
|
+
|
|
43
|
+
// Create bounding plugin instance
|
|
44
|
+
const bounding = new Bounding()
|
|
45
|
+
|
|
46
|
+
// Register plugin in engine
|
|
47
|
+
engine.use(bounding)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Configuration Options
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const bounding = new Bounding().init({
|
|
54
|
+
features: {
|
|
55
|
+
resize: true,
|
|
56
|
+
connect: true,
|
|
57
|
+
boundingBox: true
|
|
58
|
+
},
|
|
59
|
+
sizes: {
|
|
60
|
+
resizeHandle: 6,
|
|
61
|
+
connectHandle: 8,
|
|
62
|
+
boundingBoxThreshold: 200
|
|
63
|
+
},
|
|
64
|
+
styles: {
|
|
65
|
+
resizeHandle: {
|
|
66
|
+
fill: '#3b82f6',
|
|
67
|
+
stroke: '#ffffff',
|
|
68
|
+
strokeWidth: 1
|
|
69
|
+
},
|
|
70
|
+
connectHandle: {
|
|
71
|
+
fill: '#10b981',
|
|
72
|
+
stroke: '#ffffff',
|
|
73
|
+
strokeWidth: 1,
|
|
74
|
+
shadowColor: '#000000',
|
|
75
|
+
shadowWidth: 1
|
|
76
|
+
},
|
|
77
|
+
boundingBox: {
|
|
78
|
+
stroke: '#3b82f6',
|
|
79
|
+
strokeWidth: 1
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
resize: {
|
|
83
|
+
minWidth: 50,
|
|
84
|
+
minHeight: 30,
|
|
85
|
+
inertia: false,
|
|
86
|
+
handles: ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'left', 'right', 'top', 'bottom'],
|
|
87
|
+
nodesType: ['default', 'custom']
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Custom Resize Handle Attributes
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const { getCustomResizeHandleAttributes } = useKnotX().bounding
|
|
96
|
+
|
|
97
|
+
// Add resize handle to custom node
|
|
98
|
+
function ResizableNode({ node }) {
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ position: 'relative' }}>
|
|
101
|
+
<div>{node.data.label}</div>
|
|
102
|
+
|
|
103
|
+
{/* Bottom-right resize handle */}
|
|
104
|
+
<div
|
|
105
|
+
{...getCustomResizeHandleAttributes(node.id, 'bottom-right')}
|
|
106
|
+
style={{
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
right: -3,
|
|
109
|
+
bottom: -3,
|
|
110
|
+
width: 6,
|
|
111
|
+
height: 6,
|
|
112
|
+
backgroundColor: '#3b82f6',
|
|
113
|
+
border: '1px solid #ffffff',
|
|
114
|
+
borderRadius: '50%',
|
|
115
|
+
cursor: 'nw-resize'
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Complete Example
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { Engine } from '@knotx/core'
|
|
127
|
+
import { Bounding } from '@knotx/plugins-bounding'
|
|
128
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
129
|
+
|
|
130
|
+
const engine = new Engine()
|
|
131
|
+
|
|
132
|
+
// Register dependency plugins
|
|
133
|
+
engine.use(new Canvas())
|
|
134
|
+
|
|
135
|
+
// Register bounding plugin
|
|
136
|
+
engine.use(new Bounding().init({
|
|
137
|
+
features: {
|
|
138
|
+
resize: true,
|
|
139
|
+
connect: true,
|
|
140
|
+
boundingBox: true
|
|
141
|
+
},
|
|
142
|
+
sizes: {
|
|
143
|
+
resizeHandle: 8,
|
|
144
|
+
connectHandle: 10,
|
|
145
|
+
boundingBoxThreshold: 150
|
|
146
|
+
},
|
|
147
|
+
styles: {
|
|
148
|
+
resizeHandle: {
|
|
149
|
+
fill: '#ec4899',
|
|
150
|
+
stroke: '#ffffff',
|
|
151
|
+
strokeWidth: 2
|
|
152
|
+
},
|
|
153
|
+
connectHandle: {
|
|
154
|
+
fill: '#06b6d4',
|
|
155
|
+
stroke: '#ffffff',
|
|
156
|
+
strokeWidth: 2,
|
|
157
|
+
shadowColor: 'rgba(0, 0, 0, 0.2)',
|
|
158
|
+
shadowWidth: 2
|
|
159
|
+
},
|
|
160
|
+
boundingBox: {
|
|
161
|
+
stroke: '#ec4899',
|
|
162
|
+
strokeWidth: 2
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
resize: {
|
|
166
|
+
minWidth: 80,
|
|
167
|
+
minHeight: 50,
|
|
168
|
+
inertia: true,
|
|
169
|
+
handles: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
|
|
170
|
+
nodesType: ['default']
|
|
171
|
+
}
|
|
172
|
+
}))
|
|
173
|
+
|
|
174
|
+
// Create resizable node
|
|
175
|
+
engine.dispatchNodeOperation({
|
|
176
|
+
type: 'add',
|
|
177
|
+
node: {
|
|
178
|
+
id: 'resizable-node',
|
|
179
|
+
type: 'default',
|
|
180
|
+
position: { x: 100, y: 100 },
|
|
181
|
+
measured: { width: 120, height: 80 },
|
|
182
|
+
data: { label: 'Resizable Node' }
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Configuration Interface
|
|
188
|
+
|
|
189
|
+
### BoundingConfig
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
interface BoundingConfig {
|
|
193
|
+
// Feature switches
|
|
194
|
+
features?: {
|
|
195
|
+
resize?: boolean
|
|
196
|
+
connect?: boolean
|
|
197
|
+
boundingBox?: boolean
|
|
198
|
+
}
|
|
199
|
+
// Size configuration
|
|
200
|
+
sizes?: {
|
|
201
|
+
resizeHandle?: number
|
|
202
|
+
connectHandle?: number
|
|
203
|
+
boundingBoxThreshold?: number
|
|
204
|
+
}
|
|
205
|
+
// Style configuration
|
|
206
|
+
styles?: {
|
|
207
|
+
resizeHandle?: {
|
|
208
|
+
fill?: string
|
|
209
|
+
stroke?: string
|
|
210
|
+
strokeWidth?: number
|
|
211
|
+
}
|
|
212
|
+
connectHandle?: {
|
|
213
|
+
fill?: string
|
|
214
|
+
stroke?: string
|
|
215
|
+
strokeWidth?: number
|
|
216
|
+
shadowColor?: string
|
|
217
|
+
shadowWidth?: number
|
|
218
|
+
}
|
|
219
|
+
boundingBox?: {
|
|
220
|
+
stroke?: string
|
|
221
|
+
strokeWidth?: number
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Resize configuration
|
|
225
|
+
resize?: {
|
|
226
|
+
minWidth?: number
|
|
227
|
+
minHeight?: number
|
|
228
|
+
inertia?: boolean
|
|
229
|
+
handles?: ResizeHandlePosition[]
|
|
230
|
+
nodesType?: string[]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### ResizeHandlePosition
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
type ResizeHandlePosition =
|
|
239
|
+
| 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
240
|
+
| 'left' | 'right' | 'top' | 'bottom'
|
|
241
|
+
| 'center'
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Plugin Data Interface
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
declare module '@knotx/core' {
|
|
248
|
+
interface PluginData {
|
|
249
|
+
bounding: {
|
|
250
|
+
getCustomResizeHandleAttributes: (nodeId: string, position: ResizeHandlePosition) => Record<string, string>
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Default Configuration
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const DEFAULT_RESIZE_HANDLES: ResizeHandlePosition[] = [
|
|
260
|
+
'top-left',
|
|
261
|
+
'top-right',
|
|
262
|
+
'bottom-left',
|
|
263
|
+
'bottom-right'
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
const DEFAULT_CONNECT_HANDLE_POSITIONS = [
|
|
267
|
+
{ top: true },
|
|
268
|
+
{ right: true },
|
|
269
|
+
{ bottom: true },
|
|
270
|
+
{ left: true }
|
|
271
|
+
]
|
|
272
|
+
|
|
273
|
+
const DEFAULT_CONFIG = {
|
|
274
|
+
features: {
|
|
275
|
+
resize: true,
|
|
276
|
+
connect: true,
|
|
277
|
+
boundingBox: true
|
|
278
|
+
},
|
|
279
|
+
sizes: {
|
|
280
|
+
resizeHandle: 6,
|
|
281
|
+
connectHandle: 8,
|
|
282
|
+
boundingBoxThreshold: 200
|
|
283
|
+
},
|
|
284
|
+
styles: {
|
|
285
|
+
resizeHandle: {
|
|
286
|
+
fill: '#3b82f6',
|
|
287
|
+
stroke: '#ffffff',
|
|
288
|
+
strokeWidth: 1
|
|
289
|
+
},
|
|
290
|
+
connectHandle: {
|
|
291
|
+
fill: '#10b981',
|
|
292
|
+
stroke: '#ffffff',
|
|
293
|
+
strokeWidth: 1,
|
|
294
|
+
shadowColor: '#000000',
|
|
295
|
+
shadowWidth: 1
|
|
296
|
+
},
|
|
297
|
+
boundingBox: {
|
|
298
|
+
stroke: '#3b82f6',
|
|
299
|
+
strokeWidth: 1
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
resize: {
|
|
303
|
+
minWidth: 50,
|
|
304
|
+
minHeight: 30,
|
|
305
|
+
inertia: false,
|
|
306
|
+
handles: DEFAULT_RESIZE_HANDLES,
|
|
307
|
+
nodesType: []
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Interactive Features
|
|
313
|
+
|
|
314
|
+
### Resize Functionality
|
|
315
|
+
|
|
316
|
+
- **Multi-position Handles**: Supports resize handles in 8 directions
|
|
317
|
+
- **Minimum Size**: Configurable minimum width and height for nodes
|
|
318
|
+
- **Inertia Effect**: Support for enabling/disabling inertia effects
|
|
319
|
+
- **Node Type Filtering**: Specify which node types can be resized
|
|
320
|
+
|
|
321
|
+
### Connection Point Functionality
|
|
322
|
+
|
|
323
|
+
- **Edge Connection Points**: Provides connection points at the four edges of nodes
|
|
324
|
+
- **Custom Styling**: Support for custom connection point styles and shadow effects
|
|
325
|
+
- **Dynamic Display**: Dynamically show/hide connection points based on interaction state
|
|
326
|
+
|
|
327
|
+
### Bounding Box Functionality
|
|
328
|
+
|
|
329
|
+
- **Selection Indicator**: Shows bounding box for selected nodes
|
|
330
|
+
- **Size Threshold**: Only shows bounding box when node size exceeds threshold
|
|
331
|
+
- **Custom Styling**: Support for custom bounding box styles
|
|
332
|
+
|
|
333
|
+
## Event Handling
|
|
334
|
+
|
|
335
|
+
### Resize Events
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
interface ResizeEvent {
|
|
339
|
+
nodeId: string
|
|
340
|
+
startWidth: number
|
|
341
|
+
startHeight: number
|
|
342
|
+
startX: number
|
|
343
|
+
startY: number
|
|
344
|
+
position: string
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Resize Data
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
interface ResizeData {
|
|
352
|
+
nodeId: string
|
|
353
|
+
width: number
|
|
354
|
+
height: number
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## File Directory Structure
|
|
359
|
+
|
|
360
|
+
```
|
|
361
|
+
packages/plugins-bounding/
|
|
362
|
+
├── src/
|
|
363
|
+
│ ├── bounding.tsx # Bounding plugin main file
|
|
364
|
+
│ └── index.ts # Export file
|
|
365
|
+
├── dist/ # Build output directory
|
|
366
|
+
├── CHANGELOG.md # Change log
|
|
367
|
+
├── package.json # Package configuration
|
|
368
|
+
├── build.config.ts # Build configuration
|
|
369
|
+
├── eslint.config.mjs # ESLint configuration
|
|
370
|
+
└── tsconfig.json # TypeScript configuration
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## License
|
|
374
|
+
|
|
375
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# @knotx/plugins-bounding
|
|
2
|
+
|
|
3
|
+
边界框插件,为节点提供缩放和连接点功能。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-bounding
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 基本概述
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-bounding` 是 KnotX 框架的边界框插件,为节点提供缩放(resize)和连接点(connect handle)功能。支持多种缩放手柄位置、自定义样式、最小尺寸限制和惯性效果。
|
|
14
|
+
|
|
15
|
+
## 实现原理
|
|
16
|
+
|
|
17
|
+
该插件通过 InteractJS 实现交互功能:
|
|
18
|
+
|
|
19
|
+
1. **缩放手柄**:在节点周围提供可拖拽的缩放手柄
|
|
20
|
+
2. **连接点**:在节点边缘提供连接点,用于节点间连接
|
|
21
|
+
3. **边界框**:为选中节点显示边界框
|
|
22
|
+
4. **交互处理**:处理缩放和连接的拖拽交互
|
|
23
|
+
|
|
24
|
+
## 依赖插件
|
|
25
|
+
|
|
26
|
+
该插件依赖以下包:
|
|
27
|
+
|
|
28
|
+
- `@knotx/core` - 核心功能
|
|
29
|
+
- `@knotx/decorators` - 装饰器支持
|
|
30
|
+
- `@knotx/plugins-canvas` - 画布插件(peer dependency)
|
|
31
|
+
- `@knotx/jsx` - JSX 支持(peer dependency)
|
|
32
|
+
- `@knotx/render` - 渲染工具
|
|
33
|
+
- `interactjs` - 交互库
|
|
34
|
+
- `rxjs` - 响应式编程
|
|
35
|
+
|
|
36
|
+
## API 使用
|
|
37
|
+
|
|
38
|
+
### 基本使用
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Bounding } from '@knotx/plugins-bounding'
|
|
42
|
+
|
|
43
|
+
// 创建边界框插件实例
|
|
44
|
+
const bounding = new Bounding()
|
|
45
|
+
|
|
46
|
+
// 在引擎中注册插件
|
|
47
|
+
engine.use(bounding)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 配置选项
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const bounding = new Bounding().init({
|
|
54
|
+
features: {
|
|
55
|
+
resize: true,
|
|
56
|
+
connect: true,
|
|
57
|
+
boundingBox: true
|
|
58
|
+
},
|
|
59
|
+
sizes: {
|
|
60
|
+
resizeHandle: 6,
|
|
61
|
+
connectHandle: 8,
|
|
62
|
+
boundingBoxThreshold: 200
|
|
63
|
+
},
|
|
64
|
+
styles: {
|
|
65
|
+
resizeHandle: {
|
|
66
|
+
fill: '#3b82f6',
|
|
67
|
+
stroke: '#ffffff',
|
|
68
|
+
strokeWidth: 1
|
|
69
|
+
},
|
|
70
|
+
connectHandle: {
|
|
71
|
+
fill: '#10b981',
|
|
72
|
+
stroke: '#ffffff',
|
|
73
|
+
strokeWidth: 1,
|
|
74
|
+
shadowColor: '#000000',
|
|
75
|
+
shadowWidth: 1
|
|
76
|
+
},
|
|
77
|
+
boundingBox: {
|
|
78
|
+
stroke: '#3b82f6',
|
|
79
|
+
strokeWidth: 1
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
resize: {
|
|
83
|
+
minWidth: 50,
|
|
84
|
+
minHeight: 30,
|
|
85
|
+
inertia: false,
|
|
86
|
+
handles: ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'left', 'right', 'top', 'bottom'],
|
|
87
|
+
nodesType: ['default', 'custom']
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 自定义缩放手柄属性
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const { getCustomResizeHandleAttributes } = useKnotX().bounding
|
|
96
|
+
|
|
97
|
+
// 为自定义节点添加缩放手柄
|
|
98
|
+
function ResizableNode({ node }) {
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ position: 'relative' }}>
|
|
101
|
+
<div>{node.data.label}</div>
|
|
102
|
+
|
|
103
|
+
{/* 右下角缩放手柄 */}
|
|
104
|
+
<div
|
|
105
|
+
{...getCustomResizeHandleAttributes(node.id, 'bottom-right')}
|
|
106
|
+
style={{
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
right: -3,
|
|
109
|
+
bottom: -3,
|
|
110
|
+
width: 6,
|
|
111
|
+
height: 6,
|
|
112
|
+
backgroundColor: '#3b82f6',
|
|
113
|
+
border: '1px solid #ffffff',
|
|
114
|
+
borderRadius: '50%',
|
|
115
|
+
cursor: 'nw-resize'
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 完整示例
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { Engine } from '@knotx/core'
|
|
127
|
+
import { Bounding } from '@knotx/plugins-bounding'
|
|
128
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
129
|
+
|
|
130
|
+
const engine = new Engine()
|
|
131
|
+
|
|
132
|
+
// 注册依赖插件
|
|
133
|
+
engine.use(new Canvas())
|
|
134
|
+
|
|
135
|
+
// 注册边界框插件
|
|
136
|
+
engine.use(new Bounding().init({
|
|
137
|
+
features: {
|
|
138
|
+
resize: true,
|
|
139
|
+
connect: true,
|
|
140
|
+
boundingBox: true
|
|
141
|
+
},
|
|
142
|
+
sizes: {
|
|
143
|
+
resizeHandle: 8,
|
|
144
|
+
connectHandle: 10,
|
|
145
|
+
boundingBoxThreshold: 150
|
|
146
|
+
},
|
|
147
|
+
styles: {
|
|
148
|
+
resizeHandle: {
|
|
149
|
+
fill: '#ec4899',
|
|
150
|
+
stroke: '#ffffff',
|
|
151
|
+
strokeWidth: 2
|
|
152
|
+
},
|
|
153
|
+
connectHandle: {
|
|
154
|
+
fill: '#06b6d4',
|
|
155
|
+
stroke: '#ffffff',
|
|
156
|
+
strokeWidth: 2,
|
|
157
|
+
shadowColor: 'rgba(0, 0, 0, 0.2)',
|
|
158
|
+
shadowWidth: 2
|
|
159
|
+
},
|
|
160
|
+
boundingBox: {
|
|
161
|
+
stroke: '#ec4899',
|
|
162
|
+
strokeWidth: 2
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
resize: {
|
|
166
|
+
minWidth: 80,
|
|
167
|
+
minHeight: 50,
|
|
168
|
+
inertia: true,
|
|
169
|
+
handles: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
|
|
170
|
+
nodesType: ['default']
|
|
171
|
+
}
|
|
172
|
+
}))
|
|
173
|
+
|
|
174
|
+
// 创建可缩放节点
|
|
175
|
+
engine.dispatchNodeOperation({
|
|
176
|
+
type: 'add',
|
|
177
|
+
node: {
|
|
178
|
+
id: 'resizable-node',
|
|
179
|
+
type: 'default',
|
|
180
|
+
position: { x: 100, y: 100 },
|
|
181
|
+
measured: { width: 120, height: 80 },
|
|
182
|
+
data: { label: '可缩放节点' }
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## 配置接口
|
|
188
|
+
|
|
189
|
+
### BoundingConfig
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
interface BoundingConfig {
|
|
193
|
+
// 功能开关
|
|
194
|
+
features?: {
|
|
195
|
+
resize?: boolean
|
|
196
|
+
connect?: boolean
|
|
197
|
+
boundingBox?: boolean
|
|
198
|
+
}
|
|
199
|
+
// 尺寸配置
|
|
200
|
+
sizes?: {
|
|
201
|
+
resizeHandle?: number
|
|
202
|
+
connectHandle?: number
|
|
203
|
+
boundingBoxThreshold?: number
|
|
204
|
+
}
|
|
205
|
+
// 样式配置
|
|
206
|
+
styles?: {
|
|
207
|
+
resizeHandle?: {
|
|
208
|
+
fill?: string
|
|
209
|
+
stroke?: string
|
|
210
|
+
strokeWidth?: number
|
|
211
|
+
}
|
|
212
|
+
connectHandle?: {
|
|
213
|
+
fill?: string
|
|
214
|
+
stroke?: string
|
|
215
|
+
strokeWidth?: number
|
|
216
|
+
shadowColor?: string
|
|
217
|
+
shadowWidth?: number
|
|
218
|
+
}
|
|
219
|
+
boundingBox?: {
|
|
220
|
+
stroke?: string
|
|
221
|
+
strokeWidth?: number
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// resize 配置
|
|
225
|
+
resize?: {
|
|
226
|
+
minWidth?: number
|
|
227
|
+
minHeight?: number
|
|
228
|
+
inertia?: boolean
|
|
229
|
+
handles?: ResizeHandlePosition[]
|
|
230
|
+
nodesType?: string[]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### ResizeHandlePosition
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
type ResizeHandlePosition =
|
|
239
|
+
| 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
240
|
+
| 'left' | 'right' | 'top' | 'bottom'
|
|
241
|
+
| 'center'
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 插件数据接口
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
declare module '@knotx/core' {
|
|
248
|
+
interface PluginData {
|
|
249
|
+
bounding: {
|
|
250
|
+
getCustomResizeHandleAttributes: (nodeId: string, position: ResizeHandlePosition) => Record<string, string>
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## 默认配置
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const DEFAULT_RESIZE_HANDLES: ResizeHandlePosition[] = [
|
|
260
|
+
'top-left',
|
|
261
|
+
'top-right',
|
|
262
|
+
'bottom-left',
|
|
263
|
+
'bottom-right'
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
const DEFAULT_CONNECT_HANDLE_POSITIONS = [
|
|
267
|
+
{ top: true },
|
|
268
|
+
{ right: true },
|
|
269
|
+
{ bottom: true },
|
|
270
|
+
{ left: true }
|
|
271
|
+
]
|
|
272
|
+
|
|
273
|
+
const DEFAULT_CONFIG = {
|
|
274
|
+
features: {
|
|
275
|
+
resize: true,
|
|
276
|
+
connect: true,
|
|
277
|
+
boundingBox: true
|
|
278
|
+
},
|
|
279
|
+
sizes: {
|
|
280
|
+
resizeHandle: 6,
|
|
281
|
+
connectHandle: 8,
|
|
282
|
+
boundingBoxThreshold: 200
|
|
283
|
+
},
|
|
284
|
+
styles: {
|
|
285
|
+
resizeHandle: {
|
|
286
|
+
fill: '#3b82f6',
|
|
287
|
+
stroke: '#ffffff',
|
|
288
|
+
strokeWidth: 1
|
|
289
|
+
},
|
|
290
|
+
connectHandle: {
|
|
291
|
+
fill: '#10b981',
|
|
292
|
+
stroke: '#ffffff',
|
|
293
|
+
strokeWidth: 1,
|
|
294
|
+
shadowColor: '#000000',
|
|
295
|
+
shadowWidth: 1
|
|
296
|
+
},
|
|
297
|
+
boundingBox: {
|
|
298
|
+
stroke: '#3b82f6',
|
|
299
|
+
strokeWidth: 1
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
resize: {
|
|
303
|
+
minWidth: 50,
|
|
304
|
+
minHeight: 30,
|
|
305
|
+
inertia: false,
|
|
306
|
+
handles: DEFAULT_RESIZE_HANDLES,
|
|
307
|
+
nodesType: []
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## 交互功能
|
|
313
|
+
|
|
314
|
+
### 缩放功能
|
|
315
|
+
|
|
316
|
+
- **多位置手柄**:支持 8 个方向的缩放手柄
|
|
317
|
+
- **最小尺寸**:可配置节点的最小宽度和高度
|
|
318
|
+
- **惯性效果**:支持启用/禁用惯性效果
|
|
319
|
+
- **节点类型过滤**:可指定哪些节点类型可以缩放
|
|
320
|
+
|
|
321
|
+
### 连接点功能
|
|
322
|
+
|
|
323
|
+
- **边缘连接点**:在节点四个边缘提供连接点
|
|
324
|
+
- **自定义样式**:支持自定义连接点的样式和阴影效果
|
|
325
|
+
- **动态显示**:根据交互状态动态显示/隐藏连接点
|
|
326
|
+
|
|
327
|
+
### 边界框功能
|
|
328
|
+
|
|
329
|
+
- **选择指示**:为选中节点显示边界框
|
|
330
|
+
- **尺寸阈值**:当节点尺寸超过阈值时才显示边界框
|
|
331
|
+
- **自定义样式**:支持自定义边界框的样式
|
|
332
|
+
|
|
333
|
+
## 事件处理
|
|
334
|
+
|
|
335
|
+
### 缩放事件
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
interface ResizeEvent {
|
|
339
|
+
nodeId: string
|
|
340
|
+
startWidth: number
|
|
341
|
+
startHeight: number
|
|
342
|
+
startX: number
|
|
343
|
+
startY: number
|
|
344
|
+
position: string
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### 缩放数据
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
interface ResizeData {
|
|
352
|
+
nodeId: string
|
|
353
|
+
width: number
|
|
354
|
+
height: number
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## 文件目录结构
|
|
359
|
+
|
|
360
|
+
```
|
|
361
|
+
packages/plugins-bounding/
|
|
362
|
+
├── src/
|
|
363
|
+
│ ├── bounding.tsx # 边界框插件主文件
|
|
364
|
+
│ └── index.ts # 导出文件
|
|
365
|
+
├── dist/ # 编译输出目录
|
|
366
|
+
├── CHANGELOG.md # 变更日志
|
|
367
|
+
├── package.json # 包配置
|
|
368
|
+
├── build.config.ts # 构建配置
|
|
369
|
+
├── eslint.config.mjs # ESLint 配置
|
|
370
|
+
└── tsconfig.json # TypeScript 配置
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## 许可证
|
|
374
|
+
|
|
375
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-bounding",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Bounding Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@knotx/jsx": "0.4.
|
|
32
|
-
"@knotx/plugins-canvas": "0.4.
|
|
31
|
+
"@knotx/jsx": "0.4.13",
|
|
32
|
+
"@knotx/plugins-canvas": "0.4.13"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@interactjs/actions": "^1.10.27",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"@interactjs/types": "^1.10.27",
|
|
39
39
|
"interactjs": "^1.10.27",
|
|
40
40
|
"rxjs": "^7.8.1",
|
|
41
|
-
"@knotx/core": "0.4.
|
|
42
|
-
"@knotx/decorators": "0.4.
|
|
43
|
-
"@knotx/render": "0.4.
|
|
41
|
+
"@knotx/core": "0.4.13",
|
|
42
|
+
"@knotx/decorators": "0.4.13",
|
|
43
|
+
"@knotx/render": "0.4.13"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@knotx/build-config": "0.4.
|
|
47
|
-
"@knotx/eslint-config": "0.4.
|
|
48
|
-
"@knotx/jsx": "0.4.
|
|
49
|
-
"@knotx/plugins-canvas": "0.4.
|
|
50
|
-
"@knotx/typescript-config": "0.4.
|
|
46
|
+
"@knotx/build-config": "0.4.13",
|
|
47
|
+
"@knotx/eslint-config": "0.4.13",
|
|
48
|
+
"@knotx/jsx": "0.4.13",
|
|
49
|
+
"@knotx/plugins-canvas": "0.4.13",
|
|
50
|
+
"@knotx/typescript-config": "0.4.13"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "unbuild",
|