PluginProbe
Gutenberg / 21.7.0
Gutenberg v21.7.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 21.7.0, at build/keycodes/index.js

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