react-input-mask-format 1.0.5 → 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/README.md +94 -44
- package/dist/index.cjs +883 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +49 -49
- package/dist/index.js +852 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -81
- package/dist/react-input-mask.js +0 -2381
- package/dist/react-input-mask.min.js +0 -1
- package/index.js +0 -7
- package/lib/react-input-mask.development.js +0 -1017
- package/lib/react-input-mask.production.min.js +0 -1
|
@@ -1,1017 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
var React = require('react');
|
|
6
|
-
var React__default = _interopDefault(React);
|
|
7
|
-
var PropTypes = _interopDefault(require('prop-types'));
|
|
8
|
-
var invariant = _interopDefault(require('invariant'));
|
|
9
|
-
var warning = _interopDefault(require('warning'));
|
|
10
|
-
|
|
11
|
-
function _defaults2(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
|
12
|
-
|
|
13
|
-
function _extends() {
|
|
14
|
-
_extends = Object.assign || function (target) {
|
|
15
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
-
var source = arguments[i];
|
|
17
|
-
|
|
18
|
-
for (var key in source) {
|
|
19
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
20
|
-
target[key] = source[key];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return target;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return _extends.apply(this, arguments);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _inheritsLoose(subClass, superClass) {
|
|
32
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
33
|
-
subClass.prototype.constructor = subClass;
|
|
34
|
-
|
|
35
|
-
_defaults2(subClass, superClass);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
39
|
-
if (source == null) return {};
|
|
40
|
-
var target = {};
|
|
41
|
-
var sourceKeys = Object.keys(source);
|
|
42
|
-
var key, i;
|
|
43
|
-
|
|
44
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
45
|
-
key = sourceKeys[i];
|
|
46
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
47
|
-
target[key] = source[key];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return target;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function defer(fn) {
|
|
54
|
-
return requestAnimationFrame(fn);
|
|
55
|
-
}
|
|
56
|
-
function cancelDefer(deferId) {
|
|
57
|
-
cancelAnimationFrame(deferId);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function setInputSelection(input, start, end) {
|
|
61
|
-
if (end === undefined) {
|
|
62
|
-
end = start;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
input.setSelectionRange(start, end);
|
|
66
|
-
}
|
|
67
|
-
function getInputSelection(input) {
|
|
68
|
-
var start = input.selectionStart;
|
|
69
|
-
var end = input.selectionEnd;
|
|
70
|
-
return {
|
|
71
|
-
start: start,
|
|
72
|
-
end: end,
|
|
73
|
-
length: end - start
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function isInputFocused(input) {
|
|
77
|
-
var inputDocument = input.ownerDocument;
|
|
78
|
-
return inputDocument.hasFocus() && inputDocument.activeElement === input;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Element's window may differ from the one within React instance
|
|
82
|
-
// if element rendered within iframe.
|
|
83
|
-
// See https://github.com/sanniassin/react-input-mask/issues/182
|
|
84
|
-
function getElementDocument(element) {
|
|
85
|
-
return element == null ? void 0 : element.ownerDocument;
|
|
86
|
-
}
|
|
87
|
-
function getElementWindow(element) {
|
|
88
|
-
var _getElementDocument;
|
|
89
|
-
|
|
90
|
-
return (_getElementDocument = getElementDocument(element)) == null ? void 0 : _getElementDocument.defaultView;
|
|
91
|
-
}
|
|
92
|
-
function isDOMElement(element) {
|
|
93
|
-
var elementWindow = getElementWindow(element);
|
|
94
|
-
return !!elementWindow && element instanceof elementWindow.HTMLElement;
|
|
95
|
-
}
|
|
96
|
-
function isFunction(value) {
|
|
97
|
-
return typeof value === "function";
|
|
98
|
-
}
|
|
99
|
-
function findLastIndex(array, predicate) {
|
|
100
|
-
for (var i = array.length - 1; i >= 0; i--) {
|
|
101
|
-
var x = array[i];
|
|
102
|
-
|
|
103
|
-
if (predicate(x, i)) {
|
|
104
|
-
return i;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return -1;
|
|
109
|
-
}
|
|
110
|
-
function repeat(string, n) {
|
|
111
|
-
if (n === void 0) {
|
|
112
|
-
n = 1;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var result = "";
|
|
116
|
-
|
|
117
|
-
for (var i = 0; i < n; i++) {
|
|
118
|
-
result += string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
function toString(value) {
|
|
124
|
-
return "" + value;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function useInputElement(inputRef) {
|
|
128
|
-
return React.useCallback(function () {
|
|
129
|
-
var input = inputRef.current;
|
|
130
|
-
var isDOMNode = typeof window !== "undefined" && isDOMElement(input); // workaround for react-test-renderer
|
|
131
|
-
// https://github.com/sanniassin/react-input-mask/issues/147
|
|
132
|
-
|
|
133
|
-
if (!input || !isDOMNode) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (input.nodeName !== "INPUT") {
|
|
138
|
-
input = input.querySelector("input");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (!input) {
|
|
142
|
-
throw new Error("react-input-mask: inputComponent doesn't contain input node");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return input;
|
|
146
|
-
}, [inputRef]);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function useDeferLoop(callback) {
|
|
150
|
-
var deferIdRef = React.useRef(null);
|
|
151
|
-
var runLoop = React.useCallback(function () {
|
|
152
|
-
// If there are simulated focus events, runLoop could be
|
|
153
|
-
// called multiple times without blur or re-render
|
|
154
|
-
if (deferIdRef.current !== null) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function loop() {
|
|
159
|
-
callback();
|
|
160
|
-
deferIdRef.current = defer(loop);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
loop();
|
|
164
|
-
}, [callback]);
|
|
165
|
-
var stopLoop = React.useCallback(function () {
|
|
166
|
-
cancelDefer(deferIdRef.current);
|
|
167
|
-
deferIdRef.current = null;
|
|
168
|
-
}, []);
|
|
169
|
-
React.useEffect(function () {
|
|
170
|
-
if (deferIdRef.current) {
|
|
171
|
-
stopLoop();
|
|
172
|
-
runLoop();
|
|
173
|
-
}
|
|
174
|
-
}, [runLoop, stopLoop]);
|
|
175
|
-
React.useEffect(cancelDefer, []);
|
|
176
|
-
return [runLoop, stopLoop];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function useSelection(inputRef, isMasked) {
|
|
180
|
-
var selectionRef = React.useRef({
|
|
181
|
-
start: null,
|
|
182
|
-
end: null
|
|
183
|
-
});
|
|
184
|
-
var getInputElement = useInputElement(inputRef);
|
|
185
|
-
var getSelection = React.useCallback(function () {
|
|
186
|
-
var input = getInputElement();
|
|
187
|
-
return getInputSelection(input);
|
|
188
|
-
}, [getInputElement]);
|
|
189
|
-
var getLastSelection = React.useCallback(function () {
|
|
190
|
-
return selectionRef.current;
|
|
191
|
-
}, []);
|
|
192
|
-
var setSelection = React.useCallback(function (selection) {
|
|
193
|
-
var input = getInputElement(); // Don't change selection on unfocused input
|
|
194
|
-
// because Safari sets focus on selection change (#154)
|
|
195
|
-
|
|
196
|
-
if (!input || !isInputFocused(input)) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
setInputSelection(input, selection.start, selection.end); // Use actual selection in case the requested one was out of range
|
|
201
|
-
|
|
202
|
-
selectionRef.current = getSelection();
|
|
203
|
-
}, [getInputElement, getSelection]);
|
|
204
|
-
var selectionLoop = React.useCallback(function () {
|
|
205
|
-
selectionRef.current = getSelection();
|
|
206
|
-
}, [getSelection]);
|
|
207
|
-
|
|
208
|
-
var _useDeferLoop = useDeferLoop(selectionLoop),
|
|
209
|
-
runSelectionLoop = _useDeferLoop[0],
|
|
210
|
-
stopSelectionLoop = _useDeferLoop[1];
|
|
211
|
-
|
|
212
|
-
React.useLayoutEffect(function () {
|
|
213
|
-
if (!isMasked) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
var input = getInputElement();
|
|
218
|
-
input.addEventListener("focus", runSelectionLoop);
|
|
219
|
-
input.addEventListener("blur", stopSelectionLoop);
|
|
220
|
-
|
|
221
|
-
if (isInputFocused(input)) {
|
|
222
|
-
runSelectionLoop();
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return function () {
|
|
226
|
-
input.removeEventListener("focus", runSelectionLoop);
|
|
227
|
-
input.removeEventListener("blur", stopSelectionLoop);
|
|
228
|
-
stopSelectionLoop();
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
return {
|
|
232
|
-
getSelection: getSelection,
|
|
233
|
-
getLastSelection: getLastSelection,
|
|
234
|
-
setSelection: setSelection
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function useValue(inputRef, initialValue) {
|
|
239
|
-
var getInputElement = useInputElement(inputRef);
|
|
240
|
-
var valueRef = React.useRef(initialValue);
|
|
241
|
-
var getValue = React.useCallback(function () {
|
|
242
|
-
var input = getInputElement();
|
|
243
|
-
return input.value;
|
|
244
|
-
}, [getInputElement]);
|
|
245
|
-
var getLastValue = React.useCallback(function () {
|
|
246
|
-
return valueRef.current;
|
|
247
|
-
}, []);
|
|
248
|
-
var setValue = React.useCallback(function (newValue) {
|
|
249
|
-
valueRef.current = newValue;
|
|
250
|
-
var input = getInputElement();
|
|
251
|
-
|
|
252
|
-
if (input) {
|
|
253
|
-
input.value = newValue;
|
|
254
|
-
}
|
|
255
|
-
}, [getInputElement]);
|
|
256
|
-
return {
|
|
257
|
-
getValue: getValue,
|
|
258
|
-
getLastValue: getLastValue,
|
|
259
|
-
setValue: setValue
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function useInputState(initialValue, isMasked) {
|
|
264
|
-
var inputRef = React.useRef();
|
|
265
|
-
|
|
266
|
-
var _useSelection = useSelection(inputRef, isMasked),
|
|
267
|
-
getSelection = _useSelection.getSelection,
|
|
268
|
-
getLastSelection = _useSelection.getLastSelection,
|
|
269
|
-
setSelection = _useSelection.setSelection;
|
|
270
|
-
|
|
271
|
-
var _useValue = useValue(inputRef, initialValue),
|
|
272
|
-
getValue = _useValue.getValue,
|
|
273
|
-
getLastValue = _useValue.getLastValue,
|
|
274
|
-
setValue = _useValue.setValue;
|
|
275
|
-
|
|
276
|
-
function getLastInputState() {
|
|
277
|
-
return {
|
|
278
|
-
value: getLastValue(),
|
|
279
|
-
selection: getLastSelection()
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function getInputState() {
|
|
284
|
-
return {
|
|
285
|
-
value: getValue(),
|
|
286
|
-
selection: getSelection()
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function setInputState(_ref) {
|
|
291
|
-
var value = _ref.value,
|
|
292
|
-
selection = _ref.selection;
|
|
293
|
-
setValue(value);
|
|
294
|
-
setSelection(selection);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return {
|
|
298
|
-
inputRef: inputRef,
|
|
299
|
-
getInputState: getInputState,
|
|
300
|
-
getLastInputState: getLastInputState,
|
|
301
|
-
setInputState: setInputState
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function usePrevious(value) {
|
|
305
|
-
var ref = React.useRef();
|
|
306
|
-
React.useEffect(function () {
|
|
307
|
-
ref.current = value;
|
|
308
|
-
});
|
|
309
|
-
return ref.current;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
var CONTROLLED_PROPS = ["disabled", "onBlur", "onChange", "onFocus", "onMouseDown", "readOnly", "value"];
|
|
313
|
-
var defaultFormatChars = {
|
|
314
|
-
"9": /[0-9]/,
|
|
315
|
-
a: /[A-Za-z]/,
|
|
316
|
-
"*": /[A-Za-z0-9]/
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
function validateMaxLength(props) {
|
|
320
|
-
process.env.NODE_ENV !== "production" ? warning(!props.maxLength || !props.mask, "react-input-mask: maxLength property shouldn't be passed to the masked input. It breaks masking and unnecessary because length is limited by the mask length.") : void 0;
|
|
321
|
-
}
|
|
322
|
-
function validateMaskPlaceholder(props) {
|
|
323
|
-
var mask = props.mask,
|
|
324
|
-
maskPlaceholder = props.maskPlaceholder;
|
|
325
|
-
!(!mask || !maskPlaceholder || maskPlaceholder.length === 1 || maskPlaceholder.length === mask.length) ? process.env.NODE_ENV !== "production" ? invariant(false, "react-input-mask: maskPlaceholder should either be a single character or have the same length as the mask:\n" + ("mask: " + mask + "\n") + ("maskPlaceholder: " + maskPlaceholder)) : invariant(false) : void 0;
|
|
326
|
-
}
|
|
327
|
-
function validateChildren(props, inputElement) {
|
|
328
|
-
var conflictProps = CONTROLLED_PROPS.filter(function (propId) {
|
|
329
|
-
return inputElement.props[propId] != null && inputElement.props[propId] !== props[propId];
|
|
330
|
-
});
|
|
331
|
-
!!conflictProps.length ? process.env.NODE_ENV !== "production" ? invariant(false, "react-input-mask: the following props should be passed to the InputMask component, not to children: " + conflictProps.join(",")) : invariant(false) : void 0;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function parseMask (_ref) {
|
|
335
|
-
var mask = _ref.mask,
|
|
336
|
-
maskPlaceholder = _ref.maskPlaceholder;
|
|
337
|
-
var permanents = [];
|
|
338
|
-
|
|
339
|
-
if (!mask) {
|
|
340
|
-
return {
|
|
341
|
-
maskPlaceholder: null,
|
|
342
|
-
mask: null,
|
|
343
|
-
prefix: null,
|
|
344
|
-
lastEditablePosition: null,
|
|
345
|
-
permanents: []
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (typeof mask === "string") {
|
|
350
|
-
var isPermanent = false;
|
|
351
|
-
var parsedMaskString = "";
|
|
352
|
-
mask.split("").forEach(function (character) {
|
|
353
|
-
if (!isPermanent && character === "\\") {
|
|
354
|
-
isPermanent = true;
|
|
355
|
-
} else {
|
|
356
|
-
if (isPermanent || !defaultFormatChars[character]) {
|
|
357
|
-
permanents.push(parsedMaskString.length);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
parsedMaskString += character;
|
|
361
|
-
isPermanent = false;
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
mask = parsedMaskString.split("").map(function (character, index) {
|
|
365
|
-
if (permanents.indexOf(index) === -1) {
|
|
366
|
-
return defaultFormatChars[character];
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return character;
|
|
370
|
-
});
|
|
371
|
-
} else {
|
|
372
|
-
mask.forEach(function (character, index) {
|
|
373
|
-
if (typeof character === "string") {
|
|
374
|
-
permanents.push(index);
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (maskPlaceholder) {
|
|
380
|
-
if (maskPlaceholder.length === 1) {
|
|
381
|
-
maskPlaceholder = mask.map(function (character, index) {
|
|
382
|
-
if (permanents.indexOf(index) !== -1) {
|
|
383
|
-
return character;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return maskPlaceholder;
|
|
387
|
-
});
|
|
388
|
-
} else {
|
|
389
|
-
maskPlaceholder = maskPlaceholder.split("");
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
permanents.forEach(function (position) {
|
|
393
|
-
maskPlaceholder[position] = mask[position];
|
|
394
|
-
});
|
|
395
|
-
maskPlaceholder = maskPlaceholder.join("");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
var prefix = permanents.filter(function (position, index) {
|
|
399
|
-
return position === index;
|
|
400
|
-
}).map(function (position) {
|
|
401
|
-
return mask[position];
|
|
402
|
-
}).join("");
|
|
403
|
-
var lastEditablePosition = mask.length - 1;
|
|
404
|
-
|
|
405
|
-
while (permanents.indexOf(lastEditablePosition) !== -1) {
|
|
406
|
-
lastEditablePosition--;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return {
|
|
410
|
-
maskPlaceholder: maskPlaceholder,
|
|
411
|
-
prefix: prefix,
|
|
412
|
-
mask: mask,
|
|
413
|
-
lastEditablePosition: lastEditablePosition,
|
|
414
|
-
permanents: permanents
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/* eslint no-use-before-define: ["error", { functions: false }] */
|
|
419
|
-
|
|
420
|
-
var MaskUtils = function MaskUtils(options) {
|
|
421
|
-
var _this = this;
|
|
422
|
-
|
|
423
|
-
this.isCharacterAllowedAtPosition = function (character, position) {
|
|
424
|
-
var maskPlaceholder = _this.maskOptions.maskPlaceholder;
|
|
425
|
-
|
|
426
|
-
if (_this.isCharacterFillingPosition(character, position)) {
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (!maskPlaceholder) {
|
|
431
|
-
return false;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return maskPlaceholder[position] === character;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
this.isCharacterFillingPosition = function (character, position) {
|
|
438
|
-
var mask = _this.maskOptions.mask;
|
|
439
|
-
|
|
440
|
-
if (!character || position >= mask.length) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
if (!_this.isPositionEditable(position)) {
|
|
445
|
-
return mask[position] === character;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
var charRule = mask[position];
|
|
449
|
-
return new RegExp(charRule).test(character);
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
this.isPositionEditable = function (position) {
|
|
453
|
-
var _this$maskOptions = _this.maskOptions,
|
|
454
|
-
mask = _this$maskOptions.mask,
|
|
455
|
-
permanents = _this$maskOptions.permanents;
|
|
456
|
-
return position < mask.length && permanents.indexOf(position) === -1;
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
this.isValueEmpty = function (value) {
|
|
460
|
-
return value.split("").every(function (character, position) {
|
|
461
|
-
return !_this.isPositionEditable(position) || !_this.isCharacterFillingPosition(character, position);
|
|
462
|
-
});
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
this.isValueFilled = function (value) {
|
|
466
|
-
return _this.getFilledLength(value) === _this.maskOptions.lastEditablePosition + 1;
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
this.getDefaultSelectionForValue = function (value) {
|
|
470
|
-
var filledLength = _this.getFilledLength(value);
|
|
471
|
-
|
|
472
|
-
var cursorPosition = _this.getRightEditablePosition(filledLength);
|
|
473
|
-
|
|
474
|
-
return {
|
|
475
|
-
start: cursorPosition,
|
|
476
|
-
end: cursorPosition
|
|
477
|
-
};
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
this.getFilledLength = function (value) {
|
|
481
|
-
var characters = value.split("");
|
|
482
|
-
var lastFilledIndex = findLastIndex(characters, function (character, position) {
|
|
483
|
-
return _this.isPositionEditable(position) && _this.isCharacterFillingPosition(character, position);
|
|
484
|
-
});
|
|
485
|
-
return lastFilledIndex + 1;
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
this.getStringFillingLengthAtPosition = function (string, position) {
|
|
489
|
-
var characters = string.split("");
|
|
490
|
-
var insertedValue = characters.reduce(function (value, character) {
|
|
491
|
-
return _this.insertCharacterAtPosition(value, character, value.length);
|
|
492
|
-
}, repeat(" ", position));
|
|
493
|
-
return insertedValue.length - position;
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
this.getLeftEditablePosition = function (position) {
|
|
497
|
-
for (var i = position; i >= 0; i--) {
|
|
498
|
-
if (_this.isPositionEditable(i)) {
|
|
499
|
-
return i;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return null;
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
this.getRightEditablePosition = function (position) {
|
|
507
|
-
var mask = _this.maskOptions.mask;
|
|
508
|
-
|
|
509
|
-
for (var i = position; i < mask.length; i++) {
|
|
510
|
-
if (_this.isPositionEditable(i)) {
|
|
511
|
-
return i;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return null;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
this.formatValue = function (value) {
|
|
519
|
-
var _this$maskOptions2 = _this.maskOptions,
|
|
520
|
-
maskPlaceholder = _this$maskOptions2.maskPlaceholder,
|
|
521
|
-
mask = _this$maskOptions2.mask;
|
|
522
|
-
|
|
523
|
-
if (!maskPlaceholder) {
|
|
524
|
-
value = _this.insertStringAtPosition("", value, 0);
|
|
525
|
-
|
|
526
|
-
while (value.length < mask.length && !_this.isPositionEditable(value.length)) {
|
|
527
|
-
value += mask[value.length];
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return value;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return _this.insertStringAtPosition(maskPlaceholder, value, 0);
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
this.clearRange = function (value, start, len) {
|
|
537
|
-
if (!len) {
|
|
538
|
-
return value;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
var end = start + len;
|
|
542
|
-
var _this$maskOptions3 = _this.maskOptions,
|
|
543
|
-
maskPlaceholder = _this$maskOptions3.maskPlaceholder,
|
|
544
|
-
mask = _this$maskOptions3.mask;
|
|
545
|
-
var clearedValue = value.split("").map(function (character, i) {
|
|
546
|
-
var isEditable = _this.isPositionEditable(i);
|
|
547
|
-
|
|
548
|
-
if (!maskPlaceholder && i >= end && !isEditable) {
|
|
549
|
-
return "";
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
if (i < start || i >= end) {
|
|
553
|
-
return character;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (!isEditable) {
|
|
557
|
-
return mask[i];
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
if (maskPlaceholder) {
|
|
561
|
-
return maskPlaceholder[i];
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return "";
|
|
565
|
-
}).join("");
|
|
566
|
-
return _this.formatValue(clearedValue);
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
this.insertCharacterAtPosition = function (value, character, position) {
|
|
570
|
-
var _this$maskOptions4 = _this.maskOptions,
|
|
571
|
-
mask = _this$maskOptions4.mask,
|
|
572
|
-
maskPlaceholder = _this$maskOptions4.maskPlaceholder;
|
|
573
|
-
|
|
574
|
-
if (position >= mask.length) {
|
|
575
|
-
return value;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
var isAllowed = _this.isCharacterAllowedAtPosition(character, position);
|
|
579
|
-
|
|
580
|
-
var isEditable = _this.isPositionEditable(position);
|
|
581
|
-
|
|
582
|
-
var nextEditablePosition = _this.getRightEditablePosition(position);
|
|
583
|
-
|
|
584
|
-
var isNextPlaceholder = maskPlaceholder && nextEditablePosition ? character === maskPlaceholder[nextEditablePosition] : null;
|
|
585
|
-
var valueBefore = value.slice(0, position);
|
|
586
|
-
|
|
587
|
-
if (isAllowed || !isEditable) {
|
|
588
|
-
var insertedCharacter = isAllowed ? character : mask[position];
|
|
589
|
-
value = valueBefore + insertedCharacter;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
if (!isAllowed && !isEditable && !isNextPlaceholder) {
|
|
593
|
-
value = _this.insertCharacterAtPosition(value, character, position + 1);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return value;
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
this.insertStringAtPosition = function (value, string, position) {
|
|
600
|
-
var _this$maskOptions5 = _this.maskOptions,
|
|
601
|
-
mask = _this$maskOptions5.mask,
|
|
602
|
-
maskPlaceholder = _this$maskOptions5.maskPlaceholder;
|
|
603
|
-
|
|
604
|
-
if (!string || position >= mask.length) {
|
|
605
|
-
return value;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
var characters = string.split("");
|
|
609
|
-
var isFixedLength = _this.isValueFilled(value) || !!maskPlaceholder;
|
|
610
|
-
var valueAfter = value.slice(position);
|
|
611
|
-
value = characters.reduce(function (value, character) {
|
|
612
|
-
return _this.insertCharacterAtPosition(value, character, value.length);
|
|
613
|
-
}, value.slice(0, position));
|
|
614
|
-
|
|
615
|
-
if (isFixedLength) {
|
|
616
|
-
value += valueAfter.slice(value.length - position);
|
|
617
|
-
} else if (_this.isValueFilled(value)) {
|
|
618
|
-
value += mask.slice(value.length).join("");
|
|
619
|
-
} else {
|
|
620
|
-
var editableCharactersAfter = valueAfter.split("").filter(function (character, i) {
|
|
621
|
-
return _this.isPositionEditable(position + i);
|
|
622
|
-
});
|
|
623
|
-
value = editableCharactersAfter.reduce(function (value, character) {
|
|
624
|
-
var nextEditablePosition = _this.getRightEditablePosition(value.length);
|
|
625
|
-
|
|
626
|
-
if (nextEditablePosition === null) {
|
|
627
|
-
return value;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (!_this.isPositionEditable(value.length)) {
|
|
631
|
-
value += mask.slice(value.length, nextEditablePosition).join("");
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
return _this.insertCharacterAtPosition(value, character, value.length);
|
|
635
|
-
}, value);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return value;
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
this.processChange = function (currentState, previousState) {
|
|
642
|
-
var _this$maskOptions6 = _this.maskOptions,
|
|
643
|
-
mask = _this$maskOptions6.mask,
|
|
644
|
-
prefix = _this$maskOptions6.prefix,
|
|
645
|
-
lastEditablePosition = _this$maskOptions6.lastEditablePosition;
|
|
646
|
-
var value = currentState.value,
|
|
647
|
-
selection = currentState.selection;
|
|
648
|
-
var previousValue = previousState.value;
|
|
649
|
-
var previousSelection = previousState.selection;
|
|
650
|
-
var newValue = value;
|
|
651
|
-
var enteredString = "";
|
|
652
|
-
var formattedEnteredStringLength = 0;
|
|
653
|
-
var removedLength = 0;
|
|
654
|
-
var cursorPosition = Math.min(previousSelection.start, selection.start);
|
|
655
|
-
|
|
656
|
-
if (selection.end > previousSelection.start) {
|
|
657
|
-
enteredString = newValue.slice(previousSelection.start, selection.end);
|
|
658
|
-
formattedEnteredStringLength = _this.getStringFillingLengthAtPosition(enteredString, cursorPosition);
|
|
659
|
-
|
|
660
|
-
if (!formattedEnteredStringLength) {
|
|
661
|
-
removedLength = 0;
|
|
662
|
-
} else {
|
|
663
|
-
removedLength = previousSelection.length;
|
|
664
|
-
}
|
|
665
|
-
} else if (newValue.length < previousValue.length) {
|
|
666
|
-
removedLength = previousValue.length - newValue.length;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
newValue = previousValue;
|
|
670
|
-
|
|
671
|
-
if (removedLength) {
|
|
672
|
-
if (removedLength === 1 && !previousSelection.length) {
|
|
673
|
-
var deleteFromRight = previousSelection.start === selection.start;
|
|
674
|
-
cursorPosition = deleteFromRight ? _this.getRightEditablePosition(selection.start) : _this.getLeftEditablePosition(selection.start);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
newValue = _this.clearRange(newValue, cursorPosition, removedLength);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
newValue = _this.insertStringAtPosition(newValue, enteredString, cursorPosition);
|
|
681
|
-
cursorPosition += formattedEnteredStringLength;
|
|
682
|
-
|
|
683
|
-
if (cursorPosition >= mask.length) {
|
|
684
|
-
cursorPosition = mask.length;
|
|
685
|
-
} else if (cursorPosition < prefix.length && !formattedEnteredStringLength) {
|
|
686
|
-
cursorPosition = prefix.length;
|
|
687
|
-
} else if (cursorPosition >= prefix.length && cursorPosition < lastEditablePosition && formattedEnteredStringLength) {
|
|
688
|
-
cursorPosition = _this.getRightEditablePosition(cursorPosition);
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
newValue = _this.formatValue(newValue);
|
|
692
|
-
return {
|
|
693
|
-
value: newValue,
|
|
694
|
-
enteredString: enteredString,
|
|
695
|
-
selection: {
|
|
696
|
-
start: cursorPosition,
|
|
697
|
-
end: cursorPosition
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
this.maskOptions = parseMask(options);
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
var InputMaskChildrenWrapper =
|
|
706
|
-
/*#__PURE__*/
|
|
707
|
-
function (_React$Component) {
|
|
708
|
-
_inheritsLoose(InputMaskChildrenWrapper, _React$Component);
|
|
709
|
-
|
|
710
|
-
function InputMaskChildrenWrapper() {
|
|
711
|
-
return _React$Component.apply(this, arguments) || this;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
var _proto = InputMaskChildrenWrapper.prototype;
|
|
715
|
-
|
|
716
|
-
_proto.render = function render() {
|
|
717
|
-
// eslint-disable-next-line react/prop-types
|
|
718
|
-
var _this$props = this.props,
|
|
719
|
-
children = _this$props.children,
|
|
720
|
-
props = _objectWithoutPropertiesLoose(_this$props, ["children"]);
|
|
721
|
-
|
|
722
|
-
return React__default.cloneElement(children, props);
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
return InputMaskChildrenWrapper;
|
|
726
|
-
}(React__default.Component);
|
|
727
|
-
|
|
728
|
-
var InputMask = React.forwardRef(function InputMask(props, forwardedRef) {
|
|
729
|
-
var alwaysShowMask = props.alwaysShowMask,
|
|
730
|
-
children = props.children,
|
|
731
|
-
mask = props.mask,
|
|
732
|
-
maskPlaceholder = props.maskPlaceholder,
|
|
733
|
-
beforeMaskedStateChange = props.beforeMaskedStateChange,
|
|
734
|
-
restProps = _objectWithoutPropertiesLoose(props, ["alwaysShowMask", "children", "mask", "maskPlaceholder", "beforeMaskedStateChange"]);
|
|
735
|
-
|
|
736
|
-
validateMaxLength(props);
|
|
737
|
-
validateMaskPlaceholder(props);
|
|
738
|
-
var maskUtils = new MaskUtils({
|
|
739
|
-
mask: mask,
|
|
740
|
-
maskPlaceholder: maskPlaceholder
|
|
741
|
-
});
|
|
742
|
-
var isMasked = !!mask;
|
|
743
|
-
var isEditable = !restProps.disabled && !restProps.readOnly;
|
|
744
|
-
var isControlled = props.value !== null && props.value !== undefined;
|
|
745
|
-
var previousIsMasked = usePrevious(isMasked);
|
|
746
|
-
var initialValue = toString((isControlled ? props.value : props.defaultValue) || "");
|
|
747
|
-
|
|
748
|
-
var _useInputState = useInputState(initialValue, isMasked),
|
|
749
|
-
inputRef = _useInputState.inputRef,
|
|
750
|
-
getInputState = _useInputState.getInputState,
|
|
751
|
-
setInputState = _useInputState.setInputState,
|
|
752
|
-
getLastInputState = _useInputState.getLastInputState;
|
|
753
|
-
|
|
754
|
-
var getInputElement = useInputElement(inputRef);
|
|
755
|
-
|
|
756
|
-
function onChange(event) {
|
|
757
|
-
var currentState = getInputState();
|
|
758
|
-
var previousState = getLastInputState();
|
|
759
|
-
var newInputState = maskUtils.processChange(currentState, previousState);
|
|
760
|
-
|
|
761
|
-
if (beforeMaskedStateChange) {
|
|
762
|
-
newInputState = beforeMaskedStateChange({
|
|
763
|
-
currentState: currentState,
|
|
764
|
-
previousState: previousState,
|
|
765
|
-
nextState: newInputState
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
setInputState(newInputState);
|
|
770
|
-
|
|
771
|
-
if (props.onChange) {
|
|
772
|
-
props.onChange(event);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
function onFocus(event) {
|
|
777
|
-
// If autoFocus property is set, focus event fires before the ref handler gets called
|
|
778
|
-
inputRef.current = event.target;
|
|
779
|
-
var currentValue = getInputState().value;
|
|
780
|
-
|
|
781
|
-
if (isMasked && !maskUtils.isValueFilled(currentValue)) {
|
|
782
|
-
var newValue = maskUtils.formatValue(currentValue);
|
|
783
|
-
var newSelection = maskUtils.getDefaultSelectionForValue(newValue);
|
|
784
|
-
var newInputState = {
|
|
785
|
-
value: newValue,
|
|
786
|
-
selection: newSelection
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
if (beforeMaskedStateChange) {
|
|
790
|
-
newInputState = beforeMaskedStateChange({
|
|
791
|
-
currentState: getInputState(),
|
|
792
|
-
nextState: newInputState
|
|
793
|
-
});
|
|
794
|
-
newValue = newInputState.value;
|
|
795
|
-
newSelection = newInputState.selection;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
setInputState(newInputState);
|
|
799
|
-
|
|
800
|
-
if (newValue !== currentValue && props.onChange) {
|
|
801
|
-
props.onChange(event);
|
|
802
|
-
} // Chrome resets selection after focus event,
|
|
803
|
-
// so we want to restore it later
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
defer(function () {
|
|
807
|
-
setInputState(getLastInputState());
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
if (props.onFocus) {
|
|
812
|
-
props.onFocus(event);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
function onBlur(event) {
|
|
817
|
-
var currentValue = getInputState().value;
|
|
818
|
-
var lastValue = getLastInputState().value;
|
|
819
|
-
|
|
820
|
-
if (isMasked && !alwaysShowMask && maskUtils.isValueEmpty(lastValue)) {
|
|
821
|
-
var newValue = "";
|
|
822
|
-
var newInputState = {
|
|
823
|
-
value: newValue,
|
|
824
|
-
selection: {
|
|
825
|
-
start: null,
|
|
826
|
-
end: null
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
if (beforeMaskedStateChange) {
|
|
831
|
-
newInputState = beforeMaskedStateChange({
|
|
832
|
-
currentState: getInputState(),
|
|
833
|
-
nextState: newInputState
|
|
834
|
-
});
|
|
835
|
-
newValue = newInputState.value;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
setInputState(newInputState);
|
|
839
|
-
|
|
840
|
-
if (newValue !== currentValue && props.onChange) {
|
|
841
|
-
props.onChange(event);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
if (props.onBlur) {
|
|
846
|
-
props.onBlur(event);
|
|
847
|
-
}
|
|
848
|
-
} // Tiny unintentional mouse movements can break cursor
|
|
849
|
-
// position on focus, so we have to restore it in that case
|
|
850
|
-
//
|
|
851
|
-
// https://github.com/sanniassin/react-input-mask/issues/108
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
function onMouseDown(event) {
|
|
855
|
-
var input = getInputElement();
|
|
856
|
-
|
|
857
|
-
var _getInputState = getInputState(),
|
|
858
|
-
value = _getInputState.value;
|
|
859
|
-
|
|
860
|
-
var inputDocument = getElementDocument(input);
|
|
861
|
-
|
|
862
|
-
if (!isInputFocused(input) && !maskUtils.isValueFilled(value)) {
|
|
863
|
-
var mouseDownX = event.clientX;
|
|
864
|
-
var mouseDownY = event.clientY;
|
|
865
|
-
var mouseDownTime = new Date().getTime();
|
|
866
|
-
|
|
867
|
-
var mouseUpHandler = function mouseUpHandler(mouseUpEvent) {
|
|
868
|
-
inputDocument.removeEventListener("mouseup", mouseUpHandler);
|
|
869
|
-
|
|
870
|
-
if (!isInputFocused(input)) {
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
var deltaX = Math.abs(mouseUpEvent.clientX - mouseDownX);
|
|
875
|
-
var deltaY = Math.abs(mouseUpEvent.clientY - mouseDownY);
|
|
876
|
-
var axisDelta = Math.max(deltaX, deltaY);
|
|
877
|
-
var timeDelta = new Date().getTime() - mouseDownTime;
|
|
878
|
-
|
|
879
|
-
if (axisDelta <= 10 && timeDelta <= 200 || axisDelta <= 5 && timeDelta <= 300) {
|
|
880
|
-
var _lastState = getLastInputState();
|
|
881
|
-
|
|
882
|
-
var newSelection = maskUtils.getDefaultSelectionForValue(_lastState.value);
|
|
883
|
-
|
|
884
|
-
var newState = _extends({}, _lastState, {
|
|
885
|
-
selection: newSelection
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
setInputState(newState);
|
|
889
|
-
}
|
|
890
|
-
};
|
|
891
|
-
|
|
892
|
-
inputDocument.addEventListener("mouseup", mouseUpHandler);
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
if (props.onMouseDown) {
|
|
896
|
-
props.onMouseDown(event);
|
|
897
|
-
}
|
|
898
|
-
} // For controlled inputs we want to provide properly formatted
|
|
899
|
-
// value prop
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (isMasked && isControlled) {
|
|
903
|
-
var input = getInputElement();
|
|
904
|
-
var isFocused = input && isInputFocused(input);
|
|
905
|
-
var newValue = isFocused || alwaysShowMask || props.value ? maskUtils.formatValue(props.value) : props.value;
|
|
906
|
-
|
|
907
|
-
if (beforeMaskedStateChange) {
|
|
908
|
-
newValue = beforeMaskedStateChange({
|
|
909
|
-
nextState: {
|
|
910
|
-
value: newValue,
|
|
911
|
-
selection: {
|
|
912
|
-
start: null,
|
|
913
|
-
end: null
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
}).value;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
setInputState(_extends({}, getLastInputState(), {
|
|
920
|
-
value: newValue
|
|
921
|
-
}));
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
var lastState = getLastInputState();
|
|
925
|
-
var lastSelection = lastState.selection;
|
|
926
|
-
var lastValue = lastState.value;
|
|
927
|
-
React.useLayoutEffect(function () {
|
|
928
|
-
if (!isMasked) {
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
var input = getInputElement();
|
|
933
|
-
var isFocused = isInputFocused(input);
|
|
934
|
-
var previousSelection = lastSelection;
|
|
935
|
-
var currentState = getInputState();
|
|
936
|
-
|
|
937
|
-
var newInputState = _extends({}, currentState); // Update value for uncontrolled inputs to make sure
|
|
938
|
-
// it's always in sync with mask props
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (!isControlled) {
|
|
942
|
-
var currentValue = currentState.value;
|
|
943
|
-
var formattedValue = maskUtils.formatValue(currentValue);
|
|
944
|
-
var isValueEmpty = maskUtils.isValueEmpty(formattedValue);
|
|
945
|
-
var shouldFormatValue = !isValueEmpty || isFocused || alwaysShowMask;
|
|
946
|
-
|
|
947
|
-
if (shouldFormatValue) {
|
|
948
|
-
newInputState.value = formattedValue;
|
|
949
|
-
} else if (isValueEmpty && !isFocused) {
|
|
950
|
-
newInputState.value = "";
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
if (isFocused && !previousIsMasked) {
|
|
955
|
-
// Adjust selection if input got masked while being focused
|
|
956
|
-
newInputState.selection = maskUtils.getDefaultSelectionForValue(newInputState.value);
|
|
957
|
-
} else if (isControlled && isFocused && previousSelection) {
|
|
958
|
-
// Restore cursor position if value has changed outside change event
|
|
959
|
-
if (previousSelection.start !== null && previousSelection.end !== null) {
|
|
960
|
-
newInputState.selection = previousSelection;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
if (beforeMaskedStateChange) {
|
|
965
|
-
newInputState = beforeMaskedStateChange({
|
|
966
|
-
currentState: currentState,
|
|
967
|
-
nextState: newInputState
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
setInputState(newInputState);
|
|
972
|
-
});
|
|
973
|
-
|
|
974
|
-
var inputProps = _extends({}, restProps, {
|
|
975
|
-
onFocus: onFocus,
|
|
976
|
-
onBlur: onBlur,
|
|
977
|
-
onChange: isMasked && isEditable ? onChange : props.onChange,
|
|
978
|
-
onMouseDown: isMasked && isEditable ? onMouseDown : props.onMouseDown,
|
|
979
|
-
ref: function ref(_ref) {
|
|
980
|
-
inputRef.current = _ref;
|
|
981
|
-
|
|
982
|
-
if (isFunction(forwardedRef)) {
|
|
983
|
-
forwardedRef(_ref);
|
|
984
|
-
} else if (forwardedRef !== null && typeof forwardedRef === "object") {
|
|
985
|
-
forwardedRef.current = _ref;
|
|
986
|
-
}
|
|
987
|
-
},
|
|
988
|
-
value: isMasked && isControlled ? lastValue : props.value
|
|
989
|
-
});
|
|
990
|
-
|
|
991
|
-
if (children) {
|
|
992
|
-
validateChildren(props, children); // We wrap children into a class component to be able to find
|
|
993
|
-
// their input element using findDOMNode
|
|
994
|
-
|
|
995
|
-
return React__default.createElement(InputMaskChildrenWrapper, inputProps, children);
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
return React__default.createElement("input", inputProps);
|
|
999
|
-
});
|
|
1000
|
-
InputMask.displayName = "InputMask";
|
|
1001
|
-
InputMask.defaultProps = {
|
|
1002
|
-
alwaysShowMask: false,
|
|
1003
|
-
maskPlaceholder: "_"
|
|
1004
|
-
};
|
|
1005
|
-
InputMask.propTypes = {
|
|
1006
|
-
alwaysShowMask: PropTypes.bool,
|
|
1007
|
-
beforeMaskedStateChange: PropTypes.func,
|
|
1008
|
-
children: PropTypes.element,
|
|
1009
|
-
mask: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)]))]),
|
|
1010
|
-
maskPlaceholder: PropTypes.string,
|
|
1011
|
-
onFocus: PropTypes.func,
|
|
1012
|
-
onBlur: PropTypes.func,
|
|
1013
|
-
onChange: PropTypes.func,
|
|
1014
|
-
onMouseDown: PropTypes.func
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
module.exports = InputMask;
|