'use client'; import { useState, useEffect } from 'react'; import { X, Search, Keyboard } from 'lucide-react'; import { cn } from '@/lib/utils'; interface Shortcut { category: string; action: string; keys: string[]; description?: string; } const SHORTCUTS: Shortcut[] = [ // File Operations { category: 'File', action: 'New', keys: ['Ctrl', 'N'] }, { category: 'File', action: 'Open', keys: ['Ctrl', 'O'] }, { category: 'File', action: 'Save', keys: ['Ctrl', 'S'] }, { category: 'File', action: 'Save As', keys: ['Ctrl', 'Shift', 'S'] }, { category: 'File', action: 'Export', keys: ['Ctrl', 'E'] }, // Edit Operations { category: 'Edit', action: 'Undo', keys: ['Ctrl', 'Z'] }, { category: 'Edit', action: 'Redo', keys: ['Ctrl', 'Shift', 'Z'] }, { category: 'Edit', action: 'Cut', keys: ['Ctrl', 'X'] }, { category: 'Edit', action: 'Copy', keys: ['Ctrl', 'C'] }, { category: 'Edit', action: 'Paste', keys: ['Ctrl', 'V'] }, { category: 'Edit', action: 'Select All', keys: ['Ctrl', 'A'] }, { category: 'Edit', action: 'Deselect', keys: ['Ctrl', 'D'] }, // View Operations { category: 'View', action: 'Zoom In', keys: ['Ctrl', '+'] }, { category: 'View', action: 'Zoom Out', keys: ['Ctrl', '-'] }, { category: 'View', action: 'Zoom to 100%', keys: ['Ctrl', '0'] }, { category: 'View', action: 'Fit to Screen', keys: ['Ctrl', '1'] }, { category: 'View', action: 'Toggle Grid', keys: ['Ctrl', 'G'] }, // Tools (Single Key) { category: 'Tools', action: 'Move Tool', keys: ['V'] }, { category: 'Tools', action: 'Rectangle Select', keys: ['M'] }, { category: 'Tools', action: 'Lasso Select', keys: ['L'] }, { category: 'Tools', action: 'Wand Select', keys: ['W'] }, { category: 'Tools', action: 'Pencil Tool', keys: ['P'] }, { category: 'Tools', action: 'Brush Tool', keys: ['B'] }, { category: 'Tools', action: 'Eraser Tool', keys: ['E'] }, { category: 'Tools', action: 'Fill Bucket', keys: ['G'] }, { category: 'Tools', action: 'Eyedropper', keys: ['I'] }, { category: 'Tools', action: 'Text Tool', keys: ['T'] }, { category: 'Tools', action: 'Shape Tool', keys: ['U'] }, { category: 'Tools', action: 'Hand Tool (Pan)', keys: ['H'] }, { category: 'Tools', action: 'Temporary Hand', keys: ['Space'], description: 'Hold to pan' }, // Layers { category: 'Layers', action: 'New Layer', keys: ['Ctrl', 'Shift', 'N'] }, { category: 'Layers', action: 'Duplicate Layer', keys: ['Ctrl', 'J'] }, { category: 'Layers', action: 'Merge Down', keys: ['Ctrl', 'E'] }, { category: 'Layers', action: 'Next Layer', keys: ['['] }, { category: 'Layers', action: 'Previous Layer', keys: [']'] }, // Transform { category: 'Transform', action: 'Free Transform', keys: ['Ctrl', 'T'] }, { category: 'Transform', action: 'Rotate 90° CW', keys: ['Ctrl', 'R'] }, { category: 'Transform', action: 'Flip Horizontal', keys: ['Ctrl', 'Shift', 'H'] }, { category: 'Transform', action: 'Flip Vertical', keys: ['Ctrl', 'Shift', 'V'] }, // Adjustments { category: 'Adjustments', action: 'Brightness/Contrast', keys: ['Ctrl', 'M'] }, { category: 'Adjustments', action: 'Hue/Saturation', keys: ['Ctrl', 'U'] }, { category: 'Adjustments', action: 'Invert Colors', keys: ['Ctrl', 'I'] }, // Help { category: 'Help', action: 'Keyboard Shortcuts', keys: ['?'] }, { category: 'Help', action: 'Keyboard Shortcuts (Alt)', keys: ['F1'] }, ]; interface ShortcutsHelpPanelProps { isOpen: boolean; onClose: () => void; } export function ShortcutsHelpPanel({ isOpen, onClose }: ShortcutsHelpPanelProps) { const [searchQuery, setSearchQuery] = useState(''); // Handle Escape key to close useEffect(() => { if (!isOpen) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [isOpen, onClose]); if (!isOpen) return null; // Filter shortcuts based on search const filteredShortcuts = SHORTCUTS.filter((shortcut) => { const query = searchQuery.toLowerCase(); return ( shortcut.action.toLowerCase().includes(query) || shortcut.category.toLowerCase().includes(query) || shortcut.keys.some((key) => key.toLowerCase().includes(query)) || shortcut.description?.toLowerCase().includes(query) ); }); // Group by category const categories = Array.from(new Set(filteredShortcuts.map((s) => s.category))); return ( <> {/* Backdrop */}
{/* Panel */}
{/* Header */}

Keyboard Shortcuts

{/* Search */}
setSearchQuery(e.target.value)} className="w-full pl-10 pr-4 py-2 bg-background border border-border rounded-md text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary" autoFocus />
{/* Shortcuts List */}
{categories.length === 0 ? (
No shortcuts found matching "{searchQuery}"
) : (
{categories.map((category) => { const categoryShortcuts = filteredShortcuts.filter( (s) => s.category === category ); return (

{category}

{categoryShortcuts.map((shortcut, index) => (
{shortcut.action}
{shortcut.description && (
{shortcut.description}
)}
{shortcut.keys.map((key, keyIndex) => (
{key} {keyIndex < shortcut.keys.length - 1 && ( + )}
))}
))}
); })}
)}
{/* Footer */}

Press Esc to close or ? / F1 to open

); }