Refactors event drag-drop and cloning logic

Centralizes drag event listener setup in `EventRendererManager` for better separation of concerns.

Introduces factory and cloning methods in `SwpEventElement` to simplify event cloning and data extraction from DOM elements during drag operations.

Enhances `DragDropManager` to pass the actual dragged element for conversion and accurately detect the drop target (day column or header).

Updates `EventRenderer` to expose drag-handling methods publicly, allowing the `EventRendererManager` to delegate event-specific drag operations based on drop target.
This commit is contained in:
Janus C. H. Knudsen 2025-09-20 09:40:56 +02:00
parent 0b7499521e
commit b4f5b29da3
6 changed files with 357 additions and 304 deletions

View file

@ -44,22 +44,15 @@ export class HeaderManager {
* Setup header drag event listeners - REFACTORED to use mouseenter
*/
public setupHeaderDragListeners(): void {
const calendarHeader = this.getCalendarHeader();
if (!calendarHeader) return;
if (!this.getCalendarHeader()) return;
console.log('🎯 HeaderManager: Setting up drag listeners with mouseenter');
// Track last processed date to avoid duplicates
let lastProcessedDate: string | null = null;
let lastProcessedTime = 0;
// Use mouseenter instead of mouseover to avoid continuous firing
this.headerEventListener = (event: Event) => {
// OPTIMIZED: Check for active drag operation FIRST before doing any other work
const isDragActive = document.querySelector('.dragging') !== null;
if (!isDragActive) {
// Ingen drag operation, spring resten af funktionen over
if (!document.querySelector('.dragging') !== null) {
return;
}
@ -114,9 +107,8 @@ export class HeaderManager {
});
};
// Use mouseenter with capture to catch events early
calendarHeader.addEventListener('mouseenter', this.headerEventListener, true);
calendarHeader.addEventListener('mouseleave', this.headerMouseLeaveListener);
this.getCalendarHeader()?.addEventListener('mouseenter', this.headerEventListener, true);
this.getCalendarHeader()?.addEventListener('mouseleave', this.headerMouseLeaveListener);
console.log('✅ HeaderManager: Event listeners attached (mouseenter + mouseleave)');
}