Allow empty places in rankings; rebuild the list editor

Entries now sit at places 1…max with gaps allowed (#28, nothing at #29,
#30). Moving onto an empty place just puts the entry there; onto a taken
place, the entries in between shift one step, stopping at the first
empty place, so lists without gaps reorder exactly as before. Inserts
push down only to the next gap; deleting can close up or leave the place
empty. New endpoint POST /api/lists/{id}/places inserts or removes empty
places or closes every gap; move and delete reply with every entry's
place. The podium shows an empty step for an empty #2 or #3, and a list
can't shrink below its last used place.

The editor loads every entry (no paging) and applies edits instantly
with the same rules (places.js mirrors places.go), queueing saves in the
background and reconciling with the server's reply. Type a place and
press Enter (↑/↓ move between boxes, Alt+↑/↓ moves the entry), drag, or
use the row menu. Empty runs show as rows with Add here and Remove, and
a toolbar shows the gap count, Close gaps and a Go to # box. Clicking an
entry opens it for editing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-10-08 14:24:00 -07:00
1 parent bf915c04db
commit 88373176f2
15 files changed
+1090 -233

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
// A copy of the place rules in internal/store/places.go, so the editor can
// show a change the moment it's made. The server's reply is the final word.
export class Places {
/** @param {{id: number, rank: number}[]} items @param {number} limit */
constructor(items, limit) {
this.at = new Map(items.map((it) => [it.rank, it.id]));
this.limit = limit;
}
last() {
let n = 0;
for (const r of this.at.keys()) n = Math.max(n, r);
return n;
}
rankOf(id) {
for (const [r, x] of this.at) if (x === id) return r;
return 0;
}
shift(from, to, d) {
if (from > to) return;
const order = [];
for (let r = from; r <= to; r++) order.push(r);
if (d > 0) order.reverse();
for (const r of order) {
if (this.at.has(r)) {
this.at.set(r + d, this.at.get(r));
this.at.delete(r);
}
}
}
nextEmpty(from) {
let r = from;
while (this.at.has(r)) r++;
return r;
}
/** Frees place at by pushing entries down to the next empty place. */
makeRoom(at) {
if (!this.at.has(at)) return true;
const gap = this.nextEmpty(at);
if (gap > this.limit) return false;
this.shift(at, gap - 1, +1);
return true;
}
move(from, to) {
const id = this.at.get(from);
this.at.delete(from);
if (this.at.has(to)) {
if (to < from) {
this.shift(to, this.nextEmpty(to + 1) - 1, +1);
} else {
let gap = to - 1;
while (this.at.has(gap)) gap--;
this.shift(gap + 1, to, -1);
}
}
this.at.set(to, id);
}
remove(id, closeUp) {
const r = this.rankOf(id);
this.at.delete(r);
if (closeUp) this.shift(r + 1, this.nextEmpty(r + 1) - 1, -1);
}
removePlaces(at, count) {
for (let i = 0; i < count; i++) this.shift(at + 1, this.last(), -1);
}
compact() {
const ids = [...this.at.entries()].sort((a, b) => a[0] - b[0]).map((e) => e[1]);
this.at = new Map(ids.map((id, i) => [i + 1, id]));
}
/** Where a new entry goes when no place is asked for. */
appendPlace() {
const last = this.last();
if (last < this.limit) return last + 1;
for (let r = 1; r <= this.limit; r++) if (!this.at.has(r)) return r;
return this.limit + 1;
}
}