UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

76 lines (75 loc) 3.12 kB
import { KeyboardDriver } from './KeyboardDriver.js'; import type { KeyboardDriverGroup, KeyboardDriverGroupOptions } from './KeyboardDriver.js'; import type { CaptureList } from '../core/CaptureList.js'; /** * A {@link KeyboardDriverGroup} bound to a DOM element, with extra properties * used for cleaning up event listeners. * * @category Driver */ export interface DOMKeyboardDriverGroup extends KeyboardDriverGroup { /** The DOM element where the event listeners are added */ domElem: HTMLElement; /** "focus" event listener. For cleanup only */ focusListen: (event: FocusEvent) => void; /** "blue" event listener. For cleanup only */ blurListen: (event: FocusEvent) => void; /** "keydown" event listener. For cleanup only */ keydownListen: ((event: KeyboardEvent) => void) | null; /** "keyup" event listener. For cleanup only */ keyupListen: ((event: KeyboardEvent) => void) | null; /** The original tabIndex of the DOM element. For cleanup only */ origTabIndex: number; /** * If true, then the DOM element's tabIndex will be set to 0 if negative, so * that it can be selected via tab focus. Defaults to true. */ selectable: boolean; } /** * Options used for creating a new {@link DOMKeyboardDriverGroup}. * * @category Driver */ export interface DOMKeyboardDriverGroupOptions extends KeyboardDriverGroupOptions { /** See {@link DOMKeyboardDriverGroup#domElem}. */ domElem: HTMLElement; /** * If true (the default), event listeners will be added to listen for keys. * If false, then the group will not listen for key presses, but will still * keep the focsu as-is. */ listenToKeys?: boolean; /** See {@link DOMKeyboardDriverGroup#selectable}. */ selectable?: true; } /** * A {@link KeyboardDriver} which listens for key events from HTML DOM elements. * * Note that if a DOM element is unfocused in the DOM to an unbound DOM element, * the root focus is cleared. If this creates issues, other DOM elements can be * bound without listening for key events. * * @category Driver */ export declare class DOMKeyboardDriver extends KeyboardDriver<DOMKeyboardDriverGroup, DOMKeyboardDriverGroupOptions> { private tabKeyHelper; constructor(); /** * Calls preventDefault and stopImmediatePropagation on a keyboard event if * needed. * * @param captureList - List of events that were **maybe** captured by a Root * @param event - The keyboard event that can be preventDefault'ed/stopImmediatePropagation'ed */ maybePreventDefault(captureList: CaptureList, event: KeyboardEvent): void; /** * Check if the {@link KeyboardDriver#focus | root focus} should be cleared * given that the HTML DOM focus has been lost to another HTML DOM element * * @param newTarget - The HTML DOM element to which the focus has been lost to */ shouldClearFocus(newTarget: HTMLElement | null): boolean; createGroup(options: DOMKeyboardDriverGroupOptions): DOMKeyboardDriverGroup; deleteGroup(group: DOMKeyboardDriverGroup): void; }