UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

40 lines (37 loc) 1.49 kB
'use client'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs'); let react = require("react"); let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled"); //#region src/editor/useEditor.tsx /** * Initializes the Intlayer editor client singleton when the editor is enabled. * Syncs the current locale from the Intlayer context into the editor manager so * the editor always knows which locale the app is displaying. */ const useEditor = () => { const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {}; const managerRef = (0, react.useRef)(null); (0, react.useEffect)(() => { if (process.env["INTLAYER_EDITOR_ENABLED"] === "false" || !_intlayer_editor_isEnabled.isEnabled) return; import("@intlayer/editor").then(({ initEditorClient }) => { const manager = initEditorClient(); managerRef.current = manager; if (locale) manager.currentLocale.set(locale); }); return () => { managerRef.current = null; import("@intlayer/editor").then(({ stopEditorClient }) => { stopEditorClient(); }); }; }, []); (0, react.useEffect)(() => { if (!locale || !managerRef.current) return; managerRef.current.currentLocale.set(locale); }, [locale]); }; //#endregion exports.useEditor = useEditor; //# sourceMappingURL=useEditor.cjs.map