intl-tel-input 25.10.4 → 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.
@@ -1262,6 +1262,13 @@ var rawCountryData = [
1262
1262
  // Tuvalu
1263
1263
  "688"
1264
1264
  ],
1265
+ [
1266
+ "vi",
1267
+ // U.S. Virgin Islands
1268
+ "1",
1269
+ 24,
1270
+ ["340"]
1271
+ ],
1265
1272
  [
1266
1273
  "ug",
1267
1274
  // Uganda
@@ -1296,13 +1303,6 @@ var rawCountryData = [
1296
1303
  // Uruguay
1297
1304
  "598"
1298
1305
  ],
1299
- [
1300
- "vi",
1301
- // U.S. Virgin Islands
1302
- "1",
1303
- 24,
1304
- ["340"]
1305
- ],
1306
1306
  [
1307
1307
  "uz",
1308
1308
  // Uzbekistan
@@ -1878,6 +1878,9 @@ var Iti = class _Iti {
1878
1878
  }
1879
1879
  //* Add a dial code to this.dialCodeToIso2Map.
1880
1880
  _addToDialCodeMap(iso2, dialCode, priority) {
1881
+ if (!iso2 || !dialCode) {
1882
+ return;
1883
+ }
1881
1884
  if (dialCode.length > this.dialCodeMaxLen) {
1882
1885
  this.dialCodeMaxLen = dialCode.length;
1883
1886
  }
@@ -1932,6 +1935,11 @@ var Iti = class _Iti {
1932
1935
  }
1933
1936
  this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1934
1937
  }
1938
+ if (this.options.onlyCountries.length || this.options.excludeCountries.length) {
1939
+ this.dialCodes.forEach((dialCode) => {
1940
+ this.dialCodeToIso2Map[dialCode] = this.dialCodeToIso2Map[dialCode].filter(Boolean);
1941
+ });
1942
+ }
1935
1943
  for (const c of this.countries) {
1936
1944
  if (c.areaCodes) {
1937
1945
  const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
@@ -2350,7 +2358,7 @@ var Iti = class _Iti {
2350
2358
  _openDropdownWithPlus() {
2351
2359
  this._openDropdown();
2352
2360
  this.searchInput.value = "+";
2353
- this._filterCountries("", true);
2361
+ this._filterCountries("");
2354
2362
  }
2355
2363
  //* Initialize the tel input listeners.
2356
2364
  _initTelInputListeners() {
@@ -2533,11 +2541,7 @@ var Iti = class _Iti {
2533
2541
  if (this.options.countrySearch) {
2534
2542
  const doFilter = () => {
2535
2543
  const inputQuery = this.searchInput.value.trim();
2536
- if (inputQuery) {
2537
- this._filterCountries(inputQuery);
2538
- } else {
2539
- this._filterCountries("", true);
2540
- }
2544
+ this._filterCountries(inputQuery);
2541
2545
  if (this.searchInput.value) {
2542
2546
  this.searchClearButton.classList.remove("iti__hide");
2543
2547
  } else {
@@ -2576,42 +2580,44 @@ var Iti = class _Iti {
2576
2580
  }
2577
2581
  }
2578
2582
  //* Country search enabled: Filter the countries according to the search query.
2579
- _filterCountries(query, isReset = false) {
2583
+ _filterCountries(query) {
2580
2584
  let noCountriesAddedYet = true;
2581
2585
  this.countryList.innerHTML = "";
2582
2586
  const normalisedQuery = normaliseString(query);
2583
- const queryLength = normalisedQuery.length;
2584
- const iso2Matches = [];
2585
- const nameStartWith = [];
2586
- const nameContains = [];
2587
- const dialCodeMatches = [];
2588
- const dialCodeContains = [];
2589
- const initialsMatches = [];
2590
- for (const c of this.countries) {
2591
- if (isReset || queryLength === 0) {
2592
- nameContains.push(c);
2593
- } else if (c.iso2 === normalisedQuery) {
2594
- iso2Matches.push(c);
2595
- } else if (c.normalisedName.startsWith(normalisedQuery)) {
2596
- nameStartWith.push(c);
2597
- } else if (c.normalisedName.includes(normalisedQuery)) {
2598
- nameContains.push(c);
2599
- } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2600
- dialCodeMatches.push(c);
2601
- } else if (c.dialCodePlus.includes(normalisedQuery)) {
2602
- dialCodeContains.push(c);
2603
- } else if (c.initials.includes(normalisedQuery)) {
2604
- initialsMatches.push(c);
2587
+ let matchedCountries;
2588
+ if (query === "") {
2589
+ matchedCountries = this.countries;
2590
+ } else {
2591
+ const iso2Matches = [];
2592
+ const nameStartWith = [];
2593
+ const nameContains = [];
2594
+ const dialCodeMatches = [];
2595
+ const dialCodeContains = [];
2596
+ const initialsMatches = [];
2597
+ for (const c of this.countries) {
2598
+ if (c.iso2 === normalisedQuery) {
2599
+ iso2Matches.push(c);
2600
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2601
+ nameStartWith.push(c);
2602
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2603
+ nameContains.push(c);
2604
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2605
+ dialCodeMatches.push(c);
2606
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2607
+ dialCodeContains.push(c);
2608
+ } else if (c.initials.includes(normalisedQuery)) {
2609
+ initialsMatches.push(c);
2610
+ }
2605
2611
  }
2612
+ matchedCountries = [
2613
+ ...iso2Matches.sort((a, b) => a.priority - b.priority),
2614
+ ...nameStartWith.sort((a, b) => a.priority - b.priority),
2615
+ ...nameContains.sort((a, b) => a.priority - b.priority),
2616
+ ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2617
+ ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2618
+ ...initialsMatches.sort((a, b) => a.priority - b.priority)
2619
+ ];
2606
2620
  }
2607
- const matchedCountries = [
2608
- ...iso2Matches.sort((a, b) => a.priority - b.priority),
2609
- ...nameStartWith.sort((a, b) => a.priority - b.priority),
2610
- ...nameContains.sort((a, b) => a.priority - b.priority),
2611
- ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2612
- ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2613
- ...initialsMatches.sort((a, b) => a.priority - b.priority)
2614
- ];
2615
2621
  for (const c of matchedCountries) {
2616
2622
  const listItem = c.nodeById[this.id];
2617
2623
  if (listItem) {
@@ -2638,11 +2644,11 @@ var Iti = class _Iti {
2638
2644
  const { i18n } = this.options;
2639
2645
  const count = this.countryList.childElementCount;
2640
2646
  let searchText;
2641
- if ("searchResultsText" in i18n) {
2642
- searchText = i18n.searchResultsText(count);
2647
+ if (count === 0) {
2648
+ searchText = i18n.zeroSearchResults;
2643
2649
  } else {
2644
- if (count === 0) {
2645
- searchText = i18n.zeroSearchResults;
2650
+ if (i18n.searchResultsText) {
2651
+ searchText = i18n.searchResultsText(count);
2646
2652
  } else if (count === 1) {
2647
2653
  searchText = i18n.oneSearchResult;
2648
2654
  } else {
@@ -2718,22 +2724,27 @@ var Iti = class _Iti {
2718
2724
  if (dialCodeMatch) {
2719
2725
  const dialCodeMatchNumeric = getNumeric(dialCodeMatch);
2720
2726
  const iso2Codes = this.dialCodeToIso2Map[dialCodeMatchNumeric];
2727
+ if (iso2Codes.length === 1) {
2728
+ if (iso2Codes[0] === selectedIso2) {
2729
+ return null;
2730
+ }
2731
+ return iso2Codes[0];
2732
+ }
2721
2733
  if (!selectedIso2 && this.defaultCountry && iso2Codes.includes(this.defaultCountry)) {
2722
2734
  return this.defaultCountry;
2723
2735
  }
2736
+ const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2737
+ if (isRegionlessNanpNumber) {
2738
+ return null;
2739
+ }
2724
2740
  const hasAreaCodesButNoneMatched = this.selectedCountryData.areaCodes && numeric.length > dialCodeMatchNumeric.length;
2725
2741
  const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && !hasAreaCodesButNoneMatched;
2726
- const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2727
- if (!isRegionlessNanpNumber && !alreadySelected) {
2728
- for (const iso2 of iso2Codes) {
2729
- if (iso2) {
2730
- return iso2;
2731
- }
2732
- }
2742
+ if (!alreadySelected) {
2743
+ return iso2Codes[0];
2733
2744
  }
2734
2745
  } else if (number.charAt(0) === "+" && numeric.length) {
2735
2746
  return "";
2736
- } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
2747
+ } else if ((!number || number === "+") && !selectedIso2) {
2737
2748
  return this.defaultCountry;
2738
2749
  }
2739
2750
  return null;
@@ -3282,7 +3293,7 @@ var intlTelInput = Object.assign(
3282
3293
  attachUtils,
3283
3294
  startedLoadingUtilsScript: false,
3284
3295
  startedLoadingAutoCountry: false,
3285
- version: "25.10.4"
3296
+ version: "25.10.6"
3286
3297
  }
3287
3298
  );
3288
3299
  var intl_tel_input_default = intlTelInput;
@@ -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) {
@@ -2602,11 +2608,11 @@ var Iti = class _Iti {
2602
2608
  const { i18n } = this.options;
2603
2609
  const count = this.countryList.childElementCount;
2604
2610
  let searchText;
2605
- if ("searchResultsText" in i18n) {
2606
- searchText = i18n.searchResultsText(count);
2611
+ if (count === 0) {
2612
+ searchText = i18n.zeroSearchResults;
2607
2613
  } else {
2608
- if (count === 0) {
2609
- searchText = i18n.zeroSearchResults;
2614
+ if (i18n.searchResultsText) {
2615
+ searchText = i18n.searchResultsText(count);
2610
2616
  } else if (count === 1) {
2611
2617
  searchText = i18n.oneSearchResult;
2612
2618
  } else {
@@ -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.4"
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.4/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.