@taufik-nurrohman/text-editor.key 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -207,11 +207,8 @@
207
207
  map.pull(); // Reset all key(s)
208
208
  }
209
209
 
210
- function onInput(e) {
211
- var $ = this,
212
- key = e.data,
213
- map = getReference($);
214
- key && map.pull(key);
210
+ function onFocus(e) {
211
+ onBlur.call(this, e);
215
212
  }
216
213
 
217
214
  function onKeyDown(e) {
@@ -245,6 +242,20 @@
245
242
  map = getReference($);
246
243
  key && map.pull(key); // Reset current key.
247
244
  }
245
+ // Partial mobile support
246
+ function onPutDown(e) {
247
+ var $ = this,
248
+ key = e.data,
249
+ map = getReference($);
250
+ if (isString(key) && 1 === toCount(key)) {
251
+ // Having 1 printable character to put will discard the other(s)
252
+ map.toArray().forEach(function (k) {
253
+ return isString(k) && 1 === toCount(k) && map.pull(k);
254
+ });
255
+ // Put the current printable character to the list
256
+ map.push(key);
257
+ }
258
+ }
248
259
 
249
260
  function setReference(key, value) {
250
261
  return references.set(key, value);
@@ -271,9 +282,10 @@
271
282
  return $.keys[key] = of, $;
272
283
  });
273
284
  $.on('blur', onBlur);
274
- $.on('input', onInput);
285
+ $.on('focus', onFocus);
275
286
  $.on('key.down', onKeyDown);
276
287
  $.on('key.up', onKeyUp);
288
+ $.on('put.down', onPutDown);
277
289
  return setReference($, map), $;
278
290
  }
279
291
 
@@ -282,9 +294,10 @@
282
294
  map = getReference($);
283
295
  map.pull();
284
296
  $.off('blur', onBlur);
285
- $.off('input', onInput);
297
+ $.off('focus', onFocus);
286
298
  $.off('key.down', onKeyDown);
287
299
  $.off('key.up', onKeyUp);
300
+ $.off('put.down', onPutDown);
288
301
  return letReference($), $;
289
302
  }
