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