@ngneat/hotkeys
Version:
A declarative library for handling hotkeys in Angular applications
52 lines (51 loc) • 1.78 kB
TypeScript
import { EventManager } from '@angular/platform-browser';
import { Observable } from 'rxjs';
import * as i0 from "@angular/core";
export type AllowInElement = 'INPUT' | 'TEXTAREA' | 'SELECT' | 'CONTENTEDITABLE';
export type Options = {
group: string;
element: HTMLElement;
trigger: 'keydown' | 'keyup';
allowIn: AllowInElement[];
description: string;
showInHelpMenu: boolean;
preventDefault: boolean;
global?: boolean;
};
export interface HotkeyGroup {
group: string;
hotkeys: {
keys: string;
description: string;
}[];
}
export type Hotkey = Partial<Options> & {
keys: string;
};
export type HotkeyCallback = (event: KeyboardEvent | Hotkey, keys: string, target: HTMLElement) => void;
export declare class HotkeysService {
private eventManager;
private document;
private readonly hotkeys;
private readonly dispose;
private readonly defaults;
private callbacks;
private sequenceMaps;
private sequenceDebounce;
private _isActive;
isActive: import("@angular/core").Signal<boolean>;
constructor(eventManager: EventManager, document: Document);
getHotkeys(): Hotkey[];
getShortcuts(): HotkeyGroup[];
addSequenceShortcut(options: Hotkey): Observable<Hotkey>;
addShortcut(options: Hotkey): Observable<KeyboardEvent>;
removeShortcuts(hotkeys: string | string[]): void;
setSequenceDebounce(debounce: number): void;
onShortcut(callback: HotkeyCallback): () => void;
registerHelpModal(openHelpModalFn: () => void, helpShortcut?: string): void;
private targetIsExcluded;
pause(): void;
resume(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<HotkeysService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<HotkeysService>;
}