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

Class DragElement

src/editor/interactions/drag-element.ts:44–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42type GuideCandidates = { vertical: number[]; horizontal: number[] };
43
44export class DragElement extends Interaction implements IInteraction {
45 name = 'drag-element';
46
47 private pointerId?: number;
48 private startPoint?: DOMPoint;
49 private startTarget?: Selection[number];
50 private selectionForDrag: Selection = [];
51 private willReplaceSelection = false;
52 private exclusiveStarted = false;
53 private dragItems: DragItem[] = [];
54 private dragging = false;
55 private dragThreshold = 4;
56 private completeInteraction?: () => void;
57 private guideCandidates?: GuideCandidates;
58 private startBounds?: Bounds;
59 private guideVertical?: SVGLineElement;
60 private guideHorizontal?: SVGLineElement;
61
62 init(options: InteractionInitOptions) {
63 super.init(options);
64 this.editor.getDocument().addEventListener('pointerdown', this.handleStart);
65 }
66
67 destroy() {
68 this.detachPointerListeners();
69 this.editor
70 .getDocument()
71 .removeEventListener('pointerdown', this.handleStart);
72 }
73
74 private handleStart = (event: PointerEvent) => {
75 if (!this.interaction.isActive()) return;
76 if (event.pointerType === 'mouse' && event.button !== 0) return;
77
78 const target = getEventTarget(event.target as SVGElement);
79 if (!target) return;
80 if (isEditingText(target)) return;
81
82 const svg = this.editor.getDocument();
83 this.pointerId = event.pointerId;
84 this.startPoint = clientToViewport(svg, event.clientX, event.clientY);
85 this.dragging = false;
86 this.startTarget = target;
87 const isSelected = this.interaction.isSelected(target);
88 this.selectionForDrag = isSelected
89 ? this.interaction.getSelection()
90 : [target];
91 this.willReplaceSelection = !isSelected;
92 this.exclusiveStarted = false;
93 this.startBounds = this.getSelectionBounds(this.selectionForDrag);
94 this.guideCandidates = this.collectGuideCandidates(this.selectionForDrag);
95
96 window.addEventListener('pointermove', this.handleMove);
97 window.addEventListener('pointerup', this.handleEnd);
98 window.addEventListener('pointercancel', this.handleEnd);
99 };
100
101 private handleMove = (event: PointerEvent) => {

Callers

nothing calls this directly

Calls 15

getSelectionBoundsMethod · 0.95
startDragMethod · 0.95
resetMethod · 0.95
getSnappedDeltaMethod · 0.95
updateGuidesMethod · 0.95
applyTranslationMethod · 0.95
emitGeometryChangeMethod · 0.95
commitTranslationMethod · 0.95
getEventTargetFunction · 0.90
isEditingTextFunction · 0.90

Tested by

no test coverage detected