@antv/g6 5.0.0-beta.5 → 5.0.0-beta.7

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 (221) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +15 -7
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.d.ts +1 -1
  5. package/esm/item/combo.js +16 -9
  6. package/esm/item/combo.js.map +1 -1
  7. package/esm/item/edge.d.ts +22 -2
  8. package/esm/item/edge.js +93 -42
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/item.js +9 -5
  11. package/esm/item/item.js.map +1 -1
  12. package/esm/item/node.d.ts +1 -1
  13. package/esm/item/node.js +22 -15
  14. package/esm/item/node.js.map +1 -1
  15. package/esm/runtime/controller/data.d.ts +7 -10
  16. package/esm/runtime/controller/data.js +123 -281
  17. package/esm/runtime/controller/data.js.map +1 -1
  18. package/esm/runtime/controller/item.d.ts +1 -0
  19. package/esm/runtime/controller/item.js +21 -9
  20. package/esm/runtime/controller/item.js.map +1 -1
  21. package/esm/runtime/graph.d.ts +85 -7
  22. package/esm/runtime/graph.js +396 -61
  23. package/esm/runtime/graph.js.map +1 -1
  24. package/esm/stdlib/behavior/brush-select.js +1 -2
  25. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  26. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  27. package/esm/stdlib/behavior/create-edge.js +207 -0
  28. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  29. package/esm/stdlib/behavior/drag-canvas.d.ts +2 -1
  30. package/esm/stdlib/behavior/drag-canvas.js +26 -18
  31. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  32. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  33. package/esm/stdlib/behavior/drag-combo.js +35 -24
  34. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  35. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  36. package/esm/stdlib/behavior/drag-node.js +70 -57
  37. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  38. package/esm/stdlib/behavior/index.d.ts +2 -0
  39. package/esm/stdlib/behavior/index.js +2 -0
  40. package/esm/stdlib/behavior/index.js.map +1 -1
  41. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  42. package/esm/stdlib/behavior/lasso-select.js +1 -2
  43. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  44. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  45. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  46. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  47. package/esm/stdlib/behavior/zoom-canvas.d.ts +2 -1
  48. package/esm/stdlib/behavior/zoom-canvas.js +30 -22
  49. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  50. package/esm/stdlib/data/mapNodeSize.d.ts +2 -2
  51. package/esm/stdlib/data/mapNodeSize.js +2 -2
  52. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  53. package/esm/stdlib/data/transformV4Data.d.ts +2 -2
  54. package/esm/stdlib/data/transformV4Data.js +2 -2
  55. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  56. package/esm/stdlib/data/validateData.d.ts +2 -2
  57. package/esm/stdlib/data/validateData.js +9 -9
  58. package/esm/stdlib/data/validateData.js.map +1 -1
  59. package/esm/stdlib/index.d.ts +10 -6
  60. package/esm/stdlib/index.js +5 -1
  61. package/esm/stdlib/index.js.map +1 -1
  62. package/esm/stdlib/item/edge/base.js +4 -9
  63. package/esm/stdlib/item/edge/base.js.map +1 -1
  64. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  65. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  66. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  67. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  68. package/esm/stdlib/plugin/minimap/index.js +116 -9
  69. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  70. package/esm/stdlib/plugin/snapline/index.d.ts +5 -1
  71. package/esm/stdlib/plugin/snapline/index.js +23 -12
  72. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  73. package/esm/types/graph.d.ts +34 -8
  74. package/esm/types/hook.d.ts +16 -2
  75. package/esm/types/spec.d.ts +6 -3
  76. package/esm/types/view.d.ts +5 -0
  77. package/esm/util/event.d.ts +3 -1
  78. package/esm/util/event.js +8 -1
  79. package/esm/util/event.js.map +1 -1
  80. package/esm/util/item.d.ts +16 -1
  81. package/esm/util/item.js +31 -8
  82. package/esm/util/item.js.map +1 -1
  83. package/esm/util/layout.d.ts +11 -0
  84. package/esm/util/layout.js +45 -0
  85. package/esm/util/layout.js.map +1 -1
  86. package/esm/util/point.js +5 -1
  87. package/esm/util/point.js.map +1 -1
  88. package/esm/util/shape.d.ts +1 -1
  89. package/esm/util/shape.js +3 -7
  90. package/esm/util/shape.js.map +1 -1
  91. package/esm/util/warn.d.ts +14 -0
  92. package/esm/util/warn.js +4 -0
  93. package/esm/util/warn.js.map +1 -0
  94. package/lib/index.d.ts +15 -7
  95. package/lib/index.js +1 -1
  96. package/lib/item/combo.d.ts +1 -1
  97. package/lib/item/combo.js +16 -9
  98. package/lib/item/combo.js.map +1 -1
  99. package/lib/item/edge.d.ts +22 -2
  100. package/lib/item/edge.js +92 -41
  101. package/lib/item/edge.js.map +1 -1
  102. package/lib/item/item.js +9 -5
  103. package/lib/item/item.js.map +1 -1
  104. package/lib/item/node.d.ts +1 -1
  105. package/lib/item/node.js +22 -15
  106. package/lib/item/node.js.map +1 -1
  107. package/lib/runtime/controller/data.d.ts +7 -10
  108. package/lib/runtime/controller/data.js +123 -281
  109. package/lib/runtime/controller/data.js.map +1 -1
  110. package/lib/runtime/controller/item.d.ts +1 -0
  111. package/lib/runtime/controller/item.js +21 -9
  112. package/lib/runtime/controller/item.js.map +1 -1
  113. package/lib/runtime/graph.d.ts +85 -7
  114. package/lib/runtime/graph.js +396 -61
  115. package/lib/runtime/graph.js.map +1 -1
  116. package/lib/stdlib/behavior/brush-select.js +1 -2
  117. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  118. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  119. package/lib/stdlib/behavior/create-edge.js +211 -0
  120. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  121. package/lib/stdlib/behavior/drag-canvas.d.ts +2 -1
  122. package/lib/stdlib/behavior/drag-canvas.js +26 -18
  123. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  124. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  125. package/lib/stdlib/behavior/drag-combo.js +35 -24
  126. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  127. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  128. package/lib/stdlib/behavior/drag-node.js +70 -57
  129. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  130. package/lib/stdlib/behavior/index.d.ts +2 -0
  131. package/lib/stdlib/behavior/index.js +2 -0
  132. package/lib/stdlib/behavior/index.js.map +1 -1
  133. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  134. package/lib/stdlib/behavior/lasso-select.js +1 -2
  135. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  136. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  137. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  138. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  139. package/lib/stdlib/behavior/zoom-canvas.d.ts +2 -1
  140. package/lib/stdlib/behavior/zoom-canvas.js +30 -22
  141. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  142. package/lib/stdlib/data/mapNodeSize.d.ts +2 -2
  143. package/lib/stdlib/data/mapNodeSize.js +2 -2
  144. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  145. package/lib/stdlib/data/transformV4Data.d.ts +2 -2
  146. package/lib/stdlib/data/transformV4Data.js +2 -2
  147. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  148. package/lib/stdlib/data/validateData.d.ts +2 -2
  149. package/lib/stdlib/data/validateData.js +9 -9
  150. package/lib/stdlib/data/validateData.js.map +1 -1
  151. package/lib/stdlib/index.d.ts +10 -6
  152. package/lib/stdlib/index.js +5 -1
  153. package/lib/stdlib/index.js.map +1 -1
  154. package/lib/stdlib/item/edge/base.js +4 -9
  155. package/lib/stdlib/item/edge/base.js.map +1 -1
  156. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  157. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  158. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  159. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  160. package/lib/stdlib/plugin/minimap/index.js +116 -9
  161. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  162. package/lib/stdlib/plugin/snapline/index.d.ts +5 -1
  163. package/lib/stdlib/plugin/snapline/index.js +23 -12
  164. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  165. package/lib/types/graph.d.ts +34 -8
  166. package/lib/types/hook.d.ts +16 -2
  167. package/lib/types/spec.d.ts +6 -3
  168. package/lib/types/view.d.ts +5 -0
  169. package/lib/util/event.d.ts +3 -1
  170. package/lib/util/event.js +8 -1
  171. package/lib/util/event.js.map +1 -1
  172. package/lib/util/item.d.ts +16 -1
  173. package/lib/util/item.js +33 -9
  174. package/lib/util/item.js.map +1 -1
  175. package/lib/util/layout.d.ts +11 -0
  176. package/lib/util/layout.js +47 -1
  177. package/lib/util/layout.js.map +1 -1
  178. package/lib/util/point.js +5 -1
  179. package/lib/util/point.js.map +1 -1
  180. package/lib/util/shape.d.ts +1 -1
  181. package/lib/util/shape.js +3 -7
  182. package/lib/util/shape.js.map +1 -1
  183. package/lib/util/warn.d.ts +14 -0
  184. package/lib/util/warn.js +8 -0
  185. package/lib/util/warn.js.map +1 -0
  186. package/package.json +1 -1
  187. package/src/index.ts +1 -1
  188. package/src/item/combo.ts +14 -9
  189. package/src/item/edge.ts +121 -55
  190. package/src/item/item.ts +13 -9
  191. package/src/item/node.ts +20 -15
  192. package/src/runtime/controller/data.ts +139 -339
  193. package/src/runtime/controller/item.ts +30 -12
  194. package/src/runtime/graph.ts +502 -67
  195. package/src/stdlib/behavior/brush-select.ts +4 -2
  196. package/src/stdlib/behavior/create-edge.ts +296 -0
  197. package/src/stdlib/behavior/drag-canvas.ts +30 -19
  198. package/src/stdlib/behavior/drag-combo.ts +2 -2
  199. package/src/stdlib/behavior/drag-node.ts +8 -8
  200. package/src/stdlib/behavior/index.ts +2 -0
  201. package/src/stdlib/behavior/lasso-select.ts +5 -3
  202. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  203. package/src/stdlib/behavior/zoom-canvas.ts +34 -23
  204. package/src/stdlib/data/mapNodeSize.ts +2 -2
  205. package/src/stdlib/data/transformV4Data.ts +2 -2
  206. package/src/stdlib/data/validateData.ts +9 -9
  207. package/src/stdlib/index.ts +6 -0
  208. package/src/stdlib/item/edge/base.ts +4 -8
  209. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  210. package/src/stdlib/plugin/minimap/index.ts +120 -10
  211. package/src/stdlib/plugin/snapline/index.ts +36 -16
  212. package/src/types/graph.ts +37 -8
  213. package/src/types/hook.ts +16 -2
  214. package/src/types/spec.ts +9 -3
  215. package/src/types/view.ts +8 -3
  216. package/src/util/event.ts +14 -1
  217. package/src/util/item.ts +65 -28
  218. package/src/util/layout.ts +45 -0
  219. package/src/util/point.ts +4 -2
  220. package/src/util/shape.ts +6 -7
  221. package/src/util/warn.ts +20 -0
