@taufik-nurrohman/text-editor.key 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +68 -55
- package/index.min.js +1 -1
- package/index.mjs +23 -14
- 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
|
-
$.
|
135
|
-
|
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 () {
|
@@ -164,7 +172,8 @@
|
|
164
172
|
var bounce = debounce(function (map) {
|
165
173
|
return map.pull();
|
166
174
|
}, 1000);
|
167
|
-
var
|
175
|
+
var name = 'TextEditor.Key';
|
176
|
+
var id = '_Key';
|
168
177
|
|
169
178
|
function onBlur(e) {
|
170
179
|
this[id].pull(); // Reset all key(s)
|
@@ -196,16 +205,20 @@
|
|
196
205
|
|
197
206
|
function attach() {
|
198
207
|
var $ = this;
|
208
|
+
var $$ = $.constructor.prototype;
|
199
209
|
var map = new Key($);
|
200
|
-
$.command = function (command, of) {
|
201
|
-
return $.commands[command] = of, $;
|
202
|
-
};
|
203
210
|
$.commands = fromStates($.commands = map.commands, $.state.commands || {});
|
204
|
-
$.
|
205
|
-
|
211
|
+
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
212
|
+
!isFunction($$.command) && ($$.command = function (command, of) {
|
213
|
+
var $ = this;
|
214
|
+
return $.commands[command] = of, $;
|
215
|
+
});
|
216
|
+
!isFunction($$.k) && ($$.k = function (join) {
|
217
|
+
var $ = this,
|
218
|
+
key = $[id] + "",
|
206
219
|
keys;
|
207
220
|
if (isSet(join) && '-' !== join) {
|
208
|
-
keys = "" !== key ? key.split(
|
221
|
+
keys = "" !== key ? key.split(/-(?!$)/) : [];
|
209
222
|
if (false !== join) {
|
210
223
|
return keys.join(join);
|
211
224
|
}
|
@@ -217,17 +230,16 @@
|
|
217
230
|
return keys;
|
218
231
|
}
|
219
232
|
return key;
|
220
|
-
};
|
221
|
-
|
233
|
+
});
|
234
|
+
!isFunction($$.key) && ($$.key = function (key, of) {
|
235
|
+
var $ = this;
|
222
236
|
return $.keys[key] = of, $;
|
223
|
-
};
|
224
|
-
$.keys = fromStates($.keys = map.keys, $.state.keys || {});
|
237
|
+
});
|
225
238
|
$.on('blur', onBlur);
|
226
239
|
$.on('input', onInput);
|
227
240
|
$.on('key.down', onKeyDown);
|
228
241
|
$.on('key.up', onKeyUp);
|
229
|
-
$[id] = map
|
230
|
-
return $;
|
242
|
+
return $[id] = map, $;
|
231
243
|
}
|
232
244
|
|
233
245
|
function detach() {
|
@@ -242,7 +254,8 @@
|
|
242
254
|
}
|
243
255
|
var index_js = {
|
244
256
|
attach: attach,
|
245
|
-
detach: detach
|
257
|
+
detach: detach,
|
258
|
+
name: name
|
246
259
|
};
|
247
260
|
return index_js;
|
248
261
|
}));
|
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(),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/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