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,244 +0,0 @@
1
- import keyCode from "./keycode.json";
2
- import {caret, getBuffer, getBufferTemplate, getLastValidPosition, resetMaskSet, seekNext} from "./positioning";
3
- import {applyInputValue, clearOptionalTail, writeBuffer} from "./inputHandling";
4
- import {EventRuler} from "./eventruler";
5
- import {iphone, mobile} from "./environment";
6
- import {isComplete} from "./validation";
7
- import {EventHandlers} from "./eventhandlers";
8
-
9
- export{mask};
10
-
11
- //todo put on the prototype?
12
- function mask() {
13
- const inputmask = this,
14
- opts= this.opts,
15
- el=this.el,$=this.dependencyLib;
16
-
17
-
18
- function isElementTypeSupported(input, opts) {
19
- function patchValueProperty(npt) {
20
- var valueGet;
21
- var valueSet;
22
-
23
- function patchValhook(type) {
24
- if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
25
- var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) {
26
- return elem.value;
27
- };
28
- var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
29
- elem.value = value;
30
- return elem;
31
- };
32
-
33
- $.valHooks[type] = {
34
- get: function (elem) {
35
- if (elem.inputmask) {
36
- if (elem.inputmask.opts.autoUnmask) {
37
- return elem.inputmask.unmaskedvalue();
38
- } else {
39
- var result = valhookGet(elem);
40
- return getLastValidPosition.call(inputmask, undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
41
- }
42
- } else {
43
- return valhookGet(elem);
44
- }
45
- },
46
- set: function (elem, value) {
47
- var result = valhookSet(elem, value);
48
- if (elem.inputmask) {
49
- applyInputValue(elem, value);
50
- }
51
- return result;
52
- },
53
- inputmaskpatch: true
54
- };
55
- }
56
- }
57
-
58
- function getter() {
59
- if (this.inputmask) {
60
- return this.inputmask.opts.autoUnmask ?
61
- this.inputmask.unmaskedvalue() :
62
- (getLastValidPosition.call(inputmask) !== -1 || opts.nullable !== true ?
63
- (((this.inputmask.shadowRoot || this.ownerDocument).activeElement) === this && opts.clearMaskOnLostFocus ?
64
- (inputmask.isRTL ? clearOptionalTail.call(inputmask,getBuffer.call(inputmask).slice()).reverse() : clearOptionalTail.call(inputmask,getBuffer.call(inputmask).slice())).join("") :
65
- valueGet.call(this)) :
66
- "");
67
- } else {
68
- return valueGet.call(this);
69
- }
70
- }
71
-
72
- function setter(value) {
73
- valueSet.call(this, value);
74
- if (this.inputmask) {
75
- applyInputValue(this, value);
76
- }
77
- }
78
-
79
- function installNativeValueSetFallback(npt) {
80
- EventRuler.on(npt, "mouseenter", function () {
81
- var input = this,
82
- value = input.inputmask._valueGet(true);
83
- if (value !== (inputmask.isRTL ? getBuffer.call(inputmask).reverse() : getBuffer.call(inputmask)).join("")) { //Is this correct? to apply RTL? TOCHECK
84
- applyInputValue(input, value);
85
- }
86
- });
87
- }
88
-
89
- if (!npt.inputmask.__valueGet) {
90
- if (opts.noValuePatching !== true) {
91
- if (Object.getOwnPropertyDescriptor) {
92
- var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined;
93
- if (valueProperty && valueProperty.get && valueProperty.set) {
94
- valueGet = valueProperty.get;
95
- valueSet = valueProperty.set;
96
- Object.defineProperty(npt, "value", {
97
- get: getter,
98
- set: setter,
99
- configurable: true
100
- });
101
- } else if (npt.tagName.toLowerCase() !== "input") {
102
- valueGet = function () {
103
- return this.textContent;
104
- };
105
- valueSet = function (value) {
106
- this.textContent = value;
107
- };
108
- Object.defineProperty(npt, "value", {
109
- get: getter,
110
- set: setter,
111
- configurable: true
112
- });
113
- }
114
- } else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
115
- valueGet = npt.__lookupGetter__("value");
116
- valueSet = npt.__lookupSetter__("value");
117
-
118
- npt.__defineGetter__("value", getter);
119
- npt.__defineSetter__("value", setter);
120
- }
121
- npt.inputmask.__valueGet = valueGet; //store native property getter
122
- npt.inputmask.__valueSet = valueSet; //store native property setter
123
- }
124
- npt.inputmask._valueGet = function (overruleRTL) {
125
- return inputmask.isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
126
- };
127
- npt.inputmask._valueSet = function (value, overruleRTL) { //null check is needed for IE8 => otherwise converts to "null"
128
- valueSet.call(this.el, (value === null || value === undefined) ? "" : ((overruleRTL !== true && inputmask.isRTL) ? value.split("").reverse().join("") : value));
129
- };
130
-
131
- if (valueGet === undefined) { //jquery.val fallback
132
- valueGet = function () {
133
- return this.value;
134
- };
135
- valueSet = function (value) {
136
- this.value = value;
137
- };
138
- patchValhook(npt.type);
139
- installNativeValueSetFallback(npt);
140
- }
141
- }
142
- }
143
-
144
- if (input.tagName.toLowerCase() !== "textarea") {
145
- opts.ignorables.push(keyCode.ENTER);
146
- }
147
-
148
- var elementType = input.getAttribute("type");
149
- var isSupported = (input.tagName.toLowerCase() === "input" && opts.supportsInputType.includes(elementType)) || input.isContentEditable || input.tagName.toLowerCase() === "textarea";
150
- if (!isSupported) {
151
- if (input.tagName.toLowerCase() === "input") {
152
- var el = document.createElement("input");
153
- el.setAttribute("type", elementType);
154
- isSupported = el.type === "text"; //apply mask only if the type is not natively supported
155
- el = null;
156
- } else {
157
- isSupported = "partial";
158
- }
159
- }
160
- if (isSupported !== false) {
161
- patchValueProperty(input);
162
- } else {
163
- input.inputmask = undefined;
164
- }
165
- return isSupported;
166
- }
167
-
168
- //unbind all events - to make sure that no other mask will interfere when re-masking
169
- EventRuler.off(el);
170
- var isSupported = isElementTypeSupported(el, opts);
171
- if (isSupported !== false) {
172
- inputmask.originalPlaceholder = el.placeholder;
173
-
174
- //read maxlength prop from el
175
- inputmask.maxLength = el !== undefined ? el.maxLength : undefined;
176
- if (inputmask.maxLength === -1) inputmask.maxLength = undefined;
177
- if ("inputMode" in el && el.getAttribute("inputmode") === null) {
178
- el.inputMode = opts.inputmode;
179
- el.setAttribute("inputmode", opts.inputmode);
180
- }
181
-
182
-
183
- if (isSupported === true) {
184
- opts.showMaskOnFocus = opts.showMaskOnFocus && ["cc-number", "cc-exp"].indexOf(el.autocomplete) === -1;
185
- if (iphone) { //selecting the caret shows as a slection on iphone
186
- opts.insertModeVisual = false;
187
- }
188
-
189
- //bind events
190
- EventRuler.on(el, "submit", EventHandlers.submitEvent);
191
- EventRuler.on(el, "reset", EventHandlers.resetEvent);
192
- EventRuler.on(el, "blur", EventHandlers.blurEvent);
193
- EventRuler.on(el, "focus", EventHandlers.focusEvent);
194
- EventRuler.on(el, "invalid", EventHandlers.invalidEvent);
195
- EventRuler.on(el, "click", EventHandlers.clickEvent);
196
- EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
197
- EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
198
- EventRuler.on(el, "paste", EventHandlers.pasteEvent);
199
- EventRuler.on(el, "cut", EventHandlers.cutEvent);
200
- EventRuler.on(el, "complete", opts.oncomplete);
201
- EventRuler.on(el, "incomplete", opts.onincomplete);
202
- EventRuler.on(el, "cleared", opts.oncleared);
203
- if (opts.inputEventOnly !== true) {
204
- EventRuler.on(el, "keydown", EventHandlers.keydownEvent);
205
- EventRuler.on(el, "keypress", EventHandlers.keypressEvent);
206
- EventRuler.on(el, "keyup", EventHandlers.keyupEvent);
207
- }
208
- if (mobile || opts.inputEventOnly) {
209
- el.removeAttribute("maxLength");
210
- }
211
- EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
212
- EventRuler.on(el, "compositionend", EventHandlers.compositionendEvent);
213
- // EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent); //https://github.com/w3c/input-events - to implement
214
- }
215
- EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
216
-
217
- //apply mask
218
- getBufferTemplate.call(inputmask).join(""); //initialize the buffer and getmasklength
219
- inputmask.undoValue = inputmask._valueGet(true);
220
- var activeElement = (el.inputmask.shadowRoot || el.ownerDocument).activeElement;
221
- if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || activeElement === el) {
222
- applyInputValue(el, el.inputmask._valueGet(true), opts);
223
- var buffer = getBuffer.call(inputmask).slice();
224
- if (isComplete.call(inputmask, buffer) === false) {
225
- if (opts.clearIncomplete) {
226
- resetMaskSet.call(inputmask);
227
- }
228
- }
229
- if (opts.clearMaskOnLostFocus && activeElement !== el) {
230
- if (getLastValidPosition.call(inputmask) === -1) {
231
- buffer = [];
232
- } else {
233
- clearOptionalTail.call(inputmask, buffer);
234
- }
235
- }
236
- if (opts.clearMaskOnLostFocus === false || (opts.showMaskOnFocus && activeElement === el) || el.inputmask._valueGet(true) !== "") {
237
- writeBuffer(el, buffer);
238
- }
239
- if (activeElement === el) { //position the caret when in focus
240
- caret.call(inputmask,el, seekNext.call(inputmask, getLastValidPosition.call(inputmask)));
241
- }
242
- }
243
- }
244
- }
@@ -1,13 +0,0 @@
1
- export default function (isGroup, isOptional, isQuantifier, isAlternator) {
2
- this.matches = [];
3
- this.openGroup = isGroup || false;
4
- this.alternatorGroup = false;
5
- this.isGroup = isGroup || false;
6
- this.isOptional = isOptional || false;
7
- this.isQuantifier = isQuantifier || false;
8
- this.isAlternator = isAlternator || false;
9
- this.quantifier = {
10
- min: 1,
11
- max: 1
12
- };
13
- }
@@ -1,48 +0,0 @@
1
- // https://tc39.github.io/ecma262/#sec-array.prototype.includes
2
- if (!Array.prototype.includes) {
3
- Object.defineProperty(Array.prototype, "includes", {
4
- value: function(searchElement, fromIndex) {
5
-
6
- // 1. Let O be ? ToObject(this value).
7
- if (this == null) {
8
- throw new TypeError("\"this\" is null or not defined");
9
- }
10
-
11
- var o = Object(this);
12
-
13
- // 2. Let len be ? ToLength(? Get(O, "length")).
14
- var len = o.length >>> 0;
15
-
16
- // 3. If len is 0, return false.
17
- if (len === 0) {
18
- return false;
19
- }
20
-
21
- // 4. Let n be ? ToInteger(fromIndex).
22
- // (If fromIndex is undefined, this step produces the value 0.)
23
- var n = fromIndex | 0;
24
-
25
- // 5. If n ≥ 0, then
26
- // a. Let k be n.
27
- // 6. Else n < 0,
28
- // a. Let k be len + n.
29
- // b. If k < 0, let k be 0.
30
- var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
31
-
32
- // 7. Repeat, while k < len
33
- while (k < len) {
34
- // a. Let elementK be the result of ? Get(O, ! ToString(k)).
35
- // b. If SameValueZero(searchElement, elementK) is true, return true.
36
- // c. Increase k by 1.
37
- // NOTE: === provides the correct "SameValueZero" comparison needed here.
38
- if (o[k] === searchElement) {
39
- return true;
40
- }
41
- k++;
42
- }
43
-
44
- // 8. Return false
45
- return false;
46
- }
47
- });
48
- }
@@ -1,7 +0,0 @@
1
- if (typeof Object.getPrototypeOf !== "function") {
2
- Object.getPrototypeOf = typeof "test".__proto__ === "object" ? function (object) {
3
- return object.__proto__;
4
- } : function (object) {
5
- return object.constructor.prototype;
6
- };
7
- }
@@ -1,348 +0,0 @@
1
- import {
2
- determineTestTemplate,
3
- getMaskTemplate,
4
- getPlaceholder,
5
- getTest,
6
- getTests,
7
- getTestTemplate
8
- } from "./validation-tests";
9
- import {checkAlternationMatch} from "./validation";
10
-
11
- export {
12
- caret,
13
- determineLastRequiredPosition,
14
- determineNewCaretPosition,
15
- getBuffer,
16
- getBufferTemplate,
17
- getLastValidPosition,
18
- isMask,
19
- resetMaskSet,
20
- seekNext,
21
- seekPrevious,
22
- translatePosition
23
- };
24
-
25
- //tobe put on prototype?
26
- function caret(input, begin, end, notranslate, isDelete) {
27
- const inputmask = this,
28
- opts = this.opts;
29
-
30
- var range;
31
- if (begin !== undefined) {
32
- if (Array.isArray(begin)) {
33
- end = inputmask.isRTL ? begin[0] : begin[1];
34
- begin = inputmask.isRTL ? begin[1] : begin[0];
35
- }
36
- if (begin.begin !== undefined) {
37
- end = inputmask.isRTL ? begin.begin : begin.end;
38
- begin = inputmask.isRTL ? begin.end : begin.begin;
39
- }
40
- if (typeof begin === "number") {
41
- begin = notranslate ? begin : translatePosition.call(inputmask, begin);
42
- end = notranslate ? end : translatePosition.call(inputmask, end);
43
- end = (typeof end == "number") ? end : begin;
44
- // if (!$(input).is(":visible")) {
45
- // return;
46
- // }
47
-
48
- var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
49
- input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
50
- input.inputmask.caretPos = {begin: begin, end: end}; //track caret internally
51
- if (opts.insertModeVisual && opts.insertMode === false && begin === end) {
52
- if (!isDelete) {
53
- end++; //set visualization for insert/overwrite mode
54
- }
55
- }
56
- if (input === (input.inputmask.shadowRoot || input.ownerDocument).activeElement) {
57
- if ("setSelectionRange" in input) {
58
- input.setSelectionRange(begin, end);
59
- } else if (window.getSelection) {
60
- range = document.createRange();
61
- if (input.firstChild === undefined || input.firstChild === null) {
62
- var textNode = document.createTextNode("");
63
- input.appendChild(textNode);
64
- }
65
- range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
66
- range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
67
- range.collapse(true);
68
- var sel = window.getSelection();
69
- sel.removeAllRanges();
70
- sel.addRange(range);
71
- //input.focus();
72
- } else if (input.createTextRange) {
73
- range = input.createTextRange();
74
- range.collapse(true);
75
- range.moveEnd("character", end);
76
- range.moveStart("character", begin);
77
- range.select();
78
- }
79
- }
80
- }
81
- } else {
82
- if ("selectionStart" in input && "selectionEnd" in input) {
83
- begin = input.selectionStart;
84
- end = input.selectionEnd;
85
- } else if (window.getSelection) {
86
- range = window.getSelection().getRangeAt(0);
87
- if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
88
- begin = range.startOffset;
89
- end = range.endOffset;
90
- }
91
- } else if (document.selection && document.selection.createRange) {
92
- range = document.selection.createRange();
93
- begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length);
94
- end = begin + range.text.length;
95
- }
96
-
97
- // if (opts.insertModeVisual && opts.insertMode === false && begin === (end - 1)) end--; //correct caret for insert/overwrite mode
98
-
99
- /*eslint-disable consistent-return */
100
- return {
101
- "begin": notranslate ? begin : translatePosition.call(inputmask, begin),
102
- "end": notranslate ? end : translatePosition.call(inputmask, end)
103
- };
104
- /*eslint-enable consistent-return */
105
- }
106
- }
107
-
108
- //tobe put on prototype?
109
- function determineLastRequiredPosition(returnDefinition) {
110
- const inputmask = this,
111
- maskset = this.maskset,
112
- $ = this.dependencyLib;
113
-
114
- var buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true, true),
115
- bl = buffer.length,
116
- pos, lvp = getLastValidPosition.call(inputmask),
117
- positions = {},
118
- lvTest = maskset.validPositions[lvp],
119
- ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined,
120
- testPos;
121
- for (pos = lvp + 1; pos < buffer.length; pos++) {
122
- testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1);
123
- ndxIntlzr = testPos.locator.slice();
124
- positions[pos] = $.extend(true, {}, testPos);
125
- }
126
-
127
- var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
128
- for (pos = bl - 1; pos > lvp; pos--) {
129
- testPos = positions[pos];
130
- if ((testPos.match.optionality ||
131
- (testPos.match.optionalQuantifier && testPos.match.newBlockMarker) ||
132
- (lvTestAlt &&
133
- (
134
- (lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.static != true) ||
135
- (testPos.match.static === true &&
136
- testPos.locator[lvTest.alternation] &&
137
- checkAlternationMatch.call(inputmask, testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) &&
138
- getTests.call(inputmask, pos)[0].def !== "")
139
- )
140
- )) &&
141
- buffer[pos] === getPlaceholder.call(inputmask, pos, testPos.match)) {
142
- bl--;
143
- } else {
144
- break;
145
- }
146
- }
147
- return returnDefinition ? {
148
- "l": bl,
149
- "def": positions[bl] ? positions[bl].match : undefined
150
- } : bl;
151
- }
152
-
153
- //tobe put on prototype?
154
- function determineNewCaretPosition(selectedCaret, tabbed, positionCaretOnClick) {
155
- const inputmask = this,
156
- maskset = this.maskset,
157
- opts = this.opts;
158
-
159
- function doRadixFocus(clickPos) {
160
- if (opts.radixPoint !== "" && opts.digits !== 0) {
161
- var vps = maskset.validPositions;
162
- if (vps[clickPos] === undefined || (vps[clickPos].input === getPlaceholder.call(inputmask, clickPos))) {
163
- if (clickPos < seekNext.call(inputmask, -1)) return true;
164
- var radixPos = getBuffer.call(inputmask).indexOf(opts.radixPoint);
165
- if (radixPos !== -1) {
166
- for (var vp in vps) {
167
- if (vps[vp] && radixPos < vp && vps[vp].input !== getPlaceholder.call(inputmask, vp)) {
168
- return false;
169
- }
170
- }
171
- return true;
172
- }
173
- }
174
- }
175
- return false;
176
- }
177
-
178
- if (tabbed) {
179
- if (inputmask.isRTL) {
180
- selectedCaret.end = selectedCaret.begin;
181
- } else {
182
- selectedCaret.begin = selectedCaret.end;
183
- }
184
- }
185
- if (selectedCaret.begin === selectedCaret.end) {
186
- positionCaretOnClick = positionCaretOnClick || opts.positionCaretOnClick;
187
- switch (positionCaretOnClick) {
188
- case "none":
189
- break;
190
- case "select":
191
- selectedCaret = {begin: 0, end: getBuffer.call(inputmask).length};
192
- break;
193
- case "ignore":
194
- selectedCaret.end = selectedCaret.begin = seekNext.call(inputmask, getLastValidPosition.call(inputmask));
195
- break;
196
- case "radixFocus":
197
- if (doRadixFocus(selectedCaret.begin)) {
198
- var radixPos = getBuffer.call(inputmask).join("").indexOf(opts.radixPoint);
199
- selectedCaret.end = selectedCaret.begin = opts.numericInput ? seekNext.call(inputmask, radixPos) : radixPos;
200
- break;
201
- } //fallback to lvp
202
- // eslint-disable-next-line no-fallthrough
203
- default: //lvp:
204
- var clickPosition = selectedCaret.begin,
205
- lvclickPosition = getLastValidPosition.call(inputmask, clickPosition, true),
206
- lastPosition = seekNext.call(inputmask, (lvclickPosition === -1 && !isMask.call(inputmask, 0)) ? -1 : lvclickPosition);
207
-
208
- if (clickPosition <= lastPosition) {
209
- selectedCaret.end = selectedCaret.begin = !isMask.call(inputmask, clickPosition, false, true) ? seekNext.call(inputmask, clickPosition) : clickPosition;
210
- } else {
211
- var lvp = maskset.validPositions[lvclickPosition],
212
- tt = getTestTemplate.call(inputmask, lastPosition, lvp ? lvp.match.locator : undefined, lvp),
213
- placeholder = getPlaceholder.call(inputmask, lastPosition, tt.match);
214
- if ((placeholder !== "" && getBuffer.call(inputmask)[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true) || (!isMask.call(inputmask, lastPosition, opts.keepStatic, true) && tt.match.def === placeholder)) {
215
- var newPos = seekNext.call(inputmask, lastPosition);
216
- if (clickPosition >= newPos || clickPosition === lastPosition) {
217
- lastPosition = newPos;
218
- }
219
- }
220
- selectedCaret.end = selectedCaret.begin = lastPosition;
221
- }
222
- }
223
-
224
- return selectedCaret;
225
- }
226
- }
227
-
228
-
229
- //tobe put on prototype?
230
- function getBuffer(noCache) {
231
- const inputmask = this, maskset = this.maskset;
232
-
233
- if (maskset.buffer === undefined || noCache === true) {
234
- maskset.buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true);
235
- if (maskset._buffer === undefined) maskset._buffer = maskset.buffer.slice();
236
- }
237
- return maskset.buffer;
238
- }
239
-
240
- //tobe put on prototype?
241
- function getBufferTemplate() {
242
- const inputmask = this, maskset = this.maskset;
243
-
244
- if (maskset._buffer === undefined) {
245
- //generate template
246
- maskset._buffer = getMaskTemplate.call(inputmask, false, 1);
247
- if (maskset.buffer === undefined) maskset.buffer = maskset._buffer.slice();
248
- }
249
- return maskset._buffer;
250
- }
251
-
252
- //tobe put on prototype?
253
- function getLastValidPosition(closestTo, strict, validPositions) {
254
- const maskset = this.maskset;
255
-
256
- var before = -1,
257
- after = -1,
258
- valids = validPositions || maskset.validPositions; //for use in valhook ~ context switch
259
- if (closestTo === undefined) closestTo = -1;
260
- for (var posNdx in valids) {
261
- var psNdx = parseInt(posNdx);
262
- if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
263
- if (psNdx <= closestTo) before = psNdx;
264
- if (psNdx >= closestTo) after = psNdx;
265
- }
266
- }
267
- return (before === -1 || before == closestTo) ? after : after == -1 ? before : (closestTo - before) < (after - closestTo) ? before : after;
268
- }
269
-
270
- //tobe put on prototype?
271
- function isMask(pos, strict, fuzzy) {
272
- const inputmask = this, maskset = this.maskset;
273
-
274
- var test = getTestTemplate.call(inputmask, pos).match;
275
- if (test.def === "") test = getTest.call(inputmask, pos).match;
276
-
277
- if (test.static !== true) {
278
- return test.fn;
279
- }
280
- if (fuzzy === true && (maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].generatedInput !== true)) {
281
- return true;
282
- }
283
-
284
- if (strict !== true && pos > -1) {
285
- if (fuzzy) { //check on the number of tests
286
- var tests = getTests.call(inputmask, pos);
287
- return tests.length > (1 + (tests[tests.length - 1].match.def === "" ? 1 : 0));
288
- }
289
- //else based on the template
290
- var testTemplate = determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos));
291
- var testPlaceHolder = getPlaceholder.call(inputmask, pos, testTemplate.match);
292
- return testTemplate.match.def !== testPlaceHolder;
293
-
294
- }
295
- return false;
296
- }
297
-
298
- //tobe put on prototype?
299
- function resetMaskSet(soft) {
300
- const maskset = this.maskset;
301
-
302
- maskset.buffer = undefined;
303
- if (soft !== true) {
304
- maskset.validPositions = {};
305
- maskset.p = 0;
306
- }
307
- }
308
-
309
- //tobe put on prototype?
310
- function seekNext(pos, newBlock, fuzzy) {
311
- const inputmask = this;
312
-
313
- if (fuzzy === undefined) fuzzy = true;
314
- var position = pos + 1;
315
- while (getTest.call(inputmask, position).match.def !== "" &&
316
- ((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) ||
317
- (newBlock !== true && !isMask.call(inputmask, position, undefined, fuzzy)))) {
318
- position++;
319
- }
320
- return position;
321
- }
322
-
323
- //tobe put on prototype?
324
- function seekPrevious(pos, newBlock) {
325
- const inputmask = this;
326
-
327
- var position = pos - 1;
328
- if (pos <= 0) return 0;
329
-
330
- while (position > 0 &&
331
- ((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) ||
332
- (newBlock !== true && !isMask.call(inputmask, position, undefined, true)))) {
333
- position--;
334
- }
335
- return position;
336
- }
337
-
338
- //tobe put on prototype?
339
- function translatePosition(pos) {
340
- const inputmask = this,
341
- opts = this.opts,
342
- el = this.el;
343
-
344
- if (inputmask.isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) {
345
- pos = Math.abs(inputmask._valueGet().length - pos);
346
- }
347
- return pos;
348
- }