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.
- package/README.md +13 -19
- package/dist/index.cjs +191 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +34 -3
- package/dist/index.js +184 -1
- package/dist/index.js.map +1 -1
- package/package.json +49 -48
- package/src/index.tsx +3 -2
- package/src/types.ts +6 -0
- package/src/useMaskInput.ts +12 -9
- package/src/utils.spec.ts +14 -0
- package/src/utils.ts +23 -0
- package/src/withHookFormMask.ts +8 -17
- package/src/withMask.ts +5 -6
- package/dist/example/App.example.d.ts +0 -3
- package/dist/example/index.d.ts +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/useMaskInput.d.ts +0 -9
- package/dist/withHookFormMask.d.ts +0 -16
- package/dist/withMask.d.ts +0 -3
- package/node_modules/inputmask/LICENSE.txt +0 -7
- package/node_modules/inputmask/README.md +0 -1279
- package/node_modules/inputmask/bundle.js +0 -6
- package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
- package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
- package/node_modules/inputmask/dist/inputmask.js +0 -3031
- package/node_modules/inputmask/dist/inputmask.min.js +0 -8
- package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
- package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
- package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
- package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
- package/node_modules/inputmask/lib/canUseDOM.js +0 -7
- package/node_modules/inputmask/lib/defaults.js +0 -101
- package/node_modules/inputmask/lib/definitions.js +0 -13
- package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
- package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
- package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
- package/node_modules/inputmask/lib/environment.js +0 -9
- package/node_modules/inputmask/lib/escapeRegex.js +0 -4
- package/node_modules/inputmask/lib/eventhandlers.js +0 -513
- package/node_modules/inputmask/lib/eventruler.js +0 -124
- package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
- package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
- package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
- package/node_modules/inputmask/lib/global/window.js +0 -3
- package/node_modules/inputmask/lib/inputHandling.js +0 -252
- package/node_modules/inputmask/lib/inputmask.js +0 -355
- package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
- package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
- package/node_modules/inputmask/lib/keycode.json +0 -25
- package/node_modules/inputmask/lib/mask-lexer.js +0 -467
- package/node_modules/inputmask/lib/mask.js +0 -244
- package/node_modules/inputmask/lib/masktoken.js +0 -13
- package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
- package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
- package/node_modules/inputmask/lib/positioning.js +0 -348
- package/node_modules/inputmask/lib/validation-tests.js +0 -597
- package/node_modules/inputmask/lib/validation.js +0 -664
- package/node_modules/inputmask/package.json +0 -60
- package/src/example/App.example.tsx +0 -68
- package/src/example/index.tsx +0 -5
|
@@ -1,252 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Input Mask Core
|
|
3
|
-
* http://github.com/RobinHerbots/jquery.inputmask
|
|
4
|
-
* Copyright (c) Robin Herbots
|
|
5
|
-
* Licensed under the MIT license
|
|
6
|
-
*/
|
|
7
|
-
import "./polyfills/Object.getPrototypeOf";
|
|
8
|
-
import "./polyfills/Array.includes";
|
|
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";
|
|
24
|
-
|
|
25
|
-
function Inputmask(alias, options, internal) {
|
|
26
|
-
if (!canUseDOM) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//allow instanciating without new
|
|
31
|
-
if (!(this instanceof Inputmask)) {
|
|
32
|
-
return new Inputmask(alias, options, internal);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.dependencyLib = $;
|
|
36
|
-
this.el = undefined;
|
|
37
|
-
this.events = {};
|
|
38
|
-
this.maskset = undefined;
|
|
39
|
-
|
|
40
|
-
if (internal !== true) {
|
|
41
|
-
//init options
|
|
42
|
-
if (Object.prototype.toString.call(alias) === "[object Object]") {
|
|
43
|
-
options = alias;
|
|
44
|
-
} else {
|
|
45
|
-
options = options || {};
|
|
46
|
-
if (alias) options.alias = alias;
|
|
47
|
-
}
|
|
48
|
-
this.opts = $.extend(true, {}, this.defaults, options);
|
|
49
|
-
this.noMasksCache = options && options.definitions !== undefined;
|
|
50
|
-
this.userOptions = options || {}; //user passed options
|
|
51
|
-
resolveAlias(this.opts.alias, options, this.opts);
|
|
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
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
Inputmask.prototype = {
|
|
69
|
-
dataAttribute: "data-inputmask", //data attribute prefix used for attribute binding
|
|
70
|
-
//options default
|
|
71
|
-
defaults: defaults,
|
|
72
|
-
definitions: definitions,
|
|
73
|
-
aliases: {}, //aliases definitions
|
|
74
|
-
masksCache: {},
|
|
75
|
-
get isRTL() {
|
|
76
|
-
return this.opts.isRTL || this.opts.numericInput;
|
|
77
|
-
},
|
|
78
|
-
mask: function (elems) {
|
|
79
|
-
var that = this;
|
|
80
|
-
if (typeof elems === "string") {
|
|
81
|
-
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
82
|
-
}
|
|
83
|
-
elems = elems.nodeName ? [elems] : (Array.isArray(elems) ? elems : Array.from(elems));
|
|
84
|
-
elems.forEach(function (el, ndx) {
|
|
85
|
-
var scopedOpts = $.extend(true, {}, that.opts);
|
|
86
|
-
if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
|
|
87
|
-
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
|
|
88
|
-
if (maskset !== undefined) {
|
|
89
|
-
if (el.inputmask !== undefined) {
|
|
90
|
-
el.inputmask.opts.autoUnmask = true; //force autounmasking when remasking
|
|
91
|
-
el.inputmask.remove();
|
|
92
|
-
}
|
|
93
|
-
//store inputmask instance on the input with element reference
|
|
94
|
-
el.inputmask = new Inputmask(undefined, undefined, true);
|
|
95
|
-
el.inputmask.opts = scopedOpts;
|
|
96
|
-
el.inputmask.noMasksCache = that.noMasksCache;
|
|
97
|
-
el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
|
|
98
|
-
// el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
|
|
99
|
-
el.inputmask.el = el;
|
|
100
|
-
el.inputmask.$el = $(el);
|
|
101
|
-
el.inputmask.maskset = maskset;
|
|
102
|
-
|
|
103
|
-
$.data(el, dataKey, that.userOptions);
|
|
104
|
-
mask.call(el.inputmask);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return elems && elems[0] ? (elems[0].inputmask || this) : this;
|
|
109
|
-
},
|
|
110
|
-
option: function (options, noremask) { //set extra options || retrieve value of a current option
|
|
111
|
-
if (typeof options === "string") {
|
|
112
|
-
return this.opts[options];
|
|
113
|
-
} else if (typeof options === "object") {
|
|
114
|
-
$.extend(this.userOptions, options); //user passed options
|
|
115
|
-
//remask
|
|
116
|
-
if (this.el && noremask !== true) {
|
|
117
|
-
this.mask(this.el);
|
|
118
|
-
}
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
unmaskedvalue: function (value) {
|
|
123
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
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);
|
|
130
|
-
},
|
|
131
|
-
remove: function () {
|
|
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;
|
|
163
|
-
},
|
|
164
|
-
getemptymask: function () { //return the default (empty) mask value, usefull for setting the default value in validation
|
|
165
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
166
|
-
return getBufferTemplate.call(this).join("");
|
|
167
|
-
},
|
|
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
|
|
169
|
-
return !this.opts.autoUnmask;
|
|
170
|
-
},
|
|
171
|
-
isComplete: function () {
|
|
172
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
173
|
-
return isComplete.call(this, getBuffer.call(this));
|
|
174
|
-
},
|
|
175
|
-
getmetadata: function () { //return mask metadata if exists
|
|
176
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
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;
|
|
190
|
-
},
|
|
191
|
-
isValid: function (value) {
|
|
192
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
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
|
-
|
|
209
|
-
},
|
|
210
|
-
format: function (value, metadata) {
|
|
211
|
-
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
|
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;
|
|
219
|
-
},
|
|
220
|
-
setValue: function (value) {
|
|
221
|
-
if (this.el) {
|
|
222
|
-
$(this.el).trigger("setvalue", [value]);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
analyseMask: analyseMask
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
function resolveAlias(aliasStr, options, opts) {
|
|
229
|
-
var aliasDefinition = Inputmask.prototype.aliases[aliasStr];
|
|
230
|
-
if (aliasDefinition) {
|
|
231
|
-
if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
|
|
232
|
-
$.extend(true, opts, aliasDefinition); //merge alias definition in the options
|
|
233
|
-
$.extend(true, opts, options); //reapply extra given options
|
|
234
|
-
return true;
|
|
235
|
-
} else //alias not found - try as mask
|
|
236
|
-
if (opts.mask === null) {
|
|
237
|
-
opts.mask = aliasStr;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
|
|
244
|
-
function importOption(option, optionData) {
|
|
245
|
-
const attrOption = dataAttribute === "" ? option : dataAttribute + "-" + option;
|
|
246
|
-
optionData = optionData !== undefined ? optionData : npt.getAttribute(attrOption);
|
|
247
|
-
if (optionData !== null) {
|
|
248
|
-
if (typeof optionData === "string") {
|
|
249
|
-
if (option.indexOf("on") === 0) {
|
|
250
|
-
optionData = window[optionData];
|
|
251
|
-
}//get function definition
|
|
252
|
-
else if (optionData === "false") {
|
|
253
|
-
optionData = false;
|
|
254
|
-
} else if (optionData === "true") optionData = true;
|
|
255
|
-
}
|
|
256
|
-
userOptions[option] = optionData;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (opts.importDataAttributes === true) {
|
|
261
|
-
var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p;
|
|
262
|
-
|
|
263
|
-
if (attrOptions && attrOptions !== "") {
|
|
264
|
-
attrOptions = attrOptions.replace(/'/g, "\"");
|
|
265
|
-
dataoptions = JSON.parse("{" + attrOptions + "}");
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
//resolve aliases
|
|
269
|
-
if (dataoptions) { //pickup alias from dataAttribute
|
|
270
|
-
optionData = undefined;
|
|
271
|
-
for (p in dataoptions) {
|
|
272
|
-
if (p.toLowerCase() === "alias") {
|
|
273
|
-
optionData = dataoptions[p];
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
importOption("alias", optionData); //pickup alias from dataAttribute-alias
|
|
279
|
-
if (userOptions.alias) {
|
|
280
|
-
resolveAlias(userOptions.alias, userOptions, opts);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
for (option in opts) {
|
|
284
|
-
if (dataoptions) {
|
|
285
|
-
optionData = undefined;
|
|
286
|
-
for (p in dataoptions) {
|
|
287
|
-
if (p.toLowerCase() === option.toLowerCase()) {
|
|
288
|
-
optionData = dataoptions[p];
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
importOption(option, optionData);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
$.extend(true, opts, userOptions);
|
|
297
|
-
|
|
298
|
-
//handle dir=rtl
|
|
299
|
-
if (npt.dir === "rtl" || opts.rightAlign) {
|
|
300
|
-
npt.style.textAlign = "right";
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (npt.dir === "rtl" || opts.numericInput) {
|
|
304
|
-
npt.dir = "ltr";
|
|
305
|
-
npt.removeAttribute("dir");
|
|
306
|
-
opts.isRTL = true;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return Object.keys(userOptions).length;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
//apply defaults, definitions, aliases
|
|
313
|
-
Inputmask.extendDefaults = function (options) {
|
|
314
|
-
$.extend(true, Inputmask.prototype.defaults, options);
|
|
315
|
-
};
|
|
316
|
-
Inputmask.extendDefinitions = function (definition) {
|
|
317
|
-
$.extend(true, Inputmask.prototype.definitions, definition);
|
|
318
|
-
};
|
|
319
|
-
Inputmask.extendAliases = function (alias) {
|
|
320
|
-
$.extend(true, Inputmask.prototype.aliases, alias);
|
|
321
|
-
};
|
|
322
|
-
//static fn on inputmask
|
|
323
|
-
Inputmask.format = function (value, options, metadata) {
|
|
324
|
-
return Inputmask(options).format(value, metadata);
|
|
325
|
-
};
|
|
326
|
-
Inputmask.unmask = function (value, options) {
|
|
327
|
-
return Inputmask(options).unmaskedvalue(value);
|
|
328
|
-
};
|
|
329
|
-
Inputmask.isValid = function (value, options) {
|
|
330
|
-
return Inputmask(options).isValid(value);
|
|
331
|
-
};
|
|
332
|
-
Inputmask.remove = function (elems) {
|
|
333
|
-
if (typeof elems === "string") {
|
|
334
|
-
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
335
|
-
}
|
|
336
|
-
elems = elems.nodeName ? [elems] : elems;
|
|
337
|
-
elems.forEach(function (el) {
|
|
338
|
-
if (el.inputmask) el.inputmask.remove();
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
Inputmask.setValue = function (elems, value) {
|
|
342
|
-
if (typeof elems === "string") {
|
|
343
|
-
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
|
344
|
-
}
|
|
345
|
-
elems = elems.nodeName ? [elems] : elems;
|
|
346
|
-
elems.forEach(function (el) {
|
|
347
|
-
if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [value]);
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
Inputmask.dependencyLib = $;
|
|
352
|
-
|
|
353
|
-
//make inputmask available
|
|
354
|
-
window.Inputmask = Inputmask;
|
|
355
|
-
export default Inputmask;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import window from "./global/window";
|
|
2
|
-
import Inputmask from "./inputmask";
|
|
3
|
-
import canUseDOM from "./canUseDOM";
|
|
4
|
-
|
|
5
|
-
const document = window.document;
|
|
6
|
-
|
|
7
|
-
// add check if it is supported by the browser
|
|
8
|
-
// integrate shadowroot into maskcope
|
|
9
|
-
if (canUseDOM && document && document.head && document.head.attachShadow && window.customElements && window.customElements.get("input-mask") === undefined) {
|
|
10
|
-
class InputmaskElement extends HTMLElement {
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
var attributeNames = this.getAttributeNames(),
|
|
14
|
-
shadow = this.attachShadow({mode: "closed"}),
|
|
15
|
-
input = document.createElement("input");
|
|
16
|
-
input.type = "text";
|
|
17
|
-
shadow.appendChild(input);
|
|
18
|
-
|
|
19
|
-
for (var attr in attributeNames) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
|
|
21
|
-
input.setAttribute(attributeNames[attr], this.getAttribute(attributeNames[attr]));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var im = new Inputmask();
|
|
26
|
-
im.dataAttribute = "";
|
|
27
|
-
im.mask(input);
|
|
28
|
-
input.inputmask.shadowRoot = shadow; //make the shadowRoot available
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
window.customElements.define("input-mask", InputmaskElement);
|
|
33
|
-
}
|