keycodes.js (15368B)
1 this["wp"] = this["wp"] || {}; this["wp"]["keycodes"] = 2 /******/ (function(modules) { // webpackBootstrap 3 /******/ // The module cache 4 /******/ var installedModules = {}; 5 /******/ 6 /******/ // The require function 7 /******/ function __webpack_require__(moduleId) { 8 /******/ 9 /******/ // Check if module is in cache 10 /******/ if(installedModules[moduleId]) { 11 /******/ return installedModules[moduleId].exports; 12 /******/ } 13 /******/ // Create a new module (and put it into the cache) 14 /******/ var module = installedModules[moduleId] = { 15 /******/ i: moduleId, 16 /******/ l: false, 17 /******/ exports: {} 18 /******/ }; 19 /******/ 20 /******/ // Execute the module function 21 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 /******/ 23 /******/ // Flag the module as loaded 24 /******/ module.l = true; 25 /******/ 26 /******/ // Return the exports of the module 27 /******/ return module.exports; 28 /******/ } 29 /******/ 30 /******/ 31 /******/ // expose the modules object (__webpack_modules__) 32 /******/ __webpack_require__.m = modules; 33 /******/ 34 /******/ // expose the module cache 35 /******/ __webpack_require__.c = installedModules; 36 /******/ 37 /******/ // define getter function for harmony exports 38 /******/ __webpack_require__.d = function(exports, name, getter) { 39 /******/ if(!__webpack_require__.o(exports, name)) { 40 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 41 /******/ } 42 /******/ }; 43 /******/ 44 /******/ // define __esModule on exports 45 /******/ __webpack_require__.r = function(exports) { 46 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 47 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 48 /******/ } 49 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 50 /******/ }; 51 /******/ 52 /******/ // create a fake namespace object 53 /******/ // mode & 1: value is a module id, require it 54 /******/ // mode & 2: merge all properties of value into the ns 55 /******/ // mode & 4: return value when already ns object 56 /******/ // mode & 8|1: behave like require 57 /******/ __webpack_require__.t = function(value, mode) { 58 /******/ if(mode & 1) value = __webpack_require__(value); 59 /******/ if(mode & 8) return value; 60 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 61 /******/ var ns = Object.create(null); 62 /******/ __webpack_require__.r(ns); 63 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 64 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 65 /******/ return ns; 66 /******/ }; 67 /******/ 68 /******/ // getDefaultExport function for compatibility with non-harmony modules 69 /******/ __webpack_require__.n = function(module) { 70 /******/ var getter = module && module.__esModule ? 71 /******/ function getDefault() { return module['default']; } : 72 /******/ function getModuleExports() { return module; }; 73 /******/ __webpack_require__.d(getter, 'a', getter); 74 /******/ return getter; 75 /******/ }; 76 /******/ 77 /******/ // Object.prototype.hasOwnProperty.call 78 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 79 /******/ 80 /******/ // __webpack_public_path__ 81 /******/ __webpack_require__.p = ""; 82 /******/ 83 /******/ 84 /******/ // Load entry module and return exports 85 /******/ return __webpack_require__(__webpack_require__.s = "z7pY"); 86 /******/ }) 87 /************************************************************************/ 88 /******/ ({ 89 90 /***/ "YLtl": 91 /***/ (function(module, exports) { 92 93 (function() { module.exports = window["lodash"]; }()); 94 95 /***/ }), 96 97 /***/ "l3Sj": 98 /***/ (function(module, exports) { 99 100 (function() { module.exports = window["wp"]["i18n"]; }()); 101 102 /***/ }), 103 104 /***/ "z7pY": 105 /***/ (function(module, __webpack_exports__, __webpack_require__) { 106 107 "use strict"; 108 // ESM COMPAT FLAG 109 __webpack_require__.r(__webpack_exports__); 110 111 // EXPORTS 112 __webpack_require__.d(__webpack_exports__, "BACKSPACE", function() { return /* binding */ BACKSPACE; }); 113 __webpack_require__.d(__webpack_exports__, "TAB", function() { return /* binding */ TAB; }); 114 __webpack_require__.d(__webpack_exports__, "ENTER", function() { return /* binding */ ENTER; }); 115 __webpack_require__.d(__webpack_exports__, "ESCAPE", function() { return /* binding */ ESCAPE; }); 116 __webpack_require__.d(__webpack_exports__, "SPACE", function() { return /* binding */ SPACE; }); 117 __webpack_require__.d(__webpack_exports__, "LEFT", function() { return /* binding */ LEFT; }); 118 __webpack_require__.d(__webpack_exports__, "UP", function() { return /* binding */ UP; }); 119 __webpack_require__.d(__webpack_exports__, "RIGHT", function() { return /* binding */ RIGHT; }); 120 __webpack_require__.d(__webpack_exports__, "DOWN", function() { return /* binding */ DOWN; }); 121 __webpack_require__.d(__webpack_exports__, "DELETE", function() { return /* binding */ DELETE; }); 122 __webpack_require__.d(__webpack_exports__, "F10", function() { return /* binding */ F10; }); 123 __webpack_require__.d(__webpack_exports__, "ALT", function() { return /* binding */ ALT; }); 124 __webpack_require__.d(__webpack_exports__, "CTRL", function() { return /* binding */ CTRL; }); 125 __webpack_require__.d(__webpack_exports__, "COMMAND", function() { return /* binding */ COMMAND; }); 126 __webpack_require__.d(__webpack_exports__, "SHIFT", function() { return /* binding */ SHIFT; }); 127 __webpack_require__.d(__webpack_exports__, "ZERO", function() { return /* binding */ ZERO; }); 128 __webpack_require__.d(__webpack_exports__, "modifiers", function() { return /* binding */ modifiers; }); 129 __webpack_require__.d(__webpack_exports__, "rawShortcut", function() { return /* binding */ rawShortcut; }); 130 __webpack_require__.d(__webpack_exports__, "displayShortcutList", function() { return /* binding */ displayShortcutList; }); 131 __webpack_require__.d(__webpack_exports__, "displayShortcut", function() { return /* binding */ displayShortcut; }); 132 __webpack_require__.d(__webpack_exports__, "shortcutAriaLabel", function() { return /* binding */ shortcutAriaLabel; }); 133 __webpack_require__.d(__webpack_exports__, "isKeyboardEvent", function() { return /* binding */ isKeyboardEvent; }); 134 135 // EXTERNAL MODULE: external "lodash" 136 var external_lodash_ = __webpack_require__("YLtl"); 137 138 // EXTERNAL MODULE: external ["wp","i18n"] 139 var external_wp_i18n_ = __webpack_require__("l3Sj"); 140 141 // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js 142 /** 143 * External dependencies 144 */ 145 146 /** 147 * Return true if platform is MacOS. 148 * 149 * @param {Window?} _window window object by default; used for DI testing. 150 * 151 * @return {boolean} True if MacOS; false otherwise. 152 */ 153 154 function isAppleOS(_window = null) { 155 if (!_window) { 156 if (typeof window === 'undefined') { 157 return false; 158 } 159 160 _window = window; 161 } 162 163 const { 164 platform 165 } = _window.navigator; 166 return platform.indexOf('Mac') !== -1 || Object(external_lodash_["includes"])(['iPad', 'iPhone'], platform); 167 } 168 169 // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js 170 /** 171 * Note: The order of the modifier keys in many of the [foo]Shortcut() 172 * functions in this file are intentional and should not be changed. They're 173 * designed to fit with the standard menu keyboard shortcuts shown in the 174 * user's platform. 175 * 176 * For example, on MacOS menu shortcuts will place Shift before Command, but 177 * on Windows Control will usually come first. So don't provide your own 178 * shortcut combos directly to keyboardShortcut(). 179 */ 180 181 /** 182 * External dependencies 183 */ 184 185 /** 186 * WordPress dependencies 187 */ 188 189 190 /** 191 * Internal dependencies 192 */ 193 194 195 /** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */ 196 197 /** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt'} WPKeycodeModifier */ 198 199 /** 200 * An object of handler functions for each of the possible modifier 201 * combinations. A handler will return a value for a given key. 202 * 203 * @template T 204 * 205 * @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler 206 */ 207 208 /** 209 * @template T 210 * 211 * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler 212 */ 213 214 /** @typedef {(event: KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */ 215 216 /** 217 * Keycode for BACKSPACE key. 218 */ 219 220 const BACKSPACE = 8; 221 /** 222 * Keycode for TAB key. 223 */ 224 225 const TAB = 9; 226 /** 227 * Keycode for ENTER key. 228 */ 229 230 const ENTER = 13; 231 /** 232 * Keycode for ESCAPE key. 233 */ 234 235 const ESCAPE = 27; 236 /** 237 * Keycode for SPACE key. 238 */ 239 240 const SPACE = 32; 241 /** 242 * Keycode for LEFT key. 243 */ 244 245 const LEFT = 37; 246 /** 247 * Keycode for UP key. 248 */ 249 250 const UP = 38; 251 /** 252 * Keycode for RIGHT key. 253 */ 254 255 const RIGHT = 39; 256 /** 257 * Keycode for DOWN key. 258 */ 259 260 const DOWN = 40; 261 /** 262 * Keycode for DELETE key. 263 */ 264 265 const DELETE = 46; 266 /** 267 * Keycode for F10 key. 268 */ 269 270 const F10 = 121; 271 /** 272 * Keycode for ALT key. 273 */ 274 275 const ALT = 'alt'; 276 /** 277 * Keycode for CTRL key. 278 */ 279 280 const CTRL = 'ctrl'; 281 /** 282 * Keycode for COMMAND/META key. 283 */ 284 285 const COMMAND = 'meta'; 286 /** 287 * Keycode for SHIFT key. 288 */ 289 290 const SHIFT = 'shift'; 291 /** 292 * Keycode for ZERO key. 293 */ 294 295 const ZERO = 48; 296 /** 297 * Object that contains functions that return the available modifier 298 * depending on platform. 299 * 300 * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>} 301 */ 302 303 const modifiers = { 304 primary: _isApple => _isApple() ? [COMMAND] : [CTRL], 305 primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT], 306 primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT], 307 secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT], 308 access: _isApple => _isApple() ? [CTRL, ALT] : [SHIFT, ALT], 309 ctrl: () => [CTRL], 310 alt: () => [ALT], 311 ctrlShift: () => [CTRL, SHIFT], 312 shift: () => [SHIFT], 313 shiftAlt: () => [SHIFT, ALT] 314 }; 315 /** 316 * An object that contains functions to get raw shortcuts. 317 * 318 * These are intended for user with the KeyboardShortcuts. 319 * 320 * @example 321 * ```js 322 * // Assuming macOS: 323 * rawShortcut.primary( 'm' ) 324 * // "meta+m"" 325 * ``` 326 * 327 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw 328 * shortcuts. 329 */ 330 331 const rawShortcut = Object(external_lodash_["mapValues"])(modifiers, modifier => { 332 return ( 333 /** @type {WPKeyHandler<string>} */ 334 (character, _isApple = isAppleOS) => { 335 return [...modifier(_isApple), character.toLowerCase()].join('+'); 336 } 337 ); 338 }); 339 /** 340 * Return an array of the parts of a keyboard shortcut chord for display. 341 * 342 * @example 343 * ```js 344 * // Assuming macOS: 345 * displayShortcutList.primary( 'm' ); 346 * // [ "⌘", "M" ] 347 * ``` 348 * 349 * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to 350 * shortcut sequences. 351 */ 352 353 const displayShortcutList = Object(external_lodash_["mapValues"])(modifiers, modifier => { 354 return ( 355 /** @type {WPKeyHandler<string[]>} */ 356 (character, _isApple = isAppleOS) => { 357 const isApple = _isApple(); 358 359 const replacementKeyMap = { 360 [ALT]: isApple ? '⌥' : 'Alt', 361 [CTRL]: isApple ? '⌃' : 'Ctrl', 362 // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character. 363 [COMMAND]: '⌘', 364 [SHIFT]: isApple ? '⇧' : 'Shift' 365 }; 366 const modifierKeys = modifier(_isApple).reduce((accumulator, key) => { 367 const replacementKey = Object(external_lodash_["get"])(replacementKeyMap, key, key); // If on the Mac, adhere to platform convention and don't show plus between keys. 368 369 if (isApple) { 370 return [...accumulator, replacementKey]; 371 } 372 373 return [...accumulator, replacementKey, '+']; 374 }, 375 /** @type {string[]} */ 376 []); 377 const capitalizedCharacter = Object(external_lodash_["capitalize"])(character); 378 return [...modifierKeys, capitalizedCharacter]; 379 } 380 ); 381 }); 382 /** 383 * An object that contains functions to display shortcuts. 384 * 385 * @example 386 * ```js 387 * // Assuming macOS: 388 * displayShortcut.primary( 'm' ); 389 * // "⌘M" 390 * ``` 391 * 392 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to 393 * display shortcuts. 394 */ 395 396 const displayShortcut = Object(external_lodash_["mapValues"])(displayShortcutList, shortcutList => { 397 return ( 398 /** @type {WPKeyHandler<string>} */ 399 (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('') 400 ); 401 }); 402 /** 403 * An object that contains functions to return an aria label for a keyboard 404 * shortcut. 405 * 406 * @example 407 * ```js 408 * // Assuming macOS: 409 * shortcutAriaLabel.primary( '.' ); 410 * // "Command + Period" 411 * ``` 412 * 413 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to 414 * shortcut ARIA labels. 415 */ 416 417 const shortcutAriaLabel = Object(external_lodash_["mapValues"])(modifiers, modifier => { 418 return ( 419 /** @type {WPKeyHandler<string>} */ 420 (character, _isApple = isAppleOS) => { 421 const isApple = _isApple(); 422 423 const replacementKeyMap = { 424 [SHIFT]: 'Shift', 425 [COMMAND]: isApple ? 'Command' : 'Control', 426 [CTRL]: 'Control', 427 [ALT]: isApple ? 'Option' : 'Alt', 428 429 /* translators: comma as in the character ',' */ 430 ',': Object(external_wp_i18n_["__"])('Comma'), 431 432 /* translators: period as in the character '.' */ 433 '.': Object(external_wp_i18n_["__"])('Period'), 434 435 /* translators: backtick as in the character '`' */ 436 '`': Object(external_wp_i18n_["__"])('Backtick') 437 }; 438 return [...modifier(_isApple), character].map(key => Object(external_lodash_["capitalize"])(Object(external_lodash_["get"])(replacementKeyMap, key, key))).join(isApple ? ' ' : ' + '); 439 } 440 ); 441 }); 442 /** 443 * From a given KeyboardEvent, returns an array of active modifier constants for 444 * the event. 445 * 446 * @param {KeyboardEvent} event Keyboard event. 447 * 448 * @return {Array<WPModifierPart>} Active modifier constants. 449 */ 450 451 function getEventModifiers(event) { 452 return ( 453 /** @type {WPModifierPart[]} */ 454 [ALT, CTRL, COMMAND, SHIFT].filter(key => event[ 455 /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */ 456 `${key}Key`]) 457 ); 458 } 459 /** 460 * An object that contains functions to check if a keyboard event matches a 461 * predefined shortcut combination. 462 * 463 * @example 464 * ```js 465 * // Assuming an event for ⌘M key press: 466 * isKeyboardEvent.primary( event, 'm' ); 467 * // true 468 * ``` 469 * 470 * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions 471 * to match events. 472 */ 473 474 475 const isKeyboardEvent = Object(external_lodash_["mapValues"])(modifiers, getModifiers => { 476 return ( 477 /** @type {WPEventKeyHandler} */ 478 (event, character, _isApple = isAppleOS) => { 479 const mods = getModifiers(_isApple); 480 const eventMods = getEventModifiers(event); 481 482 if (Object(external_lodash_["xor"])(mods, eventMods).length) { 483 return false; 484 } 485 486 if (!character) { 487 return Object(external_lodash_["includes"])(mods, event.key.toLowerCase()); 488 } 489 490 return event.key === character; 491 } 492 ); 493 }); 494 495 496 /***/ }) 497 498 /******/ });