import{bw as ge,bZ as _e,b_ as Ne,aq as D,aT as J,bN as ne,d as M,P as I,a$ as Q,b1 as Y,ay as U,r as P,i as O,n as G,b2 as le,o as oe,c as re,a0 as ie,e as k,V as Ce,aI as ce,b$ as Te,c0 as we,M as F,b as ue,aD as Pe,k as v,aa as L,c1 as $e,c2 as Se,bt as Ee,bC as V,bv as xe,aX as ke,aH as Be,aZ as de,aw as be,aA as te,aJ as Oe,as as Re,b3 as ze,c3 as ae,Q as Ae,c4 as Me,w as Fe,U as Le,x as Ve,aL as De,b9 as Ie}from"./index.js";import{c as B}from"./strings.js";const K=Symbol("tabsRootContextKey"),Ue=(e,s,f)=>_e(e.subTree).filter(t=>{var n;return Ne(t)&&((n=t.type)==null?void 0:n.name)===s&&!!t.component}).map(t=>t.component.uid).map(t=>f[t]).filter(t=>!!t),Ke=(e,s)=>{const f={},C=ge([]);return{children:C,addChild:n=>{f[n.uid]=n,C.value=Ue(e,s,f)},removeChild:n=>{delete f[n],C.value=C.value.filter(S=>S.uid!==n)}}},qe=D({tabs:{type:J(Array),default:()=>ne([])}}),ve="ElTabBar",He=M({name:ve}),We=M({...He,props:qe,setup(e,{expose:s}){const f=e,C=I(),i=Q(K);i||Y(ve,"<el-tabs><el-tab-bar /></el-tabs>");const t=U("tabs"),n=P(),S=P(),d=()=>{let m=0,r=0;const u=["top","bottom"].includes(i.props.tabPosition)?"width":"height",b=u==="width"?"x":"y",E=b==="x"?"left":"top";return f.tabs.every($=>{var R,a;const h=(a=(R=C.parent)==null?void 0:R.refs)==null?void 0:a[`tab-${$.uid}`];if(!h)return!1;if(!$.active)return!0;m=h[`offset${B(E)}`],r=h[`client${B(u)}`];const g=window.getComputedStyle(h);return u==="width"&&(f.tabs.length>1&&(r-=Number.parseFloat(g.paddingLeft)+Number.parseFloat(g.paddingRight)),m+=Number.parseFloat(g.paddingLeft)),!1}),{[u]:`${r}px`,transform:`translate${B(b)}(${m}px)`}},y=()=>S.value=d();return O(()=>f.tabs,async()=>{await G(),y()},{immediate:!0}),le(n,()=>y()),s({ref:n,update:y}),(m,r)=>(oe(),re("div",{ref_key:"barRef",ref:n,class:ie([k(t).e("active-bar"),k(t).is(k(i).props.tabPosition)]),style:Ce(S.value)},null,6))}});var Xe=ce(We,[["__file","/home/runner/work/element-plus/element-plus/packages/components/tabs/src/tab-bar.vue"]]);const Ze=D({panes:{type:J(Array),default:()=>ne([])},currentName:{type:[String,Number],default:""},editable:Boolean,type:{type:String,values:["card","border-card",""],default:""},stretch:Boolean}),je={tabClick:(e,s,f)=>f instanceof Event,tabRemove:(e,s)=>s instanceof Event},se="ElTabNav",Je=M({name:se,props:Ze,emits:je,setup(e,{expose:s,emit:f}){const C=I(),i=Q(K);i||Y(se,"<el-tabs><tab-nav /></el-tabs>");const t=U("tabs"),n=Te(),S=we(),d=P(),y=P(),m=P(),r=P(!1),u=P(0),b=P(!1),E=P(!0),$=F(()=>["top","bottom"].includes(i.props.tabPosition)?"width":"height"),R=F(()=>({transform:`translate${$.value==="width"?"X":"Y"}(-${u.value}px)`})),a=()=>{if(!d.value)return;const l=d.value[`offset${B($.value)}`],c=u.value;if(!c)return;const o=c>l?c-l:0;u.value=o},h=()=>{if(!d.value||!y.value)return;const l=y.value[`offset${B($.value)}`],c=d.value[`offset${B($.value)}`],o=u.value;if(l-o<=c)return;const T=l-o>c*2?o+c:l-c;u.value=T},g=async()=>{const l=y.value;if(!r.value||!m.value||!d.value||!l)return;await G();const c=m.value.querySelector(".is-active");if(!c)return;const o=d.value,T=["top","bottom"].includes(i.props.tabPosition),N=c.getBoundingClientRect(),_=o.getBoundingClientRect(),x=T?l.offsetWidth-_.width:l.offsetHeight-_.height,w=u.value;let p=w;T?(N.left<_.left&&(p=w-(_.left-N.left)),N.right>_.right&&(p=w+N.right-_.right)):(N.top<_.top&&(p=w-(_.top-N.top)),N.bottom>_.bottom&&(p=w+(N.bottom-_.bottom))),p=Math.max(p,0),u.value=Math.min(p,x)},z=()=>{if(!y.value||!d.value)return;const l=y.value[`offset${B($.value)}`],c=d.value[`offset${B($.value)}`],o=u.value;if(c<l){const T=u.value;r.value=r.value||{},r.value.prev=T,r.value.next=T+c<l,l-T<c&&(u.value=l-c)}else r.value=!1,o>0&&(u.value=0)},q=l=>{const c=l.code,{up:o,down:T,left:N,right:_}=V;if(![o,T,N,_].includes(c))return;const x=Array.from(l.currentTarget.querySelectorAll("[role=tab]:not(.is-disabled)")),w=x.indexOf(l.target);let p;c===N||c===o?w===0?p=x.length-1:p=w-1:w<x.length-1?p=w+1:p=0,x[p].focus({preventScroll:!0}),x[p].click(),ee()},ee=()=>{E.value&&(b.value=!0)},H=()=>b.value=!1;return O(n,l=>{l==="hidden"?E.value=!1:l==="visible"&&setTimeout(()=>E.value=!0,50)}),O(S,l=>{l?setTimeout(()=>E.value=!0,50):E.value=!1}),le(m,z),ue(()=>setTimeout(()=>g(),0)),Pe(()=>z()),s({scrollToActiveTab:g,removeFocus:H}),O(()=>e.panes,()=>C.update(),{flush:"post"}),()=>{const l=r.value?[v("span",{class:[t.e("nav-prev"),t.is("disabled",!r.value.prev)],onClick:a},[v(L,null,{default:()=>[v($e,null,null)]})]),v("span",{class:[t.e("nav-next"),t.is("disabled",!r.value.next)],onClick:h},[v(L,null,{default:()=>[v(Se,null,null)]})])]:null,c=e.panes.map((o,T)=>{var N,_,x,w;const p=o.uid,W=o.props.disabled,X=(_=(N=o.props.name)!=null?N:o.index)!=null?_:`${T}`,Z=!W&&(o.isClosable||e.editable);o.index=`${T}`;const pe=Z?v(L,{class:"is-icon-close",onClick:A=>f("tabRemove",o,A)},{default:()=>[v(Ee,null,null)]}):null,he=((w=(x=o.slots).label)==null?void 0:w.call(x))||o.props.label,ye=!W&&o.active?0:-1;return v("div",{ref:`tab-${p}`,class:[t.e("item"),t.is(i.props.tabPosition),t.is("active",o.active),t.is("disabled",W),t.is("closable",Z),t.is("focus",b.value)],id:`tab-${X}`,key:`tab-${p}`,"aria-controls":`pane-${X}`,role:"tab","aria-selected":o.active,tabindex:ye,onFocus:()=>ee(),onBlur:()=>H(),onClick:A=>{H(),f("tabClick",o,X,A)},onKeydown:A=>{Z&&(A.code===V.delete||A.code===V.backspace)&&f("tabRemove",o,A)}},[he,pe])});return v("div",{ref:m,class:[t.e("nav-wrap"),t.is("scrollable",!!r.value),t.is(i.props.tabPosition)]},[l,v("div",{class:t.e("nav-scroll"),ref:d},[v("div",{class:[t.e("nav"),t.is(i.props.tabPosition),t.is("stretch",e.stretch&&["top","bottom"].includes(i.props.tabPosition))],ref:y,style:R.value,role:"tablist",onKeydown:q},[e.type?null:v(Xe,{tabs:[...e.panes]},null),c])])])}}}),Qe=D({type:{type:String,values:["card","border-card",""],default:""},activeName:{type:[String,Number]},closable:Boolean,addable:Boolean,modelValue:{type:[String,Number]},editable:Boolean,tabPosition:{type:String,values:["top","right","bottom","left"],default:"top"},beforeLeave:{type:J(Function),default:()=>!0},stretch:Boolean}),j=e=>Oe(e)||Re(e),Ye={[be]:e=>j(e),tabClick:(e,s)=>s instanceof Event,tabChange:e=>j(e),edit:(e,s)=>["remove","add"].includes(s),tabRemove:e=>j(e),tabAdd:()=>!0};var Ge=M({name:"ElTabs",props:Qe,emits:Ye,setup(e,{emit:s,slots:f,expose:C}){var i,t;const n=U("tabs"),{children:S,addChild:d,removeChild:y}=Ke(I(),"ElTabPane"),m=P(),r=P((t=(i=e.modelValue)!=null?i:e.activeName)!=null?t:"0"),u=a=>{r.value=a,s(be,a),s("tabChange",a)},b=async a=>{var h,g,z;if(!(r.value===a||te(a)))try{await((h=e.beforeLeave)==null?void 0:h.call(e,a,r.value))!==!1&&(u(a),(z=(g=m.value)==null?void 0:g.removeFocus)==null||z.call(g))}catch{}},E=(a,h,g)=>{a.props.disabled||(b(h),s("tabClick",a,g))},$=(a,h)=>{a.props.disabled||te(a.props.name)||(h.stopPropagation(),s("edit",a.props.name,"remove"),s("tabRemove",a.props.name))},R=()=>{s("edit",void 0,"add"),s("tabAdd")};return xe({from:'"activeName"',replacement:'"model-value" or "v-model"',scope:"ElTabs",version:"2.3.0",ref:"https://element-plus.org/en-US/component/tabs.html#attributes",type:"Attribute"},F(()=>!!e.activeName)),O(()=>e.activeName,a=>b(a)),O(()=>e.modelValue,a=>b(a)),O(r,async()=>{var a;await G(),(a=m.value)==null||a.scrollToActiveTab()}),ke(K,{props:e,currentName:r,registerPane:d,unregisterPane:y}),C({currentName:r}),()=>{const a=e.editable||e.addable?v("span",{class:n.e("new-tab"),tabindex:"0",onClick:R,onKeydown:z=>{z.code===V.enter&&R()}},[v(L,{class:n.is("icon-plus")},{default:()=>[v(Be,null,null)]})]):null,h=v("div",{class:[n.e("header"),n.is(e.tabPosition)]},[a,v(Je,{ref:m,currentName:r.value,editable:e.editable,type:e.type,panes:S.value,stretch:e.stretch,onTabClick:E,onTabRemove:$},null)]),g=v("div",{class:n.e("content")},[de(f,"default")]);return v("div",{class:[n.b(),n.m(e.tabPosition),{[n.m("card")]:e.type==="card",[n.m("border-card")]:e.type==="border-card"}]},[...e.tabPosition!=="bottom"?[h,g]:[g,h]])}}});const et=D({label:{type:String,default:""},name:{type:[String,Number]},closable:Boolean,disabled:Boolean,lazy:Boolean}),tt=["id","aria-hidden","aria-labelledby"],fe="ElTabPane",at=M({name:fe}),st=M({...at,props:et,setup(e){const s=e,f=I(),C=ze(),i=Q(K);i||Y(fe,"usage: <el-tabs><el-tab-pane /></el-tabs/>");const t=U("tab-pane"),n=P(),S=F(()=>s.closable||i.props.closable),d=ae(()=>{var b;return i.currentName.value===((b=s.name)!=null?b:n.value)}),y=P(d.value),m=F(()=>{var b;return(b=s.name)!=null?b:n.value}),r=ae(()=>!s.lazy||y.value||d.value);O(d,b=>{b&&(y.value=!0)});const u=Ae({uid:f.uid,slots:C,props:s,paneName:m,active:d,index:n,isClosable:S});return ue(()=>{i.registerPane(u)}),Me(()=>{i.unregisterPane(u.uid)}),(b,E)=>k(r)?Fe((oe(),re("div",{key:0,id:`pane-${k(m)}`,class:ie(k(t).b()),role:"tabpanel","aria-hidden":!k(d),"aria-labelledby":`tab-${k(m)}`},[de(b.$slots,"default")],10,tt)),[[Le,k(d)]]):Ve("v-if",!0)}});var me=ce(st,[["__file","/home/runner/work/element-plus/element-plus/packages/components/tabs/src/tab-pane.vue"]]);const ot=De(Ge,{TabPane:me}),rt=Ie(me);export{rt as E,ot as a};
|