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}