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.
- package/dist/example/App.example.d.ts +3 -0
- package/dist/{useMaskInput.test.d.ts → example/index.d.ts} +0 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -2
- package/dist/index.modern.js.map +1 -1
- package/dist/useMaskInput.d.ts +3 -3
- package/node_modules/inputmask/README.md +109 -79
- package/node_modules/inputmask/bundle.js +6 -5
- package/node_modules/inputmask/dist/inputmask.es6.js +5 -0
- package/node_modules/inputmask/dist/inputmask.js +2892 -2608
- package/node_modules/inputmask/dist/inputmask.min.js +3 -3
- package/node_modules/inputmask/dist/jquery.inputmask.js +2829 -2534
- package/node_modules/inputmask/dist/jquery.inputmask.min.js +3 -3
- package/node_modules/inputmask/lib/bindings/inputmask.es6.js +5 -0
- package/node_modules/inputmask/lib/canUseDOM.js +7 -0
- package/node_modules/inputmask/lib/defaults.js +101 -0
- package/node_modules/inputmask/lib/definitions.js +13 -0
- package/node_modules/inputmask/lib/dependencyLibs/data.js +8 -0
- package/node_modules/inputmask/lib/dependencyLibs/events.js +199 -0
- package/node_modules/inputmask/lib/dependencyLibs/extend.js +58 -0
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +4 -3
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +12 -343
- package/node_modules/inputmask/lib/environment.js +9 -0
- package/node_modules/inputmask/lib/escapeRegex.js +4 -0
- package/node_modules/inputmask/lib/eventhandlers.js +513 -0
- package/node_modules/inputmask/lib/eventruler.js +124 -0
- package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +552 -385
- package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +116 -97
- package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +594 -565
- package/node_modules/inputmask/lib/global/window.js +2 -6
- package/node_modules/inputmask/lib/inputHandling.js +252 -0
- package/node_modules/inputmask/lib/inputmask.js +129 -126
- package/node_modules/inputmask/lib/inputmaskElement.js +26 -20
- package/node_modules/inputmask/lib/jquery.inputmask.js +3 -1
- package/node_modules/inputmask/lib/keycode.json +6 -1
- package/node_modules/inputmask/lib/mask-lexer.js +467 -0
- package/node_modules/inputmask/lib/mask.js +244 -0
- package/node_modules/inputmask/lib/masktoken.js +13 -0
- package/node_modules/inputmask/lib/polyfills/Array.includes.js +48 -0
- package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +7 -0
- package/node_modules/inputmask/lib/positioning.js +348 -0
- package/node_modules/inputmask/lib/validation-tests.js +597 -0
- package/node_modules/inputmask/lib/validation.js +664 -0
- package/node_modules/inputmask/package.json +41 -71
- package/package.json +40 -43
- package/node_modules/inputmask/CHANGELOG.md +0 -714
- package/node_modules/inputmask/index.js +0 -1
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jqlite.js +0 -170
- package/node_modules/inputmask/lib/maskScope.js +0 -2498
- package/node_modules/inputmask/lib/maskset.js +0 -466
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
define(function () {
|
|
3
|
-
return typeof window !== "undefined" ? window : new (eval("require('jsdom').JSDOM"))("").window;
|
|
4
|
-
});
|
|
5
|
-
else if (typeof exports === "object")
|
|
6
|
-
module.exports = typeof window !== "undefined" ? window : new (eval("require('jsdom').JSDOM"))("").window;
|
|
1
|
+
import canUseDOM from "../canUseDOM";
|
|
7
2
|
|
|
3
|
+
export default canUseDOM ? window : {};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import keyCode from "./keycode.json";
|
|
2
|
+
import {getMaskTemplate, getPlaceholder, getTest} from "./validation-tests";
|
|
3
|
+
import {
|
|
4
|
+
caret,
|
|
5
|
+
determineNewCaretPosition,
|
|
6
|
+
getBuffer, getBufferTemplate,
|
|
7
|
+
getLastValidPosition,
|
|
8
|
+
isMask,
|
|
9
|
+
resetMaskSet,
|
|
10
|
+
seekNext
|
|
11
|
+
} from "./positioning";
|
|
12
|
+
import {isComplete, refreshFromBuffer} from "./validation";
|
|
13
|
+
import {ie} from "./environment";
|
|
14
|
+
import {EventHandlers} from "./eventhandlers";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export {applyInputValue, clearOptionalTail, checkVal, HandleNativePlaceholder, unmaskedvalue, writeBuffer};
|
|
18
|
+
|
|
19
|
+
function applyInputValue(input, value) {
|
|
20
|
+
const inputmask = input ? input.inputmask : this, opts = inputmask.opts;
|
|
21
|
+
|
|
22
|
+
input.inputmask.refreshValue = false;
|
|
23
|
+
if (typeof opts.onBeforeMask === "function") value = opts.onBeforeMask.call(inputmask, value, opts) || value;
|
|
24
|
+
value = value.toString().split("");
|
|
25
|
+
checkVal(input, true, false, value);
|
|
26
|
+
inputmask.undoValue = inputmask._valueGet(true);
|
|
27
|
+
if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate.call(inputmask).join("") && getLastValidPosition.call(inputmask) === -1) {
|
|
28
|
+
input.inputmask._valueSet("");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//todo put on prototype?
|
|
33
|
+
function clearOptionalTail(buffer) {
|
|
34
|
+
const inputmask = this;
|
|
35
|
+
|
|
36
|
+
buffer.length = 0;
|
|
37
|
+
var template = getMaskTemplate.call(inputmask, true, 0, true, undefined, true), lmnt;
|
|
38
|
+
while ((lmnt = template.shift()) !== undefined) buffer.push(lmnt);
|
|
39
|
+
return buffer;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
|
|
43
|
+
const inputmask = input ? input.inputmask : this,
|
|
44
|
+
maskset = inputmask.maskset,
|
|
45
|
+
opts = inputmask.opts, $ = inputmask.dependencyLib;
|
|
46
|
+
|
|
47
|
+
var inputValue = nptvl.slice(),
|
|
48
|
+
charCodes = "",
|
|
49
|
+
initialNdx = -1,
|
|
50
|
+
result = undefined, skipOptionalPartCharacter = opts.skipOptionalPartCharacter;
|
|
51
|
+
opts.skipOptionalPartCharacter = ""; //see issue #2311
|
|
52
|
+
|
|
53
|
+
function isTemplateMatch(ndx, charCodes) {
|
|
54
|
+
var targetTemplate = getMaskTemplate.call(inputmask, true, 0).slice(ndx, seekNext.call(inputmask, ndx, false, false)).join("").replace(/'/g, ""),
|
|
55
|
+
charCodeNdx = targetTemplate.indexOf(charCodes);
|
|
56
|
+
//strip spaces from targetTemplate
|
|
57
|
+
while (charCodeNdx > 0 && targetTemplate[charCodeNdx - 1] === " ") charCodeNdx--;
|
|
58
|
+
|
|
59
|
+
var match = charCodeNdx === 0 && !isMask.call(inputmask, ndx)
|
|
60
|
+
&& (getTest.call(inputmask, ndx).match.nativeDef === charCodes.charAt(0)
|
|
61
|
+
|| (getTest.call(inputmask, ndx).match.static === true && getTest.call(inputmask, ndx).match.nativeDef === ("'" + charCodes.charAt(0)))
|
|
62
|
+
|| (getTest.call(inputmask, ndx).match.nativeDef === " " && (getTest.call(inputmask, ndx + 1).match.nativeDef === charCodes.charAt(0)
|
|
63
|
+
|| (getTest.call(inputmask, ndx + 1).match.static === true && getTest.call(inputmask, ndx + 1).match.nativeDef === ("'" + charCodes.charAt(0))))));
|
|
64
|
+
|
|
65
|
+
if (!match && charCodeNdx > 0 && !isMask.call(inputmask, ndx, false, true)) {
|
|
66
|
+
var nextPos = seekNext.call(inputmask, ndx);
|
|
67
|
+
if (inputmask.caretPos.begin < nextPos) {
|
|
68
|
+
inputmask.caretPos = {begin: nextPos};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return match;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
resetMaskSet.call(inputmask);
|
|
75
|
+
maskset.tests = {}; //reset tests ~ possible after alternating
|
|
76
|
+
initialNdx = opts.radixPoint ? determineNewCaretPosition.call(inputmask, {
|
|
77
|
+
begin: 0,
|
|
78
|
+
end: 0
|
|
79
|
+
}, false, opts.__financeInput === false ? "radixFocus" : undefined).begin : 0;
|
|
80
|
+
maskset.p = initialNdx;
|
|
81
|
+
inputmask.caretPos = {begin: initialNdx};
|
|
82
|
+
|
|
83
|
+
var staticMatches = [], prevCaretPos = inputmask.caretPos;
|
|
84
|
+
inputValue.forEach(function (charCode, ndx) {
|
|
85
|
+
if (charCode !== undefined) { //inputfallback strips some elements out of the inputarray. $.each logically presents them as undefined
|
|
86
|
+
/*if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true) &&
|
|
87
|
+
isValid.call(inputmask, ndx, inputValue[ndx], true, undefined, true, true) === false) {
|
|
88
|
+
inputmask.caretPos.begin++;
|
|
89
|
+
} else*/
|
|
90
|
+
{
|
|
91
|
+
var keypress = new $.Event("_checkval");
|
|
92
|
+
keypress.keyCode = charCode.toString().charCodeAt(0);
|
|
93
|
+
charCodes += charCode;
|
|
94
|
+
var lvp = getLastValidPosition.call(inputmask, undefined, true);
|
|
95
|
+
if (!isTemplateMatch(initialNdx, charCodes)) {
|
|
96
|
+
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, inputmask.caretPos.begin);
|
|
97
|
+
|
|
98
|
+
if (result) {
|
|
99
|
+
initialNdx = inputmask.caretPos.begin + 1;
|
|
100
|
+
charCodes = "";
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, lvp + 1);
|
|
104
|
+
}
|
|
105
|
+
if (result) {
|
|
106
|
+
if (result.pos !== undefined && maskset.validPositions[result.pos] && maskset.validPositions[result.pos].match.static === true && maskset.validPositions[result.pos].alternation === undefined) {
|
|
107
|
+
staticMatches.push(result.pos);
|
|
108
|
+
if (!inputmask.isRTL) {
|
|
109
|
+
result.forwardPosition = result.pos + 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
writeBuffer.call(inputmask, undefined, getBuffer.call(inputmask), result.forwardPosition, keypress, false);
|
|
113
|
+
inputmask.caretPos = {begin: result.forwardPosition, end: result.forwardPosition};
|
|
114
|
+
prevCaretPos = inputmask.caretPos;
|
|
115
|
+
} else {
|
|
116
|
+
if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true)) {
|
|
117
|
+
inputmask.caretPos.begin++;
|
|
118
|
+
} else inputmask.caretPos = prevCaretPos; //restore the caret position from before the failed validation
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (staticMatches.length > 0) {
|
|
124
|
+
var sndx, validPos, nextValid = seekNext.call(inputmask, -1, undefined, false);
|
|
125
|
+
if ((!isComplete.call(inputmask, getBuffer.call(inputmask)) && staticMatches.length <= nextValid)
|
|
126
|
+
|| (isComplete.call(inputmask, getBuffer.call(inputmask)) && staticMatches.length > 0 && (staticMatches.length !== nextValid && staticMatches[0] === 0))) { //should check if is sequence starting from 0
|
|
127
|
+
var nextSndx = nextValid;
|
|
128
|
+
while ((sndx = staticMatches.shift()) !== undefined) {
|
|
129
|
+
var keypress = new $.Event("_checkval");
|
|
130
|
+
validPos = maskset.validPositions[sndx];
|
|
131
|
+
validPos.generatedInput = true;
|
|
132
|
+
keypress.keyCode = validPos.input.charCodeAt(0);
|
|
133
|
+
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, nextSndx);
|
|
134
|
+
if (result && result.pos !== undefined && result.pos !== sndx && maskset.validPositions[result.pos] && maskset.validPositions[result.pos].match.static === true) {
|
|
135
|
+
staticMatches.push(result.pos);
|
|
136
|
+
} else if (!result) break;
|
|
137
|
+
nextSndx++;
|
|
138
|
+
}
|
|
139
|
+
} else { //mark al statics as generated
|
|
140
|
+
// while ((sndx = staticMatches.pop())) {
|
|
141
|
+
// validPos = maskset.validPositions[sndx];
|
|
142
|
+
// if (validPos) {
|
|
143
|
+
// validPos.generatedInput = true;
|
|
144
|
+
// }
|
|
145
|
+
// }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (writeOut) {
|
|
149
|
+
writeBuffer.call(
|
|
150
|
+
inputmask,
|
|
151
|
+
input,
|
|
152
|
+
getBuffer.call(inputmask), result ? result.forwardPosition : inputmask.caretPos.begin,
|
|
153
|
+
initiatingEvent || new $.Event("checkval"),
|
|
154
|
+
initiatingEvent && ((initiatingEvent.type === "input" && inputmask.undoValue !== getBuffer.call(inputmask).join("")) || initiatingEvent.type === "paste"));
|
|
155
|
+
// for (var vndx in maskset.validPositions) {
|
|
156
|
+
// if (maskset.validPositions[vndx].match.generated !== true) { //only remove non forced generated
|
|
157
|
+
// delete maskset.validPositions[vndx].generatedInput; //clear generated markings ~ consider initializing with a value as fully typed
|
|
158
|
+
// }
|
|
159
|
+
// }
|
|
160
|
+
}
|
|
161
|
+
opts.skipOptionalPartCharacter = skipOptionalPartCharacter;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function HandleNativePlaceholder(npt, value) {
|
|
165
|
+
const inputmask = npt ? npt.inputmask : this;
|
|
166
|
+
|
|
167
|
+
if (ie) {
|
|
168
|
+
if (npt.inputmask._valueGet() !== value && (npt.placeholder !== value || npt.placeholder === "")) {
|
|
169
|
+
var buffer = getBuffer.call(inputmask).slice(),
|
|
170
|
+
nptValue = npt.inputmask._valueGet();
|
|
171
|
+
if (nptValue !== value) {
|
|
172
|
+
var lvp = getLastValidPosition.call(inputmask);
|
|
173
|
+
if (lvp === -1 && nptValue === getBufferTemplate.call(inputmask).join("")) {
|
|
174
|
+
buffer = [];
|
|
175
|
+
} else if (lvp !== -1) { //clearout optional tail of the mask
|
|
176
|
+
clearOptionalTail.call(inputmask, buffer);
|
|
177
|
+
}
|
|
178
|
+
writeBuffer(npt, buffer);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (npt.placeholder !== value) {
|
|
182
|
+
npt.placeholder = value;
|
|
183
|
+
if (npt.placeholder === "") npt.removeAttribute("placeholder");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function unmaskedvalue(input) {
|
|
188
|
+
const inputmask = input ? input.inputmask : this,
|
|
189
|
+
opts = inputmask.opts,
|
|
190
|
+
maskset = inputmask.maskset;
|
|
191
|
+
|
|
192
|
+
if (input) {
|
|
193
|
+
if (input.inputmask === undefined) {
|
|
194
|
+
return input.value;
|
|
195
|
+
}
|
|
196
|
+
if (input.inputmask && input.inputmask.refreshValue) { //forced refresh from the value form.reset
|
|
197
|
+
applyInputValue(input, input.inputmask._valueGet(true));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
var umValue = [],
|
|
201
|
+
vps = maskset.validPositions;
|
|
202
|
+
for (var pndx in vps) {
|
|
203
|
+
if (vps[pndx] && vps[pndx].match && (vps[pndx].match.static != true || (Array.isArray(maskset.metadata) && vps[pndx].generatedInput !== true))) {
|
|
204
|
+
//only include generated input with multiple masks (check on metadata)
|
|
205
|
+
umValue.push(vps[pndx].input);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
var unmaskedValue = umValue.length === 0 ? "" : (inputmask.isRTL ? umValue.reverse() : umValue).join("");
|
|
209
|
+
if (typeof opts.onUnMask === "function") {
|
|
210
|
+
var bufferValue = (inputmask.isRTL ? getBuffer.call(inputmask).slice().reverse() : getBuffer.call(inputmask)).join("");
|
|
211
|
+
unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts);
|
|
212
|
+
}
|
|
213
|
+
return unmaskedValue;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
|
|
217
|
+
const inputmask = input ? input.inputmask : this,
|
|
218
|
+
opts = inputmask.opts,
|
|
219
|
+
$ = inputmask.dependencyLib;
|
|
220
|
+
|
|
221
|
+
if (event && typeof opts.onBeforeWrite === "function") {
|
|
222
|
+
// buffer = buffer.slice(); //prevent uncontrolled manipulation of the internal buffer
|
|
223
|
+
var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);
|
|
224
|
+
if (result) {
|
|
225
|
+
if (result.refreshFromBuffer) {
|
|
226
|
+
var refresh = result.refreshFromBuffer;
|
|
227
|
+
refreshFromBuffer.call(inputmask, refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
|
|
228
|
+
buffer = getBuffer.call(inputmask, true);
|
|
229
|
+
}
|
|
230
|
+
if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (input !== undefined) {
|
|
234
|
+
input.inputmask._valueSet(buffer.join(""));
|
|
235
|
+
if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
|
|
236
|
+
// console.log(caretPos);
|
|
237
|
+
caret.call(inputmask, input, caretPos, undefined, undefined, (event !== undefined && event.type === "keydown" && (event.keyCode === keyCode.DELETE || event.keyCode === keyCode.BACKSPACE)));
|
|
238
|
+
}
|
|
239
|
+
if (triggerEvents === true) {
|
|
240
|
+
var $input = $(input), nptVal = input.inputmask._valueGet();
|
|
241
|
+
input.inputmask.skipInputEvent = true;
|
|
242
|
+
$input.trigger("input");
|
|
243
|
+
setTimeout(function () { //timeout needed for IE
|
|
244
|
+
if (nptVal === getBufferTemplate.call(inputmask).join("")) {
|
|
245
|
+
$input.trigger("cleared");
|
|
246
|
+
} else if (isComplete.call(inputmask, buffer) === true) {
|
|
247
|
+
$input.trigger("complete");
|
|
248
|
+
}
|
|
249
|
+
}, 0);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -4,27 +4,42 @@
|
|
|
4
4
|
* Copyright (c) Robin Herbots
|
|
5
5
|
* Licensed under the MIT license
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
generateMaskSet = require("./maskset").generateMaskSet,
|
|
10
|
-
analyseMask = require("./maskset").analyseMask,
|
|
11
|
-
maskScope = require("./maskScope");
|
|
7
|
+
import "./polyfills/Object.getPrototypeOf";
|
|
8
|
+
import "./polyfills/Array.includes";
|
|
12
9
|
|
|
10
|
+
import {mask} from "./mask";
|
|
11
|
+
import $ from "./dependencyLibs/inputmask.dependencyLib";
|
|
12
|
+
import window from "./global/window";
|
|
13
|
+
import {generateMaskSet, analyseMask} from "./mask-lexer";
|
|
14
|
+
import {getMaskTemplate} from "./validation-tests";
|
|
15
|
+
import {determineLastRequiredPosition, getBuffer, getBufferTemplate, isMask} from "./positioning";
|
|
16
|
+
import {isComplete} from "./validation";
|
|
17
|
+
import {checkVal, unmaskedvalue} from "./inputHandling";
|
|
18
|
+
import {EventRuler} from "./eventruler";
|
|
19
|
+
import definitions from "./definitions";
|
|
20
|
+
import defaults from "./defaults";
|
|
21
|
+
import canUseDOM from "./canUseDOM";
|
|
22
|
+
|
|
23
|
+
const document = window.document, dataKey = "_inputmask_opts";
|
|
13
24
|
|
|
14
25
|
function Inputmask(alias, options, internal) {
|
|
26
|
+
if (!canUseDOM) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
//allow instanciating without new
|
|
16
31
|
if (!(this instanceof Inputmask)) {
|
|
17
32
|
return new Inputmask(alias, options, internal);
|
|
18
33
|
}
|
|
19
34
|
|
|
35
|
+
this.dependencyLib = $;
|
|
20
36
|
this.el = undefined;
|
|
21
37
|
this.events = {};
|
|
22
38
|
this.maskset = undefined;
|
|
23
|
-
this.refreshValue = false; //indicate a refresh from the inputvalue is needed (form.reset)
|
|
24
39
|
|
|
25
40
|
if (internal !== true) {
|
|
26
41
|
//init options
|
|
27
|
-
if (
|
|
42
|
+
if (Object.prototype.toString.call(alias) === "[object Object]") {
|
|
28
43
|
options = alias;
|
|
29
44
|
} else {
|
|
30
45
|
options = options || {};
|
|
@@ -34,96 +49,39 @@ function Inputmask(alias, options, internal) {
|
|
|
34
49
|
this.noMasksCache = options && options.definitions !== undefined;
|
|
35
50
|
this.userOptions = options || {}; //user passed options
|
|
36
51
|
resolveAlias(this.opts.alias, options, this.opts);
|
|
37
|
-
this.isRTL = this.opts.numericInput;
|
|
38
52
|
}
|
|
53
|
+
|
|
54
|
+
//maskscope properties
|
|
55
|
+
this.refreshValue = false; //indicate a refresh from the inputvalue is needed (form.reset)
|
|
56
|
+
this.undoValue = undefined;
|
|
57
|
+
this.$el = undefined;
|
|
58
|
+
this.skipKeyPressEvent = false; //Safari 5.1.x - modal dialog fires keypress twice workaround
|
|
59
|
+
this.skipInputEvent = false; //skip when triggered from within inputmask
|
|
60
|
+
this.validationEvent = false;
|
|
61
|
+
this.ignorable = false;
|
|
62
|
+
this.maxLength;
|
|
63
|
+
this.mouseEnter = false;
|
|
64
|
+
this.originalPlaceholder = undefined; //needed for FF
|
|
65
|
+
this.isComposing = false; //keydowncode == 229 compositionevent fallback
|
|
39
66
|
}
|
|
40
67
|
|
|
41
68
|
Inputmask.prototype = {
|
|
42
69
|
dataAttribute: "data-inputmask", //data attribute prefix used for attribute binding
|
|
43
70
|
//options default
|
|
44
|
-
defaults:
|
|
45
|
-
|
|
46
|
-
placeholder: "_",
|
|
47
|
-
optionalmarker: ["[", "]"],
|
|
48
|
-
quantifiermarker: ["{", "}"],
|
|
49
|
-
groupmarker: ["(", ")"],
|
|
50
|
-
alternatormarker: "|",
|
|
51
|
-
escapeChar: "\\",
|
|
52
|
-
mask: null, //needs tobe null instead of undefined as the extend method does not consider props with the undefined value
|
|
53
|
-
regex: null, //regular expression as a mask
|
|
54
|
-
oncomplete: $.noop, //executes when the mask is complete
|
|
55
|
-
onincomplete: $.noop, //executes when the mask is incomplete and focus is lost
|
|
56
|
-
oncleared: $.noop, //executes when the mask is cleared
|
|
57
|
-
repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
|
|
58
|
-
greedy: false, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
|
|
59
|
-
autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
|
|
60
|
-
removeMaskOnSubmit: false, //remove the mask before submitting the form.
|
|
61
|
-
clearMaskOnLostFocus: true,
|
|
62
|
-
insertMode: true, //insert the input or overwrite the input
|
|
63
|
-
insertModeVisual: true, //show selected caret when insertmode = false
|
|
64
|
-
clearIncomplete: false, //clear the incomplete input on blur
|
|
65
|
-
alias: null,
|
|
66
|
-
onKeyDown: $.noop, //callback to implement autocomplete on certain keys for example. args => event, buffer, caretPos, opts
|
|
67
|
-
onBeforeMask: null, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
|
|
68
|
-
onBeforePaste: function (pastedValue, opts) {
|
|
69
|
-
return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue;
|
|
70
|
-
}, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
|
|
71
|
-
onBeforeWrite: null, //executes before writing to the masked element. args => event, opts
|
|
72
|
-
onUnMask: null, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
|
|
73
|
-
showMaskOnFocus: true, //show the mask-placeholder when the input has focus
|
|
74
|
-
showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
|
|
75
|
-
onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: key, result, opts
|
|
76
|
-
skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
|
|
77
|
-
numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
|
|
78
|
-
rightAlign: false, //align to the right
|
|
79
|
-
undoOnEscape: true, //pressing escape reverts the value to the value before focus
|
|
80
|
-
//numeric basic properties
|
|
81
|
-
radixPoint: "", //".", // | ","
|
|
82
|
-
_radixDance: false, //dance around the radixPoint
|
|
83
|
-
groupSeparator: "", //",", // | "."
|
|
84
|
-
//numeric basic properties
|
|
85
|
-
keepStatic: null, //try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible
|
|
86
|
-
positionCaretOnTab: true, //when enabled the caret position is set after the latest valid position on TAB
|
|
87
|
-
tabThrough: false, //allows for tabbing through the different parts of the masked field
|
|
88
|
-
supportsInputType: ["text", "tel", "url", "password", "search"], //list with the supported input types
|
|
89
|
-
//specify keyCodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
|
|
90
|
-
ignorables: [8, 9, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 0, 229],
|
|
91
|
-
isComplete: null, //override for isComplete - args => buffer, opts - return true || false
|
|
92
|
-
preValidation: null, //hook to preValidate the input. Usefull for validating regardless the definition. args => buffer, pos, char, isSelection, opts, maskset, caretPos, strict => return true/false/command object
|
|
93
|
-
postValidation: null, //hook to postValidate the result from isValid. Usefull for validating the entry as a whole. args => buffer, pos, c, currentResult, opts, maskset, strict => return true/false/json
|
|
94
|
-
staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
|
|
95
|
-
jitMasking: false, //just in time masking ~ only mask while typing, can n (number), true or false
|
|
96
|
-
nullable: true, //return nothing instead of the buffertemplate when the user hasn't entered anything.
|
|
97
|
-
inputEventOnly: false, //dev option - testing inputfallback behavior
|
|
98
|
-
noValuePatching: false, //disable value property patching
|
|
99
|
-
positionCaretOnClick: "lvp", //none, lvp (based on the last valid position (default), radixFocus (position caret to radixpoint on initial click), select (select the whole input), ignore (ignore the click and continue the mask)
|
|
100
|
-
casing: null, //mask-level casing. Options: null, "upper", "lower" or "title" or callback args => elem, test, pos, validPositions return charValue
|
|
101
|
-
inputmode: "text", //specify the inputmode
|
|
102
|
-
importDataAttributes: true, //import data-inputmask attributes
|
|
103
|
-
shiftPositions: true //shift position of the mask entries on entry and deletion.
|
|
104
|
-
},
|
|
105
|
-
definitions: {
|
|
106
|
-
"9": { //\uFF11-\uFF19 #1606
|
|
107
|
-
validator: "[0-9\uFF11-\uFF19]",
|
|
108
|
-
definitionSymbol: "*"
|
|
109
|
-
},
|
|
110
|
-
"a": { //\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5 #76
|
|
111
|
-
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
|
|
112
|
-
definitionSymbol: "*"
|
|
113
|
-
},
|
|
114
|
-
"*": {
|
|
115
|
-
validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]"
|
|
116
|
-
}
|
|
117
|
-
},
|
|
71
|
+
defaults: defaults,
|
|
72
|
+
definitions: definitions,
|
|
118
73
|
aliases: {}, //aliases definitions
|
|
119
74
|
masksCache: {},
|
|
75
|
+
get isRTL() {
|
|
76
|
+
return this.opts.isRTL || this.opts.numericInput;
|
|
77
|
+
},
|
|
120
78
|
mask: function (elems) {
|
|
121
79
|
var that = this;
|
|
122
80
|
if (typeof elems === "string") {
|
|
123
81
|
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
124
82
|
}
|
|
125
|
-
elems = elems.nodeName ? [elems] : elems;
|
|
126
|
-
|
|
83
|
+
elems = elems.nodeName ? [elems] : (Array.isArray(elems) ? elems : Array.from(elems));
|
|
84
|
+
elems.forEach(function (el, ndx) {
|
|
127
85
|
var scopedOpts = $.extend(true, {}, that.opts);
|
|
128
86
|
if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
|
|
129
87
|
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
|
|
@@ -137,15 +95,13 @@ Inputmask.prototype = {
|
|
|
137
95
|
el.inputmask.opts = scopedOpts;
|
|
138
96
|
el.inputmask.noMasksCache = that.noMasksCache;
|
|
139
97
|
el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
|
|
140
|
-
el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
|
|
98
|
+
// el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
|
|
141
99
|
el.inputmask.el = el;
|
|
100
|
+
el.inputmask.$el = $(el);
|
|
142
101
|
el.inputmask.maskset = maskset;
|
|
143
102
|
|
|
144
|
-
$.data(el,
|
|
145
|
-
|
|
146
|
-
maskScope.call(el.inputmask, {
|
|
147
|
-
"action": "mask"
|
|
148
|
-
});
|
|
103
|
+
$.data(el, dataKey, that.userOptions);
|
|
104
|
+
mask.call(el.inputmask);
|
|
149
105
|
}
|
|
150
106
|
}
|
|
151
107
|
});
|
|
@@ -165,51 +121,101 @@ Inputmask.prototype = {
|
|
|
165
121
|
},
|
|
166
122
|
unmaskedvalue: function (value) {
|
|
167
123
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
168
|
-
|
|
169
|
-
"
|
|
170
|
-
|
|
171
|
-
|
|
124
|
+
if (this.el === undefined || value !== undefined) {
|
|
125
|
+
var valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
|
|
126
|
+
checkVal.call(this, undefined, false, false, valueBuffer);
|
|
127
|
+
if (typeof this.opts.onBeforeWrite === "function") this.opts.onBeforeWrite.call(this, undefined, getBuffer.call(this), 0, this.opts);
|
|
128
|
+
}
|
|
129
|
+
return unmaskedvalue.call(this, this.el);
|
|
172
130
|
},
|
|
173
131
|
remove: function () {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
132
|
+
if (this.el) {
|
|
133
|
+
$.data(this.el, dataKey, null); //invalidate
|
|
134
|
+
//writeout the value
|
|
135
|
+
var cv = this.opts.autoUnmask ? unmaskedvalue(this.el) : this._valueGet(this.opts.autoUnmask);
|
|
136
|
+
if (cv !== getBufferTemplate.call(this).join("")) this._valueSet(cv, this.opts.autoUnmask); else this._valueSet("");
|
|
137
|
+
//unbind all events
|
|
138
|
+
EventRuler.off(this.el);
|
|
139
|
+
|
|
140
|
+
//restore the value property
|
|
141
|
+
var valueProperty;
|
|
142
|
+
if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
|
|
143
|
+
valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.el), "value");
|
|
144
|
+
if (valueProperty) {
|
|
145
|
+
if (this.__valueGet) {
|
|
146
|
+
Object.defineProperty(this.el, "value", {
|
|
147
|
+
get: this.__valueGet,
|
|
148
|
+
set: this.__valueSet,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} else if (document.__lookupGetter__ && this.el.__lookupGetter__("value")) {
|
|
154
|
+
if (this.__valueGet) {
|
|
155
|
+
this.el.__defineGetter__("value", this.__valueGet);
|
|
156
|
+
this.el.__defineSetter__("value", this.__valueSet);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//clear data
|
|
160
|
+
this.el.inputmask = undefined;
|
|
161
|
+
}
|
|
162
|
+
return this.el;
|
|
177
163
|
},
|
|
178
164
|
getemptymask: function () { //return the default (empty) mask value, usefull for setting the default value in validation
|
|
179
165
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
180
|
-
return
|
|
181
|
-
"action": "getemptymask"
|
|
182
|
-
});
|
|
166
|
+
return getBufferTemplate.call(this).join("");
|
|
183
167
|
},
|
|
184
168
|
hasMaskedValue: function () { //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
|
|
185
169
|
return !this.opts.autoUnmask;
|
|
186
170
|
},
|
|
187
171
|
isComplete: function () {
|
|
188
172
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
189
|
-
return
|
|
190
|
-
"action": "isComplete"
|
|
191
|
-
});
|
|
173
|
+
return isComplete.call(this, getBuffer.call(this));
|
|
192
174
|
},
|
|
193
175
|
getmetadata: function () { //return mask metadata if exists
|
|
194
176
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
177
|
+
if (Array.isArray(this.maskset.metadata)) {
|
|
178
|
+
var maskTarget = getMaskTemplate.call(this, true, 0, false).join("");
|
|
179
|
+
this.maskset.metadata.forEach(function (mtdt) {
|
|
180
|
+
if (mtdt.mask === maskTarget) {
|
|
181
|
+
maskTarget = mtdt;
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return true;
|
|
186
|
+
});
|
|
187
|
+
return maskTarget;
|
|
188
|
+
}
|
|
189
|
+
return this.maskset.metadata;
|
|
198
190
|
},
|
|
199
191
|
isValid: function (value) {
|
|
200
192
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
201
|
-
|
|
202
|
-
"
|
|
203
|
-
|
|
204
|
-
}
|
|
193
|
+
if (value) {
|
|
194
|
+
var valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
|
|
195
|
+
checkVal.call(this, undefined, true, false, valueBuffer);
|
|
196
|
+
} else {
|
|
197
|
+
value = this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join("");
|
|
198
|
+
}
|
|
199
|
+
var buffer = getBuffer.call(this);
|
|
200
|
+
var rl = determineLastRequiredPosition.call(this),
|
|
201
|
+
lmib = buffer.length - 1;
|
|
202
|
+
for (; lmib > rl; lmib--) {
|
|
203
|
+
if (isMask.call(this, lmib)) break;
|
|
204
|
+
}
|
|
205
|
+
buffer.splice(rl, lmib + 1 - rl);
|
|
206
|
+
|
|
207
|
+
return isComplete.call(this, buffer) && value === (this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join(""));
|
|
208
|
+
|
|
205
209
|
},
|
|
206
210
|
format: function (value, metadata) {
|
|
207
211
|
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
let valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
|
|
213
|
+
checkVal.call(this, undefined, true, false, valueBuffer);
|
|
214
|
+
let formattedValue = this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join("");
|
|
215
|
+
return metadata ? {
|
|
216
|
+
value: formattedValue,
|
|
217
|
+
metadata: this.getmetadata()
|
|
218
|
+
} : formattedValue;
|
|
213
219
|
},
|
|
214
220
|
setValue: function (value) {
|
|
215
221
|
if (this.el) {
|
|
@@ -227,16 +233,17 @@ function resolveAlias(aliasStr, options, opts) {
|
|
|
227
233
|
$.extend(true, opts, options); //reapply extra given options
|
|
228
234
|
return true;
|
|
229
235
|
} else //alias not found - try as mask
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
if (opts.mask === null) {
|
|
237
|
+
opts.mask = aliasStr;
|
|
238
|
+
}
|
|
233
239
|
|
|
234
240
|
return false;
|
|
235
241
|
}
|
|
236
242
|
|
|
237
243
|
function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
|
|
238
244
|
function importOption(option, optionData) {
|
|
239
|
-
|
|
245
|
+
const attrOption = dataAttribute === "" ? option : dataAttribute + "-" + option;
|
|
246
|
+
optionData = optionData !== undefined ? optionData : npt.getAttribute(attrOption);
|
|
240
247
|
if (optionData !== null) {
|
|
241
248
|
if (typeof optionData === "string") {
|
|
242
249
|
if (option.indexOf("on") === 0) {
|
|
@@ -327,7 +334,7 @@ Inputmask.remove = function (elems) {
|
|
|
327
334
|
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
328
335
|
}
|
|
329
336
|
elems = elems.nodeName ? [elems] : elems;
|
|
330
|
-
|
|
337
|
+
elems.forEach(function (el) {
|
|
331
338
|
if (el.inputmask) el.inputmask.remove();
|
|
332
339
|
});
|
|
333
340
|
};
|
|
@@ -336,17 +343,13 @@ Inputmask.setValue = function (elems, value) {
|
|
|
336
343
|
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
337
344
|
}
|
|
338
345
|
elems = elems.nodeName ? [elems] : elems;
|
|
339
|
-
|
|
346
|
+
elems.forEach(function (el) {
|
|
340
347
|
if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [value]);
|
|
341
348
|
});
|
|
342
349
|
};
|
|
343
|
-
var escapeRegexRegex = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^"].join("|\\") + ")", "gim");
|
|
344
|
-
Inputmask.escapeRegex = function (str) {
|
|
345
|
-
return str.replace(escapeRegexRegex, "\\$1");
|
|
346
|
-
};
|
|
347
350
|
|
|
348
351
|
Inputmask.dependencyLib = $;
|
|
349
352
|
|
|
350
353
|
//make inputmask available
|
|
351
354
|
window.Inputmask = Inputmask;
|
|
352
|
-
|
|
355
|
+
export default Inputmask;
|