@antv/g6 5.0.0-beta.31 → 5.0.0-beta.32

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 (264) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/collapse-expand.d.ts +4 -5
  3. package/dist/lib/behaviors/create-edge.d.ts +55 -0
  4. package/dist/lib/behaviors/drag-canvas.d.ts +6 -6
  5. package/dist/lib/behaviors/drag-element.d.ts +5 -3
  6. package/dist/lib/behaviors/focus-element.d.ts +4 -3
  7. package/dist/lib/behaviors/hover-element.d.ts +4 -5
  8. package/dist/lib/behaviors/index.d.ts +2 -0
  9. package/dist/lib/behaviors/zoom-canvas.d.ts +7 -6
  10. package/dist/lib/constants/events/graph.d.ts +5 -13
  11. package/dist/lib/constants/index.d.ts +1 -0
  12. package/dist/lib/constants/registry.d.ts +20 -0
  13. package/dist/lib/elements/combos/base-combo.d.ts +21 -0
  14. package/dist/lib/elements/edges/base-edge.d.ts +21 -0
  15. package/dist/lib/elements/nodes/base-node.d.ts +22 -1
  16. package/dist/lib/exports.d.ts +16 -14
  17. package/dist/lib/plugins/camera-setting.d.ts +95 -0
  18. package/dist/lib/plugins/contextmenu.d.ts +8 -5
  19. package/dist/lib/plugins/index.d.ts +4 -0
  20. package/dist/lib/plugins/legend.d.ts +49 -0
  21. package/dist/lib/plugins/tooltip.d.ts +12 -10
  22. package/dist/lib/registry/extension/index.d.ts +2 -2
  23. package/dist/lib/registry/index.d.ts +6 -4
  24. package/dist/lib/registry/types.d.ts +0 -6
  25. package/dist/lib/runtime/canvas.d.ts +2 -1
  26. package/dist/lib/runtime/data.d.ts +1 -1
  27. package/dist/lib/runtime/element.d.ts +4 -5
  28. package/dist/lib/runtime/graph.d.ts +31 -4
  29. package/dist/lib/runtime/plugin.d.ts +1 -0
  30. package/dist/lib/types/event.d.ts +42 -7
  31. package/dist/lib/types/index.d.ts +0 -1
  32. package/dist/lib/utils/bbox.d.ts +1 -1
  33. package/dist/lib/utils/element.d.ts +19 -11
  34. package/dist/lib/utils/event/events.d.ts +8 -13
  35. package/dist/lib/utils/shortcut.d.ts +10 -0
  36. package/esm/behaviors/collapse-expand.d.ts +4 -5
  37. package/esm/behaviors/collapse-expand.js +8 -4
  38. package/esm/behaviors/collapse-expand.js.map +1 -1
  39. package/esm/behaviors/create-edge.d.ts +55 -0
  40. package/esm/behaviors/create-edge.js +141 -0
  41. package/esm/behaviors/create-edge.js.map +1 -0
  42. package/esm/behaviors/drag-canvas.d.ts +6 -6
  43. package/esm/behaviors/drag-canvas.js +15 -7
  44. package/esm/behaviors/drag-canvas.js.map +1 -1
  45. package/esm/behaviors/drag-element.d.ts +5 -3
  46. package/esm/behaviors/drag-element.js.map +1 -1
  47. package/esm/behaviors/focus-element.d.ts +4 -3
  48. package/esm/behaviors/focus-element.js.map +1 -1
  49. package/esm/behaviors/hover-element.d.ts +4 -5
  50. package/esm/behaviors/hover-element.js.map +1 -1
  51. package/esm/behaviors/index.d.ts +2 -0
  52. package/esm/behaviors/index.js +1 -0
  53. package/esm/behaviors/index.js.map +1 -1
  54. package/esm/behaviors/zoom-canvas.d.ts +7 -6
  55. package/esm/behaviors/zoom-canvas.js +6 -2
  56. package/esm/behaviors/zoom-canvas.js.map +1 -1
  57. package/esm/constants/events/graph.d.ts +5 -13
  58. package/esm/constants/events/graph.js +4 -12
  59. package/esm/constants/events/graph.js.map +1 -1
  60. package/esm/constants/index.d.ts +1 -0
  61. package/esm/constants/index.js +1 -0
  62. package/esm/constants/index.js.map +1 -1
  63. package/esm/constants/registry.d.ts +20 -0
  64. package/esm/constants/registry.js +22 -0
  65. package/esm/constants/registry.js.map +1 -0
  66. package/esm/elements/combos/base-combo.d.ts +21 -0
  67. package/esm/elements/combos/base-combo.js +21 -0
  68. package/esm/elements/combos/base-combo.js.map +1 -1
  69. package/esm/elements/edges/base-edge.d.ts +21 -0
  70. package/esm/elements/edges/base-edge.js +21 -0
  71. package/esm/elements/edges/base-edge.js.map +1 -1
  72. package/esm/elements/nodes/base-node.d.ts +22 -1
  73. package/esm/elements/nodes/base-node.js +21 -0
  74. package/esm/elements/nodes/base-node.js.map +1 -1
  75. package/esm/exports.d.ts +16 -14
  76. package/esm/exports.js +7 -6
  77. package/esm/exports.js.map +1 -1
  78. package/esm/plugins/camera-setting.d.ts +95 -0
  79. package/esm/plugins/camera-setting.js +65 -0
  80. package/esm/plugins/camera-setting.js.map +1 -0
  81. package/esm/plugins/contextmenu.d.ts +8 -5
  82. package/esm/plugins/contextmenu.js.map +1 -1
  83. package/esm/plugins/index.d.ts +4 -0
  84. package/esm/plugins/index.js +2 -0
  85. package/esm/plugins/index.js.map +1 -1
  86. package/esm/plugins/legend.d.ts +49 -0
  87. package/esm/plugins/legend.js +267 -0
  88. package/esm/plugins/legend.js.map +1 -0
  89. package/esm/plugins/tooltip.d.ts +12 -10
  90. package/esm/plugins/tooltip.js +0 -1
  91. package/esm/plugins/tooltip.js.map +1 -1
  92. package/esm/preset.js +2 -5
  93. package/esm/preset.js.map +1 -1
  94. package/esm/registry/build-in.js +4 -2
  95. package/esm/registry/build-in.js.map +1 -1
  96. package/esm/registry/extension/index.d.ts +2 -2
  97. package/esm/registry/extension/index.js.map +1 -1
  98. package/esm/registry/index.d.ts +6 -4
  99. package/esm/registry/index.js.map +1 -1
  100. package/esm/registry/types.d.ts +0 -6
  101. package/esm/runtime/behavior.js +3 -2
  102. package/esm/runtime/behavior.js.map +1 -1
  103. package/esm/runtime/canvas.d.ts +2 -1
  104. package/esm/runtime/canvas.js +68 -30
  105. package/esm/runtime/canvas.js.map +1 -1
  106. package/esm/runtime/data.d.ts +1 -1
  107. package/esm/runtime/element.d.ts +4 -5
  108. package/esm/runtime/element.js +32 -13
  109. package/esm/runtime/element.js.map +1 -1
  110. package/esm/runtime/graph.d.ts +31 -4
  111. package/esm/runtime/graph.js +48 -9
  112. package/esm/runtime/graph.js.map +1 -1
  113. package/esm/runtime/plugin.d.ts +1 -0
  114. package/esm/runtime/plugin.js +3 -0
  115. package/esm/runtime/plugin.js.map +1 -1
  116. package/esm/types/event.d.ts +42 -7
  117. package/esm/types/index.d.ts +0 -1
  118. package/esm/utils/bbox.d.ts +1 -1
  119. package/esm/utils/element.d.ts +19 -11
  120. package/esm/utils/element.js +19 -9
  121. package/esm/utils/element.js.map +1 -1
  122. package/esm/utils/event/events.d.ts +8 -13
  123. package/esm/utils/event/events.js +3 -8
  124. package/esm/utils/event/events.js.map +1 -1
  125. package/esm/utils/shortcut.d.ts +10 -0
  126. package/esm/utils/shortcut.js +24 -3
  127. package/esm/utils/shortcut.js.map +1 -1
  128. package/lib/behaviors/collapse-expand.d.ts +4 -5
  129. package/lib/behaviors/collapse-expand.js +8 -4
  130. package/lib/behaviors/collapse-expand.js.map +1 -1
  131. package/lib/behaviors/create-edge.d.ts +55 -0
  132. package/lib/behaviors/create-edge.js +145 -0
  133. package/lib/behaviors/create-edge.js.map +1 -0
  134. package/lib/behaviors/drag-canvas.d.ts +6 -6
  135. package/lib/behaviors/drag-canvas.js +15 -7
  136. package/lib/behaviors/drag-canvas.js.map +1 -1
  137. package/lib/behaviors/drag-element.d.ts +5 -3
  138. package/lib/behaviors/drag-element.js.map +1 -1
  139. package/lib/behaviors/focus-element.d.ts +4 -3
  140. package/lib/behaviors/focus-element.js.map +1 -1
  141. package/lib/behaviors/hover-element.d.ts +4 -5
  142. package/lib/behaviors/hover-element.js.map +1 -1
  143. package/lib/behaviors/index.d.ts +2 -0
  144. package/lib/behaviors/index.js +3 -1
  145. package/lib/behaviors/index.js.map +1 -1
  146. package/lib/behaviors/zoom-canvas.d.ts +7 -6
  147. package/lib/behaviors/zoom-canvas.js +6 -2
  148. package/lib/behaviors/zoom-canvas.js.map +1 -1
  149. package/lib/constants/events/graph.d.ts +5 -13
  150. package/lib/constants/events/graph.js +4 -12
  151. package/lib/constants/events/graph.js.map +1 -1
  152. package/lib/constants/index.d.ts +1 -0
  153. package/lib/constants/index.js +1 -0
  154. package/lib/constants/index.js.map +1 -1
  155. package/lib/constants/registry.d.ts +20 -0
  156. package/lib/constants/registry.js +25 -0
  157. package/lib/constants/registry.js.map +1 -0
  158. package/lib/elements/combos/base-combo.d.ts +21 -0
  159. package/lib/elements/combos/base-combo.js +21 -0
  160. package/lib/elements/combos/base-combo.js.map +1 -1
  161. package/lib/elements/edges/base-edge.d.ts +21 -0
  162. package/lib/elements/edges/base-edge.js +21 -0
  163. package/lib/elements/edges/base-edge.js.map +1 -1
  164. package/lib/elements/nodes/base-node.d.ts +22 -1
  165. package/lib/elements/nodes/base-node.js +21 -0
  166. package/lib/elements/nodes/base-node.js.map +1 -1
  167. package/lib/exports.d.ts +16 -14
  168. package/lib/exports.js +23 -1
  169. package/lib/exports.js.map +1 -1
  170. package/lib/plugins/camera-setting.d.ts +95 -0
  171. package/lib/plugins/camera-setting.js +69 -0
  172. package/lib/plugins/camera-setting.js.map +1 -0
  173. package/lib/plugins/contextmenu.d.ts +8 -5
  174. package/lib/plugins/contextmenu.js.map +1 -1
  175. package/lib/plugins/index.d.ts +4 -0
  176. package/lib/plugins/index.js +5 -1
  177. package/lib/plugins/index.js.map +1 -1
  178. package/lib/plugins/legend.d.ts +49 -0
  179. package/lib/plugins/legend.js +271 -0
  180. package/lib/plugins/legend.js.map +1 -0
  181. package/lib/plugins/tooltip.d.ts +12 -10
  182. package/lib/plugins/tooltip.js +0 -1
  183. package/lib/plugins/tooltip.js.map +1 -1
  184. package/lib/preset.js +2 -5
  185. package/lib/preset.js.map +1 -1
  186. package/lib/registry/build-in.js +2 -0
  187. package/lib/registry/build-in.js.map +1 -1
  188. package/lib/registry/extension/index.d.ts +2 -2
  189. package/lib/registry/extension/index.js.map +1 -1
  190. package/lib/registry/index.d.ts +6 -4
  191. package/lib/registry/index.js.map +1 -1
  192. package/lib/registry/types.d.ts +0 -6
  193. package/lib/runtime/behavior.js +3 -2
  194. package/lib/runtime/behavior.js.map +1 -1
  195. package/lib/runtime/canvas.d.ts +2 -1
  196. package/lib/runtime/canvas.js +68 -30
  197. package/lib/runtime/canvas.js.map +1 -1
  198. package/lib/runtime/data.d.ts +1 -1
  199. package/lib/runtime/element.d.ts +4 -5
  200. package/lib/runtime/element.js +31 -12
  201. package/lib/runtime/element.js.map +1 -1
  202. package/lib/runtime/graph.d.ts +31 -4
  203. package/lib/runtime/graph.js +47 -8
  204. package/lib/runtime/graph.js.map +1 -1
  205. package/lib/runtime/plugin.d.ts +1 -0
  206. package/lib/runtime/plugin.js +3 -0
  207. package/lib/runtime/plugin.js.map +1 -1
  208. package/lib/types/event.d.ts +42 -7
  209. package/lib/types/index.d.ts +0 -1
  210. package/lib/utils/bbox.d.ts +1 -1
  211. package/lib/utils/element.d.ts +19 -11
  212. package/lib/utils/element.js +21 -10
  213. package/lib/utils/element.js.map +1 -1
  214. package/lib/utils/event/events.d.ts +8 -13
  215. package/lib/utils/event/events.js +4 -10
  216. package/lib/utils/event/events.js.map +1 -1
  217. package/lib/utils/shortcut.d.ts +10 -0
  218. package/lib/utils/shortcut.js +24 -3
  219. package/lib/utils/shortcut.js.map +1 -1
  220. package/package.json +2 -2
  221. package/src/behaviors/collapse-expand.ts +13 -11
  222. package/src/behaviors/create-edge.ts +206 -0
  223. package/src/behaviors/drag-canvas.ts +22 -14
  224. package/src/behaviors/drag-element.ts +8 -11
  225. package/src/behaviors/focus-element.ts +7 -6
  226. package/src/behaviors/hover-element.ts +14 -10
  227. package/src/behaviors/index.ts +2 -0
  228. package/src/behaviors/zoom-canvas.ts +14 -9
  229. package/src/constants/events/graph.ts +4 -12
  230. package/src/constants/index.ts +1 -0
  231. package/src/constants/registry.ts +20 -0
  232. package/src/elements/combos/base-combo.ts +24 -0
  233. package/src/elements/edges/base-edge.ts +25 -1
  234. package/src/elements/nodes/base-node.ts +25 -1
  235. package/src/exports.ts +55 -12
  236. package/src/plugins/camera-setting.ts +153 -0
  237. package/src/plugins/contextmenu.ts +10 -7
  238. package/src/plugins/index.ts +4 -0
  239. package/src/plugins/legend.ts +321 -0
  240. package/src/plugins/tooltip.ts +16 -15
  241. package/src/preset.ts +2 -6
  242. package/src/registry/build-in.ts +12 -2
  243. package/src/registry/extension/index.ts +4 -4
  244. package/src/registry/index.ts +10 -4
  245. package/src/registry/types.ts +0 -7
  246. package/src/runtime/behavior.ts +3 -2
  247. package/src/runtime/canvas.ts +80 -40
  248. package/src/runtime/element.ts +52 -20
  249. package/src/runtime/graph.ts +56 -12
  250. package/src/runtime/plugin.ts +4 -0
  251. package/src/types/event.ts +62 -7
  252. package/src/types/index.ts +0 -1
  253. package/src/utils/bbox.ts +1 -1
  254. package/src/utils/element.ts +22 -11
  255. package/src/utils/event/events.ts +15 -17
  256. package/src/utils/shortcut.ts +28 -3
  257. package/dist/lib/types/behavior.d.ts +0 -5
  258. package/esm/types/behavior.d.ts +0 -5
  259. package/esm/types/behavior.js +0 -2
  260. package/esm/types/behavior.js.map +0 -1
  261. package/lib/types/behavior.d.ts +0 -5
  262. package/lib/types/behavior.js +0 -3
  263. package/lib/types/behavior.js.map +0 -1
  264. package/src/types/behavior.ts +0 -6
