@antv/g6 5.0.0-beta.1 → 5.0.0-beta.11

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 (409) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +4 -1
  3. package/esm/constant/shape.js.map +1 -1
  4. package/esm/index.d.ts +22 -7
  5. package/esm/index.js +3 -2
  6. package/esm/index.js.map +1 -1
  7. package/esm/item/combo.d.ts +1 -1
  8. package/esm/item/combo.js +16 -9
  9. package/esm/item/combo.js.map +1 -1
  10. package/esm/item/edge.d.ts +20 -3
  11. package/esm/item/edge.js +99 -43
  12. package/esm/item/edge.js.map +1 -1
  13. package/esm/item/item.d.ts +3 -2
  14. package/esm/item/item.js +21 -11
  15. package/esm/item/item.js.map +1 -1
  16. package/esm/item/node.d.ts +2 -1
  17. package/esm/item/node.js +32 -16
  18. package/esm/item/node.js.map +1 -1
  19. package/esm/runtime/controller/data.d.ts +7 -10
  20. package/esm/runtime/controller/data.js +125 -281
  21. package/esm/runtime/controller/data.js.map +1 -1
  22. package/esm/runtime/controller/item.d.ts +1 -0
  23. package/esm/runtime/controller/item.js +267 -151
  24. package/esm/runtime/controller/item.js.map +1 -1
  25. package/esm/runtime/graph.d.ts +103 -23
  26. package/esm/runtime/graph.js +460 -88
  27. package/esm/runtime/graph.js.map +1 -1
  28. package/esm/stdlib/behavior/activate-relations.d.ts +9 -9
  29. package/esm/stdlib/behavior/activate-relations.js +8 -8
  30. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  31. package/esm/stdlib/behavior/brush-select.js +1 -2
  32. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  33. package/esm/stdlib/behavior/click-select.js +1 -1
  34. package/esm/stdlib/behavior/click-select.js.map +1 -1
  35. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  36. package/esm/stdlib/behavior/create-edge.js +207 -0
  37. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  38. package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
  39. package/esm/stdlib/behavior/drag-canvas.js +59 -28
  40. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  41. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  42. package/esm/stdlib/behavior/drag-combo.js +43 -32
  43. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  44. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  45. package/esm/stdlib/behavior/drag-node.js +76 -63
  46. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  47. package/esm/stdlib/behavior/index.d.ts +3 -0
  48. package/esm/stdlib/behavior/index.js +3 -0
  49. package/esm/stdlib/behavior/index.js.map +1 -1
  50. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  51. package/esm/stdlib/behavior/lasso-select.js +1 -2
  52. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  53. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  54. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  55. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  56. package/esm/stdlib/behavior/shortcuts-call.d.ts +38 -0
  57. package/esm/stdlib/behavior/shortcuts-call.js +80 -0
  58. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -0
  59. package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
  60. package/esm/stdlib/behavior/zoom-canvas.js +55 -24
  61. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  62. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  63. package/esm/stdlib/data/mapNodeSize.js +2 -2
  64. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  65. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  66. package/esm/stdlib/data/transformV4Data.js +2 -2
  67. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  68. package/esm/stdlib/data/validateData.d.ts +2 -2
  69. package/esm/stdlib/data/validateData.js +9 -9
  70. package/esm/stdlib/data/validateData.js.map +1 -1
  71. package/esm/stdlib/index.d.ts +16 -6
  72. package/esm/stdlib/index.js +20 -10
  73. package/esm/stdlib/index.js.map +1 -1
  74. package/esm/stdlib/item/edge/base.d.ts +10 -1
  75. package/esm/stdlib/item/edge/base.js +20 -13
  76. package/esm/stdlib/item/edge/base.js.map +1 -1
  77. package/esm/stdlib/item/edge/line.js +5 -2
  78. package/esm/stdlib/item/edge/line.js.map +1 -1
  79. package/esm/stdlib/item/edge/polyline.d.ts +3 -2
  80. package/esm/stdlib/item/edge/polyline.js +3 -3
  81. package/esm/stdlib/item/edge/polyline.js.map +1 -1
  82. package/esm/stdlib/item/node/base.d.ts +1 -1
  83. package/esm/stdlib/item/node/base.js +18 -26
  84. package/esm/stdlib/item/node/base.js.map +1 -1
  85. package/esm/stdlib/item/node/base3d.d.ts +1 -0
  86. package/esm/stdlib/item/node/base3d.js +1 -0
  87. package/esm/stdlib/item/node/base3d.js.map +1 -1
  88. package/esm/stdlib/item/node/diamond.js +1 -1
  89. package/esm/stdlib/item/node/ellipse.js +2 -2
  90. package/esm/stdlib/item/node/hexagon.js +12 -5
  91. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  92. package/esm/stdlib/item/node/image.d.ts +40 -0
  93. package/esm/stdlib/item/node/image.js +110 -0
  94. package/esm/stdlib/item/node/image.js.map +1 -0
  95. package/esm/stdlib/item/node/index.d.ts +1 -0
  96. package/esm/stdlib/item/node/index.js +1 -0
  97. package/esm/stdlib/item/node/index.js.map +1 -1
  98. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  99. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  100. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  101. package/esm/stdlib/plugin/history/index.js +14 -14
  102. package/esm/stdlib/plugin/history/index.js.map +1 -1
  103. package/esm/stdlib/plugin/history/item-data-command.js +25 -16
  104. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  105. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  106. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  107. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  108. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  109. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  110. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  111. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  112. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  113. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  114. package/esm/stdlib/plugin/index.d.ts +2 -0
  115. package/esm/stdlib/plugin/index.js +2 -0
  116. package/esm/stdlib/plugin/index.js.map +1 -1
  117. package/esm/stdlib/plugin/legend/index.js +1 -1
  118. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  119. package/esm/stdlib/plugin/map/index.d.ts +118 -0
  120. package/esm/stdlib/plugin/map/index.js +683 -0
  121. package/esm/stdlib/plugin/map/index.js.map +1 -0
  122. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  123. package/esm/stdlib/plugin/minimap/index.js +116 -9
  124. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  125. package/esm/stdlib/plugin/snapline/index.d.ts +167 -0
  126. package/esm/stdlib/plugin/snapline/index.js +1063 -0
  127. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  128. package/esm/stdlib/plugin/timebar/index.d.ts +98 -0
  129. package/esm/stdlib/plugin/timebar/index.js +303 -0
  130. package/esm/stdlib/plugin/timebar/index.js.map +1 -0
  131. package/esm/stdlib/plugin/toolbar/index.js +1 -1
  132. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  133. package/esm/stdlib/plugin/types.d.ts +2 -0
  134. package/esm/stdlib/theme/dark.js +42 -2
  135. package/esm/stdlib/theme/dark.js.map +1 -1
  136. package/esm/stdlib/theme/light.js +4 -4
  137. package/esm/types/common.d.ts +1 -0
  138. package/esm/types/event.d.ts +1 -0
  139. package/esm/types/graph.d.ts +48 -22
  140. package/esm/types/hook.d.ts +22 -2
  141. package/esm/types/item.d.ts +6 -0
  142. package/esm/types/item.js.map +1 -1
  143. package/esm/types/spec.d.ts +19 -3
  144. package/esm/types/view.d.ts +5 -0
  145. package/esm/util/bbox.d.ts +16 -1
  146. package/esm/util/bbox.js +29 -0
  147. package/esm/util/bbox.js.map +1 -1
  148. package/esm/util/canvas.d.ts +2 -2
  149. package/esm/util/canvas.js +5 -11
  150. package/esm/util/canvas.js.map +1 -1
  151. package/esm/util/event.d.ts +3 -1
  152. package/esm/util/event.js +8 -1
  153. package/esm/util/event.js.map +1 -1
  154. package/esm/util/item.d.ts +16 -1
  155. package/esm/util/item.js +31 -8
  156. package/esm/util/item.js.map +1 -1
  157. package/esm/util/layout.d.ts +11 -0
  158. package/esm/util/layout.js +45 -0
  159. package/esm/util/layout.js.map +1 -1
  160. package/esm/util/point.js +9 -2
  161. package/esm/util/point.js.map +1 -1
  162. package/esm/util/router.d.ts +4 -3
  163. package/esm/util/router.js +8 -5
  164. package/esm/util/router.js.map +1 -1
  165. package/esm/util/shape.d.ts +3 -3
  166. package/esm/util/shape.js +8 -12
  167. package/esm/util/shape.js.map +1 -1
  168. package/esm/util/warn.d.ts +14 -0
  169. package/esm/util/warn.js +4 -0
  170. package/esm/util/warn.js.map +1 -0
  171. package/lib/constant/shape.d.ts +4 -1
  172. package/lib/constant/shape.js.map +1 -1
  173. package/lib/index.d.ts +22 -7
  174. package/lib/index.js +4 -2
  175. package/lib/index.js.map +1 -1
  176. package/lib/item/combo.d.ts +1 -1
  177. package/lib/item/combo.js +16 -9
  178. package/lib/item/combo.js.map +1 -1
  179. package/lib/item/edge.d.ts +20 -3
  180. package/lib/item/edge.js +98 -42
  181. package/lib/item/edge.js.map +1 -1
  182. package/lib/item/item.d.ts +3 -2
  183. package/lib/item/item.js +21 -11
  184. package/lib/item/item.js.map +1 -1
  185. package/lib/item/node.d.ts +2 -1
  186. package/lib/item/node.js +32 -16
  187. package/lib/item/node.js.map +1 -1
  188. package/lib/runtime/controller/data.d.ts +7 -10
  189. package/lib/runtime/controller/data.js +125 -281
  190. package/lib/runtime/controller/data.js.map +1 -1
  191. package/lib/runtime/controller/item.d.ts +1 -0
  192. package/lib/runtime/controller/item.js +266 -150
  193. package/lib/runtime/controller/item.js.map +1 -1
  194. package/lib/runtime/graph.d.ts +103 -23
  195. package/lib/runtime/graph.js +460 -88
  196. package/lib/runtime/graph.js.map +1 -1
  197. package/lib/stdlib/behavior/activate-relations.d.ts +9 -9
  198. package/lib/stdlib/behavior/activate-relations.js +8 -8
  199. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  200. package/lib/stdlib/behavior/brush-select.js +1 -2
  201. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  202. package/lib/stdlib/behavior/click-select.js +1 -1
  203. package/lib/stdlib/behavior/click-select.js.map +1 -1
  204. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  205. package/lib/stdlib/behavior/create-edge.js +211 -0
  206. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  207. package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
  208. package/lib/stdlib/behavior/drag-canvas.js +59 -28
  209. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  210. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  211. package/lib/stdlib/behavior/drag-combo.js +43 -32
  212. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  213. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  214. package/lib/stdlib/behavior/drag-node.js +76 -63
  215. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  216. package/lib/stdlib/behavior/index.d.ts +3 -0
  217. package/lib/stdlib/behavior/index.js +3 -0
  218. package/lib/stdlib/behavior/index.js.map +1 -1
  219. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  220. package/lib/stdlib/behavior/lasso-select.js +1 -2
  221. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  222. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  223. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  224. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  225. package/lib/stdlib/behavior/shortcuts-call.d.ts +38 -0
  226. package/lib/stdlib/behavior/shortcuts-call.js +84 -0
  227. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -0
  228. package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
  229. package/lib/stdlib/behavior/zoom-canvas.js +55 -24
  230. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  231. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  232. package/lib/stdlib/data/mapNodeSize.js +2 -2
  233. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  234. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  235. package/lib/stdlib/data/transformV4Data.js +2 -2
  236. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  237. package/lib/stdlib/data/validateData.d.ts +2 -2
  238. package/lib/stdlib/data/validateData.js +9 -9
  239. package/lib/stdlib/data/validateData.js.map +1 -1
  240. package/lib/stdlib/index.d.ts +16 -6
  241. package/lib/stdlib/index.js +20 -10
  242. package/lib/stdlib/index.js.map +1 -1
  243. package/lib/stdlib/item/edge/base.d.ts +10 -1
  244. package/lib/stdlib/item/edge/base.js +20 -13
  245. package/lib/stdlib/item/edge/base.js.map +1 -1
  246. package/lib/stdlib/item/edge/line.js +5 -2
  247. package/lib/stdlib/item/edge/line.js.map +1 -1
  248. package/lib/stdlib/item/edge/polyline.d.ts +3 -2
  249. package/lib/stdlib/item/edge/polyline.js +3 -3
  250. package/lib/stdlib/item/edge/polyline.js.map +1 -1
  251. package/lib/stdlib/item/node/base.d.ts +1 -1
  252. package/lib/stdlib/item/node/base.js +18 -26
  253. package/lib/stdlib/item/node/base.js.map +1 -1
  254. package/lib/stdlib/item/node/base3d.d.ts +1 -0
  255. package/lib/stdlib/item/node/base3d.js +1 -0
  256. package/lib/stdlib/item/node/base3d.js.map +1 -1
  257. package/lib/stdlib/item/node/diamond.js +1 -1
  258. package/lib/stdlib/item/node/ellipse.js +2 -2
  259. package/lib/stdlib/item/node/hexagon.js +12 -5
  260. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  261. package/lib/stdlib/item/node/image.d.ts +40 -0
  262. package/lib/stdlib/item/node/image.js +114 -0
  263. package/lib/stdlib/item/node/image.js.map +1 -0
  264. package/lib/stdlib/item/node/index.d.ts +1 -0
  265. package/lib/stdlib/item/node/index.js +1 -0
  266. package/lib/stdlib/item/node/index.js.map +1 -1
  267. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  268. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  269. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  270. package/lib/stdlib/plugin/history/index.js +14 -14
  271. package/lib/stdlib/plugin/history/index.js.map +1 -1
  272. package/lib/stdlib/plugin/history/item-data-command.js +25 -16
  273. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  274. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  275. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  276. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  277. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  278. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  279. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  280. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  281. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  282. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  283. package/lib/stdlib/plugin/index.d.ts +2 -0
  284. package/lib/stdlib/plugin/index.js +2 -0
  285. package/lib/stdlib/plugin/index.js.map +1 -1
  286. package/lib/stdlib/plugin/legend/index.js +1 -1
  287. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  288. package/lib/stdlib/plugin/map/index.d.ts +118 -0
  289. package/lib/stdlib/plugin/map/index.js +687 -0
  290. package/lib/stdlib/plugin/map/index.js.map +1 -0
  291. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  292. package/lib/stdlib/plugin/minimap/index.js +116 -9
  293. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  294. package/lib/stdlib/plugin/snapline/index.d.ts +167 -0
  295. package/lib/stdlib/plugin/snapline/index.js +1067 -0
  296. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  297. package/lib/stdlib/plugin/timebar/index.d.ts +98 -0
  298. package/lib/stdlib/plugin/timebar/index.js +307 -0
  299. package/lib/stdlib/plugin/timebar/index.js.map +1 -0
  300. package/lib/stdlib/plugin/toolbar/index.js +1 -1
  301. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  302. package/lib/stdlib/plugin/types.d.ts +2 -0
  303. package/lib/stdlib/theme/dark.js +42 -2
  304. package/lib/stdlib/theme/dark.js.map +1 -1
  305. package/lib/stdlib/theme/light.js +4 -4
  306. package/lib/types/common.d.ts +1 -0
  307. package/lib/types/event.d.ts +1 -0
  308. package/lib/types/graph.d.ts +48 -22
  309. package/lib/types/hook.d.ts +22 -2
  310. package/lib/types/item.d.ts +6 -0
  311. package/lib/types/item.js.map +1 -1
  312. package/lib/types/spec.d.ts +19 -3
  313. package/lib/types/view.d.ts +5 -0
  314. package/lib/util/bbox.d.ts +16 -1
  315. package/lib/util/bbox.js +32 -1
  316. package/lib/util/bbox.js.map +1 -1
  317. package/lib/util/canvas.d.ts +2 -2
  318. package/lib/util/canvas.js +5 -11
  319. package/lib/util/canvas.js.map +1 -1
  320. package/lib/util/event.d.ts +3 -1
  321. package/lib/util/event.js +8 -1
  322. package/lib/util/event.js.map +1 -1
  323. package/lib/util/item.d.ts +16 -1
  324. package/lib/util/item.js +33 -9
  325. package/lib/util/item.js.map +1 -1
  326. package/lib/util/layout.d.ts +11 -0
  327. package/lib/util/layout.js +47 -1
  328. package/lib/util/layout.js.map +1 -1
  329. package/lib/util/point.js +9 -2
  330. package/lib/util/point.js.map +1 -1
  331. package/lib/util/router.d.ts +4 -3
  332. package/lib/util/router.js +8 -5
  333. package/lib/util/router.js.map +1 -1
  334. package/lib/util/shape.d.ts +3 -3
  335. package/lib/util/shape.js +8 -12
  336. package/lib/util/shape.js.map +1 -1
  337. package/lib/util/warn.d.ts +14 -0
  338. package/lib/util/warn.js +8 -0
  339. package/lib/util/warn.js.map +1 -0
  340. package/package.json +10 -10
  341. package/src/constant/shape.ts +2 -1
  342. package/src/index.ts +4 -2
  343. package/src/item/combo.ts +14 -9
  344. package/src/item/edge.ts +131 -57
  345. package/src/item/item.ts +24 -15
  346. package/src/item/node.ts +37 -24
  347. package/src/runtime/controller/data.ts +140 -339
  348. package/src/runtime/controller/item.ts +236 -72
  349. package/src/runtime/graph.ts +592 -96
  350. package/src/stdlib/behavior/activate-relations.ts +8 -8
  351. package/src/stdlib/behavior/brush-select.ts +4 -2
  352. package/src/stdlib/behavior/click-select.ts +1 -1
  353. package/src/stdlib/behavior/create-edge.ts +296 -0
  354. package/src/stdlib/behavior/drag-canvas.ts +78 -29
  355. package/src/stdlib/behavior/drag-combo.ts +10 -10
  356. package/src/stdlib/behavior/drag-node.ts +18 -18
  357. package/src/stdlib/behavior/index.ts +3 -0
  358. package/src/stdlib/behavior/lasso-select.ts +5 -3
  359. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  360. package/src/stdlib/behavior/shortcuts-call.ts +120 -0
  361. package/src/stdlib/behavior/zoom-canvas.ts +72 -25
  362. package/src/stdlib/data/mapNodeSize.ts +2 -2
  363. package/src/stdlib/data/transformV4Data.ts +2 -2
  364. package/src/stdlib/data/validateData.ts +9 -9
  365. package/src/stdlib/index.ts +33 -9
  366. package/src/stdlib/item/edge/base.ts +26 -13
  367. package/src/stdlib/item/edge/line.ts +8 -2
  368. package/src/stdlib/item/edge/polyline.ts +7 -5
  369. package/src/stdlib/item/node/base.ts +24 -29
  370. package/src/stdlib/item/node/base3d.ts +1 -0
  371. package/src/stdlib/item/node/diamond.ts +1 -1
  372. package/src/stdlib/item/node/ellipse.ts +2 -2
  373. package/src/stdlib/item/node/hexagon.ts +14 -6
  374. package/src/stdlib/item/node/image.ts +190 -0
  375. package/src/stdlib/item/node/index.ts +1 -0
  376. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  377. package/src/stdlib/plugin/history/index.ts +14 -14
  378. package/src/stdlib/plugin/history/item-data-command.ts +35 -17
  379. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  380. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  381. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  382. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  383. package/src/stdlib/plugin/index.ts +2 -0
  384. package/src/stdlib/plugin/legend/index.ts +1 -1
  385. package/src/stdlib/plugin/map/index.ts +808 -0
  386. package/src/stdlib/plugin/minimap/index.ts +120 -10
  387. package/src/stdlib/plugin/snapline/index.ts +1297 -0
  388. package/src/stdlib/plugin/timebar/index.ts +473 -0
  389. package/src/stdlib/plugin/toolbar/index.ts +1 -1
  390. package/src/stdlib/plugin/types.ts +2 -0
  391. package/src/stdlib/theme/dark.ts +66 -2
  392. package/src/stdlib/theme/light.ts +4 -4
  393. package/src/types/common.ts +1 -0
  394. package/src/types/event.ts +1 -0
  395. package/src/types/graph.ts +59 -25
  396. package/src/types/hook.ts +22 -2
  397. package/src/types/item.ts +10 -0
  398. package/src/types/spec.ts +22 -3
  399. package/src/types/view.ts +8 -3
  400. package/src/util/bbox.ts +38 -1
  401. package/src/util/canvas.ts +5 -5
  402. package/src/util/event.ts +14 -1
  403. package/src/util/item.ts +65 -28
  404. package/src/util/layout.ts +45 -0
  405. package/src/util/point.ts +8 -3
  406. package/src/util/router.ts +15 -6
  407. package/src/util/shape.ts +16 -14
  408. package/src/util/warn.ts +20 -0
  409. package/src/api-doc/readme.md +0 -59
