lite-phone-input 0.3.0 → 0.4.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 +30 -0
- package/dist/core/index.d.cts +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/preact/index.cjs +19 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.cts +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +19 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +19 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +19 -1
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/index.cjs +17 -1
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.d.cts +3 -0
- package/dist/vanilla/index.d.ts +3 -0
- package/dist/vanilla/index.global.js +17 -1
- package/dist/vanilla/index.global.js.map +1 -1
- package/dist/vanilla/index.js +17 -1
- package/dist/vanilla/index.js.map +1 -1
- package/package.json +1 -1
package/dist/vanilla/index.cjs
CHANGED
|
@@ -3296,6 +3296,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3296
3296
|
constructor(el, options) {
|
|
3297
3297
|
this.nationalDigits = "";
|
|
3298
3298
|
this.displayInternational = false;
|
|
3299
|
+
this.userHasInteracted = false;
|
|
3299
3300
|
this.lastValidation = null;
|
|
3300
3301
|
this.dropdown = null;
|
|
3301
3302
|
this.dialCodeEl = null;
|
|
@@ -3313,6 +3314,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3313
3314
|
if (this.opts.initialValue) {
|
|
3314
3315
|
this.setValueInternal(this.opts.initialValue, true);
|
|
3315
3316
|
}
|
|
3317
|
+
this.invokeGeoIpLookup();
|
|
3316
3318
|
}
|
|
3317
3319
|
}
|
|
3318
3320
|
get isNationalInput() {
|
|
@@ -3350,8 +3352,9 @@ var PhoneInput = class _PhoneInput {
|
|
|
3350
3352
|
return validatePhone(this.nationalDigits, this.selectedCountry);
|
|
3351
3353
|
}
|
|
3352
3354
|
setOptions(opts) {
|
|
3355
|
+
const { geoIpLookup: _, ...rest } = opts;
|
|
3353
3356
|
const prev = { ...this.opts };
|
|
3354
|
-
Object.assign(this.opts,
|
|
3357
|
+
Object.assign(this.opts, rest);
|
|
3355
3358
|
if (opts.allowedCountries !== void 0 || opts.excludedCountries !== void 0) {
|
|
3356
3359
|
this.countries = this.filterCountries(getAllCountries());
|
|
3357
3360
|
if (!this.countries.find((c) => c.code === this.selectedCountry.code)) {
|
|
@@ -3393,6 +3396,16 @@ var PhoneInput = class _PhoneInput {
|
|
|
3393
3396
|
}
|
|
3394
3397
|
this.el.innerHTML = "";
|
|
3395
3398
|
}
|
|
3399
|
+
invokeGeoIpLookup() {
|
|
3400
|
+
const lookup = this.opts.geoIpLookup;
|
|
3401
|
+
if (!lookup) return;
|
|
3402
|
+
this.opts.geoIpLookup = void 0;
|
|
3403
|
+
const signal = this.ac.signal;
|
|
3404
|
+
lookup((countryCode) => {
|
|
3405
|
+
if (signal.aborted || this.userHasInteracted || !countryCode) return;
|
|
3406
|
+
this.setCountry(countryCode);
|
|
3407
|
+
});
|
|
3408
|
+
}
|
|
3396
3409
|
// --- DOM Construction ---
|
|
3397
3410
|
buildDOM() {
|
|
3398
3411
|
this.containerEl = document.createElement("div");
|
|
@@ -3492,6 +3505,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3492
3505
|
this.inputEl.addEventListener("paste", (e) => this.handlePaste(e), { signal });
|
|
3493
3506
|
}
|
|
3494
3507
|
handleInput(e) {
|
|
3508
|
+
this.userHasInteracted = true;
|
|
3495
3509
|
if (this.opts.strict !== false && e.data === "+" && this.isNationalInput) {
|
|
3496
3510
|
this.inputEl.value = this.inputEl.value.replace("+", "");
|
|
3497
3511
|
}
|
|
@@ -3557,6 +3571,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3557
3571
|
}
|
|
3558
3572
|
}
|
|
3559
3573
|
handlePaste(e) {
|
|
3574
|
+
this.userHasInteracted = true;
|
|
3560
3575
|
e.preventDefault();
|
|
3561
3576
|
const text = e.clipboardData?.getData("text") ?? "";
|
|
3562
3577
|
if (!text) return;
|
|
@@ -3595,6 +3610,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3595
3610
|
// --- Dropdown ---
|
|
3596
3611
|
openDropdown() {
|
|
3597
3612
|
if (this.dropdown) return;
|
|
3613
|
+
this.userHasInteracted = true;
|
|
3598
3614
|
this.dropdown = new Dropdown({
|
|
3599
3615
|
countries: this.countries,
|
|
3600
3616
|
preferredCountries: this.opts.preferredCountries ?? [],
|