mood-ui 0.14.1 → 0.15.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 (171) hide show
  1. package/README.md +1 -1
  2. package/dist/components/data-display/table/Table.cjs +1 -1
  3. package/dist/components/data-display/table/Table.cjs.map +1 -1
  4. package/dist/components/data-display/table/Table.mjs +1 -1
  5. package/dist/components/data-display/table/Table.mjs.map +1 -1
  6. package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.cjs +37 -1
  7. package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  8. package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.mjs +38 -2
  9. package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  10. package/dist/components/data-display/table/TablePagination.cjs.map +1 -1
  11. package/dist/components/data-display/table/TablePagination.mjs.map +1 -1
  12. package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.cjs +24 -16
  13. package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  14. package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.mjs +24 -16
  15. package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  16. package/dist/components/feedback/EmptyState.cjs.map +1 -1
  17. package/dist/components/feedback/EmptyState.mjs.map +1 -1
  18. package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.cjs +1 -1
  19. package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  20. package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.mjs +1 -1
  21. package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  22. package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.cjs +369 -0
  23. package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
  24. package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.mjs +368 -0
  25. package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
  26. package/dist/components/feedback/tour/Tour2.cjs +6 -0
  27. package/dist/components/feedback/tour/Tour2.cjs.map +1 -0
  28. package/dist/components/feedback/tour/Tour2.mjs +7 -0
  29. package/dist/components/feedback/tour/Tour2.mjs.map +1 -0
  30. package/dist/components/feedback/tour/TourCard.cjs +6 -0
  31. package/dist/components/feedback/tour/TourCard.cjs.map +1 -0
  32. package/dist/components/feedback/tour/TourCard.mjs +7 -0
  33. package/dist/components/feedback/tour/TourCard.mjs.map +1 -0
  34. package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.cjs +102 -0
  35. package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
  36. package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.mjs +101 -0
  37. package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
  38. package/dist/components/feedback/tour/tourAnchor.cjs +75 -0
  39. package/dist/components/feedback/tour/tourAnchor.cjs.map +1 -0
  40. package/dist/components/feedback/tour/tourAnchor.mjs +72 -0
  41. package/dist/components/feedback/tour/tourAnchor.mjs.map +1 -0
  42. package/dist/components/feedback/tour/tourPlace.cjs +108 -0
  43. package/dist/components/feedback/tour/tourPlace.cjs.map +1 -0
  44. package/dist/components/feedback/tour/tourPlace.mjs +107 -0
  45. package/dist/components/feedback/tour/tourPlace.mjs.map +1 -0
  46. package/dist/components/feedback/tour/tourShape.cjs +121 -0
  47. package/dist/components/feedback/tour/tourShape.cjs.map +1 -0
  48. package/dist/components/feedback/tour/tourShape.mjs +118 -0
  49. package/dist/components/feedback/tour/tourShape.mjs.map +1 -0
  50. package/dist/components/feedback/tour/useTourSpotlight.cjs +60 -0
  51. package/dist/components/feedback/tour/useTourSpotlight.cjs.map +1 -0
  52. package/dist/components/feedback/tour/useTourSpotlight.mjs +59 -0
  53. package/dist/components/feedback/tour/useTourSpotlight.mjs.map +1 -0
  54. package/dist/components/feedback/tour/useTourSteps.cjs +108 -0
  55. package/dist/components/feedback/tour/useTourSteps.cjs.map +1 -0
  56. package/dist/components/feedback/tour/useTourSteps.mjs +107 -0
  57. package/dist/components/feedback/tour/useTourSteps.mjs.map +1 -0
  58. package/dist/components/forms/Button.cjs +1 -1
  59. package/dist/components/forms/Button.cjs.map +1 -1
  60. package/dist/components/forms/Button.mjs +1 -1
  61. package/dist/components/forms/Button.mjs.map +1 -1
  62. package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs +1 -1
  63. package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  64. package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs +1 -1
  65. package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  66. package/dist/components/forms/FileInput.cjs +1 -1
  67. package/dist/components/forms/FileInput.cjs.map +1 -1
  68. package/dist/components/forms/FileInput.mjs +1 -1
  69. package/dist/components/forms/FileInput.mjs.map +1 -1
  70. package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.cjs +34 -17
  71. package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  72. package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.mjs +34 -17
  73. package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  74. package/dist/components/forms/MultiSelect.cjs +1 -1
  75. package/dist/components/forms/MultiSelect.cjs.map +1 -1
  76. package/dist/components/forms/MultiSelect.mjs +1 -1
  77. package/dist/components/forms/MultiSelect.mjs.map +1 -1
  78. package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.cjs +2 -1
  79. package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  80. package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.mjs +2 -1
  81. package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  82. package/dist/components/forms/TagInput.cjs.map +1 -1
  83. package/dist/components/forms/TagInput.mjs.map +1 -1
  84. package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.cjs +1 -0
  85. package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  86. package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.mjs +1 -0
  87. package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  88. package/dist/components/forms/Textarea.cjs.map +1 -1
  89. package/dist/components/forms/Textarea.mjs.map +1 -1
  90. package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.cjs +1 -1
  91. package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  92. package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.mjs +1 -1
  93. package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  94. package/dist/components/layout/Canvas.cjs +1 -1
  95. package/dist/components/layout/Canvas.cjs.map +1 -1
  96. package/dist/components/layout/Canvas.mjs +1 -1
  97. package/dist/components/layout/Canvas.mjs.map +1 -1
  98. package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.cjs +1 -1
  99. package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  100. package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.mjs +1 -1
  101. package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  102. package/dist/components/layout/PopoverPanel.cjs +1 -1
  103. package/dist/components/layout/PopoverPanel.cjs.map +1 -1
  104. package/dist/components/layout/PopoverPanel.mjs +1 -1
  105. package/dist/components/layout/PopoverPanel.mjs.map +1 -1
  106. package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs +1 -1
  107. package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  108. package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs +1 -1
  109. package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  110. package/dist/components/layout/popover/PopoverTrigger.cjs.map +1 -1
  111. package/dist/components/layout/popover/PopoverTrigger.mjs.map +1 -1
  112. package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.cjs +1 -1
  113. package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  114. package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.mjs +1 -1
  115. package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  116. package/dist/components/navigation/DropdownMenu.cjs +1 -1
  117. package/dist/components/navigation/DropdownMenu.cjs.map +1 -1
  118. package/dist/components/navigation/DropdownMenu.mjs +1 -1
  119. package/dist/components/navigation/DropdownMenu.mjs.map +1 -1
  120. package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.cjs +1 -1
  121. package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  122. package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.mjs +1 -1
  123. package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  124. package/dist/components/navigation/Switcher.cjs.map +1 -1
  125. package/dist/components/navigation/Switcher.mjs.map +1 -1
  126. package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +77 -45
  127. package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  128. package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +77 -45
  129. package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  130. package/dist/components/navigation/menu/MenuTrigger.cjs.map +1 -1
  131. package/dist/components/navigation/menu/MenuTrigger.mjs.map +1 -1
  132. package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.cjs +1 -1
  133. package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  134. package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.mjs +1 -1
  135. package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
  136. package/dist/composables/useField.cjs +28 -8
  137. package/dist/composables/useField.cjs.map +1 -1
  138. package/dist/composables/useField.mjs +28 -8
  139. package/dist/composables/useField.mjs.map +1 -1
  140. package/dist/config/ModoLocale.cjs +10 -1
  141. package/dist/config/ModoLocale.cjs.map +1 -1
  142. package/dist/config/ModoLocale.mjs +10 -1
  143. package/dist/config/ModoLocale.mjs.map +1 -1
  144. package/dist/config/locales/es.cjs +10 -1
  145. package/dist/config/locales/es.cjs.map +1 -1
  146. package/dist/config/locales/es.mjs +10 -1
  147. package/dist/config/locales/es.mjs.map +1 -1
  148. package/dist/index.cjs +4 -0
  149. package/dist/index.mjs +3 -1
  150. package/dist/mood-ui.css +289 -103
  151. package/dist/types/components/data-display/surface-card/SurfaceCardBody.vue.d.ts +1 -1
  152. package/dist/types/components/data-display/surface-card/SurfaceCardFooter.vue.d.ts +1 -1
  153. package/dist/types/components/data-display/surface-card/SurfaceCardHeader.vue.d.ts +1 -1
  154. package/dist/types/components/feedback/dialog/DialogContent.vue.d.ts +1 -1
  155. package/dist/types/components/feedback/tour/Tour.vue.d.ts +31 -0
  156. package/dist/types/components/feedback/tour/TourCard.vue.d.ts +25 -0
  157. package/dist/types/components/feedback/tour/index.d.ts +2 -0
  158. package/dist/types/components/feedback/tour/tourAnchor.d.ts +12 -0
  159. package/dist/types/components/feedback/tour/tourPlace.d.ts +60 -0
  160. package/dist/types/components/feedback/tour/tourShape.d.ts +36 -0
  161. package/dist/types/components/feedback/tour/useTourSpotlight.d.ts +14 -0
  162. package/dist/types/components/feedback/tour/useTourSteps.d.ts +31 -0
  163. package/dist/types/components/layout/Canvas.vue.d.ts +1 -1
  164. package/dist/types/components/layout/popover/PopoverContent.vue.d.ts +1 -1
  165. package/dist/types/components/navigation/menu/MenuContent.vue.d.ts +1 -1
  166. package/dist/types/composables/useField.d.ts +23 -0
  167. package/dist/types/config/ModoLocale.d.ts +14 -0
  168. package/dist/types/index.d.ts +2 -0
  169. package/dist/types/interfaces/feedback/Tour.interface.d.ts +73 -0
  170. package/dist/types/interfaces/navigation/Switcher.interface.d.ts +5 -0
  171. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.vue_vue_type_script_setup_true_lang.cjs","names":[],"sources":["../../../src/components/navigation/DropdownMenu.vue"],"sourcesContent":["<template> \n <div class=\"modo-dropdown inline-flex\"> \n <!-- Trigger: prefer the `#trigger` slot (full control, e.g. wrap an \n Avatar). Default trigger uses <Button> per §14 (no raw <button>). --> \n <span ref=\"triggerEl\" class=\"inline-flex\"> \n <slot name=\"trigger\" :open=\"isOpen\" :toggle=\"toggle\">\n <Button\n :variant=\"triggerVariant\"\n :color=\"resolvedColor\"\n :size=\"resolvedSize\"\n :radius=\"resolvedRadius\"\n :icon=\"effectiveTriggerIcon\"\n :iconPosition=\"triggerLabel ? 'right' : 'left'\"\n :label=\"triggerLabel\"\n :ariaLabel=\"ariaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n triggerSurfaceClass,\n triggerVariant === 'outline' && props.color !== 'danger'\n ? '!border-border !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring'\n : '',\n ]\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"isOpen\"\n @click=\"toggle\"\n />\n </slot> \n </span> \n \n <PopoverPanel \n :open=\"isOpen\" \n :style=\"panelStyle\" \n :radius=\"resolvedRadius\" \n role=\"menu\" \n :aria-label=\"ariaLabel || triggerLabel || 'Menu'\" \n @update:panelRef=\"panelRef = $event\" \n > \n <ul \n ref=\"listEl\" \n class=\"modo-dropdown-list flex flex-col\" \n :style=\"{ minWidth }\" \n @keydown=\"onKeydown\" \n > \n <template v-for=\"(entry, idx) in entries\" :key=\"idx\"> \n <li v-if=\"isDivider(entry)\" role=\"separator\" class=\"my-1 h-px bg-border\" /> \n \n <li \n v-else-if=\"isHeader(entry)\" \n role=\"presentation\" \n class=\"px-3 pt-2 pb-1 text-caption font-semibold uppercase tracking-wider text-muted-foreground select-none\" \n > \n {{ entry.label }} \n </li> \n \n <li v-else role=\"none\"> \n <component \n :is=\"entry.href ? 'a' : 'button'\" \n :type=\"entry.href ? undefined : 'button'\" \n :href=\"entry.href && !entry.disabled ? entry.href : undefined\" \n :target=\"entry.external ? '_blank' : undefined\" \n :rel=\"entry.external ? 'noopener noreferrer' : undefined\" \n role=\"menuitem\" \n :tabindex=\"-1\" \n :aria-disabled=\"entry.disabled || undefined\" \n :data-active=\"idx === activeIndex || undefined\" \n :class=\"[\n 'modo-dropdown-item w-full flex items-center gap-2 px-3 py-2 text-left',\n 'text-body transition-colors duration-fast ease-standard',\n entry.disabled\n ? 'opacity-50 cursor-not-allowed'\n : entry.danger\n ? ['text-destructive', 'hover:bg-destructive/10', 'cursor-pointer']\n : [itemTextColor, itemHover, 'cursor-pointer'],\n !entry.disabled && idx === activeIndex\n ? (entry.danger ? 'bg-destructive/10' : itemSurface)\n : '',\n ]\" \n @click=\"onItemClick(entry, $event)\" \n @mouseenter=\"setActive(idx)\" \n @focus=\"setActive(idx)\" \n > \n <component \n :is=\"entry.icon\" \n v-if=\"entry.icon\" \n :class=\"[iconSizeClass, 'shrink-0', entry.danger ? 'text-destructive' : itemIconColor]\" \n aria-hidden=\"true\" \n /> \n <span class=\"flex flex-col min-w-0 flex-1\"> \n <span class=\"truncate\">{{ entry.label }}</span> \n <span \n v-if=\"entry.description\" \n class=\"text-caption text-muted-foreground truncate\" \n >{{ entry.description }}</span> \n </span> \n <span \n v-if=\"entry.shortcut\" \n class=\"ml-2 text-caption text-muted-foreground tabular-nums\" \n aria-hidden=\"true\" \n >{{ entry.shortcut }}</span> \n </component> \n </li> \n </template> \n </ul> \n </PopoverPanel> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch, nextTick } from 'vue'; \nimport { ChevronDownIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../forms/Button.vue'; \nimport PopoverPanel from '../layout/PopoverPanel.vue'; \nimport { usePopover } from '../../composables/usePopover'; \nimport { useResolvedColor, useResolvedRadius, useResolvedSize } from '../../composables/useModoConfig'; \nimport type { \n DropdownMenu, \n DropdownMenuEntry, \n DropdownMenuItem, \n DropdownMenuDivider, \n DropdownMenuHeader, \n DropdownMenuEmits, \n} from '../../interfaces/navigation/DropdownMenu.interface'; \n \nconst props = withDefaults(defineProps<DropdownMenu>(), { \n triggerVariant: 'outline', \n color: 'default', \n showChevron: true, \n placement: 'bottom-start', \n matchTriggerWidth: false, \n minWidth: '12rem', \n disabled: false, \n closeOnSelect: true, \n}); \n \nconst emit = defineEmits<DropdownMenuEmits>(); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \nconst resolvedSize = useResolvedSize(() => props.size); \n \nconst entries = computed<DropdownMenuEntry[]>(() => props.items ?? []); \n \nfunction isDivider(e: DropdownMenuEntry): e is DropdownMenuDivider { \n return (e as { type?: string }).type === 'divider'; \n} \nfunction isHeader(e: DropdownMenuEntry): e is DropdownMenuHeader { \n return (e as { type?: string }).type === 'header'; \n} \nfunction isItem(e: DropdownMenuEntry): e is DropdownMenuItem { \n return !isDivider(e) && !isHeader(e); \n} \n \n/* ---------- Trigger ---------- */ \nconst effectiveTriggerIcon = computed(() => { \n if (props.triggerIcon) return props.triggerIcon; \n if (props.showChevron && props.triggerLabel) return ChevronDownIcon; \n if (props.showChevron && !props.triggerLabel) return ChevronDownIcon; \n return undefined; \n}); \n \n/* ---------- Popover ---------- */ \nconst { \n triggerRef, \n panelRef, \n isOpen, \n panelStyle, \n open, \n close, \n toggle, \n} = usePopover({ \n placement: () => props.placement, \n matchTriggerWidth: () => props.matchTriggerWidth, \n onOpen: () => emit('update:open', true), \n onClose: () => { \n emit('update:open', false); \n activeIndex.value = -1; \n }, \n}); \n \nconst triggerEl = ref<HTMLElement | null>(null); \nwatch(triggerEl, (el) => { triggerRef.value = el; }); \n \n/* ---------- Active item & keyboard ---------- */ \nconst listEl = ref<HTMLElement | null>(null); \nconst activeIndex = ref(-1); \n \nconst itemIndices = computed(() => \n entries.value \n .map((e, i) => (isItem(e) && !e.disabled ? i : -1)) \n .filter((i) => i !== -1), \n); \n \nfunction setActive(idx: number) { \n activeIndex.value = idx; \n} \n \nfunction moveActive(delta: number) { \n const order = itemIndices.value; \n if (!order.length) return; \n const cur = order.indexOf(activeIndex.value); \n const next = cur === -1 \n ? (delta > 0 ? 0 : order.length - 1) \n : (cur + delta + order.length) % order.length; \n activeIndex.value = order[next]; \n focusActive(); \n} \n \nfunction focusActive() { \n nextTick(() => { \n const el = listEl.value?.querySelector<HTMLElement>('[data-active=\"true\"]'); \n el?.focus({ preventScroll: true }); \n }); \n} \n \nwatch(isOpen, async (v) => { \n if (v) { \n await nextTick(); \n const order = itemIndices.value; \n if (order.length) { \n activeIndex.value = order[0]; \n focusActive(); \n } \n } \n}); \n \nfunction onKeydown(e: KeyboardEvent) { \n switch (e.key) { \n case 'ArrowDown': \n e.preventDefault(); \n moveActive(1); \n break; \n case 'ArrowUp': \n e.preventDefault(); \n moveActive(-1); \n break; \n case 'Home': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[0]; \n focusActive(); \n } \n break; \n case 'End': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[itemIndices.value.length - 1]; \n focusActive(); \n } \n break; \n case 'Enter': \n case ' ': { \n const entry = entries.value[activeIndex.value]; \n if (entry && isItem(entry) && !entry.disabled) { \n e.preventDefault(); \n onItemClick(entry); \n } \n break; \n } \n case 'Tab': \n close(); \n break; \n } \n} \n \nfunction onItemClick(entry: DropdownMenuItem, evt?: MouseEvent) { \n if (entry.disabled) { \n evt?.preventDefault(); \n return; \n } \n entry.onClick?.(entry); \n emit('select', entry); \n if (props.closeOnSelect) close(); \n} \n \n/* ---------- Visual scaling tied to size ---------- */ \nconst iconSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case 'small': return 'w-3.5 h-3.5';\n case 'large': return 'w-5 h-5';\n default: return 'w-4 h-4';\n }\n});\n\n/* ---------- Item surface / hover (color-aware) ---------- */\nconst effectiveItemColor = computed(() => props.color === 'default' ? 'default' : resolvedColor.value);\nconst triggerSurfaceClass = computed(() => {\n if (props.triggerVariant !== 'outline') return '';\n if (effectiveItemColor.value === 'danger') {\n return 'bg-destructive/10 hover:!bg-destructive/10 active:!bg-destructive/18';\n }\n return 'bg-card';\n});\nconst ITEM_SURFACE: Record<string, string> = {\n default: 'bg-accent',\n primary: 'bg-accent',\n danger: 'bg-destructive/16',\n success: 'bg-accent',\n warning: 'bg-accent',\n};\nconst ITEM_HOVER: Record<string, string> = {\n default: 'hover:bg-accent',\n primary: 'hover:bg-accent',\n danger: 'hover:bg-destructive/14',\n success: 'hover:bg-accent',\n warning: 'hover:bg-accent',\n};\nconst ITEM_TEXT: Record<string, string> = {\n default: 'text-foreground',\n primary: 'text-foreground',\n danger: 'text-destructive',\n success: 'text-foreground',\n warning: 'text-foreground',\n};\nconst ITEM_ICON: Record<string, string> = {\n default: 'modo-affordance-icon',\n primary: 'modo-affordance-icon',\n danger: 'text-destructive',\n success: 'modo-affordance-icon',\n warning: 'modo-affordance-icon',\n};\nconst itemSurface = computed(() => ITEM_SURFACE[effectiveItemColor.value] ?? 'bg-accent');\nconst itemHover = computed(() => ITEM_HOVER[effectiveItemColor.value] ?? 'hover:bg-accent');\nconst itemTextColor = computed(() => ITEM_TEXT[effectiveItemColor.value] ?? 'text-foreground');\nconst itemIconColor = computed(() => ITEM_ICON[effectiveItemColor.value] ?? 'modo-affordance-icon');\n\ndefineExpose({ open, close, toggle }); \n</script> \n \n<style scoped> \n.modo-dropdown-item { \n /* Native focus ring is suppressed: hover/data-active styling provides \n the visual cue. Container is `role=\"menu\"`, items are reachable via \n roving tabindex. */ \n outline: none; \n} \n.modo-dropdown-item:focus-visible { \n outline: none; \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2HA,MAAM,QAAQ;EAWd,MAAM,OAAO;EAEb,MAAM,gBAAgB,sBAAA,uBAAuB,MAAM,MAAM;EACzD,MAAM,iBAAiB,sBAAA,wBAAwB,MAAM,OAAO;EAC5D,MAAM,eAAe,sBAAA,sBAAsB,MAAM,KAAK;EAEtD,MAAM,WAAA,GAAA,IAAA,gBAA8C,MAAM,SAAS,EAAE,CAAC;EAEtE,SAAS,UAAU,GAAgD;GAC/D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,SAAS,GAA+C;GAC7D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,OAAO,GAA6C;GACzD,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE;;EAIxC,MAAM,wBAAA,GAAA,IAAA,gBAAsC;GACxC,IAAI,MAAM,aAAa,OAAO,MAAM;GACpC,IAAI,MAAM,eAAe,MAAM,cAAc,OAAO,0BAAA;GACpD,IAAI,MAAM,eAAe,CAAC,MAAM,cAAc,OAAO,0BAAA;IAEvD;EAGF,MAAM,EACF,YACA,UACA,QACA,YACA,MACA,OACA,WACA,mBAAA,WAAW;GACX,iBAAiB,MAAM;GACvB,yBAAyB,MAAM;GAC/B,cAAc,KAAK,eAAe,KAAK;GACvC,eAAe;IACX,KAAK,eAAe,MAAM;IAC1B,YAAY,QAAQ;;GAE3B,CAAC;EAEF,MAAM,aAAA,GAAA,IAAA,KAAoC,KAAK;EAC/C,CAAA,GAAA,IAAA,OAA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AM,SAAM,qBAAwB,cAAA;SAAa,CAAA;QACrF,eAAY;;mCAQT,QANP,YAMO,EAAA,GAAA,IAAA,oBAL4C,QAA/C,aAAA,GAAA,IAAA,iBAA0B,MAAM,MAAK,EAAA,EAAA,EAE3B,MAAM,gBAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,oBAEe,QAH/B,aAAA,GAAA,IAAA,iBAGI,MAAM,YAAW,EAAA,EAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA,CAAA,CAAA;OAGf,MAAM,aAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,oBAGY,QAJ5B,aAAA,GAAA,IAAA,iBAII,MAAM,SAAQ,EAAA,EAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA"}
