Moves drag:move emission to animation loop

Ensures drag:move events are emitted during the animation loop
for smoother and more consistent updates during drag operations.
Removes redundant emission from the main drag handling logic.
This commit is contained in:
Janus C. H. Knudsen 2025-10-11 01:38:15 +02:00
parent 9b073a15b7
commit 0764437642

View file

@ -298,19 +298,6 @@ export class DragDropManager {
this.currentY = parseFloat(this.draggedClone!.style.top) || 0; this.currentY = parseFloat(this.draggedClone!.style.top) || 0;
this.animateDrag(); this.animateDrag();
} }
// Emit drag:move event with current draggedClone reference
if (this.draggedClone) {
const dragMovePayload: DragMoveEventPayload = {
draggedElement: this.draggedElement!,
draggedClone: this.draggedClone,
mousePosition: currentPosition,
snappedY: this.currentY,
columnBounds: column,
mouseOffset: this.mouseOffset
};
this.eventBus.emit('drag:move', dragMovePayload);
}
} }
// Check for auto-scroll // Check for auto-scroll
@ -478,7 +465,7 @@ export class DragDropManager {
/** /**
* Smooth drag animation using requestAnimationFrame * Smooth drag animation using requestAnimationFrame
* Only interpolates currentY - events are emitted from continueDrag() * Emits drag:move events with current draggedClone reference on each frame
*/ */
private animateDrag(): void { private animateDrag(): void {
if (!this.isDragStarted || !this.draggedClone || !this.targetColumn) { if (!this.isDragStarted || !this.draggedClone || !this.targetColumn) {
@ -493,10 +480,34 @@ export class DragDropManager {
// Update if difference is significant // Update if difference is significant
if (Math.abs(diff) > 0.5) { if (Math.abs(diff) > 0.5) {
this.currentY += step; this.currentY += step;
// Emit drag:move event with current draggedClone reference
const dragMovePayload: DragMoveEventPayload = {
draggedElement: this.draggedElement!,
draggedClone: this.draggedClone, // Always uses current reference
mousePosition: this.lastMousePosition,
snappedY: this.currentY,
columnBounds: this.targetColumn,
mouseOffset: this.mouseOffset
};
this.eventBus.emit('drag:move', dragMovePayload);
this.dragAnimationId = requestAnimationFrame(() => this.animateDrag()); this.dragAnimationId = requestAnimationFrame(() => this.animateDrag());
} else { } else {
// Close enough - snap to target // Close enough - snap to target
this.currentY = this.targetY; this.currentY = this.targetY;
// Emit final position
const dragMovePayload: DragMoveEventPayload = {
draggedElement: this.draggedElement!,
draggedClone: this.draggedClone,
mousePosition: this.lastMousePosition,
snappedY: this.currentY,
columnBounds: this.targetColumn,
mouseOffset: this.mouseOffset
};
this.eventBus.emit('drag:move', dragMovePayload);
this.dragAnimationId = null; this.dragAnimationId = null;
} }
} }