c1270e34a77e5f24043b111e7627001e09b9f5b671ced24dfdb4f32ebd15d7e8e56e005d322b700b20112fcac5cb6e9f255e251ec2206565adef0a2ac44fa4 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var useOption = require('./useOption.js');
  5. var option = require('./option.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-id/index.js');
  9. const _sfc_main = vue.defineComponent({
  10. name: option.COMPONENT_NAME,
  11. componentName: option.COMPONENT_NAME,
  12. props: option.optionProps,
  13. setup(props) {
  14. const ns = index.useNamespace("select");
  15. const id = index$1.useId();
  16. const containerKls = vue.computed(() => [
  17. ns.be("dropdown", "item"),
  18. ns.is("disabled", vue.unref(isDisabled)),
  19. ns.is("selected", vue.unref(itemSelected)),
  20. ns.is("hovering", vue.unref(hover))
  21. ]);
  22. const states = vue.reactive({
  23. index: -1,
  24. groupDisabled: false,
  25. visible: true,
  26. hover: false
  27. });
  28. const {
  29. currentLabel,
  30. itemSelected,
  31. isDisabled,
  32. select,
  33. hoverItem,
  34. updateOption
  35. } = useOption.useOption(props, states);
  36. const { visible, hover } = vue.toRefs(states);
  37. const vm = vue.getCurrentInstance().proxy;
  38. select.onOptionCreate(vm);
  39. vue.onBeforeUnmount(() => {
  40. const key = vm.value;
  41. vue.nextTick(() => {
  42. const { selected: selectedOptions } = select.states;
  43. const doesSelected = selectedOptions.some((item) => {
  44. return item.value === vm.value;
  45. });
  46. if (select.states.cachedOptions.get(key) === vm && !doesSelected) {
  47. select.states.cachedOptions.delete(key);
  48. }
  49. });
  50. select.onOptionDestroy(key, vm);
  51. });
  52. function selectOptionClick() {
  53. if (!isDisabled.value) {
  54. select.handleOptionSelect(vm);
  55. }
  56. }
  57. return {
  58. ns,
  59. id,
  60. containerKls,
  61. currentLabel,
  62. itemSelected,
  63. isDisabled,
  64. select,
  65. visible,
  66. hover,
  67. states,
  68. hoverItem,
  69. updateOption,
  70. selectOptionClick
  71. };
  72. }
  73. });
  74. function _sfc_render(_ctx, _cache) {
  75. return vue.withDirectives((vue.openBlock(), vue.createElementBlock("li", {
  76. id: _ctx.id,
  77. class: vue.normalizeClass(_ctx.containerKls),
  78. role: "option",
  79. "aria-disabled": _ctx.isDisabled || void 0,
  80. "aria-selected": _ctx.itemSelected,
  81. onMousemove: _ctx.hoverItem,
  82. onClick: vue.withModifiers(_ctx.selectOptionClick, ["stop"])
  83. }, [
  84. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  85. vue.createElementVNode("span", null, vue.toDisplayString(_ctx.currentLabel), 1)
  86. ])
  87. ], 42, ["id", "aria-disabled", "aria-selected", "onMousemove", "onClick"])), [
  88. [vue.vShow, _ctx.visible]
  89. ]);
  90. }
  91. var Option = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "option.vue"]]);
  92. exports["default"] = Option;
  93. //# sourceMappingURL=option2.js.map