2018-12-13 23:41:57 -05:00
this [ "wp" ] = this [ "wp" ] || { } ; this [ "wp" ] [ "keycodes" ] =
/******/ ( function ( modules ) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/
/******/ // Check if module is in cache
/******/ if ( installedModules [ moduleId ] ) {
/******/ return installedModules [ moduleId ] . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Flag the module as loaded
/******/ module . l = true ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
/******/
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
/******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
/******/ }
/******/ } ;
/******/
/******/ // define __esModule on exports
/******/ _ _webpack _require _ _ . r = function ( exports ) {
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
/******/ }
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
/******/ } ;
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ _ _webpack _require _ _ . t = function ( value , mode ) {
/******/ if ( mode & 1 ) value = _ _webpack _require _ _ ( value ) ;
/******/ if ( mode & 8 ) return value ;
/******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . _ _esModule ) return value ;
/******/ var ns = Object . create ( null ) ;
/******/ _ _webpack _require _ _ . r ( ns ) ;
/******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
/******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) _ _webpack _require _ _ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
/******/ return ns ;
/******/ } ;
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
/******/ // __webpack_public_path__
/******/ _ _webpack _require _ _ . p = "" ;
/******/
/******/
/******/ // Load entry module and return exports
2021-05-20 08:20:04 -04:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = "z7pY" ) ;
2018-12-13 23:41:57 -05:00
/******/ } )
/************************************************************************/
/******/ ( {
2021-05-20 08:20:04 -04:00
/***/ "YLtl" :
2018-12-17 22:14:52 -05:00
/***/ ( function ( module , exports ) {
2018-12-13 23:41:57 -05:00
2021-05-20 08:20:04 -04:00
( function ( ) { module . exports = window [ "lodash" ] ; } ( ) ) ;
2018-12-13 23:41:57 -05:00
/***/ } ) ,
2021-05-20 08:20:04 -04:00
/***/ "l3Sj" :
2018-12-17 22:14:52 -05:00
/***/ ( function ( module , exports ) {
2018-12-13 23:41:57 -05:00
2021-05-20 08:20:04 -04:00
( function ( ) { module . exports = window [ "wp" ] [ "i18n" ] ; } ( ) ) ;
2018-12-13 23:41:57 -05:00
2018-12-17 22:14:52 -05:00
/***/ } ) ,
2018-12-13 23:41:57 -05:00
2021-05-20 08:20:04 -04:00
/***/ "z7pY" :
2018-12-13 23:41:57 -05:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
2020-06-29 07:50:29 -04:00
// ESM COMPAT FLAG
2018-12-13 23:41:57 -05:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2018-12-17 22:14:52 -05:00
2020-06-29 07:50:29 -04:00
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "BACKSPACE" , function ( ) { return /* binding */ BACKSPACE ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "TAB" , function ( ) { return /* binding */ TAB ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "ENTER" , function ( ) { return /* binding */ ENTER ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "ESCAPE" , function ( ) { return /* binding */ ESCAPE ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "SPACE" , function ( ) { return /* binding */ SPACE ; } ) ;
2021-11-08 09:29:21 -05:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "PAGEUP" , function ( ) { return /* binding */ PAGEUP ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "PAGEDOWN" , function ( ) { return /* binding */ PAGEDOWN ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "END" , function ( ) { return /* binding */ END ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "HOME" , function ( ) { return /* binding */ HOME ; } ) ;
2020-06-29 07:50:29 -04:00
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "LEFT" , function ( ) { return /* binding */ LEFT ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "UP" , function ( ) { return /* binding */ UP ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "RIGHT" , function ( ) { return /* binding */ RIGHT ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "DOWN" , function ( ) { return /* binding */ DOWN ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "DELETE" , function ( ) { return /* binding */ DELETE ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "F10" , function ( ) { return /* binding */ F10 ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "ALT" , function ( ) { return /* binding */ ALT ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "CTRL" , function ( ) { return /* binding */ CTRL ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "COMMAND" , function ( ) { return /* binding */ COMMAND ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "SHIFT" , function ( ) { return /* binding */ SHIFT ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "ZERO" , function ( ) { return /* binding */ ZERO ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "modifiers" , function ( ) { return /* binding */ modifiers ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "rawShortcut" , function ( ) { return /* binding */ rawShortcut ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "displayShortcutList" , function ( ) { return /* binding */ displayShortcutList ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "displayShortcut" , function ( ) { return /* binding */ displayShortcut ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "shortcutAriaLabel" , function ( ) { return /* binding */ shortcutAriaLabel ; } ) ;
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , "isKeyboardEvent" , function ( ) { return /* binding */ isKeyboardEvent ; } ) ;
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external "lodash"
2021-05-20 08:20:04 -04:00
var external _lodash _ = _ _webpack _require _ _ ( "YLtl" ) ;
2018-12-17 22:14:52 -05:00
2021-01-27 21:04:13 -05:00
// EXTERNAL MODULE: external ["wp","i18n"]
2021-05-20 08:20:04 -04:00
var external _wp _i18n _ = _ _webpack _require _ _ ( "l3Sj" ) ;
2018-12-17 22:14:52 -05:00
// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js
/ * *
* External dependencies
* /
/ * *
* Return true if platform is MacOS .
*
2021-04-15 11:19:43 -04:00
* @ param { Window ? } _window window object by default ; used for DI testing .
2018-12-17 22:14:52 -05:00
*
2021-01-27 21:04:13 -05:00
* @ return { boolean } True if MacOS ; false otherwise .
2018-12-17 22:14:52 -05:00
* /
2021-11-15 07:50:17 -05:00
function isAppleOS ( ) {
let _window = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : null ;
2021-04-15 11:19:43 -04:00
if ( ! _window ) {
if ( typeof window === 'undefined' ) {
return false ;
}
_window = window ;
}
2018-12-17 22:14:52 -05:00
2021-05-19 11:09:27 -04:00
const {
platform
} = _window . navigator ;
2021-01-27 21:04:13 -05:00
return platform . indexOf ( 'Mac' ) !== - 1 || Object ( external _lodash _ [ "includes" ] ) ( [ 'iPad' , 'iPhone' ] , platform ) ;
2018-12-17 22:14:52 -05:00
}
// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js
2018-12-13 23:41:57 -05:00
/ * *
* Note : The order of the modifier keys in many of the [ foo ] Shortcut ( )
* functions in this file are intentional and should not be changed . They ' re
* designed to fit with the standard menu keyboard shortcuts shown in the
* user ' s platform .
*
* For example , on MacOS menu shortcuts will place Shift before Command , but
* on Windows Control will usually come first . So don ' t provide your own
* shortcut combos directly to keyboardShortcut ( ) .
* /
/ * *
* External dependencies
* /
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
2021-01-27 21:04:13 -05:00
/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
2021-11-08 09:29:21 -05:00
/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
2020-01-22 17:06:21 -05:00
/ * *
* An object of handler functions for each of the possible modifier
* combinations . A handler will return a value for a given key .
*
2021-01-27 21:04:13 -05:00
* @ template T
*
* @ typedef { Record < WPKeycodeModifier , T > } WPModifierHandler
* /
/ * *
* @ template T
*
* @ typedef { ( character : string , isApple ? : ( ) => boolean ) => T } WPKeyHandler
2020-01-22 17:06:21 -05:00
* /
2021-01-27 21:04:13 -05:00
/** @typedef {(event: KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for BACKSPACE key .
* /
2021-05-19 11:09:27 -04:00
const BACKSPACE = 8 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for TAB key .
* /
2021-05-19 11:09:27 -04:00
const TAB = 9 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for ENTER key .
* /
2021-05-19 11:09:27 -04:00
const ENTER = 13 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for ESCAPE key .
* /
2021-05-19 11:09:27 -04:00
const ESCAPE = 27 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for SPACE key .
* /
2021-05-19 11:09:27 -04:00
const SPACE = 32 ;
2021-11-08 09:29:21 -05:00
/ * *
* Keycode for PAGEUP key .
* /
const PAGEUP = 33 ;
/ * *
* Keycode for PAGEDOWN key .
* /
const PAGEDOWN = 34 ;
/ * *
* Keycode for END key .
* /
const END = 35 ;
/ * *
* Keycode for HOME key .
* /
const HOME = 36 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for LEFT key .
* /
2021-05-19 11:09:27 -04:00
const LEFT = 37 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for UP key .
* /
2021-05-19 11:09:27 -04:00
const UP = 38 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for RIGHT key .
* /
2021-05-19 11:09:27 -04:00
const RIGHT = 39 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for DOWN key .
* /
2021-05-19 11:09:27 -04:00
const DOWN = 40 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for DELETE key .
* /
2021-05-19 11:09:27 -04:00
const DELETE = 46 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for F10 key .
* /
2021-05-19 11:09:27 -04:00
const F10 = 121 ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for ALT key .
* /
2021-05-19 11:09:27 -04:00
const ALT = 'alt' ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for CTRL key .
* /
2021-05-19 11:09:27 -04:00
const CTRL = 'ctrl' ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for COMMAND / META key .
* /
2021-05-19 11:09:27 -04:00
const COMMAND = 'meta' ;
2019-03-21 08:48:00 -04:00
/ * *
* Keycode for SHIFT key .
* /
2021-05-19 11:09:27 -04:00
const SHIFT = 'shift' ;
2020-06-26 09:33:47 -04:00
/ * *
* Keycode for ZERO key .
* /
2021-05-19 11:09:27 -04:00
const ZERO = 48 ;
2019-03-21 08:48:00 -04:00
/ * *
* Object that contains functions that return the available modifier
* depending on platform .
*
2021-01-27 21:04:13 -05:00
* @ type { WPModifierHandler < ( isApple : ( ) => boolean ) => WPModifierPart [ ] > }
2019-03-21 08:48:00 -04:00
* /
2021-05-19 11:09:27 -04:00
const modifiers = {
primary : _isApple => _isApple ( ) ? [ COMMAND ] : [ CTRL ] ,
primaryShift : _isApple => _isApple ( ) ? [ SHIFT , COMMAND ] : [ CTRL , SHIFT ] ,
primaryAlt : _isApple => _isApple ( ) ? [ ALT , COMMAND ] : [ CTRL , ALT ] ,
secondary : _isApple => _isApple ( ) ? [ SHIFT , ALT , COMMAND ] : [ CTRL , SHIFT , ALT ] ,
access : _isApple => _isApple ( ) ? [ CTRL , ALT ] : [ SHIFT , ALT ] ,
ctrl : ( ) => [ CTRL ] ,
alt : ( ) => [ ALT ] ,
ctrlShift : ( ) => [ CTRL , SHIFT ] ,
shift : ( ) => [ SHIFT ] ,
2021-11-08 09:29:21 -05:00
shiftAlt : ( ) => [ SHIFT , ALT ] ,
undefined : ( ) => [ ]
2018-12-13 23:41:57 -05:00
} ;
/ * *
* An object that contains functions to get raw shortcuts .
*
2021-01-27 21:04:13 -05:00
* These are intended for user with the KeyboardShortcuts .
*
* @ example
* ` ` ` js
* // Assuming macOS:
* rawShortcut . primary ( 'm' )
* // "meta+m""
* ` ` `
*
* @ type { WPModifierHandler < WPKeyHandler < string >> } Keyed map of functions to raw
* shortcuts .
2018-12-13 23:41:57 -05:00
* /
2021-05-19 11:09:27 -04:00
const rawShortcut = Object ( external _lodash _ [ "mapValues" ] ) ( modifiers , modifier => {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPKeyHandler<string>} */
2021-11-15 07:50:17 -05:00
function ( character ) {
let _isApple = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : isAppleOS ;
2021-05-19 11:09:27 -04:00
return [ ... modifier ( _isApple ) , character . toLowerCase ( ) ] . join ( '+' ) ;
2021-01-27 21:04:13 -05:00
}
) ;
2018-12-13 23:41:57 -05:00
} ) ;
/ * *
2021-01-27 21:04:13 -05:00
* Return an array of the parts of a keyboard shortcut chord for display .
2018-12-13 23:41:57 -05:00
*
2021-01-27 21:04:13 -05:00
* @ example
* ` ` ` js
* // Assuming macOS:
* displayShortcutList . primary ( 'm' ) ;
* // [ "⌘", "M" ]
* ` ` `
*
* @ type { WPModifierHandler < WPKeyHandler < string [ ] >> } Keyed map of functions to
* shortcut sequences .
2018-12-13 23:41:57 -05:00
* /
2021-05-19 11:09:27 -04:00
const displayShortcutList = Object ( external _lodash _ [ "mapValues" ] ) ( modifiers , modifier => {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPKeyHandler<string[]>} */
2021-11-15 07:50:17 -05:00
function ( character ) {
let _isApple = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : isAppleOS ;
2021-05-19 11:09:27 -04:00
const isApple = _isApple ( ) ;
const replacementKeyMap = {
[ ALT ] : isApple ? '⌥' : 'Alt' ,
[ CTRL ] : isApple ? '⌃' : 'Ctrl' ,
// Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
[ COMMAND ] : '⌘' ,
[ SHIFT ] : isApple ? '⇧' : 'Shift'
} ;
const modifierKeys = modifier ( _isApple ) . reduce ( ( accumulator , key ) => {
const replacementKey = Object ( external _lodash _ [ "get" ] ) ( replacementKeyMap , key , key ) ; // If on the Mac, adhere to platform convention and don't show plus between keys.
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
if ( isApple ) {
2021-05-19 11:09:27 -04:00
return [ ... accumulator , replacementKey ] ;
2021-01-27 21:04:13 -05:00
}
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
return [ ... accumulator , replacementKey , '+' ] ;
2021-01-27 21:04:13 -05:00
} ,
/** @type {string[]} */
[ ] ) ;
2021-05-19 11:09:27 -04:00
const capitalizedCharacter = Object ( external _lodash _ [ "capitalize" ] ) ( character ) ;
return [ ... modifierKeys , capitalizedCharacter ] ;
2021-01-27 21:04:13 -05:00
}
) ;
2018-12-13 23:41:57 -05:00
} ) ;
/ * *
* An object that contains functions to display shortcuts .
*
2021-01-27 21:04:13 -05:00
* @ example
* ` ` ` js
* // Assuming macOS:
* displayShortcut . primary ( 'm' ) ;
* // "⌘M"
* ` ` `
*
* @ type { WPModifierHandler < WPKeyHandler < string >> } Keyed map of functions to
* display shortcuts .
2018-12-13 23:41:57 -05:00
* /
2021-05-19 11:09:27 -04:00
const displayShortcut = Object ( external _lodash _ [ "mapValues" ] ) ( displayShortcutList , shortcutList => {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPKeyHandler<string>} */
2021-11-15 07:50:17 -05:00
function ( character ) {
let _isApple = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : isAppleOS ;
return shortcutList ( character , _isApple ) . join ( '' ) ;
}
2021-01-27 21:04:13 -05:00
) ;
2018-12-13 23:41:57 -05:00
} ) ;
/ * *
2021-01-27 21:04:13 -05:00
* An object that contains functions to return an aria label for a keyboard
* shortcut .
*
* @ example
* ` ` ` js
* // Assuming macOS:
* shortcutAriaLabel . primary ( '.' ) ;
* // "Command + Period"
* ` ` `
2020-01-22 17:06:21 -05:00
*
2021-01-27 21:04:13 -05:00
* @ type { WPModifierHandler < WPKeyHandler < string >> } Keyed map of functions to
* shortcut ARIA labels .
2018-12-13 23:41:57 -05:00
* /
2021-05-19 11:09:27 -04:00
const shortcutAriaLabel = Object ( external _lodash _ [ "mapValues" ] ) ( modifiers , modifier => {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPKeyHandler<string>} */
2021-11-15 07:50:17 -05:00
function ( character ) {
let _isApple = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : isAppleOS ;
2021-05-19 11:09:27 -04:00
const isApple = _isApple ( ) ;
const replacementKeyMap = {
[ SHIFT ] : 'Shift' ,
[ COMMAND ] : isApple ? 'Command' : 'Control' ,
[ CTRL ] : 'Control' ,
[ ALT ] : isApple ? 'Option' : 'Alt' ,
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
/* translators: comma as in the character ',' */
',' : Object ( external _wp _i18n _ [ "__" ] ) ( 'Comma' ) ,
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
/* translators: period as in the character '.' */
'.' : Object ( external _wp _i18n _ [ "__" ] ) ( 'Period' ) ,
2018-12-13 23:41:57 -05:00
2021-05-19 11:09:27 -04:00
/* translators: backtick as in the character '`' */
'`' : Object ( external _wp _i18n _ [ "__" ] ) ( 'Backtick' )
} ;
return [ ... modifier ( _isApple ) , character ] . map ( key => Object ( external _lodash _ [ "capitalize" ] ) ( Object ( external _lodash _ [ "get" ] ) ( replacementKeyMap , key , key ) ) ) . join ( isApple ? ' ' : ' + ' ) ;
2021-01-27 21:04:13 -05:00
}
) ;
2018-12-13 23:41:57 -05:00
} ) ;
2020-06-26 09:33:47 -04:00
/ * *
* From a given KeyboardEvent , returns an array of active modifier constants for
* the event .
*
* @ param { KeyboardEvent } event Keyboard event .
*
2021-01-27 21:04:13 -05:00
* @ return { Array < WPModifierPart > } Active modifier constants .
2020-06-26 09:33:47 -04:00
* /
function getEventModifiers ( event ) {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPModifierPart[]} */
2021-05-19 11:09:27 -04:00
[ ALT , CTRL , COMMAND , SHIFT ] . filter ( key => event [
/** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
` ${ key } Key ` ] )
2021-01-27 21:04:13 -05:00
) ;
2020-06-26 09:33:47 -04:00
}
2018-12-13 23:41:57 -05:00
/ * *
* An object that contains functions to check if a keyboard event matches a
* predefined shortcut combination .
*
2021-01-27 21:04:13 -05:00
* @ example
* ` ` ` js
* // Assuming an event for ⌘M key press:
* isKeyboardEvent . primary ( event , 'm' ) ;
* // true
* ` ` `
*
* @ type { WPModifierHandler < WPEventKeyHandler > } Keyed map of functions
* to match events .
2018-12-13 23:41:57 -05:00
* /
2020-06-26 09:33:47 -04:00
2021-05-19 11:09:27 -04:00
const isKeyboardEvent = Object ( external _lodash _ [ "mapValues" ] ) ( modifiers , getModifiers => {
2021-01-27 21:04:13 -05:00
return (
/** @type {WPEventKeyHandler} */
2021-11-15 07:50:17 -05:00
function ( event , character ) {
let _isApple = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : isAppleOS ;
2021-05-19 11:09:27 -04:00
const mods = getModifiers ( _isApple ) ;
const eventMods = getEventModifiers ( event ) ;
2018-12-13 23:41:57 -05:00
2021-01-27 21:04:13 -05:00
if ( Object ( external _lodash _ [ "xor" ] ) ( mods , eventMods ) . length ) {
return false ;
}
2018-12-13 23:41:57 -05:00
2021-11-08 09:29:21 -05:00
let key = event . key . toLowerCase ( ) ;
2021-01-27 21:04:13 -05:00
if ( ! character ) {
2021-11-08 09:29:21 -05:00
return Object ( external _lodash _ [ "includes" ] ) ( mods , key ) ;
}
if ( event . altKey && character . length === 1 ) {
key = String . fromCharCode ( event . keyCode ) . toLowerCase ( ) ;
} // For backwards compatibility.
if ( character === 'del' ) {
character = 'delete' ;
2021-01-27 21:04:13 -05:00
}
2018-12-13 23:41:57 -05:00
2021-11-08 09:29:21 -05:00
return key === character . toLowerCase ( ) ;
2021-01-27 21:04:13 -05:00
}
) ;
2018-12-13 23:41:57 -05:00
} ) ;
/***/ } )
2018-12-17 22:14:52 -05:00
/******/ } ) ;