290
303
  var index_js = {
package/index.min.js CHANGED
@@ -23,4 +23,4 @@
23
23
  * SOFTWARE.
24
24
  *
25
25
  */
26
- !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):((t="undefined"!=typeof globalThis?globalThis:t||self).TextEditor=t.TextEditor||{},t.TextEditor.Key=n())}(this,(function(){"use strict";var t=function(t){return Array.isArray(t)},n=function(t){return"function"==typeof t},e=function(t,n){return void 0===n&&(n=!0),!(!t||"object"!=typeof t)&&(!n||function(t,n){return!(!t||"object"!=typeof t)&&r(n)&&r(t.constructor)&&n===t.constructor}(t,Object))},r=function(t){return function(t){return void 0!==t}(t)&&!function(t){return null===t}(t)},o=function(t){return"string"==typeof t};function u(t){var n=this;return n.commands={},n.key=null,n.keys={},n.self=t||n,n.set=new Set,n}var i=u.prototype;i.command=function(t){var n=this;if(o(t))return t===n.toString();var e=n.keys[n.toString()];return!!r(e)&&e},i.fire=function(e,u){var i,f,s=this,a=s.self||s;return u=u||[],n(e)||o(e)&&(e=s.commands[e])?(i=e.apply(a,u),f=!0):t(e)&&(t(e[1])&&e[1].forEach((function(t,n){return r(t)&&(u[n]=t)})),(e=s.commands[e[0]])&&(i=e.apply(a,u),f=!0)),f?!r(i)||i:null},i.pull=function(t){var n=this;return n.key=null,r(t)?(n.set.delete(t),n):(n.set=new Set,n)},i.push=function(t){var n=this;return n.set.add(n.key=t,1),n},i.toArray=function(){return Array.from(this.set)},i.toString=function(){return this.toArray().join("-")},Object.defineProperty(u,"name",{value:"Key"});var f,s,a,c=function(t){return t.length},l=function(){for(var n=arguments.length,o=Array(n),u=0;u<n;u++)o[u]=arguments[u];for(var i,f=o.shift(),s=0,a=c(o);s<a;++s)for(var y in o[s])if(r(f[y]))if(t(f[y])&&t(o[s][y])){f[y]=[].concat(f[y]);for(var p=0,h=c(o[s][y]);p<h;++p)i=o[s][y][p],-1===f[y].indexOf(i)&&f[y].push(o[s][y][p])}else e(f[y])&&e(o[s][y])?f[y]=l({},f[y],o[s][y]):f[y]=o[s][y];else f[y]=o[s][y];return f},y=(f=function(t,n){t.pull(),n.altKey&&t.push("Alt"),n.ctrlKey&&t.push("Control"),n.metaKey&&t.push("Meta"),n.shiftKey&&t.push("Shift")},s=1e3,function(){var t=arguments,n=this;a&&clearTimeout(a),a=setTimeout((function(){return f.apply(n,t)}),s)}),p=new WeakMap;function h(t){return p.get(t)||null}function d(t){h(this).pull()}function m(t){var n=t.data,e=h(this);n&&e.pull(n)}function v(t){var n,e,r=t.key,o=h(this);o[t.altKey?"push":"pull"]("Alt"),o[t.ctrlKey?"push":"pull"]("Control"),o[t.metaKey?"push":"pull"]("Meta"),o[t.shiftKey?"push":"pull"]("Shift"),r&&o.push(r),(n=o.command())&&(!1===(e=o.fire(n))?(function(t){t&&t.preventDefault()}(t),function(t){t&&t.stopPropagation()}(t)):null===e&&console.warn("Unknown command:",n)),y(o,t)}function k(t){var n=t.key,e=h(this);n&&e.pull(n)}var K={attach:function(){var t,e,r=this,o=r.constructor._,i=new u(r);return r.commands=l(r.commands=i.commands,r.state.commands||{}),r.keys=l(r.keys=i.keys,r.state.keys||{}),!n(o.command)&&(o.command=function(t,n){return this.commands[t]=n,this}),!n(o.k)&&(o.k=function(t){var n=h(this).toArray();return!1===t?n:n.join(t||"-")}),!n(o.key)&&(o.key=function(t,n){return this.keys[t]=n,this}),r.on("blur",d),r.on("input",m),r.on("key.down",v),r.on("key.up",k),t=r,e=i,p.set(t,e),r},detach:function(){var t,n=this;return h(n).pull(),n.off("blur",d),n.off("input",m),n.off("key.down",v),n.off("key.up",k),t=n,p.delete(t),n},name:"TextEditor.Key"};return K}));
26
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):((t="undefined"!=typeof globalThis?globalThis:t||self).TextEditor=t.TextEditor||{},t.TextEditor.Key=n())}(this,(function(){"use strict";var t=function(t){return Array.isArray(t)},n=function(t){return"function"==typeof t},e=function(t,n){return void 0===n&&(n=!0),!(!t||"object"!=typeof t)&&(!n||function(t,n){return!(!t||"object"!=typeof t)&&r(n)&&r(t.constructor)&&n===t.constructor}(t,Object))},r=function(t){return function(t){return void 0!==t}(t)&&!function(t){return null===t}(t)},o=function(t){return"string"==typeof t};function u(t){var n=this;return n.commands={},n.key=null,n.keys={},n.self=t||n,n.set=new Set,n}var i=u.prototype;i.command=function(t){var n=this;if(o(t))return t===n.toString();var e=n.keys[n.toString()];return!!r(e)&&e},i.fire=function(e,u){var i,f,s=this,c=s.self||s;return u=u||[],n(e)||o(e)&&(e=s.commands[e])?(i=e.apply(c,u),f=!0):t(e)&&(t(e[1])&&e[1].forEach((function(t,n){return r(t)&&(u[n]=t)})),(e=s.commands[e[0]])&&(i=e.apply(c,u),f=!0)),f?!r(i)||i:null},i.pull=function(t){var n=this;return n.key=null,r(t)?(n.set.delete(t),n):(n.set=new Set,n)},i.push=function(t){var n=this;return n.set.add(n.key=t,1),n},i.toArray=function(){return Array.from(this.set)},i.toString=function(){return this.toArray().join("-")},Object.defineProperty(u,"name",{value:"Key"});var f,s,c,a=function(t){return t.length},l=function(){for(var n=arguments.length,o=Array(n),u=0;u<n;u++)o[u]=arguments[u];for(var i,f=o.shift(),s=0,c=a(o);s<c;++s)for(var y in o[s])if(r(f[y]))if(t(f[y])&&t(o[s][y])){f[y]=[].concat(f[y]);for(var p=0,h=a(o[s][y]);p<h;++p)i=o[s][y][p],-1===f[y].indexOf(i)&&f[y].push(o[s][y][p])}else e(f[y])&&e(o[s][y])?f[y]=l({},f[y],o[s][y]):f[y]=o[s][y];else f[y]=o[s][y];return f},y=(f=function(t,n){t.pull(),n.altKey&&t.push("Alt"),n.ctrlKey&&t.push("Control"),n.metaKey&&t.push("Meta"),n.shiftKey&&t.push("Shift")},s=1e3,function(){var t=arguments,n=this;c&&clearTimeout(c),c=setTimeout((function(){return f.apply(n,t)}),s)}),p=new WeakMap;function h(t){return p.get(t)||null}function d(t){h(this).pull()}function m(t){d.call(this,t)}function v(t){var n,e,r=t.key,o=h(this);o[t.altKey?"push":"pull"]("Alt"),o[t.ctrlKey?"push":"pull"]("Control"),o[t.metaKey?"push":"pull"]("Meta"),o[t.shiftKey?"push":"pull"]("Shift"),r&&o.push(r),(n=o.command())&&(!1===(e=o.fire(n))?(function(t){t&&t.preventDefault()}(t),function(t){t&&t.stopPropagation()}(t)):null===e&&console.warn("Unknown command:",n)),y(o,t)}function k(t){var n=t.key,e=h(this);n&&e.pull(n)}function K(t){var n=t.data,e=h(this);o(n)&&1===a(n)&&(e.toArray().forEach((function(t){return o(t)&&1===a(t)&&e.pull(t)})),e.push(n))}var g={attach:function(){var t,e,r=this,o=r.constructor._,i=new u(r);return r.commands=l(r.commands=i.commands,r.state.commands||{}),r.keys=l(r.keys=i.keys,r.state.keys||{}),!n(o.command)&&(o.command=function(t,n){return this.commands[t]=n,this}),!n(o.k)&&(o.k=function(t){var n=h(this).toArray();return!1===t?n:n.join(t||"-")}),!n(o.key)&&(o.key=function(t,n){return this.keys[t]=n,this}),r.on("blur",d),r.on("focus",m),r.on("key.down",v),r.on("key.up",k),r.on("put.down",K),t=r,e=i,p.set(t,e),r},detach:function(){var t,n=this;return h(n).pull(),n.off("blur",d),n.off("focus",m),n.off("key.down",v),n.off("key.up",k),n.off("put.down",K),t=n,p.delete(t),n},name:"TextEditor.Key"};return g}));
package/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import Key from '@taufik-nurrohman/key';
2
- import {debounce} from '@taufik-nurrohman/tick';
2
+
3
+ import {debounce, delay} from '@taufik-nurrohman/tick';
3
4
  import {fromStates} from '@taufik-nurrohman/from';
