import { useEffect, useRef } from 'react'; interface InlineInputProps { depth: number; placeholder: string; initialValue?: string; onSubmit: (value: string) => void; onCancel: () => void; } const NODE_PADDING_LEFT = 8; export function InlineInput({ depth, placeholder, initialValue = '', onSubmit, onCancel }: InlineInputProps) { const inputRef = useRef(null); useEffect(() => { const timer = setTimeout(() => { if (inputRef.current) { inputRef.current.focus(); if (initialValue) { inputRef.current.value = initialValue; inputRef.current.select(); } } }, 50); return () => clearTimeout(timer); }, [initialValue]); const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { const value = inputRef.current?.value.trim(); if (value) { onSubmit(value); } } else if (e.key === 'Escape') { onCancel(); } }; return (
{ setTimeout(() => { if (document.activeElement !== inputRef.current) { onCancel(); } }, 100); }} />
); }