2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{d as X,I as Ie,bY as U,G as _e,aQ as se,an as Ue,bZ as Ke,b as q,a5 as le,R as j,B as ue,C as de,a as J,D,a7 as oe,H as Re,o as xe,c as Ee,al as He,n as we,f as K,g as Pe,y as _,j as x,U as Y,P as G,b_ as ye,bz as je,s as g,E as H,bl as Ge,T as qe,b1 as Je,V as re,W as $,b$ as Qe,c0 as Ze,h as ie,bC as et,J as tt,ak as at,N as Be,F as nt,bF as st,z as lt,c1 as ot,K as rt,L as it,l as ct,ab as ut}from"./index-Dq6jPnBF.js";import{c as dt,r as ce,U as Oe}from"./raf-BV6Sit1E.js";import{f as ft}from"./vnode-mg6izvAi.js";import{i as te}from"./el-scrollbar-DmODyDOE.js";import{c as ae}from"./el-select-BrrEHV9d.js";import{i as vt}from"./el-popper-DueI9GzG.js";import{c as ke}from"./clamp-Ixi6GGap.js";import{o as bt}from"./omit-DdM_zsdI.js";const ht=(e,s,r)=>ft(e.subTree).filter(c=>{var t;return Ue(c)&&((t=c.type)==null?void 0:t.name)===s&&!!c.component}).map(c=>c.component.uid).map(c=>r[c]).filter(c=>!!c),pt=(e,s)=>{const r=se({}),c=se([]),t=new WeakMap,y=u=>{r.value[u.uid]=u,U(r),_e(()=>{const l=u.getVnode().el,i=l.parentNode;if(!t.has(i)){t.set(i,[]);const d=i.insertBefore.bind(i);i.insertBefore=(a,T)=>(t.get(i).some(b=>a===b||T===b)&&U(r),d(a,T))}t.get(i).push(l)})},N=u=>{delete r.value[u.uid],U(r);const l=u.getVnode().el,i=l.parentNode,d=t.get(i),a=d.indexOf(l);d.splice(a,1)},h=()=>{c.value=ht(e,s,r.value)},v=u=>u.render();return{children:c,addChild:y,removeChild:N,ChildrenSorter:X({setup(u,{slots:l}){return()=>(h(),l.default?Ie(v,{render:l.default}):null)}})}},mt=({atEndEdge:e,atStartEdge:s,layout:r},c)=>{let t,y=0;const N=v=>v<0&&s.value||v>0&&e.value;return{hasReachedEdge:N,onWheel:v=>{dt(t);let{deltaX:u,deltaY:l}=v;v.shiftKey&&l!==0&&(u=l,l=0);const i=r.value==="horizontal"?u:l;N(i)||(y+=i,!Ke()&&i!==0&&v.preventDefault(),t=ce(()=>{c(y),y=0}))}}};const Te=e=>{let s,r;return e.type==="touchend"?(r=e.changedTouches[0].clientY,s=e.changedTouches[0].clientX):e.type.startsWith("touch")?(r=e.touches[0].clientY,s=e.touches[0].clientX):(r=e.clientY,s=e.clientX),{clientX:s,clientY:r}},Q=Symbol("tabsRootContextKey"),gt=q({tabs:{type:j(Array),default:()=>le([])},tabRefs:{type:j(Object),default:()=>le({})}}),Ce="ElTabBar";var yt=X({name:Ce,__name:"tab-bar",props:gt,setup(e,{expose:s}){const r=e,c=ue(Q);c||de(Ce,"<el-tabs><el-tab-bar /></el-tabs>");const t=J("tabs"),y=_(),N=_(),h=x(()=>{var a;return Y(c.props.defaultValue)||!!((a=N.value)!=null&&a.transform)}),v=()=>{let a=0,T=0;const b=["top","bottom"].includes(c.props.tabPosition)?"width":"height",E=b==="width"?"x":"y",P=E==="x"?"left":"top";return r.tabs.every(n=>{if(Y(n.paneName))return!1;const p=r.tabRefs[n.paneName];if(!p)return!1;if(!n.active)return!0;a=p[`offset${ae(P)}`],T=p[`client${ae(b)}`];const S=window.getComputedStyle(p);return b==="width"&&(T-=Number.parseFloat(S.paddingLeft)+Number.parseFloat(S.paddingRight),a+=Number.parseFloat(S.paddingLeft)),!1}),{[b]:`${T}px`,transform:`translate${ae(E)}(${a}px)`}},u=()=>N.value=v(),l=[],i=()=>{l.forEach(a=>a.stop()),l.length=0,Object.values(r.tabRefs).forEach(a=>{l.push(oe(a,u))})};D(()=>r.tabs,async()=>{await G(),u(),i()},{immediate:!0});const d=oe(y,()=>u());return Re(()=>{l.forEach(a=>a.stop()),l.length=0,d.stop()}),s({ref:y,update:u}),(a,T)=>h.value?(xe(),Ee("div",{key:0,ref_key:"barRef",ref:y,class:we([K(t).e("active-bar"),K(t).is(K(c).props.tabPosition)]),style:He(N.value)},null,6)):Pe("v-if",!0)}}),Tt=yt;const Ct=5,Nt=({scrollable:e,navOffset:s,navSize:r,navContainerSize:c,isHorizontal:t})=>{const y=_(!1),N=x(()=>Math.max(r.value-c.value,0));let h,v;const u=d=>{if(!e.value||d.touches.length!==1)return;const{clientX:a,clientY:T}=Te(d);h={startX:a,startY:T,startOffset:s.value},v=void 0},l=d=>{if(!h||!e.value)return;if(d.touches.length!==1){i();return}const{clientX:a,clientY:T}=Te(d),b=h.startX-a,E=h.startY-T,P=t.value?b:E,n=t.value?E:b,p=Math.abs(P),S=Math.abs(n);if(vt(v)){if(Math.max(p,S)<=Ct)return;v=p>S}if(!v)return;const w=ke(h.startOffset+P,0,N.value);N.value<=0||w===s.value||!d.cancelable||(d.preventDefault(),y.value=!0,s.value=w)},i=()=>{h=void 0,v=void 0,y.value=!1};return{isTouchScrolling:y,handleTouchStart:u,handleTouchMove:l,handleTouchEnd:i}},St=q({panes:{type:j(Array),default:()=>le([])},currentName:{type:[String,Number],default:""},editable:Boolean,type:{type:String,values:["card","border-card",""],default:""},stretch:Boolean,tabindex:{type:[String,Number],default:void 0}}),_t={tabClick:(e,s,r)=>r instanceof Event,tabRemove:(e,s)=>s instanceof Event},Ne="ElTabNav",Rt=X({name:Ne,props:St,emits:_t,setup(e,{expose:s,emit:r}){const c=ue(Q);c||de(Ne,"<el-tabs><tab-nav /></el-tabs>");const t=J("tabs"),y=Qe(),N=Ze(),h=_(),v=_(),u=_(),l=_({}),i=_(),d=_(!1),a=_(0),T=_(!1),b=_(!0),E=_(!1),P=se(),n=x(()=>["top","bottom"].includes(c.props.tabPosition)),p=x(()=>n.value?"width":"height"),S=x(()=>{const o=p.value==="width"?"X":"Y";return{transition:E.value||Me.value?"none":void 0,transform:`translate${o}(-${a.value}px)`}}),{width:w,height:M}=ye(h),{width:I,height:L}=ye(v,{width:0,height:0},{box:"border-box"}),B=x(()=>n.value?w.value:M.value),W=x(()=>n.value?I.value:L.value),{onWheel:Ae}=mt({atStartEdge:x(()=>a.value<=0),atEndEdge:x(()=>W.value-a.value<=B.value),layout:x(()=>n.value?"horizontal":"vertical")},o=>{a.value=ke(a.value+o,0,W.value-B.value)}),ze=o=>{E.value=!0,Ae(o),ce(()=>{E.value=!1})},{isTouchScrolling:Me,handleTouchStart:Fe,handleTouchMove:Ve,handleTouchEnd:fe}=Nt({scrollable:d,navOffset:a,navSize:W,navContainerSize:B,isHorizontal:n}),De=()=>{if(!h.value)return;const o=h.value.getBoundingClientRect()[p.value],m=a.value;m&&(a.value=m>o?m-o:0)},Le=()=>{if(!h.value||!v.value)return;const o=v.value.getBoundingClientRect()[p.value],m=h.value.getBoundingClientRect()[p.value],f=a.value;te(o-f,m)&&(a.value=o-f>m*2?f+m:o-m)},ve=async()=>{const o=v.value;if(!d.value||!u.value||!h.value||!o)return;await G();const m=l.value[e.currentName];if(!m)return;const f=h.value,C=m.getBoundingClientRect(),R=f.getBoundingClientRect(),F=R.left+1,A=R.right-1,V=o.getBoundingClientRect(),ee=n.value?V.width-R.width:V.height-R.height,z=a.value;let O=z;n.value?(C.left<F&&(O=z-(F-C.left)),C.right>A&&(O=z+C.right-A)):(C.top<R.top&&(O=z-(R.top-C.top)),C.bottom>R.bottom&&(O=z+(C.bottom-R.bottom))),O=Math.max(O,0),a.value=Math.min(O,ee)},be=()=>{var C;if(!v.value||!h.value)return;e.stretch&&((C=i.value)==null||C.update());const o=v.value.getBoundingClientRect()[p.value],m=h.value.getBoundingClientRect()[p.value],f=a.value;m<o?(d.value=d.value||{},d.value.prev=f,d.value.next=te(o,f+m),te(m,o-f)&&(a.value=o-m)):(d.value=!1,f>0&&(a.value=0))},We=o=>{const m=re(o);let f=0;switch(m){case $.left:case $.up:f=-1;break;case $.right:case $.down:f=1;break;default:return}const C=Array.from(o.currentTarget.querySelectorAll("[role=tab]:not(.is-disabled)"));let R=C.indexOf(o.target)+f;R<0?R=C.length-1:R>=C.length&&(R=0),C[R].focus({preventScroll:!0}),C[R].click(),he()},he=()=>{b.value&&(T.value=!0)},Z=()=>T.value=!1,Ye=(o,m)=>{l.value[m]=o},Xe=async()=>{var o;await G(),(o=l.value[e.currentName])==null||o.focus({preventScroll:!0})};return D(y,o=>{o==="hidden"?b.value=!1:o==="visible"&&setTimeout(()=>b.value=!0,50)}),D(N,o=>{o?setTimeout(()=>b.value=!0,50):b.value=!1}),oe(u,()=>{ce(be)}),_e(()=>setTimeout(()=>ve(),0)),je(()=>be()),s({scrollToActiveTab:ve,removeFocus:Z,focusActiveTab:Xe,tabListRef:v,tabBarRef:i,scheduleRender:()=>U(P)}),()=>{const o=d.value?[g("span",{class:[t.e("nav-prev"),t.is("disabled",!d.value.prev)],onClick:De},[g(H,null,{default:()=>[g(Ge,null,null)]})]),g("span",{class:[t.e("nav-next"),t.is("disabled",!d.value.next)],onClick:Le},[g(H,null,{default:()=>[g(qe,null,null)]})])]:null,m=e.panes.map((f,C)=>{var pe,me;const R=f.uid,F=f.props.disabled,A=f.props.name??f.index??`${C}`,V=!F&&(f.isClosable||f.props.closable!==!1&&e.editable);f.index=`${C}`;const ee=V?g(H,{class:"is-icon-close",onClick:k=>r("tabRemove",f,k)},{default:()=>[g(Je,null,null)]}):null,z=((me=(pe=f.slots).label)==null?void 0:me.call(pe))||f.props.label,O=!F&&f.active?e.tabindex??c.props.tabindex:-1;return g("div",{ref:k=>Ye(k,A),class:[t.e("item"),t.is(c.props.tabPosition),t.is("active",f.active),t.is("disabled",F),t.is("closable",V),t.is("focus",T.value)],id:`tab-${A}`,key:`tab-${R}`,"aria-controls":`pane-${A}`,role:"tab","aria-selected":f.active,tabindex:O,onFocus:()=>he(),onBlur:()=>Z(),onClick:k=>{Z(),r("tabClick",f,A,k)},onKeydown:k=>{const ge=re(k);V&&(ge===$.delete||ge===$.backspace)&&r("tabRemove",f,k)}},[z,ee])});return P.value,g("div",{ref:u,class:[t.e("nav-wrap"),t.is("scrollable",!!d.value),t.is(c.props.tabPosition)]},[o,g("div",{class:t.e("nav-scroll"),ref:h},[e.panes.length>0?g("div",{class:[t.e("nav"),t.is(c.props.tabPosition),t.is("stretch",e.stretch&&["top","bottom"].includes(c.props.tabPosition))],ref:v,style:S.value,role:"tablist",onKeydown:We,onWheel:ze,onTouchstart:Fe,onTouchmove:Ve,onTouchend:fe,onTouchcancel:fe},[e.type?null:g(Tt,{ref:i,tabs:[...e.panes],tabRefs:l.value},null),m]):null])])}}}),xt=q({type:{type:String,values:["card","border-card",""],default:""},closable:Boolean,addable:Boolean,modelValue:{type:[String,Number]},defaultValue:{type:[String,Number]},editable:Boolean,tabPosition:{type:String,values:["top","right","bottom","left"],default:"top"},beforeLeave:{type:j(Function),default:()=>!0},stretch:Boolean,tabindex:{type:[String,Number],default:0}}),ne=e=>tt(e)||at(e),Et={[Oe]:e=>ne(e),tabClick:(e,s)=>s instanceof Event,tabChange:e=>ne(e),edit:(e,s)=>["remove","add"].includes(s),tabRemove:e=>ne(e),tabAdd:()=>!0},wt=X({name:"ElTabs",props:xt,emits:Et,setup(e,{emit:s,slots:r,expose:c}){const t=J("tabs"),y=x(()=>["left","right"].includes(e.tabPosition)),{children:N,addChild:h,removeChild:v,ChildrenSorter:u}=pt(Be(),"ElTabPane"),l=_(),i=_((Y(e.modelValue)?e.defaultValue:e.modelValue)??"0"),d=async(n,p=!1)=>{var S,w,M,I;if(!(i.value===n||Y(n)))try{let L;if(e.beforeLeave){const B=e.beforeLeave(n,i.value);L=B instanceof Promise?await B:B}else L=!0;if(L!==!1){const B=(S=N.value.find(W=>W.paneName===i.value))==null?void 0:S.isFocusInsidePane();i.value=n,p&&(s(Oe,n),s("tabChange",n)),(M=(w=l.value)==null?void 0:w.removeFocus)==null||M.call(w),B&&((I=l.value)==null||I.focusActiveTab())}}catch{}},a=(n,p,S)=>{n.props.disabled||(s("tabClick",n,S),d(p,!0))},T=(n,p)=>{n.props.disabled||Y(n.props.name)||(p.stopPropagation(),s("edit",n.props.name,"remove"),s("tabRemove",n.props.name))},b=()=>{s("edit",void 0,"add"),s("tabAdd")},E=n=>{const p=re(n);[$.enter,$.numpadEnter].includes(p)&&b()},P=n=>{const p=n.el.firstChild,S=["bottom","right"].includes(e.tabPosition)?n.children[0].el:n.children[1].el;p!==S&&p.before(S)};return D(()=>e.modelValue,n=>d(n)),D(i,async()=>{var n;await G(),(n=l.value)==null||n.scrollToActiveTab()}),nt(Q,{props:e,currentName:i,registerPane:h,unregisterPane:v,nav$:l}),c({currentName:i,get tabNavRef(){return bt(l.value,["scheduleRender"])}}),()=>{const n=r["add-icon"],p=e.editable||e.addable?g("div",{class:[t.e("new-tab"),y.value&&t.e("new-tab-vertical")],tabindex:e.tabindex,onClick:b,onKeydown:E},[n?ie(r,"add-icon"):g(H,{class:t.is("icon-plus")},{default:()=>[g(et,null,null)]})]):null,S=()=>g(Rt,{ref:l,currentName:i.value,editable:e.editable,type:e.type,panes:N.value,stretch:e.stretch,onTabClick:a,onTabRemove:T},null),w=g("div",{class:[t.e("header"),y.value&&t.e("header-vertical"),t.is(e.tabPosition)]},[g(u,null,{default:S,$stable:!0}),p]),M=g("div",{class:t.e("content")},[ie(r,"default")]);return g("div",{class:[t.b(),t.m(e.tabPosition),{[t.m("card")]:e.type==="card",[t.m("border-card")]:e.type==="border-card"}],onVnodeMounted:P,onVnodeUpdated:P},[M,w])}}}),Pt=q({label:{type:String,default:""},name:{type:[String,Number]},closable:{type:Boolean,default:void 0},disabled:Boolean,lazy:Boolean}),Bt=["id","aria-hidden","aria-labelledby"],Se="ElTabPane";var Ot=X({name:Se,__name:"tab-pane",props:Pt,setup(e){const s=e,r=Be(),c=st(),t=ue(Q);t||de(Se,"usage: <el-tabs><el-tab-pane /></el-tabs/>");const y=J("tab-pane"),N=_(),h=_(),v=x(()=>s.closable??t.props.closable),u=x(()=>t.currentName.value===(s.name??h.value)),l=_(u.value),i=x(()=>s.name??h.value),d=x(()=>!s.lazy||l.value||u.value),a=()=>{var b;return(b=N.value)==null?void 0:b.contains(document.activeElement)};D(u,b=>{b&&(l.value=!0)});const T=lt({uid:r.uid,getVnode:()=>r.vnode,slots:c,props:s,paneName:i,active:u,index:h,isClosable:v,isFocusInsidePane:a});return t.registerPane(T),Re(()=>{t.unregisterPane(T)}),ot(()=>{var b;c.label&&((b=t.nav$.value)==null||b.scheduleRender())}),(b,E)=>d.value?rt((xe(),Ee("div",{key:0,id:`pane-${i.value}`,ref_key:"paneRef",ref:N,class:we(K(y).b()),role:"tabpanel","aria-hidden":!u.value,"aria-labelledby":`tab-${i.value}`},[ie(b.$slots,"default")],10,Bt)),[[it,u.value]]):Pe("v-if",!0)}}),$e=Ot;const Lt=ct(wt,{TabPane:$e}),Wt=ut($e);export{Wt as E,Lt as a};
|