This commit is contained in:
Janus C. H. Knudsen 2025-12-11 21:16:40 +01:00
parent 1a4c22d37f
commit 9e568fbd8e
4 changed files with 23 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import { DateService } from '../../core/DateService';
import { IGridConfig } from '../../core/IGridConfig';
import { calculateEventPosition, snapToGrid, pixelsToMinutes } from '../../utils/PositionUtils';
import { CoreEvents } from '../../constants/CoreEvents';
import { IDragColumnChangePayload, IDragMovePayload } from '../../types/DragTypes';
import { IDragColumnChangePayload, IDragMovePayload, IDragEndPayload } from '../../types/DragTypes';
import { calculateColumnLayout } from './EventLayoutEngine';
import { IGridGroupLayout } from './EventLayoutTypes';
@ -46,6 +46,22 @@ export class EventRenderer {
const payload = (e as CustomEvent<IEventUpdatedPayload>).detail;
this.handleEventUpdated(payload);
});
this.eventBus.on(CoreEvents.EVENT_DRAG_END, (e) => {
const payload = (e as CustomEvent<IDragEndPayload>).detail;
this.handleDragEnd(payload);
});
}
/**
* Handle EVENT_DRAG_END - remove element if dropped in header
*/
private handleDragEnd(payload: IDragEndPayload): void {
if (payload.target === 'header') {
// Event was dropped in header drawer - remove from grid
const element = this.container?.querySelector(`swp-content-viewport swp-event[data-event-id="${payload.eventId}"]`);
element?.remove();
}
}
/**

View file

@ -128,6 +128,8 @@ export class HeaderDrawerRenderer {
/**
* Handle drag end - finalize the item (it stays in header)
* Note: EventRenderer handles removing the original element from the grid
* via EVENT_DRAG_END with target === 'header'
*/
private handleDragEnd(): void {
if (!this.currentItem) return;
@ -135,10 +137,9 @@ export class HeaderDrawerRenderer {
// Remove dragging state
this.currentItem.classList.remove('dragging');
// Item stays - it's now permanent
// TODO: Emit event to persist allDay=true change
// Clear references but leave item in DOM
// Clear references
this.currentItem = null;
this.sourceElement = null;
}

View file

@ -159,7 +159,8 @@ export class DragDropManager {
dateKey,
resourceId,
sourceDateKey: this.dragState.sourceDateKey,
sourceResourceId: this.dragState.sourceResourceId
sourceResourceId: this.dragState.sourceResourceId,
target: this.inHeader ? 'header' : 'grid'
};
this.eventBus.emit(CoreEvents.EVENT_DRAG_END, payload);

View file

@ -32,6 +32,7 @@ export interface IDragEndPayload {
resourceId?: string; // Target column resource (resource mode)
sourceDateKey: string; // Source column date (where drag started)
sourceResourceId?: string; // Source column resource (where drag started)
target: 'grid' | 'header'; // Where the event was dropped
}
export interface IDragCancelPayload {