@@ -345,8 +345,10 @@ export class BrushSelect extends Behavior {
345
345
  const { graph, options } = this;
346
346
  const { brushStyle } = options;
347
347
  const brush = graph.drawTransient('rect', BRUSH_SHAPE_ID, {
348
- style: brushStyle,
349
- capture: false,
348
+ style: {
349
+ ...brushStyle,
350
+ pointerEvents: 'none',
351
+ },
350
352
  });
351
353
  return brush;
352
354
  }
@@ -0,0 +1,296 @@
1
+ import type { IG6GraphEvent } from '../../types';
2
+ import { warn } from '../../util/warn';
3
+ import { generateEdgeID } from '../../util/item';
4
+ import { Behavior } from '../../types/behavior';
5
+ import { EdgeDisplayModelData } from '../../types/edge';
6
+
7
+ const KEYBOARD_TRIGGERS = ['shift', 'ctrl', 'control', 'alt', 'meta'] as const;
8
+ const EVENT_TRIGGERS = ['click', 'drag'] as const;
9
+
10
+ const VIRTUAL_EDGE_ID = 'g6-create-edge-virtual-edge';
11
+ const DUMMY_NODE_ID = 'g6-create-edge-dummy-node';
12
+
13
+ // type Trigger = (typeof EVENT_TRIGGERS)[number];
14
+
15
+ interface CreateEdgeOptions {
16
+ /**
17
+ * The triggering conditions for this interaction can be either 'click' or 'drag'.
18
+ * Default to `click`.
19
+ */
20
+ trigger: (typeof EVENT_TRIGGERS)[number];
21
+ /**
22
+ * The assistant secondary key on keyboard. If it is not assigned, the behavior will be triggered when trigger happens.
23
+ * cound be 'shift', 'ctrl', 'control', 'alt', 'meta', undefined.
24
+ */
25
+ secondaryKey?: (typeof KEYBOARD_TRIGGERS)[number];
26
+ /**
27
+ * Config of the created edge.
28
+ */
29
+ edgeConfig: EdgeDisplayModelData;
30
+ /**
31
+ * The event name to trigger after creating the virtual edge.
32
+ */
33
+ createVirtualEventName?: string;
34
+ /**
35
+ * The event name to trigger after creating the actual edge.
36
+ */
37
+ createActualEventName?: string;
38
+ /**
39
+ * The event name to trigger after canceling the behavior.
40
+ */
41
+ cancelCreateEventName?: string;
42
+ /**
43
+ * Whether allow the behavior happen on the current item.
44
+ */
45
+ shouldBegin: (event: IG6GraphEvent) => boolean;
46
+ /**
47
+ *
48
+ * Whether it is allowed to end the creation of edges under the current conditions being operated.
49
+ */
50
+ shouldEnd: (event: IG6GraphEvent) => boolean;
51
+ }
52
+
53
+ const DEFAULT_OPTIONS: CreateEdgeOptions = {
54
+ trigger: 'click',
55
+ secondaryKey: undefined,
56
+ shouldBegin: () => true,
57
+ shouldEnd: () => false,
58
+ edgeConfig: {},
59
+ };
60
+
61
+ export class CreateEdge extends Behavior {
62
+ isKeyDown = false;
63
+ addingEdge = null;
64
+ dummyNode = null;
65
+
66
+ constructor(options: Partial<CreateEdgeOptions>) {
67
+ super(Object.assign({}, DEFAULT_OPTIONS, options));
68
+ this.validateOptions(options);
69
+ }
70
+
71
+ validateOptions(options: Partial<CreateEdgeOptions>) {
72
+ if (options.trigger && !EVENT_TRIGGERS.includes(options.trigger)) {
73
+ warn({
74
+ optionName: `create-edge.trigger`,
75
+ shouldBe: EVENT_TRIGGERS,
76
+ now: options.trigger,
77
+ scope: 'behavior',
78
+ });
79
+
80
+ this.options.trigger = DEFAULT_OPTIONS.trigger;
81
+ }
82
+
83
+ if (
84
+ options.secondaryKey &&
85
+ !KEYBOARD_TRIGGERS.includes(options.secondaryKey)
86
+ ) {
87
+ warn({
88
+ optionName: `create-edge.secondaryKey`,
89
+ shouldBe: KEYBOARD_TRIGGERS,
90
+ now: options.secondaryKey,
91
+ scope: 'behavior',
92
+ });
93
+ this.options.secondaryKey = DEFAULT_OPTIONS.secondaryKey;
94
+ }
95
+ }
96
+
97
+ getEvents = () => {
98
+ const { trigger, secondaryKey } = this.options;
99
+ const [CLICK_NAME] = EVENT_TRIGGERS;
100
+
101
+ const triggerEvents =
102
+ trigger === CLICK_NAME
103
+ ? {
104
+ 'node:click': this.handleCreateEdge,
105
+ pointermove: this.updateEndPoint,
106
+ 'edge:click': this.cancelCreating,
107
+ 'canvas:click': this.cancelCreating,
108
+ 'combo:click': this.handleCreateEdge,
109
+ }
110
+ : {
111
+ 'node:dragstart': this.handleCreateEdge,
112
+ 'combo:dragstart': this.handleCreateEdge,
113
+ drag: this.updateEndPoint,
114
+ drop: this.onDrop,
115
+ };
116
+
117
+ const keyboardEvents = secondaryKey
118
+ ? {
119
+ keydown: this.onKeyDown,
120
+ keyup: this.onKeyUp,
121
+ }
122
+ : {};
123
+
124
+ return { ...triggerEvents, ...keyboardEvents } as Record<
125
+ string,
126
+ (e: IG6GraphEvent) => void
127
+ >;
128
+ };
129
+
130
+ handleCreateEdge = (e: IG6GraphEvent) => {
131
+ if (this.options.secondaryKey && !this.isKeyDown) {
132
+ return;
133
+ }
134
+
135
+ if (this.options.shouldEnd(e)) {
136
+ return;
137
+ }
138
+
139
+ const { graph, options, addingEdge } = this;
140
+ const currentNodeId = e.itemId;
141
+
142
+ const { edgeConfig, createVirtualEventName, createActualEventName } =
143
+ options;
144
+
145
+ if (addingEdge) {
146
+ // create edge end, add the actual edge to graph and remove the virtual edge and node
147
+ const actualEdge = graph.addData('edge', {
148
+ id: generateEdgeID(addingEdge.source, currentNodeId),
149
+ source: addingEdge.source,
150
+ target: currentNodeId,
151
+ data: {
152
+ ...edgeConfig,
153
+ type:
154
+ currentNodeId === addingEdge.source ? 'loop-edge' : edgeConfig.type,
155
+ },
156
+ });
157
+ if (createActualEventName) {
158
+ graph.emit(createActualEventName, { edge: actualEdge });
159
+ }
160
+ this.cancelCreating();
161
+
162
+ return;
163
+ }
164
+
165
+ this.dummyNode = graph.addData('node', {
166
+ id: DUMMY_NODE_ID,
167
+ data: {
168
+ x: e.canvas.x,
169
+ y: e.canvas.y,
170
+ keyShape: {
171
+ opacity: 0,
172
+ interactive: false,
173
+ },
174
+ labelShape: {
175
+ opacity: 0,
176
+ },
177
+ anchorPoints: [[0.5, 0.5]],
178
+ },
179
+ });
180
+ this.addingEdge = graph.addData('edge', {
181
+ id: VIRTUAL_EDGE_ID,
182
+ source: currentNodeId,
183
+ target: DUMMY_NODE_ID,
184
+ data: {
185
+ ...edgeConfig,
186
+ },
187
+ });
188
+ if (createVirtualEventName) {
189
+ graph.emit(createVirtualEventName, { edge: this.addingEdge });
190
+ }
191
+ };
192
+
193
+ onDrop = async (e: IG6GraphEvent) => {
194
+ const { addingEdge, options, graph } = this;
195
+
196
+ const { edgeConfig, secondaryKey, createActualEventName } = options;
197
+ if (secondaryKey && !this.isKeyDown) {
198
+ return;
199
+ }
200
+
201
+ if (!addingEdge) {
202
+ return;
203
+ }
204
+
205
+ const elements = await this.graph.canvas.document.elementsFromPoint(
206
+ e.canvas.x,
207
+ e.canvas.y,
208
+ );
209
+ const currentIds = elements
210
+ // @ts-ignore TODO: G type
211
+ .map((ele) => ele.parentNode.getAttribute?.('data-item-id'))
212
+ .filter((id) => id !== undefined && !DUMMY_NODE_ID !== id);
213
+ const dropId = currentIds.find(
214
+ (id) => this.graph.getComboData(id) || this.graph.getNodeData(id),
215
+ );
216
+
217
+ if (!dropId) {
218
+ this.cancelCreating();
219
+ return;
220
+ }
221
+
222
+ const actualEdge = graph.addData('edge', {
223
+ id: generateEdgeID(addingEdge.source, dropId),
224
+ source: addingEdge.source,
225
+ target: dropId,
226
+ data: {
227
+ ...edgeConfig,
228
+ type: dropId === addingEdge.source ? 'loop-edge' : edgeConfig.type,
229
+ },
230
+ });
231
+ if (createActualEventName) {
232
+ graph.emit(createActualEventName, { edge: actualEdge });
233
+ }
234
+ this.cancelCreating();
235
+ };
236
+
237
+ updateEndPoint = (e: IG6GraphEvent) => {
238
+ const { options, graph, addingEdge, isKeyDown } = this;
239
+ if (options.secondaryKey && !isKeyDown) {
240
+ return;
241
+ }
242
+
243
+ if (!addingEdge) {
244
+ return;
245
+ }
246
+
247
+ const sourceId = addingEdge.source,
248
+ targetId = addingEdge.target;
249
+
250
+ if (!graph.getItemById(sourceId)) {
251
+ this.addingEdge = null;
252
+ return;
253
+ }
254
+
255
+ graph.updatePosition('node', {
256
+ id: targetId,
257
+ data: {
258
+ x: e.canvas.x,
259
+ y: e.canvas.y,
260
+ },
261
+ });
262
+ };
263
+
264
+ cancelCreating = () => {
265
+ if (this.addingEdge) {
266
+ this.graph.removeData('edge', VIRTUAL_EDGE_ID);
267
+ this.addingEdge = null;
268
+ }
269
+ if (this.dummyNode) {
270
+ this.graph.removeData('node', DUMMY_NODE_ID);
271
+ this.dummyNode = null;
272
+ }
273
+ if (this.options.cancelCreateEventName) {
274
+ this.graph.emit(this.options.cancelCreateEventName, {});
275
+ }
276
+ };
277
+
278
+ onKeyDown = (e: KeyboardEvent) => {
279
+ const code = e.key;
280
+
281
+ if (!code) {
282
+ return;
283
+ }
284
+
285
+ if (code.toLocaleLowerCase() === this.options.secondaryKey) {
286
+ this.isKeyDown = true;
287
+ }
288
+ };
289
+
290
+ onKeyUp = (e: IG6GraphEvent) => {
291
+ if (this.addingEdge) {
292
+ this.cancelCreating();
293
+ }
294
+ this.isKeyDown = false;
295
+ };
296
+ }
@@ -1,7 +1,7 @@
1
- import { ID, IG6GraphEvent } from 'types';
1
+ import { isNumber } from '@antv/util';
2
+ import { ID, IG6GraphEvent } from '../../types';
2
3
  import { Behavior } from '../../types/behavior';
