UNPKG

react-intlayer

Version:

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

63 lines 2.35 kB
"use strict"; "use client"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var useEditedContentRenderer_exports = {}; __export(useEditedContentRenderer_exports, { EditedContentRenderer: () => EditedContentRenderer, useEditedContentRenderer: () => useEditedContentRenderer }); module.exports = __toCommonJS(useEditedContentRenderer_exports); var import_core = require("@intlayer/core"); var import_editor_react = require("@intlayer/editor-react"); const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => { const editedContentContext = (0, import_editor_react.useEditedContentActions)(); if (editedContentContext) { const editedValue = editedContentContext.getEditedContentValue( dictionaryKey, keyPath ); const value = editedValue ?? children; return value; } return children; }; const EditedContentRenderer = (props) => { const content = useEditedContentRenderer(props); if (typeof content === "object") { const transformedEditedContent = (0, import_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 props.children; } return transformedEditedContent; } return content; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { EditedContentRenderer, useEditedContentRenderer }); //# sourceMappingURL=useEditedContentRenderer.cjs.map