intl-tel-input 24.8.2 → 25.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/vue/README.md CHANGED
@@ -34,7 +34,7 @@ See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master
34
34
  "vue:demo": "vite --config vue/demo/[demo variant]/vite.config.js"
35
35
  ```
36
36
 
37
- A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/vueWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/vue"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.8.2/build/js/utils.js"`.
37
+ A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/vueWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/vue"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.0.1/build/js/utils.js"`.
38
38
 
39
39
  ## Props
40
40
  Here's a list of all of the current props you can pass to the IntlTelInput Vue component.
@@ -1,4 +1,4 @@
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";
1
+ import { mergeModels as D, useModel as x, ref as L, 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
2
  const N = [
3
3
  [
4
4
  "af",
@@ -1305,10 +1305,10 @@ const N = [
1305
1305
  // Zimbabwe
1306
1306
  "263"
1307
1307
  ]
1308
- ], b = [];
1308
+ ], I = [];
1309
1309
  for (let u = 0; u < N.length; u++) {
1310
1310
  const t = N[u];
1311
- b[u] = {
1311
+ I[u] = {
1312
1312
  name: "",
1313
1313
  // this is now populated in the plugin
1314
1314
  iso2: t[0],
@@ -1573,8 +1573,8 @@ const j = {
1573
1573
  ac: "Ascension Island",
1574
1574
  xk: "Kosovo"
1575
1575
  }, k = { ...j, ...$ };
1576
- for (let u = 0; u < b.length; u++)
1577
- b[u].name = k[b[u].iso2];
1576
+ for (let u = 0; u < I.length; u++)
1577
+ I[u].name = k[I[u].iso2];
1578
1578
  let U = 0;
1579
1579
  const T = {
1580
1580
  //* Whether or not to allow the dropdown.
@@ -1607,8 +1607,8 @@ const T = {
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
+ //* A function to load the utils script.
1611
+ loadUtils: null,
1612
1612
  //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers.
1613
1613
  nationalMode: !0,
1614
1614
  //* Display only these countries.
@@ -1629,10 +1629,8 @@ const T = {
1629
1629
  navigator.userAgent
1630
1630
  ) || window.innerWidth <= 500
1631
1631
  ) : !1,
1632
- //* Deprecated! Use `loadUtilsOnInit` instead.
1633
- utilsScript: "",
1634
1632
  //* The number type to enforce during validation.
1635
- validationNumberType: "MOBILE"
1633
+ validationNumberTypes: ["MOBILE"]
1636
1634
  }, K = [
1637
1635
  "800",
1638
1636
  "822",
@@ -1651,8 +1649,8 @@ const T = {
1651
1649
  "887",
1652
1650
  "888",
1653
1651
  "889"
1654
- ], I = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (u) => {
1655
- const t = I(u);
1652
+ ], v = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (u) => {
1653
+ const t = v(u);
1656
1654
  if (t.charAt(0) === "1") {
1657
1655
  const e = t.substr(1, 3);
1658
1656
  return K.indexOf(e) !== -1;
@@ -1672,7 +1670,7 @@ const T = {
1672
1670
  }, y = (u, t, e) => {
1673
1671
  const i = document.createElement(u);
1674
1672
  return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
1675
- }, _ = (u, ...t) => {
1673
+ }, w = (u, ...t) => {
1676
1674
  const { instances: e } = l;
1677
1675
  Object.values(e).forEach((i) => i[u](...t));
1678
1676
  };
@@ -1727,18 +1725,18 @@ class G {
1727
1725
  const i = t.map(
1728
1726
  (s) => s.toLowerCase()
1729
1727
  );
1730
- this.countries = b.filter(
1728
+ this.countries = I.filter(
1731
1729
  (s) => i.indexOf(s.iso2) > -1
1732
1730
  );
1733
1731
  } else if (e.length) {
1734
1732
  const i = e.map(
1735
1733
  (s) => s.toLowerCase()
1736
1734
  );
1737
- this.countries = b.filter(
1735
+ this.countries = I.filter(
1738
1736
  (s) => i.indexOf(s.iso2) === -1
1739
1737
  );
1740
1738
  } else
1741
- this.countries = b;
1739
+ this.countries = I;
1742
1740
  }
1743
1741
  //* Translate Countries by object literal provided on config.
1744
1742
  _translateCountryNames() {
@@ -1771,7 +1769,7 @@ class G {
1771
1769
  }
1772
1770
  //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
1773
1771
  _generateMarkup() {
1774
- var h;
1772
+ var h, m, b;
1775
1773
  this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off");
1776
1774
  const {
1777
1775
  allowDropdown: t,
@@ -1810,15 +1808,15 @@ class G {
1810
1808
  { class: "iti__selected-country" },
1811
1809
  this.countryContainer
1812
1810
  );
1813
- const m = y("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
1814
- if (this.selectedCountryInner = y("div", { class: "iti__flag" }, m), this.selectedCountryA11yText = y(
1811
+ const _ = y("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
1812
+ if (this.selectedCountryInner = y("div", { class: "iti__flag" }, _), this.selectedCountryA11yText = y(
1815
1813
  "span",
1816
1814
  { class: "iti__a11y-text" },
1817
1815
  this.selectedCountryInner
1818
1816
  ), t && (this.dropdownArrow = y(
1819
1817
  "div",
1820
1818
  { class: "iti__arrow", "aria-hidden": "true" },
1821
- m
1819
+ _
1822
1820
  )), e && (this.selectedDialCode = y(
1823
1821
  "div",
1824
1822
  { class: "iti__selected-dial-code" },
@@ -1863,14 +1861,21 @@ class G {
1863
1861
  }
1864
1862
  }
1865
1863
  if (C.appendChild(this.telInput), this._updateInputPadding(), n) {
1866
- const m = this.telInput.getAttribute("name") || "", f = n(m);
1867
- f.phone && (this.hiddenInput = y("input", {
1868
- type: "hidden",
1869
- name: f.phone
1870
- }), C.appendChild(this.hiddenInput)), f.country && (this.hiddenInputCountry = y("input", {
1871
- type: "hidden",
1872
- name: f.country
1873
- }), C.appendChild(this.hiddenInputCountry));
1864
+ const _ = this.telInput.getAttribute("name") || "", f = n(_);
1865
+ if (f.phone) {
1866
+ const g = (m = this.telInput.form) == null ? void 0 : m.querySelector(`input[name="${f.phone}"]`);
1867
+ g ? this.hiddenInput = g : (this.hiddenInput = y("input", {
1868
+ type: "hidden",
1869
+ name: f.phone
1870
+ }), C.appendChild(this.hiddenInput));
1871
+ }
1872
+ if (f.country) {
1873
+ const g = (b = this.telInput.form) == null ? void 0 : b.querySelector(`input[name="${f.country}"]`);
1874
+ g ? this.hiddenInputCountry = g : (this.hiddenInputCountry = y("input", {
1875
+ type: "hidden",
1876
+ name: f.country
1877
+ }), C.appendChild(this.hiddenInputCountry));
1878
+ }
1874
1879
  }
1875
1880
  }
1876
1881
  //* For each country: add a country list item <li> to the countryList <ul> container.
@@ -1938,22 +1943,22 @@ class G {
1938
1943
  }
1939
1944
  //* Init many requests: utils script / geo ip lookup.
1940
1945
  _initRequests() {
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(() => {
1946
+ let { loadUtils: t, initialCountry: e, geoIpLookup: i } = this.options;
1947
+ t && !l.utils ? (this._handlePageLoad = () => {
1948
+ var n;
1949
+ window.removeEventListener("load", this._handlePageLoad), (n = l.attachUtils(t)) == null || n.catch(() => {
1945
1950
  });
1946
- }, l.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), i === "auto" && s && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
1951
+ }, l.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), e === "auto" && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
1947
1952
  }
1948
1953
  //* Perform the geo ip lookup.
1949
1954
  _loadAutoCountry() {
1950
1955
  l.autoCountry ? this.handleAutoCountry() : l.startedLoadingAutoCountry || (l.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(
1951
1956
  (t = "") => {
1952
1957
  const e = t.toLowerCase();
1953
- e && this._getCountryData(e, !0) ? (l.autoCountry = e, setTimeout(() => _("handleAutoCountry"))) : (this._setInitialState(!0), _("rejectAutoCountryPromise"));
1958
+ e && this._getCountryData(e, !0) ? (l.autoCountry = e, setTimeout(() => w("handleAutoCountry"))) : (this._setInitialState(!0), w("rejectAutoCountryPromise"));
1954
1959
  },
1955
1960
  () => {
1956
- this._setInitialState(!0), _("rejectAutoCountryPromise");
1961
+ this._setInitialState(!0), w("rejectAutoCountryPromise");
1957
1962
  }
1958
1963
  ));
1959
1964
  }
@@ -1975,8 +1980,8 @@ class G {
1975
1980
  p || c && !t ? a = !0 : /[^+0-9]/.test(this.telInput.value) || (a = !1);
1976
1981
  const d = (r == null ? void 0 : r.detail) && r.detail.isSetNumber && !s;
1977
1982
  if (e && !a && !d) {
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);
1983
+ const C = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, C).replace(/[^+0-9]/g, "").length, b = (r == null ? void 0 : r.inputType) === "deleteContentForward", _ = this._formatNumberAsYouType(), f = H(m, _, C, b);
1984
+ this.telInput.value = _, this.telInput.setSelectionRange(f, f);
1980
1985
  }
1981
1986
  }, this.telInput.addEventListener("input", this._handleInputEvent), (t || i) && (this._handleKeydownEvent = (r) => {
1982
1987
  if (r.key && r.key.length === 1 && !r.altKey && !r.ctrlKey && !r.metaKey) {
@@ -1985,13 +1990,13 @@ class G {
1985
1990
  return;
1986
1991
  }
1987
1992
  if (t) {
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;
1993
+ 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), b = this._getFullNumber(m), _ = l.utils.getCoreNumber(b, this.selectedCountryData.iso2), f = this.maxCoreNumberLength && _.length > this.maxCoreNumberLength;
1994
+ let g = !1;
1990
1995
  if (c) {
1991
1996
  const P = this.selectedCountryData.iso2;
1992
- L = this._getCountryFromNumber(f) !== P;
1997
+ g = this._getCountryFromNumber(b) !== P;
1993
1998
  }
1994
- (!h || w && !L && !d) && r.preventDefault();
1999
+ (!h || f && !g && !d) && r.preventDefault();
1995
2000
  }
1996
2001
  }
1997
2002
  }, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
@@ -2131,9 +2136,9 @@ class G {
2131
2136
  let i = e ? t.substring(e) : t;
2132
2137
  const s = this.selectedCountryData.dialCode;
2133
2138
  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}`);
