You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
8.9 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, computed, unref, reactive, toRefs, getCurrentInstance, onBeforeUnmount, nextTick, withDirectives, openBlock, createElementBlock, normalizeClass, withModifiers, renderSlot, createElementVNode, toDisplayString, vShow } from 'vue';\nimport { useOption } from './useOption.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useId } from '../../../hooks/use-id/index.mjs';\nconst _sfc_main = defineComponent({\n name: \"ElOption\",\n componentName: \"ElOption\",\n props: {\n value: {\n required: true,\n type: [String, Number, Boolean, Object]\n },\n label: [String, Number],\n created: Boolean,\n disabled: Boolean\n },\n setup(props) {\n const ns = useNamespace(\"select\");\n const id = useId();\n const containerKls = computed(() => [ns.be(\"dropdown\", \"item\"), ns.is(\"disabled\", unref(isDisabled)), ns.is(\"selected\", unref(itemSelected)), ns.is(\"hovering\", unref(hover))]);\n const states = reactive({\n index: -1,\n groupDisabled: false,\n visible: true,\n hover: false\n });\n const {\n currentLabel,\n itemSelected,\n isDisabled,\n select,\n hoverItem,\n updateOption\n } = useOption(props, states);\n const {\n visible,\n hover\n } = toRefs(states);\n const vm = getCurrentInstance().proxy;\n select.onOptionCreate(vm);\n onBeforeUnmount(() => {\n const key = vm.value;\n const {\n selected: selectedOptions\n } = select.states;\n const doesSelected = selectedOptions.some(item => {\n return item.value === vm.value;\n });\n nextTick(() => {\n if (select.states.cachedOptions.get(key) === vm && !doesSelected) {\n select.states.cachedOptions.delete(key);\n }\n });\n select.onOptionDestroy(key, vm);\n });\n function selectOptionClick() {\n if (!isDisabled.value) {\n select.handleOptionSelect(vm);\n }\n }\n return {\n ns,\n id,\n containerKls,\n currentLabel,\n itemSelected,\n isDisabled,\n select,\n hoverItem,\n updateOption,\n visible,\n hover,\n selectOptionClick,\n states\n };\n }\n});\nfunction _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {\n return withDirectives((openBlock(), createElementBlock(\"li\", {\n id: _ctx.id,\n class: normalizeClass(_ctx.containerKls),\n role: \"option\",\n \"aria-disabled\": _ctx.isDisabled || void 0,\n \"aria-selected\": _ctx.itemSelected,\n onMousemove: _ctx.hoverItem,\n onClick: withModifiers(_ctx.selectOptionClick, [\"stop\"])\n }, [renderSlot(_ctx.$slots, \"default\", {}, () => [createElementVNode(\"span\", null, toDisplayString(_ctx.currentLabel), 1)])], 42, [\"id\", \"aria-disabled\", \"aria-selected\", \"onMousemove\", \"onClick\"])), [[vShow, _ctx.visible]]);\n}\nvar Option = /* @__PURE__ */_export_sfc(_sfc_main, [[\"render\", _sfc_render], [\"__file\", \"option.vue\"]]);\nexport { Option as default };","map":{"version":3,"names":["_sfc_main","defineComponent","name","componentName","props","value","required","type","String","Number","Boolean","Object","label","created","disabled","setup","ns","useNamespace","id","useId","containerKls","computed","be","is","unref","isDisabled","itemSelected","hover","states","reactive","index","groupDisabled","visible","currentLabel","select","hoverItem","updateOption","useOption","toRefs","vm","getCurrentInstance","proxy","onOptionCreate","onBeforeUnmount","key","selected","selectedOptions","doesSelected","some","item","nextTick","cachedOptions","get","delete","onOptionDestroy","selectOptionClick","handleOptionSelect","_sfc_render","_ctx","_cache","$props","$setup","$data","$options","withDirectives","openBlock","createElementBlock","class","normalizeClass","role","onMousemove","createElementVNode","toDisplayString","vShow","Option","_export_sfc"],"sources":["../../../.