UNPKG

p-intl-input-tel

Version:

[![Build Status](https://travis-ci.org/jlevot/p-intl-input-tel.svg?branch=master)](https://travis-ci.org/jlevot/p-intl-input-tel) [![npm version](https://badge.fury.io/js/p-intl-input-tel.svg)](https://badge.fury.io/js/p-intl-input-tel-intl) [![npm](https

1,959 lines (1,949 loc) 62.1 kB
import * as lpn from 'google-libphonenumber'; import { PhoneNumberUtil, PhoneNumberFormat, PhoneNumber } from 'google-libphonenumber'; import * as i0 from '@angular/core'; import { Pipe, inject, ElementRef, Renderer2, input, Directive, computed, output, signal, forwardRef, Component } from '@angular/core'; import * as i2 from '@angular/forms'; import { FormControl, FormsModule, ReactiveFormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms'; import { BehaviorSubject } from 'rxjs'; import * as i1 from 'primeng/inputtext'; import { InputTextModule } from 'primeng/inputtext'; import * as i3 from 'primeng/inputgroup'; import { InputGroupModule } from 'primeng/inputgroup'; import * as i5 from 'primeng/inputgroupaddon'; import { InputGroupAddonModule } from 'primeng/inputgroupaddon'; import { Select } from 'primeng/select'; import * as i4 from 'primeng/api'; var SearchCountryField; (function (SearchCountryField) { SearchCountryField["DIALCODE"] = "dialCode"; SearchCountryField["ISO2"] = "iso2"; SearchCountryField["NAME"] = "name"; })(SearchCountryField || (SearchCountryField = {})); ; class Country { name; iso2; dialCode; priority; areaCodes; htmlId; flagClass; placeHolder; isFavorite; constructor() { this.name = ''; this.iso2 = ''; this.dialCode = ''; this.priority = 0; this.areaCodes = undefined; this.htmlId = ''; this.flagClass = ''; this.placeHolder = ''; } } class ChangeData { number; internationalNumber; nationalNumber; e164Number; countryCode; dialCode; constructor(phoneNumber) { const utils = PhoneNumberUtil.getInstance(); this.countryCode = phoneNumber && utils.getRegionCodeForNumber(phoneNumber) ? utils.getRegionCodeForNumber(phoneNumber) : ''; this.dialCode = phoneNumber?.getCountryCode() ? `+${phoneNumber.getCountryCode()}` : ''; this.e164Number = phoneNumber && utils.format(phoneNumber, PhoneNumberFormat.E164) !== '+0' ? utils.format(phoneNumber, PhoneNumberFormat.E164) : ''; this.internationalNumber = phoneNumber ? utils.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL) : ''; this.nationalNumber = phoneNumber ? utils.format(phoneNumber, PhoneNumberFormat.NATIONAL) : ''; this.number = phoneNumber ? utils.format(phoneNumber, PhoneNumberFormat.NATIONAL) : ''; } } var CountryISO; (function (CountryISO) { CountryISO["Afghanistan"] = "af"; CountryISO["Albania"] = "al"; CountryISO["Algeria"] = "dz"; CountryISO["AmericanSamoa"] = "as"; CountryISO["Andorra"] = "ad"; CountryISO["Angola"] = "ao"; CountryISO["Anguilla"] = "ai"; CountryISO["AntiguaAndBarbuda"] = "ag"; CountryISO["Argentina"] = "ar"; CountryISO["Armenia"] = "am"; CountryISO["Aruba"] = "aw"; CountryISO["Australia"] = "au"; CountryISO["Austria"] = "at"; CountryISO["Azerbaijan"] = "az"; CountryISO["Bahamas"] = "bs"; CountryISO["Bahrain"] = "bh"; CountryISO["Bangladesh"] = "bd"; CountryISO["Barbados"] = "bb"; CountryISO["Belarus"] = "by"; CountryISO["Belgium"] = "be"; CountryISO["Belize"] = "bz"; CountryISO["Benin"] = "bj"; CountryISO["Bermuda"] = "bm"; CountryISO["Bhutan"] = "bt"; CountryISO["Bolivia"] = "bo"; CountryISO["BosniaAndHerzegovina"] = "ba"; CountryISO["Botswana"] = "bw"; CountryISO["Brazil"] = "br"; CountryISO["BritishIndianOceanTerritory"] = "io"; CountryISO["BritishVirginIslands"] = "vg"; CountryISO["Brunei"] = "bn"; CountryISO["Bulgaria"] = "bg"; CountryISO["BurkinaFaso"] = "bf"; CountryISO["Burundi"] = "bi"; CountryISO["Cambodia"] = "kh"; CountryISO["Cameroon"] = "cm"; CountryISO["Canada"] = "ca"; CountryISO["CapeVerde"] = "cv"; CountryISO["CaribbeanNetherlands"] = "bq"; CountryISO["CaymanIslands"] = "ky"; CountryISO["CentralAfricanRepublic"] = "cf"; CountryISO["Chad"] = "td"; CountryISO["Chile"] = "cl"; CountryISO["China"] = "cn"; CountryISO["ChristmasIsland"] = "cx"; CountryISO["Cocos"] = "cc"; CountryISO["Colombia"] = "co"; CountryISO["Comoros"] = "km"; CountryISO["CongoDRCJamhuriYaKidemokrasiaYaKongo"] = "cd"; CountryISO["CongoRepublicCongoBrazzaville"] = "cg"; CountryISO["CookIslands"] = "ck"; CountryISO["CostaRica"] = "cr"; CountryISO["C\u00F4teDIvoire"] = "ci"; CountryISO["Croatia"] = "hr"; CountryISO["Cuba"] = "cu"; CountryISO["Cura\u00E7ao"] = "cw"; CountryISO["Cyprus"] = "cy"; CountryISO["CzechRepublic"] = "cz"; CountryISO["Denmark"] = "dk"; CountryISO["Djibouti"] = "dj"; CountryISO["Dominica"] = "dm"; CountryISO["DominicanRepublic"] = "do"; CountryISO["Ecuador"] = "ec"; CountryISO["Egypt"] = "eg"; CountryISO["ElSalvador"] = "sv"; CountryISO["EquatorialGuinea"] = "gq"; CountryISO["Eritrea"] = "er"; CountryISO["Estonia"] = "ee"; CountryISO["Ethiopia"] = "et"; CountryISO["FalklandIslands"] = "fk"; CountryISO["FaroeIslands"] = "fo"; CountryISO["Fiji"] = "fj"; CountryISO["Finland"] = "fi"; CountryISO["France"] = "fr"; CountryISO["FrenchGuiana"] = "gf"; CountryISO["FrenchPolynesia"] = "pf"; CountryISO["Gabon"] = "ga"; CountryISO["Gambia"] = "gm"; CountryISO["Georgia"] = "ge"; CountryISO["Germany"] = "de"; CountryISO["Ghana"] = "gh"; CountryISO["Gibraltar"] = "gi"; CountryISO["Greece"] = "gr"; CountryISO["Greenland"] = "gl"; CountryISO["Grenada"] = "gd"; CountryISO["Guadeloupe"] = "gp"; CountryISO["Guam"] = "gu"; CountryISO["Guatemala"] = "gt"; CountryISO["Guernsey"] = "gg"; CountryISO["Guinea"] = "gn"; CountryISO["GuineaBissau"] = "gw"; CountryISO["Guyana"] = "gy"; CountryISO["Haiti"] = "ht"; CountryISO["Honduras"] = "hn"; CountryISO["HongKong"] = "hk"; CountryISO["Hungary"] = "hu"; CountryISO["Iceland"] = "is"; CountryISO["India"] = "in"; CountryISO["Indonesia"] = "id"; CountryISO["Iran"] = "ir"; CountryISO["Iraq"] = "iq"; CountryISO["Ireland"] = "ie"; CountryISO["IsleOfMan"] = "im"; CountryISO["Israel"] = "il"; CountryISO["Italy"] = "it"; CountryISO["Jamaica"] = "jm"; CountryISO["Japan"] = "jp"; CountryISO["Jersey"] = "je"; CountryISO["Jordan"] = "jo"; CountryISO["Kazakhstan"] = "kz"; CountryISO["Kenya"] = "ke"; CountryISO["Kiribati"] = "ki"; CountryISO["Kosovo"] = "xk"; CountryISO["Kuwait"] = "kw"; CountryISO["Kyrgyzstan"] = "kg"; CountryISO["Laos"] = "la"; CountryISO["Latvia"] = "lv"; CountryISO["Lebanon"] = "lb"; CountryISO["Lesotho"] = "ls"; CountryISO["Liberia"] = "lr"; CountryISO["Libya"] = "ly"; CountryISO["Liechtenstein"] = "li"; CountryISO["Lithuania"] = "lt"; CountryISO["Luxembourg"] = "lu"; CountryISO["Macau"] = "mo"; CountryISO["Macedonia"] = "mk"; CountryISO["Madagascar"] = "mg"; CountryISO["Malawi"] = "mw"; CountryISO["Malaysia"] = "my"; CountryISO["Maldives"] = "mv"; CountryISO["Mali"] = "ml"; CountryISO["Malta"] = "mt"; CountryISO["MarshallIslands"] = "mh"; CountryISO["Martinique"] = "mq"; CountryISO["Mauritania"] = "mr"; CountryISO["Mauritius"] = "mu"; CountryISO["Mayotte"] = "yt"; CountryISO["Mexico"] = "mx"; CountryISO["Micronesia"] = "fm"; CountryISO["Moldova"] = "md"; CountryISO["Monaco"] = "mc"; CountryISO["Mongolia"] = "mn"; CountryISO["Montenegro"] = "me"; CountryISO["Montserrat"] = "ms"; CountryISO["Morocco"] = "ma"; CountryISO["Mozambique"] = "mz"; CountryISO["Myanmar"] = "mm"; CountryISO["Namibia"] = "na"; CountryISO["Nauru"] = "nr"; CountryISO["Nepal"] = "np"; CountryISO["Netherlands"] = "nl"; CountryISO["NewCaledonia"] = "nc"; CountryISO["NewZealand"] = "nz"; CountryISO["Nicaragua"] = "ni"; CountryISO["Niger"] = "ne"; CountryISO["Nigeria"] = "ng"; CountryISO["Niue"] = "nu"; CountryISO["NorfolkIsland"] = "nf"; CountryISO["NorthKorea"] = "kp"; CountryISO["NorthernMarianaIslands"] = "mp"; CountryISO["Norway"] = "no"; CountryISO["Oman"] = "om"; CountryISO["Pakistan"] = "pk"; CountryISO["Palau"] = "pw"; CountryISO["Palestine"] = "ps"; CountryISO["Panama"] = "pa"; CountryISO["PapuaNewGuinea"] = "pg"; CountryISO["Paraguay"] = "py"; CountryISO["Peru"] = "pe"; CountryISO["Philippines"] = "ph"; CountryISO["Poland"] = "pl"; CountryISO["Portugal"] = "pt"; CountryISO["PuertoRico"] = "pr"; CountryISO["Qatar"] = "qa"; CountryISO["R\u00E9union"] = "re"; CountryISO["Romania"] = "ro"; CountryISO["Russia"] = "ru"; CountryISO["Rwanda"] = "rw"; CountryISO["SaintBarth\u00E9lemy"] = "bl"; CountryISO["SaintHelena"] = "sh"; CountryISO["SaintKittsAndNevis"] = "kn"; CountryISO["SaintLucia"] = "lc"; CountryISO["SaintMartin"] = "mf"; CountryISO["SaintPierreAndMiquelon"] = "pm"; CountryISO["SaintVincentAndTheGrenadines"] = "vc"; CountryISO["Samoa"] = "ws"; CountryISO["SanMarino"] = "sm"; CountryISO["S\u00E3oTom\u00E9AndPr\u00EDncipe"] = "st"; CountryISO["SaudiArabia"] = "sa"; CountryISO["Senegal"] = "sn"; CountryISO["Serbia"] = "rs"; CountryISO["Seychelles"] = "sc"; CountryISO["SierraLeone"] = "sl"; CountryISO["Singapore"] = "sg"; CountryISO["SintMaarten"] = "sx"; CountryISO["Slovakia"] = "sk"; CountryISO["Slovenia"] = "si"; CountryISO["SolomonIslands"] = "sb"; CountryISO["Somalia"] = "so"; CountryISO["SouthAfrica"] = "za"; CountryISO["SouthKorea"] = "kr"; CountryISO["SouthSudan"] = "ss"; CountryISO["Spain"] = "es"; CountryISO["SriLanka"] = "lk"; CountryISO["Sudan"] = "sd"; CountryISO["Suriname"] = "sr"; CountryISO["SvalbardAndJanMayen"] = "sj"; CountryISO["Swaziland"] = "sz"; CountryISO["Sweden"] = "se"; CountryISO["Switzerland"] = "ch"; CountryISO["Syria"] = "sy"; CountryISO["Taiwan"] = "tw"; CountryISO["Tajikistan"] = "tj"; CountryISO["Tanzania"] = "tz"; CountryISO["Thailand"] = "th"; CountryISO["TimorLeste"] = "tl"; CountryISO["Togo"] = "tg"; CountryISO["Tokelau"] = "tk"; CountryISO["Tonga"] = "to"; CountryISO["TrinidadAndTobago"] = "tt"; CountryISO["Tunisia"] = "tn"; CountryISO["Turkey"] = "tr"; CountryISO["Turkmenistan"] = "tm"; CountryISO["TurksAndCaicosIslands"] = "tc"; CountryISO["Tuvalu"] = "tv"; CountryISO["USVirginIslands"] = "vi"; CountryISO["Uganda"] = "ug"; CountryISO["Ukraine"] = "ua"; CountryISO["UnitedArabEmirates"] = "ae"; CountryISO["UnitedKingdom"] = "gb"; CountryISO["UnitedStates"] = "us"; CountryISO["Uruguay"] = "uy"; CountryISO["Uzbekistan"] = "uz"; CountryISO["Vanuatu"] = "vu"; CountryISO["VaticanCity"] = "va"; CountryISO["Venezuela"] = "ve"; CountryISO["Vietnam"] = "vn"; CountryISO["WallisAndFutuna"] = "wf"; CountryISO["WesternSahara"] = "eh"; CountryISO["Yemen"] = "ye"; CountryISO["Zambia"] = "zm"; CountryISO["Zimbabwe"] = "zw"; CountryISO["\u00C5landIslands"] = "ax"; })(CountryISO || (CountryISO = {})); const ALL_COUNTRIES = [ [ 'Afghanistan (‫افغانستان‬‎)', CountryISO.Afghanistan, '93' ], [ 'Albania (Shqipëri)', CountryISO.Albania, '355' ], [ 'Algeria (‫الجزائر‬‎)', CountryISO.Algeria, '213' ], [ 'American Samoa', 'as', '1', 1, [ '684', ] ], [ 'Andorra', CountryISO.Andorra, '376' ], [ 'Angola', CountryISO.Angola, '244' ], [ 'Anguilla', 'ai', '1', 1, [ '264', ] ], [ 'Antigua and Barbuda', 'ag', '1', 1, [ '268', ] ], [ 'Argentina', CountryISO.Argentina, '54' ], [ 'Armenia (Հայաստան)', CountryISO.Armenia, '374' ], [ 'Aruba', CountryISO.Aruba, '297' ], [ 'Australia', CountryISO.Australia, '61', 0 ], [ 'Austria (Österreich)', CountryISO.Austria, '43' ], [ 'Azerbaijan (Azərbaycan)', CountryISO.Azerbaijan, '994' ], [ 'Bahamas', 'bs', '1', 1, [ '242', ] ], [ 'Bahrain (‫البحرين‬‎)', CountryISO.Bahrain, '973' ], [ 'Bangladesh (বাংলাদেশ)', CountryISO.Bangladesh, '880' ], [ 'Barbados', 'bb', '1', 1, [ '246', ] ], [ 'Belarus (Беларусь)', CountryISO.Belarus, '375' ], [ 'Belgium (België)', CountryISO.Belgium, '32' ], [ 'Belize', CountryISO.Belize, '501' ], [ 'Benin (Bénin)', CountryISO.Benin, '229' ], [ 'Bermuda', 'bm', '1', 1, [ '441', ] ], [ 'Bhutan (འབྲུག)', CountryISO.Bhutan, '975' ], [ 'Bolivia', CountryISO.Bolivia, '591' ], [ 'Bosnia and Herzegovina (Босна и Херцеговина)', CountryISO.BosniaAndHerzegovina, '387' ], [ 'Botswana', CountryISO.Botswana, '267' ], [ 'Brazil (Brasil)', CountryISO.Brazil, '55' ], [ 'British Indian Ocean Territory', CountryISO.BritishIndianOceanTerritory, '246' ], [ 'British Virgin Islands', 'vg', '1', 1, [ '284', ] ], [ 'Brunei', CountryISO.Brunei, '673' ], [ 'Bulgaria (България)', CountryISO.Bulgaria, '359' ], [ 'Burkina Faso', CountryISO.BurkinaFaso, '226' ], [ 'Burundi (Uburundi)', CountryISO.Burundi, '257' ], [ 'Cambodia (កម្ពុជា)', CountryISO.Cambodia, '855' ], [ 'Cameroon (Cameroun)', CountryISO.Cameroon, '237' ], [ 'Canada', CountryISO.Canada, '1', 1, [ '204', '226', '236', '249', '250', '289', '306', '343', '365', '387', '403', '416', '418', '431', '437', '438', '450', '506', '514', '519', '548', '579', '581', '587', '604', '613', '639', '647', '672', '705', '709', '742', '778', '780', '782', '807', '819', '825', '867', '873', '902', '905' ] ], [ 'Cape Verde (Kabu Verdi)', CountryISO.CapeVerde, '238' ], [ 'Caribbean Netherlands', CountryISO.CaribbeanNetherlands, '599', 1 ], [ 'Cayman Islands', 'ky', '1', 1, [ '345', ] ], [ 'Central African Republic (République centrafricaine)', CountryISO.CentralAfricanRepublic, '236' ], [ 'Chad (Tchad)', CountryISO.Chad, '235' ], [ 'Chile', CountryISO.Chile, '56' ], [ 'China (中国)', CountryISO.China, '86' ], [ 'Christmas Island', CountryISO.ChristmasIsland, '61', 2 ], [ 'Cocos (Keeling) Islands', CountryISO.Cocos, '61', 1 ], [ 'Colombia', CountryISO.Colombia, '57' ], [ 'Comoros (‫جزر القمر‬‎)', CountryISO.Comoros, '269' ], [ 'Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)', CountryISO.CongoDRCJamhuriYaKidemokrasiaYaKongo, '243' ], [ 'Congo (Republic) (Congo-Brazzaville)', CountryISO.CongoRepublicCongoBrazzaville, '242' ], [ 'Cook Islands', CountryISO.CookIslands, '682' ], [ 'Costa Rica', CountryISO.CostaRica, '506' ], [ 'Côte d’Ivoire', CountryISO.CôteDIvoire, '225' ], [ 'Croatia (Hrvatska)', CountryISO.Croatia, '385' ], [ 'Cuba', CountryISO.Cuba, '53' ], [ 'Curaçao', CountryISO.Curaçao, '599', 0 ], [ 'Cyprus (Κύπρος)', CountryISO.Cyprus, '357' ], [ 'Czech Republic (Česká republika)', CountryISO.CzechRepublic, '420' ], [ 'Denmark (Danmark)', CountryISO.Denmark, '45' ], [ 'Djibouti', CountryISO.Djibouti, '253' ], [ 'Dominica', CountryISO.Dominica, '1767' ], [ 'Dominican Republic (República Dominicana)', CountryISO.DominicanRepublic, '1', 2, ['809', '829', '849'] ], [ 'Ecuador', CountryISO.Ecuador, '593' ], [ 'Egypt (‫مصر‬‎)', CountryISO.Egypt, '20' ], [ 'El Salvador', CountryISO.ElSalvador, '503' ], [ 'Equatorial Guinea (Guinea Ecuatorial)', CountryISO.EquatorialGuinea, '240' ], [ 'Eritrea', CountryISO.Eritrea, '291' ], [ 'Estonia (Eesti)', CountryISO.Estonia, '372' ], [ 'Ethiopia', CountryISO.Ethiopia, '251' ], [ 'Falkland Islands (Islas Malvinas)', CountryISO.FalklandIslands, '500' ], [ 'Faroe Islands (Føroyar)', CountryISO.FaroeIslands, '298' ], [ 'Fiji', CountryISO.Fiji, '679' ], [ 'Finland (Suomi)', CountryISO.Finland, '358', 0 ], [ 'France', CountryISO.France, '33' ], [ 'French Guiana (Guyane française)', CountryISO.FrenchGuiana, '594' ], [ 'French Polynesia (Polynésie française)', CountryISO.FrenchPolynesia, '689' ], [ 'Gabon', CountryISO.Gabon, '241' ], [ 'Gambia', CountryISO.Gambia, '220' ], [ 'Georgia (საქართველო)', CountryISO.Georgia, '995' ], [ 'Germany (Deutschland)', CountryISO.Germany, '49' ], [ 'Ghana (Gaana)', CountryISO.Ghana, '233' ], [ 'Gibraltar', CountryISO.Gibraltar, '350' ], [ 'Greece (Ελλάδα)', CountryISO.Greece, '30' ], [ 'Greenland (Kalaallit Nunaat)', CountryISO.Greenland, '299' ], [ 'Grenada', CountryISO.Grenada, '1473' ], [ 'Guadeloupe', CountryISO.Guadeloupe, '590', 0 ], [ 'Guam', 'gu', '1', 1, [ '671', ] ], [ 'Guatemala', CountryISO.Guatemala, '502' ], [ 'Guernsey', CountryISO.Guernsey, '44', 1, [1481] ], [ 'Guinea (Guinée)', CountryISO.Guinea, '224' ], [ 'Guinea-Bissau (Guiné Bissau)', CountryISO.GuineaBissau, '245' ], [ 'Guyana', CountryISO.Guyana, '592' ], [ 'Haiti', CountryISO.Haiti, '509' ], [ 'Honduras', CountryISO.Honduras, '504' ], [ 'Hong Kong (香港)', CountryISO.HongKong, '852' ], [ 'Hungary (Magyarország)', CountryISO.Hungary, '36' ], [ 'Iceland (Ísland)', CountryISO.Iceland, '354' ], [ 'India (भारत)', CountryISO.India, '91' ], [ 'Indonesia', CountryISO.Indonesia, '62' ], [ 'Iran (‫ایران‬‎)', CountryISO.Iran, '98' ], [ 'Iraq (‫العراق‬‎)', CountryISO.Iraq, '964' ], [ 'Ireland', CountryISO.Ireland, '353' ], [ 'Isle of Man', CountryISO.IsleOfMan, '44', 2, [1624] ], [ 'Israel (‫ישראל‬‎)', CountryISO.Israel, '972' ], [ 'Italy (Italia)', CountryISO.Italy, '39', 0 ], [ 'Jamaica', 'jm', '1', 1, [ '876', ] ], [ 'Japan (日本)', CountryISO.Japan, '81' ], [ 'Jersey', CountryISO.Jersey, '44', 3, [1534] ], [ 'Jordan (‫الأردن‬‎)', CountryISO.Jordan, '962' ], [ 'Kazakhstan (Казахстан)', CountryISO.Kazakhstan, '7', 1 ], [ 'Kenya', CountryISO.Kenya, '254' ], [ 'Kiribati', CountryISO.Kiribati, '686' ], [ 'Kosovo', CountryISO.Kosovo, '383' ], [ 'Kuwait (‫الكويت‬‎)', CountryISO.Kuwait, '965' ], [ 'Kyrgyzstan (Кыргызстан)', CountryISO.Kyrgyzstan, '996' ], [ 'Laos (ລາວ)', CountryISO.Laos, '856' ], [ 'Latvia (Latvija)', CountryISO.Latvia, '371' ], [ 'Lebanon (‫لبنان‬‎)', CountryISO.Lebanon, '961' ], [ 'Lesotho', CountryISO.Lesotho, '266' ], [ 'Liberia', CountryISO.Liberia, '231' ], [ 'Libya (‫ليبيا‬‎)', CountryISO.Libya, '218' ], [ 'Liechtenstein', CountryISO.Liechtenstein, '423' ], [ 'Lithuania (Lietuva)', CountryISO.Lithuania, '370' ], [ 'Luxembourg', CountryISO.Luxembourg, '352' ], [ 'Macau (澳門)', CountryISO.Macau, '853' ], [ 'Macedonia (FYROM) (Македонија)', CountryISO.Macedonia, '389' ], [ 'Madagascar (Madagasikara)', CountryISO.Madagascar, '261' ], [ 'Malawi', CountryISO.Malawi, '265' ], [ 'Malaysia', CountryISO.Malaysia, '60' ], [ 'Maldives', CountryISO.Maldives, '960' ], [ 'Mali', CountryISO.Mali, '223' ], [ 'Malta', CountryISO.Malta, '356' ], [ 'Marshall Islands', CountryISO.MarshallIslands, '692' ], [ 'Martinique', CountryISO.Martinique, '596' ], [ 'Mauritania (‫موريتانيا‬‎)', CountryISO.Mauritania, '222' ], [ 'Mauritius (Moris)', CountryISO.Mauritius, '230' ], [ 'Mayotte', CountryISO.Mayotte, '262', 1 ], [ 'Mexico (México)', CountryISO.Mexico, '52' ], [ 'Micronesia', CountryISO.Micronesia, '691' ], [ 'Moldova (Republica Moldova)', CountryISO.Moldova, '373' ], [ 'Monaco', CountryISO.Monaco, '377' ], [ 'Mongolia (Монгол)', CountryISO.Mongolia, '976' ], [ 'Montenegro (Crna Gora)', CountryISO.Montenegro, '382' ], [ 'Montserrat', 'ms', '1', 1, [ '664', ] ], [ 'Morocco (‫المغرب‬‎)', CountryISO.Morocco, '212', 0 ], [ 'Mozambique (Moçambique)', CountryISO.Mozambique, '258' ], [ 'Myanmar (Burma) (မြန်မာ)', CountryISO.Myanmar, '95' ], [ 'Namibia (Namibië)', CountryISO.Namibia, '264' ], [ 'Nauru', CountryISO.Nauru, '674' ], [ 'Nepal (नेपाल)', CountryISO.Nepal, '977' ], [ 'Netherlands (Nederland)', CountryISO.Netherlands, '31' ], [ 'New Caledonia (Nouvelle-Calédonie)', CountryISO.NewCaledonia, '687' ], [ 'New Zealand', CountryISO.NewZealand, '64' ], [ 'Nicaragua', CountryISO.Nicaragua, '505' ], [ 'Niger (Nijar)', CountryISO.Niger, '227' ], [ 'Nigeria', CountryISO.Nigeria, '234' ], [ 'Niue', CountryISO.Niue, '683' ], [ 'Norfolk Island', CountryISO.NorfolkIsland, '672' ], [ 'North Korea (조선 민주주의 인민 공화국)', CountryISO.NorthKorea, '850' ], [ 'Northern Mariana Islands', CountryISO.NorthernMarianaIslands, '1670' ], [ 'Norway (Norge)', CountryISO.Norway, '47', 0 ], [ 'Oman (‫عُمان‬‎)', CountryISO.Oman, '968' ], [ 'Pakistan (‫پاکستان‬‎)', CountryISO.Pakistan, '92' ], [ 'Palau', CountryISO.Palau, '680' ], [ 'Palestine (‫فلسطين‬‎)', CountryISO.Palestine, '970' ], [ 'Panama (Panamá)', CountryISO.Panama, '507' ], [ 'Papua New Guinea', CountryISO.PapuaNewGuinea, '675' ], [ 'Paraguay', CountryISO.Paraguay, '595' ], [ 'Peru (Perú)', CountryISO.Peru, '51' ], [ 'Philippines', CountryISO.Philippines, '63' ], [ 'Poland (Polska)', CountryISO.Poland, '48' ], [ 'Portugal', CountryISO.Portugal, '351' ], [ 'Puerto Rico', CountryISO.PuertoRico, '1', 3, ['787', '939'] ], [ 'Qatar (‫قطر‬‎)', CountryISO.Qatar, '974' ], [ 'Réunion (La Réunion)', CountryISO.Réunion, '262', 0 ], [ 'Romania (România)', CountryISO.Romania, '40' ], [ 'Russia (Россия)', CountryISO.Russia, '7', 0 ], [ 'Rwanda', CountryISO.Rwanda, '250' ], [ 'Saint Barthélemy (Saint-Barthélemy)', CountryISO.SaintBarthélemy, '590', 1 ], [ 'Saint Helena', CountryISO.SaintHelena, '290' ], [ 'Saint Kitts and Nevis', CountryISO.SaintKittsAndNevis, '1869' ], [ 'Saint Lucia', 'lc', '1', 1, [ '758', ] ], [ 'Saint Martin (Saint-Martin (partie française))', CountryISO.SaintMartin, '590', 2 ], [ 'Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)', CountryISO.SaintPierreAndMiquelon, '508' ], [ 'Saint Vincent and the Grenadines', 'vc', '1', 1, [ '784', ] ], [ 'Samoa', CountryISO.Samoa, '685' ], [ 'San Marino', CountryISO.SanMarino, '378' ], [ 'São Tomé and Príncipe (São Tomé e Príncipe)', CountryISO.SãoToméAndPríncipe, '239' ], [ 'Saudi Arabia (‫المملكة العربية السعودية‬‎)', CountryISO.SaudiArabia, '966' ], [ 'Senegal (Sénégal)', CountryISO.Senegal, '221' ], [ 'Serbia (Србија)', CountryISO.Serbia, '381' ], [ 'Seychelles', CountryISO.Seychelles, '248' ], [ 'Sierra Leone', CountryISO.SierraLeone, '232' ], [ 'Singapore', CountryISO.Singapore, '65' ], [ 'Sint Maarten', 'sx', '1', 1, [ '721', ] ], [ 'Slovakia (Slovensko)', CountryISO.Slovakia, '421' ], [ 'Slovenia (Slovenija)', CountryISO.Slovenia, '386' ], [ 'Solomon Islands', CountryISO.SolomonIslands, '677' ], [ 'Somalia (Soomaaliya)', CountryISO.Somalia, '252' ], [ 'South Africa', CountryISO.SouthAfrica, '27' ], [ 'South Korea (대한민국)', CountryISO.SouthKorea, '82' ], [ 'South Sudan (‫جنوب السودان‬‎)', CountryISO.SouthSudan, '211' ], [ 'Spain (España)', CountryISO.Spain, '34' ], [ 'Sri Lanka (ශ්‍රී ලංකාව)', CountryISO.SriLanka, '94' ], [ 'Sudan (‫السودان‬‎)', CountryISO.Sudan, '249' ], [ 'Suriname', CountryISO.Suriname, '597' ], [ 'Svalbard and Jan Mayen', CountryISO.SvalbardAndJanMayen, '47', 1 ], [ 'Swaziland', CountryISO.Swaziland, '268' ], [ 'Sweden (Sverige)', CountryISO.Sweden, '46' ], [ 'Switzerland (Schweiz)', CountryISO.Switzerland, '41' ], [ 'Syria (‫سوريا‬‎)', CountryISO.Syria, '963' ], [ 'Taiwan (台灣)', CountryISO.Taiwan, '886' ], [ 'Tajikistan', CountryISO.Tajikistan, '992' ], [ 'Tanzania', CountryISO.Tanzania, '255' ], [ 'Thailand (ไทย)', CountryISO.Thailand, '66' ], [ 'Timor-Leste', CountryISO.TimorLeste, '670' ], [ 'Togo', CountryISO.Togo, '228' ], [ 'Tokelau', CountryISO.Tokelau, '690' ], [ 'Tonga', CountryISO.Tonga, '676' ], [ 'Trinidad and Tobago', 'tt', '1', 1, [ '868', ] ], [ 'Tunisia (‫تونس‬‎)', CountryISO.Tunisia, '216' ], [ 'Turkey (Türkiye)', CountryISO.Turkey, '90' ], [ 'Turkmenistan', CountryISO.Turkmenistan, '993' ], [ 'Turks and Caicos Islands', CountryISO.TurksAndCaicosIslands, '1649' ], [ 'Tuvalu', CountryISO.Tuvalu, '688' ], [ 'U.S. Virgin Islands', 'vi', '1', 1, [ '340', ] ], [ 'Uganda', CountryISO.Uganda, '256' ], [ 'Ukraine (Україна)', CountryISO.Ukraine, '380' ], [ 'United Arab Emirates (‫الإمارات العربية المتحدة‬‎)', CountryISO.UnitedArabEmirates, '971' ], [ 'United Kingdom', CountryISO.UnitedKingdom, '44', 0 ], [ 'United States', CountryISO.UnitedStates, '1', 0 ], [ 'Uruguay', CountryISO.Uruguay, '598' ], [ 'Uzbekistan (Oʻzbekiston)', CountryISO.Uzbekistan, '998' ], [ 'Vanuatu', CountryISO.Vanuatu, '678' ], [ 'Vatican City (Città del Vaticano)', CountryISO.VaticanCity, '39', 1 ], [ 'Venezuela', CountryISO.Venezuela, '58' ], [ 'Vietnam (Việt Nam)', CountryISO.Vietnam, '84' ], [ 'Wallis and Futuna', CountryISO.WallisAndFutuna, '681' ], [ 'Western Sahara (‫الصحراء الغربية‬‎)', CountryISO.WesternSahara, '212', 1 ], [ 'Yemen (‫اليمن‬‎)', CountryISO.Yemen, '967' ], [ 'Zambia', CountryISO.Zambia, '260' ], [ 'Zimbabwe', CountryISO.Zimbabwe, '263' ], [ 'Åland Islands', CountryISO.ÅlandIslands, '358', 1 ] ]; class LocalPhoneUtils { /** * Returns parse PhoneNumber object. * @param phoneNumber string * @param regionCode string */ static getParsedNumber(phoneNumber = '', regionCode = '') { if (!phoneNumber || !regionCode) return new PhoneNumber(); try { return lpn.PhoneNumberUtil.getInstance().parse(phoneNumber, regionCode.toUpperCase()); } catch (e) { return new PhoneNumber(); } } /** * Return a ChangeData object initialized with a phone number * @param phoneNumber */ static getChangeData(phoneNumber) { return new ChangeData(!phoneNumber ? new PhoneNumber() : lpn.PhoneNumberUtil.getInstance().parse(phoneNumber)); } /** * Gets formatted example phone number from phoneUtil. * @param numberFormat * @param countryCode */ static getPhoneNumberPlaceHolder(numberFormat, countryCode) { const phoneUtil = lpn.PhoneNumberUtil.getInstance(); return phoneUtil.format(phoneUtil.getExampleNumber(countryCode), numberFormat); } /** * Sifts through all countries and returns iso code of the primary country * based on the number provided. * @param number PhoneNumber * @param countryCode country code in number format */ static getCountryIsoCode(number, countryCode) { if (!countryCode) return; // Will use this to match area code from the first numbers // @ts-ignore const rawNumber = number['values_']['2'].toString(); // List of all countries with countryCode (can be more than one. e.x. US, CA, DO, PR all have +1 countryCode) const countriesFiltered = ALL_COUNTRIES.filter((c) => c[2].toString() === countryCode.toString()); // Main country is the country, which has no areaCodes specified in country-code.ts file. const mainCountry = countriesFiltered.find((c) => c[4] === undefined); // Secondary countries are all countries, which have areaCodes specified in country-code.ts file. const secondaryCountries = countriesFiltered.filter((c) => c[4] !== undefined); let matchedCountry = mainCountry ? mainCountry[1].toString() : undefined; /* Iterate over each secondary country and check if nationalNumber starts with any of areaCodes available. If no matches found, fallback to the main country. */ secondaryCountries.forEach((country) => { // @ts-ignore country[4].forEach((areaCode) => { if (rawNumber.startsWith(areaCode)) matchedCountry = country[1].toString(); }); }); return matchedCountry; } } /** * Check if the phone number provide is in a valid format compare to the country selected * If not, an error is pushed to the FormControl: { invalidFormat: true } * It can be catched in the parent form to display a user error * @param control */ const phoneNumberValidator = (control) => { const value = control.value; if (!value) return null; try { const phoneUtil = lpn.PhoneNumberUtil.getInstance(); const phoneNumber = phoneUtil.parse(value); const regionCode = phoneUtil.getRegionCodeForNumber(phoneNumber); if (!phoneUtil.isValidNumberForRegion(phoneNumber, regionCode)) { return { invalidFormat: true }; } } catch (error) { return { invalidFormat: true }; } return null; }; class DialCodePipe { transform(dialoCode) { if (!dialoCode) return ''; return `+${dialoCode}`; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.2", ngImport: i0, type: DialCodePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.1.2", ngImport: i0, type: DialCodePipe, isStandalone: true, name: "dialCode" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.2", ngImport: i0, type: DialCodePipe, decorators: [{ type: Pipe, args: [{ name: 'dialCode', standalone: true }] }] }); class FavoriteElementInjectorDirective { el = inject(ElementRef); renderer = inject(Renderer2); favoriteItemsCounter = input(...(ngDevMode ? [undefined, { debugName: "favoriteItemsCounter" }] : [])); ngOnInit() { const allFavorites = document.querySelectorAll('.favorite'); if (allFavorites[allFavorites.length - 1] === this.el.nativeElement && allFavorites.length === this.favoriteItemsCounter()) { this.renderer.addClass(this.el.nativeElement, 'last-favorite-option'); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.2", ngImport: i0, type: FavoriteElementInjectorDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.1.2", type: FavoriteElementInjectorDirective, isStandalone: true, selector: "[favorite]", inputs: { favoriteItemsCounter: { classPropertyName: "favoriteItemsCounter", publicName: "favoriteItemsCounter", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.2", ngImport: i0, type: FavoriteElementInjectorDirective, decorators: [{ type: Directive, args: [{ selector: '[favorite]', standalone: true }] }] }); class IntlInputTelComponent { // Custom css classes cssClass = input('', ...(ngDevMode ? [{ debugName: "cssClass" }] : [])); favoriteCountries = input(...(ngDevMode ? [undefined, { debugName: "favoriteCountries" }] : [])); // User option to display only some countries onlyCountries = input(...(ngDevMode ? [undefined, { debugName: "onlyCountries" }] : [])); // If true, the country will be set automatically if the user fill the region code enableAutoCountrySelect = input(true, ...(ngDevMode ? [{ debugName: "enableAutoCountrySelect" }] : [])); displayPlaceholder = input(true, ...(ngDevMode ? [{ debugName: "displayPlaceholder" }] : [])); customPlaceholder = input(...(ngDevMode ? [undefined, { debugName: "customPlaceholder" }] : [])); numberFormat = input(PhoneNumberFormat.INTERNATIONAL, ...(ngDevMode ? [{ debugName: "numberFormat" }] : [])); // Flag to display or not the input search for countries displaySearchCountry = input(true, ...(ngDevMode ? [{ debugName: "displaySearchCountry" }] : [])); // Search country property searchCountryField = input([SearchCountryField.NAME], ...(ngDevMode ? [{ debugName: "searchCountryField" }] : [])); searchCountryPlaceholder = input('Search country', ...(ngDevMode ? [{ debugName: "searchCountryPlaceholder" }] : [])); maxLength = input(...(ngDevMode ? [undefined, { debugName: "maxLength" }] : [])); // User option to select by default the first item of the list, default true selectFirstCountry = input(true, ...(ngDevMode ? [{ debugName: "selectFirstCountry" }] : [])); // Allow or not the phone validation form phoneValidation = input(true, ...(ngDevMode ? [{ debugName: "phoneValidation" }] : [])); // Customize the input id inputId = input('phone', ...(ngDevMode ? [{ debugName: "inputId" }] : [])); selectedCountryISO = input(...(ngDevMode ? [undefined, { debugName: "selectedCountryISO" }] : [])); separateDialCode = input(false, ...(ngDevMode ? [{ debugName: "separateDialCode" }] : [])); // Set the language for search and display name country lang = input('fr', ...(ngDevMode ? [{ debugName: "lang" }] : [])); // Target element to attach the overlay appendTo = input(null, ...(ngDevMode ? [{ debugName: "appendTo" }] : [])); // Custom css classes for the select overlay panel panelStyleClass = input('', ...(ngDevMode ? [{ debugName: "panelStyleClass" }] : [])); fullPanelStyleClass = computed(() => `fixWidth ${this.panelStyleClass()}`.trim(), ...(ngDevMode ? [{ debugName: "fullPanelStyleClass" }] : [])); countryChange = output(); SearchCountryField = SearchCountryField; phoneUtil = lpn.PhoneNumberUtil.getInstance(); selectedCountry = signal(new Country(), ...(ngDevMode ? [{ debugName: "selectedCountry" }] : [])); countries = []; phoneNumber$ = new BehaviorSubject(new PhoneNumber); phoneNumberControl = new FormControl(''); onTouched = () => { }; propagateChange = (_) => { }; get favorites() { return this.countries.filter(c => c.isFavorite); } constructor() { this.phoneNumberControl.valueChanges.subscribe(value => { this.onPhoneNumberChange(value); }); this.phoneNumber$.subscribe((phoneNumber) => { this.propagateChange(this.phoneUtil.format(phoneNumber, this.numberFormat())); }); } ngOnChanges(changes) { if (this.isSelectedCountryChanged(changes['selectedCountryISO']) && !changes['selectedCountryISO'].firstChange) this.updateSelectedCountry(); if (changes['favoriteCountries'] && !changes['favoriteCountries'].firstChange) this.onFavoriteCountriesChanged(); } init() { this.fetchCountryData(); if (this.onlyCountries()?.length) this.countries = this.countries.filter((c) => this.onlyCountries()?.includes(c.iso2)); this.updateSelectedCountry(); } /* --------------------------------- Events management -------------------------------- */ onPhoneNumberChange(value) { const currentCountryCode = this.selectedCountry().iso2; const number = LocalPhoneUtils.getParsedNumber(value, currentCountryCode); // Auto select country based on the extension (and areaCode if needed) (e.g select Canada if number starts with +1 416) if (this.enableAutoCountrySelect()) { const countryCode = LocalPhoneUtils.getCountryIsoCode(number, number?.getCountryCode()) || currentCountryCode; if (countryCode && countryCode !== this.selectedCountry().iso2) { const newCountry = this.countries .sort((a, b) => a.priority - b.priority) .find((c) => c.iso2 === countryCode.toUpperCase()); if (newCountry) this.setSelectedCountry(newCountry); } } this.phoneNumber$.next(number); } onCountrySelect(country, el) { let number = new PhoneNumber(); if (country !== this.selectedCountry()) this.setSelectedCountry(country); const currentValue = this.phoneNumberControl.value; if (currentValue) number = LocalPhoneUtils.getParsedNumber(currentValue, this.selectedCountry().iso2); this.phoneNumber$.next(number); setTimeout(() => el?.focus(), 100); } onFavoriteCountriesChanged() { this.fetchCountryData(); this.onCountrySelect(this.selectedCountry()); } onInputKeyPress(event) { const allowedChars = /[0-9\+\-\(\)\ ]/; const allowedCtrlChars = /[axcv]/; // Allows copy-pasting const allowedOtherKeys = [ 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown', 'Home', 'End', 'Insert', 'Delete', 'Backspace', 'Tab' ]; if (!allowedChars.test(event.key) && !(event.ctrlKey && allowedCtrlChars.test(event.key)) && !allowedOtherKeys.includes(event.key)) event.preventDefault(); } /* --------------------------------- Overwrite NG_VALUE_ACCESSOR -------------------------------- */ registerOnChange(fn) { this.propagateChange = fn; } registerOnTouched(fn) { this.onTouched = fn; } setDisabledState(isDisabled) { isDisabled ? this.phoneNumberControl.disable() : this.phoneNumberControl.enable(); } writeValue(obj) { this.init(); const phoneNumber = LocalPhoneUtils.getChangeData(obj); this.setSelectedCountry(this.countries.find(c => c.iso2.toUpperCase() === phoneNumber.countryCode)); this.phoneNumberControl.setValue(phoneNumber.number || ''); } /* --------------------------------- Helpers -------------------------------- */ fetchCountryData() { const regionsNames = new Intl.DisplayNames([this.lang()], { type: 'region', }); const favorites = this.favoriteCountries()?.map(code => code.toUpperCase()) ?? []; this.countries = ALL_COUNTRIES.map(country => { const countryCode = country[1].toString().toUpperCase(); return { name: regionsNames.of(countryCode) || '', iso2: countryCode, dialCode: country[2].toString(), priority: +country[3] || 0, areaCodes: country[4], htmlId: `item-${countryCode}`, flagClass: `iti__flag iti__${countryCode.toLowerCase()}`, placeHolder: this.getPlaceholder(countryCode), isFavorite: this.favoriteCountries()?.includes(country[1].toString()) ?? false }; }).sort((a, b) => { const indexA = favorites.indexOf(a.iso2); const indexB = favorites.indexOf(b.iso2); if (a.isFavorite && b.isFavorite) { return indexA - indexB; } if (a.isFavorite) return -1; if (b.isFavorite) return 1; return a.name.localeCompare(b.name); }); if (this.selectFirstCountry()) { const country = this.favoriteCountries()?.length ? this.favorites[0] : this.countries[0]; this.setSelectedCountry(country); } } /** * Updates selectedCountry. */ updateSelectedCountry() { if (!this.selectedCountryISO()) return; const countrySelected = this.countries.find((c) => c.iso2.toLowerCase() === this.selectedCountryISO()?.toLowerCase()); this.setSelectedCountry(countrySelected); } setSelectedCountry(country) { if (!country) return; this.selectedCountry.set(country); this.countryChange.emit(country); } isSelectedCountryChanged(selectedISO) { return this.countries && selectedISO && selectedISO.currentValue !== selectedISO.previousValue; } getPlaceholder(countryCode) { if (!this.displayPlaceholder()) return ''; if (this.customPlaceholder()) return this.customPlaceholder(); const placeholder = LocalPhoneUtils.getPhoneNumberPlaceHolder(this.numberFormat(), countryCode); if (this.separateDialCode() && this.numberFormat() === PhoneNumberFormat.INTERNATIONAL) return LocalPhoneUtils.getChangeData(placeholder).number || ''; return placeholder; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.2", ngImport: i0, type: IntlInputTelComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.2", type: IntlInputTelComponent, isStandalone: true, selector: "p-intl-tel-input", inputs: { cssClass: { classPropertyName: "cssClass", publicName: "cssClass", isSignal: true, isRequired: false, transformFunction: null }, favoriteCountries: { classPropertyName: "favoriteCountries", publicName: "favoriteCountries", isSignal: true, isRequired: false, transformFunction: null }, onlyCountries: { classPropertyName: "onlyCountries", publicName: "onlyCountries", isSignal: true, isRequired: false, transformFunction: null }, enableAutoCountrySelect: { classPropertyName: "enableAutoCountrySelect", publicName: "enableAutoCountrySelect", isSignal: true, isRequired: false, transformFunction: null }, displayPlaceholder: { classPropertyName: "displayPlaceholder", publicName: "displayPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, customPlaceholder: { classPropertyName: "customPlaceholder", publicName: "customPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, numberFormat: { classPropertyName: "numberFormat", publicName: "numberFormat", isSignal: true, isRequired: false, transformFunction: null }, displaySearchCountry: { classPropertyName: "displaySearchCountry", publicName: "displaySearchCountry", isSignal: true, isRequired: false, transformFunction: null }, searchCountryField: { classPropertyName: "searchCountryField", publicName: "searchCountryField", isSignal: true, isRequire