'use client'; import { Card } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import { DndContext, DragOverlay, MouseSensor, TouchSensor, rectIntersection, useDraggable, useDroppable, useSensor, useSensors } from '@dnd-kit/core'; import type { DragEndEvent } from '@dnd-kit/core'; import type React from 'react'; import type { ReactNode } from 'react'; export type { DragEndEvent } from '@dnd-kit/core'; export type Status = { id: string; name: string; color: string; }; export type Feature = { id: string; name: string; startAt: Date; endAt: Date; status: Status; }; export type KanbanBoardProps = { id: Status['id']; children: ReactNode; className?: string; }; export const KanbanBoard = ({ id, children, className }: KanbanBoardProps) => { const { isOver, setNodeRef } = useDroppable({ id }); return (
{children}
); }; export type KanbanCardProps = Pick & { index: number; parent: string; children?: ReactNode; className?: string; onClick?: (event: React.MouseEvent) => void; onDoubleClick?: (event: React.MouseEvent) => void; }; export const KanbanCard = ({ id, name, index, parent, children, className, onClick, onDoubleClick }: KanbanCardProps) => { const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ id, data: { index, parent } }); return ( !isDragging && onClick?.(e)} onDoubleClick={onDoubleClick} ref={setNodeRef} > {children ??

{name}

}
); }; export type KanbanCardsProps = { children: ReactNode; className?: string; }; export const KanbanCards = ({ children, className }: KanbanCardsProps) => (
{children}
); export type KanbanHeaderProps = | { children: ReactNode; } | { name: Status['name']; color: Status['color']; className?: string; }; export const KanbanHeader = (props: KanbanHeaderProps) => 'children' in props ? ( props.children ) : (

{props.name}

); export type KanbanProviderProps = { children: ReactNode; onDragEnd: (event: DragEndEvent) => void; onDragStart?: (event: DragEndEvent) => void; onDragCancel?: () => void; className?: string; dragOverlay?: ReactNode; }; export const KanbanProvider = ({ children, onDragEnd, onDragStart, onDragCancel, className, dragOverlay }: KanbanProviderProps) => { // Configure sensors with activation constraints to prevent accidental drags const sensors = useSensors( // Only start a drag if you've moved more than 8px useSensor(MouseSensor, { activationConstraint: { distance: 8 } }), // On touch devices, require a short press + small move useSensor(TouchSensor, { activationConstraint: { delay: 150, tolerance: 5 } }) ); return (
{children}
{dragOverlay}
); };