PluginProbe
Gutenberg / 11.6.0
Gutenberg v11.6.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 11.6.0, at build/keycodes/index.js

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