3
4
  import { Point } from '../../types/common';
4
- import { isNumber } from '@antv/util';
5
5
 
6
6
  const VALID_TRIGGERS = ['drag', 'directionKeys'];
7
7
  export interface DragCanvasOptions {
@@ -74,6 +74,7 @@ export class DragCanvas extends Behavior {
74
74
  private disableKeydown: boolean;
75
75
  private hiddenEdgeIds: ID[];
76
76
  private hiddenNodeIds: ID[];
77
+ private tileRequestId?: number;
77
78
 
78
79
  constructor(options: Partial<DragCanvasOptions>) {
79
80
  const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
@@ -136,7 +137,10 @@ export class DragCanvas extends Behavior {
136
137
 
137
138
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
138
139
  graph.getSpecification().optimize || {};
139
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
140
+ const optimize =
141
+ this.options.enableOptimize !== undefined
142
+ ? this.options.enableOptimize
143
+ : graphBehaviorOptimize;
140
144
  const shouldOptimize = isNumber(optimize)
141
145
  ? graph.getAllNodesData().length > optimize
142
146
  : optimize;
@@ -150,7 +154,6 @@ export class DragCanvas extends Behavior {
150
154
  .getAllNodesData()
151
155
  .map((node) => node.id)
152
156
  .filter((id) => graph.getItemVisible(id) === true);
153
- let requestId;
154
157
  const hiddenIds = [...this.hiddenNodeIds];
155
158
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
156
159
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -160,17 +163,18 @@ export class DragCanvas extends Behavior {
160
163
  ),
161
164
  );
162
165
  const update = () => {
163
- if (!sections.length) {
164
- cancelAnimationFrame(requestId);
166
+ if (!sections.length && this.tileRequestId) {
167
+ cancelAnimationFrame(this.tileRequestId);
168
+ this.tileRequestId = undefined;
165
169
  return;
166
170
  }
167
171
  const section = sections.shift();
168
- graph.hideItem(section, false, true);
169
- requestId = requestAnimationFrame(update);
172
+ graph.executeWithNoStack(() => {
173
+ graph.hideItem(section, false, true);
174
+ });
175
+ this.tileRequestId = requestAnimationFrame(update);
170
176
  };
171
- graph.executeWithNoStack(() => {
172
- requestId = requestAnimationFrame(update);
173
- });
177
+ this.tileRequestId = requestAnimationFrame(update);
174
178
  }
175
179
  }
176
180
 
@@ -264,14 +268,20 @@ export class DragCanvas extends Behavior {
264
268
  const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
265
269
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
266
270
  graph.getSpecification().optimize || {};
267
- const optimize = this.options.enableOptimize || graphBehaviorOptimize;
271
+ const optimize =
272
+ this.options.enableOptimize !== undefined
273
+ ? this.options.enableOptimize
274
+ : graphBehaviorOptimize;
268
275
  const shouldOptimize = isNumber(optimize)
269
276
  ? graph.getAllNodesData().length > optimize
270
277
  : optimize;
271
278
 
272
279
  if (shouldOptimize) {
280
+ if (this.tileRequestId) {
281
+ cancelAnimationFrame(this.tileRequestId);
282
+ this.tileRequestId = undefined;
283
+ }
273
284
  if (hiddenNodeIds) {
274
- let requestId;
275
285
  const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
276
286
  const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
277
287
  const sections = Array.from({ length: sectionNum }, (v, i) =>
@@ -281,16 +291,17 @@ export class DragCanvas extends Behavior {
281
291
  ),
282
292
  );
283
293
  const update = () => {
284
- if (!sections.length) {
285
- cancelAnimationFrame(requestId);
294
+ if (!sections.length && this.tileRequestId) {
295
+ cancelAnimationFrame(this.tileRequestId);
296
+ this.tileRequestId = undefined;
286
297
  return;
287
298
  }
299
+ graph.startHistoryBatch();
288
300
  graph.showItem(sections.shift(), false);
289
- requestId = requestAnimationFrame(update);
301
+ graph.stopHistoryBatch();
302
+ this.tileRequestId = requestAnimationFrame(update);
290
303
  };
291
- graph.startHistoryBatch();
292
- requestId = requestAnimationFrame(update);
293
- graph.stopHistoryBatch();
304
+ this.tileRequestId = requestAnimationFrame(update);
294
305
  }
295
306
  }
296
307
  }
@@ -526,8 +526,8 @@ export class DragCombo extends Behavior {
526
526
  this.originPositions = [];
527
527
  }
528
528
 
529
- public onDropNode(event: IG6GraphEvent) {
530
- const elements = this.graph.canvas.document.elementsFromPointSync(
529
+ public async onDropNode(event: IG6GraphEvent) {
530
+ const elements = await this.graph.canvas.document.elementsFromPoint(
531
531
  event.canvas.x,
532
532
  event.canvas.y,
533
533
  );
@@ -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,7 +472,7 @@ 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
  }
@@ -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
  );
@@ -640,8 +640,8 @@ export class DragNode extends Behavior {
640
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
  );
@@ -13,4 +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';
16
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) {