@ibragim-dev-org/ui-forge-library 1.4.52 → 1.4.54
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.
|
@@ -7,7 +7,6 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
|
7
7
|
import { isPlatformBrowser, DOCUMENT, NgStyle } from '@angular/common';
|
|
8
8
|
import { throttleTime, tap as tap$1, takeUntil, debounceTime as debounceTime$1 } from 'rxjs/operators';
|
|
9
9
|
import * as i2 from '@angular/platform-browser';
|
|
10
|
-
import { PhoneNumberUtil, AsYouTypeFormatter } from 'google-libphonenumber';
|
|
11
10
|
import { ulid } from 'ulid';
|
|
12
11
|
import * as i1 from '@angular/cdk/overlay';
|
|
13
12
|
import { OverlayConfig, FlexibleConnectedPositionStrategy } from '@angular/cdk/overlay';
|
|
@@ -1246,7 +1245,11 @@ const emptyCountry = {
|
|
|
1246
1245
|
phonePrefix: '',
|
|
1247
1246
|
};
|
|
1248
1247
|
class CountryService {
|
|
1249
|
-
static phoneUtil =
|
|
1248
|
+
static phoneUtil = null;
|
|
1249
|
+
static regionNames = null;
|
|
1250
|
+
static _supportedRegions = null;
|
|
1251
|
+
static _countries = null;
|
|
1252
|
+
static modulePromise = null;
|
|
1250
1253
|
static flagOverrides = {
|
|
1251
1254
|
AC: 'sh-ac',
|
|
1252
1255
|
TA: 'sh-ta',
|
|
@@ -1262,21 +1265,58 @@ class CountryService {
|
|
|
1262
1265
|
SX: 'sx',
|
|
1263
1266
|
MF: 'mf',
|
|
1264
1267
|
};
|
|
1265
|
-
static
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1268
|
+
static async loadLibphonenumber() {
|
|
1269
|
+
if (!this.modulePromise) {
|
|
1270
|
+
this.modulePromise = import('google-libphonenumber');
|
|
1271
|
+
}
|
|
1272
|
+
return this.modulePromise;
|
|
1273
|
+
}
|
|
1274
|
+
// Lazy initializer for phoneUtil
|
|
1275
|
+
static async getPhoneUtil() {
|
|
1276
|
+
if (!this.phoneUtil) {
|
|
1277
|
+
const { PhoneNumberUtil } = await this.loadLibphonenumber();
|
|
1278
|
+
this.phoneUtil = PhoneNumberUtil.getInstance();
|
|
1279
|
+
}
|
|
1280
|
+
return this.phoneUtil;
|
|
1281
|
+
}
|
|
1282
|
+
// Lazy initializer for regionNames
|
|
1283
|
+
static async getRegionNames() {
|
|
1284
|
+
if (!this.regionNames) {
|
|
1285
|
+
this.regionNames = new Intl.DisplayNames(['en'], { type: 'region' });
|
|
1286
|
+
}
|
|
1287
|
+
return this.regionNames;
|
|
1288
|
+
}
|
|
1289
|
+
// Lazy initializer for supported regions
|
|
1290
|
+
static async getSupportedRegions() {
|
|
1291
|
+
if (!this._supportedRegions) {
|
|
1292
|
+
const phoneUtil = await this.getPhoneUtil();
|
|
1293
|
+
this._supportedRegions = phoneUtil.getSupportedRegions();
|
|
1294
|
+
}
|
|
1295
|
+
return this._supportedRegions;
|
|
1296
|
+
}
|
|
1297
|
+
// Lazy initializer for countries
|
|
1298
|
+
static async getCountries() {
|
|
1299
|
+
if (!this._countries) {
|
|
1300
|
+
const phoneUtil = await this.getPhoneUtil();
|
|
1301
|
+
const regionNames = await this.getRegionNames();
|
|
1302
|
+
const supportedRegions = await this.getSupportedRegions();
|
|
1303
|
+
this._countries = supportedRegions.map((code) => {
|
|
1304
|
+
const name = regionNames.of(code) ?? '';
|
|
1305
|
+
const isoCode = (this.flagOverrides[code] ?? code).toLowerCase();
|
|
1306
|
+
const phonePrefix = '+' + phoneUtil.getCountryCodeForRegion(code);
|
|
1307
|
+
return {
|
|
1308
|
+
code,
|
|
1309
|
+
name,
|
|
1310
|
+
iso: isoCode,
|
|
1311
|
+
phonePrefix,
|
|
1312
|
+
};
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
return this._countries;
|
|
1316
|
+
}
|
|
1317
|
+
// Format phone number lazily
|
|
1318
|
+
static async formatPhoneNumber(raw, countryCode) {
|
|
1319
|
+
const { AsYouTypeFormatter } = await this.loadLibphonenumber();
|
|
1280
1320
|
const formatter = new AsYouTypeFormatter(countryCode);
|
|
1281
1321
|
let formatted = '';
|
|
1282
1322
|
for (const digit of raw) {
|
|
@@ -1284,8 +1324,10 @@ class CountryService {
|
|
|
1284
1324
|
}
|
|
1285
1325
|
return formatted;
|
|
1286
1326
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1327
|
+
// Lookup country lazily
|
|
1328
|
+
static async getCountryByCode(code) {
|
|
1329
|
+
const countries = await this.getCountries();
|
|
1330
|
+
return countries.find((v) => v.code === code.toUpperCase());
|
|
1289
1331
|
}
|
|
1290
1332
|
}
|
|
1291
1333
|
|
|
@@ -3895,21 +3937,23 @@ class UiInputCountryDirective extends UiInputDirective {
|
|
|
3895
3937
|
super(elementRef, renderer);
|
|
3896
3938
|
}
|
|
3897
3939
|
ngAfterViewInit() {
|
|
3898
|
-
this.autoSetCountry();
|
|
3940
|
+
void this.autoSetCountry();
|
|
3899
3941
|
}
|
|
3900
3942
|
onPaste(event) {
|
|
3901
3943
|
event.preventDefault();
|
|
3902
|
-
|
|
3903
|
-
|
|
3944
|
+
void this.handlePaste(event.clipboardData?.getData('text') || '');
|
|
3945
|
+
}
|
|
3946
|
+
async handlePaste(pastedText) {
|
|
3947
|
+
const country = await this.searchCountry(pastedText);
|
|
3904
3948
|
if (country) {
|
|
3905
3949
|
this.setCountry(country);
|
|
3906
3950
|
return;
|
|
3907
3951
|
}
|
|
3908
3952
|
this.onInput(this.value() + pastedText);
|
|
3909
3953
|
}
|
|
3910
|
-
searchCountry(temp) {
|
|
3911
|
-
const
|
|
3912
|
-
return
|
|
3954
|
+
async searchCountry(temp) {
|
|
3955
|
+
const countries = await CountryService.getCountries();
|
|
3956
|
+
return countries.find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
|
|
3913
3957
|
}
|
|
3914
3958
|
setCountry(country) {
|
|
3915
3959
|
this.$selectedCountry.set(country);
|
|
@@ -3919,7 +3963,7 @@ class UiInputCountryDirective extends UiInputDirective {
|
|
|
3919
3963
|
inputElement.focus();
|
|
3920
3964
|
}
|
|
3921
3965
|
}
|
|
3922
|
-
autoSetCountry() {
|
|
3966
|
+
async autoSetCountry() {
|
|
3923
3967
|
const value = this.value();
|
|
3924
3968
|
if (!value?.length) {
|
|
3925
3969
|
this.$selectedCountry.set({
|
|
@@ -3930,7 +3974,7 @@ class UiInputCountryDirective extends UiInputDirective {
|
|
|
3930
3974
|
});
|
|
3931
3975
|
return;
|
|
3932
3976
|
}
|
|
3933
|
-
const country = this.searchCountry(value);
|
|
3977
|
+
const country = await this.searchCountry(value);
|
|
3934
3978
|
if (country) {
|
|
3935
3979
|
this.$selectedCountry.set(country);
|
|
3936
3980
|
}
|
|
@@ -4102,13 +4146,19 @@ class UIPhoneNumberDirective extends UiInputDirective {
|
|
|
4102
4146
|
super(elementRef, renderer);
|
|
4103
4147
|
}
|
|
4104
4148
|
ngAfterViewInit() {
|
|
4105
|
-
|
|
4149
|
+
void this.initSelectedCountry();
|
|
4150
|
+
}
|
|
4151
|
+
async initSelectedCountry() {
|
|
4152
|
+
const selectedCountry = (await CountryService.getCountryByCode('US')) ?? emptyCountry;
|
|
4106
4153
|
this.$selectedCountry.set(selectedCountry);
|
|
4107
4154
|
this.$countryCode.set(selectedCountry.phonePrefix + ' ');
|
|
4108
4155
|
}
|
|
4109
4156
|
onInput(value) {
|
|
4157
|
+
void this.formatInput(value);
|
|
4158
|
+
}
|
|
4159
|
+
async formatInput(value) {
|
|
4110
4160
|
const digitsOnly = value.replace(/\D/g, '');
|
|
4111
|
-
const formattedValue = CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
|
|
4161
|
+
const formattedValue = await CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
|
|
4112
4162
|
super.onInput(formattedValue);
|
|
4113
4163
|
const inputElement = this.$inputElement()?.nativeElement;
|
|
4114
4164
|
if (inputElement) {
|
|
@@ -4117,8 +4167,11 @@ class UIPhoneNumberDirective extends UiInputDirective {
|
|
|
4117
4167
|
}
|
|
4118
4168
|
onPaste(event) {
|
|
4119
4169
|
event.preventDefault();
|
|
4120
|
-
|
|
4121
|
-
|
|
4170
|
+
void this.handlePaste(event.clipboardData?.getData('text') || '');
|
|
4171
|
+
}
|
|
4172
|
+
async handlePaste(pastedText) {
|
|
4173
|
+
const countries = await CountryService.getCountries();
|
|
4174
|
+
const country = countries.find((c) => pastedText.startsWith(c.phonePrefix));
|
|
4122
4175
|
if (country) {
|
|
4123
4176
|
const localNumber = pastedText.slice(country.phonePrefix.length);
|
|
4124
4177
|
this.setCountry(country);
|