@logicflow/core 2.0.0-beta.1 → 2.0.0-beta.3

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 (260) hide show
  1. package/.turbo/turbo-build$colon$dev.log +2 -2
  2. package/.turbo/turbo-build.log +8 -8
  3. package/dist/index.min.js +9 -3
  4. package/es/LogicFlow.d.ts +37 -20
  5. package/es/LogicFlow.js +27 -24
  6. package/es/LogicFlow.js.map +1 -1
  7. package/es/common/drag.d.ts +51 -0
  8. package/es/common/drag.js +145 -0
  9. package/es/common/drag.js.map +1 -0
  10. package/es/common/history.d.ts +28 -0
  11. package/es/common/history.js +92 -0
  12. package/es/common/history.js.map +1 -0
  13. package/es/common/index.d.ts +5 -0
  14. package/es/common/index.js +6 -0
  15. package/es/common/index.js.map +1 -0
  16. package/es/common/keyboard.d.ts +34 -0
  17. package/es/common/keyboard.js +80 -0
  18. package/es/common/keyboard.js.map +1 -0
  19. package/es/common/matrix.d.ts +30 -0
  20. package/es/common/matrix.js +155 -0
  21. package/es/common/matrix.js.map +1 -0
  22. package/es/common/vector.d.ts +23 -0
  23. package/es/common/vector.js +97 -0
  24. package/es/common/vector.js.map +1 -0
  25. package/es/event/eventEmitter.js +1 -1
  26. package/es/event/eventEmitter.js.map +1 -1
  27. package/es/index.d.ts +1 -1
  28. package/es/index.js +1 -1
  29. package/es/index.js.map +1 -1
  30. package/es/model/SnaplineModel.d.ts +2 -0
  31. package/es/model/edge/BaseEdgeModel.d.ts +5 -9
  32. package/es/model/edge/BaseEdgeModel.js +26 -23
  33. package/es/model/edge/BaseEdgeModel.js.map +1 -1
  34. package/es/model/edge/BezierEdgeModel.d.ts +2 -0
  35. package/es/model/edge/LineEdgeModel.d.ts +2 -0
  36. package/es/model/edge/PolylineEdgeModel.d.ts +2 -0
  37. package/es/model/node/BaseNodeModel.js +22 -21
  38. package/es/model/node/BaseNodeModel.js.map +1 -1
  39. package/es/model/node/CircleNodeModel.d.ts +2 -0
  40. package/es/model/node/CircleNodeModel.js +2 -2
  41. package/es/model/node/CircleNodeModel.js.map +1 -1
  42. package/es/model/node/DiamondNodeModel.d.ts +2 -0
  43. package/es/model/node/DiamondNodeModel.js +2 -1
  44. package/es/model/node/DiamondNodeModel.js.map +1 -1
  45. package/es/model/node/EllipseNodeModel.d.ts +2 -0
  46. package/es/model/node/EllipseNodeModel.js +2 -1
  47. package/es/model/node/EllipseNodeModel.js.map +1 -1
  48. package/es/model/node/HtmlNodeModel.d.ts +2 -2
  49. package/es/model/node/HtmlNodeModel.js.map +1 -1
  50. package/es/model/node/PolygonNodeModel.d.ts +2 -0
  51. package/es/model/node/PolygonNodeModel.js +2 -2
  52. package/es/model/node/PolygonNodeModel.js.map +1 -1
  53. package/es/model/node/RectNodeModel.d.ts +3 -0
  54. package/es/model/node/RectNodeModel.js +8 -2
  55. package/es/model/node/RectNodeModel.js.map +1 -1
  56. package/es/model/node/TextNodeModel.d.ts +4 -2
  57. package/es/options.d.ts +2 -2
  58. package/es/options.js +2 -11
  59. package/es/options.js.map +1 -1
  60. package/es/tool/tool.js.map +1 -1
  61. package/es/util/edge.d.ts +6 -0
  62. package/es/util/edge.js +15 -1
  63. package/es/util/edge.js.map +1 -1
  64. package/es/util/node.d.ts +6 -2
  65. package/es/util/node.js +22 -7
  66. package/es/util/node.js.map +1 -1
  67. package/es/view/Anchor.d.ts +1 -1
  68. package/es/view/Anchor.js +3 -3
  69. package/es/view/Anchor.js.map +1 -1
  70. package/es/view/Control.js +14 -2
  71. package/es/view/Control.js.map +1 -1
  72. package/es/view/Graph.d.ts +3 -0
  73. package/es/view/Graph.js +38 -3
  74. package/es/view/Graph.js.map +1 -1
  75. package/es/view/edge/AdjustPoint.js +3 -3
  76. package/es/view/edge/AdjustPoint.js.map +1 -1
  77. package/es/view/edge/BaseEdge.d.ts +2 -2
  78. package/es/view/edge/BaseEdge.js +5 -5
  79. package/es/view/node/BaseNode.d.ts +2 -2
  80. package/es/view/node/BaseNode.js +5 -5
  81. package/es/view/node/TextNode.js +1 -1
  82. package/es/view/node/TextNode.js.map +1 -1
  83. package/es/view/shape/Circle.d.ts +9 -1
  84. package/es/view/shape/Circle.js +5 -5
  85. package/es/view/shape/Circle.js.map +1 -1
  86. package/es/view/shape/Ellipse.d.ts +10 -1
  87. package/es/view/shape/Ellipse.js +5 -5
  88. package/es/view/shape/Ellipse.js.map +1 -1
  89. package/es/view/shape/Line.d.ts +14 -1
  90. package/es/view/shape/Line.js +5 -7
  91. package/es/view/shape/Line.js.map +1 -1
  92. package/es/view/shape/Path.d.ts +3 -2
  93. package/es/view/shape/Path.js +3 -3
  94. package/es/view/shape/Path.js.map +1 -1
  95. package/es/view/shape/Polygon.d.ts +5 -3
  96. package/es/view/shape/Polygon.js +6 -6
  97. package/es/view/shape/Polygon.js.map +1 -1
  98. package/es/view/shape/Polyline.d.ts +7 -1
  99. package/es/view/shape/Polyline.js +8 -6
  100. package/es/view/shape/Polyline.js.map +1 -1
  101. package/es/view/shape/Rect.d.ts +11 -13
  102. package/es/view/shape/Rect.js +6 -9
  103. package/es/view/shape/Rect.js.map +1 -1
  104. package/es/view/shape/Text.d.ts +19 -1
  105. package/es/view/shape/Text.js +28 -21
  106. package/es/view/shape/Text.js.map +1 -1
  107. package/es/view/text/BaseText.d.ts +12 -15
  108. package/es/view/text/BaseText.js +37 -27
  109. package/es/view/text/BaseText.js.map +1 -1
  110. package/es/view/text/LineText.d.ts +19 -7
  111. package/es/view/text/LineText.js +62 -54
  112. package/es/view/text/LineText.js.map +1 -1
  113. package/lib/LogicFlow.d.ts +37 -20
  114. package/lib/LogicFlow.js +26 -23
  115. package/lib/LogicFlow.js.map +1 -1
  116. package/lib/common/drag.d.ts +51 -0
  117. package/lib/common/drag.js +148 -0
  118. package/lib/common/drag.js.map +1 -0
  119. package/lib/common/history.d.ts +28 -0
  120. package/lib/common/history.js +95 -0
  121. package/lib/common/history.js.map +1 -0
  122. package/lib/common/index.d.ts +5 -0
  123. package/lib/common/index.js +22 -0
  124. package/lib/common/index.js.map +1 -0
  125. package/lib/common/keyboard.d.ts +34 -0
  126. package/lib/common/keyboard.js +86 -0
  127. package/lib/common/keyboard.js.map +1 -0
  128. package/lib/common/matrix.d.ts +30 -0
  129. package/lib/common/matrix.js +158 -0
  130. package/lib/common/matrix.js.map +1 -0
  131. package/lib/common/vector.d.ts +23 -0
  132. package/lib/common/vector.js +101 -0
  133. package/lib/common/vector.js.map +1 -0
  134. package/lib/event/eventEmitter.js +1 -1
  135. package/lib/event/eventEmitter.js.map +1 -1
  136. package/lib/index.d.ts +1 -1
  137. package/lib/index.js +2 -2
  138. package/lib/index.js.map +1 -1
  139. package/lib/model/SnaplineModel.d.ts +2 -0
  140. package/lib/model/edge/BaseEdgeModel.d.ts +5 -9
  141. package/lib/model/edge/BaseEdgeModel.js +25 -22
  142. package/lib/model/edge/BaseEdgeModel.js.map +1 -1
  143. package/lib/model/edge/BezierEdgeModel.d.ts +2 -0
  144. package/lib/model/edge/LineEdgeModel.d.ts +2 -0
  145. package/lib/model/edge/PolylineEdgeModel.d.ts +2 -0
  146. package/lib/model/node/BaseNodeModel.js +21 -20
  147. package/lib/model/node/BaseNodeModel.js.map +1 -1
  148. package/lib/model/node/CircleNodeModel.d.ts +2 -0
  149. package/lib/model/node/CircleNodeModel.js +2 -2
  150. package/lib/model/node/CircleNodeModel.js.map +1 -1
  151. package/lib/model/node/DiamondNodeModel.d.ts +2 -0
  152. package/lib/model/node/DiamondNodeModel.js +2 -1
  153. package/lib/model/node/DiamondNodeModel.js.map +1 -1
  154. package/lib/model/node/EllipseNodeModel.d.ts +2 -0
  155. package/lib/model/node/EllipseNodeModel.js +2 -1
  156. package/lib/model/node/EllipseNodeModel.js.map +1 -1
  157. package/lib/model/node/HtmlNodeModel.d.ts +2 -2
  158. package/lib/model/node/HtmlNodeModel.js.map +1 -1
  159. package/lib/model/node/PolygonNodeModel.d.ts +2 -0
  160. package/lib/model/node/PolygonNodeModel.js +2 -2
  161. package/lib/model/node/PolygonNodeModel.js.map +1 -1
  162. package/lib/model/node/RectNodeModel.d.ts +3 -0
  163. package/lib/model/node/RectNodeModel.js +8 -2
  164. package/lib/model/node/RectNodeModel.js.map +1 -1
  165. package/lib/model/node/TextNodeModel.d.ts +4 -2
  166. package/lib/options.d.ts +2 -2
  167. package/lib/options.js +2 -11
  168. package/lib/options.js.map +1 -1
  169. package/lib/tool/tool.js.map +1 -1
  170. package/lib/util/edge.d.ts +6 -0
  171. package/lib/util/edge.js +16 -1
  172. package/lib/util/edge.js.map +1 -1
  173. package/lib/util/node.d.ts +6 -2
  174. package/lib/util/node.js +24 -9
  175. package/lib/util/node.js.map +1 -1
  176. package/lib/view/Anchor.d.ts +1 -1
  177. package/lib/view/Anchor.js +2 -2
  178. package/lib/view/Anchor.js.map +1 -1
  179. package/lib/view/Control.js +14 -2
  180. package/lib/view/Control.js.map +1 -1
  181. package/lib/view/Graph.d.ts +3 -0
  182. package/lib/view/Graph.js +37 -2
  183. package/lib/view/Graph.js.map +1 -1
  184. package/lib/view/edge/AdjustPoint.js +2 -2
  185. package/lib/view/edge/AdjustPoint.js.map +1 -1
  186. package/lib/view/edge/BaseEdge.d.ts +2 -2
  187. package/lib/view/edge/BaseEdge.js +5 -5
  188. package/lib/view/node/BaseNode.d.ts +2 -2
  189. package/lib/view/node/BaseNode.js +5 -5
  190. package/lib/view/node/TextNode.js +1 -1
  191. package/lib/view/node/TextNode.js.map +1 -1
  192. package/lib/view/shape/Circle.d.ts +9 -1
  193. package/lib/view/shape/Circle.js +5 -5
  194. package/lib/view/shape/Circle.js.map +1 -1
  195. package/lib/view/shape/Ellipse.d.ts +10 -1
  196. package/lib/view/shape/Ellipse.js +5 -5
  197. package/lib/view/shape/Ellipse.js.map +1 -1
  198. package/lib/view/shape/Line.d.ts +14 -1
  199. package/lib/view/shape/Line.js +5 -7
  200. package/lib/view/shape/Line.js.map +1 -1
  201. package/lib/view/shape/Path.d.ts +3 -2
  202. package/lib/view/shape/Path.js +3 -3
  203. package/lib/view/shape/Path.js.map +1 -1
  204. package/lib/view/shape/Polygon.d.ts +5 -3
  205. package/lib/view/shape/Polygon.js +6 -6
  206. package/lib/view/shape/Polygon.js.map +1 -1
  207. package/lib/view/shape/Polyline.d.ts +7 -1
  208. package/lib/view/shape/Polyline.js +8 -6
  209. package/lib/view/shape/Polyline.js.map +1 -1
  210. package/lib/view/shape/Rect.d.ts +11 -13
  211. package/lib/view/shape/Rect.js +6 -9
  212. package/lib/view/shape/Rect.js.map +1 -1
  213. package/lib/view/shape/Text.d.ts +19 -1
  214. package/lib/view/shape/Text.js +29 -21
  215. package/lib/view/shape/Text.js.map +1 -1
  216. package/lib/view/text/BaseText.d.ts +12 -15
  217. package/lib/view/text/BaseText.js +40 -27
  218. package/lib/view/text/BaseText.js.map +1 -1
  219. package/lib/view/text/LineText.d.ts +19 -7
  220. package/lib/view/text/LineText.js +62 -57
  221. package/lib/view/text/LineText.js.map +1 -1
  222. package/package.json +2 -1
  223. package/src/LogicFlow.tsx +97 -55
  224. package/src/common/drag.ts +205 -0
  225. package/src/common/history.ts +108 -0
  226. package/src/common/index.ts +6 -0
  227. package/src/common/keyboard.ts +108 -0
  228. package/src/common/matrix.ts +122 -0
  229. package/src/common/vector.ts +93 -0
  230. package/src/event/eventEmitter.ts +1 -1
  231. package/src/index.ts +1 -1
  232. package/src/model/edge/BaseEdgeModel.ts +31 -21
  233. package/src/model/node/BaseNodeModel.ts +27 -19
  234. package/src/model/node/CircleNodeModel.ts +2 -2
  235. package/src/model/node/DiamondNodeModel.ts +2 -0
  236. package/src/model/node/EllipseNodeModel.ts +2 -0
  237. package/src/model/node/HtmlNodeModel.ts +2 -2
  238. package/src/model/node/PolygonNodeModel.ts +2 -2
  239. package/src/model/node/RectNodeModel.ts +9 -2
  240. package/src/options.ts +4 -13
  241. package/src/tool/tool.ts +1 -1
  242. package/src/util/edge.ts +26 -1
  243. package/src/util/node.ts +29 -8
  244. package/src/view/Anchor.tsx +4 -4
  245. package/src/view/Control.tsx +5 -2
  246. package/src/view/Graph.tsx +14 -2
  247. package/src/view/edge/AdjustPoint.tsx +3 -3
  248. package/src/view/edge/BaseEdge.tsx +7 -7
  249. package/src/view/node/BaseNode.tsx +7 -7
  250. package/src/view/node/TextNode.tsx +1 -1
  251. package/src/view/shape/Circle.tsx +21 -7
  252. package/src/view/shape/Ellipse.tsx +20 -6
  253. package/src/view/shape/Line.tsx +24 -9
  254. package/src/view/shape/Path.tsx +9 -6
  255. package/src/view/shape/Polygon.tsx +13 -10
  256. package/src/view/shape/Polyline.tsx +20 -8
  257. package/src/view/shape/Rect.tsx +19 -19
  258. package/src/view/shape/Text.tsx +64 -33
  259. package/src/view/text/BaseText.tsx +67 -41
  260. package/src/view/text/LineText.tsx +94 -80
