UNPKG

react-intlayer

Version:

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

61 lines (58 loc) 2.52 kB
'use client'; const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs'); let react = require("react"); let react_jsx_runtime = require("react/jsx-runtime"); let _intlayer_editor_react = require("@intlayer/editor-react"); let _intlayer_config_built = require("@intlayer/config/built"); _intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built); //#region src/editor/IntlayerEditorProvider.tsx const IntlayerEditorHooksEnabled = () => { /** * URL Messages */ (0, _intlayer_editor_react.useCrossURLPathSetter)(); /** * Click Messages */ (0, _intlayer_editor_react.useIframeClickInterceptor)(); /** * Sent local dictionaries to editor */ const { setLocaleDictionaries } = (0, _intlayer_editor_react.useDictionariesRecordActions)(); (0, react.useEffect)(() => { import("@intlayer/unmerged-dictionaries-entry").then((mod) => { const unmergedDictionaries = mod.getUnmergedDictionaries(); const dictionariesList = Object.fromEntries(Object.values(unmergedDictionaries).flat().map((dictionary) => [dictionary.localId, dictionary])); setLocaleDictionaries?.(dictionariesList); }); }, []); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {}); }; const { editor } = _intlayer_config_built.default ?? {}; const IntlayerEditorHook = () => { const { enabled } = (0, _intlayer_editor_react.useEditorEnabled)(); return enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {}); }; const IntlayerEditorProvider = ({ children }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_intlayer_editor_react.EditorProvider, { postMessage: (data) => { if (typeof window === "undefined") return; if (!editor) return; if (!(window.self !== window.top)) return; if (editor.applicationURL.length > 0) window?.postMessage(data, editor.applicationURL); if (editor.editorURL.length > 0) window.parent?.postMessage(data, editor.editorURL); if (editor.cmsURL.length > 0) window.parent?.postMessage(data, editor.cmsURL); }, allowedOrigins: [ editor?.editorURL, editor?.cmsURL, editor?.applicationURL ].filter(Boolean), mode: "client", configuration: _intlayer_config_built.default, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntlayerEditorHook, {}), children] }); }; //#endregion exports.IntlayerEditorProvider = IntlayerEditorProvider; //# sourceMappingURL=IntlayerEditorProvider.cjs.map