Files
community-rule/lib/create/reorderCustomMethodCardFieldBlocks.ts
T
2026-05-07 21:15:27 -06:00

19 lines
547 B
TypeScript

/**
* Immutable reorder for custom method card field blocks (wizard step 3, edit modal).
*/
export function reorderCustomMethodCardFieldBlocks<T>(
blocks: readonly T[],
fromIndex: number,
toIndex: number,
): T[] {
if (fromIndex === toIndex) return [...blocks];
if (fromIndex < 0 || toIndex < 0 || fromIndex >= blocks.length) {
return [...blocks];
}
if (toIndex >= blocks.length) return [...blocks];
const next = [...blocks];
const [removed] = next.splice(fromIndex, 1);
next.splice(toIndex, 0, removed);
return next;
}