Skip to content

Commit

Permalink
Keycodes: improve tree shaking by annotating exports as pure (#67615)
Browse files Browse the repository at this point in the history
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: sgomes <[email protected]>
  • Loading branch information
5 people authored and michalczaplinski committed Dec 5, 2024
1 parent c8bcda8 commit 6be0083
Showing 1 changed file with 27 additions and 29 deletions.
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__ */
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();
};
}
);
} );

0 comments on commit 6be0083

Please sign in to comment.