Barazo default frontend barazo.forum
at main 45 lines 1.4 kB view raw
1/** 2 * Plugin frontend loader. 3 * Registers bundled plugin components into the slot registry. 4 * Called once by PluginProvider after the plugin list is fetched. 5 */ 6 7import type { ComponentType } from 'react' 8import { registerPluginComponent } from './registry' 9import type { SlotName } from './registry' 10 11interface PluginComponentRegistry { 12 add: (slot: string, component: ComponentType<Record<string, unknown>>) => void 13} 14 15function createRegistryAdapter(pluginName: string): PluginComponentRegistry { 16 return { 17 add(slot: string, component: ComponentType<Record<string, unknown>>) { 18 registerPluginComponent(slot as SlotName, pluginName, component) 19 }, 20 } 21} 22 23const BUNDLED_PLUGINS: Record< 24 string, 25 () => Promise<{ register: (r: PluginComponentRegistry) => void }> 26> = { 27 '@barazo/plugin-signatures': () => import('@barazo/plugin-signatures/frontend/register'), 28} 29 30let loaded = false 31 32export async function loadBundledPlugins(enabledPluginNames: string[]): Promise<void> { 33 if (loaded) return 34 loaded = true 35 36 for (const [name, loader] of Object.entries(BUNDLED_PLUGINS)) { 37 if (!enabledPluginNames.includes(name)) continue 38 try { 39 const mod = await loader() 40 mod.register(createRegistryAdapter(name)) 41 } catch { 42 // Plugin failed to load — silently skip (error boundary catches render errors) 43 } 44 } 45}