react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
128 lines • 5.27 kB
JavaScript
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 plugins_exports = {};
__export(plugins_exports, {
intlayerNodePlugins: () => intlayerNodePlugins,
markdownPlugin: () => markdownPlugin,
markdownStringPlugin: () => markdownStringPlugin,
reactNodePlugins: () => reactNodePlugins
});
module.exports = __toCommonJS(plugins_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_core = require("@intlayer/core");
var import_IntlayerNode = require('./IntlayerNode.cjs');
var import_editor = require('./editor/index.cjs');
var import_useEditedContentRenderer = require('./editor/useEditedContentRenderer.cjs');
var import_markdown = require('./markdown/index.cjs');
var import_renderReactElement = require('./reactElement/renderReactElement.cjs');
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
}) => (0, import_IntlayerNode.renderIntlayerNode)({
...rest,
value: rest.children,
children: /* @__PURE__ */ (0, import_react.createElement)(import_editor.ContentSelectorRenderer, { ...rest, key: rest.children }, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_useEditedContentRenderer.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
}) => (0, import_IntlayerNode.renderIntlayerNode)({
...rest,
value: "[[react-element]]",
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.ContentSelectorRenderer, { ...rest, children: (0, import_renderReactElement.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 = (0, import_core.getMarkdownMetadata)(node);
const metadataPlugins = {
id: "markdown-metadata-plugin",
canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
transform: (metadataNode, props2) => (0, import_IntlayerNode.renderIntlayerNode)({
...props2,
value: metadataNode,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.ContentSelectorRenderer, { ...rest, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_markdown.MarkdownMetadataRenderer,
{
...rest,
metadataKeyPath: props2.keyPath,
children: node
}
) })
})
};
const metadataNodes = deepTransformNode(metadata, {
plugins: [metadataPlugins],
dictionaryKey: rest.dictionaryKey,
keyPath: []
});
return (0, import_IntlayerNode.renderIntlayerNode)({
...props,
value: node,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.ContentSelectorRenderer, { ...rest, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_markdown.MarkdownRenderer, { ...rest, children: node }) }),
additionalProps: {
metadata: metadataNodes
}
});
}
};
const markdownPlugin = {
id: "markdown-plugin",
canHandle: (node) => typeof node === "object" && node?.nodeType === import_core.NodeType.Markdown,
transform: (node, props, deepTransformNode) => {
const newKeyPath = [
...props.keyPath,
{
type: import_core.NodeType.Markdown
}
];
const children = node[import_core.NodeType.Markdown];
return deepTransformNode(children, {
...props,
children,
keyPath: newKeyPath,
plugins: [markdownStringPlugin, ...props.plugins ?? []]
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
intlayerNodePlugins,
markdownPlugin,
markdownStringPlugin,
reactNodePlugins
});
//# sourceMappingURL=plugins.cjs.map
;