@@ -1,11 +1,66 @@
1
- import type { Document, FederatedMouseEvent } from '@antv/g';
2
- import type { BehaviorEvent } from './behavior';
3
- import { Edge, ElementType, Node } from './element';
1
+ import type {
2
+ DisplayObject,
3
+ Document,
4
+ FederatedEvent,
5
+ FederatedPointerEvent,
6
+ FederatedWheelEvent,
7
+ IAnimation,
8
+ } from '@antv/g';
9
+ import type { AnimationType } from '../constants';
10
+ import type { ElementDatum } from './data';
11
+ import type { Element, ElementType } from './element';
12
+ import type { TransformOptions } from './viewport';
4
13
 
5
- export type Listener = (event: any) => void;
14
+ export type IEvent =
15
+ | IGraphLifeCycleEvent
16
+ | IAnimateEvent
17
+ | IElementLifeCycleEvent
18
+ | IViewportEvent
19
+ | IPointerEvent
20
+ | IWheelEvent
21
+ | IKeyboardEvent
22
+ | IDragEvent;
6
23
 
7
- export type Target = Document | Node | Edge | null;
24
+ export interface IPointerEvent<T extends Target = Target> extends TargetedEvent<FederatedPointerEvent, T> {}
8
25
 
9
- export interface ElementEvent extends BehaviorEvent<FederatedMouseEvent> {
10
- targetType: ElementType;
26
+ export interface IWheelEvent<T extends Target = Target> extends TargetedEvent<FederatedWheelEvent, T> {}
27
+
28
+ export interface IKeyboardEvent extends KeyboardEvent {}
29
+
30
+ export interface IDragEvent<T extends Target = Target> extends TargetedEvent<FederatedPointerEvent, T> {
31
+ dx: number;
32
+ dy: number;
33
+ }
34
+
35
+ export interface IGraphLifeCycleEvent extends NativeEvent {
36
+ data?: any;
37
+ }
38
+
39
+ export interface IElementLifeCycleEvent extends NativeEvent {
40
+ elementType: ElementType;
41
+ data: ElementDatum;
42
+ }
43
+
44
+ export interface IViewportEvent extends NativeEvent {
45
+ data: TransformOptions;
46
+ }
47
+
48
+ export interface IAnimateEvent extends NativeEvent {
49
+ animationType: AnimationType;
50
+ animation: IAnimation | null;
51
+ data?: any;
11
52
  }
53
+
54
+ /** <zh/> G6 原生事件 | <en/> G6 native event */
55
+ interface NativeEvent {
56
+ type: string;
57
+ }
58
+
59
+ /** <zh/> 具有目标的事件 | <en/> Event with target */
60
+ type TargetedEvent<E extends FederatedEvent, T extends Target = Target> = Omit<E, 'target'> & {
61
+ originalTarget: DisplayObject;
62
+ target: T;
63
+ targetType: 'canvas' | 'node' | 'edge' | 'combo';
64
+ };
65
+
66
+ export type Target = Document | Element;
@@ -1,6 +1,5 @@
1
1
  export type * from './anchor';
2
2
  export type * from './animation';
3
- export type * from './behavior';
4
3
  export type * from './callable';
5
4
  export type * from './canvas';
6
5
  export type * from './change';
package/src/utils/bbox.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AABB } from '@antv/g';
2
2
  import { clone } from '@antv/util';
