import { useI18n } from '@solid-primitives/i18n' import type { DragEventHandler, Draggable, Droppable, } from '@thisbeyond/solid-dnd' import { DragDropProvider, DragDropSensors, DragOverlay, SortableProvider, closestCenter, createSortable, useDragDropContext, } from '@thisbeyond/solid-dnd' import { For, Show, createSignal } from 'solid-js' import { Button } from '~/components/Button' import { AccessorKey, initColumnOrder, initColumnVisibility, } from '~/config/enum' type ColumnVisibility = Partial> type ColumnOrder = AccessorKey[] export default (props: { order: ColumnOrder visible: ColumnVisibility onOrderChange: (value: ColumnOrder) => void onVisibleChange: (value: ColumnVisibility) => void }) => { const [t] = useI18n() 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 (
{t(key)} { props.onVisibleChange({ ...props.visible, [key]: e.target.checked, }) }} />
) } return ( <> ) }