simple-table-core 0.5.4 → 0.5.7

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/README.md CHANGED
@@ -4,6 +4,10 @@ Any questions, support or features requests join me on Dicord <a href="https://d
4
4
 
5
5
  Simple Table is a React grid package designed to provide a flexible and easy-to-use table component for your React applications.
6
6
 
7
+ ## Website
8
+
9
+ For more information, visit our website: [Simple Table](https://www.simple-table.com/)
10
+
7
11
  ## Live Demo
8
12
 
9
13
  Check out the live demo on CodeSandbox: <a href="https://codesandbox.io/p/sandbox/simple-table-pagination-example-rdjm5d?file=%2Fsrc%2FApp.tsx%3A33%2C24" target="_blank" rel="noopener noreferrer">Simple Table Pagination Example</a>
@@ -1,8 +1,7 @@
1
- import React from "react";
2
1
  interface BooleanSelectProps {
3
2
  value: boolean;
4
3
  onBlur: () => void;
5
- onChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
4
+ onChange: (value: boolean) => void;
6
5
  }
7
6
  declare const BooleanSelect: ({ value, onBlur, onChange }: BooleanSelectProps) => import("react/jsx-runtime").JSX.Element;
8
7
  export default BooleanSelect;
@@ -0,0 +1,7 @@
1
+ interface NumberInputProps {
2
+ defaultValue: number;
3
+ onBlur: () => void;
4
+ onChange: (value: string) => void;
5
+ }
6
+ declare const NumberEdit: ({ defaultValue, onBlur, onChange }: NumberInputProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default NumberEdit;
@@ -0,0 +1,7 @@
1
+ interface TextInputProps {
2
+ defaultValue: string | null | undefined;
3
+ onBlur: () => void;
4
+ onChange: (value: string) => void;
5
+ }
6
+ declare const StringEdit: ({ defaultValue, onBlur, onChange }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default StringEdit;
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 l,useEffect as s,Children as i,useLayoutEffect as c,forwardRef as d,createRef as u,createContext as f,useContext as h,Fragment as g,useMemo as b,useReducer as v}from"react";var p=function(){return p=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},p.apply(this,arguments)};function m(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 w=function(e){var n={};return i.forEach(e,(function(e){if(e&&e.ref&&e.ref.current){var r=e.ref.current.getBoundingClientRect();n[e.key]=r}})),n},x=function(e){var n,r,l=e.allowHorizontalAnimate,i=void 0===l||l,d=e.children,u=e.pauseAnimation,f=e.tableRef,h=a(!1),g=o({}),b=g[0],v=g[1],p=o({}),m=p[0],x=p[1],y=(n=d,r=a(),s((function(){r.current=n}),[n]),r.current);return c((function(){var e=w(d);v(e)}),[d]),c((function(){var e=w(y);x(e);var n=f.current,r=function(){h.current=!0;var e=w(y);v(e),x(e)},t=function(){h.current=!1};return null==n||n.addEventListener("scroll",r),null==n||n.addEventListener("scrollend",t),function(){null==n||n.removeEventListener("scroll",r),null==n||n.removeEventListener("scrollend",t)}}),[y,f]),s((function(){u||h.current||Object.keys(m).length&&t.Children.forEach(d,(function(e){if(e){var n=e.ref.current,r=m[e.key],t=b[e.key];if(r&&t){var o=r.left-t.left,a=i?0:r.top-t.top,l=Math.abs(o),s=Math.abs(a);(l>10||s>10)&&requestAnimationFrame((function(){n.style.transform="translate(".concat(o,"px, ").concat(a,"px)"),n.style.transition="transform 0s, opacity 0s",requestAnimationFrame((function(){n.style.transform="",n.style.transition="transform 300ms ease-out, opacity 300ms ease-out"}))}))}}}))}),[i,b,d,u,m]),d},y=!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(!y&&(t.current=e,e.accessor!==(null===(a=n.current)||void 0===a?void 0:a.accessor)&&null!==n.current&&!y)){if(y=!0,!r.current)return;var l=m([],r.current,!0),s=l.findIndex((function(e){var r;return e.accessor===(null===(r=n.current)||void 0===r?void 0:r.accessor)})),i=l.findIndex((function(n){return n.accessor===e.accessor}));if(void 0===s||void 0===i)return;var c=l.splice(s,1)[0];l.splice(i,0,c),JSON.stringify(l)!==JSON.stringify(r.current)&&setTimeout((function(){o(l),setTimeout((function(){y=!1}),500)}),50)}}(e)},handleDragEnd:function(){n.current=null,t.current=null}}},k=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))}},D=d((function(r,t){var l,i=r.draggable,c=r.draggedHeaderRef,d=r.columnResizing,u=r.forceUpdate,f=r.headersRef,h=r.hoveredHeaderRef,g=r.index,b=r.onSort,v=r.onTableHeaderDragEnd,m=r.setIsWidthDragging,w=r.sort,x=r.sortDownIcon,y=r.sortUpIcon,D=a({pageX:0,pageY:0}),R=o(!1),N=R[0],E=R[1],I=null===(l=f.current)||void 0===l?void 0:l[g],M=Boolean(null==I?void 0:I.isSortable),A="st-header-cell ".concat(I===h.current?"st-hovered":""," ").concat(N?"st-dragging":""," ").concat(M?"clickable":""," ").concat(i&&!M?"draggable":""),L=C({draggedHeaderRef:c,headersRef:f,hoveredHeaderRef:h,onTableHeaderDragEnd:v}),S=L.handleDragStart,T=L.handleDragOver,B=L.handleDragEnd,z=a(k((function(e){T(e)}),100)).current,H=function(e){e.isSortable&&b(g,e.accessor)};return s((function(){var e=function(e){var n=new Image;n.src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",e.dataTransfer.setDragImage(n,0,0)};return document.addEventListener("dragend",e,!1),function(){document.removeEventListener("dragend",e)}}),[]),I?e("div",p({className:A,ref:t,style:{width:I.width}},{children:[n("div",p({className:"st-header-label",draggable:i,onClick:function(){return H(I)},onDragStart:function(e){i&&I&&(e.dataTransfer.dropEffect="move",function(e){E(!0),S(e)}(I))},onDragOver:function(e){return function(e,n){e.preventDefault(),e.dataTransfer.dropEffect="move";var r=e.pageX,t=e.pageY;r===D.current.pageX&&t===D.current.pageY||(D.current={pageX:r,pageY:t},z(n,e))}(e,I)},onDragEnd:function(e){e.preventDefault(),e.dataTransfer.dropEffect="move",E(!1),B()},onMouseEnter:function(){return document.body.style.overflow="hidden"},onMouseLeave:function(){return document.body.style.overflow="auto"}},{children:null==I?void 0:I.label})),w&&w.key.accessor===I.accessor&&e("div",p({className:"st-sort-icon-container",onClick:function(){return H(I)}},{children:["ascending"===w.direction&&y&&y,"descending"===w.direction&&x&&x]})),d&&n("div",{className:"st-header-resize-handle",onMouseDown:function(e){m(!0),e.preventDefault();var n=e.clientX;if(I){var r=I.width,t=k((function(e){var t=Math.max(r+(e.clientX-n),40);I&&(f.current[g].width=t,u())}),10),o=function(){document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",o),m(!1)};document.addEventListener("mousemove",t),document.addEventListener("mouseup",o)}}})]})):null})),R=d((function(e,r){return e.visible?n("div",{className:"st-cell",ref:r}):n("div",{ref:r})})),N=function(t){var o,l=t.draggable,s=t.columnResizing,i=t.forceUpdate,c=t.headersRef,d=t.hiddenColumns,f=t.isWidthDragging,h=t.onSort,g=t.onTableHeaderDragEnd,b=t.setIsWidthDragging,v=t.shouldDisplayLastColumnCell,m=t.sort,w=t.sortDownIcon,y=t.sortUpIcon,C=t.tableRef,k=a(null),N=a(null);return n(r,{children:e(x,p({pauseAnimation:f,tableRef:C},{children:[null===(o=c.current)||void 0===o?void 0:o.map((function(e,r){return d[e.accessor]?null:n(D,{draggable:l,draggedHeaderRef:k,columnResizing:s,forceUpdate:i,headersRef:c,hoveredHeaderRef:N,index:r,onSort:h,onTableHeaderDragEnd:g,ref:u(),setIsWidthDragging:b,sort:m,sortDownIcon:w,sortUpIcon:y},e.accessor)})),n(R,{ref:u(),visible:v})]}))})},E=function(r){var t=r.value,o=r.onBlur,a=r.onChange;return e("select",p({value:t.toString(),onBlur:o,onChange:a},{children:[n("option",p({value:"true"},{children:"True"})),n("option",p({value:"false"},{children:"False"}))]}))},I=function(e){var r=e.defaultValue,t=e.onBlur,o=e.onChange,l=a(null);return n("input",{className:"editable-cell-input",ref:l,autoFocus:!0,type:"text",defaultValue:r,onBlur:t,onChange:o})},M=function(e){var t=e.onChange,o=e.setIsEditing,a=e.value,l=function(e){var n=e.target.value;null==t||t(n)},s=function(){o(!1)};return n(r,{children:"string"==typeof a?n(I,{defaultValue:a,onBlur:s,onChange:l}):"boolean"==typeof a?n(E,{value:a,onBlur:s,onChange:l}):null})},A=f({rows:[],tableRows:[]}),L=d((function(e,r){var t=e.borderClass,a=e.colIndex,l=e.content,i=e.header,c=e.isSelected,d=e.isTopLeftCell,u=e.onCellChange,f=e.onMouseDown,g=e.onMouseOver,b=e.row,v=e.rowIndex,m=h(A),w=m.rows,x=m.tableRows,y=o(l),C=y[0],k=y[1],D=o(!1),R=D[0],N=D[1],E=Boolean(null==i?void 0:i.isEditable),I=v%2==0,L="st-cell ".concat(c?d?"st-cell-selected-first-cell ".concat(t):"st-cell-selected ".concat(t):""," ").concat(I?"st-cell-odd-row":""," ").concat(E?"clickable":"");s((function(){k(l)}),[l]),s((function(){if(void 0!==b.originalRowIndex&&"number"==typeof b.originalRowIndex){var e=w[b.originalRowIndex];e[i.accessor]!==C?k(e[i.accessor]):x[b.originalRowIndex][i.accessor]=C}}),[i.accessor,C,w,b.originalRowIndex,x]);return n("div",R?p({className:"st-cell-editing ".concat(I?"st-cell-odd-row":"")},{children:n(M,{onChange:function(e){k(e),null==u||u({accessor:i.accessor,newValue:e,newRowIndex:v,originalRowIndex:b.originalRowIndex,row:b})},setIsEditing:N,value:C})}):p({className:L,onDoubleClick:function(){return i.isEditable&&N(!0)},onMouseDown:function(){return f(v,a)},onMouseOver:function(){return g(v,a)},ref:r},{children:C}))})),S=function(){return n("div",{className:"st-row-separator"})},T=function(t){var o=t.getBorderClass,a=t.handleMouseDown,l=t.handleMouseOver,s=t.headers,i=t.hiddenColumns,c=t.isSelected,d=t.isTopLeftCell,f=t.isWidthDragging,h=t.onCellChange,b=t.shouldDisplayLastColumnCell,v=t.shouldPaginate,m=t.sortedRows,w=t.tableRef;return n(r,{children:m.map((function(r,t){return e(g,{children:[e(x,p({allowHorizontalAnimate:v,pauseAnimation:f,tableRef:w},{children:[s.map((function(e,s){if(i[e.accessor])return null;var f=r[e.accessor];return e.cellRenderer&&(f=e.cellRenderer(r)),n(L,{borderClass:o(t,s),colIndex:s,content:f,header:e,isSelected:c(t,s),isTopLeftCell:d(t,s),onCellChange:h,onMouseDown:function(){return a(t,s)},onMouseOver:function(){return l(t,s)},ref:u(),row:r,rowIndex:t},e.accessor)})),n(R,{ref:u(),visible:b})]})),t!==m.length-1&&n(S,{})]},r.originalRowIndex)}))})},B=function(r){var t=r.currentPage,o=r.hideFooter,a=r.nextIcon,l=r.onPageChange,s=r.prevIcon,i=r.rowsPerPage,c=r.shouldPaginate,d=r.totalRows,u=Math.ceil(d/i),f=t>1,h=t<u,g=function(e){e>=1&&e<=u&&l(e)};return o||!c?null:e("div",p({className:"st-footer"},{children:[n("button",p({className:"st-next-prev-btn ".concat(f?"":"disabled"),onClick:function(){return g(t-1)},disabled:!f},{children:s})),n("button",p({className:"st-next-prev-btn ".concat(h?"":"disabled"),onClick:function(){return g(t+1)},disabled:!h},{children:a})),Array.from({length:u},(function(e,r){return n("button",p({onClick:function(){return g(r+1)},className:"st-page-btn ".concat(t===r+1?"active":"")},{children:r+1}),r)}))]}))},z=function(e){var r=e.className;return n("svg",p({className:r,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"})}))},H=function(e){var r=e.className;return n("svg",p({className:r,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"})}))},O=function(e){var r=e.className;return n("svg",p({className:r,viewBox:"0 0 20 20",width:"20",height:"20",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M5.41 11.41L10 6.83l4.59 4.58L16 10l-6-6-6 6z"})}))},P=function(e){var r=e.className;return n("svg",p({className:r,viewBox:"0 0 20 20",width:"20",height:"20",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M5.41 7.59L10 12.17l4.59-4.58L16 9l-6 6-6-6z"})}))},j=function(r){var t=r.checked,a=void 0!==t&&t,l=r.children,s=r.onChange,i=o(a),c=i[0],d=i[1];return e("label",p({className:"st-checkbox-label"},{children:[n("input",{checked:c,className:"st-checkbox-input",onChange:function(){var e=!c;d(e),s&&s(e)},type:"checkbox"}),n("span",p({className:"st-checkbox-custom ".concat(c?"st-checked":"")},{children:c&&n("span",{className:"st-checkbox-checkmark"})})),l]}))},U=function(e){var r=e.headers,t=e.open,o=e.position;e.setOpen;var a=e.setHiddenColumns,l=e.hiddenColumns,s="left"===o?"left":"";return n("div",p({className:"st-column-editor-popout ".concat(t?"open":""," ").concat(s),onClick:function(e){return e.stopPropagation()}},{children:n("div",p({className:"st-column-editor-popout-content"},{children:r.map((function(e,r){return n(j,p({checked:l[e.accessor],onChange:function(n){var r;return a(p(p({},l),((r={})[e.accessor]=n,r)))}},{children:e.label}),r)}))}))}))},X=function(r){var t=r.columnEditorText,a=r.editColumns,l=r.headers,s=r.position,i=void 0===s?"right":s,c=r.setHiddenColumns,d=r.hiddenColumns,u=o(!1),f=u[0],h=u[1];return a?e("div",p({className:"st-column-editor ".concat(f?"open":""," ").concat(i),onClick:function(){return function(e){h(e)}(!f)}},{children:[n("div",p({className:"st-column-editor-text"},{children:t})),n(U,{headers:l,open:f,position:i,setOpen:h,setHiddenColumns:c,hiddenColumns:d})]})):null};!function(e,n){void 0===n&&(n={});var r=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&t.firstChild?t.insertBefore(o,t.firstChild):t.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('/* Import Nunito font from Google Fonts */\n@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap");\n\n:root {\n /* Slate Colors */\n --slate-50: #f8fafc;\n --slate-100: #f1f5f9;\n --slate-200: #e2e8f0;\n --slate-300: #cbd5e1;\n --slate-400: #94a3b8;\n --slate-500: #64748b;\n --slate-600: #475569;\n --slate-700: #334155;\n --slate-800: #1e293b;\n --slate-900: #0f172a;\n\n /* Blue Colors */\n --blue-50: #eff6ff;\n --blue-100: #dbeafe;\n --blue-200: #bfdbfe;\n --blue-300: #93c5fd;\n --blue-400: #60a5fa;\n --blue-500: #3b82f6;\n --blue-600: #2563eb;\n --blue-700: #1d4ed8;\n --blue-800: #1e40af;\n --blue-900: #1e3a8a;\n\n /* Orange Colors */\n --orange-50: #fff7ed;\n --orange-100: #ffedd5;\n --orange-200: #fed7aa;\n --orange-300: #fdba74;\n --orange-400: #fb923c;\n --orange-500: #f97316;\n --orange-600: #ea580c;\n --orange-700: #c2410c;\n --orange-800: #9a3412;\n --orange-900: #7c2d12;\n\n /* Amber Colors */\n --amber-50: #fffbeb;\n --amber-100: #fef3c7;\n --amber-200: #fde68a;\n --amber-300: #fcd34d;\n --amber-400: #fbbf24;\n --amber-500: #f59e0b;\n --amber-600: #d97706;\n --amber-700: #b45309;\n --amber-800: #92400e;\n --amber-900: #78350f;\n\n /* Customizable Variables */\n --st-border-radius: 4px;\n --st-border-color: var(--slate-300);\n --st-border-width: 1px;\n --st-resize-handle-color: var(--slate-300);\n --st-separator-border-color: var(--slate-300);\n --st-odd-row-background-color: var(--slate-100);\n --st-dragging-background-color: var(--blue-100);\n --st-selected-cell-background-color: var(--blue-200);\n --st-selected-first-cell-background-color: var(--amber-100);\n --st-border-top-color: var(--blue-500);\n --st-border-bottom-color: var(--blue-500);\n --st-border-left-color: var(--blue-500);\n --st-border-right-color: var(--blue-500);\n --st-border-top-white-color: white;\n --st-footer-background-color: white;\n --st-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);\n --st-cell-padding: 8px;\n}\n\n/* Global styles */\n* {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n}\n\n/* Apply Nunito as the default font */\nbody {\n font-family: "Nunito";\n}\n\n/* Wrapper for the table */\n.st-wrapper {\n position: relative;\n border: var(--st-border-width) solid var(--st-border-color);\n border-radius: var(--st-border-radius);\n max-height: 100dvh;\n overflow: hidden;\n}\n\n.st-table-wrapper {\n position: relative;\n display: flex;\n width: max-content;\n overflow: visible;\n height: 100%;\n width: 100%;\n}\n\n/* Main table styling */\n.st-table {\n position: relative;\n display: grid;\n border-collapse: collapse;\n table-layout: auto;\n white-space: nowrap;\n width: 100%;\n height: 100%;\n overflow: auto;\n}\n\n/* Styles for table header cells */\n.st-header-cell {\n position: sticky;\n top: 0;\n background-color: white;\n z-index: 1;\n font-weight: 600;\n\n display: flex;\n align-items: center;\n gap: 4px;\n border-top: var(--st-border-width) solid transparent;\n border-bottom: var(--st-border-width) solid var(--st-border-color);\n}\n.st-header-cell.clickable {\n cursor: pointer;\n}\n.st-header-cell.draggable {\n cursor: grab;\n}\n\n/* Common styles for table header and cells */\n.st-header-cell,\n.st-cell {\n color: var(--slate-800);\n overflow: hidden;\n}\n\n.st-cell.clickable {\n cursor: pointer;\n}\n\n.st-header-cell,\n.st-cell,\n.st-cell-editing {\n width: 100%;\n height: 40px;\n font-family: "Nunito";\n}\n\n.st-cell-editing {\n position: relative;\n}\n\n.st-header-label {\n flex: 1;\n}\n\n.st-header-label,\n.st-cell {\n user-select: none;\n padding: var(--st-cell-padding);\n text-align: left;\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n width: 100%;\n}\n.st-cell {\n position: relative;\n border: var(--st-border-width) solid transparent;\n}\n.st-sort-icon-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n}\n\n.st-sort-icon {\n fill: var(--slate-500);\n}\n\n.st-header-resize-handle {\n top: 0;\n right: 0;\n width: 5px;\n height: 20px;\n cursor: col-resize;\n background-color: var(--st-resize-handle-color);\n border-radius: 0.25rem;\n}\n\n.st-row-separator {\n height: 1px;\n background-color: var(--st-separator-border-color);\n grid-column: 1 / -1;\n}\n\n.st-cell-odd-row {\n background-color: var(--st-odd-row-background-color);\n}\n\n/* Style for a cell when it is being dragged */\n.st-dragging {\n background-color: var(--st-dragging-background-color);\n}\n\n/* Style for selected table cells */\n.st-cell-selected {\n background-color: var(--st-selected-cell-background-color);\n}\n\n/* Style for the first selected table cell */\n.st-cell-selected-first {\n background-color: var(--st-selected-first-cell-background-color);\n}\n\n/* Blue top border for cells */\n.st-selected-top-border {\n border-top: var(--st-border-width) solid var(--st-border-top-color);\n}\n\n/* Blue bottom border for cells */\n.st-selected-bottom-border {\n border-bottom: var(--st-border-width) solid var(--st-border-bottom-color);\n}\n\n/* Blue left border for cells */\n.st-selected-left-border {\n border-left: var(--st-border-width) solid var(--st-border-left-color);\n}\n\n/* Blue right border for cells */\n.st-selected-right-border {\n border-right: var(--st-border-width) solid var(--st-border-right-color);\n}\n\n/* White top border for cells */\n.st-selected-top-border-white {\n border-top: var(--st-border-width) solid var(--st-border-top-white-color);\n}\n\n.st-footer {\n display: flex;\n align-items: center;\n background-color: var(--st-footer-background-color);\n\n padding: 8px;\n\n border-top: var(--st-border-width) solid var(--st-border-color);\n}\n\n.st-next-prev-btn {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 4px;\n cursor: pointer;\n background-color: transparent;\n border: none;\n border-radius: 4px;\n transition: background-color 0.3s ease;\n}\n.st-next-prev-btn {\n fill: var(--slate-600);\n}\n.disabled > .st-next-prev-icon {\n cursor: not-allowed;\n fill: var(--slate-400);\n}\n\n.st-next-prev-btn:not(.disabled):hover {\n background-color: var(--slate-100);\n}\n\n.st-page-btn {\n margin-left: 4px;\n padding: 4px;\n cursor: pointer;\n background-color: transparent;\n color: var(--slate-600);\n border: none;\n border-radius: var(--st-border-radius);\n transition: background-color 0.3s ease;\n}\n\n.st-page-btn:hover {\n background-color: var(--slate-100);\n}\n\n.st-page-btn.active {\n background-color: var(--blue-500);\n color: white;\n}\n\n.editable-cell-input {\n position: absolute;\n top: 0;\n left: 0;\n border-radius: var(--st-border-radius);\n border: var(--st-border-width) solid var(--st-border-color);\n box-shadow: var(--st-shadow);\n z-index: 1;\n outline: none;\n height: 100%;\n width: 100%;\n padding: var(--st-cell-padding);\n font-size: 1rem;\n font-family: "Nunito";\n}\n.editable-cell-input:focus {\n border: var(--st-border-width) solid var(--blue-500);\n}\n.st-column-editor {\n position: relative;\n user-select: none;\n\n background: var(--st-footer-background-color);\n border-left: var(--st-border-width) solid var(--st-border-color);\n cursor: pointer;\n}\n\n.st-column-editor-text {\n padding: 8px 4px;\n\n writing-mode: vertical-rl;\n color: var(--slate-500);\n background-color: white;\n z-index: 2;\n}\n\n.st-column-editor.open,\n.st-column-editor.open .st-column-editor-text {\n background-color: var(--slate-100);\n}\n\n.st-column-editor-popout {\n position: absolute;\n top: 0;\n right: calc(100% + 1px);\n z-index: 1;\n\n height: 100%;\n background-color: var(--slate-100);\n\n transition: width 0.2s ease;\n overflow: hidden;\n width: 0;\n}\n.st-column-editor-popout-content {\n display: flex;\n flex-direction: column;\n overflow: auto;\n gap: 4px;\n padding: 8px 4px;\n border-left: var(--st-border-width) solid var(--st-border-color);\n height: 100%;\n}\n\n.st-column-editor-popout.open {\n width: 200px;\n}\n\n.st-column-editor-popout.left {\n transform: translateX(-100%);\n}\n\n.st-column-editor-popout.open.left {\n transform: translateX(0);\n}\n\n/* Checkbox styles */\n.st-checkbox-label {\n display: flex;\n align-items: center;\n cursor: pointer;\n gap: 8px;\n}\n\n.st-checkbox-input {\n display: none; /* Hide the default checkbox */\n}\n\n.st-checkbox-custom {\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 24px;\n height: 24px;\n\n border: var(--st-border-width) solid var(--slate-300);\n border-radius: var(--st-border-radius);\n\n background-color: white;\n transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.st-checkbox-custom.st-checked {\n background-color: var(--blue-500);\n border-color: var(--blue-500);\n}\n\n.st-checkbox-checkmark {\n width: 6px;\n height: 11px;\n border: solid white;\n border-width: 0 2px 2px 0;\n transform: rotate(45deg);\n}\n\n@keyframes slide-in-left {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(0);\n }\n}\n\n@keyframes slide-in-right {\n from {\n transform: translateX(100%);\n }\n to {\n transform: translateX(0);\n }\n}\n');var W=function(r){var t=r.columnEditorPosition,i=void 0===t?"right":t,c=r.columnEditorText,d=void 0===c?"Columns":c,u=r.columnResizing,f=void 0!==u&&u,h=r.defaultHeaders,g=r.draggable,w=void 0!==g&&g,x=r.editColumns,y=void 0!==x&&x,C=r.height,k=r.hideFooter,D=void 0!==k&&k;r.importStyles;var R=r.nextIcon,E=void 0===R?n(H,{className:"st-next-prev-icon"}):R,I=r.onCellChange,M=r.prevIcon,L=void 0===M?n(z,{className:"st-next-prev-icon"}):M,S=r.rows,j=r.rowsPerPage,U=void 0===j?10:j,W=r.selectableCells,F=void 0!==W&&W,V=r.shouldPaginate,Y=void 0!==V&&V,G=r.sortDownIcon,Q=void 0===G?n(P,{className:"st-sort-icon"}):G,q=r.sortUpIcon,J=void 0===q?n(O,{className:"st-sort-icon"}):q,K=b((function(){return S.map((function(e,n){return p(p({},e),{originalRowIndex:n})}))}),[S]),Z=a(null),$=o(!1),_=$[0],ee=$[1],ne=a(h),re=o(null),te=re[0],oe=re[1],ae=o({}),le=ae[0],se=ae[1],ie=o(1),ce=ie[0],de=ie[1],ue=b((function(){if(!te)return K;var e=function(e,n,r){var t=r?r.key:e[0],o="ascending";return r&&r.key.accessor===t.accessor&&"ascending"===r.direction&&(o="descending"),{sortedData:m([],n,!0).sort((function(e,n){return e[t.accessor]<n[t.accessor]?"ascending"===o?1:-1:e[t.accessor]>n[t.accessor]?"ascending"===o?-1:1:0})),newSortConfig:{key:t,direction:o}}}(ne.current,K,te).sortedData;return e}),[K,te]),fe=v((function(e){return e+1}),0)[1],he=function(e){var n=e.selectableCells,r=e.headers,t=e.rows,i=o([]),c=i[0],d=i[1],u=a(!1),f=a(null),h=l((function(){var e=c.reduce((function(e,n){var o=n.row,a=n.col;return e[o]||(e[o]=[]),e[o][a]=t[o][r[a].accessor],e}),{}),n=Object.values(e).map((function(e){return Object.values(e).join("\t")})).join("\n");navigator.clipboard.writeText(n)}),[c,t,r]);s((function(){var e=function(e){(e.ctrlKey||e.metaKey)&&"c"===e.key&&h()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[h,c]);var g=function(e,n){return c.some((function(r){return r.row===e&&r.col===n}))};return{selectedCells:c,handleMouseDown:function(e,r){n&&(u.current=!0,f.current={row:e,col:r},d([{row:e,col:r}]))},handleMouseOver:function(e,r){if(n&&u.current&&f.current){for(var t=[],o=Math.min(f.current.row,e),a=Math.max(f.current.row,e),l=Math.min(f.current.col,r),s=Math.max(f.current.col,r),i=o;i<=a;i++)for(var c=l;c<=s;c++)t.push({row:i,col:c});d(t)}},handleMouseUp:function(){u.current=!1,f.current=null},isSelected:g,getBorderClass:function(e,n){var r=[];return g(e-1,n)||r.push("st-selected-top-border"),g(e+1,n)||r.push("st-selected-bottom-border"),g(e,n-1)||r.push("st-selected-left-border"),g(e,n+1)||r.push("st-selected-right-border"),r.join(" ")},isTopLeftCell:function(e,n){return e===Math.min.apply(Math,c.map((function(e){return e.row})))&&n===Math.min.apply(Math,c.map((function(e){return e.col})))},setSelectedCells:d}}({selectableCells:F,headers:ne.current,rows:ue}),ge=he.handleMouseDown,be=he.handleMouseOver,ve=he.handleMouseUp,pe=he.isSelected,me=he.getBorderClass,we=he.isTopLeftCell,xe=he.setSelectedCells,ye=ne.current.filter((function(e){return!e.hide})),Ce=b((function(){return!!Z.current&&ye.reduce((function(e,n){return e+n.width}),0)<Z.current.clientWidth}),[ye]),ke=Y?ue.slice((ce-1)*U,ce*U):ue;s((function(){var e=function(e){e.target.closest(".st-cell")||xe([])};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[xe]);var De=b((function(){return"".concat(ye.filter((function(e){return!0!==le[e.accessor]})).map((function(e){return"".concat(e.width,"px")})).join(" ")," 1fr")}),[ye,le]);return n(A.Provider,p({value:{rows:S,tableRows:K}},{children:e("div",p({className:"st-wrapper",style:C?{height:C}:{}},{children:[e("div",p({className:"st-table-wrapper"},{children:[e("div",p({className:"st-table",onMouseUp:ve,onMouseLeave:ve,ref:Z,style:{gridTemplateColumns:De}},{children:[n(N,{columnResizing:f,draggable:w,forceUpdate:fe,headersRef:ne,hiddenColumns:le,isWidthDragging:_,onSort:function(e,n){oe((function(r){return(null==r?void 0:r.key.accessor)!==n?{key:ne.current[e],direction:"ascending"}:"ascending"===(null==r?void 0:r.direction)?{key:ne.current[e],direction:"descending"}:null}))},onTableHeaderDragEnd:function(e){ne.current=e,fe()},setIsWidthDragging:ee,shouldDisplayLastColumnCell:Ce,sort:te,sortDownIcon:Q,sortUpIcon:J,tableRef:Z}),n(T,{getBorderClass:me,handleMouseDown:ge,handleMouseOver:be,headers:ne.current,hiddenColumns:le,isSelected:pe,isTopLeftCell:we,isWidthDragging:_,onCellChange:I,shouldDisplayLastColumnCell:Ce,shouldPaginate:Y,sortedRows:ke,tableRef:Z})]})),n(X,{headers:ne.current,columnEditorText:d,editColumns:y,position:i,setHiddenColumns:se,hiddenColumns:le})]})),n(B,{currentPage:ce,hideFooter:D,nextIcon:E,onPageChange:de,prevIcon:L,rowsPerPage:U,shouldPaginate:Y,totalRows:ue.length})]}))}))};export{W 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 l,useEffect as s,Children as i,useLayoutEffect as c,forwardRef as d,createRef as u,createContext as f,useContext as h,Fragment as g,useMemo as v,useReducer as b}from"react";var p=function(){return p=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},p.apply(this,arguments)};function m(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 w=function(e){var n={};return i.forEach(e,(function(e){if(e&&e.ref&&e.ref.current){var r=e.ref.current.getBoundingClientRect();n[e.key]=r}})),n},x=function(e){var n,r,l=e.allowHorizontalAnimate,i=void 0===l||l,d=e.children,u=e.pauseAnimation,f=e.tableRef,h=a(!1),g=o({}),v=g[0],b=g[1],p=o({}),m=p[0],x=p[1],C=(n=d,r=a(),s((function(){r.current=n}),[n]),r.current);return c((function(){var e=w(d);b(e)}),[d]),c((function(){var e=w(C);x(e);var n=f.current,r=function(){h.current=!0;var e=w(C);b(e),x(e)},t=function(){h.current=!1};return null==n||n.addEventListener("scroll",r),null==n||n.addEventListener("scrollend",t),function(){null==n||n.removeEventListener("scroll",r),null==n||n.removeEventListener("scrollend",t)}}),[C,f]),s((function(){u||h.current||Object.keys(m).length&&t.Children.forEach(d,(function(e){if(e){var n=e.ref.current,r=m[e.key],t=v[e.key];if(r&&t){var o=r.left-t.left,a=i?0:r.top-t.top,l=Math.abs(o),s=Math.abs(a);(l>10||s>10)&&requestAnimationFrame((function(){n.style.transform="translate(".concat(o,"px, ").concat(a,"px)"),n.style.transition="transform 0s, opacity 0s",requestAnimationFrame((function(){n.style.transform="",n.style.transition="transform 300ms ease-out, opacity 300ms ease-out"}))}))}}}))}),[i,v,d,u,m]),d},C=!1,y=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(!C&&(t.current=e,e.accessor!==(null===(a=n.current)||void 0===a?void 0:a.accessor)&&null!==n.current&&!C)){if(C=!0,!r.current)return;var l=m([],r.current,!0),s=l.findIndex((function(e){var r;return e.accessor===(null===(r=n.current)||void 0===r?void 0:r.accessor)})),i=l.findIndex((function(n){return n.accessor===e.accessor}));if(void 0===s||void 0===i)return;var c=l.splice(s,1)[0];l.splice(i,0,c),JSON.stringify(l)!==JSON.stringify(r.current)&&setTimeout((function(){o(l),setTimeout((function(){C=!1}),500)}),50)}}(e)},handleDragEnd:function(){n.current=null,t.current=null}}},k=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))}},D=d((function(r,t){var l,i=r.draggable,c=r.draggedHeaderRef,d=r.columnResizing,u=r.forceUpdate,f=r.headersRef,h=r.hoveredHeaderRef,g=r.index,v=r.onSort,b=r.onTableHeaderDragEnd,m=r.setIsWidthDragging,w=r.sort,x=r.sortDownIcon,C=r.sortUpIcon,D=a({pageX:0,pageY:0}),N=o(!1),R=N[0],E=N[1],I=null===(l=f.current)||void 0===l?void 0:l[g],M=Boolean(null==I?void 0:I.isSortable),A="st-header-cell ".concat(I===h.current?"st-hovered":""," ").concat(R?"st-dragging":""," ").concat(M?"clickable":""," ").concat(i&&!M?"draggable":""),L=y({draggedHeaderRef:c,headersRef:f,hoveredHeaderRef:h,onTableHeaderDragEnd:b}),S=L.handleDragStart,B=L.handleDragOver,T=L.handleDragEnd,z=a(k((function(e){B(e)}),100)).current,H=function(e){e.isSortable&&v(g,e.accessor)};return s((function(){var e=function(e){var n=new Image;n.src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",e.dataTransfer.setDragImage(n,0,0)};return document.addEventListener("dragend",e,!1),function(){document.removeEventListener("dragend",e)}}),[]),I?e("div",p({className:A,ref:t,style:{width:I.width}},{children:[n("div",p({className:"st-header-label",draggable:i,onClick:function(){return H(I)},onDragStart:function(e){i&&I&&(e.dataTransfer.dropEffect="move",function(e){E(!0),S(e)}(I))},onDragOver:function(e){return function(e,n){e.preventDefault(),e.dataTransfer.dropEffect="move";var r=e.pageX,t=e.pageY;r===D.current.pageX&&t===D.current.pageY||(D.current={pageX:r,pageY:t},z(n,e))}(e,I)},onDragEnd:function(e){e.preventDefault(),e.dataTransfer.dropEffect="move",E(!1),T()},onMouseEnter:function(){return document.body.style.overflow="hidden"},onMouseLeave:function(){return document.body.style.overflow="auto"}},{children:null==I?void 0:I.label})),w&&w.key.accessor===I.accessor&&e("div",p({className:"st-sort-icon-container",onClick:function(){return H(I)}},{children:["ascending"===w.direction&&C&&C,"descending"===w.direction&&x&&x]})),d&&n("div",{className:"st-header-resize-handle",onMouseDown:function(e){m(!0),e.preventDefault();var n=e.clientX;if(I){var r=I.width,t=k((function(e){var t=Math.max(r+(e.clientX-n),40);I&&(f.current[g].width=t,u())}),10),o=function(){document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",o),m(!1)};document.addEventListener("mousemove",t),document.addEventListener("mouseup",o)}}})]})):null})),N=d((function(e,r){return e.visible?n("div",{className:"st-cell",ref:r}):n("div",{ref:r})})),R=function(t){var o,l=t.draggable,s=t.columnResizing,i=t.forceUpdate,c=t.headersRef,d=t.hiddenColumns,f=t.isWidthDragging,h=t.onSort,g=t.onTableHeaderDragEnd,v=t.setIsWidthDragging,b=t.shouldDisplayLastColumnCell,m=t.sort,w=t.sortDownIcon,C=t.sortUpIcon,y=t.tableRef,k=a(null),R=a(null);return n(r,{children:e(x,p({pauseAnimation:f,tableRef:y},{children:[null===(o=c.current)||void 0===o?void 0:o.map((function(e,r){return d[e.accessor]?null:n(D,{draggable:l,draggedHeaderRef:k,columnResizing:s,forceUpdate:i,headersRef:c,hoveredHeaderRef:R,index:r,onSort:h,onTableHeaderDragEnd:g,ref:u(),setIsWidthDragging:v,sort:m,sortDownIcon:w,sortUpIcon:C},e.accessor)})),n(N,{ref:u(),visible:b})]}))})},E=function(r){var t=r.value,o=r.onBlur,a=r.onChange;return e("select",p({value:t.toString(),onBlur:o,onChange:function(e){var n=e.target.value;a("true"===n)}},{children:[n("option",p({value:"true"},{children:"True"})),n("option",p({value:"false"},{children:"False"}))]}))},I=function(e){var r=e.defaultValue,t=e.onBlur,o=e.onChange,l=a(null);return n("input",{className:"editable-cell-input",ref:l,autoFocus:!0,type:"text",defaultValue:null!=r?r:"",onBlur:t,onChange:function(e){var n=e.target.value;o(n)}})},M=function(e){var r=e.defaultValue,t=e.onBlur,o=e.onChange,l=a(null);return n("input",{className:"editable-cell-input",ref:l,autoFocus:!0,defaultValue:r.toString(),onBlur:t,onChange:function(e){var n=e.target.value;/^\d*\.?\d*$/.test(n)&&o(n)}})},A=function(e){var t=e.onChange,o=e.setIsEditing,a=e.value,l=function(e){null==t||t(e)},s=function(){o(!1)};return n(r,{children:"string"==typeof a||null==a?n(I,{defaultValue:a,onBlur:s,onChange:l}):"boolean"==typeof a?n(E,{onBlur:s,onChange:l,value:a}):"number"==typeof a?n(M,{defaultValue:a,onBlur:s,onChange:l}):null})},L=f({rows:[],tableRows:[]}),S=d((function(e,r){var t=e.borderClass,a=e.colIndex,l=e.content,i=e.header,c=e.isSelected,d=e.isTopLeftCell,u=e.onCellChange,f=e.onMouseDown,g=e.onMouseOver,v=e.row,b=e.rowIndex,m=h(L),w=m.rows,x=m.tableRows,C=o(l),y=C[0],k=C[1],D=o(!1),N=D[0],R=D[1],E=Boolean(null==i?void 0:i.isEditable),I=b%2==0,M="st-cell ".concat(c?d?"st-cell-selected-first-cell ".concat(t):"st-cell-selected ".concat(t):""," ").concat(I?"st-cell-odd-row":""," ").concat(E?"clickable":"");s((function(){k(l)}),[l]),s((function(){if(void 0!==v.originalRowIndex&&"number"==typeof v.originalRowIndex){var e=w[v.originalRowIndex];e[i.accessor]!==y?k(e[i.accessor]):x[v.originalRowIndex][i.accessor]=y}}),[i.accessor,y,w,v.originalRowIndex,x]);return n("div",N?p({className:"st-cell-editing ".concat(I?"st-cell-odd-row":"")},{children:n(A,{onChange:function(e){k(e),null==u||u({accessor:i.accessor,newValue:e,newRowIndex:b,originalRowIndex:v.originalRowIndex,row:v})},setIsEditing:R,value:y})}):p({className:M,onDoubleClick:function(){return i.isEditable&&R(!0)},onMouseDown:function(){return f(b,a)},onMouseOver:function(){return g(b,a)},ref:r},{children:y}))})),B=function(){return n("div",{className:"st-row-separator"})},T=function(t){var o=t.getBorderClass,a=t.handleMouseDown,l=t.handleMouseOver,s=t.headers,i=t.hiddenColumns,c=t.isSelected,d=t.isTopLeftCell,f=t.isWidthDragging,h=t.onCellChange,v=t.shouldDisplayLastColumnCell,b=t.shouldPaginate,m=t.sortedRows,w=t.tableRef;return n(r,{children:m.map((function(r,t){return e(g,{children:[e(x,p({allowHorizontalAnimate:b,pauseAnimation:f,tableRef:w},{children:[s.map((function(e,s){if(i[e.accessor])return null;var f=r[e.accessor];return e.cellRenderer&&(f=e.cellRenderer(r)),n(S,{borderClass:o(t,s),colIndex:s,content:f,header:e,isSelected:c(t,s),isTopLeftCell:d(t,s),onCellChange:h,onMouseDown:function(){return a(t,s)},onMouseOver:function(){return l(t,s)},ref:u(),row:r,rowIndex:t},e.accessor)})),n(N,{ref:u(),visible:v})]})),t!==m.length-1&&n(B,{})]},r.originalRowIndex)}))})},z=function(r){var t=r.currentPage,o=r.hideFooter,a=r.nextIcon,l=r.onPageChange,s=r.prevIcon,i=r.rowsPerPage,c=r.shouldPaginate,d=r.totalRows,u=Math.ceil(d/i),f=t>1,h=t<u,g=function(e){e>=1&&e<=u&&l(e)};return o||!c?null:e("div",p({className:"st-footer"},{children:[n("button",p({className:"st-next-prev-btn ".concat(f?"":"disabled"),onClick:function(){return g(t-1)},disabled:!f},{children:s})),n("button",p({className:"st-next-prev-btn ".concat(h?"":"disabled"),onClick:function(){return g(t+1)},disabled:!h},{children:a})),Array.from({length:u},(function(e,r){return n("button",p({onClick:function(){return g(r+1)},className:"st-page-btn ".concat(t===r+1?"active":"")},{children:r+1}),r)}))]}))},H=function(e){var r=e.className;return n("svg",p({className:r,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"})}))},O=function(e){var r=e.className;return n("svg",p({className:r,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"})}))},P=function(e){var r=e.className;return n("svg",p({className:r,viewBox:"0 0 20 20",width:"20",height:"20",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M5.41 11.41L10 6.83l4.59 4.58L16 10l-6-6-6 6z"})}))},j=function(e){var r=e.className;return n("svg",p({className:r,viewBox:"0 0 20 20",width:"20",height:"20",xmlns:"http://www.w3.org/2000/svg"},{children:n("path",{d:"M5.41 7.59L10 12.17l4.59-4.58L16 9l-6 6-6-6z"})}))},U=function(r){var t=r.checked,a=void 0!==t&&t,l=r.children,s=r.onChange,i=o(a),c=i[0],d=i[1];return e("label",p({className:"st-checkbox-label"},{children:[n("input",{checked:c,className:"st-checkbox-input",onChange:function(){var e=!c;d(e),s&&s(e)},type:"checkbox"}),n("span",p({className:"st-checkbox-custom ".concat(c?"st-checked":"")},{children:c&&n("span",{className:"st-checkbox-checkmark"})})),l]}))},X=function(e){var r=e.headers,t=e.open,o=e.position;e.setOpen;var a=e.setHiddenColumns,l=e.hiddenColumns,s="left"===o?"left":"";return n("div",p({className:"st-column-editor-popout ".concat(t?"open":""," ").concat(s),onClick:function(e){return e.stopPropagation()}},{children:n("div",p({className:"st-column-editor-popout-content"},{children:r.map((function(e,r){return n(U,p({checked:l[e.accessor],onChange:function(n){var r;return a(p(p({},l),((r={})[e.accessor]=n,r)))}},{children:e.label}),r)}))}))}))},W=function(r){var t=r.columnEditorText,a=r.editColumns,l=r.headers,s=r.position,i=void 0===s?"right":s,c=r.setHiddenColumns,d=r.hiddenColumns,u=o(!1),f=u[0],h=u[1];return a?e("div",p({className:"st-column-editor ".concat(f?"open":""," ").concat(i),onClick:function(){return function(e){h(e)}(!f)}},{children:[n("div",p({className:"st-column-editor-text"},{children:t})),n(X,{headers:l,open:f,position:i,setOpen:h,setHiddenColumns:c,hiddenColumns:d})]})):null};!function(e,n){void 0===n&&(n={});var r=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&t.firstChild?t.insertBefore(o,t.firstChild):t.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('/* Import Nunito font from Google Fonts */\n@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap");\n\n:root {\n /* Slate Colors */\n --slate-50: #f8fafc;\n --slate-100: #f1f5f9;\n --slate-200: #e2e8f0;\n --slate-300: #cbd5e1;\n --slate-400: #94a3b8;\n --slate-500: #64748b;\n --slate-600: #475569;\n --slate-700: #334155;\n --slate-800: #1e293b;\n --slate-900: #0f172a;\n\n /* Blue Colors */\n --blue-50: #eff6ff;\n --blue-100: #dbeafe;\n --blue-200: #bfdbfe;\n --blue-300: #93c5fd;\n --blue-400: #60a5fa;\n --blue-500: #3b82f6;\n --blue-600: #2563eb;\n --blue-700: #1d4ed8;\n --blue-800: #1e40af;\n --blue-900: #1e3a8a;\n\n /* Orange Colors */\n --orange-50: #fff7ed;\n --orange-100: #ffedd5;\n --orange-200: #fed7aa;\n --orange-300: #fdba74;\n --orange-400: #fb923c;\n --orange-500: #f97316;\n --orange-600: #ea580c;\n --orange-700: #c2410c;\n --orange-800: #9a3412;\n --orange-900: #7c2d12;\n\n /* Amber Colors */\n --amber-50: #fffbeb;\n --amber-100: #fef3c7;\n --amber-200: #fde68a;\n --amber-300: #fcd34d;\n --amber-400: #fbbf24;\n --amber-500: #f59e0b;\n --amber-600: #d97706;\n --amber-700: #b45309;\n --amber-800: #92400e;\n --amber-900: #78350f;\n\n /* Customizable Variables */\n --st-border-radius: 4px;\n --st-border-color: var(--slate-300);\n --st-border-width: 1px;\n --st-resize-handle-color: var(--slate-300);\n --st-separator-border-color: var(--slate-300);\n --st-odd-row-background-color: var(--slate-100);\n --st-dragging-background-color: var(--blue-100);\n --st-selected-cell-background-color: var(--blue-200);\n --st-selected-first-cell-background-color: var(--amber-100);\n --st-border-top-color: var(--blue-500);\n --st-border-bottom-color: var(--blue-500);\n --st-border-left-color: var(--blue-500);\n --st-border-right-color: var(--blue-500);\n --st-border-top-white-color: white;\n --st-footer-background-color: white;\n --st-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);\n --st-cell-padding: 8px;\n}\n\n/* Global styles */\n* {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n}\n\n/* Apply Nunito as the default font */\nbody {\n font-family: "Nunito";\n}\n\n/* Wrapper for the table */\n.st-wrapper {\n position: relative;\n border: var(--st-border-width) solid var(--st-border-color);\n border-radius: var(--st-border-radius);\n max-height: 100dvh;\n overflow: hidden;\n}\n\n.st-table-wrapper {\n position: relative;\n display: flex;\n width: max-content;\n overflow: visible;\n height: 100%;\n width: 100%;\n}\n\n/* Main table styling */\n.st-table {\n position: relative;\n display: grid;\n border-collapse: collapse;\n table-layout: auto;\n white-space: nowrap;\n width: 100%;\n height: 100%;\n overflow: auto;\n}\n\n/* Styles for table header cells */\n.st-header-cell {\n position: sticky;\n top: 0;\n background-color: white;\n z-index: 1;\n font-weight: 600;\n\n display: flex;\n align-items: center;\n gap: 4px;\n border-top: var(--st-border-width) solid transparent;\n border-bottom: var(--st-border-width) solid var(--st-border-color);\n}\n.st-header-cell.clickable {\n cursor: pointer;\n}\n.st-header-cell.draggable {\n cursor: grab;\n}\n\n/* Common styles for table header and cells */\n.st-header-cell,\n.st-cell {\n color: var(--slate-800);\n overflow: hidden;\n}\n\n.st-cell.clickable {\n cursor: pointer;\n}\n\n.st-header-cell,\n.st-cell,\n.st-cell-editing {\n width: 100%;\n height: 40px;\n font-family: "Nunito";\n}\n\n.st-cell-editing {\n position: relative;\n}\n\n.st-header-label {\n flex: 1;\n}\n\n.st-header-label,\n.st-cell {\n user-select: none;\n padding: var(--st-cell-padding);\n text-align: left;\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n width: 100%;\n}\n.st-cell {\n position: relative;\n border: var(--st-border-width) solid transparent;\n}\n.st-sort-icon-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n}\n\n.st-sort-icon {\n fill: var(--slate-500);\n}\n\n.st-header-resize-handle {\n top: 0;\n right: 0;\n width: 5px;\n height: 20px;\n cursor: col-resize;\n background-color: var(--st-resize-handle-color);\n border-radius: 0.25rem;\n}\n\n.st-row-separator {\n height: 1px;\n background-color: var(--st-separator-border-color);\n grid-column: 1 / -1;\n}\n\n.st-cell-odd-row {\n background-color: var(--st-odd-row-background-color);\n}\n\n/* Style for a cell when it is being dragged */\n.st-dragging {\n background-color: var(--st-dragging-background-color);\n}\n\n/* Style for selected table cells */\n.st-cell-selected {\n background-color: var(--st-selected-cell-background-color);\n}\n\n/* Style for the first selected table cell */\n.st-cell-selected-first {\n background-color: var(--st-selected-first-cell-background-color);\n}\n\n/* Blue top border for cells */\n.st-selected-top-border {\n border-top: var(--st-border-width) solid var(--st-border-top-color);\n}\n\n/* Blue bottom border for cells */\n.st-selected-bottom-border {\n border-bottom: var(--st-border-width) solid var(--st-border-bottom-color);\n}\n\n/* Blue left border for cells */\n.st-selected-left-border {\n border-left: var(--st-border-width) solid var(--st-border-left-color);\n}\n\n/* Blue right border for cells */\n.st-selected-right-border {\n border-right: var(--st-border-width) solid var(--st-border-right-color);\n}\n\n/* White top border for cells */\n.st-selected-top-border-white {\n border-top: var(--st-border-width) solid var(--st-border-top-white-color);\n}\n\n.st-footer {\n display: flex;\n align-items: center;\n background-color: var(--st-footer-background-color);\n\n padding: 8px;\n\n border-top: var(--st-border-width) solid var(--st-border-color);\n}\n\n.st-next-prev-btn {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 4px;\n cursor: pointer;\n background-color: transparent;\n border: none;\n border-radius: 4px;\n transition: background-color 0.3s ease;\n}\n.st-next-prev-btn {\n fill: var(--slate-600);\n}\n.disabled > .st-next-prev-icon {\n cursor: not-allowed;\n fill: var(--slate-400);\n}\n\n.st-next-prev-btn:not(.disabled):hover {\n background-color: var(--slate-100);\n}\n\n.st-page-btn {\n margin-left: 4px;\n padding: 4px;\n cursor: pointer;\n background-color: transparent;\n color: var(--slate-600);\n border: none;\n border-radius: var(--st-border-radius);\n transition: background-color 0.3s ease;\n}\n\n.st-page-btn:hover {\n background-color: var(--slate-100);\n}\n\n.st-page-btn.active {\n background-color: var(--blue-500);\n color: white;\n}\n\n.editable-cell-input {\n position: absolute;\n top: 0;\n left: 0;\n border-radius: var(--st-border-radius);\n border: var(--st-border-width) solid var(--st-border-color);\n box-shadow: var(--st-shadow);\n z-index: 1;\n outline: none;\n height: 100%;\n width: 100%;\n padding: var(--st-cell-padding);\n font-size: 1rem;\n font-family: "Nunito";\n}\n.editable-cell-input:focus {\n border: var(--st-border-width) solid var(--blue-500);\n}\n.st-column-editor {\n position: relative;\n user-select: none;\n\n background: var(--st-footer-background-color);\n border-left: var(--st-border-width) solid var(--st-border-color);\n cursor: pointer;\n}\n\n.st-column-editor-text {\n padding: 8px 4px;\n\n writing-mode: vertical-rl;\n color: var(--slate-500);\n background-color: white;\n z-index: 2;\n}\n\n.st-column-editor.open,\n.st-column-editor.open .st-column-editor-text {\n background-color: var(--slate-100);\n}\n\n.st-column-editor-popout {\n position: absolute;\n top: 0;\n right: calc(100% + 1px);\n z-index: 1;\n\n height: 100%;\n background-color: var(--slate-100);\n\n transition: width 0.2s ease;\n overflow: hidden;\n width: 0;\n}\n.st-column-editor-popout-content {\n display: flex;\n flex-direction: column;\n overflow: auto;\n gap: 4px;\n padding: 8px 4px;\n border-left: var(--st-border-width) solid var(--st-border-color);\n height: 100%;\n}\n\n.st-column-editor-popout.open {\n width: 200px;\n}\n\n.st-column-editor-popout.left {\n transform: translateX(-100%);\n}\n\n.st-column-editor-popout.open.left {\n transform: translateX(0);\n}\n\n/* Checkbox styles */\n.st-checkbox-label {\n display: flex;\n align-items: center;\n cursor: pointer;\n gap: 8px;\n}\n\n.st-checkbox-input {\n display: none; /* Hide the default checkbox */\n}\n\n.st-checkbox-custom {\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 24px;\n height: 24px;\n\n border: var(--st-border-width) solid var(--slate-300);\n border-radius: var(--st-border-radius);\n\n background-color: white;\n transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.st-checkbox-custom.st-checked {\n background-color: var(--blue-500);\n border-color: var(--blue-500);\n}\n\n.st-checkbox-checkmark {\n width: 6px;\n height: 11px;\n border: solid white;\n border-width: 0 2px 2px 0;\n transform: rotate(45deg);\n}\n\n@keyframes slide-in-left {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(0);\n }\n}\n\n@keyframes slide-in-right {\n from {\n transform: translateX(100%);\n }\n to {\n transform: translateX(0);\n }\n}\n');var F=function(r){var t=r.columnEditorPosition,i=void 0===t?"right":t,c=r.columnEditorText,d=void 0===c?"Columns":c,u=r.columnResizing,f=void 0!==u&&u,h=r.defaultHeaders,g=r.draggable,w=void 0!==g&&g,x=r.editColumns,C=void 0!==x&&x,y=r.height,k=r.hideFooter,D=void 0!==k&&k;r.importStyles;var N=r.nextIcon,E=void 0===N?n(O,{className:"st-next-prev-icon"}):N,I=r.onCellChange,M=r.prevIcon,A=void 0===M?n(H,{className:"st-next-prev-icon"}):M,S=r.rows,B=r.rowsPerPage,U=void 0===B?10:B,X=r.selectableCells,F=void 0!==X&&X,V=r.shouldPaginate,Y=void 0!==V&&V,G=r.sortDownIcon,Q=void 0===G?n(j,{className:"st-sort-icon"}):G,q=r.sortUpIcon,J=void 0===q?n(P,{className:"st-sort-icon"}):q,K=v((function(){return S.map((function(e,n){return p(p({},e),{originalRowIndex:n})}))}),[S]),$=a(null),Z=o(!1),_=Z[0],ee=Z[1],ne=a(h),re=o(null),te=re[0],oe=re[1],ae=o({}),le=ae[0],se=ae[1],ie=o(1),ce=ie[0],de=ie[1],ue=v((function(){if(!te)return K;var e=function(e,n,r){var t=r?r.key:e[0],o="ascending";return r&&r.key.accessor===t.accessor&&"ascending"===r.direction&&(o="descending"),{sortedData:m([],n,!0).sort((function(e,n){return e[t.accessor]<n[t.accessor]?"ascending"===o?1:-1:e[t.accessor]>n[t.accessor]?"ascending"===o?-1:1:0})),newSortConfig:{key:t,direction:o}}}(ne.current,K,te).sortedData;return e}),[K,te]),fe=b((function(e){return e+1}),0)[1],he=function(e){var n=e.selectableCells,r=e.headers,t=e.rows,i=o([]),c=i[0],d=i[1],u=a(!1),f=a(null),h=l((function(){var e=c.reduce((function(e,n){var o=n.row,a=n.col;return e[o]||(e[o]=[]),e[o][a]=t[o][r[a].accessor],e}),{}),n=Object.values(e).map((function(e){return Object.values(e).join("\t")})).join("\n");navigator.clipboard.writeText(n)}),[c,t,r]);s((function(){var e=function(e){(e.ctrlKey||e.metaKey)&&"c"===e.key&&h()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[h,c]);var g=function(e,n){return c.some((function(r){return r.row===e&&r.col===n}))};return{selectedCells:c,handleMouseDown:function(e,r){n&&(u.current=!0,f.current={row:e,col:r},d([{row:e,col:r}]))},handleMouseOver:function(e,r){if(n&&u.current&&f.current){for(var t=[],o=Math.min(f.current.row,e),a=Math.max(f.current.row,e),l=Math.min(f.current.col,r),s=Math.max(f.current.col,r),i=o;i<=a;i++)for(var c=l;c<=s;c++)t.push({row:i,col:c});d(t)}},handleMouseUp:function(){u.current=!1,f.current=null},isSelected:g,getBorderClass:function(e,n){var r=[];return g(e-1,n)||r.push("st-selected-top-border"),g(e+1,n)||r.push("st-selected-bottom-border"),g(e,n-1)||r.push("st-selected-left-border"),g(e,n+1)||r.push("st-selected-right-border"),r.join(" ")},isTopLeftCell:function(e,n){return e===Math.min.apply(Math,c.map((function(e){return e.row})))&&n===Math.min.apply(Math,c.map((function(e){return e.col})))},setSelectedCells:d}}({selectableCells:F,headers:ne.current,rows:ue}),ge=he.handleMouseDown,ve=he.handleMouseOver,be=he.handleMouseUp,pe=he.isSelected,me=he.getBorderClass,we=he.isTopLeftCell,xe=he.setSelectedCells,Ce=ne.current.filter((function(e){return!e.hide})),ye=v((function(){return!!$.current&&Ce.reduce((function(e,n){return e+n.width}),0)<$.current.clientWidth}),[Ce]),ke=Y?ue.slice((ce-1)*U,ce*U):ue;s((function(){var e=function(e){e.target.closest(".st-cell")||xe([])};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[xe]);var De=v((function(){return"".concat(Ce.filter((function(e){return!0!==le[e.accessor]})).map((function(e){return"".concat(e.width,"px")})).join(" ")," 1fr")}),[Ce,le]);return n(L.Provider,p({value:{rows:S,tableRows:K}},{children:e("div",p({className:"st-wrapper",style:y?{height:y}:{}},{children:[e("div",p({className:"st-table-wrapper"},{children:[e("div",p({className:"st-table",onMouseUp:be,onMouseLeave:be,ref:$,style:{gridTemplateColumns:De}},{children:[n(R,{columnResizing:f,draggable:w,forceUpdate:fe,headersRef:ne,hiddenColumns:le,isWidthDragging:_,onSort:function(e,n){oe((function(r){return(null==r?void 0:r.key.accessor)!==n?{key:ne.current[e],direction:"ascending"}:"ascending"===(null==r?void 0:r.direction)?{key:ne.current[e],direction:"descending"}:null}))},onTableHeaderDragEnd:function(e){ne.current=e,fe()},setIsWidthDragging:ee,shouldDisplayLastColumnCell:ye,sort:te,sortDownIcon:Q,sortUpIcon:J,tableRef:$}),n(T,{getBorderClass:me,handleMouseDown:ge,handleMouseOver:ve,headers:ne.current,hiddenColumns:le,isSelected:pe,isTopLeftCell:we,isWidthDragging:_,onCellChange:I,shouldDisplayLastColumnCell:ye,shouldPaginate:Y,sortedRows:ke,tableRef:$})]})),n(W,{headers:ne.current,columnEditorText:d,editColumns:C,position:i,setHiddenColumns:se,hiddenColumns:le})]})),n(z,{currentPage:ce,hideFooter:D,nextIcon:E,onPageChange:de,prevIcon:A,rowsPerPage:U,shouldPaginate:Y,totalRows:ue.length})]}))}))};export{F as SimpleTable};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-table-core",
3
- "version": "0.5.4",
3
+ "version": "0.5.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- interface TextInputProps {
3
- defaultValue: string;
4
- onBlur: () => void;
5
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
6
- }
7
- declare const TextEdit: ({ defaultValue, onBlur, onChange }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
8
- export default TextEdit;