useContextMenu-c4ffe073.js 3.3 KB

1
  1. var S=Object.defineProperty,W=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var j=(o,l,s)=>l in o?S(o,l,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[l]=s,C=(o,l)=>{for(var s in l||(l={}))z.call(l,s)&&j(o,s,l[s]);if(O)for(var s of O(l))B.call(l,s)&&j(o,s,l[s]);return o},$=(o,l)=>W(o,H(l));var g=(o,l,s)=>new Promise((x,_)=>{var u=t=>{try{y(s.next(t))}catch(n){_(n)}},L=t=>{try{y(s.throw(t))}catch(n){_(n)}},y=t=>t.done?x(t.value):Promise.resolve(t.value).then(u,L);y((s=s.apply(o,l)).next())});import{d as F,r as P,A as R,n as V,p as X,ah as A,u as w,e as c,bO as E,ac as Y,aW as q,N as G,aL as J,cO as K,cP as Q,am as T,__tla as U}from"./index-b5895273.js";let D,Z=Promise.all([(()=>{try{return U}catch(o){}})()]).then(()=>g(void 0,null,function*(){function o(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!Y(t)}const l="context-menu",s={width:{type:Number,default:156},customEvent:{type:Object,default:null},styles:{type:Object},showIcon:{type:Boolean,default:!0},axis:{type:Object,default(){return{x:0,y:0}}},items:{type:Array,default(){return[]}}},x=t=>{const{item:n}=t;return c("span",{style:"display: inline-block; width: 100%; ",class:"px-4",onClick:t.handler.bind(null,n)},[t.showIcon&&n.icon&&c(J,{class:"mr-2",icon:n.icon},null),c("span",null,[n.label])])},_=F({name:"ContextMenu",props:s,setup(t){const n=P(null),f=P(!1),d=R(()=>{const{axis:i,items:e,styles:r,width:a}=t,{x:m,y:v}=i||{x:0,y:0},b=(e||[]).length*40,k=a,I=document.body,M=I.clientWidth<m+k?m-k:m,N=I.clientHeight<v+b?v-b:v;return $(C({},r),{position:"absolute",width:`${a}px`,left:`${M+1}px`,top:`${N+1}px`,zIndex:9999})});V(()=>{X(()=>f.value=!0)}),A(()=>{const i=w(n);i&&document.body.removeChild(i)});function h(i,e){const{handler:r,disabled:a}=i;a||(f.value=!1,e==null||e.stopPropagation(),e==null||e.preventDefault(),r==null||r())}function p(i){return i.filter(e=>!e.hidden).map(e=>{const{disabled:r,label:a,children:m,divider:v=!1}=e,b={item:e,handler:h,showIcon:t.showIcon};return!m||m.length===0?c(G,null,[c(E.Item,{disabled:r,class:`${l}__item`,key:a},{default:()=>[c(x,b,null)]}),v?c(q,{key:`d-${a}`},null):null]):w(f)?c(E.SubMenu,{key:a,disabled:r,popupClassName:`${l}__popup`},{title:()=>c(x,b,null),default:()=>p(m)}):null})}return()=>{let i;if(!w(f))return null;const{items:e}=t;return c("div",{class:l},[c(E,{inlineIndent:12,mode:"vertical",ref:n,style:w(d)},o(i=p(e))?i:{default:()=>[i]})])}}}),u={domList:[],resolve:()=>{}},L=function(t){const{event:n}=t||{};if(n&&(n==null||n.preventDefault()),!!K)return new Promise(f=>{const d=document.body,h=document.createElement("div"),p={};t.styles&&(p.styles=t.styles),t.items&&(p.items=t.items),t.event&&(p.customEvent=n,p.axis={x:n.clientX,y:n.clientY});const i=c(_,p);Q(i,h);const e=function(){u.resolve("")};u.domList.push(h);const r=function(){u.domList.forEach(a=>{try{a&&d.removeChild(a)}catch(m){}}),d.removeEventListener("click",e),d.removeEventListener("scroll",e)};u.resolve=function(a){r(),f(a)},r(),d.appendChild(h),d.addEventListener("click",e),d.addEventListener("scroll",e)})},y=function(){u&&(u.resolve(""),u.domList=[])};D=function(t=!0){return T()&&t&&A(()=>{y()}),[L,y]}}));export{Z as __tla,D as u};