@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,91 +0,0 @@
|
|
|
1
|
-
import { cloneDeep } from 'lodash-es'
|
|
2
|
-
import { computed, observable } from 'mobx'
|
|
3
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
4
|
-
import GraphModel from '../GraphModel'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType } from '../../constant'
|
|
7
|
-
import { ResizeControl } from '../../view/Control'
|
|
8
|
-
|
|
9
|
-
import NodeConfig = LogicFlow.NodeConfig
|
|
10
|
-
import ResizeInfo = ResizeControl.ResizeInfo
|
|
11
|
-
import ResizeNodeData = ResizeControl.ResizeNodeData
|
|
12
|
-
|
|
13
|
-
export type ICircleNodeProperties = {
|
|
14
|
-
r?: number
|
|
15
|
-
style?: LogicFlow.CommonTheme
|
|
16
|
-
textStyle?: LogicFlow.CommonTheme
|
|
17
|
-
|
|
18
|
-
[key: string]: any
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class CircleNodeModel<
|
|
22
|
-
P extends ICircleNodeProperties = ICircleNodeProperties,
|
|
23
|
-
> extends BaseNodeModel<P> {
|
|
24
|
-
modelType = ModelType.CIRCLE_NODE
|
|
25
|
-
// @observable properties: ICircleNodeProperties = {}
|
|
26
|
-
@observable r = 50
|
|
27
|
-
|
|
28
|
-
@computed get width(): number {
|
|
29
|
-
return this.r * 2
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@computed get height(): number {
|
|
33
|
-
return this.r * 2
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor(data: NodeConfig<P>, graphModel: GraphModel) {
|
|
37
|
-
super(data, graphModel)
|
|
38
|
-
// this.properties = data.properties || {}
|
|
39
|
-
|
|
40
|
-
this.initNodeData(data)
|
|
41
|
-
this.setAttributes()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setAttributes() {
|
|
45
|
-
super.setAttributes()
|
|
46
|
-
|
|
47
|
-
const { r } = this.properties
|
|
48
|
-
if (r) {
|
|
49
|
-
this.r = r
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
getNodeStyle() {
|
|
54
|
-
const style = super.getNodeStyle()
|
|
55
|
-
const {
|
|
56
|
-
graphModel: {
|
|
57
|
-
theme: { circle },
|
|
58
|
-
},
|
|
59
|
-
} = this
|
|
60
|
-
const { style: customStyle = {} } = this.properties
|
|
61
|
-
return {
|
|
62
|
-
...style,
|
|
63
|
-
...cloneDeep(circle),
|
|
64
|
-
...cloneDeep(customStyle),
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getDefaultAnchor() {
|
|
69
|
-
const { x, y, r } = this
|
|
70
|
-
return [
|
|
71
|
-
{ x, y: y - r, id: `${this.id}_0` },
|
|
72
|
-
{ x: x + r, y, id: `${this.id}_1` },
|
|
73
|
-
{ x, y: y + r, id: `${this.id}_2` },
|
|
74
|
-
{ x: x - r, y, id: `${this.id}_3` },
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
resize(resizeInfo: ResizeInfo): ResizeNodeData {
|
|
79
|
-
const { width, deltaX, deltaY } = resizeInfo
|
|
80
|
-
// 移动节点以及文本内容
|
|
81
|
-
this.move(deltaX / 2, deltaY / 2)
|
|
82
|
-
|
|
83
|
-
this.r = width
|
|
84
|
-
this.setProperties({
|
|
85
|
-
r: width,
|
|
86
|
-
})
|
|
87
|
-
return this.getData()
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default CircleNodeModel
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, forEach, map } from 'lodash-es'
|
|
2
|
-
import { computed, observable } from 'mobx'
|
|
3
|
-
import GraphModel from '../GraphModel'
|
|
4
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType } from '../../constant'
|
|
7
|
-
import { ResizeControl } from '../../view/Control'
|
|
8
|
-
|
|
9
|
-
import Point = LogicFlow.Point
|
|
10
|
-
import PointTuple = LogicFlow.PointTuple
|
|
11
|
-
import NodeConfig = LogicFlow.NodeConfig
|
|
12
|
-
import ResizeInfo = ResizeControl.ResizeInfo
|
|
13
|
-
import ResizeNodeData = ResizeControl.ResizeNodeData
|
|
14
|
-
|
|
15
|
-
export type IDiamondNodeProperties = {
|
|
16
|
-
rx?: number
|
|
17
|
-
ry?: number
|
|
18
|
-
style?: LogicFlow.CommonTheme
|
|
19
|
-
textStyle?: LogicFlow.CommonTheme
|
|
20
|
-
|
|
21
|
-
[key: string]: unknown
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class DiamondNodeModel<
|
|
25
|
-
P extends IDiamondNodeProperties = IDiamondNodeProperties,
|
|
26
|
-
> extends BaseNodeModel<P> {
|
|
27
|
-
modelType = ModelType.DIAMOND_NODE
|
|
28
|
-
@observable rx = 30
|
|
29
|
-
@observable ry = 50
|
|
30
|
-
// @observable properties: IDiamondNodeProperties = {}
|
|
31
|
-
|
|
32
|
-
constructor(data: NodeConfig<P>, graphModel: GraphModel) {
|
|
33
|
-
super(data, graphModel)
|
|
34
|
-
// this.properties = data.properties || {}
|
|
35
|
-
|
|
36
|
-
this.initNodeData(data)
|
|
37
|
-
this.setAttributes()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
setAttributes() {
|
|
41
|
-
super.setAttributes()
|
|
42
|
-
|
|
43
|
-
const { rx, ry } = this.properties
|
|
44
|
-
if (rx) {
|
|
45
|
-
this.rx = rx
|
|
46
|
-
}
|
|
47
|
-
if (ry) {
|
|
48
|
-
this.ry = ry
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getNodeStyle() {
|
|
53
|
-
const style = super.getNodeStyle()
|
|
54
|
-
const {
|
|
55
|
-
graphModel: {
|
|
56
|
-
theme: { diamond },
|
|
57
|
-
},
|
|
58
|
-
} = this
|
|
59
|
-
const { style: customStyle = {} } = this.properties
|
|
60
|
-
return {
|
|
61
|
-
...style,
|
|
62
|
-
...cloneDeep(diamond),
|
|
63
|
-
...cloneDeep(customStyle),
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@computed get points(): PointTuple[] {
|
|
68
|
-
const { x, y, rx, ry } = this
|
|
69
|
-
return [
|
|
70
|
-
[x, y - ry],
|
|
71
|
-
[x + rx, y],
|
|
72
|
-
[x, y + ry],
|
|
73
|
-
[x - rx, y],
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@computed get pointsPosition(): Point[] {
|
|
78
|
-
return map(this.points, ([x, y]) => ({ x, y }))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@computed get width(): number {
|
|
82
|
-
let min = Number.MAX_SAFE_INTEGER
|
|
83
|
-
let max = Number.MIN_SAFE_INTEGER
|
|
84
|
-
forEach(this.points, ([x]) => {
|
|
85
|
-
if (x < min) {
|
|
86
|
-
min = x
|
|
87
|
-
}
|
|
88
|
-
if (x > max) {
|
|
89
|
-
max = x
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
return max - min
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@computed get height(): number {
|
|
96
|
-
let min = Number.MAX_SAFE_INTEGER
|
|
97
|
-
let max = Number.MIN_SAFE_INTEGER
|
|
98
|
-
forEach(this.points, ([, y]) => {
|
|
99
|
-
if (y < min) {
|
|
100
|
-
min = y
|
|
101
|
-
}
|
|
102
|
-
if (y > max) {
|
|
103
|
-
max = y
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
return max - min
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getDefaultAnchor() {
|
|
110
|
-
return map(this.points, ([x, y], idx) => ({
|
|
111
|
-
x,
|
|
112
|
-
y,
|
|
113
|
-
id: `${this.id}_${idx}`,
|
|
114
|
-
}))
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
resize(resizeInfo: ResizeInfo): ResizeNodeData {
|
|
118
|
-
const { width, height, deltaX, deltaY } = resizeInfo
|
|
119
|
-
// 移动节点以及文本内容
|
|
120
|
-
this.move(deltaX / 2, deltaY / 2)
|
|
121
|
-
|
|
122
|
-
this.rx = width
|
|
123
|
-
this.ry = height
|
|
124
|
-
this.setProperties({
|
|
125
|
-
rx: width,
|
|
126
|
-
ry: height,
|
|
127
|
-
})
|
|
128
|
-
return this.getData()
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export default DiamondNodeModel
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { cloneDeep } from 'lodash-es'
|
|
2
|
-
import { computed, observable } from 'mobx'
|
|
3
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
4
|
-
import GraphModel from '../GraphModel'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType } from '../../constant'
|
|
7
|
-
import { ResizeControl } from '../../view/Control'
|
|
8
|
-
|
|
9
|
-
import NodeConfig = LogicFlow.NodeConfig
|
|
10
|
-
import ResizeInfo = ResizeControl.ResizeInfo
|
|
11
|
-
import ResizeNodeData = ResizeControl.ResizeNodeData
|
|
12
|
-
|
|
13
|
-
export type IEllipseNodeProperties = {
|
|
14
|
-
rx?: number
|
|
15
|
-
ry?: number
|
|
16
|
-
style?: LogicFlow.CommonTheme
|
|
17
|
-
textStyle?: LogicFlow.CommonTheme
|
|
18
|
-
|
|
19
|
-
[key: string]: unknown
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class EllipseNodeModel<
|
|
23
|
-
P extends IEllipseNodeProperties = IEllipseNodeProperties,
|
|
24
|
-
> extends BaseNodeModel<P> {
|
|
25
|
-
modelType = ModelType.ELLIPSE_NODE
|
|
26
|
-
@observable rx = 30
|
|
27
|
-
@observable ry = 45
|
|
28
|
-
// @observable properties: IEllipseNodeProperties = {}
|
|
29
|
-
|
|
30
|
-
constructor(data: NodeConfig<P>, graphModel: GraphModel) {
|
|
31
|
-
super(data, graphModel)
|
|
32
|
-
// this.properties = data.properties || {}
|
|
33
|
-
|
|
34
|
-
this.initNodeData(data)
|
|
35
|
-
this.setAttributes()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
setAttributes() {
|
|
39
|
-
super.setAttributes()
|
|
40
|
-
|
|
41
|
-
const { rx, ry } = this.properties
|
|
42
|
-
if (rx) {
|
|
43
|
-
this.rx = rx
|
|
44
|
-
}
|
|
45
|
-
if (ry) {
|
|
46
|
-
this.ry = ry
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
getNodeStyle() {
|
|
51
|
-
const style = super.getNodeStyle()
|
|
52
|
-
const {
|
|
53
|
-
graphModel: {
|
|
54
|
-
theme: { ellipse },
|
|
55
|
-
},
|
|
56
|
-
} = this
|
|
57
|
-
const { style: customStyle = {} } = this.properties
|
|
58
|
-
return {
|
|
59
|
-
...style,
|
|
60
|
-
...cloneDeep(ellipse),
|
|
61
|
-
...cloneDeep(customStyle),
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@computed get width(): number {
|
|
66
|
-
return this.rx * 2
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@computed get height(): number {
|
|
70
|
-
return this.ry * 2
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getDefaultAnchor() {
|
|
74
|
-
const { x, y, rx, ry } = this
|
|
75
|
-
return [
|
|
76
|
-
{ x, y: y - ry, id: `${this.id}_0` },
|
|
77
|
-
{ x: x + rx, y, id: `${this.id}_1` },
|
|
78
|
-
{ x, y: y + ry, id: `${this.id}_2` },
|
|
79
|
-
{ x: x - rx, y, id: `${this.id}_3` },
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
resize(resizeInfo: ResizeInfo): ResizeNodeData {
|
|
84
|
-
const { width, height, deltaX, deltaY } = resizeInfo
|
|
85
|
-
// 移动节点以及文本内容
|
|
86
|
-
this.move(deltaX / 2, deltaY / 2)
|
|
87
|
-
|
|
88
|
-
this.rx = width
|
|
89
|
-
this.ry = height
|
|
90
|
-
this.setProperties({
|
|
91
|
-
rx: width,
|
|
92
|
-
ry: height,
|
|
93
|
-
})
|
|
94
|
-
return this.getData()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default EllipseNodeModel
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
2
|
-
import { Model } from '../BaseModel'
|
|
3
|
-
import { ModelType } from '../../constant'
|
|
4
|
-
|
|
5
|
-
import AnchorConfig = Model.AnchorConfig
|
|
6
|
-
import LogicFlow from '../../LogicFlow'
|
|
7
|
-
import GraphModel from '../GraphModel'
|
|
8
|
-
|
|
9
|
-
export interface IHtmlNodeProperties {
|
|
10
|
-
width?: number
|
|
11
|
-
height?: number
|
|
12
|
-
style?: LogicFlow.CommonTheme
|
|
13
|
-
textStyle?: LogicFlow.CommonTheme
|
|
14
|
-
|
|
15
|
-
[key: string]: unknown
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class HtmlNodeModel<
|
|
19
|
-
P extends IHtmlNodeProperties = IHtmlNodeProperties,
|
|
20
|
-
> extends BaseNodeModel<P> {
|
|
21
|
-
modelType = ModelType.HTML_NODE
|
|
22
|
-
// @observable properties: IHtmlNodeProperties = {}
|
|
23
|
-
|
|
24
|
-
constructor(data: LogicFlow.NodeConfig<P>, graphModel: GraphModel) {
|
|
25
|
-
super(data, graphModel)
|
|
26
|
-
// this.properties = data.properties || {}
|
|
27
|
-
|
|
28
|
-
this.setAttributes()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
setAttributes() {
|
|
32
|
-
super.setAttributes()
|
|
33
|
-
|
|
34
|
-
const { width, height } = this.properties
|
|
35
|
-
if (width) this.width = width
|
|
36
|
-
if (height) this.height = height
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getDefaultAnchor(): AnchorConfig[] {
|
|
40
|
-
const { x, y, width, height } = this
|
|
41
|
-
return [
|
|
42
|
-
{ x, y: y - height / 2, id: `${this.id}_0` },
|
|
43
|
-
{ x: x + width / 2, y, id: `${this.id}_1` },
|
|
44
|
-
{ x, y: y + height / 2, id: `${this.id}_2` },
|
|
45
|
-
{ x: x - width / 2, y, id: `${this.id}_3` },
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default HtmlNodeModel
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, map } from 'lodash-es'
|
|
2
|
-
import { computed, observable } from 'mobx'
|
|
3
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
4
|
-
import GraphModel from '../GraphModel'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType } from '../../constant'
|
|
7
|
-
import { ResizeControl } from '../../view/Control'
|
|
8
|
-
import Point = LogicFlow.Point
|
|
9
|
-
import PointTuple = LogicFlow.PointTuple
|
|
10
|
-
import NodeConfig = LogicFlow.NodeConfig
|
|
11
|
-
import ResizeInfo = ResizeControl.ResizeInfo
|
|
12
|
-
import ResizeNodeData = ResizeControl.ResizeNodeData
|
|
13
|
-
import { normalizePolygon } from '../../util'
|
|
14
|
-
|
|
15
|
-
export type IPolygonNodeProperties = {
|
|
16
|
-
points?: PointTuple[]
|
|
17
|
-
width?: number
|
|
18
|
-
height?: number
|
|
19
|
-
style?: LogicFlow.CommonTheme
|
|
20
|
-
textStyle?: LogicFlow.CommonTheme
|
|
21
|
-
|
|
22
|
-
[key: string]: unknown
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class PolygonNodeModel<
|
|
26
|
-
P extends IPolygonNodeProperties = IPolygonNodeProperties,
|
|
27
|
-
> extends BaseNodeModel<P> {
|
|
28
|
-
modelType = ModelType.POLYGON_NODE
|
|
29
|
-
@observable points: PointTuple[] = [
|
|
30
|
-
[50, 0],
|
|
31
|
-
[100, 50],
|
|
32
|
-
[50, 100],
|
|
33
|
-
[0, 50], // 菱形
|
|
34
|
-
// [0,100], [50,25], [50,75], [100,0] // 闪电
|
|
35
|
-
// [100, 10],
|
|
36
|
-
// [40, 198],
|
|
37
|
-
// [190, 78],
|
|
38
|
-
// [10, 78],
|
|
39
|
-
// [160, 198], // 五角星
|
|
40
|
-
]
|
|
41
|
-
// @observable properties: IPolygonNodeProperties = {}
|
|
42
|
-
|
|
43
|
-
constructor(data: NodeConfig<P>, graphModel: GraphModel) {
|
|
44
|
-
super(data, graphModel)
|
|
45
|
-
// this.properties = data.properties || {}
|
|
46
|
-
|
|
47
|
-
this.initNodeData(data)
|
|
48
|
-
this.setAttributes()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setAttributes() {
|
|
52
|
-
super.setAttributes()
|
|
53
|
-
|
|
54
|
-
const { points, width, height } = this.properties
|
|
55
|
-
// DONE: 如果设置了 points,又设置了节点的宽高,则需要做如下操作
|
|
56
|
-
// 1. 将 points 的位置置零,即将图形向原点移动(找到 points 中 x,y 的最小值,所有坐标值减掉该值)
|
|
57
|
-
// 2. 按宽高的比例重新计算最新的 points
|
|
58
|
-
// if (points) {
|
|
59
|
-
// this.points = points
|
|
60
|
-
// }
|
|
61
|
-
const nextPoints = points || this.points
|
|
62
|
-
this.points = normalizePolygon(nextPoints, width, height)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getNodeStyle() {
|
|
66
|
-
const style = super.getNodeStyle()
|
|
67
|
-
const {
|
|
68
|
-
graphModel: {
|
|
69
|
-
theme: { polygon },
|
|
70
|
-
},
|
|
71
|
-
} = this
|
|
72
|
-
const { style: customStyle = {} } = this.properties
|
|
73
|
-
return {
|
|
74
|
-
...style,
|
|
75
|
-
...cloneDeep(polygon),
|
|
76
|
-
...cloneDeep(customStyle),
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 由于大多数情况下,我们初始化拿到的多边形坐标都是基于原点的(例如绘图工具到处的svg)。
|
|
82
|
-
* 在logicflow中对多边形进行移动,我们不需要去更新points,
|
|
83
|
-
* 而是去更新多边形中心点即可。
|
|
84
|
-
*/
|
|
85
|
-
@computed get pointsPosition(): Point[] {
|
|
86
|
-
const { x, y, width, height } = this
|
|
87
|
-
return this.points.map((item) => ({
|
|
88
|
-
x: item[0] + x - width / 2,
|
|
89
|
-
y: item[1] + y - height / 2,
|
|
90
|
-
}))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@computed get width(): number {
|
|
94
|
-
let min = Number.MAX_SAFE_INTEGER
|
|
95
|
-
let max = Number.MIN_SAFE_INTEGER
|
|
96
|
-
this.points.forEach(([x]) => {
|
|
97
|
-
if (x < min) {
|
|
98
|
-
min = x
|
|
99
|
-
}
|
|
100
|
-
if (x > max) {
|
|
101
|
-
max = x
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
return max - min
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@computed get height(): number {
|
|
108
|
-
let min = Number.MAX_SAFE_INTEGER
|
|
109
|
-
let max = Number.MIN_SAFE_INTEGER
|
|
110
|
-
this.points.forEach(([, y]) => {
|
|
111
|
-
if (y < min) {
|
|
112
|
-
min = y
|
|
113
|
-
}
|
|
114
|
-
if (y > max) {
|
|
115
|
-
max = y
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
return max - min
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getDefaultAnchor() {
|
|
122
|
-
const { x, y, width, height, points } = this
|
|
123
|
-
return points.map(([x1, y1], idx) => ({
|
|
124
|
-
x: x + x1 - width / 2,
|
|
125
|
-
y: y + y1 - height / 2,
|
|
126
|
-
id: `${this.id}_${idx}`,
|
|
127
|
-
}))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
resize(resizeInfo: ResizeInfo): ResizeNodeData {
|
|
131
|
-
const { width, height, deltaX, deltaY } = resizeInfo
|
|
132
|
-
// 移动节点以及文本内容
|
|
133
|
-
this.move(deltaX / 2, deltaY / 2)
|
|
134
|
-
|
|
135
|
-
const nextPoints: PointTuple[] = map(this.points, ([x, y]) => [
|
|
136
|
-
(x * width) / this.width,
|
|
137
|
-
(y * height) / this.height,
|
|
138
|
-
])
|
|
139
|
-
this.points = nextPoints
|
|
140
|
-
|
|
141
|
-
this.properties.points = nextPoints
|
|
142
|
-
// this.setProperties({
|
|
143
|
-
// points: toJS(nextPoints),
|
|
144
|
-
// })
|
|
145
|
-
|
|
146
|
-
return this.getData()
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export default PolygonNodeModel
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, isNil } from 'lodash-es'
|
|
2
|
-
import { observable } from 'mobx'
|
|
3
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
4
|
-
import GraphModel from '../GraphModel'
|
|
5
|
-
import LogicFlow from '../../LogicFlow'
|
|
6
|
-
import { ModelType } from '../../constant'
|
|
7
|
-
|
|
8
|
-
export type IRectNodeProperties = {
|
|
9
|
-
width?: number
|
|
10
|
-
height?: number
|
|
11
|
-
radius?: number
|
|
12
|
-
style?: LogicFlow.CommonTheme
|
|
13
|
-
textStyle?: LogicFlow.CommonTheme
|
|
14
|
-
|
|
15
|
-
[key: string]: unknown
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class RectNodeModel<
|
|
19
|
-
P extends IRectNodeProperties = IRectNodeProperties,
|
|
20
|
-
> extends BaseNodeModel<P> {
|
|
21
|
-
modelType = ModelType.RECT_NODE
|
|
22
|
-
@observable radius = 0
|
|
23
|
-
// @observable properties: P
|
|
24
|
-
|
|
25
|
-
constructor(data: LogicFlow.NodeConfig<P>, graphModel: GraphModel) {
|
|
26
|
-
super(data, graphModel)
|
|
27
|
-
|
|
28
|
-
// TODO:类字段初始化会覆盖 super、setAttributes 中设置的属性
|
|
29
|
-
// this.properties = data.properties || {}
|
|
30
|
-
// TODO: bug here, 上面更新 properties 会触发 setAttributes,下面再主动调用,会导致触发两次
|
|
31
|
-
this.initNodeData(data)
|
|
32
|
-
this.setAttributes()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
setAttributes() {
|
|
36
|
-
super.setAttributes()
|
|
37
|
-
|
|
38
|
-
const { width, height, radius } = this.properties
|
|
39
|
-
const { radius: styleRadius } = this.getNodeStyle()
|
|
40
|
-
if (!isNil(width)) this.width = width
|
|
41
|
-
if (!isNil(height)) this.height = height
|
|
42
|
-
// 矩形特有
|
|
43
|
-
if (!isNil(radius)) this.radius = radius
|
|
44
|
-
if (!isNil(styleRadius)) this.radius = styleRadius
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getDefaultAnchor() {
|
|
48
|
-
const { x, y, width, height } = this
|
|
49
|
-
return [
|
|
50
|
-
{ x, y: y - height / 2, id: `${this.id}_0` },
|
|
51
|
-
{ x: x + width / 2, y, id: `${this.id}_1` },
|
|
52
|
-
{ x, y: y + height / 2, id: `${this.id}_2` },
|
|
53
|
-
{ x: x - width / 2, y, id: `${this.id}_3` },
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getNodeStyle() {
|
|
58
|
-
const style = super.getNodeStyle()
|
|
59
|
-
const { rect } = this.graphModel.theme
|
|
60
|
-
const { style: customStyle = {} } = this.properties
|
|
61
|
-
return {
|
|
62
|
-
...style,
|
|
63
|
-
...cloneDeep(rect),
|
|
64
|
-
...cloneDeep(customStyle),
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default RectNodeModel
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { cloneDeep } from 'lodash-es'
|
|
2
|
-
import { computed } from 'mobx'
|
|
3
|
-
import BaseNodeModel from './BaseNodeModel'
|
|
4
|
-
import { ModelType } from '../../constant'
|
|
5
|
-
import { getSvgTextWidthHeight } from '../../util'
|
|
6
|
-
import LogicFlow from '../../LogicFlow'
|
|
7
|
-
|
|
8
|
-
export type ITextNodeProperties = {
|
|
9
|
-
style?: LogicFlow.CommonTheme
|
|
10
|
-
textStyle?: LogicFlow.CommonTheme
|
|
11
|
-
|
|
12
|
-
[key: string]: unknown
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class TextNodeModel<
|
|
16
|
-
P extends ITextNodeProperties = ITextNodeProperties,
|
|
17
|
-
> extends BaseNodeModel<P> {
|
|
18
|
-
modelType = ModelType.TEXT_NODE
|
|
19
|
-
|
|
20
|
-
getTextStyle() {
|
|
21
|
-
const style = super.getTextStyle()
|
|
22
|
-
const { text } = this.graphModel.theme
|
|
23
|
-
const { textStyle } = this.properties
|
|
24
|
-
return {
|
|
25
|
-
...style,
|
|
26
|
-
...cloneDeep(text),
|
|
27
|
-
...cloneDeep(textStyle),
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@computed get width(): number {
|
|
32
|
-
const rows = String(this.text.value).split(/[\r\n]/g)
|
|
33
|
-
const { fontSize } = this.getTextStyle()
|
|
34
|
-
const { width } = getSvgTextWidthHeight({
|
|
35
|
-
rows,
|
|
36
|
-
fontSize,
|
|
37
|
-
rowsLength: rows.length,
|
|
38
|
-
})
|
|
39
|
-
return width
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@computed get height(): number {
|
|
43
|
-
const rows = String(this.text.value).split(/[\r\n]/g)
|
|
44
|
-
const { fontSize } = this.getTextStyle()
|
|
45
|
-
const { height } = getSvgTextWidthHeight({
|
|
46
|
-
rows,
|
|
47
|
-
fontSize,
|
|
48
|
-
rowsLength: rows.length,
|
|
49
|
-
})
|
|
50
|
-
return height
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default TextNodeModel
|
package/src/model/node/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './BaseNodeModel'
|
|
2
|
-
export * from './CircleNodeModel'
|
|
3
|
-
export * from './DiamondNodeModel'
|
|
4
|
-
export * from './EllipseNodeModel'
|
|
5
|
-
export * from './PolygonNodeModel'
|
|
6
|
-
export * from './RectNodeModel'
|
|
7
|
-
export * from './TextNodeModel'
|
|
8
|
-
export * from './HtmlNodeModel'
|