Files
ipal-kit/docs/block-library.md
Radosław SmolińskiandClaude Fable 5.2 b91984fbcd IAPL rename: docs, agent guide, skills, reference site and starter on the new names; changelog draft
- docs, AGENT.md, the 16 skills, PROGRAMISTA and README use the preferred names (scripted, same list of forms);
  past CHANGELOG entries and the proposals in docs/dev are not rewritten
- AGENT.md: 'Names: IAPL and ipal-kit' — old name, new name, state in 1.x; what is not renamed; storageNames
- iapl-upgrade '→ 1.17.0', PROGRAMISTA §6 item 72, CHANGELOG 1.17.0 (draft): nothing required
- env.md, doctor.md (legacy-names, storage-names), stats.md, security.md, project-starter.md, iapl-reference, iapl-setup
- skill scripts read ipal-audit-skip and IPAL_IP_HEADER too; audit rule ids stay what they were
- reference site: iapl(), iapl-doctor.json, iapl-* skills, storageNames: 'iapl'; INDEX.md regenerated

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:36:09 +01:00

294 lines
22 KiB
Markdown

# Block library — ready page sections and page templates
Fifteen standard page sections (Payload block + React server component) and ten page templates,
so every site is assembled from the same parts. Each block is made of the plugin's building blocks
(`buildSectionHeaderField`, `buildLinksField`, `RenderForm`, `LightboxTrigger`, `RenderRichText`…),
has an editor panel in English and Polish (docs/dev/admin-ux.md), meets the accessibility rules below,
and is styled **only with the design-token utilities** (`bg-surface`, `text-fg`, `py-section`…).
Nothing is on by default. The project turns on the blocks it wants, and can change, swap or eject any
of them, or keep its own blocks in the same layout (CLAUDE.md main rule).
| Entry | What | Imported by |
|---|---|---|
| `@intecion/ipal-kit/blocks` | block configs, field builders, the manifest — no React | `payload.config`, collections |
| `@intecion/ipal-kit/blocks/rsc` | block components, UI primitives, `createBlockRegistry` | `src/blocks/registry.ts` |
| `@intecion/ipal-kit/templates` | page templates (seed data) | seed scripts only |
## Setup (a new site)
**1. Turn the blocks on in the Pages layout:**
```ts
// src/blocks/configs.ts — imported by src/collections/Pages.ts
import { libraryBlocks, type LibraryBlocksOptions } from '@intecion/ipal-kit/blocks'
export const blockOptions = {
hero: true, textMedia: true, featureGrid: true, cta: true, richText: true, faq: true, contact: true, gallery: true,
} satisfies LibraryBlocksOptions
export const pageBlocks = [
...libraryBlocks(blockOptions),
// the project's own blocks, e.g. TimelineBlock
]
// Pages.ts: { name: 'layout', type: 'blocks', blocks: pageBlocks }
```
The eight above are what every surveyed site built; add `testimonials`, `stats`, `steps`, `logos`, `team`,
`pricing`, `entryList` when the site map needs them. Fewer blocks = a shorter block picker for the editor.
**2. The registry** — every library block bound to lib/content, plus the project's own:
```ts
// src/blocks/registry.ts
import Image from 'next/image'
import Link from 'next/link'
import { createBlockRegistry } from '@intecion/ipal-kit/blocks/rsc'
import * as content from '@/lib/content'
import { sendForm } from '@/lib/sendForm'
import { formClasses } from '@/components/forms/formClasses'
export const blockRegistry = createBlockRegistry(content, {
Image, // next/image: optimized images with blur-up (without it: a plain <img>)
Link, // next/link: client-side navigation (without it: a plain <a>)
sendForm, // the contact block's form action (createSubmitAction, docs/forms.md)
formClassNames: formClasses,
// contactDetails: async (locale) => [{ label: 'Phone', value: '+48 …', href: 'tel:+48…' }],
// extra: { timeline: TimelineBlock },
})
```
The plugin never imports `next/*` itself, so `Image` and `Link` are passed in. `createPageRoute(content, { blocks: blockRegistry, … })`
or `<RenderBlocks components={blockRegistry} />` renders them (docs/frontend.md, docs/blocks.md).
**3. Styles.** The components use the token utilities of the design-token preset, and Tailwind must scan the
plugin's files. The standard `styles.css` ([design-tokens.md](./design-tokens.md)) already does both:
```css
@import "tailwindcss";
@import "@intecion/ipal-kit/fluid-wide.css";
@import "@intecion/ipal-kit/tokens.css";
@import "@intecion/ipal-kit/tailwind.css";
@import "../../design/tokens.css";
@source "../../../node_modules/@intecion/ipal-kit/dist/**/*.js";
```
**4. Also wire:** `<SiteProviders lightbox>` in the layout (gallery images open in the viewer, docs/lightbox.md) and
FAQ rich results: `getPageJsonLd(locale, slug, { faq: faqItemsFromLayout })` (docs/seo.md). For your own
`seo` pass-through: `faqItemsFromLayout(doc, { slugs: ['faq'] })`.
**5. Then:** `pnpm generate:types` · `pnpm payload generate:importmap` (the blocks use the plugin's row-label
component) · Postgres/SQLite: `pnpm payload migrate:create` and commit the migration (MongoDB needs none).
**Verify:** the block picker shows the blocks in the editor's language; adding each block shows at most six
fields; a page with every block renders (`pnpm build`); every section has `data-ipal-block="<slug>"` in the HTML; only the
first section's heading is `h1`; the gallery opens images in the viewer; `iapl-doctor` / `iapl-audit` report no block errors.
## The blocks
Every block has, in panel order: `header` (eyebrow, heading, intro) → its own fields → `links` (buttons, where the
block has them) → `variant` (sidebar) → `settings` (sidebar: anchor, background). Field names follow AGENT.md §6.5.
| Slug (builder) | Panel name | Own fields | Variants | Accessibility |
|---|---|---|---|---|
| `hero` (`buildHeroBlock`) | Hero / `Sekcja główna` | `media` (image or video), `poster` | `split`, `background`, `centered`, `page` | the first section's heading is the page `h1`; its image is the LCP image (eager, high priority); a background image is decorative (`alt=""`) under a full `bg-overlay` scrim (raise `--ipal-overlay` for very light photos) |
| `textMedia` (`buildTextMediaBlock`) | Text and image | `content` (rich text), `media` | `mediaRight`, `mediaLeft` | reading order = text first on every screen |
| `featureGrid` (`buildFeatureGridBlock`) | Feature grid | `items[]`: `icon` (with `icons`), `media`, `heading`, `text`, `link`; `columns` | `cards`, `list`, `numbered` | a linked feature: its heading is the link and covers the card; a dead link leaves plain text |
| `gallery` (`buildGalleryBlock`) | Gallery | `items[]`: `media`, `caption`; `columns` | `grid`, `masonry` | each image a `LightboxTrigger` (keyboard, focus return, labels from Form messages); captions in `<figcaption>` |
| `faq` (`buildFaqBlock`) | FAQ | `items[]`: `question`, `answer` | `single`, `twoColumn` | native `<details>`/`<summary>`, works without script |
| `cta` (`buildCtaBlock`) | Call to action | `media` | `band`, `card`, `split` | renders nothing without a heading and buttons |
| `contact` (`buildContactBlock`) | Contact | `form` (relation), `content` | `formWithDetails`, `formOnly` | `RenderForm` (labels, errors, consent); details as `<dl>`; the spam check widget turns dark in an inverted section |
| `team` (`buildTeamBlock`) | Team | `items[]`: `media`, `heading` (name), `text` (role), `bio`, `link` | `grid`, `list` | the name is the profile link |
| `pricing` (`buildPricingBlock`) | Pricing | `items[]`: `heading`, `price`, `period`, `text`, `features[]`, `highlighted`, `link`; `highlightLabel`, `note` | — | the highlighted plan carries a text label, not only a colour |
| `logos` (`buildLogosBlock`) | Logos | `items[]`: `media`, `heading` (name), `link` | `row`, `grid` | the name is the alt text when the image has none; no marquee |
| `testimonials` (`buildTestimonialsBlock`) | Testimonials | `items[]`: `quote`, `heading` (author), `text`, `media`, `rating`; with `collection`: `source`, `entries` | `grid`, `single` | `<figure>` + `<blockquote>` + `<figcaption>`; stars hidden, rating read as text |
| `stats` (`buildStatsBlock`) | Key figures / `Liczby` | `items[]`: `value`, `heading` (label), `text` | `row`, `cards` | a `<dl>`; static (no count-up animation) |
| `richText` (`buildRichTextBlock`) | Text | `content`, `tableOfContents` | `narrow`, `wide` | heading anchors + table of contents (`aria-current` on the section being read) |
| `steps` (`buildStepsBlock`) | Steps | `items[]`: `heading`, `text`, `media` | `numbered`, `timeline` | an `<ol>`; the number read as "Step 1" |
| `entryList` (`buildEntryListBlock`) | Entry list | `entryCollection`, `mode` (latest / chosen), `limit`, `entries` | `cards`, `list` | each title links to its entry and covers the card; dates in `<time>` |
**Rules every block meets:** one `<section>` with `aria-labelledby` its heading and `data-ipal-block`; `h1` only in the
first block (`isFirst` from `createPageRoute`), `h2` otherwise; **item headings one level below the section heading**
(`itemHeadingLevel`: `h3` under a section `h2`, `h2` under the page `h1`, and `h2` when the block shows no heading of its
own — a list right under the page header never jumps from `h1` to `h3`); images through `Media` (alt from the media
document, width and height, lazy) — **except the page's LCP image**: the first image of the block that leads the page
(`leadsWithImage`: the first section, or `firstImage` from `createPageRoute` — no block before it shows an image, e.g. an
entry list under a page header without a picture) loads eagerly with `fetchPriority="high"`, one per block; visible focus (`outline-focus`); no autoplay, motion only through
the token durations (0 ms under reduced motion); **an empty block renders nothing** (no empty section, no "Lorem").
**Visitor texts** the components write themselves — `rating` ("Rated {value} out of 5") and `step` ("Step {value}") —
ship in English and Polish (`BLOCK_TEXTS`, picked by `blockTexts(locale, own)`, `{value}` filled by `fillText`); other
languages or words: `createBlockRegistry(content, { texts: { de: { rating: '{value} von 5' } } })`. Everything else
comes from the panel.
## Change a block (schema)
`libraryBlocks(options, shared?)` takes a setting per block: `true`, an options object, a function `(block) => block`
that takes the finished block over, or `false`/missing = off. `shared` (`localization`, `settings`) applies to every
block; a block's own options win. Each block also has its own builder (`buildFaqBlock(options)` …, all in
`LIBRARY_BLOCK_BUILDERS`, slugs in `LIBRARY_BLOCK_SLUGS`).
| Option (`BlockOptions`) | Does |
|---|---|
| `slug` | keep an existing slug, e.g. `testimonials: { slug: 'reviews' }` (then `libraryBlockSlugs(options)` gives the registry and the templates the renamed slugs) |
| `interfaceName`, `labels`, `admin`, `custom` | the generated type name, the panel name, merged admin / custom |
| `fields` | an array replaces the fields; `(defaults) => fields` adds, changes or drops some — `replaceField(fields, 'media', { required: true })`, `removeField(fields, 'links')`, `isNamed(field, 'items')` |
| `variants` | a subset (`['single']`), the project's own (`{ label: { en, pl }, value }`), or `false` (no select). Unknown names throw (`pickVariants`) |
| `header`, `links`, `settings` | options for `buildSectionHeaderField`, `buildLinksField`, `buildSectionSettingsField` (e.g. project backgrounds); `header: false` / `links: false` drop them |
| `maxItems` | the `items` limit |
| `localization` | `'fields'` (default: text localized inside the block) or `'layout'` for projects that localize the whole `layout` field — drops every inner `localized` (`stripLocalized`) |
| `thumbnail` | the block picker picture: `true` = the plugin's sketch (an inline SVG from `blockThumbnail(slug)`, no route), a URL of your own, default none |
Block-specific options: `featureGrid: { icons: ['phone', 'mail'] }` (the project's icon names — adds an icon select;
the components come from `createBlockRegistry({ icons })`), `testimonials: { collection: 'testimonials' }` (pick from a
collection as well), `entryList: { collections: [{ label: { en: 'Projects', pl: 'Realizacje' }, value: 'projects' }] }`
(default posts), `contact: { formsCollection }` (default `forms`).
**Field names** never use a path name Mongoose reserves (`collection`, `schema`, `errors`, `get`, `set`…) — MongoDB is
on every live site and warns on each start (a test enforces it for the library; keep to it in your own `fields`).
**Same panel for the project's own blocks:** `buildItemsField({ fields, labels, rowLabelField, maxRows })`,
`buildMediaField()`, `buildVariantField({ options })`, `buildIconField({ names })`, `buildContentField()`,
`columnsField()` (values `COLUMNS`: `two`, `three`, `four`), `adminText(en, pl)`, `variantOption(value, en, pl)`, and
`defineLibraryBlock({ slug, interfaceName, labels, fields, links, variants })` for the same frame
(header → fields → buttons → variant → settings). `applyBlockOptions(block, options)` applies `BlockOptions` to any block.
## Change the look or the component (front end)
`createBlockRegistry(content, options)` returns the `blockType → component` map; `LIBRARY_BLOCK_COMPONENTS` lists the
plugin's components. `content` needs `resolveLink`; `getEntries` (entry list), `getFormTexts` and `getLinkOptions`
(contact) are used when present — pass the whole `@/lib/content`.
| Option (`BlockRegistryOptions`) | Does |
|---|---|
| `classNames` | replace the classes of one part: `{ faq: { item: 'border-b border-border' } }`. The parts and their defaults: `HERO_PARTS`, `TEXT_MEDIA_PARTS`, `FEATURE_GRID_PARTS`, `GALLERY_PARTS`, `FAQ_PARTS`, `CTA_PARTS`, `CONTACT_PARTS`, `TEAM_PARTS`, `PRICING_PARTS`, `LOGOS_PARTS`, `TESTIMONIALS_PARTS`, `STATS_PARTS`, `RICH_TEXT_PARTS`, `STEPS_PARTS`, `ENTRY_LIST_PARTS` |
| `ui` | swap a primitive for every block: `{ Media, CMSLink, Section, SectionHeader, Container, Card, buttonClass }` |
| `components` | replace one block's component; it gets the same props (`LibraryBlockProps`: the data, `locale`, `isFirst`, `ui`, `ctx`, `classNames`) |
| `backgrounds` | section background values → classes, merged over `SECTION_BACKGROUNDS` (`default`, `muted`, `inverted`) |
| `slugs`, `only`, `extra` | renamed slugs; only some blocks; the project's own blocks in the same map |
| `Image`, `Link` | next/image and next/link |
| `sendForm`, `formClassNames`, `contactDetails` | the contact block: form action, form classes, details beside the form |
| `entryCard`, `mapTestimonial` | how a collection document becomes an entry card / a testimonial (defaults `defaultEntryCard`, `defaultTestimonial`) |
| `noSnippet` | blocks kept out of Google's snippets (`<NoSnippet>`), e.g. `['cta']` when the same call to action is on every page (docs/seo.md) |
| `itemHeadings` | item heading level per block, e.g. `{ entryList: 'h3' }` (`h2` / `h3` / `h4`) — default: one below the section heading |
| `priorityImage` | `false` = never mark a block's first image as the LCP image (default on) |
| `icons`, `texts`, `lightbox`, `richText` | feature icons by name; visitor texts; `lightbox: false` = plain gallery images; `richText.className` for every rich text |
**UI primitives** (`/blocks/rsc`), each styled once with token utilities: `Section` (anchor, background,
`data-surface` for the inverted token scope, spacing, `Container`), `SectionHeader` (eyebrow, `h1`/`h2`, intro),
`Media` (image or video; `next/image` when passed; `resource` takes any media object, so generated `Media` types fit),
`CMSLink` (a panel link → `Anchor`, with `buttonClass`; a link that wraps something — a logo, a card — and leads nowhere
keeps its content without a link, so an empty link group never hides it),
`buttonClass` / `BUTTON_CLASSES` (button looks by appearance), `Container` / `CONTAINER_WIDTHS`, `Card` / `CARD_CLASS` /
`CARD_INTERACTIVE_CLASS`. Helpers for the project's own blocks: `Buttons` (a block's button row), `headingId(block)`
(the heading id for `aria-labelledby`), `TitleLink` (a card title that links when its link resolves), `GRID_COLUMNS`,
`cx`, `parts(defaults, overrides)`, `itemHeadingLevel(slug, props)` (the item heading tag) and `leadsWithImage(props)`
(whether the block's first image is the LCP image).
**Every component is exported** (`HeroBlock`, `TextMediaBlock`, `FeatureGridBlock`, `GalleryBlock`, `FaqBlock`, `CtaBlock`,
`ContactBlock`, `TeamBlock`, `PricingBlock`, `LogosBlock`, `TestimonialsBlock`, `StatsBlock`, `RichTextBlock`,
`StepsBlock`, `EntryListBlock`) for a project that wires them without the factory.
**Section backgrounds and tokens.** `settings.background` → `default` `bg-bg text-fg`, `muted` `bg-surface-muted`
(+ `data-surface="muted"`), `inverted` `bg-inverse text-on-inverse` + `data-surface="inverse"`; inside the inverse
scope the token preset re-maps text, borders, links and focus, so blocks use plain `text-fg`, `text-link`,
`border-border`. No hex, no `dark:` for colours, no `clamp()` in the components (a test enforces it).
## Own blocks and eject
A section no library block or variant fits → the project's own block (**iapl-block** skill): `src/blocks/<Name>/`,
the same field builders and primitives, added to `pageBlocks` and to `extra` in the registry.
To own a library block completely:
```bash
pnpm exec iapl-blocks list
pnpm exec iapl-blocks eject faq # → src/blocks/Faq/config.ts + Component.tsx
```
Eject copies the block's source with its imports pointing at the package entries (same slug, same data shape —
no migration). Then use the ejected `buildFaqBlock` in `pageBlocks` (instead of `faq: true`), pass
`components: { faq: FaqBlock }` to the registry, and record it in AGENTS.md → "Project decisions". It never
overwrites an existing file (`--dest`, `--dry-run`).
## Page templates
`pageTemplates` (`@intecion/ipal-kit/templates`) — pages made of library blocks, every text in English and Polish,
`[TO FILL: …]` where only the client can write. Data for `createSeeder` (docs/seeding.md); nothing changes in the panel.
| Template | Layout | System page role |
|---|---|---|
| `home()` | hero · logos · featureGrid · textMedia · stats · testimonials · faq · cta | `homepage` |
| `about()` | hero (page) · textMedia · stats · team · steps · cta | — |
| `services()` | hero (page) · featureGrid · steps · pricing · faq · cta | — |
| `service({ form? })` | hero · textMedia · featureGrid (list) · gallery · faq · contact | — |
| `contact({ form })` | hero (page) · contact · faq | — |
| `blogIndex()` | hero (page) · cta — the entries come from the archive view (docs/content.md) | `postsArchive` |
| `post({ title })` | hero (page, the post title as `h1`) · richText (table of contents) · entryList · cta — for a posts collection with a `layout` field | — |
| `legal('privacyPolicy' \| 'termsOfService')` | hero (page) · richText (table of contents), `noindex: true` — structure only; the wording comes from the client | `privacyPolicy`, `termsOfService` |
| `cookiePolicy()` | hero (page) · richText, `noindex: true` | `cookiePolicy` |
| `notFound()` | hero (page) with a button home | `notFound` |
```ts
// scripts/seed-content.ts
import { libraryBlockSlugs } from '@intecion/ipal-kit/blocks'
import { pageTemplates, systemPageRefs } from '@intecion/ipal-kit/templates'
import { blockOptions } from '@/blocks/configs' // the object passed to libraryBlocks
const blocks = libraryBlockSlugs(blockOptions) // blocks that are off are left out (with a warning)
await seed.upsertBy('forms', { title: 'Contact form' }, CONTACT_FORM)
await seed.upsertBySlug('pages', [
pageTemplates.home({ blocks, overrides: { hero: { header: { heading: { pl: '…', en: '…' } } } } }),
pageTemplates.contact({ blocks, form: { $form: 'Contact form' } }),
pageTemplates.legal('privacyPolicy', { blocks }),
])
await seed.fillGlobal('site-settings', systemPageRefs({ homepage: 'start', privacyPolicy: 'polityka-prywatnosci' }))
```
Template options (`TemplateOptions`): `blocks` (turned-on blocks with renamed slugs), `overrides` (data per block),
`layout` (`(blocks) => blocks` to reorder, drop or add), `slug`, `title`, `defaultLocale` (buttons link to pages by
their slug in it; default `pl`), `linkTo` (the slugs of the about / contact / home pages when yours differ).
`{ $form: 'title' }` and `{ $page: 'slug' }` are seed references (docs/seeding.md).
**After launch — named records only** (AGENT.md "Seeding on production", docs/seeding.md): use a template only through a
seed that names its records — `SEED_ONLY="pages:kontakt" pnpm payload run scripts/seed-content.ts` after
`SEED_DRY_RUN=1` and a Coolify backup — never a run of every template. Seeds stay create-only; a page an editor
changed is skipped. A newer IAPL never changes existing pages: templates are only read when a seed runs.
## Versioning — new fields never break content
- A minor release only **adds**: new optional fields (or with a `defaultValue`), new variant values. A component renders
the old output while a new field is empty.
- Never in a minor: renaming or removing a stored field, a select value, a slug or an `interfaceName`; a new
required field; a field becoming required. A rename happens only in a major, with an **iapl-migrate-fields** recipe
and upgrade notes.
- Database names come from the slugs and field names only — never from labels — so renaming a panel label changes no
table, column or enum.
- `test/blockLibrarySchema.test.ts` compares every block's field paths, types, select values and required flags with
`test/block-library.schema.json` and fails on any of the above.
- Upgrade notes list every new field. Postgres/SQLite: a new field needs `pnpm payload migrate:create` in the project;
MongoDB needs nothing.
## Manifest (for checks)
`blockLibraryManifest` (`/blocks`) is plain data built from the block configs: every block's `slug`, `interfaceName`,
`variants` and stored `fields` (paths from `fieldPaths(fields)`), the `primitives` a project may swap, the
`fieldBuilders` a project block should use instead of its own copy, and the `templates`. `iapl-doctor` reads its names
from here. `buildBlockLibraryManifest()` builds it again (e.g. in a test).
## Turn off, override, extend
| What | Default | Turn off / override |
|---|---|---|
| Any block | off | `libraryBlocks({ faq: true })`; your own block next to it |
| Fields, labels, variants, slug | the library's | `BlockOptions` per block, or `(block) => block` |
| Look of one part | token classes (`*_PARTS`) | `classNames` per block and part |
| A primitive | the plugin's | `ui: { Media, CMSLink, … }` |
| A block's component | the plugin's | `components: { faq: MyFaq }`, or eject |
| Images / links | `<img>` / `<a>` | `Image` / `Link` (next/image, next/link) |
| Lightbox on gallery images | on | `lightbox: false` |
| Visitor texts | `en`, `pl` | `texts` |
| Picker thumbnails | off | `thumbnail: true` or a URL |
| Localization | inside the blocks | `localization: 'layout'` |
| The whole library | not used | don't import it — `RenderBlocks` and the field builders work as before (docs/blocks.md) |