@@ -258,7 +258,7 @@ export class DragNode extends Behavior {
258
258
  this.selectedNodeIds,
259
259
  this.hiddenComboTreeItems,
260
260
  );
261
- this.graph.executeWithoutStacking(() => {
261
+ this.graph.executeWithNoStack(() => {
262
262
  this.graph.hideItem(
263
263
  this.hiddenEdges.map((edge) => edge.id),
264
264
  true,
@@ -292,7 +292,7 @@ export class DragNode extends Behavior {
292
292
  });
293
293
 
294
294
  // Hide original edges and nodes. They will be restored when pointerup.
295
- this.graph.executeWithoutStacking(() => {
295
+ this.graph.executeWithNoStack(() => {
296
296
  this.graph.hideItem(this.selectedNodeIds, true);
297
297
  this.graph.hideItem(
298
298
  this.hiddenEdges.map((edge) => edge.id),
@@ -457,7 +457,7 @@ export class DragNode extends Behavior {
457
457
  this.graph.drawTransient('rect', DELEGATE_SHAPE_ID, { action: 'remove' });
458
458
  }
459
459
 
460
- public clearTransientItems() {
460
+ public clearTransientItems(positions: Array<Position>) {
461
461
  this.hiddenEdges.forEach((edge) => {
462
462
  this.graph.drawTransient('node', edge.source, { action: 'remove' });
463
463
  this.graph.drawTransient('node', edge.target, { action: 'remove' });
@@ -472,13 +472,13 @@ export class DragNode extends Behavior {
472
472
  action: 'remove',
473
473
  });
474
474
  });
475
- this.originPositions.forEach(({ id }) => {
475
+ positions.forEach(({ id }) => {
476
476
  this.graph.drawTransient('node', id, { action: 'remove' });
477
477
  });
478
478
  }
479
479
 
480
480
  public restoreHiddenItems(positions?: Position[]) {
481
- this.graph.pauseStacking();
481
+ this.graph.pauseStack();
482
482
  if (this.hiddenEdges.length) {
483
483
  this.graph.showItem(
484
484
  this.hiddenEdges.map((edge) => edge.id),
@@ -508,7 +508,7 @@ export class DragNode extends Behavior {
508
508
  true,
509
509
  );
510
510
  }
511
- this.graph.resumeStacking();
511
+ this.graph.resumeStack();
512
512
  }
513
513
 
514
514
  public clearState() {
@@ -543,7 +543,7 @@ export class DragNode extends Behavior {
543
543
  debounce((positions) => {
544
544
  // restore the hidden items after move real nodes done
545
545
  if (enableTransient) {
546
- this.clearTransientItems();
546
+ this.clearTransientItems(positions);
547
547
  }
548
548
 
549
549
  if (this.options.enableDelegate) {
@@ -573,7 +573,7 @@ export class DragNode extends Behavior {
573
573
  return;
574
574
  }
575
575
  this.clearDelegate();
576
- this.clearTransientItems();
576
+ this.clearTransientItems(this.originPositions);
577
577
  this.restoreHiddenItems();
578
578
 
579
579
  const enableTransient =
@@ -589,8 +589,8 @@ export class DragNode extends Behavior {
589
589
  this.clearState();
590
590
  }
591
591
 
592
- public onDropNode(event: IG6GraphEvent) {
593
- const elements = this.graph.canvas.document.elementsFromPointSync(
592
+ public async onDropNode(event: IG6GraphEvent) {
593
+ const elements = await this.graph.canvas.document.elementsFromPoint(
594
594
  event.canvas.x,
595
595
  event.canvas.y,
596
596
  );
@@ -608,7 +608,7 @@ export class DragNode extends Behavior {
608
608
  ? this.graph.getNodeData(dropId).data.parentId
609
609
  : dropId;
610
610
 
611
- this.graph.startBatch();
611
+ this.graph.startHistoryBatch();
612
612
  this.originPositions.forEach(({ id }) => {
613
613
  const model = this.graph.getNodeData(id);
614
614
  if (!model) return;
@@ -621,13 +621,13 @@ export class DragNode extends Behavior {
621
621
  this.graph.updateData('node', { id, data: { parentId: newParentId } });
622
622
  });
623
623
  this.onPointerUp(event);
624
- this.graph.stopBatch();
624
+ this.graph.stopHistoryBatch();
625
625
  }
626
626
 
627
627
  public onDropCombo(event: IG6GraphEvent) {
628
628
  event.stopPropagation();
629
629
  const newParentId = event.itemId;
630
- this.graph.startBatch();
630
+ this.graph.startHistoryBatch();
631
631
  this.onPointerUp(event);
632
632
  this.originPositions.forEach(({ id }) => {
633
633
  const model = this.graph.getNodeData(id);
@@ -637,11 +637,11 @@ export class DragNode extends Behavior {
637
637
  this.graph.updateData('node', { id, data: { parentId: newParentId } });
638
638
  });
639
639
  this.clearState();
640
- this.graph.stopBatch();
640
+ this.graph.stopHistoryBatch();
641
641
  }
642
642
 
643
- public onDropCanvas(event: IG6GraphEvent) {
644
- const elements = this.graph.canvas.document.elementsFromPointSync(
643
+ public async onDropCanvas(event: IG6GraphEvent) {
644
+ const elements = await this.graph.canvas.document.elementsFromPoint(
645
645
  event.canvas.x,
646
646
  event.canvas.y,
647
647
  );
@@ -657,7 +657,7 @@ export class DragNode extends Behavior {
657
657
  const parentId = this.graph.getNodeData(dropId)
658
658
  ? this.graph.getNodeData(dropId).data.parentId
659
659
  : dropId;
660
- this.graph.startBatch();
660
+ this.graph.startHistoryBatch();
661
661
  this.onPointerUp(event);
662
662
  const nodeToUpdate = [];
663
663
  this.originPositions.forEach(({ id }) => {
@@ -671,6 +671,6 @@ export class DragNode extends Behavior {
671
671
  });
672
672
  if (nodeToUpdate.length) this.graph.updateData('node', nodeToUpdate);
673
673
  this.clearState();
674
- this.graph.stopBatch();
674
+ this.graph.stopHistoryBatch();
675
675
  }
676
676
  }
@@ -13,3 +13,6 @@ export * from './orbit-canvas-3d';
13
13
  export * from './rotate-canvas-3d';
14
14
  export * from './track-canvas-3d';
15
15
  export * from './zoom-canvas-3d';
16
+ export * from './create-edge';
17
+ export * from './shortcuts-call';
18
+ export * from './scroll-canvas';
@@ -61,8 +61,10 @@ export class LassoSelect extends BrushSelect {
61
61
  const { graph, options } = this;
62
62
  const { brushStyle } = options;
63
63
  return graph.drawTransient('path', LASSO_SHAPE_ID, {
64
- style: brushStyle,
65
- capture: false,
64
+ style: {
65
+ pointerEvents: 'none',
66
+ ...brushStyle,
67
+ },
66
68
  });
67
69
  }
68
70
 
@@ -82,7 +84,7 @@ export class LassoSelect extends BrushSelect {
82
84
 
83
85
  getLassoPath = () => {
84
86
  const points: Point[] = this.points;
85
- const path = [];
87
+ const path: any = [];
86
88
  if (points.length) {
87
89
  points.forEach((point, index) => {
88
90
  if (index === 0) {
@@ -0,0 +1,348 @@
1
+ import { isBoolean, isNumber, isObject } from '@antv/util';
2
+ import { Behavior } from '../../types/behavior';
3
+ import { ID, IG6GraphEvent } from '../../types';
4
+
5
+ interface ScrollCanvasOptions {
6
+ /**
7
+ * The direction of dragging that is allowed. Options: 'x', 'y', 'both'. 'both' by default.
8
+ */
9
+ direction?: string;
10
+ /**
11
+ * Whether enable optimize strategies, which will hide all the shapes excluding node keyShape while scrolling.
12
+ */
13
+ enableOptimize?: boolean;
14
+ /**
15
+ * When the zoom ratio of the graph is smaller than ```optimizeZoom```, all shapes except for node keyShape will always be hidden.
16
+ * This option requires ```enableOptimize=true```;
17
+ */
18
+ optimizeZoom?: number;
19
+ /**
20
+ * Switch to zooming while pressing the key and wheeling. Options: 'shift', 'ctrl', 'alt', 'control', 'meta', using an array of these options allows any of these keys to trigger zooming;
21
+ * Use ```'ctrl'``` by default;
22
+ */
23
+ zoomKey?: string | string[];
24
+ /** Switch to zooming while pressing the key and wheeling. This option allows you to control the zoom ratio for each event.
25
+ * Use ```'0.05'``` by default;
26
+ */
27
+ zoomRatio?: number;
28
+ /**
29
+ * The range of canvas to limit dragging, 0 by default, which means the graph cannot be dragged totally out of the view port range.
30
+ * If scalableRange is number or a string without 'px', means it is a ratio of the graph content.
31
+ * If scalableRange is a string with 'px', it is regarded as pixels.
32
+ * If scalableRange = 0, no constrains;
33
+ * If scalableRange > 0, the graph can be dragged out of the view port range
34
+ * If scalableRange < 0, the range is smaller than the view port.
35
+ * Refer to https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*IFfoS67_HssAAAAAAAAAAAAAARQnAQ
36
+ */
37
+ scalableRange?: string | number;
38
+ /**
39
+ * Whether allow trigger this behavior when drag start on nodes / edges / combos.
40
+ */
41
+ allowDragOnItem?:
42
+ | boolean
43
+ | {
44
+ node?: boolean;
45
+ edge?: boolean;
46
+ combo?: boolean;
47
+ };
48
+ }
49
+
50
+ const DEFAULT_OPTIONS: ScrollCanvasOptions = {
51
+ direction: 'both',
52
+ enableOptimize: false,
53
+ zoomKey: 'ctrl',
54
+ scalableRange: 0,
55
+ allowDragOnItem: true,
56
+ zoomRatio: 0.05,
57
+ };
58
+
59
+ export class ScrollCanvas extends Behavior {
60
+ private hiddenEdgeIds: ID[];
61
+ private hiddenNodeIds: ID[];
62
+
63
+ declare options: ScrollCanvasOptions;
64
+ timeout?: number;
65
+ optimized = false;
66
+ constructor(options: Partial<ScrollCanvasOptions>) {
67
+ const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options, {
68
+ zoomKey: initZoomKey(options.zoomKey),
69
+ });
70
+ super(finalOptions);
71
+ }
72
+
73
+ getEvents = () => {
74
+ return {
75
+ wheel: this.onWheel,
76
+ };
77
+ };
78
+
79
+ onWheel(ev: IG6GraphEvent & { deltaX?: number; deltaY?: number }) {
80
+ if (!this.allowDrag(ev)) return;
81
+ const graph = this.graph;
82
+ const { zoomKey, zoomRatio, enableOptimize } = this.options;
83
+ const zoomKeys = Array.isArray(zoomKey) ? [].concat(zoomKey) : [zoomKey];
84
+ if (zoomKeys.includes('control')) zoomKeys.push('ctrl');
85
+ const keyDown = zoomKeys.some((ele) => ev[`${ele}Key`]);
86
+
87
+ const nativeEvent = ev.nativeEvent as
88
+ | (WheelEvent & { wheelDelta: number })
89
+ | undefined;
90
+
91
+ if (keyDown) {
92
+ const canvas = graph.canvas;
93
+ const point = canvas.client2Viewport({ x: ev.client.x, y: ev.client.y });
94
+ let ratio = graph.getZoom();
95
+ if (nativeEvent && nativeEvent.wheelDelta > 0) {
96
+ ratio = ratio + ratio * zoomRatio;
97
+ } else {
98
+ ratio = ratio - ratio * zoomRatio;
99
+ }
100
+ graph.zoomTo(ratio, {
101
+ x: point.x,
102
+ y: point.y,
103
+ });
104
+ } else {
105
+ const diffX = ev.deltaX || ev.movement.x;
106
+ const diffY = ev.deltaY || ev.movement.y;
107
+
108
+ const { dx, dy } = this.formatDisplacement(diffX, diffY);
109
+ graph.translate({ dx: -dx, dy: -dy });
110
+ }
111
+
112
+ if (enableOptimize) {
113
+ const optimized = this.optimized;
114
+
115
+ // hiding
116
+ if (!optimized) {
117
+ this.hideShapes();
118
+ this.optimized = true;
119
+ }
120
+
121
+ // showing after 100ms
122
+ clearTimeout(this.timeout);
123
+ this.timeout = undefined;
124
+ const timeout = window.setTimeout(() => {
125
+ this.showShapes();
126
+ this.optimized = false;
127
+ }, 100);
128
+ this.timeout = timeout;
129
+ }
130
+ }
131
+ private formatDisplacement(dx: number, dy: number) {
132
+ const { graph } = this;
133
+ const { scalableRange, direction } = this.options;
134
+ const [width, height] = graph.getSize();
135
+ const graphBBox = graph.canvas.getRoot().getRenderBounds();
136
+ let rangeNum = Number(scalableRange);
137
+ let isPixel;
138
+ if (typeof scalableRange === 'string') {
139
+ if (scalableRange.includes('px')) {
140
+ isPixel = scalableRange.includes('px');
141
+ rangeNum = Number(scalableRange.replace('px', ''));
142
+ }
143
+ if (scalableRange.includes('%')) {
144
+ rangeNum = Number(scalableRange.replace('%', '')) / 100;
145
+ }
146
+ }
147
+
148
+ let expandWidth = rangeNum;
149
+ let expandHeight = rangeNum;
150
+ // If it is not a string with 'px', regard as ratio
151
+ if (!isPixel) {
152
+ expandWidth = width * rangeNum;
153
+ expandHeight = height * rangeNum;
154
+ }
155
+ const leftTopClient = graph.getViewportByCanvas({
156
+ x: graphBBox.min[0],
157
+ y: graphBBox.min[1],
158
+ });
159
+ const rightBottomClient = graph.getViewportByCanvas({
160
+ x: graphBBox.max[0],
161
+ y: graphBBox.max[1],
162
+ });
163
+ const minX = leftTopClient.x;
164
+ const minY = leftTopClient.y;
165
+ const maxX = rightBottomClient.x;
166
+ const maxY = rightBottomClient.y;
167
+ if (dx > 0) {
168
+ if (maxX < -expandWidth) {
169
+ dx = 0;
170
+ } else if (maxX - dx < -expandWidth) {
171
+ dx = maxX + expandWidth;
172
+ }
173
+ } else if (dx < 0) {
174
+ if (minX > width + expandWidth) {
175
+ dx = 0;
176
+ } else if (minX - dx > width + expandWidth) {
177
+ dx = minX - (width + expandWidth);
178
+ }
179
+ }
180
+
181
+ if (dy > 0) {
182
+ if (maxY < -expandHeight) {
183
+ dy = 0;
184
+ } else if (maxY - dy < -expandHeight) {
185
+ dy = maxY + expandHeight;
186
+ }
187
+ } else if (dy < 0) {
188
+ if (minY > height + expandHeight) {
189
+ dy = 0;
190
+ } else if (minY - dy > height + expandHeight) {
191
+ dy = minY - (height + expandHeight);
192
+ }
193
+ }
194
+
195
+ if (direction === 'x') {
196
+ dy = 0;
197
+ } else if (direction === 'y') {
198
+ dx = 0;
199
+ }
200
+
201
+ return { dx, dy };
202
+ }
203
+
204
+ private allowDrag(evt: IG6GraphEvent) {
205
+ const { itemType } = evt;
206
+ const { allowDragOnItem } = this.options;
207
+ const targetIsCanvas = itemType === 'canvas';
208
+ if (isBoolean(allowDragOnItem) && !allowDragOnItem && !targetIsCanvas)
209
+ return false;
210
+ if (isObject(allowDragOnItem)) {
211
+ const { node, edge, combo } = allowDragOnItem;
212
+ if (!node && itemType === 'node') return false;
213
+ if (!edge && itemType === 'edge') return false;
214
+ if (!combo && itemType === 'combo') return false;
215
+ }
216
+ return true;
217
+ }
218
+
219
+ private hideShapes() {
220
+ const { graph, options } = this;
221
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
222
+ graph.getSpecification().optimize || {};
223
+ const { optimizeZoom } = options;
224
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
225
+ const shouldOptimzie = isNumber(optimize)
226
+ ? graph.getAllNodesData().length > optimize
227
+ : optimize;
228
+ if (shouldOptimzie) {
229
+ const currentZoom = graph.getZoom();
230
+ const newHiddenEdgeIds = graph
231
+ .getAllEdgesData()
232
+ .map((edge) => edge.id)
233
+ .filter((id) => graph.getItemVisible(id));
234
+ graph.hideItem(newHiddenEdgeIds, true);
235
+
236
+ if (currentZoom < optimizeZoom) {
237
+ this.hiddenEdgeIds.push(...newHiddenEdgeIds);
238
+ } else {
239
+ this.hiddenEdgeIds = newHiddenEdgeIds;
240
+ }
241
+
242
+ const newHiddenNodeIds = graph
243
+ .getAllNodesData()
244
+ .map((node) => node.id)
245
+ .filter((id) => graph.getItemVisible(id));
246
+
247
+ let requestId;
248
+ const sectionNum = Math.ceil(newHiddenNodeIds.length / tileBehaviorSize);
249
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
250
+ newHiddenNodeIds.slice(
251
+ i * tileBehaviorSize,
252
+ i * tileBehaviorSize + tileBehaviorSize,
253
+ ),
254
+ );
255
+ const update = () => {
256
+ if (!sections.length) {
257
+ cancelAnimationFrame(requestId);
258
+ return;
259
+ }
260
+ const section = sections.shift();
261
+ graph.startHistoryBatch();
262
+ graph.hideItem(section, false, true);
263
+ graph.stopHistoryBatch();
264
+ requestId = requestAnimationFrame(update);
265
+ };
266
+ requestId = requestAnimationFrame(update);
267
+
268
+ if (currentZoom < optimizeZoom) {
269
+ this.hiddenNodeIds.push(...newHiddenNodeIds);
270
+ } else {
271
+ this.hiddenNodeIds = newHiddenNodeIds;
272
+ }
273
+ }
274
+ }
275
+ private showShapes() {
276
+ const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
277
+ const currentZoom = graph.getZoom();
278
+ const { optimizeZoom } = this.options;
279
+
280
+ // hide the shapes when the zoom ratio is smaller than optimizeZoom
281
+ // hide the shapes when zoomming
282
+ if (currentZoom < optimizeZoom) {
283
+ return;
284
+ }
285
+
286
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
287
+ graph.getSpecification().optimize || {};
288
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
289
+ const shouldOptimzie = isNumber(optimize)
290
+ ? graph.getAllNodesData().length > optimize
291
+ : optimize;
292
+ if (!shouldOptimzie) {
293
+ this.hiddenEdgeIds = this.hiddenNodeIds = [];
294
+ return;
295
+ }
296
+
297
+ let requestId;
298
+ const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
299
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
300
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
301
+ hiddenIds.slice(
302
+ i * tileBehaviorSize,
303
+ i * tileBehaviorSize + tileBehaviorSize,
304
+ ),
305
+ );
306
+ const update = () => {
307
+ if (!sections.length) {
308
+ cancelAnimationFrame(requestId);
309
+ return;
310
+ }
311
+ graph.executeWithNoStack(() => {
312
+ graph.showItem(sections.shift(), false);
313
+ });
314
+ requestId = requestAnimationFrame(update);
315
+ };
316
+ requestId = requestAnimationFrame(update);
317
+
318
+ this.hiddenEdgeIds = this.hiddenNodeIds = [];
319
+ }
320
+ }
321
+
322
+ const ALLOW_EVENTS = ['shift', 'ctrl', 'alt', 'control', 'meta'];
323
+
324
+ function initZoomKey(zoomKey?: string | string[]) {
325
+ const zoomKeys = zoomKey
326
+ ? Array.isArray(zoomKey)
327
+ ? zoomKey
328
+ : [zoomKey]
329
+ : [];
330
+
331
+ const validZoomKeys = zoomKeys.filter((zoomKey) => {
332
+ const keyIsValid = ALLOW_EVENTS.includes(zoomKey);
333
+ if (!keyIsValid)
334
+ console.warn(
335
+ `Invalid zoomKey: ${zoomKey}, please use a valid zoomKey: ${JSON.stringify(
336
+ ALLOW_EVENTS,
337
+ )}`,
338
+ );
339
+
340
+ return keyIsValid;
341
+ });
342
+
343
+ if (validZoomKeys.length === 0) {
344
+ validZoomKeys.push('ctrl');
345
+ }
346
+
347
+ return validZoomKeys;
348
+ }
@@ -0,0 +1,120 @@
1
+ import type { IG6GraphEvent } from '../../types';
2
+ import { Behavior } from '../../types/behavior';
3
+
4
+ const DEFAULT_TRIGGER = 'ctrl';
5
+ const ALLOW_TRIGGERS = ['shift', 'ctrl', 'alt', 'control'] as const;
6
+ const DEFAULT_COMBINED_KEY = '1';
7
+ type Trigger = (typeof ALLOW_TRIGGERS)[number];
8
+
9
+ interface ShortcutsCallOptions {
10
+ /**
11
+ * The main key to pressed to apply shortcuts call
12
+ * Defaults to `"ctrl"`.
13
+ */
14
+ trigger?: Trigger;
15
+ /**
16
+ * The combined key to pressed with trigger to apply shortcuts call.
17
+ * Defaults to `"1"`.
18
+ */
19
+ combinedKey?: string;
20
+ /**
21
+ *
22
+ * The function to be called.
23
+ * Defaults to `"fitView"`.
24
+ *
25
+ */
26
+ functionName?: string;
27
+ /**
28
+ * The function params.
29
+ */
30
+ functionParams?: any[];
31
+ }
32
+
33
+ const DEFAULT_OPTIONS: ShortcutsCallOptions = {
34
+ trigger: DEFAULT_TRIGGER,
35
+ combinedKey: DEFAULT_COMBINED_KEY,
36
+ functionName: 'fitView',
37
+ functionParams: [],
38
+ };
39
+
40
+ export class ShortcutsCall extends Behavior {
41
+ triggerKeydown = false;
42
+
43
+ constructor(options: Partial<ShortcutsCallOptions>) {
44
+ super(Object.assign({}, DEFAULT_OPTIONS, options));
45
+ // Validate options
46
+ if (options.trigger && !ALLOW_TRIGGERS.includes(options.trigger)) {
47
+ console.warn(
48
+ `G6: Invalid trigger option "${options.trigger}" for shortcuts-call behavior!`,
49
+ );
50
+ this.options.trigger = DEFAULT_OPTIONS.trigger;
51
+ }
52
+ if (options.combinedKey === this.options.trigger) {
53
+ this.options.combinedKey = undefined;
54
+ }
55
+ }
56
+
57
+ getEvents = () => {
58
+ return {
59
+ keyup: this.onKeyUp,
60
+ keydown: this.onKeyDown,
61
+ };
62
+ };
63
+
64
+ public onKeyDown(e: IG6GraphEvent) {
65
+ const code = e.key;
66
+ if (!code) return;
67
+
68
+ const { graph } = this;
69
+ const { trigger, combinedKey, functionName, functionParams } = this.options;
70
+
71
+ const triggerLowerCase = trigger.toLowerCase();
72
+ const codeLowerCase = code.toLowerCase();
73
+ // While holding down the Control key, allow users to set the trigger as "ctrl".
74
+ if (!this.triggerKeydown) {
75
+ if (
76
+ codeLowerCase === triggerLowerCase ||
77
+ (codeLowerCase === 'control' && triggerLowerCase === 'ctrl') ||
78
+ (codeLowerCase === 'ctrl' && triggerLowerCase === 'control')
79
+ ) {
80
+ this.triggerKeydown = true;
81
+ } else {
82
+ this.triggerKeydown = false;
83
+ }
84
+ }
85
+
86
+ if (!graph[functionName]) {
87
+ console.warn(
88
+ `G6: Invalid functionName option: "${functionName}" for shortcuts-call behavior!`,
89
+ );
90
+ return {};
91
+ }
92
+ if (!this.triggerKeydown) return;
93
+
94
+ if (!combinedKey) {
95
+ if (functionParams && functionParams.length) {
96
+ graph[functionName](...functionParams);
97
+ } else {
98
+ graph[functionName]();
99
+ }
100
+ return;
101
+ }
102
+
103
+ const combinedKeyLowerCase = combinedKey.toLowerCase();
104
+ if (
105
+ codeLowerCase === combinedKeyLowerCase ||
106
+ (codeLowerCase === 'control' && combinedKeyLowerCase === 'ctrl') ||
107
+ (codeLowerCase === 'ctrl' && combinedKeyLowerCase === 'control')
108
+ ) {
109
+ if (functionParams && functionParams.length) {
110
+ graph[functionName](...functionParams);
111
+ } else {
112
+ graph[functionName]();
113
+ }
114
+ }
115
+ }
116
+
117
+ public onKeyUp() {
118
+ this.triggerKeydown = false;
119
+ }
120
+ }