@taufik-nurrohman/text-editor.key 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +48 -40
- package/index.min.js +1 -1
- package/index.mjs +54 -32
- package/package.json +2 -1
package/index.js
CHANGED
@@ -158,33 +158,26 @@
|
|
158
158
|
}, time);
|
159
159
|
};
|
160
160
|
};
|
161
|
-
var offEvent = function offEvent(name, node, then) {
|
162
|
-
node.removeEventListener(name, then);
|
163
|
-
};
|
164
161
|
var offEventDefault = function offEventDefault(e) {
|
165
162
|
return e && e.preventDefault();
|
166
163
|
};
|
167
|
-
var onEvent = function onEvent(name, node, then, options) {
|
168
|
-
if (options === void 0) {
|
169
|
-
options = false;
|
170
|
-
}
|
171
|
-
node.addEventListener(name, then, options);
|
172
|
-
};
|
173
164
|
var bounce = debounce(function (map) {
|
174
165
|
return map.pull();
|
175
166
|
}, 1000);
|
167
|
+
var name = 'TextEditor.Key';
|
168
|
+
var id = '_Key';
|
176
169
|
|
177
170
|
function onBlur(e) {
|
178
|
-
this.
|
171
|
+
this[id].pull(); // Reset all key(s)
|
179
172
|
}
|
180
173
|
|
181
174
|
function onInput(e) {
|
182
|
-
|
175
|
+
onBlur.call(this);
|
183
176
|
}
|
184
177
|
|
185
178
|
function onKeyDown(e) {
|
186
179
|
var command,
|
187
|
-
map = this
|
180
|
+
map = this[id],
|
188
181
|
v;
|
189
182
|
map.push(e.key); // Add current key to the queue
|
190
183
|
if (command = map.command()) {
|
@@ -199,47 +192,62 @@
|
|
199
192
|
}
|
200
193
|
|
201
194
|
function onKeyUp(e) {
|
202
|
-
this.
|
195
|
+
this[id].pull(e.key); // Reset current key
|
203
196
|
}
|
204
197
|
|
205
|
-
function attach(
|
198
|
+
function attach() {
|
206
199
|
var $ = this;
|
200
|
+
var $$ = $.constructor.prototype;
|
207
201
|
var map = new Key($);
|
208
|
-
$.
|
202
|
+
$.commands = fromStates($.commands = map.commands, $.state.commands || {});
|
203
|
+
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
204
|
+
!isFunction($$.command) && ($$.command = function (command, of) {
|
205
|
+
var $ = this;
|
209
206
|
return $.commands[command] = of, $;
|
210
|
-
};
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
207
|
+
});
|
208
|
+
!isFunction($$.k) && ($$.k = function (join) {
|
209
|
+
var $ = this,
|
210
|
+
key = $[id] + "",
|
211
|
+
keys;
|
212
|
+
if (isSet(join) && '-' !== join) {
|
213
|
+
keys = "" !== key ? key.split(/-(?!$)/) : [];
|
214
|
+
if (false !== join) {
|
215
|
+
return keys.join(join);
|
216
|
+
}
|
216
217
|
}
|
217
|
-
|
218
|
-
|
219
|
-
|
218
|
+
if (false === join) {
|
219
|
+
if ('-' === key) {
|
220
|
+
return [key];
|
221
|
+
}
|
222
|
+
return keys;
|
223
|
+
}
|
224
|
+
return key;
|
225
|
+
});
|
226
|
+
!isFunction($$.key) && ($$.key = function (key, of) {
|
227
|
+
var $ = this;
|
220
228
|
return $.keys[key] = of, $;
|
221
|
-
};
|
222
|
-
$.
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
self.Key = map;
|
229
|
+
});
|
230
|
+
$.on('blur', onBlur);
|
231
|
+
$.on('input', onInput);
|
232
|
+
$.on('key.down', onKeyDown);
|
233
|
+
$.on('key.up', onKeyUp);
|
234
|
+
return $[id] = map, $;
|
228
235
|
}
|
229
236
|
|
230
|
-
function detach(
|
237
|
+
function detach() {
|
231
238
|
var $ = this;
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
+
$[id].pull();
|
240
|
+
$.off('blur', onBlur);
|
241
|
+
$.off('input', onInput);
|
242
|
+
$.off('key.down', onKeyDown);
|
243
|
+
$.off('key.up', onKeyUp);
|
244
|
+
delete $[id];
|
245
|
+
return $;
|
239
246
|
}
|
240
247
|
var index_js = {
|
241
248
|
attach: attach,
|
242
|
-
detach: detach
|
249
|
+
detach: detach,
|
250
|
+
name: name
|
243
251
|
};
|
244
252
|
return index_js;
|
245
253
|
}));
|
package/index.min.js
CHANGED
@@ -23,4 +23,4 @@
|
|
23
23
|
* SOFTWARE.
|
24
24
|
*
|
25
25
|
*/
|
26
|
-
!function(n,
|
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,20 +1,24 @@
|
|
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 {
|
4
|
+
import {isFunction, isSet} from '@taufik-nurrohman/is';
|
5
|
+
import {offEventDefault} from '@taufik-nurrohman/event';
|
5
6
|
|
6
7
|
const bounce = debounce(map => map.pull(), 1000);
|
8
|
+
const name = 'TextEditor.Key';
|
9
|
+
|
10
|
+
const id = '_Key';
|
7
11
|
|
8
12
|
function onBlur(e) {
|
9
|
-
this.
|
13
|
+
this[id].pull(); // Reset all key(s)
|
10
14
|
}
|
11
15
|
|
12
16
|
function onInput(e) {
|
13
|
-
|
17
|
+
onBlur.call(this);
|
14
18
|
}
|
15
19
|
|
16
20
|
function onKeyDown(e) {
|
17
|
-
let command, map = this
|
21
|
+
let command, map = this[id], v;
|
18
22
|
map.push(e.key); // Add current key to the queue
|
19
23
|
if (command = map.command()) {
|
20
24
|
v = map.fire(command);
|
@@ -28,39 +32,57 @@ function onKeyDown(e) {
|
|
28
32
|
}
|
29
33
|
|
30
34
|
function onKeyUp(e) {
|
31
|
-
this.
|
35
|
+
this[id].pull(e.key); // Reset current key
|
32
36
|
}
|
33
37
|
|
34
|
-
function attach(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
$.commands = fromStates(map.commands, $.state.commands || {});
|
39
|
-
$.
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
function attach() {
|
39
|
+
const $ = this;
|
40
|
+
const $$ = $.constructor.prototype;
|
41
|
+
const map = new Key($);
|
42
|
+
$.commands = fromStates($.commands = map.commands, $.state.commands || {});
|
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] + "",
|
51
|
+
keys;
|
52
|
+
if (isSet(join) && '-' !== join) {
|
53
|
+
keys = "" !== key ? key.split(/-(?!$)/) : [];
|
54
|
+
if (false !== join) {
|
55
|
+
return keys.join(join);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
if (false === join) {
|
59
|
+
if ('-' === key) {
|
60
|
+
return [key];
|
61
|
+
}
|
62
|
+
return keys;
|
43
63
|
}
|
44
|
-
return key
|
45
|
-
};
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
64
|
+
return key;
|
65
|
+
});
|
66
|
+
!isFunction($$.key) && ($$.key = function (key, of) {
|
67
|
+
let $ = this;
|
68
|
+
return ($.keys[key] = of), $;
|
69
|
+
});
|
70
|
+
$.on('blur', onBlur);
|
71
|
+
$.on('input', onInput);
|
72
|
+
$.on('key.down', onKeyDown);
|
73
|
+
$.on('key.up', onKeyUp);
|
74
|
+
return ($[id] = map), $;
|
53
75
|
}
|
54
76
|
|
55
|
-
function detach(
|
77
|
+
function detach() {
|
56
78
|
let $ = this;
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
79
|
+
$[id].pull();
|
80
|
+
$.off('blur', onBlur);
|
81
|
+
$.off('input', onInput);
|
82
|
+
$.off('key.down', onKeyDown);
|
83
|
+
$.off('key.up', onKeyUp);
|
84
|
+
delete $[id];
|
85
|
+
return $;
|
64
86
|
}
|
65
87
|
|
66
|
-
export default {attach, detach};
|
88
|
+
export default {attach, detach, name};
|
package/package.json
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
"dependencies": {
|
6
6
|
"@taufik-nurrohman/event": "*",
|
7
7
|
"@taufik-nurrohman/from": "*",
|
8
|
+
"@taufik-nurrohman/is": "*",
|
8
9
|
"@taufik-nurrohman/key": "*",
|
9
10
|
"@taufik-nurrohman/text-editor": "*",
|
10
11
|
"@taufik-nurrohman/tick": "*"
|
@@ -45,5 +46,5 @@
|
|
45
46
|
"scripts": {
|
46
47
|
"pack": "pack --clean=false --from=.factory --js-format=umd --js-name=TextEditor.Key --js-top='%(js.license)' --mjs=true --to=."
|
47
48
|
},
|
48
|
-
"version": "1.0.
|
49
|
+
"version": "1.0.4"
|
49
50
|
}
|