PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
gutenberg / build / keycodes / index.js

index.js in Gutenberg 14.5.2, at build/keycodes/index.js

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