Fix dnd for source order

please dont break 🙏
This commit is contained in:
TPN 2024-07-16 06:06:08 +01:00
parent 8c8b98afee
commit 7eb336f899
3 changed files with 4641 additions and 5527 deletions

View File

@ -27,6 +27,7 @@
},
"dependencies": {
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^7.0.0",
"@dnd-kit/sortable": "^8.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@formkit/auto-animate": "^0.8.2",

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,16 @@ import {
DndContext,
DragEndEvent,
KeyboardSensor,
PointerSensor,
MouseSensor,
TouchSensor,
closestCenter,
useSensor,
useSensors,
} from "@dnd-kit/core";
import {
restrictToParentElement,
restrictToVerticalAxis,
} from "@dnd-kit/modifiers";
import {
SortableContext,
arrayMove,
@ -41,7 +46,7 @@ function SortableItem(props: { item: Item }) {
{...attributes}
{...listeners}
className={classNames(
"bg-dropdown-background hover:bg-dropdown-hoverBackground select-none space-x-3 flex items-center max-w-[25rem] py-3 px-4 rounded-lg touch-none",
"bg-dropdown-background hover:bg-dropdown-hoverBackground select-none space-x-3 flex items-center max-w-[25rem] py-3 px-4 rounded-lg touch-manipulation",
props.item.disabled && "opacity-50",
transform ? "cursor-grabbing" : "cursor-grab",
)}
@ -58,7 +63,13 @@ export function SortableList(props: {
setItems: (items: Item[]) => void;
}) {
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(TouchSensor, {
activationConstraint: {
delay: 75,
tolerance: 1,
},
}),
useSensor(MouseSensor),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
}),
@ -81,6 +92,7 @@ export function SortableList(props: {
sensors={sensors}
collisionDetection={closestCenter}
onDragEnd={handleDragEnd}
modifiers={[restrictToVerticalAxis, restrictToParentElement]}
>
<SortableContext
items={props.items}