From eb35ffb6dd629ec23a13c1ef2f5110531f7c0f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 1 Mar 2019 20:21:37 +0100 Subject: [PATCH 1/2] Autogenerated docs and setup for keycodes --- packages/keycodes/README.md | 157 +++++++++++++++++++++++++++++++++ packages/keycodes/package.json | 6 ++ 2 files changed, 163 insertions(+) diff --git a/packages/keycodes/README.md b/packages/keycodes/README.md index cb7f5cc6e1ebb9..58fe8dcc836ee0 100644 --- a/packages/keycodes/README.md +++ b/packages/keycodes/README.md @@ -34,4 +34,161 @@ onKeyDown( event ) { } ``` +## API + + + +### ALT + +[src/index.js#L40-L40](src/index.js#L40-L40) + +Undocumented declaration. + +### BACKSPACE + +[src/index.js#L27-L27](src/index.js#L27-L27) + +Undocumented declaration. + +### COMMAND + +[src/index.js#L42-L42](src/index.js#L42-L42) + +Undocumented declaration. + +### CTRL + +[src/index.js#L41-L41](src/index.js#L41-L41) + +Undocumented declaration. + +### DELETE + +[src/index.js#L36-L36](src/index.js#L36-L36) + +Undocumented declaration. + +### displayShortcut + +[src/index.js#L108-L110](src/index.js#L108-L110) + +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#L77-L100](src/index.js#L77-L100) + +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#L35-L35](src/index.js#L35-L35) + +Undocumented declaration. + +### ENTER + +[src/index.js#L29-L29](src/index.js#L29-L29) + +Undocumented declaration. + +### ESCAPE + +[src/index.js#L30-L30](src/index.js#L30-L30) + +Undocumented declaration. + +### F10 + +[src/index.js#L38-L38](src/index.js#L38-L38) + +Undocumented declaration. + +### isKeyboardEvent + +[src/index.js#L146-L160](src/index.js#L146-L160) + +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#L32-L32](src/index.js#L32-L32) + +Undocumented declaration. + +### modifiers + +[src/index.js#L45-L56](src/index.js#L45-L56) + +Undocumented declaration. + +### rawShortcut + +[src/index.js#L65-L69](src/index.js#L65-L69) + +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#L34-L34](src/index.js#L34-L34) + +Undocumented declaration. + +### SHIFT + +[src/index.js#L43-L43](src/index.js#L43-L43) + +Undocumented declaration. + +### shortcutAriaLabel + +[src/index.js#L116-L136](src/index.js#L116-L136) + +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#L31-L31](src/index.js#L31-L31) + +Undocumented declaration. + +### TAB + +[src/index.js#L28-L28](src/index.js#L28-L28) + +Undocumented declaration. + +### UP + +[src/index.js#L33-L33](src/index.js#L33-L33) + +Undocumented declaration. + + + +

Code is Poetry.

diff --git a/packages/keycodes/package.json b/packages/keycodes/package.json index 82fb2b06fc04eb..1037e76ce69a3c 100644 --- a/packages/keycodes/package.json +++ b/packages/keycodes/package.json @@ -25,7 +25,13 @@ "@wordpress/i18n": "file:../i18n", "lodash": "^4.17.11" }, + "devDependencies": { + "@wordpress/docgen": "file:../docgen" + }, "publishConfig": { "access": "public" + }, + "scripts": { + "docs:generate": "docgen ./src/index.js --output ./README.md --to-token" } } From bcc28bfbbc64d370e7a40806969da9f87786196b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 6 Mar 2019 12:32:57 +0100 Subject: [PATCH 2/2] Use new script --- bin/update-readmes.js | 2 +- packages/keycodes/README.md | 86 +++++++++++++++++++--------------- packages/keycodes/package.json | 6 --- packages/keycodes/src/index.js | 62 +++++++++++++++++++++++- 4 files changed, 110 insertions(+), 46 deletions(-) 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 58fe8dcc836ee0..d99081ed5823c2 100644 --- a/packages/keycodes/README.md +++ b/packages/keycodes/README.md @@ -40,37 +40,37 @@ onKeyDown( event ) { ### ALT -[src/index.js#L40-L40](src/index.js#L40-L40) +[src/index.js#L74-L74](src/index.js#L74-L74) -Undocumented declaration. +Keycode for ALT key. ### BACKSPACE -[src/index.js#L27-L27](src/index.js#L27-L27) +[src/index.js#L30-L30](src/index.js#L30-L30) -Undocumented declaration. +Keycode for BACKSPACE key. ### COMMAND -[src/index.js#L42-L42](src/index.js#L42-L42) +[src/index.js#L82-L82](src/index.js#L82-L82) -Undocumented declaration. +Keycode for COMMAND/META key. ### CTRL -[src/index.js#L41-L41](src/index.js#L41-L41) +[src/index.js#L78-L78](src/index.js#L78-L78) -Undocumented declaration. +Keycode for CTRL key. ### DELETE -[src/index.js#L36-L36](src/index.js#L36-L36) +[src/index.js#L66-L66](src/index.js#L66-L66) -Undocumented declaration. +Keycode for DELETE key. ### displayShortcut -[src/index.js#L108-L110](src/index.js#L108-L110) +[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. @@ -81,7 +81,7 @@ E.g. displayShortcut.primary( 'm' ) will return '⌘M' on Mac. ### displayShortcutList -[src/index.js#L77-L100](src/index.js#L77-L100) +[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. @@ -92,31 +92,31 @@ E.g displayShortcutList.primary( 'm' ) will return [ '⌘', 'M' ] on Mac. ### DOWN -[src/index.js#L35-L35](src/index.js#L35-L35) +[src/index.js#L62-L62](src/index.js#L62-L62) -Undocumented declaration. +Keycode for DOWN key. ### ENTER -[src/index.js#L29-L29](src/index.js#L29-L29) +[src/index.js#L38-L38](src/index.js#L38-L38) -Undocumented declaration. +Keycode for ENTER key. ### ESCAPE -[src/index.js#L30-L30](src/index.js#L30-L30) +[src/index.js#L42-L42](src/index.js#L42-L42) -Undocumented declaration. +Keycode for ESCAPE key. ### F10 -[src/index.js#L38-L38](src/index.js#L38-L38) +[src/index.js#L70-L70](src/index.js#L70-L70) -Undocumented declaration. +Keycode for F10 key. ### isKeyboardEvent -[src/index.js#L146-L160](src/index.js#L146-L160) +[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. @@ -129,19 +129,31 @@ signals pressing ⌘M. ### LEFT -[src/index.js#L32-L32](src/index.js#L32-L32) +[src/index.js#L50-L50](src/index.js#L50-L50) -Undocumented declaration. +Keycode for LEFT key. ### modifiers -[src/index.js#L45-L56](src/index.js#L45-L56) +[src/index.js#L103-L114](src/index.js#L103-L114) + +Object that contains functions that return the available modifier +depending on platform. -Undocumented declaration. +- `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#L65-L69](src/index.js#L65-L69) +[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. @@ -153,40 +165,40 @@ These are intended for user with the KeyboardShortcuts component or TinyMCE. ### RIGHT -[src/index.js#L34-L34](src/index.js#L34-L34) +[src/index.js#L58-L58](src/index.js#L58-L58) -Undocumented declaration. +Keycode for RIGHT key. ### SHIFT -[src/index.js#L43-L43](src/index.js#L43-L43) +[src/index.js#L86-L86](src/index.js#L86-L86) -Undocumented declaration. +Keycode for SHIFT key. ### shortcutAriaLabel -[src/index.js#L116-L136](src/index.js#L116-L136) +[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#L31-L31](src/index.js#L31-L31) +[src/index.js#L46-L46](src/index.js#L46-L46) -Undocumented declaration. +Keycode for SPACE key. ### TAB -[src/index.js#L28-L28](src/index.js#L28-L28) +[src/index.js#L34-L34](src/index.js#L34-L34) -Undocumented declaration. +Keycode for TAB key. ### UP -[src/index.js#L33-L33](src/index.js#L33-L33) +[src/index.js#L54-L54](src/index.js#L54-L54) -Undocumented declaration. +Keycode for UP key. diff --git a/packages/keycodes/package.json b/packages/keycodes/package.json index 1037e76ce69a3c..82fb2b06fc04eb 100644 --- a/packages/keycodes/package.json +++ b/packages/keycodes/package.json @@ -25,13 +25,7 @@ "@wordpress/i18n": "file:../i18n", "lodash": "^4.17.11" }, - "devDependencies": { - "@wordpress/docgen": "file:../docgen" - }, "publishConfig": { "access": "public" - }, - "scripts": { - "docs:generate": "docgen ./src/index.js --output ./README.md --to-token" } } 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 ],