PluginProbe
Gutenberg / 13.9.0
Gutenberg v13.9.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 12.6.0 All 403 releases
gutenberg / build / keycodes / index.js

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

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