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.
@@ -1853,10 +1853,11 @@ var Iti = class {
1853
1853
  const val = useAttribute ? attributeValue : inputValue;
1854
1854
  const dialCode = this._getDialCode(val);
1855
1855
  const isRegionlessNanpNumber = isRegionlessNanp(val);
1856
- const { initialCountry } = this.options;
1856
+ const { initialCountry, geoIpLookup } = this.options;
1857
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1857
1858
  if (dialCode && !isRegionlessNanpNumber) {
1858
1859
  this._updateCountryFromNumber(val);
1859
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
1860
+ } else if (!isAutoCountry || overrideAutoCountry) {
1860
1861
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1861
1862
  const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1862
1863
  if (isValidInitialCountry) {
@@ -1935,18 +1936,20 @@ var Iti = class {
1935
1936
  }
1936
1937
  //* Init many requests: utils script / geo ip lookup.
1937
1938
  _initRequests() {
1938
- if (this.options.utilsScript && !intlTelInput.utils) {
1939
+ const { utilsScript, initialCountry, geoIpLookup } = this.options;
1940
+ if (utilsScript && !intlTelInput.utils) {
1939
1941
  if (intlTelInput.documentReady()) {
1940
- intlTelInput.loadUtils(this.options.utilsScript);
1942
+ intlTelInput.loadUtils(utilsScript);
1941
1943
  } else {
1942
1944
  window.addEventListener("load", () => {
1943
- intlTelInput.loadUtils(this.options.utilsScript);
1945
+ intlTelInput.loadUtils(utilsScript);
1944
1946
  });
1945
1947
  }
1946
1948
  } else {
1947
1949
  this.resolveUtilsScriptPromise();
1948
1950
  }
1949
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1951
+ const isAutoCountry = initialCountry === "auto" && geoIpLookup;
1952
+ if (isAutoCountry && !this.selectedCountryData.iso2) {
1950
1953
  this._loadAutoCountry();
1951
1954
  } else {
1952
1955
  this.resolveAutoCountryPromise();
@@ -1981,24 +1984,25 @@ var Iti = class {
1981
1984
  }
1982
1985
  //* Initialize the tel input listeners.
1983
1986
  _initTelInputListeners() {
1984
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
1987
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
1985
1988
  let userOverrideFormatting = false;
1986
1989
  this._handleInputEvent = (e) => {
1987
1990
  if (this._updateCountryFromNumber(this.telInput.value)) {
1988
1991
  this._triggerCountryChange();
1989
1992
  }
1990
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
1991
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
1993
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
1994
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
1992
1995
  if (isFormattingChar || isPaste && !strictMode) {
1993
1996
  userOverrideFormatting = true;
1994
1997
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
1995
1998
  userOverrideFormatting = false;
1996
1999
  }
1997
- if (formatAsYouType && !userOverrideFormatting) {
2000
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
2001
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
1998
2002
  const currentCaretPos = this.telInput.selectionStart || 0;
1999
2003
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2000
2004
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2001
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2005
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2002
2006
  const formattedValue = this._formatNumberAsYouType();
2003
2007
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2004
2008
  this.telInput.value = formattedValue;
@@ -2040,10 +2044,11 @@ var Iti = class {
2040
2044
  return max && number.length > max ? number.substr(0, max) : number;
2041
2045
  }
2042
2046
  //* Trigger a custom event on the input.
2043
- _trigger(name) {
2044
- const e = new Event(name, {
2047
+ _trigger(name, detailProps = {}) {
2048
+ const e = new CustomEvent(name, {
2045
2049
  bubbles: true,
2046
- cancelable: true
2050
+ cancelable: true,
2051
+ detail: detailProps
2047
2052
  });
2048
2053
  this.telInput.dispatchEvent(e);
2049
2054
  }
@@ -2564,7 +2569,8 @@ var Iti = class {
2564
2569
  handleAutoCountry() {
2565
2570
  if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
2566
2571
  this.defaultCountry = intlTelInput.autoCountry;
2567
- if (!this.telInput.value) {
2572
+ const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
2573
+ if (!hasSelectedCountryOrGlobe) {
2568
2574
  this.setCountry(this.defaultCountry);
2569
2575
  }
2570
2576
  this.resolveAutoCountryPromise();
@@ -2693,7 +2699,7 @@ var Iti = class {
2693
2699
  if (countryChanged) {
2694
2700
  this._triggerCountryChange();
2695
2701
  }
2696
- this._trigger("input");
2702
+ this._trigger("input", { isSetNumber: true });
2697
2703
  }
2698
2704
  //* Set the placeholder number typ
2699
2705
  setPlaceholderNumberType(type) {
@@ -2742,7 +2748,7 @@ var intlTelInput = Object.assign(
2742
2748
  //* A map from instance ID to instance object.
2743
2749
  instances: {},
2744
2750
  loadUtils,
2745
- version: "23.0.9"
2751
+ version: "23.0.11"
2746
2752
  }
2747
2753
  );
2748
2754
  var intl_tel_input_default = intlTelInput;
@@ -8946,7 +8952,7 @@ intl_tel_input_default.utils = utils_default;
8946
8952
  var intlTelInputWithUtils_default = intl_tel_input_default;
8947
8953
 
8948
8954
  // react/src/intl-tel-input/reactWithUtils.tsx
8949
- import React, { useRef, useEffect, forwardRef, useImperativeHandle } from "react";
8955
+ import React, { useRef, useEffect, forwardRef, useImperativeHandle, useCallback } from "react";
8950
8956
  var IntlTelInput = forwardRef(function IntlTelInput2({
8951
8957
  initialValue = "",
8952
8958
  onChangeNumber = () => {
@@ -8967,7 +8973,7 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
8967
8973
  getInstance: () => itiRef.current,
8968
8974
  getInput: () => inputRef.current
8969
8975
  }));
8970
- const update = () => {
8976
+ const update = useCallback(() => {
8971
8977
  const num = itiRef.current?.getNumber() || "";
8972
8978
  const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
8973
8979
  onChangeNumber(num);
@@ -8983,11 +8989,18 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
8983
8989
  onChangeErrorCode(errorCode);
8984
8990
  }
8985
8991
  }
8986
- };
8992
+ }, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
8993
+ useEffect(() => {
8994
+ if (inputRef.current) {
8995
+ itiRef.current = intlTelInputWithUtils_default(inputRef.current, initOptions);
8996
+ }
8997
+ return () => {
8998
+ itiRef.current?.destroy();
8999
+ };
9000
+ }, []);
8987
9001
  useEffect(() => {
8988
9002
  const inputRefCurrent = inputRef.current;
8989
9003
  if (inputRefCurrent) {
8990
- itiRef.current = intlTelInputWithUtils_default(inputRefCurrent, initOptions);
8991
9004
  inputRefCurrent.addEventListener("countrychange", update);
8992
9005
  itiRef.current.promise.then(update);
8993
9006
  }
@@ -8995,9 +9008,8 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
8995
9008
  if (inputRefCurrent) {
8996
9009
  inputRefCurrent.removeEventListener("countrychange", update);
8997
9010
  }
8998
- itiRef.current?.destroy();
8999
9011
  };
9000
- }, []);
9012
+ }, [update]);
9001
9013
  return /* @__PURE__ */ React.createElement(
9002
9014
  "input",
9003
9015
  {