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

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.
package/index.js CHANGED
@@ -169,6 +169,9 @@
169
169
  var offEventDefault = function offEventDefault(e) {
170
170
  return e && e.preventDefault();
171
171
  };
172
+ var offEventPropagation = function offEventPropagation(e) {
173
+ return e && e.stopPropagation();
174
+ };
172
175
  var bounce = debounce(function (map) {
173
176
  return map.pull();
174
177
  }, 1000);
@@ -176,22 +179,27 @@
176
179
  var id = '_Key';
177
180
 
178
181
  function onBlur(e) {
179
- this[id].pull(); // Reset all key(s)
182
+ var $ = this;
183
+ $._event = e;
184
+ $[id].pull(); // Reset all key(s)
180
185
  }
181
186
 
182
187
  function onInput(e) {
183
- onBlur.call(this);
188
+ onBlur.call(this, e);
184
189
  }
185
190
 
186
191
  function onKeyDown(e) {
192
+ var $ = this;
187
193
  var command,
188
- map = this[id],
194
+ map = $[id],
189
195
  v;
190
196
  map.push(e.key); // Add current key to the queue
197
+ $._event = e;
191
198
  if (command = map.command()) {
192
199
  v = map.fire(command);
193
200
  if (false === v) {
194
201
  offEventDefault(e);
202
+ offEventPropagation(e);
195
203
  } else if (null === v) {
196
204
  console.warn('Unknown command: `' + command + '`');
197
205
  }
@@ -200,7 +208,9 @@
200
208
  }
201
209
 
202
210
  function onKeyUp(e) {
203
- this[id].pull(e.key); // Reset current key
211
+ var $ = this;
212
+ $._event = e;
213
+ $[id].pull(e.key); // Reset current key
204
214
  }
205
215
 
206
216
  function attach() {
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(),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}));
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,p=i(u[a][y]);d<p;++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=function(n){return n&&n.stopPropagation()},p=(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 h(n){this._event=n,this[m].pull()}function v(n){h.call(this,n)}function k(n){var t,e,r=this[m];r.push(n.key),this._event=n,(t=r.command())&&(!1===(e=r.fire(t))?(y(n),d(n)):null===e&&console.warn("Unknown command: `"+t+"`")),p(r)}function b(n){this._event=n,this[m].pull(n.key)}var g={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",h),n.on("input",v),n.on("key.down",k),n.on("key.up",b),n[m]=o,n},detach:function(){var n=this;return n[m].pull(),n.off("blur",h),n.off("input",v),n.off("key.down",k),n.off("key.up",b),delete n[m],n},name:"TextEditor.Key"};return g}));
package/index.mjs CHANGED
@@ -2,7 +2,7 @@ import Key from '@taufik-nurrohman/key';
2
2
  import {debounce} from '@taufik-nurrohman/tick';
3
3
  import {fromStates} from '@taufik-nurrohman/from';
4
4
  import {isFunction, isSet} from '@taufik-nurrohman/is';
5
- import {offEventDefault} from '@taufik-nurrohman/event';
5
+ import {offEventDefault, offEventPropagation} from '@taufik-nurrohman/event';
6
6
 
7
7
  const bounce = debounce(map => map.pull(), 1000);
8
8
  const name = 'TextEditor.Key';
@@ -10,20 +10,25 @@ const name = 'TextEditor.Key';
10
10
  const id = '_Key';
11
11
 
12
12
  function onBlur(e) {
13
- this[id].pull(); // Reset all key(s)
13
+ let $ = this;
14
+ $._event = e;
15
+ $[id].pull(); // Reset all key(s)
14
16
  }
15
17
 
16
18
  function onInput(e) {
17
- onBlur.call(this);
19
+ onBlur.call(this, e);
18
20
  }
19
21
 
20
22
  function onKeyDown(e) {
21
- let command, map = this[id], v;
23
+ let $ = this;
24
+ let command, map = $[id], v;
22
25
  map.push(e.key); // Add current key to the queue
26
+ $._event = e;
23
27
  if (command = map.command()) {
24
28
  v = map.fire(command);
25
29
  if (false === v) {
26
30
  offEventDefault(e);
31
+ offEventPropagation(e);
27
32
  } else if (null === v) {
28
33
  console.warn('Unknown command: `' + command + '`');
29
34
  }
@@ -32,7 +37,9 @@ function onKeyDown(e) {
32
37
  }
33
38
 
34
39
  function onKeyUp(e) {
35
- this[id].pull(e.key); // Reset current key
40
+ let $ = this;
41
+ $._event = e;
42
+ $[id].pull(e.key); // Reset current key
36
43
  }
37
44
 
38
45
  function attach() {
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.5"
49
+ "version": "1.0.7"
50
50
  }