UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

47 lines (46 loc) 1.44 kB
import { unrefElement } from "./unref-element.js"; import { computed, getCurrentInstance, ref } from "vue"; //#region src/utils/use-forward-expose.ts var isElement = (el) => Object.prototype.hasOwnProperty.call(el, "nodeName") && typeof el.nodeName === "string"; function useForwardExpose() { const instance = getCurrentInstance(); const currentRef = ref(); const currentElement = computed(() => { return ["#text", "#comment"].includes(currentRef.value?.$el.nodeName) ? currentRef.value?.$el.nextElementSibling : unrefElement(currentRef); }); const localExpose = Object.assign({}, instance.exposed); const ret = {}; for (const key in instance.props) Object.defineProperty(ret, key, { enumerable: true, configurable: true, get: () => instance.props[key] }); if (Object.keys(localExpose).length > 0) for (const key in localExpose) Object.defineProperty(ret, key, { enumerable: true, configurable: true, get: () => localExpose[key] }); Object.defineProperty(ret, "$el", { enumerable: true, configurable: true, get: () => instance.vnode.el }); instance.exposed = ret; function forwardRef(ref) { currentRef.value = ref; if (!ref) return; Object.defineProperty(ret, "$el", { enumerable: true, configurable: true, get: () => isElement(ref) ? ref : ref.$el }); instance.exposed = ret; } return { forwardRef, currentRef, currentElement }; } //#endregion export { useForwardExpose };