@volverjs/ui-vue 0.0.11 → 0.0.12

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 (55) hide show
  1. package/bin/icons.js +1 -93
  2. package/dist/components/VvAccordion/VvAccordion.es.js +1 -366
  3. package/dist/components/VvAccordionGroup/VvAccordionGroup.es.js +2 -702
  4. package/dist/components/VvAction/VvAction.es.js +1 -302
  5. package/dist/components/VvAlert/VvAlert.es.js +1 -527
  6. package/dist/components/VvAlertGroup/VvAlertGroup.es.js +1 -730
  7. package/dist/components/VvAvatar/VvAvatar.es.js +1 -132
  8. package/dist/components/VvAvatarGroup/VvAvatarGroup.es.js +1 -250
  9. package/dist/components/VvBadge/VvBadge.es.js +1 -131
  10. package/dist/components/VvBreadcrumb/VvBreadcrumb.es.js +1 -410
  11. package/dist/components/VvButton/VvButton.es.js +1 -882
  12. package/dist/components/VvButtonGroup/VvButtonGroup.es.js +1 -214
  13. package/dist/components/VvCard/VvCard.es.js +1 -152
  14. package/dist/components/VvCheckbox/VvCheckbox.es.js +1 -741
  15. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +1 -981
  16. package/dist/components/VvCombobox/VvCombobox.es.js +1 -3463
  17. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  18. package/dist/components/VvCombobox/VvCombobox.vue.d.ts +8 -1
  19. package/dist/components/VvDialog/VvDialog.es.js +1 -317
  20. package/dist/components/VvDropdown/VvDropdown.es.js +1 -750
  21. package/dist/components/VvDropdown/VvDropdownAction.vue.d.ts +2 -2
  22. package/dist/components/VvDropdown/VvDropdownOptgroup.vue.d.ts +9 -2
  23. package/dist/components/VvDropdownAction/VvDropdownAction.es.js +1 -448
  24. package/dist/components/VvDropdownItem/VvDropdownItem.es.js +1 -149
  25. package/dist/components/VvDropdownOptgroup/VvDropdownOptgroup.es.js +1 -104
  26. package/dist/components/VvDropdownOptgroup/VvDropdownOptgroup.umd.js +1 -1
  27. package/dist/components/VvDropdownOption/VvDropdownOption.es.js +1 -281
  28. package/dist/components/VvIcon/VvIcon.es.js +1 -143
  29. package/dist/components/VvInputFile/VvInputFile.es.js +1 -1704
  30. package/dist/components/VvInputText/VvInputText.es.js +4 -2790
  31. package/dist/components/VvNav/VvNav.es.js +1 -438
  32. package/dist/components/VvNavItem/VvNavItem.es.js +1 -337
  33. package/dist/components/VvNavSeparator/VvNavSeparator.es.js +1 -24
  34. package/dist/components/VvProgress/VvProgress.es.js +1 -163
  35. package/dist/components/VvRadio/VvRadio.es.js +1 -661
  36. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +1 -901
  37. package/dist/components/VvSelect/VvSelect.es.js +1 -1103
  38. package/dist/components/VvSelect/VvSelect.vue.d.ts +3 -1
  39. package/dist/components/VvTab/VvTab.es.js +1 -558
  40. package/dist/components/VvTextarea/VvTextarea.es.js +2 -1989
  41. package/dist/components/VvTooltip/VvTooltip.es.js +1 -154
  42. package/dist/components/index.es.js +6 -8558
  43. package/dist/components/index.umd.js +1 -1
  44. package/dist/composables/index.es.js +2 -247
  45. package/dist/composables/index.umd.js +1 -1
  46. package/dist/directives/index.es.js +2 -311
  47. package/dist/directives/index.umd.js +1 -1
  48. package/dist/directives/v-contextmenu.es.js +2 -142
  49. package/dist/directives/v-contextmenu.umd.js +1 -1
  50. package/dist/directives/v-tooltip.es.js +1 -172
  51. package/dist/icons.es.js +1 -39
  52. package/dist/icons.umd.js +1 -1
  53. package/dist/index.es.js +1 -219
  54. package/dist/resolvers/unplugin.es.js +1 -187
  55. package/package.json +33 -33
