UNPKG

@botonic/react

Version:

Build Chatbots using React

40 lines 1.68 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { INPUT } from '@botonic/core'; import { Children } from 'react'; import { mapObjectNonBooleanValues } from '../util/react'; import { serializeMarkdown, toMarkdownChildren } from './markdown'; import { Message } from './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: serializeMarkdown(textProps.children) }; }; export const Text = (props) => { const defaultTextProps = { markdown: props.markdown === undefined ? true : props.markdown, feedbackEnabled: props.feedbackEnabled, inferenceId: props.inferenceId, botInteractionId: props.botInteractionId, }; const textProps = mapObjectNonBooleanValues(Object.assign(Object.assign(Object.assign({}, props), defaultTextProps), { children: Children.toArray(props.children) })); if (!textProps.markdown) return (_jsx(Message, Object.assign({ json: serialize(textProps) }, textProps, { type: INPUT.TEXT }, { children: textProps.children }))); return (_jsx(Message, Object.assign({ json: serialize(textProps) }, textProps, { type: INPUT.TEXT }, { children: toMarkdownChildren(textProps.children) }))); }; Text.serialize = serialize; //# sourceMappingURL=text.js.map