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:
Zaldimmar 2026-09-27 16:50:21 -05:00
parent c62dc84add
commit c5f12c769f
13 changed files with 723 additions and 169 deletions

View file

@ -1,55 +1,41 @@
/* ═══════════════════════════════════════════════════════════════
CONTENT BLOCKS
Renders the `body` slot of content_blocks. Events, organizations
and teams all own blocks and all render them the same way, so
this is written once and tinted by the caller's accent.
Renders the `body` slot of content_blocks. Events, organizations,
teams, people and blog posts all own blocks and all render them
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`,
`text`, `media`, `href` and an `items` array. If the field names
differ, this is the only file to fix — nothing else reads a
block.
What each type reads (see 032_content_block_types.sql):
heading, subheading text
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
disappearing. A block somebody typed into the admin should be
visible even if the renderer hasn't caught up with it.
═══════════════════════════════════════════════════════════════ */
import { Link } from 'react-router-dom'
import { blockMedia } from '../lib/media.ts'
import type { ContentBlock } from '../lib/useContent.ts'
import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
import VideoPlayer from './VideoPlayer.tsx'
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({
blocks,
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 }) {
const text = block.text ?? ''
@ -102,11 +97,9 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
{item.text}
</Anchor>
) : (
item.text
)}
{item.detail && (
<span className="opacity-70"> — {item.detail}</span>
<Inline text={item.text} accent={accent} />
)}
{item.detail && <span className="opacity-70">: {item.detail}</span>}
</span>
</li>
))}
@ -131,14 +124,43 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
</div>
)
case 'button':
if (!text || !block.href) return null
return (
<div>
<Anchor
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}
</Anchor>
</div>
)
case 'quote':
return (
<blockquote
className="border-l-2 pl-5 text-lg italic"
style={{ borderColor: accent, color: BODY }}
<figure className="border-l-2 pl-5" style={{ borderColor: accent }}>
<blockquote className="text-lg italic" style={{ color: BODY }}>
<Inline text={text} accent={accent} />
</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' }}
>
{text}
</blockquote>
<Paragraphs text={text} accent={accent} />
</aside>
)
case 'image': {
@ -147,10 +169,9 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
const img = (
<img
src={src}
// A caption is a caption, not alt text — but an image with
// neither is decorative, and alt="" is the correct answer
// for that rather than a filename read aloud.
alt={text}
// Alt describes the picture; the caption describes the
// moment. No alt means decorative, which alt="" says.
alt={block.alt ?? ''}
loading="lazy"
decoding="async"
className="w-full rounded-lg"
@ -159,31 +180,38 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {
return (
<figure>
{block.href ? <Anchor href={block.href}>{img}</Anchor> : img}
{text && (
<figcaption className="mt-2 text-sm opacity-70" style={{ color: BODY }}>
{text}
</figcaption>
)}
<Caption text={text} />
</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':
return <hr className="border-0 h-px" style={{ background: accent, opacity: 0.3 }} />
case 'paragraph':
default:
if (!text) return null
return (
return block.href ? (
<p className="leading-relaxed" style={{ color: BODY }}>
{block.href ? (
<Anchor href={block.href} className="underline" style={{ color: accent }}>
{text}
</Anchor>
) : (
text
)}
<Anchor href={block.href} className="underline" style={{ color: accent }}>
{text}
</Anchor>
</p>
) : (
<div className="space-y-4">
<Paragraphs text={text} accent={accent} className="leading-relaxed" style={{ color: BODY }} />
</div>
)
}
}