use-mask-input 1.0.1 → 2.0.0

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.
Files changed (51) hide show
  1. package/dist/example/App.example.d.ts +3 -0
  2. package/dist/{useMaskInput.test.d.ts → example/index.d.ts} +0 -0
  3. package/dist/index.js +1 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.js +1 -2
  6. package/dist/index.modern.js.map +1 -1
  7. package/dist/useMaskInput.d.ts +3 -3
  8. package/node_modules/inputmask/README.md +109 -79
  9. package/node_modules/inputmask/bundle.js +6 -5
  10. package/node_modules/inputmask/dist/inputmask.es6.js +5 -0
  11. package/node_modules/inputmask/dist/inputmask.js +2892 -2608
  12. package/node_modules/inputmask/dist/inputmask.min.js +3 -3
  13. package/node_modules/inputmask/dist/jquery.inputmask.js +2829 -2534
  14. package/node_modules/inputmask/dist/jquery.inputmask.min.js +3 -3
  15. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +5 -0
  16. package/node_modules/inputmask/lib/canUseDOM.js +7 -0
  17. package/node_modules/inputmask/lib/defaults.js +101 -0
  18. package/node_modules/inputmask/lib/definitions.js +13 -0
  19. package/node_modules/inputmask/lib/dependencyLibs/data.js +8 -0
  20. package/node_modules/inputmask/lib/dependencyLibs/events.js +199 -0
  21. package/node_modules/inputmask/lib/dependencyLibs/extend.js +58 -0
  22. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +4 -3
  23. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +12 -343
  24. package/node_modules/inputmask/lib/environment.js +9 -0
  25. package/node_modules/inputmask/lib/escapeRegex.js +4 -0
  26. package/node_modules/inputmask/lib/eventhandlers.js +513 -0
  27. package/node_modules/inputmask/lib/eventruler.js +124 -0
  28. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +552 -385
  29. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +116 -97
  30. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +594 -565
  31. package/node_modules/inputmask/lib/global/window.js +2 -6
  32. package/node_modules/inputmask/lib/inputHandling.js +252 -0
  33. package/node_modules/inputmask/lib/inputmask.js +129 -126
  34. package/node_modules/inputmask/lib/inputmaskElement.js +26 -20
  35. package/node_modules/inputmask/lib/jquery.inputmask.js +3 -1
  36. package/node_modules/inputmask/lib/keycode.json +6 -1
  37. package/node_modules/inputmask/lib/mask-lexer.js +467 -0
  38. package/node_modules/inputmask/lib/mask.js +244 -0
  39. package/node_modules/inputmask/lib/masktoken.js +13 -0
  40. package/node_modules/inputmask/lib/polyfills/Array.includes.js +48 -0
  41. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +7 -0
  42. package/node_modules/inputmask/lib/positioning.js +348 -0
  43. package/node_modules/inputmask/lib/validation-tests.js +597 -0
  44. package/node_modules/inputmask/lib/validation.js +664 -0
  45. package/node_modules/inputmask/package.json +41 -71
  46. package/package.json +40 -43
  47. package/node_modules/inputmask/CHANGELOG.md +0 -714
  48. package/node_modules/inputmask/index.js +0 -1
  49. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jqlite.js +0 -170
  50. package/node_modules/inputmask/lib/maskScope.js +0 -2498
  51. package/node_modules/inputmask/lib/maskset.js +0 -466
