intl-tel-input 29.2.0 → 29.2.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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v29.2.0
2
+ * International Telephone Input v29.2.2
3
3
  * git+https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -1872,6 +1872,7 @@ var _factory = (() => {
1872
1872
  NANP: "1"
1873
1873
  // North American Numbering Plan
1874
1874
  };
1875
+ var E164_MAX_DIGITS = 15;
1875
1876
  var UK = {
1876
1877
  ISO2: "gb",
1877
1878
  DIAL_CODE: "44",
@@ -4212,8 +4213,8 @@ var _factory = (() => {
4212
4213
  const after = inputValue.slice(selEnd ?? void 0);
4213
4214
  const newValue = before + normalisedKey + after;
4214
4215
  const newFullNumber = this.#buildFullNumber(newValue);
4215
- let hasExceededMaxLength = false;
4216
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
4216
+ let hasExceededMaxLength = getNumeric(newFullNumber).length > E164_MAX_DIGITS;
4217
+ if (!hasExceededMaxLength && intlTelInput.utils && this.#maxCoreNumberLength) {
4217
4218
  const coreNumber = intlTelInput.utils.getCoreNumber(
4218
4219
  newFullNumber,
4219
4220
  this.#selectedCountry?.iso2
@@ -4278,44 +4279,35 @@ var _factory = (() => {
4278
4279
  let newValue = before + sanitised + after;
4279
4280
  let rejectReason = sanitised !== pasted ? "invalid" : null;
4280
4281
  if (newValue.length > 30) {
4281
- this.#ui.playStrictRejectAnimation();
4282
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4283
- source: "paste",
4284
- rejectedInput: pastedRaw,
4285
- reason: "max-length"
4286
- });
4287
- this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4282
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4288
4283
  return true;
4289
4284
  }
4290
- if (newValue.length > 5 && intlTelInput.utils) {
4285
+ const excessDigits = getNumeric(this.#buildFullNumber(newValue)).length - E164_MAX_DIGITS;
4286
+ if (excessDigits > 0) {
4287
+ if (selEnd !== originalValue.length) {
4288
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4289
+ return true;
4290
+ }
4291
+ newValue = newValue.slice(0, newValue.length - excessDigits);
4292
+ rejectReason = "max-length";
4293
+ }
4294
+ if (this.#maxCoreNumberLength && newValue.length > 5 && intlTelInput.utils) {
4291
4295
  let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
4292
4296
  while (coreNumber.length === 0 && newValue.length > 0) {
4293
4297
  newValue = newValue.slice(0, -1);
4294
4298
  coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
4295
4299
  }
4296
4300
  if (!coreNumber) {
4297
- this.#ui.playStrictRejectAnimation();
4298
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4299
- source: "paste",
4300
- rejectedInput: pastedRaw,
4301
- reason: "max-length"
4302
- });
4303
- this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4301
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4304
4302
  return true;
4305
4303
  }
4306
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
4304
+ if (coreNumber.length > this.#maxCoreNumberLength) {
4307
4305
  if (selEnd === originalValue.length) {
4308
4306
  const trimLength = coreNumber.length - this.#maxCoreNumberLength;
4309
4307
  newValue = newValue.slice(0, newValue.length - trimLength);
4310
4308
  rejectReason = "max-length";
4311
4309
  } else {
4312
- this.#ui.playStrictRejectAnimation();
4313
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4314
- source: "paste",
4315
- rejectedInput: pastedRaw,
4316
- reason: "max-length"
4317
- });
4318
- this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4310
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4319
4311
  return true;
4320
4312
  }
4321
4313
  }
@@ -4335,6 +4327,16 @@ var _factory = (() => {
4335
4327
  }
4336
4328
  return false;
4337
4329
  }
4330
+ // Reject a paste entirely because it would exceed the max length, restoring the previous value.
4331
+ #rejectStrictPasteAsTooLong(pasteSnapshot) {
4332
+ this.#ui.playStrictRejectAnimation();
4333
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4334
+ source: "paste",
4335
+ rejectedInput: pasteSnapshot.pastedRaw,
4336
+ reason: "max-length"
4337
+ });
4338
+ this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4339
+ }
4338
4340
  #restoreValueBeforeStrictPaste(pasteSnapshot) {
4339
4341
  this.#setTelInputValue(pasteSnapshot.value);
4340
4342
  this.#ui.telInputEl.setSelectionRange(
@@ -4443,6 +4445,9 @@ var _factory = (() => {
4443
4445
  if (currentDial && currentDial.startsWith(numeric)) {
4444
4446
  return null;
4445
4447
  }
4448
+ if (!selectedIso2) {
4449
+ return null;
4450
+ }
4446
4451
  return "";
4447
4452
  } else if ((!number || number === "+") && !selectedIso2 && this.#fallbackCountryIso2) {
4448
4453
  return this.#fallbackCountryIso2;
@@ -4686,7 +4691,9 @@ var _factory = (() => {
4686
4691
  this.#autoCountryDeferred?.reject();
4687
4692
  return;
4688
4693
  }
4689
- this.#setInitialState(true);
4694
+ if (this.#ui.isLoading()) {
4695
+ this.#setInitialState(true);
4696
+ }
4690
4697
  this.#ui.setLoading(false);
4691
4698
  this.#autoCountryDeferred?.reject();
4692
4699
  }
@@ -4979,7 +4986,7 @@ var _factory = (() => {
4979
4986
  attachUtils,
4980
4987
  startedLoadingUtils: false,
4981
4988
  startedLoadingAutoCountry: false,
4982
- version: "29.2.0",
4989
+ version: "29.2.2",
4983
4990
  NUMBER_FORMAT,
4984
4991
  NUMBER_TYPE,
4985
4992
  VALIDATION_ERROR,