3
- import { TriangleDirection } from '../elements/nodes/triangle';
3
+ import type { TriangleDirection } from '../elements/nodes/triangle';
4
4
  import type { Node, Padding, Point } from '../types';
5
5
  import { isPoint } from './is';
6
6
  import { isBetween } from './math';
@@ -1,9 +1,9 @@
1
1
  import type { AABB, DisplayObject, TextStyleProps } from '@antv/g';
2
2
  import { get, isString } from '@antv/util';
3
3
  import { BaseCombo, BaseEdge, BaseNode } from '../elements';
4
- import { NodePortStyleProps } from '../elements/nodes/base-node';
4
+ import type { NodePortStyleProps } from '../elements/nodes/base-node';
5
5
  import type { TriangleDirection } from '../elements/nodes/triangle';
6
- import type { Combo, Edge, Node, Placement, Point, Position } from '../types';
6
+ import type { Combo, Edge, Element, Node, Placement, Point, Position } from '../types';
7
7
  import type { LabelPlacement, Port } from '../types/node';
8
8
  import { getBBoxHeight, getBBoxWidth } from './bbox';
9
9
  import { isPoint } from './is';
@@ -11,38 +11,49 @@ import { findNearestPoints, getEllipseIntersectPoint } from './point';
11
11
  import { getXYByPlacement } from './position';
