fixed-size-list-09a8b46f.js 6.1 KB

123456
  1. import{b4 as ht,bp as dt,b5 as mt,d as St,am as gt,aC as pt,r as C,bq as N,K as w,a as r,l as vt,br as wt,bs as yt,N as st,aQ as B,bt as j,an as K,bu as xt,bv as Ot,__tla as Mt}from"./index-7c994195.js";import{H as at,V as bt,v as zt,I as ot,S as rt,u as Tt,i as G,R as J,g as it,a as Rt,b as nt,c as It,B as Et,F as _t,d as P,A as ct,e as Wt,C as ft,E as $t,f as Lt,h as kt,__tla as Ct}from"./el-virtual-list-042939c7.js";let ut,Z,Dt=Promise.all([(()=>{try{return Mt}catch{}})(),(()=>{try{return Ct}catch{}})()]).then(async()=>{let tt;tt={[at]:"deltaX",[bt]:"deltaY"},Z=({name:u,getOffset:m,getItemSize:S,getItemOffset:E,getEstimatedTotalSize:_,getStartIndexForOffset:z,getStopIndexForStartIndex:T,initCache:g,clearCache:h,validateProps:R})=>St({name:u??"ElVirtualList",props:zt,emits:[ot,rt],setup(e,{emit:d,expose:y}){R(e);const Q=gt(),W=pt("vl"),x=C(g(e,Q)),$=Tt(),I=C(),D=C(),F=C(),i=C({isScrolling:!1,scrollDir:"forward",scrollOffset:N(e.initScrollOffset)?e.initScrollOffset:0,updateRequested:!1,isScrollbarDragging:!1,scrollbarAlwaysOn:e.scrollbarAlwaysOn}),q=w(()=>{const{total:t,cache:l}=e,{isScrolling:a,scrollDir:n,scrollOffset:s}=r(i);if(t===0)return[0,0,0,0];const o=z(e,s,r(x)),f=T(e,o,s,r(x)),c=a&&n!==Et?1:Math.max(1,l),v=a&&n!==_t?1:Math.max(1,l);return[Math.max(0,o-c),Math.max(0,Math.min(t-1,f+v)),o,f]}),p=w(()=>_(e,r(x))),O=w(()=>G(e.layout)),U=w(()=>[{position:"relative",["overflow-"+(O.value?"x":"y")]:"scroll",WebkitOverflowScrolling:"touch",willChange:"transform"},{direction:e.direction,height:N(e.height)?`${e.height}px`:e.height,width:N(e.width)?`${e.width}px`:e.width},e.style]),X=w(()=>{const t=r(p),l=r(O);return{height:l?"100%":`${t}px`,pointerEvents:r(i).isScrolling?"none":void 0,width:l?`${t}px`:"100%"}}),M=w(()=>O.value?e.width:e.height),{onWheel:Y}=(({atEndEdge:t,atStartEdge:l,layout:a},n)=>{let s,o=0;const f=c=>c<0&&l.value||c>0&&t.value;return{hasReachedEdge:f,onWheel:c=>{ht(s);const v=c[tt[a.value]];f(o)&&f(o+v)||(o+=v,dt()||c.preventDefault(),s=mt(()=>{n(o),o=0}))}}})({atStartEdge:w(()=>i.value.scrollOffset<=0),atEndEdge:w(()=>i.value.scrollOffset>=p.value),layout:w(()=>e.layout)},t=>{var l,a;(a=(l=F.value).onMouseUp)==null||a.call(l),b(Math.min(i.value.scrollOffset+t,p.value-M.value))}),A=()=>{const{total:t}=e;if(t>0){const[s,o,f,c]=r(q);d(ot,s,o,f,c)}const{scrollDir:l,scrollOffset:a,updateRequested:n}=r(i);d(rt,l,a,n)},b=t=>{(t=Math.max(t,0))!==r(i).scrollOffset&&(i.value={...r(i),scrollOffset:t,scrollDir:P(r(i).scrollOffset,t),updateRequested:!0},K(L))},H=(t,l=ct)=>{const{scrollOffset:a}=r(i);t=Math.max(0,Math.min(t,e.total-1)),b(m(e,t,l,a,r(x)))},L=()=>{i.value.isScrolling=!1,K(()=>{$.value(-1,null,null)})},k=()=>{const t=I.value;t&&(t.scrollTop=0)};vt(()=>{if(!wt)return;const{initScrollOffset:t}=e,l=r(I);N(t)&&l&&(r(O)?l.scrollLeft=t:l.scrollTop=t),A()}),yt(()=>{const{direction:t,layout:l}=e,{scrollOffset:a,updateRequested:n}=r(i),s=r(I);if(n&&s)if(l===at)if(t===J)switch(it()){case nt:s.scrollLeft=-a;break;case Rt:s.scrollLeft=a;break;default:{const{clientWidth:o,scrollWidth:f}=s;s.scrollLeft=f-o-a;break}}else s.scrollLeft=a;else s.scrollTop=a});const V={ns:W,clientSize:M,estimatedTotalSize:p,windowStyle:U,windowRef:I,innerRef:D,innerStyle:X,itemsToRender:q,scrollbarRef:F,states:i,getItemStyle:t=>{const{direction:l,itemSize:a,layout:n}=e,s=$.value(h&&a,h&&n,h&&l);let o;if(xt(s,String(t)))o=s[t];else{const f=E(e,t,r(x)),c=S(e,t,r(x)),v=r(O),et=l===J,lt=v?f:0;s[t]=o={position:"absolute",left:et?void 0:`${lt}px`,right:et?`${lt}px`:void 0,top:v?0:`${f}px`,height:v?"100%":`${c}px`,width:v?`${c}px`:"100%"}}return o},onScroll:t=>{r(O)?(l=>{const{clientWidth:a,scrollLeft:n,scrollWidth:s}=l.currentTarget,o=r(i);if(o.scrollOffset===n)return;const{direction:f}=e;let c=n;if(f===J)switch(it()){case nt:c=-n;break;case Wt:c=s-a-n}c=Math.max(0,Math.min(c,s-a)),i.value={...o,isScrolling:!0,scrollDir:P(o.scrollOffset,c),scrollOffset:c,updateRequested:!1},K(L)})(t):(l=>{const{clientHeight:a,scrollHeight:n,scrollTop:s}=l.currentTarget,o=r(i);if(o.scrollOffset===s)return;const f=Math.max(0,Math.min(s,n-a));i.value={...o,isScrolling:!0,scrollDir:P(o.scrollOffset,f),scrollOffset:f,updateRequested:!1},K(L)})(t),A()},onScrollbarScroll:(t,l)=>{const a=(p.value-M.value)/l*t;b(Math.min(p.value-M.value,a))},onWheel:Y,scrollTo:b,scrollToItem:H,resetScrollTop:k};return y({windowRef:I,innerRef:D,getItemStyleCache:$,scrollTo:b,scrollToItem:H,resetScrollTop:k,states:i}),V},render(e){var d;const{$slots:y,className:Q,clientSize:W,containerElement:x,data:$,getItemStyle:I,innerElement:D,itemsToRender:F,innerStyle:i,layout:q,total:p,onScroll:O,onScrollbarScroll:U,onWheel:X,states:M,useIsScrolling:Y,windowStyle:A,ns:b}=e,[H,L]=F,k=st(x),V=st(D),t=[];if(p>0)for(let s=H;s<=L;s++)t.push((d=y.default)==null?void 0:d.call(y,{data:$,key:s,index:s,isScrolling:Y?M.isScrolling:void 0,style:I(s)}));const l=[B(V,{style:i,ref:"innerRef"},j(V)?t:{default:()=>t})],a=B(It,{ref:"scrollbarRef",clientSize:W,layout:q,onScroll:U,ratio:100*W/this.estimatedTotalSize,scrollFrom:M.scrollOffset/(this.estimatedTotalSize-W),total:p}),n=B(k,{class:[b.e("window"),Q],style:A,onScroll:O,onWheel:X,ref:"windowRef",key:0},j(k)?[l]:{default:()=>[l]});return B("div",{key:0,class:[b.e("wrapper"),M.scrollbarAlwaysOn?"always-on":""]},[n,a])}}),ut=Z({name:"ElFixedSizeList",getItemOffset:({itemSize:u},m)=>m*u,getItemSize:({itemSize:u})=>u,getEstimatedTotalSize:({total:u,itemSize:m})=>m*u,getOffset:({height:u,total:m,itemSize:S,layout:E,width:_},z,T,g)=>{const h=G(E)?_:u;j(h)&&Ot("[ElVirtualList]",`
  2. You should set
  3. width/height
  4. to number when your layout is
  5. horizontal/vertical
  6. `);const R=Math.max(0,m*S-h),e=Math.min(R,z*S),d=Math.max(0,(z+1)*S-h);switch(T===kt&&(T=g>=d-h&&g<=e+h?ct:ft),T){case Lt:return e;case $t:return d;case ft:{const y=Math.round(d+(e-d)/2);return y<Math.ceil(h/2)?0:y>R+Math.floor(h/2)?R:y}default:return g>=d&&g<=e?g:g<d?d:e}},getStartIndexForOffset:({total:u,itemSize:m},S)=>Math.max(0,Math.min(u-1,Math.floor(S/m))),getStopIndexForStartIndex:({height:u,total:m,itemSize:S,layout:E,width:_},z,T)=>{const g=z*S,h=G(E)?_:u,R=Math.ceil((h+T-g)/S);return Math.max(0,Math.min(m-1,z+R-1))},initCache(){},clearCache:!0,validateProps(){}})});export{ut as F,Dt as __tla,Z as c};