@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.
Files changed (137) hide show
  1. package/package.json +6 -1
  2. package/.turbo/turbo-build$colon$dev.log +0 -10
  3. package/.turbo/turbo-build.log +0 -33
  4. package/CHANGELOG.md +0 -1901
  5. package/__tests__/algorithm/egde.test.ts +0 -131
  6. package/__tests__/algorithm/index.test.ts +0 -74
  7. package/__tests__/algorithm/outline.test.ts +0 -43
  8. package/__tests__/bugs/1545-spec.test.ts +0 -42
  9. package/__tests__/event/event.test.ts +0 -22
  10. package/__tests__/history/history.test.ts +0 -28
  11. package/__tests__/logicflow.test.ts +0 -575
  12. package/__tests__/model/graphmodel.test.ts +0 -87
  13. package/__tests__/util/compatible.test.ts +0 -48
  14. package/__tests__/util/edge.test.ts +0 -224
  15. package/__tests__/util/geometry.test.ts +0 -14
  16. package/__tests__/util/graph.test.ts +0 -16
  17. package/__tests__/util/matrix.test.ts +0 -41
  18. package/__tests__/util/node.test.ts +0 -68
  19. package/__tests__/util/sampling.test.ts +0 -12
  20. package/__tests__/util/vector.test.ts +0 -50
  21. package/__tests__/util/zIndex.test.ts +0 -10
  22. package/src/LogicFlow.tsx +0 -2017
  23. package/src/algorithm/edge.ts +0 -67
  24. package/src/algorithm/index.ts +0 -70
  25. package/src/algorithm/outline.ts +0 -77
  26. package/src/algorithm/rotate.ts +0 -55
  27. package/src/common/drag.ts +0 -219
  28. package/src/common/history.ts +0 -108
  29. package/src/common/index.ts +0 -6
  30. package/src/common/keyboard.ts +0 -108
  31. package/src/common/matrix.ts +0 -122
  32. package/src/common/vector.ts +0 -93
  33. package/src/constant/index.ts +0 -179
  34. package/src/constant/theme.ts +0 -708
  35. package/src/event/event.md +0 -66
  36. package/src/event/eventArgs.ts +0 -643
  37. package/src/event/eventEmitter.ts +0 -156
  38. package/src/history/index.ts +0 -119
  39. package/src/index.less +0 -1
  40. package/src/index.ts +0 -26
  41. package/src/keyboard/index.ts +0 -112
  42. package/src/keyboard/shortcut.ts +0 -200
  43. package/src/model/BaseModel.ts +0 -250
  44. package/src/model/EditConfigModel.ts +0 -334
  45. package/src/model/GraphModel.ts +0 -1824
  46. package/src/model/NestedTransformModel.ts +0 -121
  47. package/src/model/SnaplineModel.ts +0 -256
  48. package/src/model/TransformModel.ts +0 -258
  49. package/src/model/edge/BaseEdgeModel.ts +0 -785
  50. package/src/model/edge/BezierEdgeModel.ts +0 -197
  51. package/src/model/edge/LineEdgeModel.ts +0 -36
  52. package/src/model/edge/PolylineEdgeModel.ts +0 -817
  53. package/src/model/edge/index.ts +0 -4
  54. package/src/model/index.ts +0 -9
  55. package/src/model/node/BaseNodeModel.ts +0 -959
  56. package/src/model/node/CircleNodeModel.ts +0 -91
  57. package/src/model/node/DiamondNodeModel.ts +0 -132
  58. package/src/model/node/EllipseNodeModel.ts +0 -98
  59. package/src/model/node/HtmlNodeModel.ts +0 -64
  60. package/src/model/node/PolygonNodeModel.ts +0 -152
  61. package/src/model/node/RectNodeModel.ts +0 -69
  62. package/src/model/node/TextNodeModel.ts +0 -54
  63. package/src/model/node/index.ts +0 -8
  64. package/src/options.ts +0 -150
  65. package/src/style/index.less +0 -262
  66. package/src/style/raw.ts +0 -221
  67. package/src/tool/MultipleSelectTool.tsx +0 -140
  68. package/src/tool/TextEditTool.tsx +0 -193
  69. package/src/tool/index.ts +0 -101
  70. package/src/typings.d.ts +0 -5
  71. package/src/util/animation.ts +0 -29
  72. package/src/util/browser.ts +0 -4
  73. package/src/util/compatible.ts +0 -15
  74. package/src/util/drag.ts +0 -219
  75. package/src/util/edge.ts +0 -1094
  76. package/src/util/geometry.ts +0 -154
  77. package/src/util/graph.ts +0 -46
  78. package/src/util/index.ts +0 -17
  79. package/src/util/matrix.ts +0 -129
  80. package/src/util/mobx.ts +0 -23
  81. package/src/util/node.ts +0 -543
  82. package/src/util/raf.ts +0 -28
  83. package/src/util/resize.ts +0 -606
  84. package/src/util/sampling.ts +0 -85
  85. package/src/util/theme.ts +0 -84
  86. package/src/util/uuid.ts +0 -26
  87. package/src/util/vector.ts +0 -93
  88. package/src/util/zIndex.ts +0 -6
  89. package/src/view/Anchor.tsx +0 -462
  90. package/src/view/Control.tsx +0 -510
  91. package/src/view/Graph.tsx +0 -141
  92. package/src/view/Rotate.tsx +0 -113
  93. package/src/view/behavior/dnd.ts +0 -162
  94. package/src/view/behavior/index.ts +0 -2
  95. package/src/view/behavior/snapline.ts +0 -16
  96. package/src/view/edge/AdjustPoint.tsx +0 -425
  97. package/src/view/edge/Arrow.tsx +0 -54
  98. package/src/view/edge/BaseEdge.tsx +0 -660
  99. package/src/view/edge/BezierEdge.tsx +0 -101
  100. package/src/view/edge/LineEdge.tsx +0 -81
  101. package/src/view/edge/PolylineEdge.tsx +0 -311
  102. package/src/view/edge/index.ts +0 -6
  103. package/src/view/index.ts +0 -8
  104. package/src/view/node/BaseNode.tsx +0 -585
  105. package/src/view/node/CircleNode.tsx +0 -21
  106. package/src/view/node/DiamondNode.tsx +0 -24
  107. package/src/view/node/EllipseNode.tsx +0 -22
  108. package/src/view/node/HtmlNode.tsx +0 -112
  109. package/src/view/node/PolygonNode.tsx +0 -28
  110. package/src/view/node/RectNode.tsx +0 -30
  111. package/src/view/node/TextNode.tsx +0 -39
  112. package/src/view/node/index.ts +0 -8
  113. package/src/view/overlay/BackgroundOverlay.tsx +0 -34
  114. package/src/view/overlay/BezierAdjustOverlay.tsx +0 -150
  115. package/src/view/overlay/CanvasOverlay.tsx +0 -290
  116. package/src/view/overlay/Grid.tsx +0 -319
  117. package/src/view/overlay/ModificationOverlay.tsx +0 -31
  118. package/src/view/overlay/OutlineOverlay.tsx +0 -158
  119. package/src/view/overlay/SnaplineOverlay.tsx +0 -44
  120. package/src/view/overlay/ToolOverlay.tsx +0 -65
  121. package/src/view/overlay/getTransformHoc.tsx +0 -50
  122. package/src/view/overlay/gridConfig.ts +0 -103
  123. package/src/view/overlay/index.ts +0 -8
  124. package/src/view/shape/Circle.tsx +0 -41
  125. package/src/view/shape/Ellipse.tsx +0 -42
  126. package/src/view/shape/Line.tsx +0 -39
  127. package/src/view/shape/Path.tsx +0 -22
  128. package/src/view/shape/Polygon.tsx +0 -54
  129. package/src/view/shape/Polyline.tsx +0 -31
  130. package/src/view/shape/Rect.tsx +0 -44
  131. package/src/view/shape/Text.tsx +0 -168
  132. package/src/view/shape/index.ts +0 -8
  133. package/src/view/text/BaseText.tsx +0 -134
  134. package/src/view/text/LineText.tsx +0 -168
  135. package/src/view/text/index.ts +0 -2
  136. package/stats.html +0 -4842
  137. 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,64 +0,0 @@
