UNPKG

siegel

Version:

Web application development ecosystem

1 lines 1.84 kB
import e from"react";import t from"../styles.sass";let n={passive:!0},i=(e,t)=>+(100/(e/t)).toFixed(1);function l(e,t,n){let{width:l,minWidth:a,maxWidth:r,paddingLeft:s,paddingRight:o,borderLeftWidth:d,borderRightWidth:m}=getComputedStyle(e),u=parseInt(l),h=parseInt(r),p=parseInt(a)+parseInt(d)+parseInt(m)+parseInt(s)+parseInt(o),v=n?{width:u,maxWidth:h,minWidth:p}:{width:i(t,u),maxWidth:i(t,h),minWidth:i(t,p)};return v.maxWidth||(v.maxWidth=1/0),v}export default function(a,r,s,o,d){let m,{columnsConfig:u,resizable:h,theme:p,postProcessHeadRow:v,postProcessHeadCell:c}=a,{toggledColumns:f}=r,x={};h&&(x="object"==typeof h?h:{enabled:!0,resizeInPixel:!1});let W=t.table_resizer;p.table_resizer&&(W+=` ${p.table_resizer}`),(c||v)&&(m={from:o,to:d,allPagesIDs:s});let E=[];u.forEach((t,a)=>{let{label:r,ID:s}=t;if(!f.has(s)){let s={value:r};if(c?.(s,t,m),x.enabled){let t=function(e){let t,a,r,s,o,d,m,u,h,p,v,{onCellResize:c,resizeInPixel:f}=e;function x(){s=m=o=u=v=h=t=r=a=null,removeEventListener("mousemove",W),removeEventListener("mouseup",x)}function W(e){let n=e.x-t;if(a&&(n=-n),c?.(e,s,u,n),!e.defaultPrevented){let e=f?n:i(r.clientWidth,n),t=m+e,l=v-e;if(h<=l&&l<=p&&o<=t&&t<=d){let e=f?"px":"%";s.style.width=t+e,u.style.width=l+e}}}return e=>{e.preventDefault(),e.stopPropagation();let i=e.currentTarget;r=(s=i.parentElement).parentElement,t=e.nativeEvent.x,a=i.nextSibling,(u=i.nextSibling?s.previousSibling:s.nextSibling)&&({width:m,minWidth:o,maxWidth:d}=l(s,r.clientWidth,f),{width:v,minWidth:h,maxWidth:p}=l(u,r.clientWidth,f),addEventListener("mousemove",W,n),addEventListener("mouseup",x,n))}}(x);s.value=e.createElement(e.Fragment,null,!a||e.createElement("div",{className:W,onMouseDown:t}),s.value,a<u.length-1&&e.createElement("div",{className:W,onMouseDown:t}))}E.push(s)}});let b=[{children:E}];return v?.(b,m),b};