Add chapter color customization

- Store an optional accent color on each ChapterEntry so it persists with the
  chapter across switching, reordering, close/reopen, and restart
- Add a per-row color button that opens a palette popover (assign / change /
  remove) and shows a small color dot in the sidebar, readable in Light/Dark
- Expose setChapterColor through the main/preload IPC bridge
This commit is contained in:
avi 2026-08-20 11:21:14 -05:00
commit 946a2967db
7 changed files with 231 additions and 0 deletions

View file

@ -39,6 +39,7 @@ const {
duplicateChapter,
reorderChapters,
setChapterContent,
setChapterColor,
moveInOrder,
} = chapters;
@ -109,6 +110,30 @@ threw = false;
try { reorderChapters(dir, ["bogus", order[0]]); } catch { threw = true; }
ok(threw, "reorder throws on invalid id");
// ---- chapter color ----
const col = createChapter(dir, "Colorful");
setChapterColor(dir, col.id, "#22c55e");
ok(loadBook(dir).chapters[col.id].color === "#22c55e", "setChapterColor assigns color");
setChapterColor(dir, col.id, "#3b82f6");
ok(loadBook(dir).chapters[col.id].color === "#3b82f6", "setChapterColor changes color");
setChapterColor(dir, col.id, null);
ok(!("color" in loadBook(dir).chapters[col.id]), "setChapterColor removes color (null)");
// color travels with the chapter on reorder
setChapterColor(dir, col.id, "#e11d48");
const before = loadBook(dir).chapterOrder.slice();
reorderChapters(dir, [before[before.length - 1], ...before.slice(0, -1)]);
ok(loadBook(dir).chapters[col.id].color === "#e11d48", "color persists after reorder");
// duplicate does not inherit the source color
const colDup = duplicateChapter(dir, col.id);
ok(!("color" in loadBook(dir).chapters[colDup.id]), "duplicate starts without color");
// setChapterColor throws on unknown id
threw = false;
try { setChapterColor(dir, "nope", "#fff"); } catch { threw = true; }
ok(threw, "setChapterColor throws on unknown id");
// empty title throws
threw = false;
try { createChapter(dir, " "); } catch { threw = true; }