From ab8146035db0cafc189f4f9b952848a1b9e251fa Mon Sep 17 00:00:00 2001 From: JzoNg Date: Sun, 8 Jun 2025 18:37:18 +0800 Subject: [PATCH] mixed-variable-input --- .../components/base/prompt-editor/index.tsx | 25 ++++++++-- .../plugins/custom-text/node.tsx | 1 - .../prompt-editor/plugins/placeholder.tsx | 2 +- .../mixed-variable-text-input/index.tsx | 39 +++++++++++++++ .../mixed-variable-text-input/placeholder.tsx | 49 +++++++++++++++++++ 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/index.tsx create mode 100644 web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/placeholder.tsx diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 94a65e4b62..a87a51cd50 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -64,8 +64,9 @@ import cn from '@/utils/classnames' export type PromptEditorProps = { instanceId?: string compact?: boolean + wrapperClassName?: string className?: string - placeholder?: string + placeholder?: string | JSX.Element placeholderClassName?: string style?: React.CSSProperties value?: string @@ -85,6 +86,7 @@ export type PromptEditorProps = { const PromptEditor: FC = ({ instanceId, compact, + wrapperClassName, className, placeholder, placeholderClassName, @@ -147,10 +149,25 @@ const PromptEditor: FC = ({ return ( -
+
} - placeholder={} + contentEditable={ + + } + placeholder={ + + } ErrorBoundary={LexicalErrorBoundary} /> { const { t } = useTranslation() diff --git a/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/index.tsx b/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/index.tsx new file mode 100644 index 0000000000..4bb562ba3a --- /dev/null +++ b/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/index.tsx @@ -0,0 +1,39 @@ +import { + memo, +} from 'react' +import PromptEditor from '@/app/components/base/prompt-editor' +import cn from '@/utils/classnames' +import Placeholder from './placeholder' + +type MixedVariableTextInputProps = { + editable?: boolean + value?: string + onChange?: (text: string) => void +} +const MixedVariableTextInput = ({ + editable = true, + value = '', + onChange, +}: MixedVariableTextInputProps) => { + return ( + } + onChange={onChange} + /> + ) +} + +export default memo(MixedVariableTextInput) diff --git a/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/placeholder.tsx b/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/placeholder.tsx new file mode 100644 index 0000000000..e84ffbeb28 --- /dev/null +++ b/web/app/components/workflow/nodes/tool/components/mixed-variable-text-input/placeholder.tsx @@ -0,0 +1,49 @@ +import { useCallback } from 'react' +import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' +import { FOCUS_COMMAND } from 'lexical' +import { $insertNodes } from 'lexical' +import { CustomTextNode } from '@/app/components/base/prompt-editor/plugins/custom-text/node' +import Badge from '@/app/components/base/badge' + +const Placeholder = () => { + const [editor] = useLexicalComposerContext() + + const handleInsert = useCallback((text: string) => { + editor.update(() => { + const textNode = new CustomTextNode(text) + $insertNodes([textNode]) + }) + editor.dispatchCommand(FOCUS_COMMAND, undefined as any) + }, [editor]) + + return ( +
{ + e.stopPropagation() + handleInsert('') + }} + > +
+ Type or press +
/
+
{ + e.stopPropagation() + handleInsert('/') + })} + > + insert variable +
+
+ +
+ ) +} + +export default Placeholder