import PhysicalKeyboard from './controllers/PhysicalKeyboard'; import CursorWorker from './common/CursorWorker'; import SuggestionBox from './components/SuggestionBox'; import { KeyboardOptions, KeyboardInput, KeyboardButtonElements, KeyboardHandlerEvent, KeyboardElement, KeyboardType, KeyboardVisibility, LayoutDirection } from './types'; /** * Root class for @mamba/keyboard * - Parses the options * - Renders the rows and buttons * - Handles button functionality */ declare class Keyboard { input: KeyboardInput; private initialOptions; options: KeyboardOptions; cursorWorker: CursorWorker; keyboardDOM: KeyboardElement; keyboardDOMClass: string; buttonElements: KeyboardButtonElements; physicalKeyboard?: PhysicalKeyboard; suggestionsBox?: SuggestionBox; activeButtonClass: string; hiddenKeyboardClass: string; disabledKeyboardClass: string; initialized: boolean; exist: boolean; keyboardRowsDOM: KeyboardElement; keyboardType: KeyboardType; keyboardVisible: KeyboardVisibility; defaultLayoutDirection: LayoutDirection; defaultLayoutAndName: string; activeTime: number; driverBinded: boolean; updateId?: number; renderDebounceId?: number; defaultAllowKeySyntheticEvent: string[]; renderDebounceTime: number; internalOnFunctionKeyPress?: (button: string, instance: Keyboard, e?: KeyboardHandlerEvent) => void; /** * Creates an instance of MambaKeyboard * @param params If first parameter is a HTMLDivElement, it is considered as element to mount the keybaord, otherwise it will create a generic one on app-root, and the second parameter is then considered the options object. If first parameter is an object, it is considered as {@link KeyboardOptions} object. * @remarks */ constructor(elementOrOptions?: HTMLDivElement | KeyboardOptions, keyboardOptions?: KeyboardOptions); /** * Parse keyboard params * * @param elementOrOptions Pass keyboard root container or leaving argument to be the keyboard options. If no element passed, keyboard will try to add in top level(body or app root). * @param keyboardOptions Keyboard options if you use first argument as DOM element * * @throws DOM_CLASS_ERROR - DOM element have no class * @throws SIMULATOR_POS_SCREEN_NOT_FOUND - Simulator DOM container not found * @throws APP_ROOT_ERROR - Svelte `app-rot` not found */ private handleParams; /** * Parse some options that need be checked first * * @param keyboardOptions * @returns Some options that need be parsed */ private parseOptionsUpdated; /** * Define keyboard type and its properties * * @param keyboardOptions * @returns Parsed properties or defaults ones */ private parseKeyboardTypeOptions; /** * ! Methods */ /** * Sets new option or modify existing ones after initialization. * @param options The options to set */ setOptions(options?: KeyboardOptions): void; /** * Update sound enabled state from user config */ updateSoundEnabledState(options?: KeyboardOptions): void; /** * Handles dataset of HTML input and parse its options */ handleDOMInputDataset(): void; /** * Controls keyboard visibility, to handle effects */ set visibility(value: KeyboardVisibility); get visibility(): KeyboardVisibility; /** * Retrieve instance options * @returns Parsed options */ getOptions: () => KeyboardOptions; /** * Clear the keyboard’s input. */ clearInput(): void; /** * Gets the keyboard’s input (You can also get it from the onChange prop). */ getInput(): string; /** * Sets the keyboard’s input. * @param input the input value */ setInput(input: string): void; /** * Replaces the input object (`keyboard.input`) * @param keyboardInput The input object */ replaceInput(keyboardInput: KeyboardInput): void; /** * Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned. * @param button The button layout name to select */ getButtonElement(button: string): KeyboardElement | KeyboardElement[] | undefined; /** * This handles the "inputPattern" option by checking if the provided inputPattern passes. */ private inputPatternIsValid; /** * Returns if the current input is valid within current pattern option. */ currentInputPatternIsValid(): boolean; /** * Change the keyboard type. * @param type The keyboard type */ setKeyboardType(type: KeyboardType): void; /** * Set keyboard as default type. */ setKeyboardAsDefaultType(): void; /** * Set keyboard as math type. */ setKeyboardAsMathType(): void; /** * Set keyboard as numeric type. */ setKeyboardAsNumericType(): void; /** * Set keyboard as phone type. */ setKeyboardAsPhoneType(): void; /** * Set keyboard as custom type. */ setKeyboardAsCustomType(options?: KeyboardOptions): void; /** * Shows keyboard and mount it if already not. */ show(): void; /** * Hides keyboard. * This method do less things than {@link visibility}. */ hide(): void; /** * Resets keyboard properties. */ resetOptions(): void; /** * Removes all keyboard rows and set visibility to hidden. */ unmount(): void; /** * Resets keyboard properties and keyboard elements. */ reset(): void; /** * Destroy keyboard, remove listeners and DOM elements. * This method should called by svelte component on:destroy */ destroy(): void; /** * Bind public methods to the window.$Keyboard wrapper. * So you can call Keyboard methods grouped with Kernel methods. * e.g `window.$Keyboard.show();` * * @param driver driver wrapper */ static bindToDriver(driver: any, instance: Keyboard): void; /** * ! Internal methods */ /** * Detecting changes to non-function options. * This allows us to ascertain whether a button re-render is needed. */ private changedOptions; /** * Handles clicks made to keyboard buttons. * @param button The button's layout name. * @param e Click event * @param suggestionCandidate Key candidate to suggestion replacement. */ private handleButtonClicked; /** * Handles key dispatcher */ private shouldDispatchSyntheticKeyEvent; /** * Handles key active class */ private handleActiveButton; /** * Handles keyboard visibility class * @param visibility */ private handleKeyboardVisibility; /** * Handles button mousedown */ private handleButtonMouseDown; /** * Remove all keyboard rows to reset keyboard elements. * Used internally between re-renders. */ private clearRows; /** * Executes the callback function once virtual keyboard is rendered for the first time (on initialization). */ private onInit; /** * Executes the callback function before a virtual keyboard render. */ private beforeFirstRender; /** * Executes the callback function before a virtual keyboard render. */ private beforeRender; /** * Executes the callback function every time virtual keyboard is rendered (e.g: when you change layouts). */ private onRender; /** * getKeyboardClassString */ private getKeyboardClassString; /** * Parse render condition * @returns If keyboard can work or not */ get isRenderAllowed(): boolean; /** * Update keyboard view */ shouldUpdateKeyboardView(): void; /** * Debounce keyboard rendering */ render(): void; /** * True renders or update the keyboard buttons * Can be called direct if `autoRender` is off * @throws LAYOUT_NOT_FOUND_ERROR - layout not found * @throws LAYOUT_NAME_NOT_FOUND_ERROR - layout name not found in layout object */ trueRender(): void; } export type { Keyboard }; export default Keyboard;