2134
- const o = this._getDialCode(i, !0), a = I(i);
2139
+ const o = this._getDialCode(i, !0), a = v(i);
2135
2140
  if (o) {
2136
- const r = this.dialCodeToIso2Map[I(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2141
+ const r = this.dialCodeToIso2Map[v(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2137
2142
  if (!(s === "1" && S(a)) && !p) {
2138
2143
  for (let d = 0; d < r.length; d++)
2139
2144
  if (r[d])
@@ -2190,7 +2195,7 @@ class G {
2190
2195
  }
2191
2196
  //* Update the maximum valid number length for the currently selected country.
2192
2197
  _updateMaxLength() {
2193
- const { strictMode: t, placeholderNumberType: e, validationNumberType: i } = this.options, { iso2: s } = this.selectedCountryData;
2198
+ const { strictMode: t, placeholderNumberType: e, validationNumberTypes: i } = this.options, { iso2: s } = this.selectedCountryData;
2194
2199
  if (t && l.utils)
2195
2200
  if (s) {
2196
2201
  const n = l.utils.numberType[e];
@@ -2311,7 +2316,7 @@ class G {
2311
2316
  _getFullNumber(t) {
2312
2317
  const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
2313
2318
  let s;
2314
- const n = I(e);
2319
+ const n = v(e);
2315
2320
  return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
2316
2321
  }
2317
2322
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
@@ -2420,7 +2425,7 @@ class G {
2420
2425
  return this._utilsIsPossibleNumber(t);
2421
2426
  }
2422
2427
  _utilsIsPossibleNumber(t) {
2423
- return l.utils ? l.utils.isPossibleNumber(t, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
2428
+ return l.utils ? l.utils.isPossibleNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
2424
2429
  }
2425
2430
  //* Validate the input val (precise)
2426
2431
  isValidNumberPrecise() {
@@ -2434,7 +2439,7 @@ class G {
2434
2439
  return this._utilsIsValidNumber(t);
2435
2440
  }
2436
2441
  _utilsIsValidNumber(t) {
2437
- return l.utils ? l.utils.isValidNumber(t, this.selectedCountryData.iso2) : null;
2442
+ return l.utils ? l.utils.isValidNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
2438
2443
  }
2439
2444
  //* Update the selected country, and update the input val accordingly.
2440
2445
  setCountry(t) {
@@ -2457,27 +2462,21 @@ class G {
2457
2462
  const W = (u) => {
2458
2463
  if (!l.utils && !l.startedLoadingUtilsScript) {
2459
2464
  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")
2465
+ if (typeof u == "function")
2467
2466
  try {
2468
2467
  t = Promise.resolve(u());
2469
2468
  } catch (e) {
2470
2469
  return Promise.reject(e);
2471
2470
  }
2472
2471
  else
2473
- 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}`));
2472
+ return Promise.reject(new TypeError(`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof u}`));
2474
2473
  return l.startedLoadingUtilsScript = !0, t.then((e) => {
2475
2474
  const i = e == null ? void 0 : e.default;
2476
2475
  if (!i || typeof i != "object")
2477
- 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.");
2478
- return l.utils = i, _("handleUtils"), !0;
2476
+ throw new TypeError("The loader function passed to attachUtils did not resolve to a module object with utils as its default export.");
2477
+ return l.utils = i, w("handleUtils"), !0;
2479
2478
  }).catch((e) => {
2480
- throw _("rejectUtilsScriptPromise", e), e;
2479
+ throw w("rejectUtilsScriptPromise", e), e;
2481
2480
  });
2482
2481
  }
2483
2482
  return null;
@@ -2491,7 +2490,7 @@ const W = (u) => {
2491
2490
  //* Using a static var like this allows us to mock it in the tests.
2492
2491
  documentReady: () => document.readyState === "complete",
2493
2492
  //* Get the country data object.
2494
- getCountryData: () => b,
2493
+ getCountryData: () => I,
2495
2494
  //* A getter for the plugin instance.
2496
2495
  getInstance: (u) => {
2497
2496
  const t = u.getAttribute("data-intl-tel-input-id");
@@ -2499,10 +2498,10 @@ const W = (u) => {
2499
2498
  },
2500
2499
  //* A map from instance ID to instance object.
2501
2500
  instances: {},
2502
- loadUtils: W,
2501
+ attachUtils: W,
2503
2502
  startedLoadingUtilsScript: !1,
2504
2503
  startedLoadingAutoCountry: !1,
2505
- version: "24.8.2"
2504
+ version: "25.0.1"
2506
2505
  }
2507
2506
  ), J = {
2508
2507
  __name: "IntlTelInput",
@@ -2537,7 +2536,7 @@ const W = (u) => {
2537
2536
  "changeErrorCode"
2538
2537
  ], ["update:modelValue"]),
2539
2538
  setup(u, { expose: t, emit: e }) {
2540
- const i = x(u, "modelValue"), s = u, n = e, o = v(), a = v(), r = v(!1), p = () => a.value ? s.options.strictMode ? a.value.isValidNumberPrecise() : a.value.isValidNumber() : null, c = () => {
2539
+ const i = x(u, "modelValue"), s = u, n = e, o = L(), a = L(), r = L(!1), p = () => a.value ? s.options.strictMode ? a.value.isValidNumberPrecise() : a.value.isValidNumber() : null, c = () => {
2541
2540
  let h = p();
2542
2541
  r.value !== h && (r.value = h, n("changeValidity", !!h), n(
2543
2542
  "changeErrorCode",
@@ -2558,13 +2557,13 @@ const W = (u) => {
2558
2557
  var m;
2559
2558
  return (m = a.value) == null ? void 0 : m.setDisabled(h);
2560
2559
  }
2561
- ), O(() => {
2560
+ ), F(() => {
2562
2561
  var h;
2563
2562
  return (h = a.value) == null ? void 0 : h.destroy();
2564
- }), t({ instance: a, input: o }), (h, m) => F((B(), V("input", z({
2563
+ }), t({ instance: a, input: o }), (h, m) => B((O(), V("input", z({
2565
2564
  ref_key: "input",
2566
2565
  ref: o,
2567
- "onUpdate:modelValue": m[0] || (m[0] = (f) => i.value = f),
2566
+ "onUpdate:modelValue": m[0] || (m[0] = (b) => i.value = b),
2568
2567
  type: "tel",
2569
2568
  onCountrychange: C,
2570
2569
  onInput: d