import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Textarea from '@/app/components/base/textarea' import { useChatContext } from '@/app/components/base/chat/chat/context' enum DATA_FORMAT { TEXT = 'text', JSON = 'json', } enum SUPPORTED_TAGS { LABEL = 'label', INPUT = 'input', TEXTAREA = 'textarea', BUTTON = 'button', } enum SUPPORTED_TYPES { TEXT = 'text', PASSWORD = 'password', EMAIL = 'email', NUMBER = 'number', } const MarkdownForm = ({ node }: any) => { // const supportedTypes = ['text', 'password', 'email', 'number'] //
// // // // // // // //
const { onSend } = useChatContext() const getFormValues = (children: any) => { const formValues: { [key: string]: any } = {} children.forEach((child: any) => { if (child.tagName === SUPPORTED_TAGS.INPUT) formValues[child.properties.name] = child.properties.value if (child.tagName === SUPPORTED_TAGS.TEXTAREA) formValues[child.properties.name] = child.properties.value }) return formValues } const onSubmit = (e: any) => { e.preventDefault() const format = node.properties.dataFormat || DATA_FORMAT.TEXT const result = getFormValues(node.children) if (format === DATA_FORMAT.JSON) { onSend?.(JSON.stringify(result)) } else { const textResult = Object.entries(result) .map(([key, value]) => `${key}: ${value}`) .join('\n') onSend?.(textResult) } } return (
{ e.preventDefault() e.stopPropagation() }} > {node.children.filter((i: any) => i.type === 'element').map((child: any, index: number) => { if (child.tagName === SUPPORTED_TAGS.LABEL) { return ( ) } if (child.tagName === SUPPORTED_TAGS.INPUT) { if (Object.values(SUPPORTED_TYPES).includes(child.properties.type)) { return ( { e.preventDefault() child.properties.value = e.target.value }} /> ) } else { return

Unsupported input type: {child.properties.type}

} } if (child.tagName === SUPPORTED_TAGS.TEXTAREA) { return (