{"version":3,"file":"mention-dropdown2.js","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=\"item.value\"\n        :class=\"optionkls(item, index)\"\n        role=\"option\"\n        :aria-disabled=\"item.disabled || disabled || undefined\"\n        :aria-selected=\"hoveringIndex === index\"\n        @mouseenter=\"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<script setup lang=\"ts\">\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, mentionDropdownProps } from './mention-dropdown'\n\nimport type { MentionOption } from './types'\n\ndefineOptions({\n  name: 'ElMentionDropdown',\n})\n\nconst props = defineProps(mentionDropdownProps)\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) 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 = 0\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"],"names":["useNamespace","useLocale","ref","computed","nextTick","scrollIntoView","watch"],"mappings":";;;;;;;;;;;;;;uCAkDc,CAAA;AAAA,EACZ,IAAM,EAAA,mBAAA;AACR,CAAA,CAAA,CAAA;;;;;;;AAKA,IAAM,MAAA,EAAA,GAAKA,mBAAa,SAAS,CAAA,CAAA;AACjC,IAAM,MAAA,EAAE,MAAMC,iBAAU,EAAA,CAAA;AACxB,IAAM,MAAA,aAAA,GAAgBC,QAAI,CAAE,CAAA,CAAA,CAAA;AAE5B,IAAA,MAAM,eAAeA,OAAsC,EAAA,CAAA;AAC3D,IAAA,MAAM,aAAaA,OAAmB,EAAA,CAAA;AACtC,IAAA,MAAM,cAAcA,OAAiB,EAAA,CAAA;AAErC,IAAM,MAAA,SAAA,GAAY,CAAC,IAAA,EAAqB,KAAkB,KAAA;AAAA,MACxD,EAAA,CAAG,EAAG,CAAA,UAAA,EAAY,MAAM,CAAA;AAAA,MACxB,EAAG,CAAA,EAAA,CAAG,UAAY,EAAA,aAAA,CAAc,UAAU,KAAK,CAAA;AAAA,MAC/C,GAAG,EAAG,CAAA,UAAA,EAAY,IAAK,CAAA,QAAA,IAAY,MAAM,QAAQ,CAAA;AAAA,KACnD,CAAA;AAEA,IAAM,MAAA,YAAA,GAAe,CAAC,IAAwB,KAAA;AAC5C,MAAI,IAAA,IAAA,CAAK,YAAY,KAAM,CAAA,QAAA;AAAU,QAAA,OAAA;AACrC,MAAA,IAAA,CAAK,UAAU,IAAI,CAAA,CAAA;AAAA,KACrB,CAAA;AAEA,IAAM,MAAA,gBAAA,GAAmB,CAAC,KAAkB,KAAA;AAC1C,MAAA,aAAA,CAAc,KAAQ,GAAA,KAAA,CAAA;AAAA,KACxB,CAAA;AAEA,IAAA,MAAM,mBAAsB,GAAAC,YAAA,CAC1B,MAAM,KA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