intl-tel-input 25.12.6 → 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 +105 -47
- package/angular/build/IntlTelInputWithUtils.js +105 -47
- 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 +107 -52
- package/build/js/intlTelInput.min.js +4 -4
- package/build/js/intlTelInputWithUtils.js +107 -52
- package/build/js/intlTelInputWithUtils.min.js +6 -6
- package/package.json +1 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +106 -51
- package/react/build/IntlTelInput.d.ts +6 -0
- package/react/build/IntlTelInput.js +106 -51
- package/react/build/IntlTelInputWithUtils.cjs +106 -51
- package/react/build/IntlTelInputWithUtils.js +106 -51
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +325 -285
- package/vue/build/IntlTelInputWithUtils.mjs +570 -530
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* International Telephone Input v25.
|
|
2
|
+
* International Telephone Input v25.13.0
|
|
3
3
|
* https://github.com/jackocnr/intl-tel-input.git
|
|
4
4
|
* Licensed under the MIT license
|
|
5
5
|
*/
|
|
@@ -2930,6 +2930,45 @@ var factoryOutput = (() => {
|
|
|
2930
2930
|
static _getIsAndroid() {
|
|
2931
2931
|
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2932
2932
|
}
|
|
2933
|
+
_updateNumeralSet(str) {
|
|
2934
|
+
if (/[\u0660-\u0669]/.test(str)) {
|
|
2935
|
+
this.userNumeralSet = "arabic-indic";
|
|
2936
|
+
} else if (/[\u06F0-\u06F9]/.test(str)) {
|
|
2937
|
+
this.userNumeralSet = "persian";
|
|
2938
|
+
} else {
|
|
2939
|
+
this.userNumeralSet = "ascii";
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
_mapAsciiToUserNumerals(str) {
|
|
2943
|
+
if (!this.userNumeralSet) {
|
|
2944
|
+
this._updateNumeralSet(this.ui.telInput.value);
|
|
2945
|
+
}
|
|
2946
|
+
if (this.userNumeralSet === "ascii") {
|
|
2947
|
+
return str;
|
|
2948
|
+
}
|
|
2949
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2950
|
+
return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
|
|
2951
|
+
}
|
|
2952
|
+
// Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
|
|
2953
|
+
_normaliseNumerals(str) {
|
|
2954
|
+
if (!str) {
|
|
2955
|
+
return "";
|
|
2956
|
+
}
|
|
2957
|
+
this._updateNumeralSet(str);
|
|
2958
|
+
if (this.userNumeralSet === "ascii") {
|
|
2959
|
+
return str;
|
|
2960
|
+
}
|
|
2961
|
+
const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
|
|
2962
|
+
const regex = this.userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
|
|
2963
|
+
return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
|
|
2964
|
+
}
|
|
2965
|
+
_getTelInputValue() {
|
|
2966
|
+
const inputValue = this.ui.telInput.value.trim();
|
|
2967
|
+
return this._normaliseNumerals(inputValue);
|
|
2968
|
+
}
|
|
2969
|
+
_setTelInputValue(asciiValue) {
|
|
2970
|
+
this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
|
|
2971
|
+
}
|
|
2933
2972
|
_createInitPromises() {
|
|
2934
2973
|
const autoCountryPromise = new Promise((resolve, reject) => {
|
|
2935
2974
|
this.resolveAutoCountryPromise = resolve;
|
|
@@ -2964,8 +3003,9 @@ var factoryOutput = (() => {
|
|
|
2964
3003
|
//* 1. Extracting a dial code from the given number
|
|
2965
3004
|
//* 2. Using explicit initialCountry
|
|
2966
3005
|
_setInitialState(overrideAutoCountry = false) {
|
|
2967
|
-
const
|
|
2968
|
-
const
|
|
3006
|
+
const attributeValueRaw = this.ui.telInput.getAttribute("value");
|
|
3007
|
+
const attributeValue = this._normaliseNumerals(attributeValueRaw);
|
|
3008
|
+
const inputValue = this._getTelInputValue();
|
|
2969
3009
|
const useAttribute = attributeValue && attributeValue.startsWith("+") && (!inputValue || !inputValue.startsWith("+"));
|
|
2970
3010
|
const val = useAttribute ? attributeValue : inputValue;
|
|
2971
3011
|
const dialCode = this._getDialCode(val);
|
|
@@ -3136,35 +3176,34 @@ var factoryOutput = (() => {
|
|
|
3136
3176
|
countrySearch
|
|
3137
3177
|
} = this.options;
|
|
3138
3178
|
let userOverrideFormatting = false;
|
|
3139
|
-
if (REGEX.ALPHA_UNICODE.test(this.
|
|
3179
|
+
if (REGEX.ALPHA_UNICODE.test(this._getTelInputValue())) {
|
|
3140
3180
|
userOverrideFormatting = true;
|
|
3141
3181
|
}
|
|
3142
3182
|
const handleInputEvent = (e) => {
|
|
3183
|
+
const inputValue = this._getTelInputValue();
|
|
3143
3184
|
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
3144
3185
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3145
|
-
const valueBeforeCaret =
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
);
|
|
3149
|
-
const valueAfterCaret = this.ui.telInput.value.substring(currentCaretPos);
|
|
3150
|
-
this.ui.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
3186
|
+
const valueBeforeCaret = inputValue.substring(0, currentCaretPos - 1);
|
|
3187
|
+
const valueAfterCaret = inputValue.substring(currentCaretPos);
|
|
3188
|
+
this._setTelInputValue(valueBeforeCaret + valueAfterCaret);
|
|
3151
3189
|
this._openDropdownWithPlus();
|
|
3152
3190
|
return;
|
|
3153
3191
|
}
|
|
3154
|
-
if (this._updateCountryFromNumber(
|
|
3192
|
+
if (this._updateCountryFromNumber(inputValue)) {
|
|
3155
3193
|
this._triggerCountryChange();
|
|
3156
3194
|
}
|
|
3157
3195
|
const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
|
|
3158
|
-
const isPaste = e?.inputType === INPUT_TYPES.PASTE &&
|
|
3196
|
+
const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
|
|
3159
3197
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
3160
3198
|
userOverrideFormatting = true;
|
|
3161
|
-
} else if (!REGEX.NON_PLUS_NUMERIC.test(
|
|
3199
|
+
} else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
|
|
3162
3200
|
userOverrideFormatting = false;
|
|
3163
3201
|
}
|
|
3164
3202
|
const isSetNumber = e?.detail && e.detail["isSetNumber"];
|
|
3165
|
-
|
|
3203
|
+
const isAscii = this.userNumeralSet === "ascii";
|
|
3204
|
+
if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
|
|
3166
3205
|
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
3167
|
-
const valueBeforeCaret =
|
|
3206
|
+
const valueBeforeCaret = inputValue.substring(
|
|
3168
3207
|
0,
|
|
3169
3208
|
currentCaretPos
|
|
3170
3209
|
);
|
|
@@ -3176,7 +3215,7 @@ var factoryOutput = (() => {
|
|
|
3176
3215
|
const fullNumber = this._getFullNumber();
|
|
3177
3216
|
const formattedValue = formatNumberAsYouType(
|
|
3178
3217
|
fullNumber,
|
|
3179
|
-
|
|
3218
|
+
inputValue,
|
|
3180
3219
|
intlTelInput.utils,
|
|
3181
3220
|
this.selectedCountryData,
|
|
3182
3221
|
this.options.separateDialCode
|
|
@@ -3187,7 +3226,7 @@ var factoryOutput = (() => {
|
|
|
3187
3226
|
currentCaretPos,
|
|
3188
3227
|
isDeleteForwards
|
|
3189
3228
|
);
|
|
3190
|
-
this.
|
|
3229
|
+
this._setTelInputValue(formattedValue);
|
|
3191
3230
|
this.ui.telInput.setSelectionRange(newCaretPos, newCaretPos);
|
|
3192
3231
|
}
|
|
3193
3232
|
};
|
|
@@ -3210,12 +3249,18 @@ var factoryOutput = (() => {
|
|
|
3210
3249
|
return;
|
|
3211
3250
|
}
|
|
3212
3251
|
if (strictMode) {
|
|
3213
|
-
const
|
|
3214
|
-
const alreadyHasPlus =
|
|
3252
|
+
const inputValue = this._getTelInputValue();
|
|
3253
|
+
const alreadyHasPlus = inputValue.startsWith("+");
|
|
3215
3254
|
const isInitialPlus = !alreadyHasPlus && this.ui.telInput.selectionStart === 0 && e.key === "+";
|
|
3216
|
-
const
|
|
3255
|
+
const normalisedKey = this._normaliseNumerals(e.key);
|
|
3256
|
+
const isNumeric = /^[0-9]$/.test(normalisedKey);
|
|
3217
3257
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
3218
|
-
const
|
|
3258
|
+
const input = this.ui.telInput;
|
|
3259
|
+
const selStart = input.selectionStart;
|
|
3260
|
+
const selEnd = input.selectionEnd;
|
|
3261
|
+
const before = inputValue.slice(0, selStart);
|
|
3262
|
+
const after = inputValue.slice(selEnd);
|
|
3263
|
+
const newValue = before + e.key + after;
|
|
3219
3264
|
const newFullNumber = this._getFullNumber(newValue);
|
|
3220
3265
|
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3221
3266
|
newFullNumber,
|
|
@@ -3242,34 +3287,38 @@ var factoryOutput = (() => {
|
|
|
3242
3287
|
const input = this.ui.telInput;
|
|
3243
3288
|
const selStart = input.selectionStart;
|
|
3244
3289
|
const selEnd = input.selectionEnd;
|
|
3245
|
-
const
|
|
3246
|
-
const
|
|
3290
|
+
const inputValue = this._getTelInputValue();
|
|
3291
|
+
const before = inputValue.slice(0, selStart);
|
|
3292
|
+
const after = inputValue.slice(selEnd);
|
|
3247
3293
|
const iso2 = this.selectedCountryData.iso2;
|
|
3248
|
-
const
|
|
3294
|
+
const pastedRaw = e.clipboardData.getData("text");
|
|
3295
|
+
const pasted = this._normaliseNumerals(pastedRaw);
|
|
3249
3296
|
const initialCharSelected = selStart === 0 && selEnd > 0;
|
|
3250
|
-
const allowLeadingPlus = !
|
|
3297
|
+
const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
|
|
3251
3298
|
const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
|
|
3252
3299
|
const hasLeadingPlus = allowedChars.startsWith("+");
|
|
3253
3300
|
const numerics = allowedChars.replace(/\+/g, "");
|
|
3254
3301
|
const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
|
|
3255
3302
|
let newVal = before + sanitised + after;
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
}
|
|
3264
|
-
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3265
|
-
if (input.selectionEnd === input.value.length) {
|
|
3266
|
-
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3267
|
-
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3268
|
-
} else {
|
|
3303
|
+
if (newVal.length > 5) {
|
|
3304
|
+
let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3305
|
+
while (coreNumber.length === 0 && newVal.length > 0) {
|
|
3306
|
+
newVal = newVal.slice(0, -1);
|
|
3307
|
+
coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
|
|
3308
|
+
}
|
|
3309
|
+
if (!coreNumber) {
|
|
3269
3310
|
return;
|
|
3270
3311
|
}
|
|
3312
|
+
if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
|
|
3313
|
+
if (input.selectionEnd === inputValue.length) {
|
|
3314
|
+
const trimLength = coreNumber.length - this.maxCoreNumberLength;
|
|
3315
|
+
newVal = newVal.slice(0, newVal.length - trimLength);
|
|
3316
|
+
} else {
|
|
3317
|
+
return;
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3271
3320
|
}
|
|
3272
|
-
|
|
3321
|
+
this._setTelInputValue(newVal);
|
|
3273
3322
|
const caretPos = selStart + sanitised.length;
|
|
3274
3323
|
input.setSelectionRange(caretPos, caretPos);
|
|
3275
3324
|
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
@@ -3521,7 +3570,7 @@ var factoryOutput = (() => {
|
|
|
3521
3570
|
);
|
|
3522
3571
|
}
|
|
3523
3572
|
number = this._beforeSetNumber(number);
|
|
3524
|
-
this.
|
|
3573
|
+
this._setTelInputValue(number);
|
|
3525
3574
|
}
|
|
3526
3575
|
//* Check if need to select a new country based on the given number
|
|
3527
3576
|
//* Note: called from _setInitialState, keyup handler, setNumber.
|
|
@@ -3695,7 +3744,8 @@ var factoryOutput = (() => {
|
|
|
3695
3744
|
const dialCode = listItem.dataset[DATA_KEYS.DIAL_CODE];
|
|
3696
3745
|
this._updateDialCode(dialCode);
|
|
3697
3746
|
if (this.options.formatOnDisplay) {
|
|
3698
|
-
this.
|
|
3747
|
+
const inputValue = this._getTelInputValue();
|
|
3748
|
+
this._updateValFromNumber(inputValue);
|
|
3699
3749
|
}
|
|
3700
3750
|
this.ui.telInput.focus();
|
|
3701
3751
|
if (countryChanged) {
|
|
@@ -3726,7 +3776,7 @@ var factoryOutput = (() => {
|
|
|
3726
3776
|
//* Replace any existing dial code with the new one
|
|
3727
3777
|
//* Note: called from _selectListItem and setCountry
|
|
3728
3778
|
_updateDialCode(newDialCodeBare) {
|
|
3729
|
-
const inputVal = this.
|
|
3779
|
+
const inputVal = this._getTelInputValue();
|
|
3730
3780
|
const newDialCode = `+${newDialCodeBare}`;
|
|
3731
3781
|
let newNumber;
|
|
3732
3782
|
if (inputVal.startsWith("+")) {
|
|
@@ -3736,7 +3786,7 @@ var factoryOutput = (() => {
|
|
|
3736
3786
|
} else {
|
|
3737
3787
|
newNumber = newDialCode;
|
|
3738
3788
|
}
|
|
3739
|
-
this.
|
|
3789
|
+
this._setTelInputValue(newNumber);
|
|
3740
3790
|
}
|
|
3741
3791
|
}
|
|
3742
3792
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
@@ -3773,7 +3823,7 @@ var factoryOutput = (() => {
|
|
|
3773
3823
|
}
|
|
3774
3824
|
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
3775
3825
|
_getFullNumber(overrideVal) {
|
|
3776
|
-
const val = overrideVal
|
|
3826
|
+
const val = overrideVal ? this._normaliseNumerals(overrideVal) : this._getTelInputValue();
|
|
3777
3827
|
const { dialCode } = this.selectedCountryData;
|
|
3778
3828
|
let prefix;
|
|
3779
3829
|
const numericVal = getNumeric(val);
|
|
@@ -3816,8 +3866,9 @@ var factoryOutput = (() => {
|
|
|
3816
3866
|
//* This is called when the utils request completes.
|
|
3817
3867
|
handleUtils() {
|
|
3818
3868
|
if (intlTelInput.utils) {
|
|
3819
|
-
|
|
3820
|
-
|
|
3869
|
+
const inputValue = this._getTelInputValue();
|
|
3870
|
+
if (inputValue) {
|
|
3871
|
+
this._updateValFromNumber(inputValue);
|
|
3821
3872
|
}
|
|
3822
3873
|
if (this.selectedCountryData.iso2) {
|
|
3823
3874
|
this._updatePlaceholder();
|
|
@@ -3860,11 +3911,13 @@ var factoryOutput = (() => {
|
|
|
3860
3911
|
getNumber(format) {
|
|
3861
3912
|
if (intlTelInput.utils) {
|
|
3862
3913
|
const { iso2 } = this.selectedCountryData;
|
|
3863
|
-
|
|
3864
|
-
|
|
3914
|
+
const fullNumber = this._getFullNumber();
|
|
3915
|
+
const formattedNumber = intlTelInput.utils.formatNumber(
|
|
3916
|
+
fullNumber,
|
|
3865
3917
|
iso2,
|
|
3866
3918
|
format
|
|
3867
3919
|
);
|
|
3920
|
+
return this._mapAsciiToUserNumerals(formattedNumber);
|
|
3868
3921
|
}
|
|
3869
3922
|
return "";
|
|
3870
3923
|
}
|
|
@@ -3952,15 +4005,17 @@ var factoryOutput = (() => {
|
|
|
3952
4005
|
this._setCountry(iso2Lower);
|
|
3953
4006
|
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
3954
4007
|
if (this.options.formatOnDisplay) {
|
|
3955
|
-
this.
|
|
4008
|
+
const inputValue = this._getTelInputValue();
|
|
4009
|
+
this._updateValFromNumber(inputValue);
|
|
3956
4010
|
}
|
|
3957
4011
|
this._triggerCountryChange();
|
|
3958
4012
|
}
|
|
3959
4013
|
}
|
|
3960
4014
|
//* Set the input value and update the country.
|
|
3961
4015
|
setNumber(number) {
|
|
3962
|
-
const
|
|
3963
|
-
this.
|
|
4016
|
+
const normalisedNumber = this._normaliseNumerals(number);
|
|
4017
|
+
const countryChanged = this._updateCountryFromNumber(normalisedNumber);
|
|
4018
|
+
this._updateValFromNumber(normalisedNumber);
|
|
3964
4019
|
if (countryChanged) {
|
|
3965
4020
|
this._triggerCountryChange();
|
|
3966
4021
|
}
|
|
@@ -4045,7 +4100,7 @@ var factoryOutput = (() => {
|
|
|
4045
4100
|
attachUtils,
|
|
4046
4101
|
startedLoadingUtilsScript: false,
|
|
4047
4102
|
startedLoadingAutoCountry: false,
|
|
4048
|
-
version: "25.
|
|
4103
|
+
version: "25.13.0"
|
|
4049
4104
|
}
|
|
4050
4105
|
);
|
|
4051
4106
|
var intl_tel_input_default = intlTelInput;
|