{"version":3,"file":"mention-dropdown2.mjs","names":[],"sources":["../../../../../../packages/components/mention/src/mention-dropdown.vue"],"sourcesContent":["<template>\n  <div ref=\"dropdownRef\" :class=\"ns.b('dropdown')\">\n    <div v-if=\"$slots.header\" :class=\"ns.be('dropdown', 'header')\">\n      <slot name=\"header\" />\n    </div>\n    <el-scrollbar\n      v-show=\"options.length > 0 && !loading\"\n      :id=\"contentId\"\n      ref=\"scrollbarRef\"\n      tag=\"ul\"\n      :wrap-class=\"ns.be('dropdown', 'wrap')\"\n      :view-class=\"ns.be('dropdown', 'list')\"\n      role=\"listbox\"\n      :aria-label=\"ariaLabel\"\n      aria-orientation=\"vertical\"\n    >\n      <li\n        v-for=\"(item, index) in options\"\n        :id=\"`${contentId}-${index}`\"\n        ref=\"optionRefs\"\n        :key=\"index\"\n        :class=\"optionkls(item, index)\"\n        role=\"option\"\n        :aria-disabled=\"item.disabled || disabled || undefined\"\n        :aria-selected=\"hoveringIndex === index\"\n        @mousemove=\"handleMouseEnter(index)\"\n        @click.stop=\"handleSelect(item)\"\n      >\n        <slot name=\"label\" :item=\"item\" :index=\"index\">\n          <span>{{ item.label ?? item.value }}</span>\n        </slot>\n      </li>\n    </el-scrollbar>\n    <div v-if=\"loading\" :class=\"ns.be('dropdown', 'loading')\">\n      <slot name=\"loading\"> {{ t('el.mention.loading') }} </slot>\n    </div>\n    <div v-if=\"$slots.footer\" :class=\"ns.be('dropdown', 'footer')\">\n      <slot name=\"footer\" />\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, nextTick, ref, watch } from 'vue'\nimport { useLocale, useNamespace } from '@element-plus/hooks'\nimport { scrollIntoView } from '@element-plus/utils'\nimport ElScrollbar from '@element-plus/components/scrollbar'\nimport { mentionDropdownEmits } from './mention-dropdown'\n\nimport type { MentionDropdownProps } from './mention-dropdown'\nimport type { MentionOption } from './types'\n\ndefineOptions({\n  name: 'ElMentionDropdown',\n})\n\nconst props = withDefaults(defineProps<MentionDropdownProps>(), {\n  options: () => [],\n})\nconst emit = defineEmits(mentionDropdownEmits)\n\nconst ns = useNamespace('mention')\nconst { t } = useLocale()\nconst hoveringIndex = ref(-1)\n\nconst scrollbarRef = ref<InstanceType<typeof ElScrollbar>>()\nconst optionRefs = ref<HTMLElement[]>()\nconst dropdownRef = ref<HTMLElement>()\n\nconst optionkls = (item: MentionOption, index: number) => [\n  ns.be('dropdown', 'item'),\n  ns.is('hovering', hoveringIndex.value === index),\n  ns.is('disabled', item.disabled || props.disabled),\n]\n\nconst handleSelect = (item: MentionOption) => {\n  if (item.disabled || props.disabled) return\n  emit('select', item)\n}\n\nconst handleMouseEnter = (index: number) => {\n  hoveringIndex.value = index\n}\n\nconst filteredAllDisabled = computed(\n  () => props.disabled || props.options.every((item) => item.disabled)\n)\n\nconst hoverOption = computed(() => props.options[hoveringIndex.value])\n\nconst selectHoverOption = () => {\n  if (!hoverOption.value || hoverOption.value.disabled || props.disabled) return\n  emit('select', hoverOption.value)\n}\n\nconst navigateOptions = (direction: 'next' | 'prev') => {\n  const { options } = props\n  if (options.length === 0 || filteredAllDisabled.value) return\n\n  if (direction === 'next') {\n    hoveringIndex.value++\n    if (hoveringIndex.value === options.length) {\n      hoveringIndex.value = 0\n    }\n  } else if (direction === 'prev') {\n    hoveringIndex.value--\n    if (hoveringIndex.value < 0) {\n      hoveringIndex.value = options.length - 1\n    }\n  }\n  const option = options[hoveringIndex.value]\n  if (option.disabled) {\n    navigateOptions(direction)\n    return\n  }\n  nextTick(() => scrollToOption(option))\n}\n\nconst scrollToOption = (option: MentionOption) => {\n  const { options } = props\n\n  const index = options.findIndex((item) => item.value === option.value)\n  const target = optionRefs.value?.[index]\n\n  if (target) {\n    const menu = dropdownRef.value?.querySelector?.(\n      `.${ns.be('dropdown', 'wrap')}`\n    )\n    if (menu) {\n      scrollIntoView(menu as HTMLElement, target)\n    }\n  }\n  scrollbarRef.value?.handleScroll()\n}\n\nconst resetHoveringIndex = () => {\n  if (filteredAllDisabled.value || props.options.length === 0) {\n    hoveringIndex.value = -1\n  } else {\n    hoveringIndex.value = props.options.findIndex((item) => !item.disabled)\n  }\n}\n\nwatch(() => props.options, resetHoveringIndex, {\n  immediate: true,\n})\n\ndefineExpose({\n  hoveringIndex,\n  navigateOptions,\n  selectHoverOption,\n  hoverOption,\n})\n</script>\n"],"mappings":""}