Improves drag cancellation behavior
Implements drag cancellation when the mouse leaves the calendar container during a drag operation. This prevents orphaned drag clones and restores the original event's state, enhancing user experience. All-day events now correctly recalculate their height upon drag cancellation, ensuring accurate rendering after clone removal. Refactors HeaderManager by removing redundant caching of the calendar header element. Adds new mock event data for September and October 2025 to expand testing and demonstration scenarios.
This commit is contained in:
parent
35651be2f0
commit
134ee29cb1
4 changed files with 531 additions and 16 deletions
|
|
@ -62,6 +62,7 @@ export class DragDropManager {
|
|||
// Column bounds cache for coordinate-based column detection
|
||||
private columnBoundsCache: ColumnBounds[] = [];
|
||||
|
||||
|
||||
// Auto-scroll properties
|
||||
private autoScrollAnimationId: number | null = null;
|
||||
private readonly scrollSpeed = 10; // pixels per frame
|
||||
|
|
@ -108,6 +109,16 @@ export class DragDropManager {
|
|||
document.body.addEventListener('mousedown', this.boundHandlers.mouseDown);
|
||||
document.body.addEventListener('mouseup', this.boundHandlers.mouseUp);
|
||||
|
||||
// Add mouseleave listener to calendar container for drag cancellation
|
||||
const calendarContainer = document.querySelector('swp-calendar-container');
|
||||
if (calendarContainer) {
|
||||
calendarContainer.addEventListener('mouseleave', () => {
|
||||
if (this.draggedElement && this.isDragStarted) {
|
||||
this.cancelDrag();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize column bounds cache
|
||||
this.updateColumnBoundsCache();
|
||||
|
||||
|
|
@ -303,7 +314,41 @@ export class DragDropManager {
|
|||
private cleanupAllClones(): void {
|
||||
// Remove clones from all possible locations
|
||||
const allClones = document.querySelectorAll('[data-event-id^="clone"]');
|
||||
allClones.forEach(clone => clone.remove());
|
||||
|
||||
if (allClones.length > 0) {
|
||||
console.log(`🧹 DragDropManager: Removing ${allClones.length} clone(s)`);
|
||||
allClones.forEach(clone => clone.remove());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel drag operation when mouse leaves grid container
|
||||
*/
|
||||
private cancelDrag(): void {
|
||||
if (!this.draggedElement) return;
|
||||
|
||||
console.log('🚫 DragDropManager: Cancelling drag - mouse left grid container');
|
||||
|
||||
const draggedElement = this.draggedElement;
|
||||
|
||||
// 1. Remove all clones
|
||||
this.cleanupAllClones();
|
||||
|
||||
// 2. Restore original element
|
||||
if (draggedElement) {
|
||||
draggedElement.style.opacity = '';
|
||||
draggedElement.style.cursor = '';
|
||||
}
|
||||
|
||||
// 3. Emit cancellation event
|
||||
this.eventBus.emit('drag:cancelled', {
|
||||
draggedElement: draggedElement,
|
||||
reason: 'mouse-left-grid'
|
||||
});
|
||||
|
||||
// 4. Clean up state
|
||||
this.cleanupDragState();
|
||||
this.stopAutoScroll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue