keycodes.js 13 KB

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