Improve content blocks: new types, formatting, and a better editor
Blocks (migration 032): video (click to play, sharing the featured cards' player), button and callout types; quotes get an attribution and images alt text separate from the caption. Paragraphs, callouts, quotes and list items take **bold**, *italic*, [text](url), line breaks and blank-line paragraphs, parsed into elements (never HTML) with only safe link schemes. A list item's detail no longer uses an em-dash. Editor: each block type shows only its fields, with a named type and a description, and every open block previews itself with the site's renderer. Any repeater row can now be duplicated or have a new row inserted below it; nested collections take `when`, and help text can depend on the row. src/seed-showcase.js writes a local test post using every block type and option. It refuses the production database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c62dc84add
commit
c5f12c769f
13 changed files with 723 additions and 169 deletions
|
|
@ -22,6 +22,7 @@ Backend (`server/`, Node >= 22). The server reads `HOST` (default `127.0.0.1`),
|
||||||
- `DB_PATH=./dev.db pnpm dev`: run with `node --watch`
|
- `DB_PATH=./dev.db pnpm dev`: run with `node --watch`
|
||||||
- `DB_PATH=./dev.db pnpm migrate`: apply migrations without starting the server
|
- `DB_PATH=./dev.db pnpm migrate`: apply migrations without starting the server
|
||||||
- `DB_PATH=./dev.db node src/admin-cli.js add|list|passwd|role|disable|enable ...`: the only way accounts are created
|
- `DB_PATH=./dev.db node src/admin-cli.js add|list|passwd|role|disable|enable ...`: the only way accounts are created
|
||||||
|
- `DB_PATH=./dev.db node src/seed-showcase.js`: writes /blog/content-block-showcase, every content block type in one page, for checking `ContentBlocks.tsx`. Local only; refuses /var/lib/ngu.
|
||||||
|
|
||||||
In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API must listen on that port.
|
In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API must listen on that port.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,8 +174,8 @@ also in `admin-schema.js` and a CHECK):
|
||||||
| People → Affiliations → Role; Teams → Members → Role | lead, board, staff, volunteer, member | no | `ROLE_LABEL` in `src/pages/PersonDetail.tsx` |
|
| People → Affiliations → Role; Teams → Members → Role | lead, board, staff, volunteer, member | no | `ROLE_LABEL` in `src/pages/PersonDetail.tsx` |
|
||||||
| Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` |
|
| Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` |
|
||||||
| Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. |
|
| Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. |
|
||||||
| Content blocks → Slot | card, body | no | `ContentBlocks.tsx` |
|
| Content blocks → Shown in (slot) | card, body | **yes** | `paragraphs()` in `server/src/shape.js` (card), `ContentBlocks.tsx` (body) |
|
||||||
| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider | no | `ContentBlocks.tsx` (one renderer per type) |
|
| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema.ts`). |
|
||||||
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
|
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
|
||||||
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
|
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
|
||||||
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
|
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
|
||||||
|
|
|
||||||
|
|
@ -176,12 +176,17 @@ const blocksChild = (ownerKind) => ({
|
||||||
"quote",
|
"quote",
|
||||||
"image",
|
"image",
|
||||||
"divider",
|
"divider",
|
||||||
|
"video",
|
||||||
|
"button",
|
||||||
|
"callout",
|
||||||
],
|
],
|
||||||
{ required: true },
|
{ required: true },
|
||||||
),
|
),
|
||||||
text("text"),
|
text("text"),
|
||||||
text("media"),
|
text("media"),
|
||||||
text("href"),
|
text("href"),
|
||||||
|
text("alt"),
|
||||||
|
text("cite"),
|
||||||
],
|
],
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
80
server/src/migrations/032_content_block_types.sql
Normal file
80
server/src/migrations/032_content_block_types.sql
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
-- 032 CONTENT BLOCKS: VIDEO, BUTTON, CALLOUT, ALT TEXT, ATTRIBUTION
|
||||||
|
--
|
||||||
|
-- Three new block types, and two columns for types that had to
|
||||||
|
-- borrow one:
|
||||||
|
--
|
||||||
|
-- video href is the link (YouTube, Vimeo, Facebook) or a
|
||||||
|
-- video file; text is the caption; media an optional
|
||||||
|
-- still. Drawn click-to-play, like a featured card.
|
||||||
|
-- button text is the label, href where it goes.
|
||||||
|
-- callout text in a tinted box, for a note or announcement.
|
||||||
|
--
|
||||||
|
-- alt an image's alt text. text stays its caption: a
|
||||||
|
-- caption describes the moment, alt describes the
|
||||||
|
-- picture to someone who can't see it.
|
||||||
|
-- cite who a quote is by.
|
||||||
|
--
|
||||||
|
-- The type list is a CHECK, so the table is rebuilt, the same way
|
||||||
|
-- 031 did (see its header): legacy_alter_table around the rename,
|
||||||
|
-- because the *_cleanup triggers on other tables name it, then the
|
||||||
|
-- index and the owner trigger again.
|
||||||
|
--
|
||||||
|
-- PRAGMA user_version; -- reads 31 before this file
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
CREATE TABLE content_blocks_new (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
owner_kind TEXT NOT NULL
|
||||||
|
CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')),
|
||||||
|
owner_id TEXT NOT NULL,
|
||||||
|
slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')),
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
|
||||||
|
type TEXT NOT NULL
|
||||||
|
CHECK (type IN ('heading', 'subheading', 'paragraph',
|
||||||
|
'list', 'links', 'quote', 'image', 'divider',
|
||||||
|
'video', 'button', 'callout')),
|
||||||
|
text TEXT,
|
||||||
|
media TEXT,
|
||||||
|
href TEXT,
|
||||||
|
alt TEXT,
|
||||||
|
cite TEXT
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
INSERT INTO content_blocks_new (id, owner_kind, owner_id, slot, sort_order, type, text, media, href)
|
||||||
|
SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href
|
||||||
|
FROM content_blocks;
|
||||||
|
|
||||||
|
PRAGMA legacy_alter_table = ON;
|
||||||
|
DROP TABLE content_blocks;
|
||||||
|
ALTER TABLE content_blocks_new RENAME TO content_blocks;
|
||||||
|
PRAGMA legacy_alter_table = OFF;
|
||||||
|
|
||||||
|
CREATE INDEX content_blocks_owner_idx
|
||||||
|
ON content_blocks (owner_kind, owner_id, slot, sort_order);
|
||||||
|
|
||||||
|
|
||||||
|
-- ── Triggers last (see CLAUDE.md, Migrations) ──
|
||||||
|
|
||||||
|
CREATE TRIGGER content_blocks_owner_exists
|
||||||
|
BEFORE INSERT ON content_blocks
|
||||||
|
BEGIN
|
||||||
|
SELECT CASE
|
||||||
|
WHEN new.owner_kind = 'event'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id)
|
||||||
|
THEN RAISE(ABORT, 'content_blocks: no such event')
|
||||||
|
WHEN new.owner_kind = 'organization'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id)
|
||||||
|
THEN RAISE(ABORT, 'content_blocks: no such organization')
|
||||||
|
WHEN new.owner_kind = 'person'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id)
|
||||||
|
THEN RAISE(ABORT, 'content_blocks: no such person')
|
||||||
|
WHEN new.owner_kind = 'team'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id)
|
||||||
|
THEN RAISE(ABORT, 'content_blocks: no such team')
|
||||||
|
WHEN new.owner_kind = 'blog_post'
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id)
|
||||||
|
THEN RAISE(ABORT, 'content_blocks: no such blog post')
|
||||||
|
END;
|
||||||
|
END;
|
||||||
109
server/src/seed-showcase.js
Normal file
109
server/src/seed-showcase.js
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
|
CONTENT BLOCK SHOWCASE: a local test page
|
||||||
|
|
||||||
|
DB_PATH=./dev.db node src/seed-showcase.js
|
||||||
|
|
||||||
|
Writes one blog post, /blog/content-block-showcase, that uses
|
||||||
|
every content block type and every option each one has, so a
|
||||||
|
change to ContentBlocks.tsx can be checked against all of them
|
||||||
|
in one place. Run it again to put the post back as written here;
|
||||||
|
it replaces the post and its blocks, and nothing else.
|
||||||
|
|
||||||
|
The post is published but unlisted: its page works, and it stays
|
||||||
|
out of the Community page's "newest". It is test content, so this
|
||||||
|
refuses the production database (anything under /var/lib/ngu).
|
||||||
|
|
||||||
|
Image blocks point at /uploads/showcase.jpg. Upload any photo in
|
||||||
|
Admin → Media and paste its path into those blocks, or leave them
|
||||||
|
to check how a missing image degrades.
|
||||||
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
import { openDatabase, migrate, tx } from "./db.js";
|
||||||
|
|
||||||
|
const DB_PATH = process.env.DB_PATH ?? "./ngu.db";
|
||||||
|
|
||||||
|
// Matched anywhere in the path, not only at its start, so a shell
|
||||||
|
// that rewrites /var/lib/... into its own form (Git Bash) is caught too.
|
||||||
|
if (/(^|\/)var\/lib\/ngu(\/|$)/.test(DB_PATH.replace(/\\/g, "/"))) {
|
||||||
|
console.error("✗ This is test content. It won't write to the production database.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const POST_ID = "content-block-showcase";
|
||||||
|
const IMAGE = "/uploads/showcase.jpg";
|
||||||
|
|
||||||
|
/* [type, fields, items?] in page order. */
|
||||||
|
const BLOCKS = [
|
||||||
|
["paragraph", { text: "Every content block type, top to bottom, with each of its options. Use it to check the page after changing how blocks draw." }],
|
||||||
|
["heading", { text: "Heading" }],
|
||||||
|
["subheading", { text: "Subheading" }],
|
||||||
|
["paragraph", { text: "A paragraph with **bold**, *italic*, a [link to the history page](/history) and an [outside link](https://example.org).\nThis line follows a single line break.\n\nA blank line starts a second paragraph in the same block." }],
|
||||||
|
["paragraph", { text: "A whole paragraph that is a link, set with the block's Link field.", href: "/community" }],
|
||||||
|
["callout", { text: "**A callout.** For a note or an announcement. It takes the same formatting as a paragraph, including [links](/give)." }],
|
||||||
|
["quote", { text: "Unity is not a feeling we wait for. It is a practice we keep.", cite: "A retreat speaker" }],
|
||||||
|
["quote", { text: "A quote with no attribution." }],
|
||||||
|
["divider", {}],
|
||||||
|
["subheading", { text: "Lists" }],
|
||||||
|
["list", {}, [
|
||||||
|
{ text: "A plain item" },
|
||||||
|
{ text: "An item with a detail", detail: "the detail" },
|
||||||
|
{ text: "A linked item", url: "/retreats" },
|
||||||
|
{ text: "A linked item with a detail", url: "https://example.org", detail: "opens in a new tab" },
|
||||||
|
]],
|
||||||
|
["links", {}, [
|
||||||
|
{ text: "Retreats", url: "/retreats" },
|
||||||
|
{ text: "Community", url: "/community" },
|
||||||
|
{ text: "An outside site", url: "https://example.org" },
|
||||||
|
]],
|
||||||
|
["button", { text: "A button", href: "/give" }],
|
||||||
|
["divider", {}],
|
||||||
|
["subheading", { text: "Images" }],
|
||||||
|
["image", { media: IMAGE, alt: "Describe the picture here", text: "An image with a caption and alt text" }],
|
||||||
|
["image", { media: IMAGE, alt: "The same picture, linked", href: "/history" }],
|
||||||
|
["subheading", { text: "Video" }],
|
||||||
|
["video", { href: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", text: "A YouTube video, with its own thumbnail" }],
|
||||||
|
["video", { href: "https://vimeo.com/76979871", media: IMAGE, text: "A Vimeo video with an uploaded still" }],
|
||||||
|
];
|
||||||
|
|
||||||
|
const db = await openDatabase(DB_PATH);
|
||||||
|
migrate(db, { log: () => {} });
|
||||||
|
|
||||||
|
tx(db, () => {
|
||||||
|
db.prepare(`DELETE FROM blog_posts WHERE id = ?`).run(POST_ID); // takes its blocks (blog_posts_cleanup)
|
||||||
|
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO blog_posts (id, title, excerpt, published_on, tags, guest_author, is_published, is_listed)
|
||||||
|
VALUES (?, ?, ?, date('now'), ?, ?, 1, 0)`,
|
||||||
|
).run(
|
||||||
|
POST_ID,
|
||||||
|
"Content block showcase",
|
||||||
|
"Every block type in one place, for checking the page.",
|
||||||
|
"Test, Showcase",
|
||||||
|
"The showcase script",
|
||||||
|
);
|
||||||
|
|
||||||
|
const block = db.prepare(
|
||||||
|
`INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite)
|
||||||
|
VALUES ('blog_post', ?, 'body', ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
|
);
|
||||||
|
const item = db.prepare(
|
||||||
|
`INSERT INTO content_block_items (block_id, sort_order, text, detail, url) VALUES (?, ?, ?, ?, ?)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
BLOCKS.forEach(([type, f, items = []], order) => {
|
||||||
|
const { lastInsertRowid } = block.run(
|
||||||
|
POST_ID,
|
||||||
|
order,
|
||||||
|
type,
|
||||||
|
f.text ?? null,
|
||||||
|
f.media ?? null,
|
||||||
|
f.href ?? null,
|
||||||
|
f.alt ?? null,
|
||||||
|
f.cite ?? null,
|
||||||
|
);
|
||||||
|
items.forEach((it, i) => item.run(lastInsertRowid, i, it.text, it.detail ?? null, it.url ?? null));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
console.log(`✓ ${BLOCKS.length} blocks written. Open /blog/${POST_ID}`);
|
||||||
|
|
@ -66,7 +66,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
||||||
|
|
||||||
const blockRows = db
|
const blockRows = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT id, owner_id, type, text, media, href
|
`SELECT id, owner_id, type, text, media, href, alt, cite
|
||||||
FROM content_blocks
|
FROM content_blocks
|
||||||
WHERE owner_kind = ? AND slot = ? AND owner_id IN (${placeholders(ids.length)})
|
WHERE owner_kind = ? AND slot = ? AND owner_id IN (${placeholders(ids.length)})
|
||||||
ORDER BY owner_id, sort_order`,
|
ORDER BY owner_id, sort_order`,
|
||||||
|
|
@ -83,6 +83,8 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
|
||||||
text: row.text,
|
text: row.text,
|
||||||
media: row.media,
|
media: row.media,
|
||||||
href: row.href,
|
href: row.href,
|
||||||
|
alt: row.alt,
|
||||||
|
cite: row.cite,
|
||||||
items: [],
|
items: [],
|
||||||
};
|
};
|
||||||
byId.set(row.id, block);
|
byId.set(row.id, block);
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,41 @@
|
||||||
/* ═══════════════════════════════════════════════════════════════
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
CONTENT BLOCKS
|
CONTENT BLOCKS
|
||||||
|
|
||||||
Renders the `body` slot of content_blocks. Events, organizations
|
Renders the `body` slot of content_blocks. Events, organizations,
|
||||||
and teams all own blocks and all render them the same way, so
|
teams, people and blog posts all own blocks and all render them
|
||||||
this is written once and tinted by the caller's accent.
|
the same way, so this is written once and tinted by the caller's
|
||||||
|
accent. The admin's block editor previews each block through this
|
||||||
|
same component.
|
||||||
|
|
||||||
⚠ Assumes shape.js's loadBlocks returns rows carrying `type`,
|
What each type reads (see 032_content_block_types.sql):
|
||||||
`text`, `media`, `href` and an `items` array. If the field names
|
|
||||||
differ, this is the only file to fix — nothing else reads a
|
heading, subheading text
|
||||||
block.
|
paragraph text (formatted), href makes it all a link
|
||||||
|
callout text (formatted), in a tinted box
|
||||||
|
quote text (formatted), cite is who said it
|
||||||
|
list items: text, detail, url
|
||||||
|
links items with a url, as outlined buttons
|
||||||
|
button text is the label, href where it goes
|
||||||
|
image media, alt, text is the caption, href
|
||||||
|
video href is the video, media a still, text
|
||||||
|
the caption; click to play
|
||||||
|
divider nothing
|
||||||
|
|
||||||
|
"Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
|
||||||
|
line breaks, and a blank line for a new paragraph.
|
||||||
|
|
||||||
An unknown `type` renders its text as a paragraph rather than
|
An unknown `type` renders its text as a paragraph rather than
|
||||||
disappearing. A block somebody typed into the admin should be
|
disappearing. A block somebody typed into the admin should be
|
||||||
visible even if the renderer hasn't caught up with it.
|
visible even if the renderer hasn't caught up with it.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
import { Link } from 'react-router-dom'
|
|
||||||
import { blockMedia } from '../lib/media.ts'
|
import { blockMedia } from '../lib/media.ts'
|
||||||
import type { ContentBlock } from '../lib/useContent.ts'
|
import type { ContentBlock } from '../lib/useContent.ts'
|
||||||
|
import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
|
||||||
|
import VideoPlayer from './VideoPlayer.tsx'
|
||||||
|
|
||||||
const BODY = '#4a6b72'
|
const BODY = '#4a6b72'
|
||||||
|
|
||||||
/** External if it has a scheme or starts with //; otherwise it's
|
|
||||||
* one of our own routes and should go through the router. */
|
|
||||||
const isExternal = (url: string) => /^([a-z][a-z0-9+.-]*:|\/\/)/i.test(url)
|
|
||||||
|
|
||||||
function Anchor({
|
|
||||||
href,
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
style,
|
|
||||||
}: {
|
|
||||||
href: string
|
|
||||||
children: React.ReactNode
|
|
||||||
className?: string
|
|
||||||
style?: React.CSSProperties
|
|
||||||
}) {
|
|
||||||
if (isExternal(href)) {
|
|
||||||
return (
|
|
||||||
<a href={href} target="_blank" rel="noreferrer" className={className} style={style}>
|
|
||||||
{children}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Link to={href} className={className} style={style}>
|
|
||||||
{children}
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ContentBlocks({
|
export default function ContentBlocks({
|
||||||
blocks,
|
blocks,
|
||||||
accent = '#138ba0',
|
accent = '#138ba0',
|
||||||
|
|
@ -70,6 +56,15 @@ export default function ContentBlocks({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Caption({ text }: { text?: string | null }) {
|
||||||
|
if (!text) return null
|
||||||
|
return (
|
||||||
|
<figcaption className="mt-2 text-sm opacity-70" style={{ color: BODY }}>
|
||||||
|
{text}
|
||||||
|
</figcaption>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
||||||
const text = block.text ?? ''
|
const text = block.text ?? ''
|
||||||
|
|
||||||
|
|
@ -102,11 +97,9 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
||||||
{item.text}
|
{item.text}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
) : (
|
) : (
|
||||||
item.text
|
<Inline text={item.text} accent={accent} />
|
||||||
)}
|
|
||||||
{item.detail && (
|
|
||||||
<span className="opacity-70"> — {item.detail}</span>
|
|
||||||
)}
|
)}
|
||||||
|
{item.detail && <span className="opacity-70">: {item.detail}</span>}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|
@ -131,14 +124,43 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
case 'quote':
|
case 'button':
|
||||||
|
if (!text || !block.href) return null
|
||||||
return (
|
return (
|
||||||
<blockquote
|
<div>
|
||||||
className="border-l-2 pl-5 text-lg italic"
|
<Anchor
|
||||||
style={{ borderColor: accent, color: BODY }}
|
href={block.href}
|
||||||
|
className="inline-block rounded-full px-6 py-2.5 font-semibold text-white transition-transform hover:scale-105"
|
||||||
|
style={{ background: accent }}
|
||||||
>
|
>
|
||||||
{text}
|
{text}
|
||||||
|
</Anchor>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
case 'quote':
|
||||||
|
return (
|
||||||
|
<figure className="border-l-2 pl-5" style={{ borderColor: accent }}>
|
||||||
|
<blockquote className="text-lg italic" style={{ color: BODY }}>
|
||||||
|
<Inline text={text} accent={accent} />
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
{block.cite && (
|
||||||
|
<figcaption className="mt-2 text-sm font-semibold not-italic" style={{ color: accent }}>
|
||||||
|
{block.cite}
|
||||||
|
</figcaption>
|
||||||
|
)}
|
||||||
|
</figure>
|
||||||
|
)
|
||||||
|
|
||||||
|
case 'callout':
|
||||||
|
if (!text) return null
|
||||||
|
return (
|
||||||
|
<aside
|
||||||
|
className="space-y-3 rounded-2xl border-l-4 px-6 py-5 leading-relaxed"
|
||||||
|
style={{ borderColor: accent, background: `color-mix(in srgb, ${accent} 8%, white)`, color: '#26454c' }}
|
||||||
|
>
|
||||||
|
<Paragraphs text={text} accent={accent} />
|
||||||
|
</aside>
|
||||||
)
|
)
|
||||||
|
|
||||||
case 'image': {
|
case 'image': {
|
||||||
|
|
@ -147,10 +169,9 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
||||||
const img = (
|
const img = (
|
||||||
<img
|
<img
|
||||||
src={src}
|
src={src}
|
||||||
// A caption is a caption, not alt text — but an image with
|
// Alt describes the picture; the caption describes the
|
||||||
// neither is decorative, and alt="" is the correct answer
|
// moment. No alt means decorative, which alt="" says.
|
||||||
// for that rather than a filename read aloud.
|
alt={block.alt ?? ''}
|
||||||
alt={text}
|
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
decoding="async"
|
decoding="async"
|
||||||
className="w-full rounded-lg"
|
className="w-full rounded-lg"
|
||||||
|
|
@ -159,31 +180,38 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
|
||||||
return (
|
return (
|
||||||
<figure>
|
<figure>
|
||||||
{block.href ? <Anchor href={block.href}>{img}</Anchor> : img}
|
{block.href ? <Anchor href={block.href}>{img}</Anchor> : img}
|
||||||
{text && (
|
<Caption text={text} />
|
||||||
<figcaption className="mt-2 text-sm opacity-70" style={{ color: BODY }}>
|
|
||||||
{text}
|
|
||||||
</figcaption>
|
|
||||||
)}
|
|
||||||
</figure>
|
</figure>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'video':
|
||||||
|
if (!block.href) return null
|
||||||
|
return (
|
||||||
|
<figure>
|
||||||
|
<div className="overflow-hidden rounded-lg">
|
||||||
|
<VideoPlayer url={block.href} still={blockMedia(block.media)} title={text || null} />
|
||||||
|
</div>
|
||||||
|
<Caption text={text} />
|
||||||
|
</figure>
|
||||||
|
)
|
||||||
|
|
||||||
case 'divider':
|
case 'divider':
|
||||||
return <hr className="border-0 h-px" style={{ background: accent, opacity: 0.3 }} />
|
return <hr className="border-0 h-px" style={{ background: accent, opacity: 0.3 }} />
|
||||||
|
|
||||||
case 'paragraph':
|
case 'paragraph':
|
||||||
default:
|
default:
|
||||||
if (!text) return null
|
if (!text) return null
|
||||||
return (
|
return block.href ? (
|
||||||
<p className="leading-relaxed" style={{ color: BODY }}>
|
<p className="leading-relaxed" style={{ color: BODY }}>
|
||||||
{block.href ? (
|
|
||||||
<Anchor href={block.href} className="underline" style={{ color: accent }}>
|
<Anchor href={block.href} className="underline" style={{ color: accent }}>
|
||||||
{text}
|
{text}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
) : (
|
|
||||||
text
|
|
||||||
)}
|
|
||||||
</p>
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Paragraphs text={text} accent={accent} className="leading-relaxed" style={{ color: BODY }} />
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,9 @@
|
||||||
|
|
||||||
record links to the record's own page (hrefs.ts builds it)
|
record links to the record's own page (hrefs.ts builds it)
|
||||||
link links to its URL, a new tab when it leaves the site
|
link links to its URL, a new tab when it leaves the site
|
||||||
video a still with a play button; pressing it swaps in the
|
video VideoPlayer: a still with a play button that swaps in
|
||||||
player, so the page loads no iframes until then. The
|
the player when pressed. The still is the card's
|
||||||
still is the card's image, else YouTube's thumbnail,
|
image, else YouTube's thumbnail, else a plain panel.
|
||||||
else a plain panel.
|
|
||||||
|
|
||||||
A photo fills the picture area; a logo sits inside it on a soft
|
A photo fills the picture area; a logo sits inside it on a soft
|
||||||
panel instead, since cropping a logo to 16:9 cuts it off.
|
panel instead, since cropping a logo to 16:9 cuts it off.
|
||||||
|
|
@ -22,13 +21,11 @@
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
||||||
|
import VideoPlayer from './VideoPlayer.tsx'
|
||||||
import { refHref } from '../lib/hrefs.ts'
|
import { refHref } from '../lib/hrefs.ts'
|
||||||
import { logoForKind } from '../lib/media.ts'
|
import { logoForKind } from '../lib/media.ts'
|
||||||
import { playingSource, videoSource, videoThumbnail } from '../lib/embeds.ts'
|
|
||||||
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
||||||
|
|
||||||
const ACCENT = '#138ba0'
|
|
||||||
|
|
||||||
/* Image kinds that are photographs, drawn edge to edge. Anything
|
/* Image kinds that are photographs, drawn edge to edge. Anything
|
||||||
else is a logo, drawn whole. */
|
else is a logo, drawn whole. */
|
||||||
const PHOTO_KINDS = new Set(['event-background', 'featured', 'person'])
|
const PHOTO_KINDS = new Set(['event-background', 'featured', 'person'])
|
||||||
|
|
@ -71,68 +68,8 @@ function Picture({ card }: { card: FeaturedCard }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function VideoPicture({ card }: { card: FeaturedCard }) {
|
function VideoPicture({ card }: { card: FeaturedCard }) {
|
||||||
const [playing, setPlaying] = useState(false)
|
|
||||||
const source = videoSource(card.url)
|
|
||||||
|
|
||||||
if (playing && source) {
|
|
||||||
const live = playingSource(source)
|
|
||||||
return live.kind === 'file' ? (
|
|
||||||
<video src={live.src} controls autoPlay playsInline className="aspect-video w-full bg-black" />
|
|
||||||
) : (
|
|
||||||
<iframe
|
|
||||||
src={live.src}
|
|
||||||
title={card.title || 'Video'}
|
|
||||||
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
|
||||||
allowFullScreen
|
|
||||||
className="aspect-video w-full border-0 bg-black"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const own = card.image ? logoForKind(card.image.kind, card.image.file) : null
|
const own = card.image ? logoForKind(card.image.kind, card.image.file) : null
|
||||||
const still = own ?? videoThumbnail(card.url)
|
return <VideoPlayer url={card.url} still={own} title={card.title} />
|
||||||
|
|
||||||
const face = (
|
|
||||||
<>
|
|
||||||
{still ? (
|
|
||||||
<img src={still} alt="" loading="lazy" className="aspect-video w-full object-cover" />
|
|
||||||
) : (
|
|
||||||
<div className="aspect-video w-full bg-gradient-to-br from-[#073d4a] to-[#04262e]" />
|
|
||||||
)}
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="absolute inset-0 flex items-center justify-center bg-black/10 transition-colors group-hover:bg-black/25"
|
|
||||||
>
|
|
||||||
<span className="flex h-16 w-16 items-center justify-center rounded-full bg-white/90 shadow-lg transition-transform group-hover:scale-110">
|
|
||||||
<svg viewBox="0 0 24 24" className="ml-1 h-7 w-7" fill={ACCENT}>
|
|
||||||
<path d="M8 5v14l11-7z" />
|
|
||||||
</svg>
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
|
|
||||||
// A link that can't be played here still goes somewhere.
|
|
||||||
if (!source) {
|
|
||||||
return card.url ? (
|
|
||||||
<HomeLink url={card.url} className="group relative block">
|
|
||||||
{face}
|
|
||||||
</HomeLink>
|
|
||||||
) : (
|
|
||||||
<div className="relative">{face}</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setPlaying(true)}
|
|
||||||
aria-label={`Play ${card.title || 'video'}`}
|
|
||||||
className="group relative block w-full"
|
|
||||||
>
|
|
||||||
{face}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Card({ card }: { card: FeaturedCard }) {
|
function Card({ card }: { card: FeaturedCard }) {
|
||||||
|
|
|
||||||
137
src/components/InlineText.tsx
Normal file
137
src/components/InlineText.tsx
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
|
INLINE TEXT
|
||||||
|
|
||||||
|
The little formatting a content block's text may carry, typed in
|
||||||
|
the admin as plain characters:
|
||||||
|
|
||||||
|
**bold** *italic* [link text](url)
|
||||||
|
a line break keeps its place
|
||||||
|
a blank line starts a new paragraph
|
||||||
|
|
||||||
|
Parsed into React elements, never HTML, so nothing typed can
|
||||||
|
inject markup. A link only becomes one when its URL is a site
|
||||||
|
path (/history, #section), https/http, mailto: or tel:; anything
|
||||||
|
else (javascript:, data:) shows as the plain text it was.
|
||||||
|
|
||||||
|
`Paragraphs` is for block-level text (paragraph, callout): one
|
||||||
|
<p> per blank-line-separated part. `Inline` is for text that sits
|
||||||
|
inside something else (a quote, a list item).
|
||||||
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
import { Fragment, type CSSProperties, type ReactNode } from 'react'
|
||||||
|
import { Link } from 'react-router-dom'
|
||||||
|
|
||||||
|
const TOKEN = /\*\*(.+?)\*\*|\*(.+?)\*|\[([^\]]+)\]\(([^)\s]+)\)/g
|
||||||
|
const SAFE_URL = /^(\/(?!\/)|#|https?:\/\/|mailto:|tel:)/i
|
||||||
|
|
||||||
|
/** External if it has a scheme or starts with //; otherwise it's
|
||||||
|
* one of our own routes and goes through the router. */
|
||||||
|
export const isExternalUrl = (url: string) => /^([a-z][a-z0-9+.-]*:|\/\/)/i.test(url)
|
||||||
|
|
||||||
|
export function Anchor({
|
||||||
|
href,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
}: {
|
||||||
|
href: string
|
||||||
|
children: ReactNode
|
||||||
|
className?: string
|
||||||
|
style?: CSSProperties
|
||||||
|
}) {
|
||||||
|
if (isExternalUrl(href)) {
|
||||||
|
const app = /^(mailto|tel):/i.test(href)
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={href}
|
||||||
|
className={className}
|
||||||
|
style={style}
|
||||||
|
{...(app ? {} : { target: '_blank', rel: 'noreferrer' })}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (href.startsWith('#')) {
|
||||||
|
return (
|
||||||
|
<a href={href} className={className} style={style}>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Link to={href} className={className} style={style}>
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function line(text: string, accent: string, key: string): ReactNode[] {
|
||||||
|
const out: ReactNode[] = []
|
||||||
|
let last = 0
|
||||||
|
let n = 0
|
||||||
|
for (const match of text.matchAll(TOKEN)) {
|
||||||
|
const at = match.index ?? 0
|
||||||
|
if (at > last) out.push(text.slice(last, at))
|
||||||
|
const [whole, bold, italic, label, url] = match
|
||||||
|
const k = `${key}-${n++}`
|
||||||
|
if (bold != null) out.push(<strong key={k} className="font-semibold">{bold}</strong>)
|
||||||
|
else if (italic != null) out.push(<em key={k}>{italic}</em>)
|
||||||
|
else if (label != null && SAFE_URL.test(url)) {
|
||||||
|
out.push(
|
||||||
|
<Anchor key={k} href={url} className="underline underline-offset-2" style={{ color: accent }}>
|
||||||
|
{label}
|
||||||
|
</Anchor>,
|
||||||
|
)
|
||||||
|
} else out.push(whole)
|
||||||
|
last = at + whole.length
|
||||||
|
}
|
||||||
|
if (last < text.length) out.push(text.slice(last))
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Text inside another element: formatting and line breaks. */
|
||||||
|
export function Inline({ text, accent }: { text?: string | null; accent: string }) {
|
||||||
|
const lines = (text ?? '').split('\n')
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{lines.map((part, i) => (
|
||||||
|
<Fragment key={i}>
|
||||||
|
{i > 0 && <br />}
|
||||||
|
{line(part, accent, `l${i}`)}
|
||||||
|
</Fragment>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Block text: one <p> per part separated by a blank line. */
|
||||||
|
export function Paragraphs({
|
||||||
|
text,
|
||||||
|
accent,
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
}: {
|
||||||
|
text?: string | null
|
||||||
|
accent: string
|
||||||
|
className?: string
|
||||||
|
style?: CSSProperties
|
||||||
|
}) {
|
||||||
|
const parts = (text ?? '')
|
||||||
|
.split(/\n\s*\n/)
|
||||||
|
.map((part) => part.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{parts.map((part, i) => (
|
||||||
|
<p key={i} className={className} style={style}>
|
||||||
|
<Inline text={part} accent={accent} />
|
||||||
|
</p>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** For the editor's help text under a formatted box. */
|
||||||
|
export const FORMATTING_HELP =
|
||||||
|
'**bold**, *italic*, [link text](https://…). A blank line starts a new paragraph.'
|
||||||
93
src/components/VideoPlayer.tsx
Normal file
93
src/components/VideoPlayer.tsx
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
/* ═══════════════════════════════════════════════════════════════
|
||||||
|
VIDEO PLAYER: click to play
|
||||||
|
|
||||||
|
A still with a play button; pressing it swaps in the player, so a
|
||||||
|
page loads no iframes until someone asks for one. Used by the
|
||||||
|
featured cards and the video content block.
|
||||||
|
|
||||||
|
The still is the caller's image, else YouTube's own thumbnail,
|
||||||
|
else a plain dark panel. A link that embeds.ts can't turn into a
|
||||||
|
player (not https, or not a host it knows how to frame) still
|
||||||
|
goes somewhere: the still becomes a link to it.
|
||||||
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
|
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
||||||
|
import { playingSource, videoSource, videoThumbnail } from '../lib/embeds.ts'
|
||||||
|
|
||||||
|
const ACCENT = '#138ba0'
|
||||||
|
|
||||||
|
export default function VideoPlayer({
|
||||||
|
url,
|
||||||
|
still,
|
||||||
|
title,
|
||||||
|
className = '',
|
||||||
|
}: {
|
||||||
|
url?: string | null
|
||||||
|
/** An image URL to show before it plays. */
|
||||||
|
still?: string | null
|
||||||
|
title?: string | null
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const [playing, setPlaying] = useState(false)
|
||||||
|
const source = videoSource(url)
|
||||||
|
|
||||||
|
if (playing && source) {
|
||||||
|
const live = playingSource(source)
|
||||||
|
return live.kind === 'file' ? (
|
||||||
|
<video src={live.src} controls autoPlay playsInline className={`aspect-video w-full bg-black ${className}`} />
|
||||||
|
) : (
|
||||||
|
<iframe
|
||||||
|
src={live.src}
|
||||||
|
title={title || 'Video'}
|
||||||
|
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
||||||
|
allowFullScreen
|
||||||
|
className={`aspect-video w-full border-0 bg-black ${className}`}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const image = still ?? videoThumbnail(url)
|
||||||
|
|
||||||
|
const face = (
|
||||||
|
<>
|
||||||
|
{image ? (
|
||||||
|
<img src={image} alt="" loading="lazy" className={`aspect-video w-full object-cover ${className}`} />
|
||||||
|
) : (
|
||||||
|
<div className={`aspect-video w-full bg-gradient-to-br from-[#073d4a] to-[#04262e] ${className}`} />
|
||||||
|
)}
|
||||||
|
<span
|
||||||
|
aria-hidden="true"
|
||||||
|
className="absolute inset-0 flex items-center justify-center bg-black/10 transition-colors group-hover:bg-black/25"
|
||||||
|
>
|
||||||
|
<span className="flex h-16 w-16 items-center justify-center rounded-full bg-white/90 shadow-lg transition-transform group-hover:scale-110">
|
||||||
|
<svg viewBox="0 0 24 24" className="ml-1 h-7 w-7" fill={ACCENT}>
|
||||||
|
<path d="M8 5v14l11-7z" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!source) {
|
||||||
|
return url ? (
|
||||||
|
<HomeLink url={url} className="group relative block">
|
||||||
|
{face}
|
||||||
|
</HomeLink>
|
||||||
|
) : (
|
||||||
|
<div className="relative">{face}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setPlaying(true)}
|
||||||
|
aria-label={`Play ${title || 'video'}`}
|
||||||
|
className="group relative block w-full"
|
||||||
|
>
|
||||||
|
{face}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -32,6 +32,21 @@
|
||||||
can't keep a value for a choice it no longer makes: a featured
|
can't keep a value for a choice it no longer makes: a featured
|
||||||
card switched from "record" to "link" drops its record.
|
card switched from "record" to "link" drops its record.
|
||||||
|
|
||||||
|
A nested collection takes `when` the same way, and one that goes
|
||||||
|
hidden is emptied: a list block turned into a paragraph drops its
|
||||||
|
items.
|
||||||
|
|
||||||
|
`help` may be a function of the row, for help that depends on
|
||||||
|
another field (a content block's type says what its text is).
|
||||||
|
|
||||||
|
`preview` on a collection names an entry in PREVIEWS below; each
|
||||||
|
open row then shows how it will look on the site, drawn by the
|
||||||
|
site's own component.
|
||||||
|
|
||||||
|
Every row can be duplicated (a copy lands below it, ids stripped
|
||||||
|
so it saves as new) or have a blank row inserted below it, as
|
||||||
|
well as appended at the end.
|
||||||
|
|
||||||
`widget: "linkPreview"` is a URL box with a "Fetch preview" button
|
`widget: "linkPreview"` is a URL box with a "Fetch preview" button
|
||||||
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
||||||
title, blurb and image through `onPatch`.
|
title, blurb and image through `onPatch`.
|
||||||
|
|
@ -57,8 +72,15 @@
|
||||||
|
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
|
|
||||||
|
import ContentBlocks from "../ContentBlocks.tsx";
|
||||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||||
|
|
||||||
|
/* Live previews a collection can name with `preview`. Each gets the
|
||||||
|
row as the form holds it, which is the API's shape. */
|
||||||
|
const PREVIEWS = {
|
||||||
|
contentBlock: (row) => <ContentBlocks blocks={[row]} />,
|
||||||
|
};
|
||||||
|
|
||||||
const input =
|
const input =
|
||||||
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
|
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
|
||||||
"outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25";
|
"outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25";
|
||||||
|
|
@ -104,17 +126,37 @@ export function fieldShown(field, row) {
|
||||||
|
|
||||||
/* A row after an edit, with any field the edit hid cleared. "" is
|
/* A row after an edit, with any field the edit hid cleared. "" is
|
||||||
the engine's deliberate clear, so it saves as NULL. */
|
the engine's deliberate clear, so it saves as NULL. */
|
||||||
function withHiddenCleared(fields, row) {
|
function withHiddenCleared(spec, row) {
|
||||||
let next = row;
|
let next = row;
|
||||||
for (const field of fields) {
|
for (const field of spec.fields) {
|
||||||
const value = next[field.path];
|
const value = next[field.path];
|
||||||
if (!fieldShown(field, next) && value != null && value !== "") {
|
if (!fieldShown(field, next) && value != null && value !== "") {
|
||||||
next = { ...next, [field.path]: "" };
|
next = { ...next, [field.path]: "" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (const nested of spec.children ?? []) {
|
||||||
|
if (!fieldShown(nested, next) && next[nested.key]?.length) {
|
||||||
|
next = { ...next, [nested.key]: [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A copy of a row with every id removed, nested rows included, so
|
||||||
|
the server inserts it as new rather than colliding with the row
|
||||||
|
it was copied from. */
|
||||||
|
function withoutIds(value) {
|
||||||
|
if (Array.isArray(value)) return value.map(withoutIds);
|
||||||
|
if (!value || typeof value !== "object") return value;
|
||||||
|
const copy = {};
|
||||||
|
for (const [key, inner] of Object.entries(value)) {
|
||||||
|
if (key !== "id") copy[key] = withoutIds(inner);
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
const helpText = (field, row) => (typeof field.help === "function" ? field.help(row) : field.help);
|
||||||
|
|
||||||
/* ── Field ───────────────────────────────────────────────────── */
|
/* ── Field ───────────────────────────────────────────────────── */
|
||||||
|
|
||||||
export function Field({ field, value, row, options, error, onChange, onPatch }: any) {
|
export function Field({ field, value, row, options, error, onChange, onPatch }: any) {
|
||||||
|
|
@ -170,7 +212,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
||||||
onChange={(e) => onChange(e.target.checked ? 1 : 0)}
|
onChange={(e) => onChange(e.target.checked ? 1 : 0)}
|
||||||
className="h-4 w-4 rounded border-[#4a6b72]/40 text-[#138ba0] focus:ring-[#138ba0]/40 disabled:opacity-50"
|
className="h-4 w-4 rounded border-[#4a6b72]/40 text-[#138ba0] focus:ring-[#138ba0]/40 disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
{field.help ?? "Yes"}
|
{helpText(field, row) ?? "Yes"}
|
||||||
</label>
|
</label>
|
||||||
) : widget === "textarea" ? (
|
) : widget === "textarea" ? (
|
||||||
<textarea
|
<textarea
|
||||||
|
|
@ -281,9 +323,9 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
||||||
This points at something that has been deleted. Pick a replacement before saving.
|
This points at something that has been deleted. Pick a replacement before saving.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
field.help &&
|
helpText(field, row) &&
|
||||||
widget !== "checkbox" && (
|
widget !== "checkbox" && (
|
||||||
<p className="mt-1 text-xs text-[#4a6b72]">{field.help}</p>
|
<p className="mt-1 text-xs text-[#4a6b72]">{helpText(field, row)}</p>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -340,7 +382,7 @@ export function Repeater({
|
||||||
const rowRefs = useRef<any[]>([]);
|
const rowRefs = useRef<any[]>([]);
|
||||||
|
|
||||||
const update = (index, next) =>
|
const update = (index, next) =>
|
||||||
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec.fields, next) : row)));
|
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec, next) : row)));
|
||||||
|
|
||||||
const move = (index, delta) => {
|
const move = (index, delta) => {
|
||||||
const target = index + delta;
|
const target = index + delta;
|
||||||
|
|
@ -374,6 +416,13 @@ export function Repeater({
|
||||||
onChange([...list, { ...spec.blank }]);
|
onChange([...list, { ...spec.blank }]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* A row placed at `at`, pushing everything from there down one,
|
||||||
|
and opened so it can be filled in straight away. */
|
||||||
|
const insertAt = (at, row) => {
|
||||||
|
setOpen((prev) => remapOpen(prev, (i) => (i >= at ? i + 1 : i)).add(at));
|
||||||
|
onChange([...list.slice(0, at), row, ...list.slice(at)]);
|
||||||
|
};
|
||||||
|
|
||||||
const removeAt = (index) => {
|
const removeAt = (index) => {
|
||||||
setOpen((prev) => remapOpen(prev, (i) => (i === index ? -1 : i > index ? i - 1 : i)));
|
setOpen((prev) => remapOpen(prev, (i) => (i === index ? -1 : i > index ? i - 1 : i)));
|
||||||
onChange(list.filter((_, i) => i !== index));
|
onChange(list.filter((_, i) => i !== index));
|
||||||
|
|
@ -518,6 +567,18 @@ export function Repeater({
|
||||||
>
|
>
|
||||||
↓
|
↓
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
label="Insert a new one below"
|
||||||
|
onClick={() => insertAt(index + 1, { ...spec.blank })}
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
label="Duplicate"
|
||||||
|
onClick={() => insertAt(index + 1, withoutIds(row))}
|
||||||
|
>
|
||||||
|
⧉
|
||||||
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
label="Remove"
|
label="Remove"
|
||||||
danger
|
danger
|
||||||
|
|
@ -547,7 +608,9 @@ export function Repeater({
|
||||||
))}
|
))}
|
||||||
</FieldGrid>
|
</FieldGrid>
|
||||||
|
|
||||||
{(spec.children ?? []).map((nested) => (
|
{(spec.children ?? [])
|
||||||
|
.filter((nested) => fieldShown(nested, row))
|
||||||
|
.map((nested) => (
|
||||||
<div key={nested.key} className="mt-4 border-t border-[#4a6b72]/15 pt-4">
|
<div key={nested.key} className="mt-4 border-t border-[#4a6b72]/15 pt-4">
|
||||||
<Repeater
|
<Repeater
|
||||||
spec={nested}
|
spec={nested}
|
||||||
|
|
@ -560,6 +623,15 @@ export function Repeater({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{spec.preview && PREVIEWS[spec.preview] && (
|
||||||
|
<div className="mt-4 rounded-lg border border-dashed border-[#138ba0]/30 bg-white p-4">
|
||||||
|
<p className="mb-3 text-xs font-semibold uppercase tracking-wider text-[#4a6b72]/70">
|
||||||
|
Preview
|
||||||
|
</p>
|
||||||
|
{PREVIEWS[spec.preview](row)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import { preview } from "./text.ts";
|
import { preview } from "./text.ts";
|
||||||
import { PLATFORMS } from "./platforms.ts";
|
import { PLATFORMS } from "./platforms.ts";
|
||||||
|
import { FORMATTING_HELP } from "../components/InlineText.tsx";
|
||||||
import {
|
import {
|
||||||
awardLogo,
|
awardLogo,
|
||||||
blockMedia,
|
blockMedia,
|
||||||
|
|
@ -286,44 +287,126 @@ const hostsChild = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Content blocks. The type decides which fields appear (`when`),
|
||||||
|
what the text box is for (`help` as a function), and whether the
|
||||||
|
block has items; the preview under each open block is the site's
|
||||||
|
own renderer. Types and what they read: ContentBlocks.tsx. */
|
||||||
|
const BLOCK_TYPES = [
|
||||||
|
["paragraph", "Paragraph", "Body text. Formatting: " + FORMATTING_HELP],
|
||||||
|
["heading", "Heading", "A section heading."],
|
||||||
|
["subheading", "Subheading", "A smaller heading under a heading."],
|
||||||
|
["callout", "Callout", "A note or announcement in a tinted box. Formatting: " + FORMATTING_HELP],
|
||||||
|
["quote", "Quote", "A quotation, with who said it. Formatting: " + FORMATTING_HELP],
|
||||||
|
["list", "List", "Bulleted items, each optionally linked, with an optional detail."],
|
||||||
|
["links", "Link buttons", "A row of outlined buttons, one per item."],
|
||||||
|
["button", "Button", "One filled call-to-action button, eg. Register, Donate."],
|
||||||
|
["image", "Image", "A picture, with alt text and an optional caption and link."],
|
||||||
|
["video", "Video", "A YouTube, Vimeo or Facebook video, or a video file, played in place."],
|
||||||
|
["divider", "Divider", "A thin line between parts."],
|
||||||
|
];
|
||||||
|
|
||||||
|
const blockTypeLabel = (type) => BLOCK_TYPES.find(([value]) => value === type)?.[1] ?? type;
|
||||||
|
|
||||||
|
const TEXT_TYPES = ["paragraph", "heading", "subheading", "callout", "quote", "button", "image", "video"];
|
||||||
|
|
||||||
|
const TEXT_HELP = {
|
||||||
|
paragraph: FORMATTING_HELP,
|
||||||
|
callout: FORMATTING_HELP,
|
||||||
|
quote: FORMATTING_HELP,
|
||||||
|
button: "The button's label, eg. Register now",
|
||||||
|
image: "Caption shown under the image. Optional.",
|
||||||
|
video: "Caption shown under the video. Optional.",
|
||||||
|
};
|
||||||
|
|
||||||
|
const TEXT_LABEL = { button: "Label", image: "Caption", video: "Caption" };
|
||||||
|
|
||||||
|
const HREF_HELP = {
|
||||||
|
paragraph: "Optional. Makes the whole paragraph one link. For a link inside the text, use [text](url).",
|
||||||
|
button: "Where the button goes, eg. /give or https://…",
|
||||||
|
image: "Optional. Makes the image a link.",
|
||||||
|
video: "The video's page, eg. https://www.youtube.com/watch?v=…, or a video file",
|
||||||
|
};
|
||||||
|
|
||||||
const blocksChild = {
|
const blocksChild = {
|
||||||
key: "content_blocks",
|
key: "content_blocks",
|
||||||
label: "Content blocks",
|
label: "Content blocks",
|
||||||
addLabel: "Add block",
|
addLabel: "Add block",
|
||||||
title: (row) => `${row.type ?? "block"}: ${preview(row.text, 40) || "empty"}`,
|
preview: "contentBlock",
|
||||||
|
title: (row) => {
|
||||||
|
const label = blockTypeLabel(row.type) || "Block";
|
||||||
|
const text = preview(row.text || row.href || row.media || "", 40);
|
||||||
|
return text ? `${label}: ${text}` : label;
|
||||||
|
},
|
||||||
blank: { slot: "body", type: "paragraph", text: "" },
|
blank: { slot: "body", type: "paragraph", text: "" },
|
||||||
fields: [
|
fields: [
|
||||||
{ path: "slot", label: "Slot", widget: "select", options: ["card", "body"] },
|
{
|
||||||
|
path: "slot",
|
||||||
|
label: "Shown in",
|
||||||
|
widget: "select",
|
||||||
|
options: [
|
||||||
|
["body", "The page"],
|
||||||
|
["card", "The card (paragraphs only)"],
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "type",
|
path: "type",
|
||||||
label: "Type",
|
label: "Type",
|
||||||
widget: "select",
|
widget: "select",
|
||||||
options: [
|
options: BLOCK_TYPES.map(([value, label]) => [value, label]),
|
||||||
"heading",
|
help: (row) => BLOCK_TYPES.find(([value]) => value === row?.type)?.[2],
|
||||||
"subheading",
|
},
|
||||||
"paragraph",
|
{
|
||||||
"list",
|
path: "text",
|
||||||
"links",
|
label: "Text",
|
||||||
"quote",
|
widget: "textarea",
|
||||||
"image",
|
full: true,
|
||||||
"divider",
|
when: { path: "type", value: TEXT_TYPES },
|
||||||
],
|
help: (row) => TEXT_HELP[row?.type],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "cite",
|
||||||
|
label: "Attribution",
|
||||||
|
help: "Who said it, eg. Jane Doe, Retreat 2024",
|
||||||
|
full: true,
|
||||||
|
when: { path: "type", value: "quote" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "href",
|
||||||
|
label: "Link",
|
||||||
|
full: true,
|
||||||
|
when: { path: "type", value: ["paragraph", "button", "image", "video"] },
|
||||||
|
help: (row) => HREF_HELP[row?.type],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "media",
|
||||||
|
label: "Image",
|
||||||
|
widget: "image",
|
||||||
|
resolve: blockMedia,
|
||||||
|
full: true,
|
||||||
|
when: { path: "type", value: ["image", "video"] },
|
||||||
|
help: (row) =>
|
||||||
|
row?.type === "video" ? "Still shown before it plays. Default: YouTube's own thumbnail." : undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "alt",
|
||||||
|
label: "Alt text",
|
||||||
|
full: true,
|
||||||
|
when: { path: "type", value: "image" },
|
||||||
|
help: "Describes the picture for someone who can't see it, eg. Campers around a fire at dusk",
|
||||||
},
|
},
|
||||||
{ path: "text", label: "Text", widget: "textarea", full: true },
|
|
||||||
{ path: "media", label: "Media", widget: "image", resolve: blockMedia, full: true },
|
|
||||||
{ path: "href", label: "Link" },
|
|
||||||
],
|
],
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
key: "items",
|
key: "items",
|
||||||
label: "Items",
|
label: "Items",
|
||||||
addLabel: "Add item",
|
addLabel: "Add item",
|
||||||
|
when: { path: "type", value: ["list", "links"] },
|
||||||
title: (row) => row.text || "New item",
|
title: (row) => row.text || "New item",
|
||||||
blank: { text: "" },
|
blank: { text: "" },
|
||||||
fields: [
|
fields: [
|
||||||
{ path: "text", label: "Text", required: true },
|
{ path: "text", label: "Text", required: true },
|
||||||
{ path: "detail", label: "Detail" },
|
{ path: "detail", label: "Detail", help: "Lists only: shown after the text" },
|
||||||
{ path: "url", label: "URL", help: "Blank for a plain list item" },
|
{ path: "url", label: "URL", help: "Blank for a plain list item. Link buttons need one." },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,16 @@ export type ContentBlock = {
|
||||||
| 'quote'
|
| 'quote'
|
||||||
| 'image'
|
| 'image'
|
||||||
| 'divider'
|
| 'divider'
|
||||||
|
| 'video'
|
||||||
|
| 'button'
|
||||||
|
| 'callout'
|
||||||
text?: string | null
|
text?: string | null
|
||||||
media?: string | null
|
media?: string | null
|
||||||
href?: string | null
|
href?: string | null
|
||||||
|
/** An image's alt text. */
|
||||||
|
alt?: string | null
|
||||||
|
/** Who a quote is by. */
|
||||||
|
cite?: string | null
|
||||||
items?: Array<{ text: string; detail?: string | null; url?: string | null }>
|
items?: Array<{ text: string; detail?: string | null; url?: string | null }>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue