/** * This module defines a {@linkcode ComponentRegistry}, a mapping between Optimizely CMS content types and * frontend Components (React components, Vue components, etc.) * * To define the `ComponentRegistry`, developers can provide a {@linkcode ComponentMap} object or a * {@linkcode ComponentResolver} function * * @module */ /** * A component definition that includes a default component and optional * tagged variants */ type ComponentWithVariants = { /** Default component */ default?: C; /** * Tagged variants, where the keys are tag names and the values are the corresponding components. */ tags: Record; }; /** A component entry that can be a single component or a component with tagged variants */ type ComponentEntry = C | ComponentWithVariants; /** Optional arguments to resolve a component */ type ResolverOptions = { tag?: string; }; /** * A function that dynamically resolves components based on content type and options. * * This provides a flexible alternative to static component mappings, allowing you to * implement custom logic for component resolution, such as lazy loading, conditional * rendering, or dynamic imports. */ type ComponentResolver = (contentType: string, options?: ResolverOptions) => C | undefined; /** Object mapping a content type name to a {@linkcode ComponentEntry} */ type ComponentMap = Record>; /** * Defines the component resolver as a function {@linkcode ComponentResolver} * or as an object {@linkcode ComponentMap} */ export type ComponentResolverOrObject = ComponentResolver | ComponentMap; /** Every component in a {@linkcode ComponentEntry} union, variants included */ type ComponentsOf = E extends ComponentWithVariants ? C : E; type ComponentRegistryConstructor = { /** Infers the component type from the map, so entries may be any mix of one framework's components */ new >(map: M): Registry>; new (resolverOrObject: ComponentResolverOrObject): Registry; }; /** A registry mapping content type names and components */ export type ComponentRegistry = Registry; declare class Registry { resolver: ComponentResolverOrObject; constructor(resolverOrObject: ComponentResolverOrObject); /** Returns the component given its content type name. Returns `undefined` if not found */ getComponent(contentType: string, options?: ResolverOptions): T | undefined; /** Returns entry with optional fallback to base type when contentType ends with "Property" */ private getEntryWithFallback; } export declare const ComponentRegistry: ComponentRegistryConstructor; export {};