mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 16:35:33 +00:00
Fixes #6320. Part 1 of moving from lerna to a simpler, maintained monorepo solution, using TypeScript Projects and NPM Workspaces. There is more work to be done here. At this point, KeymanWeb builds and runs without errors, but the built file is substantially different, mostly in include order. Using TypeScript Projects, we move away from the need to run build scripts in various locations for almost all the Typescript modules. TODO: Embedded versions and tests have not been verified. TODO: developer/server is not yet verified. TODO: developer/js (needs a rename!) is not yet verified. TODO: Currently, the predictive-text folder needs refactoring to move the construction of the worker wrapper out of the Predictive Text build and into the final assembly of keymanweb.js (as it should be valid to run it as a separate .js anyway). TODO: Most of the `<reference>` paths need to be re-verified. Ideally there should be no references outside the current module for any given .ts. TODO: The embedded vs browser vs node (headless) builds should be tidied up for consistency so that it's obvious what depends on what. This is currently messiest in the predictive-text folder, where the output names diverge from the filenames and the various files are mixed in the same folder (as evidenced by the exclusions listed in each tsconfig.json). TODO: `npm install` should be removed from most build scripts and instead `npm ci` (#6196) should be run only once from the top-level folder for any given build. I've had eliminated side-effects from the `install` action for npm, which makes it easier to reason about state. TODO: verify_npm_setup and related functions can probably be eliminated. TODO: most of the build scripts should be largely eliminated for web. TODO: several ts projects use inconsistent output folders. TODO: it may be possible to generate a .d.ts for models/types so that we can use a consistent reference for those as well. TODO: build.sh, tsconfig.json should always be in the module's top-level folder, not in a subfolder such as src (e.g. see input-processor/src, keyboard-processor/src, web/source). TODO: resources/web-environment should be in common/web. TODO: other js node_modules imports should be wrapped like es6-shim. TODO: fix up the publish code for npm modules TODO: eliminate version numbers from package.json if possible? Whew, that's most of the stuff I noticed!
143 lines
No EOL
5.7 KiB
TypeScript
143 lines
No EOL
5.7 KiB
TypeScript
/*
|
|
* This file defines DOM-specific keyboard API that is not available in headless mode, extending web-core's
|
|
* base KeyboardInterface offerings.
|
|
*/
|
|
namespace com.keyman.text {
|
|
/**
|
|
* Function registerKeyboard KR
|
|
* Scope Public
|
|
* @param {Object} Pk Keyboard object
|
|
* Description Register and load the keyboard. This implementation overwrites web-core's intentionally,
|
|
* as web-core lacks access to the `KeyboardManager` object and class.
|
|
*/
|
|
KeyboardInterface.prototype.registerKeyboard = function(Pk): void {
|
|
let keyman = com.keyman.singleton;
|
|
keyman.keyboardManager._registerKeyboard(Pk);
|
|
}
|
|
|
|
/**
|
|
* Add the basic keyboard parameters (keyboard stub) to the array of keyboard stubs
|
|
* If no language code is specified in a keyboard it cannot be registered,
|
|
* and a keyboard stub must be registered before the keyboard is loaded
|
|
* for the keyboard to be usable.
|
|
*
|
|
* @param {Object} Pstub Keyboard stub object
|
|
* @return {?number} 1 if already registered, else null
|
|
*/
|
|
KeyboardInterface.prototype.registerStub = function(Pstub): number {
|
|
let keyboardManager = com.keyman.singleton.keyboardManager;
|
|
if (keyboardManager.keymanweb.initialized) {
|
|
// If language code already defined (or not specified in stub), check to see if stub already registered
|
|
for(let Lk=0; Lk < keyboardManager.keyboardStubs.length; Lk++) {
|
|
if(keyboardManager.keyboardStubs[Lk]['KI'] == Pstub['KI']) {
|
|
if(Pstub['KLC'] == '' || (keyboardManager.keyboardStubs[Lk]['KLC'] == Pstub['KLC'])) {
|
|
return 1; // no need to register
|
|
}
|
|
}
|
|
}
|
|
}
|
|
keyboardManager._registerStub(Pstub);
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Function KT
|
|
* Scope Public
|
|
* @param {string} Ptext Text to insert
|
|
* @param {?number} PdeadKey Dead key number, if any (???)
|
|
* @return {boolean} true if inserted
|
|
* Description Insert text into active control. Is utilized by keyboards with custom help HTML and requires
|
|
* special DOM handling.
|
|
*/
|
|
KeyboardInterface.prototype.insertText = function(Ptext: string, PdeadKey:number): boolean {
|
|
let keyman = com.keyman.singleton;
|
|
this.resetContextCache();
|
|
|
|
// Find the correct output target to manipulate.
|
|
let outputTarget: OutputTarget = this.activeTargetOutput ? this.activeTargetOutput : dom.Utils.getOutputTarget();
|
|
|
|
if(outputTarget != null) {
|
|
// Required for the `sil_euro_latin` keyboard's desktop OSK/table to function properly.
|
|
keyman.uiManager.setActivatingUI(true);
|
|
dom.DOMEventHandlers.states._IgnoreNextSelChange = 100;
|
|
keyman.domManager.focusLastActiveElement();
|
|
dom.DOMEventHandlers.states._IgnoreNextSelChange = 0;
|
|
|
|
if(Ptext!=null) {
|
|
this.output(0, outputTarget, Ptext);
|
|
}
|
|
|
|
if((typeof(PdeadKey)!=='undefined') && (PdeadKey !== null)) {
|
|
this.deadkeyOutput(0, outputTarget, PdeadKey);
|
|
}
|
|
|
|
outputTarget.invalidateSelection();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function KSF
|
|
* Scope Public
|
|
* Description Save keyboard focus
|
|
*/
|
|
KeyboardInterface.prototype.saveFocus = function(): void {
|
|
dom.DOMEventHandlers.states._IgnoreNextSelChange = 1;
|
|
}
|
|
|
|
/**
|
|
* Legacy entry points (non-standard names)- included only to allow existing IME keyboards to continue to be used
|
|
*/
|
|
KeyboardInterface.prototype['getLastActiveElement'] = function(): OutputTarget {
|
|
return dom.Utils.getOutputTarget();
|
|
}
|
|
|
|
KeyboardInterface.prototype['focusLastActiveElement'] = function(): void {
|
|
let keyman = com.keyman.singleton;
|
|
keyman.domManager.focusLastActiveElement();
|
|
}
|
|
|
|
//The following entry points are defined but should not normally be used in a keyboard, as OSK display is no longer determined by the keyboard
|
|
KeyboardInterface.prototype['hideHelp'] = function(): void {
|
|
let keyman = com.keyman.singleton;
|
|
keyman.osk.startHide(true);
|
|
}
|
|
|
|
KeyboardInterface.prototype['showHelp'] = function(Px: number, Py: number): void {
|
|
let keyman = com.keyman.singleton;
|
|
if(keyman.osk instanceof osk.FloatingOSKView) {
|
|
keyman.osk.presentAtPosition(Px,Py);
|
|
} else {
|
|
keyman.osk.present();
|
|
}
|
|
}
|
|
|
|
KeyboardInterface.prototype['showPinnedHelp'] = function(): void {
|
|
let keyman = com.keyman.singleton;
|
|
if(keyman.osk instanceof osk.FloatingOSKView) {
|
|
// An old KMW bug previously auto-unset the affected field when this function was
|
|
// used by CJK keyboards during rule processing. As a result, we need to condition
|
|
// on whether or not:
|
|
// 1. The active keyboard is CJK
|
|
// 2. A keyboard rule is actively processing.
|
|
//
|
|
// If BOTH are true, we do NOT mutate keyman.osk.userPositioned.
|
|
// Otherwise, not all conditions are met, so we still allow OSK pinning.
|
|
if(!keyman.core.activeKeyboard.isCJK || !this.ruleBehavior) {
|
|
keyman.osk.userPositioned=true;
|
|
}
|
|
}
|
|
// Automatically reuses previously-set positioning.
|
|
// Other OSK API functions must have previously been used to set the
|
|
// pinned position.
|
|
keyman.osk.present();
|
|
}
|
|
|
|
// Also needed for some legacy CJK keyboards.
|
|
KeyboardInterface.prototype['GetLastActiveElement'] = KeyboardInterface.prototype['getLastActiveElement'];
|
|
KeyboardInterface.prototype['FocusLastActiveElement'] = KeyboardInterface.prototype['focusLastActiveElement'];
|
|
KeyboardInterface.prototype['HideHelp'] = KeyboardInterface.prototype['hideHelp'];
|
|
KeyboardInterface.prototype['ShowHelp'] = KeyboardInterface.prototype['showHelp'];
|
|
KeyboardInterface.prototype['ShowPinnedHelp'] = KeyboardInterface.prototype['showPinnedHelp'];
|
|
} |