intl-tel-input 23.0.8 → 23.0.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "23.0.8",
3
+ "version": "23.0.10",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
@@ -37,6 +37,7 @@
37
37
  "eslint-plugin-jasmine": "^4.1.3",
38
38
  "eslint-plugin-jest": "^28.5.0",
39
39
  "eslint-plugin-react": "^7.34.1",
40
+ "eslint-plugin-react-hooks": "^4.6.2",
40
41
  "evenizer": "^0.1.17",
41
42
  "google-closure-compiler": "^20240317.0.0",
42
43
  "google-closure-library": "^20230802.0.0",
@@ -83,7 +84,7 @@
83
84
  },
84
85
  "homepage": "https://intl-tel-input.com",
85
86
  "scripts": {
86
- "test": "grunt travis",
87
+ "test": "grunt travis && jest",
87
88
  "jest": "jest",
88
89
  "lint:js": "eslint .",
89
90
  "lint:spelling": "cspell --dot --gitignore --no-progress '**'",
@@ -123,6 +124,7 @@
123
124
  },
124
125
  "./i18n": "./build/js/i18n/index.js",
125
126
  "./i18n/*": "./build/js/i18n/*/index.js",
127
+ "./styles": "./build/css/intlTelInput.css",
126
128
  "./*": "./*"
127
129
  },
128
130
  "typesVersions": {
@@ -136,6 +138,9 @@
136
138
  }
137
139
  },
138
140
  "jest": {
139
- "moduleDirectories": ["node_modules", "build/js"]
141
+ "moduleDirectories": [
142
+ "node_modules",
143
+ "build/js"
144
+ ]
140
145
  }
141
146
  }