12
12
 
13
13
  /**
14
- * <zh/> 判断是否是 BaseNode 的实例
14
+ * <zh/> 判断是否是 Node 的实例
15
15
  *
16
- * <en/> Judge whether the instance is BaseNode
16
+ * <en/> Judge whether the instance is Node
17
17
  * @param shape - <zh/> 实例 | <en/> instance
18
- * @returns <zh/> 是否是 BaseNode 的实例 | <en/> whether the instance is BaseNode
18
+ * @returns <zh/> 是否是 Node 的实例 | <en/> whether the instance is Node
19
19
  */
20
20
  export function isNode(shape: DisplayObject | Port): shape is Node {
21
21
  return shape instanceof BaseNode && shape.type === 'node';
22
22
  }
23
23
 
24
24
  /**
25
- * <zh/> 判断是否是 BaseEdge 的实例
25
+ * <zh/> 判断是否是 Edge 的实例
26
26
  *
27
- * <en/> Judge whether the instance is BaseEdge
27
+ * <en/> Judge whether the instance is Edge
28
28
  * @param shape - <zh/> 实例 | <en/> instance
29
- * @returns <zh/> 是否是 BaseEdge 的实例 | <en/> whether the instance is BaseEdge
29
+ * @returns <zh/> 是否是 Edge 的实例 | <en/> whether the instance is Edge
30
30
  */
