import type { DragEventHandler, Draggable, Droppable, } from '@thisbeyond/solid-dnd' import { DragDropProvider, DragDropSensors, DragOverlay, SortableProvider, closestCenter, createSortable, useDragDropContext, } from '@thisbeyond/solid-dnd' import { For, createSignal } from 'solid-js' import { AccessorKey } from '~/config/connection' type ColumnVisibility = Partial> type ColumnOrder = AccessorKey[] export default (props: { order: ColumnOrder visible: ColumnVisibility onOrderChange: (value: ColumnOrder) => void onVisibleChange: (value: ColumnVisibility) => void }) => { const [activeKey, setActiveKey] = createSignal(null) const onDragStart = ({ draggable }: { draggable: Draggable }) => setActiveKey(draggable.id as AccessorKey) const onDragEnd = ({ draggable, droppable, }: { draggable: Draggable droppable: Droppable }) => { if (draggable && droppable) { const currentItems = props.order const fromIndex = currentItems.indexOf(draggable.id as AccessorKey) const toIndex = currentItems.indexOf(droppable.id as AccessorKey) if (fromIndex !== toIndex) { const updatedItems = currentItems.slice() updatedItems.splice(toIndex, 0, ...updatedItems.splice(fromIndex, 1)) props.onOrderChange(updatedItems) } } } const FormRow = (p: { key: AccessorKey }) => { const key = p.key const sortable = createSortable(key) const [state] = useDragDropContext()! return (
{key} { props.onVisibleChange({ ...props.visible, [key]: e.target.checked, }) }} />
) } return ( <> ) }