react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
56 lines (54 loc) • 1.69 kB
JavaScript
import { Fragment, cloneElement, createElement } from "react";
//#region src/markdown/runtime.ts
/**
* React-specific runtime for the markdown processor.
* Implements the MarkdownRuntime interface using React's primitives.
*/
const reactRuntime = {
/**
* Creates a React element.
* Handles the conversion of props and children to React format.
*/
createElement: (type, props, ...children) => {
if (children.length === 0) return createElement(type, props);
if (children.length === 1) return createElement(type, props, children[0]);
return createElement(type, props, ...children);
},
/**
* Clones a React element with new props.
*/
cloneElement: (element, props, ...children) => {
if (children.length === 0) return cloneElement(element, props);
return cloneElement(element, props, ...children);
},
/**
* React Fragment component.
*/
Fragment,
/**
* React-specific prop normalization.
* React uses className instead of class, htmlFor instead of for, etc.
* The core processor already handles ATTRIBUTE_TO_NODE_PROP_MAP,
* so this is mostly a no-op but can be used for additional React-specific transforms.
*/
normalizeProps: (_tag, props) => {
return props;
}
};
/**
* Creates a React runtime with custom createElement for advanced use cases.
* Useful for wrapping elements or adding middleware.
*/
const createReactRuntime = (options = {}) => {
const { onCreateElement } = options;
if (onCreateElement) return {
...reactRuntime,
createElement: (type, props, ...children) => {
return onCreateElement(type, props, children);
}
};
return reactRuntime;
};
//#endregion
export { createReactRuntime, reactRuntime };
//# sourceMappingURL=runtime.mjs.map