ngx-mask 14.3.2-test → 14.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/ngx-mask-applier.service.mjs +88 -23
- package/esm2020/lib/ngx-mask.directive.mjs +79 -21
- package/esm2020/lib/ngx-mask.pipe.mjs +4 -1
- package/esm2020/lib/ngx-mask.service.mjs +31 -6
- package/fesm2015/ngx-mask.mjs +201 -49
- package/fesm2015/ngx-mask.mjs.map +1 -1
- package/fesm2020/ngx-mask.mjs +198 -47
- package/fesm2020/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +1 -0
- package/lib/ngx-mask.directive.d.ts +3 -1
- package/lib/ngx-mask.service.d.ts +6 -4
- package/package.json +1 -1
package/fesm2015/ngx-mask.mjs
CHANGED
|
@@ -117,6 +117,7 @@ class NgxMaskApplierService {
|
|
|
117
117
|
this.outputTransformFn = this._config.outputTransformFn;
|
|
118
118
|
this.keepCharacterPositions = this._config.keepCharacterPositions;
|
|
119
119
|
this._shift = new Set();
|
|
120
|
+
this.plusOnePosition = false;
|
|
120
121
|
this.maskExpression = '';
|
|
121
122
|
this.actualValue = '';
|
|
122
123
|
this.showKeepCharacterExp = '';
|
|
@@ -227,7 +228,7 @@ class NgxMaskApplierService {
|
|
|
227
228
|
let backspaceShift = false;
|
|
228
229
|
let shift = 1;
|
|
229
230
|
let stepBack = false;
|
|
230
|
-
if (inputValue.slice(0, this.prefix.length) === this.prefix
|
|
231
|
+
if (inputValue.slice(0, this.prefix.length) === this.prefix) {
|
|
231
232
|
// eslint-disable-next-line no-param-reassign
|
|
232
233
|
inputValue = inputValue.slice(this.prefix.length, inputValue.length);
|
|
233
234
|
}
|
|
@@ -311,24 +312,91 @@ class NgxMaskApplierService {
|
|
|
311
312
|
// eslint-disable-next-line no-param-reassign
|
|
312
313
|
inputValue = this._stripToDecimal(inputValue);
|
|
313
314
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
const precision = this.getPrecision(maskExpression);
|
|
316
|
+
const decimalMarker = Array.isArray(this.decimalMarker)
|
|
317
|
+
? "." /* MaskExpression.DOT */
|
|
318
|
+
: this.decimalMarker;
|
|
319
|
+
if (precision === 0) {
|
|
320
|
+
// eslint-disable-next-line no-param-reassign
|
|
321
|
+
inputValue = this.allowNegativeNumbers
|
|
317
322
|
? inputValue.length > 2 &&
|
|
318
|
-
inputValue[
|
|
323
|
+
inputValue[0] === "-" /* MaskExpression.MINUS */ &&
|
|
324
|
+
inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
319
325
|
inputValue[2] !== this.thousandSeparator &&
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
? inputValue.slice(
|
|
323
|
-
: inputValue
|
|
326
|
+
inputValue[2] !== "," /* MaskExpression.COMMA */ &&
|
|
327
|
+
inputValue[2] !== "." /* MaskExpression.DOT */
|
|
328
|
+
? '-' + inputValue.slice(2, inputValue.length)
|
|
329
|
+
: inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
330
|
+
inputValue.length > 1 &&
|
|
331
|
+
inputValue[1] !== this.thousandSeparator &&
|
|
332
|
+
inputValue[1] !== "," /* MaskExpression.COMMA */ &&
|
|
333
|
+
inputValue[1] !== "." /* MaskExpression.DOT */
|
|
334
|
+
? inputValue.slice(1, inputValue.length)
|
|
335
|
+
: inputValue
|
|
324
336
|
: inputValue.length > 1 &&
|
|
325
|
-
inputValue[0] ===
|
|
337
|
+
inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
326
338
|
inputValue[1] !== this.thousandSeparator &&
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
? inputValue.slice(
|
|
339
|
+
inputValue[1] !== "," /* MaskExpression.COMMA */ &&
|
|
340
|
+
inputValue[1] !== "." /* MaskExpression.DOT */
|
|
341
|
+
? inputValue.slice(1, inputValue.length)
|
|
330
342
|
: inputValue;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// eslint-disable-next-line no-param-reassign
|
|
346
|
+
if (inputValue[0] === decimalMarker && inputValue.length > 1) {
|
|
347
|
+
// eslint-disable-next-line no-param-reassign
|
|
348
|
+
inputValue =
|
|
349
|
+
"0" /* MaskExpression.NUMBER_ZERO */ + inputValue.slice(0, inputValue.length + 1);
|
|
350
|
+
this.plusOnePosition = true;
|
|
351
|
+
}
|
|
352
|
+
if (inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
353
|
+
inputValue[1] !== decimalMarker &&
|
|
354
|
+
inputValue[1] !== this.thousandSeparator) {
|
|
355
|
+
// eslint-disable-next-line no-param-reassign
|
|
356
|
+
inputValue =
|
|
357
|
+
inputValue.length > 1
|
|
358
|
+
? inputValue.slice(0, 1) +
|
|
359
|
+
decimalMarker +
|
|
360
|
+
inputValue.slice(1, inputValue.length + 1)
|
|
361
|
+
: inputValue;
|
|
362
|
+
this.plusOnePosition = true;
|
|
363
|
+
}
|
|
364
|
+
if (this.allowNegativeNumbers &&
|
|
365
|
+
inputValue[0] === "-" /* MaskExpression.MINUS */ &&
|
|
366
|
+
(inputValue[1] === decimalMarker ||
|
|
367
|
+
inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */)) {
|
|
368
|
+
// eslint-disable-next-line no-param-reassign
|
|
369
|
+
inputValue =
|
|
370
|
+
inputValue[1] === decimalMarker && inputValue.length > 2
|
|
371
|
+
? inputValue.slice(0, 1) +
|
|
372
|
+
"0" /* MaskExpression.NUMBER_ZERO */ +
|
|
373
|
+
inputValue.slice(1, inputValue.length)
|
|
374
|
+
: inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
375
|
+
inputValue.length > 2 &&
|
|
376
|
+
inputValue[2] !== decimalMarker
|
|
377
|
+
? inputValue.slice(0, 2) +
|
|
378
|
+
decimalMarker +
|
|
379
|
+
inputValue.slice(2, inputValue.length)
|
|
380
|
+
: inputValue;
|
|
381
|
+
this.plusOnePosition = true;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
331
384
|
if (backspaced) {
|
|
385
|
+
if (inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
386
|
+
inputValue[1] === this.decimalMarker &&
|
|
387
|
+
(inputValue[position] === "0" /* MaskExpression.NUMBER_ZERO */ ||
|
|
388
|
+
inputValue[position] === this.decimalMarker)) {
|
|
389
|
+
// eslint-disable-next-line no-param-reassign
|
|
390
|
+
inputValue = inputValue.slice(2, inputValue.length);
|
|
391
|
+
}
|
|
392
|
+
if (inputValue[0] === "-" /* MaskExpression.MINUS */ &&
|
|
393
|
+
inputValue[1] === "0" /* MaskExpression.NUMBER_ZERO */ &&
|
|
394
|
+
inputValue[2] === this.decimalMarker &&
|
|
395
|
+
(inputValue[position] === "0" /* MaskExpression.NUMBER_ZERO */ ||
|
|
396
|
+
inputValue[position] === this.decimalMarker)) {
|
|
397
|
+
// eslint-disable-next-line no-param-reassign
|
|
398
|
+
inputValue = "-" /* MaskExpression.MINUS */ + inputValue.slice(3, inputValue.length);
|
|
399
|
+
}
|
|
332
400
|
// eslint-disable-next-line no-param-reassign
|
|
333
401
|
inputValue = this._compareOrIncludes(inputValue[inputValue.length - 1], this.decimalMarker, this.thousandSeparator)
|
|
334
402
|
? inputValue.slice(0, inputValue.length - 1)
|
|
@@ -348,13 +416,10 @@ class NgxMaskApplierService {
|
|
|
348
416
|
invalidChars = invalidChars.replace(this._charToRegExpExpression(this.decimalMarker), '');
|
|
349
417
|
}
|
|
350
418
|
const invalidCharRegexp = new RegExp('[' + invalidChars + ']');
|
|
351
|
-
if (inputValue.match(invalidCharRegexp)
|
|
352
|
-
(inputValue.length === 1 &&
|
|
353
|
-
this._compareOrIncludes(inputValue, this.decimalMarker, this.thousandSeparator))) {
|
|
419
|
+
if (inputValue.match(invalidCharRegexp)) {
|
|
354
420
|
// eslint-disable-next-line no-param-reassign
|
|
355
421
|
inputValue = inputValue.substring(0, inputValue.length - 1);
|
|
356
422
|
}
|
|
357
|
-
const precision = this.getPrecision(maskExpression);
|
|
358
423
|
// eslint-disable-next-line no-param-reassign
|
|
359
424
|
inputValue = this.checkInputPrecision(inputValue, precision, this.decimalMarker);
|
|
360
425
|
const strForSep = inputValue.replace(new RegExp(thousandSeparatorCharEscaped, 'g'), '');
|
|
@@ -427,7 +492,7 @@ class NgxMaskApplierService {
|
|
|
427
492
|
if (maskExpression[cursor] === "H" /* MaskExpression.HOURS */) {
|
|
428
493
|
if (this.apm ? Number(inputSymbol) > 9 : Number(inputSymbol) > 2) {
|
|
429
494
|
// eslint-disable-next-line no-param-reassign
|
|
430
|
-
position = position + 1;
|
|
495
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
431
496
|
cursor += 1;
|
|
432
497
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
433
498
|
i--;
|
|
@@ -463,7 +528,7 @@ class NgxMaskApplierService {
|
|
|
463
528
|
maskExpression[cursor] === "s" /* MaskExpression.SECOND */) {
|
|
464
529
|
if (Number(inputSymbol) > 5) {
|
|
465
530
|
// eslint-disable-next-line no-param-reassign
|
|
466
|
-
position = position + 1;
|
|
531
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
467
532
|
cursor += 1;
|
|
468
533
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
469
534
|
i--;
|
|
@@ -501,7 +566,7 @@ class NgxMaskApplierService {
|
|
|
501
566
|
: Number(inputValueSliceCursorPlusTwo) > daysCount ||
|
|
502
567
|
this.specialCharacters.includes(inputValueCursorPlusOne))) {
|
|
503
568
|
// eslint-disable-next-line no-param-reassign
|
|
504
|
-
position = position + 1;
|
|
569
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
505
570
|
cursor += 1;
|
|
506
571
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
507
572
|
i--;
|
|
@@ -557,7 +622,7 @@ class NgxMaskApplierService {
|
|
|
557
622
|
day2monthInput ||
|
|
558
623
|
(day2monthInputDot && !this.leadZeroDateTime)) {
|
|
559
624
|
// eslint-disable-next-line no-param-reassign
|
|
560
|
-
position = position + 1;
|
|
625
|
+
position = !this.leadZeroDateTime ? position + 1 : position;
|
|
561
626
|
cursor += 1;
|
|
562
627
|
this._shiftStep(maskExpression, cursor, inputArray.length);
|
|
563
628
|
i--;
|
|
@@ -651,7 +716,7 @@ class NgxMaskApplierService {
|
|
|
651
716
|
if (backspaced) {
|
|
652
717
|
onlySpecial = inputArray.every((char) => this.specialCharacters.includes(char));
|
|
653
718
|
}
|
|
654
|
-
let res = `${this.prefix}${onlySpecial ? "" /* MaskExpression.EMPTY_STRING */ : result}${this.suffix}`;
|
|
719
|
+
let res = `${this.prefix}${onlySpecial ? "" /* MaskExpression.EMPTY_STRING */ : result}${this.showMaskTyped ? '' : this.suffix}`;
|
|
655
720
|
if (result.length === 0) {
|
|
656
721
|
res = !this.dropSpecialCharacters ? `${this.prefix}${result}` : `${result}`;
|
|
657
722
|
}
|
|
@@ -765,21 +830,21 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
765
830
|
this.maskChanged = false;
|
|
766
831
|
this._maskExpressionArray = [];
|
|
767
832
|
this.triggerOnMaskChange = false;
|
|
768
|
-
this._emitValue = false;
|
|
769
833
|
this._previousValue = '';
|
|
770
834
|
this._currentValue = '';
|
|
835
|
+
this._emitValue = false;
|
|
771
836
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
772
837
|
this.onChange = (_) => { };
|
|
838
|
+
this._elementRef = inject(ElementRef, { optional: true });
|
|
773
839
|
this.document = inject(DOCUMENT);
|
|
774
840
|
this._config = inject(NGX_MASK_CONFIG);
|
|
775
|
-
this._elementRef = inject(ElementRef, { optional: true });
|
|
776
841
|
this._renderer = inject(Renderer2, { optional: true });
|
|
777
842
|
}
|
|
778
843
|
// eslint-disable-next-line complexity
|
|
779
844
|
applyMask(inputValue, maskExpression, position = 0, justPasted = false, backspaced = false,
|
|
780
845
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
|
|
781
846
|
cb = () => { }) {
|
|
782
|
-
var _a;
|
|
847
|
+
var _a, _b;
|
|
783
848
|
if (!maskExpression) {
|
|
784
849
|
return inputValue !== this.actualValue ? this.actualValue : inputValue;
|
|
785
850
|
}
|
|
@@ -794,7 +859,7 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
794
859
|
}
|
|
795
860
|
if (!inputValue && this.showMaskTyped) {
|
|
796
861
|
this.formControlResult(this.prefix);
|
|
797
|
-
return this.prefix + this.maskIsShown;
|
|
862
|
+
return this.prefix + this.maskIsShown + this.suffix;
|
|
798
863
|
}
|
|
799
864
|
const getSymbol = !!inputValue && typeof this.selStart === 'number'
|
|
800
865
|
? (_a = inputValue[this.selStart]) !== null && _a !== void 0 ? _a : "" /* MaskExpression.EMPTY_STRING */
|
|
@@ -840,6 +905,11 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
840
905
|
if (justPasted && (this.hiddenInput || !this.hiddenInput)) {
|
|
841
906
|
newInputValue = inputValue;
|
|
842
907
|
}
|
|
908
|
+
if (backspaced &&
|
|
909
|
+
this.specialCharacters.indexOf((_b = this.maskExpression[position]) !== null && _b !== void 0 ? _b : "" /* MaskExpression.EMPTY_STRING */) !== -1 &&
|
|
910
|
+
this.showMaskTyped) {
|
|
911
|
+
newInputValue = this._currentValue;
|
|
912
|
+
}
|
|
843
913
|
if (this.deletedSpecialCharacter && position) {
|
|
844
914
|
if (this.specialCharacters.includes(this.actualValue.slice(position, position + 1))) {
|
|
845
915
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -908,7 +978,7 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
908
978
|
return result;
|
|
909
979
|
}
|
|
910
980
|
const resLen = result.length;
|
|
911
|
-
const prefNmask = this.prefix + this.maskIsShown;
|
|
981
|
+
const prefNmask = this.prefix + this.maskIsShown + this.suffix;
|
|
912
982
|
if (this.maskExpression.includes("H" /* MaskExpression.HOURS */)) {
|
|
913
983
|
const countSkipedSymbol = this._numberSkipedSymbols(result);
|
|
914
984
|
return result + prefNmask.slice(resLen + countSkipedSymbol);
|
|
@@ -1228,11 +1298,17 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1228
1298
|
return value ? value.replace(this.suffix, "" /* MaskExpression.EMPTY_STRING */) : value;
|
|
1229
1299
|
}
|
|
1230
1300
|
_retrieveSeparatorValue(result) {
|
|
1231
|
-
|
|
1301
|
+
let specialCharacters = Array.isArray(this.dropSpecialCharacters)
|
|
1232
1302
|
? this.specialCharacters.filter((v) => {
|
|
1233
1303
|
return this.dropSpecialCharacters.includes(v);
|
|
1234
1304
|
})
|
|
1235
1305
|
: this.specialCharacters;
|
|
1306
|
+
if (!this.deletedSpecialCharacter &&
|
|
1307
|
+
this._checkPatternForSpace() &&
|
|
1308
|
+
result.includes(" " /* MaskExpression.WHITE_SPACE */) &&
|
|
1309
|
+
this.maskExpression.includes("*" /* MaskExpression.SYMBOL_STAR */)) {
|
|
1310
|
+
specialCharacters = specialCharacters.filter((char) => char !== " " /* MaskExpression.WHITE_SPACE */);
|
|
1311
|
+
}
|
|
1236
1312
|
return this._removeMask(result, specialCharacters);
|
|
1237
1313
|
}
|
|
1238
1314
|
_regExpForRemove(specialCharactersForRemove) {
|
|
@@ -1271,6 +1347,21 @@ class NgxMaskService extends NgxMaskApplierService {
|
|
|
1271
1347
|
return separatorValue;
|
|
1272
1348
|
}
|
|
1273
1349
|
}
|
|
1350
|
+
_checkPatternForSpace() {
|
|
1351
|
+
var _a, _b, _c;
|
|
1352
|
+
for (const key in this.patterns) {
|
|
1353
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
1354
|
+
if (this.patterns[key] && ((_a = this.patterns[key]) === null || _a === void 0 ? void 0 : _a.hasOwnProperty('pattern'))) {
|
|
1355
|
+
const patternString = (_b = this.patterns[key]) === null || _b === void 0 ? void 0 : _b.pattern.toString();
|
|
1356
|
+
const pattern = (_c = this.patterns[key]) === null || _c === void 0 ? void 0 : _c.pattern;
|
|
1357
|
+
if ((patternString === null || patternString === void 0 ? void 0 : patternString.includes(" " /* MaskExpression.WHITE_SPACE */)) &&
|
|
1358
|
+
(pattern === null || pattern === void 0 ? void 0 : pattern.test(this.maskExpression))) {
|
|
1359
|
+
return true;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1274
1365
|
// TODO should think about helpers or separting decimal precision to own property
|
|
1275
1366
|
_retrieveSeparatorPrecision(maskExpretion) {
|
|
1276
1367
|
const matcher = maskExpretion.match(new RegExp(`^separator\\.([^d]*)`));
|
|
@@ -1360,6 +1451,7 @@ class NgxMaskDirective {
|
|
|
1360
1451
|
this._position = null;
|
|
1361
1452
|
this._maskExpressionArray = [];
|
|
1362
1453
|
this._justPasted = false;
|
|
1454
|
+
this._isFocused = false;
|
|
1363
1455
|
/**For IME composition event */
|
|
1364
1456
|
this._isComposing = false;
|
|
1365
1457
|
this.document = inject(DOCUMENT);
|
|
@@ -1377,13 +1469,6 @@ class NgxMaskDirective {
|
|
|
1377
1469
|
!maskExpression.firstChange) {
|
|
1378
1470
|
this._maskService.maskChanged = true;
|
|
1379
1471
|
}
|
|
1380
|
-
if (allowNegativeNumbers) {
|
|
1381
|
-
this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
|
|
1382
|
-
if (this._maskService.allowNegativeNumbers) {
|
|
1383
|
-
this._maskService.specialCharacters =
|
|
1384
|
-
this._maskService.specialCharacters.filter((c) => c !== "-" /* MaskExpression.MINUS */);
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
1472
|
if (maskExpression.currentValue &&
|
|
1388
1473
|
maskExpression.currentValue.split("||" /* MaskExpression.OR */).length > 1) {
|
|
1389
1474
|
this._maskExpressionArray = maskExpression.currentValue
|
|
@@ -1407,6 +1492,12 @@ class NgxMaskDirective {
|
|
|
1407
1492
|
this._maskService.specialCharacters = specialCharacters.currentValue || [];
|
|
1408
1493
|
}
|
|
1409
1494
|
}
|
|
1495
|
+
if (allowNegativeNumbers) {
|
|
1496
|
+
this._maskService.allowNegativeNumbers = allowNegativeNumbers.currentValue;
|
|
1497
|
+
if (this._maskService.allowNegativeNumbers) {
|
|
1498
|
+
this._maskService.specialCharacters = this._maskService.specialCharacters.filter((c) => c !== "-" /* MaskExpression.MINUS */);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1410
1501
|
// Only overwrite the mask available patterns if a pattern has actually been passed in
|
|
1411
1502
|
if (patterns && patterns.currentValue) {
|
|
1412
1503
|
this._maskService.patterns = patterns.currentValue;
|
|
@@ -1434,6 +1525,14 @@ class NgxMaskDirective {
|
|
|
1434
1525
|
}
|
|
1435
1526
|
if (showMaskTyped) {
|
|
1436
1527
|
this._maskService.showMaskTyped = showMaskTyped.currentValue;
|
|
1528
|
+
if (showMaskTyped.previousValue === false &&
|
|
1529
|
+
showMaskTyped.currentValue === true &&
|
|
1530
|
+
this._isFocused) {
|
|
1531
|
+
requestAnimationFrame(() => {
|
|
1532
|
+
var _a;
|
|
1533
|
+
(_a = this._maskService._elementRef) === null || _a === void 0 ? void 0 : _a.nativeElement.click();
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1437
1536
|
}
|
|
1438
1537
|
if (placeHolderCharacter) {
|
|
1439
1538
|
this._maskService.placeHolderCharacter = placeHolderCharacter.currentValue;
|
|
@@ -1593,6 +1692,9 @@ class NgxMaskDirective {
|
|
|
1593
1692
|
onPaste() {
|
|
1594
1693
|
this._justPasted = true;
|
|
1595
1694
|
}
|
|
1695
|
+
onFocus() {
|
|
1696
|
+
this._isFocused = true;
|
|
1697
|
+
}
|
|
1596
1698
|
onModelChange(value) {
|
|
1597
1699
|
// on form reset we need to update the actualValue
|
|
1598
1700
|
if ((value === "" /* MaskExpression.EMPTY_STRING */ || value === null || value === undefined) &&
|
|
@@ -1601,7 +1703,7 @@ class NgxMaskDirective {
|
|
|
1601
1703
|
}
|
|
1602
1704
|
}
|
|
1603
1705
|
onInput(e) {
|
|
1604
|
-
var _a, _b, _c, _d;
|
|
1706
|
+
var _a, _b, _c, _d, _e;
|
|
1605
1707
|
// If IME is composing text, we wait for the composed text.
|
|
1606
1708
|
if (this._isComposing)
|
|
1607
1709
|
return;
|
|
@@ -1692,13 +1794,32 @@ class NgxMaskDirective {
|
|
|
1692
1794
|
position = position + 1;
|
|
1693
1795
|
}
|
|
1694
1796
|
else if (checkSymbols) {
|
|
1797
|
+
if (el.value.length === 1 && position === 1) {
|
|
1798
|
+
this._maskService.actualValue =
|
|
1799
|
+
this.prefix +
|
|
1800
|
+
inputSymbol +
|
|
1801
|
+
this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
|
|
1802
|
+
this.suffix;
|
|
1803
|
+
}
|
|
1804
|
+
else {
|
|
1805
|
+
this._maskService.actualValue =
|
|
1806
|
+
el.value.slice(0, position - 1) +
|
|
1807
|
+
inputSymbol +
|
|
1808
|
+
el.value
|
|
1809
|
+
.slice(position + 1)
|
|
1810
|
+
.split(this.suffix)
|
|
1811
|
+
.join('') +
|
|
1812
|
+
this.suffix;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
else if (this.prefix &&
|
|
1816
|
+
el.value.length === 1 &&
|
|
1817
|
+
position - prefixLength === 1 &&
|
|
1818
|
+
this._maskService._checkSymbolMask(el.value, (_e = this._maskService.maskExpression[position - 1 - prefixLength]) !== null && _e !== void 0 ? _e : "" /* MaskExpression.EMPTY_STRING */)) {
|
|
1695
1819
|
this._maskService.actualValue =
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
.slice(position + 1)
|
|
1700
|
-
.split(this.suffix)
|
|
1701
|
-
.join('') +
|
|
1820
|
+
this.prefix +
|
|
1821
|
+
el.value +
|
|
1822
|
+
this._maskService.maskIsShown.slice(1, this._maskService.maskIsShown.length) +
|
|
1702
1823
|
this.suffix;
|
|
1703
1824
|
}
|
|
1704
1825
|
}
|
|
@@ -1718,6 +1839,13 @@ class NgxMaskDirective {
|
|
|
1718
1839
|
inputSymbol +
|
|
1719
1840
|
this._inputValue.slice(position + 1);
|
|
1720
1841
|
}
|
|
1842
|
+
if (this._maskService.maskExpression === "d0/M0/0000" /* MaskExpression.DAYS_MONTHS_YEARS */ &&
|
|
1843
|
+
this.leadZeroDateTime) {
|
|
1844
|
+
if ((position < 3 && Number(el.value) > 31 && Number(el.value) < 40) ||
|
|
1845
|
+
(position === 5 && Number(el.value.slice(3, 5)) > 12)) {
|
|
1846
|
+
position = position + 2;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1721
1849
|
if (this._maskService.maskExpression === "Hh:m0:s0" /* MaskExpression.HOURS_MINUTES_SECONDS */ &&
|
|
1722
1850
|
this.apm) {
|
|
1723
1851
|
if (this._justPasted && el.value.slice(0, 2) === "00" /* MaskExpression.DOUBLE_ZERO */) {
|
|
@@ -1737,6 +1865,10 @@ class NgxMaskDirective {
|
|
|
1737
1865
|
if (this._getActiveElement() !== el) {
|
|
1738
1866
|
return;
|
|
1739
1867
|
}
|
|
1868
|
+
if (this._maskService.plusOnePosition) {
|
|
1869
|
+
position = position + 1;
|
|
1870
|
+
this._maskService.plusOnePosition = false;
|
|
1871
|
+
}
|
|
1740
1872
|
// update position after applyValueChanges to prevent cursor on wrong position when it has an array of maskExpression
|
|
1741
1873
|
if (this._maskExpressionArray.length) {
|
|
1742
1874
|
if (this._code === "Backspace" /* MaskExpression.BACKSPACE */) {
|
|
@@ -1758,7 +1890,10 @@ class NgxMaskDirective {
|
|
|
1758
1890
|
: position +
|
|
1759
1891
|
(this._code === "Backspace" /* MaskExpression.BACKSPACE */ && !backspaceShift ? 0 : caretShift);
|
|
1760
1892
|
if (positionToApply > this._getActualInputLength()) {
|
|
1761
|
-
positionToApply =
|
|
1893
|
+
positionToApply =
|
|
1894
|
+
el.value === this._maskService.decimalMarker && el.value.length === 1
|
|
1895
|
+
? this._getActualInputLength() + 1
|
|
1896
|
+
: this._getActualInputLength();
|
|
1762
1897
|
}
|
|
1763
1898
|
if (positionToApply < 0) {
|
|
1764
1899
|
positionToApply = 0;
|
|
@@ -1771,6 +1906,10 @@ class NgxMaskDirective {
|
|
|
1771
1906
|
}
|
|
1772
1907
|
}
|
|
1773
1908
|
else {
|
|
1909
|
+
if (!this._maskValue) {
|
|
1910
|
+
this.onChange(el.value);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1774
1913
|
this._maskService.applyValueChanges(el.value.length, this._justPasted, this._code === "Backspace" /* MaskExpression.BACKSPACE */ || this._code === "Delete" /* MaskExpression.DELETE */);
|
|
1775
1914
|
}
|
|
1776
1915
|
}
|
|
@@ -1806,6 +1945,7 @@ class NgxMaskDirective {
|
|
|
1806
1945
|
}
|
|
1807
1946
|
this._maskService.clearIfNotMatchFn();
|
|
1808
1947
|
}
|
|
1948
|
+
this._isFocused = false;
|
|
1809
1949
|
this.onTouch();
|
|
1810
1950
|
}
|
|
1811
1951
|
onClick(e) {
|
|
@@ -1939,7 +2079,6 @@ class NgxMaskDirective {
|
|
|
1939
2079
|
}
|
|
1940
2080
|
}
|
|
1941
2081
|
/** It writes the value in the input */
|
|
1942
|
-
// public async writeValue(controlValue: unknown): Promise<void> {
|
|
1943
2082
|
writeValue(controlValue) {
|
|
1944
2083
|
var _a;
|
|
1945
2084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1947,7 +2086,7 @@ class NgxMaskDirective {
|
|
|
1947
2086
|
if ('disable' in controlValue) {
|
|
1948
2087
|
this.setDisabledState(Boolean(controlValue.disable));
|
|
1949
2088
|
}
|
|
1950
|
-
//
|
|
2089
|
+
// eslint-disable-next-line no-param-reassign
|
|
1951
2090
|
controlValue = controlValue.value;
|
|
1952
2091
|
}
|
|
1953
2092
|
if (controlValue !== null) {
|
|
@@ -1958,7 +2097,12 @@ class NgxMaskDirective {
|
|
|
1958
2097
|
}
|
|
1959
2098
|
if (typeof controlValue === 'string' ||
|
|
1960
2099
|
typeof controlValue === 'number' ||
|
|
1961
|
-
controlValue === null
|
|
2100
|
+
controlValue === null ||
|
|
2101
|
+
controlValue === undefined) {
|
|
2102
|
+
if (controlValue === null || controlValue === undefined || controlValue === '') {
|
|
2103
|
+
this._maskService._currentValue = '';
|
|
2104
|
+
this._maskService._previousValue = '';
|
|
2105
|
+
}
|
|
1962
2106
|
// eslint-disable-next-line no-param-reassign
|
|
1963
2107
|
let inputValue = controlValue;
|
|
1964
2108
|
if (typeof inputValue === 'number' ||
|
|
@@ -2114,7 +2258,8 @@ class NgxMaskDirective {
|
|
|
2114
2258
|
}
|
|
2115
2259
|
}
|
|
2116
2260
|
else {
|
|
2117
|
-
const check = (_d = this.
|
|
2261
|
+
const check = (_d = this._maskService
|
|
2262
|
+
.removeMask(this._inputValue)) === null || _d === void 0 ? void 0 : _d.split("" /* MaskExpression.EMPTY_STRING */).every((character, index) => {
|
|
2118
2263
|
const indexMask = mask.charAt(index);
|
|
2119
2264
|
return this._maskService._checkSymbolMask(character, indexMask);
|
|
2120
2265
|
});
|
|
@@ -2127,7 +2272,7 @@ class NgxMaskDirective {
|
|
|
2127
2272
|
}
|
|
2128
2273
|
}
|
|
2129
2274
|
NgxMaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2130
|
-
NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: NgxMaskDirective, selector: "input[mask], textarea[mask]", inputs: { maskExpression: ["mask", "maskExpression"], specialCharacters: "specialCharacters", patterns: "patterns", prefix: "prefix", suffix: "suffix", thousandSeparator: "thousandSeparator", decimalMarker: "decimalMarker", dropSpecialCharacters: "dropSpecialCharacters", hiddenInput: "hiddenInput", showMaskTyped: "showMaskTyped", placeHolderCharacter: "placeHolderCharacter", shownMaskExpression: "shownMaskExpression", showTemplate: "showTemplate", clearIfNotMatch: "clearIfNotMatch", validation: "validation", separatorLimit: "separatorLimit", allowNegativeNumbers: "allowNegativeNumbers", leadZeroDateTime: "leadZeroDateTime", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
|
|
2275
|
+
NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: NgxMaskDirective, selector: "input[mask], textarea[mask]", inputs: { maskExpression: ["mask", "maskExpression"], specialCharacters: "specialCharacters", patterns: "patterns", prefix: "prefix", suffix: "suffix", thousandSeparator: "thousandSeparator", decimalMarker: "decimalMarker", dropSpecialCharacters: "dropSpecialCharacters", hiddenInput: "hiddenInput", showMaskTyped: "showMaskTyped", placeHolderCharacter: "placeHolderCharacter", shownMaskExpression: "shownMaskExpression", showTemplate: "showTemplate", clearIfNotMatch: "clearIfNotMatch", validation: "validation", separatorLimit: "separatorLimit", allowNegativeNumbers: "allowNegativeNumbers", leadZeroDateTime: "leadZeroDateTime", leadZero: "leadZero", triggerOnMaskChange: "triggerOnMaskChange", apm: "apm", inputTransformFn: "inputTransformFn", outputTransformFn: "outputTransformFn", keepCharacterPositions: "keepCharacterPositions" }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "focus": "onFocus($event)", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
|
|
2131
2276
|
{
|
|
2132
2277
|
provide: NG_VALUE_ACCESSOR,
|
|
2133
2278
|
useExisting: forwardRef(() => NgxMaskDirective),
|
|
@@ -2139,7 +2284,7 @@ NgxMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", versi
|
|
|
2139
2284
|
multi: true,
|
|
2140
2285
|
},
|
|
2141
2286
|
NgxMaskService,
|
|
2142
|
-
], usesOnChanges: true, ngImport: i0 });
|
|
2287
|
+
], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
|
|
2143
2288
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: NgxMaskDirective, decorators: [{
|
|
2144
2289
|
type: Directive,
|
|
2145
2290
|
args: [{
|
|
@@ -2157,6 +2302,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
|
|
|
2157
2302
|
},
|
|
2158
2303
|
NgxMaskService,
|
|
2159
2304
|
],
|
|
2305
|
+
exportAs: 'mask,ngxMask',
|
|
2160
2306
|
}]
|
|
2161
2307
|
}], propDecorators: { maskExpression: [{
|
|
2162
2308
|
type: Input,
|
|
@@ -2212,6 +2358,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
|
|
|
2212
2358
|
}], onPaste: [{
|
|
2213
2359
|
type: HostListener,
|
|
2214
2360
|
args: ['paste']
|
|
2361
|
+
}], onFocus: [{
|
|
2362
|
+
type: HostListener,
|
|
2363
|
+
args: ['focus', ['$event']]
|
|
2215
2364
|
}], onModelChange: [{
|
|
2216
2365
|
type: HostListener,
|
|
2217
2366
|
args: ['ngModelChange', ['$event']]
|
|
@@ -2298,6 +2447,9 @@ class NgxMaskPipe {
|
|
|
2298
2447
|
}
|
|
2299
2448
|
this._maskService.isNumberValue = true;
|
|
2300
2449
|
}
|
|
2450
|
+
if (value === null || value === undefined) {
|
|
2451
|
+
return this._maskService.applyMask('', mask);
|
|
2452
|
+
}
|
|
2301
2453
|
return this._maskService.applyMask(`${value}`, mask);
|
|
2302
2454
|
}
|
|
2303
2455
|
_setMask(value) {
|