mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-12 10:45:10 +08:00
2280dd5c5e
- Using `defineComponent` to wrap component up for Volar support, this should close #841 - Also made changes for some typing - Removed `merge.ts` since `Object.assign` are now supported natively
31 lines
907 B
TypeScript
31 lines
907 B
TypeScript
import type { DirectiveBinding, VNode, ObjectDirective } from 'vue'
|
|
import { on } from '@element-plus/utils/dom'
|
|
|
|
interface PopoverInstance {
|
|
events: Record<string, EventListenerOrEventListenerObject>
|
|
triggerRef: HTMLElement
|
|
}
|
|
|
|
const attachEvents = (el: HTMLElement, binding: DirectiveBinding, vnode: VNode) => {
|
|
const _ref = binding.arg || binding.value
|
|
const popover = vnode.dirs[0].instance.$refs[_ref] as PopoverInstance
|
|
if (popover) {
|
|
popover.triggerRef = el
|
|
// because v-popover cannot modify the vnode itself due to it has already been
|
|
Object.entries(popover.events).map(([eventName, e]) => {
|
|
on(el, eventName.toLowerCase().slice(2), e)
|
|
})
|
|
}
|
|
}
|
|
|
|
export default {
|
|
mounted(el, binding, vnode) {
|
|
attachEvents(el, binding, vnode)
|
|
},
|
|
updated(el, binding, vnode) {
|
|
attachEvents(el, binding, vnode)
|
|
},
|
|
} as ObjectDirective
|
|
|
|
export const VPopover = 'popover'
|