react-hot-keys
Advanced tools
Comparing version 1.2.0 to 1.2.2
{ | ||
"name": "react-hot-keys", | ||
"version": "1.2.0", | ||
"version": "1.2.2", | ||
"description": "React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.", | ||
@@ -15,2 +15,3 @@ "author": "kenny wang <wowohoo@qq.com>", | ||
"scripts": { | ||
"deploy": "npm run build && gh-pages -d demo/dist", | ||
"build": "nwb build-react-component", | ||
@@ -24,3 +25,3 @@ "clean": "nwb clean-module && nwb clean-demo", | ||
"dependencies": { | ||
"hotkeys-js": "^3.3.1" | ||
"hotkeys-js": "^3.3.8" | ||
}, | ||
@@ -32,3 +33,4 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"nwb": "^0.21.5", | ||
"gh-pages": "^1.2.0", | ||
"nwb": "^0.23.0", | ||
"prop-types": "^15.6.0", | ||
@@ -35,0 +37,0 @@ "react": "^16.2.0", |
/*! | ||
* react-hot-keys v1.0.11 - https://jaywcjlove.github.io/react-hotkeys/ | ||
* react-hot-keys v1.2.2 - https://jaywcjlove.github.io/react-hotkeys/ | ||
* MIT Licensed | ||
@@ -14,3 +14,3 @@ */ | ||
root["ReactHotkeys"] = factory(root["React"]); | ||
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_6__) { | ||
})(window, function(__WEBPACK_EXTERNAL_MODULE__1__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -54,10 +54,30 @@ /******/ // The module cache | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
@@ -78,4 +98,5 @@ /******/ __webpack_require__.n = function(module) { | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 4); | ||
/******/ return __webpack_require__(__webpack_require__.s = 2); | ||
/******/ }) | ||
@@ -87,5 +108,101 @@ /************************************************************************/ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
if (false) { var throwOnDirectAccess, isValidElement, REACT_ELEMENT_TYPE; } else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = __webpack_require__(3)(); | ||
} | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE__1__; | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(7); | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var emptyFunction = __webpack_require__(4); | ||
var invariant = __webpack_require__(5); | ||
var ReactPropTypesSecret = __webpack_require__(6); | ||
module.exports = function() { | ||
function shim(props, propName, componentName, location, propFullName, secret) { | ||
if (secret === ReactPropTypesSecret) { | ||
// It is still safe when called from React. | ||
return; | ||
} | ||
invariant( | ||
false, | ||
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + | ||
'Use PropTypes.checkPropTypes() to call them. ' + | ||
'Read more at http://fb.me/use-check-prop-types' | ||
); | ||
}; | ||
shim.isRequired = shim; | ||
function getShim() { | ||
return shim; | ||
}; | ||
// Important! | ||
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. | ||
var ReactPropTypes = { | ||
array: shim, | ||
bool: shim, | ||
func: shim, | ||
number: shim, | ||
object: shim, | ||
string: shim, | ||
symbol: shim, | ||
any: shim, | ||
arrayOf: getShim, | ||
element: shim, | ||
instanceOf: getShim, | ||
node: shim, | ||
objectOf: getShim, | ||
oneOf: getShim, | ||
oneOfType: getShim, | ||
shape: getShim, | ||
exact: getShim | ||
}; | ||
ReactPropTypes.checkPropTypes = emptyFunction; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
@@ -127,3 +244,3 @@ * Copyright (c) 2013-present, Facebook, Inc. | ||
/***/ }), | ||
/* 1 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -155,9 +272,3 @@ | ||
if (true) { | ||
validateFormat = function validateFormat(format) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
}; | ||
} | ||
if (false) {} | ||
@@ -188,3 +299,3 @@ function invariant(condition, format, a, b, c, d, e, f) { | ||
/***/ }), | ||
/* 2 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -194,70 +305,2 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
var emptyFunction = __webpack_require__(0); | ||
/** | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var warning = emptyFunction; | ||
if (true) { | ||
var printWarning = function printWarning(format) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
warning = function warning(condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
if (format.indexOf('Failed Composite propType: ') === 0) { | ||
return; // Ignore CompositeComponent proptype check. | ||
} | ||
if (!condition) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
printWarning.apply(undefined, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
module.exports = warning; | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
@@ -277,873 +320,511 @@ * | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(5); | ||
/***/ }), | ||
/* 5 */ | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ReactHotkeys; }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(6); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(7); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_prop_types__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_hotkeys_js__ = __webpack_require__(11); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_hotkeys_js__); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
__webpack_require__.r(__webpack_exports__); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
// EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} | ||
var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__(1); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
// EXTERNAL MODULE: ./node_modules/prop-types/index.js | ||
var prop_types = __webpack_require__(0); | ||
var prop_types_default = /*#__PURE__*/__webpack_require__.n(prop_types); | ||
// CONCATENATED MODULE: ./node_modules/hotkeys-js/dist/hotkeys.esm.js | ||
/*! | ||
* hotkeys-js v3.3.8 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
* | ||
* Copyright (c) 2018 kenny wong <wowohoo@qq.com> | ||
* http://jaywcjlove.github.io/hotkeys | ||
* | ||
* Licensed under the MIT license. | ||
*/ | ||
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
// 绑定事件 | ||
function addEvent(object, event, method) { | ||
if (object.addEventListener) { | ||
object.addEventListener(event, method, false); | ||
} else if (object.attachEvent) { | ||
object.attachEvent('on' + event, function () { | ||
method(window.event); | ||
}); | ||
} | ||
} | ||
// 修饰键转换成对应的键码 | ||
function getMods(modifier, key) { | ||
var mods = key.slice(0, key.length - 1); | ||
for (var i = 0; i < mods.length; i++) { | ||
mods[i] = modifier[mods[i].toLowerCase()]; | ||
}return mods; | ||
} | ||
__WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default.a.filter = function (event) { | ||
var tagName = (event.target || event.srcElement).tagName; | ||
__WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default.a.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other'); | ||
return true; | ||
}; | ||
// 处理传的key字符串转换成数组 | ||
function getKeys(key) { | ||
if (!key) key = ''; | ||
var ReactHotkeys = function (_Component) { | ||
_inherits(ReactHotkeys, _Component); | ||
key = key.replace(/\s/g, ''); // 匹配任何空白字符,包括空格、制表符、换页符等等 | ||
var keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
var index = keys.lastIndexOf(''); | ||
function ReactHotkeys(props) { | ||
_classCallCheck(this, ReactHotkeys); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
_this.onKeyDown = _this.onKeyDown.bind(_this); | ||
_this.onKeyUp = _this.onKeyUp.bind(_this); | ||
_this.handleKeyUpEvent = _this.handleKeyUpEvent.bind(_this); | ||
_this.isKeyDown = false; | ||
_this.handle = {}; | ||
return _this; | ||
// 快捷键可能包含',',需特殊处理 | ||
for (; index >= 0;) { | ||
keys[index - 1] += ','; | ||
keys.splice(index, 1); | ||
index = keys.lastIndexOf(''); | ||
} | ||
ReactHotkeys.prototype.componentDidMount = function componentDidMount() { | ||
__WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default.a.unbind(this.props.keyName); | ||
__WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default()(this.props.keyName, this.onKeyDown); | ||
document.addEventListener('keyup', this.handleKeyUpEvent); | ||
}; | ||
return keys; | ||
} | ||
ReactHotkeys.prototype.componentWillUnmount = function componentWillUnmount() { | ||
__WEBPACK_IMPORTED_MODULE_2_hotkeys_js___default.a.unbind(this.props.keyName); | ||
this.isKeyDown = true; | ||
this.handle = {}; | ||
document.removeEventListener('keyup', this.handleKeyUpEvent); | ||
}; | ||
// 比较修饰键的数组 | ||
function compareArray(a1, a2) { | ||
var arr1 = a1.length >= a2.length ? a1 : a2; | ||
var arr2 = a1.length >= a2.length ? a2 : a1; | ||
var isIndex = true; | ||
ReactHotkeys.prototype.onKeyUp = function onKeyUp(e, handle) { | ||
var onKeyUp = this.props.onKeyUp; | ||
for (var i = 0; i < arr1.length; i++) { | ||
if (arr2.indexOf(arr1[i]) === -1) isIndex = false; | ||
} | ||
return isIndex; | ||
} | ||
onKeyUp(handle.shortcut, e, handle); | ||
}; | ||
ReactHotkeys.prototype.onKeyDown = function onKeyDown(e, handle) { | ||
var onKeyDown = this.props.onKeyDown; | ||
if (this.isKeyDown) return; | ||
this.isKeyDown = true; | ||
this.handle = handle; | ||
onKeyDown(handle.shortcut, e, handle); | ||
}; | ||
ReactHotkeys.prototype.handleKeyUpEvent = function handleKeyUpEvent(e) { | ||
if (!this.isKeyDown) return; | ||
this.isKeyDown = false; | ||
if (this.props.keyName.indexOf(this.handle.shortcut) < 0) return; | ||
this.onKeyUp(e, this.handle); | ||
this.handle = {}; | ||
}; | ||
ReactHotkeys.prototype.render = function render() { | ||
return this.props.children || null; | ||
}; | ||
return ReactHotkeys; | ||
}(__WEBPACK_IMPORTED_MODULE_0_react__["Component"]); | ||
ReactHotkeys.propTypes = { | ||
keyName: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string, | ||
onKeyDown: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.func, | ||
onKeyUp: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.func | ||
var _keyMap = { // 特殊键 | ||
backspace: 8, | ||
tab: 9, | ||
clear: 12, | ||
enter: 13, | ||
return: 13, | ||
esc: 27, | ||
escape: 27, | ||
space: 32, | ||
left: 37, | ||
up: 38, | ||
right: 39, | ||
down: 40, | ||
del: 46, | ||
delete: 46, | ||
ins: 45, | ||
insert: 45, | ||
home: 36, | ||
end: 35, | ||
pageup: 33, | ||
pagedown: 34, | ||
capslock: 20, | ||
'⇪': 20, | ||
',': 188, | ||
'.': 190, | ||
'/': 191, | ||
'`': 192, | ||
'-': isff ? 173 : 189, | ||
'=': isff ? 61 : 187, | ||
';': isff ? 59 : 186, | ||
'\'': 222, | ||
'[': 219, | ||
']': 221, | ||
'\\': 220 | ||
}; | ||
ReactHotkeys.defaultProps = { | ||
onKeyUp: function onKeyUp() {}, | ||
onKeyDown: function onKeyDown() {} | ||
var _modifier = { // 修饰键 | ||
'⇧': 16, | ||
shift: 16, | ||
'⌥': 18, | ||
alt: 18, | ||
option: 18, | ||
'⌃': 17, | ||
ctrl: 17, | ||
control: 17, | ||
'⌘': isff ? 224 : 91, | ||
cmd: isff ? 224 : 91, | ||
command: isff ? 224 : 91 | ||
}; | ||
var _downKeys = []; // 记录摁下的绑定键 | ||
var modifierMap = { | ||
16: 'shiftKey', | ||
18: 'altKey', | ||
17: 'ctrlKey' | ||
}; | ||
var _mods = { 16: false, 18: false, 17: false }; | ||
var _handlers = {}; | ||
/***/ }), | ||
/* 6 */ | ||
/***/ (function(module, exports) { | ||
// F1~F12 特殊键 | ||
for (var k = 1; k < 20; k++) { | ||
_keyMap['f' + k] = 111 + k; | ||
} | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_6__; | ||
// 兼容Firefox处理 | ||
modifierMap[isff ? 224 : 91] = 'metaKey'; | ||
_mods[isff ? 224 : 91] = false; | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var _scope = 'all'; // 默认热键范围 | ||
var isBindElement = false; // 是否绑定节点 | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// 返回键码 | ||
var code = function code(x) { | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
if (true) { | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
// 设置获取当前范围(默认为'所有') | ||
function setScope(scope) { | ||
_scope = scope || 'all'; | ||
} | ||
// 获取当前范围 | ||
function getScope() { | ||
return _scope || 'all'; | ||
} | ||
// 获取摁下绑定键的键值 | ||
function getPressedKeyCodes() { | ||
return _downKeys.slice(0); | ||
} | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
// 表单控件控件判断 返回 Boolean | ||
function filter(event) { | ||
var target = event.target || event.srcElement; | ||
var tagName = target.tagName; | ||
// 忽略这些情况下快捷键无效 | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = __webpack_require__(8)(isValidElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = require('./factoryWithThrowingShims')(); | ||
return !(tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA' || target.isContentEditable); | ||
} | ||
// 判断摁下的键是否为某个键,返回true或者false | ||
function isPressed(keyCode) { | ||
if (typeof keyCode === 'string') { | ||
keyCode = code(keyCode); // 转换成键码 | ||
} | ||
return _downKeys.indexOf(keyCode) !== -1; | ||
} | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
// 循环删除handlers中的所有 scope(范围) | ||
function deleteScope(scope, newScope) { | ||
var handlers = void 0; | ||
var i = void 0; | ||
"use strict"; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// 没有指定scope,获取scope | ||
if (!scope) scope = getScope(); | ||
var emptyFunction = __webpack_require__(0); | ||
var invariant = __webpack_require__(1); | ||
var warning = __webpack_require__(2); | ||
var assign = __webpack_require__(9); | ||
var ReactPropTypesSecret = __webpack_require__(3); | ||
var checkPropTypes = __webpack_require__(10); | ||
module.exports = function(isValidElement, throwOnDirectAccess) { | ||
/* global Symbol */ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
/** | ||
* Returns the iterator method function contained on the iterable object. | ||
* | ||
* Be sure to invoke the function with the iterable as context: | ||
* | ||
* var iteratorFn = getIteratorFn(myIterable); | ||
* if (iteratorFn) { | ||
* var iterator = iteratorFn.call(myIterable); | ||
* ... | ||
* } | ||
* | ||
* @param {?object} maybeIterable | ||
* @return {?function} | ||
*/ | ||
function getIteratorFn(maybeIterable) { | ||
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); | ||
if (typeof iteratorFn === 'function') { | ||
return iteratorFn; | ||
for (var key in _handlers) { | ||
if (Object.prototype.hasOwnProperty.call(_handlers, key)) { | ||
handlers = _handlers[key]; | ||
for (i = 0; i < handlers.length;) { | ||
if (handlers[i].scope === scope) handlers.splice(i, 1);else i++; | ||
} | ||
} | ||
} | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
// 如果scope被删除,将scope重置为all | ||
if (getScope() === scope) setScope(newScope || 'all'); | ||
} | ||
var ANONYMOUS = '<<anonymous>>'; | ||
// 清除修饰键 | ||
function clearModifier(event) { | ||
var key = event.keyCode || event.which || event.charCode; | ||
var i = _downKeys.indexOf(key); | ||
// Important! | ||
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`. | ||
var ReactPropTypes = { | ||
array: createPrimitiveTypeChecker('array'), | ||
bool: createPrimitiveTypeChecker('boolean'), | ||
func: createPrimitiveTypeChecker('function'), | ||
number: createPrimitiveTypeChecker('number'), | ||
object: createPrimitiveTypeChecker('object'), | ||
string: createPrimitiveTypeChecker('string'), | ||
symbol: createPrimitiveTypeChecker('symbol'), | ||
// 从列表中清除按压过的键 | ||
if (i >= 0) _downKeys.splice(i, 1); | ||
any: createAnyTypeChecker(), | ||
arrayOf: createArrayOfTypeChecker, | ||
element: createElementTypeChecker(), | ||
instanceOf: createInstanceTypeChecker, | ||
node: createNodeChecker(), | ||
objectOf: createObjectOfTypeChecker, | ||
oneOf: createEnumTypeChecker, | ||
oneOfType: createUnionTypeChecker, | ||
shape: createShapeTypeChecker, | ||
exact: createStrictShapeTypeChecker, | ||
}; | ||
// 修饰键 shiftKey altKey ctrlKey (command||metaKey) 清除 | ||
if (key === 93 || key === 224) key = 91; | ||
if (key in _mods) { | ||
_mods[key] = false; | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
/*eslint-disable no-self-compare*/ | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
return x !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
// 将修饰键重置为false | ||
for (var k in _modifier) { | ||
if (_modifier[k] === key) hotkeys[k] = false; | ||
} | ||
} | ||
/*eslint-enable no-self-compare*/ | ||
} | ||
/** | ||
* We use an Error-like object for backward compatibility as people may call | ||
* PropTypes directly and inspect their output. However, we don't use real | ||
* Errors anymore. We don't inspect their stack anyway, and creating them | ||
* is prohibitively expensive if they are created too often, such as what | ||
* happens in oneOfType() for any type before the one that matched. | ||
*/ | ||
function PropTypeError(message) { | ||
this.message = message; | ||
this.stack = ''; | ||
} | ||
// Make `instanceof Error` still work for returned errors. | ||
PropTypeError.prototype = Error.prototype; | ||
// 解除绑定某个范围的快捷键 | ||
function unbind(key, scope) { | ||
var multipleKeys = getKeys(key); | ||
var keys = void 0; | ||
var mods = []; | ||
var obj = void 0; | ||
function createChainableTypeChecker(validate) { | ||
if (true) { | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
for (var i = 0; i < multipleKeys.length; i++) { | ||
// 将组合快捷键拆分为数组 | ||
keys = multipleKeys[i].split('+'); | ||
if (secret !== ReactPropTypesSecret) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
invariant( | ||
false, | ||
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + | ||
'Use `PropTypes.checkPropTypes()` to call them. ' + | ||
'Read more at http://fb.me/use-check-prop-types' | ||
); | ||
} else if ("development" !== 'production' && typeof console !== 'undefined') { | ||
// Old behavior for people using React.PropTypes | ||
var cacheKey = componentName + ':' + propName; | ||
if ( | ||
!manualPropTypeCallCache[cacheKey] && | ||
// Avoid spamming the console because they are often not actionable except for lib authors | ||
manualPropTypeWarningCount < 3 | ||
) { | ||
warning( | ||
false, | ||
'You are manually calling a React.PropTypes validation ' + | ||
'function for the `%s` prop on `%s`. This is deprecated ' + | ||
'and will throw in the standalone `prop-types` package. ' + | ||
'You may be seeing this warning due to a third-party PropTypes ' + | ||
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', | ||
propFullName, | ||
componentName | ||
); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
} | ||
} | ||
} | ||
if (props[propName] == null) { | ||
if (isRequired) { | ||
if (props[propName] === null) { | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); | ||
} | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); | ||
} | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
// 记录每个组合键中的修饰键的键码 返回数组 | ||
if (keys.length > 1) mods = getMods(_modifier, keys); | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
// 获取除修饰键外的键值key | ||
key = keys[keys.length - 1]; | ||
key = key === '*' ? '*' : code(key); | ||
return chainedCheckType; | ||
} | ||
// 判断是否传入范围,没有就获取范围 | ||
if (!scope) scope = getScope(); | ||
function createPrimitiveTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== expectedType) { | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
// 如何key不在 _handlers 中返回不做处理 | ||
if (!_handlers[key]) return; | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
// 清空 handlers 中数据, | ||
// 让触发快捷键键之后没有事件执行到达解除快捷键绑定的目的 | ||
for (var r = 0; r < _handlers[key].length; r++) { | ||
obj = _handlers[key][r]; | ||
// 判断是否在范围内并且键值相同 | ||
if (obj.scope === scope && compareArray(obj.mods, mods)) { | ||
_handlers[key][r] = {}; | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
} | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunction.thatReturnsNull); | ||
} | ||
// 对监听对应快捷键的回调函数进行处理 | ||
function eventHandler(event, handler, scope) { | ||
var modifiersMatch = void 0; | ||
function createArrayOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); | ||
} | ||
var propValue = props[propName]; | ||
if (!Array.isArray(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); | ||
} | ||
for (var i = 0; i < propValue.length; i++) { | ||
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
// 看它是否在当前范围 | ||
if (handler.scope === scope || handler.scope === 'all') { | ||
// 检查是否匹配修饰符(如果有返回true) | ||
modifiersMatch = handler.mods.length > 0; | ||
function createElementTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!isValidElement(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); | ||
for (var y in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, y)) { | ||
if (!_mods[y] && handler.mods.indexOf(+y) > -1 || _mods[y] && handler.mods.indexOf(+y) === -1) modifiersMatch = false; | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createInstanceTypeChecker(expectedClass) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!(props[propName] instanceof expectedClass)) { | ||
var expectedClassName = expectedClass.name || ANONYMOUS; | ||
var actualClassName = getClassName(props[propName]); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); | ||
// 调用处理程序,如果是修饰键不做处理 | ||
if (handler.mods.length === 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91] || modifiersMatch || handler.shortcut === '*') { | ||
if (handler.method(event, handler) === false) { | ||
if (event.preventDefault) event.preventDefault();else event.returnValue = false; | ||
if (event.stopPropagation) event.stopPropagation(); | ||
if (event.cancelBubble) event.cancelBubble = true; | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
true ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; | ||
return emptyFunction.thatReturnsNull; | ||
} | ||
// 处理keydown事件 | ||
function dispatch(event) { | ||
var asterisk = _handlers['*']; | ||
var key = event.keyCode || event.which || event.charCode; | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
for (var i = 0; i < expectedValues.length; i++) { | ||
if (is(propValue, expectedValues[i])) { | ||
return null; | ||
} | ||
} | ||
// 搜集绑定的键 | ||
if (_downKeys.indexOf(key) === -1) _downKeys.push(key); | ||
var valuesString = JSON.stringify(expectedValues); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
// Gecko(Firefox)的command键值224,在Webkit(Chrome)中保持一致 | ||
// Webkit左右command键值不一样 | ||
if (key === 93 || key === 224) key = 91; | ||
if (key in _mods) { | ||
_mods[key] = true; | ||
// 将特殊字符的key注册到 hotkeys 上 | ||
for (var k in _modifier) { | ||
if (_modifier[k] === key) hotkeys[k] = true; | ||
} | ||
return createChainableTypeChecker(validate); | ||
if (!asterisk) return; | ||
} | ||
function createObjectOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); | ||
} | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); | ||
} | ||
for (var key in propValue) { | ||
if (propValue.hasOwnProperty(key)) { | ||
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
// 将modifierMap里面的修饰键绑定到event中 | ||
for (var e in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, e)) { | ||
_mods[e] = event[modifierMap[e]]; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
true ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; | ||
return emptyFunction.thatReturnsNull; | ||
} | ||
// 表单控件过滤 默认表单控件不触发快捷键 | ||
if (!hotkeys.filter.call(this, event)) return; | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (typeof checker !== 'function') { | ||
warning( | ||
false, | ||
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + | ||
'received %s at index %s.', | ||
getPostfixForTypeWarning(checker), | ||
i | ||
); | ||
return emptyFunction.thatReturnsNull; | ||
} | ||
} | ||
// 获取范围 默认为all | ||
var scope = getScope(); | ||
function validate(props, propName, componentName, location, propFullName) { | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) { | ||
return null; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
// 对任何快捷键都需要做的处理 | ||
if (asterisk) { | ||
for (var i = 0; i < asterisk.length; i++) { | ||
if (asterisk[i].scope === scope) eventHandler(event, asterisk[i], scope); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
// key 不在_handlers中返回 | ||
if (!(key in _handlers)) return; | ||
function createNodeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!isNode(props[propName])) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
for (var _i = 0; _i < _handlers[key].length; _i++) { | ||
// 找到处理内容 | ||
eventHandler(event, _handlers[key][_i], scope); | ||
} | ||
} | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
function hotkeys(key, option, method) { | ||
var keys = getKeys(key); // 需要处理的快捷键列表 | ||
var mods = []; | ||
var scope = 'all'; // scope默认为all,所有范围都有效 | ||
var element = document; // 快捷键事件绑定节点 | ||
var i = 0; | ||
// 对为设定范围的判断 | ||
if (method === undefined && typeof option === 'function') { | ||
method = option; | ||
} | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
// We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = assign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError( | ||
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + | ||
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') + | ||
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') | ||
); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
if (Object.prototype.toString.call(option) === '[object Object]') { | ||
if (option.scope) scope = option.scope; // eslint-disable-line | ||
if (option.element) element = option.element; // eslint-disable-line | ||
} | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
return true; | ||
} | ||
if (typeof option === 'string') scope = option; | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
// 对于每个快捷键进行处理 | ||
for (; i < keys.length; i++) { | ||
key = keys[i].split('+'); // 按键列表 | ||
mods = []; | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
// 如果是组合快捷键取得组合快捷键 | ||
if (key.length > 1) mods = getMods(_modifier, key); | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
} | ||
// 将非修饰键转化为键码 | ||
key = key[key.length - 1]; | ||
key = key === '*' ? '*' : code(key); // *表示匹配所有快捷键 | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} | ||
// 判断key是否在_handlers中,不在就赋一个空数组 | ||
if (!(key in _handlers)) _handlers[key] = []; | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
return false; | ||
_handlers[key].push({ | ||
scope: scope, | ||
mods: mods, | ||
shortcut: keys[i], | ||
method: method, | ||
key: keys[i] | ||
}); | ||
} | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
// 在全局document上设置快捷键 | ||
if (typeof element !== 'undefined' && !isBindElement) { | ||
isBindElement = true; | ||
addEvent(element, 'keydown', function (e) { | ||
dispatch(e); | ||
}); | ||
addEvent(element, 'keyup', function (e) { | ||
clearModifier(e); | ||
}); | ||
} | ||
} | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
} | ||
} | ||
return propType; | ||
var _api = { | ||
setScope: setScope, | ||
getScope: getScope, | ||
deleteScope: deleteScope, | ||
getPressedKeyCodes: getPressedKeyCodes, | ||
isPressed: isPressed, | ||
filter: filter, | ||
unbind: unbind | ||
}; | ||
for (var a in _api) { | ||
if (Object.prototype.hasOwnProperty.call(_api, a)) { | ||
hotkeys[a] = _api[a]; | ||
} | ||
} | ||
// Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
if (typeof window !== 'undefined') { | ||
var _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = function (deep) { | ||
if (deep && window.hotkeys === hotkeys) { | ||
window.hotkeys = _hotkeys; | ||
} | ||
} | ||
return hotkeys; | ||
}; | ||
window.hotkeys = hotkeys; | ||
} | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
/* harmony default export */ var hotkeys_esm = (hotkeys); | ||
ReactPropTypes.checkPropTypes = checkPropTypes; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
// CONCATENATED MODULE: ./src/index.js | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return src_ReactHotkeys; }); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
return ReactPropTypes; | ||
}; | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
hotkeys_esm.filter = function (event) { | ||
var tagName = (event.target || event.srcElement).tagName; | ||
hotkeys_esm.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other'); | ||
return true; | ||
}; | ||
return Object(val); | ||
} | ||
var src_ReactHotkeys = function (_Component) { | ||
_inherits(ReactHotkeys, _Component); | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
function ReactHotkeys(props) { | ||
_classCallCheck(this, ReactHotkeys); | ||
// Detect buggy property enumeration order in older V8 versions. | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
test1[5] = 'de'; | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} | ||
_this.onKeyDown = _this.onKeyDown.bind(_this); | ||
_this.onKeyUp = _this.onKeyUp.bind(_this); | ||
_this.handleKeyUpEvent = _this.handleKeyUpEvent.bind(_this); | ||
_this.isKeyDown = false; | ||
_this.handle = {}; | ||
return _this; | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test2 = {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} | ||
ReactHotkeys.prototype.componentDidMount = function componentDidMount() { | ||
hotkeys_esm.unbind(this.props.keyName); | ||
hotkeys_esm(this.props.keyName, this.onKeyDown); | ||
document.addEventListener('keyup', this.handleKeyUpEvent); | ||
}; | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
if (Object.keys(Object.assign({}, test3)).join('') !== | ||
'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
ReactHotkeys.prototype.componentWillUnmount = function componentWillUnmount() { | ||
hotkeys_esm.unbind(this.props.keyName); | ||
this.isKeyDown = true; | ||
this.handle = {}; | ||
document.removeEventListener('keyup', this.handleKeyUpEvent); | ||
}; | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
ReactHotkeys.prototype.onKeyUp = function onKeyUp(e, handle) { | ||
var onKeyUp = this.props.onKeyUp; | ||
module.exports = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
onKeyUp(handle.shortcut, e, handle); | ||
}; | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
ReactHotkeys.prototype.onKeyDown = function onKeyDown(e, handle) { | ||
var onKeyDown = this.props.onKeyDown; | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
if (this.isKeyDown) return; | ||
this.isKeyDown = true; | ||
this.handle = handle; | ||
onKeyDown(handle.shortcut, e, handle); | ||
}; | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
ReactHotkeys.prototype.handleKeyUpEvent = function handleKeyUpEvent(e) { | ||
if (!this.isKeyDown) return; | ||
this.isKeyDown = false; | ||
if (this.props.keyName.indexOf(this.handle.shortcut) < 0) return; | ||
this.onKeyUp(e, this.handle); | ||
this.handle = {}; | ||
}; | ||
return to; | ||
}; | ||
ReactHotkeys.prototype.render = function render() { | ||
return this.props.children || null; | ||
}; | ||
return ReactHotkeys; | ||
}(external_root_React_commonjs2_react_commonjs_react_amd_react_["Component"]); | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
src_ReactHotkeys.propTypes = { | ||
keyName: prop_types_default.a.string, | ||
onKeyDown: prop_types_default.a.func, | ||
onKeyUp: prop_types_default.a.func | ||
}; | ||
if (true) { | ||
var invariant = __webpack_require__(1); | ||
var warning = __webpack_require__(2); | ||
var ReactPropTypesSecret = __webpack_require__(3); | ||
var loggedTypeFailures = {}; | ||
} | ||
src_ReactHotkeys.defaultProps = { | ||
onKeyUp: function onKeyUp() {}, | ||
onKeyDown: function onKeyDown() {} | ||
}; | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (true) { | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
var stack = getStack ? getStack() : ''; | ||
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
module.exports = checkPropTypes; | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/*! hotkeys-js v2.0.9 | MIT (c) 2018 kenny wang <wowohoo@qq.com> | https://github.com/jaywcjlove/hotkeys.git */ | ||
!function(e){if(true)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).hotkeys=e()}}(function(){Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;n<this.length;n++)if(this[n]===e)return n;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(e){for(var n=this.length-1;n>=0;n--)if(this[n]===e)return n;return-1});for(var e,n="undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("firefox")>0,t={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,"⇪":20,capslock:20,",":188,".":190,"/":191,"`":192,"-":n?173:189,"=":n?61:187,";":n?59:186,"'":222,"[":219,"]":221,"\\":220},o="all",r={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":n?224:91,cmd:n?224:91,command:n?224:91},i=[],f={16:"shiftKey",18:"altKey",17:"ctrlKey"},a={16:!1,18:!1,17:!1},l={},d=1;d<20;d++)t["f"+d]=111+d;function s(e){return t[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)}function c(e){o=e||"all"}function u(){return o||"all"}function p(e,n,t){e.addEventListener?e.addEventListener(n,t,!1):e.attachEvent&&e.attachEvent("on"+n,function(){t(window.event)})}function h(e,n,t){var o;if(n.scope===t||"all"===n.scope){for(var r in o=n.mods.length>0,a)(!a[r]&&n.mods.indexOf(+r)>-1||a[r]&&-1===n.mods.indexOf(+r))&&(o=!1);(0!==n.mods.length||a[16]||a[18]||a[17]||a[91])&&!o&&"*"!==n.shortcut||!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function g(e,n){for(var t=e.length>=n.length?e:n,o=e.length>=n.length?n:e,r=0;r<t.length;r++)if(-1===o.indexOf(t[r]))return!1;return!0}function y(e){for(var n=e.slice(0,e.length-1),t=0;t<n.length;t++)n[t]=r[n[t].toLowerCase()];return n}function v(e){var n,t;for(e||(e=""),t=(n=(e=e.replace(/\s/g,"")).split(",")).lastIndexOf("");t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function w(e,n,t){var o=v(e),r=[],i=0;for(void 0===t&&(t=n,n="all");i<o.length;i++)r=[],(e=o[i].split("+")).length>1&&(r=y(e)),(e="*"===(e=e[e.length-1])?"*":s(e))in l||(l[e]=[]),l[e].push({shortcut:o[i],scope:n,method:t,key:o[i],mods:r})}for(var m in f[n?224:91]="metaKey",a[n?224:91]=!1,"undefined"!=typeof document&&(p(document,"keydown",function(e){!function(e){var n,t=e.keyCode||e.which||e.charCode,o=l["*"];if(-1===i.indexOf(t)&&i.push(t),93!==t&&224!==t||(t=91),t in a){for(var d in a[t]=!0,r)r[d]===t&&(w[d]=!0);if(!o)return}for(var s in a)a[s]=e[f[s]];if(w.filter.call(this,e)){if(n=u(),o)for(c=0;c<o.length;c++)o[c].scope===n&&h(e,o[c],n);if(t in l)for(var c=0;c<l[t].length;c++)h(e,l[t][c],n)}}(e)}),p(document,"keyup",function(e){!function(e){var n=e.keyCode||e.which||e.charCode,t=i.indexOf(n);t>=0&&i.splice(t,1);93!==n&&224!==n||(n=91);if(n in a)for(var o in a[n]=!1,r)r[o]===n&&(w[o]=!1)}(e)})),e={setScope:c,getScope:u,deleteScope:function(e,n){var t,o,r;for(t in e||(e=u()),l)for(o=l[t],r=0;r<o.length;)o[r].scope===e?o.splice(r,1):r++;u()===e&&c(n||"all")},getPressedKeyCodes:function(){return i.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=s(e)),-1!==i.indexOf(e)},filter:function(e){var n=(e.target||e.srcElement).tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n)},unbind:function(e,n){for(var t,o,r=v(e),i=[],f=0;f<r.length;f++){if((t=r[f].split("+")).length>1&&(i=y(t)),e="*"===(e=t[t.length-1])?"*":s(e),n||(n=u()),!l[e])return;for(var a=0;a<l[e].length;a++)(o=l[e][a]).scope===n&&g(o.mods,i)&&(l[e][a]={})}}})w[m]=e[m];if("undefined"!=typeof window){var x=window.hotkeys;w.noConflict=function(e){return e&&window.hotkeys===w&&(window.hotkeys=x),w},window.hotkeys=w}return window.hotkeys=w,w}); | ||
/***/ }) | ||
/******/ ])["default"]; | ||
}); |
/*! | ||
* react-hot-keys v1.0.11 - https://jaywcjlove.github.io/react-hotkeys/ | ||
* react-hot-keys v1.2.2 - https://jaywcjlove.github.io/react-hotkeys/ | ||
* MIT Licensed | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactHotkeys=t(require("react")):e.ReactHotkeys=t(e.React)}("undefined"!=typeof self?self:this,function(e){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),n.d(t,"default",function(){return f});var o=n(2),r=(n.n(o),n(3)),i=n.n(r);i.a.filter=function(e){var t=(e.target||e.srcElement).tagName;return i.a.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(t)?"input":"other"),!0};var f=function(e){function t(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,n));return o.onKeyDown=o.onKeyDown.bind(o),o.onKeyUp=o.onKeyUp.bind(o),o.handleKeyUpEvent=o.handleKeyUpEvent.bind(o),o.isKeyDown=!1,o.handle={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.componentDidMount=function(){i.a.unbind(this.props.keyName),i()(this.props.keyName,this.onKeyDown),document.addEventListener("keyup",this.handleKeyUpEvent)},t.prototype.componentWillUnmount=function(){i.a.unbind(this.props.keyName),this.isKeyDown=!0,this.handle={},document.removeEventListener("keyup",this.handleKeyUpEvent)},t.prototype.onKeyUp=function(e,t){var n=this.props.onKeyUp;n(t.shortcut,e,t)},t.prototype.onKeyDown=function(e,t){var n=this.props.onKeyDown;this.isKeyDown||(this.isKeyDown=!0,this.handle=t,n(t.shortcut,e,t))},t.prototype.handleKeyUpEvent=function(e){this.isKeyDown&&(this.isKeyDown=!1,this.props.keyName.indexOf(this.handle.shortcut)<0||(this.onKeyUp(e,this.handle),this.handle={}))},t.prototype.render=function(){return this.props.children||null},t}(o.Component);f.defaultProps={onKeyUp:function(){},onKeyDown:function(){}}},function(t,n){t.exports=e},function(e,t,n){var o;o=function(){Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;t<this.length;t++)if(this[t]===e)return t;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(e){for(var t=this.length-1;t>=0;t--)if(this[t]===e)return t;return-1});for(var e,t="undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("firefox")>0,n={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,"⇪":20,capslock:20,",":188,".":190,"/":191,"`":192,"-":t?173:189,"=":t?61:187,";":t?59:186,"'":222,"[":219,"]":221,"\\":220},o="all",r={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":t?224:91,cmd:t?224:91,command:t?224:91},i=[],f={16:"shiftKey",18:"altKey",17:"ctrlKey"},s={16:!1,18:!1,17:!1},a={},u=1;u<20;u++)n["f"+u]=111+u;function c(e){return n[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)}function p(e){o=e||"all"}function l(){return o||"all"}function d(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,function(){n(window.event)})}function h(e,t,n){var o;if(t.scope===n||"all"===t.scope){for(var r in o=t.mods.length>0,s)(!s[r]&&t.mods.indexOf(+r)>-1||s[r]&&-1===t.mods.indexOf(+r))&&(o=!1);(0!==t.mods.length||s[16]||s[18]||s[17]||s[91])&&!o&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function y(e,t){for(var n=e.length>=t.length?e:t,o=e.length>=t.length?t:e,r=0;r<n.length;r++)if(-1===o.indexOf(n[r]))return!1;return!0}function v(e){for(var t=e.slice(0,e.length-1),n=0;n<t.length;n++)t[n]=r[t[n].toLowerCase()];return t}function w(e){var t,n;for(e||(e=""),n=(t=(e=e.replace(/\s/g,"")).split(",")).lastIndexOf("");n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function g(e,t,n){var o=w(e),r=[],i=0;for(void 0===n&&(n=t,t="all");i<o.length;i++)r=[],(e=o[i].split("+")).length>1&&(r=v(e)),(e="*"===(e=e[e.length-1])?"*":c(e))in a||(a[e]=[]),a[e].push({shortcut:o[i],scope:t,method:n,key:o[i],mods:r})}for(var m in f[t?224:91]="metaKey",s[t?224:91]=!1,"undefined"!=typeof document&&(d(document,"keydown",function(e){!function(e){var t,n=e.keyCode||e.which||e.charCode,o=a["*"];if(-1===i.indexOf(n)&&i.push(n),93!==n&&224!==n||(n=91),n in s){for(var u in s[n]=!0,r)r[u]===n&&(g[u]=!0);if(!o)return}for(var c in s)s[c]=e[f[c]];if(g.filter.call(this,e)){if(t=l(),o)for(p=0;p<o.length;p++)o[p].scope===t&&h(e,o[p],t);if(n in a)for(var p=0;p<a[n].length;p++)h(e,a[n][p],t)}}(e)}),d(document,"keyup",function(e){!function(e){var t=e.keyCode||e.which||e.charCode,n=i.indexOf(t);if(n>=0&&i.splice(n,1),93!==t&&224!==t||(t=91),t in s)for(var o in s[t]=!1,r)r[o]===t&&(g[o]=!1)}(e)})),e={setScope:p,getScope:l,deleteScope:function(e,t){var n,o,r;for(n in e||(e=l()),a)for(o=a[n],r=0;r<o.length;)o[r].scope===e?o.splice(r,1):r++;l()===e&&p(t||"all")},getPressedKeyCodes:function(){return i.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=c(e)),-1!==i.indexOf(e)},filter:function(e){var t=(e.target||e.srcElement).tagName;return!("INPUT"===t||"SELECT"===t||"TEXTAREA"===t)},unbind:function(e,t){for(var n,o,r=w(e),i=[],f=0;f<r.length;f++){if((n=r[f].split("+")).length>1&&(i=v(n)),e="*"===(e=n[n.length-1])?"*":c(e),t||(t=l()),!a[e])return;for(var s=0;s<a[e].length;s++)(o=a[e][s]).scope===t&&y(o.mods,i)&&(a[e][s]={})}}})g[m]=e[m];if("undefined"!=typeof window){var b=window.hotkeys;g.noConflict=function(e){return e&&window.hotkeys===g&&(window.hotkeys=b),g},window.hotkeys=g}return window.hotkeys=g,g},e.exports=o()}]).default}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactHotkeys=t(require("react")):e.ReactHotkeys=t(e.React)}(window,function(e){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(t,n){t.exports=e},function(e,t,n){e.exports=n(2)},function(e,t,n){"use strict";n.r(t);var o=n(0),r="undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("firefox")>0; | ||
/*! | ||
* hotkeys-js v3.3.8 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
* | ||
* Copyright (c) 2018 kenny wong <wowohoo@qq.com> | ||
* http://jaywcjlove.github.io/hotkeys | ||
* | ||
* Licensed under the MIT license. | ||
*/function i(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,function(){n(window.event)})}function a(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function c(e){e||(e="");for(var t=(e=e.replace(/\s/g,"")).split(","),n=t.lastIndexOf("");n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function s(e,t){for(var n=e.length>=t.length?e:t,o=e.length>=t.length?t:e,r=!0,i=0;i<n.length;i++)-1===o.indexOf(n[i])&&(r=!1);return r}for(var f={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,"⇪":20,",":188,".":190,"/":191,"`":192,"-":r?173:189,"=":r?61:187,";":r?59:186,"'":222,"[":219,"]":221,"\\":220},u={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":r?224:91,cmd:r?224:91,command:r?224:91},p=[],l={16:"shiftKey",18:"altKey",17:"ctrlKey"},d={16:!1,18:!1,17:!1},h={},y=1;y<20;y++)f["f"+y]=111+y;l[r?224:91]="metaKey",d[r?224:91]=!1;var v="all",w=!1,b=function(e){return f[e.toLowerCase()]||u[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function g(e){v=e||"all"}function m(){return v||"all"}function O(e,t,n){var o=void 0;if(t.scope===n||"all"===t.scope){for(var r in o=t.mods.length>0,d)Object.prototype.hasOwnProperty.call(d,r)&&(!d[r]&&t.mods.indexOf(+r)>-1||d[r]&&-1===t.mods.indexOf(+r))&&(o=!1);(0!==t.mods.length||d[16]||d[18]||d[17]||d[91])&&!o&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function K(e,t,n){var o=c(e),r=[],s="all",f=document,y=0;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(s=t.scope),t.element&&(f=t.element)),"string"==typeof t&&(s=t);y<o.length;y++)r=[],(e=o[y].split("+")).length>1&&(r=a(u,e)),(e="*"===(e=e[e.length-1])?"*":b(e))in h||(h[e]=[]),h[e].push({scope:s,mods:r,shortcut:o[y],method:n,key:o[y]});void 0===f||w||(w=!0,i(f,"keydown",function(e){!function(e){var t=h["*"],n=e.keyCode||e.which||e.charCode;if(-1===p.indexOf(n)&&p.push(n),93!==n&&224!==n||(n=91),n in d){for(var o in d[n]=!0,u)u[o]===n&&(K[o]=!0);if(!t)return}for(var r in d)Object.prototype.hasOwnProperty.call(d,r)&&(d[r]=e[l[r]]);if(K.filter.call(this,e)){var i=m();if(t)for(var a=0;a<t.length;a++)t[a].scope===i&&O(e,t[a],i);if(n in h)for(var c=0;c<h[n].length;c++)O(e,h[n][c],i)}}(e)}),i(f,"keyup",function(e){!function(e){var t=e.keyCode||e.which||e.charCode,n=p.indexOf(t);if(n>=0&&p.splice(n,1),93!==t&&224!==t||(t=91),t in d)for(var o in d[t]=!1,u)u[o]===t&&(K[o]=!1)}(e)}))}var E={setScope:g,getScope:m,deleteScope:function(e,t){var n=void 0,o=void 0;for(var r in e||(e=m()),h)if(Object.prototype.hasOwnProperty.call(h,r))for(n=h[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;m()===e&&g(t||"all")},getPressedKeyCodes:function(){return p.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=b(e)),-1!==p.indexOf(e)},filter:function(e){var t=e.target||e.srcElement,n=t.tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n||t.isContentEditable)},unbind:function(e,t){for(var n=c(e),o=void 0,r=[],i=void 0,f=0;f<n.length;f++){if((o=n[f].split("+")).length>1&&(r=a(u,o)),e="*"===(e=o[o.length-1])?"*":b(e),t||(t=m()),!h[e])return;for(var p=0;p<h[e].length;p++)(i=h[e][p]).scope===t&&s(i.mods,r)&&(h[e][p]={})}}};for(var x in E)Object.prototype.hasOwnProperty.call(E,x)&&(K[x]=E[x]);if("undefined"!=typeof window){var j=window.hotkeys;K.noConflict=function(e){return e&&window.hotkeys===K&&(window.hotkeys=j),K},window.hotkeys=K}var k=K;n.d(t,"default",function(){return P}),k.filter=function(e){var t=(e.target||e.srcElement).tagName;return k.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(t)?"input":"other"),!0};var P=function(e){function t(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,n));return o.onKeyDown=o.onKeyDown.bind(o),o.onKeyUp=o.onKeyUp.bind(o),o.handleKeyUpEvent=o.handleKeyUpEvent.bind(o),o.isKeyDown=!1,o.handle={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.componentDidMount=function(){k.unbind(this.props.keyName),k(this.props.keyName,this.onKeyDown),document.addEventListener("keyup",this.handleKeyUpEvent)},t.prototype.componentWillUnmount=function(){k.unbind(this.props.keyName),this.isKeyDown=!0,this.handle={},document.removeEventListener("keyup",this.handleKeyUpEvent)},t.prototype.onKeyUp=function(e,t){var n=this.props.onKeyUp;n(t.shortcut,e,t)},t.prototype.onKeyDown=function(e,t){var n=this.props.onKeyDown;this.isKeyDown||(this.isKeyDown=!0,this.handle=t,n(t.shortcut,e,t))},t.prototype.handleKeyUpEvent=function(e){this.isKeyDown&&(this.isKeyDown=!1,this.props.keyName.indexOf(this.handle.shortcut)<0||(this.onKeyUp(e,this.handle),this.handle={}))},t.prototype.render=function(){return this.props.children||null},t}(o.Component);P.defaultProps={onKeyUp:function(){},onKeyDown:function(){}}}]).default}); | ||
//# sourceMappingURL=react-hot-keys.min.js.map |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67937
5
866
1
Updatedhotkeys-js@^3.3.8