@pluginjs/keyboard
Advanced tools
Comparing version 0.7.2 to 0.7.3
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -271,3 +271,7 @@ * Released under the GPL-3.0 License. | ||
static of(...args) { | ||
static of() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return new this(...args); | ||
@@ -278,4 +282,6 @@ } | ||
const keyboard = (...args) => Keyboard.of(...args); | ||
const keyboard = function keyboard() { | ||
return Keyboard.of(...arguments); | ||
}; | ||
module.exports = keyboard; |
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var SimpleEmitter=_interopDefault(require("@pluginjs/simple-emitter")),utils=require("@pluginjs/utils");const MAP_BY_CODE={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},MAP_BY_NAME={};for(const t in MAP_BY_CODE)Object.prototype.hasOwnProperty.call(MAP_BY_CODE,t)&&(MAP_BY_NAME[MAP_BY_CODE[t]]=Number(t));const MODIFIERS={16:"shift",17:"ctrl",18:"alt",91:"command"};class Keyboard{constructor(t){this.element=t||window.document,this.emitter=new SimpleEmitter,this.initialize(),this.registerEvent()}initialize(){this.status={},utils.each(MODIFIERS,(t,e)=>{this.status[e]=!1,this.emitter.on(`${t}down`,()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on(`${t}up`,()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){const t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){let e=t.keyCode;const s="keydown"===t.type?"down":"up";let i="";if(93!==e&&224!==e||(e=91),e in MODIFIERS){if(!1===this.emitter.emit(e+s))return!1}utils.each(this.status,(t,e)=>{e&&(i+=t)});const r=i+e+s;r in this.emitter.listeners&&!1===this.emitter.emit(r)&&(t.preventDefault(),t.stopPropagation())}on(t,e,s){return this.dispatch(!0,t,e,s)}off(t,e,s){return this.dispatch(!1,t,e,s)}dispatch(t,e,s,i){return this.parseKeys(this.processKey(s)).forEach(s=>{const r=s.modifiers,n=s.keyCode;let o="";if(null!==r)for(let t=0;t<r.length;t++)o+=MODIFIERS[r[t]];t?this.emitter.on(o+n+e,i):this.emitter.off(o+n+e,i)}),this}parseKeys(t){const e=[];return t.map(t=>{const s={};let i=null;const r=(t=t.split("+")).length;return r>1&&(i=this.processModifiers(t),t=[t[r-1]]),t=this.getKeyCode(t[0]),s.modifiers=i,s.keyCode=t,e.push(s),t}),e}processKey(t){const e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){const e=t.slice(0,t.length-1);for(let t=0;t<e.length;t++)e[t]=MAP_BY_NAME[e[t]];return e.sort(),e}distribute(t,e,s){return null==s?this.off(t,e,s):this.on(t,e,s)}getKeyName(t){return MAP_BY_CODE[t]}getKeyCode(t){return MAP_BY_NAME[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(...t){return new this(...t)}}const keyboard=(...t)=>Keyboard.of(...t);module.exports=keyboard; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var SimpleEmitter=_interopDefault(require("@pluginjs/simple-emitter")),utils=require("@pluginjs/utils");const MAP_BY_CODE={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},MAP_BY_NAME={};for(const t in MAP_BY_CODE)Object.prototype.hasOwnProperty.call(MAP_BY_CODE,t)&&(MAP_BY_NAME[MAP_BY_CODE[t]]=Number(t));const MODIFIERS={16:"shift",17:"ctrl",18:"alt",91:"command"};class Keyboard{constructor(t){this.element=t||window.document,this.emitter=new SimpleEmitter,this.initialize(),this.registerEvent()}initialize(){this.status={},utils.each(MODIFIERS,(t,e)=>{this.status[e]=!1,this.emitter.on(`${t}down`,()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on(`${t}up`,()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){const t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){let e=t.keyCode;const s="keydown"===t.type?"down":"up";let i="";if(93!==e&&224!==e||(e=91),e in MODIFIERS){if(!1===this.emitter.emit(e+s))return!1}utils.each(this.status,(t,e)=>{e&&(i+=t)});const r=i+e+s;r in this.emitter.listeners&&!1===this.emitter.emit(r)&&(t.preventDefault(),t.stopPropagation())}on(t,e,s){return this.dispatch(!0,t,e,s)}off(t,e,s){return this.dispatch(!1,t,e,s)}dispatch(t,e,s,i){return this.parseKeys(this.processKey(s)).forEach(s=>{const r=s.modifiers,n=s.keyCode;let o="";if(null!==r)for(let t=0;t<r.length;t++)o+=MODIFIERS[r[t]];t?this.emitter.on(o+n+e,i):this.emitter.off(o+n+e,i)}),this}parseKeys(t){const e=[];return t.map(t=>{const s={};let i=null;const r=(t=t.split("+")).length;return r>1&&(i=this.processModifiers(t),t=[t[r-1]]),t=this.getKeyCode(t[0]),s.modifiers=i,s.keyCode=t,e.push(s),t}),e}processKey(t){const e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){const e=t.slice(0,t.length-1);for(let t=0;t<e.length;t++)e[t]=MAP_BY_NAME[e[t]];return e.sort(),e}distribute(t,e,s){return null==s?this.off(t,e,s):this.on(t,e,s)}getKeyName(t){return MAP_BY_CODE[t]}getKeyCode(t){return MAP_BY_NAME[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return new this(...e)}}const keyboard=function(){return Keyboard.of(...arguments)};module.exports=keyboard; |
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -267,3 +267,7 @@ * Released under the GPL-3.0 License. | ||
static of(...args) { | ||
static of() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return new this(...args); | ||
@@ -274,4 +278,6 @@ } | ||
const keyboard = (...args) => Keyboard.of(...args); | ||
const keyboard = function keyboard() { | ||
return Keyboard.of(...arguments); | ||
}; | ||
export default keyboard; |
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import SimpleEmitter from"@pluginjs/simple-emitter";import{each}from"@pluginjs/utils";const MAP_BY_CODE={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},MAP_BY_NAME={};for(const t in MAP_BY_CODE)Object.prototype.hasOwnProperty.call(MAP_BY_CODE,t)&&(MAP_BY_NAME[MAP_BY_CODE[t]]=Number(t));const MODIFIERS={16:"shift",17:"ctrl",18:"alt",91:"command"};class Keyboard{constructor(t){this.element=t||window.document,this.emitter=new SimpleEmitter,this.initialize(),this.registerEvent()}initialize(){this.status={},each(MODIFIERS,(t,e)=>{this.status[e]=!1,this.emitter.on(`${t}down`,()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on(`${t}up`,()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){const t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){let e=t.keyCode;const s="keydown"===t.type?"down":"up";let i="";if(93!==e&&224!==e||(e=91),e in MODIFIERS){if(!1===this.emitter.emit(e+s))return!1}each(this.status,(t,e)=>{e&&(i+=t)});const r=i+e+s;r in this.emitter.listeners&&!1===this.emitter.emit(r)&&(t.preventDefault(),t.stopPropagation())}on(t,e,s){return this.dispatch(!0,t,e,s)}off(t,e,s){return this.dispatch(!1,t,e,s)}dispatch(t,e,s,i){return this.parseKeys(this.processKey(s)).forEach(s=>{const r=s.modifiers,n=s.keyCode;let o="";if(null!==r)for(let t=0;t<r.length;t++)o+=MODIFIERS[r[t]];t?this.emitter.on(o+n+e,i):this.emitter.off(o+n+e,i)}),this}parseKeys(t){const e=[];return t.map(t=>{const s={};let i=null;const r=(t=t.split("+")).length;return r>1&&(i=this.processModifiers(t),t=[t[r-1]]),t=this.getKeyCode(t[0]),s.modifiers=i,s.keyCode=t,e.push(s),t}),e}processKey(t){const e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){const e=t.slice(0,t.length-1);for(let t=0;t<e.length;t++)e[t]=MAP_BY_NAME[e[t]];return e.sort(),e}distribute(t,e,s){return null==s?this.off(t,e,s):this.on(t,e,s)}getKeyName(t){return MAP_BY_CODE[t]}getKeyCode(t){return MAP_BY_NAME[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(...t){return new this(...t)}}const keyboard=(...t)=>Keyboard.of(...t);export default keyboard; | ||
import SimpleEmitter from"@pluginjs/simple-emitter";import{each}from"@pluginjs/utils";const MAP_BY_CODE={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},MAP_BY_NAME={};for(const t in MAP_BY_CODE)Object.prototype.hasOwnProperty.call(MAP_BY_CODE,t)&&(MAP_BY_NAME[MAP_BY_CODE[t]]=Number(t));const MODIFIERS={16:"shift",17:"ctrl",18:"alt",91:"command"};class Keyboard{constructor(t){this.element=t||window.document,this.emitter=new SimpleEmitter,this.initialize(),this.registerEvent()}initialize(){this.status={},each(MODIFIERS,(t,e)=>{this.status[e]=!1,this.emitter.on(`${t}down`,()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on(`${t}up`,()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){const t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){let e=t.keyCode;const s="keydown"===t.type?"down":"up";let i="";if(93!==e&&224!==e||(e=91),e in MODIFIERS){if(!1===this.emitter.emit(e+s))return!1}each(this.status,(t,e)=>{e&&(i+=t)});const r=i+e+s;r in this.emitter.listeners&&!1===this.emitter.emit(r)&&(t.preventDefault(),t.stopPropagation())}on(t,e,s){return this.dispatch(!0,t,e,s)}off(t,e,s){return this.dispatch(!1,t,e,s)}dispatch(t,e,s,i){return this.parseKeys(this.processKey(s)).forEach(s=>{const r=s.modifiers,n=s.keyCode;let o="";if(null!==r)for(let t=0;t<r.length;t++)o+=MODIFIERS[r[t]];t?this.emitter.on(o+n+e,i):this.emitter.off(o+n+e,i)}),this}parseKeys(t){const e=[];return t.map(t=>{const s={};let i=null;const r=(t=t.split("+")).length;return r>1&&(i=this.processModifiers(t),t=[t[r-1]]),t=this.getKeyCode(t[0]),s.modifiers=i,s.keyCode=t,e.push(s),t}),e}processKey(t){const e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){const e=t.slice(0,t.length-1);for(let t=0;t<e.length;t++)e[t]=MAP_BY_NAME[e[t]];return e.sort(),e}distribute(t,e,s){return null==s?this.off(t,e,s):this.on(t,e,s)}getKeyName(t){return MAP_BY_CODE[t]}getKeyCode(t){return MAP_BY_NAME[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return new this(...e)}}const keyboard=function(){return Keyboard.of(...arguments)};export default keyboard; |
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/keyboard v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"category": "core", | ||
@@ -37,5 +37,5 @@ "main": "dist/keyboard.common.js", | ||
"dependencies": { | ||
"@pluginjs/dom": "^0.7.2", | ||
"@pluginjs/simple-emitter": "^0.7.2", | ||
"@pluginjs/utils": "^0.7.2" | ||
"@pluginjs/dom": "^0.7.3", | ||
"@pluginjs/simple-emitter": "^0.7.3", | ||
"@pluginjs/utils": "^0.7.3" | ||
}, | ||
@@ -45,3 +45,3 @@ "devDependencies": { | ||
"@pluginjs/browserslist-config": "^1.2.2", | ||
"@pluginjs/cli": "^0.7.2", | ||
"@pluginjs/cli": "^0.7.3", | ||
"babel-jest": "*", | ||
@@ -73,3 +73,3 @@ "jest": "*", | ||
"title": "Plugin", | ||
"gitHead": "f18c85114d702b75d2d67e57e43b51100f161f31" | ||
"gitHead": "304f657f71c8be62068380bd34fdc7f003082a24" | ||
} |
51757
10
1426
Updated@pluginjs/dom@^0.7.3
Updated@pluginjs/utils@^0.7.3