Line data Source code
1 : import type { UniqueIdentifier } from '@dnd-kit/core';
2 :
3 : export interface FeedDragEntry {
4 : scriptId: number;
5 : fileName: string;
6 : }
7 :
8 1 : export function reorderFeedEntries<T extends FeedDragEntry>(
9 1 : entries: readonly T[],
10 1 : activeId: UniqueIdentifier,
11 1 : overId: UniqueIdentifier,
12 1 : ): T[] | null {
13 1 : const from = entries.findIndex(entry => entry.scriptId === activeId);
14 1 : const to = entries.findIndex(entry => entry.scriptId === overId);
15 1 : if (from < 0 || to < 0 || from === to) return null;
16 1 : const reordered = [...entries];
17 1 : const [moved] = reordered.splice(from, 1);
18 1 : reordered.splice(to, 0, moved);
19 1 : return reordered;
20 1 : }
|