diff --git a/web/app/(humanInputLayout)/form/[token]/content-item.tsx b/web/app/(humanInputLayout)/form/[token]/content-item.tsx new file mode 100644 index 0000000000..2df647473f --- /dev/null +++ b/web/app/(humanInputLayout)/form/[token]/content-item.tsx @@ -0,0 +1,104 @@ +import React from 'react' +import { Markdown } from '@/app/components/base/markdown' +import Select from '@/app/components/base/select' +import Textarea from '@/app/components/base/textarea' +import Input from '@/app/components/base/input' +import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' +import { getProcessedFiles } from '@/app/components/base/file-uploader/utils' +import { DEFAULT_VALUE_MAX_LEN } from '@/config' +import type { GeneratedFormInputItem } from '@/app/components/workflow/nodes/human-input/types' + +type Props = { + content: string + formInputFields: GeneratedFormInputItem[] + inputs: Record + onInputChange: (name: string, value: any) => void +} + +const ContentItem = ({ content, formInputFields, inputs, onInputChange }: Props) => { + const isInputField = (field: string) => { + const outputVarRegex = /{{#\$output\.[^#]+#}}/ + return outputVarRegex.test(field) + } + + const extractFieldName = (str: string) => { + const outputVarRegex = /{{#\$output\.([^#]+)#}}/ + const match = str.match(outputVarRegex) + return match ? match[1] : '' + } + + if (!isInputField(content)) { + return ( + + ) + } + + const fieldName = extractFieldName(content) + const formInputField = formInputFields.find(field => field.output_variable_name === fieldName) + + if (!formInputField) return null + + return ( +
+ {formInputField.type === 'select' && ( + { onInputChange(fieldName, e.target.value) }} + maxLength={formInputField.max_length || DEFAULT_VALUE_MAX_LEN} + /> + )} + {formInputField.type === 'paragraph' && ( +