{"version":3,"file":"trigger2.js","sources":["../../../../../../packages/components/popper/src/trigger.vue"],"sourcesContent":["<template>\n <el-only-child\n v-if=\"!virtualTriggering\"\n v-bind=\"$attrs\"\n :aria-controls=\"ariaControls\"\n :aria-describedby=\"ariaDescribedby\"\n :aria-expanded=\"ariaExpanded\"\n :aria-haspopup=\"ariaHaspopup\"\n >\n <slot />\n </el-only-child>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, inject, onBeforeUnmount, onMounted, watch } from 'vue'\nimport { isNil } from 'lodash-unified'\nimport { unrefElement } from '@vueuse/core'\nimport { ElOnlyChild } from '@element-plus/components/slot'\nimport { useForwardRef } from '@element-plus/hooks'\nimport { isElement } from '@element-plus/utils'\nimport { POPPER_INJECTION_KEY } from './constants'\nimport { popperTriggerProps } from './trigger'\n\nimport type { WatchStopHandle } from 'vue'\n\ndefineOptions({\n name: 'ElPopperTrigger',\n inheritAttrs: false,\n})\n\nconst props = defineProps(popperTriggerProps)\n\nconst { role, triggerRef } = inject(POPPER_INJECTION_KEY, undefined)!\n\nuseForwardRef(triggerRef)\n\nconst ariaControls = computed<string | undefined>(() => {\n return ariaHaspopup.value ? props.id : undefined\n})\n\nconst ariaDescribedby = computed<string | undefined>(() => {\n if (role && role.value === 'tooltip') {\n return props.open && props.id ? props.id : undefined\n }\n return undefined\n})\n\nconst ariaHaspopup = computed<string | undefined>(() => {\n if (role && role.value !== 'tooltip') {\n return role.value\n }\n return undefined\n})\n\nconst ariaExpanded = computed<string | undefined>(() => {\n return ariaHaspopup.value ? `${props.open}` : undefined\n})\n\nlet virtualTriggerAriaStopWatch: WatchStopHandle | undefined = undefined\n\nconst TRIGGER_ELE_EVENTS = [\n 'onMouseenter',\n 'onMouseleave',\n 'onClick',\n 'onKeydown',\n 'onFocus',\n 'onBlur',\n 'onContextmenu',\n] as const\n\nonMounted(() => {\n watch(\n () => props.virtualRef,\n (virtualEl) => {\n if (virtualEl) {\n triggerRef.value = unrefElement(virtualEl as HTMLElement)\n }\n },\n {\n immediate: true,\n }\n )\n\n watch(\n triggerRef,\n (el, prevEl) => {\n virtualTriggerAriaStopWatch?.()\n virtualTriggerAriaStopWatch = undefined\n if (isElement(el)) {\n TRIGGER_ELE_EVENTS.forEach((eventName) => {\n const handler = props[eventName]\n if (handler) {\n ;(el as HTMLElement).addEventListener(\n eventName.slice(2).toLowerCase(),\n handler\n )\n ;(prevEl as HTMLElement)?.removeEventListener?.(\n eventName.slice(2).toLowerCase(),\n handler\n )\n }\n })\n virtualTriggerAriaStopWatch = watch(\n [ariaControls, ariaDescribedby, ariaHaspopup, ariaExpanded],\n (watches) => {\n ;[\n 'aria-controls',\n 'aria-describedby',\n 'aria-haspopup',\n 'aria-expanded',\n ].forEach((key, idx) => {\n isNil(watches[idx])\n ? el.removeAttribute(key)\n : el.setAttribute(key, watches[idx]!)\n })\n },\n { immediate: true }\n )\n }\n if (isElement(prevEl)) {\n ;[\n 'aria-controls',\n 'aria-describedby',\n 'aria-haspopup',\n 'aria-expanded',\n ].forEach((key) => prevEl.removeAttribute(key))\n }\n },\n {\n immediate: true,\n }\n )\n})\n\nonBeforeUnmount(() => {\n virtualTriggerAriaStopWatch?.()\n virtualTriggerAriaStopWatch = undefined\n if (triggerRef.value && isElement(triggerRef.value)) {\n const el = triggerRef.value as HTMLElement\n TRIGGER_ELE_EVENTS.forEach((eventName) => {\n const handler = props[eventName]\n if (handler) {\n el.removeEventListener(eventName.slice(2).toLowerCase(), handler)\n }\n })\n triggerRef.value = undefined\n }\n})\n\ndefineExpose({\n /**\n * @description trigger element\n */\n triggerRef,\n})\n</script>\n"],"names":["inject","POPPER_INJECTION_KEY","useForwardRef","computed","onMounted","watch","unrefElement","isElement","isNil","onBeforeUnmount"],"mappings":";;;;;;;;;;;;;;;;;uCAyBc,CAAA;AAAA,EACZ,IAAM,EAAA,iBAAA;AAAA,EACN,YAAc,EAAA,KAAA;AAChB,CAAA,CAAA,CAAA;;;;;;AAIA,IAAA,MAAM,EAAE,IAAA,EA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