import { PluginTranslationProvider, usePluginTranslationRuntime } from "./translations.js"; import { useCallback, type ReactNode } from "react"; import { PluginComposerProvider, PluginComposersProvider, usePluginComposerValue, usePluginComposersSource, } from "./composer.js"; import { PluginClientStateProvider, usePluginClientStateSource } from "./client-state.js"; import { PaseoApiProvider, usePaseoContextValue } from "./paseo-context.js"; import { PluginRpcProvider, usePluginRpcContextValue } from "./rpc-context.js"; export type PluginRuntimeContextBridge = (children: ReactNode) => ReactNode; /** Rebuilds plugin runtime contexts inside React Native portal hosts. */ export function usePluginRuntimeContextBridge(): PluginRuntimeContextBridge { const translations = usePluginTranslationRuntime(); const paseo = usePaseoContextValue(); const rpc = usePluginRpcContextValue(); const state = usePluginClientStateSource(); const composer = usePluginComposerValue(); const composers = usePluginComposersSource(); if (!paseo || !rpc) { throw new Error("Plugin UI must run inside a contributed plugin surface"); } return useCallback( (children: ReactNode) => { const withState = state ? ( {children} ) : ( children ); const withComposers = composers ? ( {withState} ) : ( withState ); const content = composer ? ( {withComposers} ) : ( withComposers ); return ( {content} ); }, [composer, composers, paseo, rpc, state, translations], ); }