intl-tel-input 25.10.6 → 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 +415 -316
- package/angular/build/IntlTelInputWithUtils.js +466 -338
- 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 +17 -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 +100 -292
- package/build/js/intlTelInput.js +461 -357
- package/build/js/intlTelInput.min.js +13 -13
- package/build/js/intlTelInputWithUtils.js +512 -379
- 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 +460 -356
- package/react/build/IntlTelInput.d.ts +104 -294
- package/react/build/IntlTelInput.js +460 -356
- package/react/build/IntlTelInputWithUtils.cjs +511 -378
- package/react/build/IntlTelInputWithUtils.js +511 -378
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +506 -452
- package/vue/build/IntlTelInputWithUtils.mjs +1096 -1013
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeModels as
|
|
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
2
|
const j = [
|
|
3
3
|
[
|
|
4
4
|
"af",
|
|
@@ -1322,18 +1322,18 @@ const j = [
|
|
|
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
1338
|
const U = {
|
|
1339
1339
|
ad: "Andorra",
|
|
@@ -1590,17 +1590,13 @@ const U = {
|
|
|
1590
1590
|
// additional countries (not supported by country-list library)
|
|
1591
1591
|
ac: "Ascension Island",
|
|
1592
1592
|
xk: "Kosovo"
|
|
1593
|
-
},
|
|
1594
|
-
for (const u of w)
|
|
1595
|
-
u.name = T[u.iso2];
|
|
1596
|
-
let K = 0;
|
|
1597
|
-
const N = (u) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(u).matches, W = () => {
|
|
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 N = (u) => 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 N = (u) => 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
|
-
}, q = (u, t, e, i) => {
|
|
1680
|
-
if (e === 0 && !i)
|
|
1681
|
-
return 0;
|
|
1682
|
-
let s = 0;
|
|
1683
|
-
for (let n = 0; n < t.length; n++) {
|
|
1684
|
-
if (/[+0-9]/.test(t[n]) && s++, s === u && !i)
|
|
1685
|
-
return n + 1;
|
|
1686
|
-
if (i && s === u + 1)
|
|
1687
|
-
return n;
|
|
1688
|
-
}
|
|
1689
|
-
return t.length;
|
|
1690
|
-
}, y = (u, t, e) => {
|
|
1691
|
-
const i = document.createElement(u);
|
|
1692
|
-
return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
|
|
1693
|
-
}, I = (u, ...t) => {
|
|
1694
|
-
const { instances: e } = l;
|
|
1695
|
-
Object.values(e).forEach((i) => i[u](...t));
|
|
1696
1771
|
};
|
|
1697
|
-
|
|
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) => {
|
|
1776
|
+
const { instances: e } = u;
|
|
1777
|
+
Object.values(e).forEach((i) => i[r](...t));
|
|
1778
|
+
};
|
|
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 L {
|
|
|
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 = k(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: d,
|
|
1815
|
-
countrySearch: c,
|
|
1816
|
-
i18n: C
|
|
1817
|
-
} = this.options, r = L._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
|
-
|
|
1825
|
-
|
|
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) {
|
|
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",
|
|
@@ -1838,145 +1861,160 @@ class L {
|
|
|
1838
1861
|
"aria-controls": `iti-${this.id}__dropdown-content`
|
|
1839
1862
|
},
|
|
1840
1863
|
this.countryContainer
|
|
1841
|
-
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry =
|
|
1864
|
+
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = m(
|
|
1842
1865
|
"div",
|
|
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 b = o ? "" : "iti--flexible-dropdown-width";
|
|
1865
|
-
if (this.dropdownContent = y("div", {
|
|
1866
|
-
id: `iti-${this.id}__dropdown-content`,
|
|
1867
|
-
class: `iti__dropdown-content iti__hide ${b}`,
|
|
1868
|
-
role: "dialog",
|
|
1869
|
-
"aria-modal": "true"
|
|
1870
|
-
}), c) {
|
|
1871
|
-
const f = y(
|
|
1872
|
-
"div",
|
|
1873
|
-
{ class: "iti__search-input-wrapper" },
|
|
1874
|
-
this.dropdownContent
|
|
1875
|
-
);
|
|
1876
|
-
this.searchIcon = y(
|
|
1877
|
-
"span",
|
|
1878
|
-
{
|
|
1879
|
-
class: "iti__search-icon",
|
|
1880
|
-
"aria-hidden": "true"
|
|
1881
|
-
},
|
|
1882
|
-
f
|
|
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 = y(
|
|
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: C.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": C.searchPlaceholder,
|
|
1899
|
-
"aria-controls": `iti-${this.id}__country-listbox`,
|
|
1900
|
-
"aria-autocomplete": "list",
|
|
1901
|
-
autocomplete: "off"
|
|
1902
|
-
},
|
|
1903
|
-
f
|
|
1904
|
-
), this.searchClearButton = y(
|
|
1905
|
-
"button",
|
|
1906
|
-
{
|
|
1907
|
-
type: "button",
|
|
1908
|
-
class: "iti__search-clear iti__hide",
|
|
1909
|
-
"aria-label": C.clearSearchAriaLabel,
|
|
1910
|
-
tabindex: "-1"
|
|
1911
|
-
},
|
|
1912
|
-
f
|
|
1913
|
-
);
|
|
1914
|
-
const S = `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="${S}" 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(#${S})" />
|
|
1922
|
-
</svg>`, this.searchResultsA11yText = y(
|
|
1923
|
-
"span",
|
|
1924
|
-
{ class: "iti__a11y-text" },
|
|
1925
|
-
this.dropdownContent
|
|
1926
|
-
), this.searchNoResults = y(
|
|
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 = C.zeroSearchResults;
|
|
1935
|
-
}
|
|
1936
|
-
if (this.countryList = y(
|
|
1937
|
-
"ul",
|
|
1938
|
-
{
|
|
1939
|
-
class: "iti__country-list",
|
|
1940
|
-
id: `iti-${this.id}__country-listbox`,
|
|
1941
|
-
role: "listbox",
|
|
1942
|
-
"aria-label": C.countryListAriaLabel
|
|
1943
|
-
},
|
|
1944
|
-
this.dropdownContent
|
|
1945
|
-
), this._appendListItems(), c && this._updateSearchResultsA11yText(), a) {
|
|
1946
|
-
const f = L._buildClassNames({
|
|
1947
|
-
iti: !0,
|
|
1948
|
-
"iti--container": !0,
|
|
1949
|
-
"iti--fullscreen-popup": d,
|
|
1950
|
-
"iti--inline-dropdown": !d,
|
|
1951
|
-
[s]: !!s
|
|
1952
|
-
});
|
|
1953
|
-
this.dropdown = y("div", { class: f }), 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
|
}
|
|
1976
2014
|
//* For each country: add a country list item <li> to the countryList <ul> container.
|
|
1977
2015
|
_appendListItems() {
|
|
1978
2016
|
for (let t = 0; t < this.countries.length; t++) {
|
|
1979
|
-
const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s =
|
|
2017
|
+
const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s = m(
|
|
1980
2018
|
"li",
|
|
1981
2019
|
{
|
|
1982
2020
|
id: `iti-${this.id}__item-${e.iso2}`,
|
|
@@ -1998,12 +2036,12 @@ class L {
|
|
|
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
|
}
|
|
@@ -2039,21 +2077,21 @@ class L {
|
|
|
2039
2077
|
//* Init many requests: utils script / geo ip lookup.
|
|
2040
2078
|
_initRequests() {
|
|
2041
2079
|
let { loadUtils: t, initialCountry: e, geoIpLookup: i } = this.options;
|
|
2042
|
-
t && !
|
|
2080
|
+
t && !u.utils ? (this._handlePageLoad = () => {
|
|
2043
2081
|
var n;
|
|
2044
|
-
window.removeEventListener("load", this._handlePageLoad), (n =
|
|
2082
|
+
window.removeEventListener("load", this._handlePageLoad), (n = u.attachUtils(t)) == null || n.catch(() => {
|
|
2045
2083
|
});
|
|
2046
|
-
},
|
|
2084
|
+
}, u.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), e === "auto" && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
|
|
2047
2085
|
}
|
|
2048
2086
|
//* Perform the geo ip lookup.
|
|
2049
2087
|
_loadAutoCountry() {
|
|
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,35 +2100,68 @@ class L {
|
|
|
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 d = (
|
|
2075
|
-
d ||
|
|
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
|
-
(!h ||
|
|
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
2143
|
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
|
|
2093
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);
|
|
2158
|
+
} else
|
|
2159
|
+
return;
|
|
2160
|
+
e.value = y;
|
|
2161
|
+
const b = i + C.length;
|
|
2162
|
+
e.setSelectionRange(b, b), e.dispatchEvent(new InputEvent("input", { bubbles: !0 }));
|
|
2163
|
+
}, this.telInput.addEventListener("paste", this._handlePasteEvent));
|
|
2164
|
+
}
|
|
2094
2165
|
//* Adhere to the input's maxlength attr.
|
|
2095
2166
|
_cap(t) {
|
|
2096
2167
|
const e = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
|
|
@@ -2173,30 +2244,28 @@ class L {
|
|
|
2173
2244
|
}
|
|
2174
2245
|
//* Country search enabled: Filter the countries according to the search query.
|
|
2175
2246
|
_filterCountries(t) {
|
|
2176
|
-
let e = !0;
|
|
2177
2247
|
this.countryList.innerHTML = "";
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
for (const r of this.countries)
|
|
2185
|
-
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 ? d.push(r) : r.dialCodePlus.includes(i) ? c.push(r) : r.initials.includes(i) && C.push(r);
|
|
2186
|
-
s = [
|
|
2187
|
-
...n.sort((r, h) => r.priority - h.priority),
|
|
2188
|
-
...a.sort((r, h) => r.priority - h.priority),
|
|
2189
|
-
...o.sort((r, h) => r.priority - h.priority),
|
|
2190
|
-
...d.sort((r, h) => r.priority - h.priority),
|
|
2191
|
-
...c.sort((r, h) => r.priority - h.priority),
|
|
2192
|
-
...C.sort((r, h) => r.priority - h.priority)
|
|
2193
|
-
];
|
|
2194
|
-
}
|
|
2195
|
-
for (const n of s) {
|
|
2196
|
-
const a = n.nodeById[this.id];
|
|
2197
|
-
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));
|
|
2198
2254
|
}
|
|
2199
|
-
|
|
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
|
+
];
|
|
2200
2269
|
}
|
|
2201
2270
|
//* Update search results text (for a11y).
|
|
2202
2271
|
_updateSearchResultsA11yText() {
|
|
@@ -2218,12 +2287,12 @@ class L {
|
|
|
2218
2287
|
//* NOTE: this is called from _setInitialState, handleUtils and setNumber.
|
|
2219
2288
|
_updateValFromNumber(t) {
|
|
2220
2289
|
let e = t;
|
|
2221
|
-
if (this.options.formatOnDisplay &&
|
|
2222
|
-
const i = this.options.nationalMode || e.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: n } =
|
|
2223
|
-
e =
|
|
2290
|
+
if (this.options.formatOnDisplay && u.utils && this.selectedCountryData) {
|
|
2291
|
+
const i = this.options.nationalMode || e.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: n } = u.utils.numberFormat, o = i ? s : n;
|
|
2292
|
+
e = u.utils.formatNumber(
|
|
2224
2293
|
e,
|
|
2225
2294
|
this.selectedCountryData.iso2,
|
|
2226
|
-
|
|
2295
|
+
o
|
|
2227
2296
|
);
|
|
2228
2297
|
}
|
|
2229
2298
|
e = this._beforeSetNumber(e), this.telInput.value = e;
|
|
@@ -2238,8 +2307,8 @@ class L {
|
|
|
2238
2307
|
const { dialCode: e, nationalPrefix: i } = this.selectedCountryData;
|
|
2239
2308
|
if (t.charAt(0) === "+" || !e)
|
|
2240
2309
|
return t;
|
|
2241
|
-
const
|
|
2242
|
-
return `+${e}${
|
|
2310
|
+
const o = i && t.charAt(0) === i && !this.options.separateDialCode ? t.substring(1) : t;
|
|
2311
|
+
return `+${e}${o}`;
|
|
2243
2312
|
}
|
|
2244
2313
|
// Get the country ISO2 code from the given number
|
|
2245
2314
|
// BUT ONLY IF ITS CHANGED FROM THE CURRENTLY SELECTED COUNTRY
|
|
@@ -2249,20 +2318,20 @@ class L {
|
|
|
2249
2318
|
let i = e ? t.substring(e) : t;
|
|
2250
2319
|
const s = this.selectedCountryData.iso2, n = this.selectedCountryData.dialCode;
|
|
2251
2320
|
i = this._ensureHasDialCode(i);
|
|
2252
|
-
const
|
|
2253
|
-
if (
|
|
2254
|
-
const d =
|
|
2255
|
-
if (
|
|
2256
|
-
return
|
|
2257
|
-
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))
|
|
2258
2327
|
return this.defaultCountry;
|
|
2259
|
-
if (n === "1" &&
|
|
2328
|
+
if (n === "1" && A(a))
|
|
2260
2329
|
return null;
|
|
2261
|
-
const
|
|
2262
|
-
if (!(s &&
|
|
2263
|
-
return
|
|
2330
|
+
const p = this.selectedCountryData.areaCodes && a.length > d.length;
|
|
2331
|
+
if (!(s && l.includes(s) && !p))
|
|
2332
|
+
return l[0];
|
|
2264
2333
|
} else {
|
|
2265
|
-
if (i.charAt(0) === "+" &&
|
|
2334
|
+
if (i.charAt(0) === "+" && a.length)
|
|
2266
2335
|
return "";
|
|
2267
2336
|
if ((!i || i === "+") && !s)
|
|
2268
2337
|
return this.defaultCountry;
|
|
@@ -2278,33 +2347,23 @@ class L {
|
|
|
2278
2347
|
}
|
|
2279
2348
|
e && this.highlightedItem.focus();
|
|
2280
2349
|
}
|
|
2281
|
-
//* Find the country data for the given iso2 code
|
|
2282
|
-
//* 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
|
|
2283
|
-
_getCountryData(t, e) {
|
|
2284
|
-
const i = this.countryByIso2.get(t);
|
|
2285
|
-
if (i)
|
|
2286
|
-
return i;
|
|
2287
|
-
if (e)
|
|
2288
|
-
return null;
|
|
2289
|
-
throw new Error(`No country data for '${t}'`);
|
|
2290
|
-
}
|
|
2291
2350
|
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
|
|
2292
2351
|
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
|
|
2293
2352
|
_setCountry(t) {
|
|
2294
2353
|
const { separateDialCode: e, showFlags: i, i18n: s } = this.options, n = this.selectedCountryData.iso2 || "";
|
|
2295
|
-
if (this.selectedCountryData = t ? this.
|
|
2296
|
-
const
|
|
2297
|
-
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;
|
|
2298
2357
|
if (t) {
|
|
2299
|
-
const { name:
|
|
2300
|
-
d =
|
|
2358
|
+
const { name: l, dialCode: h } = this.selectedCountryData;
|
|
2359
|
+
d = l, a = s.selectedCountryAriaLabel.replace("${countryName}", l).replace("${dialCode}", `+${h}`);
|
|
2301
2360
|
} else
|
|
2302
|
-
d = s.noCountrySelected,
|
|
2303
|
-
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);
|
|
2304
2363
|
}
|
|
2305
2364
|
if (e) {
|
|
2306
|
-
const
|
|
2307
|
-
this.selectedDialCode.innerHTML =
|
|
2365
|
+
const o = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2366
|
+
this.selectedDialCode.innerHTML = o, this._updateInputPadding();
|
|
2308
2367
|
}
|
|
2309
2368
|
return this._updatePlaceholder(), this._updateMaxLength(), n !== t;
|
|
2310
2369
|
}
|
|
@@ -2318,18 +2377,18 @@ class L {
|
|
|
2318
2377
|
//* Update the maximum valid number length for the currently selected country.
|
|
2319
2378
|
_updateMaxLength() {
|
|
2320
2379
|
const { strictMode: t, placeholderNumberType: e, validationNumberTypes: i } = this.options, { iso2: s } = this.selectedCountryData;
|
|
2321
|
-
if (t &&
|
|
2380
|
+
if (t && u.utils)
|
|
2322
2381
|
if (s) {
|
|
2323
|
-
const n =
|
|
2324
|
-
let
|
|
2382
|
+
const n = u.utils.numberType[e];
|
|
2383
|
+
let o = u.utils.getExampleNumber(
|
|
2325
2384
|
s,
|
|
2326
2385
|
!1,
|
|
2327
2386
|
n,
|
|
2328
2387
|
!0
|
|
2329
|
-
),
|
|
2330
|
-
for (;
|
|
2331
|
-
|
|
2332
|
-
const d =
|
|
2388
|
+
), a = o;
|
|
2389
|
+
for (; u.utils.isPossibleNumber(o, s, i); )
|
|
2390
|
+
a = o, o += "0";
|
|
2391
|
+
const d = u.utils.getCoreNumber(a, s);
|
|
2333
2392
|
this.maxCoreNumberLength = d.length, s === "by" && (this.maxCoreNumberLength = d.length + 1);
|
|
2334
2393
|
} else
|
|
2335
2394
|
this.maxCoreNumberLength = null;
|
|
@@ -2365,22 +2424,22 @@ class L {
|
|
|
2365
2424
|
nationalMode: i,
|
|
2366
2425
|
customPlaceholder: s
|
|
2367
2426
|
} = this.options, n = t === "aggressive" || !this.hadInitialPlaceholder && t === "polite";
|
|
2368
|
-
if (
|
|
2369
|
-
const
|
|
2370
|
-
let
|
|
2427
|
+
if (u.utils && n) {
|
|
2428
|
+
const o = u.utils.numberType[e];
|
|
2429
|
+
let a = this.selectedCountryData.iso2 ? u.utils.getExampleNumber(
|
|
2371
2430
|
this.selectedCountryData.iso2,
|
|
2372
2431
|
i,
|
|
2373
|
-
|
|
2432
|
+
o
|
|
2374
2433
|
) : "";
|
|
2375
|
-
|
|
2434
|
+
a = this._beforeSetNumber(a), typeof s == "function" && (a = s(a, this.selectedCountryData)), this.telInput.setAttribute("placeholder", a);
|
|
2376
2435
|
}
|
|
2377
2436
|
}
|
|
2378
2437
|
//* Called when the user selects a list item from the dropdown.
|
|
2379
2438
|
_selectListItem(t) {
|
|
2380
|
-
const e = this._setCountry(
|
|
2381
|
-
|
|
2382
|
-
);
|
|
2383
|
-
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();
|
|
2384
2443
|
}
|
|
2385
2444
|
//* Close the dropdown and unbind any listeners.
|
|
2386
2445
|
_closeDropdown() {
|
|
@@ -2394,12 +2453,12 @@ class L {
|
|
|
2394
2453
|
}
|
|
2395
2454
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2396
2455
|
_scrollTo(t) {
|
|
2397
|
-
const e = this.countryList, i = document.documentElement.scrollTop, s = e.offsetHeight, n = e.getBoundingClientRect().top + i,
|
|
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;
|
|
2398
2457
|
if (d < n)
|
|
2399
|
-
e.scrollTop =
|
|
2400
|
-
else if (
|
|
2401
|
-
const
|
|
2402
|
-
e.scrollTop =
|
|
2458
|
+
e.scrollTop = h;
|
|
2459
|
+
else if (l > o) {
|
|
2460
|
+
const p = s - a;
|
|
2461
|
+
e.scrollTop = h - p;
|
|
2403
2462
|
}
|
|
2404
2463
|
}
|
|
2405
2464
|
//* Replace any existing dial code with the new one
|
|
@@ -2419,9 +2478,9 @@ class L {
|
|
|
2419
2478
|
if (t.charAt(0) === "+") {
|
|
2420
2479
|
let s = "";
|
|
2421
2480
|
for (let n = 0; n < t.length; n++) {
|
|
2422
|
-
const
|
|
2423
|
-
if (!isNaN(parseInt(
|
|
2424
|
-
if (s +=
|
|
2481
|
+
const o = t.charAt(n);
|
|
2482
|
+
if (!isNaN(parseInt(o, 10))) {
|
|
2483
|
+
if (s += o, e)
|
|
2425
2484
|
this.dialCodeToIso2Map[s] && (i = t.substring(0, n + 1));
|
|
2426
2485
|
else if (this.dialCodes.has(s)) {
|
|
2427
2486
|
i = t.substring(0, n + 1);
|
|
@@ -2438,48 +2497,40 @@ class L {
|
|
|
2438
2497
|
_getFullNumber(t) {
|
|
2439
2498
|
const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
|
|
2440
2499
|
let s;
|
|
2441
|
-
const n =
|
|
2500
|
+
const n = I(e);
|
|
2442
2501
|
return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
|
|
2443
2502
|
}
|
|
2444
2503
|
//* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
|
|
2445
2504
|
_beforeSetNumber(t) {
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
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);
|
|
2456
2512
|
}
|
|
2457
2513
|
//* Trigger the 'countrychange' event.
|
|
2458
2514
|
_triggerCountryChange() {
|
|
2459
2515
|
this._trigger("countrychange");
|
|
2460
2516
|
}
|
|
2461
|
-
//* Format the number as the user types.
|
|
2462
|
-
_formatNumberAsYouType() {
|
|
2463
|
-
const t = this._getFullNumber(), e = l.utils ? l.utils.formatNumberAsYouType(t, this.selectedCountryData.iso2) : t, { dialCode: i } = this.selectedCountryData;
|
|
2464
|
-
return this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && e.includes(`+${i}`) ? (e.split(`+${i}`)[1] || "").trim() : e;
|
|
2465
|
-
}
|
|
2466
2517
|
//**************************
|
|
2467
2518
|
//* SECRET PUBLIC METHODS
|
|
2468
2519
|
//**************************
|
|
2469
2520
|
//* This is called when the geoip call returns.
|
|
2470
2521
|
handleAutoCountry() {
|
|
2471
|
-
this.options.initialCountry === "auto" &&
|
|
2522
|
+
this.options.initialCountry === "auto" && u.autoCountry && (this.defaultCountry = u.autoCountry, this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe") || this.setCountry(this.defaultCountry), this.resolveAutoCountryPromise());
|
|
2472
2523
|
}
|
|
2473
2524
|
//* This is called when the utils request completes.
|
|
2474
2525
|
handleUtils() {
|
|
2475
|
-
|
|
2526
|
+
u.utils && (this.telInput.value && this._updateValFromNumber(this.telInput.value), this.selectedCountryData.iso2 && (this._updatePlaceholder(), this._updateMaxLength())), this.resolveUtilsScriptPromise();
|
|
2476
2527
|
}
|
|
2477
2528
|
//********************
|
|
2478
2529
|
//* PUBLIC METHODS
|
|
2479
2530
|
//********************
|
|
2480
2531
|
//* Remove plugin.
|
|
2481
2532
|
destroy() {
|
|
2482
|
-
var n,
|
|
2533
|
+
var n, o;
|
|
2483
2534
|
this.telInput.iti = void 0;
|
|
2484
2535
|
const { allowDropdown: t, separateDialCode: e } = this.options;
|
|
2485
2536
|
if (t) {
|
|
@@ -2490,26 +2541,26 @@ class L {
|
|
|
2490
2541
|
"keydown",
|
|
2491
2542
|
this._handleCountryContainerKeydown
|
|
2492
2543
|
);
|
|
2493
|
-
const
|
|
2494
|
-
|
|
2544
|
+
const a = this.telInput.closest("label");
|
|
2545
|
+
a && a.removeEventListener("click", this._handleLabelClick);
|
|
2495
2546
|
}
|
|
2496
2547
|
const { form: i } = this.telInput;
|
|
2497
|
-
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);
|
|
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);
|
|
2498
2549
|
const s = this.telInput.parentNode;
|
|
2499
|
-
(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];
|
|
2500
2551
|
}
|
|
2501
2552
|
//* Get the extension from the current number.
|
|
2502
2553
|
getExtension() {
|
|
2503
|
-
return
|
|
2554
|
+
return u.utils ? u.utils.getExtension(
|
|
2504
2555
|
this._getFullNumber(),
|
|
2505
2556
|
this.selectedCountryData.iso2
|
|
2506
2557
|
) : "";
|
|
2507
2558
|
}
|
|
2508
2559
|
//* Format the number to the given format.
|
|
2509
2560
|
getNumber(t) {
|
|
2510
|
-
if (
|
|
2561
|
+
if (u.utils) {
|
|
2511
2562
|
const { iso2: e } = this.selectedCountryData;
|
|
2512
|
-
return
|
|
2563
|
+
return u.utils.formatNumber(
|
|
2513
2564
|
this._getFullNumber(),
|
|
2514
2565
|
e,
|
|
2515
2566
|
t
|
|
@@ -2519,7 +2570,7 @@ class L {
|
|
|
2519
2570
|
}
|
|
2520
2571
|
//* Get the type of the entered number e.g. landline/mobile.
|
|
2521
2572
|
getNumberType() {
|
|
2522
|
-
return
|
|
2573
|
+
return u.utils ? u.utils.getNumberType(
|
|
2523
2574
|
this._getFullNumber(),
|
|
2524
2575
|
this.selectedCountryData.iso2
|
|
2525
2576
|
) : -99;
|
|
@@ -2530,9 +2581,9 @@ class L {
|
|
|
2530
2581
|
}
|
|
2531
2582
|
//* Get the validation error.
|
|
2532
2583
|
getValidationError() {
|
|
2533
|
-
if (
|
|
2584
|
+
if (u.utils) {
|
|
2534
2585
|
const { iso2: t } = this.selectedCountryData;
|
|
2535
|
-
return
|
|
2586
|
+
return u.utils.getValidationError(this._getFullNumber(), t);
|
|
2536
2587
|
}
|
|
2537
2588
|
return -99;
|
|
2538
2589
|
}
|
|
@@ -2545,25 +2596,28 @@ class L {
|
|
|
2545
2596
|
return this._validateNumber(!0);
|
|
2546
2597
|
}
|
|
2547
2598
|
_utilsIsPossibleNumber(t) {
|
|
2548
|
-
return
|
|
2599
|
+
return u.utils ? u.utils.isPossibleNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
|
|
2549
2600
|
}
|
|
2550
2601
|
//* Shared internal validation logic to handle alpha character extension rules.
|
|
2551
2602
|
_validateNumber(t) {
|
|
2552
2603
|
if (!this.selectedCountryData.iso2)
|
|
2553
2604
|
return !1;
|
|
2554
|
-
const e = (
|
|
2605
|
+
const e = (o) => t ? this._utilsIsValidNumber(o) : this._utilsIsPossibleNumber(o), i = this._getFullNumber(), s = i.search(new RegExp("\\p{L}", "u"));
|
|
2555
2606
|
if (s > -1 && !this.options.allowPhonewords) {
|
|
2556
|
-
const
|
|
2557
|
-
return
|
|
2607
|
+
const o = i.substring(0, s), a = e(o), d = e(i);
|
|
2608
|
+
return a && d;
|
|
2558
2609
|
}
|
|
2559
2610
|
return e(i);
|
|
2560
2611
|
}
|
|
2561
2612
|
_utilsIsValidNumber(t) {
|
|
2562
|
-
return
|
|
2613
|
+
return u.utils ? u.utils.isValidNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
|
|
2563
2614
|
}
|
|
2564
2615
|
//* Update the selected country, and update the input val accordingly.
|
|
2565
2616
|
setCountry(t) {
|
|
2566
|
-
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;
|
|
2567
2621
|
(t && e !== i || !t && i) && (this._setCountry(e), this._updateDialCode(this.selectedCountryData.dialCode), this.options.formatOnDisplay && this._updateValFromNumber(this.telInput.value), this._triggerCountryChange());
|
|
2568
2622
|
}
|
|
2569
2623
|
//* Set the input value and update the country.
|
|
@@ -2579,53 +2633,53 @@ class L {
|
|
|
2579
2633
|
this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled");
|
|
2580
2634
|
}
|
|
2581
2635
|
}
|
|
2582
|
-
const
|
|
2583
|
-
if (!
|
|
2636
|
+
const nt = (r) => {
|
|
2637
|
+
if (!u.utils && !u.startedLoadingUtilsScript) {
|
|
2584
2638
|
let t;
|
|
2585
|
-
if (typeof
|
|
2639
|
+
if (typeof r == "function")
|
|
2586
2640
|
try {
|
|
2587
|
-
t = Promise.resolve(
|
|
2641
|
+
t = Promise.resolve(r());
|
|
2588
2642
|
} catch (e) {
|
|
2589
2643
|
return Promise.reject(e);
|
|
2590
2644
|
}
|
|
2591
2645
|
else
|
|
2592
|
-
return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof
|
|
2593
|
-
return
|
|
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}`));
|
|
2647
|
+
return u.startedLoadingUtilsScript = !0, t.then((e) => {
|
|
2594
2648
|
const i = e == null ? void 0 : e.default;
|
|
2595
2649
|
if (!i || typeof i != "object")
|
|
2596
2650
|
throw new TypeError("The loader function passed to attachUtils did not resolve to a module object with utils as its default export.");
|
|
2597
|
-
return
|
|
2651
|
+
return u.utils = i, w("handleUtils"), !0;
|
|
2598
2652
|
}).catch((e) => {
|
|
2599
|
-
throw
|
|
2653
|
+
throw w("rejectUtilsScriptPromise", e), e;
|
|
2600
2654
|
});
|
|
2601
2655
|
}
|
|
2602
2656
|
return null;
|
|
2603
|
-
},
|
|
2604
|
-
(
|
|
2605
|
-
const e = new
|
|
2606
|
-
return e._init(),
|
|
2657
|
+
}, u = Object.assign(
|
|
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;
|
|
2607
2661
|
},
|
|
2608
2662
|
{
|
|
2609
|
-
defaults:
|
|
2663
|
+
defaults: P,
|
|
2610
2664
|
//* Using a static var like this allows us to mock it in the tests.
|
|
2611
2665
|
documentReady: () => document.readyState === "complete",
|
|
2612
2666
|
//* Get the country data object.
|
|
2613
|
-
getCountryData: () =>
|
|
2667
|
+
getCountryData: () => _,
|
|
2614
2668
|
//* A getter for the plugin instance.
|
|
2615
|
-
getInstance: (
|
|
2616
|
-
const t =
|
|
2617
|
-
return t ?
|
|
2669
|
+
getInstance: (r) => {
|
|
2670
|
+
const t = r.getAttribute("data-intl-tel-input-id");
|
|
2671
|
+
return t ? u.instances[t] : null;
|
|
2618
2672
|
},
|
|
2619
2673
|
//* A map from instance ID to instance object.
|
|
2620
2674
|
instances: {},
|
|
2621
|
-
attachUtils:
|
|
2675
|
+
attachUtils: nt,
|
|
2622
2676
|
startedLoadingUtilsScript: !1,
|
|
2623
2677
|
startedLoadingAutoCountry: !1,
|
|
2624
|
-
version: "25.10.
|
|
2678
|
+
version: "25.10.8"
|
|
2625
2679
|
}
|
|
2626
|
-
),
|
|
2680
|
+
), at = {
|
|
2627
2681
|
__name: "IntlTelInput",
|
|
2628
|
-
props: /* @__PURE__ */
|
|
2682
|
+
props: /* @__PURE__ */ S({
|
|
2629
2683
|
disabled: {
|
|
2630
2684
|
type: Boolean,
|
|
2631
2685
|
default: !1
|
|
@@ -2649,47 +2703,47 @@ const Y = (u) => {
|
|
|
2649
2703
|
},
|
|
2650
2704
|
modelModifiers: {}
|
|
2651
2705
|
}),
|
|
2652
|
-
emits: /* @__PURE__ */
|
|
2706
|
+
emits: /* @__PURE__ */ S([
|
|
2653
2707
|
"changeNumber",
|
|
2654
2708
|
"changeCountry",
|
|
2655
2709
|
"changeValidity",
|
|
2656
2710
|
"changeErrorCode"
|
|
2657
2711
|
], ["update:modelValue"]),
|
|
2658
|
-
setup(
|
|
2659
|
-
const i =
|
|
2660
|
-
let
|
|
2661
|
-
d.value !==
|
|
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(
|
|
2662
2716
|
"changeErrorCode",
|
|
2663
|
-
|
|
2717
|
+
c ? null : a.value.getValidationError()
|
|
2664
2718
|
));
|
|
2665
|
-
},
|
|
2666
|
-
var
|
|
2667
|
-
n("changeNumber", ((
|
|
2668
|
-
},
|
|
2669
|
-
var
|
|
2670
|
-
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();
|
|
2671
2725
|
};
|
|
2672
|
-
return
|
|
2673
|
-
|
|
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());
|
|
2674
2728
|
}), B(
|
|
2675
2729
|
() => s.disabled,
|
|
2676
|
-
(
|
|
2677
|
-
var
|
|
2678
|
-
return (
|
|
2730
|
+
(c) => {
|
|
2731
|
+
var C;
|
|
2732
|
+
return (C = a.value) == null ? void 0 : C.setDisabled(c);
|
|
2679
2733
|
}
|
|
2680
2734
|
), R(() => {
|
|
2681
|
-
var
|
|
2682
|
-
return (
|
|
2683
|
-
}), t({ instance:
|
|
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", $({
|
|
2684
2738
|
ref_key: "input",
|
|
2685
|
-
ref:
|
|
2686
|
-
"onUpdate:modelValue":
|
|
2739
|
+
ref: o,
|
|
2740
|
+
"onUpdate:modelValue": C[0] || (C[0] = (y) => i.value = y),
|
|
2687
2741
|
type: "tel",
|
|
2688
|
-
onCountrychange:
|
|
2689
|
-
onInput:
|
|
2690
|
-
},
|
|
2742
|
+
onCountrychange: f,
|
|
2743
|
+
onInput: p
|
|
2744
|
+
}, r.inputProps), null, 16)), [
|
|
2691
2745
|
[
|
|
2692
|
-
|
|
2746
|
+
O,
|
|
2693
2747
|
i.value,
|
|
2694
2748
|
void 0,
|
|
2695
2749
|
{ lazy: !0 }
|
|
@@ -2698,5 +2752,5 @@ const Y = (u) => {
|
|
|
2698
2752
|
}
|
|
2699
2753
|
};
|
|
2700
2754
|
export {
|
|
2701
|
-
|
|
2755
|
+
at as default
|
|
2702
2756
|
};
|