@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
47 lines (46 loc) • 1.48 kB
JavaScript
const require_unref_element = require("./unref-element.cjs");
let vue = require("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 = (0, vue.getCurrentInstance)();
const currentRef = (0, vue.ref)();
const currentElement = (0, vue.computed)(() => {
return ["#text", "#comment"].includes(currentRef.value?.$el.nodeName) ? currentRef.value?.$el.nextElementSibling : require_unref_element.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
exports.useForwardExpose = useForwardExpose;