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.
- package/README.md +33 -23
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.js +24 -18
- package/build/js/intlTelInput.min.js +2 -2
- package/build/js/intlTelInputWithUtils.js +24 -18
- package/build/js/intlTelInputWithUtils.min.js +2 -2
- package/package.json +7 -2
- package/react/README.md +57 -1
- package/react/build/IntlTelInput.cjs +34 -22
- package/react/build/IntlTelInput.js +35 -23
- package/react/build/IntlTelInputWithUtils.cjs +34 -22
- package/react/build/IntlTelInputWithUtils.js +35 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-tel-input",
|
|
3
|
-
"version": "23.0.
|
|
3
|
+
"version": "23.0.11",
|
|
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",
|
|
@@ -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": [
|
|
141
|
+
"moduleDirectories": [
|
|
142
|
+
"node_modules",
|
|
143
|
+
"build/js"
|
|
144
|
+
]
|
|
140
145
|
}
|
|
141
146
|
}
|
package/react/README.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
#
|
|
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 code [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
|
+
- [Accessing Static Methods](#accessing-static-methods)
|
|
10
|
+
- [Troubleshooting](#troubleshooting)
|
|
11
|
+
|
|
12
|
+
## Demo and Examples
|
|
13
|
+
Check out [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--vanilla) where you can play with the various props. Alternatively, try it for yourself by downloading the project and opening /react/demo/validation.html (etc) in a browser.
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
```js
|
|
17
|
+
import IntlTelInput from "intl-tel-input/react";
|
|
18
|
+
import "intl-tel-input/styles";
|
|
19
|
+
|
|
20
|
+
<IntlTelInput
|
|
21
|
+
onChangeNumber={setNumber}
|
|
22
|
+
onChangeValidity={setIsValid}
|
|
23
|
+
initOptions={{
|
|
24
|
+
initialCountry: "us",
|
|
25
|
+
utilsScript: "path/to/utils.js",
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"` instead, 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 - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@23.0.11/build/js/utils.js"`.
|
|
33
|
+
|
|
34
|
+
## Props
|
|
3
35
|
Here's a list of all of the current props you can pass to the IntlTelInput react component.
|
|
4
36
|
|
|
5
37
|
**initialValue**
|
|
@@ -33,3 +65,27 @@ An object containing all of the [initialisation options](https://github.com/jack
|
|
|
33
65
|
**inputProps**
|
|
34
66
|
Type: `Object`
|
|
35
67
|
The props to pass to the input element e.g. `className`, `placeholder`, `required`, `disabled`, `onBlur` etc.
|
|
68
|
+
|
|
69
|
+
## Accessing Instance Methods
|
|
70
|
+
|
|
71
|
+
You can access all of the plugin's [instance methods](https://github.com/jackocnr/intl-tel-input/blob/master/README.md#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()`.
|
|
72
|
+
|
|
73
|
+
## Accessing Static Methods
|
|
74
|
+
|
|
75
|
+
You can access all of the plugin's [static methods](https://github.com/jackocnr/intl-tel-input/blob/master/README.md#static-methods) by importing `intlTelInput` from the same file as the react component e.g. `import { intlTelInput } from "intl-tel-input/react"` (note the lower case "i" in "intlTelInput"). You can then use this as you would with the main plugin e.g. `intlTelInput.getCountryData()` or `intlTelInput.utils.numberType` etc.
|
|
76
|
+
|
|
77
|
+
## Troubleshooting
|
|
78
|
+
|
|
79
|
+
**Error when toggle presence of IntlTelInput component**
|
|
80
|
+
|
|
81
|
+
Error message: `Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`
|
|
82
|
+
|
|
83
|
+
Solution: wrap the component in a div e.g.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
{showIntlTelInput && (
|
|
87
|
+
<div>
|
|
88
|
+
<IntlTelInput />
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
```
|
|
@@ -1889,10 +1889,11 @@ var Iti = class {
|
|
|
1889
1889
|
const val = useAttribute ? attributeValue : inputValue;
|
|
1890
1890
|
const dialCode = this._getDialCode(val);
|
|
1891
1891
|
const isRegionlessNanpNumber = isRegionlessNanp(val);
|
|
1892
|
-
const { initialCountry } = this.options;
|
|
1892
|
+
const { initialCountry, geoIpLookup } = this.options;
|
|
1893
|
+
const isAutoCountry = initialCountry === "auto" && geoIpLookup;
|
|
1893
1894
|
if (dialCode && !isRegionlessNanpNumber) {
|
|
1894
1895
|
this._updateCountryFromNumber(val);
|
|
1895
|
-
} else if (
|
|
1896
|
+
} else if (!isAutoCountry || overrideAutoCountry) {
|
|
1896
1897
|
const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
|
|
1897
1898
|
const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
|
|
1898
1899
|
if (isValidInitialCountry) {
|
|
@@ -1971,18 +1972,20 @@ var Iti = class {
|
|
|
1971
1972
|
}
|
|
1972
1973
|
//* Init many requests: utils script / geo ip lookup.
|
|
1973
1974
|
_initRequests() {
|
|
1974
|
-
|
|
1975
|
+
const { utilsScript, initialCountry, geoIpLookup } = this.options;
|
|
1976
|
+
if (utilsScript && !intlTelInput.utils) {
|
|
1975
1977
|
if (intlTelInput.documentReady()) {
|
|
1976
|
-
intlTelInput.loadUtils(
|
|
1978
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1977
1979
|
} else {
|
|
1978
1980
|
window.addEventListener("load", () => {
|
|
1979
|
-
intlTelInput.loadUtils(
|
|
1981
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1980
1982
|
});
|
|
1981
1983
|
}
|
|
1982
1984
|
} else {
|
|
1983
1985
|
this.resolveUtilsScriptPromise();
|
|
1984
1986
|
}
|
|
1985
|
-
|
|
1987
|
+
const isAutoCountry = initialCountry === "auto" && geoIpLookup;
|
|
1988
|
+
if (isAutoCountry && !this.selectedCountryData.iso2) {
|
|
1986
1989
|
this._loadAutoCountry();
|
|
1987
1990
|
} else {
|
|
1988
1991
|
this.resolveAutoCountryPromise();
|
|
@@ -2017,24 +2020,25 @@ var Iti = class {
|
|
|
2017
2020
|
}
|
|
2018
2021
|
//* Initialize the tel input listeners.
|
|
2019
2022
|
_initTelInputListeners() {
|
|
2020
|
-
const { strictMode, formatAsYouType, separateDialCode } = this.options;
|
|
2023
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2021
2024
|
let userOverrideFormatting = false;
|
|
2022
2025
|
this._handleInputEvent = (e) => {
|
|
2023
2026
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
2024
2027
|
this._triggerCountryChange();
|
|
2025
2028
|
}
|
|
2026
|
-
const isFormattingChar = e
|
|
2027
|
-
const isPaste = e
|
|
2029
|
+
const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
|
|
2030
|
+
const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
|
|
2028
2031
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
2029
2032
|
userOverrideFormatting = true;
|
|
2030
2033
|
} else if (!/[^+0-9]/.test(this.telInput.value)) {
|
|
2031
2034
|
userOverrideFormatting = false;
|
|
2032
2035
|
}
|
|
2033
|
-
|
|
2036
|
+
const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
|
|
2037
|
+
if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
|
|
2034
2038
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2035
2039
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
|
|
2036
2040
|
const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
|
|
2037
|
-
const isDeleteForwards = e
|
|
2041
|
+
const isDeleteForwards = e?.inputType === "deleteContentForward";
|
|
2038
2042
|
const formattedValue = this._formatNumberAsYouType();
|
|
2039
2043
|
const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
|
|
2040
2044
|
this.telInput.value = formattedValue;
|
|
@@ -2076,10 +2080,11 @@ var Iti = class {
|
|
|
2076
2080
|
return max && number.length > max ? number.substr(0, max) : number;
|
|
2077
2081
|
}
|
|
2078
2082
|
//* Trigger a custom event on the input.
|
|
2079
|
-
_trigger(name) {
|
|
2080
|
-
const e = new
|
|
2083
|
+
_trigger(name, detailProps = {}) {
|
|
2084
|
+
const e = new CustomEvent(name, {
|
|
2081
2085
|
bubbles: true,
|
|
2082
|
-
cancelable: true
|
|
2086
|
+
cancelable: true,
|
|
2087
|
+
detail: detailProps
|
|
2083
2088
|
});
|
|
2084
2089
|
this.telInput.dispatchEvent(e);
|
|
2085
2090
|
}
|
|
@@ -2600,7 +2605,8 @@ var Iti = class {
|
|
|
2600
2605
|
handleAutoCountry() {
|
|
2601
2606
|
if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
|
|
2602
2607
|
this.defaultCountry = intlTelInput.autoCountry;
|
|
2603
|
-
|
|
2608
|
+
const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
|
|
2609
|
+
if (!hasSelectedCountryOrGlobe) {
|
|
2604
2610
|
this.setCountry(this.defaultCountry);
|
|
2605
2611
|
}
|
|
2606
2612
|
this.resolveAutoCountryPromise();
|
|
@@ -2729,7 +2735,7 @@ var Iti = class {
|
|
|
2729
2735
|
if (countryChanged) {
|
|
2730
2736
|
this._triggerCountryChange();
|
|
2731
2737
|
}
|
|
2732
|
-
this._trigger("input");
|
|
2738
|
+
this._trigger("input", { isSetNumber: true });
|
|
2733
2739
|
}
|
|
2734
2740
|
//* Set the placeholder number typ
|
|
2735
2741
|
setPlaceholderNumberType(type) {
|
|
@@ -2778,7 +2784,7 @@ var intlTelInput = Object.assign(
|
|
|
2778
2784
|
//* A map from instance ID to instance object.
|
|
2779
2785
|
instances: {},
|
|
2780
2786
|
loadUtils,
|
|
2781
|
-
version: "23.0.
|
|
2787
|
+
version: "23.0.11"
|
|
2782
2788
|
}
|
|
2783
2789
|
);
|
|
2784
2790
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -2805,7 +2811,7 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
2805
2811
|
getInstance: () => itiRef.current,
|
|
2806
2812
|
getInput: () => inputRef.current
|
|
2807
2813
|
}));
|
|
2808
|
-
const update = () => {
|
|
2814
|
+
const update = (0, import_react.useCallback)(() => {
|
|
2809
2815
|
const num = itiRef.current?.getNumber() || "";
|
|
2810
2816
|
const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
|
|
2811
2817
|
onChangeNumber(num);
|
|
@@ -2821,11 +2827,18 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
2821
2827
|
onChangeErrorCode(errorCode);
|
|
2822
2828
|
}
|
|
2823
2829
|
}
|
|
2824
|
-
};
|
|
2830
|
+
}, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
|
|
2831
|
+
(0, import_react.useEffect)(() => {
|
|
2832
|
+
if (inputRef.current) {
|
|
2833
|
+
itiRef.current = intl_tel_input_default(inputRef.current, initOptions);
|
|
2834
|
+
}
|
|
2835
|
+
return () => {
|
|
2836
|
+
itiRef.current?.destroy();
|
|
2837
|
+
};
|
|
2838
|
+
}, []);
|
|
2825
2839
|
(0, import_react.useEffect)(() => {
|
|
2826
2840
|
const inputRefCurrent = inputRef.current;
|
|
2827
2841
|
if (inputRefCurrent) {
|
|
2828
|
-
itiRef.current = intl_tel_input_default(inputRefCurrent, initOptions);
|
|
2829
2842
|
inputRefCurrent.addEventListener("countrychange", update);
|
|
2830
2843
|
itiRef.current.promise.then(update);
|
|
2831
2844
|
}
|
|
@@ -2833,9 +2846,8 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
2833
2846
|
if (inputRefCurrent) {
|
|
2834
2847
|
inputRefCurrent.removeEventListener("countrychange", update);
|
|
2835
2848
|
}
|
|
2836
|
-
itiRef.current?.destroy();
|
|
2837
2849
|
};
|
|
2838
|
-
}, []);
|
|
2850
|
+
}, [update]);
|
|
2839
2851
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
2840
2852
|
"input",
|
|
2841
2853
|
{
|
|
@@ -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 (
|
|
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
|
-
|
|
1939
|
+
const { utilsScript, initialCountry, geoIpLookup } = this.options;
|
|
1940
|
+
if (utilsScript && !intlTelInput.utils) {
|
|
1939
1941
|
if (intlTelInput.documentReady()) {
|
|
1940
|
-
intlTelInput.loadUtils(
|
|
1942
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1941
1943
|
} else {
|
|
1942
1944
|
window.addEventListener("load", () => {
|
|
1943
|
-
intlTelInput.loadUtils(
|
|
1945
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1944
1946
|
});
|
|
1945
1947
|
}
|
|
1946
1948
|
} else {
|
|
1947
1949
|
this.resolveUtilsScriptPromise();
|
|
1948
1950
|
}
|
|
1949
|
-
|
|
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
|
|
1991
|
-
const isPaste = e
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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,13 +2748,13 @@ var intlTelInput = Object.assign(
|
|
|
2742
2748
|
//* A map from instance ID to instance object.
|
|
2743
2749
|
instances: {},
|
|
2744
2750
|
loadUtils,
|
|
2745
|
-
version: "23.0.
|
|
2751
|
+
version: "23.0.11"
|
|
2746
2752
|
}
|
|
2747
2753
|
);
|
|
2748
2754
|
var intl_tel_input_default = intlTelInput;
|
|
2749
2755
|
|
|
2750
2756
|
// react/src/intl-tel-input/react.tsx
|
|
2751
|
-
import React, { useRef, useEffect, forwardRef, useImperativeHandle } from "react";
|
|
2757
|
+
import React, { useRef, useEffect, forwardRef, useImperativeHandle, useCallback } from "react";
|
|
2752
2758
|
var IntlTelInput = forwardRef(function IntlTelInput2({
|
|
2753
2759
|
initialValue = "",
|
|
2754
2760
|
onChangeNumber = () => {
|
|
@@ -2769,7 +2775,7 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
|
|
|
2769
2775
|
getInstance: () => itiRef.current,
|
|
2770
2776
|
getInput: () => inputRef.current
|
|
2771
2777
|
}));
|
|
2772
|
-
const update = () => {
|
|
2778
|
+
const update = useCallback(() => {
|
|
2773
2779
|
const num = itiRef.current?.getNumber() || "";
|
|
2774
2780
|
const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
|
|
2775
2781
|
onChangeNumber(num);
|
|
@@ -2785,11 +2791,18 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
|
|
|
2785
2791
|
onChangeErrorCode(errorCode);
|
|
2786
2792
|
}
|
|
2787
2793
|
}
|
|
2788
|
-
};
|
|
2794
|
+
}, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
|
|
2795
|
+
useEffect(() => {
|
|
2796
|
+
if (inputRef.current) {
|
|
2797
|
+
itiRef.current = intl_tel_input_default(inputRef.current, initOptions);
|
|
2798
|
+
}
|
|
2799
|
+
return () => {
|
|
2800
|
+
itiRef.current?.destroy();
|
|
2801
|
+
};
|
|
2802
|
+
}, []);
|
|
2789
2803
|
useEffect(() => {
|
|
2790
2804
|
const inputRefCurrent = inputRef.current;
|
|
2791
2805
|
if (inputRefCurrent) {
|
|
2792
|
-
itiRef.current = intl_tel_input_default(inputRefCurrent, initOptions);
|
|
2793
2806
|
inputRefCurrent.addEventListener("countrychange", update);
|
|
2794
2807
|
itiRef.current.promise.then(update);
|
|
2795
2808
|
}
|
|
@@ -2797,9 +2810,8 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
|
|
|
2797
2810
|
if (inputRefCurrent) {
|
|
2798
2811
|
inputRefCurrent.removeEventListener("countrychange", update);
|
|
2799
2812
|
}
|
|
2800
|
-
itiRef.current?.destroy();
|
|
2801
2813
|
};
|
|
2802
|
-
}, []);
|
|
2814
|
+
}, [update]);
|
|
2803
2815
|
return /* @__PURE__ */ React.createElement(
|
|
2804
2816
|
"input",
|
|
2805
2817
|
{
|
|
@@ -1889,10 +1889,11 @@ var Iti = class {
|
|
|
1889
1889
|
const val = useAttribute ? attributeValue : inputValue;
|
|
1890
1890
|
const dialCode = this._getDialCode(val);
|
|
1891
1891
|
const isRegionlessNanpNumber = isRegionlessNanp(val);
|
|
1892
|
-
const { initialCountry } = this.options;
|
|
1892
|
+
const { initialCountry, geoIpLookup } = this.options;
|
|
1893
|
+
const isAutoCountry = initialCountry === "auto" && geoIpLookup;
|
|
1893
1894
|
if (dialCode && !isRegionlessNanpNumber) {
|
|
1894
1895
|
this._updateCountryFromNumber(val);
|
|
1895
|
-
} else if (
|
|
1896
|
+
} else if (!isAutoCountry || overrideAutoCountry) {
|
|
1896
1897
|
const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
|
|
1897
1898
|
const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
|
|
1898
1899
|
if (isValidInitialCountry) {
|
|
@@ -1971,18 +1972,20 @@ var Iti = class {
|
|
|
1971
1972
|
}
|
|
1972
1973
|
//* Init many requests: utils script / geo ip lookup.
|
|
1973
1974
|
_initRequests() {
|
|
1974
|
-
|
|
1975
|
+
const { utilsScript, initialCountry, geoIpLookup } = this.options;
|
|
1976
|
+
if (utilsScript && !intlTelInput.utils) {
|
|
1975
1977
|
if (intlTelInput.documentReady()) {
|
|
1976
|
-
intlTelInput.loadUtils(
|
|
1978
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1977
1979
|
} else {
|
|
1978
1980
|
window.addEventListener("load", () => {
|
|
1979
|
-
intlTelInput.loadUtils(
|
|
1981
|
+
intlTelInput.loadUtils(utilsScript);
|
|
1980
1982
|
});
|
|
1981
1983
|
}
|
|
1982
1984
|
} else {
|
|
1983
1985
|
this.resolveUtilsScriptPromise();
|
|
1984
1986
|
}
|
|
1985
|
-
|
|
1987
|
+
const isAutoCountry = initialCountry === "auto" && geoIpLookup;
|
|
1988
|
+
if (isAutoCountry && !this.selectedCountryData.iso2) {
|
|
1986
1989
|
this._loadAutoCountry();
|
|
1987
1990
|
} else {
|
|
1988
1991
|
this.resolveAutoCountryPromise();
|
|
@@ -2017,24 +2020,25 @@ var Iti = class {
|
|
|
2017
2020
|
}
|
|
2018
2021
|
//* Initialize the tel input listeners.
|
|
2019
2022
|
_initTelInputListeners() {
|
|
2020
|
-
const { strictMode, formatAsYouType, separateDialCode } = this.options;
|
|
2023
|
+
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
2021
2024
|
let userOverrideFormatting = false;
|
|
2022
2025
|
this._handleInputEvent = (e) => {
|
|
2023
2026
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
2024
2027
|
this._triggerCountryChange();
|
|
2025
2028
|
}
|
|
2026
|
-
const isFormattingChar = e
|
|
2027
|
-
const isPaste = e
|
|
2029
|
+
const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
|
|
2030
|
+
const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
|
|
2028
2031
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
2029
2032
|
userOverrideFormatting = true;
|
|
2030
2033
|
} else if (!/[^+0-9]/.test(this.telInput.value)) {
|
|
2031
2034
|
userOverrideFormatting = false;
|
|
2032
2035
|
}
|
|
2033
|
-
|
|
2036
|
+
const disableFormatOnSetNumber = e?.detail && e.detail["isSetNumber"] && !formatOnDisplay;
|
|
2037
|
+
if (formatAsYouType && !userOverrideFormatting && !disableFormatOnSetNumber) {
|
|
2034
2038
|
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2035
2039
|
const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
|
|
2036
2040
|
const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
|
|
2037
|
-
const isDeleteForwards = e
|
|
2041
|
+
const isDeleteForwards = e?.inputType === "deleteContentForward";
|
|
2038
2042
|
const formattedValue = this._formatNumberAsYouType();
|
|
2039
2043
|
const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
|
|
2040
2044
|
this.telInput.value = formattedValue;
|
|
@@ -2076,10 +2080,11 @@ var Iti = class {
|
|
|
2076
2080
|
return max && number.length > max ? number.substr(0, max) : number;
|
|
2077
2081
|
}
|
|
2078
2082
|
//* Trigger a custom event on the input.
|
|
2079
|
-
_trigger(name) {
|
|
2080
|
-
const e = new
|
|
2083
|
+
_trigger(name, detailProps = {}) {
|
|
2084
|
+
const e = new CustomEvent(name, {
|
|
2081
2085
|
bubbles: true,
|
|
2082
|
-
cancelable: true
|
|
2086
|
+
cancelable: true,
|
|
2087
|
+
detail: detailProps
|
|
2083
2088
|
});
|
|
2084
2089
|
this.telInput.dispatchEvent(e);
|
|
2085
2090
|
}
|
|
@@ -2600,7 +2605,8 @@ var Iti = class {
|
|
|
2600
2605
|
handleAutoCountry() {
|
|
2601
2606
|
if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
|
|
2602
2607
|
this.defaultCountry = intlTelInput.autoCountry;
|
|
2603
|
-
|
|
2608
|
+
const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
|
|
2609
|
+
if (!hasSelectedCountryOrGlobe) {
|
|
2604
2610
|
this.setCountry(this.defaultCountry);
|
|
2605
2611
|
}
|
|
2606
2612
|
this.resolveAutoCountryPromise();
|
|
@@ -2729,7 +2735,7 @@ var Iti = class {
|
|
|
2729
2735
|
if (countryChanged) {
|
|
2730
2736
|
this._triggerCountryChange();
|
|
2731
2737
|
}
|
|
2732
|
-
this._trigger("input");
|
|
2738
|
+
this._trigger("input", { isSetNumber: true });
|
|
2733
2739
|
}
|
|
2734
2740
|
//* Set the placeholder number typ
|
|
2735
2741
|
setPlaceholderNumberType(type) {
|
|
@@ -2778,7 +2784,7 @@ var intlTelInput = Object.assign(
|
|
|
2778
2784
|
//* A map from instance ID to instance object.
|
|
2779
2785
|
instances: {},
|
|
2780
2786
|
loadUtils,
|
|
2781
|
-
version: "23.0.
|
|
2787
|
+
version: "23.0.11"
|
|
2782
2788
|
}
|
|
2783
2789
|
);
|
|
2784
2790
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -9003,7 +9009,7 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
9003
9009
|
getInstance: () => itiRef.current,
|
|
9004
9010
|
getInput: () => inputRef.current
|
|
9005
9011
|
}));
|
|
9006
|
-
const update = () => {
|
|
9012
|
+
const update = (0, import_react.useCallback)(() => {
|
|
9007
9013
|
const num = itiRef.current?.getNumber() || "";
|
|
9008
9014
|
const countryIso = itiRef.current?.getSelectedCountryData().iso2 || "";
|
|
9009
9015
|
onChangeNumber(num);
|
|
@@ -9019,11 +9025,18 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
9019
9025
|
onChangeErrorCode(errorCode);
|
|
9020
9026
|
}
|
|
9021
9027
|
}
|
|
9022
|
-
};
|
|
9028
|
+
}, [onChangeCountry, onChangeErrorCode, onChangeNumber, onChangeValidity, usePreciseValidation]);
|
|
9029
|
+
(0, import_react.useEffect)(() => {
|
|
9030
|
+
if (inputRef.current) {
|
|
9031
|
+
itiRef.current = intlTelInputWithUtils_default(inputRef.current, initOptions);
|
|
9032
|
+
}
|
|
9033
|
+
return () => {
|
|
9034
|
+
itiRef.current?.destroy();
|
|
9035
|
+
};
|
|
9036
|
+
}, []);
|
|
9023
9037
|
(0, import_react.useEffect)(() => {
|
|
9024
9038
|
const inputRefCurrent = inputRef.current;
|
|
9025
9039
|
if (inputRefCurrent) {
|
|
9026
|
-
itiRef.current = intlTelInputWithUtils_default(inputRefCurrent, initOptions);
|
|
9027
9040
|
inputRefCurrent.addEventListener("countrychange", update);
|
|
9028
9041
|
itiRef.current.promise.then(update);
|
|
9029
9042
|
}
|
|
@@ -9031,9 +9044,8 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
|
|
|
9031
9044
|
if (inputRefCurrent) {
|
|
9032
9045
|
inputRefCurrent.removeEventListener("countrychange", update);
|
|
9033
9046
|
}
|
|
9034
|
-
itiRef.current?.destroy();
|
|
9035
9047
|
};
|
|
9036
|
-
}, []);
|
|
9048
|
+
}, [update]);
|
|
9037
9049
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
9038
9050
|
"input",
|
|
9039
9051
|
{
|