From 7ac0af090c6c64580f58196c61fc1f3e6292064d Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Thu, 5 Feb 2026 00:45:25 +0100 Subject: [PATCH] commit (working version) --- src/lib/layout.ts | 24 +++++++++++++----------- src/lib/website/EditableWebsite.svelte | 26 ++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/lib/layout.ts b/src/lib/layout.ts index 155f0f1..c8ff5f2 100644 --- a/src/lib/layout.ts +++ b/src/lib/layout.ts @@ -66,11 +66,15 @@ export function fixCollisions( items: Item[], item: Item, mobile: boolean = false, - skipCompact: boolean = false + skipCompact: boolean = false, + originalPos?: { x: number; y: number } ) { if (mobile) item.mobileX = clamp(item.mobileX, 0, COLUMNS - item.mobileW); else item.x = clamp(item.x, 0, COLUMNS - item.w); + const targetX = mobile ? item.mobileX : item.x; + const targetY = mobile ? item.mobileY : item.y; + let layout = toLayout(items, mobile); const movedLayoutItem = layout.find((i) => i.i === item.id); @@ -80,16 +84,14 @@ export function fixCollisions( return; } - layout = moveElement( - layout, - movedLayoutItem, - movedLayoutItem.x, - movedLayoutItem.y, - true, - false, - 'vertical', - COLUMNS - ); + // If we know the original position, set it on the layout item so + // moveElement can detect direction and push items properly. + if (originalPos) { + movedLayoutItem.x = originalPos.x; + movedLayoutItem.y = originalPos.y; + } + + layout = moveElement(layout, movedLayoutItem, targetX, targetY, true, false, 'vertical', COLUMNS); if (!skipCompact) layout = verticalCompactor.compact(layout, COLUMNS) as LayoutItem[]; diff --git a/src/lib/website/EditableWebsite.svelte b/src/lib/website/EditableWebsite.svelte index 6375b33..dfcbe48 100644 --- a/src/lib/website/EditableWebsite.svelte +++ b/src/lib/website/EditableWebsite.svelte @@ -829,7 +829,18 @@ } } - fixCollisions(items, activeDragElement.item, isMobile); + fixCollisions( + items, + activeDragElement.item, + isMobile, + false, + draggedOrigPos + ? { + x: isMobile ? draggedOrigPos.mobileX : draggedOrigPos.x, + y: isMobile ? draggedOrigPos.mobileY : draggedOrigPos.y + } + : undefined + ); } function touchEnd() { @@ -1376,7 +1387,18 @@ } // Now fix collisions (with compacting) - fixCollisions(items, activeDragElement.item, isMobile); + fixCollisions( + items, + activeDragElement.item, + isMobile, + false, + draggedOrigPos + ? { + x: isMobile ? draggedOrigPos.mobileX : draggedOrigPos.x, + y: isMobile ? draggedOrigPos.mobileY : draggedOrigPos.y + } + : undefined + ); } }} ondragend={async (e) => { -- 2.51.2