melt
Version:
The next generation of Melt UI. Built for Svelte 5.
92 lines (91 loc) • 3.23 kB
TypeScript
/**
* A constant object that maps commonly used keyboard keys to their corresponding string values.
* This object can be used in other parts of the application to handle keyboard input and prevent
* hard-coded strings throughout.
*/
export declare const kbd: {
readonly ALT: "Alt";
readonly ARROW_DOWN: "ArrowDown";
readonly ARROW_LEFT: "ArrowLeft";
readonly ARROW_RIGHT: "ArrowRight";
readonly ARROW_UP: "ArrowUp";
readonly BACKSPACE: "Backspace";
readonly CAPS_LOCK: "CapsLock";
readonly CONTROL: "Control";
readonly DELETE: "Delete";
readonly END: "End";
readonly ENTER: "Enter";
readonly ESCAPE: "Escape";
readonly F1: "F1";
readonly F10: "F10";
readonly F11: "F11";
readonly F12: "F12";
readonly F2: "F2";
readonly F3: "F3";
readonly F4: "F4";
readonly F5: "F5";
readonly F6: "F6";
readonly F7: "F7";
readonly F8: "F8";
readonly F9: "F9";
readonly HOME: "Home";
readonly META: "Meta";
readonly PAGE_DOWN: "PageDown";
readonly PAGE_UP: "PageUp";
readonly SHIFT: "Shift";
readonly SPACE: " ";
readonly TAB: "Tab";
readonly CTRL: "Control";
readonly ASTERISK: "*";
readonly A: "a";
readonly P: "p";
};
type Key = (typeof kbd)[keyof typeof kbd];
/** Key sets for navigation within lists, such as select, menu, and combobox. */
export declare const FIRST_KEYS: ("ArrowDown" | "Home" | "PageUp")[];
export declare const LAST_KEYS: ("ArrowUp" | "End" | "PageDown")[];
export declare const FIRST_LAST_KEYS: ("ArrowDown" | "ArrowUp" | "End" | "Home" | "PageDown" | "PageUp")[];
export declare const SELECTION_KEYS: ("Enter" | " ")[];
export declare const getNextKey: (dir?: "ltr" | "rtl", orientation?: "horizontal" | "vertical") => "ArrowDown" | "ArrowLeft" | "ArrowRight";
export declare const getPrevKey: (dir?: "ltr" | "rtl", orientation?: "horizontal" | "vertical") => "ArrowLeft" | "ArrowRight" | "ArrowUp";
export declare const getDirectionalKeys: (dir?: "ltr" | "rtl", orientation?: "horizontal" | "vertical") => {
nextKey: "ArrowDown" | "ArrowLeft" | "ArrowRight";
prevKey: "ArrowLeft" | "ArrowRight" | "ArrowUp";
};
type KeyMap = {
[key in Key]?: ((e: KeyboardEvent) => void) | {
handler: (e: KeyboardEvent) => void;
/**
* Whether to prevent default behaviour
* @default true
**/
preventDefault?: boolean;
/**
* Whether to stop propagation of the event
* @default false
**/
stopPropagation?: boolean;
/**
* Whether to stop immediate propagation of the event
* @default false
**/
stopImmediatePropagation?: boolean;
/**
* Whether to only activate if ctrl/cmd key is pressed
* @default false
**/
ctrl?: boolean;
/**
* Whether to only activate if shift key is pressed
* @default false
**/
shift?: boolean;
/**
* Whether to only activate if alt key is pressed
* @default false
**/
alt?: boolean;
};
};
export declare function createKeydownHandler(keyMap: KeyMap): (e: KeyboardEvent) => void;
export {};