You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →

@wordpress/keycodes

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/keycodes - npm Package Compare versions

Comparing version

to
2.0.1

@@ -20,2 +20,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies

@@ -98,9 +103,9 @@ */

var isMac = _isApple();
var isApple = _isApple();
var replacementKeyMap = (_replacementKeyMap = {}, _defineProperty(_replacementKeyMap, ALT, isMac ? '⌥' : 'Alt'), _defineProperty(_replacementKeyMap, CTRL, isMac ? '^' : 'Ctrl'), _defineProperty(_replacementKeyMap, COMMAND, '⌘'), _defineProperty(_replacementKeyMap, SHIFT, isMac ? '⇧' : 'Shift'), _replacementKeyMap);
var replacementKeyMap = (_replacementKeyMap = {}, _defineProperty(_replacementKeyMap, ALT, isApple ? '⌥' : 'Alt'), _defineProperty(_replacementKeyMap, CTRL, isApple ? '^' : 'Ctrl'), _defineProperty(_replacementKeyMap, COMMAND, '⌘'), _defineProperty(_replacementKeyMap, SHIFT, isApple ? '⇧' : 'Shift'), _replacementKeyMap);
var modifierKeys = modifier(_isApple).reduce(function (accumulator, key) {
var replacementKey = get(replacementKeyMap, key, key); // If on the Mac, adhere to platform convention and don't show plus between keys.
if (isMac) {
if (isApple) {
return _toConsumableArray(accumulator).concat([replacementKey]);

@@ -122,10 +127,29 @@ }

export var displayShortcut = mapValues(displayShortcutList, function (sequence) {
export var displayShortcut = mapValues(displayShortcutList, function (shortcutList) {
return function (character) {
var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
return sequence(character, _isApple).join('');
return shortcutList(character, _isApple).join('');
};
});
/**
* An object that contains functions to return an aria label for a keyboard shortcut.
* E.g. shortcutAriaLabel.primary( '.' ) will return 'Command + Period' on Mac.
*/
export var shortcutAriaLabel = mapValues(modifiers, function (modifier) {
return function (character) {
var _replacementKeyMap2;
var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isAppleOS;
var isApple = _isApple();
var replacementKeyMap = (_replacementKeyMap2 = {}, _defineProperty(_replacementKeyMap2, SHIFT, 'Shift'), _defineProperty(_replacementKeyMap2, COMMAND, isApple ? 'Command' : 'Control'), _defineProperty(_replacementKeyMap2, CTRL, 'Control'), _defineProperty(_replacementKeyMap2, ALT, isApple ? 'Option' : 'Alt'), _defineProperty(_replacementKeyMap2, ',', __('Comma')), _defineProperty(_replacementKeyMap2, '.', __('Period')), _defineProperty(_replacementKeyMap2, '`', __('Backtick')), _replacementKeyMap2);
return _toConsumableArray(modifier(_isApple)).concat([character]).map(function (key) {
return capitalize(get(replacementKeyMap, key, key));
}).join(isApple ? ' ' : ' + ');
};
});
/**
* An object that contains functions to check if a keyboard event matches a

@@ -132,0 +156,0 @@ * predefined shortcut combination.

@@ -8,3 +8,3 @@ "use strict";

});
exports.isKeyboardEvent = exports.displayShortcut = exports.displayShortcutList = exports.rawShortcut = exports.SHIFT = exports.COMMAND = exports.CTRL = exports.ALT = exports.F10 = exports.DELETE = exports.DOWN = exports.RIGHT = exports.UP = exports.LEFT = exports.SPACE = exports.ESCAPE = exports.ENTER = exports.TAB = exports.BACKSPACE = void 0;
exports.isKeyboardEvent = exports.shortcutAriaLabel = exports.displayShortcut = exports.displayShortcutList = exports.rawShortcut = exports.SHIFT = exports.COMMAND = exports.CTRL = exports.ALT = exports.F10 = exports.DELETE = exports.DOWN = exports.RIGHT = exports.UP = exports.LEFT = exports.SPACE = exports.ESCAPE = exports.ENTER = exports.TAB = exports.BACKSPACE = void 0;

@@ -17,2 +17,4 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _i18n = require("@wordpress/i18n");
var _platform = require("./platform");

@@ -36,2 +38,6 @@

/**
* WordPress dependencies
*/
/**
* Internal dependencies

@@ -128,9 +134,9 @@ */

var isMac = _isApple();
var isApple = _isApple();
var replacementKeyMap = (_replacementKeyMap = {}, (0, _defineProperty2.default)(_replacementKeyMap, ALT, isMac ? '⌥' : 'Alt'), (0, _defineProperty2.default)(_replacementKeyMap, CTRL, isMac ? '^' : 'Ctrl'), (0, _defineProperty2.default)(_replacementKeyMap, COMMAND, '⌘'), (0, _defineProperty2.default)(_replacementKeyMap, SHIFT, isMac ? '⇧' : 'Shift'), _replacementKeyMap);
var replacementKeyMap = (_replacementKeyMap = {}, (0, _defineProperty2.default)(_replacementKeyMap, ALT, isApple ? '⌥' : 'Alt'), (0, _defineProperty2.default)(_replacementKeyMap, CTRL, isApple ? '^' : 'Ctrl'), (0, _defineProperty2.default)(_replacementKeyMap, COMMAND, '⌘'), (0, _defineProperty2.default)(_replacementKeyMap, SHIFT, isApple ? '⇧' : 'Shift'), _replacementKeyMap);
var modifierKeys = modifier(_isApple).reduce(function (accumulator, key) {
var replacementKey = (0, _lodash.get)(replacementKeyMap, key, key); // If on the Mac, adhere to platform convention and don't show plus between keys.
if (isMac) {
if (isApple) {
return (0, _toConsumableArray2.default)(accumulator).concat([replacementKey]);

@@ -153,10 +159,30 @@ }

exports.displayShortcutList = displayShortcutList;
var displayShortcut = (0, _lodash.mapValues)(displayShortcutList, function (sequence) {
var displayShortcut = (0, _lodash.mapValues)(displayShortcutList, function (shortcutList) {
return function (character) {
var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _platform.isAppleOS;
return sequence(character, _isApple).join('');
return shortcutList(character, _isApple).join('');
};
});
/**
* An object that contains functions to return an aria label for a keyboard shortcut.
* E.g. shortcutAriaLabel.primary( '.' ) will return 'Command + Period' on Mac.
*/
exports.displayShortcut = displayShortcut;
var shortcutAriaLabel = (0, _lodash.mapValues)(modifiers, function (modifier) {
return function (character) {
var _replacementKeyMap2;
var _isApple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _platform.isAppleOS;
var isApple = _isApple();
var replacementKeyMap = (_replacementKeyMap2 = {}, (0, _defineProperty2.default)(_replacementKeyMap2, SHIFT, 'Shift'), (0, _defineProperty2.default)(_replacementKeyMap2, COMMAND, isApple ? 'Command' : 'Control'), (0, _defineProperty2.default)(_replacementKeyMap2, CTRL, 'Control'), (0, _defineProperty2.default)(_replacementKeyMap2, ALT, isApple ? 'Option' : 'Alt'), (0, _defineProperty2.default)(_replacementKeyMap2, ',', (0, _i18n.__)('Comma')), (0, _defineProperty2.default)(_replacementKeyMap2, '.', (0, _i18n.__)('Period')), (0, _defineProperty2.default)(_replacementKeyMap2, '`', (0, _i18n.__)('Backtick')), _replacementKeyMap2);
return (0, _toConsumableArray2.default)(modifier(_isApple)).concat([character]).map(function (key) {
return (0, _lodash.capitalize)((0, _lodash.get)(replacementKeyMap, key, key));
}).join(isApple ? ' ' : ' + ');
};
});
/**
* An object that contains functions to check if a keyboard event matches a

@@ -170,3 +196,3 @@ * predefined shortcut combination.

exports.displayShortcut = displayShortcut;
exports.shortcutAriaLabel = shortcutAriaLabel;
var isKeyboardEvent = (0, _lodash.mapValues)(modifiers, function (getModifiers) {

@@ -173,0 +199,0 @@ return function (event, character) {

@@ -1,2 +0,2 @@

## 2.0.0 (Unreleased)
## 2.0.0 (2018-09-05)

@@ -3,0 +3,0 @@ ### Breaking Change

{
"name": "@wordpress/keycodes",
"version": "2.0.0",
"version": "2.0.1",
"description": "Keycodes utilities for WordPress. Used to check for keyboard events across browsers/operating systems.",

@@ -29,3 +29,3 @@ "author": "The WordPress Contributors",

},
"gitHead": "df6f8da7b557894e4364c17db2dd4af0d1e20252"
"gitHead": "7b17d5777076896fb25170b23d6e83e8c049240d"
}

@@ -18,2 +18,7 @@ /**

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies

@@ -75,8 +80,8 @@ */

return ( character, _isApple = isAppleOS ) => {
const isMac = _isApple();
const isApple = _isApple();
const replacementKeyMap = {
[ ALT ]: isMac ? '⌥' : 'Alt',
[ CTRL ]: isMac ? '^' : 'Ctrl',
[ ALT ]: isApple ? '⌥' : 'Alt',
[ CTRL ]: isApple ? '^' : 'Ctrl',
[ COMMAND ]: '⌘',
[ SHIFT ]: isMac ? '⇧' : 'Shift',
[ SHIFT ]: isApple ? '⇧' : 'Shift',
};

@@ -87,3 +92,3 @@

// If on the Mac, adhere to platform convention and don't show plus between keys.
if ( isMac ) {
if ( isApple ) {
return [ ...accumulator, replacementKey ];

@@ -106,7 +111,33 @@ }

*/
export const displayShortcut = mapValues( displayShortcutList, ( sequence ) => {
return ( character, _isApple = isAppleOS ) => sequence( character, _isApple ).join( '' );
export const displayShortcut = mapValues( displayShortcutList, ( shortcutList ) => {
return ( character, _isApple = isAppleOS ) => shortcutList( character, _isApple ).join( '' );
} );
/**
* An object that contains functions to return an aria label for a keyboard shortcut.
* E.g. shortcutAriaLabel.primary( '.' ) will return 'Command + Period' on Mac.
*/
export const shortcutAriaLabel = mapValues( modifiers, ( modifier ) => {
return ( character, _isApple = isAppleOS ) => {
const isApple = _isApple();
const replacementKeyMap = {
[ SHIFT ]: 'Shift',
[ COMMAND ]: isApple ? 'Command' : 'Control',
[ CTRL ]: 'Control',
[ ALT ]: isApple ? 'Option' : 'Alt',
/* translators: comma as in the character ',' */
',': __( 'Comma' ),
/* translators: period as in the character '.' */
'.': __( 'Period' ),
/* translators: backtick as in the character '`' */
'`': __( 'Backtick' ),
};
return [ ...modifier( _isApple ), character ]
.map( ( key ) => capitalize( get( replacementKeyMap, key, key ) ) )
.join( isApple ? ' ' : ' + ' );
};
} );
/**
* An object that contains functions to check if a keyboard event matches a

@@ -113,0 +144,0 @@ * predefined shortcut combination.

@@ -8,2 +8,3 @@ /**

rawShortcut,
shortcutAriaLabel,
} from '../';

@@ -134,2 +135,52 @@

describe( 'shortcutAriaLabel', () => {
describe( 'primary', () => {
it( 'should output "Control + Period" on Windows', () => {
const shortcut = shortcutAriaLabel.primary( '.', isAppleOSFalse );
expect( shortcut ).toEqual( 'Control + Period' );
} );
it( 'should output "Command Period" on Windows', () => {
const shortcut = shortcutAriaLabel.primary( '.', isAppleOSTrue );
expect( shortcut ).toEqual( 'Command Period' );
} );
} );
describe( 'primaryShift', () => {
it( 'should output "Control + Shift + Period" on Windows', () => {
const shortcut = shortcutAriaLabel.primaryShift( '.', isAppleOSFalse );
expect( shortcut ).toEqual( 'Control + Shift + Period' );
} );
it( 'should output "Shift Command Period" on MacOS', () => {
const shortcut = shortcutAriaLabel.primaryShift( '.', isAppleOSTrue );
expect( shortcut ).toEqual( 'Shift Command Period' );
} );
} );
describe( 'secondary', () => {
it( 'should output "Control + Shift + Alt + Period" on Windows', () => {
const shortcut = shortcutAriaLabel.secondary( '.', isAppleOSFalse );
expect( shortcut ).toEqual( 'Control + Shift + Alt + Period' );
} );
it( 'should output "Shift Option Command Period" on MacOS', () => {
const shortcut = shortcutAriaLabel.secondary( '.', isAppleOSTrue );
expect( shortcut ).toEqual( 'Shift Option Command Period' );
} );
} );
describe( 'access', () => {
it( 'should output "Shift + Alt + Period" on Windows', () => {
const shortcut = shortcutAriaLabel.access( '.', isAppleOSFalse );
expect( shortcut ).toEqual( 'Shift + Alt + Period' );
} );
it( 'should output "Control Option Period" on MacOS', () => {
const shortcut = shortcutAriaLabel.access( '.', isAppleOSTrue );
expect( shortcut ).toEqual( 'Control Option Period' );
} );
} );
} );
describe( 'rawShortcut', () => {

@@ -136,0 +187,0 @@ describe( 'primary', () => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet