Fix types

This commit is contained in:
Francisco Hodge 2024-07-25 09:52:25 -04:00
parent bfaecfd2e1
commit 2bea9db4da
2 changed files with 15 additions and 14 deletions

View File

@ -9,13 +9,10 @@ import {
KeyboardButtonElements, KeyboardButtonElements,
KeyboardHandlerEvent, KeyboardHandlerEvent,
KeyboardElement, KeyboardElement,
SKWindow,
} from "../interfaces"; } from "../interfaces";
import CandidateBox from "./CandidateBox"; import CandidateBox from "./CandidateBox";
declare global {
interface Window { SimpleKeyboardInstances: any; }
}
/** /**
* Root class for simple-keyboard. * Root class for simple-keyboard.
* This class: * This class:
@ -193,17 +190,17 @@ class SimpleKeyboard {
* Simple-keyboard Instances * Simple-keyboard Instances
* This enables multiple simple-keyboard support with easier management * This enables multiple simple-keyboard support with easier management
*/ */
if (!window["SimpleKeyboardInstances"]) if (!(window as SKWindow)["SimpleKeyboardInstances"])
window["SimpleKeyboardInstances"] = {}; (window as SKWindow)["SimpleKeyboardInstances"] = {};
this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass); this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass);
window["SimpleKeyboardInstances"][this.currentInstanceName] = this; (window as SKWindow)["SimpleKeyboardInstances"][this.currentInstanceName] = this;
/** /**
* Instance vars * Instance vars
*/ */
this.allKeyboardInstances = window["SimpleKeyboardInstances"]; this.allKeyboardInstances = (window as SKWindow)["SimpleKeyboardInstances"];
this.keyboardInstanceNames = Object.keys(window["SimpleKeyboardInstances"]); this.keyboardInstanceNames = Object.keys((window as SKWindow)["SimpleKeyboardInstances"]);
this.isFirstKeyboardInstance = this.isFirstKeyboardInstance =
this.keyboardInstanceNames[0] === this.currentInstanceName; this.keyboardInstanceNames[0] === this.currentInstanceName;
@ -954,15 +951,15 @@ class SimpleKeyboard {
*/ */
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
dispatch(callback: (instance: SimpleKeyboard, key?: string) => void): void { dispatch(callback: (instance: SimpleKeyboard, key?: string) => void): void {
if (!window["SimpleKeyboardInstances"]) { if (!(window as SKWindow)["SimpleKeyboardInstances"]) {
console.warn( console.warn(
`SimpleKeyboardInstances is not defined. Dispatch cannot be called.` `SimpleKeyboardInstances is not defined. Dispatch cannot be called.`
); );
throw new Error("INSTANCES_VAR_ERROR"); throw new Error("INSTANCES_VAR_ERROR");
} }
return Object.keys(window["SimpleKeyboardInstances"]).forEach((key) => { return Object.keys((window as SKWindow)["SimpleKeyboardInstances"]).forEach((key) => {
callback(window["SimpleKeyboardInstances"][key], key); callback((window as SKWindow)["SimpleKeyboardInstances"][key], key);
}); });
} }
@ -1395,8 +1392,8 @@ class SimpleKeyboard {
/** /**
* Remove instance * Remove instance
*/ */
window["SimpleKeyboardInstances"][this.currentInstanceName] = null; (window as SKWindow)["SimpleKeyboardInstances"][this.currentInstanceName] = null;
delete window["SimpleKeyboardInstances"][this.currentInstanceName]; delete (window as SKWindow)["SimpleKeyboardInstances"][this.currentInstanceName];
/** /**
* Reset initialized flag * Reset initialized flag

View File

@ -2,6 +2,10 @@
import SimpleKeyboard from "./components/Keyboard"; import SimpleKeyboard from "./components/Keyboard";
import Utilities from "./services/Utilities"; import Utilities from "./services/Utilities";
export interface SKWindow extends Window {
SimpleKeyboardInstances?: any;
};
export interface KeyboardLayoutObject { export interface KeyboardLayoutObject {
[key: string]: string[]; [key: string]: string[];
} }