d5519eaac85a153f65dd624df8ace336b08ed75ec95dd2f76163d5e7cb2226bbe32e23fe8b16e37ce6fb61e893ddb960f4f2b604ec5ed8ade74b58581361c3 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$2 = require('../../scrollbar/index.js');
  5. var mentionDropdown = require('./mention-dropdown.js');
  6. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  7. var index = require('../../../hooks/use-namespace/index.js');
  8. var index$1 = require('../../../hooks/use-locale/index.js');
  9. var scroll = require('../../../utils/dom/scroll.js');
  10. const __default__ = vue.defineComponent({
  11. name: "ElMentionDropdown"
  12. });
  13. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  14. ...__default__,
  15. props: mentionDropdown.mentionDropdownProps,
  16. emits: mentionDropdown.mentionDropdownEmits,
  17. setup(__props, { expose, emit }) {
  18. const props = __props;
  19. const ns = index.useNamespace("mention");
  20. const { t } = index$1.useLocale();
  21. const hoveringIndex = vue.ref(-1);
  22. const scrollbarRef = vue.ref();
  23. const optionRefs = vue.ref();
  24. const dropdownRef = vue.ref();
  25. const optionkls = (item, index) => [
  26. ns.be("dropdown", "item"),
  27. ns.is("hovering", hoveringIndex.value === index),
  28. ns.is("disabled", item.disabled || props.disabled)
  29. ];
  30. const handleSelect = (item) => {
  31. if (item.disabled || props.disabled)
  32. return;
  33. emit("select", item);
  34. };
  35. const handleMouseEnter = (index) => {
  36. hoveringIndex.value = index;
  37. };
  38. const filteredAllDisabled = vue.computed(() => props.disabled || props.options.every((item) => item.disabled));
  39. const hoverOption = vue.computed(() => props.options[hoveringIndex.value]);
  40. const selectHoverOption = () => {
  41. if (!hoverOption.value)
  42. return;
  43. emit("select", hoverOption.value);
  44. };
  45. const navigateOptions = (direction) => {
  46. const { options } = props;
  47. if (options.length === 0 || filteredAllDisabled.value)
  48. return;
  49. if (direction === "next") {
  50. hoveringIndex.value++;
  51. if (hoveringIndex.value === options.length) {
  52. hoveringIndex.value = 0;
  53. }
  54. } else if (direction === "prev") {
  55. hoveringIndex.value--;
  56. if (hoveringIndex.value < 0) {
  57. hoveringIndex.value = options.length - 1;
  58. }
  59. }
  60. const option = options[hoveringIndex.value];
  61. if (option.disabled) {
  62. navigateOptions(direction);
  63. return;
  64. }
  65. vue.nextTick(() => scrollToOption(option));
  66. };
  67. const scrollToOption = (option) => {
  68. var _a, _b, _c, _d;
  69. const { options } = props;
  70. const index = options.findIndex((item) => item.value === option.value);
  71. const target = (_a = optionRefs.value) == null ? void 0 : _a[index];
  72. if (target) {
  73. const menu = (_c = (_b = dropdownRef.value) == null ? void 0 : _b.querySelector) == null ? void 0 : _c.call(_b, `.${ns.be("dropdown", "wrap")}`);
  74. if (menu) {
  75. scroll.scrollIntoView(menu, target);
  76. }
  77. }
  78. (_d = scrollbarRef.value) == null ? void 0 : _d.handleScroll();
  79. };
  80. const resetHoveringIndex = () => {
  81. if (filteredAllDisabled.value || props.options.length === 0) {
  82. hoveringIndex.value = -1;
  83. } else {
  84. hoveringIndex.value = 0;
  85. }
  86. };
  87. vue.watch(() => props.options, resetHoveringIndex, {
  88. immediate: true
  89. });
  90. expose({
  91. hoveringIndex,
  92. navigateOptions,
  93. selectHoverOption,
  94. hoverOption
  95. });
  96. return (_ctx, _cache) => {
  97. return vue.openBlock(), vue.createElementBlock("div", {
  98. ref_key: "dropdownRef",
  99. ref: dropdownRef,
  100. class: vue.normalizeClass(vue.unref(ns).b("dropdown"))
  101. }, [
  102. _ctx.$slots.header ? (vue.openBlock(), vue.createElementBlock("div", {
  103. key: 0,
  104. class: vue.normalizeClass(vue.unref(ns).be("dropdown", "header"))
  105. }, [
  106. vue.renderSlot(_ctx.$slots, "header")
  107. ], 2)) : vue.createCommentVNode("v-if", true),
  108. vue.withDirectives(vue.createVNode(vue.unref(index$2.ElScrollbar), {
  109. id: _ctx.contentId,
  110. ref_key: "scrollbarRef",
  111. ref: scrollbarRef,
  112. tag: "ul",
  113. "wrap-class": vue.unref(ns).be("dropdown", "wrap"),
  114. "view-class": vue.unref(ns).be("dropdown", "list"),
  115. role: "listbox",
  116. "aria-label": _ctx.ariaLabel,
  117. "aria-orientation": "vertical"
  118. }, {
  119. default: vue.withCtx(() => [
  120. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.options, (item, index) => {
  121. return vue.openBlock(), vue.createElementBlock("li", {
  122. id: `${_ctx.contentId}-${index}`,
  123. ref_for: true,
  124. ref_key: "optionRefs",
  125. ref: optionRefs,
  126. key: index,
  127. class: vue.normalizeClass(optionkls(item, index)),
  128. role: "option",
  129. "aria-disabled": item.disabled || _ctx.disabled || void 0,
  130. "aria-selected": hoveringIndex.value === index,
  131. onMousemove: ($event) => handleMouseEnter(index),
  132. onClick: vue.withModifiers(($event) => handleSelect(item), ["stop"])
  133. }, [
  134. vue.renderSlot(_ctx.$slots, "label", {
  135. item,
  136. index
  137. }, () => {
  138. var _a;
  139. return [
  140. vue.createElementVNode("span", null, vue.toDisplayString((_a = item.label) != null ? _a : item.value), 1)
  141. ];
  142. })
  143. ], 42, ["id", "aria-disabled", "aria-selected", "onMousemove", "onClick"]);
  144. }), 128))
  145. ]),
  146. _: 3
  147. }, 8, ["id", "wrap-class", "view-class", "aria-label"]), [
  148. [vue.vShow, _ctx.options.length > 0 && !_ctx.loading]
  149. ]),
  150. _ctx.loading ? (vue.openBlock(), vue.createElementBlock("div", {
  151. key: 1,
  152. class: vue.normalizeClass(vue.unref(ns).be("dropdown", "loading"))
  153. }, [
  154. vue.renderSlot(_ctx.$slots, "loading", {}, () => [
  155. vue.createTextVNode(vue.toDisplayString(vue.unref(t)("el.mention.loading")), 1)
  156. ])
  157. ], 2)) : vue.createCommentVNode("v-if", true),
  158. _ctx.$slots.footer ? (vue.openBlock(), vue.createElementBlock("div", {
  159. key: 2,
  160. class: vue.normalizeClass(vue.unref(ns).be("dropdown", "footer"))
  161. }, [
  162. vue.renderSlot(_ctx.$slots, "footer")
  163. ], 2)) : vue.createCommentVNode("v-if", true)
  164. ], 2);
  165. };
  166. }
  167. });
  168. var ElMentionDropdown = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "mention-dropdown.vue"]]);
  169. exports["default"] = ElMentionDropdown;
  170. //# sourceMappingURL=mention-dropdown2.js.map