@instincthub/react-ui 0.1.12 → 0.1.13

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,2 +1,2 @@
1
- import{slicedToArray as e,objectSpread2 as n,defineProperty as t,toConsumableArray as i,asyncToGenerator as r,regeneratorRuntime as c}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as a}from"react/jsx-runtime";import l,{useRef as u,useState as s,useCallback as d,useEffect as h,useMemo as m}from"react";import f from"@mui/icons-material/FileDownloadOutlined";import b from"@mui/icons-material/RefreshOutlined";import p from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/FilterAltOutlined";import g from"@mui/icons-material/FilterAltOffOutlined";import N from"@mui/icons-material/ExpandMoreOutlined";import x from"@mui/icons-material/ExpandLessOutlined";import y from"@mui/icons-material/VisibilityOutlined";import C from"@mui/icons-material/EditOutlined";import k from"@mui/icons-material/DeleteOutlined";import w from"@mui/icons-material/UnfoldLessOutlined";var S=function(S){var O=S.columns,L=S.data,E=S.isLoading,P=void 0!==E&&E,M=S.emptyStateMessage,R=void 0===M?"No data available":M,F=S.emptyStateIcon,j=void 0===F?o(p,{}):F,A=S.title,D=S.showSearch,H=void 0!==D&&D,U=S.pagination,V=void 0===U||U,B=S.rowsPerPageOptions,I=void 0===B?[10,25,50]:B,J=S.defaultRowsPerPage,T=void 0===J?10:J,_=S.actions,G=S.onRowClick,X=S.keyExtractor,Y=void 0===X?function(e,n){return n}:X,q=S.hideHeaderOnMobile,z=void 0!==q&&q,K=S.stickyHeader,Q=void 0!==K&&K,W=S.maxHeight,Z=S.sortable,$=void 0===Z||Z,ee=S.defaultSortColumn,ne=S.defaultSortDirection,te=void 0===ne?"asc":ne,ie=S.onSort,re=S.onFilter,ce=S.selectable,oe=void 0!==ce&&ce,ae=S.onSelectionChange,le=S.expandable,ue=void 0!==le&&le,se=S.renderExpandedRow,de=S.exportOptions,he=S.refreshable,me=void 0!==he&&he,fe=S.onRefresh,be=u(null),pe=u(!0),ve=s(""),ge=e(ve,2),Ne=ge[0],xe=ge[1],ye=s(1),Ce=e(ye,2),ke=Ce[0],we=Ce[1],Se=s(T),Oe=e(Se,2),Le=Oe[0],Ee=Oe[1],Pe=s({column:ee,direction:te}),Me=e(Pe,2),Re=Me[0],Fe=Me[1],je=s({}),Ae=e(je,2),De=Ae[0],He=Ae[1],Ue=s(null),Ve=e(Ue,2),Be=Ve[0],Ie=Ve[1],Je=s([]),Te=e(Je,2),_e=Te[0],Ge=Te[1],Xe=s([]),Ye=e(Xe,2),qe=Ye[0],ze=Ye[1],Ke=s(!1),Qe=e(Ke,2),We=Qe[0],Ze=Qe[1],$e=s({visible:!1,x:0,y:0,row:null}),en=e($e,2),nn=en[0],tn=en[1],rn=d((function(e,n){return Y(e,n)}),[]);h((function(){var e=function(e){Be&&be.current&&!be.current.contains(e.target)&&Ie(null),nn.visible&&tn((function(e){return n(n({},e),{},{visible:!1})}))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[Be,nn.visible]),h((function(){pe.current?pe.current=!1:0!==(L||[]).length?Ge((function(e){if(0===(e||[]).length)return e;var n=e.filter((function(e){return L.some((function(n){return JSON.stringify(n)===JSON.stringify(e)}))}));return(n||[]).length!==(e||[]).length?n:e})):Ge([])}),[L]),h((function(){ae&&!pe.current&&ae(_e)}),[_e]);var cn=d((function(e){if($&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Fe((function(e){if(e.column===n){var t="asc"===e.direction?"desc":"asc";return ie&&ie(n,t),{column:n,direction:t}}return ie&&ie(n,"asc"),{column:n,direction:"asc"}}))}}),[$,ie]),on=d((function(e,i){He((function(r){var c=n(n({},r),{},t({},e,i.length>0?i:null));return re&&re(c),c}))}),[re]),an=d((function(e,n,t){Ge((function(r){return n?[].concat(i(r),[e]):r.filter((function(n,i){return rn(n,i)!==rn(e,t)}))}))}),[rn]),ln=d((function(e){Ge(e?i(L):[])}),[L]),un=d((function(e,n){return _e.some((function(t,i){return rn(t,i)===rn(e,n)}))}),[_e,rn]),sn=d((function(e,n){n.stopPropagation(),ze((function(n){return n.includes(e)?n.filter((function(n){return n!==e})):[].concat(i(n),[e])}))}),[]),dn=d((function(e,n){e.preventDefault(),tn({visible:!0,x:e.clientX,y:e.clientY,row:n})}),[]),hn=d(r(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!fe){e.next=13;break}return Ze(!0),e.prev=2,e.next=5,fe();case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),console.error("Error refreshing data:",e.t0);case 10:return e.prev=10,Ze(!1),e.finish(10);case 13:case"end":return e.stop()}}),e,null,[[2,7,10,13]])}))),[fe]),mn=d((function(e){if(de){var n=de.fileName||"table-export";if("csv"===e){var t=O.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),r=L.map((function(e){return O.filter((function(e){return"string"==typeof e.accessor})).map((function(n){var t,i=n.accessor;return String(null!==(t=e[i])&&void 0!==t?t:"")})).join(",")})),c=[t.join(",")].concat(i(r)).join("\n"),o=new Blob([c],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),l=URL.createObjectURL(o);a.setAttribute("href",l),a.setAttribute("download","".concat(n,".csv")),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)}}}),[O,L,de]),fn=m((function(){var n=L;return Ne.trim()&&(n=n.filter((function(e){return O.some((function(n){if("string"==typeof n.accessor){var t=e[n.accessor];return String(t).toLowerCase().includes(Ne.toLowerCase())}return!1}))}))),Object.entries(De).forEach((function(t){var i=e(t,2),r=i[0],c=i[1];null!==c&&(n=n.filter((function(e){return String(e[r]||"").toLowerCase().includes(String(c).toLowerCase())})))})),n}),[L,Ne,O,De]),bn=m((function(){return Re.column?i(fn).sort((function(e,n){var t=Re.column,i=e[t],r=n[t];if(i===r)return 0;var c=i<r?-1:1;return"asc"===Re.direction?c:-c})):fn}),[fn,Re.column,Re.direction]),pn=m((function(){if(!V)return bn;var e=(ke-1)*Le;return bn.slice(e,e+Le)}),[bn,V,ke,Le]),vn=m((function(){return V?Math.ceil(bn.length/Le):1}),[bn.length,Le,V]);return h((function(){we(1)}),[Ne,Le,De]),P||We?a("div",{className:"ihub-data-list-container",children:[A&&o("h2",{children:A}),o("div",{className:"ihub-loading-state",children:o("p",{children:"Loading data..."})})]}):P||L&&0!==L.length?a("div",{className:"ihub-data-list-container",ref:be,children:[(A||_||H||de||me)&&a("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[o("div",{children:A&&o("h2",{children:A})}),a("div",{className:"ihub-table-controls",children:[H&&o("div",{className:"ihub-table-search",children:o("input",{type:"text",placeholder:"Search...",value:Ne,onChange:function(e){return xe(e.target.value)},className:"ihub-search-input"})}),de&&a("div",{className:"ihub-export-buttons",children:[de.csv&&a("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return mn("csv")},children:[o(f,{}),"CSV"]}),de.excel&&a("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return mn("excel")},children:[o(f,{}),"Excel"]}),de.pdf&&a("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return mn("pdf")},children:[o(f,{}),"PDF"]})]}),me&&fe&&a("button",{className:"ihub-export-button",onClick:hn,disabled:We,children:[o(b,{}),"Refresh"]}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_})]})]}),oe&&_e.length>0&&a("div",{className:"ihub-selection-summary",children:[a("p",{children:[_e.length," item(s) selected"]}),o("button",{className:"ihub-outlined-btn",onClick:function(){return Ge([])},children:"Clear Selection"})]}),o("div",{className:"ihub-scroll-container ".concat(Q?"ihub-sticky-header":""),style:W?{maxHeight:W}:void 0,children:a("table",{className:"ihub-table ihub-scroll-container",children:[o("thead",{className:z?"ihub-hide-on-mobile":"",children:a("tr",{children:[oe&&o("th",{className:"ihub-checkbox-cell",children:o("div",{className:"ihub-checkbox-header",children:o("input",{type:"checkbox",checked:_e.length===L.length&&L.length>0,onChange:function(e){return ln(e.target.checked)}})})}),ue&&se&&o("th",{style:{width:"40px"},children:o(w,{})}),O.map((function(e,n){return o("th",{className:"".concat(e.sortable&&$?"ihub-sortable-column":""," ").concat(Re.column===e.accessor?"ihub-sorted-".concat(Re.direction):""),style:e.width?{width:e.width}:void 0,children:a("div",{className:"ihub-column-header",children:[o("span",{onClick:function(){return e.sortable&&$?cn(e):void 0},style:{cursor:e.sortable&&$?"pointer":"default"},children:e.header}),e.sortable&&$&&o("span",{className:"ihub-sort-icon",onClick:function(){return cn(e)},children:Re.column===e.accessor&&"asc"===Re.direction?"▲":Re.column===e.accessor&&"desc"===Re.direction?"▼":"⇅"}),e.filterable&&"string"==typeof e.accessor&&a("div",{className:"ihub-column-filter",children:[o("button",{className:"ihub-filter-button",onClick:function(n){n.stopPropagation(),Ie(Be===e.accessor?null:e.accessor)},children:De[e.accessor]?o(g,{}):o(v,{})}),Be===e.accessor&&a("div",{className:"ihub-filter-dropdown",onClick:function(e){return e.stopPropagation()},children:[a("label",{children:["Filter ",e.header]}),o("input",{type:"text",className:"ihub-filter-input",value:De[e.accessor]||"",onChange:function(n){return on(e.accessor,n.target.value)},placeholder:"Filter by ".concat(e.header.toLowerCase()),autoFocus:!0}),a("div",{className:"ihub-filter-actions",children:[o("button",{className:"ihub-outlined-btn",onClick:function(){on(e.accessor,""),Ie(null)},children:"Clear"}),o("button",{className:"ihub-important-btn",onClick:function(){return Ie(null)},children:"Apply"})]})]})]})]})},n)}))]})}),o("tbody",{children:pn.map((function(e,n){var t=rn(e,n),i=qe.includes(t);return a(l.Fragment,{children:[a("tr",{onClick:function(){return G&&G(e)},onContextMenu:function(n){return dn(n,e)},className:"\n ".concat(G?"ihub-clickable-row":"","\n ").concat(un(e,n)?"ihub-selected-row":"","\n "),children:[oe&&o("td",{className:"ihub-checkbox-cell",onClick:function(e){return e.stopPropagation()},children:o("input",{type:"checkbox",checked:un(e,n),onChange:function(t){return an(e,t.target.checked,n)}})}),ue&&se&&o("td",{onClick:function(e){return sn(t,e)},children:o(i?x:N,{})}),O.map((function(n,t){var i,r,c;return o("td",{"data-label":z?n.header:void 0,children:n.tooltip&&"string"==typeof n.accessor?o("div",{className:"ihub-cell-tooltip","data-tooltip":String(null!==(i=e[n.accessor])&&void 0!==i?i:""),children:n.cell?n.cell(e):String(null!==(r=e[n.accessor])&&void 0!==r?r:"")}):n.cell?n.cell(e):"function"==typeof n.accessor?n.accessor(e):String(null!==(c=e[n.accessor])&&void 0!==c?c:"")},t)}))]}),ue&&se&&i&&o("tr",{className:"ihub-expanded-row",children:o("td",{colSpan:O.length+(oe?1:0)+1,children:o("div",{className:"ihub-row-details",children:se(e)})})})]},t)}))})]})}),nn.visible&&nn.row&&a("div",{className:"ihub-context-menu",style:{top:nn.y,left:nn.x},children:[a("div",{className:"ihub-context-menu-item",onClick:function(){nn.row&&G&&G(nn.row),tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(y,{}),"View"]}),a("div",{className:"ihub-context-menu-item",onClick:function(){tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(C,{}),"Edit"]}),o("div",{className:"ihub-context-menu-separator"}),a("div",{className:"ihub-context-menu-item",onClick:function(){tn((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(k,{}),"Delete"]})]}),V&&vn>1&&a("div",{className:"ihub-table-pagination",children:[a("div",{className:"ihub-pagination-info",children:["Showing"," ",Math.min((ke-1)*Le+1,bn.length)," ","to ",Math.min(ke*Le,bn.length)," of"," ",bn.length," entries"]}),a("div",{className:"ihub-pagination-controls",children:[o("button",{className:"ihub-pagination-button",disabled:1===ke,onClick:function(){return we(1)},children:"«"}),o("button",{className:"ihub-pagination-button",disabled:1===ke,onClick:function(){return we((function(e){return Math.max(1,e-1)}))},children:"‹"}),Array.from({length:Math.min(5,vn)},(function(e,n){var t;return o("button",{className:"ihub-pagination-button ".concat(ke===(t=vn<=5||ke<=3?n+1:ke>=vn-2?vn-4+n:ke-2+n)?"ihub-active":""),onClick:function(){return we(Number(t))},children:t},t)})),o("button",{className:"ihub-pagination-button",disabled:ke===vn,onClick:function(){return we((function(e){return Math.min(vn,e+1)}))},children:"›"}),o("button",{className:"ihub-pagination-button",disabled:ke===vn,onClick:function(){return we(vn)},children:"»"})]}),a("div",{className:"ihub-rows-per-page",children:[o("span",{children:"Rows per page:"}),o("select",{value:Le,onChange:function(e){return Ee(Number(e.target.value))},className:"ihub-rows-select",children:I.map((function(e){return o("option",{value:e,children:e},e)}))})]})]})]}):a("div",{className:"ihub-data-list-container",children:[A&&o("h2",{children:A}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_}),o("div",{className:"ihub-empty-state",children:a("div",{children:[j,o("p",{children:R})]})})]})};export{S as IHubTable,S as default};
1
+ import{slicedToArray as e,objectSpread2 as n,defineProperty as t,toConsumableArray as i,asyncToGenerator as r,regeneratorRuntime as c}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as a}from"react/jsx-runtime";import l,{useRef as u,useState as s,useCallback as d,useEffect as h,useMemo as m}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import f from"@mui/icons-material/RefreshOutlined";import p from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/FilterAltOutlined";import g from"@mui/icons-material/FilterAltOffOutlined";import N from"@mui/icons-material/ExpandMoreOutlined";import x from"@mui/icons-material/ExpandLessOutlined";import y from"@mui/icons-material/VisibilityOutlined";import C from"@mui/icons-material/EditOutlined";import k from"@mui/icons-material/DeleteOutlined";import w from"@mui/icons-material/UnfoldLessOutlined";var S=function(S){var O=S.columns,L=S.data,E=S.isLoading,P=void 0!==E&&E,R=S.emptyStateMessage,A=void 0===R?"No data available":R,F=S.emptyStateIcon,M=void 0===F?o(p,{}):F,j=S.title,D=S.showSearch,H=void 0!==D&&D,U=S.pagination,V=void 0===U||U,B=S.rowsPerPageOptions,I=void 0===B?[10,25,50]:B,J=S.defaultRowsPerPage,T=void 0===J?10:J,_=S.actions,G=S.onRowClick,W=S.keyExtractor,X=void 0===W?function(e,n){return n}:W,Y=S.hideHeaderOnMobile,q=void 0!==Y&&Y,z=S.stickyHeader,K=void 0!==z&&z,Q=S.maxHeight,Z=S.sortable,$=void 0===Z||Z,ee=S.defaultSortColumn,ne=S.defaultSortDirection,te=void 0===ne?"asc":ne,ie=S.onSort,re=S.onFilter,ce=S.selectable,oe=void 0!==ce&&ce,ae=S.onSelectionChange,le=S.expandable,ue=void 0!==le&&le,se=S.renderExpandedRow,de=S.exportOptions,he=S.refreshable,me=void 0!==he&&he,be=S.onRefresh,fe=S.showRowNumbers,pe=void 0!==fe&&fe,ve=S.rowNumberStartFrom,ge=void 0===ve?1:ve,Ne=u(null),xe=u(!0),ye=s(""),Ce=e(ye,2),ke=Ce[0],we=Ce[1],Se=s(1),Oe=e(Se,2),Le=Oe[0],Ee=Oe[1],Pe=s(T),Re=e(Pe,2),Ae=Re[0],Fe=Re[1],Me=s({column:ee,direction:te}),je=e(Me,2),De=je[0],He=je[1],Ue=s({}),Ve=e(Ue,2),Be=Ve[0],Ie=Ve[1],Je=s(null),Te=e(Je,2),_e=Te[0],Ge=Te[1],We=s([]),Xe=e(We,2),Ye=Xe[0],qe=Xe[1],ze=s([]),Ke=e(ze,2),Qe=Ke[0],Ze=Ke[1],$e=s(!1),en=e($e,2),nn=en[0],tn=en[1],rn=s({visible:!1,x:0,y:0,row:null}),cn=e(rn,2),on=cn[0],an=cn[1],ln=d((function(e,n){return X(e,n)}),[]);h((function(){var e=function(e){_e&&Ne.current&&!Ne.current.contains(e.target)&&Ge(null),on.visible&&an((function(e){return n(n({},e),{},{visible:!1})}))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[_e,on.visible]),h((function(){xe.current?xe.current=!1:0!==(L||[]).length?qe((function(e){if(0===(e||[]).length)return e;var n=e.filter((function(e){return L.some((function(n){return JSON.stringify(n)===JSON.stringify(e)}))}));return(n||[]).length!==(e||[]).length?n:e})):qe([])}),[L]),h((function(){ae&&!xe.current&&ae(Ye)}),[Ye]);var un=d((function(e){if($&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;He((function(e){if(e.column===n){var t="asc"===e.direction?"desc":"asc";return ie&&ie(n,t),{column:n,direction:t}}return ie&&ie(n,"asc"),{column:n,direction:"asc"}}))}}),[$,ie]),sn=d((function(e,i){Ie((function(r){var c=n(n({},r),{},t({},e,i.length>0?i:null));return re&&re(c),c}))}),[re]),dn=d((function(e,n,t){qe((function(r){return n?[].concat(i(r),[e]):r.filter((function(n,i){return ln(n,i)!==ln(e,t)}))}))}),[ln]),hn=d((function(e){qe(e?i(L):[])}),[L]),mn=d((function(e,n){return Ye.some((function(t,i){return ln(t,i)===ln(e,n)}))}),[Ye,ln]),bn=d((function(e,n){n.stopPropagation(),Ze((function(n){return n.includes(e)?n.filter((function(n){return n!==e})):[].concat(i(n),[e])}))}),[]),fn=d((function(e,n){e.preventDefault(),an({visible:!0,x:e.clientX,y:e.clientY,row:n})}),[]),pn=d(r(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!be){e.next=13;break}return tn(!0),e.prev=2,e.next=5,be();case 5:e.next=10;break;case 7:e.prev=7,e.t0=e.catch(2),console.error("Error refreshing data:",e.t0);case 10:return e.prev=10,tn(!1),e.finish(10);case 13:case"end":return e.stop()}}),e,null,[[2,7,10,13]])}))),[be]),vn=d((function(e){if(de){var n=de.fileName||"table-export";if("csv"===e){var t=[].concat(i(pe?["#"]:[]),i(O.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})))),r=L.map((function(e,n){return[].concat(i(pe?[String(n+ge)]:[]),i(O.filter((function(e){return"string"==typeof e.accessor})).map((function(n){var t,i=n.accessor;return String(null!==(t=e[i])&&void 0!==t?t:"")})))).join(",")})),c=[t.join(",")].concat(i(r)).join("\n"),o=new Blob([c],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),l=URL.createObjectURL(o);a.setAttribute("href",l),a.setAttribute("download","".concat(n,".csv")),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)}}}),[O,L,de]),gn=m((function(){var n=L;return ke.trim()&&(n=n.filter((function(e){return O.some((function(n){if("string"==typeof n.accessor){var t=e[n.accessor];return String(t).toLowerCase().includes(ke.toLowerCase())}return!1}))}))),Object.entries(Be).forEach((function(t){var i=e(t,2),r=i[0],c=i[1];null!==c&&(n=n.filter((function(e){return String(e[r]||"").toLowerCase().includes(String(c).toLowerCase())})))})),n}),[L,ke,O,Be]),Nn=m((function(){return De.column?i(gn).sort((function(e,n){var t=De.column,i=e[t],r=n[t];if(i===r)return 0;var c=i<r?-1:1;return"asc"===De.direction?c:-c})):gn}),[gn,De.column,De.direction]),xn=m((function(){if(!V)return Nn;var e=(Le-1)*Ae;return Nn.slice(e,e+Ae)}),[Nn,V,Le,Ae]),yn=m((function(){return V?Math.ceil(Nn.length/Ae):1}),[Nn.length,Ae,V]);return h((function(){Ee(1)}),[ke,Ae,Be]),P||nn?a("div",{className:"ihub-data-list-container",children:[j&&o("h2",{children:j}),o("div",{className:"ihub-loading-state",children:o("p",{children:"Loading data..."})})]}):P||L&&0!==L.length?a("div",{className:"ihub-data-list-container",ref:Ne,children:[(j||_||H||de||me)&&a("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[o("div",{children:j&&o("h2",{children:j})}),a("div",{className:"ihub-table-controls",children:[H&&o("div",{className:"ihub-table-search",children:o("input",{type:"text",placeholder:"Search...",value:ke,onChange:function(e){return we(e.target.value)},className:"ihub-search-input"})}),de&&a("div",{className:"ihub-export-buttons",children:[de.csv&&a("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return vn("csv")},children:[o(b,{}),"CSV"]}),de.excel&&a("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return vn("excel")},children:[o(b,{}),"Excel"]}),de.pdf&&a("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return vn("pdf")},children:[o(b,{}),"PDF"]})]}),me&&be&&a("button",{className:"ihub-export-button",onClick:pn,disabled:nn,children:[o(f,{}),"Refresh"]}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_})]})]}),oe&&Ye.length>0&&a("div",{className:"ihub-selection-summary",children:[a("p",{children:[Ye.length," item(s) selected"]}),o("button",{className:"ihub-outlined-btn",onClick:function(){return qe([])},children:"Clear Selection"})]}),o("div",{className:"ihub-scroll-container ".concat(K?"ihub-sticky-header":""),style:Q?{maxHeight:Q}:void 0,children:a("table",{className:"ihub-table ihub-scroll-container",children:[o("thead",{className:q?"ihub-hide-on-mobile":"",children:a("tr",{children:[pe&&o("th",{style:{width:"60px",textAlign:"center"},children:"#"}),oe&&o("th",{className:"ihub-checkbox-cell",children:o("div",{className:"ihub-checkbox-header",children:o("input",{type:"checkbox",checked:Ye.length===L.length&&L.length>0,onChange:function(e){return hn(e.target.checked)}})})}),ue&&se&&o("th",{style:{width:"40px"},children:o(w,{})}),O.map((function(e,n){return o("th",{className:"".concat(e.sortable&&$?"ihub-sortable-column":""," ").concat(De.column===e.accessor?"ihub-sorted-".concat(De.direction):""),style:e.width?{width:e.width}:void 0,children:a("div",{className:"ihub-column-header",children:[o("span",{onClick:function(){return e.sortable&&$?un(e):void 0},style:{cursor:e.sortable&&$?"pointer":"default"},children:e.header}),e.sortable&&$&&o("span",{className:"ihub-sort-icon",onClick:function(){return un(e)},children:De.column===e.accessor&&"asc"===De.direction?"▲":De.column===e.accessor&&"desc"===De.direction?"▼":"⇅"}),e.filterable&&"string"==typeof e.accessor&&a("div",{className:"ihub-column-filter",children:[o("button",{className:"ihub-filter-button",onClick:function(n){n.stopPropagation(),Ge(_e===e.accessor?null:e.accessor)},children:Be[e.accessor]?o(g,{}):o(v,{})}),_e===e.accessor&&a("div",{className:"ihub-filter-dropdown",onClick:function(e){return e.stopPropagation()},children:[a("label",{children:["Filter ",e.header]}),o("input",{type:"text",className:"ihub-filter-input",value:Be[e.accessor]||"",onChange:function(n){return sn(e.accessor,n.target.value)},placeholder:"Filter by ".concat(e.header.toLowerCase()),autoFocus:!0}),a("div",{className:"ihub-filter-actions",children:[o("button",{className:"ihub-outlined-btn",onClick:function(){sn(e.accessor,""),Ge(null)},children:"Clear"}),o("button",{className:"ihub-important-btn",onClick:function(){return Ge(null)},children:"Apply"})]})]})]})]})},n)}))]})}),o("tbody",{children:xn.map((function(e,n){var t=ln(e,n),i=Qe.includes(t);return a(l.Fragment,{children:[a("tr",{onClick:function(){return G&&G(e)},onContextMenu:function(n){return fn(n,e)},className:"\n ".concat(G?"ihub-clickable-row":"","\n ").concat(mn(e,n)?"ihub-selected-row":"","\n "),children:[pe&&o("td",{style:{textAlign:"center",fontWeight:"500"},children:(Le-1)*Ae+n+ge}),oe&&o("td",{className:"ihub-checkbox-cell",onClick:function(e){return e.stopPropagation()},children:o("input",{type:"checkbox",checked:mn(e,n),onChange:function(t){return dn(e,t.target.checked,n)}})}),ue&&se&&o("td",{onClick:function(e){return bn(t,e)},children:o(i?x:N,{})}),O.map((function(n,t){var i,r,c;return o("td",{"data-label":q?n.header:void 0,children:n.tooltip&&"string"==typeof n.accessor?o("div",{className:"ihub-cell-tooltip","data-tooltip":String(null!==(i=e[n.accessor])&&void 0!==i?i:""),children:n.cell?n.cell(e):String(null!==(r=e[n.accessor])&&void 0!==r?r:"")}):n.cell?n.cell(e):"function"==typeof n.accessor?n.accessor(e):String(null!==(c=e[n.accessor])&&void 0!==c?c:"")},t)}))]}),ue&&se&&i&&o("tr",{className:"ihub-expanded-row",children:o("td",{colSpan:O.length+(oe?1:0)+1+(pe?1:0),children:o("div",{className:"ihub-row-details",children:se(e)})})})]},t)}))})]})}),on.visible&&on.row&&a("div",{className:"ihub-context-menu",style:{top:on.y,left:on.x},children:[a("div",{className:"ihub-context-menu-item",onClick:function(){on.row&&G&&G(on.row),an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(y,{}),"View"]}),a("div",{className:"ihub-context-menu-item",onClick:function(){an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(C,{}),"Edit"]}),o("div",{className:"ihub-context-menu-separator"}),a("div",{className:"ihub-context-menu-item",onClick:function(){an((function(e){return n(n({},e),{},{visible:!1})}))},children:[o(k,{}),"Delete"]})]}),V&&yn>1&&a("div",{className:"ihub-table-pagination",children:[a("div",{className:"ihub-pagination-info",children:["Showing"," ",Math.min((Le-1)*Ae+1,Nn.length)," ","to ",Math.min(Le*Ae,Nn.length)," of"," ",Nn.length," entries"]}),a("div",{className:"ihub-pagination-controls",children:[o("button",{className:"ihub-pagination-button",disabled:1===Le,onClick:function(){return Ee(1)},children:"«"}),o("button",{className:"ihub-pagination-button",disabled:1===Le,onClick:function(){return Ee((function(e){return Math.max(1,e-1)}))},children:"‹"}),Array.from({length:Math.min(5,yn)},(function(e,n){var t;return o("button",{className:"ihub-pagination-button ".concat(Le===(t=yn<=5||Le<=3?n+1:Le>=yn-2?yn-4+n:Le-2+n)?"ihub-active":""),onClick:function(){return Ee(Number(t))},children:t},t)})),o("button",{className:"ihub-pagination-button",disabled:Le===yn,onClick:function(){return Ee((function(e){return Math.min(yn,e+1)}))},children:"›"}),o("button",{className:"ihub-pagination-button",disabled:Le===yn,onClick:function(){return Ee(yn)},children:"»"})]}),a("div",{className:"ihub-rows-per-page",children:[o("span",{children:"Rows per page:"}),o("select",{value:Ae,onChange:function(e){return Fe(Number(e.target.value))},className:"ihub-rows-select",children:I.map((function(e){return o("option",{value:e,children:e},e)}))})]})]})]}):a("div",{className:"ihub-data-list-container",children:[j&&o("h2",{children:j}),_&&o("div",{className:"ihub-data-controls ihub-mb-0",children:_}),o("div",{className:"ihub-empty-state",children:a("div",{children:[M,o("p",{children:A})]})})]})};export{S as IHubTable,S as default};
2
2
  //# sourceMappingURL=IHubTable.js.map
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as s,useRef as l,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/ExpandMoreOutlined";import g from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as P,API_HOST_URL as x}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var k=s((function(s,k){var w,C,S=s.token,E=s.columns,j=s.defaultData,R=s.endpointPath,O=s.initialParams,M=void 0===O?{}:O,A=s.searchParams,H=s.dataAdapter,L=s.title,F=s.emptyStateMessage,D=void 0===F?"No data available":F,I=s.emptyStateIcon,T=void 0===I?i(f,{}):I,U=s.actions,_=s.showSearch,B=void 0===_||_,G=s.searchPlaceholder,J=void 0===G?"Search...":G,V=s.searchDebounceMs,q=void 0===V?1e3:V,z=s.enableSorting,K=void 0===z||z,Q=s.enableExport,W=void 0!==Q&&Q,X=s.exportOptions,Y=void 0===X?{csv:!0}:X,Z=s.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=s.defaultRowsPerPage,te=void 0===ee?10:ee,ne=s.onRowClick,re=s.onFetchError,ae=s.expandable,ie=void 0!==ae&&ae,oe=s.renderExpandedRow,ce=s.keyExtractor,se=void 0===ce?function(e){return JSON.stringify(e)}:ce,le=s.stickyHeader,ue=void 0!==le&&le,de=s.maxHeight,he=s.hideHeaderOnMobile,pe=void 0!==he&&he,be=l(!0),me=l(null),fe=u(j||[]),ve=e(fe,2),ge=ve[0],Ne=ve[1],Pe=u(!0),xe=e(Pe,2),ye=xe[0],ke=xe[1],we=u(null),Ce=e(we,2),Se=Ce[0],Ee=Ce[1],je=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u(t({page:1,limit:te},M)),He=e(Ae,2),Le=He[0],Fe=He[1],De=u([]),Ie=e(De,2),Te=Ie[0],Ue=Ie[1],_e=u(M.search||""),Be=e(_e,2),Ge=Be[0],Je=Be[1],Ve=d(y.exports.debounce((function(e){Fe((function(n){return t(t({},n),{},{search:e,page:1})}))}),q),[]),qe={data:j||[],pagination:{totalCount:null===(w=j||[])||void 0===w?void 0:w.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},ze=d(function(){var t=r(a().mark((function t(n){var r,i,o,c,s,l;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(ke(!0),t.prev=1,R){t.next=4;break}return t.abrupt("return",qe);case 4:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),A&&Object.entries(A).forEach((function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))})),o=P("GET",null,S),c="".concat(x).concat(R,"?").concat(r.toString()),t.next=12,fetch(c,o);case 12:return s=t.sent,t.next=15,s.json();case 15:return l=t.sent,t.abrupt("return",{data:l.results,pagination:{totalCount:l.count,currentPage:Math.floor(parseInt(new URLSearchParams(l.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(l.count/n.limit)},links:{next:l.next,previous:l.previous}});case 19:throw t.prev=19,t.t0=t.catch(1),console.error("Error fetching program courses:",t.t0),t.t0;case 23:return t.prev=23,ke(!1),t.finish(23);case 26:case"end":return t.stop()}}),t,null,[[1,19,23,26]])})));return function(e){return t.apply(this,arguments)}}(),[A]),Ke=d((function(e){var t=e.target.value;Je(t),Ve(t)}),[Ve]),Qe=d((function(e){Fe((function(n){return t(t({},n),{},{page:e})}))}),[]),We=d((function(e){Fe((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),Xe=d((function(e){if(K&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Fe((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[K]),Ye=d((function(){Fe((function(e){return t({},e)}))}),[]);h(k,(function(){return{refresh:Ye}}),[Ye]);var Ze=d(function(){var e=r(a().mark((function e(r){var i,o,c,s,l,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(W){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,ke(!0),i=t(t({},Le),{},{page:1,limit:1e3,export:r}),e.next=7,ze(i);case 7:(o=e.sent)&&(c=H?H(o).data:o.data,s=Y.fileName||"table-export","csv"===r&&(l=E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),u=c.map((function(e){return E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})).join(",")})),d=[l.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(s,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),re&&re(e.t0);case 15:return e.prev=15,ke(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,Le,W,Y,H,re]),$e=d((function(e,t){t.stopPropagation(),Ue((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,ke(!0),t.next=4,ze(Le);case 4:n=t.sent,e&&(H?(r=H(n),Ne(r.data),r.pagination&&Me(r.pagination)):n&&(Ne(n.data),n.pagination&&Me(n.pagination)),Ee(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Ee(t.t0),re&&re(t.t0));case 12:return t.prev=12,e&&(ke(!1),be.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[Le,H,re]),p((function(){A&&!be.current&&Fe((function(e){return t({},e)}))}),[A]),ye&&be.current?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Se&&!ye&&0===(ge||[]).length?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:Ye,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:me,children:[(L||U||B||W)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:L&&i("h2",{children:L})}),o("div",{className:"ihub-table-controls",children:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:Ge,onChange:Ke,className:"ihub-search-input"}),ye&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),W&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return Ze("csv")},disabled:ye,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return Ze("excel")},disabled:ye,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return Ze("pdf")},disabled:ye,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:Ye,disabled:ye,children:[i(m,{}),"Refresh"]}),U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U})]})]}),ye&&!be.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(ue?"ihub-sticky-header":""),style:de?{maxHeight:de}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:pe?"ihub-hide-on-mobile":"",children:o("tr",{children:[ie&&oe&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&K?"ihub-sortable-column":""," ").concat(Le.sort===e.accessor?"ihub-sorted-".concat(Le.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&K?Xe(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&K&&i("span",{className:"ihub-sort-icon",children:Le.sort===e.accessor&&"asc"===Le.direction?"▲":Le.sort===e.accessor&&"desc"===Le.direction?"▼":"⇅"})]})},t)}))]})}),ye||0!==(ge||[]).length?i("tbody",{children:ge.map((function(e,t){var n=se(e),r=Te.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[ie&&oe&&i("td",{onClick:function(e){return $e(n,e)},children:i(r?g:v,{})}),E.map((function(t,n){return i("td",{"data-label":pe?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ie&&oe&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1,children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)}))}):""]}),ye||0!==(ge||[]).length?"":o("div",{className:"ihub-data-list-container",children:[U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U}),i("div",{className:"ihub-empty-state",children:o("div",{children:[T,i("p",{children:D})]})})]})]}),Oe&&Oe.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Oe.currentPage-1)*Oe.perPage+1," to"," ",Math.min(Oe.currentPage*Oe.perPage,Oe.totalCount)," ","of ",Oe.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(Oe.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Oe.totalPages)},(function(e,t){var n;return n=Oe.totalPages<=5||Oe.currentPage<=3?t+1:Oe.currentPage>=Oe.totalPages-2?Oe.totalPages-4+t:Oe.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Oe.currentPage===n?"ihub-active":""),onClick:function(){return Qe(Number(n))},disabled:ye,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Oe.perPage,onChange:function(e){return We(Number(e.target.value))},className:"ihub-rows-select",disabled:ye,children:$.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));k.displayName="IHubTableServer";export{k as IHubTableServer,k as default};
1
+ import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as l,useRef as s,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import g from"@mui/icons-material/ExpandMoreOutlined";import v from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as x,API_HOST_URL as P}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var w=l((function(l,w){var k,C,S=l.token,E=l.columns,j=l.defaultData,R=l.endpointPath,O=l.initialParams,M=void 0===O?{}:O,A=l.searchParams,F=l.dataAdapter,H=l.title,L=l.emptyStateMessage,D=void 0===L?"No data available":L,I=l.emptyStateIcon,T=void 0===I?i(f,{}):I,U=l.actions,_=l.showSearch,B=void 0===_||_,G=l.searchPlaceholder,J=void 0===G?"Search...":G,V=l.searchDebounceMs,W=void 0===V?1e3:V,q=l.enableSorting,z=void 0===q||q,K=l.enableExport,Q=void 0!==K&&K,X=l.exportOptions,Y=void 0===X?{csv:!0}:X,Z=l.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=l.defaultRowsPerPage,te=void 0===ee?10:ee,ne=l.onRowClick,re=l.onFetchError,ae=l.expandable,ie=void 0!==ae&&ae,oe=l.renderExpandedRow,ce=l.keyExtractor,le=void 0===ce?function(e){return JSON.stringify(e)}:ce,se=l.stickyHeader,ue=void 0!==se&&se,de=l.maxHeight,he=l.hideHeaderOnMobile,pe=void 0!==he&&he,be=l.showRowNumbers,me=void 0!==be&&be,fe=l.rowNumberStartFrom,ge=void 0===fe?1:fe,ve=s(!0),Ne=s(null),xe=u(j||[]),Pe=e(xe,2),ye=Pe[0],we=Pe[1],ke=u(!0),Ce=e(ke,2),Se=Ce[0],Ee=Ce[1],je=u(null),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Fe=e(Ae,2),He=Fe[0],Le=Fe[1],De=u(t({page:1,limit:te},M)),Ie=e(De,2),Te=Ie[0],Ue=Ie[1],_e=u([]),Be=e(_e,2),Ge=Be[0],Je=Be[1],Ve=u(M.search||""),We=e(Ve,2),qe=We[0],ze=We[1],Ke=d(y.exports.debounce((function(e){Ue((function(n){return t(t({},n),{},{search:e,page:1})}))}),W),[]),Qe={data:j||[],pagination:{totalCount:null===(k=j||[])||void 0===k?void 0:k.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},Xe=d(function(){var t=r(a().mark((function t(n){var r,i,o,c,l,s;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Ee(!0),t.prev=1,R){t.next=4;break}return t.abrupt("return",Qe);case 4:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),A&&Object.entries(A).forEach((function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))})),o=x("GET",null,S),c="".concat(P).concat(R,"?").concat(r.toString()),t.next=12,fetch(c,o);case 12:return l=t.sent,t.next=15,l.json();case 15:return s=t.sent,t.abrupt("return",{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(s.count/n.limit)},links:{next:s.next,previous:s.previous}});case 19:throw t.prev=19,t.t0=t.catch(1),console.error("Error fetching program courses:",t.t0),t.t0;case 23:return t.prev=23,Ee(!1),t.finish(23);case 26:case"end":return t.stop()}}),t,null,[[1,19,23,26]])})));return function(e){return t.apply(this,arguments)}}(),[A]),Ye=d((function(e){var t=e.target.value;ze(t),Ke(t)}),[Ke]),Ze=d((function(e){Ue((function(n){return t(t({},n),{},{page:e})}))}),[]),$e=d((function(e){Ue((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),et=d((function(e){if(z&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Ue((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[z]),tt=d((function(){Ue((function(e){return t({},e)}))}),[]);h(w,(function(){return{refresh:tt}}),[tt]);var nt=d(function(){var e=r(a().mark((function e(r){var i,o,c,l,s,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,Ee(!0),i=t(t({},Te),{},{page:1,limit:1e3,export:r}),e.next=7,Xe(i);case 7:(o=e.sent)&&(c=F?F(o).data:o.data,l=Y.fileName||"table-export","csv"===r&&(s=[].concat(n(me?["#"]:[]),n(E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})))),u=c.map((function(e,t){return[].concat(n(me?[String(t+ge)]:[]),n(E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})))).join(",")})),d=[s.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(l,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),re&&re(e.t0);case 15:return e.prev=15,Ee(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,Te,Q,Y,F,re]),rt=d((function(e,t){t.stopPropagation(),Je((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,Ee(!0),t.next=4,Xe(Te);case 4:n=t.sent,e&&(F?(r=F(n),we(r.data),r.pagination&&Le(r.pagination)):n&&(we(n.data),n.pagination&&Le(n.pagination)),Me(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Me(t.t0),re&&re(t.t0));case 12:return t.prev=12,e&&(Ee(!1),ve.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[Te,F,re]),p((function(){A&&!ve.current&&Ue((function(e){return t({},e)}))}),[A]),Se&&ve.current?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Oe&&!Se&&0===(ye||[]).length?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:tt,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:Ne,children:[(H||U||B||Q)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:H&&i("h2",{children:H})}),o("div",{className:"ihub-table-controls",children:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:qe,onChange:Ye,className:"ihub-search-input"}),Se&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),Q&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return nt("csv")},disabled:Se,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return nt("excel")},disabled:Se,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return nt("pdf")},disabled:Se,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:tt,disabled:Se,children:[i(m,{}),"Refresh"]}),U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U})]})]}),Se&&!ve.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(ue?"ihub-sticky-header":""),style:de?{maxHeight:de}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:pe?"ihub-hide-on-mobile":"",children:o("tr",{children:[me&&i("th",{style:{width:"60px",textAlign:"center"},children:"#"}),ie&&oe&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&z?"ihub-sortable-column":""," ").concat(Te.sort===e.accessor?"ihub-sorted-".concat(Te.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&z?et(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&z&&i("span",{className:"ihub-sort-icon",children:Te.sort===e.accessor&&"asc"===Te.direction?"▲":Te.sort===e.accessor&&"desc"===Te.direction?"▼":"⇅"})]})},t)}))]})}),Se||0!==(ye||[]).length?i("tbody",{children:ye.map((function(e,t){var n=le(e),r=Ge.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[me&&i("td",{style:{textAlign:"center",fontWeight:"500"},children:(He.currentPage-1)*He.perPage+t+ge}),ie&&oe&&i("td",{onClick:function(e){return rt(n,e)},children:i(r?v:g,{})}),E.map((function(t,n){return i("td",{"data-label":pe?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ie&&oe&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1+(me?1:0),children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)}))}):""]}),Se||0!==(ye||[]).length?"":o("div",{className:"ihub-data-list-container",children:[U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U}),i("div",{className:"ihub-empty-state",children:o("div",{children:[T,i("p",{children:D})]})})]})]}),He&&He.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(He.currentPage-1)*He.perPage+1," to"," ",Math.min(He.currentPage*He.perPage,He.totalCount)," ","of ",He.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(He.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,He.totalPages)},(function(e,t){var n;return n=He.totalPages<=5||He.currentPage<=3?t+1:He.currentPage>=He.totalPages-2?He.totalPages-4+t:He.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(He.currentPage===n?"ihub-active":""),onClick:function(){return Ze(Number(n))},disabled:Se,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:He.perPage,onChange:function(e){return $e(Number(e.target.value))},className:"ihub-rows-select",disabled:Se,children:$.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));w.displayName="IHubTableServer";export{w as IHubTableServer,w as default};
2
2
  //# sourceMappingURL=IHubTableServer.js.map
