Files
ipal-kit/docs/blocks.md
T
Radosław SmolińskiandClaude Opus 5.5 2a07fb8844 Block library: docs, agent guide, skills; picker order as an explicit list
- docs/block-library.md: setup, every block (fields, variants, accessibility),
  options, registry, primitives, eject, page templates, seeding after launch,
  versioning, manifest, turn off / override / extend
- AGENT.md (compass, how to add, §6, §6.3, module map), ipal-block (library
  block first), ipal-site (phases 2, 4, 6, 8), ipal-reference (wiring rows,
  export index), seed-content template from pageTemplates, seeding.md ($form)
- CHANGELOG Unreleased; proposal marked built with an as-built section

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 14:12:50 +01:00

5.3 KiB

blocks

Ready sections: the plugin ships fifteen standard blocks (hero, FAQ, gallery, contact…) and page templates — 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.

// 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):

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:

// 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

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 and blockProps — frontend.md). Spacing/layout are yours — the engine does not wrap blocks in any markup.

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.