@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.
Files changed (236) hide show
  1. package/dist/index.css +3 -2
  2. package/dist/index.min.js +1 -1
  3. package/dist/index.min.js.map +1 -1
  4. package/es/LogicFlow.d.ts +9 -0
  5. package/es/LogicFlow.js +0 -1
  6. package/es/constant/index.d.ts +1 -1
  7. package/es/constant/index.js +1 -1
  8. package/es/constant/theme.d.ts +136 -0
  9. package/es/constant/theme.js +680 -0
  10. package/es/index.css +3 -2
  11. package/es/model/GraphModel.d.ts +10 -2
  12. package/es/model/GraphModel.js +48 -14
  13. package/es/model/TransformModel.js +9 -9
  14. package/es/model/edge/BaseEdgeModel.js +7 -2
  15. package/es/model/edge/PolylineEdgeModel.d.ts +7 -0
  16. package/es/model/edge/PolylineEdgeModel.js +136 -7
  17. package/es/model/node/BaseNodeModel.d.ts +12 -1
  18. package/es/model/node/BaseNodeModel.js +9 -2
  19. package/es/model/node/HtmlNodeModel.d.ts +12 -0
  20. package/es/model/node/HtmlNodeModel.js +19 -0
  21. package/es/model/node/PolygonNodeModel.js +3 -3
  22. package/es/options.d.ts +4 -2
  23. package/es/style/index.css +3 -2
  24. package/es/style/index.less +3 -2
  25. package/es/style/raw.d.ts +1 -1
  26. package/es/style/raw.js +1 -1
  27. package/es/tool/MultipleSelectTool.js +10 -5
  28. package/es/util/drag.js +0 -1
  29. package/es/util/edge.d.ts +40 -1
  30. package/es/util/edge.js +43 -9
  31. package/es/util/geometry.d.ts +8 -0
  32. package/es/util/geometry.js +79 -0
  33. package/es/util/theme.d.ts +2 -65
  34. package/es/util/theme.js +4 -281
  35. package/es/view/Anchor.d.ts +1 -0
  36. package/es/view/Anchor.js +24 -21
  37. package/es/view/Control.d.ts +5 -0
  38. package/es/view/Control.js +44 -57
  39. package/es/view/edge/BaseEdge.js +9 -0
  40. package/es/view/edge/PolylineEdge.js +13 -2
  41. package/es/view/node/BaseNode.d.ts +1 -0
  42. package/es/view/node/BaseNode.js +23 -11
  43. package/es/view/node/HtmlNode.js +2 -4
  44. package/es/view/overlay/CanvasOverlay.js +5 -2
  45. package/es/view/overlay/Grid.d.ts +12 -1
  46. package/es/view/overlay/Grid.js +85 -23
  47. package/es/view/overlay/OutlineOverlay.d.ts +1 -0
  48. package/es/view/overlay/OutlineOverlay.js +18 -17
  49. package/es/view/overlay/gridConfig.d.ts +46 -0
  50. package/es/view/overlay/gridConfig.js +99 -0
  51. package/es/view/shape/Polygon.d.ts +0 -7
  52. package/es/view/shape/Polygon.js +12 -43
  53. package/lib/LogicFlow.d.ts +9 -0
  54. package/lib/LogicFlow.js +0 -1
  55. package/lib/constant/index.d.ts +1 -1
  56. package/lib/constant/index.js +16 -2
  57. package/lib/constant/theme.d.ts +136 -0
  58. package/lib/constant/theme.js +683 -0
  59. package/lib/index.css +3 -2
  60. package/lib/model/GraphModel.d.ts +10 -2
  61. package/lib/model/GraphModel.js +49 -15
  62. package/lib/model/TransformModel.js +9 -9
  63. package/lib/model/edge/BaseEdgeModel.js +7 -2
  64. package/lib/model/edge/PolylineEdgeModel.d.ts +7 -0
  65. package/lib/model/edge/PolylineEdgeModel.js +136 -7
  66. package/lib/model/node/BaseNodeModel.d.ts +12 -1
  67. package/lib/model/node/BaseNodeModel.js +9 -2
  68. package/lib/model/node/HtmlNodeModel.d.ts +12 -0
  69. package/lib/model/node/HtmlNodeModel.js +19 -0
  70. package/lib/model/node/PolygonNodeModel.js +3 -3
  71. package/lib/options.d.ts +4 -2
  72. package/lib/style/index.css +3 -2
  73. package/lib/style/index.less +3 -2
  74. package/lib/style/raw.d.ts +1 -1
  75. package/lib/style/raw.js +1 -1
  76. package/lib/tool/MultipleSelectTool.js +10 -5
  77. package/lib/util/drag.js +0 -1
  78. package/lib/util/edge.d.ts +40 -1
  79. package/lib/util/edge.js +43 -9
  80. package/lib/util/geometry.d.ts +8 -0
  81. package/lib/util/geometry.js +81 -1
  82. package/lib/util/theme.d.ts +2 -65
  83. package/lib/util/theme.js +15 -292
  84. package/lib/view/Anchor.d.ts +1 -0
  85. package/lib/view/Anchor.js +24 -21
  86. package/lib/view/Control.d.ts +5 -0
  87. package/lib/view/Control.js +44 -57
  88. package/lib/view/edge/BaseEdge.js +9 -0
  89. package/lib/view/edge/PolylineEdge.js +13 -2
  90. package/lib/view/node/BaseNode.d.ts +1 -0
  91. package/lib/view/node/BaseNode.js +22 -10
  92. package/lib/view/node/HtmlNode.js +1 -3
  93. package/lib/view/overlay/CanvasOverlay.js +5 -2
  94. package/lib/view/overlay/Grid.d.ts +12 -1
  95. package/lib/view/overlay/Grid.js +83 -21
  96. package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
  97. package/lib/view/overlay/OutlineOverlay.js +18 -17
  98. package/lib/view/overlay/gridConfig.d.ts +46 -0
  99. package/lib/view/overlay/gridConfig.js +104 -0
  100. package/lib/view/shape/Polygon.d.ts +0 -7
  101. package/lib/view/shape/Polygon.js +13 -45
  102. package/package.json +6 -1
  103. package/.turbo/turbo-build$colon$dev.log +0 -10
  104. package/.turbo/turbo-build.log +0 -33
  105. package/CHANGELOG.md +0 -1849
  106. package/__tests__/algorithm/egde.test.ts +0 -131
  107. package/__tests__/algorithm/index.test.ts +0 -74
  108. package/__tests__/algorithm/outline.test.ts +0 -43
  109. package/__tests__/bugs/1545-spec.test.ts +0 -42
  110. package/__tests__/event/event.test.ts +0 -22
  111. package/__tests__/history/history.test.ts +0 -28
  112. package/__tests__/logicflow.test.ts +0 -575
  113. package/__tests__/model/graphmodel.test.ts +0 -87
  114. package/__tests__/util/compatible.test.ts +0 -48
  115. package/__tests__/util/edge.test.ts +0 -224
  116. package/__tests__/util/geometry.test.ts +0 -14
  117. package/__tests__/util/graph.test.ts +0 -16
  118. package/__tests__/util/matrix.test.ts +0 -41
  119. package/__tests__/util/node.test.ts +0 -68
  120. package/__tests__/util/sampling.test.ts +0 -12
  121. package/__tests__/util/vector.test.ts +0 -50
  122. package/__tests__/util/zIndex.test.ts +0 -10
  123. package/src/LogicFlow.tsx +0 -2008
  124. package/src/algorithm/edge.ts +0 -67
  125. package/src/algorithm/index.ts +0 -70
  126. package/src/algorithm/outline.ts +0 -77
  127. package/src/algorithm/rotate.ts +0 -55
  128. package/src/common/drag.ts +0 -219
  129. package/src/common/history.ts +0 -108
  130. package/src/common/index.ts +0 -6
  131. package/src/common/keyboard.ts +0 -108
  132. package/src/common/matrix.ts +0 -122
  133. package/src/common/vector.ts +0 -93
  134. package/src/constant/index.ts +0 -179
  135. package/src/event/event.md +0 -66
  136. package/src/event/eventArgs.ts +0 -643
  137. package/src/event/eventEmitter.ts +0 -156
  138. package/src/history/index.ts +0 -119
  139. package/src/index.less +0 -1
  140. package/src/index.ts +0 -26
  141. package/src/keyboard/index.ts +0 -112
  142. package/src/keyboard/shortcut.ts +0 -200
  143. package/src/model/BaseModel.ts +0 -250
  144. package/src/model/EditConfigModel.ts +0 -334
  145. package/src/model/GraphModel.ts +0 -1788
  146. package/src/model/NestedTransformModel.ts +0 -121
  147. package/src/model/SnaplineModel.ts +0 -256
  148. package/src/model/TransformModel.ts +0 -258
  149. package/src/model/edge/BaseEdgeModel.ts +0 -777
  150. package/src/model/edge/BezierEdgeModel.ts +0 -197
  151. package/src/model/edge/LineEdgeModel.ts +0 -36
  152. package/src/model/edge/PolylineEdgeModel.ts +0 -672
  153. package/src/model/edge/index.ts +0 -4
  154. package/src/model/index.ts +0 -9
  155. package/src/model/node/BaseNodeModel.ts +0 -949
  156. package/src/model/node/CircleNodeModel.ts +0 -91
  157. package/src/model/node/DiamondNodeModel.ts +0 -132
  158. package/src/model/node/EllipseNodeModel.ts +0 -98
  159. package/src/model/node/HtmlNodeModel.ts +0 -50
  160. package/src/model/node/PolygonNodeModel.ts +0 -150
  161. package/src/model/node/RectNodeModel.ts +0 -69
  162. package/src/model/node/TextNodeModel.ts +0 -54
  163. package/src/model/node/index.ts +0 -8
  164. package/src/options.ts +0 -145
  165. package/src/style/index.less +0 -261
  166. package/src/style/raw.ts +0 -220
  167. package/src/tool/MultipleSelectTool.tsx +0 -132
  168. package/src/tool/TextEditTool.tsx +0 -193
  169. package/src/tool/index.ts +0 -101
  170. package/src/typings.d.ts +0 -5
  171. package/src/util/animation.ts +0 -29
  172. package/src/util/browser.ts +0 -4
  173. package/src/util/compatible.ts +0 -15
  174. package/src/util/drag.ts +0 -220
  175. package/src/util/edge.ts +0 -1060
  176. package/src/util/geometry.ts +0 -55
  177. package/src/util/graph.ts +0 -46
  178. package/src/util/index.ts +0 -17
  179. package/src/util/matrix.ts +0 -129
  180. package/src/util/mobx.ts +0 -23
  181. package/src/util/node.ts +0 -543
  182. package/src/util/raf.ts +0 -28
  183. package/src/util/resize.ts +0 -606
  184. package/src/util/sampling.ts +0 -85
  185. package/src/util/theme.ts +0 -375
  186. package/src/util/uuid.ts +0 -26
  187. package/src/util/vector.ts +0 -93
  188. package/src/util/zIndex.ts +0 -6
  189. package/src/view/Anchor.tsx +0 -445
  190. package/src/view/Control.tsx +0 -512
  191. package/src/view/Graph.tsx +0 -141
  192. package/src/view/Rotate.tsx +0 -113
  193. package/src/view/behavior/dnd.ts +0 -162
  194. package/src/view/behavior/index.ts +0 -2
  195. package/src/view/behavior/snapline.ts +0 -16
  196. package/src/view/edge/AdjustPoint.tsx +0 -425
  197. package/src/view/edge/Arrow.tsx +0 -54
  198. package/src/view/edge/BaseEdge.tsx +0 -650
  199. package/src/view/edge/BezierEdge.tsx +0 -101
  200. package/src/view/edge/LineEdge.tsx +0 -81
  201. package/src/view/edge/PolylineEdge.tsx +0 -299
  202. package/src/view/edge/index.ts +0 -6
  203. package/src/view/index.ts +0 -8
  204. package/src/view/node/BaseNode.tsx +0 -571
  205. package/src/view/node/CircleNode.tsx +0 -21
  206. package/src/view/node/DiamondNode.tsx +0 -24
  207. package/src/view/node/EllipseNode.tsx +0 -22
  208. package/src/view/node/HtmlNode.tsx +0 -95
  209. package/src/view/node/PolygonNode.tsx +0 -28
  210. package/src/view/node/RectNode.tsx +0 -30
  211. package/src/view/node/TextNode.tsx +0 -39
  212. package/src/view/node/index.ts +0 -8
  213. package/src/view/overlay/BackgroundOverlay.tsx +0 -34
  214. package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
  215. package/src/view/overlay/CanvasOverlay.tsx +0 -288
  216. package/src/view/overlay/Grid.tsx +0 -162
  217. package/src/view/overlay/ModificationOverlay.tsx +0 -31
  218. package/src/view/overlay/OutlineOverlay.tsx +0 -170
  219. package/src/view/overlay/SnaplineOverlay.tsx +0 -44
  220. package/src/view/overlay/ToolOverlay.tsx +0 -65
  221. package/src/view/overlay/getTransformHoc.tsx +0 -50
  222. package/src/view/overlay/index.ts +0 -8
  223. package/src/view/shape/Circle.tsx +0 -41
  224. package/src/view/shape/Ellipse.tsx +0 -42
  225. package/src/view/shape/Line.tsx +0 -39
  226. package/src/view/shape/Path.tsx +0 -22
  227. package/src/view/shape/Polygon.tsx +0 -91
  228. package/src/view/shape/Polyline.tsx +0 -31
  229. package/src/view/shape/Rect.tsx +0 -44
  230. package/src/view/shape/Text.tsx +0 -169
  231. package/src/view/shape/index.ts +0 -8
  232. package/src/view/text/BaseText.tsx +0 -134
  233. package/src/view/text/LineText.tsx +0 -168
  234. package/src/view/text/index.ts +0 -2
  235. package/stats.html +0 -4842
  236. 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
@@ -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'