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