7da4bcdba119eca3f4b221d2e72850e3e8a0b4f56286132e3c0db5944f63f9efd6ce559b9d47c1c79a2ace6d1f519fa4ad2c3d589230a8036d03ef7e30804d 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var rovingFocusItem = require('../../roving-focus-group/src/roving-focus-item.js');
  5. var dropdownItemImpl = require('./dropdown-item-impl.js');
  6. var useDropdown = require('./useDropdown.js');
  7. var dropdown = require('./dropdown.js');
  8. var tokens = require('./tokens.js');
  9. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  10. var event = require('../../../utils/dom/event.js');
  11. const _sfc_main = vue.defineComponent({
  12. name: "ElDropdownItem",
  13. components: {
  14. ElDropdownCollectionItem: dropdown.ElCollectionItem,
  15. ElRovingFocusItem: rovingFocusItem["default"],
  16. ElDropdownItemImpl: dropdownItemImpl["default"]
  17. },
  18. inheritAttrs: false,
  19. props: dropdown.dropdownItemProps,
  20. emits: ["pointermove", "pointerleave", "click"],
  21. setup(props, { emit, attrs }) {
  22. const { elDropdown } = useDropdown.useDropdown();
  23. const _instance = vue.getCurrentInstance();
  24. const itemRef = vue.ref(null);
  25. const textContent = vue.computed(() => {
  26. var _a, _b;
  27. return (_b = (_a = vue.unref(itemRef)) == null ? void 0 : _a.textContent) != null ? _b : "";
  28. });
  29. const { onItemEnter, onItemLeave } = vue.inject(tokens.DROPDOWN_INJECTION_KEY, void 0);
  30. const handlePointerMove = event.composeEventHandlers((e) => {
  31. emit("pointermove", e);
  32. return e.defaultPrevented;
  33. }, event.whenMouse((e) => {
  34. if (props.disabled) {
  35. onItemLeave(e);
  36. return;
  37. }
  38. const target = e.currentTarget;
  39. if (target === document.activeElement || target.contains(document.activeElement)) {
  40. return;
  41. }
  42. onItemEnter(e);
  43. if (!e.defaultPrevented) {
  44. target == null ? void 0 : target.focus({
  45. preventScroll: true
  46. });
  47. }
  48. }));
  49. const handlePointerLeave = event.composeEventHandlers((e) => {
  50. emit("pointerleave", e);
  51. return e.defaultPrevented;
  52. }, event.whenMouse(onItemLeave));
  53. const handleClick = event.composeEventHandlers((e) => {
  54. if (props.disabled) {
  55. return;
  56. }
  57. emit("click", e);
  58. return e.type !== "keydown" && e.defaultPrevented;
  59. }, (e) => {
  60. var _a, _b, _c;
  61. if (props.disabled) {
  62. e.stopImmediatePropagation();
  63. return;
  64. }
  65. if ((_a = elDropdown == null ? void 0 : elDropdown.hideOnClick) == null ? void 0 : _a.value) {
  66. (_b = elDropdown.handleClick) == null ? void 0 : _b.call(elDropdown);
  67. }
  68. (_c = elDropdown.commandHandler) == null ? void 0 : _c.call(elDropdown, props.command, _instance, e);
  69. });
  70. const propsAndAttrs = vue.computed(() => ({ ...props, ...attrs }));
  71. return {
  72. handleClick,
  73. handlePointerMove,
  74. handlePointerLeave,
  75. textContent,
  76. propsAndAttrs
  77. };
  78. }
  79. });
  80. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  81. var _a;
  82. const _component_el_dropdown_item_impl = vue.resolveComponent("el-dropdown-item-impl");
  83. const _component_el_roving_focus_item = vue.resolveComponent("el-roving-focus-item");
  84. const _component_el_dropdown_collection_item = vue.resolveComponent("el-dropdown-collection-item");
  85. return vue.openBlock(), vue.createBlock(_component_el_dropdown_collection_item, {
  86. disabled: _ctx.disabled,
  87. "text-value": (_a = _ctx.textValue) != null ? _a : _ctx.textContent
  88. }, {
  89. default: vue.withCtx(() => [
  90. vue.createVNode(_component_el_roving_focus_item, {
  91. focusable: !_ctx.disabled
  92. }, {
  93. default: vue.withCtx(() => [
  94. vue.createVNode(_component_el_dropdown_item_impl, vue.mergeProps(_ctx.propsAndAttrs, {
  95. onPointerleave: _ctx.handlePointerLeave,
  96. onPointermove: _ctx.handlePointerMove,
  97. onClickimpl: _ctx.handleClick
  98. }), {
  99. default: vue.withCtx(() => [
  100. vue.renderSlot(_ctx.$slots, "default")
  101. ]),
  102. _: 3
  103. }, 16, ["onPointerleave", "onPointermove", "onClickimpl"])
  104. ]),
  105. _: 3
  106. }, 8, ["focusable"])
  107. ]),
  108. _: 3
  109. }, 8, ["disabled", "text-value"]);
  110. }
  111. var DropdownItem = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "dropdown-item.vue"]]);
  112. exports["default"] = DropdownItem;
  113. //# sourceMappingURL=dropdown-item.js.map