package/react/README.md CHANGED
@@ -1,5 +1,36 @@
1
- # Props
1
+ # IntlTelInput React Component
2
+ A React component wrapper for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the source [here](https://github.com/jackocnr/intl-tel-input/blob/master/react/src/intl-tel-input/react.tsx).
2
3
 
4
+ ## Table of Contents
5
+ - [Demo and Examples](#demo-and-examples)
6
+ - [Getting Started](#getting-started)
7
+ - [Props](#props)
8
+ - [Accessing Instance Methods](#accessing-instance-methods)
9
+ - [Troubleshooting](#troubleshooting)
10
+
11
+ ## Demo and Examples
12
+ Check out [Storybook](https://intl-tel-input.com/storybook) where you can play with the various options. Alternatively, try it for yourself by downloading the project and opening /react/demo/validation.html (etc) in a browser.
13
+
14
+ ## Getting Started
15
+ ```js
16
+ import IntlTelInput from "intl-tel-input/react";
17
+ import "intl-tel-input/styles";
18
+
19
+ <IntlTelInput
20
+ onChangeNumber={setNumber}
21
+ onChangeValidity={setIsValid}
22
+ initOptions={{
23
+ initialCountry: "us",
24
+ utilsScript: "path/to/utils.js",
25
+ }}
26
+ />
27
+ ```
28
+
29
+ See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/ValidationApp.tsx) for a more fleshed out example of how to handle validation.
30
+
31
+ A note on the utils script (~250kb): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import `"intl-tel-input/reactWithUtils"` to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option, and point that to your hosted [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file (or just point it to a CDN e.g. "https://cdn.jsdelivr.net/npm/intl-tel-input@23.0.9/build/js/utils.js").
32
+
33
+ ## Props
3
34
  Here's a list of all of the current props you can pass to the IntlTelInput react component.
4
35
 
5
36
  **initialValue**
@@ -33,3 +64,23 @@ An object containing all of the [initialisation options](https://github.com/jack
33
64
  **inputProps**
34
65
  Type: `Object`
35
66
  The props to pass to the input element e.g. `className`, `placeholder`, `required`, `disabled`, `onBlur` etc.
67
+
68
+ ## Accessing Instance Methods
69
+
70
+ You can access the instance methods (`setNumber`, `setCountry`, `setPlaceholderNumberType` etc) by passing a ref into the IntlTelInput component (using the `ref` prop), and then calling `ref.current.getInstance()` e.g. `ref.current.getInstance().setNumber(...);`. See the [Set Number demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/SetNumberApp.tsx) for a full example. You can also access the input DOM element in a similar way: `ref.current.getInput()`.
71
+
72
+ ## Troubleshooting
73
+
74
+ **Error when toggle presence of IntlTelInput component**
75
+
76
+ Error message: `Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`
77
+
78
+ Solution: wrap the component in a div e.g.
79
+
80
+ ```js
81
+ {showIntlTelInput && (
82
+ <div>
83
+ <IntlTelInput />
84
+ </div>
85
+ )}
86
+ ```
@@ -2017,24 +2017,25 @@ var Iti = class {
2017
2017
  }
2018
2018
  //* Initialize the tel input listeners.
2019
2019
  _initTelInputListeners() {
2020
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
2020
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
2021
2021
  let userOverrideFormatting = false;
2022
2022
  this._handleInputEvent = (e) => {
2023
2023
  if (this._updateCountryFromNumber(this.telInput.value)) {
2024
2024
  this._triggerCountryChange();
2025
2025
  }
2026
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
2027
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
2026
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
2027
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
2028
2028
  if (isFormattingChar || isPaste && !strictMode) {
2029
2029
  userOverrideFormatting = true;
2030
2030
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
2031
2031
  userOverrideFormatting = false;
2032
2032
  }
2033
- if (formatAsYouType && !userOverrideFormatting) {
2033
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
2034
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
2034
2035
  const currentCaretPos = this.telInput.selectionStart || 0;
2035
2036
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2036
2037
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2037
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2038
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2038
2039
  const formattedValue = this._formatNumberAsYouType();
2039
2040
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2040
2041
  this.telInput.value = formattedValue;
@@ -2076,10 +2077,11 @@ var Iti = class {
2076
2077
  return max && number.length > max ? number.substr(0, max) : number;
2077
2078
  }
2078
2079
  //* Trigger a custom event on the input.
2079
- _trigger(name) {
2080
- const e = new Event(name, {
2080
+ _trigger(name, detailProps = {}) {
2081
+ const e = new CustomEvent(name, {
2081
2082
  bubbles: true,
2082
- cancelable: true
2083
+ cancelable: true,
2084
+ detail: detailProps
2083
2085
  });
2084
2086
  this.telInput.dispatchEvent(e);
2085
2087
  }
@@ -2729,6 +2731,7 @@ var Iti = class {
2729
2731
  if (countryChanged) {
2730
2732
  this._triggerCountryChange();
2731
2733
  }
2734
+ this._trigger("input", { isSetNumber: true });
2732
2735
  }
2733
2736
  //* Set the placeholder number typ
2734
2737
  setPlaceholderNumberType(type) {
@@ -2777,7 +2780,7 @@ var intlTelInput = Object.assign(
2777
2780
  //* A map from instance ID to instance object.
2778
2781
  instances: {},
2779
2782
  loadUtils,
2780
- version: "23.0.8"
2783
+ version: "23.0.10"
2781
2784
  }
2782
2785
  );
2783
2786
  var intl_tel_input_default = intlTelInput;
@@ -2801,17 +2804,10 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
2801
2804
  const inputRef = (0, import_react.useRef)(null);
2802
2805
  const itiRef = (0, import_react.useRef)(null);
2803
2806
  (0, import_react.useImperativeHandle)(ref, () => ({
2804
- getInstance: () => ({
2805
- setCountry: (country) => itiRef.current?.setCountry(country),
2806
- // override setNumber to also call update, to trigger onChangeNumber etc
2807
- setNumber: (num) => {
2808
- itiRef.current?.setNumber(num);
2809
- update();
2810
- }
2811
- }),
2807
+ getInstance: () => itiRef.current,
2812
2808
  getInput: () => inputRef.current
2813
2809
  }));
2814
- const update = () => {
2810
+ const update = (0, import_react.useCallback)(() => {
2815
2811
  const num = itiRef.current?.getNumber() || "";
2816
2812
  const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
2817
2813
  onChangeNumber(num);
@@ -2827,11 +2823,18 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
2827
2823
  onChangeErrorCode(errorCode);
2828
2824
  }
2829
2825
  }
2830
- };
2826
+ }, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
2827
+ (0, import_react.useEffect)(() => {
2828
+ if (inputRef.current) {
2829
+ itiRef.current = intl_tel_input_default(inputRef.current, initOptions);
2830
+ }
2831
+ return () => {
2832
+ itiRef.current?.destroy();
2833
+ };
2834
+ }, []);
2831
2835
  (0, import_react.useEffect)(() => {
2832
2836
  const inputRefCurrent = inputRef.current;
2833
2837
  if (inputRefCurrent) {
2834
- itiRef.current = intl_tel_input_default(inputRefCurrent, initOptions);
2835
2838
  inputRefCurrent.addEventListener("countrychange", update);
2836
2839
  itiRef.current.promise.then(update);
2837
2840
  }
@@ -2839,9 +2842,8 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
2839
2842
  if (inputRefCurrent) {
2840
2843
  inputRefCurrent.removeEventListener("countrychange", update);
2841
2844
  }
2842
- itiRef.current?.destroy();
2843
2845
  };
2844
- }, []);
2846
+ }, [update]);
2845
2847
  return /* @__PURE__ */ import_react.default.createElement(
2846
2848
  "input",
2847
2849
  {
@@ -1981,24 +1981,25 @@ var Iti = class {
1981
1981
  }
1982
1982
  //* Initialize the tel input listeners.
1983
1983
  _initTelInputListeners() {
1984
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
1984
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
1985
1985
  let userOverrideFormatting = false;
1986
1986
  this._handleInputEvent = (e) => {
1987
1987
  if (this._updateCountryFromNumber(this.telInput.value)) {
1988
1988
  this._triggerCountryChange();
1989
1989
  }
1990
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
1991
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
1990
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
1991
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
1992
1992
  if (isFormattingChar || isPaste && !strictMode) {
1993
1993
  userOverrideFormatting = true;
1994
1994
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
1995
1995
  userOverrideFormatting = false;
1996
1996
  }
1997
- if (formatAsYouType && !userOverrideFormatting) {
1997
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
1998
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
1998
1999
  const currentCaretPos = this.telInput.selectionStart || 0;
1999
2000
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2000
2001
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2001
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2002
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2002
2003
  const formattedValue = this._formatNumberAsYouType();
2003
2004
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2004
2005
  this.telInput.value = formattedValue;
@@ -2040,10 +2041,11 @@ var Iti = class {
2040
2041
  return max && number.length > max ? number.substr(0, max) : number;
2041
2042
  }
2042
2043
  //* Trigger a custom event on the input.
2043
- _trigger(name) {
2044
- const e = new Event(name, {
2044
+ _trigger(name, detailProps = {}) {
2045
+ const e = new CustomEvent(name, {
2045
2046
  bubbles: true,
2046
- cancelable: true
2047
+ cancelable: true,
2048
+ detail: detailProps
2047
2049
  });
2048
2050
  this.telInput.dispatchEvent(e);
2049
2051
  }
@@ -2693,6 +2695,7 @@ var Iti = class {
2693
2695
  if (countryChanged) {
2694
2696
  this._triggerCountryChange();
2695
2697
  }
2698
+ this._trigger("input", { isSetNumber: true });
2696
2699
  }
2697
2700
  //* Set the placeholder number typ
2698
2701
  setPlaceholderNumberType(type) {
@@ -2741,13 +2744,13 @@ var intlTelInput = Object.assign(
2741
2744
  //* A map from instance ID to instance object.
2742
2745
  instances: {},
2743
2746
  loadUtils,
2744
- version: "23.0.8"
2747
+ version: "23.0.10"
2745
2748
  }
2746
2749
  );
2747
2750
  var intl_tel_input_default = intlTelInput;
2748
2751
 
2749
2752
  // react/src/intl-tel-input/react.tsx
2750
- import React, { useRef, useEffect, forwardRef, useImperativeHandle } from "react";
2753
+ import React, { useRef, useEffect, forwardRef, useImperativeHandle, useCallback } from "react";
2751
2754
  var IntlTelInput = forwardRef(function IntlTelInput2({
2752
2755
  initialValue = "",
2753
2756
  onChangeNumber = () => {
@@ -2765,17 +2768,10 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
2765
2768
  const inputRef = useRef(null);
2766
2769
  const itiRef = useRef(null);
2767
2770
  useImperativeHandle(ref, () => ({
2768
- getInstance: () => ({
2769
- setCountry: (country) => itiRef.current?.setCountry(country),
2770
- // override setNumber to also call update, to trigger onChangeNumber etc
2771
- setNumber: (num) => {
2772
- itiRef.current?.setNumber(num);
2773
- update();
2774
- }
2775
- }),
2771
+ getInstance: () => itiRef.current,
2776
2772
  getInput: () => inputRef.current
2777
2773
  }));
2778
- const update = () => {
2774
+ const update = useCallback(() => {
2779
2775
  const num = itiRef.current?.getNumber() || "";
2780
2776
  const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
2781
2777
  onChangeNumber(num);
@@ -2791,11 +2787,18 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
2791
2787
  onChangeErrorCode(errorCode);
2792
2788
  }
2793
2789
  }
2794
- };
2790
+ }, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
2791
+ useEffect(() => {
2792
+ if (inputRef.current) {
2793
+ itiRef.current = intl_tel_input_default(inputRef.current, initOptions);
2794
+ }
2795
+ return () => {
2796
+ itiRef.current?.destroy();
2797
+ };
2798
+ }, []);
2795
2799
  useEffect(() => {
2796
2800
  const inputRefCurrent = inputRef.current;
2797
2801
  if (inputRefCurrent) {
2798
- itiRef.current = intl_tel_input_default(inputRefCurrent, initOptions);
2799
2802
  inputRefCurrent.addEventListener("countrychange", update);
2800
2803
  itiRef.current.promise.then(update);
2801
2804
  }
@@ -2803,9 +2806,8 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
2803
2806
  if (inputRefCurrent) {
2804
2807
  inputRefCurrent.removeEventListener("countrychange", update);
2805
2808
  }
2806
- itiRef.current?.destroy();
2807
2809
  };
2808
- }, []);
2810
+ }, [update]);
2809
2811
  return /* @__PURE__ */ React.createElement(
2810
2812
  "input",
2811
2813
  {
@@ -2017,24 +2017,25 @@ var Iti = class {
2017
2017
  }
2018
2018
  //* Initialize the tel input listeners.
2019
2019
  _initTelInputListeners() {
2020
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
2020
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
2021
2021
  let userOverrideFormatting = false;
2022
2022
  this._handleInputEvent = (e) => {
2023
2023
  if (this._updateCountryFromNumber(this.telInput.value)) {
2024
2024
  this._triggerCountryChange();
2025
2025
  }
2026
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
2027
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
2026
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
2027
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
2028
2028
  if (isFormattingChar || isPaste && !strictMode) {
2029
2029
  userOverrideFormatting = true;
2030
2030
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
2031
2031
  userOverrideFormatting = false;
2032
2032
  }
2033
- if (formatAsYouType && !userOverrideFormatting) {
2033
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
2034
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
2034
2035
  const currentCaretPos = this.telInput.selectionStart || 0;
2035
2036
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2036
2037
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2037
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2038
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2038
2039
  const formattedValue = this._formatNumberAsYouType();
2039
2040
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2040
2041
  this.telInput.value = formattedValue;
@@ -2076,10 +2077,11 @@ var Iti = class {
2076
2077
  return max && number.length > max ? number.substr(0, max) : number;
2077
2078
  }
2078
2079
  //* Trigger a custom event on the input.
2079
- _trigger(name) {
2080
- const e = new Event(name, {
2080
+ _trigger(name, detailProps = {}) {
2081
+ const e = new CustomEvent(name, {
2081
2082
  bubbles: true,
2082
- cancelable: true
2083
+ cancelable: true,
2084
+ detail: detailProps
2083
2085
  });
2084
2086
  this.telInput.dispatchEvent(e);
2085
2087
  }
@@ -2729,6 +2731,7 @@ var Iti = class {
2729
2731
  if (countryChanged) {
2730
2732
  this._triggerCountryChange();
2731
2733
  }
2734
+ this._trigger("input", { isSetNumber: true });
2732
2735
  }
2733
2736
  //* Set the placeholder number typ
2734
2737
  setPlaceholderNumberType(type) {
@@ -2777,7 +2780,7 @@ var intlTelInput = Object.assign(
2777
2780
  //* A map from instance ID to instance object.
2778
2781
  instances: {},
2779
2782
  loadUtils,
2780
- version: "23.0.8"
2783
+ version: "23.0.10"
2781
2784
  }
2782
2785
  );
2783
2786
  var intl_tel_input_default = intlTelInput;
@@ -8999,17 +9002,10 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
8999
9002
  const inputRef = (0, import_react.useRef)(null);
9000
9003
  const itiRef = (0, import_react.useRef)(null);
9001
9004
  (0, import_react.useImperativeHandle)(ref, () => ({
9002
- getInstance: () => ({
9003
- setCountry: (country) => itiRef.current?.setCountry(country),
9004
- // override setNumber to also call update, to trigger onChangeNumber etc
9005
- setNumber: (num) => {
9006
- itiRef.current?.setNumber(num);
9007
- update();
9008
- }
9009
- }),
9005
+ getInstance: () => itiRef.current,
9010
9006
  getInput: () => inputRef.current
9011
9007
  }));
9012
- const update = () => {
9008
+ const update = (0, import_react.useCallback)(() => {
9013
9009
  const num = itiRef.current?.getNumber() || "";
9014
9010
  const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
9015
9011
  onChangeNumber(num);
@@ -9025,11 +9021,18 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
9025
9021
  onChangeErrorCode(errorCode);
9026
9022
  }
9027
9023
  }
9028
- };
9024
+ }, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
9025
+ (0, import_react.useEffect)(() => {
9026
+ if (inputRef.current) {
9027
+ itiRef.current = intlTelInputWithUtils_default(inputRef.current, initOptions);
9028
+ }
9029
+ return () => {
9030
+ itiRef.current?.destroy();
9031
+ };
9032
+ }, []);
9029
9033
  (0, import_react.useEffect)(() => {
9030
9034
  const inputRefCurrent = inputRef.current;
9031
9035
  if (inputRefCurrent) {
9032
- itiRef.current = intlTelInputWithUtils_default(inputRefCurrent, initOptions);
9033
9036
  inputRefCurrent.addEventListener("countrychange", update);
9034
9037
  itiRef.current.promise.then(update);
9035
9038
  }
@@ -9037,9 +9040,8 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
9037
9040
  if (inputRefCurrent) {
9038
9041
  inputRefCurrent.removeEventListener("countrychange", update);
9039
9042
  }
9040
- itiRef.current?.destroy();
9041
9043
  };
9042
- }, []);
9044
+ }, [update]);
9043
9045
  return /* @__PURE__ */ import_react.default.createElement(
9044
9046
  "input",
9045
9047
  {
@@ -1981,24 +1981,25 @@ var Iti = class {
1981
1981
  }
1982
1982
  //* Initialize the tel input listeners.
1983
1983
  _initTelInputListeners() {
1984
- const { strictMode, formatAsYouType, separateDialCode } = this.options;
1984
+ const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
1985
1985
  let userOverrideFormatting = false;
1986
1986
  this._handleInputEvent = (e) => {
1987
1987
  if (this._updateCountryFromNumber(this.telInput.value)) {
1988
1988
  this._triggerCountryChange();
1989
1989
  }
1990
- const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
1991
- const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
1990
+ const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
1991
+ const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
1992
1992
  if (isFormattingChar || isPaste && !strictMode) {
1993
1993
  userOverrideFormatting = true;
1994
1994
  } else if (!/[^+0-9]/.test(this.telInput.value)) {
1995
1995
  userOverrideFormatting = false;
1996
1996
  }
1997
- if (formatAsYouType && !userOverrideFormatting) {
1997
+ const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
1998
+ if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
1998
1999
  const currentCaretPos = this.telInput.selectionStart || 0;
1999
2000
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2000
2001
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2001
- const isDeleteForwards = e && e.inputType === "deleteContentForward";
2002
+ const isDeleteForwards = e?.inputType === "deleteContentForward";
2002
2003
  const formattedValue = this._formatNumberAsYouType();
2003
2004
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2004
2005
  this.telInput.value = formattedValue;
@@ -2040,10 +2041,11 @@ var Iti = class {
2040
2041
  return max && number.length > max ? number.substr(0, max) : number;
2041
2042
  }
2042
2043
  //* Trigger a custom event on the input.
2043
- _trigger(name) {
2044
- const e = new Event(name, {
2044
+ _trigger(name, detailProps = {}) {
2045
+ const e = new CustomEvent(name, {
2045
2046
  bubbles: true,
2046
- cancelable: true
2047
+ cancelable: true,
2048
+ detail: detailProps
2047
2049
  });
2048
2050
  this.telInput.dispatchEvent(e);
2049
2051
  }
@@ -2693,6 +2695,7 @@ var Iti = class {
2693
2695
  if (countryChanged) {
2694
2696
  this._triggerCountryChange();
2695
2697
  }
2698
+ this._trigger("input", { isSetNumber: true });
2696
2699
  }
2697
2700
  //* Set the placeholder number typ
2698
2701
  setPlaceholderNumberType(type) {
@@ -2741,7 +2744,7 @@ var intlTelInput = Object.assign(
2741
2744
  //* A map from instance ID to instance object.
2742
2745
  instances: {},
2743
2746
  loadUtils,
2744
- version: "23.0.8"
2747
+ version: "23.0.10"
2745
2748
  }
2746
2749
  );
2747
2750
  var intl_tel_input_default = intlTelInput;
@@ -8945,7 +8948,7 @@ intl_tel_input_default.utils = utils_default;
8945
8948
  var intlTelInputWithUtils_default = intl_tel_input_default;
8946
8949
 
8947
8950
  // react/src/intl-tel-input/reactWithUtils.tsx
8948
- import React, { useRef, useEffect, forwardRef, useImperativeHandle } from "react";
8951
+ import React, { useRef, useEffect, forwardRef, useImperativeHandle, useCallback } from "react";
8949
8952
  var IntlTelInput = forwardRef(function IntlTelInput2({
8950
8953
  initialValue = "",
8951
8954
  onChangeNumber = () => {
@@ -8963,17 +8966,10 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
8963
8966
  const inputRef = useRef(null);
8964
8967
  const itiRef = useRef(null);
8965
8968
  useImperativeHandle(ref, () => ({
8966
- getInstance: () => ({
8967
- setCountry: (country) => itiRef.current?.setCountry(country),
8968
- // override setNumber to also call update, to trigger onChangeNumber etc
8969
- setNumber: (num) => {
8970
- itiRef.current?.setNumber(num);
8971
- update();
8972
- }
8973
- }),
8969
+ getInstance: () => itiRef.current,
8974
8970
  getInput: () => inputRef.current
8975
8971
  }));
8976
- const update = () => {
8972
+ const update = useCallback(() => {
8977
8973
  const num = itiRef.current?.getNumber() || "";
8978
8974
  const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
8979
8975
  onChangeNumber(num);
@@ -8989,11 +8985,18 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
8989
8985
  onChangeErrorCode(errorCode);
8990
8986
  }
8991
8987
  }
8992
- };
8988
+ }, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
8989
+ useEffect(() => {
8990
+ if (inputRef.current) {
8991
+ itiRef.current = intlTelInputWithUtils_default(inputRef.current, initOptions);
8992
+ }
8993
+ return () => {
8994
+ itiRef.current?.destroy();
8995
+ };
8996
+ }, []);
8993
8997
  useEffect(() => {
8994
8998
  const inputRefCurrent = inputRef.current;
8995
8999
  if (inputRefCurrent) {
8996
- itiRef.current = intlTelInputWithUtils_default(inputRefCurrent, initOptions);
8997
9000
  inputRefCurrent.addEventListener("countrychange", update);
8998
9001
  itiRef.current.promise.then(update);
8999
9002
  }
@@ -9001,9 +9004,8 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
9001
9004
  if (inputRefCurrent) {
9002
9005
  inputRefCurrent.removeEventListener("countrychange", update);
9003
9006
  }
9004
- itiRef.current?.destroy();
9005
9007
  };
9006
- }, []);
9008
+ }, [update]);
9007
9009
  return /* @__PURE__ */ React.createElement(
9008
9010
  "input",
9009
9011
  {