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.js
CHANGED
|
@@ -3270,6 +3270,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3270
3270
|
constructor(el, options) {
|
|
3271
3271
|
this.nationalDigits = "";
|
|
3272
3272
|
this.displayInternational = false;
|
|
3273
|
+
this.userHasInteracted = false;
|
|
3273
3274
|
this.lastValidation = null;
|
|
3274
3275
|
this.dropdown = null;
|
|
3275
3276
|
this.dialCodeEl = null;
|
|
@@ -3287,6 +3288,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3287
3288
|
if (this.opts.initialValue) {
|
|
3288
3289
|
this.setValueInternal(this.opts.initialValue, true);
|
|
3289
3290
|
}
|
|
3291
|
+
this.invokeGeoIpLookup();
|
|
3290
3292
|
}
|
|
3291
3293
|
}
|
|
3292
3294
|
get isNationalInput() {
|
|
@@ -3324,8 +3326,9 @@ var PhoneInput = class _PhoneInput {
|
|
|
3324
3326
|
return validatePhone(this.nationalDigits, this.selectedCountry);
|
|
3325
3327
|
}
|
|
3326
3328
|
setOptions(opts) {
|
|
3329
|
+
const { geoIpLookup: _, ...rest } = opts;
|
|
3327
3330
|
const prev = { ...this.opts };
|
|
3328
|
-
Object.assign(this.opts,
|
|
3331
|
+
Object.assign(this.opts, rest);
|
|
3329
3332
|
if (opts.allowedCountries !== void 0 || opts.excludedCountries !== void 0) {
|
|
3330
3333
|
this.countries = this.filterCountries(getAllCountries());
|
|
3331
3334
|
if (!this.countries.find((c) => c.code === this.selectedCountry.code)) {
|
|
@@ -3367,6 +3370,16 @@ var PhoneInput = class _PhoneInput {
|
|
|
3367
3370
|
}
|
|
3368
3371
|
this.el.innerHTML = "";
|
|
3369
3372
|
}
|
|
3373
|
+
invokeGeoIpLookup() {
|
|
3374
|
+
const lookup = this.opts.geoIpLookup;
|
|
3375
|
+
if (!lookup) return;
|
|
3376
|
+
this.opts.geoIpLookup = void 0;
|
|
3377
|
+
const signal = this.ac.signal;
|
|
3378
|
+
lookup((countryCode) => {
|
|
3379
|
+
if (signal.aborted || this.userHasInteracted || !countryCode) return;
|
|
3380
|
+
this.setCountry(countryCode);
|
|
3381
|
+
});
|
|
3382
|
+
}
|
|
3370
3383
|
// --- DOM Construction ---
|
|
3371
3384
|
buildDOM() {
|
|
3372
3385
|
this.containerEl = document.createElement("div");
|
|
@@ -3466,6 +3479,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3466
3479
|
this.inputEl.addEventListener("paste", (e) => this.handlePaste(e), { signal });
|
|
3467
3480
|
}
|
|
3468
3481
|
handleInput(e) {
|
|
3482
|
+
this.userHasInteracted = true;
|
|
3469
3483
|
if (this.opts.strict !== false && e.data === "+" && this.isNationalInput) {
|
|
3470
3484
|
this.inputEl.value = this.inputEl.value.replace("+", "");
|
|
3471
3485
|
}
|
|
@@ -3531,6 +3545,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3531
3545
|
}
|
|
3532
3546
|
}
|
|
3533
3547
|
handlePaste(e) {
|
|
3548
|
+
this.userHasInteracted = true;
|
|
3534
3549
|
e.preventDefault();
|
|
3535
3550
|
const text = e.clipboardData?.getData("text") ?? "";
|
|
3536
3551
|
if (!text) return;
|
|
@@ -3569,6 +3584,7 @@ var PhoneInput = class _PhoneInput {
|
|
|
3569
3584
|
// --- Dropdown ---
|
|
3570
3585
|
openDropdown() {
|
|
3571
3586
|
if (this.dropdown) return;
|
|
3587
|
+
this.userHasInteracted = true;
|
|
3572
3588
|
this.dropdown = new Dropdown({
|
|
3573
3589
|
countries: this.countries,
|
|
3574
3590
|
preferredCountries: this.opts.preferredCountries ?? [],
|