your personal website on atproto - mirror blento.app

commit (working version)

Florian 7ac0af09 5399f15e

+37 -13
+13 -11
src/lib/layout.ts
··· 66 66 items: Item[], 67 67 item: Item, 68 68 mobile: boolean = false, 69 - skipCompact: boolean = false 69 + skipCompact: boolean = false, 70 + originalPos?: { x: number; y: number } 70 71 ) { 71 72 if (mobile) item.mobileX = clamp(item.mobileX, 0, COLUMNS - item.mobileW); 72 73 else item.x = clamp(item.x, 0, COLUMNS - item.w); 74 + 75 + const targetX = mobile ? item.mobileX : item.x; 76 + const targetY = mobile ? item.mobileY : item.y; 73 77 74 78 let layout = toLayout(items, mobile); 75 79 ··· 80 84 return; 81 85 } 82 86 83 - layout = moveElement( 84 - layout, 85 - movedLayoutItem, 86 - movedLayoutItem.x, 87 - movedLayoutItem.y, 88 - true, 89 - false, 90 - 'vertical', 91 - COLUMNS 92 - ); 87 + // If we know the original position, set it on the layout item so 88 + // moveElement can detect direction and push items properly. 89 + if (originalPos) { 90 + movedLayoutItem.x = originalPos.x; 91 + movedLayoutItem.y = originalPos.y; 92 + } 93 + 94 + layout = moveElement(layout, movedLayoutItem, targetX, targetY, true, false, 'vertical', COLUMNS); 93 95 94 96 if (!skipCompact) layout = verticalCompactor.compact(layout, COLUMNS) as LayoutItem[]; 95 97
+24 -2
src/lib/website/EditableWebsite.svelte
··· 829 829 } 830 830 } 831 831 832 - fixCollisions(items, activeDragElement.item, isMobile); 832 + fixCollisions( 833 + items, 834 + activeDragElement.item, 835 + isMobile, 836 + false, 837 + draggedOrigPos 838 + ? { 839 + x: isMobile ? draggedOrigPos.mobileX : draggedOrigPos.x, 840 + y: isMobile ? draggedOrigPos.mobileY : draggedOrigPos.y 841 + } 842 + : undefined 843 + ); 833 844 } 834 845 835 846 function touchEnd() { ··· 1376 1387 } 1377 1388 1378 1389 // Now fix collisions (with compacting) 1379 - fixCollisions(items, activeDragElement.item, isMobile); 1390 + fixCollisions( 1391 + items, 1392 + activeDragElement.item, 1393 + isMobile, 1394 + false, 1395 + draggedOrigPos 1396 + ? { 1397 + x: isMobile ? draggedOrigPos.mobileX : draggedOrigPos.x, 1398 + y: isMobile ? draggedOrigPos.mobileY : draggedOrigPos.y 1399 + } 1400 + : undefined 1401 + ); 1380 1402 } 1381 1403 }} 1382 1404 ondragend={async (e) => {