Replace arrayMove with custom implementation in PairEditor to remove dependency on @dnd-kit/sortable.

This commit is contained in:
Gregory Schier
2025-10-19 09:40:11 -07:00
parent b11c72fde4
commit e902b67a63

View File

@@ -10,7 +10,6 @@ import {
useSensor,
useSensors,
} from '@dnd-kit/core';
import { arrayMove } from '@dnd-kit/sortable';
import classNames from 'classnames';
import {
forwardRef,
@@ -261,7 +260,13 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
const to = hoveredIndex ?? (baseTo === -1 ? from : baseTo);
if (from !== -1 && to !== -1 && from !== to) {
setPairsAndSave((ps) => arrayMove(ps, from, to > from ? to - 1 : to));
setPairsAndSave((ps) => {
const next = [...ps];
const [moved] = next.splice(from, 1);
if (moved === undefined) return ps; // Make TS happy
next.splice(to > from ? to - 1 : to, 0, moved);
return next;
});
}
},
[pairs, hoveredIndex, setPairsAndSave],