maz-ui 3.19.2 → 3.19.3
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/components/MazFullscreenLoader.d.ts +3 -0
- package/components/MazPhoneNumberInput.mjs +1 -1
- package/components/assets/MazPhoneNumberInput.css +1 -1
- package/components/chunks/{MazBtn-0d8e3249.mjs → MazBtn-b29e3116.mjs} +2 -2
- package/components/chunks/MazPhoneNumberInput-e4f90230.mjs +1423 -0
- package/components/chunks/{MazSpinner-6025406b.mjs → MazSpinner-c9df761f.mjs} +1 -1
- package/nuxt/index.json +1 -1
- package/nuxt/index.mjs +9 -5
- package/package.json +10 -10
- package/types/components/MazFullscreenLoader.vue.d.ts +3 -0
- package/types/modules/directives/v-fullscreen-img/MazFullscreenImg.vue.d.ts +3 -0
- package/types/tailwindcss/tailwind.config.d.ts +1 -2
- package/components/chunks/MazInput-15f3e149.mjs +0 -344
- package/components/chunks/MazPhoneNumberInput-901c4fa6.mjs +0 -651
- package/components/chunks/MazSelect-c5c3f874.mjs +0 -444
|
@@ -1,651 +0,0 @@
|
|
|
1
|
-
import "../assets/MazPhoneNumberInput.css";
|
|
2
|
-
import { computed, defineComponent, defineAsyncComponent, getCurrentInstance, ref, reactive, onMounted, nextTick, watch, openBlock, createElementBlock, unref, normalizeClass, toDisplayString, createCommentVNode, createBlock, withCtx, createElementVNode, createVNode, mergeProps } from "vue";
|
|
3
|
-
import { isSupportedCountry, getCountryCallingCode, getExampleNumber, getCountries, parsePhoneNumberFromString, AsYouType } from "libphonenumber-js";
|
|
4
|
-
function truthyFilter(value) {
|
|
5
|
-
return !!value;
|
|
6
|
-
}
|
|
7
|
-
const useInstanceUniqId = ({
|
|
8
|
-
componentName,
|
|
9
|
-
instance,
|
|
10
|
-
providedId
|
|
11
|
-
}) => {
|
|
12
|
-
return computed(() => providedId ?? `${componentName}-${instance == null ? void 0 : instance.uid}`);
|
|
13
|
-
};
|
|
14
|
-
const defaultLocales = {
|
|
15
|
-
countrySelector: {
|
|
16
|
-
placeholder: "Country code",
|
|
17
|
-
error: "Choose country",
|
|
18
|
-
searchPlaceholder: "Search the country"
|
|
19
|
-
},
|
|
20
|
-
phoneInput: {
|
|
21
|
-
placeholder: "Phone number",
|
|
22
|
-
example: "Example:"
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
function localeToUnicodeFlag(locale) {
|
|
26
|
-
const characters = [...locale];
|
|
27
|
-
return characters.map((letter) => letter.charCodeAt(0) % 32 + 127461).map((n) => String.fromCodePoint(n)).join("");
|
|
28
|
-
}
|
|
29
|
-
let displayNamesInstance = void 0;
|
|
30
|
-
function getCountryName(locale, code, customCountriesNameListByIsoCode) {
|
|
31
|
-
if (customCountriesNameListByIsoCode == null ? void 0 : customCountriesNameListByIsoCode[code]) {
|
|
32
|
-
return customCountriesNameListByIsoCode[code];
|
|
33
|
-
}
|
|
34
|
-
if (!displayNamesInstance) {
|
|
35
|
-
displayNamesInstance = new Intl.DisplayNames([locale], { type: "region" });
|
|
36
|
-
}
|
|
37
|
-
return displayNamesInstance.of(code);
|
|
38
|
-
}
|
|
39
|
-
const PHONE_CHAR_REGEX = /^[\d ().-]+$/;
|
|
40
|
-
const NON_ALPHA_REGEX = /^[^a-z]+$/i;
|
|
41
|
-
let examples;
|
|
42
|
-
async function loadPhoneNumberExamplesFile() {
|
|
43
|
-
const { default: data } = await import("./examples.mobile.json-618ba782.mjs");
|
|
44
|
-
examples = data;
|
|
45
|
-
return examples;
|
|
46
|
-
}
|
|
47
|
-
function isSameCountryCallingCode(countryCode, countryCode2) {
|
|
48
|
-
return getCountryCallingCode(countryCode) === getCountryCallingCode(countryCode2);
|
|
49
|
-
}
|
|
50
|
-
function getPhoneNumberExample(countryCode) {
|
|
51
|
-
var _a;
|
|
52
|
-
try {
|
|
53
|
-
return countryCode ? (_a = getExampleNumber(countryCode, examples)) == null ? void 0 : _a.formatNational() : void 0;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error(`[maz-ui](MazPhoneNumberInput) ${error}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function sanitizePhoneNumber(input) {
|
|
59
|
-
if (!input) {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
const hasNonAlpha = NON_ALPHA_REGEX.test(input);
|
|
63
|
-
const hasPhoneChar = PHONE_CHAR_REGEX.test(input);
|
|
64
|
-
if (!hasNonAlpha && !hasPhoneChar) {
|
|
65
|
-
return input.replaceAll(/[^\d.]/g, "");
|
|
66
|
-
}
|
|
67
|
-
return input;
|
|
68
|
-
}
|
|
69
|
-
function getCountriesList(locale, customCountriesNameListByIsoCode) {
|
|
70
|
-
const countriesList = [];
|
|
71
|
-
const isoList = getCountries();
|
|
72
|
-
for (const iso2 of isoList) {
|
|
73
|
-
locale = locale ?? browserLocale().browserLocale ?? "en-US";
|
|
74
|
-
const name = getCountryName(locale, iso2, customCountriesNameListByIsoCode);
|
|
75
|
-
if (name) {
|
|
76
|
-
try {
|
|
77
|
-
const dialCode = getCountryCallingCode(iso2);
|
|
78
|
-
countriesList.push({
|
|
79
|
-
iso2,
|
|
80
|
-
dialCode,
|
|
81
|
-
name
|
|
82
|
-
});
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error(`[MazPhoneNumberInput](getCountryCallingCode) ${error}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return countriesList;
|
|
89
|
-
}
|
|
90
|
-
function browserLocale() {
|
|
91
|
-
if (typeof window === "undefined") {
|
|
92
|
-
return {};
|
|
93
|
-
}
|
|
94
|
-
const browserLocale2 = window.navigator.language;
|
|
95
|
-
if (!browserLocale2) {
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
let locale = browserLocale2.slice(3, 7).toUpperCase();
|
|
99
|
-
if (locale === "") {
|
|
100
|
-
locale = browserLocale2.slice(0, 2).toUpperCase();
|
|
101
|
-
}
|
|
102
|
-
if (locale === "EN") {
|
|
103
|
-
locale = "US";
|
|
104
|
-
}
|
|
105
|
-
if (locale === "JA") {
|
|
106
|
-
locale = "JP";
|
|
107
|
-
}
|
|
108
|
-
return { locale, browserLocale: browserLocale2 };
|
|
109
|
-
}
|
|
110
|
-
function isCountryAvailable(locale) {
|
|
111
|
-
try {
|
|
112
|
-
const response = isSupportedCountry(locale);
|
|
113
|
-
if (!response) {
|
|
114
|
-
console.error(`[maz-ui](MazPhoneNumberInput) The code country "${locale}" is not available`);
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return response;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error(`[maz-ui](MazPhoneNumberInput) ${error}`);
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const getResultsFromPhoneNumber = ({
|
|
124
|
-
phoneNumber,
|
|
125
|
-
countryCode
|
|
126
|
-
}) => {
|
|
127
|
-
try {
|
|
128
|
-
if (!phoneNumber) {
|
|
129
|
-
return {
|
|
130
|
-
isValid: false,
|
|
131
|
-
countryCode
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const parsedNumber = parsePhoneNumberFromString(phoneNumber, countryCode);
|
|
135
|
-
return {
|
|
136
|
-
isValid: (parsedNumber == null ? void 0 : parsedNumber.isValid()) ?? false,
|
|
137
|
-
isPossible: parsedNumber == null ? void 0 : parsedNumber.isPossible(),
|
|
138
|
-
countryCode: parsedNumber == null ? void 0 : parsedNumber.country,
|
|
139
|
-
countryCallingCode: parsedNumber == null ? void 0 : parsedNumber.countryCallingCode,
|
|
140
|
-
nationalNumber: parsedNumber == null ? void 0 : parsedNumber.nationalNumber,
|
|
141
|
-
type: parsedNumber == null ? void 0 : parsedNumber.getType(),
|
|
142
|
-
formatInternational: parsedNumber == null ? void 0 : parsedNumber.formatInternational(),
|
|
143
|
-
formatNational: parsedNumber == null ? void 0 : parsedNumber.formatNational(),
|
|
144
|
-
uri: parsedNumber == null ? void 0 : parsedNumber.getURI(),
|
|
145
|
-
e164: parsedNumber == null ? void 0 : parsedNumber.format("E.164"),
|
|
146
|
-
rfc3966: parsedNumber == null ? void 0 : parsedNumber.format("RFC3966")
|
|
147
|
-
};
|
|
148
|
-
} catch (error) {
|
|
149
|
-
throw new Error(`[MazPhoneNumberInput](getResultsFromPhoneNumber) ${error}`);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
function getAsYouTypeFormat(countryCode, phoneNumber) {
|
|
153
|
-
try {
|
|
154
|
-
if (!phoneNumber) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
return new AsYouType(countryCode).input(phoneNumber);
|
|
158
|
-
} catch (error) {
|
|
159
|
-
throw new Error(`[MazPhoneNumberInput](getAsYouTypeFormat) ${error}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async function fetchCountryCode() {
|
|
163
|
-
try {
|
|
164
|
-
const reponse = await fetch("https://ipwho.is");
|
|
165
|
-
const { country_code } = await reponse.json();
|
|
166
|
-
return country_code;
|
|
167
|
-
} catch (error) {
|
|
168
|
-
throw new Error(`[MazPhoneNumberInput](fetchCountryCode) ${error}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function useLibphonenumber() {
|
|
172
|
-
return {
|
|
173
|
-
fetchCountryCode,
|
|
174
|
-
getAsYouTypeFormat,
|
|
175
|
-
getResultsFromPhoneNumber,
|
|
176
|
-
loadPhoneNumberExamplesFile,
|
|
177
|
-
getPhoneNumberExample,
|
|
178
|
-
sanitizePhoneNumber,
|
|
179
|
-
getCountriesList,
|
|
180
|
-
browserLocale,
|
|
181
|
-
isSameCountryCallingCode
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
const _hoisted_1 = ["id"];
|
|
185
|
-
const _hoisted_2 = {
|
|
186
|
-
key: 0,
|
|
187
|
-
class: "maz-mr-2 maz-text-lg"
|
|
188
|
-
};
|
|
189
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
190
|
-
__name: "MazPhoneNumberInput",
|
|
191
|
-
props: {
|
|
192
|
-
modelValue: {
|
|
193
|
-
type: String,
|
|
194
|
-
validator: (prop) => {
|
|
195
|
-
return typeof prop === "string" || prop === void 0;
|
|
196
|
-
},
|
|
197
|
-
default: void 0
|
|
198
|
-
},
|
|
199
|
-
/** @deprecated */
|
|
200
|
-
defaultPhoneNumber: { type: String, default: void 0 },
|
|
201
|
-
countryCode: {
|
|
202
|
-
type: String,
|
|
203
|
-
default: void 0,
|
|
204
|
-
validator: (code) => isCountryAvailable(code)
|
|
205
|
-
},
|
|
206
|
-
/** @deprecated - use country-code or v-model:country-code */
|
|
207
|
-
defaultCountryCode: {
|
|
208
|
-
type: String,
|
|
209
|
-
default: void 0,
|
|
210
|
-
validator: (code) => isCountryAvailable(code)
|
|
211
|
-
},
|
|
212
|
-
id: { type: String, default: void 0 },
|
|
213
|
-
placeholder: { type: String, default: void 0 },
|
|
214
|
-
preferredCountries: { type: Array, default: void 0 },
|
|
215
|
-
ignoredCountries: { type: Array, default: void 0 },
|
|
216
|
-
onlyCountries: { type: Array, default: void 0 },
|
|
217
|
-
translations: { type: Object, default: void 0 },
|
|
218
|
-
listPosition: {
|
|
219
|
-
type: String,
|
|
220
|
-
default: "bottom left",
|
|
221
|
-
validator: (value) => {
|
|
222
|
-
return ["top", "top right", "top left", "bottom", "bottom right", "bottom left"].includes(
|
|
223
|
-
value
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
color: { type: String, default: "primary" },
|
|
228
|
-
size: {
|
|
229
|
-
type: String,
|
|
230
|
-
default: "md",
|
|
231
|
-
validator: (value) => {
|
|
232
|
-
return ["mini", "xs", "sm", "md", "lg", "xl"].includes(value);
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
noFlags: { type: Boolean, default: false },
|
|
236
|
-
disabled: { type: Boolean, default: false },
|
|
237
|
-
noExample: { type: Boolean, default: false },
|
|
238
|
-
noSearch: { type: Boolean, default: false },
|
|
239
|
-
noUseBrowserLocale: { type: Boolean, default: false },
|
|
240
|
-
fetchCountry: { type: Boolean, default: false },
|
|
241
|
-
noCountrySelector: { type: Boolean, default: false },
|
|
242
|
-
showCodeOnList: { type: Boolean, default: false },
|
|
243
|
-
error: { type: Boolean, default: false },
|
|
244
|
-
customCountriesList: {
|
|
245
|
-
type: Object,
|
|
246
|
-
default: void 0
|
|
247
|
-
},
|
|
248
|
-
/**
|
|
249
|
-
* Disabled auto-format as you type
|
|
250
|
-
*/
|
|
251
|
-
noFormattingAsYouType: { type: Boolean, default: false },
|
|
252
|
-
/**
|
|
253
|
-
* locale of country list - Ex: "fr-FR"
|
|
254
|
-
* @default browser locale
|
|
255
|
-
*/
|
|
256
|
-
countryLocale: { type: String, default: void 0 }
|
|
257
|
-
},
|
|
258
|
-
emits: [
|
|
259
|
-
/** emitted when country or phone number changed
|
|
260
|
-
* @returns data - {Result}
|
|
261
|
-
*/
|
|
262
|
-
"update",
|
|
263
|
-
/** emitted when country or phone number changed
|
|
264
|
-
* @returns data - {Result}
|
|
265
|
-
*/
|
|
266
|
-
"data",
|
|
267
|
-
/** emitted when selected country changed */
|
|
268
|
-
"country-code",
|
|
269
|
-
/** Two way binding (v-model:model-value) - emitted when country changed */
|
|
270
|
-
"update:model-value",
|
|
271
|
-
/** Two way binding (v-model:country-code) - emitted when country changed */
|
|
272
|
-
"update:country-code"
|
|
273
|
-
],
|
|
274
|
-
setup(__props, { emit: __emit }) {
|
|
275
|
-
const {
|
|
276
|
-
fetchCountryCode: fetchCountryCode2,
|
|
277
|
-
browserLocale: browserLocale2,
|
|
278
|
-
getResultsFromPhoneNumber: getResultsFromPhoneNumber2,
|
|
279
|
-
getAsYouTypeFormat: getAsYouTypeFormat2,
|
|
280
|
-
getCountriesList: getCountriesList2,
|
|
281
|
-
getPhoneNumberExample: getPhoneNumberExample2,
|
|
282
|
-
sanitizePhoneNumber: sanitizePhoneNumber2,
|
|
283
|
-
loadPhoneNumberExamplesFile: loadPhoneNumberExamplesFile2
|
|
284
|
-
} = useLibphonenumber();
|
|
285
|
-
const MazInput = defineAsyncComponent(() => import("./MazInput-15f3e149.mjs"));
|
|
286
|
-
const MazSelect = defineAsyncComponent(() => import("./MazSelect-c5c3f874.mjs"));
|
|
287
|
-
const emits = __emit;
|
|
288
|
-
const props = __props;
|
|
289
|
-
const instance = getCurrentInstance();
|
|
290
|
-
const instanceId = useInstanceUniqId({
|
|
291
|
-
componentName: "MazPhoneNumberInput",
|
|
292
|
-
instance,
|
|
293
|
-
providedId: props.id
|
|
294
|
-
});
|
|
295
|
-
const PhoneNumberInput = ref();
|
|
296
|
-
const CountrySelector = ref();
|
|
297
|
-
const selectionRange = reactive({
|
|
298
|
-
start: 0,
|
|
299
|
-
end: 0,
|
|
300
|
-
cursorAtEnd: true
|
|
301
|
-
});
|
|
302
|
-
const examplesFileLoaded = ref(false);
|
|
303
|
-
const inputFocused = ref(false);
|
|
304
|
-
const countries = computed(() => getCountriesList2(props.countryLocale, props.customCountriesList));
|
|
305
|
-
const countriesList = computed(() => {
|
|
306
|
-
var _a;
|
|
307
|
-
return (_a = countries.value) == null ? void 0 : _a.filter((item) => {
|
|
308
|
-
var _a2;
|
|
309
|
-
return !((_a2 = props.ignoredCountries) == null ? void 0 : _a2.includes(item.iso2));
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
const countriesFiltered = computed(() => {
|
|
313
|
-
const countries2 = props.onlyCountries || props.preferredCountries;
|
|
314
|
-
return countries2 == null ? void 0 : countries2.map(
|
|
315
|
-
(country) => {
|
|
316
|
-
var _a;
|
|
317
|
-
return (_a = countriesList.value) == null ? void 0 : _a.find((item) => item.iso2.includes(country));
|
|
318
|
-
}
|
|
319
|
-
);
|
|
320
|
-
});
|
|
321
|
-
const otherCountries = computed(() => {
|
|
322
|
-
var _a;
|
|
323
|
-
return (_a = countriesList.value) == null ? void 0 : _a.filter((item) => {
|
|
324
|
-
var _a2;
|
|
325
|
-
return !((_a2 = props.preferredCountries) == null ? void 0 : _a2.includes(item.iso2));
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
const countriesSorted = computed(() => {
|
|
329
|
-
return props.preferredCountries ? [...countriesFiltered.value ?? [], ...otherCountries.value ?? []] : props.onlyCountries ? countriesFiltered.value : countriesList.value;
|
|
330
|
-
});
|
|
331
|
-
const countryOptions = computed(() => {
|
|
332
|
-
var _a;
|
|
333
|
-
return (_a = countriesSorted.value) == null ? void 0 : _a.map((country) => {
|
|
334
|
-
return country ? {
|
|
335
|
-
...country,
|
|
336
|
-
dialCode: `+${country.dialCode}`
|
|
337
|
-
} : void 0;
|
|
338
|
-
}).filter(truthyFilter);
|
|
339
|
-
});
|
|
340
|
-
const locales = computed(() => ({
|
|
341
|
-
...defaultLocales,
|
|
342
|
-
...props.translations
|
|
343
|
-
}));
|
|
344
|
-
const inputPlaceholder = computed(() => {
|
|
345
|
-
if (props.placeholder) {
|
|
346
|
-
return props.placeholder;
|
|
347
|
-
}
|
|
348
|
-
const defaultPlaceholder = locales.value.phoneInput.placeholder;
|
|
349
|
-
if (props.noExample || !examplesFileLoaded.value) {
|
|
350
|
-
return defaultPlaceholder;
|
|
351
|
-
} else {
|
|
352
|
-
const example = getPhoneNumberExample2(countryCode.value);
|
|
353
|
-
return results.value.isValid || !example ? defaultPlaceholder : `${locales.value.phoneInput.example} ${example}`;
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
const model = computed({
|
|
357
|
-
get: () => props.modelValue || props.defaultPhoneNumber,
|
|
358
|
-
set: (value) => {
|
|
359
|
-
emits("update:model-value", value);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
const internalCountryCode = ref();
|
|
363
|
-
const countryCode = computed({
|
|
364
|
-
get: () => props.countryCode || props.defaultCountryCode || internalCountryCode.value,
|
|
365
|
-
set: (value) => {
|
|
366
|
-
emits("country-code", value);
|
|
367
|
-
emits("update:country-code", value);
|
|
368
|
-
internalCountryCode.value = value;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
const internalValue = ref(model.value);
|
|
372
|
-
const results = ref(
|
|
373
|
-
getResultsFromPhoneNumber2({
|
|
374
|
-
phoneNumber: model.value,
|
|
375
|
-
countryCode: countryCode.value
|
|
376
|
-
})
|
|
377
|
-
);
|
|
378
|
-
const asYouTypeFormatted = ref();
|
|
379
|
-
const inputValue = computed(() => {
|
|
380
|
-
if (props.noFormattingAsYouType) {
|
|
381
|
-
return internalValue.value ?? "";
|
|
382
|
-
}
|
|
383
|
-
return asYouTypeFormatted.value ?? internalValue.value ?? "";
|
|
384
|
-
});
|
|
385
|
-
async function setCountryFromIpWho() {
|
|
386
|
-
const fetchedLocale = await fetchCountryCode2();
|
|
387
|
-
if (fetchedLocale)
|
|
388
|
-
setCountryCode(fetchedLocale);
|
|
389
|
-
}
|
|
390
|
-
async function loadExamples() {
|
|
391
|
-
try {
|
|
392
|
-
if (!props.noExample && !examplesFileLoaded.value) {
|
|
393
|
-
await loadPhoneNumberExamplesFile2();
|
|
394
|
-
examplesFileLoaded.value = true;
|
|
395
|
-
}
|
|
396
|
-
} catch {
|
|
397
|
-
console.error("[maz-ui](MazPhoneNumberInput) while loading phone number examples file");
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
onMounted(async () => {
|
|
401
|
-
await parseModel(model.value);
|
|
402
|
-
await nextTick();
|
|
403
|
-
if (props.fetchCountry && !countryCode.value) {
|
|
404
|
-
await setCountryFromIpWho();
|
|
405
|
-
}
|
|
406
|
-
if (!props.defaultCountryCode && !props.noUseBrowserLocale && !countryCode.value) {
|
|
407
|
-
setCountryCodeFromBrowserLocale();
|
|
408
|
-
}
|
|
409
|
-
await loadExamples();
|
|
410
|
-
});
|
|
411
|
-
watch(
|
|
412
|
-
() => results.value,
|
|
413
|
-
(newResults) => {
|
|
414
|
-
emits("update", newResults);
|
|
415
|
-
emits("data", newResults);
|
|
416
|
-
},
|
|
417
|
-
{ immediate: true, deep: true }
|
|
418
|
-
);
|
|
419
|
-
watch(
|
|
420
|
-
() => countryCode.value,
|
|
421
|
-
(newCountryCode, oldCountryCode) => {
|
|
422
|
-
if (newCountryCode && newCountryCode !== oldCountryCode) {
|
|
423
|
-
setCountryCode(newCountryCode);
|
|
424
|
-
onInputValueChanged(inputValue.value);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
);
|
|
428
|
-
watch(
|
|
429
|
-
() => model.value,
|
|
430
|
-
async (newModel, oldModel) => {
|
|
431
|
-
if (newModel !== oldModel) {
|
|
432
|
-
parseModel(newModel);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
);
|
|
436
|
-
watch(
|
|
437
|
-
() => inputValue.value,
|
|
438
|
-
async (newModel, oldModel) => {
|
|
439
|
-
if (!props.noFormattingAsYouType && newModel && newModel !== oldModel) {
|
|
440
|
-
const input = getPhoneNumberInput();
|
|
441
|
-
if (input && !results.value.isValid && typeof selectionRange.start === "number" && !selectionRange.cursorAtEnd) {
|
|
442
|
-
const start = selectionRange.start;
|
|
443
|
-
const end = selectionRange.end;
|
|
444
|
-
setTimeout(() => {
|
|
445
|
-
input.setSelectionRange(start, end ?? start);
|
|
446
|
-
}, 0);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
function setCountryCodeFromBrowserLocale() {
|
|
452
|
-
const { locale } = browserLocale2();
|
|
453
|
-
if (locale) {
|
|
454
|
-
setCountryCode(locale);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
function updateResults(phoneNumber, countryCode2) {
|
|
458
|
-
results.value = getResultsFromPhoneNumber2({
|
|
459
|
-
phoneNumber,
|
|
460
|
-
countryCode: countryCode2
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
async function onInputValueChanged(phoneNumber) {
|
|
464
|
-
const input = getPhoneNumberInput();
|
|
465
|
-
selectionRange.start = input == null ? void 0 : input.selectionStart;
|
|
466
|
-
selectionRange.end = input == null ? void 0 : input.selectionEnd;
|
|
467
|
-
selectionRange.cursorAtEnd = selectionRange.start ? selectionRange.start >= phoneNumber.length : true;
|
|
468
|
-
const sanitizedPhoneNumber = sanitizePhoneNumber2(phoneNumber);
|
|
469
|
-
internalValue.value = sanitizedPhoneNumber;
|
|
470
|
-
const newResults = getResultsFromPhoneNumber2({
|
|
471
|
-
phoneNumber: sanitizedPhoneNumber,
|
|
472
|
-
countryCode: countryCode.value
|
|
473
|
-
});
|
|
474
|
-
model.value = newResults.e164;
|
|
475
|
-
}
|
|
476
|
-
function onCountryChanged(codeCountry) {
|
|
477
|
-
updateResults(inputValue.value, codeCountry);
|
|
478
|
-
setCountryCode(codeCountry, true);
|
|
479
|
-
}
|
|
480
|
-
function setCountryCode(selectedCountryCode, autoFocusInput = false) {
|
|
481
|
-
try {
|
|
482
|
-
const countryAvailable = isCountryAvailable(selectedCountryCode);
|
|
483
|
-
if (countryAvailable) {
|
|
484
|
-
countryCode.value = selectedCountryCode;
|
|
485
|
-
if (autoFocusInput) {
|
|
486
|
-
focusPhoneNumberInput();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
} catch (error) {
|
|
490
|
-
console.error(`[maz-ui](MazPhoneNumberInput) ${error}`);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async function parseModel(newModel) {
|
|
494
|
-
updateResults(newModel, countryCode.value);
|
|
495
|
-
await nextTick();
|
|
496
|
-
if (props.noFormattingAsYouType) {
|
|
497
|
-
internalValue.value = inputValue.value;
|
|
498
|
-
} else {
|
|
499
|
-
asYouTypeFormatted.value = selectionRange.cursorAtEnd || results.value.isValid ? internalValue.value = getAsYouTypeFormat2(
|
|
500
|
-
results.value.countryCode ?? countryCode.value,
|
|
501
|
-
results.value.formatNational ?? internalValue.value
|
|
502
|
-
) : internalValue.value;
|
|
503
|
-
}
|
|
504
|
-
await nextTick();
|
|
505
|
-
autoUpdateCountryCodeWithResults(results.value);
|
|
506
|
-
}
|
|
507
|
-
function autoUpdateCountryCodeWithResults(newResults) {
|
|
508
|
-
if (newResults.countryCode && countryCode.value !== newResults.countryCode) {
|
|
509
|
-
setCountryCode(newResults.countryCode);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function getPhoneNumberInput() {
|
|
513
|
-
var _a;
|
|
514
|
-
return (_a = PhoneNumberInput.value) == null ? void 0 : _a.$el.querySelector("input");
|
|
515
|
-
}
|
|
516
|
-
function focusCountrySelector() {
|
|
517
|
-
var _a, _b;
|
|
518
|
-
(_b = (_a = CountrySelector.value) == null ? void 0 : _a.$el.querySelector("input")) == null ? void 0 : _b.focus();
|
|
519
|
-
}
|
|
520
|
-
function focusPhoneNumberInput() {
|
|
521
|
-
var _a;
|
|
522
|
-
(_a = getPhoneNumberInput()) == null ? void 0 : _a.focus();
|
|
523
|
-
}
|
|
524
|
-
return (_ctx, _cache) => {
|
|
525
|
-
var _a, _b;
|
|
526
|
-
return openBlock(), createElementBlock("div", {
|
|
527
|
-
id: unref(instanceId),
|
|
528
|
-
class: normalizeClass(["m-phone-number-input", {
|
|
529
|
-
"--no-flags": __props.noFlags
|
|
530
|
-
}])
|
|
531
|
-
}, [
|
|
532
|
-
countryCode.value && !__props.noFlags && !__props.noCountrySelector ? (openBlock(), createElementBlock(
|
|
533
|
-
"button",
|
|
534
|
-
{
|
|
535
|
-
key: 0,
|
|
536
|
-
class: "m-phone-number-input__country-flag maz-text-xl",
|
|
537
|
-
tabindex: "-1",
|
|
538
|
-
type: "button",
|
|
539
|
-
onClick: focusCountrySelector
|
|
540
|
-
},
|
|
541
|
-
toDisplayString(unref(localeToUnicodeFlag)(countryCode.value)),
|
|
542
|
-
1
|
|
543
|
-
/* TEXT */
|
|
544
|
-
)) : createCommentVNode("v-if", true),
|
|
545
|
-
!__props.noCountrySelector && countryOptions.value ? (openBlock(), createBlock(unref(MazSelect), {
|
|
546
|
-
key: 1,
|
|
547
|
-
ref_key: "CountrySelector",
|
|
548
|
-
ref: CountrySelector,
|
|
549
|
-
class: "m-phone-number-input__select",
|
|
550
|
-
"model-value": countryCode.value,
|
|
551
|
-
"option-value-key": "iso2",
|
|
552
|
-
"option-label-key": "name",
|
|
553
|
-
"option-input-value-key": "dialCode",
|
|
554
|
-
"max-list-width": 250,
|
|
555
|
-
disabled: __props.disabled,
|
|
556
|
-
color: __props.color,
|
|
557
|
-
size: __props.size,
|
|
558
|
-
"list-position": __props.listPosition,
|
|
559
|
-
search: !__props.noSearch,
|
|
560
|
-
"search-placeholder": locales.value.countrySelector.searchPlaceholder,
|
|
561
|
-
options: countryOptions.value,
|
|
562
|
-
error: __props.error || !!inputValue.value && !countryCode.value,
|
|
563
|
-
hint: !!inputValue.value && !countryCode.value ? locales.value.countrySelector.error : void 0,
|
|
564
|
-
label: locales.value.countrySelector.placeholder,
|
|
565
|
-
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => onCountryChanged($event)),
|
|
566
|
-
onFocus: _cache[1] || (_cache[1] = ($event) => inputFocused.value = false)
|
|
567
|
-
}, {
|
|
568
|
-
default: withCtx(({ option, isSelected }) => [
|
|
569
|
-
createElementVNode(
|
|
570
|
-
"div",
|
|
571
|
-
{
|
|
572
|
-
class: normalizeClass(["m-phone-number-input__select__item maz-flex maz-items-center maz-truncate", {
|
|
573
|
-
"m-phone-number-input__select__item--selected": isSelected
|
|
574
|
-
}])
|
|
575
|
-
},
|
|
576
|
-
[
|
|
577
|
-
!__props.noFlags && typeof option.iso2 === "string" ? (openBlock(), createElementBlock(
|
|
578
|
-
"span",
|
|
579
|
-
_hoisted_2,
|
|
580
|
-
toDisplayString(unref(localeToUnicodeFlag)(option.iso2)),
|
|
581
|
-
1
|
|
582
|
-
/* TEXT */
|
|
583
|
-
)) : createCommentVNode("v-if", true),
|
|
584
|
-
__props.showCodeOnList ? (openBlock(), createElementBlock(
|
|
585
|
-
"span",
|
|
586
|
-
{
|
|
587
|
-
key: 1,
|
|
588
|
-
class: normalizeClass(["maz-w-10 maz-flex-none", { "maz-text-muted": !isSelected }])
|
|
589
|
-
},
|
|
590
|
-
toDisplayString(option.dialCode),
|
|
591
|
-
3
|
|
592
|
-
/* TEXT, CLASS */
|
|
593
|
-
)) : createCommentVNode("v-if", true),
|
|
594
|
-
createElementVNode(
|
|
595
|
-
"span",
|
|
596
|
-
{
|
|
597
|
-
class: normalizeClass(["maz-flex-1 maz-truncate", { "maz-font-semibold": isSelected }])
|
|
598
|
-
},
|
|
599
|
-
toDisplayString(option.name),
|
|
600
|
-
3
|
|
601
|
-
/* TEXT, CLASS */
|
|
602
|
-
)
|
|
603
|
-
],
|
|
604
|
-
2
|
|
605
|
-
/* CLASS */
|
|
606
|
-
)
|
|
607
|
-
]),
|
|
608
|
-
_: 1
|
|
609
|
-
/* STABLE */
|
|
610
|
-
}, 8, ["model-value", "disabled", "color", "size", "list-position", "search", "search-placeholder", "options", "error", "hint", "label"])) : createCommentVNode("v-if", true),
|
|
611
|
-
createVNode(unref(MazInput), mergeProps({
|
|
612
|
-
id: __props.id,
|
|
613
|
-
ref_key: "PhoneNumberInput",
|
|
614
|
-
ref: PhoneNumberInput,
|
|
615
|
-
"model-value": inputValue.value,
|
|
616
|
-
label: inputPlaceholder.value,
|
|
617
|
-
disabled: __props.disabled,
|
|
618
|
-
color: __props.color,
|
|
619
|
-
error: __props.error || !!inputValue.value && !((_a = results.value) == null ? void 0 : _a.isValid)
|
|
620
|
-
}, _ctx.$attrs, {
|
|
621
|
-
size: __props.size,
|
|
622
|
-
"icon-name": "phone",
|
|
623
|
-
type: "tel",
|
|
624
|
-
clearable: "",
|
|
625
|
-
class: ["m-phone-number-input__input maz-flex-1", {
|
|
626
|
-
"--border-radius": !__props.noCountrySelector,
|
|
627
|
-
"--error": __props.error || !((_b = results.value) == null ? void 0 : _b.isValid),
|
|
628
|
-
"--focused": inputFocused.value
|
|
629
|
-
}],
|
|
630
|
-
onFocus: _cache[2] || (_cache[2] = ($event) => inputFocused.value = true),
|
|
631
|
-
onBlur: _cache[3] || (_cache[3] = ($event) => inputFocused.value = false),
|
|
632
|
-
"onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => onInputValueChanged($event))
|
|
633
|
-
}), null, 16, ["id", "model-value", "label", "disabled", "color", "error", "size", "class"])
|
|
634
|
-
], 10, _hoisted_1);
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
const MazPhoneNumberInput_vue_vue_type_style_index_0_scoped_5aac3f0b_lang = "";
|
|
639
|
-
const _export_sfc = (sfc, props) => {
|
|
640
|
-
const target = sfc.__vccOpts || sfc;
|
|
641
|
-
for (const [key, val] of props) {
|
|
642
|
-
target[key] = val;
|
|
643
|
-
}
|
|
644
|
-
return target;
|
|
645
|
-
};
|
|
646
|
-
const MazPhoneNumberInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-5aac3f0b"]]);
|
|
647
|
-
export {
|
|
648
|
-
MazPhoneNumberInput as M,
|
|
649
|
-
_export_sfc as _,
|
|
650
|
-
useInstanceUniqId as u
|
|
651
|
-
};
|