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
+92
View File
@@ -0,0 +1,92 @@
import type { Block } from 'payload'
import type { ContactOptions } from './blocks/contact/config.js'
import type { EntryListOptions } from './blocks/entryList/config.js'
import type { FeatureGridOptions } from './blocks/featureGrid/config.js'
import type { TestimonialsOptions } from './blocks/testimonials/config.js'
import type { BlockBuilder, BlockOptions, LibraryBlockSetting, LibraryBlockSlug, LibraryBlocksShared } from './types.js'
import { buildContactBlock } from './blocks/contact/config.js'
import { buildCtaBlock } from './blocks/cta/config.js'
import { buildEntryListBlock } from './blocks/entryList/config.js'
import { buildFaqBlock } from './blocks/faq/config.js'
import { buildFeatureGridBlock } from './blocks/featureGrid/config.js'
import { buildGalleryBlock } from './blocks/gallery/config.js'
import { buildHeroBlock } from './blocks/hero/config.js'
import { buildLogosBlock } from './blocks/logos/config.js'
import { buildPricingBlock } from './blocks/pricing/config.js'
import { buildRichTextBlock } from './blocks/richText/config.js'
import { buildStatsBlock } from './blocks/stats/config.js'
import { buildStepsBlock } from './blocks/steps/config.js'
import { buildTeamBlock } from './blocks/team/config.js'
import { buildTestimonialsBlock } from './blocks/testimonials/config.js'
import { buildTextMediaBlock } from './blocks/textMedia/config.js'
/** Every library block builder, by default slug, in the order of the block picker. */
export const LIBRARY_BLOCK_BUILDERS = {
contact: buildContactBlock,
cta: buildCtaBlock,
entryList: buildEntryListBlock,
faq: buildFaqBlock,
featureGrid: buildFeatureGridBlock,
gallery: buildGalleryBlock,
hero: buildHeroBlock,
logos: buildLogosBlock,
pricing: buildPricingBlock,
richText: buildRichTextBlock,
stats: buildStatsBlock,
steps: buildStepsBlock,
team: buildTeamBlock,
testimonials: buildTestimonialsBlock,
textMedia: buildTextMediaBlock,
} satisfies Record<LibraryBlockSlug, BlockBuilder<never>>
export const LIBRARY_BLOCK_SLUGS = Object.keys(LIBRARY_BLOCK_BUILDERS) as LibraryBlockSlug[]
/** What `libraryBlocks` takes: a setting per block. Blocks not listed are off. */
export type LibraryBlocksOptions = {
contact?: LibraryBlockSetting<ContactOptions>
cta?: LibraryBlockSetting
entryList?: LibraryBlockSetting<EntryListOptions>
faq?: LibraryBlockSetting
featureGrid?: LibraryBlockSetting<FeatureGridOptions>
gallery?: LibraryBlockSetting
hero?: LibraryBlockSetting
logos?: LibraryBlockSetting
pricing?: LibraryBlockSetting
richText?: LibraryBlockSetting
stats?: LibraryBlockSetting
steps?: LibraryBlockSetting
team?: LibraryBlockSetting
testimonials?: LibraryBlockSetting<TestimonialsOptions>
textMedia?: LibraryBlockSetting
}
/**
* The library blocks the project turned on, ready for a `blocks` field:
*
* { name: 'layout', type: 'blocks', blocks: [...libraryBlocks({ hero: true, faq: { maxItems: 10 } }), MyBlock] }
*
* Nothing is on by default. `shared` applies to every block (a block's own options win).
*/
export function libraryBlocks(options: LibraryBlocksOptions, shared: LibraryBlocksShared = {}): Block[] {
return LIBRARY_BLOCK_SLUGS.flatMap((slug) => {
const setting = options[slug] as LibraryBlockSetting | undefined
if (!setting) {return []}
const build = LIBRARY_BLOCK_BUILDERS[slug] as BlockBuilder
if (typeof setting === 'function') {return [setting(build(shared))]}
const own: BlockOptions = setting === true ? {} : setting
return [build({ ...shared, ...own, settings: own.settings ?? shared.settings })]
})
}
/** The block slugs `libraryBlocks(options)` turns on, with the project's renames — for templates and the registry. */
export function libraryBlockSlugs(options: LibraryBlocksOptions): Partial<Record<LibraryBlockSlug, string>> {
const out: Partial<Record<LibraryBlockSlug, string>> = {}
for (const slug of LIBRARY_BLOCK_SLUGS) {
const setting = options[slug]
if (!setting) {continue}
out[slug] = typeof setting === 'object' && setting.slug ? setting.slug : slug
}
return out
}