@logicflow/core 2.0.0-beta.0 → 2.0.0-beta.10

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 (479) hide show
  1. package/.turbo/turbo-build$colon$dev.log +2 -2
  2. package/.turbo/turbo-build.log +16 -22
  3. package/__tests__/bugs/1545-spec.test.ts +19 -15
  4. package/__tests__/util/edge.test.ts +57 -57
  5. package/dist/index.min.js +32 -0
  6. package/dist/index.min.js.map +1 -0
  7. package/es/LogicFlow.d.ts +88 -40
  8. package/es/LogicFlow.js +38 -33
  9. package/es/LogicFlow.js.map +1 -1
  10. package/es/algorithm/edge.js.map +1 -1
  11. package/es/algorithm/index.d.ts +2 -0
  12. package/es/algorithm/index.js +2 -0
  13. package/es/algorithm/index.js.map +1 -1
  14. package/es/algorithm/outline.d.ts +1 -1
  15. package/es/common/drag.d.ts +51 -0
  16. package/es/common/drag.js +145 -0
  17. package/es/common/drag.js.map +1 -0
  18. package/es/common/history.d.ts +28 -0
  19. package/es/common/history.js +92 -0
  20. package/es/common/history.js.map +1 -0
  21. package/es/common/index.d.ts +5 -0
  22. package/es/common/index.js +6 -0
  23. package/es/common/index.js.map +1 -0
  24. package/es/common/keyboard.d.ts +34 -0
  25. package/es/common/keyboard.js +80 -0
  26. package/es/common/keyboard.js.map +1 -0
  27. package/es/common/matrix.d.ts +30 -0
  28. package/es/common/matrix.js +155 -0
  29. package/es/common/matrix.js.map +1 -0
  30. package/es/common/vector.d.ts +23 -0
  31. package/es/common/vector.js +97 -0
  32. package/es/common/vector.js.map +1 -0
  33. package/es/constant/index.d.ts +39 -2
  34. package/es/constant/index.js +41 -1
  35. package/es/constant/index.js.map +1 -1
  36. package/es/event/eventArgs.d.ts +103 -25
  37. package/es/event/eventEmitter.d.ts +2 -2
  38. package/es/event/eventEmitter.js +0 -1
  39. package/es/event/eventEmitter.js.map +1 -1
  40. package/es/index.d.ts +6 -1
  41. package/es/index.js +6 -1
  42. package/es/index.js.map +1 -1
  43. package/es/keyboard/index.d.ts +1 -0
  44. package/es/keyboard/index.js +1 -0
  45. package/es/keyboard/index.js.map +1 -1
  46. package/es/keyboard/shortcut.d.ts +8 -0
  47. package/es/keyboard/shortcut.js +70 -8
  48. package/es/keyboard/shortcut.js.map +1 -1
  49. package/es/model/BaseModel.d.ts +16 -7
  50. package/es/model/EditConfigModel.d.ts +97 -36
  51. package/es/model/EditConfigModel.js +169 -82
  52. package/es/model/EditConfigModel.js.map +1 -1
  53. package/es/model/GraphModel.d.ts +36 -14
  54. package/es/model/GraphModel.js +60 -10
  55. package/es/model/GraphModel.js.map +1 -1
  56. package/es/model/SnaplineModel.d.ts +2 -0
  57. package/es/model/TransformModel.js +1 -1
  58. package/es/model/TransformModel.js.map +1 -1
  59. package/es/model/edge/BaseEdgeModel.d.ts +21 -17
  60. package/es/model/edge/BaseEdgeModel.js +64 -42
  61. package/es/model/edge/BaseEdgeModel.js.map +1 -1
  62. package/es/model/edge/BezierEdgeModel.d.ts +5 -3
  63. package/es/model/edge/BezierEdgeModel.js +7 -3
  64. package/es/model/edge/BezierEdgeModel.js.map +1 -1
  65. package/es/model/edge/LineEdgeModel.d.ts +2 -0
  66. package/es/model/edge/LineEdgeModel.js +2 -1
  67. package/es/model/edge/LineEdgeModel.js.map +1 -1
  68. package/es/model/edge/PolylineEdgeModel.d.ts +5 -3
  69. package/es/model/edge/PolylineEdgeModel.js +22 -15
  70. package/es/model/edge/PolylineEdgeModel.js.map +1 -1
  71. package/es/model/node/BaseNodeModel.d.ts +42 -14
  72. package/es/model/node/BaseNodeModel.js +62 -48
  73. package/es/model/node/BaseNodeModel.js.map +1 -1
  74. package/es/model/node/CircleNodeModel.d.ts +4 -3
  75. package/es/model/node/CircleNodeModel.js +4 -7
  76. package/es/model/node/CircleNodeModel.js.map +1 -1
  77. package/es/model/node/DiamondNodeModel.d.ts +5 -4
  78. package/es/model/node/DiamondNodeModel.js +4 -6
  79. package/es/model/node/DiamondNodeModel.js.map +1 -1
  80. package/es/model/node/EllipseNodeModel.d.ts +5 -4
  81. package/es/model/node/EllipseNodeModel.js +4 -6
  82. package/es/model/node/EllipseNodeModel.js.map +1 -1
  83. package/es/model/node/HtmlNodeModel.d.ts +4 -5
  84. package/es/model/node/HtmlNodeModel.js +2 -12
  85. package/es/model/node/HtmlNodeModel.js.map +1 -1
  86. package/es/model/node/PolygonNodeModel.d.ts +5 -4
  87. package/es/model/node/PolygonNodeModel.js +4 -7
  88. package/es/model/node/PolygonNodeModel.js.map +1 -1
  89. package/es/model/node/RectNodeModel.d.ts +7 -5
  90. package/es/model/node/RectNodeModel.js +10 -7
  91. package/es/model/node/RectNodeModel.js.map +1 -1
  92. package/es/model/node/TextNodeModel.d.ts +17 -9
  93. package/es/model/node/TextNodeModel.js +2 -1
  94. package/es/model/node/TextNodeModel.js.map +1 -1
  95. package/es/options.d.ts +11 -14
  96. package/es/options.js +3 -42
  97. package/es/options.js.map +1 -1
  98. package/es/tool/MultipleSelectTool.d.ts +1 -1
  99. package/es/tool/MultipleSelectTool.js +5 -5
  100. package/es/tool/MultipleSelectTool.js.map +1 -1
  101. package/es/tool/TextEditTool.d.ts +3 -3
  102. package/es/tool/TextEditTool.js +2 -2
  103. package/es/tool/TextEditTool.js.map +1 -1
  104. package/es/tool/index.d.ts +24 -2
  105. package/es/tool/index.js +82 -2
  106. package/es/tool/index.js.map +1 -1
  107. package/es/util/drag.d.ts +5 -5
  108. package/es/util/drag.js +3 -1
  109. package/es/util/drag.js.map +1 -1
  110. package/es/util/edge.d.ts +9 -2
  111. package/es/util/edge.js +23 -12
  112. package/es/util/edge.js.map +1 -1
  113. package/es/util/index.d.ts +1 -0
  114. package/es/util/index.js +1 -0
  115. package/es/util/index.js.map +1 -1
  116. package/es/util/node.d.ts +8 -7
  117. package/es/util/node.js +26 -7
  118. package/es/util/node.js.map +1 -1
  119. package/es/util/resize.d.ts +32 -0
  120. package/es/util/resize.js +197 -0
  121. package/es/util/resize.js.map +1 -0
  122. package/es/view/Anchor.d.ts +6 -7
  123. package/es/view/Anchor.js +6 -3
  124. package/es/view/Anchor.js.map +1 -1
  125. package/es/view/Control.d.ts +1 -1
  126. package/es/view/Control.js +88 -39
  127. package/es/view/Control.js.map +1 -1
  128. package/es/view/Graph.d.ts +5 -1
  129. package/es/view/Graph.js +45 -5
  130. package/es/view/Graph.js.map +1 -1
  131. package/es/view/Rotate.js +2 -1
  132. package/es/view/Rotate.js.map +1 -1
  133. package/es/view/behavior/index.d.ts +2 -0
  134. package/es/view/behavior/index.js +3 -0
  135. package/es/view/behavior/index.js.map +1 -0
  136. package/es/view/behavior/snapline.d.ts +3 -0
  137. package/es/{tool → view/behavior}/snapline.js +0 -1
  138. package/es/view/behavior/snapline.js.map +1 -0
  139. package/es/view/edge/AdjustPoint.js +12 -23
  140. package/es/view/edge/AdjustPoint.js.map +1 -1
  141. package/es/view/edge/BaseEdge.d.ts +2 -2
  142. package/es/view/edge/BaseEdge.js +30 -22
  143. package/es/view/edge/BaseEdge.js.map +1 -1
  144. package/es/view/node/BaseNode.d.ts +4 -4
  145. package/es/view/node/BaseNode.js +33 -24
  146. package/es/view/node/BaseNode.js.map +1 -1
  147. package/es/view/node/CircleNode.d.ts +1 -1
  148. package/es/view/node/CircleNode.js.map +1 -1
  149. package/es/view/node/DiamondNode.d.ts +1 -1
  150. package/es/view/node/DiamondNode.js.map +1 -1
  151. package/es/view/node/EllipseNode.d.ts +1 -1
  152. package/es/view/node/EllipseNode.js.map +1 -1
  153. package/es/view/node/HtmlNode.d.ts +1 -1
  154. package/es/view/node/HtmlNode.js +2 -2
  155. package/es/view/node/HtmlNode.js.map +1 -1
  156. package/es/view/node/PolygonNode.d.ts +1 -1
  157. package/es/view/node/PolygonNode.js.map +1 -1
  158. package/es/view/node/RectNode.d.ts +1 -1
  159. package/es/view/node/RectNode.js.map +1 -1
  160. package/es/view/node/TextNode.d.ts +1 -1
  161. package/es/view/node/TextNode.js +1 -1
  162. package/es/view/node/TextNode.js.map +1 -1
  163. package/es/view/overlay/CanvasOverlay.js +5 -4
  164. package/es/view/overlay/CanvasOverlay.js.map +1 -1
  165. package/es/view/overlay/Grid.d.ts +35 -20
  166. package/es/view/overlay/Grid.js +35 -26
  167. package/es/view/overlay/Grid.js.map +1 -1
  168. package/es/view/overlay/ToolOverlay.d.ts +1 -1
  169. package/es/view/overlay/ToolOverlay.js +1 -1
  170. package/es/view/overlay/ToolOverlay.js.map +1 -1
  171. package/es/view/shape/Circle.d.ts +9 -1
  172. package/es/view/shape/Circle.js +5 -5
  173. package/es/view/shape/Circle.js.map +1 -1
  174. package/es/view/shape/Ellipse.d.ts +10 -1
  175. package/es/view/shape/Ellipse.js +5 -5
  176. package/es/view/shape/Ellipse.js.map +1 -1
  177. package/es/view/shape/Line.d.ts +14 -1
  178. package/es/view/shape/Line.js +5 -7
  179. package/es/view/shape/Line.js.map +1 -1
  180. package/es/view/shape/Path.d.ts +3 -2
  181. package/es/view/shape/Path.js +3 -3
  182. package/es/view/shape/Path.js.map +1 -1
  183. package/es/view/shape/Polygon.d.ts +5 -3
  184. package/es/view/shape/Polygon.js +6 -6
  185. package/es/view/shape/Polygon.js.map +1 -1
  186. package/es/view/shape/Polyline.d.ts +7 -1
  187. package/es/view/shape/Polyline.js +8 -6
  188. package/es/view/shape/Polyline.js.map +1 -1
  189. package/es/view/shape/Rect.d.ts +11 -13
  190. package/es/view/shape/Rect.js +6 -9
  191. package/es/view/shape/Rect.js.map +1 -1
  192. package/es/view/shape/Text.d.ts +19 -1
  193. package/es/view/shape/Text.js +28 -21
  194. package/es/view/shape/Text.js.map +1 -1
  195. package/es/view/text/BaseText.d.ts +12 -15
  196. package/es/view/text/BaseText.js +43 -29
  197. package/es/view/text/BaseText.js.map +1 -1
  198. package/es/view/text/LineText.d.ts +19 -7
  199. package/es/view/text/LineText.js +62 -54
  200. package/es/view/text/LineText.js.map +1 -1
  201. package/lib/LogicFlow.d.ts +88 -40
  202. package/lib/LogicFlow.js +40 -35
  203. package/lib/LogicFlow.js.map +1 -1
  204. package/lib/algorithm/edge.js.map +1 -1
  205. package/lib/algorithm/index.d.ts +2 -0
  206. package/lib/algorithm/index.js +17 -1
  207. package/lib/algorithm/index.js.map +1 -1
  208. package/lib/algorithm/outline.d.ts +1 -1
  209. package/lib/common/drag.d.ts +51 -0
  210. package/lib/common/drag.js +148 -0
  211. package/lib/common/drag.js.map +1 -0
  212. package/lib/common/history.d.ts +28 -0
  213. package/lib/common/history.js +95 -0
  214. package/lib/common/history.js.map +1 -0
  215. package/lib/common/index.d.ts +5 -0
  216. package/lib/common/index.js +22 -0
  217. package/lib/common/index.js.map +1 -0
  218. package/lib/common/keyboard.d.ts +34 -0
  219. package/lib/common/keyboard.js +86 -0
  220. package/lib/common/keyboard.js.map +1 -0
  221. package/lib/common/matrix.d.ts +30 -0
  222. package/lib/common/matrix.js +158 -0
  223. package/lib/common/matrix.js.map +1 -0
  224. package/lib/common/vector.d.ts +23 -0
  225. package/lib/common/vector.js +101 -0
  226. package/lib/common/vector.js.map +1 -0
  227. package/lib/constant/index.d.ts +39 -2
  228. package/lib/constant/index.js +42 -2
  229. package/lib/constant/index.js.map +1 -1
  230. package/lib/event/eventArgs.d.ts +103 -25
  231. package/lib/event/eventEmitter.d.ts +2 -2
  232. package/lib/event/eventEmitter.js +0 -1
  233. package/lib/event/eventEmitter.js.map +1 -1
  234. package/lib/index.d.ts +6 -1
  235. package/lib/index.js +7 -2
  236. package/lib/index.js.map +1 -1
  237. package/lib/keyboard/index.d.ts +1 -0
  238. package/lib/keyboard/index.js +15 -0
  239. package/lib/keyboard/index.js.map +1 -1
  240. package/lib/keyboard/shortcut.d.ts +8 -0
  241. package/lib/keyboard/shortcut.js +75 -9
  242. package/lib/keyboard/shortcut.js.map +1 -1
  243. package/lib/model/BaseModel.d.ts +16 -7
  244. package/lib/model/EditConfigModel.d.ts +97 -36
  245. package/lib/model/EditConfigModel.js +168 -81
  246. package/lib/model/EditConfigModel.js.map +1 -1
  247. package/lib/model/GraphModel.d.ts +36 -14
  248. package/lib/model/GraphModel.js +59 -9
  249. package/lib/model/GraphModel.js.map +1 -1
  250. package/lib/model/SnaplineModel.d.ts +2 -0
  251. package/lib/model/TransformModel.js +1 -1
  252. package/lib/model/TransformModel.js.map +1 -1
  253. package/lib/model/edge/BaseEdgeModel.d.ts +21 -17
  254. package/lib/model/edge/BaseEdgeModel.js +61 -39
  255. package/lib/model/edge/BaseEdgeModel.js.map +1 -1
  256. package/lib/model/edge/BezierEdgeModel.d.ts +5 -3
  257. package/lib/model/edge/BezierEdgeModel.js +6 -2
  258. package/lib/model/edge/BezierEdgeModel.js.map +1 -1
  259. package/lib/model/edge/LineEdgeModel.d.ts +2 -0
  260. package/lib/model/edge/LineEdgeModel.js +2 -1
  261. package/lib/model/edge/LineEdgeModel.js.map +1 -1
  262. package/lib/model/edge/PolylineEdgeModel.d.ts +5 -3
  263. package/lib/model/edge/PolylineEdgeModel.js +21 -14
  264. package/lib/model/edge/PolylineEdgeModel.js.map +1 -1
  265. package/lib/model/node/BaseNodeModel.d.ts +42 -14
  266. package/lib/model/node/BaseNodeModel.js +60 -46
  267. package/lib/model/node/BaseNodeModel.js.map +1 -1
  268. package/lib/model/node/CircleNodeModel.d.ts +4 -3
  269. package/lib/model/node/CircleNodeModel.js +4 -7
  270. package/lib/model/node/CircleNodeModel.js.map +1 -1
  271. package/lib/model/node/DiamondNodeModel.d.ts +5 -4
  272. package/lib/model/node/DiamondNodeModel.js +4 -6
  273. package/lib/model/node/DiamondNodeModel.js.map +1 -1
  274. package/lib/model/node/EllipseNodeModel.d.ts +5 -4
  275. package/lib/model/node/EllipseNodeModel.js +4 -6
  276. package/lib/model/node/EllipseNodeModel.js.map +1 -1
  277. package/lib/model/node/HtmlNodeModel.d.ts +4 -5
  278. package/lib/model/node/HtmlNodeModel.js +2 -12
  279. package/lib/model/node/HtmlNodeModel.js.map +1 -1
  280. package/lib/model/node/PolygonNodeModel.d.ts +5 -4
  281. package/lib/model/node/PolygonNodeModel.js +4 -7
  282. package/lib/model/node/PolygonNodeModel.js.map +1 -1
  283. package/lib/model/node/RectNodeModel.d.ts +7 -5
  284. package/lib/model/node/RectNodeModel.js +10 -7
  285. package/lib/model/node/RectNodeModel.js.map +1 -1
  286. package/lib/model/node/TextNodeModel.d.ts +17 -9
  287. package/lib/model/node/TextNodeModel.js +2 -1
  288. package/lib/model/node/TextNodeModel.js.map +1 -1
  289. package/lib/options.d.ts +11 -14
  290. package/lib/options.js +3 -42
  291. package/lib/options.js.map +1 -1
  292. package/lib/tool/MultipleSelectTool.d.ts +1 -1
  293. package/lib/tool/MultipleSelectTool.js +5 -5
  294. package/lib/tool/MultipleSelectTool.js.map +1 -1
  295. package/lib/tool/TextEditTool.d.ts +3 -3
  296. package/lib/tool/TextEditTool.js +4 -4
  297. package/lib/tool/TextEditTool.js.map +1 -1
  298. package/lib/tool/index.d.ts +24 -2
  299. package/lib/tool/index.js +85 -15
  300. package/lib/tool/index.js.map +1 -1
  301. package/lib/util/drag.d.ts +5 -5
  302. package/lib/util/drag.js +3 -1
  303. package/lib/util/drag.js.map +1 -1
  304. package/lib/util/edge.d.ts +9 -2
  305. package/lib/util/edge.js +27 -15
  306. package/lib/util/edge.js.map +1 -1
  307. package/lib/util/index.d.ts +1 -0
  308. package/lib/util/index.js +1 -0
  309. package/lib/util/index.js.map +1 -1
  310. package/lib/util/node.d.ts +8 -7
  311. package/lib/util/node.js +28 -9
  312. package/lib/util/node.js.map +1 -1
  313. package/lib/util/resize.d.ts +32 -0
  314. package/lib/util/resize.js +204 -0
  315. package/lib/util/resize.js.map +1 -0
  316. package/lib/view/Anchor.d.ts +6 -7
  317. package/lib/view/Anchor.js +5 -2
  318. package/lib/view/Anchor.js.map +1 -1
  319. package/lib/view/Control.d.ts +1 -1
  320. package/lib/view/Control.js +87 -38
  321. package/lib/view/Control.js.map +1 -1
  322. package/lib/view/Graph.d.ts +5 -1
  323. package/lib/view/Graph.js +44 -4
  324. package/lib/view/Graph.js.map +1 -1
  325. package/lib/view/Rotate.js +2 -1
  326. package/lib/view/Rotate.js.map +1 -1
  327. package/lib/view/behavior/index.d.ts +2 -0
  328. package/lib/view/behavior/index.js +19 -0
  329. package/lib/view/behavior/index.js.map +1 -0
  330. package/lib/view/behavior/snapline.d.ts +3 -0
  331. package/lib/{tool → view/behavior}/snapline.js +0 -1
  332. package/lib/view/behavior/snapline.js.map +1 -0
  333. package/lib/view/edge/AdjustPoint.js +11 -22
  334. package/lib/view/edge/AdjustPoint.js.map +1 -1
  335. package/lib/view/edge/BaseEdge.d.ts +2 -2
  336. package/lib/view/edge/BaseEdge.js +29 -21
  337. package/lib/view/edge/BaseEdge.js.map +1 -1
  338. package/lib/view/node/BaseNode.d.ts +4 -4
  339. package/lib/view/node/BaseNode.js +32 -23
  340. package/lib/view/node/BaseNode.js.map +1 -1
  341. package/lib/view/node/CircleNode.d.ts +1 -1
  342. package/lib/view/node/CircleNode.js.map +1 -1
  343. package/lib/view/node/DiamondNode.d.ts +1 -1
  344. package/lib/view/node/DiamondNode.js.map +1 -1
  345. package/lib/view/node/EllipseNode.d.ts +1 -1
  346. package/lib/view/node/EllipseNode.js.map +1 -1
  347. package/lib/view/node/HtmlNode.d.ts +1 -1
  348. package/lib/view/node/HtmlNode.js +2 -2
  349. package/lib/view/node/HtmlNode.js.map +1 -1
  350. package/lib/view/node/PolygonNode.d.ts +1 -1
  351. package/lib/view/node/PolygonNode.js.map +1 -1
  352. package/lib/view/node/RectNode.d.ts +1 -1
  353. package/lib/view/node/RectNode.js.map +1 -1
  354. package/lib/view/node/TextNode.d.ts +1 -1
  355. package/lib/view/node/TextNode.js +1 -1
  356. package/lib/view/node/TextNode.js.map +1 -1
  357. package/lib/view/overlay/CanvasOverlay.js +5 -4
  358. package/lib/view/overlay/CanvasOverlay.js.map +1 -1
  359. package/lib/view/overlay/Grid.d.ts +35 -20
  360. package/lib/view/overlay/Grid.js +35 -26
  361. package/lib/view/overlay/Grid.js.map +1 -1
  362. package/lib/view/overlay/ToolOverlay.d.ts +1 -1
  363. package/lib/view/overlay/ToolOverlay.js +1 -1
  364. package/lib/view/overlay/ToolOverlay.js.map +1 -1
  365. package/lib/view/shape/Circle.d.ts +9 -1
  366. package/lib/view/shape/Circle.js +5 -5
  367. package/lib/view/shape/Circle.js.map +1 -1
  368. package/lib/view/shape/Ellipse.d.ts +10 -1
  369. package/lib/view/shape/Ellipse.js +5 -5
  370. package/lib/view/shape/Ellipse.js.map +1 -1
  371. package/lib/view/shape/Line.d.ts +14 -1
  372. package/lib/view/shape/Line.js +5 -7
  373. package/lib/view/shape/Line.js.map +1 -1
  374. package/lib/view/shape/Path.d.ts +3 -2
  375. package/lib/view/shape/Path.js +3 -3
  376. package/lib/view/shape/Path.js.map +1 -1
  377. package/lib/view/shape/Polygon.d.ts +5 -3
  378. package/lib/view/shape/Polygon.js +6 -6
  379. package/lib/view/shape/Polygon.js.map +1 -1
  380. package/lib/view/shape/Polyline.d.ts +7 -1
  381. package/lib/view/shape/Polyline.js +8 -6
  382. package/lib/view/shape/Polyline.js.map +1 -1
  383. package/lib/view/shape/Rect.d.ts +11 -13
  384. package/lib/view/shape/Rect.js +6 -9
  385. package/lib/view/shape/Rect.js.map +1 -1
  386. package/lib/view/shape/Text.d.ts +19 -1
  387. package/lib/view/shape/Text.js +29 -21
  388. package/lib/view/shape/Text.js.map +1 -1
  389. package/lib/view/text/BaseText.d.ts +12 -15
  390. package/lib/view/text/BaseText.js +46 -29
  391. package/lib/view/text/BaseText.js.map +1 -1
  392. package/lib/view/text/LineText.d.ts +19 -7
  393. package/lib/view/text/LineText.js +62 -57
  394. package/lib/view/text/LineText.js.map +1 -1
  395. package/package.json +5 -4
  396. package/src/LogicFlow.tsx +163 -79
  397. package/src/algorithm/edge.ts +1 -0
  398. package/src/algorithm/index.ts +2 -0
  399. package/src/algorithm/outline.ts +2 -2
  400. package/src/common/drag.ts +219 -0
  401. package/src/common/history.ts +108 -0
  402. package/src/common/index.ts +6 -0
  403. package/src/common/keyboard.ts +108 -0
  404. package/src/common/matrix.ts +122 -0
  405. package/src/common/vector.ts +93 -0
  406. package/src/constant/index.ts +43 -1
  407. package/src/event/eventArgs.ts +173 -34
  408. package/src/event/eventEmitter.ts +2 -3
  409. package/src/index.ts +6 -1
  410. package/src/keyboard/index.ts +2 -0
  411. package/src/keyboard/shortcut.ts +79 -8
  412. package/src/model/BaseModel.ts +18 -7
  413. package/src/model/EditConfigModel.ts +209 -97
  414. package/src/model/GraphModel.ts +64 -9
  415. package/src/model/TransformModel.ts +1 -1
  416. package/src/model/edge/BaseEdgeModel.ts +105 -42
  417. package/src/model/edge/BezierEdgeModel.ts +7 -6
  418. package/src/model/edge/LineEdgeModel.ts +2 -0
  419. package/src/model/edge/PolylineEdgeModel.ts +24 -18
  420. package/src/model/node/BaseNodeModel.ts +72 -47
  421. package/src/model/node/CircleNodeModel.ts +8 -7
  422. package/src/model/node/DiamondNodeModel.ts +9 -6
  423. package/src/model/node/EllipseNodeModel.ts +9 -6
  424. package/src/model/node/HtmlNodeModel.ts +8 -7
  425. package/src/model/node/PolygonNodeModel.ts +9 -7
  426. package/src/model/node/RectNodeModel.ts +16 -8
  427. package/src/model/node/TextNodeModel.ts +14 -1
  428. package/src/options.ts +18 -53
  429. package/src/tool/MultipleSelectTool.tsx +6 -6
  430. package/src/tool/TextEditTool.tsx +3 -3
  431. package/src/tool/index.ts +96 -2
  432. package/src/util/drag.ts +22 -6
  433. package/src/util/edge.ts +39 -13
  434. package/src/util/index.ts +1 -0
  435. package/src/util/node.ts +36 -13
  436. package/src/util/resize.ts +286 -0
  437. package/src/view/Anchor.tsx +7 -5
  438. package/src/view/Control.tsx +93 -62
  439. package/src/view/Graph.tsx +23 -6
  440. package/src/view/Rotate.tsx +2 -1
  441. package/src/view/behavior/index.ts +2 -0
  442. package/src/{tool → view/behavior}/snapline.ts +3 -4
  443. package/src/view/edge/AdjustPoint.tsx +35 -49
  444. package/src/view/edge/BaseEdge.tsx +65 -45
  445. package/src/view/node/BaseNode.tsx +55 -28
  446. package/src/view/node/CircleNode.tsx +3 -1
  447. package/src/view/node/DiamondNode.tsx +3 -1
  448. package/src/view/node/EllipseNode.tsx +3 -1
  449. package/src/view/node/HtmlNode.tsx +5 -3
  450. package/src/view/node/PolygonNode.tsx +3 -1
  451. package/src/view/node/RectNode.tsx +3 -1
  452. package/src/view/node/TextNode.tsx +4 -2
  453. package/src/view/overlay/CanvasOverlay.tsx +5 -4
  454. package/src/view/overlay/Grid.tsx +75 -53
  455. package/src/view/overlay/ToolOverlay.tsx +1 -1
  456. package/src/view/shape/Circle.tsx +21 -7
  457. package/src/view/shape/Ellipse.tsx +20 -6
  458. package/src/view/shape/Line.tsx +24 -9
  459. package/src/view/shape/Path.tsx +9 -6
  460. package/src/view/shape/Polygon.tsx +13 -10
  461. package/src/view/shape/Polyline.tsx +20 -8
  462. package/src/view/shape/Rect.tsx +19 -19
  463. package/src/view/shape/Text.tsx +64 -33
  464. package/src/view/text/BaseText.tsx +76 -42
  465. package/src/view/text/LineText.tsx +94 -80
  466. package/tsconfig.json +1 -1
  467. package/dist/index.js +0 -26
  468. package/dist/index.js.map +0 -1
  469. package/es/tool/snapline.d.ts +0 -3
  470. package/es/tool/snapline.js.map +0 -1
  471. package/es/tool/tool.d.ts +0 -22
  472. package/es/tool/tool.js +0 -43
  473. package/es/tool/tool.js.map +0 -1
  474. package/lib/tool/snapline.d.ts +0 -3
  475. package/lib/tool/snapline.js.map +0 -1
  476. package/lib/tool/tool.d.ts +0 -22
  477. package/lib/tool/tool.js +0 -49
  478. package/lib/tool/tool.js.map +0 -1
  479. package/src/tool/tool.ts +0 -66
