intl-tel-input 23.0.9 → 23.0.11

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 v23.0.9
2
+ * International Telephone Input v23.0.11
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -1893,10 +1893,11 @@ var factoryOutput = (() => {
1893
1893
  const val = useAttribute ? attributeValue : inputValue;
1894
1894
  const dialCode = this._getDialCode(val);
1895
1895
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1896
- const { initialCountry } = this.options;
1896
+ const { initialCountry, geoIpLookup } = this.options;
1897
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1897
1898
  if (dialCode && !isRegionlessNanpNumber) {
1898
1899
  this._updateCountryFromNumber(val);
1899
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1900
+ } else if (!isAutoCountry || overrideAutoCountry) {
1900
1901
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1901
1902
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1902
1903
  if (isValidInitialCountry) {
@@ -1975,18 +1976,20 @@ var factoryOutput = (() => {
1975
1976
  }
1976
1977
  //* Init many requests: utils script / geo ip lookup.
1977
1978
  _initRequests() {
1978
- if (this.options.utilsScript && !intlTelInput.utils) {
1979
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1980
+ if (utilsScript && !intlTelInput.utils) {
1979
1981
  if (intlTelInput.documentReady()) {
1980
- intlTelInput.loadUtils(this.options.utilsScript);
1982
+ intlTelInput.loadUtils(utilsScript);
1981
1983
  } else {
1982
1984
  window.addEventListener("load", () => {
1983
- intlTelInput.loadUtils(this.options.utilsScript);
1985
+ intlTelInput.loadUtils(utilsScript);
1984
1986
  });
1985
1987
  }
1986
1988
  } else {
1987
1989
  this.resolveUtilsScriptPromise();
1988
1990
  }
1989
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1991
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1992
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1990
1993
  this._loadAutoCountry();
1991
1994
  } else {
1992
1995
  this.resolveAutoCountryPromise();
@@ -2021,24 +2024,25 @@ var factoryOutput = (() => {
2021
2024
  }
2022
2025
  //* Initialize the tel input listeners.
2023
2026
  _initTelInputListeners() {
2024
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
2027
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
2025
2028
  let userOverrideFormatting = false;
2026
2029
  this._handleInputEvent = (e) => {
2027
2030
  if (this._updateCountryFromNumber(this.telInput.value)) {
2028
2031
  this._triggerCountryChange();
2029
2032
  }
2030
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
2031
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
2033
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
2034
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
2032
2035
  if (isFormattingChar || isPaste && !strictMode) {
2033
2036
  userOverrideFormatting = true;
2034
2037
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
2035
2038
  userOverrideFormatting = false;
2036
2039
  }
2037
- if (formatAsYouType && !userOverrideFormatting) {
2040
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
2041
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
2038
2042
  const currentCaretPos = this.telInput.selectionStart || 0;
2039
2043
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2040
2044
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2041
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2045
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2042
2046
  const formattedValue = this._formatNumberAsYouType();
2043
2047
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2044
2048
  this.telInput.value = formattedValue;
@@ -2080,10 +2084,11 @@ var factoryOutput = (() => {
2080
2084
  return max && number.length > max ? number.substr(0, max) : number;
2081
2085
  }
2082
2086
  //* Trigger a custom event on the input.
2083
- _trigger(name) {
2084
- const e = new Event(name, {
2087
+ _trigger(name, detailProps = {}) {
2088
+ const e = new CustomEvent(name, {
2085
2089
  bubbles: true,
2086
- cancelable: true
2090
+ cancelable: true,
2091
+ detail: detailProps
2087
2092
  });
2088
2093
  this.telInput.dispatchEvent(e);
2089
2094
  }
@@ -2604,7 +2609,8 @@ var factoryOutput = (() => {
2604
2609
  handleAutoCountry() {
2605
2610
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2606
2611
  this.defaultCountry = intlTelInput.autoCountry;
2607
- if (!this.telInput.value) {
2612
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2613
+ if (!hasSelectedCountryOrGlobe) {
2608
2614
  this.setCountry(this.defaultCountry);
2609
2615
  }
2610
2616
  this.resolveAutoCountryPromise();
@@ -2733,7 +2739,7 @@ var factoryOutput = (() => {
2733
2739
  if (countryChanged) {
2734
2740
  this._triggerCountryChange();
2735
2741
  }
2736
- this._trigger("input");
2742
+ this._trigger("input", { isSetNumber: true });
2737
2743
  }
2738
2744
  //* Set the placeholder number typ
2739
2745
  setPlaceholderNumberType(type) {
@@ -2782,7 +2788,7 @@ var factoryOutput = (() => {
2782
2788
  //* A map from instance ID to instance object.
2783
2789
  instances: {},
2784
2790
  loadUtils,
2785
- version: "23.0.9"
2791
+ version: "23.0.11"
2786
2792
  }
2787
2793
  );
2788
2794
  var intl_tel_input_default = intlTelInput;