1 /******/ (function() { // webpackBootstrap |
1 /******/ (() => { // webpackBootstrap |
2 /******/ "use strict"; |
2 /******/ "use strict"; |
3 /******/ // The require scope |
3 /******/ // The require scope |
4 /******/ var __webpack_require__ = {}; |
4 /******/ var __webpack_require__ = {}; |
5 /******/ |
5 /******/ |
6 /************************************************************************/ |
6 /************************************************************************/ |
7 /******/ /* webpack/runtime/define property getters */ |
7 /******/ /* webpack/runtime/define property getters */ |
8 /******/ !function() { |
8 /******/ (() => { |
9 /******/ // define getter functions for harmony exports |
9 /******/ // define getter functions for harmony exports |
10 /******/ __webpack_require__.d = function(exports, definition) { |
10 /******/ __webpack_require__.d = (exports, definition) => { |
11 /******/ for(var key in definition) { |
11 /******/ for(var key in definition) { |
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
14 /******/ } |
14 /******/ } |
15 /******/ } |
15 /******/ } |
16 /******/ }; |
16 /******/ }; |
17 /******/ }(); |
17 /******/ })(); |
18 /******/ |
18 /******/ |
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
20 /******/ !function() { |
20 /******/ (() => { |
21 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
22 /******/ }(); |
22 /******/ })(); |
23 /******/ |
23 /******/ |
24 /******/ /* webpack/runtime/make namespace object */ |
24 /******/ /* webpack/runtime/make namespace object */ |
25 /******/ !function() { |
25 /******/ (() => { |
26 /******/ // define __esModule on exports |
26 /******/ // define __esModule on exports |
27 /******/ __webpack_require__.r = function(exports) { |
27 /******/ __webpack_require__.r = (exports) => { |
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
30 /******/ } |
30 /******/ } |
31 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
31 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
32 /******/ }; |
32 /******/ }; |
33 /******/ }(); |
33 /******/ })(); |
34 /******/ |
34 /******/ |
35 /************************************************************************/ |
35 /************************************************************************/ |
36 var __webpack_exports__ = {}; |
36 var __webpack_exports__ = {}; |
37 // ESM COMPAT FLAG |
37 // ESM COMPAT FLAG |
38 __webpack_require__.r(__webpack_exports__); |
38 __webpack_require__.r(__webpack_exports__); |
39 |
39 |
40 // EXPORTS |
40 // EXPORTS |
41 __webpack_require__.d(__webpack_exports__, { |
41 __webpack_require__.d(__webpack_exports__, { |
42 "ALT": function() { return /* binding */ ALT; }, |
42 ALT: () => (/* binding */ ALT), |
43 "BACKSPACE": function() { return /* binding */ BACKSPACE; }, |
43 BACKSPACE: () => (/* binding */ BACKSPACE), |
44 "COMMAND": function() { return /* binding */ COMMAND; }, |
44 COMMAND: () => (/* binding */ COMMAND), |
45 "CTRL": function() { return /* binding */ CTRL; }, |
45 CTRL: () => (/* binding */ CTRL), |
46 "DELETE": function() { return /* binding */ DELETE; }, |
46 DELETE: () => (/* binding */ DELETE), |
47 "DOWN": function() { return /* binding */ DOWN; }, |
47 DOWN: () => (/* binding */ DOWN), |
48 "END": function() { return /* binding */ END; }, |
48 END: () => (/* binding */ END), |
49 "ENTER": function() { return /* binding */ ENTER; }, |
49 ENTER: () => (/* binding */ ENTER), |
50 "ESCAPE": function() { return /* binding */ ESCAPE; }, |
50 ESCAPE: () => (/* binding */ ESCAPE), |
51 "F10": function() { return /* binding */ F10; }, |
51 F10: () => (/* binding */ F10), |
52 "HOME": function() { return /* binding */ HOME; }, |
52 HOME: () => (/* binding */ HOME), |
53 "LEFT": function() { return /* binding */ LEFT; }, |
53 LEFT: () => (/* binding */ LEFT), |
54 "PAGEDOWN": function() { return /* binding */ PAGEDOWN; }, |
54 PAGEDOWN: () => (/* binding */ PAGEDOWN), |
55 "PAGEUP": function() { return /* binding */ PAGEUP; }, |
55 PAGEUP: () => (/* binding */ PAGEUP), |
56 "RIGHT": function() { return /* binding */ RIGHT; }, |
56 RIGHT: () => (/* binding */ RIGHT), |
57 "SHIFT": function() { return /* binding */ SHIFT; }, |
57 SHIFT: () => (/* binding */ SHIFT), |
58 "SPACE": function() { return /* binding */ SPACE; }, |
58 SPACE: () => (/* binding */ SPACE), |
59 "TAB": function() { return /* binding */ TAB; }, |
59 TAB: () => (/* binding */ TAB), |
60 "UP": function() { return /* binding */ UP; }, |
60 UP: () => (/* binding */ UP), |
61 "ZERO": function() { return /* binding */ ZERO; }, |
61 ZERO: () => (/* binding */ ZERO), |
62 "displayShortcut": function() { return /* binding */ displayShortcut; }, |
62 displayShortcut: () => (/* binding */ displayShortcut), |
63 "displayShortcutList": function() { return /* binding */ displayShortcutList; }, |
63 displayShortcutList: () => (/* binding */ displayShortcutList), |
64 "isKeyboardEvent": function() { return /* binding */ isKeyboardEvent; }, |
64 isAppleOS: () => (/* reexport */ isAppleOS), |
65 "modifiers": function() { return /* binding */ modifiers; }, |
65 isKeyboardEvent: () => (/* binding */ isKeyboardEvent), |
66 "rawShortcut": function() { return /* binding */ rawShortcut; }, |
66 modifiers: () => (/* binding */ modifiers), |
67 "shortcutAriaLabel": function() { return /* binding */ shortcutAriaLabel; } |
67 rawShortcut: () => (/* binding */ rawShortcut), |
68 }); |
68 shortcutAriaLabel: () => (/* binding */ shortcutAriaLabel) |
69 |
69 }); |
70 ;// CONCATENATED MODULE: external "lodash" |
70 |
71 var external_lodash_namespaceObject = window["lodash"]; |
|
72 ;// CONCATENATED MODULE: external ["wp","i18n"] |
71 ;// CONCATENATED MODULE: external ["wp","i18n"] |
73 var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
72 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
74 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js |
73 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js |
75 /** |
74 /** |
76 * External dependencies |
|
77 */ |
|
78 |
|
79 /** |
|
80 * Return true if platform is MacOS. |
75 * Return true if platform is MacOS. |
81 * |
76 * |
82 * @param {Window?} _window window object by default; used for DI testing. |
77 * @param {Window?} _window window object by default; used for DI testing. |
83 * |
78 * |
84 * @return {boolean} True if MacOS; false otherwise. |
79 * @return {boolean} True if MacOS; false otherwise. |
85 */ |
80 */ |
86 |
81 function isAppleOS(_window = null) { |
87 function isAppleOS() { |
|
88 let _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; |
|
89 |
|
90 if (!_window) { |
82 if (!_window) { |
91 if (typeof window === 'undefined') { |
83 if (typeof window === 'undefined') { |
92 return false; |
84 return false; |
93 } |
85 } |
94 |
|
95 _window = window; |
86 _window = window; |
96 } |
87 } |
97 |
|
98 const { |
88 const { |
99 platform |
89 platform |
100 } = _window.navigator; |
90 } = _window.navigator; |
101 return platform.indexOf('Mac') !== -1 || (0,external_lodash_namespaceObject.includes)(['iPad', 'iPhone'], platform); |
91 return platform.indexOf('Mac') !== -1 || ['iPad', 'iPhone'].includes(platform); |
102 } |
92 } |
103 |
93 |
104 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js |
94 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js |
105 /** |
95 /** |
106 * Note: The order of the modifier keys in many of the [foo]Shortcut() |
96 * Note: The order of the modifier keys in many of the [foo]Shortcut() |
143 /** |
129 /** |
144 * @template T |
130 * @template T |
145 * |
131 * |
146 * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler |
132 * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler |
147 */ |
133 */ |
148 |
134 /** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */ |
149 /** @typedef {(event: KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */ |
135 |
|
136 /** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */ |
150 |
137 |
151 /** |
138 /** |
152 * Keycode for BACKSPACE key. |
139 * Keycode for BACKSPACE key. |
153 */ |
140 */ |
154 |
|
155 const BACKSPACE = 8; |
141 const BACKSPACE = 8; |
|
142 |
156 /** |
143 /** |
157 * Keycode for TAB key. |
144 * Keycode for TAB key. |
158 */ |
145 */ |
159 |
|
160 const TAB = 9; |
146 const TAB = 9; |
|
147 |
161 /** |
148 /** |
162 * Keycode for ENTER key. |
149 * Keycode for ENTER key. |
163 */ |
150 */ |
164 |
|
165 const ENTER = 13; |
151 const ENTER = 13; |
|
152 |
166 /** |
153 /** |
167 * Keycode for ESCAPE key. |
154 * Keycode for ESCAPE key. |
168 */ |
155 */ |
169 |
|
170 const ESCAPE = 27; |
156 const ESCAPE = 27; |
|
157 |
171 /** |
158 /** |
172 * Keycode for SPACE key. |
159 * Keycode for SPACE key. |
173 */ |
160 */ |
174 |
|
175 const SPACE = 32; |
161 const SPACE = 32; |
|
162 |
176 /** |
163 /** |
177 * Keycode for PAGEUP key. |
164 * Keycode for PAGEUP key. |
178 */ |
165 */ |
179 |
|
180 const PAGEUP = 33; |
166 const PAGEUP = 33; |
|
167 |
181 /** |
168 /** |
182 * Keycode for PAGEDOWN key. |
169 * Keycode for PAGEDOWN key. |
183 */ |
170 */ |
184 |
|
185 const PAGEDOWN = 34; |
171 const PAGEDOWN = 34; |
|
172 |
186 /** |
173 /** |
187 * Keycode for END key. |
174 * Keycode for END key. |
188 */ |
175 */ |
189 |
|
190 const END = 35; |
176 const END = 35; |
|
177 |
191 /** |
178 /** |
192 * Keycode for HOME key. |
179 * Keycode for HOME key. |
193 */ |
180 */ |
194 |
|
195 const HOME = 36; |
181 const HOME = 36; |
|
182 |
196 /** |
183 /** |
197 * Keycode for LEFT key. |
184 * Keycode for LEFT key. |
198 */ |
185 */ |
199 |
|
200 const LEFT = 37; |
186 const LEFT = 37; |
|
187 |
201 /** |
188 /** |
202 * Keycode for UP key. |
189 * Keycode for UP key. |
203 */ |
190 */ |
204 |
|
205 const UP = 38; |
191 const UP = 38; |
|
192 |
206 /** |
193 /** |
207 * Keycode for RIGHT key. |
194 * Keycode for RIGHT key. |
208 */ |
195 */ |
209 |
|
210 const RIGHT = 39; |
196 const RIGHT = 39; |
|
197 |
211 /** |
198 /** |
212 * Keycode for DOWN key. |
199 * Keycode for DOWN key. |
213 */ |
200 */ |
214 |
|
215 const DOWN = 40; |
201 const DOWN = 40; |
|
202 |
216 /** |
203 /** |
217 * Keycode for DELETE key. |
204 * Keycode for DELETE key. |
218 */ |
205 */ |
219 |
|
220 const DELETE = 46; |
206 const DELETE = 46; |
|
207 |
221 /** |
208 /** |
222 * Keycode for F10 key. |
209 * Keycode for F10 key. |
223 */ |
210 */ |
224 |
|
225 const F10 = 121; |
211 const F10 = 121; |
|
212 |
226 /** |
213 /** |
227 * Keycode for ALT key. |
214 * Keycode for ALT key. |
228 */ |
215 */ |
229 |
|
230 const ALT = 'alt'; |
216 const ALT = 'alt'; |
|
217 |
231 /** |
218 /** |
232 * Keycode for CTRL key. |
219 * Keycode for CTRL key. |
233 */ |
220 */ |
234 |
|
235 const CTRL = 'ctrl'; |
221 const CTRL = 'ctrl'; |
|
222 |
236 /** |
223 /** |
237 * Keycode for COMMAND/META key. |
224 * Keycode for COMMAND/META key. |
238 */ |
225 */ |
239 |
|
240 const COMMAND = 'meta'; |
226 const COMMAND = 'meta'; |
|
227 |
241 /** |
228 /** |
242 * Keycode for SHIFT key. |
229 * Keycode for SHIFT key. |
243 */ |
230 */ |
244 |
|
245 const SHIFT = 'shift'; |
231 const SHIFT = 'shift'; |
|
232 |
246 /** |
233 /** |
247 * Keycode for ZERO key. |
234 * Keycode for ZERO key. |
248 */ |
235 */ |
249 |
|
250 const ZERO = 48; |
236 const ZERO = 48; |
|
237 |
|
238 |
|
239 /** |
|
240 * Capitalise the first character of a string. |
|
241 * @param {string} string String to capitalise. |
|
242 * @return {string} Capitalised string. |
|
243 */ |
|
244 function capitaliseFirstCharacter(string) { |
|
245 return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1); |
|
246 } |
|
247 |
|
248 /** |
|
249 * Map the values of an object with a specified callback and return the result object. |
|
250 * |
|
251 * @template {{ [s: string]: any; } | ArrayLike<any>} T |
|
252 * |
|
253 * @param {T} object Object to map values of. |
|
254 * @param {( value: any ) => any} mapFn Mapping function |
|
255 * |
|
256 * @return {any} Active modifier constants. |
|
257 */ |
|
258 function mapValues(object, mapFn) { |
|
259 return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, mapFn(value)])); |
|
260 } |
|
261 |
251 /** |
262 /** |
252 * Object that contains functions that return the available modifier |
263 * Object that contains functions that return the available modifier |
253 * depending on platform. |
264 * depending on platform. |
254 * |
265 * |
255 * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>} |
266 * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>} |
256 */ |
267 */ |
257 |
|
258 const modifiers = { |
268 const modifiers = { |
259 primary: _isApple => _isApple() ? [COMMAND] : [CTRL], |
269 primary: _isApple => _isApple() ? [COMMAND] : [CTRL], |
260 primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT], |
270 primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT], |
261 primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT], |
271 primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT], |
262 secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT], |
272 secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT], |
305 * ``` |
311 * ``` |
306 * |
312 * |
307 * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to |
313 * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to |
308 * shortcut sequences. |
314 * shortcut sequences. |
309 */ |
315 */ |
310 |
316 const displayShortcutList = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => { |
311 const displayShortcutList = (0,external_lodash_namespaceObject.mapValues)(modifiers, modifier => { |
317 return /** @type {WPKeyHandler<string[]>} */(character, _isApple = isAppleOS) => { |
312 return ( |
318 const isApple = _isApple(); |
313 /** @type {WPKeyHandler<string[]>} */ |
319 const replacementKeyMap = { |
314 function (character) { |
320 [ALT]: isApple ? '⌥' : 'Alt', |
315 let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS; |
321 [CTRL]: isApple ? '⌃' : 'Ctrl', |
316 |
322 // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character. |
317 const isApple = _isApple(); |
323 [COMMAND]: '⌘', |
318 |
324 [SHIFT]: isApple ? '⇧' : 'Shift' |
319 const replacementKeyMap = { |
325 }; |
320 [ALT]: isApple ? '⌥' : 'Alt', |
326 const modifierKeys = modifier(_isApple).reduce((accumulator, key) => { |
321 [CTRL]: isApple ? '⌃' : 'Ctrl', |
327 var _replacementKeyMap$ke; |
322 // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character. |
328 const replacementKey = (_replacementKeyMap$ke = replacementKeyMap[key]) !== null && _replacementKeyMap$ke !== void 0 ? _replacementKeyMap$ke : key; |
323 [COMMAND]: '⌘', |
329 // If on the Mac, adhere to platform convention and don't show plus between keys. |
324 [SHIFT]: isApple ? '⇧' : 'Shift' |
330 if (isApple) { |
325 }; |
331 return [...accumulator, replacementKey]; |
326 const modifierKeys = modifier(_isApple).reduce((accumulator, key) => { |
332 } |
327 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. |
333 return [...accumulator, replacementKey, '+']; |
328 |
334 }, /** @type {string[]} */[]); |
329 if (isApple) { |
335 return [...modifierKeys, capitaliseFirstCharacter(character)]; |
330 return [...accumulator, replacementKey]; |
336 }; |
331 } |
337 }); |
332 |
338 |
333 return [...accumulator, replacementKey, '+']; |
|
334 }, |
|
335 /** @type {string[]} */ |
|
336 []); |
|
337 const capitalizedCharacter = (0,external_lodash_namespaceObject.capitalize)(character); |
|
338 return [...modifierKeys, capitalizedCharacter]; |
|
339 } |
|
340 ); |
|
341 }); |
|
342 /** |
339 /** |
343 * An object that contains functions to display shortcuts. |
340 * An object that contains functions to display shortcuts. |
344 * |
341 * |
345 * @example |
342 * @example |
346 * ```js |
343 * ```js |
375 * ``` |
365 * ``` |
376 * |
366 * |
377 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to |
367 * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to |
378 * shortcut ARIA labels. |
368 * shortcut ARIA labels. |
379 */ |
369 */ |
380 |
370 const shortcutAriaLabel = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => { |
381 const shortcutAriaLabel = (0,external_lodash_namespaceObject.mapValues)(modifiers, modifier => { |
371 return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => { |
382 return ( |
372 const isApple = _isApple(); |
383 /** @type {WPKeyHandler<string>} */ |
373 /** @type {Record<string,string>} */ |
384 function (character) { |
374 const replacementKeyMap = { |
385 let _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS; |
375 [SHIFT]: 'Shift', |
386 |
376 [COMMAND]: isApple ? 'Command' : 'Control', |
387 const isApple = _isApple(); |
377 [CTRL]: 'Control', |
388 |
378 [ALT]: isApple ? 'Option' : 'Alt', |
389 const replacementKeyMap = { |
379 /* translators: comma as in the character ',' */ |
390 [SHIFT]: 'Shift', |
380 ',': (0,external_wp_i18n_namespaceObject.__)('Comma'), |
391 [COMMAND]: isApple ? 'Command' : 'Control', |
381 /* translators: period as in the character '.' */ |
392 [CTRL]: 'Control', |
382 '.': (0,external_wp_i18n_namespaceObject.__)('Period'), |
393 [ALT]: isApple ? 'Option' : 'Alt', |
383 /* translators: backtick as in the character '`' */ |
394 |
384 '`': (0,external_wp_i18n_namespaceObject.__)('Backtick'), |
395 /* translators: comma as in the character ',' */ |
385 /* translators: tilde as in the character '~' */ |
396 ',': (0,external_wp_i18n_namespaceObject.__)('Comma'), |
386 '~': (0,external_wp_i18n_namespaceObject.__)('Tilde') |
397 |
387 }; |
398 /* translators: period as in the character '.' */ |
388 return [...modifier(_isApple), character].map(key => { |
399 '.': (0,external_wp_i18n_namespaceObject.__)('Period'), |
389 var _replacementKeyMap$ke2; |
400 |
390 return capitaliseFirstCharacter((_replacementKeyMap$ke2 = replacementKeyMap[key]) !== null && _replacementKeyMap$ke2 !== void 0 ? _replacementKeyMap$ke2 : key); |
401 /* translators: backtick as in the character '`' */ |
391 }).join(isApple ? ' ' : ' + '); |
402 '`': (0,external_wp_i18n_namespaceObject.__)('Backtick') |
392 }; |
403 }; |
393 }); |
404 return [...modifier(_isApple), character].map(key => (0,external_lodash_namespaceObject.capitalize)((0,external_lodash_namespaceObject.get)(replacementKeyMap, key, key))).join(isApple ? ' ' : ' + '); |
394 |
405 } |
|
406 ); |
|
407 }); |
|
408 /** |
395 /** |
409 * From a given KeyboardEvent, returns an array of active modifier constants for |
396 * From a given KeyboardEvent, returns an array of active modifier constants for |
410 * the event. |
397 * the event. |
411 * |
398 * |
412 * @param {KeyboardEvent} event Keyboard event. |
399 * @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event. |
413 * |
400 * |
414 * @return {Array<WPModifierPart>} Active modifier constants. |
401 * @return {Array<WPModifierPart>} Active modifier constants. |
415 */ |
402 */ |
416 |
|
417 function getEventModifiers(event) { |
403 function getEventModifiers(event) { |
418 return ( |
404 return /** @type {WPModifierPart[]} */[ALT, CTRL, COMMAND, SHIFT].filter(key => event[( /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */ |
419 /** @type {WPModifierPart[]} */ |
405 `${key}Key`)]); |
420 [ALT, CTRL, COMMAND, SHIFT].filter(key => event[ |
|
421 /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */ |
|
422 `${key}Key`]) |
|
423 ); |
|
424 } |
406 } |
|
407 |
425 /** |
408 /** |
426 * An object that contains functions to check if a keyboard event matches a |
409 * An object that contains functions to check if a keyboard event matches a |
427 * predefined shortcut combination. |
410 * predefined shortcut combination. |
428 * |
411 * |
429 * @example |
412 * @example |
434 * ``` |
417 * ``` |
435 * |
418 * |
436 * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions |
419 * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions |
437 * to match events. |
420 * to match events. |
438 */ |
421 */ |
439 |
422 const isKeyboardEvent = mapValues(modifiers, ( /** @type {WPModifier} */getModifiers) => { |
440 |
423 return /** @type {WPEventKeyHandler} */(event, character, _isApple = isAppleOS) => { |
441 const isKeyboardEvent = (0,external_lodash_namespaceObject.mapValues)(modifiers, getModifiers => { |
424 const mods = getModifiers(_isApple); |
442 return ( |
425 const eventMods = getEventModifiers(event); |
443 /** @type {WPEventKeyHandler} */ |
426 /** @type {Record<string,string>} */ |
444 function (event, character) { |
427 const replacementWithShiftKeyMap = { |
445 let _isApple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : isAppleOS; |
428 Comma: ',', |
446 |
429 Backslash: '\\', |
447 const mods = getModifiers(_isApple); |
430 // Windows returns `\` for both IntlRo and IntlYen. |
448 const eventMods = getEventModifiers(event); |
431 IntlRo: '\\', |
449 |
432 IntlYen: '\\' |
450 if ((0,external_lodash_namespaceObject.xor)(mods, eventMods).length) { |
433 }; |
451 return false; |
434 const modsDiff = mods.filter(mod => !eventMods.includes(mod)); |
452 } |
435 const eventModsDiff = eventMods.filter(mod => !mods.includes(mod)); |
453 |
436 if (modsDiff.length > 0 || eventModsDiff.length > 0) { |
454 let key = event.key.toLowerCase(); |
437 return false; |
455 |
438 } |
456 if (!character) { |
439 let key = event.key.toLowerCase(); |
457 return (0,external_lodash_namespaceObject.includes)(mods, key); |
440 if (!character) { |
458 } |
441 return mods.includes( /** @type {WPModifierPart} */key); |
459 |
442 } |
460 if (event.altKey && character.length === 1) { |
443 if (event.altKey && character.length === 1) { |
461 key = String.fromCharCode(event.keyCode).toLowerCase(); |
444 key = String.fromCharCode(event.keyCode).toLowerCase(); |
462 } // For backwards compatibility. |
445 } |
463 |
446 |
464 |
447 // `event.key` returns the value of the key pressed, taking into the state of |
465 if (character === 'del') { |
448 // modifier keys such as `Shift`. If the shift key is pressed, a different |
466 character = 'delete'; |
449 // value may be returned depending on the keyboard layout. It is necessary to |
467 } |
450 // convert to the physical key value that don't take into account keyboard |
468 |
451 // layout or modifier key state. |
469 return key === character.toLowerCase(); |
452 if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) { |
470 } |
453 key = replacementWithShiftKeyMap[event.code]; |
471 ); |
454 } |
|
455 |
|
456 // For backwards compatibility. |
|
457 if (character === 'del') { |
|
458 character = 'delete'; |
|
459 } |
|
460 return key === character.toLowerCase(); |
|
461 }; |
472 }); |
462 }); |
473 |
463 |
474 (window.wp = window.wp || {}).keycodes = __webpack_exports__; |
464 (window.wp = window.wp || {}).keycodes = __webpack_exports__; |
475 /******/ })() |
465 /******/ })() |
476 ; |
466 ; |