maz-ui 3.19.2 → 3.20.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.
Files changed (30) hide show
  1. package/components/MazCheckbox.d.ts +22 -2
  2. package/components/MazCheckbox.mjs +144 -32
  3. package/components/MazFullscreenLoader.d.ts +3 -0
  4. package/components/MazPhoneNumberInput.mjs +1 -1
  5. package/components/MazSelect.d.ts +12 -4
  6. package/components/MazSelect.mjs +1 -1
  7. package/components/assets/MazCheckbox.css +1 -1
  8. package/components/assets/MazPhoneNumberInput.css +1 -1
  9. package/components/assets/MazSelect.css +1 -1
  10. package/components/chunks/{MazBtn-16ab35fe.mjs → MazBtn-090f5ced.mjs} +2 -2
  11. package/components/chunks/{MazBtn-0d8e3249.mjs → MazBtn-e578aab0.mjs} +2 -2
  12. package/components/chunks/MazCheckbox-12a37b71.mjs +144 -0
  13. package/components/chunks/MazCheckbox-aeada499.mjs +144 -0
  14. package/components/chunks/MazPhoneNumberInput-94d7c29b.mjs +1482 -0
  15. package/components/chunks/{MazSelect-1f4d1193.mjs → MazSelect-5c3b7a30.mjs} +128 -70
  16. package/components/chunks/{MazSpinner-5fdafc97.mjs → MazSpinner-5be69292.mjs} +1 -1
  17. package/components/chunks/{MazSpinner-6025406b.mjs → MazSpinner-f1454eeb.mjs} +1 -1
  18. package/components/chunks/check-77afbaee.mjs +32 -0
  19. package/css/main.css +1 -1
  20. package/nuxt/index.json +1 -1
  21. package/nuxt/index.mjs +9 -5
  22. package/package.json +15 -15
  23. package/types/components/MazCheckbox.vue.d.ts +22 -2
  24. package/types/components/MazFullscreenLoader.vue.d.ts +3 -0
  25. package/types/components/MazSelect.vue.d.ts +12 -4
  26. package/types/modules/directives/v-fullscreen-img/MazFullscreenImg.vue.d.ts +3 -0
  27. package/types/tailwindcss/tailwind.config.d.ts +1 -2
  28. package/components/chunks/MazInput-15f3e149.mjs +0 -344
  29. package/components/chunks/MazPhoneNumberInput-901c4fa6.mjs +0 -651
  30. package/components/chunks/MazSelect-c5c3f874.mjs +0 -444
