diff --git a/bin/update-readmes.js b/bin/update-readmes.js index ce9d702bbbba77..d4bf9476710990 100755 --- a/bin/update-readmes.js +++ b/bin/update-readmes.js @@ -23,7 +23,7 @@ const packages = [ 'escape-html', //'html-entities', //'i18n', - //'keycodes', + 'keycodes', //'plugins', //'priority-queue', //'redux-routine', diff --git a/packages/keycodes/README.md b/packages/keycodes/README.md index cb7f5cc6e1ebb9..d99081ed5823c2 100644 --- a/packages/keycodes/README.md +++ b/packages/keycodes/README.md @@ -34,4 +34,173 @@ onKeyDown( event ) { } ``` +## API + + + +### ALT + +[src/index.js#L74-L74](src/index.js#L74-L74) + +Keycode for ALT key. + +### BACKSPACE + +[src/index.js#L30-L30](src/index.js#L30-L30) + +Keycode for BACKSPACE key. + +### COMMAND + +[src/index.js#L82-L82](src/index.js#L82-L82) + +Keycode for COMMAND/META key. + +### CTRL + +[src/index.js#L78-L78](src/index.js#L78-L78) + +Keycode for CTRL key. + +### DELETE + +[src/index.js#L66-L66](src/index.js#L66-L66) + +Keycode for DELETE key. + +### displayShortcut + +[src/index.js#L166-L168](src/index.js#L166-L168) + +An object that contains functions to display shortcuts. +E.g. displayShortcut.primary( 'm' ) will return '⌘M' on Mac. + +**Type** + +`Object` Keyed map of functions to display shortcuts. + +### displayShortcutList + +[src/index.js#L135-L158](src/index.js#L135-L158) + +Return an array of the parts of a keyboard shortcut chord for display +E.g displayShortcutList.primary( 'm' ) will return [ '⌘', 'M' ] on Mac. + +**Type** + +`Object` keyed map of functions to shortcut sequences + +### DOWN + +[src/index.js#L62-L62](src/index.js#L62-L62) + +Keycode for DOWN key. + +### ENTER + +[src/index.js#L38-L38](src/index.js#L38-L38) + +Keycode for ENTER key. + +### ESCAPE + +[src/index.js#L42-L42](src/index.js#L42-L42) + +Keycode for ESCAPE key. + +### F10 + +[src/index.js#L70-L70](src/index.js#L70-L70) + +Keycode for F10 key. + +### isKeyboardEvent + +[src/index.js#L204-L218](src/index.js#L204-L218) + +An object that contains functions to check if a keyboard event matches a +predefined shortcut combination. +E.g. isKeyboardEvent.primary( event, 'm' ) will return true if the event +signals pressing ⌘M. + +**Type** + +`Object` Keyed map of functions to match events. + +### LEFT + +[src/index.js#L50-L50](src/index.js#L50-L50) + +Keycode for LEFT key. + +### modifiers + +[src/index.js#L103-L114](src/index.js#L103-L114) + +Object that contains functions that return the available modifier +depending on platform. + +- `primary`: takes a isApple function as a parameter. +- `primaryShift`: takes a isApple function as a parameter. +- `primaryAlt`: takes a isApple function as a parameter. +- `secondary`: takes a isApple function as a parameter. +- `access`: takes a isApple function as a parameter. +- `ctrl` +- `alt` +- `ctrlShift` +- `shift` +- `shiftAlt` + +### rawShortcut + +[src/index.js#L123-L127](src/index.js#L123-L127) + +An object that contains functions to get raw shortcuts. +E.g. rawShortcut.primary( 'm' ) will return 'meta+m' on Mac. +These are intended for user with the KeyboardShortcuts component or TinyMCE. + +**Type** + +`Object` Keyed map of functions to raw shortcuts. + +### RIGHT + +[src/index.js#L58-L58](src/index.js#L58-L58) + +Keycode for RIGHT key. + +### SHIFT + +[src/index.js#L86-L86](src/index.js#L86-L86) + +Keycode for SHIFT key. + +### shortcutAriaLabel + +[src/index.js#L174-L194](src/index.js#L174-L194) + +An object that contains functions to return an aria label for a keyboard shortcut. +E.g. shortcutAriaLabel.primary( '.' ) will return 'Command + Period' on Mac. + +### SPACE + +[src/index.js#L46-L46](src/index.js#L46-L46) + +Keycode for SPACE key. + +### TAB + +[src/index.js#L34-L34](src/index.js#L34-L34) + +Keycode for TAB key. + +### UP + +[src/index.js#L54-L54](src/index.js#L54-L54) + +Keycode for UP key. + + + +

Code is Poetry.

diff --git a/packages/keycodes/src/index.js b/packages/keycodes/src/index.js index 5465b9df19184d..ea0047a6596f45 100644 --- a/packages/keycodes/src/index.js +++ b/packages/keycodes/src/index.js @@ -24,24 +24,82 @@ import { __ } from '@wordpress/i18n'; */ import { isAppleOS } from './platform'; +/** + * Keycode for BACKSPACE key. + */ export const BACKSPACE = 8; +/** + * Keycode for TAB key. + */ export const TAB = 9; +/** + * Keycode for ENTER key. + */ export const ENTER = 13; +/** + * Keycode for ESCAPE key. + */ export const ESCAPE = 27; +/** + * Keycode for SPACE key. + */ export const SPACE = 32; +/** + * Keycode for LEFT key. + */ export const LEFT = 37; +/** + * Keycode for UP key. + */ export const UP = 38; +/** + * Keycode for RIGHT key. + */ export const RIGHT = 39; +/** + * Keycode for DOWN key. + */ export const DOWN = 40; +/** + * Keycode for DELETE key. + */ export const DELETE = 46; - +/** + * Keycode for F10 key. + */ export const F10 = 121; - +/** + * Keycode for ALT key. + */ export const ALT = 'alt'; +/** + * Keycode for CTRL key. + */ export const CTRL = 'ctrl'; +/** + * Keycode for COMMAND/META key. + */ export const COMMAND = 'meta'; +/** + * Keycode for SHIFT key. + */ export const SHIFT = 'shift'; +/** + * Object that contains functions that return the available modifier + * depending on platform. + * + * - `primary`: takes a isApple function as a parameter. + * - `primaryShift`: takes a isApple function as a parameter. + * - `primaryAlt`: takes a isApple function as a parameter. + * - `secondary`: takes a isApple function as a parameter. + * - `access`: takes a isApple function as a parameter. + * - `ctrl` + * - `alt` + * - `ctrlShift` + * - `shift` + * - `shiftAlt` + */ export const modifiers = { primary: ( _isApple ) => _isApple() ? [ COMMAND ] : [ CTRL ], primaryShift: ( _isApple ) => _isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],