intl-tel-input 26.1.0 → 26.2.0
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 +1 -1
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +95 -55
- package/angular/build/IntlTelInputWithUtils.js +95 -55
- package/angular/build/types/intl-tel-input.d.ts +2 -1
- package/angular/build/types/modules/constants.d.ts +1 -0
- package/angular/build/types/modules/utils/isAndroid.d.ts +1 -0
- package/build/css/intlTelInput-no-assets.css +36 -4
- package/build/css/intlTelInput-no-assets.min.css +1 -1
- package/build/css/intlTelInput.css +36 -4
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +6 -1
- package/build/js/intlTelInput.js +90 -53
- package/build/js/intlTelInput.min.js +4 -4
- package/build/js/intlTelInputWithUtils.js +90 -53
- package/build/js/intlTelInputWithUtils.min.js +5 -5
- package/package.json +1 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +89 -52
- package/react/build/IntlTelInput.d.ts +6 -1
- package/react/build/IntlTelInput.js +89 -52
- package/react/build/IntlTelInputWithUtils.cjs +89 -52
- package/react/build/IntlTelInputWithUtils.js +89 -52
- package/svelte/README.md +1 -1
- package/svelte/build/IntlTelInput.mjs +623 -615
- package/svelte/build/IntlTelInputWithUtils.mjs +807 -799
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.vue.d.ts +4 -0
- package/vue/build/IntlTelInputWithUtils.vue.d.ts +4 -0
- package/vue/build/exports/IntlTelInput.mjs +1 -1
- package/vue/build/exports/IntlTelInputWithUtils.mjs +1 -1
- package/vue/build/{intl-tel-input-Btkve2N2.mjs → intl-tel-input-CfNQ1iD-.mjs} +136 -128
- package/vue/build/intl-tel-input.d.ts +2 -1
- package/vue/build/modules/constants.d.ts +1 -0
- package/vue/build/modules/utils/isAndroid.d.ts +1 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A JavaScript plugin for entering, formatting and validating international telephone numbers. React, Vue, Angular and Svelte components also included.
|
|
4
4
|
|
|
5
|
-
[Explore docs »](https://intl-tel-input.com/docs/getting-started
|
|
5
|
+
[Explore docs »](https://intl-tel-input.com/docs/getting-started)
|
|
6
6
|
|
|
7
7
|
<picture>
|
|
8
8
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-dark.png">
|
package/angular/README.md
CHANGED
|
@@ -54,7 +54,7 @@ import "intl-tel-input/styles";
|
|
|
54
54
|
|
|
55
55
|
See the [validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/angular/demo/validation/validation.component.ts) for a more fleshed-out example of how to handle validation, or check out the [form demo](https://github.com/jackocnr/intl-tel-input/blob/master/angular/demo/form/form.component.ts) for an alternative approach using `ReactiveFormsModule`.
|
|
56
56
|
|
|
57
|
-
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 { IntlTelInputComponent } from "intl-tel-input/angularWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/angular"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the utils.js file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN-hosted version, e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@26.
|
|
57
|
+
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 { IntlTelInputComponent } from "intl-tel-input/angularWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/angular"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the utils.js file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN-hosted version, e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@26.2.0/build/js/utils.js"`.
|
|
58
58
|
|
|
59
59
|
## Props
|
|
60
60
|
|
|
@@ -1713,6 +1713,7 @@ var CLASSES = {
|
|
|
1713
1713
|
ARROW_UP: "iti__arrow--up",
|
|
1714
1714
|
GLOBE: "iti__globe",
|
|
1715
1715
|
FLAG: "iti__flag",
|
|
1716
|
+
LOADING: "iti__loading",
|
|
1716
1717
|
COUNTRY_ITEM: "iti__country",
|
|
1717
1718
|
HIGHLIGHT: "iti__highlight"
|
|
1718
1719
|
};
|
|
@@ -1832,6 +1833,8 @@ var computeDefaultUseFullscreenPopup = () => {
|
|
|
1832
1833
|
var defaults = {
|
|
1833
1834
|
//* Whether or not to allow the dropdown.
|
|
1834
1835
|
allowDropdown: true,
|
|
1836
|
+
//* The number type to enforce during validation.
|
|
1837
|
+
allowedNumberTypes: ["MOBILE", "FIXED_LINE"],
|
|
1835
1838
|
//* Whether or not to allow extensions after the main number.
|
|
1836
1839
|
allowNumberExtensions: false,
|
|
1837
1840
|
// Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
|
|
@@ -1881,9 +1884,7 @@ var defaults = {
|
|
|
1881
1884
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1882
1885
|
strictMode: false,
|
|
1883
1886
|
//* Use full screen popup instead of dropdown for country list.
|
|
1884
|
-
useFullscreenPopup: computeDefaultUseFullscreenPopup()
|
|
1885
|
-
//* The number type to enforce during validation.
|
|
1886
|
-
allowedNumberTypes: ["MOBILE", "FIXED_LINE"]
|
|
1887
|
+
useFullscreenPopup: computeDefaultUseFullscreenPopup()
|
|
1887
1888
|
};
|
|
1888
1889
|
var applyOptionSideEffects = (o) => {
|
|
1889
1890
|
if (o.useFullscreenPopup) {
|
|
@@ -1908,6 +1909,9 @@ var applyOptionSideEffects = (o) => {
|
|
|
1908
1909
|
var getNumeric = (s) => s.replace(/\D/g, "");
|
|
1909
1910
|
var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
1910
1911
|
|
|
1912
|
+
// angular/build/temp/modules/utils/isAndroid.js
|
|
1913
|
+
var getIsAndroid = () => typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1914
|
+
|
|
1911
1915
|
// angular/build/temp/modules/core/countrySearch.js
|
|
1912
1916
|
var getMatchedCountries = (countries, query) => {
|
|
1913
1917
|
const normalisedQuery = normaliseString(query);
|
|
@@ -2548,14 +2552,14 @@ var isRegionlessNanp = (number) => {
|
|
|
2548
2552
|
var id = 0;
|
|
2549
2553
|
var iso2Set = new Set(data_default.map((c) => c.iso2));
|
|
2550
2554
|
var isIso2 = (val) => iso2Set.has(val);
|
|
2551
|
-
var Iti = class
|
|
2555
|
+
var Iti = class {
|
|
2552
2556
|
constructor(input, customOptions = {}) {
|
|
2553
2557
|
this.id = id++;
|
|
2554
2558
|
this.options = Object.assign(Object.assign({}, defaults), customOptions);
|
|
2555
2559
|
applyOptionSideEffects(this.options);
|
|
2556
2560
|
this.ui = new UI(input, this.options, this.id);
|
|
2557
|
-
this.isAndroid =
|
|
2558
|
-
this.promise = this._createInitPromises();
|
|
2561
|
+
this.isAndroid = getIsAndroid();
|
|
2562
|
+
this.promise = this._createInitPromises(this.options);
|
|
2559
2563
|
this.countries = processAllCountries(this.options);
|
|
2560
2564
|
const { dialCodes, dialCodeMaxLen, dialCodeToIso2Map } = processDialCodes(this.countries);
|
|
2561
2565
|
this.dialCodes = dialCodes;
|
|
@@ -2564,9 +2568,6 @@ var Iti = class _Iti {
|
|
|
2564
2568
|
this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
|
|
2565
2569
|
this._init();
|
|
2566
2570
|
}
|
|
2567
|
-
static _getIsAndroid() {
|
|
2568
|
-
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2569
|
-
}
|
|
2570
2571
|
_updateNumeralSet(str) {
|
|
2571
2572
|
if (/[\u0660-\u0669]/.test(str)) {
|
|
2572
2573
|
this.userNumeralSet = "arabic-indic";
|
|
@@ -2606,15 +2607,36 @@ var Iti = class _Iti {
|
|
|
2606
2607
|
_setTelInputValue(asciiValue) {
|
|
2607
2608
|
this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
|
|
2608
2609
|
}
|
|
2609
|
-
_createInitPromises() {
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2610
|
+
_createInitPromises(options) {
|
|
2611
|
+
const { initialCountry, geoIpLookup, loadUtils } = options;
|
|
2612
|
+
const needsAutoCountryPromise = initialCountry === INITIAL_COUNTRY.AUTO && Boolean(geoIpLookup);
|
|
2613
|
+
const needsUtilsScriptPromise = Boolean(loadUtils) && !intlTelInput.utils;
|
|
2614
|
+
let autoCountryPromise;
|
|
2615
|
+
if (needsAutoCountryPromise) {
|
|
2616
|
+
autoCountryPromise = new Promise((resolve, reject) => {
|
|
2617
|
+
this.resolveAutoCountryPromise = resolve;
|
|
2618
|
+
this.rejectAutoCountryPromise = reject;
|
|
2619
|
+
});
|
|
2620
|
+
} else {
|
|
2621
|
+
autoCountryPromise = Promise.resolve(void 0);
|
|
2622
|
+
this.resolveAutoCountryPromise = () => {
|
|
2623
|
+
};
|
|
2624
|
+
this.rejectAutoCountryPromise = () => {
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
let utilsScriptPromise;
|
|
2628
|
+
if (needsUtilsScriptPromise) {
|
|
2629
|
+
utilsScriptPromise = new Promise((resolve, reject) => {
|
|
2630
|
+
this.resolveUtilsScriptPromise = resolve;
|
|
2631
|
+
this.rejectUtilsScriptPromise = reject;
|
|
2632
|
+
});
|
|
2633
|
+
} else {
|
|
2634
|
+
utilsScriptPromise = Promise.resolve(void 0);
|
|
2635
|
+
this.resolveUtilsScriptPromise = () => {
|
|
2636
|
+
};
|
|
2637
|
+
this.rejectUtilsScriptPromise = () => {
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2618
2640
|
return Promise.all([autoCountryPromise, utilsScriptPromise]);
|
|
2619
2641
|
}
|
|
2620
2642
|
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
@@ -2649,19 +2671,23 @@ var Iti = class _Iti {
|
|
|
2649
2671
|
const isRegionlessNanpNumber = isRegionlessNanp(val);
|
|
2650
2672
|
const { initialCountry, geoIpLookup } = this.options;
|
|
2651
2673
|
const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
if (
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
if (
|
|
2674
|
+
const doingAutoCountryLookup = isAutoCountry && !overrideAutoCountry;
|
|
2675
|
+
const initialCountryLower = initialCountry.toLowerCase();
|
|
2676
|
+
const isValidInitialCountry = isIso2(initialCountryLower);
|
|
2677
|
+
if (dialCode) {
|
|
2678
|
+
if (isRegionlessNanpNumber) {
|
|
2679
|
+
if (isValidInitialCountry) {
|
|
2680
|
+
this._setCountry(initialCountryLower);
|
|
2681
|
+
} else if (!doingAutoCountryLookup) {
|
|
2660
2682
|
this._setCountry(US.ISO2);
|
|
2661
|
-
} else {
|
|
2662
|
-
this._setCountry("");
|
|
2663
2683
|
}
|
|
2684
|
+
} else {
|
|
2685
|
+
this._updateCountryFromNumber(val);
|
|
2664
2686
|
}
|
|
2687
|
+
} else if (isValidInitialCountry) {
|
|
2688
|
+
this._setCountry(initialCountryLower);
|
|
2689
|
+
} else if (!doingAutoCountryLookup) {
|
|
2690
|
+
this._setCountry("");
|
|
2665
2691
|
}
|
|
2666
2692
|
if (val) {
|
|
2667
2693
|
this._updateValFromNumber(val);
|
|
@@ -2728,7 +2754,7 @@ var Iti = class _Iti {
|
|
|
2728
2754
|
};
|
|
2729
2755
|
this.ui.countryContainer.addEventListener("keydown", handleCountryContainerKeydown, { signal });
|
|
2730
2756
|
}
|
|
2731
|
-
//* Init
|
|
2757
|
+
//* Init requests: utils script / geo ip lookup.
|
|
2732
2758
|
_initRequests() {
|
|
2733
2759
|
const { loadUtils, initialCountry, geoIpLookup } = this.options;
|
|
2734
2760
|
if (loadUtils && !intlTelInput.utils) {
|
|
@@ -2751,32 +2777,39 @@ var Iti = class _Iti {
|
|
|
2751
2777
|
this.resolveUtilsScriptPromise();
|
|
2752
2778
|
}
|
|
2753
2779
|
const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
|
|
2754
|
-
if (isAutoCountry
|
|
2755
|
-
this.
|
|
2756
|
-
|
|
2757
|
-
|
|
2780
|
+
if (isAutoCountry) {
|
|
2781
|
+
if (this.selectedCountryData.iso2) {
|
|
2782
|
+
this.resolveAutoCountryPromise();
|
|
2783
|
+
} else {
|
|
2784
|
+
this._loadAutoCountry();
|
|
2785
|
+
}
|
|
2758
2786
|
}
|
|
2759
2787
|
}
|
|
2760
2788
|
//* Perform the geo ip lookup.
|
|
2761
2789
|
_loadAutoCountry() {
|
|
2762
2790
|
if (intlTelInput.autoCountry) {
|
|
2763
2791
|
this.handleAutoCountry();
|
|
2764
|
-
} else
|
|
2765
|
-
|
|
2766
|
-
if (
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2792
|
+
} else {
|
|
2793
|
+
this.ui.selectedCountryInner.classList.add(CLASSES.LOADING);
|
|
2794
|
+
if (!intlTelInput.startedLoadingAutoCountry) {
|
|
2795
|
+
intlTelInput.startedLoadingAutoCountry = true;
|
|
2796
|
+
if (typeof this.options.geoIpLookup === "function") {
|
|
2797
|
+
const successCallback = (iso2 = "") => {
|
|
2798
|
+
this.ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
2799
|
+
const iso2Lower = iso2.toLowerCase();
|
|
2800
|
+
if (isIso2(iso2Lower)) {
|
|
2801
|
+
intlTelInput.autoCountry = iso2Lower;
|
|
2802
|
+
setTimeout(() => forEachInstance("handleAutoCountry"));
|
|
2803
|
+
} else {
|
|
2804
|
+
forEachInstance("handleAutoCountryFailure");
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
const failureCallback = () => {
|
|
2808
|
+
this.ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
2809
|
+
forEachInstance("handleAutoCountryFailure");
|
|
2810
|
+
};
|
|
2811
|
+
this.options.geoIpLookup(successCallback, failureCallback);
|
|
2812
|
+
}
|
|
2780
2813
|
}
|
|
2781
2814
|
}
|
|
2782
2815
|
}
|
|
@@ -3175,9 +3208,7 @@ var Iti = class _Iti {
|
|
|
3175
3208
|
const cleanNumber = hasPrefix ? number.substring(1) : number;
|
|
3176
3209
|
return `+${dialCode}${cleanNumber}`;
|
|
3177
3210
|
}
|
|
3178
|
-
|
|
3179
|
-
// BUT ONLY IF ITS CHANGED FROM THE CURRENTLY SELECTED COUNTRY
|
|
3180
|
-
// NOTE: consider refactoring this to be more clear
|
|
3211
|
+
//* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
|
|
3181
3212
|
_getNewCountryFromNumber(fullNumber) {
|
|
3182
3213
|
const plusIndex = fullNumber.indexOf("+");
|
|
3183
3214
|
let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
|
|
@@ -3224,7 +3255,7 @@ var Iti = class _Iti {
|
|
|
3224
3255
|
return null;
|
|
3225
3256
|
}
|
|
3226
3257
|
return "";
|
|
3227
|
-
} else if ((!number || number === "+") && !selectedIso2) {
|
|
3258
|
+
} else if ((!number || number === "+") && !selectedIso2 && this.defaultCountry) {
|
|
3228
3259
|
return this.defaultCountry;
|
|
3229
3260
|
}
|
|
3230
3261
|
return null;
|
|
@@ -3428,6 +3459,11 @@ var Iti = class _Iti {
|
|
|
3428
3459
|
this.resolveAutoCountryPromise();
|
|
3429
3460
|
}
|
|
3430
3461
|
}
|
|
3462
|
+
//* This is called when the geoip call fails or times out.
|
|
3463
|
+
handleAutoCountryFailure() {
|
|
3464
|
+
this._setInitialState(true);
|
|
3465
|
+
this.rejectAutoCountryPromise();
|
|
3466
|
+
}
|
|
3431
3467
|
//* This is called when the utils request completes.
|
|
3432
3468
|
handleUtils() {
|
|
3433
3469
|
if (intlTelInput.utils) {
|
|
@@ -3442,6 +3478,10 @@ var Iti = class _Iti {
|
|
|
3442
3478
|
}
|
|
3443
3479
|
this.resolveUtilsScriptPromise();
|
|
3444
3480
|
}
|
|
3481
|
+
//* This is called when the utils request fails or times out.
|
|
3482
|
+
handleUtilsFailure(error) {
|
|
3483
|
+
this.rejectUtilsScriptPromise(error);
|
|
3484
|
+
}
|
|
3445
3485
|
//********************
|
|
3446
3486
|
//* PUBLIC METHODS
|
|
3447
3487
|
//********************
|
|
@@ -3610,7 +3650,7 @@ var attachUtils = (source) => {
|
|
|
3610
3650
|
forEachInstance("handleUtils");
|
|
3611
3651
|
return true;
|
|
3612
3652
|
}).catch((error) => {
|
|
3613
|
-
forEachInstance("
|
|
3653
|
+
forEachInstance("handleUtilsFailure", error);
|
|
3614
3654
|
throw error;
|
|
3615
3655
|
});
|
|
3616
3656
|
}
|
|
@@ -3645,7 +3685,7 @@ var intlTelInput = Object.assign((input, options) => {
|
|
|
3645
3685
|
attachUtils,
|
|
3646
3686
|
startedLoadingUtilsScript: false,
|
|
3647
3687
|
startedLoadingAutoCountry: false,
|
|
3648
|
-
version: "26.
|
|
3688
|
+
version: "26.2.0"
|
|
3649
3689
|
});
|
|
3650
3690
|
var intl_tel_input_default = intlTelInput;
|
|
3651
3691
|
|
|
@@ -1713,6 +1713,7 @@ var CLASSES = {
|
|
|
1713
1713
|
ARROW_UP: "iti__arrow--up",
|
|
1714
1714
|
GLOBE: "iti__globe",
|
|
1715
1715
|
FLAG: "iti__flag",
|
|
1716
|
+
LOADING: "iti__loading",
|
|
1716
1717
|
COUNTRY_ITEM: "iti__country",
|
|
1717
1718
|
HIGHLIGHT: "iti__highlight"
|
|
1718
1719
|
};
|
|
@@ -1832,6 +1833,8 @@ var computeDefaultUseFullscreenPopup = () => {
|
|
|
1832
1833
|
var defaults = {
|
|
1833
1834
|
//* Whether or not to allow the dropdown.
|
|
1834
1835
|
allowDropdown: true,
|
|
1836
|
+
//* The number type to enforce during validation.
|
|
1837
|
+
allowedNumberTypes: ["MOBILE", "FIXED_LINE"],
|
|
1835
1838
|
//* Whether or not to allow extensions after the main number.
|
|
1836
1839
|
allowNumberExtensions: false,
|
|
1837
1840
|
// Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
|
|
@@ -1881,9 +1884,7 @@ var defaults = {
|
|
|
1881
1884
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1882
1885
|
strictMode: false,
|
|
1883
1886
|
//* Use full screen popup instead of dropdown for country list.
|
|
1884
|
-
useFullscreenPopup: computeDefaultUseFullscreenPopup()
|
|
1885
|
-
//* The number type to enforce during validation.
|
|
1886
|
-
allowedNumberTypes: ["MOBILE", "FIXED_LINE"]
|
|
1887
|
+
useFullscreenPopup: computeDefaultUseFullscreenPopup()
|
|
1887
1888
|
};
|
|
1888
1889
|
var applyOptionSideEffects = (o) => {
|
|
1889
1890
|
if (o.useFullscreenPopup) {
|
|
@@ -1908,6 +1909,9 @@ var applyOptionSideEffects = (o) => {
|
|
|
1908
1909
|
var getNumeric = (s) => s.replace(/\D/g, "");
|
|
1909
1910
|
var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
1910
1911
|
|
|
1912
|
+
// angular/build/temp/modules/utils/isAndroid.js
|
|
1913
|
+
var getIsAndroid = () => typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
1914
|
+
|
|
1911
1915
|
// angular/build/temp/modules/core/countrySearch.js
|
|
1912
1916
|
var getMatchedCountries = (countries, query) => {
|
|
1913
1917
|
const normalisedQuery = normaliseString(query);
|
|
@@ -2548,14 +2552,14 @@ var isRegionlessNanp = (number) => {
|
|
|
2548
2552
|
var id = 0;
|
|
2549
2553
|
var iso2Set = new Set(data_default.map((c) => c.iso2));
|
|
2550
2554
|
var isIso2 = (val) => iso2Set.has(val);
|
|
2551
|
-
var Iti = class
|
|
2555
|
+
var Iti = class {
|
|
2552
2556
|
constructor(input, customOptions = {}) {
|
|
2553
2557
|
this.id = id++;
|
|
2554
2558
|
this.options = Object.assign(Object.assign({}, defaults), customOptions);
|
|
2555
2559
|
applyOptionSideEffects(this.options);
|
|
2556
2560
|
this.ui = new UI(input, this.options, this.id);
|
|
2557
|
-
this.isAndroid =
|
|
2558
|
-
this.promise = this._createInitPromises();
|
|
2561
|
+
this.isAndroid = getIsAndroid();
|
|
2562
|
+
this.promise = this._createInitPromises(this.options);
|
|
2559
2563
|
this.countries = processAllCountries(this.options);
|
|
2560
2564
|
const { dialCodes, dialCodeMaxLen, dialCodeToIso2Map } = processDialCodes(this.countries);
|
|
2561
2565
|
this.dialCodes = dialCodes;
|
|
@@ -2564,9 +2568,6 @@ var Iti = class _Iti {
|
|
|
2564
2568
|
this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
|
|
2565
2569
|
this._init();
|
|
2566
2570
|
}
|
|
2567
|
-
static _getIsAndroid() {
|
|
2568
|
-
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2569
|
-
}
|
|
2570
2571
|
_updateNumeralSet(str) {
|
|
2571
2572
|
if (/[\u0660-\u0669]/.test(str)) {
|
|
2572
2573
|
this.userNumeralSet = "arabic-indic";
|
|
@@ -2606,15 +2607,36 @@ var Iti = class _Iti {
|
|
|
2606
2607
|
_setTelInputValue(asciiValue) {
|
|
2607
2608
|
this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
|
|
2608
2609
|
}
|
|
2609
|
-
_createInitPromises() {
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2610
|
+
_createInitPromises(options) {
|
|
2611
|
+
const { initialCountry, geoIpLookup, loadUtils } = options;
|
|
2612
|
+
const needsAutoCountryPromise = initialCountry === INITIAL_COUNTRY.AUTO && Boolean(geoIpLookup);
|
|
2613
|
+
const needsUtilsScriptPromise = Boolean(loadUtils) && !intlTelInput.utils;
|
|
2614
|
+
let autoCountryPromise;
|
|
2615
|
+
if (needsAutoCountryPromise) {
|
|
2616
|
+
autoCountryPromise = new Promise((resolve, reject) => {
|
|
2617
|
+
this.resolveAutoCountryPromise = resolve;
|
|
2618
|
+
this.rejectAutoCountryPromise = reject;
|
|
2619
|
+
});
|
|
2620
|
+
} else {
|
|
2621
|
+
autoCountryPromise = Promise.resolve(void 0);
|
|
2622
|
+
this.resolveAutoCountryPromise = () => {
|
|
2623
|
+
};
|
|
2624
|
+
this.rejectAutoCountryPromise = () => {
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
let utilsScriptPromise;
|
|
2628
|
+
if (needsUtilsScriptPromise) {
|
|
2629
|
+
utilsScriptPromise = new Promise((resolve, reject) => {
|
|
2630
|
+
this.resolveUtilsScriptPromise = resolve;
|
|
2631
|
+
this.rejectUtilsScriptPromise = reject;
|
|
2632
|
+
});
|
|
2633
|
+
} else {
|
|
2634
|
+
utilsScriptPromise = Promise.resolve(void 0);
|
|
2635
|
+
this.resolveUtilsScriptPromise = () => {
|
|
2636
|
+
};
|
|
2637
|
+
this.rejectUtilsScriptPromise = () => {
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2618
2640
|
return Promise.all([autoCountryPromise, utilsScriptPromise]);
|
|
2619
2641
|
}
|
|
2620
2642
|
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
@@ -2649,19 +2671,23 @@ var Iti = class _Iti {
|
|
|
2649
2671
|
const isRegionlessNanpNumber = isRegionlessNanp(val);
|
|
2650
2672
|
const { initialCountry, geoIpLookup } = this.options;
|
|
2651
2673
|
const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
if (
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
if (
|
|
2674
|
+
const doingAutoCountryLookup = isAutoCountry && !overrideAutoCountry;
|
|
2675
|
+
const initialCountryLower = initialCountry.toLowerCase();
|
|
2676
|
+
const isValidInitialCountry = isIso2(initialCountryLower);
|
|
2677
|
+
if (dialCode) {
|
|
2678
|
+
if (isRegionlessNanpNumber) {
|
|
2679
|
+
if (isValidInitialCountry) {
|
|
2680
|
+
this._setCountry(initialCountryLower);
|
|
2681
|
+
} else if (!doingAutoCountryLookup) {
|
|
2660
2682
|
this._setCountry(US.ISO2);
|
|
2661
|
-
} else {
|
|
2662
|
-
this._setCountry("");
|
|
2663
2683
|
}
|
|
2684
|
+
} else {
|
|
2685
|
+
this._updateCountryFromNumber(val);
|
|
2664
2686
|
}
|
|
2687
|
+
} else if (isValidInitialCountry) {
|
|
2688
|
+
this._setCountry(initialCountryLower);
|
|
2689
|
+
} else if (!doingAutoCountryLookup) {
|
|
2690
|
+
this._setCountry("");
|
|
2665
2691
|
}
|
|
2666
2692
|
if (val) {
|
|
2667
2693
|
this._updateValFromNumber(val);
|
|
@@ -2728,7 +2754,7 @@ var Iti = class _Iti {
|
|
|
2728
2754
|
};
|
|
2729
2755
|
this.ui.countryContainer.addEventListener("keydown", handleCountryContainerKeydown, { signal });
|
|
2730
2756
|
}
|
|
2731
|
-
//* Init
|
|
2757
|
+
//* Init requests: utils script / geo ip lookup.
|
|
2732
2758
|
_initRequests() {
|
|
2733
2759
|
const { loadUtils, initialCountry, geoIpLookup } = this.options;
|
|
2734
2760
|
if (loadUtils && !intlTelInput.utils) {
|
|
@@ -2751,32 +2777,39 @@ var Iti = class _Iti {
|
|
|
2751
2777
|
this.resolveUtilsScriptPromise();
|
|
2752
2778
|
}
|
|
2753
2779
|
const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
|
|
2754
|
-
if (isAutoCountry
|
|
2755
|
-
this.
|
|
2756
|
-
|
|
2757
|
-
|
|
2780
|
+
if (isAutoCountry) {
|
|
2781
|
+
if (this.selectedCountryData.iso2) {
|
|
2782
|
+
this.resolveAutoCountryPromise();
|
|
2783
|
+
} else {
|
|
2784
|
+
this._loadAutoCountry();
|
|
2785
|
+
}
|
|
2758
2786
|
}
|
|
2759
2787
|
}
|
|
2760
2788
|
//* Perform the geo ip lookup.
|
|
2761
2789
|
_loadAutoCountry() {
|
|
2762
2790
|
if (intlTelInput.autoCountry) {
|
|
2763
2791
|
this.handleAutoCountry();
|
|
2764
|
-
} else
|
|
2765
|
-
|
|
2766
|
-
if (
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2792
|
+
} else {
|
|
2793
|
+
this.ui.selectedCountryInner.classList.add(CLASSES.LOADING);
|
|
2794
|
+
if (!intlTelInput.startedLoadingAutoCountry) {
|
|
2795
|
+
intlTelInput.startedLoadingAutoCountry = true;
|
|
2796
|
+
if (typeof this.options.geoIpLookup === "function") {
|
|
2797
|
+
const successCallback = (iso2 = "") => {
|
|
2798
|
+
this.ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
2799
|
+
const iso2Lower = iso2.toLowerCase();
|
|
2800
|
+
if (isIso2(iso2Lower)) {
|
|
2801
|
+
intlTelInput.autoCountry = iso2Lower;
|
|
2802
|
+
setTimeout(() => forEachInstance("handleAutoCountry"));
|
|
2803
|
+
} else {
|
|
2804
|
+
forEachInstance("handleAutoCountryFailure");
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
const failureCallback = () => {
|
|
2808
|
+
this.ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
2809
|
+
forEachInstance("handleAutoCountryFailure");
|
|
2810
|
+
};
|
|
2811
|
+
this.options.geoIpLookup(successCallback, failureCallback);
|
|
2812
|
+
}
|
|
2780
2813
|
}
|
|
2781
2814
|
}
|
|
2782
2815
|
}
|
|
@@ -3175,9 +3208,7 @@ var Iti = class _Iti {
|
|
|
3175
3208
|
const cleanNumber = hasPrefix ? number.substring(1) : number;
|
|
3176
3209
|
return `+${dialCode}${cleanNumber}`;
|
|
3177
3210
|
}
|
|
3178
|
-
|
|
3179
|
-
// BUT ONLY IF ITS CHANGED FROM THE CURRENTLY SELECTED COUNTRY
|
|
3180
|
-
// NOTE: consider refactoring this to be more clear
|
|
3211
|
+
//* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
|
|
3181
3212
|
_getNewCountryFromNumber(fullNumber) {
|
|
3182
3213
|
const plusIndex = fullNumber.indexOf("+");
|
|
3183
3214
|
let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
|
|
@@ -3224,7 +3255,7 @@ var Iti = class _Iti {
|
|
|
3224
3255
|
return null;
|
|
3225
3256
|
}
|
|
3226
3257
|
return "";
|
|
3227
|
-
} else if ((!number || number === "+") && !selectedIso2) {
|
|
3258
|
+
} else if ((!number || number === "+") && !selectedIso2 && this.defaultCountry) {
|
|
3228
3259
|
return this.defaultCountry;
|
|
3229
3260
|
}
|
|
3230
3261
|
return null;
|
|
@@ -3428,6 +3459,11 @@ var Iti = class _Iti {
|
|
|
3428
3459
|
this.resolveAutoCountryPromise();
|
|
3429
3460
|
}
|
|
3430
3461
|
}
|
|
3462
|
+
//* This is called when the geoip call fails or times out.
|
|
3463
|
+
handleAutoCountryFailure() {
|
|
3464
|
+
this._setInitialState(true);
|
|
3465
|
+
this.rejectAutoCountryPromise();
|
|
3466
|
+
}
|
|
3431
3467
|
//* This is called when the utils request completes.
|
|
3432
3468
|
handleUtils() {
|
|
3433
3469
|
if (intlTelInput.utils) {
|
|
@@ -3442,6 +3478,10 @@ var Iti = class _Iti {
|
|
|
3442
3478
|
}
|
|
3443
3479
|
this.resolveUtilsScriptPromise();
|
|
3444
3480
|
}
|
|
3481
|
+
//* This is called when the utils request fails or times out.
|
|
3482
|
+
handleUtilsFailure(error) {
|
|
3483
|
+
this.rejectUtilsScriptPromise(error);
|
|
3484
|
+
}
|
|
3445
3485
|
//********************
|
|
3446
3486
|
//* PUBLIC METHODS
|
|
3447
3487
|
//********************
|
|
@@ -3610,7 +3650,7 @@ var attachUtils = (source) => {
|
|
|
3610
3650
|
forEachInstance("handleUtils");
|
|
3611
3651
|
return true;
|
|
3612
3652
|
}).catch((error) => {
|
|
3613
|
-
forEachInstance("
|
|
3653
|
+
forEachInstance("handleUtilsFailure", error);
|
|
3614
3654
|
throw error;
|
|
3615
3655
|
});
|
|
3616
3656
|
}
|
|
@@ -3645,7 +3685,7 @@ var intlTelInput = Object.assign((input, options) => {
|
|
|
3645
3685
|
attachUtils,
|
|
3646
3686
|
startedLoadingUtilsScript: false,
|
|
3647
3687
|
startedLoadingAutoCountry: false,
|
|
3648
|
-
version: "26.
|
|
3688
|
+
version: "26.2.0"
|
|
3649
3689
|
});
|
|
3650
3690
|
var intl_tel_input_default = intlTelInput;
|
|
3651
3691
|
|
|
@@ -27,7 +27,6 @@ export declare class Iti {
|
|
|
27
27
|
private resolveUtilsScriptPromise;
|
|
28
28
|
private rejectUtilsScriptPromise;
|
|
29
29
|
constructor(input: HTMLInputElement, customOptions?: SomeOptions);
|
|
30
|
-
private static _getIsAndroid;
|
|
31
30
|
private _updateNumeralSet;
|
|
32
31
|
private _mapAsciiToUserNumerals;
|
|
33
32
|
private _normaliseNumerals;
|
|
@@ -76,7 +75,9 @@ export declare class Iti {
|
|
|
76
75
|
private _beforeSetNumber;
|
|
77
76
|
private _triggerCountryChange;
|
|
78
77
|
handleAutoCountry(): void;
|
|
78
|
+
handleAutoCountryFailure(): void;
|
|
79
79
|
handleUtils(): void;
|
|
80
|
+
handleUtilsFailure(error: any): void;
|
|
80
81
|
destroy(): void;
|
|
81
82
|
getExtension(): string;
|
|
82
83
|
getNumber(format?: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getIsAndroid: () => boolean;
|