MCPcopy
hub / github.com/FlowiseAI/Flowise / ExpandTextDialog

Function ExpandTextDialog

packages/agentflow/src/atoms/ExpandTextDialog.tsx:39–194  ·  view source on GitHub ↗
({
    open,
    value,
    title,
    placeholder,
    disabled = false,
    inputType = 'string',
    language,
    suggestionItems,
    onConfirm,
    onCancel
}: ExpandTextDialogProps)

Source from the content-addressed store, hash-verified

37 * WYSIWYG TipTap editor and a raw markdown text view.
38 */
39export function ExpandTextDialog({
40 open,
41 value,
42 title,
43 placeholder,
44 disabled = false,
45 inputType = 'string',
46 language,
47 suggestionItems,
48 onConfirm,
49 onCancel
50}: ExpandTextDialogProps) {
51 const [localValue, setLocalValue] = useState(value)
52 const [prevOpen, setPrevOpen] = useState(open)
53 const [mode, setMode] = useState<EditorMode>('edit')
54 const editorRef = useRef<Editor | null>(null)
55
56 // Sync localValue and reset mode synchronously when the dialog opens so the TipTap
57 // editor initialises with the correct content (useEffect would leave a one-render
58 // gap where localValue is stale, causing the editor to show empty/old text).
59 if (open && !prevOpen) {
60 setLocalValue(value)
61 setMode('edit')
62 setPrevOpen(true)
63 } else if (!open && prevOpen) {
64 setPrevOpen(false)
65 }
66
67 const handleConfirm = useCallback(() => {
68 onConfirm(localValue)
69 }, [localValue, onConfirm])
70
71 const handleModeChange = (_: React.MouseEvent<HTMLElement>, newMode: EditorMode | null) => {
72 if (!newMode || newMode === mode) return
73 // When switching to Source, flush the editor's current state to markdown so the
74 // textarea shows markdown rather than a raw HTML string (Gap 3 fix — mirrors PR #6021).
75 if (newMode === 'source' && editorRef.current) {
76 setLocalValue(unescapeXmlTags(getEditorMarkdown(editorRef.current)))
77 }
78 setMode(newMode)
79 }
80
81 const isRichText = inputType === 'string'
82
83 return (
84 <Dialog open={open} fullWidth maxWidth='md'>
85 <DialogContent>
86 {(title || isRichText) && (
87 <Box sx={{ display: 'flex', alignItems: 'center', mb: '10px' }}>
88 {title && (
89 <Typography variant='h4' sx={{ flex: 1 }}>
90 {title}
91 </Typography>
92 )}
93 {!title && <Box sx={{ flex: 1 }} />}
94 {isRichText && (
95 <ToggleButtonGroup
96 value={mode}

Callers

nothing calls this directly

Calls 1

onConfirmFunction · 0.50

Tested by

no test coverage detected