ngx-mask 19.0.0 → 19.0.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/fesm2022/ngx-mask.mjs +233 -289
- package/fesm2022/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +0 -2
- package/lib/ngx-mask.config.d.ts +0 -1
- package/lib/ngx-mask.directive.d.ts +30 -27
- package/lib/ngx-mask.pipe.d.ts +1 -1
- package/lib/ngx-mask.service.d.ts +4 -4
- package/package.json +1 -1
package/fesm2022/ngx-mask.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, EventEmitter, inject, Injectable, ElementRef, Renderer2, makeEnvironmentProviders,
|
|
2
|
+
import { InjectionToken, EventEmitter, inject, Injectable, ElementRef, Renderer2, makeEnvironmentProviders, input, output, signal, Directive, HostListener, Pipe } from '@angular/core';
|
|
3
3
|
import { DOCUMENT } from '@angular/common';
|
|
4
4
|
import { NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
5
5
|
|
|
@@ -57,7 +57,6 @@ const initialConfig = {
|
|
|
57
57
|
thousandSeparator: ' ',
|
|
58
58
|
decimalMarker: ['.', ','],
|
|
59
59
|
clearIfNotMatch: false,
|
|
60
|
-
showTemplate: false,
|
|
61
60
|
showMaskTyped: false,
|
|
62
61
|
placeHolderCharacter: '_',
|
|
63
62
|
dropSpecialCharacters: true,
|
|
@@ -140,7 +139,6 @@ class NgxMaskApplierService {
|
|
|
140
139
|
_config = inject(NGX_MASK_CONFIG);
|
|
141
140
|
dropSpecialCharacters = this._config.dropSpecialCharacters;
|
|
142
141
|
hiddenInput = this._config.hiddenInput;
|
|
143
|
-
showTemplate;
|
|
144
142
|
clearIfNotMatch = this._config.clearIfNotMatch;
|
|
145
143
|
specialCharacters = this._config.specialCharacters;
|
|
146
144
|
patterns = this._config.patterns;
|
|
@@ -169,11 +167,6 @@ class NgxMaskApplierService {
|
|
|
169
167
|
deletedSpecialCharacter = false;
|
|
170
168
|
ipError;
|
|
171
169
|
cpfCnpjError;
|
|
172
|
-
applyMaskWithPattern(inputValue, maskAndPattern) {
|
|
173
|
-
const [mask, customPattern] = maskAndPattern;
|
|
174
|
-
this.customPattern = customPattern;
|
|
175
|
-
return this.applyMask(inputValue, mask);
|
|
176
|
-
}
|
|
177
170
|
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false, cb = () => { }) {
|
|
178
171
|
if (!maskExpression || typeof inputValue !== 'string') {
|
|
179
172
|
return MaskExpression.EMPTY_STRING;
|
|
@@ -875,12 +868,12 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
875
868
|
maskIsShown = '';
|
|
876
869
|
selStart = null;
|
|
877
870
|
selEnd = null;
|
|
878
|
-
writingValue = false;
|
|
879
871
|
maskChanged = false;
|
|
880
|
-
|
|
872
|
+
maskExpressionArray = [];
|
|
881
873
|
triggerOnMaskChange = false;
|
|
882
|
-
|
|
883
|
-
|
|
874
|
+
previousValue = '';
|
|
875
|
+
currentValue = '';
|
|
876
|
+
writingValue = false;
|
|
884
877
|
_emitValue = false;
|
|
885
878
|
_start;
|
|
886
879
|
_end;
|
|
@@ -949,7 +942,7 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
949
942
|
this.specialCharacters.indexOf(this.maskExpression[newPosition] ?? MaskExpression.EMPTY_STRING) !== -1 &&
|
|
950
943
|
this.showMaskTyped &&
|
|
951
944
|
!this.prefix) {
|
|
952
|
-
newInputValue = this.
|
|
945
|
+
newInputValue = this.currentValue;
|
|
953
946
|
}
|
|
954
947
|
if (this.deletedSpecialCharacter && newPosition) {
|
|
955
948
|
if (this.specialCharacters.includes(this.actualValue.slice(newPosition, newPosition + 1))) {
|
|
@@ -996,13 +989,13 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
996
989
|
this.specialCharacters = this.specialCharacters.filter((item) => !this._compareOrIncludes(item, this.decimalMarker, this.thousandSeparator));
|
|
997
990
|
}
|
|
998
991
|
if (result || result === '') {
|
|
999
|
-
this.
|
|
1000
|
-
this.
|
|
992
|
+
this.previousValue = this.currentValue;
|
|
993
|
+
this.currentValue = result;
|
|
1001
994
|
this._emitValue =
|
|
1002
|
-
this.
|
|
995
|
+
this.previousValue !== this.currentValue ||
|
|
1003
996
|
this.maskChanged ||
|
|
1004
997
|
this.writingValue ||
|
|
1005
|
-
(this.
|
|
998
|
+
(this.previousValue === this.currentValue && justPasted);
|
|
1006
999
|
}
|
|
1007
1000
|
this._emitValue
|
|
1008
1001
|
? this.writingValue && this.triggerOnMaskChange
|
|
@@ -1462,65 +1455,60 @@ function provideEnvironmentNgxMask(configValue) {
|
|
|
1462
1455
|
}
|
|
1463
1456
|
|
|
1464
1457
|
class NgxMaskDirective {
|
|
1465
|
-
|
|
1466
|
-
specialCharacters = [];
|
|
1467
|
-
patterns = {};
|
|
1468
|
-
prefix = '';
|
|
1469
|
-
suffix = '';
|
|
1470
|
-
thousandSeparator = ' ';
|
|
1471
|
-
decimalMarker = '.';
|
|
1472
|
-
dropSpecialCharacters = null;
|
|
1473
|
-
hiddenInput = null;
|
|
1474
|
-
showMaskTyped = null;
|
|
1475
|
-
placeHolderCharacter = null;
|
|
1476
|
-
shownMaskExpression = null;
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
_isComposing = false;
|
|
1499
|
-
document = inject(DOCUMENT);
|
|
1458
|
+
mask = input('');
|
|
1459
|
+
specialCharacters = input([]);
|
|
1460
|
+
patterns = input({});
|
|
1461
|
+
prefix = input('');
|
|
1462
|
+
suffix = input('');
|
|
1463
|
+
thousandSeparator = input(' ');
|
|
1464
|
+
decimalMarker = input('.');
|
|
1465
|
+
dropSpecialCharacters = input(null);
|
|
1466
|
+
hiddenInput = input(null);
|
|
1467
|
+
showMaskTyped = input(null);
|
|
1468
|
+
placeHolderCharacter = input(null);
|
|
1469
|
+
shownMaskExpression = input(null);
|
|
1470
|
+
clearIfNotMatch = input(null);
|
|
1471
|
+
validation = input(null);
|
|
1472
|
+
separatorLimit = input('');
|
|
1473
|
+
allowNegativeNumbers = input(null);
|
|
1474
|
+
leadZeroDateTime = input(null);
|
|
1475
|
+
leadZero = input(null);
|
|
1476
|
+
triggerOnMaskChange = input(null);
|
|
1477
|
+
apm = input(null);
|
|
1478
|
+
inputTransformFn = input(null);
|
|
1479
|
+
outputTransformFn = input(null);
|
|
1480
|
+
keepCharacterPositions = input(null);
|
|
1481
|
+
maskFilled = output();
|
|
1482
|
+
_maskValue = signal('');
|
|
1483
|
+
_inputValue = signal('');
|
|
1484
|
+
_position = signal(null);
|
|
1485
|
+
_code = signal('');
|
|
1486
|
+
_maskExpressionArray = signal([]);
|
|
1487
|
+
_allowFewMaskChangeMask = signal(false);
|
|
1488
|
+
_justPasted = signal(false);
|
|
1489
|
+
_isFocused = signal(false);
|
|
1490
|
+
_isComposing = signal(false);
|
|
1500
1491
|
_maskService = inject(NgxMaskService, { self: true });
|
|
1492
|
+
document = inject(DOCUMENT);
|
|
1501
1493
|
_config = inject(NGX_MASK_CONFIG);
|
|
1502
1494
|
onChange = (_) => { };
|
|
1503
1495
|
onTouch = () => { };
|
|
1504
1496
|
ngOnChanges(changes) {
|
|
1505
|
-
const {
|
|
1506
|
-
if (
|
|
1507
|
-
if (
|
|
1508
|
-
!maskExpression.firstChange) {
|
|
1497
|
+
const { mask, specialCharacters, patterns, prefix, suffix, thousandSeparator, decimalMarker, dropSpecialCharacters, hiddenInput, showMaskTyped, placeHolderCharacter, shownMaskExpression, clearIfNotMatch, validation, separatorLimit, allowNegativeNumbers, leadZeroDateTime, leadZero, triggerOnMaskChange, apm, inputTransformFn, outputTransformFn, keepCharacterPositions, } = changes;
|
|
1498
|
+
if (mask) {
|
|
1499
|
+
if (mask.currentValue !== mask.previousValue && !mask.firstChange) {
|
|
1509
1500
|
this._maskService.maskChanged = true;
|
|
1510
1501
|
}
|
|
1511
|
-
if (
|
|
1512
|
-
|
|
1513
|
-
this._maskExpressionArray = maskExpression.currentValue
|
|
1514
|
-
.split(MaskExpression.OR)
|
|
1515
|
-
.sort((a, b) => {
|
|
1502
|
+
if (mask.currentValue && mask.currentValue.split(MaskExpression.OR).length > 1) {
|
|
1503
|
+
this._maskExpressionArray.set(mask.currentValue.split(MaskExpression.OR).sort((a, b) => {
|
|
1516
1504
|
return a.length - b.length;
|
|
1517
|
-
});
|
|
1505
|
+
}));
|
|
1518
1506
|
this._setMask();
|
|
1519
1507
|
}
|
|
1520
1508
|
else {
|
|
1521
|
-
this._maskExpressionArray
|
|
1522
|
-
this._maskValue
|
|
1523
|
-
this._maskService.maskExpression = this._maskValue;
|
|
1509
|
+
this._maskExpressionArray.set([]);
|
|
1510
|
+
this._maskValue.set(mask.currentValue || MaskExpression.EMPTY_STRING);
|
|
1511
|
+
this._maskService.maskExpression = this._maskValue();
|
|
1524
1512
|
}
|
|
1525
1513
|
}
|
|
1526
1514
|
if (specialCharacters) {
|
|
@@ -1565,7 +1553,7 @@ class NgxMaskDirective {
|
|
|
1565
1553
|
this._maskService.showMaskTyped = showMaskTyped.currentValue;
|
|
1566
1554
|
if (showMaskTyped.previousValue === false &&
|
|
1567
1555
|
showMaskTyped.currentValue === true &&
|
|
1568
|
-
this._isFocused) {
|
|
1556
|
+
this._isFocused()) {
|
|
1569
1557
|
requestAnimationFrame(() => {
|
|
1570
1558
|
this._maskService._elementRef?.nativeElement.click();
|
|
1571
1559
|
});
|
|
@@ -1577,9 +1565,6 @@ class NgxMaskDirective {
|
|
|
1577
1565
|
if (shownMaskExpression) {
|
|
1578
1566
|
this._maskService.shownMaskExpression = shownMaskExpression.currentValue;
|
|
1579
1567
|
}
|
|
1580
|
-
if (showTemplate) {
|
|
1581
|
-
this._maskService.showTemplate = showTemplate.currentValue;
|
|
1582
|
-
}
|
|
1583
1568
|
if (clearIfNotMatch) {
|
|
1584
1569
|
this._maskService.clearIfNotMatch = clearIfNotMatch.currentValue;
|
|
1585
1570
|
}
|
|
@@ -1611,7 +1596,8 @@ class NgxMaskDirective {
|
|
|
1611
1596
|
}
|
|
1612
1597
|
validate({ value }) {
|
|
1613
1598
|
const processedValue = typeof value === 'number' ? String(value) : value;
|
|
1614
|
-
|
|
1599
|
+
const maskValue = this._maskValue();
|
|
1600
|
+
if (!this._maskService.validation || !maskValue) {
|
|
1615
1601
|
return null;
|
|
1616
1602
|
}
|
|
1617
1603
|
if (this._maskService.ipError) {
|
|
@@ -1620,19 +1606,19 @@ class NgxMaskDirective {
|
|
|
1620
1606
|
if (this._maskService.cpfCnpjError) {
|
|
1621
1607
|
return this._createValidationError(processedValue);
|
|
1622
1608
|
}
|
|
1623
|
-
if (
|
|
1609
|
+
if (maskValue.startsWith(MaskExpression.SEPARATOR)) {
|
|
1624
1610
|
return null;
|
|
1625
1611
|
}
|
|
1626
|
-
if (withoutValidation.includes(
|
|
1612
|
+
if (withoutValidation.includes(maskValue)) {
|
|
1627
1613
|
return null;
|
|
1628
1614
|
}
|
|
1629
1615
|
if (this._maskService.clearIfNotMatch) {
|
|
1630
1616
|
return null;
|
|
1631
1617
|
}
|
|
1632
|
-
if (timeMasks.includes(
|
|
1618
|
+
if (timeMasks.includes(maskValue)) {
|
|
1633
1619
|
return this._validateTime(processedValue);
|
|
1634
1620
|
}
|
|
1635
|
-
if (
|
|
1621
|
+
if (maskValue === MaskExpression.EMAIL_MASK) {
|
|
1636
1622
|
const emailPattern = /^[^@]+@[^@]+\.[^@]+$/;
|
|
1637
1623
|
if (!emailPattern.test(processedValue) && processedValue) {
|
|
1638
1624
|
return this._createValidationError(processedValue);
|
|
@@ -1643,53 +1629,53 @@ class NgxMaskDirective {
|
|
|
1643
1629
|
}
|
|
1644
1630
|
if (processedValue && processedValue.length >= 1) {
|
|
1645
1631
|
let counterOfOpt = 0;
|
|
1646
|
-
if (
|
|
1647
|
-
|
|
1648
|
-
const lengthInsideCurlyBrackets =
|
|
1632
|
+
if (maskValue.includes(MaskExpression.CURLY_BRACKETS_LEFT) &&
|
|
1633
|
+
maskValue.includes(MaskExpression.CURLY_BRACKETS_RIGHT)) {
|
|
1634
|
+
const lengthInsideCurlyBrackets = maskValue.slice(maskValue.indexOf(MaskExpression.CURLY_BRACKETS_LEFT) + 1, maskValue.indexOf(MaskExpression.CURLY_BRACKETS_RIGHT));
|
|
1649
1635
|
return lengthInsideCurlyBrackets === String(processedValue.length)
|
|
1650
1636
|
? null
|
|
1651
1637
|
: this._createValidationError(processedValue);
|
|
1652
1638
|
}
|
|
1653
|
-
if (
|
|
1639
|
+
if (maskValue.startsWith(MaskExpression.PERCENT)) {
|
|
1654
1640
|
return null;
|
|
1655
1641
|
}
|
|
1656
1642
|
for (const key in this._maskService.patterns) {
|
|
1657
1643
|
if (this._maskService.patterns[key]?.optional) {
|
|
1658
|
-
if (
|
|
1659
|
-
const opt =
|
|
1644
|
+
if (maskValue.indexOf(key) !== maskValue.lastIndexOf(key)) {
|
|
1645
|
+
const opt = maskValue
|
|
1660
1646
|
.split(MaskExpression.EMPTY_STRING)
|
|
1661
1647
|
.filter((i) => i === key)
|
|
1662
1648
|
.join(MaskExpression.EMPTY_STRING);
|
|
1663
1649
|
counterOfOpt += opt.length;
|
|
1664
1650
|
}
|
|
1665
|
-
else if (
|
|
1651
|
+
else if (maskValue.indexOf(key) !== -1) {
|
|
1666
1652
|
counterOfOpt++;
|
|
1667
1653
|
}
|
|
1668
|
-
if (
|
|
1669
|
-
processedValue.length >=
|
|
1654
|
+
if (maskValue.indexOf(key) !== -1 &&
|
|
1655
|
+
processedValue.length >= maskValue.indexOf(key)) {
|
|
1670
1656
|
return null;
|
|
1671
1657
|
}
|
|
1672
|
-
if (counterOfOpt ===
|
|
1658
|
+
if (counterOfOpt === maskValue.length) {
|
|
1673
1659
|
return null;
|
|
1674
1660
|
}
|
|
1675
1661
|
}
|
|
1676
1662
|
}
|
|
1677
|
-
if ((
|
|
1678
|
-
processedValue.length <
|
|
1679
|
-
(
|
|
1680
|
-
processedValue.length <
|
|
1663
|
+
if ((maskValue.indexOf(MaskExpression.SYMBOL_STAR) > 1 &&
|
|
1664
|
+
processedValue.length < maskValue.indexOf(MaskExpression.SYMBOL_STAR)) ||
|
|
1665
|
+
(maskValue.indexOf(MaskExpression.SYMBOL_QUESTION) > 1 &&
|
|
1666
|
+
processedValue.length < maskValue.indexOf(MaskExpression.SYMBOL_QUESTION))) {
|
|
1681
1667
|
return this._createValidationError(processedValue);
|
|
1682
1668
|
}
|
|
1683
|
-
if (
|
|
1684
|
-
|
|
1685
|
-
const array =
|
|
1669
|
+
if (maskValue.indexOf(MaskExpression.SYMBOL_STAR) === -1 ||
|
|
1670
|
+
maskValue.indexOf(MaskExpression.SYMBOL_QUESTION) === -1) {
|
|
1671
|
+
const array = maskValue.split('*');
|
|
1686
1672
|
const length = this._maskService.dropSpecialCharacters
|
|
1687
|
-
?
|
|
1688
|
-
this._maskService.checkDropSpecialCharAmount(
|
|
1673
|
+
? maskValue.length -
|
|
1674
|
+
this._maskService.checkDropSpecialCharAmount(maskValue) -
|
|
1689
1675
|
counterOfOpt
|
|
1690
|
-
: this.prefix
|
|
1691
|
-
?
|
|
1692
|
-
:
|
|
1676
|
+
: this.prefix()
|
|
1677
|
+
? maskValue.length + this.prefix().length - counterOfOpt
|
|
1678
|
+
: maskValue.length - counterOfOpt;
|
|
1693
1679
|
if (array.length === 1) {
|
|
1694
1680
|
if (processedValue.length < length) {
|
|
1695
1681
|
return this._createValidationError(processedValue);
|
|
@@ -1700,7 +1686,7 @@ class NgxMaskDirective {
|
|
|
1700
1686
|
if (lastIndexArray &&
|
|
1701
1687
|
this._maskService.specialCharacters.includes(lastIndexArray[0]) &&
|
|
1702
1688
|
String(processedValue).includes(lastIndexArray[0] ?? '') &&
|
|
1703
|
-
!this.dropSpecialCharacters) {
|
|
1689
|
+
!this.dropSpecialCharacters()) {
|
|
1704
1690
|
const special = value.split(lastIndexArray[0]);
|
|
1705
1691
|
return special[special.length - 1].length === lastIndexArray.length - 1
|
|
1706
1692
|
? null
|
|
@@ -1718,8 +1704,8 @@ class NgxMaskDirective {
|
|
|
1718
1704
|
}
|
|
1719
1705
|
}
|
|
1720
1706
|
}
|
|
1721
|
-
if (
|
|
1722
|
-
|
|
1707
|
+
if (maskValue.indexOf(MaskExpression.SYMBOL_STAR) === 1 ||
|
|
1708
|
+
maskValue.indexOf(MaskExpression.SYMBOL_QUESTION) === 1) {
|
|
1723
1709
|
return null;
|
|
1724
1710
|
}
|
|
1725
1711
|
}
|
|
@@ -1730,10 +1716,10 @@ class NgxMaskDirective {
|
|
|
1730
1716
|
return null;
|
|
1731
1717
|
}
|
|
1732
1718
|
onPaste() {
|
|
1733
|
-
this._justPasted
|
|
1719
|
+
this._justPasted.set(true);
|
|
1734
1720
|
}
|
|
1735
1721
|
onFocus() {
|
|
1736
|
-
this._isFocused
|
|
1722
|
+
this._isFocused.set(true);
|
|
1737
1723
|
}
|
|
1738
1724
|
onModelChange(value) {
|
|
1739
1725
|
if ((value === MaskExpression.EMPTY_STRING ||
|
|
@@ -1744,7 +1730,7 @@ class NgxMaskDirective {
|
|
|
1744
1730
|
}
|
|
1745
1731
|
}
|
|
1746
1732
|
onInput(e) {
|
|
1747
|
-
if (this._isComposing) {
|
|
1733
|
+
if (this._isComposing()) {
|
|
1748
1734
|
return;
|
|
1749
1735
|
}
|
|
1750
1736
|
const el = e.target;
|
|
@@ -1752,20 +1738,22 @@ class NgxMaskDirective {
|
|
|
1752
1738
|
if (el.type !== 'number') {
|
|
1753
1739
|
if (typeof transformedValue === 'string' || typeof transformedValue === 'number') {
|
|
1754
1740
|
el.value = transformedValue.toString();
|
|
1755
|
-
this._inputValue
|
|
1741
|
+
this._inputValue.set(el.value);
|
|
1756
1742
|
this._setMask();
|
|
1757
|
-
if (!this._maskValue) {
|
|
1743
|
+
if (!this._maskValue()) {
|
|
1758
1744
|
this.onChange(el.value);
|
|
1759
1745
|
return;
|
|
1760
1746
|
}
|
|
1761
1747
|
let position = el.selectionStart === 1
|
|
1762
1748
|
? el.selectionStart + this._maskService.prefix.length
|
|
1763
1749
|
: el.selectionStart;
|
|
1764
|
-
if (this.showMaskTyped &&
|
|
1765
|
-
this.keepCharacterPositions &&
|
|
1750
|
+
if (this.showMaskTyped() &&
|
|
1751
|
+
this.keepCharacterPositions() &&
|
|
1766
1752
|
this._maskService.placeHolderCharacter.length === 1) {
|
|
1753
|
+
const suffix = this.suffix();
|
|
1754
|
+
const prefix = this.prefix();
|
|
1767
1755
|
const inputSymbol = el.value.slice(position - 1, position);
|
|
1768
|
-
const prefixLength =
|
|
1756
|
+
const prefixLength = prefix.length;
|
|
1769
1757
|
const checkSymbols = this._maskService._checkSymbolMask(inputSymbol, this._maskService.maskExpression[position - 1 - prefixLength] ??
|
|
1770
1758
|
MaskExpression.EMPTY_STRING);
|
|
1771
1759
|
const checkSpecialCharacter = this._maskService._checkSymbolMask(inputSymbol, this._maskService.maskExpression[position + 1 - prefixLength] ??
|
|
@@ -1773,32 +1761,32 @@ class NgxMaskDirective {
|
|
|
1773
1761
|
const selectRangeBackspace = this._maskService.selStart === this._maskService.selEnd;
|
|
1774
1762
|
const selStart = Number(this._maskService.selStart) - prefixLength;
|
|
1775
1763
|
const selEnd = Number(this._maskService.selEnd) - prefixLength;
|
|
1776
|
-
const backspaceOrDelete = this._code === MaskExpression.BACKSPACE ||
|
|
1777
|
-
this._code === MaskExpression.DELETE;
|
|
1764
|
+
const backspaceOrDelete = this._code() === MaskExpression.BACKSPACE ||
|
|
1765
|
+
this._code() === MaskExpression.DELETE;
|
|
1778
1766
|
if (backspaceOrDelete) {
|
|
1779
1767
|
if (!selectRangeBackspace) {
|
|
1780
1768
|
if (this._maskService.selStart === prefixLength) {
|
|
1781
|
-
this._maskService.actualValue = `${
|
|
1769
|
+
this._maskService.actualValue = `${prefix}${this._maskService.maskIsShown.slice(0, selEnd)}${this._inputValue().split(prefix).join('')}`;
|
|
1782
1770
|
}
|
|
1783
1771
|
else if (this._maskService.selStart ===
|
|
1784
1772
|
this._maskService.maskIsShown.length + prefixLength) {
|
|
1785
|
-
this._maskService.actualValue = `${this._inputValue}${this._maskService.maskIsShown.slice(selStart, selEnd)}`;
|
|
1773
|
+
this._maskService.actualValue = `${this._inputValue()}${this._maskService.maskIsShown.slice(selStart, selEnd)}`;
|
|
1786
1774
|
}
|
|
1787
1775
|
else {
|
|
1788
|
-
this._maskService.actualValue = `${
|
|
1789
|
-
.split(
|
|
1776
|
+
this._maskService.actualValue = `${prefix}${this._inputValue()
|
|
1777
|
+
.split(prefix)
|
|
1790
1778
|
.join('')
|
|
1791
|
-
.slice(0, selStart)}${this._maskService.maskIsShown.slice(selStart, selEnd)}${this._maskService.actualValue.slice(selEnd + prefixLength, this._maskService.maskIsShown.length + prefixLength)}${
|
|
1779
|
+
.slice(0, selStart)}${this._maskService.maskIsShown.slice(selStart, selEnd)}${this._maskService.actualValue.slice(selEnd + prefixLength, this._maskService.maskIsShown.length + prefixLength)}${suffix}`;
|
|
1792
1780
|
}
|
|
1793
1781
|
}
|
|
1794
|
-
else if (!this._maskService.specialCharacters.includes(this._maskService.maskExpression.slice(position -
|
|
1782
|
+
else if (!this._maskService.specialCharacters.includes(this._maskService.maskExpression.slice(position - prefixLength, position + 1 - prefixLength)) &&
|
|
1795
1783
|
selectRangeBackspace) {
|
|
1796
|
-
if (selStart === 1 &&
|
|
1797
|
-
this._maskService.actualValue = `${
|
|
1798
|
-
.split(
|
|
1784
|
+
if (selStart === 1 && prefix) {
|
|
1785
|
+
this._maskService.actualValue = `${prefix}${this._maskService.placeHolderCharacter}${el.value
|
|
1786
|
+
.split(prefix)
|
|
1799
1787
|
.join('')
|
|
1800
|
-
.split(
|
|
1801
|
-
.join('')}${
|
|
1788
|
+
.split(suffix)
|
|
1789
|
+
.join('')}${suffix}`;
|
|
1802
1790
|
position = position - 1;
|
|
1803
1791
|
}
|
|
1804
1792
|
else {
|
|
@@ -1807,7 +1795,7 @@ class NgxMaskDirective {
|
|
|
1807
1795
|
this._maskService.actualValue = `${part1}${this._maskService.placeHolderCharacter}${part2}`;
|
|
1808
1796
|
}
|
|
1809
1797
|
}
|
|
1810
|
-
position = this._code === MaskExpression.DELETE ? position + 1 : position;
|
|
1798
|
+
position = this._code() === MaskExpression.DELETE ? position + 1 : position;
|
|
1811
1799
|
}
|
|
1812
1800
|
if (!backspaceOrDelete) {
|
|
1813
1801
|
if (!checkSymbols && !checkSpecialCharacter && selectRangeBackspace) {
|
|
@@ -1821,49 +1809,49 @@ class NgxMaskDirective {
|
|
|
1821
1809
|
}
|
|
1822
1810
|
else if (checkSymbols) {
|
|
1823
1811
|
if (el.value.length === 1 && position === 1) {
|
|
1824
|
-
this._maskService.actualValue = `${
|
|
1812
|
+
this._maskService.actualValue = `${prefix}${inputSymbol}${this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length)}${suffix}`;
|
|
1825
1813
|
}
|
|
1826
1814
|
else {
|
|
1827
1815
|
this._maskService.actualValue = `${el.value.slice(0, position - 1)}${inputSymbol}${el.value
|
|
1828
1816
|
.slice(position + 1)
|
|
1829
|
-
.split(
|
|
1830
|
-
.join('')}${
|
|
1817
|
+
.split(suffix)
|
|
1818
|
+
.join('')}${suffix}`;
|
|
1831
1819
|
}
|
|
1832
1820
|
}
|
|
1833
|
-
else if (
|
|
1821
|
+
else if (prefix &&
|
|
1834
1822
|
el.value.length === 1 &&
|
|
1835
1823
|
position - prefixLength === 1 &&
|
|
1836
1824
|
this._maskService._checkSymbolMask(el.value, this._maskService.maskExpression[position - 1 - prefixLength] ??
|
|
1837
1825
|
MaskExpression.EMPTY_STRING)) {
|
|
1838
|
-
this._maskService.actualValue = `${
|
|
1826
|
+
this._maskService.actualValue = `${prefix}${el.value}${this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length)}${suffix}`;
|
|
1839
1827
|
}
|
|
1840
1828
|
}
|
|
1841
1829
|
}
|
|
1842
1830
|
let caretShift = 0;
|
|
1843
1831
|
let backspaceShift = false;
|
|
1844
|
-
if (this._code === MaskExpression.DELETE && MaskExpression.SEPARATOR) {
|
|
1832
|
+
if (this._code() === MaskExpression.DELETE && MaskExpression.SEPARATOR) {
|
|
1845
1833
|
this._maskService.deletedSpecialCharacter = true;
|
|
1846
1834
|
}
|
|
1847
|
-
if (this._inputValue.length >= this._maskService.maskExpression.length - 1 &&
|
|
1848
|
-
this._code !== MaskExpression.BACKSPACE &&
|
|
1835
|
+
if (this._inputValue().length >= this._maskService.maskExpression.length - 1 &&
|
|
1836
|
+
this._code() !== MaskExpression.BACKSPACE &&
|
|
1849
1837
|
this._maskService.maskExpression === MaskExpression.DAYS_MONTHS_YEARS &&
|
|
1850
1838
|
position < 10) {
|
|
1851
|
-
const inputSymbol = this._inputValue.slice(position - 1, position);
|
|
1839
|
+
const inputSymbol = this._inputValue().slice(position - 1, position);
|
|
1852
1840
|
el.value =
|
|
1853
|
-
this._inputValue.slice(0, position - 1) +
|
|
1841
|
+
this._inputValue().slice(0, position - 1) +
|
|
1854
1842
|
inputSymbol +
|
|
1855
|
-
this._inputValue.slice(position + 1);
|
|
1843
|
+
this._inputValue().slice(position + 1);
|
|
1856
1844
|
}
|
|
1857
1845
|
if (this._maskService.maskExpression === MaskExpression.DAYS_MONTHS_YEARS &&
|
|
1858
|
-
this.leadZeroDateTime) {
|
|
1846
|
+
this.leadZeroDateTime()) {
|
|
1859
1847
|
if ((position < 3 && Number(el.value) > 31 && Number(el.value) < 40) ||
|
|
1860
1848
|
(position === 5 && Number(el.value.slice(3, 5)) > 12)) {
|
|
1861
1849
|
position = position + 2;
|
|
1862
1850
|
}
|
|
1863
1851
|
}
|
|
1864
1852
|
if (this._maskService.maskExpression === MaskExpression.HOURS_MINUTES_SECONDS &&
|
|
1865
|
-
this.apm) {
|
|
1866
|
-
if (this._justPasted && el.value.slice(0, 2) === MaskExpression.DOUBLE_ZERO) {
|
|
1853
|
+
this.apm()) {
|
|
1854
|
+
if (this._justPasted() && el.value.slice(0, 2) === MaskExpression.DOUBLE_ZERO) {
|
|
1867
1855
|
el.value = el.value.slice(1, 2) + el.value.slice(2, el.value.length);
|
|
1868
1856
|
}
|
|
1869
1857
|
el.value =
|
|
@@ -1871,8 +1859,9 @@ class NgxMaskDirective {
|
|
|
1871
1859
|
? MaskExpression.NUMBER_ZERO
|
|
1872
1860
|
: el.value;
|
|
1873
1861
|
}
|
|
1874
|
-
this._maskService.applyValueChanges(position, this._justPasted, this._code === MaskExpression.BACKSPACE ||
|
|
1875
|
-
this.
|
|
1862
|
+
this._maskService.applyValueChanges(position, this._justPasted(), this._code() === MaskExpression.BACKSPACE ||
|
|
1863
|
+
this._code() === MaskExpression.DELETE, (shift, _backspaceShift) => {
|
|
1864
|
+
this._justPasted.set(false);
|
|
1876
1865
|
caretShift = shift;
|
|
1877
1866
|
backspaceShift = _backspaceShift;
|
|
1878
1867
|
});
|
|
@@ -1883,13 +1872,13 @@ class NgxMaskDirective {
|
|
|
1883
1872
|
position = position + 1;
|
|
1884
1873
|
this._maskService.plusOnePosition = false;
|
|
1885
1874
|
}
|
|
1886
|
-
if (this._maskExpressionArray.length) {
|
|
1887
|
-
if (this._code === MaskExpression.BACKSPACE) {
|
|
1888
|
-
const specialChartMinusOne = this.specialCharacters.includes(this._maskService.actualValue.slice(position - 1, position));
|
|
1889
|
-
const specialChartPlusOne = this.specialCharacters.includes(this._maskService.actualValue.slice(position, position + 1));
|
|
1890
|
-
if (this._allowFewMaskChangeMask && !specialChartPlusOne) {
|
|
1875
|
+
if (this._maskExpressionArray().length) {
|
|
1876
|
+
if (this._code() === MaskExpression.BACKSPACE) {
|
|
1877
|
+
const specialChartMinusOne = this.specialCharacters().includes(this._maskService.actualValue.slice(position - 1, position));
|
|
1878
|
+
const specialChartPlusOne = this.specialCharacters().includes(this._maskService.actualValue.slice(position, position + 1));
|
|
1879
|
+
if (this._allowFewMaskChangeMask() && !specialChartPlusOne) {
|
|
1891
1880
|
position = el.selectionStart + 1;
|
|
1892
|
-
this._allowFewMaskChangeMask
|
|
1881
|
+
this._allowFewMaskChangeMask.set(false);
|
|
1893
1882
|
}
|
|
1894
1883
|
else {
|
|
1895
1884
|
position = specialChartMinusOne ? position - 1 : position;
|
|
@@ -1902,12 +1891,15 @@ class NgxMaskDirective {
|
|
|
1902
1891
|
: el.selectionStart;
|
|
1903
1892
|
}
|
|
1904
1893
|
}
|
|
1905
|
-
this._position
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1894
|
+
this._position.set(this._position() === 1 && this._inputValue().length === 1
|
|
1895
|
+
? null
|
|
1896
|
+
: this._position());
|
|
1897
|
+
let positionToApply = this._position()
|
|
1898
|
+
? this._inputValue().length + position + caretShift
|
|
1909
1899
|
: position +
|
|
1910
|
-
(this._code === MaskExpression.BACKSPACE && !backspaceShift
|
|
1900
|
+
(this._code() === MaskExpression.BACKSPACE && !backspaceShift
|
|
1901
|
+
? 0
|
|
1902
|
+
: caretShift);
|
|
1911
1903
|
if (positionToApply > this._getActualInputLength()) {
|
|
1912
1904
|
positionToApply =
|
|
1913
1905
|
el.value === this._maskService.decimalMarker && el.value.length === 1
|
|
@@ -1918,59 +1910,59 @@ class NgxMaskDirective {
|
|
|
1918
1910
|
positionToApply = 0;
|
|
1919
1911
|
}
|
|
1920
1912
|
el.setSelectionRange(positionToApply, positionToApply);
|
|
1921
|
-
this._position
|
|
1913
|
+
this._position.set(null);
|
|
1922
1914
|
}
|
|
1923
1915
|
else {
|
|
1924
1916
|
console.warn('Ngx-mask writeValue work with string | number, your current value:', typeof transformedValue);
|
|
1925
1917
|
}
|
|
1926
1918
|
}
|
|
1927
1919
|
else {
|
|
1928
|
-
if (!this._maskValue) {
|
|
1920
|
+
if (!this._maskValue()) {
|
|
1929
1921
|
this.onChange(el.value);
|
|
1930
1922
|
return;
|
|
1931
1923
|
}
|
|
1932
|
-
this._maskService.applyValueChanges(el.value.length, this._justPasted, this._code === MaskExpression.BACKSPACE || this._code === MaskExpression.DELETE);
|
|
1924
|
+
this._maskService.applyValueChanges(el.value.length, this._justPasted(), this._code() === MaskExpression.BACKSPACE || this._code() === MaskExpression.DELETE);
|
|
1933
1925
|
}
|
|
1934
1926
|
}
|
|
1935
1927
|
onCompositionStart() {
|
|
1936
|
-
this._isComposing
|
|
1928
|
+
this._isComposing.set(true);
|
|
1937
1929
|
}
|
|
1938
1930
|
onCompositionEnd(e) {
|
|
1939
|
-
this._isComposing
|
|
1940
|
-
this._justPasted
|
|
1931
|
+
this._isComposing.set(false);
|
|
1932
|
+
this._justPasted.set(true);
|
|
1941
1933
|
this.onInput(e);
|
|
1942
1934
|
}
|
|
1943
1935
|
onBlur(e) {
|
|
1944
|
-
if (this._maskValue) {
|
|
1936
|
+
if (this._maskValue()) {
|
|
1945
1937
|
const el = e.target;
|
|
1946
1938
|
if (this._maskService.leadZero &&
|
|
1947
1939
|
el.value.length > 0 &&
|
|
1948
1940
|
typeof this._maskService.decimalMarker === 'string') {
|
|
1949
1941
|
const maskExpression = this._maskService.maskExpression;
|
|
1942
|
+
const decimalMarker = this._maskService.decimalMarker;
|
|
1943
|
+
const suffix = this._maskService.suffix;
|
|
1950
1944
|
const precision = Number(this._maskService.maskExpression.slice(maskExpression.length - 1, maskExpression.length));
|
|
1951
1945
|
if (precision > 0) {
|
|
1952
|
-
el.value =
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
const decimalPart = el.value.split(this._maskService.decimalMarker)[1];
|
|
1956
|
-
el.value = el.value.includes(this._maskService.decimalMarker)
|
|
1946
|
+
el.value = suffix ? el.value.split(suffix).join('') : el.value;
|
|
1947
|
+
const decimalPart = el.value.split(decimalMarker)[1];
|
|
1948
|
+
el.value = el.value.includes(decimalMarker)
|
|
1957
1949
|
? el.value +
|
|
1958
1950
|
MaskExpression.NUMBER_ZERO.repeat(precision - decimalPart.length) +
|
|
1959
|
-
|
|
1951
|
+
suffix
|
|
1960
1952
|
: el.value +
|
|
1961
|
-
|
|
1953
|
+
decimalMarker +
|
|
1962
1954
|
MaskExpression.NUMBER_ZERO.repeat(precision) +
|
|
1963
|
-
|
|
1955
|
+
suffix;
|
|
1964
1956
|
this._maskService.actualValue = el.value;
|
|
1965
1957
|
}
|
|
1966
1958
|
}
|
|
1967
1959
|
this._maskService.clearIfNotMatchFn();
|
|
1968
1960
|
}
|
|
1969
|
-
this._isFocused
|
|
1961
|
+
this._isFocused.set(false);
|
|
1970
1962
|
this.onTouch();
|
|
1971
1963
|
}
|
|
1972
1964
|
onClick(e) {
|
|
1973
|
-
if (!this._maskValue) {
|
|
1965
|
+
if (!this._maskValue()) {
|
|
1974
1966
|
return;
|
|
1975
1967
|
}
|
|
1976
1968
|
const el = e.target;
|
|
@@ -1981,7 +1973,7 @@ class NgxMaskDirective {
|
|
|
1981
1973
|
el.selectionStart === el.selectionEnd &&
|
|
1982
1974
|
el.selectionStart > this._maskService.prefix.length &&
|
|
1983
1975
|
e.keyCode !== 38) {
|
|
1984
|
-
if (this._maskService.showMaskTyped && !this.keepCharacterPositions) {
|
|
1976
|
+
if (this._maskService.showMaskTyped && !this.keepCharacterPositions()) {
|
|
1985
1977
|
this._maskService.maskIsShown = this._maskService.showMaskInInput();
|
|
1986
1978
|
if (el.setSelectionRange &&
|
|
1987
1979
|
this._maskService.prefix + this._maskService.maskIsShown === el.value) {
|
|
@@ -2015,18 +2007,18 @@ class NgxMaskDirective {
|
|
|
2015
2007
|
}
|
|
2016
2008
|
}
|
|
2017
2009
|
onKeyDown(e) {
|
|
2018
|
-
if (!this._maskValue) {
|
|
2010
|
+
if (!this._maskValue()) {
|
|
2019
2011
|
return;
|
|
2020
2012
|
}
|
|
2021
|
-
if (this._isComposing) {
|
|
2013
|
+
if (this._isComposing()) {
|
|
2022
2014
|
if (e.key === 'Enter') {
|
|
2023
2015
|
this.onCompositionEnd(e);
|
|
2024
2016
|
}
|
|
2025
2017
|
return;
|
|
2026
2018
|
}
|
|
2027
|
-
this._code
|
|
2019
|
+
this._code.set(e.code ? e.code : e.key);
|
|
2028
2020
|
const el = e.target;
|
|
2029
|
-
this._inputValue
|
|
2021
|
+
this._inputValue.set(el.value);
|
|
2030
2022
|
this._setMask();
|
|
2031
2023
|
if (el.type !== 'number') {
|
|
2032
2024
|
if (e.key === MaskExpression.ARROW_UP) {
|
|
@@ -2039,21 +2031,21 @@ class NgxMaskDirective {
|
|
|
2039
2031
|
el.selectionStart = el.selectionEnd;
|
|
2040
2032
|
}
|
|
2041
2033
|
if (e.key === MaskExpression.BACKSPACE && el.selectionStart !== 0) {
|
|
2042
|
-
|
|
2043
|
-
|
|
2034
|
+
const prefixLength = this.prefix().length;
|
|
2035
|
+
const specialCharacters = this.specialCharacters().length
|
|
2036
|
+
? this.specialCharacters()
|
|
2044
2037
|
: this._config.specialCharacters;
|
|
2045
|
-
if (
|
|
2046
|
-
el.
|
|
2047
|
-
el.setSelectionRange(this.prefix.length, el.selectionEnd);
|
|
2038
|
+
if (prefixLength > 1 && el.selectionStart <= prefixLength) {
|
|
2039
|
+
el.setSelectionRange(prefixLength, el.selectionEnd);
|
|
2048
2040
|
}
|
|
2049
2041
|
else {
|
|
2050
|
-
if (this._inputValue.length !== el.selectionStart &&
|
|
2042
|
+
if (this._inputValue().length !== el.selectionStart &&
|
|
2051
2043
|
el.selectionStart !== 1) {
|
|
2052
|
-
while (
|
|
2044
|
+
while (specialCharacters.includes((this._inputValue()[el.selectionStart - 1] ??
|
|
2053
2045
|
MaskExpression.EMPTY_STRING).toString()) &&
|
|
2054
|
-
((
|
|
2055
|
-
el.selectionStart >
|
|
2056
|
-
|
|
2046
|
+
((prefixLength >= 1 &&
|
|
2047
|
+
el.selectionStart > prefixLength) ||
|
|
2048
|
+
prefixLength === 0)) {
|
|
2057
2049
|
el.setSelectionRange(el.selectionStart - 1, el.selectionEnd);
|
|
2058
2050
|
}
|
|
2059
2051
|
}
|
|
@@ -2071,14 +2063,14 @@ class NgxMaskDirective {
|
|
|
2071
2063
|
cursorStart === 0 &&
|
|
2072
2064
|
el.selectionEnd === el.value.length &&
|
|
2073
2065
|
el.value.length !== 0) {
|
|
2074
|
-
this._position
|
|
2075
|
-
this._maskService.applyMask(this._maskService.prefix, this._maskService.maskExpression, this._position);
|
|
2066
|
+
this._position.set(this._maskService.prefix ? this._maskService.prefix.length : 0);
|
|
2067
|
+
this._maskService.applyMask(this._maskService.prefix, this._maskService.maskExpression, this._position());
|
|
2076
2068
|
}
|
|
2077
2069
|
}
|
|
2078
|
-
if (!!this.suffix &&
|
|
2079
|
-
this.suffix.length > 1 &&
|
|
2080
|
-
this._inputValue.length - this.suffix.length < el.selectionStart) {
|
|
2081
|
-
el.setSelectionRange(this._inputValue.length - this.suffix.length, this._inputValue.length);
|
|
2070
|
+
if (!!this.suffix() &&
|
|
2071
|
+
this.suffix().length > 1 &&
|
|
2072
|
+
this._inputValue().length - this.suffix().length < el.selectionStart) {
|
|
2073
|
+
el.setSelectionRange(this._inputValue().length - this.suffix().length, this._inputValue().length);
|
|
2082
2074
|
}
|
|
2083
2075
|
else if ((e.code === 'KeyA' && e.ctrlKey) ||
|
|
2084
2076
|
(e.code === 'KeyA' && e.metaKey)) {
|
|
@@ -2091,6 +2083,7 @@ class NgxMaskDirective {
|
|
|
2091
2083
|
}
|
|
2092
2084
|
async writeValue(controlValue) {
|
|
2093
2085
|
let value = controlValue;
|
|
2086
|
+
const inputTransformFn = this.inputTransformFn();
|
|
2094
2087
|
if (typeof value === 'object' && value !== null && 'value' in value) {
|
|
2095
2088
|
if ('disable' in value) {
|
|
2096
2089
|
this.setDisabledState(Boolean(value.disable));
|
|
@@ -2098,19 +2091,19 @@ class NgxMaskDirective {
|
|
|
2098
2091
|
value = value.value;
|
|
2099
2092
|
}
|
|
2100
2093
|
if (value !== null) {
|
|
2101
|
-
value =
|
|
2094
|
+
value = inputTransformFn ? inputTransformFn(value) : value;
|
|
2102
2095
|
}
|
|
2103
2096
|
if (typeof value === 'string' ||
|
|
2104
2097
|
typeof value === 'number' ||
|
|
2105
2098
|
value === null ||
|
|
2106
2099
|
typeof value === 'undefined') {
|
|
2107
2100
|
if (value === null || typeof value === 'undefined' || value === '') {
|
|
2108
|
-
this._maskService.
|
|
2109
|
-
this._maskService.
|
|
2101
|
+
this._maskService.currentValue = '';
|
|
2102
|
+
this._maskService.previousValue = '';
|
|
2110
2103
|
}
|
|
2111
2104
|
let inputValue = value;
|
|
2112
2105
|
if (typeof inputValue === 'number' ||
|
|
2113
|
-
this._maskValue.startsWith(MaskExpression.SEPARATOR)) {
|
|
2106
|
+
this._maskValue().startsWith(MaskExpression.SEPARATOR)) {
|
|
2114
2107
|
inputValue = String(inputValue);
|
|
2115
2108
|
const localeDecimalMarker = this._maskService.currentLocaleDecimalMarker();
|
|
2116
2109
|
if (!Array.isArray(this._maskService.decimalMarker)) {
|
|
@@ -2121,8 +2114,8 @@ class NgxMaskDirective {
|
|
|
2121
2114
|
}
|
|
2122
2115
|
if (this._maskService.leadZero &&
|
|
2123
2116
|
inputValue &&
|
|
2124
|
-
this.
|
|
2125
|
-
this.dropSpecialCharacters !== false) {
|
|
2117
|
+
this.mask() &&
|
|
2118
|
+
this.dropSpecialCharacters() !== false) {
|
|
2126
2119
|
inputValue = this._maskService._checkPrecision(this._maskService.maskExpression, inputValue);
|
|
2127
2120
|
}
|
|
2128
2121
|
if (this._maskService.decimalMarker === MaskExpression.COMMA ||
|
|
@@ -2132,7 +2125,7 @@ class NgxMaskDirective {
|
|
|
2132
2125
|
.toString()
|
|
2133
2126
|
.replace(MaskExpression.DOT, MaskExpression.COMMA);
|
|
2134
2127
|
}
|
|
2135
|
-
if (this.
|
|
2128
|
+
if (this.mask()?.startsWith(MaskExpression.SEPARATOR) && this.leadZero()) {
|
|
2136
2129
|
requestAnimationFrame(() => {
|
|
2137
2130
|
this._maskService.applyMask(inputValue?.toString() ?? '', this._maskService.maskExpression);
|
|
2138
2131
|
});
|
|
@@ -2142,26 +2135,26 @@ class NgxMaskDirective {
|
|
|
2142
2135
|
if (typeof inputValue !== 'string') {
|
|
2143
2136
|
inputValue = '';
|
|
2144
2137
|
}
|
|
2145
|
-
this._inputValue
|
|
2138
|
+
this._inputValue.set(inputValue);
|
|
2146
2139
|
this._setMask();
|
|
2147
2140
|
if ((inputValue && this._maskService.maskExpression) ||
|
|
2148
2141
|
(this._maskService.maskExpression &&
|
|
2149
2142
|
(this._maskService.prefix || this._maskService.showMaskTyped))) {
|
|
2150
|
-
if (typeof
|
|
2143
|
+
if (typeof inputTransformFn !== 'function') {
|
|
2151
2144
|
this._maskService.writingValue = true;
|
|
2152
2145
|
}
|
|
2153
2146
|
this._maskService.formElementProperty = [
|
|
2154
2147
|
'value',
|
|
2155
2148
|
this._maskService.applyMask(inputValue, this._maskService.maskExpression),
|
|
2156
2149
|
];
|
|
2157
|
-
if (typeof
|
|
2150
|
+
if (typeof inputTransformFn !== 'function') {
|
|
2158
2151
|
this._maskService.writingValue = false;
|
|
2159
2152
|
}
|
|
2160
2153
|
}
|
|
2161
2154
|
else {
|
|
2162
2155
|
this._maskService.formElementProperty = ['value', inputValue];
|
|
2163
2156
|
}
|
|
2164
|
-
this._inputValue
|
|
2157
|
+
this._inputValue.set(inputValue);
|
|
2165
2158
|
}
|
|
2166
2159
|
else {
|
|
2167
2160
|
console.warn('Ngx-mask writeValue work with string | number, your current value:', typeof value);
|
|
@@ -2183,21 +2176,24 @@ class NgxMaskDirective {
|
|
|
2183
2176
|
}
|
|
2184
2177
|
}
|
|
2185
2178
|
checkSelectionOnDeletion(el) {
|
|
2186
|
-
|
|
2187
|
-
|
|
2179
|
+
const prefixLength = this.prefix().length;
|
|
2180
|
+
const suffixLength = this.suffix().length;
|
|
2181
|
+
const inputValueLength = this._inputValue().length;
|
|
2182
|
+
el.selectionStart = Math.min(Math.max(prefixLength, el.selectionStart), inputValueLength - suffixLength);
|
|
2183
|
+
el.selectionEnd = Math.min(Math.max(prefixLength, el.selectionEnd), inputValueLength - suffixLength);
|
|
2188
2184
|
}
|
|
2189
2185
|
setDisabledState(isDisabled) {
|
|
2190
2186
|
this._maskService.formElementProperty = ['disabled', isDisabled];
|
|
2191
2187
|
}
|
|
2192
2188
|
_applyMask() {
|
|
2193
|
-
this._maskService.maskExpression = this._maskService._repeatPatternSymbols(this._maskValue || '');
|
|
2189
|
+
this._maskService.maskExpression = this._maskService._repeatPatternSymbols(this._maskValue() || '');
|
|
2194
2190
|
this._maskService.formElementProperty = [
|
|
2195
2191
|
'value',
|
|
2196
|
-
this._maskService.applyMask(this._inputValue, this._maskService.maskExpression),
|
|
2192
|
+
this._maskService.applyMask(this._inputValue(), this._maskService.maskExpression),
|
|
2197
2193
|
];
|
|
2198
2194
|
}
|
|
2199
2195
|
_validateTime(value) {
|
|
2200
|
-
const rowMaskLen = this._maskValue
|
|
2196
|
+
const rowMaskLen = this._maskValue()
|
|
2201
2197
|
.split(MaskExpression.EMPTY_STRING)
|
|
2202
2198
|
.filter((s) => s !== ':').length;
|
|
2203
2199
|
if (!value) {
|
|
@@ -2216,55 +2212,54 @@ class NgxMaskDirective {
|
|
|
2216
2212
|
_createValidationError(actualValue) {
|
|
2217
2213
|
return {
|
|
2218
2214
|
mask: {
|
|
2219
|
-
requiredMask: this._maskValue,
|
|
2215
|
+
requiredMask: this._maskValue(),
|
|
2220
2216
|
actualValue,
|
|
2221
2217
|
},
|
|
2222
2218
|
};
|
|
2223
2219
|
}
|
|
2224
2220
|
_setMask() {
|
|
2225
|
-
this._maskExpressionArray.some((mask) => {
|
|
2221
|
+
this._maskExpressionArray().some((mask) => {
|
|
2226
2222
|
const specialChart = mask
|
|
2227
2223
|
.split(MaskExpression.EMPTY_STRING)
|
|
2228
2224
|
.some((char) => this._maskService.specialCharacters.includes(char));
|
|
2229
2225
|
if ((specialChart &&
|
|
2230
|
-
this._inputValue &&
|
|
2231
|
-
this._areAllCharactersInEachStringSame(this._maskExpressionArray)) ||
|
|
2226
|
+
this._inputValue() &&
|
|
2227
|
+
this._areAllCharactersInEachStringSame(this._maskExpressionArray())) ||
|
|
2232
2228
|
mask.includes(MaskExpression.CURLY_BRACKETS_LEFT)) {
|
|
2233
|
-
const test = this._maskService.removeMask(this._inputValue)?.length <=
|
|
2229
|
+
const test = this._maskService.removeMask(this._inputValue())?.length <=
|
|
2234
2230
|
this._maskService.removeMask(mask)?.length;
|
|
2235
2231
|
if (test) {
|
|
2236
|
-
|
|
2237
|
-
this.
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
: mask;
|
|
2232
|
+
const maskValue = mask.includes(MaskExpression.CURLY_BRACKETS_LEFT)
|
|
2233
|
+
? this._maskService._repeatPatternSymbols(mask)
|
|
2234
|
+
: mask;
|
|
2235
|
+
this._maskValue.set(maskValue);
|
|
2236
|
+
this._maskService.maskExpression = maskValue;
|
|
2242
2237
|
return test;
|
|
2243
2238
|
}
|
|
2244
2239
|
else {
|
|
2245
|
-
if (this._code === MaskExpression.BACKSPACE) {
|
|
2246
|
-
this._allowFewMaskChangeMask
|
|
2240
|
+
if (this._code() === MaskExpression.BACKSPACE) {
|
|
2241
|
+
this._allowFewMaskChangeMask.set(true);
|
|
2247
2242
|
}
|
|
2248
|
-
const expression = this._maskExpressionArray[this._maskExpressionArray.length - 1] ??
|
|
2243
|
+
const expression = this._maskExpressionArray()[this._maskExpressionArray().length - 1] ??
|
|
2249
2244
|
MaskExpression.EMPTY_STRING;
|
|
2250
|
-
|
|
2251
|
-
this.
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
: expression;
|
|
2245
|
+
const maskValue = expression.includes(MaskExpression.CURLY_BRACKETS_LEFT)
|
|
2246
|
+
? this._maskService._repeatPatternSymbols(expression)
|
|
2247
|
+
: expression;
|
|
2248
|
+
this._maskValue.set(maskValue);
|
|
2249
|
+
this._maskService.maskExpression = maskValue;
|
|
2256
2250
|
}
|
|
2257
2251
|
}
|
|
2258
2252
|
else {
|
|
2259
2253
|
const check = this._maskService
|
|
2260
|
-
.removeMask(this._inputValue)
|
|
2254
|
+
.removeMask(this._inputValue())
|
|
2261
2255
|
?.split(MaskExpression.EMPTY_STRING)
|
|
2262
2256
|
.every((character, index) => {
|
|
2263
2257
|
const indexMask = mask.charAt(index);
|
|
2264
2258
|
return this._maskService._checkSymbolMask(character, indexMask);
|
|
2265
2259
|
});
|
|
2266
|
-
if (check || this._justPasted) {
|
|
2267
|
-
this._maskValue
|
|
2260
|
+
if (check || this._justPasted()) {
|
|
2261
|
+
this._maskValue.set(mask);
|
|
2262
|
+
this._maskService.maskExpression = mask;
|
|
2268
2263
|
return check;
|
|
2269
2264
|
}
|
|
2270
2265
|
}
|
|
@@ -2283,7 +2278,7 @@ class NgxMaskDirective {
|
|
|
2283
2278
|
});
|
|
2284
2279
|
}
|
|
2285
2280
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2286
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
2281
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.0", type: NgxMaskDirective, isStandalone: true, selector: "input[mask], textarea[mask]", inputs: { mask: { classPropertyName: "mask", publicName: "mask", isSignal: true, isRequired: false, transformFunction: null }, specialCharacters: { classPropertyName: "specialCharacters", publicName: "specialCharacters", isSignal: true, isRequired: false, transformFunction: null }, patterns: { classPropertyName: "patterns", publicName: "patterns", isSignal: true, isRequired: false, transformFunction: null }, prefix: { classPropertyName: "prefix", publicName: "prefix", isSignal: true, isRequired: false, transformFunction: null }, suffix: { classPropertyName: "suffix", publicName: "suffix", isSignal: true, isRequired: false, transformFunction: null }, thousandSeparator: { classPropertyName: "thousandSeparator", publicName: "thousandSeparator", isSignal: true, isRequired: false, transformFunction: null }, decimalMarker: { classPropertyName: "decimalMarker", publicName: "decimalMarker", isSignal: true, isRequired: false, transformFunction: null }, dropSpecialCharacters: { classPropertyName: "dropSpecialCharacters", publicName: "dropSpecialCharacters", isSignal: true, isRequired: false, transformFunction: null }, hiddenInput: { classPropertyName: "hiddenInput", publicName: "hiddenInput", isSignal: true, isRequired: false, transformFunction: null }, showMaskTyped: { classPropertyName: "showMaskTyped", publicName: "showMaskTyped", isSignal: true, isRequired: false, transformFunction: null }, placeHolderCharacter: { classPropertyName: "placeHolderCharacter", publicName: "placeHolderCharacter", isSignal: true, isRequired: false, transformFunction: null }, shownMaskExpression: { classPropertyName: "shownMaskExpression", publicName: "shownMaskExpression", isSignal: true, isRequired: false, transformFunction: null }, clearIfNotMatch: { classPropertyName: "clearIfNotMatch", publicName: "clearIfNotMatch", isSignal: true, isRequired: false, transformFunction: null }, validation: { classPropertyName: "validation", publicName: "validation", isSignal: true, isRequired: false, transformFunction: null }, separatorLimit: { classPropertyName: "separatorLimit", publicName: "separatorLimit", isSignal: true, isRequired: false, transformFunction: null }, allowNegativeNumbers: { classPropertyName: "allowNegativeNumbers", publicName: "allowNegativeNumbers", isSignal: true, isRequired: false, transformFunction: null }, leadZeroDateTime: { classPropertyName: "leadZeroDateTime", publicName: "leadZeroDateTime", isSignal: true, isRequired: false, transformFunction: null }, leadZero: { classPropertyName: "leadZero", publicName: "leadZero", isSignal: true, isRequired: false, transformFunction: null }, triggerOnMaskChange: { classPropertyName: "triggerOnMaskChange", publicName: "triggerOnMaskChange", isSignal: true, isRequired: false, transformFunction: null }, apm: { classPropertyName: "apm", publicName: "apm", isSignal: true, isRequired: false, transformFunction: null }, inputTransformFn: { classPropertyName: "inputTransformFn", publicName: "inputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, outputTransformFn: { classPropertyName: "outputTransformFn", publicName: "outputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, keepCharacterPositions: { classPropertyName: "keepCharacterPositions", publicName: "keepCharacterPositions", isSignal: true, isRequired: false, transformFunction: null } }, 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: [
|
|
2287
2282
|
{
|
|
2288
2283
|
provide: NG_VALUE_ACCESSOR,
|
|
2289
2284
|
useExisting: NgxMaskDirective,
|
|
@@ -2317,58 +2312,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
2317
2312
|
],
|
|
2318
2313
|
exportAs: 'mask,ngxMask',
|
|
2319
2314
|
}]
|
|
2320
|
-
}], propDecorators: {
|
|
2321
|
-
type: Input,
|
|
2322
|
-
args: ['mask']
|
|
2323
|
-
}], specialCharacters: [{
|
|
2324
|
-
type: Input
|
|
2325
|
-
}], patterns: [{
|
|
2326
|
-
type: Input
|
|
2327
|
-
}], prefix: [{
|
|
2328
|
-
type: Input
|
|
2329
|
-
}], suffix: [{
|
|
2330
|
-
type: Input
|
|
2331
|
-
}], thousandSeparator: [{
|
|
2332
|
-
type: Input
|
|
2333
|
-
}], decimalMarker: [{
|
|
2334
|
-
type: Input
|
|
2335
|
-
}], dropSpecialCharacters: [{
|
|
2336
|
-
type: Input
|
|
2337
|
-
}], hiddenInput: [{
|
|
2338
|
-
type: Input
|
|
2339
|
-
}], showMaskTyped: [{
|
|
2340
|
-
type: Input
|
|
2341
|
-
}], placeHolderCharacter: [{
|
|
2342
|
-
type: Input
|
|
2343
|
-
}], shownMaskExpression: [{
|
|
2344
|
-
type: Input
|
|
2345
|
-
}], showTemplate: [{
|
|
2346
|
-
type: Input
|
|
2347
|
-
}], clearIfNotMatch: [{
|
|
2348
|
-
type: Input
|
|
2349
|
-
}], validation: [{
|
|
2350
|
-
type: Input
|
|
2351
|
-
}], separatorLimit: [{
|
|
2352
|
-
type: Input
|
|
2353
|
-
}], allowNegativeNumbers: [{
|
|
2354
|
-
type: Input
|
|
2355
|
-
}], leadZeroDateTime: [{
|
|
2356
|
-
type: Input
|
|
2357
|
-
}], leadZero: [{
|
|
2358
|
-
type: Input
|
|
2359
|
-
}], triggerOnMaskChange: [{
|
|
2360
|
-
type: Input
|
|
2361
|
-
}], apm: [{
|
|
2362
|
-
type: Input
|
|
2363
|
-
}], inputTransformFn: [{
|
|
2364
|
-
type: Input
|
|
2365
|
-
}], outputTransformFn: [{
|
|
2366
|
-
type: Input
|
|
2367
|
-
}], keepCharacterPositions: [{
|
|
2368
|
-
type: Input
|
|
2369
|
-
}], maskFilled: [{
|
|
2370
|
-
type: Output
|
|
2371
|
-
}], onPaste: [{
|
|
2315
|
+
}], propDecorators: { onPaste: [{
|
|
2372
2316
|
type: HostListener,
|
|
2373
2317
|
args: ['paste']
|
|
2374
2318
|
}], onFocus: [{
|
|
@@ -2400,8 +2344,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
2400
2344
|
class NgxMaskPipe {
|
|
2401
2345
|
defaultOptions = inject(NGX_MASK_CONFIG);
|
|
2402
2346
|
_maskService = inject(NgxMaskService);
|
|
2403
|
-
_maskExpressionArray = [];
|
|
2404
|
-
|
|
2347
|
+
_maskExpressionArray = signal([]);
|
|
2348
|
+
_mask = signal('');
|
|
2405
2349
|
transform(value, mask, { patterns, ...config } = {}) {
|
|
2406
2350
|
let processedValue = value;
|
|
2407
2351
|
const currentConfig = {
|
|
@@ -2419,13 +2363,13 @@ class NgxMaskPipe {
|
|
|
2419
2363
|
if (mask.includes('||')) {
|
|
2420
2364
|
const maskParts = mask.split('||');
|
|
2421
2365
|
if (maskParts.length > 1) {
|
|
2422
|
-
this._maskExpressionArray
|
|
2366
|
+
this._maskExpressionArray.set(maskParts.sort((a, b) => a.length - b.length));
|
|
2423
2367
|
this._setMask(processedValue);
|
|
2424
|
-
return this._maskService.applyMask(`${processedValue}`, this.
|
|
2368
|
+
return this._maskService.applyMask(`${processedValue}`, this._mask());
|
|
2425
2369
|
}
|
|
2426
2370
|
else {
|
|
2427
|
-
this._maskExpressionArray
|
|
2428
|
-
return this._maskService.applyMask(`${processedValue}`, this.
|
|
2371
|
+
this._maskExpressionArray.set([]);
|
|
2372
|
+
return this._maskService.applyMask(`${processedValue}`, this._mask());
|
|
2429
2373
|
}
|
|
2430
2374
|
}
|
|
2431
2375
|
if (mask.includes(MaskExpression.CURLY_BRACKETS_LEFT)) {
|
|
@@ -2465,18 +2409,18 @@ class NgxMaskPipe {
|
|
|
2465
2409
|
return this._maskService.applyMask(`${processedValue}`, mask);
|
|
2466
2410
|
}
|
|
2467
2411
|
_setMask(value) {
|
|
2468
|
-
if (this._maskExpressionArray.length > 0) {
|
|
2469
|
-
this._maskExpressionArray.some((mask) => {
|
|
2412
|
+
if (this._maskExpressionArray().length > 0) {
|
|
2413
|
+
this._maskExpressionArray().some((mask) => {
|
|
2470
2414
|
const test = this._maskService.removeMask(value)?.length <=
|
|
2471
2415
|
this._maskService.removeMask(mask)?.length;
|
|
2472
2416
|
if (value && test) {
|
|
2473
|
-
this.mask
|
|
2417
|
+
this._mask.set(mask);
|
|
2474
2418
|
return test;
|
|
2475
2419
|
}
|
|
2476
2420
|
else {
|
|
2477
|
-
const expression = this._maskExpressionArray[this._maskExpressionArray.length - 1] ??
|
|
2421
|
+
const expression = this._maskExpressionArray()[this._maskExpressionArray.length - 1] ??
|
|
2478
2422
|
MaskExpression.EMPTY_STRING;
|
|
2479
|
-
this.
|
|
2423
|
+
this._mask.set(expression);
|
|
2480
2424
|
}
|
|
2481
2425
|
});
|
|
2482
2426
|
}
|