@@ -0,0 +1,1482 @@
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, useCssVars, onBeforeMount, watch, unref, Transition, normalizeStyle, Fragment, renderList, nextTick, 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-e578aab0.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-77afbaee.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, Array],
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
+ multiple: { type: Boolean, default: false }
593
+ },
594
+ emits: [
595
+ "close",
596
+ "open",
597
+ "blur",
598
+ "focus",
599
+ "change",
600
+ "update:model-value",
601
+ /** On selected value, returns the option object */
602
+ "selected-option"
603
+ ],
604
+ setup(__props, { emit: __emit }) {
605
+ useCssVars((_ctx) => ({
606
+ "4268d79e": keyboardSelectedBgColor.value,
607
+ "71723ca0": selectedTextColor.value,
608
+ "66e06018": selectedBgColor.value
609
+ }));
610
+ const MazCheckbox = defineAsyncComponent(() => import("./MazCheckbox-12a37b71.mjs"));
611
+ const SearchIcon = defineAsyncComponent(() => import("./magnifying-glass-6a0dd1a2.mjs"));
612
+ const ChevronDownIcon = defineAsyncComponent(() => import("./chevron-down-7a070b10.mjs"));
613
+ const NoSymbolIcon = defineAsyncComponent(() => import("./no-symbol-6173a20b.mjs"));
614
+ const instance = getCurrentInstance();
615
+ const props = __props;
616
+ const emits = __emit;
617
+ const listOpened = ref(false);
618
+ const tmpModelValueIndex = ref();
619
+ const isBlackOrTransparentColor = computed(
620
+ () => ["black", "transparent", "white"].includes(props.color)
621
+ );
622
+ const selectedTextColor = computed(
623
+ () => isBlackOrTransparentColor.value ? `var(--maz-color-black)` : `var(--maz-color-${props.color}-800)`
624
+ );
625
+ const selectedBgColor = computed(
626
+ () => isBlackOrTransparentColor.value ? "var(--maz-color-muted)" : `var(--maz-color-${props.color}-100)`
627
+ );
628
+ const keyboardSelectedBgColor = computed(
629
+ () => isBlackOrTransparentColor.value ? "var(--maz-color-muted)" : `var(--maz-color-${props.color}-200)`
630
+ );
631
+ const hasListOpened = computed(() => listOpened.value || props.open);
632
+ const instanceId = useInstanceUniqId({
633
+ componentName: "MazSelect",
634
+ instance,
635
+ providedId: props.id
636
+ });
637
+ const selectedOptions = computed(
638
+ () => {
639
+ var _a;
640
+ return ((_a = props.options) == null ? void 0 : _a.filter((option) => {
641
+ return props.multiple ? Array.isArray(props.modelValue) ? props.modelValue.includes(option[props.optionValueKey]) && !isNullOrUndefined(option[props.optionValueKey]) : false : props.modelValue === option[props.optionValueKey] && !isNullOrUndefined(option[props.optionValueKey]);
642
+ })) ?? [];
643
+ }
644
+ );
645
+ onBeforeMount(() => {
646
+ var _a;
647
+ if (!((_a = props.options) == null ? void 0 : _a.length)) {
648
+ console.warn("[maz-ui](MazSelect) you must provide options");
649
+ }
650
+ updateTmpModelValueIndex();
651
+ });
652
+ const mazSelectElement = ref();
653
+ const mazInputComponent = ref();
654
+ const searchInputComponent = ref();
655
+ const optionsListElement = ref();
656
+ const isNullOrUndefined = (value) => {
657
+ return value === void 0 || value === null;
658
+ };
659
+ function isSelectedOption(option) {
660
+ var _a;
661
+ const hasOption = ((_a = selectedOptions.value) == null ? void 0 : _a.some(
662
+ (selectedOption) => selectedOption[props.optionValueKey] === option[props.optionValueKey]
663
+ )) ?? false;
664
+ return hasOption && !isNullOrUndefined(option[props.optionValueKey]);
665
+ }
666
+ const mazInputValue = computed(() => {
667
+ var _a, _b;
668
+ if (props.multiple && props.modelValue && Array.isArray(props.modelValue)) {
669
+ return props.modelValue.map(
670
+ (value) => {
671
+ var _a2, _b2;
672
+ return (_b2 = (_a2 = optionsList.value) == null ? void 0 : _a2.find((option) => option[props.optionValueKey] === value)) == null ? void 0 : _b2[props.optionInputValueKey];
673
+ }
674
+ ).join(", ");
675
+ }
676
+ return (_b = (_a = optionsList.value) == null ? void 0 : _a.find((option) => option[props.optionValueKey] === props.modelValue)) == null ? void 0 : _b[props.optionInputValueKey];
677
+ });
678
+ const listTransition = computed(
679
+ () => props.listPosition.includes("bottom") ? "maz-slide" : "maz-slideinvert"
680
+ );
681
+ const searchQuery = ref("");
682
+ const query = ref("");
683
+ function normalizeString(str) {
684
+ return str.normalize("NFD").replaceAll(/[\u0300-\u036F]/g, "").replaceAll(/[^\dA-Za-z]/g, "");
685
+ }
686
+ const searchInValue = (value, query2) => {
687
+ return query2 && value && normalizeString(value.toString().toLocaleLowerCase().trim()).includes(
688
+ normalizeString(query2.toLocaleLowerCase().trim())
689
+ );
690
+ };
691
+ watch(
692
+ () => props.modelValue,
693
+ (value, oldValue) => {
694
+ }
695
+ );
696
+ function getFilteredOptionWithQuery(query2) {
697
+ var _a;
698
+ return query2 ? (_a = props.options) == null ? void 0 : _a.filter((option) => {
699
+ const searchValue = option[props.optionLabelKey];
700
+ const searchValue3 = option[props.optionValueKey];
701
+ const searchValue2 = option[props.optionInputValueKey];
702
+ return searchInValue(searchValue, query2) || searchInValue(searchValue3, query2) || searchInValue(searchValue2, query2);
703
+ }) : props.options;
704
+ }
705
+ const optionsList = computed(() => getFilteredOptionWithQuery(searchQuery.value));
706
+ const closeList = async (event) => {
707
+ var _a;
708
+ if (event && ("relatedTarget" in event && ((_a = mazSelectElement.value) == null ? void 0 : _a.contains(event.relatedTarget)) || event.type === "keydown")) {
709
+ return event.preventDefault();
710
+ }
711
+ await nextTick();
712
+ listOpened.value = false;
713
+ tmpModelValueIndex.value = 0;
714
+ emits("close", event);
715
+ };
716
+ const openList = async (event) => {
717
+ if (props.disabled || hasListOpened.value)
718
+ return;
719
+ event == null ? void 0 : event.preventDefault();
720
+ listOpened.value = true;
721
+ await scrollToOptionIndex();
722
+ emits("focus", event);
723
+ emits("open", listOpened.value);
724
+ };
725
+ function focusMainInput() {
726
+ var _a, _b;
727
+ (_b = (_a = mazInputComponent.value) == null ? void 0 : _a.$el.querySelector("input")) == null ? void 0 : _b.focus();
728
+ }
729
+ function toggleList(event) {
730
+ listOpened.value ? closeList(event) : focusMainInput();
731
+ }
732
+ function focusSearchInputAndSetQuery(q) {
733
+ var _a;
734
+ searchQuery.value = q;
735
+ (_a = searchInputComponent.value) == null ? void 0 : _a.input.focus();
736
+ }
737
+ function searchOptionWithQuery(keyPressed) {
738
+ var _a;
739
+ if (keyPressed === "Backspace" && query.value.length > 0) {
740
+ query.value = query.value.slice(0, -1);
741
+ } else {
742
+ query.value += keyPressed;
743
+ }
744
+ const filteredOptions = getFilteredOptionWithQuery(query.value);
745
+ if (filteredOptions == null ? void 0 : filteredOptions.length) {
746
+ tmpModelValueIndex.value = (_a = optionsList.value) == null ? void 0 : _a.findIndex(
747
+ (option) => option[props.optionValueKey] === filteredOptions[0][props.optionValueKey]
748
+ );
749
+ if (typeof tmpModelValueIndex.value === "number" && tmpModelValueIndex.value >= 0) {
750
+ scrollToOptionIndex(tmpModelValueIndex.value);
751
+ }
752
+ }
753
+ debounceCallback(() => {
754
+ query.value = "";
755
+ }, 1e3);
756
+ }
757
+ const mainInputKeyboardHandler = (event) => {
758
+ const keyPressed = event.key;
759
+ if (/^[\dA-Za-z]$/.test(keyPressed)) {
760
+ event.preventDefault();
761
+ openList(event);
762
+ props.search ? focusSearchInputAndSetQuery(keyPressed) : searchOptionWithQuery(keyPressed);
763
+ } else {
764
+ keyboardHandler(event);
765
+ }
766
+ };
767
+ const keyboardHandler = (event) => {
768
+ const code = event.code;
769
+ const isArrow = ["ArrowUp", "ArrowDown"].includes(code);
770
+ const shouldSelect = ["Enter", "Space"].includes(code);
771
+ const shouldCloseList = "Escape" === code && hasListOpened.value;
772
+ if (isArrow) {
773
+ arrowHandler(event, tmpModelValueIndex.value);
774
+ } else if (shouldSelect) {
775
+ enterHandler(event, tmpModelValueIndex.value);
776
+ } else if (shouldCloseList) {
777
+ closeList();
778
+ }
779
+ };
780
+ const arrowHandler = (event, currentIndex) => {
781
+ var _a;
782
+ event.preventDefault();
783
+ const code = event.code;
784
+ if (!hasListOpened.value)
785
+ openList(event);
786
+ const optionsLength = (_a = optionsList.value) == null ? void 0 : _a.length;
787
+ if (!optionsLength) {
788
+ return;
789
+ }
790
+ if (typeof currentIndex === "number") {
791
+ if (currentIndex === optionsLength - 1 && code === "ArrowDown") {
792
+ tmpModelValueIndex.value = 0;
793
+ } else if (currentIndex === 0 && code === "ArrowUp") {
794
+ tmpModelValueIndex.value = optionsLength - 1;
795
+ } else {
796
+ tmpModelValueIndex.value = code === "ArrowDown" ? currentIndex + 1 : currentIndex - 1;
797
+ }
798
+ } else {
799
+ tmpModelValueIndex.value = code === "ArrowDown" ? 0 : optionsLength - 1;
800
+ }
801
+ scrollToOptionIndex(tmpModelValueIndex.value);
802
+ };
803
+ const enterHandler = (event, currentIndex) => {
804
+ var _a, _b, _c;
805
+ event.preventDefault();
806
+ if (!hasListOpened.value) {
807
+ return openList(event);
808
+ }
809
+ 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];
810
+ if (!isNullOrUndefined(newValue)) {
811
+ updateValue(newValue);
812
+ }
813
+ };
814
+ async function scrollToOptionIndex(index) {
815
+ var _a, _b;
816
+ await nextTick();
817
+ if (typeof index !== "number") {
818
+ updateTmpModelValueIndex();
819
+ }
820
+ const selectedIndex = index ?? tmpModelValueIndex.value;
821
+ if (typeof selectedIndex === "number" && selectedIndex >= 0) {
822
+ (_b = (_a = optionsListElement.value) == null ? void 0 : _a.querySelectorAll(".m-select-list-item")[selectedIndex]) == null ? void 0 : _b.scrollIntoView({
823
+ behavior: "auto",
824
+ block: "nearest",
825
+ inline: "start"
826
+ });
827
+ }
828
+ }
829
+ function updateTmpModelValueIndex(inputOption) {
830
+ var _a;
831
+ const index = (_a = optionsList.value) == null ? void 0 : _a.findIndex((option) => {
832
+ var _a2, _b;
833
+ if (props.multiple && Array.isArray(props.modelValue)) {
834
+ if (inputOption) {
835
+ return inputOption[props.optionValueKey] === option[props.optionValueKey];
836
+ }
837
+ const values = [...props.modelValue].reverse();
838
+ return values[0] === option[props.optionValueKey];
839
+ } else {
840
+ return ((_b = (_a2 = selectedOptions.value) == null ? void 0 : _a2[0]) == null ? void 0 : _b[props.optionValueKey]) === option[props.optionValueKey];
841
+ }
842
+ });
843
+ tmpModelValueIndex.value = index && index >= 0 ? index : 0;
844
+ }
845
+ const updateValue = (inputOption, mustCloseList = true) => {
846
+ var _a;
847
+ if (mustCloseList && !props.multiple) {
848
+ nextTick(() => closeList());
849
+ }
850
+ searchQuery.value = "";
851
+ const isAlreadySelected = (_a = selectedOptions.value) == null ? void 0 : _a.some(
852
+ (option) => option[props.optionValueKey] === inputOption[props.optionValueKey]
853
+ );
854
+ let newValue = selectedOptions.value;
855
+ if (isAlreadySelected && props.multiple) {
856
+ newValue = newValue == null ? void 0 : newValue.filter(
857
+ (option) => option[props.optionValueKey] !== inputOption[props.optionValueKey]
858
+ );
859
+ } else if (props.multiple) {
860
+ newValue.push(inputOption);
861
+ } else {
862
+ newValue = [inputOption];
863
+ }
864
+ const selectedValues = newValue.map((option) => option[props.optionValueKey]);
865
+ emits("update:model-value", props.multiple ? selectedValues : selectedValues[0]);
866
+ emits("selected-option", inputOption);
867
+ updateTmpModelValueIndex(inputOption);
868
+ focusMainInput();
869
+ };
870
+ return (_ctx, _cache) => {
871
+ return openBlock(), createElementBlock(
872
+ "div",
873
+ {
874
+ ref_key: "mazSelectElement",
875
+ ref: mazSelectElement,
876
+ class: normalizeClass(["m-select", { "--is-open": hasListOpened.value, "--disabled": __props.disabled }]),
877
+ onBlurCapture: closeList
878
+ },
879
+ [
880
+ createVNode(MazInput, mergeProps({
881
+ id: unref(instanceId),
882
+ ref_key: "mazInputComponent",
883
+ ref: mazInputComponent,
884
+ class: "m-select-input"
885
+ }, _ctx.$attrs, {
886
+ required: __props.required,
887
+ "border-active": listOpened.value,
888
+ color: __props.color,
889
+ "model-value": mazInputValue.value,
890
+ autocomplete: "off",
891
+ size: __props.size,
892
+ disabled: __props.disabled,
893
+ onFocus: withModifiers(openList, ["prevent", "stop"]),
894
+ onClick: withModifiers(openList, ["prevent", "stop"]),
895
+ onChange: _cache[0] || (_cache[0] = ($event) => emits("change", $event)),
896
+ onKeydown: mainInputKeyboardHandler
897
+ }), {
898
+ "right-icon": withCtx(() => [
899
+ createElementVNode("button", {
900
+ tabindex: "-1",
901
+ type: "button",
902
+ class: "m-select-input__toggle-button maz-custom",
903
+ onClick: withModifiers(toggleList, ["stop"])
904
+ }, [
905
+ createVNode(unref(ChevronDownIcon), { class: "m-select-chevron maz-text-xl" })
906
+ ], 8, _hoisted_1$1)
907
+ ]),
908
+ _: 1
909
+ /* STABLE */
910
+ }, 16, ["id", "required", "border-active", "color", "model-value", "size", "disabled", "onFocus", "onClick"]),
911
+ createVNode(Transition, { name: listTransition.value }, {
912
+ default: withCtx(() => [
913
+ hasListOpened.value ? (openBlock(), createElementBlock(
914
+ "div",
915
+ {
916
+ key: 0,
917
+ ref_key: "optionsListElement",
918
+ ref: optionsListElement,
919
+ class: normalizeClass(["m-select-list", {
920
+ "--top": __props.listPosition.includes("top"),
921
+ "--left": __props.listPosition.includes("left"),
922
+ "--right": __props.listPosition.includes("right"),
923
+ "--bottom": __props.listPosition.includes("bottom")
924
+ }]),
925
+ style: normalizeStyle({
926
+ maxHeight: `${__props.maxListHeight}px`,
927
+ maxWidth: `${__props.maxListWidth}px`
928
+ })
929
+ },
930
+ [
931
+ __props.search ? (openBlock(), createElementBlock("div", _hoisted_2$1, [
932
+ createVNode(MazInput, {
933
+ ref_key: "searchInputComponent",
934
+ ref: searchInputComponent,
935
+ modelValue: searchQuery.value,
936
+ "onUpdate:modelValue": [
937
+ _cache[1] || (_cache[1] = ($event) => searchQuery.value = $event),
938
+ _cache[2] || (_cache[2] = ($event) => tmpModelValueIndex.value = 0)
939
+ ],
940
+ size: "sm",
941
+ color: __props.color,
942
+ placeholder: __props.searchPlaceholder,
943
+ name: "search",
944
+ autocomplete: "off",
945
+ tabindex: "-1",
946
+ class: "m-select-list__search-input",
947
+ onKeydown: keyboardHandler
948
+ }, {
949
+ "left-icon": withCtx(() => [
950
+ createVNode(unref(SearchIcon), { class: "maz-h-[1.3rem] maz-w-[1.3rem]" })
951
+ ]),
952
+ _: 1
953
+ /* STABLE */
954
+ }, 8, ["modelValue", "color", "placeholder"])
955
+ ])) : createCommentVNode("v-if", true),
956
+ createCommentVNode("\n @slot No results slot - Displayed when no results corresponding with seeach query\n "),
957
+ !optionsList.value || optionsList.value.length <= 0 ? renderSlot(_ctx.$slots, "no-results", { key: 1 }, () => [
958
+ createElementVNode("span", _hoisted_3, [
959
+ createVNode(unref(NoSymbolIcon), { class: "maz-h-6 maz-w-6 maz-text-normal" })
960
+ ])
961
+ ], true) : (openBlock(), createElementBlock("div", _hoisted_4, [
962
+ (openBlock(true), createElementBlock(
963
+ Fragment,
964
+ null,
965
+ renderList(optionsList.value, (option, i) => {
966
+ return openBlock(), createElementBlock("button", {
967
+ key: i,
968
+ tabindex: "-1",
969
+ type: "button",
970
+ class: normalizeClass(["m-select-list-item maz-custom", [
971
+ {
972
+ "--is-keyboard-selected": tmpModelValueIndex.value === i,
973
+ "--is-selected": isSelectedOption(option),
974
+ "--is-none-value": isNullOrUndefined(option[__props.optionValueKey])
975
+ }
976
+ ]]),
977
+ style: normalizeStyle({ minHeight: `${__props.itemHeight}px` }),
978
+ onClick: withModifiers(($event) => updateValue(option), ["prevent", "stop"])
979
+ }, [
980
+ __props.multiple ? (openBlock(), createBlock(unref(MazCheckbox), {
981
+ key: 0,
982
+ tabindex: "-1",
983
+ "model-value": isSelectedOption(option),
984
+ size: "sm",
985
+ color: __props.color
986
+ }, null, 8, ["model-value", "color"])) : createCommentVNode("v-if", true),
987
+ createCommentVNode("\n @slot Custom option\n @binding {Object} option\n @binding {Boolean} is-selected\n "),
988
+ renderSlot(_ctx.$slots, "default", {
989
+ option,
990
+ isSelected: isSelectedOption(option)
991
+ }, () => [
992
+ createElementVNode(
993
+ "span",
994
+ null,
995
+ toDisplayString(option[__props.optionLabelKey]),
996
+ 1
997
+ /* TEXT */
998
+ )
999
+ ], true)
1000
+ ], 14, _hoisted_5);
1001
+ }),
1002
+ 128
1003
+ /* KEYED_FRAGMENT */
1004
+ ))
1005
+ ]))
1006
+ ],
1007
+ 6
1008
+ /* CLASS, STYLE */
1009
+ )) : createCommentVNode("v-if", true)
1010
+ ]),
1011
+ _: 3
1012
+ /* FORWARDED */
1013
+ }, 8, ["name"])
1014
+ ],
1015
+ 34
1016
+ /* CLASS, HYDRATE_EVENTS */
1017
+ );
1018
+ };
1019
+ }
1020
+ });
1021
+ const MazSelect_vue_vue_type_style_index_0_scoped_6ebd3ef8_lang = "";
1022
+ const MazSelect = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-6ebd3ef8"]]);
1023
+ const _hoisted_1 = ["id"];
1024
+ const _hoisted_2 = {
1025
+ key: 0,
1026
+ class: "maz-mr-2 maz-text-lg"
1027
+ };
1028
+ const _sfc_main = /* @__PURE__ */ defineComponent({
1029
+ __name: "MazPhoneNumberInput",
1030
+ props: {
1031
+ modelValue: {
1032
+ type: String,
1033
+ validator: (prop) => {
1034
+ return typeof prop === "string" || prop === void 0;
1035
+ },
1036
+ default: void 0
1037
+ },
1038
+ /** @deprecated */
1039
+ defaultPhoneNumber: { type: String, default: void 0 },
1040
+ countryCode: {
1041
+ type: String,
1042
+ default: void 0,
1043
+ validator: (code) => isCountryAvailable(code)
1044
+ },
1045
+ /** @deprecated - use country-code or v-model:country-code */
1046
+ defaultCountryCode: {
1047
+ type: String,
1048
+ default: void 0,
1049
+ validator: (code) => isCountryAvailable(code)
1050
+ },
1051
+ id: { type: String, default: void 0 },
1052
+ placeholder: { type: String, default: void 0 },
1053
+ preferredCountries: { type: Array, default: void 0 },
1054
+ ignoredCountries: { type: Array, default: void 0 },
1055
+ onlyCountries: { type: Array, default: void 0 },
1056
+ translations: { type: Object, default: void 0 },
1057
+ listPosition: {
1058
+ type: String,
1059
+ default: "bottom left",
1060
+ validator: (value) => {
1061
+ return ["top", "top right", "top left", "bottom", "bottom right", "bottom left"].includes(
1062
+ value
1063
+ );
1064
+ }
1065
+ },
1066
+ color: { type: String, default: "primary" },
1067
+ size: {
1068
+ type: String,
1069
+ default: "md",
1070
+ validator: (value) => {
1071
+ return ["mini", "xs", "sm", "md", "lg", "xl"].includes(value);
1072
+ }
1073
+ },
1074
+ noFlags: { type: Boolean, default: false },
1075
+ disabled: { type: Boolean, default: false },
1076
+ noExample: { type: Boolean, default: false },
1077
+ noSearch: { type: Boolean, default: false },
1078
+ noUseBrowserLocale: { type: Boolean, default: false },
1079
+ fetchCountry: { type: Boolean, default: false },
1080
+ noCountrySelector: { type: Boolean, default: false },
1081
+ showCodeOnList: { type: Boolean, default: false },
1082
+ error: { type: Boolean, default: false },
1083
+ customCountriesList: {
1084
+ type: Object,
1085
+ default: void 0
1086
+ },
1087
+ /**
1088
+ * Disabled auto-format as you type
1089
+ */
1090
+ noFormattingAsYouType: { type: Boolean, default: false },
1091
+ /**
1092
+ * locale of country list - Ex: "fr-FR"
1093
+ * @default browser locale
1094
+ */
1095
+ countryLocale: { type: String, default: void 0 }
1096
+ },
1097
+ emits: [
1098
+ /** emitted when country or phone number changed
1099
+ * @returns data - {Result}
1100
+ */
1101
+ "update",
1102
+ /** emitted when country or phone number changed
1103
+ * @returns data - {Result}
1104
+ */
1105
+ "data",
1106
+ /** emitted when selected country changed */
1107
+ "country-code",
1108
+ /** Two way binding (v-model:model-value) - emitted when country changed */
1109
+ "update:model-value",
1110
+ /** Two way binding (v-model:country-code) - emitted when country changed */
1111
+ "update:country-code"
1112
+ ],
1113
+ setup(__props, { emit: __emit }) {
1114
+ const {
1115
+ fetchCountryCode: fetchCountryCode2,
1116
+ browserLocale: browserLocale2,
1117
+ getResultsFromPhoneNumber: getResultsFromPhoneNumber2,
1118
+ getAsYouTypeFormat: getAsYouTypeFormat2,
1119
+ getCountriesList: getCountriesList2,
1120
+ getPhoneNumberExample: getPhoneNumberExample2,
1121
+ sanitizePhoneNumber: sanitizePhoneNumber2,
1122
+ loadPhoneNumberExamplesFile: loadPhoneNumberExamplesFile2
1123
+ } = useLibphonenumber();
1124
+ const emits = __emit;
1125
+ const props = __props;
1126
+ const instance = getCurrentInstance();
1127
+ const instanceId = useInstanceUniqId({
1128
+ componentName: "MazPhoneNumberInput",
1129
+ instance,
1130
+ providedId: props.id
1131
+ });
1132
+ const PhoneNumberInput = ref();
1133
+ const CountrySelector = ref();
1134
+ const selectionRange = reactive({
1135
+ start: 0,
1136
+ end: 0,
1137
+ cursorAtEnd: true
1138
+ });
1139
+ const examplesFileLoaded = ref(false);
1140
+ const inputFocused = ref(false);
1141
+ const countries = computed(() => getCountriesList2(props.countryLocale, props.customCountriesList));
1142
+ const countriesList = computed(() => {
1143
+ var _a;
1144
+ return (_a = countries.value) == null ? void 0 : _a.filter((item) => {
1145
+ var _a2;
1146
+ return !((_a2 = props.ignoredCountries) == null ? void 0 : _a2.includes(item.iso2));
1147
+ });
1148
+ });
1149
+ const countriesFiltered = computed(() => {
1150
+ const countries2 = props.onlyCountries || props.preferredCountries;
1151
+ return countries2 == null ? void 0 : countries2.map(
1152
+ (country) => {
1153
+ var _a;
1154
+ return (_a = countriesList.value) == null ? void 0 : _a.find((item) => item.iso2.includes(country));
1155
+ }
1156
+ );
1157
+ });
1158
+ const otherCountries = computed(() => {
1159
+ var _a;
1160
+ return (_a = countriesList.value) == null ? void 0 : _a.filter((item) => {
1161
+ var _a2;
1162
+ return !((_a2 = props.preferredCountries) == null ? void 0 : _a2.includes(item.iso2));
1163
+ });
1164
+ });
1165
+ const countriesSorted = computed(() => {
1166
+ return props.preferredCountries ? [...countriesFiltered.value ?? [], ...otherCountries.value ?? []] : props.onlyCountries ? countriesFiltered.value : countriesList.value;
1167
+ });
1168
+ const countryOptions = computed(() => {
1169
+ var _a;
1170
+ return (_a = countriesSorted.value) == null ? void 0 : _a.map((country) => {
1171
+ return country ? {
1172
+ ...country,
1173
+ dialCode: `+${country.dialCode}`
1174
+ } : void 0;
1175
+ }).filter(truthyFilter);
1176
+ });
1177
+ const locales = computed(() => ({
1178
+ ...defaultLocales,
1179
+ ...props.translations
1180
+ }));
1181
+ const inputPlaceholder = computed(() => {
1182
+ if (props.placeholder) {
1183
+ return props.placeholder;
1184
+ }
1185
+ const defaultPlaceholder = locales.value.phoneInput.placeholder;
1186
+ if (props.noExample || !examplesFileLoaded.value) {
1187
+ return defaultPlaceholder;
1188
+ } else {
1189
+ const example = getPhoneNumberExample2(countryCode.value);
1190
+ return results.value.isValid || !example ? defaultPlaceholder : `${locales.value.phoneInput.example} ${example}`;
1191
+ }
1192
+ });
1193
+ const model = computed({
1194
+ get: () => props.modelValue || props.defaultPhoneNumber,
1195
+ set: (value) => {
1196
+ emits("update:model-value", value);
1197
+ }
1198
+ });
1199
+ const internalCountryCode = ref();
1200
+ const countryCode = computed({
1201
+ get: () => props.countryCode || props.defaultCountryCode || internalCountryCode.value,
1202
+ set: (value) => {
1203
+ emits("country-code", value);
1204
+ emits("update:country-code", value);
1205
+ internalCountryCode.value = value;
1206
+ }
1207
+ });
1208
+ const internalValue = ref(model.value);
1209
+ const results = ref(
1210
+ getResultsFromPhoneNumber2({
1211
+ phoneNumber: model.value,
1212
+ countryCode: countryCode.value
1213
+ })
1214
+ );
1215
+ const asYouTypeFormatted = ref();
1216
+ const inputValue = computed(() => {
1217
+ if (props.noFormattingAsYouType) {
1218
+ return internalValue.value ?? "";
1219
+ }
1220
+ return asYouTypeFormatted.value ?? internalValue.value ?? "";
1221
+ });
1222
+ async function setCountryFromIpWho() {
1223
+ const fetchedLocale = await fetchCountryCode2();
1224
+ if (fetchedLocale)
1225
+ setCountryCode(fetchedLocale);
1226
+ }
1227
+ async function loadExamples() {
1228
+ try {
1229
+ if (!props.noExample && !examplesFileLoaded.value) {
1230
+ await loadPhoneNumberExamplesFile2();
1231
+ examplesFileLoaded.value = true;
1232
+ }
1233
+ } catch {
1234
+ console.error("[maz-ui](MazPhoneNumberInput) while loading phone number examples file");
1235
+ }
1236
+ }
1237
+ onMounted(async () => {
1238
+ await parseModel(model.value);
1239
+ await nextTick();
1240
+ if (props.fetchCountry && !countryCode.value) {
1241
+ await setCountryFromIpWho();
1242
+ }
1243
+ if (!props.defaultCountryCode && !props.noUseBrowserLocale && !countryCode.value) {
1244
+ setCountryCodeFromBrowserLocale();
1245
+ }
1246
+ await loadExamples();
1247
+ });
1248
+ watch(
1249
+ () => results.value,
1250
+ (newResults) => {
1251
+ emits("update", newResults);
1252
+ emits("data", newResults);
1253
+ },
1254
+ { immediate: true, deep: true }
1255
+ );
1256
+ watch(
1257
+ () => countryCode.value,
1258
+ (newCountryCode, oldCountryCode) => {
1259
+ if (newCountryCode && newCountryCode !== oldCountryCode) {
1260
+ setCountryCode(newCountryCode);
1261
+ onInputValueChanged(inputValue.value);
1262
+ }
1263
+ }
1264
+ );
1265
+ watch(
1266
+ () => model.value,
1267
+ async (newModel, oldModel) => {
1268
+ if (newModel !== oldModel) {
1269
+ parseModel(newModel);
1270
+ }
1271
+ }
1272
+ );
1273
+ watch(
1274
+ () => inputValue.value,
1275
+ async (newModel, oldModel) => {
1276
+ if (!props.noFormattingAsYouType && newModel && newModel !== oldModel) {
1277
+ const input = getPhoneNumberInput();
1278
+ if (input && !results.value.isValid && typeof selectionRange.start === "number" && !selectionRange.cursorAtEnd) {
1279
+ const start = selectionRange.start;
1280
+ const end = selectionRange.end;
1281
+ setTimeout(() => {
1282
+ input.setSelectionRange(start, end ?? start);
1283
+ }, 0);
1284
+ }
1285
+ }
1286
+ }
1287
+ );
1288
+ function setCountryCodeFromBrowserLocale() {
1289
+ const { locale } = browserLocale2();
1290
+ if (locale) {
1291
+ setCountryCode(locale);
1292
+ }
1293
+ }
1294
+ function updateResults(phoneNumber, countryCode2) {
1295
+ results.value = getResultsFromPhoneNumber2({
1296
+ phoneNumber,
1297
+ countryCode: countryCode2
1298
+ });
1299
+ }
1300
+ async function onInputValueChanged(phoneNumber) {
1301
+ const input = getPhoneNumberInput();
1302
+ selectionRange.start = input == null ? void 0 : input.selectionStart;
1303
+ selectionRange.end = input == null ? void 0 : input.selectionEnd;
1304
+ selectionRange.cursorAtEnd = selectionRange.start ? selectionRange.start >= phoneNumber.length : true;
1305
+ const sanitizedPhoneNumber = sanitizePhoneNumber2(phoneNumber);
1306
+ internalValue.value = sanitizedPhoneNumber;
1307
+ const newResults = getResultsFromPhoneNumber2({
1308
+ phoneNumber: sanitizedPhoneNumber,
1309
+ countryCode: countryCode.value
1310
+ });
1311
+ model.value = newResults.e164;
1312
+ }
1313
+ function onCountryChanged(codeCountry) {
1314
+ updateResults(inputValue.value, codeCountry);
1315
+ setCountryCode(codeCountry, true);
1316
+ }
1317
+ function setCountryCode(selectedCountryCode, autoFocusInput = false) {
1318
+ try {
1319
+ const countryAvailable = isCountryAvailable(selectedCountryCode);
1320
+ if (countryAvailable) {
1321
+ countryCode.value = selectedCountryCode;
1322
+ if (autoFocusInput) {
1323
+ focusPhoneNumberInput();
1324
+ }
1325
+ }
1326
+ } catch (error) {
1327
+ console.error(`[maz-ui](MazPhoneNumberInput) ${error}`);
1328
+ }
1329
+ }
1330
+ async function parseModel(newModel) {
1331
+ updateResults(newModel, countryCode.value);
1332
+ await nextTick();
1333
+ if (props.noFormattingAsYouType) {
1334
+ internalValue.value = inputValue.value;
1335
+ } else {
1336
+ asYouTypeFormatted.value = selectionRange.cursorAtEnd || results.value.isValid ? internalValue.value = getAsYouTypeFormat2(
1337
+ results.value.countryCode ?? countryCode.value,
1338
+ results.value.formatNational ?? internalValue.value
1339
+ ) : internalValue.value;
1340
+ }
1341
+ await nextTick();
1342
+ autoUpdateCountryCodeWithResults(results.value);
1343
+ }
1344
+ function autoUpdateCountryCodeWithResults(newResults) {
1345
+ if (newResults.countryCode && countryCode.value !== newResults.countryCode) {
1346
+ setCountryCode(newResults.countryCode);
1347
+ }
1348
+ }
1349
+ function getPhoneNumberInput() {
1350
+ var _a;
1351
+ return (_a = PhoneNumberInput.value) == null ? void 0 : _a.$el.querySelector("input");
1352
+ }
1353
+ function focusCountrySelector() {
1354
+ var _a, _b;
1355
+ (_b = (_a = CountrySelector.value) == null ? void 0 : _a.$el.querySelector("input")) == null ? void 0 : _b.focus();
1356
+ }
1357
+ async function focusPhoneNumberInput() {
1358
+ var _a;
1359
+ await nextTick();
1360
+ (_a = getPhoneNumberInput()) == null ? void 0 : _a.focus();
1361
+ }
1362
+ return (_ctx, _cache) => {
1363
+ var _a, _b;
1364
+ return openBlock(), createElementBlock("div", {
1365
+ id: unref(instanceId),
1366
+ class: normalizeClass(["m-phone-number-input", {
1367
+ "--no-flags": __props.noFlags
1368
+ }])
1369
+ }, [
1370
+ countryCode.value && !__props.noFlags && !__props.noCountrySelector ? (openBlock(), createElementBlock(
1371
+ "button",
1372
+ {
1373
+ key: 0,
1374
+ class: "m-phone-number-input__country-flag maz-text-xl",
1375
+ tabindex: "-1",
1376
+ type: "button",
1377
+ onClick: focusCountrySelector
1378
+ },
1379
+ toDisplayString(unref(localeToUnicodeFlag)(countryCode.value)),
1380
+ 1
1381
+ /* TEXT */
1382
+ )) : createCommentVNode("v-if", true),
1383
+ !__props.noCountrySelector && countryOptions.value ? (openBlock(), createBlock(MazSelect, {
1384
+ key: 1,
1385
+ ref_key: "CountrySelector",
1386
+ ref: CountrySelector,
1387
+ class: "m-phone-number-input__select",
1388
+ "model-value": countryCode.value,
1389
+ "option-value-key": "iso2",
1390
+ "option-label-key": "name",
1391
+ "option-input-value-key": "dialCode",
1392
+ "max-list-width": 250,
1393
+ disabled: __props.disabled,
1394
+ color: __props.color,
1395
+ size: __props.size,
1396
+ "list-position": __props.listPosition,
1397
+ search: !__props.noSearch,
1398
+ "search-placeholder": locales.value.countrySelector.searchPlaceholder,
1399
+ options: countryOptions.value,
1400
+ error: __props.error || !!inputValue.value && !countryCode.value,
1401
+ hint: !!inputValue.value && !countryCode.value ? locales.value.countrySelector.error : void 0,
1402
+ label: locales.value.countrySelector.placeholder,
1403
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => onCountryChanged($event)),
1404
+ onFocus: _cache[1] || (_cache[1] = ($event) => inputFocused.value = false)
1405
+ }, {
1406
+ default: withCtx(({ option, isSelected }) => [
1407
+ createElementVNode(
1408
+ "div",
1409
+ {
1410
+ class: normalizeClass(["m-phone-number-input__select__item maz-flex maz-items-center maz-truncate", {
1411
+ "m-phone-number-input__select__item--selected": isSelected
1412
+ }])
1413
+ },
1414
+ [
1415
+ !__props.noFlags && typeof option.iso2 === "string" ? (openBlock(), createElementBlock(
1416
+ "span",
1417
+ _hoisted_2,
1418
+ toDisplayString(unref(localeToUnicodeFlag)(option.iso2)),
1419
+ 1
1420
+ /* TEXT */
1421
+ )) : createCommentVNode("v-if", true),
1422
+ __props.showCodeOnList ? (openBlock(), createElementBlock(
1423
+ "span",
1424
+ {
1425
+ key: 1,
1426
+ class: normalizeClass(["maz-w-10 maz-flex-none", { "maz-text-muted": !isSelected }])
1427
+ },
1428
+ toDisplayString(option.dialCode),
1429
+ 3
1430
+ /* TEXT, CLASS */
1431
+ )) : createCommentVNode("v-if", true),
1432
+ createElementVNode(
1433
+ "span",
1434
+ {
1435
+ class: normalizeClass(["maz-flex-1 maz-truncate", { "maz-font-semibold": isSelected }])
1436
+ },
1437
+ toDisplayString(option.name),
1438
+ 3
1439
+ /* TEXT, CLASS */
1440
+ )
1441
+ ],
1442
+ 2
1443
+ /* CLASS */
1444
+ )
1445
+ ]),
1446
+ _: 1
1447
+ /* STABLE */
1448
+ }, 8, ["model-value", "disabled", "color", "size", "list-position", "search", "search-placeholder", "options", "error", "hint", "label"])) : createCommentVNode("v-if", true),
1449
+ createVNode(MazInput, mergeProps({
1450
+ id: __props.id,
1451
+ ref_key: "PhoneNumberInput",
1452
+ ref: PhoneNumberInput,
1453
+ "model-value": inputValue.value,
1454
+ label: inputPlaceholder.value,
1455
+ disabled: __props.disabled,
1456
+ color: __props.color,
1457
+ error: __props.error || !!inputValue.value && !((_a = results.value) == null ? void 0 : _a.isValid)
1458
+ }, _ctx.$attrs, {
1459
+ size: __props.size,
1460
+ "icon-name": "phone",
1461
+ type: "tel",
1462
+ clearable: "",
1463
+ class: ["m-phone-number-input__input maz-flex-1", {
1464
+ "--border-radius": !__props.noCountrySelector,
1465
+ "--error": __props.error || !((_b = results.value) == null ? void 0 : _b.isValid),
1466
+ "--focused": inputFocused.value
1467
+ }],
1468
+ onFocus: _cache[2] || (_cache[2] = ($event) => inputFocused.value = true),
1469
+ onBlur: _cache[3] || (_cache[3] = ($event) => inputFocused.value = false),
1470
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => onInputValueChanged($event))
1471
+ }), null, 16, ["id", "model-value", "label", "disabled", "color", "error", "size", "class"])
1472
+ ], 10, _hoisted_1);
1473
+ };
1474
+ }
1475
+ });
1476
+ const MazPhoneNumberInput_vue_vue_type_style_index_0_scoped_2cc88337_lang = "";
1477
+ const MazPhoneNumberInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2cc88337"]]);
1478
+ export {
1479
+ MazPhoneNumberInput as M,
1480
+ _export_sfc as _,
1481
+ useInstanceUniqId as u
1482
+ };