initial commit
This commit is contained in:
41
src/types.ts
Normal file
41
src/types.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { KeybindEmitter } from "./keybindEmitter";
|
||||
|
||||
export type KeyCode = string;
|
||||
export enum ModifierKey {
|
||||
Shift = 'Shift',
|
||||
Control = 'Ctrl',
|
||||
Alt = 'Alt',
|
||||
Meta = 'Meta'
|
||||
}
|
||||
export type Modifiers = Array<ModifierKey>;
|
||||
|
||||
export interface KeyCommand{
|
||||
key: KeyCode;
|
||||
modifiers: Modifiers;
|
||||
}
|
||||
|
||||
export interface CommandMap {
|
||||
command: KeyCommand[];
|
||||
callback: () => void;
|
||||
}
|
||||
|
||||
export const KeybindEventTypes = {
|
||||
SequenceProgress: "sequenceProgress",
|
||||
CommandMatched: "commandMatched",
|
||||
SequenceTimeout: "sequenceTimeout",
|
||||
SequenceNoMatch: "sequenceNoMatch",
|
||||
} as const;
|
||||
|
||||
export type KeybindEventType = (typeof KeybindEventTypes)[keyof typeof KeybindEventTypes];
|
||||
|
||||
export type KeybindEvent =
|
||||
| { type: typeof KeybindEventTypes.SequenceProgress; pressedKeys: KeyCommand[] }
|
||||
| { type: typeof KeybindEventTypes.CommandMatched; callback: (() => void) | null }
|
||||
| { type: typeof KeybindEventTypes.SequenceTimeout; }
|
||||
| { type: typeof KeybindEventTypes.SequenceNoMatch; };
|
||||
|
||||
export type KeyEventHandler = (event: KeyboardEvent) => void;
|
||||
export interface KeyHandlerReturn {
|
||||
handler: KeyEventHandler;
|
||||
emitter: KeybindEmitter;
|
||||
}
|
||||
Reference in New Issue
Block a user