import { Hotkey } from "./hotkey.js"; import { Store } from "@tanstack/store"; //#region src/hotkey-recorder.d.ts /** * State interface for the HotkeyRecorder. */ interface HotkeyRecorderState { /** Whether recording is currently active */ isRecording: boolean; /** The currently recorded hotkey (for live preview) */ recordedHotkey: Hotkey | null; } /** * Options for configuring a HotkeyRecorder instance. */ interface HotkeyRecorderOptions { /** Callback when a hotkey is successfully recorded */ onRecord: (hotkey: Hotkey) => void; /** Optional callback when recording is cancelled (Escape pressed) */ onCancel?: () => void; /** Optional callback when shortcut is cleared (Backspace/Delete pressed) */ onClear?: () => void; /** * Whether to ignore keyboard events from input-like elements (text inputs, * textarea, select, contenteditable). When true, typing in inputs passes * through normally instead of being captured as a hotkey recording. * Escape always works regardless of this setting. * @default true */ ignoreInputs?: boolean; } /** * Framework-agnostic class for recording keyboard shortcuts. * * This class handles all the complexity of capturing keyboard events, * converting them to hotkey strings, and handling edge cases like * Escape to cancel or Backspace/Delete to clear. * * State Management: * - Uses TanStack Store for reactive state management * - State can be accessed via `recorder.store.state` when using the class directly * - When using framework adapters (React), use `useSelector` hooks for reactive state * * @example * ```ts * const recorder = new HotkeyRecorder({ * onRecord: (hotkey) => { * console.log('Recorded:', hotkey) * }, * onCancel: () => { * console.log('Recording cancelled') * }, * }) * * // Start recording * recorder.start() * * // Access state directly * console.log(recorder.store.state.isRecording) // true * * // Subscribe to changes with TanStack Store * const unsubscribe = recorder.store.subscribe(() => { * console.log('Recording:', recorder.store.state.isRecording) * }) * * // Cleanup * recorder.destroy() * unsubscribe() * ``` */ declare class HotkeyRecorder { #private; /** * The TanStack Store instance containing the recorder state. * Use this to subscribe to state changes or access current state. */ readonly store: Store; constructor(options: HotkeyRecorderOptions); /** * Updates the recorder options, including callbacks. * This allows framework adapters to sync callback changes without recreating the recorder. */ setOptions(options: Partial): void; /** * Start recording a new hotkey. * * Sets up a keydown event listener that captures keyboard events * and converts them to hotkey strings. Recording continues until * a valid hotkey is recorded, Escape is pressed, or stop/cancel is called. */ start(): void; /** * Stop recording (same as cancel, but doesn't call onCancel). * * Removes the event listener and resets the recording state. */ stop(): void; /** * Cancel recording without saving. * * Removes the event listener, resets the recording state, and calls * the onCancel callback if provided. */ cancel(): void; /** * Clean up event listeners and reset state. * * Call this when you're done with the recorder to ensure * all event listeners are properly removed. */ destroy(): void; } //#endregion export { HotkeyRecorder, HotkeyRecorderOptions, HotkeyRecorderState }; //# sourceMappingURL=hotkey-recorder.d.ts.map