31
31
  export function isEdge(shape: DisplayObject): shape is Edge {
32
32
  return shape instanceof BaseEdge;
33
33
  }
34
34
 
35
35
  /**
36
- * <zh/> 判断是否是 BaseCombo 的实例
36
+ * <zh/> 判断是否是 Combo 的实例
37
37
  *
38
- * <en/> Judge whether the instance is BaseCombo
38
+ * <en/> Judge whether the instance is Combo
39
39
  * @param shape - <zh/> 实例 | <en/> instance
40
- * @returns <zh/> 是否是 BaseCombo 的实例 | <en/> whether the instance is BaseCombo
40
+ * @returns <zh/> 是否是 Combo 的实例 | <en/> whether the instance is Combo
41
41
  */
42
42
  export function isCombo(shape: DisplayObject): shape is Combo {
43
43
  return shape instanceof BaseCombo;
44
44
  }
45
45
 
46
+ /**
47
+ * <zh/> 判断是否是 Element 的实例
48
+ *
49
+ * <en/> Judge whether the instance is Element
50
+ * @param shape - <zh/> 实例 | <en/> instance
51
+ * @returns <zh/> 是否是 Element 的实例 | <en/> whether the instance is Element
52
+ */
53
+ export function isElement(shape: any): shape is Element {
54
+ return isNode(shape) || isEdge(shape) || isCombo(shape);
55
+ }
56
+
46
57
  /**
47
58
  * <zh/> 判断两个节点是否相同
48
59
  *
@@ -1,14 +1,20 @@
1
1
  import type { IAnimation } from '@antv/g';
2
- import type { ID } from '@antv/graphlib';
3
2
  import type { AnimationType, GraphEvent } from '../../constants';
4
- import type { GraphData } from '../../spec';
5
- import type { State, TransformOptions } from '../../types';
3
+ import type {
4
+ ElementDatum,
5
+ ElementType,
6
+ IAnimateEvent,
7
+ IElementLifeCycleEvent,
8
+ IGraphLifeCycleEvent,
9
+ IViewportEvent,
10
+ TransformOptions,
11
+ } from '../../types';
6
12
 
7
13
  export class BaseEvent {
8
14
  constructor(public type: string) {}
9
15
  }
10
16
 
11
- export class GraphLifeCycleEvent extends BaseEvent {
17
+ export class GraphLifeCycleEvent extends BaseEvent implements IGraphLifeCycleEvent {
12
18
  constructor(
13
19
  type:
14
20
  | GraphEvent.BEFORE_RENDER
@@ -25,7 +31,7 @@ export class GraphLifeCycleEvent extends BaseEvent {
25
31
  }
26
32
  }
27
33
 
28
- export class AnimateEvent extends BaseEvent {
34
+ export class AnimateEvent extends BaseEvent implements IAnimateEvent {
29
35
  constructor(
30
36
  type: GraphEvent.BEFORE_ANIMATE | GraphEvent.AFTER_ANIMATE,
31
37
  public animationType: AnimationType,
@@ -36,7 +42,7 @@ export class AnimateEvent extends BaseEvent {
36
42
  }
37
43
  }
38
44
 
39
- export class ElementLifeCycleEvent extends BaseEvent {
45
+ export class ElementLifeCycleEvent extends BaseEvent implements IElementLifeCycleEvent {
40
46
  constructor(
41
47
  type:
42
48
  | GraphEvent.BEFORE_ELEMENT_CREATE
@@ -45,13 +51,14 @@ export class ElementLifeCycleEvent extends BaseEvent {
45
51
  | GraphEvent.AFTER_ELEMENT_UPDATE
46
52
  | GraphEvent.BEFORE_ELEMENT_DESTROY
47
53
  | GraphEvent.AFTER_ELEMENT_DESTROY,
48
- public data: GraphData,
54
+ public elementType: ElementType,
55
+ public data: ElementDatum,
49
56
  ) {
50
57
  super(type);
51
58
  }
52
59
  }
53
60
 
54
- export class ViewportEvent extends BaseEvent {
61
+ export class ViewportEvent extends BaseEvent implements IViewportEvent {
55
62
  constructor(
56
63
  type: GraphEvent.BEFORE_TRANSFORM | GraphEvent.AFTER_TRANSFORM,
57
64
  public data: TransformOptions,
@@ -59,12 +66,3 @@ export class ViewportEvent extends BaseEvent {
59
66
  super(type);
60
67
  }
61
68
  }
62
-
63
- export class ElementStateChangeEvent extends BaseEvent {
64
- constructor(
65
- type: GraphEvent.BEFORE_ELEMENT_STATE_CHANGE | GraphEvent.AFTER_ELEMENT_STATE_CHANGE,
66
- public states: Record<ID, State | State[]>,
67
- ) {
68
- super(type);
69
- }
70
- }
@@ -1,4 +1,5 @@
1
1
  import EventEmitter from '@antv/event-emitter';
2
+ import type { FederatedMouseEvent } from '@antv/g';
2
3
  import { isEqual } from '@antv/util';
3
4
  import { CommonEvent } from '../constants';
4
5
 
@@ -43,6 +44,7 @@ export class Shortcut {
43
44
  emitter.on(CommonEvent.KEY_DOWN, this.onKeyDown);
44
45
  emitter.on(CommonEvent.KEY_UP, this.onKeyUp);
45
46
  emitter.on(CommonEvent.WHEEL, this.onWheel);
47
+ emitter.on(CommonEvent.DRAG, this.onDrag);
46
48
  }
47
49
 
48
50
  private onKeyDown = (event: KeyboardEvent) => {
@@ -60,18 +62,41 @@ export class Shortcut {
60
62
  });
61
63
  }
62
64
 
63
- private onWheel = (event: WheelEvent) => {
65
+ /**
66
+ * <zh/> 扩展 wheel, drag 操作
67
+ *
68
+ * <en/> Extend wheel, drag operations
69
+ * @param eventType - event name
70
+ * @param event - event
71
+ */
72
+ private triggerExtendKey(eventType: CommonEvent, event: unknown) {
64
73
  this.map.forEach((handler, key) => {
65
- if (key.includes(CommonEvent.WHEEL)) {
74
+ if (key.includes(eventType)) {
66
75
  if (
67
76
  isEqual(
68
77
  Array.from(this.recordKey),
69
- key.filter((k) => k !== CommonEvent.WHEEL),
78
+ key.filter((k) => k !== eventType),
70
79
  )
71
80
  ) {
72
81
  handler(event);
73
82
  }
74
83
  }
75
84
  });
85
+ }
86
+
87
+ private onWheel = (event: WheelEvent) => {
88
+ this.triggerExtendKey(CommonEvent.WHEEL, event);
76
89
  };
90
+
91
+ private onDrag = (event: FederatedMouseEvent) => {
92
+ this.triggerExtendKey(CommonEvent.DRAG, event);
93
+ };
94
+
95
+ public destroy() {
96
+ this.unbindAll();
97
+ this.emitter.off(CommonEvent.KEY_DOWN, this.onKeyDown);
98
+ this.emitter.off(CommonEvent.KEY_UP, this.onKeyUp);
99
+ this.emitter.off(CommonEvent.WHEEL, this.onWheel);
100
+ this.emitter.off(CommonEvent.DRAG, this.onDrag);
101
+ }
77
102
  }
