Improves drag-and-drop event positioning logic
Refactors element positioning during drag operations to: - Use getBoundingClientRect for precise Y positioning - Move events to events-layer for consistent dragging - Ensure proper absolute positioning across different event layouts Addresses positioning inconsistencies for grouped and stacked events
This commit is contained in:
parent
70172e8f10
commit
1a4c22d37f
1 changed files with 21 additions and 2 deletions
|
|
@ -175,7 +175,27 @@ export class DragDropManager {
|
||||||
const columnElement = element.closest('swp-day-column') as HTMLElement;
|
const columnElement = element.closest('swp-day-column') as HTMLElement;
|
||||||
|
|
||||||
if (!columnElement) return;
|
if (!columnElement) return;
|
||||||
const startY = parseFloat(element.style.top) || 0;
|
|
||||||
|
// Calculate absolute Y position using getBoundingClientRect
|
||||||
|
const elementRect = element.getBoundingClientRect();
|
||||||
|
const columnRect = columnElement.getBoundingClientRect();
|
||||||
|
const startY = elementRect.top - columnRect.top;
|
||||||
|
|
||||||
|
// If event is inside a group, move it to events-layer for correct positioning during drag
|
||||||
|
const group = element.closest('swp-event-group');
|
||||||
|
if (group) {
|
||||||
|
const eventsLayer = columnElement.querySelector('swp-events-layer');
|
||||||
|
if (eventsLayer) {
|
||||||
|
eventsLayer.appendChild(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set consistent positioning for drag (works for both grouped and stacked events)
|
||||||
|
element.style.position = 'absolute';
|
||||||
|
element.style.top = `${startY}px`;
|
||||||
|
element.style.left = '2px';
|
||||||
|
element.style.right = '2px';
|
||||||
|
element.style.marginLeft = '0'; // Reset stacking margin
|
||||||
|
|
||||||
// Create ghost clone
|
// Create ghost clone
|
||||||
const ghostElement = element.cloneNode(true) as HTMLElement;
|
const ghostElement = element.cloneNode(true) as HTMLElement;
|
||||||
|
|
@ -190,7 +210,6 @@ export class DragDropManager {
|
||||||
element.classList.add('dragging');
|
element.classList.add('dragging');
|
||||||
|
|
||||||
// Calculate initial target from mouse position
|
// Calculate initial target from mouse position
|
||||||
const columnRect = columnElement.getBoundingClientRect();
|
|
||||||
const targetY = e.clientY - columnRect.top - mouseOffset.y;
|
const targetY = e.clientY - columnRect.top - mouseOffset.y;
|
||||||
|
|
||||||
// Initialize drag state
|
// Initialize drag state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue