Skip to content

Commit

Permalink
change(web): move KeyboardProcessor.Codes into common/web/types
Browse files Browse the repository at this point in the history
Fixes: #8146
  • Loading branch information
ermshiperete committed Jul 4, 2024
1 parent c9a6284 commit f17f847
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 30 deletions.
5 changes: 3 additions & 2 deletions common/web/input-processor/src/correctionLayout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActiveKey, ActiveKeyBase, ActiveLayer, ActiveRow, Codes } from "@keymanapp/keyboard-processor";
import { ActiveKey, ActiveKeyBase, ActiveLayer, ActiveRow } from "@keymanapp/keyboard-processor";
import { Codes } from "@keymanapp/common-types";

/**
* Defines correction-layout mappings for keys to be considered by
Expand Down Expand Up @@ -108,4 +109,4 @@ export function buildCorrectiveLayout(layer: ActiveLayer, kbdScaleRatio: number)
.filter((entry) => correctionKeyFilter(entry.keySpec)),
kbdScaleRatio: kbdScaleRatio
};
}
}
4 changes: 2 additions & 2 deletions common/web/input-processor/src/text/inputProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import ContextWindow from "./contextWindow.js";
import LanguageProcessor from "./prediction/languageProcessor.js";
import type ModelSpec from "./prediction/modelSpec.js";
import { globalObject, DeviceSpec } from "@keymanapp/web-utils";
import { Codes } from "@keymanapp/common-types";

import {
type Alternate,
Codes,
isEmptyTransform,
type Keyboard,
KeyboardInterface,
Expand Down Expand Up @@ -385,4 +385,4 @@ export default class InputProcessor {
// With the layer now set, we trigger new predictions.
this.languageProcessor.invalidateContext(outputTarget, this.keyboardProcessor.layerId);
}
}
}
2 changes: 0 additions & 2 deletions common/web/keyboard-processor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export {
export { default as SpacebarText } from "./keyboards/spacebarText.js";
export { default as StateKeyMap } from "./keyboards/stateKeyMap.js";

export { default as Codes } from "./text/codes.js";
export * from "./text/codes.js";
export * from "./text/deadkeys.js";
export { default as DefaultRules } from "./text/defaultRules.js";
export * from "./text/defaultRules.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Codes from "../text/codes.js";
import { Codes } from '@keymanapp/common-types';
import KeyEvent, { KeyEventSpec } from "../text/keyEvent.js";
import KeyMapping from "../text/keyMapping.js";
import { ButtonClasses, Layouts } from "./defaultLayouts.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
***/

import { Version, deepCopy } from "@keymanapp/web-utils";
import { TouchLayout } from "@keymanapp/common-types";
import { Codes, TouchLayout } from "@keymanapp/common-types";

import LayoutFormFactorSpec = TouchLayout.TouchLayoutPlatform;
import LayoutLayerBase = TouchLayout.TouchLayoutLayer;
Expand All @@ -16,7 +16,6 @@ import ButtonClasses = TouchLayout.TouchLayoutKeySp;

export { ButtonClasses };

import Codes from "../text/codes.js";
import type Keyboard from "./keyboard.js";

