intl-tel-input 25.10.12 → 25.11.1
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 +62 -59
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +887 -688
- package/angular/build/IntlTelInputWithUtils.js +891 -692
- package/angular/build/types/intl-tel-input/data.d.ts +3 -3
- package/angular/build/types/intl-tel-input.d.ts +22 -70
- package/angular/build/types/modules/constants.d.ts +84 -0
- package/angular/build/types/modules/core/countrySearch.d.ts +17 -0
- package/angular/build/types/modules/core/icons.d.ts +7 -0
- package/angular/build/types/modules/core/options.d.ts +2 -1
- package/angular/build/types/modules/core/ui.d.ts +44 -0
- package/angular/build/types/modules/data/country-data.d.ts +5 -5
- package/angular/build/types/modules/format/caret.d.ts +1 -1
- package/angular/build/types/modules/format/formatting.d.ts +3 -3
- package/angular/build/types/modules/types/events.d.ts +9 -0
- package/angular/build/types/modules/types/public-api.d.ts +3 -0
- package/angular/build/types/modules/utils/dom.d.ts +5 -0
- package/build/js/data.js +8 -2
- package/build/js/data.min.js +2 -2
- package/build/js/intlTelInput.d.ts +214 -83
- package/build/js/intlTelInput.js +1034 -770
- package/build/js/intlTelInput.min.js +13 -13
- package/build/js/intlTelInputWithUtils.js +1038 -774
- package/build/js/intlTelInputWithUtils.min.js +13 -13
- package/build/js/utils.js +4 -4
- package/package.json +3 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +1033 -769
- package/react/build/IntlTelInput.d.ts +214 -83
- package/react/build/IntlTelInput.js +1033 -769
- package/react/build/IntlTelInputWithUtils.cjs +1037 -773
- package/react/build/IntlTelInputWithUtils.js +1037 -773
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +967 -739
- package/vue/build/IntlTelInputWithUtils.mjs +1279 -1051
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mergeModels as
|
|
2
|
-
const
|
|
1
|
+
import { mergeModels as U, useModel as K, ref as T, onMounted as Y, watch as q, onUnmounted as X, withDirectives as Q, createElementBlock as J, openBlock as Z, mergeProps as tt, vModelText as et } from "vue";
|
|
2
|
+
const it = [
|
|
3
3
|
[
|
|
4
4
|
"af",
|
|
5
5
|
// Afghanistan
|
|
@@ -1676,20 +1676,26 @@ const j = [
|
|
|
1676
1676
|
null,
|
|
1677
1677
|
"0"
|
|
1678
1678
|
]
|
|
1679
|
-
],
|
|
1680
|
-
for (const
|
|
1681
|
-
|
|
1679
|
+
], L = [];
|
|
1680
|
+
for (const l of it)
|
|
1681
|
+
L.push({
|
|
1682
1682
|
name: "",
|
|
1683
1683
|
// populated in the plugin
|
|
1684
|
-
iso2:
|
|
1685
|
-
dialCode:
|
|
1686
|
-
priority:
|
|
1687
|
-
areaCodes:
|
|
1684
|
+
iso2: l[0],
|
|
1685
|
+
dialCode: l[1],
|
|
1686
|
+
priority: l[2] || 0,
|
|
1687
|
+
areaCodes: l[3] || null,
|
|
1688
1688
|
nodeById: {},
|
|
1689
1689
|
// populated by the plugin
|
|
1690
|
-
nationalPrefix:
|
|
1690
|
+
nationalPrefix: l[4] || null,
|
|
1691
|
+
normalisedName: "",
|
|
1692
|
+
// populated in the plugin
|
|
1693
|
+
initials: "",
|
|
1694
|
+
// populated in the plugin
|
|
1695
|
+
dialCodePlus: ""
|
|
1696
|
+
// populated in the plugin
|
|
1691
1697
|
});
|
|
1692
|
-
const
|
|
1698
|
+
const st = {
|
|
1693
1699
|
ad: "Andorra",
|
|
1694
1700
|
ae: "United Arab Emirates",
|
|
1695
1701
|
af: "Afghanistan",
|
|
@@ -1932,7 +1938,7 @@ const O = {
|
|
|
1932
1938
|
za: "South Africa",
|
|
1933
1939
|
zm: "Zambia",
|
|
1934
1940
|
zw: "Zimbabwe"
|
|
1935
|
-
},
|
|
1941
|
+
}, nt = {
|
|
1936
1942
|
selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})",
|
|
1937
1943
|
noCountrySelected: "Select country",
|
|
1938
1944
|
countryListAriaLabel: "List of countries",
|
|
@@ -1944,19 +1950,95 @@ const O = {
|
|
|
1944
1950
|
// additional countries (not supported by country-list library)
|
|
1945
1951
|
ac: "Ascension Island",
|
|
1946
1952
|
xk: "Kosovo"
|
|
1947
|
-
},
|
|
1953
|
+
}, V = { ...st, ...nt }, A = {
|
|
1954
|
+
OPEN_COUNTRY_DROPDOWN: "open:countrydropdown",
|
|
1955
|
+
CLOSE_COUNTRY_DROPDOWN: "close:countrydropdown",
|
|
1956
|
+
COUNTRY_CHANGE: "countrychange",
|
|
1957
|
+
INPUT: "input"
|
|
1958
|
+
// used for synthetic input trigger
|
|
1959
|
+
}, h = {
|
|
1960
|
+
HIDE: "iti__hide",
|
|
1961
|
+
V_HIDE: "iti__v-hide",
|
|
1962
|
+
ARROW_UP: "iti__arrow--up",
|
|
1963
|
+
GLOBE: "iti__globe",
|
|
1964
|
+
FLAG: "iti__flag",
|
|
1965
|
+
COUNTRY_ITEM: "iti__country",
|
|
1966
|
+
HIGHLIGHT: "iti__highlight"
|
|
1967
|
+
}, g = {
|
|
1968
|
+
ARROW_UP: "ArrowUp",
|
|
1969
|
+
ARROW_DOWN: "ArrowDown",
|
|
1970
|
+
SPACE: " ",
|
|
1971
|
+
ENTER: "Enter",
|
|
1972
|
+
ESC: "Escape",
|
|
1973
|
+
TAB: "Tab"
|
|
1974
|
+
}, B = {
|
|
1975
|
+
PASTE: "insertFromPaste",
|
|
1976
|
+
DELETE_FWD: "deleteContentForward"
|
|
1977
|
+
}, D = {
|
|
1978
|
+
ALPHA_UNICODE: new RegExp("\\p{L}", "u"),
|
|
1979
|
+
// any kind of letter from any language
|
|
1980
|
+
NON_PLUS_NUMERIC: /[^+0-9]/,
|
|
1981
|
+
// chars that are NOT + or digit
|
|
1982
|
+
NON_PLUS_NUMERIC_GLOBAL: /[^+0-9]/g,
|
|
1983
|
+
// chars that are NOT + or digit (global)
|
|
1984
|
+
HIDDEN_SEARCH_CHAR: /^[a-zA-ZÀ-ÿа-яА-Я ]$/
|
|
1985
|
+
// single acceptable hidden-search char
|
|
1986
|
+
}, ot = {
|
|
1987
|
+
HIDDEN_SEARCH_RESET_MS: 1e3
|
|
1988
|
+
}, H = {
|
|
1989
|
+
UNKNOWN_NUMBER_TYPE: -99,
|
|
1990
|
+
UNKNOWN_VALIDATION_ERROR: -99
|
|
1991
|
+
}, S = {
|
|
1992
|
+
SANE_SELECTED_WITH_DIAL_WIDTH: 78,
|
|
1993
|
+
// px width fallback when separateDialCode enabled
|
|
1994
|
+
SANE_SELECTED_NO_DIAL_WIDTH: 42,
|
|
1995
|
+
// px width fallback when no separate dial code
|
|
1996
|
+
INPUT_PADDING_EXTRA_LEFT: 6
|
|
1997
|
+
// px gap between selected country container and input text
|
|
1998
|
+
}, $ = {
|
|
1999
|
+
NANP: "1"
|
|
2000
|
+
// North American Numbering Plan
|
|
2001
|
+
}, P = {
|
|
2002
|
+
DIAL_CODE: "44",
|
|
2003
|
+
// +44 United Kingdom
|
|
2004
|
+
MOBILE_PREFIX: "7",
|
|
2005
|
+
// UK mobile numbers start with 7 after national trunk (0) or core section
|
|
2006
|
+
MOBILE_CORE_LENGTH: 10
|
|
2007
|
+
// core number length (excluding dial code / national prefix) for mobiles
|
|
2008
|
+
}, lt = {
|
|
2009
|
+
ISO2: "us"
|
|
2010
|
+
}, rt = {
|
|
2011
|
+
POLITE: "polite"
|
|
2012
|
+
}, O = {
|
|
2013
|
+
AUTO: "auto"
|
|
2014
|
+
}, W = {
|
|
2015
|
+
COUNTRY_CODE: "countryCode",
|
|
2016
|
+
DIAL_CODE: "dialCode"
|
|
2017
|
+
}, C = {
|
|
2018
|
+
EXPANDED: "aria-expanded",
|
|
2019
|
+
LABEL: "aria-label",
|
|
2020
|
+
SELECTED: "aria-selected",
|
|
2021
|
+
ACTIVE_DESCENDANT: "aria-activedescendant",
|
|
2022
|
+
HASPOPUP: "aria-haspopup",
|
|
2023
|
+
CONTROLS: "aria-controls",
|
|
2024
|
+
HIDDEN: "aria-hidden",
|
|
2025
|
+
AUTOCOMPLETE: "aria-autocomplete",
|
|
2026
|
+
MODAL: "aria-modal"
|
|
2027
|
+
}, R = (l) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(l).matches, at = () => {
|
|
1948
2028
|
if (typeof navigator < "u" && typeof window < "u") {
|
|
1949
|
-
const
|
|
1950
|
-
|
|
2029
|
+
const l = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
2030
|
+
navigator.userAgent
|
|
2031
|
+
), t = R("(max-width: 500px)"), e = R("(max-height: 600px)"), i = R("(pointer: coarse)");
|
|
2032
|
+
return l || t || i && e;
|
|
1951
2033
|
}
|
|
1952
2034
|
return !1;
|
|
1953
|
-
},
|
|
2035
|
+
}, G = {
|
|
1954
2036
|
// Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
|
|
1955
2037
|
allowPhonewords: !1,
|
|
1956
2038
|
//* Whether or not to allow the dropdown.
|
|
1957
2039
|
allowDropdown: !0,
|
|
1958
2040
|
//* Add a placeholder in the input with an example number for the selected country.
|
|
1959
|
-
autoPlaceholder:
|
|
2041
|
+
autoPlaceholder: rt.POLITE,
|
|
1960
2042
|
//* Modify the parentClass.
|
|
1961
2043
|
containerClass: "",
|
|
1962
2044
|
//* The order of the countries in the dropdown. Defaults to alphabetical.
|
|
@@ -1998,225 +2080,91 @@ const O = {
|
|
|
1998
2080
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1999
2081
|
strictMode: !1,
|
|
2000
2082
|
//* Use full screen popup instead of dropdown for country list.
|
|
2001
|
-
useFullscreenPopup:
|
|
2083
|
+
useFullscreenPopup: at(),
|
|
2002
2084
|
//* The number type to enforce during validation.
|
|
2003
2085
|
validationNumberTypes: ["MOBILE"]
|
|
2086
|
+
}, ut = (l, t) => {
|
|
2087
|
+
l.useFullscreenPopup && (l.fixDropdownWidth = !1), l.onlyCountries.length === 1 && (l.initialCountry = l.onlyCountries[0]), l.separateDialCode && (l.nationalMode = !1), l.allowDropdown && !l.showFlags && !l.separateDialCode && (l.nationalMode = !1), l.useFullscreenPopup && !l.dropdownContainer && (l.dropdownContainer = document.body), l.i18n = { ...t, ...l.i18n };
|
|
2088
|
+
}, v = (l) => l.replace(/\D/g, ""), z = (l = "") => l.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), dt = (l, t) => {
|
|
2089
|
+
const e = z(t), i = [], s = [], o = [], n = [], r = [], a = [];
|
|
2090
|
+
for (const c of l)
|
|
2091
|
+
c.iso2 === e ? i.push(c) : c.normalisedName.startsWith(e) ? s.push(c) : c.normalisedName.includes(e) ? o.push(c) : e === c.dialCode || e === c.dialCodePlus ? n.push(c) : c.dialCodePlus.includes(e) ? r.push(c) : c.initials.includes(e) && a.push(c);
|
|
2092
|
+
const d = (c, f) => c.priority - f.priority;
|
|
2093
|
+
return [
|
|
2094
|
+
...i.sort(d),
|
|
2095
|
+
...s.sort(d),
|
|
2096
|
+
...o.sort(d),
|
|
2097
|
+
...n.sort(d),
|
|
2098
|
+
...r.sort(d),
|
|
2099
|
+
...a.sort(d)
|
|
2100
|
+
];
|
|
2101
|
+
}, ct = (l, t) => {
|
|
2102
|
+
const e = t.toLowerCase();
|
|
2103
|
+
for (const i of l)
|
|
2104
|
+
if (i.name.toLowerCase().startsWith(e))
|
|
2105
|
+
return i;
|
|
2106
|
+
return null;
|
|
2107
|
+
}, k = (l) => Object.keys(l).filter((t) => !!l[t]).join(" "), m = (l, t, e) => {
|
|
2108
|
+
const i = document.createElement(l);
|
|
2109
|
+
return t && Object.entries(t).forEach(
|
|
2110
|
+
([s, o]) => i.setAttribute(s, o)
|
|
2111
|
+
), e && e.appendChild(i), i;
|
|
2112
|
+
}, ht = () => `
|
|
2113
|
+
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" ${C.HIDDEN}="true">
|
|
2114
|
+
<circle cx="11" cy="11" r="7" />
|
|
2115
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
2116
|
+
</svg>`, pt = (l) => {
|
|
2117
|
+
const t = `iti-${l}-clear-mask`;
|
|
2118
|
+
return `
|
|
2119
|
+
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" ${C.HIDDEN}="true" focusable="false">
|
|
2120
|
+
<mask id="${t}" maskUnits="userSpaceOnUse">
|
|
2121
|
+
<rect width="16" height="16" fill="white" />
|
|
2122
|
+
<path d="M5.2 5.2 L10.8 10.8 M10.8 5.2 L5.2 10.8" stroke="black" stroke-linecap="round" class="iti__search-clear-x" />
|
|
2123
|
+
</mask>
|
|
2124
|
+
<circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${t})" />
|
|
2125
|
+
</svg>`;
|
|
2004
2126
|
};
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
const I = (r) => r.replace(/\D/g, ""), E = (r = "") => r.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), m = (r, e, t) => {
|
|
2009
|
-
const i = document.createElement(r);
|
|
2010
|
-
return e && Object.entries(e).forEach(([n, s]) => i.setAttribute(n, s)), t && t.appendChild(i), i;
|
|
2011
|
-
};
|
|
2012
|
-
function G(r) {
|
|
2013
|
-
const { onlyCountries: e, excludeCountries: t } = r;
|
|
2014
|
-
if (e.length) {
|
|
2015
|
-
const i = e.map((n) => n.toLowerCase());
|
|
2016
|
-
return _.filter((n) => i.includes(n.iso2));
|
|
2017
|
-
} else if (t.length) {
|
|
2018
|
-
const i = t.map((n) => n.toLowerCase());
|
|
2019
|
-
return _.filter((n) => !i.includes(n.iso2));
|
|
2020
|
-
}
|
|
2021
|
-
return _;
|
|
2022
|
-
}
|
|
2023
|
-
function q(r, e) {
|
|
2024
|
-
for (const t of r) {
|
|
2025
|
-
const i = t.iso2.toLowerCase();
|
|
2026
|
-
e.i18n[i] && (t.name = e.i18n[i]);
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
function Y(r, e) {
|
|
2030
|
-
const t = /* @__PURE__ */ new Set();
|
|
2031
|
-
let i = 0;
|
|
2032
|
-
const n = {}, s = (o, a, d) => {
|
|
2033
|
-
if (!o || !a)
|
|
2034
|
-
return;
|
|
2035
|
-
a.length > i && (i = a.length), n.hasOwnProperty(a) || (n[a] = []);
|
|
2036
|
-
const l = n[a];
|
|
2037
|
-
if (l.includes(o))
|
|
2038
|
-
return;
|
|
2039
|
-
const h = d !== void 0 ? d : l.length;
|
|
2040
|
-
l[h] = o;
|
|
2041
|
-
};
|
|
2042
|
-
for (const o of r) {
|
|
2043
|
-
t.has(o.dialCode) || t.add(o.dialCode);
|
|
2044
|
-
for (let a = 1; a < o.dialCode.length; a++) {
|
|
2045
|
-
const d = o.dialCode.substring(0, a);
|
|
2046
|
-
s(o.iso2, d);
|
|
2047
|
-
}
|
|
2048
|
-
s(o.iso2, o.dialCode, o.priority);
|
|
2049
|
-
}
|
|
2050
|
-
(e.onlyCountries.length || e.excludeCountries.length) && t.forEach((o) => {
|
|
2051
|
-
n[o] = n[o].filter(Boolean);
|
|
2052
|
-
});
|
|
2053
|
-
for (const o of r)
|
|
2054
|
-
if (o.areaCodes) {
|
|
2055
|
-
const a = n[o.dialCode][0];
|
|
2056
|
-
for (const d of o.areaCodes) {
|
|
2057
|
-
for (let l = 1; l < d.length; l++) {
|
|
2058
|
-
const h = d.substring(0, l), p = o.dialCode + h;
|
|
2059
|
-
s(a, p), s(o.iso2, p);
|
|
2060
|
-
}
|
|
2061
|
-
s(o.iso2, o.dialCode + d);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
return { dialCodes: t, dialCodeMaxLen: i, dialCodeToIso2Map: n };
|
|
2065
|
-
}
|
|
2066
|
-
function J(r, e) {
|
|
2067
|
-
e.countryOrder && (e.countryOrder = e.countryOrder.map((t) => t.toLowerCase())), r.sort((t, i) => {
|
|
2068
|
-
const { countryOrder: n } = e;
|
|
2069
|
-
if (n) {
|
|
2070
|
-
const s = n.indexOf(t.iso2), o = n.indexOf(i.iso2), a = s > -1, d = o > -1;
|
|
2071
|
-
if (a || d)
|
|
2072
|
-
return a && d ? s - o : a ? -1 : 1;
|
|
2073
|
-
}
|
|
2074
|
-
return t.name.localeCompare(i.name);
|
|
2075
|
-
});
|
|
2076
|
-
}
|
|
2077
|
-
function Z(r) {
|
|
2078
|
-
for (const e of r)
|
|
2079
|
-
e.normalisedName = E(e.name), e.initials = e.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((t) => t[0]).join("").toLowerCase(), e.dialCodePlus = `+${e.dialCode}`;
|
|
2080
|
-
}
|
|
2081
|
-
function Q(r, e, t, i) {
|
|
2082
|
-
let n = r;
|
|
2083
|
-
if (t && e) {
|
|
2084
|
-
e = `+${i.dialCode}`;
|
|
2085
|
-
const s = n[e.length] === " " || n[e.length] === "-" ? e.length + 1 : e.length;
|
|
2086
|
-
n = n.substring(s);
|
|
2087
|
-
}
|
|
2088
|
-
return n;
|
|
2089
|
-
}
|
|
2090
|
-
function X(r, e, t, i, n) {
|
|
2091
|
-
const s = t ? t.formatNumberAsYouType(r, i.iso2) : r, { dialCode: o } = i;
|
|
2092
|
-
return n && e.charAt(0) !== "+" && s.includes(`+${o}`) ? (s.split(`+${o}`)[1] || "").trim() : s;
|
|
2093
|
-
}
|
|
2094
|
-
function tt(r, e, t, i) {
|
|
2095
|
-
if (t === 0 && !i)
|
|
2096
|
-
return 0;
|
|
2097
|
-
let n = 0;
|
|
2098
|
-
for (let s = 0; s < e.length; s++) {
|
|
2099
|
-
if (/[+0-9]/.test(e[s]) && n++, n === r && !i)
|
|
2100
|
-
return s + 1;
|
|
2101
|
-
if (i && n === r + 1)
|
|
2102
|
-
return s;
|
|
2103
|
-
}
|
|
2104
|
-
return e.length;
|
|
2105
|
-
}
|
|
2106
|
-
const et = [
|
|
2107
|
-
"800",
|
|
2108
|
-
"822",
|
|
2109
|
-
"833",
|
|
2110
|
-
"844",
|
|
2111
|
-
"855",
|
|
2112
|
-
"866",
|
|
2113
|
-
"877",
|
|
2114
|
-
"880",
|
|
2115
|
-
"881",
|
|
2116
|
-
"882",
|
|
2117
|
-
"883",
|
|
2118
|
-
"884",
|
|
2119
|
-
"885",
|
|
2120
|
-
"886",
|
|
2121
|
-
"887",
|
|
2122
|
-
"888",
|
|
2123
|
-
"889"
|
|
2124
|
-
], k = (r) => {
|
|
2125
|
-
const e = I(r);
|
|
2126
|
-
if (e.charAt(0) === "1") {
|
|
2127
|
-
const t = e.substring(1, 4);
|
|
2128
|
-
return et.includes(t);
|
|
2129
|
-
}
|
|
2130
|
-
return !1;
|
|
2131
|
-
};
|
|
2132
|
-
for (const r of _)
|
|
2133
|
-
r.name = P[r.iso2];
|
|
2134
|
-
let it = 0;
|
|
2135
|
-
const nt = new Set(_.map((r) => r.iso2)), S = (r) => nt.has(r), v = (r, ...e) => {
|
|
2136
|
-
const { instances: t } = u;
|
|
2137
|
-
Object.values(t).forEach((i) => i[r](...e));
|
|
2138
|
-
};
|
|
2139
|
-
class L {
|
|
2140
|
-
/**
|
|
2141
|
-
* Build a space-delimited class string from an object map of className -> truthy/falsey.
|
|
2142
|
-
* Only keys with truthy values are included.
|
|
2143
|
-
*/
|
|
2144
|
-
static _buildClassNames(e) {
|
|
2145
|
-
return Object.keys(e).filter((t) => !!e[t]).join(" ");
|
|
2146
|
-
}
|
|
2147
|
-
constructor(e, t = {}) {
|
|
2148
|
-
this.id = it++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, x, t), this.hadInitialPlaceholder = !!e.getAttribute("placeholder");
|
|
2149
|
-
}
|
|
2150
|
-
_detectEnvironmentAndLayout() {
|
|
2151
|
-
this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.options.separateDialCode && (this.originalPaddingLeft = this.telInput.style.paddingLeft);
|
|
2152
|
-
}
|
|
2153
|
-
_createInitPromises() {
|
|
2154
|
-
const e = new Promise((i, n) => {
|
|
2155
|
-
this.resolveAutoCountryPromise = i, this.rejectAutoCountryPromise = n;
|
|
2156
|
-
}), t = new Promise((i, n) => {
|
|
2157
|
-
this.resolveUtilsScriptPromise = i, this.rejectUtilsScriptPromise = n;
|
|
2158
|
-
});
|
|
2159
|
-
this.promise = Promise.all([e, t]);
|
|
2160
|
-
}
|
|
2161
|
-
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
2162
|
-
_init() {
|
|
2163
|
-
W(this.options), this._detectEnvironmentAndLayout(), this._createInitPromises(), this.selectedCountryData = {}, this._processCountryData(), this._generateMarkup(), this._setInitialState(), this._initListeners(), this._initRequests();
|
|
2164
|
-
}
|
|
2165
|
-
//********************
|
|
2166
|
-
//* PRIVATE METHODS
|
|
2167
|
-
//********************
|
|
2168
|
-
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
2169
|
-
_processCountryData() {
|
|
2170
|
-
this.countries = G(this.options);
|
|
2171
|
-
const e = Y(this.countries, this.options);
|
|
2172
|
-
this.dialCodes = e.dialCodes, this.dialCodeMaxLen = e.dialCodeMaxLen, this.dialCodeToIso2Map = e.dialCodeToIso2Map, q(this.countries, this.options), J(this.countries, this.options), this.countryByIso2 = new Map(this.countries.map((t) => [t.iso2, t])), Z(this.countries);
|
|
2127
|
+
class Ct {
|
|
2128
|
+
constructor(t, e, i) {
|
|
2129
|
+
this.highlightedItem = null, t.dataset.intlTelInputId = i.toString(), this.telInput = t, this.options = e, this.id = i, this.hadInitialPlaceholder = !!t.getAttribute("placeholder"), this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.options.separateDialCode && (this.originalPaddingLeft = this.telInput.style.paddingLeft);
|
|
2173
2130
|
}
|
|
2174
2131
|
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
|
|
2175
|
-
|
|
2176
|
-
this._prepareTelInput();
|
|
2132
|
+
generateMarkup(t) {
|
|
2133
|
+
this.countries = t, this._prepareTelInput();
|
|
2177
2134
|
const e = this._createWrapperAndInsert();
|
|
2178
2135
|
this._maybeBuildCountryContainer(e), e.appendChild(this.telInput), this._maybeUpdateInputPaddingAndReveal(), this._maybeBuildHiddenInputs(e);
|
|
2179
2136
|
}
|
|
2180
2137
|
_prepareTelInput() {
|
|
2181
|
-
|
|
2138
|
+
var t;
|
|
2139
|
+
this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !((t = this.telInput.form) != null && t.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off");
|
|
2182
2140
|
}
|
|
2183
2141
|
_createWrapperAndInsert() {
|
|
2184
|
-
|
|
2185
|
-
const {
|
|
2186
|
-
allowDropdown: e,
|
|
2187
|
-
showFlags: t,
|
|
2188
|
-
containerClass: i,
|
|
2189
|
-
useFullscreenPopup: n
|
|
2190
|
-
} = this.options, s = L._buildClassNames({
|
|
2142
|
+
const { allowDropdown: t, showFlags: e, containerClass: i, useFullscreenPopup: s } = this.options, o = k({
|
|
2191
2143
|
iti: !0,
|
|
2192
|
-
"iti--allow-dropdown":
|
|
2193
|
-
"iti--show-flags":
|
|
2194
|
-
"iti--inline-dropdown": !
|
|
2144
|
+
"iti--allow-dropdown": t,
|
|
2145
|
+
"iti--show-flags": e,
|
|
2146
|
+
"iti--inline-dropdown": !s,
|
|
2195
2147
|
[i]: !!i
|
|
2196
|
-
}),
|
|
2197
|
-
return this.isRTL &&
|
|
2148
|
+
}), n = m("div", { class: o });
|
|
2149
|
+
return this.isRTL && n.setAttribute("dir", "ltr"), this.telInput.before(n), n;
|
|
2198
2150
|
}
|
|
2199
|
-
_maybeBuildCountryContainer(
|
|
2200
|
-
const {
|
|
2201
|
-
|
|
2202
|
-
separateDialCode: i,
|
|
2203
|
-
showFlags: n
|
|
2204
|
-
} = this.options;
|
|
2205
|
-
if (t || n || i) {
|
|
2151
|
+
_maybeBuildCountryContainer(t) {
|
|
2152
|
+
const { allowDropdown: e, separateDialCode: i, showFlags: s } = this.options;
|
|
2153
|
+
if (e || s || i) {
|
|
2206
2154
|
this.countryContainer = m(
|
|
2207
2155
|
"div",
|
|
2208
2156
|
// visibly hidden until we measure it's width to set the input padding correctly
|
|
2209
|
-
{ class:
|
|
2210
|
-
|
|
2211
|
-
),
|
|
2157
|
+
{ class: `iti__country-container ${h.V_HIDE}` },
|
|
2158
|
+
t
|
|
2159
|
+
), e ? (this.selectedCountry = m(
|
|
2212
2160
|
"button",
|
|
2213
2161
|
{
|
|
2214
2162
|
type: "button",
|
|
2215
2163
|
class: "iti__selected-country",
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2164
|
+
[C.EXPANDED]: "false",
|
|
2165
|
+
[C.LABEL]: this.options.i18n.noCountrySelected,
|
|
2166
|
+
[C.HASPOPUP]: "dialog",
|
|
2167
|
+
[C.CONTROLS]: `iti-${this.id}__dropdown-content`
|
|
2220
2168
|
},
|
|
2221
2169
|
this.countryContainer
|
|
2222
2170
|
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = m(
|
|
@@ -2224,63 +2172,63 @@ class L {
|
|
|
2224
2172
|
{ class: "iti__selected-country" },
|
|
2225
2173
|
this.countryContainer
|
|
2226
2174
|
);
|
|
2227
|
-
const
|
|
2175
|
+
const o = m(
|
|
2228
2176
|
"div",
|
|
2229
2177
|
{ class: "iti__selected-country-primary" },
|
|
2230
2178
|
this.selectedCountry
|
|
2231
2179
|
);
|
|
2232
2180
|
this.selectedCountryInner = m(
|
|
2233
2181
|
"div",
|
|
2234
|
-
{ class:
|
|
2235
|
-
|
|
2236
|
-
),
|
|
2182
|
+
{ class: h.FLAG },
|
|
2183
|
+
o
|
|
2184
|
+
), e && (this.dropdownArrow = m(
|
|
2237
2185
|
"div",
|
|
2238
|
-
{ class: "iti__arrow",
|
|
2239
|
-
|
|
2186
|
+
{ class: "iti__arrow", [C.HIDDEN]: "true" },
|
|
2187
|
+
o
|
|
2240
2188
|
)), i && (this.selectedDialCode = m(
|
|
2241
2189
|
"div",
|
|
2242
2190
|
{ class: "iti__selected-dial-code" },
|
|
2243
2191
|
this.selectedCountry
|
|
2244
|
-
)),
|
|
2192
|
+
)), e && this._buildDropdownContent();
|
|
2245
2193
|
}
|
|
2246
2194
|
}
|
|
2247
2195
|
_buildDropdownContent() {
|
|
2248
2196
|
const {
|
|
2249
|
-
fixDropdownWidth:
|
|
2250
|
-
useFullscreenPopup:
|
|
2197
|
+
fixDropdownWidth: t,
|
|
2198
|
+
useFullscreenPopup: e,
|
|
2251
2199
|
countrySearch: i,
|
|
2252
|
-
i18n:
|
|
2253
|
-
dropdownContainer:
|
|
2254
|
-
containerClass:
|
|
2255
|
-
} = this.options,
|
|
2200
|
+
i18n: s,
|
|
2201
|
+
dropdownContainer: o,
|
|
2202
|
+
containerClass: n
|
|
2203
|
+
} = this.options, r = t ? "" : "iti--flexible-dropdown-width";
|
|
2256
2204
|
if (this.dropdownContent = m("div", {
|
|
2257
2205
|
id: `iti-${this.id}__dropdown-content`,
|
|
2258
|
-
class: `iti__dropdown-content
|
|
2206
|
+
class: `iti__dropdown-content ${h.HIDE} ${r}`,
|
|
2259
2207
|
role: "dialog",
|
|
2260
|
-
|
|
2208
|
+
[C.MODAL]: "true"
|
|
2261
2209
|
}), this.isRTL && this.dropdownContent.setAttribute("dir", "rtl"), i && this._buildSearchUI(), this.countryList = m(
|
|
2262
2210
|
"ul",
|
|
2263
2211
|
{
|
|
2264
2212
|
class: "iti__country-list",
|
|
2265
2213
|
id: `iti-${this.id}__country-listbox`,
|
|
2266
2214
|
role: "listbox",
|
|
2267
|
-
|
|
2215
|
+
[C.LABEL]: s.countryListAriaLabel
|
|
2268
2216
|
},
|
|
2269
2217
|
this.dropdownContent
|
|
2270
|
-
), this._appendListItems(), i && this.
|
|
2271
|
-
const
|
|
2218
|
+
), this._appendListItems(), i && this.updateSearchResultsA11yText(), o) {
|
|
2219
|
+
const a = k({
|
|
2272
2220
|
iti: !0,
|
|
2273
2221
|
"iti--container": !0,
|
|
2274
|
-
"iti--fullscreen-popup":
|
|
2275
|
-
"iti--inline-dropdown": !
|
|
2276
|
-
[
|
|
2222
|
+
"iti--fullscreen-popup": e,
|
|
2223
|
+
"iti--inline-dropdown": !e,
|
|
2224
|
+
[n]: !!n
|
|
2277
2225
|
});
|
|
2278
|
-
this.dropdown = m("div", { class:
|
|
2226
|
+
this.dropdown = m("div", { class: a }), this.dropdown.appendChild(this.dropdownContent);
|
|
2279
2227
|
} else
|
|
2280
2228
|
this.countryContainer.appendChild(this.dropdownContent);
|
|
2281
2229
|
}
|
|
2282
2230
|
_buildSearchUI() {
|
|
2283
|
-
const { i18n:
|
|
2231
|
+
const { i18n: t } = this.options, e = m(
|
|
2284
2232
|
"div",
|
|
2285
2233
|
{ class: "iti__search-input-wrapper" },
|
|
2286
2234
|
this.dropdownContent
|
|
@@ -2289,574 +2237,852 @@ class L {
|
|
|
2289
2237
|
"span",
|
|
2290
2238
|
{
|
|
2291
2239
|
class: "iti__search-icon",
|
|
2292
|
-
|
|
2240
|
+
[C.HIDDEN]: "true"
|
|
2293
2241
|
},
|
|
2294
|
-
|
|
2295
|
-
), this.searchIcon.innerHTML =
|
|
2296
|
-
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
|
|
2297
|
-
<circle cx="11" cy="11" r="7" />
|
|
2298
|
-
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
2299
|
-
</svg>`, this.searchInput = m(
|
|
2242
|
+
e
|
|
2243
|
+
), this.searchIcon.innerHTML = ht(), this.searchInput = m(
|
|
2300
2244
|
"input",
|
|
2301
2245
|
{
|
|
2302
2246
|
id: `iti-${this.id}__search-input`,
|
|
2303
2247
|
// Chrome says inputs need either a name or an id
|
|
2304
2248
|
type: "search",
|
|
2305
2249
|
class: "iti__search-input",
|
|
2306
|
-
placeholder:
|
|
2250
|
+
placeholder: t.searchPlaceholder,
|
|
2307
2251
|
// role=combobox + aria-autocomplete=list + aria-activedescendant allows maintaining focus on the search input while allowing users to navigate search results with up/down keyboard keys
|
|
2308
2252
|
role: "combobox",
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2253
|
+
[C.EXPANDED]: "true",
|
|
2254
|
+
[C.LABEL]: t.searchPlaceholder,
|
|
2255
|
+
[C.CONTROLS]: `iti-${this.id}__country-listbox`,
|
|
2256
|
+
[C.AUTOCOMPLETE]: "list",
|
|
2313
2257
|
autocomplete: "off"
|
|
2314
2258
|
},
|
|
2315
|
-
|
|
2259
|
+
e
|
|
2316
2260
|
), this.searchClearButton = m(
|
|
2317
2261
|
"button",
|
|
2318
2262
|
{
|
|
2319
2263
|
type: "button",
|
|
2320
|
-
class:
|
|
2321
|
-
|
|
2264
|
+
class: `iti__search-clear ${h.HIDE}`,
|
|
2265
|
+
[C.LABEL]: t.clearSearchAriaLabel,
|
|
2322
2266
|
tabindex: "-1"
|
|
2323
2267
|
},
|
|
2324
|
-
|
|
2325
|
-
)
|
|
2326
|
-
const i = `iti-${this.id}-clear-mask`;
|
|
2327
|
-
this.searchClearButton.innerHTML = `
|
|
2328
|
-
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
|
2329
|
-
<mask id="${i}" maskUnits="userSpaceOnUse">
|
|
2330
|
-
<rect width="16" height="16" fill="white" />
|
|
2331
|
-
<path d="M5.2 5.2 L10.8 10.8 M10.8 5.2 L5.2 10.8" stroke="black" stroke-linecap="round" class="iti__search-clear-x" />
|
|
2332
|
-
</mask>
|
|
2333
|
-
<circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${i})" />
|
|
2334
|
-
</svg>`, this.searchResultsA11yText = m(
|
|
2268
|
+
e
|
|
2269
|
+
), this.searchClearButton.innerHTML = pt(this.id), this.searchResultsA11yText = m(
|
|
2335
2270
|
"span",
|
|
2336
2271
|
{ class: "iti__a11y-text" },
|
|
2337
2272
|
this.dropdownContent
|
|
2338
2273
|
), this.searchNoResults = m(
|
|
2339
2274
|
"div",
|
|
2340
2275
|
{
|
|
2341
|
-
class:
|
|
2342
|
-
|
|
2276
|
+
class: `iti__no-results ${h.HIDE}`,
|
|
2277
|
+
[C.HIDDEN]: "true"
|
|
2343
2278
|
// all a11y messaging happens in this.searchResultsA11yText
|
|
2344
2279
|
},
|
|
2345
2280
|
this.dropdownContent
|
|
2346
|
-
), this.searchNoResults.textContent =
|
|
2281
|
+
), this.searchNoResults.textContent = t.zeroSearchResults;
|
|
2347
2282
|
}
|
|
2348
2283
|
_maybeUpdateInputPaddingAndReveal() {
|
|
2349
|
-
this.countryContainer && (this.
|
|
2350
|
-
}
|
|
2351
|
-
_maybeBuildHiddenInputs(
|
|
2352
|
-
var i,
|
|
2353
|
-
const { hiddenInput:
|
|
2354
|
-
if (
|
|
2355
|
-
const
|
|
2356
|
-
if (
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2284
|
+
this.countryContainer && (this.updateInputPadding(), this.countryContainer.classList.remove(h.V_HIDE));
|
|
2285
|
+
}
|
|
2286
|
+
_maybeBuildHiddenInputs(t) {
|
|
2287
|
+
var i, s;
|
|
2288
|
+
const { hiddenInput: e } = this.options;
|
|
2289
|
+
if (e) {
|
|
2290
|
+
const o = this.telInput.getAttribute("name") || "", n = e(o);
|
|
2291
|
+
if (n.phone) {
|
|
2292
|
+
const r = (i = this.telInput.form) == null ? void 0 : i.querySelector(
|
|
2293
|
+
`input[name="${n.phone}"]`
|
|
2294
|
+
);
|
|
2295
|
+
r ? this.hiddenInput = r : (this.hiddenInput = m("input", {
|
|
2359
2296
|
type: "hidden",
|
|
2360
|
-
name:
|
|
2361
|
-
}),
|
|
2297
|
+
name: n.phone
|
|
2298
|
+
}), t.appendChild(this.hiddenInput));
|
|
2362
2299
|
}
|
|
2363
|
-
if (
|
|
2364
|
-
const
|
|
2365
|
-
|
|
2300
|
+
if (n.country) {
|
|
2301
|
+
const r = (s = this.telInput.form) == null ? void 0 : s.querySelector(
|
|
2302
|
+
`input[name="${n.country}"]`
|
|
2303
|
+
);
|
|
2304
|
+
r ? this.hiddenInputCountry = r : (this.hiddenInputCountry = m("input", {
|
|
2366
2305
|
type: "hidden",
|
|
2367
|
-
name:
|
|
2368
|
-
}),
|
|
2306
|
+
name: n.country
|
|
2307
|
+
}), t.appendChild(this.hiddenInputCountry));
|
|
2369
2308
|
}
|
|
2370
2309
|
}
|
|
2371
2310
|
}
|
|
2372
2311
|
//* For each country: add a country list item <li> to the countryList <ul> container.
|
|
2373
2312
|
_appendListItems() {
|
|
2313
|
+
const t = document.createDocumentFragment();
|
|
2374
2314
|
for (let e = 0; e < this.countries.length; e++) {
|
|
2375
|
-
const
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2315
|
+
const i = this.countries[e], s = k({
|
|
2316
|
+
[h.COUNTRY_ITEM]: !0,
|
|
2317
|
+
[h.HIGHLIGHT]: e === 0
|
|
2318
|
+
}), o = m("li", {
|
|
2319
|
+
id: `iti-${this.id}__item-${i.iso2}`,
|
|
2320
|
+
class: s,
|
|
2321
|
+
tabindex: "-1",
|
|
2322
|
+
role: "option",
|
|
2323
|
+
[C.SELECTED]: "false"
|
|
2324
|
+
});
|
|
2325
|
+
o.dataset.dialCode = i.dialCode, o.dataset.countryCode = i.iso2, i.nodeById[this.id] = o, this.options.showFlags && m("div", { class: `${h.FLAG} iti__${i.iso2}` }, o);
|
|
2326
|
+
const n = m("span", { class: "iti__country-name" }, o);
|
|
2327
|
+
n.textContent = i.name;
|
|
2328
|
+
const r = m("span", { class: "iti__dial-code" }, o);
|
|
2329
|
+
this.isRTL && r.setAttribute("dir", "ltr"), r.textContent = `+${i.dialCode}`, t.appendChild(o);
|
|
2330
|
+
}
|
|
2331
|
+
this.countryList.appendChild(t);
|
|
2332
|
+
}
|
|
2333
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2334
|
+
updateInputPadding() {
|
|
2335
|
+
if (this.selectedCountry) {
|
|
2336
|
+
const t = this.options.separateDialCode ? S.SANE_SELECTED_WITH_DIAL_WIDTH : S.SANE_SELECTED_NO_DIAL_WIDTH, i = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || t) + S.INPUT_PADDING_EXTRA_LEFT;
|
|
2337
|
+
this.telInput.style.paddingLeft = `${i}px`;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
//* When input is in a hidden container during init, we cannot calculate the selected country width.
|
|
2341
|
+
//* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
|
|
2342
|
+
//* To get the right styling to apply, all we need is a shallow clone of the container,
|
|
2343
|
+
//* and then to inject a deep clone of the selectedCountry element.
|
|
2344
|
+
_getHiddenSelectedCountryWidth() {
|
|
2345
|
+
if (this.telInput.parentNode) {
|
|
2346
|
+
let t;
|
|
2347
|
+
try {
|
|
2348
|
+
t = window.top.document.body;
|
|
2349
|
+
} catch {
|
|
2350
|
+
t = document.body;
|
|
2351
|
+
}
|
|
2352
|
+
const e = this.telInput.parentNode.cloneNode(
|
|
2353
|
+
!1
|
|
2387
2354
|
);
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2355
|
+
e.style.visibility = "hidden", t.appendChild(e);
|
|
2356
|
+
const i = this.countryContainer.cloneNode();
|
|
2357
|
+
e.appendChild(i);
|
|
2358
|
+
const s = this.selectedCountry.cloneNode(
|
|
2359
|
+
!0
|
|
2360
|
+
);
|
|
2361
|
+
i.appendChild(s);
|
|
2362
|
+
const o = s.offsetWidth;
|
|
2363
|
+
return t.removeChild(e), o;
|
|
2364
|
+
}
|
|
2365
|
+
return 0;
|
|
2366
|
+
}
|
|
2367
|
+
//* Update search results text (for a11y).
|
|
2368
|
+
updateSearchResultsA11yText() {
|
|
2369
|
+
const { i18n: t } = this.options, e = this.countryList.childElementCount;
|
|
2370
|
+
let i;
|
|
2371
|
+
e === 0 ? i = t.zeroSearchResults : t.searchResultsText ? i = t.searchResultsText(e) : e === 1 ? i = t.oneSearchResult : i = t.multipleSearchResults.replace(
|
|
2372
|
+
"${count}",
|
|
2373
|
+
e.toString()
|
|
2374
|
+
), this.searchResultsA11yText.textContent = i;
|
|
2375
|
+
}
|
|
2376
|
+
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2377
|
+
scrollTo(t) {
|
|
2378
|
+
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, o = e.getBoundingClientRect().top + i, n = o + s, r = t.offsetHeight, a = t.getBoundingClientRect().top + i, d = a + r, c = a - o + e.scrollTop;
|
|
2379
|
+
if (a < o)
|
|
2380
|
+
e.scrollTop = c;
|
|
2381
|
+
else if (d > n) {
|
|
2382
|
+
const f = s - r;
|
|
2383
|
+
e.scrollTop = c - f;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
//* Remove highlighting from other list items and highlight the given item.
|
|
2387
|
+
highlightListItem(t, e) {
|
|
2388
|
+
const i = this.highlightedItem;
|
|
2389
|
+
if (i && (i.classList.remove(h.HIGHLIGHT), i.setAttribute(C.SELECTED, "false")), this.highlightedItem = t, this.highlightedItem && (this.highlightedItem.classList.add(h.HIGHLIGHT), this.highlightedItem.setAttribute(C.SELECTED, "true"), this.options.countrySearch)) {
|
|
2390
|
+
const s = this.highlightedItem.getAttribute("id") || "";
|
|
2391
|
+
this.searchInput.setAttribute(C.ACTIVE_DESCENDANT, s);
|
|
2391
2392
|
}
|
|
2393
|
+
e && this.highlightedItem.focus();
|
|
2394
|
+
}
|
|
2395
|
+
//* Country search: Filter the country list to the given array of countries.
|
|
2396
|
+
filterCountries(t) {
|
|
2397
|
+
this.countryList.innerHTML = "";
|
|
2398
|
+
let e = !0;
|
|
2399
|
+
for (const i of t) {
|
|
2400
|
+
const s = i.nodeById[this.id];
|
|
2401
|
+
s && (this.countryList.appendChild(s), e && (this.highlightListItem(s, !1), e = !1));
|
|
2402
|
+
}
|
|
2403
|
+
e ? (this.highlightListItem(null, !1), this.searchNoResults && this.searchNoResults.classList.remove(h.HIDE)) : this.searchNoResults && this.searchNoResults.classList.add(h.HIDE), this.countryList.scrollTop = 0, this.updateSearchResultsA11yText();
|
|
2404
|
+
}
|
|
2405
|
+
destroy() {
|
|
2406
|
+
this.telInput.iti = void 0, delete this.telInput.dataset.intlTelInputId, this.options.separateDialCode && (this.telInput.style.paddingLeft = this.originalPaddingLeft);
|
|
2407
|
+
const t = this.telInput.parentNode;
|
|
2408
|
+
t.before(this.telInput), t.remove(), this.telInput = null, this.countryContainer = null, this.selectedCountry = null, this.selectedCountryInner = null, this.selectedDialCode = null, this.dropdownArrow = null, this.dropdownContent = null, this.searchInput = null, this.searchIcon = null, this.searchClearButton = null, this.searchNoResults = null, this.searchResultsA11yText = null, this.countryList = null, this.dropdown = null, this.hiddenInput = null, this.hiddenInputCountry = null, this.highlightedItem = null;
|
|
2409
|
+
for (const e of this.countries)
|
|
2410
|
+
delete e.nodeById[this.id];
|
|
2411
|
+
this.countries = null;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
const mt = (l) => {
|
|
2415
|
+
const { onlyCountries: t, excludeCountries: e } = l;
|
|
2416
|
+
if (t.length) {
|
|
2417
|
+
const i = t.map(
|
|
2418
|
+
(s) => s.toLowerCase()
|
|
2419
|
+
);
|
|
2420
|
+
return L.filter(
|
|
2421
|
+
(s) => i.includes(s.iso2)
|
|
2422
|
+
);
|
|
2423
|
+
} else if (e.length) {
|
|
2424
|
+
const i = e.map(
|
|
2425
|
+
(s) => s.toLowerCase()
|
|
2426
|
+
);
|
|
2427
|
+
return L.filter(
|
|
2428
|
+
(s) => !i.includes(s.iso2)
|
|
2429
|
+
);
|
|
2430
|
+
}
|
|
2431
|
+
return L;
|
|
2432
|
+
}, ft = (l, t) => {
|
|
2433
|
+
for (const e of l) {
|
|
2434
|
+
const i = e.iso2.toLowerCase();
|
|
2435
|
+
t.i18n[i] && (e.name = t.i18n[i]);
|
|
2436
|
+
}
|
|
2437
|
+
}, yt = (l, t) => {
|
|
2438
|
+
const e = /* @__PURE__ */ new Set();
|
|
2439
|
+
let i = 0;
|
|
2440
|
+
const s = {}, o = (n, r, a) => {
|
|
2441
|
+
if (!n || !r)
|
|
2442
|
+
return;
|
|
2443
|
+
r.length > i && (i = r.length), s.hasOwnProperty(r) || (s[r] = []);
|
|
2444
|
+
const d = s[r];
|
|
2445
|
+
if (d.includes(n))
|
|
2446
|
+
return;
|
|
2447
|
+
const c = a !== void 0 ? a : d.length;
|
|
2448
|
+
d[c] = n;
|
|
2449
|
+
};
|
|
2450
|
+
for (const n of l) {
|
|
2451
|
+
e.has(n.dialCode) || e.add(n.dialCode);
|
|
2452
|
+
for (let r = 1; r < n.dialCode.length; r++) {
|
|
2453
|
+
const a = n.dialCode.substring(0, r);
|
|
2454
|
+
o(n.iso2, a);
|
|
2455
|
+
}
|
|
2456
|
+
o(n.iso2, n.dialCode, n.priority);
|
|
2457
|
+
}
|
|
2458
|
+
(t.onlyCountries.length || t.excludeCountries.length) && e.forEach((n) => {
|
|
2459
|
+
s[n] = s[n].filter(Boolean);
|
|
2460
|
+
});
|
|
2461
|
+
for (const n of l)
|
|
2462
|
+
if (n.areaCodes) {
|
|
2463
|
+
const r = s[n.dialCode][0];
|
|
2464
|
+
for (const a of n.areaCodes) {
|
|
2465
|
+
for (let d = 1; d < a.length; d++) {
|
|
2466
|
+
const c = a.substring(0, d), f = n.dialCode + c;
|
|
2467
|
+
o(r, f), o(n.iso2, f);
|
|
2468
|
+
}
|
|
2469
|
+
o(n.iso2, n.dialCode + a);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
return { dialCodes: e, dialCodeMaxLen: i, dialCodeToIso2Map: s };
|
|
2473
|
+
}, gt = (l, t) => {
|
|
2474
|
+
t.countryOrder && (t.countryOrder = t.countryOrder.map(
|
|
2475
|
+
(e) => e.toLowerCase()
|
|
2476
|
+
)), l.sort((e, i) => {
|
|
2477
|
+
const { countryOrder: s } = t;
|
|
2478
|
+
if (s) {
|
|
2479
|
+
const o = s.indexOf(e.iso2), n = s.indexOf(i.iso2), r = o > -1, a = n > -1;
|
|
2480
|
+
if (r || a)
|
|
2481
|
+
return r && a ? o - n : r ? -1 : 1;
|
|
2482
|
+
}
|
|
2483
|
+
return e.name.localeCompare(i.name);
|
|
2484
|
+
});
|
|
2485
|
+
}, bt = (l) => {
|
|
2486
|
+
for (const t of l)
|
|
2487
|
+
t.normalisedName = z(t.name), t.initials = t.normalisedName.split(/[^a-z]/).map((e) => e[0]).join(""), t.dialCodePlus = `+${t.dialCode}`;
|
|
2488
|
+
}, It = (l, t, e, i) => {
|
|
2489
|
+
let s = l;
|
|
2490
|
+
if (e && t) {
|
|
2491
|
+
t = `+${i.dialCode}`;
|
|
2492
|
+
const o = s[t.length] === " " || s[t.length] === "-" ? t.length + 1 : t.length;
|
|
2493
|
+
s = s.substring(o);
|
|
2494
|
+
}
|
|
2495
|
+
return s;
|
|
2496
|
+
}, _t = (l, t, e, i, s) => {
|
|
2497
|
+
const o = e ? e.formatNumberAsYouType(l, i.iso2) : l, { dialCode: n } = i;
|
|
2498
|
+
return s && t.charAt(0) !== "+" && o.includes(`+${n}`) ? (o.split(`+${n}`)[1] || "").trim() : o;
|
|
2499
|
+
}, wt = (l, t, e, i) => {
|
|
2500
|
+
if (e === 0 && !i)
|
|
2501
|
+
return 0;
|
|
2502
|
+
let s = 0;
|
|
2503
|
+
for (let o = 0; o < t.length; o++) {
|
|
2504
|
+
if (/[+0-9]/.test(t[o]) && s++, s === l && !i)
|
|
2505
|
+
return o + 1;
|
|
2506
|
+
if (i && s === l + 1)
|
|
2507
|
+
return o;
|
|
2508
|
+
}
|
|
2509
|
+
return t.length;
|
|
2510
|
+
}, Nt = [
|
|
2511
|
+
"800",
|
|
2512
|
+
"822",
|
|
2513
|
+
"833",
|
|
2514
|
+
"844",
|
|
2515
|
+
"855",
|
|
2516
|
+
"866",
|
|
2517
|
+
"877",
|
|
2518
|
+
"880",
|
|
2519
|
+
"881",
|
|
2520
|
+
"882",
|
|
2521
|
+
"883",
|
|
2522
|
+
"884",
|
|
2523
|
+
"885",
|
|
2524
|
+
"886",
|
|
2525
|
+
"887",
|
|
2526
|
+
"888",
|
|
2527
|
+
"889"
|
|
2528
|
+
], F = (l) => {
|
|
2529
|
+
const t = v(l);
|
|
2530
|
+
if (t.startsWith($.NANP) && t.length >= 4) {
|
|
2531
|
+
const e = t.substring(1, 4);
|
|
2532
|
+
return Nt.includes(e);
|
|
2533
|
+
}
|
|
2534
|
+
return !1;
|
|
2535
|
+
};
|
|
2536
|
+
for (const l of L)
|
|
2537
|
+
l.name = V[l.iso2];
|
|
2538
|
+
let Dt = 0;
|
|
2539
|
+
const Lt = new Set(L.map((l) => l.iso2)), M = (l) => Lt.has(l);
|
|
2540
|
+
class x {
|
|
2541
|
+
constructor(t, e = {}) {
|
|
2542
|
+
this.id = Dt++, this.options = { ...G, ...e }, ut(this.options, V), this.ui = new Ct(t, this.options, this.id), this.isAndroid = x._getIsAndroid(), this.promise = this._createInitPromises(), this.countries = mt(this.options);
|
|
2543
|
+
const { dialCodes: i, dialCodeMaxLen: s, dialCodeToIso2Map: o } = yt(
|
|
2544
|
+
this.countries,
|
|
2545
|
+
this.options
|
|
2546
|
+
);
|
|
2547
|
+
this.dialCodes = i, this.dialCodeMaxLen = s, this.dialCodeToIso2Map = o, this.countryByIso2 = new Map(this.countries.map((n) => [n.iso2, n])), this._init();
|
|
2548
|
+
}
|
|
2549
|
+
static _getIsAndroid() {
|
|
2550
|
+
return typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1;
|
|
2551
|
+
}
|
|
2552
|
+
_createInitPromises() {
|
|
2553
|
+
const t = new Promise((i, s) => {
|
|
2554
|
+
this.resolveAutoCountryPromise = i, this.rejectAutoCountryPromise = s;
|
|
2555
|
+
}), e = new Promise((i, s) => {
|
|
2556
|
+
this.resolveUtilsScriptPromise = i, this.rejectUtilsScriptPromise = s;
|
|
2557
|
+
});
|
|
2558
|
+
return Promise.all([t, e]);
|
|
2559
|
+
}
|
|
2560
|
+
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
2561
|
+
_init() {
|
|
2562
|
+
this.selectedCountryData = {}, this.abortController = new AbortController(), this._processCountryData(), this.ui.generateMarkup(this.countries), this._setInitialState(), this._initListeners(), this._initRequests();
|
|
2563
|
+
}
|
|
2564
|
+
//********************
|
|
2565
|
+
//* PRIVATE METHODS
|
|
2566
|
+
//********************
|
|
2567
|
+
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
2568
|
+
_processCountryData() {
|
|
2569
|
+
ft(this.countries, this.options), gt(this.countries, this.options), bt(this.countries);
|
|
2392
2570
|
}
|
|
2393
2571
|
//* Set the initial state of the input value and the selected country by:
|
|
2394
2572
|
//* 1. Extracting a dial code from the given number
|
|
2395
2573
|
//* 2. Using explicit initialCountry
|
|
2396
|
-
_setInitialState(
|
|
2397
|
-
const
|
|
2398
|
-
if (
|
|
2399
|
-
this._updateCountryFromNumber(
|
|
2400
|
-
else if (!
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2574
|
+
_setInitialState(t = !1) {
|
|
2575
|
+
const e = this.ui.telInput.getAttribute("value"), i = this.ui.telInput.value, o = e && e.startsWith("+") && (!i || !i.startsWith("+")) ? e : i, n = this._getDialCode(o), r = F(o), { initialCountry: a, geoIpLookup: d } = this.options, c = a === O.AUTO && d;
|
|
2576
|
+
if (n && !r)
|
|
2577
|
+
this._updateCountryFromNumber(o);
|
|
2578
|
+
else if (!c || t) {
|
|
2579
|
+
const f = a ? a.toLowerCase() : "";
|
|
2580
|
+
M(f) ? this._setCountry(f) : n && r ? this._setCountry(lt.ISO2) : this._setCountry("");
|
|
2403
2581
|
}
|
|
2404
|
-
|
|
2582
|
+
o && this._updateValFromNumber(o);
|
|
2405
2583
|
}
|
|
2406
2584
|
//* Initialise the main event listeners: input keyup, and click selected country.
|
|
2407
2585
|
_initListeners() {
|
|
2408
|
-
this._initTelInputListeners(), this.options.allowDropdown && this._initDropdownListeners(), (this.hiddenInput || this.hiddenInputCountry) && this.telInput.form && this._initHiddenInputListener();
|
|
2586
|
+
this._initTelInputListeners(), this.options.allowDropdown && this._initDropdownListeners(), (this.ui.hiddenInput || this.ui.hiddenInputCountry) && this.ui.telInput.form && this._initHiddenInputListener();
|
|
2409
2587
|
}
|
|
2410
2588
|
//* Update hidden input on form submit.
|
|
2411
2589
|
_initHiddenInputListener() {
|
|
2412
2590
|
var e;
|
|
2413
|
-
|
|
2414
|
-
this.hiddenInput && (this.hiddenInput.value = this.getNumber()), this.hiddenInputCountry && (this.hiddenInputCountry.value = this.
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
this.
|
|
2418
|
-
);
|
|
2591
|
+
const t = () => {
|
|
2592
|
+
this.ui.hiddenInput && (this.ui.hiddenInput.value = this.getNumber()), this.ui.hiddenInputCountry && (this.ui.hiddenInputCountry.value = this.selectedCountryData.iso2 || "");
|
|
2593
|
+
};
|
|
2594
|
+
(e = this.ui.telInput.form) == null || e.addEventListener("submit", t, {
|
|
2595
|
+
signal: this.abortController.signal
|
|
2596
|
+
});
|
|
2419
2597
|
}
|
|
2420
2598
|
//* initialise the dropdown listeners.
|
|
2421
2599
|
_initDropdownListeners() {
|
|
2422
|
-
this.
|
|
2423
|
-
this.dropdownContent.classList.contains(
|
|
2600
|
+
const t = this.abortController.signal, e = (n) => {
|
|
2601
|
+
this.ui.dropdownContent.classList.contains(h.HIDE) ? this.ui.telInput.focus() : n.preventDefault();
|
|
2602
|
+
}, i = this.ui.telInput.closest("label");
|
|
2603
|
+
i && i.addEventListener("click", e, { signal: t });
|
|
2604
|
+
const s = () => {
|
|
2605
|
+
this.ui.dropdownContent.classList.contains(
|
|
2606
|
+
h.HIDE
|
|
2607
|
+
) && !this.ui.telInput.disabled && !this.ui.telInput.readOnly && this._openDropdown();
|
|
2424
2608
|
};
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2609
|
+
this.ui.selectedCountry.addEventListener(
|
|
2610
|
+
"click",
|
|
2611
|
+
s,
|
|
2612
|
+
{
|
|
2613
|
+
signal: t
|
|
2614
|
+
}
|
|
2615
|
+
);
|
|
2616
|
+
const o = (n) => {
|
|
2617
|
+
this.ui.dropdownContent.classList.contains(
|
|
2618
|
+
h.HIDE
|
|
2619
|
+
) && [g.ARROW_UP, g.ARROW_DOWN, g.SPACE, g.ENTER].includes(n.key) && (n.preventDefault(), n.stopPropagation(), this._openDropdown()), n.key === g.TAB && this._closeDropdown();
|
|
2620
|
+
};
|
|
2621
|
+
this.ui.countryContainer.addEventListener(
|
|
2431
2622
|
"keydown",
|
|
2432
|
-
|
|
2623
|
+
o,
|
|
2624
|
+
{ signal: t }
|
|
2433
2625
|
);
|
|
2434
2626
|
}
|
|
2435
2627
|
//* Init many requests: utils script / geo ip lookup.
|
|
2436
2628
|
_initRequests() {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2629
|
+
const { loadUtils: t, initialCountry: e, geoIpLookup: i } = this.options;
|
|
2630
|
+
if (t && !u.utils) {
|
|
2631
|
+
const o = () => {
|
|
2632
|
+
var n;
|
|
2633
|
+
(n = u.attachUtils(t)) == null || n.catch(() => {
|
|
2634
|
+
});
|
|
2635
|
+
};
|
|
2636
|
+
if (u.documentReady())
|
|
2637
|
+
o();
|
|
2638
|
+
else {
|
|
2639
|
+
const n = () => {
|
|
2640
|
+
o();
|
|
2641
|
+
};
|
|
2642
|
+
window.addEventListener("load", n, {
|
|
2643
|
+
signal: this.abortController.signal
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2646
|
+
} else
|
|
2647
|
+
this.resolveUtilsScriptPromise();
|
|
2648
|
+
e === O.AUTO && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
|
|
2445
2649
|
}
|
|
2446
2650
|
//* Perform the geo ip lookup.
|
|
2447
2651
|
_loadAutoCountry() {
|
|
2448
2652
|
u.autoCountry ? this.handleAutoCountry() : u.startedLoadingAutoCountry || (u.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(
|
|
2449
|
-
(
|
|
2450
|
-
const
|
|
2451
|
-
|
|
2653
|
+
(t = "") => {
|
|
2654
|
+
const e = t.toLowerCase();
|
|
2655
|
+
M(e) ? (u.autoCountry = e, setTimeout(() => E("handleAutoCountry"))) : (this._setInitialState(!0), E("rejectAutoCountryPromise"));
|
|
2452
2656
|
},
|
|
2453
2657
|
() => {
|
|
2454
|
-
this._setInitialState(!0),
|
|
2658
|
+
this._setInitialState(!0), E("rejectAutoCountryPromise");
|
|
2455
2659
|
}
|
|
2456
2660
|
));
|
|
2457
2661
|
}
|
|
2458
2662
|
_openDropdownWithPlus() {
|
|
2459
|
-
this._openDropdown(), this.searchInput.value = "+", this.
|
|
2663
|
+
this._openDropdown(), this.ui.searchInput.value = "+", this._filterCountriesByQuery("");
|
|
2460
2664
|
}
|
|
2461
2665
|
//* Initialize the tel input listeners.
|
|
2462
2666
|
_initTelInputListeners() {
|
|
2463
2667
|
this._bindInputListener(), this._maybeBindKeydownListener(), this._maybeBindPasteListener();
|
|
2464
2668
|
}
|
|
2465
2669
|
_bindInputListener() {
|
|
2466
|
-
const {
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2670
|
+
const {
|
|
2671
|
+
strictMode: t,
|
|
2672
|
+
formatAsYouType: e,
|
|
2673
|
+
separateDialCode: i,
|
|
2674
|
+
allowDropdown: s,
|
|
2675
|
+
countrySearch: o
|
|
2676
|
+
} = this.options;
|
|
2677
|
+
let n = !1;
|
|
2678
|
+
D.ALPHA_UNICODE.test(this.ui.telInput.value) && (n = !0);
|
|
2679
|
+
const r = (a) => {
|
|
2680
|
+
if (this.isAndroid && (a == null ? void 0 : a.data) === "+" && i && s && o) {
|
|
2681
|
+
const b = this.ui.telInput.selectionStart || 0, p = this.ui.telInput.value.substring(
|
|
2682
|
+
0,
|
|
2683
|
+
b - 1
|
|
2684
|
+
), y = this.ui.telInput.value.substring(b);
|
|
2685
|
+
this.ui.telInput.value = p + y, this._openDropdownWithPlus();
|
|
2472
2686
|
return;
|
|
2473
2687
|
}
|
|
2474
|
-
this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
|
|
2475
|
-
const d = (a == null ? void 0 : a.data) &&
|
|
2476
|
-
d ||
|
|
2477
|
-
const
|
|
2478
|
-
if (
|
|
2479
|
-
const
|
|
2480
|
-
|
|
2481
|
-
|
|
2688
|
+
this._updateCountryFromNumber(this.ui.telInput.value) && this._triggerCountryChange();
|
|
2689
|
+
const d = (a == null ? void 0 : a.data) && D.NON_PLUS_NUMERIC.test(a.data), c = (a == null ? void 0 : a.inputType) === B.PASTE && this.ui.telInput.value;
|
|
2690
|
+
d || c && !t ? n = !0 : D.NON_PLUS_NUMERIC.test(this.ui.telInput.value) || (n = !1);
|
|
2691
|
+
const f = (a == null ? void 0 : a.detail) && a.detail.isSetNumber;
|
|
2692
|
+
if (e && !n && !f) {
|
|
2693
|
+
const b = this.ui.telInput.selectionStart || 0, y = this.ui.telInput.value.substring(
|
|
2694
|
+
0,
|
|
2695
|
+
b
|
|
2696
|
+
).replace(
|
|
2697
|
+
D.NON_PLUS_NUMERIC_GLOBAL,
|
|
2698
|
+
""
|
|
2699
|
+
).length, w = (a == null ? void 0 : a.inputType) === B.DELETE_FWD, I = this._getFullNumber(), _ = _t(
|
|
2700
|
+
I,
|
|
2701
|
+
this.ui.telInput.value,
|
|
2482
2702
|
u.utils,
|
|
2483
2703
|
this.selectedCountryData,
|
|
2484
2704
|
this.options.separateDialCode
|
|
2485
|
-
),
|
|
2486
|
-
|
|
2705
|
+
), N = wt(
|
|
2706
|
+
y,
|
|
2707
|
+
_,
|
|
2708
|
+
b,
|
|
2709
|
+
w
|
|
2710
|
+
);
|
|
2711
|
+
this.ui.telInput.value = _, this.ui.telInput.setSelectionRange(N, N);
|
|
2487
2712
|
}
|
|
2488
|
-
}
|
|
2713
|
+
};
|
|
2714
|
+
this.ui.telInput.addEventListener(
|
|
2715
|
+
"input",
|
|
2716
|
+
r,
|
|
2717
|
+
{
|
|
2718
|
+
signal: this.abortController.signal
|
|
2719
|
+
}
|
|
2720
|
+
);
|
|
2489
2721
|
}
|
|
2490
2722
|
_maybeBindKeydownListener() {
|
|
2491
|
-
const { strictMode:
|
|
2492
|
-
(
|
|
2493
|
-
|
|
2494
|
-
if (
|
|
2495
|
-
s.
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2723
|
+
const { strictMode: t, separateDialCode: e, allowDropdown: i, countrySearch: s } = this.options;
|
|
2724
|
+
if (t || e) {
|
|
2725
|
+
const o = (n) => {
|
|
2726
|
+
if (n.key && n.key.length === 1 && !n.altKey && !n.ctrlKey && !n.metaKey) {
|
|
2727
|
+
if (e && i && s && n.key === "+") {
|
|
2728
|
+
n.preventDefault(), this._openDropdownWithPlus();
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
if (t) {
|
|
2732
|
+
const r = this.ui.telInput.value, d = !r.startsWith("+") && this.ui.telInput.selectionStart === 0 && n.key === "+", c = /^[0-9]$/.test(n.key), f = e ? c : d || c, b = r.slice(0, this.ui.telInput.selectionStart) + n.key + r.slice(this.ui.telInput.selectionEnd), p = this._getFullNumber(b), y = u.utils.getCoreNumber(
|
|
2733
|
+
p,
|
|
2734
|
+
this.selectedCountryData.iso2
|
|
2735
|
+
), w = this.maxCoreNumberLength && y.length > this.maxCoreNumberLength, _ = this._getNewCountryFromNumber(p) !== null;
|
|
2736
|
+
(!f || w && !_ && !d) && n.preventDefault();
|
|
2737
|
+
}
|
|
2501
2738
|
}
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2739
|
+
};
|
|
2740
|
+
this.ui.telInput.addEventListener("keydown", o, {
|
|
2741
|
+
signal: this.abortController.signal
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2504
2744
|
}
|
|
2505
2745
|
_maybeBindPasteListener() {
|
|
2506
|
-
this.options.strictMode
|
|
2507
|
-
e
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
if (this.maxCoreNumberLength && y.length > this.maxCoreNumberLength)
|
|
2515
|
-
if (t.selectionEnd === t.value.length) {
|
|
2516
|
-
const w = y.length - this.maxCoreNumberLength;
|
|
2517
|
-
C = C.slice(0, C.length - w);
|
|
2518
|
-
} else
|
|
2746
|
+
if (this.options.strictMode) {
|
|
2747
|
+
const t = (e) => {
|
|
2748
|
+
e.preventDefault();
|
|
2749
|
+
const i = this.ui.telInput, s = i.selectionStart, o = i.selectionEnd, n = i.value.slice(0, s), r = i.value.slice(o), a = this.selectedCountryData.iso2, d = e.clipboardData.getData("text"), c = s === 0 && o > 0, f = !i.value.startsWith("+") || c, b = d.replace(D.NON_PLUS_NUMERIC_GLOBAL, ""), p = b.startsWith("+"), y = b.replace(/\+/g, ""), w = p && f ? `+${y}` : y;
|
|
2750
|
+
let I = n + w + r, _ = u.utils.getCoreNumber(I, a);
|
|
2751
|
+
for (; _.length === 0 && I.length > 0; )
|
|
2752
|
+
I = I.slice(0, -1), _ = u.utils.getCoreNumber(I, a);
|
|
2753
|
+
if (!_)
|
|
2519
2754
|
return;
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2755
|
+
if (this.maxCoreNumberLength && _.length > this.maxCoreNumberLength)
|
|
2756
|
+
if (i.selectionEnd === i.value.length) {
|
|
2757
|
+
const j = _.length - this.maxCoreNumberLength;
|
|
2758
|
+
I = I.slice(0, I.length - j);
|
|
2759
|
+
} else
|
|
2760
|
+
return;
|
|
2761
|
+
i.value = I;
|
|
2762
|
+
const N = s + w.length;
|
|
2763
|
+
i.setSelectionRange(N, N), i.dispatchEvent(new InputEvent("input", { bubbles: !0 }));
|
|
2764
|
+
};
|
|
2765
|
+
this.ui.telInput.addEventListener("paste", t, {
|
|
2766
|
+
signal: this.abortController.signal
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2524
2769
|
}
|
|
2525
2770
|
//* Adhere to the input's maxlength attr.
|
|
2526
|
-
_cap(
|
|
2527
|
-
const
|
|
2528
|
-
return
|
|
2771
|
+
_cap(t) {
|
|
2772
|
+
const e = Number(this.ui.telInput.getAttribute("maxlength"));
|
|
2773
|
+
return e && t.length > e ? t.substring(0, e) : t;
|
|
2529
2774
|
}
|
|
2530
|
-
//* Trigger a custom event on the input.
|
|
2531
|
-
_trigger(
|
|
2532
|
-
const i = new CustomEvent(
|
|
2775
|
+
//* Trigger a custom event on the input (typed via ItiEventMap).
|
|
2776
|
+
_trigger(t, e = {}) {
|
|
2777
|
+
const i = new CustomEvent(t, {
|
|
2533
2778
|
bubbles: !0,
|
|
2534
2779
|
cancelable: !0,
|
|
2535
|
-
detail:
|
|
2780
|
+
detail: e
|
|
2536
2781
|
});
|
|
2537
|
-
this.telInput.dispatchEvent(i);
|
|
2782
|
+
this.ui.telInput.dispatchEvent(i);
|
|
2538
2783
|
}
|
|
2539
2784
|
//* Open the dropdown.
|
|
2540
2785
|
_openDropdown() {
|
|
2541
|
-
const { fixDropdownWidth:
|
|
2542
|
-
if (
|
|
2543
|
-
const i = this.countryList.firstElementChild;
|
|
2544
|
-
i && (this.
|
|
2786
|
+
const { fixDropdownWidth: t, countrySearch: e } = this.options;
|
|
2787
|
+
if (this.dropdownAbortController = new AbortController(), t && (this.ui.dropdownContent.style.width = `${this.ui.telInput.offsetWidth}px`), this.ui.dropdownContent.classList.remove(h.HIDE), this.ui.selectedCountry.setAttribute(C.EXPANDED, "true"), this._setDropdownPosition(), e) {
|
|
2788
|
+
const i = this.ui.countryList.firstElementChild;
|
|
2789
|
+
i && (this.ui.highlightListItem(i, !1), this.ui.countryList.scrollTop = 0), this.ui.searchInput.focus();
|
|
2545
2790
|
}
|
|
2546
|
-
this._bindDropdownListeners(), this.dropdownArrow.classList.add(
|
|
2791
|
+
this._bindDropdownListeners(), this.ui.dropdownArrow.classList.add(h.ARROW_UP), this._trigger(A.OPEN_COUNTRY_DROPDOWN);
|
|
2547
2792
|
}
|
|
2548
2793
|
//* Set the dropdown position
|
|
2549
2794
|
_setDropdownPosition() {
|
|
2550
|
-
if (this.options.dropdownContainer && this.options.dropdownContainer.appendChild(this.dropdown), !this.options.useFullscreenPopup) {
|
|
2551
|
-
const
|
|
2552
|
-
this.options.dropdownContainer
|
|
2795
|
+
if (this.options.dropdownContainer && this.options.dropdownContainer.appendChild(this.ui.dropdown), !this.options.useFullscreenPopup) {
|
|
2796
|
+
const t = this.ui.telInput.getBoundingClientRect(), e = this.ui.telInput.offsetHeight;
|
|
2797
|
+
if (this.options.dropdownContainer) {
|
|
2798
|
+
this.ui.dropdown.style.top = `${t.top + e}px`, this.ui.dropdown.style.left = `${t.left}px`;
|
|
2799
|
+
const i = () => this._closeDropdown();
|
|
2800
|
+
window.addEventListener("scroll", i, {
|
|
2801
|
+
signal: this.dropdownAbortController.signal
|
|
2802
|
+
});
|
|
2803
|
+
}
|
|
2553
2804
|
}
|
|
2554
2805
|
}
|
|
2555
2806
|
//* We only bind dropdown listeners when the dropdown is open.
|
|
2556
2807
|
_bindDropdownListeners() {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2808
|
+
const t = this.dropdownAbortController.signal;
|
|
2809
|
+
this._bindDropdownMouseoverListener(t), this._bindDropdownCountryClickListener(t), this._bindDropdownClickOffListener(t), this._bindDropdownKeydownListener(t), this.options.countrySearch && this._bindDropdownSearchListeners(t);
|
|
2810
|
+
}
|
|
2811
|
+
//* When mouse over a list item, just highlight that one
|
|
2812
|
+
//* we add the class "highlight", so if they hit "enter" we know which one to select.
|
|
2813
|
+
_bindDropdownMouseoverListener(t) {
|
|
2814
|
+
const e = (i) => {
|
|
2815
|
+
var o;
|
|
2816
|
+
const s = (o = i.target) == null ? void 0 : o.closest(
|
|
2817
|
+
`.${h.COUNTRY_ITEM}`
|
|
2818
|
+
);
|
|
2819
|
+
s && this.ui.highlightListItem(s, !1);
|
|
2820
|
+
};
|
|
2821
|
+
this.ui.countryList.addEventListener(
|
|
2562
2822
|
"mouseover",
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2823
|
+
e,
|
|
2824
|
+
{
|
|
2825
|
+
signal: t
|
|
2826
|
+
}
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
//* Listen for country selection.
|
|
2830
|
+
_bindDropdownCountryClickListener(t) {
|
|
2831
|
+
const e = (i) => {
|
|
2832
|
+
var o;
|
|
2833
|
+
const s = (o = i.target) == null ? void 0 : o.closest(
|
|
2834
|
+
`.${h.COUNTRY_ITEM}`
|
|
2835
|
+
);
|
|
2836
|
+
s && this._selectListItem(s);
|
|
2837
|
+
};
|
|
2838
|
+
this.ui.countryList.addEventListener("click", e, {
|
|
2839
|
+
signal: t
|
|
2840
|
+
});
|
|
2841
|
+
}
|
|
2842
|
+
//* Click off to close (except when this initial opening click is bubbling up).
|
|
2843
|
+
//* We cannot just stopPropagation as it may be needed to close another instance.
|
|
2844
|
+
_bindDropdownClickOffListener(t) {
|
|
2845
|
+
const e = (i) => {
|
|
2846
|
+
!!i.target.closest(
|
|
2847
|
+
`#iti-${this.id}__dropdown-content`
|
|
2848
|
+
) || this._closeDropdown();
|
|
2849
|
+
};
|
|
2850
|
+
setTimeout(() => {
|
|
2571
2851
|
document.documentElement.addEventListener(
|
|
2572
2852
|
"click",
|
|
2573
|
-
|
|
2853
|
+
e,
|
|
2854
|
+
{ signal: t }
|
|
2574
2855
|
);
|
|
2575
2856
|
}, 0);
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2857
|
+
}
|
|
2858
|
+
//* Listen for up/down scrolling, enter to select, or escape to close.
|
|
2859
|
+
//* Use keydown as keypress doesn't fire for non-char keys and we want to catch if they
|
|
2860
|
+
//* just hit down and hold it to scroll down (no keyup event).
|
|
2861
|
+
//* Listen on the document because that's where key events are triggered if no input has focus.
|
|
2862
|
+
_bindDropdownKeydownListener(t) {
|
|
2863
|
+
let e = "", i = null;
|
|
2864
|
+
const s = (o) => {
|
|
2865
|
+
[
|
|
2866
|
+
g.ARROW_UP,
|
|
2867
|
+
g.ARROW_DOWN,
|
|
2868
|
+
g.ENTER,
|
|
2869
|
+
g.ESC
|
|
2870
|
+
].includes(o.key) && (o.preventDefault(), o.stopPropagation(), o.key === g.ARROW_UP || o.key === g.ARROW_DOWN ? this._handleUpDownKey(o.key) : o.key === g.ENTER ? this._handleEnterKey() : o.key === g.ESC && this._closeDropdown()), !this.options.countrySearch && D.HIDDEN_SEARCH_CHAR.test(o.key) && (o.stopPropagation(), i && clearTimeout(i), e += o.key.toLowerCase(), this._searchForCountry(e), i = setTimeout(() => {
|
|
2579
2871
|
e = "";
|
|
2580
|
-
},
|
|
2581
|
-
}
|
|
2582
|
-
|
|
2583
|
-
const s = this.searchInput.value.trim();
|
|
2584
|
-
this._filterCountries(s), this.searchInput.value ? this.searchClearButton.classList.remove("iti__hide") : this.searchClearButton.classList.add("iti__hide");
|
|
2585
|
-
};
|
|
2586
|
-
let n = null;
|
|
2587
|
-
this._handleSearchChange = () => {
|
|
2588
|
-
n && clearTimeout(n), n = setTimeout(() => {
|
|
2589
|
-
i(), n = null;
|
|
2590
|
-
}, 100);
|
|
2591
|
-
}, this.searchInput.addEventListener("input", this._handleSearchChange), this._handleSearchClear = () => {
|
|
2592
|
-
this.searchInput.value = "", this.searchInput.focus(), i();
|
|
2593
|
-
}, this.searchClearButton.addEventListener("click", this._handleSearchClear);
|
|
2594
|
-
}
|
|
2872
|
+
}, ot.HIDDEN_SEARCH_RESET_MS));
|
|
2873
|
+
};
|
|
2874
|
+
document.addEventListener("keydown", s, { signal: t });
|
|
2595
2875
|
}
|
|
2596
|
-
//*
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2876
|
+
//* Search input listeners when countrySearch enabled.
|
|
2877
|
+
_bindDropdownSearchListeners(t) {
|
|
2878
|
+
const e = () => {
|
|
2879
|
+
const n = this.ui.searchInput.value.trim();
|
|
2880
|
+
this._filterCountriesByQuery(n), this.ui.searchInput.value ? this.ui.searchClearButton.classList.remove(h.HIDE) : this.ui.searchClearButton.classList.add(h.HIDE);
|
|
2881
|
+
};
|
|
2882
|
+
let i = null;
|
|
2883
|
+
const s = () => {
|
|
2884
|
+
i && clearTimeout(i), i = setTimeout(() => {
|
|
2885
|
+
e(), i = null;
|
|
2886
|
+
}, 100);
|
|
2887
|
+
};
|
|
2888
|
+
this.ui.searchInput.addEventListener("input", s, {
|
|
2889
|
+
signal: t
|
|
2890
|
+
});
|
|
2891
|
+
const o = () => {
|
|
2892
|
+
this.ui.searchInput.value = "", this.ui.searchInput.focus(), e();
|
|
2893
|
+
};
|
|
2894
|
+
this.ui.searchClearButton.addEventListener("click", o, {
|
|
2895
|
+
signal: t
|
|
2896
|
+
});
|
|
2604
2897
|
}
|
|
2605
|
-
//*
|
|
2606
|
-
|
|
2607
|
-
this.
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
for (const n of t) {
|
|
2612
|
-
const s = n.nodeById[this.id];
|
|
2613
|
-
s && (this.countryList.appendChild(s), i && (this._highlightListItem(s, !1), i = !1));
|
|
2898
|
+
//* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
|
|
2899
|
+
_searchForCountry(t) {
|
|
2900
|
+
const e = ct(this.countries, t);
|
|
2901
|
+
if (e) {
|
|
2902
|
+
const i = e.nodeById[this.id];
|
|
2903
|
+
this.ui.highlightListItem(i, !1), this.ui.scrollTo(i);
|
|
2614
2904
|
}
|
|
2615
|
-
i ? (this._highlightListItem(null, !1), this.searchNoResults && this.searchNoResults.classList.remove("iti__hide")) : this.searchNoResults && this.searchNoResults.classList.add("iti__hide"), this.countryList.scrollTop = 0, this._updateSearchResultsA11yText();
|
|
2616
|
-
}
|
|
2617
|
-
_getMatchedCountries(e) {
|
|
2618
|
-
const t = E(e), i = [], n = [], s = [], o = [], a = [], d = [];
|
|
2619
|
-
for (const l of this.countries)
|
|
2620
|
-
l.iso2 === t ? i.push(l) : l.normalisedName.startsWith(t) ? n.push(l) : l.normalisedName.includes(t) ? s.push(l) : t === l.dialCode || t === l.dialCodePlus ? o.push(l) : l.dialCodePlus.includes(t) ? a.push(l) : l.initials.includes(t) && d.push(l);
|
|
2621
|
-
return [
|
|
2622
|
-
...i.sort((l, h) => l.priority - h.priority),
|
|
2623
|
-
...n.sort((l, h) => l.priority - h.priority),
|
|
2624
|
-
...s.sort((l, h) => l.priority - h.priority),
|
|
2625
|
-
...o.sort((l, h) => l.priority - h.priority),
|
|
2626
|
-
...a.sort((l, h) => l.priority - h.priority),
|
|
2627
|
-
...d.sort((l, h) => l.priority - h.priority)
|
|
2628
|
-
];
|
|
2629
2905
|
}
|
|
2630
|
-
//*
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
t === 0 ? i = e.zeroSearchResults : e.searchResultsText ? i = e.searchResultsText(t) : t === 1 ? i = e.oneSearchResult : i = e.multipleSearchResults.replace("${count}", t.toString()), this.searchResultsA11yText.textContent = i;
|
|
2906
|
+
//* Country search: Filter the countries according to the search query.
|
|
2907
|
+
_filterCountriesByQuery(t) {
|
|
2908
|
+
let e;
|
|
2909
|
+
t === "" ? e = this.countries : e = dt(this.countries, t), this.ui.filterCountries(e);
|
|
2635
2910
|
}
|
|
2636
2911
|
//* Highlight the next/prev item in the list (and ensure it is visible).
|
|
2637
|
-
_handleUpDownKey(
|
|
2638
|
-
var i,
|
|
2639
|
-
let
|
|
2640
|
-
!
|
|
2912
|
+
_handleUpDownKey(t) {
|
|
2913
|
+
var i, s;
|
|
2914
|
+
let e = t === g.ARROW_UP ? (i = this.ui.highlightedItem) == null ? void 0 : i.previousElementSibling : (s = this.ui.highlightedItem) == null ? void 0 : s.nextElementSibling;
|
|
2915
|
+
!e && this.ui.countryList.childElementCount > 1 && (e = t === g.ARROW_UP ? this.ui.countryList.lastElementChild : this.ui.countryList.firstElementChild), e && (this.ui.scrollTo(e), this.ui.highlightListItem(e, !1));
|
|
2641
2916
|
}
|
|
2642
2917
|
//* Select the currently highlighted item.
|
|
2643
2918
|
_handleEnterKey() {
|
|
2644
|
-
this.highlightedItem && this._selectListItem(this.highlightedItem);
|
|
2919
|
+
this.ui.highlightedItem && this._selectListItem(this.ui.highlightedItem);
|
|
2645
2920
|
}
|
|
2646
2921
|
//* Update the input's value to the given val (format first if possible)
|
|
2647
2922
|
//* NOTE: this is called from _setInitialState, handleUtils and setNumber.
|
|
2648
|
-
_updateValFromNumber(
|
|
2649
|
-
let
|
|
2923
|
+
_updateValFromNumber(t) {
|
|
2924
|
+
let e = t;
|
|
2650
2925
|
if (this.options.formatOnDisplay && u.utils && this.selectedCountryData) {
|
|
2651
|
-
const i = this.options.nationalMode ||
|
|
2652
|
-
|
|
2653
|
-
|
|
2926
|
+
const i = this.options.nationalMode || !e.startsWith("+") && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: o } = u.utils.numberFormat, n = i ? s : o;
|
|
2927
|
+
e = u.utils.formatNumber(
|
|
2928
|
+
e,
|
|
2654
2929
|
this.selectedCountryData.iso2,
|
|
2655
|
-
|
|
2930
|
+
n
|
|
2656
2931
|
);
|
|
2657
2932
|
}
|
|
2658
|
-
|
|
2933
|
+
e = this._beforeSetNumber(e), this.ui.telInput.value = e;
|
|
2659
2934
|
}
|
|
2660
2935
|
//* Check if need to select a new country based on the given number
|
|
2661
2936
|
//* Note: called from _setInitialState, keyup handler, setNumber.
|
|
2662
|
-
_updateCountryFromNumber(
|
|
2663
|
-
const
|
|
2664
|
-
return
|
|
2937
|
+
_updateCountryFromNumber(t) {
|
|
2938
|
+
const e = this._getNewCountryFromNumber(t);
|
|
2939
|
+
return e !== null ? this._setCountry(e) : !1;
|
|
2665
2940
|
}
|
|
2666
2941
|
// if there is a selected country, and the number doesn't start with a dial code, then add it
|
|
2667
|
-
_ensureHasDialCode(
|
|
2668
|
-
const { dialCode:
|
|
2669
|
-
if (
|
|
2670
|
-
return
|
|
2671
|
-
const
|
|
2672
|
-
return `+${
|
|
2942
|
+
_ensureHasDialCode(t) {
|
|
2943
|
+
const { dialCode: e, nationalPrefix: i } = this.selectedCountryData;
|
|
2944
|
+
if (t.startsWith("+") || !e)
|
|
2945
|
+
return t;
|
|
2946
|
+
const n = i && t.startsWith(i) && !this.options.separateDialCode ? t.substring(1) : t;
|
|
2947
|
+
return `+${e}${n}`;
|
|
2673
2948
|
}
|
|
2674
2949
|
// Get the country ISO2 code from the given number
|
|
2675
2950
|
// BUT ONLY IF ITS CHANGED FROM THE CURRENTLY SELECTED COUNTRY
|
|
2676
2951
|
// NOTE: consider refactoring this to be more clear
|
|
2677
|
-
_getNewCountryFromNumber(
|
|
2678
|
-
const
|
|
2679
|
-
let i =
|
|
2680
|
-
const
|
|
2952
|
+
_getNewCountryFromNumber(t) {
|
|
2953
|
+
const e = t.indexOf("+");
|
|
2954
|
+
let i = e ? t.substring(e) : t;
|
|
2955
|
+
const s = this.selectedCountryData.iso2, o = this.selectedCountryData.dialCode;
|
|
2681
2956
|
i = this._ensureHasDialCode(i);
|
|
2682
|
-
const
|
|
2683
|
-
if (
|
|
2684
|
-
const
|
|
2685
|
-
if (
|
|
2686
|
-
return
|
|
2687
|
-
if (!
|
|
2957
|
+
const n = this._getDialCode(i, !0), r = v(i);
|
|
2958
|
+
if (n) {
|
|
2959
|
+
const a = v(n), d = this.dialCodeToIso2Map[a];
|
|
2960
|
+
if (d.length === 1)
|
|
2961
|
+
return d[0] === s ? null : d[0];
|
|
2962
|
+
if (!s && this.defaultCountry && d.includes(this.defaultCountry))
|
|
2688
2963
|
return this.defaultCountry;
|
|
2689
|
-
if (
|
|
2964
|
+
if (o === $.NANP && F(r))
|
|
2690
2965
|
return null;
|
|
2691
|
-
const { areaCodes:
|
|
2692
|
-
if (
|
|
2693
|
-
const
|
|
2694
|
-
|
|
2695
|
-
|
|
2966
|
+
const { areaCodes: f, priority: b } = this.selectedCountryData;
|
|
2967
|
+
if (f) {
|
|
2968
|
+
const _ = f.map(
|
|
2969
|
+
(N) => `${o}${N}`
|
|
2970
|
+
);
|
|
2971
|
+
for (const N of _)
|
|
2972
|
+
if (r.startsWith(N))
|
|
2696
2973
|
return null;
|
|
2697
2974
|
}
|
|
2698
|
-
const
|
|
2699
|
-
if (!
|
|
2700
|
-
return
|
|
2975
|
+
const y = f && !(b === 0) && r.length > a.length, w = s && d.includes(s) && !y, I = s === d[0];
|
|
2976
|
+
if (!w && !I)
|
|
2977
|
+
return d[0];
|
|
2701
2978
|
} else {
|
|
2702
|
-
if (i.
|
|
2979
|
+
if (i.startsWith("+") && r.length)
|
|
2703
2980
|
return "";
|
|
2704
|
-
if ((!i || i === "+") && !
|
|
2981
|
+
if ((!i || i === "+") && !s)
|
|
2705
2982
|
return this.defaultCountry;
|
|
2706
2983
|
}
|
|
2707
2984
|
return null;
|
|
2708
2985
|
}
|
|
2709
|
-
//* Remove highlighting from other list items and highlight the given item.
|
|
2710
|
-
_highlightListItem(e, t) {
|
|
2711
|
-
const i = this.highlightedItem;
|
|
2712
|
-
if (i && (i.classList.remove("iti__highlight"), i.setAttribute("aria-selected", "false")), this.highlightedItem = e, this.highlightedItem && (this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true"), this.options.countrySearch)) {
|
|
2713
|
-
const n = this.highlightedItem.getAttribute("id") || "";
|
|
2714
|
-
this.searchInput.setAttribute("aria-activedescendant", n);
|
|
2715
|
-
}
|
|
2716
|
-
t && this.highlightedItem.focus();
|
|
2717
|
-
}
|
|
2718
2986
|
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
|
|
2719
2987
|
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
|
|
2720
|
-
_setCountry(
|
|
2721
|
-
const { separateDialCode:
|
|
2722
|
-
if (this.selectedCountryData =
|
|
2723
|
-
const
|
|
2724
|
-
let
|
|
2725
|
-
if (
|
|
2726
|
-
const { name:
|
|
2727
|
-
|
|
2988
|
+
_setCountry(t) {
|
|
2989
|
+
const { separateDialCode: e, showFlags: i, i18n: s } = this.options, o = this.selectedCountryData.iso2 || "";
|
|
2990
|
+
if (this.selectedCountryData = t ? this.countryByIso2.get(t) : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.ui.selectedCountry) {
|
|
2991
|
+
const n = t && i ? `${h.FLAG} iti__${t}` : `${h.FLAG} ${h.GLOBE}`;
|
|
2992
|
+
let r, a;
|
|
2993
|
+
if (t) {
|
|
2994
|
+
const { name: d, dialCode: c } = this.selectedCountryData;
|
|
2995
|
+
a = d, r = s.selectedCountryAriaLabel.replace("${countryName}", d).replace("${dialCode}", `+${c}`);
|
|
2728
2996
|
} else
|
|
2729
|
-
|
|
2730
|
-
this.selectedCountryInner.className =
|
|
2731
|
-
}
|
|
2732
|
-
if (t) {
|
|
2733
|
-
const o = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2734
|
-
this.selectedDialCode.innerHTML = o, this._updateInputPadding();
|
|
2997
|
+
a = s.noCountrySelected, r = s.noCountrySelected;
|
|
2998
|
+
this.ui.selectedCountryInner.className = n, this.ui.selectedCountry.setAttribute("title", a), this.ui.selectedCountry.setAttribute(C.LABEL, r);
|
|
2735
2999
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
_updateInputPadding() {
|
|
2740
|
-
if (this.selectedCountry) {
|
|
2741
|
-
const e = this.options.separateDialCode ? 78 : 42, i = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || e) + 6;
|
|
2742
|
-
this.telInput.style.paddingLeft = `${i}px`;
|
|
3000
|
+
if (e) {
|
|
3001
|
+
const n = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
3002
|
+
this.ui.selectedDialCode.textContent = n, this.ui.updateInputPadding();
|
|
2743
3003
|
}
|
|
3004
|
+
return this._updatePlaceholder(), this._updateMaxLength(), o !== t;
|
|
2744
3005
|
}
|
|
2745
3006
|
//* Update the maximum valid number length for the currently selected country.
|
|
2746
3007
|
_updateMaxLength() {
|
|
2747
|
-
const { strictMode:
|
|
2748
|
-
if (
|
|
2749
|
-
if (
|
|
2750
|
-
const
|
|
2751
|
-
let
|
|
2752
|
-
n,
|
|
2753
|
-
!1,
|
|
3008
|
+
const { strictMode: t, placeholderNumberType: e, validationNumberTypes: i } = this.options, { iso2: s } = this.selectedCountryData;
|
|
3009
|
+
if (t && u.utils)
|
|
3010
|
+
if (s) {
|
|
3011
|
+
const o = u.utils.numberType[e];
|
|
3012
|
+
let n = u.utils.getExampleNumber(
|
|
2754
3013
|
s,
|
|
3014
|
+
!1,
|
|
3015
|
+
o,
|
|
2755
3016
|
!0
|
|
2756
|
-
),
|
|
2757
|
-
for (; u.utils.isPossibleNumber(
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
3017
|
+
), r = n;
|
|
3018
|
+
for (; u.utils.isPossibleNumber(
|
|
3019
|
+
n,
|
|
3020
|
+
s,
|
|
3021
|
+
i
|
|
3022
|
+
); )
|
|
3023
|
+
r = n, n += "0";
|
|
3024
|
+
const a = u.utils.getCoreNumber(r, s);
|
|
3025
|
+
this.maxCoreNumberLength = a.length, s === "by" && (this.maxCoreNumberLength = a.length + 1);
|
|
2761
3026
|
} else
|
|
2762
3027
|
this.maxCoreNumberLength = null;
|
|
2763
3028
|
}
|
|
2764
|
-
//* When input is in a hidden container during init, we cannot calculate the selected country width.
|
|
2765
|
-
//* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
|
|
2766
|
-
//* To get the right styling to apply, all we need is a shallow clone of the container,
|
|
2767
|
-
//* and then to inject a deep clone of the selectedCountry element.
|
|
2768
|
-
_getHiddenSelectedCountryWidth() {
|
|
2769
|
-
if (this.telInput.parentNode) {
|
|
2770
|
-
let e;
|
|
2771
|
-
try {
|
|
2772
|
-
e = window.top.document.body;
|
|
2773
|
-
} catch {
|
|
2774
|
-
e = document.body;
|
|
2775
|
-
}
|
|
2776
|
-
const t = this.telInput.parentNode.cloneNode(!1);
|
|
2777
|
-
t.style.visibility = "hidden", e.appendChild(t);
|
|
2778
|
-
const i = this.countryContainer.cloneNode();
|
|
2779
|
-
t.appendChild(i);
|
|
2780
|
-
const n = this.selectedCountry.cloneNode(!0);
|
|
2781
|
-
i.appendChild(n);
|
|
2782
|
-
const s = n.offsetWidth;
|
|
2783
|
-
return e.removeChild(t), s;
|
|
2784
|
-
}
|
|
2785
|
-
return 0;
|
|
2786
|
-
}
|
|
2787
3029
|
//* Update the input placeholder to an example number from the currently selected country.
|
|
2788
3030
|
_updatePlaceholder() {
|
|
2789
3031
|
const {
|
|
2790
|
-
autoPlaceholder:
|
|
2791
|
-
placeholderNumberType:
|
|
3032
|
+
autoPlaceholder: t,
|
|
3033
|
+
placeholderNumberType: e,
|
|
2792
3034
|
nationalMode: i,
|
|
2793
|
-
customPlaceholder:
|
|
2794
|
-
} = this.options,
|
|
2795
|
-
if (u.utils &&
|
|
2796
|
-
const
|
|
2797
|
-
let
|
|
3035
|
+
customPlaceholder: s
|
|
3036
|
+
} = this.options, o = t === "aggressive" || !this.ui.hadInitialPlaceholder && t === "polite";
|
|
3037
|
+
if (u.utils && o) {
|
|
3038
|
+
const n = u.utils.numberType[e];
|
|
3039
|
+
let r = this.selectedCountryData.iso2 ? u.utils.getExampleNumber(
|
|
2798
3040
|
this.selectedCountryData.iso2,
|
|
2799
3041
|
i,
|
|
2800
|
-
|
|
3042
|
+
n
|
|
2801
3043
|
) : "";
|
|
2802
|
-
|
|
3044
|
+
r = this._beforeSetNumber(r), typeof s == "function" && (r = s(r, this.selectedCountryData)), this.ui.telInput.setAttribute("placeholder", r);
|
|
2803
3045
|
}
|
|
2804
3046
|
}
|
|
2805
3047
|
//* Called when the user selects a list item from the dropdown.
|
|
2806
|
-
_selectListItem(
|
|
2807
|
-
const
|
|
3048
|
+
_selectListItem(t) {
|
|
3049
|
+
const e = t.dataset[W.COUNTRY_CODE], i = this._setCountry(e);
|
|
2808
3050
|
this._closeDropdown();
|
|
2809
|
-
const
|
|
2810
|
-
this._updateDialCode(
|
|
3051
|
+
const s = t.dataset[W.DIAL_CODE];
|
|
3052
|
+
this._updateDialCode(s), this.options.formatOnDisplay && this._updateValFromNumber(this.ui.telInput.value), this.ui.telInput.focus(), i && this._triggerCountryChange();
|
|
2811
3053
|
}
|
|
2812
3054
|
//* Close the dropdown and unbind any listeners.
|
|
2813
3055
|
_closeDropdown() {
|
|
2814
|
-
this.dropdownContent.classList.add(
|
|
2815
|
-
"click",
|
|
2816
|
-
this._handleClickOffToClose
|
|
2817
|
-
), this.countryList.removeEventListener(
|
|
2818
|
-
"mouseover",
|
|
2819
|
-
this._handleMouseoverCountryList
|
|
2820
|
-
), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._trigger("close:countrydropdown");
|
|
2821
|
-
}
|
|
2822
|
-
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2823
|
-
_scrollTo(e) {
|
|
2824
|
-
const t = this.countryList, i = document.documentElement.scrollTop, n = t.offsetHeight, s = t.getBoundingClientRect().top + i, o = s + n, a = e.offsetHeight, d = e.getBoundingClientRect().top + i, l = d + a, h = d - s + t.scrollTop;
|
|
2825
|
-
if (d < s)
|
|
2826
|
-
t.scrollTop = h;
|
|
2827
|
-
else if (l > o) {
|
|
2828
|
-
const p = n - a;
|
|
2829
|
-
t.scrollTop = h - p;
|
|
2830
|
-
}
|
|
3056
|
+
this.ui.dropdownContent.classList.contains(h.HIDE) || (this.ui.dropdownContent.classList.add(h.HIDE), this.ui.selectedCountry.setAttribute(C.EXPANDED, "false"), this.ui.highlightedItem && this.ui.highlightedItem.setAttribute(C.SELECTED, "false"), this.options.countrySearch && this.ui.searchInput.removeAttribute(C.ACTIVE_DESCENDANT), this.ui.dropdownArrow.classList.remove(h.ARROW_UP), this.dropdownAbortController.abort(), this.dropdownAbortController = null, this.options.dropdownContainer && this.ui.dropdown.remove(), this._trigger(A.CLOSE_COUNTRY_DROPDOWN));
|
|
2831
3057
|
}
|
|
2832
3058
|
//* Replace any existing dial code with the new one
|
|
2833
3059
|
//* Note: called from _selectListItem and setCountry
|
|
2834
|
-
_updateDialCode(
|
|
2835
|
-
const
|
|
2836
|
-
let
|
|
2837
|
-
if (
|
|
2838
|
-
const
|
|
2839
|
-
|
|
3060
|
+
_updateDialCode(t) {
|
|
3061
|
+
const e = this.ui.telInput.value, i = `+${t}`;
|
|
3062
|
+
let s;
|
|
3063
|
+
if (e.startsWith("+")) {
|
|
3064
|
+
const o = this._getDialCode(e);
|
|
3065
|
+
o ? s = e.replace(o, i) : s = i, this.ui.telInput.value = s;
|
|
2840
3066
|
}
|
|
2841
3067
|
}
|
|
2842
3068
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
2843
3069
|
//* Note: returns the raw string inc plus character and any whitespace/dots etc.
|
|
2844
|
-
_getDialCode(
|
|
3070
|
+
_getDialCode(t, e) {
|
|
2845
3071
|
let i = "";
|
|
2846
|
-
if (
|
|
2847
|
-
let
|
|
2848
|
-
for (let
|
|
2849
|
-
const
|
|
2850
|
-
if (/[0-9]/.test(
|
|
2851
|
-
if (
|
|
3072
|
+
if (t.startsWith("+")) {
|
|
3073
|
+
let s = "";
|
|
3074
|
+
for (let o = 0; o < t.length; o++) {
|
|
3075
|
+
const n = t.charAt(o);
|
|
3076
|
+
if (/[0-9]/.test(n)) {
|
|
3077
|
+
if (s += n, !!!this.dialCodeToIso2Map[s])
|
|
2852
3078
|
break;
|
|
2853
|
-
if (
|
|
2854
|
-
i =
|
|
2855
|
-
else if (this.dialCodes.has(
|
|
2856
|
-
i =
|
|
3079
|
+
if (e)
|
|
3080
|
+
i = t.substring(0, o + 1);
|
|
3081
|
+
else if (this.dialCodes.has(s)) {
|
|
3082
|
+
i = t.substring(0, o + 1);
|
|
2857
3083
|
break;
|
|
2858
3084
|
}
|
|
2859
|
-
if (
|
|
3085
|
+
if (s.length === this.dialCodeMaxLen)
|
|
2860
3086
|
break;
|
|
2861
3087
|
}
|
|
2862
3088
|
}
|
|
@@ -2864,17 +3090,17 @@ class L {
|
|
|
2864
3090
|
return i;
|
|
2865
3091
|
}
|
|
2866
3092
|
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
2867
|
-
_getFullNumber(
|
|
2868
|
-
const
|
|
2869
|
-
let
|
|
2870
|
-
const
|
|
2871
|
-
return this.options.separateDialCode &&
|
|
3093
|
+
_getFullNumber(t) {
|
|
3094
|
+
const e = t || this.ui.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
|
|
3095
|
+
let s;
|
|
3096
|
+
const o = v(e);
|
|
3097
|
+
return this.options.separateDialCode && !e.startsWith("+") && i && o ? s = `+${i}` : s = "", s + e;
|
|
2872
3098
|
}
|
|
2873
3099
|
//* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
|
|
2874
|
-
_beforeSetNumber(
|
|
2875
|
-
const
|
|
2876
|
-
e,
|
|
3100
|
+
_beforeSetNumber(t) {
|
|
3101
|
+
const e = this._getDialCode(t), i = It(
|
|
2877
3102
|
t,
|
|
3103
|
+
e,
|
|
2878
3104
|
this.options.separateDialCode,
|
|
2879
3105
|
this.selectedCountryData
|
|
2880
3106
|
);
|
|
@@ -2882,42 +3108,25 @@ class L {
|
|
|
2882
3108
|
}
|
|
2883
3109
|
//* Trigger the 'countrychange' event.
|
|
2884
3110
|
_triggerCountryChange() {
|
|
2885
|
-
this._trigger(
|
|
3111
|
+
this._trigger(A.COUNTRY_CHANGE);
|
|
2886
3112
|
}
|
|
2887
3113
|
//**************************
|
|
2888
3114
|
//* SECRET PUBLIC METHODS
|
|
2889
3115
|
//**************************
|
|
2890
3116
|
//* This is called when the geoip call returns.
|
|
2891
3117
|
handleAutoCountry() {
|
|
2892
|
-
this.options.initialCountry ===
|
|
3118
|
+
this.options.initialCountry === O.AUTO && u.autoCountry && (this.defaultCountry = u.autoCountry, this.selectedCountryData.iso2 || this.ui.selectedCountryInner.classList.contains(h.GLOBE) || this.setCountry(this.defaultCountry), this.resolveAutoCountryPromise());
|
|
2893
3119
|
}
|
|
2894
3120
|
//* This is called when the utils request completes.
|
|
2895
3121
|
handleUtils() {
|
|
2896
|
-
u.utils && (this.telInput.value && this._updateValFromNumber(this.telInput.value), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength())), this.resolveUtilsScriptPromise();
|
|
3122
|
+
u.utils && (this.ui.telInput.value && this._updateValFromNumber(this.ui.telInput.value), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength())), this.resolveUtilsScriptPromise();
|
|
2897
3123
|
}
|
|
2898
3124
|
//********************
|
|
2899
3125
|
//* PUBLIC METHODS
|
|
2900
3126
|
//********************
|
|
2901
3127
|
//* Remove plugin.
|
|
2902
3128
|
destroy() {
|
|
2903
|
-
|
|
2904
|
-
this.telInput.iti = void 0;
|
|
2905
|
-
const { allowDropdown: e, separateDialCode: t } = this.options;
|
|
2906
|
-
if (e) {
|
|
2907
|
-
this._closeDropdown(), this.selectedCountry.removeEventListener(
|
|
2908
|
-
"click",
|
|
2909
|
-
this._handleClickSelectedCountry
|
|
2910
|
-
), this.countryContainer.removeEventListener(
|
|
2911
|
-
"keydown",
|
|
2912
|
-
this._handleCountryContainerKeydown
|
|
2913
|
-
);
|
|
2914
|
-
const a = this.telInput.closest("label");
|
|
2915
|
-
a && a.removeEventListener("click", this._handleLabelClick);
|
|
2916
|
-
}
|
|
2917
|
-
const { form: i } = this.telInput;
|
|
2918
|
-
this._handleHiddenInputSubmit && i && i.removeEventListener("submit", this._handleHiddenInputSubmit), this.telInput.removeEventListener("input", this._handleInputEvent), this._handleKeydownEvent && this.telInput.removeEventListener("keydown", this._handleKeydownEvent), this._handlePasteEvent && this.telInput.removeEventListener("paste", this._handlePasteEvent), this._handlePageLoad && window.removeEventListener("load", this._handlePageLoad), this.telInput.removeAttribute("data-intl-tel-input-id"), t && (this.telInput.style.paddingLeft = this.originalPaddingLeft);
|
|
2919
|
-
const n = this.telInput.parentNode;
|
|
2920
|
-
(s = n == null ? void 0 : n.parentNode) == null || s.insertBefore(this.telInput, n), (o = n == null ? void 0 : n.parentNode) == null || o.removeChild(n), delete u.instances[this.id];
|
|
3129
|
+
this.ui.telInput && (this.options.allowDropdown && this._closeDropdown(), this.abortController.abort(), this.abortController = null, this.ui.destroy(), u.instances instanceof Map ? u.instances.delete(this.id) : delete u.instances[this.id]);
|
|
2921
3130
|
}
|
|
2922
3131
|
//* Get the extension from the current number.
|
|
2923
3132
|
getExtension() {
|
|
@@ -2927,13 +3136,13 @@ class L {
|
|
|
2927
3136
|
) : "";
|
|
2928
3137
|
}
|
|
2929
3138
|
//* Format the number to the given format.
|
|
2930
|
-
getNumber(
|
|
3139
|
+
getNumber(t) {
|
|
2931
3140
|
if (u.utils) {
|
|
2932
|
-
const { iso2:
|
|
3141
|
+
const { iso2: e } = this.selectedCountryData;
|
|
2933
3142
|
return u.utils.formatNumber(
|
|
2934
3143
|
this._getFullNumber(),
|
|
2935
|
-
|
|
2936
|
-
|
|
3144
|
+
e,
|
|
3145
|
+
t
|
|
2937
3146
|
);
|
|
2938
3147
|
}
|
|
2939
3148
|
return "";
|
|
@@ -2943,7 +3152,7 @@ class L {
|
|
|
2943
3152
|
return u.utils ? u.utils.getNumberType(
|
|
2944
3153
|
this._getFullNumber(),
|
|
2945
3154
|
this.selectedCountryData.iso2
|
|
2946
|
-
) :
|
|
3155
|
+
) : H.UNKNOWN_NUMBER_TYPE;
|
|
2947
3156
|
}
|
|
2948
3157
|
//* Get the country data for the currently selected country.
|
|
2949
3158
|
getSelectedCountryData() {
|
|
@@ -2952,17 +3161,17 @@ class L {
|
|
|
2952
3161
|
//* Get the validation error.
|
|
2953
3162
|
getValidationError() {
|
|
2954
3163
|
if (u.utils) {
|
|
2955
|
-
const { iso2:
|
|
2956
|
-
return u.utils.getValidationError(this._getFullNumber(),
|
|
3164
|
+
const { iso2: t } = this.selectedCountryData;
|
|
3165
|
+
return u.utils.getValidationError(this._getFullNumber(), t);
|
|
2957
3166
|
}
|
|
2958
|
-
return
|
|
3167
|
+
return H.UNKNOWN_VALIDATION_ERROR;
|
|
2959
3168
|
}
|
|
2960
3169
|
//* Validate the input val using number length only
|
|
2961
3170
|
isValidNumber() {
|
|
2962
|
-
const { dialCode:
|
|
2963
|
-
if (
|
|
2964
|
-
const i = this._getFullNumber(),
|
|
2965
|
-
if (
|
|
3171
|
+
const { dialCode: t, iso2: e } = this.selectedCountryData;
|
|
3172
|
+
if (t === P.DIAL_CODE && u.utils) {
|
|
3173
|
+
const i = this._getFullNumber(), s = u.utils.getCoreNumber(i, e);
|
|
3174
|
+
if (s[0] === P.MOBILE_PREFIX && s.length !== P.MOBILE_CORE_LENGTH)
|
|
2966
3175
|
return !1;
|
|
2967
3176
|
}
|
|
2968
3177
|
return this._validateNumber(!1);
|
|
@@ -2971,93 +3180,112 @@ class L {
|
|
|
2971
3180
|
isValidNumberPrecise() {
|
|
2972
3181
|
return this._validateNumber(!0);
|
|
2973
3182
|
}
|
|
2974
|
-
_utilsIsPossibleNumber(
|
|
2975
|
-
return u.utils ? u.utils.isPossibleNumber(
|
|
3183
|
+
_utilsIsPossibleNumber(t) {
|
|
3184
|
+
return u.utils ? u.utils.isPossibleNumber(
|
|
3185
|
+
t,
|
|
3186
|
+
this.selectedCountryData.iso2,
|
|
3187
|
+
this.options.validationNumberTypes
|
|
3188
|
+
) : null;
|
|
2976
3189
|
}
|
|
2977
3190
|
//* Shared internal validation logic to handle alpha character extension rules.
|
|
2978
|
-
_validateNumber(
|
|
3191
|
+
_validateNumber(t) {
|
|
2979
3192
|
if (!u.utils)
|
|
2980
3193
|
return null;
|
|
2981
3194
|
if (!this.selectedCountryData.iso2)
|
|
2982
3195
|
return !1;
|
|
2983
|
-
const
|
|
2984
|
-
if (
|
|
2985
|
-
const
|
|
2986
|
-
return
|
|
3196
|
+
const e = (n) => t ? this._utilsIsValidNumber(n) : this._utilsIsPossibleNumber(n), i = this._getFullNumber(), s = i.search(D.ALPHA_UNICODE);
|
|
3197
|
+
if (s > -1 && !this.options.allowPhonewords) {
|
|
3198
|
+
const n = i.substring(0, s), r = e(n), a = e(i);
|
|
3199
|
+
return r && a;
|
|
2987
3200
|
}
|
|
2988
|
-
return
|
|
3201
|
+
return e(i);
|
|
2989
3202
|
}
|
|
2990
|
-
_utilsIsValidNumber(
|
|
2991
|
-
return u.utils ? u.utils.isValidNumber(
|
|
3203
|
+
_utilsIsValidNumber(t) {
|
|
3204
|
+
return u.utils ? u.utils.isValidNumber(
|
|
3205
|
+
t,
|
|
3206
|
+
this.selectedCountryData.iso2,
|
|
3207
|
+
this.options.validationNumberTypes
|
|
3208
|
+
) : null;
|
|
2992
3209
|
}
|
|
2993
3210
|
//* Update the selected country, and update the input val accordingly.
|
|
2994
|
-
setCountry(
|
|
2995
|
-
const
|
|
2996
|
-
if (!
|
|
2997
|
-
throw new Error(`Invalid country code: '${
|
|
3211
|
+
setCountry(t) {
|
|
3212
|
+
const e = t == null ? void 0 : t.toLowerCase();
|
|
3213
|
+
if (!M(e))
|
|
3214
|
+
throw new Error(`Invalid country code: '${e}'`);
|
|
2998
3215
|
const i = this.selectedCountryData.iso2;
|
|
2999
|
-
(
|
|
3216
|
+
(t && e !== i || !t && i) && (this._setCountry(e), this._updateDialCode(this.selectedCountryData.dialCode), this.options.formatOnDisplay && this._updateValFromNumber(this.ui.telInput.value), this._triggerCountryChange());
|
|
3000
3217
|
}
|
|
3001
3218
|
//* Set the input value and update the country.
|
|
3002
|
-
setNumber(
|
|
3003
|
-
const
|
|
3004
|
-
this._updateValFromNumber(
|
|
3219
|
+
setNumber(t) {
|
|
3220
|
+
const e = this._updateCountryFromNumber(t);
|
|
3221
|
+
this._updateValFromNumber(t), e && this._triggerCountryChange(), this._trigger(A.INPUT, { isSetNumber: !0 });
|
|
3005
3222
|
}
|
|
3006
3223
|
//* Set the placeholder number typ
|
|
3007
|
-
setPlaceholderNumberType(
|
|
3008
|
-
this.options.placeholderNumberType =
|
|
3224
|
+
setPlaceholderNumberType(t) {
|
|
3225
|
+
this.options.placeholderNumberType = t, this._updatePlaceholder();
|
|
3009
3226
|
}
|
|
3010
|
-
setDisabled(
|
|
3011
|
-
this.telInput.disabled =
|
|
3227
|
+
setDisabled(t) {
|
|
3228
|
+
this.ui.telInput.disabled = t, t ? this.ui.selectedCountry.setAttribute("disabled", "true") : this.ui.selectedCountry.removeAttribute("disabled");
|
|
3012
3229
|
}
|
|
3013
3230
|
}
|
|
3014
|
-
const
|
|
3231
|
+
const Et = (l) => {
|
|
3015
3232
|
if (!u.utils && !u.startedLoadingUtilsScript) {
|
|
3016
|
-
let
|
|
3017
|
-
if (typeof
|
|
3233
|
+
let t;
|
|
3234
|
+
if (typeof l == "function")
|
|
3018
3235
|
try {
|
|
3019
|
-
|
|
3020
|
-
} catch (
|
|
3021
|
-
return Promise.reject(
|
|
3236
|
+
t = Promise.resolve(l());
|
|
3237
|
+
} catch (e) {
|
|
3238
|
+
return Promise.reject(e);
|
|
3022
3239
|
}
|
|
3023
3240
|
else
|
|
3024
|
-
return Promise.reject(
|
|
3025
|
-
|
|
3026
|
-
|
|
3241
|
+
return Promise.reject(
|
|
3242
|
+
new TypeError(
|
|
3243
|
+
`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof l}`
|
|
3244
|
+
)
|
|
3245
|
+
);
|
|
3246
|
+
return u.startedLoadingUtilsScript = !0, t.then((e) => {
|
|
3247
|
+
const i = e == null ? void 0 : e.default;
|
|
3027
3248
|
if (!i || typeof i != "object")
|
|
3028
|
-
throw new TypeError(
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3249
|
+
throw new TypeError(
|
|
3250
|
+
"The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
|
|
3251
|
+
);
|
|
3252
|
+
return u.utils = i, E("handleUtils"), !0;
|
|
3253
|
+
}).catch((e) => {
|
|
3254
|
+
throw E("rejectUtilsScriptPromise", e), e;
|
|
3032
3255
|
});
|
|
3033
3256
|
}
|
|
3034
3257
|
return null;
|
|
3258
|
+
}, E = (l, ...t) => {
|
|
3259
|
+
Object.values(u.instances).forEach((e) => {
|
|
3260
|
+
const i = e[l];
|
|
3261
|
+
typeof i == "function" && i.apply(e, t);
|
|
3262
|
+
});
|
|
3035
3263
|
}, u = Object.assign(
|
|
3036
|
-
(
|
|
3037
|
-
const
|
|
3038
|
-
return
|
|
3264
|
+
(l, t) => {
|
|
3265
|
+
const e = new x(l, t);
|
|
3266
|
+
return u.instances[e.id] = e, l.iti = e, e;
|
|
3039
3267
|
},
|
|
3040
3268
|
{
|
|
3041
|
-
defaults:
|
|
3269
|
+
defaults: G,
|
|
3042
3270
|
//* Using a static var like this allows us to mock it in the tests.
|
|
3043
3271
|
documentReady: () => document.readyState === "complete",
|
|
3044
3272
|
//* Get the country data object.
|
|
3045
|
-
getCountryData: () =>
|
|
3273
|
+
getCountryData: () => L,
|
|
3046
3274
|
//* A getter for the plugin instance.
|
|
3047
|
-
getInstance: (
|
|
3048
|
-
const
|
|
3049
|
-
return
|
|
3275
|
+
getInstance: (l) => {
|
|
3276
|
+
const t = l.dataset.intlTelInputId;
|
|
3277
|
+
return t ? u.instances[t] : null;
|
|
3050
3278
|
},
|
|
3051
3279
|
//* A map from instance ID to instance object.
|
|
3052
3280
|
instances: {},
|
|
3053
|
-
attachUtils:
|
|
3281
|
+
attachUtils: Et,
|
|
3054
3282
|
startedLoadingUtilsScript: !1,
|
|
3055
3283
|
startedLoadingAutoCountry: !1,
|
|
3056
|
-
version: "25.
|
|
3284
|
+
version: "25.11.1"
|
|
3057
3285
|
}
|
|
3058
|
-
),
|
|
3286
|
+
), vt = {
|
|
3059
3287
|
__name: "IntlTelInput",
|
|
3060
|
-
props: /* @__PURE__ */
|
|
3288
|
+
props: /* @__PURE__ */ U({
|
|
3061
3289
|
disabled: {
|
|
3062
3290
|
type: Boolean,
|
|
3063
3291
|
default: !1
|
|
@@ -3081,47 +3309,47 @@ const st = (r) => {
|
|
|
3081
3309
|
},
|
|
3082
3310
|
modelModifiers: {}
|
|
3083
3311
|
}),
|
|
3084
|
-
emits: /* @__PURE__ */
|
|
3312
|
+
emits: /* @__PURE__ */ U([
|
|
3085
3313
|
"changeNumber",
|
|
3086
3314
|
"changeCountry",
|
|
3087
3315
|
"changeValidity",
|
|
3088
3316
|
"changeErrorCode"
|
|
3089
3317
|
], ["update:modelValue"]),
|
|
3090
|
-
setup(
|
|
3091
|
-
const i =
|
|
3092
|
-
let
|
|
3093
|
-
|
|
3318
|
+
setup(l, { expose: t, emit: e }) {
|
|
3319
|
+
const i = K(l, "modelValue"), s = l, o = e, n = T(), r = T(), a = T(!1), d = () => r.value ? s.options.strictMode ? r.value.isValidNumberPrecise() : r.value.isValidNumber() : null, c = () => {
|
|
3320
|
+
let p = d();
|
|
3321
|
+
a.value !== p && (a.value = p, o("changeValidity", !!p), o(
|
|
3094
3322
|
"changeErrorCode",
|
|
3095
|
-
|
|
3323
|
+
p ? null : r.value.getValidationError()
|
|
3096
3324
|
));
|
|
3097
|
-
},
|
|
3098
|
-
var
|
|
3099
|
-
|
|
3100
|
-
},
|
|
3101
|
-
var
|
|
3102
|
-
|
|
3325
|
+
}, f = () => {
|
|
3326
|
+
var p;
|
|
3327
|
+
o("changeNumber", ((p = r.value) == null ? void 0 : p.getNumber()) ?? ""), c();
|
|
3328
|
+
}, b = () => {
|
|
3329
|
+
var p;
|
|
3330
|
+
o("changeCountry", ((p = r.value) == null ? void 0 : p.getSelectedCountryData().iso2) ?? ""), f(), c();
|
|
3103
3331
|
};
|
|
3104
|
-
return
|
|
3105
|
-
|
|
3106
|
-
}),
|
|
3107
|
-
() =>
|
|
3108
|
-
(
|
|
3109
|
-
var
|
|
3110
|
-
return (
|
|
3332
|
+
return Y(() => {
|
|
3333
|
+
n.value && (r.value = u(n.value, s.options), s.value && r.value.setNumber(s.value), s.disabled && r.value.setDisabled(s.disabled), a.value = d());
|
|
3334
|
+
}), q(
|
|
3335
|
+
() => s.disabled,
|
|
3336
|
+
(p) => {
|
|
3337
|
+
var y;
|
|
3338
|
+
return (y = r.value) == null ? void 0 : y.setDisabled(p);
|
|
3111
3339
|
}
|
|
3112
|
-
),
|
|
3113
|
-
var
|
|
3114
|
-
return (
|
|
3115
|
-
}),
|
|
3340
|
+
), X(() => {
|
|
3341
|
+
var p;
|
|
3342
|
+
return (p = r.value) == null ? void 0 : p.destroy();
|
|
3343
|
+
}), t({ instance: r, input: n }), (p, y) => Q((Z(), J("input", tt({
|
|
3116
3344
|
ref_key: "input",
|
|
3117
|
-
ref:
|
|
3118
|
-
"onUpdate:modelValue":
|
|
3345
|
+
ref: n,
|
|
3346
|
+
"onUpdate:modelValue": y[0] || (y[0] = (w) => i.value = w),
|
|
3119
3347
|
type: "tel",
|
|
3120
|
-
onCountrychange:
|
|
3121
|
-
onInput:
|
|
3122
|
-
},
|
|
3348
|
+
onCountrychange: b,
|
|
3349
|
+
onInput: f
|
|
3350
|
+
}, l.inputProps), null, 16)), [
|
|
3123
3351
|
[
|
|
3124
|
-
|
|
3352
|
+
et,
|
|
3125
3353
|
i.value,
|
|
3126
3354
|
void 0,
|
|
3127
3355
|
{ lazy: !0 }
|
|
@@ -3130,5 +3358,5 @@ const st = (r) => {
|
|
|
3130
3358
|
}
|
|
3131
3359
|
};
|
|
3132
3360
|
export {
|
|
3133
|
-
|
|
3361
|
+
vt as default
|
|
3134
3362
|
};
|