// src/primitives/card-registry.tsx // One source of truth mapping a CardEnvelope.type to a renderer, for both layers: // - CardComponentMap drives the Solid . // - CardTagMap drives the web component (child kc-* elements). // Built-ins cover the 5 contract card types; consumers extend/override via a `types` // prop (merged OVER the built-ins). kc-card (bare shell) is intentionally NOT a target. import type { Component } from 'solid-js'; import type { CardEnvelope, CardHost } from './card-contract'; import { Form } from '../components/form'; import { ConfirmCard } from '../components/confirm-card'; import { TasksCard } from '../components/tasks-card'; import { ChoiceCard } from '../components/choice-card'; import { LinkPreview } from '../components/link-preview'; import { Embed } from '../components/embed'; /** Solid renderer for one envelope. `host` is the resolved CardHost so each wrapper * can bridge its card's emit convention (form/confirm/tasks take `host`; * link/embed take `onEmit`). */ export type CardComponent = Component<{ envelope: CardEnvelope; host?: CardHost }>; export type CardComponentMap = Record; /** Web-component layer: envelope type → kc-* tag name. */ export type CardTagMap = Record; export const BUILTIN_CARD_TAGS: CardTagMap = { form: 'kc-form', confirm: 'kc-confirm', 'tasks': 'kc-tasks', choice: 'kc-choice', link: 'kc-link-preview', embed: 'kc-embed', }; export const BUILTIN_CARD_COMPONENTS: CardComponentMap = { form: (p) => (
), confirm: (p) => ( ), 'tasks': (p) => ( ), choice: (p) => ( ), // link/embed have no `heading` and emit via an onEmit callback (no context). link: (p) => ( p.host?.emit(e)} /> ), embed: (p) => ( p.host?.emit(e)} /> ), }; /** Built-ins with the consumer's overrides merged on top (consumer wins). */ export function mergeCardComponents(types?: CardComponentMap): CardComponentMap { return types ? { ...BUILTIN_CARD_COMPONENTS, ...types } : { ...BUILTIN_CARD_COMPONENTS }; } export function mergeCardTags(types?: CardTagMap): CardTagMap { return types ? { ...BUILTIN_CARD_TAGS, ...types } : { ...BUILTIN_CARD_TAGS }; }