@taufik-nurrohman/text-editor.key 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +49 -41
  2. package/index.min.js +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -101,52 +101,60 @@
101
101
 
102
102
  function Key(self) {
103
103
  var $ = this;
104
- var queue = {};
105
- $.command = function (v) {
106
- if (isString(v)) {
107
- return v === $.toString();
108
- }
109
- var command = $.keys[$.toString()];
110
- return isSet(command) ? command : false;
111
- };
112
104
  $.commands = {};
113
- $.fire = function (command) {
114
- var self = $.self || $,
115
- value,
116
- exist;
117
- if (isFunction(command)) {
118
- value = command.call(self);
119
- exist = true;
120
- } else if (isString(command) && (command = $.commands[command])) {
121
- value = command.call(self);
122
- exist = true;
123
- } else if (isArray(command)) {
124
- var data = command[1] || [];
125
- if (command = $.commands[command[0]]) {
126
- value = command.apply(self, data);
127
- exist = true;
128
- }
129
- }
130
- return exist ? isSet(value) ? value : true : null;
131
- };
132
105
  $.key = null;
133
106
  $.keys = {};
134
- $.pull = function (key) {
135
- $.key = null;
136
- if (!isSet(key)) {
137
- return queue = {}, $;
138
- }
139
- return delete queue[key], $;
140
- };
141
- $.push = function (key) {
142
- return queue[$.key = key] = 1, $;
143
- };
144
- $.self = self;
145
- $.toString = function () {
146
- return toObjectKeys(queue).join('-');
147
- };
107
+ $.queue = {};
108
+ $.self = self || $;
148
109
  return $;
149
110
  }
