UNPKG

siegel

Version:

Web application development ecosystem

1 lines 1.42 kB
import e from"../../../../common/is/exists/index.js";import{getExpanderRow as t}from"../helpers/apply_virtualization.js";export default function(n,r,i){let l,o,a,h,{entities:{byID:s,sorted:c},pinnedEntities:f,columnsConfig:p,postProcessBodyRow:u,withFooter:d,theme:m}=n,g=f?.sorted,{searchByField:x,sortByField:I,toggledColumns:y,showPerPage:M,currentPage:S}=r,_=c;if(Object.entries(x).forEach(([t,n])=>{l||(l={},p.forEach(({ID:e},t)=>{l[e]=t}));let r=l[t];if(e(r)){let t=p[r];e(t.onFilter)&&(_=t.onFilter(_,s,n))}}),e(I.ID)){let{value:t,ID:n}=I,r=l?l[n]:p.findIndex(e=>e.ID==n),i=p[r];e(i.onSort)&&(_=i.onSort(_.slice(),s,t),g&&=i.onSort(g.slice(),f.byID,t))}let b=_.length;if(d){let e=Math.ceil(b/M)||1;S>e&&(r.currentPage=e),a=Math.min((o=(r.currentPage-1)*M)+M,b),i&&(o+=i.from,a=Math.min(a,o+(i.to-i.from)))}else i?(o=i.from,a=Math.min(i.to,b)):(o=0,a=b);g?.length>0?(h=Array.from(new Set(_=_.splice(0,o).concat(g,_))),d&&(a+=g.length)):h=_;let D=[];i&&D.push(t(!0,m.virtualization_expander_cell));let E=new Set;for(let e=o;e<a;e++){let t=_[e];if(E.has(t)){a=Math.min(_.length,a+1);continue}E.add(t);let n=s[t],r={pageIndex:e,gridIndex:e};d&&(r.pageIndex%=M);let i=[];p.forEach(e=>{y.has(e.ID)||i.push(e.showValue(n,r))});let l=[{children:i,attributes:{key:t}}];u?.(l,n,r),l.length>1?l.forEach(e=>{D.push(e)}):D.push(l[0])}return i&&D.push(t(!1,m.virtualization_expander_cell)),{from:o,to:a,resultIDs:h,body:D}};