"use client" import React, { useMemo } from 'react' import type { Section } from '@/lib/state/store' import { DndContext, closestCenter, PointerSensor, useSensor, useSensors, DragEndEvent } from '@dnd-kit/core' import { SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' function SortableItem({ id, children, testId }: { id: string; children: React.ReactNode; testId?: string }) { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }) const style = { transform: CSS.Transform.toString(transform), transition, } return (
  • {children}
  • ) } export default function SectionCanvas({ sections, onMove, onRemove, onSelect, }: { sections: Section[] onMove: (from: number, to: number) => void onRemove: (index: number) => void onSelect?: (index: number) => void }) { const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 8 } })) const ids = useMemo(() => sections.map((_, i) => `sec-${i}`), [sections]) const handleDragEnd = (event: DragEndEvent) => { const { active, over } = event if (!over) return if (active.id === over.id) return const from = ids.indexOf(String(active.id)) const to = ids.indexOf(String(over.id)) if (from !== -1 && to !== -1) onMove(from, to) } return ( ) }