- docs/block-library.md: setup, every block (fields, variants, accessibility), options, registry, primitives, eject, page templates, seeding after launch, versioning, manifest, turn off / override / extend - AGENT.md (compass, how to add, §6, §6.3, module map), ipal-block (library block first), ipal-site (phases 2, 4, 6, 8), ipal-reference (wiring rows, export index), seed-content template from pageTemplates, seeding.md ($form) - CHANGELOG Unreleased; proposal marked built with an as-built section Co-Authored-By: Claude Opus 5.5 <[email protected]>
110 lines
4.2 KiB
TypeScript
110 lines
4.2 KiB
TypeScript
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. */
|
|
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>>
|
|
|
|
/** The 15 slugs in the order of the block picker: the sections every site needs first. */
|
|
export const LIBRARY_BLOCK_SLUGS: readonly LibraryBlockSlug[] = [
|
|
'hero',
|
|
'textMedia',
|
|
'featureGrid',
|
|
'cta',
|
|
'richText',
|
|
'faq',
|
|
'contact',
|
|
'gallery',
|
|
'testimonials',
|
|
'stats',
|
|
'steps',
|
|
'logos',
|
|
'team',
|
|
'pricing',
|
|
'entryList',
|
|
]
|
|
|
|
/** 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
|
|
}
|