intl-tel-input 25.10.6 → 25.10.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-tel-input",
3
- "version": "25.10.6",
3
+ "version": "25.10.7",
4
4
  "description": "A JavaScript plugin for entering and validating international telephone numbers",
5
5
  "keywords": [
6
6
  "international",
package/react/README.md CHANGED
@@ -28,7 +28,7 @@ import "intl-tel-input/styles";
28
28
 
29
29
  See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/validation/ValidationApp.tsx) for a more fleshed-out example of how to handle validation.
30
30
 
31
- A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.6/build/js/utils.js"`.
31
+ A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.7/build/js/utils.js"`.
32
32
 
33
33
  ## Props
34
34
  Here's a list of all of the current props you can pass to the IntlTelInput React component.
@@ -2427,6 +2427,36 @@ var Iti = class _Iti {
2427
2427
  };
2428
2428
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2429
2429
  }
2430
+ if (strictMode) {
2431
+ this._handlePasteEvent = (e) => {
2432
+ e.preventDefault();
2433
+ const input = this.telInput;
2434
+ const selStart = input.selectionStart;
2435
+ const selEnd = input.selectionEnd;
2436
+ const pasted = e.clipboardData.getData("text");
2437
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2438
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2439
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2440
+ const hasLeadingPlus = allowedChars.startsWith("+");
2441
+ const numerics = allowedChars.replace(/\+/g, "");
2442
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2443
+ let newVal = input.value.slice(0, selStart) + sanitised + input.value.slice(selEnd);
2444
+ const coreNumber = intlTelInput.utils.getCoreNumber(newVal, this.selectedCountryData.iso2);
2445
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2446
+ if (input.selectionEnd === input.value.length) {
2447
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2448
+ newVal = newVal.slice(0, newVal.length - trimLength);
2449
+ } else {
2450
+ return;
2451
+ }
2452
+ }
2453
+ input.value = newVal;
2454
+ const caretPos = selStart + sanitised.length;
2455
+ input.setSelectionRange(caretPos, caretPos);
2456
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2457
+ };
2458
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2459
+ }
2430
2460
  }
2431
2461
  //* Adhere to the input's maxlength attr.
