Socket
Socket
Sign inDemoInstall

react-keydown

Package Overview
Dependencies
6
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.6 to 1.9.7

6

dist/decorators/class_decorator.js

@@ -17,3 +17,3 @@ 'use strict';

var _store2 = _interopRequireDefault(_store);
var store = _interopRequireWildcard(_store);

@@ -24,2 +24,4 @@ var _event_handlers = require('../event_handlers');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -92,3 +94,3 @@

_store2.default.setBinding({ keys: [].concat(keys), fn: KeyBoardHelper.prototype.handleKeyDown, target: KeyBoardHelper.prototype });
store.setBinding({ keys: [].concat(keys), fn: KeyBoardHelper.prototype.handleKeyDown, target: KeyBoardHelper.prototype });

@@ -95,0 +97,0 @@ return KeyBoardHelper;

@@ -15,7 +15,7 @@ 'use strict';

var _store2 = _interopRequireDefault(_store);
var store = _interopRequireWildcard(_store);
var _event_handlers = require('../event_handlers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -54,3 +54,3 @@ /**

// decorated method), wrap these lifecycle methods.
if (!_store2.default.getBinding(target)) {
if (!store.getBinding(target)) {
var componentDidMount = target.componentDidMount,

@@ -72,3 +72,3 @@ componentWillUnmount = target.componentWillUnmount;

// add this binding of keys and method to the target's bindings
_store2.default.setBinding({ keys: keys, target: target, fn: fn });
store.setBinding({ keys: keys, target: target, fn: fn });

@@ -75,0 +75,0 @@ descriptor.value = function () {

@@ -21,4 +21,6 @@ 'use strict';

var _store2 = _interopRequireDefault(_store);
var store = _interopRequireWildcard(_store);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -48,3 +50,3 @@

_store2.default.activate([].concat(_toConsumableArray(_store2.default.getInstances())).reduce(_dom_helpers2.default.findContainerNodes(target), []).sort(_dom_helpers2.default.sortByDOMPosition).map(function (item) {
store.activate([].concat(_toConsumableArray(store.getInstances())).reduce(_dom_helpers2.default.findContainerNodes(target), []).sort(_dom_helpers2.default.sortByDOMPosition).map(function (item) {
return item.instance;

@@ -65,3 +67,3 @@ }));

if (forceConsider || _shouldConsider(event)) {
var _ref2 = _store2.default.findBindingForEvent(event) || {},
var _ref2 = store.findBindingForEvent(event) || {},
fn = _ref2.fn,

@@ -104,6 +106,6 @@ instance = _ref2.instance;

function onMount(instance) {
_store2.default.activate(instance);
store.activate(instance);
_listeners2.default.bindKeys(_onKeyDown);
_listeners2.default.bindClicks(_onClick);
_dom_helpers2.default.bindFocusables(instance, _store2.default.activate);
_dom_helpers2.default.bindFocusables(instance, store.activate);
}

@@ -117,4 +119,4 @@

function onUnmount(instance) {
_store2.default.deleteInstance(instance);
if (_store2.default.isEmpty()) {
store.deleteInstance(instance);
if (store.isEmpty()) {
_listeners2.default.unbindClicks(_onClick);

@@ -121,0 +123,0 @@ _listeners2.default.unbindKeys(_onKeyDown);

@@ -10,2 +10,9 @@ 'use strict';

exports._resetStore = _resetStore;
exports.activate = activate;
exports.deleteInstance = deleteInstance;
exports.findBindingForEvent = findBindingForEvent;
exports.getBinding = getBinding;
exports.getInstances = getInstances;
exports.isEmpty = isEmpty;
exports.setBinding = setBinding;

@@ -50,178 +57,164 @@ var _match_keys = require('./lib/match_keys');

/**
* public
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
function activate(instances) {
var instancesArray = [].concat(instances);
var Store = {
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if (!instancesArray.length) {
_instances.add(null);
} else {
_instances.delete(null);
/**
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
activate: function activate(instances) {
var instancesArray = [].concat(instances);
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach(function (instance) {
_instances.delete(instance);
_instances.add(instance);
});
}
};
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if (!instancesArray.length) {
_instances.add(null);
} else {
_instances.delete(null);
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
function deleteInstance(target) {
_instances.delete(target);
};
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach(function (instance) {
_instances.delete(instance);
_instances.add(instance);
});
}
},
function findBindingForEvent(event) {
if (!_instances.has(null)) {
var keyMatchesEvent = function keyMatchesEvent(keySet) {
return (0, _match_keys2.default)({ keySet: keySet, event: event });
};
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
deleteInstance: function deleteInstance(target) {
_instances.delete(target);
},
findBindingForEvent: function findBindingForEvent(event) {
if (!_instances.has(null)) {
var keyMatchesEvent = function keyMatchesEvent(keySet) {
return (0, _match_keys2.default)({ keySet: keySet, event: event });
};
try {
for (var _iterator = [].concat(_toConsumableArray(_instances)).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var instance = _step.value;
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var bindings = this.getBinding(instance.constructor.prototype);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator = [].concat(_toConsumableArray(_instances)).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var instance = _step.value;
try {
for (var _iterator2 = bindings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
keySets = _step2$value[0],
fn = _step2$value[1];
var bindings = this.getBinding(instance.constructor.prototype);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
if (keySets.some(keyMatchesEvent)) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn: fn, instance: instance };
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
for (var _iterator2 = bindings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
keySets = _step2$value[0],
fn = _step2$value[1];
if (keySets.some(keyMatchesEvent)) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn: fn, instance: instance };
}
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return null;
},
}
return null;
};
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
function getBinding(_ref) {
var __reactKeydownUUID = _ref.__reactKeydownUUID;
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
getBinding: function getBinding(_ref) {
var __reactKeydownUUID = _ref.__reactKeydownUUID;
return _handlers.get(__reactKeydownUUID);
};
return _handlers.get(__reactKeydownUUID);
},
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
function getInstances() {
return _instances;
};
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
function isEmpty() {
return !_instances.size;
};
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
getInstances: function getInstances() {
return _instances;
},
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
function setBinding(_ref2) {
var keys = _ref2.keys,
fn = _ref2.fn,
target = _ref2.target;
var keySets = (0, _parse_keys2.default)(keys);
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
isEmpty: function isEmpty() {
return !_instances.size;
},
var __reactKeydownUUID = target.__reactKeydownUUID;
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
setBinding: function setBinding(_ref2) {
var keys = _ref2.keys,
fn = _ref2.fn,
target = _ref2.target;
var keySets = (0, _parse_keys2.default)(keys);
var __reactKeydownUUID = target.__reactKeydownUUID;
if (!__reactKeydownUUID) {
target.__reactKeydownUUID = (0, _uuid2.default)();
_handlers.set(target.__reactKeydownUUID, new Map([[keySets, fn]]));
} else {
_handlers.get(__reactKeydownUUID).set(keySets, fn);
}
if (!__reactKeydownUUID) {
target.__reactKeydownUUID = (0, _uuid2.default)();
_handlers.set(target.__reactKeydownUUID, new Map([[keySets, fn]]));
} else {
_handlers.get(__reactKeydownUUID).set(keySets, fn);
}
};
exports.default = Store;
};

@@ -17,3 +17,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

import store from '../store';
import * as store from '../store';
import { onMount, onUnmount } from '../event_handlers';

@@ -20,0 +20,0 @@ import { ALL_KEYS } from '../lib/keys';

@@ -7,3 +7,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

*/
import store from '../store';
import * as store from '../store';
import { onMount, onUnmount, _onKeyDown } from '../event_handlers';

@@ -10,0 +10,0 @@

@@ -10,3 +10,3 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

import listeners from './lib/listeners';
import store from './store';
import * as store from './store';

@@ -13,0 +13,0 @@ /**

@@ -31,178 +31,164 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

/**
* public
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
export function activate(instances) {
var instancesArray = [].concat(instances);
var Store = {
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if (!instancesArray.length) {
_instances.add(null);
} else {
_instances.delete(null);
/**
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
activate: function activate(instances) {
var instancesArray = [].concat(instances);
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach(function (instance) {
_instances.delete(instance);
_instances.add(instance);
});
}
};
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if (!instancesArray.length) {
_instances.add(null);
} else {
_instances.delete(null);
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
export function deleteInstance(target) {
_instances.delete(target);
};
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach(function (instance) {
_instances.delete(instance);
_instances.add(instance);
});
}
},
export function findBindingForEvent(event) {
if (!_instances.has(null)) {
var keyMatchesEvent = function keyMatchesEvent(keySet) {
return matchKeys({ keySet: keySet, event: event });
};
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
deleteInstance: function deleteInstance(target) {
_instances.delete(target);
},
findBindingForEvent: function findBindingForEvent(event) {
if (!_instances.has(null)) {
var keyMatchesEvent = function keyMatchesEvent(keySet) {
return matchKeys({ keySet: keySet, event: event });
};
try {
for (var _iterator = [].concat(_toConsumableArray(_instances)).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var instance = _step.value;
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var bindings = getBinding(instance.constructor.prototype);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator = [].concat(_toConsumableArray(_instances)).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var instance = _step.value;
try {
for (var _iterator2 = bindings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
keySets = _step2$value[0],
fn = _step2$value[1];
var bindings = this.getBinding(instance.constructor.prototype);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
if (keySets.some(keyMatchesEvent)) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn: fn, instance: instance };
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
for (var _iterator2 = bindings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
keySets = _step2$value[0],
fn = _step2$value[1];
if (keySets.some(keyMatchesEvent)) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn: fn, instance: instance };
}
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return null;
},
}
return null;
};
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
export function getBinding(_ref) {
var __reactKeydownUUID = _ref.__reactKeydownUUID;
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
getBinding: function getBinding(_ref) {
var __reactKeydownUUID = _ref.__reactKeydownUUID;
return _handlers.get(__reactKeydownUUID);
};
return _handlers.get(__reactKeydownUUID);
},
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
export function getInstances() {
return _instances;
};
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
export function isEmpty() {
return !_instances.size;
};
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
getInstances: function getInstances() {
return _instances;
},
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
export function setBinding(_ref2) {
var keys = _ref2.keys,
fn = _ref2.fn,
target = _ref2.target;
var keySets = parseKeys(keys);
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
isEmpty: function isEmpty() {
return !_instances.size;
},
var __reactKeydownUUID = target.__reactKeydownUUID;
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
setBinding: function setBinding(_ref2) {
var keys = _ref2.keys,
fn = _ref2.fn,
target = _ref2.target;
var keySets = parseKeys(keys);
var __reactKeydownUUID = target.__reactKeydownUUID;
if (!__reactKeydownUUID) {
target.__reactKeydownUUID = uuid();
_handlers.set(target.__reactKeydownUUID, new Map([[keySets, fn]]));
} else {
_handlers.get(__reactKeydownUUID).set(keySets, fn);
}
if (!__reactKeydownUUID) {
target.__reactKeydownUUID = uuid();
_handlers.set(target.__reactKeydownUUID, new Map([[keySets, fn]]));
} else {
_handlers.get(__reactKeydownUUID).set(keySets, fn);
}
};
export default Store;
};
{
"name": "react-keydown",
"version": "1.9.6",
"version": "1.9.7",
"description": "Lightweight keydown wrapper for React components",

@@ -44,3 +44,3 @@ "main": "dist/index.js",

"babel-cli": "^6.24.0",
"babel-loader": "6.x",
"babel-loader": "^7.1.3",
"babel-plugin-transform-decorators-legacy": "^1.3.4",

@@ -56,3 +56,4 @@ "babel-plugin-transform-es2015-modules-commonjs": "6.x",

"tape": "^4.2.2",
"webpack": "^1.12.2"
"webpack": "^4.1.0",
"webpack-cli": "^2.0.10"
},

@@ -59,0 +60,0 @@ "peerDependencies": {

@@ -201,6 +201,7 @@ <p align="center">

the [Babel legacy decorators transform](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy) or the equivalent.
* The default build uses CommonJS modules. For AMD or other support, use the
* Components that have a [React 16 fragment](https://reactjs.org/docs/fragments.html) at their root may not be activated properly when clicked. See [this issue](https://github.com/glortho/react-keydown/issues/80) for more detail.
* The default build outputs CommonJS modules and native ES modules. For AMD or other support, use the
[umd-specific
branch](https://github.com/jedverity/react-keydown/tree/master-umd) instead.
* This lib has only been tested using ES2015 classes. Some method decoration
branch](https://github.com/glortho/react-keydown/tree/master-umd) instead.
* This lib has only been tested using ES2015 classes and class methods. Some method decoration
functionality may work on other types of object methods.

@@ -207,0 +208,0 @@ * Duplicate keybindings for components that are mounted at the same time will

@@ -7,3 +7,3 @@ /**

import store from '../store';
import * as store from '../store';
import { onMount, onUnmount } from '../event_handlers';

@@ -10,0 +10,0 @@ import { ALL_KEYS } from '../lib/keys';

@@ -5,3 +5,3 @@ /**

*/
import store from '../store';
import * as store from '../store';
import { onMount, onUnmount, _onKeyDown } from '../event_handlers';

@@ -8,0 +8,0 @@

@@ -8,3 +8,3 @@ /* eslint-disable no-use-before-define */

import listeners from './lib/listeners';
import store from './store';
import * as store from './store';

@@ -11,0 +11,0 @@ /**

@@ -26,123 +26,112 @@ /**

/**
* public
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
export function activate( instances ) {
const instancesArray = [].concat( instances );
const Store = {
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if ( !instancesArray.length ) {
_instances.add( null );
} else {
_instances.delete( null );
/**
* activate
*
* @access public
* @param {object} instance Instantiated class that extended React.Component, to be focused to receive keydown events
*/
activate( instances ) {
const instancesArray = [].concat( instances );
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach( instance => {
_instances.delete( instance );
_instances.add( instance );
});
}
};
// if no components were found as ancestors of the event target,
// effectively deactivate keydown handling by capping the set of instances
// with `null`.
if ( !instancesArray.length ) {
_instances.add( null );
} else {
_instances.delete( null );
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
export function deleteInstance( target ) {
_instances.delete( target );
};
// deleting and then adding the instance(s) has the effect of sorting the set
// according to instance activation (ascending)
instancesArray.forEach( instance => {
_instances.delete( instance );
_instances.add( instance );
});
}
},
export function findBindingForEvent( event ) {
if ( !_instances.has( null ) ) {
const keyMatchesEvent = keySet => matchKeys( { keySet, event } );
/**
* deleteInstance
*
* @access public
* @param {object} target Instantiated class that extended React.Component
* @return {boolean} The value set.has( target ) would have returned prior to deletion
*/
deleteInstance( target ) {
_instances.delete( target );
},
findBindingForEvent( event ) {
if ( !_instances.has( null ) ) {
const keyMatchesEvent = keySet => matchKeys( { keySet, event } );
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
for ( const instance of [ ..._instances ].reverse() ) {
const bindings = this.getBinding( instance.constructor.prototype );
for ( const [ keySets, fn ] of bindings ) {
if ( keySets.some( keyMatchesEvent ) ) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn, instance };
}
// loop through instances in reverse activation order so that most
// recently activated instance gets first dibs on event
for ( const instance of [ ..._instances ].reverse() ) {
const bindings = getBinding( instance.constructor.prototype );
for ( const [ keySets, fn ] of bindings ) {
if ( keySets.some( keyMatchesEvent ) ) {
// return when matching keybinding is found - i.e. only one
// keybound component can respond to a given key code. to get around this,
// scope a common ancestor component class with @keydown and use
// @keydownScoped to bind the duplicate keys in your child components
// (or just inspect nextProps.keydown.event).
return { fn, instance };
}
}
}
return null;
},
}
return null;
};
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
getBinding( { __reactKeydownUUID } ) {
return _handlers.get( __reactKeydownUUID );
},
/**
* getBinding
*
* @access public
* @param {object} target Class used as key in dict of key bindings
* @return {object} The object containing bindings for the given class
*/
export function getBinding( { __reactKeydownUUID } ) {
return _handlers.get( __reactKeydownUUID );
};
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
getInstances() {
return _instances;
},
/**
* getInstances
*
* @access public
* @return {set} All stored instances (all mounted component instances with keybindings)
*/
export function getInstances() {
return _instances;
};
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
isEmpty() {
return !_instances.size;
},
/**
* isEmpty
*
* @access public
* @return {number} Size of the set of all stored instances
*/
export function isEmpty() {
return !_instances.size;
};
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
setBinding( { keys, fn, target } ) {
const keySets = parseKeys( keys );
/**
* setBinding
*
* @access public
* @param {object} args All arguments necessary to set the binding
* @param {array} args.keys Key codes that should trigger the fn
* @param {function} args.fn The callback to be triggered when given keys are pressed
* @param {object} args.target The decorated class
*/
export function setBinding( { keys, fn, target } ) {
const keySets = parseKeys( keys );
const { __reactKeydownUUID } = target;
if ( !__reactKeydownUUID ) {
target.__reactKeydownUUID = uuid();
_handlers.set( target.__reactKeydownUUID, new Map( [ [ keySets, fn ] ] ) );
} else {
_handlers.get( __reactKeydownUUID ).set( keySets, fn );
}
const { __reactKeydownUUID } = target;
if ( !__reactKeydownUUID ) {
target.__reactKeydownUUID = uuid();
_handlers.set( target.__reactKeydownUUID, new Map( [ [ keySets, fn ] ] ) );
} else {
_handlers.get( __reactKeydownUUID ).set( keySets, fn );
}
};
export default Store;

@@ -11,8 +11,8 @@ 'use strict';

module: {
loaders: [{
rules: [{
exclude: /node_modules/,
test: /\.js$/,
loader: 'babel'
loader: 'babel-loader'
}]
}
};

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc