From 84056682b60cc236b3a4bbd758d5dcad1718eea8 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 16 May 2024 14:34:26 +0700 Subject: [PATCH] chore(web): adds explicit typing for the app/ui Web modules --- web/src/app/ui/kmwuibutton.ts | 3 ++- web/src/app/ui/kmwuifloat.ts | 6 ++--- web/src/app/ui/kmwuitoggle.ts | 22 +++++++++------- web/src/app/ui/kmwuitoolbar.ts | 48 ++++++++++++++++++++++------------ 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/web/src/app/ui/kmwuibutton.ts b/web/src/app/ui/kmwuibutton.ts index adf929fac4e..700e854b280 100644 --- a/web/src/app/ui/kmwuibutton.ts +++ b/web/src/app/ui/kmwuibutton.ts @@ -293,7 +293,7 @@ if(!keyman?.ui?.name) { /* TODO: why is this still needed??? Does it actually do anything?? */ osk.addEventListener('hide', function(obj) { - if((arguments.length > 0) && obj['hiddenByUser']) { + if((arguments.length > 0) && obj['HiddenByUser']) { let _a = document.getElementById('KMW_Keyboard'); if(_a) { _a.className = 'kmw_hide'; @@ -405,6 +405,7 @@ if(!keyman?.ui?.name) { // ... wait, what? I can't find any evidence of this reference point existing. // Even tag `release-web-stable-2.0` turns up results only for this specific sourcefile. // Thus, in essence: if(true) { /* ... */ } + // @ts-ignore if(!keymanweb['iOS']) { var _li = util.createElement('li'); var _a = util.createElement('a'); diff --git a/web/src/app/ui/kmwuifloat.ts b/web/src/app/ui/kmwuifloat.ts index 06b3ef9715a..8d06534ad7c 100644 --- a/web/src/app/ui/kmwuifloat.ts +++ b/web/src/app/ui/kmwuifloat.ts @@ -442,7 +442,7 @@ if(!keyman?.ui?.name) { * @param {Object} e event * Description Change active keyboard in response to user selection event */ - readonly SelectKeyboardChange = (e) => { + readonly SelectKeyboardChange = (e: Event) => { keymanweb.activatingUI(true); if(this.KeyboardSelector.value != '-') { @@ -465,7 +465,7 @@ if(!keyman?.ui?.name) { * @param {Object} e event * Description Ensure OSK is hidden when moving focus after reselecting a keyboard */ - readonly SelectBlur = (e) => { + readonly SelectBlur = (e: Event) => { if(!this.selecting) { keymanweb.focusLastActiveElement(); } @@ -542,7 +542,7 @@ if(!keyman?.ui?.name) { * @return {boolean} * Description Display KMW OSK at specified position (returns nothing) */ - readonly _Resize = (e) => { + readonly _Resize = (e: Event) => { if(this.outerDiv.style.display =='block') { var elem = keymanweb.getLastActiveElement(); if(this.floatRight) { // I1296 diff --git a/web/src/app/ui/kmwuitoggle.ts b/web/src/app/ui/kmwuitoggle.ts index 266ce1f5ccf..e354b0c97e5 100644 --- a/web/src/app/ui/kmwuitoggle.ts +++ b/web/src/app/ui/kmwuitoggle.ts @@ -14,6 +14,10 @@ type KeyboardMenuEntry = { _Index: number; } +interface Owned { + _owningObject?: T; +} + // If a UI module has been loaded, we can rely on the publically-published 'name' property // having been set as a way to short-out a UI reload. Its parent object always exists by // this point in the build process. @@ -80,7 +84,7 @@ if(!keyman?.ui?.name) { * @param {(boolean|number)} focusing true if focusing * @param {Object} activeControl Object representing API specs for the control, if it exists and is now focused. */ - doFocus(someElement: HTMLElement, focusing: boolean | number, activeControl) { + doFocus(someElement: HTMLElement, focusing: boolean | number, activeControl: HTMLElement) { // This callback must be ignored until UI is initialized, or for touch devices (which can never initialize the UI) if(!this.initialized) { return; @@ -260,9 +264,9 @@ if(!keyman?.ui?.name) { class Button { // Button event-state management fields - _onclick = null; - _onmouseover = null; - _onmouseout = null; + _onclick: () => void = null; + _onmouseover: () => void = null; + _onmouseout: () => void = null; _down = false; _over = false; _selected: boolean; @@ -270,7 +274,7 @@ if(!keyman?.ui?.name) { /** * The top-level element of the button. */ - _elem: HTMLDivElement; + _elem: HTMLDivElement & Owned