useContextMenu-d25efcaf.js
3.11 KB
var $=Object.defineProperty,O=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var C=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))N.call(t,n)&&C(e,n,t[n]);if(_)for(var n of _(t))S.call(t,n)&&C(e,n,t[n]);return e},M=(e,t)=>O(e,D(t));import{d as A,k as g,e as P,o as V,q as F,b as E,u as v,f as r,i as H,F as R,m as T,g as W}from"./vue-5a35c3f5.js";import{I as X,_ as q,aT as z}from"./index.js";import{X as h,aA as B}from"./antd-6b087f69.js";function U(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!H(e)}const x="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[]}}},w=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(X,{class:"mr-2",icon:t.icon},null),r("span",null,[t.label])])},G=A({name:"ContextMenu",props:Y,setup(e){const t=g(null),n=g(!1),i=P(()=>{const{axis:s,items:o,styles:l,width:c}=e,{x:a,y:d}=s||{x:0,y:0},y=(o||[]).length*40,p=c,b=document.body,L=b.clientWidth<a+p?a-p:a,j=b.clientHeight<d+y?d-y:d;return M(I({},l),{position:"absolute",width:`${c}px`,left:`${L+1}px`,top:`${j+1}px`,zIndex:9999})});V(()=>{F(()=>n.value=!0)}),E(()=>{const s=v(t);s&&document.body.removeChild(s)});function m(s,o){const{handler:l,disabled:c}=s;c||(n.value=!1,o==null||o.stopPropagation(),o==null||o.preventDefault(),l==null||l())}function u(s){return s.filter(l=>!l.hidden).map(l=>{const{disabled:c,label:a,children:d,divider:y=!1}=l,p={item:l,handler:m,showIcon:e.showIcon};return!d||d.length===0?r(R,null,[r(h.Item,{disabled:c,class:`${x}__item`,key:a},{default:()=>[r(w,p,null)]}),y?r(B,{key:`d-${a}`},null):null]):v(n)?r(h.SubMenu,{key:a,disabled:c,popupClassName:`${x}__popup`},{title:()=>r(w,p,null),default:()=>u(d)}):null})}return()=>{let s;if(!v(n))return null;const{items:o}=e;return r("div",{class:x},[r(h,{inlineIndent:12,mode:"vertical",ref:t,style:v(i)},U(s=u(o))?s:{default:()=>[s]})])}}});const J=q(G,[["__file","E:/allcode/erp/test7901/order-erp-front/src/components/ContextMenu/src/ContextMenu.vue"]]),f={domList:[],resolve:()=>{}},K=function(e){const{event:t}=e||{};if(t&&(t==null||t.preventDefault()),!!z)return new Promise(n=>{const i=document.body,m=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=r(J,u);T(s,m);const o=function(){f.resolve("")};f.domList.push(m);const l=function(){f.domList.forEach(c=>{try{c&&i.removeChild(c)}catch(a){}}),i.removeEventListener("click",o),i.removeEventListener("scroll",o)};f.resolve=function(c){l(),n(c)},l(),i.appendChild(m),i.addEventListener("click",o),i.addEventListener("scroll",o)})},k=function(){f&&(f.resolve(""),f.domList=[])};function ne(e=!0){return W()&&e&&E(()=>{k()}),[K,k]}export{ne as u};