Block library: 15 blocks, registry, primitives, templates, manifest, eject

- @intecion/ipal-kit/blocks: libraryBlocks() opt-in, one builder per block, field
  builders, option merging, blockLibraryManifest, faqItemsFromLayout
- @intecion/ipal-kit/blocks/rsc: createBlockRegistry, the block components and UI
  primitives (token utilities only; next/image and next/link passed in)
- @intecion/ipal-kit/templates: 10 page templates as createSeeder data
- createSeeder: { $form: title } references
- ipal-blocks eject <block>
- tests: options, rendering and a11y per block, Payload + seeding, GraphQL, admin
  wording, schema snapshot (versioning), eject imports
- shorter admin labels: link "New tab", table of contents "Show contents"

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 14:05:47 +01:00
co-authored by Claude Opus 5.5
parent 7918eaf6d4
commit 2d1cc0e77d
73 changed files with 5091 additions and 9 deletions
@@ -0,0 +1,58 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, MediaValue } from '../../data.js'
import { lightboxImage } from '../../../lightbox/lightboxImage.js'
import { LightboxTrigger } from '../../../lightbox/LightboxProvider.js'
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
import { Buttons, GRID_COLUMNS, headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type GalleryItem = { caption?: null | string; id?: null | string; media?: MediaValue }
export type GalleryBlockData = { columns?: null | string; items?: GalleryItem[] | null } & BaseBlockData
export const GALLERY_PARTS = {
caption: 'mt-2 text-sm text-fg-muted',
grid: 'grid gap-4',
image: 'h-full w-full rounded-media object-cover',
item: 'm-0',
masonry: 'columns-1 gap-4 sm:columns-2 lg:columns-3 [&>*]:mb-4 [&>*]:break-inside-avoid',
trigger: 'block w-full overflow-hidden rounded-media focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus',
}
/** Images in a grid or a mosaic; each opens in the site's image viewer (one group per gallery). */
export function GalleryBlock(props: LibraryBlockProps<GalleryBlockData>) {
const { classNames, columns, ctx, header, isFirst, items, links, locale, settings, ui, variant } = props
const shown = (items ?? []).filter((item) => item.media)
if (!shown.length) {return null}
const c = parts(GALLERY_PARTS, classNames)
const id = headingId(props)
const group = `gallery-${props.id ?? 'block'}`
const masonry = variant === 'masonry'
const sizes = columns === 'two' ? MEDIA_SIZES.half : columns === 'four' ? MEDIA_SIZES.quarter : MEDIA_SIZES.third
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width="wide">
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
<ul className={masonry ? c.masonry : cx(c.grid, GRID_COLUMNS[columns ?? 'three'])}>
{shown.map((item, i) => {
const image = <ui.Media className={c.image} resource={item.media} sizes={sizes} />
const large = ctx.lightbox ? lightboxImage(item.media, item.caption ? { caption: item.caption } : {}) : null
return (
<li key={item.id ?? i}>
<figure className={c.item}>
{large ? (
<LightboxTrigger className={c.trigger} group={group} image={large}>
{image}
</LightboxTrigger>
) : (
image
)}
{item.caption ? <figcaption className={c.caption}>{item.caption}</figcaption> : null}
</figure>
</li>
)
})}
</ul>
<Buttons CMSLink={ui.CMSLink} links={links} locale={locale} />
</ui.Section>
)
}
@@ -0,0 +1,26 @@
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildItemsField, buildMediaField } from '../../fields.js'
import { columnsField } from '../../shared.js'
export const GALLERY_VARIANTS = [variantOption('grid', 'Even grid', 'Równa siatka'), variantOption('masonry', 'Mosaic', 'Mozaika')] as const
/** Gallery — images that open enlarged in the site's image viewer. */
export const buildGalleryBlock = defineLibraryBlock({
slug: 'gallery',
fields: ({ maxItems = 48 }) => [
buildItemsField({
fields: [
buildMediaField({ required: true }),
{ name: 'caption', type: 'text', label: adminText('Caption', 'Podpis'), localized: true },
],
labels: { plural: adminText('Images', 'Obrazy'), singular: adminText('Image', 'Obraz') },
maxRows: maxItems,
rowLabelField: ['caption', 'media.alt', 'media.filename'],
}),
columnsField(),
],
interfaceName: 'GalleryBlock',
labels: { plural: adminText('Galleries', 'Galerie'), singular: adminText('Gallery', 'Galeria') },
links: { maxRows: 1 },
variants: GALLERY_VARIANTS,
})