keycodes.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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. "isAppleOS": function() { return /* reexport */ isAppleOS; },
  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. ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
  70. /*! *****************************************************************************
  71. Copyright (c) Microsoft Corporation.
  72. Permission to use, copy, modify, and/or distribute this software for any
  73. purpose with or without fee is hereby granted.
  74. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  75. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  76. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  77. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  78. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  79. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  80. PERFORMANCE OF THIS SOFTWARE.
  81. ***************************************************************************** */
  82. /* global Reflect, Promise */
  83. var extendStatics = function(d, b) {
  84. extendStatics = Object.setPrototypeOf ||
  85. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  86. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  87. return extendStatics(d, b);
  88. };
  89. function __extends(d, b) {
  90. if (typeof b !== "function" && b !== null)
  91. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  92. extendStatics(d, b);
  93. function __() { this.constructor = d; }
  94. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  95. }
  96. var __assign = function() {
  97. __assign = Object.assign || function __assign(t) {
  98. for (var s, i = 1, n = arguments.length; i < n; i++) {
  99. s = arguments[i];
  100. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  101. }
  102. return t;
  103. }
  104. return __assign.apply(this, arguments);
  105. }
  106. function __rest(s, e) {
  107. var t = {};
  108. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  109. t[p] = s[p];
  110. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  111. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  112. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  113. t[p[i]] = s[p[i]];
  114. }
  115. return t;
  116. }
  117. function __decorate(decorators, target, key, desc) {
  118. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  119. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  120. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  121. return c > 3 && r && Object.defineProperty(target, key, r), r;
  122. }
  123. function __param(paramIndex, decorator) {
  124. return function (target, key) { decorator(target, key, paramIndex); }
  125. }
  126. function __metadata(metadataKey, metadataValue) {
  127. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  128. }
  129. function __awaiter(thisArg, _arguments, P, generator) {
  130. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  131. return new (P || (P = Promise))(function (resolve, reject) {
  132. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  133. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  134. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  135. step((generator = generator.apply(thisArg, _arguments || [])).next());
  136. });
  137. }
  138. function __generator(thisArg, body) {
  139. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  140. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  141. function verb(n) { return function (v) { return step([n, v]); }; }
  142. function step(op) {
  143. if (f) throw new TypeError("Generator is already executing.");
  144. while (_) try {
  145. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  146. if (y = 0, t) op = [op[0] & 2, t.value];
  147. switch (op[0]) {
  148. case 0: case 1: t = op; break;
  149. case 4: _.label++; return { value: op[1], done: false };
  150. case 5: _.label++; y = op[1]; op = [0]; continue;
  151. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  152. default:
  153. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  154. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  155. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  156. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  157. if (t[2]) _.ops.pop();
  158. _.trys.pop(); continue;
  159. }
  160. op = body.call(thisArg, _);
  161. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  162. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  163. }
  164. }
  165. var __createBinding = Object.create ? (function(o, m, k, k2) {
  166. if (k2 === undefined) k2 = k;
  167. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  168. }) : (function(o, m, k, k2) {
  169. if (k2 === undefined) k2 = k;
  170. o[k2] = m[k];
  171. });
  172. function __exportStar(m, o) {
  173. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
  174. }
  175. function __values(o) {
  176. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  177. if (m) return m.call(o);
  178. if (o && typeof o.length === "number") return {
  179. next: function () {
  180. if (o && i >= o.length) o = void 0;
  181. return { value: o && o[i++], done: !o };
  182. }
  183. };
  184. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  185. }
  186. function __read(o, n) {
  187. var m = typeof Symbol === "function" && o[Symbol.iterator];
  188. if (!m) return o;
  189. var i = m.call(o), r, ar = [], e;
  190. try {
  191. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  192. }
  193. catch (error) { e = { error: error }; }
  194. finally {
  195. try {
  196. if (r && !r.done && (m = i["return"])) m.call(i);
  197. }
  198. finally { if (e) throw e.error; }
  199. }
  200. return ar;
  201. }
  202. /** @deprecated */
  203. function __spread() {
  204. for (var ar = [], i = 0; i < arguments.length; i++)
  205. ar = ar.concat(__read(arguments[i]));
  206. return ar;
  207. }
  208. /** @deprecated */
  209. function __spreadArrays() {
  210. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  211. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  212. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  213. r[k] = a[j];
  214. return r;
  215. }
  216. function __spreadArray(to, from, pack) {
  217. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  218. if (ar || !(i in from)) {
  219. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  220. ar[i] = from[i];
  221. }
  222. }
  223. return to.concat(ar || Array.prototype.slice.call(from));
  224. }
  225. function __await(v) {
  226. return this instanceof __await ? (this.v = v, this) : new __await(v);
  227. }
  228. function __asyncGenerator(thisArg, _arguments, generator) {
  229. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  230. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  231. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  232. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  233. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  234. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  235. function fulfill(value) { resume("next", value); }
  236. function reject(value) { resume("throw", value); }
  237. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  238. }
  239. function __asyncDelegator(o) {
  240. var i, p;
  241. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  242. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  243. }
  244. function __asyncValues(o) {
  245. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  246. var m = o[Symbol.asyncIterator], i;
  247. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  248. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  249. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  250. }
  251. function __makeTemplateObject(cooked, raw) {
  252. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  253. return cooked;
  254. };
  255. var __setModuleDefault = Object.create ? (function(o, v) {
  256. Object.defineProperty(o, "default", { enumerable: true, value: v });
  257. }) : function(o, v) {
  258. o["default"] = v;
  259. };
  260. function __importStar(mod) {
  261. if (mod && mod.__esModule) return mod;
  262. var result = {};
  263. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  264. __setModuleDefault(result, mod);
  265. return result;
  266. }
  267. function __importDefault(mod) {
  268. return (mod && mod.__esModule) ? mod : { default: mod };
  269. }
  270. function __classPrivateFieldGet(receiver, state, kind, f) {
  271. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
  272. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  273. return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
  274. }
  275. function __classPrivateFieldSet(receiver, state, value, kind, f) {
  276. if (kind === "m") throw new TypeError("Private method is not writable");
  277. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
  278. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  279. return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
  280. }
  281. ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
  282. /**
  283. * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
  284. */
  285. var SUPPORTED_LOCALE = {
  286. tr: {
  287. regexp: /\u0130|\u0049|\u0049\u0307/g,
  288. map: {
  289. İ: "\u0069",
  290. I: "\u0131",
  291. İ: "\u0069",
  292. },
  293. },
  294. az: {
  295. regexp: /\u0130/g,
  296. map: {
  297. İ: "\u0069",
  298. I: "\u0131",
  299. İ: "\u0069",
  300. },
  301. },
  302. lt: {
  303. regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
  304. map: {
  305. I: "\u0069\u0307",
  306. J: "\u006A\u0307",
  307. Į: "\u012F\u0307",
  308. Ì: "\u0069\u0307\u0300",
  309. Í: "\u0069\u0307\u0301",
  310. Ĩ: "\u0069\u0307\u0303",
  311. },
  312. },
  313. };
  314. /**
  315. * Localized lower case.
  316. */
  317. function localeLowerCase(str, locale) {
  318. var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
  319. if (lang)
  320. return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
  321. return lowerCase(str);
  322. }
  323. /**
  324. * Lower case as a function.
  325. */
  326. function lowerCase(str) {
  327. return str.toLowerCase();
  328. }
  329. ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
  330. // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
  331. var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
  332. // Remove all non-word characters.
  333. var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
  334. /**
  335. * Normalize the string into something other libraries can manipulate easier.
  336. */
  337. function noCase(input, options) {
  338. if (options === void 0) { options = {}; }
  339. var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
  340. var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
  341. var start = 0;
  342. var end = result.length;
  343. // Trim the delimiter from around the output string.
  344. while (result.charAt(start) === "\0")
  345. start++;
  346. while (result.charAt(end - 1) === "\0")
  347. end--;
  348. // Transform each token independently.
  349. return result.slice(start, end).split("\0").map(transform).join(delimiter);
  350. }
  351. /**
  352. * Replace `re` in the input string with the replacement value.
  353. */
  354. function replace(input, re, value) {
  355. if (re instanceof RegExp)
  356. return input.replace(re, value);
  357. return re.reduce(function (input, re) { return input.replace(re, value); }, input);
  358. }
  359. ;// CONCATENATED MODULE: ./node_modules/upper-case-first/dist.es2015/index.js
  360. /**
  361. * Upper case the first character of an input string.
  362. */
  363. function upperCaseFirst(input) {
  364. return input.charAt(0).toUpperCase() + input.substr(1);
  365. }
  366. ;// CONCATENATED MODULE: ./node_modules/capital-case/dist.es2015/index.js
  367. function capitalCaseTransform(input) {
  368. return upperCaseFirst(input.toLowerCase());
  369. }
  370. function capitalCase(input, options) {
  371. if (options === void 0) { options = {}; }
  372. return noCase(input, __assign({ delimiter: " ", transform: capitalCaseTransform }, options));
  373. }
  374. ;// CONCATENATED MODULE: external "lodash"
  375. var external_lodash_namespaceObject = window["lodash"];
  376. ;// CONCATENATED MODULE: external ["wp","i18n"]
  377. var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  378. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js
  379. /**
  380. * External dependencies
  381. */
  382. /**
  383. * Return true if platform is MacOS.
  384. *
  385. * @param {Window?} _window window object by default; used for DI testing.
  386. *
  387. * @return {boolean} True if MacOS; false otherwise.
  388. */
  389. function isAppleOS() {
  390. let _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  391. if (!_window) {
  392. if (typeof window === 'undefined') {
  393. return false;
  394. }
  395. _window = window;
  396. }
  397. const {
  398. platform
  399. } = _window.navigator;
  400. return platform.indexOf('Mac') !== -1 || (0,external_lodash_namespaceObject.includes)(['iPad', 'iPhone'], platform);
  401. }
  402. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js
  403. /**
  404. * Note: The order of the modifier keys in many of the [foo]Shortcut()
  405. * functions in this file are intentional and should not be changed. They're
  406. * designed to fit with the standard menu keyboard shortcuts shown in the
  407. * user's platform.
  408. *
  409. * For example, on MacOS menu shortcuts will place Shift before Command, but
  410. * on Windows Control will usually come first. So don't provide your own
  411. * shortcut combos directly to keyboardShortcut().
  412. */
  413. /**
  414. * External dependencies
  415. */
  416. /**
  417. * WordPress dependencies
  418. */
  419. /**
  420. * Internal dependencies
  421. */
  422. /** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
  423. /** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
  424. /**
  425. * An object of handler functions for each of the possible modifier
  426. * combinations. A handler will return a value for a given key.
  427. *
  428. * @template T
  429. *
  430. * @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler
  431. */
  432. /**
  433. * @template T
  434. *
  435. * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler
  436. */
  437. /** @typedef {(event: KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
  438. /**
  439. * Keycode for BACKSPACE key.
  440. */
  441. const BACKSPACE = 8;
  442. /**
  443. * Keycode for TAB key.
  444. */
  445. const TAB = 9;
  446. /**
  447. * Keycode for ENTER key.
  448. */
  449. const ENTER = 13;
  450. /**
  451. * Keycode for ESCAPE key.
  452. */
  453. const ESCAPE = 27;
  454. /**
  455. * Keycode for SPACE key.
  456. */
  457. const SPACE = 32;
  458. /**
  459. * Keycode for PAGEUP key.
  460. */
  461. const PAGEUP = 33;
  462. /**
  463. * Keycode for PAGEDOWN key.
  464. */
  465. const PAGEDOWN = 34;
  466. /**
  467. * Keycode for END key.
  468. */
  469. const END = 35;
  470. /**
  471. * Keycode for HOME key.
  472. */
  473. const HOME = 36;
  474. /**
  475. * Keycode for LEFT key.
  476. */
  477. const LEFT = 37;
  478. /**
  479. * Keycode for UP key.
  480. */
  481. const UP = 38;
  482. /**
  483. * Keycode for RIGHT key.
  484. */
  485. const RIGHT = 39;
  486. /**
  487. * Keycode for DOWN key.
  488. */
  489. const DOWN = 40;
  490. /**
  491. * Keycode for DELETE key.
  492. */
  493. const DELETE = 46;
  494. /**
  495. * Keycode for F10 key.
  496. */
  497. const F10 = 121;
  498. /**
  499. * Keycode for ALT key.
  500. */
  501. const ALT = 'alt';
  502. /**
  503. * Keycode for CTRL key.
  504. */
  505. const CTRL = 'ctrl';
  506. /**
  507. * Keycode for COMMAND/META key.
  508. */
  509. const COMMAND = 'meta';
  510. /**
  511. * Keycode for SHIFT key.
  512. */
  513. const SHIFT = 'shift';
  514. /**
  515. * Keycode for ZERO key.
  516. */
  517. const ZERO = 48;
  518. /**
  519. * Object that contains functions that return the available modifier
  520. * depending on platform.
  521. *
  522. * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}
  523. */
  524. const modifiers = {
  525. primary: _isApple => _isApple() ? [COMMAND] : [CTRL],
  526. primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT],
  527. primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT],
  528. secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT],
  529. access: _isApple => _isApple() ? [CTRL, ALT] : [SHIFT, ALT],
  530. ctrl: () => [CTRL],
  531. alt: () => [ALT],
  532. ctrlShift: () => [CTRL, SHIFT],
  533. shift: () => [SHIFT],
  534. shiftAlt: () => [SHIFT, ALT],
  535. undefined: () => []
  536. };
  537. /**
  538. * An object that contains functions to get raw shortcuts.
  539. *
  540. * These are intended for user with the KeyboardShortcuts.
  541. *
  542. * @example
  543. * ```js
  544. * // Assuming macOS:
  545. * rawShortcut.primary( 'm' )
  546. * // "meta+m""
  547. * ```
  548. *
  549. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
  550. * shortcuts.
  551. */
  552. const rawShortcut = (0,external_lodash_namespaceObject.mapValues)(modifiers, modifier => {
  553. return (
  554. /** @type {WPKeyHandler<string>} */
  555. function (character) {
  556. let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  557. return [...modifier(_isApple), character.toLowerCase()].join('+');
  558. }
  559. );
  560. });
  561. /**
  562. * Return an array of the parts of a keyboard shortcut chord for display.
  563. *
  564. * @example
  565. * ```js
  566. * // Assuming macOS:
  567. * displayShortcutList.primary( 'm' );
  568. * // [ "⌘", "M" ]
  569. * ```
  570. *
  571. * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
  572. * shortcut sequences.
  573. */
  574. const displayShortcutList = (0,external_lodash_namespaceObject.mapValues)(modifiers, modifier => {
  575. return (
  576. /** @type {WPKeyHandler<string[]>} */
  577. function (character) {
  578. let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  579. const isApple = _isApple();
  580. const replacementKeyMap = {
  581. [ALT]: isApple ? '⌥' : 'Alt',
  582. [CTRL]: isApple ? '⌃' : 'Ctrl',
  583. // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
  584. [COMMAND]: '⌘',
  585. [SHIFT]: isApple ? '⇧' : 'Shift'
  586. };
  587. const modifierKeys = modifier(_isApple).reduce((accumulator, key) => {
  588. 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.
  589. if (isApple) {
  590. return [...accumulator, replacementKey];
  591. }
  592. return [...accumulator, replacementKey, '+'];
  593. },
  594. /** @type {string[]} */
  595. []); // Symbols (`,.) are removed by the default regular expression,
  596. // so override the rule to allow symbols used for shortcuts.
  597. // see: https://github.com/blakeembrey/change-case#options
  598. const capitalizedCharacter = capitalCase(character, {
  599. stripRegexp: /[^A-Z0-9`,\.]/gi
  600. });
  601. return [...modifierKeys, capitalizedCharacter];
  602. }
  603. );
  604. });
  605. /**
  606. * An object that contains functions to display shortcuts.
  607. *
  608. * @example
  609. * ```js
  610. * // Assuming macOS:
  611. * displayShortcut.primary( 'm' );
  612. * // "⌘M"
  613. * ```
  614. *
  615. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
  616. * display shortcuts.
  617. */
  618. const displayShortcut = (0,external_lodash_namespaceObject.mapValues)(displayShortcutList, shortcutList => {
  619. return (
  620. /** @type {WPKeyHandler<string>} */
  621. function (character) {
  622. let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  623. return shortcutList(character, _isApple).join('');
  624. }
  625. );
  626. });
  627. /**
  628. * An object that contains functions to return an aria label for a keyboard
  629. * shortcut.
  630. *
  631. * @example
  632. * ```js
  633. * // Assuming macOS:
  634. * shortcutAriaLabel.primary( '.' );
  635. * // "Command + Period"
  636. * ```
  637. *
  638. * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
  639. * shortcut ARIA labels.
  640. */
  641. const shortcutAriaLabel = (0,external_lodash_namespaceObject.mapValues)(modifiers, modifier => {
  642. return (
  643. /** @type {WPKeyHandler<string>} */
  644. function (character) {
  645. let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
  646. const isApple = _isApple();
  647. const replacementKeyMap = {
  648. [SHIFT]: 'Shift',
  649. [COMMAND]: isApple ? 'Command' : 'Control',
  650. [CTRL]: 'Control',
  651. [ALT]: isApple ? 'Option' : 'Alt',
  652. /* translators: comma as in the character ',' */
  653. ',': (0,external_wp_i18n_namespaceObject.__)('Comma'),
  654. /* translators: period as in the character '.' */
  655. '.': (0,external_wp_i18n_namespaceObject.__)('Period'),
  656. /* translators: backtick as in the character '`' */
  657. '`': (0,external_wp_i18n_namespaceObject.__)('Backtick')
  658. };
  659. return [...modifier(_isApple), character].map(key => capitalCase((0,external_lodash_namespaceObject.get)(replacementKeyMap, key, key))).join(isApple ? ' ' : ' + ');
  660. }
  661. );
  662. });
  663. /**
  664. * From a given KeyboardEvent, returns an array of active modifier constants for
  665. * the event.
  666. *
  667. * @param {KeyboardEvent} event Keyboard event.
  668. *
  669. * @return {Array<WPModifierPart>} Active modifier constants.
  670. */
  671. function getEventModifiers(event) {
  672. return (
  673. /** @type {WPModifierPart[]} */
  674. [ALT, CTRL, COMMAND, SHIFT].filter(key => event[
  675. /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
  676. `${key}Key`])
  677. );
  678. }
  679. /**
  680. * An object that contains functions to check if a keyboard event matches a
  681. * predefined shortcut combination.
  682. *
  683. * @example
  684. * ```js
  685. * // Assuming an event for ⌘M key press:
  686. * isKeyboardEvent.primary( event, 'm' );
  687. * // true
  688. * ```
  689. *
  690. * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
  691. * to match events.
  692. */
  693. const isKeyboardEvent = (0,external_lodash_namespaceObject.mapValues)(modifiers, getModifiers => {
  694. return (
  695. /** @type {WPEventKeyHandler} */
  696. function (event, character) {
  697. let _isApple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : isAppleOS;
  698. const mods = getModifiers(_isApple);
  699. const eventMods = getEventModifiers(event);
  700. const modsDiff = mods.filter(mod => !eventMods.includes(mod));
  701. const eventModsDiff = eventMods.filter(mod => !mods.includes(mod));
  702. if (modsDiff.length > 0 || eventModsDiff.length > 0) {
  703. return false;
  704. }
  705. let key = event.key.toLowerCase();
  706. if (!character) {
  707. return (0,external_lodash_namespaceObject.includes)(mods, key);
  708. }
  709. if (event.altKey && character.length === 1) {
  710. key = String.fromCharCode(event.keyCode).toLowerCase();
  711. } // For backwards compatibility.
  712. if (character === 'del') {
  713. character = 'delete';
  714. }
  715. return key === character.toLowerCase();
  716. }
  717. );
  718. });
  719. (window.wp = window.wp || {}).keycodes = __webpack_exports__;
  720. /******/ })()
  721. ;