intl-tel-input 27.0.0 → 27.0.2
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.
- package/CHANGELOG.md +2 -1
- package/angular/dist/IntlTelInput.js +484 -367
- package/angular/dist/IntlTelInputWithUtils.js +484 -367
- package/dist/js/data.d.ts +1 -1
- package/dist/js/data.js +58 -2
- package/dist/js/data.min.js +1 -1
- package/dist/js/data.mjs +57 -1
- package/dist/js/i18n.d.ts +1 -1
- package/dist/js/intlTelInput.d.ts +1 -1
- package/dist/js/intlTelInput.js +485 -368
- package/dist/js/intlTelInput.min.js +3 -3
- package/dist/js/intlTelInput.mjs +484 -367
- package/dist/js/intlTelInputWithUtils.js +485 -368
- package/dist/js/intlTelInputWithUtils.min.js +3 -3
- package/dist/js/intlTelInputWithUtils.mjs +484 -367
- package/dist/js/utils.d.ts +6 -0
- package/package.json +2 -2
- package/react/dist/IntlTelInput.js +484 -367
- package/react/dist/IntlTelInputWithUtils.js +484 -367
- package/vue/dist/{IntlTelInput-D7r449B2.js → IntlTelInput-D7BKnLyx.js} +289 -286
- package/vue/dist/IntlTelInput.js +1 -1
- package/vue/dist/IntlTelInputWithUtils.js +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* International Telephone Input v27.0.
|
|
2
|
+
* International Telephone Input v27.0.2
|
|
3
3
|
* https://github.com/jackocnr/intl-tel-input.git
|
|
4
4
|
* Licensed under the MIT license
|
|
5
5
|
*/
|
|
@@ -300,7 +300,63 @@ var _factory = (() => {
|
|
|
300
300
|
// Canada
|
|
301
301
|
"1",
|
|
302
302
|
1,
|
|
303
|
-
[
|
|
303
|
+
[
|
|
304
|
+
"204",
|
|
305
|
+
"226",
|
|
306
|
+
"236",
|
|
307
|
+
"249",
|
|
308
|
+
"250",
|
|
309
|
+
"257",
|
|
310
|
+
"263",
|
|
311
|
+
"289",
|
|
312
|
+
"306",
|
|
313
|
+
"343",
|
|
314
|
+
"354",
|
|
315
|
+
"365",
|
|
316
|
+
"367",
|
|
317
|
+
"368",
|
|
318
|
+
"382",
|
|
319
|
+
"403",
|
|
320
|
+
"416",
|
|
321
|
+
"418",
|
|
322
|
+
"428",
|
|
323
|
+
"431",
|
|
324
|
+
"437",
|
|
325
|
+
"438",
|
|
326
|
+
"450",
|
|
327
|
+
"468",
|
|
328
|
+
"474",
|
|
329
|
+
"506",
|
|
330
|
+
"514",
|
|
331
|
+
"519",
|
|
332
|
+
"548",
|
|
333
|
+
"579",
|
|
334
|
+
"581",
|
|
335
|
+
"584",
|
|
336
|
+
"587",
|
|
337
|
+
"604",
|
|
338
|
+
"613",
|
|
339
|
+
"639",
|
|
340
|
+
"647",
|
|
341
|
+
"672",
|
|
342
|
+
"683",
|
|
343
|
+
"705",
|
|
344
|
+
"709",
|
|
345
|
+
"742",
|
|
346
|
+
"753",
|
|
347
|
+
"778",
|
|
348
|
+
"780",
|
|
349
|
+
"782",
|
|
350
|
+
"807",
|
|
351
|
+
"819",
|
|
352
|
+
"825",
|
|
353
|
+
"867",
|
|
354
|
+
"873",
|
|
355
|
+
"879",
|
|
356
|
+
"902",
|
|
357
|
+
"905",
|
|
358
|
+
"942"
|
|
359
|
+
],
|
|
304
360
|
"1"
|
|
305
361
|
],
|
|
306
362
|
[
|
|
@@ -1959,9 +2015,10 @@ var _factory = (() => {
|
|
|
1959
2015
|
console.warn(`[intl-tel-input] ${message}`);
|
|
1960
2016
|
};
|
|
1961
2017
|
var warnOption = (optionName, expectedType, actualValue) => {
|
|
1962
|
-
warn(
|
|
2018
|
+
warn(
|
|
2019
|
+
`Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`
|
|
2020
|
+
);
|
|
1963
2021
|
};
|
|
1964
|
-
var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
1965
2022
|
var validateIso2Array = (key, value) => {
|
|
1966
2023
|
const expectedType = "an array of ISO2 country code strings";
|
|
1967
2024
|
if (!Array.isArray(value)) {
|
|
@@ -1994,7 +2051,7 @@ var _factory = (() => {
|
|
|
1994
2051
|
}
|
|
1995
2052
|
const validatedOptions = {};
|
|
1996
2053
|
for (const [key, value] of Object.entries(customOptions)) {
|
|
1997
|
-
if (!hasOwn(defaults, key)) {
|
|
2054
|
+
if (!Object.hasOwn(defaults, key)) {
|
|
1998
2055
|
warn(`Unknown option '${key}'. Ignoring.`);
|
|
1999
2056
|
continue;
|
|
2000
2057
|
}
|
|
@@ -2088,8 +2145,12 @@ var _factory = (() => {
|
|
|
2088
2145
|
break;
|
|
2089
2146
|
}
|
|
2090
2147
|
const lower = value.toLowerCase();
|
|
2091
|
-
if (lower &&
|
|
2092
|
-
warnOption(
|
|
2148
|
+
if (lower && lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower)) {
|
|
2149
|
+
warnOption(
|
|
2150
|
+
"initialCountry",
|
|
2151
|
+
"a valid ISO2 country code or 'auto'",
|
|
2152
|
+
value
|
|
2153
|
+
);
|
|
2093
2154
|
break;
|
|
2094
2155
|
}
|
|
2095
2156
|
validatedOptions[key] = value;
|
|
@@ -2106,14 +2167,22 @@ var _factory = (() => {
|
|
|
2106
2167
|
case "allowedNumberTypes":
|
|
2107
2168
|
if (value !== null) {
|
|
2108
2169
|
if (!Array.isArray(value)) {
|
|
2109
|
-
warnOption(
|
|
2170
|
+
warnOption(
|
|
2171
|
+
"allowedNumberTypes",
|
|
2172
|
+
"an array of number types or null",
|
|
2173
|
+
value
|
|
2174
|
+
);
|
|
2110
2175
|
break;
|
|
2111
2176
|
}
|
|
2112
2177
|
let allValid = true;
|
|
2113
2178
|
for (const v of value) {
|
|
2114
2179
|
if (typeof v !== "string" || !NUMBER_TYPE_SET.has(v)) {
|
|
2115
2180
|
const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
|
|
2116
|
-
warnOption(
|
|
2181
|
+
warnOption(
|
|
2182
|
+
"allowedNumberTypes",
|
|
2183
|
+
`an array of valid number types (${validTypes})`,
|
|
2184
|
+
v
|
|
2185
|
+
);
|
|
2117
2186
|
allValid = false;
|
|
2118
2187
|
break;
|
|
2119
2188
|
}
|
|
@@ -2282,6 +2351,7 @@ var _factory = (() => {
|
|
|
2282
2351
|
#searchResultsA11yText;
|
|
2283
2352
|
#dropdownForContainer;
|
|
2284
2353
|
#selectedItem = null;
|
|
2354
|
+
#viewportHandler = null;
|
|
2285
2355
|
// public
|
|
2286
2356
|
telInput;
|
|
2287
2357
|
countryContainer;
|
|
@@ -2332,16 +2402,12 @@ var _factory = (() => {
|
|
|
2332
2402
|
const wrapper = this.#createWrapperAndInsert();
|
|
2333
2403
|
this.#maybeBuildCountryContainer(wrapper);
|
|
2334
2404
|
wrapper.appendChild(this.telInput);
|
|
2405
|
+
this.#maybeEnsureDropdownWidthSet();
|
|
2335
2406
|
this.#maybeUpdateInputPaddingAndReveal();
|
|
2336
2407
|
this.#maybeBuildHiddenInputs(wrapper);
|
|
2337
2408
|
}
|
|
2338
2409
|
#createWrapperAndInsert() {
|
|
2339
|
-
const {
|
|
2340
|
-
allowDropdown,
|
|
2341
|
-
showFlags,
|
|
2342
|
-
containerClass,
|
|
2343
|
-
useFullscreenPopup
|
|
2344
|
-
} = this.#options;
|
|
2410
|
+
const { allowDropdown, showFlags, containerClass, useFullscreenPopup } = this.#options;
|
|
2345
2411
|
const parentClasses = buildClassNames({
|
|
2346
2412
|
iti: true,
|
|
2347
2413
|
"iti--allow-dropdown": allowDropdown,
|
|
@@ -2358,72 +2424,74 @@ var _factory = (() => {
|
|
|
2358
2424
|
}
|
|
2359
2425
|
#maybeBuildCountryContainer(wrapper) {
|
|
2360
2426
|
const { allowDropdown, separateDialCode, showFlags } = this.#options;
|
|
2361
|
-
if (allowDropdown
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2427
|
+
if (!allowDropdown && !showFlags && !separateDialCode) {
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
this.countryContainer = createEl(
|
|
2431
|
+
"div",
|
|
2432
|
+
// visibly hidden until we measure its width to set the input padding correctly
|
|
2433
|
+
{ class: `iti__country-container ${CLASSES.V_HIDE}` },
|
|
2434
|
+
wrapper
|
|
2435
|
+
);
|
|
2436
|
+
if (allowDropdown) {
|
|
2437
|
+
this.selectedCountry = createEl(
|
|
2438
|
+
"button",
|
|
2439
|
+
{
|
|
2440
|
+
type: "button",
|
|
2441
|
+
class: "iti__selected-country",
|
|
2442
|
+
[ARIA.EXPANDED]: "false",
|
|
2443
|
+
[ARIA.LABEL]: this.#options.i18n.noCountrySelected,
|
|
2444
|
+
[ARIA.HASPOPUP]: "dialog",
|
|
2445
|
+
[ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
|
|
2446
|
+
},
|
|
2447
|
+
this.countryContainer
|
|
2367
2448
|
);
|
|
2368
|
-
if (
|
|
2369
|
-
this.selectedCountry
|
|
2370
|
-
"button",
|
|
2371
|
-
{
|
|
2372
|
-
type: "button",
|
|
2373
|
-
class: "iti__selected-country",
|
|
2374
|
-
[ARIA.EXPANDED]: "false",
|
|
2375
|
-
[ARIA.LABEL]: this.#options.i18n.noCountrySelected,
|
|
2376
|
-
[ARIA.HASPOPUP]: "dialog",
|
|
2377
|
-
[ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
|
|
2378
|
-
},
|
|
2379
|
-
this.countryContainer
|
|
2380
|
-
);
|
|
2381
|
-
if (this.telInput.disabled) {
|
|
2382
|
-
this.selectedCountry.setAttribute("disabled", "true");
|
|
2383
|
-
}
|
|
2384
|
-
} else {
|
|
2385
|
-
this.selectedCountry = createEl(
|
|
2386
|
-
"div",
|
|
2387
|
-
{ class: "iti__selected-country" },
|
|
2388
|
-
this.countryContainer
|
|
2389
|
-
);
|
|
2449
|
+
if (this.telInput.disabled) {
|
|
2450
|
+
this.selectedCountry.setAttribute("disabled", "true");
|
|
2390
2451
|
}
|
|
2391
|
-
|
|
2452
|
+
} else {
|
|
2453
|
+
this.selectedCountry = createEl(
|
|
2392
2454
|
"div",
|
|
2393
|
-
{ class: "iti__selected-country
|
|
2394
|
-
this.
|
|
2455
|
+
{ class: "iti__selected-country" },
|
|
2456
|
+
this.countryContainer
|
|
2395
2457
|
);
|
|
2396
|
-
|
|
2458
|
+
}
|
|
2459
|
+
const selectedCountryPrimary = createEl(
|
|
2460
|
+
"div",
|
|
2461
|
+
{ class: "iti__selected-country-primary" },
|
|
2462
|
+
this.selectedCountry
|
|
2463
|
+
);
|
|
2464
|
+
this.selectedCountryInner = createEl(
|
|
2465
|
+
"div",
|
|
2466
|
+
{ class: CLASSES.FLAG },
|
|
2467
|
+
selectedCountryPrimary
|
|
2468
|
+
);
|
|
2469
|
+
if (allowDropdown) {
|
|
2470
|
+
this.#dropdownArrow = createEl(
|
|
2397
2471
|
"div",
|
|
2398
|
-
{ class:
|
|
2472
|
+
{ class: "iti__arrow", [ARIA.HIDDEN]: "true" },
|
|
2399
2473
|
selectedCountryPrimary
|
|
2400
2474
|
);
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
{ class: "iti__selected-dial-code" },
|
|
2412
|
-
this.selectedCountry
|
|
2413
|
-
);
|
|
2414
|
-
}
|
|
2415
|
-
if (allowDropdown) {
|
|
2416
|
-
this.#buildDropdownContent();
|
|
2417
|
-
}
|
|
2475
|
+
}
|
|
2476
|
+
if (separateDialCode) {
|
|
2477
|
+
this.#selectedDialCode = createEl(
|
|
2478
|
+
"div",
|
|
2479
|
+
{ class: "iti__selected-dial-code" },
|
|
2480
|
+
this.selectedCountry
|
|
2481
|
+
);
|
|
2482
|
+
}
|
|
2483
|
+
if (allowDropdown) {
|
|
2484
|
+
this.#buildDropdownContent();
|
|
2418
2485
|
}
|
|
2419
2486
|
}
|
|
2420
2487
|
#maybeEnsureDropdownWidthSet() {
|
|
2421
|
-
const { fixDropdownWidth } = this.#options;
|
|
2422
|
-
if (fixDropdownWidth
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2488
|
+
const { fixDropdownWidth, allowDropdown } = this.#options;
|
|
2489
|
+
if (!allowDropdown || !fixDropdownWidth || this.#dropdownContent.style.width) {
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
const inputWidth = this.telInput.offsetWidth;
|
|
2493
|
+
if (inputWidth > 0) {
|
|
2494
|
+
this.#dropdownContent.style.width = `${inputWidth}px`;
|
|
2427
2495
|
}
|
|
2428
2496
|
}
|
|
2429
2497
|
#buildDropdownContent() {
|
|
@@ -2463,7 +2531,6 @@ var _factory = (() => {
|
|
|
2463
2531
|
this.#updateSearchResultsA11yText();
|
|
2464
2532
|
}
|
|
2465
2533
|
if (!useFullscreenPopup) {
|
|
2466
|
-
this.#maybeEnsureDropdownWidthSet();
|
|
2467
2534
|
this.#inlineDropdownHeight = this.#getHiddenInlineDropdownHeight();
|
|
2468
2535
|
if (countrySearch) {
|
|
2469
2536
|
this.#dropdownContent.style.height = `${this.#inlineDropdownHeight}px`;
|
|
@@ -2545,43 +2612,45 @@ var _factory = (() => {
|
|
|
2545
2612
|
this.#searchNoResults.textContent = i18n.searchEmptyState ?? null;
|
|
2546
2613
|
}
|
|
2547
2614
|
#maybeUpdateInputPaddingAndReveal() {
|
|
2548
|
-
if (this.countryContainer) {
|
|
2549
|
-
|
|
2550
|
-
this.countryContainer.classList.remove(CLASSES.V_HIDE);
|
|
2615
|
+
if (!this.countryContainer) {
|
|
2616
|
+
return;
|
|
2551
2617
|
}
|
|
2618
|
+
this.#updateInputPadding();
|
|
2619
|
+
this.countryContainer.classList.remove(CLASSES.V_HIDE);
|
|
2552
2620
|
}
|
|
2553
2621
|
#maybeBuildHiddenInputs(wrapper) {
|
|
2554
2622
|
const { hiddenInput } = this.#options;
|
|
2555
|
-
if (hiddenInput) {
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
}
|
|
2623
|
+
if (!hiddenInput) {
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2627
|
+
const names = hiddenInput(telInputName);
|
|
2628
|
+
if (names.phone) {
|
|
2629
|
+
const existingInput = this.telInput.form?.querySelector(
|
|
2630
|
+
`input[name="${names.phone}"]`
|
|
2631
|
+
);
|
|
2632
|
+
if (existingInput) {
|
|
2633
|
+
this.hiddenInputPhone = existingInput;
|
|
2634
|
+
} else {
|
|
2635
|
+
this.hiddenInputPhone = createEl("input", {
|
|
2636
|
+
type: "hidden",
|
|
2637
|
+
name: names.phone
|
|
2638
|
+
});
|
|
2639
|
+
wrapper.appendChild(this.hiddenInputPhone);
|
|
2571
2640
|
}
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2641
|
+
}
|
|
2642
|
+
if (names.country) {
|
|
2643
|
+
const existingInput = this.telInput.form?.querySelector(
|
|
2644
|
+
`input[name="${names.country}"]`
|
|
2645
|
+
);
|
|
2646
|
+
if (existingInput) {
|
|
2647
|
+
this.hiddenInputCountry = existingInput;
|
|
2648
|
+
} else {
|
|
2649
|
+
this.hiddenInputCountry = createEl("input", {
|
|
2650
|
+
type: "hidden",
|
|
2651
|
+
name: names.country
|
|
2652
|
+
});
|
|
2653
|
+
wrapper.appendChild(this.hiddenInputCountry);
|
|
2585
2654
|
}
|
|
2586
2655
|
}
|
|
2587
2656
|
}
|
|
@@ -2640,30 +2709,32 @@ var _factory = (() => {
|
|
|
2640
2709
|
//* To get the right styling to apply, all we need is a shallow clone of the container,
|
|
2641
2710
|
//* and then to inject a deep clone of the selectedCountry element.
|
|
2642
2711
|
#getHiddenSelectedCountryWidth() {
|
|
2643
|
-
if (this.telInput.parentNode) {
|
|
2644
|
-
|
|
2645
|
-
const containerClone = this.telInput.parentNode.cloneNode(
|
|
2646
|
-
false
|
|
2647
|
-
);
|
|
2648
|
-
containerClone.style.visibility = "hidden";
|
|
2649
|
-
body.appendChild(containerClone);
|
|
2650
|
-
const countryContainerClone = this.countryContainer.cloneNode();
|
|
2651
|
-
containerClone.appendChild(countryContainerClone);
|
|
2652
|
-
const selectedCountryClone = this.selectedCountry.cloneNode(
|
|
2653
|
-
true
|
|
2654
|
-
);
|
|
2655
|
-
countryContainerClone.appendChild(selectedCountryClone);
|
|
2656
|
-
const width = selectedCountryClone.offsetWidth;
|
|
2657
|
-
body.removeChild(containerClone);
|
|
2658
|
-
return width;
|
|
2712
|
+
if (!this.telInput.parentNode) {
|
|
2713
|
+
return 0;
|
|
2659
2714
|
}
|
|
2660
|
-
|
|
2715
|
+
const body = _UI.#getBody();
|
|
2716
|
+
const containerClone = this.telInput.parentNode.cloneNode(
|
|
2717
|
+
false
|
|
2718
|
+
);
|
|
2719
|
+
containerClone.style.visibility = "hidden";
|
|
2720
|
+
body.appendChild(containerClone);
|
|
2721
|
+
const countryContainerClone = this.countryContainer.cloneNode();
|
|
2722
|
+
containerClone.appendChild(countryContainerClone);
|
|
2723
|
+
const selectedCountryClone = this.selectedCountry.cloneNode(
|
|
2724
|
+
true
|
|
2725
|
+
);
|
|
2726
|
+
countryContainerClone.appendChild(selectedCountryClone);
|
|
2727
|
+
const width = selectedCountryClone.offsetWidth;
|
|
2728
|
+
body.removeChild(containerClone);
|
|
2729
|
+
return width;
|
|
2661
2730
|
}
|
|
2662
|
-
//
|
|
2731
|
+
// Get the dropdown height (before it is added to the DOM)
|
|
2663
2732
|
#getHiddenInlineDropdownHeight() {
|
|
2664
2733
|
const body = _UI.#getBody();
|
|
2665
2734
|
this.#dropdownContent.classList.remove(CLASSES.HIDE);
|
|
2666
|
-
const tempContainer = createEl("div", {
|
|
2735
|
+
const tempContainer = createEl("div", {
|
|
2736
|
+
class: "iti iti--inline-dropdown"
|
|
2737
|
+
});
|
|
2667
2738
|
tempContainer.appendChild(this.#dropdownContent);
|
|
2668
2739
|
tempContainer.style.visibility = "hidden";
|
|
2669
2740
|
body.appendChild(tempContainer);
|
|
@@ -2736,7 +2807,10 @@ var _factory = (() => {
|
|
|
2736
2807
|
this.highlightedItem.classList.add(CLASSES.HIGHLIGHT);
|
|
2737
2808
|
if (this.#options.countrySearch) {
|
|
2738
2809
|
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
|
|
2739
|
-
this.searchInput.setAttribute(
|
|
2810
|
+
this.searchInput.setAttribute(
|
|
2811
|
+
ARIA.ACTIVE_DESCENDANT,
|
|
2812
|
+
activeDescendant
|
|
2813
|
+
);
|
|
2740
2814
|
}
|
|
2741
2815
|
if (shouldFocus) {
|
|
2742
2816
|
this.highlightedItem.focus();
|
|
@@ -2817,11 +2891,7 @@ var _factory = (() => {
|
|
|
2817
2891
|
}
|
|
2818
2892
|
// UI: Open the dropdown (DOM only).
|
|
2819
2893
|
openDropdown() {
|
|
2820
|
-
const {
|
|
2821
|
-
countrySearch,
|
|
2822
|
-
dropdownAlwaysOpen,
|
|
2823
|
-
dropdownContainer
|
|
2824
|
-
} = this.#options;
|
|
2894
|
+
const { countrySearch, dropdownAlwaysOpen, dropdownContainer } = this.#options;
|
|
2825
2895
|
this.#maybeEnsureDropdownWidthSet();
|
|
2826
2896
|
if (dropdownContainer) {
|
|
2827
2897
|
this.#handleDropdownContainer();
|
|
@@ -2836,15 +2906,22 @@ var _factory = (() => {
|
|
|
2836
2906
|
}
|
|
2837
2907
|
this.#dropdownContent.classList.remove(CLASSES.HIDE);
|
|
2838
2908
|
this.selectedCountry.setAttribute(ARIA.EXPANDED, "true");
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2909
|
+
const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
|
|
2910
|
+
if (itemToHighlight) {
|
|
2911
|
+
this.highlightListItem(itemToHighlight, false);
|
|
2912
|
+
this.scrollCountryListToItem(itemToHighlight);
|
|
2913
|
+
}
|
|
2914
|
+
if (countrySearch && !dropdownAlwaysOpen) {
|
|
2915
|
+
this.searchInput.focus();
|
|
2916
|
+
}
|
|
2917
|
+
if (this.#options.useFullscreenPopup && this.#dropdownForContainer && window.visualViewport) {
|
|
2918
|
+
this.#viewportHandler = () => {
|
|
2919
|
+
this.#adjustFullscreenPopupToViewport();
|
|
2920
|
+
if (this.highlightedItem) {
|
|
2921
|
+
this.scrollCountryListToItem(this.highlightedItem);
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
window.visualViewport.addEventListener("resize", this.#viewportHandler);
|
|
2848
2925
|
}
|
|
2849
2926
|
this.#dropdownArrow.classList.add(CLASSES.ARROW_UP);
|
|
2850
2927
|
}
|
|
@@ -2863,6 +2940,13 @@ var _factory = (() => {
|
|
|
2863
2940
|
}
|
|
2864
2941
|
}
|
|
2865
2942
|
this.#dropdownArrow.classList.remove(CLASSES.ARROW_UP);
|
|
2943
|
+
if (this.#viewportHandler && window.visualViewport) {
|
|
2944
|
+
window.visualViewport.removeEventListener(
|
|
2945
|
+
"resize",
|
|
2946
|
+
this.#viewportHandler
|
|
2947
|
+
);
|
|
2948
|
+
this.#viewportHandler = null;
|
|
2949
|
+
}
|
|
2866
2950
|
if (dropdownContainer) {
|
|
2867
2951
|
this.#dropdownForContainer.remove();
|
|
2868
2952
|
this.#dropdownForContainer.style.top = "";
|
|
@@ -2905,6 +2989,16 @@ var _factory = (() => {
|
|
|
2905
2989
|
}
|
|
2906
2990
|
dropdownContainer.appendChild(this.#dropdownForContainer);
|
|
2907
2991
|
}
|
|
2992
|
+
// Adjust the fullscreen popup dimensions to match the visual viewport,
|
|
2993
|
+
// so it stays above the virtual keyboard on mobile devices.
|
|
2994
|
+
#adjustFullscreenPopupToViewport() {
|
|
2995
|
+
const vv = window.visualViewport;
|
|
2996
|
+
if (!vv || !this.#dropdownForContainer) {
|
|
2997
|
+
return;
|
|
2998
|
+
}
|
|
2999
|
+
const virtualKeyboardHeight = window.innerHeight - vv.height;
|
|
3000
|
+
this.#dropdownForContainer.style.bottom = `${virtualKeyboardHeight}px`;
|
|
3001
|
+
}
|
|
2908
3002
|
// UI: Whether the dropdown is currently closed (hidden).
|
|
2909
3003
|
isDropdownClosed() {
|
|
2910
3004
|
return this.#dropdownContent.classList.contains(CLASSES.HIDE);
|
|
@@ -2954,7 +3048,7 @@ var _factory = (() => {
|
|
|
2954
3048
|
(country) => !excludeCountries.includes(country.iso2)
|
|
2955
3049
|
);
|
|
2956
3050
|
}
|
|
2957
|
-
return data_default;
|
|
3051
|
+
return [...data_default];
|
|
2958
3052
|
};
|
|
2959
3053
|
var generateCountryNames = (countries, options) => {
|
|
2960
3054
|
const { countryNameLocale, i18n } = options;
|
|
@@ -2987,7 +3081,7 @@ var _factory = (() => {
|
|
|
2987
3081
|
if (dialCode.length > dialCodeMaxLen) {
|
|
2988
3082
|
dialCodeMaxLen = dialCode.length;
|
|
2989
3083
|
}
|
|
2990
|
-
if (!
|
|
3084
|
+
if (!Object.hasOwn(dialCodeToIso2Map, dialCode)) {
|
|
2991
3085
|
dialCodeToIso2Map[dialCode] = [];
|
|
2992
3086
|
}
|
|
2993
3087
|
const iso2List = dialCodeToIso2Map[dialCode];
|
|
@@ -2996,7 +3090,9 @@ var _factory = (() => {
|
|
|
2996
3090
|
}
|
|
2997
3091
|
iso2List.push(iso2);
|
|
2998
3092
|
};
|
|
2999
|
-
const countriesSortedByPriority = [...countries].sort(
|
|
3093
|
+
const countriesSortedByPriority = [...countries].sort(
|
|
3094
|
+
(a, b) => a.priority - b.priority
|
|
3095
|
+
);
|
|
3000
3096
|
for (const c of countriesSortedByPriority) {
|
|
3001
3097
|
if (!dialCodes.has(c.dialCode)) {
|
|
3002
3098
|
dialCodes.add(c.dialCode);
|
|
@@ -3065,15 +3161,12 @@ var _factory = (() => {
|
|
|
3065
3161
|
|
|
3066
3162
|
// src/js/format/formatting.ts
|
|
3067
3163
|
var beforeSetNumber = (fullNumber, hasValidDialCode, separateDialCode, selectedCountryData) => {
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
if (hasValidDialCode) {
|
|
3071
|
-
const dialCode = `+${selectedCountryData.dialCode}`;
|
|
3072
|
-
const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
|
|
3073
|
-
number = number.substring(start);
|
|
3074
|
-
}
|
|
3164
|
+
if (!separateDialCode || !hasValidDialCode) {
|
|
3165
|
+
return fullNumber;
|
|
3075
3166
|
}
|
|
3076
|
-
|
|
3167
|
+
const dialCode = `+${selectedCountryData.dialCode}`;
|
|
3168
|
+
const start = fullNumber[dialCode.length] === " " || fullNumber[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
|
|
3169
|
+
return fullNumber.substring(start);
|
|
3077
3170
|
};
|
|
3078
3171
|
var formatNumberAsYouType = (fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) => {
|
|
3079
3172
|
const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData?.iso2) : fullNumber;
|
|
@@ -3172,7 +3265,10 @@ var _factory = (() => {
|
|
|
3172
3265
|
}
|
|
3173
3266
|
const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
3174
3267
|
const regex = this.#userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
|
|
3175
|
-
return str.replace(
|
|
3268
|
+
return str.replace(
|
|
3269
|
+
regex,
|
|
3270
|
+
(ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base))
|
|
3271
|
+
);
|
|
3176
3272
|
}
|
|
3177
3273
|
isAscii() {
|
|
3178
3274
|
return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
|
|
@@ -3183,7 +3279,9 @@ var _factory = (() => {
|
|
|
3183
3279
|
var id = 0;
|
|
3184
3280
|
var ensureUtils = (methodName) => {
|
|
3185
3281
|
if (!intlTelInput.utils) {
|
|
3186
|
-
throw new Error(
|
|
3282
|
+
throw new Error(
|
|
3283
|
+
`intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`
|
|
3284
|
+
);
|
|
3187
3285
|
}
|
|
3188
3286
|
};
|
|
3189
3287
|
var createDeferred = () => {
|
|
@@ -3338,9 +3436,13 @@ var _factory = (() => {
|
|
|
3338
3436
|
this.#ui.hiddenInputCountry.value = this.#selectedCountryData?.iso2 || "";
|
|
3339
3437
|
}
|
|
3340
3438
|
};
|
|
3341
|
-
this.#ui.telInput.form?.addEventListener(
|
|
3342
|
-
|
|
3343
|
-
|
|
3439
|
+
this.#ui.telInput.form?.addEventListener(
|
|
3440
|
+
"submit",
|
|
3441
|
+
handleHiddenInputSubmit,
|
|
3442
|
+
{
|
|
3443
|
+
signal: this.#abortController.signal
|
|
3444
|
+
}
|
|
3445
|
+
);
|
|
3344
3446
|
}
|
|
3345
3447
|
//* initialise the dropdown listeners.
|
|
3346
3448
|
#initDropdownListeners() {
|
|
@@ -3369,7 +3471,12 @@ var _factory = (() => {
|
|
|
3369
3471
|
}
|
|
3370
3472
|
);
|
|
3371
3473
|
const handleCountryContainerKeydown = (e) => {
|
|
3372
|
-
const allowedKeys = [
|
|
3474
|
+
const allowedKeys = [
|
|
3475
|
+
KEYS.ARROW_UP,
|
|
3476
|
+
KEYS.ARROW_DOWN,
|
|
3477
|
+
KEYS.SPACE,
|
|
3478
|
+
KEYS.ENTER
|
|
3479
|
+
];
|
|
3373
3480
|
if (this.#ui.isDropdownClosed() && allowedKeys.includes(e.key)) {
|
|
3374
3481
|
e.preventDefault();
|
|
3375
3482
|
e.stopPropagation();
|
|
@@ -3387,8 +3494,8 @@ var _factory = (() => {
|
|
|
3387
3494
|
}
|
|
3388
3495
|
//* Init requests: utils script / geo ip lookup.
|
|
3389
3496
|
#initRequests() {
|
|
3390
|
-
|
|
3391
|
-
|
|
3497
|
+
if (this.#utilsScriptDeferred) {
|
|
3498
|
+
const { loadUtils } = this.#options;
|
|
3392
3499
|
const doAttachUtils = () => {
|
|
3393
3500
|
intlTelInput.attachUtils(loadUtils)?.catch(() => {
|
|
3394
3501
|
});
|
|
@@ -3400,13 +3507,10 @@ var _factory = (() => {
|
|
|
3400
3507
|
signal: this.#abortController.signal
|
|
3401
3508
|
});
|
|
3402
3509
|
}
|
|
3403
|
-
} else {
|
|
3404
|
-
this.#utilsScriptDeferred?.resolve();
|
|
3405
3510
|
}
|
|
3406
|
-
|
|
3407
|
-
if (isAutoCountry) {
|
|
3511
|
+
if (this.#autoCountryDeferred) {
|
|
3408
3512
|
if (this.#selectedCountryData) {
|
|
3409
|
-
this.#autoCountryDeferred
|
|
3513
|
+
this.#autoCountryDeferred.resolve();
|
|
3410
3514
|
} else {
|
|
3411
3515
|
this.#loadAutoCountry();
|
|
3412
3516
|
}
|
|
@@ -3416,28 +3520,29 @@ var _factory = (() => {
|
|
|
3416
3520
|
#loadAutoCountry() {
|
|
3417
3521
|
if (intlTelInput.autoCountry) {
|
|
3418
3522
|
this.#handleAutoCountry();
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
3436
|
-
_Iti.forEachInstance("handleAutoCountryFailure");
|
|
3437
|
-
};
|
|
3438
|
-
this.#options.geoIpLookup(successCallback, failureCallback);
|
|
3523
|
+
return;
|
|
3524
|
+
}
|
|
3525
|
+
this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
|
|
3526
|
+
if (intlTelInput.startedLoadingAutoCountry) {
|
|
3527
|
+
return;
|
|
3528
|
+
}
|
|
3529
|
+
intlTelInput.startedLoadingAutoCountry = true;
|
|
3530
|
+
if (typeof this.#options.geoIpLookup === "function") {
|
|
3531
|
+
const successCallback = (iso2 = "") => {
|
|
3532
|
+
this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
3533
|
+
const iso2Lower = iso2.toLowerCase();
|
|
3534
|
+
if (isIso2(iso2Lower)) {
|
|
3535
|
+
intlTelInput.autoCountry = iso2Lower;
|
|
3536
|
+
setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
|
|
3537
|
+
} else {
|
|
3538
|
+
_Iti.forEachInstance("handleAutoCountryFailure");
|
|
3439
3539
|
}
|
|
3440
|
-
}
|
|
3540
|
+
};
|
|
3541
|
+
const failureCallback = () => {
|
|
3542
|
+
this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
|
|
3543
|
+
_Iti.forEachInstance("handleAutoCountryFailure");
|
|
3544
|
+
};
|
|
3545
|
+
this.#options.geoIpLookup(successCallback, failureCallback);
|
|
3441
3546
|
}
|
|
3442
3547
|
}
|
|
3443
3548
|
#openDropdownWithPlus() {
|
|
@@ -3487,10 +3592,7 @@ var _factory = (() => {
|
|
|
3487
3592
|
const isAscii = this.#numerals.isAscii();
|
|
3488
3593
|
if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
|
|
3489
3594
|
const currentCaretPos = this.#ui.telInput.selectionStart || 0;
|
|
3490
|
-
const valueBeforeCaret = inputValue.substring(
|
|
3491
|
-
0,
|
|
3492
|
-
currentCaretPos
|
|
3493
|
-
);
|
|
3595
|
+
const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
|
|
3494
3596
|
const relevantCharsBeforeCaret = valueBeforeCaret.replace(
|
|
3495
3597
|
REGEX.NON_PLUS_NUMERIC_GLOBAL,
|
|
3496
3598
|
""
|
|
@@ -3533,96 +3635,100 @@ var _factory = (() => {
|
|
|
3533
3635
|
}
|
|
3534
3636
|
#maybeBindKeydownListener() {
|
|
3535
3637
|
const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
|
|
3536
|
-
if (strictMode
|
|
3537
|
-
|
|
3538
|
-
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
3539
|
-
if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
|
|
3540
|
-
e.preventDefault();
|
|
3541
|
-
this.#openDropdownWithPlus();
|
|
3542
|
-
return;
|
|
3543
|
-
}
|
|
3544
|
-
if (strictMode) {
|
|
3545
|
-
const inputValue = this.#getTelInputValue();
|
|
3546
|
-
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3547
|
-
const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
|
|
3548
|
-
const normalisedKey = this.#numerals.normalise(e.key);
|
|
3549
|
-
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3550
|
-
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3551
|
-
const input = this.#ui.telInput;
|
|
3552
|
-
const selStart = input.selectionStart;
|
|
3553
|
-
const selEnd = input.selectionEnd;
|
|
3554
|
-
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3555
|
-
const after = inputValue.slice(selEnd ?? void 0);
|
|
3556
|
-
const newValue = before + e.key + after;
|
|
3557
|
-
const newFullNumber = this.#getFullNumber(newValue);
|
|
3558
|
-
let hasExceededMaxLength = false;
|
|
3559
|
-
if (intlTelInput.utils && this.#maxCoreNumberLength) {
|
|
3560
|
-
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3561
|
-
newFullNumber,
|
|
3562
|
-
this.#selectedCountryData?.iso2
|
|
3563
|
-
);
|
|
3564
|
-
hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
|
|
3565
|
-
}
|
|
3566
|
-
const newCountry = this.#getNewCountryFromNumber(newFullNumber);
|
|
3567
|
-
const isChangingDialCode = newCountry !== null;
|
|
3568
|
-
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
3569
|
-
e.preventDefault();
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3573
|
-
};
|
|
3574
|
-
this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
|
|
3575
|
-
signal: this.#abortController.signal
|
|
3576
|
-
});
|
|
3638
|
+
if (!strictMode && !separateDialCode) {
|
|
3639
|
+
return;
|
|
3577
3640
|
}
|
|
3641
|
+
const handleKeydownEvent = (e) => {
|
|
3642
|
+
if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
|
|
3643
|
+
return;
|
|
3644
|
+
}
|
|
3645
|
+
if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
|
|
3646
|
+
e.preventDefault();
|
|
3647
|
+
this.#openDropdownWithPlus();
|
|
3648
|
+
return;
|
|
3649
|
+
}
|
|
3650
|
+
if (!strictMode) {
|
|
3651
|
+
return;
|
|
3652
|
+
}
|
|
3653
|
+
const inputValue = this.#getTelInputValue();
|
|
3654
|
+
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3655
|
+
const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
|
|
3656
|
+
const normalisedKey = this.#numerals.normalise(e.key);
|
|
3657
|
+
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3658
|
+
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3659
|
+
const input = this.#ui.telInput;
|
|
3660
|
+
const selStart = input.selectionStart;
|
|
3661
|
+
const selEnd = input.selectionEnd;
|
|
3662
|
+
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3663
|
+
const after = inputValue.slice(selEnd ?? void 0);
|
|
3664
|
+
const newValue = before + e.key + after;
|
|
3665
|
+
const newFullNumber = this.#getFullNumber(newValue);
|
|
3666
|
+
let hasExceededMaxLength = false;
|
|
3667
|
+
if (intlTelInput.utils && this.#maxCoreNumberLength) {
|
|
3668
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3669
|
+
newFullNumber,
|
|
3670
|
+
this.#selectedCountryData?.iso2
|
|
3671
|
+
);
|
|
3672
|
+
hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
|
|
3673
|
+
}
|
|
3674
|
+
const newCountry = this.#getNewCountryFromNumber(newFullNumber);
|
|
3675
|
+
const isChangingDialCode = newCountry !== null;
|
|
3676
|
+
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
3677
|
+
e.preventDefault();
|
|
3678
|
+
}
|
|
3679
|
+
};
|
|
3680
|
+
this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
|
|
3681
|
+
signal: this.#abortController.signal
|
|
3682
|
+
});
|
|
3578
3683
|
}
|
|
3579
3684
|
#maybeBindPasteListener() {
|
|
3580
|
-
if (this.#options.strictMode) {
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3685
|
+
if (!this.#options.strictMode) {
|
|
3686
|
+
return;
|
|
3687
|
+
}
|
|
3688
|
+
const handlePasteEvent = (e) => {
|
|
3689
|
+
e.preventDefault();
|
|
3690
|
+
const input = this.#ui.telInput;
|
|
3691
|
+
const selStart = input.selectionStart;
|
|
3692
|
+
const selEnd = input.selectionEnd;
|
|
3693
|
+
const inputValue = this.#getTelInputValue();
|
|
3694
|
+
const before = inputValue.slice(0, selStart ?? void 0);
|
|
3695
|
+
const after = inputValue.slice(selEnd ?? void 0);
|
|
3696
|
+
const iso2 = this.#selectedCountryData?.iso2;
|
|
3697
|
+
const pastedRaw = e.clipboardData.getData("text");
|
|
3698
|
+
const pasted = this.#numerals.normalise(pastedRaw);
|
|
3699
|
+
const initialCharSelected = selStart === 0 && selEnd > 0;
|
|
3700
|
+
const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
|
|
3701
|
+
const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
|
|
3702
|
+
const hasLeadingPlus = allowedChars.startsWith("+");
|
|
3703
|
+
const numerics = allowedChars.replace(/\+/g, "");
|
|
3704
|
+
const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
|
|
3705
|
+
let newVal = before + sanitised + after;
|
|
3706
|
+
if (newVal.length > 5 && intlTelInput.utils) {
|
|
3707
|
+
let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3708
|
+
while (coreNumber.length === 0 && newVal.length > 0) {
|
|
3709
|
+
newVal = newVal.slice(0, -1);
|
|
3710
|
+
coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3711
|
+
}
|
|
3712
|
+
if (!coreNumber) {
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
|
|
3716
|
+
if (input.selectionEnd === inputValue.length) {
|
|
3717
|
+
const trimLength = coreNumber.length - this.#maxCoreNumberLength;
|
|
3718
|
+
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3719
|
+
} else {
|
|
3606
3720
|
return;
|
|
3607
3721
|
}
|
|
3608
|
-
if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
|
|
3609
|
-
if (input.selectionEnd === inputValue.length) {
|
|
3610
|
-
const trimLength = coreNumber.length - this.#maxCoreNumberLength;
|
|
3611
|
-
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3612
|
-
} else {
|
|
3613
|
-
return;
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
3722
|
}
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
};
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
}
|
|
3723
|
+
}
|
|
3724
|
+
this.#setTelInputValue(newVal);
|
|
3725
|
+
const caretPos = selStart + sanitised.length;
|
|
3726
|
+
input.setSelectionRange(caretPos, caretPos);
|
|
3727
|
+
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
3728
|
+
};
|
|
3729
|
+
this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
|
|
3730
|
+
signal: this.#abortController.signal
|
|
3731
|
+
});
|
|
3626
3732
|
}
|
|
3627
3733
|
//* Adhere to the input's maxlength attr.
|
|
3628
3734
|
#cap(number) {
|
|
@@ -3829,7 +3935,7 @@ var _factory = (() => {
|
|
|
3829
3935
|
//* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
|
|
3830
3936
|
#getNewCountryFromNumber(fullNumber) {
|
|
3831
3937
|
const plusIndex = fullNumber.indexOf("+");
|
|
3832
|
-
let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
|
|
3938
|
+
let number = plusIndex > 0 ? fullNumber.substring(plusIndex) : fullNumber;
|
|
3833
3939
|
const selectedIso2 = this.#selectedCountryData?.iso2;
|
|
3834
3940
|
const selectedDialCode = this.#selectedCountryData?.dialCode;
|
|
3835
3941
|
number = this.#ensureHasDialCode(number);
|
|
@@ -3897,33 +4003,34 @@ var _factory = (() => {
|
|
|
3897
4003
|
//* Update the maximum valid number length for the currently selected country.
|
|
3898
4004
|
#updateMaxLength() {
|
|
3899
4005
|
const { strictMode, placeholderNumberType, allowedNumberTypes } = this.#options;
|
|
4006
|
+
if (!strictMode || !intlTelInput.utils) {
|
|
4007
|
+
return;
|
|
4008
|
+
}
|
|
3900
4009
|
const iso2 = this.#selectedCountryData?.iso2;
|
|
3901
|
-
if (
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
this.#maxCoreNumberLength = null;
|
|
3926
|
-
}
|
|
4010
|
+
if (!iso2) {
|
|
4011
|
+
this.#maxCoreNumberLength = null;
|
|
4012
|
+
return;
|
|
4013
|
+
}
|
|
4014
|
+
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
4015
|
+
let exampleNumber = intlTelInput.utils.getExampleNumber(
|
|
4016
|
+
iso2,
|
|
4017
|
+
false,
|
|
4018
|
+
numberType,
|
|
4019
|
+
true
|
|
4020
|
+
);
|
|
4021
|
+
let validNumber = exampleNumber;
|
|
4022
|
+
while (intlTelInput.utils.isPossibleNumber(
|
|
4023
|
+
exampleNumber,
|
|
4024
|
+
iso2,
|
|
4025
|
+
allowedNumberTypes
|
|
4026
|
+
)) {
|
|
4027
|
+
validNumber = exampleNumber;
|
|
4028
|
+
exampleNumber += "0";
|
|
4029
|
+
}
|
|
4030
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
|
|
4031
|
+
this.#maxCoreNumberLength = coreNumber.length;
|
|
4032
|
+
if (iso2 === "by") {
|
|
4033
|
+
this.#maxCoreNumberLength = coreNumber.length + 1;
|
|
3927
4034
|
}
|
|
3928
4035
|
}
|
|
3929
4036
|
//* Update the input placeholder to an example number from the currently selected country.
|
|
@@ -3935,19 +4042,20 @@ var _factory = (() => {
|
|
|
3935
4042
|
customPlaceholder
|
|
3936
4043
|
} = this.#options;
|
|
3937
4044
|
const shouldSetPlaceholder = autoPlaceholder === PLACEHOLDER_MODES.AGGRESSIVE || !this.#ui.hadInitialPlaceholder && autoPlaceholder === PLACEHOLDER_MODES.POLITE;
|
|
3938
|
-
if (intlTelInput.utils
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
4045
|
+
if (!intlTelInput.utils || !shouldSetPlaceholder) {
|
|
4046
|
+
return;
|
|
4047
|
+
}
|
|
4048
|
+
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
4049
|
+
let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
|
|
4050
|
+
this.#selectedCountryData.iso2,
|
|
4051
|
+
nationalMode,
|
|
4052
|
+
numberType
|
|
4053
|
+
) : "";
|
|
4054
|
+
placeholder = this.#beforeSetNumber(placeholder);
|
|
4055
|
+
if (typeof customPlaceholder === "function") {
|
|
4056
|
+
placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
|
|
3950
4057
|
}
|
|
4058
|
+
this.#ui.telInput.setAttribute("placeholder", placeholder);
|
|
3951
4059
|
}
|
|
3952
4060
|
//* Called when the user selects a list item from the dropdown.
|
|
3953
4061
|
#selectListItem(listItem) {
|
|
@@ -3979,46 +4087,49 @@ var _factory = (() => {
|
|
|
3979
4087
|
//* Note: called from _selectListItem and setCountry
|
|
3980
4088
|
#updateDialCode(newDialCodeBare) {
|
|
3981
4089
|
const inputVal = this.#getTelInputValue();
|
|
4090
|
+
if (!inputVal.startsWith("+")) {
|
|
4091
|
+
return;
|
|
4092
|
+
}
|
|
3982
4093
|
const newDialCode = `+${newDialCodeBare}`;
|
|
4094
|
+
const prevDialCode = this.#getDialCode(inputVal);
|
|
3983
4095
|
let newNumber;
|
|
3984
|
-
if (
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
} else {
|
|
3989
|
-
newNumber = newDialCode;
|
|
3990
|
-
}
|
|
3991
|
-
this.#setTelInputValue(newNumber);
|
|
4096
|
+
if (prevDialCode) {
|
|
4097
|
+
newNumber = inputVal.replace(prevDialCode, newDialCode);
|
|
4098
|
+
} else {
|
|
4099
|
+
newNumber = newDialCode;
|
|
3992
4100
|
}
|
|
4101
|
+
this.#setTelInputValue(newNumber);
|
|
3993
4102
|
}
|
|
3994
4103
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
3995
4104
|
//* Note: returns the raw string inc plus character and any whitespace/dots etc.
|
|
3996
4105
|
#getDialCode(number, includeAreaCode) {
|
|
4106
|
+
if (!number.startsWith("+")) {
|
|
4107
|
+
return "";
|
|
4108
|
+
}
|
|
3997
4109
|
let dialCode = "";
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
} else if (includeAreaCode && foundBaseDialCode) {
|
|
4016
|
-
dialCode = number.substring(0, i + 1);
|
|
4017
|
-
}
|
|
4018
|
-
if (numericChars.length === this.#dialCodeMaxLen) {
|
|
4019
|
-
break;
|
|
4020
|
-
}
|
|
4110
|
+
let numericChars = "";
|
|
4111
|
+
let foundBaseDialCode = false;
|
|
4112
|
+
for (let i = 0; i < number.length; i++) {
|
|
4113
|
+
const c = number.charAt(i);
|
|
4114
|
+
if (!/[0-9]/.test(c)) {
|
|
4115
|
+
continue;
|
|
4116
|
+
}
|
|
4117
|
+
numericChars += c;
|
|
4118
|
+
const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
|
|
4119
|
+
if (!hasMapEntry) {
|
|
4120
|
+
break;
|
|
4121
|
+
}
|
|
4122
|
+
if (this.#dialCodes.has(numericChars)) {
|
|
4123
|
+
dialCode = number.substring(0, i + 1);
|
|
4124
|
+
foundBaseDialCode = true;
|
|
4125
|
+
if (!includeAreaCode) {
|
|
4126
|
+
break;
|
|
4021
4127
|
}
|
|
4128
|
+
} else if (includeAreaCode && foundBaseDialCode) {
|
|
4129
|
+
dialCode = number.substring(0, i + 1);
|
|
4130
|
+
}
|
|
4131
|
+
if (numericChars.length === this.#dialCodeMaxLen) {
|
|
4132
|
+
break;
|
|
4022
4133
|
}
|
|
4023
4134
|
}
|
|
4024
4135
|
return dialCode;
|
|
@@ -4066,18 +4177,19 @@ var _factory = (() => {
|
|
|
4066
4177
|
//**************************
|
|
4067
4178
|
//* Called when the geoip call returns.
|
|
4068
4179
|
#handleAutoCountry() {
|
|
4180
|
+
if (!this.#autoCountryDeferred || !intlTelInput.autoCountry) {
|
|
4181
|
+
return;
|
|
4182
|
+
}
|
|
4069
4183
|
if (this.#destroyed) {
|
|
4070
|
-
this.#autoCountryDeferred
|
|
4184
|
+
this.#autoCountryDeferred.resolve();
|
|
4071
4185
|
return;
|
|
4072
4186
|
}
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
this.setCountry(this.#defaultCountry);
|
|
4078
|
-
}
|
|
4079
|
-
this.#autoCountryDeferred?.resolve();
|
|
4187
|
+
this.#defaultCountry = intlTelInput.autoCountry;
|
|
4188
|
+
const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
|
|
4189
|
+
if (!hasSelectedCountryOrGlobe) {
|
|
4190
|
+
this.setCountry(this.#defaultCountry);
|
|
4080
4191
|
}
|
|
4192
|
+
this.#autoCountryDeferred.resolve();
|
|
4081
4193
|
}
|
|
4082
4194
|
//* Called when the geoip call fails or times out.
|
|
4083
4195
|
#handleAutoCountryFailure() {
|
|
@@ -4094,15 +4206,17 @@ var _factory = (() => {
|
|
|
4094
4206
|
this.#utilsScriptDeferred?.resolve();
|
|
4095
4207
|
return;
|
|
4096
4208
|
}
|
|
4097
|
-
if (intlTelInput.utils) {
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4209
|
+
if (!intlTelInput.utils) {
|
|
4210
|
+
this.#utilsScriptDeferred?.resolve();
|
|
4211
|
+
return;
|
|
4212
|
+
}
|
|
4213
|
+
const inputValue = this.#getTelInputValue();
|
|
4214
|
+
if (inputValue) {
|
|
4215
|
+
this.#updateValFromNumber(inputValue);
|
|
4216
|
+
}
|
|
4217
|
+
if (this.#selectedCountryData) {
|
|
4218
|
+
this.#updatePlaceholder();
|
|
4219
|
+
this.#updateMaxLength();
|
|
4106
4220
|
}
|
|
4107
4221
|
this.#utilsScriptDeferred?.resolve();
|
|
4108
4222
|
}
|
|
@@ -4244,7 +4358,9 @@ var _factory = (() => {
|
|
|
4244
4358
|
const hasAlphaChar = alphaCharPosition > -1;
|
|
4245
4359
|
if (hasAlphaChar) {
|
|
4246
4360
|
const selectedIso2 = this.#selectedCountryData?.iso2;
|
|
4247
|
-
const hasExtension = Boolean(
|
|
4361
|
+
const hasExtension = Boolean(
|
|
4362
|
+
intlTelInput.utils.getExtension(val, selectedIso2)
|
|
4363
|
+
);
|
|
4248
4364
|
if (hasExtension) {
|
|
4249
4365
|
return allowNumberExtensions;
|
|
4250
4366
|
}
|
|
@@ -4270,15 +4386,16 @@ var _factory = (() => {
|
|
|
4270
4386
|
}
|
|
4271
4387
|
const currentCountry = this.#selectedCountryData?.iso2;
|
|
4272
4388
|
const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
|
|
4273
|
-
if (isCountryChange) {
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
this.#
|
|
4389
|
+
if (!isCountryChange) {
|
|
4390
|
+
return;
|
|
4391
|
+
}
|
|
4392
|
+
this.#setCountry(iso2Lower);
|
|
4393
|
+
this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
|
|
4394
|
+
if (this.#options.formatOnDisplay) {
|
|
4395
|
+
const inputValue = this.#getTelInputValue();
|
|
4396
|
+
this.#updateValFromNumber(inputValue);
|
|
4281
4397
|
}
|
|
4398
|
+
this.#triggerCountryChange();
|
|
4282
4399
|
}
|
|
4283
4400
|
//* Set the input value and update the country.
|
|
4284
4401
|
setNumber(number) {
|
|
@@ -4416,7 +4533,7 @@ var _factory = (() => {
|
|
|
4416
4533
|
attachUtils,
|
|
4417
4534
|
startedLoadingUtilsScript: false,
|
|
4418
4535
|
startedLoadingAutoCountry: false,
|
|
4419
|
-
version: "27.0.
|
|
4536
|
+
version: "27.0.2"
|
|
4420
4537
|
}
|
|
4421
4538
|
);
|
|
4422
4539
|
var intl_tel_input_default = intlTelInput;
|