import React from "react"; import Editor from "@monaco-editor/react"; import { Button } from "@/components/ui"; import { Loader2 } from "lucide-react"; interface YamlEditorProps { content?: string; onChange?: (yaml: string) => void; onApply?: (yaml: string) => void; onCancel?: () => void; readOnly?: boolean; height?: string; showControls?: boolean; } export function YamlEditor({ content = "", onChange, onApply, onCancel, readOnly = false, height = "400px", showControls = true, }: YamlEditorProps) { const [value, setValue] = React.useState(content); const [isLoading, setIsLoading] = React.useState(true); React.useEffect(() => { setValue(content); }, [content]); const handleChange = (v: string | undefined) => { const next = v ?? ""; setValue(next); // When there are no controls, propagate every change immediately to the parent. if (!showControls) { onChange?.(next); } }; const handleApply = () => { onChange?.(value); onApply?.(value); }; return (
{isLoading && (
)} setIsLoading(false)} options={{ minimap: { enabled: false }, scrollBeyondLastLine: false, fontSize: 13, wordWrap: "on", readOnly, }} />
{showControls && (
)}
); }