UNPKG

@lbgm/phone-input

Version:

An Angular phone input module

1,849 lines (1,839 loc) 74.9 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('libphonenumber-js'), require('@angular/common'), require('@angular/forms')) : typeof define === 'function' && define.amd ? define('@lbgm/phone-input', ['exports', '@angular/core', 'libphonenumber-js', '@angular/common', '@angular/forms'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lbgm = global.lbgm || {}, global.lbgm["phone-input"] = {}), global.ng.core, global.parsePhoneNumber, global.ng.common, global.ng.forms)); })(this, (function (exports, i0, parsePhoneNumber, i1, i2) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var i0__namespace = /*#__PURE__*/_interopNamespace(i0); var parsePhoneNumber__default = /*#__PURE__*/_interopDefaultLegacy(parsePhoneNumber); var i1__namespace = /*#__PURE__*/_interopNamespace(i1); var i2__namespace = /*#__PURE__*/_interopNamespace(i2); var PhoneInputService = /** @class */ (function () { function PhoneInputService() { } return PhoneInputService; }()); PhoneInputService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PhoneInputService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable }); PhoneInputService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PhoneInputService, providedIn: 'root' }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PhoneInputService, decorators: [{ type: i0.Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return []; } }); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function () { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } /** @deprecated */ function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** @deprecated */ function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } function __spreadArray(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); } function __classPrivateFieldSet(receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; } function __classPrivateFieldIn(state, receiver) { if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object"); return typeof state === "function" ? receiver === state : state.has(receiver); } // Array of country objects for the flag dropdown. var allCountries = [ [ 'Afghanistan (‫افغانستان‬‎)', 'af', '93', ], [ 'Albania (Shqipëri)', 'al', '355', ], [ 'Algeria (‫الجزائر‬‎)', 'dz', '213', ], [ 'American Samoa', 'as', '1684', ], [ 'Andorra', 'ad', '376', ], [ 'Angola', 'ao', '244', ], [ 'Anguilla', 'ai', '1264', ], [ 'Antigua and Barbuda', 'ag', '1268', ], [ 'Argentina', 'ar', '54', ], [ 'Armenia (Հայաստան)', 'am', '374', ], [ 'Aruba', 'aw', '297', ], [ 'Australia', 'au', '61', ], [ 'Austria (Österreich)', 'at', '43', ], [ 'Azerbaijan (Azərbaycan)', 'az', '994', ], [ 'Bahamas', 'bs', '1242', ], [ 'Bahrain (‫البحرين‬‎)', 'bh', '973', ], [ 'Bangladesh (বাংলাদেশ)', 'bd', '880', ], [ 'Barbados', 'bb', '1246', ], [ 'Belarus (Беларусь)', 'by', '375', ], [ 'Belgium (België)', 'be', '32', ], [ 'Belize', 'bz', '501', ], [ 'Benin (Bénin)', 'bj', '229', ], [ 'Bermuda', 'bm', '1441', ], [ 'Bhutan (འབྲུག)', 'bt', '975', ], [ 'Bolivia', 'bo', '591', ], [ 'Bosnia and Herzegovina (Босна и Херцеговина)', 'ba', '387', ], [ 'Botswana', 'bw', '267', ], [ 'Brazil (Brasil)', 'br', '55', ], [ 'British Indian Ocean Territory', 'io', '246', ], [ 'British Virgin Islands', 'vg', '1284', ], [ 'Brunei', 'bn', '673', ], [ 'Bulgaria (България)', 'bg', '359', ], [ 'Burkina Faso', 'bf', '226', ], [ 'Burundi (Uburundi)', 'bi', '257', ], [ 'Cambodia (កម្ពុជា)', 'kh', '855', ], [ 'Cameroon (Cameroun)', 'cm', '237', ], [ 'Canada', 'ca', '1', ], [ 'Cape Verde (Kabu Verdi)', 'cv', '238', ], [ 'Caribbean Netherlands', 'bq', '599', ], [ 'Cayman Islands', 'ky', '1345', ], [ 'Central African Republic (République centrafricaine)', 'cf', '236', ], [ 'Chad (Tchad)', 'td', '235', ], [ 'Chile', 'cl', '56', ], [ 'China (中国)', 'cn', '86', ], [ 'Christmas Island', 'cx', '61', ], [ 'Cocos (Keeling) Islands', 'cc', '61', ], [ 'Colombia', 'co', '57', ], [ 'Comoros (‫جزر القمر‬‎)', 'km', '269', ], [ 'Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)', 'cd', '243', ], [ 'Congo (Republic) (Congo-Brazzaville)', 'cg', '242', ], [ 'Cook Islands', 'ck', '682', ], [ 'Costa Rica', 'cr', '506', ], [ 'Côte d’Ivoire', 'ci', '225', ], [ 'Croatia (Hrvatska)', 'hr', '385', ], [ 'Cuba', 'cu', '53', ], [ 'Curaçao', 'cw', '599', ], [ 'Cyprus (Κύπρος)', 'cy', '357', ], [ 'Czech Republic (Česká republika)', 'cz', '420', ], [ 'Denmark (Danmark)', 'dk', '45', ], [ 'Djibouti', 'dj', '253', ], [ 'Dominica', 'dm', '1767', ], [ 'Dominican Republic (República Dominicana)', 'do', '1', ], [ 'Ecuador', 'ec', '593', ], [ 'Egypt (‫مصر‬‎)', 'eg', '20', ], [ 'El Salvador', 'sv', '503', ], [ 'Equatorial Guinea (Guinea Ecuatorial)', 'gq', '240', ], [ 'Eritrea', 'er', '291', ], [ 'Estonia (Eesti)', 'ee', '372', ], [ 'Ethiopia', 'et', '251', ], [ 'Falkland Islands (Islas Malvinas)', 'fk', '500', ], [ 'Faroe Islands (Føroyar)', 'fo', '298', ], [ 'Fiji', 'fj', '679', ], [ 'Finland (Suomi)', 'fi', '358', ], [ 'France', 'fr', '33', ], [ 'French Guiana (Guyane française)', 'gf', '594', ], [ 'French Polynesia (Polynésie française)', 'pf', '689', ], [ 'Gabon', 'ga', '241', ], [ 'Gambia', 'gm', '220', ], [ 'Georgia (საქართველო)', 'ge', '995', ], [ 'Germany (Deutschland)', 'de', '49', ], [ 'Ghana (Gaana)', 'gh', '233', ], [ 'Gibraltar', 'gi', '350', ], [ 'Greece (Ελλάδα)', 'gr', '30', ], [ 'Greenland (Kalaallit Nunaat)', 'gl', '299', ], [ 'Grenada', 'gd', '1473', ], [ 'Guadeloupe', 'gp', '590', ], [ 'Guam', 'gu', '1671', ], [ 'Guatemala', 'gt', '502', ], [ 'Guernsey', 'gg', '44', 1, ], [ 'Guinea (Guinée)', 'gn', '224', ], [ 'Guinea-Bissau (Guiné Bissau)', 'gw', '245', ], [ 'Guyana', 'gy', '592', ], [ 'Haiti', 'ht', '509', ], [ 'Honduras', 'hn', '504', ], [ 'Hong Kong (香港)', 'hk', '852', ], [ 'Hungary (Magyarország)', 'hu', '36', ], [ 'Iceland (Ísland)', 'is', '354', ], [ 'India (भारत)', 'in', '91', ], [ 'Indonesia', 'id', '62', ], [ 'Iran (‫ایران‬‎)', 'ir', '98', ], [ 'Iraq (‫العراق‬‎)', 'iq', '964', ], [ 'Ireland', 'ie', '353', ], [ 'Isle of Man', 'im', '44', ], [ 'Israel (‫ישראל‬‎)', 'il', '972', ], [ 'Italy (Italia)', 'it', '39', ], [ 'Jamaica', 'jm', '1876', ], [ 'Japan (日本)', 'jp', '81', ], [ 'Jersey', 'je', '44', ], [ 'Jordan (‫الأردن‬‎)', 'jo', '962', ], [ 'Kazakhstan (Казахстан)', 'kz', '7', ], [ 'Kenya', 'ke', '254', ], [ 'Kiribati', 'ki', '686', ], [ 'Kosovo', 'xk', '383', ], [ 'Kuwait (‫الكويت‬‎)', 'kw', '965', ], [ 'Kyrgyzstan (Кыргызстан)', 'kg', '996', ], [ 'Laos (ລາວ)', 'la', '856', ], [ 'Latvia (Latvija)', 'lv', '371', ], [ 'Lebanon (‫لبنان‬‎)', 'lb', '961', ], [ 'Lesotho', 'ls', '266', ], [ 'Liberia', 'lr', '231', ], [ 'Libya (‫ليبيا‬‎)', 'ly', '218', ], [ 'Liechtenstein', 'li', '423', ], [ 'Lithuania (Lietuva)', 'lt', '370', ], [ 'Luxembourg', 'lu', '352', ], [ 'Macau (澳門)', 'mo', '853', ], [ 'Macedonia (FYROM) (Македонија)', 'mk', '389', ], [ 'Madagascar (Madagasikara)', 'mg', '261', ], [ 'Malawi', 'mw', '265', ], [ 'Malaysia', 'my', '60', ], [ 'Maldives', 'mv', '960', ], [ 'Mali', 'ml', '223', ], [ 'Malta', 'mt', '356', ], [ 'Marshall Islands', 'mh', '692', ], [ 'Martinique', 'mq', '596', ], [ 'Mauritania (‫موريتانيا‬‎)', 'mr', '222', ], [ 'Mauritius (Moris)', 'mu', '230', ], [ 'Mayotte', 'yt', '262', ], [ 'Mexico (México)', 'mx', '52', ], [ 'Micronesia', 'fm', '691', ], [ 'Moldova (Republica Moldova)', 'md', '373', ], [ 'Monaco', 'mc', '377', ], [ 'Mongolia (Монгол)', 'mn', '976', ], [ 'Montenegro (Crna Gora)', 'me', '382', ], [ 'Montserrat', 'ms', '1664', ], [ 'Morocco (‫المغرب‬‎)', 'ma', '212', ], [ 'Mozambique (Moçambique)', 'mz', '258', ], [ 'Myanmar (Burma) (မြန်မာ)', 'mm', '95', ], [ 'Namibia (Namibië)', 'na', '264', ], [ 'Nauru', 'nr', '674', ], [ 'Nepal (नेपाल)', 'np', '977', ], [ 'Netherlands (Nederland)', 'nl', '31', ], [ 'New Caledonia (Nouvelle-Calédonie)', 'nc', '687', ], [ 'New Zealand', 'nz', '64', ], [ 'Nicaragua', 'ni', '505', ], [ 'Niger (Nijar)', 'ne', '227', ], [ 'Nigeria', 'ng', '234', ], [ 'Niue', 'nu', '683', ], [ 'Norfolk Island', 'nf', '672', ], [ 'North Korea (조선 민주주의 인민 공화국)', 'kp', '850', ], [ 'Northern Mariana Islands', 'mp', '1670', ], [ 'Norway (Norge)', 'no', '47', ], [ 'Oman (‫عُمان‬‎)', 'om', '968', ], [ 'Pakistan (‫پاکستان‬‎)', 'pk', '92', ], [ 'Palau', 'pw', '680', ], [ 'Palestine (‫فلسطين‬‎)', 'ps', '970', ], [ 'Panama (Panamá)', 'pa', '507', ], [ 'Papua New Guinea', 'pg', '675', ], [ 'Paraguay', 'py', '595', ], [ 'Peru (Perú)', 'pe', '51', ], [ 'Philippines', 'ph', '63', ], [ 'Poland (Polska)', 'pl', '48', ], [ 'Portugal', 'pt', '351', ], [ 'Puerto Rico', 'pr', '1', ], [ 'Qatar (‫قطر‬‎)', 'qa', '974', ], [ 'Réunion (La Réunion)', 're', '262', ], [ 'Romania (România)', 'ro', '40', ], [ 'Russia (Россия)', 'ru', '7', ], [ 'Rwanda', 'rw', '250', ], [ 'Saint Barthélemy', 'bl', '590', ], [ 'Saint Helena', 'sh', '290', ], [ 'Saint Kitts and Nevis', 'kn', '1869', ], [ 'Saint Lucia', 'lc', '1758', ], [ 'Saint Martin (Saint-Martin (partie française))', 'mf', '590', ], [ 'Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)', 'pm', '508', ], [ 'Saint Vincent and the Grenadines', 'vc', '1784', ], [ 'Samoa', 'ws', '685', ], [ 'San Marino', 'sm', '378', ], [ 'São Tomé and Príncipe (São Tomé e Príncipe)', 'st', '239', ], [ 'Saudi Arabia (‫المملكة العربية السعودية‬‎)', 'sa', '966', ], [ 'Senegal (Sénégal)', 'sn', '221', ], [ 'Serbia (Србија)', 'rs', '381', ], [ 'Seychelles', 'sc', '248', ], [ 'Sierra Leone', 'sl', '232', ], [ 'Singapore', 'sg', '65', ], [ 'Sint Maarten', 'sx', '1721', ], [ 'Slovakia (Slovensko)', 'sk', '421', ], [ 'Slovenia (Slovenija)', 'si', '386', ], [ 'Solomon Islands', 'sb', '677', ], [ 'Somalia (Soomaaliya)', 'so', '252', ], [ 'South Africa', 'za', '27', ], [ 'South Korea (대한민국)', 'kr', '82', ], [ 'South Sudan (‫جنوب السودان‬‎)', 'ss', '211', ], [ 'Spain (España)', 'es', '34', ], [ 'Sri Lanka (ශ්‍රී ලංකාව)', 'lk', '94', ], [ 'Sudan (‫السودان‬‎)', 'sd', '249', ], [ 'Suriname', 'sr', '597', ], [ 'Svalbard and Jan Mayen', 'sj', '47', ], [ 'Swaziland', 'sz', '268', ], [ 'Sweden (Sverige)', 'se', '46', ], [ 'Switzerland (Schweiz)', 'ch', '41', ], [ 'Syria (‫سوريا‬‎)', 'sy', '963', ], [ 'Taiwan (台灣)', 'tw', '886', ], [ 'Tajikistan', 'tj', '992', ], [ 'Tanzania', 'tz', '255', ], [ 'Thailand (ไทย)', 'th', '66', ], [ 'Timor-Leste', 'tl', '670', ], [ 'Togo', 'tg', '228', ], [ 'Tokelau', 'tk', '690', ], [ 'Tonga', 'to', '676', ], [ 'Trinidad and Tobago', 'tt', '1868', ], [ 'Tunisia (‫تونس‬‎)', 'tn', '216', ], [ 'Turkey (Türkiye)', 'tr', '90', ], [ 'Turkmenistan', 'tm', '993', ], [ 'Turks and Caicos Islands', 'tc', '1649', ], [ 'Tuvalu', 'tv', '688', ], [ 'U.S. Virgin Islands', 'vi', '1340', ], [ 'Uganda', 'ug', '256', ], [ 'Ukraine (Україна)', 'ua', '380', ], [ 'United Arab Emirates (‫الإمارات العربية المتحدة‬‎)', 'ae', '971', ], [ 'United Kingdom', 'gb', '44', ], [ 'United States', 'us', '1', ], [ 'Uruguay', 'uy', '598', ], [ 'Uzbekistan (Oʻzbekiston)', 'uz', '998', ], [ 'Vanuatu', 'vu', '678', ], [ 'Vatican City (Città del Vaticano)', 'va', '39', ], [ 'Venezuela', 've', '58', ], [ 'Vietnam (Việt Nam)', 'vn', '84', ], [ 'Wallis and Futuna (Wallis-et-Futuna)', 'wf', '681', ], [ 'Western Sahara (‫الصحراء الغربية‬‎)', 'eh', '212', ], [ 'Yemen (‫اليمن‬‎)', 'ye', '967', ], [ 'Zambia', 'zm', '260', ], [ 'Zimbabwe', 'zw', '263', ], [ 'Åland Islands', 'ax', '358', ], ]; var allCountries$1 = allCountries.map(function (_a) { var _b = __read(_a, 3), name = _b[0], iso2 = _b[1], dialCode = _b[2]; return ({ name: name, iso2: String(iso2).toUpperCase(), dialCode: dialCode, }); }); var TypingDirective = /** @class */ (function () { function TypingDirective(el) { this.el = el; this.inputInterval = 100; this.run = new i0.EventEmitter(); this.finish = new i0.EventEmitter(); } TypingDirective.prototype.onType = function (e) { var _this = this; var tping = function () { _this.run.emit(); }; var tpfinished = function () { _this.finish.emit(); }; if (e.type === "keyup") { if (e.key !== "Backspace") tping(); clearTimeout(this.inputTimer); this.inputTimer = setTimeout(tpfinished, this.inputInterval); } else if (e.type === "keydown") { clearTimeout(this.inputTimer); } }; return TypingDirective; }()); TypingDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TypingDirective, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive }); TypingDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: TypingDirective, selector: "[inputTyping]", inputs: { inputInterval: "inputInterval" }, outputs: { run: "run", finish: "finish" }, host: { listeners: { "keydown": "onType($event)", "keyup": "onType($event)" } }, ngImport: i0__namespace }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TypingDirective, decorators: [{ type: i0.Directive, args: [{ selector: '[inputTyping]' }] }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { inputInterval: [{ type: i0.Input }], run: [{ type: i0.Output }], finish: [{ type: i0.Output }], onType: [{ type: i0.HostListener, args: ["keydown", ['$event']] }, { type: i0.HostListener, args: ["keyup", ['$event']] }] } }); exports.FormControlEvent = void 0; (function (FormControlEvent) { FormControlEvent["INVALID"] = "INVALID"; FormControlEvent["VALID"] = "VALID"; })(exports.FormControlEvent || (exports.FormControlEvent = {})); var PhoneInputComponent = /** @class */ (function () { function PhoneInputComponent(el, cd) { this.el = el; this.cd = cd; this.value = ""; this.label = ""; this.hasError = false; this.hasSuccess = false; this.placeholder = ""; this.name = "lbgm-phone-input"; this.required = false; this.defaultCountry = 'BJ'; this.arrow = true; this.listHeight = 150; this.allowed = ([]); this.phoneEvent = new i0.EventEmitter(true); this.phoneData = new i0.EventEmitter(true); this.country = new i0.EventEmitter(true); this.countries = allCountries$1; this.openSelect = false; this.phone = ""; this.popupPos = "bottom"; this.focus = false; } /** * TrackBy for *ngFor * @param index * @param item * @returns */ PhoneInputComponent.prototype.trackByCountry = function (index, country) { return index; // you can also return item.X; }; PhoneInputComponent.prototype.ngOnInit = function () { // initialize default country selected this.defaultSelected = this.formatPhoneInput(this.value); }; PhoneInputComponent.prototype.ngOnChanges = function (changes) { // // watch changes on @Input() here }; PhoneInputComponent.prototype.ngDoCheck = function () { // this.cd.markForCheck(); }; PhoneInputComponent.prototype.ngAfterViewInit = function () { var _this = this; this.emitAll(); // outside document.addEventListener("click", function (event) { var _a, _b; if (((_a = _this.basePhoneArrow) === null || _a === void 0 ? void 0 : _a.nativeElement) && !((_b = _this.basePhoneArrow) === null || _b === void 0 ? void 0 : _b.nativeElement).contains(event.target)) { _this.openSelect = false; } }); }; /** * used to send custom Event: usable in case of scroll turning off when popup is under */ PhoneInputComponent.prototype.cev_dash_select = function () { var _a; var event = new CustomEvent("CEV_SELECT_POPUP", { detail: { opened: this.openSelect, target: (_a = this.selectPhone) === null || _a === void 0 ? void 0 : _a.nativeElement }, }); document.body.dispatchEvent(event); }; Object.defineProperty(PhoneInputComponent.prototype, "allowedCountries", { /** * filt allowedCountries from props */ get: function () { var _this = this; var tbl = this.allowed.length !== 0 ? this.countries.filter(function (o) { return _this.allowed.includes(o.iso2); }) : this.countries; return tbl; }, enumerable: false, configurable: true }); Object.defineProperty(PhoneInputComponent.prototype, "getGroup", { get: function () { return this.group; }, enumerable: false, configurable: true }); Object.defineProperty(PhoneInputComponent.prototype, "getName", { get: function () { return this.name; }, enumerable: false, configurable: true }); Object.defineProperty(PhoneInputComponent.prototype, "fieldError", { get: function () { var _a; if (!this.controls) return (_a = this.hasError) !== null && _a !== void 0 ? _a : false; var f = this.controls[this.name]; return f.status === exports.FormControlEvent.INVALID && f.touched && this.required; }, enumerable: false, configurable: true }); Object.defineProperty(PhoneInputComponent.prototype, "fieldSuccess", { get: function () { var _a; if (!this.controls) return (_a = this.hasSuccess) !== null && _a !== void 0 ? _a : false; var f = this.controls[this.name]; return f.status === exports.FormControlEvent.VALID && f.touched && this.required; }, enumerable: false, configurable: true }); /** * ToggleSelect * to open countries list */ PhoneInputComponent.prototype.toggleSelect = function () { var _a; this.openSelect = !this.openSelect; // calculate popup position: top or bottom var selectRect = (_a = this.selectPhone) === null || _a === void 0 ? void 0 : _a.nativeElement.getBoundingClientRect(); // y this.popupPos = selectRect.bottom < this.listHeight ? "top" : "bottom"; // this.cev_dash_select(); }; ; /** * formatPhoneInput * used to format Phone Input * @param val */ PhoneInputComponent.prototype.formatPhoneInput = function (val) { var _this = this; var _a; var phoneNumber = parsePhoneNumber__default["default"]("+" + val); if (phoneNumber) { this.phone = phoneNumber.nationalNumber; return { iso2: phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.country, dialCode: phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.countryCallingCode, name: (_a = this.countries.find(function (o) { return o.iso2 === (phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.country); })) === null || _a === void 0 ? void 0 : _a.name, }; } // else return Object.assign({}, this.countries.find(function (o) { return o.iso2 === _this.defaultCountry; })); }; ; /** * emitPhone * used to emit phone in internationalFormat */ PhoneInputComponent.prototype.emitPhone = function () { if (this.phone) this.phoneEvent.emit("" + this.defaultSelected.dialCode + this.phone); else this.phoneEvent.emit(""); }; ; /** * emitPhoneData * Used to emit phoneData as an object * @returns {} */ PhoneInputComponent.prototype.emitPhoneData = function (event) { void event; var ph = parsePhoneNumber__default["default"]("+" + this.defaultSelected.dialCode + this.phone); this.phoneData.emit({ country: ph === null || ph === void 0 ? void 0 : ph.country, dialCode: ph === null || ph === void 0 ? void 0 : ph.countryCallingCode, nationalNumber: ph === null || ph === void 0 ? void 0 : ph.nationalNumber, number: ph === null || ph === void 0 ? void 0 : ph.number, isValid: ph === null || ph === void 0 ? void 0 : ph.isValid(), }); }; ; /** * emitAll * used to emit all event */ PhoneInputComponent.prototype.emitAll = function () { this.country.emit(this.defaultSelected.iso2); this.emitPhone(); this.emitPhoneData(); }; /** * to select any country * @param country */ PhoneInputComponent.prototype.choose = function (country) { this.defaultSele