| 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 ["wp","i18n"] |
| 72 |
const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
| 73 |
;// CONCATENATED MODULE: ./packages/keycodes/build-module/platform.js |
| 74 |
/** |
| 75 |
* Return true if platform is MacOS. |
| 76 |
* |
| 77 |
* @param {Window?} _window window object by default; used for DI testing. |
| 78 |
* |
| 79 |
* @return {boolean} True if MacOS; false otherwise. |
| 80 |
*/ |
| 81 |
function isAppleOS(_window = null) { |
| 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 |
;// CONCATENATED MODULE: ./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 |
/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */ |
| 117 |
|
| 118 |
/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */ |
| 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 |
* @template T |
| 125 |
* |
| 126 |
* @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler |
| 127 |
*/ |
| 128 |
|
| 129 |
/** |
| 130 |
* @template T |
| 131 |
* |
| 132 |
* @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler |
| 133 |
*/ |
| 134 |
/** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */ |
| 135 |
|
| 136 |
/** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */ |
| 137 |
|
| 138 |
/** |
| 139 |
* Keycode for BACKSPACE key. |
| 140 |
*/ |
| 141 |
const BACKSPACE = 8; |
| 142 |
|
| 143 |
/** |
| 144 |
* Keycode for TAB key. |
| 145 |
*/ |
| 146 |
const TAB = 9; |
| 147 |
|
| 148 |
/** |
| 149 |
* Keycode for ENTER key. |
| 150 |
*/ |
| 151 |
const ENTER = 13; |
| 152 |
|
| 153 |
/** |
| 154 |
* Keycode for ESCAPE key. |
| 155 |
*/ |
| 156 |
const ESCAPE = 27; |
| 157 |
|
| 158 |
/** |
| 159 |
* Keycode for SPACE key. |
| 160 |
*/ |
| 161 |
const SPACE = 32; |
| 162 |
|
| 163 |
/** |
| 164 |
* Keycode for PAGEUP key. |
| 165 |
*/ |
| 166 |
const PAGEUP = 33; |
| 167 |
|
| 168 |
/** |
| 169 |
* Keycode for PAGEDOWN key. |
| 170 |
*/ |
| 171 |
const PAGEDOWN = 34; |
| 172 |
|
| 173 |
/** |
| 174 |
* Keycode for END key. |
| 175 |
*/ |
| 176 |
const END = 35; |
| 177 |
|
| 178 |
/** |
| 179 |
* Keycode for HOME key. |
| 180 |
*/ |
| 181 |
const HOME = 36; |
| 182 |
|
| 183 |
/** |
| 184 |
* Keycode for LEFT key. |
| 185 |
*/ |
| 186 |
const LEFT = 37; |
| 187 |
|
| 188 |
/** |
| 189 |
* Keycode for UP key. |
| 190 |
*/ |
| 191 |
const UP = 38; |
| 192 |
|
| 193 |
/** |
| 194 |
* Keycode for RIGHT key. |
| 195 |
*/ |
| 196 |
const RIGHT = 39; |
| 197 |
|
| 198 |
/** |
| 199 |
* Keycode for DOWN key. |
| 200 |
*/ |
| 201 |
const DOWN = 40; |
| 202 |
|
| 203 |
/** |
| 204 |
* Keycode for DELETE key. |
| 205 |
*/ |
| 206 |
const DELETE = 46; |
| 207 |
|
| 208 |
/** |
| 209 |
* Keycode for F10 key. |
| 210 |
*/ |
| 211 |
const F10 = 121; |
| 212 |
|
| 213 |
/** |
| 214 |
* Keycode for ALT key. |
| 215 |
*/ |
| 216 |
const ALT = 'alt'; |
| 217 |
|
| 218 |
/** |
| 219 |
* Keycode for CTRL key. |
| 220 |
*/ |
| 221 |
const CTRL = 'ctrl'; |
| 222 |
|
| 223 |
/** |
| 224 |
* Keycode for COMMAND/META key. |
| 225 |
*/ |
| 226 |
const COMMAND = 'meta'; |
| 227 |
|
| 228 |
/** |
| 229 |
* Keycode for SHIFT key. |
| 230 |
*/ |
| 231 |
const SHIFT = 'shift'; |
| 232 |
|
| 233 |
/** |
| 234 |
* Keycode for ZERO key. |
| 235 |
*/ |
| 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 |
|
| 262 |
/** |
| 263 |
* Object that contains functions that return the available modifier |
| 264 |
* depending on platform. |
| 265 |
* |
| 266 |
* @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>} |
| 267 |
*/ |
| 268 |
const modifiers = { |
| 269 |
primary: _isApple => _isApple() ? [COMMAND] : [CTRL], |
| 270 |
primaryShift: _isApple => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT], |
| 271 |
primaryAlt: _isApple => _isApple() ? [ALT, COMMAND] : [CTRL, ALT], |
| 272 |
secondary: _isApple => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT], |
| 273 |
access: _isApple => _isApple() ? [CTRL, ALT] : [SHIFT, ALT], |
| 274 |
ctrl: () => [CTRL], |
| 275 |
alt: () => [ALT], |
| 276 |
ctrlShift: () => [CTRL, SHIFT], |
| 277 |
shift: () => [SHIFT], |
| 278 |
shiftAlt: () => [SHIFT, ALT], |
| 279 |
undefined: () => [] |
| 280 |
}; |
| 281 |
|
| 282 |
/** |
| 283 |
* An object that contains functions to get raw shortcuts. |
| 284 |
* |
| 285 |
* These are intended for user with the KeyboardShortcuts. |
| 286 |
* |
| 287 |
* @example |
| 288 |
* ```js |
| 289 |
* // Assuming macOS: |
| 290 |
* rawShortcut.primary( 'm' ) |
| 291 |
* // "meta+m"" |
| 292 |
* ``` |
| 293 |
* |
| 294 |
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw |
| 295 |
* shortcuts. |
| 296 |
*/ |
| 297 |
const rawShortcut = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => { |
| 298 |
return (/** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => { |
| 299 |
return [...modifier(_isApple), character.toLowerCase()].join('+'); |
| 300 |
} |
| 301 |
); |
| 302 |
}); |
| 303 |
|
| 304 |
/** |
| 305 |
* Return an array of the parts of a keyboard shortcut chord for display. |
| 306 |
* |
| 307 |
* @example |
| 308 |
* ```js |
| 309 |
* // Assuming macOS: |
| 310 |
* displayShortcutList.primary( 'm' ); |
| 311 |
* // [ "⌘", "M" ] |
| 312 |
* ``` |
| 313 |
* |
| 314 |
* @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to |
| 315 |
* shortcut sequences. |
| 316 |
*/ |
| 317 |
const displayShortcutList = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => { |
| 318 |
return (/** @type {WPKeyHandler<string[]>} */(character, _isApple = isAppleOS) => { |
| 319 |
const isApple = _isApple(); |
| 320 |
const replacementKeyMap = { |
| 321 |
[ALT]: isApple ? '⌥' : 'Alt', |
| 322 |
[CTRL]: isApple ? '⌃' : 'Ctrl', |
| 323 |
// Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character. |
| 324 |
[COMMAND]: '⌘', |
| 325 |
[SHIFT]: isApple ? '⇧' : 'Shift' |
| 326 |
}; |
| 327 |
const modifierKeys = modifier(_isApple).reduce((accumulator, key) => { |
| 328 |
var _replacementKeyMap$ke; |
| 329 |
const replacementKey = (_replacementKeyMap$ke = replacementKeyMap[key]) !== null && _replacementKeyMap$ke !== void 0 ? _replacementKeyMap$ke : key; |
| 330 |
// If on the Mac, adhere to platform convention and don't show plus between keys. |
| 331 |
if (isApple) { |
| 332 |
return [...accumulator, replacementKey]; |
| 333 |
} |
| 334 |
return [...accumulator, replacementKey, '+']; |
| 335 |
}, /** @type {string[]} */[]); |
| 336 |
return [...modifierKeys, capitaliseFirstCharacter(character)]; |
| 337 |
} |
| 338 |
); |
| 339 |
}); |
| 340 |
|
| 341 |
/** |
| 342 |
* An object that contains functions to display shortcuts. |
| 343 |
* |
| 344 |
* @example |
| 345 |
* ```js |
| 346 |
* // Assuming macOS: |
| 347 |
* displayShortcut.primary( 'm' ); |
| 348 |
* // "⌘M" |
| 349 |
* ``` |
| 350 |
* |
| 351 |
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to |
| 352 |
* display shortcuts. |
| 353 |
*/ |
| 354 |
const displayShortcut = mapValues(displayShortcutList, ( /** @type {WPKeyHandler<string[]>} */shortcutList) => { |
| 355 |
return (/** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('') |
| 356 |
); |
| 357 |
}); |
| 358 |
|
| 359 |
/** |
| 360 |
* An object that contains functions to return an aria label for a keyboard |
| 361 |
* shortcut. |
| 362 |
* |
| 363 |
* @example |
| 364 |
* ```js |
| 365 |
* // Assuming macOS: |
| 366 |
* shortcutAriaLabel.primary( '.' ); |
| 367 |
* // "Command + Period" |
| 368 |
* ``` |
| 369 |
* |
| 370 |
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to |
| 371 |
* shortcut ARIA labels. |
| 372 |
*/ |
| 373 |
const shortcutAriaLabel = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => { |
| 374 |
return (/** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => { |
| 375 |
const isApple = _isApple(); |
| 376 |
/** @type {Record<string,string>} */ |
| 377 |
const replacementKeyMap = { |
| 378 |
[SHIFT]: 'Shift', |
| 379 |
[COMMAND]: isApple ? 'Command' : 'Control', |
| 380 |
[CTRL]: 'Control', |
| 381 |
[ALT]: isApple ? 'Option' : 'Alt', |
| 382 |
/* translators: comma as in the character ',' */ |
| 383 |
',': (0,external_wp_i18n_namespaceObject.__)('Comma'), |
| 384 |
/* translators: period as in the character '.' */ |
| 385 |
'.': (0,external_wp_i18n_namespaceObject.__)('Period'), |
| 386 |
/* translators: backtick as in the character '`' */ |
| 387 |
'`': (0,external_wp_i18n_namespaceObject.__)('Backtick'), |
| 388 |
/* translators: tilde as in the character '~' */ |
| 389 |
'~': (0,external_wp_i18n_namespaceObject.__)('Tilde') |
| 390 |
}; |
| 391 |
return [...modifier(_isApple), character].map(key => { |
| 392 |
var _replacementKeyMap$ke2; |
| 393 |
return capitaliseFirstCharacter((_replacementKeyMap$ke2 = replacementKeyMap[key]) !== null && _replacementKeyMap$ke2 !== void 0 ? _replacementKeyMap$ke2 : key); |
| 394 |
}).join(isApple ? ' ' : ' + '); |
| 395 |
} |
| 396 |
); |
| 397 |
}); |
| 398 |
|
| 399 |
/** |
| 400 |
* From a given KeyboardEvent, returns an array of active modifier constants for |
| 401 |
* the event. |
| 402 |
* |
| 403 |
* @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event. |
| 404 |
* |
| 405 |
* @return {Array<WPModifierPart>} Active modifier constants. |
| 406 |
*/ |
| 407 |
function getEventModifiers(event) { |
| 408 |
return (/** @type {WPModifierPart[]} */[ALT, CTRL, COMMAND, SHIFT].filter(key => event[/** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */ |
| 409 |
`${key}Key`]) |
| 410 |
); |
| 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 |
const isKeyboardEvent = mapValues(modifiers, ( /** @type {WPModifier} */getModifiers) => { |
| 428 |
return (/** @type {WPEventKeyHandler} */(event, character, _isApple = isAppleOS) => { |
| 429 |
const mods = getModifiers(_isApple); |
| 430 |
const eventMods = getEventModifiers(event); |
| 431 |
/** @type {Record<string,string>} */ |
| 432 |
const replacementWithShiftKeyMap = { |
| 433 |
Comma: ',', |
| 434 |
Backslash: '\\', |
| 435 |
// Windows returns `\` for both IntlRo and IntlYen. |
| 436 |
IntlRo: '\\', |
| 437 |
IntlYen: '\\' |
| 438 |
}; |
| 439 |
const modsDiff = mods.filter(mod => !eventMods.includes(mod)); |
| 440 |
const eventModsDiff = eventMods.filter(mod => !mods.includes(mod)); |
| 441 |
if (modsDiff.length > 0 || eventModsDiff.length > 0) { |
| 442 |
return false; |
| 443 |
} |
| 444 |
let key = event.key.toLowerCase(); |
| 445 |
if (!character) { |
| 446 |
return mods.includes( /** @type {WPModifierPart} */key); |
| 447 |
} |
| 448 |
if (event.altKey && character.length === 1) { |
| 449 |
key = String.fromCharCode(event.keyCode).toLowerCase(); |
| 450 |
} |
| 451 |
|
| 452 |
// `event.key` returns the value of the key pressed, taking into the state of |
| 453 |
// modifier keys such as `Shift`. If the shift key is pressed, a different |
| 454 |
// value may be returned depending on the keyboard layout. It is necessary to |
| 455 |
// convert to the physical key value that don't take into account keyboard |
| 456 |
// layout or modifier key state. |
| 457 |
if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) { |
| 458 |
key = replacementWithShiftKeyMap[event.code]; |
| 459 |
} |
| 460 |
|
| 461 |
// For backwards compatibility. |
| 462 |
if (character === 'del') { |
| 463 |
character = 'delete'; |
| 464 |
} |
| 465 |
return key === character.toLowerCase(); |
| 466 |
} |
| 467 |
); |
| 468 |
}); |
| 469 |
|
| 470 |
(window.wp = window.wp || {}).keycodes = __webpack_exports__; |
| 471 |
/******/ })() |
| 472 |
; |