PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.0
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 16.2.0, at build/keycodes/index.js

864 lines 28.4 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 ["wp","i18n"]
414 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
415 ;// CONCATENATED MODULE: ./packages/keycodes/build-module/platform.js
416 /**
417 * Return true if platform is MacOS.
418 *
419 * @param {Window?} _window window object by default; used for DI testing.
420 *
421 * @return {boolean} True if MacOS; false otherwise.
422 */
423 function isAppleOS(_window = null) {
424 if (!_window) {
425 if (typeof window === 'undefined') {
426 return false;
427 }
428
429 _window = window;
430 }
431
432 const {
433 platform
434 } = _window.navigator;
435 return platform.indexOf('Mac') !== -1 || ['iPad', 'iPhone'].includes(platform);
436 }
437
438 ;// CONCATENATED MODULE: ./packages/keycodes/build-module/index.js
439 /**
440 * Note: The order of the modifier keys in many of the [foo]Shortcut()
441 * functions in this file are intentional and should not be changed. They're
442 * designed to fit with the standard menu keyboard shortcuts shown in the
443 * user's platform.
444 *
445 * For example, on MacOS menu shortcuts will place Shift before Command, but
446 * on Windows Control will usually come first. So don't provide your own
447 * shortcut combos directly to keyboardShortcut().
448 */
449
450 /**
451 * External dependencies
452 */
453
454 /**
455 * WordPress dependencies
456 */
457
458
459 /**
460 * Internal dependencies
461 */
462
463
464 /** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
465
466 /** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
467
468 /**
469 * An object of handler functions for each of the possible modifier
470 * combinations. A handler will return a value for a given key.
471 *
472 * @template T
473 *
474 * @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler
475 */
476
477 /**
478 * @template T
479 *
480 * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler
481 */
482
483 /** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
484
485 /** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */
486
487 /**
488 * Keycode for BACKSPACE key.
489 */
490
491 const BACKSPACE = 8;
492 /**
493 * Keycode for TAB key.
494 */
495
496 const TAB = 9;
497 /**
498 * Keycode for ENTER key.
499 */
500
501 const ENTER = 13;
502 /**
503 * Keycode for ESCAPE key.
504 */
505
506 const ESCAPE = 27;
507 /**
508 * Keycode for SPACE key.
509 */
510
511 const SPACE = 32;
512 /**
513 * Keycode for PAGEUP key.
514 */
515
516 const PAGEUP = 33;
517 /**
518 * Keycode for PAGEDOWN key.
519 */
520
521 const PAGEDOWN = 34;
522 /**
523 * Keycode for END key.
524 */
525
526 const END = 35;
527 /**
528 * Keycode for HOME key.
529 */
530
531 const HOME = 36;
532 /**
533 * Keycode for LEFT key.
534 */
535
536 const LEFT = 37;
537 /**
538 * Keycode for UP key.
539 */
540
541 const UP = 38;
542 /**
543 * Keycode for RIGHT key.
544 */
545
546 const RIGHT = 39;
547 /**
548 * Keycode for DOWN key.
549 */
550
551 const DOWN = 40;
552 /**
553 * Keycode for DELETE key.
554 */
555
556 const DELETE = 46;
557 /**
558 * Keycode for F10 key.
559 */
560
561 const F10 = 121;
562 /**
563 * Keycode for ALT key.
564 */
565
566 const ALT = 'alt';
567 /**
568 * Keycode for CTRL key.
569 */
570
571 const CTRL = 'ctrl';
572 /**
573 * Keycode for COMMAND/META key.
574 */
575
576 const COMMAND = 'meta';
577 /**
578 * Keycode for SHIFT key.
579 */
580
581 const SHIFT = 'shift';
582 /**
583 * Keycode for ZERO key.
584 */
585
586 const ZERO = 48;
587
588 /**
589 * Map the values of an object with a specified callback and return the result object.
590 *
591 * @template {{ [s: string]: any; } | ArrayLike<any>} T
592 *
593 * @param {T} object Object to map values of.
594 * @param {( value: any ) => any} mapFn Mapping function
595 *
596 * @return {any} Active modifier constants.
597 */
598
599 function mapValues(object, mapFn) {
600 return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, mapFn(value)]));
601 }
602 /**
603 * Object that contains functions that return the available modifier
604 * depending on platform.
605 *
606 * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}
607 */
608
609
610 const modifiers = {
611 primary: _isApple => _isApple() ? [COMMAND] : [CTRL],
612 primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT],
613 primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT],
614 secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT],
615 access: _isApple => _isApple() ? [CTRL, ALT] : [SHIFT, ALT],
616 ctrl: () => [CTRL],
617 alt: () => [ALT],
618 ctrlShift: () => [CTRL, SHIFT],
619 shift: () => [SHIFT],
620 shiftAlt: () => [SHIFT, ALT],
621 undefined: () => []
622 };
623 /**
624 * An object that contains functions to get raw shortcuts.
625 *
626 * These are intended for user with the KeyboardShortcuts.
627 *
628 * @example
629 * ```js
630 * // Assuming macOS:
631 * rawShortcut.primary( 'm' )
632 * // "meta+m""
633 * ```
634 *
635 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
636 * shortcuts.
637 */
638
639 const rawShortcut = mapValues(modifiers, (
640 /** @type {WPModifier} */
641 modifier) => {
642 return (
643 /** @type {WPKeyHandler<string>} */
644 (character, _isApple = isAppleOS) => {
645 return [...modifier(_isApple), character.toLowerCase()].join('+');
646 }
647 );
648 });
649 /**
650 * Return an array of the parts of a keyboard shortcut chord for display.
651 *
652 * @example
653 * ```js
654 * // Assuming macOS:
655 * displayShortcutList.primary( 'm' );
656 * // [ "⌘", "M" ]
657 * ```
658 *
659 * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
660 * shortcut sequences.
661 */
662
663 const displayShortcutList = mapValues(modifiers, (
664 /** @type {WPModifier} */
665 modifier) => {
666 return (
667 /** @type {WPKeyHandler<string[]>} */
668 (character, _isApple = isAppleOS) => {
669 const isApple = _isApple();
670
671 const replacementKeyMap = {
672 [ALT]: isApple ? '⌥' : 'Alt',
673 [CTRL]: isApple ? '⌃' : 'Ctrl',
674 // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
675 [COMMAND]: '⌘',
676 [SHIFT]: isApple ? '⇧' : 'Shift'
677 };
678 const modifierKeys = modifier(_isApple).reduce((accumulator, key) => {
679 var _replacementKeyMap$ke;
680
681 const replacementKey = (_replacementKeyMap$ke = replacementKeyMap[key]) !== null && _replacementKeyMap$ke !== void 0 ? _replacementKeyMap$ke : key; // If on the Mac, adhere to platform convention and don't show plus between keys.
682
683 if (isApple) {
684 return [...accumulator, replacementKey];
685 }
686
687 return [...accumulator, replacementKey, '+'];
688 },
689 /** @type {string[]} */
690 []); // Symbols (~`,.) are removed by the default regular expression,
691 // so override the rule to allow symbols used for shortcuts.
692 // see: https://github.com/blakeembrey/change-case#options
693
694 const capitalizedCharacter = capitalCase(character, {
695 stripRegexp: /[^A-Z0-9~`,\.\\\-]/gi
696 });
697 return [...modifierKeys, capitalizedCharacter];
698 }
699 );
700 });
701 /**
702 * An object that contains functions to display shortcuts.
703 *
704 * @example
705 * ```js
706 * // Assuming macOS:
707 * displayShortcut.primary( 'm' );
708 * // "⌘M"
709 * ```
710 *
711 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
712 * display shortcuts.
713 */
714
715 const displayShortcut = mapValues(displayShortcutList, (
716 /** @type {WPKeyHandler<string[]>} */
717 shortcutList) => {
718 return (
719 /** @type {WPKeyHandler<string>} */
720 (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('')
721 );
722 });
723 /**
724 * An object that contains functions to return an aria label for a keyboard
725 * shortcut.
726 *
727 * @example
728 * ```js
729 * // Assuming macOS:
730 * shortcutAriaLabel.primary( '.' );
731 * // "Command + Period"
732 * ```
733 *
734 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
735 * shortcut ARIA labels.
736 */
737
738 const shortcutAriaLabel = mapValues(modifiers, (
739 /** @type {WPModifier} */
740 modifier) => {
741 return (
742 /** @type {WPKeyHandler<string>} */
743 (character, _isApple = isAppleOS) => {
744 const isApple = _isApple();
745 /** @type {Record<string,string>} */
746
747
748 const replacementKeyMap = {
749 [SHIFT]: 'Shift',
750 [COMMAND]: isApple ? 'Command' : 'Control',
751 [CTRL]: 'Control',
752 [ALT]: isApple ? 'Option' : 'Alt',
753
754 /* translators: comma as in the character ',' */
755 ',': (0,external_wp_i18n_namespaceObject.__)('Comma'),
756
757 /* translators: period as in the character '.' */
758 '.': (0,external_wp_i18n_namespaceObject.__)('Period'),
759
760 /* translators: backtick as in the character '`' */
761 '`': (0,external_wp_i18n_namespaceObject.__)('Backtick'),
762
763 /* translators: tilde as in the character '~' */
764 '~': (0,external_wp_i18n_namespaceObject.__)('Tilde')
765 };
766 return [...modifier(_isApple), character].map(key => {
767 var _replacementKeyMap$ke2;
768
769 return capitalCase((_replacementKeyMap$ke2 = replacementKeyMap[key]) !== null && _replacementKeyMap$ke2 !== void 0 ? _replacementKeyMap$ke2 : key);
770 }).join(isApple ? ' ' : ' + ');
771 }
772 );
773 });
774 /**
775 * From a given KeyboardEvent, returns an array of active modifier constants for
776 * the event.
777 *
778 * @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event.
779 *
780 * @return {Array<WPModifierPart>} Active modifier constants.
781 */
782
783 function getEventModifiers(event) {
784 return (
785 /** @type {WPModifierPart[]} */
786 [ALT, CTRL, COMMAND, SHIFT].filter(key => event[
787 /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
788 `${key}Key`])
789 );
790 }
791 /**
792 * An object that contains functions to check if a keyboard event matches a
793 * predefined shortcut combination.
794 *
795 * @example
796 * ```js
797 * // Assuming an event for ⌘M key press:
798 * isKeyboardEvent.primary( event, 'm' );
799 * // true
800 * ```
801 *
802 * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
803 * to match events.
804 */
805
806
807 const isKeyboardEvent = mapValues(modifiers, (
808 /** @type {WPModifier} */
809 getModifiers) => {
810 return (
811 /** @type {WPEventKeyHandler} */
812 (event, character, _isApple = isAppleOS) => {
813 const mods = getModifiers(_isApple);
814 const eventMods = getEventModifiers(event);
815 /** @type {Record<string,string>} */
816
817 const replacementWithShiftKeyMap = {
818 Comma: ',',
819 Backslash: '\\',
820 // Windows returns `\` for both IntlRo and IntlYen.
821 IntlRo: '\\',
822 IntlYen: '\\'
823 };
824 const modsDiff = mods.filter(mod => !eventMods.includes(mod));
825 const eventModsDiff = eventMods.filter(mod => !mods.includes(mod));
826
827 if (modsDiff.length > 0 || eventModsDiff.length > 0) {
828 return false;
829 }
830
831 let key = event.key.toLowerCase();
832
833 if (!character) {
834 return mods.includes(
835 /** @type {WPModifierPart} */
836 key);
837 }
838
839 if (event.altKey && character.length === 1) {
840 key = String.fromCharCode(event.keyCode).toLowerCase();
841 } // `event.key` returns the value of the key pressed, taking into the state of
842 // modifier keys such as `Shift`. If the shift key is pressed, a different
843 // value may be returned depending on the keyboard layout. It is necessary to
844 // convert to the physical key value that don't take into account keyboard
845 // layout or modifier key state.
846
847
848 if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) {
849 key = replacementWithShiftKeyMap[event.code];
850 } // For backwards compatibility.
851
852
853 if (character === 'del') {
854 character = 'delete';
855 }
856
857 return key === character.toLowerCase();
858 }
859 );
860 });
861
862 (window.wp = window.wp || {}).keycodes = __webpack_exports__;
863 /******/ })()
864 ;