import type { SelectorParam } from 'i18next' import type { ReactNode } from 'react' import type { ChatVariableTranslator, EditorToggleLabelKey, ObjectValueItem, } from './variable-modal.helpers' import { Button } from '@langgenius/dify-ui/button' import { cn } from '@langgenius/dify-ui/cn' import { RiDraftLine, RiInputField } from '@remixicon/react' import Input from '@/app/components/base/input' import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { ChatVarType } from '../type' import ArrayBoolList from './array-bool-list' import ArrayValueList from './array-value-list' import BoolValue from './bool-value' import ObjectValueList from './object-value-list' import VariableTypeSelector from './variable-type-select' const editorToggleLabelSelectors: Record> = { 'chatVariable.modal.editInForm': ($) => $['chatVariable.modal.editInForm'], 'chatVariable.modal.editInJSON': ($) => $['chatVariable.modal.editInJSON'], 'chatVariable.modal.oneByOne': ($) => $['chatVariable.modal.oneByOne'], } type SectionTitleProps = { children: ReactNode } const SectionTitle = ({ children }: SectionTitleProps) => (
{children}
) type NameSectionProps = { name: string onBlur: (value: string) => void onChange: (e: React.ChangeEvent) => void placeholder: string title: string } export const NameSection = ({ name, onBlur, onChange, placeholder, title }: NameSectionProps) => (
{title}
onBlur(e.target.value)} type="text" />
) type TypeSectionProps = { list: ChatVarType[] onSelect: (value: ChatVarType) => void title: string type: ChatVarType } export const TypeSection = ({ list, onSelect, title, type }: TypeSectionProps) => (
{title}
) type ValueSectionProps = { editorContent?: string editorMinHeight: string editInJSON: boolean objectValue: ObjectValueItem[] onArrayBoolChange: (value: boolean[]) => void onArrayChange: (value: Array) => void onEditorChange: (nextEditInJson: boolean) => void onEditorValueChange: (content: string) => void onObjectChange: (value: ObjectValueItem[]) => void onValueChange: (value: boolean) => void placeholder: ReactNode t: ChatVariableTranslator toggleLabelKey?: EditorToggleLabelKey type: ChatVarType value: unknown } export const ValueSection = ({ editorContent, editorMinHeight, editInJSON, objectValue, onArrayBoolChange, onArrayChange, onEditorChange, onEditorValueChange, onObjectChange, onValueChange, placeholder, t, toggleLabelKey, type, value, }: ValueSectionProps) => (
{t(($) => $['chatVariable.modal.value'], { ns: 'workflow' })}
{toggleLabelKey && ( )}
{type === ChatVarType.String && (