@@ -1,5 +0,0 @@
1
- import type { DisplayObject, FederatedEvent } from '@antv/g';
2
- export type BehaviorEvent<T extends Event | FederatedEvent = Event> = Omit<T, 'target'> & {
3
- targetType: 'canvas' | 'node' | 'edge' | 'combo';
4
- target: DisplayObject;
5
- };
@@ -1,5 +0,0 @@
1
- import type { DisplayObject, FederatedEvent } from '@antv/g';
2
- export type BehaviorEvent<T extends Event | FederatedEvent = Event> = Omit<T, 'target'> & {
3
- targetType: 'canvas' | 'node' | 'edge' | 'combo';
4
- target: DisplayObject;
5
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=behavior.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"behavior.js","sourceRoot":"src/","sources":["types/behavior.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import type { DisplayObject, FederatedEvent } from '@antv/g';
2
- export type BehaviorEvent<T extends Event | FederatedEvent = Event> = Omit<T, 'target'> & {
3
- targetType: 'canvas' | 'node' | 'edge' | 'combo';
4
- target: DisplayObject;
5
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=behavior.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"behavior.js","sourceRoot":"src/","sources":["types/behavior.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import type { DisplayObject, FederatedEvent } from '@antv/g';
2
-
3
- export type BehaviorEvent<T extends Event | FederatedEvent = Event> = Omit<T, 'target'> & {
4
- targetType: 'canvas' | 'node' | 'edge' | 'combo';
5
- target: DisplayObject;
6
- };