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
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
import { preview } from "./text.ts";
|
||||
import { PLATFORMS } from "./platforms.ts";
|
||||
import { FORMATTING_HELP } from "../components/InlineText.tsx";
|
||||
import {
|
||||
awardLogo,
|
||||
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 = {
|
||||
key: "content_blocks",
|
||||
label: "Content blocks",
|
||||
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: "" },
|
||||
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",
|
||||
label: "Type",
|
||||
widget: "select",
|
||||
options: [
|
||||
"heading",
|
||||
"subheading",
|
||||
"paragraph",
|
||||
"list",
|
||||
"links",
|
||||
"quote",
|
||||
"image",
|
||||
"divider",
|
||||
],
|
||||
options: BLOCK_TYPES.map(([value, label]) => [value, label]),
|
||||
help: (row) => BLOCK_TYPES.find(([value]) => value === row?.type)?.[2],
|
||||
},
|
||||
{
|
||||
path: "text",
|
||||
label: "Text",
|
||||
widget: "textarea",
|
||||
full: true,
|
||||
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: [
|
||||
{
|
||||
key: "items",
|
||||
label: "Items",
|
||||
addLabel: "Add item",
|
||||
when: { path: "type", value: ["list", "links"] },
|
||||
title: (row) => row.text || "New item",
|
||||
blank: { text: "" },
|
||||
fields: [
|
||||
{ path: "text", label: "Text", required: true },
|
||||
{ path: "detail", label: "Detail" },
|
||||
{ path: "url", label: "URL", help: "Blank for a plain list item" },
|
||||
{ path: "detail", label: "Detail", help: "Lists only: shown after the text" },
|
||||
{ path: "url", label: "URL", help: "Blank for a plain list item. Link buttons need one." },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -31,9 +31,16 @@ export type ContentBlock = {
|
|||
| 'quote'
|
||||
| 'image'
|
||||
| 'divider'
|
||||
| 'video'
|
||||
| 'button'
|
||||
| 'callout'
|
||||
text?: string | null
|
||||
media?: 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 }>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue