chore: Fix ESLint errors.

pull/165/head
jaywcjlove 5 years ago
parent d3c0d4830b
commit bcb3f691f1

@ -10,6 +10,7 @@
"jasmine": true "jasmine": true
}, },
"rules": { "rules": {
"object-curly-newline": 0,
"linebreak-style": 0, "linebreak-style": 0,
"arrow-body-style": 0, "arrow-body-style": 0,
"max-len": 0, "max-len": 0,

@ -7,10 +7,9 @@ let _scope = 'all'; // 默认热键范围
const elementHasBindEvent = []; // 已绑定事件的节点记录 const elementHasBindEvent = []; // 已绑定事件的节点记录
// 返回键码 // 返回键码
const code = x => const code = (x) => _keyMap[x.toLowerCase()]
_keyMap[x.toLowerCase()] || || _modifier[x.toLowerCase()]
_modifier[x.toLowerCase()] || || x.toUpperCase().charCodeAt(0);
x.toUpperCase().charCodeAt(0);
// 设置获取当前范围(默认为'所有' // 设置获取当前范围(默认为'所有'
function setScope(scope) { function setScope(scope) {
@ -33,8 +32,8 @@ function filter(event) {
let flag = true; let flag = true;
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select> // ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select>
if ( if (
target.isContentEditable || target.isContentEditable
((tagName === 'INPUT' || tagName === 'TEXTAREA') && !target.readOnly) || ((tagName === 'INPUT' || tagName === 'TEXTAREA') && !target.readOnly)
) { ) {
flag = false; flag = false;
} }
@ -98,7 +97,7 @@ function clearModifier(event) {
function unbind(keysInfo, ...args) { function unbind(keysInfo, ...args) {
// unbind(), unbind all keys // unbind(), unbind all keys
if (!keysInfo) { if (!keysInfo) {
Object.keys(_handlers).forEach(key => delete _handlers[key]); Object.keys(_handlers).forEach((key) => delete _handlers[key]);
} else if (Array.isArray(keysInfo)) { } else if (Array.isArray(keysInfo)) {
// support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}]) // support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}])
keysInfo.forEach((info) => { keysInfo.forEach((info) => {
@ -142,9 +141,9 @@ const eachUnbind = ({
// 通过函数判断,是否解除绑定,函数相等直接返回 // 通过函数判断,是否解除绑定,函数相等直接返回
const isMatchingMethod = method ? record.method === method : true; const isMatchingMethod = method ? record.method === method : true;
if ( if (
isMatchingMethod && isMatchingMethod
record.scope === scope && && record.scope === scope
compareArray(record.mods, mods) && compareArray(record.mods, mods)
) { ) {
return {}; return {};
} }
@ -165,8 +164,8 @@ function eventHandler(event, handler, scope) {
for (const y in _mods) { for (const y in _mods) {
if (Object.prototype.hasOwnProperty.call(_mods, y)) { if (Object.prototype.hasOwnProperty.call(_mods, y)) {
if ( if (
(!_mods[y] && handler.mods.indexOf(+y) > -1) || (!_mods[y] && handler.mods.indexOf(+y) > -1)
(_mods[y] && handler.mods.indexOf(+y) === -1) || (_mods[y] && handler.mods.indexOf(+y) === -1)
) { ) {
modifiersMatch = false; modifiersMatch = false;
} }
@ -175,13 +174,13 @@ function eventHandler(event, handler, scope) {
// 调用处理程序,如果是修饰键不做处理 // 调用处理程序,如果是修饰键不做处理
if ( if (
(handler.mods.length === 0 && (handler.mods.length === 0
!_mods[16] && && !_mods[16]
!_mods[18] && && !_mods[18]
!_mods[17] && && !_mods[17]
!_mods[91]) || && !_mods[91])
modifiersMatch || || modifiersMatch
handler.shortcut === '*' || handler.shortcut === '*'
) { ) {
if (handler.method(event, handler) === false) { if (handler.method(event, handler) === false) {
if (event.preventDefault) event.preventDefault(); if (event.preventDefault) event.preventDefault();
@ -270,9 +269,9 @@ function dispatch(event) {
if (asterisk) { if (asterisk) {
for (let i = 0; i < asterisk.length; i++) { for (let i = 0; i < asterisk.length; i++) {
if ( if (
asterisk[i].scope === scope && asterisk[i].scope === scope
((event.type === 'keydown' && asterisk[i].keydown) || && ((event.type === 'keydown' && asterisk[i].keydown)
(event.type === 'keyup' && asterisk[i].keyup)) || (event.type === 'keyup' && asterisk[i].keyup))
) { ) {
eventHandler(event, asterisk[i], scope); eventHandler(event, asterisk[i], scope);
} }
@ -283,8 +282,8 @@ function dispatch(event) {
for (let i = 0; i < _handlers[key].length; i++) { for (let i = 0; i < _handlers[key].length; i++) {
if ( if (
(event.type === 'keydown' && _handlers[key][i].keydown) || (event.type === 'keydown' && _handlers[key][i].keydown)
(event.type === 'keyup' && _handlers[key][i].keyup) || (event.type === 'keyup' && _handlers[key][i].keyup)
) { ) {
if (_handlers[key][i].key) { if (_handlers[key][i].key) {
const record = _handlers[key][i]; const record = _handlers[key][i];

@ -18,6 +18,7 @@ export default class App extends Component {
}; };
this.onKeyUpEvent = this.onKeyUpEvent.bind(this); this.onKeyUpEvent = this.onKeyUpEvent.bind(this);
} }
componentDidMount() { componentDidMount() {
document.addEventListener('keyup', this.onKeyUpEvent); document.addEventListener('keyup', this.onKeyUpEvent);
function pkeys(keys, key) { function pkeys(keys, key) {
@ -58,40 +59,49 @@ export default class App extends Component {
}); });
return false; return false;
} }
componentWillUnmount() { componentWillUnmount() {
document.removeEventListener('keyup', this.onKeyUpEvent); document.removeEventListener('keyup', this.onKeyUpEvent);
} }
onKeyUpEvent() { onKeyUpEvent() {
this.setState({ keyCode: [], keyStr: [] }); this.setState({ keyCode: [], keyStr: [] });
} }
onKeyBoardMouseDown(item) { onKeyBoardMouseDown(item) {
if (item.keycode > -1) { if (item.keycode > -1) {
this.setState({ keyStr: [item.keycode] }); this.setState({ keyStr: [item.keycode] });
} }
} }
onKeyBoardMouseUp() { onKeyBoardMouseUp() {
this.setState({ keyStr: [] }); this.setState({ keyStr: [] });
} }
openVersionWebsite(e) { openVersionWebsite(e) {
if (e.target && e.target.value) { if (e.target && e.target.value) {
window.location.href = e.target.value; window.location.href = e.target.value;
} }
} }
render() { render() {
const { keyStr } = this.state; const { keyStr, keyCode } = this.state;
let DocumentStrSource = DocumentStr; let DocumentStrSource = DocumentStr;
if (DocumentStrSource) DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, ''); if (DocumentStrSource) DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '');
return ( return (
<div> <div>
<select className={styles.version} onChange={this.openVersionWebsite.bind(this)}> <select className={styles.version} onChange={this.openVersionWebsite.bind(this)}>
<option value="https://jaywcjlove.github.io/hotkeys">v{pkg.version}</option> <option value="https://jaywcjlove.github.io/hotkeys">
v
{pkg.version}
</option>
<option value="https://unpkg.com/hotkeys-js@3.4.3/doc/index.html">v3.4.3</option> <option value="https://unpkg.com/hotkeys-js@3.4.3/doc/index.html">v3.4.3</option>
<option value="https://unpkg.com/hotkeys-js@3.4.2/doc/index.html">v3.4.2</option> <option value="https://unpkg.com/hotkeys-js@3.4.2/doc/index.html">v3.4.2</option>
<option value="https://unpkg.com/hotkeys-js@2.0.10/doc/index.html">v2.0.10</option> <option value="https://unpkg.com/hotkeys-js@2.0.10/doc/index.html">v2.0.10</option>
</select> </select>
{keyStr.length > -1 && ( {keyStr.length > -1 && (
<div className={styles.keyCodeInfo}> <div className={styles.keyCodeInfo}>
{keyStr.map(item => <span key={`${item}`}>{item}</span>)} {keyStr.map((item) => <span key={`${item}`}>{item}</span>)}
</div> </div>
)} )}
<GithubCorner href="https://github.com/jaywcjlove/hotkeys" target="__blank" /> <GithubCorner href="https://github.com/jaywcjlove/hotkeys" target="__blank" />
@ -99,16 +109,16 @@ export default class App extends Component {
<div className={styles.title}>HotKeys.js</div> <div className={styles.title}>HotKeys.js</div>
<div className={styles.github}> <div className={styles.github}>
<a href="https://www.npmjs.com/package/hotkeys-js"> <a href="https://www.npmjs.com/package/hotkeys-js">
<button>On NPM</button> <button type="button">On NPM</button>
</a> </a>
<a href="https://github.com/jaywcjlove/hotkeys/"> <a href="https://github.com/jaywcjlove/hotkeys/">
<button>Fork on Github</button> <button type="button">Fork on Github</button>
</a> </a>
<a href="https://github.com/jaywcjlove/hotkeys/"> <a href="https://github.com/jaywcjlove/hotkeys/">
<button>Doc on Github</button> <button type="button">Doc on Github</button>
</a> </a>
<a href="https://jaywcjlove.gitee.io/hotkeys/"> <a href="https://jaywcjlove.gitee.io/hotkeys/">
<button>Doc on Gitee</button> <button type="button">Doc on Gitee</button>
</a> </a>
</div> </div>
<div className={styles.info}>A robust Javascript library for capturing keyboard input and key combinations entered. It has no dependencies. Try to press your keyboard, The following button will highlight.</div> <div className={styles.info}>A robust Javascript library for capturing keyboard input and key combinations entered. It has no dependencies. Try to press your keyboard, The following button will highlight.</div>
@ -116,7 +126,7 @@ export default class App extends Component {
<KeyBoard <KeyBoard
onMouseDown={this.onKeyBoardMouseDown.bind(this)} onMouseDown={this.onKeyBoardMouseDown.bind(this)}
onMouseUp={this.onKeyBoardMouseUp.bind(this)} onMouseUp={this.onKeyBoardMouseUp.bind(this)}
keyCode={this.state.keyCode} keyCode={keyCode}
/> />
<Markdown source={DocumentStrSource} /> <Markdown source={DocumentStrSource} />
<GithubShields <GithubShields

@ -4,9 +4,15 @@ import style from './Footer.less';
export default function Footer({ name, href, year }) { export default function Footer({ name, href, year }) {
return ( return (
<div className={style.footer}> <div className={style.footer}>
<div>Licensed under MIT. (Yes it&acute;s free and <a href="https://github.com/jaywcjlove/hotkeys">open-sourced</a>)</div>
<div> <div>
© <a target="_blank" rel="noopener noreferrer" href={href}>{name}</a> {year} Licensed under MIT. (Yes it&acute;s free and
<a href="https://github.com/jaywcjlove/hotkeys">open-sourced</a>
)
</div>
<div>
©
<a target="_blank" rel="noopener noreferrer" href={href}>{name}</a>
{year}
</div> </div>
</div> </div>
); );

@ -18,6 +18,7 @@ export default class Markdown extends Component {
} }
} }
} }
render() { render() {
const { source } = this.props; const { source } = this.props;
return ( return (

Loading…
Cancel
Save