flexitablesort 1.1.7 → 1.1.9
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/index.cjs.js +14 -2
- package/dist/index.es.js +323 -283
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`styled-components`);l=s(l);let u=require(`react
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`styled-components`);l=s(l);let u=require(`react-dom`),d=require(`react/jsx-runtime`),f=require(`classnames`);f=s(f);var p=l.default.div`
|
|
2
2
|
height: 100%;
|
|
3
3
|
|
|
4
4
|
/* Structural elements: full reset */
|
|
@@ -16,7 +16,19 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
&.is-dragging, &.is-dragging * {
|
|
19
|
+
cursor: -webkit-grabbing !important;
|
|
20
|
+
cursor: grabbing !important;
|
|
19
21
|
user-select: none !important;
|
|
20
22
|
-webkit-user-select: none !important;
|
|
23
|
+
-webkit-touch-callout: none !important;
|
|
21
24
|
}
|
|
22
|
-
`,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.useRef)(null),s=(0,c.useCallback)(e=>{o.current=e},[]),l=(0,c.useCallback)(()=>{n.current=!1,t.current=!1,i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),u=(0,c.useCallback)((e,s,c)=>{let l=c===`vertical`,d=l?n:t;if(!d.current)return;let f=o.current;if(f){let e=a.current;if(l){let t=e.y<f.top+g,n=e.y>f.bottom-g;if(!t&&!n){d.current=!1;return}}else{let t=e.x<f.left+g,n=e.x>f.right-g;if(!t&&!n){d.current=!1;return}}}let p=l?s.scrollHeight-s.clientHeight:s.scrollWidth-s.clientWidth;l?s.scrollTop+=e:s.scrollLeft+=e;let m=l?s.scrollTop:s.scrollLeft;if(m>=p||m<=0){d.current=!1;return}r.current+=e/1e3,i.current=requestAnimationFrame(()=>u(e+r.current,s,c))},[]);return{startAutoScroll:(0,c.useCallback)((e,a,o)=>{let s=o===`vertical`?n:t;s.current||(s.current=!0,r.current=0,i.current=requestAnimationFrame(()=>u(e,a,o)))},[u]),stopAutoScroll:l,setContainerRect:s,isAutoScrollingVertical:n,isAutoScrollingHorizontal:t,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=300,y=8;function b(e,t,n,r){let i=(0,c.useRef)(null),a=(0,c.useRef)({x:0,y:0}),o=(0,c.useRef)(null),s=(0,c.useRef)(!1),l=(0,c.useRef)(null),u=(0,c.useCallback)(()=>{i.current&&=(clearTimeout(i.current),null),o.current=null,l.current&&=(l.current(),null)},[]);return{touchStart:(0,c.useCallback)(c=>{if(c.target===c.currentTarget)return;let d=c.target,f=!1;for(;d&&!(d.dataset?.contextid||d.dataset?.disabled===`true`);){if(d.dataset?.id){f=!0;break}d=d.parentNode}if(!f)return;u(),s.current=!0;let p=c.touches[0];a.current={x:p.clientX,y:p.clientY},o.current=c;let m=e.tableRef?.current;if(!m)return;let h=!1,g=!1,_=p.clientY,b=p.clientX,x=t=>{t.preventDefault();let n=t.touches[0];if(g){let t=e.bodyRef?.current;t&&(t.scrollTop-=n.clientY-_,t.scrollLeft-=n.clientX-b),_=n.clientY,b=n.clientX}else if(h)r(n.clientX,n.clientY);else{let e=n.clientX-a.current.x,t=n.clientY-a.current.y;(Math.abs(e)>y||Math.abs(t)>y)&&(i.current&&=(clearTimeout(i.current),null),o.current=null,g=!0,_=n.clientY,b=n.clientX)}},S=()=>{h?(C(),n()):(u(),setTimeout(()=>{s.current=!1},400))},C=()=>{m.removeEventListener(`touchmove`,x),m.removeEventListener(`touchend`,S),m.removeEventListener(`touchcancel`,S),l.current=null};m.addEventListener(`touchmove`,x,{passive:!1}),m.addEventListener(`touchend`,S,!1),m.addEventListener(`touchcancel`,S,!1),l.current=C,i.current=setTimeout(()=>{i.current=null,h=!0;let e=o.current;o.current=null,e&&t(e,p.clientX,p.clientY)},v)},[t,n,r,u,e.tableRef?.current,e.bodyRef?.current]),cancelLongPress:u,isTouchActiveRef:s}}var x=(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},S=(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},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=(e,t,n,r,i,a)=>{let{startAutoScroll:o,stopAutoScroll:s,setContainerRect:l,pointerRef:u}=_(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),g=(0,c.useRef)(null),v=(0,c.useRef)({width:0,height:0}),y=(0,c.useRef)({x:0,y:0}),C=(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{start:s,end:c}=i.rowDragRange;return(s||c)&&(o=o.filter(e=>(!s||+e.index>=s)&&(!c||+e.index<c))),o},[e.bodyRef,i.rowDragRange]),T=(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),{start:r,end:a}=i.columnDragRange??{};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]),E=(0,c.useCallback)((t,n,r,i)=>{let a=e.placeholderRef?.current;if(!a||!t){a&&(a.style.display=`none`);return}let o=v.current,s=t.getBoundingClientRect(),c=e.tableRef?.current?.getBoundingClientRect(),l=(n??0)<(r??0);a.style.display=`block`,i===`row`?(a.style.top=`${l?s.top+s.height-o.height:s.top}px`,a.style.left=`${c?.left??s.left}px`,a.style.width=`${c?.width??s.width}px`,a.style.height=`${o.height}px`):(a.style.top=`${c?.top??s.top}px`,a.style.left=`${l?s.left+s.width-o.width:s.left}px`,a.style.width=`${o.width}px`,a.style.height=`${c?.height??s.height}px`)},[e.placeholderRef,e.tableRef]),D=(0,c.useCallback)((t,n,r)=>{if(t===null||n===null)return;let i=v.current,a=null,o=(e,r,i,o)=>{if(!e)return;let s=e.querySelectorAll(r);for(let e=0;e<s.length;e++){let r=s[e],c=+r.dataset.index,l=r.firstElementChild;if(!l)continue;let u=``;c>t&&c<=n?u=`translate${i}(-${o}px)`:c<t&&c>=n&&(u=`translate${i}(${o}px)`),l.style.transform=u,l.style.transition=c===t?`none`:w,c===n?(r.setAttribute(`data-drop-target`,`true`),a=r):r.removeAttribute(`data-drop-target`)}};if(r===`row`)o(e.bodyRef?.current??null,`.draggable[data-type="row"]`,`Y`,i.height);else if(r===`column`){o(e.headerRef?.current??null,`.draggable[data-type="column"]`,`X`,i.width);let r=e.bodyRef?.current;if(r){let e=r.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=w}}}E(a,t,n,r)},[e.bodyRef,e.headerRef,E]),O=(0,c.useCallback)(()=>{let t=e.placeholderRef?.current;t&&(t.style.display=`none`);for(let t of[e.bodyRef?.current,e.headerRef?.current]){if(!t)continue;let e=t.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 n=e.bodyRef?.current;if(n){let e=n.querySelectorAll(`.td[data-col-index]`);for(let t=0;t<e.length;t++)e[t].style.transform=``,e[t].style.transition=``}},[e.bodyRef,e.headerRef,e.placeholderRef]),k=e=>{let t=e,n=!1;for(;t;){if(t.dataset?.dragHandle===`true`&&(n=!0),t.dataset?.contextid||t.dataset?.disabled===`true`)return null;if(t.dataset?.id)return{element:t,foundHandle:n};t=t.parentNode}return null},A=(0,c.useCallback)((t,r,i)=>{let a=k(t.target);if(!a)return;let{element:o,foundHandle:s}=a;if(!s&&o.querySelector(`[data-drag-handle]`))return;let c=o.dataset.id,_=+o.dataset.index,b=o.dataset.type,x=t.type===`touchstart`;p.current=b,h.current=_,g.current=null,x&&o.dispatchEvent(new PointerEvent(`pointerdown`,{bubbles:!0,pointerType:`mouse`}));let S=b===`row`?e.bodyRef?.current?.scrollLeft??0:0,w=o.getBoundingClientRect();v.current={width:w.width,height:w.height};let E={x:r-w.left-S,y:i-w.top};m.current=E,y.current={x:r,y:i},u.current={x:r,y:i};let D={x:w.left+S,y:w.top};d.current=b===`row`?C():T();let O=e.bodyRef?.current;if(O){let e=O.getBoundingClientRect();f.current=e,l(e)}let A=e.tableRef?.current;A&&(A.style.touchAction=`none`);let j=e.cloneRef?.current;j&&(j.style.transform=`translate(${D.x}px, ${D.y}px)`);let M=e.tableRef?.current;M&&n({type:`setTableDimensions`,value:{height:M.offsetHeight,width:M.offsetWidth}}),n({type:`dragStart`,value:{rect:{draggedItemHeight:w.height,draggedItemWidth:w.width},dragged:{initial:E,translate:D,draggedID:c,isDragging:!0,sourceIndex:_},dragType:b}});let N=()=>{let t=e.cloneRef?.current,n=e.bodyRef?.current;if(!(!t||!n))if(b===`row`)t.scrollLeft=n.scrollLeft;else{let e=t.querySelector(`.clone-body`);e&&(e.scrollTop=n.scrollTop)}};N(),requestAnimationFrame(()=>{N(),requestAnimationFrame(N)})},[n,e,C,T,u,l]),j=(0,c.useCallback)(()=>{P(),setTimeout(()=>{F.current=!1},400);let t=g.current,r=h.current,i=p.current,o=e.bodyRef?.current,c=o?.scrollTop??0,l=o?.scrollLeft??0;d.current=null,f.current=null;let u=e.cloneRef?.current;u&&(u.style.transform=`translate(0px, 0px)`,u.scrollLeft=0);let m=e.tableRef?.current;m&&(m.style.touchAction=``),O(),a&&r!==null&&t!==null&&(i===`row`||i===`column`)&&a({sourceIndex:r,targetIndex:t,dragType:i}),n({type:`dragEnd`,value:{targetIndex:t,sourceIndex:r}}),s(),o&&(o.scrollTop=c,o.scrollLeft=l,requestAnimationFrame(()=>{o.scrollTop=c,o.scrollLeft=l})),p.current=null,h.current=null,g.current=null},[n,s,e.bodyRef,e.cloneRef,e.tableRef,O,a]),M=(0,c.useRef)(()=>{}),{touchStart:N,cancelLongPress:P,isTouchActiveRef:F}=b(e,A,j,(e,t)=>M.current(e,t)),I=(0,c.useCallback)(e=>{e.target!==e.currentTarget&&(F.current||A(e,e.clientX,e.clientY))},[A,F]),L=(0,c.useCallback)((t,n)=>{let i=m.current;y.current={x:t,y:n},u.current={x:t,y:n};let a=e.cloneRef?.current;if(a){a.style.transform=`translate(${t-i.x}px, ${n-i.y}px)`;let r=e.bodyRef?.current;if(r)if(p.current===`row`)a.scrollLeft=r.scrollLeft;else{let e=a.querySelector(`.clone-body`);e&&(e.scrollTop=r.scrollTop)}}let c=e.bodyRef?.current;if(!c)return;let l=f.current;l||(l=c.getBoundingClientRect(),f.current=l);let _=0,v=p.current||r;v===`row`?n<l.top+30?(o(-5,c,`vertical`),d.current=null):n>l.bottom-30?(o(5,c,`vertical`),d.current=null):s():t<l.left+30?(o(-5,c,`horizontal`),d.current=null):t>l.right-30?(o(5,c,`horizontal`),d.current=null):s();let b;v===`row`?(b=C(),d.current=b,b&&b.length>0&&(_=x(n-l.top+c.scrollTop,b))):(b=T(),d.current=b,b&&b.length>0&&(_=S(t,b))),_!==g.current&&(g.current=_,requestAnimationFrame(()=>D(h.current,_,v)))},[r,e.bodyRef,e.cloneRef,C,T,o,s,D,u]);M.current=L;let R=(0,c.useCallback)(()=>{P(),d.current=null,f.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=``),O(),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),p.current=null,h.current=null,g.current=null},[n,s,e.cloneRef,e.tableRef,O,P]),z=(0,c.useCallback)(e=>{e.key===`Escape`&&R()},[R]);return(0,c.useEffect)(()=>{let t=e.bodyRef?.current;return t&&(t.style.touchAction=`none`),()=>{t&&(t.style.touchAction=``)}},[e.bodyRef]),(0,c.useEffect)(()=>{if(!t.isDragging)return;let e=e=>{L(e.clientX,e.clientY)},n=()=>{j()};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),window.addEventListener(`keydown`,z),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n),window.removeEventListener(`keydown`,z)}},[t.isDragging,L,j,z]),{dragStart:I,touchStart:N}},E={columnDragRange:{start:void 0,end:void 0},rowDragRange:{start:void 0,end:void 0},defaultSizing:50};function D(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??E};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 O={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:E,widths:[],columnIds:[]},k={position:`relative`,display:`flex`,flexFlow:`column`},A={position:`fixed`,pointerEvents:`none`,zIndex:3,top:0,left:0,display:`none`},j=(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)(D,O),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}=T(f.refs,f.dragged,h,f.dragType,f.options,i),y=(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}px`,width:f.dragType===`column`?`${f.rect.draggedItemWidth}px`:`${f.tableDimensions.width}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:{...y,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:A,children:a()}),(0,u.jsx)(`div`,{"data-contextid":`context`,ref:s,onMouseDown:_,onTouchStart:v,style:{...k,...n},className:`table ${t??``}`,children:e})]})})});j.displayName=`TableProvider`;var M=(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})})})});M.displayName=`TableHeader`;var N=(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`?C(n,a.options.rowDragRange.start,a.options.rowDragRange.end):C(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})})});N.displayName=`Draggable`;var P=(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)(N,{...i,styles:s,type:`column`,children:(0,u.jsx)(`div`,{className:`th ${r??``}`,"data-width":t,style:{width:`100%`,...n},children:e})})});P.displayName=`ColumnCell`;var F=(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:I,children:(0,u.jsx)(`div`,{className:`ibody`,style:f,"data-droppableid":`body`,onScroll:l,ref:i,children:e})})]})}),I={display:`flex`,overflow:`hidden`,flex:1};F.displayName=`TableBody`;var L={display:`flex`,flex:`1 0 auto`,minHeight:`24px`},R=(0,c.memo)(({children:e,style:t,className:n,...r})=>{let i=(0,c.useMemo)(()=>t?{...L,...t}:L,[t]),a=(0,f.default)(`tr`,n);return(0,u.jsx)(N,{...r,type:`row`,children:(0,u.jsx)(`div`,{className:a,style:i,children:e})})});R.displayName=`BodyRow`;var z=(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})});z.displayName=`RowCell`;var B=(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}));B.displayName=`DragHandle`,exports.BodyRow=R,exports.ColumnCell=P,exports.DragHandle=B,exports.RowCell=z,exports.TableBody=F,exports.TableContainer=j,exports.TableHeader=M,exports.useTable=h;
|
|
25
|
+
|
|
26
|
+
/* When a DragHandle exists, only the handle shows grab cursor */
|
|
27
|
+
&:not(.is-dragging) .draggable:has([data-drag-handle]) > div {
|
|
28
|
+
cursor: default !important;
|
|
29
|
+
}
|
|
30
|
+
&:not(.is-dragging) [data-drag-handle] {
|
|
31
|
+
cursor: -webkit-grab;
|
|
32
|
+
cursor: grab;
|
|
33
|
+
}
|
|
34
|
+
`,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.useRef)(null),s=(0,c.useCallback)(e=>{o.current=e},[]),l=(0,c.useCallback)(()=>{n.current=!1,t.current=!1,i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),u=(0,c.useCallback)((e,s,c)=>{let l=c===`vertical`,d=l?n:t;if(!d.current)return;let f=o.current;if(f){let e=a.current;if(l){let t=e.y<f.top+g,n=e.y>f.bottom-g;if(!t&&!n){d.current=!1;return}}else{let t=e.x<f.left+g,n=e.x>f.right-g;if(!t&&!n){d.current=!1;return}}}let p=l?s.scrollHeight-s.clientHeight:s.scrollWidth-s.clientWidth;l?s.scrollTop+=e:s.scrollLeft+=e;let m=l?s.scrollTop:s.scrollLeft;if(m>=p||m<=0){d.current=!1;return}r.current+=e/1e3,i.current=requestAnimationFrame(()=>u(e+r.current,s,c))},[]);return{startAutoScroll:(0,c.useCallback)((e,a,o)=>{let s=o===`vertical`?n:t;s.current||(s.current=!0,r.current=0,i.current=requestAnimationFrame(()=>u(e,a,o)))},[u]),stopAutoScroll:l,setContainerRect:s,isAutoScrollingVertical:n,isAutoScrollingHorizontal:t,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=300,y=8;function b(e,t,n,r){let i=(0,c.useRef)(null),a=(0,c.useRef)({x:0,y:0}),o=(0,c.useRef)(null),s=(0,c.useRef)(!1),l=(0,c.useRef)(null),u=(0,c.useCallback)(()=>{i.current&&=(clearTimeout(i.current),null),o.current=null,l.current&&=(l.current(),null)},[]);return{touchStart:(0,c.useCallback)(c=>{if(c.target===c.currentTarget)return;let d=c.target,f=!1;for(;d&&!(d.dataset?.contextid||d.dataset?.disabled===`true`);){if(d.dataset?.id){f=!0;break}d=d.parentNode}if(!f)return;u(),s.current=!0,window.getSelection()?.removeAllRanges();let p=c.touches[0];a.current={x:p.clientX,y:p.clientY},o.current=c;let m=e.tableRef?.current;if(!m)return;let h=!1,g=!1,_=p.clientY,b=p.clientX,x=e=>e.preventDefault();document.addEventListener(`selectstart`,x);let S=t=>{t.preventDefault();let n=t.touches[0];if(g){let t=e.bodyRef?.current;t&&(t.scrollTop-=n.clientY-_,t.scrollLeft-=n.clientX-b),_=n.clientY,b=n.clientX}else if(h)r(n.clientX,n.clientY);else{let e=n.clientX-a.current.x,t=n.clientY-a.current.y;(Math.abs(e)>y||Math.abs(t)>y)&&(i.current&&=(clearTimeout(i.current),null),o.current=null,g=!0,_=n.clientY,b=n.clientX)}},C=()=>{h?(w(),n()):(u(),setTimeout(()=>{s.current=!1},400))},w=()=>{m.removeEventListener(`touchmove`,S),m.removeEventListener(`touchend`,C),m.removeEventListener(`touchcancel`,C),document.removeEventListener(`selectstart`,x),l.current=null};m.addEventListener(`touchmove`,S,{passive:!1}),m.addEventListener(`touchend`,C,!1),m.addEventListener(`touchcancel`,C,!1),l.current=w,i.current=setTimeout(()=>{i.current=null,h=!0;let e=o.current;o.current=null,e&&t(e,p.clientX,p.clientY)},v)},[t,n,r,u,e.tableRef?.current,e.bodyRef?.current]),cancelLongPress:u,isTouchActiveRef:s}}var x=(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},S=(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},C=(e,t,n)=>t!==void 0&&e<t||n!==void 0&&e>n,w=`transform 450ms cubic-bezier(0.2, 0, 0, 1)`,T=200,E=(e,t,n,r,i,a)=>{let{startAutoScroll:o,stopAutoScroll:s,setContainerRect:l,pointerRef:d}=_(e),f=(0,c.useRef)(null),p=(0,c.useRef)(null),m=(0,c.useRef)(null),h=(0,c.useRef)({x:0,y:0}),g=(0,c.useRef)(null),v=(0,c.useRef)(null),y=(0,c.useRef)({width:0,height:0}),C=(0,c.useRef)({x:0,y:0}),E=(0,c.useRef)(!1),D=(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{start:s,end:c}=i.rowDragRange;return(s||c)&&(o=o.filter(e=>(!s||+e.index>=s)&&(!c||+e.index<c))),o},[e.bodyRef,i.rowDragRange]),O=(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),{start:r,end:a}=i.columnDragRange??{};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]),k=(0,c.useCallback)((t,n,r,i)=>{let a=e.placeholderRef?.current;if(!a||!t){a&&(a.style.display=`none`);return}let o=y.current,s=t.getBoundingClientRect(),c=e.tableRef?.current?.getBoundingClientRect(),l=(n??0)<(r??0);a.style.display=`block`,i===`row`?(a.style.top=`${l?s.top+s.height-o.height:s.top}px`,a.style.left=`${c?.left??s.left}px`,a.style.width=`${c?.width??s.width}px`,a.style.height=`${o.height}px`):(a.style.top=`${c?.top??s.top}px`,a.style.left=`${l?s.left+s.width-o.width:s.left}px`,a.style.width=`${o.width}px`,a.style.height=`${c?.height??s.height}px`)},[e.placeholderRef,e.tableRef]),A=(0,c.useCallback)((t,n,r)=>{if(t===null||n===null)return;let i=y.current,a=null,o=(e,r,i,o)=>{if(!e)return;let s=e.querySelectorAll(r);for(let e=0;e<s.length;e++){let r=s[e],c=+r.dataset.index,l=r.firstElementChild;if(!l)continue;let u=``;c>t&&c<=n?u=`translate${i}(-${o}px)`:c<t&&c>=n&&(u=`translate${i}(${o}px)`),l.style.transform=u,l.style.transition=c===t?`none`:w,c===n?(r.setAttribute(`data-drop-target`,`true`),a=r):r.removeAttribute(`data-drop-target`)}};if(r===`row`)o(e.bodyRef?.current??null,`.draggable[data-type="row"]`,`Y`,i.height);else if(r===`column`){o(e.headerRef?.current??null,`.draggable[data-type="column"]`,`X`,i.width);let r=e.bodyRef?.current;if(r){let e=r.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=w}}}k(a,t,n,r)},[e.bodyRef,e.headerRef,k]),j=(0,c.useCallback)(()=>{let t=e.placeholderRef?.current;t&&(t.style.display=`none`);for(let t of[e.bodyRef?.current,e.headerRef?.current]){if(!t)continue;let e=t.querySelectorAll(`.draggable`);for(let t=0;t<e.length;t++){e[t].removeAttribute(`data-drop-target`);let n=e[t].firstElementChild;n&&(n.style.transition=`none`,n.style.transform=``)}}let n=e.bodyRef?.current;if(n){let e=n.querySelectorAll(`.td[data-col-index]`);for(let t=0;t<e.length;t++)e[t].style.transition=`none`,e[t].style.transform=``}},[e.bodyRef,e.headerRef,e.placeholderRef]),M=e=>{let t=e,n=!1;for(;t;){if(t.dataset?.dragHandle===`true`&&(n=!0),t.dataset?.contextid||t.dataset?.disabled===`true`)return null;if(t.dataset?.id)return{element:t,foundHandle:n};t=t.parentNode}return null},N=(0,c.useCallback)((t,r,i)=>{let a=M(t.target);if(!a)return;let{element:o,foundHandle:s}=a;if(!s&&o.querySelector(`[data-drag-handle]`))return;let c=o.dataset.id,u=+o.dataset.index,_=o.dataset.type,b=t.type===`touchstart`;m.current=_,g.current=u,v.current=null,E.current=!1,b&&o.dispatchEvent(new PointerEvent(`pointerdown`,{bubbles:!0,pointerType:`mouse`}));let x=_===`row`?e.bodyRef?.current?.scrollLeft??0:0,S=o.getBoundingClientRect();y.current={width:S.width,height:S.height};let w={x:r-S.left-x,y:i-S.top};h.current=w,C.current={x:r,y:i},d.current={x:r,y:i};let T={x:S.left+x,y:S.top};f.current=_===`row`?D():O();let k=e.bodyRef?.current;if(k){let e=k.getBoundingClientRect();p.current=e,l(e)}let A=e.tableRef?.current;A&&(A.style.touchAction=`none`);let j=e.cloneRef?.current;j&&(j.style.transform=`translate(${T.x}px, ${T.y}px)`);let N=e.tableRef?.current;N&&n({type:`setTableDimensions`,value:{height:N.offsetHeight,width:N.offsetWidth}}),n({type:`dragStart`,value:{rect:{draggedItemHeight:S.height,draggedItemWidth:S.width},dragged:{initial:w,translate:T,draggedID:c,isDragging:!0,sourceIndex:u},dragType:_}});let P=()=>{let t=e.cloneRef?.current,n=e.bodyRef?.current;if(!(!t||!n))if(_===`row`)t.scrollLeft=n.scrollLeft;else{let e=t.querySelector(`.clone-body`);e&&(e.scrollTop=n.scrollTop)}};P(),requestAnimationFrame(()=>{P(),requestAnimationFrame(P)})},[n,e,D,O,d,l]),P=(0,c.useCallback)((t,r,i,o,s)=>{let c=e.cloneRef?.current;c&&(c.style.visibility=`hidden`);let l=e.tableRef?.current;l&&(l.style.touchAction=``),(0,u.flushSync)(()=>{a&&t!==null&&r!==null&&(i===`row`||i===`column`)&&a({sourceIndex:t,targetIndex:r,dragType:i}),n({type:`dragEnd`,value:{targetIndex:r,sourceIndex:t}})}),j();let d=e.bodyRef?.current;d&&(d.scrollTop=o,d.scrollLeft=s,requestAnimationFrame(()=>{d.scrollTop=o,d.scrollLeft=s}))},[n,e.bodyRef,e.cloneRef,e.tableRef,j,a]),F=(0,c.useCallback)(()=>{if(E.current)return;E.current=!0,R(),setTimeout(()=>{z.current=!1},400);let t=v.current,n=g.current,r=m.current,i=e.bodyRef?.current,a=i?.scrollTop??0,o=i?.scrollLeft??0;f.current=null,p.current=null,s(),m.current=null,g.current=null,v.current=null;let c=e.cloneRef?.current,l=e.placeholderRef?.current;if(c&&l&&l.style.display!==`none`){let e=parseFloat(l.style.left)||0,i=parseFloat(l.style.top)||0;c.style.transition=`transform ${T}ms cubic-bezier(0.2, 0, 0, 1)`,c.style.transform=`translate(${e}px, ${i}px)`,setTimeout(()=>P(n,t,r,a,o),T)}else P(n,t,r,a,o)},[s,e.bodyRef,e.placeholderRef,e.cloneRef,P]),I=(0,c.useRef)(()=>{}),{touchStart:L,cancelLongPress:R,isTouchActiveRef:z}=b(e,N,F,(e,t)=>I.current(e,t)),B=(0,c.useCallback)(e=>{e.target!==e.currentTarget&&(z.current||N(e,e.clientX,e.clientY))},[N,z]),V=(0,c.useCallback)((t,n)=>{if(E.current)return;let i=h.current;C.current={x:t,y:n},d.current={x:t,y:n};let a=e.cloneRef?.current;if(a){a.style.transform=`translate(${t-i.x}px, ${n-i.y}px)`;let r=e.bodyRef?.current;if(r)if(m.current===`row`)a.scrollLeft=r.scrollLeft;else{let e=a.querySelector(`.clone-body`);e&&(e.scrollTop=r.scrollTop)}}let c=e.bodyRef?.current;if(!c)return;let l=p.current;l||(l=c.getBoundingClientRect(),p.current=l);let u=0,_=m.current||r;_===`row`?n<l.top+30?(o(-5,c,`vertical`),f.current=null):n>l.bottom-30?(o(5,c,`vertical`),f.current=null):s():t<l.left+30?(o(-5,c,`horizontal`),f.current=null):t>l.right-30?(o(5,c,`horizontal`),f.current=null):s();let y;_===`row`?(y=D(),f.current=y,y&&y.length>0&&(u=x(n-l.top+c.scrollTop,y))):(y=O(),f.current=y,y&&y.length>0&&(u=S(t,y))),u!==v.current&&(v.current=u,requestAnimationFrame(()=>A(g.current,u,_)))},[r,e.bodyRef,e.cloneRef,D,O,o,s,A,d]);I.current=V;let H=(0,c.useCallback)(()=>{R(),f.current=null,p.current=null;let t=e.cloneRef?.current;t&&(t.style.visibility=`hidden`);let r=e.tableRef?.current;r&&(r.style.touchAction=``),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),m.current=null,g.current=null,v.current=null},[n,s,e.cloneRef,e.tableRef,R]),U=(0,c.useCallback)(e=>{e.key===`Escape`&&H()},[H]);return(0,c.useLayoutEffect)(()=>{if(!t.isDragging){j();let t=e.cloneRef?.current;t&&(t.style.transition=``,t.style.transform=`translate(0px, 0px)`,t.style.visibility=``,t.scrollLeft=0)}},[t.isDragging,j,e.cloneRef]),(0,c.useEffect)(()=>{let t=e.bodyRef?.current;return t&&(t.style.touchAction=`none`),()=>{t&&(t.style.touchAction=``)}},[e.bodyRef]),(0,c.useEffect)(()=>{if(!t.isDragging)return;let e=e=>{V(e.clientX,e.clientY)},n=()=>{F()};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),window.addEventListener(`keydown`,U),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n),window.removeEventListener(`keydown`,U)}},[t.isDragging,V,F,U]),{dragStart:B,touchStart:L}},D={columnDragRange:{start:void 0,end:void 0},rowDragRange:{start:void 0,end:void 0},defaultSizing:50};function O(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??D};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 k={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:D,widths:[],columnIds:[]},A={position:`relative`,display:`flex`,flexFlow:`column`},j={position:`fixed`,pointerEvents:`none`,zIndex:3,top:0,left:0,display:`none`},M=(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),u=(0,c.useRef)(null);(0,c.useImperativeHandle)(o,()=>s.current,[]);let[f,h]=(0,c.useReducer)(O,k),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:u})},[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}=E(f.refs,f.dragged,h,f.dragType,f.options,i),y=(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}px`,width:f.dragType===`column`?`${f.rect.draggedItemWidth}px`:`${f.tableDimensions.width}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,d.jsx)(m.Provider,{value:g,children:(0,d.jsxs)(p,{className:f.dragged.isDragging?`is-dragging`:``,children:[(0,d.jsx)(`div`,{id:`portalroot`,style:{...y,visibility:f.dragged.isDragging?`visible`:`hidden`},ref:l,children:(0,d.jsx)(`div`,{style:{flexShrink:0,order:-1},children:f.clone})}),a&&(0,d.jsx)(`div`,{ref:u,style:j,children:a()}),(0,d.jsx)(`div`,{"data-contextid":`context`,ref:s,onMouseDown:_,onTouchStart:v,style:{...A,...n},className:`table ${t??``}`,children:e})]})})});M.displayName=`TableProvider`;var N=(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),u={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.useLayoutEffect)(()=>{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.useLayoutEffect)(()=>{a.current&&s({type:`setColumnIds`,value:Array.from(a.current.querySelectorAll(`.draggable`)).map(e=>e.getAttribute(`data-id`))})},[e,s,a]),(0,d.jsx)(`div`,{className:`header ${n??``}`,children:(0,d.jsx)(`div`,{className:`thead`,style:f,"data-droppableid":`header`,onScroll:l,ref:a,children:(0,d.jsx)(`div`,{style:u,className:`tr`,children:e})})})});N.displayName=`TableHeader`;var P=(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`?C(n,a.options.rowDragRange.start,a.options.rowDragRange.end):C(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]),u=(0,c.useRef)(null),f=(0,c.useRef)(!1);(0,c.useEffect)(()=>{u.current&&(f.current=!!u.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,d.jsx)(`div`,{className:`draggable`,"data-id":t,"data-index":n,"data-type":r,onPointerDown:m,"data-disabled":l?`true`:`false`,style:i,children:(0,d.jsx)(`div`,{ref:u,style:p,children:e})})});P.displayName=`Draggable`;var F=(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,d.jsx)(P,{...i,styles:s,type:`column`,children:(0,d.jsx)(`div`,{className:`th ${r??``}`,"data-width":t,style:{width:`100%`,...n},children:e})})});F.displayName=`ColumnCell`;var I=(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,d.jsxs)(c.default.Fragment,{children:[a.dragType===`column`&&a.refs.cloneRef?.current&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`body clone-body`,"data-droppableid":`body`,style:{overflow:`hidden`,flex:1},children:(0,d.jsx)(`div`,{className:`rbody`,style:{height:p,position:`relative`},children:s})}),a.refs.cloneRef.current),(0,d.jsx)(`div`,{className:`body ${n??``}`,style:L,children:(0,d.jsx)(`div`,{className:`ibody`,style:f,"data-droppableid":`body`,onScroll:l,ref:i,children:e})})]})}),L={display:`flex`,overflow:`hidden`,flex:1};I.displayName=`TableBody`;var R={display:`flex`,flex:`1 0 auto`,minHeight:`24px`},z=(0,c.memo)(({children:e,style:t,className:n,...r})=>{let i=(0,c.useMemo)(()=>t?{...R,...t}:R,[t]),a=(0,f.default)(`tr`,n);return(0,d.jsx)(P,{...r,type:`row`,children:(0,d.jsx)(`div`,{className:a,style:i,children:e})})});z.displayName=`BodyRow`;var B=(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]),u=(0,c.useMemo)(()=>r?!1:s===o.dragged.draggedID,[r,s,o.dragged.draggedID]),f=(0,c.useMemo)(()=>({display:`inline-flex`,opacity:u?0:1,width:`${l}px`,flex:`${l} 0 auto`,...t}),[u,l,t]);return(0,d.jsx)(`div`,{className:`td ${n??``}`,style:f,"data-col-index":a,children:e})});B.displayName=`RowCell`;var V=(0,c.memo)(({children:e,className:t,style:n})=>(0,d.jsx)(`div`,{"data-drag-handle":`true`,className:t,style:{cursor:`-webkit-grab`,display:`inline-flex`,alignItems:`center`,...n},children:e}));V.displayName=`DragHandle`,exports.BodyRow=z,exports.ColumnCell=F,exports.DragHandle=V,exports.RowCell=B,exports.TableBody=I,exports.TableContainer=M,exports.TableHeader=N,exports.useTable=h;
|
package/dist/index.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import e, { createContext as t, forwardRef as n, memo as r, useCallback as i, useContext as a, useEffect as o, useImperativeHandle as s,
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import e, { createContext as t, forwardRef as n, memo as r, useCallback as i, useContext as a, useEffect as o, useImperativeHandle as s, useLayoutEffect as c, useMemo as l, useReducer as u, useRef as d } from "react";
|
|
2
|
+
import f from "styled-components";
|
|
3
|
+
import { createPortal as p, flushSync as m } from "react-dom";
|
|
4
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
5
|
+
import _ from "classnames";
|
|
6
6
|
//#region src/Components/TableContainer/styles.tsx
|
|
7
|
-
var
|
|
7
|
+
var v = f.div`
|
|
8
8
|
height: 100%;
|
|
9
9
|
|
|
10
10
|
/* Structural elements: full reset */
|
|
@@ -22,37 +22,49 @@ var g = d.div`
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
&.is-dragging, &.is-dragging * {
|
|
25
|
+
cursor: -webkit-grabbing !important;
|
|
26
|
+
cursor: grabbing !important;
|
|
25
27
|
user-select: none !important;
|
|
26
28
|
-webkit-user-select: none !important;
|
|
29
|
+
-webkit-touch-callout: none !important;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
|
|
32
|
+
/* When a DragHandle exists, only the handle shows grab cursor */
|
|
33
|
+
&:not(.is-dragging) .draggable:has([data-drag-handle]) > div {
|
|
34
|
+
cursor: default !important;
|
|
35
|
+
}
|
|
36
|
+
&:not(.is-dragging) [data-drag-handle] {
|
|
37
|
+
cursor: -webkit-grab;
|
|
38
|
+
cursor: grab;
|
|
39
|
+
}
|
|
40
|
+
`, y = t(void 0), b = () => {
|
|
41
|
+
let e = a(y);
|
|
30
42
|
if (e === void 0) throw Error("useTable must be used within a TableProvider");
|
|
31
43
|
return e;
|
|
32
|
-
},
|
|
33
|
-
let t =
|
|
44
|
+
}, x = 30, S = (e) => {
|
|
45
|
+
let t = d(!1), n = d(!1), r = d(0), a = d(null), o = d({
|
|
34
46
|
x: 0,
|
|
35
47
|
y: 0
|
|
36
|
-
}), s =
|
|
48
|
+
}), s = d(null), c = i((e) => {
|
|
37
49
|
s.current = e;
|
|
38
50
|
}, []), l = i(() => {
|
|
39
51
|
n.current = !1, t.current = !1, a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
|
|
40
|
-
}, []),
|
|
41
|
-
let l = c === "vertical",
|
|
42
|
-
if (!
|
|
52
|
+
}, []), u = i((e, i, c) => {
|
|
53
|
+
let l = c === "vertical", d = l ? n : t;
|
|
54
|
+
if (!d.current) return;
|
|
43
55
|
let f = s.current;
|
|
44
56
|
if (f) {
|
|
45
57
|
let e = o.current;
|
|
46
58
|
if (l) {
|
|
47
|
-
let t = e.y < f.top +
|
|
59
|
+
let t = e.y < f.top + x, n = e.y > f.bottom - x;
|
|
48
60
|
if (!t && !n) {
|
|
49
|
-
|
|
61
|
+
d.current = !1;
|
|
50
62
|
return;
|
|
51
63
|
}
|
|
52
64
|
} else {
|
|
53
|
-
let t = e.x < f.left +
|
|
65
|
+
let t = e.x < f.left + x, n = e.x > f.right - x;
|
|
54
66
|
if (!t && !n) {
|
|
55
|
-
|
|
67
|
+
d.current = !1;
|
|
56
68
|
return;
|
|
57
69
|
}
|
|
58
70
|
}
|
|
@@ -61,16 +73,16 @@ var g = d.div`
|
|
|
61
73
|
l ? i.scrollTop += e : i.scrollLeft += e;
|
|
62
74
|
let m = l ? i.scrollTop : i.scrollLeft;
|
|
63
75
|
if (m >= p || m <= 0) {
|
|
64
|
-
|
|
76
|
+
d.current = !1;
|
|
65
77
|
return;
|
|
66
78
|
}
|
|
67
|
-
r.current += e / 1e3, a.current = requestAnimationFrame(() =>
|
|
79
|
+
r.current += e / 1e3, a.current = requestAnimationFrame(() => u(e + r.current, i, c));
|
|
68
80
|
}, []);
|
|
69
81
|
return {
|
|
70
82
|
startAutoScroll: i((e, i, o) => {
|
|
71
83
|
let s = o === "vertical" ? n : t;
|
|
72
|
-
s.current || (s.current = !0, r.current = 0, a.current = requestAnimationFrame(() =>
|
|
73
|
-
}, [
|
|
84
|
+
s.current || (s.current = !0, r.current = 0, a.current = requestAnimationFrame(() => u(e, i, o)));
|
|
85
|
+
}, [u]),
|
|
74
86
|
stopAutoScroll: l,
|
|
75
87
|
setContainerRect: c,
|
|
76
88
|
isAutoScrollingVertical: n,
|
|
@@ -83,27 +95,27 @@ var g = d.div`
|
|
|
83
95
|
e.bodyRef?.current && t.currentTarget && (e.bodyRef.current.scrollLeft = t.currentTarget.scrollLeft);
|
|
84
96
|
}, [e])
|
|
85
97
|
};
|
|
86
|
-
},
|
|
87
|
-
function
|
|
88
|
-
let a =
|
|
98
|
+
}, C = 300, w = 8;
|
|
99
|
+
function T(e, t, n, r) {
|
|
100
|
+
let a = d(null), o = d({
|
|
89
101
|
x: 0,
|
|
90
102
|
y: 0
|
|
91
|
-
}), s =
|
|
103
|
+
}), s = d(null), c = d(!1), l = d(null), u = i(() => {
|
|
92
104
|
a.current &&= (clearTimeout(a.current), null), s.current = null, l.current &&= (l.current(), null);
|
|
93
105
|
}, []);
|
|
94
106
|
return {
|
|
95
107
|
touchStart: i((i) => {
|
|
96
108
|
if (i.target === i.currentTarget) return;
|
|
97
|
-
let
|
|
98
|
-
for (;
|
|
99
|
-
if (
|
|
109
|
+
let d = i.target, f = !1;
|
|
110
|
+
for (; d && !(d.dataset?.contextid || d.dataset?.disabled === "true");) {
|
|
111
|
+
if (d.dataset?.id) {
|
|
100
112
|
f = !0;
|
|
101
113
|
break;
|
|
102
114
|
}
|
|
103
|
-
|
|
115
|
+
d = d.parentNode;
|
|
104
116
|
}
|
|
105
117
|
if (!f) return;
|
|
106
|
-
|
|
118
|
+
u(), c.current = !0, window.getSelection()?.removeAllRanges();
|
|
107
119
|
let p = i.touches[0];
|
|
108
120
|
o.current = {
|
|
109
121
|
x: p.clientX,
|
|
@@ -111,7 +123,9 @@ function C(e, t, n, r) {
|
|
|
111
123
|
}, s.current = i;
|
|
112
124
|
let m = e.tableRef?.current;
|
|
113
125
|
if (!m) return;
|
|
114
|
-
let h = !1, g = !1, _ = p.clientY, v = p.clientX, y = (
|
|
126
|
+
let h = !1, g = !1, _ = p.clientY, v = p.clientX, y = (e) => e.preventDefault();
|
|
127
|
+
document.addEventListener("selectstart", y);
|
|
128
|
+
let b = (t) => {
|
|
115
129
|
t.preventDefault();
|
|
116
130
|
let n = t.touches[0];
|
|
117
131
|
if (g) {
|
|
@@ -120,35 +134,35 @@ function C(e, t, n, r) {
|
|
|
120
134
|
} else if (h) r(n.clientX, n.clientY);
|
|
121
135
|
else {
|
|
122
136
|
let e = n.clientX - o.current.x, t = n.clientY - o.current.y;
|
|
123
|
-
(Math.abs(e) >
|
|
137
|
+
(Math.abs(e) > w || Math.abs(t) > w) && (a.current &&= (clearTimeout(a.current), null), s.current = null, g = !0, _ = n.clientY, v = n.clientX);
|
|
124
138
|
}
|
|
125
|
-
},
|
|
126
|
-
h ? (
|
|
139
|
+
}, x = () => {
|
|
140
|
+
h ? (S(), n()) : (u(), setTimeout(() => {
|
|
127
141
|
c.current = !1;
|
|
128
142
|
}, 400));
|
|
129
|
-
},
|
|
130
|
-
m.removeEventListener("touchmove",
|
|
143
|
+
}, S = () => {
|
|
144
|
+
m.removeEventListener("touchmove", b), m.removeEventListener("touchend", x), m.removeEventListener("touchcancel", x), document.removeEventListener("selectstart", y), l.current = null;
|
|
131
145
|
};
|
|
132
|
-
m.addEventListener("touchmove",
|
|
146
|
+
m.addEventListener("touchmove", b, { passive: !1 }), m.addEventListener("touchend", x, !1), m.addEventListener("touchcancel", x, !1), l.current = S, a.current = setTimeout(() => {
|
|
133
147
|
a.current = null, h = !0;
|
|
134
148
|
let e = s.current;
|
|
135
149
|
s.current = null, e && t(e, p.clientX, p.clientY);
|
|
136
|
-
},
|
|
150
|
+
}, C);
|
|
137
151
|
}, [
|
|
138
152
|
t,
|
|
139
153
|
n,
|
|
140
154
|
r,
|
|
141
|
-
|
|
155
|
+
u,
|
|
142
156
|
e.tableRef?.current,
|
|
143
157
|
e.bodyRef?.current
|
|
144
158
|
]),
|
|
145
|
-
cancelLongPress:
|
|
159
|
+
cancelLongPress: u,
|
|
146
160
|
isTouchActiveRef: c
|
|
147
161
|
};
|
|
148
162
|
}
|
|
149
163
|
//#endregion
|
|
150
164
|
//#region src/Components/utils.ts
|
|
151
|
-
var
|
|
165
|
+
var E = (e, t) => {
|
|
152
166
|
let n = e, r = 0, i = t.length - 1;
|
|
153
167
|
for (; r < i;) {
|
|
154
168
|
let e = Math.floor((r + i) / 2), a = t[e];
|
|
@@ -156,7 +170,7 @@ var w = (e, t) => {
|
|
|
156
170
|
n < a.itemTop ? i = e - 1 : r = e + 1;
|
|
157
171
|
}
|
|
158
172
|
return +t[r].index;
|
|
159
|
-
},
|
|
173
|
+
}, D = (e, t) => {
|
|
160
174
|
let n = e, r = 0, i = t.length - 1;
|
|
161
175
|
for (; r < i;) {
|
|
162
176
|
let e = Math.floor((r + i) / 2), a = t[e];
|
|
@@ -164,17 +178,17 @@ var w = (e, t) => {
|
|
|
164
178
|
n < a.itemLeft ? i = e - 1 : r = e + 1;
|
|
165
179
|
}
|
|
166
180
|
return +t[r].index;
|
|
167
|
-
},
|
|
168
|
-
let { startAutoScroll:
|
|
181
|
+
}, O = (e, t, n) => t !== void 0 && e < t || n !== void 0 && e > n, k = "transform 450ms cubic-bezier(0.2, 0, 0, 1)", A = 200, j = (e, t, n, r, a, s) => {
|
|
182
|
+
let { startAutoScroll: l, stopAutoScroll: u, setContainerRect: f, pointerRef: p } = S(e), h = d(null), g = d(null), _ = d(null), v = d({
|
|
169
183
|
x: 0,
|
|
170
184
|
y: 0
|
|
171
|
-
}),
|
|
185
|
+
}), y = d(null), b = d(null), x = d({
|
|
172
186
|
width: 0,
|
|
173
187
|
height: 0
|
|
174
|
-
}),
|
|
188
|
+
}), C = d({
|
|
175
189
|
x: 0,
|
|
176
190
|
y: 0
|
|
177
|
-
}),
|
|
191
|
+
}), w = d(!1), O = i(() => {
|
|
178
192
|
let t = e.bodyRef?.current;
|
|
179
193
|
if (!t) return null;
|
|
180
194
|
let n = t.scrollTop, r = t.getBoundingClientRect().top, i = t.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
|
|
@@ -191,7 +205,7 @@ var w = (e, t) => {
|
|
|
191
205
|
}
|
|
192
206
|
let { start: s, end: c } = a.rowDragRange;
|
|
193
207
|
return (s || c) && (o = o.filter((e) => (!s || +e.index >= s) && (!c || +e.index < c))), o;
|
|
194
|
-
}, [e.bodyRef, a.rowDragRange]),
|
|
208
|
+
}, [e.bodyRef, a.rowDragRange]), j = i(() => {
|
|
195
209
|
let t = e.headerRef?.current;
|
|
196
210
|
if (!t || !t.children[0]) return null;
|
|
197
211
|
let n = Array.from(t.children[0].children).map((e) => {
|
|
@@ -208,24 +222,24 @@ var w = (e, t) => {
|
|
|
208
222
|
let t = +e.index;
|
|
209
223
|
return (r === void 0 || t >= r) && (i === void 0 || t < i);
|
|
210
224
|
})), n;
|
|
211
|
-
}, [e.headerRef, a.columnDragRange]),
|
|
225
|
+
}, [e.headerRef, a.columnDragRange]), M = i((t, n, r, i) => {
|
|
212
226
|
let a = e.placeholderRef?.current;
|
|
213
227
|
if (!a || !t) {
|
|
214
228
|
a && (a.style.display = "none");
|
|
215
229
|
return;
|
|
216
230
|
}
|
|
217
|
-
let o =
|
|
231
|
+
let o = x.current, s = t.getBoundingClientRect(), c = e.tableRef?.current?.getBoundingClientRect(), l = (n ?? 0) < (r ?? 0);
|
|
218
232
|
a.style.display = "block", i === "row" ? (a.style.top = `${l ? s.top + s.height - o.height : s.top}px`, a.style.left = `${c?.left ?? s.left}px`, a.style.width = `${c?.width ?? s.width}px`, a.style.height = `${o.height}px`) : (a.style.top = `${c?.top ?? s.top}px`, a.style.left = `${l ? s.left + s.width - o.width : s.left}px`, a.style.width = `${o.width}px`, a.style.height = `${c?.height ?? s.height}px`);
|
|
219
|
-
}, [e.placeholderRef, e.tableRef]),
|
|
233
|
+
}, [e.placeholderRef, e.tableRef]), N = i((t, n, r) => {
|
|
220
234
|
if (t === null || n === null) return;
|
|
221
|
-
let i =
|
|
235
|
+
let i = x.current, a = null, o = (e, r, i, o) => {
|
|
222
236
|
if (!e) return;
|
|
223
237
|
let s = e.querySelectorAll(r);
|
|
224
238
|
for (let e = 0; e < s.length; e++) {
|
|
225
239
|
let r = s[e], c = +r.dataset.index, l = r.firstElementChild;
|
|
226
240
|
if (!l) continue;
|
|
227
241
|
let u = "";
|
|
228
|
-
c > t && c <= n ? u = `translate${i}(-${o}px)` : c < t && c >= n && (u = `translate${i}(${o}px)`), l.style.transform = u, l.style.transition = c === t ? "none" :
|
|
242
|
+
c > t && c <= n ? u = `translate${i}(-${o}px)` : c < t && c >= n && (u = `translate${i}(${o}px)`), l.style.transform = u, l.style.transition = c === t ? "none" : k, c === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
|
|
229
243
|
}
|
|
230
244
|
};
|
|
231
245
|
if (r === "row") o(e.bodyRef?.current ?? null, ".draggable[data-type=\"row\"]", "Y", i.height);
|
|
@@ -236,16 +250,16 @@ var w = (e, t) => {
|
|
|
236
250
|
let e = r.querySelectorAll(".td[data-col-index]");
|
|
237
251
|
for (let r = 0; r < e.length; r++) {
|
|
238
252
|
let a = e[r], o = +a.dataset.colIndex, s = "";
|
|
239
|
-
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 =
|
|
253
|
+
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 = k;
|
|
240
254
|
}
|
|
241
255
|
}
|
|
242
256
|
}
|
|
243
|
-
|
|
257
|
+
M(a, t, n, r);
|
|
244
258
|
}, [
|
|
245
259
|
e.bodyRef,
|
|
246
260
|
e.headerRef,
|
|
247
|
-
|
|
248
|
-
]),
|
|
261
|
+
M
|
|
262
|
+
]), P = i(() => {
|
|
249
263
|
let t = e.placeholderRef?.current;
|
|
250
264
|
t && (t.style.display = "none");
|
|
251
265
|
for (let t of [e.bodyRef?.current, e.headerRef?.current]) {
|
|
@@ -254,19 +268,19 @@ var w = (e, t) => {
|
|
|
254
268
|
for (let t = 0; t < e.length; t++) {
|
|
255
269
|
e[t].removeAttribute("data-drop-target");
|
|
256
270
|
let n = e[t].firstElementChild;
|
|
257
|
-
n && (n.style.
|
|
271
|
+
n && (n.style.transition = "none", n.style.transform = "");
|
|
258
272
|
}
|
|
259
273
|
}
|
|
260
274
|
let n = e.bodyRef?.current;
|
|
261
275
|
if (n) {
|
|
262
276
|
let e = n.querySelectorAll(".td[data-col-index]");
|
|
263
|
-
for (let t = 0; t < e.length; t++) e[t].style.
|
|
277
|
+
for (let t = 0; t < e.length; t++) e[t].style.transition = "none", e[t].style.transform = "";
|
|
264
278
|
}
|
|
265
279
|
}, [
|
|
266
280
|
e.bodyRef,
|
|
267
281
|
e.headerRef,
|
|
268
282
|
e.placeholderRef
|
|
269
|
-
]),
|
|
283
|
+
]), F = (e) => {
|
|
270
284
|
let t = e, n = !1;
|
|
271
285
|
for (; t;) {
|
|
272
286
|
if (t.dataset?.dragHandle === "true" && (n = !0), t.dataset?.contextid || t.dataset?.disabled === "true") return null;
|
|
@@ -277,46 +291,46 @@ var w = (e, t) => {
|
|
|
277
291
|
t = t.parentNode;
|
|
278
292
|
}
|
|
279
293
|
return null;
|
|
280
|
-
},
|
|
281
|
-
let a =
|
|
294
|
+
}, I = i((t, r, i) => {
|
|
295
|
+
let a = F(t.target);
|
|
282
296
|
if (!a) return;
|
|
283
297
|
let { element: o, foundHandle: s } = a;
|
|
284
298
|
if (!s && o.querySelector("[data-drag-handle]")) return;
|
|
285
|
-
let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type,
|
|
286
|
-
|
|
299
|
+
let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type, d = t.type === "touchstart";
|
|
300
|
+
_.current = u, y.current = l, b.current = null, w.current = !1, d && o.dispatchEvent(new PointerEvent("pointerdown", {
|
|
287
301
|
bubbles: !0,
|
|
288
302
|
pointerType: "mouse"
|
|
289
303
|
}));
|
|
290
|
-
let
|
|
291
|
-
|
|
292
|
-
width:
|
|
293
|
-
height:
|
|
304
|
+
let m = u === "row" ? e.bodyRef?.current?.scrollLeft ?? 0 : 0, S = o.getBoundingClientRect();
|
|
305
|
+
x.current = {
|
|
306
|
+
width: S.width,
|
|
307
|
+
height: S.height
|
|
294
308
|
};
|
|
295
309
|
let T = {
|
|
296
|
-
x: r -
|
|
297
|
-
y: i -
|
|
310
|
+
x: r - S.left - m,
|
|
311
|
+
y: i - S.top
|
|
298
312
|
};
|
|
299
|
-
|
|
313
|
+
v.current = T, C.current = {
|
|
300
314
|
x: r,
|
|
301
315
|
y: i
|
|
302
|
-
},
|
|
316
|
+
}, p.current = {
|
|
303
317
|
x: r,
|
|
304
318
|
y: i
|
|
305
319
|
};
|
|
306
|
-
let
|
|
307
|
-
x:
|
|
308
|
-
y:
|
|
320
|
+
let E = {
|
|
321
|
+
x: S.left + m,
|
|
322
|
+
y: S.top
|
|
309
323
|
};
|
|
310
|
-
|
|
311
|
-
let
|
|
312
|
-
if (
|
|
313
|
-
let e =
|
|
314
|
-
|
|
324
|
+
h.current = u === "row" ? O() : j();
|
|
325
|
+
let D = e.bodyRef?.current;
|
|
326
|
+
if (D) {
|
|
327
|
+
let e = D.getBoundingClientRect();
|
|
328
|
+
g.current = e, f(e);
|
|
315
329
|
}
|
|
316
330
|
let k = e.tableRef?.current;
|
|
317
331
|
k && (k.style.touchAction = "none");
|
|
318
332
|
let A = e.cloneRef?.current;
|
|
319
|
-
A && (A.style.transform = `translate(${
|
|
333
|
+
A && (A.style.transform = `translate(${E.x}px, ${E.y}px)`);
|
|
320
334
|
let M = e.tableRef?.current;
|
|
321
335
|
M && n({
|
|
322
336
|
type: "setTableDimensions",
|
|
@@ -328,12 +342,12 @@ var w = (e, t) => {
|
|
|
328
342
|
type: "dragStart",
|
|
329
343
|
value: {
|
|
330
344
|
rect: {
|
|
331
|
-
draggedItemHeight:
|
|
332
|
-
draggedItemWidth:
|
|
345
|
+
draggedItemHeight: S.height,
|
|
346
|
+
draggedItemWidth: S.width
|
|
333
347
|
},
|
|
334
348
|
dragged: {
|
|
335
349
|
initial: T,
|
|
336
|
-
translate:
|
|
350
|
+
translate: E,
|
|
337
351
|
draggedID: c,
|
|
338
352
|
isDragging: !0,
|
|
339
353
|
sourceIndex: l
|
|
@@ -355,48 +369,65 @@ var w = (e, t) => {
|
|
|
355
369
|
}, [
|
|
356
370
|
n,
|
|
357
371
|
e,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
]),
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
})), h.current = null, _.current = null, v.current = null;
|
|
372
|
+
O,
|
|
373
|
+
j,
|
|
374
|
+
p,
|
|
375
|
+
f
|
|
376
|
+
]), L = i((t, r, i, a, o) => {
|
|
377
|
+
let c = e.cloneRef?.current;
|
|
378
|
+
c && (c.style.visibility = "hidden");
|
|
379
|
+
let l = e.tableRef?.current;
|
|
380
|
+
l && (l.style.touchAction = ""), m(() => {
|
|
381
|
+
s && t !== null && r !== null && (i === "row" || i === "column") && s({
|
|
382
|
+
sourceIndex: t,
|
|
383
|
+
targetIndex: r,
|
|
384
|
+
dragType: i
|
|
385
|
+
}), n({
|
|
386
|
+
type: "dragEnd",
|
|
387
|
+
value: {
|
|
388
|
+
targetIndex: r,
|
|
389
|
+
sourceIndex: t
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}), P();
|
|
393
|
+
let u = e.bodyRef?.current;
|
|
394
|
+
u && (u.scrollTop = a, u.scrollLeft = o, requestAnimationFrame(() => {
|
|
395
|
+
u.scrollTop = a, u.scrollLeft = o;
|
|
396
|
+
}));
|
|
384
397
|
}, [
|
|
385
398
|
n,
|
|
386
|
-
l,
|
|
387
399
|
e.bodyRef,
|
|
388
400
|
e.cloneRef,
|
|
389
401
|
e.tableRef,
|
|
390
|
-
|
|
402
|
+
P,
|
|
391
403
|
s
|
|
392
|
-
]),
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
404
|
+
]), R = i(() => {
|
|
405
|
+
if (w.current) return;
|
|
406
|
+
w.current = !0, V(), setTimeout(() => {
|
|
407
|
+
H.current = !1;
|
|
408
|
+
}, 400);
|
|
409
|
+
let t = b.current, n = y.current, r = _.current, i = e.bodyRef?.current, a = i?.scrollTop ?? 0, o = i?.scrollLeft ?? 0;
|
|
410
|
+
h.current = null, g.current = null, u(), _.current = null, y.current = null, b.current = null;
|
|
411
|
+
let s = e.cloneRef?.current, c = e.placeholderRef?.current;
|
|
412
|
+
if (s && c && c.style.display !== "none") {
|
|
413
|
+
let e = parseFloat(c.style.left) || 0, i = parseFloat(c.style.top) || 0;
|
|
414
|
+
s.style.transition = `transform ${A}ms cubic-bezier(0.2, 0, 0, 1)`, s.style.transform = `translate(${e}px, ${i}px)`, setTimeout(() => L(n, t, r, a, o), A);
|
|
415
|
+
} else L(n, t, r, a, o);
|
|
416
|
+
}, [
|
|
417
|
+
u,
|
|
418
|
+
e.bodyRef,
|
|
419
|
+
e.placeholderRef,
|
|
420
|
+
e.cloneRef,
|
|
421
|
+
L
|
|
422
|
+
]), z = d(() => {}), { touchStart: B, cancelLongPress: V, isTouchActiveRef: H } = T(e, I, R, (e, t) => z.current(e, t)), U = i((e) => {
|
|
423
|
+
e.target !== e.currentTarget && (H.current || I(e, e.clientX, e.clientY));
|
|
424
|
+
}, [I, H]), W = i((t, n) => {
|
|
425
|
+
if (w.current) return;
|
|
426
|
+
let i = v.current;
|
|
427
|
+
C.current = {
|
|
397
428
|
x: t,
|
|
398
429
|
y: n
|
|
399
|
-
},
|
|
430
|
+
}, p.current = {
|
|
400
431
|
x: t,
|
|
401
432
|
y: n
|
|
402
433
|
};
|
|
@@ -404,7 +435,7 @@ var w = (e, t) => {
|
|
|
404
435
|
if (a) {
|
|
405
436
|
a.style.transform = `translate(${t - i.x}px, ${n - i.y}px)`;
|
|
406
437
|
let r = e.bodyRef?.current;
|
|
407
|
-
if (r) if (
|
|
438
|
+
if (r) if (_.current === "row") a.scrollLeft = r.scrollLeft;
|
|
408
439
|
else {
|
|
409
440
|
let e = a.querySelector(".clone-body");
|
|
410
441
|
e && (e.scrollTop = r.scrollTop);
|
|
@@ -412,47 +443,56 @@ var w = (e, t) => {
|
|
|
412
443
|
}
|
|
413
444
|
let o = e.bodyRef?.current;
|
|
414
445
|
if (!o) return;
|
|
415
|
-
let s =
|
|
416
|
-
s || (s = o.getBoundingClientRect(),
|
|
417
|
-
let
|
|
418
|
-
d === "row" ? n < s.top + 30 ? (
|
|
419
|
-
let
|
|
420
|
-
d === "row" ? (
|
|
446
|
+
let s = g.current;
|
|
447
|
+
s || (s = o.getBoundingClientRect(), g.current = s);
|
|
448
|
+
let c = 0, d = _.current || r;
|
|
449
|
+
d === "row" ? n < s.top + 30 ? (l(-5, o, "vertical"), h.current = null) : n > s.bottom - 30 ? (l(5, o, "vertical"), h.current = null) : u() : t < s.left + 30 ? (l(-5, o, "horizontal"), h.current = null) : t > s.right - 30 ? (l(5, o, "horizontal"), h.current = null) : u();
|
|
450
|
+
let f;
|
|
451
|
+
d === "row" ? (f = O(), h.current = f, f && f.length > 0 && (c = E(n - s.top + o.scrollTop, f))) : (f = j(), h.current = f, f && f.length > 0 && (c = D(t, f))), c !== b.current && (b.current = c, requestAnimationFrame(() => N(y.current, c, d)));
|
|
421
452
|
}, [
|
|
422
453
|
r,
|
|
423
454
|
e.bodyRef,
|
|
424
455
|
e.cloneRef,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
c,
|
|
456
|
+
O,
|
|
457
|
+
j,
|
|
428
458
|
l,
|
|
429
|
-
|
|
430
|
-
|
|
459
|
+
u,
|
|
460
|
+
N,
|
|
461
|
+
p
|
|
431
462
|
]);
|
|
432
|
-
|
|
433
|
-
let
|
|
434
|
-
|
|
463
|
+
z.current = W;
|
|
464
|
+
let G = i(() => {
|
|
465
|
+
V(), h.current = null, g.current = null;
|
|
435
466
|
let t = e.cloneRef?.current;
|
|
436
|
-
t && (t.style.
|
|
467
|
+
t && (t.style.visibility = "hidden");
|
|
437
468
|
let r = e.tableRef?.current;
|
|
438
|
-
r && (r.style.touchAction = ""),
|
|
469
|
+
r && (r.style.touchAction = ""), n({
|
|
439
470
|
type: "dragEnd",
|
|
440
471
|
value: {
|
|
441
472
|
targetIndex: null,
|
|
442
473
|
sourceIndex: null
|
|
443
474
|
}
|
|
444
|
-
}),
|
|
475
|
+
}), u(), _.current = null, y.current = null, b.current = null;
|
|
445
476
|
}, [
|
|
446
477
|
n,
|
|
447
|
-
|
|
478
|
+
u,
|
|
448
479
|
e.cloneRef,
|
|
449
480
|
e.tableRef,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
481
|
+
V
|
|
482
|
+
]), K = i((e) => {
|
|
483
|
+
e.key === "Escape" && G();
|
|
484
|
+
}, [G]);
|
|
485
|
+
return c(() => {
|
|
486
|
+
if (!t.isDragging) {
|
|
487
|
+
P();
|
|
488
|
+
let t = e.cloneRef?.current;
|
|
489
|
+
t && (t.style.transition = "", t.style.transform = "translate(0px, 0px)", t.style.visibility = "", t.scrollLeft = 0);
|
|
490
|
+
}
|
|
491
|
+
}, [
|
|
492
|
+
t.isDragging,
|
|
493
|
+
P,
|
|
494
|
+
e.cloneRef
|
|
495
|
+
]), o(() => {
|
|
456
496
|
let t = e.bodyRef?.current;
|
|
457
497
|
return t && (t.style.touchAction = "none"), () => {
|
|
458
498
|
t && (t.style.touchAction = "");
|
|
@@ -460,23 +500,23 @@ var w = (e, t) => {
|
|
|
460
500
|
}, [e.bodyRef]), o(() => {
|
|
461
501
|
if (!t.isDragging) return;
|
|
462
502
|
let e = (e) => {
|
|
463
|
-
|
|
503
|
+
W(e.clientX, e.clientY);
|
|
464
504
|
}, n = () => {
|
|
465
|
-
|
|
505
|
+
R();
|
|
466
506
|
};
|
|
467
|
-
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), window.addEventListener("keydown",
|
|
468
|
-
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), window.removeEventListener("keydown",
|
|
507
|
+
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), window.addEventListener("keydown", K), () => {
|
|
508
|
+
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), window.removeEventListener("keydown", K);
|
|
469
509
|
};
|
|
470
510
|
}, [
|
|
471
511
|
t.isDragging,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
512
|
+
W,
|
|
513
|
+
R,
|
|
514
|
+
K
|
|
475
515
|
]), {
|
|
476
|
-
dragStart:
|
|
477
|
-
touchStart:
|
|
516
|
+
dragStart: U,
|
|
517
|
+
touchStart: B
|
|
478
518
|
};
|
|
479
|
-
},
|
|
519
|
+
}, M = {
|
|
480
520
|
columnDragRange: {
|
|
481
521
|
start: void 0,
|
|
482
522
|
end: void 0
|
|
@@ -487,7 +527,7 @@ var w = (e, t) => {
|
|
|
487
527
|
},
|
|
488
528
|
defaultSizing: 50
|
|
489
529
|
};
|
|
490
|
-
function
|
|
530
|
+
function N(e, t) {
|
|
491
531
|
switch (t.type) {
|
|
492
532
|
case "setClone": return {
|
|
493
533
|
...e,
|
|
@@ -561,7 +601,7 @@ function A(e, t) {
|
|
|
561
601
|
};
|
|
562
602
|
case "setOptions": return {
|
|
563
603
|
...e,
|
|
564
|
-
options: t.value ??
|
|
604
|
+
options: t.value ?? M
|
|
565
605
|
};
|
|
566
606
|
case "dragStart": return {
|
|
567
607
|
...e,
|
|
@@ -598,7 +638,7 @@ function A(e, t) {
|
|
|
598
638
|
default: throw Error(`Unhandled action type: ${t.type}`);
|
|
599
639
|
}
|
|
600
640
|
}
|
|
601
|
-
var
|
|
641
|
+
var P = {
|
|
602
642
|
clone: null,
|
|
603
643
|
dragged: {
|
|
604
644
|
initial: {
|
|
@@ -631,58 +671,58 @@ var j = {
|
|
|
631
671
|
placeholderRef: null
|
|
632
672
|
},
|
|
633
673
|
bodyScrollBarWidth: 0,
|
|
634
|
-
options:
|
|
674
|
+
options: M,
|
|
635
675
|
widths: [],
|
|
636
676
|
columnIds: []
|
|
637
|
-
},
|
|
677
|
+
}, F = {
|
|
638
678
|
position: "relative",
|
|
639
679
|
display: "flex",
|
|
640
680
|
flexFlow: "column"
|
|
641
|
-
},
|
|
681
|
+
}, I = {
|
|
642
682
|
position: "fixed",
|
|
643
683
|
pointerEvents: "none",
|
|
644
684
|
zIndex: 3,
|
|
645
685
|
top: 0,
|
|
646
686
|
left: 0,
|
|
647
687
|
display: "none"
|
|
648
|
-
},
|
|
649
|
-
let
|
|
650
|
-
s(
|
|
651
|
-
let [
|
|
652
|
-
state:
|
|
688
|
+
}, L = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, c) => {
|
|
689
|
+
let f = d(null), p = d(null), m = d(null);
|
|
690
|
+
s(c, () => f.current, []);
|
|
691
|
+
let [_, b] = u(N, P), x = l(() => ({
|
|
692
|
+
state: _,
|
|
653
693
|
dispatch: b
|
|
654
|
-
}), [
|
|
694
|
+
}), [_]);
|
|
655
695
|
o(() => {
|
|
656
696
|
b({
|
|
657
697
|
type: "setTableRef",
|
|
658
|
-
value:
|
|
698
|
+
value: f
|
|
659
699
|
}), b({
|
|
660
700
|
type: "setCloneRef",
|
|
661
|
-
value:
|
|
701
|
+
value: p
|
|
662
702
|
}), b({
|
|
663
703
|
type: "setPlaceholderRef",
|
|
664
|
-
value:
|
|
704
|
+
value: m
|
|
665
705
|
});
|
|
666
|
-
}, [
|
|
706
|
+
}, [f]), o(() => {
|
|
667
707
|
let e = () => {
|
|
668
|
-
|
|
708
|
+
f.current && b({
|
|
669
709
|
type: "setTableDimensions",
|
|
670
710
|
value: {
|
|
671
|
-
height:
|
|
672
|
-
width:
|
|
711
|
+
height: f.current.offsetHeight,
|
|
712
|
+
width: f.current.offsetWidth
|
|
673
713
|
}
|
|
674
714
|
});
|
|
675
715
|
};
|
|
676
716
|
return e(), window.addEventListener("resize", e), () => {
|
|
677
717
|
window.removeEventListener("resize", e);
|
|
678
718
|
};
|
|
679
|
-
}, [
|
|
719
|
+
}, [f]), o(() => {
|
|
680
720
|
b({
|
|
681
721
|
type: "setOptions",
|
|
682
722
|
value: r
|
|
683
723
|
});
|
|
684
724
|
}, [r]);
|
|
685
|
-
let { dragStart: S, touchStart: C } =
|
|
725
|
+
let { dragStart: S, touchStart: C } = j(_.refs, _.dragged, b, _.dragType, _.options, i), w = l(() => ({
|
|
686
726
|
position: "fixed",
|
|
687
727
|
zIndex: "5",
|
|
688
728
|
pointerEvents: "none",
|
|
@@ -690,50 +730,50 @@ var j = {
|
|
|
690
730
|
left: 0,
|
|
691
731
|
display: "flex",
|
|
692
732
|
flexDirection: "column",
|
|
693
|
-
height:
|
|
694
|
-
width:
|
|
733
|
+
height: _.dragType === "row" ? _.rect.draggedItemHeight : `${_.tableDimensions.height}px`,
|
|
734
|
+
width: _.dragType === "column" ? `${_.rect.draggedItemWidth}px` : `${_.tableDimensions.width}px`,
|
|
695
735
|
overflow: "hidden",
|
|
696
|
-
boxShadow:
|
|
736
|
+
boxShadow: _.dragged.isDragging ? "0 0 10px 0 rgba(0, 0, 0, 0.1)" : "none"
|
|
697
737
|
}), [
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
738
|
+
_.dragType,
|
|
739
|
+
_.dragged.isDragging,
|
|
740
|
+
_.rect.draggedItemHeight,
|
|
741
|
+
_.rect.draggedItemWidth,
|
|
742
|
+
_.tableDimensions.height,
|
|
743
|
+
_.tableDimensions.width
|
|
704
744
|
]);
|
|
705
|
-
return /* @__PURE__ */
|
|
745
|
+
return /* @__PURE__ */ h(y.Provider, {
|
|
706
746
|
value: x,
|
|
707
|
-
children: /* @__PURE__ */
|
|
708
|
-
className:
|
|
747
|
+
children: /* @__PURE__ */ g(v, {
|
|
748
|
+
className: _.dragged.isDragging ? "is-dragging" : "",
|
|
709
749
|
children: [
|
|
710
|
-
/* @__PURE__ */
|
|
750
|
+
/* @__PURE__ */ h("div", {
|
|
711
751
|
id: "portalroot",
|
|
712
752
|
style: {
|
|
713
753
|
...w,
|
|
714
|
-
visibility:
|
|
754
|
+
visibility: _.dragged.isDragging ? "visible" : "hidden"
|
|
715
755
|
},
|
|
716
|
-
ref:
|
|
717
|
-
children: /* @__PURE__ */
|
|
756
|
+
ref: p,
|
|
757
|
+
children: /* @__PURE__ */ h("div", {
|
|
718
758
|
style: {
|
|
719
759
|
flexShrink: 0,
|
|
720
760
|
order: -1
|
|
721
761
|
},
|
|
722
|
-
children:
|
|
762
|
+
children: _.clone
|
|
723
763
|
})
|
|
724
764
|
}),
|
|
725
|
-
a && /* @__PURE__ */
|
|
726
|
-
ref:
|
|
727
|
-
style:
|
|
765
|
+
a && /* @__PURE__ */ h("div", {
|
|
766
|
+
ref: m,
|
|
767
|
+
style: I,
|
|
728
768
|
children: a()
|
|
729
769
|
}),
|
|
730
|
-
/* @__PURE__ */
|
|
770
|
+
/* @__PURE__ */ h("div", {
|
|
731
771
|
"data-contextid": "context",
|
|
732
|
-
ref:
|
|
772
|
+
ref: f,
|
|
733
773
|
onMouseDown: S,
|
|
734
774
|
onTouchStart: C,
|
|
735
775
|
style: {
|
|
736
|
-
...
|
|
776
|
+
...F,
|
|
737
777
|
...n
|
|
738
778
|
},
|
|
739
779
|
className: `table ${t ?? ""}`,
|
|
@@ -743,21 +783,21 @@ var j = {
|
|
|
743
783
|
})
|
|
744
784
|
});
|
|
745
785
|
});
|
|
746
|
-
|
|
786
|
+
L.displayName = "TableProvider";
|
|
747
787
|
//#endregion
|
|
748
788
|
//#region src/Components/TableHeader.tsx
|
|
749
|
-
var
|
|
750
|
-
let i =
|
|
789
|
+
var R = n(({ children: e, style: t, className: n }, r) => {
|
|
790
|
+
let i = d(null), a = r || i, { state: s, dispatch: u } = b();
|
|
751
791
|
o(() => {
|
|
752
|
-
|
|
792
|
+
u({
|
|
753
793
|
type: "setHeaderRef",
|
|
754
794
|
value: a
|
|
755
795
|
});
|
|
756
|
-
}, [
|
|
757
|
-
let { HeaderScrollHandle:
|
|
796
|
+
}, [u, a]);
|
|
797
|
+
let { HeaderScrollHandle: f } = S(s.refs), p = {
|
|
758
798
|
display: "flex",
|
|
759
799
|
flex: "1 0 auto"
|
|
760
|
-
}, m =
|
|
800
|
+
}, m = l(() => ({
|
|
761
801
|
overflow: "hidden",
|
|
762
802
|
display: "flex",
|
|
763
803
|
paddingRight: `${s.bodyScrollBarWidth}px`,
|
|
@@ -768,8 +808,8 @@ var F = n(({ children: e, style: t, className: n }, r) => {
|
|
|
768
808
|
s.dragged.isDragging,
|
|
769
809
|
t
|
|
770
810
|
]);
|
|
771
|
-
return
|
|
772
|
-
a.current &&
|
|
811
|
+
return c(() => {
|
|
812
|
+
a.current && u({
|
|
773
813
|
type: "setWidths",
|
|
774
814
|
value: Array.from(a.current.querySelectorAll(".th")).map((e) => {
|
|
775
815
|
let t = e.getAttribute("data-width");
|
|
@@ -778,26 +818,26 @@ var F = n(({ children: e, style: t, className: n }, r) => {
|
|
|
778
818
|
});
|
|
779
819
|
}, [
|
|
780
820
|
e,
|
|
781
|
-
|
|
821
|
+
u,
|
|
782
822
|
a
|
|
783
|
-
]),
|
|
784
|
-
a.current &&
|
|
823
|
+
]), c(() => {
|
|
824
|
+
a.current && u({
|
|
785
825
|
type: "setColumnIds",
|
|
786
826
|
value: Array.from(a.current.querySelectorAll(".draggable")).map((e) => e.getAttribute("data-id"))
|
|
787
827
|
});
|
|
788
828
|
}, [
|
|
789
829
|
e,
|
|
790
|
-
|
|
830
|
+
u,
|
|
791
831
|
a
|
|
792
|
-
]), /* @__PURE__ */
|
|
832
|
+
]), /* @__PURE__ */ h("div", {
|
|
793
833
|
className: `header ${n ?? ""}`,
|
|
794
|
-
children: /* @__PURE__ */
|
|
834
|
+
children: /* @__PURE__ */ h("div", {
|
|
795
835
|
className: "thead",
|
|
796
836
|
style: m,
|
|
797
837
|
"data-droppableid": "header",
|
|
798
|
-
onScroll:
|
|
838
|
+
onScroll: f,
|
|
799
839
|
ref: a,
|
|
800
|
-
children: /* @__PURE__ */
|
|
840
|
+
children: /* @__PURE__ */ h("div", {
|
|
801
841
|
style: p,
|
|
802
842
|
className: "tr",
|
|
803
843
|
children: e
|
|
@@ -805,67 +845,67 @@ var F = n(({ children: e, style: t, className: n }, r) => {
|
|
|
805
845
|
})
|
|
806
846
|
});
|
|
807
847
|
});
|
|
808
|
-
|
|
848
|
+
R.displayName = "TableHeader";
|
|
809
849
|
//#endregion
|
|
810
850
|
//#region src/Components/Draggable.tsx
|
|
811
|
-
var
|
|
812
|
-
let { state: s, dispatch:
|
|
851
|
+
var z = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
852
|
+
let { state: s, dispatch: c } = b(), u = l(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
|
|
813
853
|
n,
|
|
814
854
|
s.dragged.draggedID,
|
|
815
855
|
s.dragged.isDragging
|
|
816
|
-
]),
|
|
856
|
+
]), f = l(() => i === "row" ? O(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : O(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
|
|
817
857
|
r,
|
|
818
858
|
s.options.columnDragRange.end,
|
|
819
859
|
s.options.columnDragRange.start,
|
|
820
860
|
s.options.rowDragRange.end,
|
|
821
861
|
s.options.rowDragRange.start,
|
|
822
862
|
i
|
|
823
|
-
]),
|
|
863
|
+
]), p = d(null), m = d(!1);
|
|
824
864
|
o(() => {
|
|
825
|
-
|
|
865
|
+
p.current && (m.current = !!p.current.querySelector("[data-drag-handle]"));
|
|
826
866
|
});
|
|
827
|
-
let g =
|
|
828
|
-
cursor:
|
|
829
|
-
zIndex:
|
|
830
|
-
opacity:
|
|
831
|
-
pointerEvents:
|
|
867
|
+
let g = l(() => ({
|
|
868
|
+
cursor: u ? "-webkit-grabbing" : f || m.current ? "auto" : "-webkit-grab",
|
|
869
|
+
zIndex: u ? 2 : 1,
|
|
870
|
+
opacity: u ? 0 : 1,
|
|
871
|
+
pointerEvents: u ? "none" : "auto",
|
|
832
872
|
display: "flex"
|
|
833
|
-
}), [
|
|
834
|
-
n.pointerType !== "touch" && (
|
|
835
|
-
|
|
873
|
+
}), [f, u]), _ = (n) => {
|
|
874
|
+
n.pointerType !== "touch" && (f || requestAnimationFrame(() => {
|
|
875
|
+
c({
|
|
836
876
|
type: "setClone",
|
|
837
877
|
value: e.cloneElement(t)
|
|
838
878
|
});
|
|
839
879
|
}));
|
|
840
880
|
};
|
|
841
|
-
return /* @__PURE__ */
|
|
881
|
+
return /* @__PURE__ */ h("div", {
|
|
842
882
|
className: "draggable",
|
|
843
883
|
"data-id": n,
|
|
844
884
|
"data-index": r,
|
|
845
885
|
"data-type": i,
|
|
846
886
|
onPointerDown: _,
|
|
847
|
-
"data-disabled":
|
|
887
|
+
"data-disabled": f ? "true" : "false",
|
|
848
888
|
style: a,
|
|
849
|
-
children: /* @__PURE__ */
|
|
850
|
-
ref:
|
|
889
|
+
children: /* @__PURE__ */ h("div", {
|
|
890
|
+
ref: p,
|
|
851
891
|
style: g,
|
|
852
892
|
children: t
|
|
853
893
|
})
|
|
854
894
|
});
|
|
855
895
|
});
|
|
856
|
-
|
|
896
|
+
z.displayName = "Draggable";
|
|
857
897
|
//#endregion
|
|
858
898
|
//#region src/Components/ColumnCell.tsx
|
|
859
|
-
var
|
|
860
|
-
let { state: a } =
|
|
899
|
+
var B = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
900
|
+
let { state: a } = b(), o = l(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = l(() => ({
|
|
861
901
|
width: `${o}px`,
|
|
862
902
|
flex: `${o} 0 auto`
|
|
863
903
|
}), [o]);
|
|
864
|
-
return /* @__PURE__ */
|
|
904
|
+
return /* @__PURE__ */ h(z, {
|
|
865
905
|
...i,
|
|
866
906
|
styles: s,
|
|
867
907
|
type: "column",
|
|
868
|
-
children: /* @__PURE__ */
|
|
908
|
+
children: /* @__PURE__ */ h("div", {
|
|
869
909
|
className: `th ${r ?? ""}`,
|
|
870
910
|
"data-width": t,
|
|
871
911
|
style: {
|
|
@@ -876,14 +916,14 @@ var L = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
|
876
916
|
})
|
|
877
917
|
});
|
|
878
918
|
});
|
|
879
|
-
|
|
919
|
+
B.displayName = "ColumnCell";
|
|
880
920
|
//#endregion
|
|
881
921
|
//#region src/Components/TableBody.tsx
|
|
882
|
-
var
|
|
883
|
-
let a =
|
|
922
|
+
var V = n(({ children: t, style: n, className: r }, i) => {
|
|
923
|
+
let a = d(null);
|
|
884
924
|
s(i, () => a.current, []);
|
|
885
|
-
let { state:
|
|
886
|
-
if (
|
|
925
|
+
let { state: c, dispatch: u } = b(), f = l(() => {
|
|
926
|
+
if (c.dragged.sourceIndex === null) return null;
|
|
887
927
|
let n = (t) => {
|
|
888
928
|
let r = [];
|
|
889
929
|
return e.Children.forEach(t, (t) => {
|
|
@@ -891,124 +931,124 @@ var R = n(({ children: t, style: n, className: r }, i) => {
|
|
|
891
931
|
}), r;
|
|
892
932
|
};
|
|
893
933
|
return n(t).map((t) => {
|
|
894
|
-
let n = e.Children.toArray(t.props.children).filter((t) => e.isValidElement(t) && String(t.props.index) === String(
|
|
934
|
+
let n = e.Children.toArray(t.props.children).filter((t) => e.isValidElement(t) && String(t.props.index) === String(c.dragged.sourceIndex)).map((t) => e.cloneElement(t, { isClone: !0 }));
|
|
895
935
|
return e.cloneElement(t, {
|
|
896
936
|
...t.props,
|
|
897
937
|
children: n
|
|
898
938
|
});
|
|
899
939
|
});
|
|
900
|
-
}, [t,
|
|
940
|
+
}, [t, c.dragged.sourceIndex]);
|
|
901
941
|
o(() => {
|
|
902
|
-
|
|
942
|
+
u({
|
|
903
943
|
type: "setBodyRef",
|
|
904
944
|
value: a
|
|
905
945
|
});
|
|
906
|
-
}, [
|
|
907
|
-
let { BodyScrollHandle:
|
|
946
|
+
}, [u, a]);
|
|
947
|
+
let { BodyScrollHandle: m } = S(c.refs), _ = l(() => ({
|
|
908
948
|
overflowX: "auto",
|
|
909
949
|
overflowY: "auto",
|
|
910
950
|
flex: 1,
|
|
911
|
-
userSelect:
|
|
951
|
+
userSelect: c.dragged.isDragging ? "none" : "auto",
|
|
912
952
|
...n
|
|
913
|
-
}), [
|
|
953
|
+
}), [c.dragged.isDragging, n]);
|
|
914
954
|
o(() => {
|
|
915
955
|
if (a.current) {
|
|
916
956
|
let e = a.current.clientWidth;
|
|
917
|
-
|
|
957
|
+
u({
|
|
918
958
|
type: "setBodyScrollBarWidth",
|
|
919
959
|
value: a.current.offsetWidth - e
|
|
920
960
|
});
|
|
921
961
|
}
|
|
922
|
-
}, [
|
|
923
|
-
let
|
|
924
|
-
return /* @__PURE__ */
|
|
962
|
+
}, [u, a]);
|
|
963
|
+
let v = a.current?.scrollHeight ?? 0;
|
|
964
|
+
return /* @__PURE__ */ g(e.Fragment, { children: [c.dragType === "column" && c.refs.cloneRef?.current && p(/* @__PURE__ */ h("div", {
|
|
925
965
|
className: "body clone-body",
|
|
926
966
|
"data-droppableid": "body",
|
|
927
967
|
style: {
|
|
928
968
|
overflow: "hidden",
|
|
929
969
|
flex: 1
|
|
930
970
|
},
|
|
931
|
-
children: /* @__PURE__ */
|
|
971
|
+
children: /* @__PURE__ */ h("div", {
|
|
932
972
|
className: "rbody",
|
|
933
973
|
style: {
|
|
934
|
-
height:
|
|
974
|
+
height: v,
|
|
935
975
|
position: "relative"
|
|
936
976
|
},
|
|
937
|
-
children:
|
|
977
|
+
children: f
|
|
938
978
|
})
|
|
939
|
-
}),
|
|
979
|
+
}), c.refs.cloneRef.current), /* @__PURE__ */ h("div", {
|
|
940
980
|
className: `body ${r ?? ""}`,
|
|
941
|
-
style:
|
|
942
|
-
children: /* @__PURE__ */
|
|
981
|
+
style: H,
|
|
982
|
+
children: /* @__PURE__ */ h("div", {
|
|
943
983
|
className: "ibody",
|
|
944
984
|
style: _,
|
|
945
985
|
"data-droppableid": "body",
|
|
946
|
-
onScroll:
|
|
986
|
+
onScroll: m,
|
|
947
987
|
ref: a,
|
|
948
988
|
children: t
|
|
949
989
|
})
|
|
950
990
|
})] });
|
|
951
|
-
}),
|
|
991
|
+
}), H = {
|
|
952
992
|
display: "flex",
|
|
953
993
|
overflow: "hidden",
|
|
954
994
|
flex: 1
|
|
955
995
|
};
|
|
956
|
-
|
|
996
|
+
V.displayName = "TableBody";
|
|
957
997
|
//#endregion
|
|
958
998
|
//#region src/Components/BodyRow.tsx
|
|
959
|
-
var
|
|
999
|
+
var U = {
|
|
960
1000
|
display: "flex",
|
|
961
1001
|
flex: "1 0 auto",
|
|
962
1002
|
minHeight: "24px"
|
|
963
|
-
},
|
|
964
|
-
let i =
|
|
965
|
-
...
|
|
1003
|
+
}, W = r(({ children: e, style: t, className: n, ...r }) => {
|
|
1004
|
+
let i = l(() => t ? {
|
|
1005
|
+
...U,
|
|
966
1006
|
...t
|
|
967
|
-
} :
|
|
968
|
-
return /* @__PURE__ */
|
|
1007
|
+
} : U, [t]), a = _("tr", n);
|
|
1008
|
+
return /* @__PURE__ */ h(z, {
|
|
969
1009
|
...r,
|
|
970
1010
|
type: "row",
|
|
971
|
-
children: /* @__PURE__ */
|
|
1011
|
+
children: /* @__PURE__ */ h("div", {
|
|
972
1012
|
className: a,
|
|
973
1013
|
style: i,
|
|
974
1014
|
children: e
|
|
975
1015
|
})
|
|
976
1016
|
});
|
|
977
1017
|
});
|
|
978
|
-
|
|
1018
|
+
W.displayName = "BodyRow";
|
|
979
1019
|
//#endregion
|
|
980
1020
|
//#region src/Components/RowCell.tsx
|
|
981
|
-
var
|
|
982
|
-
let { index: a } = i, { state: o } =
|
|
1021
|
+
var G = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
|
|
1022
|
+
let { index: a } = i, { state: o } = b(), s = l(() => o.columnIds[a] ?? "", [o.columnIds, a]), c = l(() => o.widths[a] ?? o.options.defaultSizing, [
|
|
983
1023
|
o.widths,
|
|
984
1024
|
a,
|
|
985
1025
|
o.options.defaultSizing
|
|
986
|
-
]), u =
|
|
1026
|
+
]), u = l(() => r ? !1 : s === o.dragged.draggedID, [
|
|
987
1027
|
r,
|
|
988
1028
|
s,
|
|
989
1029
|
o.dragged.draggedID
|
|
990
|
-
]), d =
|
|
1030
|
+
]), d = l(() => ({
|
|
991
1031
|
display: "inline-flex",
|
|
992
1032
|
opacity: u ? 0 : 1,
|
|
993
|
-
width: `${
|
|
994
|
-
flex: `${
|
|
1033
|
+
width: `${c}px`,
|
|
1034
|
+
flex: `${c} 0 auto`,
|
|
995
1035
|
...t
|
|
996
1036
|
}), [
|
|
997
1037
|
u,
|
|
998
|
-
|
|
1038
|
+
c,
|
|
999
1039
|
t
|
|
1000
1040
|
]);
|
|
1001
|
-
return /* @__PURE__ */
|
|
1041
|
+
return /* @__PURE__ */ h("div", {
|
|
1002
1042
|
className: `td ${n ?? ""}`,
|
|
1003
1043
|
style: d,
|
|
1004
1044
|
"data-col-index": a,
|
|
1005
1045
|
children: e
|
|
1006
1046
|
});
|
|
1007
1047
|
});
|
|
1008
|
-
|
|
1048
|
+
G.displayName = "RowCell";
|
|
1009
1049
|
//#endregion
|
|
1010
1050
|
//#region src/Components/DragHandle.tsx
|
|
1011
|
-
var
|
|
1051
|
+
var K = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ h("div", {
|
|
1012
1052
|
"data-drag-handle": "true",
|
|
1013
1053
|
className: t,
|
|
1014
1054
|
style: {
|
|
@@ -1019,6 +1059,6 @@ var U = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div",
|
|
|
1019
1059
|
},
|
|
1020
1060
|
children: e
|
|
1021
1061
|
}));
|
|
1022
|
-
|
|
1062
|
+
K.displayName = "DragHandle";
|
|
1023
1063
|
//#endregion
|
|
1024
|
-
export {
|
|
1064
|
+
export { W as BodyRow, B as ColumnCell, K as DragHandle, G as RowCell, V as TableBody, L as TableContainer, R as TableHeader, b as useTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flexitablesort",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Sortable table with draggable rows and columns",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"type": "git",
|
|
43
43
|
"url": "git+https://github.com/samiodeh1337/sortable-table.git"
|
|
44
44
|
},
|
|
45
|
-
"homepage": "https://github.
|
|
45
|
+
"homepage": "https://samiodeh1337.github.io/sortable-table/",
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=17.0.0",
|
|
48
48
|
"react-dom": ">=17.0.0"
|