数通智联化工云平台
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.

1 line
7.1 KiB

2 years ago
{"version":3,"file":"dropdown-item.mjs","sources":["../../../../../../packages/components/dropdown/src/dropdown-item.vue"],"sourcesContent":["<template>\n <el-dropdown-collection-item\n :disabled=\"disabled\"\n :text-value=\"textValue ?? textContent\"\n >\n <el-roving-focus-item :focusable=\"!disabled\">\n <el-dropdown-item-impl\n v-bind=\"propsAndAttrs\"\n @pointerleave=\"handlePointerLeave\"\n @pointermove=\"handlePointerMove\"\n @clickimpl=\"handleClick\"\n >\n <slot />\n </el-dropdown-item-impl>\n </el-roving-focus-item>\n </el-dropdown-collection-item>\n</template>\n<script lang=\"ts\">\nimport {\n computed,\n defineComponent,\n getCurrentInstance,\n inject,\n ref,\n unref,\n} from 'vue'\nimport { ElRovingFocusItem } from '@element-plus/components/roving-focus-group'\nimport { composeEventHandlers, whenMouse } from '@element-plus/utils'\nimport ElDropdownItemImpl from './dropdown-item-impl.vue'\nimport { useDropdown } from './useDropdown'\nimport {\n ElCollectionItem as ElDropdownCollectionItem,\n dropdownItemProps,\n} from './dropdown'\nimport { DROPDOWN_INJECTION_KEY } from './tokens'\n\nexport default defineComponent({\n name: 'ElDropdownItem',\n components: {\n ElDropdownCollectionItem,\n ElRovingFocusItem,\n ElDropdownItemImpl,\n },\n inheritAttrs: false,\n props: dropdownItemProps,\n emits: ['pointermove', 'pointerleave', 'click'],\n setup(props, { emit, attrs }) {\n const { elDropdown } = useDropdown()\n const _instance = getCurrentInstance()\n const itemRef = ref<HTMLElement | null>(null)\n const textContent = computed(() => unref(itemRef)?.textContent ?? '')\n const { onItemEnter, onItemLeave } = inject(\n DROPDOWN_INJECTION_KEY,\n undefined\n )!\n\n const handlePointerMove = composeEventHandlers(\n (e: PointerEvent) => {\n emit('pointermove', e)\n return e.defaultPrevented\n },\n whenMouse((e) => {\n if (props.disabled) {\n onItemLeave(e)\n return\n }\n\n const target = e.currentTarget as HTMLElement\n /**\n * This handles the following scenario:\n * when the item contains a form element such as input element\n * when the mouse is moving over the element itself which is contained by\n * the item, the default focusing logic should be prevented so that\n * it won't cause weird action.\n */\n if (\n target === document.activeElement ||\n target.contains(document.activeElement)\n ) {\n return\n }\n\n onItemEnter(e)\n if (!e.defaultPrevented) {\n target?.focus()\n }\n })\n )\n\n const handlePointerLeave = composeEventHandlers(\n (e: PointerEvent) => {\n emit('pointerleave', e)\n return e.defaultPrevented\n },\n whenMouse((e) => {\n onItemLeave(e)\n })\n )\n\n const handleClick = composeEventHandlers(\n (e: PointerEvent) => {\n if (props.disabled) {\n return\n }\n emit('click', e)\n return e.type !== 'keydown' && e.defaultPrevented\n },\n (e) => {\n if (props.disabled) {\n e.stopImmediatePropagation()\n return\n }\n if (elDropdown?.hideOnClick?.value) {\n elDropdown.handleClick?.()\n }\n elDropdown.commandHandler?.(props.command, _instance, e)\n }\n )\n\n // direct usage of v-bind={ ...$props, ...$attrs } causes type errors\n const propsAndAttrs = computed(() => {\n return { ...props, ...attrs }\n })\n\n return {\n handleClick,\n handlePointerMove,\n handlePointerLeave,\n textContent,\n propsAndAttrs,\n }\n },\n})\n</script>\n"],"names":["ElDropdownCollectionItem","_resolveComponent","_openBlock","_createBlock","_withCtx","_createVNode","_mergeProps"],"mappings":";;;;;;;;;;;AAoCA,MAAK,YAAa,eAAa,CAAA;AAAA,EAC7B,IAAM,EAAA,gBAAA;AAAA,EACN,UAAY,EAAA;AAAA,8BACVA,gBAAA;AAA