intl-tel-input 24.5.1 → 24.6.0
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/README.md +51 -12
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +10 -5
- package/build/js/intlTelInput.js +78 -46
- package/build/js/intlTelInput.min.js +2 -2
- package/build/js/intlTelInputWithUtils.js +75 -47
- package/build/js/intlTelInputWithUtils.min.js +2 -2
- package/package.json +6 -8
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +77 -45
- package/react/build/IntlTelInput.d.ts +10 -5
- package/react/build/IntlTelInput.js +77 -45
- package/react/build/IntlTelInputWithUtils.cjs +74 -46
- package/react/build/IntlTelInputWithUtils.js +74 -46
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +95 -74
- package/vue/build/IntlTelInputWithUtils.mjs +668 -651
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-tel-input",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.6.0",
|
|
4
4
|
"description": "A JavaScript plugin for entering and validating international telephone numbers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"international",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"author": "Jack O'Connor (http://jackocnr.com)",
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@babel/plugin-transform-modules-commonjs": "^7.25.7",
|
|
27
28
|
"@testing-library/jest-dom": "^6.4.6",
|
|
28
29
|
"@testing-library/user-event": "^14.5.2",
|
|
29
30
|
"@types/react": "^18.2.74",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
32
33
|
"@typescript-eslint/parser": "^8.1.0",
|
|
33
34
|
"@vitejs/plugin-vue": "^5.1.2",
|
|
35
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
34
36
|
"cspell": "^8.6.1",
|
|
35
37
|
"esbuild": "^0.23.0",
|
|
36
38
|
"eslint": "^8.57.0",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"grunt": "^1.6.1",
|
|
47
49
|
"grunt-bump": "^0.8.0",
|
|
48
50
|
"grunt-cli": "^1.2.0",
|
|
51
|
+
"grunt-contrib-connect": "^5.0.0",
|
|
49
52
|
"grunt-contrib-cssmin": "^5.0.0",
|
|
50
53
|
"grunt-contrib-jasmine": "^4.0.0",
|
|
51
54
|
"grunt-contrib-watch": "^1.1.0",
|
|
@@ -98,7 +101,8 @@
|
|
|
98
101
|
"build:img": "grunt img",
|
|
99
102
|
"build:react": "grunt react",
|
|
100
103
|
"build:vue": "grunt vue",
|
|
101
|
-
"vue:demo": "vite --config vue/demo/validation/vite.config.js"
|
|
104
|
+
"vue:demo": "vite --config vue/demo/validation/vite.config.js",
|
|
105
|
+
"server": "grunt test:interactive"
|
|
102
106
|
},
|
|
103
107
|
"style": "build/css/intlTelInput.css",
|
|
104
108
|
"main": "./build/js/intlTelInput.js",
|
|
@@ -150,11 +154,5 @@
|
|
|
150
154
|
"react/build/IntlTelInput.d.ts"
|
|
151
155
|
]
|
|
152
156
|
}
|
|
153
|
-
},
|
|
154
|
-
"jest": {
|
|
155
|
-
"moduleDirectories": [
|
|
156
|
-
"node_modules",
|
|
157
|
-
"build/js"
|
|
158
|
-
]
|
|
159
157
|
}
|
|
160
158
|
}
|
package/react/README.md
CHANGED
|
@@ -28,7 +28,7 @@ import "intl-tel-input/styles";
|
|
|
28
28
|
|
|
29
29
|
See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/validation/ValidationApp.tsx) for a more fleshed-out example of how to handle validation.
|
|
30
30
|
|
|
31
|
-
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.
|
|
31
|
+
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.6.0/build/js/utils.js"`.
|
|
32
32
|
|
|
33
33
|
## Props
|
|
34
34
|
Here's a list of all of the current props you can pass to the IntlTelInput React component.
|
|
@@ -1659,6 +1659,8 @@ var defaults = {
|
|
|
1659
1659
|
i18n: {},
|
|
1660
1660
|
//* Initial country.
|
|
1661
1661
|
initialCountry: "",
|
|
1662
|
+
//* Specify the path to the libphonenumber script to enable validation/formatting.
|
|
1663
|
+
loadUtilsOnInit: "",
|
|
1662
1664
|
//* National vs international formatting for numbers e.g. placeholders and displaying existing numbers.
|
|
1663
1665
|
nationalMode: true,
|
|
1664
1666
|
//* Display only these countries.
|
|
@@ -1679,7 +1681,7 @@ var defaults = {
|
|
|
1679
1681
|
navigator.userAgent
|
|
1680
1682
|
) || window.innerWidth <= 500
|
|
1681
1683
|
) : false,
|
|
1682
|
-
//*
|
|
1684
|
+
//* Deprecated! Use `loadUtilsOnInit` instead.
|
|
1683
1685
|
utilsScript: "",
|
|
1684
1686
|
//* The number type to enforce during validation.
|
|
1685
1687
|
validationNumberType: "MOBILE"
|
|
@@ -1741,9 +1743,9 @@ var createEl = (name, attrs, container) => {
|
|
|
1741
1743
|
}
|
|
1742
1744
|
return el;
|
|
1743
1745
|
};
|
|
1744
|
-
var forEachInstance = (method) => {
|
|
1746
|
+
var forEachInstance = (method, ...args) => {
|
|
1745
1747
|
const { instances } = intlTelInput;
|
|
1746
|
-
Object.values(instances).forEach((instance) => instance[method]());
|
|
1748
|
+
Object.values(instances).forEach((instance) => instance[method](...args));
|
|
1747
1749
|
};
|
|
1748
1750
|
var Iti = class {
|
|
1749
1751
|
constructor(input, customOptions = {}) {
|
|
@@ -2191,14 +2193,21 @@ var Iti = class {
|
|
|
2191
2193
|
}
|
|
2192
2194
|
//* Init many requests: utils script / geo ip lookup.
|
|
2193
2195
|
_initRequests() {
|
|
2194
|
-
|
|
2195
|
-
if (
|
|
2196
|
+
let { loadUtilsOnInit, utilsScript, initialCountry, geoIpLookup } = this.options;
|
|
2197
|
+
if (!loadUtilsOnInit && utilsScript) {
|
|
2198
|
+
console.warn("intl-tel-input: The `utilsScript` option is deprecated and will be removed in a future release! Please use the `loadUtilsOnInit` option instead.");
|
|
2199
|
+
loadUtilsOnInit = utilsScript;
|
|
2200
|
+
}
|
|
2201
|
+
if (loadUtilsOnInit && !intlTelInput.utils) {
|
|
2202
|
+
this._handlePageLoad = () => {
|
|
2203
|
+
window.removeEventListener("load", this._handlePageLoad);
|
|
2204
|
+
intlTelInput.loadUtils(loadUtilsOnInit)?.catch(() => {
|
|
2205
|
+
});
|
|
2206
|
+
};
|
|
2196
2207
|
if (intlTelInput.documentReady()) {
|
|
2197
|
-
|
|
2208
|
+
this._handlePageLoad();
|
|
2198
2209
|
} else {
|
|
2199
|
-
window.addEventListener("load",
|
|
2200
|
-
intlTelInput.loadUtils(utilsScript);
|
|
2201
|
-
});
|
|
2210
|
+
window.addEventListener("load", this._handlePageLoad);
|
|
2202
2211
|
}
|
|
2203
2212
|
} else {
|
|
2204
2213
|
this.resolveUtilsScriptPromise();
|
|
@@ -2295,13 +2304,17 @@ var Iti = class {
|
|
|
2295
2304
|
const isInitialPlus = !alreadyHasPlus && this.telInput.selectionStart === 0 && e.key === "+";
|
|
2296
2305
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2297
2306
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2298
|
-
const
|
|
2299
|
-
const
|
|
2300
|
-
const
|
|
2301
|
-
const
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2307
|
+
const newValue = value.slice(0, this.telInput.selectionStart) + e.key + value.slice(this.telInput.selectionEnd);
|
|
2308
|
+
const newFullNumber = this._getFullNumber(newValue);
|
|
2309
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(newFullNumber, this.selectedCountryData.iso2);
|
|
2310
|
+
const hasExceededMaxLength = this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength;
|
|
2311
|
+
let isChangingDialCode = false;
|
|
2312
|
+
if (alreadyHasPlus) {
|
|
2313
|
+
const currentCountry = this.selectedCountryData.iso2;
|
|
2314
|
+
const newCountry = this._getCountryFromNumber(newFullNumber);
|
|
2315
|
+
isChangingDialCode = newCountry !== currentCountry;
|
|
2316
|
+
}
|
|
2317
|
+
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
2305
2318
|
e.preventDefault();
|
|
2306
2319
|
}
|
|
2307
2320
|
}
|
|
@@ -2310,17 +2323,6 @@ var Iti = class {
|
|
|
2310
2323
|
this.telInput.addEventListener("keydown", this._handleKeydownEvent);
|
|
2311
2324
|
}
|
|
2312
2325
|
}
|
|
2313
|
-
_isChangingDialCode(char) {
|
|
2314
|
-
const value = this.telInput.value;
|
|
2315
|
-
if (value.charAt(0) === "+") {
|
|
2316
|
-
const currentCountry = this.selectedCountryData.iso2;
|
|
2317
|
-
const newValue = value.slice(0, this.telInput.selectionStart) + char + value.slice(this.telInput.selectionEnd);
|
|
2318
|
-
const newFullNumber = this._getFullNumber(newValue);
|
|
2319
|
-
const newCountry = this._getCountryFromNumber(newFullNumber);
|
|
2320
|
-
return newCountry !== currentCountry;
|
|
2321
|
-
}
|
|
2322
|
-
return false;
|
|
2323
|
-
}
|
|
2324
2326
|
//* Adhere to the input's maxlength attr.
|
|
2325
2327
|
_cap(number) {
|
|
2326
2328
|
const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
|
|
@@ -2664,22 +2666,26 @@ var Iti = class {
|
|
|
2664
2666
|
//* Update the maximum valid number length for the currently selected country.
|
|
2665
2667
|
_updateMaxLength() {
|
|
2666
2668
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
2669
|
+
const { iso2 } = this.selectedCountryData;
|
|
2667
2670
|
if (strictMode && intlTelInput.utils) {
|
|
2668
|
-
if (
|
|
2671
|
+
if (iso2) {
|
|
2669
2672
|
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
2670
2673
|
let exampleNumber = intlTelInput.utils.getExampleNumber(
|
|
2671
|
-
|
|
2674
|
+
iso2,
|
|
2672
2675
|
false,
|
|
2673
2676
|
numberType,
|
|
2674
2677
|
true
|
|
2675
2678
|
);
|
|
2676
2679
|
let validNumber = exampleNumber;
|
|
2677
|
-
while (intlTelInput.utils.isPossibleNumber(exampleNumber,
|
|
2680
|
+
while (intlTelInput.utils.isPossibleNumber(exampleNumber, iso2, validationNumberType)) {
|
|
2678
2681
|
validNumber = exampleNumber;
|
|
2679
2682
|
exampleNumber += "0";
|
|
2680
2683
|
}
|
|
2681
|
-
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber,
|
|
2684
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
|
|
2682
2685
|
this.maxCoreNumberLength = coreNumber.length;
|
|
2686
|
+
if (iso2 === "by") {
|
|
2687
|
+
this.maxCoreNumberLength = coreNumber.length + 1;
|
|
2688
|
+
}
|
|
2683
2689
|
} else {
|
|
2684
2690
|
this.maxCoreNumberLength = null;
|
|
2685
2691
|
}
|
|
@@ -2786,6 +2792,9 @@ var Iti = class {
|
|
|
2786
2792
|
this.dropdown.parentNode.removeChild(this.dropdown);
|
|
2787
2793
|
}
|
|
2788
2794
|
}
|
|
2795
|
+
if (this._handlePageLoad) {
|
|
2796
|
+
window.removeEventListener("load", this._handlePageLoad);
|
|
2797
|
+
}
|
|
2789
2798
|
this._trigger("close:countrydropdown");
|
|
2790
2799
|
}
|
|
2791
2800
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
@@ -3074,22 +3083,43 @@ var Iti = class {
|
|
|
3074
3083
|
}
|
|
3075
3084
|
}
|
|
3076
3085
|
};
|
|
3077
|
-
var loadUtils = (
|
|
3086
|
+
var loadUtils = (source) => {
|
|
3078
3087
|
if (!intlTelInput.utils && !intlTelInput.startedLoadingUtilsScript) {
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
import(
|
|
3088
|
+
let loadCall;
|
|
3089
|
+
if (typeof source === "string") {
|
|
3090
|
+
loadCall = import(
|
|
3082
3091
|
/* webpackIgnore: true */
|
|
3083
3092
|
/* @vite-ignore */
|
|
3084
|
-
|
|
3085
|
-
)
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
})
|
|
3093
|
+
source
|
|
3094
|
+
);
|
|
3095
|
+
} else if (typeof source === "function") {
|
|
3096
|
+
try {
|
|
3097
|
+
loadCall = source();
|
|
3098
|
+
if (!(loadCall instanceof Promise)) {
|
|
3099
|
+
throw new TypeError(`The function passed to loadUtils must return a promise for the utilities module, not ${typeof loadCall}`);
|
|
3100
|
+
}
|
|
3101
|
+
} catch (error) {
|
|
3102
|
+
return Promise.reject(error);
|
|
3103
|
+
}
|
|
3104
|
+
} else {
|
|
3105
|
+
return Promise.reject(new TypeError(`The argument passed to loadUtils must be a URL string or a function that returns a promise for the utilities module, not ${typeof source}`));
|
|
3106
|
+
}
|
|
3107
|
+
intlTelInput.startedLoadingUtilsScript = true;
|
|
3108
|
+
return loadCall.then((module2) => {
|
|
3109
|
+
const utils = module2?.default;
|
|
3110
|
+
if (!utils || typeof utils !== "object") {
|
|
3111
|
+
if (typeof source === "string") {
|
|
3112
|
+
throw new TypeError(`The module loaded from ${source} did not set utils as its default export.`);
|
|
3113
|
+
} else {
|
|
3114
|
+
throw new TypeError("The loader function passed to loadUtils did not resolve to a module object with utils as its default export.");
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
intlTelInput.utils = utils;
|
|
3118
|
+
forEachInstance("handleUtils");
|
|
3119
|
+
return true;
|
|
3120
|
+
}).catch((error) => {
|
|
3121
|
+
forEachInstance("rejectUtilsScriptPromise", error);
|
|
3122
|
+
throw error;
|
|
3093
3123
|
});
|
|
3094
3124
|
}
|
|
3095
3125
|
return null;
|
|
@@ -3116,7 +3146,9 @@ var intlTelInput = Object.assign(
|
|
|
3116
3146
|
//* A map from instance ID to instance object.
|
|
3117
3147
|
instances: {},
|
|
3118
3148
|
loadUtils,
|
|
3119
|
-
|
|
3149
|
+
startedLoadingUtilsScript: false,
|
|
3150
|
+
startedLoadingAutoCountry: false,
|
|
3151
|
+
version: "24.6.0"
|
|
3120
3152
|
}
|
|
3121
3153
|
);
|
|
3122
3154
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -286,6 +286,9 @@ declare module "intl-tel-input/i18n/en" {
|
|
|
286
286
|
declare module "intl-tel-input" {
|
|
287
287
|
import { Country } from "intl-tel-input/data";
|
|
288
288
|
import { I18n } from "intl-tel-input/i18n/types";
|
|
289
|
+
type UtilsLoader = () => Promise<{
|
|
290
|
+
default: ItiUtils;
|
|
291
|
+
}>;
|
|
289
292
|
interface IntlTelInputInterface {
|
|
290
293
|
(input: HTMLInputElement, options?: SomeOptions): Iti;
|
|
291
294
|
autoCountry?: string;
|
|
@@ -296,9 +299,9 @@ declare module "intl-tel-input" {
|
|
|
296
299
|
instances: {
|
|
297
300
|
[key: string]: Iti;
|
|
298
301
|
};
|
|
299
|
-
loadUtils: (
|
|
300
|
-
startedLoadingAutoCountry
|
|
301
|
-
startedLoadingUtilsScript
|
|
302
|
+
loadUtils: (source: string | UtilsLoader) => Promise<unknown> | null;
|
|
303
|
+
startedLoadingAutoCountry: boolean;
|
|
304
|
+
startedLoadingUtilsScript: boolean;
|
|
302
305
|
version: string | undefined;
|
|
303
306
|
utils?: ItiUtils;
|
|
304
307
|
}
|
|
@@ -345,6 +348,7 @@ declare module "intl-tel-input" {
|
|
|
345
348
|
}) | null;
|
|
346
349
|
i18n: I18n;
|
|
347
350
|
initialCountry: string;
|
|
351
|
+
loadUtilsOnInit: string | UtilsLoader;
|
|
348
352
|
nationalMode: boolean;
|
|
349
353
|
onlyCountries: string[];
|
|
350
354
|
placeholderNumberType: NumberType;
|
|
@@ -352,7 +356,8 @@ declare module "intl-tel-input" {
|
|
|
352
356
|
separateDialCode: boolean;
|
|
353
357
|
strictMode: boolean;
|
|
354
358
|
useFullscreenPopup: boolean;
|
|
355
|
-
|
|
359
|
+
/** @deprecated Please use the `loadUtilsOnInit` option. */
|
|
360
|
+
utilsScript: string | UtilsLoader;
|
|
356
361
|
validationNumberType: NumberType | null;
|
|
357
362
|
}
|
|
358
363
|
export type SomeOptions = Partial<AllOptions>;
|
|
@@ -400,6 +405,7 @@ declare module "intl-tel-input" {
|
|
|
400
405
|
private _handleClickOffToClose;
|
|
401
406
|
private _handleKeydownOnDropdown;
|
|
402
407
|
private _handleSearchChange;
|
|
408
|
+
private _handlePageLoad;
|
|
403
409
|
private resolveAutoCountryPromise;
|
|
404
410
|
private rejectAutoCountryPromise;
|
|
405
411
|
private resolveUtilsScriptPromise;
|
|
@@ -422,7 +428,6 @@ declare module "intl-tel-input" {
|
|
|
422
428
|
private _loadAutoCountry;
|
|
423
429
|
private _openDropdownWithPlus;
|
|
424
430
|
private _initTelInputListeners;
|
|
425
|
-
private _isChangingDialCode;
|
|
426
431
|
private _cap;
|
|
427
432
|
private _trigger;
|
|
428
433
|
private _openDropdown;
|
|
@@ -1623,6 +1623,8 @@ var defaults = {
|
|
|
1623
1623
|
i18n: {},
|
|
1624
1624
|
//* Initial country.
|
|
1625
1625
|
initialCountry: "",
|
|
1626
|
+
//* Specify the path to the libphonenumber script to enable validation/formatting.
|
|
1627
|
+
loadUtilsOnInit: "",
|
|
1626
1628
|
//* National vs international formatting for numbers e.g. placeholders and displaying existing numbers.
|
|
1627
1629
|
nationalMode: true,
|
|
1628
1630
|
//* Display only these countries.
|
|
@@ -1643,7 +1645,7 @@ var defaults = {
|
|
|
1643
1645
|
navigator.userAgent
|
|
1644
1646
|
) || window.innerWidth <= 500
|
|
1645
1647
|
) : false,
|
|
1646
|
-
//*
|
|
1648
|
+
//* Deprecated! Use `loadUtilsOnInit` instead.
|
|
1647
1649
|
utilsScript: "",
|
|
1648
1650
|
//* The number type to enforce during validation.
|
|
1649
1651
|
validationNumberType: "MOBILE"
|
|
@@ -1705,9 +1707,9 @@ var createEl = (name, attrs, container) => {
|
|
|
1705
1707
|
}
|
|
1706
1708
|
return el;
|
|
1707
1709
|
};
|
|
1708
|
-
var forEachInstance = (method) => {
|
|
1710
|
+
var forEachInstance = (method, ...args) => {
|
|
1709
1711
|
const { instances } = intlTelInput;
|
|
1710
|
-
Object.values(instances).forEach((instance) => instance[method]());
|
|
1712
|
+
Object.values(instances).forEach((instance) => instance[method](...args));
|
|
1711
1713
|
};
|
|
1712
1714
|
var Iti = class {
|
|
1713
1715
|
constructor(input, customOptions = {}) {
|
|
@@ -2155,14 +2157,21 @@ var Iti = class {
|
|
|
2155
2157
|
}
|
|
2156
2158
|
//* Init many requests: utils script / geo ip lookup.
|
|
2157
2159
|
_initRequests() {
|
|
2158
|
-
|
|
2159
|
-
if (
|
|
2160
|
+
let { loadUtilsOnInit, utilsScript, initialCountry, geoIpLookup } = this.options;
|
|
2161
|
+
if (!loadUtilsOnInit && utilsScript) {
|
|
2162
|
+
console.warn("intl-tel-input: The `utilsScript` option is deprecated and will be removed in a future release! Please use the `loadUtilsOnInit` option instead.");
|
|
2163
|
+
loadUtilsOnInit = utilsScript;
|
|
2164
|
+
}
|
|
2165
|
+
if (loadUtilsOnInit && !intlTelInput.utils) {
|
|
2166
|
+
this._handlePageLoad = () => {
|
|
2167
|
+
window.removeEventListener("load", this._handlePageLoad);
|
|
2168
|
+
intlTelInput.loadUtils(loadUtilsOnInit)?.catch(() => {
|
|
2169
|
+
});
|
|
2170
|
+
};
|
|
2160
2171
|
if (intlTelInput.documentReady()) {
|
|
2161
|
-
|
|
2172
|
+
this._handlePageLoad();
|
|
2162
2173
|
} else {
|
|
2163
|
-
window.addEventListener("load",
|
|
2164
|
-
intlTelInput.loadUtils(utilsScript);
|
|
2165
|
-
});
|
|
2174
|
+
window.addEventListener("load", this._handlePageLoad);
|
|
2166
2175
|
}
|
|
2167
2176
|
} else {
|
|
2168
2177
|
this.resolveUtilsScriptPromise();
|
|
@@ -2259,13 +2268,17 @@ var Iti = class {
|
|
|
2259
2268
|
const isInitialPlus = !alreadyHasPlus && this.telInput.selectionStart === 0 && e.key === "+";
|
|
2260
2269
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2261
2270
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2262
|
-
const
|
|
2263
|
-
const
|
|
2264
|
-
const
|
|
2265
|
-
const
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2271
|
+
const newValue = value.slice(0, this.telInput.selectionStart) + e.key + value.slice(this.telInput.selectionEnd);
|
|
2272
|
+
const newFullNumber = this._getFullNumber(newValue);
|
|
2273
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(newFullNumber, this.selectedCountryData.iso2);
|
|
2274
|
+
const hasExceededMaxLength = this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength;
|
|
2275
|
+
let isChangingDialCode = false;
|
|
2276
|
+
if (alreadyHasPlus) {
|
|
2277
|
+
const currentCountry = this.selectedCountryData.iso2;
|
|
2278
|
+
const newCountry = this._getCountryFromNumber(newFullNumber);
|
|
2279
|
+
isChangingDialCode = newCountry !== currentCountry;
|
|
2280
|
+
}
|
|
2281
|
+
if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
|
|
2269
2282
|
e.preventDefault();
|
|
2270
2283
|
}
|
|
2271
2284
|
}
|
|
@@ -2274,17 +2287,6 @@ var Iti = class {
|
|
|
2274
2287
|
this.telInput.addEventListener("keydown", this._handleKeydownEvent);
|
|
2275
2288
|
}
|
|
2276
2289
|
}
|
|
2277
|
-
_isChangingDialCode(char) {
|
|
2278
|
-
const value = this.telInput.value;
|
|
2279
|
-
if (value.charAt(0) === "+") {
|
|
2280
|
-
const currentCountry = this.selectedCountryData.iso2;
|
|
2281
|
-
const newValue = value.slice(0, this.telInput.selectionStart) + char + value.slice(this.telInput.selectionEnd);
|
|
2282
|
-
const newFullNumber = this._getFullNumber(newValue);
|
|
2283
|
-
const newCountry = this._getCountryFromNumber(newFullNumber);
|
|
2284
|
-
return newCountry !== currentCountry;
|
|
2285
|
-
}
|
|
2286
|
-
return false;
|
|
2287
|
-
}
|
|
2288
2290
|
//* Adhere to the input's maxlength attr.
|
|
2289
2291
|
_cap(number) {
|
|
2290
2292
|
const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
|
|
@@ -2628,22 +2630,26 @@ var Iti = class {
|
|
|
2628
2630
|
//* Update the maximum valid number length for the currently selected country.
|
|
2629
2631
|
_updateMaxLength() {
|
|
2630
2632
|
const { strictMode, placeholderNumberType, validationNumberType } = this.options;
|
|
2633
|
+
const { iso2 } = this.selectedCountryData;
|
|
2631
2634
|
if (strictMode && intlTelInput.utils) {
|
|
2632
|
-
if (
|
|
2635
|
+
if (iso2) {
|
|
2633
2636
|
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
2634
2637
|
let exampleNumber = intlTelInput.utils.getExampleNumber(
|
|
2635
|
-
|
|
2638
|
+
iso2,
|
|
2636
2639
|
false,
|
|
2637
2640
|
numberType,
|
|
2638
2641
|
true
|
|
2639
2642
|
);
|
|
2640
2643
|
let validNumber = exampleNumber;
|
|
2641
|
-
while (intlTelInput.utils.isPossibleNumber(exampleNumber,
|
|
2644
|
+
while (intlTelInput.utils.isPossibleNumber(exampleNumber, iso2, validationNumberType)) {
|
|
2642
2645
|
validNumber = exampleNumber;
|
|
2643
2646
|
exampleNumber += "0";
|
|
2644
2647
|
}
|
|
2645
|
-
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber,
|
|
2648
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
|
|
2646
2649
|
this.maxCoreNumberLength = coreNumber.length;
|
|
2650
|
+
if (iso2 === "by") {
|
|
2651
|
+
this.maxCoreNumberLength = coreNumber.length + 1;
|
|
2652
|
+
}
|
|
2647
2653
|
} else {
|
|
2648
2654
|
this.maxCoreNumberLength = null;
|
|
2649
2655
|
}
|
|
@@ -2750,6 +2756,9 @@ var Iti = class {
|
|
|
2750
2756
|
this.dropdown.parentNode.removeChild(this.dropdown);
|
|
2751
2757
|
}
|
|
2752
2758
|
}
|
|
2759
|
+
if (this._handlePageLoad) {
|
|
2760
|
+
window.removeEventListener("load", this._handlePageLoad);
|
|
2761
|
+
}
|
|
2753
2762
|
this._trigger("close:countrydropdown");
|
|
2754
2763
|
}
|
|
2755
2764
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
@@ -3038,22 +3047,43 @@ var Iti = class {
|
|
|
3038
3047
|
}
|
|
3039
3048
|
}
|
|
3040
3049
|
};
|
|
3041
|
-
var loadUtils = (
|
|
3050
|
+
var loadUtils = (source) => {
|
|
3042
3051
|
if (!intlTelInput.utils && !intlTelInput.startedLoadingUtilsScript) {
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
import(
|
|
3052
|
+
let loadCall;
|
|
3053
|
+
if (typeof source === "string") {
|
|
3054
|
+
loadCall = import(
|
|
3046
3055
|
/* webpackIgnore: true */
|
|
3047
3056
|
/* @vite-ignore */
|
|
3048
|
-
|
|
3049
|
-
)
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
})
|
|
3057
|
+
source
|
|
3058
|
+
);
|
|
3059
|
+
} else if (typeof source === "function") {
|
|
3060
|
+
try {
|
|
3061
|
+
loadCall = source();
|
|
3062
|
+
if (!(loadCall instanceof Promise)) {
|
|
3063
|
+
throw new TypeError(`The function passed to loadUtils must return a promise for the utilities module, not ${typeof loadCall}`);
|
|
3064
|
+
}
|
|
3065
|
+
} catch (error) {
|
|
3066
|
+
return Promise.reject(error);
|
|
3067
|
+
}
|
|
3068
|
+
} else {
|
|
3069
|
+
return Promise.reject(new TypeError(`The argument passed to loadUtils must be a URL string or a function that returns a promise for the utilities module, not ${typeof source}`));
|
|
3070
|
+
}
|
|
3071
|
+
intlTelInput.startedLoadingUtilsScript = true;
|
|
3072
|
+
return loadCall.then((module) => {
|
|
3073
|
+
const utils = module?.default;
|
|
3074
|
+
if (!utils || typeof utils !== "object") {
|
|
3075
|
+
if (typeof source === "string") {
|
|
3076
|
+
throw new TypeError(`The module loaded from ${source} did not set utils as its default export.`);
|
|
3077
|
+
} else {
|
|
3078
|
+
throw new TypeError("The loader function passed to loadUtils did not resolve to a module object with utils as its default export.");
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
intlTelInput.utils = utils;
|
|
3082
|
+
forEachInstance("handleUtils");
|
|
3083
|
+
return true;
|
|
3084
|
+
}).catch((error) => {
|
|
3085
|
+
forEachInstance("rejectUtilsScriptPromise", error);
|
|
3086
|
+
throw error;
|
|
3057
3087
|
});
|
|
3058
3088
|
}
|
|
3059
3089
|
return null;
|
|
@@ -3080,7 +3110,9 @@ var intlTelInput = Object.assign(
|
|
|
3080
3110
|
//* A map from instance ID to instance object.
|
|
3081
3111
|
instances: {},
|
|
3082
3112
|
loadUtils,
|
|
3083
|
-
|
|
3113
|
+
startedLoadingUtilsScript: false,
|
|
3114
|
+
startedLoadingAutoCountry: false,
|
|
3115
|
+
version: "24.6.0"
|
|
3084
3116
|
}
|
|
3085
3117
|
);
|
|
3086
3118
|
var intl_tel_input_default = intlTelInput;
|