intl-tel-input 25.5.2 → 25.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +15 -15
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +170 -116
- package/angular/build/IntlTelInputWithUtils.js +235 -202
- package/angular/build/types/intl-tel-input/data.d.ts +7 -2
- package/angular/build/types/intl-tel-input/i18n/types.d.ts +1 -0
- package/angular/build/types/intl-tel-input.d.ts +14 -2
- package/build/css/intlTelInput.css +67 -6
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +6 -6
- package/build/js/data.min.js +2 -2
- package/build/js/i18n/en/interface.js +1 -0
- package/build/js/intlTelInput.d.ts +22 -4
- package/build/js/intlTelInput.js +187 -119
- package/build/js/intlTelInput.min.js +13 -2
- package/build/js/intlTelInputWithUtils.js +251 -204
- package/build/js/intlTelInputWithUtils.min.js +13 -2
- package/build/js/utils.js +22 -21
- package/package.json +9 -12
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +186 -118
- package/react/build/IntlTelInput.d.ts +22 -4
- package/react/build/IntlTelInput.js +186 -118
- package/react/build/IntlTelInputWithUtils.cjs +250 -203
- package/react/build/IntlTelInputWithUtils.js +250 -203
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +333 -274
- package/vue/build/IntlTelInputWithUtils.mjs +800 -763
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mergeModels as
|
|
2
|
-
const
|
|
1
|
+
import { mergeModels as A, useModel as E, ref as N, onMounted as M, watch as B, onUnmounted as R, withDirectives as F, createElementBlock as z, openBlock as V, mergeProps as O, vModelText as $ } from "vue";
|
|
2
|
+
const j = [
|
|
3
3
|
[
|
|
4
4
|
"af",
|
|
5
5
|
// Afghanistan
|
|
@@ -1322,21 +1322,20 @@ const N = [
|
|
|
1322
1322
|
// Zimbabwe
|
|
1323
1323
|
"263"
|
|
1324
1324
|
]
|
|
1325
|
-
],
|
|
1326
|
-
for (
|
|
1327
|
-
|
|
1328
|
-
I[h] = {
|
|
1325
|
+
], w = [];
|
|
1326
|
+
for (const d of j)
|
|
1327
|
+
w.push({
|
|
1329
1328
|
name: "",
|
|
1330
|
-
//
|
|
1331
|
-
iso2:
|
|
1332
|
-
dialCode:
|
|
1333
|
-
priority:
|
|
1334
|
-
areaCodes:
|
|
1329
|
+
// populated in the plugin
|
|
1330
|
+
iso2: d[0],
|
|
1331
|
+
dialCode: d[1],
|
|
1332
|
+
priority: d[2] || 0,
|
|
1333
|
+
areaCodes: d[3] || null,
|
|
1335
1334
|
nodeById: {},
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
}
|
|
1339
|
-
const
|
|
1335
|
+
// populated by the plugin
|
|
1336
|
+
nationalPrefix: d[4] || null
|
|
1337
|
+
});
|
|
1338
|
+
const U = {
|
|
1340
1339
|
ad: "Andorra",
|
|
1341
1340
|
ae: "United Arab Emirates",
|
|
1342
1341
|
af: "Afghanistan",
|
|
@@ -1579,22 +1578,29 @@ const j = {
|
|
|
1579
1578
|
za: "South Africa",
|
|
1580
1579
|
zm: "Zambia",
|
|
1581
1580
|
zw: "Zimbabwe"
|
|
1582
|
-
},
|
|
1581
|
+
}, H = {
|
|
1583
1582
|
selectedCountryAriaLabel: "Selected country",
|
|
1584
1583
|
noCountrySelected: "No country selected",
|
|
1585
1584
|
countryListAriaLabel: "List of countries",
|
|
1586
1585
|
searchPlaceholder: "Search",
|
|
1586
|
+
clearSearchAriaLabel: "Clear search",
|
|
1587
1587
|
zeroSearchResults: "No results found",
|
|
1588
1588
|
oneSearchResult: "1 result found",
|
|
1589
1589
|
multipleSearchResults: "${count} results found",
|
|
1590
1590
|
// additional countries (not supported by country-list library)
|
|
1591
1591
|
ac: "Ascension Island",
|
|
1592
1592
|
xk: "Kosovo"
|
|
1593
|
-
},
|
|
1594
|
-
for (
|
|
1595
|
-
|
|
1596
|
-
let
|
|
1597
|
-
const
|
|
1593
|
+
}, T = { ...U, ...H };
|
|
1594
|
+
for (const d of w)
|
|
1595
|
+
d.name = T[d.iso2];
|
|
1596
|
+
let K = 0;
|
|
1597
|
+
const S = (d) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(d).matches, W = () => {
|
|
1598
|
+
if (typeof navigator < "u" && typeof window < "u") {
|
|
1599
|
+
const d = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), t = S("(max-width: 500px)"), e = S("(max-height: 600px)"), i = S("(pointer: coarse)");
|
|
1600
|
+
return d || t || i && e;
|
|
1601
|
+
}
|
|
1602
|
+
return !1;
|
|
1603
|
+
}, x = {
|
|
1598
1604
|
//* Whether or not to allow the dropdown.
|
|
1599
1605
|
allowDropdown: !0,
|
|
1600
1606
|
//* Add a placeholder in the input with an example number for the selected country.
|
|
@@ -1640,16 +1646,10 @@ const T = {
|
|
|
1640
1646
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1641
1647
|
strictMode: !1,
|
|
1642
1648
|
//* Use full screen popup instead of dropdown for country list.
|
|
1643
|
-
useFullscreenPopup:
|
|
1644
|
-
//* We cannot just test screen size as some smartphones/website meta tags will report desktop resolutions.
|
|
1645
|
-
//* Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
|
|
1646
|
-
/Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
1647
|
-
navigator.userAgent
|
|
1648
|
-
) || window.innerWidth <= 500
|
|
1649
|
-
) : !1,
|
|
1649
|
+
useFullscreenPopup: W(),
|
|
1650
1650
|
//* The number type to enforce during validation.
|
|
1651
1651
|
validationNumberTypes: ["MOBILE"]
|
|
1652
|
-
},
|
|
1652
|
+
}, q = [
|
|
1653
1653
|
"800",
|
|
1654
1654
|
"822",
|
|
1655
1655
|
"833",
|
|
@@ -1667,40 +1667,47 @@ const T = {
|
|
|
1667
1667
|
"887",
|
|
1668
1668
|
"888",
|
|
1669
1669
|
"889"
|
|
1670
|
-
],
|
|
1671
|
-
const t =
|
|
1670
|
+
], L = (d) => d.replace(/\D/g, ""), k = (d = "") => d.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), P = (d) => {
|
|
1671
|
+
const t = L(d);
|
|
1672
1672
|
if (t.charAt(0) === "1") {
|
|
1673
|
-
const e = t.
|
|
1674
|
-
return
|
|
1673
|
+
const e = t.substring(1, 4);
|
|
1674
|
+
return q.includes(e);
|
|
1675
1675
|
}
|
|
1676
1676
|
return !1;
|
|
1677
|
-
},
|
|
1677
|
+
}, G = (d, t, e, i) => {
|
|
1678
1678
|
if (e === 0 && !i)
|
|
1679
1679
|
return 0;
|
|
1680
1680
|
let s = 0;
|
|
1681
1681
|
for (let n = 0; n < t.length; n++) {
|
|
1682
|
-
if (/[+0-9]/.test(t[n]) && s++, s ===
|
|
1682
|
+
if (/[+0-9]/.test(t[n]) && s++, s === d && !i)
|
|
1683
1683
|
return n + 1;
|
|
1684
|
-
if (i && s ===
|
|
1684
|
+
if (i && s === d + 1)
|
|
1685
1685
|
return n;
|
|
1686
1686
|
}
|
|
1687
1687
|
return t.length;
|
|
1688
|
-
},
|
|
1689
|
-
const i = document.createElement(
|
|
1688
|
+
}, C = (d, t, e) => {
|
|
1689
|
+
const i = document.createElement(d);
|
|
1690
1690
|
return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
|
|
1691
|
-
},
|
|
1691
|
+
}, I = (d, ...t) => {
|
|
1692
1692
|
const { instances: e } = u;
|
|
1693
|
-
Object.values(e).forEach((i) => i[
|
|
1693
|
+
Object.values(e).forEach((i) => i[d](...t));
|
|
1694
1694
|
};
|
|
1695
|
-
class
|
|
1695
|
+
class D {
|
|
1696
|
+
/**
|
|
1697
|
+
* Build a space-delimited class string from an object map of className -> truthy/falsey.
|
|
1698
|
+
* Only keys with truthy values are included.
|
|
1699
|
+
*/
|
|
1700
|
+
static _buildClassNames(t) {
|
|
1701
|
+
return Object.keys(t).filter((e) => !!t[e]).join(" ");
|
|
1702
|
+
}
|
|
1696
1703
|
constructor(t, e = {}) {
|
|
1697
|
-
this.id =
|
|
1704
|
+
this.id = K++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, x, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder");
|
|
1698
1705
|
}
|
|
1699
1706
|
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
1700
1707
|
_init() {
|
|
1701
1708
|
this.options.useFullscreenPopup && (this.options.fixDropdownWidth = !1), this.options.onlyCountries.length === 1 && (this.options.initialCountry = this.options.onlyCountries[0]), this.options.separateDialCode && (this.options.nationalMode = !1), this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode && (this.options.nationalMode = !1), this.options.useFullscreenPopup && !this.options.dropdownContainer && (this.options.dropdownContainer = document.body), this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.telInput.dir = "ltr";
|
|
1702
1709
|
const t = this.options.allowDropdown || this.options.separateDialCode;
|
|
1703
|
-
this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft), this.options.i18n = { ...
|
|
1710
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft), this.options.i18n = { ...T, ...this.options.i18n };
|
|
1704
1711
|
const e = new Promise((s, n) => {
|
|
1705
1712
|
this.resolveAutoCountryPromise = s, this.rejectAutoCountryPromise = n;
|
|
1706
1713
|
}), i = new Promise((s, n) => {
|
|
@@ -1713,16 +1720,21 @@ class W {
|
|
|
1713
1720
|
//********************
|
|
1714
1721
|
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
1715
1722
|
_processCountryData() {
|
|
1716
|
-
this._processAllCountries(), this._processDialCodes(), this._translateCountryNames(), this._sortCountries();
|
|
1723
|
+
this._processAllCountries(), this._processDialCodes(), this._translateCountryNames(), this._sortCountries(), this.countryByIso2 = new Map(this.countries.map((t) => [t.iso2, t])), this._cacheSearchTokens();
|
|
1724
|
+
}
|
|
1725
|
+
//* Precompute and cache country search tokens to speed up filtering
|
|
1726
|
+
_cacheSearchTokens() {
|
|
1727
|
+
for (const t of this.countries)
|
|
1728
|
+
t.normalisedName = k(t.name), t.initials = t.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((e) => e[0]).join("").toLowerCase(), t.dialCodePlus = `+${t.dialCode}`;
|
|
1717
1729
|
}
|
|
1718
1730
|
//* Sort countries by countryOrder option (if present), then name.
|
|
1719
1731
|
_sortCountries() {
|
|
1720
1732
|
this.options.countryOrder && (this.options.countryOrder = this.options.countryOrder.map((t) => t.toLowerCase())), this.countries.sort((t, e) => {
|
|
1721
1733
|
const { countryOrder: i } = this.options;
|
|
1722
1734
|
if (i) {
|
|
1723
|
-
const s = i.indexOf(t.iso2), n = i.indexOf(e.iso2), o = s > -1,
|
|
1724
|
-
if (o ||
|
|
1725
|
-
return o &&
|
|
1735
|
+
const s = i.indexOf(t.iso2), n = i.indexOf(e.iso2), o = s > -1, l = n > -1;
|
|
1736
|
+
if (o || l)
|
|
1737
|
+
return o && l ? s - n : o ? -1 : 1;
|
|
1726
1738
|
}
|
|
1727
1739
|
return t.name.localeCompare(e.name);
|
|
1728
1740
|
});
|
|
@@ -1730,11 +1742,11 @@ class W {
|
|
|
1730
1742
|
//* Add a dial code to this.dialCodeToIso2Map.
|
|
1731
1743
|
_addToDialCodeMap(t, e, i) {
|
|
1732
1744
|
e.length > this.dialCodeMaxLen && (this.dialCodeMaxLen = e.length), this.dialCodeToIso2Map.hasOwnProperty(e) || (this.dialCodeToIso2Map[e] = []);
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1745
|
+
const s = this.dialCodeToIso2Map[e];
|
|
1746
|
+
if (s.includes(t))
|
|
1747
|
+
return;
|
|
1748
|
+
const n = i !== void 0 ? i : s.length;
|
|
1749
|
+
s[n] = t;
|
|
1738
1750
|
}
|
|
1739
1751
|
//* Process onlyCountries or excludeCountries array if present.
|
|
1740
1752
|
_processAllCountries() {
|
|
@@ -1743,51 +1755,46 @@ class W {
|
|
|
1743
1755
|
const i = t.map(
|
|
1744
1756
|
(s) => s.toLowerCase()
|
|
1745
1757
|
);
|
|
1746
|
-
this.countries =
|
|
1758
|
+
this.countries = w.filter(
|
|
1747
1759
|
(s) => i.includes(s.iso2)
|
|
1748
1760
|
);
|
|
1749
1761
|
} else if (e.length) {
|
|
1750
1762
|
const i = e.map(
|
|
1751
1763
|
(s) => s.toLowerCase()
|
|
1752
1764
|
);
|
|
1753
|
-
this.countries =
|
|
1765
|
+
this.countries = w.filter(
|
|
1754
1766
|
(s) => !i.includes(s.iso2)
|
|
1755
1767
|
);
|
|
1756
1768
|
} else
|
|
1757
|
-
this.countries =
|
|
1769
|
+
this.countries = w;
|
|
1758
1770
|
}
|
|
1759
1771
|
//* Translate Countries by object literal provided on config.
|
|
1760
1772
|
_translateCountryNames() {
|
|
1761
|
-
for (
|
|
1762
|
-
const e =
|
|
1763
|
-
this.options.i18n.hasOwnProperty(e) && (
|
|
1773
|
+
for (const t of this.countries) {
|
|
1774
|
+
const e = t.iso2.toLowerCase();
|
|
1775
|
+
this.options.i18n.hasOwnProperty(e) && (t.name = this.options.i18n[e]);
|
|
1764
1776
|
}
|
|
1765
1777
|
}
|
|
1766
1778
|
//* Generate this.dialCodes and this.dialCodeToIso2Map.
|
|
1767
1779
|
_processDialCodes() {
|
|
1768
|
-
this.dialCodes =
|
|
1769
|
-
for (
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
const n = e.areaCodes[s];
|
|
1779
|
-
for (let o = 1; o < n.length; o++) {
|
|
1780
|
-
const r = n.substr(0, o), a = e.dialCode + r;
|
|
1781
|
-
this._addToDialCodeMap(i, a), this._addToDialCodeMap(e.iso2, a);
|
|
1780
|
+
this.dialCodes = /* @__PURE__ */ new Set(), this.dialCodeMaxLen = 0, this.dialCodeToIso2Map = {};
|
|
1781
|
+
for (const t of this.countries)
|
|
1782
|
+
this.dialCodes.has(t.dialCode) || this.dialCodes.add(t.dialCode), this._addToDialCodeMap(t.iso2, t.dialCode, t.priority);
|
|
1783
|
+
for (const t of this.countries)
|
|
1784
|
+
if (t.areaCodes) {
|
|
1785
|
+
const e = this.dialCodeToIso2Map[t.dialCode][0];
|
|
1786
|
+
for (const i of t.areaCodes) {
|
|
1787
|
+
for (let s = 1; s < i.length; s++) {
|
|
1788
|
+
const n = i.substring(0, s), o = t.dialCode + n;
|
|
1789
|
+
this._addToDialCodeMap(e, o), this._addToDialCodeMap(t.iso2, o);
|
|
1782
1790
|
}
|
|
1783
|
-
this._addToDialCodeMap(
|
|
1791
|
+
this._addToDialCodeMap(t.iso2, t.dialCode + i);
|
|
1784
1792
|
}
|
|
1785
1793
|
}
|
|
1786
|
-
}
|
|
1787
1794
|
}
|
|
1788
1795
|
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
|
|
1789
1796
|
_generateMarkup() {
|
|
1790
|
-
var
|
|
1797
|
+
var a, h, _;
|
|
1791
1798
|
this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off");
|
|
1792
1799
|
const {
|
|
1793
1800
|
allowDropdown: t,
|
|
@@ -1796,110 +1803,168 @@ class W {
|
|
|
1796
1803
|
containerClass: s,
|
|
1797
1804
|
hiddenInput: n,
|
|
1798
1805
|
dropdownContainer: o,
|
|
1799
|
-
fixDropdownWidth:
|
|
1800
|
-
useFullscreenPopup:
|
|
1806
|
+
fixDropdownWidth: l,
|
|
1807
|
+
useFullscreenPopup: r,
|
|
1801
1808
|
countrySearch: c,
|
|
1802
|
-
i18n:
|
|
1803
|
-
} = this.options
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
+
i18n: p
|
|
1810
|
+
} = this.options, y = D._buildClassNames({
|
|
1811
|
+
iti: !0,
|
|
1812
|
+
"iti--allow-dropdown": t,
|
|
1813
|
+
"iti--show-flags": i,
|
|
1814
|
+
"iti--inline-dropdown": !r,
|
|
1815
|
+
[s]: !!s
|
|
1816
|
+
}), m = C("div", { class: y });
|
|
1817
|
+
if ((a = this.telInput.parentNode) == null || a.insertBefore(m, this.telInput), t || i || e) {
|
|
1818
|
+
this.countryContainer = C(
|
|
1809
1819
|
"div",
|
|
1810
1820
|
{ class: "iti__country-container" },
|
|
1811
|
-
|
|
1812
|
-
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", t ? (this.selectedCountry =
|
|
1821
|
+
m
|
|
1822
|
+
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", t ? (this.selectedCountry = C(
|
|
1813
1823
|
"button",
|
|
1814
1824
|
{
|
|
1815
1825
|
type: "button",
|
|
1816
1826
|
class: "iti__selected-country",
|
|
1817
1827
|
"aria-expanded": "false",
|
|
1818
1828
|
"aria-label": this.options.i18n.selectedCountryAriaLabel,
|
|
1819
|
-
"aria-haspopup": "
|
|
1820
|
-
"aria-controls": `iti-${this.id}__dropdown-content
|
|
1821
|
-
role: "combobox"
|
|
1829
|
+
"aria-haspopup": "dialog",
|
|
1830
|
+
"aria-controls": `iti-${this.id}__dropdown-content`
|
|
1822
1831
|
},
|
|
1823
1832
|
this.countryContainer
|
|
1824
|
-
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry =
|
|
1833
|
+
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = C(
|
|
1825
1834
|
"div",
|
|
1826
1835
|
{ class: "iti__selected-country" },
|
|
1827
1836
|
this.countryContainer
|
|
1828
1837
|
);
|
|
1829
|
-
const b =
|
|
1830
|
-
if (this.selectedCountryInner =
|
|
1838
|
+
const b = C("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
|
|
1839
|
+
if (this.selectedCountryInner = C("div", { class: "iti__flag" }, b), this.selectedCountryA11yText = C(
|
|
1831
1840
|
"span",
|
|
1832
1841
|
{ class: "iti__a11y-text" },
|
|
1833
1842
|
this.selectedCountryInner
|
|
1834
|
-
), t && (this.dropdownArrow =
|
|
1843
|
+
), t && (this.dropdownArrow = C(
|
|
1835
1844
|
"div",
|
|
1836
1845
|
{ class: "iti__arrow", "aria-hidden": "true" },
|
|
1837
1846
|
b
|
|
1838
|
-
)), e && (this.selectedDialCode =
|
|
1847
|
+
)), e && (this.selectedDialCode = C(
|
|
1839
1848
|
"div",
|
|
1840
1849
|
{ class: "iti__selected-dial-code", "aria-hidden": "true", dir: "ltr" },
|
|
1841
1850
|
this.selectedCountry
|
|
1842
1851
|
)), t) {
|
|
1843
|
-
const f =
|
|
1844
|
-
if (this.dropdownContent =
|
|
1852
|
+
const f = l ? "" : "iti--flexible-dropdown-width";
|
|
1853
|
+
if (this.dropdownContent = C("div", {
|
|
1845
1854
|
id: `iti-${this.id}__dropdown-content`,
|
|
1846
|
-
class: `iti__dropdown-content iti__hide ${f}
|
|
1847
|
-
|
|
1848
|
-
"
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
"
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1855
|
+
class: `iti__dropdown-content iti__hide ${f}`,
|
|
1856
|
+
role: "dialog",
|
|
1857
|
+
"aria-modal": "true"
|
|
1858
|
+
}), c) {
|
|
1859
|
+
const g = C(
|
|
1860
|
+
"div",
|
|
1861
|
+
{ class: "iti__search-input-wrapper" },
|
|
1862
|
+
this.dropdownContent
|
|
1863
|
+
);
|
|
1864
|
+
this.searchIcon = C(
|
|
1865
|
+
"span",
|
|
1866
|
+
{
|
|
1867
|
+
class: "iti__search-icon",
|
|
1868
|
+
"aria-hidden": "true"
|
|
1869
|
+
},
|
|
1870
|
+
g
|
|
1871
|
+
), this.searchIcon.innerHTML = `
|
|
1872
|
+
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
|
|
1873
|
+
<circle cx="11" cy="11" r="7" />
|
|
1874
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1875
|
+
</svg>`, this.searchInput = C(
|
|
1876
|
+
"input",
|
|
1877
|
+
{
|
|
1878
|
+
id: `iti-${this.id}__search-input`,
|
|
1879
|
+
// Chrome says inputs need either a name or an id
|
|
1880
|
+
type: "search",
|
|
1881
|
+
class: "iti__search-input",
|
|
1882
|
+
placeholder: p.searchPlaceholder,
|
|
1883
|
+
// 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
|
|
1884
|
+
role: "combobox",
|
|
1885
|
+
"aria-expanded": "true",
|
|
1886
|
+
"aria-label": p.searchPlaceholder,
|
|
1887
|
+
"aria-controls": `iti-${this.id}__country-listbox`,
|
|
1888
|
+
"aria-autocomplete": "list",
|
|
1889
|
+
autocomplete: "off"
|
|
1890
|
+
},
|
|
1891
|
+
g
|
|
1892
|
+
), this.searchClearButton = C(
|
|
1893
|
+
"button",
|
|
1894
|
+
{
|
|
1895
|
+
type: "button",
|
|
1896
|
+
class: "iti__search-clear iti__hide",
|
|
1897
|
+
"aria-label": p.clearSearchAriaLabel,
|
|
1898
|
+
tabindex: "-1"
|
|
1899
|
+
},
|
|
1900
|
+
g
|
|
1901
|
+
);
|
|
1902
|
+
const v = `iti-${this.id}-clear-mask`;
|
|
1903
|
+
this.searchClearButton.innerHTML = `
|
|
1904
|
+
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
|
1905
|
+
<mask id="${v}" maskUnits="userSpaceOnUse">
|
|
1906
|
+
<rect width="16" height="16" fill="white" />
|
|
1907
|
+
<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" />
|
|
1908
|
+
</mask>
|
|
1909
|
+
<circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${v})" />
|
|
1910
|
+
</svg>`, this.searchResultsA11yText = C(
|
|
1911
|
+
"span",
|
|
1912
|
+
{ class: "iti__a11y-text" },
|
|
1913
|
+
this.dropdownContent
|
|
1914
|
+
), this.searchNoResults = C(
|
|
1915
|
+
"div",
|
|
1916
|
+
{
|
|
1917
|
+
class: "iti__no-results iti__hide",
|
|
1918
|
+
"aria-hidden": "true"
|
|
1919
|
+
// all a11y messaging happens in this.searchResultsA11yText
|
|
1920
|
+
},
|
|
1921
|
+
this.dropdownContent
|
|
1922
|
+
), this.searchNoResults.textContent = p.zeroSearchResults;
|
|
1923
|
+
}
|
|
1924
|
+
if (this.countryList = C(
|
|
1866
1925
|
"ul",
|
|
1867
1926
|
{
|
|
1868
1927
|
class: "iti__country-list",
|
|
1869
1928
|
id: `iti-${this.id}__country-listbox`,
|
|
1870
1929
|
role: "listbox",
|
|
1871
|
-
"aria-label":
|
|
1930
|
+
"aria-label": p.countryListAriaLabel
|
|
1872
1931
|
},
|
|
1873
1932
|
this.dropdownContent
|
|
1874
|
-
), this._appendListItems(), c && this.
|
|
1875
|
-
|
|
1876
|
-
|
|
1933
|
+
), this._appendListItems(), c && this._updateSearchResultsA11yText(), o) {
|
|
1934
|
+
const g = D._buildClassNames({
|
|
1935
|
+
iti: !0,
|
|
1936
|
+
"iti--container": !0,
|
|
1937
|
+
"iti--fullscreen-popup": r,
|
|
1938
|
+
"iti--inline-dropdown": !r,
|
|
1939
|
+
[s]: !!s
|
|
1940
|
+
});
|
|
1941
|
+
this.dropdown = C("div", { class: g }), this.dropdown.appendChild(this.dropdownContent);
|
|
1877
1942
|
} else
|
|
1878
1943
|
this.countryContainer.appendChild(this.dropdownContent);
|
|
1879
1944
|
}
|
|
1880
1945
|
}
|
|
1881
|
-
if (
|
|
1946
|
+
if (m.appendChild(this.telInput), this._updateInputPadding(), n) {
|
|
1882
1947
|
const b = this.telInput.getAttribute("name") || "", f = n(b);
|
|
1883
1948
|
if (f.phone) {
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1949
|
+
const g = (h = this.telInput.form) == null ? void 0 : h.querySelector(`input[name="${f.phone}"]`);
|
|
1950
|
+
g ? this.hiddenInput = g : (this.hiddenInput = C("input", {
|
|
1886
1951
|
type: "hidden",
|
|
1887
1952
|
name: f.phone
|
|
1888
|
-
}),
|
|
1953
|
+
}), m.appendChild(this.hiddenInput));
|
|
1889
1954
|
}
|
|
1890
1955
|
if (f.country) {
|
|
1891
|
-
const
|
|
1892
|
-
|
|
1956
|
+
const g = (_ = this.telInput.form) == null ? void 0 : _.querySelector(`input[name="${f.country}"]`);
|
|
1957
|
+
g ? this.hiddenInputCountry = g : (this.hiddenInputCountry = C("input", {
|
|
1893
1958
|
type: "hidden",
|
|
1894
1959
|
name: f.country
|
|
1895
|
-
}),
|
|
1960
|
+
}), m.appendChild(this.hiddenInputCountry));
|
|
1896
1961
|
}
|
|
1897
1962
|
}
|
|
1898
1963
|
}
|
|
1899
1964
|
//* For each country: add a country list item <li> to the countryList <ul> container.
|
|
1900
1965
|
_appendListItems() {
|
|
1901
1966
|
for (let t = 0; t < this.countries.length; t++) {
|
|
1902
|
-
const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s =
|
|
1967
|
+
const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s = C(
|
|
1903
1968
|
"li",
|
|
1904
1969
|
{
|
|
1905
1970
|
id: `iti-${this.id}__item-${e.iso2}`,
|
|
@@ -1921,12 +1986,12 @@ class W {
|
|
|
1921
1986
|
//* 1. Extracting a dial code from the given number
|
|
1922
1987
|
//* 2. Using explicit initialCountry
|
|
1923
1988
|
_setInitialState(t = !1) {
|
|
1924
|
-
const e = this.telInput.getAttribute("value"), i = this.telInput.value, n = e && e.charAt(0) === "+" && (!i || i.charAt(0) !== "+") ? e : i, o = this._getDialCode(n),
|
|
1925
|
-
if (o && !
|
|
1989
|
+
const e = this.telInput.getAttribute("value"), i = this.telInput.value, n = e && e.charAt(0) === "+" && (!i || i.charAt(0) !== "+") ? e : i, o = this._getDialCode(n), l = P(n), { initialCountry: r, geoIpLookup: c } = this.options, p = r === "auto" && c;
|
|
1990
|
+
if (o && !l)
|
|
1926
1991
|
this._updateCountryFromNumber(n);
|
|
1927
|
-
else if (!
|
|
1928
|
-
const
|
|
1929
|
-
|
|
1992
|
+
else if (!p || t) {
|
|
1993
|
+
const y = r ? r.toLowerCase() : "";
|
|
1994
|
+
y && this._getCountryData(y, !0) ? this._setCountry(y) : o && l ? this._setCountry("us") : this._setCountry();
|
|
1930
1995
|
}
|
|
1931
1996
|
n && this._updateValFromNumber(n);
|
|
1932
1997
|
}
|
|
@@ -1973,10 +2038,10 @@ class W {
|
|
|
1973
2038
|
u.autoCountry ? this.handleAutoCountry() : u.startedLoadingAutoCountry || (u.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(
|
|
1974
2039
|
(t = "") => {
|
|
1975
2040
|
const e = t.toLowerCase();
|
|
1976
|
-
e && this._getCountryData(e, !0) ? (u.autoCountry = e, setTimeout(() =>
|
|
2041
|
+
e && this._getCountryData(e, !0) ? (u.autoCountry = e, setTimeout(() => I("handleAutoCountry"))) : (this._setInitialState(!0), I("rejectAutoCountryPromise"));
|
|
1977
2042
|
},
|
|
1978
2043
|
() => {
|
|
1979
|
-
this._setInitialState(!0),
|
|
2044
|
+
this._setInitialState(!0), I("rejectAutoCountryPromise");
|
|
1980
2045
|
}
|
|
1981
2046
|
));
|
|
1982
2047
|
}
|
|
@@ -1986,30 +2051,30 @@ class W {
|
|
|
1986
2051
|
//* Initialize the tel input listeners.
|
|
1987
2052
|
_initTelInputListeners() {
|
|
1988
2053
|
const { strictMode: t, formatAsYouType: e, separateDialCode: i, formatOnDisplay: s, allowDropdown: n, countrySearch: o } = this.options;
|
|
1989
|
-
let
|
|
1990
|
-
new RegExp("\\p{L}", "u").test(this.telInput.value) && (
|
|
1991
|
-
if (this.isAndroid && (
|
|
1992
|
-
const
|
|
1993
|
-
this.telInput.value =
|
|
2054
|
+
let l = !1;
|
|
2055
|
+
new RegExp("\\p{L}", "u").test(this.telInput.value) && (l = !0), this._handleInputEvent = (r) => {
|
|
2056
|
+
if (this.isAndroid && (r == null ? void 0 : r.data) === "+" && i && n && o) {
|
|
2057
|
+
const m = this.telInput.selectionStart || 0, a = this.telInput.value.substring(0, m - 1), h = this.telInput.value.substring(m);
|
|
2058
|
+
this.telInput.value = a + h, this._openDropdownWithPlus();
|
|
1994
2059
|
return;
|
|
1995
2060
|
}
|
|
1996
2061
|
this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
|
|
1997
|
-
const c = (
|
|
1998
|
-
c ||
|
|
1999
|
-
const
|
|
2000
|
-
if (e && !
|
|
2001
|
-
const
|
|
2062
|
+
const c = (r == null ? void 0 : r.data) && /[^+0-9]/.test(r.data), p = (r == null ? void 0 : r.inputType) === "insertFromPaste" && this.telInput.value;
|
|
2063
|
+
c || p && !t ? l = !0 : /[^+0-9]/.test(this.telInput.value) || (l = !1);
|
|
2064
|
+
const y = (r == null ? void 0 : r.detail) && r.detail.isSetNumber && !s;
|
|
2065
|
+
if (e && !l && !y) {
|
|
2066
|
+
const m = this.telInput.selectionStart || 0, h = this.telInput.value.substring(0, m).replace(/[^+0-9]/g, "").length, _ = (r == null ? void 0 : r.inputType) === "deleteContentForward", b = this._formatNumberAsYouType(), f = G(h, b, m, _);
|
|
2002
2067
|
this.telInput.value = b, this.telInput.setSelectionRange(f, f);
|
|
2003
2068
|
}
|
|
2004
|
-
}, this.telInput.addEventListener("input", this._handleInputEvent), (t || i) && (this._handleKeydownEvent = (
|
|
2005
|
-
if (
|
|
2006
|
-
if (i && n && o &&
|
|
2007
|
-
|
|
2069
|
+
}, this.telInput.addEventListener("input", this._handleInputEvent), (t || i) && (this._handleKeydownEvent = (r) => {
|
|
2070
|
+
if (r.key && r.key.length === 1 && !r.altKey && !r.ctrlKey && !r.metaKey) {
|
|
2071
|
+
if (i && n && o && r.key === "+") {
|
|
2072
|
+
r.preventDefault(), this._openDropdownWithPlus();
|
|
2008
2073
|
return;
|
|
2009
2074
|
}
|
|
2010
2075
|
if (t) {
|
|
2011
|
-
const c = this.telInput.value,
|
|
2012
|
-
(!
|
|
2076
|
+
const c = this.telInput.value, y = !(c.charAt(0) === "+") && this.telInput.selectionStart === 0 && r.key === "+", m = /^[0-9]$/.test(r.key), a = i ? m : y || m, h = c.slice(0, this.telInput.selectionStart) + r.key + c.slice(this.telInput.selectionEnd), _ = this._getFullNumber(h), b = u.utils.getCoreNumber(_, this.selectedCountryData.iso2), f = this.maxCoreNumberLength && b.length > this.maxCoreNumberLength, v = this._getNewCountryFromNumber(_) !== null;
|
|
2077
|
+
(!a || f && !v && !y) && r.preventDefault();
|
|
2013
2078
|
}
|
|
2014
2079
|
}
|
|
2015
2080
|
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
|
|
@@ -2017,7 +2082,7 @@ class W {
|
|
|
2017
2082
|
//* Adhere to the input's maxlength attr.
|
|
2018
2083
|
_cap(t) {
|
|
2019
2084
|
const e = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
|
|
2020
|
-
return e && t.length > e ? t.
|
|
2085
|
+
return e && t.length > e ? t.substring(0, e) : t;
|
|
2021
2086
|
}
|
|
2022
2087
|
//* Trigger a custom event on the input.
|
|
2023
2088
|
_trigger(t, e = {}) {
|
|
@@ -2073,52 +2138,50 @@ class W {
|
|
|
2073
2138
|
}, document.addEventListener("keydown", this._handleKeydownOnDropdown), this.options.countrySearch) {
|
|
2074
2139
|
const s = () => {
|
|
2075
2140
|
const o = this.searchInput.value.trim();
|
|
2076
|
-
o ? this._filterCountries(o) : this._filterCountries("", !0);
|
|
2141
|
+
o ? this._filterCountries(o) : this._filterCountries("", !0), this.searchInput.value ? this.searchClearButton.classList.remove("iti__hide") : this.searchClearButton.classList.add("iti__hide");
|
|
2077
2142
|
};
|
|
2078
2143
|
let n = null;
|
|
2079
2144
|
this._handleSearchChange = () => {
|
|
2080
2145
|
n && clearTimeout(n), n = setTimeout(() => {
|
|
2081
2146
|
s(), n = null;
|
|
2082
2147
|
}, 100);
|
|
2083
|
-
}, this.searchInput.addEventListener("input", this._handleSearchChange), this.
|
|
2148
|
+
}, this.searchInput.addEventListener("input", this._handleSearchChange), this._handleSearchClear = (o) => {
|
|
2149
|
+
o.stopPropagation(), this.searchInput.value = "", this.searchInput.focus(), s();
|
|
2150
|
+
}, this.searchClearButton.addEventListener("click", this._handleSearchClear), this.searchInput.addEventListener("click", (o) => o.stopPropagation());
|
|
2084
2151
|
}
|
|
2085
2152
|
}
|
|
2086
2153
|
//* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
|
|
2087
2154
|
_searchForCountry(t) {
|
|
2088
|
-
for (
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
this._highlightListItem(n, !1), this._scrollTo(n);
|
|
2155
|
+
for (const e of this.countries)
|
|
2156
|
+
if (e.name.substring(0, t.length).toLowerCase() === t) {
|
|
2157
|
+
const s = e.nodeById[this.id];
|
|
2158
|
+
this._highlightListItem(s, !1), this._scrollTo(s);
|
|
2093
2159
|
break;
|
|
2094
2160
|
}
|
|
2095
|
-
}
|
|
2096
2161
|
}
|
|
2097
2162
|
//* Country search enabled: Filter the countries according to the search query.
|
|
2098
2163
|
_filterCountries(t, e = !1) {
|
|
2099
2164
|
let i = !0;
|
|
2100
2165
|
this.countryList.innerHTML = "";
|
|
2101
|
-
const s =
|
|
2102
|
-
for (
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
...
|
|
2108
|
-
...
|
|
2109
|
-
...
|
|
2110
|
-
...
|
|
2111
|
-
...y.sort((l, d) => l.priority - d.priority),
|
|
2112
|
-
...p.sort((l, d) => l.priority - d.priority)
|
|
2166
|
+
const s = k(t), n = s.length, o = [], l = [], r = [], c = [], p = [], y = [];
|
|
2167
|
+
for (const a of this.countries)
|
|
2168
|
+
e || n === 0 ? r.push(a) : a.iso2 === s ? o.push(a) : a.normalisedName.startsWith(s) ? l.push(a) : a.normalisedName.includes(s) ? r.push(a) : s === a.dialCode || s === a.dialCodePlus ? c.push(a) : a.dialCodePlus.includes(s) ? p.push(a) : a.initials.includes(s) && y.push(a);
|
|
2169
|
+
const m = [
|
|
2170
|
+
...o.sort((a, h) => a.priority - h.priority),
|
|
2171
|
+
...l.sort((a, h) => a.priority - h.priority),
|
|
2172
|
+
...r.sort((a, h) => a.priority - h.priority),
|
|
2173
|
+
...c.sort((a, h) => a.priority - h.priority),
|
|
2174
|
+
...p.sort((a, h) => a.priority - h.priority),
|
|
2175
|
+
...y.sort((a, h) => a.priority - h.priority)
|
|
2113
2176
|
];
|
|
2114
|
-
for (const
|
|
2115
|
-
const
|
|
2116
|
-
|
|
2177
|
+
for (const a of m) {
|
|
2178
|
+
const h = a.nodeById[this.id];
|
|
2179
|
+
h && (this.countryList.appendChild(h), i && (this._highlightListItem(h, !1), i = !1));
|
|
2117
2180
|
}
|
|
2118
|
-
i
|
|
2181
|
+
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();
|
|
2119
2182
|
}
|
|
2120
2183
|
//* Update search results text (for a11y).
|
|
2121
|
-
|
|
2184
|
+
_updateSearchResultsA11yText() {
|
|
2122
2185
|
const { i18n: t } = this.options, e = this.countryList.childElementCount;
|
|
2123
2186
|
let i;
|
|
2124
2187
|
"searchResultsText" in t ? i = t.searchResultsText(e) : e === 0 ? i = t.zeroSearchResults : e === 1 ? i = t.oneSearchResult : i = t.multipleSearchResults.replace("${count}", e.toString()), this.searchResultsA11yText.textContent = i;
|
|
@@ -2168,19 +2231,19 @@ class W {
|
|
|
2168
2231
|
let i = e ? t.substring(e) : t;
|
|
2169
2232
|
const s = this.selectedCountryData.iso2, n = this.selectedCountryData.dialCode;
|
|
2170
2233
|
i = this._ensureHasDialCode(i);
|
|
2171
|
-
const o = this._getDialCode(i, !0),
|
|
2234
|
+
const o = this._getDialCode(i, !0), l = L(i);
|
|
2172
2235
|
if (o) {
|
|
2173
|
-
const
|
|
2236
|
+
const r = L(o), c = this.dialCodeToIso2Map[r];
|
|
2174
2237
|
if (!s && this.defaultCountry && c.includes(this.defaultCountry))
|
|
2175
2238
|
return this.defaultCountry;
|
|
2176
|
-
const
|
|
2177
|
-
if (!(n === "1" &&
|
|
2178
|
-
for (
|
|
2179
|
-
if (
|
|
2180
|
-
return
|
|
2239
|
+
const p = this.selectedCountryData.areaCodes && l.length > r.length, y = s && c.includes(s) && !p;
|
|
2240
|
+
if (!(n === "1" && P(l)) && !y) {
|
|
2241
|
+
for (const a of c)
|
|
2242
|
+
if (a)
|
|
2243
|
+
return a;
|
|
2181
2244
|
}
|
|
2182
2245
|
} else {
|
|
2183
|
-
if (i.charAt(0) === "+" &&
|
|
2246
|
+
if (i.charAt(0) === "+" && l.length)
|
|
2184
2247
|
return "";
|
|
2185
2248
|
if ((!i || i === "+") && !this.selectedCountryData.iso2)
|
|
2186
2249
|
return this.defaultCountry;
|
|
@@ -2190,19 +2253,18 @@ class W {
|
|
|
2190
2253
|
//* Remove highlighting from other list items and highlight the given item.
|
|
2191
2254
|
_highlightListItem(t, e) {
|
|
2192
2255
|
const i = this.highlightedItem;
|
|
2193
|
-
if (i && (i.classList.remove("iti__highlight"), i.setAttribute("aria-selected", "false")), this.highlightedItem = t, this.highlightedItem) {
|
|
2194
|
-
this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true");
|
|
2256
|
+
if (i && (i.classList.remove("iti__highlight"), i.setAttribute("aria-selected", "false")), this.highlightedItem = t, this.highlightedItem && (this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true"), this.options.countrySearch)) {
|
|
2195
2257
|
const s = this.highlightedItem.getAttribute("id") || "";
|
|
2196
|
-
this.
|
|
2258
|
+
this.searchInput.setAttribute("aria-activedescendant", s);
|
|
2197
2259
|
}
|
|
2198
2260
|
e && this.highlightedItem.focus();
|
|
2199
2261
|
}
|
|
2200
2262
|
//* Find the country data for the given iso2 code
|
|
2201
|
-
//* the
|
|
2263
|
+
//* the allowFail option is only used during init() for the initialCountry option, and for the iso2 returned from geoIpLookup - in these 2 cases we don't want to error out
|
|
2202
2264
|
_getCountryData(t, e) {
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2265
|
+
const i = this.countryByIso2.get(t);
|
|
2266
|
+
if (i)
|
|
2267
|
+
return i;
|
|
2206
2268
|
if (e)
|
|
2207
2269
|
return null;
|
|
2208
2270
|
throw new Error(`No country data for '${t}'`);
|
|
@@ -2212,8 +2274,8 @@ class W {
|
|
|
2212
2274
|
_setCountry(t) {
|
|
2213
2275
|
const { separateDialCode: e, showFlags: i, i18n: s } = this.options, n = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
|
|
2214
2276
|
if (this.selectedCountryData = t ? this._getCountryData(t, !1) || {} : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.selectedCountryInner) {
|
|
2215
|
-
let o = "",
|
|
2216
|
-
t && i ? (o = `iti__flag iti__${t}`,
|
|
2277
|
+
let o = "", l = "";
|
|
2278
|
+
t && i ? (o = `iti__flag iti__${t}`, l = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`) : (o = "iti__flag iti__globe", l = s.noCountrySelected), this.selectedCountryInner.className = o, this.selectedCountryA11yText.textContent = l;
|
|
2217
2279
|
}
|
|
2218
2280
|
if (this._setSelectedCountryTitleAttribute(t, e), e) {
|
|
2219
2281
|
const o = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
@@ -2239,11 +2301,11 @@ class W {
|
|
|
2239
2301
|
!1,
|
|
2240
2302
|
n,
|
|
2241
2303
|
!0
|
|
2242
|
-
),
|
|
2304
|
+
), l = o;
|
|
2243
2305
|
for (; u.utils.isPossibleNumber(o, s, i); )
|
|
2244
|
-
|
|
2245
|
-
const
|
|
2246
|
-
this.maxCoreNumberLength =
|
|
2306
|
+
l = o, o += "0";
|
|
2307
|
+
const r = u.utils.getCoreNumber(l, s);
|
|
2308
|
+
this.maxCoreNumberLength = r.length, s === "by" && (this.maxCoreNumberLength = r.length + 1);
|
|
2247
2309
|
} else
|
|
2248
2310
|
this.maxCoreNumberLength = null;
|
|
2249
2311
|
}
|
|
@@ -2280,12 +2342,12 @@ class W {
|
|
|
2280
2342
|
} = this.options, n = t === "aggressive" || !this.hadInitialPlaceholder && t === "polite";
|
|
2281
2343
|
if (u.utils && n) {
|
|
2282
2344
|
const o = u.utils.numberType[e];
|
|
2283
|
-
let
|
|
2345
|
+
let l = this.selectedCountryData.iso2 ? u.utils.getExampleNumber(
|
|
2284
2346
|
this.selectedCountryData.iso2,
|
|
2285
2347
|
i,
|
|
2286
2348
|
o
|
|
2287
2349
|
) : "";
|
|
2288
|
-
|
|
2350
|
+
l = this._beforeSetNumber(l), typeof s == "function" && (l = s(l, this.selectedCountryData)), this.telInput.setAttribute("placeholder", l);
|
|
2289
2351
|
}
|
|
2290
2352
|
}
|
|
2291
2353
|
//* Called when the user selects a list item from the dropdown.
|
|
@@ -2297,7 +2359,7 @@ class W {
|
|
|
2297
2359
|
}
|
|
2298
2360
|
//* Close the dropdown and unbind any listeners.
|
|
2299
2361
|
_closeDropdown() {
|
|
2300
|
-
this.dropdownContent.classList.add("iti__hide"), this.selectedCountry.setAttribute("aria-expanded", "false"), this.
|
|
2362
|
+
this.dropdownContent.classList.add("iti__hide"), this.selectedCountry.setAttribute("aria-expanded", "false"), this.highlightedItem && this.highlightedItem.setAttribute("aria-selected", "false"), this.options.countrySearch && this.searchInput.removeAttribute("aria-activedescendant"), this.dropdownArrow.classList.remove("iti__arrow--up"), this.options.countrySearch && (this.searchInput.removeEventListener("input", this._handleSearchChange), this.searchClearButton.removeEventListener("click", this._handleSearchClear)), document.documentElement.removeEventListener(
|
|
2301
2363
|
"click",
|
|
2302
2364
|
this._handleClickOffToClose
|
|
2303
2365
|
), this.countryList.removeEventListener(
|
|
@@ -2307,12 +2369,12 @@ class W {
|
|
|
2307
2369
|
}
|
|
2308
2370
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2309
2371
|
_scrollTo(t) {
|
|
2310
|
-
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, n = e.getBoundingClientRect().top + i, o = n + s,
|
|
2311
|
-
if (
|
|
2312
|
-
e.scrollTop =
|
|
2372
|
+
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, n = e.getBoundingClientRect().top + i, o = n + s, l = t.offsetHeight, r = t.getBoundingClientRect().top + i, c = r + l, p = r - n + e.scrollTop;
|
|
2373
|
+
if (r < n)
|
|
2374
|
+
e.scrollTop = p;
|
|
2313
2375
|
else if (c > o) {
|
|
2314
|
-
const
|
|
2315
|
-
e.scrollTop =
|
|
2376
|
+
const y = s - l;
|
|
2377
|
+
e.scrollTop = p - y;
|
|
2316
2378
|
}
|
|
2317
2379
|
}
|
|
2318
2380
|
//* Replace any existing dial code with the new one
|
|
@@ -2335,9 +2397,9 @@ class W {
|
|
|
2335
2397
|
const o = t.charAt(n);
|
|
2336
2398
|
if (!isNaN(parseInt(o, 10))) {
|
|
2337
2399
|
if (s += o, e)
|
|
2338
|
-
this.dialCodeToIso2Map[s] && (i = t.
|
|
2339
|
-
else if (this.dialCodes
|
|
2340
|
-
i = t.
|
|
2400
|
+
this.dialCodeToIso2Map[s] && (i = t.substring(0, n + 1));
|
|
2401
|
+
else if (this.dialCodes.has(s)) {
|
|
2402
|
+
i = t.substring(0, n + 1);
|
|
2341
2403
|
break;
|
|
2342
2404
|
}
|
|
2343
2405
|
if (s.length === this.dialCodeMaxLen)
|
|
@@ -2351,7 +2413,7 @@ class W {
|
|
|
2351
2413
|
_getFullNumber(t) {
|
|
2352
2414
|
const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
|
|
2353
2415
|
let s;
|
|
2354
|
-
const n =
|
|
2416
|
+
const n = L(e);
|
|
2355
2417
|
return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
|
|
2356
2418
|
}
|
|
2357
2419
|
//* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
|
|
@@ -2362,7 +2424,7 @@ class W {
|
|
|
2362
2424
|
if (i) {
|
|
2363
2425
|
i = `+${this.selectedCountryData.dialCode}`;
|
|
2364
2426
|
const s = e[i.length] === " " || e[i.length] === "-" ? i.length + 1 : i.length;
|
|
2365
|
-
e = e.
|
|
2427
|
+
e = e.substring(s);
|
|
2366
2428
|
}
|
|
2367
2429
|
}
|
|
2368
2430
|
return this._cap(e);
|
|
@@ -2403,8 +2465,8 @@ class W {
|
|
|
2403
2465
|
"keydown",
|
|
2404
2466
|
this._handleCountryContainerKeydown
|
|
2405
2467
|
);
|
|
2406
|
-
const
|
|
2407
|
-
|
|
2468
|
+
const l = this.telInput.closest("label");
|
|
2469
|
+
l && l.removeEventListener("click", this._handleLabelClick);
|
|
2408
2470
|
}
|
|
2409
2471
|
const { form: i } = this.telInput;
|
|
2410
2472
|
this._handleHiddenInputSubmit && i && i.removeEventListener("submit", this._handleHiddenInputSubmit), this.telInput.removeEventListener("input", this._handleInputEvent), this._handleKeydownEvent && this.telInput.removeEventListener("keydown", this._handleKeydownEvent), this.telInput.removeAttribute("data-intl-tel-input-id"), e && (this.isRTL ? this.telInput.style.paddingRight = this.originalPaddingRight : this.telInput.style.paddingLeft = this.originalPaddingLeft);
|
|
@@ -2449,30 +2511,27 @@ class W {
|
|
|
2449
2511
|
}
|
|
2450
2512
|
return -99;
|
|
2451
2513
|
}
|
|
2452
|
-
//* Validate the input val
|
|
2514
|
+
//* Validate the input val (with precise=false)
|
|
2453
2515
|
isValidNumber() {
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
return s && n;
|
|
2460
|
-
}
|
|
2461
|
-
return this._utilsIsPossibleNumber(t);
|
|
2516
|
+
return this._validateNumber(!1);
|
|
2517
|
+
}
|
|
2518
|
+
//* Validate the input val (with precise=true)
|
|
2519
|
+
isValidNumberPrecise() {
|
|
2520
|
+
return this._validateNumber(!0);
|
|
2462
2521
|
}
|
|
2463
2522
|
_utilsIsPossibleNumber(t) {
|
|
2464
2523
|
return u.utils ? u.utils.isPossibleNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
|
|
2465
2524
|
}
|
|
2466
|
-
//*
|
|
2467
|
-
|
|
2525
|
+
//* Shared internal validation logic to handle alpha character extension rules.
|
|
2526
|
+
_validateNumber(t) {
|
|
2468
2527
|
if (!this.selectedCountryData.iso2)
|
|
2469
2528
|
return !1;
|
|
2470
|
-
const
|
|
2471
|
-
if (
|
|
2472
|
-
const
|
|
2473
|
-
return
|
|
2529
|
+
const e = this._getFullNumber(), i = e.search(new RegExp("\\p{L}", "u")), s = (n) => t ? this._utilsIsValidNumber(n) : this._utilsIsPossibleNumber(n);
|
|
2530
|
+
if (i > -1) {
|
|
2531
|
+
const n = e.substring(0, i), o = s(n), l = s(e);
|
|
2532
|
+
return o && l;
|
|
2474
2533
|
}
|
|
2475
|
-
return
|
|
2534
|
+
return s(e);
|
|
2476
2535
|
}
|
|
2477
2536
|
_utilsIsValidNumber(t) {
|
|
2478
2537
|
return u.utils ? u.utils.isValidNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
|
|
@@ -2495,53 +2554,53 @@ class W {
|
|
|
2495
2554
|
this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled");
|
|
2496
2555
|
}
|
|
2497
2556
|
}
|
|
2498
|
-
const
|
|
2557
|
+
const Y = (d) => {
|
|
2499
2558
|
if (!u.utils && !u.startedLoadingUtilsScript) {
|
|
2500
2559
|
let t;
|
|
2501
|
-
if (typeof
|
|
2560
|
+
if (typeof d == "function")
|
|
2502
2561
|
try {
|
|
2503
|
-
t = Promise.resolve(
|
|
2562
|
+
t = Promise.resolve(d());
|
|
2504
2563
|
} catch (e) {
|
|
2505
2564
|
return Promise.reject(e);
|
|
2506
2565
|
}
|
|
2507
2566
|
else
|
|
2508
|
-
return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof
|
|
2567
|
+
return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof d}`));
|
|
2509
2568
|
return u.startedLoadingUtilsScript = !0, t.then((e) => {
|
|
2510
2569
|
const i = e == null ? void 0 : e.default;
|
|
2511
2570
|
if (!i || typeof i != "object")
|
|
2512
2571
|
throw new TypeError("The loader function passed to attachUtils did not resolve to a module object with utils as its default export.");
|
|
2513
|
-
return u.utils = i,
|
|
2572
|
+
return u.utils = i, I("handleUtils"), !0;
|
|
2514
2573
|
}).catch((e) => {
|
|
2515
|
-
throw
|
|
2574
|
+
throw I("rejectUtilsScriptPromise", e), e;
|
|
2516
2575
|
});
|
|
2517
2576
|
}
|
|
2518
2577
|
return null;
|
|
2519
2578
|
}, u = Object.assign(
|
|
2520
|
-
(
|
|
2521
|
-
const e = new
|
|
2522
|
-
return e._init(),
|
|
2579
|
+
(d, t) => {
|
|
2580
|
+
const e = new D(d, t);
|
|
2581
|
+
return e._init(), d.setAttribute("data-intl-tel-input-id", e.id.toString()), u.instances[e.id] = e, d.iti = e, e;
|
|
2523
2582
|
},
|
|
2524
2583
|
{
|
|
2525
|
-
defaults:
|
|
2584
|
+
defaults: x,
|
|
2526
2585
|
//* Using a static var like this allows us to mock it in the tests.
|
|
2527
2586
|
documentReady: () => document.readyState === "complete",
|
|
2528
2587
|
//* Get the country data object.
|
|
2529
|
-
getCountryData: () =>
|
|
2588
|
+
getCountryData: () => w,
|
|
2530
2589
|
//* A getter for the plugin instance.
|
|
2531
|
-
getInstance: (
|
|
2532
|
-
const t =
|
|
2590
|
+
getInstance: (d) => {
|
|
2591
|
+
const t = d.getAttribute("data-intl-tel-input-id");
|
|
2533
2592
|
return t ? u.instances[t] : null;
|
|
2534
2593
|
},
|
|
2535
2594
|
//* A map from instance ID to instance object.
|
|
2536
2595
|
instances: {},
|
|
2537
|
-
attachUtils:
|
|
2596
|
+
attachUtils: Y,
|
|
2538
2597
|
startedLoadingUtilsScript: !1,
|
|
2539
2598
|
startedLoadingAutoCountry: !1,
|
|
2540
|
-
version: "25.
|
|
2599
|
+
version: "25.8.0"
|
|
2541
2600
|
}
|
|
2542
|
-
),
|
|
2601
|
+
), Z = {
|
|
2543
2602
|
__name: "IntlTelInput",
|
|
2544
|
-
props: /* @__PURE__ */
|
|
2603
|
+
props: /* @__PURE__ */ A({
|
|
2545
2604
|
disabled: {
|
|
2546
2605
|
type: Boolean,
|
|
2547
2606
|
default: !1
|
|
@@ -2565,47 +2624,47 @@ const G = (h) => {
|
|
|
2565
2624
|
},
|
|
2566
2625
|
modelModifiers: {}
|
|
2567
2626
|
}),
|
|
2568
|
-
emits: /* @__PURE__ */
|
|
2627
|
+
emits: /* @__PURE__ */ A([
|
|
2569
2628
|
"changeNumber",
|
|
2570
2629
|
"changeCountry",
|
|
2571
2630
|
"changeValidity",
|
|
2572
2631
|
"changeErrorCode"
|
|
2573
2632
|
], ["update:modelValue"]),
|
|
2574
|
-
setup(
|
|
2575
|
-
const i =
|
|
2576
|
-
let
|
|
2577
|
-
|
|
2633
|
+
setup(d, { expose: t, emit: e }) {
|
|
2634
|
+
const i = E(d, "modelValue"), s = d, n = e, o = N(), l = N(), r = N(!1), c = () => l.value ? s.options.strictMode ? l.value.isValidNumberPrecise() : l.value.isValidNumber() : null, p = () => {
|
|
2635
|
+
let a = c();
|
|
2636
|
+
r.value !== a && (r.value = a, n("changeValidity", !!a), n(
|
|
2578
2637
|
"changeErrorCode",
|
|
2579
|
-
|
|
2638
|
+
a ? null : l.value.getValidationError()
|
|
2580
2639
|
));
|
|
2581
|
-
},
|
|
2582
|
-
var
|
|
2583
|
-
n("changeNumber", ((
|
|
2584
|
-
},
|
|
2585
|
-
var
|
|
2586
|
-
n("changeCountry", ((
|
|
2640
|
+
}, y = () => {
|
|
2641
|
+
var a;
|
|
2642
|
+
n("changeNumber", ((a = l.value) == null ? void 0 : a.getNumber()) ?? ""), p();
|
|
2643
|
+
}, m = () => {
|
|
2644
|
+
var a;
|
|
2645
|
+
n("changeCountry", ((a = l.value) == null ? void 0 : a.getSelectedCountryData().iso2) ?? ""), y(), p();
|
|
2587
2646
|
};
|
|
2588
|
-
return
|
|
2589
|
-
o.value && (
|
|
2590
|
-
}),
|
|
2647
|
+
return M(() => {
|
|
2648
|
+
o.value && (l.value = u(o.value, s.options), s.value && l.value.setNumber(s.value), s.disabled && l.value.setDisabled(s.disabled), r.value = c());
|
|
2649
|
+
}), B(
|
|
2591
2650
|
() => s.disabled,
|
|
2592
|
-
(
|
|
2593
|
-
var
|
|
2594
|
-
return (
|
|
2651
|
+
(a) => {
|
|
2652
|
+
var h;
|
|
2653
|
+
return (h = l.value) == null ? void 0 : h.setDisabled(a);
|
|
2595
2654
|
}
|
|
2596
|
-
),
|
|
2597
|
-
var
|
|
2598
|
-
return (
|
|
2599
|
-
}), t({ instance:
|
|
2655
|
+
), R(() => {
|
|
2656
|
+
var a;
|
|
2657
|
+
return (a = l.value) == null ? void 0 : a.destroy();
|
|
2658
|
+
}), t({ instance: l, input: o }), (a, h) => F((V(), z("input", O({
|
|
2600
2659
|
ref_key: "input",
|
|
2601
2660
|
ref: o,
|
|
2602
|
-
"onUpdate:modelValue":
|
|
2661
|
+
"onUpdate:modelValue": h[0] || (h[0] = (_) => i.value = _),
|
|
2603
2662
|
type: "tel",
|
|
2604
|
-
onCountrychange:
|
|
2605
|
-
onInput:
|
|
2606
|
-
},
|
|
2663
|
+
onCountrychange: m,
|
|
2664
|
+
onInput: y
|
|
2665
|
+
}, d.inputProps), null, 16)), [
|
|
2607
2666
|
[
|
|
2608
|
-
|
|
2667
|
+
$,
|
|
2609
2668
|
i.value,
|
|
2610
2669
|
void 0,
|
|
2611
2670
|
{ lazy: !0 }
|
|
@@ -2614,5 +2673,5 @@ const G = (h) => {
|
|
|
2614
2673
|
}
|
|
2615
2674
|
};
|
|
2616
2675
|
export {
|
|
2617
|
-
|
|
2676
|
+
Z as default
|
|
2618
2677
|
};
|