flexitablesort 1.1.1 → 1.1.3

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.
@@ -0,0 +1,82 @@
1
+ import { MutableRefObject } from 'react';
2
+ export interface DragEndResult {
3
+ sourceIndex: number;
4
+ targetIndex: number;
5
+ dragType: "row" | "column";
6
+ }
7
+ export interface DraggedState {
8
+ initial: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ translate: {
13
+ x: number;
14
+ y: number;
15
+ };
16
+ isDragging: boolean;
17
+ draggedID: string | null;
18
+ targetIndex: number | null;
19
+ sourceIndex: number | null;
20
+ }
21
+ export interface DragRange {
22
+ start?: number;
23
+ end?: number;
24
+ }
25
+ export interface Options {
26
+ columnDragRange: DragRange;
27
+ rowDragRange: DragRange;
28
+ defaultSizing: number;
29
+ }
30
+ export interface HookRefs {
31
+ tableRef: MutableRefObject<HTMLDivElement | null> | null;
32
+ bodyRef: MutableRefObject<HTMLDivElement | null> | null;
33
+ headerRef: MutableRefObject<HTMLDivElement | null> | null;
34
+ cloneRef: MutableRefObject<HTMLDivElement | null> | null;
35
+ placeholderRef: MutableRefObject<HTMLDivElement | null> | null;
36
+ }
37
+ export type DragAction = {
38
+ type: "dragStart";
39
+ value: {
40
+ rect: {
41
+ draggedItemHeight: number;
42
+ draggedItemWidth: number;
43
+ };
44
+ dragged: {
45
+ initial: {
46
+ x: number;
47
+ y: number;
48
+ };
49
+ translate: {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ draggedID: string | undefined;
54
+ isDragging: boolean;
55
+ sourceIndex: number;
56
+ };
57
+ dragType: string | undefined;
58
+ };
59
+ } | {
60
+ type: "dragEnd";
61
+ value: {
62
+ targetIndex: number | null;
63
+ sourceIndex: number | null;
64
+ };
65
+ };
66
+ export interface RowItem {
67
+ height: number;
68
+ itemTop: number;
69
+ itemBottom: number;
70
+ index: string;
71
+ }
72
+ export interface ColumnItem {
73
+ left: number;
74
+ width: number;
75
+ itemLeft: number;
76
+ itemRight: number;
77
+ index: string | undefined;
78
+ }
79
+ export interface Point {
80
+ x: number;
81
+ y: number;
82
+ }
@@ -6,8 +6,9 @@ interface Refs {
6
6
  declare const useAutoScroll: (refs: Refs) => {
7
7
  startAutoScroll: (speed: number, ref: HTMLDivElement, dir: "horizontal" | "vertical") => void;
8
8
  stopAutoScroll: () => void;
9
- isAutoScrollingHorizontal: import('react').RefObject<boolean>;
9
+ setContainerRect: (rect: DOMRect) => void;
10
10
  isAutoScrollingVertical: import('react').RefObject<boolean>;
11
+ isAutoScrollingHorizontal: import('react').RefObject<boolean>;
11
12
  pointerRef: import('react').RefObject<{
12
13
  x: number;
13
14
  y: number;
@@ -1,6 +1,6 @@
1
- declare const useDragContextEvents: (refs: any, dragged: any, dispatch: any, dragType: any, options: any, onDragEnd: any) => {
2
- dragStart: (e: any) => void;
3
- touchStart: (e: any) => void;
4
- onPointerDown: (e: any) => void;
1
+ import { HookRefs, DraggedState, DragAction, Options, DragEndResult } from './types';
2
+ declare const useDragContextEvents: (refs: HookRefs, dragged: DraggedState, dispatch: (action: DragAction) => void, dragType: string | null, options: Options, onDragEnd: ((result: DragEndResult) => void) | undefined) => {
3
+ dragStart: (e: React.MouseEvent<HTMLDivElement>) => void;
4
+ touchStart: (e: React.TouchEvent<HTMLDivElement>) => void;
5
5
  };
6
6
  export default useDragContextEvents;
@@ -0,0 +1,17 @@
1
+ import { HookRefs } from './types';
2
+ /**
3
+ * Mobile long-press-to-drag.
4
+ *
5
+ * touch-action:none is set permanently on the body element (by
6
+ * useDragContextEvents on mount) so Chrome Android respects it at
7
+ * pointerdown time. Since native scrolling is disabled on the body,
8
+ * this hook implements JS-based scrolling when the long press is cancelled.
9
+ *
10
+ * preventDefault() is still called on touchmove to stop any residual
11
+ * browser behavior during the 300ms detection window.
12
+ */
13
+ export default function useLongPress(refs: HookRefs, beginDrag: (e: React.TouchEvent<HTMLDivElement>, clientX: number, clientY: number) => void, dragEnd: () => void, onDragMove: (clientX: number, clientY: number) => void): {
14
+ touchStart: (e: React.TouchEvent<HTMLDivElement>) => void;
15
+ cancelLongPress: () => void;
16
+ isTouchActiveRef: import('react').RefObject<boolean>;
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=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;
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.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.cloneRef?.current;A&&(A.style.transform=`translate(${D.x}px, ${D.y}px)`),n({type:`dragStart`,value:{rect:{draggedItemHeight:w.height,draggedItemWidth:w.width},dragged:{initial:E,translate:D,draggedID:c,isDragging:!0,sourceIndex:_},dragType:b}});let j=()=>{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)}};j(),requestAnimationFrame(()=>{j(),requestAnimationFrame(j)})},[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),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,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),O(),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),p.current=null,h.current=null,g.current=null},[n,s,e.cloneRef,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-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:{...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;
package/dist/index.es.js CHANGED
@@ -26,23 +26,28 @@ var g = d.div`
26
26
  let t = u(!1), n = u(!1), r = u(0), a = u(null), o = u({
27
27
  x: 0,
28
28
  y: 0
29
- }), s = i(() => {
29
+ }), s = u(null), c = i((e) => {
30
+ s.current = e;
31
+ }, []), l = i(() => {
30
32
  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
+ }, []), d = i((e, i, c) => {
34
+ let l = c === "vertical", u = l ? n : t;
33
35
  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;
36
+ let f = s.current;
37
+ if (f) {
38
+ let e = o.current;
39
+ if (l) {
40
+ let t = e.y < f.top + y, n = e.y > f.bottom - y;
41
+ if (!t && !n) {
42
+ u.current = !1;
43
+ return;
44
+ }
45
+ } else {
46
+ let t = e.x < f.left + y, n = e.x > f.right - y;
47
+ if (!t && !n) {
48
+ u.current = !1;
49
+ return;
50
+ }
46
51
  }
47
52
  }
48
53
  let p = l ? i.scrollHeight - i.clientHeight : i.scrollWidth - i.clientWidth;
@@ -52,16 +57,17 @@ var g = d.div`
52
57
  u.current = !1;
53
58
  return;
54
59
  }
55
- r.current += e / 1e3, a.current = requestAnimationFrame(() => c(e + r.current, i, s));
60
+ r.current += e / 1e3, a.current = requestAnimationFrame(() => d(e + r.current, i, c));
56
61
  }, []);
