use-mask-input 3.0.6 → 3.1.1

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 (66) hide show
  1. package/README.md +13 -19
  2. package/dist/index.cjs +191 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +34 -3
  5. package/dist/index.js +184 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +49 -48
  8. package/src/index.tsx +3 -2
  9. package/src/types.ts +6 -0
  10. package/src/useMaskInput.ts +12 -9
  11. package/src/utils.spec.ts +14 -0
  12. package/src/utils.ts +23 -0
  13. package/src/withHookFormMask.ts +8 -17
  14. package/src/withMask.ts +5 -6
  15. package/dist/example/App.example.d.ts +0 -3
  16. package/dist/example/index.d.ts +0 -1
  17. package/dist/index.modern.js +0 -2
  18. package/dist/index.modern.js.map +0 -1
  19. package/dist/index.umd.js +0 -2
  20. package/dist/index.umd.js.map +0 -1
  21. package/dist/useMaskInput.d.ts +0 -9
  22. package/dist/withHookFormMask.d.ts +0 -16
  23. package/dist/withMask.d.ts +0 -3
  24. package/node_modules/inputmask/LICENSE.txt +0 -7
  25. package/node_modules/inputmask/README.md +0 -1279
  26. package/node_modules/inputmask/bundle.js +0 -6
  27. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  28. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  29. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  30. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  31. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  32. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  33. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  34. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  35. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  36. package/node_modules/inputmask/lib/defaults.js +0 -101
  37. package/node_modules/inputmask/lib/definitions.js +0 -13
  38. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  39. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  40. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  42. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  43. package/node_modules/inputmask/lib/environment.js +0 -9
  44. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  45. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  46. package/node_modules/inputmask/lib/eventruler.js +0 -124
  47. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  48. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  49. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  50. package/node_modules/inputmask/lib/global/window.js +0 -3
  51. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  52. package/node_modules/inputmask/lib/inputmask.js +0 -355
  53. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  54. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  55. package/node_modules/inputmask/lib/keycode.json +0 -25
  56. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  57. package/node_modules/inputmask/lib/mask.js +0 -244
  58. package/node_modules/inputmask/lib/masktoken.js +0 -13
  59. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  60. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  61. package/node_modules/inputmask/lib/positioning.js +0 -348
  62. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  63. package/node_modules/inputmask/lib/validation.js +0 -664
  64. package/node_modules/inputmask/package.json +0 -60
  65. package/src/example/App.example.tsx +0 -68
  66. package/src/example/index.tsx +0 -5
@@ -1,58 +0,0 @@
1
- export default function extend() {
2
- let options, name, src, copy, copyIsArray, clone,
3
- target = arguments[0] || {},
4
- i = 1,
5
- length = arguments.length,
6
- deep = false;
7
-
8
- // Handle a deep copy situation
9
- if (typeof target === "boolean") {
10
- deep = target;
11
-
12
- // Skip the boolean and the target
13
- target = arguments[i] || {};
14
- i++;
15
- }
16
-
17
- // Handle case when target is a string or something (possible in deep copy)
18
- if (typeof target !== "object" && typeof target !== "function") {
19
- target = {};
20
- }
21
-
22
- for (; i < length; i++) {
23
- // Only deal with non-null/undefined values
24
- if ((options = arguments[i]) != null) {
25
- // Extend the base object
26
- for (name in options) {
27
- src = target[name];
28
- copy = options[name];
29
-
30
- // Prevent never-ending loop
31
- if (target === copy) {
32
- continue;
33
- }
34
-
35
- // Recurse if we're merging plain objects or arrays
36
- if (deep && copy && (Object.prototype.toString.call(copy) === "[object Object]" || (copyIsArray = Array.isArray(copy)))) {
37
- if (copyIsArray) {
38
- copyIsArray = false;
39
- clone = src && Array.isArray(src) ? src : [];
40
-
41
- } else {
42
- clone = src && Object.prototype.toString.call(src) === "[object Object]" ? src : {};
43
- }
44
-
45
- // Never move original objects, clone them
46
- target[name] = extend(deep, clone, copy);
47
-
48
- // Don't bring in undefined values
49
- } else if (copy !== undefined) {
50
- target[name] = copy;
51
- }
52
- }
53
- }
54
- }
55
-
56
- // Return the modified object
57
- return target;
58
- }
@@ -1,13 +0,0 @@
1
- /*
2
- Input Mask plugin dependencyLib
3
- http://github.com/RobinHerbots/jquery.inputmask
4
- Copyright (c) Robin Herbots
5
- Licensed under the MIT license
6
- */
7
-
8
- import jQuery from "jquery";
9
-
10
- if (jQuery === undefined) {
11
- throw "jQuery not loaded!";
12
- }
13
- export default jQuery;
@@ -1,41 +0,0 @@
1
- /*
2
- Input Mask plugin dependencyLib
3
- http://github.com/RobinHerbots/jquery.inputmask
4
- Copyright (c) Robin Herbots
5
- Licensed under the MIT license
6
- */
7
-
8
- import extend from "./extend";
9
- import window from "../global/window";
10
- import data from "./data";
11
- import { on, off, trigger, Event} from "./events";
12
-
13
- const document = window.document;
14
-
15
- function DependencyLib(elem) {
16
- if (elem instanceof DependencyLib) {
17
- return elem;
18
- }
19
- if (!(this instanceof DependencyLib)) {
20
- return new DependencyLib(elem);
21
- }
22
- if (elem !== undefined && elem !== null && elem !== window) {
23
- this[0] = elem.nodeName ? elem : (elem[0] !== undefined && elem[0].nodeName ? elem[0] : document.querySelector(elem));
24
- if (this[0] !== undefined && this[0] !== null) {
25
- this[0].eventRegistry = this[0].eventRegistry || {};
26
- }
27
- }
28
- }
29
-
30
- DependencyLib.prototype = {
31
- on: on,
32
- off: off,
33
- trigger: trigger
34
- };
35
-
36
- //static
37
- DependencyLib.extend = extend;
38
- DependencyLib.data = data;
39
- DependencyLib.Event = Event;
40
-
41
- export default DependencyLib;
@@ -1,9 +0,0 @@
1
- import window from "./global/window";
2
-
3
- const ua = (window.navigator && window.navigator.userAgent) || "",
4
- ie = (ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0),
5
- mobile = "ontouchstart" in window, //not entirely correct but will currently do
6
- iemobile = /iemobile/i.test(ua),
7
- iphone = /iphone/i.test(ua) && !iemobile;
8
-
9
- export {ua, ie, mobile, iemobile, iphone};
@@ -1,4 +0,0 @@
1
- const escapeRegexRegex = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^"].join("|\\") + ")", "gim");
2
- export default function (str) {
3
- return str.replace(escapeRegexRegex, "\\$1");
4
- }
@@ -1,513 +0,0 @@
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
- };