|
@@ -3,15 +3,15 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-import CKEditorError from './ckeditorerror.js';
|
|
|
|
|
-import env from './env.js';
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Set of utils related to keyboard support.
|
|
* Set of utils related to keyboard support.
|
|
|
*
|
|
*
|
|
|
- * @namespace utils.keyboard
|
|
|
|
|
|
|
+ * @module utils/keyboard
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+import CKEditorError from './ckeditorerror.js';
|
|
|
|
|
+import env from './env.js';
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Object with `keyName => keyCode` pairs for a set of known keys.
|
|
* Object with `keyName => keyCode` pairs for a set of known keys.
|
|
|
*
|
|
*
|
|
@@ -23,17 +23,17 @@ import env from './env.js';
|
|
|
* * `backspace`, `delete`, `enter`, `esc`, `tab`,
|
|
* * `backspace`, `delete`, `enter`, `esc`, `tab`,
|
|
|
* * `ctrl`, `cmd`, `shift`, `alt`.
|
|
* * `ctrl`, `cmd`, `shift`, `alt`.
|
|
|
*
|
|
*
|
|
|
- * @member {Object} utils.keyboard.keyCodes
|
|
|
|
|
|
|
+ * @member {Object} module:utils/keyboard~keyCodes
|
|
|
*/
|
|
*/
|
|
|
export const keyCodes = generateKnownKeyCodes();
|
|
export const keyCodes = generateKnownKeyCodes();
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Converts a key name or a {@link utils.keyboard.KeystrokeInfo keystroke info} into a key code.
|
|
|
|
|
|
|
+ * Converts a key name or a {@link module:utils/keyboard~KeystrokeInfo keystroke info} into a key code.
|
|
|
*
|
|
*
|
|
|
- * Note: Key names are matched with {@link utils.keyboard.keyCodes} in a case-insensitive way.
|
|
|
|
|
|
|
+ * Note: Key names are matched with {@link module:utils/keyboard~keyCodes} in a case-insensitive way.
|
|
|
*
|
|
*
|
|
|
- * @method utils.keyboard.getCode
|
|
|
|
|
- * @param {String|utils.keyboard.KeystrokeInfo} Key name (see {@link utils.keyboard.keyCodes})
|
|
|
|
|
|
|
+ * @method module:utils/keyboard.getCode
|
|
|
|
|
+ * @param {String|module:utils/keyboard~KeystrokeInfo} Key name (see {@link module:utils/keyboard~keyCodes})
|
|
|
* or a keystroke data object.
|
|
* or a keystroke data object.
|
|
|
* @returns {Number} Key or keystroke code.
|
|
* @returns {Number} Key or keystroke code.
|
|
|
*/
|
|
*/
|
|
@@ -45,7 +45,7 @@ export function getCode( key ) {
|
|
|
|
|
|
|
|
if ( !keyCode ) {
|
|
if ( !keyCode ) {
|
|
|
/**
|
|
/**
|
|
|
- * Unknown key name. Only key names contained by the {@link utils.keyboard.keyCodes} can be used.
|
|
|
|
|
|
|
+ * Unknown key name. Only key names contained by the {@link module:utils/keyboard~keyCodes} can be used.
|
|
|
*
|
|
*
|
|
|
* @errror keyboard-unknown-key
|
|
* @errror keyboard-unknown-key
|
|
|
* @param {String} key
|
|
* @param {String} key
|
|
@@ -64,20 +64,20 @@ export function getCode( key ) {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Parses keystroke and returns a keystroke code that will match the code returned by
|
|
* Parses keystroke and returns a keystroke code that will match the code returned by
|
|
|
- * link {@link utils.keyboard.getCode} for a corresponding {@link utils.keyboard.KeystrokeInfo keystroke info}.
|
|
|
|
|
|
|
+ * link {@link module:utils/keyboard.getCode} for a corresponding {@link module:utils/keyboard~KeystrokeInfo keystroke info}.
|
|
|
*
|
|
*
|
|
|
* The keystroke can be passed in two formats:
|
|
* The keystroke can be passed in two formats:
|
|
|
*
|
|
*
|
|
|
* * as a single string – e.g. `ctrl + A`,
|
|
* * as a single string – e.g. `ctrl + A`,
|
|
|
- * * as an array of {@link utils.keyboard.keyCodes known key names} and key codes – e.g.:
|
|
|
|
|
|
|
+ * * as an array of {@link module:utils/keyboard~keyCodes known key names} and key codes – e.g.:
|
|
|
* * `[ 'ctrl', 32 ]` (ctrl + space),
|
|
* * `[ 'ctrl', 32 ]` (ctrl + space),
|
|
|
* * `[ 'ctrl', 'a' ]` (ctrl + A).
|
|
* * `[ 'ctrl', 'a' ]` (ctrl + A).
|
|
|
*
|
|
*
|
|
|
- * Note: Key names are matched with {@link utils.keyboard.keyCodes} in a case-insensitive way.
|
|
|
|
|
|
|
+ * Note: Key names are matched with {@link module:utils/keyboard~keyCodes} in a case-insensitive way.
|
|
|
*
|
|
*
|
|
|
* Note: Only keystrokes with a single non-modifier key are supported (e.g. `ctrl+A` is OK, but `ctrl+A+B` is not).
|
|
* Note: Only keystrokes with a single non-modifier key are supported (e.g. `ctrl+A` is OK, but `ctrl+A+B` is not).
|
|
|
*
|
|
*
|
|
|
- * @method utils.keyboard.parseKeystroke
|
|
|
|
|
|
|
+ * @method module:utils/keyboard~parseKeystroke
|
|
|
* @param {String|Array.<Number|String>} keystroke Keystroke definition.
|
|
* @param {String|Array.<Number|String>} keystroke Keystroke definition.
|
|
|
* @returns {Number} Keystroke code.
|
|
* @returns {Number} Keystroke code.
|
|
|
*/
|
|
*/
|
|
@@ -95,7 +95,7 @@ export function parseKeystroke( keystroke ) {
|
|
|
* It translates any keystroke string text like `"CTRL+A"` to an
|
|
* It translates any keystroke string text like `"CTRL+A"` to an
|
|
|
* environment–specific keystroke, i.e. `"⌘A"` on Mac OSX.
|
|
* environment–specific keystroke, i.e. `"⌘A"` on Mac OSX.
|
|
|
*
|
|
*
|
|
|
- * @method utils.keyboard.getEnvKeystrokeText
|
|
|
|
|
|
|
+ * @method module:utils/keyboard~getEnvKeystrokeText
|
|
|
* @param {String} keystroke Keystroke text.
|
|
* @param {String} keystroke Keystroke text.
|
|
|
* @returns {String} Keystroke text specific for the environment.
|
|
* @returns {String} Keystroke text specific for the environment.
|
|
|
*/
|
|
*/
|
|
@@ -155,29 +155,29 @@ function splitKeystrokeText( keystroke ) {
|
|
|
/**
|
|
/**
|
|
|
* Information about a keystroke.
|
|
* Information about a keystroke.
|
|
|
*
|
|
*
|
|
|
- * @interface utils.keyboard.KeystrokeInfo
|
|
|
|
|
|
|
+ * @interface module:utils/keyboard~KeystrokeInfo
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* The [key code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode).
|
|
* The [key code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode).
|
|
|
*
|
|
*
|
|
|
- * @member {Number} utils.keyboard.KeystrokeInfo#keyCode
|
|
|
|
|
|
|
+ * @member {Number} module:utils/keyboard~KeystrokeInfo#keyCode
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Whether the <kbd>Alt</kbd> modifier was pressed.
|
|
* Whether the <kbd>Alt</kbd> modifier was pressed.
|
|
|
*
|
|
*
|
|
|
- * @member {Bolean} utils.keyboard.KeystrokeInfo#altKey
|
|
|
|
|
|
|
+ * @member {Bolean} module:utils/keyboard~KeystrokeInfo#altKey
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Whether the <kbd>Ctrl</kbd> or <kbd>Cmd</kbd> modifier was pressed.
|
|
* Whether the <kbd>Ctrl</kbd> or <kbd>Cmd</kbd> modifier was pressed.
|
|
|
*
|
|
*
|
|
|
- * @member {Bolean} utils.keyboard.KeystrokeInfo#ctrlKey
|
|
|
|
|
|
|
+ * @member {Bolean} module:utils/keyboard~KeystrokeInfo#ctrlKey
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Whether the <kbd>Shift</kbd> modifier was pressed.
|
|
* Whether the <kbd>Shift</kbd> modifier was pressed.
|
|
|
*
|
|
*
|
|
|
- * @member {Bolean} utils.keyboard.KeystrokeInfo#shiftKey
|
|
|
|
|
|
|
+ * @member {Bolean} module:utils/keyboard~KeystrokeInfo#shiftKey
|
|
|
*/
|
|
*/
|