@pluginjs/keyboard
Advanced tools
Comparing version 0.7.16 to 0.7.17
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import t from"@pluginjs/simple-emitter";import{each as e}from"@pluginjs/utils";var r={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"},s={};for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(s[r[i]]=Number(i));var n={16:"shift",17:"ctrl",18:"alt",91:"command"};export default function(){return class{constructor(e){this.element=e||window.document,this.emitter=new t,this.initialize(),this.registerEvent()}initialize(){this.status={},e(n,(t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on("".concat(t,"up"),()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var r=t.keyCode,s="keydown"===t.type?"down":"up",i="";if(93!==r&&224!==r||(r=91),r in n&&!1===this.emitter.emit(r+s))return!1;e(this.status,(t,e)=>{e&&(i+=t)});var o=i+r+s;o in this.emitter.listeners&&!1===this.emitter.emit(o)&&(t.preventDefault(),t.stopPropagation())}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach(r=>{var i=r.modifiers,o=r.keyCode,a="";if(null!==i)for(var h=0;h<i.length;h++)a+=n[i[h]];t?this.emitter.on(a+o+e,s):this.emitter.off(a+o+e,s)}),this}parseKeys(t){var e=[];return t.map(t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t}),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=s[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return r[t]}getKeyCode(t){return s[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),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}.of(...arguments)} | ||
import t from"@pluginjs/simple-emitter";import{each as e}from"@pluginjs/utils";var r={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"},s={};for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(s[r[i]]=Number(i));var n={16:"shift",17:"ctrl",18:"alt",91:"command"};class o{constructor(e){this.element=e||window.document,this.emitter=new t,this.initialize(),this.registerEvent()}initialize(){this.status={},e(n,(t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on("".concat(t,"up"),()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var r=t.keyCode,s="keydown"===t.type?"down":"up",i="";if((93!==r&&224!==r||(r=91),r in n)&&!1===this.emitter.emit(r+s))return!1;e(this.status,(t,e)=>{e&&(i+=t)});var o=i+r+s;o in this.emitter.listeners&&(!1===this.emitter.emit(o)&&(t.preventDefault(),t.stopPropagation()))}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach(r=>{var i=r.modifiers,o=r.keyCode,a="";if(null!==i)for(var h=0;h<i.length;h++)a+=n[i[h]];t?this.emitter.on(a+o+e,s):this.emitter.off(a+o+e,s)}),this}parseKeys(t){var e=[];return t.map(t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t}),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=s[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return r[t]}getKeyCode(t){return s[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),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}export default function(){return o.of(...arguments)} |
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/keyboard v0.7.16 (https://pluginjs.com) | ||
* @pluginjs/keyboard v0.7.17 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@pluginjs/simple-emitter"),require("@pluginjs/utils")):"function"==typeof define&&define.amd?define(["@pluginjs/simple-emitter","@pluginjs/utils"],t):(e=e||self)["@pluginjs/keyboard"]=t(e["@pluginjs/simple-emitter"],e["@pluginjs/utils"])}(this,function(e,t){"use strict";function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t,n){return(i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var u=new(Function.bind.apply(e,i));return n&&r(u,n.prototype),u}).apply(null,arguments)}e=e&&e.hasOwnProperty("default")?e.default:e;var u={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"},o={};for(var s in u)Object.prototype.hasOwnProperty.call(u,s)&&(o[u[s]]=Number(s));var a={16:"shift",17:"ctrl",18:"alt",91:"command"},f=function(){function r(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.element=t||window.document,this.emitter=new e,this.initialize(),this.registerEvent()}var s,f,c;return s=r,c=[{key:"of",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i(this,t)}}],(f=[{key:"initialize",value:function(){var e=this;this.status={},t.each(a,function(t,n){e.status[n]=!1,e.emitter.on("".concat(t,"down"),function(){e.status[n]||(e.status[n]=!0)}),e.emitter.on("".concat(t,"up"),function(){e.status[n]&&(e.status[n]=!1)})})}},{key:"registerEvent",value:function(){var e=this,t=function(t){return e.handler(t)};this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}},{key:"handler",value:function(e){var n=e.keyCode,r="keydown"===e.type?"down":"up",i="";if((93!==n&&224!==n||(n=91),n in a)&&!1===this.emitter.emit(n+r))return!1;t.each(this.status,function(e,t){t&&(i+=e)});var u=i+n+r;u in this.emitter.listeners&&(!1===this.emitter.emit(u)&&(e.preventDefault(),e.stopPropagation()))}},{key:"on",value:function(e,t,n){return this.dispatch(!0,e,t,n)}},{key:"off",value:function(e,t,n){return this.dispatch(!1,e,t,n)}},{key:"dispatch",value:function(e,t,n,r){var i=this;return this.parseKeys(this.processKey(n)).forEach(function(n){var u=n.modifiers,o=n.keyCode,s="";if(null!==u)for(var f=0;f<u.length;f++)s+=a[u[f]];e?i.emitter.on(s+o+t,r):i.emitter.off(s+o+t,r)}),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map(function(e){var r={},i=null,u=(e=e.split("+")).length;return u>1&&(i=t.processModifiers(e),e=[e[u-1]]),e=t.getKeyCode(e[0]),r.modifiers=i,r.keyCode=e,n.push(r),e}),n}},{key:"processKey",value:function(e){var t=(e=e.toLowerCase().replace(/\s/g,"")).split(",");return""===t[t.length-1]&&(t[t.length-2]+=","),t}},{key:"processModifiers",value:function(e){for(var t=e.slice(0,e.length-1),n=0;n<t.length;n++)t[n]=o[t[n]];return t.sort(),t}},{key:"distribute",value:function(e,t,n){return null==n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return u[e]}},{key:"getKeyCode",value:function(e){return o[e]}},{key:"up",value:function(e,t){return this.distribute("up",e,t)}},{key:"down",value:function(e,t){return this.distribute("down",e,t)}}])&&n(s.prototype,f),c&&n(s,c),r}();return function(){return f.of.apply(f,arguments)}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@pluginjs/simple-emitter"),require("@pluginjs/utils")):"function"==typeof define&&define.amd?define(["@pluginjs/simple-emitter","@pluginjs/utils"],t):(e=e||self)["@pluginjs/keyboard"]=t(e["@pluginjs/simple-emitter"],e["@pluginjs/utils"])}(this,(function(e,t){"use strict";function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t,n){return(i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var u=new(Function.bind.apply(e,i));return n&&r(u,n.prototype),u}).apply(null,arguments)}e=e&&e.hasOwnProperty("default")?e.default:e;var u={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"},o={};for(var s in u)Object.prototype.hasOwnProperty.call(u,s)&&(o[u[s]]=Number(s));var a={16:"shift",17:"ctrl",18:"alt",91:"command"},f=function(){function r(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.element=t||window.document,this.emitter=new e,this.initialize(),this.registerEvent()}var s,f,c;return s=r,c=[{key:"of",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i(this,t)}}],(f=[{key:"initialize",value:function(){var e=this;this.status={},t.each(a,(function(t,n){e.status[n]=!1,e.emitter.on("".concat(t,"down"),(function(){e.status[n]||(e.status[n]=!0)})),e.emitter.on("".concat(t,"up"),(function(){e.status[n]&&(e.status[n]=!1)}))}))}},{key:"registerEvent",value:function(){var e=this,t=function(t){return e.handler(t)};this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}},{key:"handler",value:function(e){var n=e.keyCode,r="keydown"===e.type?"down":"up",i="";if(93!==n&&224!==n||(n=91),n in a&&!1===this.emitter.emit(n+r))return!1;t.each(this.status,(function(e,t){t&&(i+=e)}));var u=i+n+r;u in this.emitter.listeners&&!1===this.emitter.emit(u)&&(e.preventDefault(),e.stopPropagation())}},{key:"on",value:function(e,t,n){return this.dispatch(!0,e,t,n)}},{key:"off",value:function(e,t,n){return this.dispatch(!1,e,t,n)}},{key:"dispatch",value:function(e,t,n,r){var i=this;return this.parseKeys(this.processKey(n)).forEach((function(n){var u=n.modifiers,o=n.keyCode,s="";if(null!==u)for(var f=0;f<u.length;f++)s+=a[u[f]];e?i.emitter.on(s+o+t,r):i.emitter.off(s+o+t,r)})),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map((function(e){var r={},i=null,u=(e=e.split("+")).length;return u>1&&(i=t.processModifiers(e),e=[e[u-1]]),e=t.getKeyCode(e[0]),r.modifiers=i,r.keyCode=e,n.push(r),e})),n}},{key:"processKey",value:function(e){var t=(e=e.toLowerCase().replace(/\s/g,"")).split(",");return""===t[t.length-1]&&(t[t.length-2]+=","),t}},{key:"processModifiers",value:function(e){for(var t=e.slice(0,e.length-1),n=0;n<t.length;n++)t[n]=o[t[n]];return t.sort(),t}},{key:"distribute",value:function(e,t,n){return null==n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return u[e]}},{key:"getKeyCode",value:function(e){return o[e]}},{key:"up",value:function(e,t){return this.distribute("up",e,t)}},{key:"down",value:function(e,t){return this.distribute("down",e,t)}}])&&n(s.prototype,f),c&&n(s,c),r}();return function(){return f.of.apply(f,arguments)}})); |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.7.16", | ||
"version": "0.7.17", | ||
"category": "core", | ||
@@ -37,10 +37,10 @@ "main": "dist/keyboard.common.js", | ||
"dependencies": { | ||
"@pluginjs/dom": "^0.7.16", | ||
"@pluginjs/simple-emitter": "^0.7.13", | ||
"@pluginjs/utils": "^0.7.15" | ||
"@pluginjs/dom": "^0.7.17", | ||
"@pluginjs/simple-emitter": "^0.7.14", | ||
"@pluginjs/utils": "^0.7.16" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.5.5", | ||
"@pluginjs/browserslist-config": "^1.2.10", | ||
"@pluginjs/cli": "^0.7.13", | ||
"@babel/core": "^7.6.0", | ||
"@pluginjs/browserslist-config": "^1.2.11", | ||
"@pluginjs/cli": "^0.7.14", | ||
"babel-jest": "*", | ||
@@ -71,4 +71,4 @@ "jest": "*", | ||
], | ||
"gitHead": "2d2c629bf12f5a071c43b3074a6becdd4afadedc", | ||
"gitHead": "d1b3d9591a2fa49f13758c5ad8effcb021b096fc", | ||
"title": "Plugin" | ||
} |
42151
Updated@pluginjs/dom@^0.7.17
Updated@pluginjs/utils@^0.7.16