@@ -0,0 +1,513 @@
1
+ import {
2
+ caret, determineNewCaretPosition,
3
+ getBuffer, getBufferTemplate,
4
+ getLastValidPosition, isMask,
5
+ resetMaskSet,
6
+ seekNext,
7
+ seekPrevious,
8
+ translatePosition
9
+ } from "./positioning";
10
+ import keyCode from "./keycode.json";
11
+ import { iemobile, iphone } from "./environment";
12
+ import { handleRemove, isComplete, isSelection, isValid } from "./validation";
13
+ import { applyInputValue, checkVal, clearOptionalTail, HandleNativePlaceholder, writeBuffer } from "./inputHandling";
14
+ import { getPlaceholder, getTest } from "./validation-tests";
15
+
16
+ export { EventHandlers };
17
+
18
+ var EventHandlers = {
19
+ keydownEvent: function (e) {
20
+ const inputmask = this.inputmask, opts = inputmask.opts, $ = inputmask.dependencyLib,
21
+ maskset = inputmask.maskset;
22
+
23
+ var input = this,
24
+ $input = $(input),
25
+ k = e.keyCode,
26
+ pos = caret.call(inputmask, input);
27
+
28
+ var kdResult = opts.onKeyDown.call(this, e, getBuffer.call(inputmask), pos, opts);
29
+ if (kdResult !== undefined) return kdResult;
30
+
31
+ //backspace, delete, and escape get special treatment
32
+ if (k === keyCode.BACKSPACE || k === keyCode.DELETE || (iphone && k === keyCode.BACKSPACE_SAFARI) || (e.ctrlKey && k === keyCode.X && !("oncut" in input))) { //backspace/delete
33
+ e.preventDefault(); //stop default action but allow propagation
34
+ handleRemove.call(inputmask, input, k, pos);
35
+ writeBuffer(input, getBuffer.call(inputmask, true), maskset.p, e, input.inputmask._valueGet() !== getBuffer.call(inputmask).join(""));
36
+ } else if (k === keyCode.END || k === keyCode.PAGE_DOWN) { //when END or PAGE_DOWN pressed set position at lastmatch
37
+ e.preventDefault();
38
+ var caretPos = seekNext.call(inputmask, getLastValidPosition.call(inputmask));
39
+ caret.call(inputmask, input, e.shiftKey ? pos.begin : caretPos, caretPos, true);
40
+ } else if ((k === keyCode.HOME && !e.shiftKey) || k === keyCode.PAGE_UP) { //Home or page_up
41
+ e.preventDefault();
42
+ caret.call(inputmask, input, 0, e.shiftKey ? pos.begin : 0, true);
43
+ } else if (((opts.undoOnEscape && k === keyCode.ESCAPE) || (false && k === keyCode.Z && e.ctrlKey)) && e.altKey !== true) { //escape && undo && #762
44
+ checkVal(input, true, false, inputmask.undoValue.split(""));
45
+ $input.trigger("click");
46
+ } else if (k === keyCode.INSERT && !(e.shiftKey || e.ctrlKey) && inputmask.userOptions.insertMode === undefined) { //insert
47
+ if (!isSelection.call(inputmask, pos)) {
48
+ opts.insertMode = !opts.insertMode;
49
+ caret.call(inputmask, input, pos.begin, pos.begin);
50
+ } else opts.insertMode = !opts.insertMode;
51
+ } else if (opts.tabThrough === true && k === keyCode.TAB) {
52
+ if (e.shiftKey === true) {
53
+ pos.end = seekPrevious.call(inputmask, pos.end, true);
54
+ if (getTest.call(inputmask, pos.end - 1).match.static === true) {
55
+ pos.end--;
56
+ }
57
+ pos.begin = seekPrevious.call(inputmask, pos.end, true);
58
+ if (pos.begin >= 0 && pos.end > 0) {
59
+ e.preventDefault();
60
+ caret.call(inputmask, input, pos.begin, pos.end);
61
+ }
62
+ } else {
63
+ pos.begin = seekNext.call(inputmask, pos.begin, true);
64
+ pos.end = seekNext.call(inputmask, pos.begin, true);
65
+ if (pos.end < maskset.maskLength) pos.end--;
66
+ if (pos.begin <= maskset.maskLength) {
67
+ e.preventDefault();
68
+ caret.call(inputmask, input, pos.begin, pos.end);
69
+ }
70
+ }
71
+ } else if (!e.shiftKey) {
72
+ if (opts.insertModeVisual && opts.insertMode === false) {
73
+ if (k === keyCode.RIGHT) {
74
+ setTimeout(function () {
75
+ var caretPos = caret.call(inputmask, input);
76
+ caret.call(inputmask, input, caretPos.begin);
77
+ }, 0);
78
+ } else if (k === keyCode.LEFT) {
79
+ setTimeout(function () {
80
+ var caretPos = {
81
+ begin: translatePosition.call(inputmask, input.inputmask.caretPos.begin),
82
+ end: translatePosition.call(inputmask, input.inputmask.caretPos.end)
83
+ };
84
+ if (inputmask.isRTL) {
85
+ caret.call(inputmask, input, caretPos.begin + (caretPos.begin === maskset.maskLength ? 0 : 1));
86
+ } else {
87
+ caret.call(inputmask, input, caretPos.begin - (caretPos.begin === 0 ? 0 : 1));
88
+ }
89
+ }, 0);
90
+ }
91
+ }
92
+ }
93
+
94
+ inputmask.ignorable = opts.ignorables.includes(k);
95
+ },
96
+ keypressEvent: function (e, checkval, writeOut, strict, ndx) {
97
+ const inputmask = this.inputmask || this, opts = inputmask.opts, $ = inputmask.dependencyLib,
98
+ maskset = inputmask.maskset;
99
+
100
+ var input = inputmask.el,
101
+ $input = $(input),
102
+ k = e.keyCode;
103
+
104
+ if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || inputmask.ignorable))) {
105
+ if (k === keyCode.ENTER && inputmask.undoValue !== inputmask._valueGet(true)) {
106
+ inputmask.undoValue = inputmask._valueGet(true);
107
+ // e.preventDefault();
108
+ setTimeout(function () {
109
+ $input.trigger("change");
110
+ }, 0);
111
+ }
112
+ inputmask.skipInputEvent = true; //skip the input as otherwise the skipped char could be picked up for validation by the inputfallback
113
+ return true;
114
+ } else if (k) {
115
+ //special treat the decimal separator
116
+ if ((k === 44 || k === 46) && e.location === 3 && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
117
+ var pos = checkval ? {
118
+ begin: ndx,
119
+ end: ndx
120
+ } : caret.call(inputmask, input),
121
+ forwardPosition, c = String.fromCharCode(k);
122
+
123
+ //allow for character substitution
124
+ c = opts.substitutes[c] || c;
125
+ maskset.writeOutBuffer = true;
126
+ var valResult = isValid.call(inputmask, pos, c, strict, undefined, undefined, undefined, checkval);
127
+ if (valResult !== false) {
128
+ resetMaskSet.call(inputmask, true);
129
+ forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext.call(inputmask, valResult.pos.begin ? valResult.pos.begin : valResult.pos);
130
+ maskset.p = forwardPosition; //needed for checkval
131
+ }
132
+
133
+ forwardPosition = ((opts.numericInput && valResult.caret === undefined) ? seekPrevious.call(inputmask, forwardPosition) : forwardPosition);
134
+ if (writeOut !== false) {
135
+
136
+ setTimeout(function () {
137
+ opts.onKeyValidation.call(input, k, valResult);
138
+ }, 0);
139
+ if (maskset.writeOutBuffer && valResult !== false) {
140
+ var buffer = getBuffer.call(inputmask);
141
+ writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
142
+ }
143
+ }
144
+
145
+ e.preventDefault();
146
+
147
+ if (checkval) {
148
+ if (valResult !== false) valResult.forwardPosition = forwardPosition;
149
+ return valResult;
150
+ }
151
+ }
152
+ },
153
+ keyupEvent: function (e) {
154
+ const inputmask = this.inputmask;
155
+
156
+ if (inputmask.isComposing && (e.keyCode === keyCode.KEY_229 || e.keyCode === keyCode.ENTER)) {
157
+ inputmask.$el.trigger("input");
158
+ }
159
+ },
160
+ pasteEvent: function (e) {
161
+ const inputmask = this.inputmask, opts = inputmask.opts;
162
+
163
+ var input = this,
164
+ inputValue = inputmask._valueGet(true),
165
+ caretPos = caret.call(inputmask, input),
166
+ tempValue;
167
+
168
+ if (inputmask.isRTL) {
169
+ tempValue = caretPos.end;
170
+ caretPos.end = translatePosition.call(inputmask, caretPos.begin);
171
+ caretPos.begin = translatePosition.call(inputmask, tempValue);
172
+ }
173
+
174
+ var valueBeforeCaret = inputValue.substr(0, caretPos.begin),
175
+ valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
176
+
177
+ if (valueBeforeCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(0, caretPos.begin).join("")) valueBeforeCaret = "";
178
+ if (valueAfterCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(caretPos.end).join("")) valueAfterCaret = "";
179
+
180
+ if (window.clipboardData && window.clipboardData.getData) { // IE
181
+ inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret;
182
+ } else if (e.clipboardData && e.clipboardData.getData) {
183
+ inputValue = valueBeforeCaret + e.clipboardData.getData("text/plain") + valueAfterCaret;
184
+ } else {
185
+ return true;
186
+ } //allow native paste event as fallback ~ masking will continue by inputfallback
187
+
188
+ var pasteValue = inputValue;
189
+ if (inputmask.isRTL) {
190
+ pasteValue = pasteValue.split("")
191
+ for (let c of getBufferTemplate.call(inputmask)) {
192
+ if (pasteValue[0] === c)
193
+ pasteValue.shift();
194
+ }
195
+ pasteValue = pasteValue.join("");
196
+ }
197
+ if (typeof opts.onBeforePaste === "function") {
198
+ pasteValue = opts.onBeforePaste.call(inputmask, pasteValue, opts);
199
+ if (pasteValue === false) {
200
+ return false;
201
+ }
202
+ if (!pasteValue) {
203
+ pasteValue = inputValue;
204
+ }
205
+ }
206
+ checkVal(input, true, false, pasteValue.toString().split(""), e);
207
+ e.preventDefault()
208
+ },
209
+ inputFallBackEvent: function (e) { //fallback when keypress is not triggered
210
+ const inputmask = this.inputmask, opts = inputmask.opts, $ = inputmask.dependencyLib;
211
+
212
+ function ieMobileHandler(input, inputValue, caretPos) {
213
+ if (iemobile) { //iemobile just sets the character at the end althought the caret position is correctly set
214
+ var inputChar = inputValue.replace(getBuffer.call(inputmask).join(""), "");
215
+ if (inputChar.length === 1) {
216
+ var iv = inputValue.split("");
217
+ iv.splice(caretPos.begin, 0, inputChar);
218
+ inputValue = iv.join("");
219
+ }
220
+ }
221
+ return inputValue;
222
+ }
223
+
224
+ function analyseChanges(inputValue, buffer, caretPos) {
225
+ var frontPart = inputValue.substr(0, caretPos.begin).split(""),
226
+ backPart = inputValue.substr(caretPos.begin).split(""),
227
+ frontBufferPart = buffer.substr(0, caretPos.begin).split(""),
228
+ backBufferPart = buffer.substr(caretPos.begin).split("");
229
+
230
+ var fpl = frontPart.length >= frontBufferPart.length ? frontPart.length : frontBufferPart.length,
231
+ bpl = backPart.length >= backBufferPart.length ? backPart.length : backBufferPart.length,
232
+ bl, i, action = "", data = [], marker = "~", placeholder;
233
+
234
+ //align buffers
235
+ while (frontPart.length < fpl) frontPart.push(marker);
236
+ while (frontBufferPart.length < fpl) frontBufferPart.push(marker);
237
+ while (backPart.length < bpl) backPart.unshift(marker);
238
+ while (backBufferPart.length < bpl) backBufferPart.unshift(marker);
239
+
240
+ var newBuffer = frontPart.concat(backPart);
241
+ var oldBuffer = frontBufferPart.concat(backBufferPart);
242
+
243
+ // console.log("N " + newBuffer);
244
+ // console.log("O " + oldBuffer);
245
+
246
+ for (i = 0, bl = newBuffer.length; i < bl; i++) {
247
+ placeholder = getPlaceholder.call(inputmask, translatePosition.call(inputmask, i));
248
+ switch (action) {
249
+ case "insertText":
250
+ if (oldBuffer[i - 1] === newBuffer[i] && caretPos.begin == newBuffer.length - 1) {
251
+ data.push(newBuffer[i]);
252
+ }
253
+ i = bl;
254
+ break;
255
+ case "insertReplacementText":
256
+ if (newBuffer[i] === marker) { //extend selection
257
+ caretPos.end++;
258
+ } else {
259
+ // breakout loop
260
+ i = bl;
261
+ }
262
+ break;
263
+ case "deleteContentBackward":
264
+ if (newBuffer[i] === marker) {
265
+ caretPos.end++;
266
+ } else {
267
+ //breakout loop
268
+ i = bl;
269
+ }
270
+ break;
271
+ default:
272
+ if (newBuffer[i] !== oldBuffer[i]) {
273
+ if ((newBuffer[i + 1] === marker || newBuffer[i + 1] === placeholder || newBuffer[i + 1] === undefined) && ((oldBuffer[i] === placeholder && oldBuffer[i + 1] === marker) || oldBuffer[i] === marker)) { //basic insert
274
+ action = "insertText";
275
+ data.push(newBuffer[i]);
276
+ caretPos.begin--;
277
+ caretPos.end--;
278
+ } else if (oldBuffer[i + 1] === marker && oldBuffer[i] === newBuffer[i + 1]) { //insert between
279
+ action = "insertText";
280
+ data.push(newBuffer[i]);
281
+ caretPos.begin--;
282
+ caretPos.end--;
283
+ } else if (newBuffer[i] !== placeholder && newBuffer[i] !== marker &&
284
+ (newBuffer[i + 1] === marker || (oldBuffer[i] !== newBuffer[i] && oldBuffer[i + 1] === newBuffer[i + 1] /*single char replacement*/))) { //replace selection
285
+ action = "insertReplacementText";
286
+ data.push(newBuffer[i]);
287
+ caretPos.begin--;
288
+ } else if (newBuffer[i] === marker) { //delete~backspace
289
+ action = "deleteContentBackward";
290
+ if (isMask.call(inputmask, translatePosition.call(inputmask, i), true) || oldBuffer[i] === opts.radixPoint) caretPos.end++;
291
+ } else {
292
+ i = bl;
293
+ }
294
+ }
295
+ break;
296
+ }
297
+ }
298
+
299
+ return {
300
+ action: action,
301
+ data: data,
302
+ caret: caretPos
303
+ };
304
+ }
305
+
306
+ var input = this,
307
+ inputValue = input.inputmask._valueGet(true),
308
+ buffer = (inputmask.isRTL ? getBuffer.call(inputmask).slice().reverse() : getBuffer.call(inputmask)).join(""),
309
+ caretPos = caret.call(inputmask, input, undefined, undefined, true);
310
+
311
+ if (buffer !== inputValue) {
312
+ inputValue = ieMobileHandler(input, inputValue, caretPos);
313
+
314
+ var changes = analyseChanges(inputValue, buffer, caretPos);
315
+
316
+ // console.log(JSON.stringify(changes));
317
+ if ((input.inputmask.shadowRoot || input.ownerDocument).activeElement !== input) {
318
+ input.focus();
319
+ }
320
+ writeBuffer(input, getBuffer.call(inputmask));
321
+ caret.call(inputmask, input, caretPos.begin, caretPos.end, true);
322
+ switch (changes.action) {
323
+ case "insertText":
324
+ case "insertReplacementText":
325
+ changes.data.forEach(function (entry, ndx) {
326
+ var keypress = new $.Event("keypress");
327
+ keypress.keyCode = entry.charCodeAt(0);
328
+ inputmask.ignorable = false; //make sure ignorable is ignored ;-)
329
+ EventHandlers.keypressEvent.call(input, keypress);
330
+ });
331
+ setTimeout(function () { //#2195 trigger keyup to help some other plugins to track changes
332
+ inputmask.$el.trigger("keyup");
333
+ }, 0);
334
+ break;
335
+ case "deleteContentBackward":
336
+ var keydown = new $.Event("keydown");
337
+ keydown.keyCode = keyCode.BACKSPACE;
338
+ EventHandlers.keydownEvent.call(input, keydown);
339
+ break;
340
+ default:
341
+ applyInputValue(input, inputValue);
342
+ break;
343
+ }
344
+
345
+ e.preventDefault();
346
+ }
347
+ },
348
+ compositionendEvent: function (e) {
349
+ const inputmask = this.inputmask;
350
+
351
+ inputmask.isComposing = false;
352
+ inputmask.$el.trigger("input");
353
+ },
354
+ setValueEvent: function (e) {
355
+ const inputmask = this.inputmask;
356
+ var input = this,
357
+ value = (e && e.detail) ? e.detail[0] : arguments[1];
358
+
359
+ if (value === undefined) {
360
+ value = input.inputmask._valueGet(true);
361
+ }
362
+
363
+ applyInputValue(input, value);
364
+
365
+ if ((e.detail && e.detail[1] !== undefined) || arguments[2] !== undefined) {
366
+ caret.call(inputmask, input, e.detail ? e.detail[1] : arguments[2]);
367
+ }
368
+ }
369
+ ,
370
+ focusEvent: function (e) {
371
+ const inputmask = this.inputmask, opts = inputmask.opts;
372
+ var input = this,
373
+ nptValue = input.inputmask._valueGet();
374
+
375
+ if (opts.showMaskOnFocus) {
376
+ if (nptValue !== getBuffer.call(inputmask).join("")) {
377
+ writeBuffer(input, getBuffer.call(inputmask), seekNext.call(inputmask, getLastValidPosition.call(inputmask)));
378
+ } /*else if (mouseEnter === false) { //only executed on focus without mouseenter
379
+ caret(input, seekNext(getLastValidPosition()));
380
+ }*/
381
+ }
382
+ if (opts.positionCaretOnTab === true && inputmask.mouseEnter === false && (!isComplete.call(inputmask, getBuffer.call(inputmask)) || getLastValidPosition.call(inputmask) === -1)) {
383
+ EventHandlers.clickEvent.apply(input, [e, true]);
384
+ }
385
+ inputmask.undoValue = inputmask._valueGet(true);
386
+ },
387
+ invalidEvent: function (e) {
388
+ this.inputmask.validationEvent = true;
389
+ },
390
+ mouseleaveEvent: function () {
391
+ const inputmask = this.inputmask, opts = inputmask.opts;
392
+
393
+ var input = this;
394
+ inputmask.mouseEnter = false;
395
+ if (opts.clearMaskOnLostFocus && (input.inputmask.shadowRoot || input.ownerDocument).activeElement !== input) {
396
+ HandleNativePlaceholder(input, inputmask.originalPlaceholder);
397
+ }
398
+ },
399
+ clickEvent: function (e, tabbed) {
400
+ const inputmask = this.inputmask;
401
+
402
+ var input = this;
403
+ if ((input.inputmask.shadowRoot || input.ownerDocument).activeElement === input) {
404
+ var newCaretPosition = determineNewCaretPosition.call(inputmask, caret.call(inputmask, input), tabbed);
405
+ if (newCaretPosition !== undefined) {
406
+ caret.call(inputmask, input, newCaretPosition);
407
+ }
408
+ }
409
+ },
410
+ cutEvent: function (e) {
411
+ const inputmask = this.inputmask, maskset = inputmask.maskset;
412
+
413
+ var input = this,
414
+ pos = caret.call(inputmask, input);
415
+
416
+ //correct clipboardData
417
+ var clipData = inputmask.isRTL ? getBuffer.call(inputmask).slice(pos.end, pos.begin) : getBuffer.call(inputmask).slice(pos.begin, pos.end),
418
+ clipDataText = inputmask.isRTL ? clipData.reverse().join("") : clipData.join("");
419
+ if (window.navigator.clipboard) window.navigator.clipboard.writeText(clipDataText);
420
+ else if (window.clipboardData && window.clipboardData.getData) { // IE
421
+ window.clipboardData.setData("Text", clipDataText);
422
+ }
423
+ handleRemove.call(inputmask, input, keyCode.DELETE, pos);
424
+ writeBuffer(input, getBuffer.call(inputmask), maskset.p, e, inputmask.undoValue !== inputmask._valueGet(true));
425
+ },
426
+ blurEvent: function (e) {
427
+ const inputmask = this.inputmask, opts = inputmask.opts, $ = inputmask.dependencyLib;
428
+
429
+ var $input = $(this),
430
+ input = this;
431
+ if (input.inputmask) {
432
+ HandleNativePlaceholder(input, inputmask.originalPlaceholder);
433
+ var nptValue = input.inputmask._valueGet(),
434
+ buffer = getBuffer.call(inputmask).slice();
435
+
436
+ if (nptValue !== "") {
437
+ if (opts.clearMaskOnLostFocus) {
438
+ if (getLastValidPosition.call(inputmask) === -1 && nptValue === getBufferTemplate.call(inputmask).join("")) {
439
+ buffer = [];
440
+ } else { //clearout optional tail of the mask
441
+ clearOptionalTail.call(inputmask, buffer);
442
+ }
443
+ }
444
+ if (isComplete.call(inputmask, buffer) === false) {
445
+ setTimeout(function () {
446
+ $input.trigger("incomplete");
447
+ }, 0);
448
+ if (opts.clearIncomplete) {
449
+ resetMaskSet.call(inputmask);
450
+ if (opts.clearMaskOnLostFocus) {
451
+ buffer = [];
452
+ } else {
453
+ buffer = getBufferTemplate.call(inputmask).slice();
454
+ }
455
+
456
+ }
457
+ }
458
+
459
+ writeBuffer(input, buffer, undefined, e);
460
+ }
461
+
462
+ if (inputmask.undoValue !== inputmask._valueGet(true)) {
463
+ inputmask.undoValue = inputmask._valueGet(true);
464
+ $input.trigger("change");
465
+ }
466
+ }
467
+ }
468
+ ,
469
+ mouseenterEvent: function () {
470
+ const inputmask = this.inputmask, opts = inputmask.opts;
471
+
472
+ var input = this;
473
+ inputmask.mouseEnter = true;
474
+ if ((input.inputmask.shadowRoot || input.ownerDocument).activeElement !== input) {
475
+ var bufferTemplate = (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).join("");
476
+ if (inputmask.placeholder !== bufferTemplate && input.placeholder !== inputmask.originalPlaceholder) {
477
+ inputmask.originalPlaceholder = input.placeholder;
478
+ }
479
+ if (opts.showMaskOnHover) {
480
+ HandleNativePlaceholder(input, bufferTemplate);
481
+ }
482
+ }
483
+ }
484
+ ,
485
+ submitEvent: function () { //trigger change on submit if any
486
+ const inputmask = this.inputmask, opts = inputmask.opts;
487
+
488
+ if (inputmask.undoValue !== inputmask._valueGet(true)) {
489
+ inputmask.$el.trigger("change");
490
+ }
491
+ if (/*opts.clearMaskOnLostFocus && */getLastValidPosition.call(inputmask) === -1 && inputmask._valueGet && inputmask._valueGet() === getBufferTemplate.call(inputmask).join("")) {
492
+ inputmask._valueSet(""); //clear masktemplete on submit and still has focus
493
+ }
494
+ if (opts.clearIncomplete && isComplete.call(inputmask, getBuffer.call(inputmask)) === false) {
495
+ inputmask._valueSet("");
496
+ }
497
+ if (opts.removeMaskOnSubmit) {
498
+ inputmask._valueSet(inputmask.unmaskedvalue(), true);
499
+ setTimeout(function () {
500
+ writeBuffer(inputmask.el, getBuffer.call(inputmask));
501
+ }, 0);
502
+ }
503
+ }
504
+ ,
505
+ resetEvent: function () {
506
+ const inputmask = this.inputmask;
507
+
508
+ inputmask.refreshValue = true; //indicate a forced refresh when there is a call to the value before leaving the triggering event fn
509
+ setTimeout(function () {
510
+ applyInputValue(inputmask.el, inputmask._valueGet(true));
511
+ }, 0);
512
+ }
513
+ };
@@ -0,0 +1,124 @@
1
+ import Inputmask from "./inputmask";
2
+ import keyCode from "./keycode.json";
3
+ import {getBufferTemplate} from "./positioning";
4
+ import {HandleNativePlaceholder} from "./inputHandling";
5
+
6
+ export {EventRuler};
7
+
8
+ var EventRuler = {
9
+ on: function (input, eventName, eventHandler) {
10
+ const $ = input.inputmask.dependencyLib;
11
+
12
+ var ev = function (e) {
13
+ if (e.originalEvent) {
14
+ e = e.originalEvent || e; //get original event from jquery evenbt
15
+ arguments[0] = e;
16
+ }
17
+ // console.log(e.type);
18
+ var that = this, args, inputmask = that.inputmask, opts = inputmask ? inputmask.opts : undefined;
19
+ if (inputmask === undefined && this.nodeName !== "FORM") { //happens when cloning an object with jquery.clone
20
+ var imOpts = $.data(that, "_inputmask_opts");
21
+ $(that).off(); //unbind all events
22
+ if (imOpts) {
23
+ (new Inputmask(imOpts)).mask(that);
24
+ }
25
+ } else if (!["submit", "reset", "setvalue"].includes(e.type) && this.nodeName !== "FORM" && (that.disabled || (that.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || (opts.tabThrough === false && e.keyCode === keyCode.TAB))))) {
26
+ e.preventDefault();
27
+ } else {
28
+ switch (e.type) {
29
+ case "input":
30
+ if (inputmask.skipInputEvent === true || (e.inputType && e.inputType === "insertCompositionText")) {
31
+ inputmask.skipInputEvent = false;
32
+ return e.preventDefault();
33
+ }
34
+
35
+ // if (mobile) { //this causes problem see #2220
36
+ // args = arguments;
37
+ // setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818
38
+ // eventHandler.apply(that, args);
39
+ // caret(that, that.inputmask.caretPos, undefined, true);
40
+ // }, 0);
41
+ // return false;
42
+ // }
43
+ break;
44
+ case "keydown":
45
+ //Safari 5.1.x - modal dialog fires keypress twice workaround
46
+ inputmask.skipKeyPressEvent = false;
47
+ inputmask.skipInputEvent = inputmask.isComposing = e.keyCode === keyCode.KEY_229;
48
+ break;
49
+ case "keyup":
50
+ case "compositionend":
51
+ if (inputmask.isComposing) {
52
+ inputmask.skipInputEvent = false;
53
+ }
54
+ break;
55
+ case "keypress":
56
+ if (inputmask.skipKeyPressEvent === true) {
57
+ return e.preventDefault();
58
+ }
59
+ inputmask.skipKeyPressEvent = true;
60
+ break;
61
+ case "click":
62
+ case "focus":
63
+ if (inputmask.validationEvent) { // #841
64
+ inputmask.validationEvent = false;
65
+ input.blur();
66
+ HandleNativePlaceholder(input, (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).join(""));
67
+ setTimeout(function () {
68
+ input.focus();
69
+ }, opts.validationEventTimeOut);
70
+ return false;
71
+ }
72
+ args = arguments;
73
+ setTimeout(function () { //needed for Chrome ~ initial selection clears after the clickevent
74
+ if (!input.inputmask) {
75
+ // `inputmask.remove()` was called before this callback
76
+ return;
77
+ }
78
+ eventHandler.apply(that, args);
79
+ }, 0);
80
+ return false;
81
+ }
82
+ var returnVal = eventHandler.apply(that, arguments);
83
+ if (returnVal === false) {
84
+ e.preventDefault();
85
+ e.stopPropagation();
86
+ }
87
+ return returnVal;
88
+ }
89
+ };
90
+ if (["submit", "reset"].includes(eventName)) {
91
+ ev = ev.bind(input); //bind creates a new eventhandler (wrap)
92
+ if (input.form !== null) $(input.form).on(eventName, ev);
93
+ } else {
94
+ $(input).on(eventName, ev);
95
+ }
96
+
97
+ //keep instance of the event
98
+ input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
99
+ input.inputmask.events[eventName].push(ev);
100
+
101
+ },
102
+ off: function (input, event) {
103
+ if (input.inputmask && input.inputmask.events) {
104
+ const $ = input.inputmask.dependencyLib;
105
+ let events = input.inputmask.events;
106
+ if (event) {
107
+ events = [];
108
+ events[event] = input.inputmask.events[event];
109
+ }
110
+ for (let eventName in events) {
111
+ let evArr = events[eventName];
112
+ while (evArr.length > 0) {
113
+ let ev = evArr.pop();
114
+ if (["submit", "reset",].includes(eventName)) {
115
+ if (input.form !== null) $(input.form).off(eventName, ev);
116
+ } else {
117
+ $(input).off(eventName, ev);
118
+ }
119
+ }
120
+ delete input.inputmask.events[eventName];
121
+ }
122
+ }
123
+ }
124
+ };