@@ -41,6 +41,8 @@ export interface TableProps<T> {
41
41
  };
42
42
  refreshable?: boolean;
43
43
  onRefresh?: () => Promise<void>;
44
+ showRowNumbers?: boolean;
45
+ rowNumberStartFrom?: number;
44
46
  }
45
47
  /**
46
48
  * Enhanced reusable table component for InstinctHub applications
@@ -76,6 +78,8 @@ export interface TableProps<T> {
76
78
  * exportOptions={exportOptions}
77
79
  * refreshable={refreshable}
78
80
  * onRefresh={onRefresh}
81
+ * showRowNumbers={true}
82
+ * rowNumberStartFrom={1}
79
83
  * />
80
84
  * ```
81
85
  * @prop {TableColumnType<T>[]} columns - The columns to display in the table
@@ -106,8 +110,10 @@ export interface TableProps<T> {
106
110
  * @prop {object} exportOptions - The options for exporting the table
107
111
  * @prop {boolean} refreshable - Whether to allow refreshing the table
108
112
  * @prop {function} onRefresh - The function to call when the table is refreshed
113
+ * @prop {boolean} showRowNumbers - Whether to show row numbers for each record
114
+ * @prop {number} rowNumberStartFrom - The starting number for row numbering (defaults to 1)
109
115
  *
110
116
  * @link https://github.com/instincthub/instincthub-react-ui/blob/main/src/__examples__/src/components/ui/TableExamples.tsx
111
117
  */
