[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> keycodes.js (source)

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


Generated: Sun Dec 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1