From bdf1e9ed3b999f2c709b11cc3f9bebeafb5d7f9b Mon Sep 17 00:00:00 2001 From: JzoNg Date: Tue, 12 Aug 2025 13:59:28 +0800 Subject: [PATCH] form content --- .../form/[token]/content-item.tsx | 104 ++++++++++++++++++ .../(humanInputLayout)/form/[token]/form.tsx | 65 +++++++++-- .../(humanInputLayout)/form/[token]/mock.ts | 28 ++++- .../workflow/nodes/human-input/types.ts | 17 +++ web/service/share.ts | 4 +- 5 files changed, 206 insertions(+), 12 deletions(-) create mode 100644 web/app/(humanInputLayout)/form/[token]/content-item.tsx 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' && ( +