/** * useInputGuard Hook * * Validates keyboard input against the current UI state. * Provides centralized input validation with debug logging support. */ import { type Key, type StateContext, type UIState } from '../state/index.js'; /** * Options for the useInputGuard hook */ export interface UseInputGuardOptions { /** Current UI state context */ context: StateContext; /** Callback when input is rejected */ onInvalidInput?: (keyId: string, state: UIState, reason: string) => void; /** Callback when input is throttled */ onThrottled?: (keyId: string, action: string) => void; } /** * Return type for useInputGuard hook */ export interface UseInputGuardResult { /** * Validate an input against the current state. * Returns true if the input should be processed. */ validateInput: (input: string, key: Key) => boolean; /** * Check if a specific key ID is valid for the current state. * Useful for checking before dispatching an action. */ isKeyValid: (keyId: string) => boolean; /** * Get the normalized key identifier for an input. */ getKeyId: (input: string, key: Key) => string; /** * Current UI state (convenience accessor) */ currentState: UIState; } /** * Hook that provides input validation against the current UI state * * @param options - Configuration options * @returns Validation functions and state info * * @example * const { validateInput, currentState } = useInputGuard({ context }); * * useInput((input, key) => { * // Skip invalid inputs * if (!validateInput(input, key)) return; * * // Process valid input * if (input === 'r') { * refresh(); * } * }); */ export declare function useInputGuard(options: UseInputGuardOptions): UseInputGuardResult; /** * Simple validation function (non-hook) for use outside React components * * @param input - Input character * @param key - Key object from useInput * @param state - Current UI state * @returns Whether the input is valid */ export declare function validateInputForState(input: string, key: Key, state: UIState): boolean; /** * Check if input should trigger special handling in a state * * Some states have special behavior: * - 'help' and 'config': any key closes them * - 'command-palette': any printable char is valid for typing * - 'login-dialog': text input for form fields */ export declare function hasSpecialInputHandling(state: UIState): boolean; /** * Get the appropriate action for an escape key press * * @param state - Current UI state * @param canCancel - Whether the current operation can be cancelled * @returns The action to take, or null if escape should be ignored */ export declare function getEscapeAction(state: UIState, canCancel?: boolean): 'close' | 'cancel' | 'ignore' | null; //# sourceMappingURL=useInputGuard.d.ts.map