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
|
@@ -0,0 +1,1423 @@
|
|
|
1
|
+
import "../assets/MazPhoneNumberInput.css";
|
|
2
|
+
import { computed, defineAsyncComponent, defineComponent, ref, getCurrentInstance, onMounted, resolveComponent, openBlock, createElementBlock, normalizeClass, createElementVNode, renderSlot, createVNode, createCommentVNode, withDirectives, mergeProps, toHandlers, vModelDynamic, createTextVNode, toDisplayString, createBlock, withModifiers, withCtx, onBeforeMount, watch, nextTick, unref, Transition, normalizeStyle, Fragment, renderList, reactive } 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
|
+
function debounce(func, delay) {
|
|
185
|
+
let timeoutId;
|
|
186
|
+
return (...args) => {
|
|
187
|
+
if (timeoutId) {
|
|
188
|
+
clearTimeout(timeoutId);
|
|
189
|
+
}
|
|
190
|
+
timeoutId = setTimeout(() => {
|
|
191
|
+
func(...args);
|
|
192
|
+
}, delay);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const MazBtn = defineAsyncComponent(() => import("./MazBtn-b29e3116.mjs"));
|
|
196
|
+
const MazIcon = defineAsyncComponent(() => import("./MazIcon-bda198b4.mjs"));
|
|
197
|
+
const EyeOffIcon = defineAsyncComponent(() => import("./eye-slash-3c6844fc.mjs"));
|
|
198
|
+
const EyeIcon = defineAsyncComponent(() => import("./eye-290c6a03.mjs"));
|
|
199
|
+
const CheckIcon = defineAsyncComponent(() => import("./check-b1507ce9.mjs"));
|
|
200
|
+
const _sfc_main$2 = defineComponent({
|
|
201
|
+
components: {
|
|
202
|
+
MazBtn,
|
|
203
|
+
MazIcon,
|
|
204
|
+
CheckIcon,
|
|
205
|
+
EyeIcon,
|
|
206
|
+
EyeOffIcon
|
|
207
|
+
},
|
|
208
|
+
inheritAttrs: false,
|
|
209
|
+
props: {
|
|
210
|
+
modelValue: {
|
|
211
|
+
type: [String, Number, Boolean],
|
|
212
|
+
default: void 0
|
|
213
|
+
},
|
|
214
|
+
placeholder: { type: String, default: void 0 },
|
|
215
|
+
color: {
|
|
216
|
+
type: String,
|
|
217
|
+
default: "primary"
|
|
218
|
+
},
|
|
219
|
+
label: { type: String, default: void 0 },
|
|
220
|
+
name: { type: String, default: "input" },
|
|
221
|
+
type: {
|
|
222
|
+
type: String,
|
|
223
|
+
default: "text",
|
|
224
|
+
validator: (value) => {
|
|
225
|
+
return [
|
|
226
|
+
"text",
|
|
227
|
+
"date",
|
|
228
|
+
"number",
|
|
229
|
+
"tel",
|
|
230
|
+
"search",
|
|
231
|
+
"url",
|
|
232
|
+
"password",
|
|
233
|
+
"month",
|
|
234
|
+
"time",
|
|
235
|
+
"week",
|
|
236
|
+
"email"
|
|
237
|
+
].includes(value);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
required: { type: Boolean, default: false },
|
|
241
|
+
disabled: { type: Boolean, default: false },
|
|
242
|
+
readonly: { type: Boolean, default: false },
|
|
243
|
+
id: { type: String, default: void 0 },
|
|
244
|
+
error: { type: Boolean, default: false },
|
|
245
|
+
success: { type: Boolean, default: false },
|
|
246
|
+
warning: { type: Boolean, default: false },
|
|
247
|
+
hint: { type: String, default: void 0 },
|
|
248
|
+
inputClasses: { type: String, default: void 0 },
|
|
249
|
+
noBorder: { type: Boolean, default: false },
|
|
250
|
+
noRadius: { type: Boolean, default: false },
|
|
251
|
+
size: {
|
|
252
|
+
type: String,
|
|
253
|
+
default: "md",
|
|
254
|
+
validator: (value) => {
|
|
255
|
+
return ["mini", "xs", "sm", "md", "lg", "xl"].includes(value);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
debounce: { type: Boolean, default: false },
|
|
259
|
+
debounceDelay: { type: Number, default: 500 },
|
|
260
|
+
validButton: { type: Boolean, default: false },
|
|
261
|
+
validButtonLoading: { type: Boolean, default: false },
|
|
262
|
+
autoFocus: { type: Boolean, default: false },
|
|
263
|
+
borderActive: { type: Boolean, default: false },
|
|
264
|
+
leftIcon: { type: String, default: void 0 },
|
|
265
|
+
rightIcon: { type: String, default: void 0 }
|
|
266
|
+
},
|
|
267
|
+
emits: ["focus", "blur", "update:model-value", "click", "change", "update"],
|
|
268
|
+
setup(props, { emit, slots }) {
|
|
269
|
+
const hasPasswordVisible = ref(false);
|
|
270
|
+
const isFocused = ref(false);
|
|
271
|
+
const input = ref();
|
|
272
|
+
const instance = getCurrentInstance();
|
|
273
|
+
const instanceId = useInstanceUniqId({
|
|
274
|
+
componentName: "MazInput",
|
|
275
|
+
instance,
|
|
276
|
+
providedId: props.id
|
|
277
|
+
});
|
|
278
|
+
onMounted(() => {
|
|
279
|
+
var _a;
|
|
280
|
+
if (props.autoFocus) {
|
|
281
|
+
(_a = input.value) == null ? void 0 : _a.focus();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
const isPasswordType = computed(() => props.type === "password");
|
|
285
|
+
const inputType = computed(() => hasPasswordVisible.value ? "text" : props.type);
|
|
286
|
+
const borderStyle = computed(() => {
|
|
287
|
+
if (props.noBorder)
|
|
288
|
+
return void 0;
|
|
289
|
+
if (props.error)
|
|
290
|
+
return "maz-border-danger";
|
|
291
|
+
if (props.success)
|
|
292
|
+
return "maz-border-success";
|
|
293
|
+
if (props.warning)
|
|
294
|
+
return "maz-border-warning";
|
|
295
|
+
if (isFocused.value || props.borderActive) {
|
|
296
|
+
if (props.color === "black")
|
|
297
|
+
return "maz-border-black";
|
|
298
|
+
if (props.color === "danger")
|
|
299
|
+
return "maz-border-danger";
|
|
300
|
+
if (props.color === "info")
|
|
301
|
+
return "maz-border-info";
|
|
302
|
+
if (props.color === "primary")
|
|
303
|
+
return "maz-border-primary";
|
|
304
|
+
if (props.color === "secondary")
|
|
305
|
+
return "maz-border-secondary";
|
|
306
|
+
if (props.color === "success")
|
|
307
|
+
return "maz-border-success";
|
|
308
|
+
if (props.color === "warning")
|
|
309
|
+
return "maz-border-warning";
|
|
310
|
+
if (props.color === "white")
|
|
311
|
+
return "maz-border-white";
|
|
312
|
+
}
|
|
313
|
+
return "--default-border";
|
|
314
|
+
});
|
|
315
|
+
const computedPlaceholder = computed(() => {
|
|
316
|
+
const { required, placeholder } = props;
|
|
317
|
+
if (!placeholder)
|
|
318
|
+
return void 0;
|
|
319
|
+
return required ? `${placeholder} *` : placeholder;
|
|
320
|
+
});
|
|
321
|
+
const hasValue = computed(() => props.modelValue !== void 0 && props.modelValue !== "");
|
|
322
|
+
const inputValue = computed({
|
|
323
|
+
get: () => props.modelValue,
|
|
324
|
+
set: (value) => emitValue(value)
|
|
325
|
+
});
|
|
326
|
+
const shouldUp = computed(() => {
|
|
327
|
+
return (!!props.label || !!props.hint) && (isFocused.value || !!hasValue.value || !!props.placeholder || ["date", "month", "week"].includes(props.type));
|
|
328
|
+
});
|
|
329
|
+
const hasLabel = computed(() => !!props.label || !!props.hint);
|
|
330
|
+
const hasRightPart = () => {
|
|
331
|
+
return !!slots["right-icon"] || isPasswordType.value || !!slots["valid-button"] || props.validButton || !!props.rightIcon;
|
|
332
|
+
};
|
|
333
|
+
const hasLeftPart = () => {
|
|
334
|
+
return !!slots["left-icon"] || !!props.leftIcon;
|
|
335
|
+
};
|
|
336
|
+
const focus = (event) => {
|
|
337
|
+
emit("focus", event);
|
|
338
|
+
isFocused.value = true;
|
|
339
|
+
};
|
|
340
|
+
const blur = (event) => {
|
|
341
|
+
emit("blur", event);
|
|
342
|
+
isFocused.value = false;
|
|
343
|
+
};
|
|
344
|
+
const change = (event) => emit("change", event);
|
|
345
|
+
const debounceEmitValue = debounce((value) => {
|
|
346
|
+
emit("update:model-value", value);
|
|
347
|
+
}, props.debounceDelay);
|
|
348
|
+
const emitValue = (value) => {
|
|
349
|
+
if (props.debounce)
|
|
350
|
+
return debounceEmitValue(value);
|
|
351
|
+
emit("update:model-value", value);
|
|
352
|
+
};
|
|
353
|
+
return {
|
|
354
|
+
inputValue,
|
|
355
|
+
shouldUp,
|
|
356
|
+
hasLabel,
|
|
357
|
+
computedPlaceholder,
|
|
358
|
+
isPasswordType,
|
|
359
|
+
inputType,
|
|
360
|
+
input,
|
|
361
|
+
isFocused,
|
|
362
|
+
hasPasswordVisible,
|
|
363
|
+
borderStyle,
|
|
364
|
+
focus,
|
|
365
|
+
blur,
|
|
366
|
+
change,
|
|
367
|
+
emitValue,
|
|
368
|
+
hasRightPart,
|
|
369
|
+
hasLeftPart,
|
|
370
|
+
instanceId
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
const MazInput_vue_vue_type_style_index_0_scoped_52aef9c7_lang = "";
|
|
375
|
+
const _export_sfc = (sfc, props) => {
|
|
376
|
+
const target = sfc.__vccOpts || sfc;
|
|
377
|
+
for (const [key, val] of props) {
|
|
378
|
+
target[key] = val;
|
|
379
|
+
}
|
|
380
|
+
return target;
|
|
381
|
+
};
|
|
382
|
+
const _hoisted_1$2 = {
|
|
383
|
+
key: 0,
|
|
384
|
+
class: "m-input-wrapper-left"
|
|
385
|
+
};
|
|
386
|
+
const _hoisted_2$2 = { class: "m-input-wrapper-input" };
|
|
387
|
+
const _hoisted_3$1 = ["id", "type", "name", "placeholder", "aria-label", "disabled", "readonly", "required"];
|
|
388
|
+
const _hoisted_4$1 = ["for"];
|
|
389
|
+
const _hoisted_5$1 = { key: 0 };
|
|
390
|
+
const _hoisted_6 = {
|
|
391
|
+
key: 1,
|
|
392
|
+
class: "m-input-wrapper-right"
|
|
393
|
+
};
|
|
394
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
395
|
+
const _component_MazIcon = resolveComponent("MazIcon");
|
|
396
|
+
const _component_EyeOffIcon = resolveComponent("EyeOffIcon");
|
|
397
|
+
const _component_EyeIcon = resolveComponent("EyeIcon");
|
|
398
|
+
const _component_MazBtn = resolveComponent("MazBtn");
|
|
399
|
+
const _component_CheckIcon = resolveComponent("CheckIcon");
|
|
400
|
+
return openBlock(), createElementBlock(
|
|
401
|
+
"div",
|
|
402
|
+
{
|
|
403
|
+
class: normalizeClass(["m-input", [
|
|
404
|
+
{
|
|
405
|
+
"--is-focused": _ctx.isFocused || _ctx.borderActive,
|
|
406
|
+
"--should-up": _ctx.shouldUp,
|
|
407
|
+
"--has-label": _ctx.hasLabel,
|
|
408
|
+
"--is-disabled": _ctx.disabled,
|
|
409
|
+
"--is-readonly": _ctx.readonly,
|
|
410
|
+
"--has-z-2": _ctx.error || _ctx.warning || _ctx.success,
|
|
411
|
+
"--has-state": _ctx.error || _ctx.warning || _ctx.success
|
|
412
|
+
},
|
|
413
|
+
_ctx.$attrs.class,
|
|
414
|
+
`--${_ctx.color}`,
|
|
415
|
+
`--${_ctx.size}`
|
|
416
|
+
]]),
|
|
417
|
+
onClick: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("click", $event))
|
|
418
|
+
},
|
|
419
|
+
[
|
|
420
|
+
createElementVNode(
|
|
421
|
+
"div",
|
|
422
|
+
{
|
|
423
|
+
class: normalizeClass(["m-input-wrapper", [_ctx.inputClasses, _ctx.borderStyle, { "maz-rounded": !_ctx.noRadius }]])
|
|
424
|
+
},
|
|
425
|
+
[
|
|
426
|
+
_ctx.hasLeftPart() ? (openBlock(), createElementBlock("div", _hoisted_1$2, [
|
|
427
|
+
_ctx.$slots["left-icon"] || _ctx.leftIcon ? renderSlot(_ctx.$slots, "left-icon", { key: 0 }, () => [
|
|
428
|
+
createVNode(_component_MazIcon, {
|
|
429
|
+
name: _ctx.leftIcon,
|
|
430
|
+
class: "maz-text-xl maz-text-muted"
|
|
431
|
+
}, null, 8, ["name"])
|
|
432
|
+
], true) : createCommentVNode("v-if", true)
|
|
433
|
+
])) : createCommentVNode("v-if", true),
|
|
434
|
+
createElementVNode("div", _hoisted_2$2, [
|
|
435
|
+
withDirectives(createElementVNode("input", mergeProps({
|
|
436
|
+
id: _ctx.instanceId,
|
|
437
|
+
ref: "input",
|
|
438
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.inputValue = $event),
|
|
439
|
+
type: _ctx.inputType,
|
|
440
|
+
name: _ctx.name
|
|
441
|
+
}, _ctx.$attrs, {
|
|
442
|
+
placeholder: _ctx.computedPlaceholder,
|
|
443
|
+
"aria-label": _ctx.label || _ctx.placeholder,
|
|
444
|
+
disabled: _ctx.disabled,
|
|
445
|
+
readonly: _ctx.readonly,
|
|
446
|
+
required: _ctx.required,
|
|
447
|
+
class: "m-input-input"
|
|
448
|
+
}, toHandlers({
|
|
449
|
+
blur: _ctx.blur,
|
|
450
|
+
focus: _ctx.focus,
|
|
451
|
+
change: _ctx.change
|
|
452
|
+
}, true)), null, 16, _hoisted_3$1), [
|
|
453
|
+
[vModelDynamic, _ctx.inputValue]
|
|
454
|
+
]),
|
|
455
|
+
_ctx.label || _ctx.hint ? (openBlock(), createElementBlock("label", {
|
|
456
|
+
key: 0,
|
|
457
|
+
ref: "label",
|
|
458
|
+
for: _ctx.instanceId,
|
|
459
|
+
class: normalizeClass(["m-input-label", [
|
|
460
|
+
{
|
|
461
|
+
"maz-text-danger-600": _ctx.error,
|
|
462
|
+
"maz-text-success-600": _ctx.success,
|
|
463
|
+
"maz-text-warning-600": _ctx.warning
|
|
464
|
+
}
|
|
465
|
+
]])
|
|
466
|
+
}, [
|
|
467
|
+
createTextVNode(
|
|
468
|
+
toDisplayString(_ctx.hint || _ctx.label) + " ",
|
|
469
|
+
1
|
|
470
|
+
/* TEXT */
|
|
471
|
+
),
|
|
472
|
+
_ctx.required ? (openBlock(), createElementBlock("sup", _hoisted_5$1, "*")) : createCommentVNode("v-if", true)
|
|
473
|
+
], 10, _hoisted_4$1)) : createCommentVNode("v-if", true)
|
|
474
|
+
]),
|
|
475
|
+
_ctx.hasRightPart() ? (openBlock(), createElementBlock("div", _hoisted_6, [
|
|
476
|
+
_ctx.$slots["right-icon"] || _ctx.rightIcon ? renderSlot(_ctx.$slots, "right-icon", { key: 0 }, () => [
|
|
477
|
+
createVNode(_component_MazIcon, {
|
|
478
|
+
name: _ctx.rightIcon,
|
|
479
|
+
class: "maz-text-xl maz-text-muted"
|
|
480
|
+
}, null, 8, ["name"])
|
|
481
|
+
], true) : createCommentVNode("v-if", true),
|
|
482
|
+
_ctx.isPasswordType ? (openBlock(), createBlock(_component_MazBtn, {
|
|
483
|
+
key: 1,
|
|
484
|
+
color: "transparent",
|
|
485
|
+
tabindex: "-1",
|
|
486
|
+
size: "mini",
|
|
487
|
+
onClick: _cache[1] || (_cache[1] = withModifiers(($event) => _ctx.hasPasswordVisible = !_ctx.hasPasswordVisible, ["stop"]))
|
|
488
|
+
}, {
|
|
489
|
+
default: withCtx(() => [
|
|
490
|
+
_ctx.hasPasswordVisible ? (openBlock(), createBlock(_component_EyeOffIcon, {
|
|
491
|
+
key: 0,
|
|
492
|
+
class: "maz-text-xl maz-text-muted"
|
|
493
|
+
})) : (openBlock(), createBlock(_component_EyeIcon, {
|
|
494
|
+
key: 1,
|
|
495
|
+
class: "maz-text-xl maz-text-muted"
|
|
496
|
+
}))
|
|
497
|
+
]),
|
|
498
|
+
_: 1
|
|
499
|
+
/* STABLE */
|
|
500
|
+
})) : createCommentVNode("v-if", true),
|
|
501
|
+
_ctx.$slots["valid-button"] || _ctx.validButton ? renderSlot(_ctx.$slots, "valid-button", { key: 2 }, () => [
|
|
502
|
+
createVNode(_component_MazBtn, {
|
|
503
|
+
color: "transparent",
|
|
504
|
+
disabled: _ctx.disabled,
|
|
505
|
+
tabindex: "-1",
|
|
506
|
+
loading: _ctx.validButtonLoading,
|
|
507
|
+
class: "m-input-valid-button",
|
|
508
|
+
size: "mini",
|
|
509
|
+
type: "submit"
|
|
510
|
+
}, {
|
|
511
|
+
default: withCtx(() => [
|
|
512
|
+
createVNode(_component_CheckIcon, { class: "maz-text-2xl maz-text-normal" })
|
|
513
|
+
]),
|
|
514
|
+
_: 1
|
|
515
|
+
/* STABLE */
|
|
516
|
+
}, 8, ["disabled", "loading"])
|
|
517
|
+
], true) : createCommentVNode("v-if", true)
|
|
518
|
+
])) : createCommentVNode("v-if", true)
|
|
519
|
+
],
|
|
520
|
+
2
|
|
521
|
+
/* CLASS */
|
|
522
|
+
)
|
|
523
|
+
],
|
|
524
|
+
2
|
|
525
|
+
/* CLASS */
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
const MazInput = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render], ["__scopeId", "data-v-52aef9c7"]]);
|
|
529
|
+
ref("system");
|
|
530
|
+
ref();
|
|
531
|
+
ref([]);
|
|
532
|
+
let timeout = null;
|
|
533
|
+
function debounceCallback(callback, delay) {
|
|
534
|
+
if (timeout) {
|
|
535
|
+
clearTimeout(timeout);
|
|
536
|
+
}
|
|
537
|
+
timeout = setTimeout(callback, delay);
|
|
538
|
+
}
|
|
539
|
+
const _hoisted_1$1 = ["onClick"];
|
|
540
|
+
const _hoisted_2$1 = {
|
|
541
|
+
key: 0,
|
|
542
|
+
tabindex: "-1",
|
|
543
|
+
class: "m-select-list__search-wrapper"
|
|
544
|
+
};
|
|
545
|
+
const _hoisted_3 = { class: "m-select-list__no-results" };
|
|
546
|
+
const _hoisted_4 = {
|
|
547
|
+
key: 2,
|
|
548
|
+
class: "m-select-list__scroll-wrapper",
|
|
549
|
+
tabindex: "-1"
|
|
550
|
+
};
|
|
551
|
+
const _hoisted_5 = ["onClick"];
|
|
552
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
553
|
+
__name: "MazSelect",
|
|
554
|
+
props: {
|
|
555
|
+
modelValue: {
|
|
556
|
+
type: [Number, String, Boolean],
|
|
557
|
+
default: void 0
|
|
558
|
+
},
|
|
559
|
+
id: { type: String, default: void 0 },
|
|
560
|
+
options: { type: Array, default: void 0 },
|
|
561
|
+
optionValueKey: { type: String, default: "value" },
|
|
562
|
+
optionLabelKey: { type: String, default: "label" },
|
|
563
|
+
optionInputValueKey: { type: String, default: "label" },
|
|
564
|
+
listPosition: {
|
|
565
|
+
type: String,
|
|
566
|
+
default: "bottom left",
|
|
567
|
+
validator: (value) => {
|
|
568
|
+
return ["top", "top right", "top left", "bottom", "bottom right", "bottom left"].includes(
|
|
569
|
+
value
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
required: { type: Boolean, default: false },
|
|
574
|
+
disabled: { type: Boolean, default: false },
|
|
575
|
+
open: { type: Boolean, default: false },
|
|
576
|
+
color: {
|
|
577
|
+
type: String,
|
|
578
|
+
default: "primary"
|
|
579
|
+
},
|
|
580
|
+
itemHeight: { type: Number, default: 40 },
|
|
581
|
+
maxListHeight: { type: Number, default: 240 },
|
|
582
|
+
maxListWidth: { type: Number, default: void 0 },
|
|
583
|
+
size: {
|
|
584
|
+
type: String,
|
|
585
|
+
default: "md",
|
|
586
|
+
validator: (value) => {
|
|
587
|
+
return ["mini", "xs", "sm", "md", "lg", "xl"].includes(value);
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
search: { type: Boolean, default: false },
|
|
591
|
+
searchPlaceholder: { type: String, default: "Search in options" }
|
|
592
|
+
},
|
|
593
|
+
emits: [
|
|
594
|
+
"close",
|
|
595
|
+
"open",
|
|
596
|
+
"blur",
|
|
597
|
+
"focus",
|
|
598
|
+
"change",
|
|
599
|
+
"update:model-value",
|
|
600
|
+
/** On selected value, returns the option object */
|
|
601
|
+
"selected-option"
|
|
602
|
+
],
|
|
603
|
+
setup(__props, { emit: __emit }) {
|
|
604
|
+
const SearchIcon = defineAsyncComponent(() => import("./magnifying-glass-6a0dd1a2.mjs"));
|
|
605
|
+
const ChevronDownIcon = defineAsyncComponent(() => import("./chevron-down-7a070b10.mjs"));
|
|
606
|
+
const NoSymbolIcon = defineAsyncComponent(() => import("./no-symbol-6173a20b.mjs"));
|
|
607
|
+
const instance = getCurrentInstance();
|
|
608
|
+
const props = __props;
|
|
609
|
+
const emits = __emit;
|
|
610
|
+
const listOpened = ref(false);
|
|
611
|
+
const tmpModelValueIndex = ref();
|
|
612
|
+
const hasListOpened = computed(() => listOpened.value || props.open);
|
|
613
|
+
const instanceId = useInstanceUniqId({
|
|
614
|
+
componentName: "MazSelect",
|
|
615
|
+
instance,
|
|
616
|
+
providedId: props.id
|
|
617
|
+
});
|
|
618
|
+
onBeforeMount(() => {
|
|
619
|
+
var _a, _b;
|
|
620
|
+
if (!((_a = props.options) == null ? void 0 : _a.length)) {
|
|
621
|
+
console.warn("[maz-ui](MazSelect) you must provide options");
|
|
622
|
+
}
|
|
623
|
+
if (selectedOption.value) {
|
|
624
|
+
tmpModelValueIndex.value = (_b = props.options) == null ? void 0 : _b.findIndex(
|
|
625
|
+
(option) => {
|
|
626
|
+
var _a2;
|
|
627
|
+
return option[props.optionValueKey] === ((_a2 = selectedOption.value) == null ? void 0 : _a2[props.optionValueKey]);
|
|
628
|
+
}
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
const mazSelectElement = ref();
|
|
633
|
+
const mazInputComponent = ref();
|
|
634
|
+
const searchInputComponent = ref();
|
|
635
|
+
const optionsListElement = ref();
|
|
636
|
+
const selectedOption = computed(
|
|
637
|
+
() => {
|
|
638
|
+
var _a;
|
|
639
|
+
return (_a = props.options) == null ? void 0 : _a.find((option) => props.modelValue === option[props.optionValueKey]);
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
const isNullOrUndefined = (value) => {
|
|
643
|
+
return value === void 0 || value === null;
|
|
644
|
+
};
|
|
645
|
+
const mazInputValue = computed(() => {
|
|
646
|
+
var _a, _b, _c;
|
|
647
|
+
return isNullOrUndefined((_a = selectedOption.value) == null ? void 0 : _a[props.optionValueKey]) ? void 0 : ((_b = selectedOption.value) == null ? void 0 : _b[props.optionInputValueKey]) ?? ((_c = selectedOption.value) == null ? void 0 : _c[props.optionLabelKey]);
|
|
648
|
+
});
|
|
649
|
+
const listTransition = computed(
|
|
650
|
+
() => props.listPosition.includes("bottom") ? "maz-slide" : "maz-slideinvert"
|
|
651
|
+
);
|
|
652
|
+
const searchQuery = ref("");
|
|
653
|
+
const query = ref("");
|
|
654
|
+
function normalizeString(str) {
|
|
655
|
+
return str.normalize("NFD").replaceAll(/[\u0300-\u036F]/g, "").replaceAll(/[^\dA-Za-z]/g, "");
|
|
656
|
+
}
|
|
657
|
+
const searchInValue = (value, query2) => {
|
|
658
|
+
return query2 && value && normalizeString(value.toString().toLocaleLowerCase().trim()).includes(
|
|
659
|
+
normalizeString(query2.toLocaleLowerCase().trim())
|
|
660
|
+
);
|
|
661
|
+
};
|
|
662
|
+
watch(
|
|
663
|
+
() => props.modelValue,
|
|
664
|
+
(value, oldValue) => {
|
|
665
|
+
if (value && value !== oldValue) {
|
|
666
|
+
scrollToSelected();
|
|
667
|
+
updateTmpModelValueIndex();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
function getFilteredOptionWithQuery(query2) {
|
|
672
|
+
var _a;
|
|
673
|
+
return query2 ? (_a = props.options) == null ? void 0 : _a.filter((option) => {
|
|
674
|
+
const searchValue = option[props.optionLabelKey];
|
|
675
|
+
const searchValue3 = option[props.optionValueKey];
|
|
676
|
+
const searchValue2 = option[props.optionInputValueKey];
|
|
677
|
+
return searchInValue(searchValue, query2) || searchInValue(searchValue3, query2) || searchInValue(searchValue2, query2);
|
|
678
|
+
}) : props.options;
|
|
679
|
+
}
|
|
680
|
+
const optionsList = computed(() => getFilteredOptionWithQuery(searchQuery.value));
|
|
681
|
+
const closeList = async (event) => {
|
|
682
|
+
var _a;
|
|
683
|
+
if (event && ("relatedTarget" in event && ((_a = mazSelectElement.value) == null ? void 0 : _a.contains(event.relatedTarget)) || event.type === "keydown")) {
|
|
684
|
+
return event.preventDefault();
|
|
685
|
+
}
|
|
686
|
+
await nextTick();
|
|
687
|
+
listOpened.value = false;
|
|
688
|
+
tmpModelValueIndex.value = 0;
|
|
689
|
+
emits("close", event);
|
|
690
|
+
};
|
|
691
|
+
const openList = async (event) => {
|
|
692
|
+
event == null ? void 0 : event.preventDefault();
|
|
693
|
+
if (props.disabled)
|
|
694
|
+
return;
|
|
695
|
+
listOpened.value = true;
|
|
696
|
+
await scrollToSelected();
|
|
697
|
+
emits("focus", event);
|
|
698
|
+
emits("open", listOpened.value);
|
|
699
|
+
};
|
|
700
|
+
function toggleList(event) {
|
|
701
|
+
var _a, _b;
|
|
702
|
+
return listOpened.value ? closeList(event) : ((_b = (_a = mazInputComponent.value) == null ? void 0 : _a.$el.querySelector("input")) == null ? void 0 : _b.focus()) ?? openList();
|
|
703
|
+
}
|
|
704
|
+
function focusSearchInputAndSetQuery(q) {
|
|
705
|
+
var _a;
|
|
706
|
+
searchQuery.value = q;
|
|
707
|
+
(_a = searchInputComponent.value) == null ? void 0 : _a.input.focus();
|
|
708
|
+
}
|
|
709
|
+
function searchOptionWithQuery(keyPressed) {
|
|
710
|
+
var _a;
|
|
711
|
+
if (keyPressed === "Backspace" && query.value.length > 0) {
|
|
712
|
+
query.value = query.value.slice(0, -1);
|
|
713
|
+
} else {
|
|
714
|
+
query.value += keyPressed;
|
|
715
|
+
}
|
|
716
|
+
const filteredOptions = getFilteredOptionWithQuery(query.value);
|
|
717
|
+
if (filteredOptions == null ? void 0 : filteredOptions.length) {
|
|
718
|
+
tmpModelValueIndex.value = (_a = optionsList.value) == null ? void 0 : _a.findIndex(
|
|
719
|
+
(option) => option[props.optionValueKey] === filteredOptions[0][props.optionValueKey]
|
|
720
|
+
);
|
|
721
|
+
scrollToSelected(tmpModelValueIndex.value);
|
|
722
|
+
}
|
|
723
|
+
debounceCallback(() => {
|
|
724
|
+
query.value = "";
|
|
725
|
+
}, 1e3);
|
|
726
|
+
}
|
|
727
|
+
const mainInputKeyboardHandler = (event) => {
|
|
728
|
+
const keyPressed = event.key;
|
|
729
|
+
if (/^[\dA-Za-z]$/.test(keyPressed)) {
|
|
730
|
+
event.preventDefault();
|
|
731
|
+
openList(event);
|
|
732
|
+
props.search ? focusSearchInputAndSetQuery(keyPressed) : searchOptionWithQuery(keyPressed);
|
|
733
|
+
} else {
|
|
734
|
+
keyboardHandler(event);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
const keyboardHandler = (event) => {
|
|
738
|
+
const code = event.code;
|
|
739
|
+
const isArrow = ["ArrowUp", "ArrowDown"].includes(code);
|
|
740
|
+
const isEnter = "Enter" === code;
|
|
741
|
+
const isEscape = "Escape" === code && hasListOpened.value;
|
|
742
|
+
if (isArrow) {
|
|
743
|
+
arrowHandler(event, tmpModelValueIndex.value);
|
|
744
|
+
} else if (isEnter) {
|
|
745
|
+
enterHandler(event, tmpModelValueIndex.value);
|
|
746
|
+
} else if (isEscape) {
|
|
747
|
+
closeList();
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
const arrowHandler = (event, currentIndex) => {
|
|
751
|
+
var _a;
|
|
752
|
+
event.preventDefault();
|
|
753
|
+
const code = event.code;
|
|
754
|
+
if (!hasListOpened.value)
|
|
755
|
+
openList(event);
|
|
756
|
+
const optionsLength = (_a = optionsList.value) == null ? void 0 : _a.length;
|
|
757
|
+
if (!optionsLength) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (typeof currentIndex === "number") {
|
|
761
|
+
if (currentIndex === optionsLength - 1 && code === "ArrowDown") {
|
|
762
|
+
tmpModelValueIndex.value = 0;
|
|
763
|
+
} else if (currentIndex === 0 && code === "ArrowUp") {
|
|
764
|
+
tmpModelValueIndex.value = optionsLength - 1;
|
|
765
|
+
} else {
|
|
766
|
+
tmpModelValueIndex.value = code === "ArrowDown" ? currentIndex + 1 : currentIndex - 1;
|
|
767
|
+
}
|
|
768
|
+
} else {
|
|
769
|
+
tmpModelValueIndex.value = code === "ArrowDown" ? 0 : optionsLength - 1;
|
|
770
|
+
}
|
|
771
|
+
scrollToSelected(tmpModelValueIndex.value);
|
|
772
|
+
};
|
|
773
|
+
const enterHandler = (event, currentIndex) => {
|
|
774
|
+
var _a, _b, _c;
|
|
775
|
+
event.preventDefault();
|
|
776
|
+
if (!hasListOpened.value) {
|
|
777
|
+
return openList(event);
|
|
778
|
+
}
|
|
779
|
+
const newValue = currentIndex ? ((_a = optionsList.value) == null ? void 0 : _a[currentIndex]) ?? ((_b = optionsList.value) == null ? void 0 : _b[0]) : (_c = optionsList.value) == null ? void 0 : _c[0];
|
|
780
|
+
if (!isNullOrUndefined(newValue)) {
|
|
781
|
+
updateValue(newValue);
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
async function scrollToSelected(index) {
|
|
785
|
+
var _a, _b, _c;
|
|
786
|
+
await nextTick();
|
|
787
|
+
const selectedIndex = index ?? ((_a = optionsList.value) == null ? void 0 : _a.findIndex(
|
|
788
|
+
(option) => {
|
|
789
|
+
var _a2;
|
|
790
|
+
return ((_a2 = selectedOption.value) == null ? void 0 : _a2[props.optionValueKey]) === option[props.optionValueKey];
|
|
791
|
+
}
|
|
792
|
+
));
|
|
793
|
+
if (typeof selectedIndex === "number") {
|
|
794
|
+
if (!tmpModelValueIndex.value)
|
|
795
|
+
tmpModelValueIndex.value = selectedIndex;
|
|
796
|
+
(_c = (_b = optionsListElement.value) == null ? void 0 : _b.querySelectorAll(".m-select-list-item")[selectedIndex]) == null ? void 0 : _c.scrollIntoView({
|
|
797
|
+
behavior: "auto",
|
|
798
|
+
block: "nearest",
|
|
799
|
+
inline: "start"
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function updateTmpModelValueIndex() {
|
|
804
|
+
var _a;
|
|
805
|
+
const index = (_a = optionsList.value) == null ? void 0 : _a.findIndex(
|
|
806
|
+
(option) => selectedOption[props.optionValueKey] === option[props.optionValueKey]
|
|
807
|
+
);
|
|
808
|
+
tmpModelValueIndex.value = index && index >= 0 ? index : void 0;
|
|
809
|
+
}
|
|
810
|
+
const updateValue = (selectedOption2, mustCloseList = true) => {
|
|
811
|
+
if (mustCloseList) {
|
|
812
|
+
nextTick(() => closeList());
|
|
813
|
+
}
|
|
814
|
+
searchQuery.value = "";
|
|
815
|
+
emits("update:model-value", selectedOption2[props.optionValueKey]);
|
|
816
|
+
emits("selected-option", selectedOption2);
|
|
817
|
+
updateTmpModelValueIndex();
|
|
818
|
+
};
|
|
819
|
+
return (_ctx, _cache) => {
|
|
820
|
+
return openBlock(), createElementBlock(
|
|
821
|
+
"div",
|
|
822
|
+
{
|
|
823
|
+
ref_key: "mazSelectElement",
|
|
824
|
+
ref: mazSelectElement,
|
|
825
|
+
class: normalizeClass(["m-select", { "--is-open": hasListOpened.value, "--disabled": __props.disabled }]),
|
|
826
|
+
onBlurCapture: closeList
|
|
827
|
+
},
|
|
828
|
+
[
|
|
829
|
+
createVNode(MazInput, mergeProps({
|
|
830
|
+
id: unref(instanceId),
|
|
831
|
+
ref_key: "mazInputComponent",
|
|
832
|
+
ref: mazInputComponent,
|
|
833
|
+
class: "m-select-input"
|
|
834
|
+
}, _ctx.$attrs, {
|
|
835
|
+
required: __props.required,
|
|
836
|
+
"border-active": listOpened.value,
|
|
837
|
+
color: __props.color,
|
|
838
|
+
"model-value": mazInputValue.value,
|
|
839
|
+
autocomplete: "off",
|
|
840
|
+
size: __props.size,
|
|
841
|
+
disabled: __props.disabled,
|
|
842
|
+
onFocus: withModifiers(openList, ["prevent", "stop"]),
|
|
843
|
+
onChange: _cache[0] || (_cache[0] = ($event) => emits("change", $event)),
|
|
844
|
+
onKeydown: mainInputKeyboardHandler
|
|
845
|
+
}), {
|
|
846
|
+
"right-icon": withCtx(() => [
|
|
847
|
+
createElementVNode("button", {
|
|
848
|
+
tabindex: "-1",
|
|
849
|
+
type: "button",
|
|
850
|
+
class: "m-select-input__toggle-button maz-custom",
|
|
851
|
+
onClick: withModifiers(toggleList, ["stop"])
|
|
852
|
+
}, [
|
|
853
|
+
createVNode(unref(ChevronDownIcon), { class: "m-select-chevron maz-text-xl" })
|
|
854
|
+
], 8, _hoisted_1$1)
|
|
855
|
+
]),
|
|
856
|
+
_: 1
|
|
857
|
+
/* STABLE */
|
|
858
|
+
}, 16, ["id", "required", "border-active", "color", "model-value", "size", "disabled", "onFocus"]),
|
|
859
|
+
createVNode(Transition, { name: listTransition.value }, {
|
|
860
|
+
default: withCtx(() => [
|
|
861
|
+
hasListOpened.value ? (openBlock(), createElementBlock(
|
|
862
|
+
"div",
|
|
863
|
+
{
|
|
864
|
+
key: 0,
|
|
865
|
+
ref_key: "optionsListElement",
|
|
866
|
+
ref: optionsListElement,
|
|
867
|
+
class: normalizeClass(["m-select-list", {
|
|
868
|
+
"--top": __props.listPosition.includes("top"),
|
|
869
|
+
"--left": __props.listPosition.includes("left"),
|
|
870
|
+
"--right": __props.listPosition.includes("right"),
|
|
871
|
+
"--bottom": __props.listPosition.includes("bottom")
|
|
872
|
+
}]),
|
|
873
|
+
style: normalizeStyle({
|
|
874
|
+
maxHeight: `${__props.maxListHeight}px`,
|
|
875
|
+
maxWidth: `${__props.maxListWidth}px`
|
|
876
|
+
})
|
|
877
|
+
},
|
|
878
|
+
[
|
|
879
|
+
__props.search ? (openBlock(), createElementBlock("div", _hoisted_2$1, [
|
|
880
|
+
createVNode(MazInput, {
|
|
881
|
+
ref_key: "searchInputComponent",
|
|
882
|
+
ref: searchInputComponent,
|
|
883
|
+
modelValue: searchQuery.value,
|
|
884
|
+
"onUpdate:modelValue": [
|
|
885
|
+
_cache[1] || (_cache[1] = ($event) => searchQuery.value = $event),
|
|
886
|
+
_cache[2] || (_cache[2] = ($event) => tmpModelValueIndex.value = 0)
|
|
887
|
+
],
|
|
888
|
+
size: "sm",
|
|
889
|
+
color: __props.color,
|
|
890
|
+
placeholder: __props.searchPlaceholder,
|
|
891
|
+
name: "search",
|
|
892
|
+
autocomplete: "off",
|
|
893
|
+
tabindex: "-1",
|
|
894
|
+
class: "m-select-list__search-input",
|
|
895
|
+
onKeydown: keyboardHandler
|
|
896
|
+
}, {
|
|
897
|
+
"left-icon": withCtx(() => [
|
|
898
|
+
createVNode(unref(SearchIcon), { class: "maz-h-[1.3rem] maz-w-[1.3rem]" })
|
|
899
|
+
]),
|
|
900
|
+
_: 1
|
|
901
|
+
/* STABLE */
|
|
902
|
+
}, 8, ["modelValue", "color", "placeholder"])
|
|
903
|
+
])) : createCommentVNode("v-if", true),
|
|
904
|
+
createCommentVNode(" No results slot - Displayed when no results corresponding with seeach query "),
|
|
905
|
+
!optionsList.value || optionsList.value.length <= 0 ? renderSlot(_ctx.$slots, "no-results", { key: 1 }, () => [
|
|
906
|
+
createElementVNode("span", _hoisted_3, [
|
|
907
|
+
createVNode(unref(NoSymbolIcon), { class: "maz-h-6 maz-w-6 maz-text-normal" })
|
|
908
|
+
])
|
|
909
|
+
], true) : (openBlock(), createElementBlock("div", _hoisted_4, [
|
|
910
|
+
(openBlock(true), createElementBlock(
|
|
911
|
+
Fragment,
|
|
912
|
+
null,
|
|
913
|
+
renderList(optionsList.value, (option, i) => {
|
|
914
|
+
var _a, _b, _c;
|
|
915
|
+
return openBlock(), createElementBlock("button", {
|
|
916
|
+
key: i,
|
|
917
|
+
tabindex: "-1",
|
|
918
|
+
type: "button",
|
|
919
|
+
class: normalizeClass(["m-select-list-item maz-custom", [
|
|
920
|
+
{
|
|
921
|
+
"--is-keyboard-selected": tmpModelValueIndex.value === i,
|
|
922
|
+
"--is-selected": ((_a = selectedOption.value) == null ? void 0 : _a[__props.optionValueKey]) === option[__props.optionValueKey] && !isNullOrUndefined(option[__props.optionValueKey]),
|
|
923
|
+
"--is-none-value": isNullOrUndefined(option[__props.optionValueKey])
|
|
924
|
+
},
|
|
925
|
+
`--${__props.color}`
|
|
926
|
+
]]),
|
|
927
|
+
style: normalizeStyle({ minHeight: `${__props.itemHeight}px` }),
|
|
928
|
+
onClick: withModifiers(($event) => updateValue(option), ["prevent", "stop"])
|
|
929
|
+
}, [
|
|
930
|
+
renderSlot(_ctx.$slots, "default", {
|
|
931
|
+
option,
|
|
932
|
+
isSelected: ((_b = selectedOption.value) == null ? void 0 : _b[__props.optionValueKey]) === option[__props.optionValueKey],
|
|
933
|
+
selectedOption: (_c = selectedOption.value) == null ? void 0 : _c[__props.optionValueKey]
|
|
934
|
+
}, () => [
|
|
935
|
+
createElementVNode(
|
|
936
|
+
"span",
|
|
937
|
+
null,
|
|
938
|
+
toDisplayString(option[__props.optionLabelKey]),
|
|
939
|
+
1
|
|
940
|
+
/* TEXT */
|
|
941
|
+
)
|
|
942
|
+
], true)
|
|
943
|
+
], 14, _hoisted_5);
|
|
944
|
+
}),
|
|
945
|
+
128
|
|
946
|
+
/* KEYED_FRAGMENT */
|
|
947
|
+
))
|
|
948
|
+
]))
|
|
949
|
+
],
|
|
950
|
+
6
|
|
951
|
+
/* CLASS, STYLE */
|
|
952
|
+
)) : createCommentVNode("v-if", true)
|
|
953
|
+
]),
|
|
954
|
+
_: 3
|
|
955
|
+
/* FORWARDED */
|
|
956
|
+
}, 8, ["name"])
|
|
957
|
+
],
|
|
958
|
+
34
|
|
959
|
+
/* CLASS, HYDRATE_EVENTS */
|
|
960
|
+
);
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
const MazSelect_vue_vue_type_style_index_0_scoped_2589528b_lang = "";
|
|
965
|
+
const MazSelect = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-2589528b"]]);
|
|
966
|
+
const _hoisted_1 = ["id"];
|
|
967
|
+
const _hoisted_2 = {
|
|
968
|
+
key: 0,
|
|
969
|
+
class: "maz-mr-2 maz-text-lg"
|
|
970
|
+
};
|
|
971
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
972
|
+
__name: "MazPhoneNumberInput",
|
|
973
|
+
props: {
|
|
974
|
+
modelValue: {
|
|
975
|
+
type: String,
|
|
976
|
+
validator: (prop) => {
|
|
977
|
+
return typeof prop === "string" || prop === void 0;
|
|
978
|
+
},
|
|
979
|
+
default: void 0
|
|
980
|
+
},
|
|
981
|
+
/** @deprecated */
|
|
982
|
+
defaultPhoneNumber: { type: String, default: void 0 },
|
|
983
|
+
countryCode: {
|
|
984
|
+
type: String,
|
|
985
|
+
default: void 0,
|
|
986
|
+
validator: (code) => isCountryAvailable(code)
|
|
987
|
+
},
|
|
988
|
+
/** @deprecated - use country-code or v-model:country-code */
|
|
989
|
+
defaultCountryCode: {
|
|
990
|
+
type: String,
|
|
991
|
+
default: void 0,
|
|
992
|
+
validator: (code) => isCountryAvailable(code)
|
|
993
|
+
},
|
|
994
|
+
id: { type: String, default: void 0 },
|
|
995
|
+
placeholder: { type: String, default: void 0 },
|
|
996
|
+
preferredCountries: { type: Array, default: void 0 },
|
|
997
|
+
ignoredCountries: { type: Array, default: void 0 },
|
|
998
|
+
onlyCountries: { type: Array, default: void 0 },
|
|
999
|
+
translations: { type: Object, default: void 0 },
|
|
1000
|
+
listPosition: {
|
|
1001
|
+
type: String,
|
|
1002
|
+
default: "bottom left",
|
|
1003
|
+
validator: (value) => {
|
|
1004
|
+
return ["top", "top right", "top left", "bottom", "bottom right", "bottom left"].includes(
|
|
1005
|
+
value
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
color: { type: String, default: "primary" },
|
|
1010
|
+
size: {
|
|
1011
|
+
type: String,
|
|
1012
|
+
default: "md",
|
|
1013
|
+
validator: (value) => {
|
|
1014
|
+
return ["mini", "xs", "sm", "md", "lg", "xl"].includes(value);
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
noFlags: { type: Boolean, default: false },
|
|
1018
|
+
disabled: { type: Boolean, default: false },
|
|
1019
|
+
noExample: { type: Boolean, default: false },
|
|
1020
|
+
noSearch: { type: Boolean, default: false },
|
|
1021
|
+
noUseBrowserLocale: { type: Boolean, default: false },
|
|
1022
|
+
fetchCountry: { type: Boolean, default: false },
|
|
1023
|
+
noCountrySelector: { type: Boolean, default: false },
|
|
1024
|
+
showCodeOnList: { type: Boolean, default: false },
|
|
1025
|
+
error: { type: Boolean, default: false },
|
|
1026
|
+
customCountriesList: {
|
|
1027
|
+
type: Object,
|
|
1028
|
+
default: void 0
|
|
1029
|
+
},
|
|
1030
|
+
/**
|
|
1031
|
+
* Disabled auto-format as you type
|
|
1032
|
+
*/
|
|
1033
|
+
noFormattingAsYouType: { type: Boolean, default: false },
|
|
1034
|
+
/**
|
|
1035
|
+
* locale of country list - Ex: "fr-FR"
|
|
1036
|
+
* @default browser locale
|
|
1037
|
+
*/
|
|
1038
|
+
countryLocale: { type: String, default: void 0 }
|
|
1039
|
+
},
|
|
1040
|
+
emits: [
|
|
1041
|
+
/** emitted when country or phone number changed
|
|
1042
|
+
* @returns data - {Result}
|
|
1043
|
+
*/
|
|
1044
|
+
"update",
|
|
1045
|
+
/** emitted when country or phone number changed
|
|
1046
|
+
* @returns data - {Result}
|
|
1047
|
+
*/
|
|
1048
|
+
"data",
|
|
1049
|
+
/** emitted when selected country changed */
|
|
1050
|
+
"country-code",
|
|
1051
|
+
/** Two way binding (v-model:model-value) - emitted when country changed */
|
|
1052
|
+
"update:model-value",
|
|
1053
|
+
/** Two way binding (v-model:country-code) - emitted when country changed */
|
|
1054
|
+
"update:country-code"
|
|
1055
|
+
],
|
|
1056
|
+
setup(__props, { emit: __emit }) {
|
|
1057
|
+
const {
|
|
1058
|
+
fetchCountryCode: fetchCountryCode2,
|
|
1059
|
+
browserLocale: browserLocale2,
|
|
1060
|
+
getResultsFromPhoneNumber: getResultsFromPhoneNumber2,
|
|
1061
|
+
getAsYouTypeFormat: getAsYouTypeFormat2,
|
|
1062
|
+
getCountriesList: getCountriesList2,
|
|
1063
|
+
getPhoneNumberExample: getPhoneNumberExample2,
|
|
1064
|
+
sanitizePhoneNumber: sanitizePhoneNumber2,
|
|
1065
|
+
loadPhoneNumberExamplesFile: loadPhoneNumberExamplesFile2
|
|
1066
|
+
} = useLibphonenumber();
|
|
1067
|
+
const emits = __emit;
|
|
1068
|
+
const props = __props;
|
|
1069
|
+
const instance = getCurrentInstance();
|
|
1070
|
+
const instanceId = useInstanceUniqId({
|
|
1071
|
+
componentName: "MazPhoneNumberInput",
|
|
1072
|
+
instance,
|
|
1073
|
+
providedId: props.id
|
|
1074
|
+
});
|
|
1075
|
+
const PhoneNumberInput = ref();
|
|
1076
|
+
const CountrySelector = ref();
|
|
1077
|
+
const selectionRange = reactive({
|
|
1078
|
+
start: 0,
|
|
1079
|
+
end: 0,
|
|
1080
|
+
cursorAtEnd: true
|
|
1081
|
+
});
|
|
1082
|
+
const examplesFileLoaded = ref(false);
|
|
1083
|
+
const inputFocused = ref(false);
|
|
1084
|
+
const countries = computed(() => getCountriesList2(props.countryLocale, props.customCountriesList));
|
|
1085
|
+
const countriesList = computed(() => {
|
|
1086
|
+
var _a;
|
|
1087
|
+
return (_a = countries.value) == null ? void 0 : _a.filter((item) => {
|
|
1088
|
+
var _a2;
|
|
1089
|
+
return !((_a2 = props.ignoredCountries) == null ? void 0 : _a2.includes(item.iso2));
|
|
1090
|
+
});
|
|
1091
|
+
});
|
|
1092
|
+
const countriesFiltered = computed(() => {
|
|
1093
|
+
const countries2 = props.onlyCountries || props.preferredCountries;
|
|
1094
|
+
return countries2 == null ? void 0 : countries2.map(
|
|
1095
|
+
(country) => {
|
|
1096
|
+
var _a;
|
|
1097
|
+
return (_a = countriesList.value) == null ? void 0 : _a.find((item) => item.iso2.includes(country));
|
|
1098
|
+
}
|
|
1099
|
+
);
|
|
1100
|
+
});
|
|
1101
|
+
const otherCountries = computed(() => {
|
|
1102
|
+
var _a;
|
|
1103
|
+
return (_a = countriesList.value) == null ? void 0 : _a.filter((item) => {
|
|
1104
|
+
var _a2;
|
|
1105
|
+
return !((_a2 = props.preferredCountries) == null ? void 0 : _a2.includes(item.iso2));
|
|
1106
|
+
});
|
|
1107
|
+
});
|
|
1108
|
+
const countriesSorted = computed(() => {
|
|
1109
|
+
return props.preferredCountries ? [...countriesFiltered.value ?? [], ...otherCountries.value ?? []] : props.onlyCountries ? countriesFiltered.value : countriesList.value;
|
|
1110
|
+
});
|
|
1111
|
+
const countryOptions = computed(() => {
|
|
1112
|
+
var _a;
|
|
1113
|
+
return (_a = countriesSorted.value) == null ? void 0 : _a.map((country) => {
|
|
1114
|
+
return country ? {
|
|
1115
|
+
...country,
|
|
1116
|
+
dialCode: `+${country.dialCode}`
|
|
1117
|
+
} : void 0;
|
|
1118
|
+
}).filter(truthyFilter);
|
|
1119
|
+
});
|
|
1120
|
+
const locales = computed(() => ({
|
|
1121
|
+
...defaultLocales,
|
|
1122
|
+
...props.translations
|
|
1123
|
+
}));
|
|
1124
|
+
const inputPlaceholder = computed(() => {
|
|
1125
|
+
if (props.placeholder) {
|
|
1126
|
+
return props.placeholder;
|
|
1127
|
+
}
|
|
1128
|
+
const defaultPlaceholder = locales.value.phoneInput.placeholder;
|
|
1129
|
+
if (props.noExample || !examplesFileLoaded.value) {
|
|
1130
|
+
return defaultPlaceholder;
|
|
1131
|
+
} else {
|
|
1132
|
+
const example = getPhoneNumberExample2(countryCode.value);
|
|
1133
|
+
return results.value.isValid || !example ? defaultPlaceholder : `${locales.value.phoneInput.example} ${example}`;
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
const model = computed({
|
|
1137
|
+
get: () => props.modelValue || props.defaultPhoneNumber,
|
|
1138
|
+
set: (value) => {
|
|
1139
|
+
emits("update:model-value", value);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
const internalCountryCode = ref();
|
|
1143
|
+
const countryCode = computed({
|
|
1144
|
+
get: () => props.countryCode || props.defaultCountryCode || internalCountryCode.value,
|
|
1145
|
+
set: (value) => {
|
|
1146
|
+
emits("country-code", value);
|
|
1147
|
+
emits("update:country-code", value);
|
|
1148
|
+
internalCountryCode.value = value;
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
const internalValue = ref(model.value);
|
|
1152
|
+
const results = ref(
|
|
1153
|
+
getResultsFromPhoneNumber2({
|
|
1154
|
+
phoneNumber: model.value,
|
|
1155
|
+
countryCode: countryCode.value
|
|
1156
|
+
})
|
|
1157
|
+
);
|
|
1158
|
+
const asYouTypeFormatted = ref();
|
|
1159
|
+
const inputValue = computed(() => {
|
|
1160
|
+
if (props.noFormattingAsYouType) {
|
|
1161
|
+
return internalValue.value ?? "";
|
|
1162
|
+
}
|
|
1163
|
+
return asYouTypeFormatted.value ?? internalValue.value ?? "";
|
|
1164
|
+
});
|
|
1165
|
+
async function setCountryFromIpWho() {
|
|
1166
|
+
const fetchedLocale = await fetchCountryCode2();
|
|
1167
|
+
if (fetchedLocale)
|
|
1168
|
+
setCountryCode(fetchedLocale);
|
|
1169
|
+
}
|
|
1170
|
+
async function loadExamples() {
|
|
1171
|
+
try {
|
|
1172
|
+
if (!props.noExample && !examplesFileLoaded.value) {
|
|
1173
|
+
await loadPhoneNumberExamplesFile2();
|
|
1174
|
+
examplesFileLoaded.value = true;
|
|
1175
|
+
}
|
|
1176
|
+
} catch {
|
|
1177
|
+
console.error("[maz-ui](MazPhoneNumberInput) while loading phone number examples file");
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
onMounted(async () => {
|
|
1181
|
+
await parseModel(model.value);
|
|
1182
|
+
await nextTick();
|
|
1183
|
+
if (props.fetchCountry && !countryCode.value) {
|
|
1184
|
+
await setCountryFromIpWho();
|
|
1185
|
+
}
|
|
1186
|
+
if (!props.defaultCountryCode && !props.noUseBrowserLocale && !countryCode.value) {
|
|
1187
|
+
setCountryCodeFromBrowserLocale();
|
|
1188
|
+
}
|
|
1189
|
+
await loadExamples();
|
|
1190
|
+
});
|
|
1191
|
+
watch(
|
|
1192
|
+
() => results.value,
|
|
1193
|
+
(newResults) => {
|
|
1194
|
+
emits("update", newResults);
|
|
1195
|
+
emits("data", newResults);
|
|
1196
|
+
},
|
|
1197
|
+
{ immediate: true, deep: true }
|
|
1198
|
+
);
|
|
1199
|
+
watch(
|
|
1200
|
+
() => countryCode.value,
|
|
1201
|
+
(newCountryCode, oldCountryCode) => {
|
|
1202
|
+
if (newCountryCode && newCountryCode !== oldCountryCode) {
|
|
1203
|
+
setCountryCode(newCountryCode);
|
|
1204
|
+
onInputValueChanged(inputValue.value);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
);
|
|
1208
|
+
watch(
|
|
1209
|
+
() => model.value,
|
|
1210
|
+
async (newModel, oldModel) => {
|
|
1211
|
+
if (newModel !== oldModel) {
|
|
1212
|
+
parseModel(newModel);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
);
|
|
1216
|
+
watch(
|
|
1217
|
+
() => inputValue.value,
|
|
1218
|
+
async (newModel, oldModel) => {
|
|
1219
|
+
if (!props.noFormattingAsYouType && newModel && newModel !== oldModel) {
|
|
1220
|
+
const input = getPhoneNumberInput();
|
|
1221
|
+
if (input && !results.value.isValid && typeof selectionRange.start === "number" && !selectionRange.cursorAtEnd) {
|
|
1222
|
+
const start = selectionRange.start;
|
|
1223
|
+
const end = selectionRange.end;
|
|
1224
|
+
setTimeout(() => {
|
|
1225
|
+
input.setSelectionRange(start, end ?? start);
|
|
1226
|
+
}, 0);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
);
|
|
1231
|
+
function setCountryCodeFromBrowserLocale() {
|
|
1232
|
+
const { locale } = browserLocale2();
|
|
1233
|
+
if (locale) {
|
|
1234
|
+
setCountryCode(locale);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function updateResults(phoneNumber, countryCode2) {
|
|
1238
|
+
results.value = getResultsFromPhoneNumber2({
|
|
1239
|
+
phoneNumber,
|
|
1240
|
+
countryCode: countryCode2
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
async function onInputValueChanged(phoneNumber) {
|
|
1244
|
+
const input = getPhoneNumberInput();
|
|
1245
|
+
selectionRange.start = input == null ? void 0 : input.selectionStart;
|
|
1246
|
+
selectionRange.end = input == null ? void 0 : input.selectionEnd;
|
|
1247
|
+
selectionRange.cursorAtEnd = selectionRange.start ? selectionRange.start >= phoneNumber.length : true;
|
|
1248
|
+
const sanitizedPhoneNumber = sanitizePhoneNumber2(phoneNumber);
|
|
1249
|
+
internalValue.value = sanitizedPhoneNumber;
|
|
1250
|
+
const newResults = getResultsFromPhoneNumber2({
|
|
1251
|
+
phoneNumber: sanitizedPhoneNumber,
|
|
1252
|
+
countryCode: countryCode.value
|
|
1253
|
+
});
|
|
1254
|
+
model.value = newResults.e164;
|
|
1255
|
+
}
|
|
1256
|
+
function onCountryChanged(codeCountry) {
|
|
1257
|
+
updateResults(inputValue.value, codeCountry);
|
|
1258
|
+
setCountryCode(codeCountry, true);
|
|
1259
|
+
}
|
|
1260
|
+
function setCountryCode(selectedCountryCode, autoFocusInput = false) {
|
|
1261
|
+
try {
|
|
1262
|
+
const countryAvailable = isCountryAvailable(selectedCountryCode);
|
|
1263
|
+
if (countryAvailable) {
|
|
1264
|
+
countryCode.value = selectedCountryCode;
|
|
1265
|
+
if (autoFocusInput) {
|
|
1266
|
+
focusPhoneNumberInput();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
} catch (error) {
|
|
1270
|
+
console.error(`[maz-ui](MazPhoneNumberInput) ${error}`);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
async function parseModel(newModel) {
|
|
1274
|
+
updateResults(newModel, countryCode.value);
|
|
1275
|
+
await nextTick();
|
|
1276
|
+
if (props.noFormattingAsYouType) {
|
|
1277
|
+
internalValue.value = inputValue.value;
|
|
1278
|
+
} else {
|
|
1279
|
+
asYouTypeFormatted.value = selectionRange.cursorAtEnd || results.value.isValid ? internalValue.value = getAsYouTypeFormat2(
|
|
1280
|
+
results.value.countryCode ?? countryCode.value,
|
|
1281
|
+
results.value.formatNational ?? internalValue.value
|
|
1282
|
+
) : internalValue.value;
|
|
1283
|
+
}
|
|
1284
|
+
await nextTick();
|
|
1285
|
+
autoUpdateCountryCodeWithResults(results.value);
|
|
1286
|
+
}
|
|
1287
|
+
function autoUpdateCountryCodeWithResults(newResults) {
|
|
1288
|
+
if (newResults.countryCode && countryCode.value !== newResults.countryCode) {
|
|
1289
|
+
setCountryCode(newResults.countryCode);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
function getPhoneNumberInput() {
|
|
1293
|
+
var _a;
|
|
1294
|
+
return (_a = PhoneNumberInput.value) == null ? void 0 : _a.$el.querySelector("input");
|
|
1295
|
+
}
|
|
1296
|
+
function focusCountrySelector() {
|
|
1297
|
+
var _a, _b;
|
|
1298
|
+
(_b = (_a = CountrySelector.value) == null ? void 0 : _a.$el.querySelector("input")) == null ? void 0 : _b.focus();
|
|
1299
|
+
}
|
|
1300
|
+
function focusPhoneNumberInput() {
|
|
1301
|
+
var _a;
|
|
1302
|
+
(_a = getPhoneNumberInput()) == null ? void 0 : _a.focus();
|
|
1303
|
+
}
|
|
1304
|
+
return (_ctx, _cache) => {
|
|
1305
|
+
var _a, _b;
|
|
1306
|
+
return openBlock(), createElementBlock("div", {
|
|
1307
|
+
id: unref(instanceId),
|
|
1308
|
+
class: normalizeClass(["m-phone-number-input", {
|
|
1309
|
+
"--no-flags": __props.noFlags
|
|
1310
|
+
}])
|
|
1311
|
+
}, [
|
|
1312
|
+
countryCode.value && !__props.noFlags && !__props.noCountrySelector ? (openBlock(), createElementBlock(
|
|
1313
|
+
"button",
|
|
1314
|
+
{
|
|
1315
|
+
key: 0,
|
|
1316
|
+
class: "m-phone-number-input__country-flag maz-text-xl",
|
|
1317
|
+
tabindex: "-1",
|
|
1318
|
+
type: "button",
|
|
1319
|
+
onClick: focusCountrySelector
|
|
1320
|
+
},
|
|
1321
|
+
toDisplayString(unref(localeToUnicodeFlag)(countryCode.value)),
|
|
1322
|
+
1
|
|
1323
|
+
/* TEXT */
|
|
1324
|
+
)) : createCommentVNode("v-if", true),
|
|
1325
|
+
!__props.noCountrySelector && countryOptions.value ? (openBlock(), createBlock(MazSelect, {
|
|
1326
|
+
key: 1,
|
|
1327
|
+
ref_key: "CountrySelector",
|
|
1328
|
+
ref: CountrySelector,
|
|
1329
|
+
class: "m-phone-number-input__select",
|
|
1330
|
+
"model-value": countryCode.value,
|
|
1331
|
+
"option-value-key": "iso2",
|
|
1332
|
+
"option-label-key": "name",
|
|
1333
|
+
"option-input-value-key": "dialCode",
|
|
1334
|
+
"max-list-width": 250,
|
|
1335
|
+
disabled: __props.disabled,
|
|
1336
|
+
color: __props.color,
|
|
1337
|
+
size: __props.size,
|
|
1338
|
+
"list-position": __props.listPosition,
|
|
1339
|
+
search: !__props.noSearch,
|
|
1340
|
+
"search-placeholder": locales.value.countrySelector.searchPlaceholder,
|
|
1341
|
+
options: countryOptions.value,
|
|
1342
|
+
error: __props.error || !!inputValue.value && !countryCode.value,
|
|
1343
|
+
hint: !!inputValue.value && !countryCode.value ? locales.value.countrySelector.error : void 0,
|
|
1344
|
+
label: locales.value.countrySelector.placeholder,
|
|
1345
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => onCountryChanged($event)),
|
|
1346
|
+
onFocus: _cache[1] || (_cache[1] = ($event) => inputFocused.value = false)
|
|
1347
|
+
}, {
|
|
1348
|
+
default: withCtx(({ option, isSelected }) => [
|
|
1349
|
+
createElementVNode(
|
|
1350
|
+
"div",
|
|
1351
|
+
{
|
|
1352
|
+
class: normalizeClass(["m-phone-number-input__select__item maz-flex maz-items-center maz-truncate", {
|
|
1353
|
+
"m-phone-number-input__select__item--selected": isSelected
|
|
1354
|
+
}])
|
|
1355
|
+
},
|
|
1356
|
+
[
|
|
1357
|
+
!__props.noFlags && typeof option.iso2 === "string" ? (openBlock(), createElementBlock(
|
|
1358
|
+
"span",
|
|
1359
|
+
_hoisted_2,
|
|
1360
|
+
toDisplayString(unref(localeToUnicodeFlag)(option.iso2)),
|
|
1361
|
+
1
|
|
1362
|
+
/* TEXT */
|
|
1363
|
+
)) : createCommentVNode("v-if", true),
|
|
1364
|
+
__props.showCodeOnList ? (openBlock(), createElementBlock(
|
|
1365
|
+
"span",
|
|
1366
|
+
{
|
|
1367
|
+
key: 1,
|
|
1368
|
+
class: normalizeClass(["maz-w-10 maz-flex-none", { "maz-text-muted": !isSelected }])
|
|
1369
|
+
},
|
|
1370
|
+
toDisplayString(option.dialCode),
|
|
1371
|
+
3
|
|
1372
|
+
/* TEXT, CLASS */
|
|
1373
|
+
)) : createCommentVNode("v-if", true),
|
|
1374
|
+
createElementVNode(
|
|
1375
|
+
"span",
|
|
1376
|
+
{
|
|
1377
|
+
class: normalizeClass(["maz-flex-1 maz-truncate", { "maz-font-semibold": isSelected }])
|
|
1378
|
+
},
|
|
1379
|
+
toDisplayString(option.name),
|
|
1380
|
+
3
|
|
1381
|
+
/* TEXT, CLASS */
|
|
1382
|
+
)
|
|
1383
|
+
],
|
|
1384
|
+
2
|
|
1385
|
+
/* CLASS */
|
|
1386
|
+
)
|
|
1387
|
+
]),
|
|
1388
|
+
_: 1
|
|
1389
|
+
/* STABLE */
|
|
1390
|
+
}, 8, ["model-value", "disabled", "color", "size", "list-position", "search", "search-placeholder", "options", "error", "hint", "label"])) : createCommentVNode("v-if", true),
|
|
1391
|
+
createVNode(MazInput, mergeProps({
|
|
1392
|
+
id: __props.id,
|
|
1393
|
+
ref_key: "PhoneNumberInput",
|
|
1394
|
+
ref: PhoneNumberInput,
|
|
1395
|
+
"model-value": inputValue.value,
|
|
1396
|
+
label: inputPlaceholder.value,
|
|
1397
|
+
disabled: __props.disabled,
|
|
1398
|
+
color: __props.color,
|
|
1399
|
+
error: __props.error || !!inputValue.value && !((_a = results.value) == null ? void 0 : _a.isValid)
|
|
1400
|
+
}, _ctx.$attrs, {
|
|
1401
|
+
size: __props.size,
|
|
1402
|
+
"icon-name": "phone",
|
|
1403
|
+
type: "tel",
|
|
1404
|
+
clearable: "",
|
|
1405
|
+
class: ["m-phone-number-input__input maz-flex-1", {
|
|
1406
|
+
"--border-radius": !__props.noCountrySelector,
|
|
1407
|
+
"--error": __props.error || !((_b = results.value) == null ? void 0 : _b.isValid),
|
|
1408
|
+
"--focused": inputFocused.value
|
|
1409
|
+
}],
|
|
1410
|
+
onFocus: _cache[2] || (_cache[2] = ($event) => inputFocused.value = true),
|
|
1411
|
+
onBlur: _cache[3] || (_cache[3] = ($event) => inputFocused.value = false),
|
|
1412
|
+
"onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => onInputValueChanged($event))
|
|
1413
|
+
}), null, 16, ["id", "model-value", "label", "disabled", "color", "error", "size", "class"])
|
|
1414
|
+
], 10, _hoisted_1);
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
const MazPhoneNumberInput_vue_vue_type_style_index_0_scoped_6478d9a7_lang = "";
|
|
1419
|
+
const MazPhoneNumberInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-6478d9a7"]]);
|
|
1420
|
+
export {
|
|
1421
|
+
MazPhoneNumberInput as M,
|
|
1422
|
+
_export_sfc as _
|
|
1423
|
+
};
|