111
+ var $$ = Key.prototype;
112
+ $$.command = function (v) {
113
+ var $ = this;
114
+ if (isString(v)) {
115
+ return v === $.toString();
116
+ }
117
+ var command = $.keys[$.toString()];
118
+ return isSet(command) ? command : false;
119
+ };
120
+ $$.fire = function (command) {
121
+ var $ = this;
122
+ var self = $.self || $,
123
+ value,
124
+ exist;
125
+ if (isFunction(command)) {
126
+ value = command.call(self);
127
+ exist = true;
128
+ } else if (isString(command) && (command = $.commands[command])) {
129
+ value = command.call(self);
130
+ exist = true;
131
+ } else if (isArray(command)) {
132
+ var data = command[1] || [];
133
+ if (command = $.commands[command[0]]) {
134
+ value = command.apply(self, data);
135
+ exist = true;
136
+ }
137
+ }
138
+ return exist ? isSet(value) ? value : true : null;
139
+ };
140
+ $$.pull = function (key) {
141
+ var $ = this;
142
+ $.key = null;
143
+ if (!isSet(key)) {
144
+ return $.queue = {}, $;
145
+ }
146
+ return delete $.queue[key], $;
147
+ };
148
+ $$.push = function (key) {
149
+ var $ = this;
150
+ return $.queue[$.key = key] = 1, $;
151
+ };
152
+ $$.toString = function () {
153
+ return toObjectKeys(this.queue).join('-');
154
+ };
155
+ Object.defineProperty(Key, 'name', {
156
+ value: 'Key'
157
+ });
150
158
  var debounce = function debounce(then, time) {
151
159
  var timer;
152
160
  return function () {
package/index.min.js CHANGED
@@ -23,4 +23,4 @@
23
23
  * SOFTWARE.
24
24
  *
25
25
  */
26
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((n="undefined"!=typeof globalThis?globalThis:n||self).TextEditor=n.TextEditor||{},n.TextEditor.Key=t())}(this,(function(){"use strict";var n=function(n){return Array.isArray(n)},t=function(n){return"function"==typeof n},e=function(n,t){return void 0===t&&(t=!0),"object"==typeof n&&(!t||function(n,t){return n&&r(t)&&n instanceof t}(n,Object))},r=function(n){return function(n){return void 0!==n}(n)&&!function(n){return null===n}(n)},o=function(n){return"string"==typeof n},u=function t(){for(var o=arguments.length,u=Array(o),f=0;f<o;f++)u[f]=arguments[f];for(var c,s=u.shift(),l=0,a=i(u);l<a;++l)for(var d in u[l])if(r(s[d]))if(n(s[d])&&n(u[l][d])){s[d]=[].concat(s[d]);for(var y=0,m=i(u[l][d]);y<m;++y)c=u[l][d][y],-1===s[d].indexOf(c)&&s[d].push(u[l][d][y])}else e(s[d])&&e(u[l][d])?s[d]=t({},s[d],u[l][d]):s[d]=u[l][d];else s[d]=u[l][d];return s},i=function(n){return n.length},f=function(n){return Object.keys(n)};function c(e){var u=this,i={};return u.command=function(n){if(o(n))return n===u.toString();var t=u.keys[u.toString()];return!!r(t)&&t},u.commands={},u.fire=function(e){var i,f,c=u.self||u;if(t(e))i=e.call(c),f=!0;else if(o(e)&&(e=u.commands[e]))i=e.call(c),f=!0;else if(n(e)){var s=e[1]||[];(e=u.commands[e[0]])&&(i=e.apply(c,s),f=!0)}return f?!r(i)||i:null},u.key=null,u.keys={},u.pull=function(n){return u.key=null,r(n)?(delete i[n],u):(i={},u)},u.push=function(n){return i[u.key=n]=1,u},u.self=e,u.toString=function(){return f(i).join("-")},u}var s,l,a,d=function(n){return n&&n.preventDefault()},y=(s=function(n){return n.pull()},l=1e3,function(){var n=arguments,t=this;a&&clearTimeout(a),a=setTimeout((function(){return s.apply(t,n)}),l)}),m="_Key";function p(n){this[m].pull()}function h(n){p.call(this)}function k(n){var t,e,r=this[m];r.push(n.key),(t=r.command())&&(!1===(e=r.fire(t))?d(n):null===e&&console.warn("Unknown command: `"+t+"`")),y(r)}function v(n){this[m].pull(n.key)}return{attach:function(){var n=this,e=n.constructor.prototype,o=new c(n);return n.commands=u(n.commands=o.commands,n.state.commands||{}),n.keys=u(n.keys=o.keys,n.state.keys||{}),!t(e.command)&&(e.command=function(n,t){return this.commands[n]=t,this}),!t(e.k)&&(e.k=function(n){var t,e=this[m]+"";return r(n)&&"-"!==n&&(t=""!==e?e.split(/-(?!$)/):[],!1!==n)?t.join(n):!1===n?"-"===e?[e]:t:e}),!t(e.key)&&(e.key=function(n,t){return this.keys[n]=t,this}),n.on("blur",p),n.on("input",h),n.on("key.down",k),n.on("key.up",v),n[m]=o,n},detach:function(){var n=this;return n[m].pull(),n.off("blur",p),n.off("input",h),n.off("key.down",k),n.off("key.up",v),delete n[m],n},name:"TextEditor.Key"}}));
26
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((n="undefined"!=typeof globalThis?globalThis:n||self).TextEditor=n.TextEditor||{},n.TextEditor.Key=t())}(this,(function(){"use strict";var n=function(n){return Array.isArray(n)},t=function(n){return"function"==typeof n},e=function(n,t){return void 0===t&&(t=!0),"object"==typeof n&&(!t||function(n,t){return n&&r(t)&&n instanceof t}(n,Object))},r=function(n){return function(n){return void 0!==n}(n)&&!function(n){return null===n}(n)},o=function(n){return"string"==typeof n},u=function t(){for(var o=arguments.length,u=Array(o),f=0;f<o;f++)u[f]=arguments[f];for(var c,s=u.shift(),a=0,l=i(u);a<l;++a)for(var y in u[a])if(r(s[y]))if(n(s[y])&&n(u[a][y])){s[y]=[].concat(s[y]);for(var d=0,m=i(u[a][y]);d<m;++d)c=u[a][y][d],-1===s[y].indexOf(c)&&s[y].push(u[a][y][d])}else e(s[y])&&e(u[a][y])?s[y]=t({},s[y],u[a][y]):s[y]=u[a][y];else s[y]=u[a][y];return s},i=function(n){return n.length};function f(n){var t=this;return t.commands={},t.key=null,t.keys={},t.queue={},t.self=n||t,t}var c=f.prototype;c.command=function(n){var t=this;if(o(n))return n===t.toString();var e=t.keys[t.toString()];return!!r(e)&&e},c.fire=function(e){var u,i,f=this,c=f.self||f;if(t(e))u=e.call(c),i=!0;else if(o(e)&&(e=f.commands[e]))u=e.call(c),i=!0;else if(n(e)){var s=e[1]||[];(e=f.commands[e[0]])&&(u=e.apply(c,s),i=!0)}return i?!r(u)||u:null},c.pull=function(n){var t=this;return t.key=null,r(n)?(delete t.queue[n],t):(t.queue={},t)},c.push=function(n){var t=this;return t.queue[t.key=n]=1,t},c.toString=function(){return(n=this.queue,Object.keys(n)).join("-");var n},Object.defineProperty(f,"name",{value:"Key"});var s,a,l,y=function(n){return n&&n.preventDefault()},d=(s=function(n){return n.pull()},a=1e3,function(){var n=arguments,t=this;l&&clearTimeout(l),l=setTimeout((function(){return s.apply(t,n)}),a)}),m="_Key";function p(n){this[m].pull()}function h(n){p.call(this)}function v(n){var t,e,r=this[m];r.push(n.key),(t=r.command())&&(!1===(e=r.fire(t))?y(n):null===e&&console.warn("Unknown command: `"+t+"`")),d(r)}function k(n){this[m].pull(n.key)}var b={attach:function(){var n=this,e=n.constructor.prototype,o=new f(n);return n.commands=u(n.commands=o.commands,n.state.commands||{}),n.keys=u(n.keys=o.keys,n.state.keys||{}),!t(e.command)&&(e.command=function(n,t){return this.commands[n]=t,this}),!t(e.k)&&(e.k=function(n){var t,e=this[m]+"";return r(n)&&"-"!==n&&(t=""!==e?e.split(/-(?!$)/):[],!1!==n)?t.join(n):!1===n?"-"===e?[e]:t:e}),!t(e.key)&&(e.key=function(n,t){return this.keys[n]=t,this}),n.on("blur",p),n.on("input",h),n.on("key.down",v),n.on("key.up",k),n[m]=o,n},detach:function(){var n=this;return n[m].pull(),n.off("blur",p),n.off("input",h),n.off("key.down",v),n.off("key.up",k),delete n[m],n},name:"TextEditor.Key"};return b}));
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "scripts": {
47
47
  "pack": "pack --clean=false --from=.factory --js-format=umd --js-name=TextEditor.Key --js-top='%(js.license)' --mjs=true --to=."
48
48
  },
49
- "version": "1.0.4"
49
+ "version": "1.0.5"
50
50
  }