1 line
4.2 KiB
JavaScript
1 line
4.2 KiB
JavaScript
import{At as e,B as t,G as n,H as r,K as i,Mt as a,Nt as o,Tt as s,U as c,V as l,W as u,Y as d,Z as f,at as p,bt as m,ct as h,dt as g,g as _,it as v,j as y,kt as b,ot as x,p as S,ut as C,vt as w}from"./vue-B11_pI9F.js";import{t as T}from"./_plugin-vue_export-helper-B67ILkmu.js";import{v as E}from"./index-jtNAhQeK.js";import{t as D}from"./dom-CWEl93tC.js";var O=e=>typeof e==`object`&&!!e&&`name`in e&&`label`in e,k={key:0,class:`menu-divider`},A=[`onClick`],j={class:`menu-item-content`},M={class:`menu-item-text`},N=T(f({__name:`Menu`,props:{menuList:{},activeMenu:{},scrollIntoView:{type:Boolean},disabled:{type:Boolean}},emits:[`click`],setup(r,{emit:a}){let l=r,d=a,f=s(),p=(e,t)=>{l.disabled||e.disabled||d(`click`,e.value,t)},m=()=>{let e=f.value?.querySelector(`.menu-item.active`);e&&D(e,{pos:`center`,behavior:`instant`})};return x(()=>{l.scrollIntoView&&m()}),(a,s)=>(h(),i(`div`,{ref_key:`$menuWrapper`,ref:f,class:`menu`},[(h(!0),i(t,null,C(r.menuList,(l,d)=>(h(),i(t,{key:d},[l===`divider`?(h(),i(`div`,k,[g(a.$slots,`default`,{item:l,index:d},()=>[s[0]||(s[0]=c(`div`,{class:`menu-divider-line`},null,-1))],!0)])):(h(),i(`div`,{key:1,class:e([`menu-item`,{active:l.value===r.activeMenu,disabled:l.disabled}]),onClick:e=>p(l,e)},[c(`div`,j,[g(a.$slots,`default`,{item:l,index:d},()=>[b(O)(l)?(h(),u(b(E),{key:0,class:`menu-item-icon`,name:l.name,width:`16`,height:`16`},null,8,[`name`])):n(``,!0),c(`span`,M,o(l.label),1)],!0)]),r.activeMenu===void 0?n(``,!0):(h(),u(b(E),{key:0,class:e([`menu-item-check`,{active:l.value===r.activeMenu}]),name:`Check`,width:`16`,height:`16`},null,8,[`class`]))],10,A))],64))),128)),g(a.$slots,`extra`,{},void 0,!0)],512))}}),[[`__scopeId`,`data-v-366403b6`]]),P=1e3/30,F=f({__name:`FloatingContent`,props:{open:{type:Boolean},triggerEl:{},options:{default:()=>({})}},emits:[`update:open`],setup(e,{emit:t}){let o=e,c=t,f=s(),b=s({}),x=null,C=``,T=r(()=>({teleport:o.options.teleport??!1,placement:o.options.placement??`bottom`,offset:o.options.offset??20,align:o.options.align??`center`,withinWindow:o.options.withinWindow??!1,zIndex:o.options.zIndex??1e3,matchTriggerWidth:o.options.matchTriggerWidth??!1})),E=r(()=>({position:`fixed`,width:T.value.matchTriggerWidth?void 0:`max-content`,maxWidth:`100vw`,top:`0`,left:`0`,zIndex:`${T.value.zIndex}`,...b.value}));function D(e,t,n){return Math.max(t,Math.min(e,n))}function O(e,t){if(T.value.matchTriggerWidth)return e.left;let{align:n}=T.value;return n===`start`?e.left:n===`end`?e.right-t:e.left+e.width/2-t/2}function k(e,t){let{placement:n,offset:r}=T.value;return n===`top`?e.top-r-t:e.bottom+r}let A=()=>{if(!o.open||!T.value.teleport)return;let e=o.triggerEl?.getBoundingClientRect();if(!e)return;let t=f.value?.getBoundingClientRect(),n=t?.width??0,r=t?.height??0,i=O(e,n),a=k(e,r);T.value.withinWindow&&(i=D(i,0,Math.max(0,window.innerWidth-n)),a=D(a,0,Math.max(0,window.innerHeight-r))),b.value={position:`fixed`,width:T.value.matchTriggerWidth?`${e.width}px`:`max-content`,maxWidth:`100vw`,top:`${a}px`,left:`${i}px`,zIndex:`${T.value.zIndex}`}},j=()=>{let e=o.triggerEl?.getBoundingClientRect();return e?`${e.left},${e.top},${e.width},${e.height}`:``},M=()=>{x&&(window.clearInterval(x),x=null,C=``)},N=()=>{M(),!(!o.open||!T.value.teleport)&&(C=j(),x=window.setInterval(()=>{let e=j();!e||e===C||(C=e,A())},P))},F=async()=>{await v(),A(),await new Promise(e=>requestAnimationFrame(e)),A()};return w(()=>o.open,async e=>{if(!e){M();return}await F(),N()},{immediate:!0}),w(()=>o.options,async()=>{o.open&&(await F(),N())},{deep:!0}),p(M),_(f,A),S(window,`resize`,A),S(window,`scroll`,A,!0),S(document,`click`,e=>{if(!o.open||!T.value.teleport)return;let t=e.target;o.triggerEl?.contains(t)||f.value?.contains(t)||c(`update:open`,!1)}),(t,r)=>T.value.teleport?(h(),u(l,{key:0,to:`body`},[d(y,{name:`fade`},{default:m(()=>[e.open?(h(),i(`div`,{key:0,ref_key:`contentRef`,ref:f,style:a(E.value)},[g(t.$slots,`default`)],4)):n(``,!0)]),_:3})])):(h(),u(y,{key:1,name:`fade`},{default:m(()=>[e.open?g(t.$slots,`default`,{key:0}):n(``,!0)]),_:3}))}}),I=`ppt-menu:open`,L=0;function R(e){let t=++L;return S(window,I,n=>{n.detail!==t&&e()}),{notifyOpen:()=>{window.dispatchEvent(new CustomEvent(I,{detail:t}))}}}export{O as i,F as n,N as r,R as t}; |