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
|
// Debounce cross-column moves to prevent oscillation crashes
|
||||||
const lastCrossColumnMoveRef = useRef<number>(0);
|
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(() => {
|
const clearDragState = useCallback(() => {
|
||||||
setActiveId(null);
|
setActiveId(null);
|
||||||
setActiveType(null);
|
setActiveType(null);
|
||||||
|
setColumnMarker(null);
|
||||||
lastCrossColumnMoveRef.current = 0;
|
lastCrossColumnMoveRef.current = 0;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -215,17 +218,48 @@ export function BoardView() {
|
|||||||
lastCrossColumnMoveRef.current = 0;
|
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(
|
const handleDragOver = useCallback(
|
||||||
(event: DragOverEvent) => {
|
(event: DragOverEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
if (!over) return;
|
|
||||||
|
|
||||||
// Always read fresh state to avoid stale-closure bugs
|
// Always read fresh state to avoid stale-closure bugs
|
||||||
const currentBoard = useBoardStore.getState().board;
|
const currentBoard = useBoardStore.getState().board;
|
||||||
if (!currentBoard) return;
|
if (!currentBoard) return;
|
||||||
|
|
||||||
const activeType = active.data.current?.type;
|
const activeType = active.data.current?.type;
|
||||||
|
if (activeType === "column") {
|
||||||
|
setColumnMarker(columnDropMarker(currentBoard, active.id as string, over));
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (activeType !== "card") return;
|
if (activeType !== "card") return;
|
||||||
|
if (!over) return;
|
||||||
|
|
||||||
const activeCardId = active.id as string;
|
const activeCardId = active.id as string;
|
||||||
const overId = over.id as string;
|
const overId = over.id as string;
|
||||||
@@ -265,7 +299,7 @@ export function BoardView() {
|
|||||||
|
|
||||||
moveCard(activeCardId, activeColumn.id, overColumn.id, overIndex);
|
moveCard(activeCardId, activeColumn.id, overColumn.id, overIndex);
|
||||||
},
|
},
|
||||||
[moveCard]
|
[moveCard, columnDropMarker]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDragEnd = useCallback(
|
const handleDragEnd = useCallback(
|
||||||
@@ -427,12 +461,30 @@ export function BoardView() {
|
|||||||
defer
|
defer
|
||||||
>
|
>
|
||||||
<motion.div
|
<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) }}
|
style={{ gap: `calc(1.5rem * var(--density-factor))`, padding: `calc(1.5rem * var(--density-factor))`, ...getBoardBackground(board) }}
|
||||||
variants={staggerContainer(0.06)}
|
variants={staggerContainer(0.06)}
|
||||||
initial="hidden"
|
initial="hidden"
|
||||||
animate="visible"
|
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>
|
<AnimatePresence>
|
||||||
{board.columns.map((column) => (
|
{board.columns.map((column) => (
|
||||||
<KanbanColumn
|
<KanbanColumn
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ export function KanbanColumn({ column, filteredCardIds, focusedCardId, onCardCli
|
|||||||
exit={{ width: 0, opacity: 0 }}
|
exit={{ width: 0, opacity: 0 }}
|
||||||
transition={springs.bouncy}
|
transition={springs.bouncy}
|
||||||
className="shrink-0 overflow-hidden"
|
className="shrink-0 overflow-hidden"
|
||||||
|
data-column-id={column.id}
|
||||||
{...attributes}
|
{...attributes}
|
||||||
>
|
>
|
||||||
{column.collapsed ? (
|
{column.collapsed ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user