ngx-mask 16.2.8 → 16.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/ngx-mask-applier.service.mjs +12 -9
- package/esm2022/lib/ngx-mask.config.mjs +3 -1
- package/esm2022/lib/ngx-mask.directive.mjs +150 -112
- package/esm2022/lib/ngx-mask.pipe.mjs +3 -3
- package/esm2022/lib/ngx-mask.service.mjs +16 -8
- package/fesm2022/ngx-mask.mjs +180 -129
- package/fesm2022/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +2 -0
- package/lib/ngx-mask.config.d.ts +8 -0
- package/lib/ngx-mask.directive.d.ts +4 -5
- package/package.json +1 -1
package/fesm2022/ngx-mask.mjs
CHANGED
|
@@ -27,6 +27,8 @@ const initialConfig = {
|
|
|
27
27
|
apm: false,
|
|
28
28
|
leadZero: false,
|
|
29
29
|
triggerOnMaskChange: false,
|
|
30
|
+
inputTransformFn: (value) => value,
|
|
31
|
+
outputTransformFn: (value) => value,
|
|
30
32
|
maskFilled: new EventEmitter(),
|
|
31
33
|
patterns: {
|
|
32
34
|
'0': {
|
|
@@ -109,6 +111,8 @@ class NgxMaskApplierService {
|
|
|
109
111
|
this.leadZeroDateTime = this._config.leadZeroDateTime;
|
|
110
112
|
this.leadZero = this._config.leadZero;
|
|
111
113
|
this.apm = this._config.apm;
|
|
114
|
+
this.inputTransformFn = this._config.inputTransformFn;
|
|
115
|
+
this.outputTransformFn = this._config.outputTransformFn;
|
|
112
116
|
this._shift = new Set();
|
|
113
117
|
this.maskExpression = '';
|
|
114
118
|
this.actualValue = '';
|
|
@@ -215,7 +219,7 @@ class NgxMaskApplierService {
|
|
|
215
219
|
let backspaceShift = false;
|
|
216
220
|
let shift = 1;
|
|
217
221
|
let stepBack = false;
|
|
218
|
-
if (inputValue.slice(0, this.prefix.length) === this.prefix) {
|
|
222
|
+
if (inputValue.slice(0, this.prefix.length) === this.prefix && !this.showMaskTyped) {
|
|
219
223
|
// eslint-disable-next-line no-param-reassign
|
|
220
224
|
inputValue = inputValue.slice(this.prefix.length, inputValue.length);
|
|
221
225
|
}
|
|
@@ -351,7 +355,8 @@ class NgxMaskApplierService {
|
|
|
351
355
|
}
|
|
352
356
|
else if (result[position - 1] === this.decimalMarker ||
|
|
353
357
|
shiftStep === -4 ||
|
|
354
|
-
shiftStep === -3
|
|
358
|
+
shiftStep === -3 ||
|
|
359
|
+
result[position] === "," /* MaskExpression.COMMA */) {
|
|
355
360
|
this._shift.clear();
|
|
356
361
|
this._shift.add(position - 1);
|
|
357
362
|
}
|
|
@@ -419,11 +424,11 @@ class NgxMaskApplierService {
|
|
|
419
424
|
if (maskExpression[cursor] === "h" /* MaskExpression.HOUR */) {
|
|
420
425
|
if (this.apm
|
|
421
426
|
? (result.length === 1 && Number(result) > 1) ||
|
|
422
|
-
(result === '1' && Number(inputSymbol) >
|
|
427
|
+
(result === '1' && Number(inputSymbol) > 2) ||
|
|
423
428
|
(inputValue.slice(cursor - 1, cursor).length === 1 &&
|
|
424
|
-
Number(inputValue.slice(cursor - 1, cursor)) >
|
|
429
|
+
Number(inputValue.slice(cursor - 1, cursor)) > 2) ||
|
|
425
430
|
(inputValue.slice(cursor - 1, cursor) === '1' &&
|
|
426
|
-
Number(inputSymbol) >
|
|
431
|
+
Number(inputSymbol) > 2)
|
|
427
432
|
: (result === '2' && Number(inputSymbol) > 3) ||
|
|
428
433
|
((result.slice(cursor - 2, cursor) === '2' ||
|
|
429
434
|
result.slice(cursor - 3, cursor) === '2' ||
|
|
@@ -709,10 +714,10 @@ class NgxMaskApplierService {
|
|
|
709
714
|
: integerString + decimal + decimalPart;
|
|
710
715
|
}
|
|
711
716
|
}
|
|
712
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
713
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.
|
|
717
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskApplierService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
718
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskApplierService }); }
|
|
714
719
|
}
|
|
715
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
720
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskApplierService, decorators: [{
|
|
716
721
|
type: Injectable
|
|
717
722
|
}] });
|
|
718
723
|
|
|
@@ -1118,20 +1123,20 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1118
1123
|
formControlResult(inputValue) {
|
|
1119
1124
|
if (this.writingValue || (!this.triggerOnMaskChange && this.maskChanged)) {
|
|
1120
1125
|
this.maskChanged
|
|
1121
|
-
? this.onChange(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue)))))
|
|
1126
|
+
? this.onChange(this.outputTransformFn(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue))))))
|
|
1122
1127
|
: '';
|
|
1123
1128
|
this.maskChanged = false;
|
|
1124
1129
|
return;
|
|
1125
1130
|
}
|
|
1126
1131
|
if (Array.isArray(this.dropSpecialCharacters)) {
|
|
1127
|
-
this.onChange(this._toNumber(this._checkSymbols(this._removeMask(this._removeSuffix(this._removePrefix(inputValue)), this.dropSpecialCharacters))));
|
|
1132
|
+
this.onChange(this.outputTransformFn(this._toNumber(this._checkSymbols(this._removeMask(this._removeSuffix(this._removePrefix(inputValue)), this.dropSpecialCharacters)))));
|
|
1128
1133
|
}
|
|
1129
1134
|
else if (this.dropSpecialCharacters ||
|
|
1130
1135
|
(!this.dropSpecialCharacters && this.prefix === inputValue)) {
|
|
1131
|
-
this.onChange(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue)))));
|
|
1136
|
+
this.onChange(this.outputTransformFn(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue))))));
|
|
1132
1137
|
}
|
|
1133
1138
|
else {
|
|
1134
|
-
this.onChange(this._toNumber(inputValue));
|
|
1139
|
+
this.onChange(this.outputTransformFn(this._toNumber(inputValue)));
|
|
1135
1140
|
}
|
|
1136
1141
|
}
|
|
1137
1142
|
_toNumber(value) {
|
|
@@ -1146,6 +1151,10 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1146
1151
|
return String(value);
|
|
1147
1152
|
}
|
|
1148
1153
|
const num = Number(value);
|
|
1154
|
+
if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */) && Number.isNaN(num)) {
|
|
1155
|
+
const val = String(value).replace(',', '.');
|
|
1156
|
+
return Number(val);
|
|
1157
|
+
}
|
|
1149
1158
|
return Number.isNaN(num) ? value : num;
|
|
1150
1159
|
}
|
|
1151
1160
|
_removeMask(value, specialCharactersForRemove) {
|
|
@@ -1222,6 +1231,10 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1222
1231
|
const separatorPrecision = separatorExpression.slice(10, 11);
|
|
1223
1232
|
if (separatorExpression.indexOf('2') > 0 ||
|
|
1224
1233
|
(this.leadZero && Number(separatorPrecision) > 1)) {
|
|
1234
|
+
if (this.decimalMarker === "," /* MaskExpression.COMMA */ && this.leadZero) {
|
|
1235
|
+
// eslint-disable-next-line no-param-reassign
|
|
1236
|
+
separatorValue = separatorValue.replace(',', '.');
|
|
1237
|
+
}
|
|
1225
1238
|
return this.leadZero
|
|
1226
1239
|
? Number(separatorValue).toFixed(Number(separatorPrecision))
|
|
1227
1240
|
: Number(separatorValue).toFixed(2);
|
|
@@ -1257,10 +1270,10 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1257
1270
|
currentLocaleDecimalMarker() {
|
|
1258
1271
|
return (1.1).toLocaleString().substring(1, 2);
|
|
1259
1272
|
}
|
|
1260
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
1261
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.
|
|
1273
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1274
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskService }); }
|
|
1262
1275
|
}
|
|
1263
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
1276
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskService, decorators: [{
|
|
1264
1277
|
type: Injectable
|
|
1265
1278
|
}] });
|
|
1266
1279
|
|
|
@@ -1319,6 +1332,8 @@ class NgxMaskDirective {
|
|
|
1319
1332
|
this.leadZero = null;
|
|
1320
1333
|
this.triggerOnMaskChange = null;
|
|
1321
1334
|
this.apm = null;
|
|
1335
|
+
this.inputTransformFn = null;
|
|
1336
|
+
this.outputTransformFn = null;
|
|
1322
1337
|
this.maskFilled = new EventEmitter();
|
|
1323
1338
|
this._maskValue = '';
|
|
1324
1339
|
this._position = null;
|
|
@@ -1335,7 +1350,7 @@ class NgxMaskDirective {
|
|
|
1335
1350
|
this.onTouch = () => { };
|
|
1336
1351
|
}
|
|
1337
1352
|
ngOnChanges(changes) {
|
|
1338
|
-
const { maskExpression, specialCharacters, patterns, prefix, suffix, thousandSeparator, decimalMarker, dropSpecialCharacters, hiddenInput, showMaskTyped, placeHolderCharacter, shownMaskExpression, showTemplate, clearIfNotMatch, validation, separatorLimit, allowNegativeNumbers, leadZeroDateTime, leadZero, triggerOnMaskChange, apm, } = 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;
|
|
1339
1354
|
if (maskExpression) {
|
|
1340
1355
|
if (maskExpression.currentValue !== maskExpression.previousValue &&
|
|
1341
1356
|
!maskExpression.firstChange) {
|
|
@@ -1426,6 +1441,12 @@ class NgxMaskDirective {
|
|
|
1426
1441
|
if (triggerOnMaskChange) {
|
|
1427
1442
|
this._maskService.triggerOnMaskChange = triggerOnMaskChange.currentValue;
|
|
1428
1443
|
}
|
|
1444
|
+
if (inputTransformFn) {
|
|
1445
|
+
this._maskService.inputTransformFn = inputTransformFn.currentValue;
|
|
1446
|
+
}
|
|
1447
|
+
if (outputTransformFn) {
|
|
1448
|
+
this._maskService.outputTransformFn = outputTransformFn.currentValue;
|
|
1449
|
+
}
|
|
1429
1450
|
this._applyMask();
|
|
1430
1451
|
}
|
|
1431
1452
|
// eslint-disable-next-line complexity
|
|
@@ -1558,67 +1579,74 @@ class NgxMaskDirective {
|
|
|
1558
1579
|
if (this._isComposing)
|
|
1559
1580
|
return;
|
|
1560
1581
|
const el = e.target;
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
this.
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
: el.selectionStart;
|
|
1570
|
-
let caretShift = 0;
|
|
1571
|
-
let backspaceShift = false;
|
|
1572
|
-
if (this._code === "Delete" /* MaskExpression.DELETE */ && "separator" /* MaskExpression.SEPARATOR */) {
|
|
1573
|
-
this._maskService.deletedSpecialCharacter = true;
|
|
1574
|
-
}
|
|
1575
|
-
if (this._inputValue.length >= this._maskService.maskExpression.length - 1 &&
|
|
1576
|
-
this._code !== "Backspace" /* MaskExpression.BACKSPACE */ &&
|
|
1577
|
-
this._maskService.maskExpression === "d0/M0/0000" /* MaskExpression.DAYS_MONTHS_YEARS */ &&
|
|
1578
|
-
position < 10) {
|
|
1579
|
-
const inputSymbol = this._inputValue.slice(position - 1, position);
|
|
1580
|
-
el.value =
|
|
1581
|
-
this._inputValue.slice(0, position - 1) +
|
|
1582
|
-
inputSymbol +
|
|
1583
|
-
this._inputValue.slice(position + 1);
|
|
1584
|
-
}
|
|
1585
|
-
this._maskService.applyValueChanges(position, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */, (shift, _backspaceShift) => {
|
|
1586
|
-
this._justPasted = false;
|
|
1587
|
-
caretShift = shift;
|
|
1588
|
-
backspaceShift = _backspaceShift;
|
|
1589
|
-
});
|
|
1590
|
-
// only set the selection if the element is active
|
|
1591
|
-
if (this._getActiveElement() !== el) {
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
// update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
|
|
1595
|
-
if (this._maskExpressionArray.length) {
|
|
1596
|
-
if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
1597
|
-
position = this.specialCharacters.includes(this._inputValue.slice(position - 1, position))
|
|
1598
|
-
? position - 1
|
|
1599
|
-
: position;
|
|
1582
|
+
const transformedValue = this._maskService.inputTransformFn(el.value);
|
|
1583
|
+
if (typeof transformedValue === 'string' || typeof transformedValue === 'number') {
|
|
1584
|
+
el.value = transformedValue.toString();
|
|
1585
|
+
this._inputValue = el.value;
|
|
1586
|
+
this._setMask();
|
|
1587
|
+
if (!this._maskValue) {
|
|
1588
|
+
this.onChange(el.value);
|
|
1589
|
+
return;
|
|
1600
1590
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
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;
|
|
1606
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;
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
position =
|
|
1627
|
+
el.selectionStart === 1
|
|
1628
|
+
? el.selectionStart + this._maskService.prefix.length
|
|
1629
|
+
: el.selectionStart;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
this._position =
|
|
1633
|
+
this._position === 1 && this._inputValue.length === 1 ? null : this._position;
|
|
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;
|
|
1643
|
+
}
|
|
1644
|
+
el.setSelectionRange(positionToApply, positionToApply);
|
|
1645
|
+
this._position = null;
|
|
1607
1646
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
let positionToApply = this._position
|
|
1611
|
-
? this._inputValue.length + position + caretShift
|
|
1612
|
-
: position +
|
|
1613
|
-
(this._code === "Backspace" /* MaskExpression.BACKSPACE */ && !backspaceShift ? 0 : caretShift);
|
|
1614
|
-
if (positionToApply > this._getActualInputLength()) {
|
|
1615
|
-
positionToApply = this._getActualInputLength();
|
|
1616
|
-
}
|
|
1617
|
-
if (positionToApply < 0) {
|
|
1618
|
-
positionToApply = 0;
|
|
1647
|
+
else {
|
|
1648
|
+
console.warn('Ngx-mask writeValue work with string | number, your current value:', typeof transformedValue);
|
|
1619
1649
|
}
|
|
1620
|
-
el.setSelectionRange(positionToApply, positionToApply);
|
|
1621
|
-
this._position = null;
|
|
1622
1650
|
}
|
|
1623
1651
|
// IME starts
|
|
1624
1652
|
onCompositionStart() {
|
|
@@ -1781,68 +1809,87 @@ class NgxMaskDirective {
|
|
|
1781
1809
|
this._maskService.selEnd = el.selectionEnd;
|
|
1782
1810
|
}
|
|
1783
1811
|
/** It writes the value in the input */
|
|
1784
|
-
async writeValue(
|
|
1785
|
-
if (typeof
|
|
1786
|
-
if ('disable' in
|
|
1787
|
-
this.setDisabledState(Boolean(
|
|
1812
|
+
async writeValue(controlValue) {
|
|
1813
|
+
if (typeof controlValue === 'object' && controlValue !== null && 'value' in controlValue) {
|
|
1814
|
+
if ('disable' in controlValue) {
|
|
1815
|
+
this.setDisabledState(Boolean(controlValue.disable));
|
|
1788
1816
|
}
|
|
1789
1817
|
// eslint-disable-next-line no-param-reassign
|
|
1790
|
-
|
|
1818
|
+
controlValue = controlValue.value;
|
|
1791
1819
|
}
|
|
1792
|
-
if (
|
|
1793
|
-
this._maskValue.startsWith("separator" /* MaskExpression.SEPARATOR */)) {
|
|
1820
|
+
if (controlValue !== null) {
|
|
1794
1821
|
// eslint-disable-next-line no-param-reassign
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
if (
|
|
1805
|
-
|
|
1806
|
-
this.maskExpression &&
|
|
1807
|
-
this.dropSpecialCharacters !== false) {
|
|
1822
|
+
controlValue = this.inputTransformFn
|
|
1823
|
+
? this.inputTransformFn(controlValue)
|
|
1824
|
+
: controlValue;
|
|
1825
|
+
}
|
|
1826
|
+
if (typeof controlValue === 'string' ||
|
|
1827
|
+
typeof controlValue === 'number' ||
|
|
1828
|
+
controlValue === null) {
|
|
1829
|
+
// eslint-disable-next-line no-param-reassign
|
|
1830
|
+
let inputValue = controlValue;
|
|
1831
|
+
if (typeof inputValue === 'number' ||
|
|
1832
|
+
this._maskValue.startsWith("separator" /* MaskExpression.SEPARATOR */)) {
|
|
1808
1833
|
// eslint-disable-next-line no-param-reassign
|
|
1809
|
-
inputValue =
|
|
1834
|
+
inputValue = String(inputValue);
|
|
1835
|
+
const localeDecimalMarker = this._maskService.currentLocaleDecimalMarker();
|
|
1836
|
+
if (!Array.isArray(this._maskService.decimalMarker)) {
|
|
1837
|
+
// eslint-disable-next-line no-param-reassign
|
|
1838
|
+
inputValue =
|
|
1839
|
+
this._maskService.decimalMarker !== localeDecimalMarker
|
|
1840
|
+
? inputValue.replace(localeDecimalMarker, this._maskService.decimalMarker)
|
|
1841
|
+
: inputValue;
|
|
1842
|
+
}
|
|
1843
|
+
if (this._maskService.leadZero &&
|
|
1844
|
+
inputValue &&
|
|
1845
|
+
this.maskExpression &&
|
|
1846
|
+
this.dropSpecialCharacters !== false) {
|
|
1847
|
+
// eslint-disable-next-line no-param-reassign
|
|
1848
|
+
inputValue = this._maskService._checkPrecision(this._maskService.maskExpression, inputValue);
|
|
1849
|
+
}
|
|
1850
|
+
if (this._maskService.decimalMarker === "," /* MaskExpression.COMMA */) {
|
|
1851
|
+
// eslint-disable-next-line no-param-reassign
|
|
1852
|
+
inputValue = inputValue
|
|
1853
|
+
.toString()
|
|
1854
|
+
.replace("." /* MaskExpression.DOT */, "," /* MaskExpression.COMMA */);
|
|
1855
|
+
}
|
|
1856
|
+
if (this.maskExpression?.startsWith("separator" /* MaskExpression.SEPARATOR */) && this.leadZero) {
|
|
1857
|
+
requestAnimationFrame(() => {
|
|
1858
|
+
this._maskService.applyMask(inputValue?.toString() ?? '', this._maskService.maskExpression);
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
this._maskService.isNumberValue = true;
|
|
1810
1862
|
}
|
|
1811
|
-
if (
|
|
1863
|
+
if (typeof inputValue !== 'string') {
|
|
1812
1864
|
// eslint-disable-next-line no-param-reassign
|
|
1813
|
-
inputValue =
|
|
1814
|
-
|
|
1815
|
-
|
|
1865
|
+
inputValue = '';
|
|
1866
|
+
}
|
|
1867
|
+
this._inputValue = inputValue;
|
|
1868
|
+
this._setMask();
|
|
1869
|
+
if ((inputValue && this._maskService.maskExpression) ||
|
|
1870
|
+
(this._maskService.maskExpression &&
|
|
1871
|
+
(this._maskService.prefix || this._maskService.showMaskTyped))) {
|
|
1872
|
+
// Let the service we know we are writing value so that triggering onChange function won't happen during applyMask
|
|
1873
|
+
typeof this.inputTransformFn !== 'function'
|
|
1874
|
+
? (this._maskService.writingValue = true)
|
|
1875
|
+
: '';
|
|
1876
|
+
this._maskService.formElementProperty = [
|
|
1877
|
+
'value',
|
|
1878
|
+
this._maskService.applyMask(inputValue, this._maskService.maskExpression),
|
|
1879
|
+
];
|
|
1880
|
+
// Let the service know we've finished writing value
|
|
1881
|
+
typeof this.inputTransformFn !== 'function'
|
|
1882
|
+
? (this._maskService.writingValue = false)
|
|
1883
|
+
: '';
|
|
1816
1884
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
this._maskService.applyMask(inputValue.toString(), this._maskService.maskExpression);
|
|
1820
|
-
});
|
|
1885
|
+
else {
|
|
1886
|
+
this._maskService.formElementProperty = ['value', inputValue];
|
|
1821
1887
|
}
|
|
1822
|
-
this.
|
|
1823
|
-
}
|
|
1824
|
-
if (typeof inputValue !== 'string') {
|
|
1825
|
-
// eslint-disable-next-line no-param-reassign
|
|
1826
|
-
inputValue = '';
|
|
1827
|
-
}
|
|
1828
|
-
this._inputValue = inputValue;
|
|
1829
|
-
this._setMask();
|
|
1830
|
-
if ((inputValue && this._maskService.maskExpression) ||
|
|
1831
|
-
(this._maskService.maskExpression &&
|
|
1832
|
-
(this._maskService.prefix || this._maskService.showMaskTyped))) {
|
|
1833
|
-
// Let the service we know we are writing value so that triggering onChange function won't happen during applyMask
|
|
1834
|
-
this._maskService.writingValue = true;
|
|
1835
|
-
this._maskService.formElementProperty = [
|
|
1836
|
-
'value',
|
|
1837
|
-
this._maskService.applyMask(inputValue, this._maskService.maskExpression),
|
|
1838
|
-
];
|
|
1839
|
-
// Let the service know we've finished writing value
|
|
1840
|
-
this._maskService.writingValue = false;
|
|
1888
|
+
this._inputValue = inputValue;
|
|
1841
1889
|
}
|
|
1842
1890
|
else {
|
|
1843
|
-
|
|
1891
|
+
console.warn('Ngx-mask writeValue work with string | number, your current value:', typeof controlValue);
|
|
1844
1892
|
}
|
|
1845
|
-
this._inputValue = inputValue;
|
|
1846
1893
|
}
|
|
1847
1894
|
registerOnChange(fn) {
|
|
1848
1895
|
this._maskService.onChange = this.onChange = fn;
|
|
@@ -1943,8 +1990,8 @@ class NgxMaskDirective {
|
|
|
1943
1990
|
}
|
|
1944
1991
|
});
|
|
1945
1992
|
}
|
|
1946
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
1947
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.
|
|
1993
|
+
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: [
|
|
1948
1995
|
{
|
|
1949
1996
|
provide: NG_VALUE_ACCESSOR,
|
|
1950
1997
|
useExisting: NgxMaskDirective,
|
|
@@ -1958,7 +2005,7 @@ class NgxMaskDirective {
|
|
|
1958
2005
|
NgxMaskService,
|
|
1959
2006
|
], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 }); }
|
|
1960
2007
|
}
|
|
1961
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
2008
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskDirective, decorators: [{
|
|
1962
2009
|
type: Directive,
|
|
1963
2010
|
args: [{
|
|
1964
2011
|
selector: 'input[mask], textarea[mask]',
|
|
@@ -2021,6 +2068,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.8", ngImpor
|
|
|
2021
2068
|
type: Input
|
|
2022
2069
|
}], apm: [{
|
|
2023
2070
|
type: Input
|
|
2071
|
+
}], inputTransformFn: [{
|
|
2072
|
+
type: Input
|
|
2073
|
+
}], outputTransformFn: [{
|
|
2074
|
+
type: Input
|
|
2024
2075
|
}], maskFilled: [{
|
|
2025
2076
|
type: Output
|
|
2026
2077
|
}], onPaste: [{
|
|
@@ -2138,10 +2189,10 @@ class NgxMaskPipe {
|
|
|
2138
2189
|
});
|
|
2139
2190
|
}
|
|
2140
2191
|
}
|
|
2141
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2142
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.
|
|
2192
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
2193
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskPipe, isStandalone: true, name: "mask" }); }
|
|
2143
2194
|
}
|
|
2144
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
2195
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: NgxMaskPipe, decorators: [{
|
|
2145
2196
|
type: Pipe,
|
|
2146
2197
|
args: [{
|
|
2147
2198
|
name: 'mask',
|