import type { ComponentPropsWithoutRef, ReactNode } from "react"; import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core"; import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { GripVertical, PinOff } from "lucide-react"; import { SidebarNavItem } from "./SidebarNavItem"; import { cn } from "@/lib/utils"; export interface PinnedNavigationItem { key: string; to: string; label: string; icon: ReactNode } /** Keep this row mounted when a pin is toggled so its controls retain focus. */ export function SortablePinnedRow({ id, label, disabled = false, className, handleClassName, handleIconClassName, children, ...props }: Omit, "id"> & { id: string; label: string; disabled?: boolean; handleClassName: string; handleIconClassName: string; }) { const sortable = useSortable({ id, disabled, transition: null }); return
event.preventDefault()}> {children} {!disabled && }
; } function PinnedItem({ item, rail, onUnpin }: { item: PinnedNavigationItem; rail: boolean; onUnpin: (key: string) => void }) { return {!rail && } ; } export function SortablePinnedList({ keys, onReorder, children }: { keys: string[]; onReorder?: (keys: string[]) => void; children: ReactNode; }) { const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 8 } }), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), ); function move({ active, over }: DragEndEvent) { if (!over || active.id === over.id) return; const from = keys.indexOf(String(active.id)), to = keys.indexOf(String(over.id)); if (from >= 0 && to >= 0) onReorder?.(arrayMove(keys, from, to)); } return {children} ; } export function PinnedNavigationList({ items, rail, onReorder, onUnpin }: { items: PinnedNavigationItem[]; rail: boolean; onReorder: (keys: string[]) => void; onUnpin: (key: string) => void; }) { return item.key)} onReorder={onReorder}> {items.map(item => )} ; }