flexitablesort 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useAutoScroll.d.ts +4 -0
- package/dist/hooks/useDragContextEvents.d.ts +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +341 -195
- package/package.json +1 -1
|
@@ -8,6 +8,10 @@ declare const useAutoScroll: (refs: Refs) => {
|
|
|
8
8
|
stopAutoScroll: () => void;
|
|
9
9
|
isAutoScrollingHorizontal: import('react').RefObject<boolean>;
|
|
10
10
|
isAutoScrollingVertical: import('react').RefObject<boolean>;
|
|
11
|
+
pointerRef: import('react').RefObject<{
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}>;
|
|
11
15
|
BodyScrollHandle: import('react').UIEventHandler<HTMLDivElement>;
|
|
12
16
|
HeaderScrollHandle: import('react').UIEventHandler<HTMLDivElement>;
|
|
13
17
|
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -12,4 +12,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
12
12
|
user-select: none !important;
|
|
13
13
|
-webkit-user-select: none !important;
|
|
14
14
|
}
|
|
15
|
-
`,m=(0,c.createContext)(void 0),h=()=>{let e=(0,c.useContext)(m);if(e===void 0)throw Error(`useTable must be used within a TableProvider`);return e},g=e=>{let t=(0,c.useRef)(!1),n=(0,c.useRef)(!1),r=(0,c.useRef)(0),i=(0,c.useRef)(null),a=(0,c.useCallback)((e,o,s)=>{let c=s===`vertical`,l=c?o.scrollHeight-o.clientHeight:o.scrollWidth-o.clientWidth;c?o.scrollTop+=e:o.scrollLeft+=e,c&&(o.scrollTop>=l||o.scrollTop<=0)||!c&&(o.scrollLeft>=l||o.scrollLeft<=0)?i.current!==null&&cancelAnimationFrame(i.current):n.current||t.current?(i.current=requestAnimationFrame(()=>a(e+r.current,o,s)),r.current+=e/1e3):i.current!==null&&cancelAnimationFrame(i.current)},[]);return{startAutoScroll:(0,c.useCallback)((e,i,o)=>{let s=o===`vertical`;!n.current&&!t.current&&(s?n.current=!0:t.current=!0,r.current=0,a(e,i,o))},[a]),stopAutoScroll:(0,c.useCallback)(()=>{n.current=!1,t.current=!1,i.current!==null&&cancelAnimationFrame(i.current)},[]),isAutoScrollingHorizontal:t,isAutoScrollingVertical:n,BodyScrollHandle:(0,c.useCallback)(t=>{e.headerRef?.current&&t.currentTarget&&(e.headerRef.current.scrollLeft=t.currentTarget.scrollLeft)},[e]),HeaderScrollHandle:(0,c.useCallback)(t=>{e.bodyRef?.current&&t.currentTarget&&(e.bodyRef.current.scrollLeft=t.currentTarget.scrollLeft)},[e])}},_=(e,t)=>{let n=e,r=0,i=t.length-1;for(;r<i;){let e=Math.floor((r+i)/2),a=t[e];if(a.itemTop<=n&&n<=a.itemBottom)return n<a.itemTop+a.height/2?+a.index:+a.index+1;n<a.itemTop?i=e-1:r=e+1}return+t[r].index},v=(e,t)=>{let n=e,r=0,i=t.length-1;for(;r<i;){let e=Math.floor((r+i)/2),a=t[e];if(a.itemLeft<=n&&n<=a.itemRight)return n<a.itemLeft+a.width/2?+a.index:+a.index+1;n<a.itemLeft?i=e-1:r=e+1}return+t[r].index},y=(e,t,n)=>t!==void 0&&e<t||n!==void 0&&e>n,b=`all 450ms cubic-bezier(0.2, 0, 0, 1)`,x=(e,t,n,r,i,a)=>{let{startAutoScroll:o,stopAutoScroll:s,isAutoScrollingHorizontal:l,isAutoScrollingVertical:u}=g(e),d=(0,c.useRef)(null),f=(0,c.useRef)(null),p=(0,c.useRef)(null),m=(0,c.useRef)({x:0,y:0}),h=(0,c.useRef)(null),y=(0,c.useRef)(null),x=(0,c.useRef)({width:0,height:0}),S=(0,c.useCallback)(()=>{let t=e.bodyRef.current;if(!t)return null;let n=t.scrollTop,r=t.getBoundingClientRect().top,a=t.querySelectorAll(`.draggable[data-type="row"]`),o=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.dataset.index===void 0)continue;let i=t.getBoundingClientRect(),s=i.top-r+n;o.push({height:i.height,itemTop:s,itemBottom:s+i.height,index:t.dataset.index})}let s=i.rowDragRange.start,c=i.rowDragRange.end;return(s||c)&&(o=o.filter(e=>(!s||e.index>=s)&&(!c||e.index<c))),o},[e.bodyRef,i.rowDragRange]),C=(0,c.useCallback)(()=>{let t=e.headerRef.current;if(!t||!t.children[0])return null;let n=Array.from(t.children[0].children).map(e=>{let t=e.getBoundingClientRect();return{left:t.left,width:t.width,itemLeft:t.left,itemRight:t.left+t.width,index:e.dataset.index}}).filter(e=>e.index!==void 0),r=i.columnDragRange?.start,a=i.columnDragRange?.end;return(r!==void 0||a!==void 0)&&(n=n.filter(e=>{let t=+e.index;return(r===void 0||t>=r)&&(a===void 0||t<a)})),n},[e.headerRef,i.columnDragRange]),w=(0,c.useCallback)((t,n,r,i)=>{let a=e.placeholderRef?.current;if(!a||!t){a&&(a.style.display=`none`);return}let o=x.current,s=t.getBoundingClientRect();a.style.display=`block`;let c=n<r;if(i===`row`){let e=c?s.top+s.height-o.height:s.top;a.style.top=`${e}px`,a.style.left=`${s.left}px`,a.style.width=`${s.width}px`,a.style.height=`${o.height}px`}else{let t=(e.tableRef?.current)?.getBoundingClientRect(),n=c?s.left+s.width-o.width:s.left;a.style.top=`${t?.top??s.top}px`,a.style.left=`${n}px`,a.style.width=`${o.width}px`,a.style.height=`${t?.height??s.height}px`}},[e.placeholderRef,e.tableRef]),T=(0,c.useCallback)((t,n,r)=>{if(t===null||n===null)return;let i=x.current,a=null;if(r===`row`){let r=e.bodyRef.current;if(!r)return;let o=r.querySelectorAll(`.draggable[data-type="row"]`);for(let e=0;e<o.length;e++){let r=o[e],s=+r.dataset.index,c=r.firstElementChild;if(!c)continue;let l=``;s>t&&s<=n?l=`translateY(-${i.height}px)`:s<t&&s>=n&&(l=`translateY(${i.height}px)`),c.style.transform=l,c.style.transition=s===t?`none`:b,s===n?(r.setAttribute(`data-drop-target`,`true`),a=r):r.removeAttribute(`data-drop-target`)}}else if(r===`column`){let r=e.headerRef.current;if(r){let e=r.querySelectorAll(`.draggable[data-type="column"]`);for(let r=0;r<e.length;r++){let o=e[r],s=+o.dataset.index,c=o.firstElementChild;if(!c)continue;let l=``;s>t&&s<=n?l=`translateX(-${i.width}px)`:s<t&&s>=n&&(l=`translateX(${i.width}px)`),c.style.transform=l,c.style.transition=s===t?`none`:b,s===n?(o.setAttribute(`data-drop-target`,`true`),a=o):o.removeAttribute(`data-drop-target`)}}let o=e.bodyRef.current;if(o){let e=o.querySelectorAll(`.td[data-col-index]`);for(let r=0;r<e.length;r++){let a=e[r],o=+a.dataset.colIndex,s=``;o>t&&o<=n?s=`translateX(-${i.width}px)`:o<t&&o>=n&&(s=`translateX(${i.width}px)`),a.style.transform=s,a.style.transition=b}}}w(a,t,n,r)},[e.bodyRef,e.headerRef,e.placeholderRef,w]),E=(0,c.useCallback)(()=>{let t=e.placeholderRef?.current;t&&(t.style.display=`none`);let n=e.bodyRef.current;if(n){let e=n.querySelectorAll(`.draggable`);for(let t=0;t<e.length;t++){e[t].removeAttribute(`data-drop-target`);let n=e[t].firstElementChild;n&&(n.style.transform=``,n.style.transition=``)}let t=n.querySelectorAll(`.td[data-col-index]`);for(let e=0;e<t.length;e++)t[e].style.transform=``,t[e].style.transition=``}let r=e.headerRef.current;if(r){let e=r.querySelectorAll(`.draggable`);for(let t=0;t<e.length;t++){e[t].removeAttribute(`data-drop-target`);let n=e[t].firstElementChild;n&&(n.style.transform=``,n.style.transition=``)}}},[e.bodyRef,e.headerRef]),D=(0,c.useCallback)(t=>{if(t.target!==t.currentTarget){let r=!1,i=(e=>{for(;e;){if(e.dataset?.dragHandle===`true`&&(r=!0),e.dataset?.contextid||e.dataset?.disabled===`true`)return null;if(e.dataset?.id)return e;e=e.parentNode}return null})(t.target);if(!i||!r&&i.querySelector(`[data-drag-handle]`))return;let a=i.dataset.id,o=+i.dataset.index,s=i.dataset.type;p.current=s,h.current=o,y.current=null;let c=s===`row`?e.bodyRef.current.scrollLeft:0,l=i.getBoundingClientRect();x.current={width:l.width,height:l.height};let u={x:0,y:0};t.type===`touchstart`?(u.x=t.touches[0].clientX,u.y=t.touches[0].clientY):(u.x=t.clientX-l.left-c,u.y=t.clientY-l.top),m.current=u;let g={x:l.left+c,y:l.top};s===`row`?d.current=S():d.current=C();let _=e.bodyRef.current;_&&(f.current=_.getBoundingClientRect());let v=e.cloneRef?.current;v&&(v.style.transform=`translate(${g.x}px, ${g.y}px)`),requestAnimationFrame(()=>{n({type:`dragStart`,value:{rect:{draggedItemHeight:l.height,draggedItemWidth:l.width},dragged:{initial:u,translate:g,draggedID:a,isDragging:!0,sourceIndex:o},dragType:s}}),requestAnimationFrame(()=>{let t=e.cloneRef?.current,n=e.bodyRef.current;if(t&&n){if(s===`row`)t.scrollLeft=n.scrollLeft;else if(s===`column`){let e=t.querySelector(`.clone-body`);e&&(e.scrollTop=n.scrollTop)}}})})}},[n,e,S,C]),O=(0,c.useCallback)(()=>{let t=y.current,r=h.current,i=p.current;d.current=null,f.current=null;let o=e.cloneRef?.current;o&&(o.style.transform=`translate(0px, 0px)`,o.scrollLeft=0),E(),a&&r!==null&&t!==null&&i&&a({sourceIndex:r,targetIndex:t,dragType:i}),n({type:`dragEnd`,value:{targetIndex:t,sourceIndex:r}}),s(),p.current=null,h.current=null,y.current=null},[n,s,e.cloneRef,E,a]),k=(0,c.useCallback)(()=>{d.current=null,f.current=null;let e=h.current,t=y.current,n=p.current;e!==null&&t!==null&&T(e,t,n)},[T]),A=(0,c.useCallback)(t=>{t.stopPropagation();let n=m.current,i,a;t.type===`touchmove`?(i=t.touches[0].clientX-n.x,a=t.touches[0].clientY-n.y):(i=t.clientX-n.x,a=t.clientY-n.y);let c=e.cloneRef?.current;if(c){c.style.transform=`translate(${i}px, ${a}px)`;let t=e.bodyRef.current;if(t){if(p.current===`row`)c.scrollLeft=t.scrollLeft;else if(p.current===`column`){let e=c.querySelector(`.clone-body`);e&&(e.scrollTop=t.scrollTop)}}}u.current=!1,l.current=!1;let g=e.bodyRef.current;if(!g)return;let{clientY:b,clientX:x}=t,w=f.current;w||(w=g.getBoundingClientRect(),f.current=w);let{top:E,bottom:D,left:O,right:k}=w,A=0,j=p.current||r;if(j===`row`){let e=g.scrollTop,t=w.top,n=d.current;n||(n=S(),d.current=n),n&&n.length>0&&(A=_(b-t+e,n)),b<E+30?(o(-5,g,`vertical`),d.current=null):b>D-30?(o(5,g,`vertical`),d.current=null):s()}else{let e=d.current;e||(e=C(),d.current=e),e&&e.length>0&&(A=v(x,e)),x<O+30?(o(-5,g,`horizontal`),d.current=null):x>k-30?(o(5,g,`horizontal`),d.current=null):s()}A!==y.current&&(y.current=A,requestAnimationFrame(()=>{T(h.current,A,j)}))},[r,l,u,e.bodyRef,e.cloneRef,S,C,o,s,T]),j=(0,c.useCallback)(()=>{d.current=null,f.current=null;let t=e.cloneRef?.current;t&&(t.style.transform=`translate(0px, 0px)`,t.scrollLeft=0),E(),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),p.current=null,h.current=null,y.current=null},[n,s,e.cloneRef,E]),M=(0,c.useCallback)(e=>{e.key===`Escape`&&j()},[j]);return(0,c.useEffect)(()=>{if(t.isDragging){let t=e.bodyRef.current;return window.addEventListener(`mousemove`,A,{passive:!0}),window.addEventListener(`touchmove`,A,!1),window.addEventListener(`touchend`,O,!1),window.addEventListener(`mouseup`,O,!1),window.addEventListener(`keydown`,M),t?.addEventListener(`scroll`,k,{passive:!0}),()=>{window.removeEventListener(`mousemove`,A),window.removeEventListener(`touchmove`,A,!1),window.removeEventListener(`touchend`,O,!1),window.removeEventListener(`mouseup`,O,!1),window.removeEventListener(`keydown`,M),t?.removeEventListener(`scroll`,k)}}},[t.isDragging,A,O,j,M,k,e.bodyRef]),{dragStart:D}},S={columnDragRange:{start:void 0,end:void 0},rowDragRange:{start:void 0,end:void 0},defaultSizing:50};function C(e,t){switch(t.type){case`setClone`:return{...e,clone:t.value};case`setDragged`:return{...e,dragged:{...e.dragged,...t.value}};case`setDragType`:return{...e,dragType:t.value};case`setRect`:return{...e,rect:t.value};case`setTableDimensions`:return{...e,tableDimensions:t.value};case`setTableRef`:return{...e,refs:{...e.refs,tableRef:t.value}};case`setBodyRef`:return{...e,refs:{...e.refs,bodyRef:t.value}};case`setHeaderRef`:return{...e,refs:{...e.refs,headerRef:t.value}};case`setCloneRef`:return{...e,refs:{...e.refs,cloneRef:t.value}};case`setPlaceholderRef`:return{...e,refs:{...e.refs,placeholderRef:t.value}};case`setBodyScrollBarWidth`:return{...e,bodyScrollBarWidth:t.value};case`setWidths`:return{...e,widths:t.value};case`setColumnIds`:return{...e,columnIds:t.value};case`setOptions`:return{...e,options:t.value??S};case`dragStart`:return{...e,rect:t.value.rect,dragged:{...e.dragged,...t.value.dragged},dragType:t.value.dragType};case`dragEnd`:return{...e,clone:null,dragged:{initial:{x:0,y:0},translate:{x:0,y:0},isDragging:!1,draggedID:null,targetIndex:t.value?.targetIndex??null,sourceIndex:t.value?.sourceIndex??null},dragType:null,rect:{draggedItemWidth:0,draggedItemHeight:0}};default:throw Error(`Unhandled action type: ${t.type}`)}}var w={clone:null,dragged:{initial:{x:0,y:0},translate:{x:0,y:0},isDragging:!1,draggedID:null,targetIndex:null,sourceIndex:null},dragType:null,rect:{draggedItemWidth:0,draggedItemHeight:0},tableDimensions:{height:0,width:0},refs:{tableRef:null,bodyRef:null,headerRef:null,cloneRef:null,placeholderRef:null},bodyScrollBarWidth:0,options:S,widths:[],columnIds:[]},T={position:`relative`,display:`flex`,flexFlow:`column`},E={position:`fixed`,pointerEvents:`none`,zIndex:3,top:0,left:0,display:`none`},D=(0,c.forwardRef)(({children:e,className:t,style:n,options:r,onDragEnd:i,renderPlaceholder:a},o)=>{let s=(0,c.useRef)(null),l=(0,c.useRef)(null),d=(0,c.useRef)(null);(0,c.useImperativeHandle)(o,()=>s.current,[]);let[f,h]=(0,c.useReducer)(C,w),g=(0,c.useMemo)(()=>({state:f,dispatch:h}),[f]);(0,c.useEffect)(()=>{h({type:`setTableRef`,value:s}),h({type:`setCloneRef`,value:l}),h({type:`setPlaceholderRef`,value:d})},[s]),(0,c.useEffect)(()=>{let e=()=>{s.current&&h({type:`setTableDimensions`,value:{height:s.current.offsetHeight,width:s.current.offsetWidth}})};return e(),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[s]),(0,c.useEffect)(()=>{h({type:`setOptions`,value:r})},[r]);let{dragStart:_}=x(f.refs,f.dragged,h,f.dragType,f.options,i),v=(0,c.useMemo)(()=>({position:`fixed`,zIndex:`5`,pointerEvents:`none`,top:0,left:0,display:`flex`,flexDirection:`column`,height:f.dragType===`row`?f.rect.draggedItemHeight:`${f.tableDimensions.height-20}px`,width:f.dragType===`column`?`${f.rect.draggedItemWidth}px`:`${f.tableDimensions.width-20}px`,overflow:`hidden`,boxShadow:f.dragged.isDragging?`0 0 10px 0 rgba(0, 0, 0, 0.1)`:`none`}),[f.dragType,f.dragged.isDragging,f.rect.draggedItemHeight,f.rect.draggedItemWidth,f.tableDimensions.height,f.tableDimensions.width]);return(0,u.jsx)(m.Provider,{value:g,children:(0,u.jsxs)(p,{className:f.dragged.isDragging?`is-dragging`:``,children:[(0,u.jsx)(`div`,{id:`portalroot`,style:v,ref:l,children:f.clone}),a&&(0,u.jsx)(`div`,{ref:d,style:E,children:a()}),(0,u.jsx)(`div`,{"data-contextid":`context`,ref:s,onMouseDown:_,onTouchStart:_,style:{...T,...n},className:`table ${t??``}`,children:e})]})})});D.displayName=`TableProvider`;var O=(0,c.forwardRef)(({children:e,style:t,className:n},r)=>{let i=(0,c.useRef)(null),a=r||i,{state:o,dispatch:s}=h();(0,c.useEffect)(()=>{s({type:`setHeaderRef`,value:a})},[s,a]);let{HeaderScrollHandle:l}=g(o.refs),d={display:`flex`,flex:`1 0 auto`},f=(0,c.useMemo)(()=>({overflow:`hidden`,display:`flex`,paddingRight:`${o.bodyScrollBarWidth}px`,userSelect:o.dragged.isDragging?`none`:`auto`,...t}),[o.bodyScrollBarWidth,o.dragged.isDragging,t]);return(0,c.useEffect)(()=>{a.current&&s({type:`setWidths`,value:Array.from(a.current.querySelectorAll(`.th`)).map(e=>{let t=e.getAttribute(`data-width`);return t?parseInt(t,10):null})})},[e,s,a]),(0,c.useEffect)(()=>{a.current&&s({type:`setColumnIds`,value:Array.from(a.current.querySelectorAll(`.draggable`)).map(e=>e.getAttribute(`data-id`))})},[e,s,a]),(0,u.jsx)(`div`,{className:`header ${n??``}`,children:(0,u.jsx)(`div`,{className:`thead`,style:f,"data-droppableid":`header`,onScroll:l,ref:a,children:(0,u.jsx)(`div`,{style:d,className:`tr`,children:e})})})});O.displayName=`TableHeader`;var k=(0,c.memo)(({children:e,id:t,index:n,type:r,styles:i={}})=>{let{state:a,dispatch:o}=h(),s=(0,c.useMemo)(()=>String(t)===String(a.dragged.draggedID)&&a.dragged.isDragging,[t,a.dragged.draggedID,a.dragged.isDragging]),l=(0,c.useMemo)(()=>r===`row`?y(n,a.options.rowDragRange.start,a.options.rowDragRange.end):y(n,a.options.columnDragRange.start,a.options.columnDragRange.end),[n,a.options.columnDragRange.end,a.options.columnDragRange.start,a.options.rowDragRange.end,a.options.rowDragRange.start,r]),d=(0,c.useRef)(null),f=(0,c.useRef)(!1);(0,c.useEffect)(()=>{d.current&&(f.current=!!d.current.querySelector(`[data-drag-handle]`))});let p=(0,c.useMemo)(()=>({cursor:s?`-webkit-grabbing`:l||f.current?`auto`:`-webkit-grab`,zIndex:s?2:1,opacity:s?0:1,pointerEvents:s?`none`:`auto`,display:`flex`}),[l,s]),m=t=>{l||requestAnimationFrame(()=>{o({type:`setClone`,value:c.default.cloneElement(e)})})};return(0,u.jsx)(`div`,{className:`draggable`,"data-id":t,"data-index":n,"data-type":r,onMouseDown:m,"data-disabled":l?`true`:`false`,style:i,children:(0,u.jsx)(`div`,{ref:d,style:p,children:e})})});k.displayName=`Draggable`;var A=(0,c.memo)(({children:e,width:t,style:n,className:r,...i})=>{let{state:a}=h(),o=(0,c.useMemo)(()=>t??a.options.defaultSizing,[t,a.options.defaultSizing]),s=(0,c.useMemo)(()=>({width:`${o}px`,flex:`${o} 0 auto`}),[o]);return(0,u.jsx)(k,{...i,styles:s,type:`column`,children:(0,u.jsx)(`div`,{className:`th ${r??``}`,"data-width":t,style:{width:`100%`,...n},children:e})})});A.displayName=`ColumnCell`;var j=(0,c.forwardRef)(({children:e,style:t,className:n},r)=>{let i=(0,c.useRef)(null);(0,c.useImperativeHandle)(r,()=>i.current,[]);let{state:a,dispatch:o}=h(),s=(0,c.useMemo)(()=>{if(a.dragged.sourceIndex===null)return null;let t=e=>{let n=[];return c.default.Children.forEach(e,e=>{c.default.isValidElement(e)&&(e.props.id!==void 0&&e.props.index!==void 0&&e.props.children?n.push(e):e.props.children&&n.push(...t(e.props.children)))}),n};return t(e).map(e=>{let t=c.default.Children.toArray(e.props.children).filter(e=>c.default.isValidElement(e)&&String(e.props.index)===String(a.dragged.sourceIndex)).map(e=>c.default.cloneElement(e,{isClone:!0}));return c.default.cloneElement(e,{...e.props,children:t})})},[e,a.dragged.sourceIndex]);(0,c.useEffect)(()=>{o({type:`setBodyRef`,value:i})},[o,i]);let{BodyScrollHandle:l}=g(a.refs),f=(0,c.useMemo)(()=>({overflowX:`auto`,overflowY:`auto`,flex:1,userSelect:a.dragged.isDragging?`none`:`auto`,...t}),[a.dragged.isDragging,t]);(0,c.useEffect)(()=>{if(i.current){let e=i.current.clientWidth;o({type:`setBodyScrollBarWidth`,value:i.current.offsetWidth-e})}},[o,i]);let p=i.current?.scrollHeight??0;return(0,u.jsxs)(c.default.Fragment,{children:[a.dragType===`column`&&a.refs.cloneRef?.current&&(0,d.createPortal)((0,u.jsx)(`div`,{className:`body clone-body`,"data-droppableid":`body`,style:{overflow:`hidden`,flex:1},children:(0,u.jsx)(`div`,{className:`rbody`,style:{height:p,position:`relative`},children:s})}),a.refs.cloneRef.current),(0,u.jsx)(`div`,{className:`body ${n??``}`,style:M,children:(0,u.jsx)(`div`,{className:`ibody`,style:f,"data-droppableid":`body`,onScroll:l,ref:i,children:e})})]})}),M={display:`flex`,overflow:`hidden`,flex:1};j.displayName=`TableBody`;var N={display:`flex`,flex:`1 0 auto`,minHeight:`24px`},P=(0,c.memo)(({children:e,style:t,className:n,...r})=>{let i=(0,c.useMemo)(()=>t?{...N,...t}:N,[t]),a=(0,f.default)(`tr`,n);return(0,u.jsx)(k,{...r,type:`row`,children:(0,u.jsx)(`div`,{className:a,style:i,children:e})})});P.displayName=`BodyRow`;var F=(0,c.memo)(({children:e,style:t,className:n,isClone:r,...i})=>{let{index:a}=i,{state:o}=h(),s=(0,c.useMemo)(()=>o.columnIds[a]??``,[o.columnIds,a]),l=(0,c.useMemo)(()=>o.widths[a]??o.options.defaultSizing,[o.widths,a,o.options.defaultSizing]),d=(0,c.useMemo)(()=>r?!1:s===o.dragged.draggedID,[r,s,o.dragged.draggedID]),f=(0,c.useMemo)(()=>({display:`inline-flex`,opacity:d?0:1,width:`${l}px`,flex:`${l} 0 auto`,...t}),[d,l,t]);return(0,u.jsx)(`div`,{className:`td ${n??``}`,style:f,"data-col-index":a,children:e})});F.displayName=`RowCell`;var I=(0,c.memo)(({children:e,className:t,style:n})=>(0,u.jsx)(`div`,{"data-drag-handle":`true`,className:t,style:{cursor:`-webkit-grab`,display:`inline-flex`,alignItems:`center`,...n},children:e}));I.displayName=`DragHandle`,exports.BodyRow=P,exports.ColumnCell=A,exports.DragHandle=I,exports.RowCell=F,exports.TableBody=j,exports.TableContainer=D,exports.TableHeader=O,exports.useTable=h;
|
|
15
|
+
`,m=(0,c.createContext)(void 0),h=()=>{let e=(0,c.useContext)(m);if(e===void 0)throw Error(`useTable must be used within a TableProvider`);return e},g=30,_=e=>{let t=(0,c.useRef)(!1),n=(0,c.useRef)(!1),r=(0,c.useRef)(0),i=(0,c.useRef)(null),a=(0,c.useRef)({x:0,y:0}),o=(0,c.useCallback)(()=>{n.current=!1,t.current=!1,i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),s=(0,c.useCallback)((e,o,c)=>{let l=c===`vertical`,u=l?n:t;if(!u.current)return;let d=o.getBoundingClientRect(),f=a.current;if(l){let e=f.y<d.top+g,t=f.y>d.bottom-g;if(!e&&!t){u.current=!1;return}}else{let e=f.x<d.left+g,t=f.x>d.right-g;if(!e&&!t){u.current=!1;return}}let p=l?o.scrollHeight-o.clientHeight:o.scrollWidth-o.clientWidth;l?o.scrollTop+=e:o.scrollLeft+=e;let m=l?o.scrollTop:o.scrollLeft;if(m>=p||m<=0){u.current=!1;return}r.current+=e/1e3,i.current=requestAnimationFrame(()=>s(e+r.current,o,c))},[]);return{startAutoScroll:(0,c.useCallback)((e,i,a)=>{let o=a===`vertical`?n:t;o.current||(o.current=!0,r.current=0,s(e,i,a))},[s]),stopAutoScroll:o,isAutoScrollingHorizontal:t,isAutoScrollingVertical:n,pointerRef:a,BodyScrollHandle:(0,c.useCallback)(t=>{e.headerRef?.current&&t.currentTarget&&(e.headerRef.current.scrollLeft=t.currentTarget.scrollLeft)},[e]),HeaderScrollHandle:(0,c.useCallback)(t=>{e.bodyRef?.current&&t.currentTarget&&(e.bodyRef.current.scrollLeft=t.currentTarget.scrollLeft)},[e])}},v=(e,t)=>{let n=e,r=0,i=t.length-1;for(;r<i;){let e=Math.floor((r+i)/2),a=t[e];if(a.itemTop<=n&&n<=a.itemBottom)return n<a.itemTop+a.height/2?+a.index:+a.index+1;n<a.itemTop?i=e-1:r=e+1}return+t[r].index},y=(e,t)=>{let n=e,r=0,i=t.length-1;for(;r<i;){let e=Math.floor((r+i)/2),a=t[e];if(a.itemLeft<=n&&n<=a.itemRight)return n<a.itemLeft+a.width/2?+a.index:+a.index+1;n<a.itemLeft?i=e-1:r=e+1}return+t[r].index},b=(e,t,n)=>t!==void 0&&e<t||n!==void 0&&e>n,x=`all 450ms cubic-bezier(0.2, 0, 0, 1)`,S=300,C=8,w=(e,t,n,r,i,a)=>{let{startAutoScroll:o,stopAutoScroll:s,pointerRef:l}=_(e),u=(0,c.useRef)(null),d=(0,c.useRef)(null),f=(0,c.useRef)(null),p=(0,c.useRef)({x:0,y:0}),m=(0,c.useRef)(null),h=(0,c.useRef)(null),g=(0,c.useRef)({width:0,height:0}),b=(0,c.useRef)({x:0,y:0}),w=(0,c.useRef)(null),T=(0,c.useRef)({x:0,y:0}),E=(0,c.useRef)(null),D=(0,c.useRef)(!1),O=(0,c.useRef)(null),k=(0,c.useRef)(null),A=(0,c.useRef)(null),j=(0,c.useCallback)(()=>{let t=e.bodyRef.current;if(!t)return null;let n=t.scrollTop,r=t.getBoundingClientRect().top,a=t.querySelectorAll(`.draggable[data-type="row"]`),o=[];for(let e=0;e<a.length;e++){let t=a[e];if(t.dataset.index===void 0)continue;let i=t.getBoundingClientRect(),s=i.top-r+n;o.push({height:i.height,itemTop:s,itemBottom:s+i.height,index:t.dataset.index})}let s=i.rowDragRange.start,c=i.rowDragRange.end;return(s||c)&&(o=o.filter(e=>(!s||e.index>=s)&&(!c||e.index<c))),o},[e.bodyRef,i.rowDragRange]),M=(0,c.useCallback)(()=>{let t=e.headerRef.current;if(!t||!t.children[0])return null;let n=Array.from(t.children[0].children).map(e=>{let t=e.getBoundingClientRect();return{left:t.left,width:t.width,itemLeft:t.left,itemRight:t.left+t.width,index:e.dataset.index}}).filter(e=>e.index!==void 0),r=i.columnDragRange?.start,a=i.columnDragRange?.end;return(r!==void 0||a!==void 0)&&(n=n.filter(e=>{let t=+e.index;return(r===void 0||t>=r)&&(a===void 0||t<a)})),n},[e.headerRef,i.columnDragRange]),N=(0,c.useCallback)((t,n,r,i)=>{let a=e.placeholderRef?.current;if(!a||!t){a&&(a.style.display=`none`);return}let o=g.current,s=t.getBoundingClientRect();a.style.display=`block`;let c=n<r;if(i===`row`){let t=(e.tableRef?.current)?.getBoundingClientRect(),n=c?s.top+s.height-o.height:s.top;a.style.top=`${n}px`,a.style.left=`${t?.left??s.left}px`,a.style.width=`${t?.width??s.width}px`,a.style.height=`${o.height}px`}else{let t=(e.tableRef?.current)?.getBoundingClientRect(),n=c?s.left+s.width-o.width:s.left;a.style.top=`${t?.top??s.top}px`,a.style.left=`${n}px`,a.style.width=`${o.width}px`,a.style.height=`${t?.height??s.height}px`}},[e.placeholderRef,e.tableRef]),P=(0,c.useCallback)((t,n,r)=>{if(t===null||n===null)return;let i=g.current,a=null;if(r===`row`){let r=e.bodyRef.current;if(!r)return;let o=r.querySelectorAll(`.draggable[data-type="row"]`);for(let e=0;e<o.length;e++){let r=o[e],s=+r.dataset.index,c=r.firstElementChild;if(!c)continue;let l=``;s>t&&s<=n?l=`translateY(-${i.height}px)`:s<t&&s>=n&&(l=`translateY(${i.height}px)`),c.style.transform=l,c.style.transition=s===t?`none`:x,s===n?(r.setAttribute(`data-drop-target`,`true`),a=r):r.removeAttribute(`data-drop-target`)}}else if(r===`column`){let r=e.headerRef.current;if(r){let e=r.querySelectorAll(`.draggable[data-type="column"]`);for(let r=0;r<e.length;r++){let o=e[r],s=+o.dataset.index,c=o.firstElementChild;if(!c)continue;let l=``;s>t&&s<=n?l=`translateX(-${i.width}px)`:s<t&&s>=n&&(l=`translateX(${i.width}px)`),c.style.transform=l,c.style.transition=s===t?`none`:x,s===n?(o.setAttribute(`data-drop-target`,`true`),a=o):o.removeAttribute(`data-drop-target`)}}let o=e.bodyRef.current;if(o){let e=o.querySelectorAll(`.td[data-col-index]`);for(let r=0;r<e.length;r++){let a=e[r],o=+a.dataset.colIndex,s=``;o>t&&o<=n?s=`translateX(-${i.width}px)`:o<t&&o>=n&&(s=`translateX(${i.width}px)`),a.style.transform=s,a.style.transition=x}}}N(a,t,n,r)},[e.bodyRef,e.headerRef,N]),F=(0,c.useCallback)(()=>{let t=e.placeholderRef?.current;t&&(t.style.display=`none`);let n=e.bodyRef.current;if(n){let e=n.querySelectorAll(`.draggable`);for(let t=0;t<e.length;t++){e[t].removeAttribute(`data-drop-target`);let n=e[t].firstElementChild;n&&(n.style.transform=``,n.style.transition=``)}let t=n.querySelectorAll(`.td[data-col-index]`);for(let e=0;e<t.length;e++)t[e].style.transform=``,t[e].style.transition=``}let r=e.headerRef.current;if(r){let e=r.querySelectorAll(`.draggable`);for(let t=0;t<e.length;t++){e[t].removeAttribute(`data-drop-target`);let n=e[t].firstElementChild;n&&(n.style.transform=``,n.style.transition=``)}}},[e.bodyRef,e.headerRef]),I=(0,c.useCallback)((t,r,i)=>{let a=!1,o=(e=>{for(;e;){if(e.dataset?.dragHandle===`true`&&(a=!0),e.dataset?.contextid||e.dataset?.disabled===`true`)return null;if(e.dataset?.id)return e;e=e.parentNode}return null})(t.target);if(!o||!a&&o.querySelector(`[data-drag-handle]`))return;let s=o.dataset.id,c=+o.dataset.index,_=o.dataset.type,v=t.type===`touchstart`;f.current=_,m.current=c,h.current=null,v&&o.dispatchEvent(new PointerEvent(`pointerdown`,{bubbles:!0,pointerType:`mouse`}));let y=_===`row`?e.bodyRef.current.scrollLeft:0,x=o.getBoundingClientRect();g.current={width:x.width,height:x.height};let S={x:r-x.left-y,y:i-x.top};p.current=S,b.current={x:r,y:i},l.current={x:r,y:i};let C={x:x.left+y,y:x.top};_===`row`?u.current=j():u.current=M();let w=e.bodyRef.current;w&&(d.current=w.getBoundingClientRect());let T=e.cloneRef?.current;T&&(T.style.transform=`translate(${C.x}px, ${C.y}px)`);let E=e.tableRef?.current;E&&(E.style.touchAction=`none`),n({type:`dragStart`,value:{rect:{draggedItemHeight:x.height,draggedItemWidth:x.width},dragged:{initial:S,translate:C,draggedID:s,isDragging:!0,sourceIndex:c},dragType:_}});let D=()=>{let t=e.cloneRef?.current,n=e.bodyRef.current;if(t&&n){if(_===`row`)t.scrollLeft=n.scrollLeft;else if(_===`column`){let e=t.querySelector(`.clone-body`);e&&(e.scrollTop=n.scrollTop)}}};D(),requestAnimationFrame(()=>{D(),requestAnimationFrame(D)})},[e.bodyRef,e.cloneRef,e.tableRef,l,n,j,M]),L=(0,c.useCallback)(e=>{e.target!==e.currentTarget&&(D.current||I(e,e.clientX,e.clientY))},[I]),R=(0,c.useCallback)(()=>{w.current&&=(clearTimeout(w.current),null),E.current=null,window.removeEventListener(`touchmove`,O.current),window.removeEventListener(`touchend`,k.current)},[]),z=(0,c.useCallback)(e=>{if(e.target===e.currentTarget)return;R(),D.current=!0;let t=e.touches[0];T.current={x:t.clientX,y:t.clientY},E.current=e;let n=e=>{let t=e.touches[0],n=t.clientX-T.current.x,r=t.clientY-T.current.y;(Math.abs(n)>C||Math.abs(r)>C)&&(R(),setTimeout(()=>{D.current=!1},400))},r=()=>{R(),setTimeout(()=>{D.current=!1},400)};O.current=n,k.current=r,window.addEventListener(`touchmove`,n,{passive:!0}),window.addEventListener(`touchend`,r,!1),w.current=setTimeout(()=>{w.current=null,window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r);let e=E.current;E.current=null,e&&I(e,t.clientX,t.clientY)},S)},[I,R]),B=(0,c.useCallback)(e=>{A.current=e.pointerId??null},[]),V=(0,c.useCallback)(()=>{R(),setTimeout(()=>{D.current=!1},400);let t=h.current,r=m.current,i=f.current;u.current=null,d.current=null;let o=e.cloneRef?.current;o&&(o.style.transform=`translate(0px, 0px)`,o.scrollLeft=0);let c=e.tableRef?.current;c&&(c.style.touchAction=``),F(),a&&r!==null&&t!==null&&i&&a({sourceIndex:r,targetIndex:t,dragType:i}),n({type:`dragEnd`,value:{targetIndex:t,sourceIndex:r}}),s(),f.current=null,m.current=null,h.current=null},[n,s,e.cloneRef,e.tableRef,F,R,a]),H=(0,c.useCallback)(()=>{u.current=null,d.current=null;let t=m.current,n=h.current,r=f.current;t!==null&&n!==null&&P(t,n,r);let i=e.cloneRef?.current,a=e.bodyRef?.current;if(i&&a){if(r===`row`)i.scrollLeft=a.scrollLeft;else if(r===`column`){let e=i.querySelector(`.clone-body`);e&&(e.scrollTop=a.scrollTop)}}let o=e.bodyRef?.current;if(o&&r){let e=b.current,n=d.current;n||(n=o.getBoundingClientRect(),d.current=n);let i=0;if(r===`row`){let t=u.current;t||(t=j(),u.current=t),t&&t.length>0&&(i=v(e.y-n.top+o.scrollTop,t))}else{let t=u.current;t||(t=M(),u.current=t),t&&t.length>0&&(i=y(e.x,t))}i!==h.current&&(h.current=i,P(t,i,r))}},[P,e.cloneRef,e.bodyRef,j,M]),U=(0,c.useCallback)(t=>{let n=t.clientX??0,i=t.clientY??0,a=p.current,c=n-a.x,g=i-a.y;b.current={x:n,y:i},l.current={x:n,y:i};let _=e.cloneRef?.current;if(_){_.style.transform=`translate(${c}px, ${g}px)`;let t=e.bodyRef.current;if(t){if(f.current===`row`)_.scrollLeft=t.scrollLeft;else if(f.current===`column`){let e=_.querySelector(`.clone-body`);e&&(e.scrollTop=t.scrollTop)}}}let x=e.bodyRef.current;if(!x)return;let S=d.current;S||(S=x.getBoundingClientRect(),d.current=S);let{top:C,bottom:w,left:T,right:E}=S,D=0,O=f.current||r;if(O===`row`){let e=x.scrollTop,t=S.top,n=u.current;n||(n=j(),u.current=n),n&&n.length>0&&(D=v(i-t+e,n)),i<C+30?(o(-5,x,`vertical`),u.current=null):i>w-30?(o(5,x,`vertical`),u.current=null):s()}else{let e=u.current;e||(e=M(),u.current=e),e&&e.length>0&&(D=y(n,e)),n<T+30?(o(-5,x,`horizontal`),u.current=null):n>E-30?(o(5,x,`horizontal`),u.current=null):s()}D!==h.current&&(h.current=D,requestAnimationFrame(()=>{P(m.current,D,O)}))},[l,e.cloneRef,e.bodyRef,r,j,o,s,M,P]),W=(0,c.useCallback)(()=>{R(),u.current=null,d.current=null;let t=e.cloneRef?.current;t&&(t.style.transform=`translate(0px, 0px)`,t.scrollLeft=0);let r=e.tableRef?.current;r&&(r.style.touchAction=``),F(),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),f.current=null,m.current=null,h.current=null},[n,s,e.cloneRef,e.tableRef,F,R]),G=(0,c.useCallback)(e=>{e.key===`Escape`&&W()},[W]);return(0,c.useEffect)(()=>{if(t.isDragging){let t=e.bodyRef.current,n=e.tableRef?.current;if(n&&A.current!==null)try{n.setPointerCapture(A.current)}catch{}let r=e=>{e.pointerType===`touch`&&e.preventDefault(),U(e)},i=()=>V(),a=()=>V();return n&&(n.addEventListener(`pointermove`,r,{passive:!1}),n.addEventListener(`pointerup`,i),n.addEventListener(`pointercancel`,a)),window.addEventListener(`mouseup`,V,!1),window.addEventListener(`keydown`,G),t?.addEventListener(`scroll`,H,{passive:!0}),()=>{if(n){if(n.removeEventListener(`pointermove`,r),n.removeEventListener(`pointerup`,i),n.removeEventListener(`pointercancel`,a),A.current!==null){try{n.releasePointerCapture(A.current)}catch{}A.current=null}n.style.touchAction=``}window.removeEventListener(`mouseup`,V,!1),window.removeEventListener(`keydown`,G),t?.removeEventListener(`scroll`,H)}}},[t.isDragging,U,V,W,G,H,e.bodyRef,e.tableRef]),{dragStart:L,touchStart:z,onPointerDown:B}},T={columnDragRange:{start:void 0,end:void 0},rowDragRange:{start:void 0,end:void 0},defaultSizing:50};function E(e,t){switch(t.type){case`setClone`:return{...e,clone:t.value};case`setDragged`:return{...e,dragged:{...e.dragged,...t.value}};case`setDragType`:return{...e,dragType:t.value};case`setRect`:return{...e,rect:t.value};case`setTableDimensions`:return{...e,tableDimensions:t.value};case`setTableRef`:return{...e,refs:{...e.refs,tableRef:t.value}};case`setBodyRef`:return{...e,refs:{...e.refs,bodyRef:t.value}};case`setHeaderRef`:return{...e,refs:{...e.refs,headerRef:t.value}};case`setCloneRef`:return{...e,refs:{...e.refs,cloneRef:t.value}};case`setPlaceholderRef`:return{...e,refs:{...e.refs,placeholderRef:t.value}};case`setBodyScrollBarWidth`:return{...e,bodyScrollBarWidth:t.value};case`setWidths`:return{...e,widths:t.value};case`setColumnIds`:return{...e,columnIds:t.value};case`setOptions`:return{...e,options:t.value??T};case`dragStart`:return{...e,rect:t.value.rect,dragged:{...e.dragged,...t.value.dragged},dragType:t.value.dragType};case`dragEnd`:return{...e,clone:null,dragged:{initial:{x:0,y:0},translate:{x:0,y:0},isDragging:!1,draggedID:null,targetIndex:t.value?.targetIndex??null,sourceIndex:t.value?.sourceIndex??null},dragType:null,rect:{draggedItemWidth:0,draggedItemHeight:0}};default:throw Error(`Unhandled action type: ${t.type}`)}}var D={clone:null,dragged:{initial:{x:0,y:0},translate:{x:0,y:0},isDragging:!1,draggedID:null,targetIndex:null,sourceIndex:null},dragType:null,rect:{draggedItemWidth:0,draggedItemHeight:0},tableDimensions:{height:0,width:0},refs:{tableRef:null,bodyRef:null,headerRef:null,cloneRef:null,placeholderRef:null},bodyScrollBarWidth:0,options:T,widths:[],columnIds:[]},O={position:`relative`,display:`flex`,flexFlow:`column`},k={position:`fixed`,pointerEvents:`none`,zIndex:3,top:0,left:0,display:`none`},A=(0,c.forwardRef)(({children:e,className:t,style:n,options:r,onDragEnd:i,renderPlaceholder:a},o)=>{let s=(0,c.useRef)(null),l=(0,c.useRef)(null),d=(0,c.useRef)(null);(0,c.useImperativeHandle)(o,()=>s.current,[]);let[f,h]=(0,c.useReducer)(E,D),g=(0,c.useMemo)(()=>({state:f,dispatch:h}),[f]);(0,c.useEffect)(()=>{h({type:`setTableRef`,value:s}),h({type:`setCloneRef`,value:l}),h({type:`setPlaceholderRef`,value:d})},[s]),(0,c.useEffect)(()=>{let e=()=>{s.current&&h({type:`setTableDimensions`,value:{height:s.current.offsetHeight,width:s.current.offsetWidth}})};return e(),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[s]),(0,c.useEffect)(()=>{h({type:`setOptions`,value:r})},[r]);let{dragStart:_,touchStart:v,onPointerDown:y}=w(f.refs,f.dragged,h,f.dragType,f.options,i),b=(0,c.useMemo)(()=>({position:`fixed`,zIndex:`5`,pointerEvents:`none`,top:0,left:0,display:`flex`,flexDirection:`column`,height:f.dragType===`row`?f.rect.draggedItemHeight:`${f.tableDimensions.height-20}px`,width:f.dragType===`column`?`${f.rect.draggedItemWidth}px`:`${f.tableDimensions.width-20}px`,overflow:`hidden`,boxShadow:f.dragged.isDragging?`0 0 10px 0 rgba(0, 0, 0, 0.1)`:`none`}),[f.dragType,f.dragged.isDragging,f.rect.draggedItemHeight,f.rect.draggedItemWidth,f.tableDimensions.height,f.tableDimensions.width]);return(0,u.jsx)(m.Provider,{value:g,children:(0,u.jsxs)(p,{className:f.dragged.isDragging?`is-dragging`:``,children:[(0,u.jsx)(`div`,{id:`portalroot`,style:{...b,visibility:f.dragged.isDragging?`visible`:`hidden`},ref:l,children:(0,u.jsx)(`div`,{style:{flexShrink:0,order:-1},children:f.clone})}),a&&(0,u.jsx)(`div`,{ref:d,style:k,children:a()}),(0,u.jsx)(`div`,{"data-contextid":`context`,ref:s,onMouseDown:_,onTouchStart:v,onPointerDown:y,style:{...O,...n},className:`table ${t??``}`,children:e})]})})});A.displayName=`TableProvider`;var j=(0,c.forwardRef)(({children:e,style:t,className:n},r)=>{let i=(0,c.useRef)(null),a=r||i,{state:o,dispatch:s}=h();(0,c.useEffect)(()=>{s({type:`setHeaderRef`,value:a})},[s,a]);let{HeaderScrollHandle:l}=_(o.refs),d={display:`flex`,flex:`1 0 auto`},f=(0,c.useMemo)(()=>({overflow:`hidden`,display:`flex`,paddingRight:`${o.bodyScrollBarWidth}px`,userSelect:o.dragged.isDragging?`none`:`auto`,...t}),[o.bodyScrollBarWidth,o.dragged.isDragging,t]);return(0,c.useEffect)(()=>{a.current&&s({type:`setWidths`,value:Array.from(a.current.querySelectorAll(`.th`)).map(e=>{let t=e.getAttribute(`data-width`);return t?parseInt(t,10):null})})},[e,s,a]),(0,c.useEffect)(()=>{a.current&&s({type:`setColumnIds`,value:Array.from(a.current.querySelectorAll(`.draggable`)).map(e=>e.getAttribute(`data-id`))})},[e,s,a]),(0,u.jsx)(`div`,{className:`header ${n??``}`,children:(0,u.jsx)(`div`,{className:`thead`,style:f,"data-droppableid":`header`,onScroll:l,ref:a,children:(0,u.jsx)(`div`,{style:d,className:`tr`,children:e})})})});j.displayName=`TableHeader`;var M=(0,c.memo)(({children:e,id:t,index:n,type:r,styles:i={}})=>{let{state:a,dispatch:o}=h(),s=(0,c.useMemo)(()=>String(t)===String(a.dragged.draggedID)&&a.dragged.isDragging,[t,a.dragged.draggedID,a.dragged.isDragging]),l=(0,c.useMemo)(()=>r===`row`?b(n,a.options.rowDragRange.start,a.options.rowDragRange.end):b(n,a.options.columnDragRange.start,a.options.columnDragRange.end),[n,a.options.columnDragRange.end,a.options.columnDragRange.start,a.options.rowDragRange.end,a.options.rowDragRange.start,r]),d=(0,c.useRef)(null),f=(0,c.useRef)(!1);(0,c.useEffect)(()=>{d.current&&(f.current=!!d.current.querySelector(`[data-drag-handle]`))});let p=(0,c.useMemo)(()=>({cursor:s?`-webkit-grabbing`:l||f.current?`auto`:`-webkit-grab`,zIndex:s?2:1,opacity:s?0:1,pointerEvents:s?`none`:`auto`,display:`flex`}),[l,s]),m=t=>{t.pointerType!==`touch`&&(l||requestAnimationFrame(()=>{o({type:`setClone`,value:c.default.cloneElement(e)})}))};return(0,u.jsx)(`div`,{className:`draggable`,"data-id":t,"data-index":n,"data-type":r,onPointerDown:m,"data-disabled":l?`true`:`false`,style:i,children:(0,u.jsx)(`div`,{ref:d,style:p,children:e})})});M.displayName=`Draggable`;var N=(0,c.memo)(({children:e,width:t,style:n,className:r,...i})=>{let{state:a}=h(),o=(0,c.useMemo)(()=>t??a.options.defaultSizing,[t,a.options.defaultSizing]),s=(0,c.useMemo)(()=>({width:`${o}px`,flex:`${o} 0 auto`}),[o]);return(0,u.jsx)(M,{...i,styles:s,type:`column`,children:(0,u.jsx)(`div`,{className:`th ${r??``}`,"data-width":t,style:{width:`100%`,...n},children:e})})});N.displayName=`ColumnCell`;var P=(0,c.forwardRef)(({children:e,style:t,className:n},r)=>{let i=(0,c.useRef)(null);(0,c.useImperativeHandle)(r,()=>i.current,[]);let{state:a,dispatch:o}=h(),s=(0,c.useMemo)(()=>{if(a.dragged.sourceIndex===null)return null;let t=e=>{let n=[];return c.default.Children.forEach(e,e=>{c.default.isValidElement(e)&&(e.props.id!==void 0&&e.props.index!==void 0&&e.props.children?n.push(e):e.props.children&&n.push(...t(e.props.children)))}),n};return t(e).map(e=>{let t=c.default.Children.toArray(e.props.children).filter(e=>c.default.isValidElement(e)&&String(e.props.index)===String(a.dragged.sourceIndex)).map(e=>c.default.cloneElement(e,{isClone:!0}));return c.default.cloneElement(e,{...e.props,children:t})})},[e,a.dragged.sourceIndex]);(0,c.useEffect)(()=>{o({type:`setBodyRef`,value:i})},[o,i]);let{BodyScrollHandle:l}=_(a.refs),f=(0,c.useMemo)(()=>({overflowX:`auto`,overflowY:`auto`,flex:1,userSelect:a.dragged.isDragging?`none`:`auto`,...t}),[a.dragged.isDragging,t]);(0,c.useEffect)(()=>{if(i.current){let e=i.current.clientWidth;o({type:`setBodyScrollBarWidth`,value:i.current.offsetWidth-e})}},[o,i]);let p=i.current?.scrollHeight??0;return(0,u.jsxs)(c.default.Fragment,{children:[a.dragType===`column`&&a.refs.cloneRef?.current&&(0,d.createPortal)((0,u.jsx)(`div`,{className:`body clone-body`,"data-droppableid":`body`,style:{overflow:`hidden`,flex:1},children:(0,u.jsx)(`div`,{className:`rbody`,style:{height:p,position:`relative`},children:s})}),a.refs.cloneRef.current),(0,u.jsx)(`div`,{className:`body ${n??``}`,style:F,children:(0,u.jsx)(`div`,{className:`ibody`,style:f,"data-droppableid":`body`,onScroll:l,ref:i,children:e})})]})}),F={display:`flex`,overflow:`hidden`,flex:1};P.displayName=`TableBody`;var I={display:`flex`,flex:`1 0 auto`,minHeight:`24px`},L=(0,c.memo)(({children:e,style:t,className:n,...r})=>{let i=(0,c.useMemo)(()=>t?{...I,...t}:I,[t]),a=(0,f.default)(`tr`,n);return(0,u.jsx)(M,{...r,type:`row`,children:(0,u.jsx)(`div`,{className:a,style:i,children:e})})});L.displayName=`BodyRow`;var R=(0,c.memo)(({children:e,style:t,className:n,isClone:r,...i})=>{let{index:a}=i,{state:o}=h(),s=(0,c.useMemo)(()=>o.columnIds[a]??``,[o.columnIds,a]),l=(0,c.useMemo)(()=>o.widths[a]??o.options.defaultSizing,[o.widths,a,o.options.defaultSizing]),d=(0,c.useMemo)(()=>r?!1:s===o.dragged.draggedID,[r,s,o.dragged.draggedID]),f=(0,c.useMemo)(()=>({display:`inline-flex`,opacity:d?0:1,width:`${l}px`,flex:`${l} 0 auto`,...t}),[d,l,t]);return(0,u.jsx)(`div`,{className:`td ${n??``}`,style:f,"data-col-index":a,children:e})});R.displayName=`RowCell`;var z=(0,c.memo)(({children:e,className:t,style:n})=>(0,u.jsx)(`div`,{"data-drag-handle":`true`,className:t,style:{cursor:`-webkit-grab`,display:`inline-flex`,alignItems:`center`,...n},children:e}));z.displayName=`DragHandle`,exports.BodyRow=L,exports.ColumnCell=N,exports.DragHandle=z,exports.RowCell=R,exports.TableBody=P,exports.TableContainer=A,exports.TableHeader=j,exports.useTable=h;
|
package/dist/index.es.js
CHANGED
|
@@ -22,21 +22,47 @@ var g = d.div`
|
|
|
22
22
|
let e = a(_);
|
|
23
23
|
if (e === void 0) throw Error("useTable must be used within a TableProvider");
|
|
24
24
|
return e;
|
|
25
|
-
}, y = (e) => {
|
|
26
|
-
let t = u(!1), n = u(!1), r = u(0), a = u(null), o =
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
}, y = 30, b = (e) => {
|
|
26
|
+
let t = u(!1), n = u(!1), r = u(0), a = u(null), o = u({
|
|
27
|
+
x: 0,
|
|
28
|
+
y: 0
|
|
29
|
+
}), s = i(() => {
|
|
30
|
+
n.current = !1, t.current = !1, a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
|
|
31
|
+
}, []), c = i((e, i, s) => {
|
|
32
|
+
let l = s === "vertical", u = l ? n : t;
|
|
33
|
+
if (!u.current) return;
|
|
34
|
+
let d = i.getBoundingClientRect(), f = o.current;
|
|
35
|
+
if (l) {
|
|
36
|
+
let e = f.y < d.top + y, t = f.y > d.bottom - y;
|
|
37
|
+
if (!e && !t) {
|
|
38
|
+
u.current = !1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
let e = f.x < d.left + y, t = f.x > d.right - y;
|
|
43
|
+
if (!e && !t) {
|
|
44
|
+
u.current = !1;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let p = l ? i.scrollHeight - i.clientHeight : i.scrollWidth - i.clientWidth;
|
|
49
|
+
l ? i.scrollTop += e : i.scrollLeft += e;
|
|
50
|
+
let m = l ? i.scrollTop : i.scrollLeft;
|
|
51
|
+
if (m >= p || m <= 0) {
|
|
52
|
+
u.current = !1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
r.current += e / 1e3, a.current = requestAnimationFrame(() => c(e + r.current, i, s));
|
|
29
56
|
}, []);
|
|
30
57
|
return {
|
|
31
58
|
startAutoScroll: i((e, i, a) => {
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
}, [
|
|
35
|
-
stopAutoScroll:
|
|
36
|
-
n.current = !1, t.current = !1, a.current !== null && cancelAnimationFrame(a.current);
|
|
37
|
-
}, []),
|
|
59
|
+
let o = a === "vertical" ? n : t;
|
|
60
|
+
o.current || (o.current = !0, r.current = 0, c(e, i, a));
|
|
61
|
+
}, [c]),
|
|
62
|
+
stopAutoScroll: s,
|
|
38
63
|
isAutoScrollingHorizontal: t,
|
|
39
64
|
isAutoScrollingVertical: n,
|
|
65
|
+
pointerRef: o,
|
|
40
66
|
BodyScrollHandle: i((t) => {
|
|
41
67
|
e.headerRef?.current && t.currentTarget && (e.headerRef.current.scrollLeft = t.currentTarget.scrollLeft);
|
|
42
68
|
}, [e]),
|
|
@@ -44,7 +70,7 @@ var g = d.div`
|
|
|
44
70
|
e.bodyRef?.current && t.currentTarget && (e.bodyRef.current.scrollLeft = t.currentTarget.scrollLeft);
|
|
45
71
|
}, [e])
|
|
46
72
|
};
|
|
47
|
-
},
|
|
73
|
+
}, x = (e, t) => {
|
|
48
74
|
let n = e, r = 0, i = t.length - 1;
|
|
49
75
|
for (; r < i;) {
|
|
50
76
|
let e = Math.floor((r + i) / 2), a = t[e];
|
|
@@ -52,7 +78,7 @@ var g = d.div`
|
|
|
52
78
|
n < a.itemTop ? i = e - 1 : r = e + 1;
|
|
53
79
|
}
|
|
54
80
|
return +t[r].index;
|
|
55
|
-
},
|
|
81
|
+
}, S = (e, t) => {
|
|
56
82
|
let n = e, r = 0, i = t.length - 1;
|
|
57
83
|
for (; r < i;) {
|
|
58
84
|
let e = Math.floor((r + i) / 2), a = t[e];
|
|
@@ -60,14 +86,20 @@ var g = d.div`
|
|
|
60
86
|
n < a.itemLeft ? i = e - 1 : r = e + 1;
|
|
61
87
|
}
|
|
62
88
|
return +t[r].index;
|
|
63
|
-
},
|
|
64
|
-
let { startAutoScroll: c, stopAutoScroll: l,
|
|
89
|
+
}, C = (e, t, n) => t !== void 0 && e < t || n !== void 0 && e > n, w = "all 450ms cubic-bezier(0.2, 0, 0, 1)", T = 300, E = 8, D = (e, t, n, r, a, s) => {
|
|
90
|
+
let { startAutoScroll: c, stopAutoScroll: l, pointerRef: d } = b(e), f = u(null), p = u(null), m = u(null), h = u({
|
|
65
91
|
x: 0,
|
|
66
92
|
y: 0
|
|
67
|
-
}),
|
|
93
|
+
}), g = u(null), _ = u(null), v = u({
|
|
68
94
|
width: 0,
|
|
69
95
|
height: 0
|
|
70
|
-
}),
|
|
96
|
+
}), y = u({
|
|
97
|
+
x: 0,
|
|
98
|
+
y: 0
|
|
99
|
+
}), C = u(null), D = u({
|
|
100
|
+
x: 0,
|
|
101
|
+
y: 0
|
|
102
|
+
}), O = u(null), k = u(!1), A = u(null), j = u(null), M = u(null), N = i(() => {
|
|
71
103
|
let t = e.bodyRef.current;
|
|
72
104
|
if (!t) return null;
|
|
73
105
|
let n = t.scrollTop, r = t.getBoundingClientRect().top, i = t.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
|
|
@@ -84,7 +116,7 @@ var g = d.div`
|
|
|
84
116
|
}
|
|
85
117
|
let s = a.rowDragRange.start, c = a.rowDragRange.end;
|
|
86
118
|
return (s || c) && (o = o.filter((e) => (!s || e.index >= s) && (!c || e.index < c))), o;
|
|
87
|
-
}, [e.bodyRef, a.rowDragRange]),
|
|
119
|
+
}, [e.bodyRef, a.rowDragRange]), P = i(() => {
|
|
88
120
|
let t = e.headerRef.current;
|
|
89
121
|
if (!t || !t.children[0]) return null;
|
|
90
122
|
let n = Array.from(t.children[0].children).map((e) => {
|
|
@@ -101,25 +133,25 @@ var g = d.div`
|
|
|
101
133
|
let t = +e.index;
|
|
102
134
|
return (r === void 0 || t >= r) && (i === void 0 || t < i);
|
|
103
135
|
})), n;
|
|
104
|
-
}, [e.headerRef, a.columnDragRange]),
|
|
136
|
+
}, [e.headerRef, a.columnDragRange]), F = i((t, n, r, i) => {
|
|
105
137
|
let a = e.placeholderRef?.current;
|
|
106
138
|
if (!a || !t) {
|
|
107
139
|
a && (a.style.display = "none");
|
|
108
140
|
return;
|
|
109
141
|
}
|
|
110
|
-
let o =
|
|
142
|
+
let o = v.current, s = t.getBoundingClientRect();
|
|
111
143
|
a.style.display = "block";
|
|
112
144
|
let c = n < r;
|
|
113
145
|
if (i === "row") {
|
|
114
|
-
let e = c ? s.top + s.height - o.height : s.top;
|
|
115
|
-
a.style.top = `${
|
|
146
|
+
let t = (e.tableRef?.current)?.getBoundingClientRect(), n = c ? s.top + s.height - o.height : s.top;
|
|
147
|
+
a.style.top = `${n}px`, a.style.left = `${t?.left ?? s.left}px`, a.style.width = `${t?.width ?? s.width}px`, a.style.height = `${o.height}px`;
|
|
116
148
|
} else {
|
|
117
149
|
let t = (e.tableRef?.current)?.getBoundingClientRect(), n = c ? s.left + s.width - o.width : s.left;
|
|
118
150
|
a.style.top = `${t?.top ?? s.top}px`, a.style.left = `${n}px`, a.style.width = `${o.width}px`, a.style.height = `${t?.height ?? s.height}px`;
|
|
119
151
|
}
|
|
120
|
-
}, [e.placeholderRef, e.tableRef]),
|
|
152
|
+
}, [e.placeholderRef, e.tableRef]), I = i((t, n, r) => {
|
|
121
153
|
if (t === null || n === null) return;
|
|
122
|
-
let i =
|
|
154
|
+
let i = v.current, a = null;
|
|
123
155
|
if (r === "row") {
|
|
124
156
|
let r = e.bodyRef.current;
|
|
125
157
|
if (!r) return;
|
|
@@ -128,7 +160,7 @@ var g = d.div`
|
|
|
128
160
|
let r = o[e], s = +r.dataset.index, c = r.firstElementChild;
|
|
129
161
|
if (!c) continue;
|
|
130
162
|
let l = "";
|
|
131
|
-
s > t && s <= n ? l = `translateY(-${i.height}px)` : s < t && s >= n && (l = `translateY(${i.height}px)`), c.style.transform = l, c.style.transition = s === t ? "none" :
|
|
163
|
+
s > t && s <= n ? l = `translateY(-${i.height}px)` : s < t && s >= n && (l = `translateY(${i.height}px)`), c.style.transform = l, c.style.transition = s === t ? "none" : w, s === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
|
|
132
164
|
}
|
|
133
165
|
} else if (r === "column") {
|
|
134
166
|
let r = e.headerRef.current;
|
|
@@ -138,7 +170,7 @@ var g = d.div`
|
|
|
138
170
|
let o = e[r], s = +o.dataset.index, c = o.firstElementChild;
|
|
139
171
|
if (!c) continue;
|
|
140
172
|
let l = "";
|
|
141
|
-
s > t && s <= n ? l = `translateX(-${i.width}px)` : s < t && s >= n && (l = `translateX(${i.width}px)`), c.style.transform = l, c.style.transition = s === t ? "none" :
|
|
173
|
+
s > t && s <= n ? l = `translateX(-${i.width}px)` : s < t && s >= n && (l = `translateX(${i.width}px)`), c.style.transform = l, c.style.transition = s === t ? "none" : w, s === n ? (o.setAttribute("data-drop-target", "true"), a = o) : o.removeAttribute("data-drop-target");
|
|
142
174
|
}
|
|
143
175
|
}
|
|
144
176
|
let o = e.bodyRef.current;
|
|
@@ -146,17 +178,16 @@ var g = d.div`
|
|
|
146
178
|
let e = o.querySelectorAll(".td[data-col-index]");
|
|
147
179
|
for (let r = 0; r < e.length; r++) {
|
|
148
180
|
let a = e[r], o = +a.dataset.colIndex, s = "";
|
|
149
|
-
o > t && o <= n ? s = `translateX(-${i.width}px)` : o < t && o >= n && (s = `translateX(${i.width}px)`), a.style.transform = s, a.style.transition =
|
|
181
|
+
o > t && o <= n ? s = `translateX(-${i.width}px)` : o < t && o >= n && (s = `translateX(${i.width}px)`), a.style.transform = s, a.style.transition = w;
|
|
150
182
|
}
|
|
151
183
|
}
|
|
152
184
|
}
|
|
153
|
-
|
|
185
|
+
F(a, t, n, r);
|
|
154
186
|
}, [
|
|
155
187
|
e.bodyRef,
|
|
156
188
|
e.headerRef,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
]), O = i(() => {
|
|
189
|
+
F
|
|
190
|
+
]), L = i(() => {
|
|
160
191
|
let t = e.placeholderRef?.current;
|
|
161
192
|
t && (t.style.display = "none");
|
|
162
193
|
let n = e.bodyRef.current;
|
|
@@ -179,76 +210,124 @@ var g = d.div`
|
|
|
179
210
|
n && (n.style.transform = "", n.style.transition = "");
|
|
180
211
|
}
|
|
181
212
|
}
|
|
182
|
-
}, [e.bodyRef, e.headerRef]),
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
}, [e.bodyRef, e.headerRef]), R = i((t, r, i) => {
|
|
214
|
+
let a = !1, o = ((e) => {
|
|
215
|
+
for (; e;) {
|
|
216
|
+
if (e.dataset?.dragHandle === "true" && (a = !0), e.dataset?.contextid || e.dataset?.disabled === "true") return null;
|
|
217
|
+
if (e.dataset?.id) return e;
|
|
218
|
+
e = e.parentNode;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
})(t.target);
|
|
222
|
+
if (!o || !a && o.querySelector("[data-drag-handle]")) return;
|
|
223
|
+
let s = o.dataset.id, c = +o.dataset.index, l = o.dataset.type, u = t.type === "touchstart";
|
|
224
|
+
m.current = l, g.current = c, _.current = null, u && o.dispatchEvent(new PointerEvent("pointerdown", {
|
|
225
|
+
bubbles: !0,
|
|
226
|
+
pointerType: "mouse"
|
|
227
|
+
}));
|
|
228
|
+
let b = l === "row" ? e.bodyRef.current.scrollLeft : 0, x = o.getBoundingClientRect();
|
|
229
|
+
v.current = {
|
|
230
|
+
width: x.width,
|
|
231
|
+
height: x.height
|
|
232
|
+
};
|
|
233
|
+
let S = {
|
|
234
|
+
x: r - x.left - b,
|
|
235
|
+
y: i - x.top
|
|
236
|
+
};
|
|
237
|
+
h.current = S, y.current = {
|
|
238
|
+
x: r,
|
|
239
|
+
y: i
|
|
240
|
+
}, d.current = {
|
|
241
|
+
x: r,
|
|
242
|
+
y: i
|
|
243
|
+
};
|
|
244
|
+
let C = {
|
|
245
|
+
x: x.left + b,
|
|
246
|
+
y: x.top
|
|
247
|
+
};
|
|
248
|
+
l === "row" ? f.current = N() : f.current = P();
|
|
249
|
+
let w = e.bodyRef.current;
|
|
250
|
+
w && (p.current = w.getBoundingClientRect());
|
|
251
|
+
let T = e.cloneRef?.current;
|
|
252
|
+
T && (T.style.transform = `translate(${C.x}px, ${C.y}px)`);
|
|
253
|
+
let E = e.tableRef?.current;
|
|
254
|
+
E && (E.style.touchAction = "none"), n({
|
|
255
|
+
type: "dragStart",
|
|
256
|
+
value: {
|
|
257
|
+
rect: {
|
|
258
|
+
draggedItemHeight: x.height,
|
|
259
|
+
draggedItemWidth: x.width
|
|
260
|
+
},
|
|
261
|
+
dragged: {
|
|
262
|
+
initial: S,
|
|
263
|
+
translate: C,
|
|
264
|
+
draggedID: s,
|
|
265
|
+
isDragging: !0,
|
|
266
|
+
sourceIndex: c
|
|
267
|
+
},
|
|
268
|
+
dragType: l
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
let D = () => {
|
|
272
|
+
let t = e.cloneRef?.current, n = e.bodyRef.current;
|
|
273
|
+
if (t && n) {
|
|
274
|
+
if (l === "row") t.scrollLeft = n.scrollLeft;
|
|
275
|
+
else if (l === "column") {
|
|
276
|
+
let e = t.querySelector(".clone-body");
|
|
277
|
+
e && (e.scrollTop = n.scrollTop);
|
|
189
278
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let c = s === "row" ? e.bodyRef.current.scrollLeft : 0, l = i.getBoundingClientRect();
|
|
196
|
-
S.current = {
|
|
197
|
-
width: l.width,
|
|
198
|
-
height: l.height
|
|
199
|
-
};
|
|
200
|
-
let u = {
|
|
201
|
-
x: 0,
|
|
202
|
-
y: 0
|
|
203
|
-
};
|
|
204
|
-
t.type === "touchstart" ? (u.x = t.touches[0].clientX, u.y = t.touches[0].clientY) : (u.x = t.clientX - l.left - c, u.y = t.clientY - l.top), g.current = u;
|
|
205
|
-
let d = {
|
|
206
|
-
x: l.left + c,
|
|
207
|
-
y: l.top
|
|
208
|
-
};
|
|
209
|
-
s === "row" ? p.current = w() : p.current = T();
|
|
210
|
-
let f = e.bodyRef.current;
|
|
211
|
-
f && (m.current = f.getBoundingClientRect());
|
|
212
|
-
let y = e.cloneRef?.current;
|
|
213
|
-
y && (y.style.transform = `translate(${d.x}px, ${d.y}px)`), requestAnimationFrame(() => {
|
|
214
|
-
n({
|
|
215
|
-
type: "dragStart",
|
|
216
|
-
value: {
|
|
217
|
-
rect: {
|
|
218
|
-
draggedItemHeight: l.height,
|
|
219
|
-
draggedItemWidth: l.width
|
|
220
|
-
},
|
|
221
|
-
dragged: {
|
|
222
|
-
initial: u,
|
|
223
|
-
translate: d,
|
|
224
|
-
draggedID: a,
|
|
225
|
-
isDragging: !0,
|
|
226
|
-
sourceIndex: o
|
|
227
|
-
},
|
|
228
|
-
dragType: s
|
|
229
|
-
}
|
|
230
|
-
}), requestAnimationFrame(() => {
|
|
231
|
-
let t = e.cloneRef?.current, n = e.bodyRef.current;
|
|
232
|
-
if (t && n) {
|
|
233
|
-
if (s === "row") t.scrollLeft = n.scrollLeft;
|
|
234
|
-
else if (s === "column") {
|
|
235
|
-
let e = t.querySelector(".clone-body");
|
|
236
|
-
e && (e.scrollTop = n.scrollTop);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
D(), requestAnimationFrame(() => {
|
|
282
|
+
D(), requestAnimationFrame(D);
|
|
283
|
+
});
|
|
242
284
|
}, [
|
|
285
|
+
e.bodyRef,
|
|
286
|
+
e.cloneRef,
|
|
287
|
+
e.tableRef,
|
|
288
|
+
d,
|
|
243
289
|
n,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
290
|
+
N,
|
|
291
|
+
P
|
|
292
|
+
]), z = i((e) => {
|
|
293
|
+
e.target !== e.currentTarget && (k.current || R(e, e.clientX, e.clientY));
|
|
294
|
+
}, [R]), B = i(() => {
|
|
295
|
+
C.current &&= (clearTimeout(C.current), null), O.current = null, window.removeEventListener("touchmove", A.current), window.removeEventListener("touchend", j.current);
|
|
296
|
+
}, []), V = i((e) => {
|
|
297
|
+
if (e.target === e.currentTarget) return;
|
|
298
|
+
B(), k.current = !0;
|
|
299
|
+
let t = e.touches[0];
|
|
300
|
+
D.current = {
|
|
301
|
+
x: t.clientX,
|
|
302
|
+
y: t.clientY
|
|
303
|
+
}, O.current = e;
|
|
304
|
+
let n = (e) => {
|
|
305
|
+
let t = e.touches[0], n = t.clientX - D.current.x, r = t.clientY - D.current.y;
|
|
306
|
+
(Math.abs(n) > E || Math.abs(r) > E) && (B(), setTimeout(() => {
|
|
307
|
+
k.current = !1;
|
|
308
|
+
}, 400));
|
|
309
|
+
}, r = () => {
|
|
310
|
+
B(), setTimeout(() => {
|
|
311
|
+
k.current = !1;
|
|
312
|
+
}, 400);
|
|
313
|
+
};
|
|
314
|
+
A.current = n, j.current = r, window.addEventListener("touchmove", n, { passive: !0 }), window.addEventListener("touchend", r, !1), C.current = setTimeout(() => {
|
|
315
|
+
C.current = null, window.removeEventListener("touchmove", n), window.removeEventListener("touchend", r);
|
|
316
|
+
let e = O.current;
|
|
317
|
+
O.current = null, e && R(e, t.clientX, t.clientY);
|
|
318
|
+
}, T);
|
|
319
|
+
}, [R, B]), H = i((e) => {
|
|
320
|
+
M.current = e.pointerId ?? null;
|
|
321
|
+
}, []), U = i(() => {
|
|
322
|
+
B(), setTimeout(() => {
|
|
323
|
+
k.current = !1;
|
|
324
|
+
}, 400);
|
|
325
|
+
let t = _.current, r = g.current, i = m.current;
|
|
326
|
+
f.current = null, p.current = null;
|
|
250
327
|
let a = e.cloneRef?.current;
|
|
251
|
-
a && (a.style.transform = "translate(0px, 0px)", a.scrollLeft = 0)
|
|
328
|
+
a && (a.style.transform = "translate(0px, 0px)", a.scrollLeft = 0);
|
|
329
|
+
let o = e.tableRef?.current;
|
|
330
|
+
o && (o.style.touchAction = ""), L(), s && r !== null && t !== null && i && s({
|
|
252
331
|
sourceIndex: r,
|
|
253
332
|
targetIndex: t,
|
|
254
333
|
dragType: i
|
|
@@ -258,95 +337,152 @@ var g = d.div`
|
|
|
258
337
|
targetIndex: t,
|
|
259
338
|
sourceIndex: r
|
|
260
339
|
}
|
|
261
|
-
}), l(),
|
|
340
|
+
}), l(), m.current = null, g.current = null, _.current = null;
|
|
262
341
|
}, [
|
|
263
342
|
n,
|
|
264
343
|
l,
|
|
265
344
|
e.cloneRef,
|
|
266
|
-
|
|
345
|
+
e.tableRef,
|
|
346
|
+
L,
|
|
347
|
+
B,
|
|
267
348
|
s
|
|
268
|
-
]),
|
|
269
|
-
|
|
270
|
-
let
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
349
|
+
]), W = i(() => {
|
|
350
|
+
f.current = null, p.current = null;
|
|
351
|
+
let t = g.current, n = _.current, r = m.current;
|
|
352
|
+
t !== null && n !== null && I(t, n, r);
|
|
353
|
+
let i = e.cloneRef?.current, a = e.bodyRef?.current;
|
|
354
|
+
if (i && a) {
|
|
355
|
+
if (r === "row") i.scrollLeft = a.scrollLeft;
|
|
356
|
+
else if (r === "column") {
|
|
357
|
+
let e = i.querySelector(".clone-body");
|
|
358
|
+
e && (e.scrollTop = a.scrollTop);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
let o = e.bodyRef?.current;
|
|
362
|
+
if (o && r) {
|
|
363
|
+
let e = y.current, n = p.current;
|
|
364
|
+
n || (n = o.getBoundingClientRect(), p.current = n);
|
|
365
|
+
let i = 0;
|
|
366
|
+
if (r === "row") {
|
|
367
|
+
let t = f.current;
|
|
368
|
+
t || (t = N(), f.current = t), t && t.length > 0 && (i = x(e.y - n.top + o.scrollTop, t));
|
|
369
|
+
} else {
|
|
370
|
+
let t = f.current;
|
|
371
|
+
t || (t = P(), f.current = t), t && t.length > 0 && (i = S(e.x, t));
|
|
372
|
+
}
|
|
373
|
+
i !== _.current && (_.current = i, I(t, i, r));
|
|
374
|
+
}
|
|
375
|
+
}, [
|
|
376
|
+
I,
|
|
377
|
+
e.cloneRef,
|
|
378
|
+
e.bodyRef,
|
|
379
|
+
N,
|
|
380
|
+
P
|
|
381
|
+
]), G = i((t) => {
|
|
382
|
+
let n = t.clientX ?? 0, i = t.clientY ?? 0, a = h.current, o = n - a.x, s = i - a.y;
|
|
383
|
+
y.current = {
|
|
384
|
+
x: n,
|
|
385
|
+
y: i
|
|
386
|
+
}, d.current = {
|
|
387
|
+
x: n,
|
|
388
|
+
y: i
|
|
389
|
+
};
|
|
390
|
+
let u = e.cloneRef?.current;
|
|
391
|
+
if (u) {
|
|
392
|
+
u.style.transform = `translate(${o}px, ${s}px)`;
|
|
279
393
|
let t = e.bodyRef.current;
|
|
280
394
|
if (t) {
|
|
281
|
-
if (
|
|
282
|
-
else if (
|
|
283
|
-
let e =
|
|
395
|
+
if (m.current === "row") u.scrollLeft = t.scrollLeft;
|
|
396
|
+
else if (m.current === "column") {
|
|
397
|
+
let e = u.querySelector(".clone-body");
|
|
284
398
|
e && (e.scrollTop = t.scrollTop);
|
|
285
399
|
}
|
|
286
400
|
}
|
|
287
401
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
n || (n = w(), p.current = n), n && n.length > 0 && (A = b(u - t + e, n)), u < C + 30 ? (c(-5, s, "vertical"), p.current = null) : u > E - 30 ? (c(5, s, "vertical"), p.current = null) : l();
|
|
402
|
+
let v = e.bodyRef.current;
|
|
403
|
+
if (!v) return;
|
|
404
|
+
let b = p.current;
|
|
405
|
+
b || (b = v.getBoundingClientRect(), p.current = b);
|
|
406
|
+
let { top: C, bottom: w, left: T, right: E } = b, D = 0, O = m.current || r;
|
|
407
|
+
if (O === "row") {
|
|
408
|
+
let e = v.scrollTop, t = b.top, n = f.current;
|
|
409
|
+
n || (n = N(), f.current = n), n && n.length > 0 && (D = x(i - t + e, n)), i < C + 30 ? (c(-5, v, "vertical"), f.current = null) : i > w - 30 ? (c(5, v, "vertical"), f.current = null) : l();
|
|
297
410
|
} else {
|
|
298
|
-
let e =
|
|
299
|
-
e || (e =
|
|
411
|
+
let e = f.current;
|
|
412
|
+
e || (e = P(), f.current = e), e && e.length > 0 && (D = S(n, e)), n < T + 30 ? (c(-5, v, "horizontal"), f.current = null) : n > E - 30 ? (c(5, v, "horizontal"), f.current = null) : l();
|
|
300
413
|
}
|
|
301
|
-
|
|
302
|
-
|
|
414
|
+
D !== _.current && (_.current = D, requestAnimationFrame(() => {
|
|
415
|
+
I(g.current, D, O);
|
|
303
416
|
}));
|
|
304
417
|
}, [
|
|
305
|
-
r,
|
|
306
418
|
d,
|
|
307
|
-
f,
|
|
308
|
-
e.bodyRef,
|
|
309
419
|
e.cloneRef,
|
|
310
|
-
|
|
311
|
-
|
|
420
|
+
e.bodyRef,
|
|
421
|
+
r,
|
|
422
|
+
N,
|
|
312
423
|
c,
|
|
313
424
|
l,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
425
|
+
P,
|
|
426
|
+
I
|
|
427
|
+
]), K = i(() => {
|
|
428
|
+
B(), f.current = null, p.current = null;
|
|
317
429
|
let t = e.cloneRef?.current;
|
|
318
|
-
t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0)
|
|
430
|
+
t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0);
|
|
431
|
+
let r = e.tableRef?.current;
|
|
432
|
+
r && (r.style.touchAction = ""), L(), n({
|
|
319
433
|
type: "dragEnd",
|
|
320
434
|
value: {
|
|
321
435
|
targetIndex: null,
|
|
322
436
|
sourceIndex: null
|
|
323
437
|
}
|
|
324
|
-
}), l(),
|
|
438
|
+
}), l(), m.current = null, g.current = null, _.current = null;
|
|
325
439
|
}, [
|
|
326
440
|
n,
|
|
327
441
|
l,
|
|
328
442
|
e.cloneRef,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
443
|
+
e.tableRef,
|
|
444
|
+
L,
|
|
445
|
+
B
|
|
446
|
+
]), q = i((e) => {
|
|
447
|
+
e.key === "Escape" && K();
|
|
448
|
+
}, [K]);
|
|
333
449
|
return o(() => {
|
|
334
450
|
if (t.isDragging) {
|
|
335
|
-
let t = e.bodyRef.current;
|
|
336
|
-
|
|
337
|
-
|
|
451
|
+
let t = e.bodyRef.current, n = e.tableRef?.current;
|
|
452
|
+
if (n && M.current !== null) try {
|
|
453
|
+
n.setPointerCapture(M.current);
|
|
454
|
+
} catch {}
|
|
455
|
+
let r = (e) => {
|
|
456
|
+
e.pointerType === "touch" && e.preventDefault(), G(e);
|
|
457
|
+
}, i = () => U(), a = () => U();
|
|
458
|
+
return n && (n.addEventListener("pointermove", r, { passive: !1 }), n.addEventListener("pointerup", i), n.addEventListener("pointercancel", a)), window.addEventListener("mouseup", U, !1), window.addEventListener("keydown", q), t?.addEventListener("scroll", W, { passive: !0 }), () => {
|
|
459
|
+
if (n) {
|
|
460
|
+
if (n.removeEventListener("pointermove", r), n.removeEventListener("pointerup", i), n.removeEventListener("pointercancel", a), M.current !== null) {
|
|
461
|
+
try {
|
|
462
|
+
n.releasePointerCapture(M.current);
|
|
463
|
+
} catch {}
|
|
464
|
+
M.current = null;
|
|
465
|
+
}
|
|
466
|
+
n.style.touchAction = "";
|
|
467
|
+
}
|
|
468
|
+
window.removeEventListener("mouseup", U, !1), window.removeEventListener("keydown", q), t?.removeEventListener("scroll", W);
|
|
338
469
|
};
|
|
339
470
|
}
|
|
340
471
|
}, [
|
|
341
472
|
t.isDragging,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
e.bodyRef
|
|
348
|
-
|
|
349
|
-
|
|
473
|
+
G,
|
|
474
|
+
U,
|
|
475
|
+
K,
|
|
476
|
+
q,
|
|
477
|
+
W,
|
|
478
|
+
e.bodyRef,
|
|
479
|
+
e.tableRef
|
|
480
|
+
]), {
|
|
481
|
+
dragStart: z,
|
|
482
|
+
touchStart: V,
|
|
483
|
+
onPointerDown: H
|
|
484
|
+
};
|
|
485
|
+
}, O = {
|
|
350
486
|
columnDragRange: {
|
|
351
487
|
start: void 0,
|
|
352
488
|
end: void 0
|
|
@@ -357,7 +493,7 @@ var g = d.div`
|
|
|
357
493
|
},
|
|
358
494
|
defaultSizing: 50
|
|
359
495
|
};
|
|
360
|
-
function
|
|
496
|
+
function k(e, t) {
|
|
361
497
|
switch (t.type) {
|
|
362
498
|
case "setClone": return {
|
|
363
499
|
...e,
|
|
@@ -431,7 +567,7 @@ function E(e, t) {
|
|
|
431
567
|
};
|
|
432
568
|
case "setOptions": return {
|
|
433
569
|
...e,
|
|
434
|
-
options: t.value ??
|
|
570
|
+
options: t.value ?? O
|
|
435
571
|
};
|
|
436
572
|
case "dragStart": return {
|
|
437
573
|
...e,
|
|
@@ -468,7 +604,7 @@ function E(e, t) {
|
|
|
468
604
|
default: throw Error(`Unhandled action type: ${t.type}`);
|
|
469
605
|
}
|
|
470
606
|
}
|
|
471
|
-
var
|
|
607
|
+
var A = {
|
|
472
608
|
clone: null,
|
|
473
609
|
dragged: {
|
|
474
610
|
initial: {
|
|
@@ -501,24 +637,24 @@ var D = {
|
|
|
501
637
|
placeholderRef: null
|
|
502
638
|
},
|
|
503
639
|
bodyScrollBarWidth: 0,
|
|
504
|
-
options:
|
|
640
|
+
options: O,
|
|
505
641
|
widths: [],
|
|
506
642
|
columnIds: []
|
|
507
|
-
},
|
|
643
|
+
}, j = {
|
|
508
644
|
position: "relative",
|
|
509
645
|
display: "flex",
|
|
510
646
|
flexFlow: "column"
|
|
511
|
-
},
|
|
647
|
+
}, M = {
|
|
512
648
|
position: "fixed",
|
|
513
649
|
pointerEvents: "none",
|
|
514
650
|
zIndex: 3,
|
|
515
651
|
top: 0,
|
|
516
652
|
left: 0,
|
|
517
653
|
display: "none"
|
|
518
|
-
},
|
|
654
|
+
}, N = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, d) => {
|
|
519
655
|
let m = u(null), h = u(null), v = u(null);
|
|
520
656
|
s(d, () => m.current, []);
|
|
521
|
-
let [y, b] = l(
|
|
657
|
+
let [y, b] = l(k, A), x = c(() => ({
|
|
522
658
|
state: y,
|
|
523
659
|
dispatch: b
|
|
524
660
|
}), [y]);
|
|
@@ -552,7 +688,7 @@ var D = {
|
|
|
552
688
|
value: r
|
|
553
689
|
});
|
|
554
690
|
}, [r]);
|
|
555
|
-
let { dragStart: S } =
|
|
691
|
+
let { dragStart: S, touchStart: C, onPointerDown: w } = D(y.refs, y.dragged, b, y.dragType, y.options, i), T = c(() => ({
|
|
556
692
|
position: "fixed",
|
|
557
693
|
zIndex: "5",
|
|
558
694
|
pointerEvents: "none",
|
|
@@ -579,22 +715,32 @@ var D = {
|
|
|
579
715
|
children: [
|
|
580
716
|
/* @__PURE__ */ f("div", {
|
|
581
717
|
id: "portalroot",
|
|
582
|
-
style:
|
|
718
|
+
style: {
|
|
719
|
+
...T,
|
|
720
|
+
visibility: y.dragged.isDragging ? "visible" : "hidden"
|
|
721
|
+
},
|
|
583
722
|
ref: h,
|
|
584
|
-
children:
|
|
723
|
+
children: /* @__PURE__ */ f("div", {
|
|
724
|
+
style: {
|
|
725
|
+
flexShrink: 0,
|
|
726
|
+
order: -1
|
|
727
|
+
},
|
|
728
|
+
children: y.clone
|
|
729
|
+
})
|
|
585
730
|
}),
|
|
586
731
|
a && /* @__PURE__ */ f("div", {
|
|
587
732
|
ref: v,
|
|
588
|
-
style:
|
|
733
|
+
style: M,
|
|
589
734
|
children: a()
|
|
590
735
|
}),
|
|
591
736
|
/* @__PURE__ */ f("div", {
|
|
592
737
|
"data-contextid": "context",
|
|
593
738
|
ref: m,
|
|
594
739
|
onMouseDown: S,
|
|
595
|
-
onTouchStart:
|
|
740
|
+
onTouchStart: C,
|
|
741
|
+
onPointerDown: w,
|
|
596
742
|
style: {
|
|
597
|
-
...
|
|
743
|
+
...j,
|
|
598
744
|
...n
|
|
599
745
|
},
|
|
600
746
|
className: `table ${t ?? ""}`,
|
|
@@ -604,10 +750,10 @@ var D = {
|
|
|
604
750
|
})
|
|
605
751
|
});
|
|
606
752
|
});
|
|
607
|
-
|
|
753
|
+
N.displayName = "TableProvider";
|
|
608
754
|
//#endregion
|
|
609
755
|
//#region src/Components/TableHeader.tsx
|
|
610
|
-
var
|
|
756
|
+
var P = n(({ children: e, style: t, className: n }, r) => {
|
|
611
757
|
let i = u(null), a = r || i, { state: s, dispatch: l } = v();
|
|
612
758
|
o(() => {
|
|
613
759
|
l({
|
|
@@ -615,7 +761,7 @@ var j = n(({ children: e, style: t, className: n }, r) => {
|
|
|
615
761
|
value: a
|
|
616
762
|
});
|
|
617
763
|
}, [l, a]);
|
|
618
|
-
let { HeaderScrollHandle: d } =
|
|
764
|
+
let { HeaderScrollHandle: d } = b(s.refs), p = {
|
|
619
765
|
display: "flex",
|
|
620
766
|
flex: "1 0 auto"
|
|
621
767
|
}, m = c(() => ({
|
|
@@ -666,15 +812,15 @@ var j = n(({ children: e, style: t, className: n }, r) => {
|
|
|
666
812
|
})
|
|
667
813
|
});
|
|
668
814
|
});
|
|
669
|
-
|
|
815
|
+
P.displayName = "TableHeader";
|
|
670
816
|
//#endregion
|
|
671
817
|
//#region src/Components/Draggable.tsx
|
|
672
|
-
var
|
|
818
|
+
var F = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
673
819
|
let { state: s, dispatch: l } = v(), d = c(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
|
|
674
820
|
n,
|
|
675
821
|
s.dragged.draggedID,
|
|
676
822
|
s.dragged.isDragging
|
|
677
|
-
]), p = c(() => i === "row" ?
|
|
823
|
+
]), p = c(() => i === "row" ? C(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : C(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
|
|
678
824
|
r,
|
|
679
825
|
s.options.columnDragRange.end,
|
|
680
826
|
s.options.columnDragRange.start,
|
|
@@ -692,19 +838,19 @@ var M = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
|
692
838
|
pointerEvents: d ? "none" : "auto",
|
|
693
839
|
display: "flex"
|
|
694
840
|
}), [p, d]), _ = (n) => {
|
|
695
|
-
p || requestAnimationFrame(() => {
|
|
841
|
+
n.pointerType !== "touch" && (p || requestAnimationFrame(() => {
|
|
696
842
|
l({
|
|
697
843
|
type: "setClone",
|
|
698
844
|
value: e.cloneElement(t)
|
|
699
845
|
});
|
|
700
|
-
});
|
|
846
|
+
}));
|
|
701
847
|
};
|
|
702
848
|
return /* @__PURE__ */ f("div", {
|
|
703
849
|
className: "draggable",
|
|
704
850
|
"data-id": n,
|
|
705
851
|
"data-index": r,
|
|
706
852
|
"data-type": i,
|
|
707
|
-
|
|
853
|
+
onPointerDown: _,
|
|
708
854
|
"data-disabled": p ? "true" : "false",
|
|
709
855
|
style: a,
|
|
710
856
|
children: /* @__PURE__ */ f("div", {
|
|
@@ -714,15 +860,15 @@ var M = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
|
714
860
|
})
|
|
715
861
|
});
|
|
716
862
|
});
|
|
717
|
-
|
|
863
|
+
F.displayName = "Draggable";
|
|
718
864
|
//#endregion
|
|
719
865
|
//#region src/Components/ColumnCell.tsx
|
|
720
|
-
var
|
|
866
|
+
var I = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
721
867
|
let { state: a } = v(), o = c(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = c(() => ({
|
|
722
868
|
width: `${o}px`,
|
|
723
869
|
flex: `${o} 0 auto`
|
|
724
870
|
}), [o]);
|
|
725
|
-
return /* @__PURE__ */ f(
|
|
871
|
+
return /* @__PURE__ */ f(F, {
|
|
726
872
|
...i,
|
|
727
873
|
styles: s,
|
|
728
874
|
type: "column",
|
|
@@ -737,10 +883,10 @@ var N = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
|
737
883
|
})
|
|
738
884
|
});
|
|
739
885
|
});
|
|
740
|
-
|
|
886
|
+
I.displayName = "ColumnCell";
|
|
741
887
|
//#endregion
|
|
742
888
|
//#region src/Components/TableBody.tsx
|
|
743
|
-
var
|
|
889
|
+
var L = n(({ children: t, style: n, className: r }, i) => {
|
|
744
890
|
let a = u(null);
|
|
745
891
|
s(i, () => a.current, []);
|
|
746
892
|
let { state: l, dispatch: d } = v(), h = c(() => {
|
|
@@ -765,7 +911,7 @@ var P = n(({ children: t, style: n, className: r }, i) => {
|
|
|
765
911
|
value: a
|
|
766
912
|
});
|
|
767
913
|
}, [d, a]);
|
|
768
|
-
let { BodyScrollHandle: g } =
|
|
914
|
+
let { BodyScrollHandle: g } = b(l.refs), _ = c(() => ({
|
|
769
915
|
overflowX: "auto",
|
|
770
916
|
overflowY: "auto",
|
|
771
917
|
flex: 1,
|
|
@@ -781,7 +927,7 @@ var P = n(({ children: t, style: n, className: r }, i) => {
|
|
|
781
927
|
});
|
|
782
928
|
}
|
|
783
929
|
}, [d, a]);
|
|
784
|
-
let
|
|
930
|
+
let y = a.current?.scrollHeight ?? 0;
|
|
785
931
|
return /* @__PURE__ */ p(e.Fragment, { children: [l.dragType === "column" && l.refs.cloneRef?.current && m(/* @__PURE__ */ f("div", {
|
|
786
932
|
className: "body clone-body",
|
|
787
933
|
"data-droppableid": "body",
|
|
@@ -792,14 +938,14 @@ var P = n(({ children: t, style: n, className: r }, i) => {
|
|
|
792
938
|
children: /* @__PURE__ */ f("div", {
|
|
793
939
|
className: "rbody",
|
|
794
940
|
style: {
|
|
795
|
-
height:
|
|
941
|
+
height: y,
|
|
796
942
|
position: "relative"
|
|
797
943
|
},
|
|
798
944
|
children: h
|
|
799
945
|
})
|
|
800
946
|
}), l.refs.cloneRef.current), /* @__PURE__ */ f("div", {
|
|
801
947
|
className: `body ${r ?? ""}`,
|
|
802
|
-
style:
|
|
948
|
+
style: R,
|
|
803
949
|
children: /* @__PURE__ */ f("div", {
|
|
804
950
|
className: "ibody",
|
|
805
951
|
style: _,
|
|
@@ -809,24 +955,24 @@ var P = n(({ children: t, style: n, className: r }, i) => {
|
|
|
809
955
|
children: t
|
|
810
956
|
})
|
|
811
957
|
})] });
|
|
812
|
-
}),
|
|
958
|
+
}), R = {
|
|
813
959
|
display: "flex",
|
|
814
960
|
overflow: "hidden",
|
|
815
961
|
flex: 1
|
|
816
962
|
};
|
|
817
|
-
|
|
963
|
+
L.displayName = "TableBody";
|
|
818
964
|
//#endregion
|
|
819
965
|
//#region src/Components/BodyRow.tsx
|
|
820
|
-
var
|
|
966
|
+
var z = {
|
|
821
967
|
display: "flex",
|
|
822
968
|
flex: "1 0 auto",
|
|
823
969
|
minHeight: "24px"
|
|
824
|
-
},
|
|
970
|
+
}, B = r(({ children: e, style: t, className: n, ...r }) => {
|
|
825
971
|
let i = c(() => t ? {
|
|
826
|
-
...
|
|
972
|
+
...z,
|
|
827
973
|
...t
|
|
828
|
-
} :
|
|
829
|
-
return /* @__PURE__ */ f(
|
|
974
|
+
} : z, [t]), a = h("tr", n);
|
|
975
|
+
return /* @__PURE__ */ f(F, {
|
|
830
976
|
...r,
|
|
831
977
|
type: "row",
|
|
832
978
|
children: /* @__PURE__ */ f("div", {
|
|
@@ -836,10 +982,10 @@ var I = {
|
|
|
836
982
|
})
|
|
837
983
|
});
|
|
838
984
|
});
|
|
839
|
-
|
|
985
|
+
B.displayName = "BodyRow";
|
|
840
986
|
//#endregion
|
|
841
987
|
//#region src/Components/RowCell.tsx
|
|
842
|
-
var
|
|
988
|
+
var V = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
|
|
843
989
|
let { index: a } = i, { state: o } = v(), s = c(() => o.columnIds[a] ?? "", [o.columnIds, a]), l = c(() => o.widths[a] ?? o.options.defaultSizing, [
|
|
844
990
|
o.widths,
|
|
845
991
|
a,
|
|
@@ -866,10 +1012,10 @@ var R = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
|
|
|
866
1012
|
children: e
|
|
867
1013
|
});
|
|
868
1014
|
});
|
|
869
|
-
|
|
1015
|
+
V.displayName = "RowCell";
|
|
870
1016
|
//#endregion
|
|
871
1017
|
//#region src/Components/DragHandle.tsx
|
|
872
|
-
var
|
|
1018
|
+
var H = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
|
|
873
1019
|
"data-drag-handle": "true",
|
|
874
1020
|
className: t,
|
|
875
1021
|
style: {
|
|
@@ -880,6 +1026,6 @@ var z = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div",
|
|
|
880
1026
|
},
|
|
881
1027
|
children: e
|
|
882
1028
|
}));
|
|
883
|
-
|
|
1029
|
+
H.displayName = "DragHandle";
|
|
884
1030
|
//#endregion
|
|
885
|
-
export {
|
|
1031
|
+
export { B as BodyRow, I as ColumnCell, H as DragHandle, V as RowCell, L as TableBody, N as TableContainer, P as TableHeader, v as useTable };
|