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
+19 -2
View File
@@ -80,6 +80,8 @@ export type SeederOptions = {
* Refused outside a local database unless `guard.forceOnlyLocal: false`.
*/
force?: boolean
/** Collection `{ $form: '<title>' }` references resolve in. Default 'forms'. */
formsCollection?: string
/**
* The production guard. false turns it off (the project takes the risk).
* `update` on production (NODE_ENV=production) or a non-local database is
@@ -164,10 +166,16 @@ const defaultLog = (line: string) => {
type Item = { data: Record<string, unknown>; key: Record<string, number | string>; label: string; ref: string }
type Planned = { action?: 'create' | 'update'; id?: number | string; result?: SeedResult } & Item
const formRef = (v: object): string | undefined => {
const ref = (v as { $form?: unknown }).$form
return typeof ref === 'string' ? ref : undefined
}
/** True when the value holds a { $page } or { $form } reference — such fields are written once refs resolve. */
const hasRef = (v: unknown): boolean =>
Array.isArray(v)
? v.some(hasRef)
: !!v && typeof v === 'object' && (typeof (v as { $page?: unknown }).$page === 'string' || Object.values(v).some(hasRef))
: !!v && typeof v === 'object' && (typeof (v as { $page?: unknown }).$page === 'string' || formRef(v) !== undefined || Object.values(v).some(hasRef))
export function createSeeder(payload: BasePayload, options: SeederOptions = {}): Seeder {
const env = process.env
@@ -180,6 +188,7 @@ export function createSeeder(payload: BasePayload, options: SeederOptions = {}):
const hashField = options.editCheck?.hashField ?? defaultHashField()
const untouchedSeconds = options.editCheck?.untouchedSeconds ?? defaultUntouchedSeconds()
const pagesCollection = options.pagesCollection ?? 'pages'
const formsCollection = options.formsCollection ?? 'forms'
const context = { ...DEFAULT_CONTEXT, ...options.context }
const onlyList = options.only ?? (env.SEED_ONLY ? env.SEED_ONLY.split(',') : undefined)
const only = onlyList ? onlyList.map((r) => r.trim()).filter(Boolean) : null
@@ -255,12 +264,20 @@ export function createSeeder(payload: BasePayload, options: SeederOptions = {}):
}
/**
* Replaces { $page: slug } with the page id (a placeholder for a planned create in a dry run).
* Replaces { $page: slug } with the page id (a placeholder for a planned create in a dry run)
* and { $form: title } with the form id (forms are seeded before the pages that use them).
* lenient: an unknown page gives a placeholder instead of an error (edit check before pass 1).
*/
const resolveRefs = async (v: unknown, lenient = false): Promise<unknown> => {
if (Array.isArray(v)) {return Promise.all(v.map((x) => resolveRefs(x, lenient)))}
if (!v || typeof v !== 'object') {return v}
const form = formRef(v)
if (form !== undefined) {
const id = await findId(formsCollection, { title: form })
if (id !== undefined) {return id}
if (lenient || dryRun) {return `(form:${form})`}
throw new Error(`$form "${form}" not found — seed that form first or create it in the panel`)
}
const ref = (v as { $page?: unknown }).$page
if (typeof ref === 'string') {
let id = pageIds.get(ref)