export interface EncodedVisualKeyboard {
Expand Down
2 changes: 1 addition & 1 deletion common/web/keyboard-processor/src/keyboards/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Codes from "../text/codes.js";
import { Codes } from '@keymanapp/common-types';
import { EncodedVisualKeyboard, LayoutSpec, Layouts } from "./defaultLayouts.js";
import { ActiveKey, ActiveLayout, ActiveSubKey } from "./activeLayout.js";
import KeyEvent from "../text/keyEvent.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Codes } from '@keymanapp/common-types';
import Keyboard from "./keyboard.js";
import Codes from "../text/codes.js";

/**
* Defines members of the top-level `keyman` global object necessary to guarantee
Expand Down
2 changes: 1 addition & 1 deletion common/web/keyboard-processor/src/text/defaultRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// We should start splitting off code needed by keyboards even without a KeyboardProcessor active.
// There's an upcoming `/common/web/types` package that 'codes' and 'keyboards' may fit well within.

import Codes from "./codes.js";
import { Codes } from '@keymanapp/common-types';
import type KeyEvent from "./keyEvent.js";
import type OutputTarget from "./outputTarget.js";

Expand Down
2 changes: 1 addition & 1 deletion common/web/keyboard-processor/src/text/kbdInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//#region Imports

import { type DeviceSpec } from "@keymanapp/web-utils";
import { Codes } from '@keymanapp/common-types';

import Codes from "./codes.js";
import type KeyEvent from "./keyEvent.js";
import type { Deadkey } from "./deadkeys.js";
import KeyMapping from "./keyMapping.js";
Expand Down
2 changes: 1 addition & 1 deletion common/web/keyboard-processor/src/text/keyEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import type Keyboard from "../keyboards/keyboard.js";
import { type DeviceSpec } from "@keymanapp/web-utils";
import { Codes } from '@keymanapp/common-types';

import Codes from './codes.js';
import DefaultRules from './defaultRules.js';
import { ActiveKeyBase } from "../index.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// #region Big ol' list of imports

import { EventEmitter } from 'eventemitter3';
import { Codes } from '@keymanapp/common-types';

import Codes from "./codes.js";
import type Keyboard from "../keyboards/keyboard.js";
import { MinimalKeymanGlobal } from '../keyboards/keyboardHarness.js';
import KeyEvent from "./keyEvent.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// TODO: Move to separate folder: 'codes'
// We should start splitting off code needed by keyboards even without a KeyboardProcessor active.

// see also: common/web/types/src/kmx/kmx.ts

const Codes = {
export const Codes = {
// Define Keyman Developer modifier bit-flags (exposed for use by other modules)
// Compare against /common/include/kmx_file.h. CTRL+F "#define LCTRLFLAG" to find the secton.
modifierCodes: {
Expand Down Expand Up @@ -115,13 +114,13 @@ const Codes = {
* @return {number} modifier key state (desktop keyboards)
*/
getModifierState(layerId: string): number {
var modifier=0;
let modifier=0;
if(layerId.indexOf('shift') >= 0) {
modifier |= Codes.modifierCodes['SHIFT'];
}

// The chiral checks must not be directly exclusive due each other to visual OSK feedback.
var ctrlMatched=false;
let ctrlMatched=false;
if(layerId.indexOf('leftctrl') >= 0) {
modifier |= Codes.modifierCodes['LCTRL'];
ctrlMatched=true;
Expand All @@ -134,7 +133,7 @@ const Codes = {
modifier |= Codes.modifierCodes['CTRL'];
}

var altMatched=false;
let altMatched=false;
if(layerId.indexOf('leftalt') >= 0) {
modifier |= Codes.modifierCodes['LALT'];
altMatched=true;
Expand All @@ -157,7 +156,7 @@ const Codes = {
* @return {number} modifier key state (desktop keyboards)
*/
getStateFromLayer(layerId: string): number {
var modifier=0;
let modifier=0;

if(layerId.indexOf('caps') >= 0) {
modifier |= Codes.modifierCodes['CAPS'];
Expand All @@ -168,5 +167,3 @@ const Codes = {
return modifier;
}
}

export default Codes;
1 change: 1 addition & 0 deletions common/web/types/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export { UnicodeSetParser, UnicodeSet } from './ldml-keyboard/unicodeset-parser-
export { VariableParser, MarkerParser } from './ldml-keyboard/pattern-parser.js';
export { LDMLKeyboardXMLSourceFileReader, LDMLKeyboardXMLSourceFileReaderOptions } from './ldml-keyboard/ldml-keyboard-xml-reader.js';

export { Codes } from './consts/codes.js';
export * as Constants from './consts/virtual-key-constants.js';

export { defaultCompilerOptions, CompilerBaseOptions, CompilerCallbacks, CompilerOptions, CompilerEvent, CompilerErrorNamespace,
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/browser/src/defaultBrowserRules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Codes } from "@keymanapp/common-types";
import {
Codes,
DefaultRules,
type KeyEvent,
type OutputTarget
Expand Down
3 changes: 2 additions & 1 deletion web/src/app/browser/src/hardwareEventKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Codes, DeviceSpec, KeyEvent, KeyMapping, Keyboard, KeyboardProcessor } from '@keymanapp/keyboard-processor';
import { Codes } from "@keymanapp/common-types";
import { DeviceSpec, KeyEvent, KeyMapping, Keyboard, KeyboardProcessor } from '@keymanapp/keyboard-processor';

import { HardKeyboard, processForMnemonicsAndLegacy } from 'keyman/engine/main';
import { DomEventTracker } from 'keyman/engine/events';
Expand Down
3 changes: 2 additions & 1 deletion web/src/engine/main/src/hardKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventEmitter } from "eventemitter3";
import { Keyboard, KeyMapping, KeyEvent, type RuleBehavior, Codes } from "@keymanapp/keyboard-processor";
import { Keyboard, KeyMapping, KeyEvent, type RuleBehavior } from "@keymanapp/keyboard-processor";
import { Codes } from "@keymanapp/common-types";
import { KeyEventSourceInterface } from 'keyman/engine/events';

interface EventMap {
Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/osk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Codes, DeviceSpec, Keyboard, KeyboardProperties, SpacebarText } from '@keymanapp/keyboard-processor';
export { DeviceSpec, Keyboard, KeyboardProperties, SpacebarText } from '@keymanapp/keyboard-processor';

export { default as OSKView } from './views/oskView.js';
export { default as FloatingOSKView, FloatingOSKViewConfiguration } from './views/floatingOskView.js';
Expand Down
3 changes: 2 additions & 1 deletion web/src/engine/osk/src/keyboard-layout/oskBaseKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActiveKey, Codes } from '@keymanapp/keyboard-processor';
import { ActiveKey } from '@keymanapp/keyboard-processor';
import { Codes } from "@keymanapp/common-types";

import OSKKey, { KeyLayoutParams, renameSpecialKey } from './oskKey.js';
import { KeyData, KeyElement, link } from '../keyElement.js';
Expand Down
2 changes: 1 addition & 1 deletion web/src/engine/osk/src/views/oskView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from 'eventemitter3';
import { Codes } from "@keymanapp/common-types";

import { BannerView } from '../banner/bannerView.js';
import { BannerController } from '../banner/bannerController.js';
Expand All @@ -11,7 +12,6 @@ import { LengthStyle, ParsedLengthStyle } from '../lengthStyle.js';
import { type KeyElement } from '../keyElement.js';

import {
Codes,
DeviceSpec,
Keyboard,
KeyboardProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { preprocessKeyboardEvent } from 'keyman/app/browser';
import { processForMnemonicsAndLegacy } from 'keyman/engine/main';
import { PhysicalInputEventSpec } from '@keymanapp/recorder-core';
import { DeviceSpec } from '@keymanapp/web-utils';
import { Codes, Keyboard, KeyEvent } from '@keymanapp/keyboard-processor';
import { Codes } from "@keymanapp/common-types";
import { Keyboard, KeyEvent } from '@keymanapp/keyboard-processor';

const ModifierCodes = Codes.modifierCodes;
const KeyCodes = Codes.keyCodes;
Expand Down

0 comments on commit f17f847

Please sign in to comment.