mirror of
https://github.com/keymanapp/keyman.git
synced 2026-11-03 09:37:47 +00:00
Merge pull request #15414 from keymanapp/refactor/web/renames
refactor(web): remove some aliases This is a follow-up of review comments in #15401. - rename `DefaultWorker` (in `web` subfolder) → `WebWorker` - rename `Worker` (in `node` subfolder) → `NodeWorker` - rename `BUTTON_CLASSES` → `buttonClassNames` All exports now also match the filenames. Follow-up-of: #15401
This commit is contained in:
commit
89681cefba
13 changed files with 33 additions and 30 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { KeymanEngine } from './keymanEngine.js'
|
||||
import { Worker } from '@keymanapp/lexical-model-layer/web'
|
||||
import { WebWorker } from '@keymanapp/lexical-model-layer/web'
|
||||
|
||||
/**
|
||||
* Determine path and protocol of executing script, setting them as
|
||||
|
|
@ -9,4 +9,4 @@ const ss = (document.currentScript as HTMLScriptElement)?.src;
|
|||
const sPath = ss ? ss.substring(0, ss.lastIndexOf('/') + 1) : './';
|
||||
|
||||
// @ts-ignore
|
||||
window['keyman'] = new KeymanEngine(Worker, sPath);
|
||||
window['keyman'] = new KeymanEngine(WebWorker, sPath);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { KeymanEngine } from './keymanEngine.js'
|
||||
import { Worker } from '@keymanapp/lexical-model-layer/web'
|
||||
import { WebWorker } from '@keymanapp/lexical-model-layer/web'
|
||||
|
||||
/**
|
||||
* Determine path and protocol of executing script, setting them as
|
||||
|
|
@ -9,4 +9,4 @@ const ss = (document.currentScript as HTMLScriptElement)?.src;
|
|||
const sPath = ss ? ss.substring(0, ss.lastIndexOf('/') + 1) : './';
|
||||
|
||||
// @ts-ignore
|
||||
window['keyman'] = new KeymanEngine(Worker, sPath);
|
||||
window['keyman'] = new KeymanEngine(WebWorker, sPath);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
export { default as LMLayer } from './lmlayer.js';
|
||||
export { default as NodeWorker } from './node/worker.js';
|
||||
export { default as WebWorker } from './web/worker.js';
|
||||
export { LMLayer } from './lmlayer.js';
|
||||
export { NodeWorker } from './node/node-worker.js';
|
||||
export { WebWorker } from './web/web-worker.js';
|
||||
|
||||
export interface WorkerFactory {
|
||||
constructInstance(): Worker
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export { LMLayer } from '../lmlayer.js';
|
||||
export { Worker } from './worker.js';
|
||||
export { NodeWorker } from './node-worker.js';
|
||||
export { SourcemappedWorker } from './sourcemappedWorker.js';
|
||||
|
||||
export interface WorkerFactory {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
/*
|
||||
* Keyman is copyright (C) SIL Global. MIT License.
|
||||
*/
|
||||
import { MappedWorker } from "./mappedWorker.js";
|
||||
import { unwrap } from '../unwrap.js';
|
||||
|
||||
import { LMLayerWorkerCode, LMLayerWorkerSourcemapComment } from "@keymanapp/lm-worker/worker-main.wrapped.min.js";
|
||||
|
||||
export class Worker {
|
||||
export class NodeWorker {
|
||||
static constructInstance(): Worker {
|
||||
let scriptStr = unwrap(LMLayerWorkerCode);
|
||||
const srcMapUrlIndex = scriptStr.indexOf("//# sourceMappingURL")
|
||||
|
|
@ -12,8 +15,6 @@ export class Worker {
|
|||
}
|
||||
|
||||
scriptStr += '\n' + LMLayerWorkerSourcemapComment;
|
||||
let worker = new MappedWorker(scriptStr);
|
||||
|
||||
return worker as any as Worker;
|
||||
return new MappedWorker(scriptStr);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
export { LMLayer } from '../lmlayer.js';
|
||||
export { DefaultWorker as Worker } from './worker.js'; // TODO: eliminate rename
|
||||
export { WebWorker } from './web-worker.js';
|
||||
export { SourcemappedWorker } from './sourcemappedWorker.js';
|
||||
|
||||
export interface WorkerFactory {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { unwrap } from '../unwrap.js';
|
|||
import { LMLayerWorkerCode, LMLayerWorkerSourcemapComment } from "@keymanapp/lm-worker/worker-main.wrapped.js";
|
||||
|
||||
export class SourcemappedWorker {
|
||||
// the only difference to DefaultWorker is that this class uses
|
||||
// the only difference to WebWorker is that this class uses
|
||||
// the unminified LM* blobs
|
||||
|
||||
static constructInstance(): Worker {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
/*
|
||||
* Keyman is copyright (C) SIL Global. MIT License.
|
||||
*/
|
||||
import { unwrap } from '../unwrap.js';
|
||||
import { LMLayerWorkerCode, LMLayerWorkerSourcemapComment } from "@keymanapp/lm-worker/worker-main.wrapped.min.js";
|
||||
|
||||
export class DefaultWorker {
|
||||
export class WebWorker {
|
||||
static constructInstance(): Worker {
|
||||
return new Worker(this.asBlobURI(LMLayerWorkerCode));
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { assert } from 'chai';
|
||||
|
||||
import { LMLayer, Worker as WorkerBuilder } from "@keymanapp/lexical-model-layer/web";
|
||||
import { LMLayer, WebWorker } from "@keymanapp/lexical-model-layer/web";
|
||||
|
||||
import { DEFAULT_BROWSER_TIMEOUT } from '@keymanapp/common-test-resources/test-timeouts.mjs';
|
||||
import { defaultCapabilities } from '../helpers.mjs';
|
||||
|
|
@ -10,7 +10,7 @@ describe('LMLayer', function () {
|
|||
|
||||
describe('[[constructor]]', function () {
|
||||
it('should construct with a single argument', function () {
|
||||
let lmLayer = new LMLayer(defaultCapabilities, WorkerBuilder.constructInstance(), true);
|
||||
let lmLayer = new LMLayer(defaultCapabilities, WebWorker.constructInstance(), true);
|
||||
assert.instanceOf(lmLayer, LMLayer);
|
||||
lmLayer.shutdown();
|
||||
});
|
||||
|
|
@ -31,7 +31,7 @@ describe('LMLayer', function () {
|
|||
// Note: the full declaration exists; the code we want is wrapped within the func.
|
||||
// So... let's just call the func.
|
||||
const workerSrc = dummyHandler.toString() + "\ndummyHandler()";
|
||||
let uri = WorkerBuilder.asBlobURI(workerSrc);
|
||||
let uri = WebWorker.asBlobURI(workerSrc);
|
||||
assert.match(uri, /^blob:/);
|
||||
|
||||
let worker = new Worker(uri);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { assert } from 'chai';
|
||||
|
||||
import { LMLayer, Worker } from "@keymanapp/lexical-model-layer/web";
|
||||
import { LMLayer, WebWorker } from "@keymanapp/lexical-model-layer/web";
|
||||
|
||||
import { DEFAULT_BROWSER_TIMEOUT } from '@keymanapp/common-test-resources/test-timeouts.mjs';
|
||||
import { defaultCapabilities } from '../helpers.mjs';
|
||||
|
|
@ -52,7 +52,7 @@ describe('LMLayer using dummy model', function () {
|
|||
|
||||
describe('Prediction', function () {
|
||||
it('will predict future suggestions', function () {
|
||||
var lmLayer = new LMLayer(defaultCapabilities, Worker.constructInstance(), true);
|
||||
var lmLayer = new LMLayer(defaultCapabilities, WebWorker.constructInstance(), true);
|
||||
|
||||
var stripIDs = function(suggestions) {
|
||||
suggestions.forEach(function(suggestion) {
|
||||
|
|
@ -93,7 +93,7 @@ describe('LMLayer using dummy model', function () {
|
|||
|
||||
describe('Wordbreaking', function () {
|
||||
it('will perform (default) wordbreaking and return word at caret', function () {
|
||||
var lmLayer = new LMLayer(defaultCapabilities, Worker.constructInstance());
|
||||
var lmLayer = new LMLayer(defaultCapabilities, WebWorker.constructInstance());
|
||||
|
||||
// We're testing many as asynchronous messages in a row.
|
||||
// this would be cleaner using async/await syntax, but
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { assert } from 'chai';
|
||||
|
||||
import { LMLayer, Worker } from "@keymanapp/lexical-model-layer/web";
|
||||
import { LMLayer, WebWorker } from "@keymanapp/lexical-model-layer/web";
|
||||
import { DEFAULT_BROWSER_TIMEOUT } from '@keymanapp/common-test-resources/test-timeouts.mjs';
|
||||
import { defaultCapabilities } from '../helpers.mjs';
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ describe('LMLayer using the trie model', function () {
|
|||
// Parameter 3 = true: enables 'test mode', disables correction-search timeout.
|
||||
// This helps prevent the correction-search timeout from flaking out periodically during unit tests in
|
||||
// CI, since remote servers / devices are involved.
|
||||
var lmLayer = new LMLayer(defaultCapabilities, Worker.constructInstance(), true);
|
||||
var lmLayer = new LMLayer(defaultCapabilities, WebWorker.constructInstance(), true);
|
||||
|
||||
// We're testing many as asynchronous messages in a row.
|
||||
// this would be cleaner using async/await syntax, but
|
||||
|
|
@ -71,7 +71,7 @@ describe('LMLayer using the trie model', function () {
|
|||
//
|
||||
// https://community.software.sil.org/t/search-term-to-key-in-lexical-model-not-working-both-ways-by-default/3133
|
||||
it('should use the default searchTermToKey()', function () {
|
||||
var lmLayer = new LMLayer(defaultCapabilities, Worker.constructInstance(), /* testMode */ true);
|
||||
var lmLayer = new LMLayer(defaultCapabilities, WebWorker.constructInstance(), /* testMode */ true);
|
||||
|
||||
let loc = document.location;
|
||||
return lmLayer.loadModel(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Maps 'sp' properties on a touch-layout spec to their corresponding CSS class names.
|
||||
*/
|
||||
export const BUTTON_CLASSES = [
|
||||
export const buttonClassNames = [
|
||||
'default',
|
||||
'shift',
|
||||
'shift-on',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { ActiveKey, ActiveSubKey, ButtonClass, ButtonClasses, DeviceSpec } from 'keyman/engine/keyboard';
|
||||
|
||||
// At present, we don't use @keymanapp/keyman. Just `keyman`. (Refer to <root>/web/package.json.)
|
||||
import { specialCharacters as specialChars } from '../specialCharacters.js'; // TODO: eliminate 'as specialChars'
|
||||
import { BUTTON_CLASSES as buttonClassNames } from '../buttonClassNames.js'; // TODO: eliminate 'as buttonClasNames'
|
||||
|
||||
import { specialCharacters } from '../specialCharacters.js';
|
||||
import { buttonClassNames } from '../buttonClassNames.js';
|
||||
import { KeyElement } from '../keyElement.js';
|
||||
import { VisualKeyboard } from '../visualKeyboard.js';
|
||||
import { getTextMetrics } from './getTextMetrics.js';
|
||||
|
|
@ -42,7 +41,7 @@ export function renameSpecialKey(oldText: string, vkbd: VisualKeyboard): string
|
|||
// do nothing.
|
||||
}
|
||||
|
||||
const specialCode = specialChars[oldText as keyof typeof specialChars];
|
||||
const specialCode = specialCharacters[oldText as keyof typeof specialCharacters];
|
||||
const specialCodePUA = 0XE000 + specialCode;
|
||||
|
||||
return specialCode ?
|
||||
|
|
@ -52,7 +51,7 @@ export function renameSpecialKey(oldText: string, vkbd: VisualKeyboard): string
|
|||
|
||||
export abstract class OSKKey {
|
||||
// Only set here to act as an alias for code built against legacy versions.
|
||||
static readonly specialCharacters = specialChars;
|
||||
static readonly specialCharacters = specialCharacters;
|
||||
|
||||
static readonly BUTTON_CLASSES = buttonClassNames;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue