@taufik-nurrohman/text-editor.key 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +19 -14
- package/index.min.js +1 -1
- package/index.mjs +23 -14
- package/package.json +1 -1
package/index.js
CHANGED
@@ -164,7 +164,8 @@
|
|
164
164
|
var bounce = debounce(function (map) {
|
165
165
|
return map.pull();
|
166
166
|
}, 1000);
|
167
|
-
var
|
167
|
+
var name = 'TextEditor.Key';
|
168
|
+
var id = '_Key';
|
168
169
|
|
169
170
|
function onBlur(e) {
|
170
171
|
this[id].pull(); // Reset all key(s)
|
@@ -196,16 +197,20 @@
|
|
196
197
|
|
197
198
|
function attach() {
|
198
199
|
var $ = this;
|
200
|
+
var $$ = $.constructor.prototype;
|
199
201
|
var map = new Key($);
|
200
|
-
$.command = function (command, of) {
|
201
|
-
return $.commands[command] = of, $;
|
202
|
-
};
|
203
202
|
$.commands = fromStates($.commands = map.commands, $.state.commands || {});
|
204
|
-
$.
|
205
|
-
|
203
|
+
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
204
|
+
!isFunction($$.command) && ($$.command = function (command, of) {
|
205
|
+
var $ = this;
|
206
|
+
return $.commands[command] = of, $;
|
207
|
+
});
|
208
|
+
!isFunction($$.k) && ($$.k = function (join) {
|
209
|
+
var $ = this,
|
210
|
+
key = $[id] + "",
|
206
211
|
keys;
|
207
212
|
if (isSet(join) && '-' !== join) {
|
208
|
-
keys = "" !== key ? key.split(
|
213
|
+
keys = "" !== key ? key.split(/-(?!$)/) : [];
|
209
214
|
if (false !== join) {
|
210
215
|
return keys.join(join);
|
211
216
|
}
|
@@ -217,17 +222,16 @@
|
|
217
222
|
return keys;
|
218
223
|
}
|
219
224
|
return key;
|
220
|
-
};
|
221
|
-
|
225
|
+
});
|
226
|
+
!isFunction($$.key) && ($$.key = function (key, of) {
|
227
|
+
var $ = this;
|
222
228
|
return $.keys[key] = of, $;
|
223
|
-
};
|
224
|
-
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
229
|
+
});
|
225
230
|
$.on('blur', onBlur);
|
226
231
|
$.on('input', onInput);
|
227
232
|
$.on('key.down', onKeyDown);
|
228
233
|
$.on('key.up', onKeyUp);
|
229
|
-
$[id] = map
|
230
|
-
return $;
|
234
|
+
return $[id] = map, $;
|
231
235
|
}
|
232
236
|
|
233
237
|
function detach() {
|
@@ -242,7 +246,8 @@
|
|
242
246
|
}
|
243
247
|
var index_js = {
|
244
248
|
attach: attach,
|
245
|
-
detach: detach
|
249
|
+
detach: detach,
|
250
|
+
name: name
|
246
251
|
};
|
247
252
|
return index_js;
|
248
253
|
}));
|
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,
|
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"}}));
|
package/index.mjs
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
import Key from '@taufik-nurrohman/key';
|
2
2
|
import {debounce} from '@taufik-nurrohman/tick';
|
3
3
|
import {fromStates} from '@taufik-nurrohman/from';
|
4
|
-
import {isSet} from '@taufik-nurrohman/is';
|
4
|
+
import {isFunction, isSet} from '@taufik-nurrohman/is';
|
5
5
|
import {offEventDefault} from '@taufik-nurrohman/event';
|
6
6
|
|
7
7
|
const bounce = debounce(map => map.pull(), 1000);
|
8
|
-
const
|
8
|
+
const name = 'TextEditor.Key';
|
9
|
+
|
10
|
+
const id = '_Key';
|
9
11
|
|
10
12
|
function onBlur(e) {
|
11
13
|
this[id].pull(); // Reset all key(s)
|
@@ -34,15 +36,21 @@ function onKeyUp(e) {
|
|
34
36
|
}
|
35
37
|
|
36
38
|
function attach() {
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
const $ = this;
|
40
|
+
const $$ = $.constructor.prototype;
|
41
|
+
const map = new Key($);
|
40
42
|
$.commands = fromStates($.commands = map.commands, $.state.commands || {});
|
41
|
-
$.
|
42
|
-
|
43
|
+
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
44
|
+
!isFunction($$.command) && ($$.command = function (command, of) {
|
45
|
+
let $ = this;
|
46
|
+
return ($.commands[command] = of), $;
|
47
|
+
});
|
48
|
+
!isFunction($$.k) && ($$.k = function (join) {
|
49
|
+
let $ = this,
|
50
|
+
key = $[id] + "",
|
43
51
|
keys;
|
44
52
|
if (isSet(join) && '-' !== join) {
|
45
|
-
keys = "" !== key ? key.split(
|
53
|
+
keys = "" !== key ? key.split(/-(?!$)/) : [];
|
46
54
|
if (false !== join) {
|
47
55
|
return keys.join(join);
|
48
56
|
}
|
@@ -54,15 +62,16 @@ function attach() {
|
|
54
62
|
return keys;
|
55
63
|
}
|
56
64
|
return key;
|
57
|
-
};
|
58
|
-
|
59
|
-
|
65
|
+
});
|
66
|
+
!isFunction($$.key) && ($$.key = function (key, of) {
|
67
|
+
let $ = this;
|
68
|
+
return ($.keys[key] = of), $;
|
69
|
+
});
|
60
70
|
$.on('blur', onBlur);
|
61
71
|
$.on('input', onInput);
|
62
72
|
$.on('key.down', onKeyDown);
|
63
73
|
$.on('key.up', onKeyUp);
|
64
|
-
$[id] = map
|
65
|
-
return $;
|
74
|
+
return ($[id] = map), $;
|
66
75
|
}
|
67
76
|
|
68
77
|
function detach() {
|
@@ -76,4 +85,4 @@ function detach() {
|
|
76
85
|
return $;
|
77
86
|
}
|
78
87
|
|
79
|
-
export default {attach, detach};
|
88
|
+
export default {attach, detach, name};
|
package/package.json
CHANGED