From 15a993ecc6ebd4dc005303e3fa2f45a8fa9143ed Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Fri, 22 May 2026 14:23:19 +0200 Subject: [PATCH] Drag-and-drop waypoint reordering in sidebar list --- src/Planner.svelte | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Planner.svelte b/src/Planner.svelte index 4554d04..6e9f6b3 100644 --- a/src/Planner.svelte +++ b/src/Planner.svelte @@ -391,6 +391,40 @@ fetchRoute(); } + let dragSrcIdx = $state(null); + let dragOverIdx = $state(null); + + function onDragStart(e, i) { + dragSrcIdx = i; + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('text/plain', i); + } + + function onDragOver(e, i) { + e.preventDefault(); + e.dataTransfer.dropEffect = 'move'; + dragOverIdx = i; + } + + function onDrop(e, i) { + e.preventDefault(); + if (dragSrcIdx === null || dragSrcIdx === i) { dragSrcIdx = null; dragOverIdx = null; return; } + const arr = [...waypoints]; + const [moved] = arr.splice(dragSrcIdx, 1); + arr.splice(i, 0, moved); + waypoints = arr; + waypoints.forEach((wp, idx) => { wp.marker.getElement().textContent = idx + 1; }); + activePlanId = null; + fetchRoute(); + dragSrcIdx = null; + dragOverIdx = null; + } + + function onDragEnd() { + dragSrcIdx = null; + dragOverIdx = null; + } + function removeWaypoint(i) { waypoints[i].marker.remove(); waypoints = waypoints.filter((_, idx) => idx !== i); @@ -1094,7 +1128,16 @@ ${trkpts} {:else}