UNPKG

react-intlayer

Version:

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

104 lines 3.67 kB
import { jsx } from "react/jsx-runtime"; import { createElement } from "react"; import { NodeType, getMarkdownMetadata } from "@intlayer/core"; import { renderIntlayerNode } from "./IntlayerNode.mjs"; import { ContentSelectorRenderer } from "./editor/index.mjs"; import { EditedContentRenderer } from "./editor/useEditedContentRenderer.mjs"; import { MarkdownMetadataRenderer, MarkdownRenderer } from "./markdown/index.mjs"; import { renderReactElement } from "./reactElement/renderReactElement.mjs"; const intlayerNodePlugins = { id: "intlayer-node-plugin", canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number", transform: (_node, { plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components ...rest }) => renderIntlayerNode({ ...rest, value: rest.children, children: /* @__PURE__ */ createElement(ContentSelectorRenderer, { ...rest, key: rest.children }, /* @__PURE__ */ jsx(EditedContentRenderer, { ...rest, children: rest.children })) }) }; const reactNodePlugins = { id: "react-node-plugin", canHandle: (node) => typeof node === "object" && typeof node.props !== "undefined" && typeof node.key !== "undefined", transform: (node, { plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components ...rest }) => renderIntlayerNode({ ...rest, value: "[[react-element]]", children: /* @__PURE__ */ jsx(ContentSelectorRenderer, { ...rest, children: renderReactElement(node) }) }) }; const markdownStringPlugin = { id: "markdown-string-plugin", canHandle: (node) => typeof node === "string", transform: (node, props, deepTransformNode) => { const { plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components ...rest } = props; const metadata = getMarkdownMetadata(node); const metadataPlugins = { id: "markdown-metadata-plugin", canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode, transform: (metadataNode, props2) => renderIntlayerNode({ ...props2, value: metadataNode, children: /* @__PURE__ */ jsx(ContentSelectorRenderer, { ...rest, children: /* @__PURE__ */ jsx( MarkdownMetadataRenderer, { ...rest, metadataKeyPath: props2.keyPath, children: node } ) }) }) }; const metadataNodes = deepTransformNode(metadata, { plugins: [metadataPlugins], dictionaryKey: rest.dictionaryKey, keyPath: [] }); return renderIntlayerNode({ ...props, value: node, children: /* @__PURE__ */ jsx(ContentSelectorRenderer, { ...rest, children: /* @__PURE__ */ jsx(MarkdownRenderer, { ...rest, children: node }) }), additionalProps: { metadata: metadataNodes } }); } }; const markdownPlugin = { id: "markdown-plugin", canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Markdown, transform: (node, props, deepTransformNode) => { const newKeyPath = [ ...props.keyPath, { type: NodeType.Markdown } ]; const children = node[NodeType.Markdown]; return deepTransformNode(children, { ...props, children, keyPath: newKeyPath, plugins: [markdownStringPlugin, ...props.plugins ?? []] }); } }; export { intlayerNodePlugins, markdownPlugin, markdownStringPlugin, reactNodePlugins }; //# sourceMappingURL=plugins.mjs.map