import React from 'react' import { Handle, Position } from 'reactflow' import Editor, { loader } from '@monaco-editor/react' import FlowContext from '../lib/flowContext' // Ensure Monaco can load its web workers under Vite by pointing to a CDN // This avoids the editor hanging while trying to locate worker scripts locally. loader.config({ paths: { vs: 'https://unpkg.com/monaco-editor@latest/min/vs' } }) type Props = { id: string data: any } export default function ConfigNode({ id, data }: Props) { const [value, setValue] = React.useState(data?.yaml ?? "# Enter YAML here\n") const ctx = React.useContext(FlowContext) const setNodes = ctx?.setNodes const storedYaml = ctx?.nodes?.find((n: any) => n.id === id)?.data?.yaml ?? '' React.useEffect(() => { // keep node data in sync on mount if (setNodes) { setNodes((nds: any[]) => nds.map((n) => (n.id === id ? { ...n, data: { ...n.data, yaml: value } } : n))) } // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const onChange = React.useCallback( (val?: string) => { const v = val ?? '' setValue(v) // debug log to help trace updates // eslint-disable-next-line no-console console.debug('ConfigNode:onChange', id, v.substring(0, 60)) if (setNodes) { setNodes((nds: any[]) => nds.map((n) => (n.id === id ? { ...n, data: { ...n.data, yaml: v } } : n))) } }, [id, setNodes] ) return (
Configuration
YAML
Stored YAML: {storedYaml ? `${storedYaml.length} chars` : 'none'}
) }