react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
98 lines (96 loc) • 4.18 kB
JavaScript
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
const require_IntlayerNode = require('./IntlayerNode.cjs');
const require_editor_ContentSelectorWrapper = require('./editor/ContentSelectorWrapper.cjs');
const require_editor_useEditedContentRenderer = require('./editor/useEditedContentRenderer.cjs');
const require_markdown_MarkdownRenderer = require('./markdown/MarkdownRenderer.cjs');
const require_reactElement_renderReactElement = require('./reactElement/renderReactElement.cjs');
let react_jsx_runtime = require("react/jsx-runtime");
let _intlayer_core = require("@intlayer/core");
let _intlayer_types = require("@intlayer/types");
//#region src/plugins.tsx
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
const intlayerNodePlugins = {
id: "intlayer-node-plugin",
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
transform: (_node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
...rest,
value: rest.children,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_useEditedContentRenderer.EditedContentRenderer, {
...rest,
children: rest.children
})
})
};
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
const reactNodePlugins = {
id: "react-node-plugin",
canHandle: (node) => typeof node === "object" && typeof node?.props !== "undefined" && typeof node.key !== "undefined",
transform: (node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
...rest,
value: "[[react-element]]",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...rest,
children: require_reactElement_renderReactElement.renderReactElement(node)
})
})
};
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
const markdownStringPlugin = {
id: "markdown-string-plugin",
canHandle: (node) => typeof node === "string",
transform: (node, props, deepTransformNode) => {
const { plugins, ...rest } = props;
const metadataNodes = deepTransformNode((0, _intlayer_core.getMarkdownMetadata)(node), {
plugins: [{
id: "markdown-metadata-plugin",
canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
transform: (metadataNode, props$1) => require_IntlayerNode.renderIntlayerNode({
...props$1,
value: metadataNode,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...rest,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_markdown_MarkdownRenderer.MarkdownMetadataRenderer, {
...rest,
metadataKeyPath: props$1.keyPath,
children: node
})
})
})
}],
dictionaryKey: rest.dictionaryKey,
keyPath: []
});
return require_IntlayerNode.renderIntlayerNode({
...props,
value: node,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelectorWrapper.ContentSelectorRenderer, {
...rest,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_markdown_MarkdownRenderer.MarkdownRenderer, {
...rest,
children: node
})
}),
additionalProps: { metadata: metadataNodes }
});
}
};
const markdownPlugin = {
id: "markdown-plugin",
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types.NodeType.Markdown,
transform: (node, props, deepTransformNode) => {
const newKeyPath = [...props.keyPath, { type: _intlayer_types.NodeType.Markdown }];
const children = node[_intlayer_types.NodeType.Markdown];
return deepTransformNode(children, {
...props,
children,
keyPath: newKeyPath,
plugins: [markdownStringPlugin, ...props.plugins ?? []]
});
}
};
//#endregion
exports.intlayerNodePlugins = intlayerNodePlugins;
exports.markdownPlugin = markdownPlugin;
exports.markdownStringPlugin = markdownStringPlugin;
exports.reactNodePlugins = reactNodePlugins;
//# sourceMappingURL=plugins.cjs.map