@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
33 lines (30 loc) • 1.04 kB
JavaScript
import { hasProp, isString } from '@zag-js/utils';
import { getCurrentInstance } from 'vue';
function hasVnodeScopeId(vnode) {
if (vnode === null || typeof vnode !== "object") return false;
const vnodeObj = vnode;
return hasProp(vnodeObj, "scopeId") && isString(vnodeObj.scopeId);
}
function hasTypeScopeId(type) {
if (type === null || typeof type !== "object") return false;
const typeObj = type;
return hasProp(typeObj, "__scopeId") && isString(typeObj.__scopeId);
}
function getScopeIdFromInstance(instance) {
if (hasVnodeScopeId(instance.vnode)) return instance.vnode.scopeId;
if (hasTypeScopeId(instance.type)) return instance.type.__scopeId;
}
function useScopeId() {
const instance = getCurrentInstance();
if (!instance) return;
let scopeId = getScopeIdFromInstance(instance);
if (!scopeId && instance.parent) {
let parent = instance.parent;
while (parent && !scopeId) {
scopeId = getScopeIdFromInstance(parent);
parent = parent.parent;
}
}
return scopeId;
}
export { useScopeId };