486 lines
33 KiB
Markdown
486 lines
33 KiB
Markdown
# Block library — proposal
|
||
|
||
> **Status:** approved design, not built. The owner accepted every recommendation, D1–D10, on 2026-10-29 (§12).
|
||
> Building starts when the coordinator confirms that all five designs (tokens, blocks, reference site,
|
||
> doctor, starter) are in and consistent.
|
||
> **Scope:** a shared set of page blocks and page templates in `@intecion/ipal-kit`, so agents
|
||
> assemble pages from standard parts instead of rebuilding them on each site.
|
||
> **Related tracks:** design tokens standard (token names, §6), project starter and reference
|
||
> site (consumers, §10), `ipal-doctor` (conformance checks, §10).
|
||
|
||
---
|
||
|
||
## 1. Why
|
||
|
||
Seven client sites (`/Users/rasm/Projects/Payload/*-web`) have built **about 170 blocks** between
|
||
them. Almost every site rebuilt the same ten blocks (hero, CTA, rich text, text with image,
|
||
feature cards, FAQ, contact form, testimonials, gallery, stats). The field names, panel labels,
|
||
localization model and accessibility differ from site to site. An agent that starts a new site
|
||
copies the closest older site and inherits its quirks.
|
||
|
||
Today the plugin ships the **engine and the building blocks** (`RenderBlocks`, `buildSectionHeaderField`,
|
||
`buildSectionSettingsField`, `buildLinkField(s)`, `rowLabel`, `RenderForm`, `LightboxTrigger`,
|
||
`RenderRichText`, `buildFaqJsonLd`, `CookieTable`, `buildTableOfContentsField`). It ships **no
|
||
blocks**. The `ipal-block` skill gives patterns (`section-code.md`) that every project copies by hand.
|
||
|
||
The library adds the next layer: **ready blocks (schema + component) built from those parts**. The
|
||
project can still turn any of them off, change its fields, swap its component or add its own blocks.
|
||
|
||
## 2. Survey
|
||
|
||
### 2.1 Blocks per site
|
||
|
||
| Site | ipal-kit | Blocks | Uses plugin section fields |
|
||
|---|---|---|---|
|
||
| architektimprezpl-web | 1.14.6 | 20 | yes, plus a local `adminLabels` map |
|
||
| coastalclimatesupplycomau-web | 1.14.1 | 30 | mostly no: local `buildActionButtonsField`, `buildMetricsField`, `buildStatsField` |
|
||
| ecogenicacouk-web | 1.14.1 | 14 | yes, plus a local `buildItemsField` |
|
||
| intecioncom-web | 1.14.6 | 44 | yes |
|
||
| saydiamondspl-web | 1.11.0 | 15 | yes |
|
||
| thecleanteampl-web | ^1.12.2 | 11 | yes |
|
||
| vanstevpl-web | 1.12.2 | 25 | **no**: `ctaLabel`/`ctaTarget`/`url` fields, local `ctaHref.ts` |
|
||
|
||
### 2.2 The common set (how many of the 7 sites built it)
|
||
|
||
| Block kind | Sites | Names found |
|
||
|---|---|---|
|
||
| Hero (incl. a smaller page hero) | 7 | `hero`, `pageHero`, `simpleHero`, `videoHero`, `aboutHero`, `trustHero`, `hotWaterHero`, `productEnquiryHero` |
|
||
| CTA band | 7 | `cta`, `ctaBanner`, `ctaBand`, `bannerCta`, `ctaSection`, `callout`, `textCta`, `joinBanner`, `trustCta` |
|
||
| Rich text section | 7 | `richText`, `content`, `fullContent`, `textSection`, `introText`, `legal` |
|
||
| Contact / form | 7 | `formBlock`, `contact`, `contactBlock`, `contactSection`, `contactDetails`, `freeQuote`, `consultationCta` |
|
||
| Text with image | 7 | `imageText`, `imageStory`, `about`, `serviceIntro`, `textWithFacts`, `twoColumnWhy` |
|
||
| Feature / card grid | 7 | `featureGrid`, `features`, `uspList`, `infoGrid`, `servicesGrid`, `reasonCards`, `audienceCards`, `categoryGrid`, `offer`, `services`, `values`… |
|
||
| FAQ | 5 | `faq` (4 × `items[].question/answer`, 1 × `heading/text`) |
|
||
| Testimonials | 5 | `testimonials`, `testimonial`, `reviews`, `trustReviews` (inline items or a relation to a collection) |
|
||
| Gallery | 4 | `gallery`, `galleryMasonry`, `galleryStrip`, `photoGallery` (lightbox in 1 site) |
|
||
| Stats | 4 | `statsCounter`, `statsStrip`, `stats`, hero `metrics` |
|
||
| Steps / process | 4 | `processSteps`, `process`, `guideSteps`, `storySteps`, `numberedList`, `whyUsTimeline` |
|
||
| List of collection entries | 4 | `blogList`, `projectList`, `projects`, `featuredProducts`, `products`, `jobsList` |
|
||
| Pricing | 2 | `pricingTiers`, `pricing` |
|
||
| Logos | 2 | `clientLogos`, `certificates` |
|
||
| Tabs / accordion with content | 2 | `featureTabs`, `systemTabs`, `splitAccordion` |
|
||
| Video section | 1 | `videoShowcase` (+ `videoHero`) |
|
||
| Team | 1 | `teamGrid` |
|
||
| Map | 1 | `mapEmbed` |
|
||
| Cookie table | 1 | `cookieTable` (wraps the plugin's `CookieTable`) |
|
||
|
||
About 60 % of all blocks are one of the first twelve kinds. The other 40 % are site-specific
|
||
(`eventTypesMarquee`, `grantChecker`, `systemDiagram`, `jobDetail`, `incentives`…) and stay in the
|
||
projects.
|
||
|
||
### 2.3 Differences that cause the drift
|
||
|
||
1. **One block per page section.** coastal has `aboutClimate`, `aboutEfficiency`, `aboutSupport`,
|
||
`aboutTrade`, `aboutWhy` (five near-identical blocks); intecion has 10+ card-grid blocks that
|
||
differ only in layout. AGENT.md asks for a `variant` instead.
|
||
2. **Field names.** FAQ `question/answer` vs `heading/text`; pricing `tiers[].name` vs
|
||
`items[].heading`; logos `name` vs `heading`; galleries carry their own `prevLabel`/`nextLabel`
|
||
fields instead of the lightbox texts.
|
||
3. **Localization model.** ecogenica and saydiamonds localize the whole `layout` field
|
||
(each language has its own list of sections); the others localize fields inside blocks
|
||
(one structure, text per language). architekt localizes whole arrays (`items` with
|
||
`localized: true`), so item counts can differ per language.
|
||
4. **Panel language.** Bare English strings (intecion, saydiamonds), a local `adminLabels` map
|
||
(architekt), `{ en, pl }` objects (newer blocks). `docs/dev/admin-ux.md` asks for `{ en, pl }`.
|
||
5. **Local copies of plugin helpers.** `buildItemsField`, `buildActionButtonsField`,
|
||
`buildMetricsField`, `ctaHref.ts`.
|
||
6. **Hand-made image dialogs.** vanstev `PhotoGallery` (227 lines with `useState` + `role="dialog"`);
|
||
only architekt uses `LightboxTrigger`.
|
||
7. **Monoliths.** vanstev `JobDetail` (420 lines), coastal `TrustProjects` (288), `ProductEnquiryHero` (187).
|
||
8. **Registry file names.** `registry.ts` everywhere, but the config list is `allBlocks.ts`, `configs.ts`
|
||
or `pageBlocks.ts`.
|
||
|
||
**Conclusion:** the plugin's field builders fixed the "CTA field zoo", but each site still designs
|
||
the same blocks again. A shared library fixes items 1–7 for new sites and gives old sites a path to
|
||
move over (§9).
|
||
|
||
## 3. Design principles
|
||
|
||
1. **Building blocks first, finished blocks on top.** Every block is made from exported parts that
|
||
a project can use on its own: field builders, UI primitives, item cards, the block config, the block component.
|
||
2. **Nothing is on by default.** Installing or upgrading ipal-kit adds no block to any collection.
|
||
The project lists the blocks it wants (§7.1).
|
||
3. **The project wins.** Slug, labels, fields, variants, component, primitives and styles can all be
|
||
overridden per block (§7). Projects keep their own blocks next to library blocks in one registry.
|
||
4. **Server components, native HTML.** Interaction only where HTML is not enough, in small
|
||
`'use client'` files (FAQ = `<details>`, gallery = `LightboxTrigger`).
|
||
5. **Styling only through the shared design tokens** (§6). No hex values, no fixed widths, no `clamp()`
|
||
in components.
|
||
6. **Panel per `docs/dev/admin-ux.md`.** Every label `{ en, pl }`, glossary terms, sentence case,
|
||
descriptions ≤ 120 characters, `settings` in the sidebar.
|
||
7. **Additive versioning.** A minor release never removes or renames a stored field (§8).
|
||
|
||
## 4. Package layout
|
||
|
||
New entries (names to confirm, decision D1):
|
||
|
||
| Entry | Contains | Imported by |
|
||
|---|---|---|
|
||
| `@intecion/ipal-kit/blocks` | block configs and field builders (no React) | `payload.config`, collections |
|
||
| `@intecion/ipal-kit/blocks/rsc` | block components, UI primitives, `createBlockRegistry` | the page route, `blocks/registry.ts` |
|
||
| `@intecion/ipal-kit/blocks/client` | small client parts (accordion state, if any) | used internally; exported for custom components |
|
||
| `@intecion/ipal-kit/templates` | page template data for seeds | seed scripts only |
|
||
|
||
Configs and components are separate entries so `payload.config` never imports React
|
||
(AGENT.md §6.12). Source layout: `src/modules/block-library/<block>/{config.ts,Component.tsx,<Item>Card.tsx,texts.ts}`.
|
||
|
||
## 5. The blocks
|
||
|
||
### 5.1 Shared parts every block uses
|
||
|
||
**Fields (already in the plugin):** `buildSectionHeaderField()` → `header` (eyebrow, heading, intro),
|
||
`buildSectionSettingsField()` → `settings` (anchor, background), `buildLinksField()` → `links`,
|
||
`buildLinkField()` → `link`, `rowLabel()`.
|
||
|
||
**Fields (new, exported):**
|
||
|
||
| Builder | Field | Why |
|
||
|---|---|---|
|
||
| `buildItemsField({ fields, labels, rowLabelField, maxRows, minRows })` | `items` array with `initCollapsed` + `rowLabel` | replaces the local copies (ecogenica, coastal) |
|
||
| `buildMediaField({ name, required, label })` | `media` upload to `media` | one label set, one place for `relationTo` |
|
||
| `buildVariantField({ options, defaultValue })` | `variant` select in the sidebar | variants instead of copies |
|
||
| `buildIconField({ names })` | `icon` select | the names list from the project; the plugin ships no icon set |
|
||
|
||
**UI primitives (new, exported from `/blocks/rsc`):** `Section`, `SectionHeader`, `Media`, `CMSLink`,
|
||
`Button`, `Container`, `Card`. These are the files every project copies today from `section-code.md`.
|
||
The plugin versions take `resolveLink` from `createContentHelpers` through the registry factory (§7.3),
|
||
so they need no `@/lib/content` import. A project can keep its own primitives and pass them in.
|
||
|
||
**Heading levels.** The first block on the page gets `isFirst` from `createPageRoute`; its
|
||
`SectionHeader` renders `h1`, every other block `h2`, and item headings `h3`. One `h1` per page, no
|
||
skipped levels.
|
||
|
||
**Background.** `settings.background` (`default` / `muted` / `inverted` + project values) maps to
|
||
token utilities in `Section` (§6). Contrast is the tokens' job: each background has a matching text token.
|
||
|
||
### 5.2 Block list
|
||
|
||
Phase 1 = the twelve blocks the brief asks for plus `steps` and `entryList` (both built by 4 of 7 sites).
|
||
Phase 2 = less common blocks.
|
||
|
||
| Slug | Panel name (en / pl) | Fields (in panel order) | Variants | Notes |
|
||
|---|---|---|---|---|
|
||
| `hero` | Hero / Sekcja główna | `header`, `media`, `links`, `settings` | `split` (image beside), `background` (image behind, `bg-overlay` scrim), `centered`, `page` (small page hero, no media) | the LCP image: `priority` when `isFirst`; video via `Media videoMode="background"` with a poster |
|
||
| `textMedia` | Text and image / Tekst i obraz | `header`, `content` (rich text), `media`, `links`, `settings` | `mediaRight`, `mediaLeft` | rich text via `RenderRichText`; image `sizes` = half |
|
||
| `featureGrid` | Feature grid / Siatka zalet | `header`, `items[]` (`icon` or `media`, `heading`, `text`, `link`), `links`, `settings` | `cards`, `list`, `numbered`; columns 2 / 3 / 4 | covers USP lists, service cards, category cards; whole card clickable when `link` has no label |
|
||
| `gallery` | Gallery / Galeria | `header`, `items[]` (`media`, `caption`), `links`, `settings` | `grid`, `masonry`; columns | every image a `LightboxTrigger` (group = block id); labels from Form messages → Image viewer; no own prev/next fields |
|
||
| `faq` | FAQ / Pytania i odpowiedzi | `header`, `items[]` (`question`, `answer`), `links`, `settings` | `single`, `twoColumn` | `<details>`/`<summary>`; FAQPage JSON-LD through `getPageJsonLd({ faq })` with the exported `faqItemsFromLayout()` |
|
||
| `cta` | Call to action / Wezwanie do działania | `header`, `links`, `media` (optional), `settings` | `band`, `card`, `split` | wrap in `<NoSnippet>` when the project repeats it on every page (option) |
|
||
| `contact` | Contact / Kontakt | `header`, `form` (relation to `forms`), `details` (from the company global, toggle), `content`, `settings` | `formOnly`, `formWithDetails` | form through `RenderForm` (`sendForm`, `formTexts` from `blockProps`); `classNames` from the shared form tokens; contact details from a project-supplied resolver, never typed into the block |
|
||
| `team` | Team / Zespół | `header`, `items[]` (`media`, `heading` = name, `text` = role, `link` = profile), `settings` | `grid`, `list` | profile link label = screen-reader text |
|
||
| `pricing` | Pricing / Cennik | `header`, `items[]` (`heading`, `price`, `period`, `text`, `features[]`, `highlighted`, `link`), `note`, `settings` | — | highlighted plan: label text from the block (`highlightLabel`), not colour only |
|
||
| `logos` | Logos / Logotypy | `header`, `items[]` (`media`, `heading` = name, `link`), `settings` | `row`, `grid` | alt = name when the media alt is empty; no marquee by default (reduced motion) |
|
||
| `testimonials` | Testimonials / Opinie | `header`, `source` (`inline` / `collection`), `items[]` (`quote`, `heading` = author, `text` = role, `media`, `rating`) or `entries` (relation), `settings` | `grid`, `single` | `<figure>` + `<blockquote>` + `<figcaption>`; rating has a text equivalent; `collection` mode only when the project passes the collection slug |
|
||
| `stats` | Key figures / Liczby | `header`, `items[]` (`value`, `heading` = label, `text`), `settings` | `row`, `cards` | static numbers; count-up animation off by default and never under reduced motion. Panel name avoids "statistics" (glossary: visit counting) |
|
||
| `richText` | Text / Tekst | `header`, `content`, `tableOfContents` (`buildTableOfContentsField`), `settings` | `narrow` (measure), `wide` | used by legal pages and posts; heading anchors from `richtext/headings` |
|
||
| `steps` | Steps / Kroki | `header`, `items[]` (`heading`, `text`, `media`), `links`, `settings` | `numbered`, `timeline` | ordered list `<ol>` |
|
||
| `entryList` | Entry list / Lista wpisów | `header`, `collection` (select from the project's `content.collections`), `mode` (`latest` / `selected`), `entries`, `limit`, `links`, `settings` | `cards`, `list` | blog teasers, projects, products; data loaded on the server through `createContentHelpers` |
|
||
| *phase 2* `video`, `tabs`, `map`, `cookieTable`, `comparisonTable` | | | | `video` = `YouTubeEmbed`/`Media player`; `map` behind consent; `cookieTable` wraps `CookieTable` |
|
||
|
||
Field names follow AGENT.md §6.5 (`header`, `items`, `heading`, `text`, `content`, `media`, `link(s)`,
|
||
`settings`). Two deliberate exceptions, both already the norm in the sites: FAQ keeps
|
||
`question`/`answer` (4 of 5 sites; also the `buildFaqJsonLd` input), and testimonials keep `quote`.
|
||
|
||
### 5.3 Example — `faq`
|
||
|
||
```ts
|
||
// src/modules/block-library/faq/config.ts (plugin)
|
||
export function buildFaqBlock(options: BlockOptions<'faq'> = {}): Block {
|
||
return applyBlockOptions(
|
||
{
|
||
slug: 'faq',
|
||
interfaceName: 'FaqBlock',
|
||
labels: { singular: { en: 'FAQ', pl: 'Pytania i odpowiedzi' }, plural: { en: 'FAQs', pl: 'Pytania i odpowiedzi' } },
|
||
imageURL: '/ipal-blocks/faq.svg', // block picker thumbnail (optional, §5.5)
|
||
fields: [
|
||
buildSectionHeaderField(),
|
||
buildItemsField({
|
||
labels: { singular: { en: 'Question', pl: 'Pytanie' }, plural: { en: 'Questions', pl: 'Pytania' } },
|
||
rowLabelField: 'question',
|
||
fields: [
|
||
{ name: 'question', type: 'text', localized: true, required: true, label: { en: 'Question', pl: 'Pytanie' } },
|
||
{ name: 'answer', type: 'textarea', localized: true, required: true, label: { en: 'Answer', pl: 'Odpowiedź' } },
|
||
],
|
||
}),
|
||
buildLinksField({ maxRows: 1 }),
|
||
buildVariantField({ options: FAQ_VARIANTS, defaultValue: 'single' }),
|
||
buildSectionSettingsField(),
|
||
],
|
||
},
|
||
options,
|
||
)
|
||
}
|
||
```
|
||
|
||
```tsx
|
||
// src/modules/block-library/faq/Component.tsx (plugin) — server component
|
||
export function FaqBlock({ header, items, links, settings, variant, ui, locale, isFirst }: FaqBlockProps) {
|
||
const { Section, SectionHeader, CMSLink } = ui
|
||
if (!items?.length) return null
|
||
return (
|
||
<Section settings={settings} data-ipal-block="faq">
|
||
<SectionHeader header={header} as={isFirst ? 'h1' : 'h2'} />
|
||
<div className={FAQ_LAYOUT[variant ?? 'single']}>
|
||
{items.map((item) => <FaqItem key={item.id} item={item} />)}
|
||
</div>
|
||
{links?.map(({ id, link }) => <CMSLink key={id} link={link} locale={locale} />)}
|
||
</Section>
|
||
)
|
||
}
|
||
```
|
||
|
||
### 5.4 Accessibility (every block)
|
||
|
||
The plugin's tests check these for each block, and the block docs list them:
|
||
|
||
- Landmarks: each block is one `<section>` with `aria-labelledby` pointing at its heading (when there is one).
|
||
- Headings: `h1` only in the first block, then `h2`, items `h3`.
|
||
- Images: alt from the media document (required, localized); decorative images (`background` hero)
|
||
get `alt=""`; logos fall back to the item name.
|
||
- Links: no "Read more" alone — a card link without a label uses the card heading as its name.
|
||
- Keyboard: every control reachable, visible focus ring from the focus token; `<details>` for FAQ;
|
||
lightbox focus handling is already in `LightboxDialog`.
|
||
- Motion: no autoplay carousels; animations only with `prefers-reduced-motion: no-preference`.
|
||
- Colour: information never by colour only (highlighted plan, rating); contrast through token pairs (§6).
|
||
- Forms: `RenderForm` handles labels, errors and `aria-describedby`.
|
||
- Language: visitor-facing fixed strings (lightbox, "Highlighted", rating text) ship in `en` and `pl`
|
||
and follow the page locale, overridable per project.
|
||
|
||
### 5.5 Panel (admin-ux)
|
||
|
||
- Every label, description, option and `labels.singular/plural` is `{ en, pl }`.
|
||
- Block names say what the editor sees: "Text and image", not "ImageText".
|
||
- Order inside each block: `header` → content → `media` → `items` → `links`; `variant`, `settings`
|
||
in the sidebar.
|
||
- Optional block thumbnails (`imageURL`) in the block picker, served from the plugin's static folder
|
||
only when the project turns them on (`thumbnails: true`) — no forced route (decision D7).
|
||
- Every block passes the empty-block test (≤ 6 fields visible when added).
|
||
|
||
## 6. Styling — design tokens
|
||
|
||
The library styles **only through the token names of the design-tokens track**
|
||
(`docs/dev/design-tokens-proposal.md` on `claude/design-tokens-95806d`; names agreed with that session
|
||
on 2026-10-29; the owner may still rename the utilities, see below). The canonical variables are the `--ipal-*` names the
|
||
plugin already ships; utilities come from the plugin preset `@intecion/ipal-kit/tailwind.css`.
|
||
Colours switch under `html[data-theme=dark]`, so blocks never use `dark:` for colours.
|
||
|
||
| Block need | Utilities (variable) |
|
||
|---|---|
|
||
| Section backgrounds (`settings.background`) | `default` → `bg-bg`; `muted` → `bg-surface-muted`; `inverted` → `bg-inverse text-on-inverse` (`--ipal-bg`, `--ipal-surface-muted`, `--ipal-surface-inverse`, `--ipal-text-inverse`) |
|
||
| Body, heading, muted text | `text-fg`, `text-fg-strong`, `text-fg-muted` (eyebrow, captions, item roles) |
|
||
| Card (feature, team, pricing, testimonial) | `bg-surface text-fg border border-border rounded-card shadow-sm`; clickable card: `hover:shadow-md transition-shadow duration-fast ease-out` |
|
||
| Highlighted pricing plan, rating stars, badges | `bg-accent text-on-accent` / `text-accent` (always with a text label, §5.4) |
|
||
| Buttons (in the `Button` primitive only) | `bg-primary hover:bg-primary-hover text-on-primary`, `bg-secondary …`, ghost `hover:bg-hover`; `rounded-control` |
|
||
| Links in rich text and cards | `text-link hover:text-link-hover` |
|
||
| Focus | `focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus` |
|
||
| Hero image overlay | `bg-overlay` (scrim), gradient `bg-linear-to-t from-overlay to-transparent` |
|
||
| Images | `rounded-media` |
|
||
| Type | `font-heading text-display / text-h1 / text-h2 / text-h3 / text-h4`, `text-lead` (intro), `leading-heading tracking-heading`; hero fit: `text-[length:var(--ipal-fs-display-fit)]`, `min-h-[var(--ipal-hero-min-h)]` |
|
||
| Spacing | `py-section` (`py-section-sm` for CTA band, logos), `gap-gap` for section grids, Tailwind steps inside cards, `mt-stack` heading → content, `px-gutter` |
|
||
| Widths | `max-w-container` (default), `max-w-container-wide` (gallery wide), `max-w-narrow` (`richText narrow`, legal), `max-w-measure` (running text) |
|
||
| Motion | `duration-fast/base/slow`, `ease-out` (0 ms under reduced motion) |
|
||
| Layering | `z-overlay` (lightbox is already the plugin's) |
|
||
|
||
**Inverted sections** (agreed with the tokens track). `Section` renders `bg-inverse` with
|
||
`data-surface="inverse"`. Inside that scope the preset re-maps the text, muted-text, border, surface and
|
||
hover tokens, plus link (`--ipal-link-inverse`) and focus (`--ipal-focus-inverse`), and flips `color-scheme`.
|
||
Blocks inside use plain `text-fg`, `text-link`, `border-border` and need no inverse variants. Primary and accent are not re-mapped; the
|
||
tokens contrast report warns when primary on `surface-inverse` fails. `data-surface="muted"` is set on
|
||
muted sections as a hook and re-maps nothing by default.
|
||
|
||
If the owner picks shadcn-style utility names instead (`text-foreground`, `bg-muted`), the blocks change
|
||
by a mechanical class rename; the roles stay.
|
||
|
||
**How blocks carry styles (decision D2).** Recommended: **Tailwind v4 utilities that use only token
|
||
names**, compiled by the project through `@source "…/node_modules/@intecion/ipal-kit/dist/**/*.js"`
|
||
(the line projects already have). All seven sites use Tailwind v4. Each element also gets a
|
||
`data-ipal-block` / `data-ipal-part` attribute, and each block takes a `classNames` map (like
|
||
`RenderForm`) that replaces the default classes per part. Alternative: a plain CSS file
|
||
(`@intecion/ipal-kit/blocks.css`) on CSS variables — works without Tailwind, but is harder to
|
||
change per project.
|
||
|
||
## 7. How a project uses, changes and extends it
|
||
|
||
### 7.1 Opt in per block (schema)
|
||
|
||
```ts
|
||
// src/collections/Pages.ts
|
||
import { libraryBlocks } from '@intecion/ipal-kit/blocks'
|
||
import { ProjectTimeline } from '@/blocks/ProjectTimeline/config'
|
||
|
||
{
|
||
name: 'layout',
|
||
type: 'blocks',
|
||
blocks: [
|
||
...libraryBlocks({
|
||
hero: true,
|
||
textMedia: true,
|
||
faq: { variants: ['single'] }, // fewer variants
|
||
gallery: { fields: (fields) => [...fields, captionPosition] }, // add a field
|
||
pricing: false, // off (also the default when not listed)
|
||
testimonials: { slug: 'reviews', interfaceName: 'ReviewsBlock' }, // keep an old slug
|
||
}),
|
||
ProjectTimeline, // the project's own block
|
||
],
|
||
}
|
||
```
|
||
|
||
Each block also has its own builder (`buildFaqBlock(options)`) for projects that prefer to list them one by one.
|
||
|
||
**Options per block** (`BlockOptions`): `slug`, `interfaceName`, `labels`, `fields` (array or
|
||
`(defaults) => fields`), `variants` (subset or extra values), `maxItems`, `header` / `links` / `settings`
|
||
options passed to the shared builders (e.g. `settings: { backgrounds: […] }`), `localization`
|
||
(§7.5), `admin` (merged), `custom`. An object merges with the defaults key by key and the project's
|
||
keys win; a function `(block) => block` takes over completely — the same rule as `globalOverrides`.
|
||
|
||
### 7.2 Override fields
|
||
|
||
- Add: `fields: (defaults) => [...defaults, myField]`.
|
||
- Change one: `fields: (defaults) => defaults.map((f) => (isNamed(f, 'media') ? { ...f, required: true } : f))`
|
||
— the plugin exports `isNamed` and `replaceField(fields, name, patch)`.
|
||
- Remove one: allowed (e.g. drop `links` from `faq`); the component renders nothing for a missing field.
|
||
- Labels: any `label`/`labels` override wins; texts for other locales than `en`/`pl` come from the project.
|
||
|
||
### 7.3 Swap a component or a primitive (front end)
|
||
|
||
```ts
|
||
// src/blocks/registry.ts
|
||
import { createBlockRegistry } from '@intecion/ipal-kit/blocks/rsc'
|
||
import * as content from '@/lib/content'
|
||
import { Media } from '@/components/ui/Media' // project primitive
|
||
import { HeroSplit } from '@/blocks/Hero/Component' // project component for one block
|
||
import { ProjectTimeline } from '@/blocks/ProjectTimeline/Component'
|
||
|
||
export const blockRegistry = createBlockRegistry(content, {
|
||
ui: { Media }, // replace one primitive for every library block
|
||
components: { hero: HeroSplit }, // replace one block component
|
||
classNames: { faq: { item: 'border-b border-border' } },
|
||
extra: { projectTimeline: ProjectTimeline }, // the project's own blocks, same registry
|
||
})
|
||
```
|
||
|
||
`createBlockRegistry` returns a plain `blockType → component` map for `RenderBlocks` /
|
||
`createPageRoute`. It binds `resolveLink`, `ui` and `classNames` into server components, so no
|
||
function crosses to the client. A project that wants nothing from the factory imports the bare
|
||
components (`FaqBlock`, `FaqItem`) and wires them itself. **Eject:** `pnpm exec ipal-blocks eject faq`
|
||
copies the block's config and component into `src/blocks/Faq/` with the same slug and data shape, for
|
||
a project that wants to own it fully (decision D3).
|
||
|
||
### 7.4 Add your own block
|
||
|
||
Unchanged from today: `ipal-block` skill, `src/blocks/<Name>/`, same primitives (now importable from
|
||
the plugin), same registry. Rule for agents: **a library block or a variant of one first; a new block
|
||
only when no variant fits**, recorded in "Project decisions".
|
||
|
||
### 7.5 Localization model (decision D4)
|
||
|
||
Default: **fields inside blocks are localized** (`localized: true` on text, rich text and media
|
||
that differ per language); the `layout` field is not. One page structure, text per language — this matches
|
||
`createSeeder` (`writeLocales` writes the same row ids per locale) and the content audits.
|
||
Option `localization: 'layout'` drops the inner `localized` flags for projects that localize the whole
|
||
`layout` field (ecogenica, saydiamonds), so Payload does not store nested localized values.
|
||
|
||
## 8. Versioning — adding fields never breaks content
|
||
|
||
Rules for the library (enforced in plugin CI):
|
||
|
||
1. **Minor releases only add.** New fields are optional, or have a `defaultValue`; new variants are
|
||
new select values; the component renders the old output when the new field is empty.
|
||
2. **Never rename or remove** a stored field, a select value, a slug or an `interfaceName` in a minor.
|
||
A rename happens only in a major, with an **ipal-migrate-fields** recipe and upgrade notes.
|
||
3. **`dbName` is pinned** on array and select fields so Postgres table and enum names do not change
|
||
when a label or a project slug changes.
|
||
4. **Schema snapshot test.** `test/block-library.schema.json` stores every block's field paths, types,
|
||
select values and `required` flags. CI fails when a path disappears, a type changes or a field becomes
|
||
required. Adding is allowed and updates the snapshot.
|
||
5. **Upgrade notes** list every new field per block. On Postgres/SQLite a new field still needs a project
|
||
migration (`payload migrate:create`); the notes say so. MongoDB needs none.
|
||
6. **Content safety.** New required fields are never added to existing blocks; validation that would reject
|
||
old documents is never added in a minor.
|
||
|
||
## 9. Page templates
|
||
|
||
A template is **data, not code**: a function that returns a page (`title`, `slug`, `layout`) built from
|
||
library blocks, with every visible text in `en` and `pl` and `[TO FILL: …]` where only the client can write it.
|
||
Templates feed `createSeeder.upsertBySlug`; nothing in the panel changes.
|
||
|
||
| Template | Layout (blocks, in order) | 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 (cards)` · `steps` · `pricing` · `faq` · `cta` | — |
|
||
| `service` (one service) | `hero (split)` · `textMedia` · `featureGrid (list)` · `gallery` · `faq` · `contact` | — |
|
||
| `contact` | `hero (page)` · `contact (formWithDetails)` · `faq` | — |
|
||
| `blogIndex` | `hero (page)` · archive view from `createPageRoute` `render` (content.md) · `cta` | `postsArchive` |
|
||
| `post` (posts collection) | post header (title, date, author, media) · `content` with `tableOfContents` · `entryList (related)` · `cta` | — |
|
||
| `legal` (privacy, terms) | `hero (page)` · `richText (narrow, tableOfContents)` | `privacyPolicy`, `termsOfService` |
|
||
| `cookiePolicy` | `hero (page)` · `richText` · `cookieTable` | `cookiePolicy` |
|
||
| `notFound` | `hero (page, with links home)` | `notFound` |
|
||
|
||
```ts
|
||
// scripts/seed-content.ts
|
||
import { pageTemplates } from '@intecion/ipal-kit/templates'
|
||
|
||
await seed.upsertBySlug('pages', [
|
||
pageTemplates.home({ slug: { pl: 'start', en: 'home' }, overrides: { hero: { header: { heading: { pl: '…', en: '…' } } } } }),
|
||
pageTemplates.contact({ form: { $form: 'Contact form' } }),
|
||
pageTemplates.legal('privacyPolicy'),
|
||
])
|
||
```
|
||
|
||
- A template takes `overrides` per block and `layout: (blocks) => blocks` to reorder, drop or add sections.
|
||
- It only uses blocks the project turned on; a missing block is left out and reported in the seed summary.
|
||
- Templates set the system page role in Site settings through `fillGlobal` (empty fields only).
|
||
- Text defaults are neutral and short (admin-ux tone); legal templates ship structure and headings, never
|
||
legal wording presented as final.
|
||
- `$form: 'title'` is a new seed reference (like `$page`) — a small `createSeeder` addition.
|
||
|
||
**After launch** (AGENT.md / seeding.md, "named records only"): templates are used only through a seed
|
||
that names the records it writes (`upsertBySlug('pages', [pageTemplates.contact(…)])`), never a full
|
||
"seed every template" run. Seeds stay create-only; `SEED_UPDATE` keeps skipping edited pages. A template
|
||
change in a new ipal-kit version never touches existing pages.
|
||
|
||
## 10. Links to the other tracks and the skills
|
||
|
||
| Track / skill | What changes |
|
||
|---|---|
|
||
| **Design tokens** | the token contract in §6; the starter's `styles.css` defines them; blocks never introduce new names without that track |
|
||
| **Project starter** | turns on the phase 1 blocks, `createBlockRegistry`, the token CSS and a `seed-content.ts` built from templates |
|
||
| **Reference site** | uses every library block and variant on real pages; it is the visual test and the screenshot source for docs |
|
||
| **ipal-doctor** | checks: library blocks used where one fits (warns on project blocks that duplicate one), no local copies of `buildItemsField` etc., registry from `createBlockRegistry` or `RenderBlocks`, token-only classes |
|
||
| **ipal-block** skill | step 0: "is there a library block or a variant?"; then options (§7.1), component swap (§7.3), eject; own blocks as today |
|
||
| **ipal-site** skill | phase 2 maps each section of the site map to a library block + variant first; phase 6 builds `seed-content.ts` from templates |
|
||
| **seeding.md + ipal-site `seed-content.template.ts`** | templates, `$form`, named-records rule after launch |
|
||
| **ipal-audit** | "panel:" checks also run on library blocks with project overrides |
|
||
| **AGENT.md** | §6 starts with "use the block library"; §12 module map gets `blocks` and `templates`; `docs/blocks.md` gets a "Block library" part and one doc per block (fields, variants, a11y, options, verify) |
|
||
|
||
## 11. Delivery plan (after approval)
|
||
|
||
1. **Foundations** — new field builders, UI primitives, `createBlockRegistry`, `BlockOptions` + merge,
|
||
schema snapshot test, docs skeleton. Patch-safe: nothing is on by default.
|
||
2. **Phase 1 blocks** — `hero`, `textMedia`, `featureGrid`, `cta`, `richText`, `faq`, `contact`, `gallery`,
|
||
then `testimonials`, `stats`, `steps`, `logos`, `team`, `pricing`, `entryList`. Each with tests
|
||
(render with empty data, a11y checks, schema snapshot), docs and `{ en, pl }` texts.
|
||
3. **Templates** — `@intecion/ipal-kit/templates`, `$form` in the seeder.
|
||
4. **Agent guide and skills** — AGENT.md, ipal-block, ipal-site, ipal-reference `api.md`, ipal-audit.
|
||
5. **Reference site + starter** adopt it; then one existing site as the first move-over (decision D8).
|
||
|
||
Ships as **1.15.0** (new feature, no breaking change).
|
||
|
||
## 12. Decisions
|
||
|
||
The owner accepted every recommendation below on 2026-10-29 ("Accept all three", relayed by the coordinator).
|
||
|
||
| # | Decision | Accepted |
|
||
|---|---|---|
|
||
| D1 | Ship the library inside `@intecion/ipal-kit` (new entries) or as a separate package `@intecion/ipal-blocks` | **inside**, new entries `/blocks`, `/blocks/rsc`, `/templates` — one version, one guide |
|
||
| D2 | Styling: Tailwind token utilities from the plugin preset + `classNames`/`data-ipal-*`, or a plain CSS file on variables | **Tailwind token utilities** (all sites are on Tailwind v4; agreed with the design-tokens session) |
|
||
| D3 | Offer an `ipal-blocks eject <block>` command that copies a block into the project | **yes**, phase 2 |
|
||
| D4 | Localization default: fields inside blocks (one structure) or the whole `layout` per language | **fields inside blocks**, `localization: 'layout'` as an option |
|
||
| D5 | Default slugs: plain (`faq`, `hero`) or prefixed (`ipalFaq`) | **plain**, with a `slug` option for clashes — data stays readable and matches what sites use |
|
||
| D6 | Phase 1 scope: the 15 blocks in §5.2 | **yes**; `video`, `tabs`, `map`, `cookieTable`, `comparisonTable` in phase 2 |
|
||
| D7 | Block picker thumbnails in the admin panel | **opt-in** (`thumbnails: true`) |
|
||
| D8 | Move existing sites onto the library, or new sites only | **new sites + the reference site now**; old sites move block by block when they get work, with ipal-migrate-fields recipes, never as a big-bang |
|
||
| D9 | Testimonials: inline items only, or also a relation to a `testimonials` collection | **both**, collection mode only when the project names the collection |
|
||
| D10 | Panel name for the stats block ("Statistics" is the glossary word for visit counting) | **"Key figures" / "Liczby"** |
|