flexitablesort 1.1.2 → 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.
- package/dist/hooks/types.d.ts +82 -0
- package/dist/hooks/useAutoScroll.d.ts +2 -1
- package/dist/hooks/useDragContextEvents.d.ts +4 -3
- package/dist/hooks/useLongPress.d.ts +17 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +303 -332
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
4
5
|
};
|
|
5
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.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]),j=(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]),M=(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]),N=(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}}}M(a,t,n,r)},[e.bodyRef,e.headerRef,e.placeholderRef,M]),P=(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]),F=(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=A():u.current=j();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)})},[n,e,A,j]),I=(0,c.useCallback)(e=>{e.target!==e.currentTarget&&(D.current||F(e,e.clientX,e.clientY))},[F]),L=(0,c.useCallback)(()=>{w.current&&=(clearTimeout(w.current),null),E.current=null,window.removeEventListener(`touchmove`,O.current),window.removeEventListener(`touchend`,k.current)},[]),R=(0,c.useCallback)(t=>{if(t.target===t.currentTarget)return;let n=t.target,r=!1;for(;n&&!(n.dataset?.contextid||n.dataset?.disabled===`true`);){if(n.dataset?.id){r=!0;break}n=n.parentNode}if(!r)return;L(),D.current=!0;let i=t.touches[0];T.current={x:i.clientX,y:i.clientY},E.current=t;let a=!1,o=e=>{let t=e.touches[0],n=t.clientX-T.current.x,r=t.clientY-T.current.y;!a&&(Math.abs(n)>C||Math.abs(r)>C)?(L(),setTimeout(()=>{D.current=!1},400)):a&&e.preventDefault()},s=()=>{L(),setTimeout(()=>{D.current=!1},400)};O.current=o,k.current=s,window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s,!1),w.current=setTimeout(()=>{w.current=null,a=!0;let t=e.tableRef?.current;t&&(t.style.touchAction=`none`);let n=E.current;E.current=null,n&&F(n,i.clientX,i.clientY),window.removeEventListener(`touchend`,s);let r=()=>{window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,r),z()};window.addEventListener(`touchend`,r,!1)},S)},[F,L,e.tableRef]),z=(0,c.useCallback)(()=>{L(),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=``),P(),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,P,L,a]),B=(0,c.useCallback)(()=>{u.current=null,d.current=null;let t=m.current,n=h.current,r=f.current;t!==null&&n!==null&&N(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=A(),u.current=t),t&&t.length>0&&(i=v(e.y-n.top+o.scrollTop,t))}else{let t=u.current;t||(t=j(),u.current=t),t&&t.length>0&&(i=y(e.x,t))}i!==h.current&&(h.current=i,N(t,i,r))}},[N,e.cloneRef,e.bodyRef,A,j]),V=(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=A(),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=j(),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(()=>{N(m.current,D,O)}))},[r,e.bodyRef,e.cloneRef,A,j,o,s,N]),H=(0,c.useCallback)(()=>{L(),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=``),P(),n({type:`dragEnd`,value:{targetIndex:null,sourceIndex:null}}),s(),f.current=null,m.current=null,h.current=null},[n,s,e.cloneRef,e.tableRef,P,L]),U=(0,c.useCallback)(e=>{e.key===`Escape`&&H()},[H]);return(0,c.useEffect)(()=>{if(t.isDragging){let t=e.bodyRef.current,n=e.tableRef?.current,r=e=>{V(e)};return window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,z),window.addEventListener(`pointercancel`,z),window.addEventListener(`keydown`,U),t?.addEventListener(`scroll`,B,{passive:!0}),()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,z),window.removeEventListener(`pointercancel`,z),window.removeEventListener(`keydown`,U),t?.removeEventListener(`scroll`,B),n&&(n.style.touchAction=``)}}},[t.isDragging,V,z,H,U,B,e.bodyRef,e.tableRef]),{dragStart:I,touchStart:R}},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}=w(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:k,children:a()}),(0,u.jsx)(`div`,{"data-contextid":`context`,ref:s,onMouseDown:_,onTouchStart:v,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
|
-
}, []),
|
|
32
|
-
let l =
|
|
33
|
+
}, []), d = i((e, i, c) => {
|
|
34
|
+
let l = c === "vertical", u = l ? n : t;
|
|
33
35
|
if (!u.current) return;
|
|
34
|
-
let
|
|
35
|
-
if (
|
|
36
|
-
let e =
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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(() =>
|
|
60
|
+
r.current += e / 1e3, a.current = requestAnimationFrame(() => d(e + r.current, i, c));
|
|
56
61
|
}, []);
|
|
57
62
|
return {
|
|
58
|
-
startAutoScroll: i((e, i,
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
}, [
|
|
62
|
-
stopAutoScroll:
|
|
63
|
-
|
|
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 =
|
|
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
|
-
},
|
|
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
|
-
},
|
|
90
|
-
let { startAutoScroll: c, stopAutoScroll: l,
|
|
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
|
-
}),
|
|
164
|
+
}), _ = u(null), v = u(null), y = u({
|
|
94
165
|
width: 0,
|
|
95
166
|
height: 0
|
|
96
|
-
}),
|
|
97
|
-
x: 0,
|
|
98
|
-
y: 0
|
|
99
|
-
}), C = u(null), D = u({
|
|
167
|
+
}), x = u({
|
|
100
168
|
x: 0,
|
|
101
169
|
y: 0
|
|
102
|
-
}),
|
|
103
|
-
let t = e.bodyRef
|
|
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
|
|
118
|
-
return (s || c) && (o = o.filter((e) => (!s || e.index >= s) && (!c || e.index < c))), o;
|
|
119
|
-
}, [e.bodyRef, a.rowDragRange]),
|
|
120
|
-
let t = e.headerRef
|
|
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,221 +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),
|
|
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]),
|
|
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 =
|
|
143
|
-
a.style.display = "block";
|
|
144
|
-
|
|
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]), F = 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 =
|
|
155
|
-
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
|
|
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
|
-
}
|
|
166
|
-
|
|
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(".
|
|
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 =
|
|
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
|
-
|
|
236
|
+
O(a, t, n, r);
|
|
186
237
|
}, [
|
|
187
238
|
e.bodyRef,
|
|
188
239
|
e.headerRef,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
]), I = i(() => {
|
|
240
|
+
O
|
|
241
|
+
]), A = i(() => {
|
|
192
242
|
let t = e.placeholderRef?.current;
|
|
193
243
|
t && (t.style.display = "none");
|
|
194
|
-
let
|
|
195
|
-
|
|
196
|
-
let e =
|
|
244
|
+
for (let t of [e.bodyRef?.current, e.headerRef?.current]) {
|
|
245
|
+
if (!t) continue;
|
|
246
|
+
let e = t.querySelectorAll(".draggable");
|
|
197
247
|
for (let t = 0; t < e.length; t++) {
|
|
198
248
|
e[t].removeAttribute("data-drop-target");
|
|
199
249
|
let n = e[t].firstElementChild;
|
|
200
250
|
n && (n.style.transform = "", n.style.transition = "");
|
|
201
251
|
}
|
|
202
|
-
let t = n.querySelectorAll(".td[data-col-index]");
|
|
203
|
-
for (let e = 0; e < t.length; e++) t[e].style.transform = "", t[e].style.transition = "";
|
|
204
252
|
}
|
|
205
|
-
let
|
|
206
|
-
if (
|
|
207
|
-
let e =
|
|
208
|
-
for (let t = 0; t < e.length; t++)
|
|
209
|
-
e[t].removeAttribute("data-drop-target");
|
|
210
|
-
let n = e[t].firstElementChild;
|
|
211
|
-
n && (n.style.transform = "", n.style.transition = "");
|
|
212
|
-
}
|
|
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 = "";
|
|
213
257
|
}
|
|
214
|
-
}, [
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return null;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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", {
|
|
226
280
|
bubbles: !0,
|
|
227
281
|
pointerType: "mouse"
|
|
228
282
|
}));
|
|
229
|
-
let
|
|
230
|
-
|
|
231
|
-
width:
|
|
232
|
-
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
|
|
233
287
|
};
|
|
234
|
-
let
|
|
235
|
-
x: r -
|
|
236
|
-
y: i -
|
|
288
|
+
let T = {
|
|
289
|
+
x: r - w.left - C,
|
|
290
|
+
y: i - w.top
|
|
237
291
|
};
|
|
238
|
-
|
|
292
|
+
g.current = T, x.current = {
|
|
239
293
|
x: r,
|
|
240
294
|
y: i
|
|
241
|
-
},
|
|
295
|
+
}, f.current = {
|
|
242
296
|
x: r,
|
|
243
297
|
y: i
|
|
244
298
|
};
|
|
245
|
-
let
|
|
246
|
-
x:
|
|
247
|
-
y:
|
|
299
|
+
let D = {
|
|
300
|
+
x: w.left + C,
|
|
301
|
+
y: w.top
|
|
248
302
|
};
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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({
|
|
256
311
|
type: "dragStart",
|
|
257
312
|
value: {
|
|
258
313
|
rect: {
|
|
259
|
-
draggedItemHeight:
|
|
260
|
-
draggedItemWidth:
|
|
314
|
+
draggedItemHeight: w.height,
|
|
315
|
+
draggedItemWidth: w.width
|
|
261
316
|
},
|
|
262
317
|
dragged: {
|
|
263
|
-
initial:
|
|
264
|
-
translate:
|
|
265
|
-
draggedID:
|
|
318
|
+
initial: T,
|
|
319
|
+
translate: D,
|
|
320
|
+
draggedID: c,
|
|
266
321
|
isDragging: !0,
|
|
267
|
-
sourceIndex:
|
|
322
|
+
sourceIndex: l
|
|
268
323
|
},
|
|
269
|
-
dragType:
|
|
324
|
+
dragType: u
|
|
270
325
|
}
|
|
271
326
|
});
|
|
272
|
-
let
|
|
273
|
-
let t = e.cloneRef?.current, n = e.bodyRef
|
|
274
|
-
if (t
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
e && (e.scrollTop = n.scrollTop);
|
|
279
|
-
}
|
|
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);
|
|
280
333
|
}
|
|
281
334
|
};
|
|
282
|
-
|
|
283
|
-
|
|
335
|
+
A(), requestAnimationFrame(() => {
|
|
336
|
+
A(), requestAnimationFrame(A);
|
|
284
337
|
});
|
|
285
338
|
}, [
|
|
286
339
|
n,
|
|
287
340
|
e,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (t.target === t.currentTarget) return;
|
|
296
|
-
let n = t.target, r = !1;
|
|
297
|
-
for (; n && !(n.dataset?.contextid || n.dataset?.disabled === "true");) {
|
|
298
|
-
if (n.dataset?.id) {
|
|
299
|
-
r = !0;
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
n = n.parentNode;
|
|
303
|
-
}
|
|
304
|
-
if (!r) return;
|
|
305
|
-
z(), k.current = !0;
|
|
306
|
-
let i = t.touches[0];
|
|
307
|
-
D.current = {
|
|
308
|
-
x: i.clientX,
|
|
309
|
-
y: i.clientY
|
|
310
|
-
}, O.current = t;
|
|
311
|
-
let a = !1, o = (e) => {
|
|
312
|
-
let t = e.touches[0], n = t.clientX - D.current.x, r = t.clientY - D.current.y;
|
|
313
|
-
!a && (Math.abs(n) > E || Math.abs(r) > E) ? (z(), setTimeout(() => {
|
|
314
|
-
k.current = !1;
|
|
315
|
-
}, 400)) : a && e.preventDefault();
|
|
316
|
-
}, s = () => {
|
|
317
|
-
z(), setTimeout(() => {
|
|
318
|
-
k.current = !1;
|
|
319
|
-
}, 400);
|
|
320
|
-
};
|
|
321
|
-
A.current = o, j.current = s, window.addEventListener("touchmove", o, { passive: !1 }), window.addEventListener("touchend", s, !1), C.current = setTimeout(() => {
|
|
322
|
-
C.current = null, a = !0;
|
|
323
|
-
let t = e.tableRef?.current;
|
|
324
|
-
t && (t.style.touchAction = "none");
|
|
325
|
-
let n = O.current;
|
|
326
|
-
O.current = null, n && L(n, i.clientX, i.clientY), window.removeEventListener("touchend", s);
|
|
327
|
-
let r = () => {
|
|
328
|
-
window.removeEventListener("touchmove", o), window.removeEventListener("touchend", r), V();
|
|
329
|
-
};
|
|
330
|
-
window.addEventListener("touchend", r, !1);
|
|
331
|
-
}, T);
|
|
332
|
-
}, [
|
|
333
|
-
L,
|
|
334
|
-
z,
|
|
335
|
-
e.tableRef
|
|
336
|
-
]), V = i(() => {
|
|
337
|
-
z(), setTimeout(() => {
|
|
338
|
-
k.current = !1;
|
|
341
|
+
S,
|
|
342
|
+
E,
|
|
343
|
+
f,
|
|
344
|
+
d
|
|
345
|
+
]), N = i(() => {
|
|
346
|
+
I(), setTimeout(() => {
|
|
347
|
+
L.current = !1;
|
|
339
348
|
}, 400);
|
|
340
|
-
let t =
|
|
341
|
-
|
|
342
|
-
let
|
|
343
|
-
|
|
344
|
-
let o = e.tableRef?.current;
|
|
345
|
-
o && (o.style.touchAction = ""), I(), 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({
|
|
346
353
|
sourceIndex: r,
|
|
347
354
|
targetIndex: t,
|
|
348
355
|
dragType: i
|
|
@@ -352,137 +359,101 @@ var g = d.div`
|
|
|
352
359
|
targetIndex: t,
|
|
353
360
|
sourceIndex: r
|
|
354
361
|
}
|
|
355
|
-
}), l(),
|
|
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;
|
|
356
365
|
}, [
|
|
357
366
|
n,
|
|
358
367
|
l,
|
|
368
|
+
e.bodyRef,
|
|
359
369
|
e.cloneRef,
|
|
360
|
-
|
|
361
|
-
I,
|
|
362
|
-
z,
|
|
370
|
+
A,
|
|
363
371
|
s
|
|
364
|
-
]),
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
let o = e.bodyRef?.current;
|
|
377
|
-
if (o && r) {
|
|
378
|
-
let e = y.current, n = p.current;
|
|
379
|
-
n || (n = o.getBoundingClientRect(), p.current = n);
|
|
380
|
-
let i = 0;
|
|
381
|
-
if (r === "row") {
|
|
382
|
-
let t = f.current;
|
|
383
|
-
t || (t = M(), f.current = t), t && t.length > 0 && (i = x(e.y - n.top + o.scrollTop, t));
|
|
384
|
-
} else {
|
|
385
|
-
let t = f.current;
|
|
386
|
-
t || (t = N(), f.current = t), t && t.length > 0 && (i = S(e.x, t));
|
|
387
|
-
}
|
|
388
|
-
i !== _.current && (_.current = i, F(t, i, r));
|
|
389
|
-
}
|
|
390
|
-
}, [
|
|
391
|
-
F,
|
|
392
|
-
e.cloneRef,
|
|
393
|
-
e.bodyRef,
|
|
394
|
-
M,
|
|
395
|
-
N
|
|
396
|
-
]), U = i((t) => {
|
|
397
|
-
let n = t.clientX ?? 0, i = t.clientY ?? 0, a = h.current, o = n - a.x, s = i - a.y;
|
|
398
|
-
y.current = {
|
|
399
|
-
x: n,
|
|
400
|
-
y: i
|
|
401
|
-
}, d.current = {
|
|
402
|
-
x: n,
|
|
403
|
-
y: i
|
|
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
|
|
404
382
|
};
|
|
405
|
-
let
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
let
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
e && (e.scrollTop = t.scrollTop);
|
|
414
|
-
}
|
|
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);
|
|
415
391
|
}
|
|
416
392
|
}
|
|
417
|
-
let
|
|
418
|
-
if (!
|
|
419
|
-
let
|
|
420
|
-
|
|
421
|
-
let
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
} else {
|
|
426
|
-
let e = f.current;
|
|
427
|
-
e || (e = N(), 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();
|
|
428
|
-
}
|
|
429
|
-
D !== _.current && (_.current = D, requestAnimationFrame(() => {
|
|
430
|
-
F(g.current, D, O);
|
|
431
|
-
}));
|
|
393
|
+
let o = e.bodyRef?.current;
|
|
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)));
|
|
432
401
|
}, [
|
|
433
402
|
r,
|
|
434
403
|
e.bodyRef,
|
|
435
404
|
e.cloneRef,
|
|
436
|
-
|
|
437
|
-
|
|
405
|
+
S,
|
|
406
|
+
E,
|
|
438
407
|
c,
|
|
439
408
|
l,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
409
|
+
k,
|
|
410
|
+
f
|
|
411
|
+
]);
|
|
412
|
+
P.current = z;
|
|
413
|
+
let B = i(() => {
|
|
414
|
+
I(), p.current = null, m.current = null;
|
|
443
415
|
let t = e.cloneRef?.current;
|
|
444
|
-
t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0)
|
|
445
|
-
let r = e.tableRef?.current;
|
|
446
|
-
r && (r.style.touchAction = ""), I(), n({
|
|
416
|
+
t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0), A(), n({
|
|
447
417
|
type: "dragEnd",
|
|
448
418
|
value: {
|
|
449
419
|
targetIndex: null,
|
|
450
420
|
sourceIndex: null
|
|
451
421
|
}
|
|
452
|
-
}), l(),
|
|
422
|
+
}), l(), h.current = null, _.current = null, v.current = null;
|
|
453
423
|
}, [
|
|
454
424
|
n,
|
|
455
425
|
l,
|
|
456
426
|
e.cloneRef,
|
|
457
|
-
|
|
458
|
-
I
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}, [W]);
|
|
427
|
+
A,
|
|
428
|
+
I
|
|
429
|
+
]), V = i((e) => {
|
|
430
|
+
e.key === "Escape" && B();
|
|
431
|
+
}, [B]);
|
|
463
432
|
return o(() => {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
+
};
|
|
472
447
|
}, [
|
|
473
448
|
t.isDragging,
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
G,
|
|
478
|
-
H,
|
|
479
|
-
e.bodyRef,
|
|
480
|
-
e.tableRef
|
|
449
|
+
z,
|
|
450
|
+
N,
|
|
451
|
+
V
|
|
481
452
|
]), {
|
|
482
453
|
dragStart: R,
|
|
483
|
-
touchStart:
|
|
454
|
+
touchStart: F
|
|
484
455
|
};
|
|
485
|
-
},
|
|
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
|
|
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 ??
|
|
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
|
|
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:
|
|
611
|
+
options: k,
|
|
641
612
|
widths: [],
|
|
642
613
|
columnIds: []
|
|
643
|
-
},
|
|
614
|
+
}, M = {
|
|
644
615
|
position: "relative",
|
|
645
616
|
display: "flex",
|
|
646
617
|
flexFlow: "column"
|
|
647
|
-
},
|
|
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
|
-
},
|
|
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(
|
|
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 } =
|
|
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",
|
|
@@ -730,7 +701,7 @@ var A = {
|
|
|
730
701
|
}),
|
|
731
702
|
a && /* @__PURE__ */ f("div", {
|
|
732
703
|
ref: v,
|
|
733
|
-
style:
|
|
704
|
+
style: N,
|
|
734
705
|
children: a()
|
|
735
706
|
}),
|
|
736
707
|
/* @__PURE__ */ f("div", {
|
|
@@ -739,7 +710,7 @@ var A = {
|
|
|
739
710
|
onMouseDown: S,
|
|
740
711
|
onTouchStart: C,
|
|
741
712
|
style: {
|
|
742
|
-
...
|
|
713
|
+
...M,
|
|
743
714
|
...n
|
|
744
715
|
},
|
|
745
716
|
className: `table ${t ?? ""}`,
|
|
@@ -749,10 +720,10 @@ var A = {
|
|
|
749
720
|
})
|
|
750
721
|
});
|
|
751
722
|
});
|
|
752
|
-
|
|
723
|
+
P.displayName = "TableProvider";
|
|
753
724
|
//#endregion
|
|
754
725
|
//#region src/Components/TableHeader.tsx
|
|
755
|
-
var
|
|
726
|
+
var F = n(({ children: e, style: t, className: n }, r) => {
|
|
756
727
|
let i = u(null), a = r || i, { state: s, dispatch: l } = v();
|
|
757
728
|
o(() => {
|
|
758
729
|
l({
|
|
@@ -811,15 +782,15 @@ var P = n(({ children: e, style: t, className: n }, r) => {
|
|
|
811
782
|
})
|
|
812
783
|
});
|
|
813
784
|
});
|
|
814
|
-
|
|
785
|
+
F.displayName = "TableHeader";
|
|
815
786
|
//#endregion
|
|
816
787
|
//#region src/Components/Draggable.tsx
|
|
817
|
-
var
|
|
788
|
+
var I = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
818
789
|
let { state: s, dispatch: l } = v(), d = c(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
|
|
819
790
|
n,
|
|
820
791
|
s.dragged.draggedID,
|
|
821
792
|
s.dragged.isDragging
|
|
822
|
-
]), p = c(() => i === "row" ?
|
|
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), [
|
|
823
794
|
r,
|
|
824
795
|
s.options.columnDragRange.end,
|
|
825
796
|
s.options.columnDragRange.start,
|
|
@@ -859,15 +830,15 @@ var F = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
|
|
|
859
830
|
})
|
|
860
831
|
});
|
|
861
832
|
});
|
|
862
|
-
|
|
833
|
+
I.displayName = "Draggable";
|
|
863
834
|
//#endregion
|
|
864
835
|
//#region src/Components/ColumnCell.tsx
|
|
865
|
-
var
|
|
836
|
+
var L = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
866
837
|
let { state: a } = v(), o = c(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = c(() => ({
|
|
867
838
|
width: `${o}px`,
|
|
868
839
|
flex: `${o} 0 auto`
|
|
869
840
|
}), [o]);
|
|
870
|
-
return /* @__PURE__ */ f(
|
|
841
|
+
return /* @__PURE__ */ f(I, {
|
|
871
842
|
...i,
|
|
872
843
|
styles: s,
|
|
873
844
|
type: "column",
|
|
@@ -882,10 +853,10 @@ var I = r(({ children: e, width: t, style: n, className: r, ...i }) => {
|
|
|
882
853
|
})
|
|
883
854
|
});
|
|
884
855
|
});
|
|
885
|
-
|
|
856
|
+
L.displayName = "ColumnCell";
|
|
886
857
|
//#endregion
|
|
887
858
|
//#region src/Components/TableBody.tsx
|
|
888
|
-
var
|
|
859
|
+
var R = n(({ children: t, style: n, className: r }, i) => {
|
|
889
860
|
let a = u(null);
|
|
890
861
|
s(i, () => a.current, []);
|
|
891
862
|
let { state: l, dispatch: d } = v(), h = c(() => {
|
|
@@ -944,7 +915,7 @@ var L = n(({ children: t, style: n, className: r }, i) => {
|
|
|
944
915
|
})
|
|
945
916
|
}), l.refs.cloneRef.current), /* @__PURE__ */ f("div", {
|
|
946
917
|
className: `body ${r ?? ""}`,
|
|
947
|
-
style:
|
|
918
|
+
style: z,
|
|
948
919
|
children: /* @__PURE__ */ f("div", {
|
|
949
920
|
className: "ibody",
|
|
950
921
|
style: _,
|
|
@@ -954,24 +925,24 @@ var L = n(({ children: t, style: n, className: r }, i) => {
|
|
|
954
925
|
children: t
|
|
955
926
|
})
|
|
956
927
|
})] });
|
|
957
|
-
}),
|
|
928
|
+
}), z = {
|
|
958
929
|
display: "flex",
|
|
959
930
|
overflow: "hidden",
|
|
960
931
|
flex: 1
|
|
961
932
|
};
|
|
962
|
-
|
|
933
|
+
R.displayName = "TableBody";
|
|
963
934
|
//#endregion
|
|
964
935
|
//#region src/Components/BodyRow.tsx
|
|
965
|
-
var
|
|
936
|
+
var B = {
|
|
966
937
|
display: "flex",
|
|
967
938
|
flex: "1 0 auto",
|
|
968
939
|
minHeight: "24px"
|
|
969
|
-
},
|
|
940
|
+
}, V = r(({ children: e, style: t, className: n, ...r }) => {
|
|
970
941
|
let i = c(() => t ? {
|
|
971
|
-
...
|
|
942
|
+
...B,
|
|
972
943
|
...t
|
|
973
|
-
} :
|
|
974
|
-
return /* @__PURE__ */ f(
|
|
944
|
+
} : B, [t]), a = h("tr", n);
|
|
945
|
+
return /* @__PURE__ */ f(I, {
|
|
975
946
|
...r,
|
|
976
947
|
type: "row",
|
|
977
948
|
children: /* @__PURE__ */ f("div", {
|
|
@@ -981,10 +952,10 @@ var z = {
|
|
|
981
952
|
})
|
|
982
953
|
});
|
|
983
954
|
});
|
|
984
|
-
|
|
955
|
+
V.displayName = "BodyRow";
|
|
985
956
|
//#endregion
|
|
986
957
|
//#region src/Components/RowCell.tsx
|
|
987
|
-
var
|
|
958
|
+
var H = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
|
|
988
959
|
let { index: a } = i, { state: o } = v(), s = c(() => o.columnIds[a] ?? "", [o.columnIds, a]), l = c(() => o.widths[a] ?? o.options.defaultSizing, [
|
|
989
960
|
o.widths,
|
|
990
961
|
a,
|
|
@@ -1011,10 +982,10 @@ var V = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
|
|
|
1011
982
|
children: e
|
|
1012
983
|
});
|
|
1013
984
|
});
|
|
1014
|
-
|
|
985
|
+
H.displayName = "RowCell";
|
|
1015
986
|
//#endregion
|
|
1016
987
|
//#region src/Components/DragHandle.tsx
|
|
1017
|
-
var
|
|
988
|
+
var U = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
|
|
1018
989
|
"data-drag-handle": "true",
|
|
1019
990
|
className: t,
|
|
1020
991
|
style: {
|
|
@@ -1025,6 +996,6 @@ var H = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div",
|
|
|
1025
996
|
},
|
|
1026
997
|
children: e
|
|
1027
998
|
}));
|
|
1028
|
-
|
|
999
|
+
U.displayName = "DragHandle";
|
|
1029
1000
|
//#endregion
|
|
1030
|
-
export {
|
|
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 };
|