UNPKG

@botonic/react

Version:

Build Chatbots using React

44 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Text = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const react_1 = require("react"); const react_2 = require("../util/react"); const markdown_1 = require("./markdown"); const message_1 = require("./message"); const serializeText = children => { children = Array.isArray(children) ? children : [children]; const text = children .filter(e => !e.type) .map(e => { if (Array.isArray(e)) return serializeText(e); else return String(e); }) .join(''); return text; }; const serialize = (textProps) => { if (!textProps.markdown) return { text: serializeText(textProps.children), }; return { text: (0, markdown_1.serializeMarkdown)(textProps.children) }; }; const Text = (props) => { const defaultTextProps = { markdown: props.markdown === undefined ? true : props.markdown, feedbackEnabled: props.feedbackEnabled, inferenceId: props.inferenceId, botInteractionId: props.botInteractionId, }; const textProps = (0, react_2.mapObjectNonBooleanValues)(Object.assign(Object.assign(Object.assign({}, props), defaultTextProps), { children: react_1.Children.toArray(props.children) })); if (!textProps.markdown) return ((0, jsx_runtime_1.jsx)(message_1.Message, Object.assign({ json: serialize(textProps) }, textProps, { type: core_1.INPUT.TEXT }, { children: textProps.children }))); return ((0, jsx_runtime_1.jsx)(message_1.Message, Object.assign({ json: serialize(textProps) }, textProps, { type: core_1.INPUT.TEXT }, { children: (0, markdown_1.toMarkdownChildren)(textProps.children) }))); }; exports.Text = Text; exports.Text.serialize = serialize; //# sourceMappingURL=text.js.map