Skip to content
Open
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
3 changes: 1 addition & 2 deletions web/src/engine/src/js-processor/jsKeyboardInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
type KeyEvent,
type TextStore,
VariableStore,
VariableStoreDictionary,
VariableStoreSerializer,
} from "keyman/engine/keyboard";
import { PlatformSystemStore } from './platformSystemStore.js';
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/src/keyboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions web/src/engine/src/keyboard/keyboards/jsKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/engine/src/keyboard/keyboards/processorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions web/src/engine/src/keyboard/variableStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 10 additions & 30 deletions web/src/engine/src/main/variableStoreCookieSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<VariableStore> {
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<VariableStore>(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<VariableStore>(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<VariableStore>(this.getStoreCookieName(keyboardID, storeName));
storeCookieSerializer.save(storeMap, encodeURIComponent);
}

/**
Expand All @@ -54,6 +32,8 @@ export class VariableStoreCookieSerializer implements VariableStoreSerializer {
* @returns An array of VariableStore objects found for the keyboard.
*/
public findStores(keyboardID: string): VariableStore[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the broken function, right? VariableStore is already a map, so it should be returning a map, not an array of maps. And this is a change in epic/web-core, not in the current alpha, so I think it's a change you made based on VariableStore being badly named.

Should we go ahead with naming it VariableStores and eliminate VariableStoreDictionary?

return VarStoreSerializer.findStores(keyboardID);
const pattern = new RegExp(`^${this.getStoreCookieName(keyboardID, '')}`);
const matching = CookieSerializer.loadAllMatching<VariableStore>(pattern, decodeURIComponent);
return matching.map(m => m.value);
}
}