@desource/phone-mask-vue 0.2.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 +15 -0
- package/LICENSE +21 -0
- package/README.md +554 -0
- package/dist/index.cjs +1439 -0
- package/dist/index.js +1441 -0
- package/dist/index.mjs +1439 -0
- package/dist/phone-mask-vue.css +362 -0
- package/dist/types/components/PhoneInput.vue.d.ts +49 -0
- package/dist/types/components/PhoneInput.vue.d.ts.map +1 -0
- package/dist/types/composables/useClipboard.d.ts +7 -0
- package/dist/types/composables/useClipboard.d.ts.map +1 -0
- package/dist/types/composables/useCountrySelector.d.ts +21 -0
- package/dist/types/composables/useCountrySelector.d.ts.map +1 -0
- package/dist/types/composables/useMask.d.ts +20 -0
- package/dist/types/composables/useMask.d.ts.map +1 -0
- package/dist/types/composables/usePhoneFormatter.d.ts +16 -0
- package/dist/types/composables/usePhoneFormatter.d.ts.map +1 -0
- package/dist/types/consts.d.ts +8 -0
- package/dist/types/consts.d.ts.map +1 -0
- package/dist/types/directives/vPhoneMask.d.ts +10 -0
- package/dist/types/directives/vPhoneMask.d.ts.map +1 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +184 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +73 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1439 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
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 ###-######", "+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 ##-#######", "+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 #### ######"] };
|
|
5
|
+
const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (o) => {
|
|
6
|
+
if (!t$1.test(o)) {
|
|
7
|
+
const t2 = typeof o;
|
|
8
|
+
throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string" === t2 ? o : t2}' instead.`);
|
|
9
|
+
}
|
|
10
|
+
const e = [...o.toUpperCase()].map((t2) => (t2.codePointAt(0) ?? 0) + 127397);
|
|
11
|
+
return String.fromCodePoint(...e);
|
|
12
|
+
};
|
|
13
|
+
const t = Object.entries(M), divideMask = (e) => e.split(/ (.*)/s);
|
|
14
|
+
function getCodeAndMask(e) {
|
|
15
|
+
let n = "", t2 = "";
|
|
16
|
+
if (Array.isArray(e)) {
|
|
17
|
+
const o = [];
|
|
18
|
+
for (const t3 of e) {
|
|
19
|
+
const [e2, s] = divideMask(t3);
|
|
20
|
+
n || (n = e2), o.push(s);
|
|
21
|
+
}
|
|
22
|
+
t2 = o;
|
|
23
|
+
} else {
|
|
24
|
+
const [o, s] = divideMask(e);
|
|
25
|
+
n = o, t2 = s;
|
|
26
|
+
}
|
|
27
|
+
return [n, t2];
|
|
28
|
+
}
|
|
29
|
+
t.map(([e, n]) => ({ id: e, mask: n }));
|
|
30
|
+
t.reduce((e, [n, t2]) => {
|
|
31
|
+
const [o, s] = getCodeAndMask(t2);
|
|
32
|
+
return e[n] = { code: o, mask: s }, e;
|
|
33
|
+
}, {});
|
|
34
|
+
t.map(([e, n]) => {
|
|
35
|
+
const [t2, o] = getCodeAndMask(n);
|
|
36
|
+
return { id: e, code: t2, mask: o };
|
|
37
|
+
});
|
|
38
|
+
t.reduce((e, [t2, o]) => {
|
|
39
|
+
const [s, a] = getCodeAndMask(o);
|
|
40
|
+
return e[t2] = { code: s, mask: a, flag: countryCodeEmoji(t2) }, e;
|
|
41
|
+
}, {});
|
|
42
|
+
t.map(([e, t2]) => {
|
|
43
|
+
const [o, s] = getCodeAndMask(t2);
|
|
44
|
+
return { id: e, code: o, mask: s, flag: countryCodeEmoji(e) };
|
|
45
|
+
});
|
|
46
|
+
const MasksFullMap = (e) => {
|
|
47
|
+
const o = new Intl.DisplayNames([e], { type: "region" });
|
|
48
|
+
return t.reduce((e2, [t2, s]) => {
|
|
49
|
+
const [a, r] = getCodeAndMask(s), d = o.of(t2) ?? "";
|
|
50
|
+
return e2[t2] = { code: a, mask: r, name: d, flag: countryCodeEmoji(t2) }, e2;
|
|
51
|
+
}, {});
|
|
52
|
+
}, MasksFull = (e) => {
|
|
53
|
+
const o = new Intl.DisplayNames([e], { type: "region" });
|
|
54
|
+
return t.map(([e2, t2]) => {
|
|
55
|
+
const [s, a] = getCodeAndMask(t2);
|
|
56
|
+
return { id: e2, code: s, mask: a, name: o.of(e2) ?? "", flag: countryCodeEmoji(e2) };
|
|
57
|
+
});
|
|
58
|
+
}, m = t.reduce((e, [t2, o]) => {
|
|
59
|
+
const [s, a] = getCodeAndMask(o), r = new Intl.DisplayNames(["en"], { type: "region" });
|
|
60
|
+
return e[t2] = { code: s, mask: a, name: r.of(t2) ?? "", flag: countryCodeEmoji(t2) }, e;
|
|
61
|
+
}, {}), i = t.map(([e, t2]) => {
|
|
62
|
+
const [o, s] = getCodeAndMask(t2);
|
|
63
|
+
return { id: e, code: o, mask: s, name: new Intl.DisplayNames(["en"], { type: "region" }).of(e) ?? "", flag: countryCodeEmoji(e) };
|
|
64
|
+
}), g = countryCodeEmoji;
|
|
65
|
+
function toArray(t2) {
|
|
66
|
+
return Array.isArray(t2) ? t2 : [t2];
|
|
67
|
+
}
|
|
68
|
+
function countPlaceholders(t2) {
|
|
69
|
+
return (t2.match(/#/g) || []).length;
|
|
70
|
+
}
|
|
71
|
+
function removeCountryCodePrefix(t2) {
|
|
72
|
+
return t2.replace(/^\+\d+\s?/, "");
|
|
73
|
+
}
|
|
74
|
+
function pickMaskVariant(t2, n) {
|
|
75
|
+
if (1 === t2.length) return t2[0];
|
|
76
|
+
const r = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), e = r.filter((t3) => t3.count >= n).sort((t3, n2) => t3.count - n2.count);
|
|
77
|
+
if (e.length > 0) return e[0].mask;
|
|
78
|
+
const o = r.sort((t3, n2) => n2.count - t3.count)[0];
|
|
79
|
+
return o ? o.mask : t2[0];
|
|
80
|
+
}
|
|
81
|
+
function formatDigitsWithMap(t2, n) {
|
|
82
|
+
let r = "";
|
|
83
|
+
const e = [];
|
|
84
|
+
let o = 0;
|
|
85
|
+
const c = n.length, a = t2.length;
|
|
86
|
+
for (let i2 = 0; i2 < a; i2++) {
|
|
87
|
+
const a2 = t2[i2];
|
|
88
|
+
if ("#" === a2) {
|
|
89
|
+
if (!(o < c)) break;
|
|
90
|
+
r += n[o], e.push(o), o++;
|
|
91
|
+
} else {
|
|
92
|
+
const n2 = -1 !== t2.indexOf("#", i2 + 1) && o < c;
|
|
93
|
+
(r.length > 0 || n2) && (r += a2, e.push(-1));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { display: r, map: e };
|
|
97
|
+
}
|
|
98
|
+
const CACHE_KEY = "@desource/phone-mask:geo";
|
|
99
|
+
const CACHE_EXPIRY_MS = 24 * 60 * 6e4;
|
|
100
|
+
const GEO_IP_TIMEOUT = 1500;
|
|
101
|
+
const GEO_IP_URL = "https://ipapi.co/json/";
|
|
102
|
+
const Delimiters = [" ", "-", "(", ")"];
|
|
103
|
+
const NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"];
|
|
104
|
+
const InvalidPattern = /[^\d\s\-()]/;
|
|
105
|
+
const emptyCountry = { id: "", code: "", mask: "", flag: "", name: "" };
|
|
106
|
+
function useCountrySelector(usedLocale) {
|
|
107
|
+
const isEnLocale = vue.computed(() => usedLocale.value.toLowerCase().startsWith("en"));
|
|
108
|
+
const countries = vue.computed(() => isEnLocale.value ? i : MasksFull(usedLocale.value));
|
|
109
|
+
const countriesMap = vue.computed(() => isEnLocale.value ? m : MasksFullMap(usedLocale.value));
|
|
110
|
+
const selectedId = vue.ref(countries.value[0]?.id || "");
|
|
111
|
+
const dropdownOpened = vue.ref(false);
|
|
112
|
+
const hasDropdown = vue.ref(true);
|
|
113
|
+
const search = vue.ref("");
|
|
114
|
+
const focusedIndex = vue.ref(0);
|
|
115
|
+
const selected = vue.computed(() => {
|
|
116
|
+
const id = selectedId.value;
|
|
117
|
+
const found = countriesMap.value[id];
|
|
118
|
+
return found ? { id, ...found } : countries.value[0] || emptyCountry;
|
|
119
|
+
});
|
|
120
|
+
const hasCountry = (id) => {
|
|
121
|
+
const _id = id.toUpperCase();
|
|
122
|
+
return !!countriesMap.value[_id];
|
|
123
|
+
};
|
|
124
|
+
const filteredCountries = vue.computed(() => {
|
|
125
|
+
const q = search.value.trim().toUpperCase();
|
|
126
|
+
if (!q) return countries.value;
|
|
127
|
+
const qCodeDigits = q.replace(/\D/g, "");
|
|
128
|
+
const isNumericSearch = qCodeDigits.length > 0;
|
|
129
|
+
return countries.value.map((c) => {
|
|
130
|
+
const nameUpper = c.name.toUpperCase();
|
|
131
|
+
const idUpper = c.id.toUpperCase();
|
|
132
|
+
const codeDigits = c.code.replace(/\D/g, "");
|
|
133
|
+
let score = 0;
|
|
134
|
+
if (nameUpper.startsWith(q)) score = 1e3;
|
|
135
|
+
else if (nameUpper.includes(q)) score = 500;
|
|
136
|
+
if (c.code.startsWith(q)) score += 100;
|
|
137
|
+
else if (c.code.includes(q)) score += 50;
|
|
138
|
+
if (idUpper === q) score += 200;
|
|
139
|
+
else if (idUpper.startsWith(q)) score += 150;
|
|
140
|
+
if (isNumericSearch && codeDigits.startsWith(qCodeDigits)) score += 80;
|
|
141
|
+
else if (isNumericSearch && codeDigits.includes(qCodeDigits)) score += 40;
|
|
142
|
+
return { country: c, score };
|
|
143
|
+
}).filter(({ score }) => score > 0).sort((a, b) => {
|
|
144
|
+
if (b.score !== a.score) return b.score - a.score;
|
|
145
|
+
return a.country.name.localeCompare(b.country.name);
|
|
146
|
+
}).map(({ country }) => country);
|
|
147
|
+
});
|
|
148
|
+
const selectCountry = (id) => {
|
|
149
|
+
selectedId.value = id;
|
|
150
|
+
closeDropdown();
|
|
151
|
+
};
|
|
152
|
+
const toggleDropdown = async (searchRef) => {
|
|
153
|
+
dropdownOpened.value = !dropdownOpened.value;
|
|
154
|
+
if (!dropdownOpened.value) return;
|
|
155
|
+
await vue.nextTick();
|
|
156
|
+
searchRef.value?.focus();
|
|
157
|
+
focusedIndex.value = 0;
|
|
158
|
+
};
|
|
159
|
+
const closeDropdown = () => {
|
|
160
|
+
dropdownOpened.value = false;
|
|
161
|
+
};
|
|
162
|
+
const focusNextOption = (scrollFn) => {
|
|
163
|
+
if (filteredCountries.value.length === 0) return;
|
|
164
|
+
focusedIndex.value = Math.min(filteredCountries.value.length - 1, focusedIndex.value + 1);
|
|
165
|
+
scrollFn?.();
|
|
166
|
+
};
|
|
167
|
+
const focusPrevOption = (scrollFn) => {
|
|
168
|
+
if (filteredCountries.value.length === 0) return;
|
|
169
|
+
focusedIndex.value = Math.max(0, focusedIndex.value - 1);
|
|
170
|
+
scrollFn?.();
|
|
171
|
+
};
|
|
172
|
+
const chooseFocusedOption = () => {
|
|
173
|
+
const item = filteredCountries.value[focusedIndex.value];
|
|
174
|
+
if (item) selectCountry(item.id);
|
|
175
|
+
};
|
|
176
|
+
const detectFromLocale = () => {
|
|
177
|
+
try {
|
|
178
|
+
const lang = navigator.language || "";
|
|
179
|
+
try {
|
|
180
|
+
const loc = new Intl.Locale(lang);
|
|
181
|
+
if (loc.region && hasCountry(loc.region)) return loc.region.toUpperCase();
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
const parts = lang.split(/[-_]/);
|
|
185
|
+
if (parts.length > 1 && hasCountry(parts[1])) return parts[1].toUpperCase();
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
};
|
|
190
|
+
const detectByGeoIp = async () => {
|
|
191
|
+
try {
|
|
192
|
+
const cached = localStorage.getItem(CACHE_KEY);
|
|
193
|
+
if (cached) {
|
|
194
|
+
const parsed = JSON.parse(cached);
|
|
195
|
+
const isExpired = Date.now() - parsed.ts > CACHE_EXPIRY_MS;
|
|
196
|
+
if (!isExpired && parsed.country_code && hasCountry(parsed.country_code)) {
|
|
197
|
+
return parsed.country_code.toUpperCase();
|
|
198
|
+
}
|
|
199
|
+
if (isExpired) {
|
|
200
|
+
localStorage.removeItem(CACHE_KEY);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
const controller = new AbortController();
|
|
206
|
+
const timeoutId = setTimeout(() => controller.abort(), GEO_IP_TIMEOUT);
|
|
207
|
+
try {
|
|
208
|
+
const res = await fetch(GEO_IP_URL, {
|
|
209
|
+
signal: controller.signal,
|
|
210
|
+
headers: { Accept: "application/json" }
|
|
211
|
+
});
|
|
212
|
+
if (!res.ok) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const json = await res.json();
|
|
216
|
+
const code = (json.country || json.country_code || json.countryCode || json.country_code2 || "").toString().toUpperCase();
|
|
217
|
+
if (code && hasCountry(code)) {
|
|
218
|
+
try {
|
|
219
|
+
localStorage.setItem(CACHE_KEY, JSON.stringify({ country_code: code, ts: Date.now() }));
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
return code;
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
} finally {
|
|
226
|
+
clearTimeout(timeoutId);
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
const selectInitialCountry = (id, emitFn) => {
|
|
231
|
+
const previousId = selectedId.value;
|
|
232
|
+
selectedId.value = id;
|
|
233
|
+
if (previousId !== selectedId.value && emitFn) vue.nextTick(emitFn);
|
|
234
|
+
};
|
|
235
|
+
const initCountry = async (predefined, detect, emitFn) => {
|
|
236
|
+
hasDropdown.value = !predefined && countries.value.length > 1;
|
|
237
|
+
if (predefined && hasCountry(predefined)) {
|
|
238
|
+
selectInitialCountry(predefined.toUpperCase(), emitFn);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!detect) return;
|
|
242
|
+
const geo = await detectByGeoIp();
|
|
243
|
+
if (geo) {
|
|
244
|
+
selectInitialCountry(geo, emitFn);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const loc = detectFromLocale();
|
|
248
|
+
if (loc) {
|
|
249
|
+
selectInitialCountry(loc, emitFn);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
return {
|
|
254
|
+
countries,
|
|
255
|
+
selectedId,
|
|
256
|
+
selected,
|
|
257
|
+
hasCountry,
|
|
258
|
+
// Dropdown
|
|
259
|
+
hasDropdown,
|
|
260
|
+
dropdownOpened,
|
|
261
|
+
search,
|
|
262
|
+
focusedIndex,
|
|
263
|
+
filteredCountries,
|
|
264
|
+
selectCountry,
|
|
265
|
+
toggleDropdown,
|
|
266
|
+
closeDropdown,
|
|
267
|
+
focusNextOption,
|
|
268
|
+
focusPrevOption,
|
|
269
|
+
chooseFocusedOption,
|
|
270
|
+
// Country Detection
|
|
271
|
+
initCountry
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function createPhoneFormatter(country) {
|
|
275
|
+
const variants = toArray(country.mask);
|
|
276
|
+
const variantsDigits = variants.map((m2) => countPlaceholders(removeCountryCodePrefix(m2)));
|
|
277
|
+
const maxDigits = Math.max(...variantsDigits);
|
|
278
|
+
const getMask = (digitLength) => {
|
|
279
|
+
const mask = pickMaskVariant(variants, digitLength);
|
|
280
|
+
return removeCountryCodePrefix(mask);
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
formatDisplay: (digits) => {
|
|
284
|
+
const template = getMask(digits.length);
|
|
285
|
+
return formatDigitsWithMap(template, digits).display;
|
|
286
|
+
},
|
|
287
|
+
getMaxDigits: () => maxDigits,
|
|
288
|
+
getPlaceholder: () => {
|
|
289
|
+
const template = getMask(0);
|
|
290
|
+
return template;
|
|
291
|
+
},
|
|
292
|
+
getCaretPosition: (digitIndex) => {
|
|
293
|
+
const template = getMask(digitIndex);
|
|
294
|
+
const { display, map } = formatDigitsWithMap(template, "0".repeat(digitIndex));
|
|
295
|
+
for (let i2 = 0; i2 < map.length; i2++) {
|
|
296
|
+
if (map[i2] === digitIndex) return i2;
|
|
297
|
+
}
|
|
298
|
+
if (digitIndex >= map.length) return display.length;
|
|
299
|
+
for (let i2 = 0; i2 < map.length; i2++) {
|
|
300
|
+
if (map[i2] > digitIndex) return i2;
|
|
301
|
+
}
|
|
302
|
+
return display.length;
|
|
303
|
+
},
|
|
304
|
+
getDigitRange: (digits, selStart, selEnd) => {
|
|
305
|
+
const template = getMask(digits.length);
|
|
306
|
+
const { map } = formatDigitsWithMap(template, digits);
|
|
307
|
+
let min = Infinity;
|
|
308
|
+
let max = -Infinity;
|
|
309
|
+
for (let i2 = selStart; i2 < selEnd && i2 < map.length; i2++) {
|
|
310
|
+
const digitIdx = map[i2];
|
|
311
|
+
if (digitIdx !== void 0 && digitIdx >= 0) {
|
|
312
|
+
min = Math.min(min, digitIdx);
|
|
313
|
+
max = Math.max(max, digitIdx);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return min === Infinity ? null : [min, max + 1];
|
|
317
|
+
},
|
|
318
|
+
isComplete: (digits) => {
|
|
319
|
+
return variantsDigits.includes(digits.length);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function setCaret(el, position) {
|
|
324
|
+
if (!el) return;
|
|
325
|
+
try {
|
|
326
|
+
el.setSelectionRange(position, position);
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function extractDigits(value, maxLength) {
|
|
331
|
+
const digits = value.replace(/\D/g, "");
|
|
332
|
+
return maxLength ? digits.slice(0, maxLength) : digits;
|
|
333
|
+
}
|
|
334
|
+
function getSelection(el) {
|
|
335
|
+
if (!el) return [0, 0];
|
|
336
|
+
return [el.selectionStart ?? 0, el.selectionEnd ?? 0];
|
|
337
|
+
}
|
|
338
|
+
function useMask(selected, telRef) {
|
|
339
|
+
const digits = vue.ref("");
|
|
340
|
+
const displayValue = vue.ref("");
|
|
341
|
+
const validationTimer = vue.ref(null);
|
|
342
|
+
const showValidationHint = vue.ref(false);
|
|
343
|
+
const formatter = vue.computed(() => createPhoneFormatter(selected.value));
|
|
344
|
+
const displayPlaceholder = vue.computed(() => formatter.value.getPlaceholder());
|
|
345
|
+
const isComplete = vue.computed(() => formatter.value.isComplete(digits.value));
|
|
346
|
+
const isEmpty = vue.computed(() => digits.value.length === 0);
|
|
347
|
+
const maxDigits = vue.computed(() => formatter.value.getMaxDigits());
|
|
348
|
+
const shouldShowWarn = vue.computed(() => showValidationHint.value && !isEmpty.value && !isComplete.value);
|
|
349
|
+
const fullFormatted = vue.computed(() => {
|
|
350
|
+
if (!displayValue.value) return "";
|
|
351
|
+
return `${selected.value.code} ${displayValue.value}`;
|
|
352
|
+
});
|
|
353
|
+
const full = vue.computed(() => {
|
|
354
|
+
if (!digits.value) return "";
|
|
355
|
+
return `${selected.value.code}${digits.value}`;
|
|
356
|
+
});
|
|
357
|
+
const updateDisplay2 = () => {
|
|
358
|
+
displayValue.value = formatter.value.formatDisplay(digits.value);
|
|
359
|
+
};
|
|
360
|
+
const setCaretToDigitPosition = (digitIndex) => {
|
|
361
|
+
const pos = formatter.value.getCaretPosition(digitIndex);
|
|
362
|
+
setCaret(telRef.value, pos);
|
|
363
|
+
};
|
|
364
|
+
const removeDigitsRange = (startIdx, endIdx) => {
|
|
365
|
+
if (startIdx >= endIdx) return;
|
|
366
|
+
digits.value = digits.value.slice(0, startIdx) + digits.value.slice(endIdx);
|
|
367
|
+
};
|
|
368
|
+
const handleBeforeInput = (e) => {
|
|
369
|
+
const el = e.target;
|
|
370
|
+
if (!el) return;
|
|
371
|
+
const data = e.data;
|
|
372
|
+
if (e.inputType !== "insertText" || !data) return;
|
|
373
|
+
if (InvalidPattern.test(data) || data === " " && el.value.endsWith(" ")) {
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const handleInput = (e) => {
|
|
378
|
+
const el = e.target;
|
|
379
|
+
if (!el) return;
|
|
380
|
+
const newDigits = extractDigits(el.value, maxDigits.value);
|
|
381
|
+
showValidationHint.value = false;
|
|
382
|
+
if (validationTimer.value) {
|
|
383
|
+
clearTimeout(validationTimer.value);
|
|
384
|
+
}
|
|
385
|
+
digits.value = newDigits;
|
|
386
|
+
updateDisplay2();
|
|
387
|
+
if (newDigits.length > 0) {
|
|
388
|
+
validationTimer.value = setTimeout(() => {
|
|
389
|
+
showValidationHint.value = true;
|
|
390
|
+
}, 500);
|
|
391
|
+
}
|
|
392
|
+
vue.nextTick(() => {
|
|
393
|
+
setCaretToDigitPosition(digits.value.length);
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
const handleKeydownInternal = (e) => {
|
|
397
|
+
const el = telRef.value ?? e.target;
|
|
398
|
+
if (!el) return;
|
|
399
|
+
if (e.ctrlKey || e.metaKey || e.altKey || NavigationKeys.includes(e.key)) return;
|
|
400
|
+
const [selStart, selEnd] = getSelection(el);
|
|
401
|
+
if (e.key === "Backspace") {
|
|
402
|
+
e.preventDefault();
|
|
403
|
+
if (selStart !== selEnd) {
|
|
404
|
+
const range = formatter.value.getDigitRange(digits.value, selStart, selEnd);
|
|
405
|
+
if (range) {
|
|
406
|
+
const [start, end] = range;
|
|
407
|
+
removeDigitsRange(start, end);
|
|
408
|
+
updateDisplay2();
|
|
409
|
+
vue.nextTick(() => setCaretToDigitPosition(start));
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (selStart > 0) {
|
|
414
|
+
const displayStr = displayValue.value;
|
|
415
|
+
let prevPos = selStart - 1;
|
|
416
|
+
while (prevPos >= 0 && Delimiters.includes(displayStr[prevPos])) {
|
|
417
|
+
prevPos--;
|
|
418
|
+
}
|
|
419
|
+
if (prevPos >= 0) {
|
|
420
|
+
const range = formatter.value.getDigitRange(digits.value, prevPos, prevPos + 1);
|
|
421
|
+
if (range) {
|
|
422
|
+
const [start] = range;
|
|
423
|
+
removeDigitsRange(start, start + 1);
|
|
424
|
+
updateDisplay2();
|
|
425
|
+
vue.nextTick(() => setCaretToDigitPosition(start));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (e.key === "Delete") {
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
if (selStart !== selEnd) {
|
|
434
|
+
const range = formatter.value.getDigitRange(digits.value, selStart, selEnd);
|
|
435
|
+
if (range) {
|
|
436
|
+
const [start, end] = range;
|
|
437
|
+
removeDigitsRange(start, end);
|
|
438
|
+
updateDisplay2();
|
|
439
|
+
vue.nextTick(() => setCaretToDigitPosition(start));
|
|
440
|
+
}
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (selStart < displayValue.value.length) {
|
|
444
|
+
const range = formatter.value.getDigitRange(digits.value, selStart, selStart + 1);
|
|
445
|
+
if (range) {
|
|
446
|
+
const [start] = range;
|
|
447
|
+
removeDigitsRange(start, start + 1);
|
|
448
|
+
updateDisplay2();
|
|
449
|
+
vue.nextTick(() => setCaretToDigitPosition(start));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (/^[0-9]$/.test(e.key)) {
|
|
455
|
+
if (digits.value.length >= maxDigits.value) {
|
|
456
|
+
e.preventDefault();
|
|
457
|
+
}
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (e.key.length === 1) {
|
|
461
|
+
e.preventDefault();
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const handleKeydown = (e) => {
|
|
465
|
+
showValidationHint.value = false;
|
|
466
|
+
if (validationTimer.value) {
|
|
467
|
+
clearTimeout(validationTimer.value);
|
|
468
|
+
}
|
|
469
|
+
handleKeydownInternal(e);
|
|
470
|
+
if (validationTimer.value) clearTimeout(validationTimer.value);
|
|
471
|
+
validationTimer.value = setTimeout(() => {
|
|
472
|
+
if (!isComplete.value && !isEmpty.value) showValidationHint.value = true;
|
|
473
|
+
}, 300);
|
|
474
|
+
};
|
|
475
|
+
const handlePaste = (e) => {
|
|
476
|
+
e.preventDefault();
|
|
477
|
+
const text = e.clipboardData?.getData("text") || "";
|
|
478
|
+
const pastedDigits = extractDigits(text, maxDigits.value);
|
|
479
|
+
if (pastedDigits.length === 0) return;
|
|
480
|
+
const el = telRef.value;
|
|
481
|
+
if (!el) return;
|
|
482
|
+
const [selStart, selEnd] = getSelection(el);
|
|
483
|
+
if (selStart !== selEnd) {
|
|
484
|
+
const range2 = formatter.value.getDigitRange(digits.value, selStart, selEnd);
|
|
485
|
+
if (range2) {
|
|
486
|
+
const [start, end] = range2;
|
|
487
|
+
const left2 = digits.value.slice(0, start);
|
|
488
|
+
const right2 = digits.value.slice(end);
|
|
489
|
+
digits.value = extractDigits(left2 + pastedDigits + right2, maxDigits.value);
|
|
490
|
+
updateDisplay2();
|
|
491
|
+
vue.nextTick(() => setCaretToDigitPosition(start + pastedDigits.length));
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const range = formatter.value.getDigitRange(digits.value, selStart, selStart);
|
|
496
|
+
const insertIndex = range ? range[0] : digits.value.length;
|
|
497
|
+
const left = digits.value.slice(0, insertIndex);
|
|
498
|
+
const right = digits.value.slice(insertIndex);
|
|
499
|
+
digits.value = extractDigits(left + pastedDigits + right, maxDigits.value);
|
|
500
|
+
updateDisplay2();
|
|
501
|
+
if (validationTimer.value) clearTimeout(validationTimer.value);
|
|
502
|
+
validationTimer.value = setTimeout(() => {
|
|
503
|
+
if (!isComplete.value && !isEmpty.value) showValidationHint.value = true;
|
|
504
|
+
}, 300);
|
|
505
|
+
vue.nextTick(() => setCaretToDigitPosition(insertIndex + pastedDigits.length));
|
|
506
|
+
};
|
|
507
|
+
const handleFocus = () => {
|
|
508
|
+
if (validationTimer.value) {
|
|
509
|
+
clearTimeout(validationTimer.value);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const clear = () => {
|
|
513
|
+
digits.value = "";
|
|
514
|
+
displayValue.value = "";
|
|
515
|
+
showValidationHint.value = false;
|
|
516
|
+
if (validationTimer.value) {
|
|
517
|
+
clearTimeout(validationTimer.value);
|
|
518
|
+
validationTimer.value = null;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
vue.watch(selected, () => {
|
|
522
|
+
if (digits.value.length > maxDigits.value) {
|
|
523
|
+
digits.value = digits.value.slice(0, maxDigits.value);
|
|
524
|
+
}
|
|
525
|
+
updateDisplay2();
|
|
526
|
+
});
|
|
527
|
+
updateDisplay2();
|
|
528
|
+
return {
|
|
529
|
+
// State
|
|
530
|
+
digits,
|
|
531
|
+
displayValue,
|
|
532
|
+
// Computed
|
|
533
|
+
displayPlaceholder,
|
|
534
|
+
isComplete,
|
|
535
|
+
isEmpty,
|
|
536
|
+
shouldShowWarn,
|
|
537
|
+
fullFormatted,
|
|
538
|
+
full,
|
|
539
|
+
// Handlers
|
|
540
|
+
handleBeforeInput,
|
|
541
|
+
handleInput,
|
|
542
|
+
handleKeydown,
|
|
543
|
+
handlePaste,
|
|
544
|
+
handleFocus,
|
|
545
|
+
// Methods
|
|
546
|
+
updateDisplayFromDigits: updateDisplay2,
|
|
547
|
+
clear
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function useClipboard() {
|
|
551
|
+
const copied = vue.ref(false);
|
|
552
|
+
const isCopying = vue.ref(false);
|
|
553
|
+
let copyTimer = null;
|
|
554
|
+
const clearTimer = () => {
|
|
555
|
+
if (copyTimer) {
|
|
556
|
+
clearTimeout(copyTimer);
|
|
557
|
+
copyTimer = null;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const copy = async (text) => {
|
|
561
|
+
if (isCopying.value) return false;
|
|
562
|
+
const trimmedText = text.trim();
|
|
563
|
+
if (!trimmedText) return false;
|
|
564
|
+
isCopying.value = true;
|
|
565
|
+
try {
|
|
566
|
+
await navigator.clipboard.writeText(trimmedText);
|
|
567
|
+
copied.value = true;
|
|
568
|
+
clearTimer();
|
|
569
|
+
copyTimer = setTimeout(() => {
|
|
570
|
+
copied.value = false;
|
|
571
|
+
copyTimer = null;
|
|
572
|
+
}, 1800);
|
|
573
|
+
return true;
|
|
574
|
+
} catch (err) {
|
|
575
|
+
console.warn("Copy failed", err);
|
|
576
|
+
return false;
|
|
577
|
+
} finally {
|
|
578
|
+
isCopying.value = false;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
const onUnmount = () => {
|
|
582
|
+
clearTimer();
|
|
583
|
+
};
|
|
584
|
+
return { copied, isCopying, copy, onUnmount };
|
|
585
|
+
}
|
|
586
|
+
const _hoisted_1 = { class: "pi-selector" };
|
|
587
|
+
const _hoisted_2 = ["disabled", "tabindex", "aria-label", "aria-expanded", "aria-haspopup"];
|
|
588
|
+
const _hoisted_3 = ["aria-label"];
|
|
589
|
+
const _hoisted_4 = { class: "pi-code" };
|
|
590
|
+
const _hoisted_5 = { class: "pi-input-wrap" };
|
|
591
|
+
const _hoisted_6 = ["placeholder", "value", "disabled", "readonly", "aria-invalid"];
|
|
592
|
+
const _hoisted_7 = {
|
|
593
|
+
class: "pi-actions",
|
|
594
|
+
role: "toolbar",
|
|
595
|
+
"aria-label": "Phone input actions"
|
|
596
|
+
};
|
|
597
|
+
const _hoisted_8 = ["aria-label", "title"];
|
|
598
|
+
const _hoisted_9 = {
|
|
599
|
+
key: 1,
|
|
600
|
+
width: "16",
|
|
601
|
+
height: "16",
|
|
602
|
+
viewBox: "0 0 16 16",
|
|
603
|
+
fill: "none",
|
|
604
|
+
"aria-hidden": "true"
|
|
605
|
+
};
|
|
606
|
+
const _hoisted_10 = {
|
|
607
|
+
key: 2,
|
|
608
|
+
width: "16",
|
|
609
|
+
height: "16",
|
|
610
|
+
viewBox: "0 0 16 16",
|
|
611
|
+
fill: "none",
|
|
612
|
+
"aria-hidden": "true"
|
|
613
|
+
};
|
|
614
|
+
const _hoisted_11 = ["aria-label", "title"];
|
|
615
|
+
const _hoisted_12 = {
|
|
616
|
+
key: 0,
|
|
617
|
+
width: "11",
|
|
618
|
+
height: "11",
|
|
619
|
+
viewBox: "0 0 14 14",
|
|
620
|
+
fill: "none",
|
|
621
|
+
"aria-hidden": "true"
|
|
622
|
+
};
|
|
623
|
+
const _hoisted_13 = { class: "pi-search-wrap" };
|
|
624
|
+
const _hoisted_14 = ["placeholder"];
|
|
625
|
+
const _hoisted_15 = ["aria-activedescendant"];
|
|
626
|
+
const _hoisted_16 = ["id", "aria-selected", "title", "onClick", "onMouseenter"];
|
|
627
|
+
const _hoisted_17 = ["aria-label"];
|
|
628
|
+
const _hoisted_18 = { class: "pi-opt-name" };
|
|
629
|
+
const _hoisted_19 = { class: "pi-opt-code" };
|
|
630
|
+
const _hoisted_20 = {
|
|
631
|
+
key: 0,
|
|
632
|
+
class: "pi-empty"
|
|
633
|
+
};
|
|
634
|
+
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
635
|
+
__name: "PhoneInput",
|
|
636
|
+
props: /* @__PURE__ */ vue.mergeModels({
|
|
637
|
+
country: {},
|
|
638
|
+
detect: { type: Boolean, default: true },
|
|
639
|
+
locale: {},
|
|
640
|
+
size: { default: "normal" },
|
|
641
|
+
theme: { default: "auto" },
|
|
642
|
+
disabled: { type: Boolean, default: false },
|
|
643
|
+
readonly: { type: Boolean, default: false },
|
|
644
|
+
showCopy: { type: Boolean, default: true },
|
|
645
|
+
showClear: { type: Boolean, default: false },
|
|
646
|
+
withValidity: { type: Boolean, default: true },
|
|
647
|
+
searchPlaceholder: { default: "Search country or code..." },
|
|
648
|
+
noResultsText: { default: "No countries found" },
|
|
649
|
+
clearButtonLabel: { default: "Clear phone number" },
|
|
650
|
+
dropdownClass: {},
|
|
651
|
+
disableDefaultStyles: { type: Boolean, default: false }
|
|
652
|
+
}, {
|
|
653
|
+
"modelValue": {},
|
|
654
|
+
"modelModifiers": {}
|
|
655
|
+
}),
|
|
656
|
+
emits: /* @__PURE__ */ vue.mergeModels(["change", "country-change", "validation-change", "focus", "blur", "copy", "clear"], ["update:modelValue"]),
|
|
657
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
658
|
+
const props = __props;
|
|
659
|
+
const slots = vue.useSlots();
|
|
660
|
+
const model = vue.useModel(__props, "modelValue");
|
|
661
|
+
const emit = __emit;
|
|
662
|
+
const rootRef = vue.useTemplateRef("rootRef");
|
|
663
|
+
const telRef = vue.useTemplateRef("telRef");
|
|
664
|
+
const searchRef = vue.useTemplateRef("searchRef");
|
|
665
|
+
const liveRef = vue.useTemplateRef("liveRef");
|
|
666
|
+
const dropdownRef = vue.useTemplateRef("dropdownRef");
|
|
667
|
+
const usedLocale = vue.computed(() => {
|
|
668
|
+
if (props.locale) return props.locale;
|
|
669
|
+
if (typeof navigator !== "undefined") {
|
|
670
|
+
return navigator.language || navigator.userLanguage || "en";
|
|
671
|
+
}
|
|
672
|
+
return "en";
|
|
673
|
+
});
|
|
674
|
+
const dropdownStyle = vue.shallowRef({});
|
|
675
|
+
const countrySelector = useCountrySelector(usedLocale);
|
|
676
|
+
const {
|
|
677
|
+
search,
|
|
678
|
+
filteredCountries,
|
|
679
|
+
focusedIndex,
|
|
680
|
+
selected,
|
|
681
|
+
dropdownOpened,
|
|
682
|
+
hasDropdown,
|
|
683
|
+
focusNextOption,
|
|
684
|
+
focusPrevOption,
|
|
685
|
+
chooseFocusedOption,
|
|
686
|
+
closeDropdown
|
|
687
|
+
} = countrySelector;
|
|
688
|
+
const mask = useMask(selected, telRef);
|
|
689
|
+
const { digits, displayValue, displayPlaceholder, isComplete, isEmpty, shouldShowWarn, full, fullFormatted } = mask;
|
|
690
|
+
const { copied, copy, onUnmount: onClipboardUnmount } = useClipboard();
|
|
691
|
+
const inactive = vue.computed(() => props.disabled || props.readonly);
|
|
692
|
+
const showCopyButton = vue.computed(() => props.showCopy && !isEmpty.value && !props.disabled);
|
|
693
|
+
const showClearButton = vue.computed(() => props.showClear && !isEmpty.value && !inactive.value);
|
|
694
|
+
const copyAriaLabel = vue.computed(() => copied.value ? "Copied" : `Copy ${selected.value.code} ${displayValue.value}`);
|
|
695
|
+
const copyButtonTitle = vue.computed(() => copied.value ? "Copied" : "Copy phone number");
|
|
696
|
+
const copyMessage = vue.computed(() => copied.value ? "Phone number copied to clipboard" : "");
|
|
697
|
+
const sizeClass = vue.computed(() => `size-${props.size}`);
|
|
698
|
+
const themeClass = vue.computed(() => {
|
|
699
|
+
if (props.theme !== "auto") return `theme-${props.theme}`;
|
|
700
|
+
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
|
|
701
|
+
return "theme-dark";
|
|
702
|
+
}
|
|
703
|
+
return "theme-light";
|
|
704
|
+
});
|
|
705
|
+
const rootClasses = vue.computed(() => [
|
|
706
|
+
"phone-input",
|
|
707
|
+
sizeClass.value,
|
|
708
|
+
themeClass.value,
|
|
709
|
+
{
|
|
710
|
+
"is-disabled": props.disabled,
|
|
711
|
+
"is-readonly": props.readonly,
|
|
712
|
+
"is-unstyled": props.disableDefaultStyles,
|
|
713
|
+
"is-incomplete": props.withValidity && shouldShowWarn.value,
|
|
714
|
+
"is-complete": props.withValidity && isComplete.value
|
|
715
|
+
}
|
|
716
|
+
]);
|
|
717
|
+
const rootStyles = vue.computed(() => ({
|
|
718
|
+
"--pi-actions-count": +showCopyButton.value + +showClearButton.value + (slots["actions-before"] ? 1 : 0)
|
|
719
|
+
}));
|
|
720
|
+
const emitModelUpdate = () => {
|
|
721
|
+
if (model.value === digits.value) return;
|
|
722
|
+
model.value = digits.value;
|
|
723
|
+
emit("change", {
|
|
724
|
+
full: full.value,
|
|
725
|
+
fullFormatted: fullFormatted.value,
|
|
726
|
+
digits: digits.value
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
const onInput = async (e) => {
|
|
730
|
+
if (inactive.value) return;
|
|
731
|
+
mask.handleInput(e);
|
|
732
|
+
await vue.nextTick();
|
|
733
|
+
emitModelUpdate();
|
|
734
|
+
};
|
|
735
|
+
const onKeydown = async (e) => {
|
|
736
|
+
if (inactive.value) return;
|
|
737
|
+
mask.handleKeydown(e);
|
|
738
|
+
await vue.nextTick();
|
|
739
|
+
emitModelUpdate();
|
|
740
|
+
};
|
|
741
|
+
const onPaste = async (e) => {
|
|
742
|
+
if (inactive.value) return;
|
|
743
|
+
mask.handlePaste(e);
|
|
744
|
+
await vue.nextTick();
|
|
745
|
+
emitModelUpdate();
|
|
746
|
+
};
|
|
747
|
+
const onFocus = (e) => {
|
|
748
|
+
mask.handleFocus();
|
|
749
|
+
dropdownOpened.value = false;
|
|
750
|
+
emit("focus", e);
|
|
751
|
+
};
|
|
752
|
+
const onBlur = (e) => emit("blur", e);
|
|
753
|
+
const onSelectCountry = async (countryId) => {
|
|
754
|
+
countrySelector.selectCountry(countryId);
|
|
755
|
+
emit("country-change", selected.value);
|
|
756
|
+
await vue.nextTick();
|
|
757
|
+
telRef.value?.focus();
|
|
758
|
+
};
|
|
759
|
+
const onCopyClick = async () => {
|
|
760
|
+
const valueToCopy = fullFormatted.value;
|
|
761
|
+
const success = await copy(valueToCopy);
|
|
762
|
+
if (success) {
|
|
763
|
+
emit("copy", valueToCopy);
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
const onClearClick = async () => {
|
|
767
|
+
mask.clear();
|
|
768
|
+
model.value = "";
|
|
769
|
+
emit("change", {
|
|
770
|
+
full: "",
|
|
771
|
+
fullFormatted: "",
|
|
772
|
+
digits: ""
|
|
773
|
+
});
|
|
774
|
+
emit("clear");
|
|
775
|
+
await vue.nextTick();
|
|
776
|
+
telRef.value?.focus();
|
|
777
|
+
};
|
|
778
|
+
const positionDropdown = (e) => {
|
|
779
|
+
if (e?.type === "scroll" && e.target && dropdownRef.value?.contains(e.target)) return;
|
|
780
|
+
const root = rootRef.value;
|
|
781
|
+
if (!root) return;
|
|
782
|
+
const rect = root.getBoundingClientRect();
|
|
783
|
+
dropdownStyle.value = {
|
|
784
|
+
top: `${rect.bottom + window.scrollY + 8}px`,
|
|
785
|
+
left: `${rect.left + window.scrollX}px`,
|
|
786
|
+
width: `${rect.width}px`
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
const removeDropdownListeners = () => {
|
|
790
|
+
window.removeEventListener("scroll", positionDropdown, true);
|
|
791
|
+
window.removeEventListener("click", onDocClick, true);
|
|
792
|
+
window.removeEventListener("resize", positionDropdown);
|
|
793
|
+
};
|
|
794
|
+
const toggleDropdown = async () => {
|
|
795
|
+
if (inactive.value || !hasDropdown.value) return;
|
|
796
|
+
await countrySelector.toggleDropdown(searchRef);
|
|
797
|
+
if (dropdownOpened.value) {
|
|
798
|
+
positionDropdown();
|
|
799
|
+
window.addEventListener("scroll", positionDropdown, true);
|
|
800
|
+
window.addEventListener("click", onDocClick, true);
|
|
801
|
+
window.addEventListener("resize", positionDropdown);
|
|
802
|
+
} else {
|
|
803
|
+
removeDropdownListeners();
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
const scrollFocusedIntoView = async () => {
|
|
807
|
+
await vue.nextTick();
|
|
808
|
+
const list = dropdownRef.value?.lastElementChild;
|
|
809
|
+
if (!list) return;
|
|
810
|
+
list.children[focusedIndex.value]?.scrollIntoView?.({ block: "nearest" });
|
|
811
|
+
};
|
|
812
|
+
const onDocClick = (ev) => {
|
|
813
|
+
const dropdown = dropdownRef.value;
|
|
814
|
+
const selector = rootRef.value?.firstChild;
|
|
815
|
+
if (!(dropdown || selector)) return;
|
|
816
|
+
const target = ev.target;
|
|
817
|
+
if (!target || dropdown?.contains(target) || selector?.contains(target)) return;
|
|
818
|
+
dropdownOpened.value = false;
|
|
819
|
+
};
|
|
820
|
+
vue.watch(
|
|
821
|
+
model,
|
|
822
|
+
(newValue) => {
|
|
823
|
+
if (!newValue) {
|
|
824
|
+
if (!isEmpty.value) mask.clear();
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
const currentDigits = digits.value;
|
|
828
|
+
if (newValue !== currentDigits) {
|
|
829
|
+
const incomingDigits = newValue.replace(/\D/g, "");
|
|
830
|
+
if (incomingDigits !== currentDigits) {
|
|
831
|
+
digits.value = incomingDigits;
|
|
832
|
+
mask.updateDisplayFromDigits();
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
{ immediate: true }
|
|
837
|
+
);
|
|
838
|
+
vue.watch(
|
|
839
|
+
[() => props.country, () => props.detect],
|
|
840
|
+
async ([country, detect]) => {
|
|
841
|
+
await vue.nextTick();
|
|
842
|
+
await countrySelector.initCountry(country, detect, () => emit("country-change", selected.value));
|
|
843
|
+
},
|
|
844
|
+
{ immediate: true }
|
|
845
|
+
);
|
|
846
|
+
vue.watch(
|
|
847
|
+
copyMessage,
|
|
848
|
+
(val) => {
|
|
849
|
+
if (liveRef.value && val) {
|
|
850
|
+
liveRef.value.textContent = val;
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
{ flush: "post" }
|
|
854
|
+
);
|
|
855
|
+
vue.watch(
|
|
856
|
+
isComplete,
|
|
857
|
+
(valid) => {
|
|
858
|
+
emit("validation-change", valid);
|
|
859
|
+
},
|
|
860
|
+
{ flush: "post" }
|
|
861
|
+
);
|
|
862
|
+
vue.onBeforeUnmount(() => {
|
|
863
|
+
removeDropdownListeners();
|
|
864
|
+
onClipboardUnmount();
|
|
865
|
+
});
|
|
866
|
+
__expose({
|
|
867
|
+
focus: () => telRef.value?.focus(),
|
|
868
|
+
blur: () => telRef.value?.blur(),
|
|
869
|
+
clear: mask.clear,
|
|
870
|
+
selectCountry: countrySelector.selectCountry,
|
|
871
|
+
getFullNumber: () => full.value,
|
|
872
|
+
getFullFormattedNumber: () => fullFormatted.value,
|
|
873
|
+
getDigits: () => digits.value,
|
|
874
|
+
isValid: () => isComplete.value,
|
|
875
|
+
isComplete: () => isComplete.value
|
|
876
|
+
});
|
|
877
|
+
return (_ctx, _cache) => {
|
|
878
|
+
return vue.openBlock(), vue.createElementBlock("div", {
|
|
879
|
+
ref_key: "rootRef",
|
|
880
|
+
ref: rootRef,
|
|
881
|
+
"aria-label": "Phone input with country selector",
|
|
882
|
+
role: "group",
|
|
883
|
+
class: vue.normalizeClass(rootClasses.value),
|
|
884
|
+
style: vue.normalizeStyle(rootStyles.value)
|
|
885
|
+
}, [
|
|
886
|
+
vue.createElementVNode("div", _hoisted_1, [
|
|
887
|
+
vue.createElementVNode("button", {
|
|
888
|
+
type: "button",
|
|
889
|
+
class: vue.normalizeClass(["pi-selector-btn", { "no-dropdown": !vue.unref(hasDropdown) || __props.readonly }]),
|
|
890
|
+
disabled: __props.disabled,
|
|
891
|
+
tabindex: inactive.value || !vue.unref(hasDropdown) ? -1 : void 0,
|
|
892
|
+
"aria-label": `Selected country: ${vue.unref(selected).name}`,
|
|
893
|
+
"aria-expanded": vue.unref(dropdownOpened),
|
|
894
|
+
"aria-haspopup": vue.unref(hasDropdown) ? "listbox" : void 0,
|
|
895
|
+
onClick: toggleDropdown
|
|
896
|
+
}, [
|
|
897
|
+
vue.createElementVNode("span", {
|
|
898
|
+
class: "pi-flag",
|
|
899
|
+
role: "img",
|
|
900
|
+
"aria-label": `${vue.unref(selected).name} flag`
|
|
901
|
+
}, [
|
|
902
|
+
vue.renderSlot(_ctx.$slots, "flag", { country: vue.unref(selected) }, () => [
|
|
903
|
+
vue.createTextVNode(vue.toDisplayString(vue.unref(selected).flag), 1)
|
|
904
|
+
], true)
|
|
905
|
+
], 8, _hoisted_3),
|
|
906
|
+
vue.createElementVNode("span", _hoisted_4, vue.toDisplayString(vue.unref(selected).code), 1),
|
|
907
|
+
!inactive.value && vue.unref(hasDropdown) ? (vue.openBlock(), vue.createElementBlock("svg", {
|
|
908
|
+
key: 0,
|
|
909
|
+
class: vue.normalizeClass(["pi-chevron", { "is-open": vue.unref(dropdownOpened) }]),
|
|
910
|
+
width: "12",
|
|
911
|
+
height: "12",
|
|
912
|
+
viewBox: "0 0 12 12",
|
|
913
|
+
fill: "none",
|
|
914
|
+
"aria-hidden": "true"
|
|
915
|
+
}, [..._cache[6] || (_cache[6] = [
|
|
916
|
+
vue.createElementVNode("path", {
|
|
917
|
+
d: "M2.5 4.5L6 8L9.5 4.5",
|
|
918
|
+
stroke: "currentColor",
|
|
919
|
+
"stroke-width": "1.5",
|
|
920
|
+
"stroke-linecap": "round",
|
|
921
|
+
"stroke-linejoin": "round"
|
|
922
|
+
}, null, -1)
|
|
923
|
+
])], 2)) : vue.createCommentVNode("", true)
|
|
924
|
+
], 10, _hoisted_2)
|
|
925
|
+
]),
|
|
926
|
+
vue.createElementVNode("div", _hoisted_5, [
|
|
927
|
+
vue.createElementVNode("input", {
|
|
928
|
+
ref_key: "telRef",
|
|
929
|
+
ref: telRef,
|
|
930
|
+
type: "tel",
|
|
931
|
+
inputmode: "tel",
|
|
932
|
+
autocomplete: "tel-national",
|
|
933
|
+
autocorrect: "off",
|
|
934
|
+
autocapitalize: "off",
|
|
935
|
+
spellcheck: "false",
|
|
936
|
+
class: "pi-input",
|
|
937
|
+
placeholder: vue.unref(displayPlaceholder),
|
|
938
|
+
value: vue.unref(displayValue),
|
|
939
|
+
disabled: __props.disabled,
|
|
940
|
+
readonly: __props.readonly,
|
|
941
|
+
"aria-invalid": vue.unref(shouldShowWarn),
|
|
942
|
+
onBeforeinput: _cache[0] || (_cache[0] = //@ts-ignore
|
|
943
|
+
(...args) => vue.unref(mask).handleBeforeInput && vue.unref(mask).handleBeforeInput(...args)),
|
|
944
|
+
onInput,
|
|
945
|
+
onKeydown,
|
|
946
|
+
onPaste,
|
|
947
|
+
onFocus,
|
|
948
|
+
onBlur
|
|
949
|
+
}, null, 40, _hoisted_6),
|
|
950
|
+
vue.createElementVNode("div", _hoisted_7, [
|
|
951
|
+
vue.createVNode(vue.Transition, { name: "fade-scale" }, {
|
|
952
|
+
default: vue.withCtx(() => [
|
|
953
|
+
vue.renderSlot(_ctx.$slots, "actions-before", {}, void 0, true)
|
|
954
|
+
]),
|
|
955
|
+
_: 3
|
|
956
|
+
}),
|
|
957
|
+
vue.createVNode(vue.Transition, { name: "fade-scale" }, {
|
|
958
|
+
default: vue.withCtx(() => [
|
|
959
|
+
showCopyButton.value ? (vue.openBlock(), vue.createElementBlock("button", {
|
|
960
|
+
key: 0,
|
|
961
|
+
type: "button",
|
|
962
|
+
class: vue.normalizeClass(["pi-btn", { "is-copied": vue.unref(copied) }]),
|
|
963
|
+
"aria-label": copyAriaLabel.value,
|
|
964
|
+
title: copyButtonTitle.value,
|
|
965
|
+
onClick: onCopyClick
|
|
966
|
+
}, [
|
|
967
|
+
slots["copy-svg"] ? vue.renderSlot(_ctx.$slots, "copy-svg", {
|
|
968
|
+
key: 0,
|
|
969
|
+
copied: vue.unref(copied)
|
|
970
|
+
}, void 0, true) : !vue.unref(copied) ? (vue.openBlock(), vue.createElementBlock("svg", _hoisted_9, [..._cache[7] || (_cache[7] = [
|
|
971
|
+
vue.createElementVNode("path", {
|
|
972
|
+
d: "M13.5 5.5V13.5H5.5V5.5H13.5ZM13.5 4H5.5C4.67 4 4 4.67 4 5.5V13.5C4 14.33 4.67 15 5.5 15H13.5C14.33 15 15 14.33 15 13.5V5.5C15 4.67 14.33 4 13.5 4ZM10.5 1H2.5V11H4V2.5H10.5V1Z",
|
|
973
|
+
fill: "currentColor"
|
|
974
|
+
}, null, -1)
|
|
975
|
+
])])) : (vue.openBlock(), vue.createElementBlock("svg", _hoisted_10, [..._cache[8] || (_cache[8] = [
|
|
976
|
+
vue.createElementVNode("path", {
|
|
977
|
+
d: "M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z",
|
|
978
|
+
fill: "currentColor"
|
|
979
|
+
}, null, -1)
|
|
980
|
+
])]))
|
|
981
|
+
], 10, _hoisted_8)) : vue.createCommentVNode("", true)
|
|
982
|
+
]),
|
|
983
|
+
_: 3
|
|
984
|
+
}),
|
|
985
|
+
vue.createVNode(vue.Transition, { name: "fade-scale" }, {
|
|
986
|
+
default: vue.withCtx(() => [
|
|
987
|
+
showClearButton.value ? (vue.openBlock(), vue.createElementBlock("button", {
|
|
988
|
+
key: 0,
|
|
989
|
+
type: "button",
|
|
990
|
+
class: "pi-btn",
|
|
991
|
+
"aria-label": __props.clearButtonLabel,
|
|
992
|
+
title: __props.clearButtonLabel,
|
|
993
|
+
onClick: onClearClick
|
|
994
|
+
}, [
|
|
995
|
+
!slots["clear-svg"] ? (vue.openBlock(), vue.createElementBlock("svg", _hoisted_12, [..._cache[9] || (_cache[9] = [
|
|
996
|
+
vue.createElementVNode("path", {
|
|
997
|
+
d: "M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z",
|
|
998
|
+
fill: "currentColor"
|
|
999
|
+
}, null, -1)
|
|
1000
|
+
])])) : vue.renderSlot(_ctx.$slots, "clear-svg", { key: 1 }, void 0, true)
|
|
1001
|
+
], 8, _hoisted_11)) : vue.createCommentVNode("", true)
|
|
1002
|
+
]),
|
|
1003
|
+
_: 3
|
|
1004
|
+
})
|
|
1005
|
+
])
|
|
1006
|
+
]),
|
|
1007
|
+
(vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
|
|
1008
|
+
vue.createVNode(vue.Transition, { name: "dropdown" }, {
|
|
1009
|
+
default: vue.withCtx(() => [
|
|
1010
|
+
vue.unref(dropdownOpened) ? (vue.openBlock(), vue.createElementBlock("div", {
|
|
1011
|
+
key: 0,
|
|
1012
|
+
ref_key: "dropdownRef",
|
|
1013
|
+
ref: dropdownRef,
|
|
1014
|
+
class: vue.normalizeClass(["phone-dropdown", [__props.dropdownClass, themeClass.value]]),
|
|
1015
|
+
role: "dialog",
|
|
1016
|
+
"aria-modal": "false",
|
|
1017
|
+
"aria-label": "Select country",
|
|
1018
|
+
style: vue.normalizeStyle(dropdownStyle.value)
|
|
1019
|
+
}, [
|
|
1020
|
+
vue.createElementVNode("div", _hoisted_13, [
|
|
1021
|
+
vue.withDirectives(vue.createElementVNode("input", {
|
|
1022
|
+
ref_key: "searchRef",
|
|
1023
|
+
ref: searchRef,
|
|
1024
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => vue.isRef(search) ? search.value = $event : null),
|
|
1025
|
+
type: "search",
|
|
1026
|
+
class: "pi-search",
|
|
1027
|
+
"aria-label": "Search countries",
|
|
1028
|
+
placeholder: __props.searchPlaceholder,
|
|
1029
|
+
onKeydown: [
|
|
1030
|
+
_cache[2] || (_cache[2] = vue.withKeys(vue.withModifiers(($event) => vue.unref(focusNextOption)(scrollFocusedIntoView), ["prevent"]), ["down"])),
|
|
1031
|
+
_cache[3] || (_cache[3] = vue.withKeys(vue.withModifiers(($event) => vue.unref(focusPrevOption)(scrollFocusedIntoView), ["prevent"]), ["up"])),
|
|
1032
|
+
_cache[4] || (_cache[4] = vue.withKeys(vue.withModifiers(
|
|
1033
|
+
//@ts-ignore
|
|
1034
|
+
(...args) => vue.unref(chooseFocusedOption) && vue.unref(chooseFocusedOption)(...args),
|
|
1035
|
+
["prevent"]
|
|
1036
|
+
), ["enter"])),
|
|
1037
|
+
_cache[5] || (_cache[5] = vue.withKeys(
|
|
1038
|
+
//@ts-ignore
|
|
1039
|
+
(...args) => vue.unref(closeDropdown) && vue.unref(closeDropdown)(...args),
|
|
1040
|
+
["escape"]
|
|
1041
|
+
))
|
|
1042
|
+
]
|
|
1043
|
+
}, null, 40, _hoisted_14), [
|
|
1044
|
+
[vue.vModelText, vue.unref(search)]
|
|
1045
|
+
])
|
|
1046
|
+
]),
|
|
1047
|
+
vue.createElementVNode("ul", {
|
|
1048
|
+
class: "pi-options",
|
|
1049
|
+
role: "listbox",
|
|
1050
|
+
"aria-activedescendant": `option-${vue.unref(focusedIndex)}`,
|
|
1051
|
+
tabindex: "-1"
|
|
1052
|
+
}, [
|
|
1053
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(filteredCountries), (c, idx) => {
|
|
1054
|
+
return vue.openBlock(), vue.createElementBlock("li", {
|
|
1055
|
+
id: `option-${idx}`,
|
|
1056
|
+
key: c.id,
|
|
1057
|
+
role: "option",
|
|
1058
|
+
class: vue.normalizeClass([
|
|
1059
|
+
"pi-option",
|
|
1060
|
+
{
|
|
1061
|
+
"is-focused": idx === vue.unref(focusedIndex),
|
|
1062
|
+
"is-selected": c.id === vue.unref(selected).id
|
|
1063
|
+
}
|
|
1064
|
+
]),
|
|
1065
|
+
"aria-selected": c.id === vue.unref(selected).id,
|
|
1066
|
+
title: c.name,
|
|
1067
|
+
onClick: ($event) => onSelectCountry(c.id),
|
|
1068
|
+
onMouseenter: ($event) => focusedIndex.value = idx
|
|
1069
|
+
}, [
|
|
1070
|
+
vue.createElementVNode("span", {
|
|
1071
|
+
class: "pi-flag",
|
|
1072
|
+
role: "img",
|
|
1073
|
+
"aria-label": `${c.name} flag`
|
|
1074
|
+
}, [
|
|
1075
|
+
vue.renderSlot(_ctx.$slots, "flag", { country: c }, () => [
|
|
1076
|
+
vue.createTextVNode(vue.toDisplayString(c.flag), 1)
|
|
1077
|
+
], true)
|
|
1078
|
+
], 8, _hoisted_17),
|
|
1079
|
+
vue.createElementVNode("span", _hoisted_18, vue.toDisplayString(c.name), 1),
|
|
1080
|
+
vue.createElementVNode("span", _hoisted_19, vue.toDisplayString(c.code), 1)
|
|
1081
|
+
], 42, _hoisted_16);
|
|
1082
|
+
}), 128)),
|
|
1083
|
+
vue.unref(filteredCountries).length === 0 ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_20, vue.toDisplayString(__props.noResultsText), 1)) : vue.createCommentVNode("", true)
|
|
1084
|
+
], 8, _hoisted_15)
|
|
1085
|
+
], 6)) : vue.createCommentVNode("", true)
|
|
1086
|
+
]),
|
|
1087
|
+
_: 3
|
|
1088
|
+
})
|
|
1089
|
+
])),
|
|
1090
|
+
vue.createElementVNode("div", {
|
|
1091
|
+
ref_key: "liveRef",
|
|
1092
|
+
ref: liveRef,
|
|
1093
|
+
class: "sr-only",
|
|
1094
|
+
role: "status",
|
|
1095
|
+
"aria-live": "polite",
|
|
1096
|
+
"aria-atomic": "true"
|
|
1097
|
+
}, null, 512)
|
|
1098
|
+
], 6);
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
const _export_sfc = (sfc, props) => {
|
|
1103
|
+
const target = sfc.__vccOpts || sfc;
|
|
1104
|
+
for (const [key, val] of props) {
|
|
1105
|
+
target[key] = val;
|
|
1106
|
+
}
|
|
1107
|
+
return target;
|
|
1108
|
+
};
|
|
1109
|
+
const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-cd4ff552"]]);
|
|
1110
|
+
function getNavigatorLang() {
|
|
1111
|
+
if (typeof navigator !== "undefined") {
|
|
1112
|
+
return navigator.language || "";
|
|
1113
|
+
}
|
|
1114
|
+
return "";
|
|
1115
|
+
}
|
|
1116
|
+
function getCountry(countryCode, locale) {
|
|
1117
|
+
const isEn = locale.toLowerCase().startsWith("en");
|
|
1118
|
+
const countriesMap = isEn ? m : MasksFullMap(locale);
|
|
1119
|
+
const id = countryCode.toUpperCase();
|
|
1120
|
+
const found = countriesMap[id];
|
|
1121
|
+
return found ? { id, ...found } : null;
|
|
1122
|
+
}
|
|
1123
|
+
function getDefaultCountry(locale) {
|
|
1124
|
+
const isEn = locale.toLowerCase().startsWith("en");
|
|
1125
|
+
const countries = isEn ? m : MasksFullMap(locale);
|
|
1126
|
+
return { id: "US", ...countries.US };
|
|
1127
|
+
}
|
|
1128
|
+
async function detectCountryFromGeoIP() {
|
|
1129
|
+
try {
|
|
1130
|
+
const controller = new AbortController();
|
|
1131
|
+
const timeoutId = setTimeout(() => controller.abort(), GEO_IP_TIMEOUT);
|
|
1132
|
+
const res = await fetch(GEO_IP_URL, {
|
|
1133
|
+
signal: controller.signal,
|
|
1134
|
+
headers: { Accept: "application/json" }
|
|
1135
|
+
});
|
|
1136
|
+
clearTimeout(timeoutId);
|
|
1137
|
+
if (!res.ok) return null;
|
|
1138
|
+
const json = await res.json();
|
|
1139
|
+
const code = (json.country || json.country_code || json.countryCode || json.country_code2 || "").toString().toUpperCase();
|
|
1140
|
+
return code || null;
|
|
1141
|
+
} catch {
|
|
1142
|
+
return null;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
function detectCountryFromLocale() {
|
|
1146
|
+
try {
|
|
1147
|
+
const lang = getNavigatorLang();
|
|
1148
|
+
try {
|
|
1149
|
+
const loc = new Intl.Locale(lang);
|
|
1150
|
+
if (loc.region) return loc.region.toUpperCase();
|
|
1151
|
+
} catch {
|
|
1152
|
+
}
|
|
1153
|
+
const parts = lang.split(/[-_]/);
|
|
1154
|
+
if (parts.length > 1) return parts[1]?.toUpperCase() || null;
|
|
1155
|
+
} catch {
|
|
1156
|
+
}
|
|
1157
|
+
return null;
|
|
1158
|
+
}
|
|
1159
|
+
async function initState(binding) {
|
|
1160
|
+
const value = binding.value;
|
|
1161
|
+
let options = {};
|
|
1162
|
+
if (typeof value === "string") {
|
|
1163
|
+
options = { country: value };
|
|
1164
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1165
|
+
options = value;
|
|
1166
|
+
}
|
|
1167
|
+
const locale = options.locale || getNavigatorLang() || "en";
|
|
1168
|
+
let country = null;
|
|
1169
|
+
if (options.country) {
|
|
1170
|
+
country = getCountry(options.country, locale);
|
|
1171
|
+
} else if (options.detect) {
|
|
1172
|
+
const geoCountry = await detectCountryFromGeoIP();
|
|
1173
|
+
if (geoCountry) {
|
|
1174
|
+
country = getCountry(geoCountry, locale);
|
|
1175
|
+
}
|
|
1176
|
+
if (!country) {
|
|
1177
|
+
const localeCountry = detectCountryFromLocale();
|
|
1178
|
+
if (localeCountry) {
|
|
1179
|
+
country = getCountry(localeCountry, locale);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (!country) {
|
|
1184
|
+
country = getDefaultCountry(locale);
|
|
1185
|
+
}
|
|
1186
|
+
return {
|
|
1187
|
+
country,
|
|
1188
|
+
formatter: createPhoneFormatter(country),
|
|
1189
|
+
digits: "",
|
|
1190
|
+
locale,
|
|
1191
|
+
options
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
function updateDisplay(el, state) {
|
|
1195
|
+
el.value = state.formatter.formatDisplay(state.digits);
|
|
1196
|
+
if (state.options.onChange) {
|
|
1197
|
+
const fullNumberFormatted = `${state.country.code} ${el.value}`;
|
|
1198
|
+
const fullNumber = `${state.country.code}${state.digits}`;
|
|
1199
|
+
state.options.onChange({
|
|
1200
|
+
full: fullNumber,
|
|
1201
|
+
fullFormatted: fullNumberFormatted,
|
|
1202
|
+
digits: state.digits
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
function createBeforeInputHandler(el) {
|
|
1207
|
+
return (e) => {
|
|
1208
|
+
const data = e.data;
|
|
1209
|
+
if (e.inputType !== "insertText" || !data) return;
|
|
1210
|
+
if (InvalidPattern.test(data) || data === " " && el.value.endsWith(" ")) {
|
|
1211
|
+
e.preventDefault();
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function createInputHandler(el, state) {
|
|
1216
|
+
return (e) => {
|
|
1217
|
+
const target = e.target;
|
|
1218
|
+
if (!target) return;
|
|
1219
|
+
const raw = target.value || "";
|
|
1220
|
+
const maxDigits = state.formatter.getMaxDigits();
|
|
1221
|
+
state.digits = extractDigits(raw, maxDigits);
|
|
1222
|
+
updateDisplay(el, state);
|
|
1223
|
+
vue.nextTick(() => {
|
|
1224
|
+
const pos = state.formatter.getCaretPosition(state.digits.length);
|
|
1225
|
+
setCaret(el, pos);
|
|
1226
|
+
});
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
function createKeydownHandler(el, state) {
|
|
1230
|
+
return (e) => {
|
|
1231
|
+
if (e.ctrlKey || e.metaKey || e.altKey || NavigationKeys.includes(e.key)) return;
|
|
1232
|
+
const [selStart, selEnd] = getSelection(el);
|
|
1233
|
+
if (e.key === "Backspace") {
|
|
1234
|
+
e.preventDefault();
|
|
1235
|
+
if (selStart !== selEnd) {
|
|
1236
|
+
const range = state.formatter.getDigitRange(state.digits, selStart, selEnd);
|
|
1237
|
+
if (range) {
|
|
1238
|
+
const [start, end] = range;
|
|
1239
|
+
state.digits = state.digits.slice(0, start) + state.digits.slice(end);
|
|
1240
|
+
updateDisplay(el, state);
|
|
1241
|
+
vue.nextTick(() => {
|
|
1242
|
+
const pos = state.formatter.getCaretPosition(start);
|
|
1243
|
+
setCaret(el, pos);
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
if (selStart > 0) {
|
|
1249
|
+
const displayStr = el.value;
|
|
1250
|
+
let prevPos = selStart - 1;
|
|
1251
|
+
while (prevPos >= 0 && Delimiters.includes(displayStr[prevPos])) {
|
|
1252
|
+
prevPos--;
|
|
1253
|
+
}
|
|
1254
|
+
if (prevPos >= 0) {
|
|
1255
|
+
const range = state.formatter.getDigitRange(state.digits, prevPos, prevPos + 1);
|
|
1256
|
+
if (range) {
|
|
1257
|
+
const [start] = range;
|
|
1258
|
+
state.digits = state.digits.slice(0, start) + state.digits.slice(start + 1);
|
|
1259
|
+
updateDisplay(el, state);
|
|
1260
|
+
vue.nextTick(() => {
|
|
1261
|
+
const pos = state.formatter.getCaretPosition(start);
|
|
1262
|
+
setCaret(el, pos);
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (e.key === "Delete") {
|
|
1270
|
+
e.preventDefault();
|
|
1271
|
+
if (selStart !== selEnd) {
|
|
1272
|
+
const range = state.formatter.getDigitRange(state.digits, selStart, selEnd);
|
|
1273
|
+
if (range) {
|
|
1274
|
+
const [start, end] = range;
|
|
1275
|
+
state.digits = state.digits.slice(0, start) + state.digits.slice(end);
|
|
1276
|
+
updateDisplay(el, state);
|
|
1277
|
+
vue.nextTick(() => {
|
|
1278
|
+
const pos = state.formatter.getCaretPosition(start);
|
|
1279
|
+
setCaret(el, pos);
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
if (selStart < el.value.length) {
|
|
1285
|
+
const range = state.formatter.getDigitRange(state.digits, selStart, selStart + 1);
|
|
1286
|
+
if (range) {
|
|
1287
|
+
const [start] = range;
|
|
1288
|
+
state.digits = state.digits.slice(0, start) + state.digits.slice(start + 1);
|
|
1289
|
+
updateDisplay(el, state);
|
|
1290
|
+
vue.nextTick(() => {
|
|
1291
|
+
const pos = state.formatter.getCaretPosition(start);
|
|
1292
|
+
setCaret(el, pos);
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (/^[0-9]$/.test(e.key)) {
|
|
1299
|
+
if (state.digits.length >= state.formatter.getMaxDigits()) {
|
|
1300
|
+
e.preventDefault();
|
|
1301
|
+
}
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
if (e.key.length === 1) {
|
|
1305
|
+
e.preventDefault();
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
function createPasteHandler(el, state) {
|
|
1310
|
+
return (e) => {
|
|
1311
|
+
e.preventDefault();
|
|
1312
|
+
const text = e.clipboardData?.getData("text") || "";
|
|
1313
|
+
const maxDigits = state.formatter.getMaxDigits();
|
|
1314
|
+
const pastedDigits = extractDigits(text, maxDigits);
|
|
1315
|
+
if (pastedDigits.length === 0) return;
|
|
1316
|
+
const [selStart, selEnd] = getSelection(el);
|
|
1317
|
+
if (selStart !== selEnd) {
|
|
1318
|
+
const range2 = state.formatter.getDigitRange(state.digits, selStart, selEnd);
|
|
1319
|
+
if (range2) {
|
|
1320
|
+
const [start, end] = range2;
|
|
1321
|
+
const left2 = state.digits.slice(0, start);
|
|
1322
|
+
const right2 = state.digits.slice(end);
|
|
1323
|
+
state.digits = extractDigits(left2 + pastedDigits + right2, maxDigits);
|
|
1324
|
+
updateDisplay(el, state);
|
|
1325
|
+
vue.nextTick(() => {
|
|
1326
|
+
const pos = state.formatter.getCaretPosition(start + pastedDigits.length);
|
|
1327
|
+
setCaret(el, pos);
|
|
1328
|
+
});
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
const range = state.formatter.getDigitRange(state.digits, selStart, selStart);
|
|
1333
|
+
const insertIndex = range ? range[0] : state.digits.length;
|
|
1334
|
+
const left = state.digits.slice(0, insertIndex);
|
|
1335
|
+
const right = state.digits.slice(insertIndex);
|
|
1336
|
+
state.digits = extractDigits(left + pastedDigits + right, maxDigits);
|
|
1337
|
+
updateDisplay(el, state);
|
|
1338
|
+
vue.nextTick(() => {
|
|
1339
|
+
const pos = state.formatter.getCaretPosition(insertIndex + pastedDigits.length);
|
|
1340
|
+
setCaret(el, pos);
|
|
1341
|
+
});
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
async function updateCountry(el, state, newCountryCode) {
|
|
1345
|
+
const newCountry = getCountry(newCountryCode, state.locale);
|
|
1346
|
+
if (!newCountry) return;
|
|
1347
|
+
state.country = newCountry;
|
|
1348
|
+
state.formatter = createPhoneFormatter(newCountry);
|
|
1349
|
+
el.placeholder = state.formatter.getPlaceholder();
|
|
1350
|
+
const maxDigits = state.formatter.getMaxDigits();
|
|
1351
|
+
if (state.digits.length > maxDigits) {
|
|
1352
|
+
state.digits = state.digits.slice(0, maxDigits);
|
|
1353
|
+
}
|
|
1354
|
+
updateDisplay(el, state);
|
|
1355
|
+
if (state.options.onCountryChange) {
|
|
1356
|
+
state.options.onCountryChange(newCountry);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
const vPhoneMask = {
|
|
1360
|
+
async mounted(el, binding) {
|
|
1361
|
+
if (el.tagName !== "INPUT") {
|
|
1362
|
+
console.warn("[v-phone-mask] Directive can only be used on input elements");
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
el.setAttribute("type", "tel");
|
|
1366
|
+
el.setAttribute("inputmode", "tel");
|
|
1367
|
+
const state = await initState(binding);
|
|
1368
|
+
el.__phoneMaskState = state;
|
|
1369
|
+
state.inputHandler = createInputHandler(el, state);
|
|
1370
|
+
state.keydownHandler = createKeydownHandler(el, state);
|
|
1371
|
+
state.pasteHandler = createPasteHandler(el, state);
|
|
1372
|
+
state.beforeInputHandler = createBeforeInputHandler(el);
|
|
1373
|
+
el.addEventListener("beforeinput", state.beforeInputHandler);
|
|
1374
|
+
el.addEventListener("input", state.inputHandler);
|
|
1375
|
+
el.addEventListener("keydown", state.keydownHandler);
|
|
1376
|
+
el.addEventListener("paste", state.pasteHandler);
|
|
1377
|
+
el.setAttribute("placeholder", state.formatter.getPlaceholder());
|
|
1378
|
+
if (state.options.onCountryChange) {
|
|
1379
|
+
state.options.onCountryChange(state.country);
|
|
1380
|
+
}
|
|
1381
|
+
if (el.value) {
|
|
1382
|
+
const maxDigits = state.formatter.getMaxDigits();
|
|
1383
|
+
state.digits = extractDigits(el.value, maxDigits);
|
|
1384
|
+
updateDisplay(el, state);
|
|
1385
|
+
}
|
|
1386
|
+
},
|
|
1387
|
+
async updated(el, binding) {
|
|
1388
|
+
const state = el.__phoneMaskState;
|
|
1389
|
+
if (!state) return;
|
|
1390
|
+
const value = binding.value;
|
|
1391
|
+
let newOptions = {};
|
|
1392
|
+
if (typeof value === "string") {
|
|
1393
|
+
newOptions = { country: value };
|
|
1394
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1395
|
+
newOptions = value;
|
|
1396
|
+
}
|
|
1397
|
+
const oldCountry = state.options.country;
|
|
1398
|
+
state.options = newOptions;
|
|
1399
|
+
const newCountry = newOptions.country;
|
|
1400
|
+
if (newCountry && newCountry !== oldCountry) {
|
|
1401
|
+
await updateCountry(el, state, newCountry);
|
|
1402
|
+
}
|
|
1403
|
+
const newDigits = extractDigits(el.value);
|
|
1404
|
+
if (newDigits !== state.digits) {
|
|
1405
|
+
state.digits = newDigits;
|
|
1406
|
+
updateDisplay(el, state);
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
unmounted(el) {
|
|
1410
|
+
const state = el.__phoneMaskState;
|
|
1411
|
+
if (!state) return;
|
|
1412
|
+
if (state.beforeInputHandler) el.removeEventListener("beforeinput", state.beforeInputHandler);
|
|
1413
|
+
if (state.inputHandler) el.removeEventListener("input", state.inputHandler);
|
|
1414
|
+
if (state.keydownHandler) el.removeEventListener("keydown", state.keydownHandler);
|
|
1415
|
+
if (state.pasteHandler) el.removeEventListener("paste", state.pasteHandler);
|
|
1416
|
+
delete el.__phoneMaskState;
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
function install(app) {
|
|
1420
|
+
app.component("PhoneInput", PhoneInput);
|
|
1421
|
+
app.directive("phone-mask", vPhoneMask);
|
|
1422
|
+
}
|
|
1423
|
+
const index = {
|
|
1424
|
+
install
|
|
1425
|
+
};
|
|
1426
|
+
const PMaskHelpers = {
|
|
1427
|
+
getFlagEmoji: g,
|
|
1428
|
+
countPlaceholders,
|
|
1429
|
+
formatDigitsWithMap,
|
|
1430
|
+
pickMaskVariant,
|
|
1431
|
+
removeCountryCodePrefix,
|
|
1432
|
+
toArray
|
|
1433
|
+
};
|
|
1434
|
+
exports.PMaskHelpers = PMaskHelpers;
|
|
1435
|
+
exports.PhoneInput = PhoneInput;
|
|
1436
|
+
exports.default = index;
|
|
1437
|
+
exports.install = install;
|
|
1438
|
+
exports.vPhoneMask = vPhoneMask;
|
|
1439
|
+
exports.vPhoneMaskSetCountry = updateCountry;
|