mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-27 19:52:49 +00:00
Keep translation resources and subscriptions inside each installation. Resolve host labels against the presentation locale so live language changes preserve mounted drafts and RPC state. Existing descriptor types retain string defaults for source compatibility.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { PluginTranslationProvider, usePluginTranslationRuntime } from "./translations.js";
|
|
import { useCallback, type ReactNode } from "react";
|
|
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();
|
|
|
|
if (!paseo || !rpc) {
|
|
throw new Error("Plugin UI must run inside a contributed plugin surface");
|
|
}
|
|
|
|
return useCallback(
|
|
(children: ReactNode) => {
|
|
const content = state ? (
|
|
<PluginClientStateProvider source={state}>{children}</PluginClientStateProvider>
|
|
) : (
|
|
children
|
|
);
|
|
return (
|
|
<PaseoApiProvider paseo={paseo}>
|
|
<PluginRpcProvider invoke={rpc.invoke}>
|
|
<PluginTranslationProvider runtime={translations}>{content}</PluginTranslationProvider>
|
|
</PluginRpcProvider>
|
|
</PaseoApiProvider>
|
|
);
|
|
},
|
|
[paseo, rpc, state, translations],
|
|
);
|
|
}
|