intl-tel-input 25.10.7 → 25.10.8
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 +5 -5
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +385 -319
- package/angular/build/IntlTelInputWithUtils.js +436 -341
- package/angular/build/types/intl-tel-input/angular.d.ts +2 -1
- package/angular/build/types/intl-tel-input/angularWithUtils.d.ts +2 -1
- package/angular/build/types/intl-tel-input/data.d.ts +3 -1
- package/angular/build/types/intl-tel-input/i18n/types.d.ts +2 -245
- package/angular/build/types/intl-tel-input.d.ts +16 -87
- package/angular/build/types/modules/core/options.d.ts +3 -0
- package/angular/build/types/modules/data/country-data.d.ts +12 -0
- package/angular/build/types/modules/data/nanp-regionless.d.ts +2 -0
- package/angular/build/types/modules/format/caret.d.ts +1 -0
- package/angular/build/types/modules/format/formatting.d.ts +3 -0
- package/angular/build/types/modules/types/public-api.d.ts +79 -0
- package/angular/build/types/modules/utils/dom.d.ts +1 -0
- package/angular/build/types/modules/utils/string.d.ts +2 -0
- package/build/js/data.js +3 -2
- package/build/js/data.min.js +2 -2
- package/build/js/intlTelInput.d.ts +99 -292
- package/build/js/intlTelInput.js +431 -360
- package/build/js/intlTelInput.min.js +13 -13
- package/build/js/intlTelInputWithUtils.js +482 -382
- package/build/js/intlTelInputWithUtils.min.js +13 -13
- package/build/js/utils.js +18 -15
- package/package.json +1 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +430 -359
- package/react/build/IntlTelInput.d.ts +103 -294
- package/react/build/IntlTelInput.js +430 -359
- package/react/build/IntlTelInputWithUtils.cjs +481 -381
- package/react/build/IntlTelInputWithUtils.js +481 -381
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +483 -443
- package/vue/build/IntlTelInputWithUtils.mjs +1128 -1059
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mergeModels as
|
|
2
|
-
const
|
|
1
|
+
import { mergeModels as S, useModel as E, ref as L, onMounted as M, watch as B, onUnmounted as R, withDirectives as F, createElementBlock as z, openBlock as V, mergeProps as $, vModelText as O } from "vue";
|
|
2
|
+
const j = [
|
|
3
3
|
[
|
|
4
4
|
"af",
|
|
5
5
|
// Afghanistan
|
|
@@ -1322,20 +1322,20 @@ const H = [
|
|
|
1322
1322
|
// Zimbabwe
|
|
1323
1323
|
"263"
|
|
1324
1324
|
]
|
|
1325
|
-
],
|
|
1326
|
-
for (const
|
|
1327
|
-
|
|
1325
|
+
], _ = [];
|
|
1326
|
+
for (const r of j)
|
|
1327
|
+
_.push({
|
|
1328
1328
|
name: "",
|
|
1329
1329
|
// populated in the plugin
|
|
1330
|
-
iso2:
|
|
1331
|
-
dialCode:
|
|
1332
|
-
priority:
|
|
1333
|
-
areaCodes:
|
|
1330
|
+
iso2: r[0],
|
|
1331
|
+
dialCode: r[1],
|
|
1332
|
+
priority: r[2] || 0,
|
|
1333
|
+
areaCodes: r[3] || null,
|
|
1334
1334
|
nodeById: {},
|
|
1335
1335
|
// populated by the plugin
|
|
1336
|
-
nationalPrefix:
|
|
1336
|
+
nationalPrefix: r[4] || null
|
|
1337
1337
|
});
|
|
1338
|
-
const
|
|
1338
|
+
const U = {
|
|
1339
1339
|
ad: "Andorra",
|
|
1340
1340
|
ae: "United Arab Emirates",
|
|
1341
1341
|
af: "Afghanistan",
|
|
@@ -1578,7 +1578,7 @@ const K = {
|
|
|
1578
1578
|
za: "South Africa",
|
|
1579
1579
|
zm: "Zambia",
|
|
1580
1580
|
zw: "Zimbabwe"
|
|
1581
|
-
},
|
|
1581
|
+
}, H = {
|
|
1582
1582
|
selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})",
|
|
1583
1583
|
noCountrySelected: "Select country",
|
|
1584
1584
|
countryListAriaLabel: "List of countries",
|
|
@@ -1590,17 +1590,13 @@ const K = {
|
|
|
1590
1590
|
// additional countries (not supported by country-list library)
|
|
1591
1591
|
ac: "Ascension Island",
|
|
1592
1592
|
xk: "Kosovo"
|
|
1593
|
-
},
|
|
1594
|
-
for (const d of w)
|
|
1595
|
-
d.name = x[d.iso2];
|
|
1596
|
-
let G = 0;
|
|
1597
|
-
const S = (d) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(d).matches, q = () => {
|
|
1593
|
+
}, k = { ...U, ...H }, N = (r) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(r).matches, K = () => {
|
|
1598
1594
|
if (typeof navigator < "u" && typeof window < "u") {
|
|
1599
|
-
const
|
|
1600
|
-
return
|
|
1595
|
+
const r = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), t = N("(max-width: 500px)"), e = N("(max-height: 600px)"), i = N("(pointer: coarse)");
|
|
1596
|
+
return r || t || i && e;
|
|
1601
1597
|
}
|
|
1602
1598
|
return !1;
|
|
1603
|
-
},
|
|
1599
|
+
}, P = {
|
|
1604
1600
|
// Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
|
|
1605
1601
|
allowPhonewords: !1,
|
|
1606
1602
|
//* Whether or not to allow the dropdown.
|
|
@@ -1648,10 +1644,106 @@ const S = (d) => typeof window < "u" && typeof window.matchMedia == "function" &
|
|
|
1648
1644
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1649
1645
|
strictMode: !1,
|
|
1650
1646
|
//* Use full screen popup instead of dropdown for country list.
|
|
1651
|
-
useFullscreenPopup:
|
|
1647
|
+
useFullscreenPopup: K(),
|
|
1652
1648
|
//* The number type to enforce during validation.
|
|
1653
1649
|
validationNumberTypes: ["MOBILE"]
|
|
1654
|
-
}
|
|
1650
|
+
};
|
|
1651
|
+
function W(r) {
|
|
1652
|
+
r.useFullscreenPopup && (r.fixDropdownWidth = !1), r.onlyCountries.length === 1 && (r.initialCountry = r.onlyCountries[0]), r.separateDialCode && (r.nationalMode = !1), r.allowDropdown && !r.showFlags && !r.separateDialCode && (r.nationalMode = !1), r.useFullscreenPopup && !r.dropdownContainer && (r.dropdownContainer = document.body), r.i18n = { ...k, ...r.i18n };
|
|
1653
|
+
}
|
|
1654
|
+
const I = (r) => r.replace(/\D/g, ""), x = (r = "") => r.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), m = (r, t, e) => {
|
|
1655
|
+
const i = document.createElement(r);
|
|
1656
|
+
return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
|
|
1657
|
+
};
|
|
1658
|
+
function G(r) {
|
|
1659
|
+
const { onlyCountries: t, excludeCountries: e } = r;
|
|
1660
|
+
if (t.length) {
|
|
1661
|
+
const i = t.map((s) => s.toLowerCase());
|
|
1662
|
+
return _.filter((s) => i.includes(s.iso2));
|
|
1663
|
+
} else if (e.length) {
|
|
1664
|
+
const i = e.map((s) => s.toLowerCase());
|
|
1665
|
+
return _.filter((s) => !i.includes(s.iso2));
|
|
1666
|
+
}
|
|
1667
|
+
return _;
|
|
1668
|
+
}
|
|
1669
|
+
function q(r, t) {
|
|
1670
|
+
for (const e of r) {
|
|
1671
|
+
const i = e.iso2.toLowerCase();
|
|
1672
|
+
t.i18n[i] && (e.name = t.i18n[i]);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
function Y(r, t) {
|
|
1676
|
+
const e = /* @__PURE__ */ new Set();
|
|
1677
|
+
let i = 0;
|
|
1678
|
+
const s = {}, n = (o, a, d) => {
|
|
1679
|
+
if (!o || !a)
|
|
1680
|
+
return;
|
|
1681
|
+
a.length > i && (i = a.length), s.hasOwnProperty(a) || (s[a] = []);
|
|
1682
|
+
const l = s[a];
|
|
1683
|
+
if (l.includes(o))
|
|
1684
|
+
return;
|
|
1685
|
+
const h = d !== void 0 ? d : l.length;
|
|
1686
|
+
l[h] = o;
|
|
1687
|
+
};
|
|
1688
|
+
for (const o of r)
|
|
1689
|
+
e.has(o.dialCode) || e.add(o.dialCode), n(o.iso2, o.dialCode, o.priority);
|
|
1690
|
+
(t.onlyCountries.length || t.excludeCountries.length) && e.forEach((o) => {
|
|
1691
|
+
s[o] = s[o].filter(Boolean);
|
|
1692
|
+
});
|
|
1693
|
+
for (const o of r)
|
|
1694
|
+
if (o.areaCodes) {
|
|
1695
|
+
const a = s[o.dialCode][0];
|
|
1696
|
+
for (const d of o.areaCodes) {
|
|
1697
|
+
for (let l = 1; l < d.length; l++) {
|
|
1698
|
+
const h = d.substring(0, l), p = o.dialCode + h;
|
|
1699
|
+
n(a, p), n(o.iso2, p);
|
|
1700
|
+
}
|
|
1701
|
+
n(o.iso2, o.dialCode + d);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return { dialCodes: e, dialCodeMaxLen: i, dialCodeToIso2Map: s };
|
|
1705
|
+
}
|
|
1706
|
+
function J(r, t) {
|
|
1707
|
+
t.countryOrder && (t.countryOrder = t.countryOrder.map((e) => e.toLowerCase())), r.sort((e, i) => {
|
|
1708
|
+
const { countryOrder: s } = t;
|
|
1709
|
+
if (s) {
|
|
1710
|
+
const n = s.indexOf(e.iso2), o = s.indexOf(i.iso2), a = n > -1, d = o > -1;
|
|
1711
|
+
if (a || d)
|
|
1712
|
+
return a && d ? n - o : a ? -1 : 1;
|
|
1713
|
+
}
|
|
1714
|
+
return e.name.localeCompare(i.name);
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
function Z(r) {
|
|
1718
|
+
for (const t of r)
|
|
1719
|
+
t.normalisedName = x(t.name), t.initials = t.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((e) => e[0]).join("").toLowerCase(), t.dialCodePlus = `+${t.dialCode}`;
|
|
1720
|
+
}
|
|
1721
|
+
function Q(r, t, e, i) {
|
|
1722
|
+
let s = r;
|
|
1723
|
+
if (e && t) {
|
|
1724
|
+
t = `+${i.dialCode}`;
|
|
1725
|
+
const n = s[t.length] === " " || s[t.length] === "-" ? t.length + 1 : t.length;
|
|
1726
|
+
s = s.substring(n);
|
|
1727
|
+
}
|
|
1728
|
+
return s;
|
|
1729
|
+
}
|
|
1730
|
+
function X(r, t, e, i, s) {
|
|
1731
|
+
const n = e ? e.formatNumberAsYouType(r, i.iso2) : r, { dialCode: o } = i;
|
|
1732
|
+
return s && t.charAt(0) !== "+" && n.includes(`+${o}`) ? (n.split(`+${o}`)[1] || "").trim() : n;
|
|
1733
|
+
}
|
|
1734
|
+
function tt(r, t, e, i) {
|
|
1735
|
+
if (e === 0 && !i)
|
|
1736
|
+
return 0;
|
|
1737
|
+
let s = 0;
|
|
1738
|
+
for (let n = 0; n < t.length; n++) {
|
|
1739
|
+
if (/[+0-9]/.test(t[n]) && s++, s === r && !i)
|
|
1740
|
+
return n + 1;
|
|
1741
|
+
if (i && s === r + 1)
|
|
1742
|
+
return n;
|
|
1743
|
+
}
|
|
1744
|
+
return t.length;
|
|
1745
|
+
}
|
|
1746
|
+
const et = [
|
|
1655
1747
|
"800",
|
|
1656
1748
|
"822",
|
|
1657
1749
|
"833",
|
|
@@ -1669,32 +1761,22 @@ const S = (d) => typeof window < "u" && typeof window.matchMedia == "function" &
|
|
|
1669
1761
|
"887",
|
|
1670
1762
|
"888",
|
|
1671
1763
|
"889"
|
|
1672
|
-
],
|
|
1673
|
-
const t =
|
|
1764
|
+
], A = (r) => {
|
|
1765
|
+
const t = I(r);
|
|
1674
1766
|
if (t.charAt(0) === "1") {
|
|
1675
1767
|
const e = t.substring(1, 4);
|
|
1676
|
-
return
|
|
1768
|
+
return et.includes(e);
|
|
1677
1769
|
}
|
|
1678
1770
|
return !1;
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
if (/[+0-9]/.test(t[n]) && s++, s === d && !i)
|
|
1685
|
-
return n + 1;
|
|
1686
|
-
if (i && s === d + 1)
|
|
1687
|
-
return n;
|
|
1688
|
-
}
|
|
1689
|
-
return t.length;
|
|
1690
|
-
}, m = (d, t, e) => {
|
|
1691
|
-
const i = document.createElement(d);
|
|
1692
|
-
return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
|
|
1693
|
-
}, I = (d, ...t) => {
|
|
1771
|
+
};
|
|
1772
|
+
for (const r of _)
|
|
1773
|
+
r.name = k[r.iso2];
|
|
1774
|
+
let it = 0;
|
|
1775
|
+
const st = new Set(_.map((r) => r.iso2)), D = (r) => st.has(r), w = (r, ...t) => {
|
|
1694
1776
|
const { instances: e } = u;
|
|
1695
|
-
Object.values(e).forEach((i) => i[
|
|
1777
|
+
Object.values(e).forEach((i) => i[r](...t));
|
|
1696
1778
|
};
|
|
1697
|
-
class
|
|
1779
|
+
class v {
|
|
1698
1780
|
/**
|
|
1699
1781
|
* Build a space-delimited class string from an object map of className -> truthy/falsey.
|
|
1700
1782
|
* Only keys with truthy values are included.
|
|
@@ -1703,131 +1785,72 @@ class N {
|
|
|
1703
1785
|
return Object.keys(t).filter((e) => !!t[e]).join(" ");
|
|
1704
1786
|
}
|
|
1705
1787
|
constructor(t, e = {}) {
|
|
1706
|
-
this.id =
|
|
1788
|
+
this.id = it++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, P, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder");
|
|
1707
1789
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
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";
|
|
1790
|
+
_detectEnvironmentAndLayout() {
|
|
1791
|
+
this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.telInput.dir = "ltr";
|
|
1711
1792
|
const t = this.options.allowDropdown || this.options.separateDialCode;
|
|
1712
|
-
this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft)
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
this.
|
|
1793
|
+
this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft);
|
|
1794
|
+
}
|
|
1795
|
+
_createInitPromises() {
|
|
1796
|
+
const t = new Promise((i, s) => {
|
|
1797
|
+
this.resolveAutoCountryPromise = i, this.rejectAutoCountryPromise = s;
|
|
1798
|
+
}), e = new Promise((i, s) => {
|
|
1799
|
+
this.resolveUtilsScriptPromise = i, this.rejectUtilsScriptPromise = s;
|
|
1717
1800
|
});
|
|
1718
|
-
this.promise = Promise.all([
|
|
1801
|
+
this.promise = Promise.all([t, e]);
|
|
1802
|
+
}
|
|
1803
|
+
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
1804
|
+
_init() {
|
|
1805
|
+
W(this.options), this._detectEnvironmentAndLayout(), this._createInitPromises(), this.selectedCountryData = {}, this._processCountryData(), this._generateMarkup(), this._setInitialState(), this._initListeners(), this._initRequests();
|
|
1719
1806
|
}
|
|
1720
1807
|
//********************
|
|
1721
1808
|
//* PRIVATE METHODS
|
|
1722
1809
|
//********************
|
|
1723
1810
|
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
1724
1811
|
_processCountryData() {
|
|
1725
|
-
this.
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
_cacheSearchTokens() {
|
|
1729
|
-
for (const t of this.countries)
|
|
1730
|
-
t.normalisedName = P(t.name), t.initials = t.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((e) => e[0]).join("").toLowerCase(), t.dialCodePlus = `+${t.dialCode}`;
|
|
1731
|
-
}
|
|
1732
|
-
//* Sort countries by countryOrder option (if present), then name.
|
|
1733
|
-
_sortCountries() {
|
|
1734
|
-
this.options.countryOrder && (this.options.countryOrder = this.options.countryOrder.map((t) => t.toLowerCase())), this.countries.sort((t, e) => {
|
|
1735
|
-
const { countryOrder: i } = this.options;
|
|
1736
|
-
if (i) {
|
|
1737
|
-
const s = i.indexOf(t.iso2), n = i.indexOf(e.iso2), a = s > -1, o = n > -1;
|
|
1738
|
-
if (a || o)
|
|
1739
|
-
return a && o ? s - n : a ? -1 : 1;
|
|
1740
|
-
}
|
|
1741
|
-
return t.name.localeCompare(e.name);
|
|
1742
|
-
});
|
|
1743
|
-
}
|
|
1744
|
-
//* Add a dial code to this.dialCodeToIso2Map.
|
|
1745
|
-
_addToDialCodeMap(t, e, i) {
|
|
1746
|
-
if (!t || !e)
|
|
1747
|
-
return;
|
|
1748
|
-
e.length > this.dialCodeMaxLen && (this.dialCodeMaxLen = e.length), this.dialCodeToIso2Map.hasOwnProperty(e) || (this.dialCodeToIso2Map[e] = []);
|
|
1749
|
-
const s = this.dialCodeToIso2Map[e];
|
|
1750
|
-
if (s.includes(t))
|
|
1751
|
-
return;
|
|
1752
|
-
const n = i !== void 0 ? i : s.length;
|
|
1753
|
-
s[n] = t;
|
|
1754
|
-
}
|
|
1755
|
-
//* Process onlyCountries or excludeCountries array if present.
|
|
1756
|
-
_processAllCountries() {
|
|
1757
|
-
const { onlyCountries: t, excludeCountries: e } = this.options;
|
|
1758
|
-
if (t.length) {
|
|
1759
|
-
const i = t.map(
|
|
1760
|
-
(s) => s.toLowerCase()
|
|
1761
|
-
);
|
|
1762
|
-
this.countries = w.filter(
|
|
1763
|
-
(s) => i.includes(s.iso2)
|
|
1764
|
-
);
|
|
1765
|
-
} else if (e.length) {
|
|
1766
|
-
const i = e.map(
|
|
1767
|
-
(s) => s.toLowerCase()
|
|
1768
|
-
);
|
|
1769
|
-
this.countries = w.filter(
|
|
1770
|
-
(s) => !i.includes(s.iso2)
|
|
1771
|
-
);
|
|
1772
|
-
} else
|
|
1773
|
-
this.countries = w;
|
|
1774
|
-
}
|
|
1775
|
-
//* Translate Countries by object literal provided on config.
|
|
1776
|
-
_translateCountryNames() {
|
|
1777
|
-
for (const t of this.countries) {
|
|
1778
|
-
const e = t.iso2.toLowerCase();
|
|
1779
|
-
this.options.i18n.hasOwnProperty(e) && (t.name = this.options.i18n[e]);
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
//* Generate this.dialCodes and this.dialCodeToIso2Map.
|
|
1783
|
-
_processDialCodes() {
|
|
1784
|
-
this.dialCodes = /* @__PURE__ */ new Set(), this.dialCodeMaxLen = 0, this.dialCodeToIso2Map = {};
|
|
1785
|
-
for (const t of this.countries)
|
|
1786
|
-
this.dialCodes.has(t.dialCode) || this.dialCodes.add(t.dialCode), this._addToDialCodeMap(t.iso2, t.dialCode, t.priority);
|
|
1787
|
-
(this.options.onlyCountries.length || this.options.excludeCountries.length) && this.dialCodes.forEach((t) => {
|
|
1788
|
-
this.dialCodeToIso2Map[t] = this.dialCodeToIso2Map[t].filter(Boolean);
|
|
1789
|
-
});
|
|
1790
|
-
for (const t of this.countries)
|
|
1791
|
-
if (t.areaCodes) {
|
|
1792
|
-
const e = this.dialCodeToIso2Map[t.dialCode][0];
|
|
1793
|
-
for (const i of t.areaCodes) {
|
|
1794
|
-
for (let s = 1; s < i.length; s++) {
|
|
1795
|
-
const n = i.substring(0, s), a = t.dialCode + n;
|
|
1796
|
-
this._addToDialCodeMap(e, a), this._addToDialCodeMap(t.iso2, a);
|
|
1797
|
-
}
|
|
1798
|
-
this._addToDialCodeMap(t.iso2, t.dialCode + i);
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1812
|
+
this.countries = G(this.options);
|
|
1813
|
+
const t = Y(this.countries, this.options);
|
|
1814
|
+
this.dialCodes = t.dialCodes, this.dialCodeMaxLen = t.dialCodeMaxLen, this.dialCodeToIso2Map = t.dialCodeToIso2Map, q(this.countries, this.options), J(this.countries, this.options), this.countryByIso2 = new Map(this.countries.map((e) => [e.iso2, e])), Z(this.countries);
|
|
1801
1815
|
}
|
|
1802
1816
|
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
|
|
1803
1817
|
_generateMarkup() {
|
|
1804
|
-
|
|
1818
|
+
this._prepareTelInput();
|
|
1819
|
+
const t = this._createWrapperAndInsert();
|
|
1820
|
+
this._maybeBuildCountryContainer(t), t.appendChild(this.telInput), this._maybeUpdateInputPaddingAndReveal(), this._maybeBuildHiddenInputs(t);
|
|
1821
|
+
}
|
|
1822
|
+
_prepareTelInput() {
|
|
1805
1823
|
this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off");
|
|
1824
|
+
}
|
|
1825
|
+
_createWrapperAndInsert() {
|
|
1826
|
+
var a;
|
|
1806
1827
|
const {
|
|
1807
1828
|
allowDropdown: t,
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
dropdownContainer: a,
|
|
1813
|
-
fixDropdownWidth: o,
|
|
1814
|
-
useFullscreenPopup: l,
|
|
1815
|
-
countrySearch: h,
|
|
1816
|
-
i18n: p
|
|
1817
|
-
} = this.options, r = N._buildClassNames({
|
|
1829
|
+
showFlags: e,
|
|
1830
|
+
containerClass: i,
|
|
1831
|
+
useFullscreenPopup: s
|
|
1832
|
+
} = this.options, n = v._buildClassNames({
|
|
1818
1833
|
iti: !0,
|
|
1819
1834
|
"iti--allow-dropdown": t,
|
|
1820
|
-
"iti--show-flags":
|
|
1821
|
-
"iti--inline-dropdown": !
|
|
1822
|
-
[
|
|
1823
|
-
}),
|
|
1824
|
-
|
|
1835
|
+
"iti--show-flags": e,
|
|
1836
|
+
"iti--inline-dropdown": !s,
|
|
1837
|
+
[i]: !!i
|
|
1838
|
+
}), o = m("div", { class: n });
|
|
1839
|
+
return (a = this.telInput.parentNode) == null || a.insertBefore(o, this.telInput), o;
|
|
1840
|
+
}
|
|
1841
|
+
_maybeBuildCountryContainer(t) {
|
|
1842
|
+
const {
|
|
1843
|
+
allowDropdown: e,
|
|
1844
|
+
separateDialCode: i,
|
|
1845
|
+
showFlags: s
|
|
1846
|
+
} = this.options;
|
|
1847
|
+
if (e || s || i) {
|
|
1825
1848
|
this.countryContainer = m(
|
|
1826
1849
|
"div",
|
|
1827
1850
|
// visibly hidden until we measure it's width to set the input padding correctly
|
|
1828
1851
|
{ class: "iti__country-container iti__v-hide" },
|
|
1829
|
-
|
|
1830
|
-
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px",
|
|
1852
|
+
t
|
|
1853
|
+
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", e ? (this.selectedCountry = m(
|
|
1831
1854
|
"button",
|
|
1832
1855
|
{
|
|
1833
1856
|
type: "button",
|
|
@@ -1843,133 +1866,148 @@ class N {
|
|
|
1843
1866
|
{ class: "iti__selected-country" },
|
|
1844
1867
|
this.countryContainer
|
|
1845
1868
|
);
|
|
1846
|
-
const
|
|
1869
|
+
const n = m(
|
|
1847
1870
|
"div",
|
|
1848
1871
|
{ class: "iti__selected-country-primary" },
|
|
1849
1872
|
this.selectedCountry
|
|
1850
1873
|
);
|
|
1851
|
-
|
|
1874
|
+
this.selectedCountryInner = m(
|
|
1852
1875
|
"div",
|
|
1853
1876
|
{ class: "iti__flag" },
|
|
1854
|
-
|
|
1855
|
-
),
|
|
1877
|
+
n
|
|
1878
|
+
), e && (this.dropdownArrow = m(
|
|
1856
1879
|
"div",
|
|
1857
1880
|
{ class: "iti__arrow", "aria-hidden": "true" },
|
|
1858
|
-
|
|
1859
|
-
)),
|
|
1881
|
+
n
|
|
1882
|
+
)), i && (this.selectedDialCode = m(
|
|
1860
1883
|
"div",
|
|
1861
1884
|
{ class: "iti__selected-dial-code", dir: "ltr" },
|
|
1862
1885
|
this.selectedCountry
|
|
1863
|
-
)),
|
|
1864
|
-
const _ = o ? "" : "iti--flexible-dropdown-width";
|
|
1865
|
-
if (this.dropdownContent = m("div", {
|
|
1866
|
-
id: `iti-${this.id}__dropdown-content`,
|
|
1867
|
-
class: `iti__dropdown-content iti__hide ${_}`,
|
|
1868
|
-
role: "dialog",
|
|
1869
|
-
"aria-modal": "true"
|
|
1870
|
-
}), h) {
|
|
1871
|
-
const y = m(
|
|
1872
|
-
"div",
|
|
1873
|
-
{ class: "iti__search-input-wrapper" },
|
|
1874
|
-
this.dropdownContent
|
|
1875
|
-
);
|
|
1876
|
-
this.searchIcon = m(
|
|
1877
|
-
"span",
|
|
1878
|
-
{
|
|
1879
|
-
class: "iti__search-icon",
|
|
1880
|
-
"aria-hidden": "true"
|
|
1881
|
-
},
|
|
1882
|
-
y
|
|
1883
|
-
), this.searchIcon.innerHTML = `
|
|
1884
|
-
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
|
|
1885
|
-
<circle cx="11" cy="11" r="7" />
|
|
1886
|
-
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1887
|
-
</svg>`, this.searchInput = m(
|
|
1888
|
-
"input",
|
|
1889
|
-
{
|
|
1890
|
-
id: `iti-${this.id}__search-input`,
|
|
1891
|
-
// Chrome says inputs need either a name or an id
|
|
1892
|
-
type: "search",
|
|
1893
|
-
class: "iti__search-input",
|
|
1894
|
-
placeholder: p.searchPlaceholder,
|
|
1895
|
-
// 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
|
|
1896
|
-
role: "combobox",
|
|
1897
|
-
"aria-expanded": "true",
|
|
1898
|
-
"aria-label": p.searchPlaceholder,
|
|
1899
|
-
"aria-controls": `iti-${this.id}__country-listbox`,
|
|
1900
|
-
"aria-autocomplete": "list",
|
|
1901
|
-
autocomplete: "off"
|
|
1902
|
-
},
|
|
1903
|
-
y
|
|
1904
|
-
), this.searchClearButton = m(
|
|
1905
|
-
"button",
|
|
1906
|
-
{
|
|
1907
|
-
type: "button",
|
|
1908
|
-
class: "iti__search-clear iti__hide",
|
|
1909
|
-
"aria-label": p.clearSearchAriaLabel,
|
|
1910
|
-
tabindex: "-1"
|
|
1911
|
-
},
|
|
1912
|
-
y
|
|
1913
|
-
);
|
|
1914
|
-
const v = `iti-${this.id}-clear-mask`;
|
|
1915
|
-
this.searchClearButton.innerHTML = `
|
|
1916
|
-
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
|
1917
|
-
<mask id="${v}" maskUnits="userSpaceOnUse">
|
|
1918
|
-
<rect width="16" height="16" fill="white" />
|
|
1919
|
-
<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" />
|
|
1920
|
-
</mask>
|
|
1921
|
-
<circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${v})" />
|
|
1922
|
-
</svg>`, this.searchResultsA11yText = m(
|
|
1923
|
-
"span",
|
|
1924
|
-
{ class: "iti__a11y-text" },
|
|
1925
|
-
this.dropdownContent
|
|
1926
|
-
), this.searchNoResults = m(
|
|
1927
|
-
"div",
|
|
1928
|
-
{
|
|
1929
|
-
class: "iti__no-results iti__hide",
|
|
1930
|
-
"aria-hidden": "true"
|
|
1931
|
-
// all a11y messaging happens in this.searchResultsA11yText
|
|
1932
|
-
},
|
|
1933
|
-
this.dropdownContent
|
|
1934
|
-
), this.searchNoResults.textContent = p.zeroSearchResults;
|
|
1935
|
-
}
|
|
1936
|
-
if (this.countryList = m(
|
|
1937
|
-
"ul",
|
|
1938
|
-
{
|
|
1939
|
-
class: "iti__country-list",
|
|
1940
|
-
id: `iti-${this.id}__country-listbox`,
|
|
1941
|
-
role: "listbox",
|
|
1942
|
-
"aria-label": p.countryListAriaLabel
|
|
1943
|
-
},
|
|
1944
|
-
this.dropdownContent
|
|
1945
|
-
), this._appendListItems(), h && this._updateSearchResultsA11yText(), a) {
|
|
1946
|
-
const y = N._buildClassNames({
|
|
1947
|
-
iti: !0,
|
|
1948
|
-
"iti--container": !0,
|
|
1949
|
-
"iti--fullscreen-popup": l,
|
|
1950
|
-
"iti--inline-dropdown": !l,
|
|
1951
|
-
[s]: !!s
|
|
1952
|
-
});
|
|
1953
|
-
this.dropdown = m("div", { class: y }), this.dropdown.appendChild(this.dropdownContent);
|
|
1954
|
-
} else
|
|
1955
|
-
this.countryContainer.appendChild(this.dropdownContent);
|
|
1956
|
-
}
|
|
1886
|
+
)), e && this._buildDropdownContent();
|
|
1957
1887
|
}
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1888
|
+
}
|
|
1889
|
+
_buildDropdownContent() {
|
|
1890
|
+
const {
|
|
1891
|
+
fixDropdownWidth: t,
|
|
1892
|
+
useFullscreenPopup: e,
|
|
1893
|
+
countrySearch: i,
|
|
1894
|
+
i18n: s,
|
|
1895
|
+
dropdownContainer: n,
|
|
1896
|
+
containerClass: o
|
|
1897
|
+
} = this.options, a = t ? "" : "iti--flexible-dropdown-width";
|
|
1898
|
+
if (this.dropdownContent = m("div", {
|
|
1899
|
+
id: `iti-${this.id}__dropdown-content`,
|
|
1900
|
+
class: `iti__dropdown-content iti__hide ${a}`,
|
|
1901
|
+
role: "dialog",
|
|
1902
|
+
"aria-modal": "true"
|
|
1903
|
+
}), i && this._buildSearchUI(), this.countryList = m(
|
|
1904
|
+
"ul",
|
|
1905
|
+
{
|
|
1906
|
+
class: "iti__country-list",
|
|
1907
|
+
id: `iti-${this.id}__country-listbox`,
|
|
1908
|
+
role: "listbox",
|
|
1909
|
+
"aria-label": s.countryListAriaLabel
|
|
1910
|
+
},
|
|
1911
|
+
this.dropdownContent
|
|
1912
|
+
), this._appendListItems(), i && this._updateSearchResultsA11yText(), n) {
|
|
1913
|
+
const d = v._buildClassNames({
|
|
1914
|
+
iti: !0,
|
|
1915
|
+
"iti--container": !0,
|
|
1916
|
+
"iti--fullscreen-popup": e,
|
|
1917
|
+
"iti--inline-dropdown": !e,
|
|
1918
|
+
[o]: !!o
|
|
1919
|
+
});
|
|
1920
|
+
this.dropdown = m("div", { class: d }), this.dropdown.appendChild(this.dropdownContent);
|
|
1921
|
+
} else
|
|
1922
|
+
this.countryContainer.appendChild(this.dropdownContent);
|
|
1923
|
+
}
|
|
1924
|
+
_buildSearchUI() {
|
|
1925
|
+
const { i18n: t } = this.options, e = m(
|
|
1926
|
+
"div",
|
|
1927
|
+
{ class: "iti__search-input-wrapper" },
|
|
1928
|
+
this.dropdownContent
|
|
1929
|
+
);
|
|
1930
|
+
this.searchIcon = m(
|
|
1931
|
+
"span",
|
|
1932
|
+
{
|
|
1933
|
+
class: "iti__search-icon",
|
|
1934
|
+
"aria-hidden": "true"
|
|
1935
|
+
},
|
|
1936
|
+
e
|
|
1937
|
+
), this.searchIcon.innerHTML = `
|
|
1938
|
+
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
|
|
1939
|
+
<circle cx="11" cy="11" r="7" />
|
|
1940
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1941
|
+
</svg>`, this.searchInput = m(
|
|
1942
|
+
"input",
|
|
1943
|
+
{
|
|
1944
|
+
id: `iti-${this.id}__search-input`,
|
|
1945
|
+
// Chrome says inputs need either a name or an id
|
|
1946
|
+
type: "search",
|
|
1947
|
+
class: "iti__search-input",
|
|
1948
|
+
placeholder: t.searchPlaceholder,
|
|
1949
|
+
// 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
|
|
1950
|
+
role: "combobox",
|
|
1951
|
+
"aria-expanded": "true",
|
|
1952
|
+
"aria-label": t.searchPlaceholder,
|
|
1953
|
+
"aria-controls": `iti-${this.id}__country-listbox`,
|
|
1954
|
+
"aria-autocomplete": "list",
|
|
1955
|
+
autocomplete: "off"
|
|
1956
|
+
},
|
|
1957
|
+
e
|
|
1958
|
+
), this.searchClearButton = m(
|
|
1959
|
+
"button",
|
|
1960
|
+
{
|
|
1961
|
+
type: "button",
|
|
1962
|
+
class: "iti__search-clear iti__hide",
|
|
1963
|
+
"aria-label": t.clearSearchAriaLabel,
|
|
1964
|
+
tabindex: "-1"
|
|
1965
|
+
},
|
|
1966
|
+
e
|
|
1967
|
+
);
|
|
1968
|
+
const i = `iti-${this.id}-clear-mask`;
|
|
1969
|
+
this.searchClearButton.innerHTML = `
|
|
1970
|
+
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
|
|
1971
|
+
<mask id="${i}" maskUnits="userSpaceOnUse">
|
|
1972
|
+
<rect width="16" height="16" fill="white" />
|
|
1973
|
+
<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" />
|
|
1974
|
+
</mask>
|
|
1975
|
+
<circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${i})" />
|
|
1976
|
+
</svg>`, this.searchResultsA11yText = m(
|
|
1977
|
+
"span",
|
|
1978
|
+
{ class: "iti__a11y-text" },
|
|
1979
|
+
this.dropdownContent
|
|
1980
|
+
), this.searchNoResults = m(
|
|
1981
|
+
"div",
|
|
1982
|
+
{
|
|
1983
|
+
class: "iti__no-results iti__hide",
|
|
1984
|
+
"aria-hidden": "true"
|
|
1985
|
+
// all a11y messaging happens in this.searchResultsA11yText
|
|
1986
|
+
},
|
|
1987
|
+
this.dropdownContent
|
|
1988
|
+
), this.searchNoResults.textContent = t.zeroSearchResults;
|
|
1989
|
+
}
|
|
1990
|
+
_maybeUpdateInputPaddingAndReveal() {
|
|
1991
|
+
this.countryContainer && (this._updateInputPadding(), this.countryContainer.classList.remove("iti__v-hide"));
|
|
1992
|
+
}
|
|
1993
|
+
_maybeBuildHiddenInputs(t) {
|
|
1994
|
+
var i, s;
|
|
1995
|
+
const { hiddenInput: e } = this.options;
|
|
1996
|
+
if (e) {
|
|
1997
|
+
const n = this.telInput.getAttribute("name") || "", o = e(n);
|
|
1998
|
+
if (o.phone) {
|
|
1999
|
+
const a = (i = this.telInput.form) == null ? void 0 : i.querySelector(`input[name="${o.phone}"]`);
|
|
2000
|
+
a ? this.hiddenInput = a : (this.hiddenInput = m("input", {
|
|
1963
2001
|
type: "hidden",
|
|
1964
|
-
name:
|
|
1965
|
-
}),
|
|
2002
|
+
name: o.phone
|
|
2003
|
+
}), t.appendChild(this.hiddenInput));
|
|
1966
2004
|
}
|
|
1967
|
-
if (
|
|
1968
|
-
const
|
|
1969
|
-
|
|
2005
|
+
if (o.country) {
|
|
2006
|
+
const a = (s = this.telInput.form) == null ? void 0 : s.querySelector(`input[name="${o.country}"]`);
|
|
2007
|
+
a ? this.hiddenInputCountry = a : (this.hiddenInputCountry = m("input", {
|
|
1970
2008
|
type: "hidden",
|
|
1971
|
-
name:
|
|
1972
|
-
}),
|
|
2009
|
+
name: o.country
|
|
2010
|
+
}), t.appendChild(this.hiddenInputCountry));
|
|
1973
2011
|
}
|
|
1974
2012
|
}
|
|
1975
2013
|
}
|
|
@@ -1998,12 +2036,12 @@ class N {
|
|
|
1998
2036
|
//* 1. Extracting a dial code from the given number
|
|
1999
2037
|
//* 2. Using explicit initialCountry
|
|
2000
2038
|
_setInitialState(t = !1) {
|
|
2001
|
-
const e = this.telInput.getAttribute("value"), i = this.telInput.value, n = e && e.charAt(0) === "+" && (!i || i.charAt(0) !== "+") ? e : i,
|
|
2002
|
-
if (
|
|
2039
|
+
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), a = A(n), { initialCountry: d, geoIpLookup: l } = this.options, h = d === "auto" && l;
|
|
2040
|
+
if (o && !a)
|
|
2003
2041
|
this._updateCountryFromNumber(n);
|
|
2004
|
-
else if (!
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2042
|
+
else if (!h || t) {
|
|
2043
|
+
const p = d ? d.toLowerCase() : "";
|
|
2044
|
+
D(p) ? this._setCountry(p) : o && a ? this._setCountry("us") : this._setCountry("");
|
|
2007
2045
|
}
|
|
2008
2046
|
n && this._updateValFromNumber(n);
|
|
2009
2047
|
}
|
|
@@ -2050,10 +2088,10 @@ class N {
|
|
|
2050
2088
|
u.autoCountry ? this.handleAutoCountry() : u.startedLoadingAutoCountry || (u.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(
|
|
2051
2089
|
(t = "") => {
|
|
2052
2090
|
const e = t.toLowerCase();
|
|
2053
|
-
|
|
2091
|
+
D(e) ? (u.autoCountry = e, setTimeout(() => w("handleAutoCountry"))) : (this._setInitialState(!0), w("rejectAutoCountryPromise"));
|
|
2054
2092
|
},
|
|
2055
2093
|
() => {
|
|
2056
|
-
this._setInitialState(!0),
|
|
2094
|
+
this._setInitialState(!0), w("rejectAutoCountryPromise");
|
|
2057
2095
|
}
|
|
2058
2096
|
));
|
|
2059
2097
|
}
|
|
@@ -2062,47 +2100,66 @@ class N {
|
|
|
2062
2100
|
}
|
|
2063
2101
|
//* Initialize the tel input listeners.
|
|
2064
2102
|
_initTelInputListeners() {
|
|
2103
|
+
this._bindInputListener(), this._maybeBindKeydownListener(), this._maybeBindPasteListener();
|
|
2104
|
+
}
|
|
2105
|
+
_bindInputListener() {
|
|
2065
2106
|
const { strictMode: t, formatAsYouType: e, separateDialCode: i, allowDropdown: s, countrySearch: n } = this.options;
|
|
2066
|
-
let
|
|
2067
|
-
new RegExp("\\p{L}", "u").test(this.telInput.value) && (
|
|
2068
|
-
if (this.isAndroid && (
|
|
2069
|
-
const
|
|
2070
|
-
this.telInput.value =
|
|
2107
|
+
let o = !1;
|
|
2108
|
+
new RegExp("\\p{L}", "u").test(this.telInput.value) && (o = !0), this._handleInputEvent = (a) => {
|
|
2109
|
+
if (this.isAndroid && (a == null ? void 0 : a.data) === "+" && i && s && n) {
|
|
2110
|
+
const p = this.telInput.selectionStart || 0, f = this.telInput.value.substring(0, p - 1), c = this.telInput.value.substring(p);
|
|
2111
|
+
this.telInput.value = f + c, this._openDropdownWithPlus();
|
|
2071
2112
|
return;
|
|
2072
2113
|
}
|
|
2073
2114
|
this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2076
|
-
const
|
|
2077
|
-
if (e && !
|
|
2078
|
-
const
|
|
2079
|
-
|
|
2115
|
+
const d = (a == null ? void 0 : a.data) && /[^+0-9]/.test(a.data), l = (a == null ? void 0 : a.inputType) === "insertFromPaste" && this.telInput.value;
|
|
2116
|
+
d || l && !t ? o = !0 : /[^+0-9]/.test(this.telInput.value) || (o = !1);
|
|
2117
|
+
const h = (a == null ? void 0 : a.detail) && a.detail.isSetNumber;
|
|
2118
|
+
if (e && !o && !h) {
|
|
2119
|
+
const p = this.telInput.selectionStart || 0, c = this.telInput.value.substring(0, p).replace(/[^+0-9]/g, "").length, C = (a == null ? void 0 : a.inputType) === "deleteContentForward", y = this._getFullNumber(), g = X(
|
|
2120
|
+
y,
|
|
2121
|
+
this.telInput.value,
|
|
2122
|
+
u.utils,
|
|
2123
|
+
this.selectedCountryData,
|
|
2124
|
+
this.options.separateDialCode
|
|
2125
|
+
), b = tt(c, g, p, C);
|
|
2126
|
+
this.telInput.value = g, this.telInput.setSelectionRange(b, b);
|
|
2080
2127
|
}
|
|
2081
|
-
}, this.telInput.addEventListener("input", this._handleInputEvent)
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2128
|
+
}, this.telInput.addEventListener("input", this._handleInputEvent);
|
|
2129
|
+
}
|
|
2130
|
+
_maybeBindKeydownListener() {
|
|
2131
|
+
const { strictMode: t, separateDialCode: e, allowDropdown: i, countrySearch: s } = this.options;
|
|
2132
|
+
(t || e) && (this._handleKeydownEvent = (n) => {
|
|
2133
|
+
if (n.key && n.key.length === 1 && !n.altKey && !n.ctrlKey && !n.metaKey) {
|
|
2134
|
+
if (e && i && s && n.key === "+") {
|
|
2135
|
+
n.preventDefault(), this._openDropdownWithPlus();
|
|
2085
2136
|
return;
|
|
2086
2137
|
}
|
|
2087
2138
|
if (t) {
|
|
2088
|
-
const
|
|
2089
|
-
(!
|
|
2139
|
+
const o = this.telInput.value, d = !(o.charAt(0) === "+") && this.telInput.selectionStart === 0 && n.key === "+", l = /^[0-9]$/.test(n.key), h = e ? l : d || l, p = o.slice(0, this.telInput.selectionStart) + n.key + o.slice(this.telInput.selectionEnd), f = this._getFullNumber(p), c = u.utils.getCoreNumber(f, this.selectedCountryData.iso2), C = this.maxCoreNumberLength && c.length > this.maxCoreNumberLength, g = this._getNewCountryFromNumber(f) !== null;
|
|
2140
|
+
(!h || C && !g && !d) && n.preventDefault();
|
|
2090
2141
|
}
|
|
2091
2142
|
}
|
|
2092
|
-
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent))
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2143
|
+
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
|
|
2144
|
+
}
|
|
2145
|
+
_maybeBindPasteListener() {
|
|
2146
|
+
this.options.strictMode && (this._handlePasteEvent = (t) => {
|
|
2147
|
+
t.preventDefault();
|
|
2148
|
+
const e = this.telInput, i = e.selectionStart, s = e.selectionEnd, n = e.value.slice(0, i), o = e.value.slice(s), a = this.selectedCountryData.iso2, d = t.clipboardData.getData("text"), l = i === 0 && s > 0, h = !e.value.startsWith("+") || l, p = d.replace(/[^0-9+]/g, ""), f = p.startsWith("+"), c = p.replace(/\+/g, ""), C = f && h ? `+${c}` : c;
|
|
2149
|
+
let y = n + C + o, g = u.utils.getCoreNumber(y, a);
|
|
2150
|
+
for (; g.length === 0 && y.length > 0; )
|
|
2151
|
+
y = y.slice(0, -1), g = u.utils.getCoreNumber(y, a);
|
|
2152
|
+
if (!g)
|
|
2153
|
+
return;
|
|
2154
|
+
if (this.maxCoreNumberLength && g.length > this.maxCoreNumberLength)
|
|
2155
|
+
if (e.selectionEnd === e.value.length) {
|
|
2156
|
+
const T = g.length - this.maxCoreNumberLength;
|
|
2157
|
+
y = y.slice(0, y.length - T);
|
|
2101
2158
|
} else
|
|
2102
2159
|
return;
|
|
2103
|
-
|
|
2104
|
-
const
|
|
2105
|
-
|
|
2160
|
+
e.value = y;
|
|
2161
|
+
const b = i + C.length;
|
|
2162
|
+
e.setSelectionRange(b, b), e.dispatchEvent(new InputEvent("input", { bubbles: !0 }));
|
|
2106
2163
|
}, this.telInput.addEventListener("paste", this._handlePasteEvent));
|
|
2107
2164
|
}
|
|
2108
2165
|
//* Adhere to the input's maxlength attr.
|
|
@@ -2187,30 +2244,28 @@ class N {
|
|
|
2187
2244
|
}
|
|
2188
2245
|
//* Country search enabled: Filter the countries according to the search query.
|
|
2189
2246
|
_filterCountries(t) {
|
|
2190
|
-
let e = !0;
|
|
2191
2247
|
this.countryList.innerHTML = "";
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
for (const r of this.countries)
|
|
2199
|
-
r.iso2 === i ? n.push(r) : r.normalisedName.startsWith(i) ? a.push(r) : r.normalisedName.includes(i) ? o.push(r) : i === r.dialCode || i === r.dialCodePlus ? l.push(r) : r.dialCodePlus.includes(i) ? h.push(r) : r.initials.includes(i) && p.push(r);
|
|
2200
|
-
s = [
|
|
2201
|
-
...n.sort((r, c) => r.priority - c.priority),
|
|
2202
|
-
...a.sort((r, c) => r.priority - c.priority),
|
|
2203
|
-
...o.sort((r, c) => r.priority - c.priority),
|
|
2204
|
-
...l.sort((r, c) => r.priority - c.priority),
|
|
2205
|
-
...h.sort((r, c) => r.priority - c.priority),
|
|
2206
|
-
...p.sort((r, c) => r.priority - c.priority)
|
|
2207
|
-
];
|
|
2208
|
-
}
|
|
2209
|
-
for (const n of s) {
|
|
2210
|
-
const a = n.nodeById[this.id];
|
|
2211
|
-
a && (this.countryList.appendChild(a), e && (this._highlightListItem(a, !1), e = !1));
|
|
2248
|
+
let e;
|
|
2249
|
+
t === "" ? e = this.countries : e = this._getMatchedCountries(t);
|
|
2250
|
+
let i = !0;
|
|
2251
|
+
for (const s of e) {
|
|
2252
|
+
const n = s.nodeById[this.id];
|
|
2253
|
+
n && (this.countryList.appendChild(n), i && (this._highlightListItem(n, !1), i = !1));
|
|
2212
2254
|
}
|
|
2213
|
-
|
|
2255
|
+
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();
|
|
2256
|
+
}
|
|
2257
|
+
_getMatchedCountries(t) {
|
|
2258
|
+
const e = x(t), i = [], s = [], n = [], o = [], a = [], d = [];
|
|
2259
|
+
for (const l of this.countries)
|
|
2260
|
+
l.iso2 === e ? i.push(l) : l.normalisedName.startsWith(e) ? s.push(l) : l.normalisedName.includes(e) ? n.push(l) : e === l.dialCode || e === l.dialCodePlus ? o.push(l) : l.dialCodePlus.includes(e) ? a.push(l) : l.initials.includes(e) && d.push(l);
|
|
2261
|
+
return [
|
|
2262
|
+
...i.sort((l, h) => l.priority - h.priority),
|
|
2263
|
+
...s.sort((l, h) => l.priority - h.priority),
|
|
2264
|
+
...n.sort((l, h) => l.priority - h.priority),
|
|
2265
|
+
...o.sort((l, h) => l.priority - h.priority),
|
|
2266
|
+
...a.sort((l, h) => l.priority - h.priority),
|
|
2267
|
+
...d.sort((l, h) => l.priority - h.priority)
|
|
2268
|
+
];
|
|
2214
2269
|
}
|
|
2215
2270
|
//* Update search results text (for a11y).
|
|
2216
2271
|
_updateSearchResultsA11yText() {
|
|
@@ -2233,11 +2288,11 @@ class N {
|
|
|
2233
2288
|
_updateValFromNumber(t) {
|
|
2234
2289
|
let e = t;
|
|
2235
2290
|
if (this.options.formatOnDisplay && u.utils && this.selectedCountryData) {
|
|
2236
|
-
const i = this.options.nationalMode || e.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: n } = u.utils.numberFormat,
|
|
2291
|
+
const i = this.options.nationalMode || e.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: n } = u.utils.numberFormat, o = i ? s : n;
|
|
2237
2292
|
e = u.utils.formatNumber(
|
|
2238
2293
|
e,
|
|
2239
2294
|
this.selectedCountryData.iso2,
|
|
2240
|
-
|
|
2295
|
+
o
|
|
2241
2296
|
);
|
|
2242
2297
|
}
|
|
2243
2298
|
e = this._beforeSetNumber(e), this.telInput.value = e;
|
|
@@ -2252,8 +2307,8 @@ class N {
|
|
|
2252
2307
|
const { dialCode: e, nationalPrefix: i } = this.selectedCountryData;
|
|
2253
2308
|
if (t.charAt(0) === "+" || !e)
|
|
2254
2309
|
return t;
|
|
2255
|
-
const
|
|
2256
|
-
return `+${e}${
|
|
2310
|
+
const o = i && t.charAt(0) === i && !this.options.separateDialCode ? t.substring(1) : t;
|
|
2311
|
+
return `+${e}${o}`;
|
|
2257
2312
|
}
|
|
2258
2313
|
// Get the country ISO2 code from the given number
|
|
2259
2314
|
// BUT ONLY IF ITS CHANGED FROM THE CURRENTLY SELECTED COUNTRY
|
|
@@ -2263,20 +2318,20 @@ class N {
|
|
|
2263
2318
|
let i = e ? t.substring(e) : t;
|
|
2264
2319
|
const s = this.selectedCountryData.iso2, n = this.selectedCountryData.dialCode;
|
|
2265
2320
|
i = this._ensureHasDialCode(i);
|
|
2266
|
-
const
|
|
2267
|
-
if (
|
|
2268
|
-
const
|
|
2269
|
-
if (
|
|
2270
|
-
return
|
|
2271
|
-
if (!s && this.defaultCountry &&
|
|
2321
|
+
const o = this._getDialCode(i, !0), a = I(i);
|
|
2322
|
+
if (o) {
|
|
2323
|
+
const d = I(o), l = this.dialCodeToIso2Map[d];
|
|
2324
|
+
if (l.length === 1)
|
|
2325
|
+
return l[0] === s ? null : l[0];
|
|
2326
|
+
if (!s && this.defaultCountry && l.includes(this.defaultCountry))
|
|
2272
2327
|
return this.defaultCountry;
|
|
2273
|
-
if (n === "1" &&
|
|
2328
|
+
if (n === "1" && A(a))
|
|
2274
2329
|
return null;
|
|
2275
|
-
const
|
|
2276
|
-
if (!(s &&
|
|
2277
|
-
return
|
|
2330
|
+
const p = this.selectedCountryData.areaCodes && a.length > d.length;
|
|
2331
|
+
if (!(s && l.includes(s) && !p))
|
|
2332
|
+
return l[0];
|
|
2278
2333
|
} else {
|
|
2279
|
-
if (i.charAt(0) === "+" &&
|
|
2334
|
+
if (i.charAt(0) === "+" && a.length)
|
|
2280
2335
|
return "";
|
|
2281
2336
|
if ((!i || i === "+") && !s)
|
|
2282
2337
|
return this.defaultCountry;
|
|
@@ -2292,33 +2347,23 @@ class N {
|
|
|
2292
2347
|
}
|
|
2293
2348
|
e && this.highlightedItem.focus();
|
|
2294
2349
|
}
|
|
2295
|
-
//* Find the country data for the given iso2 code
|
|
2296
|
-
//* 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
|
|
2297
|
-
_getCountryData(t, e) {
|
|
2298
|
-
const i = this.countryByIso2.get(t);
|
|
2299
|
-
if (i)
|
|
2300
|
-
return i;
|
|
2301
|
-
if (e)
|
|
2302
|
-
return null;
|
|
2303
|
-
throw new Error(`No country data for '${t}'`);
|
|
2304
|
-
}
|
|
2305
2350
|
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
|
|
2306
2351
|
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
|
|
2307
2352
|
_setCountry(t) {
|
|
2308
2353
|
const { separateDialCode: e, showFlags: i, i18n: s } = this.options, n = this.selectedCountryData.iso2 || "";
|
|
2309
|
-
if (this.selectedCountryData = t ? this.
|
|
2310
|
-
const
|
|
2311
|
-
let
|
|
2354
|
+
if (this.selectedCountryData = t ? this.countryByIso2.get(t) : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.selectedCountry) {
|
|
2355
|
+
const o = t && i ? `iti__flag iti__${t}` : "iti__flag iti__globe";
|
|
2356
|
+
let a, d;
|
|
2312
2357
|
if (t) {
|
|
2313
|
-
const { name:
|
|
2314
|
-
|
|
2358
|
+
const { name: l, dialCode: h } = this.selectedCountryData;
|
|
2359
|
+
d = l, a = s.selectedCountryAriaLabel.replace("${countryName}", l).replace("${dialCode}", `+${h}`);
|
|
2315
2360
|
} else
|
|
2316
|
-
|
|
2317
|
-
this.selectedCountryInner.className =
|
|
2361
|
+
d = s.noCountrySelected, a = s.noCountrySelected;
|
|
2362
|
+
this.selectedCountryInner.className = o, this.selectedCountry.setAttribute("title", d), this.selectedCountry.setAttribute("aria-label", a);
|
|
2318
2363
|
}
|
|
2319
2364
|
if (e) {
|
|
2320
|
-
const
|
|
2321
|
-
this.selectedDialCode.innerHTML =
|
|
2365
|
+
const o = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2366
|
+
this.selectedDialCode.innerHTML = o, this._updateInputPadding();
|
|
2322
2367
|
}
|
|
2323
2368
|
return this._updatePlaceholder(), this._updateMaxLength(), n !== t;
|
|
2324
2369
|
}
|
|
@@ -2335,16 +2380,16 @@ class N {
|
|
|
2335
2380
|
if (t && u.utils)
|
|
2336
2381
|
if (s) {
|
|
2337
2382
|
const n = u.utils.numberType[e];
|
|
2338
|
-
let
|
|
2383
|
+
let o = u.utils.getExampleNumber(
|
|
2339
2384
|
s,
|
|
2340
2385
|
!1,
|
|
2341
2386
|
n,
|
|
2342
2387
|
!0
|
|
2343
|
-
),
|
|
2344
|
-
for (; u.utils.isPossibleNumber(
|
|
2345
|
-
|
|
2346
|
-
const
|
|
2347
|
-
this.maxCoreNumberLength =
|
|
2388
|
+
), a = o;
|
|
2389
|
+
for (; u.utils.isPossibleNumber(o, s, i); )
|
|
2390
|
+
a = o, o += "0";
|
|
2391
|
+
const d = u.utils.getCoreNumber(a, s);
|
|
2392
|
+
this.maxCoreNumberLength = d.length, s === "by" && (this.maxCoreNumberLength = d.length + 1);
|
|
2348
2393
|
} else
|
|
2349
2394
|
this.maxCoreNumberLength = null;
|
|
2350
2395
|
}
|
|
@@ -2380,21 +2425,21 @@ class N {
|
|
|
2380
2425
|
customPlaceholder: s
|
|
2381
2426
|
} = this.options, n = t === "aggressive" || !this.hadInitialPlaceholder && t === "polite";
|
|
2382
2427
|
if (u.utils && n) {
|
|
2383
|
-
const
|
|
2384
|
-
let
|
|
2428
|
+
const o = u.utils.numberType[e];
|
|
2429
|
+
let a = this.selectedCountryData.iso2 ? u.utils.getExampleNumber(
|
|
2385
2430
|
this.selectedCountryData.iso2,
|
|
2386
2431
|
i,
|
|
2387
|
-
|
|
2432
|
+
o
|
|
2388
2433
|
) : "";
|
|
2389
|
-
|
|
2434
|
+
a = this._beforeSetNumber(a), typeof s == "function" && (a = s(a, this.selectedCountryData)), this.telInput.setAttribute("placeholder", a);
|
|
2390
2435
|
}
|
|
2391
2436
|
}
|
|
2392
2437
|
//* Called when the user selects a list item from the dropdown.
|
|
2393
2438
|
_selectListItem(t) {
|
|
2394
|
-
const e = this._setCountry(
|
|
2395
|
-
|
|
2396
|
-
);
|
|
2397
|
-
this.
|
|
2439
|
+
const e = t.getAttribute("data-country-code"), i = this._setCountry(e);
|
|
2440
|
+
this._closeDropdown();
|
|
2441
|
+
const s = t.getAttribute("data-dial-code");
|
|
2442
|
+
this._updateDialCode(s), this.options.formatOnDisplay && this._updateValFromNumber(this.telInput.value), this.telInput.focus(), i && this._triggerCountryChange();
|
|
2398
2443
|
}
|
|
2399
2444
|
//* Close the dropdown and unbind any listeners.
|
|
2400
2445
|
_closeDropdown() {
|
|
@@ -2408,12 +2453,12 @@ class N {
|
|
|
2408
2453
|
}
|
|
2409
2454
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2410
2455
|
_scrollTo(t) {
|
|
2411
|
-
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, n = e.getBoundingClientRect().top + i,
|
|
2412
|
-
if (
|
|
2413
|
-
e.scrollTop =
|
|
2414
|
-
else if (
|
|
2415
|
-
const
|
|
2416
|
-
e.scrollTop =
|
|
2456
|
+
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, n = e.getBoundingClientRect().top + i, o = n + s, a = t.offsetHeight, d = t.getBoundingClientRect().top + i, l = d + a, h = d - n + e.scrollTop;
|
|
2457
|
+
if (d < n)
|
|
2458
|
+
e.scrollTop = h;
|
|
2459
|
+
else if (l > o) {
|
|
2460
|
+
const p = s - a;
|
|
2461
|
+
e.scrollTop = h - p;
|
|
2417
2462
|
}
|
|
2418
2463
|
}
|
|
2419
2464
|
//* Replace any existing dial code with the new one
|
|
@@ -2433,9 +2478,9 @@ class N {
|
|
|
2433
2478
|
if (t.charAt(0) === "+") {
|
|
2434
2479
|
let s = "";
|
|
2435
2480
|
for (let n = 0; n < t.length; n++) {
|
|
2436
|
-
const
|
|
2437
|
-
if (!isNaN(parseInt(
|
|
2438
|
-
if (s +=
|
|
2481
|
+
const o = t.charAt(n);
|
|
2482
|
+
if (!isNaN(parseInt(o, 10))) {
|
|
2483
|
+
if (s += o, e)
|
|
2439
2484
|
this.dialCodeToIso2Map[s] && (i = t.substring(0, n + 1));
|
|
2440
2485
|
else if (this.dialCodes.has(s)) {
|
|
2441
2486
|
i = t.substring(0, n + 1);
|
|
@@ -2452,31 +2497,23 @@ class N {
|
|
|
2452
2497
|
_getFullNumber(t) {
|
|
2453
2498
|
const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
|
|
2454
2499
|
let s;
|
|
2455
|
-
const n =
|
|
2500
|
+
const n = I(e);
|
|
2456
2501
|
return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
|
|
2457
2502
|
}
|
|
2458
2503
|
//* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
|
|
2459
2504
|
_beforeSetNumber(t) {
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
return this._cap(e);
|
|
2505
|
+
const e = this._getDialCode(t), i = Q(
|
|
2506
|
+
t,
|
|
2507
|
+
e,
|
|
2508
|
+
this.options.separateDialCode,
|
|
2509
|
+
this.selectedCountryData
|
|
2510
|
+
);
|
|
2511
|
+
return this._cap(i);
|
|
2470
2512
|
}
|
|
2471
2513
|
//* Trigger the 'countrychange' event.
|
|
2472
2514
|
_triggerCountryChange() {
|
|
2473
2515
|
this._trigger("countrychange");
|
|
2474
2516
|
}
|
|
2475
|
-
//* Format the number as the user types.
|
|
2476
|
-
_formatNumberAsYouType() {
|
|
2477
|
-
const t = this._getFullNumber(), e = u.utils ? u.utils.formatNumberAsYouType(t, this.selectedCountryData.iso2) : t, { dialCode: i } = this.selectedCountryData;
|
|
2478
|
-
return this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && e.includes(`+${i}`) ? (e.split(`+${i}`)[1] || "").trim() : e;
|
|
2479
|
-
}
|
|
2480
2517
|
//**************************
|
|
2481
2518
|
//* SECRET PUBLIC METHODS
|
|
2482
2519
|
//**************************
|
|
@@ -2493,7 +2530,7 @@ class N {
|
|
|
2493
2530
|
//********************
|
|
2494
2531
|
//* Remove plugin.
|
|
2495
2532
|
destroy() {
|
|
2496
|
-
var n,
|
|
2533
|
+
var n, o;
|
|
2497
2534
|
this.telInput.iti = void 0;
|
|
2498
2535
|
const { allowDropdown: t, separateDialCode: e } = this.options;
|
|
2499
2536
|
if (t) {
|
|
@@ -2504,13 +2541,13 @@ class N {
|
|
|
2504
2541
|
"keydown",
|
|
2505
2542
|
this._handleCountryContainerKeydown
|
|
2506
2543
|
);
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2544
|
+
const a = this.telInput.closest("label");
|
|
2545
|
+
a && a.removeEventListener("click", this._handleLabelClick);
|
|
2509
2546
|
}
|
|
2510
2547
|
const { form: i } = this.telInput;
|
|
2511
2548
|
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.telInput.removeAttribute("data-intl-tel-input-id"), e && (this.isRTL ? this.telInput.style.paddingRight = this.originalPaddingRight : this.telInput.style.paddingLeft = this.originalPaddingLeft);
|
|
2512
2549
|
const s = this.telInput.parentNode;
|
|
2513
|
-
(n = s == null ? void 0 : s.parentNode) == null || n.insertBefore(this.telInput, s), (
|
|
2550
|
+
(n = s == null ? void 0 : s.parentNode) == null || n.insertBefore(this.telInput, s), (o = s == null ? void 0 : s.parentNode) == null || o.removeChild(s), delete u.instances[this.id];
|
|
2514
2551
|
}
|
|
2515
2552
|
//* Get the extension from the current number.
|
|
2516
2553
|
getExtension() {
|
|
@@ -2565,10 +2602,10 @@ class N {
|
|
|
2565
2602
|
_validateNumber(t) {
|
|
2566
2603
|
if (!this.selectedCountryData.iso2)
|
|
2567
2604
|
return !1;
|
|
2568
|
-
const e = (
|
|
2605
|
+
const e = (o) => t ? this._utilsIsValidNumber(o) : this._utilsIsPossibleNumber(o), i = this._getFullNumber(), s = i.search(new RegExp("\\p{L}", "u"));
|
|
2569
2606
|
if (s > -1 && !this.options.allowPhonewords) {
|
|
2570
|
-
const
|
|
2571
|
-
return
|
|
2607
|
+
const o = i.substring(0, s), a = e(o), d = e(i);
|
|
2608
|
+
return a && d;
|
|
2572
2609
|
}
|
|
2573
2610
|
return e(i);
|
|
2574
2611
|
}
|
|
@@ -2577,7 +2614,10 @@ class N {
|
|
|
2577
2614
|
}
|
|
2578
2615
|
//* Update the selected country, and update the input val accordingly.
|
|
2579
2616
|
setCountry(t) {
|
|
2580
|
-
const e = t == null ? void 0 : t.toLowerCase()
|
|
2617
|
+
const e = t == null ? void 0 : t.toLowerCase();
|
|
2618
|
+
if (!D(e))
|
|
2619
|
+
throw new Error(`Invalid country code: '${e}'`);
|
|
2620
|
+
const i = this.selectedCountryData.iso2;
|
|
2581
2621
|
(t && e !== i || !t && i) && (this._setCountry(e), this._updateDialCode(this.selectedCountryData.dialCode), this.options.formatOnDisplay && this._updateValFromNumber(this.telInput.value), this._triggerCountryChange());
|
|
2582
2622
|
}
|
|
2583
2623
|
//* Set the input value and update the country.
|
|
@@ -2593,53 +2633,53 @@ class N {
|
|
|
2593
2633
|
this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled");
|
|
2594
2634
|
}
|
|
2595
2635
|
}
|
|
2596
|
-
const
|
|
2636
|
+
const nt = (r) => {
|
|
2597
2637
|
if (!u.utils && !u.startedLoadingUtilsScript) {
|
|
2598
2638
|
let t;
|
|
2599
|
-
if (typeof
|
|
2639
|
+
if (typeof r == "function")
|
|
2600
2640
|
try {
|
|
2601
|
-
t = Promise.resolve(
|
|
2641
|
+
t = Promise.resolve(r());
|
|
2602
2642
|
} catch (e) {
|
|
2603
2643
|
return Promise.reject(e);
|
|
2604
2644
|
}
|
|
2605
2645
|
else
|
|
2606
|
-
return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof
|
|
2646
|
+
return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof r}`));
|
|
2607
2647
|
return u.startedLoadingUtilsScript = !0, t.then((e) => {
|
|
2608
2648
|
const i = e == null ? void 0 : e.default;
|
|
2609
2649
|
if (!i || typeof i != "object")
|
|
2610
2650
|
throw new TypeError("The loader function passed to attachUtils did not resolve to a module object with utils as its default export.");
|
|
2611
|
-
return u.utils = i,
|
|
2651
|
+
return u.utils = i, w("handleUtils"), !0;
|
|
2612
2652
|
}).catch((e) => {
|
|
2613
|
-
throw
|
|
2653
|
+
throw w("rejectUtilsScriptPromise", e), e;
|
|
2614
2654
|
});
|
|
2615
2655
|
}
|
|
2616
2656
|
return null;
|
|
2617
2657
|
}, u = Object.assign(
|
|
2618
|
-
(
|
|
2619
|
-
const e = new
|
|
2620
|
-
return e._init(),
|
|
2658
|
+
(r, t) => {
|
|
2659
|
+
const e = new v(r, t);
|
|
2660
|
+
return e._init(), r.setAttribute("data-intl-tel-input-id", e.id.toString()), u.instances[e.id] = e, r.iti = e, e;
|
|
2621
2661
|
},
|
|
2622
2662
|
{
|
|
2623
|
-
defaults:
|
|
2663
|
+
defaults: P,
|
|
2624
2664
|
//* Using a static var like this allows us to mock it in the tests.
|
|
2625
2665
|
documentReady: () => document.readyState === "complete",
|
|
2626
2666
|
//* Get the country data object.
|
|
2627
|
-
getCountryData: () =>
|
|
2667
|
+
getCountryData: () => _,
|
|
2628
2668
|
//* A getter for the plugin instance.
|
|
2629
|
-
getInstance: (
|
|
2630
|
-
const t =
|
|
2669
|
+
getInstance: (r) => {
|
|
2670
|
+
const t = r.getAttribute("data-intl-tel-input-id");
|
|
2631
2671
|
return t ? u.instances[t] : null;
|
|
2632
2672
|
},
|
|
2633
2673
|
//* A map from instance ID to instance object.
|
|
2634
2674
|
instances: {},
|
|
2635
|
-
attachUtils:
|
|
2675
|
+
attachUtils: nt,
|
|
2636
2676
|
startedLoadingUtilsScript: !1,
|
|
2637
2677
|
startedLoadingAutoCountry: !1,
|
|
2638
|
-
version: "25.10.
|
|
2678
|
+
version: "25.10.8"
|
|
2639
2679
|
}
|
|
2640
|
-
),
|
|
2680
|
+
), at = {
|
|
2641
2681
|
__name: "IntlTelInput",
|
|
2642
|
-
props: /* @__PURE__ */
|
|
2682
|
+
props: /* @__PURE__ */ S({
|
|
2643
2683
|
disabled: {
|
|
2644
2684
|
type: Boolean,
|
|
2645
2685
|
default: !1
|
|
@@ -2663,47 +2703,47 @@ const Z = (d) => {
|
|
|
2663
2703
|
},
|
|
2664
2704
|
modelModifiers: {}
|
|
2665
2705
|
}),
|
|
2666
|
-
emits: /* @__PURE__ */
|
|
2706
|
+
emits: /* @__PURE__ */ S([
|
|
2667
2707
|
"changeNumber",
|
|
2668
2708
|
"changeCountry",
|
|
2669
2709
|
"changeValidity",
|
|
2670
2710
|
"changeErrorCode"
|
|
2671
2711
|
], ["update:modelValue"]),
|
|
2672
|
-
setup(
|
|
2673
|
-
const i =
|
|
2674
|
-
let
|
|
2675
|
-
|
|
2712
|
+
setup(r, { expose: t, emit: e }) {
|
|
2713
|
+
const i = E(r, "modelValue"), s = r, n = e, o = L(), a = L(), d = L(!1), l = () => a.value ? s.options.strictMode ? a.value.isValidNumberPrecise() : a.value.isValidNumber() : null, h = () => {
|
|
2714
|
+
let c = l();
|
|
2715
|
+
d.value !== c && (d.value = c, n("changeValidity", !!c), n(
|
|
2676
2716
|
"changeErrorCode",
|
|
2677
|
-
|
|
2717
|
+
c ? null : a.value.getValidationError()
|
|
2678
2718
|
));
|
|
2679
|
-
},
|
|
2680
|
-
var
|
|
2681
|
-
n("changeNumber", ((
|
|
2682
|
-
},
|
|
2683
|
-
var
|
|
2684
|
-
n("changeCountry", ((
|
|
2719
|
+
}, p = () => {
|
|
2720
|
+
var c;
|
|
2721
|
+
n("changeNumber", ((c = a.value) == null ? void 0 : c.getNumber()) ?? ""), h();
|
|
2722
|
+
}, f = () => {
|
|
2723
|
+
var c;
|
|
2724
|
+
n("changeCountry", ((c = a.value) == null ? void 0 : c.getSelectedCountryData().iso2) ?? ""), p(), h();
|
|
2685
2725
|
};
|
|
2686
|
-
return
|
|
2687
|
-
|
|
2688
|
-
}),
|
|
2726
|
+
return M(() => {
|
|
2727
|
+
o.value && (a.value = u(o.value, s.options), s.value && a.value.setNumber(s.value), s.disabled && a.value.setDisabled(s.disabled), d.value = l());
|
|
2728
|
+
}), B(
|
|
2689
2729
|
() => s.disabled,
|
|
2690
|
-
(
|
|
2691
|
-
var
|
|
2692
|
-
return (
|
|
2730
|
+
(c) => {
|
|
2731
|
+
var C;
|
|
2732
|
+
return (C = a.value) == null ? void 0 : C.setDisabled(c);
|
|
2693
2733
|
}
|
|
2694
|
-
),
|
|
2695
|
-
var
|
|
2696
|
-
return (
|
|
2697
|
-
}), t({ instance:
|
|
2734
|
+
), R(() => {
|
|
2735
|
+
var c;
|
|
2736
|
+
return (c = a.value) == null ? void 0 : c.destroy();
|
|
2737
|
+
}), t({ instance: a, input: o }), (c, C) => F((V(), z("input", $({
|
|
2698
2738
|
ref_key: "input",
|
|
2699
|
-
ref:
|
|
2700
|
-
"onUpdate:modelValue":
|
|
2739
|
+
ref: o,
|
|
2740
|
+
"onUpdate:modelValue": C[0] || (C[0] = (y) => i.value = y),
|
|
2701
2741
|
type: "tel",
|
|
2702
|
-
onCountrychange:
|
|
2703
|
-
onInput:
|
|
2704
|
-
},
|
|
2742
|
+
onCountrychange: f,
|
|
2743
|
+
onInput: p
|
|
2744
|
+
}, r.inputProps), null, 16)), [
|
|
2705
2745
|
[
|
|
2706
|
-
|
|
2746
|
+
O,
|
|
2707
2747
|
i.value,
|
|
2708
2748
|
void 0,
|
|
2709
2749
|
{ lazy: !0 }
|
|
@@ -2712,5 +2752,5 @@ const Z = (d) => {
|
|
|
2712
2752
|
}
|
|
2713
2753
|
};
|
|
2714
2754
|
export {
|
|
2715
|
-
|
|
2755
|
+
at as default
|
|
2716
2756
|
};
|