intl-tel-input 24.5.1 → 24.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { mergeModels as L, useModel as x, ref as v, onMounted as E, watch as M, onUnmounted as F, withDirectives as B, openBlock as O, createElementBlock as V, mergeProps as z, vModelText as R } from "vue";
2
- const D = [
1
+ import { mergeModels as D, useModel as x, ref as v, onMounted as E, watch as M, onUnmounted as O, withDirectives as F, openBlock as B, createElementBlock as V, mergeProps as z, vModelText as R } from "vue";
2
+ const N = [
3
3
  [
4
4
  "af",
5
5
  // Afghanistan
@@ -1306,8 +1306,8 @@ const D = [
1306
1306
  "263"
1307
1307
  ]
1308
1308
  ], b = [];
1309
- for (let u = 0; u < D.length; u++) {
1310
- const t = D[u];
1309
+ for (let u = 0; u < N.length; u++) {
1310
+ const t = N[u];
1311
1311
  b[u] = {
1312
1312
  name: "",
1313
1313
  // this is now populated in the plugin
@@ -1318,7 +1318,7 @@ for (let u = 0; u < D.length; u++) {
1318
1318
  nodeById: {}
1319
1319
  };
1320
1320
  }
1321
- const $ = {
1321
+ const j = {
1322
1322
  ad: "Andorra",
1323
1323
  ae: "United Arab Emirates",
1324
1324
  af: "Afghanistan",
@@ -1561,7 +1561,7 @@ const $ = {
1561
1561
  za: "South Africa",
1562
1562
  zm: "Zambia",
1563
1563
  zw: "Zimbabwe"
1564
- }, j = {
1564
+ }, $ = {
1565
1565
  selectedCountryAriaLabel: "Selected country",
1566
1566
  noCountrySelected: "No country selected",
1567
1567
  countryListAriaLabel: "List of countries",
@@ -1572,11 +1572,11 @@ const $ = {
1572
1572
  // additional countries (not supported by country-list library)
1573
1573
  ac: "Ascension Island",
1574
1574
  xk: "Kosovo"
1575
- }, S = { ...$, ...j };
1575
+ }, k = { ...j, ...$ };
1576
1576
  for (let u = 0; u < b.length; u++)
1577
- b[u].name = S[b[u].iso2];
1578
- let K = 0;
1579
- const k = {
1577
+ b[u].name = k[b[u].iso2];
1578
+ let U = 0;
1579
+ const T = {
1580
1580
  //* Whether or not to allow the dropdown.
1581
1581
  allowDropdown: !0,
1582
1582
  //* Add a placeholder in the input with an example number for the selected country.
@@ -1607,6 +1607,8 @@ const k = {
1607
1607
  i18n: {},
1608
1608
  //* Initial country.
1609
1609
  initialCountry: "",
1610
+ //* Specify the path to the libphonenumber script to enable validation/formatting.
1611
+ loadUtilsOnInit: "",
1610
1612
  //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers.
1611
1613
  nationalMode: !0,
1612
1614
  //* Display only these countries.
@@ -1627,11 +1629,11 @@ const k = {
1627
1629
  navigator.userAgent
1628
1630
  ) || window.innerWidth <= 500
1629
1631
  ) : !1,
1630
- //* Specify the path to the libphonenumber script to enable validation/formatting.
1632
+ //* Deprecated! Use `loadUtilsOnInit` instead.
1631
1633
  utilsScript: "",
1632
1634
  //* The number type to enforce during validation.
1633
1635
  validationNumberType: "MOBILE"
1634
- }, U = [
1636
+ }, K = [
1635
1637
  "800",
1636
1638
  "822",
1637
1639
  "833",
@@ -1649,11 +1651,11 @@ const k = {
1649
1651
  "887",
1650
1652
  "888",
1651
1653
  "889"
1652
- ], w = (u) => u.replace(/\D/g, ""), N = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), A = (u) => {
1653
- const t = w(u);
1654
+ ], I = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (u) => {
1655
+ const t = I(u);
1654
1656
  if (t.charAt(0) === "1") {
1655
1657
  const e = t.substr(1, 3);
1656
- return U.indexOf(e) !== -1;
1658
+ return K.indexOf(e) !== -1;
1657
1659
  }
1658
1660
  return !1;
1659
1661
  }, H = (u, t, e, i) => {
@@ -1670,19 +1672,19 @@ const k = {
1670
1672
  }, y = (u, t, e) => {
1671
1673
  const i = document.createElement(u);
1672
1674
  return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
1673
- }, _ = (u) => {
1674
- const { instances: t } = l;
1675
- Object.values(t).forEach((e) => e[u]());
1675
+ }, _ = (u, ...t) => {
1676
+ const { instances: e } = l;
1677
+ Object.values(e).forEach((i) => i[u](...t));
1676
1678
  };
1677
1679
  class G {
1678
1680
  constructor(t, e = {}) {
1679
- this.id = K++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, k, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder");
1681
+ this.id = U++, this.telInput = t, this.highlightedItem = null, this.options = Object.assign({}, T, e), this.hadInitialPlaceholder = !!t.getAttribute("placeholder");
1680
1682
  }
1681
1683
  //* Can't be private as it's called from intlTelInput convenience wrapper.
1682
1684
  _init() {
1683
1685
  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]");
1684
1686
  const t = this.options.allowDropdown || this.options.separateDialCode;
1685
- this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft), this.options.i18n = { ...S, ...this.options.i18n };
1687
+ this.showSelectedCountryOnLeft = this.isRTL ? !t : t, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft), this.options.i18n = { ...k, ...this.options.i18n };
1686
1688
  const e = new Promise((s, n) => {
1687
1689
  this.resolveAutoCountryPromise = s, this.rejectAutoCountryPromise = n;
1688
1690
  }), i = new Promise((s, n) => {
@@ -1896,7 +1898,7 @@ class G {
1896
1898
  //* 1. Extracting a dial code from the given number
1897
1899
  //* 2. Using explicit initialCountry
1898
1900
  _setInitialState(t = !1) {
1899
- 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: r, geoIpLookup: p } = this.options, c = r === "auto" && p;
1901
+ 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 = S(n), { initialCountry: r, geoIpLookup: p } = this.options, c = r === "auto" && p;
1900
1902
  if (o && !a)
1901
1903
  this._updateCountryFromNumber(n);
1902
1904
  else if (!c || t) {
@@ -1936,10 +1938,12 @@ class G {
1936
1938
  }
1937
1939
  //* Init many requests: utils script / geo ip lookup.
1938
1940
  _initRequests() {
1939
- const { utilsScript: t, initialCountry: e, geoIpLookup: i } = this.options;
1940
- t && !l.utils ? l.documentReady() ? l.loadUtils(t) : window.addEventListener("load", () => {
1941
- l.loadUtils(t);
1942
- }) : this.resolveUtilsScriptPromise(), e === "auto" && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
1941
+ let { loadUtilsOnInit: t, utilsScript: e, initialCountry: i, geoIpLookup: s } = this.options;
1942
+ !t && e && (console.warn("intl-tel-input: The `utilsScript` option is deprecated and will be removed in a future release! Please use the `loadUtilsOnInit` option instead."), t = e), t && !l.utils ? (this._handlePageLoad = () => {
1943
+ var o;
1944
+ window.removeEventListener("load", this._handlePageLoad), (o = l.loadUtils(t)) == null || o.catch(() => {
1945
+ });
1946
+ }, l.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), i === "auto" && s && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
1943
1947
  }
1944
1948
  //* Perform the geo ip lookup.
1945
1949
  _loadAutoCountry() {
@@ -1971,8 +1975,8 @@ class G {
1971
1975
  p || c && !t ? a = !0 : /[^+0-9]/.test(this.telInput.value) || (a = !1);
1972
1976
  const d = (r == null ? void 0 : r.detail) && r.detail.isSetNumber && !s;
1973
1977
  if (e && !a && !d) {
1974
- const C = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, C).replace(/[^+0-9]/g, "").length, f = (r == null ? void 0 : r.inputType) === "deleteContentForward", g = this._formatNumberAsYouType(), I = H(m, g, C, f);
1975
- this.telInput.value = g, this.telInput.setSelectionRange(I, I);
1978
+ const C = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, C).replace(/[^+0-9]/g, "").length, f = (r == null ? void 0 : r.inputType) === "deleteContentForward", g = this._formatNumberAsYouType(), w = H(m, g, C, f);
1979
+ this.telInput.value = g, this.telInput.setSelectionRange(w, w);
1976
1980
  }
1977
1981
  }, this.telInput.addEventListener("input", this._handleInputEvent), (t || i) && (this._handleKeydownEvent = (r) => {
1978
1982
  if (r.key && r.key.length === 1 && !r.altKey && !r.ctrlKey && !r.metaKey) {
@@ -1981,20 +1985,17 @@ class G {
1981
1985
  return;
1982
1986
  }
1983
1987
  if (t) {
1984
- const p = this.telInput.value, d = !(p.charAt(0) === "+") && this.telInput.selectionStart === 0 && r.key === "+", C = /^[0-9]$/.test(r.key), h = i ? C : d || C, m = this._getFullNumber(), f = l.utils.getCoreNumber(m, this.selectedCountryData.iso2), g = this.maxCoreNumberLength && f.length >= this.maxCoreNumberLength, I = p.substring(this.telInput.selectionStart, this.telInput.selectionEnd), T = /\d/.test(I), P = d ? !0 : this._isChangingDialCode(r.key);
1985
- (!h || g && !T && !P) && r.preventDefault();
1988
+ const p = this.telInput.value, c = p.charAt(0) === "+", d = !c && this.telInput.selectionStart === 0 && r.key === "+", C = /^[0-9]$/.test(r.key), h = i ? C : d || C, m = p.slice(0, this.telInput.selectionStart) + r.key + p.slice(this.telInput.selectionEnd), f = this._getFullNumber(m), g = l.utils.getCoreNumber(f, this.selectedCountryData.iso2), w = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength;
1989
+ let L = !1;
1990
+ if (c) {
1991
+ const P = this.selectedCountryData.iso2;
1992
+ L = this._getCountryFromNumber(f) !== P;
1993
+ }
1994
+ (!h || w && !L && !d) && r.preventDefault();
1986
1995
  }
1987
1996
  }
1988
1997
  }, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
1989
1998
  }
1990
- _isChangingDialCode(t) {
1991
- const e = this.telInput.value;
1992
- if (e.charAt(0) === "+") {
1993
- const i = this.selectedCountryData.iso2, s = e.slice(0, this.telInput.selectionStart) + t + e.slice(this.telInput.selectionEnd), n = this._getFullNumber(s);
1994
- return this._getCountryFromNumber(n) !== i;
1995
- }
1996
- return !1;
1997
- }
1998
1999
  //* Adhere to the input's maxlength attr.
1999
2000
  _cap(t) {
2000
2001
  const e = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
@@ -2079,9 +2080,9 @@ class G {
2079
2080
  _filterCountries(t, e = !1) {
2080
2081
  let i = !0;
2081
2082
  this.countryList.innerHTML = "";
2082
- const s = N(t);
2083
+ const s = A(t);
2083
2084
  for (let n = 0; n < this.countries.length; n++) {
2084
- const o = this.countries[n], a = N(o.name), r = o.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((c) => c[0]).join("").toLowerCase(), p = `+${o.dialCode}`;
2085
+ const o = this.countries[n], a = A(o.name), r = o.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((c) => c[0]).join("").toLowerCase(), p = `+${o.dialCode}`;
2085
2086
  if (e || a.includes(s) || p.includes(s) || o.iso2.includes(s) || r.includes(s)) {
2086
2087
  const c = o.nodeById[this.id];
2087
2088
  c && this.countryList.appendChild(c), i && (this._highlightListItem(c, !1), i = !1);
@@ -2130,10 +2131,10 @@ class G {
2130
2131
  let i = e ? t.substring(e) : t;
2131
2132
  const s = this.selectedCountryData.dialCode;
2132
2133
  i && s === "1" && i.charAt(0) !== "+" && (i.charAt(0) !== "1" && (i = `1${i}`), i = `+${i}`), this.options.separateDialCode && s && i.charAt(0) !== "+" && (i = `+${s}${i}`);
2133
- const o = this._getDialCode(i, !0), a = w(i);
2134
+ const o = this._getDialCode(i, !0), a = I(i);
2134
2135
  if (o) {
2135
- const r = this.dialCodeToIso2Map[w(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2136
- if (!(s === "1" && A(a)) && !p) {
2136
+ const r = this.dialCodeToIso2Map[I(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2137
+ if (!(s === "1" && S(a)) && !p) {
2137
2138
  for (let d = 0; d < r.length; d++)
2138
2139
  if (r[d])
2139
2140
  return r[d];
@@ -2189,20 +2190,20 @@ class G {
2189
2190
  }
2190
2191
  //* Update the maximum valid number length for the currently selected country.
2191
2192
  _updateMaxLength() {
2192
- const { strictMode: t, placeholderNumberType: e, validationNumberType: i } = this.options;
2193
+ const { strictMode: t, placeholderNumberType: e, validationNumberType: i } = this.options, { iso2: s } = this.selectedCountryData;
2193
2194
  if (t && l.utils)
2194
- if (this.selectedCountryData.iso2) {
2195
- const s = l.utils.numberType[e];
2196
- let n = l.utils.getExampleNumber(
2197
- this.selectedCountryData.iso2,
2198
- !1,
2195
+ if (s) {
2196
+ const n = l.utils.numberType[e];
2197
+ let o = l.utils.getExampleNumber(
2199
2198
  s,
2199
+ !1,
2200
+ n,
2200
2201
  !0
2201
- ), o = n;
2202
- for (; l.utils.isPossibleNumber(n, this.selectedCountryData.iso2, i); )
2203
- o = n, n += "0";
2204
- const a = l.utils.getCoreNumber(o, this.selectedCountryData.iso2);
2205
- this.maxCoreNumberLength = a.length;
2202
+ ), a = o;
2203
+ for (; l.utils.isPossibleNumber(o, s, i); )
2204
+ a = o, o += "0";
2205
+ const r = l.utils.getCoreNumber(a, s);
2206
+ this.maxCoreNumberLength = r.length, s === "by" && (this.maxCoreNumberLength = r.length + 1);
2206
2207
  } else
2207
2208
  this.maxCoreNumberLength = null;
2208
2209
  }
@@ -2262,7 +2263,7 @@ class G {
2262
2263
  ), this.countryList.removeEventListener(
2263
2264
  "mouseover",
2264
2265
  this._handleMouseoverCountryList
2265
- ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._trigger("close:countrydropdown");
2266
+ ), this.countryList.removeEventListener("click", this._handleClickCountryList), this.options.dropdownContainer && (this.options.useFullscreenPopup || window.removeEventListener("scroll", this._handleWindowScroll), this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown)), this._handlePageLoad && window.removeEventListener("load", this._handlePageLoad), this._trigger("close:countrydropdown");
2266
2267
  }
2267
2268
  //* Check if an element is visible within it's container, else scroll until it is.
2268
2269
  _scrollTo(t) {
@@ -2310,7 +2311,7 @@ class G {
2310
2311
  _getFullNumber(t) {
2311
2312
  const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
2312
2313
  let s;
2313
- const n = w(e);
2314
+ const n = I(e);
2314
2315
  return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
2315
2316
  }
2316
2317
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
@@ -2453,23 +2454,41 @@ class G {
2453
2454
  this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled");
2454
2455
  }
2455
2456
  }
2456
- const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUtilsScript = !0, new Promise((t, e) => {
2457
- import(
2458
- /* webpackIgnore: true */
2459
- /* @vite-ignore */
2460
- u
2461
- ).then(({ default: i }) => {
2462
- l.utils = i, _("handleUtils"), t(!0);
2463
- }).catch(() => {
2464
- _("rejectUtilsScriptPromise"), e();
2465
- });
2466
- })) : null, l = Object.assign(
2457
+ const W = (u) => {
2458
+ if (!l.utils && !l.startedLoadingUtilsScript) {
2459
+ let t;
2460
+ if (typeof u == "string")
2461
+ t = import(
2462
+ /* webpackIgnore: true */
2463
+ /* @vite-ignore */
2464
+ u
2465
+ );
2466
+ else if (typeof u == "function")
2467
+ try {
2468
+ if (t = u(), !(t instanceof Promise))
2469
+ throw new TypeError(`The function passed to loadUtils must return a promise for the utilities module, not ${typeof t}`);
2470
+ } catch (e) {
2471
+ return Promise.reject(e);
2472
+ }
2473
+ else
2474
+ return Promise.reject(new TypeError(`The argument passed to loadUtils must be a URL string or a function that returns a promise for the utilities module, not ${typeof u}`));
2475
+ return l.startedLoadingUtilsScript = !0, t.then((e) => {
2476
+ const i = e == null ? void 0 : e.default;
2477
+ if (!i || typeof i != "object")
2478
+ throw typeof u == "string" ? new TypeError(`The module loaded from ${u} did not set utils as its default export.`) : new TypeError("The loader function passed to loadUtils did not resolve to a module object with utils as its default export.");
2479
+ return l.utils = i, _("handleUtils"), !0;
2480
+ }).catch((e) => {
2481
+ throw _("rejectUtilsScriptPromise", e), e;
2482
+ });
2483
+ }
2484
+ return null;
2485
+ }, l = Object.assign(
2467
2486
  (u, t) => {
2468
2487
  const e = new G(u, t);
2469
2488
  return e._init(), u.setAttribute("data-intl-tel-input-id", e.id.toString()), l.instances[e.id] = e, e;
2470
2489
  },
2471
2490
  {
2472
- defaults: k,
2491
+ defaults: T,
2473
2492
  //* Using a static var like this allows us to mock it in the tests.
2474
2493
  documentReady: () => document.readyState === "complete",
2475
2494
  //* Get the country data object.
@@ -2482,11 +2501,13 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2482
2501
  //* A map from instance ID to instance object.
2483
2502
  instances: {},
2484
2503
  loadUtils: W,
2485
- version: "24.5.1"
2504
+ startedLoadingUtilsScript: !1,
2505
+ startedLoadingAutoCountry: !1,
2506
+ version: "24.6.0"
2486
2507
  }
2487
- ), Y = {
2508
+ ), J = {
2488
2509
  __name: "IntlTelInput",
2489
- props: /* @__PURE__ */ L({
2510
+ props: /* @__PURE__ */ D({
2490
2511
  disabled: {
2491
2512
  type: Boolean,
2492
2513
  default: !1
@@ -2510,7 +2531,7 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2510
2531
  },
2511
2532
  modelModifiers: {}
2512
2533
  }),
2513
- emits: /* @__PURE__ */ L([
2534
+ emits: /* @__PURE__ */ D([
2514
2535
  "changeNumber",
2515
2536
  "changeCountry",
2516
2537
  "changeValidity",
@@ -2538,10 +2559,10 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2538
2559
  var m;
2539
2560
  return (m = a.value) == null ? void 0 : m.setDisabled(h);
2540
2561
  }
2541
- ), F(() => {
2562
+ ), O(() => {
2542
2563
  var h;
2543
2564
  return (h = a.value) == null ? void 0 : h.destroy();
2544
- }), t({ instance: a, input: o }), (h, m) => B((O(), V("input", z({
2565
+ }), t({ instance: a, input: o }), (h, m) => F((B(), V("input", z({
2545
2566
  ref_key: "input",
2546
2567
  ref: o,
2547
2568
  "onUpdate:modelValue": m[0] || (m[0] = (f) => i.value = f),
@@ -2554,5 +2575,5 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2554
2575
  }
2555
2576
  };
2556
2577
  export {
2557
- Y as default
2578
+ J as default
2558
2579
  };