package/src/util/edge.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { pick } from 'lodash-es'
1
+ import { forEach, pick } from 'lodash-es'
2
2
  import { getNodeBBox, isInNode, distance, sampleCubic } from '.'
3
3
  import LogicFlow from '../LogicFlow'
4
4
  import { Options } from '../options'
@@ -1032,3 +1032,28 @@ export function createEdgeGenerator(
1032
1032
  return Object.assign({ type: result }, currentEdge)
1033
1033
  }
1034
1034
  }
1035
+
1036
+ // 获取 Svg 标签文案高度,自动换行
1037
+ export type IGetSvgTextSizeParams = {
1038
+ rows: string[]
1039
+ rowsLength: number
1040
+ fontSize: number
1041
+ }
1042
+ export const getSvgTextSize = ({
1043
+ rows,
1044
+ rowsLength,
1045
+ fontSize,
1046
+ }: IGetSvgTextSizeParams): LogicFlow.RectSize => {
1047
+ let longestBytes = 0
1048
+ forEach(rows, (row) => {
1049
+ const rowBytesLength = getBytesLength(row)
1050
+ longestBytes = rowBytesLength > longestBytes ? rowBytesLength : longestBytes
1051
+ })
1052
+
1053
+ // 背景框宽度,最长一行字节数/2 * fontsize + 2
1054
+ // 背景框宽度, 行数 * fontsize + 2
1055
+ return {
1056
+ width: Math.ceil(longestBytes / 2) * fontSize + fontSize / 4,
1057
+ height: rowsLength * (fontSize + 2) + fontSize / 4,
1058
+ }
1059
+ }
package/src/util/node.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { pick } from 'lodash-es'
2
+ import { createElement as h } from 'preact/compat'
2
3
  import { getBytesLength } from './edge'
