Add a Schedule content block with day tabs

A schedule block's entries (migration 034) each have a day, time,
title, detail, location, person and link, and fold out for a longer
description, the person's photo and page, a graphic and a Google map
of a place or address. Entries sit in one tab per day, in the order
entered; the tab for today's weekday opens first, and a one-day
schedule draws no tabs.

In the editor, the entry fields show only under a schedule block:
repeater `when` can now look at the parent row (scope "parent"), and
a field's label can depend on the row. The block preview names an
entry's person. The showcase retreat and post each have a schedule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-27 21:12:47 -05:00
parent d6477b6d30
commit 71a470b66f
10 changed files with 556 additions and 29 deletions

View file

@ -32,12 +32,17 @@
can't keep a value for a choice it no longer makes: a featured
card switched from "record" to "link" drops its record.
`when: { scope: "parent", path, value }` looks at the row this
collection belongs to instead: a schedule entry shows its day and
time only while the block above it is a schedule.
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).
`help` and `label` may be functions of the row, for wording 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
@ -78,7 +83,24 @@ 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]} />,
// The form holds an entry's person as person_id; the renderer wants
// the person, so it's looked up in the select options (a name, no
// photo: the options carry no more).
contentBlock: (row, options) => (
<ContentBlocks
blocks={[
{
...row,
items: (row.items ?? []).map((item) => {
const person = item.person_id
? options?.people?.find((p) => p.id === item.person_id)
: null;
return { ...item, person: person ? { id: person.id, name: person.label } : null };
}),
},
]}
/>
),
};
const input =
@ -118,25 +140,33 @@ export function setPath(object, path, value) {
/* ── Conditional fields ──────────────────────────────────────── */
export function fieldShown(field, row) {
export function fieldShown(field, row, parent?) {
if (!field.when) return true;
const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value];
return want.includes(row?.[field.when.path]);
const source = field.when.scope === "parent" ? parent : row;
return want.includes(source?.[field.when.path]);
}
/* A row after an edit, with any field the edit hid cleared. "" is
the engine's deliberate clear, so it saves as NULL. */
function withHiddenCleared(spec, row) {
function withHiddenCleared(spec, row, parent?) {
let next = row;
for (const field of spec.fields) {
const value = next[field.path];
if (!fieldShown(field, next) && value != null && value !== "") {
if (!fieldShown(field, next, parent) && value != null && value !== "") {
next = { ...next, [field.path]: "" };
}
}
for (const nested of spec.children ?? []) {
if (!fieldShown(nested, next) && next[nested.key]?.length) {
const rows = next[nested.key];
if (!rows?.length) continue;
if (!fieldShown(nested, next, parent)) {
next = { ...next, [nested.key]: [] };
} else {
// Its rows may have fields that follow this row (scope
// "parent"), which this edit may just have hidden.
const cleared = rows.map((child) => withHiddenCleared(nested, child, next));
if (cleared.some((child, i) => child !== rows[i])) next = { ...next, [nested.key]: cleared };
}
}
return next;
@ -197,7 +227,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
return (
<div className={field.full ? "sm:col-span-2" : ""}>
<label htmlFor={id} className="block text-sm font-medium text-[#26454c]">
{field.label}
{typeof field.label === "function" ? field.label(row) : field.label}
{field.required && !locked && <span className="ml-1 text-[#b3261e]">*</span>}
</label>
@ -357,6 +387,7 @@ export function Repeater({
errorPrefix,
onChange,
className = "mt-8",
parentRow = undefined,
}: any) {
const list = rows ?? [];
@ -382,7 +413,7 @@ export function Repeater({
const rowRefs = useRef<any[]>([]);
const update = (index, next) =>
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec, next) : row)));
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec, next, parentRow) : row)));
const move = (index, delta) => {
const target = index + delta;
@ -593,7 +624,7 @@ export function Repeater({
<>
<FieldGrid>
{spec.fields
.filter((field) => fieldShown(field, row))
.filter((field) => fieldShown(field, row, parentRow))
.map((field) => (
<Field
key={field.path}
@ -609,7 +640,7 @@ export function Repeater({
</FieldGrid>
{(spec.children ?? [])
.filter((nested) => fieldShown(nested, row))
.filter((nested) => fieldShown(nested, row, parentRow))
.map((nested) => (
<div key={nested.key} className="mt-4 border-t border-[#4a6b72]/15 pt-4">
<Repeater
@ -618,6 +649,7 @@ export function Repeater({
options={options}
errors={errors}
errorPrefix={`${errorPrefix}${index}.${nested.key}.`}
parentRow={row}
className=""
onChange={(value) => update(index, { ...row, [nested.key]: value })}
/>
@ -629,7 +661,7 @@ export function Repeater({
<p className="mb-3 text-xs font-semibold uppercase tracking-wider text-[#4a6b72]/70">
Preview
</p>
{PREVIEWS[spec.preview](row)}
{PREVIEWS[spec.preview](row, options)}
</div>
)}
</>