ngx-mask 11.1.5 → 12.0.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.
@@ -371,18 +371,21 @@
371
371
  function __importDefault(mod) {
372
372
  return (mod && mod.__esModule) ? mod : { default: mod };
373
373
  }
374
- function __classPrivateFieldGet(receiver, privateMap) {
375
- if (!privateMap.has(receiver)) {
376
- throw new TypeError("attempted to get private field on non-instance");
377
- }
378
- return privateMap.get(receiver);
374
+ function __classPrivateFieldGet(receiver, state, kind, f) {
375
+ if (kind === "a" && !f)
376
+ throw new TypeError("Private accessor was defined without a getter");
377
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
378
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
379
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
379
380
  }
380
- function __classPrivateFieldSet(receiver, privateMap, value) {
381
- if (!privateMap.has(receiver)) {
382
- throw new TypeError("attempted to set private field on non-instance");
383
- }
384
- privateMap.set(receiver, value);
385
- return value;
381
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
382
+ if (kind === "m")
383
+ throw new TypeError("Private method is not writable");
384
+ if (kind === "a" && !f)
385
+ throw new TypeError("Private accessor was defined without a setter");
386
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
387
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
388
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
386
389
  }
387
390
 
388
391
  var MaskApplierService = /** @class */ (function () {
@@ -541,7 +544,7 @@
541
544
  inputValue = this._stripToDecimal(inputValue);
542
545
  }
543
546
  inputValue =
544
- inputValue.length > 1 && inputValue[0] === '0' && inputValue[1] !== this.decimalMarker
547
+ inputValue.length > 1 && inputValue[0] === '0' && inputValue[1] !== this.decimalMarker && !backspaced
545
548
  ? inputValue.slice(1, inputValue.length)
546
549
  : inputValue;
547
550
  // TODO: we had different rexexps here for the different cases... but tests dont seam to bother - check this
@@ -840,6 +843,7 @@
840
843
  * since writeValue should be a one way only process of writing the DOM value based on the Angular model value.
841
844
  */
842
845
  _this.writingValue = false;
846
+ _this.maskChanged = false;
843
847
  _this.onChange = function (_) { };
844
848
  return _this;
845
849
  }
@@ -1108,7 +1112,8 @@
1108
1112
  * @param inputValue the current form input value
1109
1113
  */
1110
1114
  MaskService.prototype.formControlResult = function (inputValue) {
1111
- if (this.writingValue) {
1115
+ if (this.writingValue || this.maskChanged) {
1116
+ this.maskChanged = false;
1112
1117
  return;
1113
1118
  }
1114
1119
  if (Array.isArray(this.dropSpecialCharacters)) {
@@ -1229,6 +1234,9 @@
1229
1234
  MaskDirective.prototype.ngOnChanges = function (changes) {
1230
1235
  var maskExpression = changes.maskExpression, specialCharacters = changes.specialCharacters, patterns = changes.patterns, prefix = changes.prefix, suffix = changes.suffix, thousandSeparator = changes.thousandSeparator, decimalMarker = changes.decimalMarker, dropSpecialCharacters = changes.dropSpecialCharacters, hiddenInput = changes.hiddenInput, showMaskTyped = changes.showMaskTyped, placeHolderCharacter = changes.placeHolderCharacter, shownMaskExpression = changes.shownMaskExpression, showTemplate = changes.showTemplate, clearIfNotMatch = changes.clearIfNotMatch, validation = changes.validation, separatorLimit = changes.separatorLimit, allowNegativeNumbers = changes.allowNegativeNumbers, leadZeroDateTime = changes.leadZeroDateTime;
1231
1236
  if (maskExpression) {
1237
+ if (maskExpression.currentValue !== maskExpression.previousValue && !maskExpression.firstChange) {
1238
+ this._maskService.maskChanged = true;
1239
+ }
1232
1240
  this._maskValue = maskExpression.currentValue || '';
1233
1241
  if (maskExpression.currentValue && maskExpression.currentValue.split('||').length > 1) {
1234
1242
  this._maskExpressionArray = maskExpression.currentValue.split('||').sort(function (a, b) {
@@ -1302,8 +1310,8 @@
1302
1310
  this._applyMask();
1303
1311
  };
1304
1312
  // tslint:disable-next-line: cyclomatic-complexity
1305
- MaskDirective.prototype.validate = function (_b) {
1306
- var value = _b.value;
1313
+ MaskDirective.prototype.validate = function (_c) {
1314
+ var value = _c.value;
1307
1315
  if (!this._maskService.validation || !this._maskValue) {
1308
1316
  return null;
1309
1317
  }
@@ -1394,7 +1402,7 @@
1394
1402
  : el.selectionStart;
1395
1403
  var caretShift = 0;
1396
1404
  var backspaceShift = false;
1397
- this._maskService.applyValueChanges(position, this._justPasted, this._code === 'Backspace', function (shift, _backspaceShift) {
1405
+ this._maskService.applyValueChanges(position, this._justPasted, this._code === 'Backspace' || this._code === 'Delete', function (shift, _backspaceShift) {
1398
1406
  _this._justPasted = false;
1399
1407
  caretShift = shift;
1400
1408
  backspaceShift = _backspaceShift;
@@ -1410,6 +1418,9 @@
1410
1418
  if (positionToApply > this._getActualInputLength()) {
1411
1419
  positionToApply = this._getActualInputLength();
1412
1420
  }
1421
+ if (positionToApply < 0) {
1422
+ positionToApply = 0;
1423
+ }
1413
1424
  el.setSelectionRange(positionToApply, positionToApply);
1414
1425
  this._position = null;
1415
1426
  };
@@ -1485,7 +1496,8 @@
1485
1496
  }
1486
1497
  if (e.keyCode === 8 && el.selectionStart !== 0) {
1487
1498
  // If specialChars is false, (shouldn't ever happen) then set to the defaults
1488
- this.specialCharacters = ((_a = this.specialCharacters) === null || _a === void 0 ? void 0 : _a.length) ? this.specialCharacters
1499
+ this.specialCharacters = ((_a = this.specialCharacters) === null || _a === void 0 ? void 0 : _a.length)
1500
+ ? this.specialCharacters
1489
1501
  : this._config.specialCharacters;
1490
1502
  if (this.prefix.length > 1 && el.selectionStart <= this.prefix.length) {
1491
1503
  el.setSelectionRange(this.prefix.length, this.prefix.length);
@@ -1535,7 +1547,7 @@
1535
1547
  /** It writes the value in the input */
1536
1548
  MaskDirective.prototype.writeValue = function (inputValue) {
1537
1549
  return __awaiter(this, void 0, void 0, function () {
1538
- return __generator(this, function (_b) {
1550
+ return __generator(this, function (_c) {
1539
1551
  if (typeof inputValue === 'object' && inputValue !== null && 'value' in inputValue) {
1540
1552
  if ('disable' in inputValue) {
1541
1553
  this.setDisabledState(Boolean(inputValue.disable));
@@ -1622,7 +1634,7 @@
1622
1634
  };
1623
1635
  MaskDirective.prototype._validateTime = function (value) {
1624
1636
  var rowMaskLen = this._maskValue.split('').filter(function (s) { return s !== ':'; }).length;
1625
- if (value === null || value.length === 0) {
1637
+ if (!value) {
1626
1638
  return null; // Don't validate empty values to allow for optional form control
1627
1639
  }
1628
1640
  if ((+value[value.length - 1] === 0 && value.length < rowMaskLen) || value.length <= rowMaskLen - 2) {
@@ -1645,7 +1657,8 @@
1645
1657
  var _this = this;
1646
1658
  if (this._maskExpressionArray.length > 0) {
1647
1659
  this._maskExpressionArray.some(function (mask) {
1648
- var test = _this._maskService.removeMask(_this._inputValue).length <= _this._maskService.removeMask(mask).length;
1660
+ var _a, _b;
1661
+ var test = ((_a = _this._maskService.removeMask(_this._inputValue)) === null || _a === void 0 ? void 0 : _a.length) <= ((_b = _this._maskService.removeMask(mask)) === null || _b === void 0 ? void 0 : _b.length);
1649
1662
  if (_this._inputValue && test) {
1650
1663
  _this._maskValue = mask;
1651
1664
  _this.maskExpression = mask;