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,41 @@
import type { LibraryBlockProps } from '../../context.js'
import type { BaseBlockData, RichTextData } from '../../data.js'
import { extractHeadings } from '../../../richtext/headings.js'
import { RenderRichText } from '../../../richtext/RenderRichText.js'
import { TableOfContents } from '../../../richtext/TableOfContents.js'
import { headingId } from '../../ui/Buttons.js'
import { cx, parts } from '../../ui/cx.js'
export type RichTextBlockData = { content?: RichTextData; tableOfContents?: { label?: null | string; show?: boolean | null } | null } & BaseBlockData
export const RICH_TEXT_PARTS = {
content: 'space-y-4 text-fg [&_a]:text-link [&_a:hover]:text-link-hover [&_h2]:mt-10 [&_h2]:font-heading [&_h2]:text-h3 [&_h2]:text-fg-strong [&_h3]:mt-8 [&_h3]:font-heading [&_h3]:text-h4 [&_h3]:text-fg-strong [&_ol]:list-decimal [&_ol]:pl-6 [&_ul]:list-disc [&_ul]:pl-6',
layout: 'grid gap-gap lg:grid-cols-[16rem_1fr]',
toc: 'self-start text-sm lg:sticky lg:top-24',
}
/** A text section; with a table of contents its headings get anchor ids and a list beside the text. */
export function RichTextBlock(props: LibraryBlockProps<RichTextBlockData>) {
const { classNames, content, ctx, header, isFirst, settings, tableOfContents, ui, variant } = props
if (!content) {return null}
const c = parts(RICH_TEXT_PARTS, classNames)
const id = headingId(props)
const toc = tableOfContents?.show ? extractHeadings(content) : []
const text = <RenderRichText className={cx(c.content, ctx.richText?.className)} data={content as never} headingIds={toc.length > 0} />
return (
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width={variant === 'wide' || toc.length ? 'default' : 'narrow'}>
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
{toc.length ? (
<div className={c.layout}>
<div className={c.toc}>
<TableOfContents items={toc} label={tableOfContents?.label ?? undefined} />
</div>
<div className="max-w-measure">{text}</div>
</div>
) : (
text
)}
</ui.Section>
)
}
@@ -0,0 +1,15 @@
import { buildTableOfContentsField } from '../../../richtext/headings.js'
import { adminText, defineLibraryBlock, variantOption } from '../../define.js'
import { buildContentField } from '../../fields.js'
export const RICH_TEXT_VARIANTS = [variantOption('narrow', 'Narrow column', 'Wąska kolumna'), variantOption('wide', 'Full width', 'Pełna szerokość')] as const
/** Text — a formatted text section (legal pages, articles), with an optional table of contents. */
export const buildRichTextBlock = defineLibraryBlock({
slug: 'richText',
fields: () => [buildContentField({ required: true }), buildTableOfContentsField()],
interfaceName: 'RichTextBlock',
labels: { plural: adminText('Text sections', 'Sekcje tekstu'), singular: adminText('Text', 'Tekst') },
links: false,
variants: RICH_TEXT_VARIANTS,
})