rdesign/frontend/node_modules/@copilotkit/a2ui-renderer/dist/react-renderer/registry/ComponentRegistry.mjs.map

1 line
4.5 KiB
Plaintext

{"version":3,"file":"ComponentRegistry.mjs","names":[],"sources":["../../../src/react-renderer/registry/ComponentRegistry.ts"],"sourcesContent":["import { lazy, type ComponentType } from \"react\";\nimport type { Types } from \"@a2ui/lit/0.8\";\nimport type {\n A2UIComponentProps,\n ComponentLoader,\n ComponentRegistration,\n} from \"../types\";\n\n/**\n * Registry for A2UI components. Allows registration of custom components\n * and supports lazy loading for code splitting.\n *\n * @example\n * ```tsx\n * const registry = new ComponentRegistry();\n *\n * // Register a component directly\n * registry.register('Text', { component: Text });\n *\n * // Register with lazy loading\n * registry.register('Modal', {\n * component: () => import('./components/Modal'),\n * lazy: true\n * });\n *\n * // Use with A2UIRenderer\n * <A2UIRenderer surfaceId=\"main\" registry={registry} />\n * ```\n */\nexport class ComponentRegistry {\n private static _instance: ComponentRegistry | null = null;\n private registry = new Map<string, ComponentRegistration>();\n private lazyCache = new Map<string, ComponentType<A2UIComponentProps>>();\n\n /**\n * Get the singleton instance of the registry.\n * Use this for the default global registry.\n */\n static getInstance(): ComponentRegistry {\n if (!ComponentRegistry._instance) {\n ComponentRegistry._instance = new ComponentRegistry();\n }\n return ComponentRegistry._instance;\n }\n\n /**\n * Reset the singleton instance.\n * Useful for testing.\n */\n static resetInstance(): void {\n ComponentRegistry._instance = null;\n }\n\n /**\n * Register a component type.\n *\n * @param type - The A2UI component type name (e.g., 'Text', 'Button')\n * @param registration - The component registration\n */\n register<T extends Types.AnyComponentNode>(\n type: string,\n registration: ComponentRegistration<T>,\n ): void {\n this.registry.set(type, registration as unknown as ComponentRegistration);\n }\n\n /**\n * Unregister a component type.\n *\n * @param type - The component type to unregister\n */\n unregister(type: string): void {\n this.registry.delete(type);\n this.lazyCache.delete(type);\n }\n\n /**\n * Check if a component type is registered.\n *\n * @param type - The component type to check\n * @returns True if the component is registered\n */\n has(type: string): boolean {\n return this.registry.has(type);\n }\n\n /**\n * Get a component by type. If the component is registered with lazy loading,\n * returns a React.lazy wrapped component.\n *\n * @param type - The component type to get\n * @returns The React component, or null if not found\n */\n get(type: string): ComponentType<A2UIComponentProps> | null {\n const registration = this.registry.get(type);\n if (!registration) return null;\n\n // If lazy loading is enabled and the component is a loader function\n if (registration.lazy && typeof registration.component === \"function\") {\n // Check cache first\n const cached = this.lazyCache.get(type);\n if (cached) return cached;\n\n // Create lazy component and cache it\n const lazyComponent = lazy(registration.component as ComponentLoader);\n this.lazyCache.set(type, lazyComponent);\n return lazyComponent;\n }\n\n return registration.component as ComponentType<A2UIComponentProps>;\n }\n\n /**\n * Get all registered component types.\n *\n * @returns Array of registered type names\n */\n getRegisteredTypes(): string[] {\n return Array.from(this.registry.keys());\n }\n\n /**\n * Clear all registrations.\n */\n clear(): void {\n this.registry.clear();\n this.lazyCache.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,oBAAb,MAAa,kBAAkB;;kCAEV,IAAI,KAAoC;mCACvC,IAAI,KAAgD;;;mBAFnB;;;;;;CAQrD,OAAO,cAAiC;AACtC,MAAI,CAAC,kBAAkB,UACrB,mBAAkB,YAAY,IAAI,mBAAmB;AAEvD,SAAO,kBAAkB;;;;;;CAO3B,OAAO,gBAAsB;AAC3B,oBAAkB,YAAY;;;;;;;;CAShC,SACE,MACA,cACM;AACN,OAAK,SAAS,IAAI,MAAM,aAAiD;;;;;;;CAQ3E,WAAW,MAAoB;AAC7B,OAAK,SAAS,OAAO,KAAK;AAC1B,OAAK,UAAU,OAAO,KAAK;;;;;;;;CAS7B,IAAI,MAAuB;AACzB,SAAO,KAAK,SAAS,IAAI,KAAK;;;;;;;;;CAUhC,IAAI,MAAwD;EAC1D,MAAM,eAAe,KAAK,SAAS,IAAI,KAAK;AAC5C,MAAI,CAAC,aAAc,QAAO;AAG1B,MAAI,aAAa,QAAQ,OAAO,aAAa,cAAc,YAAY;GAErE,MAAM,SAAS,KAAK,UAAU,IAAI,KAAK;AACvC,OAAI,OAAQ,QAAO;GAGnB,MAAM,gBAAgB,KAAK,aAAa,UAA6B;AACrE,QAAK,UAAU,IAAI,MAAM,cAAc;AACvC,UAAO;;AAGT,SAAO,aAAa;;;;;;;CAQtB,qBAA+B;AAC7B,SAAO,MAAM,KAAK,KAAK,SAAS,MAAM,CAAC;;;;;CAMzC,QAAc;AACZ,OAAK,SAAS,OAAO;AACrB,OAAK,UAAU,OAAO"}