show where a dragged column will land
a white line in the gap, following the same rule as the drop
This commit is contained in:
@@ -200,10 +200,13 @@ export function BoardView() {
|
||||
|
||||
// Debounce cross-column moves to prevent oscillation crashes
|
||||
const lastCrossColumnMoveRef = useRef<number>(0);
|
||||
const rowRef = useRef<HTMLDivElement>(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<HTMLElement>(`[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
|
||||
>
|
||||
<motion.div
|
||||
className="flex h-full"
|
||||
ref={rowRef}
|
||||
className="relative flex h-full"
|
||||
style={{ gap: `calc(1.5rem * var(--density-factor))`, padding: `calc(1.5rem * var(--density-factor))`, ...getBoardBackground(board) }}
|
||||
variants={staggerContainer(0.06)}
|
||||
initial="hidden"
|
||||
animate="visible"
|
||||
>
|
||||
{columnMarker && (
|
||||
<motion.div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute z-10 w-[3px] rounded-full bg-white transition-[left,top,height] duration-150 ease-out"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ duration: 0.12 }}
|
||||
style={{
|
||||
left: columnMarker.left,
|
||||
top: columnMarker.top,
|
||||
height: columnMarker.height,
|
||||
marginLeft: -1.5,
|
||||
// white glow, with a faint dark edge so the line still shows on the light theme
|
||||
boxShadow: "0 0 10px oklch(100% 0 0 / 60%), 0 0 2px oklch(0% 0 0 / 25%)",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<AnimatePresence>
|
||||
{board.columns.map((column) => (
|
||||
<KanbanColumn
|
||||
|
||||
@@ -89,6 +89,7 @@ export function KanbanColumn({ column, filteredCardIds, focusedCardId, onCardCli
|
||||
exit={{ width: 0, opacity: 0 }}
|
||||
transition={springs.bouncy}
|
||||
className="shrink-0 overflow-hidden"
|
||||
data-column-id={column.id}
|
||||
{...attributes}
|
||||
>
|
||||
{column.collapsed ? (
|
||||
|
||||
Reference in New Issue
Block a user