112
- export declare const IHubTable: <T extends object>({ columns, data, isLoading, emptyStateMessage, emptyStateIcon, title, showSearch, pagination, rowsPerPageOptions, defaultRowsPerPage, actions, onRowClick, keyExtractor, hideHeaderOnMobile, stickyHeader, maxHeight, sortable, defaultSortColumn, defaultSortDirection, onSort, onFilter, selectable, onSelectionChange, expandable, renderExpandedRow, exportOptions, refreshable, onRefresh, }: TableProps<T>) => JSX.Element;
118
+ export declare const IHubTable: <T extends object>({ columns, data, isLoading, emptyStateMessage, emptyStateIcon, title, showSearch, pagination, rowsPerPageOptions, defaultRowsPerPage, actions, onRowClick, keyExtractor, hideHeaderOnMobile, stickyHeader, maxHeight, sortable, defaultSortColumn, defaultSortDirection, onSort, onFilter, selectable, onSelectionChange, expandable, renderExpandedRow, exportOptions, refreshable, onRefresh, showRowNumbers, rowNumberStartFrom, }: TableProps<T>) => JSX.Element;
113
119
  export default IHubTable;
@@ -39,6 +39,8 @@ interface IHubTableServerPropsType<T> {
39
39
  stickyHeader?: boolean;
40
40
  maxHeight?: string;
41
41
  hideHeaderOnMobile?: boolean;
42
+ showRowNumbers?: boolean;
43
+ rowNumberStartFrom?: number;
42
44
  }