@@ -1,33 +1,16 @@
1
1
  import { Component } from 'preact/compat'
2
+ import { cloneDeep, assign } from 'lodash-es'
2
3
  import { observer } from '../..'
3
4
  import { createUuid } from '../../util'
4
5
  import { GraphModel } from '../../model'
5
6
  import { DEFAULT_GRID_SIZE } from '../../constant'
6
7
 
7
- export type GridOptions = {
8
- /**
9
- * 网格格子间距
10
- */
11
- size?: number
12
- /**
13
- * 网格是否可见
14
- */
15
- visible?: boolean
8
+ import GridOptions = Grid.GridOptions
16
9
 
10
+ type IProps = GridOptions & {
17
11
  graphModel: GraphModel
18
- /**
19
- * 网格类型
20
- * 'dot' || 'mesh'
21
- */
22
- type?: string
23
- config?: {
24
- color: string
25
- thickness?: number
26
- }
27
12
  }
28
13
 
29
- type IProps = GridOptions
30
-
31
14
  @observer
32
15
  export class Grid extends Component<IProps> {
33
16
  readonly id = createUuid()
@@ -38,21 +21,16 @@ export class Grid extends Component<IProps> {
38
21
 
39
22
  const { color, thickness = 2 } = config ?? {}
40
23
 
41
- const length = Math.min(Math.max(1.5, thickness), size / 2) // 2 < length < size /2
42
- let opacity = 1
43
- if (!visible) {
44
- opacity = 0
45
- }
46
- /* eslint-disable-next-line */
24
+ // 对于点状网格,点的半径不能大于网格大小的四分之一
25
+ const radius = Math.min(Math.max(2, thickness), size / 4)
26
+ const opacity = visible ? 1 : 0
47
27
  return (
48
- <rect
49
- width={length}
50
- height={length}
51
- rx={length / 2}
52
- ry={length / 2}
53
- fill={color}
54
- opacity={opacity}
55
- />
28
+ <g fill={color} opacity={opacity}>
29
+ <circle cx={0} cy={0} r={radius / 2} />
30
+ <circle cx={0} cy={size} r={radius / 2} />
31
+ <circle cx={size} cy={0} r={radius / 2} />
32
+ <circle cx={size} cy={size} r={radius / 2} />
33
+ </g>
56
34
  )
57
35
  }
58
36
 
@@ -61,22 +39,26 @@ export class Grid extends Component<IProps> {
61
39
  renderMesh() {
62
40
  const { config, size = 1, visible } = this.props
63
41
  const { color, thickness = 1 } = config ?? {}
64
- const strokeWidth = Math.min(Math.max(1, thickness), size / 2) // 1 < strokeWidth < size /2
65
- const d = `M ${size} 0 H0 M0 0 V0 ${size}`
66
- let opacity = 1
67
- if (!visible) {
68
- opacity = 0
69
- }
42
+
43
+ // 对于交叉线网格,线的宽度不能大于网格大小的一半
44
+ const strokeWidth = Math.min(Math.max(1, thickness), size / 2)
45
+ const d = `M 0 0 H ${size} V ${size} H 0 Z`
46
+ const opacity = visible ? 1 : 0
70
47
  return (
71
- <path d={d} stroke={color} strokeWidth={strokeWidth} opacity={opacity} />
48
+ <path
49
+ d={d}
50
+ stroke={color}
51
+ strokeWidth={strokeWidth}
52
+ opacity={opacity}
53
+ fill="transparent"
54
+ />
72
55
  )
73
56
  }
74
57
 
75
58
  render() {
76
- // TODO 生成网格️️️✔、网格支持 options(size)✔
77
59
  const {
78
60
  type,
79
- size,
61
+ size = 1,
80
62
  graphModel: { transformModel },
81
63
  } = this.props
82
64
  const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
@@ -122,14 +104,54 @@ export class Grid extends Component<IProps> {
122
104
  }
123
105
  }
124
106
 
125
- Grid.defaultProps = {
126
- size: DEFAULT_GRID_SIZE,
127
- visible: true,
128
- type: 'dot',
129
- config: {
130
- color: '#ababab',
131
- thickness: 1,
132
- },
133
- }
107
+ export namespace Grid {
108
+ export type GridOptions = {
109
+ /**
110
+ * 网格格子间距
111
+ */
112
+ size?: number
113
+ /**
114
+ * 网格是否可见
115
+ */
116
+ visible?: boolean
117
+ /**
118
+ * 网格类型
119
+ * - `dot` 点状网格
120
+ * - `mesh` 交叉线网格
121
+ */
122
+ type?: 'dot' | 'mesh'
123
+ config?: {
124
+ /**
125
+ * 网格的颜色
126
+ */
127
+ color: string
128
+ /**
129
+ * 网格的宽度
130
+ * - 对于 `dot` 点状网格,表示点的大小
131
+ * - 对于 `mesh` 交叉线网格,表示线的宽度
132
+ */
133
+ thickness?: number
134
+ }
135
+ }
136
+
137
+ export const defaultProps: GridOptions = {
138
+ size: DEFAULT_GRID_SIZE,
139
+ visible: true,
140
+ type: 'dot',
141
+ config: {
142
+ color: '#ababab',
143
+ thickness: 1,
144
+ },
145
+ }
134
146
 
135
- export default Grid
147
+ export function getGridOptions(options: number | boolean | GridOptions) {
148
+ const defaultOptions = cloneDeep(Grid.defaultProps)
149
+ if (typeof options === 'number') {
150
+ return assign(defaultOptions, { size: options })
151
+ } else if (typeof options === 'boolean') {
152
+ return assign(defaultOptions, { visible: options })
153
+ } else {
154
+ return assign(defaultOptions, options)
155
+ }
156
+ }
157
+ }
@@ -35,7 +35,7 @@ export class ToolOverlay extends Component<IProps> {
35
35
  h(t, {
36
36
  textEditElement,
37
37
  graphModel,
38
- logicFlow: tool.instance,
38
+ lf: tool.instance,
39
39
  }),
40
40
  )
41
41
  tool.components = components
@@ -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
@@ -1,37 +1,63 @@
1
- import { getHtmlTextHeight } from '../../util'
1
+ import { createElement as h } from 'preact/compat'
2
+ import { BaseNodeModel, BaseEdgeModel } from '../../model'
2
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'
3
23
 
4
- export function Text(props) {
24
+ export function Text(props: ITextProps): h.JSX.Element | null {
5
25
  const {
6
26
  x = 0,
7
27
  y = 0,
8
28
  value,
9
- fontSize,
29
+ fontSize = 12,
10
30
  fill = 'currentColor',
11
31
  overflowMode = 'default',
12
- textWidth = '',
32
+ // TODO: 确认该 textWidth '' 时跟设置什么值一致
33
+ textWidth = undefined,
13
34
  model,
14
35
  } = props
15
- const attrs = {
16
- textAnchor: 'middle',
17
- 'dominant-baseline': 'middle',
36
+
37
+ const attrs: Record<string, any> = {
18
38
  x,
19
39
  y,
20
40
  fill,
41
+ fontSize,
42
+ textAnchor: 'middle',
43
+ dominantBaseline: 'central',
21
44
  // ...props,
22
45
  }
23
- Object.entries(props).forEach(([k, v]) => {
24
- const valueType = typeof v
25
- if (valueType !== 'object') {
46
+
47
+ forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
48
+ if (typeof v !== 'object') {
26
49
  attrs[k] = v
27
50
  }
28
51
  })
52
+
29
53
  if (value) {
30
- // String(value),兼容纯数字的文案
54
+ // String(value),兼容纯数字的文案
55
+ // TODO: 将 value 转为纯文本,移除其中 \n \r 等特殊字符,看是否应该丰富该功能
31
56
  const rows = String(value).split(/[\r\n]/g)
32
57
  const rowsLength = rows.length
58
+
33
59
  if (overflowMode !== 'default') {
34
- // 非文本节点设置了自动换行,或边设置了自动换行并且设置了textWidth
60
+ // 非文本节点设置了自动换行,或者边设置了自动换行并且设置了 textWidth
35
61
  const { BaseType, modelType } = model
36
62
  if (
37
63
  (BaseType === ElementType.NODE && modelType !== ModelType.TEXT_NODE) ||
@@ -40,11 +66,12 @@ export function Text(props) {
40
66
  return renderHtmlText(props)
41
67
  }
42
68
  }
69
+
43
70
  if (rowsLength > 1) {
44
- const tSpans = rows.map((row, i) => {
45
- // 保证文字居中,文字Y轴偏移为当前行数对应中心行数的偏移行 * 行高
46
- const tspanLineHeight = fontSize + 2
47
- const offsetY = (i - (rowsLength - 1) / 2) * tspanLineHeight
71
+ const tSpans = rows.map((row, idx) => {
72
+ // 保证文字居中,文字 Y 轴偏移为当前行数对应中心行数的偏移行 * 行高
73
+ const tSpanLineHeight = fontSize + 2
74
+ const offsetY = (idx - (rowsLength - 1) / 2) * tSpanLineHeight
48
75
  return (
49
76
  <tspan className="lf-text-tspan" x={x} y={y + offsetY}>
50
77
  {row}
@@ -55,24 +82,26 @@ export function Text(props) {
55
82
  }
56
83
  return <text {...attrs}>{value}</text>
57
84
  }
58
-
59
85
  return null
60
86
  }
61
87
 
62
- function renderHtmlText(props) {
88
+ export function renderHtmlText(props: ITextProps): h.JSX.Element {
63
89
  const {
90
+ x,
91
+ y,
64
92
  value,
65
- fontSize,
66
93
  model,
67
- fontFamily = '',
94
+ textWidth,
95
+ fontSize = 12,
68
96
  lineHeight,
97
+ fontFamily = '',
69
98
  wrapPadding = '0, 0',
70
99
  overflowMode,
71
- x,
72
- y,
73
100
  } = props
74
- const { width, textHeight } = model
75
- const textRealWidth = props.textWidth || width
101
+
102
+ const { width, height, textHeight } = model
103
+ // TODO: 设置文本宽度为 textWidth 或 节点的宽度
104
+ const textRealWidth: number = textWidth || (width as number)
76
105
  const rows = String(value).split(/[\r\n]/g)
77
106
  const rowsLength = rows.length
78
107
  const textRealHeight = getHtmlTextHeight({
@@ -87,17 +116,20 @@ function renderHtmlText(props) {
87
116
  rowsLength,
88
117
  className: 'lf-get-text-height',
89
118
  })
119
+
90
120
  // 当文字超过边框时,取文字高度的实际值,也就是文字可以超过边框
91
- let foreignObjectHeight =
92
- model.height > textRealHeight ? model.height : textRealHeight
93
- // 如果设置了文字高度,取设置的高度
121
+ let foreignObjectHeight: number =
122
+ (height as number) > textRealHeight ? (height as number) : textRealHeight
123
+ // 如果设置了文本高度,取设置的高度
94
124
  if (textHeight) {
95
- foreignObjectHeight = textHeight
125
+ foreignObjectHeight = textHeight as number
96
126
  }
127
+
97
128
  const isEllipsis = overflowMode === 'ellipsis'
98
129
  if (isEllipsis) {
99
130
  foreignObjectHeight = fontSize + 2
100
131
  }
132
+
101
133
  return (
102
134
  <g>
103
135
  <foreignObject
@@ -105,6 +137,7 @@ function renderHtmlText(props) {
105
137
  height={foreignObjectHeight}
106
138
  x={x - textRealWidth / 2}
107
139
  y={y - foreignObjectHeight / 2}
140
+ style={{ overflow: 'visible', textAlign: 'left' }}
108
141
  >
109
142
  <div
110
143
  className="lf-node-text-auto-wrap"
@@ -121,12 +154,10 @@ function renderHtmlText(props) {
121
154
  : 'lf-node-text-auto-wrap-content'
122
155
  }
123
156
  title={isEllipsis ? rows.join('') : ''}
124
- style={{
125
- ...props,
126
- }}
157
+ style={{ ...(props as h.JSX.CSSProperties) }}
127
158
  >
128
- {rows.map((item) => (
129
- <div className="lf-node-text--auto-wrap-inner">{item}</div>
159
+ {rows.map((row) => (
160
+ <div className="lf-node-text--auto-wrap-inner">{row}</div>
130
161
  ))}
131
162
  </div>
132
163
  </div>