@desource/phone-mask-vue 0.2.2 → 0.3.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/CHANGELOG.md +21 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/index.cjs +184 -214
- package/dist/index.js +184 -214
- package/dist/index.mjs +184 -214
- package/dist/phone-mask-vue.css +64 -64
- package/dist/types/components/PhoneInput.vue.d.ts.map +1 -1
- package/dist/types/composables/useCountrySelector.d.ts.map +1 -1
- package/dist/types/consts.d.ts +0 -4
- package/dist/types/consts.d.ts.map +1 -1
- package/dist/types/directives/vPhoneMask.d.ts.map +1 -1
- package/dist/types/types.d.ts +0 -4
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,65 +1,75 @@
|
|
|
1
1
|
import { computed, ref, nextTick, watch, defineComponent, useSlots, useModel, useTemplateRef, shallowRef, onBeforeUnmount, openBlock, createElementBlock, normalizeStyle, normalizeClass, createElementVNode, unref, renderSlot, createTextVNode, toDisplayString, createCommentVNode, createVNode, Transition, withCtx, createBlock, Teleport, withDirectives, withKeys, withModifiers, isRef, vModelText, Fragment, renderList, mergeModels } from "vue";
|
|
2
2
|
const M = { AC: "+247 #####", AD: ["+376 ### ###", "+376 #### ####"], AE: ["+971 # ### ####", "+971 ## ### ####", "+971 ### ######", "+971 ### # #####"], AF: "+93 ## ### ####", AG: "+1 ###-###-####", AI: "+1 ###-###-####", AL: ["+355 ## ### ###", "+355 ## ### ####", "+355 ### ####", "+355 ### ###", "+355 ### #####"], AM: ["+374 ## ######", "+374 ### ## ###"], AO: "+244 ### ### ###", AR: ["+54 ## ####-####", "+54 # ## ####-####", "+54 ###-###-####"], AS: "+1 ###-###-####", AT: ["+43 # #########", "+43 ### ######"], AU: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###", "+61 ## ### ##"], AW: "+297 ### ####", AX: ["+358 ## #######", "+358 ### ######"], AZ: ["+994 ## ### ## ##", "+994 ### ## ## ##"], BA: ["+387 ## ###-###", "+387 ## ### ###"], BB: "+1 ###-###-####", BD: ["+880 #-#######", "+880 ####-######", "+880 ###-#######"], BE: ["+32 ## ## ## ##", "+32 ### ## ## ##", "+32 ### ## ###"], BF: "+226 ## ## ## ##", BG: ["+359 # ### ###", "+359 ## ### ###", "+359 ### ## ###"], BH: "+973 #### ####", BI: "+257 ## ## ## ##", BJ: ["+229 ## ## ## ## ##", "+229 ## ## ## ##"], BL: "+590 ### ## ## ##", BM: "+1 ###-###-####", BN: "+673 ### ####", BO: ["+591 # #######", "+591 ########", "+591 ### ## ####"], BQ: "+599 ### ####", BR: ["+55 ## ####-####", "+55 ## #####-####", "+55 ### ## ####", "+55 ####-####"], BS: "+1 ###-###-####", BT: ["+975 # ### ###", "+975 ## ## ## ##"], BW: ["+267 ### ####", "+267 ## ### ###", "+267 #### ### ###", "+267 ## #####"], BY: ["+375 ### ##-##-##", "+375 ## ###-##-##", "+375 ### ### ####"], BZ: ["+501 ###-####", "+501 #-###-####-###"], CA: "+1 ###-###-####", CC: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CD: ["+243 ## #####", "+243 ### ### ###"], CF: "+236 ## ## ## ##", CG: ["+242 ## ### ####", "+242 # #### ####"], CH: ["+41 ## ### ## ##", "+41 ### ### ###"], CI: ["+225 ## ## # #####", "+225 ## ## ## ####"], CK: "+682 ## ###", CL: ["+56 ### ### ###", "+56 # #### ####", "+56 ### ### ####", "+56 ## ### ####"], CM: ["+237 # ## ## ## ##", "+237 ## ## ## ##"], CN: ["+86 ## #### ####", "+86 ### #### ####", "+86 ### ### ####", "+86 ########"], CO: ["+57 ### #######", "+57 # ### #######"], CR: ["+506 #### ####", "+506 ###-###-####"], CU: ["+53 # #######", "+53 ### #######"], CV: "+238 ### ## ##", CW: ["+599 # ### ####", "+599 ### ####"], CX: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CY: "+357 ## ######", CZ: "+420 ### ### ###", DE: ["+49 ## ######", "+49 #### #######", "+49 ### ##########", "+49 ### # ######", "+49 ### # ####", "+49 ### #### ####", "+49 ########"], DJ: "+253 ## ## ## ##", DK: "+45 ## ## ## ##", DM: "+1 ###-###-####", DO: "+1 ###-###-####", DZ: ["+213 ## ## ## ##", "+213 ### ## ## ##", "+213 ## ### ## ##"], EC: ["+593 #-###-####", "+593 ## ### ####", "+593 #### ### ####"], EE: ["+372 ### ####", "+372 #### ####", "+372 ## ## ####"], EG: ["+20 # ########", "+20 ## ########", "+20 ### ### ####"], EH: ["+212 # ## ## ## ##", "+212 ##-#######"], ER: "+291 # ### ###", ES: ["+34 ### ## ## ##", "+34 ### ### ###"], ET: "+251 ## ### ####", FI: ["+358 ## #######", "+358 ### ######"], FJ: ["+679 ### ####", "+679 #### ### ####"], FK: "+500 #####", FM: "+691 ### ####", FO: "+298 ######", FR: ["+33 # ## ## ## ##", "+33 ### ## ## ##"], GA: "+241 ## ## ## ##", GB: ["+44 ### ### ####", "+44 #### ######", "+44 ## #### ####"], GD: "+1 ###-###-####", GE: ["+995 ## ### ## ##", "+995 ### ## ## ##", "+995 ### ### ###"], GF: "+594 ### ## ## ##", GG: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], GH: ["+233 ## ### ####", "+233 ### #####"], GI: ["+350 ### #####", "+350 ########"], GL: "+299 ## ## ##", GM: "+220 ### ####", GN: ["+224 ## ## ## ##", "+224 ### ## ## ##"], GP: "+590 ### ## ## ##", GQ: ["+240 ### ### ###", "+240 ### ######"], GR: ["+30 ## #### ####", "+30 ### ### ####"], GT: ["+502 #### ####", "+502 #### ### ####"], GU: "+1 ###-###-####", GW: ["+245 ### ### ###", "+245 ### ####"], GY: "+592 ### ####", HK: ["+852 #### ####", "+852 ### ### ###", "+852 ### ## ### ###"], HN: ["+504 ####-####", "+504 ###########"], HR: ["+385 # #### ###", "+385 ## ### ####", "+385 ### ### ###", "+385 ## ## ###", "+385 ## ### ###"], HT: "+509 ## ## ####", HU: ["+36 # ### ####", "+36 ## ### ####", "+36 ## ### ###"], ID: ["+62 ## #######", "+62 ###-###-###", "+62 ### #######", "+62 ### # ### ###", "+62 ### ### ####"], IE: ["+353 ## #####", "+353 ## ### ####", "+353 #### ### ###", "+353 ### ### ###"], IL: ["+972 #-###-####", "+972 ##-###-####", "+972 #-###-###-###"], IM: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], IN: ["+91 ##### #####", "+91 #### ## ####", "+91 #### ### ### ###", "+91 #### ### ####"], IO: "+246 ### ####", IQ: ["+964 # ### ####", "+964 ### ### ####"], IR: ["+98 ## #### ####", "+98 ### ### ####"], IS: "+354 ### ####", IT: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], JE: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], JM: "+1 ###-###-####", JO: ["+962 # ### ####", "+962 # #### ####", "+962 ### #####", "+962 ## #######"], JP: ["+81 #-####-####", "+81 ##-####-####", "+81 ###-###-###", "+81 ##-###-####"], KE: ["+254 ## #######", "+254 ### ######", "+254 ### ### ###"], KG: ["+996 ### ### ###", "+996 ### ### # ##"], KH: ["+855 ## ### ###", "+855 #### ### ###"], KI: ["+686 #####", "+686 ########"], KM: "+269 ### ## ##", KN: "+1 ###-###-####", KP: ["+850 # ### ####", "+850 ### ### ####"], KR: ["+82 #-###-####", "+82 ##-####-####", "+82 ##-###-####"], KW: ["+965 #### ####", "+965 ### #####", "+965 #### ###"], KY: "+1 ###-###-####", KZ: ["+7 ##### # ## ##", "+7 ### ### ####", "+7 ### ###-##-##"], LA: ["+856 ## ### ###", "+856 ## ## ### ###"], LB: ["+961 # ### ###", "+961 ## ### ###"], LC: "+1 ###-###-####", LI: ["+423 ### ## ##", "+423 ### ### ###"], LK: ["+94 ### ### ###", "+94 ## ### ####"], LR: ["+231 ## ### ###", "+231 ## ### ####"], LS: "+266 #### ####", LT: ["+370 ### #####", "+370 ### ## ###"], LU: ["+352 ## ## ## ##", "+352 ### ### ###", "+352 ### ## ###"], LV: "+371 ## ### ###", LY: "+218 ##-#######", MA: ["+212 # ## ## ## ##", "+212 ##-#######"], MC: ["+377 ## ## ## ##", "+377 # ## ## ## ##"], MD: ["+373 ## ### ###", "+373 ### ## ###", "+373 ### #####"], ME: "+382 ## ### ###", MF: "+590 ### ## ## ##", MG: "+261 ## ## ### ##", MH: "+692 ###-####", MK: ["+389 # ### ####", "+389 ## ### ###", "+389 ### # ## ##"], ML: "+223 ## ## ## ##", MM: ["+95 # ### ###", "+95 # ### ####", "+95 ### ### ####"], MN: "+976 #### ####", MO: ["+853 #### ####", "+853 #### ###"], MP: "+1 ###-###-####", MQ: "+596 ### ## ## ##", MR: "+222 ## ## ## ##", MS: "+1 ###-###-####", MT: "+356 #### ####", MU: ["+230 #### ####", "+230 ### ####"], MV: ["+960 ###-####", "+960 ### ### ####"], MW: ["+265 # ### ###", "+265 ### ## ## ##"], MX: "+52 ### ### ####", MY: ["+60 #-#### ####", "+60 ##-### ####", "+60 #-###-##-####", "+60 ###-### ####"], MZ: ["+258 ## ### ###", "+258 ## ### ####", "+258 ### ### ###"], NA: ["+264 ## ### ###", "+264 ## ### ####", "+264 ### ### ###"], NC: "+687 ##.##.##", NE: ["+227 ## ## ## ##", "+227 ## ### ###"], NF: ["+672 ## ####", "+672 # #####"], NG: ["+234 #### ## ####", "+234 ### ### ####", "+234 ### #### ####"], NI: "+505 #### ####", NL: ["+31 ## ### ####", "+31 # ########", "+31 ### ####", "+31 ## #######"], NO: ["+47 ## ## ## ##", "+47 ### ## ###"], NP: ["+977 #-#######", "+977 ###-#######", "+977 ###########"], NR: "+674 ### ####", NU: ["+683 ####", "+683 ### ####"], NZ: ["+64 # ### ####", "+64 ## ### ####", "+64 ### ### ###"], OM: ["+968 ## ######", "+968 #### ####", "+968 ### #####"], PA: ["+507 ###-####", "+507 ####-####"], PE: ["+51 # #######", "+51 ### ### ###", "+51 ### #####"], PF: ["+689 ## ## ## ##", "+689 ### ## ## ##"], PG: ["+675 ### ####", "+675 #### ####"], PH: ["+63 # #### ####", "+63 ### ### ####", "+63 #### # ### ####"], PK: ["+92 ## ########", "+92 ### #######", "+92 ### ### ##", "+92 #### #####"], PL: ["+48 ## ### ## ##", "+48 ### ### ###"], PM: ["+508 ## ## ##", "+508 ### ## ## ##"], PR: "+1 ###-###-####", PS: ["+970 # ### ####", "+970 ### ### ###", "+970 #### ### ###"], PT: ["+351 ## ### ####", "+351 ### ### ###"], PW: "+680 ### ####", PY: ["+595 ## ### ####", "+595 ### ######", "+595 #### ### ####"], QA: ["+974 #### ####", "+974 ### ####"], RE: "+262 ### ## ## ##", RO: ["+40 ## ### ####", "+40 ### ### ###"], RS: ["+381 ## ######", "+381 ## #######", "+381 ### #####"], RU: "+7 ### ###-##-##", RW: "+250 ### ### ###", SA: ["+966 ## ### ####", "+966 ### ### ####", "+966 #### #####"], SB: ["+677 #####", "+677 ## #####"], SC: ["+248 # ### ###", "+248 #######"], SD: "+249 ## ### ####", SE: ["+46 # ## ## ##", "+46 ## ### ## ##", "+46 ## ## ## ##", "+46 ### ## ## ###"], SG: ["+65 #### ####", "+65 #### ### ####"], SH: "+290 #####", SI: ["+386 # ### ## ##", "+386 ## ### ###", "+386 ## ######", "+386 ### #####"], SJ: ["+47 ## ## ## ##", "+47 ### ## ###"], SK: ["+421 #/### ### ##", "+421 ### ### ###", "+421 #######"], SL: "+232 ## ######", SM: ["+378 #### ######", "+378 ## ## ## ##"], SN: ["+221 ## ### ## ##", "+221 ### ## ## ##"], SO: ["+252 # ######", "+252 # #######"], SR: ["+597 ###-###", "+597 ###-####", "+597 ##-##-##"], SS: "+211 ### ### ###", ST: "+239 ### ####", SV: ["+503 #### ####", "+503 ### ####"], SX: "+1 ###-###-####", SY: ["+963 ## ### ####", "+963 ### ### ###"], SZ: ["+268 #### ####", "+268 ##### ####"], TA: "+290 ####", TC: "+1 ###-###-####", TD: "+235 ## ## ## ##", TG: "+228 ## ## ## ##", TH: ["+66 # ### ####", "+66 ## ### ####", "+66 #### ### ###"], TJ: ["+992 ### ## ####", "+992 ## ### ####"], TK: "+690 ####", TL: ["+670 ### ####", "+670 #### ####"], TM: ["+993 ## ##-##-##", "+993 ## ######"], TN: "+216 ## ### ###", TO: ["+676 ##-###", "+676 ### ####", "+676 #### ###"], TR: ["+90 ### ### ## ##", "+90 ### ### ####"], TT: "+1 ###-###-####", TV: ["+688 ## ###", "+688 ## ####"], TW: ["+886 # #### ####", "+886 ### ### ###", "+886 ## ### ####", "+886 ## #### ####"], TZ: ["+255 ## ### ####", "+255 ### ### ###", "+255 ### ## ####"], UA: ["+380 #### #####", "+380 ## ### ####", "+380 ### ### ###"], UG: ["+256 ## #######", "+256 ### ######"], US: "+1 ###-###-####", UY: ["+598 #### ####", "+598 ## ### ###", "+598 ### ####"], UZ: "+998 ## ### ## ##", VA: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], VC: "+1 ###-###-####", VE: "+58 ###-#######", VG: "+1 ###-###-####", VI: "+1 ###-###-####", VN: ["+84 ### #### ###", "+84 ### ### ###", "+84 #### ######", "+84 ## ### ## ##"], VU: ["+678 #####", "+678 ### ####"], WF: ["+681 ## ## ##", "+681 ### ## ## ##"], WS: ["+685 #####", "+685 ## #####", "+685 ### ###"], XK: ["+383 ## ### ###", "+383 ### #####"], YE: ["+967 # ### ###", "+967 ### ### ###"], YT: "+262 ### ## ## ##", ZA: ["+27 ## ### ####", "+27 ### ### ###"], ZM: ["+260 ### ### ###", "+260 ## #######", "+260 #########"], ZW: ["+263 ## #####", "+263 ## ### ####", "+263 ### ####", "+263 #### ######"] };
|
|
3
|
-
const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (
|
|
4
|
-
if (!t$1.test(
|
|
5
|
-
const t2 = typeof
|
|
6
|
-
throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string" === t2 ?
|
|
3
|
+
const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (o2) => {
|
|
4
|
+
if (!t$1.test(o2)) {
|
|
5
|
+
const t2 = typeof o2;
|
|
6
|
+
throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string" === t2 ? o2 : t2}' instead.`);
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
return String.fromCodePoint(...
|
|
8
|
+
const e2 = [...o2.toUpperCase()].map((t2) => (t2.codePointAt(0) ?? 0) + 127397);
|
|
9
|
+
return String.fromCodePoint(...e2);
|
|
10
10
|
};
|
|
11
|
-
const t = Object.entries(M), divideMask = (
|
|
12
|
-
function getCodeAndMask(
|
|
11
|
+
const t = Object.entries(M), divideMask = (e2) => e2.split(/ (.*)/s);
|
|
12
|
+
function getCodeAndMask(e2) {
|
|
13
13
|
let n = "", t2 = "";
|
|
14
|
-
if (Array.isArray(
|
|
15
|
-
const
|
|
16
|
-
for (const t3 of
|
|
17
|
-
const [
|
|
18
|
-
n || (n =
|
|
14
|
+
if (Array.isArray(e2)) {
|
|
15
|
+
const o2 = [];
|
|
16
|
+
for (const t3 of e2) {
|
|
17
|
+
const [e3, s2] = divideMask(t3);
|
|
18
|
+
n || (n = e3), o2.push(s2);
|
|
19
19
|
}
|
|
20
|
-
t2 =
|
|
20
|
+
t2 = o2;
|
|
21
21
|
} else {
|
|
22
|
-
const [
|
|
23
|
-
n =
|
|
22
|
+
const [o2, s2] = divideMask(e2);
|
|
23
|
+
n = o2, t2 = s2;
|
|
24
24
|
}
|
|
25
25
|
return [n, t2];
|
|
26
26
|
}
|
|
27
|
-
t.map(([
|
|
28
|
-
t.reduce((
|
|
29
|
-
const [
|
|
30
|
-
return
|
|
27
|
+
t.map(([e2, n]) => ({ id: e2, mask: n }));
|
|
28
|
+
t.reduce((e2, [n, t2]) => {
|
|
29
|
+
const [o2, s2] = getCodeAndMask(t2);
|
|
30
|
+
return e2[n] = { code: o2, mask: s2 }, e2;
|
|
31
31
|
}, {});
|
|
32
|
-
t.map(([
|
|
33
|
-
const [t2,
|
|
34
|
-
return { id:
|
|
32
|
+
t.map(([e2, n]) => {
|
|
33
|
+
const [t2, o2] = getCodeAndMask(n);
|
|
34
|
+
return { id: e2, code: t2, mask: o2 };
|
|
35
35
|
});
|
|
36
|
-
t.reduce((
|
|
37
|
-
const [
|
|
38
|
-
return
|
|
36
|
+
t.reduce((e2, [t2, o2]) => {
|
|
37
|
+
const [s2, a] = getCodeAndMask(o2);
|
|
38
|
+
return e2[t2] = { code: s2, mask: a, flag: countryCodeEmoji(t2) }, e2;
|
|
39
39
|
}, {});
|
|
40
|
-
t.map(([
|
|
41
|
-
const [
|
|
42
|
-
return { id:
|
|
40
|
+
t.map(([e2, t2]) => {
|
|
41
|
+
const [o2, s2] = getCodeAndMask(t2);
|
|
42
|
+
return { id: e2, code: o2, mask: s2, flag: countryCodeEmoji(e2) };
|
|
43
43
|
});
|
|
44
|
-
const MasksFullMap = (
|
|
45
|
-
const
|
|
46
|
-
return t.reduce((
|
|
47
|
-
const [a, r] = getCodeAndMask(
|
|
48
|
-
return
|
|
44
|
+
const MasksFullMap = (e2) => {
|
|
45
|
+
const o2 = new Intl.DisplayNames([e2], { type: "region" });
|
|
46
|
+
return t.reduce((e3, [t2, s2]) => {
|
|
47
|
+
const [a, r] = getCodeAndMask(s2), d = o2.of(t2) ?? "";
|
|
48
|
+
return e3[t2] = { code: a, mask: r, name: d, flag: countryCodeEmoji(t2) }, e3;
|
|
49
49
|
}, {});
|
|
50
|
-
}, MasksFull = (
|
|
51
|
-
const
|
|
52
|
-
return t.map(([
|
|
53
|
-
const [
|
|
54
|
-
return { id:
|
|
50
|
+
}, MasksFull = (e2) => {
|
|
51
|
+
const o2 = new Intl.DisplayNames([e2], { type: "region" });
|
|
52
|
+
return t.map(([e3, t2]) => {
|
|
53
|
+
const [s2, a] = getCodeAndMask(t2);
|
|
54
|
+
return { id: e3, code: s2, mask: a, name: o2.of(e3) ?? "", flag: countryCodeEmoji(e3) };
|
|
55
55
|
});
|
|
56
|
-
}, m = t.reduce((
|
|
57
|
-
const [
|
|
58
|
-
return
|
|
59
|
-
}, {}), i = t.map(([
|
|
60
|
-
const [
|
|
61
|
-
return { id:
|
|
56
|
+
}, m = t.reduce((e2, [t2, o2]) => {
|
|
57
|
+
const [s2, a] = getCodeAndMask(o2), r = new Intl.DisplayNames(["en"], { type: "region" });
|
|
58
|
+
return e2[t2] = { code: s2, mask: a, name: r.of(t2) ?? "", flag: countryCodeEmoji(t2) }, e2;
|
|
59
|
+
}, {}), i = t.map(([e2, t2]) => {
|
|
60
|
+
const [o2, s2] = getCodeAndMask(t2);
|
|
61
|
+
return { id: e2, code: o2, mask: s2, name: new Intl.DisplayNames(["en"], { type: "region" }).of(e2) ?? "", flag: countryCodeEmoji(e2) };
|
|
62
62
|
}), g = countryCodeEmoji;
|
|
63
|
+
function getNavigatorLang() {
|
|
64
|
+
return "undefined" != typeof navigator && navigator.language || "en";
|
|
65
|
+
}
|
|
66
|
+
function getMasksFullMapByLocale(e2) {
|
|
67
|
+
return e2.toLowerCase().startsWith("en") ? m : MasksFullMap(e2);
|
|
68
|
+
}
|
|
69
|
+
function getCountry(t2, n) {
|
|
70
|
+
const e2 = getMasksFullMapByLocale(n), r = t2.toUpperCase();
|
|
71
|
+
return r in e2 ? { id: r, ...e2[r] } : { id: "US", ...e2.US };
|
|
72
|
+
}
|
|
63
73
|
function toArray(t2) {
|
|
64
74
|
return Array.isArray(t2) ? t2 : [t2];
|
|
65
75
|
}
|
|
@@ -71,35 +81,60 @@ function removeCountryCodePrefix(t2) {
|
|
|
71
81
|
}
|
|
72
82
|
function pickMaskVariant(t2, n) {
|
|
73
83
|
if (1 === t2.length) return t2[0];
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
77
|
-
return
|
|
84
|
+
const e2 = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), r = e2.filter((t3) => t3.count >= n).sort((t3, n2) => t3.count - n2.count);
|
|
85
|
+
if (r.length > 0) return r[0].mask;
|
|
86
|
+
const o2 = e2.sort((t3, n2) => n2.count - t3.count)[0];
|
|
87
|
+
return o2 ? o2.mask : t2[0];
|
|
78
88
|
}
|
|
79
89
|
function formatDigitsWithMap(t2, n) {
|
|
80
|
-
let
|
|
81
|
-
const
|
|
82
|
-
let
|
|
83
|
-
const
|
|
84
|
-
for (let
|
|
85
|
-
const
|
|
86
|
-
if ("#" ===
|
|
87
|
-
if (!(
|
|
88
|
-
|
|
90
|
+
let e2 = "";
|
|
91
|
+
const r = [];
|
|
92
|
+
let o2 = 0;
|
|
93
|
+
const a = n.length, i2 = t2.length;
|
|
94
|
+
for (let u = 0; u < i2; u++) {
|
|
95
|
+
const i3 = t2[u];
|
|
96
|
+
if ("#" === i3) {
|
|
97
|
+
if (!(o2 < a)) break;
|
|
98
|
+
e2 += n[o2], r.push(o2), o2++;
|
|
89
99
|
} else {
|
|
90
|
-
const n2 = -1 !== t2.indexOf("#",
|
|
91
|
-
(
|
|
100
|
+
const n2 = -1 !== t2.indexOf("#", u + 1) && o2 < a;
|
|
101
|
+
(e2.length > 0 || n2) && (e2 += i3, r.push(-1));
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
|
-
return { display:
|
|
104
|
+
return { display: e2, map: r };
|
|
105
|
+
}
|
|
106
|
+
const o = "https://ipapi.co/json/", e = 1500, p = "@desource/phone-mask:geo", s = 864e5;
|
|
107
|
+
async function detectCountryFromGeoIP(e$1 = o, r = e) {
|
|
108
|
+
const c = new AbortController(), n = setTimeout(() => c.abort(), r);
|
|
109
|
+
try {
|
|
110
|
+
const t2 = await fetch(e$1, { signal: c.signal, headers: { Accept: "application/json" } });
|
|
111
|
+
if (clearTimeout(n), !t2.ok) return null;
|
|
112
|
+
const o2 = await t2.json();
|
|
113
|
+
return (o2.country || o2.country_code || o2.countryCode || o2.country_code2 || "").toString().toUpperCase() || null;
|
|
114
|
+
} catch {
|
|
115
|
+
return clearTimeout(n), null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function detectByGeoIp(t2) {
|
|
119
|
+
try {
|
|
120
|
+
const o3 = localStorage.getItem(p);
|
|
121
|
+
if (o3) {
|
|
122
|
+
const c = JSON.parse(o3), n = Date.now() - c.ts > s;
|
|
123
|
+
if (!n && c.country_code && t2(c.country_code)) return c.country_code.toUpperCase();
|
|
124
|
+
n && localStorage.removeItem(p);
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
const o2 = await detectCountryFromGeoIP();
|
|
129
|
+
if (o2 && t2(o2)) {
|
|
130
|
+
try {
|
|
131
|
+
localStorage.setItem(p, JSON.stringify({ country_code: o2, ts: Date.now() }));
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
return o2;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
95
137
|
}
|
|
96
|
-
const CACHE_KEY = "@desource/phone-mask:geo";
|
|
97
|
-
const CACHE_EXPIRY_MS = 24 * 60 * 6e4;
|
|
98
|
-
const GEO_IP_TIMEOUT = 1500;
|
|
99
|
-
const GEO_IP_URL = "https://ipapi.co/json/";
|
|
100
|
-
const Delimiters = [" ", "-", "(", ")"];
|
|
101
|
-
const NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"];
|
|
102
|
-
const InvalidPattern = /[^\d\s\-()]/;
|
|
103
138
|
const emptyCountry = { id: "", code: "", mask: "", flag: "", name: "" };
|
|
104
139
|
function useCountrySelector(usedLocale) {
|
|
105
140
|
const isEnLocale = computed(() => usedLocale.value.toLowerCase().startsWith("en"));
|
|
@@ -151,7 +186,7 @@ function useCountrySelector(usedLocale) {
|
|
|
151
186
|
dropdownOpened.value = !dropdownOpened.value;
|
|
152
187
|
if (!dropdownOpened.value) return;
|
|
153
188
|
await nextTick();
|
|
154
|
-
searchRef.value?.focus();
|
|
189
|
+
searchRef.value?.focus({ preventScroll: true });
|
|
155
190
|
focusedIndex.value = 0;
|
|
156
191
|
};
|
|
157
192
|
const closeDropdown = () => {
|
|
@@ -173,7 +208,7 @@ function useCountrySelector(usedLocale) {
|
|
|
173
208
|
};
|
|
174
209
|
const detectFromLocale = () => {
|
|
175
210
|
try {
|
|
176
|
-
const lang =
|
|
211
|
+
const lang = getNavigatorLang();
|
|
177
212
|
try {
|
|
178
213
|
const loc = new Intl.Locale(lang);
|
|
179
214
|
if (loc.region && hasCountry(loc.region)) return loc.region.toUpperCase();
|
|
@@ -185,46 +220,6 @@ function useCountrySelector(usedLocale) {
|
|
|
185
220
|
}
|
|
186
221
|
return null;
|
|
187
222
|
};
|
|
188
|
-
const detectByGeoIp = async () => {
|
|
189
|
-
try {
|
|
190
|
-
const cached = localStorage.getItem(CACHE_KEY);
|
|
191
|
-
if (cached) {
|
|
192
|
-
const parsed = JSON.parse(cached);
|
|
193
|
-
const isExpired = Date.now() - parsed.ts > CACHE_EXPIRY_MS;
|
|
194
|
-
if (!isExpired && parsed.country_code && hasCountry(parsed.country_code)) {
|
|
195
|
-
return parsed.country_code.toUpperCase();
|
|
196
|
-
}
|
|
197
|
-
if (isExpired) {
|
|
198
|
-
localStorage.removeItem(CACHE_KEY);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
} catch {
|
|
202
|
-
}
|
|
203
|
-
const controller = new AbortController();
|
|
204
|
-
const timeoutId = setTimeout(() => controller.abort(), GEO_IP_TIMEOUT);
|
|
205
|
-
try {
|
|
206
|
-
const res = await fetch(GEO_IP_URL, {
|
|
207
|
-
signal: controller.signal,
|
|
208
|
-
headers: { Accept: "application/json" }
|
|
209
|
-
});
|
|
210
|
-
if (!res.ok) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
const json = await res.json();
|
|
214
|
-
const code = (json.country || json.country_code || json.countryCode || json.country_code2 || "").toString().toUpperCase();
|
|
215
|
-
if (code && hasCountry(code)) {
|
|
216
|
-
try {
|
|
217
|
-
localStorage.setItem(CACHE_KEY, JSON.stringify({ country_code: code, ts: Date.now() }));
|
|
218
|
-
} catch {
|
|
219
|
-
}
|
|
220
|
-
return code;
|
|
221
|
-
}
|
|
222
|
-
} catch {
|
|
223
|
-
} finally {
|
|
224
|
-
clearTimeout(timeoutId);
|
|
225
|
-
}
|
|
226
|
-
return null;
|
|
227
|
-
};
|
|
228
223
|
const selectInitialCountry = (id, emitFn) => {
|
|
229
224
|
const previousId = selectedId.value;
|
|
230
225
|
selectedId.value = id;
|
|
@@ -237,7 +232,7 @@ function useCountrySelector(usedLocale) {
|
|
|
237
232
|
return;
|
|
238
233
|
}
|
|
239
234
|
if (!detect) return;
|
|
240
|
-
const geo = await detectByGeoIp();
|
|
235
|
+
const geo = await detectByGeoIp(hasCountry);
|
|
241
236
|
if (geo) {
|
|
242
237
|
selectInitialCountry(geo, emitFn);
|
|
243
238
|
return;
|
|
@@ -333,6 +328,9 @@ function getSelection(el) {
|
|
|
333
328
|
if (!el) return [0, 0];
|
|
334
329
|
return [el.selectionStart ?? 0, el.selectionEnd ?? 0];
|
|
335
330
|
}
|
|
331
|
+
const Delimiters = [" ", "-", "(", ")"];
|
|
332
|
+
const NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"];
|
|
333
|
+
const InvalidPattern = /[^\d\s\-()]/;
|
|
336
334
|
function useMask(selected, telRef) {
|
|
337
335
|
const digits = ref("");
|
|
338
336
|
const displayValue = ref("");
|
|
@@ -363,17 +361,17 @@ function useMask(selected, telRef) {
|
|
|
363
361
|
if (startIdx >= endIdx) return;
|
|
364
362
|
digits.value = digits.value.slice(0, startIdx) + digits.value.slice(endIdx);
|
|
365
363
|
};
|
|
366
|
-
const handleBeforeInput = (
|
|
367
|
-
const el =
|
|
364
|
+
const handleBeforeInput = (e2) => {
|
|
365
|
+
const el = e2.target;
|
|
368
366
|
if (!el) return;
|
|
369
|
-
const data =
|
|
370
|
-
if (
|
|
367
|
+
const data = e2.data;
|
|
368
|
+
if (e2.inputType !== "insertText" || !data) return;
|
|
371
369
|
if (InvalidPattern.test(data) || data === " " && el.value.endsWith(" ")) {
|
|
372
|
-
|
|
370
|
+
e2.preventDefault();
|
|
373
371
|
}
|
|
374
372
|
};
|
|
375
|
-
const handleInput = (
|
|
376
|
-
const el =
|
|
373
|
+
const handleInput = (e2) => {
|
|
374
|
+
const el = e2.target;
|
|
377
375
|
if (!el) return;
|
|
378
376
|
const newDigits = extractDigits(el.value, maxDigits.value);
|
|
379
377
|
showValidationHint.value = false;
|
|
@@ -391,13 +389,13 @@ function useMask(selected, telRef) {
|
|
|
391
389
|
setCaretToDigitPosition(digits.value.length);
|
|
392
390
|
});
|
|
393
391
|
};
|
|
394
|
-
const handleKeydownInternal = (
|
|
395
|
-
const el = telRef.value ??
|
|
392
|
+
const handleKeydownInternal = (e2) => {
|
|
393
|
+
const el = telRef.value ?? e2.target;
|
|
396
394
|
if (!el) return;
|
|
397
|
-
if (
|
|
395
|
+
if (e2.ctrlKey || e2.metaKey || e2.altKey || NavigationKeys.includes(e2.key)) return;
|
|
398
396
|
const [selStart, selEnd] = getSelection(el);
|
|
399
|
-
if (
|
|
400
|
-
|
|
397
|
+
if (e2.key === "Backspace") {
|
|
398
|
+
e2.preventDefault();
|
|
401
399
|
if (selStart !== selEnd) {
|
|
402
400
|
const range = formatter.value.getDigitRange(digits.value, selStart, selEnd);
|
|
403
401
|
if (range) {
|
|
@@ -426,8 +424,8 @@ function useMask(selected, telRef) {
|
|
|
426
424
|
}
|
|
427
425
|
return;
|
|
428
426
|
}
|
|
429
|
-
if (
|
|
430
|
-
|
|
427
|
+
if (e2.key === "Delete") {
|
|
428
|
+
e2.preventDefault();
|
|
431
429
|
if (selStart !== selEnd) {
|
|
432
430
|
const range = formatter.value.getDigitRange(digits.value, selStart, selEnd);
|
|
433
431
|
if (range) {
|
|
@@ -449,30 +447,30 @@ function useMask(selected, telRef) {
|
|
|
449
447
|
}
|
|
450
448
|
return;
|
|
451
449
|
}
|
|
452
|
-
if (/^[0-9]$/.test(
|
|
450
|
+
if (/^[0-9]$/.test(e2.key)) {
|
|
453
451
|
if (digits.value.length >= maxDigits.value) {
|
|
454
|
-
|
|
452
|
+
e2.preventDefault();
|
|
455
453
|
}
|
|
456
454
|
return;
|
|
457
455
|
}
|
|
458
|
-
if (
|
|
459
|
-
|
|
456
|
+
if (e2.key.length === 1) {
|
|
457
|
+
e2.preventDefault();
|
|
460
458
|
}
|
|
461
459
|
};
|
|
462
|
-
const handleKeydown = (
|
|
460
|
+
const handleKeydown = (e2) => {
|
|
463
461
|
showValidationHint.value = false;
|
|
464
462
|
if (validationTimer.value) {
|
|
465
463
|
clearTimeout(validationTimer.value);
|
|
466
464
|
}
|
|
467
|
-
handleKeydownInternal(
|
|
465
|
+
handleKeydownInternal(e2);
|
|
468
466
|
if (validationTimer.value) clearTimeout(validationTimer.value);
|
|
469
467
|
validationTimer.value = setTimeout(() => {
|
|
470
468
|
if (!isComplete.value && !isEmpty.value) showValidationHint.value = true;
|
|
471
469
|
}, 300);
|
|
472
470
|
};
|
|
473
|
-
const handlePaste = (
|
|
474
|
-
|
|
475
|
-
const text =
|
|
471
|
+
const handlePaste = (e2) => {
|
|
472
|
+
e2.preventDefault();
|
|
473
|
+
const text = e2.clipboardData?.getData("text") || "";
|
|
476
474
|
const pastedDigits = extractDigits(text, maxDigits.value);
|
|
477
475
|
if (pastedDigits.length === 0) return;
|
|
478
476
|
const el = telRef.value;
|
|
@@ -663,11 +661,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
663
661
|
const liveRef = useTemplateRef("liveRef");
|
|
664
662
|
const dropdownRef = useTemplateRef("dropdownRef");
|
|
665
663
|
const usedLocale = computed(() => {
|
|
666
|
-
|
|
667
|
-
if (typeof navigator !== "undefined") {
|
|
668
|
-
return navigator.language || "en";
|
|
669
|
-
}
|
|
670
|
-
return "en";
|
|
664
|
+
return props.locale || getNavigatorLang();
|
|
671
665
|
});
|
|
672
666
|
const dropdownStyle = shallowRef({});
|
|
673
667
|
const countrySelector = useCountrySelector(usedLocale);
|
|
@@ -724,30 +718,30 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
724
718
|
digits: digits.value
|
|
725
719
|
});
|
|
726
720
|
};
|
|
727
|
-
const onInput = async (
|
|
721
|
+
const onInput = async (e2) => {
|
|
728
722
|
if (inactive.value) return;
|
|
729
|
-
mask.handleInput(
|
|
723
|
+
mask.handleInput(e2);
|
|
730
724
|
await nextTick();
|
|
731
725
|
emitModelUpdate();
|
|
732
726
|
};
|
|
733
|
-
const onKeydown = async (
|
|
727
|
+
const onKeydown = async (e2) => {
|
|
734
728
|
if (inactive.value) return;
|
|
735
|
-
mask.handleKeydown(
|
|
729
|
+
mask.handleKeydown(e2);
|
|
736
730
|
await nextTick();
|
|
737
731
|
emitModelUpdate();
|
|
738
732
|
};
|
|
739
|
-
const onPaste = async (
|
|
733
|
+
const onPaste = async (e2) => {
|
|
740
734
|
if (inactive.value) return;
|
|
741
|
-
mask.handlePaste(
|
|
735
|
+
mask.handlePaste(e2);
|
|
742
736
|
await nextTick();
|
|
743
737
|
emitModelUpdate();
|
|
744
738
|
};
|
|
745
|
-
const onFocus = (
|
|
739
|
+
const onFocus = (e2) => {
|
|
746
740
|
mask.handleFocus();
|
|
747
741
|
dropdownOpened.value = false;
|
|
748
|
-
emit("focus",
|
|
742
|
+
emit("focus", e2);
|
|
749
743
|
};
|
|
750
|
-
const onBlur = (
|
|
744
|
+
const onBlur = (e2) => emit("blur", e2);
|
|
751
745
|
const onSelectCountry = async (countryId) => {
|
|
752
746
|
countrySelector.selectCountry(countryId);
|
|
753
747
|
emit("country-change", selected.value);
|
|
@@ -773,8 +767,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
773
767
|
await nextTick();
|
|
774
768
|
telRef.value?.focus();
|
|
775
769
|
};
|
|
776
|
-
const positionDropdown = (
|
|
777
|
-
if (
|
|
770
|
+
const positionDropdown = (e2) => {
|
|
771
|
+
if (e2?.type === "scroll" && e2.target && dropdownRef.value?.contains(e2.target)) return;
|
|
778
772
|
const root = rootRef.value;
|
|
779
773
|
if (!root) return;
|
|
780
774
|
const rect = root.getBoundingClientRect();
|
|
@@ -805,7 +799,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
805
799
|
await nextTick();
|
|
806
800
|
const list = dropdownRef.value?.lastElementChild;
|
|
807
801
|
if (!list) return;
|
|
808
|
-
list.children[focusedIndex.value]
|
|
802
|
+
const option = list.children[focusedIndex.value];
|
|
803
|
+
if (!option) return;
|
|
804
|
+
const listRect = list.getBoundingClientRect();
|
|
805
|
+
const optionRect = option.getBoundingClientRect();
|
|
806
|
+
let scrollAmount = 0;
|
|
807
|
+
if (optionRect.top < listRect.top) {
|
|
808
|
+
scrollAmount = list.scrollTop - (listRect.top - optionRect.top);
|
|
809
|
+
} else if (optionRect.bottom > listRect.bottom) {
|
|
810
|
+
scrollAmount = list.scrollTop + (optionRect.bottom - listRect.bottom);
|
|
811
|
+
} else {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
list.scrollTo({ top: scrollAmount, behavior: "smooth" });
|
|
809
815
|
};
|
|
810
816
|
const onDocClick = (ev) => {
|
|
811
817
|
const dropdown = dropdownRef.value;
|
|
@@ -1104,42 +1110,7 @@ const _export_sfc = (sfc, props) => {
|
|
|
1104
1110
|
}
|
|
1105
1111
|
return target;
|
|
1106
1112
|
};
|
|
1107
|
-
const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
1108
|
-
function getNavigatorLang() {
|
|
1109
|
-
if (typeof navigator !== "undefined") {
|
|
1110
|
-
return navigator.language || "";
|
|
1111
|
-
}
|
|
1112
|
-
return "";
|
|
1113
|
-
}
|
|
1114
|
-
function getCountry(countryCode, locale) {
|
|
1115
|
-
const isEn = locale.toLowerCase().startsWith("en");
|
|
1116
|
-
const countriesMap = isEn ? m : MasksFullMap(locale);
|
|
1117
|
-
const id = countryCode.toUpperCase();
|
|
1118
|
-
const found = countriesMap[id];
|
|
1119
|
-
return found ? { id, ...found } : null;
|
|
1120
|
-
}
|
|
1121
|
-
function getDefaultCountry(locale) {
|
|
1122
|
-
const isEn = locale.toLowerCase().startsWith("en");
|
|
1123
|
-
const countries = isEn ? m : MasksFullMap(locale);
|
|
1124
|
-
return { id: "US", ...countries.US };
|
|
1125
|
-
}
|
|
1126
|
-
async function detectCountryFromGeoIP() {
|
|
1127
|
-
try {
|
|
1128
|
-
const controller = new AbortController();
|
|
1129
|
-
const timeoutId = setTimeout(() => controller.abort(), GEO_IP_TIMEOUT);
|
|
1130
|
-
const res = await fetch(GEO_IP_URL, {
|
|
1131
|
-
signal: controller.signal,
|
|
1132
|
-
headers: { Accept: "application/json" }
|
|
1133
|
-
});
|
|
1134
|
-
clearTimeout(timeoutId);
|
|
1135
|
-
if (!res.ok) return null;
|
|
1136
|
-
const json = await res.json();
|
|
1137
|
-
const code = (json.country || json.country_code || json.countryCode || json.country_code2 || "").toString().toUpperCase();
|
|
1138
|
-
return code || null;
|
|
1139
|
-
} catch {
|
|
1140
|
-
return null;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1113
|
+
const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-755b15ee"]]);
|
|
1143
1114
|
function detectCountryFromLocale() {
|
|
1144
1115
|
try {
|
|
1145
1116
|
const lang = getNavigatorLang();
|
|
@@ -1162,24 +1133,24 @@ async function initState(binding) {
|
|
|
1162
1133
|
} else if (typeof value === "object" && value !== null) {
|
|
1163
1134
|
options = value;
|
|
1164
1135
|
}
|
|
1165
|
-
const locale = options.locale || getNavigatorLang()
|
|
1166
|
-
let country
|
|
1136
|
+
const locale = options.locale || getNavigatorLang();
|
|
1137
|
+
let country;
|
|
1167
1138
|
if (options.country) {
|
|
1168
1139
|
country = getCountry(options.country, locale);
|
|
1169
1140
|
} else if (options.detect) {
|
|
1170
1141
|
const geoCountry = await detectCountryFromGeoIP();
|
|
1171
1142
|
if (geoCountry) {
|
|
1172
1143
|
country = getCountry(geoCountry, locale);
|
|
1173
|
-
}
|
|
1174
|
-
if (!country) {
|
|
1144
|
+
} else {
|
|
1175
1145
|
const localeCountry = detectCountryFromLocale();
|
|
1176
1146
|
if (localeCountry) {
|
|
1177
1147
|
country = getCountry(localeCountry, locale);
|
|
1148
|
+
} else {
|
|
1149
|
+
country = getCountry("US", locale);
|
|
1178
1150
|
}
|
|
1179
1151
|
}
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
country = getDefaultCountry(locale);
|
|
1152
|
+
} else {
|
|
1153
|
+
country = getCountry("US", locale);
|
|
1183
1154
|
}
|
|
1184
1155
|
return {
|
|
1185
1156
|
country,
|
|
@@ -1202,17 +1173,17 @@ function updateDisplay(el, state) {
|
|
|
1202
1173
|
}
|
|
1203
1174
|
}
|
|
1204
1175
|
function createBeforeInputHandler(el) {
|
|
1205
|
-
return (
|
|
1206
|
-
const data =
|
|
1207
|
-
if (
|
|
1176
|
+
return (e2) => {
|
|
1177
|
+
const data = e2.data;
|
|
1178
|
+
if (e2.inputType !== "insertText" || !data) return;
|
|
1208
1179
|
if (InvalidPattern.test(data) || data === " " && el.value.endsWith(" ")) {
|
|
1209
|
-
|
|
1180
|
+
e2.preventDefault();
|
|
1210
1181
|
}
|
|
1211
1182
|
};
|
|
1212
1183
|
}
|
|
1213
1184
|
function createInputHandler(el, state) {
|
|
1214
|
-
return (
|
|
1215
|
-
const target =
|
|
1185
|
+
return (e2) => {
|
|
1186
|
+
const target = e2.target;
|
|
1216
1187
|
if (!target) return;
|
|
1217
1188
|
const raw = target.value || "";
|
|
1218
1189
|
const maxDigits = state.formatter.getMaxDigits();
|
|
@@ -1225,11 +1196,11 @@ function createInputHandler(el, state) {
|
|
|
1225
1196
|
};
|
|
1226
1197
|
}
|
|
1227
1198
|
function createKeydownHandler(el, state) {
|
|
1228
|
-
return (
|
|
1229
|
-
if (
|
|
1199
|
+
return (e2) => {
|
|
1200
|
+
if (e2.ctrlKey || e2.metaKey || e2.altKey || NavigationKeys.includes(e2.key)) return;
|
|
1230
1201
|
const [selStart, selEnd] = getSelection(el);
|
|
1231
|
-
if (
|
|
1232
|
-
|
|
1202
|
+
if (e2.key === "Backspace") {
|
|
1203
|
+
e2.preventDefault();
|
|
1233
1204
|
if (selStart !== selEnd) {
|
|
1234
1205
|
const range = state.formatter.getDigitRange(state.digits, selStart, selEnd);
|
|
1235
1206
|
if (range) {
|
|
@@ -1264,8 +1235,8 @@ function createKeydownHandler(el, state) {
|
|
|
1264
1235
|
}
|
|
1265
1236
|
return;
|
|
1266
1237
|
}
|
|
1267
|
-
if (
|
|
1268
|
-
|
|
1238
|
+
if (e2.key === "Delete") {
|
|
1239
|
+
e2.preventDefault();
|
|
1269
1240
|
if (selStart !== selEnd) {
|
|
1270
1241
|
const range = state.formatter.getDigitRange(state.digits, selStart, selEnd);
|
|
1271
1242
|
if (range) {
|
|
@@ -1293,21 +1264,21 @@ function createKeydownHandler(el, state) {
|
|
|
1293
1264
|
}
|
|
1294
1265
|
return;
|
|
1295
1266
|
}
|
|
1296
|
-
if (/^[0-9]$/.test(
|
|
1267
|
+
if (/^[0-9]$/.test(e2.key)) {
|
|
1297
1268
|
if (state.digits.length >= state.formatter.getMaxDigits()) {
|
|
1298
|
-
|
|
1269
|
+
e2.preventDefault();
|
|
1299
1270
|
}
|
|
1300
1271
|
return;
|
|
1301
1272
|
}
|
|
1302
|
-
if (
|
|
1303
|
-
|
|
1273
|
+
if (e2.key.length === 1) {
|
|
1274
|
+
e2.preventDefault();
|
|
1304
1275
|
}
|
|
1305
1276
|
};
|
|
1306
1277
|
}
|
|
1307
1278
|
function createPasteHandler(el, state) {
|
|
1308
|
-
return (
|
|
1309
|
-
|
|
1310
|
-
const text =
|
|
1279
|
+
return (e2) => {
|
|
1280
|
+
e2.preventDefault();
|
|
1281
|
+
const text = e2.clipboardData?.getData("text") || "";
|
|
1311
1282
|
const maxDigits = state.formatter.getMaxDigits();
|
|
1312
1283
|
const pastedDigits = extractDigits(text, maxDigits);
|
|
1313
1284
|
if (pastedDigits.length === 0) return;
|
|
@@ -1341,7 +1312,6 @@ function createPasteHandler(el, state) {
|
|
|
1341
1312
|
}
|
|
1342
1313
|
async function updateCountry(el, state, newCountryCode) {
|
|
1343
1314
|
const newCountry = getCountry(newCountryCode, state.locale);
|
|
1344
|
-
if (!newCountry) return;
|
|
1345
1315
|
state.country = newCountry;
|
|
1346
1316
|
state.formatter = createPhoneFormatter(newCountry);
|
|
1347
1317
|
el.placeholder = state.formatter.getPlaceholder();
|