wp/wp-includes/js/dist/keycodes.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    66   modifiers: () => (/* binding */ modifiers),
    66   modifiers: () => (/* binding */ modifiers),
    67   rawShortcut: () => (/* binding */ rawShortcut),
    67   rawShortcut: () => (/* binding */ rawShortcut),
    68   shortcutAriaLabel: () => (/* binding */ shortcutAriaLabel)
    68   shortcutAriaLabel: () => (/* binding */ shortcutAriaLabel)
    69 });
    69 });
    70 
    70 
    71 ;// CONCATENATED MODULE: external ["wp","i18n"]
    71 ;// external ["wp","i18n"]
    72 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
    72 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
    73 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/platform.js
    73 ;// ./node_modules/@wordpress/keycodes/build-module/platform.js
    74 /**
    74 /**
    75  * Return true if platform is MacOS.
    75  * Return true if platform is MacOS.
    76  *
    76  *
    77  * @param {Window?} _window window object by default; used for DI testing.
    77  * @param {Window?} _window window object by default; used for DI testing.
    78  *
    78  *
    89     platform
    89     platform
    90   } = _window.navigator;
    90   } = _window.navigator;
    91   return platform.indexOf('Mac') !== -1 || ['iPad', 'iPhone'].includes(platform);
    91   return platform.indexOf('Mac') !== -1 || ['iPad', 'iPhone'].includes(platform);
    92 }
    92 }
    93 
    93 
    94 ;// CONCATENATED MODULE: ./node_modules/@wordpress/keycodes/build-module/index.js
    94 ;// ./node_modules/@wordpress/keycodes/build-module/index.js
    95 /**
    95 /**
    96  * 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()
    97  * functions in this file are intentional and should not be changed. They're
    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
    98  * designed to fit with the standard menu keyboard shortcuts shown in the
    99  * user's platform.
    99  * user's platform.
   292  * ```
   292  * ```
   293  *
   293  *
   294  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
   294  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
   295  *                                                 shortcuts.
   295  *                                                 shortcuts.
   296  */
   296  */
   297 const rawShortcut = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => {
   297 const rawShortcut = /* @__PURE__ */
       
   298 mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
   298   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => {
   299   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => {
   299     return [...modifier(_isApple), character.toLowerCase()].join('+');
   300     return [...modifier(_isApple), character.toLowerCase()].join('+');
   300   };
   301   };
   301 });
   302 });
   302 
   303 
   311  * ```
   312  * ```
   312  *
   313  *
   313  * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
   314  * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
   314  *                                                   shortcut sequences.
   315  *                                                   shortcut sequences.
   315  */
   316  */
   316 const displayShortcutList = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => {
   317 const displayShortcutList = /* @__PURE__ */
       
   318 mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
   317   return /** @type {WPKeyHandler<string[]>} */(character, _isApple = isAppleOS) => {
   319   return /** @type {WPKeyHandler<string[]>} */(character, _isApple = isAppleOS) => {
   318     const isApple = _isApple();
   320     const isApple = _isApple();
   319     const replacementKeyMap = {
   321     const replacementKeyMap = {
   320       [ALT]: isApple ? '⌥' : 'Alt',
   322       [ALT]: isApple ? '⌥' : 'Alt',
   321       [CTRL]: isApple ? '⌃' : 'Ctrl',
   323       [CTRL]: isApple ? '⌃' : 'Ctrl',
   347  * ```
   349  * ```
   348  *
   350  *
   349  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
   351  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
   350  *                                                 display shortcuts.
   352  *                                                 display shortcuts.
   351  */
   353  */
   352 const displayShortcut = mapValues(displayShortcutList, ( /** @type {WPKeyHandler<string[]>} */shortcutList) => {
   354 const displayShortcut = /* @__PURE__ */
       
   355 mapValues(displayShortcutList, (/** @type {WPKeyHandler<string[]>} */shortcutList) => {
   353   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('');
   356   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('');
   354 });
   357 });
   355 
   358 
   356 /**
   359 /**
   357  * An object that contains functions to return an aria label for a keyboard
   360  * An object that contains functions to return an aria label for a keyboard
   365  * ```
   368  * ```
   366  *
   369  *
   367  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
   370  * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
   368  *                                                 shortcut ARIA labels.
   371  *                                                 shortcut ARIA labels.
   369  */
   372  */
   370 const shortcutAriaLabel = mapValues(modifiers, ( /** @type {WPModifier} */modifier) => {
   373 const shortcutAriaLabel = /* @__PURE__ */
       
   374 mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
   371   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => {
   375   return /** @type {WPKeyHandler<string>} */(character, _isApple = isAppleOS) => {
   372     const isApple = _isApple();
   376     const isApple = _isApple();
   373     /** @type {Record<string,string>} */
   377     /** @type {Record<string,string>} */
   374     const replacementKeyMap = {
   378     const replacementKeyMap = {
   375       [SHIFT]: 'Shift',
   379       [SHIFT]: 'Shift',
   399  * @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event.
   403  * @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event.
   400  *
   404  *
   401  * @return {Array<WPModifierPart>} Active modifier constants.
   405  * @return {Array<WPModifierPart>} Active modifier constants.
   402  */
   406  */
   403 function getEventModifiers(event) {
   407 function getEventModifiers(event) {
   404   return /** @type {WPModifierPart[]} */[ALT, CTRL, COMMAND, SHIFT].filter(key => event[( /** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
   408   return /** @type {WPModifierPart[]} */[ALT, CTRL, COMMAND, SHIFT].filter(key => event[(/** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */
   405   `${key}Key`)]);
   409   `${key}Key`)]);
   406 }
   410 }
   407 
   411 
   408 /**
   412 /**
   409  * An object that contains functions to check if a keyboard event matches a
   413  * An object that contains functions to check if a keyboard event matches a
   417  * ```
   421  * ```
   418  *
   422  *
   419  * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
   423  * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
   420  *                                                       to match events.
   424  *                                                       to match events.
   421  */
   425  */
   422 const isKeyboardEvent = mapValues(modifiers, ( /** @type {WPModifier} */getModifiers) => {
   426 const isKeyboardEvent = /* @__PURE__ */
       
   427 mapValues(modifiers, (/** @type {WPModifier} */getModifiers) => {
   423   return /** @type {WPEventKeyHandler} */(event, character, _isApple = isAppleOS) => {
   428   return /** @type {WPEventKeyHandler} */(event, character, _isApple = isAppleOS) => {
   424     const mods = getModifiers(_isApple);
   429     const mods = getModifiers(_isApple);
   425     const eventMods = getEventModifiers(event);
   430     const eventMods = getEventModifiers(event);
   426     /** @type {Record<string,string>} */
   431     /** @type {Record<string,string>} */
   427     const replacementWithShiftKeyMap = {
   432     const replacementWithShiftKeyMap = {
   436     if (modsDiff.length > 0 || eventModsDiff.length > 0) {
   441     if (modsDiff.length > 0 || eventModsDiff.length > 0) {
   437       return false;
   442       return false;
   438     }
   443     }
   439     let key = event.key.toLowerCase();
   444     let key = event.key.toLowerCase();
   440     if (!character) {
   445     if (!character) {
   441       return mods.includes( /** @type {WPModifierPart} */key);
   446       return mods.includes(/** @type {WPModifierPart} */key);
   442     }
   447     }
   443     if (event.altKey && character.length === 1) {
   448     if (event.altKey && character.length === 1) {
   444       key = String.fromCharCode(event.keyCode).toLowerCase();
   449       key = String.fromCharCode(event.keyCode).toLowerCase();
   445     }
   450     }
   446 
   451