Skip to content

Commit

Permalink
keycodes: set up auto-generated API docs (#14265)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Mar 6, 2019
1 parent 7d98658 commit 078041b
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const packages = [
'escape-html',
'html-entities',
//'i18n',
//'keycodes',
'keycodes',
//'plugins',
//'priority-queue',
//'redux-routine',
Expand Down
169 changes: 169 additions & 0 deletions packages/keycodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,173 @@ onKeyDown( event ) {
}
```

## API

<!-- START TOKEN(Autogenerated API docs) -->

### 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.


<!-- END TOKEN(Autogenerated API docs) -->

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
62 changes: 60 additions & 2 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],
Expand Down

0 comments on commit 078041b

Please sign in to comment.