- Forms: step and checkboxGroup field types (radio, date on), server validation for them, useBuilderForm (logic) + BuilderForm (unstyled default) + RenderForm (/rsc: rich text, bound action, public part of the form only — the Emails tab never reaches the browser) - Notifications: next / back / stepOf texts - createContentHelpers: getSiteShell, getFormTexts, getLinkOptions, resolveLink, resolveNav, resolvePageRedirect, one-line route handlers (llms, llms-full, md, mcp, health, indexnow, manifest) - /rsc: SiteProviders, createPageRoute, createNotFoundPage - resolveLink / resolveNav / homeSlugFrom, buildSectionHeaderField / buildSectionSettingsField - Dev sandbox frontend built on these imports; tests (unit + real Payload) Co-Authored-By: Claude Opus 5.5 <[email protected]>
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import type { Field, GroupField } from 'payload'
|
|
|
|
/**
|
|
* The two field groups every section block shares — same panel, same data
|
|
* shape in every project, so the shared <Section>/<SectionHeader> components
|
|
* work on every block. Everything is overridable: names, options, extra fields.
|
|
*
|
|
* fields: [buildSectionHeaderField(), …the block's own fields…, buildSectionSettingsField()]
|
|
* fields: [buildSectionSettingsField({ backgrounds: [{ label: 'Brand', value: 'brand' }] })]
|
|
*/
|
|
|
|
export type SectionHeaderFieldOptions = {
|
|
/** Extra fields inside the group (e.g. a heading level select). */
|
|
fields?: Field[]
|
|
/** Generated TS type name. Default 'SectionHeaderData'. */
|
|
interfaceName?: string
|
|
/** Default 'header'. */
|
|
name?: string
|
|
}
|
|
|
|
/** eyebrow + heading + intro, localized — rendered by the project's <SectionHeader>. */
|
|
export function buildSectionHeaderField({ name = 'header', fields = [], interfaceName = 'SectionHeaderData' }: SectionHeaderFieldOptions = {}): GroupField {
|
|
return {
|
|
name,
|
|
type: 'group',
|
|
fields: [
|
|
{ name: 'eyebrow', type: 'text', admin: { description: 'Small line above the heading. Optional.' }, localized: true },
|
|
{ name: 'heading', type: 'text', localized: true },
|
|
{ name: 'intro', type: 'textarea', admin: { rows: 3 }, localized: true },
|
|
...fields,
|
|
],
|
|
interfaceName,
|
|
}
|
|
}
|
|
|
|
export type SectionSettingsFieldOptions = {
|
|
/** Section #id for anchor links and a section nav. Default true. */
|
|
anchor?: boolean
|
|
/**
|
|
* Background choices — values map to the project's own classes in <Section>.
|
|
* Default Default / Muted / Inverted (dark). `false` → no background select.
|
|
*/
|
|
backgrounds?: { label: string; value: string }[] | false
|
|
/** Extra settings (e.g. spacing, width). */
|
|
fields?: Field[]
|
|
/** Generated TS type name. Default 'SectionSettings'. */
|
|
interfaceName?: string
|
|
/** Default 'settings'. */
|
|
name?: string
|
|
}
|
|
|
|
const DEFAULT_BACKGROUNDS = [
|
|
{ label: 'Default', value: 'default' },
|
|
{ label: 'Muted', value: 'muted' },
|
|
{ label: 'Inverted (dark)', value: 'inverted' },
|
|
]
|
|
|
|
/** Sidebar group: anchor + background (+ your own) — instead of bgColor / sectionId per block. */
|
|
export function buildSectionSettingsField({
|
|
name = 'settings',
|
|
anchor = true,
|
|
backgrounds = DEFAULT_BACKGROUNDS,
|
|
fields = [],
|
|
interfaceName = 'SectionSettings',
|
|
}: SectionSettingsFieldOptions = {}): GroupField {
|
|
return {
|
|
name,
|
|
type: 'group',
|
|
admin: { position: 'sidebar' },
|
|
fields: [
|
|
...(anchor
|
|
? [{ name: 'anchor', type: 'text', admin: { description: 'Section id for #links and section nav, e.g. "pricing".' } } as Field]
|
|
: []),
|
|
...(backgrounds && backgrounds.length
|
|
? [{ name: 'background', type: 'select', defaultValue: backgrounds[0].value, options: backgrounds } as Field]
|
|
: []),
|
|
...fields,
|
|
],
|
|
interfaceName,
|
|
label: 'Section settings',
|
|
}
|
|
}
|