types.ts RawHistoryFolder
1/**
2 * Keyboard Service Types
3 *
4 * Type definitions for the unified keyboard shortcut system.
5 * Provides type-safe interfaces for registering and handling keyboard shortcuts.
6 */
7
8export interface ShortcutConfig {
9 /** The keyboard shortcut key combination (e.g., 'cmdorctrl+l', 'escape', 'enter') */
10 key: string;
11
12 /** Function to execute when the shortcut is triggered */
13 handler: () => void;
14
15 /** Whether to prevent the default browser behavior (default: true) */
16 preventDefault?: boolean;
17
18 /** Whether to stop event propagation (default: true) */
19 stopPropagation?: boolean;
20
21 /** Only trigger when this component is focused (default: false) */
22 whenFocused?: boolean;
23
24 /** Optional description for debugging */
25 description?: string;
26}
27
28export interface KeyboardEventDetail {
29 /** The original keyboard shortcut string */
30 shortcut: string;
31
32 /** Timestamp when the event occurred */
33 timestamp: number;
34
35 /** Component that should handle this event (if specified) */
36 targetComponent?: string;
37}
38
39export interface ComponentShortcuts {
40 /** Unique component identifier */
41 componentId: string;
42
43 /** Array of shortcuts registered by this component */
44 shortcuts: ShortcutConfig[];
45
46 /** Whether this component is currently focused */
47 focused: boolean;
48
49 /** Optional cleanup function called when component is destroyed */
50 cleanup?: () => void;
51}
52
53export interface KeyboardServiceConfig {
54 /** Enable debug logging for keyboard events */
55 debug?: boolean;
56
57 /** Global shortcuts that work regardless of component focus */
58 globalShortcuts?: ShortcutConfig[];
59}
60
61/**
62 * Event types for keyboard service
63 */
64export type KeyboardEventType =
65 | 'shortcut-triggered'
66 | 'component-focused'
67 | 'component-blurred'
68 | 'shortcut-registered'
69 | 'shortcut-unregistered';
70
71export interface KeyboardEvent {
72 type: KeyboardEventType;
73 detail: KeyboardEventDetail | ComponentShortcuts | ShortcutConfig;
74}
75
76/**
77 * Keyboard modifiers mapping
78 */
79export const MODIFIER_KEYS = {
80 ctrl: 'ctrlKey',
81 cmd: 'metaKey',
82 cmdorctrl: navigator.platform.includes('Mac') ? 'metaKey' : 'ctrlKey',
83 alt: 'altKey',
84 shift: 'shiftKey'
85} as const;
86
87/**
88 * Common shortcut patterns used throughout the application
89 */
90export const COMMON_SHORTCUTS = {
91 OMNIBOX_OPEN: 'cmdorctrl+l',
92 FIND_OPEN: 'cmdorctrl+f',
93 ESCAPE: 'escape',
94 ENTER: 'enter',
95 ARROW_UP: 'arrowup',
96 ARROW_DOWN: 'arrowdown',
97 ARROW_LEFT: 'arrowleft',
98 ARROW_RIGHT: 'arrowright',
99 TAB: 'tab',
100 SHIFT_TAB: 'shift+tab'
101} as const;