UNPKG

react-intlayer

Version:

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

53 lines (51 loc) 1.71 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); let react = require("react"); //#region src/reactElement/renderReactElement.ts const renderReactElement = (element) => { if (element === null || typeof element !== "object") return element; const convertChildrenAsArray = (element) => { const children = element.props?.children; if (Array.isArray(children)) { const childrenResult = children.map((child, index) => { const renderedChild = renderReactElement(child); if (typeof renderedChild === "object" && renderedChild !== null && "type" in renderedChild) { const childElement = renderedChild; return (0, react.createElement)(childElement.type, { ...childElement.props, key: index }, ...Array.isArray(childElement.props?.children) ? childElement.props.children : typeof childElement.props?.children !== "undefined" ? [childElement.props.children] : []); } return renderedChild; }); return { ...element, props: { ...element.props, children: childrenResult } }; } else if (typeof children !== "undefined" && children !== null) { const renderedChild = renderReactElement(children); return { ...element, props: { ...element.props, children: [renderedChild] } }; } return { ...element, props: { ...element.props, children: [] } }; }; const { type, props } = convertChildrenAsArray(element); return (0, react.createElement)(type ?? "span", props, ...props.children); }; //#endregion exports.renderReactElement = renderReactElement; //# sourceMappingURL=renderReactElement.cjs.map