2432
2462
  _cap(number) {
@@ -3115,6 +3145,9 @@ var Iti = class _Iti {
3115
3145
  if (this._handleKeydownEvent) {
3116
3146
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3117
3147
  }
3148
+ if (this._handlePasteEvent) {
3149
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3150
+ }
3118
3151
  this.telInput.removeAttribute("data-intl-tel-input-id");
3119
3152
  if (separateDialCode) {
3120
3153
  if (this.isRTL) {
@@ -3293,7 +3326,7 @@ var intlTelInput = Object.assign(
3293
3326
  attachUtils,
3294
3327
  startedLoadingUtilsScript: false,
3295
3328
  startedLoadingAutoCountry: false,
3296
- version: "25.10.6"
3329
+ version: "25.10.7"
3297
3330
  }
3298
3331
  );
3299
3332
  var intl_tel_input_default = intlTelInput;
@@ -416,6 +416,7 @@ declare module "intl-tel-input" {
416
416
  private _handleCountryContainerKeydown;
417
417
  private _handleInputEvent;
418
418
  private _handleKeydownEvent;
419
+ private _handlePasteEvent;
419
420
  private _handleWindowScroll;
420
421
  private _handleMouseoverCountryList;
421
422
  private _handleClickCountryList;
@@ -2391,6 +2391,36 @@ var Iti = class _Iti {
2391
2391
  };
2392
2392
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2393
2393
  }
2394
+ if (strictMode) {
2395
+ this._handlePasteEvent = (e) => {
2396
+ e.preventDefault();
2397
+ const input = this.telInput;
2398
+ const selStart = input.selectionStart;
2399
+ const selEnd = input.selectionEnd;
2400
+ const pasted = e.clipboardData.getData("text");
2401
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2402
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2403
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2404
+ const hasLeadingPlus = allowedChars.startsWith("+");
2405
+ const numerics = allowedChars.replace(/\+/g, "");
2406
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2407
+ let newVal = input.value.slice(0, selStart) + sanitised + input.value.slice(selEnd);
2408
+ const coreNumber = intlTelInput.utils.getCoreNumber(newVal, this.selectedCountryData.iso2);
2409
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2410
+ if (input.selectionEnd === input.value.length) {
2411
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2412
+ newVal = newVal.slice(0, newVal.length - trimLength);
2413
+ } else {
2414
+ return;
2415
+ }
2416
+ }
2417
+ input.value = newVal;
2418
+ const caretPos = selStart + sanitised.length;
2419
+ input.setSelectionRange(caretPos, caretPos);
2420
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2421
+ };
2422
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2423
+ }
2394
2424
  }
2395
2425
  //* Adhere to the input's maxlength attr.
2396
2426
  _cap(number) {
@@ -3079,6 +3109,9 @@ var Iti = class _Iti {
3079
3109
  if (this._handleKeydownEvent) {
3080
3110
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3081
3111
  }
3112
+ if (this._handlePasteEvent) {
3113
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3114
+ }
3082
3115
  this.telInput.removeAttribute("data-intl-tel-input-id");
3083
3116
  if (separateDialCode) {
3084
3117
  if (this.isRTL) {
@@ -3257,7 +3290,7 @@ var intlTelInput = Object.assign(
3257
3290
  attachUtils,
3258
3291
  startedLoadingUtilsScript: false,
3259
3292
  startedLoadingAutoCountry: false,
3260
- version: "25.10.6"
3293
+ version: "25.10.7"
3261
3294
  }
3262
3295
  );
3263
3296
  var intl_tel_input_default = intlTelInput;
@@ -2427,6 +2427,36 @@ var Iti = class _Iti {
2427
2427
  };
2428
2428
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2429
2429
  }
2430
+ if (strictMode) {
2431
+ this._handlePasteEvent = (e) => {
2432
+ e.preventDefault();
2433
+ const input = this.telInput;
2434
+ const selStart = input.selectionStart;
2435
+ const selEnd = input.selectionEnd;
2436
+ const pasted = e.clipboardData.getData("text");
2437
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2438
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2439
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2440
+ const hasLeadingPlus = allowedChars.startsWith("+");
2441
+ const numerics = allowedChars.replace(/\+/g, "");
2442
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2443
+ let newVal = input.value.slice(0, selStart) + sanitised + input.value.slice(selEnd);
2444
+ const coreNumber = intlTelInput.utils.getCoreNumber(newVal, this.selectedCountryData.iso2);
2445
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2446
+ if (input.selectionEnd === input.value.length) {
2447
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2448
+ newVal = newVal.slice(0, newVal.length - trimLength);
2449
+ } else {
2450
+ return;
2451
+ }
2452
+ }
2453
+ input.value = newVal;
2454
+ const caretPos = selStart + sanitised.length;
2455
+ input.setSelectionRange(caretPos, caretPos);
2456
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2457
+ };
2458
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2459
+ }
2430
2460
  }
2431
2461
  //* Adhere to the input's maxlength attr.
2432
2462
  _cap(number) {
@@ -3115,6 +3145,9 @@ var Iti = class _Iti {
3115
3145
  if (this._handleKeydownEvent) {
3116
3146
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3117
3147
  }
3148
+ if (this._handlePasteEvent) {
3149
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3150
+ }
3118
3151
  this.telInput.removeAttribute("data-intl-tel-input-id");
3119
3152
  if (separateDialCode) {
3120
3153
  if (this.isRTL) {
@@ -3293,7 +3326,7 @@ var intlTelInput = Object.assign(
3293
3326
  attachUtils,
3294
3327
  startedLoadingUtilsScript: false,
3295
3328
  startedLoadingAutoCountry: false,
3296
- version: "25.10.6"
3329
+ version: "25.10.7"
3297
3330
  }
3298
3331
  );
3299
3332
  var intl_tel_input_default = intlTelInput;
@@ -2391,6 +2391,36 @@ var Iti = class _Iti {
2391
2391
  };
2392
2392
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2393
2393
  }
2394
+ if (strictMode) {
2395
+ this._handlePasteEvent = (e) => {
2396
+ e.preventDefault();
2397
+ const input = this.telInput;
2398
+ const selStart = input.selectionStart;
2399
+ const selEnd = input.selectionEnd;
2400
+ const pasted = e.clipboardData.getData("text");
2401
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2402
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2403
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2404
+ const hasLeadingPlus = allowedChars.startsWith("+");
2405
+ const numerics = allowedChars.replace(/\+/g, "");
2406
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2407
+ let newVal = input.value.slice(0, selStart) + sanitised + input.value.slice(selEnd);
2408
+ const coreNumber = intlTelInput.utils.getCoreNumber(newVal, this.selectedCountryData.iso2);
2409
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2410
+ if (input.selectionEnd === input.value.length) {
2411
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2412
+ newVal = newVal.slice(0, newVal.length - trimLength);
2413
+ } else {
2414
+ return;
2415
+ }
2416
+ }
2417
+ input.value = newVal;
2418
+ const caretPos = selStart + sanitised.length;
2419
+ input.setSelectionRange(caretPos, caretPos);
2420
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2421
+ };
2422
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2423
+ }
2394
2424
  }
2395
2425
  //* Adhere to the input's maxlength attr.
2396
2426
  _cap(number) {
@@ -3079,6 +3109,9 @@ var Iti = class _Iti {
3079
3109
  if (this._handleKeydownEvent) {
3080
3110
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3081
3111
  }
3112
+ if (this._handlePasteEvent) {
3113
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3114
+ }
3082
3115
  this.telInput.removeAttribute("data-intl-tel-input-id");
3083
3116
  if (separateDialCode) {
3084
3117
  if (this.isRTL) {
@@ -3257,7 +3290,7 @@ var intlTelInput = Object.assign(
3257
3290
  attachUtils,
3258
3291
  startedLoadingUtilsScript: false,
3259
3292
  startedLoadingAutoCountry: false,
3260
- version: "25.10.6"
3293
+ version: "25.10.7"
3261
3294
  }
3262
3295
  );
3263
3296
  var intl_tel_input_default = intlTelInput;
package/vue/README.md CHANGED
@@ -34,7 +34,7 @@ See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master
34
34
  "vue:demo": "vite --config vue/demo/[demo variant]/vite.config.js"
35
35
  ```
36
36
 
37
- A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/vueWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/vue"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.6/build/js/utils.js"`.
37
+ A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/vueWithUtils"`, to include the utils script. Alternatively, if you use the main `"intl-tel-input/vue"` import, then you should couple this with the `loadUtils` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `loadUtils` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@25.10.7/build/js/utils.js"`.
38
38
 
39
39
  ## Props
40
40
  Here's a list of all of the current props you can pass to the IntlTelInput Vue component.