ngx-mask 16.3.0 → 16.3.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/esm2022/lib/ngx-mask-applier.service.mjs +11 -1
- package/esm2022/lib/ngx-mask-expression.enum.mjs +1 -1
- package/esm2022/lib/ngx-mask.config.mjs +2 -1
- package/esm2022/lib/ngx-mask.directive.mjs +226 -115
- package/esm2022/lib/ngx-mask.service.mjs +10 -1
- package/fesm2022/ngx-mask.mjs +246 -115
- package/fesm2022/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +2 -0
- package/lib/ngx-mask-expression.enum.d.ts +2 -1
- package/lib/ngx-mask.config.d.ts +1 -0
- package/lib/ngx-mask.directive.d.ts +2 -1
- package/package.json +1 -1
package/fesm2022/ngx-mask.mjs
CHANGED
|
@@ -26,6 +26,7 @@ const initialConfig = {
|
|
|
26
26
|
leadZeroDateTime: false,
|
|
27
27
|
apm: false,
|
|
28
28
|
leadZero: false,
|
|
29
|
+
keepCharacterPositions: false,
|
|
29
30
|
triggerOnMaskChange: false,
|
|
30
31
|
inputTransformFn: (value) => value,
|
|
31
32
|
outputTransformFn: (value) => value,
|
|
@@ -113,9 +114,11 @@ class NgxMaskApplierService {
|
|
|
113
114
|
this.apm = this._config.apm;
|
|
114
115
|
this.inputTransformFn = this._config.inputTransformFn;
|
|
115
116
|
this.outputTransformFn = this._config.outputTransformFn;
|
|
117
|
+
this.keepCharacterPositions = this._config.keepCharacterPositions;
|
|
116
118
|
this._shift = new Set();
|
|
117
119
|
this.maskExpression = '';
|
|
118
120
|
this.actualValue = '';
|
|
121
|
+
this.showKeepCharacterExp = '';
|
|
119
122
|
this.shownMaskExpression = '';
|
|
120
123
|
this.deletedSpecialCharacter = false;
|
|
121
124
|
this._formatWithSeparators = (str, thousandSeparatorChar, decimalChars, precision) => {
|
|
@@ -640,6 +643,14 @@ class NgxMaskApplierService {
|
|
|
640
643
|
if (result.length === 0) {
|
|
641
644
|
res = !this.dropSpecialCharacters ? `${this.prefix}${result}` : `${result}`;
|
|
642
645
|
}
|
|
646
|
+
if (result.includes("-" /* MaskExpression.MINUS */) && this.prefix && this.allowNegativeNumbers) {
|
|
647
|
+
if (backspaced && result === "-" /* MaskExpression.MINUS */) {
|
|
648
|
+
return '';
|
|
649
|
+
}
|
|
650
|
+
res = `${"-" /* MaskExpression.MINUS */}${this.prefix}${result
|
|
651
|
+
.split("-" /* MaskExpression.MINUS */)
|
|
652
|
+
.join("" /* MaskExpression.EMPTY_STRING */)}${this.suffix}`;
|
|
653
|
+
}
|
|
643
654
|
return res;
|
|
644
655
|
}
|
|
645
656
|
_findSpecialChar(inputSymbol) {
|
|
@@ -835,6 +846,15 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
835
846
|
newInputValue =
|
|
836
847
|
Boolean(newInputValue) && newInputValue.length ? newInputValue : inputValue;
|
|
837
848
|
}
|
|
849
|
+
if (this.showMaskTyped && this.keepCharacterPositions && this.actualValue && !justPasted) {
|
|
850
|
+
const value = this.dropSpecialCharacters
|
|
851
|
+
? this.removeMask(this.actualValue)
|
|
852
|
+
: this.actualValue;
|
|
853
|
+
this.formControlResult(value);
|
|
854
|
+
return this.actualValue
|
|
855
|
+
? this.actualValue
|
|
856
|
+
: this.prefix + this.maskIsShown + this.suffix;
|
|
857
|
+
}
|
|
838
858
|
const result = super.applyMask(newInputValue, maskExpression, position, justPasted, backspaced, cb);
|
|
839
859
|
this.actualValue = this.getActualValue(result);
|
|
840
860
|
// handle some separator implications:
|
|
@@ -1334,6 +1354,7 @@ class NgxMaskDirective {
|
|
|
1334
1354
|
this.apm = null;
|
|
1335
1355
|
this.inputTransformFn = null;
|
|
1336
1356
|
this.outputTransformFn = null;
|
|
1357
|
+
this.keepCharacterPositions = null;
|
|
1337
1358
|
this.maskFilled = new EventEmitter();
|
|
1338
1359
|
this._maskValue = '';
|
|
1339
1360
|
this._position = null;
|
|
@@ -1350,7 +1371,7 @@ class NgxMaskDirective {
|
|
|
1350
1371
|
this.onTouch = () => { };
|
|
1351
1372
|
}
|
|
1352
1373
|
ngOnChanges(changes) {
|
|
1353
|
-
const { maskExpression, specialCharacters, patterns, prefix, suffix, thousandSeparator, decimalMarker, dropSpecialCharacters, hiddenInput, showMaskTyped, placeHolderCharacter, shownMaskExpression, showTemplate, clearIfNotMatch, validation, separatorLimit, allowNegativeNumbers, leadZeroDateTime, leadZero, triggerOnMaskChange, apm, inputTransformFn, outputTransformFn, } = changes;
|
|
1374
|
+
const { maskExpression, specialCharacters, patterns, prefix, suffix, thousandSeparator, decimalMarker, dropSpecialCharacters, hiddenInput, showMaskTyped, placeHolderCharacter, shownMaskExpression, showTemplate, clearIfNotMatch, validation, separatorLimit, allowNegativeNumbers, leadZeroDateTime, leadZero, triggerOnMaskChange, apm, inputTransformFn, outputTransformFn, keepCharacterPositions, } = changes;
|
|
1354
1375
|
if (maskExpression) {
|
|
1355
1376
|
if (maskExpression.currentValue !== maskExpression.previousValue &&
|
|
1356
1377
|
!maskExpression.firstChange) {
|
|
@@ -1447,6 +1468,9 @@ class NgxMaskDirective {
|
|
|
1447
1468
|
if (outputTransformFn) {
|
|
1448
1469
|
this._maskService.outputTransformFn = outputTransformFn.currentValue;
|
|
1449
1470
|
}
|
|
1471
|
+
if (keepCharacterPositions) {
|
|
1472
|
+
this._maskService.keepCharacterPositions = keepCharacterPositions.currentValue;
|
|
1473
|
+
}
|
|
1450
1474
|
this._applyMask();
|
|
1451
1475
|
}
|
|
1452
1476
|
// eslint-disable-next-line complexity
|
|
@@ -1534,7 +1558,7 @@ class NgxMaskDirective {
|
|
|
1534
1558
|
const lastIndexArray = array[array.length - 1];
|
|
1535
1559
|
if (lastIndexArray &&
|
|
1536
1560
|
this._maskService.specialCharacters.includes(lastIndexArray[0]) &&
|
|
1537
|
-
value.includes(lastIndexArray[0]) &&
|
|
1561
|
+
String(value).includes(lastIndexArray[0] ?? '') &&
|
|
1538
1562
|
!this.dropSpecialCharacters) {
|
|
1539
1563
|
const special = value.split(lastIndexArray[0]);
|
|
1540
1564
|
return special[special.length - 1].length === lastIndexArray.length - 1
|
|
@@ -1580,72 +1604,173 @@ class NgxMaskDirective {
|
|
|
1580
1604
|
return;
|
|
1581
1605
|
const el = e.target;
|
|
1582
1606
|
const transformedValue = this._maskService.inputTransformFn(el.value);
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
this.
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
let position = el.selectionStart === 1
|
|
1592
|
-
? el.selectionStart + this._maskService.prefix.length
|
|
1593
|
-
: el.selectionStart;
|
|
1594
|
-
let caretShift = 0;
|
|
1595
|
-
let backspaceShift = false;
|
|
1596
|
-
if (this._code === "Delete" /* MaskExpression.DELETE */ && "separator" /* MaskExpression.SEPARATOR */) {
|
|
1597
|
-
this._maskService.deletedSpecialCharacter = true;
|
|
1598
|
-
}
|
|
1599
|
-
if (this._inputValue.length >= this._maskService.maskExpression.length - 1 &&
|
|
1600
|
-
this._code !== "Backspace" /* MaskExpression.BACKSPACE */ &&
|
|
1601
|
-
this._maskService.maskExpression === "d0/M0/0000" /* MaskExpression.DAYS_MONTHS_YEARS */ &&
|
|
1602
|
-
position < 10) {
|
|
1603
|
-
const inputSymbol = this._inputValue.slice(position - 1, position);
|
|
1604
|
-
el.value =
|
|
1605
|
-
this._inputValue.slice(0, position - 1) +
|
|
1606
|
-
inputSymbol +
|
|
1607
|
-
this._inputValue.slice(position + 1);
|
|
1608
|
-
}
|
|
1609
|
-
this._maskService.applyValueChanges(position, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */, (shift, _backspaceShift) => {
|
|
1610
|
-
this._justPasted = false;
|
|
1611
|
-
caretShift = shift;
|
|
1612
|
-
backspaceShift = _backspaceShift;
|
|
1613
|
-
});
|
|
1614
|
-
// only set the selection if the element is active
|
|
1615
|
-
if (this._getActiveElement() !== el) {
|
|
1616
|
-
return;
|
|
1617
|
-
}
|
|
1618
|
-
// update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
|
|
1619
|
-
if (this._maskExpressionArray.length) {
|
|
1620
|
-
if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
1621
|
-
position = this.specialCharacters.includes(this._inputValue.slice(position - 1, position))
|
|
1622
|
-
? position - 1
|
|
1623
|
-
: position;
|
|
1607
|
+
if (el.type !== 'number') {
|
|
1608
|
+
if (typeof transformedValue === 'string' || typeof transformedValue === 'number') {
|
|
1609
|
+
el.value = transformedValue.toString();
|
|
1610
|
+
this._inputValue = el.value;
|
|
1611
|
+
this._setMask();
|
|
1612
|
+
if (!this._maskValue) {
|
|
1613
|
+
this.onChange(el.value);
|
|
1614
|
+
return;
|
|
1624
1615
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1616
|
+
let position = el.selectionStart === 1
|
|
1617
|
+
? el.selectionStart + this._maskService.prefix.length
|
|
1618
|
+
: el.selectionStart;
|
|
1619
|
+
if (this.showMaskTyped &&
|
|
1620
|
+
this.keepCharacterPositions &&
|
|
1621
|
+
this._maskService.placeHolderCharacter.length === 1) {
|
|
1622
|
+
const inputSymbol = el.value.slice(position - 1, position);
|
|
1623
|
+
const prefixLength = this.prefix.length;
|
|
1624
|
+
const checkSymbols = this._maskService._checkSymbolMask(inputSymbol, this._maskService.maskExpression[position - 1 - prefixLength] ??
|
|
1625
|
+
"" /* MaskExpression.EMPTY_STRING */);
|
|
1626
|
+
const checkSpecialCharacter = this._maskService._checkSymbolMask(inputSymbol, this._maskService.maskExpression[position + 1 - prefixLength] ??
|
|
1627
|
+
"" /* MaskExpression.EMPTY_STRING */);
|
|
1628
|
+
const selectRangeBackspace = this._maskService.selStart === this._maskService.selEnd;
|
|
1629
|
+
const selStart = Number(this._maskService.selStart) - prefixLength ?? '';
|
|
1630
|
+
const selEnd = Number(this._maskService.selEnd) - prefixLength ?? '';
|
|
1631
|
+
if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
1632
|
+
if (!selectRangeBackspace) {
|
|
1633
|
+
if (this._maskService.selStart === prefixLength) {
|
|
1634
|
+
this._maskService.actualValue =
|
|
1635
|
+
this.prefix +
|
|
1636
|
+
this._maskService.maskIsShown.slice(0, selEnd) +
|
|
1637
|
+
this._inputValue.split(this.prefix).join('');
|
|
1638
|
+
}
|
|
1639
|
+
else if (this._maskService.selStart ===
|
|
1640
|
+
this._maskService.maskIsShown.length + prefixLength) {
|
|
1641
|
+
this._maskService.actualValue =
|
|
1642
|
+
this._inputValue +
|
|
1643
|
+
this._maskService.maskIsShown.slice(selStart, selEnd);
|
|
1644
|
+
}
|
|
1645
|
+
else {
|
|
1646
|
+
this._maskService.actualValue =
|
|
1647
|
+
this.prefix +
|
|
1648
|
+
this._inputValue
|
|
1649
|
+
.split(this.prefix)
|
|
1650
|
+
.join('')
|
|
1651
|
+
.slice(0, selStart) +
|
|
1652
|
+
this._maskService.maskIsShown.slice(selStart, selEnd) +
|
|
1653
|
+
this._maskService.actualValue.slice(selEnd + prefixLength, this._maskService.maskIsShown.length + prefixLength) +
|
|
1654
|
+
this.suffix;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
else if (!this._maskService.specialCharacters.includes(this._maskService.maskExpression.slice(position - this.prefix.length, position + 1 - this.prefix.length)) &&
|
|
1658
|
+
selectRangeBackspace) {
|
|
1659
|
+
if (selStart === 1 && this.prefix) {
|
|
1660
|
+
this._maskService.actualValue =
|
|
1661
|
+
this.prefix +
|
|
1662
|
+
this._maskService.placeHolderCharacter +
|
|
1663
|
+
el.value
|
|
1664
|
+
.split(this.prefix)
|
|
1665
|
+
.join('')
|
|
1666
|
+
.split(this.suffix)
|
|
1667
|
+
.join('') +
|
|
1668
|
+
this.suffix;
|
|
1669
|
+
position = position - 1;
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
const part1 = el.value.substring(0, position);
|
|
1673
|
+
const part2 = el.value.substring(position);
|
|
1674
|
+
this._maskService.actualValue =
|
|
1675
|
+
part1 + this._maskService.placeHolderCharacter + part2;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (this._code !== "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
1680
|
+
if (!checkSymbols && !checkSpecialCharacter && selectRangeBackspace) {
|
|
1681
|
+
position = Number(el.selectionStart) - 1;
|
|
1682
|
+
}
|
|
1683
|
+
else if (this._maskService.specialCharacters.includes(el.value.slice(position, position + 1)) &&
|
|
1684
|
+
checkSpecialCharacter &&
|
|
1685
|
+
!this._maskService.specialCharacters.includes(el.value.slice(position + 1, position + 2))) {
|
|
1686
|
+
this._maskService.actualValue =
|
|
1687
|
+
el.value.slice(0, position - 1) +
|
|
1688
|
+
el.value.slice(position, position + 1) +
|
|
1689
|
+
inputSymbol +
|
|
1690
|
+
el.value.slice(position + 2);
|
|
1691
|
+
position = position + 1;
|
|
1692
|
+
}
|
|
1693
|
+
else if (checkSymbols) {
|
|
1694
|
+
this._maskService.actualValue =
|
|
1695
|
+
el.value.slice(0, position - 1) +
|
|
1696
|
+
inputSymbol +
|
|
1697
|
+
el.value
|
|
1698
|
+
.slice(position + 1)
|
|
1699
|
+
.split(this.suffix)
|
|
1700
|
+
.join('') +
|
|
1701
|
+
this.suffix;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1630
1704
|
}
|
|
1705
|
+
let caretShift = 0;
|
|
1706
|
+
let backspaceShift = false;
|
|
1707
|
+
if (this._code === "Delete" /* MaskExpression.DELETE */ && "separator" /* MaskExpression.SEPARATOR */) {
|
|
1708
|
+
this._maskService.deletedSpecialCharacter = true;
|
|
1709
|
+
}
|
|
1710
|
+
if (this._inputValue.length >= this._maskService.maskExpression.length - 1 &&
|
|
1711
|
+
this._code !== "Backspace" /* MaskExpression.BACKSPACE */ &&
|
|
1712
|
+
this._maskService.maskExpression === "d0/M0/0000" /* MaskExpression.DAYS_MONTHS_YEARS */ &&
|
|
1713
|
+
position < 10) {
|
|
1714
|
+
const inputSymbol = this._inputValue.slice(position - 1, position);
|
|
1715
|
+
el.value =
|
|
1716
|
+
this._inputValue.slice(0, position - 1) +
|
|
1717
|
+
inputSymbol +
|
|
1718
|
+
this._inputValue.slice(position + 1);
|
|
1719
|
+
}
|
|
1720
|
+
if (this._maskService.maskExpression === "Hh:m0:s0" /* MaskExpression.HOURS_MINUTES_SECONDS */ &&
|
|
1721
|
+
this.apm) {
|
|
1722
|
+
if (this._justPasted && el.value.slice(0, 2) === "00" /* MaskExpression.DOUBLE_ZERO */) {
|
|
1723
|
+
el.value = el.value.slice(1, 2) + el.value.slice(2, el.value.length);
|
|
1724
|
+
}
|
|
1725
|
+
el.value =
|
|
1726
|
+
el.value === "00" /* MaskExpression.DOUBLE_ZERO */
|
|
1727
|
+
? "0" /* MaskExpression.NUMBER_ZERO */
|
|
1728
|
+
: el.value;
|
|
1729
|
+
}
|
|
1730
|
+
this._maskService.applyValueChanges(position, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */, (shift, _backspaceShift) => {
|
|
1731
|
+
this._justPasted = false;
|
|
1732
|
+
caretShift = shift;
|
|
1733
|
+
backspaceShift = _backspaceShift;
|
|
1734
|
+
});
|
|
1735
|
+
// only set the selection if the element is active
|
|
1736
|
+
if (this._getActiveElement() !== el) {
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
// update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
|
|
1740
|
+
if (this._maskExpressionArray.length) {
|
|
1741
|
+
if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
1742
|
+
position = this.specialCharacters.includes(this._inputValue.slice(position - 1, position))
|
|
1743
|
+
? position - 1
|
|
1744
|
+
: position;
|
|
1745
|
+
}
|
|
1746
|
+
else {
|
|
1747
|
+
position =
|
|
1748
|
+
el.selectionStart === 1
|
|
1749
|
+
? el.selectionStart + this._maskService.prefix.length
|
|
1750
|
+
: el.selectionStart;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
this._position =
|
|
1754
|
+
this._position === 1 && this._inputValue.length === 1 ? null : this._position;
|
|
1755
|
+
let positionToApply = this._position
|
|
1756
|
+
? this._inputValue.length + position + caretShift
|
|
1757
|
+
: position +
|
|
1758
|
+
(this._code === "Backspace" /* MaskExpression.BACKSPACE */ && !backspaceShift ? 0 : caretShift);
|
|
1759
|
+
if (positionToApply > this._getActualInputLength()) {
|
|
1760
|
+
positionToApply = this._getActualInputLength();
|
|
1761
|
+
}
|
|
1762
|
+
if (positionToApply < 0) {
|
|
1763
|
+
positionToApply = 0;
|
|
1764
|
+
}
|
|
1765
|
+
el.setSelectionRange(positionToApply, positionToApply);
|
|
1766
|
+
this._position = null;
|
|
1631
1767
|
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
let positionToApply = this._position
|
|
1635
|
-
? this._inputValue.length + position + caretShift
|
|
1636
|
-
: position +
|
|
1637
|
-
(this._code === "Backspace" /* MaskExpression.BACKSPACE */ && !backspaceShift ? 0 : caretShift);
|
|
1638
|
-
if (positionToApply > this._getActualInputLength()) {
|
|
1639
|
-
positionToApply = this._getActualInputLength();
|
|
1640
|
-
}
|
|
1641
|
-
if (positionToApply < 0) {
|
|
1642
|
-
positionToApply = 0;
|
|
1768
|
+
else {
|
|
1769
|
+
console.warn('Ngx-mask writeValue work with string | number, your current value:', typeof transformedValue);
|
|
1643
1770
|
}
|
|
1644
|
-
el.setSelectionRange(positionToApply, positionToApply);
|
|
1645
|
-
this._position = null;
|
|
1646
1771
|
}
|
|
1647
1772
|
else {
|
|
1648
|
-
|
|
1773
|
+
this._maskService.applyValueChanges(el.value.length, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */);
|
|
1649
1774
|
}
|
|
1650
1775
|
}
|
|
1651
1776
|
// IME starts
|
|
@@ -1695,7 +1820,7 @@ class NgxMaskDirective {
|
|
|
1695
1820
|
el.selectionStart > this._maskService.prefix.length &&
|
|
1696
1821
|
// eslint-disable-next-line
|
|
1697
1822
|
e.keyCode !== 38) {
|
|
1698
|
-
if (this._maskService.showMaskTyped) {
|
|
1823
|
+
if (this._maskService.showMaskTyped && !this.keepCharacterPositions) {
|
|
1699
1824
|
// We are showing the mask in the input
|
|
1700
1825
|
this._maskService.maskIsShown = this._maskService.showMaskInInput();
|
|
1701
1826
|
if (el.setSelectionRange &&
|
|
@@ -1723,6 +1848,7 @@ class NgxMaskDirective {
|
|
|
1723
1848
|
}
|
|
1724
1849
|
/** fix of cursor position with prefix when mouse click occur */
|
|
1725
1850
|
if (el &&
|
|
1851
|
+
el.type !== 'number' &&
|
|
1726
1852
|
(el.selectionStart || el.selectionEnd) <=
|
|
1727
1853
|
this._maskService.prefix.length) {
|
|
1728
1854
|
el.selectionStart = this._maskService.prefix.length;
|
|
@@ -1748,65 +1874,68 @@ class NgxMaskDirective {
|
|
|
1748
1874
|
const el = e.target;
|
|
1749
1875
|
this._inputValue = el.value;
|
|
1750
1876
|
this._setMask();
|
|
1751
|
-
if (
|
|
1752
|
-
e.
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
e.key === "
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
if (e.key === "Backspace" /* MaskExpression.BACKSPACE */ && el.selectionStart !== 0) {
|
|
1761
|
-
// If specialChars is false, (shouldn't ever happen) then set to the defaults
|
|
1762
|
-
this.specialCharacters = this.specialCharacters?.length
|
|
1763
|
-
? this.specialCharacters
|
|
1764
|
-
: this._config.specialCharacters;
|
|
1765
|
-
if (this.prefix.length > 1 && el.selectionStart <= this.prefix.length) {
|
|
1766
|
-
el.setSelectionRange(this.prefix.length, el.selectionEnd);
|
|
1877
|
+
if (el.type !== 'number') {
|
|
1878
|
+
if (e.key === "ArrowUp" /* MaskExpression.ARROW_UP */) {
|
|
1879
|
+
e.preventDefault();
|
|
1880
|
+
}
|
|
1881
|
+
if (e.key === "ArrowLeft" /* MaskExpression.ARROW_LEFT */ ||
|
|
1882
|
+
e.key === "Backspace" /* MaskExpression.BACKSPACE */ ||
|
|
1883
|
+
e.key === "Delete" /* MaskExpression.DELETE */) {
|
|
1884
|
+
if (e.key === "Backspace" /* MaskExpression.BACKSPACE */ && el.value.length === 0) {
|
|
1885
|
+
el.selectionStart = el.selectionEnd;
|
|
1767
1886
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1887
|
+
if (e.key === "Backspace" /* MaskExpression.BACKSPACE */ && el.selectionStart !== 0) {
|
|
1888
|
+
// If specialChars is false, (shouldn't ever happen) then set to the defaults
|
|
1889
|
+
this.specialCharacters = this.specialCharacters?.length
|
|
1890
|
+
? this.specialCharacters
|
|
1891
|
+
: this._config.specialCharacters;
|
|
1892
|
+
if (this.prefix.length > 1 &&
|
|
1893
|
+
el.selectionStart <= this.prefix.length) {
|
|
1894
|
+
el.setSelectionRange(this.prefix.length, el.selectionEnd);
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
if (this._inputValue.length !== el.selectionStart &&
|
|
1898
|
+
el.selectionStart !== 1) {
|
|
1899
|
+
while (this.specialCharacters.includes((this._inputValue[el.selectionStart - 1] ??
|
|
1900
|
+
"" /* MaskExpression.EMPTY_STRING */).toString()) &&
|
|
1901
|
+
((this.prefix.length >= 1 &&
|
|
1902
|
+
el.selectionStart > this.prefix.length) ||
|
|
1903
|
+
this.prefix.length === 0)) {
|
|
1904
|
+
el.setSelectionRange(el.selectionStart - 1, el.selectionEnd);
|
|
1905
|
+
}
|
|
1777
1906
|
}
|
|
1778
1907
|
}
|
|
1779
1908
|
}
|
|
1909
|
+
this.checkSelectionOnDeletion(el);
|
|
1910
|
+
if (this._maskService.prefix.length &&
|
|
1911
|
+
el.selectionStart <= this._maskService.prefix.length &&
|
|
1912
|
+
el.selectionEnd <= this._maskService.prefix.length) {
|
|
1913
|
+
e.preventDefault();
|
|
1914
|
+
}
|
|
1915
|
+
const cursorStart = el.selectionStart;
|
|
1916
|
+
if (e.key === "Backspace" /* MaskExpression.BACKSPACE */ &&
|
|
1917
|
+
!el.readOnly &&
|
|
1918
|
+
cursorStart === 0 &&
|
|
1919
|
+
el.selectionEnd === el.value.length &&
|
|
1920
|
+
el.value.length !== 0) {
|
|
1921
|
+
this._position = this._maskService.prefix ? this._maskService.prefix.length : 0;
|
|
1922
|
+
this._maskService.applyMask(this._maskService.prefix, this._maskService.maskExpression, this._position);
|
|
1923
|
+
}
|
|
1780
1924
|
}
|
|
1781
|
-
this.
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
el.
|
|
1785
|
-
e.preventDefault();
|
|
1925
|
+
if (!!this.suffix &&
|
|
1926
|
+
this.suffix.length > 1 &&
|
|
1927
|
+
this._inputValue.length - this.suffix.length < el.selectionStart) {
|
|
1928
|
+
el.setSelectionRange(this._inputValue.length - this.suffix.length, this._inputValue.length);
|
|
1786
1929
|
}
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
el.value.length !== 0) {
|
|
1793
|
-
this._position = this._maskService.prefix ? this._maskService.prefix.length : 0;
|
|
1794
|
-
this._maskService.applyMask(this._maskService.prefix, this._maskService.maskExpression, this._position);
|
|
1930
|
+
else if ((e.code === 'KeyA' && e.ctrlKey) ||
|
|
1931
|
+
(e.code === 'KeyA' && e.metaKey) // Cmd + A (Mac)
|
|
1932
|
+
) {
|
|
1933
|
+
el.setSelectionRange(0, this._getActualInputLength());
|
|
1934
|
+
e.preventDefault();
|
|
1795
1935
|
}
|
|
1936
|
+
this._maskService.selStart = el.selectionStart;
|
|
1937
|
+
this._maskService.selEnd = el.selectionEnd;
|
|
1796
1938
|
}
|
|
1797
|
-
if (!!this.suffix &&
|
|
1798
|
-
this.suffix.length > 1 &&
|
|
1799
|
-
this._inputValue.length - this.suffix.length < el.selectionStart) {
|
|
1800
|
-
el.setSelectionRange(this._inputValue.length - this.suffix.length, this._inputValue.length);
|
|
1801
|
-
}
|
|
1802
|
-
else if ((e.code === 'KeyA' && e.ctrlKey) ||
|
|
1803
|
-
(e.code === 'KeyA' && e.metaKey) // Cmd + A (Mac)
|
|
1804
|
-
) {
|
|
1805
|
-
el.setSelectionRange(0, this._getActualInputLength());
|
|
1806
|
-
e.preventDefault();
|
|
1807
|
-
}
|
|
1808
|
-
this._maskService.selStart = el.selectionStart;
|
|
1809
|
-
this._maskService.selEnd = el.selectionEnd;
|
|
1810
1939
|
}
|
|
1811
1940
|
/** It writes the value in the input */
|
|
1812
1941
|
async writeValue(controlValue) {
|
|
@@ -1991,7 +2120,7 @@ class NgxMaskDirective {
|
|
|
1991
2120
|
});
|
|
1992
2121
|
}
|
|
1993
2122
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1994
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.2", type: NgxMaskDirective, isStandalone: true, 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" }, 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: [
|
|
2123
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.2", type: NgxMaskDirective, isStandalone: true, 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: [
|
|
1995
2124
|
{
|
|
1996
2125
|
provide: NG_VALUE_ACCESSOR,
|
|
1997
2126
|
useExisting: NgxMaskDirective,
|
|
@@ -2072,6 +2201,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImpor
|
|
|
2072
2201
|
type: Input
|
|
2073
2202
|
}], outputTransformFn: [{
|
|
2074
2203
|
type: Input
|
|
2204
|
+
}], keepCharacterPositions: [{
|
|
2205
|
+
type: Input
|
|
2075
2206
|
}], maskFilled: [{
|
|
2076
2207
|
type: Output
|
|
2077
2208
|
}], onPaste: [{
|