intl-tel-input 25.12.5 → 25.13.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 +5 -5
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +106 -47
- package/angular/build/IntlTelInputWithUtils.js +216 -191
- package/angular/build/types/intl-tel-input.d.ts +6 -0
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +6 -0
- package/build/js/intlTelInput.js +108 -52
- package/build/js/intlTelInput.min.js +4 -4
- package/build/js/intlTelInputWithUtils.js +218 -196
- package/build/js/intlTelInputWithUtils.min.js +6 -6
- package/build/js/utils.js +40 -39
- package/package.json +1 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +107 -51
- package/react/build/IntlTelInput.d.ts +6 -0
- package/react/build/IntlTelInput.js +107 -51
- package/react/build/IntlTelInputWithUtils.cjs +217 -195
- package/react/build/IntlTelInputWithUtils.js +217 -195
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +325 -285
- package/vue/build/IntlTelInputWithUtils.mjs +680 -674
|
@@ -2926,6 +2926,45 @@ var Iti = class _Iti {
|
|
|
2926
2926
|
static _getIsAndroid() {
|
|
2927
2927
|
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2928
2928
|
}
|
|
2929
|
+
_updateNumeralSet(str) {
|
|
2930
|
+
if (/[\u0660-\u0669]/.test(str)) {
|
|
2931
|
+
this.userNumeralSet = "arabic-indic";
|
|
2932
|
+
} else if (/[\u06F0-\u06F9]/.test(str)) {
|
|
2933
|
+
this.userNumeralSet = "persian";
|
|
2934
|
+
} else {
|
|
2935
|
+
this.userNumeralSet = "ascii";
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
_mapAsciiToUserNumerals(str) {
|
|
2939
|
+
if (!this.userNumeralSet) {
|
|
2940
|
+
this._updateNumeralSet(this.ui.telInput.value);
|
|
2941
|
+
}
|
|
2942
|
+
if (this.userNumeralSet === "ascii") {
|
|
2943
|
+
return str;
|
|
2944
|
+
}
|
|
2945
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2946
|
+
return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
|
|
2947
|
+
}
|
|
2948
|
+
// Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
|
|
2949
|
+
_normaliseNumerals(str) {
|
|
2950
|
+
if (!str) {
|
|
2951
|
+
return "";
|
|
2952
|
+
}
|
|
2953
|
+
this._updateNumeralSet(str);
|
|
2954
|
+
if (this.userNumeralSet === "ascii") {
|
|
2955
|
+
return str;
|
|
2956
|
+
}
|
|
2957
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2958
|
+
const regex = this.userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
|
|
2959
|
+
return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
|
|
2960
|
+
}
|
|
2961
|
+
_getTelInputValue() {
|
|
2962
|
+
const inputValue = this.ui.telInput.value.trim();
|
|
2963
|
+
return this._normaliseNumerals(inputValue);
|
|
2964
|
+
}
|
|
2965
|
+
_setTelInputValue(asciiValue) {
|
|
2966
|
+
this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
|
|
2967
|
+
}
|
|
2929
2968
|
_createInitPromises() {
|
|
2930
2969
|
const autoCountryPromise = new Promise((resolve, reject) => {
|
|
2931
2970
|
this.resolveAutoCountryPromise = resolve;
|
|
@@ -2960,8 +2999,9 @@ var Iti = class _Iti {
|
|
|
2960
2999
|
//* 1. Extracting a dial code from the given number
|
|
2961
3000
|
//* 2. Using explicit initialCountry
|
|
2962
3001
|
_setInitialState(overrideAutoCountry = false) {
|
|
2963
|
-
const
|
|
2964
|
-
const
|
|
3002
|
+
const attributeValueRaw = this.ui.telInput.getAttribute("value");
|
|
3003
|
+
const attributeValue = this._normaliseNumerals(attributeValueRaw);
|
|
3004
|
+
const inputValue = this._getTelInputValue();
|
|
2965
3005
|
const useAttribute = attributeValue && attributeValue.startsWith("+") && (!inputValue || !inputValue.startsWith("+"));
|
|
2966
3006
|
const val = useAttribute ? attributeValue : inputValue;
|
|
2967
3007
|
const dialCode = this._getDialCode(val);
|
|
@@ -3132,35 +3172,34 @@ var Iti = class _Iti {
|
|
|
3132
3172
|
countrySearch
|
|
3133
3173
|
} = this.options;
|
|
3134
3174
|
let userOverrideFormatting = false;
|
|
3135
|
-
if (REGEX.ALPHA_UNICODE.test(this.
|
|
3175
|
+
if (REGEX.ALPHA_UNICODE.test(this._getTelInputValue())) {
|
|
3136
3176
|
userOverrideFormatting = true;
|
|
3137
3177
|
}
|
|
3138
3178
|
const handleInputEvent = (e) => {
|
|
3179
|
+
const inputValue = this._getTelInputValue();
|
|
3139
3180
|
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
3140
3181
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3141
|
-
const valueBeforeCaret =
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
);
|
|
3145
|
-
const valueAfterCaret = this.ui.telInput.value.substring(currentCaretPos);
|
|
3146
|
-
this.ui.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
3182
|
+
const valueBeforeCaret = inputValue.substring(0, currentCaretPos - 1);
|
|
3183
|
+
const valueAfterCaret = inputValue.substring(currentCaretPos);
|
|
3184
|
+
this._setTelInputValue(valueBeforeCaret + valueAfterCaret);
|
|
3147
3185
|
this._openDropdownWithPlus();
|
|
3148
3186
|
return;
|
|
3149
3187
|
}
|
|
3150
|
-
if (this._updateCountryFromNumber(
|
|
3188
|
+
if (this._updateCountryFromNumber(inputValue)) {
|
|
3151
3189
|
this._triggerCountryChange();
|
|
3152
3190
|
}
|
|
3153
3191
|
const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
|
|
3154
|
-
const isPaste = e?.inputType === INPUT_TYPES.PASTE &&
|
|
3192
|
+
const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
|
|
3155
3193
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
3156
3194
|
userOverrideFormatting = true;
|
|
3157
|
-
} else if (!REGEX.NON_PLUS_NUMERIC.test(
|
|
3195
|
+
} else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
|
|
3158
3196
|
userOverrideFormatting = false;
|
|
3159
3197
|
}
|
|
3160
3198
|
const isSetNumber = e?.detail && e.detail["isSetNumber"];
|
|
3161
|
-
|
|
3199
|
+
const isAscii = this.userNumeralSet === "ascii";
|
|
3200
|
+
if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
|
|
3162
3201
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3163
|
-
const valueBeforeCaret =
|
|
3202
|
+
const valueBeforeCaret = inputValue.substring(
|
|
3164
3203
|
0,
|
|
3165
3204
|
currentCaretPos
|
|
3166
3205
|
);
|
|
@@ -3172,7 +3211,7 @@ var Iti = class _Iti {
|
|
|
3172
3211
|
const fullNumber = this._getFullNumber();
|
|
3173
3212
|
const formattedValue = formatNumberAsYouType(
|
|
3174
3213
|
fullNumber,
|
|
3175
|
-
|
|
3214
|
+
inputValue,
|
|
3176
3215
|
intlTelInput.utils,
|
|
3177
3216
|
this.selectedCountryData,
|
|
3178
3217
|
this.options.separateDialCode
|
|
@@ -3183,7 +3222,7 @@ var Iti = class _Iti {
|
|
|
3183
3222
|
currentCaretPos,
|
|
3184
3223
|
isDeleteForwards
|
|
3185
3224
|
);
|
|
3186
|
-
this.
|
|
3225
|
+
this._setTelInputValue(formattedValue);
|
|
3187
3226
|
this.ui.telInput.setSelectionRange(newCaretPos, newCaretPos);
|
|
3188
3227
|
}
|
|
3189
3228
|
};
|
|
@@ -3206,12 +3245,18 @@ var Iti = class _Iti {
|
|
|
3206
3245
|
return;
|
|
3207
3246
|
}
|
|
3208
3247
|
if (strictMode) {
|
|
3209
|
-
const
|
|
3210
|
-
const alreadyHasPlus =
|
|
3248
|
+
const inputValue = this._getTelInputValue();
|
|
3249
|
+
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3211
3250
|
const isInitialPlus = !alreadyHasPlus && this.ui.telInput.selectionStart === 0 && e.key === "+";
|
|
3212
|
-
const
|
|
3251
|
+
const normalisedKey = this._normaliseNumerals(e.key);
|
|
3252
|
+
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3213
3253
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3214
|
-
const
|
|
3254
|
+
const input = this.ui.telInput;
|
|
3255
|
+
const selStart = input.selectionStart;
|
|
3256
|
+
const selEnd = input.selectionEnd;
|
|
3257
|
+
const before = inputValue.slice(0, selStart);
|
|
3258
|
+
const after = inputValue.slice(selEnd);
|
|
3259
|
+
const newValue = before + e.key + after;
|
|
3215
3260
|
const newFullNumber = this._getFullNumber(newValue);
|
|
3216
3261
|
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3217
3262
|
newFullNumber,
|
|
@@ -3238,34 +3283,38 @@ var Iti = class _Iti {
|
|
|
3238
3283
|
const input = this.ui.telInput;
|
|
3239
3284
|
const selStart = input.selectionStart;
|
|
3240
3285
|
const selEnd = input.selectionEnd;
|
|
3241
|
-
const
|
|
3242
|
-
const
|
|
3286
|
+
const inputValue = this._getTelInputValue();
|
|
3287
|
+
const before = inputValue.slice(0, selStart);
|
|
3288
|
+
const after = inputValue.slice(selEnd);
|
|
3243
3289
|
const iso2 = this.selectedCountryData.iso2;
|
|
3244
|
-
const
|
|
3290
|
+
const pastedRaw = e.clipboardData.getData("text");
|
|
3291
|
+
const pasted = this._normaliseNumerals(pastedRaw);
|
|
3245
3292
|
const initialCharSelected = selStart === 0 && selEnd > 0;
|
|
3246
|
-
const allowLeadingPlus = !
|
|
3293
|
+
const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
|
|
3247
3294
|
const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
|
|
3248
3295
|
const hasLeadingPlus = allowedChars.startsWith("+");
|
|
3249
3296
|
const numerics = allowedChars.replace(/\+/g, "");
|
|
3250
3297
|
const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
|
|
3251
3298
|
let newVal = before + sanitised + after;
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
}
|
|
3260
|
-
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3261
|
-
if (input.selectionEnd === input.value.length) {
|
|
3262
|
-
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3263
|
-
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3264
|
-
} else {
|
|
3299
|
+
if (newVal.length > 5) {
|
|
3300
|
+
let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3301
|
+
while (coreNumber.length === 0 && newVal.length > 0) {
|
|
3302
|
+
newVal = newVal.slice(0, -1);
|
|
3303
|
+
coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3304
|
+
}
|
|
3305
|
+
if (!coreNumber) {
|
|
3265
3306
|
return;
|
|
3266
3307
|
}
|
|
3308
|
+
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3309
|
+
if (input.selectionEnd === inputValue.length) {
|
|
3310
|
+
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3311
|
+
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3312
|
+
} else {
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3267
3316
|
}
|
|
3268
|
-
|
|
3317
|
+
this._setTelInputValue(newVal);
|
|
3269
3318
|
const caretPos = selStart + sanitised.length;
|
|
3270
3319
|
input.setSelectionRange(caretPos, caretPos);
|
|
3271
3320
|
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
@@ -3416,6 +3465,7 @@ var Iti = class _Iti {
|
|
|
3416
3465
|
this._handleEnterKey();
|
|
3417
3466
|
} else if (e.key === KEYS.ESC) {
|
|
3418
3467
|
this._closeDropdown();
|
|
3468
|
+
this.ui.selectedCountry.focus();
|
|
3419
3469
|
}
|
|
3420
3470
|
}
|
|
3421
3471
|
if (!this.options.countrySearch && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
|
|
@@ -3516,7 +3566,7 @@ var Iti = class _Iti {
|
|
|
3516
3566
|
);
|
|
3517
3567
|
}
|
|
3518
3568
|
number = this._beforeSetNumber(number);
|
|
3519
|
-
this.
|
|
3569
|
+
this._setTelInputValue(number);
|
|
3520
3570
|
}
|
|
3521
3571
|
//* Check if need to select a new country based on the given number
|
|
3522
3572
|
//* Note: called from _setInitialState, keyup handler, setNumber.
|
|
@@ -3690,7 +3740,8 @@ var Iti = class _Iti {
|
|
|
3690
3740
|
const dialCode = listItem.dataset[DATA_KEYS.DIAL_CODE];
|
|
3691
3741
|
this._updateDialCode(dialCode);
|
|
3692
3742
|
if (this.options.formatOnDisplay) {
|
|
3693
|
-
this.
|
|
3743
|
+
const inputValue = this._getTelInputValue();
|
|
3744
|
+
this._updateValFromNumber(inputValue);
|
|
3694
3745
|
}
|
|
3695
3746
|
this.ui.telInput.focus();
|
|
3696
3747
|
if (countryChanged) {
|
|
@@ -3721,7 +3772,7 @@ var Iti = class _Iti {
|
|
|
3721
3772
|
//* Replace any existing dial code with the new one
|
|
3722
3773
|
//* Note: called from _selectListItem and setCountry
|
|
3723
3774
|
_updateDialCode(newDialCodeBare) {
|
|
3724
|
-
const inputVal = this.
|
|
3775
|
+
const inputVal = this._getTelInputValue();
|
|
3725
3776
|
const newDialCode = `+${newDialCodeBare}`;
|
|
3726
3777
|
let newNumber;
|
|
3727
3778
|
if (inputVal.startsWith("+")) {
|
|
@@ -3731,7 +3782,7 @@ var Iti = class _Iti {
|
|
|
3731
3782
|
} else {
|
|
3732
3783
|
newNumber = newDialCode;
|
|
3733
3784
|
}
|
|
3734
|
-
this.
|
|
3785
|
+
this._setTelInputValue(newNumber);
|
|
3735
3786
|
}
|
|
3736
3787
|
}
|
|
3737
3788
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
@@ -3768,7 +3819,7 @@ var Iti = class _Iti {
|
|
|
3768
3819
|
}
|
|
3769
3820
|
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
3770
3821
|
_getFullNumber(overrideVal) {
|
|
3771
|
-
const val = overrideVal
|
|
3822
|
+
const val = overrideVal ? this._normaliseNumerals(overrideVal) : this._getTelInputValue();
|
|
3772
3823
|
const { dialCode } = this.selectedCountryData;
|
|
3773
3824
|
let prefix;
|
|
3774
3825
|
const numericVal = getNumeric(val);
|
|
@@ -3811,8 +3862,9 @@ var Iti = class _Iti {
|
|
|
3811
3862
|
//* This is called when the utils request completes.
|
|
3812
3863
|
handleUtils() {
|
|
3813
3864
|
if (intlTelInput.utils) {
|
|
3814
|
-
|
|
3815
|
-
|
|
3865
|
+
const inputValue = this._getTelInputValue();
|
|
3866
|
+
if (inputValue) {
|
|
3867
|
+
this._updateValFromNumber(inputValue);
|
|
3816
3868
|
}
|
|
3817
3869
|
if (this.selectedCountryData.iso2) {
|
|
3818
3870
|
this._updatePlaceholder();
|
|
@@ -3855,11 +3907,13 @@ var Iti = class _Iti {
|
|
|
3855
3907
|
getNumber(format) {
|
|
3856
3908
|
if (intlTelInput.utils) {
|
|
3857
3909
|
const { iso2 } = this.selectedCountryData;
|
|
3858
|
-
|
|
3859
|
-
|
|
3910
|
+
const fullNumber = this._getFullNumber();
|
|
3911
|
+
const formattedNumber = intlTelInput.utils.formatNumber(
|
|
3912
|
+
fullNumber,
|
|
3860
3913
|
iso2,
|
|
3861
3914
|
format
|
|
3862
3915
|
);
|
|
3916
|
+
return this._mapAsciiToUserNumerals(formattedNumber);
|
|
3863
3917
|
}
|
|
3864
3918
|
return "";
|
|
3865
3919
|
}
|
|
@@ -3947,15 +4001,17 @@ var Iti = class _Iti {
|
|
|
3947
4001
|
this._setCountry(iso2Lower);
|
|
3948
4002
|
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
3949
4003
|
if (this.options.formatOnDisplay) {
|
|
3950
|
-
this.
|
|
4004
|
+
const inputValue = this._getTelInputValue();
|
|
4005
|
+
this._updateValFromNumber(inputValue);
|
|
3951
4006
|
}
|
|
3952
4007
|
this._triggerCountryChange();
|
|
3953
4008
|
}
|
|
3954
4009
|
}
|
|
3955
4010
|
//* Set the input value and update the country.
|
|
3956
4011
|
setNumber(number) {
|
|
3957
|
-
const
|
|
3958
|
-
this.
|
|
4012
|
+
const normalisedNumber = this._normaliseNumerals(number);
|
|
4013
|
+
const countryChanged = this._updateCountryFromNumber(normalisedNumber);
|
|
4014
|
+
this._updateValFromNumber(normalisedNumber);
|
|
3959
4015
|
if (countryChanged) {
|
|
3960
4016
|
this._triggerCountryChange();
|
|
3961
4017
|
}
|
|
@@ -4040,7 +4096,7 @@ var intlTelInput = Object.assign(
|
|
|
4040
4096
|
attachUtils,
|
|
4041
4097
|
startedLoadingUtilsScript: false,
|
|
4042
4098
|
startedLoadingAutoCountry: false,
|
|
4043
|
-
version: "25.
|
|
4099
|
+
version: "25.13.0"
|
|
4044
4100
|
}
|
|
4045
4101
|
);
|
|
4046
4102
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -368,12 +368,18 @@ declare module "intl-tel-input" {
|
|
|
368
368
|
private defaultCountry;
|
|
369
369
|
private abortController;
|
|
370
370
|
private dropdownAbortController;
|
|
371
|
+
private userNumeralSet;
|
|
371
372
|
private resolveAutoCountryPromise;
|
|
372
373
|
private rejectAutoCountryPromise;
|
|
373
374
|
private resolveUtilsScriptPromise;
|
|
374
375
|
private rejectUtilsScriptPromise;
|
|
375
376
|
constructor(input: HTMLInputElement, customOptions?: SomeOptions);
|
|
376
377
|
private static _getIsAndroid;
|
|
378
|
+
private _updateNumeralSet;
|
|
379
|
+
private _mapAsciiToUserNumerals;
|
|
380
|
+
private _normaliseNumerals;
|
|
381
|
+
private _getTelInputValue;
|
|
382
|
+
private _setTelInputValue;
|
|
377
383
|
private _createInitPromises;
|
|
378
384
|
_init(): void;
|
|
379
385
|
private _processCountryData;
|
|
@@ -2890,6 +2890,45 @@ var Iti = class _Iti {
|
|
|
2890
2890
|
static _getIsAndroid() {
|
|
2891
2891
|
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2892
2892
|
}
|
|
2893
|
+
_updateNumeralSet(str) {
|
|
2894
|
+
if (/[\u0660-\u0669]/.test(str)) {
|
|
2895
|
+
this.userNumeralSet = "arabic-indic";
|
|
2896
|
+
} else if (/[\u06F0-\u06F9]/.test(str)) {
|
|
2897
|
+
this.userNumeralSet = "persian";
|
|
2898
|
+
} else {
|
|
2899
|
+
this.userNumeralSet = "ascii";
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
_mapAsciiToUserNumerals(str) {
|
|
2903
|
+
if (!this.userNumeralSet) {
|
|
2904
|
+
this._updateNumeralSet(this.ui.telInput.value);
|
|
2905
|
+
}
|
|
2906
|
+
if (this.userNumeralSet === "ascii") {
|
|
2907
|
+
return str;
|
|
2908
|
+
}
|
|
2909
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2910
|
+
return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
|
|
2911
|
+
}
|
|
2912
|
+
// Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
|
|
2913
|
+
_normaliseNumerals(str) {
|
|
2914
|
+
if (!str) {
|
|
2915
|
+
return "";
|
|
2916
|
+
}
|
|
2917
|
+
this._updateNumeralSet(str);
|
|
2918
|
+
if (this.userNumeralSet === "ascii") {
|
|
2919
|
+
return str;
|
|
2920
|
+
}
|
|
2921
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2922
|
+
const regex = this.userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
|
|
2923
|
+
return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
|
|
2924
|
+
}
|
|
2925
|
+
_getTelInputValue() {
|
|
2926
|
+
const inputValue = this.ui.telInput.value.trim();
|
|
2927
|
+
return this._normaliseNumerals(inputValue);
|
|
2928
|
+
}
|
|
2929
|
+
_setTelInputValue(asciiValue) {
|
|
2930
|
+
this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
|
|
2931
|
+
}
|
|
2893
2932
|
_createInitPromises() {
|
|
2894
2933
|
const autoCountryPromise = new Promise((resolve, reject) => {
|
|
2895
2934
|
this.resolveAutoCountryPromise = resolve;
|
|
@@ -2924,8 +2963,9 @@ var Iti = class _Iti {
|
|
|
2924
2963
|
//* 1. Extracting a dial code from the given number
|
|
2925
2964
|
//* 2. Using explicit initialCountry
|
|
2926
2965
|
_setInitialState(overrideAutoCountry = false) {
|
|
2927
|
-
const
|
|
2928
|
-
const
|
|
2966
|
+
const attributeValueRaw = this.ui.telInput.getAttribute("value");
|
|
2967
|
+
const attributeValue = this._normaliseNumerals(attributeValueRaw);
|
|
2968
|
+
const inputValue = this._getTelInputValue();
|
|
2929
2969
|
const useAttribute = attributeValue && attributeValue.startsWith("+") && (!inputValue || !inputValue.startsWith("+"));
|
|
2930
2970
|
const val = useAttribute ? attributeValue : inputValue;
|
|
2931
2971
|
const dialCode = this._getDialCode(val);
|
|
@@ -3096,35 +3136,34 @@ var Iti = class _Iti {
|
|
|
3096
3136
|
countrySearch
|
|
3097
3137
|
} = this.options;
|
|
3098
3138
|
let userOverrideFormatting = false;
|
|
3099
|
-
if (REGEX.ALPHA_UNICODE.test(this.
|
|
3139
|
+
if (REGEX.ALPHA_UNICODE.test(this._getTelInputValue())) {
|
|
3100
3140
|
userOverrideFormatting = true;
|
|
3101
3141
|
}
|
|
3102
3142
|
const handleInputEvent = (e) => {
|
|
3143
|
+
const inputValue = this._getTelInputValue();
|
|
3103
3144
|
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
3104
3145
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3105
|
-
const valueBeforeCaret =
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
);
|
|
3109
|
-
const valueAfterCaret = this.ui.telInput.value.substring(currentCaretPos);
|
|
3110
|
-
this.ui.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
3146
|
+
const valueBeforeCaret = inputValue.substring(0, currentCaretPos - 1);
|
|
3147
|
+
const valueAfterCaret = inputValue.substring(currentCaretPos);
|
|
3148
|
+
this._setTelInputValue(valueBeforeCaret + valueAfterCaret);
|
|
3111
3149
|
this._openDropdownWithPlus();
|
|
3112
3150
|
return;
|
|
3113
3151
|
}
|
|
3114
|
-
if (this._updateCountryFromNumber(
|
|
3152
|
+
if (this._updateCountryFromNumber(inputValue)) {
|
|
3115
3153
|
this._triggerCountryChange();
|
|
3116
3154
|
}
|
|
3117
3155
|
const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
|
|
3118
|
-
const isPaste = e?.inputType === INPUT_TYPES.PASTE &&
|
|
3156
|
+
const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
|
|
3119
3157
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
3120
3158
|
userOverrideFormatting = true;
|
|
3121
|
-
} else if (!REGEX.NON_PLUS_NUMERIC.test(
|
|
3159
|
+
} else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
|
|
3122
3160
|
userOverrideFormatting = false;
|
|
3123
3161
|
}
|
|
3124
3162
|
const isSetNumber = e?.detail && e.detail["isSetNumber"];
|
|
3125
|
-
|
|
3163
|
+
const isAscii = this.userNumeralSet === "ascii";
|
|
3164
|
+
if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
|
|
3126
3165
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3127
|
-
const valueBeforeCaret =
|
|
3166
|
+
const valueBeforeCaret = inputValue.substring(
|
|
3128
3167
|
0,
|
|
3129
3168
|
currentCaretPos
|
|
3130
3169
|
);
|
|
@@ -3136,7 +3175,7 @@ var Iti = class _Iti {
|
|
|
3136
3175
|
const fullNumber = this._getFullNumber();
|
|
3137
3176
|
const formattedValue = formatNumberAsYouType(
|
|
3138
3177
|
fullNumber,
|
|
3139
|
-
|
|
3178
|
+
inputValue,
|
|
3140
3179
|
intlTelInput.utils,
|
|
3141
3180
|
this.selectedCountryData,
|
|
3142
3181
|
this.options.separateDialCode
|
|
@@ -3147,7 +3186,7 @@ var Iti = class _Iti {
|
|
|
3147
3186
|
currentCaretPos,
|
|
3148
3187
|
isDeleteForwards
|
|
3149
3188
|
);
|
|
3150
|
-
this.
|
|
3189
|
+
this._setTelInputValue(formattedValue);
|
|
3151
3190
|
this.ui.telInput.setSelectionRange(newCaretPos, newCaretPos);
|
|
3152
3191
|
}
|
|
3153
3192
|
};
|
|
@@ -3170,12 +3209,18 @@ var Iti = class _Iti {
|
|
|
3170
3209
|
return;
|
|
3171
3210
|
}
|
|
3172
3211
|
if (strictMode) {
|
|
3173
|
-
const
|
|
3174
|
-
const alreadyHasPlus =
|
|
3212
|
+
const inputValue = this._getTelInputValue();
|
|
3213
|
+
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3175
3214
|
const isInitialPlus = !alreadyHasPlus && this.ui.telInput.selectionStart === 0 && e.key === "+";
|
|
3176
|
-
const
|
|
3215
|
+
const normalisedKey = this._normaliseNumerals(e.key);
|
|
3216
|
+
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3177
3217
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3178
|
-
const
|
|
3218
|
+
const input = this.ui.telInput;
|
|
3219
|
+
const selStart = input.selectionStart;
|
|
3220
|
+
const selEnd = input.selectionEnd;
|
|
3221
|
+
const before = inputValue.slice(0, selStart);
|
|
3222
|
+
const after = inputValue.slice(selEnd);
|
|
3223
|
+
const newValue = before + e.key + after;
|
|
3179
3224
|
const newFullNumber = this._getFullNumber(newValue);
|
|
3180
3225
|
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3181
3226
|
newFullNumber,
|
|
@@ -3202,34 +3247,38 @@ var Iti = class _Iti {
|
|
|
3202
3247
|
const input = this.ui.telInput;
|
|
3203
3248
|
const selStart = input.selectionStart;
|
|
3204
3249
|
const selEnd = input.selectionEnd;
|
|
3205
|
-
const
|
|
3206
|
-
const
|
|
3250
|
+
const inputValue = this._getTelInputValue();
|
|
3251
|
+
const before = inputValue.slice(0, selStart);
|
|
3252
|
+
const after = inputValue.slice(selEnd);
|
|
3207
3253
|
const iso2 = this.selectedCountryData.iso2;
|
|
3208
|
-
const
|
|
3254
|
+
const pastedRaw = e.clipboardData.getData("text");
|
|
3255
|
+
const pasted = this._normaliseNumerals(pastedRaw);
|
|
3209
3256
|
const initialCharSelected = selStart === 0 && selEnd > 0;
|
|
3210
|
-
const allowLeadingPlus = !
|
|
3257
|
+
const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
|
|
3211
3258
|
const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
|
|
3212
3259
|
const hasLeadingPlus = allowedChars.startsWith("+");
|
|
3213
3260
|
const numerics = allowedChars.replace(/\+/g, "");
|
|
3214
3261
|
const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
|
|
3215
3262
|
let newVal = before + sanitised + after;
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
}
|
|
3224
|
-
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3225
|
-
if (input.selectionEnd === input.value.length) {
|
|
3226
|
-
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3227
|
-
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3228
|
-
} else {
|
|
3263
|
+
if (newVal.length > 5) {
|
|
3264
|
+
let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3265
|
+
while (coreNumber.length === 0 && newVal.length > 0) {
|
|
3266
|
+
newVal = newVal.slice(0, -1);
|
|
3267
|
+
coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3268
|
+
}
|
|
3269
|
+
if (!coreNumber) {
|
|
3229
3270
|
return;
|
|
3230
3271
|
}
|
|
3272
|
+
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3273
|
+
if (input.selectionEnd === inputValue.length) {
|
|
3274
|
+
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3275
|
+
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3276
|
+
} else {
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3231
3280
|
}
|
|
3232
|
-
|
|
3281
|
+
this._setTelInputValue(newVal);
|
|
3233
3282
|
const caretPos = selStart + sanitised.length;
|
|
3234
3283
|
input.setSelectionRange(caretPos, caretPos);
|
|
3235
3284
|
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
@@ -3380,6 +3429,7 @@ var Iti = class _Iti {
|
|
|
3380
3429
|
this._handleEnterKey();
|
|
3381
3430
|
} else if (e.key === KEYS.ESC) {
|
|
3382
3431
|
this._closeDropdown();
|
|
3432
|
+
this.ui.selectedCountry.focus();
|
|
3383
3433
|
}
|
|
3384
3434
|
}
|
|
3385
3435
|
if (!this.options.countrySearch && REGEX.HIDDEN_SEARCH_CHAR.test(e.key)) {
|
|
@@ -3480,7 +3530,7 @@ var Iti = class _Iti {
|
|
|
3480
3530
|
);
|
|
3481
3531
|
}
|
|
3482
3532
|
number = this._beforeSetNumber(number);
|
|
3483
|
-
this.
|
|
3533
|
+
this._setTelInputValue(number);
|
|
3484
3534
|
}
|
|
3485
3535
|
//* Check if need to select a new country based on the given number
|
|
3486
3536
|
//* Note: called from _setInitialState, keyup handler, setNumber.
|
|
@@ -3654,7 +3704,8 @@ var Iti = class _Iti {
|
|
|
3654
3704
|
const dialCode = listItem.dataset[DATA_KEYS.DIAL_CODE];
|
|
3655
3705
|
this._updateDialCode(dialCode);
|
|
3656
3706
|
if (this.options.formatOnDisplay) {
|
|
3657
|
-
this.
|
|
3707
|
+
const inputValue = this._getTelInputValue();
|
|
3708
|
+
this._updateValFromNumber(inputValue);
|
|
3658
3709
|
}
|
|
3659
3710
|
this.ui.telInput.focus();
|
|
3660
3711
|
if (countryChanged) {
|
|
@@ -3685,7 +3736,7 @@ var Iti = class _Iti {
|
|
|
3685
3736
|
//* Replace any existing dial code with the new one
|
|
3686
3737
|
//* Note: called from _selectListItem and setCountry
|
|
3687
3738
|
_updateDialCode(newDialCodeBare) {
|
|
3688
|
-
const inputVal = this.
|
|
3739
|
+
const inputVal = this._getTelInputValue();
|
|
3689
3740
|
const newDialCode = `+${newDialCodeBare}`;
|
|
3690
3741
|
let newNumber;
|
|
3691
3742
|
if (inputVal.startsWith("+")) {
|
|
@@ -3695,7 +3746,7 @@ var Iti = class _Iti {
|
|
|
3695
3746
|
} else {
|
|
3696
3747
|
newNumber = newDialCode;
|
|
3697
3748
|
}
|
|
3698
|
-
this.
|
|
3749
|
+
this._setTelInputValue(newNumber);
|
|
3699
3750
|
}
|
|
3700
3751
|
}
|
|
3701
3752
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
@@ -3732,7 +3783,7 @@ var Iti = class _Iti {
|
|
|
3732
3783
|
}
|
|
3733
3784
|
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
3734
3785
|
_getFullNumber(overrideVal) {
|
|
3735
|
-
const val = overrideVal
|
|
3786
|
+
const val = overrideVal ? this._normaliseNumerals(overrideVal) : this._getTelInputValue();
|
|
3736
3787
|
const { dialCode } = this.selectedCountryData;
|
|
3737
3788
|
let prefix;
|
|
3738
3789
|
const numericVal = getNumeric(val);
|
|
@@ -3775,8 +3826,9 @@ var Iti = class _Iti {
|
|
|
3775
3826
|
//* This is called when the utils request completes.
|
|
3776
3827
|
handleUtils() {
|
|
3777
3828
|
if (intlTelInput.utils) {
|
|
3778
|
-
|
|
3779
|
-
|
|
3829
|
+
const inputValue = this._getTelInputValue();
|
|
3830
|
+
if (inputValue) {
|
|
3831
|
+
this._updateValFromNumber(inputValue);
|
|
3780
3832
|
}
|
|
3781
3833
|
if (this.selectedCountryData.iso2) {
|
|
3782
3834
|
this._updatePlaceholder();
|
|
@@ -3819,11 +3871,13 @@ var Iti = class _Iti {
|
|
|
3819
3871
|
getNumber(format) {
|
|
3820
3872
|
if (intlTelInput.utils) {
|
|
3821
3873
|
const { iso2 } = this.selectedCountryData;
|
|
3822
|
-
|
|
3823
|
-
|
|
3874
|
+
const fullNumber = this._getFullNumber();
|
|
3875
|
+
const formattedNumber = intlTelInput.utils.formatNumber(
|
|
3876
|
+
fullNumber,
|
|
3824
3877
|
iso2,
|
|
3825
3878
|
format
|
|
3826
3879
|
);
|
|
3880
|
+
return this._mapAsciiToUserNumerals(formattedNumber);
|
|
3827
3881
|
}
|
|
3828
3882
|
return "";
|
|
3829
3883
|
}
|
|
@@ -3911,15 +3965,17 @@ var Iti = class _Iti {
|
|
|
3911
3965
|
this._setCountry(iso2Lower);
|
|
3912
3966
|
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
3913
3967
|
if (this.options.formatOnDisplay) {
|
|
3914
|
-
this.
|
|
3968
|
+
const inputValue = this._getTelInputValue();
|
|
3969
|
+
this._updateValFromNumber(inputValue);
|
|
3915
3970
|
}
|
|
3916
3971
|
this._triggerCountryChange();
|
|
3917
3972
|
}
|
|
3918
3973
|
}
|
|
3919
3974
|
//* Set the input value and update the country.
|
|
3920
3975
|
setNumber(number) {
|
|
3921
|
-
const
|
|
3922
|
-
this.
|
|
3976
|
+
const normalisedNumber = this._normaliseNumerals(number);
|
|
3977
|
+
const countryChanged = this._updateCountryFromNumber(normalisedNumber);
|
|
3978
|
+
this._updateValFromNumber(normalisedNumber);
|
|
3923
3979
|
if (countryChanged) {
|
|
3924
3980
|
this._triggerCountryChange();
|
|
3925
3981
|
}
|
|
@@ -4004,7 +4060,7 @@ var intlTelInput = Object.assign(
|
|
|
4004
4060
|
attachUtils,
|
|
4005
4061
|
startedLoadingUtilsScript: false,
|
|
4006
4062
|
startedLoadingAutoCountry: false,
|
|
4007
|
-
version: "25.
|
|
4063
|
+
version: "25.13.0"
|
|
4008
4064
|
}
|
|
4009
4065
|
);
|
|
4010
4066
|
var intl_tel_input_default = intlTelInput;
|