@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 { createElement as h } from 'preact/compat'
2
- import { forEach, toPairs } from 'lodash-es'
3
- import { LogicFlow } from '../..'
4
-
5
- export type IPolygonProps = {
6
- points: LogicFlow.PointTuple[]
7
- x?: number
8
- y?: number
9
- className?: string
10
- radius?: number
11
- }
12
- /**
13
- * 生成带圆角的多边形路径
14
- * @param points 多边形顶点坐标数组
15
- * @param radius 圆角半径
16
- * @returns SVG 路径字符串
17
- */
18
- export function createRoundedPolygonPath(points, radius): string {
19
- const pointList = points.map((point) => ({ x: point[0], y: point[1] }))
20
- const len = pointList.length
21
- if (len < 3) return ''
22
-
23
- const r = Math.abs(radius)
24
- let path = ''
25
-
26
- for (let i = 0; i < len; i++) {
27
- const prev = pointList[(i - 1 + len) % len]
28
- const curr = pointList[i]
29
- const next = pointList[(i + 1) % len]
30
-
31
- // 向量
32
- const v1 = { x: curr.x - prev.x, y: curr.y - prev.y }
33
- const v2 = { x: next.x - curr.x, y: next.y - curr.y }
34
-
35
- // 单位向量
36
- const len1 = Math.hypot(v1.x, v1.y)
37
- const len2 = Math.hypot(v2.x, v2.y)
38
- const u1 = { x: v1.x / len1, y: v1.y / len1 }
39
- const u2 = { x: v2.x / len2, y: v2.y / len2 }
40
-
41
- // 起点 = curr - u1 * r,终点 = curr + u2 * r
42
- const start = { x: curr.x - u1.x * r, y: curr.y - u1.y * r }
43
- const end = { x: curr.x + u2.x * r, y: curr.y + u2.y * r }
44
-
45
- if (i === 0) {
46
- path += `M ${start.x} ${start.y} `
47
- } else {
48
- path += `L ${start.x} ${start.y} `
49
- }
50
-
51
- // Q 控制点是当前拐角点
52
- path += `Q ${curr.x} ${curr.y} ${end.x} ${end.y} `
53
- }
54
-
55
- path += 'Z'
56
- return path
57
- }
58
-
59
- export function Polygon(props: IPolygonProps): h.JSX.Element {
60
- const { points = [], className, radius } = props
61
- const attrs: Record<string, any> = {
62
- fill: 'transparent',
63
- fillOpacity: 1,
64
- strokeWidth: 1,
65
- stroke: '#000',
66
- strokeOpacity: 1,
67
- points: '',
68
- }
69
-
70
- forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
71
- if (typeof v !== 'object') {
72
- attrs[k] = v
73
- }
74
- })
75
-
76
- if (className) {
77
- attrs.classNmae = `lf-basic-shape ${className}`
78
- } else {
79
- attrs.className = 'lf-basic-shape'
80
- }
81
- if (radius) {
82
- const path = createRoundedPolygonPath(points, radius)
83
- attrs.d = path
84
- return <path {...attrs} />
85
- } else {
86
- attrs.points = points.map((point) => point.join(',')).join(' ')
87
- return <polygon {...attrs} />
88
- }
89
- }
90
-
91
- export default Polygon
@@ -1,31 +0,0 @@
1
- import { createElement as h } from 'preact/compat'
2
- import { forEach, toPairs } from 'lodash-es'
3
-
4
- export type IPolylineProps = {
5
- points: string
6
- pathLength?: number | 'none'
7
- className?: string
8
- }
9
-
10
- export function Polyline(props: IPolylineProps): h.JSX.Element {
11
- const { className } = props
12
- const attrs: Record<string, unknown> = {
13
- points: '',
14
- fill: 'none',
15
- }
16
-
17
- forEach(toPairs(props), ([k, v]: [k: string, v: unknown]) => {
18
- if (k === 'style') {
19
- attrs[k] = v
20
- } else if (typeof v !== 'object') {
21
- attrs[k] = v
22
- }
23
- })
24
- if (className) {
25
- attrs.className = `${className}`
26
- }
27
-
28
- return <polyline {...attrs} />
29
- }
30
-
31
- export default Polyline
@@ -1,44 +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 IRectProps = {
6
- x: number
7
- y: number
8
- width: number
9
- height: number
10
- className?: string
11
- radius?: LogicFlow.NumberOrPercent
12
- [key: string]: any
13
- }
14
-
15
- export function Rect(props: IRectProps): h.JSX.Element {
16
- const { x, y, width, height, className, strokeWidth, radius = 0 } = props
17
-
18
- const leftTopX = x - width / 2
19
- const leftTopY = y - height / 2
20
- const attrs: Record<string, any> = {}
21
- attrs['stroke-width'] = strokeWidth
22
- forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
23
- if (typeof v !== 'object') {
24
- attrs[k] = v
25
- }
26
- })
27
-
28
- if (className) {
29
- attrs.className = `lf-basic-shape ${className}`
30
- } else {
31
- attrs.className = 'lf-basic-shape'
32
- }
33
-
34
- if (radius) {
35
- attrs.rx = radius
36
- attrs.ry = radius
37
- }
38
- attrs.x = leftTopX
39
- attrs.y = leftTopY
40
-
41
- return <rect {...attrs} />
42
- }
43
-
44
- export default Rect
@@ -1,169 +0,0 @@
1
- import { createElement as h } from 'preact/compat'
2
- import { BaseNodeModel, BaseEdgeModel } from '../../model'
3
- import { ElementType, ModelType } from '../../constant'
4
- import { getHtmlTextHeight } from '../../util'
5
- import { forEach, toPairs } from 'lodash-es'
6
-
7
- export type ITextProps = {
8
- x: number
9
- y: number
10
- value: string
11
- fontSize?: number
12
- fill?: string
13
- overflowMode?: 'default' | 'autoWrap' | 'ellipsis'
14
- textWidth?: number
15
- lineHeight?: number
16
- fontFamily?: string | null
17
- wrapPadding?: string | number | null
18
- model: BaseNodeModel | BaseEdgeModel
19
- [key: string]: any
20
- }
21
- export type ForeignObjectPropsType =
22
- 'string | number | SignalLike<string | number | undefined> | undefined'
23
-
24
- export function Text(props: ITextProps): h.JSX.Element | null {
25
- const {
26
- x = 0,
27
- y = 0,
28
- value,
29
- fontSize = 12,
30
- fill = 'currentColor',
31
- overflowMode = 'default',
32
- // TODO: 确认该 textWidth 为 '' 时跟设置什么值一致
33
- textWidth = undefined,
34
- model,
35
- } = props
36
-
37
- const attrs: Record<string, any> = {
38
- x,
39
- y,
40
- fill,
41
- fontSize,
42
- textAnchor: 'middle',
43
- dominantBaseline: 'central',
44
- // ...props,
45
- }
46
-
47
- forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
48
- if (typeof v !== 'object') {
49
- attrs[k] = v
50
- }
51
- })
52
-
53
- if (value) {
54
- // String(value),兼容纯数字的文案
55
- // TODO: 将 value 转为纯文本,移除其中 \n \r 等特殊字符,看是否应该丰富该功能
56
- const rows = String(value).split(/[\r\n]/g)
57
- const rowsLength = rows.length
58
-
59
- if (overflowMode !== 'default') {
60
- // 非文本节点设置了自动换行,或者边设置了自动换行并且设置了 textWidth
61
- const { BaseType, modelType } = model
62
- if (
63
- (BaseType === ElementType.NODE && modelType !== ModelType.TEXT_NODE) ||
64
- (BaseType === ElementType.EDGE && textWidth)
65
- ) {
66
- return renderHtmlText(props)
67
- }
68
- }
69
-
70
- if (rowsLength > 1) {
71
- const tSpans = rows.map((row, idx) => {
72
- // 保证文字居中,文字 Y 轴偏移为当前行数对应中心行数的偏移行 * 行高
73
- const tSpanLineHeight = fontSize + 2
74
- const offsetY = (idx - (rowsLength - 1) / 2) * tSpanLineHeight
75
- return (
76
- <tspan className="lf-text-tspan" x={x} y={y + offsetY}>
77
- {row}
78
- </tspan>
79
- )
80
- })
81
- return <text {...attrs}>{tSpans}</text>
82
- }
83
- return <text {...attrs}>{value}</text>
84
- }
85
- return null
86
- }
87
-
88
- export function renderHtmlText(props: ITextProps): h.JSX.Element {
89
- const {
90
- x,
91
- y,
92
- value,
93
- model,
94
- textWidth,
95
- fontSize = 12,
96
- lineHeight,
97
- fontFamily = '',
98
- wrapPadding = '0, 0',
99
- overflowMode,
100
- } = props
101
-
102
- const { width, height, textHeight } = model
103
- // TODO: 设置文本宽度为 textWidth 或 节点的宽度
104
- const textRealWidth: number = textWidth || (width as number)
105
- const rows = String(value).split(/[\r\n]/g)
106
- const rowsLength = rows.length
107
- const textRealHeight = getHtmlTextHeight({
108
- rows,
109
- style: {
110
- fontSize: `${fontSize}px`,
111
- width: `${textRealWidth}px`,
112
- fontFamily,
113
- lineHeight,
114
- padding: wrapPadding,
115
- },
116
- rowsLength,
117
- className: 'lf-get-text-height',
118
- })
119
-
120
- // 当文字超过边框时,取文字高度的实际值,也就是文字可以超过边框
121
- let foreignObjectHeight: number =
122
- (height as number) > textRealHeight ? (height as number) : textRealHeight
123
- // 如果设置了文本高度,取设置的高度
124
- if (textHeight) {
125
- foreignObjectHeight = textHeight as number
126
- }
127
-
128
- const isEllipsis = overflowMode === 'ellipsis'
129
- if (isEllipsis) {
130
- foreignObjectHeight = fontSize + 2
131
- }
132
-
133
- return (
134
- <g>
135
- <foreignObject
136
- width={textRealWidth}
137
- height={foreignObjectHeight}
138
- x={x - textRealWidth / 2}
139
- y={y - foreignObjectHeight / 2}
140
- style={{ overflow: 'visible', textAlign: 'left' }}
141
- >
142
- <div
143
- className="lf-node-text-auto-wrap"
144
- style={{
145
- minHeight: foreignObjectHeight,
146
- width: textRealWidth,
147
- padding: wrapPadding,
148
- }}
149
- >
150
- <div
151
- className={
152
- isEllipsis
153
- ? 'lf-node-text-ellipsis-content'
154
- : 'lf-node-text-auto-wrap-content'
155
- }
156
- title={isEllipsis ? rows.join('') : ''}
157
- style={{ ...(props as h.JSX.CSSProperties) }}
158
- >
159
- {rows.map((row) => (
160
- <div className="lf-node-text--auto-wrap-inner">{row}</div>
161
- ))}
162
- </div>
163
- </div>
164
- </foreignObject>
165
- </g>
166
- )
167
- }
168
-
169
- export default Text
@@ -1,8 +0,0 @@
1
- export * from './Text'
2
- export * from './Line'
3
- export * from './Rect'
4
- export * from './Path'
5
- export * from './Circle'
6
- export * from './Ellipse'
7
- export * from './Polygon'
8
- export * from './Polyline'
@@ -1,134 +0,0 @@
1
- import classNames from 'classnames'
2
- import { createElement as h, Component } from 'preact/compat'
3
- import { ElementState, EventType } from '../../constant'
4
- import { GraphModel, BaseNodeModel, BaseEdgeModel } from '../../model'
5
- import { Text } from '../shape'
6
- import { IDragParams, StepDrag } from '../../util'
7
-
8
- export type IBaseTextProps = {
9
- model: BaseNodeModel | BaseEdgeModel
10
- graphModel: GraphModel
11
- draggable: boolean
12
- editable: boolean
13
- }
14
-
15
- export type IBaseTextState = {
16
- isHovered: boolean
17
- }
18
-
19
- export class BaseText<
20
- P extends IBaseTextProps,
21
- S extends IBaseTextState,
22
- > extends Component<P, S> {
23
- stepperDrag: StepDrag
24
-
25
- constructor(props: P) {
26
- super()
27
- const { draggable } = props
28
- // TODO: 确认为什么不在 new 的时候传入 model,而在下面使用的时候赋值
29
- this.stepperDrag = new StepDrag({
30
- onDragging: this.onDragging,
31
- step: 1,
32
- // model,
33
- eventType: 'TEXT',
34
- isStopPropagation: draggable,
35
- })
36
- }
37
-
38
- getShape(): h.JSX.Element | null {
39
- const { model, graphModel } = this.props
40
- const { editConfigModel } = graphModel
41
- const {
42
- text: { value, x, y, editable, draggable },
43
- } = model
44
- const attr = {
45
- x,
46
- y,
47
- className: '',
48
- value,
49
- }
50
- // DONE: 代码优化,看是否可以引入 classnames
51
- // TODO: 确认下面逻辑是否正确,确认正确后删除下面注释
52
- // if (editable) {
53
- // attr.className = 'lf-element-text';
54
- // } else if (draggable || editConfigModel.nodeTextDraggable) {
55
- // attr.className = 'lf-text-draggable';
56
- // } else {
57
- // attr.className = 'lf-text-disabled';
58
- // }
59
- const style = model.getTextStyle()
60
- const isDraggable = editConfigModel.nodeTextDraggable || draggable
61
-
62
- return (
63
- <Text
64
- {...attr}
65
- {...style}
66
- className={classNames({
67
- 'lf-element-text': editable,
68
- 'lf-text-draggable': !editable && isDraggable,
69
- 'lf-text-disabled': !editable && !isDraggable,
70
- })}
71
- model={model}
72
- />
73
- )
74
- }
75
-
76
- mouseDownHandler = (e: PointerEvent) => {
77
- const { draggable, model, graphModel } = this.props
78
- const {
79
- editConfigModel: { nodeTextDraggable },
80
- } = graphModel
81
-
82
- if (draggable ?? nodeTextDraggable) {
83
- e.stopPropagation()
84
- this.stepperDrag.model = model
85
- this.stepperDrag.handleMouseDown(e)
86
- }
87
- }
88
-
89
- onDragging = ({ deltaX, deltaY }: IDragParams) => {
90
- const {
91
- model,
92
- graphModel: { transformModel },
93
- } = this.props
94
-
95
- if (deltaX || deltaY) {
96
- const [curDeltaX, curDeltaY] = transformModel.fixDeltaXY(deltaX, deltaY)
97
- model.moveText(curDeltaX, curDeltaY)
98
- }
99
- }
100
-
101
- dbClickHandler = () => {
102
- // 静默模式下,双击不更改状态,不可编辑
103
- const {
104
- editable,
105
- graphModel: { eventCenter },
106
- model,
107
- } = this.props
108
- if (editable) {
109
- model.setElementState(ElementState.TEXT_EDIT)
110
- }
111
- eventCenter.emit(EventType.TEXT_DBCLICK, {
112
- data: model.text,
113
- model,
114
- })
115
- }
116
-
117
- render(): h.JSX.Element | undefined {
118
- const {
119
- model: { text },
120
- } = this.props
121
- if (text) {
122
- return (
123
- <g
124
- onPointerDown={this.mouseDownHandler}
125
- onDblClick={this.dbClickHandler}
126
- >
127
- {this.getShape()}
128
- </g>
129
- )
130
- }
131
- }
132
- }
133
-
134
- export default BaseText
@@ -1,168 +0,0 @@
1
- import { createElement as h } from 'preact/compat'
2
- import { Text, ITextProps, Rect, IRectProps } from '..'
3
- import { BaseText } from '.'
4
- import { BaseEdgeModel, GraphModel } from '../../model'
5
- import { getHtmlTextHeight, getSvgTextSize } from '../../util'
6
-
7
- export type ILineTextProps = {
8
- model: BaseEdgeModel
9
- graphModel: GraphModel
10
- draggable: boolean
11
- editable: boolean
12
- [key: string]: unknown
13
- }
14
-
15
- export type ILineTextState = {
16
- isHovered: boolean
17
- }
18
-
19
- export class LineText extends BaseText<ILineTextProps, ILineTextState> {
20
- constructor(props: ILineTextProps) {
21
- super(props)
22
- this.state = {
23
- isHovered: false,
24
- }
25
- }
26
-
27
- // Hover 状态相关
28
- setHoverOn = () => {
29
- this.setState({
30
- isHovered: true,
31
- })
32
- }
33
- setHoverOff = () => {
34
- this.setState({
35
- isHovered: false,
36
- })
37
- }
38
-
39
- getBackground(): h.JSX.Element | null {
40
- const { isHovered } = this.state
41
- const { model } = this.props
42
- const { text } = model
43
- const style = model.getTextStyle()
44
-
45
- let backgroundStyle = style.background || {}
46
- if (isHovered && style.hover && style.hover.background) {
47
- backgroundStyle = { ...backgroundStyle, ...style.hover.background }
48
- }
49
-
50
- // 当存在文本并且文本背景不为透明时,计算背景框
51
- if (text?.value && backgroundStyle?.fill !== 'transparent') {
52
- const { fontSize, textWidth, lineHeight, overflowMode } = style
53
- const { wrapPadding } = backgroundStyle
54
- const rows = text?.value.split(/[\r\n]/g)
55
- const rowsLength = rows.length
56
-
57
- let { x, y } = text
58
- let rectAttr: unknown = {}
59
-
60
- if (overflowMode === 'autoWrap' && textWidth) {
61
- const textHeight = getHtmlTextHeight({
62
- rows,
63
- style: {
64
- fontSize: `${fontSize}px`,
65
- width: `${textWidth}px`,
66
- lineHeight,
67
- padding: wrapPadding,
68
- },
69
- rowsLength,
70
- className: 'lf-get-text-height',
71
- })
72
-
73
- rectAttr = {
74
- ...backgroundStyle,
75
- x,
76
- y,
77
- width: textWidth,
78
- height: textHeight,
79
- }
80
- } else {
81
- // 背景框宽度,最长一行字节数 / 2 * fontSize + 2
82
- // 背景框宽度,行数 * fontSize + 2
83
- let { width, height } = getSvgTextSize({ rows, rowsLength, fontSize })
84
- if (overflowMode === 'ellipsis') {
85
- // https://github.com/didi/LogicFlow/issues/1151
86
- // 边上的文字过长(使用"ellipsis"模式)出现省略号,背景也需要进行宽度的重新计算
87
-
88
- // 跟Text.tsx保持同样的计算逻辑(overflowMode === 'ellipsis')
89
- // Text.tsx使用textRealWidth=textWidth || width
90
- // Text.tsx使用foreignObjectHeight = fontSize + 2;
91
- width = textWidth
92
- height = fontSize + 2
93
- }
94
-
95
- // 根据设置的 padding 调整 width, height, x, y 的值
96
- // TODO: 下面方法感觉可以提取成工具方法
97
- if (typeof backgroundStyle.wrapPadding === 'string') {
98
- let padding = backgroundStyle.wrapPadding
99
- .split(',')
100
- .filter((padding) => padding.trim())
101
- .map((padding) => parseFloat(padding.trim()))
102
-
103
- if (padding.length > 0 && padding.length <= 4) {
104
- if (padding.length === 1) {
105
- const [allSides] = padding
106
- padding = [allSides, allSides, allSides, allSides]
107
- } else if (padding.length === 2) {
108
- const [vertical, horizontal] = padding
109
- padding = [vertical, horizontal, vertical, horizontal]
110
- } else if (padding.length === 3) {
111
- const [top, horizontal, bottom] = padding
112
- padding = [top, horizontal, bottom, horizontal]
113
- }
114
-
115
- const [top, right, bottom, left] = padding
116
- width += right + left
117
- height += top + bottom
118
- x = x + (right - left) / 2
119
- y = y + (bottom - top) / 2
120
- }
121
- }
122
-
123
- rectAttr = {
124
- ...backgroundStyle,
125
- x: x - 1,
126
- y: y - 1,
127
- width,
128
- height,
129
- }
130
- }
131
-
132
- return <Rect {...(rectAttr as IRectProps)} />
133
- }
134
-
135
- return null
136
- }
137
-
138
- getShape(): h.JSX.Element | null {
139
- const { model } = this.props
140
- const {
141
- text: { x, y, value },
142
- } = model
143
- if (!value) return null
144
-
145
- const style = model.getTextStyle()
146
- const attrs: ITextProps = {
147
- x,
148
- y,
149
- value,
150
- model,
151
- className: 'lf-element-text',
152
- ...style, // 透传 edgeText 属性,如:color, fontSize, fontWeight, fontFamily, textAnchor 等
153
- }
154
-
155
- return (
156
- <g
157
- className="lf-line-text"
158
- onMouseEnter={this.setHoverOn}
159
- onMouseLeave={this.setHoverOff}
160
- >
161
- {this.getBackground()}
162
- <Text {...attrs} />
163
- </g>
164
- )
165
- }
166
- }
167
-
168
- export default LineText
@@ -1,2 +0,0 @@
1
- export * from './BaseText'
2
- export * from './LineText'