Files
ipal-kit/docs/agent/skills/ipal-block/SKILL.md
T

59 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: ipal-block
description: Builds or refactors one page section (Payload block + React component) in an ipal-kit project the correct way — a clean editor panel (repeatable things as "+ Add …" arrays with rowLabel, never cta1/cta2 slots, short `{ en, pl }` labels per docs/dev/admin-ux.md, no empty spare fields), shared fields from the plugin (buildSectionHeaderField, buildLinksField, buildLinkField, buildSectionSettingsField), UI primitives (Section, SectionHeader, Media, CMSLink), fixed field vocabulary, max ~80 lines of JSX, subcomponents for repeated items, registry wiring. Use when creating a new section/block (hero, features, CTA, FAQ, gallery, pricing, testimonials…), changing a block's fields, or fixing a block with ctaLabel/buttonUrl/pdfUrl fields or a monolithic component.
---
# ipal-block
One section per use of this skill. Details and ready code:
`node_modules/@intecion/ipal-kit/docs/agent/AGENT.md` §6.
## 0. Prerequisites
Check that these exist: `src/components/ui/{CMSLink,Button,Media,Section,SectionHeader}.tsx`.
Old `src/fields/sectionHeader.ts` / `sectionSettings.ts` → replace with the plugin import and delete them (blocks.md, no migration).
Links (`buildLinkField`, `buildLinksField`, `resolveLink`) and section fields (`buildSectionHeaderField`, `buildSectionSettingsField`) come from the plugin — do not create them in the project.
Missing → first create them 1:1 from `resources/section-code.md` (this skill)
(and tell the user). Do not write your own versions.
## 1. Plan (write 3–5 points, then go straight to code — AGENT.md §0a)
- block slug (camelCase), folder name (PascalCase),
- the field list, **only** from the AGENT.md §6.5 vocabulary:
`header`, `media`, `links`, `link`, `items` (+ `heading`, `text`, `content`), `settings`,
- whether `items` get a `<Name>Card.tsx` subcomponent,
- whether interaction is needed → a separate `'use client'` file (try `<details>`/`<dialog>` first),
- whether the section is a variant of an existing block (then a `variant: select` field, not a new block).
## 2. Code
File patterns (Hero, FeatureGrid + FeatureCard): `resources/section-code.md`.
1. `src/blocks/<Name>/config.ts` — `interfaceName: '<Name>Block'`, fields from the plan,
always `buildSectionSettingsField()`. CTA = `buildLinksField()`, never `cta*`/`button*` fields.
A downloadable file = a link of type `file`. **Panel per AGENT.md §6.5a:**
- repeatable → an array with `labels: { singular, plural }` + `admin: { initCollapsed: true, components: rowLabel('heading', '<Singular>') }`, `maxRows` from the design;
- no numbered fields (`cta1`, `feature2Title`, `image3`) and no spare fields "just in case";
- EN labels of 1–3 words, `description` only when needed (≤ 80 chars, what/where, an example);
- dependent fields use `admin.condition`, a variant = a `variant` select, > ~10 fields → `tabs`;
- block: `labels: { singular: 'Feature grid', plural: 'Feature grids' }`.
2. `src/blocks/<Name>/Component.tsx` — named export, type from `@/payload-types`
(`<Name>Block & { locale: string }`), structure:
`<Section settings>` → `<SectionHeader header>` → content with `<Media>`, `<CMSLink>`,
`items.map(<Card/>)`. No text, `href`, `<img>`, hex colors or inline SVG.
3. Subcomponents go in the same folder; shared by 2+ sections → `src/components/ui/`.
An image the visitor can enlarge (gallery, card, product, certificate) → wrap the `<Media>` in
`<LightboxTrigger group={`<name>-${id}`} image={lightboxImage(item.image, { size: 'hero' })}>`
(`@intecion/ipal-kit/client`; skip the trigger when `lightboxImage` returns `null`). No
`useState` dialog, no `glightbox` — lightbox.md.
4. Add `config.ts` to `layout` in `src/collections/Pages.ts`,
and the component to `src/blocks/registry.ts` (key = slug).
5. `pnpm generate:types`.
## 3. Check
- `Component.tsx` ≤ ~80 lines of JSX.
- **Empty block test** in the panel: ≤ 6 items at the start, every label and description
readable in English and Polish (switch the admin language in Account),
"+ Add Button / Add Feature", collapsed rows showing their content, every field shows something.
First `rowLabel` in the project → `pnpm payload generate:importmap`.
- Run the **ipal-audit** skill (`--quick`), fix every `[ERROR]`.
- Refactoring an existing block with renamed fields: **migrate the data first**
(old field → new), and only then remove the old fields (AGENT.md §6.7).