diff --git a/web/app/components/base/markdown-blocks/button.tsx b/web/app/components/base/markdown-blocks/button.tsx new file mode 100644 index 0000000000..56647b3bbe --- /dev/null +++ b/web/app/components/base/markdown-blocks/button.tsx @@ -0,0 +1,22 @@ +import { useChatContext } from '@/app/components/base/chat/chat/context' +import Button from '@/app/components/base/button' +import cn from '@/utils/classnames' + +const MarkdownButton = ({ node }: any) => { + const { onSend } = useChatContext() + const variant = node.properties.dataVariant + const message = node.properties.dataMessage + const size = node.properties.dataSize + + return +} +MarkdownButton.displayName = 'MarkdownButton' + +export default MarkdownButton diff --git a/web/app/components/base/markdown-blocks/form.tsx b/web/app/components/base/markdown-blocks/form.tsx new file mode 100644 index 0000000000..f87f2dcd91 --- /dev/null +++ b/web/app/components/base/markdown-blocks/form.tsx @@ -0,0 +1,137 @@ +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 ( + + ) +} +MarkdownForm.displayName = 'MarkdownForm' +export default MarkdownForm diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx index dde4bcf786..58e54123dd 100644 --- a/web/app/components/base/markdown.tsx +++ b/web/app/components/base/markdown.tsx @@ -20,7 +20,8 @@ import { useChatContext } from '@/app/components/base/chat/chat/context' import VideoGallery from '@/app/components/base/video-gallery' import AudioGallery from '@/app/components/base/audio-gallery' import SVGRenderer from '@/app/components/base/svg-gallery' -import Button from '@/app/components/base/button' +import MarkdownButton from '@/app/components/base/markdown-blocks/button' +import MarkdownForm from '@/app/components/base/markdown-blocks/form' // Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD const capitalizationLanguageNameMap: Record