ngx-mask 11.1.2 → 12.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/bundles/ngx-mask.umd.js +80 -42
- package/bundles/ngx-mask.umd.js.map +1 -1
- package/esm2015/index.js +1 -1
- package/esm2015/lib/config.js +1 -1
- package/esm2015/lib/custom-keyboard-event.js +1 -1
- package/esm2015/lib/mask-applier.service.js +21 -6
- package/esm2015/lib/mask.directive.js +18 -14
- package/esm2015/lib/mask.pipe.js +1 -1
- package/esm2015/lib/mask.service.js +14 -9
- package/esm2015/lib/ngx-mask.module.js +1 -1
- package/esm2015/ngx-mask.js +1 -1
- package/fesm2015/ngx-mask.js +50 -26
- package/fesm2015/ngx-mask.js.map +1 -1
- package/lib/mask-applier.service.d.ts +2 -1
- package/lib/mask.directive.d.ts +0 -1
- package/lib/mask.service.d.ts +3 -2
- package/ngx-mask.metadata.json +1 -1
- package/package.json +3 -3
- package/bundles/ngx-mask.umd.min.js +0 -2
- package/bundles/ngx-mask.umd.min.js.map +0 -1
package/bundles/ngx-mask.umd.js
CHANGED
|
@@ -100,6 +100,8 @@
|
|
|
100
100
|
return extendStatics(d, b);
|
|
101
101
|
};
|
|
102
102
|
function __extends(d, b) {
|
|
103
|
+
if (typeof b !== "function" && b !== null)
|
|
104
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
103
105
|
extendStatics(d, b);
|
|
104
106
|
function __() { this.constructor = d; }
|
|
105
107
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -285,11 +287,13 @@
|
|
|
285
287
|
}
|
|
286
288
|
return ar;
|
|
287
289
|
}
|
|
290
|
+
/** @deprecated */
|
|
288
291
|
function __spread() {
|
|
289
292
|
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
290
293
|
ar = ar.concat(__read(arguments[i]));
|
|
291
294
|
return ar;
|
|
292
295
|
}
|
|
296
|
+
/** @deprecated */
|
|
293
297
|
function __spreadArrays() {
|
|
294
298
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
295
299
|
s += arguments[i].length;
|
|
@@ -298,7 +302,11 @@
|
|
|
298
302
|
r[k] = a[j];
|
|
299
303
|
return r;
|
|
300
304
|
}
|
|
301
|
-
|
|
305
|
+
function __spreadArray(to, from) {
|
|
306
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
307
|
+
to[j] = from[i];
|
|
308
|
+
return to;
|
|
309
|
+
}
|
|
302
310
|
function __await(v) {
|
|
303
311
|
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
304
312
|
}
|
|
@@ -363,18 +371,21 @@
|
|
|
363
371
|
function __importDefault(mod) {
|
|
364
372
|
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
365
373
|
}
|
|
366
|
-
function __classPrivateFieldGet(receiver,
|
|
367
|
-
if (!
|
|
368
|
-
throw new TypeError("
|
|
369
|
-
|
|
370
|
-
|
|
374
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
375
|
+
if (kind === "a" && !f)
|
|
376
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
377
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
378
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
379
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
371
380
|
}
|
|
372
|
-
function __classPrivateFieldSet(receiver,
|
|
373
|
-
if (
|
|
374
|
-
throw new TypeError("
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
382
|
+
if (kind === "m")
|
|
383
|
+
throw new TypeError("Private method is not writable");
|
|
384
|
+
if (kind === "a" && !f)
|
|
385
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
386
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
387
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
388
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
378
389
|
}
|
|
379
390
|
|
|
380
391
|
var MaskApplierService = /** @class */ (function () {
|
|
@@ -419,6 +430,17 @@
|
|
|
419
430
|
}
|
|
420
431
|
return Infinity;
|
|
421
432
|
};
|
|
433
|
+
this.checkAndRemoveSuffix = function (inputValue) {
|
|
434
|
+
var _a, _b, _c;
|
|
435
|
+
for (var i = ((_a = _this.suffix) === null || _a === void 0 ? void 0 : _a.length) - 1; i >= 0; i--) {
|
|
436
|
+
var substr = _this.suffix.substr(i, (_b = _this.suffix) === null || _b === void 0 ? void 0 : _b.length);
|
|
437
|
+
if (inputValue.includes(substr) &&
|
|
438
|
+
(i - 1 < 0 || !inputValue.includes(_this.suffix.substr(i - 1, (_c = _this.suffix) === null || _c === void 0 ? void 0 : _c.length)))) {
|
|
439
|
+
return inputValue.replace(substr, '');
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return inputValue;
|
|
443
|
+
};
|
|
422
444
|
this.checkInputPrecision = function (inputValue, precision, decimalMarker) {
|
|
423
445
|
if (precision < Infinity) {
|
|
424
446
|
var precisionRegEx = new RegExp(_this._charToRegExpExpression(decimalMarker) + ("\\d{" + precision + "}.*$"));
|
|
@@ -451,13 +473,15 @@
|
|
|
451
473
|
this.leadZeroDateTime = this._config.leadZeroDateTime;
|
|
452
474
|
}
|
|
453
475
|
MaskApplierService.prototype.applyMaskWithPattern = function (inputValue, maskAndPattern) {
|
|
454
|
-
var
|
|
476
|
+
var _d = __read(maskAndPattern, 2), mask = _d[0], customPattern = _d[1];
|
|
455
477
|
this.customPattern = customPattern;
|
|
456
478
|
return this.applyMask(inputValue, mask);
|
|
457
479
|
};
|
|
458
|
-
MaskApplierService.prototype.applyMask = function (inputValue, maskExpression, position, justPasted, cb) {
|
|
480
|
+
MaskApplierService.prototype.applyMask = function (inputValue, maskExpression, position, justPasted, backspaced, cb) {
|
|
481
|
+
var _this = this;
|
|
459
482
|
if (position === void 0) { position = 0; }
|
|
460
483
|
if (justPasted === void 0) { justPasted = false; }
|
|
484
|
+
if (backspaced === void 0) { backspaced = false; }
|
|
461
485
|
if (cb === void 0) { cb = function () { }; }
|
|
462
486
|
if (inputValue === undefined || inputValue === null || maskExpression === undefined) {
|
|
463
487
|
return '';
|
|
@@ -471,8 +495,8 @@
|
|
|
471
495
|
if (inputValue.slice(0, this.prefix.length) === this.prefix) {
|
|
472
496
|
inputValue = inputValue.slice(this.prefix.length, inputValue.length);
|
|
473
497
|
}
|
|
474
|
-
if (!!this.suffix && inputValue.
|
|
475
|
-
inputValue =
|
|
498
|
+
if (!!this.suffix && (inputValue === null || inputValue === void 0 ? void 0 : inputValue.length) > 0) {
|
|
499
|
+
inputValue = this.checkAndRemoveSuffix(inputValue);
|
|
476
500
|
}
|
|
477
501
|
var inputArray = inputValue.toString().split('');
|
|
478
502
|
if (maskExpression === 'IP') {
|
|
@@ -520,7 +544,7 @@
|
|
|
520
544
|
inputValue = this._stripToDecimal(inputValue);
|
|
521
545
|
}
|
|
522
546
|
inputValue =
|
|
523
|
-
inputValue.length > 1 && inputValue[0] === '0' && inputValue[1] !== this.decimalMarker
|
|
547
|
+
inputValue.length > 1 && inputValue[0] === '0' && inputValue[1] !== this.decimalMarker && !backspaced
|
|
524
548
|
? inputValue.slice(1, inputValue.length)
|
|
525
549
|
: inputValue;
|
|
526
550
|
// TODO: we had different rexexps here for the different cases... but tests dont seam to bother - check this
|
|
@@ -748,7 +772,11 @@
|
|
|
748
772
|
if (shift < 0) {
|
|
749
773
|
this._shift.clear();
|
|
750
774
|
}
|
|
751
|
-
var
|
|
775
|
+
var onlySpecial = false;
|
|
776
|
+
if (backspaced) {
|
|
777
|
+
onlySpecial = inputArray.every(function (char) { return _this.maskSpecialCharacters.includes(char); });
|
|
778
|
+
}
|
|
779
|
+
var res = "" + this.prefix + (onlySpecial ? '' : result) + this.suffix;
|
|
752
780
|
if (result.length === 0) {
|
|
753
781
|
res = "" + this.prefix + result;
|
|
754
782
|
}
|
|
@@ -815,14 +843,16 @@
|
|
|
815
843
|
* since writeValue should be a one way only process of writing the DOM value based on the Angular model value.
|
|
816
844
|
*/
|
|
817
845
|
_this.writingValue = false;
|
|
846
|
+
_this.maskChanged = false;
|
|
818
847
|
_this.onChange = function (_) { };
|
|
819
848
|
return _this;
|
|
820
849
|
}
|
|
821
850
|
// tslint:disable-next-line:cyclomatic-complexity
|
|
822
|
-
MaskService.prototype.applyMask = function (inputValue, maskExpression, position, justPasted, cb) {
|
|
851
|
+
MaskService.prototype.applyMask = function (inputValue, maskExpression, position, justPasted, backspaced, cb) {
|
|
823
852
|
var _this = this;
|
|
824
853
|
if (position === void 0) { position = 0; }
|
|
825
854
|
if (justPasted === void 0) { justPasted = false; }
|
|
855
|
+
if (backspaced === void 0) { backspaced = false; }
|
|
826
856
|
if (cb === void 0) { cb = function () { }; }
|
|
827
857
|
if (!maskExpression) {
|
|
828
858
|
return inputValue;
|
|
@@ -840,7 +870,7 @@
|
|
|
840
870
|
}
|
|
841
871
|
var getSymbol = !!inputValue && typeof this.selStart === 'number' ? inputValue[this.selStart] : '';
|
|
842
872
|
var newInputValue = '';
|
|
843
|
-
if (this.hiddenInput
|
|
873
|
+
if (this.hiddenInput && !this.writingValue) {
|
|
844
874
|
var actualResult = this.actualValue.split('');
|
|
845
875
|
// tslint:disable no-unused-expression
|
|
846
876
|
inputValue !== '' && actualResult.length
|
|
@@ -855,10 +885,13 @@
|
|
|
855
885
|
: null
|
|
856
886
|
: (actualResult = []);
|
|
857
887
|
// tslint:enable no-unused-expression
|
|
858
|
-
newInputValue =
|
|
888
|
+
newInputValue =
|
|
889
|
+
this.actualValue.length && actualResult.length <= inputValue.length
|
|
890
|
+
? this.shiftTypedSymbols(actualResult.join(''))
|
|
891
|
+
: inputValue;
|
|
859
892
|
}
|
|
860
893
|
newInputValue = Boolean(newInputValue) && newInputValue.length ? newInputValue : inputValue;
|
|
861
|
-
var result = _super.prototype.applyMask.call(this, newInputValue, maskExpression, position, justPasted, cb);
|
|
894
|
+
var result = _super.prototype.applyMask.call(this, newInputValue, maskExpression, position, justPasted, backspaced, cb);
|
|
862
895
|
this.actualValue = this.getActualValue(result);
|
|
863
896
|
// handle some separator implications:
|
|
864
897
|
// a.) adjust decimalMarker default (. -> ,) if thousandSeparator is a dot
|
|
@@ -898,11 +931,11 @@
|
|
|
898
931
|
}
|
|
899
932
|
return countSkipedSymbol;
|
|
900
933
|
};
|
|
901
|
-
MaskService.prototype.applyValueChanges = function (position, justPasted, cb) {
|
|
934
|
+
MaskService.prototype.applyValueChanges = function (position, justPasted, backspaced, cb) {
|
|
902
935
|
if (position === void 0) { position = 0; }
|
|
903
936
|
if (cb === void 0) { cb = function () { }; }
|
|
904
937
|
var formElement = this._elementRef.nativeElement;
|
|
905
|
-
formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, cb);
|
|
938
|
+
formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, backspaced, cb);
|
|
906
939
|
if (formElement === this.document.activeElement) {
|
|
907
940
|
return;
|
|
908
941
|
}
|
|
@@ -1079,7 +1112,8 @@
|
|
|
1079
1112
|
* @param inputValue the current form input value
|
|
1080
1113
|
*/
|
|
1081
1114
|
MaskService.prototype.formControlResult = function (inputValue) {
|
|
1082
|
-
if (this.writingValue) {
|
|
1115
|
+
if (this.writingValue || this.maskChanged) {
|
|
1116
|
+
this.maskChanged = false;
|
|
1083
1117
|
return;
|
|
1084
1118
|
}
|
|
1085
1119
|
if (Array.isArray(this.dropSpecialCharacters)) {
|
|
@@ -1093,7 +1127,7 @@
|
|
|
1093
1127
|
}
|
|
1094
1128
|
};
|
|
1095
1129
|
MaskService.prototype._toNumber = function (value) {
|
|
1096
|
-
if (!this.isNumberValue) {
|
|
1130
|
+
if (!this.isNumberValue || value === '') {
|
|
1097
1131
|
return value;
|
|
1098
1132
|
}
|
|
1099
1133
|
var num = Number(value);
|
|
@@ -1200,6 +1234,9 @@
|
|
|
1200
1234
|
MaskDirective.prototype.ngOnChanges = function (changes) {
|
|
1201
1235
|
var maskExpression = changes.maskExpression, specialCharacters = changes.specialCharacters, patterns = changes.patterns, prefix = changes.prefix, suffix = changes.suffix, thousandSeparator = changes.thousandSeparator, decimalMarker = changes.decimalMarker, dropSpecialCharacters = changes.dropSpecialCharacters, hiddenInput = changes.hiddenInput, showMaskTyped = changes.showMaskTyped, placeHolderCharacter = changes.placeHolderCharacter, shownMaskExpression = changes.shownMaskExpression, showTemplate = changes.showTemplate, clearIfNotMatch = changes.clearIfNotMatch, validation = changes.validation, separatorLimit = changes.separatorLimit, allowNegativeNumbers = changes.allowNegativeNumbers, leadZeroDateTime = changes.leadZeroDateTime;
|
|
1202
1236
|
if (maskExpression) {
|
|
1237
|
+
if (maskExpression.currentValue !== maskExpression.previousValue && !maskExpression.firstChange) {
|
|
1238
|
+
this._maskService.maskChanged = true;
|
|
1239
|
+
}
|
|
1203
1240
|
this._maskValue = maskExpression.currentValue || '';
|
|
1204
1241
|
if (maskExpression.currentValue && maskExpression.currentValue.split('||').length > 1) {
|
|
1205
1242
|
this._maskExpressionArray = maskExpression.currentValue.split('||').sort(function (a, b) {
|
|
@@ -1273,8 +1310,8 @@
|
|
|
1273
1310
|
this._applyMask();
|
|
1274
1311
|
};
|
|
1275
1312
|
// tslint:disable-next-line: cyclomatic-complexity
|
|
1276
|
-
MaskDirective.prototype.validate = function (
|
|
1277
|
-
var value =
|
|
1313
|
+
MaskDirective.prototype.validate = function (_c) {
|
|
1314
|
+
var value = _c.value;
|
|
1278
1315
|
if (!this._maskService.validation || !this._maskValue) {
|
|
1279
1316
|
return null;
|
|
1280
1317
|
}
|
|
@@ -1365,7 +1402,7 @@
|
|
|
1365
1402
|
: el.selectionStart;
|
|
1366
1403
|
var caretShift = 0;
|
|
1367
1404
|
var backspaceShift = false;
|
|
1368
|
-
this._maskService.applyValueChanges(position, this._justPasted, function (shift, _backspaceShift) {
|
|
1405
|
+
this._maskService.applyValueChanges(position, this._justPasted, this._code === 'Backspace' || this._code === 'Delete', function (shift, _backspaceShift) {
|
|
1369
1406
|
_this._justPasted = false;
|
|
1370
1407
|
caretShift = shift;
|
|
1371
1408
|
backspaceShift = _backspaceShift;
|
|
@@ -1381,6 +1418,9 @@
|
|
|
1381
1418
|
if (positionToApply > this._getActualInputLength()) {
|
|
1382
1419
|
positionToApply = this._getActualInputLength();
|
|
1383
1420
|
}
|
|
1421
|
+
if (positionToApply < 0) {
|
|
1422
|
+
positionToApply = 0;
|
|
1423
|
+
}
|
|
1384
1424
|
el.setSelectionRange(positionToApply, positionToApply);
|
|
1385
1425
|
this._position = null;
|
|
1386
1426
|
};
|
|
@@ -1456,7 +1496,8 @@
|
|
|
1456
1496
|
}
|
|
1457
1497
|
if (e.keyCode === 8 && el.selectionStart !== 0) {
|
|
1458
1498
|
// If specialChars is false, (shouldn't ever happen) then set to the defaults
|
|
1459
|
-
this.specialCharacters = ((_a = this.specialCharacters) === null || _a === void 0 ? void 0 : _a.length)
|
|
1499
|
+
this.specialCharacters = ((_a = this.specialCharacters) === null || _a === void 0 ? void 0 : _a.length)
|
|
1500
|
+
? this.specialCharacters
|
|
1460
1501
|
: this._config.specialCharacters;
|
|
1461
1502
|
if (this.prefix.length > 1 && el.selectionStart <= this.prefix.length) {
|
|
1462
1503
|
el.setSelectionRange(this.prefix.length, this.prefix.length);
|
|
@@ -1506,7 +1547,7 @@
|
|
|
1506
1547
|
/** It writes the value in the input */
|
|
1507
1548
|
MaskDirective.prototype.writeValue = function (inputValue) {
|
|
1508
1549
|
return __awaiter(this, void 0, void 0, function () {
|
|
1509
|
-
return __generator(this, function (
|
|
1550
|
+
return __generator(this, function (_c) {
|
|
1510
1551
|
if (typeof inputValue === 'object' && inputValue !== null && 'value' in inputValue) {
|
|
1511
1552
|
if ('disable' in inputValue) {
|
|
1512
1553
|
this.setDisabledState(Boolean(inputValue.disable));
|
|
@@ -1521,6 +1562,8 @@
|
|
|
1521
1562
|
inputValue = this.decimalMarker !== '.' ? inputValue.replace('.', this.decimalMarker) : inputValue;
|
|
1522
1563
|
this._maskService.isNumberValue = true;
|
|
1523
1564
|
}
|
|
1565
|
+
this._inputValue = inputValue;
|
|
1566
|
+
this._setMask();
|
|
1524
1567
|
if ((inputValue && this._maskService.maskExpression) ||
|
|
1525
1568
|
(this._maskService.maskExpression && (this._maskService.prefix || this._maskService.showMaskTyped))) {
|
|
1526
1569
|
// Let the service we know we are writing value so that triggering onChange function wont happen during applyMask
|
|
@@ -1566,11 +1609,6 @@
|
|
|
1566
1609
|
MaskDirective.prototype.setDisabledState = function (isDisabled) {
|
|
1567
1610
|
this._maskService.formElementProperty = ['disabled', isDisabled];
|
|
1568
1611
|
};
|
|
1569
|
-
MaskDirective.prototype.onModelChange = function (e) {
|
|
1570
|
-
if (!e) {
|
|
1571
|
-
this._maskService.actualValue = '';
|
|
1572
|
-
}
|
|
1573
|
-
};
|
|
1574
1612
|
MaskDirective.prototype._repeatPatternSymbols = function (maskExp) {
|
|
1575
1613
|
var _this = this;
|
|
1576
1614
|
return ((maskExp.match(/{[0-9]+}/) &&
|
|
@@ -1581,8 +1619,8 @@
|
|
|
1581
1619
|
}
|
|
1582
1620
|
_this._end = index;
|
|
1583
1621
|
var repeatNumber = Number(maskExp.slice(_this._start + 1, _this._end));
|
|
1584
|
-
var
|
|
1585
|
-
return accum +
|
|
1622
|
+
var replaceWith = new Array(repeatNumber + 1).join(maskExp[_this._start - 1]);
|
|
1623
|
+
return accum + replaceWith;
|
|
1586
1624
|
}, '')) ||
|
|
1587
1625
|
maskExp);
|
|
1588
1626
|
};
|
|
@@ -1596,7 +1634,7 @@
|
|
|
1596
1634
|
};
|
|
1597
1635
|
MaskDirective.prototype._validateTime = function (value) {
|
|
1598
1636
|
var rowMaskLen = this._maskValue.split('').filter(function (s) { return s !== ':'; }).length;
|
|
1599
|
-
if (value
|
|
1637
|
+
if (!value) {
|
|
1600
1638
|
return null; // Don't validate empty values to allow for optional form control
|
|
1601
1639
|
}
|
|
1602
1640
|
if ((+value[value.length - 1] === 0 && value.length < rowMaskLen) || value.length <= rowMaskLen - 2) {
|
|
@@ -1619,7 +1657,8 @@
|
|
|
1619
1657
|
var _this = this;
|
|
1620
1658
|
if (this._maskExpressionArray.length > 0) {
|
|
1621
1659
|
this._maskExpressionArray.some(function (mask) {
|
|
1622
|
-
var
|
|
1660
|
+
var _a, _b;
|
|
1661
|
+
var test = ((_a = _this._maskService.removeMask(_this._inputValue)) === null || _a === void 0 ? void 0 : _a.length) <= ((_b = _this._maskService.removeMask(mask)) === null || _b === void 0 ? void 0 : _b.length);
|
|
1623
1662
|
if (_this._inputValue && test) {
|
|
1624
1663
|
_this._maskValue = mask;
|
|
1625
1664
|
_this.maskExpression = mask;
|
|
@@ -1682,8 +1721,7 @@
|
|
|
1682
1721
|
onInput: [{ type: core.HostListener, args: ['input', ['$event'],] }],
|
|
1683
1722
|
onBlur: [{ type: core.HostListener, args: ['blur',] }],
|
|
1684
1723
|
onFocus: [{ type: core.HostListener, args: ['click', ['$event'],] }],
|
|
1685
|
-
onKeyDown: [{ type: core.HostListener, args: ['keydown', ['$event'],] }]
|
|
1686
|
-
onModelChange: [{ type: core.HostListener, args: ['ngModelChange', ['$event'],] }]
|
|
1724
|
+
onKeyDown: [{ type: core.HostListener, args: ['keydown', ['$event'],] }]
|
|
1687
1725
|
};
|
|
1688
1726
|
|
|
1689
1727
|
var MaskPipe = /** @class */ (function () {
|