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.
@@ -1841,6 +1841,7 @@ var DIAL_CODE = {
1841
1841
  NANP: "1"
1842
1842
  // North American Numbering Plan
1843
1843
  };
1844
+ var E164_MAX_DIGITS = 15;
1844
1845
  var UK = {
1845
1846
  ISO2: "gb",
1846
1847
  DIAL_CODE: "44",
@@ -4181,8 +4182,8 @@ var Iti = class _Iti {
4181
4182
  const after = inputValue.slice(selEnd ?? void 0);
4182
4183
  const newValue = before + normalisedKey + after;
4183
4184
  const newFullNumber = this.#buildFullNumber(newValue);
4184
- let hasExceededMaxLength = false;
4185
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
4185
+ let hasExceededMaxLength = getNumeric(newFullNumber).length > E164_MAX_DIGITS;
4186
+ if (!hasExceededMaxLength && intlTelInput.utils && this.#maxCoreNumberLength) {
4186
4187
  const coreNumber = intlTelInput.utils.getCoreNumber(
4187
4188
  newFullNumber,
4188
4189
  this.#selectedCountry?.iso2
@@ -4247,44 +4248,35 @@ var Iti = class _Iti {
4247
4248
  let newValue = before + sanitised + after;
4248
4249
  let rejectReason = sanitised !== pasted ? "invalid" : null;
4249
4250
  if (newValue.length > 30) {
4250
- this.#ui.playStrictRejectAnimation();
4251
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4252
- source: "paste",
4253
- rejectedInput: pastedRaw,
4254
- reason: "max-length"
4255
- });
4256
- this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4251
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4257
4252
  return true;
4258
4253
  }
4259
- if (newValue.length > 5 && intlTelInput.utils) {
4254
+ const excessDigits = getNumeric(this.#buildFullNumber(newValue)).length - E164_MAX_DIGITS;
4255
+ if (excessDigits > 0) {
4256
+ if (selEnd !== originalValue.length) {
4257
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4258
+ return true;
4259
+ }
4260
+ newValue = newValue.slice(0, newValue.length - excessDigits);
4261
+ rejectReason = "max-length";
4262
+ }
4263
+ if (this.#maxCoreNumberLength && newValue.length > 5 && intlTelInput.utils) {
4260
4264
  let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
4261
4265
  while (coreNumber.length === 0 && newValue.length > 0) {
4262
4266
  newValue = newValue.slice(0, -1);
4263
4267
  coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
4264
4268
  }
4265
4269
  if (!coreNumber) {
4266
- this.#ui.playStrictRejectAnimation();
4267
- this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4268
- source: "paste",
4269
- rejectedInput: pastedRaw,
4270
- reason: "max-length"
4271
- });
4272
- this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4270
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4273
4271
  return true;
4274
4272
  }
4275
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
4273
+ if (coreNumber.length > this.#maxCoreNumberLength) {
4276
4274
  if (selEnd === originalValue.length) {
4277
4275
  const trimLength = coreNumber.length - this.#maxCoreNumberLength;
4278
4276
  newValue = newValue.slice(0, newValue.length - trimLength);
4279
4277
  rejectReason = "max-length";
4280
4278
  } else {
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);
4279
+ this.#rejectStrictPasteAsTooLong(pasteSnapshot);
4288
4280
  return true;
4289
4281
  }
4290
4282
  }
@@ -4304,6 +4296,16 @@ var Iti = class _Iti {
4304
4296
  }
4305
4297
  return false;
4306
4298
  }
4299
+ // Reject a paste entirely because it would exceed the max length, restoring the previous value.
4300
+ #rejectStrictPasteAsTooLong(pasteSnapshot) {
4301
+ this.#ui.playStrictRejectAnimation();
4302
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
4303
+ source: "paste",
4304
+ rejectedInput: pasteSnapshot.pastedRaw,
4305
+ reason: "max-length"
4306
+ });
4307
+ this.#restoreValueBeforeStrictPaste(pasteSnapshot);
4308
+ }
4307
4309
  #restoreValueBeforeStrictPaste(pasteSnapshot) {
4308
4310
  this.#setTelInputValue(pasteSnapshot.value);
4309
4311
  this.#ui.telInputEl.setSelectionRange(
@@ -4412,6 +4414,9 @@ var Iti = class _Iti {
4412
4414
  if (currentDial && currentDial.startsWith(numeric)) {
4413
4415
  return null;
4414
4416
  }
4417
+ if (!selectedIso2) {
4418
+ return null;
4419
+ }
4415
4420
  return "";
4416
4421
  } else if ((!number || number === "+") && !selectedIso2 && this.#fallbackCountryIso2) {
4417
4422
  return this.#fallbackCountryIso2;
@@ -4655,7 +4660,9 @@ var Iti = class _Iti {
4655
4660
  this.#autoCountryDeferred?.reject();
4656
4661
  return;
4657
4662
  }
4658
- this.#setInitialState(true);
4663
+ if (this.#ui.isLoading()) {
4664
+ this.#setInitialState(true);
4665
+ }
4659
4666
  this.#ui.setLoading(false);
4660
4667
  this.#autoCountryDeferred?.reject();
4661
4668
  }
@@ -4948,7 +4955,7 @@ var intlTelInput = Object.assign(
4948
4955
  attachUtils,
4949
4956
  startedLoadingUtils: false,
4950
4957
  startedLoadingAutoCountry: false,
4951
- version: "29.2.0",
4958
+ version: "29.2.2",
4952
4959
  NUMBER_FORMAT,
4953
4960
  NUMBER_TYPE,
4954
4961
  VALIDATION_ERROR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "29.2.0",
3
+ "version": "29.2.2",
4
4
  "description": "A JavaScript library for entering, formatting, and validating international telephone numbers",
5
5
  "type": "module",
6
6
  "license": "MIT",