Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(web): refactor JS based keyboard related class and file names 🎼 #12824

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/src/app/browser/src/beepHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type KeyboardInterface } from 'keyman/engine/js-processor';
import { type JSKeyboardInterface } from 'keyman/engine/js-processor';
import { DesignIFrame, OutputTarget } from 'keyman/engine/element-wrappers';

// Utility object used to handle beep (keyboard error response) operations.
Expand All @@ -17,9 +17,9 @@ class BeepData {
}

export class BeepHandler {
readonly keyboardInterface: KeyboardInterface;
readonly keyboardInterface: JSKeyboardInterface;

constructor(keyboardInterface: KeyboardInterface) {
constructor(keyboardInterface: JSKeyboardInterface) {
this.keyboardInterface = keyboardInterface;
}

Expand Down
10 changes: 5 additions & 5 deletions web/src/app/browser/src/contextManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Keyboard, KeyboardScriptError } from 'keyman/engine/keyboard';
import { type JSKeyboard, KeyboardScriptError } from 'keyman/engine/keyboard';
import { type KeyboardStub } from 'keyman/engine/keyboard-storage';
import { CookieSerializer } from 'keyman/engine/dom-utils';
import { eventOutputTarget, outputTargetForElement, PageContextAttachment } from 'keyman/engine/attachment';
Expand All @@ -25,7 +25,7 @@ export interface KeyboardCookie {
*
* @param {Object} Ptarg Target element
*/
function _SetTargDir(Ptarg: HTMLElement, activeKeyboard: Keyboard) {
function _SetTargDir(Ptarg: HTMLElement, activeKeyboard: JSKeyboard) {
const elDir = activeKeyboard?.isRTL ? 'rtl' : 'ltr';

if(Ptarg) {
Expand All @@ -41,14 +41,14 @@ function _SetTargDir(Ptarg: HTMLElement, activeKeyboard: Keyboard) {
}

export default class ContextManager extends ContextManagerBase<BrowserConfiguration> {
private _activeKeyboard: {keyboard: Keyboard, metadata: KeyboardStub};
private _activeKeyboard: {keyboard: JSKeyboard, metadata: KeyboardStub};
private cookieManager = new CookieSerializer<KeyboardCookie>('KeymanWeb_Keyboard');
readonly focusAssistant = new FocusAssistant(() => this.activeTarget?.isForcingScroll());
readonly page: PageContextAttachment;
private mostRecentTarget: OutputTarget<any>;
private currentTarget: OutputTarget<any>;

private globalKeyboard: {keyboard: Keyboard, metadata: KeyboardStub};
private globalKeyboard: {keyboard: JSKeyboard, metadata: KeyboardStub};

private _eventsObj: () => LegacyEventEmitter<LegacyAPIEvents>;
private domEventTracker = new DomEventTracker();
Expand Down Expand Up @@ -385,7 +385,7 @@ export default class ContextManager extends ContextManagerBase<BrowserConfigurat
}

// Note: is part of the keyboard activation process. Not to be called directly by published API.
activateKeyboardForTarget(kbd: {keyboard: Keyboard, metadata: KeyboardStub}, target: OutputTarget<any>) {
activateKeyboardForTarget(kbd: {keyboard: JSKeyboard, metadata: KeyboardStub}, target: OutputTarget<any>) {
let attachment = target?.getElement()._kmwAttachment;

if(!attachment) {
Expand Down
10 changes: 5 additions & 5 deletions web/src/app/browser/src/hardwareEventKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Codes, DeviceSpec, KeyEvent, KeyMapping, Keyboard } from 'keyman/engine/keyboard';
import { KeyboardProcessor } from 'keyman/engine/js-processor';
import { Codes, DeviceSpec, KeyEvent, KeyMapping, JSKeyboard } from 'keyman/engine/keyboard';
import { JSKeyboardProcessor } from 'keyman/engine/js-processor';
import { ModifierKeyConstants } from '@keymanapp/common-types';

import { HardKeyboard, processForMnemonicsAndLegacy } from 'keyman/engine/main';
Expand All @@ -10,7 +10,7 @@ import { eventOutputTarget, outputTargetForElement } from 'keyman/engine/attachm
import ContextManager from './contextManager.js';

type KeyboardState = {
activeKeyboard: Keyboard,
activeKeyboard: JSKeyboard,
modStateFlags: number,
baseLayout: string
}
Expand Down Expand Up @@ -209,13 +209,13 @@ export default class HardwareEventKeyboard extends HardKeyboard {
// - `modStateFlags`
// - `baseLayout`
// - `doModifierPress()` - for modifier updates on key-up.
private readonly processor: KeyboardProcessor;
private readonly processor: JSKeyboardProcessor;
private readonly contextManager: ContextManager;
private domEventTracker = new DomEventTracker();

private swallowKeypress: boolean = false;

constructor(hardDevice: DeviceSpec, processor: KeyboardProcessor, contextManager: ContextManager) {
constructor(hardDevice: DeviceSpec, processor: JSKeyboardProcessor, contextManager: ContextManager) {
super();
this.hardDevice = hardDevice;
this.contextManager = contextManager;
Expand Down
16 changes: 8 additions & 8 deletions web/src/app/browser/src/keymanEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
VisualKeyboard
} from 'keyman/engine/osk';
import { ErrorStub, KeyboardStub, CloudQueryResult, toPrefixedKeyboardId as prefixed } from 'keyman/engine/keyboard-storage';
import { DeviceSpec, Keyboard } from "keyman/engine/keyboard";
import { DeviceSpec, JSKeyboard } from "keyman/engine/keyboard";
import KeyboardObject = KeymanWebKeyboard.KeyboardObject;

import * as views from './viewsAnchorpoint.js';
Expand Down Expand Up @@ -271,7 +271,7 @@ export default class KeymanEngine extends KeymanEngineBase<BrowserConfiguration,
* Function setKeyboardForControl
* Scope Public
* @param {Element} Pelem Control element
* @param {string|null=} Pkbd Keyboard (Clears the set keyboard if set to null.)
* @param {string|null=} Pkbd JSKeyboard (Clears the set keyboard if set to null.)
* @param {string|null=} Plc Language Code
* Description Set default keyboard for the control
*
Expand Down Expand Up @@ -385,12 +385,12 @@ export default class KeymanEngine extends KeymanEngineBase<BrowserConfiguration,
* This is a public API function documented at
* https://help.keyman.com/developer/engine/web/current-version/reference/core/getKeyboard.
*
* @param {Object} Lstub Keyboard stub object
* @param {Object} Lkbd Keyboard script object
* @param {Object} Lstub JSKeyboard stub object
* @param {Object} Lkbd JSKeyboard script object
* @return {Object} Copy of keyboard identification strings
*
*/
private _GetKeyboardDetail = function(Lstub: KeyboardStub, Lkbd: Keyboard) { // I2078 - Full keyboard detail
private _GetKeyboardDetail = function(Lstub: KeyboardStub, Lkbd: JSKeyboard) { // I2078 - Full keyboard detail
let Lr = {
Name: Lstub.KN,
InternalName: Lstub.KI,
Expand Down Expand Up @@ -425,13 +425,13 @@ export default class KeymanEngine extends KeymanEngineBase<BrowserConfiguration,
* See https://help.keyman.com/developer/engine/web/current-version/reference/core/isCJK
*/
public isCJK(k0?: KeyboardObject | ReturnType<KeymanEngine['_GetKeyboardDetail']> /* [b/c Toolbar UI]*/) {
let kbd: Keyboard;
let kbd: JSKeyboard;
if(k0) {
let kbdDetail = k0 as ReturnType<KeymanEngine['_GetKeyboardDetail']>;
if(kbdDetail.KeyboardID){
kbd = this.keyboardRequisitioner.cache.getKeyboard(kbdDetail.KeyboardID);
} else {
kbd = new Keyboard(k0);
kbd = new JSKeyboard(k0);
}
} else {
kbd = this.core.activeKeyboard;
Expand Down Expand Up @@ -669,7 +669,7 @@ export default class KeymanEngine extends KeymanEngineBase<BrowserConfiguration,
argFormFactor?: DeviceSpec.FormFactor,
argLayerId?: string
): HTMLElement {
let PKbd: Keyboard = null;
let PKbd: JSKeyboard = null;

if(PInternalName != null) {
PKbd = this.keyboardRequisitioner.cache.getKeyboard(PInternalName);
Expand Down
8 changes: 4 additions & 4 deletions web/src/app/webview/src/contextManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Keyboard } from 'keyman/engine/keyboard';
import { type JSKeyboard } from 'keyman/engine/keyboard';
import { Mock, OutputTarget, Transcription, findCommonSubstringEndIndex, isEmptyTransform, TextTransform } from 'keyman/engine/js-processor';
import { KeyboardStub } from 'keyman/engine/keyboard-storage';
import { ContextManagerBase } from 'keyman/engine/main';
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class ContextManager extends ContextManagerBase<WebviewConfigurat
// yet to be modularized at this time, though.)
private _rawContext: ContextHost;

private _activeKeyboard: {keyboard: Keyboard, metadata: KeyboardStub};
private _activeKeyboard: {keyboard: JSKeyboard, metadata: KeyboardStub};

constructor(engineConfig: WebviewConfiguration) {
super(engineConfig);
Expand All @@ -136,7 +136,7 @@ export default class ContextManager extends ContextManagerBase<WebviewConfigurat
return this._activeKeyboard;
}

activateKeyboardForTarget(kbd: {keyboard: Keyboard, metadata: KeyboardStub}, target: OutputTarget) {
activateKeyboardForTarget(kbd: {keyboard: JSKeyboard, metadata: KeyboardStub}, target: OutputTarget) {
// `target` is irrelevant for `app/webview`, as it'll only ever use 'global' keyboard settings.

// Clone the object to prevent accidental by-reference changes.
Expand Down Expand Up @@ -192,7 +192,7 @@ export default class ContextManager extends ContextManagerBase<WebviewConfigurat
protected prepareKeyboardForActivation(
keyboardId: string,
languageCode?: string
): {keyboard: Promise<Keyboard>, metadata: KeyboardStub} {
): {keyboard: Promise<JSKeyboard>, metadata: KeyboardStub} {
const originalKeyboard = this.activeKeyboard;
const activatingKeyboard = super.prepareKeyboardForActivation(keyboardId, languageCode);

Expand Down
4 changes: 2 additions & 2 deletions web/src/app/webview/src/passthroughKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DeviceSpec, Keyboard, KeyEvent, ManagedPromise } from 'keyman/engine/keyboard';
import { DeviceSpec, JSKeyboard, KeyEvent, ManagedPromise } from 'keyman/engine/keyboard';

import { HardKeyboard, processForMnemonicsAndLegacy } from 'keyman/engine/main';

export default class PassthroughKeyboard extends HardKeyboard {
readonly baseDevice: DeviceSpec;
public activeKeyboard: Keyboard;
public activeKeyboard: JSKeyboard;

constructor(baseDevice: DeviceSpec) {
super();
Expand Down
6 changes: 2 additions & 4 deletions web/src/engine/js-processor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export { default as KeyboardProcessor } from "./keyboardProcessor.js";
export * from "./keyboardProcessor.js";
export { BeepHandler, JSKeyboardProcessor, LogMessageHandler, ProcessorInitOptions } from "./jsKeyboardProcessor.js";
export { default as RuleBehavior } from "./ruleBehavior.js";
export * from './kbdInterface.js';
export { default as KeyboardInterface } from "./kbdInterface.js";
export { JSKeyboardInterface, KeyInformation, StoreNonCharEntry } from "./jsKeyboardInterface.js";
export * from "./systemStores.js";
export * from "./deadkeys.js";
export { default as OutputTarget } from "./outputTarget.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { type DeviceSpec } from "@keymanapp/web-utils";
import { ModifierKeyConstants } from '@keymanapp/common-types';
import { Codes, type KeyEvent, KeyMapping, Keyboard, KeyboardHarness, KeyboardKeymanGlobal, VariableStoreDictionary } from "keyman/engine/keyboard";
import { Codes, type KeyEvent, KeyMapping, JSKeyboard, KeyboardHarness, KeyboardKeymanGlobal, VariableStoreDictionary } from "keyman/engine/keyboard";
import type OutputTarget from './outputTarget.js';
import { type Deadkey } from './deadkeys.js';
import { Mock } from "./mock.js";
Expand Down Expand Up @@ -165,7 +165,7 @@ class CachedContextEx {

//#endregion

export default class KeyboardInterface extends KeyboardHarness {
export class JSKeyboardInterface extends KeyboardHarness {
static readonly GLOBAL_NAME = 'KeymanWeb';

cachedContext: CachedContext = new CachedContext();
Expand All @@ -180,7 +180,7 @@ export default class KeyboardInterface extends KeyboardHarness {
_AnyIndices: number[] = []; // AnyIndex - array of any/index match indices

// Must be accessible to some of the keyboard API methods.
activeKeyboard: Keyboard;
activeKeyboard: JSKeyboard;
activeDevice: DeviceSpec;

variableStoreSerializer?: VariableStoreSerializer;
Expand Down Expand Up @@ -222,7 +222,7 @@ export default class KeyboardInterface extends KeyboardHarness {
/**
* Function registerKeyboard KR
* Scope Public
* @param {Object} Pk Keyboard object
* @param {Object} Pk JSKeyboard object
* Description Registers a keyboard with KeymanWeb once its script has fully loaded.
*
* In web-core, this also activates the keyboard; in other modules, this method
Expand All @@ -231,7 +231,7 @@ export default class KeyboardInterface extends KeyboardHarness {
registerKeyboard(Pk: any): void {
// NOTE: This implementation is web-core specific and is intentionally replaced, whole-sale,
// by DOM-aware code.
let keyboard = new Keyboard(Pk);
let keyboard = new JSKeyboard(Pk);
this.loadedKeyboard = keyboard;
}

Expand Down Expand Up @@ -571,7 +571,7 @@ export default class KeyboardInterface extends KeyboardHarness {
var modifierBitmask = bitmask & Codes.modifierBitmasks["ALL"];
var stateBitmask = bitmask & Codes.stateBitmasks["ALL"];

const eventModifiers = KeyboardInterface.matchModifiersToRuleChirality(e.Lmodifiers, Lruleshift);
const eventModifiers = JSKeyboardInterface.matchModifiersToRuleChirality(e.Lmodifiers, Lruleshift);

if(e.vkCode > 255) {
keyCode = e.vkCode; // added to support extended (touch-hold) keys for mnemonic layouts
Expand Down Expand Up @@ -1101,7 +1101,7 @@ export default class KeyboardInterface extends KeyboardHarness {
}

/**
* Publishes the KeyboardInterface's shorthand API names. As this assigns the current functions
* Publishes the JSKeyboardInterface's shorthand API names. As this assigns the current functions
* held by the longform versions, note that this should be called after replacing any of them via
* JS method extension.
*
Expand All @@ -1112,7 +1112,7 @@ export default class KeyboardInterface extends KeyboardHarness {
// Keyboard callbacks
let prototype = this.prototype;

var exportKBCallback = function(miniName: string, longName: keyof KeyboardInterface) {
var exportKBCallback = function(miniName: string, longName: keyof JSKeyboardInterface) {
if(prototype[longName]) {
// @ts-ignore
prototype[miniName] = prototype[longName];
Expand Down Expand Up @@ -1151,5 +1151,5 @@ export default class KeyboardInterface extends KeyboardHarness {

(function() {
// This will be the only call within the keyboard module.
KeyboardInterface.__publishShorthandAPI();
JSKeyboardInterface.__publishShorthandAPI();
}());
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import { EventEmitter } from 'eventemitter3';
import { ModifierKeyConstants } from '@keymanapp/common-types';
import {
Codes, type Keyboard, MinimalKeymanGlobal, KeyEvent, Layouts,
Codes, type JSKeyboard, MinimalKeymanGlobal, KeyEvent, Layouts,
DefaultRules, EmulationKeystrokes
} from "keyman/engine/keyboard";
import { Mock } from "./mock.js";
import type OutputTarget from "./outputTarget.js";
import RuleBehavior from "./ruleBehavior.js";
import KeyboardInterface from './kbdInterface.js';
import { JSKeyboardInterface } from './jsKeyboardInterface.js';
import { DeviceSpec, globalObject } from "@keymanapp/web-utils";
import { type MutableSystemStore, SystemStoreIDs } from "./systemStores.js";

Expand All @@ -28,15 +28,15 @@ export type LogMessageHandler = (str: string) => void;

export interface ProcessorInitOptions {
baseLayout?: string;
keyboardInterface?: KeyboardInterface;
keyboardInterface?: JSKeyboardInterface;
defaultOutputRules?: DefaultRules; // Takes the class def object, not an instance thereof.
}

interface EventMap {
statekeychange: (stateKeys: typeof KeyboardProcessor.prototype.stateKeys) => void;
statekeychange: (stateKeys: typeof JSKeyboardProcessor.prototype.stateKeys) => void;
}

export default class KeyboardProcessor extends EventEmitter<EventMap> {
export class JSKeyboardProcessor extends EventEmitter<EventMap> {
public static readonly DEFAULT_OPTIONS: ProcessorInitOptions = {
baseLayout: 'us',
defaultOutputRules: new DefaultRules()
Expand All @@ -55,7 +55,7 @@ export default class KeyboardProcessor extends EventEmitter<EventMap> {
// Needed for AltGr simulation.
modStateFlags: number = 0;

keyboardInterface: KeyboardInterface;
keyboardInterface: JSKeyboardInterface;

/**
* Indicates the device (platform) to be used for non-keystroke events,
Expand All @@ -77,21 +77,21 @@ export default class KeyboardProcessor extends EventEmitter<EventMap> {
super();

if(!options) {
options = KeyboardProcessor.DEFAULT_OPTIONS;
options = JSKeyboardProcessor.DEFAULT_OPTIONS;
}

this.contextDevice = device;

this.baseLayout = options.baseLayout || KeyboardProcessor.DEFAULT_OPTIONS.baseLayout;
this.keyboardInterface = options.keyboardInterface || new KeyboardInterface(globalObject(), MinimalKeymanGlobal);
this.defaultRules = options.defaultOutputRules || KeyboardProcessor.DEFAULT_OPTIONS.defaultOutputRules;
this.baseLayout = options.baseLayout || JSKeyboardProcessor.DEFAULT_OPTIONS.baseLayout;
this.keyboardInterface = options.keyboardInterface || new JSKeyboardInterface(globalObject(), MinimalKeymanGlobal);
this.defaultRules = options.defaultOutputRules || JSKeyboardProcessor.DEFAULT_OPTIONS.defaultOutputRules;
}

public get activeKeyboard(): Keyboard {
public get activeKeyboard(): JSKeyboard {
return this.keyboardInterface.activeKeyboard;
}

public set activeKeyboard(keyboard: Keyboard) {
public set activeKeyboard(keyboard: JSKeyboard) {
this.keyboardInterface.activeKeyboard = keyboard;

// All old deadkeys and keyboard-specific cache should immediately be invalidated
Expand Down
4 changes: 2 additions & 2 deletions web/src/engine/js-processor/src/ruleBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import KeyboardProcessor from "./keyboardProcessor.js";
import { JSKeyboardProcessor } from "./jsKeyboardProcessor.js";
import { VariableStoreDictionary } from "keyman/engine/keyboard";
import OutputTarget, { type Transcription } from './outputTarget.js';
import { Mock } from "./mock.js";
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class RuleBehavior {
*/
triggerKeyDefault?: boolean;

finalize(processor: KeyboardProcessor, outputTarget: OutputTarget, readonly: boolean) {
finalize(processor: JSKeyboardProcessor, outputTarget: OutputTarget, readonly: boolean) {
if(!this.transcription) {
throw "Cannot finalize a RuleBehavior with no transcription.";
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/js-processor/src/systemStores.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type KeyboardHarness } from 'keyman/engine/keyboard';
import { StoreNonCharEntry } from './kbdInterface.js';
import { StoreNonCharEntry } from './jsKeyboardInterface.js';

export enum SystemStoreIDs {
TSS_LAYER = 33,
Expand Down
Loading
Loading