@ibragim-dev-org/ui-forge-library 1.4.51 → 1.4.53
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.
|
@@ -1246,7 +1246,10 @@ const emptyCountry = {
|
|
|
1246
1246
|
phonePrefix: '',
|
|
1247
1247
|
};
|
|
1248
1248
|
class CountryService {
|
|
1249
|
-
static phoneUtil =
|
|
1249
|
+
static phoneUtil = null;
|
|
1250
|
+
static regionNames = null;
|
|
1251
|
+
static _supportedRegions = null;
|
|
1252
|
+
static _countries = null;
|
|
1250
1253
|
static flagOverrides = {
|
|
1251
1254
|
AC: 'sh-ac',
|
|
1252
1255
|
TA: 'sh-ta',
|
|
@@ -1262,20 +1265,47 @@ class CountryService {
|
|
|
1262
1265
|
SX: 'sx',
|
|
1263
1266
|
MF: 'mf',
|
|
1264
1267
|
};
|
|
1265
|
-
|
|
1266
|
-
static
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1268
|
+
// Lazy initializer for phoneUtil
|
|
1269
|
+
static getPhoneUtil() {
|
|
1270
|
+
if (!this.phoneUtil) {
|
|
1271
|
+
this.phoneUtil = PhoneNumberUtil.getInstance();
|
|
1272
|
+
}
|
|
1273
|
+
return this.phoneUtil;
|
|
1274
|
+
}
|
|
1275
|
+
// Lazy initializer for regionNames
|
|
1276
|
+
static getRegionNames() {
|
|
1277
|
+
if (!this.regionNames) {
|
|
1278
|
+
this.regionNames = new Intl.DisplayNames(['en'], { type: 'region' });
|
|
1279
|
+
}
|
|
1280
|
+
return this.regionNames;
|
|
1281
|
+
}
|
|
1282
|
+
// Lazy initializer for supported regions
|
|
1283
|
+
static getSupportedRegions() {
|
|
1284
|
+
if (!this._supportedRegions) {
|
|
1285
|
+
this._supportedRegions = this.getPhoneUtil().getSupportedRegions();
|
|
1286
|
+
}
|
|
1287
|
+
return this._supportedRegions;
|
|
1288
|
+
}
|
|
1289
|
+
// Lazy initializer for countries
|
|
1290
|
+
static getCountries() {
|
|
1291
|
+
if (!this._countries) {
|
|
1292
|
+
const phoneUtil = this.getPhoneUtil();
|
|
1293
|
+
const regionNames = this.getRegionNames();
|
|
1294
|
+
this._countries = this.getSupportedRegions().map((code) => {
|
|
1295
|
+
const name = regionNames.of(code) ?? '';
|
|
1296
|
+
const isoCode = (this.flagOverrides[code] ?? code).toLowerCase();
|
|
1297
|
+
const phonePrefix = '+' + phoneUtil.getCountryCodeForRegion(code);
|
|
1298
|
+
return {
|
|
1299
|
+
code,
|
|
1300
|
+
name,
|
|
1301
|
+
iso: isoCode,
|
|
1302
|
+
phonePrefix,
|
|
1303
|
+
};
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
return this._countries;
|
|
1307
|
+
}
|
|
1308
|
+
// Format phone number lazily
|
|
1279
1309
|
static formatPhoneNumber(raw, countryCode) {
|
|
1280
1310
|
const formatter = new AsYouTypeFormatter(countryCode);
|
|
1281
1311
|
let formatted = '';
|
|
@@ -1284,8 +1314,9 @@ class CountryService {
|
|
|
1284
1314
|
}
|
|
1285
1315
|
return formatted;
|
|
1286
1316
|
}
|
|
1317
|
+
// Lookup country lazily
|
|
1287
1318
|
static getCountryByCode(code) {
|
|
1288
|
-
return
|
|
1319
|
+
return this.getCountries().find((v) => v.code === code.toUpperCase());
|
|
1289
1320
|
}
|
|
1290
1321
|
}
|
|
1291
1322
|
|
|
@@ -2113,7 +2144,7 @@ class UiCodeDirective {
|
|
|
2113
2144
|
$codeToCopy = computed(() => {
|
|
2114
2145
|
let code = this.$code();
|
|
2115
2146
|
code = code.replace(/^\s*\n+|\n+\s*$/g, '');
|
|
2116
|
-
code = code.replace(/^(js|ts|css|html|xml|json)\
|
|
2147
|
+
code = code.replace(/^(js|ts|css|html|xml|json)(?=[ \n])/i, '');
|
|
2117
2148
|
code = code.replace(/^const\s+codeLanguages\s*:\s*Record<string,\s*LangRegExps>\s*=\s*\{[\s\S]*?\};?\s*\n?/, '');
|
|
2118
2149
|
return code.trim();
|
|
2119
2150
|
}, ...(ngDevMode ? [{ debugName: "$codeToCopy" }] : []));
|
|
@@ -3908,7 +3939,7 @@ class UiInputCountryDirective extends UiInputDirective {
|
|
|
3908
3939
|
this.onInput(this.value() + pastedText);
|
|
3909
3940
|
}
|
|
3910
3941
|
searchCountry(temp) {
|
|
3911
|
-
const country = CountryService.
|
|
3942
|
+
const country = CountryService.getCountries().find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
|
|
3912
3943
|
return country;
|
|
3913
3944
|
}
|
|
3914
3945
|
setCountry(country) {
|
|
@@ -4118,7 +4149,7 @@ class UIPhoneNumberDirective extends UiInputDirective {
|
|
|
4118
4149
|
onPaste(event) {
|
|
4119
4150
|
event.preventDefault();
|
|
4120
4151
|
const pastedText = event.clipboardData?.getData('text') || '';
|
|
4121
|
-
const country = CountryService.
|
|
4152
|
+
const country = CountryService.getCountries().find((c) => pastedText.startsWith(c.phonePrefix));
|
|
4122
4153
|
if (country) {
|
|
4123
4154
|
const localNumber = pastedText.slice(country.phonePrefix.length);
|
|
4124
4155
|
this.setCountry(country);
|