intl-tel-input 25.10.5 → 25.10.6

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.
@@ -1226,6 +1226,13 @@ var rawCountryData = [
1226
1226
  // Tuvalu
1227
1227
  "688"
1228
1228
  ],
1229
+ [
1230
+ "vi",
1231
+ // U.S. Virgin Islands
1232
+ "1",
1233
+ 24,
1234
+ ["340"]
1235
+ ],
1229
1236
  [
1230
1237
  "ug",
1231
1238
  // Uganda
@@ -1260,13 +1267,6 @@ var rawCountryData = [
1260
1267
  // Uruguay
1261
1268
  "598"
1262
1269
  ],
1263
- [
1264
- "vi",
1265
- // U.S. Virgin Islands
1266
- "1",
1267
- 24,
1268
- ["340"]
1269
- ],
1270
1270
  [
1271
1271
  "uz",
1272
1272
  // Uzbekistan
@@ -1842,6 +1842,9 @@ var Iti = class _Iti {
1842
1842
  }
1843
1843
  //* Add a dial code to this.dialCodeToIso2Map.
1844
1844
  _addToDialCodeMap(iso2, dialCode, priority) {
1845
+ if (!iso2 || !dialCode) {
1846
+ return;
1847
+ }
1845
1848
  if (dialCode.length > this.dialCodeMaxLen) {
1846
1849
  this.dialCodeMaxLen = dialCode.length;
1847
1850
  }
@@ -1896,6 +1899,11 @@ var Iti = class _Iti {
1896
1899
  }
1897
1900
  this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1898
1901
  }
1902
+ if (this.options.onlyCountries.length || this.options.excludeCountries.length) {
1903
+ this.dialCodes.forEach((dialCode) => {
1904
+ this.dialCodeToIso2Map[dialCode] = this.dialCodeToIso2Map[dialCode].filter(Boolean);
1905
+ });
1906
+ }
1899
1907
  for (const c of this.countries) {
1900
1908
  if (c.areaCodes) {
1901
1909
  const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
@@ -2314,7 +2322,7 @@ var Iti = class _Iti {
2314
2322
  _openDropdownWithPlus() {
2315
2323
  this._openDropdown();
2316
2324
  this.searchInput.value = "+";
2317
- this._filterCountries("", true);
2325
+ this._filterCountries("");
2318
2326
  }
2319
2327
  //* Initialize the tel input listeners.
2320
2328
  _initTelInputListeners() {
@@ -2497,11 +2505,7 @@ var Iti = class _Iti {
2497
2505
  if (this.options.countrySearch) {
2498
2506
  const doFilter = () => {
2499
2507
  const inputQuery = this.searchInput.value.trim();
2500
- if (inputQuery) {
2501
- this._filterCountries(inputQuery);
2502
- } else {
2503
- this._filterCountries("", true);
2504
- }
2508
+ this._filterCountries(inputQuery);
2505
2509
  if (this.searchInput.value) {
2506
2510
  this.searchClearButton.classList.remove("iti__hide");
2507
2511
  } else {
@@ -2540,42 +2544,44 @@ var Iti = class _Iti {
2540
2544
  }
2541
2545
  }
2542
2546
  //* Country search enabled: Filter the countries according to the search query.
2543
- _filterCountries(query, isReset = false) {
2547
+ _filterCountries(query) {
2544
2548
  let noCountriesAddedYet = true;
2545
2549
  this.countryList.innerHTML = "";
2546
2550
  const normalisedQuery = normaliseString(query);
2547
- const queryLength = normalisedQuery.length;
2548
- const iso2Matches = [];
2549
- const nameStartWith = [];
2550
- const nameContains = [];
2551
- const dialCodeMatches = [];
2552
- const dialCodeContains = [];
2553
- const initialsMatches = [];
2554
- for (const c of this.countries) {
2555
- if (isReset || queryLength === 0) {
2556
- nameContains.push(c);
2557
- } else if (c.iso2 === normalisedQuery) {
2558
- iso2Matches.push(c);
2559
- } else if (c.normalisedName.startsWith(normalisedQuery)) {
2560
- nameStartWith.push(c);
2561
- } else if (c.normalisedName.includes(normalisedQuery)) {
2562
- nameContains.push(c);
2563
- } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2564
- dialCodeMatches.push(c);
2565
- } else if (c.dialCodePlus.includes(normalisedQuery)) {
2566
- dialCodeContains.push(c);
2567
- } else if (c.initials.includes(normalisedQuery)) {
2568
- initialsMatches.push(c);
2551
+ let matchedCountries;
2552
+ if (query === "") {
2553
+ matchedCountries = this.countries;
2554
+ } else {
2555
+ const iso2Matches = [];
2556
+ const nameStartWith = [];
2557
+ const nameContains = [];
2558
+ const dialCodeMatches = [];
2559
+ const dialCodeContains = [];
2560
+ const initialsMatches = [];
2561
+ for (const c of this.countries) {
2562
+ if (c.iso2 === normalisedQuery) {
2563
+ iso2Matches.push(c);
2564
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2565
+ nameStartWith.push(c);
2566
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2567
+ nameContains.push(c);
2568
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2569
+ dialCodeMatches.push(c);
2570
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2571
+ dialCodeContains.push(c);
2572
+ } else if (c.initials.includes(normalisedQuery)) {
2573
+ initialsMatches.push(c);
2574
+ }
2569
2575
  }
2576
+ matchedCountries = [
2577
+ ...iso2Matches.sort((a, b) => a.priority - b.priority),
2578
+ ...nameStartWith.sort((a, b) => a.priority - b.priority),
2579
+ ...nameContains.sort((a, b) => a.priority - b.priority),
2580
+ ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2581
+ ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2582
+ ...initialsMatches.sort((a, b) => a.priority - b.priority)
2583
+ ];
2570
2584
  }
2571
- const matchedCountries = [
2572
- ...iso2Matches.sort((a, b) => a.priority - b.priority),
2573
- ...nameStartWith.sort((a, b) => a.priority - b.priority),
2574
- ...nameContains.sort((a, b) => a.priority - b.priority),
2575
- ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2576
- ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2577
- ...initialsMatches.sort((a, b) => a.priority - b.priority)
2578
- ];
2579
2585
  for (const c of matchedCountries) {
2580
2586
  const listItem = c.nodeById[this.id];
2581
2587
  if (listItem) {
@@ -2682,22 +2688,27 @@ var Iti = class _Iti {
2682
2688
  if (dialCodeMatch) {
2683
2689
  const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
2684
2690
  const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
2691
+ if (iso2Codes.length === 1) {
2692
+ if (iso2Codes[0] === selectedIso2) {
2693
+ return null;
2694
+ }
2695
+ return iso2Codes[0];
2696
+ }
2685
2697
  if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
2686
2698
  return this.defaultCountry;
2687
2699
  }
2700
+ const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2701
+ if (isRegionlessNanpNumber) {
2702
+ return null;
2703
+ }
2688
2704
  const hasAreaCodesButNoneMatched = this.selectedCountryData.areaCodes && numeric.length > dialCodeMatchNumeric.length;
2689
2705
  const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && !hasAreaCodesButNoneMatched;
2690
- const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2691
- if (!isRegionlessNanpNumber && !alreadySelected) {
2692
- for (const iso2 of iso2Codes) {
2693
- if (iso2) {
2694
- return iso2;
2695
- }
2696
- }
2706
+ if (!alreadySelected) {
2707
+ return iso2Codes[0];
2697
2708
  }
2698
2709
  } else if (number.charAt(0) === "+" && numeric.length) {
2699
2710
  return "";
2700
- } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
2711
+ } else if ((!number || number === "+") && !selectedIso2) {
2701
2712
  return this.defaultCountry;
2702
2713
  }
2703
2714
  return null;
@@ -3246,7 +3257,7 @@ var intlTelInput = Object.assign(
3246
3257
  attachUtils,
3247
3258
  startedLoadingUtilsScript: false,
3248
3259
  startedLoadingAutoCountry: false,
3249
- version: "25.10.5"
3260
+ version: "25.10.6"
3250
3261
  }
3251
3262
  );
3252
3263
  var intl_tel_input_default = intlTelInput;
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 `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.10.5/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.10.6/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.