UNPKG

@mitcsutt/kiln-dnd

Version:

Kiln drag and drop: sortable lists, boards, drop zones and grid layouts with one keyboard model and one announcer, rendered through kiln-ui

30 lines (29 loc) • 1.16 kB
/** * Moves one entry of a list to a new index and returns a new array. The input is left * alone. An index out of range is clamped, so `arrayMove(items, 0, Infinity)` moves the * first entry to the end. * * @example * ```ts * arrayMove(['Draft', 'Review', 'Publish'], 2, 0) // ['Publish', 'Draft', 'Review'] * ``` */ export declare function arrayMove<T>(items: readonly T[], from: number, to: number): T[]; /** A position in a {@link moveBetween} map: the column's key and an index inside it. */ export interface ListPosition { /** The key of the column. */ column: string; /** The index inside that column. */ index: number; } /** * Moves one entry from one list of a map to another (or within one list) and returns a * new map. Lists that don't change keep their identity. This is the shape `Board` reads * and writes: `{ todo: […], doing: […], done: […] }`. * * @example * ```ts * moveBetween(cards, { column: 'todo', index: 0 }, { column: 'doing', index: 2 }) * ``` */ export declare function moveBetween<T>(lists: Readonly<Record<string, readonly T[]>>, from: ListPosition, to: ListPosition): Record<string, T[]>;