el-tabs.5174ba6c.js 8.9 KB

1
  1. import{D as z,E as J,ap as oe,f as L,I as O,R as V,j as P,k as B,C as W,b3 as ne,o as re,l as ie,q as ue,u as T,a0 as Le,H as ce,Y as j,ch as qe,ci as Me,J as q,at as ve,b4 as ze,x as v,P as H,aL as Ve,aM as je,aK as He,G as U,K as Ue,cg as Xe,r as de,bM as pe,av as Ye,aq as De,an as Ge,cj as be,a7 as Ie,a5 as Je,a8 as Oe,a9 as We,X as Qe,a1 as Ze,a2 as ea,__tla as aa}from"./entry.7ac74952.js";import{t as Q}from"./error.78e43d3e.js";import{c as E,__tla as ta}from"./strings.dc56295c.js";import{U as me}from"./event.9519ab40.js";import{u as la,__tla as sa}from"./index.46aa596f.js";import{u as oa,__tla as na}from"./index.623d89cd.js";let fe,he,ra=Promise.all([(()=>{try{return aa}catch{}})(),(()=>{try{return ta}catch{}})(),(()=>{try{return sa}catch{}})(),(()=>{try{return na}catch{}})()]).then(async()=>{const M=Symbol("tabsRootContextKey"),ye=z({tabs:{type:J(Array),default:()=>oe([])}}),Z="ElTabBar",ge=L({name:Z}),_e=L({...ge,props:ye,setup(e,{expose:o}){const k=e,F=j(),i=O(M);i||Q(Z,"<el-tabs><el-tab-bar /></el-tabs>");const s=V("tabs"),d=P(),S=P(),u=()=>{let p=0,b=0;const c=["top","bottom"].includes(i.props.tabPosition)?"width":"height",l=c==="width"?"x":"y",R=l==="x"?"left":"top";return k.tabs.every(N=>{var $,a;const f=(a=($=F.parent)==null?void 0:$.refs)==null?void 0:a[`tab-${N.uid}`];if(!f)return!1;if(!N.active)return!0;p=f[`offset${E(R)}`],b=f[`client${E(c)}`];const g=window.getComputedStyle(f);return c==="width"&&(k.tabs.length>1&&(b-=Number.parseFloat(g.paddingLeft)+Number.parseFloat(g.paddingRight)),p+=Number.parseFloat(g.paddingLeft)),!1}),{[c]:`${b}px`,transform:`translate${E(l)}(${p}px)`}},h=()=>S.value=u();return B(()=>k.tabs,async()=>{await W(),h()},{immediate:!0}),ne(d,()=>h()),o({ref:d,update:h}),(p,b)=>(re(),ie("div",{ref_key:"barRef",ref:d,class:ue([T(s).e("active-bar"),T(s).is(T(i).props.tabPosition)]),style:Le(S.value)},null,6))}});var xe=ce(_e,[["__file","/home/runner/work/element-plus/element-plus/packages/components/tabs/src/tab-bar.vue"]]);const Pe=z({panes:{type:J(Array),default:()=>oe([])},currentName:{type:[String,Number],default:""},editable:Boolean,type:{type:String,values:["card","border-card",""],default:""},stretch:Boolean}),ke={tabClick:(e,o,k)=>k instanceof Event,tabRemove:(e,o)=>o instanceof Event},ee="ElTabNav",we=L({name:ee,props:Pe,emits:ke,setup(e,{expose:o,emit:k}){const F=j(),i=O(M);i||Q(ee,"<el-tabs><tab-nav /></el-tabs>");const s=V("tabs"),d=qe(),S=Me(),u=P(),h=P(),p=P(),b=P(),c=P(!1),l=P(0),R=P(!1),N=P(!0),$=q(()=>["top","bottom"].includes(i.props.tabPosition)?"width":"height"),a=q(()=>({transform:`translate${$.value==="width"?"X":"Y"}(-${l.value}px)`})),f=()=>{if(!u.value)return;const n=u.value[`offset${E($.value)}`],r=l.value;if(!r)return;const t=r>n?r-n:0;l.value=t},g=()=>{if(!u.value||!h.value)return;const n=h.value[`offset${E($.value)}`],r=u.value[`offset${E($.value)}`],t=l.value;if(n-t<=r)return;const _=n-t>r*2?t+r:n-r;l.value=_},A=async()=>{const n=h.value;if(!c.value||!p.value||!u.value||!n)return;await W();const r=p.value.querySelector(".is-active");if(!r)return;const t=u.value,_=["top","bottom"].includes(i.props.tabPosition),x=r.getBoundingClientRect(),y=t.getBoundingClientRect(),C=_?n.offsetWidth-y.width:n.offsetHeight-y.height,w=l.value;let m=w;_?(x.left<y.left&&(m=w-(y.left-x.left)),x.right>y.right&&(m=w+x.right-y.right)):(x.top<y.top&&(m=w-(y.top-x.top)),x.bottom>y.bottom&&(m=w+(x.bottom-y.bottom))),m=Math.max(m,0),l.value=Math.min(m,C)},le=()=>{var n;if(!h.value||!u.value)return;e.stretch&&((n=b.value)==null||n.update());const r=h.value[`offset${E($.value)}`],t=u.value[`offset${E($.value)}`],_=l.value;t<r?(c.value=c.value||{},c.value.prev=_,c.value.next=_+t<r,r-_<t&&(l.value=r-t)):(c.value=!1,_>0&&(l.value=0))},Ee=n=>{const r=n.code,{up:t,down:_,left:x,right:y}=U;if(![t,_,x,y].includes(r))return;const C=Array.from(n.currentTarget.querySelectorAll("[role=tab]:not(.is-disabled)")),w=C.indexOf(n.target);let m;r===x||r===t?w===0?m=C.length-1:m=w-1:w<C.length-1?m=w+1:m=0,C[m].focus({preventScroll:!0}),C[m].click(),se()},se=()=>{N.value&&(R.value=!0)},Y=()=>R.value=!1;return B(d,n=>{n==="hidden"?N.value=!1:n==="visible"&&setTimeout(()=>N.value=!0,50)}),B(S,n=>{n?setTimeout(()=>N.value=!0,50):N.value=!1}),ne(p,le),ve(()=>setTimeout(()=>A(),0)),ze(()=>le()),o({scrollToActiveTab:A,removeFocus:Y}),B(()=>e.panes,()=>F.update(),{flush:"post",deep:!0}),()=>{const n=c.value?[v("span",{class:[s.e("nav-prev"),s.is("disabled",!c.value.prev)],onClick:f},[v(H,null,{default:()=>[v(Ve,null,null)]})]),v("span",{class:[s.e("nav-next"),s.is("disabled",!c.value.next)],onClick:g},[v(H,null,{default:()=>[v(je,null,null)]})])]:null,r=e.panes.map((t,_)=>{var x,y,C,w;const m=t.uid,D=t.props.disabled,G=(y=(x=t.props.name)!=null?x:t.index)!=null?y:`${_}`,I=!D&&(t.isClosable||e.editable);t.index=`${_}`;const Fe=I?v(H,{class:"is-icon-close",onClick:K=>k("tabRemove",t,K)},{default:()=>[v(He,null,null)]}):null,Ae=((w=(C=t.slots).label)==null?void 0:w.call(C))||t.props.label,Ke=!D&&t.active?0:-1;return v("div",{ref:`tab-${m}`,class:[s.e("item"),s.is(i.props.tabPosition),s.is("active",t.active),s.is("disabled",D),s.is("closable",I),s.is("focus",R.value)],id:`tab-${G}`,key:`tab-${m}`,"aria-controls":`pane-${G}`,role:"tab","aria-selected":t.active,tabindex:Ke,onFocus:()=>se(),onBlur:()=>Y(),onClick:K=>{Y(),k("tabClick",t,G,K)},onKeydown:K=>{I&&(K.code===U.delete||K.code===U.backspace)&&k("tabRemove",t,K)}},[Ae,Fe])});return v("div",{ref:p,class:[s.e("nav-wrap"),s.is("scrollable",!!c.value),s.is(i.props.tabPosition)]},[n,v("div",{class:s.e("nav-scroll"),ref:u},[v("div",{class:[s.e("nav"),s.is(i.props.tabPosition),s.is("stretch",e.stretch&&["top","bottom"].includes(i.props.tabPosition))],ref:h,style:a.value,role:"tablist",onKeydown:Ee},[e.type?null:v(xe,{ref:b,tabs:[...e.panes]},null),r])])])}}}),$e=z({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}),X=e=>Ye(e)||De(e),Ne={[me]:e=>X(e),tabClick:(e,o)=>o instanceof Event,tabChange:e=>X(e),edit:(e,o)=>["remove","add"].includes(o),tabRemove:e=>X(e),tabAdd:()=>!0};var Ce=L({name:"ElTabs",props:$e,emits:Ne,setup(e,{emit:o,slots:k,expose:F}){var i,s;const d=V("tabs"),{children:S,addChild:u,removeChild:h}=la(j(),"ElTabPane"),p=P(),b=P((s=(i=e.modelValue)!=null?i:e.activeName)!=null?s:"0"),c=a=>{b.value=a,o(me,a),o("tabChange",a)},l=async a=>{var f,g,A;if(!(b.value===a||pe(a)))try{await((f=e.beforeLeave)==null?void 0:f.call(e,a,b.value))!==!1&&(c(a),(A=(g=p.value)==null?void 0:g.removeFocus)==null||A.call(g))}catch{}},R=(a,f,g)=>{a.props.disabled||(l(f),o("tabClick",a,g))},N=(a,f)=>{a.props.disabled||pe(a.props.name)||(f.stopPropagation(),o("edit",a.props.name,"remove"),o("tabRemove",a.props.name))},$=()=>{o("edit",void 0,"add"),o("tabAdd")};return oa({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"},q(()=>!!e.activeName)),B(()=>e.activeName,a=>l(a)),B(()=>e.modelValue,a=>l(a)),B(b,async()=>{var a;await W(),(a=p.value)==null||a.scrollToActiveTab()}),Ue(M,{props:e,currentName:b,registerPane:u,unregisterPane:h}),F({currentName:b}),()=>{const a=e.editable||e.addable?v("span",{class:d.e("new-tab"),tabindex:"0",onClick:$,onKeydown:A=>{A.code===U.enter&&$()}},[v(H,{class:d.is("icon-plus")},{default:()=>[v(Xe,null,null)]})]):null,f=v("div",{class:[d.e("header"),d.is(e.tabPosition)]},[a,v(we,{ref:p,currentName:b.value,editable:e.editable,type:e.type,panes:S.value,stretch:e.stretch,onTabClick:R,onTabRemove:N},null)]),g=v("div",{class:d.e("content")},[de(k,"default")]);return v("div",{class:[d.b(),d.m(e.tabPosition),{[d.m("card")]:e.type==="card",[d.m("border-card")]:e.type==="border-card"}]},[...e.tabPosition!=="bottom"?[f,g]:[g,f]])}}});const Te=z({label:{type:String,default:""},name:{type:[String,Number]},closable:Boolean,disabled:Boolean,lazy:Boolean}),Se=["id","aria-hidden","aria-labelledby"],ae="ElTabPane",Re=L({name:ae}),Be=L({...Re,props:Te,setup(e){const o=e,k=j(),F=Ge(),i=O(M);i||Q(ae,"usage: <el-tabs><el-tab-pane /></el-tabs/>");const s=V("tab-pane"),d=P(),S=q(()=>o.closable||i.props.closable),u=be(()=>{var l;return i.currentName.value===((l=o.name)!=null?l:d.value)}),h=P(u.value),p=q(()=>{var l;return(l=o.name)!=null?l:d.value}),b=be(()=>!o.lazy||h.value||u.value);B(u,l=>{l&&(h.value=!0)});const c=Ie({uid:k.uid,slots:F,props:o,paneName:p,active:u,index:d,isClosable:S});return ve(()=>{i.registerPane(c)}),Je(()=>{i.unregisterPane(c.uid)}),(l,R)=>T(b)?Oe((re(),ie("div",{key:0,id:`pane-${T(p)}`,class:ue(T(s).b()),role:"tabpanel","aria-hidden":!T(u),"aria-labelledby":`tab-${T(p)}`},[de(l.$slots,"default")],10,Se)),[[We,T(u)]]):Qe("v-if",!0)}});var te=ce(Be,[["__file","/home/runner/work/element-plus/element-plus/packages/components/tabs/src/tab-pane.vue"]]);fe=Ze(Ce,{TabPane:te}),he=ea(te)});export{fe as E,ra as __tla,he as a};