@@ -1,750 +1 @@
1
- import { computed, useId, defineComponent, h, Fragment, provide, unref, toRefs, useAttrs, ref, onMounted, watch, createElementBlock, openBlock, createVNode, withCtx, renderSlot, normalizeProps, guardReactiveProps, Transition, mergeProps, toHandlers, withDirectives, createElementVNode, normalizeClass, normalizeStyle, createCommentVNode, vShow, nextTick } from "vue";
2
- import { autoPlacement, flip, shift, size, offset, arrow, useFloating, autoUpdate } from "@floating-ui/vue";
3
- import { useMutationObserver, useVModel, onClickOutside, useFocusWithin, useElementHover, onKeyStroke } from "@vueuse/core";
4
- import mitt from "mitt";
5
- var StorageType = /* @__PURE__ */ ((StorageType2) => {
6
- StorageType2["local"] = "local";
7
- StorageType2["session"] = "session";
8
- return StorageType2;
9
- })(StorageType || {});
10
- var Strategy = /* @__PURE__ */ ((Strategy2) => {
11
- Strategy2["absolute"] = "absolute";
12
- Strategy2["fixed"] = "fixed";
13
- return Strategy2;
14
- })(Strategy || {});
15
- var Side = /* @__PURE__ */ ((Side2) => {
16
- Side2["left"] = "left";
17
- Side2["right"] = "right";
18
- Side2["top"] = "top";
19
- Side2["bottom"] = "bottom";
20
- return Side2;
21
- })(Side || {});
22
- var Placement = /* @__PURE__ */ ((Placement2) => {
23
- Placement2["topStart"] = "top-start";
24
- Placement2["topEnd"] = "top-end";
25
- Placement2["bottomStart"] = "bottom-start";
26
- Placement2["bottomEnd"] = "bottom-end";
27
- Placement2["leftStart"] = "left-start";
28
- Placement2["leftEnd"] = "left-end";
29
- Placement2["rightStart"] = "right-start";
30
- Placement2["rightEnd"] = "right-end";
31
- return Placement2;
32
- })(Placement || {});
33
- var Position = /* @__PURE__ */ ((Position2) => {
34
- Position2["before"] = "before";
35
- Position2["after"] = "after";
36
- return Position2;
37
- })(Position || {});
38
- var ButtonType = /* @__PURE__ */ ((ButtonType2) => {
39
- ButtonType2["button"] = "button";
40
- ButtonType2["submit"] = "submit";
41
- ButtonType2["reset"] = "reset";
42
- return ButtonType2;
43
- })(ButtonType || {});
44
- var ActionTag = /* @__PURE__ */ ((ActionTag2) => {
45
- ActionTag2["nuxtLink"] = "nuxt-link";
46
- ActionTag2["routerLink"] = "router-link";
47
- ActionTag2["a"] = "a";
48
- ActionTag2["button"] = "button";
49
- return ActionTag2;
50
- })(ActionTag || {});
51
- var DropdownRole = /* @__PURE__ */ ((DropdownRole2) => {
52
- DropdownRole2["listbox"] = "listbox";
53
- DropdownRole2["menu"] = "menu";
54
- return DropdownRole2;
55
- })(DropdownRole || {});
56
- var DropdownItemRole = /* @__PURE__ */ ((DropdownItemRole2) => {
57
- DropdownItemRole2["option"] = "option";
58
- DropdownItemRole2["presentation"] = "presentation";
59
- return DropdownItemRole2;
60
- })(DropdownItemRole || {});
61
- const INJECTION_KEY_DROPDOWN_TRIGGER = Symbol.for(
62
- "dropdownTrigger"
63
- );
64
- const INJECTION_KEY_DROPDOWN_ITEM = Symbol.for(
65
- "dropdownItem"
66
- );
67
- const ModifiersProps = {
68
- /**
69
- * Component BEM modifiers
70
- */
71
- modifiers: {
72
- type: [String, Array],
73
- default: void 0
74
- }
75
- };
76
- ({
77
- /**
78
- * VvIcon position
79
- */
80
- iconPosition: {
81
- default: Position.before
82
- }
83
- });
84
- const IdProps = {
85
- /**
86
- * Global attribute id
87
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
88
- */
89
- id: [String, Number]
90
- };
91
- const DropdownProps = {
92
- /**
93
- * Dropdown placement
94
- */
95
- placement: {
96
- type: String,
97
- default: Side.bottom,
98
- validator: (value) => Object.values(Side).includes(value) || Object.values(Placement).includes(value)
99
- },
100
- /**
101
- * Dropdown strategy
102
- */
103
- strategy: {
104
- type: String,
105
- default: void 0,
106
- validator: (value) => Object.values(Strategy).includes(value)
107
- },
108
- /**
109
- * Dropdown show / hide transition name
110
- */
111
- transitionName: {
112
- type: String,
113
- default: void 0
114
- },
115
- /**
116
- * Offset of the dropdown from the trigger
117
- * @see https://floating-ui.com/docs/offset
118
- */
119
- offset: {
120
- type: [Number, String, Object],
121
- default: 0
122
- },
123
- /**
124
- * Move dropdown to the side if there is no space in the default position
125
- * @see https://floating-ui.com/docs/shift
126
- */
127
- shift: {
128
- type: [Boolean, Object],
129
- default: false
130
- },
131
- /**
132
- * Flip dropdown position if there is no space in the default position
133
- * @see https://floating-ui.com/docs/flip
134
- */
135
- flip: {
136
- type: [Boolean, Object],
137
- default: true
138
- },
139
- /**
140
- * Size of the dropdown
141
- * @see https://floating-ui.com/docs/size
142
- */
143
- size: {
144
- type: [Boolean, Object],
145
- default: () => ({ padding: 10 })
146
- },
147
- /**
148
- * Automatically change the position of the dropdown
149
- * @see https://floating-ui.com/docs/autoPlacement
150
- */
151
- autoPlacement: {
152
- type: [Boolean, Object],
153
- default: false
154
- },
155
- /**
156
- * Add arrow to the dropdown
157
- * @see https://floating-ui.com/docs/arrow
158
- */
159
- arrow: {
160
- type: Boolean,
161
- default: false
162
- },
163
- /**
164
- * Keep open dropdown on click outside
165
- */
166
- keepOpen: {
167
- type: Boolean,
168
- default: false
169
- },
170
- /**
171
- * Autofocus first item on dropdown open
172
- */
173
- autofocusFirst: {
174
- type: Boolean,
175
- default: true
176
- },
177
- /**
178
- * Set dropdown width to the same as the trigger
179
- */
180
- triggerWidth: {
181
- type: Boolean,
182
- default: false
183
- }
184
- };
185
- ({
186
- /**
187
- * Button type
188
- */
189
- type: {
190
- default: ButtonType.button
191
- },
192
- /**
193
- * Default tag for the action
194
- */
195
- defaultTag: {
196
- default: ActionTag.button
197
- }
198
- });
199
- ({
200
- storageType: {
201
- default: StorageType.local
202
- }
203
- });
204
- const VvDropdownProps = {
205
- ...IdProps,
206
- ...DropdownProps,
207
- ...ModifiersProps,
208
- /**
209
- * Show / hide dropdown programmatically
210
- */
211
- modelValue: {
212
- type: Boolean,
213
- default: void 0
214
- },
215
- /**
216
- * Dropdown trigger element
217
- */
218
- reference: {
219
- type: Object,
220
- default: null
221
- },
222
- /**
223
- * Dropdown role
224
- */
225
- role: {
226
- type: String,
227
- default: DropdownRole.menu,
228
- validator: (value) => Object.values(DropdownRole).includes(value)
229
- }
230
- };
231
- function useUniqueId(id) {
232
- return computed(() => String(id?.value || useId()));
233
- }
234
- function useDropdownProvideTrigger({
235
- reference,
236
- id,
237
- expanded,
238
- aria
239
- }) {
240
- const bus = mitt();
241
- const component = defineComponent({
242
- name: "VvDropdownTriggerProvider",
243
- setup() {
244
- provide(INJECTION_KEY_DROPDOWN_TRIGGER, {
245
- reference,
246
- id,
247
- expanded,
248
- aria,
249
- bus
250
- });
251
- },
252
- render() {
253
- return h(Fragment, {}, this.$slots.default?.());
254
- }
255
- });
256
- return {
257
- bus,
258
- component
259
- };
260
- }
261
- function useDropdownProvideItem({
262
- role,
263
- ...others
264
- }) {
265
- const itemRole = computed(
266
- () => role.value === DropdownRole.listbox ? DropdownItemRole.option : DropdownItemRole.presentation
267
- );
268
- provide(INJECTION_KEY_DROPDOWN_ITEM, {
269
- role: itemRole,
270
- ...others
271
- });
272
- return { itemRole };
273
- }
274
- function useModifiers(prefix, modifiers, others) {
275
- return computed(() => {
276
- const toReturn = {
277
- [prefix]: true
278
- };
279
- const modifiersArray = typeof modifiers?.value === "string" ? modifiers.value.split(" ") : modifiers?.value;
280
- if (modifiersArray) {
281
- if (Array.isArray(modifiersArray)) {
282
- modifiersArray.forEach((modifier) => {
283
- if (modifier) {
284
- toReturn[`${prefix}--${modifier}`] = true;
285
- }
286
- });
287
- }
288
- }
289
- if (others) {
290
- Object.keys(others.value).forEach((key) => {
291
- toReturn[`${prefix}--${key}`] = unref(others.value[key]);
292
- });
293
- }
294
- return toReturn;
295
- });
296
- }
297
- const _hoisted_1 = ["id", "tabindex", "role", "aria-labelledby"];
298
- const __default__ = {
299
- name: "VvDropdown",
300
- inheritAttrs: false
301
- };
302
- const _sfc_main = /* @__PURE__ */ defineComponent({
303
- ...__default__,
304
- props: VvDropdownProps,
305
- emits: [
306
- "update:modelValue",
307
- "beforeEnter",
308
- "afterLeave",
309
- "beforeExpand",
310
- "beforeCollapse",
311
- "afterExpand",
312
- "afterCollapse",
313
- "before-enter",
314
- "after-leave",
315
- "enter",
316
- "afterEnter",
317
- "enterCancelled",
318
- "beforeLeave",
319
- "leave",
320
- "leaveCancelled"
321
- ],
322
- setup(__props, { expose: __expose, emit: __emit }) {
323
- const props = __props;
324
- const emit = __emit;
325
- const { id } = toRefs(props);
326
- const hasId = useUniqueId(id);
327
- const attrs = useAttrs();
328
- const maxWidth = ref("auto");
329
- const maxHeight = ref("auto");
330
- const localReferenceEl = ref();
331
- const floatingEl = ref();
332
- const arrowEl = ref();
333
- const listEl = ref();
334
- const referenceEl = computed({
335
- get: () => props.reference ?? localReferenceEl.value,
336
- set: (newValue) => {
337
- localReferenceEl.value = newValue;
338
- }
339
- });
340
- const hasCustomPosition = ref(false);
341
- onMounted(() => {
342
- useMutationObserver(
343
- floatingEl.value,
344
- () => {
345
- hasCustomPosition.value = window.getComputedStyle(floatingEl.value).getPropertyValue("--dropdown-custom-position")?.trim() === "true";
346
- },
347
- {
348
- attributeFilter: ["style"],
349
- window
350
- }
351
- );
352
- });
353
- const middleware = computed(() => {
354
- const toReturn = [];
355
- if (props.autoPlacement) {
356
- if (typeof props.autoPlacement === "boolean") {
357
- toReturn.push(autoPlacement());
358
- } else {
359
- toReturn.push(
360
- autoPlacement(props.autoPlacement)
361
- );
362
- }
363
- } else if (props.flip) {
364
- if (typeof props.flip === "boolean") {
365
- toReturn.push(flip({ fallbackStrategy: "initialPlacement" }));
366
- } else {
367
- toReturn.push(flip(props.flip));
368
- }
369
- }
370
- if (props.shift) {
371
- if (typeof props.shift === "boolean") {
372
- toReturn.push(shift());
373
- } else {
374
- toReturn.push(shift(props.shift));
375
- }
376
- }
377
- if (props.size) {
378
- const apply = ({
379
- availableWidth,
380
- availableHeight
381
- }) => {
382
- maxWidth.value = `${availableWidth}px`;
383
- maxHeight.value = `${availableHeight}px`;
384
- };
385
- if (typeof props.size === "boolean") {
386
- toReturn.push(
387
- size({
388
- apply
389
- })
390
- );
391
- } else {
392
- toReturn.push(
393
- size({
394
- ...props.size,
395
- apply
396
- })
397
- );
398
- }
399
- }
400
- if (props.offset) {
401
- toReturn.push(offset(Number(props.offset)));
402
- if (["string", "number"].includes(typeof props.offset)) {
403
- toReturn.push(offset(Number(props.offset)));
404
- } else {
405
- toReturn.push(offset(props.offset));
406
- }
407
- }
408
- if (props.arrow) {
409
- toReturn.push(
410
- arrow({
411
- element: arrowEl
412
- })
413
- );
414
- }
415
- return toReturn;
416
- });
417
- const { x, y, middlewareData, placement, strategy } = useFloating(
418
- referenceEl,
419
- floatingEl,
420
- {
421
- whileElementsMounted: (...args) => {
422
- return autoUpdate(...args, {
423
- animationFrame: props.strategy === Strategy.fixed
424
- });
425
- },
426
- placement: computed(() => props.placement),
427
- strategy: computed(() => props.strategy),
428
- middleware
429
- }
430
- );
431
- const dropdownPlacement = computed(() => {
432
- if (hasCustomPosition.value) {
433
- return void 0;
434
- }
435
- const width = props.triggerWidth && referenceEl.value ? `${referenceEl.value?.offsetWidth}px` : void 0;
436
- return {
437
- position: strategy.value,
438
- top: `${y.value ?? 0}px`,
439
- left: `${x.value ?? 0}px`,
440
- maxWidth: width ? void 0 : maxWidth.value,
441
- maxHeight: maxHeight.value,
442
- width
443
- };
444
- });
445
- const side = computed(
446
- () => placement.value.split("-")[0]
447
- );
448
- const arrowPlacement = computed(() => {
449
- if (hasCustomPosition.value) {
450
- return void 0;
451
- }
452
- const staticSide = {
453
- [Side.top]: Side.bottom,
454
- [Side.right]: Side.left,
455
- [Side.bottom]: Side.top,
456
- [Side.left]: Side.right
457
- }[side.value];
458
- return {
459
- left: middlewareData.value.arrow?.x !== void 0 ? `${middlewareData.value.arrow?.x}px` : void 0,
460
- top: middlewareData.value.arrow?.y !== void 0 ? `${middlewareData.value.arrow?.y}px` : void 0,
461
- [staticSide]: `${-(arrowEl.value?.offsetWidth ?? 0) / 2}px`
462
- };
463
- });
464
- const modelValue = useVModel(props, "modelValue", emit);
465
- const localModelValue = ref(false);
466
- const expanded = computed({
467
- get: () => modelValue.value ?? localModelValue.value,
468
- set: (newValue) => {
469
- if (modelValue.value === void 0) {
470
- localModelValue.value = newValue;
471
- return;
472
- }
473
- modelValue.value = newValue;
474
- }
475
- });
476
- function show() {
477
- expanded.value = true;
478
- }
479
- function hide() {
480
- expanded.value = false;
481
- }
482
- function toggle() {
483
- expanded.value = !expanded.value;
484
- }
485
- function init(el) {
486
- referenceEl.value = el;
487
- }
488
- onClickOutside(
489
- floatingEl,
490
- () => {
491
- if (!props.keepOpen && expanded.value) {
492
- expanded.value = false;
493
- }
494
- },
495
- { ignore: [referenceEl] }
496
- );
497
- const hasAriaLabelledby = computed(() => {
498
- return referenceEl.value?.getAttribute?.("id") ?? void 0;
499
- });
500
- const referenceAria = computed(() => ({
501
- "aria-controls": hasId.value,
502
- "aria-haspopup": true,
503
- "aria-expanded": expanded.value
504
- }));
505
- const { component: VvDropdownTriggerProvider, bus } = useDropdownProvideTrigger({
506
- reference: referenceEl,
507
- id: hasId,
508
- expanded,
509
- aria: referenceAria
510
- });
511
- bus.on("click", toggle);
512
- const { role, modifiers } = toRefs(props);
513
- const bemCssClasses = useModifiers(
514
- "vv-dropdown",
515
- modifiers,
516
- computed(() => ({
517
- arrow: props.arrow
518
- }))
519
- );
520
- const { focused } = useFocusWithin(floatingEl);
521
- function getKeyboardFocusableElements(element) {
522
- if (!element) {
523
- return [];
524
- }
525
- return [
526
- ...element.querySelectorAll(
527
- 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])'
528
- )
529
- ].filter(
530
- (el) => !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden")
531
- );
532
- }
533
- function focusFirst() {
534
- nextTick(() => {
535
- const focusableElements = getKeyboardFocusableElements(
536
- floatingEl.value
537
- );
538
- if (focusableElements.length > 0) {
539
- focusableElements[0].focus({
540
- preventScroll: true
541
- });
542
- }
543
- });
544
- }
545
- function focusFirstListElement() {
546
- nextTick(() => {
547
- const focusableElements = getKeyboardFocusableElements(
548
- listEl.value
549
- );
550
- if (focusableElements.length > 0) {
551
- focusableElements[0].focus({
552
- preventScroll: true
553
- });
554
- }
555
- });
556
- }
557
- function focusNext() {
558
- nextTick(() => {
559
- if (focused.value) {
560
- const focusableElements = getKeyboardFocusableElements(
561
- floatingEl.value
562
- );
563
- if (focusableElements.length === 0 || !document.activeElement) {
564
- return;
565
- }
566
- const activeElementIndex = focusableElements.indexOf(
567
- document.activeElement
568
- );
569
- if (activeElementIndex < focusableElements.length - 1) {
570
- focusableElements[activeElementIndex + 1].focus({
571
- preventScroll: true
572
- });
573
- } else {
574
- focusableElements[0].focus({
575
- preventScroll: true
576
- });
577
- }
578
- }
579
- });
580
- }
581
- function focusPrev() {
582
- nextTick(() => {
583
- if (focused.value) {
584
- const focusableElements = getKeyboardFocusableElements(
585
- floatingEl.value
586
- );
587
- if (focusableElements.length === 0 || !document.activeElement) {
588
- return;
589
- }
590
- const activeElementIndex = focusableElements.indexOf(
591
- document.activeElement
592
- );
593
- if (activeElementIndex > 0) {
594
- focusableElements[activeElementIndex - 1].focus({
595
- preventScroll: true
596
- });
597
- } else {
598
- focusableElements[focusableElements.length - 1].focus({
599
- preventScroll: true
600
- });
601
- }
602
- }
603
- });
604
- }
605
- watch(expanded, (newValue) => {
606
- if (newValue && props.autofocusFirst) {
607
- focusFirst();
608
- }
609
- });
610
- __expose({
611
- toggle,
612
- show,
613
- hide,
614
- init,
615
- focusFirst,
616
- focusFirstListElement,
617
- focusNext,
618
- focusPrev,
619
- customPosition: hasCustomPosition
620
- });
621
- const hovered = useElementHover(floatingEl);
622
- const { itemRole } = useDropdownProvideItem({
623
- role,
624
- expanded,
625
- focused,
626
- hovered
627
- });
628
- onKeyStroke("Escape", (e) => {
629
- if (expanded.value) {
630
- e.preventDefault();
631
- hide();
632
- }
633
- });
634
- onKeyStroke("ArrowDown", (e) => {
635
- if (expanded.value && focused.value) {
636
- e.preventDefault();
637
- focusNext();
638
- }
639
- });
640
- onKeyStroke("ArrowUp", (e) => {
641
- if (expanded.value && focused.value) {
642
- e.preventDefault();
643
- focusPrev();
644
- }
645
- });
646
- onKeyStroke([" ", "Enter"], (e) => {
647
- const htmlEl = e.target;
648
- if (expanded.value && focused.value && htmlEl) {
649
- htmlEl?.click();
650
- }
651
- });
652
- const dropdownTransitionHandlers = {
653
- "before-enter": () => {
654
- emit(expanded.value ? "beforeExpand" : "beforeCollapse");
655
- emit("beforeEnter");
656
- },
657
- "after-leave": () => {
658
- emit(expanded.value ? "afterExpand" : "afterCollapse");
659
- emit("afterLeave");
660
- },
661
- "enter": () => {
662
- emit("enter");
663
- },
664
- "after-enter": () => {
665
- emit("afterEnter");
666
- },
667
- "enter-cancelled": () => {
668
- emit("enterCancelled");
669
- },
670
- "before-leave": () => {
671
- emit("beforeLeave");
672
- },
673
- "leave": () => {
674
- emit("leave");
675
- },
676
- "leave-cancelled": () => {
677
- emit("leaveCancelled");
678
- }
679
- };
680
- return (_ctx, _cache) => {
681
- return openBlock(), createElementBlock(
682
- Fragment,
683
- null,
684
- [
685
- createVNode(unref(VvDropdownTriggerProvider), null, {
686
- default: withCtx(() => [
687
- renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({ init, show, hide, toggle, expanded: unref(expanded), aria: unref(referenceAria) })))
688
- ]),
689
- _: 3
690
- /* FORWARDED */
691
- }),
692
- createVNode(Transition, mergeProps({ name: _ctx.transitionName }, toHandlers(dropdownTransitionHandlers), { persisted: "" }), {
693
- default: withCtx(() => [
694
- withDirectives(createElementVNode(
695
- "div",
696
- {
697
- ref_key: "floatingEl",
698
- ref: floatingEl,
699
- style: normalizeStyle(unref(dropdownPlacement)),
700
- class: normalizeClass(unref(bemCssClasses))
701
- },
702
- [
703
- props.arrow ? (openBlock(), createElementBlock(
704
- "div",
705
- {
706
- key: 0,
707
- ref_key: "arrowEl",
708
- ref: arrowEl,
709
- style: normalizeStyle(unref(arrowPlacement)),
710
- class: "vv-dropdown__arrow"
711
- },
712
- null,
713
- 4
714
- /* STYLE */
715
- )) : createCommentVNode("v-if", true),
716
- renderSlot(_ctx.$slots, "before", normalizeProps(guardReactiveProps({ expanded: unref(expanded) }))),
717
- createElementVNode("div", mergeProps(unref(attrs), {
718
- id: unref(hasId),
719
- ref_key: "listEl",
720
- ref: listEl,
721
- tabindex: !unref(expanded) ? -1 : void 0,
722
- role: unref(role),
723
- "aria-labelledby": unref(hasAriaLabelledby),
724
- class: "vv-dropdown__list"
725
- }), [
726
- renderSlot(_ctx.$slots, "items", normalizeProps(guardReactiveProps({
727
- role: unref(itemRole)
728
- })))
729
- ], 16, _hoisted_1),
730
- renderSlot(_ctx.$slots, "after", normalizeProps(guardReactiveProps({ expanded: unref(expanded) })))
731
- ],
732
- 6
733
- /* CLASS, STYLE */
734
- ), [
735
- [vShow, unref(expanded)]
736
- ])
737
- ]),
738
- _: 3
739
- /* FORWARDED */
740
- }, 16, ["name"])
741
- ],
742
- 64
743
- /* STABLE_FRAGMENT */
744
- );
745
- };
746
- }
747
- });
748
- export {
749
- _sfc_main as default
750
- };
1
+ import{computed as e,useId as t,defineComponent as o,h as a,Fragment as l,provide as r,unref as n,toRefs as u,useAttrs as i,ref as s,onMounted as f,watch as d,createElementBlock as p,openBlock as v,createVNode as c,withCtx as b,renderSlot as m,normalizeProps as g,guardReactiveProps as h,Transition as y,mergeProps as x,toHandlers as w,withDirectives as E,createElementVNode as S,normalizeClass as $,normalizeStyle as O,createCommentVNode as k,vShow as j,nextTick as A}from"vue";import{autoPlacement as B,flip as C,shift as P,size as _,offset as D,arrow as L,useFloating as N,autoUpdate as F}from"@floating-ui/vue";import{useMutationObserver as V,useVModel as W,onClickOutside as z,useFocusWithin as H,useElementHover as R,onKeyStroke as T}from"@vueuse/core";import q from"mitt";var I=/* @__PURE__ */(e=>(e.local="local",e.session="session",e))(I||{}),M=/* @__PURE__ */(e=>(e.absolute="absolute",e.fixed="fixed",e))(M||{}),U=/* @__PURE__ */(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(U||{}),G=/* @__PURE__ */(e=>(e.topStart="top-start",e.topEnd="top-end",e.bottomStart="bottom-start",e.bottomEnd="bottom-end",e.leftStart="left-start",e.leftEnd="left-end",e.rightStart="right-start",e.rightEnd="right-end",e))(G||{}),J=/* @__PURE__ */(e=>(e.before="before",e.after="after",e))(J||{}),K=/* @__PURE__ */(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(K||{}),Q=/* @__PURE__ */(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(Q||{}),X=/* @__PURE__ */(e=>(e.listbox="listbox",e.menu="menu",e))(X||{}),Y=/* @__PURE__ */(e=>(e.option="option",e.presentation="presentation",e))(Y||{});const Z=Symbol.for("dropdownTrigger"),ee=Symbol.for("dropdownItem"),te={modifiers:{type:[String,Array],default:void 0}};J.before;const oe={id:[String,Number]},ae={placement:{type:String,default:U.bottom,validator:e=>Object.values(U).includes(e)||Object.values(G).includes(e)},strategy:{type:String,default:void 0,validator:e=>Object.values(M).includes(e)},transitionName:{type:String,default:void 0},offset:{type:[Number,String,Object],default:0},shift:{type:[Boolean,Object],default:!1},flip:{type:[Boolean,Object],default:!0},size:{type:[Boolean,Object],default:()=>({padding:10})},autoPlacement:{type:[Boolean,Object],default:!1},arrow:{type:Boolean,default:!1},keepOpen:{type:Boolean,default:!1},autofocusFirst:{type:Boolean,default:!0},triggerWidth:{type:Boolean,default:!1}};K.button,Q.button,I.local;const le={...oe,...ae,...te,modelValue:{type:Boolean,default:void 0},reference:{type:Object,default:null},role:{type:String,default:X.menu,validator:e=>Object.values(X).includes(e)}};const re=["id","tabindex","role","aria-labelledby"],ne=/* @__PURE__ */o({name:"VvDropdown",inheritAttrs:!1,props:le,emits:["update:modelValue","beforeEnter","afterLeave","beforeExpand","beforeCollapse","afterExpand","afterCollapse","before-enter","after-leave","enter","afterEnter","enterCancelled","beforeLeave","leave","leaveCancelled"],setup(I,{expose:G,emit:J}){const K=I,Q=J,{id:te}=u(K),oe=function(o){return e(()=>String(o?.value||t()))}(te),ae=i(),le=s("auto"),ne=s("auto"),ue=s(),ie=s(),se=s(),fe=s(),de=e({get:()=>K.reference??ue.value,set:e=>{ue.value=e}}),pe=s(!1);f(()=>{V(ie.value,()=>{pe.value="true"===window.getComputedStyle(ie.value).getPropertyValue("--dropdown-custom-position")?.trim()},{attributeFilter:["style"],window:window})});const ve=e(()=>{const e=[];if(K.autoPlacement?"boolean"==typeof K.autoPlacement?e.push(B()):e.push(B(K.autoPlacement)):K.flip&&("boolean"==typeof K.flip?e.push(C({fallbackStrategy:"initialPlacement"})):e.push(C(K.flip))),K.shift&&("boolean"==typeof K.shift?e.push(P()):e.push(P(K.shift))),K.size){const t=({availableWidth:e,availableHeight:t})=>{le.value=`${e}px`,ne.value=`${t}px`};"boolean"==typeof K.size?e.push(_({apply:t})):e.push(_({...K.size,apply:t}))}return K.offset&&(e.push(D(Number(K.offset))),["string","number"].includes(typeof K.offset)?e.push(D(Number(K.offset))):e.push(D(K.offset))),K.arrow&&e.push(L({element:se})),e}),{x:ce,y:be,middlewareData:me,placement:ge,strategy:he}=N(de,ie,{whileElementsMounted:(...e)=>F(...e,{animationFrame:K.strategy===M.fixed}),placement:e(()=>K.placement),strategy:e(()=>K.strategy),middleware:ve}),ye=e(()=>{if(pe.value)return;const e=K.triggerWidth&&de.value?`${de.value?.offsetWidth}px`:void 0;return{position:he.value,top:`${be.value??0}px`,left:`${ce.value??0}px`,maxWidth:e?void 0:le.value,maxHeight:ne.value,width:e}}),xe=e(()=>ge.value.split("-")[0]),we=e(()=>{if(pe.value)return;const e={[U.top]:U.bottom,[U.right]:U.left,[U.bottom]:U.top,[U.left]:U.right}[xe.value];return{left:void 0!==me.value.arrow?.x?`${me.value.arrow?.x}px`:void 0,top:void 0!==me.value.arrow?.y?`${me.value.arrow?.y}px`:void 0,[e]:-(se.value?.offsetWidth??0)/2+"px"}}),Ee=W(K,"modelValue",Q),Se=s(!1),$e=e({get:()=>Ee.value??Se.value,set:e=>{void 0!==Ee.value?Ee.value=e:Se.value=e}});function Oe(){$e.value=!0}function ke(){$e.value=!1}function je(){$e.value=!$e.value}function Ae(e){de.value=e}z(ie,()=>{!K.keepOpen&&$e.value&&($e.value=!1)},{ignore:[de]});const Be=e(()=>de.value?.getAttribute?.("id")??void 0),Ce=e(()=>({"aria-controls":oe.value,"aria-haspopup":!0,"aria-expanded":$e.value})),{component:Pe,bus:_e}=function({reference:e,id:t,expanded:n,aria:u}){const i=q(),s=o({name:"VvDropdownTriggerProvider",setup(){r(Z,{reference:e,id:t,expanded:n,aria:u,bus:i})},render(){return a(l,{},this.$slots.default?.())}});return{bus:i,component:s}}({reference:de,id:oe,expanded:$e,aria:Ce});_e.on("click",je);const{role:De,modifiers:Le}=u(K),Ne=function(t,o,a){return e(()=>{const e={[t]:!0},l="string"==typeof o?.value?o.value.split(" "):o?.value;return l&&Array.isArray(l)&&l.forEach(o=>{o&&(e[`${t}--${o}`]=!0)}),a&&Object.keys(a.value).forEach(o=>{e[`${t}--${o}`]=n(a.value[o])}),e})}("vv-dropdown",Le,e(()=>({arrow:K.arrow}))),{focused:Fe}=H(ie);function Ve(e){return e?[...e.querySelectorAll('a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])')].filter(e=>!e.hasAttribute("disabled")&&!e.getAttribute("aria-hidden")):[]}function We(){A(()=>{const e=Ve(ie.value);e.length>0&&e[0].focus({preventScroll:!0})})}function ze(){A(()=>{if(Fe.value){const e=Ve(ie.value);if(0===e.length||!document.activeElement)return;const t=e.indexOf(document.activeElement);t<e.length-1?e[t+1].focus({preventScroll:!0}):e[0].focus({preventScroll:!0})}})}function He(){A(()=>{if(Fe.value){const e=Ve(ie.value);if(0===e.length||!document.activeElement)return;const t=e.indexOf(document.activeElement);t>0?e[t-1].focus({preventScroll:!0}):e[e.length-1].focus({preventScroll:!0})}})}d($e,e=>{e&&K.autofocusFirst&&We()}),G({toggle:je,show:Oe,hide:ke,init:Ae,focusFirst:We,focusFirstListElement:function(){A(()=>{const e=Ve(fe.value);e.length>0&&e[0].focus({preventScroll:!0})})},focusNext:ze,focusPrev:He,customPosition:pe});const Re=R(ie),{itemRole:Te}=function({role:t,...o}){const a=e(()=>t.value===X.listbox?Y.option:Y.presentation);return r(ee,{role:a,...o}),{itemRole:a}}({role:De,expanded:$e,focused:Fe,hovered:Re});T("Escape",e=>{$e.value&&(e.preventDefault(),ke())}),T("ArrowDown",e=>{$e.value&&Fe.value&&(e.preventDefault(),ze())}),T("ArrowUp",e=>{$e.value&&Fe.value&&(e.preventDefault(),He())}),T([" ","Enter"],e=>{const t=e.target;$e.value&&Fe.value&&t&&t?.click()});const qe={"before-enter":()=>{Q($e.value?"beforeExpand":"beforeCollapse"),Q("beforeEnter")},"after-leave":()=>{Q($e.value?"afterExpand":"afterCollapse"),Q("afterLeave")},enter:()=>{Q("enter")},"after-enter":()=>{Q("afterEnter")},"enter-cancelled":()=>{Q("enterCancelled")},"before-leave":()=>{Q("beforeLeave")},leave:()=>{Q("leave")},"leave-cancelled":()=>{Q("leaveCancelled")}};return(e,t)=>(v(),p(l,null,[c(n(Pe),null,{default:b(()=>[m(e.$slots,"default",g(h({init:Ae,show:Oe,hide:ke,toggle:je,expanded:n($e),aria:n(Ce)})))]),_:3}),c(y,x({name:e.transitionName},w(qe),{persisted:""}),{default:b(()=>[E(S("div",{ref_key:"floatingEl",ref:ie,style:O(n(ye)),class:$(n(Ne))},[K.arrow?(v(),p("div",{key:0,ref_key:"arrowEl",ref:se,style:O(n(we)),class:"vv-dropdown__arrow"},null,4)):k("v-if",!0),m(e.$slots,"before",g(h({expanded:n($e)}))),S("div",x(n(ae),{id:n(oe),ref_key:"listEl",ref:fe,tabindex:n($e)?void 0:-1,role:n(De),"aria-labelledby":n(Be),class:"vv-dropdown__list"}),[m(e.$slots,"items",g(h({role:n(Te)})))],16,re),m(e.$slots,"after",g(h({expanded:n($e)})))],6),[[j,n($e)]])]),_:3},16,["name"])],64))}});export{ne as default};