@wordpress/keycodes 4.51.0 → 4.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +14 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/with-ignore-ime-events.cjs +42 -0
- package/build/with-ignore-ime-events.cjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/with-ignore-ime-events.mjs +17 -0
- package/build-module/with-ignore-ime-events.mjs.map +7 -0
- package/build-types/index.d.ts +2 -17
- package/build-types/index.d.ts.map +1 -1
- package/build-types/with-ignore-ime-events.d.ts +14 -0
- package/build-types/with-ignore-ime-events.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +2 -13
- package/src/test/index.ts +0 -3
- package/src/test/platform.ts +0 -3
- package/src/test/with-ignore-ime-events.ts +65 -0
- package/src/with-ignore-ime-events.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.53.0 (2026-08-12)
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- Add `withIgnoreIMEEvents`, a helper that wraps a keydown handler so it ignores events fired during an IME composition. Previously a private API of `@wordpress/components` ([#81343](https://github.com/WordPress/gutenberg/pull/81343)).
|
|
10
|
+
|
|
11
|
+
## 4.52.0 (2026-07-29)
|
|
12
|
+
|
|
5
13
|
## 4.51.0 (2026-07-14)
|
|
6
14
|
|
|
7
15
|
### Enhancements
|
package/README.md
CHANGED
|
@@ -237,6 +237,20 @@ Keycode for TAB key.
|
|
|
237
237
|
|
|
238
238
|
Keycode for UP key.
|
|
239
239
|
|
|
240
|
+
### withIgnoreIMEEvents
|
|
241
|
+
|
|
242
|
+
A higher-order function that wraps a keyboard event handler to ensure it is not an IME event.
|
|
243
|
+
|
|
244
|
+
In CJK languages, an IME (Input Method Editor) is used to input complex characters. During an IME composition, keyboard events (e.g. Enter or Escape) can be fired which are intended to control the IME and not the application. These events should be ignored by any application logic.
|
|
245
|
+
|
|
246
|
+
_Parameters_
|
|
247
|
+
|
|
248
|
+
- _handler_ `( event: E ) => void`: The keyboard event handler to execute after ensuring it was not an IME event.
|
|
249
|
+
|
|
250
|
+
_Returns_
|
|
251
|
+
|
|
252
|
+
- A wrapped version of the given event handler that ignores IME events.
|
|
253
|
+
|
|
240
254
|
### ZERO
|
|
241
255
|
|
|
242
256
|
Keycode for ZERO key.
|
package/build/index.cjs
CHANGED
|
@@ -47,11 +47,13 @@ __export(index_exports, {
|
|
|
47
47
|
isKeyboardEvent: () => isKeyboardEvent,
|
|
48
48
|
modifiers: () => modifiers,
|
|
49
49
|
rawShortcut: () => rawShortcut,
|
|
50
|
-
shortcutAriaLabel: () => shortcutAriaLabel
|
|
50
|
+
shortcutAriaLabel: () => shortcutAriaLabel,
|
|
51
|
+
withIgnoreIMEEvents: () => import_with_ignore_ime_events.withIgnoreIMEEvents
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(index_exports);
|
|
53
54
|
var import_i18n = require("@wordpress/i18n");
|
|
54
55
|
var import_platform = require("./platform.cjs");
|
|
56
|
+
var import_with_ignore_ime_events = require("./with-ignore-ime-events.cjs");
|
|
55
57
|
var BACKSPACE = 8;
|
|
56
58
|
var TAB = 9;
|
|
57
59
|
var ENTER = 13;
|
|
@@ -238,6 +240,7 @@ var isKeyboardEvent = /* @__PURE__ */ mapValues(modifiers, (getModifiers) => {
|
|
|
238
240
|
isKeyboardEvent,
|
|
239
241
|
modifiers,
|
|
240
242
|
rawShortcut,
|
|
241
|
-
shortcutAriaLabel
|
|
243
|
+
shortcutAriaLabel,
|
|
244
|
+
withIgnoreIMEEvents
|
|
242
245
|
});
|
|
243
246
|
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isAppleOS } from './platform';\n\n/**\n * External dependencies\n */\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\nexport type WPModifierPart =\n\t| typeof ALT\n\t| typeof CTRL\n\t| typeof COMMAND\n\t| typeof SHIFT;\n\nexport type WPKeycodeModifier =\n\t| 'primary'\n\t| 'primaryShift'\n\t| 'primaryAlt'\n\t| 'secondary'\n\t| 'access'\n\t| 'ctrl'\n\t| 'alt'\n\t| 'ctrlShift'\n\t| 'shift'\n\t| 'shiftAlt'\n\t| 'undefined';\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n */\nexport type WPModifierHandler< T > = Record< WPKeycodeModifier, T >;\n\nexport type WPKeyHandler< T > = (\n\tcharacter: string,\n\tisApple?: () => boolean\n) => T;\n\nexport type WPEventKeyHandler = (\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent,\n\tcharacter: string,\n\tisApple?: () => boolean\n) => boolean;\n\nexport type WPModifier = ( isApple: () => boolean ) => WPModifierPart[];\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\n\n/**\n * Capitalise the first character of a string.\n * @param string String to capitalise.\n * @return Capitalised string.\n */\nfunction capitaliseFirstCharacter( string: string ): string {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template T The object type\n * @template R The return type of the mapping function\n *\n * @param object Object to map values of.\n * @param mapFn Mapping function to apply to each value.\n * @return Object with the same keys and transformed values.\n */\nfunction mapValues< T extends Record< string, any >, R >(\n\tobject: T,\n\tmapFn: ( value: T[ keyof T ] ) => R\n): Record< keyof T, R > {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t) as Record< keyof T, R >;\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: WPModifierHandler< WPModifier > = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for use with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\n * ```\n */\nexport const rawShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * An object that contains functions to get shortcuts in a format compatible\n * with the [`aria-keyshortcuts` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts).\n *\n * **Note**: The provided shortcut character strings (ie. not the modifiers) should follow\n * the values specified in the [UI Events KeyboardEvent key Values spec](https://www.w3.org/TR/uievents-key/) — for example, \"Enter\", \"Tab\", \"ArrowRight\", \"PageDown\",\n * \"Escape\", \"Plus\", or \"F1\". The spacebar key should be represented with the\n * \"Space\" string (an exception to the UI Events KeyboardEvent key Values spec).\n *\n * @see https://www.w3.org/TR/wai-aria-1.2/#aria-keyshortcuts\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts\n * @see https://www.w3.org/TR/uievents-key/\n *\n * @example\n * ```js\n * // Assuming macOS:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Meta+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Meta+Alt+M\"\n *\n * // Assuming Windows:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Control+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Control+Alt+M\"\n *\n * ariaKeyShortcut.primaryShift( 'del' )\n * // \"Control+Shift+Delete\"\n * ```\n */\nexport const ariaKeyShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [\n\t\t\t\t...modifier( _isApple )\n\t\t\t\t\t// Swap 'ctrl' for 'control' (spec-compliant)\n\t\t\t\t\t.map( ( key ) => ( key === CTRL ? 'Control' : key ) )\n\t\t\t\t\t.map( ( key ) => capitaliseFirstCharacter( key ) ),\n\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t].join( '+' );\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * Keyed map of functions to shortcut sequences.\n */\nexport const displayShortcutList: WPModifierHandler<\n\tWPKeyHandler< string[] >\n> =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tmodifiers,\n\t\t( modifier: WPModifier ): WPKeyHandler< string[] > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\t\tconst isApple = _isApple();\n\t\t\t\tconst replacementKeyMap = {\n\t\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t\t};\n\n\t\t\t\tconst modifierKeys = modifier( _isApple ).reduce< string[] >(\n\t\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\t\treturn [\n\t\t\t\t\t...modifierKeys,\n\t\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t\t];\n\t\t\t};\n\t\t}\n\t);\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * Keyed map of functions to display shortcuts.\n */\nexport const displayShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( shortcutList: WPKeyHandler< string[] > ): WPKeyHandler< string > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) =>\n\t\t\t\tshortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * Keyed map of functions to shortcut ARIA labels.\n */\nexport const shortcutAriaLabel: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ): WPKeyHandler< string > => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap: Record< string, string > = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param event Keyboard event.\n *\n * @return Active modifier constants.\n */\nfunction getEventModifiers(\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent\n): WPModifierPart[] {\n\treturn ( [ ALT, CTRL, COMMAND, SHIFT ] as const ).filter(\n\t\t( key ) =>\n\t\t\t( event as KeyboardEvent )[\n\t\t\t\t`${ key }Key` as 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * Keyed map of functions to match events.\n */\nexport const isKeyboardEvent: WPModifierHandler< WPEventKeyHandler > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( getModifiers: WPModifier ): WPEventKeyHandler => {\n\t\treturn ( event, character, _isApple = isAppleOS ) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\n\t\t\tconst replacementWithShiftKeyMap: Record< string, string > = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( key as WPModifierPart );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\nimport { __ } from '@wordpress/i18n';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport { isAppleOS } from './platform';\n\nexport type WPModifierPart =\n\t| typeof ALT\n\t| typeof CTRL\n\t| typeof COMMAND\n\t| typeof SHIFT;\n\nexport type WPKeycodeModifier =\n\t| 'primary'\n\t| 'primaryShift'\n\t| 'primaryAlt'\n\t| 'secondary'\n\t| 'access'\n\t| 'ctrl'\n\t| 'alt'\n\t| 'ctrlShift'\n\t| 'shift'\n\t| 'shiftAlt'\n\t| 'undefined';\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n */\nexport type WPModifierHandler< T > = Record< WPKeycodeModifier, T >;\n\nexport type WPKeyHandler< T > = (\n\tcharacter: string,\n\tisApple?: () => boolean\n) => T;\n\nexport type WPEventKeyHandler = (\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent,\n\tcharacter: string,\n\tisApple?: () => boolean\n) => boolean;\n\nexport type WPModifier = ( isApple: () => boolean ) => WPModifierPart[];\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\nexport { withIgnoreIMEEvents } from './with-ignore-ime-events';\n\n/**\n * Capitalise the first character of a string.\n * @param string String to capitalise.\n * @return Capitalised string.\n */\nfunction capitaliseFirstCharacter( string: string ): string {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template T The object type\n * @template R The return type of the mapping function\n *\n * @param object Object to map values of.\n * @param mapFn Mapping function to apply to each value.\n * @return Object with the same keys and transformed values.\n */\nfunction mapValues< T extends Record< string, any >, R >(\n\tobject: T,\n\tmapFn: ( value: T[ keyof T ] ) => R\n): Record< keyof T, R > {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t) as Record< keyof T, R >;\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: WPModifierHandler< WPModifier > = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for use with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\n * ```\n */\nexport const rawShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * An object that contains functions to get shortcuts in a format compatible\n * with the [`aria-keyshortcuts` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts).\n *\n * **Note**: The provided shortcut character strings (ie. not the modifiers) should follow\n * the values specified in the [UI Events KeyboardEvent key Values spec](https://www.w3.org/TR/uievents-key/) — for example, \"Enter\", \"Tab\", \"ArrowRight\", \"PageDown\",\n * \"Escape\", \"Plus\", or \"F1\". The spacebar key should be represented with the\n * \"Space\" string (an exception to the UI Events KeyboardEvent key Values spec).\n *\n * @see https://www.w3.org/TR/wai-aria-1.2/#aria-keyshortcuts\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts\n * @see https://www.w3.org/TR/uievents-key/\n *\n * @example\n * ```js\n * // Assuming macOS:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Meta+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Meta+Alt+M\"\n *\n * // Assuming Windows:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Control+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Control+Alt+M\"\n *\n * ariaKeyShortcut.primaryShift( 'del' )\n * // \"Control+Shift+Delete\"\n * ```\n */\nexport const ariaKeyShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [\n\t\t\t\t...modifier( _isApple )\n\t\t\t\t\t// Swap 'ctrl' for 'control' (spec-compliant)\n\t\t\t\t\t.map( ( key ) => ( key === CTRL ? 'Control' : key ) )\n\t\t\t\t\t.map( ( key ) => capitaliseFirstCharacter( key ) ),\n\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t].join( '+' );\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * Keyed map of functions to shortcut sequences.\n */\nexport const displayShortcutList: WPModifierHandler<\n\tWPKeyHandler< string[] >\n> =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tmodifiers,\n\t\t( modifier: WPModifier ): WPKeyHandler< string[] > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\t\tconst isApple = _isApple();\n\t\t\t\tconst replacementKeyMap = {\n\t\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t\t};\n\n\t\t\t\tconst modifierKeys = modifier( _isApple ).reduce< string[] >(\n\t\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\t\treturn [\n\t\t\t\t\t...modifierKeys,\n\t\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t\t];\n\t\t\t};\n\t\t}\n\t);\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * Keyed map of functions to display shortcuts.\n */\nexport const displayShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( shortcutList: WPKeyHandler< string[] > ): WPKeyHandler< string > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) =>\n\t\t\t\tshortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * Keyed map of functions to shortcut ARIA labels.\n */\nexport const shortcutAriaLabel: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ): WPKeyHandler< string > => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap: Record< string, string > = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param event Keyboard event.\n *\n * @return Active modifier constants.\n */\nfunction getEventModifiers(\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent\n): WPModifierPart[] {\n\treturn ( [ ALT, CTRL, COMMAND, SHIFT ] as const ).filter(\n\t\t( key ) =>\n\t\t\t( event as KeyboardEvent )[\n\t\t\t\t`${ key }Key` as 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * Keyed map of functions to match events.\n */\nexport const isKeyboardEvent: WPModifierHandler< WPEventKeyHandler > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( getModifiers: WPModifier ): WPEventKeyHandler => {\n\t\treturn ( event, character, _isApple = isAppleOS ) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\n\t\t\tconst replacementWithShiftKeyMap: Record< string, string > = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( key as WPModifierPart );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAAmB;AAEnB,sBAA0B;AA6I1B,oCAAoC;AAlG7B,IAAM,YAAY;AAKlB,IAAM,MAAM;AAKZ,IAAM,QAAQ;AAKd,IAAM,SAAS;AAKf,IAAM,QAAQ;AAKd,IAAM,SAAS;AAKf,IAAM,WAAW;AAKjB,IAAM,MAAM;AAKZ,IAAM,OAAO;AAKb,IAAM,OAAO;AAKb,IAAM,KAAK;AAKX,IAAM,QAAQ;AAKd,IAAM,OAAO;AAKb,IAAM,SAAS;AAKf,IAAM,MAAM;AAKZ,IAAM,MAAM;AAKZ,IAAM,OAAO;AAKb,IAAM,UAAU;AAKhB,IAAM,QAAQ;AAKd,IAAM,OAAO;AAUpB,SAAS,yBAA0B,QAAyB;AAC3D,SAAO,OAAO,SAAS,IACpB,OAAO,YAAY,IACnB,OAAO,OAAQ,CAAE,EAAE,YAAY,IAAI,OAAO,MAAO,CAAE;AACvD;AAYA,SAAS,UACR,QACA,OACuB;AACvB,SAAO,OAAO;AAAA,IACb,OAAO,QAAS,MAAO,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO;AAAA,MACnD;AAAA,MACA,MAAO,KAAM;AAAA,IACd,CAAE;AAAA,EACH;AACD;AAMO,IAAM,YAA6C;AAAA,EACzD,SAAS,CAAE,aAAgB,SAAS,IAAI,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ict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/keycodes/src/with-ignore-ime-events.ts
|
|
21
|
+
var with_ignore_ime_events_exports = {};
|
|
22
|
+
__export(with_ignore_ime_events_exports, {
|
|
23
|
+
withIgnoreIMEEvents: () => withIgnoreIMEEvents
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(with_ignore_ime_events_exports);
|
|
26
|
+
function withIgnoreIMEEvents(handler) {
|
|
27
|
+
return (event) => {
|
|
28
|
+
const { isComposing } = "nativeEvent" in event ? event.nativeEvent : event;
|
|
29
|
+
if (isComposing || // Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
30
|
+
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
31
|
+
// These can only be detected by keyCode.
|
|
32
|
+
event.keyCode === 229) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
handler(event);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
withIgnoreIMEEvents
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=with-ignore-ime-events.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/with-ignore-ime-events.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A higher-order function that wraps a keyboard event handler to ensure it is not an IME event.\n *\n * In CJK languages, an IME (Input Method Editor) is used to input complex characters.\n * During an IME composition, keyboard events (e.g. Enter or Escape) can be fired\n * which are intended to control the IME and not the application.\n * These events should be ignored by any application logic.\n *\n * @param handler The keyboard event handler to execute after ensuring it was not an IME event.\n *\n * @return A wrapped version of the given event handler that ignores IME events.\n */\nexport function withIgnoreIMEEvents<\n\tE extends React.KeyboardEvent | KeyboardEvent,\n>( handler: ( event: E ) => void ) {\n\treturn ( event: E ) => {\n\t\tconst { isComposing } =\n\t\t\t'nativeEvent' in event ? event.nativeEvent : event;\n\n\t\tif (\n\t\t\tisComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\thandler( event );\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,oBAEb,SAAgC;AAClC,SAAO,CAAE,UAAc;AACtB,UAAM,EAAE,YAAY,IACnB,iBAAiB,QAAQ,MAAM,cAAc;AAE9C,QACC;AAAA;AAAA;AAAA,IAIA,MAAM,YAAY,KACjB;AACD;AAAA,IACD;AAEA,YAAS,KAAM;AAAA,EAChB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// packages/keycodes/src/index.ts
|
|
2
2
|
import { __ } from "@wordpress/i18n";
|
|
3
3
|
import { isAppleOS } from "./platform.mjs";
|
|
4
|
+
import { withIgnoreIMEEvents } from "./with-ignore-ime-events.mjs";
|
|
4
5
|
var BACKSPACE = 8;
|
|
5
6
|
var TAB = 9;
|
|
6
7
|
var ENTER = 13;
|
|
@@ -186,6 +187,7 @@ export {
|
|
|
186
187
|
isKeyboardEvent,
|
|
187
188
|
modifiers,
|
|
188
189
|
rawShortcut,
|
|
189
|
-
shortcutAriaLabel
|
|
190
|
+
shortcutAriaLabel,
|
|
191
|
+
withIgnoreIMEEvents
|
|
190
192
|
};
|
|
191
193
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isAppleOS } from './platform';\n\n/**\n * External dependencies\n */\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\nexport type WPModifierPart =\n\t| typeof ALT\n\t| typeof CTRL\n\t| typeof COMMAND\n\t| typeof SHIFT;\n\nexport type WPKeycodeModifier =\n\t| 'primary'\n\t| 'primaryShift'\n\t| 'primaryAlt'\n\t| 'secondary'\n\t| 'access'\n\t| 'ctrl'\n\t| 'alt'\n\t| 'ctrlShift'\n\t| 'shift'\n\t| 'shiftAlt'\n\t| 'undefined';\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n */\nexport type WPModifierHandler< T > = Record< WPKeycodeModifier, T >;\n\nexport type WPKeyHandler< T > = (\n\tcharacter: string,\n\tisApple?: () => boolean\n) => T;\n\nexport type WPEventKeyHandler = (\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent,\n\tcharacter: string,\n\tisApple?: () => boolean\n) => boolean;\n\nexport type WPModifier = ( isApple: () => boolean ) => WPModifierPart[];\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\n\n/**\n * Capitalise the first character of a string.\n * @param string String to capitalise.\n * @return Capitalised string.\n */\nfunction capitaliseFirstCharacter( string: string ): string {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template T The object type\n * @template R The return type of the mapping function\n *\n * @param object Object to map values of.\n * @param mapFn Mapping function to apply to each value.\n * @return Object with the same keys and transformed values.\n */\nfunction mapValues< T extends Record< string, any >, R >(\n\tobject: T,\n\tmapFn: ( value: T[ keyof T ] ) => R\n): Record< keyof T, R > {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t) as Record< keyof T, R >;\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: WPModifierHandler< WPModifier > = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for use with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\n * ```\n */\nexport const rawShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * An object that contains functions to get shortcuts in a format compatible\n * with the [`aria-keyshortcuts` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts).\n *\n * **Note**: The provided shortcut character strings (ie. not the modifiers) should follow\n * the values specified in the [UI Events KeyboardEvent key Values spec](https://www.w3.org/TR/uievents-key/) — for example, \"Enter\", \"Tab\", \"ArrowRight\", \"PageDown\",\n * \"Escape\", \"Plus\", or \"F1\". The spacebar key should be represented with the\n * \"Space\" string (an exception to the UI Events KeyboardEvent key Values spec).\n *\n * @see https://www.w3.org/TR/wai-aria-1.2/#aria-keyshortcuts\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts\n * @see https://www.w3.org/TR/uievents-key/\n *\n * @example\n * ```js\n * // Assuming macOS:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Meta+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Meta+Alt+M\"\n *\n * // Assuming Windows:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Control+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Control+Alt+M\"\n *\n * ariaKeyShortcut.primaryShift( 'del' )\n * // \"Control+Shift+Delete\"\n * ```\n */\nexport const ariaKeyShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [\n\t\t\t\t...modifier( _isApple )\n\t\t\t\t\t// Swap 'ctrl' for 'control' (spec-compliant)\n\t\t\t\t\t.map( ( key ) => ( key === CTRL ? 'Control' : key ) )\n\t\t\t\t\t.map( ( key ) => capitaliseFirstCharacter( key ) ),\n\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t].join( '+' );\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * Keyed map of functions to shortcut sequences.\n */\nexport const displayShortcutList: WPModifierHandler<\n\tWPKeyHandler< string[] >\n> =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tmodifiers,\n\t\t( modifier: WPModifier ): WPKeyHandler< string[] > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\t\tconst isApple = _isApple();\n\t\t\t\tconst replacementKeyMap = {\n\t\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t\t};\n\n\t\t\t\tconst modifierKeys = modifier( _isApple ).reduce< string[] >(\n\t\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\t\treturn [\n\t\t\t\t\t...modifierKeys,\n\t\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t\t];\n\t\t\t};\n\t\t}\n\t);\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * Keyed map of functions to display shortcuts.\n */\nexport const displayShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( shortcutList: WPKeyHandler< string[] > ): WPKeyHandler< string > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) =>\n\t\t\t\tshortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * Keyed map of functions to shortcut ARIA labels.\n */\nexport const shortcutAriaLabel: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ): WPKeyHandler< string > => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap: Record< string, string > = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param event Keyboard event.\n *\n * @return Active modifier constants.\n */\nfunction getEventModifiers(\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent\n): WPModifierPart[] {\n\treturn ( [ ALT, CTRL, COMMAND, SHIFT ] as const ).filter(\n\t\t( key ) =>\n\t\t\t( event as KeyboardEvent )[\n\t\t\t\t`${ key }Key` as 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * Keyed map of functions to match events.\n */\nexport const isKeyboardEvent: WPModifierHandler< WPEventKeyHandler > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( getModifiers: WPModifier ): WPEventKeyHandler => {\n\t\treturn ( event, character, _isApple = isAppleOS ) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\n\t\t\tconst replacementWithShiftKeyMap: Record< string, string > = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( key as WPModifierPart );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\nimport { __ } from '@wordpress/i18n';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport { isAppleOS } from './platform';\n\nexport type WPModifierPart =\n\t| typeof ALT\n\t| typeof CTRL\n\t| typeof COMMAND\n\t| typeof SHIFT;\n\nexport type WPKeycodeModifier =\n\t| 'primary'\n\t| 'primaryShift'\n\t| 'primaryAlt'\n\t| 'secondary'\n\t| 'access'\n\t| 'ctrl'\n\t| 'alt'\n\t| 'ctrlShift'\n\t| 'shift'\n\t| 'shiftAlt'\n\t| 'undefined';\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n */\nexport type WPModifierHandler< T > = Record< WPKeycodeModifier, T >;\n\nexport type WPKeyHandler< T > = (\n\tcharacter: string,\n\tisApple?: () => boolean\n) => T;\n\nexport type WPEventKeyHandler = (\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent,\n\tcharacter: string,\n\tisApple?: () => boolean\n) => boolean;\n\nexport type WPModifier = ( isApple: () => boolean ) => WPModifierPart[];\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\nexport { withIgnoreIMEEvents } from './with-ignore-ime-events';\n\n/**\n * Capitalise the first character of a string.\n * @param string String to capitalise.\n * @return Capitalised string.\n */\nfunction capitaliseFirstCharacter( string: string ): string {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template T The object type\n * @template R The return type of the mapping function\n *\n * @param object Object to map values of.\n * @param mapFn Mapping function to apply to each value.\n * @return Object with the same keys and transformed values.\n */\nfunction mapValues< T extends Record< string, any >, R >(\n\tobject: T,\n\tmapFn: ( value: T[ keyof T ] ) => R\n): Record< keyof T, R > {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t) as Record< keyof T, R >;\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: WPModifierHandler< WPModifier > = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for use with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\n * ```\n */\nexport const rawShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * An object that contains functions to get shortcuts in a format compatible\n * with the [`aria-keyshortcuts` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts).\n *\n * **Note**: The provided shortcut character strings (ie. not the modifiers) should follow\n * the values specified in the [UI Events KeyboardEvent key Values spec](https://www.w3.org/TR/uievents-key/) — for example, \"Enter\", \"Tab\", \"ArrowRight\", \"PageDown\",\n * \"Escape\", \"Plus\", or \"F1\". The spacebar key should be represented with the\n * \"Space\" string (an exception to the UI Events KeyboardEvent key Values spec).\n *\n * @see https://www.w3.org/TR/wai-aria-1.2/#aria-keyshortcuts\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-keyshortcuts\n * @see https://www.w3.org/TR/uievents-key/\n *\n * @example\n * ```js\n * // Assuming macOS:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Meta+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Meta+Alt+M\"\n *\n * // Assuming Windows:\n * ariaKeyShortcut.primary( 'm' )\n * // \"Control+M\"\n *\n * ariaKeyShortcut.primaryAlt( 'm' )\n * // \"Control+Alt+M\"\n *\n * ariaKeyShortcut.primaryShift( 'del' )\n * // \"Control+Shift+Delete\"\n * ```\n */\nexport const ariaKeyShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [\n\t\t\t\t...modifier( _isApple )\n\t\t\t\t\t// Swap 'ctrl' for 'control' (spec-compliant)\n\t\t\t\t\t.map( ( key ) => ( key === CTRL ? 'Control' : key ) )\n\t\t\t\t\t.map( ( key ) => capitaliseFirstCharacter( key ) ),\n\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t].join( '+' );\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * Keyed map of functions to shortcut sequences.\n */\nexport const displayShortcutList: WPModifierHandler<\n\tWPKeyHandler< string[] >\n> =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tmodifiers,\n\t\t( modifier: WPModifier ): WPKeyHandler< string[] > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\t\tconst isApple = _isApple();\n\t\t\t\tconst replacementKeyMap = {\n\t\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t\t};\n\n\t\t\t\tconst modifierKeys = modifier( _isApple ).reduce< string[] >(\n\t\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\t\treturn [\n\t\t\t\t\t...modifierKeys,\n\t\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t\t];\n\t\t\t};\n\t\t}\n\t);\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * Keyed map of functions to display shortcuts.\n */\nexport const displayShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( shortcutList: WPKeyHandler< string[] > ): WPKeyHandler< string > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) =>\n\t\t\t\tshortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * Keyed map of functions to shortcut ARIA labels.\n */\nexport const shortcutAriaLabel: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ): WPKeyHandler< string > => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap: Record< string, string > = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param event Keyboard event.\n *\n * @return Active modifier constants.\n */\nfunction getEventModifiers(\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent\n): WPModifierPart[] {\n\treturn ( [ ALT, CTRL, COMMAND, SHIFT ] as const ).filter(\n\t\t( key ) =>\n\t\t\t( event as KeyboardEvent )[\n\t\t\t\t`${ key }Key` as 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * Keyed map of functions to match events.\n */\nexport const isKeyboardEvent: WPModifierHandler< WPEventKeyHandler > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( getModifiers: WPModifier ): WPEventKeyHandler => {\n\t\treturn ( event, character, _isApple = isAppleOS ) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\n\t\t\tconst replacementWithShiftKeyMap: Record< string, string > = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( key as WPModifierPart );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],
|
|
5
|
+
"mappings": ";AAUA,SAAS,UAAU;AAEnB,SAAS,iBAAiB;AA6I1B,SAAS,2BAA2B;AAlG7B,IAAM,YAAY;AAKlB,IAAM,MAAM;AAKZ,IAAM,QAAQ;AAKd,IAAM,SAAS;AAKf,IAAM,QAAQ;AAKd,IAAM,SAAS;AAKf,IAAM,WAAW;AAKjB,IAAM,MAAM;AAKZ,IAAM,OAAO;AAKb,IAAM,OAAO;AAKb,IAAM,KAAK;AAKX,IAAM,QAAQ;AAKd,IAAM,OAAO;AAKb,IAAM,SAAS;AAKf,IAAM,MAAM;AAKZ,IAAM,MAAM;AAKZ,IAAM,OAAO;AAKb,IAAM,UAAU;AAKhB,IAAM,QAAQ;AAKd,IAAM,OAAO;AAUpB,SAAS,yBAA0B,QAAyB;AAC3D,SAAO,OAAO,SAAS,IACpB,OAAO,YAAY,IACnB,OAAO,OAAQ,CAAE,EAAE,YAAY,IAAI,OAAO,MAAO,CAAE;AACvD;AAYA,SAAS,UACR,QACA,OACuB;AACvB,SAAO,OAAO;AAAA,IACb,OAAO,QAAS,MAAO,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO;AAAA,MACnD;AAAA,MACA,MAAO,KAAM;AAAA,IACd,CAAE;AAAA,EACH;AACD;AAMO,IAAM,YAA6C;AAAA,EACzD,SAAS,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|
1
|
+
// packages/keycodes/src/with-ignore-ime-events.ts
|
|
2
|
+
function withIgnoreIMEEvents(handler) {
|
|
3
|
+
return (event) => {
|
|
4
|
+
const { isComposing } = "nativeEvent" in event ? event.nativeEvent : event;
|
|
5
|
+
if (isComposing || // Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
6
|
+
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
7
|
+
// These can only be detected by keyCode.
|
|
8
|
+
event.keyCode === 229) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
handler(event);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
withIgnoreIMEEvents
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=with-ignore-ime-events.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/with-ignore-ime-events.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A higher-order function that wraps a keyboard event handler to ensure it is not an IME event.\n *\n * In CJK languages, an IME (Input Method Editor) is used to input complex characters.\n * During an IME composition, keyboard events (e.g. Enter or Escape) can be fired\n * which are intended to control the IME and not the application.\n * These events should be ignored by any application logic.\n *\n * @param handler The keyboard event handler to execute after ensuring it was not an IME event.\n *\n * @return A wrapped version of the given event handler that ignores IME events.\n */\nexport function withIgnoreIMEEvents<\n\tE extends React.KeyboardEvent | KeyboardEvent,\n>( handler: ( event: E ) => void ) {\n\treturn ( event: E ) => {\n\t\tconst { isComposing } =\n\t\t\t'nativeEvent' in event ? event.nativeEvent : event;\n\n\t\tif (\n\t\t\tisComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\thandler( event );\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAYO,SAAS,oBAEb,SAAgC;AAClC,SAAO,CAAE,UAAc;AACtB,UAAM,EAAE,YAAY,IACnB,iBAAiB,QAAQ,MAAM,cAAc;AAE9C,QACC;AAAA;AAAA;AAAA,IAIA,MAAM,YAAY,KACjB;AACD;AAAA,IACD;AAEA,YAAS,KAAM;AAAA,EAChB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Note: The order of the modifier keys in many of the [foo]Shortcut()
|
|
3
|
-
* functions in this file are intentional and should not be changed. They're
|
|
4
|
-
* designed to fit with the standard menu keyboard shortcuts shown in the
|
|
5
|
-
* user's platform.
|
|
6
|
-
*
|
|
7
|
-
* For example, on MacOS menu shortcuts will place Shift before Command, but
|
|
8
|
-
* on Windows Control will usually come first. So don't provide your own
|
|
9
|
-
* shortcut combos directly to keyboardShortcut().
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { isAppleOS } from './platform';
|
|
15
|
-
/**
|
|
16
|
-
* External dependencies
|
|
17
|
-
*/
|
|
18
1
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
2
|
+
import { isAppleOS } from './platform';
|
|
19
3
|
export type WPModifierPart = typeof ALT | typeof CTRL | typeof COMMAND | typeof SHIFT;
|
|
20
4
|
export type WPKeycodeModifier = 'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined';
|
|
21
5
|
/**
|
|
@@ -107,6 +91,7 @@ export declare const SHIFT = "shift";
|
|
|
107
91
|
*/
|
|
108
92
|
export declare const ZERO = 48;
|
|
109
93
|
export { isAppleOS };
|
|
94
|
+
export { withIgnoreIMEEvents } from './with-ignore-ime-events';
|
|
110
95
|
/**
|
|
111
96
|
* Object that contains functions that return the available modifier
|
|
112
97
|
* depending on platform.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,MAAM,cAAc,GACvB,OAAO,GAAG,GACV,OAAO,IAAI,GACX,OAAO,OAAO,GACd,OAAO,KAAK,CAAC;AAEhB,MAAM,MAAM,iBAAiB,GAC1B,SAAS,GACT,cAAc,GACd,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,MAAM,GACN,KAAK,GACL,WAAW,GACX,OAAO,GACP,UAAU,GACV,WAAW,CAAC;AAEf;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAE,CAAC,IAAK,MAAM,CAAE,iBAAiB,EAAE,CAAC,CAAE,CAAC;AAEpE,MAAM,MAAM,YAAY,CAAE,CAAC,IAAK,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,OAAO,KACnB,CAAC,CAAC;AAEP,MAAM,MAAM,iBAAiB,GAAG,CAC/B,KAAK,EAAE,kBAAkB,CAAE,WAAW,CAAE,GAAG,aAAa,EACxD,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,OAAO,KACnB,OAAO,CAAC;AAEb,MAAM,MAAM,UAAU,GAAG,CAAE,OAAO,EAAE,MAAM,OAAO,KAAM,cAAc,EAAE,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,SAAS,IAAI,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,GAAG,IAAI,CAAC;AAErB;;GAEG;AACH,eAAO,MAAM,KAAK,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,MAA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AACH,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAClD,YAAY,CAAE,MAAM,EAAE,CAAE,CAkCvB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAE,YAAY,CAAE,MAAM,CAAE,CAQrE,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAE,YAAY,CAAE,MAAM,CAAE,CA0BrE,CAAC;AAqBL;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAE,iBAAiB,CAwD9D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A higher-order function that wraps a keyboard event handler to ensure it is not an IME event.
|
|
3
|
+
*
|
|
4
|
+
* In CJK languages, an IME (Input Method Editor) is used to input complex characters.
|
|
5
|
+
* During an IME composition, keyboard events (e.g. Enter or Escape) can be fired
|
|
6
|
+
* which are intended to control the IME and not the application.
|
|
7
|
+
* These events should be ignored by any application logic.
|
|
8
|
+
*
|
|
9
|
+
* @param handler The keyboard event handler to execute after ensuring it was not an IME event.
|
|
10
|
+
*
|
|
11
|
+
* @return A wrapped version of the given event handler that ignores IME events.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withIgnoreIMEEvents<E extends React.KeyboardEvent | KeyboardEvent>(handler: (event: E) => void): (event: E) => void;
|
|
14
|
+
//# sourceMappingURL=with-ignore-ime-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-ignore-ime-events.d.ts","sourceRoot":"","sources":["../src/with-ignore-ime-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAClC,CAAC,SAAS,KAAK,CAAC,aAAa,GAAG,aAAa,EAC3C,OAAO,EAAE,CAAE,KAAK,EAAE,CAAC,KAAM,IAAI,WACf,CAAC,UAgBjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/keycodes",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.53.0",
|
|
4
4
|
"description": "Keycodes utilities for WordPress. Used to check for keyboard events across browsers/operating systems.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"types": "build-types",
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@wordpress/i18n": "^6.
|
|
46
|
+
"@wordpress/i18n": "^6.26.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@types/react": "^18 || ^19"
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "989764d42ff93e33684aaf0b96a5b7f3d9bbff52"
|
|
60
60
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,21 +8,9 @@
|
|
|
8
8
|
* on Windows Control will usually come first. So don't provide your own
|
|
9
9
|
* shortcut combos directly to keyboardShortcut().
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/
|
|
15
11
|
import { __ } from '@wordpress/i18n';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
import { isAppleOS } from './platform';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* External dependencies
|
|
24
|
-
*/
|
|
25
12
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
13
|
+
import { isAppleOS } from './platform';
|
|
26
14
|
|
|
27
15
|
export type WPModifierPart =
|
|
28
16
|
| typeof ALT
|
|
@@ -163,6 +151,7 @@ export const SHIFT = 'shift';
|
|
|
163
151
|
export const ZERO = 48;
|
|
164
152
|
|
|
165
153
|
export { isAppleOS };
|
|
154
|
+
export { withIgnoreIMEEvents } from './with-ignore-ime-events';
|
|
166
155
|
|
|
167
156
|
/**
|
|
168
157
|
* Capitalise the first character of a string.
|
package/src/test/index.ts
CHANGED
package/src/test/platform.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { withIgnoreIMEEvents } from '../with-ignore-ime-events';
|
|
2
|
+
|
|
3
|
+
// Builds a native-shaped keyboard event, i.e. one that carries `isComposing`
|
|
4
|
+
// on the object itself rather than on a `nativeEvent` property.
|
|
5
|
+
function nativeEvent( {
|
|
6
|
+
isComposing = false,
|
|
7
|
+
keyCode = 13,
|
|
8
|
+
}: { isComposing?: boolean; keyCode?: number } = {} ) {
|
|
9
|
+
return { isComposing, keyCode } as unknown as KeyboardEvent;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Builds a React-shaped synthetic event, which reads `isComposing` from its
|
|
13
|
+
// `nativeEvent` but exposes `keyCode` on the synthetic event itself.
|
|
14
|
+
function reactEvent( {
|
|
15
|
+
isComposing = false,
|
|
16
|
+
keyCode = 13,
|
|
17
|
+
}: { isComposing?: boolean; keyCode?: number } = {} ) {
|
|
18
|
+
return {
|
|
19
|
+
keyCode,
|
|
20
|
+
nativeEvent: { isComposing },
|
|
21
|
+
} as unknown as React.KeyboardEvent;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe( 'withIgnoreIMEEvents', () => {
|
|
25
|
+
it( 'calls the handler for a regular key press', () => {
|
|
26
|
+
const handler = jest.fn();
|
|
27
|
+
withIgnoreIMEEvents( handler )( nativeEvent() );
|
|
28
|
+
expect( handler ).toHaveBeenCalledTimes( 1 );
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
it( 'passes the event through to the handler untouched', () => {
|
|
32
|
+
const handler = jest.fn();
|
|
33
|
+
const event = nativeEvent();
|
|
34
|
+
withIgnoreIMEEvents( handler )( event );
|
|
35
|
+
expect( handler ).toHaveBeenCalledWith( event );
|
|
36
|
+
} );
|
|
37
|
+
|
|
38
|
+
it( 'ignores an event fired mid-composition', () => {
|
|
39
|
+
const handler = jest.fn();
|
|
40
|
+
withIgnoreIMEEvents( handler )( nativeEvent( { isComposing: true } ) );
|
|
41
|
+
expect( handler ).not.toHaveBeenCalled();
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
it( 'ignores keyCode 229, which ends a composition in Mac Safari without setting isComposing', () => {
|
|
45
|
+
const handler = jest.fn();
|
|
46
|
+
withIgnoreIMEEvents( handler )( nativeEvent( { keyCode: 229 } ) );
|
|
47
|
+
expect( handler ).not.toHaveBeenCalled();
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
describe( 'React synthetic events', () => {
|
|
51
|
+
it( 'reads isComposing from nativeEvent', () => {
|
|
52
|
+
const handler = jest.fn();
|
|
53
|
+
withIgnoreIMEEvents( handler )(
|
|
54
|
+
reactEvent( { isComposing: true } )
|
|
55
|
+
);
|
|
56
|
+
expect( handler ).not.toHaveBeenCalled();
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
it( 'calls the handler when the composition has finished', () => {
|
|
60
|
+
const handler = jest.fn();
|
|
61
|
+
withIgnoreIMEEvents( handler )( reactEvent() );
|
|
62
|
+
expect( handler ).toHaveBeenCalledTimes( 1 );
|
|
63
|
+
} );
|
|
64
|
+
} );
|
|
65
|
+
} );
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A higher-order function that wraps a keyboard event handler to ensure it is not an IME event.
|
|
3
|
+
*
|
|
4
|
+
* In CJK languages, an IME (Input Method Editor) is used to input complex characters.
|
|
5
|
+
* During an IME composition, keyboard events (e.g. Enter or Escape) can be fired
|
|
6
|
+
* which are intended to control the IME and not the application.
|
|
7
|
+
* These events should be ignored by any application logic.
|
|
8
|
+
*
|
|
9
|
+
* @param handler The keyboard event handler to execute after ensuring it was not an IME event.
|
|
10
|
+
*
|
|
11
|
+
* @return A wrapped version of the given event handler that ignores IME events.
|
|
12
|
+
*/
|
|
13
|
+
export function withIgnoreIMEEvents<
|
|
14
|
+
E extends React.KeyboardEvent | KeyboardEvent,
|
|
15
|
+
>( handler: ( event: E ) => void ) {
|
|
16
|
+
return ( event: E ) => {
|
|
17
|
+
const { isComposing } =
|
|
18
|
+
'nativeEvent' in event ? event.nativeEvent : event;
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
isComposing ||
|
|
22
|
+
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
23
|
+
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
24
|
+
// These can only be detected by keyCode.
|
|
25
|
+
event.keyCode === 229
|
|
26
|
+
) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
handler( event );
|
|
31
|
+
};
|
|
32
|
+
}
|