Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export const modifiers = {
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
* shortcuts.
*/
export const rawShortcut = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const rawShortcut =
/* @__PURE__ */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something supported by all bundlers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webpack + Terser combo also supports it. Webpack adds the comment to code that is pure (typically re-exports) and then Terser uses the comment to eliminate the dead code.

mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
Expand All @@ -222,8 +222,7 @@ export const rawShortcut = mapValues(
'+'
);
};
}
);
} );

/**
* Return an array of the parts of a keyboard shortcut chord for display.
Expand All @@ -238,9 +237,9 @@ export const rawShortcut = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to
* shortcut sequences.
*/
export const displayShortcutList = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const displayShortcutList =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string[]>} */ (
character,
_isApple = isAppleOS
Expand Down Expand Up @@ -268,8 +267,7 @@ export const displayShortcutList = mapValues(

return [ ...modifierKeys, capitaliseFirstCharacter( character ) ];
};
}
);
} );

/**
* An object that contains functions to display shortcuts.
Expand All @@ -284,15 +282,17 @@ export const displayShortcutList = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
* display shortcuts.
*/
export const displayShortcut = mapValues(
displayShortcutList,
( /** @type {WPKeyHandler<string[]>} */ shortcutList ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
) => shortcutList( character, _isApple ).join( '' );
}
);
export const displayShortcut =
/* @__PURE__ */
mapValues(
displayShortcutList,
( /** @type {WPKeyHandler<string[]>} */ shortcutList ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
) => shortcutList( character, _isApple ).join( '' );
}
);

/**
* An object that contains functions to return an aria label for a keyboard
Expand All @@ -308,9 +308,9 @@ export const displayShortcut = mapValues(
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to
* shortcut ARIA labels.
*/
export const shortcutAriaLabel = mapValues(
modifiers,
( /** @type {WPModifier} */ modifier ) => {
export const shortcutAriaLabel =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {
return /** @type {WPKeyHandler<string>} */ (
character,
_isApple = isAppleOS
Expand Down Expand Up @@ -338,8 +338,7 @@ export const shortcutAriaLabel = mapValues(
)
.join( isApple ? ' ' : ' + ' );
};
}
);
} );

/**
* From a given KeyboardEvent, returns an array of active modifier constants for
Expand Down Expand Up @@ -379,9 +378,9 @@ function getEventModifiers( event ) {
* @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions
* to match events.
*/
export const isKeyboardEvent = mapValues(
modifiers,
( /** @type {WPModifier} */ getModifiers ) => {
export const isKeyboardEvent =
/* @__PURE__ */
mapValues( modifiers, ( /** @type {WPModifier} */ getModifiers ) => {
return /** @type {WPEventKeyHandler} */ (
event,
character,
Expand Down Expand Up @@ -439,5 +438,4 @@ export const isKeyboardEvent = mapValues(

return key === character.toLowerCase();
};
}
);
} );
Loading