forked from vueuse/vueuse
/
index.ts
20 lines (16 loc) · 830 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { ComponentPublicInstance } from 'vue-demi'
import { unref } from 'vue-demi'
import type { MaybeRef } from '@vueuse/shared'
export type VueInstance = ComponentPublicInstance
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>
export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null
export type UnRefElementReturn<T extends MaybeElement = MaybeElement> = T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined
/**
* Get the dom element of a ref of element or Vue component instance
*
* @param elRef
*/
export function unrefElement<T extends MaybeElement>(elRef: MaybeElementRef<T>): UnRefElementReturn<T> {
const plain = unref(elRef)
return plain != null && '$el' in (plain as VueInstance) ? (plain as VueInstance).$el : plain
}