From cfacbb6cc5cd1866f5ad38eae634a4ee711e4b7f Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 15 May 2025 18:23:03 +0200 Subject: [PATCH] =?UTF-8?q?refactor(web):=20rename=20`OutputTarget`=20inte?= =?UTF-8?q?rface=20=E2=86=92=20`OutputTargetInterface`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/app/browser/src/configuration.ts | 4 +- .../app/browser/src/defaultBrowserRules.ts | 4 +- web/src/app/webview/src/contextManager.ts | 8 ++-- .../attachment/src/outputTargetForElement.ts | 6 +-- .../prediction/languageProcessor.interface.ts | 12 +++--- .../src/prediction/predictionContext.ts | 8 ++-- .../js-processor/src/jsKeyboardInterface.ts | 40 +++++++++---------- .../js-processor/src/jsKeyboardProcessor.ts | 3 +- .../js-processor/src/outputTargetBase.ts | 4 +- web/src/engine/keyboard/src/defaultRules.ts | 4 +- web/src/engine/keyboard/src/index.ts | 2 +- .../keyboard/src/keyboards/jsKeyboard.ts | 12 +++--- ...tputTarget.ts => outputTargetInterface.ts} | 7 ++-- web/src/engine/main/src/contextManagerBase.ts | 20 +++++----- .../engine/main/src/engineConfiguration.ts | 4 +- .../main/src/headless/inputProcessor.ts | 8 ++-- .../main/src/headless/languageProcessor.ts | 16 ++++---- .../tools/testing/recorder-core/src/index.ts | 4 +- .../testing/recorder-core/src/nodeProctor.ts | 6 +-- .../testing/recorder-core/src/proctor.ts | 4 +- .../tools/testing/recorder/browserProctor.ts | 4 +- 21 files changed, 91 insertions(+), 89 deletions(-) rename web/src/engine/keyboard/src/{outputTarget.ts => outputTargetInterface.ts} (92%) diff --git a/web/src/app/browser/src/configuration.ts b/web/src/app/browser/src/configuration.ts index 4831b74c55..3799821165 100644 --- a/web/src/app/browser/src/configuration.ts +++ b/web/src/app/browser/src/configuration.ts @@ -1,7 +1,7 @@ import { EngineConfiguration, InitOptionSpec, InitOptionDefaults } from "keyman/engine/main"; import { OutputTargetElementWrapper as DOMOutputTarget } from 'keyman/engine/element-wrappers'; -import { OutputTarget } from 'keyman/engine/keyboard'; +import { OutputTargetInterface } from 'keyman/engine/keyboard'; import { isEmptyTransform, RuleBehavior } from 'keyman/engine/js-processor'; import { AlertHost } from "./utils/alertHost.js"; import { whenDocumentReady } from "./utils/documentReady.js"; @@ -66,7 +66,7 @@ export class BrowserConfiguration extends EngineConfiguration { return baseReport; } - onRuleFinalization(ruleBehavior: RuleBehavior, outputTarget: OutputTarget) { + onRuleFinalization(ruleBehavior: RuleBehavior, outputTarget: OutputTargetInterface) { // TODO: Patch up to modularized form. But that doesn't exist yet for some of these... // If the transform isn't empty, we've changed text - which should produce a 'changed' event in the DOM. diff --git a/web/src/app/browser/src/defaultBrowserRules.ts b/web/src/app/browser/src/defaultBrowserRules.ts index 5a0ceca3e9..433cd188bf 100644 --- a/web/src/app/browser/src/defaultBrowserRules.ts +++ b/web/src/app/browser/src/defaultBrowserRules.ts @@ -3,7 +3,7 @@ import { Codes, DefaultRules, type KeyEvent, - type OutputTarget + type OutputTargetInterface } from 'keyman/engine/keyboard'; import ContextManager from './contextManager.js'; @@ -32,7 +32,7 @@ export default class DefaultBrowserRules extends DefaultRules { /** * applyCommand - used when a RuleBehavior represents a non-text "command" within the Engine. */ - applyCommand(Lkc: KeyEvent, outputTarget: OutputTarget): void { + applyCommand(Lkc: KeyEvent, outputTarget: OutputTargetInterface): void { const code = this.codeForEvent(Lkc); const moveToNext = (back: boolean) => { diff --git a/web/src/app/webview/src/contextManager.ts b/web/src/app/webview/src/contextManager.ts index 7c3a53097e..48ab4ca927 100644 --- a/web/src/app/webview/src/contextManager.ts +++ b/web/src/app/webview/src/contextManager.ts @@ -1,5 +1,5 @@ -import { JSKeyboard, Keyboard, OutputTarget } from 'keyman/engine/keyboard'; -// TODO-web-core: remove usage of OutputTargetBase, use OutputTarget instead +import { JSKeyboard, Keyboard, OutputTargetInterface } from 'keyman/engine/keyboard'; +// TODO-web-core: remove usage of OutputTargetBase, use OutputTargetInterface instead import { Mock, Transcription, findCommonSubstringEndIndex, isEmptyTransform, TextTransform, OutputTargetBase } from 'keyman/engine/js-processor'; import { KeyboardStub } from 'keyman/engine/keyboard-storage'; import { ContextManagerBase } from 'keyman/engine/main'; @@ -59,7 +59,7 @@ export class ContextHost extends Mock { this.savedState = Mock.from(this); } - restoreTo(original: OutputTarget): void { + restoreTo(original: OutputTargetInterface): void { this.savedState = Mock.from(this); // TODO-web-core super.restoreTo(original as OutputTargetBase); @@ -139,7 +139,7 @@ export default class ContextManager extends ContextManagerBase boolean + 'suggestionapplied': (outputTarget: OutputTargetInterface) => boolean } @@ -56,7 +56,7 @@ export interface LanguageProcessorSpec extends EventEmitter; + invalidateContext(outputTarget: OutputTargetInterface, layerId: string): Promise; /** * @@ -66,9 +66,9 @@ export interface LanguageProcessorSpec extends EventEmitter string): Promise; + applySuggestion(suggestion: LexicalModelTypes.Suggestion, outputTarget: OutputTargetInterface, getLayerId: () => string): Promise; - applyReversion(reversion: LexicalModelTypes.Reversion, outputTarget: OutputTarget): Promise; + applyReversion(reversion: LexicalModelTypes.Reversion, outputTarget: OutputTargetInterface): Promise; get wordbreaksAfterSuggestions(): boolean; diff --git a/web/src/engine/interfaces/src/prediction/predictionContext.ts b/web/src/engine/interfaces/src/prediction/predictionContext.ts index 902566eed2..1efe3b5615 100644 --- a/web/src/engine/interfaces/src/prediction/predictionContext.ts +++ b/web/src/engine/interfaces/src/prediction/predictionContext.ts @@ -4,7 +4,7 @@ import Keep = LexicalModelTypes.Keep; import Reversion = LexicalModelTypes.Reversion; import Suggestion = LexicalModelTypes.Suggestion; import { type LanguageProcessorSpec , ReadySuggestions, type InvalidateSourceEnum, StateChangeHandler } from './languageProcessor.interface.js'; -import { type OutputTarget } from "keyman/engine/keyboard"; +import { type OutputTargetInterface } from "keyman/engine/keyboard"; interface PredictionContextEventMap { update: (suggestions: Suggestion[]) => void; @@ -41,13 +41,13 @@ export default class PredictionContext extends EventEmitter { + public setCurrentTarget(target: OutputTargetInterface): Promise { const originalTarget = this._currentTarget; this._currentTarget = target; diff --git a/web/src/engine/js-processor/src/jsKeyboardInterface.ts b/web/src/engine/js-processor/src/jsKeyboardInterface.ts index 147075f0f2..d15900bc6c 100644 --- a/web/src/engine/js-processor/src/jsKeyboardInterface.ts +++ b/web/src/engine/js-processor/src/jsKeyboardInterface.ts @@ -7,7 +7,7 @@ import { type DeviceSpec, KMWString } from "@keymanapp/web-utils"; import { ModifierKeyConstants } from '@keymanapp/common-types'; -import { Codes, type KeyEvent, KeyMapping, JSKeyboard, KeyboardHarness, KeyboardKeymanGlobal, type OutputTarget, VariableStoreDictionary } from "keyman/engine/keyboard"; +import { Codes, type KeyEvent, KeyMapping, JSKeyboard, KeyboardHarness, KeyboardKeymanGlobal, type OutputTargetInterface, VariableStoreDictionary } from "keyman/engine/keyboard"; import { type OutputTargetBase } from './outputTargetBase.js'; import { type Deadkey } from './deadkeys.js'; import { Mock } from "./mock.js"; @@ -174,7 +174,7 @@ export class JSKeyboardInterface extends KeyboardHarness { cachedContextEx: CachedContextEx = new CachedContextEx(); ruleContextEx: CachedContextEx; - activeTargetOutput: OutputTarget; + activeTargetOutput: OutputTargetInterface; ruleBehavior: RuleBehavior; systemStores: {[storeID: number]: SystemStore}; @@ -251,7 +251,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * KC(10,10,Pelem) == "abcdef" i.e. return as much as possible of the requested string */ - context(n: number, ln: number, outputTarget: OutputTarget): string { + context(n: number, ln: number, outputTarget: OutputTargetInterface): string { const v = this.cachedContext.get(n, ln); if(v !== null) { return v; @@ -275,7 +275,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * KC(3,3,Pelem) == "def" * KC(10,10,Pelem) == "XXXXabcdef" i.e. return as much as possible of the requested string, where X = \uFFFE */ - private KC_(n: number, ln: number, outputTarget: OutputTarget): string { + private KC_(n: number, ln: number, outputTarget: OutputTargetInterface): string { let tempContext = ''; // If we have a selection, we have an empty context @@ -301,7 +301,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * KN(2,Pelem) == FALSE * KN(4,Pelem) == TRUE */ - nul(n: number, outputTarget: OutputTarget): boolean { + nul(n: number, outputTarget: OutputTargetInterface): boolean { const cx=this.context(n+1, 1, outputTarget); // With #31, the result will be a replacement character if context is empty. @@ -318,7 +318,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @return {boolean} True if selected context matches val * Description Test keyboard context for match */ - contextMatch(n: number, outputTarget: OutputTarget, val: string, ln: number): boolean { + contextMatch(n: number, outputTarget: OutputTargetInterface, val: string, ln: number): boolean { const cx=this.context(n, ln, outputTarget); if(cx === val) { return true; // I3318 @@ -616,7 +616,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @return {boolean} True if deadkey found selected context matches val * Description Match deadkey at current cursor position */ - deadkeyMatch(n: number, outputTarget: OutputTarget, d: number): boolean { + deadkeyMatch(n: number, outputTarget: OutputTargetInterface, d: number): boolean { return outputTarget.hasDeadkeyMatch(n, d); } @@ -626,7 +626,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @param {Object} outputTarget element to flash * Description Flash body as substitute for audible beep; notify embedded device to vibrate */ - beep(outputTarget: OutputTarget): void { + beep(outputTarget: OutputTargetInterface): void { this.resetContextCache(); // Denote as part of the matched rule's behavior. @@ -719,7 +719,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @param {Object} outputTarget element to output to * Description Output a character selected from the string according to the offset in the index array */ - indexOutput(Pdn: number, Ps: KeyboardStore, Pn: number, outputTarget: OutputTarget): void { + indexOutput(Pdn: number, Ps: KeyboardStore, Pn: number, outputTarget: OutputTargetInterface): void { this.resetContextCache(); const assertNever = function(x: never): never { @@ -756,7 +756,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @param {Object} outputTarget element to output to * Description Keyboard output */ - deleteContext(dn: number, outputTarget: OutputTarget): void { + deleteContext(dn: number, outputTarget: OutputTargetInterface): void { let context: CachedExEntry; // We want to control exactly which deadkeys get removed. @@ -802,7 +802,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @param {string} s string to output * Description Keyboard output */ - output(dn: number, outputTarget: OutputTarget, s:string): void { + output(dn: number, outputTarget: OutputTargetInterface, s:string): void { this.resetContextCache(); outputTarget.saveProperties(); @@ -825,11 +825,11 @@ export class JSKeyboardInterface extends KeyboardHarness { * @alias KCXO * @public * @param {number} Pdn number of characters to delete left of cursor - * @param {OutputTarget} outputTarget target to output to + * @param {OutputTargetInterface} outputTarget target to output to * @param {number} contextLength length of current rule context to retrieve * @param {number} contextOffset offset from start of current rule context, 1-based */ - contextExOutput(Pdn: number, outputTarget: OutputTarget, contextLength: number, contextOffset: number): void { + contextExOutput(Pdn: number, outputTarget: OutputTargetInterface, contextLength: number, contextOffset: number): void { this.resetContextCache(); if(Pdn >= 0) { @@ -851,11 +851,11 @@ export class JSKeyboardInterface extends KeyboardHarness { * Function deadkeyOutput KDO * Scope Public * @param {number} Pdn no of character to overwrite (delete) - * @param {Object} outputTarget element to output to + * @param {OutputTargetInterface} outputTarget element to output to * @param {number} Pd deadkey id * Description Record a deadkey at current cursor position, deleting Pdn characters first */ - deadkeyOutput(Pdn: number, outputTarget: OutputTarget, Pd: number): void { + deadkeyOutput(Pdn: number, outputTarget: OutputTargetInterface, Pd: number): void { this.resetContextCache(); if(Pdn >= 0) { @@ -871,10 +871,10 @@ export class JSKeyboardInterface extends KeyboardHarness { * * @param {number} systemId ID of the system store to test (only TSS_LAYER currently supported) * @param {string} strValue String value to compare to - * @param {Object} outputTarget Currently active element (may be needed by future tests) + * @param {OutputTargetInterface} outputTarget Currently active element (may be needed by future tests) * @return {boolean} True if the test succeeds */ - ifStore(systemId: number, strValue: string, outputTarget: OutputTarget): boolean { + ifStore(systemId: number, strValue: string, outputTarget: OutputTargetInterface): boolean { let result=true; const store = this.systemStores[systemId]; if(store) { @@ -888,14 +888,14 @@ export class JSKeyboardInterface extends KeyboardHarness { * * @param {number} systemId ID of the system store to set (only TSS_LAYER currently supported) * @param {string} strValue String to set as the system store content - * @param {Object} outputTarget Currently active element (may be needed in future tests) + * @param {OutputTargetInterface} outputTarget Currently active element (may be needed in future tests) * @return {boolean} True if command succeeds * (i.e. for TSS_LAYER, if the layer is successfully selected) * * Note that option/variable stores are instead set within keyboard script code, as they only * affect keyboard behavior. */ - setStore(systemId: number, strValue: string, outputTarget: OutputTarget): boolean { + setStore(systemId: number, strValue: string, outputTarget: OutputTargetInterface): boolean { this.resetContextCache(); // Unique case: we only allow set(&layer) ops from keyboard rules triggered by touch OSKs. if(systemId == SystemStoreIDs.TSS_LAYER && this.activeDevice.touchable) { @@ -965,7 +965,7 @@ export class JSKeyboardInterface extends KeyboardHarness { this.cachedContextEx.reset(); } - defaultBackspace(outputTarget: OutputTarget) { + defaultBackspace(outputTarget: OutputTargetInterface) { if(outputTarget.isSelectionEmpty()) { // Delete the character left of the caret this.output(1, outputTarget, ""); diff --git a/web/src/engine/js-processor/src/jsKeyboardProcessor.ts b/web/src/engine/js-processor/src/jsKeyboardProcessor.ts index 9c1aa8b55b..9b238cdd2f 100644 --- a/web/src/engine/js-processor/src/jsKeyboardProcessor.ts +++ b/web/src/engine/js-processor/src/jsKeyboardProcessor.ts @@ -125,7 +125,8 @@ export class JSKeyboardProcessor extends EventEmitter { * where and when appropriate. * * @param {object} Lkc The pre-analyzed KeyEvent object - * @param {boolean} outputTarget The OutputTarget receiving the KeyEvent + * @param {OutputTargetInterface} outputTarget The OutputTarget receiving the KeyEvent + * @param {boolean} readonly True if the target is read-only * @return {string} */ private defaultRuleBehavior(Lkc: KeyEvent, outputTarget: OutputTargetBase, readonly: boolean): RuleBehavior { diff --git a/web/src/engine/js-processor/src/outputTargetBase.ts b/web/src/engine/js-processor/src/outputTargetBase.ts index 86c4c405ab..181e25c941 100644 --- a/web/src/engine/js-processor/src/outputTargetBase.ts +++ b/web/src/engine/js-processor/src/outputTargetBase.ts @@ -1,7 +1,7 @@ import { KMWString } from "@keymanapp/web-utils"; import { findCommonSubstringEndIndex } from "./stringDivergence.js"; import { Mock } from "./mock.js"; -import { OutputTarget } from 'keyman/engine/keyboard'; +import { OutputTargetInterface } from 'keyman/engine/keyboard'; // Defines deadkey management in a manner attachable to each element interface. import { type KeyEvent } from 'keyman/engine/keyboard'; @@ -64,7 +64,7 @@ export class Transcription { export type Alternate = LexicalModelTypes.ProbabilityMass; -export abstract class OutputTargetBase implements OutputTarget { +export abstract class OutputTargetBase implements OutputTargetInterface { private _dks: DeadkeyTracker; constructor() { diff --git a/web/src/engine/keyboard/src/defaultRules.ts b/web/src/engine/keyboard/src/defaultRules.ts index a057eda386..8b33b884d4 100644 --- a/web/src/engine/keyboard/src/defaultRules.ts +++ b/web/src/engine/keyboard/src/defaultRules.ts @@ -7,7 +7,7 @@ import { ModifierKeyConstants } from '@keymanapp/common-types'; import Codes from './codes.js'; import { type KeyEvent } from './keyEvent.js'; -import { type OutputTarget } from './outputTarget.js'; +import { type OutputTargetInterface } from './outputTargetInterface.js'; export enum EmulationKeystrokes { Enter = '\n', @@ -83,7 +83,7 @@ export default class DefaultRules { * * Note: is extended by DOM-aware KeymanWeb code. */ - public applyCommand(Lkc: KeyEvent, outputTarget: OutputTarget): void { + public applyCommand(Lkc: KeyEvent, outputTarget: OutputTargetInterface): void { // Notes for potential default-handling extensions: // // switch(code) { diff --git a/web/src/engine/keyboard/src/index.ts b/web/src/engine/keyboard/src/index.ts index 1ff8203dfe..864d01a5c2 100644 --- a/web/src/engine/keyboard/src/index.ts +++ b/web/src/engine/keyboard/src/index.ts @@ -27,7 +27,7 @@ export { default as DefaultRules } from "./defaultRules.js"; export * from "./defaultRules.js"; export { type KeyDistribution, KeyEventSpec, KeyEvent } from "./keyEvent.js"; export { default as KeyMapping } from "./keyMapping.js"; -export { OutputTarget } from "./outputTarget.js"; +export { OutputTargetInterface } from "./outputTargetInterface.js"; export * from "./systemStores.js"; export * from "@keymanapp/web-utils"; diff --git a/web/src/engine/keyboard/src/keyboards/jsKeyboard.ts b/web/src/engine/keyboard/src/keyboards/jsKeyboard.ts index cef519406e..ffb9799889 100644 --- a/web/src/engine/keyboard/src/keyboards/jsKeyboard.ts +++ b/web/src/engine/keyboard/src/keyboards/jsKeyboard.ts @@ -2,7 +2,7 @@ import Codes from "../codes.js"; import { Layouts } from "./defaultLayouts.js"; import { ActiveKey, ActiveLayout, ActiveSubKey } from "./activeLayout.js"; import { KeyEvent } from "../keyEvent.js"; -import { type OutputTarget } from "../outputTarget.js"; +import { type OutputTargetInterface } from "../outputTargetInterface.js"; import { KeymanWebKeyboard, ModifierKeyConstants, TouchLayout } from "@keymanapp/common-types"; import ComplexKeyboardStore = KeymanWebKeyboard.ComplexKeyboardStore; @@ -53,7 +53,7 @@ type KmwKeyboardObject = KeyboardObject & { */ export class JSKeyboard { public static DEFAULT_SCRIPT_OBJECT: KmwKeyboardObject = { - 'gs': function(outputTarget: OutputTarget, keystroke: KeyEvent) { return false; }, // no matching rules; rely on defaultRuleOutput entirely + 'gs': function(outputTarget: OutputTargetInterface, keystroke: KeyEvent) { return false; }, // no matching rules; rely on defaultRuleOutput entirely 'KI': '', // The currently-existing default keyboard ID; we already have checks that focus against this. 'KN': '', 'KV': Layouts.DEFAULT_RAW_SPEC, @@ -81,21 +81,21 @@ export class JSKeyboard { /** * Calls the keyboard's `gs` function, which represents the keyboard source's begin Unicode group. */ - process(outputTarget: OutputTarget, keystroke: KeyEvent): boolean { + process(outputTarget: OutputTargetInterface, keystroke: KeyEvent): boolean { return this.scriptObject['gs'](outputTarget, keystroke); } /** * Calls the keyboard's `gn` function, which represents the keyboard source's begin newContext group. */ - processNewContextEvent(outputTarget: OutputTarget, keystroke: KeyEvent): boolean { + processNewContextEvent(outputTarget: OutputTargetInterface, keystroke: KeyEvent): boolean { return this.scriptObject['gn'] ? this.scriptObject['gn'](outputTarget, keystroke) : false; } /** * Calls the keyboard's `gpk` function, which represents the keyboard source's begin postKeystroke group. */ - processPostKeystroke(outputTarget: OutputTarget, keystroke: KeyEvent): boolean { + processPostKeystroke(outputTarget: OutputTargetInterface, keystroke: KeyEvent): boolean { return this.scriptObject['gpk'] ? this.scriptObject['gpk'](outputTarget, keystroke) : false; } @@ -362,7 +362,7 @@ export class JSKeyboard { * @param {number} _PData 1 or 0 * Notifies keyboard of keystroke or other event */ - notify(_PCommand: number, _PTarget: OutputTarget, _PData: number) { // I2187 + notify(_PCommand: number, _PTarget: OutputTargetInterface, _PData: number) { // I2187 // Good example use case - the Japanese CJK-picker keyboard if(typeof(this.scriptObject['KNS']) == 'function') { this.scriptObject['KNS'](_PCommand, _PTarget, _PData); diff --git a/web/src/engine/keyboard/src/outputTarget.ts b/web/src/engine/keyboard/src/outputTargetInterface.ts similarity index 92% rename from web/src/engine/keyboard/src/outputTarget.ts rename to web/src/engine/keyboard/src/outputTargetInterface.ts index 34faa5667a..5dac4eb2cd 100644 --- a/web/src/engine/keyboard/src/outputTarget.ts +++ b/web/src/engine/keyboard/src/outputTargetInterface.ts @@ -1,10 +1,11 @@ /* * Keyman is copyright (C) SIL Global. MIT License. */ -export interface OutputTarget { +export interface OutputTargetInterface { /** - * Signifies that this OutputTarget has no default key processing behaviors. This should be false - * for OutputTargets backed by web elements like HTMLInputElement or HTMLTextAreaElement. + * Signifies that this OutputTargetInterface has no default key processing behaviors. + * This should be false for OutputTargets backed by web elements like HTMLInputElement + * or HTMLTextAreaElement. */ get isSynthetic(): boolean; diff --git a/web/src/engine/main/src/contextManagerBase.ts b/web/src/engine/main/src/contextManagerBase.ts index 3f2701cb82..8aa7319c83 100644 --- a/web/src/engine/main/src/contextManagerBase.ts +++ b/web/src/engine/main/src/contextManagerBase.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'eventemitter3'; -import { ManagedPromise, type Keyboard, type OutputTarget } from 'keyman/engine/keyboard'; +import { ManagedPromise, type Keyboard, type OutputTargetInterface } from 'keyman/engine/keyboard'; import { type JSKeyboardInterface } from 'keyman/engine/js-processor'; import { StubAndKeyboardCache, type KeyboardStub } from 'keyman/engine/keyboard-storage'; import { PredictionContext } from 'keyman/engine/interfaces'; @@ -7,7 +7,7 @@ import { EngineConfiguration } from './engineConfiguration.js'; interface EventMap { // target, then keyboard. - 'targetchange': (target: OutputTarget) => boolean; + 'targetchange': (target: OutputTargetInterface) => boolean; /** * This event is raised whenever a keyboard change is requested. @@ -48,7 +48,7 @@ export interface ContextManagerConfiguration { * * Does not reset option-stores, variable-stores, etc. */ - readonly resetContext: (outputTarget?: OutputTarget) => void; + readonly resetContext: (outputTarget?: OutputTargetInterface) => void; /** * A predictive-state management object that interfaces the predictive-text banner @@ -64,7 +64,7 @@ export interface ContextManagerConfiguration { } interface PendingActivation { - target: OutputTarget, + target: OutputTargetInterface, keyboard: Promise, stub: KeyboardStub; } @@ -74,11 +74,11 @@ export abstract class ContextManagerBase abstract initialize(): void; - abstract get activeTarget(): OutputTarget; + abstract get activeTarget(): OutputTargetInterface; private _predictionContext: PredictionContext; protected keyboardCache: StubAndKeyboardCache; - private _resetContext: (outputTarget?: OutputTarget) => void; + private _resetContext: (outputTarget?: OutputTargetInterface) => void; private pendingActivations: PendingActivation[] = []; protected engineConfig: MainConfig; @@ -135,7 +135,7 @@ export abstract class ContextManagerBase * attached elements within the app/browser target. For `app/webview`, this should * always return a consistent value - likely, `null`. */ - protected abstract currentKeyboardSrcTarget(): OutputTarget; + protected abstract currentKeyboardSrcTarget(): OutputTargetInterface; /** * Ensures that newly activated keyboards are set correctly within managed context, possibly @@ -143,7 +143,7 @@ export abstract class ContextManagerBase * @param kbd * @param target */ - protected abstract activateKeyboardForTarget(kbd: {keyboard: Keyboard, metadata: KeyboardStub}, target: OutputTarget): void; + protected abstract activateKeyboardForTarget(kbd: { keyboard: Keyboard, metadata: KeyboardStub }, target: OutputTargetInterface): void; /** * Checks the pending keyboard-activation array for an entry corresponding to the specified @@ -152,7 +152,7 @@ export abstract class ContextManagerBase * May be `null`, which corresponds to the global default Keyboard. * @returns `true` if pending activation is still valid, `false` otherwise. */ - private findAndPopActivation(target: OutputTarget): PendingActivation { + private findAndPopActivation(target: OutputTargetInterface): PendingActivation { // Array.findIndex requires Chrome 45+. :( let activationIndex; for(activationIndex = 0; activationIndex < this.pendingActivations.length; activationIndex++) { @@ -180,7 +180,7 @@ export abstract class ContextManagerBase protected async deferredKeyboardActivation( kbdPromise: Promise, metadata: KeyboardStub, - target: OutputTarget + target: OutputTargetInterface ): Promise { const activation: PendingActivation = { target: target, diff --git a/web/src/engine/main/src/engineConfiguration.ts b/web/src/engine/main/src/engineConfiguration.ts index 8e5daa2c0d..df394e7cb9 100644 --- a/web/src/engine/main/src/engineConfiguration.ts +++ b/web/src/engine/main/src/engineConfiguration.ts @@ -1,6 +1,6 @@ import { EventEmitter } from "eventemitter3"; -import { DeviceSpec, KeyboardProperties, ManagedPromise, OutputTarget, physicalKeyDeviceAlias, SpacebarText } from "keyman/engine/keyboard"; +import { DeviceSpec, KeyboardProperties, ManagedPromise, OutputTargetInterface, physicalKeyDeviceAlias, SpacebarText } from "keyman/engine/keyboard"; import { RuleBehavior } from 'keyman/engine/js-processor'; import { PathConfiguration, PathOptionDefaults, PathOptionSpec } from "keyman/engine/interfaces"; import { DeviceDetector } from "./headless/deviceDetector.js"; @@ -110,7 +110,7 @@ export class EngineConfiguration extends EventEmitter { * @param ruleBehavior The full effects of keystroke + postkeystroke rules from a processed keystroke. * @param outputTarget The engine's current source for context */ - onRuleFinalization(ruleBehavior: RuleBehavior, outputTarget: OutputTarget) {}; + onRuleFinalization(ruleBehavior: RuleBehavior, outputTarget: OutputTargetInterface) {}; } export interface InitOptionSpec extends PathOptionSpec { diff --git a/web/src/engine/main/src/headless/inputProcessor.ts b/web/src/engine/main/src/headless/inputProcessor.ts index fc7961bfee..fb946bd9c6 100644 --- a/web/src/engine/main/src/headless/inputProcessor.ts +++ b/web/src/engine/main/src/headless/inputProcessor.ts @@ -7,7 +7,7 @@ import { globalObject, DeviceSpec } from "@keymanapp/web-utils"; import { KM_Core } from 'keyman/engine/core-processor'; -import { Codes, JSKeyboard, KeyboardMinimalInterface, type Keyboard, type KeyEvent, type OutputTarget, SystemStoreIDs } from "keyman/engine/keyboard"; +import { Codes, JSKeyboard, KeyboardMinimalInterface, type Keyboard, type KeyEvent, type OutputTargetInterface, SystemStoreIDs } from "keyman/engine/keyboard"; // TODO-web-core: remove usage of OutputTargetBase import { type Alternate, @@ -96,7 +96,7 @@ export class InputProcessor { * @returns {Object} A RuleBehavior object describing the cumulative effects of * all matched keyboard rules. */ - processKeyEvent(keyEvent: KeyEvent, outputTarget: OutputTarget): RuleBehavior { + processKeyEvent(keyEvent: KeyEvent, outputTarget: OutputTargetInterface): RuleBehavior { const kbdMismatch = keyEvent.srcKeyboard && this.activeKeyboard != keyEvent.srcKeyboard; const trueActiveKeyboard = this.activeKeyboard; @@ -150,7 +150,7 @@ export class InputProcessor { * @param outputTarget * @returns */ - private _processKeyEvent(keyEvent: KeyEvent, outputTarget: OutputTarget): RuleBehavior { + private _processKeyEvent(keyEvent: KeyEvent, outputTarget: OutputTargetInterface): RuleBehavior { const formFactor = keyEvent.device.formFactor; const fromOSK = keyEvent.isSynthetic; @@ -395,7 +395,7 @@ export class InputProcessor { return alternates; } - public resetContext(outputTarget?: OutputTarget) { + public resetContext(outputTarget?: OutputTargetInterface) { // Also handles new-context events, which may modify the layer // TODO-web-core this.keyboardProcessor.resetContext(outputTarget as OutputTargetBase); diff --git a/web/src/engine/main/src/headless/languageProcessor.ts b/web/src/engine/main/src/headless/languageProcessor.ts index 719b11f1de..19d2229cdf 100644 --- a/web/src/engine/main/src/headless/languageProcessor.ts +++ b/web/src/engine/main/src/headless/languageProcessor.ts @@ -2,7 +2,7 @@ import { EventEmitter } from "eventemitter3"; import { LMLayer, WorkerFactory } from "@keymanapp/lexical-model-layer/web"; // TODO-web-core: remove use of OutputTargetBase import { Transcription, Mock, OutputTargetBase } from "keyman/engine/js-processor"; -import { OutputTarget } from 'keyman/engine/keyboard'; +import { OutputTargetInterface } from 'keyman/engine/keyboard'; import { LanguageProcessorEventMap, ModelSpec, StateChangeEnum, ReadySuggestions } from 'keyman/engine/interfaces'; import ContextWindow from "./contextWindow.js"; import { TranscriptionCache } from "./transcriptionCache.js"; @@ -127,7 +127,7 @@ export class LanguageProcessor extends EventEmitter { }); } - public invalidateContext(outputTarget: OutputTarget, layerId: string): Promise { + public invalidateContext(outputTarget: OutputTargetInterface, layerId: string): Promise { // If there's no active model, there can be no predictions. // We'll also be missing important data needed to even properly REQUEST the predictions. if(!this.currentModel || !this.configuration) { @@ -156,7 +156,7 @@ export class LanguageProcessor extends EventEmitter { } } - public wordbreak(target: OutputTarget, layerId: string): Promise { + public wordbreak(target: OutputTargetInterface, layerId: string): Promise { if(!this.isActive) { return null; } @@ -192,9 +192,9 @@ export class LanguageProcessor extends EventEmitter { * required because layerid can be changed by PostKeystroke * @returns */ - public applySuggestion(suggestion: Suggestion, outputTarget: OutputTarget, getLayerId: ()=>string): Promise { + public applySuggestion(suggestion: Suggestion, outputTarget: OutputTargetInterface, getLayerId: ()=>string): Promise { if(!outputTarget) { - throw "Accepting suggestions requires a destination OutputTarget instance." + throw "Accepting suggestions requires a destination OutputTargetInterface instance." } if(!this.isActive) { @@ -269,9 +269,9 @@ export class LanguageProcessor extends EventEmitter { } } - public applyReversion(reversion: Reversion, outputTarget: OutputTarget) { + public applyReversion(reversion: Reversion, outputTarget: OutputTargetInterface) { if(!outputTarget) { - throw "Accepting suggestions requires a destination OutputTarget instance." + throw "Accepting suggestions requires a destination OutputTargetInterface instance." } if(!this.isActive) { @@ -313,7 +313,7 @@ export class LanguageProcessor extends EventEmitter { return promise; } - public predictFromTarget(outputTarget: OutputTarget, layerId: string): Promise { + public predictFromTarget(outputTarget: OutputTargetInterface, layerId: string): Promise { if(!this.isActive || !outputTarget) { return null; } diff --git a/web/src/tools/testing/recorder-core/src/index.ts b/web/src/tools/testing/recorder-core/src/index.ts index 1e7631d687..60ab11a843 100644 --- a/web/src/tools/testing/recorder-core/src/index.ts +++ b/web/src/tools/testing/recorder-core/src/index.ts @@ -1,5 +1,5 @@ import { Mock } from "keyman/engine/js-processor"; -import { KeyDistribution, KeyEvent, type OutputTarget } from "keyman/engine/keyboard"; +import { KeyDistribution, KeyEvent, type OutputTargetInterface } from "keyman/engine/keyboard"; import Proctor from "./proctor.js"; @@ -217,7 +217,7 @@ export abstract class TestSequence { + async test(proctor: Proctor, target?: OutputTargetInterface): Promise<{success: boolean, result: string}> { // Start with an empty OutputTarget and a fresh KeyboardProcessor. if(!target) { target = new Mock(); diff --git a/web/src/tools/testing/recorder-core/src/nodeProctor.ts b/web/src/tools/testing/recorder-core/src/nodeProctor.ts index f65089c063..72980a528f 100644 --- a/web/src/tools/testing/recorder-core/src/nodeProctor.ts +++ b/web/src/tools/testing/recorder-core/src/nodeProctor.ts @@ -8,8 +8,8 @@ import { RecordedSyntheticKeystroke } from "./index.js"; -import { KeyEvent, KeyEventSpec, KeyboardHarness, type OutputTarget } from "keyman/engine/keyboard"; -// TODO-web-core: remove usage of OutputTargetBase, use OutputTarget instead +import { KeyEvent, KeyEventSpec, KeyboardHarness, type OutputTargetInterface } from "keyman/engine/keyboard"; +// TODO-web-core: remove usage of OutputTargetBase, use OutputTargetInterface instead import { Mock, OutputTargetBase } from 'keyman/engine/js-processor'; import { DeviceSpec } from "@keymanapp/web-utils"; import { JSKeyboardInterface, JSKeyboardProcessor } from 'keyman/engine/js-processor'; @@ -50,7 +50,7 @@ export default class NodeProctor extends Proctor { return true; } - async simulateSequence(sequence: TestSequence, target?: OutputTarget): Promise { + async simulateSequence(sequence: TestSequence, target?: OutputTargetInterface): Promise { // Start with an empty OutputTarget and a fresh KeyboardProcessor. if(!target) { target = new Mock(); diff --git a/web/src/tools/testing/recorder-core/src/proctor.ts b/web/src/tools/testing/recorder-core/src/proctor.ts index 0242b911a1..533648e88c 100644 --- a/web/src/tools/testing/recorder-core/src/proctor.ts +++ b/web/src/tools/testing/recorder-core/src/proctor.ts @@ -1,5 +1,5 @@ import { type DeviceSpec } from "@keymanapp/web-utils"; -import { type OutputTarget } from "keyman/engine/keyboard"; +import { type OutputTargetInterface } from "keyman/engine/keyboard"; import type { KeyboardTest, TestSet, TestSequence } from "./index.js"; @@ -49,5 +49,5 @@ export default abstract class Proctor { * Simulates the specified test sequence for use in testing. * @param sequence The recorded sequence, generally provided by a test set. */ - abstract simulateSequence(sequence: TestSequence, target?: OutputTarget): Promise; + abstract simulateSequence(sequence: TestSequence, target?: OutputTargetInterface): Promise; } \ No newline at end of file diff --git a/web/src/tools/testing/recorder/browserProctor.ts b/web/src/tools/testing/recorder/browserProctor.ts index fb6d6a7c04..cc81b89cea 100644 --- a/web/src/tools/testing/recorder/browserProctor.ts +++ b/web/src/tools/testing/recorder/browserProctor.ts @@ -4,7 +4,7 @@ import { type DeviceSpec } from "@keymanapp/web-utils"; -import { type OutputTarget } from "keyman/engine/keyboard"; +import { type OutputTargetInterface } from "keyman/engine/keyboard"; import { type KeymanEngine } from 'keyman/app/browser'; @@ -81,7 +81,7 @@ export class BrowserProctor extends Proctor { // Execution of a test sequence depends on the testing environment; this handles // the browser-specific aspects. - async simulateSequence(sequence: TestSequence, outputTarget?: OutputTarget): Promise { + async simulateSequence(sequence: TestSequence, outputTarget?: OutputTargetInterface): Promise { const driver = new BrowserDriver(this.target); // For the version 10.0 spec