cms-renderer 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/lib/ai-preview.d.ts +62 -0
- package/dist/lib/ai-preview.js +114 -0
- package/dist/lib/ai-preview.js.map +1 -0
- package/dist/lib/block-renderer.js +14 -2
- package/dist/lib/block-renderer.js.map +1 -1
- package/dist/lib/custom-schemas.js +126 -42
- package/dist/lib/custom-schemas.js.map +1 -1
- package/dist/lib/docs-markdown.js +49 -1
- package/dist/lib/docs-markdown.js.map +1 -1
- package/dist/lib/markdown-utils.js +46 -1
- package/dist/lib/markdown-utils.js.map +1 -1
- package/dist/lib/parametric-route.js +18 -6
- package/dist/lib/parametric-route.js.map +1 -1
- package/dist/lib/renderer.js +18 -6
- package/dist/lib/renderer.js.map +1 -1
- package/dist/lib/types.d.ts +2 -0
- package/dist/lib/types.js.map +1 -1
- package/package.json +5 -1
package/dist/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../lib/types.ts"],"sourcesContent":["/**\n * Block Rendering Types\n *\n * Type definitions for the ComponentMap pattern.\n * Block types map to React components via the blockComponents registry.\n */\n\nimport type { ComponentType } from 'react';\n\n// Ensures the emitted JS stays a module for consumers that import this entry for types.\nexport const __cmsRendererTypesModule = true;\n\n// -----------------------------------------------------------------------------\n// Block Type Discriminant\n// -----------------------------------------------------------------------------\n\n/**\n * Valid block type strings.\n * Must match the schema_name field in block data from the tRPC API.\n */\nexport type BlockType =\n | 'navigation'\n | 'header'\n | 'article'\n | 'hero-block'\n | 'features-block'\n | 'cta-block'\n | 'logo-trust-block';\n\n// -----------------------------------------------------------------------------\n// Content Types (inferred from seed data)\n// -----------------------------------------------------------------------------\n\n/**\n * Navigation link button structure.\n */\ninterface NavigationButton {\n label: string;\n href: string;\n ariaLabel: string;\n}\n\n/**\n * Navigation link with type and button.\n */\ninterface NavigationLink {\n button: NavigationButton;\n type: 'Default' | 'Flyout';\n}\n\n/**\n * Level 3 navigation item (leaf node).\n */\ninterface Level3Link {\n link: NavigationLink;\n}\n\n/**\n * Level 2 navigation item with optional Level 3 children.\n */\ninterface Level2Link {\n link: NavigationLink;\n children?: Level3Link[];\n}\n\n/**\n * Level 1 navigation item with optional Level 2 children.\n */\ninterface Level1Link {\n link: NavigationLink;\n children?: Level2Link[];\n}\n\n/**\n * Navigation block content.\n */\ninterface NavigationContent {\n logo?: {\n url: string;\n alt: string;\n };\n ariaLabel: string;\n links: Level1Link[];\n}\n\n/**\n * Header block content.\n */\ninterface HeaderContent {\n headline: string;\n subheadline?: string;\n backgroundImage?: {\n url: string;\n alt: string;\n };\n ctaButton?: {\n label: string;\n href: string;\n };\n alignment: 'left' | 'center' | 'right';\n}\n\n/**\n * Article block content.\n */\ninterface ArticleContent {\n headline: string;\n author?: string;\n publishedAt?: string;\n body: string;\n tags?: readonly string[] | string[];\n status?: string;\n}\n\n/**\n * Hero block content (from CMS schema).\n */\nexport type HeroBlockContent = import('@repo/cms-schema/blocks').HeroBlockContent;\n\n/**\n * Features block content (from CMS schema).\n */\nexport type FeaturesBlockContent = import('@repo/cms-schema/blocks').FeaturesBlockContent;\n\n/**\n * CTA block content (from CMS schema).\n */\nexport type CTABlockContent = import('@repo/cms-schema/blocks').CTABlockContent;\n\n/**\n * Logo Trust block content (from CMS schema).\n */\nexport type LogoTrustBlockContent = import('@repo/cms-schema/blocks').LogoTrustBlockContent;\n\n// -----------------------------------------------------------------------------\n// Block Data Union\n// -----------------------------------------------------------------------------\n\n/**\n * Discriminated union of all block types.\n * Use the `type` field to narrow to specific content types.\n *\n * Each block also carries its stable CMS `id`, which should be used as the\n * React `key` when rendering lists of blocks.\n *\n * @example\n * ```tsx\n * function renderBlock(block: BlockData) {\n * if (block.type === 'header') {\n * // TypeScript knows block.content is HeaderContent\n * return <h1>{block.content.headline}</h1>;\n * }\n * }\n * ```\n */\nexport type BlockData =\n | { id: string; type: 'navigation'; content: NavigationContent }\n | { id: string; type: 'header'; content: HeaderContent }\n | { id: string; type: 'article'; content: ArticleContent }\n | { id: string; type: 'hero-block'; content: HeroBlockContent }\n | { id: string; type: 'features-block'; content: FeaturesBlockContent }\n | { id: string; type: 'cta-block'; content: CTABlockContent }\n | { id: string; type: 'logo-trust-block'; content: LogoTrustBlockContent }\n | { id: string; type: string; content: Record<string, unknown> };\n\n// -----------------------------------------------------------------------------\n// Document Types (for custom schema data fetching)\n// -----------------------------------------------------------------------------\n\n/**\n * Document metadata fields returned by the CMS API.\n * These are added to all documents beyond their schema-defined fields.\n *\n * Use with generated Zod schemas:\n * @example\n * ```ts\n * import type { DocumentMetadata } from 'cms-renderer/lib/types';\n * import type { Post as GeneratedPost } from './generated/cms-schemas';\n *\n * export interface Post extends DocumentMetadata, GeneratedPost {}\n * ```\n */\ninterface DocumentMetadata {\n _id: string;\n _title?: string;\n}\n\n/**\n * Reference to another document.\n * Used in reference fields and arrays of references.\n *\n * @example\n * ```ts\n * interface Category extends DocumentMetadata {\n * post_list?: Reference[];\n * }\n * ```\n */\ninterface Reference {\n _ref: string;\n}\n\n// -----------------------------------------------------------------------------\n// Route Parameter Types\n// -----------------------------------------------------------------------------\n\n/**\n * Resolved route parameter info exposed to block components.\n * Contains the parameter value, its schema name, and the resolved document.\n */\ninterface RouteParamInfo {\n value: string;\n schemaName: string;\n document: {\n id: string;\n title: string;\n content: Record<string, unknown>;\n schema_name: string;\n };\n}\n\n/**\n * Map of route parameter names to their resolved info.\n * E.g., `{ country: { value: \"us\", schemaName: \"country\", document: {...} } }`\n */\nexport type ResolvedRouteParams = Record<string, RouteParamInfo>;\n\n// -----------------------------------------------------------------------------\n// Component Types\n// -----------------------------------------------------------------------------\n\n/**\n * Props for a block component.\n * Each block component receives its typed content.\n */\ninterface BlockComponentProps<T> {\n content: T;\n routeParams?: ResolvedRouteParams;\n /** ISO 639-1 language code extracted from the route's language param, if present. */\n language?: string;\n}\n\n/**\n * A React component that renders a specific block type.\n */\nexport type BlockComponent<T> = ComponentType<BlockComponentProps<T>>;\n\n/**\n * Registry of block type to component mappings.\n * This is the core of the ComponentMap pattern.\n *\n * Predefined block types have strongly-typed content.\n * Custom blocks (keyed by their schema_name) receive `Record<string, unknown>`.\n */\ninterface BlockComponentRegistry {\n navigation: BlockComponent<NavigationContent>;\n header: BlockComponent<HeaderContent>;\n article: BlockComponent<ArticleContent>;\n 'hero-block': BlockComponent<HeroBlockContent>;\n 'features-block': BlockComponent<FeaturesBlockContent>;\n 'cta-block': BlockComponent<CTABlockContent>;\n 'logo-trust-block': BlockComponent<LogoTrustBlockContent>;\n // Custom blocks: register by schema_name\n // biome-ignore lint/suspicious/noExplicitAny: Custom block content is dynamic\n [schemaName: string]: BlockComponent<any>;\n}\n\nexport type {\n ArticleContent,\n BlockComponentProps,\n BlockComponentRegistry,\n DocumentMetadata,\n HeaderContent,\n Level1Link,\n Level2Link,\n Level3Link,\n NavigationButton,\n NavigationContent,\n NavigationLink,\n Reference,\n RouteParamInfo,\n};\n"],"mappings":";AAUO,IAAM,2BAA2B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../lib/types.ts"],"sourcesContent":["/**\n * Block Rendering Types\n *\n * Type definitions for the ComponentMap pattern.\n * Block types map to React components via the blockComponents registry.\n */\n\nimport type { ComponentType } from 'react';\n\n// Ensures the emitted JS stays a module for consumers that import this entry for types.\nexport const __cmsRendererTypesModule = true;\n\n// -----------------------------------------------------------------------------\n// Block Type Discriminant\n// -----------------------------------------------------------------------------\n\n/**\n * Valid block type strings.\n * Must match the schema_name field in block data from the tRPC API.\n */\nexport type BlockType =\n | 'navigation'\n | 'header'\n | 'article'\n | 'hero-block'\n | 'features-block'\n | 'cta-block'\n | 'logo-trust-block';\n\n// -----------------------------------------------------------------------------\n// Content Types (inferred from seed data)\n// -----------------------------------------------------------------------------\n\n/**\n * Navigation link button structure.\n */\ninterface NavigationButton {\n label: string;\n href: string;\n ariaLabel: string;\n}\n\n/**\n * Navigation link with type and button.\n */\ninterface NavigationLink {\n button: NavigationButton;\n type: 'Default' | 'Flyout';\n}\n\n/**\n * Level 3 navigation item (leaf node).\n */\ninterface Level3Link {\n link: NavigationLink;\n}\n\n/**\n * Level 2 navigation item with optional Level 3 children.\n */\ninterface Level2Link {\n link: NavigationLink;\n children?: Level3Link[];\n}\n\n/**\n * Level 1 navigation item with optional Level 2 children.\n */\ninterface Level1Link {\n link: NavigationLink;\n children?: Level2Link[];\n}\n\n/**\n * Navigation block content.\n */\ninterface NavigationContent {\n logo?: {\n url: string;\n alt: string;\n };\n ariaLabel: string;\n links: Level1Link[];\n}\n\n/**\n * Header block content.\n */\ninterface HeaderContent {\n headline: string;\n subheadline?: string;\n backgroundImage?: {\n url: string;\n alt: string;\n };\n ctaButton?: {\n label: string;\n href: string;\n };\n alignment: 'left' | 'center' | 'right';\n}\n\n/**\n * Article block content.\n */\ninterface ArticleContent {\n headline: string;\n author?: string;\n publishedAt?: string;\n body: string;\n tags?: readonly string[] | string[];\n status?: string;\n}\n\n/**\n * Hero block content (from CMS schema).\n */\nexport type HeroBlockContent = import('@repo/cms-schema/blocks').HeroBlockContent;\n\n/**\n * Features block content (from CMS schema).\n */\nexport type FeaturesBlockContent = import('@repo/cms-schema/blocks').FeaturesBlockContent;\n\n/**\n * CTA block content (from CMS schema).\n */\nexport type CTABlockContent = import('@repo/cms-schema/blocks').CTABlockContent;\n\n/**\n * Logo Trust block content (from CMS schema).\n */\nexport type LogoTrustBlockContent = import('@repo/cms-schema/blocks').LogoTrustBlockContent;\n\n// -----------------------------------------------------------------------------\n// Block Data Union\n// -----------------------------------------------------------------------------\n\n/**\n * Discriminated union of all block types.\n * Use the `type` field to narrow to specific content types.\n *\n * Each block also carries its stable CMS `id`, which should be used as the\n * React `key` when rendering lists of blocks.\n *\n * @example\n * ```tsx\n * function renderBlock(block: BlockData) {\n * if (block.type === 'header') {\n * // TypeScript knows block.content is HeaderContent\n * return <h1>{block.content.headline}</h1>;\n * }\n * }\n * ```\n */\nexport type BlockData =\n | { id: string; type: 'navigation'; content: NavigationContent }\n | { id: string; type: 'header'; content: HeaderContent }\n | { id: string; type: 'article'; content: ArticleContent }\n | { id: string; type: 'hero-block'; content: HeroBlockContent }\n | { id: string; type: 'features-block'; content: FeaturesBlockContent }\n | { id: string; type: 'cta-block'; content: CTABlockContent }\n | { id: string; type: 'logo-trust-block'; content: LogoTrustBlockContent }\n | { id: string; type: string; content: Record<string, unknown> };\n\n// -----------------------------------------------------------------------------\n// Document Types (for custom schema data fetching)\n// -----------------------------------------------------------------------------\n\n/**\n * Document metadata fields returned by the CMS API.\n * These are added to all documents beyond their schema-defined fields.\n *\n * Use with generated Zod schemas:\n * @example\n * ```ts\n * import type { DocumentMetadata } from 'cms-renderer/lib/types';\n * import type { Post as GeneratedPost } from './generated/cms-schemas';\n *\n * export interface Post extends DocumentMetadata, GeneratedPost {}\n * ```\n */\ninterface DocumentMetadata {\n _id: string;\n _title?: string;\n}\n\n/**\n * Reference to another document.\n * Used in reference fields and arrays of references.\n *\n * @example\n * ```ts\n * interface Category extends DocumentMetadata {\n * post_list?: Reference[];\n * }\n * ```\n */\ninterface Reference {\n _ref: string;\n}\n\n// -----------------------------------------------------------------------------\n// Route Parameter Types\n// -----------------------------------------------------------------------------\n\n/**\n * Resolved route parameter info exposed to block components.\n * Contains the parameter value, its schema name, and the resolved document.\n */\ninterface RouteParamInfo {\n value: string;\n schemaName: string;\n document: {\n id: string;\n title: string;\n content: Record<string, unknown>;\n schema_name: string;\n };\n}\n\n/**\n * Map of route parameter names to their resolved info.\n * E.g., `{ country: { value: \"us\", schemaName: \"country\", document: {...} } }`\n */\nexport type ResolvedRouteParams = Record<string, RouteParamInfo>;\n\n// -----------------------------------------------------------------------------\n// Component Types\n// -----------------------------------------------------------------------------\n\n/**\n * Props for a block component.\n * Each block component receives its typed content.\n */\ninterface BlockComponentProps<T> {\n content: T;\n routeParams?: ResolvedRouteParams;\n /** ISO 639-1 language code extracted from the route's language param, if present. */\n language?: string;\n /** Normalized current route path, e.g. \"/blog\". */\n path?: string;\n}\n\n/**\n * A React component that renders a specific block type.\n */\nexport type BlockComponent<T> = ComponentType<BlockComponentProps<T>>;\n\n/**\n * Registry of block type to component mappings.\n * This is the core of the ComponentMap pattern.\n *\n * Predefined block types have strongly-typed content.\n * Custom blocks (keyed by their schema_name) receive `Record<string, unknown>`.\n */\ninterface BlockComponentRegistry {\n navigation: BlockComponent<NavigationContent>;\n header: BlockComponent<HeaderContent>;\n article: BlockComponent<ArticleContent>;\n 'hero-block': BlockComponent<HeroBlockContent>;\n 'features-block': BlockComponent<FeaturesBlockContent>;\n 'cta-block': BlockComponent<CTABlockContent>;\n 'logo-trust-block': BlockComponent<LogoTrustBlockContent>;\n // Custom blocks: register by schema_name\n // biome-ignore lint/suspicious/noExplicitAny: Custom block content is dynamic\n [schemaName: string]: BlockComponent<any>;\n}\n\nexport type {\n ArticleContent,\n BlockComponentProps,\n BlockComponentRegistry,\n DocumentMetadata,\n HeaderContent,\n Level1Link,\n Level2Link,\n Level3Link,\n NavigationButton,\n NavigationContent,\n NavigationLink,\n Reference,\n RouteParamInfo,\n};\n"],"mappings":";AAUO,IAAM,2BAA2B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cms-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
+
"./lib/ai-preview": {
|
|
8
|
+
"types": "./dist/lib/ai-preview.d.ts",
|
|
9
|
+
"import": "./dist/lib/ai-preview.js"
|
|
10
|
+
},
|
|
7
11
|
"./lib/block-renderer": {
|
|
8
12
|
"types": "./dist/lib/block-renderer.d.ts",
|
|
9
13
|
"import": "./dist/lib/block-renderer.js"
|