intl-tel-input 20.3.0 → 21.0.1
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 +29 -30
- package/build/css/demo.css +4 -4
- package/build/css/intlTelInput.css +78 -46
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +1360 -31
- package/build/js/data.min.js +16 -2
- package/build/js/intlTelInput.d.ts +450 -0
- package/build/js/intlTelInput.js +2865 -1678
- package/build/js/intlTelInput.min.js +16 -2
- package/build/js/utils.js +14 -14
- package/package.json +24 -21
- package/react/build/IntlTelInput.d.ts +512 -0
- package/react/build/IntlTelInput.js +1 -0
- package/build/js/intlTelInput-jquery.js +0 -1720
- package/build/js/intlTelInput-jquery.min.js +0 -6
- package/react/build/IntlTelInput.cjs.js +0 -2
- package/react/build/IntlTelInput.cjs.js.map +0 -7
- package/react/build/IntlTelInput.esm.js +0 -2
- package/react/build/IntlTelInput.esm.js.map +0 -7
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
declare module "src/js/data" {
|
|
2
|
+
global {
|
|
3
|
+
type Country = {
|
|
4
|
+
name: string;
|
|
5
|
+
iso2: string;
|
|
6
|
+
dialCode: string;
|
|
7
|
+
priority: number;
|
|
8
|
+
areaCodes: string[] | null;
|
|
9
|
+
nodeById: object;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const allCountries: Country[];
|
|
13
|
+
export default allCountries;
|
|
14
|
+
}
|
|
15
|
+
declare module "src/js/intlTelInput" {
|
|
16
|
+
type Globals = {
|
|
17
|
+
autoCountry?: string;
|
|
18
|
+
defaults: AllOptions;
|
|
19
|
+
documentReady: () => boolean;
|
|
20
|
+
getCountryData: () => Country[];
|
|
21
|
+
getInstance: (input: HTMLInputElement) => Iti | null;
|
|
22
|
+
instances: {
|
|
23
|
+
[key: string]: Iti;
|
|
24
|
+
};
|
|
25
|
+
loadUtils: (path: string) => Promise<unknown> | null;
|
|
26
|
+
startedLoadingAutoCountry?: boolean;
|
|
27
|
+
startedLoadingUtilsScript?: boolean;
|
|
28
|
+
version: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
type Utils = {
|
|
31
|
+
formatNumber(number: string, iso2: string | undefined, format?: number): string;
|
|
32
|
+
formatNumberAsYouType(number: string, iso2: string | undefined): string;
|
|
33
|
+
getCoreNumber(number: string, iso2: string | undefined): string;
|
|
34
|
+
getExampleNumber(iso2: string | undefined, nationalMode: boolean, numberType: number, useE164?: boolean): string;
|
|
35
|
+
getExtension(number: string, iso2: string | undefined): string;
|
|
36
|
+
getNumberType: (number: string, iso2: string | undefined) => number;
|
|
37
|
+
getValidationError(number: string, iso2: string | undefined): number;
|
|
38
|
+
isPossibleNumber(number: string, iso2: string | undefined, mobileOnly?: boolean): boolean;
|
|
39
|
+
isValidNumber: (number: string, iso2: string | undefined) => boolean;
|
|
40
|
+
numberFormat: {
|
|
41
|
+
NATIONAL: number;
|
|
42
|
+
INTERNATIONAL: number;
|
|
43
|
+
E164: number;
|
|
44
|
+
RFC3966: number;
|
|
45
|
+
};
|
|
46
|
+
numberType: object;
|
|
47
|
+
};
|
|
48
|
+
global {
|
|
49
|
+
interface Window {
|
|
50
|
+
intlTelInputGlobals: Globals;
|
|
51
|
+
intlTelInputUtils: Utils;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
type NumberType = "FIXED_LINE_OR_MOBILE" | "FIXED_LINE" | "MOBILE" | "PAGER" | "PERSONAL_NUMBER" | "PREMIUM_RATE" | "SHARED_COST" | "TOLL_FREE" | "UAN" | "UNKNOWN" | "VOICEMAIL" | "VOIP";
|
|
55
|
+
type SelectedCountryData = Country | {
|
|
56
|
+
name?: string;
|
|
57
|
+
iso2?: string;
|
|
58
|
+
dialCode?: string;
|
|
59
|
+
};
|
|
60
|
+
interface AllOptions {
|
|
61
|
+
allowDropdown: boolean;
|
|
62
|
+
autoPlaceholder: string;
|
|
63
|
+
containerClass: string;
|
|
64
|
+
countrySearch: boolean;
|
|
65
|
+
customPlaceholder: ((selectedCountryPlaceholder: string, selectedCountryData: object) => string) | null;
|
|
66
|
+
dropdownContainer: HTMLElement | null;
|
|
67
|
+
excludeCountries: string[];
|
|
68
|
+
fixDropdownWidth: boolean;
|
|
69
|
+
formatAsYouType: boolean;
|
|
70
|
+
formatOnDisplay: boolean;
|
|
71
|
+
geoIpLookup: ((success: (iso2: string) => void, failure: () => void) => void) | null;
|
|
72
|
+
hiddenInput: ((telInputName: string) => {
|
|
73
|
+
phone: string;
|
|
74
|
+
country?: string;
|
|
75
|
+
}) | null;
|
|
76
|
+
i18n: {
|
|
77
|
+
af?: string;
|
|
78
|
+
al?: string;
|
|
79
|
+
dz?: string;
|
|
80
|
+
as?: string;
|
|
81
|
+
ad?: string;
|
|
82
|
+
ao?: string;
|
|
83
|
+
ai?: string;
|
|
84
|
+
ag?: string;
|
|
85
|
+
ar?: string;
|
|
86
|
+
am?: string;
|
|
87
|
+
aw?: string;
|
|
88
|
+
ac?: string;
|
|
89
|
+
au?: string;
|
|
90
|
+
at?: string;
|
|
91
|
+
az?: string;
|
|
92
|
+
bs?: string;
|
|
93
|
+
bh?: string;
|
|
94
|
+
bd?: string;
|
|
95
|
+
bb?: string;
|
|
96
|
+
by?: string;
|
|
97
|
+
be?: string;
|
|
98
|
+
bz?: string;
|
|
99
|
+
bj?: string;
|
|
100
|
+
bm?: string;
|
|
101
|
+
bt?: string;
|
|
102
|
+
bo?: string;
|
|
103
|
+
ba?: string;
|
|
104
|
+
bw?: string;
|
|
105
|
+
br?: string;
|
|
106
|
+
io?: string;
|
|
107
|
+
vg?: string;
|
|
108
|
+
bn?: string;
|
|
109
|
+
bg?: string;
|
|
110
|
+
bf?: string;
|
|
111
|
+
bi?: string;
|
|
112
|
+
kh?: string;
|
|
113
|
+
cm?: string;
|
|
114
|
+
ca?: string;
|
|
115
|
+
cv?: string;
|
|
116
|
+
bq?: string;
|
|
117
|
+
ky?: string;
|
|
118
|
+
cf?: string;
|
|
119
|
+
td?: string;
|
|
120
|
+
cl?: string;
|
|
121
|
+
cn?: string;
|
|
122
|
+
cx?: string;
|
|
123
|
+
cc?: string;
|
|
124
|
+
co?: string;
|
|
125
|
+
km?: string;
|
|
126
|
+
cg?: string;
|
|
127
|
+
cd?: string;
|
|
128
|
+
ck?: string;
|
|
129
|
+
cr?: string;
|
|
130
|
+
hr?: string;
|
|
131
|
+
cu?: string;
|
|
132
|
+
cw?: string;
|
|
133
|
+
cy?: string;
|
|
134
|
+
cz?: string;
|
|
135
|
+
ci?: string;
|
|
136
|
+
dk?: string;
|
|
137
|
+
dj?: string;
|
|
138
|
+
dm?: string;
|
|
139
|
+
do?: string;
|
|
140
|
+
ec?: string;
|
|
141
|
+
eg?: string;
|
|
142
|
+
sv?: string;
|
|
143
|
+
gq?: string;
|
|
144
|
+
er?: string;
|
|
145
|
+
ee?: string;
|
|
146
|
+
sz?: string;
|
|
147
|
+
et?: string;
|
|
148
|
+
fk?: string;
|
|
149
|
+
fo?: string;
|
|
150
|
+
fj?: string;
|
|
151
|
+
fi?: string;
|
|
152
|
+
fr?: string;
|
|
153
|
+
gf?: string;
|
|
154
|
+
pf?: string;
|
|
155
|
+
ga?: string;
|
|
156
|
+
gm?: string;
|
|
157
|
+
ge?: string;
|
|
158
|
+
de?: string;
|
|
159
|
+
gh?: string;
|
|
160
|
+
gi?: string;
|
|
161
|
+
gr?: string;
|
|
162
|
+
gl?: string;
|
|
163
|
+
gd?: string;
|
|
164
|
+
gp?: string;
|
|
165
|
+
gu?: string;
|
|
166
|
+
gt?: string;
|
|
167
|
+
gg?: string;
|
|
168
|
+
gn?: string;
|
|
169
|
+
gw?: string;
|
|
170
|
+
gy?: string;
|
|
171
|
+
ht?: string;
|
|
172
|
+
hn?: string;
|
|
173
|
+
hk?: string;
|
|
174
|
+
hu?: string;
|
|
175
|
+
is?: string;
|
|
176
|
+
in?: string;
|
|
177
|
+
id?: string;
|
|
178
|
+
ir?: string;
|
|
179
|
+
iq?: string;
|
|
180
|
+
ie?: string;
|
|
181
|
+
im?: string;
|
|
182
|
+
il?: string;
|
|
183
|
+
it?: string;
|
|
184
|
+
jm?: string;
|
|
185
|
+
jp?: string;
|
|
186
|
+
je?: string;
|
|
187
|
+
jo?: string;
|
|
188
|
+
kz?: string;
|
|
189
|
+
ke?: string;
|
|
190
|
+
ki?: string;
|
|
191
|
+
xk?: string;
|
|
192
|
+
kw?: string;
|
|
193
|
+
kg?: string;
|
|
194
|
+
la?: string;
|
|
195
|
+
lv?: string;
|
|
196
|
+
lb?: string;
|
|
197
|
+
ls?: string;
|
|
198
|
+
lr?: string;
|
|
199
|
+
ly?: string;
|
|
200
|
+
li?: string;
|
|
201
|
+
lt?: string;
|
|
202
|
+
lu?: string;
|
|
203
|
+
mo?: string;
|
|
204
|
+
mg?: string;
|
|
205
|
+
mw?: string;
|
|
206
|
+
my?: string;
|
|
207
|
+
mv?: string;
|
|
208
|
+
ml?: string;
|
|
209
|
+
mt?: string;
|
|
210
|
+
mh?: string;
|
|
211
|
+
mq?: string;
|
|
212
|
+
mr?: string;
|
|
213
|
+
mu?: string;
|
|
214
|
+
yt?: string;
|
|
215
|
+
mx?: string;
|
|
216
|
+
fm?: string;
|
|
217
|
+
md?: string;
|
|
218
|
+
mc?: string;
|
|
219
|
+
mn?: string;
|
|
220
|
+
me?: string;
|
|
221
|
+
ms?: string;
|
|
222
|
+
ma?: string;
|
|
223
|
+
mz?: string;
|
|
224
|
+
mm?: string;
|
|
225
|
+
na?: string;
|
|
226
|
+
nr?: string;
|
|
227
|
+
np?: string;
|
|
228
|
+
nl?: string;
|
|
229
|
+
nc?: string;
|
|
230
|
+
nz?: string;
|
|
231
|
+
ni?: string;
|
|
232
|
+
ne?: string;
|
|
233
|
+
ng?: string;
|
|
234
|
+
nu?: string;
|
|
235
|
+
nf?: string;
|
|
236
|
+
kp?: string;
|
|
237
|
+
mk?: string;
|
|
238
|
+
mp?: string;
|
|
239
|
+
no?: string;
|
|
240
|
+
om?: string;
|
|
241
|
+
pk?: string;
|
|
242
|
+
pw?: string;
|
|
243
|
+
ps?: string;
|
|
244
|
+
pa?: string;
|
|
245
|
+
pg?: string;
|
|
246
|
+
py?: string;
|
|
247
|
+
pe?: string;
|
|
248
|
+
ph?: string;
|
|
249
|
+
pl?: string;
|
|
250
|
+
pt?: string;
|
|
251
|
+
pr?: string;
|
|
252
|
+
qa?: string;
|
|
253
|
+
ro?: string;
|
|
254
|
+
ru?: string;
|
|
255
|
+
rw?: string;
|
|
256
|
+
re?: string;
|
|
257
|
+
ws?: string;
|
|
258
|
+
sm?: string;
|
|
259
|
+
sa?: string;
|
|
260
|
+
sn?: string;
|
|
261
|
+
rs?: string;
|
|
262
|
+
sc?: string;
|
|
263
|
+
sl?: string;
|
|
264
|
+
sg?: string;
|
|
265
|
+
sx?: string;
|
|
266
|
+
sk?: string;
|
|
267
|
+
si?: string;
|
|
268
|
+
sb?: string;
|
|
269
|
+
so?: string;
|
|
270
|
+
za?: string;
|
|
271
|
+
kr?: string;
|
|
272
|
+
ss?: string;
|
|
273
|
+
es?: string;
|
|
274
|
+
lk?: string;
|
|
275
|
+
bl?: string;
|
|
276
|
+
sh?: string;
|
|
277
|
+
kn?: string;
|
|
278
|
+
lc?: string;
|
|
279
|
+
mf?: string;
|
|
280
|
+
pm?: string;
|
|
281
|
+
vc?: string;
|
|
282
|
+
sd?: string;
|
|
283
|
+
sr?: string;
|
|
284
|
+
sj?: string;
|
|
285
|
+
se?: string;
|
|
286
|
+
ch?: string;
|
|
287
|
+
sy?: string;
|
|
288
|
+
st?: string;
|
|
289
|
+
tw?: string;
|
|
290
|
+
tj?: string;
|
|
291
|
+
tz?: string;
|
|
292
|
+
th?: string;
|
|
293
|
+
tl?: string;
|
|
294
|
+
tg?: string;
|
|
295
|
+
tk?: string;
|
|
296
|
+
to?: string;
|
|
297
|
+
tt?: string;
|
|
298
|
+
tn?: string;
|
|
299
|
+
tr?: string;
|
|
300
|
+
tm?: string;
|
|
301
|
+
tc?: string;
|
|
302
|
+
tv?: string;
|
|
303
|
+
vi?: string;
|
|
304
|
+
ug?: string;
|
|
305
|
+
ua?: string;
|
|
306
|
+
ae?: string;
|
|
307
|
+
gb?: string;
|
|
308
|
+
us?: string;
|
|
309
|
+
uy?: string;
|
|
310
|
+
uz?: string;
|
|
311
|
+
vu?: string;
|
|
312
|
+
va?: string;
|
|
313
|
+
ve?: string;
|
|
314
|
+
vn?: string;
|
|
315
|
+
wf?: string;
|
|
316
|
+
eh?: string;
|
|
317
|
+
ye?: string;
|
|
318
|
+
zm?: string;
|
|
319
|
+
zw?: string;
|
|
320
|
+
ax?: string;
|
|
321
|
+
selectedCountryAriaLabel?: string;
|
|
322
|
+
searchPlaceholder?: string;
|
|
323
|
+
countryListAriaLabel?: string;
|
|
324
|
+
oneSearchResult?: string;
|
|
325
|
+
multipleSearchResults?: string;
|
|
326
|
+
noCountrySelected?: string;
|
|
327
|
+
zeroSearchResults?: string;
|
|
328
|
+
};
|
|
329
|
+
initialCountry: string;
|
|
330
|
+
nationalMode: boolean;
|
|
331
|
+
onlyCountries: string[];
|
|
332
|
+
placeholderNumberType: NumberType;
|
|
333
|
+
preferredCountries: string[];
|
|
334
|
+
showFlags: boolean;
|
|
335
|
+
showSelectedDialCode: boolean;
|
|
336
|
+
strictMode: boolean;
|
|
337
|
+
useFullscreenPopup: boolean;
|
|
338
|
+
utilsScript: string;
|
|
339
|
+
}
|
|
340
|
+
global {
|
|
341
|
+
type SomeOptions = Partial<AllOptions>;
|
|
342
|
+
}
|
|
343
|
+
export class Iti {
|
|
344
|
+
id: number;
|
|
345
|
+
promise: Promise<[unknown, unknown]>;
|
|
346
|
+
private telInput;
|
|
347
|
+
private activeItem;
|
|
348
|
+
private highlightedItem;
|
|
349
|
+
private options;
|
|
350
|
+
private hadInitialPlaceholder;
|
|
351
|
+
private isRTL;
|
|
352
|
+
private selectedCountryData;
|
|
353
|
+
private countries;
|
|
354
|
+
private dialCodeMaxLen;
|
|
355
|
+
private dialCodeToIso2Map;
|
|
356
|
+
private dialCodes;
|
|
357
|
+
private preferredCountries;
|
|
358
|
+
private countryContainer;
|
|
359
|
+
private selectedCountry;
|
|
360
|
+
private selectedCountryInner;
|
|
361
|
+
private selectedCountryA11yText;
|
|
362
|
+
private selectedDialCode;
|
|
363
|
+
private dropdownArrow;
|
|
364
|
+
private dropdownContent;
|
|
365
|
+
private searchInput;
|
|
366
|
+
private searchResultsA11yText;
|
|
367
|
+
private countryList;
|
|
368
|
+
private dropdown;
|
|
369
|
+
private hiddenInput;
|
|
370
|
+
private hiddenInputCountry;
|
|
371
|
+
private maxCoreNumberLength;
|
|
372
|
+
private defaultCountry;
|
|
373
|
+
private _handleHiddenInputSubmit;
|
|
374
|
+
private _handleLabelClick;
|
|
375
|
+
private _handleClickSelectedCountry;
|
|
376
|
+
private _handleCountryContainerKeydown;
|
|
377
|
+
private _handleInputEvent;
|
|
378
|
+
private _handleKeydownEvent;
|
|
379
|
+
private _handleWindowScroll;
|
|
380
|
+
private _handleMouseoverCountryList;
|
|
381
|
+
private _handleClickCountryList;
|
|
382
|
+
private _handleClickOffToClose;
|
|
383
|
+
private _handleKeydownOnDropdown;
|
|
384
|
+
private _handleSearchChange;
|
|
385
|
+
private resolveAutoCountryPromise;
|
|
386
|
+
private rejectAutoCountryPromise;
|
|
387
|
+
private resolveUtilsScriptPromise;
|
|
388
|
+
private rejectUtilsScriptPromise;
|
|
389
|
+
constructor(input: HTMLInputElement, customOptions?: SomeOptions);
|
|
390
|
+
_init(): void;
|
|
391
|
+
private _processCountryData;
|
|
392
|
+
private _addToDialCodeMap;
|
|
393
|
+
private _processAllCountries;
|
|
394
|
+
private _translateCountryNames;
|
|
395
|
+
private _processDialCodes;
|
|
396
|
+
private _processPreferredCountries;
|
|
397
|
+
private _generateMarkup;
|
|
398
|
+
private _appendListItems;
|
|
399
|
+
private _setInitialState;
|
|
400
|
+
private _initListeners;
|
|
401
|
+
private _initHiddenInputListener;
|
|
402
|
+
private _initDropdownListeners;
|
|
403
|
+
private _initRequests;
|
|
404
|
+
private _loadAutoCountry;
|
|
405
|
+
private _initTelInputListeners;
|
|
406
|
+
private _cap;
|
|
407
|
+
private _trigger;
|
|
408
|
+
private _openDropdown;
|
|
409
|
+
private _setDropdownPosition;
|
|
410
|
+
private _bindDropdownListeners;
|
|
411
|
+
private _filterCountries;
|
|
412
|
+
private _updateSearchResultsText;
|
|
413
|
+
private _handleUpDownKey;
|
|
414
|
+
private _handleEnterKey;
|
|
415
|
+
private _searchForCountry;
|
|
416
|
+
private _updateValFromNumber;
|
|
417
|
+
private _updateCountryFromNumber;
|
|
418
|
+
private _highlightListItem;
|
|
419
|
+
private _getCountryData;
|
|
420
|
+
private _setCountry;
|
|
421
|
+
private _updateMaxLength;
|
|
422
|
+
private _setSelectedCountryTitleAttribute;
|
|
423
|
+
private _getHiddenSelectedCountryWidth;
|
|
424
|
+
private _updatePlaceholder;
|
|
425
|
+
private _selectListItem;
|
|
426
|
+
private _closeDropdown;
|
|
427
|
+
private _scrollTo;
|
|
428
|
+
private _updateDialCode;
|
|
429
|
+
private _getDialCode;
|
|
430
|
+
private _getFullNumber;
|
|
431
|
+
private _beforeSetNumber;
|
|
432
|
+
private _triggerCountryChange;
|
|
433
|
+
private _formatNumberAsYouType;
|
|
434
|
+
handleAutoCountry(): void;
|
|
435
|
+
handleUtils(): void;
|
|
436
|
+
destroy(): void;
|
|
437
|
+
getExtension(): string;
|
|
438
|
+
getNumber(format?: number): string;
|
|
439
|
+
getNumberType(): number;
|
|
440
|
+
getSelectedCountryData(): SelectedCountryData;
|
|
441
|
+
getValidationError(): number;
|
|
442
|
+
isValidNumber(mobileOnly?: boolean): boolean | null;
|
|
443
|
+
isValidNumberPrecise(): boolean | null;
|
|
444
|
+
setCountry(iso2: string): void;
|
|
445
|
+
setNumber(number: string): void;
|
|
446
|
+
setPlaceholderNumberType(type: NumberType): void;
|
|
447
|
+
}
|
|
448
|
+
const intlTelInput: (input: HTMLInputElement, options?: SomeOptions) => Iti;
|
|
449
|
+
export default intlTelInput;
|
|
450
|
+
}
|
|
451
|
+
declare module "react/src/IntlTelInput" {
|
|
452
|
+
import { ReactElement } from "react";
|
|
453
|
+
import PropTypes from "prop-types";
|
|
454
|
+
const IntlTelInput: {
|
|
455
|
+
({ initialValue, onChangeNumber, onChangeCountry, onChangeValidity, onChangeErrorCode, usePreciseValidation, initOptions, inputProps, }: {
|
|
456
|
+
initialValue: string;
|
|
457
|
+
onChangeNumber: (number: string) => void;
|
|
458
|
+
onChangeCountry: (country: string) => void;
|
|
459
|
+
onChangeValidity: (valid: boolean) => void;
|
|
460
|
+
onChangeErrorCode: (errorCode: number | null) => void;
|
|
461
|
+
usePreciseValidation: boolean;
|
|
462
|
+
initOptions: SomeOptions;
|
|
463
|
+
inputProps: object;
|
|
464
|
+
}): ReactElement;
|
|
465
|
+
propTypes: {
|
|
466
|
+
initialValue: PropTypes.Requireable<string>;
|
|
467
|
+
onChangeNumber: PropTypes.Requireable<(...args: any[]) => any>;
|
|
468
|
+
onChangeCountry: PropTypes.Requireable<(...args: any[]) => any>;
|
|
469
|
+
onChangeValidity: PropTypes.Requireable<(...args: any[]) => any>;
|
|
470
|
+
onChangeErrorCode: PropTypes.Requireable<(...args: any[]) => any>;
|
|
471
|
+
usePreciseValidation: PropTypes.Requireable<boolean>;
|
|
472
|
+
initOptions: PropTypes.Requireable<PropTypes.InferProps<{
|
|
473
|
+
allowDropdown: PropTypes.Requireable<boolean>;
|
|
474
|
+
autoPlaceholder: PropTypes.Requireable<string>;
|
|
475
|
+
containerClass: PropTypes.Requireable<string>;
|
|
476
|
+
countrySearch: PropTypes.Requireable<boolean>;
|
|
477
|
+
customPlaceholder: PropTypes.Requireable<(...args: any[]) => any>;
|
|
478
|
+
dropdownContainer: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
479
|
+
excludeCountries: PropTypes.Requireable<string[]>;
|
|
480
|
+
fixDropdownWidth: PropTypes.Requireable<boolean>;
|
|
481
|
+
formatAsYouType: PropTypes.Requireable<boolean>;
|
|
482
|
+
formatOnDisplay: PropTypes.Requireable<boolean>;
|
|
483
|
+
geoIpLookup: PropTypes.Requireable<(...args: any[]) => any>;
|
|
484
|
+
hiddenInput: PropTypes.Requireable<(...args: any[]) => any>;
|
|
485
|
+
i18n: PropTypes.Requireable<{
|
|
486
|
+
[x: string]: string;
|
|
487
|
+
}>;
|
|
488
|
+
initialCountry: PropTypes.Requireable<string>;
|
|
489
|
+
nationalMode: PropTypes.Requireable<boolean>;
|
|
490
|
+
onlyCountries: PropTypes.Requireable<string[]>;
|
|
491
|
+
placeholderNumberType: PropTypes.Requireable<string>;
|
|
492
|
+
preferredCountries: PropTypes.Requireable<string[]>;
|
|
493
|
+
showFlags: PropTypes.Requireable<boolean>;
|
|
494
|
+
showSelectedDialCode: PropTypes.Requireable<boolean>;
|
|
495
|
+
useFullscreenPopup: PropTypes.Requireable<boolean>;
|
|
496
|
+
utilsScript: PropTypes.Requireable<string>;
|
|
497
|
+
}>>;
|
|
498
|
+
inputProps: PropTypes.Requireable<object>;
|
|
499
|
+
};
|
|
500
|
+
defaultProps: {
|
|
501
|
+
initialValue: string;
|
|
502
|
+
onChangeNumber: () => void;
|
|
503
|
+
onChangeCountry: () => void;
|
|
504
|
+
onChangeValidity: () => void;
|
|
505
|
+
onChangeErrorCode: () => void;
|
|
506
|
+
usePreciseValidation: boolean;
|
|
507
|
+
initOptions: {};
|
|
508
|
+
inputProps: {};
|
|
509
|
+
};
|
|
510
|
+
};
|
|
511
|
+
export default IntlTelInput;
|
|
512
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import O,{useRef as D,useEffect as F}from"react";import u from"prop-types";var I=[["Afghanistan","af","93"],["Albania","al","355"],["Algeria","dz","213"],["American Samoa","as","1",5,["684"]],["Andorra","ad","376"],["Angola","ao","244"],["Anguilla","ai","1",6,["264"]],["Antigua & Barbuda","ag","1",7,["268"]],["Argentina","ar","54"],["Armenia","am","374"],["Aruba","aw","297"],["Ascension Island","ac","247"],["Australia","au","61",0],["Austria","at","43"],["Azerbaijan","az","994"],["Bahamas","bs","1",8,["242"]],["Bahrain","bh","973"],["Bangladesh","bd","880"],["Barbados","bb","1",9,["246"]],["Belarus","by","375"],["Belgium","be","32"],["Belize","bz","501"],["Benin","bj","229"],["Bermuda","bm","1",10,["441"]],["Bhutan","bt","975"],["Bolivia","bo","591"],["Bosnia & Herzegovina","ba","387"],["Botswana","bw","267"],["Brazil","br","55"],["British Indian Ocean Territory","io","246"],["British Virgin Islands","vg","1",11,["284"]],["Brunei","bn","673"],["Bulgaria","bg","359"],["Burkina Faso","bf","226"],["Burundi","bi","257"],["Cambodia","kh","855"],["Cameroon","cm","237"],["Canada","ca","1",1,["204","226","236","249","250","263","289","306","343","354","365","367","368","382","387","403","416","418","428","431","437","438","450","584","468","474","506","514","519","548","579","581","584","587","604","613","639","647","672","683","705","709","742","753","778","780","782","807","819","825","867","873","902","905"]],["Cape Verde","cv","238"],["Caribbean Netherlands","bq","599",1,["3","4","7"]],["Cayman Islands","ky","1",12,["345"]],["Central African Republic","cf","236"],["Chad","td","235"],["Chile","cl","56"],["China","cn","86"],["Christmas Island","cx","61",2,["89164"]],["Cocos (Keeling) Islands","cc","61",1,["89162"]],["Colombia","co","57"],["Comoros","km","269"],["Congo - Brazzaville","cg","242"],["Congo - Kinshasa","cd","243"],["Cook Islands","ck","682"],["Costa Rica","cr","506"],["C\xF4te d\u2019Ivoire","ci","225"],["Croatia","hr","385"],["Cuba","cu","53"],["Cura\xE7ao","cw","599",0],["Cyprus","cy","357"],["Czech Republic","cz","420"],["Denmark","dk","45"],["Djibouti","dj","253"],["Dominica","dm","1",13,["767"]],["Dominican Republic","do","1",2,["809","829","849"]],["Ecuador","ec","593"],["Egypt","eg","20"],["El Salvador","sv","503"],["Equatorial Guinea","gq","240"],["Eritrea","er","291"],["Estonia","ee","372"],["Eswatini","sz","268"],["Ethiopia","et","251"],["Falkland Islands","fk","500"],["Faroe Islands","fo","298"],["Fiji","fj","679"],["Finland","fi","358",0],["France","fr","33"],["French Guiana","gf","594"],["French Polynesia","pf","689"],["Gabon","ga","241"],["Gambia","gm","220"],["Georgia","ge","995"],["Germany","de","49"],["Ghana","gh","233"],["Gibraltar","gi","350"],["Greece","gr","30"],["Greenland","gl","299"],["Grenada","gd","1",14,["473"]],["Guadeloupe","gp","590",0],["Guam","gu","1",15,["671"]],["Guatemala","gt","502"],["Guernsey","gg","44",1,["1481","7781","7839","7911"]],["Guinea","gn","224"],["Guinea-Bissau","gw","245"],["Guyana","gy","592"],["Haiti","ht","509"],["Honduras","hn","504"],["Hong Kong","hk","852"],["Hungary","hu","36"],["Iceland","is","354"],["India","in","91"],["Indonesia","id","62"],["Iran","ir","98"],["Iraq","iq","964"],["Ireland","ie","353"],["Isle of Man","im","44",2,["1624","74576","7524","7924","7624"]],["Israel","il","972"],["Italy","it","39",0],["Jamaica","jm","1",4,["876","658"]],["Japan","jp","81"],["Jersey","je","44",3,["1534","7509","7700","7797","7829","7937"]],["Jordan","jo","962"],["Kazakhstan","kz","7",1,["33","7"]],["Kenya","ke","254"],["Kiribati","ki","686"],["Kosovo","xk","383"],["Kuwait","kw","965"],["Kyrgyzstan","kg","996"],["Laos","la","856"],["Latvia","lv","371"],["Lebanon","lb","961"],["Lesotho","ls","266"],["Liberia","lr","231"],["Libya","ly","218"],["Liechtenstein","li","423"],["Lithuania","lt","370"],["Luxembourg","lu","352"],["Macau","mo","853"],["Madagascar","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","mu","230"],["Mayotte","yt","262",1,["269","639"]],["Mexico","mx","52"],["Micronesia","fm","691"],["Moldova","md","373"],["Monaco","mc","377"],["Mongolia","mn","976"],["Montenegro","me","382"],["Montserrat","ms","1",16,["664"]],["Morocco","ma","212",0],["Mozambique","mz","258"],["Myanmar (Burma)","mm","95"],["Namibia","na","264"],["Nauru","nr","674"],["Nepal","np","977"],["Netherlands","nl","31"],["New Caledonia","nc","687"],["New Zealand","nz","64"],["Nicaragua","ni","505"],["Niger","ne","227"],["Nigeria","ng","234"],["Niue","nu","683"],["Norfolk Island","nf","672"],["North Korea","kp","850"],["North Macedonia","mk","389"],["Northern Mariana Islands","mp","1",17,["670"]],["Norway","no","47",0],["Oman","om","968"],["Pakistan","pk","92"],["Palau","pw","680"],["Palestine","ps","970"],["Panama","pa","507"],["Papua New Guinea","pg","675"],["Paraguay","py","595"],["Peru","pe","51"],["Philippines","ph","63"],["Poland","pl","48"],["Portugal","pt","351"],["Puerto Rico","pr","1",3,["787","939"]],["Qatar","qa","974"],["R\xE9union","re","262",0],["Romania","ro","40"],["Russia","ru","7",0],["Rwanda","rw","250"],["Samoa","ws","685"],["San Marino","sm","378"],["S\xE3o Tom\xE9 & Pr\xEDncipe","st","239"],["Saudi Arabia","sa","966"],["Senegal","sn","221"],["Serbia","rs","381"],["Seychelles","sc","248"],["Sierra Leone","sl","232"],["Singapore","sg","65"],["Sint Maarten","sx","1",21,["721"]],["Slovakia","sk","421"],["Slovenia","si","386"],["Solomon Islands","sb","677"],["Somalia","so","252"],["South Africa","za","27"],["South Korea","kr","82"],["South Sudan","ss","211"],["Spain","es","34"],["Sri Lanka","lk","94"],["St Barth\xE9lemy","bl","590",1],["St Helena","sh","290"],["St Kitts & Nevis","kn","1",18,["869"]],["St Lucia","lc","1",19,["758"]],["St Martin","mf","590",2],["St Pierre & Miquelon","pm","508"],["St Vincent & Grenadines","vc","1",20,["784"]],["Sudan","sd","249"],["Suriname","sr","597"],["Svalbard & Jan Mayen","sj","47",1,["79"]],["Sweden","se","46"],["Switzerland","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 & Tobago","tt","1",22,["868"]],["Tunisia","tn","216"],["Turkey","tr","90"],["Turkmenistan","tm","993"],["Turks & Caicos Islands","tc","1",23,["649"]],["Tuvalu","tv","688"],["Uganda","ug","256"],["Ukraine","ua","380"],["United Arab Emirates","ae","971"],["United Kingdom","gb","44",0],["United States","us","1",0],["Uruguay","uy","598"],["US Virgin Islands","vi","1",24,["340"]],["Uzbekistan","uz","998"],["Vanuatu","vu","678"],["Vatican City","va","39",1,["06698"]],["Venezuela","ve","58"],["Vietnam","vn","84"],["Wallis & Futuna","wf","681"],["Western Sahara","eh","212",1,["5288","5289"]],["Yemen","ye","967"],["Zambia","zm","260"],["Zimbabwe","zw","263"],["\xC5land Islands","ax","358",1,["18"]]],_=[];for(let l=0;l<I.length;l++){let e=I[l];_[l]={name:e[0],iso2:e[1],dialCode:e[2],priority:e[3]||0,areaCodes:e[4]||null,nodeById:{}}}var y=_;var N=0,E={allowDropdown:!0,autoPlaceholder:"polite",countrySearch:!0,containerClass:"",customPlaceholder:null,dropdownContainer:null,excludeCountries:[],fixDropdownWidth:!0,formatAsYouType:!0,formatOnDisplay:!0,geoIpLookup:null,hiddenInput:null,i18n:{},initialCountry:"",nationalMode:!0,onlyCountries:[],placeholderNumberType:"MOBILE",preferredCountries:[],showFlags:!0,showSelectedDialCode:!1,strictMode:!1,useFullscreenPopup:typeof navigator<"u"&&typeof window<"u"?/Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||window.innerWidth<=500:!1,utilsScript:""},A=["800","822","833","844","855","866","877","880","881","882","883","884","885","886","887","888","889"],b=l=>l.replace(/\D/g,""),L=(l="")=>l.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase(),M=(l,e,t)=>{t&&!l.classList.contains(e)?l.classList.add(e):!t&&l.classList.contains(e)&&l.classList.remove(e)},T=l=>{let e=b(l);if(e.charAt(0)==="1"){let t=e.substr(1,3);return A.indexOf(t)!==-1}return!1},k=(l,e)=>l.name<e.name?-1:l.name>e.name?1:0,P=(l,e,t,i)=>{if(t===0&&!i)return 0;let n=0;for(let s=0;s<e.length;s++){if(/[+0-9]/.test(e[s])&&n++,n===l&&!i)return s+1;if(i&&n===l+1)return s}return e.length},g=(l,e,t)=>{let i=document.createElement(l);return e&&Object.entries(e).forEach(([n,s])=>i.setAttribute(n,s)),t&&t.appendChild(i),i},f=l=>{let{instances:e}=window.intlTelInputGlobals;Object.values(e).forEach(t=>t[l]())},v=class{id;promise;telInput;activeItem;highlightedItem;options;hadInitialPlaceholder;isRTL;selectedCountryData;countries;dialCodeMaxLen;dialCodeToIso2Map;dialCodes;preferredCountries;countryContainer;selectedCountry;selectedCountryInner;selectedCountryA11yText;selectedDialCode;dropdownArrow;dropdownContent;searchInput;searchResultsA11yText;countryList;dropdown;hiddenInput;hiddenInputCountry;maxCoreNumberLength;defaultCountry;_handleHiddenInputSubmit;_handleLabelClick;_handleClickSelectedCountry;_handleCountryContainerKeydown;_handleInputEvent;_handleKeydownEvent;_handleWindowScroll;_handleMouseoverCountryList;_handleClickCountryList;_handleClickOffToClose;_handleKeydownOnDropdown;_handleSearchChange;resolveAutoCountryPromise;rejectAutoCountryPromise;resolveUtilsScriptPromise;rejectUtilsScriptPromise;constructor(e,t={}){this.id=N++,this.telInput=e,this.activeItem=null,this.highlightedItem=null,this.options=Object.assign({},E,t),this.hadInitialPlaceholder=!!e.getAttribute("placeholder")}_init(){this.options.useFullscreenPopup&&(this.options.fixDropdownWidth=!1),this.options.countrySearch&&!this.options.useFullscreenPopup&&(this.options.fixDropdownWidth=!0);let e=this.options.allowDropdown&&!this.options.showSelectedDialCode;!this.options.showFlags&&e&&(this.options.showFlags=!0),this.options.useFullscreenPopup&&!this.options.dropdownContainer&&(this.options.dropdownContainer=document.body),this.isRTL=!!this.telInput.closest("[dir=rtl]");let t=new Promise((n,s)=>{this.resolveAutoCountryPromise=n,this.rejectAutoCountryPromise=s}),i=new Promise((n,s)=>{this.resolveUtilsScriptPromise=n,this.rejectUtilsScriptPromise=s});this.promise=Promise.all([t,i]),this.selectedCountryData={},this._processCountryData(),this._generateMarkup(),this._setInitialState(),this._initListeners(),this._initRequests()}_processCountryData(){this._processAllCountries(),this._processDialCodes(),this._processPreferredCountries(),this._translateCountryNames(),(this.options.onlyCountries.length||this.options.i18n)&&this.countries.sort(k)}_addToDialCodeMap(e,t,i){t.length>this.dialCodeMaxLen&&(this.dialCodeMaxLen=t.length),this.dialCodeToIso2Map.hasOwnProperty(t)||(this.dialCodeToIso2Map[t]=[]);for(let s=0;s<this.dialCodeToIso2Map[t].length;s++)if(this.dialCodeToIso2Map[t][s]===e)return;let n=i!==void 0?i:this.dialCodeToIso2Map[t].length;this.dialCodeToIso2Map[t][n]=e}_processAllCountries(){let{onlyCountries:e,excludeCountries:t}=this.options;if(e.length){let i=e.map(n=>n.toLowerCase());this.countries=y.filter(n=>i.indexOf(n.iso2)>-1)}else if(t.length){let i=t.map(n=>n.toLowerCase());this.countries=y.filter(n=>i.indexOf(n.iso2)===-1)}else this.countries=y}_translateCountryNames(){for(let e=0;e<this.countries.length;e++){let t=this.countries[e].iso2.toLowerCase();this.options.i18n.hasOwnProperty(t)&&(this.countries[e].name=this.options.i18n[t])}}_processDialCodes(){this.dialCodes={},this.dialCodeMaxLen=0,this.dialCodeToIso2Map={};for(let e=0;e<this.countries.length;e++){let t=this.countries[e];this.dialCodes[t.dialCode]||(this.dialCodes[t.dialCode]=!0),this._addToDialCodeMap(t.iso2,t.dialCode,t.priority)}for(let e=0;e<this.countries.length;e++){let t=this.countries[e];if(t.areaCodes){let i=this.dialCodeToIso2Map[t.dialCode][0];for(let n=0;n<t.areaCodes.length;n++){let s=t.areaCodes[n];for(let r=1;r<s.length;r++){let d=t.dialCode+s.substr(0,r);this._addToDialCodeMap(i,d),this._addToDialCodeMap(t.iso2,d)}this._addToDialCodeMap(t.iso2,t.dialCode+s)}}}}_processPreferredCountries(){this.preferredCountries=[];for(let e=0;e<this.options.preferredCountries.length;e++){let t=this.options.preferredCountries[e].toLowerCase(),i=this._getCountryData(t,!0);i&&this.preferredCountries.push(i)}}_generateMarkup(){this.telInput.classList.add("iti__tel-input"),!this.telInput.hasAttribute("autocomplete")&&!(this.telInput.form&&this.telInput.form.hasAttribute("autocomplete"))&&this.telInput.setAttribute("autocomplete","off");let{allowDropdown:e,showSelectedDialCode:t,showFlags:i,containerClass:n,hiddenInput:s,dropdownContainer:r,fixDropdownWidth:d,useFullscreenPopup:a,countrySearch:o,i18n:p}=this.options,h="iti";e&&(h+=" iti--allow-dropdown"),t&&(h+=" iti--show-selected-dial-code"),i&&(h+=" iti--show-flags"),n&&(h+=` ${n}`),a||(h+=" iti--inline-dropdown");let c=g("div",{class:h});if(this.telInput.parentNode?.insertBefore(c,this.telInput),(i||t)&&(this.countryContainer=g("div",{class:"iti__country-container"},c),this.selectedCountry=g("button",{type:"button",class:"iti__selected-country",...e&&{"aria-expanded":"false","aria-label":this.options.i18n.selectedCountryAriaLabel||"Selected country","aria-haspopup":o?"true":"listbox","aria-controls":o?`iti-${this.id}__dropdown-content`:`iti-${this.id}__country-listbox`,...o?{role:"combobox"}:{}}},this.countryContainer),this.selectedCountryInner=g("div",null,this.selectedCountry),this.selectedCountryA11yText=g("span",{class:"iti__a11y-text"},this.selectedCountryInner)),c.appendChild(this.telInput),this.selectedCountry&&this.telInput.disabled&&this.selectedCountry.setAttribute("aria-disabled","true"),t&&(this.selectedDialCode=g("div",{class:"iti__selected-dial-code"},this.selectedCountry)),e){this.telInput.disabled||this.selectedCountry.setAttribute("tabindex","0"),this.dropdownArrow=g("div",{class:"iti__arrow","aria-hidden":"true"},this.selectedCountry);let C=d?"":"iti--flexible-dropdown-width";if(this.dropdownContent=g("div",{id:`iti-${this.id}__dropdown-content`,class:`iti__dropdown-content iti__hide ${C}`}),o&&(this.searchInput=g("input",{type:"text",class:"iti__search-input",placeholder:p.searchPlaceholder||"Search",role:"combobox","aria-expanded":"true","aria-label":p.searchPlaceholder||"Search","aria-controls":`iti-${this.id}__country-listbox`,"aria-autocomplete":"list",autocomplete:"off"},this.dropdownContent),this.searchResultsA11yText=g("span",{class:"iti__a11y-text"},this.dropdownContent)),this.countryList=g("ul",{class:"iti__country-list",id:`iti-${this.id}__country-listbox`,role:"listbox","aria-label":p.countryListAriaLabel||"List of countries"},this.dropdownContent),this.preferredCountries.length&&!o&&(this._appendListItems(this.preferredCountries,"iti__preferred",!0),g("li",{class:"iti__divider","aria-hidden":"true"},this.countryList)),this._appendListItems(this.countries,"iti__standard"),o&&this._updateSearchResultsText(),r){let m="iti iti--container";a?m+=" iti--fullscreen-popup":m+=" iti--inline-dropdown",o&&(m+=" iti--country-search"),this.dropdown=g("div",{class:m}),this.dropdown.appendChild(this.dropdownContent)}else this.countryContainer.appendChild(this.dropdownContent)}if(s){let C=this.telInput.getAttribute("name")||"",m=s(C);m.phone&&(this.hiddenInput=g("input",{type:"hidden",name:m.phone}),c.appendChild(this.hiddenInput)),m.country&&(this.hiddenInputCountry=g("input",{type:"hidden",name:m.country}),c.appendChild(this.hiddenInputCountry))}}_appendListItems(e,t,i){for(let n=0;n<e.length;n++){let s=e[n],r=i?"-preferred":"",d=g("li",{id:`iti-${this.id}__item-${s.iso2}${r}`,class:`iti__country ${t}`,tabindex:"-1",role:"option","data-dial-code":s.dialCode,"data-country-code":s.iso2,"aria-selected":"false"},this.countryList);s.nodeById[this.id]=d;let a="";this.options.showFlags&&(a+=`<div class='iti__flag-box'><div class='iti__flag iti__${s.iso2}'></div></div>`),a+=`<span class='iti__country-name'>${s.name}</span>`,a+=`<span class='iti__dial-code'>+${s.dialCode}</span>`,d.insertAdjacentHTML("beforeend",a)}}_setInitialState(e=!1){let t=this.telInput.getAttribute("value"),i=this.telInput.value,s=t&&t.charAt(0)==="+"&&(!i||i.charAt(0)!=="+")?t:i,r=this._getDialCode(s),d=T(s),{initialCountry:a}=this.options;if(r&&!d)this._updateCountryFromNumber(s);else if(a!=="auto"||e){let o=a?a.toLowerCase():"";o&&this._getCountryData(o,!0)?this._setCountry(o):r&&d?this._setCountry("us"):this._setCountry()}s&&this._updateValFromNumber(s)}_initListeners(){this._initTelInputListeners(),this.options.allowDropdown&&this._initDropdownListeners(),(this.hiddenInput||this.hiddenInputCountry)&&this.telInput.form&&this._initHiddenInputListener()}_initHiddenInputListener(){this._handleHiddenInputSubmit=()=>{this.hiddenInput&&(this.hiddenInput.value=this.getNumber()),this.hiddenInputCountry&&(this.hiddenInputCountry.value=this.getSelectedCountryData().iso2||"")},this.telInput.form?.addEventListener("submit",this._handleHiddenInputSubmit)}_initDropdownListeners(){this._handleLabelClick=t=>{this.dropdownContent.classList.contains("iti__hide")?this.telInput.focus():t.preventDefault()};let e=this.telInput.closest("label");e&&e.addEventListener("click",this._handleLabelClick),this._handleClickSelectedCountry=()=>{this.dropdownContent.classList.contains("iti__hide")&&!this.telInput.disabled&&!this.telInput.readOnly&&this._openDropdown()},this.selectedCountry.addEventListener("click",this._handleClickSelectedCountry),this._handleCountryContainerKeydown=t=>{this.dropdownContent.classList.contains("iti__hide")&&["ArrowUp","ArrowDown"," ","Enter"].includes(t.key)&&(t.preventDefault(),t.stopPropagation(),this._openDropdown()),t.key==="Tab"&&this._closeDropdown()},this.countryContainer.addEventListener("keydown",this._handleCountryContainerKeydown)}_initRequests(){this.options.utilsScript&&!window.intlTelInputUtils?window.intlTelInputGlobals.documentReady()?window.intlTelInputGlobals.loadUtils(this.options.utilsScript):window.addEventListener("load",()=>{window.intlTelInputGlobals.loadUtils(this.options.utilsScript)}):this.resolveUtilsScriptPromise(),this.options.initialCountry==="auto"&&!this.selectedCountryData.iso2?this._loadAutoCountry():this.resolveAutoCountryPromise()}_loadAutoCountry(){window.intlTelInputGlobals.autoCountry?this.handleAutoCountry():window.intlTelInputGlobals.startedLoadingAutoCountry||(window.intlTelInputGlobals.startedLoadingAutoCountry=!0,typeof this.options.geoIpLookup=="function"&&this.options.geoIpLookup((e="")=>{let t=e.toLowerCase();t&&this._getCountryData(t,!0)?(window.intlTelInputGlobals.autoCountry=t,setTimeout(()=>f("handleAutoCountry"))):(this._setInitialState(!0),f("rejectAutoCountryPromise"))},()=>{this._setInitialState(!0),f("rejectAutoCountryPromise")}))}_initTelInputListeners(){let{strictMode:e,formatAsYouType:t}=this.options,i=!1;this._handleInputEvent=n=>{this._updateCountryFromNumber(this.telInput.value)&&this._triggerCountryChange();let s=n&&n.data&&/[^+0-9]/.test(n.data),r=n&&n.inputType==="insertFromPaste"&&this.telInput.value;if(s||r&&!e?i=!0:/[^+0-9]/.test(this.telInput.value)||(i=!1),t&&!i){let d=this.telInput.selectionStart||0,o=this.telInput.value.substring(0,d).replace(/[^+0-9]/g,"").length,p=n&&n.inputType==="deleteContentForward",h=this._formatNumberAsYouType(),c=P(o,h,d,p);this.telInput.value=h,this.telInput.setSelectionRange(c,c)}},this.telInput.addEventListener("input",this._handleInputEvent),e&&(this._handleKeydownEvent=n=>{if(n.key.length===1&&!n.altKey&&!n.ctrlKey&&!n.metaKey){let s=this.telInput.selectionStart===0&&n.key==="+",r=/^[0-9]$/.test(n.key),d=s||r,a=this._getFullNumber(),o=window.intlTelInputUtils.getCoreNumber(a,this.selectedCountryData.iso2),p=this.maxCoreNumberLength&&o.length>=this.maxCoreNumberLength;(!d||p)&&n.preventDefault()}},this.telInput.addEventListener("keydown",this._handleKeydownEvent))}_cap(e){let t=parseInt(this.telInput.getAttribute("maxlength")||"",10);return t&&e.length>t?e.substr(0,t):e}_trigger(e){let t=new Event(e,{bubbles:!0,cancelable:!0});this.telInput.dispatchEvent(t)}_openDropdown(){let{fixDropdownWidth:e,countrySearch:t}=this.options;if(e&&(this.dropdownContent.style.width=`${this.telInput.offsetWidth}px`),this.dropdownContent.classList.remove("iti__hide"),this.selectedCountry.setAttribute("aria-expanded","true"),this._setDropdownPosition(),this.activeItem&&!t)this._highlightListItem(this.activeItem,!1),this._scrollTo(this.activeItem,!0);else{let i=this.countryList.firstElementChild;i&&(this._highlightListItem(i,!1),this.countryList.scrollTop=0),t&&this.searchInput.focus()}this._bindDropdownListeners(),this.dropdownArrow.classList.add("iti__arrow--up"),this._trigger("open:countrydropdown")}_setDropdownPosition(){if(this.options.dropdownContainer&&this.options.dropdownContainer.appendChild(this.dropdown),!this.options.useFullscreenPopup){let e=this.telInput.getBoundingClientRect(),t=document.documentElement.scrollTop,i=e.top+t,n=this.dropdownContent.offsetHeight,s=i+this.telInput.offsetHeight+n<t+window.innerHeight,r=i-n>t,d=!this.options.countrySearch&&!s&&r;if(M(this.dropdownContent,"iti__dropdown-content--dropup",d),this.options.dropdownContainer){let a=d?0:this.telInput.offsetHeight;this.dropdown.style.top=`${i+a}px`,this.dropdown.style.left=`${e.left+document.body.scrollLeft}px`,this._handleWindowScroll=()=>this._closeDropdown(),window.addEventListener("scroll",this._handleWindowScroll)}}}_bindDropdownListeners(){this._handleMouseoverCountryList=n=>{let s=n.target?.closest(".iti__country");s&&this._highlightListItem(s,!1)},this.countryList.addEventListener("mouseover",this._handleMouseoverCountryList),this._handleClickCountryList=n=>{let s=n.target?.closest(".iti__country");s&&this._selectListItem(s)},this.countryList.addEventListener("click",this._handleClickCountryList);let e=!0;this._handleClickOffToClose=()=>{e||this._closeDropdown(),e=!1},document.documentElement.addEventListener("click",this._handleClickOffToClose);let t="",i=null;if(this._handleKeydownOnDropdown=n=>{["ArrowUp","ArrowDown","Enter","Escape"].includes(n.key)&&(n.preventDefault(),n.stopPropagation(),n.key==="ArrowUp"||n.key==="ArrowDown"?this._handleUpDownKey(n.key):n.key==="Enter"?this._handleEnterKey():n.key==="Escape"&&this._closeDropdown()),!this.options.countrySearch&&/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(n.key)&&(n.stopPropagation(),i&&clearTimeout(i),t+=n.key.toLowerCase(),this._searchForCountry(t),i=setTimeout(()=>{t=""},1e3))},document.addEventListener("keydown",this._handleKeydownOnDropdown),this.options.countrySearch){let n=()=>{let r=this.searchInput.value.trim();r?this._filterCountries(r):this._filterCountries("",!0)},s=null;this._handleSearchChange=()=>{s&&clearTimeout(s),s=setTimeout(()=>{n(),s=null},100)},this.searchInput.addEventListener("input",this._handleSearchChange),this.searchInput.addEventListener("click",r=>r.stopPropagation())}}_filterCountries(e,t=!1){let i=!0;this.countryList.innerHTML="";let n=L(e);for(let s=0;s<this.countries.length;s++){let r=this.countries[s],d=L(r.name),a=`+${r.dialCode}`;if(t||d.includes(n)||a.includes(n)||r.iso2.includes(n)){let o=r.nodeById[this.id];o&&this.countryList.appendChild(o),i&&(this._highlightListItem(o,!1),i=!1)}}this.countryList.scrollTop=0,this._updateSearchResultsText()}_updateSearchResultsText(){let{i18n:e}=this.options,t=this.countryList.childElementCount,i;t===0?i=e.zeroSearchResults||"No results found":t===1?i=e.oneSearchResult||"1 result found":i=e.multipleSearchResults?e.multipleSearchResults.replace("${count}",t.toString()):`${t} results found`,this.searchResultsA11yText.textContent=i}_handleUpDownKey(e){let t=e==="ArrowUp"?this.highlightedItem?.previousElementSibling:this.highlightedItem?.nextElementSibling;if(t?t.classList.contains("iti__divider")&&(t=e==="ArrowUp"?t.previousElementSibling:t.nextElementSibling):this.countryList.childElementCount>1&&(t=e==="ArrowUp"?this.countryList.lastElementChild:this.countryList.firstElementChild),t){this._scrollTo(t,!1);let i=!this.options.countrySearch;this._highlightListItem(t,i)}}_handleEnterKey(){this.highlightedItem&&this._selectListItem(this.highlightedItem)}_searchForCountry(e){for(let t=0;t<this.countries.length;t++){let i=this.countries[t];if(i.name.substr(0,e.length).toLowerCase()===e){let s=i.nodeById[this.id];this._highlightListItem(s,!1),this._scrollTo(s,!0);break}}}_updateValFromNumber(e){let t=e;if(this.options.formatOnDisplay&&window.intlTelInputUtils&&this.selectedCountryData){let i=this.options.nationalMode||t.charAt(0)!=="+"&&!this.options.showSelectedDialCode,{NATIONAL:n,INTERNATIONAL:s}=window.intlTelInputUtils.numberFormat,r=i?n:s;t=window.intlTelInputUtils.formatNumber(t,this.selectedCountryData.iso2,r)}t=this._beforeSetNumber(t),this.telInput.value=t}_updateCountryFromNumber(e){let t=e.indexOf("+"),i=t?e.substring(t):e,n=this.selectedCountryData.dialCode;i&&n==="1"&&i.charAt(0)!=="+"&&(i.charAt(0)!=="1"&&(i=`1${i}`),i=`+${i}`),this.options.showSelectedDialCode&&n&&i.charAt(0)!=="+"&&(i=`+${n}${i}`);let r=this._getDialCode(i,!0),d=b(i),a=null;if(r){let o=this.dialCodeToIso2Map[b(r)],p=o.indexOf(this.selectedCountryData.iso2)!==-1&&d.length<=r.length-1;if(!(n==="1"&&T(d))&&!p){for(let c=0;c<o.length;c++)if(o[c]){a=o[c];break}}}else i.charAt(0)==="+"&&d.length?a="":(!i||i==="+")&&!this.selectedCountryData.iso2&&(a=this.defaultCountry);return a!==null?this._setCountry(a):!1}_highlightListItem(e,t){let i=this.highlightedItem;i&&(i.classList.remove("iti__highlight"),i.setAttribute("aria-selected","false")),this.highlightedItem=e,this.highlightedItem.classList.add("iti__highlight"),this.highlightedItem.setAttribute("aria-selected","true"),this.selectedCountry.setAttribute("aria-activedescendant",e.getAttribute("id")||""),this.options.countrySearch&&this.searchInput.setAttribute("aria-activedescendant",e.getAttribute("id")||""),t&&this.highlightedItem.focus()}_getCountryData(e,t){for(let i=0;i<this.countries.length;i++)if(this.countries[i].iso2===e)return this.countries[i];if(t)return null;throw new Error(`No country data for '${e}'`)}_setCountry(e){let{allowDropdown:t,showSelectedDialCode:i,showFlags:n,countrySearch:s,i18n:r}=this.options,d=this.selectedCountryData.iso2?this.selectedCountryData:{};if(this.selectedCountryData=e?this._getCountryData(e,!1)||{}:{},this.selectedCountryData.iso2&&(this.defaultCountry=this.selectedCountryData.iso2),this.selectedCountryInner){let a="",o="";e?n&&(a=`iti__flag iti__${e}`,o=`${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`):(a="iti__flag iti__globe",o=r.noCountrySelected||"No country selected"),this.selectedCountryInner.className=a,this.selectedCountryA11yText.textContent=o}if(this._setSelectedCountryTitleAttribute(e,i),i){let a=this.selectedCountryData.dialCode?`+${this.selectedCountryData.dialCode}`:"";this.selectedDialCode.innerHTML=a;let o=this.selectedCountry.offsetWidth||this._getHiddenSelectedCountryWidth();this.isRTL?this.telInput.style.paddingRight=`${o+6}px`:this.telInput.style.paddingLeft=`${o+6}px`}if(this._updatePlaceholder(),this._updateMaxLength(),t&&!s){let a=this.activeItem;if(a&&(a.classList.remove("iti__active"),a.setAttribute("aria-selected","false")),e){let o=this.countryList.querySelector(`#iti-${this.id}__item-${e}-preferred`)||this.countryList.querySelector(`#iti-${this.id}__item-${e}`);o&&(o.setAttribute("aria-selected","true"),o.classList.add("iti__active"),this.activeItem=o)}}return d.iso2!==e}_updateMaxLength(){if(this.options.strictMode&&window.intlTelInputUtils)if(this.selectedCountryData.iso2){let e=window.intlTelInputUtils.numberType[this.options.placeholderNumberType],t=window.intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2,!1,e,!0),i=t;for(;window.intlTelInputUtils.isPossibleNumber(t,this.selectedCountryData.iso2);)i=t,t+="0";let n=window.intlTelInputUtils.getCoreNumber(i,this.selectedCountryData.iso2);this.maxCoreNumberLength=n.length}else this.maxCoreNumberLength=null}_setSelectedCountryTitleAttribute(e=null,t){if(!this.selectedCountry)return;let i;e&&!t?i=`${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`:e?i=this.selectedCountryData.name:i="Unknown",this.selectedCountry.setAttribute("title",i)}_getHiddenSelectedCountryWidth(){if(this.telInput.parentNode){let e=this.telInput.parentNode.cloneNode(!1);e.style.visibility="hidden",document.body.appendChild(e);let t=this.countryContainer.cloneNode();e.appendChild(t);let i=this.selectedCountry.cloneNode(!0);t.appendChild(i);let n=i.offsetWidth;return document.body.removeChild(e),n}return 0}_updatePlaceholder(){let{autoPlaceholder:e,placeholderNumberType:t,nationalMode:i,customPlaceholder:n}=this.options,s=e==="aggressive"||!this.hadInitialPlaceholder&&e==="polite";if(window.intlTelInputUtils&&s){let r=window.intlTelInputUtils.numberType[t],d=this.selectedCountryData.iso2?window.intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2,i,r):"";d=this._beforeSetNumber(d),typeof n=="function"&&(d=n(d,this.selectedCountryData)),this.telInput.setAttribute("placeholder",d)}}_selectListItem(e){let t=this._setCountry(e.getAttribute("data-country-code"));this._closeDropdown(),this._updateDialCode(e.getAttribute("data-dial-code")),this.telInput.focus(),t&&this._triggerCountryChange()}_closeDropdown(){this.dropdownContent.classList.add("iti__hide"),this.selectedCountry.setAttribute("aria-expanded","false"),this.selectedCountry.removeAttribute("aria-activedescendant"),this.highlightedItem&&this.highlightedItem.setAttribute("aria-selected","false"),this.options.countrySearch&&this.searchInput.removeAttribute("aria-activedescendant"),this.dropdownArrow.classList.remove("iti__arrow--up"),document.removeEventListener("keydown",this._handleKeydownOnDropdown),this.options.countrySearch&&this.searchInput.removeEventListener("input",this._handleSearchChange),document.documentElement.removeEventListener("click",this._handleClickOffToClose),this.countryList.removeEventListener("mouseover",this._handleMouseoverCountryList),this.countryList.removeEventListener("click",this._handleClickCountryList),this.options.dropdownContainer&&(this.options.useFullscreenPopup||window.removeEventListener("scroll",this._handleWindowScroll),this.dropdown.parentNode&&this.dropdown.parentNode.removeChild(this.dropdown)),this._trigger("close:countrydropdown")}_scrollTo(e,t){let i=this.countryList,n=document.documentElement.scrollTop,s=i.offsetHeight,r=i.getBoundingClientRect().top+n,d=r+s,a=e.offsetHeight,o=e.getBoundingClientRect().top+n,p=o+a,h=o-r+i.scrollTop,c=s/2-a/2;if(o<r)t&&(h-=c),i.scrollTop=h;else if(p>d){t&&(h+=c);let C=s-a;i.scrollTop=h-C}}_updateDialCode(e){let t=this.telInput.value,i=`+${e}`,n;if(t.charAt(0)==="+"){let s=this._getDialCode(t);s?n=t.replace(s,i):n=i,this.telInput.value=n}}_getDialCode(e,t){let i="";if(e.charAt(0)==="+"){let n="";for(let s=0;s<e.length;s++){let r=e.charAt(s);if(!isNaN(parseInt(r,10))){if(n+=r,t)this.dialCodeToIso2Map[n]&&(i=e.substr(0,s+1));else if(this.dialCodes[n]){i=e.substr(0,s+1);break}if(n.length===this.dialCodeMaxLen)break}}}return i}_getFullNumber(){let e=this.telInput.value.trim(),{dialCode:t}=this.selectedCountryData,i,n=b(e);return this.options.showSelectedDialCode&&!this.options.nationalMode&&e.charAt(0)!=="+"&&t&&n?i=`+${t}`:i="",i+e}_beforeSetNumber(e){let t=e;if(this.options.showSelectedDialCode){let i=this._getDialCode(t);if(i){i=`+${this.selectedCountryData.dialCode}`;let n=t[i.length]===" "||t[i.length]==="-"?i.length+1:i.length;t=t.substr(n)}}return this._cap(t)}_triggerCountryChange(){this._trigger("countrychange")}_formatNumberAsYouType(){let e=this._getFullNumber(),t=window.intlTelInputUtils?window.intlTelInputUtils.formatNumberAsYouType(e,this.selectedCountryData.iso2):e,{dialCode:i}=this.selectedCountryData;return this.options.showSelectedDialCode&&!this.options.nationalMode&&this.telInput.value.charAt(0)!=="+"&&t.includes(`+${i}`)?(t.split(`+${i}`)[1]||"").trim():t}handleAutoCountry(){this.options.initialCountry==="auto"&&window.intlTelInputGlobals.autoCountry&&(this.defaultCountry=window.intlTelInputGlobals.autoCountry,this.telInput.value||this.setCountry(this.defaultCountry),this.resolveAutoCountryPromise())}handleUtils(){window.intlTelInputUtils&&(this.telInput.value&&this._updateValFromNumber(this.telInput.value),this.selectedCountryData.iso2&&(this._updatePlaceholder(),this._updateMaxLength())),this.resolveUtilsScriptPromise()}destroy(){if(this.options.allowDropdown){this._closeDropdown(),this.selectedCountry.removeEventListener("click",this._handleClickSelectedCountry),this.countryContainer.removeEventListener("keydown",this._handleCountryContainerKeydown);let i=this.telInput.closest("label");i&&i.removeEventListener("click",this._handleLabelClick)}let{form:e}=this.telInput;this._handleHiddenInputSubmit&&e&&e.removeEventListener("submit",this._handleHiddenInputSubmit),this.telInput.removeEventListener("input",this._handleInputEvent),this._handleKeydownEvent&&this.telInput.removeEventListener("keydown",this._handleKeydownEvent),this.telInput.removeAttribute("data-intl-tel-input-id");let t=this.telInput.parentNode;t?.parentNode?.insertBefore(this.telInput,t),t?.parentNode?.removeChild(t),delete window.intlTelInputGlobals.instances[this.id]}getExtension(){return window.intlTelInputUtils?window.intlTelInputUtils.getExtension(this._getFullNumber(),this.selectedCountryData.iso2):""}getNumber(e){if(window.intlTelInputUtils){let{iso2:t}=this.selectedCountryData;return window.intlTelInputUtils.formatNumber(this._getFullNumber(),t,e)}return""}getNumberType(){return window.intlTelInputUtils?window.intlTelInputUtils.getNumberType(this._getFullNumber(),this.selectedCountryData.iso2):-99}getSelectedCountryData(){return this.selectedCountryData}getValidationError(){if(window.intlTelInputUtils){let{iso2:e}=this.selectedCountryData;return window.intlTelInputUtils.getValidationError(this._getFullNumber(),e)}return-99}isValidNumber(e=!0){let t=this._getFullNumber();return/\p{L}/u.test(t)?!1:window.intlTelInputUtils?window.intlTelInputUtils.isPossibleNumber(t,this.selectedCountryData.iso2,e):null}isValidNumberPrecise(){let e=this._getFullNumber();return/\p{L}/u.test(e)?!1:window.intlTelInputUtils?window.intlTelInputUtils.isValidNumber(e,this.selectedCountryData.iso2):null}setCountry(e){let t=e.toLowerCase();this.selectedCountryData.iso2!==t&&(this._setCountry(t),this._updateDialCode(this.selectedCountryData.dialCode),this._triggerCountryChange())}setNumber(e){let t=this._updateCountryFromNumber(e);this._updateValFromNumber(e),t&&this._triggerCountryChange()}setPlaceholderNumberType(e){this.options.placeholderNumberType=e,this._updatePlaceholder()}},x=(l,e,t)=>{let i=document.createElement("script");i.onload=()=>{f("handleUtils"),e&&e()},i.onerror=()=>{f("rejectUtilsScriptPromise"),t&&t()},i.className="iti-load-utils",i.async=!0,i.src=l,document.body.appendChild(i)},H=l=>!window.intlTelInputUtils&&!window.intlTelInputGlobals.startedLoadingUtilsScript?(window.intlTelInputGlobals.startedLoadingUtilsScript=!0,new Promise((e,t)=>x(l,e,t))):null;if(typeof window=="object"){let l={defaults:E,documentReady:()=>document.readyState==="complete",getCountryData:()=>y,getInstance:e=>{let t=e.getAttribute("data-intl-tel-input-id");return t?l.instances[t]:null},instances:{},loadUtils:H,version:"21.0.1"};window.intlTelInputGlobals=l}var U=(l,e)=>{let t=new v(l,e);return t._init(),l.setAttribute("data-intl-tel-input-id",t.id.toString()),window.intlTelInputGlobals.instances[t.id]=t,t},S=U;var w=({initialValue:l,onChangeNumber:e,onChangeCountry:t,onChangeValidity:i,onChangeErrorCode:n,usePreciseValidation:s,initOptions:r,inputProps:d})=>{let a=D(null),o=D(null),p=()=>{let h=o.current.getNumber(),c=o.current.getSelectedCountryData().iso2;if(e(h),t(c),s?o.current.isValidNumberPrecise():o.current.isValidNumber())i(!0),n(null);else{let m=o.current.getValidationError();i(!1),n(m)}};return F(()=>{let h=a.current;return o.current=S(a.current,r),h&&h.addEventListener("countrychange",p),()=>{h&&h.removeEventListener("countrychange",p),o.current.destroy()}},[]),O.createElement("input",{type:"tel",ref:a,onInput:p,defaultValue:l,...d})};w.propTypes={initialValue:u.string,onChangeNumber:u.func,onChangeCountry:u.func,onChangeValidity:u.func,onChangeErrorCode:u.func,usePreciseValidation:u.bool,initOptions:u.shape({allowDropdown:u.bool,autoPlaceholder:u.string,containerClass:u.string,countrySearch:u.bool,customPlaceholder:u.func,dropdownContainer:u.node,excludeCountries:u.arrayOf(u.string),fixDropdownWidth:u.bool,formatAsYouType:u.bool,formatOnDisplay:u.bool,geoIpLookup:u.func,hiddenInput:u.func,i18n:u.objectOf(u.string),initialCountry:u.string,nationalMode:u.bool,onlyCountries:u.arrayOf(u.string),placeholderNumberType:u.string,preferredCountries:u.arrayOf(u.string),showFlags:u.bool,showSelectedDialCode:u.bool,useFullscreenPopup:u.bool,utilsScript:u.string}),inputProps:u.object};w.defaultProps={initialValue:"",onChangeNumber:()=>{},onChangeCountry:()=>{},onChangeValidity:()=>{},onChangeErrorCode:()=>{},usePreciseValidation:!1,initOptions:{},inputProps:{}};var W=w;export{W as default};
|