From 0bd1780589219e3e1c92aa810852b822a313fcb6 Mon Sep 17 00:00:00 2001 From: lashman Date: Mon, 16 Nov 2026 19:36:58 +0200 Subject: [PATCH] show where a dragged column will land a white line in the gap, following the same rule as the drop --- src/components/board/BoardView.tsx | 58 +++++++++++++++++++++++++-- src/components/board/KanbanColumn.tsx | 1 + 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/components/board/BoardView.tsx b/src/components/board/BoardView.tsx index f11537f..6bc06b9 100644 --- a/src/components/board/BoardView.tsx +++ b/src/components/board/BoardView.tsx @@ -200,10 +200,13 @@ export function BoardView() { // Debounce cross-column moves to prevent oscillation crashes const lastCrossColumnMoveRef = useRef(0); + const rowRef = useRef(null); + const [columnMarker, setColumnMarker] = useState<{ left: number; top: number; height: number } | null>(null); const clearDragState = useCallback(() => { setActiveId(null); setActiveType(null); + setColumnMarker(null); lastCrossColumnMoveRef.current = 0; }, []); @@ -215,17 +218,48 @@ export function BoardView() { lastCrossColumnMoveRef.current = 0; }, []); + // where a dragged column would land, measured inside the columns row + const columnDropMarker = useCallback( + (board: Board, activeId: string, over: DragOverEvent["over"]) => { + if (!over) return null; + // the card list inside a column is a droppable of its own, so over.id can be a prefixed id + const overColumnId = String(over.data.current?.columnId ?? over.id); + + const fromIndex = board.columns.findIndex((c) => c.id === activeId); + const toIndex = board.columns.findIndex((c) => c.id === overColumnId); + const row = rowRef.current; + if (!row || fromIndex === -1 || toIndex === -1 || fromIndex === toIndex) return null; + + const target = row.querySelector(`[data-column-id="${overColumnId}"]`); + if (!target) return null; + + // dropping to the right lands after the target, dropping to the left lands before it + const gap = parseFloat(getComputedStyle(row).columnGap) || 0; + const left = + fromIndex < toIndex + ? target.offsetLeft + target.offsetWidth + gap / 2 + : target.offsetLeft - gap / 2; + + return { left, top: target.offsetTop, height: target.offsetHeight }; + }, + [] + ); + const handleDragOver = useCallback( (event: DragOverEvent) => { const { active, over } = event; - if (!over) return; // Always read fresh state to avoid stale-closure bugs const currentBoard = useBoardStore.getState().board; if (!currentBoard) return; const activeType = active.data.current?.type; + if (activeType === "column") { + setColumnMarker(columnDropMarker(currentBoard, active.id as string, over)); + return; + } if (activeType !== "card") return; + if (!over) return; const activeCardId = active.id as string; const overId = over.id as string; @@ -265,7 +299,7 @@ export function BoardView() { moveCard(activeCardId, activeColumn.id, overColumn.id, overIndex); }, - [moveCard] + [moveCard, columnDropMarker] ); const handleDragEnd = useCallback( @@ -427,12 +461,30 @@ export function BoardView() { defer > + {columnMarker && ( + + )} {board.columns.map((column) => ( {column.collapsed ? (