diff --git a/web/src/engine/src/js-processor/jsKeyboardInterface.ts b/web/src/engine/src/js-processor/jsKeyboardInterface.ts index 2ea921871ad..19f564d9d74 100644 --- a/web/src/engine/src/js-processor/jsKeyboardInterface.ts +++ b/web/src/engine/src/js-processor/jsKeyboardInterface.ts @@ -22,7 +22,6 @@ import { type KeyEvent, type TextStore, VariableStore, - VariableStoreDictionary, VariableStoreSerializer, } from "keyman/engine/keyboard"; import { PlatformSystemStore } from './platformSystemStore.js'; @@ -1103,7 +1102,7 @@ export class JSKeyboardInterface extends KeyboardHarness { * @param stores A dictionary of stores which should be found in the * keyboard */ - applyVariableStores(stores: VariableStoreDictionary): void { + applyVariableStores(stores: VariableStore): void { this.activeKeyboard.variableStores = stores; } diff --git a/web/src/engine/src/keyboard/index.ts b/web/src/engine/src/keyboard/index.ts index 3cf2aca3d30..ac4f70a4055 100644 --- a/web/src/engine/src/keyboard/index.ts +++ b/web/src/engine/src/keyboard/index.ts @@ -30,7 +30,7 @@ export { EmulationKeystrokes, LogMessages, DefaultRules } from "./defaultRules.j export { type KeyDistribution, KeyEventSpec, KeyEvent } from "./keyEvent.js"; export { KeyMapping } from "./keyMapping.js"; export { type SystemStoreMutationHandler, MutableSystemStore, SystemStore, SystemStoreIDs, type SystemStoreDictionary } from "./systemStore.js"; -export { type VariableStore, VariableStoreSerializer, VariableStoreDictionary } from "./variableStore.js"; +export { type VariableStore, VariableStoreSerializer } from "./variableStore.js"; export { DOMKeyboardLoader } from './keyboards/loaders/domKeyboardLoader.js'; export { SyntheticTextStore } from "./syntheticTextStore.js"; diff --git a/web/src/engine/src/keyboard/keyboards/jsKeyboard.ts b/web/src/engine/src/keyboard/keyboards/jsKeyboard.ts index 5fd6e06530b..78eeaf53876 100644 --- a/web/src/engine/src/keyboard/keyboards/jsKeyboard.ts +++ b/web/src/engine/src/keyboard/keyboards/jsKeyboard.ts @@ -4,7 +4,7 @@ import { ActiveKey, ActiveLayout, ActiveSubKey } from "./activeLayout.js"; import { KeyEvent } from "../keyEvent.js"; import { type TextStore } from "../textStore.js"; import { KeymanWebKeyboard, ModifierKeyConstants, TouchLayout } from "@keymanapp/common-types"; -import { VariableStoreDictionary } from "../variableStore.js"; +import { VariableStore } from "../variableStore.js"; import ComplexKeyboardStore = KeymanWebKeyboard.ComplexKeyboardStore; import KeyboardObject = KeymanWebKeyboard.KeyboardObject; @@ -120,9 +120,9 @@ export class JSKeyboard { * * @returns an object with each property referencing a variable store */ - get variableStores(): VariableStoreDictionary { + get variableStores(): VariableStore { const storeNames = this.scriptObject['KVS']; - let values: VariableStoreDictionary = {}; + let values: VariableStore = {}; if(Array.isArray(storeNames)) { for(let store of storeNames) { values[store] = this.scriptObject[store]; @@ -139,7 +139,7 @@ export class JSKeyboard { * * @param values name-value pairs for each store value */ - set variableStores(values: VariableStoreDictionary) { + set variableStores(values: VariableStore) { const storeNames = this.scriptObject['KVS']; if(Array.isArray(storeNames)) { for(let store of storeNames) { diff --git a/web/src/engine/src/keyboard/keyboards/processorAction.ts b/web/src/engine/src/keyboard/keyboards/processorAction.ts index e6bb3be5dad..12e9c8bca21 100644 --- a/web/src/engine/src/keyboard/keyboards/processorAction.ts +++ b/web/src/engine/src/keyboard/keyboards/processorAction.ts @@ -3,7 +3,7 @@ */ import { LexicalModelTypes } from '@keymanapp/common-types'; import { Transcription } from './transcription.js'; -import { VariableStore, VariableStoreDictionary } from '../variableStore.js'; +import { VariableStore } from '../variableStore.js'; import { SystemStoreDictionary } from '../systemStore.js'; /** @@ -34,7 +34,7 @@ export class ProcessorAction { /** * A set of variable stores with possible changes to be applied during finalization. */ - variableStores: VariableStoreDictionary = {}; + variableStores: VariableStore = {}; /** * Denotes a non-output default behavior; this should be evaluated later, against the true keystroke. diff --git a/web/src/engine/src/keyboard/variableStore.ts b/web/src/engine/src/keyboard/variableStore.ts index 2b7687245ae..09c80c500e9 100644 --- a/web/src/engine/src/keyboard/variableStore.ts +++ b/web/src/engine/src/keyboard/variableStore.ts @@ -4,10 +4,6 @@ * Definitions for variable stores (see kmn reference) */ -export interface VariableStoreDictionary { - [name: string]: string; -}; - export type VariableStore = { [name: string]: string; }; export interface VariableStoreSerializer { diff --git a/web/src/engine/src/main/variableStoreCookieSerializer.ts b/web/src/engine/src/main/variableStoreCookieSerializer.ts index 58425d61ee2..b0772fb05b7 100644 --- a/web/src/engine/src/main/variableStoreCookieSerializer.ts +++ b/web/src/engine/src/main/variableStoreCookieSerializer.ts @@ -8,42 +8,20 @@ import { CookieSerializer } from "keyman/engine/dom-utils"; // Also of note: there's nothing we can do to allow TS to provide type-checking of // dynamic property names; they'd have to be known at compile time to facilitate // strict type checking. -class VarStoreSerializer extends CookieSerializer { - public constructor(keyboardID: string, storeName: string) { - super(`KeymanWeb_${keyboardID}_Option_${storeName}`); - } - - public load(): VariableStore { - return super.load(decodeURIComponent); - } - - public save(storeMap: VariableStore) { - super.save(storeMap, encodeURIComponent); - } - /** - * Find all variable stores associated with a given keyboard. - * - * @param {string} keyboardID The keyboard ID whose variable stores are to be found. - * - * @returns An array of VariableStore objects found for the keyboard. - */ - public static findStores(keyboardID: string): VariableStore[] { - const pattern = new RegExp(`^KeymanWeb_${keyboardID}_Option_`); - const matching = CookieSerializer.loadAllMatching(pattern, decodeURIComponent); - return matching.map(m => m.value); +export class VariableStoreCookieSerializer implements VariableStoreSerializer { + private getStoreCookieName(keyboardID: string, storeName: string): string { + return `KeymanWeb_${keyboardID}_Option_${storeName}`; } -} -export class VariableStoreCookieSerializer implements VariableStoreSerializer { public loadStore(keyboardID: string, storeName: string): VariableStore { - const storeCookieSerializer = new VarStoreSerializer(keyboardID, storeName); - return storeCookieSerializer.load(); + const storeCookieSerializer = new CookieSerializer(this.getStoreCookieName(keyboardID, storeName)); + return storeCookieSerializer.load(decodeURIComponent); } public saveStore(keyboardID: string, storeName: string, storeMap: VariableStore) { - const storeCookieSerializer = new VarStoreSerializer(keyboardID, storeName); - storeCookieSerializer.save(storeMap); + const storeCookieSerializer = new CookieSerializer(this.getStoreCookieName(keyboardID, storeName)); + storeCookieSerializer.save(storeMap, encodeURIComponent); } /** @@ -54,6 +32,8 @@ export class VariableStoreCookieSerializer implements VariableStoreSerializer { * @returns An array of VariableStore objects found for the keyboard. */ public findStores(keyboardID: string): VariableStore[] { - return VarStoreSerializer.findStores(keyboardID); + const pattern = new RegExp(`^${this.getStoreCookieName(keyboardID, '')}`); + const matching = CookieSerializer.loadAllMatching(pattern, decodeURIComponent); + return matching.map(m => m.value); } } \ No newline at end of file