intl-tel-input 24.5.2 → 24.6.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.5.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 `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.6.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 F, withDirectives as B, openBlock as O, createElementBlock as V, mergeProps as z, vModelText as R } from "vue";
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
2
  const N = [
3
3
  [
4
4
  "af",
@@ -1318,7 +1318,7 @@ for (let u = 0; u < N.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,10 +1572,10 @@ const $ = {
1572
1572
  // additional countries (not supported by country-list library)
1573
1573
  ac: "Ascension Island",
1574
1574
  xk: "Kosovo"
1575
- }, k = { ...$, ...j };
1575
+ }, k = { ...j, ...$ };
1576
1576
  for (let u = 0; u < b.length; u++)
1577
1577
  b[u].name = k[b[u].iso2];
1578
- let K = 0;
1578
+ let U = 0;
1579
1579
  const T = {
1580
1580
  //* Whether or not to allow the dropdown.
1581
1581
  allowDropdown: !0,
@@ -1607,6 +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
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 T = {
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 T = {
1649
1651
  "887",
1650
1652
  "888",
1651
1653
  "889"
1652
- ], w = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), S = (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,13 +1672,13 @@ const T = {
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({}, T, 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() {
@@ -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,13 +1985,13 @@ class G {
1981
1985
  return;
1982
1986
  }
1983
1987
  if (t) {
1984
- 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), I = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength;
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;
1985
1989
  let L = !1;
1986
1990
  if (c) {
1987
1991
  const P = this.selectedCountryData.iso2;
1988
1992
  L = this._getCountryFromNumber(f) !== P;
1989
1993
  }
1990
- (!h || I && !L && !d) && r.preventDefault();
1994
+ (!h || w && !L && !d) && r.preventDefault();
1991
1995
  }
1992
1996
  }
1993
1997
  }, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
@@ -2127,9 +2131,9 @@ class G {
2127
2131
  let i = e ? t.substring(e) : t;
2128
2132
  const s = this.selectedCountryData.dialCode;
2129
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}`);
2130
- const o = this._getDialCode(i, !0), a = w(i);
2134
+ const o = this._getDialCode(i, !0), a = I(i);
2131
2135
  if (o) {
2132
- const r = this.dialCodeToIso2Map[w(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2136
+ const r = this.dialCodeToIso2Map[I(o)], p = r.indexOf(this.selectedCountryData.iso2) !== -1 && a.length <= o.length - 1;
2133
2137
  if (!(s === "1" && S(a)) && !p) {
2134
2138
  for (let d = 0; d < r.length; d++)
2135
2139
  if (r[d])
@@ -2259,7 +2263,7 @@ class G {
2259
2263
  ), this.countryList.removeEventListener(
2260
2264
  "mouseover",
2261
2265
  this._handleMouseoverCountryList
2262
- ), 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");
2263
2267
  }
2264
2268
  //* Check if an element is visible within it's container, else scroll until it is.
2265
2269
  _scrollTo(t) {
@@ -2307,7 +2311,7 @@ class G {
2307
2311
  _getFullNumber(t) {
2308
2312
  const e = t || this.telInput.value.trim(), { dialCode: i } = this.selectedCountryData;
2309
2313
  let s;
2310
- const n = w(e);
2314
+ const n = I(e);
2311
2315
  return this.options.separateDialCode && e.charAt(0) !== "+" && i && n ? s = `+${i}` : s = "", s + e;
2312
2316
  }
2313
2317
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
@@ -2450,17 +2454,35 @@ class G {
2450
2454
  this.telInput.disabled = t, t ? this.selectedCountry.setAttribute("disabled", "true") : this.selectedCountry.removeAttribute("disabled");
2451
2455
  }
2452
2456
  }
2453
- const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUtilsScript = !0, new Promise((t, e) => {
2454
- import(
2455
- /* webpackIgnore: true */
2456
- /* @vite-ignore */
2457
- u
2458
- ).then(({ default: i }) => {
2459
- l.utils = i, _("handleUtils"), t(!0);
2460
- }).catch(() => {
2461
- _("rejectUtilsScriptPromise"), e();
2462
- });
2463
- })) : 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(
2464
2486
  (u, t) => {
2465
2487
  const e = new G(u, t);
2466
2488
  return e._init(), u.setAttribute("data-intl-tel-input-id", e.id.toString()), l.instances[e.id] = e, e;
@@ -2479,7 +2501,9 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2479
2501
  //* A map from instance ID to instance object.
2480
2502
  instances: {},
2481
2503
  loadUtils: W,
2482
- version: "24.5.2"
2504
+ startedLoadingUtilsScript: !1,
2505
+ startedLoadingAutoCountry: !1,
2506
+ version: "24.6.1"
2483
2507
  }
2484
2508
  ), J = {
2485
2509
  __name: "IntlTelInput",
@@ -2535,10 +2559,10 @@ const W = (u) => !l.utils && !l.startedLoadingUtilsScript ? (l.startedLoadingUti
2535
2559
  var m;
2536
2560
  return (m = a.value) == null ? void 0 : m.setDisabled(h);
2537
2561
  }
2538
- ), F(() => {
2562
+ ), O(() => {
2539
2563
  var h;
2540
2564
  return (h = a.value) == null ? void 0 : h.destroy();
2541
- }), 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({
2542
2566
  ref_key: "input",
2543
2567
  ref: o,
2544
2568
  "onUpdate:modelValue": m[0] || (m[0] = (f) => i.value = f),