MCPcopy
hub / github.com/antvis/Infographic / DragCanvas

Class DragCanvas

src/editor/interactions/drag-canvas.ts:12–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12export class DragCanvas extends Interaction implements IInteraction {
13 name = 'drag-canvas';
14
15 /**
16 * 触发交互的按键代码。
17 * 参考标准的 KeyboardEvent.code 值:
18 * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
19 * @default ['Space']
20 */
21 public trigger: KeyCode[] = ['Space'];
22
23 constructor(options?: DragCanvasOptions) {
24 super();
25 if (options?.trigger) {
26 this.trigger = options.trigger;
27 }
28 }
29
30 private isTriggerPressed = false;
31
32 private pointerId?: number;
33 private startPoint?: DOMPoint;
34
35 private document!: SVGSVGElement;
36
37 private startViewBoxString?: string;
38
39 private completeInteraction?: () => void;
40
41 // 防止组件快捷键侵入性过强
42 private isHovering = false;
43
44 init(options: InteractionInitOptions): void {
45 super.init(options);
46 this.document = this.editor.getDocument();
47
48 this.document.addEventListener('mouseenter', this.onMouseEnter);
49 this.document.addEventListener('mouseleave', this.onMouseLeave);
50 window.addEventListener('keydown', this.handleKeyDown);
51 window.addEventListener('blur', this.handleBlur);
52 }
53
54 destroy(): void {
55 window.removeEventListener('keydown', this.handleKeyDown);
56 window.removeEventListener('keyup', this.handleKeyUp);
57
58 this.document.removeEventListener('pointerdown', this.handlePointerDown);
59 window.removeEventListener('pointermove', this.handlePointerMove);
60 window.removeEventListener('pointerup', this.handlePointerUp);
61 window.removeEventListener('pointercancel', this.handlePointerUp);
62
63 window.removeEventListener('blur', this.handleBlur);
64 this.document.removeEventListener('mouseenter', this.onMouseEnter);
65 this.document.removeEventListener('mouseleave', this.onMouseLeave);
66 }
67
68 private handleKeyDown = (event: KeyboardEvent) => {
69 if (!this.interaction.isActive()) return;

Callers

nothing calls this directly

Calls 8

isTextSelectionTargetFunction · 0.90
getViewBoxFunction · 0.90
viewBoxToStringFunction · 0.90
clientToViewportFunction · 0.90
isActiveMethod · 0.65
updateOptionsMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected