Sin descripción

keycodes.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. /***/ "YLtl":
  90. /***/ (function(module, exports) {
  91. (function() { module.exports = window["lodash"]; }());
  92. /***/ }),
  93. /***/ "l3Sj":
  94. /***/ (function(module, exports) {
  95. (function() { module.exports = window["wp"]["i18n"]; }());
  96. /***/ }),
  97. /***/ "z7pY":
  98. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99. "use strict";
  100. // ESM COMPAT FLAG
  101. __webpack_require__.r(__webpack_exports__);
  102. // EXPORTS
  103. __webpack_require__.d(__webpack_exports__, "BACKSPACE", function() { return /* binding */ BACKSPACE; });
  104. __webpack_require__.d(__webpack_exports__, "TAB", function() { return /* binding */ TAB; });
  105. __webpack_require__.d(__webpack_exports__, "ENTER", function() { return /* binding */ ENTER; });
  106. __webpack_require__.d(__webpack_exports__, "ESCAPE", function() { return /* binding */ ESCAPE; });
  107. __webpack_require__.d(__webpack_exports__, "SPACE", function() { return /* binding */ SPACE; });
  108. __webpack_require__.d(__webpack_exports__, "LEFT", function() { return /* binding */ LEFT; });
  109. __webpack_require__.d(__webpack_exports__, "UP", function() { return /* binding */ UP; });
  110. __webpack_require__.d(__webpack_exports__, "RIGHT", function() { return /* binding */ RIGHT; });
  111. __webpack_require__.d(__webpack_exports__, "DOWN", function() { return /* binding */ DOWN; });
  112. __webpack_require__.d(__webpack_exports__, "DELETE", function() { return /* binding */ DELETE; });
  113. __webpack_require__.d(__webpack_exports__, "F10", function() { return /* binding */ F10; });
  114. __webpack_require__.d(__webpack_exports__, "ALT", function() { return /* binding */ ALT; });
  115. __webpack_require__.d(__webpack_exports__, "CTRL", function() { return /* binding */ CTRL; });
  116. __webpack_require__.d(__webpack_exports__, "COMMAND", function() { return /* binding */ COMMAND; });
  117. __webpack_require__.d(__webpack_exports__, "SHIFT", function() { return /* binding */ SHIFT; });
  118. __webpack_require__.d(__webpack_exports__, "ZERO", function() { return /* binding */ ZERO; });
  119. __webpack_require__.d(__webpack_exports__, "modifiers", function() { return /* binding */ modifiers; });
  120. __webpack_require__.d(__webpack_exports__, "rawShortcut", function() { return /* binding */ rawShortcut; });
  121. __webpack_require__.d(__webpack_exports__, "displayShortcutList", function() { return /* binding */ displayShortcutList; });
  122. __webpack_require__.d(__webpack_exports__, "displayShortcut", function() { return /* binding */ displayShortcut; });
  123. __webpack_require__.d(__webpack_exports__, "shortcutAriaLabel", function() { return /* binding */ shortcutAriaLabel; });
  124. __webpack_require__.d(__webpack_exports__, "isKeyboardEvent", function() { return /* binding */ isKeyboardEvent; });
  125. // EXTERNAL MODULE: external "lodash"
  126. var external_lodash_ = __webpack_require__("YLtl");
  127. // EXTERNAL MODULE: external ["wp","i18n"]
  128. var external_wp_i18n_ = __webpack_require__("l3Sj");
  129. // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js
  130. /**
  131. * External dependencies
  132. */
  133. /**
  134. * Return true if platform is MacOS.
  135. *
  136. * @param {Window?} _window window object by default; used for DI testing.
  137. *
  138. * @return {boolean} True if MacOS; false otherwise.
  139. */
  140. function isAppleOS(_window = null) {
  141. if (!_window) {
  142. if (typeof window === 'undefined') {
  143. return false;
  144. }
  145. _window = window;
  146. }
  147. const {
  148. platform
  149. } = _window.navigator;
  150. return platform.indexOf('Mac') !== -1 || Object(external_lodash_["includes"])(['iPad', 'iPhone'], platform);
  151. }
  152. // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js
  153. /**
  154. * Note: The order of the modifier keys in many of the [foo]Shortcut()
  155. * functions in this file are intentional and should not be changed. They're
  156. * designed to fit with the standard menu keyboard shortcuts shown in the
  157. * user's platform.
  158. *
  159. * For example, on MacOS menu shortcuts will place Shift before Command, but
  160. * on Windows Control will usually come first. So don't provide your own
  161. * shortcut combos directly to keyboardShortcut().
  162. */
  163. /**
  164. * External dependencies
  165. */
  166. /**
  167. * WordPress dependencies
  168. */
  169. /**
  170. * Internal dependencies
  171. */
  172. /** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
  173. /** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt'} WPKeycodeModifier */
  174. /**
  175. * An object of handler functions for each of the possible modifier
  176. * combinations. A handler will return a value for a given key.
  177. *
  178. * @template T
  179. *
  180. * @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler
  181. */
  182. /**
  183. * @template T
  184. *
  185. * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler
  186. */
  187. /** @typedef {(event: KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
  188. /**
  189. * Keycode for BACKSPACE key.
  190. */
  191. const BACKSPACE = 8;
  192. /**
  193. * Keycode for TAB key.
  194. */
  195. const TAB = 9;
  196. /**
  197. * Keycode for ENTER key.
  198. */
  199. const ENTER = 13;
  200. /**
  201. * Keycode for ESCAPE key.
  202. */
  203. const ESCAPE = 27;
  204. /**
  205. * Keycode for SPACE key.
  206. */
  207. const SPACE = 32;
  208. /**
  209. * Keycode for LEFT key.
  210. */
  211. const LEFT = 37;
  212. /**
  213. * Keycode for UP key.
  214. */
  215. const UP = 38;
  216. /**
  217. * Keycode for RIGHT key.
  218. */
  219. const RIGHT = 39;
  220. /**
  221. * Keycode for DOWN key.
  222. */
  223. const DOWN = 40;
  224. /**
  225. * Keycode for DELETE key.
  226. */
  227. const DELETE = 46;
  228. /**
  229. * Keycode for F10 key.
  230. */
  231. const F10 = 121;
  232. /**
  233. * Keycode for ALT key.
  234. */
  235. const ALT = 'alt';
  236. /**
  237. * Keycode for CTRL key.
  238. */
  239. const CTRL = 'ctrl';
  240. /**
  241. * Keycode for COMMAND/META key.
  242. */
  243. const COMMAND = 'meta';
  244. /**
  245. * Keycode for SHIFT key.
  246. */
  247. const SHIFT = 'shift';
  248. /**
  249. * Keycode for ZERO key.
  250. */
  251. const ZERO = 48;
  252. /**
  253. * Object that contains functions that return the available modifier
  254. * depending on platform.
  255. *
  256. * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}
  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. };
  270. /**
  271. * An object that contains functions to get raw shortcuts.
  272. *
  273. * These are intended for user with the KeyboardShortcuts.
  274. *
  275. * @example
  276. * ```js
  277. * // Assuming macOS:
  278. * rawShortcut.primary( 'm' )
  279. * // "meta+m""
  280. * ```
  281. *
  282. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
  283. * shortcuts.
  284. */
  285. const rawShortcut = Object(external_lodash_["mapValues"])(modifiers, modifier => {
  286. return (
  287. /** @type {WPKeyHandler<string>} */
  288. (character, _isApple = isAppleOS) => {
  289. return [...modifier(_isApple), character.toLowerCase()].join('+');
  290. }
  291. );
  292. });
  293. /**
  294. * Return an array of the parts of a keyboard shortcut chord for display.
  295. *
  296. * @example
  297. * ```js
  298. * // Assuming macOS:
  299. * displayShortcutList.primary( 'm' );
  300. * // [ "⌘", "M" ]
  301. * ```
  302. *
  303. * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
  304. * shortcut sequences.
  305. */
  306. const displayShortcutList = Object(external_lodash_["mapValues"])(modifiers, modifier => {
  307. return (
  308. /** @type {WPKeyHandler<string[]>} */
  309. (character, _isApple = isAppleOS) => {
  310. const isApple = _isApple();
  311. const replacementKeyMap = {
  312. [ALT]: isApple ? '⌥' : 'Alt',
  313. [CTRL]: isApple ? '⌃' : 'Ctrl',
  314. // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
  315. [COMMAND]: '⌘',
  316. [SHIFT]: isApple ? '⇧' : 'Shift'
  317. };
  318. const modifierKeys = modifier(_isApple).reduce((accumulator, key) => {
  319. const replacementKey = Object(external_lodash_["get"])(replacementKeyMap, key, key); // If on the Mac, adhere to platform convention and don't show plus between keys.
  320. if (isApple) {
  321. return [...accumulator, replacementKey];
  322. }
  323. return [...accumulator, replacementKey, '+'];
  324. },
  325. /** @type {string[]} */
  326. []);
  327. const capitalizedCharacter = Object(external_lodash_["capitalize"])(character);
  328. return [...modifierKeys, capitalizedCharacter];
  329. }
  330. );
  331. });
  332. /**
  333. * An object that contains functions to display shortcuts.
  334. *
  335. * @example
  336. * ```js
  337. * // Assuming macOS:
  338. * displayShortcut.primary( 'm' );
  339. * // "⌘M"
  340. * ```
  341. *
  342. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
  343. * display shortcuts.
  344. */
  345. const displayShortcut = Object(external_lodash_["mapValues"])(displayShortcutList, shortcutList => {
  346. return (
  347. /** @type {WPKeyHandler<string>} */
  348. (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('')
  349. );
  350. });
  351. /**
  352. * An object that contains functions to return an aria label for a keyboard
  353. * shortcut.
  354. *
  355. * @example
  356. * ```js
  357. * // Assuming macOS:
  358. * shortcutAriaLabel.primary( '.' );
  359. * // "Command + Period"
  360. * ```
  361. *
  362. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
  363. * shortcut ARIA labels.
  364. */
  365. const shortcutAriaLabel = Object(external_lodash_["mapValues"])(modifiers, modifier => {
  366. return (
  367. /** @type {WPKeyHandler<string>} */
  368. (character, _isApple = isAppleOS) => {
  369. const isApple = _isApple();
  370. const replacementKeyMap = {
  371. [SHIFT]: 'Shift',
  372. [COMMAND]: isApple ? 'Command' : 'Control',
  373. [CTRL]: 'Control',
  374. [ALT]: isApple ? 'Option' : 'Alt',
  375. /* translators: comma as in the character ',' */
  376. ',': Object(external_wp_i18n_["__"])('Comma'),
  377. /* translators: period as in the character '.' */
  378. '.': Object(external_wp_i18n_["__"])('Period'),
  379. /* translators: backtick as in the character '`' */
  380. '`': Object(external_wp_i18n_["__"])('Backtick')
  381. };
  382. return [...modifier(_isApple), character].map(key => Object(external_lodash_["capitalize"])(Object(external_lodash_["get"])(replacementKeyMap, key, key))).join(isApple ? ' ' : ' + ');
  383. }
  384. );
  385. });
  386. /**
  387. * From a given KeyboardEvent, returns an array of active modifier constants for
  388. * the event.
  389. *
  390. * @param {KeyboardEvent} event Keyboard event.
  391. *
  392. * @return {Array<WPModifierPart>} Active modifier constants.
  393. */
  394. function getEventModifiers(event) {
  395. return (
  396. /** @type {WPModifierPart[]} */
  397. [ALT, CTRL, COMMAND, SHIFT].filter(key => event[
  398. /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
  399. `${key}Key`])
  400. );
  401. }
  402. /**
  403. * An object that contains functions to check if a keyboard event matches a
  404. * predefined shortcut combination.
  405. *
  406. * @example
  407. * ```js
  408. * // Assuming an event for ⌘M key press:
  409. * isKeyboardEvent.primary( event, 'm' );
  410. * // true
  411. * ```
  412. *
  413. * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
  414. * to match events.
  415. */
  416. const isKeyboardEvent = Object(external_lodash_["mapValues"])(modifiers, getModifiers => {
  417. return (
  418. /** @type {WPEventKeyHandler} */
  419. (event, character, _isApple = isAppleOS) => {
  420. const mods = getModifiers(_isApple);
  421. const eventMods = getEventModifiers(event);
  422. if (Object(external_lodash_["xor"])(mods, eventMods).length) {
  423. return false;
  424. }
  425. if (!character) {
  426. return Object(external_lodash_["includes"])(mods, event.key.toLowerCase());
  427. }
  428. return event.key === character;
  429. }
  430. );
  431. });
  432. /***/ })
  433. /******/ });