Files
ipal-kit/src/modules/block-library/context.ts
T
Radosław SmolińskiandClaude Opus 5.5 2d1cc0e77d 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]>
2026-10-29 14:05:47 +01:00

77 lines
3.8 KiB
TypeScript

import type { ComponentType, ReactNode } from 'react'
import type { ArchiveEntries } from '../content/getArchiveEntries.js'
import type { BuilderFormClassNames } from '../forms/BuilderForm.js'
import type { SendFormAction } from '../forms/RenderForm.js'
import type { ResolveLinkHrefOptions } from '../links/resolveLinkHref.js'
import type { BlockTexts } from './texts.js'
import type { LinkComponent } from './ui/Anchor.js'
import type { CardProps } from './ui/Card.js'
import type { CMSLinkProps, ResolveLink } from './ui/CMSLink.js'
import type { ContainerProps } from './ui/Container.js'
import type { PartClasses } from './ui/cx.js'
import type { ImageComponent, MediaProps } from './ui/Media.js'
import type { SectionProps } from './ui/Section.js'
import type { SectionHeaderProps } from './ui/SectionHeader.js'
/** The UI primitives every library block is built from. Swap any of them with createBlockRegistry({ ui }). */
export type BlockUi = {
buttonClass: (appearance?: null | string) => string
Card: ComponentType<CardProps>
CMSLink: (props: CMSLinkProps) => Promise<ReactNode> | ReactNode
Container: ComponentType<ContainerProps>
Media: ComponentType<MediaProps>
Section: ComponentType<SectionProps>
SectionHeader: ComponentType<SectionHeaderProps>
}
/** One line of contact details beside the contact form. */
export type ContactDetail = { href?: string; label: string; value: string }
/** One testimonial as the component renders it. */
export type TestimonialItem = { heading: string; id?: null | string; media?: unknown; quote: string; rating?: null | number; text?: null | string }
/** One entry card of the entry list. */
export type EntryCard = { date?: null | string; media?: unknown; text?: null | string; title: string }
/** What the blocks may need from lib/content (createContentHelpers). Only resolveLink is required. */
export type BlockContent = {
getEntries?: (collection: string, locale: string, page: number, perPage: number) => Promise<ArchiveEntries>
getFormTexts?: (locale: string) => Promise<unknown>
getLinkOptions?: (locale: string) => Promise<ResolveLinkHrefOptions>
resolveLink: ResolveLink
}
/** Everything a block gets from the registry besides its data. */
export type BlockContext = {
/** Contact details beside the form (from the project's company global). */
contactDetails?: (locale: string) => ContactDetail[] | Promise<ContactDetail[]>
content: BlockContent
/** Turns a collection document into an entry card. Default: title, excerpt/description, media/image, publishedAt. */
entryCard?: (doc: Record<string, unknown>, collection: string) => EntryCard | null
formClassNames?: BuilderFormClassNames
/** The project's icon components by name (the names of buildFeatureGridBlock({ icons })). */
icons?: Record<string, ComponentType<{ 'aria-hidden'?: boolean; className?: string }>>
/** next/image — optimized images with blur-up. Without it: a plain <img>. */
Image?: ImageComponent
/** Lightbox triggers on gallery images. Default true (needs <SiteProviders lightbox>). */
lightbox: boolean
/** next/link — client-side navigation for internal links. Without it: a plain <a>. */
Link?: LinkComponent
/** Turns a testimonials-collection document into an item. Default: quote, heading/author/name, text/role, media, rating. */
mapTestimonial?: (doc: Record<string, unknown>) => null | TestimonialItem
richText?: { className?: string }
/** The project's sendForm server action (createSubmitAction) — the contact block needs it. */
sendForm?: SendFormAction
texts?: Partial<Record<string, Partial<BlockTexts>>>
}
/** Props of every library block component: its data + locale + what the registry binds. */
export type LibraryBlockProps<D> = {
classNames?: PartClasses
ctx: BlockContext
isFirst?: boolean
locale: string
ui: BlockUi
} & D