UNPKG

reka-ui

Version:

Vue port for Radix UI Primitives.

57 lines (55 loc) 1.7 kB
import { computed, getCurrentInstance, ref } from "vue"; import { unrefElement } from "@vueuse/core"; //#region src/shared/useForwardExpose.ts 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$1) { currentRef.value = ref$1; if (!ref$1) return; Object.defineProperty(ret, "$el", { enumerable: true, configurable: true, get: () => ref$1 instanceof Element ? ref$1 : ref$1.$el }); if (!(ref$1 instanceof Element) && !Object.hasOwn(ref$1, "$el")) { const childExposed = ref$1.$.exposed; const merged = Object.assign({}, ret); for (const key in childExposed) Object.defineProperty(merged, key, { enumerable: true, configurable: true, get: () => childExposed[key] }); instance.exposed = merged; } } return { forwardRef, currentRef, currentElement }; } //#endregion export { useForwardExpose }; //# sourceMappingURL=useForwardExpose.js.map