UNPKG

@ai-growth/nextjs

Version:

Seamlessly integrate Sanity CMS with Next.js applications for automated blog routing and rendering

121 lines 3.72 kB
import { type TemplateComponent, type TemplateRegistry, type ContentRenderers } from '../components/CmsProvider'; /** * Template resolution options */ export interface TemplateResolutionOptions { /** Fallback template when no match is found */ fallbackTemplate?: TemplateComponent; /** Content type hierarchy for inheritance */ contentTypeHierarchy?: string[]; /** Enable debug logging */ debug?: boolean; } /** * Template resolution result */ export interface TemplateResolutionResult { /** Resolved template component */ template: TemplateComponent | null; /** Match type that was used */ matchType: 'exact' | 'wildcard' | 'parent' | 'hierarchy' | 'fallback' | 'none'; /** Content type that matched */ matchedContentType?: string; /** Resolution path taken */ resolutionPath: string[]; } /** * Partial template override configuration */ export interface PartialTemplateOverride { /** Content types this override applies to */ contentTypes: string[]; /** Custom renderers for specific sections */ customRenderers?: ContentRenderers; /** Base template to extend (optional) */ baseTemplate?: TemplateComponent; /** Override specific template properties */ templateProps?: Partial<{ showMetadata: boolean; showAuthor: boolean; className: string; }>; } /** * Enhanced template resolver with advanced features */ export declare class TemplateResolver { private templateRegistry; private partialOverrides; private resolutionCache; constructor(templateRegistry: TemplateRegistry); /** * Register a partial template override */ registerPartialOverride(override: PartialTemplateOverride): void; /** * Remove all partial overrides */ clearPartialOverrides(): void; /** * Update the template registry */ updateRegistry(newRegistry: TemplateRegistry): void; /** * Clear resolution cache */ clearCache(): void; /** * Resolve template for a content type with advanced logic */ resolveTemplate(contentType: string, options?: TemplateResolutionOptions): TemplateResolutionResult; /** * Get partial overrides for a content type */ getPartialOverrides(contentType: string): PartialTemplateOverride[]; /** * Create a template component with partial overrides applied */ createTemplateWithOverrides(baseTemplate: TemplateComponent, contentType: string): TemplateComponent; /** * Perform the actual template resolution */ private performResolution; /** * Find wildcard pattern match */ private findWildcardMatch; /** * Find parent type match */ private findParentMatch; /** * Check if content type matches a wildcard pattern */ private matchesWildcardPattern; /** * Check if content type matches another content type (including wildcards) */ private matchesContentType; /** * Generate cache key for resolution result */ private getCacheKey; /** * Get resolution statistics */ getStatistics(): { cacheSize: number; registrySize: number; overridesCount: number; }; } /** * Create a template resolver instance */ export declare function createTemplateResolver(templateRegistry: TemplateRegistry): TemplateResolver; /** * Utility function to resolve template with simple interface */ export declare function resolveTemplate(contentType: string, templateRegistry: TemplateRegistry, options?: TemplateResolutionOptions): TemplateComponent | null; export default TemplateResolver; //# sourceMappingURL=templateResolver.d.ts.map