Found by ipal-doctor live-seo on the reference archive pages (entry list under a
page header without a picture): cards jumped h1 → h3, and the first card image
was lazy.
- itemHeadingLevel: items one below the section heading (h3 under h2, h2 under the
page h1, h2 when the block shows no heading); createBlockRegistry({ itemHeadings })
fixes a level per block. featureGrid, entryList, pricing, steps, team.
- blockPosition / blockHasImage (root): createPageRoute and the 404 view pass
firstImage next to isFirst; leadsWithImage marks the first image of the leading
block eager + fetchPriority high (hero, textMedia, featureGrid, gallery, team,
entryList); priorityImage: false turns it off.
- reference/ipal-doctor.json: the two live-seo silences removed; reference skills
and docs/agent/reference-site/INDEX.md refreshed.
- bin/ipal-blocks.mjs executable like the other bins.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
125 lines
5.4 KiB
Markdown
125 lines
5.4 KiB
Markdown
# blocks
|
|
|
|
> **Ready sections:** the plugin ships fifteen standard blocks (hero, FAQ, gallery, contact…) and page
|
|
> templates — [block-library.md](./block-library.md). Use a library block or a variant of one first; this page
|
|
> describes the engine and the field builders they are made of, which your own blocks use too.
|
|
|
|
`RenderBlocks` — a generic, server-side block rendering engine. The plugin does not
|
|
know your blocks: it iterates over the data, maps `blockType` → component through a
|
|
registry (prop), handles nesting and per-block extensions. You define the blocks
|
|
(schema + components) in your project.
|
|
|
|
## Config
|
|
|
|
No options in payload.config — you define blocks in your collections
|
|
(a `blocks` type field). The plugin provides only the rendering engine.
|
|
|
|
## ⚠️ Do NOT write your own block renderer (switch)
|
|
|
|
**The block renderer is `RenderBlocks` from the plugin — NEVER your own `switch`/`if`.**
|
|
Common mistake: the project writes its own `BlockRenderer` with `switch (block.blockType)`
|
|
and 20 cases. That breaks A0 — the plugin has the engine, the project provides only the
|
|
component MAP.
|
|
|
|
```tsx
|
|
// WRONG — own switch in the project (verbose, no enhanceProps, grows linearly)
|
|
switch (block.blockType) {
|
|
case 'hero': return <Hero {...block} />
|
|
case 'faq': return <FAQ {...block} />
|
|
// ...20 cases
|
|
}
|
|
|
|
// RIGHT — map + RenderBlocks (engine from the plugin)
|
|
const registry = { hero: Hero, faq: FAQ, /* ... */ }
|
|
<RenderBlocks blocks={page.layout} components={registry} />
|
|
```
|
|
|
|
Why RenderBlocks, not a switch: enhanceProps (nav anchors, etc.), guards, nesting
|
|
support, consistency across projects. A switch has none of this and grows with
|
|
every block. The map is flat and declarative.
|
|
|
|
## Front — RenderBlocks
|
|
|
|
Import from `@intecion/ipal-kit/rsc` (it is a server component):
|
|
|
|
```tsx
|
|
import { RenderBlocks } from '@intecion/ipal-kit/rsc'
|
|
|
|
// Your registry: blockType → component (the components are yours)
|
|
import { Hero } from '@/blocks/Hero'
|
|
import { FormBlock } from '@/blocks/FormBlock'
|
|
|
|
const registry = { hero: Hero, formBlock: FormBlock }
|
|
|
|
export default async function Page() {
|
|
const page = await payload.findByID({ collection: 'pages', id })
|
|
return <RenderBlocks blocks={page.layout} components={registry} />
|
|
}
|
|
```
|
|
|
|
- unknown `blockType` → skipped (null), does not crash
|
|
- `blocks` empty / `null` → `null`
|
|
- nested blocks: the parent component renders `<RenderBlocks>` itself and **imports the
|
|
registry itself** — the engine does NOT pass the map in props (functions do not cross the
|
|
server→client boundary in RSC)
|
|
|
|
## enhanceProps — per-block logic without the plugin knowing
|
|
|
|
When a block needs data from other blocks (e.g. a nav collecting anchors
|
|
from sections), pass `enhanceProps`. The plugin calls it without knowing your blocks:
|
|
|
|
```tsx
|
|
// arguments: { block, allBlocks, index }
|
|
const enhanceProps = ({ block, allBlocks }) => {
|
|
if (block.blockType !== 'sectionNav') return {}
|
|
const sections = allBlocks
|
|
.filter((b) => b.blockType === 'anchoredSection')
|
|
.map((b) => ({ anchor: b.anchor, label: b.navLabel }))
|
|
return { _sections: sections }
|
|
}
|
|
|
|
<RenderBlocks blocks={page.layout} components={registry} enhanceProps={enhanceProps} />
|
|
```
|
|
|
|
## Shared section fields — `buildSectionHeaderField`, `buildSectionSettingsField`
|
|
|
|
```ts
|
|
import { buildLinksField, buildSectionHeaderField, buildSectionSettingsField } from '@intecion/ipal-kit'
|
|
|
|
fields: [
|
|
buildSectionHeaderField(), // `header` group: eyebrow, heading, intro (localized) — type SectionHeaderData
|
|
…block fields…,
|
|
buildLinksField(),
|
|
buildSectionSettingsField(), // `settings` sidebar: anchor, background — type SectionSettings
|
|
]
|
|
```
|
|
Default: `header` (interface `SectionHeaderData`), `settings` in the sidebar (interface `SectionSettings`)
|
|
with `anchor` and `background` (`default` / `muted` / `inverted`, the first value by default).
|
|
Everything can be changed: `buildSectionSettingsField({ backgrounds: [{ label: 'Brand', value: 'brand' }], anchor: false,
|
|
fields: [{ name: 'spacing', … }] })`, `backgrounds: false` (no background choice), `buildSectionHeaderField({ name, fields,
|
|
interfaceName })`. The project maps the background values to its `<Section>` classes. The data shape matches the former
|
|
`src/fields/sectionHeader.ts` / `sectionSettings.ts` from section-code.md — swapping the import needs no migration.
|
|
|
|
## Block component
|
|
|
|
Each component gets the block data as props (plus whatever `enhanceProps` returns;
|
|
in `createPageRoute` also `locale`, `isFirst`, `firstImage` and `blockProps` — frontend.md; `blockPosition` computes the
|
|
two for your own `enhanceProps`). Spacing/layout are yours — the engine does not wrap
|
|
blocks in any markup.
|
|
|
|
```tsx
|
|
export function Hero(props) {
|
|
return <section className="py-16">{/* ... */}</section>
|
|
}
|
|
```
|
|
|
|
Types: `BlockComponentMap`, `BlockData`, `EnhanceProps`, `RenderBlocksProps` (`/rsc`),
|
|
`SectionHeaderFieldOptions`, `SectionSettingsFieldOptions` (root).
|
|
|
|
## Turn off, override, extend
|
|
|
|
- The module has no options in `ipalKit()` — it adds nothing to the schema; you either use `RenderBlocks` or not.
|
|
- The project keeps the component map and the block schemas; add per-block logic through `enhanceProps`.
|
|
- `buildSectionHeaderField` / `buildSectionSettingsField`: `name`, `fields` (extra fields), `interfaceName`, `anchor: false`, `backgrounds: […] | false`.
|
|
- The engine does not wrap blocks in markup and has no wrapper option — the project component does the wrapping.
|