// The order of the articles of a section, as a person proposes another one // (Yvv, 2026-10-30: « une simple liste clipable »): click an article, then its // new place — or move it with its arrows. The rules of the vote (who is in the // order, an order completed at the end) are the server's (ADR 0009). /** The article `chosen` takes the place of `target`; the others close up. */ export function place(list: string[], chosen: string, target: string): string[] { const from = list.indexOf(chosen); const to = list.indexOf(target); if (from < 0 || to < 0 || from === to) return list; const next = list.filter((id) => id !== chosen); next.splice(to, 0, chosen); return next; } /** One place up (-1) or down (1), never beyond the ends. */ export function step(list: string[], id: string, by: -1 | 1): string[] { const from = list.indexOf(id); const to = from + by; if (from < 0 || to < 0 || to >= list.length) return list; const target = list[to]; return target === undefined ? list : place(list, id, target); } export function sameOrder(a: string[], b: string[]): boolean { return a.length === b.length && a.every((id, i) => b[i] === id); } /** The articles whose place changed from `before` to `after`. */ export function moved(before: string[], after: string[]): Set { return new Set(after.filter((id, i) => before[i] !== id)); }