vuux
Version:
Vue3 Nuxt3 Nuxt4 组件库
39 lines (38 loc) • 1.07 kB
JavaScript
import { computed as u, ref as s, provide as v, nextTick as r } from "vue";
import { Utils as x } from "@vuux/utils";
const y = (d, l) => {
const h = u(() => d.shadow), o = s(!1), e = s({
top: 0,
left: 0
}), t = s({
width: 0,
height: 0
}), c = u(() => ({
zIndex: d.zIndex,
top: e.value.top + "px",
left: e.value.left + "px"
})), w = async (a) => {
o.value = !0, await r();
const i = l.value;
if (!i)
return;
(!t.value.width || !t.value.height) && (t.value.width = i.offsetWidth, t.value.height = i.offsetHeight);
const f = typeof window < "u" ? window.innerWidth : 0, p = typeof window < "u" ? window.innerHeight : 0;
e.value.left = Math.min(a.clientX, f - t.value.width), e.value.top = Math.min(a.clientY, p - t.value.height), i.focus();
}, n = () => {
o.value = !1;
};
return x.useClickOutside(l, n), v("contextMenuContext", {
hide: n,
isShadow: h
}), {
isShadow: h,
isDisplay: o,
positionStyle: c,
show: w,
hide: n
};
};
export {
y as useContextMenu
};