3
4
  import LogicFlow from '../LogicFlow'
4
5
  import {
@@ -444,7 +445,26 @@ export const getNodeAnchorPosition = (
444
445
  }
445
446
  }
446
447
 
447
- // 获取文案高度,自动换行,利用dom计算高度
448
+ /*********************************************************
449
+ * Text 节点文本相关工具函数
450
+ ********************************************************/
451
+ // Text 相关节点工具函数
452
+ // TODO: 获取文案高度,设置自动换行,利用 dom 计算高度
453
+ // function getTextHeight(text: string, font: string): number {
454
+ // const span = document.createElement('span');
455
+ // span.textContent = text;
456
+ // span.style.font = font;
457
+
458
+ // const range = document.createRange();
459
+ // range.selectNodeContents(span);
460
+
461
+ // const rect = range.getBoundingClientRect();
462
+ // const height = rect.height;
463
+
464
+ // return height;
465
+ // }
466
+
467
+ // 获取文案高度,自动换行,利用 dom 计算高度
448
468
  export const getHtmlTextHeight = ({
449
469
  rows,
450
470
  style,
@@ -452,18 +472,18 @@ export const getHtmlTextHeight = ({
452
472
  className,
453
473
  }: {
454
474
  rows: string[]
455
- style: any // TODO: 完善类型
475
+ style: h.JSX.CSSProperties
456
476
  rowsLength: number
457
477
  className: string
458
478
  }) => {
459
479
  const dom = document.createElement('div')
460
- dom.style.fontSize = style.fontSize
461
- dom.style.width = style.width
462
480
  dom.className = className
463
- dom.style.lineHeight = style.lineHeight
464
- dom.style.padding = style.padding
481
+ dom.style.fontSize = `${style.fontSize}`
482
+ dom.style.width = `${style.width}`
483
+ dom.style.lineHeight = `${style.lineHeight}`
484
+ dom.style.padding = `${style.padding}`
465
485
  if (style.fontFamily) {
466
- dom.style.fontFamily = style.fontFamily
486
+ dom.style.fontFamily = `${style.fontFamily}`
467
487
  }
468
488
  if (rowsLength > 1) {
469
489
  rows.forEach((row) => {
@@ -479,6 +499,7 @@ export const getHtmlTextHeight = ({
479
499
  document.body.removeChild(dom)
480
500
  return height
481
501
  }
502
+
482
503
  // 获取文案高度,自动换行,利用dom计算高度
483
504
  export const getSvgTextWidthHeight = ({
484
505
  rows,
@@ -506,7 +527,7 @@ export const getSvgTextWidthHeight = ({
506
527
  /**
507
528
  * @description 格式化边校验信息
508
529
  */
509
- export const formateAnchorConnectValidateData = (
530
+ export const formatAnchorConnectValidateData = (
510
531
  data: Model.ConnectRuleResult,
511
532
  ) => {
512
533
  if (typeof data !== 'object') {
@@ -6,7 +6,7 @@ import { ElementState, EventType } from '../constant'
6
6
  import { GraphModel, BaseNodeModel, Model } from '../model'
7
7
  import {
8
8
  StepDrag,
9
- formateAnchorConnectValidateData,
9
+ formatAnchorConnectValidateData,
10
10
  targetNodeInfo,
11
11
  distance,
12
12
  cancelRaf,
@@ -29,7 +29,7 @@ interface IProps {
29
29
  anchorIndex: number
30
30
  graphModel: GraphModel
31
31
  nodeModel: BaseNodeModel
32
- setHoverOFF: (e: MouseEvent) => void
32
+ setHoverOff: (e: MouseEvent) => void
33
33
  }
34
34
 
35
35
  interface IState {
@@ -326,11 +326,11 @@ class Anchor extends Component<IProps, IState> {
326
326
  )
327
327
  this.sourceRuleResults.set(
328
328
  targetInfoId,
329
- formateAnchorConnectValidateData(sourceRuleResult),
329
+ formatAnchorConnectValidateData(sourceRuleResult),
330
330
  )
331
331
  this.targetRuleResults.set(
332
332
  targetInfoId,
333
- formateAnchorConnectValidateData(targetRuleResult),
333
+ formatAnchorConnectValidateData(targetRuleResult),
334
334
  )
335
335
  }
336
336
  const { isAllPass: isSourcePass } =
@@ -304,6 +304,7 @@ export class ResizeControl extends Component<
304
304
 
305
305
  // 由于将拖拽放大缩小改成丝滑模式,这个时候需要再拖拽结束的时候,将节点的位置更新到 grid 上。
306
306
  onDragEnd = () => {
307
+ // TODO: 确认下面该代码是否还需要(应该是默认让节点拖拽以 gridSize 为步长移动)
307
308
  // const { gridSize = 1 } = this.graphModel
308
309
  // const x = gridSize * Math.round(this.nodeModel.x / gridSize)
309
310
  // const y = gridSize * Math.round(this.nodeModel.y / gridSize)
@@ -319,14 +320,16 @@ export class ResizeControl extends Component<
319
320
 
320
321
  render(): h.JSX.Element {
321
322
  const { x, y, direction, model } = this.props
322
- const style = model.getResizeControlStyle()
323
+ const { width, height, ...restStyle } = model.getResizeControlStyle()
323
324
  return (
324
325
  <g className={`lf-resize-control lf-resize-control-${direction}`}>
325
326
  <Rect
326
327
  className="lf-resize-control-content"
327
328
  x={x}
328
329
  y={y}
329
- {...style}
330
+ width={width ?? 7}
331
+ height={height ?? 7}
332
+ {...restStyle}
330
333
  onMouseDown={this.dragHandler.handleMouseDown}
331
334
  />
332
335
  </g>
@@ -1,5 +1,5 @@
1
1
  import { Component, ComponentType } from 'preact/compat'
2
- import { map } from 'lodash-es'
2
+ import { map, throttle } from 'lodash-es'
3
3
  import {
4
4
  CanvasOverlay,
5
5
  ToolOverlay,
@@ -37,6 +37,18 @@ type ContainerStyle = {
37
37
 
38
38
  @observer
39
39
  class Graph extends Component<IGraphProps> {
40
+ handleResize = () => {
41
+ this.props.graphModel.resize()
42
+ }
43
+
44
+ componentDidMount() {
45
+ window.addEventListener('resize', throttle(this.handleResize, 200))
46
+ }
47
+
48
+ componentWillUnmount() {
49
+ window.removeEventListener('resize', throttle(this.handleResize, 200))
50
+ }
51
+
40
52
  getComponent(
41
53
  model: BaseEdgeModel | BaseNodeModel,
42
54
  graphModel: GraphModel,
@@ -73,7 +85,7 @@ class Graph extends Component<IGraphProps> {
73
85
  const { adjustEdge } = editConfigModel
74
86
 
75
87
  return (
76
- <div className="lf-graph" flow-id={graphModel.flowId} style={style}>
88
+ <div className="lf-graph" flow-id={graphModel.flowId}>
77
89
  <CanvasOverlay graphModel={graphModel} dnd={dnd}>
78
90
  <g className="lf-base">
79
91
  {map(graphModel.sortElements, (nodeModel) =>
@@ -4,7 +4,7 @@ import { GraphModel, BaseNodeModel, BaseEdgeModel, Model } from '../../model'
4
4
  import {
5
5
  IDragParams,
6
6
  StepDrag,
7
- formateAnchorConnectValidateData,
7
+ formatAnchorConnectValidateData,
8
8
  targetNodeInfo,
9
9
  NodeContaint,
10
10
  } from '../../util'
@@ -394,11 +394,11 @@ export class AdjustPoint extends Component<IProps, IState> {
394
394
  )
395
395
  this.sourceRuleResults.set(
396
396
  targetInfoId,
397
- formateAnchorConnectValidateData(sourceRuleResult),
397
+ formatAnchorConnectValidateData(sourceRuleResult),
398
398
  )
399
399
  this.targetRuleResults.set(
400
400
  targetInfoId,
401
- formateAnchorConnectValidateData(targetRuleResult),
401
+ formatAnchorConnectValidateData(targetRuleResult),
402
402
  )
403
403
  }
404
404
  const { isAllPass: isSourcePass, msg: sourceMsg } =
@@ -307,24 +307,24 @@ export abstract class BaseEdge<P extends IProps> extends Component<
307
307
  /**
308
308
  * 不支持重写,如果想要基于hover状态设置不同的样式,请在model中使用isHovered属性。
309
309
  */
310
- setHoverON = (ev: MouseEvent) => {
310
+ setHoverOn = (ev: MouseEvent) => {
311
311
  // ! hover多次触发, onMouseOver + onMouseEnter
312
312
  const {
313
313
  model: { isHovered },
314
314
  } = this.props
315
315
  if (isHovered) return
316
- this.textRef && this.textRef.current && this.textRef.current.setHoverON()
316
+ this.textRef && this.textRef.current && this.textRef.current.setHoverOn()
317
317
  this.handleHover(true, ev)
318
318
  }
319
319
  /**
320
320
  * 不支持重写,如果想要基于hover状态设置不同的样式,请在model中使用isHovered属性。
321
321
  */
322
- setHoverOFF = (ev: MouseEvent) => {
322
+ setHoverOff = (ev: MouseEvent) => {
323
323
  const {
324
324
  model: { isHovered },
325
325
  } = this.props
326
326
  if (!isHovered) return
327
- this.textRef && this.textRef.current && this.textRef.current.setHoverOFF()
327
+ this.textRef && this.textRef.current && this.textRef.current.setHoverOff()
328
328
  this.handleHover(false, ev)
329
329
  }
330
330
  /**
@@ -471,9 +471,9 @@ export abstract class BaseEdge<P extends IProps> extends Component<
471
471
  onMouseDown={this.handleMouseDown}
472
472
  onMouseUp={this.handleMouseUp}
473
473
  onContextMenu={this.handleContextMenu}
474
- onMouseOver={this.setHoverON}
475
- onMouseEnter={this.setHoverON}
476
- onMouseLeave={this.setHoverOFF}
474
+ onMouseOver={this.setHoverOn}
475
+ onMouseEnter={this.setHoverOn}
476
+ onMouseLeave={this.setHoverOff}
477
477
  >
478
478
  {this.getShape()}
479
479
  {this.getAppend()}
@@ -106,7 +106,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
106
106
  anchorIndex={index}
107
107
  nodeModel={model}
108
108
  graphModel={graphModel}
109
- setHoverOFF={this.setHoverOFF}
109
+ setHoverOff={this.setHoverOff}
110
110
  />
111
111
  )
112
112
  })
@@ -395,7 +395,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
395
395
  }
396
396
  // 为什么将hover状态放到model中?
397
397
  // 因为自定义节点的时候,可能会基于hover状态自定义不同的样式。
398
- setHoverON = (ev: MouseEvent) => {
398
+ setHoverOn = (ev: MouseEvent) => {
399
399
  const { model, graphModel } = this.props
400
400
  if (model.isHovered) return
401
401
  const nodeData = model.getData()
@@ -405,7 +405,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
405
405
  e: ev,
406
406
  })
407
407
  }
408
- setHoverOFF = (ev: MouseEvent) => {
408
+ setHoverOff = (ev: MouseEvent) => {
409
409
  const { model, graphModel } = this.props
410
410
  const nodeData = model.getData()
411
411
  if (!model.isHovered) return
@@ -417,7 +417,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
417
417
  }
418
418
  onMouseOut = (ev: MouseEvent) => {
419
419
  if (isIe) {
420
- this.setHoverOFF(ev)
420
+ this.setHoverOff(ev)
421
421
  }
422
422
  }
423
423
 
@@ -476,9 +476,9 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
476
476
  onMouseDown={this.handleMouseDown}
477
477
  onMouseUp={this.handleMouseUp}
478
478
  onClick={this.handleClick}
479
- onMouseEnter={this.setHoverON}
480
- onMouseOver={this.setHoverON}
481
- onMouseLeave={this.setHoverOFF}
479
+ onMouseEnter={this.setHoverOn}
480
+ onMouseOver={this.setHoverOn}
481
+ onMouseLeave={this.setHoverOff}
482
482
  onMouseOut={this.onMouseOut}
483
483
  onContextMenu={this.handleContextMenu}
484
484
  {...restAttributes}
@@ -18,7 +18,7 @@ export class TextNode extends BaseNode<ITextNodeProps> {
18
18
  const rectAttr = {
19
19
  ...style.background,
20
20
  x,
21
- y: y - 1,
21
+ y,
22
22
  width,
23
23
  height,
24
24
  }
@@ -1,26 +1,40 @@
1
- export function Circle(props) {
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+ import { LogicFlow } from '../..'
4
+
5
+ export type ICircleProps = {
6
+ x?: number
7
+ y?: number
8
+ r?: number
9
+ className?: string
10
+ } & LogicFlow.CommonTheme
11
+
12
+ export function Circle(props: ICircleProps): h.JSX.Element {
2
13
  const { x = 0, y = 0, r = 4, className } = props
3
- const attrs: Record<string, any> = {
14
+
15
+ const attrs: ICircleProps = {
4
16
  cx: x,
5
17
  cy: y,
6
18
  r,
7
19
  fill: 'transparent',
8
20
  fillOpacity: 1,
9
- strokeWidth: '1',
21
+ strokeWidth: 1,
10
22
  stroke: '#000',
11
23
  strokeOpacity: 1,
12
24
  }
13
- Object.entries(props).forEach(([k, v]) => {
14
- const valueType = typeof v
15
- if (valueType !== 'object') {
25
+
26
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
27
+ if (typeof v !== 'object') {
16
28
  attrs[k] = v
17
29
  }
18
30
  })
31
+
19
32
  if (className) {
20
33
  attrs.className = `lf-basic-shape ${className}`
21
34
  } else {
22
- attrs.className = 'lf-shape'
35
+ attrs.className = `lf-basic-shape`
23
36
  }
37
+
24
38
  return <circle {...attrs} />
25
39
  }
26
40
 
@@ -1,5 +1,18 @@
1
- export function Ellipse(props) {
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+ import { LogicFlow } from '../..'
4
+
5
+ export type IEllipseProps = {
6
+ x?: number
7
+ y?: number
8
+ rx?: number
9
+ ry?: number
10
+ className?: string
11
+ } & LogicFlow.CommonTheme
12
+
13
+ export function Ellipse(props: IEllipseProps): h.JSX.Element {
2
14
  const { x = 0, y = 0, rx = 4, ry = 4, className } = props
15
+
3
16
  const attrs: Record<string, any> = {
4
17
  cx: x,
5
18
  cy: y,
@@ -7,21 +20,22 @@ export function Ellipse(props) {
7
20
  ry,
8
21
  fill: 'transparent',
9
22
  fillOpacity: 1,
10
- strokeWidth: '1',
23
+ strokeWidth: 1,
11
24
  stroke: '#000',
12
25
  strokeOpacity: 1,
13
26
  }
14
- Object.entries(props).forEach(([k, v]) => {
15
- const valueType = typeof v
16
- if (valueType !== 'object') {
27
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
28
+ if (typeof v !== 'object') {
17
29
  attrs[k] = v
18
30
  }
19
31
  })
32
+
20
33
  if (className) {
21
34
  attrs.className = `lf-basic-shape ${className}`
22
35
  } else {
23
- attrs.className = 'lf-shape'
36
+ attrs.className = `lf-basic-shape`
24
37
  }
38
+
25
39
  return <ellipse {...attrs} />
26
40
  }
27
41
 
@@ -1,23 +1,38 @@
1
- export function Line(props) {
2
- const attrs = {
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+
4
+ export type ILineProps = {
5
+ id?: string
6
+ tabindex?: number
7
+ x1?: number
8
+ y1?: number
9
+ x2?: number
10
+ y2?: number
11
+ stroke?: string // Color
12
+ className?: string
13
+ style?: h.JSX.CSSProperties
14
+ [key: string]: any
15
+ }
16
+
17
+ export function Line(props: ILineProps): h.JSX.Element {
18
+ const attrs: ILineProps = {
3
19
  // default
4
20
  x1: 10,
5
21
  y1: 10,
6
22
  x2: 20,
7
23
  y2: 20,
8
24
  stroke: 'black',
9
- // ...props,
25
+ // ...props
10
26
  }
11
- Object.entries(props).forEach(([k, v]) => {
27
+
28
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
12
29
  if (k === 'style') {
13
30
  attrs[k] = v
14
- } else {
15
- const valueType = typeof v
16
- if (valueType !== 'object') {
17
- attrs[k] = v
18
- }
31
+ } else if (typeof v !== 'object') {
32
+ attrs[k] = v
19
33
  }
20
34
  })
35
+
21
36
  return <line {...attrs} />
22
37
  }
23
38
 
@@ -1,18 +1,21 @@
1
- type IProps = {
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+
4
+ export type IPathProps = {
2
5
  d: string
3
6
  [key: string]: any
4
7
  }
5
8
 
6
- export function Path(props: IProps) {
7
- const attrs = {
9
+ export function Path(props: IPathProps): h.JSX.Element {
10
+ const attrs: Record<string, any> = {
8
11
  d: '',
9
12
  }
10
- Object.entries(props).forEach(([k, v]) => {
11
- const valueType = typeof v
12
- if (k === 'style' || valueType !== 'object') {
13
+ forEach(toPairs(props), ([k, v]: [key: string, v: any]) => {
14
+ if (k === 'style' || typeof v !== 'object') {
13
15
  attrs[k] = v
14
16
  }
15
17
  })
18
+
16
19
  return <path {...attrs} />
17
20
  }
18
21
 
@@ -1,14 +1,16 @@
1
- import LogicFlow from '../../LogicFlow'
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+ import { LogicFlow } from '../..'
2
4
 
3
- // TODO: 定义基础图形的类型
4
5
  export type IPolygonProps = {
5
6
  points: LogicFlow.PointTuple[]
7
+ x?: number
8
+ y?: number
6
9
  className?: string
7
- [key: string]: any
8
10
  }
9
11
 
10
- export function Polygon(props: IPolygonProps) {
11
- const { points, className } = props
12
+ export function Polygon(props: IPolygonProps): h.JSX.Element {
13
+ const { points = [], className } = props
12
14
  const attrs: Record<string, any> = {
13
15
  fill: 'transparent',
14
16
  fillOpacity: 1,
@@ -17,16 +19,17 @@ export function Polygon(props: IPolygonProps) {
17
19
  strokeOpacity: 1,
18
20
  points: '',
19
21
  }
20
- Object.entries(props).forEach(([k, v]) => {
21
- const valueType = typeof v
22
- if (valueType !== 'object') {
22
+
23
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
24
+ if (typeof v !== 'object') {
23
25
  attrs[k] = v
24
26
  }
25
27
  })
28
+
26
29
  if (className) {
27
- attrs.className = `lf-basic-shape ${className}`
30
+ attrs.classNmae = `lf-basic-shape ${className}`
28
31
  } else {
29
- attrs.className = 'lf-shape'
32
+ attrs.className = 'lf-basic-shape'
30
33
  }
31
34
  attrs.points = points.map((point) => point.join(',')).join(' ')
32
35
 
@@ -1,18 +1,30 @@
1
- export function Polyline(props) {
2
- const attrs = {
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> = {
3
13
  points: '',
4
14
  fill: 'none',
5
15
  }
6
- Object.entries(props).forEach(([k, v]) => {
16
+
17
+ forEach(toPairs(props), ([k, v]: [k: string, v: unknown]) => {
7
18
  if (k === 'style') {
8
19
  attrs[k] = v
9
- } else {
10
- const valueType = typeof v
11
- if (valueType !== 'object') {
12
- attrs[k] = v
13
- }
20
+ } else if (typeof v !== 'object') {
21
+ attrs[k] = v
14
22
  }
15
23
  })
24
+ if (className) {
25
+ attrs.className = `${className}`
26
+ }
27
+
16
28
  return <polyline {...attrs} />
17
29
  }
18
30
 
@@ -1,23 +1,26 @@
1
- import LogicFlow from '../../LogicFlow'
1
+ import { createElement as h } from 'preact/compat'
2
+ import { forEach, toPairs } from 'lodash-es'
3
+ import LogicFlow from '../..'
2
4
 
3
- import Point = LogicFlow.Point
4
- import RectSize = LogicFlow.RectSize
5
-
6
- type IRectProps = {
5
+ export type IRectProps = {
6
+ x: number
7
+ y: number
8
+ width: number
9
+ height: number
7
10
  className?: string
8
- radius?: number
9
- } & Point &
10
- RectSize
11
+ radius?: LogicFlow.NumberOrPercent
12
+ [key: string]: any
13
+ }
11
14
 
12
- export function Rect(props: IRectProps) {
13
- const { x, y, width, height, className, radius } = props
15
+ export function Rect(props: IRectProps): h.JSX.Element {
16
+ const { x, y, width, height, className, strokeWidth, radius = 0 } = props
14
17
 
15
18
  const leftTopX = x - width / 2
16
19
  const leftTopY = y - height / 2
17
20
  const attrs: Record<string, any> = {}
18
- Object.entries(props).forEach(([k, v]) => {
19
- const valueType = typeof v
20
- if (valueType !== 'object') {
21
+ attrs['stroke-width'] = strokeWidth
22
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
23
+ if (typeof v !== 'object') {
21
24
  attrs[k] = v
22
25
  }
23
26
  })
@@ -25,20 +28,17 @@ export function Rect(props: IRectProps) {
25
28
  if (className) {
26
29
  attrs.className = `lf-basic-shape ${className}`
27
30
  } else {
28
- attrs.className = 'lf-shape'
31
+ attrs.className = 'lf-basic-shape'
29
32
  }
33
+
30
34
  if (radius) {
31
35
  attrs.rx = radius
32
36
  attrs.ry = radius
33
37
  }
34
38
  attrs.x = leftTopX
35
39
  attrs.y = leftTopY
36
- return <rect {...attrs} />
37
- }
38
40
 
39
- Rect.defaultProps = {
40
- className: '',
41
- radius: '',
41
+ return <rect {...attrs} />
42
42
  }
43
43
 
44
44
  export default Rect