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