simple-table-core 0.2.5 → 0.2.6
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface AnimateProps {
|
|
2
2
|
allowHorizontalAnimate?: boolean;
|
|
3
3
|
children: any;
|
|
4
|
-
|
|
4
|
+
pauseAnimation?: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare const Animate: ({ allowHorizontalAnimate, children,
|
|
6
|
+
declare const Animate: ({ allowHorizontalAnimate, children, pauseAnimation, }: AnimateProps) => any;
|
|
7
7
|
export default Animate;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
interface TableCellProps {
|
|
3
|
-
|
|
3
|
+
borderClass: string;
|
|
4
4
|
colIndex: number;
|
|
5
5
|
content: any;
|
|
6
6
|
isSelected: boolean;
|
|
7
7
|
isTopLeftCell: boolean;
|
|
8
|
-
borderClass: string;
|
|
9
8
|
onMouseDown: (rowIndex: number, colIndex: number) => void;
|
|
10
9
|
onMouseOver: (rowIndex: number, colIndex: number) => void;
|
|
11
|
-
|
|
10
|
+
rowIndex: number;
|
|
12
11
|
}
|
|
13
12
|
declare const TableCell: import("react").ForwardRefExoticComponent<TableCellProps & import("react").RefAttributes<HTMLTableCellElement>>;
|
|
14
13
|
export default TableCell;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as n,Fragment as r}from"react/jsx-runtime";import t,{useState as o,useRef as a,useCallback as c,useEffect as i,Children as l,useLayoutEffect as s,forwardRef as u,createRef as d,Fragment as f,useReducer as h,useMemo as v}from"react";var g=function(){return g=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},g.apply(this,arguments)};function p(e,n,r){if(r||2===arguments.length)for(var t,o=0,a=n.length;o<a;o++)!t&&o in n||(t||(t=Array.prototype.slice.call(n,0,o)),t[o]=n[o]);return e.concat(t||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var m=function(e){var n={};return l.forEach(e,(function(e){if(e.ref&&e.ref.current){var r=e.ref.current.getBoundingClientRect();n[e.key]=r}})),n},w=function(e){var n,r,c=e.allowHorizontalAnimate,l=void 0===c||c,u=e.children,d=e.pause,f=o({}),h=f[0],v=f[1],g=o({}),p=g[0],w=g[1],b=(n=u,r=a(),i((function(){r.current=n}),[n]),r.current);return s((function(){var e=m(u);v(e)}),[u]),s((function(){var e=m(b);w(e)}),[b]),i((function(){d||Object.keys(p).length&&t.Children.forEach(u,(function(e){var n=e.ref.current,r=p[e.key],t=h[e.key],o=r.left-t.left,a=l?0:r.top-t.top,c=Math.abs(o),i=Math.abs(a);(c>10||i>10)&&requestAnimationFrame((function(){n.style.transform="translate(".concat(o,"px, ").concat(a,"px)"),n.style.transition="transform 0s",requestAnimationFrame((function(){n.style.transform="",n.style.transition="transform 500ms"}))}))}))}),[h,p,u,d,l]),u},b=!1,C=function(e){var n=e.draggedHeaderRef,r=e.headersRef,t=e.hoveredHeaderRef,o=e.onTableHeaderDragEnd;return{handleDragStart:function(e){n.current=e},handleDragOver:function(e){!function(e){var a;if(!b&&(t.current=e,e.accessor!==(null===(a=n.current)||void 0===a?void 0:a.accessor)&&null!==n.current&&!b)){if(b=!0,!r.current)return;var c=p([],r.current,!0),i=c.findIndex((function(e){var r;return e.accessor===(null===(r=n.current)||void 0===r?void 0:r.accessor)})),l=c.findIndex((function(n){return n.accessor===e.accessor}));if(void 0===i||void 0===l)return;var s=c.splice(i,1)[0];c.splice(l,0,s),JSON.stringify(c)!==JSON.stringify(r.current)&&setTimeout((function(){o(c),setTimeout((function(){b=!1}),500)}),50)}}(e)},handleDragEnd:function(){n.current=null,t.current=null}}},D=function(e,n){var r=!0,t=!0;return function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];if(r)return r=!1,void setTimeout((function(){return t=!1}),n);t||(e.apply(this,o),t=!0,setTimeout((function(){return t=!1}),n))}},y=u((function(r,t){var c,i=r.draggedHeaderRef,l=r.enableColumnResizing,s=r.forceUpdate,u=r.headersRef,d=r.hoveredHeaderRef,f=r.index,h=r.onSort,v=r.onTableHeaderDragEnd,p=r.setIsWidthDragging,m=a({pageX:0,pageY:0}),w=o(!1),b=w[0],y=w[1],M=null===(c=u.current)||void 0===c?void 0:c[f],R=C({draggedHeaderRef:i,headersRef:u,hoveredHeaderRef:d,onTableHeaderDragEnd:v}),L=R.handleDragStart,x=R.handleDragOver,E=R.handleDragEnd,S=a(D((function(e){x(e)}),100)).current;return M?e("div",g({className:"st-table-header-cell ".concat(M===d.current?"st-hovered":""," ").concat(b?"st-dragging":""),ref:t,style:{width:M.width}},{children:[n("div",g({className:"st-table-header-label",draggable:!0,onClick:function(){return h(f)},onDragStart:function(){return function(e){y(!0),L(e)}(M)},onDragOver:function(e){var n=e.pageX,r=e.pageY;n===m.current.pageX&&r===m.current.pageY||(m.current={pageX:n,pageY:r},e.preventDefault(),S(M,e))},onDragEnd:function(){y(!1),E()}},{children:null==M?void 0:M.label})),l&&n("div",{className:"st-table-header-resize-handle",onMouseDown:function(e){p(!0),e.preventDefault();var n=e.clientX;if(M){var r=M.width,t=D((function(e){var t=Math.max(r+(e.clientX-n),10);M&&(u.current[f].width=t,s())}),10),o=function(){document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",o),p(!1)};document.addEventListener("mousemove",t),document.addEventListener("mouseup",o)}}})]})):null})),M=u((function(e,r){return e.visible?n("div",{className:"st-table-cell ".concat(e.isLastRow?"st-table-cell-last-row":""),ref:r}):n("div",{ref:r})})),R=function(){return n("div",{className:"st-table-row-separator"})},L=function(t){var o,c=t.enableColumnResizing,i=t.forceUpdate,l=t.headersRef,s=t.isWidthDragging,u=t.onSort,f=t.onTableHeaderDragEnd,h=t.setIsWidthDragging,v=t.shouldDisplayLastColumnCell,p=a(null),m=a(null);return e(r,{children:[e(w,g({pause:s},{children:[null===(o=l.current)||void 0===o?void 0:o.map((function(e,r){return n(y,{draggedHeaderRef:p,enableColumnResizing:c,forceUpdate:i,headersRef:l,hoveredHeaderRef:m,index:r,onSort:u,onTableHeaderDragEnd:f,ref:d(),setIsWidthDragging:h},e.accessor)})),n(M,{ref:d(),visible:v})]})),n(R,{})]})},x=u((function(e,r){var t=e.rowIndex,o=e.colIndex,a=e.content,c=e.isSelected,i=e.isTopLeftCell,l=e.borderClass,s=e.onMouseDown,u=e.onMouseOver,d=e.isLastRow,f=t%2==0;return n("div",g({onMouseDown:function(){return s(t,o)},onMouseOver:function(){return u(t,o)},ref:r,className:"st-table-cell ".concat(c?i?"st-table-cell-selected-first-cell ".concat(l):"st-table-cell-selected ".concat(l):""," ").concat(d?"st-table-cell-last-row":"","\n ").concat(f?"st-table-cell-odd-row":"")},{children:a}))})),E=function(t){var o=t.getBorderClass,a=t.handleMouseDown,c=t.handleMouseOver,i=t.headers,l=t.isSelected,s=t.isTopLeftCell,u=t.isWidthDragging,h=t.shouldDisplayLastColumnCell,v=t.shouldPaginate,p=t.sortedRows;return n(r,{children:p.map((function(r,t){return e(f,{children:[e(w,g({allowHorizontalAnimate:v,pause:u},{children:[i.map((function(e,i){var u=r[e.accessor];return e.cellRenderer&&(u=e.cellRenderer(r)),n(x,{borderClass:o(t,i),colIndex:i,content:u,isSelected:l(t,i),isTopLeftCell:s(t,i),onMouseDown:function(){return a(t,i)},onMouseOver:function(){return c(t,i)},ref:d(),rowIndex:t,isLastRow:t===p.length-1},e.accessor)})),n(M,{isLastRow:t===p.length-1,ref:d(),visible:h})]})),t!==p.length-1&&n(R,{})]},r.id)}))})},S=function(r){var t=r.currentPage,o=r.hideFooter,a=r.nextIcon,c=r.onPageChange,i=r.prevIcon,l=r.rowsPerPage,s=r.totalRows,u=Math.ceil(s/l),d=function(e){e>=1&&e<=u&&c(e)};return o?null:e("div",g({className:"st-footer"},{children:[n("button",g({className:"st-next-prev-btn",onClick:function(){return d(t-1)},disabled:1===t},{children:i})),n("button",g({className:"st-next-prev-btn",onClick:function(){return d(t+1)},disabled:t===u},{children:a})),Array.from({length:u},(function(e,r){return n("button",g({onClick:function(){return d(r+1)},className:"st-page-btn ".concat(t===r+1?"active":"")},{children:r+1}),r)}))]}))},O=function(){return n("svg",g({className:"angle-icon",viewBox:"0 0 24 24",width:"24",height:"24",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})}))},T=function(){return n("svg",g({className:"angle-icon",viewBox:"0 0 24 24",width:"24",height:"24",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M8.59 16.59L10 18l6-6-6-6-1.41 1.41L13.17 12z"})}))},H=function(r){var t,l=r.defaultHeaders,s=r.enableColumnResizing,u=void 0===s||s,d=r.height,f=r.hideFooter,m=void 0!==f&&f,w=r.nextIcon,b=void 0===w?n(T,{}):w,C=r.prevIcon,D=void 0===C?n(O,{}):C,y=r.rows,M=r.rowsPerPage,R=void 0===M?10:M,x=r.shouldPaginate,H=void 0===x||x,I=o(!1),N=I[0],P=I[1],k=a(l),j=o(y),z=j[0],W=j[1],A=o(null),B=A[0],U=A[1],F=h((function(e){return e+1}),0)[1],X=o(1),Y=X[0],q=X[1],J=a(null),K=v((function(){return!!J.current&&k.current.reduce((function(e,n){return e+n.width}),0)<J.current.clientWidth}),[]),G=function(e,n){var r=o([]),t=r[0],l=r[1],s=a(!1),u=a(null),d=c((function(){var r=t.reduce((function(r,t){var o=t.row,a=t.col;return r[o]||(r[o]=[]),r[o][a]=e[o][n[a].accessor],r}),{}),o=Object.values(r).map((function(e){return Object.values(e).join("\t")})).join("\n");navigator.clipboard.writeText(o)}),[t,e,n]);i((function(){var e=function(e){(e.ctrlKey||e.metaKey)&&"c"===e.key&&d()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[d,t]);var f=function(e,n){return t.some((function(r){return r.row===e&&r.col===n}))};return{selectedCells:t,handleMouseDown:function(e,n){s.current=!0,u.current={row:e,col:n},l([{row:e,col:n}])},handleMouseOver:function(e,n){if(s.current&&u.current){for(var r=[],t=Math.min(u.current.row,e),o=Math.max(u.current.row,e),a=Math.min(u.current.col,n),c=Math.max(u.current.col,n),i=t;i<=o;i++)for(var d=a;d<=c;d++)r.push({row:i,col:d});l(r)}},handleMouseUp:function(){s.current=!1,u.current=null},isSelected:f,getBorderClass:function(e,n){var r=[];return f(e-1,n)||r.push("border-top-blue"),f(e+1,n)||r.push("border-bottom-blue"),f(e,n-1)||r.push("border-left-blue"),f(e,n+1)||r.push("border-right-blue"),r.join(" ")},isTopLeftCell:function(e,n){return e===Math.min.apply(Math,t.map((function(e){return e.row})))&&n===Math.min.apply(Math,t.map((function(e){return e.col})))},setSelectedCells:l}}(z,k.current),Q=G.handleMouseDown,V=G.handleMouseOver,Z=G.handleMouseUp,$=G.isSelected,_=G.getBorderClass,ee=G.isTopLeftCell,ne=G.setSelectedCells;i((function(){var e=function(e){e.target.closest(".st-table-cell")||ne([])};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[ne]);var re=H?z.slice((Y-1)*R,Y*R):z;return e("div",g({ref:J,className:"st-table-wrapper",style:d?{height:d}:{}},{children:[e("div",g({className:"st-table",onMouseUp:Z,onMouseLeave:Z,style:{gridTemplateColumns:"".concat(null===(t=k.current)||void 0===t?void 0:t.map((function(e){return"".concat(e.width,"px")})).join(" ")," 1fr")}},{children:[n(L,{enableColumnResizing:u,forceUpdate:F,headersRef:k,isWidthDragging:N,onSort:function(e){var n=function(e,n,r,t){var o=e[t],a="ascending";return r&&r.key.accessor===o.accessor&&"ascending"===r.direction&&(a="descending"),{sortedData:p([],n,!0).sort((function(e,n){return e[o.accessor]<n[o.accessor]?"ascending"===a?-1:1:e[o.accessor]>n[o.accessor]?"ascending"===a?1:-1:0})),newSortConfig:{key:o,direction:a}}}(k.current,z,B,e),r=n.sortedData,t=n.newSortConfig;W(r),U(t)},onTableHeaderDragEnd:function(e){k.current=e,F()},setIsWidthDragging:P,shouldDisplayLastColumnCell:K}),n(E,{getBorderClass:_,handleMouseDown:Q,handleMouseOver:V,headers:k.current,isSelected:$,isTopLeftCell:ee,isWidthDragging:N,shouldDisplayLastColumnCell:K,shouldPaginate:H,sortedRows:re})]})),H&&n(S,{currentPage:Y,hideFooter:m,onPageChange:q,rowsPerPage:R,totalRows:z.length,nextIcon:b,prevIcon:D})]}))};export{H as SimpleTable};
|
|
1
|
+
import{jsxs as e,jsx as n,Fragment as r}from"react/jsx-runtime";import t,{useState as o,useRef as a,useCallback as c,useEffect as i,Children as s,useLayoutEffect as u,forwardRef as l,createRef as d,Fragment as f,useReducer as h,useMemo as v}from"react";var g=function(){return g=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},g.apply(this,arguments)};function p(e,n,r){if(r||2===arguments.length)for(var t,o=0,a=n.length;o<a;o++)!t&&o in n||(t||(t=Array.prototype.slice.call(n,0,o)),t[o]=n[o]);return e.concat(t||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var m=function(e){var n={};return s.forEach(e,(function(e,r){if(e.ref&&e.ref.current){var t=e.ref.current.getBoundingClientRect();n[e.key]=t}})),n},w=function(e){var n,r,c=e.allowHorizontalAnimate,s=void 0===c||c,l=e.children,d=e.pauseAnimation,f=o({}),h=f[0],v=f[1],g=o({}),p=g[0],w=g[1],b=(n=l,r=a(),i((function(){r.current=n}),[n]),r.current);return u((function(){var e=m(l);v(e)}),[l]),u((function(){var e=m(b);w(e)}),[b]),i((function(){d||Object.keys(p).length&&t.Children.forEach(l,(function(e){var n=e.ref.current,r=p[e.key],t=h[e.key],o=r.left-t.left,a=s?0:r.top-t.top,c=Math.abs(o),i=Math.abs(a);(c>10||i>10)&&requestAnimationFrame((function(){n.style.transform="translate(".concat(o,"px, ").concat(a,"px)"),n.style.transition="transform 0s",requestAnimationFrame((function(){n.style.transform="",n.style.transition="transform 500ms"}))}))}))}),[s,h,l,d,p]),l},b=!1,C=function(e){var n=e.draggedHeaderRef,r=e.headersRef,t=e.hoveredHeaderRef,o=e.onTableHeaderDragEnd;return{handleDragStart:function(e){n.current=e},handleDragOver:function(e){!function(e){var a;if(!b&&(t.current=e,e.accessor!==(null===(a=n.current)||void 0===a?void 0:a.accessor)&&null!==n.current&&!b)){if(b=!0,!r.current)return;var c=p([],r.current,!0),i=c.findIndex((function(e){var r;return e.accessor===(null===(r=n.current)||void 0===r?void 0:r.accessor)})),s=c.findIndex((function(n){return n.accessor===e.accessor}));if(void 0===i||void 0===s)return;var u=c.splice(i,1)[0];c.splice(s,0,u),JSON.stringify(c)!==JSON.stringify(r.current)&&setTimeout((function(){o(c),setTimeout((function(){b=!1}),500)}),50)}}(e)},handleDragEnd:function(){n.current=null,t.current=null}}},D=function(e,n){var r=!0,t=!0;return function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];if(r)return r=!1,void setTimeout((function(){return t=!1}),n);t||(e.apply(this,o),t=!0,setTimeout((function(){return t=!1}),n))}},y=l((function(r,t){var c,i=r.draggedHeaderRef,s=r.enableColumnResizing,u=r.forceUpdate,l=r.headersRef,d=r.hoveredHeaderRef,f=r.index,h=r.onSort,v=r.onTableHeaderDragEnd,p=r.setIsWidthDragging,m=a({pageX:0,pageY:0}),w=o(!1),b=w[0],y=w[1],M=null===(c=l.current)||void 0===c?void 0:c[f],x=C({draggedHeaderRef:i,headersRef:l,hoveredHeaderRef:d,onTableHeaderDragEnd:v}),R=x.handleDragStart,L=x.handleDragOver,E=x.handleDragEnd,S=a(D((function(e){L(e)}),100)).current;return M?e("div",g({className:"st-header-cell ".concat(M===d.current?"st-hovered":""," ").concat(b?"st-dragging":""),ref:t,style:{width:M.width}},{children:[n("div",g({className:"st-header-label",draggable:!0,onClick:function(){return h(f)},onDragStart:function(){return function(e){y(!0),R(e)}(M)},onDragOver:function(e){var n=e.pageX,r=e.pageY;n===m.current.pageX&&r===m.current.pageY||(m.current={pageX:n,pageY:r},e.preventDefault(),S(M,e))},onDragEnd:function(){y(!1),E()}},{children:null==M?void 0:M.label})),s&&n("div",{className:"st-header-resize-handle",onMouseDown:function(e){p(!0),e.preventDefault();var n=e.clientX;if(M){var r=M.width,t=D((function(e){var t=Math.max(r+(e.clientX-n),10);M&&(l.current[f].width=t,u())}),10),o=function(){document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",o),p(!1)};document.addEventListener("mousemove",t),document.addEventListener("mouseup",o)}}})]})):null})),M=l((function(e,r){return e.visible?n("div",{className:"st-cell",ref:r}):n("div",{ref:r})})),x=function(){return n("div",{className:"st-row-separator"})},R=function(t){var o,c=t.enableColumnResizing,i=t.forceUpdate,s=t.headersRef,u=t.isWidthDragging,l=t.onSort,f=t.onTableHeaderDragEnd,h=t.setIsWidthDragging,v=t.shouldDisplayLastColumnCell,p=a(null),m=a(null);return e(r,{children:[e(w,g({pauseAnimation:u},{children:[null===(o=s.current)||void 0===o?void 0:o.map((function(e,r){return n(y,{draggedHeaderRef:p,enableColumnResizing:c,forceUpdate:i,headersRef:s,hoveredHeaderRef:m,index:r,onSort:l,onTableHeaderDragEnd:f,ref:d(),setIsWidthDragging:h},e.accessor)})),n(M,{ref:d(),visible:v})]})),n(x,{})]})},L=l((function(e,r){var t=e.rowIndex,o=e.colIndex,a=e.content,c=e.isSelected,i=e.isTopLeftCell,s=e.borderClass,u=e.onMouseDown,l=e.onMouseOver,d=t%2==0;return n("div",g({onMouseDown:function(){return u(t,o)},onMouseOver:function(){return l(t,o)},ref:r,className:"st-cell ".concat(c?i?"st-cell-selected-first-cell ".concat(s):"st-cell-selected ".concat(s):""," ").concat(d?"st-cell-odd-row":"")},{children:a}))})),E=function(t){var o=t.getBorderClass,a=t.handleMouseDown,c=t.handleMouseOver,i=t.headers,s=t.isSelected,u=t.isTopLeftCell,l=t.isWidthDragging,h=t.shouldDisplayLastColumnCell,v=t.shouldPaginate,p=t.sortedRows;return n(r,{children:p.map((function(r,t){return e(f,{children:[e(w,g({allowHorizontalAnimate:v,pauseAnimation:l},{children:[i.map((function(e,i){var l=r[e.accessor];return e.cellRenderer&&(l=e.cellRenderer(r)),n(L,{borderClass:o(t,i),colIndex:i,content:l,isSelected:s(t,i),isTopLeftCell:u(t,i),onMouseDown:function(){return a(t,i)},onMouseOver:function(){return c(t,i)},ref:d(),rowIndex:t},e.accessor)})),n(M,{ref:d(),visible:h})]})),t!==p.length-1&&n(x,{})]},r.id)}))})},S=function(r){var t=r.currentPage,o=r.hideFooter,a=r.nextIcon,c=r.onPageChange,i=r.prevIcon,s=r.rowsPerPage,u=r.totalRows,l=Math.ceil(u/s),d=function(e){e>=1&&e<=l&&c(e)};return o?null:e("div",g({className:"st-footer"},{children:[n("button",g({className:"st-next-prev-btn",onClick:function(){return d(t-1)},disabled:1===t},{children:i})),n("button",g({className:"st-next-prev-btn",onClick:function(){return d(t+1)},disabled:t===l},{children:a})),Array.from({length:l},(function(e,r){return n("button",g({onClick:function(){return d(r+1)},className:"st-page-btn ".concat(t===r+1?"active":"")},{children:r+1}),r)}))]}))},O=function(){return n("svg",g({className:"angle-icon",viewBox:"0 0 24 24",width:"24",height:"24",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})}))},T=function(){return n("svg",g({className:"angle-icon",viewBox:"0 0 24 24",width:"24",height:"24",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M8.59 16.59L10 18l6-6-6-6-1.41 1.41L13.17 12z"})}))},H=function(r){var t,s=r.defaultHeaders,u=r.enableColumnResizing,l=void 0===u||u,d=r.height,f=r.hideFooter,m=void 0!==f&&f,w=r.nextIcon,b=void 0===w?n(T,{}):w,C=r.prevIcon,D=void 0===C?n(O,{}):C,y=r.rows,M=r.rowsPerPage,x=void 0===M?10:M,L=r.shouldPaginate,H=void 0===L||L,I=o(!1),N=I[0],P=I[1],k=a(s),j=o(y),z=j[0],A=j[1],W=o(null),B=W[0],U=W[1],F=h((function(e){return e+1}),0)[1],X=o(1),Y=X[0],q=X[1],J=a(null),K=v((function(){return!!J.current&&k.current.reduce((function(e,n){return e+n.width}),0)<J.current.clientWidth}),[]),G=function(e,n){var r=o([]),t=r[0],s=r[1],u=a(!1),l=a(null),d=c((function(){var r=t.reduce((function(r,t){var o=t.row,a=t.col;return r[o]||(r[o]=[]),r[o][a]=e[o][n[a].accessor],r}),{}),o=Object.values(r).map((function(e){return Object.values(e).join("\t")})).join("\n");navigator.clipboard.writeText(o)}),[t,e,n]);i((function(){var e=function(e){(e.ctrlKey||e.metaKey)&&"c"===e.key&&d()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[d,t]);var f=function(e,n){return t.some((function(r){return r.row===e&&r.col===n}))};return{selectedCells:t,handleMouseDown:function(e,n){u.current=!0,l.current={row:e,col:n},s([{row:e,col:n}])},handleMouseOver:function(e,n){if(u.current&&l.current){for(var r=[],t=Math.min(l.current.row,e),o=Math.max(l.current.row,e),a=Math.min(l.current.col,n),c=Math.max(l.current.col,n),i=t;i<=o;i++)for(var d=a;d<=c;d++)r.push({row:i,col:d});s(r)}},handleMouseUp:function(){u.current=!1,l.current=null},isSelected:f,getBorderClass:function(e,n){var r=[];return f(e-1,n)||r.push("st-selected-top-border"),f(e+1,n)||r.push("st-selected-bottom-border"),f(e,n-1)||r.push("st-selected-left-border"),f(e,n+1)||r.push("st-selected-right-border"),r.join(" ")},isTopLeftCell:function(e,n){return e===Math.min.apply(Math,t.map((function(e){return e.row})))&&n===Math.min.apply(Math,t.map((function(e){return e.col})))},setSelectedCells:s}}(z,k.current),Q=G.handleMouseDown,V=G.handleMouseOver,Z=G.handleMouseUp,$=G.isSelected,_=G.getBorderClass,ee=G.isTopLeftCell,ne=G.setSelectedCells;i((function(){var e=function(e){e.target.closest(".st-cell")||ne([])};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[ne]);var re=H?z.slice((Y-1)*x,Y*x):z;return e("div",g({ref:J,className:"st-wrapper",style:d?{height:d}:{}},{children:[e("div",g({className:"st-table",onMouseUp:Z,onMouseLeave:Z,style:{gridTemplateColumns:"".concat(null===(t=k.current)||void 0===t?void 0:t.map((function(e){return"".concat(e.width,"px")})).join(" ")," 1fr")}},{children:[n(R,{enableColumnResizing:l,forceUpdate:F,headersRef:k,isWidthDragging:N,onSort:function(e){var n=function(e,n,r,t){var o=e[t],a="ascending";return r&&r.key.accessor===o.accessor&&"ascending"===r.direction&&(a="descending"),{sortedData:p([],n,!0).sort((function(e,n){return e[o.accessor]<n[o.accessor]?"ascending"===a?-1:1:e[o.accessor]>n[o.accessor]?"ascending"===a?1:-1:0})),newSortConfig:{key:o,direction:a}}}(k.current,z,B,e),r=n.sortedData,t=n.newSortConfig;A(r),U(t)},onTableHeaderDragEnd:function(e){k.current=e,F()},setIsWidthDragging:P,shouldDisplayLastColumnCell:K}),n(E,{getBorderClass:_,handleMouseDown:Q,handleMouseOver:V,headers:k.current,isSelected:$,isTopLeftCell:ee,isWidthDragging:N,shouldDisplayLastColumnCell:K,shouldPaginate:H,sortedRows:re})]})),H&&n(S,{currentPage:Y,hideFooter:m,onPageChange:q,rowsPerPage:x,totalRows:z.length,nextIcon:b,prevIcon:D})]}))};export{H as SimpleTable};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap");:root{--slate-50:#f8fafc;--slate-100:#f1f5f9;--slate-200:#e2e8f0;--slate-300:#cbd5e1;--slate-400:#94a3b8;--slate-500:#64748b;--slate-600:#475569;--slate-700:#334155;--slate-800:#1e293b;--slate-900:#0f172a;--blue-50:#eff6ff;--blue-100:#dbeafe;--blue-200:#bfdbfe;--blue-300:#93c5fd;--blue-400:#60a5fa;--blue-500:#3b82f6;--blue-600:#2563eb;--blue-700:#1d4ed8;--blue-800:#1e40af;--blue-900:#1e3a8a;--orange-50:#fff7ed;--orange-100:#ffedd5;--orange-200:#fed7aa;--orange-300:#fdba74;--orange-400:#fb923c;--orange-500:#f97316;--orange-600:#ea580c;--orange-700:#c2410c;--orange-800:#9a3412;--orange-900:#7c2d12;--amber-50:#fffbeb;--amber-100:#fef3c7;--amber-200:#fde68a;--amber-300:#fcd34d;--amber-400:#fbbf24;--amber-500:#f59e0b;--amber-600:#d97706;--amber-700:#b45309;--amber-800:#92400e;--amber-900:#78350f;--st-border-radius:4px;--st-
|
|
1
|
+
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap");:root{--slate-50:#f8fafc;--slate-100:#f1f5f9;--slate-200:#e2e8f0;--slate-300:#cbd5e1;--slate-400:#94a3b8;--slate-500:#64748b;--slate-600:#475569;--slate-700:#334155;--slate-800:#1e293b;--slate-900:#0f172a;--blue-50:#eff6ff;--blue-100:#dbeafe;--blue-200:#bfdbfe;--blue-300:#93c5fd;--blue-400:#60a5fa;--blue-500:#3b82f6;--blue-600:#2563eb;--blue-700:#1d4ed8;--blue-800:#1e40af;--blue-900:#1e3a8a;--orange-50:#fff7ed;--orange-100:#ffedd5;--orange-200:#fed7aa;--orange-300:#fdba74;--orange-400:#fb923c;--orange-500:#f97316;--orange-600:#ea580c;--orange-700:#c2410c;--orange-800:#9a3412;--orange-900:#7c2d12;--amber-50:#fffbeb;--amber-100:#fef3c7;--amber-200:#fde68a;--amber-300:#fcd34d;--amber-400:#fbbf24;--amber-500:#f59e0b;--amber-600:#d97706;--amber-700:#b45309;--amber-800:#92400e;--amber-900:#78350f;--st-border-radius:4px;--st-border-color:var(--slate-300);--st-border-width:1px;--st-resize-handle-color:var(--slate-300);--st-separator-border-color:var(--slate-300);--st-odd-row-background-color:var(--slate-100);--st-dragging-background-color:var(--blue-100);--st-selected-cell-background-color:var(--blue-200);--st-selected-first-cell-background-color:var(--amber-100);--st-border-top-color:var(--blue-500);--st-border-bottom-color:var(--blue-500);--st-border-left-color:var(--blue-500);--st-border-right-color:var(--blue-500);--st-border-top-white-color:#fff;--st-footer-background-color:#fff}*{box-sizing:border-box;margin:0;padding:0}body{font-family:Nunito}.st-wrapper{border:var(--st-border-width) solid var(--st-border-color);border-radius:var(--st-border-radius);height:auto;max-height:100dvh;overflow:auto}.st-table{border-collapse:collapse;display:grid;table-layout:auto;white-space:nowrap;width:100%}.st-header-cell{background-color:#fff;position:sticky;top:0;z-index:1}.st-cell,.st-header-cell{border:var(--st-border-width) solid #0000;color:var(--slate-800);cursor:pointer;height:40px;overflow:hidden}.st-cell,.st-header-label{overflow:hidden;padding:8px;text-align:left;text-overflow:ellipsis;user-select:none;white-space:nowrap}.st-header-resize-handle{background-color:var(--st-resize-handle-color);border-radius:.25rem;bottom:0;cursor:col-resize;margin-bottom:.25rem;margin-top:.25rem;position:absolute;right:0;top:0;width:5px}.st-row-separator{background-color:var(--st-separator-border-color);grid-column:1/-1;height:1px}.st-cell-odd-row{background-color:var(--st-odd-row-background-color)}.st-dragging{background-color:var(--st-dragging-background-color)}.st-cell-selected{background-color:var(--st-selected-cell-background-color)}.st-cell-selected-first{background-color:var(--st-selected-first-cell-background-color)}.st-selected-top-border{border-top:var(--st-border-width) solid var(--st-border-top-color)}.st-selected-bottom-border{border-bottom:var(--st-border-width) solid var(--st-border-bottom-color)}.st-selected-left-border{border-left:var(--st-border-width) solid var(--st-border-left-color)}.st-selected-right-border{border-right:var(--st-border-width) solid var(--st-border-right-color)}.st-selected-top-border-white{border-top:var(--st-border-width) solid var(--st-border-top-white-color)}.st-footer{background-color:var(--st-footer-background-color);border-top:var(--st-border-width) solid var(--st-border-color);bottom:0;left:0;padding:8px;position:sticky}.st-footer,.st-next-prev-btn{align-items:center;display:flex}.st-next-prev-btn{background-color:initial;border:none;border-radius:4px;color:var(--slate-600);cursor:pointer;justify-content:center;padding:4px;transition:background-color .3s ease}.st-next-prev-btn:hover{background-color:var(--slate-100)}.st-page-btn{background-color:initial;border:none;border-radius:var(--st-border-radius);color:var(--slate-600);cursor:pointer;margin-left:4px;padding:4px;transition:background-color .3s ease}.st-page-btn:hover{background-color:var(--slate-100)}.st-page-btn.active{background-color:var(--blue-500);color:#fff}
|