import { messages } from '../i18n'; import { useEffect, useRef, useState } from 'react'; import { Search, X } from 'lucide-react'; export interface Command { label: string; shortcut?: string; run: () => void; disabled?: boolean; } export function CommandMenu({ open, onClose, commands, }: { open: boolean; onClose: () => void; commands: Command[]; }) { const dialog = useRef(null); const search = useRef(null); const [query, setQuery] = useState(''); useEffect(() => { if (open) { setQuery(''); dialog.current?.showModal(); search.current?.focus(); } else dialog.current?.close(); }, [open]); const matching = commands.filter((command) => command.label.toLocaleLowerCase('en').includes(query.trim().toLocaleLowerCase('en')), ); return ( { if (event.target === event.currentTarget) onClose(); }} >

{messages.commandsAndShortcuts}

{matching.map((command) => ( ))} {matching.length === 0 &&

{messages.noMatchingCommands}

}

{messages.editorShortcuts}
{messages.workspaceShortcuts}

); }