@logicflow/core 2.2.0 → 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/dist/index.css +3 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +9 -0
- package/es/LogicFlow.js +0 -1
- package/es/constant/index.d.ts +1 -1
- package/es/constant/index.js +1 -1
- package/es/constant/theme.d.ts +136 -0
- package/es/constant/theme.js +680 -0
- package/es/index.css +3 -2
- package/es/model/GraphModel.d.ts +10 -2
- package/es/model/GraphModel.js +48 -14
- package/es/model/TransformModel.js +9 -9
- package/es/model/edge/BaseEdgeModel.js +7 -2
- package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/es/model/edge/PolylineEdgeModel.js +136 -7
- package/es/model/node/BaseNodeModel.d.ts +12 -1
- package/es/model/node/BaseNodeModel.js +9 -2
- package/es/model/node/HtmlNodeModel.d.ts +12 -0
- package/es/model/node/HtmlNodeModel.js +19 -0
- package/es/model/node/PolygonNodeModel.js +3 -3
- package/es/options.d.ts +4 -2
- package/es/style/index.css +3 -2
- package/es/style/index.less +3 -2
- package/es/style/raw.d.ts +1 -1
- package/es/style/raw.js +1 -1
- package/es/tool/MultipleSelectTool.js +10 -5
- package/es/util/drag.js +0 -1
- package/es/util/edge.d.ts +40 -1
- package/es/util/edge.js +43 -9
- package/es/util/geometry.d.ts +8 -0
- package/es/util/geometry.js +79 -0
- package/es/util/theme.d.ts +2 -65
- package/es/util/theme.js +4 -281
- package/es/view/Anchor.d.ts +1 -0
- package/es/view/Anchor.js +24 -21
- package/es/view/Control.d.ts +5 -0
- package/es/view/Control.js +44 -57
- package/es/view/edge/BaseEdge.js +9 -0
- package/es/view/edge/PolylineEdge.js +13 -2
- package/es/view/node/BaseNode.d.ts +1 -0
- package/es/view/node/BaseNode.js +23 -11
- package/es/view/node/HtmlNode.js +2 -4
- package/es/view/overlay/CanvasOverlay.js +5 -2
- package/es/view/overlay/Grid.d.ts +12 -1
- package/es/view/overlay/Grid.js +85 -23
- package/es/view/overlay/OutlineOverlay.d.ts +1 -0
- package/es/view/overlay/OutlineOverlay.js +18 -17
- package/es/view/overlay/gridConfig.d.ts +46 -0
- package/es/view/overlay/gridConfig.js +99 -0
- package/es/view/shape/Polygon.d.ts +0 -7
- package/es/view/shape/Polygon.js +12 -43
- package/lib/LogicFlow.d.ts +9 -0
- package/lib/LogicFlow.js +0 -1
- package/lib/constant/index.d.ts +1 -1
- package/lib/constant/index.js +16 -2
- package/lib/constant/theme.d.ts +136 -0
- package/lib/constant/theme.js +683 -0
- package/lib/index.css +3 -2
- package/lib/model/GraphModel.d.ts +10 -2
- package/lib/model/GraphModel.js +49 -15
- package/lib/model/TransformModel.js +9 -9
- package/lib/model/edge/BaseEdgeModel.js +7 -2
- package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
- package/lib/model/edge/PolylineEdgeModel.js +136 -7
- package/lib/model/node/BaseNodeModel.d.ts +12 -1
- package/lib/model/node/BaseNodeModel.js +9 -2
- package/lib/model/node/HtmlNodeModel.d.ts +12 -0
- package/lib/model/node/HtmlNodeModel.js +19 -0
- package/lib/model/node/PolygonNodeModel.js +3 -3
- package/lib/options.d.ts +4 -2
- package/lib/style/index.css +3 -2
- package/lib/style/index.less +3 -2
- package/lib/style/raw.d.ts +1 -1
- package/lib/style/raw.js +1 -1
- package/lib/tool/MultipleSelectTool.js +10 -5
- package/lib/util/drag.js +0 -1
- package/lib/util/edge.d.ts +40 -1
- package/lib/util/edge.js +43 -9
- package/lib/util/geometry.d.ts +8 -0
- package/lib/util/geometry.js +81 -1
- package/lib/util/theme.d.ts +2 -65
- package/lib/util/theme.js +15 -292
- package/lib/view/Anchor.d.ts +1 -0
- package/lib/view/Anchor.js +24 -21
- package/lib/view/Control.d.ts +5 -0
- package/lib/view/Control.js +44 -57
- package/lib/view/edge/BaseEdge.js +9 -0
- package/lib/view/edge/PolylineEdge.js +13 -2
- package/lib/view/node/BaseNode.d.ts +1 -0
- package/lib/view/node/BaseNode.js +22 -10
- package/lib/view/node/HtmlNode.js +1 -3
- package/lib/view/overlay/CanvasOverlay.js +5 -2
- package/lib/view/overlay/Grid.d.ts +12 -1
- package/lib/view/overlay/Grid.js +83 -21
- package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
- package/lib/view/overlay/OutlineOverlay.js +18 -17
- package/lib/view/overlay/gridConfig.d.ts +46 -0
- package/lib/view/overlay/gridConfig.js +104 -0
- package/lib/view/shape/Polygon.d.ts +0 -7
- package/lib/view/shape/Polygon.js +13 -45
- 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 -1849
- 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 -2008
- 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/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 -1788
- 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 -777
- package/src/model/edge/BezierEdgeModel.ts +0 -197
- package/src/model/edge/LineEdgeModel.ts +0 -36
- package/src/model/edge/PolylineEdgeModel.ts +0 -672
- package/src/model/edge/index.ts +0 -4
- package/src/model/index.ts +0 -9
- package/src/model/node/BaseNodeModel.ts +0 -949
- 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 -50
- package/src/model/node/PolygonNodeModel.ts +0 -150
- 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 -145
- package/src/style/index.less +0 -261
- package/src/style/raw.ts +0 -220
- package/src/tool/MultipleSelectTool.tsx +0 -132
- 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 -220
- package/src/util/edge.ts +0 -1060
- package/src/util/geometry.ts +0 -55
- 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 -375
- 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 -445
- package/src/view/Control.tsx +0 -512
- 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 -650
- package/src/view/edge/BezierEdge.tsx +0 -101
- package/src/view/edge/LineEdge.tsx +0 -81
- package/src/view/edge/PolylineEdge.tsx +0 -299
- package/src/view/edge/index.ts +0 -6
- package/src/view/index.ts +0 -8
- package/src/view/node/BaseNode.tsx +0 -571
- 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 -95
- 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 -288
- package/src/view/overlay/Grid.tsx +0 -162
- package/src/view/overlay/ModificationOverlay.tsx +0 -31
- package/src/view/overlay/OutlineOverlay.tsx +0 -170
- 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/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 -91
- package/src/view/shape/Polyline.tsx +0 -31
- package/src/view/shape/Rect.tsx +0 -44
- package/src/view/shape/Text.tsx +0 -169
- 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,162 +0,0 @@
|
|
|
1
|
-
import { Component } from 'preact/compat'
|
|
2
|
-
import { cloneDeep, assign } from 'lodash-es'
|
|
3
|
-
import { observer } from '../..'
|
|
4
|
-
import { createUuid } from '../../util'
|
|
5
|
-
import { GraphModel } from '../../model'
|
|
6
|
-
import { DEFAULT_GRID_SIZE } from '../../constant'
|
|
7
|
-
|
|
8
|
-
type IProps = {
|
|
9
|
-
graphModel: GraphModel
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@observer
|
|
13
|
-
export class Grid extends Component<IProps> {
|
|
14
|
-
gridOptions: Grid.GridOptions
|
|
15
|
-
|
|
16
|
-
readonly id = createUuid()
|
|
17
|
-
|
|
18
|
-
constructor(props: IProps) {
|
|
19
|
-
super(props)
|
|
20
|
-
this.gridOptions = this.props.graphModel.grid
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 网格类型为点状
|
|
24
|
-
renderDot() {
|
|
25
|
-
const { config, size = 1, visible } = this.gridOptions
|
|
26
|
-
|
|
27
|
-
const { color, thickness = 2 } = config ?? {}
|
|
28
|
-
|
|
29
|
-
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
30
|
-
const radius = Math.min(Math.max(2, thickness), size / 4)
|
|
31
|
-
const opacity = visible ? 1 : 0
|
|
32
|
-
return (
|
|
33
|
-
<g fill={color} opacity={opacity}>
|
|
34
|
-
<circle cx={0} cy={0} r={radius / 2} />
|
|
35
|
-
<circle cx={0} cy={size} r={radius / 2} />
|
|
36
|
-
<circle cx={size} cy={0} r={radius / 2} />
|
|
37
|
-
<circle cx={size} cy={size} r={radius / 2} />
|
|
38
|
-
</g>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 网格类型为交叉线
|
|
43
|
-
// todo: 采用背景缩放的方式,实现更好的体验
|
|
44
|
-
renderMesh() {
|
|
45
|
-
const { config, size = 1, visible } = this.gridOptions
|
|
46
|
-
const { color, thickness = 1 } = config ?? {}
|
|
47
|
-
|
|
48
|
-
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
49
|
-
const strokeWidth = Math.min(Math.max(1, thickness), size / 2)
|
|
50
|
-
const d = `M 0 0 H ${size} V ${size} H 0 Z`
|
|
51
|
-
const opacity = visible ? 1 : 0
|
|
52
|
-
return (
|
|
53
|
-
<path
|
|
54
|
-
d={d}
|
|
55
|
-
stroke={color}
|
|
56
|
-
strokeWidth={strokeWidth / 2}
|
|
57
|
-
opacity={opacity}
|
|
58
|
-
fill="transparent"
|
|
59
|
-
/>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
render() {
|
|
64
|
-
const {
|
|
65
|
-
graphModel: { transformModel, grid },
|
|
66
|
-
} = this.props
|
|
67
|
-
this.gridOptions = grid
|
|
68
|
-
const { type, size = 1 } = this.gridOptions
|
|
69
|
-
const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
|
|
70
|
-
transformModel
|
|
71
|
-
const matrixString = [
|
|
72
|
-
SCALE_X,
|
|
73
|
-
SKEW_Y,
|
|
74
|
-
SKEW_X,
|
|
75
|
-
SCALE_Y,
|
|
76
|
-
TRANSLATE_X,
|
|
77
|
-
TRANSLATE_Y,
|
|
78
|
-
].join(',')
|
|
79
|
-
const transform = `matrix(${matrixString})`
|
|
80
|
-
// const transitionStyle = {
|
|
81
|
-
// transition: 'all 0.1s ease',
|
|
82
|
-
// };
|
|
83
|
-
return (
|
|
84
|
-
<div className="lf-grid">
|
|
85
|
-
<svg
|
|
86
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
87
|
-
version="1.1"
|
|
88
|
-
width="100%"
|
|
89
|
-
height="100%"
|
|
90
|
-
>
|
|
91
|
-
<defs>
|
|
92
|
-
<pattern
|
|
93
|
-
id={this.id}
|
|
94
|
-
patternUnits="userSpaceOnUse"
|
|
95
|
-
patternTransform={transform}
|
|
96
|
-
x="0"
|
|
97
|
-
y="0"
|
|
98
|
-
width={size}
|
|
99
|
-
height={size}
|
|
100
|
-
>
|
|
101
|
-
{type === 'dot' && this.renderDot()}
|
|
102
|
-
{type === 'mesh' && this.renderMesh()}
|
|
103
|
-
</pattern>
|
|
104
|
-
</defs>
|
|
105
|
-
<rect width="100%" height="100%" fill={`url(#${this.id})`} />
|
|
106
|
-
</svg>
|
|
107
|
-
</div>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export namespace Grid {
|
|
113
|
-
export type GridOptions = {
|
|
114
|
-
/**
|
|
115
|
-
* 网格格子间距
|
|
116
|
-
*/
|
|
117
|
-
size?: number
|
|
118
|
-
/**
|
|
119
|
-
* 网格是否可见
|
|
120
|
-
*/
|
|
121
|
-
visible?: boolean
|
|
122
|
-
/**
|
|
123
|
-
* 网格类型
|
|
124
|
-
* - `dot` 点状网格
|
|
125
|
-
* - `mesh` 交叉线网格
|
|
126
|
-
*/
|
|
127
|
-
type?: 'dot' | 'mesh'
|
|
128
|
-
config?: {
|
|
129
|
-
/**
|
|
130
|
-
* 网格的颜色
|
|
131
|
-
*/
|
|
132
|
-
color?: string
|
|
133
|
-
/**
|
|
134
|
-
* 网格的宽度
|
|
135
|
-
* - 对于 `dot` 点状网格,表示点的大小
|
|
136
|
-
* - 对于 `mesh` 交叉线网格,表示线的宽度
|
|
137
|
-
*/
|
|
138
|
-
thickness?: number
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export const defaultProps: GridOptions = {
|
|
143
|
-
size: DEFAULT_GRID_SIZE,
|
|
144
|
-
visible: true,
|
|
145
|
-
type: 'dot',
|
|
146
|
-
config: {
|
|
147
|
-
color: '#ababab',
|
|
148
|
-
thickness: 1,
|
|
149
|
-
},
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function getGridOptions(options: number | boolean | GridOptions) {
|
|
153
|
-
const defaultOptions = cloneDeep(Grid.defaultProps)
|
|
154
|
-
if (typeof options === 'number') {
|
|
155
|
-
return assign(defaultOptions, { size: options })
|
|
156
|
-
} else if (typeof options === 'boolean') {
|
|
157
|
-
return assign(defaultOptions, { visible: options })
|
|
158
|
-
} else {
|
|
159
|
-
return assign(defaultOptions, options)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -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,170 +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
|
-
// 节点outline
|
|
20
|
-
getNodesOutline() {
|
|
21
|
-
const { graphModel } = this.props
|
|
22
|
-
const {
|
|
23
|
-
nodes,
|
|
24
|
-
editConfigModel: { hoverOutline, nodeSelectedOutline },
|
|
25
|
-
} = graphModel
|
|
26
|
-
const nodeOutline: any = []
|
|
27
|
-
nodes.forEach((element) => {
|
|
28
|
-
if (element.isHovered || element.isSelected) {
|
|
29
|
-
const { isHovered, isSelected, x, y, width, height } = element
|
|
30
|
-
if (
|
|
31
|
-
(nodeSelectedOutline && isSelected) ||
|
|
32
|
-
(hoverOutline && isHovered)
|
|
33
|
-
) {
|
|
34
|
-
const style = element.getOutlineStyle()
|
|
35
|
-
let attributes = {}
|
|
36
|
-
Object.keys(style).forEach((key) => {
|
|
37
|
-
if (key !== 'hover') {
|
|
38
|
-
attributes[key] = style[key]
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
if (isHovered) {
|
|
42
|
-
const hoverStyle = style.hover
|
|
43
|
-
attributes = {
|
|
44
|
-
...attributes,
|
|
45
|
-
...hoverStyle,
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
nodeOutline.push(
|
|
49
|
-
<Rect
|
|
50
|
-
transform={element.transform}
|
|
51
|
-
className="lf-outline-node"
|
|
52
|
-
{...{
|
|
53
|
-
x,
|
|
54
|
-
y,
|
|
55
|
-
// width: width + 10,
|
|
56
|
-
// height: height + 10,
|
|
57
|
-
width: width + 10,
|
|
58
|
-
height: height + 10,
|
|
59
|
-
}}
|
|
60
|
-
{...attributes}
|
|
61
|
-
/>,
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
return nodeOutline
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 边的outline
|
|
70
|
-
getEdgeOutline() {
|
|
71
|
-
const {
|
|
72
|
-
graphModel: {
|
|
73
|
-
edges: edgeList,
|
|
74
|
-
editConfigModel: { edgeSelectedOutline, hoverOutline },
|
|
75
|
-
},
|
|
76
|
-
} = this.props
|
|
77
|
-
const edgeOutline: any = []
|
|
78
|
-
for (let i = 0; i < edgeList.length; i++) {
|
|
79
|
-
const edge = edgeList[i]
|
|
80
|
-
if (
|
|
81
|
-
(edgeSelectedOutline && edge.isSelected) ||
|
|
82
|
-
(hoverOutline && edge.isHovered)
|
|
83
|
-
) {
|
|
84
|
-
if (edge.modelType === ModelType.LINE_EDGE) {
|
|
85
|
-
edgeOutline.push(this.getLineOutline(edge as LineEdgeModel))
|
|
86
|
-
} else if (edge.modelType === ModelType.POLYLINE_EDGE) {
|
|
87
|
-
edgeOutline.push(this.getPolylineOutline(edge as PolylineEdgeModel))
|
|
88
|
-
} else if (edge.modelType === ModelType.BEZIER_EDGE) {
|
|
89
|
-
edgeOutline.push(this.getBezierOutline(edge as BezierEdgeModel))
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return edgeOutline
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 直线outline
|
|
97
|
-
getLineOutline(line: LineEdgeModel) {
|
|
98
|
-
const { startPoint, endPoint } = line
|
|
99
|
-
const x = (startPoint.x + endPoint.x) / 2
|
|
100
|
-
const y = (startPoint.y + endPoint.y) / 2
|
|
101
|
-
const width = Math.abs(startPoint.x - endPoint.x) + 10
|
|
102
|
-
const height = Math.abs(startPoint.y - endPoint.y) + 10
|
|
103
|
-
const style = line.getOutlineStyle()
|
|
104
|
-
return (
|
|
105
|
-
<Rect
|
|
106
|
-
className="lf-outline-edge"
|
|
107
|
-
{...{
|
|
108
|
-
x,
|
|
109
|
-
y,
|
|
110
|
-
width,
|
|
111
|
-
height,
|
|
112
|
-
}}
|
|
113
|
-
{...style}
|
|
114
|
-
/>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 折线outline
|
|
119
|
-
getPolylineOutline(polyline: PolylineEdgeModel) {
|
|
120
|
-
const { points } = polyline
|
|
121
|
-
const pointsList = points2PointsList(points)
|
|
122
|
-
const bbox = getBBoxOfPoints(pointsList, 8)
|
|
123
|
-
const { x, y, width, height } = bbox
|
|
124
|
-
const style = polyline.getOutlineStyle()
|
|
125
|
-
return (
|
|
126
|
-
<Rect
|
|
127
|
-
className="lf-outline"
|
|
128
|
-
{...{
|
|
129
|
-
x,
|
|
130
|
-
y,
|
|
131
|
-
width,
|
|
132
|
-
height,
|
|
133
|
-
}}
|
|
134
|
-
{...style}
|
|
135
|
-
/>
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// 曲线outline
|
|
140
|
-
getBezierOutline(bezier: BezierEdgeModel) {
|
|
141
|
-
const { path } = bezier
|
|
142
|
-
const pointsList = getBezierPoints(path)
|
|
143
|
-
const bbox = getBBoxOfPoints(pointsList, 8)
|
|
144
|
-
const { x, y, width, height } = bbox
|
|
145
|
-
const style = bezier.getOutlineStyle()
|
|
146
|
-
return (
|
|
147
|
-
<Rect
|
|
148
|
-
className="lf-outline"
|
|
149
|
-
{...{
|
|
150
|
-
x,
|
|
151
|
-
y,
|
|
152
|
-
width,
|
|
153
|
-
height,
|
|
154
|
-
}}
|
|
155
|
-
{...style}
|
|
156
|
-
/>
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
render() {
|
|
161
|
-
return (
|
|
162
|
-
<g className="lf-outline">
|
|
163
|
-
{this.getNodesOutline()}
|
|
164
|
-
{this.getEdgeOutline()}
|
|
165
|
-
</g>
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './CanvasOverlay'
|
|
2
|
-
export * from './BezierAdjustOverlay'
|
|
3
|
-
export * from './BackgroundOverlay'
|
|
4
|
-
export * from './Grid'
|
|
5
|
-
export * from './ModificationOverlay'
|
|
6
|
-
export * from './OutlineOverlay'
|
|
7
|
-
export * from './SnaplineOverlay'
|
|
8
|
-
export * from './ToolOverlay'
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import { LogicFlow } from '../..'
|
|
4
|
-
|
|
5
|
-
export type ICircleProps = {
|
|
6
|
-
x?: number
|
|
7
|
-
y?: number
|
|
8
|
-
r?: number
|
|
9
|
-
className?: string
|
|
10
|
-
} & LogicFlow.CommonTheme
|
|
11
|
-
|
|
12
|
-
export function Circle(props: ICircleProps): h.JSX.Element {
|
|
13
|
-
const { x = 0, y = 0, r = 4, className } = props
|
|
14
|
-
|
|
15
|
-
const attrs: ICircleProps = {
|
|
16
|
-
cx: x,
|
|
17
|
-
cy: y,
|
|
18
|
-
r,
|
|
19
|
-
fill: 'transparent',
|
|
20
|
-
fillOpacity: 1,
|
|
21
|
-
strokeWidth: 1,
|
|
22
|
-
stroke: '#000',
|
|
23
|
-
strokeOpacity: 1,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
27
|
-
if (typeof v !== 'object') {
|
|
28
|
-
attrs[k] = v
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
if (className) {
|
|
33
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
34
|
-
} else {
|
|
35
|
-
attrs.className = `lf-basic-shape`
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return <circle {...attrs} />
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default Circle
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
import { LogicFlow } from '../..'
|
|
4
|
-
|
|
5
|
-
export type IEllipseProps = {
|
|
6
|
-
x?: number
|
|
7
|
-
y?: number
|
|
8
|
-
rx?: number
|
|
9
|
-
ry?: number
|
|
10
|
-
className?: string
|
|
11
|
-
} & LogicFlow.CommonTheme
|
|
12
|
-
|
|
13
|
-
export function Ellipse(props: IEllipseProps): h.JSX.Element {
|
|
14
|
-
const { x = 0, y = 0, rx = 4, ry = 4, className } = props
|
|
15
|
-
|
|
16
|
-
const attrs: Record<string, any> = {
|
|
17
|
-
cx: x,
|
|
18
|
-
cy: y,
|
|
19
|
-
rx,
|
|
20
|
-
ry,
|
|
21
|
-
fill: 'transparent',
|
|
22
|
-
fillOpacity: 1,
|
|
23
|
-
strokeWidth: 1,
|
|
24
|
-
stroke: '#000',
|
|
25
|
-
strokeOpacity: 1,
|
|
26
|
-
}
|
|
27
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
28
|
-
if (typeof v !== 'object') {
|
|
29
|
-
attrs[k] = v
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
if (className) {
|
|
34
|
-
attrs.className = `lf-basic-shape ${className}`
|
|
35
|
-
} else {
|
|
36
|
-
attrs.className = `lf-basic-shape`
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return <ellipse {...attrs} />
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default Ellipse
|
package/src/view/shape/Line.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export type ILineProps = {
|
|
5
|
-
id?: string
|
|
6
|
-
tabindex?: number
|
|
7
|
-
x1?: number
|
|
8
|
-
y1?: number
|
|
9
|
-
x2?: number
|
|
10
|
-
y2?: number
|
|
11
|
-
stroke?: string // Color
|
|
12
|
-
className?: string
|
|
13
|
-
style?: h.JSX.CSSProperties
|
|
14
|
-
[key: string]: any
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function Line(props: ILineProps): h.JSX.Element {
|
|
18
|
-
const attrs: ILineProps = {
|
|
19
|
-
// default
|
|
20
|
-
x1: 10,
|
|
21
|
-
y1: 10,
|
|
22
|
-
x2: 20,
|
|
23
|
-
y2: 20,
|
|
24
|
-
stroke: 'black',
|
|
25
|
-
// ...props
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
29
|
-
if (k === 'style') {
|
|
30
|
-
attrs[k] = v
|
|
31
|
-
} else if (typeof v !== 'object') {
|
|
32
|
-
attrs[k] = v
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
return <line {...attrs} />
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default Line
|
package/src/view/shape/Path.tsx
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'preact/compat'
|
|
2
|
-
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
-
|
|
4
|
-
export type IPathProps = {
|
|
5
|
-
d: string
|
|
6
|
-
[key: string]: any
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function Path(props: IPathProps): h.JSX.Element {
|
|
10
|
-
const attrs: Record<string, any> = {
|
|
11
|
-
d: '',
|
|
12
|
-
}
|
|
13
|
-
forEach(toPairs(props), ([k, v]: [key: string, v: any]) => {
|
|
14
|
-
if (k === 'style' || typeof v !== 'object') {
|
|
15
|
-
attrs[k] = v
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
return <path {...attrs} />
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default Path
|