UNPKG

@ark-ui/vue

Version:

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

59 lines (56 loc) 1.75 kB
import { getCurrentInstance, ref, computed } from 'vue'; import { unrefElement } from './unref-element.js'; const isElement = (el) => ( // biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation> 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) ? ( // @ts-expect-error ignore ts error currentRef.value?.$el.nextElementSibling ) : ( // @ts-expect-error ignore ts error 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, // biome-ignore lint/style/noNonNullAssertion: intentional get: () => localExpose[key] }); } } Object.defineProperty(ret, "$el", { enumerable: true, configurable: true, get: () => instance.vnode.el }); instance.exposed = ret; function forwardRef(ref2) { currentRef.value = ref2; if (isElement(ref2) || !ref2) return; Object.defineProperty(ret, "$el", { enumerable: true, configurable: true, get: () => ref2.$el }); instance.exposed = ret; } return { forwardRef, currentRef, currentElement }; } export { useForwardExpose };