@logicflow/core 2.2.0-alpha.7 → 2.2.1
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/package.json +6 -1
- package/.turbo/turbo-build$colon$dev.log +0 -10
- package/.turbo/turbo-build.log +0 -33
- package/CHANGELOG.md +0 -1901
- package/__tests__/algorithm/egde.test.ts +0 -131
- package/__tests__/algorithm/index.test.ts +0 -74
- package/__tests__/algorithm/outline.test.ts +0 -43
- package/__tests__/bugs/1545-spec.test.ts +0 -42
- package/__tests__/event/event.test.ts +0 -22
- package/__tests__/history/history.test.ts +0 -28
- package/__tests__/logicflow.test.ts +0 -575
- package/__tests__/model/graphmodel.test.ts +0 -87
- package/__tests__/util/compatible.test.ts +0 -48
- package/__tests__/util/edge.test.ts +0 -224
- package/__tests__/util/geometry.test.ts +0 -14
- package/__tests__/util/graph.test.ts +0 -16
- package/__tests__/util/matrix.test.ts +0 -41
- package/__tests__/util/node.test.ts +0 -68
- package/__tests__/util/sampling.test.ts +0 -12
- package/__tests__/util/vector.test.ts +0 -50
- package/__tests__/util/zIndex.test.ts +0 -10
- package/src/LogicFlow.tsx +0 -2017
- package/src/algorithm/edge.ts +0 -67
- package/src/algorithm/index.ts +0 -70
- package/src/algorithm/outline.ts +0 -77
- package/src/algorithm/rotate.ts +0 -55
- package/src/common/drag.ts +0 -219
- package/src/common/history.ts +0 -108
- package/src/common/index.ts +0 -6
- package/src/common/keyboard.ts +0 -108
- package/src/common/matrix.ts +0 -122
- package/src/common/vector.ts +0 -93
- package/src/constant/index.ts +0 -179
- package/src/constant/theme.ts +0 -708
- package/src/event/event.md +0 -66
- package/src/event/eventArgs.ts +0 -643
- package/src/event/eventEmitter.ts +0 -156
- package/src/history/index.ts +0 -119
- package/src/index.less +0 -1
- package/src/index.ts +0 -26
- package/src/keyboard/index.ts +0 -112
- package/src/keyboard/shortcut.ts +0 -200
- package/src/model/BaseModel.ts +0 -250
- package/src/model/EditConfigModel.ts +0 -334
- package/src/model/GraphModel.ts +0 -1824
- package/src/model/NestedTransformModel.ts +0 -121
- package/src/model/SnaplineModel.ts +0 -256
- package/src/model/TransformModel.ts +0 -258
- package/src/model/edge/BaseEdgeModel.ts +0 -785
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -817
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -959
- package/src/model/node/CircleNodeModel.ts +0 -91
- package/src/model/node/DiamondNodeModel.ts +0 -132
- package/src/model/node/EllipseNodeModel.ts +0 -98
- package/src/model/node/HtmlNodeModel.ts +0 -64
- package/src/model/node/PolygonNodeModel.ts +0 -152
- package/src/model/node/RectNodeModel.ts +0 -69
- package/src/model/node/TextNodeModel.ts +0 -54
- package/src/model/node/index.ts +0 -8
- package/src/options.ts +0 -150
- package/src/style/index.less +0 -262
- package/src/style/raw.ts +0 -221
- package/src/tool/MultipleSelectTool.tsx +0 -140
- package/src/tool/TextEditTool.tsx +0 -193
- package/src/tool/index.ts +0 -101
- package/src/typings.d.ts +0 -5
- package/src/util/animation.ts +0 -29
- package/src/util/browser.ts +0 -4
- package/src/util/compatible.ts +0 -15
- package/src/util/drag.ts +0 -219
- package/src/util/edge.ts +0 -1094
- package/src/util/geometry.ts +0 -154
- package/src/util/graph.ts +0 -46
- package/src/util/index.ts +0 -17
- package/src/util/matrix.ts +0 -129
- package/src/util/mobx.ts +0 -23
- package/src/util/node.ts +0 -543
- package/src/util/raf.ts +0 -28
- package/src/util/resize.ts +0 -606
- package/src/util/sampling.ts +0 -85
- package/src/util/theme.ts +0 -84
- package/src/util/uuid.ts +0 -26
- package/src/util/vector.ts +0 -93
- package/src/util/zIndex.ts +0 -6
- package/src/view/Anchor.tsx +0 -462
- package/src/view/Control.tsx +0 -510
- package/src/view/Graph.tsx +0 -141
- package/src/view/Rotate.tsx +0 -113
- package/src/view/behavior/dnd.ts +0 -162
- package/src/view/behavior/index.ts +0 -2
- package/src/view/behavior/snapline.ts +0 -16
- package/src/view/edge/AdjustPoint.tsx +0 -425
- package/src/view/edge/Arrow.tsx +0 -54
- package/src/view/edge/BaseEdge.tsx +0 -660
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -311
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -585
- package/src/view/node/CircleNode.tsx +0 -21
- package/src/view/node/DiamondNode.tsx +0 -24
- package/src/view/node/EllipseNode.tsx +0 -22
- package/src/view/node/HtmlNode.tsx +0 -112
- package/src/view/node/PolygonNode.tsx +0 -28
- package/src/view/node/RectNode.tsx +0 -30
- package/src/view/node/TextNode.tsx +0 -39
- package/src/view/node/index.ts +0 -8
- package/src/view/overlay/BackgroundOverlay.tsx +0 -34
- package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
- package/src/view/overlay/CanvasOverlay.tsx +0 -290
- package/src/view/overlay/Grid.tsx +0 -319
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -158
- package/src/view/overlay/SnaplineOverlay.tsx +0 -44
- package/src/view/overlay/ToolOverlay.tsx +0 -65
- package/src/view/overlay/getTransformHoc.tsx +0 -50
- package/src/view/overlay/gridConfig.ts +0 -103
- package/src/view/overlay/index.ts +0 -8
- package/src/view/shape/Circle.tsx +0 -41
- package/src/view/shape/Ellipse.tsx +0 -42
- package/src/view/shape/Line.tsx +0 -39
- package/src/view/shape/Path.tsx +0 -22
- package/src/view/shape/Polygon.tsx +0 -54
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -168
- package/src/view/shape/index.ts +0 -8
- package/src/view/text/BaseText.tsx +0 -134
- package/src/view/text/LineText.tsx +0 -168
- package/src/view/text/index.ts +0 -2
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import { cloneDeep, assign, isNil } from 'lodash-es'
|
|
3
|
-
import { observer } from '../..'
|
|
4
|
-
import { mergeMajorBoldConfig, MajorBoldConfig } from './gridConfig'
|
|
5
|
-
import { createUuid } from '../../util'
|
|
6
|
-
import { GraphModel } from '../../model'
|
|
7
|
-
import { defaultGrid } from '../../constant'
|
|
8
|
-
|
|
9
|
-
type IProps = {
|
|
10
|
-
graphModel: GraphModel
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@observer
|
|
14
|
-
export class Grid extends Component<IProps> {
|
|
15
|
-
gridOptions: Grid.GridOptions
|
|
16
|
-
|
|
17
|
-
readonly id = createUuid()
|
|
18
|
-
|
|
19
|
-
constructor(props: IProps) {
|
|
20
|
-
super(props)
|
|
21
|
-
this.gridOptions = this.props.graphModel.grid
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// 网格类型为点状
|
|
25
|
-
renderDot() {
|
|
26
|
-
const { config, size = 1, visible } = this.gridOptions
|
|
27
|
-
|
|
28
|
-
const { color, thickness = 2 } = config ?? {}
|
|
29
|
-
|
|
30
|
-
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
31
|
-
const radius = Math.min(Math.max(2, thickness), size / 4)
|
|
32
|
-
const opacity = visible ? 1 : 0
|
|
33
|
-
return (
|
|
34
|
-
<g fill={color} opacity={opacity}>
|
|
35
|
-
<circle cx={0} cy={0} r={radius / 2} />
|
|
36
|
-
<circle cx={0} cy={size} r={radius / 2} />
|
|
37
|
-
<circle cx={size} cy={0} r={radius / 2} />
|
|
38
|
-
<circle cx={size} cy={size} r={radius / 2} />
|
|
39
|
-
</g>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 计算与 size 整除的虚线周期,使边长能被 (dash + gap) 完整分割
|
|
44
|
-
private getDashArrayForSize(dashCfg?: { pattern: number[] }): string {
|
|
45
|
-
// 若提供了直接可用的 pattern,则优先使用
|
|
46
|
-
const direct = dashCfg?.pattern?.filter(
|
|
47
|
-
(n) => typeof n === 'number' && n > 0,
|
|
48
|
-
)
|
|
49
|
-
return direct?.join(',') || '2,1'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 计算一个周期内的最大加粗索引(作为周期大小)
|
|
53
|
-
private getPeriod(advanced: any): number {
|
|
54
|
-
const list = Array.isArray(advanced?.boldIndices)
|
|
55
|
-
? advanced.boldIndices.filter((n: any) => typeof n === 'number' && n > 0)
|
|
56
|
-
: []
|
|
57
|
-
return list.length ? Math.max(...list) : 0
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 计算加粗线宽,优先使用自定义;否则根据周期与厚度估算
|
|
61
|
-
private getBoldStrokeWidth(
|
|
62
|
-
advanced: any,
|
|
63
|
-
size: number,
|
|
64
|
-
thickness?: number,
|
|
65
|
-
period?: number,
|
|
66
|
-
): number {
|
|
67
|
-
if (typeof advanced?.customBoldWidth === 'number')
|
|
68
|
-
return advanced.customBoldWidth
|
|
69
|
-
const baseThickness = Math.max(1, thickness ?? 1)
|
|
70
|
-
const p = Math.max(1, period ?? this.getPeriod(advanced))
|
|
71
|
-
return Math.min(baseThickness, (size * p) / 2) / 2
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 渲染 mesh 类型四条边的虚线,减少重复代码
|
|
75
|
-
private renderMeshEdgeLines(
|
|
76
|
-
size: number,
|
|
77
|
-
color: string,
|
|
78
|
-
strokeWidth: number,
|
|
79
|
-
opacity: number,
|
|
80
|
-
dash?: string,
|
|
81
|
-
) {
|
|
82
|
-
const segments = [
|
|
83
|
-
{ d: `M 0 0 H ${size}` },
|
|
84
|
-
{ d: `M 0 ${size} H ${size}` },
|
|
85
|
-
{ d: `M 0 0 V ${size}` },
|
|
86
|
-
{ d: `M ${size} 0 V ${size}` },
|
|
87
|
-
]
|
|
88
|
-
return (
|
|
89
|
-
<g opacity={opacity} fill="transparent">
|
|
90
|
-
{segments.map((seg) => (
|
|
91
|
-
<path
|
|
92
|
-
d={seg.d}
|
|
93
|
-
stroke={color}
|
|
94
|
-
strokeWidth={strokeWidth / 2}
|
|
95
|
-
strokeDasharray={dash}
|
|
96
|
-
strokeLinecap="butt"
|
|
97
|
-
fill="transparent"
|
|
98
|
-
/>
|
|
99
|
-
))}
|
|
100
|
-
</g>
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 网格类型为交叉线
|
|
105
|
-
// todo: 采用背景缩放的方式,实现更好的体验
|
|
106
|
-
renderMesh() {
|
|
107
|
-
const {
|
|
108
|
-
config,
|
|
109
|
-
size = 1,
|
|
110
|
-
visible,
|
|
111
|
-
majorBold,
|
|
112
|
-
} = this.gridOptions as Grid.GridOptions & {
|
|
113
|
-
majorBold?: boolean | MajorBoldConfig
|
|
114
|
-
}
|
|
115
|
-
const { config: advanced } = mergeMajorBoldConfig(majorBold)
|
|
116
|
-
const { opacity: baseOpacity } = advanced
|
|
117
|
-
const color: string = (config?.color ?? '#D7DEEB') as string
|
|
118
|
-
const thickness: number = (config?.thickness ?? 1) as number
|
|
119
|
-
|
|
120
|
-
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
121
|
-
const strokeWidth = Math.min(Math.max(1, thickness), size / 2)
|
|
122
|
-
const opacity = visible ? baseOpacity : 0
|
|
123
|
-
|
|
124
|
-
// 根据 size 自动计算合适的 dash/gap 周期,使 size 能被 (dash + gap) 整除
|
|
125
|
-
const dash =
|
|
126
|
-
majorBold === false
|
|
127
|
-
? undefined
|
|
128
|
-
: this.getDashArrayForSize(advanced.dashArrayConfig)
|
|
129
|
-
return this.renderMeshEdgeLines(size, color, strokeWidth, opacity, dash)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
render() {
|
|
133
|
-
const {
|
|
134
|
-
graphModel: { transformModel, grid },
|
|
135
|
-
} = this.props
|
|
136
|
-
this.gridOptions = grid
|
|
137
|
-
const {
|
|
138
|
-
type,
|
|
139
|
-
config = {},
|
|
140
|
-
size = 1,
|
|
141
|
-
majorBold,
|
|
142
|
-
} = this.gridOptions as Grid.GridOptions & {
|
|
143
|
-
majorBold?: boolean | MajorBoldConfig
|
|
144
|
-
}
|
|
145
|
-
const showMajorBold = majorBold !== false && !isNil(majorBold)
|
|
146
|
-
const { config: advanced } = mergeMajorBoldConfig(majorBold)
|
|
147
|
-
const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
|
|
148
|
-
transformModel
|
|
149
|
-
const matrixString = [
|
|
150
|
-
SCALE_X,
|
|
151
|
-
SKEW_Y,
|
|
152
|
-
SKEW_X,
|
|
153
|
-
SCALE_Y,
|
|
154
|
-
TRANSLATE_X,
|
|
155
|
-
TRANSLATE_Y,
|
|
156
|
-
].join(',')
|
|
157
|
-
const transform = `matrix(${matrixString})`
|
|
158
|
-
const radius = Math.min(Math.max(2, config.thickness ?? 1), size / 4)
|
|
159
|
-
const opacity = showMajorBold ? advanced.opacity : 1
|
|
160
|
-
return (
|
|
161
|
-
<div className="lf-grid">
|
|
162
|
-
<svg
|
|
163
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
164
|
-
version="1.1"
|
|
165
|
-
width="100%"
|
|
166
|
-
height="100%"
|
|
167
|
-
>
|
|
168
|
-
<defs>
|
|
169
|
-
<pattern
|
|
170
|
-
id={this.id}
|
|
171
|
-
patternUnits="userSpaceOnUse"
|
|
172
|
-
patternTransform={transform}
|
|
173
|
-
x="0"
|
|
174
|
-
y="0"
|
|
175
|
-
width={size}
|
|
176
|
-
height={size}
|
|
177
|
-
>
|
|
178
|
-
{type === 'dot' && this.renderDot()}
|
|
179
|
-
{type === 'mesh' && this.renderMesh()}
|
|
180
|
-
</pattern>
|
|
181
|
-
{type === 'dot' && advanced.boldIndices.length ? (
|
|
182
|
-
<pattern
|
|
183
|
-
id={`${this.id}-dot-major`}
|
|
184
|
-
patternUnits="userSpaceOnUse"
|
|
185
|
-
patternTransform={transform}
|
|
186
|
-
x="0"
|
|
187
|
-
y="0"
|
|
188
|
-
width={size * this.getPeriod(advanced)}
|
|
189
|
-
height={size * this.getPeriod(advanced)}
|
|
190
|
-
>
|
|
191
|
-
<g
|
|
192
|
-
fill={this.gridOptions.config?.color ?? '#D7DEEB'}
|
|
193
|
-
opacity={this.gridOptions.visible ? opacity : 0}
|
|
194
|
-
>
|
|
195
|
-
<circle cx={0} cy={0} r={(radius * 1.5) / 2} />
|
|
196
|
-
<circle
|
|
197
|
-
cx={size * this.getPeriod(advanced)}
|
|
198
|
-
cy={0}
|
|
199
|
-
r={(radius * 1.5) / 2}
|
|
200
|
-
/>
|
|
201
|
-
<circle
|
|
202
|
-
cx={0}
|
|
203
|
-
cy={size * this.getPeriod(advanced)}
|
|
204
|
-
r={(radius * 1.5) / 2}
|
|
205
|
-
/>
|
|
206
|
-
<circle
|
|
207
|
-
cx={size * this.getPeriod(advanced)}
|
|
208
|
-
cy={size * this.getPeriod(advanced)}
|
|
209
|
-
r={(radius * 1.5) / 2}
|
|
210
|
-
/>
|
|
211
|
-
</g>
|
|
212
|
-
</pattern>
|
|
213
|
-
) : null}
|
|
214
|
-
{type === 'mesh' && advanced.boldIndices.length ? (
|
|
215
|
-
<pattern
|
|
216
|
-
id={`${this.id}-major`}
|
|
217
|
-
patternUnits="userSpaceOnUse"
|
|
218
|
-
patternTransform={transform}
|
|
219
|
-
x="0"
|
|
220
|
-
y="0"
|
|
221
|
-
width={size * this.getPeriod(advanced)}
|
|
222
|
-
height={size * this.getPeriod(advanced)}
|
|
223
|
-
>
|
|
224
|
-
{advanced.boldIndices.map((i: number) => (
|
|
225
|
-
<g>
|
|
226
|
-
<path
|
|
227
|
-
d={`M ${size * i} 0 V ${size * this.getPeriod(advanced)}`}
|
|
228
|
-
stroke={this.gridOptions.config?.color ?? '#D7DEEB'}
|
|
229
|
-
strokeWidth={this.getBoldStrokeWidth(
|
|
230
|
-
advanced,
|
|
231
|
-
size,
|
|
232
|
-
(this.gridOptions.config ?? {}).thickness,
|
|
233
|
-
this.getPeriod(advanced),
|
|
234
|
-
)}
|
|
235
|
-
opacity={this.gridOptions.visible ? opacity : 0}
|
|
236
|
-
fill="transparent"
|
|
237
|
-
/>
|
|
238
|
-
<path
|
|
239
|
-
d={`M 0 ${size * i} H ${size * this.getPeriod(advanced)}`}
|
|
240
|
-
stroke={this.gridOptions.config?.color ?? '#D7DEEB'}
|
|
241
|
-
strokeWidth={this.getBoldStrokeWidth(
|
|
242
|
-
advanced,
|
|
243
|
-
size,
|
|
244
|
-
(this.gridOptions.config ?? {}).thickness,
|
|
245
|
-
this.getPeriod(advanced),
|
|
246
|
-
)}
|
|
247
|
-
opacity={this.gridOptions.visible ? opacity : 0}
|
|
248
|
-
fill="transparent"
|
|
249
|
-
/>
|
|
250
|
-
</g>
|
|
251
|
-
))}
|
|
252
|
-
</pattern>
|
|
253
|
-
) : null}
|
|
254
|
-
</defs>
|
|
255
|
-
<rect width="100%" height="100%" fill={`url(#${this.id})`} />
|
|
256
|
-
{type === 'dot' && showMajorBold && advanced.boldIndices.length ? (
|
|
257
|
-
<rect
|
|
258
|
-
width="100%"
|
|
259
|
-
height="100%"
|
|
260
|
-
fill={`url(#${this.id}-dot-major)`}
|
|
261
|
-
/>
|
|
262
|
-
) : null}
|
|
263
|
-
{type === 'mesh' && showMajorBold && advanced.boldIndices.length ? (
|
|
264
|
-
<rect width="100%" height="100%" fill={`url(#${this.id}-major)`} />
|
|
265
|
-
) : null}
|
|
266
|
-
</svg>
|
|
267
|
-
</div>
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export namespace Grid {
|
|
273
|
-
export type GridOptions = {
|
|
274
|
-
/**
|
|
275
|
-
* 网格格子间距
|
|
276
|
-
*/
|
|
277
|
-
size?: number
|
|
278
|
-
/**
|
|
279
|
-
* 网格是否可见
|
|
280
|
-
*/
|
|
281
|
-
visible?: boolean
|
|
282
|
-
/**
|
|
283
|
-
* 网格类型
|
|
284
|
-
* - `dot` 点状网格
|
|
285
|
-
* - `mesh` 交叉线网格
|
|
286
|
-
*/
|
|
287
|
-
type?: 'dot' | 'mesh'
|
|
288
|
-
config?: {
|
|
289
|
-
/**
|
|
290
|
-
* 网格的颜色
|
|
291
|
-
*/
|
|
292
|
-
color?: string
|
|
293
|
-
/**
|
|
294
|
-
* 网格的宽度
|
|
295
|
-
* - 对于 `dot` 点状网格,表示点的大小
|
|
296
|
-
* - 对于 `mesh` 交叉线网格,表示线的宽度
|
|
297
|
-
*/
|
|
298
|
-
thickness?: number
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* 行为配置:支持 boolean 或高级对象
|
|
302
|
-
* - false: 禁用特殊样式,opacity=1,无加粗,无虚线
|
|
303
|
-
* - true: 启用默认样式,opacity=0.75,每第5个加粗/实线,虚线动态计算
|
|
304
|
-
* - object: 高级配置,详见 MajorBoldConfig
|
|
305
|
-
*/
|
|
306
|
-
majorBold?: boolean | MajorBoldConfig
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export function getGridOptions(options: number | boolean | GridOptions) {
|
|
310
|
-
const defaultOptions = cloneDeep(defaultGrid) as GridOptions
|
|
311
|
-
if (typeof options === 'number') {
|
|
312
|
-
return assign(defaultOptions, { size: options })
|
|
313
|
-
} else if (typeof options === 'boolean') {
|
|
314
|
-
return assign(defaultOptions, { visible: options })
|
|
315
|
-
} else {
|
|
316
|
-
return assign(defaultOptions, options)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import { observer } from '../..'
|
|
3
|
-
import GraphModel from '../../model/GraphModel'
|
|
4
|
-
|
|
5
|
-
type IProps = {
|
|
6
|
-
graphModel: GraphModel
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@observer
|
|
10
|
-
export class ModificationOverlay extends Component<IProps> {
|
|
11
|
-
render() {
|
|
12
|
-
const {
|
|
13
|
-
graphModel: { transformModel },
|
|
14
|
-
} = this.props
|
|
15
|
-
const { transform } = transformModel.getTransformStyle()
|
|
16
|
-
const { children } = this.props
|
|
17
|
-
return (
|
|
18
|
-
<svg
|
|
19
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
20
|
-
version="1.1"
|
|
21
|
-
width="100%"
|
|
22
|
-
height="100%"
|
|
23
|
-
className="modification-overlay"
|
|
24
|
-
>
|
|
25
|
-
<g transform={transform}>{children}</g>
|
|
26
|
-
</svg>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default ModificationOverlay
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import { Rect } from '../shape'
|
|
3
|
-
import { observer } from '../..'
|
|
4
|
-
import { ModelType } from '../../constant'
|
|
5
|
-
import {
|
|
6
|
-
GraphModel,
|
|
7
|
-
LineEdgeModel,
|
|
8
|
-
BezierEdgeModel,
|
|
9
|
-
PolylineEdgeModel,
|
|
10
|
-
} from '../../model'
|
|
11
|
-
import { points2PointsList, getBezierPoints, getBBoxOfPoints } from '../../util'
|
|
12
|
-
|
|
13
|
-
type IProps = {
|
|
14
|
-
graphModel: GraphModel
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@observer
|
|
18
|
-
export class OutlineOverlay extends Component<IProps> {
|
|
19
|
-
// 通用渲染函数:根据点集合与样式计算包围盒并返回矩形轮廓
|
|
20
|
-
private renderRectOutline(
|
|
21
|
-
pointsList: any[],
|
|
22
|
-
style: Record<string, unknown>,
|
|
23
|
-
className: string,
|
|
24
|
-
defaultOffsets: { widthOffset: number; heightOffset: number },
|
|
25
|
-
) {
|
|
26
|
-
const {
|
|
27
|
-
widthOffset = defaultOffsets.widthOffset,
|
|
28
|
-
heightOffset = defaultOffsets.heightOffset,
|
|
29
|
-
} = (style || {}) as any
|
|
30
|
-
const { x, y, width, height } = getBBoxOfPoints(
|
|
31
|
-
pointsList,
|
|
32
|
-
widthOffset,
|
|
33
|
-
heightOffset,
|
|
34
|
-
)
|
|
35
|
-
return (
|
|
36
|
-
<Rect className={className} {...{ x, y, width, height }} {...style} />
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
// 节点outline
|
|
40
|
-
getNodesOutline() {
|
|
41
|
-
const { graphModel } = this.props
|
|
42
|
-
const {
|
|
43
|
-
nodes,
|
|
44
|
-
editConfigModel: { hoverOutline, nodeSelectedOutline },
|
|
45
|
-
} = graphModel
|
|
46
|
-
const nodeOutline: any = []
|
|
47
|
-
nodes.forEach((element) => {
|
|
48
|
-
if (element.isHovered || element.isSelected) {
|
|
49
|
-
const { isHovered, isSelected, x, y, width, height } = element
|
|
50
|
-
if (
|
|
51
|
-
(nodeSelectedOutline && isSelected) ||
|
|
52
|
-
(hoverOutline && isHovered)
|
|
53
|
-
) {
|
|
54
|
-
const style = element.getOutlineStyle() || {}
|
|
55
|
-
let attributes = {}
|
|
56
|
-
Object.keys(style).forEach((key) => {
|
|
57
|
-
if (key !== 'hover') {
|
|
58
|
-
attributes[key] = style[key]
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
if (isHovered) {
|
|
62
|
-
const hoverStyle = style.hover
|
|
63
|
-
attributes = {
|
|
64
|
-
...attributes,
|
|
65
|
-
...hoverStyle,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
nodeOutline.push(
|
|
69
|
-
<Rect
|
|
70
|
-
transform={element.transform}
|
|
71
|
-
className="lf-outline-node"
|
|
72
|
-
{...{
|
|
73
|
-
x,
|
|
74
|
-
y,
|
|
75
|
-
width: width + 4,
|
|
76
|
-
height: height + 4,
|
|
77
|
-
}}
|
|
78
|
-
{...attributes}
|
|
79
|
-
/>,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
return nodeOutline
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 边的outline
|
|
88
|
-
getEdgeOutline() {
|
|
89
|
-
const {
|
|
90
|
-
graphModel: {
|
|
91
|
-
edges: edgeList,
|
|
92
|
-
editConfigModel: { edgeSelectedOutline, hoverOutline },
|
|
93
|
-
},
|
|
94
|
-
} = this.props
|
|
95
|
-
const edgeOutline: any = []
|
|
96
|
-
for (let i = 0; i < edgeList.length; i++) {
|
|
97
|
-
const edge = edgeList[i]
|
|
98
|
-
if (
|
|
99
|
-
(edgeSelectedOutline && edge.isSelected) ||
|
|
100
|
-
(hoverOutline && edge.isHovered)
|
|
101
|
-
) {
|
|
102
|
-
if (edge.modelType === ModelType.LINE_EDGE) {
|
|
103
|
-
edgeOutline.push(this.getLineOutline(edge as LineEdgeModel))
|
|
104
|
-
} else if (edge.modelType === ModelType.POLYLINE_EDGE) {
|
|
105
|
-
edgeOutline.push(this.getPolylineOutline(edge as PolylineEdgeModel))
|
|
106
|
-
} else if (edge.modelType === ModelType.BEZIER_EDGE) {
|
|
107
|
-
edgeOutline.push(this.getBezierOutline(edge as BezierEdgeModel))
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return edgeOutline
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 直线outline
|
|
115
|
-
getLineOutline(line: LineEdgeModel) {
|
|
116
|
-
const { startPoint, endPoint } = line
|
|
117
|
-
const style = line.getOutlineStyle()
|
|
118
|
-
return this.renderRectOutline(
|
|
119
|
-
[startPoint, endPoint],
|
|
120
|
-
style,
|
|
121
|
-
'lf-outline-edge',
|
|
122
|
-
{ widthOffset: 10, heightOffset: 10 },
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 折线outline
|
|
127
|
-
getPolylineOutline(polyline: PolylineEdgeModel) {
|
|
128
|
-
const { points } = polyline
|
|
129
|
-
const pointsList = points2PointsList(points)
|
|
130
|
-
const style = polyline.getOutlineStyle()
|
|
131
|
-
return this.renderRectOutline(pointsList, style, 'lf-outline', {
|
|
132
|
-
widthOffset: 8,
|
|
133
|
-
heightOffset: 16,
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 曲线outline
|
|
138
|
-
getBezierOutline(bezier: BezierEdgeModel) {
|
|
139
|
-
const { path } = bezier
|
|
140
|
-
const pointsList = getBezierPoints(path)
|
|
141
|
-
const style = bezier.getOutlineStyle()
|
|
142
|
-
return this.renderRectOutline(pointsList, style, 'lf-outline', {
|
|
143
|
-
widthOffset: 8,
|
|
144
|
-
heightOffset: 16,
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
render() {
|
|
149
|
-
return (
|
|
150
|
-
<g className="lf-outline">
|
|
151
|
-
{this.getNodesOutline()}
|
|
152
|
-
{this.getEdgeOutline()}
|
|
153
|
-
</g>
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export default OutlineOverlay
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import SnaplineModel from '../../model/SnaplineModel'
|
|
3
|
-
import Line from '../shape/Line'
|
|
4
|
-
import { observer } from '../..'
|
|
5
|
-
import OutlineOverlay from './OutlineOverlay'
|
|
6
|
-
|
|
7
|
-
type IProps = {
|
|
8
|
-
snaplineModel?: SnaplineModel
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@observer
|
|
12
|
-
export class SnaplineOverlay extends Component<IProps> {
|
|
13
|
-
render() {
|
|
14
|
-
const { snaplineModel } = this.props
|
|
15
|
-
const { position, isShowHorizontal, isShowVertical } = snaplineModel ?? {}
|
|
16
|
-
const style = snaplineModel?.getStyle()
|
|
17
|
-
const { x = 0, y = 0 } = position ?? {}
|
|
18
|
-
// 展示横向,纵向默认-100000,100000 减少计算量
|
|
19
|
-
const horizontalLine = {
|
|
20
|
-
x1: -100000,
|
|
21
|
-
y1: y,
|
|
22
|
-
x2: 100000,
|
|
23
|
-
y2: y,
|
|
24
|
-
...style,
|
|
25
|
-
stroke: isShowHorizontal ? style?.stroke : 'none',
|
|
26
|
-
}
|
|
27
|
-
const verticalLine = {
|
|
28
|
-
x1: x,
|
|
29
|
-
y1: -100000,
|
|
30
|
-
x2: x,
|
|
31
|
-
y2: 100000,
|
|
32
|
-
...style,
|
|
33
|
-
stroke: isShowVertical ? style?.stroke : 'none',
|
|
34
|
-
}
|
|
35
|
-
return (
|
|
36
|
-
<g className="lf-snapline">
|
|
37
|
-
<Line {...horizontalLine} />
|
|
38
|
-
<Line {...verticalLine} />
|
|
39
|
-
</g>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default OutlineOverlay
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { createElement as h, Component } from 'preact/compat'
|
|
2
|
-
import { OutlineOverlay } from '.'
|
|
3
|
-
import { observer } from '../..'
|
|
4
|
-
import LogicFlow from '../../LogicFlow'
|
|
5
|
-
import { GraphModel } from '../../model'
|
|
6
|
-
import { Tool } from '../../tool'
|
|
7
|
-
|
|
8
|
-
type IProps = {
|
|
9
|
-
graphModel: GraphModel
|
|
10
|
-
tool: Tool
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@observer
|
|
14
|
-
export class ToolOverlay extends Component<IProps> {
|
|
15
|
-
// 在react严格模式下,useEffect会执行两次,但是在LogicFlow内部,则只会触发一次componentDidMount和componentDidUpdate。
|
|
16
|
-
// 其中第一次componentDidMount对应的graphModel为被丢弃的graphModel, 所以不应该生效。
|
|
17
|
-
// 在非react环境下,只会触发一次componentDidMount,不会触发componentDidUpdate。
|
|
18
|
-
// 所以这里采用componentDidUpdate和componentDidMount都去触发插件的render方法。
|
|
19
|
-
componentDidMount(): void {
|
|
20
|
-
this.triggerToolRender()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
componentDidUpdate(): void {
|
|
24
|
-
this.triggerToolRender()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 外部传入的一般是HTMLElement
|
|
29
|
-
*/
|
|
30
|
-
getTools() {
|
|
31
|
-
const { tool, graphModel } = this.props
|
|
32
|
-
const { textEditElement } = graphModel
|
|
33
|
-
const tools = tool.getTools()
|
|
34
|
-
const components = tools.map((t) =>
|
|
35
|
-
h(t, {
|
|
36
|
-
textEditElement,
|
|
37
|
-
graphModel,
|
|
38
|
-
lf: tool.instance,
|
|
39
|
-
}),
|
|
40
|
-
)
|
|
41
|
-
tool.components = components
|
|
42
|
-
return components
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
triggerToolRender() {
|
|
46
|
-
const { tool, graphModel } = this.props
|
|
47
|
-
const ToolOverlayElement = document.querySelector(
|
|
48
|
-
`#ToolOverlay_${graphModel.flowId}`,
|
|
49
|
-
) as HTMLElement
|
|
50
|
-
const lf: LogicFlow = tool.getInstance()
|
|
51
|
-
lf.components.forEach((render) => render(lf, ToolOverlayElement))
|
|
52
|
-
lf.components = [] // 保证extension组件的render只执行一次
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
render() {
|
|
56
|
-
const { graphModel } = this.props
|
|
57
|
-
return (
|
|
58
|
-
<div className="lf-tool-overlay" id={`ToolOverlay_${graphModel.flowId}`}>
|
|
59
|
-
{this.getTools()}
|
|
60
|
-
</div>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default OutlineOverlay
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Component, ComponentType } from 'preact'
|
|
2
|
-
import GraphModel from '../../model/GraphModel'
|
|
3
|
-
|
|
4
|
-
type IProps = {
|
|
5
|
-
graphModel: GraphModel
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type GraphTransform = {
|
|
9
|
-
transform: string
|
|
10
|
-
transformOrigin: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getTransform<P>(WrappedComponent: ComponentType<P>) {
|
|
14
|
-
return class extends Component<IProps & P> {
|
|
15
|
-
getMatrixString(): GraphTransform {
|
|
16
|
-
const { graphModel } = this.props
|
|
17
|
-
const {
|
|
18
|
-
transformModel: {
|
|
19
|
-
SCALE_X,
|
|
20
|
-
SKEW_Y,
|
|
21
|
-
SKEW_X,
|
|
22
|
-
SCALE_Y,
|
|
23
|
-
TRANSLATE_X,
|
|
24
|
-
TRANSLATE_Y,
|
|
25
|
-
},
|
|
26
|
-
} = graphModel
|
|
27
|
-
const matrixString = [
|
|
28
|
-
SCALE_X,
|
|
29
|
-
SKEW_Y,
|
|
30
|
-
SKEW_X,
|
|
31
|
-
SCALE_Y,
|
|
32
|
-
TRANSLATE_X,
|
|
33
|
-
TRANSLATE_Y,
|
|
34
|
-
].join(',')
|
|
35
|
-
return {
|
|
36
|
-
transform: `matrix(${matrixString})`,
|
|
37
|
-
transformOrigin: 'left top',
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
render() {
|
|
42
|
-
return (
|
|
43
|
-
<WrappedComponent
|
|
44
|
-
{...(this.props as P)}
|
|
45
|
-
transformStyle={this.getMatrixString()}
|
|
46
|
-
/>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|