Newsletter: every part editable and movable

A draft is one ordered list of parts (migration 060, newsletters.layout
as JSON), edited with the content block editor so any part can be
moved, copied or removed, each aligned left or center:
- header: words, a PNG/JPEG logo, band color or none
- title
- any email block; dividers take color, thickness and spacing
- picked items: events, posts or front page cards picked in order,
  with the heading, its underline, the card bar and the button label
- footer: its lines and the line above

Colors come from the palette or none. 057's fixed fields and blocks
are dropped; that migration never reached a live database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-01 19:37:26 -05:00
parent 222c9e69a2
commit 3194fdbb7d
5 changed files with 561 additions and 397 deletions

View file

@ -1,11 +1,12 @@
import { text, blocksChild } from "./columns.js";
import { text } from "./columns.js";
/* ── Newsletter drafts (057_newsletters.sql) ─────────────────────
/* ── Newsletter drafts (057, 060_newsletter_layout.sql) ─────────
Saved from Tools → Newsletter (AdminNewsletter.tsx), which is
their only editor: there is no list or form for them in Data.
`picks` is the builder's JSON of what's ticked. Deleting a draft
takes its blocks with it (newsletters_cleanup). */
`layout` is the builder's JSON list of parts, in order
(src/lib/newsletter.ts); `title` is the title part's text, kept
apart for the list of drafts. */
export const newsletters = {
key: "newsletters",
@ -21,7 +22,5 @@ export const newsletters = {
order: "updated_at DESC, id DESC",
},
columns: [text("title"), text("intro"), text("footer"), text("picks")],
children: [blocksChild("newsletter")],
columns: [text("title"), text("layout", { required: true })],
};

View file

@ -0,0 +1,47 @@
-- ═══════════════════════════════════════════════════════════════
-- 060 NEWSLETTER LAYOUT
--
-- A newsletter is one ordered list of parts now, each movable and
-- each with its own settings (src/lib/newsletter.ts reads them):
-- the header band, the title, any email block, a section of picked
-- events, posts or front page cards, and the footer. It's kept as
-- JSON in `layout`, the builder's only editor.
--
-- That replaces 057's fixed fields (intro, footer, picks) and the
-- drafts' content_blocks. 057 never reached a live database, so
-- there are no drafts to carry over: the table is rebuilt keeping
-- each row's id, title and dates, and its blocks are deleted.
-- `title` stays as its own column, for the list of drafts.
-- ═══════════════════════════════════════════════════════════════
DELETE FROM content_blocks WHERE owner_kind = 'newsletter';
DROP TRIGGER newsletters_touch;
DROP TRIGGER newsletters_cleanup;
CREATE TABLE newsletters_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
layout TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(layout) AND json_type(layout) = 'array'),
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
) STRICT;
INSERT INTO newsletters_new (id, title, created_at, updated_at)
SELECT id, title, created_at, updated_at FROM newsletters;
-- content_blocks_owner_exists names this table.
PRAGMA legacy_alter_table = ON;
DROP TABLE newsletters;
ALTER TABLE newsletters_new RENAME TO newsletters;
PRAGMA legacy_alter_table = OFF;
-- ── Triggers last (see CLAUDE.md, Migrations) ──
CREATE TRIGGER newsletters_touch
AFTER UPDATE ON newsletters
FOR EACH ROW WHEN new.updated_at = old.updated_at
BEGIN
UPDATE newsletters SET updated_at = datetime('now') WHERE id = new.id;
END;