57
62
  return {
58
- startAutoScroll: i((e, i, a) => {
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,
63
- isAutoScrollingHorizontal: t,
63
+ startAutoScroll: i((e, i, o) => {
64
+ let s = o === "vertical" ? n : t;
65
+ s.current || (s.current = !0, r.current = 0, a.current = requestAnimationFrame(() => d(e, i, o)));
66
+ }, [d]),
67
+ stopAutoScroll: l,
68
+ setContainerRect: c,
64
69
  isAutoScrollingVertical: n,
70
+ isAutoScrollingHorizontal: t,
65
71
  pointerRef: o,
66
72
  BodyScrollHandle: i((t) => {
67
73
  e.headerRef?.current && t.currentTarget && (e.headerRef.current.scrollLeft = t.currentTarget.scrollLeft);
@@ -70,7 +76,72 @@ var g = d.div`
70
76
  e.bodyRef?.current && t.currentTarget && (e.bodyRef.current.scrollLeft = t.currentTarget.scrollLeft);
71
77
  }, [e])
72
78
  };
73
- }, x = (e, t) => {
79
+ }, x = 300, S = 8;
80
+ function C(e, t, n, r) {
81
+ let a = u(null), o = u({
82
+ x: 0,
83
+ y: 0
84
+ }), s = u(null), c = u(!1), l = u(null), d = i(() => {
85
+ a.current &&= (clearTimeout(a.current), null), s.current = null, l.current &&= (l.current(), null);
86
+ }, []);
87
+ return {
88
+ touchStart: i((i) => {
89
+ if (i.target === i.currentTarget) return;
90
+ let u = i.target, f = !1;
91
+ for (; u && !(u.dataset?.contextid || u.dataset?.disabled === "true");) {
92
+ if (u.dataset?.id) {
93
+ f = !0;
94
+ break;
95
+ }
96
+ u = u.parentNode;
97
+ }
98
+ if (!f) return;
99
+ d(), c.current = !0;
100
+ let p = i.touches[0];
101
+ o.current = {
102
+ x: p.clientX,
103
+ y: p.clientY
104
+ }, s.current = i;
105
+ let m = e.tableRef?.current;
106
+ if (!m) return;
107
+ let h = !1, g = !1, _ = p.clientY, v = p.clientX, y = (t) => {
108
+ t.preventDefault();
109
+ let n = t.touches[0];
110
+ if (g) {
111
+ let t = e.bodyRef?.current;
112
+ t && (t.scrollTop -= n.clientY - _, t.scrollLeft -= n.clientX - v), _ = n.clientY, v = n.clientX;
113
+ } else if (h) r(n.clientX, n.clientY);
114
+ else {
115
+ let e = n.clientX - o.current.x, t = n.clientY - o.current.y;
116
+ (Math.abs(e) > S || Math.abs(t) > S) && (a.current &&= (clearTimeout(a.current), null), s.current = null, g = !0, _ = n.clientY, v = n.clientX);
117
+ }
118
+ }, b = () => {
119
+ h ? (C(), n()) : (d(), setTimeout(() => {
120
+ c.current = !1;
121
+ }, 400));
122
+ }, C = () => {
123
+ m.removeEventListener("touchmove", y), m.removeEventListener("touchend", b), m.removeEventListener("touchcancel", b), l.current = null;
124
+ };
125
+ m.addEventListener("touchmove", y, { passive: !1 }), m.addEventListener("touchend", b, !1), m.addEventListener("touchcancel", b, !1), l.current = C, a.current = setTimeout(() => {
126
+ a.current = null, h = !0;
127
+ let e = s.current;
128
+ s.current = null, e && t(e, p.clientX, p.clientY);
129
+ }, x);
130
+ }, [
131
+ t,
132
+ n,
133
+ r,
134
+ d,
135
+ e.tableRef?.current,
136
+ e.bodyRef?.current
137
+ ]),
138
+ cancelLongPress: d,
139
+ isTouchActiveRef: c
140
+ };
141
+ }
142
+ //#endregion
143
+ //#region src/Components/utils.ts
144
+ var w = (e, t) => {
74
145
  let n = e, r = 0, i = t.length - 1;
75
146
  for (; r < i;) {
76
147
  let e = Math.floor((r + i) / 2), a = t[e];
@@ -78,7 +149,7 @@ var g = d.div`
78
149
  n < a.itemTop ? i = e - 1 : r = e + 1;
79
150
  }
80
151
  return +t[r].index;
81
- }, S = (e, t) => {
152
+ }, T = (e, t) => {
82
153
  let n = e, r = 0, i = t.length - 1;
83
154
  for (; r < i;) {
84
155
  let e = Math.floor((r + i) / 2), a = t[e];
@@ -86,21 +157,18 @@ var g = d.div`
86
157
  n < a.itemLeft ? i = e - 1 : r = e + 1;
87
158
  }
88
159
  return +t[r].index;
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({
160
+ }, E = (e, t, n) => t !== void 0 && e < t || n !== void 0 && e > n, D = "all 450ms cubic-bezier(0.2, 0, 0, 1)", O = (e, t, n, r, a, s) => {
161
+ let { startAutoScroll: c, stopAutoScroll: l, setContainerRect: d, pointerRef: f } = b(e), p = u(null), m = u(null), h = u(null), g = u({
91
162
  x: 0,
92
163
  y: 0
93
- }), g = u(null), _ = u(null), v = u({
164
+ }), _ = u(null), v = u(null), y = u({
94
165
  width: 0,
95
166
  height: 0
96
- }), y = u({
97
- x: 0,
98
- y: 0
99
- }), C = u(null), D = u({
167
+ }), x = u({
100
168
  x: 0,
101
169
  y: 0
102
- }), O = u(null), k = u(!1), A = u(null), j = u(null), M = u(null), N = i(() => {
103
- let t = e.bodyRef.current;
170
+ }), S = i(() => {
171
+ let t = e.bodyRef?.current;
104
172
  if (!t) return null;
105
173
  let n = t.scrollTop, r = t.getBoundingClientRect().top, i = t.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
106
174
  for (let e = 0; e < i.length; e++) {
@@ -114,10 +182,10 @@ var g = d.div`
114
182
  index: t.dataset.index
115
183
  });
116
184
  }
117
- let s = a.rowDragRange.start, c = a.rowDragRange.end;
118
- return (s || c) && (o = o.filter((e) => (!s || e.index >= s) && (!c || e.index < c))), o;
119
- }, [e.bodyRef, a.rowDragRange]), P = i(() => {
120
- let t = e.headerRef.current;
185
+ let { start: s, end: c } = a.rowDragRange;
186
+ return (s || c) && (o = o.filter((e) => (!s || +e.index >= s) && (!c || +e.index < c))), o;
187
+ }, [e.bodyRef, a.rowDragRange]), E = i(() => {
188
+ let t = e.headerRef?.current;
121
189
  if (!t || !t.children[0]) return null;
122
190
  let n = Array.from(t.children[0].children).map((e) => {
123
191
  let t = e.getBoundingClientRect();
@@ -128,206 +196,160 @@ var g = d.div`
128
196
  itemRight: t.left + t.width,
129
197
  index: e.dataset.index
130
198
  };
131
- }).filter((e) => e.index !== void 0), r = a.columnDragRange?.start, i = a.columnDragRange?.end;
199
+ }).filter((e) => e.index !== void 0), { start: r, end: i } = a.columnDragRange ?? {};
132
200
  return (r !== void 0 || i !== void 0) && (n = n.filter((e) => {
133
201
  let t = +e.index;
134
202
  return (r === void 0 || t >= r) && (i === void 0 || t < i);
135
203
  })), n;
136
- }, [e.headerRef, a.columnDragRange]), F = i((t, n, r, i) => {
204
+ }, [e.headerRef, a.columnDragRange]), O = i((t, n, r, i) => {
137
205
  let a = e.placeholderRef?.current;
138
206
  if (!a || !t) {
139
207
  a && (a.style.display = "none");
140
208
  return;
141
209
  }
142
- let o = v.current, s = t.getBoundingClientRect();
143
- a.style.display = "block";
144
- let c = n < r;
145
- if (i === "row") {
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`;
148
- } else {
149
- let t = (e.tableRef?.current)?.getBoundingClientRect(), n = c ? s.left + s.width - o.width : s.left;
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`;
151
- }
152
- }, [e.placeholderRef, e.tableRef]), I = i((t, n, r) => {
210
+ let o = y.current, s = t.getBoundingClientRect(), c = e.tableRef?.current?.getBoundingClientRect(), l = (n ?? 0) < (r ?? 0);
211
+ 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`);
212
+ }, [e.placeholderRef, e.tableRef]), k = i((t, n, r) => {
153
213
  if (t === null || n === null) return;
154
- let i = v.current, a = null;
155
- if (r === "row") {
156
- let r = e.bodyRef.current;
157
- if (!r) return;
158
- let o = r.querySelectorAll(".draggable[data-type=\"row\"]");
159
- for (let e = 0; e < o.length; e++) {
160
- let r = o[e], s = +r.dataset.index, c = r.firstElementChild;
161
- if (!c) continue;
162
- let l = "";
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");
214
+ let i = y.current, a = null, o = (e, r, i, o) => {
215
+ if (!e) return;
216
+ let s = e.querySelectorAll(r);
217
+ for (let e = 0; e < s.length; e++) {
218
+ let r = s[e], c = +r.dataset.index, l = r.firstElementChild;
219
+ if (!l) continue;
220
+ let u = "";
221
+ 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" : D, c === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
164
222
  }
165
- } else if (r === "column") {
166
- let r = e.headerRef.current;
223
+ };
224
+ if (r === "row") o(e.bodyRef?.current ?? null, ".draggable[data-type=\"row\"]", "Y", i.height);
225
+ else if (r === "column") {
226
+ o(e.headerRef?.current ?? null, ".draggable[data-type=\"column\"]", "X", i.width);
227
+ let r = e.bodyRef?.current;
167
228
  if (r) {
168
- let e = r.querySelectorAll(".draggable[data-type=\"column\"]");
169
- for (let r = 0; r < e.length; r++) {
170
- let o = e[r], s = +o.dataset.index, c = o.firstElementChild;
171
- if (!c) continue;
172
- let l = "";
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");
174
- }
175
- }
176
- let o = e.bodyRef.current;
177
- if (o) {
178
- let e = o.querySelectorAll(".td[data-col-index]");
229
+ let e = r.querySelectorAll(".td[data-col-index]");
179
230
  for (let r = 0; r < e.length; r++) {
180
231
  let a = e[r], o = +a.dataset.colIndex, s = "";
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;
232
+ 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 = D;
182
233
  }
183
234
  }
184
235
  }
185
- F(a, t, n, r);
236
+ O(a, t, n, r);
186
237
  }, [
187
238
  e.bodyRef,
188
239
  e.headerRef,
189
- F
190
- ]), L = i(() => {
240
+ O
241
+ ]), A = i(() => {
191
242
  let t = e.placeholderRef?.current;
192
243
  t && (t.style.display = "none");
193
- let n = e.bodyRef.current;
194
- if (n) {
195
- let e = n.querySelectorAll(".draggable");
244
+ for (let t of [e.bodyRef?.current, e.headerRef?.current]) {
245
+ if (!t) continue;
246
+ let e = t.querySelectorAll(".draggable");
196
247
  for (let t = 0; t < e.length; t++) {
197
248
  e[t].removeAttribute("data-drop-target");
198
249
  let n = e[t].firstElementChild;
199
250
  n && (n.style.transform = "", n.style.transition = "");
200
251
  }
201
- let t = n.querySelectorAll(".td[data-col-index]");
202
- for (let e = 0; e < t.length; e++) t[e].style.transform = "", t[e].style.transition = "";
203
252
  }
204
- let r = e.headerRef.current;
205
- if (r) {
206
- let e = r.querySelectorAll(".draggable");
207
- for (let t = 0; t < e.length; t++) {
208
- e[t].removeAttribute("data-drop-target");
209
- let n = e[t].firstElementChild;
210
- n && (n.style.transform = "", n.style.transition = "");
211
- }
253
+ let n = e.bodyRef?.current;
254
+ if (n) {
255
+ let e = n.querySelectorAll(".td[data-col-index]");
256
+ for (let t = 0; t < e.length; t++) e[t].style.transform = "", e[t].style.transition = "";
212
257
  }
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", {
258
+ }, [
259
+ e.bodyRef,
260
+ e.headerRef,
261
+ e.placeholderRef
262
+ ]), j = (e) => {
263
+ let t = e, n = !1;
264
+ for (; t;) {
265
+ if (t.dataset?.dragHandle === "true" && (n = !0), t.dataset?.contextid || t.dataset?.disabled === "true") return null;
266
+ if (t.dataset?.id) return {
267
+ element: t,
268
+ foundHandle: n
269
+ };
270
+ t = t.parentNode;
271
+ }
272
+ return null;
273
+ }, M = i((t, r, i) => {
274
+ let a = j(t.target);
275
+ if (!a) return;
276
+ let { element: o, foundHandle: s } = a;
277
+ if (!s && o.querySelector("[data-drag-handle]")) return;
278
+ let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type, b = t.type === "touchstart";
279
+ h.current = u, _.current = l, v.current = null, b && o.dispatchEvent(new PointerEvent("pointerdown", {
225
280
  bubbles: !0,
226
281
  pointerType: "mouse"
227
282
  }));
228
- let b = l === "row" ? e.bodyRef.current.scrollLeft : 0, x = o.getBoundingClientRect();
229
- v.current = {
230
- width: x.width,
231
- height: x.height
283
+ let C = u === "row" ? e.bodyRef?.current?.scrollLeft ?? 0 : 0, w = o.getBoundingClientRect();
284
+ y.current = {
285
+ width: w.width,
286
+ height: w.height
232
287
  };
233
- let S = {
234
- x: r - x.left - b,
235
- y: i - x.top
288
+ let T = {
289
+ x: r - w.left - C,
290
+ y: i - w.top
236
291
  };
237
- h.current = S, y.current = {
292
+ g.current = T, x.current = {
238
293
  x: r,
239
294
  y: i
240
- }, d.current = {
295
+ }, f.current = {
241
296
  x: r,
242
297
  y: i
243
298
  };
244
- let C = {
245
- x: x.left + b,
246
- y: x.top
299
+ let D = {
300
+ x: w.left + C,
301
+ y: w.top
247
302
  };
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({
303
+ p.current = u === "row" ? S() : E();
304
+ let O = e.bodyRef?.current;
305
+ if (O) {
306
+ let e = O.getBoundingClientRect();
307
+ m.current = e, d(e);
308
+ }
309
+ let k = e.cloneRef?.current;
310
+ k && (k.style.transform = `translate(${D.x}px, ${D.y}px)`), n({
255
311
  type: "dragStart",
256
312
  value: {
257
313
  rect: {
258
- draggedItemHeight: x.height,
259
- draggedItemWidth: x.width
314
+ draggedItemHeight: w.height,
315
+ draggedItemWidth: w.width
260
316
  },
261
317
  dragged: {
262
- initial: S,
263
- translate: C,
264
- draggedID: s,
318
+ initial: T,
319
+ translate: D,
320
+ draggedID: c,
265
321
  isDragging: !0,
266
- sourceIndex: c
322
+ sourceIndex: l
267
323
  },
268
- dragType: l
324
+ dragType: u
269
325
  }
270
326
  });
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);
278
- }
327
+ let A = () => {
328
+ let t = e.cloneRef?.current, n = e.bodyRef?.current;
329
+ if (!(!t || !n)) if (u === "row") t.scrollLeft = n.scrollLeft;
330
+ else {
331
+ let e = t.querySelector(".clone-body");
332
+ e && (e.scrollTop = n.scrollTop);
279
333
  }
280
334
  };
281
- D(), requestAnimationFrame(() => {
282
- D(), requestAnimationFrame(D);
335
+ A(), requestAnimationFrame(() => {
336
+ A(), requestAnimationFrame(A);
283
337
  });
284
338
  }, [
285
- e.bodyRef,
286
- e.cloneRef,
287
- e.tableRef,
288
- d,
289
339
  n,
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;
340
+ e,
341
+ S,
342
+ E,
343
+ f,
344
+ d
345
+ ]), N = i(() => {
346
+ I(), setTimeout(() => {
347
+ L.current = !1;
324
348
  }, 400);
325
- let t = _.current, r = g.current, i = m.current;
326
- f.current = null, p.current = null;
327
- let a = e.cloneRef?.current;
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({
349
+ let t = v.current, r = _.current, i = h.current, a = e.bodyRef?.current, o = a?.scrollTop ?? 0, c = a?.scrollLeft ?? 0;
350
+ p.current = null, m.current = null;
351
+ let u = e.cloneRef?.current;
352
+ u && (u.style.transform = "translate(0px, 0px)", u.scrollLeft = 0), A(), s && r !== null && t !== null && (i === "row" || i === "column") && s({
331
353
  sourceIndex: r,
332
354
  targetIndex: t,
333
355
  dragType: i
@@ -337,152 +359,101 @@ var g = d.div`
337
359
  targetIndex: t,
338
360
  sourceIndex: r
339
361
  }
340
- }), l(), m.current = null, g.current = null, _.current = null;
362
+ }), l(), a && (a.scrollTop = o, a.scrollLeft = c, requestAnimationFrame(() => {
363
+ a.scrollTop = o, a.scrollLeft = c;
364
+ })), h.current = null, _.current = null, v.current = null;
341
365
  }, [
342
366
  n,
343
367
  l,
368
+ e.bodyRef,
344
369
  e.cloneRef,
345
- e.tableRef,
346
- L,
347
- B,
370
+ A,
348
371
  s
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);
372
+ ]), P = u(() => {}), { touchStart: F, cancelLongPress: I, isTouchActiveRef: L } = C(e, M, N, (e, t) => P.current(e, t)), R = i((e) => {
373
+ e.target !== e.currentTarget && (L.current || M(e, e.clientX, e.clientY));
374
+ }, [M, L]), z = i((t, n) => {
375
+ let i = g.current;
376
+ x.current = {
377
+ x: t,
378
+ y: n
379
+ }, f.current = {
380
+ x: t,
381
+ y: n
382
+ };
383
+ let a = e.cloneRef?.current;
384
+ if (a) {
385
+ a.style.transform = `translate(${t - i.x}px, ${n - i.y}px)`;
386
+ let r = e.bodyRef?.current;
387
+ if (r) if (h.current === "row") a.scrollLeft = r.scrollLeft;
388
+ else {
389
+ let e = a.querySelector(".clone-body");
390
+ e && (e.scrollTop = r.scrollTop);
359
391
  }
360
392
  }
361
393
  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
- }
394
+ if (!o) return;
395
+ let s = m.current;
396
+ s || (s = o.getBoundingClientRect(), m.current = s);
397
+ let u = 0, d = h.current || r;
398
+ d === "row" ? n < s.top + 30 ? (c(-5, o, "vertical"), p.current = null) : n > s.bottom - 30 ? (c(5, o, "vertical"), p.current = null) : l() : t < s.left + 30 ? (c(-5, o, "horizontal"), p.current = null) : t > s.right - 30 ? (c(5, o, "horizontal"), p.current = null) : l();
399
+ let y;
400
+ d === "row" ? (y = S(), p.current = y, y && y.length > 0 && (u = w(n - s.top + o.scrollTop, y))) : (y = E(), p.current = y, y && y.length > 0 && (u = T(t, y))), u !== v.current && (v.current = u, requestAnimationFrame(() => k(_.current, u, d)));
375
401
  }, [
376
- I,
377
- e.cloneRef,
402
+ r,
378
403
  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)`;
393
- let t = e.bodyRef.current;
394
- if (t) {
395
- if (m.current === "row") u.scrollLeft = t.scrollLeft;
396
- else if (m.current === "column") {
397
- let e = u.querySelector(".clone-body");
398
- e && (e.scrollTop = t.scrollTop);
399
- }
400
- }
401
- }
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();
410
- } else {
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();
413
- }
414
- D !== _.current && (_.current = D, requestAnimationFrame(() => {
415
- I(g.current, D, O);
416
- }));
417
- }, [
418
- d,
419
404
  e.cloneRef,
420
- e.bodyRef,
421
- r,
422
- N,
405
+ S,
406
+ E,
423
407
  c,
424
408
  l,
425
- P,
426
- I
427
- ]), K = i(() => {
428
- B(), f.current = null, p.current = null;
409
+ k,
410
+ f
411
+ ]);
412
+ P.current = z;
413
+ let B = i(() => {
414
+ I(), p.current = null, m.current = null;
429
415
  let t = e.cloneRef?.current;
430
- t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0);
431
- let r = e.tableRef?.current;
432
- r && (r.style.touchAction = ""), L(), n({
416
+ t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0), A(), n({
433
417
  type: "dragEnd",
434
418
  value: {
435
419
  targetIndex: null,
436
420
  sourceIndex: null
437
421
  }
438
- }), l(), m.current = null, g.current = null, _.current = null;
422
+ }), l(), h.current = null, _.current = null, v.current = null;
439
423
  }, [
440
424
  n,
441
425
  l,
442
426
  e.cloneRef,
443
- e.tableRef,
444
- L,
445
- B
446
- ]), q = i((e) => {
447
- e.key === "Escape" && K();
448
- }, [K]);
427
+ A,
428
+ I
429
+ ]), V = i((e) => {
430
+ e.key === "Escape" && B();
431
+ }, [B]);
449
432
  return o(() => {
450
- if (t.isDragging) {
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);
469
- };
470
- }
433
+ let t = e.bodyRef?.current;
434
+ return t && (t.style.touchAction = "none"), () => {
435
+ t && (t.style.touchAction = "");
436
+ };
437
+ }, [e.bodyRef]), o(() => {
438
+ if (!t.isDragging) return;
439
+ let e = (e) => {
440
+ z(e.clientX, e.clientY);
441
+ }, n = () => {
442
+ N();
443
+ };
444
+ return window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), window.addEventListener("keydown", V), () => {
445
+ window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), window.removeEventListener("keydown", V);
446
+ };
471
447
  }, [
472
448
  t.isDragging,
473
- G,
474
- U,
475
- K,
476
- q,
477
- W,
478
- e.bodyRef,
479
- e.tableRef
449
+ z,
450
+ N,
451
+ V
480
452
  ]), {
481
- dragStart: z,
482
- touchStart: V,
483
- onPointerDown: H
453
+ dragStart: R,
454
+ touchStart: F
484
455
  };
485
- }, O = {
456
+ }, k = {
486
457
  columnDragRange: {
487
458
  start: void 0,
488
459
  end: void 0
@@ -493,7 +464,7 @@ var g = d.div`
493
464
  },
494
465
  defaultSizing: 50
495
466
  };
496
- function k(e, t) {
467
+ function A(e, t) {
497
468
  switch (t.type) {
498
469
  case "setClone": return {
499
470
  ...e,
@@ -567,7 +538,7 @@ function k(e, t) {
567
538
  };
568
539
  case "setOptions": return {
569
540
  ...e,
570
- options: t.value ?? O
541
+ options: t.value ?? k
571
542
  };
572
543
  case "dragStart": return {
573
544
  ...e,
@@ -604,7 +575,7 @@ function k(e, t) {
604
575
  default: throw Error(`Unhandled action type: ${t.type}`);
605
576
  }
606
577
  }
607
- var A = {
578
+ var j = {
608
579
  clone: null,
609
580
  dragged: {
610
581
  initial: {
@@ -637,24 +608,24 @@ var A = {
637
608
  placeholderRef: null
638
609
  },
639
610
  bodyScrollBarWidth: 0,
640
- options: O,
611
+ options: k,
641
612
  widths: [],
642
613
  columnIds: []
643
- }, j = {
614
+ }, M = {
644
615
  position: "relative",
645
616
  display: "flex",
646
617
  flexFlow: "column"
647
- }, M = {
618
+ }, N = {
648
619
  position: "fixed",
649
620
  pointerEvents: "none",
650
621
  zIndex: 3,
651
622
  top: 0,
652
623
  left: 0,
653
624
  display: "none"
654
- }, N = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, d) => {
625
+ }, P = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, d) => {
655
626
  let m = u(null), h = u(null), v = u(null);
656
627
  s(d, () => m.current, []);
657
- let [y, b] = l(k, A), x = c(() => ({
628
+ let [y, b] = l(A, j), x = c(() => ({
658
629
  state: y,
659
630
  dispatch: b
660
631
  }), [y]);
@@ -688,7 +659,7 @@ var A = {
688
659
  value: r
689
660
  });
690
661
  }, [r]);
691
- let { dragStart: S, touchStart: C, onPointerDown: w } = D(y.refs, y.dragged, b, y.dragType, y.options, i), T = c(() => ({
662
+ let { dragStart: S, touchStart: C } = O(y.refs, y.dragged, b, y.dragType, y.options, i), w = c(() => ({
692
663
  position: "fixed",
693
664
  zIndex: "5",
694
665
  pointerEvents: "none",
@@ -716,7 +687,7 @@ var A = {
716
687
  /* @__PURE__ */ f("div", {
717
688
  id: "portalroot",
718
689
  style: {
719
- ...T,
690
+ ...w,
720
691
  visibility: y.dragged.isDragging ? "visible" : "hidden"
721
692
  },
722
693
  ref: h,
@@ -730,7 +701,7 @@ var A = {
730
701
  }),
731
702
  a && /* @__PURE__ */ f("div", {
732
703
  ref: v,
733
- style: M,
704
+ style: N,
734
705
  children: a()
735
706
  }),
736
707
  /* @__PURE__ */ f("div", {
@@ -738,9 +709,8 @@ var A = {
738
709
  ref: m,
739
710
  onMouseDown: S,
740
711
  onTouchStart: C,
741
- onPointerDown: w,
742
712
  style: {
743
- ...j,
713
+ ...M,
744
714
  ...n
745
715
  },
746
716
  className: `table ${t ?? ""}`,
@@ -750,10 +720,10 @@ var A = {
750
720
  })
751
721
  });
752
722
  });
753
- N.displayName = "TableProvider";
723
+ P.displayName = "TableProvider";
754
724
  //#endregion
755
725
  //#region src/Components/TableHeader.tsx
756
- var P = n(({ children: e, style: t, className: n }, r) => {
726
+ var F = n(({ children: e, style: t, className: n }, r) => {
757
727
  let i = u(null), a = r || i, { state: s, dispatch: l } = v();
758
728
  o(() => {
759
729
  l({
@@ -812,15 +782,15 @@ var P = n(({ children: e, style: t, className: n }, r) => {
812
782
  })
813
783
  });
814
784
  });
815
- P.displayName = "TableHeader";
785
+ F.displayName = "TableHeader";
816
786
  //#endregion
817
787
  //#region src/Components/Draggable.tsx
818
- var F = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
788
+ var I = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
819
789
  let { state: s, dispatch: l } = v(), d = c(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
820
790
  n,
821
791
  s.dragged.draggedID,
822
792
  s.dragged.isDragging
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), [
793
+ ]), p = c(() => i === "row" ? E(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : E(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
824
794
  r,
825
795
  s.options.columnDragRange.end,
826
796
  s.options.columnDragRange.start,
@@ -860,15 +830,15 @@ var F = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
860
830
  })
861
831
  });
862
832
  });
863
- F.displayName = "Draggable";
833
+ I.displayName = "Draggable";
864
834
  //#endregion
865
835
  //#region src/Components/ColumnCell.tsx
866
- var I = r(({ children: e, width: t, style: n, className: r, ...i }) => {
836
+ var L = r(({ children: e, width: t, style: n, className: r, ...i }) => {
867
837
  let { state: a } = v(), o = c(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = c(() => ({
868
838
  width: `${o}px`,
869
839
  flex: `${o} 0 auto`
870
840
  }), [o]);
871
- return /* @__PURE__ */ f(F, {
841
+ return /* @__PURE__ */ f(I, {
872
842
  ...i,
873
843
  styles: s,
874
844
  type: "column",
@@ -883,10 +853,10 @@ var I = r(({ children: e, width: t, style: n, className: r, ...i }) => {
883
853
  })
884
854
  });
885
855
  });
886
- I.displayName = "ColumnCell";
856
+ L.displayName = "ColumnCell";
887
857
  //#endregion
888
858
  //#region src/Components/TableBody.tsx
889
- var L = n(({ children: t, style: n, className: r }, i) => {
859
+ var R = n(({ children: t, style: n, className: r }, i) => {
890
860
  let a = u(null);
891
861
  s(i, () => a.current, []);
892
862
  let { state: l, dispatch: d } = v(), h = c(() => {
@@ -945,7 +915,7 @@ var L = n(({ children: t, style: n, className: r }, i) => {
945
915
  })
946
916
  }), l.refs.cloneRef.current), /* @__PURE__ */ f("div", {
947
917
  className: `body ${r ?? ""}`,
948
- style: R,
918
+ style: z,
949
919
  children: /* @__PURE__ */ f("div", {
950
920
  className: "ibody",
951
921
  style: _,
@@ -955,24 +925,24 @@ var L = n(({ children: t, style: n, className: r }, i) => {
955
925
  children: t
956
926
  })
957
927
  })] });
958
- }), R = {
928
+ }), z = {
959
929
  display: "flex",
960
930
  overflow: "hidden",
961
931
  flex: 1
962
932
  };
963
- L.displayName = "TableBody";
933
+ R.displayName = "TableBody";
964
934
  //#endregion
965
935
  //#region src/Components/BodyRow.tsx
966
- var z = {
936
+ var B = {
967
937
  display: "flex",
968
938
  flex: "1 0 auto",
969
939
  minHeight: "24px"
970
- }, B = r(({ children: e, style: t, className: n, ...r }) => {
940
+ }, V = r(({ children: e, style: t, className: n, ...r }) => {
971
941
  let i = c(() => t ? {
972
- ...z,
942
+ ...B,
973
943
  ...t
974
- } : z, [t]), a = h("tr", n);
975
- return /* @__PURE__ */ f(F, {
944
+ } : B, [t]), a = h("tr", n);
945
+ return /* @__PURE__ */ f(I, {
976
946
  ...r,
977
947
  type: "row",
978
948
  children: /* @__PURE__ */ f("div", {
@@ -982,10 +952,10 @@ var z = {
982
952
  })
983
953
  });
984
954
  });
985
- B.displayName = "BodyRow";
955
+ V.displayName = "BodyRow";
986
956
  //#endregion
987
957
  //#region src/Components/RowCell.tsx
988
- var V = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
958
+ var H = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
989
959
  let { index: a } = i, { state: o } = v(), s = c(() => o.columnIds[a] ?? "", [o.columnIds, a]), l = c(() => o.widths[a] ?? o.options.defaultSizing, [
990
960
  o.widths,
991
961
  a,
@@ -1012,10 +982,10 @@ var V = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
1012
982
  children: e
1013
983
  });
1014
984
  });
1015
- V.displayName = "RowCell";
985
+ H.displayName = "RowCell";
1016
986
  //#endregion
1017
987
  //#region src/Components/DragHandle.tsx
1018
- var H = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
988
+ var U = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
1019
989
  "data-drag-handle": "true",
1020
990
  className: t,
1021
991
  style: {
@@ -1026,6 +996,6 @@ var H = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div",
1026
996
  },
1027
997
  children: e
1028
998
  }));
1029
- H.displayName = "DragHandle";
999
+ U.displayName = "DragHandle";
1030
1000
  //#endregion
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 };
1001
+ export { V as BodyRow, L as ColumnCell, U as DragHandle, H as RowCell, R as TableBody, P as TableContainer, F as TableHeader, v as useTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexitablesort",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "Sortable table with draggable rows and columns",
6
6
  "main": "dist/index.cjs.js",