ngx-mask 13.2.1-test → 13.2.2
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/esm2020/lib/ngx-mask-applier.service.mjs +88 -23
- package/esm2020/lib/ngx-mask.directive.mjs +77 -20
- package/esm2020/lib/ngx-mask.pipe.mjs +4 -1
- package/esm2020/lib/ngx-mask.service.mjs +29 -4
- package/fesm2015/ngx-mask.mjs +197 -46
- package/fesm2015/ngx-mask.mjs.map +1 -1
- package/fesm2020/ngx-mask.mjs +194 -44
- package/fesm2020/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +1 -0
- package/lib/ngx-mask.directive.d.ts +2 -0
- package/lib/ngx-mask.service.d.ts +4 -3
- package/package.json +1 -1
package/fesm2020/ngx-mask.mjs
CHANGED
|
@@ -96,6 +96,7 @@ class NgxMaskApplierService {
|
|
|
96
96
|
constructor(_config) {
|
|
97
97
|
this._config = _config;
|
|
98
98
|
this._shift = new Set();
|
|
99
|
+
this.plusOnePosition = false;
|
|
99
100
|
this.maskExpression = '';
|
|
100
101
|
this.actualValue = '';
|
|
101
102
|
this.showKeepCharacterExp = '';
|
|
@@ -222,7 +223,7 @@ class NgxMaskApplierService {
|
|
|
222
223
|
let backspaceShift = false;
|
|
223
224
|
let shift = 1;
|
|
224
225
|
let stepBack = false;
|
|
225
|
-
if (inputValue.slice(0, this.prefix.length) === this.prefix
|
|
226
|
+
if (inputValue.slice(0, this.prefix.length) === this.prefix) {
|
|
226
227
|
// eslint-disable-next-line no-param-reassign
|
|
227
228
|
inputValue = inputValue.slice(this.prefix.length, inputValue.length);
|
|
228
229
|
}
|
|
@@ -306,24 +307,91 @@ class NgxMaskApplierService {
|
|
|
306
307
|
// eslint-disable-next-line no-param-reassign
|
|
307
308
|
inputValue = this._stripToDecimal(inputValue);
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
const precision = this.getPrecision(maskExpression);
|
|
311
|
+
const decimalMarker = Array.isArray(this.decimalMarker)
|
|
312
|
+
? "." /* DOT */
|
|
313
|
+
: this.decimalMarker;
|
|
314
|
+
if (precision === 0) {
|
|
315
|
+
// eslint-disable-next-line no-param-reassign
|
|
316
|
+
inputValue = this.allowNegativeNumbers
|
|
312
317
|
? inputValue.length > 2 &&
|
|
313
|
-
inputValue[
|
|
318
|
+
inputValue[0] === "-" /* MINUS */ &&
|
|
319
|
+
inputValue[1] === "0" /* NUMBER_ZERO */ &&
|
|
314
320
|
inputValue[2] !== this.thousandSeparator &&
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
? inputValue.slice(
|
|
318
|
-
: inputValue
|
|
321
|
+
inputValue[2] !== "," /* COMMA */ &&
|
|
322
|
+
inputValue[2] !== "." /* DOT */
|
|
323
|
+
? '-' + inputValue.slice(2, inputValue.length)
|
|
324
|
+
: inputValue[0] === "0" /* NUMBER_ZERO */ &&
|
|
325
|
+
inputValue.length > 1 &&
|
|
326
|
+
inputValue[1] !== this.thousandSeparator &&
|
|
327
|
+
inputValue[1] !== "," /* COMMA */ &&
|
|
328
|
+
inputValue[1] !== "." /* DOT */
|
|
329
|
+
? inputValue.slice(1, inputValue.length)
|
|
330
|
+
: inputValue
|
|
319
331
|
: inputValue.length > 1 &&
|
|
320
|
-
inputValue[0] ===
|
|
332
|
+
inputValue[0] === "0" /* NUMBER_ZERO */ &&
|
|
321
333
|
inputValue[1] !== this.thousandSeparator &&
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
? inputValue.slice(
|
|
334
|
+
inputValue[1] !== "," /* COMMA */ &&
|
|
335
|
+
inputValue[1] !== "." /* DOT */
|
|
336
|
+
? inputValue.slice(1, inputValue.length)
|
|
325
337
|
: inputValue;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
// eslint-disable-next-line no-param-reassign
|
|
341
|
+
if (inputValue[0] === decimalMarker && inputValue.length > 1) {
|
|
342
|
+
// eslint-disable-next-line no-param-reassign
|
|
343
|
+
inputValue =
|
|
344
|
+
"0" /* NUMBER_ZERO */ + inputValue.slice(0, inputValue.length + 1);
|
|
345
|
+
this.plusOnePosition = true;
|
|
346
|
+
}
|
|
347
|
+
if (inputValue[0] === "0" /* NUMBER_ZERO */ &&
|
|
348
|
+
inputValue[1] !== decimalMarker &&
|
|
349
|
+
inputValue[1] !== this.thousandSeparator) {
|
|
350
|
+
// eslint-disable-next-line no-param-reassign
|
|
351
|
+
inputValue =
|
|
352
|
+
inputValue.length > 1
|
|
353
|
+
? inputValue.slice(0, 1) +
|
|
354
|
+
decimalMarker +
|
|
355
|
+
inputValue.slice(1, inputValue.length + 1)
|
|
356
|
+
: inputValue;
|
|
357
|
+
this.plusOnePosition = true;
|
|
358
|
+
}
|
|
359
|
+
if (this.allowNegativeNumbers &&
|
|
360
|
+
inputValue[0] === "-" /* MINUS */ &&
|
|
361
|
+
(inputValue[1] === decimalMarker ||
|
|
362
|
+
inputValue[1] === "0" /* NUMBER_ZERO */)) {
|
|
363
|
+
// eslint-disable-next-line no-param-reassign
|
|
364
|
+
inputValue =
|
|
365
|
+
inputValue[1] === decimalMarker && inputValue.length > 2
|
|
366
|
+
? inputValue.slice(0, 1) +
|
|
367
|
+
"0" /* NUMBER_ZERO */ +
|
|
368
|
+
inputValue.slice(1, inputValue.length)
|
|
369
|
+
: inputValue[1] === "0" /* NUMBER_ZERO */ &&
|
|
370
|
+
inputValue.length > 2 &&
|
|
371
|
+
inputValue[2] !== decimalMarker
|
|
372
|
+
? inputValue.slice(0, 2) +
|
|
373
|
+
decimalMarker +
|
|
374
|
+
inputValue.slice(2, inputValue.length)
|
|
375
|
+
: inputValue;
|
|
376
|
+
this.plusOnePosition = true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
326
379
|
if (backspaced) {
|
|
380
|
+
if (inputValue[0] === "0" /* NUMBER_ZERO */ &&
|
|
381
|
+
inputValue[1] === this.decimalMarker &&
|
|
382
|
+
(inputValue[position] === "0" /* NUMBER_ZERO */ ||
|
|
383
|
+
inputValue[position] === this.decimalMarker)) {
|
|
384
|
+
// eslint-disable-next-line no-param-reassign
|
|
385
|
+
inputValue = inputValue.slice(2, inputValue.length);
|
|
386
|
+
}
|
|
387
|
+
if (inputValue[0] === "-" /* MINUS */ &&
|
|
388
|
+
inputValue[1] === "0" /* NUMBER_ZERO */ &&
|
|
389
|
+
inputValue[2] === this.decimalMarker &&
|
|
390
|
+
(inputValue[position] === "0" /* NUMBER_ZERO */ ||
|
|
391
|
+
inputValue[position] === this.decimalMarker)) {
|
|
392
|
+
// eslint-disable-next-line no-param-reassign
|
|
393
|
+
inputValue = "-" /* MINUS */ + inputValue.slice(3, inputValue.length);
|
|
394
|
+
}
|
|
327
395
|
// eslint-disable-next-line no-param-reassign
|
|
328
396
|
inputValue = this._compareOrIncludes(inputValue[inputValue.length - 1], this.decimalMarker, this.thousandSeparator)
|
|
329
397
|
? inputValue.slice(0, inputValue.length - 1)
|
|
@@ -343,13 +411,10 @@ class NgxMaskApplierService {
|
|
|
343
411
|
invalidChars = invalidChars.replace(this._charToRegExpExpression(this.decimalMarker), '');
|
|
344
412
|
}
|
|
345
413
|
const invalidCharRegexp = new RegExp('[' + invalidChars + ']');
|
|
346
|
-
if (inputValue.match(invalidCharRegexp)
|
|
347
|
-
(inputValue.length === 1 &&
|
|
348
|
-
this._compareOrIncludes(inputValue, this.decimalMarker, this.thousandSeparator))) {
|
|
414
|
+
if (inputValue.match(invalidCharRegexp)) {
|
|
349
415
|
// eslint-disable-next-line no-param-reassign
|
|
350
416
|
inputValue = inputValue.substring(0, inputValue.length - 1);
|
|
351
417
|
}
|
|
352
|
-
const precision = this.getPrecision(maskExpression);
|
|
353
418
|
// eslint-disable-next-line no-param-reassign
|
|
354
419
|
inputValue = this.checkInputPrecision(inputValue, precision, this.decimalMarker);
|
|
355
420
|
const strForSep = inputValue.replace(new RegExp(thousandSeparatorCharEscaped, 'g'), '');
|
|
@@ -422,7 +487,7 @@ class NgxMaskApplierService {
|
|
|
422
487
|
if (maskExpression[cursor] === "H" /* HOURS */) {
|
|
423
488
|
if (this.apm ? Number(inputSymbol) > 9 : Number(inputSymbol) > 2) {
|
|
424
489
|
// eslint-disable-next-line no-param-reassign
|
|
425
|
-
position = position + 1;
|
|
490
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
426
491
|
cursor += 1;
|
|
427
492
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
428
493
|
i--;
|
|
@@ -458,7 +523,7 @@ class NgxMaskApplierService {
|
|
|
458
523
|
maskExpression[cursor] === "s" /* SECOND */) {
|
|
459
524
|
if (Number(inputSymbol) > 5) {
|
|
460
525
|
// eslint-disable-next-line no-param-reassign
|
|
461
|
-
position = position + 1;
|
|
526
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
462
527
|
cursor += 1;
|
|
463
528
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
464
529
|
i--;
|
|
@@ -496,7 +561,7 @@ class NgxMaskApplierService {
|
|
|
496
561
|
: Number(inputValueSliceCursorPlusTwo) > daysCount ||
|
|
497
562
|
this.specialCharacters.includes(inputValueCursorPlusOne))) {
|
|
498
563
|
// eslint-disable-next-line no-param-reassign
|
|
499
|
-
position = position + 1;
|
|
564
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
500
565
|
cursor += 1;
|
|
501
566
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
502
567
|
i--;
|
|
@@ -552,7 +617,7 @@ class NgxMaskApplierService {
|
|
|
552
617
|
day2monthInput ||
|
|
553
618
|
(day2monthInputDot && !this.leadZeroDateTime)) {
|
|
554
619
|
// eslint-disable-next-line no-param-reassign
|
|
555
|
-
position = position + 1;
|
|
620
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
556
621
|
cursor += 1;
|
|
557
622
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
558
623
|
i--;
|
|
@@ -647,7 +712,7 @@ class NgxMaskApplierService {
|
|
|
647
712
|
if (backspaced) {
|
|
648
713
|
onlySpecial = inputArray.every((char) => this.specialCharacters.includes(char));
|
|
649
714
|
}
|
|
650
|
-
let res = `${this.prefix}${onlySpecial ? "" /* EMPTY_STRING */ : result}${this.suffix}`;
|
|
715
|
+
let res = `${this.prefix}${onlySpecial ? "" /* EMPTY_STRING */ : result}${this.showMaskTyped ? '' : this.suffix}`;
|
|
651
716
|
if (result.length === 0) {
|
|
652
717
|
res = !this.dropSpecialCharacters ? `${this.prefix}${result}` : `${result}`;
|
|
653
718
|
}
|
|
@@ -792,7 +857,7 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
792
857
|
}
|
|
793
858
|
if (!inputValue && this.showMaskTyped) {
|
|
794
859
|
this.formControlResult(this.prefix);
|
|
795
|
-
return this.prefix + this.maskIsShown;
|
|
860
|
+
return this.prefix + this.maskIsShown + this.suffix;
|
|
796
861
|
}
|
|
797
862
|
const getSymbol = !!inputValue && typeof this.selStart === 'number'
|
|
798
863
|
? inputValue[this.selStart] ?? "" /* EMPTY_STRING */
|
|
@@ -838,6 +903,11 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
838
903
|
if (justPasted && (this.hiddenInput || !this.hiddenInput)) {
|
|
839
904
|
newInputValue = inputValue;
|
|
840
905
|
}
|
|
906
|
+
if (backspaced &&
|
|
907
|
+
this.specialCharacters.indexOf(this.maskExpression[position] ?? "" /* EMPTY_STRING */) !== -1 &&
|
|
908
|
+
this.showMaskTyped) {
|
|
909
|
+
newInputValue = this._currentValue;
|
|
910
|
+
}
|
|
841
911
|
if (this.deletedSpecialCharacter && position) {
|
|
842
912
|
if (this.specialCharacters.includes(this.actualValue.slice(position, position + 1))) {
|
|
843
913
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -906,7 +976,7 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
906
976
|
return result;
|
|
907
977
|
}
|
|
908
978
|
const resLen = result.length;
|
|
909
|
-
const prefNmask = this.prefix + this.maskIsShown;
|
|
979
|
+
const prefNmask = this.prefix + this.maskIsShown + this.suffix;
|
|
910
980
|
if (this.maskExpression.includes("H" /* HOURS */)) {
|
|
911
981
|
const countSkipedSymbol = this._numberSkipedSymbols(result);
|
|
912
982
|
return result + prefNmask.slice(resLen + countSkipedSymbol);
|
|
@@ -1219,11 +1289,17 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1219
1289
|
return value ? value.replace(this.suffix, "" /* EMPTY_STRING */) : value;
|
|
1220
1290
|
}
|
|
1221
1291
|
_retrieveSeparatorValue(result) {
|
|
1222
|
-
|
|
1292
|
+
let specialCharacters = Array.isArray(this.dropSpecialCharacters)
|
|
1223
1293
|
? this.specialCharacters.filter((v) => {
|
|
1224
1294
|
return this.dropSpecialCharacters.includes(v);
|
|
1225
1295
|
})
|
|
1226
1296
|
: this.specialCharacters;
|
|
1297
|
+
if (!this.deletedSpecialCharacter &&
|
|
1298
|
+
this._checkPatternForSpace() &&
|
|
1299
|
+
result.includes(" " /* WHITE_SPACE */) &&
|
|
1300
|
+
this.maskExpression.includes("*" /* SYMBOL_STAR */)) {
|
|
1301
|
+
specialCharacters = specialCharacters.filter((char) => char !== " " /* WHITE_SPACE */);
|
|
1302
|
+
}
|
|
1227
1303
|
return this._removeMask(result, specialCharacters);
|
|
1228
1304
|
}
|
|
1229
1305
|
_regExpForRemove(specialCharactersForRemove) {
|
|
@@ -1262,6 +1338,20 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1262
1338
|
return separatorValue;
|
|
1263
1339
|
}
|
|
1264
1340
|
}
|
|
1341
|
+
_checkPatternForSpace() {
|
|
1342
|
+
for (const key in this.patterns) {
|
|
1343
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
1344
|
+
if (this.patterns[key] && this.patterns[key]?.hasOwnProperty('pattern')) {
|
|
1345
|
+
const patternString = this.patterns[key]?.pattern.toString();
|
|
1346
|
+
const pattern = this.patterns[key]?.pattern;
|
|
1347
|
+
if (patternString?.includes(" " /* WHITE_SPACE */) &&
|
|
1348
|
+
pattern?.test(this.maskExpression)) {
|
|
1349
|
+
return true;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return false;
|
|
1354
|
+
}
|
|
1265
1355
|
// TODO should think about helpers or separting decimal precision to own property
|
|
1266
1356
|
_retrieveSeparatorPrecision(maskExpretion) {
|
|
1267
1357
|
const matcher = maskExpretion.match(new RegExp(`^separator\\.([^d]*)`));
|
|
@@ -1363,6 +1453,7 @@ class NgxMaskDirective {
|
|
|
1363
1453
|
this.keepCharacterPositions = null;
|
|
1364
1454
|
this.maskFilled = new EventEmitter();
|
|
1365
1455
|
this._maskValue = '';
|
|
1456
|
+
this._isFocused = false;
|
|
1366
1457
|
this._position = null;
|
|
1367
1458
|
this._maskExpressionArray = [];
|
|
1368
1459
|
this._justPasted = false;
|
|
@@ -1380,13 +1471,6 @@ class NgxMaskDirective {
|
|
|
1380
1471
|
!maskExpression.firstChange) {
|
|
1381
1472
|
this._maskService.maskChanged = true;
|
|
1382
1473
|
}
|
|
1383
|
-
if (allowNegativeNumbers) {
|
|
1384
|
-
this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
|
|
1385
|
-
if (this._maskService.allowNegativeNumbers) {
|
|
1386
|
-
this._maskService.specialCharacters =
|
|
1387
|
-
this._maskService.specialCharacters.filter((c) => c !== "-" /* MINUS */);
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
1474
|
if (maskExpression.currentValue &&
|
|
1391
1475
|
maskExpression.currentValue.split("||" /* OR */).length > 1) {
|
|
1392
1476
|
this._maskExpressionArray = maskExpression.currentValue
|
|
@@ -1410,6 +1494,12 @@ class NgxMaskDirective {
|
|
|
1410
1494
|
this._maskService.specialCharacters = specialCharacters.currentValue || [];
|
|
1411
1495
|
}
|
|
1412
1496
|
}
|
|
1497
|
+
if (allowNegativeNumbers) {
|
|
1498
|
+
this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
|
|
1499
|
+
if (this._maskService.allowNegativeNumbers) {
|
|
1500
|
+
this._maskService.specialCharacters = this._maskService.specialCharacters.filter((c) => c !== "-" /* MINUS */);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1413
1503
|
// Only overwrite the mask available patterns if a pattern has actually been passed in
|
|
1414
1504
|
if (patterns && patterns.currentValue) {
|
|
1415
1505
|
this._maskService.patterns = patterns.currentValue;
|
|
@@ -1437,6 +1527,13 @@ class NgxMaskDirective {
|
|
|
1437
1527
|
}
|
|
1438
1528
|
if (showMaskTyped) {
|
|
1439
1529
|
this._maskService.showMaskTyped = showMaskTyped.currentValue;
|
|
1530
|
+
if (showMaskTyped.previousValue === false &&
|
|
1531
|
+
showMaskTyped.currentValue === true &&
|
|
1532
|
+
this._isFocused) {
|
|
1533
|
+
requestAnimationFrame(() => {
|
|
1534
|
+
this._maskService._elementRef?.nativeElement.click();
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1440
1537
|
}
|
|
1441
1538
|
if (placeHolderCharacter) {
|
|
1442
1539
|
this._maskService.placeHolderCharacter = placeHolderCharacter.currentValue;
|
|
@@ -1596,6 +1693,9 @@ class NgxMaskDirective {
|
|
|
1596
1693
|
onPaste() {
|
|
1597
1694
|
this._justPasted = true;
|
|
1598
1695
|
}
|
|
1696
|
+
onFocus() {
|
|
1697
|
+
this._isFocused = true;
|
|
1698
|
+
}
|
|
1599
1699
|
onModelChange(value) {
|
|
1600
1700
|
// on form reset we need to update the actualValue
|
|
1601
1701
|
if ((value === "" /* EMPTY_STRING */ || value === null || value === undefined) &&
|
|
@@ -1696,13 +1796,33 @@ class NgxMaskDirective {
|
|
|
1696
1796
|
position = position + 1;
|
|
1697
1797
|
}
|
|
1698
1798
|
else if (checkSymbols) {
|
|
1799
|
+
if (el.value.length === 1 && position === 1) {
|
|
1800
|
+
this._maskService.actualValue =
|
|
1801
|
+
this.prefix +
|
|
1802
|
+
inputSymbol +
|
|
1803
|
+
this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
|
|
1804
|
+
this.suffix;
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
this._maskService.actualValue =
|
|
1808
|
+
el.value.slice(0, position - 1) +
|
|
1809
|
+
inputSymbol +
|
|
1810
|
+
el.value
|
|
1811
|
+
.slice(position + 1)
|
|
1812
|
+
.split(this.suffix)
|
|
1813
|
+
.join('') +
|
|
1814
|
+
this.suffix;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
else if (this.prefix &&
|
|
1818
|
+
el.value.length === 1 &&
|
|
1819
|
+
position - prefixLength === 1 &&
|
|
1820
|
+
this._maskService._checkSymbolMask(el.value, this._maskService.maskExpression[position - 1 - prefixLength] ??
|
|
1821
|
+
"" /* EMPTY_STRING */)) {
|
|
1699
1822
|
this._maskService.actualValue =
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
.slice(position + 1)
|
|
1704
|
-
.split(this.suffix)
|
|
1705
|
-
.join('') +
|
|
1823
|
+
this.prefix +
|
|
1824
|
+
el.value +
|
|
1825
|
+
this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
|
|
1706
1826
|
this.suffix;
|
|
1707
1827
|
}
|
|
1708
1828
|
}
|
|
@@ -1722,6 +1842,13 @@ class NgxMaskDirective {
|
|
|
1722
1842
|
inputSymbol +
|
|
1723
1843
|
this._inputValue.slice(position + 1);
|
|
1724
1844
|
}
|
|
1845
|
+
if (this._maskService.maskExpression === "d0/M0/0000" /* DAYS_MONTHS_YEARS */ &&
|
|
1846
|
+
this.leadZeroDateTime) {
|
|
1847
|
+
if ((position < 3 && Number(el.value) > 31 && Number(el.value) < 40) ||
|
|
1848
|
+
(position === 5 && Number(el.value.slice(3, 5)) > 12)) {
|
|
1849
|
+
position = position + 2;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1725
1852
|
if (this._maskService.maskExpression === "Hh:m0:s0" /* HOURS_MINUTES_SECONDS */ &&
|
|
1726
1853
|
this.apm) {
|
|
1727
1854
|
if (this._justPasted && el.value.slice(0, 2) === "00" /* DOUBLE_ZERO */) {
|
|
@@ -1741,6 +1868,10 @@ class NgxMaskDirective {
|
|
|
1741
1868
|
if (this._getActiveElement() !== el) {
|
|
1742
1869
|
return;
|
|
1743
1870
|
}
|
|
1871
|
+
if (this._maskService.plusOnePosition) {
|
|
1872
|
+
position = position + 1;
|
|
1873
|
+
this._maskService.plusOnePosition = false;
|
|
1874
|
+
}
|
|
1744
1875
|
// update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
|
|
1745
1876
|
if (this._maskExpressionArray.length) {
|
|
1746
1877
|
if (this._code === "Backspace" /* BACKSPACE */) {
|
|
@@ -1762,7 +1893,10 @@ class NgxMaskDirective {
|
|
|
1762
1893
|
: position +
|
|
1763
1894
|
(this._code === "Backspace" /* BACKSPACE */ && !backspaceShift ? 0 : caretShift);
|
|
1764
1895
|
if (positionToApply > this._getActualInputLength()) {
|
|
1765
|
-
positionToApply =
|
|
1896
|
+
positionToApply =
|
|
1897
|
+
el.value === this._maskService.decimalMarker && el.value.length === 1
|
|
1898
|
+
? this._getActualInputLength() + 1
|
|
1899
|
+
: this._getActualInputLength();
|
|
1766
1900
|
}
|
|
1767
1901
|
if (positionToApply < 0) {
|
|
1768
1902
|
positionToApply = 0;
|
|
@@ -1775,6 +1909,10 @@ class NgxMaskDirective {
|
|
|
1775
1909
|
}
|
|
1776
1910
|
}
|
|
1777
1911
|
else {
|
|
1912
|
+
if (!this._maskValue) {
|
|
1913
|
+
this.onChange(el.value);
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1778
1916
|
this._maskService.applyValueChanges(el.value.length, this._justPasted, this._code === "Backspace" /* BACKSPACE */ || this._code === "Delete" /* DELETE */);
|
|
1779
1917
|
}
|
|
1780
1918
|
}
|
|
@@ -1810,6 +1948,7 @@ class NgxMaskDirective {
|
|
|
1810
1948
|
}
|
|
1811
1949
|
this._maskService.clearIfNotMatchFn();
|
|
1812
1950
|
}
|
|
1951
|
+
this._isFocused = false;
|
|
1813
1952
|
this.onTouch();
|
|
1814
1953
|
}
|
|
1815
1954
|
onClick(e) {
|
|
@@ -1943,13 +2082,12 @@ class NgxMaskDirective {
|
|
|
1943
2082
|
}
|
|
1944
2083
|
}
|
|
1945
2084
|
/** It writes the value in the input */
|
|
1946
|
-
// public async writeValue(controlValue: unknown): Promise<void> {
|
|
1947
2085
|
async writeValue(controlValue) {
|
|
1948
2086
|
if (typeof controlValue === 'object' && controlValue !== null && 'value' in controlValue) {
|
|
1949
2087
|
if ('disable' in controlValue) {
|
|
1950
2088
|
this.setDisabledState(Boolean(controlValue.disable));
|
|
1951
2089
|
}
|
|
1952
|
-
//
|
|
2090
|
+
// eslint-disable-next-line no-param-reassign
|
|
1953
2091
|
controlValue = controlValue.value;
|
|
1954
2092
|
}
|
|
1955
2093
|
if (controlValue !== null) {
|
|
@@ -1960,7 +2098,12 @@ class NgxMaskDirective {
|
|
|
1960
2098
|
}
|
|
1961
2099
|
if (typeof controlValue === 'string' ||
|
|
1962
2100
|
typeof controlValue === 'number' ||
|
|
1963
|
-
controlValue === null
|
|
2101
|
+
controlValue === null ||
|
|
2102
|
+
controlValue === undefined) {
|
|
2103
|
+
if (controlValue === null || controlValue === undefined || controlValue === '') {
|
|
2104
|
+
this._maskService._currentValue = '';
|
|
2105
|
+
this._maskService._previousValue = '';
|
|
2106
|
+
}
|
|
1964
2107
|
// eslint-disable-next-line no-param-reassign
|
|
1965
2108
|
let inputValue = controlValue;
|
|
1966
2109
|
if (typeof inputValue === 'number' ||
|
|
@@ -2112,7 +2255,8 @@ class NgxMaskDirective {
|
|
|
2112
2255
|
}
|
|
2113
2256
|
}
|
|
2114
2257
|
else {
|
|
2115
|
-
const check = this.
|
|
2258
|
+
const check = this._maskService
|
|
2259
|
+
.removeMask(this._inputValue)
|
|
2116
2260
|
?.split("" /* EMPTY_STRING */)
|
|
2117
2261
|
.every((character, index) => {
|
|
2118
2262
|
const indexMask = mask.charAt(index);
|
|
@@ -2127,7 +2271,7 @@ class NgxMaskDirective {
|
|
|
2127
2271
|
}
|
|
2128
2272
|
}
|
|
2129
2273
|
NgxMaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: NgxMaskDirective, deps: [{ token: DOCUMENT }, { token: NGX_MASK_CONFIG }, { token: NgxMaskService }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2130
|
-
NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: NgxMaskDirective, selector: "input[mask], textarea[mask]", inputs: { maskExpression: ["mask", "maskExpression"], specialCharacters: "specialCharacters", patterns: "patterns", prefix: "prefix", suffix: "suffix", thousandSeparator: "thousandSeparator", decimalMarker: "decimalMarker", dropSpecialCharacters: "dropSpecialCharacters", hiddenInput: "hiddenInput", showMaskTyped: "showMaskTyped", placeHolderCharacter: "placeHolderCharacter", shownMaskExpression: "shownMaskExpression", showTemplate: "showTemplate", clearIfNotMatch: "clearIfNotMatch", validation: "validation", separatorLimit: "separatorLimit", allowNegativeNumbers: "allowNegativeNumbers", leadZeroDateTime: "leadZeroDateTime", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
|
|
2274
|
+
NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: NgxMaskDirective, selector: "input[mask], textarea[mask]", inputs: { maskExpression: ["mask", "maskExpression"], specialCharacters: "specialCharacters", patterns: "patterns", prefix: "prefix", suffix: "suffix", thousandSeparator: "thousandSeparator", decimalMarker: "decimalMarker", dropSpecialCharacters: "dropSpecialCharacters", hiddenInput: "hiddenInput", showMaskTyped: "showMaskTyped", placeHolderCharacter: "placeHolderCharacter", shownMaskExpression: "shownMaskExpression", showTemplate: "showTemplate", clearIfNotMatch: "clearIfNotMatch", validation: "validation", separatorLimit: "separatorLimit", allowNegativeNumbers: "allowNegativeNumbers", leadZeroDateTime: "leadZeroDateTime", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "focus": "onFocus($event)", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
|
|
2131
2275
|
{
|
|
2132
2276
|
provide: NG_VALUE_ACCESSOR,
|
|
2133
2277
|
useExisting: forwardRef(() => NgxMaskDirective),
|
|
@@ -2219,6 +2363,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
2219
2363
|
}], onPaste: [{
|
|
2220
2364
|
type: HostListener,
|
|
2221
2365
|
args: ['paste']
|
|
2366
|
+
}], onFocus: [{
|
|
2367
|
+
type: HostListener,
|
|
2368
|
+
args: ['focus', ['$event']]
|
|
2222
2369
|
}], onModelChange: [{
|
|
2223
2370
|
type: HostListener,
|
|
2224
2371
|
args: ['ngModelChange', ['$event']]
|
|
@@ -2312,6 +2459,9 @@ class NgxMaskPipe {
|
|
|
2312
2459
|
}
|
|
2313
2460
|
this._maskService.isNumberValue = true;
|
|
2314
2461
|
}
|
|
2462
|
+
if (value === null || value === undefined) {
|
|
2463
|
+
return this._maskService.applyMask('', mask);
|
|
2464
|
+
}
|
|
2315
2465
|
return this._maskService.applyMask(`${value}`, mask);
|
|
2316
2466
|
}
|
|
2317
2467
|
_setMask(value) {
|