keycodes.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 = 368);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 1:
  90. /***/ (function(module, exports) {
  91. (function() { module.exports = this["wp"]["i18n"]; }());
  92. /***/ }),
  93. /***/ 10:
  94. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  95. "use strict";
  96. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
  97. function _defineProperty(obj, key, value) {
  98. if (key in obj) {
  99. Object.defineProperty(obj, key, {
  100. value: value,
  101. enumerable: true,
  102. configurable: true,
  103. writable: true
  104. });
  105. } else {
  106. obj[key] = value;
  107. }
  108. return obj;
  109. }
  110. /***/ }),
  111. /***/ 17:
  112. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  113. "use strict";
  114. // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  115. function _arrayWithoutHoles(arr) {
  116. if (Array.isArray(arr)) {
  117. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  118. arr2[i] = arr[i];
  119. }
  120. return arr2;
  121. }
  122. }
  123. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
  124. var iterableToArray = __webpack_require__(30);
  125. // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
  126. function _nonIterableSpread() {
  127. throw new TypeError("Invalid attempt to spread non-iterable instance");
  128. }
  129. // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
  130. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _toConsumableArray; });
  131. function _toConsumableArray(arr) {
  132. return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || _nonIterableSpread();
  133. }
  134. /***/ }),
  135. /***/ 2:
  136. /***/ (function(module, exports) {
  137. (function() { module.exports = this["lodash"]; }());
  138. /***/ }),
  139. /***/ 30:
  140. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  141. "use strict";
  142. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; });
  143. function _iterableToArray(iter) {
  144. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  145. }
  146. /***/ }),
  147. /***/ 368:
  148. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  149. "use strict";
  150. __webpack_require__.r(__webpack_exports__);
  151. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
  152. var defineProperty = __webpack_require__(10);
  153. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules
  154. var toConsumableArray = __webpack_require__(17);
  155. // EXTERNAL MODULE: external "lodash"
  156. var external_lodash_ = __webpack_require__(2);
  157. // EXTERNAL MODULE: external {"this":["wp","i18n"]}
  158. var external_this_wp_i18n_ = __webpack_require__(1);
  159. // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js
  160. /**
  161. * External dependencies
  162. */
  163. /**
  164. * Return true if platform is MacOS.
  165. *
  166. * @param {Object} _window window object by default; used for DI testing.
  167. *
  168. * @return {boolean} True if MacOS; false otherwise.
  169. */
  170. function isAppleOS() {
  171. var _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
  172. var platform = _window.navigator.platform;
  173. return platform.indexOf('Mac') !== -1 || Object(external_lodash_["includes"])(['iPad', 'iPhone'], platform);
  174. }
  175. // CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js
  176. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BACKSPACE", function() { return BACKSPACE; });
  177. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TAB", function() { return TAB; });
  178. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ENTER", function() { return ENTER; });
  179. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ESCAPE", function() { return ESCAPE; });
  180. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SPACE", function() { return SPACE; });
  181. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LEFT", function() { return LEFT; });
  182. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "UP", function() { return UP; });
  183. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RIGHT", function() { return RIGHT; });
  184. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DOWN", function() { return DOWN; });
  185. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DELETE", function() { return DELETE; });
  186. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F10", function() { return F10; });
  187. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ALT", function() { return ALT; });
  188. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CTRL", function() { return CTRL; });
  189. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "COMMAND", function() { return COMMAND; });
  190. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SHIFT", function() { return SHIFT; });
  191. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "modifiers", function() { return modifiers; });
  192. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rawShortcut", function() { return rawShortcut; });
  193. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "displayShortcutList", function() { return displayShortcutList; });
  194. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "displayShortcut", function() { return displayShortcut; });
  195. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shortcutAriaLabel", function() { return shortcutAriaLabel; });
  196. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isKeyboardEvent", function() { return isKeyboardEvent; });
  197. /**
  198. * Note: The order of the modifier keys in many of the [foo]Shortcut()
  199. * functions in this file are intentional and should not be changed. They're
  200. * designed to fit with the standard menu keyboard shortcuts shown in the
  201. * user's platform.
  202. *
  203. * For example, on MacOS menu shortcuts will place Shift before Command, but
  204. * on Windows Control will usually come first. So don't provide your own
  205. * shortcut combos directly to keyboardShortcut().
  206. */
  207. /**
  208. * External dependencies
  209. */
  210. /**
  211. * WordPress dependencies
  212. */
  213. /**
  214. * Internal dependencies
  215. */
  216. /**
  217. * Keycode for BACKSPACE key.
  218. */
  219. var BACKSPACE = 8;
  220. /**
  221. * Keycode for TAB key.
  222. */
  223. var TAB = 9;
  224. /**
  225. * Keycode for ENTER key.
  226. */
  227. var ENTER = 13;
  228. /**
  229. * Keycode for ESCAPE key.
  230. */
  231. var ESCAPE = 27;
  232. /**
  233. * Keycode for SPACE key.
  234. */
  235. var SPACE = 32;
  236. /**
  237. * Keycode for LEFT key.
  238. */
  239. var LEFT = 37;
  240. /**
  241. * Keycode for UP key.
  242. */
  243. var UP = 38;
  244. /**
  245. * Keycode for RIGHT key.
  246. */
  247. var RIGHT = 39;
  248. /**
  249. * Keycode for DOWN key.
  250. */
  251. var DOWN = 40;
  252. /**
  253. * Keycode for DELETE key.
  254. */
  255. var DELETE = 46;
  256. /**
  257. * Keycode for F10 key.
  258. */
  259. var F10 = 121;
  260. /**
  261. * Keycode for ALT key.
  262. */
  263. var ALT = 'alt';
  264. /**
  265. * Keycode for CTRL key.
  266. */
  267. var CTRL = 'ctrl';
  268. /**
  269. * Keycode for COMMAND/META key.
  270. */
  271. var COMMAND = 'meta';
  272. /**
  273. * Keycode for SHIFT key.
  274. */
  275. var SHIFT = 'shift';
  276. /**
  277. * Object that contains functions that return the available modifier
  278. * depending on platform.
  279. *
  280. * - `primary`: takes a isApple function as a parameter.
  281. * - `primaryShift`: takes a isApple function as a parameter.
  282. * - `primaryAlt`: takes a isApple function as a parameter.
  283. * - `secondary`: takes a isApple function as a parameter.
  284. * - `access`: takes a isApple function as a parameter.
  285. * - `ctrl`
  286. * - `alt`
  287. * - `ctrlShift`
  288. * - `shift`
  289. * - `shiftAlt`
  290. */
  291. var modifiers = {
  292. primary: function primary(_isApple) {
  293. return _isApple() ? [COMMAND] : [CTRL];
  294. },
  295. primaryShift: function primaryShift(_isApple) {
  296. return _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT];
  297. },
  298. primaryAlt: function primaryAlt(_isApple) {
  299. return _isApple() ? [ALT, COMMAND] : [CTRL, ALT];
  300. },
  301. secondary: function secondary(_isApple) {
  302. return _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT];
  303. },
  304. access: function access(_isApple) {
  305. return _isApple() ? [CTRL, ALT] : [SHIFT, ALT];
  306. },
  307. ctrl: function ctrl() {
  308. return [CTRL];
  309. },
  310. alt: function alt() {
  311. return [ALT];
  312. },
  313. ctrlShift: function ctrlShift() {
  314. return [CTRL, SHIFT];
  315. },
  316. shift: function shift() {
  317. return [SHIFT];
  318. },
  319. shiftAlt: function shiftAlt() {
  320. return [SHIFT, ALT];
  321. }
  322. };
  323. /**
  324. * An object that contains functions to get raw shortcuts.
  325. * E.g. rawShortcut.primary( 'm' ) will return 'meta+m' on Mac.
  326. * These are intended for user with the KeyboardShortcuts component or TinyMCE.
  327. *
  328. * @type {Object} Keyed map of functions to raw shortcuts.
  329. */
  330. var rawShortcut = Object(external_lodash_["mapValues"])(modifiers, function (modifier) {
  331. return function (character) {
  332. var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  333. return [].concat(Object(toConsumableArray["a" /* default */])(modifier(_isApple)), [character.toLowerCase()]).join('+');
  334. };
  335. });
  336. /**
  337. * Return an array of the parts of a keyboard shortcut chord for display
  338. * E.g displayShortcutList.primary( 'm' ) will return [ '⌘', 'M' ] on Mac.
  339. *
  340. * @type {Object} keyed map of functions to shortcut sequences
  341. */
  342. var displayShortcutList = Object(external_lodash_["mapValues"])(modifiers, function (modifier) {
  343. return function (character) {
  344. var _replacementKeyMap;
  345. var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  346. var isApple = _isApple();
  347. var replacementKeyMap = (_replacementKeyMap = {}, Object(defineProperty["a" /* default */])(_replacementKeyMap, ALT, isApple ? '⌥' : 'Alt'), Object(defineProperty["a" /* default */])(_replacementKeyMap, CTRL, isApple ? '^' : 'Ctrl'), Object(defineProperty["a" /* default */])(_replacementKeyMap, COMMAND, '⌘'), Object(defineProperty["a" /* default */])(_replacementKeyMap, SHIFT, isApple ? '⇧' : 'Shift'), _replacementKeyMap);
  348. var modifierKeys = modifier(_isApple).reduce(function (accumulator, key) {
  349. var replacementKey = Object(external_lodash_["get"])(replacementKeyMap, key, key); // If on the Mac, adhere to platform convention and don't show plus between keys.
  350. if (isApple) {
  351. return [].concat(Object(toConsumableArray["a" /* default */])(accumulator), [replacementKey]);
  352. }
  353. return [].concat(Object(toConsumableArray["a" /* default */])(accumulator), [replacementKey, '+']);
  354. }, []);
  355. var capitalizedCharacter = Object(external_lodash_["capitalize"])(character);
  356. return [].concat(Object(toConsumableArray["a" /* default */])(modifierKeys), [capitalizedCharacter]);
  357. };
  358. });
  359. /**
  360. * An object that contains functions to display shortcuts.
  361. * E.g. displayShortcut.primary( 'm' ) will return '⌘M' on Mac.
  362. *
  363. * @type {Object} Keyed map of functions to display shortcuts.
  364. */
  365. var displayShortcut = Object(external_lodash_["mapValues"])(displayShortcutList, function (shortcutList) {
  366. return function (character) {
  367. var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  368. return shortcutList(character, _isApple).join('');
  369. };
  370. });
  371. /**
  372. * An object that contains functions to return an aria label for a keyboard shortcut.
  373. * E.g. shortcutAriaLabel.primary( '.' ) will return 'Command + Period' on Mac.
  374. */
  375. var shortcutAriaLabel = Object(external_lodash_["mapValues"])(modifiers, function (modifier) {
  376. return function (character) {
  377. var _replacementKeyMap2;
  378. var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  379. var isApple = _isApple();
  380. var replacementKeyMap = (_replacementKeyMap2 = {}, Object(defineProperty["a" /* default */])(_replacementKeyMap2, SHIFT, 'Shift'), Object(defineProperty["a" /* default */])(_replacementKeyMap2, COMMAND, isApple ? 'Command' : 'Control'), Object(defineProperty["a" /* default */])(_replacementKeyMap2, CTRL, 'Control'), Object(defineProperty["a" /* default */])(_replacementKeyMap2, ALT, isApple ? 'Option' : 'Alt'), Object(defineProperty["a" /* default */])(_replacementKeyMap2, ',', Object(external_this_wp_i18n_["__"])('Comma')), Object(defineProperty["a" /* default */])(_replacementKeyMap2, '.', Object(external_this_wp_i18n_["__"])('Period')), Object(defineProperty["a" /* default */])(_replacementKeyMap2, '`', Object(external_this_wp_i18n_["__"])('Backtick')), _replacementKeyMap2);
  381. return [].concat(Object(toConsumableArray["a" /* default */])(modifier(_isApple)), [character]).map(function (key) {
  382. return Object(external_lodash_["capitalize"])(Object(external_lodash_["get"])(replacementKeyMap, key, key));
  383. }).join(isApple ? ' ' : ' + ');
  384. };
  385. });
  386. /**
  387. * An object that contains functions to check if a keyboard event matches a
  388. * predefined shortcut combination.
  389. * E.g. isKeyboardEvent.primary( event, 'm' ) will return true if the event
  390. * signals pressing ⌘M.
  391. *
  392. * @type {Object} Keyed map of functions to match events.
  393. */
  394. var isKeyboardEvent = Object(external_lodash_["mapValues"])(modifiers, function (getModifiers) {
  395. return function (event, character) {
  396. var _isApple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : isAppleOS;
  397. var mods = getModifiers(_isApple);
  398. if (!mods.every(function (key) {
  399. return event["".concat(key, "Key")];
  400. })) {
  401. return false;
  402. }
  403. if (!character) {
  404. return Object(external_lodash_["includes"])(mods, event.key.toLowerCase());
  405. }
  406. return event.key === character;
  407. };
  408. });
  409. /***/ })
  410. /******/ });