1
+ {"version":3,"file":"DropdownMenu.vue_vue_type_script_setup_true_lang.cjs","names":[],"sources":["../../../src/components/navigation/DropdownMenu.vue"],"sourcesContent":["<template> \n <div class=\"modo-dropdown inline-flex\"> \n <!-- Trigger: prefer the `#trigger` slot (full control, e.g. wrap an \n Avatar). Default trigger uses <Button> per §14 (no raw <button>). --> \n <span ref=\"triggerEl\" class=\"inline-flex\"> \n <slot name=\"trigger\" :open=\"isOpen\" :toggle=\"toggle\">\n <Button\n :variant=\"triggerVariant\"\n :color=\"resolvedColor\"\n :size=\"resolvedSize\"\n :radius=\"resolvedRadius\"\n :icon=\"effectiveTriggerIcon\"\n :iconPosition=\"triggerLabel ? 'right' : 'left'\"\n :label=\"triggerLabel\"\n :ariaLabel=\"ariaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n triggerSurfaceClass,\n triggerVariant === 'outline' && props.color !== 'danger'\n ? '!border-input hover:!border-input-hover !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring'\n : '',\n ]\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"isOpen\"\n @click=\"toggle\"\n />\n </slot> \n </span> \n \n <PopoverPanel \n :open=\"isOpen\" \n :style=\"panelStyle\" \n :radius=\"resolvedRadius\" \n role=\"menu\" \n :aria-label=\"ariaLabel || triggerLabel || 'Menu'\" \n @update:panelRef=\"panelRef = $event\" \n > \n <ul \n ref=\"listEl\" \n class=\"modo-dropdown-list flex flex-col\" \n :style=\"{ minWidth }\" \n @keydown=\"onKeydown\" \n > \n <template v-for=\"(entry, idx) in entries\" :key=\"idx\"> \n <li v-if=\"isDivider(entry)\" role=\"separator\" class=\"my-1 h-px bg-border\" /> \n \n <li \n v-else-if=\"isHeader(entry)\" \n role=\"presentation\" \n class=\"px-3 pt-2 pb-1 text-caption font-semibold uppercase tracking-wider text-muted-foreground select-none\" \n > \n {{ entry.label }} \n </li> \n \n <li v-else role=\"none\"> \n <component \n :is=\"entry.href ? 'a' : 'button'\" \n :type=\"entry.href ? undefined : 'button'\" \n :href=\"entry.href && !entry.disabled ? entry.href : undefined\" \n :target=\"entry.external ? '_blank' : undefined\" \n :rel=\"entry.external ? 'noopener noreferrer' : undefined\" \n role=\"menuitem\" \n :tabindex=\"-1\" \n :aria-disabled=\"entry.disabled || undefined\" \n :data-active=\"idx === activeIndex || undefined\" \n :class=\"[\n 'modo-dropdown-item w-full flex items-center gap-2 px-3 py-2 text-left',\n 'text-body transition-colors duration-fast ease-standard',\n entry.disabled\n ? 'opacity-50 cursor-not-allowed'\n : entry.danger\n ? ['text-destructive', 'hover:bg-destructive/10', 'cursor-pointer']\n : [itemTextColor, itemHover, 'cursor-pointer'],\n !entry.disabled && idx === activeIndex\n ? (entry.danger ? 'bg-destructive/10' : itemSurface)\n : '',\n ]\" \n @click=\"onItemClick(entry, $event)\" \n @mouseenter=\"setActive(idx)\" \n @focus=\"setActive(idx)\" \n > \n <component \n :is=\"entry.icon\" \n v-if=\"entry.icon\" \n :class=\"[iconSizeClass, 'shrink-0', entry.danger ? 'text-destructive' : itemIconColor]\" \n aria-hidden=\"true\" \n /> \n <span class=\"flex flex-col min-w-0 flex-1\"> \n <span class=\"truncate\">{{ entry.label }}</span> \n <span \n v-if=\"entry.description\" \n class=\"text-caption text-muted-foreground truncate\" \n >{{ entry.description }}</span> \n </span> \n <span \n v-if=\"entry.shortcut\" \n class=\"ml-2 text-caption text-muted-foreground tabular-nums\" \n aria-hidden=\"true\" \n >{{ entry.shortcut }}</span> \n </component> \n </li> \n </template> \n </ul> \n </PopoverPanel> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch, nextTick } from 'vue'; \nimport { ChevronDownIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../forms/Button.vue'; \nimport PopoverPanel from '../layout/PopoverPanel.vue'; \nimport { usePopover } from '../../composables/usePopover'; \nimport { useResolvedColor, useResolvedRadius, useResolvedSize } from '../../composables/useModoConfig'; \nimport type { \n DropdownMenu, \n DropdownMenuEntry, \n DropdownMenuItem, \n DropdownMenuDivider, \n DropdownMenuHeader, \n DropdownMenuEmits, \n} from '../../interfaces/navigation/DropdownMenu.interface'; \n \nconst props = withDefaults(defineProps<DropdownMenu>(), { \n triggerVariant: 'outline', \n color: 'default', \n showChevron: true, \n placement: 'bottom-start', \n matchTriggerWidth: false, \n minWidth: '12rem', \n disabled: false, \n closeOnSelect: true, \n}); \n \nconst emit = defineEmits<DropdownMenuEmits>(); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \nconst resolvedSize = useResolvedSize(() => props.size); \n \nconst entries = computed<DropdownMenuEntry[]>(() => props.items ?? []); \n \nfunction isDivider(e: DropdownMenuEntry): e is DropdownMenuDivider { \n return (e as { type?: string }).type === 'divider'; \n} \nfunction isHeader(e: DropdownMenuEntry): e is DropdownMenuHeader { \n return (e as { type?: string }).type === 'header'; \n} \nfunction isItem(e: DropdownMenuEntry): e is DropdownMenuItem { \n return !isDivider(e) && !isHeader(e); \n} \n \n/* ---------- Trigger ---------- */ \nconst effectiveTriggerIcon = computed(() => { \n if (props.triggerIcon) return props.triggerIcon; \n if (props.showChevron && props.triggerLabel) return ChevronDownIcon; \n if (props.showChevron && !props.triggerLabel) return ChevronDownIcon; \n return undefined; \n}); \n \n/* ---------- Popover ---------- */ \nconst { \n triggerRef, \n panelRef, \n isOpen, \n panelStyle, \n open, \n close, \n toggle, \n} = usePopover({ \n placement: () => props.placement, \n matchTriggerWidth: () => props.matchTriggerWidth, \n onOpen: () => emit('update:open', true), \n onClose: () => { \n emit('update:open', false); \n activeIndex.value = -1; \n }, \n}); \n \nconst triggerEl = ref<HTMLElement | null>(null); \nwatch(triggerEl, (el) => { triggerRef.value = el; }); \n \n/* ---------- Active item & keyboard ---------- */ \nconst listEl = ref<HTMLElement | null>(null); \nconst activeIndex = ref(-1); \n \nconst itemIndices = computed(() => \n entries.value \n .map((e, i) => (isItem(e) && !e.disabled ? i : -1)) \n .filter((i) => i !== -1), \n); \n \nfunction setActive(idx: number) { \n activeIndex.value = idx; \n} \n \nfunction moveActive(delta: number) { \n const order = itemIndices.value; \n if (!order.length) return; \n const cur = order.indexOf(activeIndex.value); \n const next = cur === -1 \n ? (delta > 0 ? 0 : order.length - 1) \n : (cur + delta + order.length) % order.length; \n activeIndex.value = order[next]; \n focusActive(); \n} \n \nfunction focusActive() { \n nextTick(() => { \n const el = listEl.value?.querySelector<HTMLElement>('[data-active=\"true\"]'); \n el?.focus({ preventScroll: true }); \n }); \n} \n \nwatch(isOpen, async (v) => { \n if (v) { \n await nextTick(); \n const order = itemIndices.value; \n if (order.length) { \n activeIndex.value = order[0]; \n focusActive(); \n } \n } \n}); \n \nfunction onKeydown(e: KeyboardEvent) { \n switch (e.key) { \n case 'ArrowDown': \n e.preventDefault(); \n moveActive(1); \n break; \n case 'ArrowUp': \n e.preventDefault(); \n moveActive(-1); \n break; \n case 'Home': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[0]; \n focusActive(); \n } \n break; \n case 'End': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[itemIndices.value.length - 1]; \n focusActive(); \n } \n break; \n case 'Enter': \n case ' ': { \n const entry = entries.value[activeIndex.value]; \n if (entry && isItem(entry) && !entry.disabled) { \n e.preventDefault(); \n onItemClick(entry); \n } \n break; \n } \n case 'Tab': \n close(); \n break; \n } \n} \n \nfunction onItemClick(entry: DropdownMenuItem, evt?: MouseEvent) { \n if (entry.disabled) { \n evt?.preventDefault(); \n return; \n } \n entry.onClick?.(entry); \n emit('select', entry); \n if (props.closeOnSelect) close(); \n} \n \n/* ---------- Visual scaling tied to size ---------- */ \nconst iconSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case 'small': return 'w-3.5 h-3.5';\n case 'large': return 'w-5 h-5';\n default: return 'w-4 h-4';\n }\n});\n\n/* ---------- Item surface / hover (color-aware) ---------- */\nconst effectiveItemColor = computed(() => props.color === 'default' ? 'default' : resolvedColor.value);\nconst triggerSurfaceClass = computed(() => {\n if (props.triggerVariant !== 'outline') return '';\n if (effectiveItemColor.value === 'danger') {\n return 'bg-destructive/10 hover:!bg-destructive/10 active:!bg-destructive/18';\n }\n return 'bg-card';\n});\nconst ITEM_SURFACE: Record<string, string> = {\n default: 'bg-accent',\n primary: 'bg-accent',\n danger: 'bg-destructive/16',\n success: 'bg-accent',\n warning: 'bg-accent',\n};\nconst ITEM_HOVER: Record<string, string> = {\n default: 'hover:bg-accent',\n primary: 'hover:bg-accent',\n danger: 'hover:bg-destructive/14',\n success: 'hover:bg-accent',\n warning: 'hover:bg-accent',\n};\nconst ITEM_TEXT: Record<string, string> = {\n default: 'text-foreground',\n primary: 'text-foreground',\n danger: 'text-destructive',\n success: 'text-foreground',\n warning: 'text-foreground',\n};\nconst ITEM_ICON: Record<string, string> = {\n default: 'modo-affordance-icon',\n primary: 'modo-affordance-icon',\n danger: 'text-destructive',\n success: 'modo-affordance-icon',\n warning: 'modo-affordance-icon',\n};\nconst itemSurface = computed(() => ITEM_SURFACE[effectiveItemColor.value] ?? 'bg-accent');\nconst itemHover = computed(() => ITEM_HOVER[effectiveItemColor.value] ?? 'hover:bg-accent');\nconst itemTextColor = computed(() => ITEM_TEXT[effectiveItemColor.value] ?? 'text-foreground');\nconst itemIconColor = computed(() => ITEM_ICON[effectiveItemColor.value] ?? 'modo-affordance-icon');\n\ndefineExpose({ open, close, toggle }); \n</script> \n \n<style scoped> \n.modo-dropdown-item { \n /* Native focus ring is suppressed: hover/data-active styling provides \n the visual cue. Container is `role=\"menu\"`, items are reachable via \n roving tabindex. */ \n outline: none; \n} \n.modo-dropdown-item:focus-visible { \n outline: none; \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2HA,MAAM,QAAQ;EAWd,MAAM,OAAO;EAEb,MAAM,gBAAgB,sBAAA,uBAAuB,MAAM,MAAM;EACzD,MAAM,iBAAiB,sBAAA,wBAAwB,MAAM,OAAO;EAC5D,MAAM,eAAe,sBAAA,sBAAsB,MAAM,KAAK;EAEtD,MAAM,WAAA,GAAA,IAAA,gBAA8C,MAAM,SAAS,EAAE,CAAC;EAEtE,SAAS,UAAU,GAAgD;GAC/D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,SAAS,GAA+C;GAC7D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,OAAO,GAA6C;GACzD,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE;;EAIxC,MAAM,wBAAA,GAAA,IAAA,gBAAsC;GACxC,IAAI,MAAM,aAAa,OAAO,MAAM;GACpC,IAAI,MAAM,eAAe,MAAM,cAAc,OAAO,0BAAA;GACpD,IAAI,MAAM,eAAe,CAAC,MAAM,cAAc,OAAO,0BAAA;IAEvD;EAGF,MAAM,EACF,YACA,UACA,QACA,YACA,MACA,OACA,WACA,mBAAA,WAAW;GACX,iBAAiB,MAAM;GACvB,yBAAyB,MAAM;GAC/B,cAAc,KAAK,eAAe,KAAK;GACvC,eAAe;IACX,KAAK,eAAe,MAAM;IAC1B,YAAY,QAAQ;;GAE3B,CAAC;EAEF,MAA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AA;;QAEd,QAAA,GAAA,IAAA,gBAAK;SAAG,cAAA;SAAa;SAAc,MAAM,SAAM,qBAAwB,cAAA;SAAa,CAAA;QACrF,eAAY;;mCAQT,QANP,YAMO,EAAA,GAAA,IAAA,oBAL4C,QAA/C,aAAA,GAAA,IAAA,iBAA0B,MAAM,MAAK,EAAA,EAAA,EAE3B,MAAM,gBAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,oBAEe,QAH/B,aAAA,GAAA,IAAA,iBAGI,MAAM,YAAW,EAAA,EAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA,CAAA,CAAA;OAGf,MAAM,aAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,oBAGY,QAJ5B,aAAA,GAAA,IAAA,iBAII,MAAM,SAAQ,EAAA,EAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA"}
@@ -239,7 +239,7 @@ var DropdownMenu_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ d
239
239
  label: __props.triggerLabel,
240
240
  ariaLabel: __props.ariaLabel,
241
241
  disabled: __props.disabled,
242
- class: normalizeClass([triggerSurfaceClass.value, __props.triggerVariant === "outline" && props.color !== "danger" ? "!border-border !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring" : ""]),
242
+ class: normalizeClass([triggerSurfaceClass.value, __props.triggerVariant === "outline" && props.color !== "danger" ? "!border-input hover:!border-input-hover !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring" : ""]),
243
243
  "aria-haspopup": "menu",
244
244
  "aria-expanded": unref(isOpen),
245
245
  onClick: unref(toggle)
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.vue_vue_type_script_setup_true_lang.mjs","names":[],"sources":["../../../src/components/navigation/DropdownMenu.vue"],"sourcesContent":["<template> \n <div class=\"modo-dropdown inline-flex\"> \n <!-- Trigger: prefer the `#trigger` slot (full control, e.g. wrap an \n Avatar). Default trigger uses <Button> per §14 (no raw <button>). --> \n <span ref=\"triggerEl\" class=\"inline-flex\"> \n <slot name=\"trigger\" :open=\"isOpen\" :toggle=\"toggle\">\n <Button\n :variant=\"triggerVariant\"\n :color=\"resolvedColor\"\n :size=\"resolvedSize\"\n :radius=\"resolvedRadius\"\n :icon=\"effectiveTriggerIcon\"\n :iconPosition=\"triggerLabel ? 'right' : 'left'\"\n :label=\"triggerLabel\"\n :ariaLabel=\"ariaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n triggerSurfaceClass,\n triggerVariant === 'outline' && props.color !== 'danger'\n ? '!border-border !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring'\n : '',\n ]\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"isOpen\"\n @click=\"toggle\"\n />\n </slot> \n </span> \n \n <PopoverPanel \n :open=\"isOpen\" \n :style=\"panelStyle\" \n :radius=\"resolvedRadius\" \n role=\"menu\" \n :aria-label=\"ariaLabel || triggerLabel || 'Menu'\" \n @update:panelRef=\"panelRef = $event\" \n > \n <ul \n ref=\"listEl\" \n class=\"modo-dropdown-list flex flex-col\" \n :style=\"{ minWidth }\" \n @keydown=\"onKeydown\" \n > \n <template v-for=\"(entry, idx) in entries\" :key=\"idx\"> \n <li v-if=\"isDivider(entry)\" role=\"separator\" class=\"my-1 h-px bg-border\" /> \n \n <li \n v-else-if=\"isHeader(entry)\" \n role=\"presentation\" \n class=\"px-3 pt-2 pb-1 text-caption font-semibold uppercase tracking-wider text-muted-foreground select-none\" \n > \n {{ entry.label }} \n </li> \n \n <li v-else role=\"none\"> \n <component \n :is=\"entry.href ? 'a' : 'button'\" \n :type=\"entry.href ? undefined : 'button'\" \n :href=\"entry.href && !entry.disabled ? entry.href : undefined\" \n :target=\"entry.external ? '_blank' : undefined\" \n :rel=\"entry.external ? 'noopener noreferrer' : undefined\" \n role=\"menuitem\" \n :tabindex=\"-1\" \n :aria-disabled=\"entry.disabled || undefined\" \n :data-active=\"idx === activeIndex || undefined\" \n :class=\"[\n 'modo-dropdown-item w-full flex items-center gap-2 px-3 py-2 text-left',\n 'text-body transition-colors duration-fast ease-standard',\n entry.disabled\n ? 'opacity-50 cursor-not-allowed'\n : entry.danger\n ? ['text-destructive', 'hover:bg-destructive/10', 'cursor-pointer']\n : [itemTextColor, itemHover, 'cursor-pointer'],\n !entry.disabled && idx === activeIndex\n ? (entry.danger ? 'bg-destructive/10' : itemSurface)\n : '',\n ]\" \n @click=\"onItemClick(entry, $event)\" \n @mouseenter=\"setActive(idx)\" \n @focus=\"setActive(idx)\" \n > \n <component \n :is=\"entry.icon\" \n v-if=\"entry.icon\" \n :class=\"[iconSizeClass, 'shrink-0', entry.danger ? 'text-destructive' : itemIconColor]\" \n aria-hidden=\"true\" \n /> \n <span class=\"flex flex-col min-w-0 flex-1\"> \n <span class=\"truncate\">{{ entry.label }}</span> \n <span \n v-if=\"entry.description\" \n class=\"text-caption text-muted-foreground truncate\" \n >{{ entry.description }}</span> \n </span> \n <span \n v-if=\"entry.shortcut\" \n class=\"ml-2 text-caption text-muted-foreground tabular-nums\" \n aria-hidden=\"true\" \n >{{ entry.shortcut }}</span> \n </component> \n </li> \n </template> \n </ul> \n </PopoverPanel> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch, nextTick } from 'vue'; \nimport { ChevronDownIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../forms/Button.vue'; \nimport PopoverPanel from '../layout/PopoverPanel.vue'; \nimport { usePopover } from '../../composables/usePopover'; \nimport { useResolvedColor, useResolvedRadius, useResolvedSize } from '../../composables/useModoConfig'; \nimport type { \n DropdownMenu, \n DropdownMenuEntry, \n DropdownMenuItem, \n DropdownMenuDivider, \n DropdownMenuHeader, \n DropdownMenuEmits, \n} from '../../interfaces/navigation/DropdownMenu.interface'; \n \nconst props = withDefaults(defineProps<DropdownMenu>(), { \n triggerVariant: 'outline', \n color: 'default', \n showChevron: true, \n placement: 'bottom-start', \n matchTriggerWidth: false, \n minWidth: '12rem', \n disabled: false, \n closeOnSelect: true, \n}); \n \nconst emit = defineEmits<DropdownMenuEmits>(); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \nconst resolvedSize = useResolvedSize(() => props.size); \n \nconst entries = computed<DropdownMenuEntry[]>(() => props.items ?? []); \n \nfunction isDivider(e: DropdownMenuEntry): e is DropdownMenuDivider { \n return (e as { type?: string }).type === 'divider'; \n} \nfunction isHeader(e: DropdownMenuEntry): e is DropdownMenuHeader { \n return (e as { type?: string }).type === 'header'; \n} \nfunction isItem(e: DropdownMenuEntry): e is DropdownMenuItem { \n return !isDivider(e) && !isHeader(e); \n} \n \n/* ---------- Trigger ---------- */ \nconst effectiveTriggerIcon = computed(() => { \n if (props.triggerIcon) return props.triggerIcon; \n if (props.showChevron && props.triggerLabel) return ChevronDownIcon; \n if (props.showChevron && !props.triggerLabel) return ChevronDownIcon; \n return undefined; \n}); \n \n/* ---------- Popover ---------- */ \nconst { \n triggerRef, \n panelRef, \n isOpen, \n panelStyle, \n open, \n close, \n toggle, \n} = usePopover({ \n placement: () => props.placement, \n matchTriggerWidth: () => props.matchTriggerWidth, \n onOpen: () => emit('update:open', true), \n onClose: () => { \n emit('update:open', false); \n activeIndex.value = -1; \n }, \n}); \n \nconst triggerEl = ref<HTMLElement | null>(null); \nwatch(triggerEl, (el) => { triggerRef.value = el; }); \n \n/* ---------- Active item & keyboard ---------- */ \nconst listEl = ref<HTMLElement | null>(null); \nconst activeIndex = ref(-1); \n \nconst itemIndices = computed(() => \n entries.value \n .map((e, i) => (isItem(e) && !e.disabled ? i : -1)) \n .filter((i) => i !== -1), \n); \n \nfunction setActive(idx: number) { \n activeIndex.value = idx; \n} \n \nfunction moveActive(delta: number) { \n const order = itemIndices.value; \n if (!order.length) return; \n const cur = order.indexOf(activeIndex.value); \n const next = cur === -1 \n ? (delta > 0 ? 0 : order.length - 1) \n : (cur + delta + order.length) % order.length; \n activeIndex.value = order[next]; \n focusActive(); \n} \n \nfunction focusActive() { \n nextTick(() => { \n const el = listEl.value?.querySelector<HTMLElement>('[data-active=\"true\"]'); \n el?.focus({ preventScroll: true }); \n }); \n} \n \nwatch(isOpen, async (v) => { \n if (v) { \n await nextTick(); \n const order = itemIndices.value; \n if (order.length) { \n activeIndex.value = order[0]; \n focusActive(); \n } \n } \n}); \n \nfunction onKeydown(e: KeyboardEvent) { \n switch (e.key) { \n case 'ArrowDown': \n e.preventDefault(); \n moveActive(1); \n break; \n case 'ArrowUp': \n e.preventDefault(); \n moveActive(-1); \n break; \n case 'Home': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[0]; \n focusActive(); \n } \n break; \n case 'End': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[itemIndices.value.length - 1]; \n focusActive(); \n } \n break; \n case 'Enter': \n case ' ': { \n const entry = entries.value[activeIndex.value]; \n if (entry && isItem(entry) && !entry.disabled) { \n e.preventDefault(); \n onItemClick(entry); \n } \n break; \n } \n case 'Tab': \n close(); \n break; \n } \n} \n \nfunction onItemClick(entry: DropdownMenuItem, evt?: MouseEvent) { \n if (entry.disabled) { \n evt?.preventDefault(); \n return; \n } \n entry.onClick?.(entry); \n emit('select', entry); \n if (props.closeOnSelect) close(); \n} \n \n/* ---------- Visual scaling tied to size ---------- */ \nconst iconSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case 'small': return 'w-3.5 h-3.5';\n case 'large': return 'w-5 h-5';\n default: return 'w-4 h-4';\n }\n});\n\n/* ---------- Item surface / hover (color-aware) ---------- */\nconst effectiveItemColor = computed(() => props.color === 'default' ? 'default' : resolvedColor.value);\nconst triggerSurfaceClass = computed(() => {\n if (props.triggerVariant !== 'outline') return '';\n if (effectiveItemColor.value === 'danger') {\n return 'bg-destructive/10 hover:!bg-destructive/10 active:!bg-destructive/18';\n }\n return 'bg-card';\n});\nconst ITEM_SURFACE: Record<string, string> = {\n default: 'bg-accent',\n primary: 'bg-accent',\n danger: 'bg-destructive/16',\n success: 'bg-accent',\n warning: 'bg-accent',\n};\nconst ITEM_HOVER: Record<string, string> = {\n default: 'hover:bg-accent',\n primary: 'hover:bg-accent',\n danger: 'hover:bg-destructive/14',\n success: 'hover:bg-accent',\n warning: 'hover:bg-accent',\n};\nconst ITEM_TEXT: Record<string, string> = {\n default: 'text-foreground',\n primary: 'text-foreground',\n danger: 'text-destructive',\n success: 'text-foreground',\n warning: 'text-foreground',\n};\nconst ITEM_ICON: Record<string, string> = {\n default: 'modo-affordance-icon',\n primary: 'modo-affordance-icon',\n danger: 'text-destructive',\n success: 'modo-affordance-icon',\n warning: 'modo-affordance-icon',\n};\nconst itemSurface = computed(() => ITEM_SURFACE[effectiveItemColor.value] ?? 'bg-accent');\nconst itemHover = computed(() => ITEM_HOVER[effectiveItemColor.value] ?? 'hover:bg-accent');\nconst itemTextColor = computed(() => ITEM_TEXT[effectiveItemColor.value] ?? 'text-foreground');\nconst itemIconColor = computed(() => ITEM_ICON[effectiveItemColor.value] ?? 'modo-affordance-icon');\n\ndefineExpose({ open, close, toggle }); \n</script> \n \n<style scoped> \n.modo-dropdown-item { \n /* Native focus ring is suppressed: hover/data-active styling provides \n the visual cue. Container is `role=\"menu\"`, items are reachable via \n roving tabindex. */ \n outline: none; \n} \n.modo-dropdown-item:focus-visible { \n outline: none; \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2HA,MAAM,QAAQ;EAWd,MAAM,OAAO;EAEb,MAAM,gBAAgB,uBAAuB,MAAM,MAAM;EACzD,MAAM,iBAAiB,wBAAwB,MAAM,OAAO;EAC5D,MAAM,eAAe,sBAAsB,MAAM,KAAK;EAEtD,MAAM,UAAU,eAAoC,MAAM,SAAS,EAAE,CAAC;EAEtE,SAAS,UAAU,GAAgD;GAC/D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,SAAS,GAA+C;GAC7D,OAAQ,EAAwB,SAAS;;E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,CALH,mBAA+C,QAA/C,YAA+C,gBAArB,MAAM,MAAK,EAAA,EAAA,EAE3B,MAAM,eAAA,WAAA,EADhB,mBAG+B,QAH/B,YAG+B,gBAA3B,MAAM,YAAW,EAAA,EAAA,IAAA,mBAAA,IAAA,KAAA,CAAA,CAAA;OAGf,MAAM,YAAA,WAAA,EADhB,mBAI4B,QAJ5B,YAI4B,gBAAxB,MAAM,SAAQ,EAAA,EAAA,IAAA,mBAAA,IAAA,KAAA"}
1
+ {"version":3,"file":"DropdownMenu.vue_vue_type_script_setup_true_lang.mjs","names":[],"sources":["../../../src/components/navigation/DropdownMenu.vue"],"sourcesContent":["<template> \n <div class=\"modo-dropdown inline-flex\"> \n <!-- Trigger: prefer the `#trigger` slot (full control, e.g. wrap an \n Avatar). Default trigger uses <Button> per §14 (no raw <button>). --> \n <span ref=\"triggerEl\" class=\"inline-flex\"> \n <slot name=\"trigger\" :open=\"isOpen\" :toggle=\"toggle\">\n <Button\n :variant=\"triggerVariant\"\n :color=\"resolvedColor\"\n :size=\"resolvedSize\"\n :radius=\"resolvedRadius\"\n :icon=\"effectiveTriggerIcon\"\n :iconPosition=\"triggerLabel ? 'right' : 'left'\"\n :label=\"triggerLabel\"\n :ariaLabel=\"ariaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n triggerSurfaceClass,\n triggerVariant === 'outline' && props.color !== 'danger'\n ? '!border-input hover:!border-input-hover !text-foreground hover:!bg-card active:!bg-accent focus-visible:!ring-ring'\n : '',\n ]\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"isOpen\"\n @click=\"toggle\"\n />\n </slot> \n </span> \n \n <PopoverPanel \n :open=\"isOpen\" \n :style=\"panelStyle\" \n :radius=\"resolvedRadius\" \n role=\"menu\" \n :aria-label=\"ariaLabel || triggerLabel || 'Menu'\" \n @update:panelRef=\"panelRef = $event\" \n > \n <ul \n ref=\"listEl\" \n class=\"modo-dropdown-list flex flex-col\" \n :style=\"{ minWidth }\" \n @keydown=\"onKeydown\" \n > \n <template v-for=\"(entry, idx) in entries\" :key=\"idx\"> \n <li v-if=\"isDivider(entry)\" role=\"separator\" class=\"my-1 h-px bg-border\" /> \n \n <li \n v-else-if=\"isHeader(entry)\" \n role=\"presentation\" \n class=\"px-3 pt-2 pb-1 text-caption font-semibold uppercase tracking-wider text-muted-foreground select-none\" \n > \n {{ entry.label }} \n </li> \n \n <li v-else role=\"none\"> \n <component \n :is=\"entry.href ? 'a' : 'button'\" \n :type=\"entry.href ? undefined : 'button'\" \n :href=\"entry.href && !entry.disabled ? entry.href : undefined\" \n :target=\"entry.external ? '_blank' : undefined\" \n :rel=\"entry.external ? 'noopener noreferrer' : undefined\" \n role=\"menuitem\" \n :tabindex=\"-1\" \n :aria-disabled=\"entry.disabled || undefined\" \n :data-active=\"idx === activeIndex || undefined\" \n :class=\"[\n 'modo-dropdown-item w-full flex items-center gap-2 px-3 py-2 text-left',\n 'text-body transition-colors duration-fast ease-standard',\n entry.disabled\n ? 'opacity-50 cursor-not-allowed'\n : entry.danger\n ? ['text-destructive', 'hover:bg-destructive/10', 'cursor-pointer']\n : [itemTextColor, itemHover, 'cursor-pointer'],\n !entry.disabled && idx === activeIndex\n ? (entry.danger ? 'bg-destructive/10' : itemSurface)\n : '',\n ]\" \n @click=\"onItemClick(entry, $event)\" \n @mouseenter=\"setActive(idx)\" \n @focus=\"setActive(idx)\" \n > \n <component \n :is=\"entry.icon\" \n v-if=\"entry.icon\" \n :class=\"[iconSizeClass, 'shrink-0', entry.danger ? 'text-destructive' : itemIconColor]\" \n aria-hidden=\"true\" \n /> \n <span class=\"flex flex-col min-w-0 flex-1\"> \n <span class=\"truncate\">{{ entry.label }}</span> \n <span \n v-if=\"entry.description\" \n class=\"text-caption text-muted-foreground truncate\" \n >{{ entry.description }}</span> \n </span> \n <span \n v-if=\"entry.shortcut\" \n class=\"ml-2 text-caption text-muted-foreground tabular-nums\" \n aria-hidden=\"true\" \n >{{ entry.shortcut }}</span> \n </component> \n </li> \n </template> \n </ul> \n </PopoverPanel> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, ref, watch, nextTick } from 'vue'; \nimport { ChevronDownIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../forms/Button.vue'; \nimport PopoverPanel from '../layout/PopoverPanel.vue'; \nimport { usePopover } from '../../composables/usePopover'; \nimport { useResolvedColor, useResolvedRadius, useResolvedSize } from '../../composables/useModoConfig'; \nimport type { \n DropdownMenu, \n DropdownMenuEntry, \n DropdownMenuItem, \n DropdownMenuDivider, \n DropdownMenuHeader, \n DropdownMenuEmits, \n} from '../../interfaces/navigation/DropdownMenu.interface'; \n \nconst props = withDefaults(defineProps<DropdownMenu>(), { \n triggerVariant: 'outline', \n color: 'default', \n showChevron: true, \n placement: 'bottom-start', \n matchTriggerWidth: false, \n minWidth: '12rem', \n disabled: false, \n closeOnSelect: true, \n}); \n \nconst emit = defineEmits<DropdownMenuEmits>(); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \nconst resolvedSize = useResolvedSize(() => props.size); \n \nconst entries = computed<DropdownMenuEntry[]>(() => props.items ?? []); \n \nfunction isDivider(e: DropdownMenuEntry): e is DropdownMenuDivider { \n return (e as { type?: string }).type === 'divider'; \n} \nfunction isHeader(e: DropdownMenuEntry): e is DropdownMenuHeader { \n return (e as { type?: string }).type === 'header'; \n} \nfunction isItem(e: DropdownMenuEntry): e is DropdownMenuItem { \n return !isDivider(e) && !isHeader(e); \n} \n \n/* ---------- Trigger ---------- */ \nconst effectiveTriggerIcon = computed(() => { \n if (props.triggerIcon) return props.triggerIcon; \n if (props.showChevron && props.triggerLabel) return ChevronDownIcon; \n if (props.showChevron && !props.triggerLabel) return ChevronDownIcon; \n return undefined; \n}); \n \n/* ---------- Popover ---------- */ \nconst { \n triggerRef, \n panelRef, \n isOpen, \n panelStyle, \n open, \n close, \n toggle, \n} = usePopover({ \n placement: () => props.placement, \n matchTriggerWidth: () => props.matchTriggerWidth, \n onOpen: () => emit('update:open', true), \n onClose: () => { \n emit('update:open', false); \n activeIndex.value = -1; \n }, \n}); \n \nconst triggerEl = ref<HTMLElement | null>(null); \nwatch(triggerEl, (el) => { triggerRef.value = el; }); \n \n/* ---------- Active item & keyboard ---------- */ \nconst listEl = ref<HTMLElement | null>(null); \nconst activeIndex = ref(-1); \n \nconst itemIndices = computed(() => \n entries.value \n .map((e, i) => (isItem(e) && !e.disabled ? i : -1)) \n .filter((i) => i !== -1), \n); \n \nfunction setActive(idx: number) { \n activeIndex.value = idx; \n} \n \nfunction moveActive(delta: number) { \n const order = itemIndices.value; \n if (!order.length) return; \n const cur = order.indexOf(activeIndex.value); \n const next = cur === -1 \n ? (delta > 0 ? 0 : order.length - 1) \n : (cur + delta + order.length) % order.length; \n activeIndex.value = order[next]; \n focusActive(); \n} \n \nfunction focusActive() { \n nextTick(() => { \n const el = listEl.value?.querySelector<HTMLElement>('[data-active=\"true\"]'); \n el?.focus({ preventScroll: true }); \n }); \n} \n \nwatch(isOpen, async (v) => { \n if (v) { \n await nextTick(); \n const order = itemIndices.value; \n if (order.length) { \n activeIndex.value = order[0]; \n focusActive(); \n } \n } \n}); \n \nfunction onKeydown(e: KeyboardEvent) { \n switch (e.key) { \n case 'ArrowDown': \n e.preventDefault(); \n moveActive(1); \n break; \n case 'ArrowUp': \n e.preventDefault(); \n moveActive(-1); \n break; \n case 'Home': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[0]; \n focusActive(); \n } \n break; \n case 'End': \n e.preventDefault(); \n if (itemIndices.value.length) { \n activeIndex.value = itemIndices.value[itemIndices.value.length - 1]; \n focusActive(); \n } \n break; \n case 'Enter': \n case ' ': { \n const entry = entries.value[activeIndex.value]; \n if (entry && isItem(entry) && !entry.disabled) { \n e.preventDefault(); \n onItemClick(entry); \n } \n break; \n } \n case 'Tab': \n close(); \n break; \n } \n} \n \nfunction onItemClick(entry: DropdownMenuItem, evt?: MouseEvent) { \n if (entry.disabled) { \n evt?.preventDefault(); \n return; \n } \n entry.onClick?.(entry); \n emit('select', entry); \n if (props.closeOnSelect) close(); \n} \n \n/* ---------- Visual scaling tied to size ---------- */ \nconst iconSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case 'small': return 'w-3.5 h-3.5';\n case 'large': return 'w-5 h-5';\n default: return 'w-4 h-4';\n }\n});\n\n/* ---------- Item surface / hover (color-aware) ---------- */\nconst effectiveItemColor = computed(() => props.color === 'default' ? 'default' : resolvedColor.value);\nconst triggerSurfaceClass = computed(() => {\n if (props.triggerVariant !== 'outline') return '';\n if (effectiveItemColor.value === 'danger') {\n return 'bg-destructive/10 hover:!bg-destructive/10 active:!bg-destructive/18';\n }\n return 'bg-card';\n});\nconst ITEM_SURFACE: Record<string, string> = {\n default: 'bg-accent',\n primary: 'bg-accent',\n danger: 'bg-destructive/16',\n success: 'bg-accent',\n warning: 'bg-accent',\n};\nconst ITEM_HOVER: Record<string, string> = {\n default: 'hover:bg-accent',\n primary: 'hover:bg-accent',\n danger: 'hover:bg-destructive/14',\n success: 'hover:bg-accent',\n warning: 'hover:bg-accent',\n};\nconst ITEM_TEXT: Record<string, string> = {\n default: 'text-foreground',\n primary: 'text-foreground',\n danger: 'text-destructive',\n success: 'text-foreground',\n warning: 'text-foreground',\n};\nconst ITEM_ICON: Record<string, string> = {\n default: 'modo-affordance-icon',\n primary: 'modo-affordance-icon',\n danger: 'text-destructive',\n success: 'modo-affordance-icon',\n warning: 'modo-affordance-icon',\n};\nconst itemSurface = computed(() => ITEM_SURFACE[effectiveItemColor.value] ?? 'bg-accent');\nconst itemHover = computed(() => ITEM_HOVER[effectiveItemColor.value] ?? 'hover:bg-accent');\nconst itemTextColor = computed(() => ITEM_TEXT[effectiveItemColor.value] ?? 'text-foreground');\nconst itemIconColor = computed(() => ITEM_ICON[effectiveItemColor.value] ?? 'modo-affordance-icon');\n\ndefineExpose({ open, close, toggle }); \n</script> \n \n<style scoped> \n.modo-dropdown-item { \n /* Native focus ring is suppressed: hover/data-active styling provides \n the visual cue. Container is `role=\"menu\"`, items are reachable via \n roving tabindex. */ \n outline: none; \n} \n.modo-dropdown-item:focus-visible { \n outline: none; \n} \n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2HA,MAAM,QAAQ;EAWd,MAAM,OAAO;EAEb,MAAM,gBAAgB,uBAAuB,MAAM,MAAM;EACzD,MAAM,iBAAiB,wBAAwB,MAAM,OAAO;EAC5D,MAAM,eAAe,sBAAsB,MAAM,KAAK;EAEtD,MAAM,UAAU,eAAoC,MAAM,SAAS,EAAE,CAAC;EAEtE,SAAS,UAAU,GAAgD;GAC/D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,SAAS,GAA+C;GAC7D,OAAQ,EAAwB,SAAS;;EAE7C,SAAS,OAAO,GAA6C;GACzD,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE;;EAIxC,MAAM,uBAAuB,eAAe;GACxC,IAAI,MAAM,aAAa,OAAO,MAAM;GACpC,IAAI,MAAM,eAAe,MAAM,cAAc,OAAO;GACpD,IAAI,MAAM,eAAe,CAAC,MAAM,cAAc,OAAO;IAEvD;EAGF,MAAM,EACF,YACA,UACA,QACA,YACA,MACA,OACA,WACA,WAAW;GACX,iBAAiB,MAAM;GACvB,yBAAyB,MAAM;GAC/B,cAAc,KAAK,eAAe,KAAK;GACvC,eAAe;IACX,KAAK,eAAe,MAAM;IAC1B,YAAY,QAAQ;;GAE3B,CAAC;EAEF,MAAM,YAAY,IAAwB,KAAK;EAC/C,MAAM,YAAY,OAAO;GAAE,WAAW,QAAQ;IAAM;EAGpD,MAAM,SAAS,IAAwB,KAAK;EAC5C,MAAM,cAAc,IAAI,GAAG;EAE3B,MAAM,cAAc,eAChB,QAAQ,MACH,KAAK,GAAG,MAAO,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,IAAI,GAAI,CAClD,QAAQ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V,iBAAe,MAAM,YAAY,KAAA;MACjC,eAAa,QAAQ,YAAA,SAAe,KAAA;MACpC,OAAK,eAAA;;;OAAwO,MAAM,WAAA,kCAAqH,MAAM,SAAA;;;;;QAA8J,cAAA;QAAe,UAAA;QAAS;QAAA;QAAsD,MAAM,YAAY,QAAQ,YAAA,QAAmD,MAAM,SAAM,sBAAyB,YAAA,QAAA;;MAY5sB,UAAK,WAAE,YAAY,OAAO,OAAM;MAChC,eAAU,WAAE,UAAU,IAAG;MACzB,UAAK,WAAE,UAAU,IAAG;;6BAOnB;OAHQ,MAAM,QAAA,WAAA,EAFhB,YAKE,wBAJO,MAAM,KAAI,EAAA;;QAEd,OAAK,eAAA;SAAG,cAAA;SAAa;SAAc,MAAM,SAAM,qBAAwB,cAAA;SAAa,CAAA;QACrF,eAAY;;OAEhB,mBAMO,QANP,YAMO,CALH,mBAA+C,QAA/C,YAA+C,gBAArB,MAAM,MAAK,EAAA,EAAA,EAE3B,MAAM,eAAA,WAAA,EADhB,mBAG+B,QAH/B,YAG+B,gBAA3B,MAAM,YAAW,EAAA,EAAA,IAAA,mBAAA,IAAA,KAAA,CAAA,CAAA;OAGf,MAAM,YAAA,WAAA,EADhB,mBAI4B,QAJ5B,YAI4B,gBAAxB,MAAM,SAAQ,EAAA,EAAA,IAAA,mBAAA,IAAA,KAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Switcher.cjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
1
+ {"version":3,"file":"Switcher.cjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center text-left transition-colors',\n triggerSizeClass,\n 'border bg-card text-card-foreground border-input hover:border-input-hover',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n v-if=\"activeItem?.avatar\"\n data-modo-switcher-lead\n :class=\"['shrink-0', sized ? ['inline-flex items-center justify-center', sized.leadAvatar] : '']\"\n >\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n :size=\"sized ? 'xsmall' : 'small'\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n data-modo-switcher-lead\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center bg-accent/60 text-foreground',\n sized ? sized.lead : 'w-9 h-9',\n radiusClass,\n ]\"\n >\n <component\n :is=\"activeItem.icon\"\n :class=\"sized ? sized.leadIcon : 'w-5 h-5'\"\n aria-hidden=\"true\"\n />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span :class=\"['truncate font-medium', sized ? sizeTokens.text : 'text-body']\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!sized && !compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n :class=\"['shrink-0 text-muted-foreground', sized ? sizeTokens.icon : 'w-4 h-4']\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n :class=\"['shrink-0 text-muted-foreground', sized ? sizeTokens.icon : 'w-4 h-4']\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-input rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport { SIZE_TOKENS, normalizeSize } from \"../../config/sizes\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\n// Opt-in sizing: without an explicit `size` the trigger keeps its original\n// two-line look (padding-driven height). With one, it becomes a single-line\n// control that shares height / padding / font / icon tokens with Button, Input\n// and Select, and the subtitle is dropped so the line fits the control height.\nconst LEADING: Record<string, { lead: string; leadIcon: string; leadAvatar: string }> = {\n xsmall: { lead: \"w-5 h-5\", leadIcon: \"w-3 h-3\", leadAvatar: \"[&>div>*]:!w-5 [&>div>*]:!h-5\" },\n small: { lead: \"w-6 h-6\", leadIcon: \"w-3.5 h-3.5\", leadAvatar: \"[&>div>*]:!w-6 [&>div>*]:!h-6\" },\n medium: { lead: \"w-7 h-7\", leadIcon: \"w-4 h-4\", leadAvatar: \"[&>div>*]:!w-7 [&>div>*]:!h-7\" },\n large: { lead: \"w-8 h-8\", leadIcon: \"w-5 h-5\", leadAvatar: \"[&>div>*]:!w-8 [&>div>*]:!h-8\" },\n};\nconst sizeTokens = computed(() => SIZE_TOKENS[normalizeSize(props.size)]);\nconst sized = computed(() =>\n props.size ? LEADING[normalizeSize(props.size)] : null,\n);\nconst triggerSizeClass = computed(() =>\n sized.value\n ? `${sizeTokens.value.control} ${sizeTokens.value.padX} ${sizeTokens.value.gap}`\n : \"gap-3 px-3 py-2\",\n);\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"Switcher.mjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center gap-3 px-3 py-2 text-left transition-colors',\n 'border bg-card text-card-foreground border-border',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span v-if=\"activeItem?.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"activeItem.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-border rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}
1
+ {"version":3,"file":"Switcher.mjs","names":[],"sources":["../../../src/components/navigation/Switcher.vue"],"sourcesContent":["<template>\n <div class=\"modo-switcher inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <span ref=\"triggerWrapEl\" class=\"inline-flex\" :class=\"{ 'w-full': fullWidth }\">\n <slot\n name=\"trigger\"\n :activeItem=\"activeItem\"\n :isOpen=\"isOpen\"\n :toggle=\"onTriggerClick\"\n >\n <button\n ref=\"triggerEl\"\n type=\"button\"\n data-modo-switcher-trigger\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen\"\n :aria-label=\"resolvedAriaLabel\"\n :disabled=\"disabled\"\n :class=\"[\n 'inline-flex items-center text-left transition-colors',\n triggerSizeClass,\n 'border bg-card text-card-foreground border-input hover:border-input-hover',\n 'hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60',\n radiusClass,\n fullWidth ? 'w-full' : '',\n disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n v-if=\"activeItem?.avatar\"\n data-modo-switcher-lead\n :class=\"['shrink-0', sized ? ['inline-flex items-center justify-center', sized.leadAvatar] : '']\"\n >\n <Avatar\n :src=\"activeItem.avatar.src\"\n :initials=\"activeItem.avatar.initials\"\n :name=\"activeItem.title\"\n :size=\"sized ? 'xsmall' : 'small'\"\n />\n </span>\n <span\n v-else-if=\"activeItem?.icon\"\n data-modo-switcher-lead\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center bg-accent/60 text-foreground',\n sized ? sized.lead : 'w-9 h-9',\n radiusClass,\n ]\"\n >\n <component\n :is=\"activeItem.icon\"\n :class=\"sized ? sized.leadIcon : 'w-5 h-5'\"\n aria-hidden=\"true\"\n />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span :class=\"['truncate font-medium', sized ? sizeTokens.text : 'text-body']\">\n {{ activeItem ? activeItem.title : resolvedPlaceholder }}\n </span>\n <span\n v-if=\"!sized && !compactTrigger && activeItem?.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >\n {{ activeItem.subtitle }}\n </span>\n </span>\n <ChevronUpDownIcon\n v-if=\"chevron === 'updown'\"\n :class=\"['shrink-0 text-muted-foreground', sized ? sizeTokens.icon : 'w-4 h-4']\"\n aria-hidden=\"true\"\n />\n <ChevronDownIcon\n v-else-if=\"chevron === 'down'\"\n :class=\"['shrink-0 text-muted-foreground', sized ? sizeTokens.icon : 'w-4 h-4']\"\n aria-hidden=\"true\"\n />\n </button>\n </slot>\n </span>\n\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"resolvedRadius\"\n role=\"dialog\"\n :aria-label=\"resolvedAriaLabel\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div\n data-modo-switcher-panel\n class=\"modo-switcher-panel overflow-y-auto\"\n :style=\"{ maxHeight: panelMaxHeightStyle }\"\n >\n <div\n v-if=\"panelTitle\"\n class=\"px-3 pt-3 pb-2 text-caption text-muted-foreground uppercase tracking-wider\"\n >\n {{ panelTitle }}\n </div>\n\n <div v-if=\"searchable\" class=\"px-2 pt-2 pb-1\">\n <input\n ref=\"searchInputEl\"\n v-model=\"searchQuery\"\n role=\"searchbox\"\n type=\"text\"\n :placeholder=\"resolvedSearchPlaceholder\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"activeDescendantId\"\n class=\"w-full px-2 py-1.5 text-body bg-background border border-input rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60\"\n @keydown=\"onSearchKeydown\"\n />\n </div>\n\n <template v-if=\"loading\">\n <slot name=\"loading\">\n <div class=\"p-2 flex flex-col gap-1\">\n <div\n v-for=\"i in 3\"\n :key=\"i\"\n data-modo-switcher-skeleton\n >\n <Skeleton height=\"44px\" />\n </div>\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"items.length === 0\">\n <slot name=\"empty\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedEmptyText }}\n </div>\n </slot>\n </template>\n\n <template v-else-if=\"displayedItems.length === 0\">\n <div class=\"px-3 py-6 text-center text-muted-foreground text-body\">\n {{ resolvedNoResults }}\n </div>\n </template>\n\n <ul\n v-else\n role=\"listbox\"\n :id=\"listboxId\"\n class=\"flex flex-col\"\n @keydown=\"onListKeydown\"\n >\n <li\n v-for=\"(item, idx) in displayedItems\"\n :key=\"item.value\"\n :ref=\"(el) => setOptionRef(el as HTMLElement | null, idx)\"\n role=\"option\"\n :id=\"`${listboxId}-opt-${idx}`\"\n :aria-selected=\"item.value === modelValue\"\n :aria-current=\"item.value === modelValue ? 'true' : undefined\"\n :aria-disabled=\"item.disabled || undefined\"\n :data-active=\"item.value === modelValue || undefined\"\n :tabindex=\"-1\"\n class=\"modo-switcher-item flex items-center gap-3 px-3 py-2 cursor-pointer\"\n :class=\"[\n item.value === modelValue ? 'bg-accent/40' : '',\n searchable && idx === highlightedIdx ? 'bg-accent' : 'hover:bg-accent',\n item.disabled ? 'opacity-50 cursor-not-allowed' : '',\n ]\"\n @click=\"selectItem(item)\"\n @mouseenter=\"searchable ? (highlightedIdx = idx) : null\"\n >\n <span v-if=\"item.avatar\" class=\"shrink-0\">\n <Avatar\n :src=\"item.avatar.src\"\n :initials=\"item.avatar.initials\"\n :name=\"item.title\"\n size=\"small\"\n />\n </span>\n <span\n v-else-if=\"item.icon\"\n data-modo-switcher-iconwrap\n :class=\"[\n 'shrink-0 inline-flex items-center justify-center w-9 h-9 bg-accent/60 text-foreground',\n radiusClass,\n ]\"\n >\n <component :is=\"item.icon\" class=\"w-5 h-5\" aria-hidden=\"true\" />\n </span>\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate text-body font-medium\">{{ item.title }}</span>\n <span\n v-if=\"item.subtitle\"\n class=\"truncate text-caption text-muted-foreground\"\n >{{ item.subtitle }}</span>\n </span>\n <slot\n name=\"item-trailing\"\n :item=\"item\"\n :active=\"item.value === modelValue\"\n :close=\"close\"\n >\n <CheckIcon\n v-if=\"item.value === modelValue\"\n class=\"w-4 h-4 shrink-0\"\n aria-hidden=\"true\"\n />\n </slot>\n </li>\n </ul>\n\n <template v-if=\"$slots.footer\">\n <hr\n data-modo-switcher-footer-sep\n role=\"separator\"\n class=\"my-1 border-t border-border\"\n />\n <div class=\"p-1\">\n <slot name=\"footer\" :close=\"close\" />\n </div>\n </template>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch, watchEffect } from \"vue\";\nimport { ChevronUpDownIcon, ChevronDownIcon, CheckIcon } from \"@heroicons/vue/24/outline\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Avatar from \"../data-display/avatar/Avatar.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport { SIZE_TOKENS, normalizeSize } from \"../../config/sizes\";\nimport {\n useResolvedRadius,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport type {\n Switcher as SwitcherProps,\n SwitcherEmits,\n SwitcherItem,\n SwitcherValue,\n} from \"../../interfaces/navigation/Switcher.interface\";\n\nconst props = withDefaults(defineProps<SwitcherProps>(), {\n modelValue: null,\n chevron: \"updown\",\n triggerVariant: \"outline\",\n compactTrigger: false,\n fullWidth: false,\n panelWidth: \"trigger\",\n panelMinWidth: \"15rem\",\n panelMaxHeight: 320,\n placement: \"bottom-start\",\n searchable: false,\n loading: false,\n disabled: false,\n});\n\nconst emit = defineEmits<SwitcherEmits>();\n\nconst locale = useModoLocale();\nconst resolvedRadius = useResolvedRadius(() => props.radius);\nconst listboxId = useId();\n\nconst resolvedPlaceholder = computed(\n () => props.placeholder ?? locale.value.switcher.placeholder,\n);\nconst resolvedAriaLabel = computed(\n () => props.ariaLabel ?? locale.value.switcher.ariaLabel,\n);\nconst resolvedEmptyText = computed(\n () => props.emptyText ?? locale.value.switcher.empty,\n);\nconst resolvedSearchPlaceholder = computed(\n () => props.searchPlaceholder ?? locale.value.switcher.searchPlaceholder,\n);\nconst resolvedNoResults = computed(\n () => props.noResultsText ?? locale.value.switcher.noResults,\n);\n\nconst searchQuery = ref(\"\");\nconst searchInputEl = ref<HTMLInputElement | null>(null);\n\nconst displayedItems = computed<SwitcherItem[]>(() => {\n if (!props.searchable) return props.items;\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return props.items;\n const fields = props.searchFields ?? [\"title\", \"subtitle\"];\n return props.items.filter((it) =>\n fields.some((f) => {\n const v = it[f];\n return typeof v === \"string\" && v.toLowerCase().includes(q);\n }),\n );\n});\n\nwatch(searchQuery, (q) => {\n emit(\"search\", q);\n});\n\nconst radiusClass = computed(() => {\n switch (resolvedRadius.value) {\n case \"none\": return \"rounded-none\";\n case \"small\": return \"rounded-sm\";\n case \"large\": return \"rounded-lg\";\n case \"full\": return \"rounded-[999px]\";\n default: return \"rounded-md\";\n }\n});\n\n// Opt-in sizing: without an explicit `size` the trigger keeps its original\n// two-line look (padding-driven height). With one, it becomes a single-line\n// control that shares height / padding / font / icon tokens with Button, Input\n// and Select, and the subtitle is dropped so the line fits the control height.\nconst LEADING: Record<string, { lead: string; leadIcon: string; leadAvatar: string }> = {\n xsmall: { lead: \"w-5 h-5\", leadIcon: \"w-3 h-3\", leadAvatar: \"[&>div>*]:!w-5 [&>div>*]:!h-5\" },\n small: { lead: \"w-6 h-6\", leadIcon: \"w-3.5 h-3.5\", leadAvatar: \"[&>div>*]:!w-6 [&>div>*]:!h-6\" },\n medium: { lead: \"w-7 h-7\", leadIcon: \"w-4 h-4\", leadAvatar: \"[&>div>*]:!w-7 [&>div>*]:!h-7\" },\n large: { lead: \"w-8 h-8\", leadIcon: \"w-5 h-5\", leadAvatar: \"[&>div>*]:!w-8 [&>div>*]:!h-8\" },\n};\nconst sizeTokens = computed(() => SIZE_TOKENS[normalizeSize(props.size)]);\nconst sized = computed(() =>\n props.size ? LEADING[normalizeSize(props.size)] : null,\n);\nconst triggerSizeClass = computed(() =>\n sized.value\n ? `${sizeTokens.value.control} ${sizeTokens.value.padX} ${sizeTokens.value.gap}`\n : \"gap-3 px-3 py-2\",\n);\n\nconst panelMaxHeightStyle = computed(() => {\n const v = props.panelMaxHeight;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\nconst panelMinWidthStyle = computed(() => {\n const v = props.panelMinWidth;\n if (v == null) return undefined;\n return typeof v === \"number\" ? `${v}px` : v;\n});\n\n// The popover composable sizes the panel to the trigger width when\n// `panelWidth='trigger'`. A narrow trigger (e.g. an avatar-only custom\n// trigger) would otherwise crush the panel — `minWidth` floors it.\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(panelMinWidthStyle.value ? { minWidth: panelMinWidthStyle.value } : {}),\n}));\n\nconst activeItem = computed<SwitcherItem | null>(() => {\n if (props.modelValue == null) return null;\n return props.items.find((i) => i.value === props.modelValue) ?? null;\n});\n\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open,\n close,\n toggle,\n} = usePopover({\n placement: () => props.placement,\n matchTriggerWidth: () => props.panelWidth === \"trigger\",\n closeOnEscape: false,\n onOpen: () => emit(\"open\"),\n onClose: () => {\n searchQuery.value = \"\";\n emit(\"close\");\n },\n});\n\nconst triggerEl = ref<HTMLElement | null>(null);\nconst triggerWrapEl = ref<HTMLElement | null>(null);\nwatch([triggerEl, triggerWrapEl], ([btn, wrap]) => {\n triggerRef.value = (btn as HTMLElement | null) ?? (wrap as HTMLElement | null);\n});\n\nfunction focusTrigger() {\n const el = triggerEl.value ?? triggerWrapEl.value;\n el?.focus?.();\n}\n\nfunction onTriggerClick() {\n if (props.disabled) return;\n toggle();\n}\n\nfunction selectItem(item: SwitcherItem) {\n if (item.disabled || props.disabled) return;\n emit(\"update:modelValue\", item.value);\n emit(\"change\", item.value, item);\n close();\n}\n\nfunction focusableIndices(): number[] {\n return displayedItems.value\n .map((it, i) => (it.disabled ? -1 : i))\n .filter((i) => i !== -1);\n}\n\nconst optionRefs = new Map<number, HTMLElement>();\nfunction setOptionRef(el: HTMLElement | null, idx: number) {\n if (el) optionRefs.set(idx, el);\n else optionRefs.delete(idx);\n}\n\nfunction focusOptionByIdx(idx: number) {\n optionRefs.get(idx)?.focus();\n}\n\nasync function openAndFocusActive() {\n if (props.disabled) return;\n if (!isOpen.value) open();\n await nextTick();\n if (props.searchable) {\n searchInputEl.value?.focus();\n return;\n }\n const order = focusableIndices();\n if (!order.length) return;\n const activeIdx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue,\n );\n const usable =\n activeIdx >= 0 && !displayedItems.value[activeIdx].disabled\n ? activeIdx\n : order[0];\n focusOptionByIdx(usable);\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n e.preventDefault();\n openAndFocusActive();\n } else if (e.key === \"Escape\" && isOpen.value) {\n e.preventDefault();\n close();\n }\n}\n\nfunction currentFocusedIdx(): number {\n const el = document.activeElement as HTMLElement | null;\n if (!el) return -1;\n for (const [idx, node] of optionRefs.entries()) {\n if (node === el) return idx;\n }\n return -1;\n}\n\nfunction moveFocus(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = currentFocusedIdx();\n let pos = order.indexOf(cur);\n if (pos === -1) {\n focusOptionByIdx(delta > 0 ? order[0] : order[order.length - 1]);\n return;\n }\n pos = (pos + delta + order.length) % order.length;\n focusOptionByIdx(order[pos]);\n}\n\nfunction onListKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveFocus(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveFocus(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[0]);\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) focusOptionByIdx(order[order.length - 1]);\n } else if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n const idx = currentFocusedIdx();\n if (idx >= 0) selectItem(displayedItems.value[idx]);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n } else if (\n !props.searchable &&\n e.key.length === 1 &&\n /^[a-zA-Z0-9]$/.test(e.key)\n ) {\n const order = focusableIndices();\n const letter = e.key.toLowerCase();\n const match = order.find((i) =>\n displayedItems.value[i].title.toLowerCase().startsWith(letter),\n );\n if (match !== undefined) focusOptionByIdx(match);\n }\n}\n\nwatch(isOpen, (open) => {\n if (!open) focusTrigger();\n});\n\nconst highlightedIdx = ref<number>(-1);\n\nconst activeDescendantId = computed(() =>\n highlightedIdx.value >= 0\n ? `${listboxId}-opt-${highlightedIdx.value}`\n : undefined,\n);\n\nwatch(displayedItems, () => {\n if (!props.searchable) return;\n const order = focusableIndices();\n highlightedIdx.value = order[0] ?? -1;\n});\n\nwatch(isOpen, (open) => {\n if (!open) {\n highlightedIdx.value = -1;\n return;\n }\n if (!props.searchable) return;\n const idx = displayedItems.value.findIndex(\n (it) => it.value === props.modelValue && !it.disabled,\n );\n const order = focusableIndices();\n highlightedIdx.value = idx >= 0 ? idx : order[0] ?? -1;\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = focusableIndices();\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n if (cur === -1) {\n highlightedIdx.value = delta > 0 ? order[0] : order[order.length - 1];\n return;\n }\n const next = (cur + delta + order.length) % order.length;\n highlightedIdx.value = order[next];\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveHighlight(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveHighlight(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[0];\n } else if (e.key === \"End\") {\n e.preventDefault();\n const order = focusableIndices();\n if (order.length) highlightedIdx.value = order[order.length - 1];\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (highlightedIdx.value >= 0) {\n selectItem(displayedItems.value[highlightedIdx.value]);\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n close();\n focusTrigger();\n }\n}\n\n// Dev-only: warn once per offending item when both icon and avatar are set.\nif (import.meta.env?.DEV ?? true) {\n const warned = new Set<SwitcherValue>();\n watchEffect(() => {\n for (const item of props.items) {\n if (item.icon && item.avatar && !warned.has(item.value)) {\n warned.add(item.value);\n console.warn(\n `[Switcher] item \"${item.value}\" declares both \\`icon\\` and \\`avatar\\`; \\`avatar\\` wins. Pick one.`,\n );\n }\n }\n });\n}\n\ndefineExpose({ open, close, toggle });\n</script>\n"],"mappings":""}