react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
40 lines (37 loc) • 1.84 kB
JavaScript
'use client';
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
const require_editor_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
let react = require("react");
let _intlayer_core = require("@intlayer/core");
let _intlayer_editor_react = require("@intlayer/editor-react");
//#region src/editor/useEditedContentRenderer.tsx
const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => {
const editedContentContext = (0, _intlayer_editor_react.useEditedContentActions)();
if (editedContentContext) return editedContentContext.getEditedContentValue(dictionaryKey, keyPath) ?? children;
return children;
};
const EditedContentRenderer = (props) => {
const content = useEditedContentRenderer(props);
if (typeof content === "object") {
const transformedEditedContent = (0, _intlayer_core.getContent)(content, props, props.locale);
if (typeof transformedEditedContent !== "string") {
console.error(`Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`);
return /* @__PURE__ */ (0, react.createElement)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...props,
key: props.children
}, props.children);
}
return /* @__PURE__ */ (0, react.createElement)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...props,
key: props.children
}, transformedEditedContent);
}
return /* @__PURE__ */ (0, react.createElement)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...props,
key: props.children
}, content);
};
//#endregion
exports.EditedContentRenderer = EditedContentRenderer;
exports.useEditedContentRenderer = useEditedContentRenderer;
//# sourceMappingURL=useEditedContentRenderer.cjs.map