mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
e945da693a
Theme infra (fixedThemes, theme utils), music-network presetIcon, audio-device probe, library-index sync, and the auth*SettingsActions slices stay in the core/global layer (consumed via @/ alias) to avoid inverting core->feature.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { BackdropSourcePref } from '@/cover/artistBackdrop';
|
|
|
|
/**
|
|
* Move the source at `from` so it lands at exactly index `to` — the ↑/↓ buttons,
|
|
* i.e. a swap with the neighbour. Returns a new array, or `null` for an
|
|
* out-of-range or no-op move (so the caller can skip a redundant update).
|
|
*/
|
|
export function moveSourceTo(
|
|
sources: BackdropSourcePref[],
|
|
from: number,
|
|
to: number,
|
|
): BackdropSourcePref[] | null {
|
|
if (from === to || from < 0 || to < 0 || from >= sources.length || to >= sources.length) return null;
|
|
const next = sources.slice();
|
|
const [item] = next.splice(from, 1);
|
|
next.splice(to, 0, item);
|
|
return next;
|
|
}
|
|
|
|
/**
|
|
* Insert the source at `from` immediately before the row at `beforeIndex` — the
|
|
* drag-drop case, matching the "line above this row" drop indicator. The -1 when
|
|
* dragging downward accounts for the slot the dragged item vacated. Returns a
|
|
* new array, or `null` for an out-of-range or no-op move.
|
|
*/
|
|
export function dropSourceBefore(
|
|
sources: BackdropSourcePref[],
|
|
from: number,
|
|
beforeIndex: number,
|
|
): BackdropSourcePref[] | null {
|
|
if (from === beforeIndex || from < 0 || from >= sources.length) return null;
|
|
const next = sources.slice();
|
|
const [item] = next.splice(from, 1);
|
|
next.splice(from < beforeIndex ? beforeIndex - 1 : beforeIndex, 0, item);
|
|
return next;
|
|
}
|