43
45
  /**
44
46
  * Server-side table component for InstinctHub applications
@@ -62,6 +64,8 @@ interface IHubTableServerPropsType<T> {
62
64
  * stickyHeader={true}
63
65
  * maxHeight="600px"
64
66
  * hideHeaderOnMobile={true}
67
+ * showRowNumbers={true}
68
+ * rowNumberStartFrom={1}
65
69
  * token={process.env.NEXT_PUBLIC_TOKEN}
66
70
  * dataAdapter={dataAdapter}
67
71
  * rowsPerPageOptions={[10, 25, 50, 100]}
@@ -104,6 +108,8 @@ interface IHubTableServerPropsType<T> {
104
108
  * @prop {boolean} stickyHeader - Whether to enable sticky header
105
109
  * @prop {string} maxHeight - The maximum height of the table
106
110
  * @prop {boolean} hideHeaderOnMobile - Whether to hide the header on mobile
111
+ * @prop {boolean} showRowNumbers - Whether to show row numbers for each record
112
+ * @prop {number} rowNumberStartFrom - The starting number for row numbering (defaults to 1)
107
113
  *
108
114
  * @link https://github.com/instincthub/instincthub-react-ui/blob/main/src/__examples__/src/components/ui/TableServerExamples.tsx
109
115
  */