Let superadmins change the whole colour palette

Panel -> Site settings -> Colours: any colour token, with a light and a
dark value (migration 041). The server writes the overrides into each
page's head in the same cascade layers as index.css, so a light-only
change leaves dark mode alone. Values must be #rrggbb (a table CHECK),
and saving refuses a palette that puts any text under 4.5:1 in either
mode, through a new descriptor hook, check(db, id), run inside the
save's transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 23:26:35 -05:00
parent a225e84408
commit f1edaaf92a
9 changed files with 258 additions and 4 deletions

View file

@ -15,6 +15,9 @@
children ordered collections, replaced wholesale on save
singleton the one id this entity ever has; the engine
refuses create and delete (see front_page)
check (db, id) => void, run after a save has written
everything, inside its transaction: throw an
HttpError to refuse it (site settings' colours)
Replacing children wholesale is only safe because nothing has a
foreign key INTO these tables. That is the dividing line, and
@ -35,6 +38,8 @@
what the other side owns rather than blanking it.
═══════════════════════════════════════════════════════════════ */
import { THEME_TOKENS, checkTheme } from "./theme.js";
/* ── Column helpers ──────────────────────────────────────────── */
const text = (name, opts = {}) => ({ name, type: "text", ...opts });
@ -945,7 +950,21 @@ const siteSettings = {
order: "sort_order",
columns: [text("path", { required: true }), text("title"), text("description")],
},
{
key: "colors",
table: "site_setting_colors",
owner: { column: "settings_id" },
order: "sort_order",
columns: [
enumeration("token", THEME_TOKENS, { required: true }),
text("light"),
text("dark"),
],
},
],
// Refuses a palette that would make text hard to read (theme.js).
check: checkTheme,
};
export const ENTITIES = {