4
- import {isFunction, isSet} from '@taufik-nurrohman/is';
5
+ import {isFunction, isSet, isString} from '@taufik-nurrohman/is';
5
6
  import {offEventDefault, offEventPropagation} from '@taufik-nurrohman/event';
7
+ import {toCount} from '@taufik-nurrohman/to';
6
8
 
7
9
  const bounce = debounce((map, e) => {
8
10
  // Remove all key(s)
@@ -31,11 +33,8 @@ function onBlur(e) {
31
33
  map.pull(); // Reset all key(s)
32
34
  }
33
35
 
34
- function onInput(e) {
35
- let $ = this,
36
- key = e.data,
37
- map = getReference($);
38
- key && map.pull(key);
36
+ function onFocus(e) {
37
+ onBlur.call(this, e);
39
38
  }
40
39
 
41
40
  function onKeyDown(e) {
@@ -68,6 +67,19 @@ function onKeyUp(e) {
68
67
  key && map.pull(key); // Reset current key.
69
68
  }
70
69
 
70
+ // Partial mobile support
71
+ function onPutDown(e) {
72
+ let $ = this,
73
+ key = e.data,
74
+ map = getReference($);
75
+ if (isString(key) && 1 === toCount(key)) {
76
+ // Having 1 printable character to put will discard the other(s)
77
+ map.toArray().forEach(k => isString(k) && 1 === toCount(k) && map.pull(k));
78
+ // Put the current printable character to the list
79
+ map.push(key);
80
+ }
81
+ }
82
+
71
83
  function setReference(key, value) {
72
84
  return references.set(key, value);
73
85
  }
@@ -93,9 +105,10 @@ function attach() {
93
105
  return ($.keys[key] = of), $;
94
106
  });
95
107
  $.on('blur', onBlur);
96
- $.on('input', onInput);
108
+ $.on('focus', onFocus);
97
109
  $.on('key.down', onKeyDown);
98
110
  $.on('key.up', onKeyUp);
111
+ $.on('put.down', onPutDown);
99
112
  return setReference($, map), $;
100
113
  }
101
114
 
@@ -104,9 +117,10 @@ function detach() {
104
117
  map = getReference($);
105
118
  map.pull();
106
119
  $.off('blur', onBlur);
107
- $.off('input', onInput);
120
+ $.off('focus', onFocus);
108
121
  $.off('key.down', onKeyDown);
109
122
  $.off('key.up', onKeyUp);
123
+ $.off('put.down', onPutDown);
110
124
  return letReference($), $;
111
125
  }
112
126
 
package/package.json CHANGED
@@ -8,7 +8,8 @@
8
8
  "@taufik-nurrohman/is": "*",
9
9
  "@taufik-nurrohman/key": "*",
10
10
  "@taufik-nurrohman/text-editor": "*",
11
- "@taufik-nurrohman/tick": "*"
11
+ "@taufik-nurrohman/tick": "*",
12
+ "@taufik-nurrohman/to": "*"
12
13
  },
13
14
  "description": "Provides a feature to easily interact with the keyboard keys.",
14
15
  "devDependencies": {
@@ -46,5 +47,5 @@
46
47
  "scripts": {
47
48
  "pack": "pack --clean=false --from=.factory --js-format=umd --js-name=TextEditor.Key --js-top='%(js.license)' --mjs=true --to=."
48
49
  },
49
- "version": "1.0.10"
50
+ "version": "1.0.11"
50
51
  }