({
value,
onChange,
placeholder,
disabled = false,
rows,
suggestionItems,
autoFocus = false,
onEditorReady
}: VariableInputProps)
| 157 | * This is the agentflow equivalent of the UI package's RichInput component. |
| 158 | */ |
| 159 | export function VariableInput({ |
| 160 | value, |
| 161 | onChange, |
| 162 | placeholder, |
| 163 | disabled = false, |
| 164 | rows, |
| 165 | suggestionItems, |
| 166 | autoFocus = false, |
| 167 | onEditorReady |
| 168 | }: VariableInputProps) { |
| 169 | const onChangeRef = useRef(onChange) |
| 170 | useEffect(() => { |
| 171 | onChangeRef.current = onChange |
| 172 | }, [onChange]) |
| 173 | |
| 174 | // Track the last value we emitted (or loaded) to avoid re-setting content |
| 175 | // when the parent echoes our own onChange value back as the new prop. |
| 176 | const lastEmittedRef = useRef<string>(value || '') |
| 177 | |
| 178 | // Capture initial value for the mount effect below so we can depend only on |
| 179 | // `editor` without suppressing the exhaustive-deps rule. |
| 180 | const initialValueRef = useRef(value) |
| 181 | |
| 182 | const useMarkdown = !!rows |
| 183 | |
| 184 | const suggestionConfig = useMemo( |
| 185 | () => (suggestionItems?.length ? createSuggestionConfig(suggestionItems) : undefined), |
| 186 | [suggestionItems] |
| 187 | ) |
| 188 | const suggestionConfigRef = useRef(suggestionConfig) |
| 189 | useEffect(() => { |
| 190 | suggestionConfigRef.current = suggestionConfig |
| 191 | }, [suggestionConfig]) |
| 192 | |
| 193 | const extensions = useMemo( |
| 194 | () => [ |
| 195 | Markdown, |
| 196 | StarterKit.configure({ |
| 197 | codeBlock: false, |
| 198 | ...(!useMarkdown && { link: false }) |
| 199 | }), |
| 200 | CodeBlockLowlight.configure({ lowlight, enableTabIndentation: true, tabSize: 2 }), |
| 201 | ...(placeholder ? [Placeholder.configure({ placeholder })] : []), |
| 202 | ...(suggestionConfig |
| 203 | ? [ |
| 204 | CustomMention.configure({ |
| 205 | HTMLAttributes: { class: 'mention' }, |
| 206 | renderHTML({ options, node }) { |
| 207 | return [ |
| 208 | 'span', |
| 209 | mergeAttributes(this.HTMLAttributes ?? {}, options.HTMLAttributes), |
| 210 | `${options.suggestion?.char ?? '{{'}${node.attrs.id ?? node.attrs.label}}}` |
| 211 | ] |
| 212 | }, |
| 213 | suggestion: suggestionConfig, |
| 214 | deleteTriggerWithBackspace: true |
| 215 | }) |
| 216 | ] |
nothing calls this directly
no test coverage detected