1
- import { cloneDeep } from 'lodash-es'
2
- import BaseNodeModel from './BaseNodeModel'
3
- import { Model } from '../BaseModel'
4
- import { ModelType } from '../../constant'
5
-
6
- import AnchorConfig = Model.AnchorConfig
7
- import LogicFlow from '../../LogicFlow'
8
- import GraphModel from '../GraphModel'
9
-
10
- export interface IHtmlNodeProperties {
11
- width?: number
12
- height?: number
13
- style?: LogicFlow.CommonTheme
14
- textStyle?: LogicFlow.CommonTheme
15
-
16
- [key: string]: unknown
17
- }
18
-
19
- export class HtmlNodeModel<
20
- P extends IHtmlNodeProperties = IHtmlNodeProperties,
21
- > extends BaseNodeModel<P> {
22
- modelType = ModelType.HTML_NODE
23
- // @observable properties: IHtmlNodeProperties = {}
24
-
25
- constructor(data: LogicFlow.NodeConfig<P>, graphModel: GraphModel) {
26
- super(data, graphModel)
27
- // this.properties = data.properties || {}
28
-
29
- this.setAttributes()
30
- }
31
-
32
- setAttributes() {
33
- super.setAttributes()
34
-
35
- const { width, height } = this.properties
36
- if (width) this.width = width
37
- if (height) this.height = height
38
- }
39
-
40
- getDefaultAnchor(): AnchorConfig[] {
41
- const { x, y, width, height } = this
42
- return [
43
- { x, y: y - height / 2, id: `${this.id}_0` },
44
- { x: x + width / 2, y, id: `${this.id}_1` },
45
- { x, y: y + height / 2, id: `${this.id}_2` },
46
- { x: x - width / 2, y, id: `${this.id}_3` },
47
- ]
48
- }
49
-
50
- getNodeStyle() {
51
- const style = super.getNodeStyle()
52
- const { baseNode, html } = this.graphModel.theme
53
- const { style: customStyle = {} } = this.properties
54
- const finalStyle = {
55
- ...style,
56
- ...cloneDeep(baseNode),
57
- ...cloneDeep(html),
58
- ...cloneDeep(customStyle),
59
- }
60
- return finalStyle
61
- }
62
- }
63
-
64
- export default HtmlNodeModel
@@ -1,152 +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
- customStyles: { polygon: customPolygon },
71
- },
72
- } = this
73
- const { style: customStyle = {} } = this.properties
74
- return {
75
- ...style,
76
- ...cloneDeep(polygon),
77
- ...cloneDeep(customPolygon),
78
- ...cloneDeep(customStyle),
79
- }
80
- }
81
-
82
- /**
83
- * 由于大多数情况下,我们初始化拿到的多边形坐标都是基于原点的(例如绘图工具到处的svg)。
84
- * 在logicflow中对多边形进行移动,我们不需要去更新points,
85
- * 而是去更新多边形中心点即可。
86
- */
87
- @computed get pointsPosition(): Point[] {
88
- const { x, y, width, height } = this
89
- return this.points.map((item) => ({
90
- x: item[0] + x - width / 2,
91
- y: item[1] + y - height / 2,
92
- }))
93
- }
94
-
95
- @computed get width(): number {
96
- let min = Number.MAX_SAFE_INTEGER
97
- let max = Number.MIN_SAFE_INTEGER
98
- this.points.forEach(([x]) => {
99
- if (x < min) {
100
- min = x
101
- }
102
- if (x > max) {
103
- max = x
104
- }
105
- })
106
- return max - min
107
- }
108
-
109
- @computed get height(): number {
110
- let min = Number.MAX_SAFE_INTEGER
111
- let max = Number.MIN_SAFE_INTEGER
112
- this.points.forEach(([, y]) => {
113
- if (y < min) {
114
- min = y
115
- }
116
- if (y > max) {
117
- max = y
118
- }
119
- })
120
- return max - min
121
- }
122
-
123
- getDefaultAnchor() {
124
- const { x, y, width, height, points } = this
125
- return points.map(([x1, y1], idx) => ({
126
- x: x + x1 - width / 2,
127
- y: y + y1 - height / 2,
128
- id: `${this.id}_${idx}`,
129
- }))
130
- }
131
-
132
- resize(resizeInfo: ResizeInfo): ResizeNodeData {
133
- const { width, height, deltaX, deltaY } = resizeInfo
134
- // 移动节点以及文本内容
135
- this.move(deltaX / 2, deltaY / 2)
136
-
137
- const nextPoints: PointTuple[] = map(this.points, ([x, y]) => [
138
- (x * width) / this.width,
139
- (y * height) / this.height,
140
- ])
141
- this.points = nextPoints
142
-
143
- this.properties.points = nextPoints
144
- // this.setProperties({
145
- // points: toJS(nextPoints),
146
- // })
147
-
148
- return this.getData()
149
- }
150
- }
151
-
152
- 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'