better-table 1.0.0 β 1.1.0
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 +33 -0
- package/dist/better-table.cjs.js +1 -1
- package/dist/better-table.cjs.js.map +1 -1
- package/dist/better-table.css +1 -1
- package/dist/better-table.es.js +852 -699
- package/dist/better-table.es.js.map +1 -1
- package/dist/components/BetterTable/components/TableCard.d.ts +8 -0
- package/dist/components/BetterTable/components/TableCards.d.ts +4 -0
- package/dist/components/BetterTable/components/index.d.ts +2 -0
- package/dist/setupTests.d.ts +0 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,4 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
A modern, flexible, and fully typed data table component for React.
|
|
4
4
|
|
|
5
|
+
## π Documentation
|
|
6
|
+
|
|
7
|
+
- **[Getting Started](https://github.com/jrodrigopuca/BetterTable#readme)** - Installation and basic usage
|
|
8
|
+
- **[Architecture](./docs/architecture.md)** - Design patterns and technical decisions
|
|
9
|
+
- **[Components](./docs/components.md)** - Detailed API reference
|
|
10
|
+
- **[Interaction Flows](./docs/interaction-flows.md)** - Sequence diagrams and component interactions
|
|
11
|
+
- **[Known Issues](./docs/known-issues.md)** - Known bugs and limitations
|
|
12
|
+
|
|
13
|
+
## π Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install better-table
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { BetterTable } from 'better-table';
|
|
21
|
+
import 'better-table/styles.css';
|
|
22
|
+
|
|
23
|
+
const MyTable = () => {
|
|
24
|
+
const data = [
|
|
25
|
+
{ id: 1, name: 'Juan', email: 'juan@example.com' },
|
|
26
|
+
{ id: 2, name: 'MarΓa', email: 'maria@example.com' }
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const columns = [
|
|
30
|
+
{ id: 'name', accessor: 'name', header: 'Name' },
|
|
31
|
+
{ id: 'email', accessor: 'email', header: 'Email' }
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
return <BetterTable data={data} columns={columns} />;
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
5
38
|
For full documentation, see the [main README](https://github.com/jrodrigopuca/BetterTable#readme).
|
package/dist/better-table.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),l=require("react/jsx-runtime");require("./styles.cjs");const Ce={search:"Buscar",searchPlaceholder:"Buscar...",noData:"No hay datos",loading:"Cargando...",page:"PΓ‘gina",of:"de",items:"elementos",selected:"seleccionados",rowsPerPage:"Filas por pΓ‘gina",actions:"Acciones",sortAsc:"Ordenar ascendente",sortDesc:"Ordenar descendente",filterBy:"Filtrar por",clearFilters:"Limpiar filtros",selectAll:"Seleccionar todo",deselectAll:"Deseleccionar todo"},Te=c.createContext(null);function T(){const e=c.useContext(Te);if(!e)throw new Error("useTableContext must be used within a TableProvider");return e}function De({value:e,children:n}){return l.jsx(Te.Provider,{value:e,children:n})}function Pe(e){var n,s,a="";if(typeof e=="string"||typeof e=="number")a+=e;else if(typeof e=="object")if(Array.isArray(e)){var i=e.length;for(n=0;n<i;n++)e[n]&&(s=Pe(e[n]))&&(a&&(a+=" "),a+=s)}else for(s in e)e[s]&&(a&&(a+=" "),a+=s);return a}function S(){for(var e,n,s=0,a="",i=arguments.length;s<i;s++)(e=arguments[s])&&(n=Pe(e))&&(a&&(a+=" "),a+=n);return a}function Je({column:e}){const{sortState:n,handleSort:s,filters:a,setFilter:i,locale:t}=T(),r=n.columnId===e.id,d=r?n.direction:null,b=c.useCallback(()=>{e.sortable!==!1&&s(e.id)},[e.id,e.sortable,s]),u=c.useCallback(h=>{const m=h.target.value;e.type==="boolean"?m===""?i(e.id,null):i(e.id,m==="true"):i(e.id,m||null)},[e.id,e.type,i]),f=c.useCallback(h=>{h.key==="Enter"&&e.sortable!==!1&&s(e.id)},[e.id,e.sortable,s]),g=()=>e.sortable===!1||e.type==="custom"?null:l.jsx("button",{className:S("bt-sort-btn",r&&"bt-active"),onClick:b,"aria-label":d==="asc"?t.sortDesc:t.sortAsc,type:"button",children:r?d==="asc"?"β":"β":"β
"}),p=()=>{if(e.filterable===!1||e.type==="custom")return null;const h=a[e.id];return e.type==="boolean"?l.jsxs("select",{className:"bt-filter-select",value:h==null?"":String(h),onChange:u,"aria-label":`${t.filterBy} ${e.header}`,children:[l.jsx("option",{value:"",children:"-"}),l.jsx("option",{value:"true",children:"β
"}),l.jsx("option",{value:"false",children:"β"})]}):l.jsx("input",{type:e.type==="number"?"number":"text",className:"bt-filter-input",placeholder:`${t.filterBy}...`,value:h!=null?String(h):"",onChange:u,"aria-label":`${t.filterBy} ${e.header}`})};return e.headerCell?l.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},children:e.headerCell(e)}):l.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},role:"columnheader","aria-sort":r?d==="asc"?"ascending":"descending":void 0,tabIndex:e.sortable!==!1?0:void 0,onKeyDown:e.sortable!==!1?f:void 0,children:l.jsxs("div",{className:"bt-th-content",children:[l.jsxs("div",{className:"bt-th-header",children:[l.jsx("span",{className:"bt-th-title",children:e.header}),g()]}),e.filterable!==!1&&p()]})})}const _e=c.memo(Je);function Qe(){const{columns:e,selectable:n,selectionMode:s,rowActions:a,isAllSelected:i,isPartiallySelected:t,selectAll:r,deselectAll:d,locale:b,stickyHeader:u}=T(),f=e.filter(h=>!h.hidden),g=a&&a.length>0,p=()=>{i?d():r()};return l.jsx("thead",{className:S("bt-thead",u&&"bt-sticky"),children:l.jsxs("tr",{className:"bt-tr",children:[n&&l.jsx("th",{className:"bt-th bt-checkbox-cell",children:s==="multiple"&&l.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:i,ref:h=>{h&&(h.indeterminate=t)},onChange:p,"aria-label":i?b.deselectAll:b.selectAll})}),f.map(h=>l.jsx(_e,{column:h},h.id)),g&&l.jsx("th",{className:"bt-th bt-actions-cell",children:b.actions})]})})}const Fe=Qe;function M(e,n){if(!e||!n)return;const s=n.split(".");let a=e;for(const i of s){if(a==null)return;if(typeof a=="object")a=a[i];else return}return a}function we(e,n,s){return[...e].sort((a,i)=>{const t=M(a,n),r=M(i,n);if(t==null)return s==="asc"?1:-1;if(r==null)return s==="asc"?-1:1;if(typeof t=="string"&&typeof r=="string"){const f=t.localeCompare(r,void 0,{sensitivity:"base",numeric:!0});return s==="asc"?f:-f}if(typeof t=="number"&&typeof r=="number")return s==="asc"?t-r:r-t;if(typeof t=="boolean"&&typeof r=="boolean"){const f=t===r?0:t?-1:1;return s==="asc"?f:-f}if(t instanceof Date&&r instanceof Date){const f=t.getTime()-r.getTime();return s==="asc"?f:-f}const d=String(t),b=String(r),u=d.localeCompare(b);return s==="asc"?u:-u})}function Ae(e,n,s){const a=Object.entries(n).filter(([,i])=>i!=null&&i!=="");return a.length===0?e:e.filter(i=>a.every(([t,r])=>{const d=s.find(f=>f.id===t);if(!d)return!0;const b=M(i,String(d.accessor));if(b==null)return!1;switch(d.type??"string"){case"boolean":return b===r;case"number":return String(b)===String(r);case"date":if(b instanceof Date&&r){const f=new Date(String(r));return b.toDateString()===f.toDateString()}return String(b).includes(String(r));case"string":default:return String(b).toLowerCase().includes(String(r).toLowerCase())}}))}function Me(e,n,s,a){if(!n.trim())return e;const i=n.toLowerCase().trim(),t=a?s.filter(r=>a.includes(r.id)):s.filter(r=>r.type!=="custom");return e.filter(r=>t.some(d=>{const b=M(r,String(d.accessor));return b==null?!1:String(b).toLowerCase().includes(i)}))}function Ge({row:e,column:n,rowIndex:s}){const a=M(e,String(n.accessor)),t=(()=>{if(n.cell)return n.cell(a,e,s);if(a==null)return l.jsx("span",{className:"bt-cell-empty",children:"β"});switch(n.type){case"boolean":return a?"β
":"β";case"date":if(a instanceof Date)return a.toLocaleDateString();const r=new Date(String(a));return isNaN(r.getTime())?String(a):r.toLocaleDateString();case"number":return typeof a=="number"?a.toLocaleString():a;case"string":default:return String(a)}})();return l.jsx("td",{className:S("bt-td",n.align&&`bt-align-${n.align}`),style:{width:n.width},children:t})}const Ue=c.memo(Ge);function We({row:e,rowIndex:n}){const{rowActions:s,openModal:a}=T(),i=c.useCallback(t=>{if(t.mode==="callback"&&t.onClick)t.onClick(e,n);else if(t.mode==="modal"&&t.modalContent){const r=t.modalContent;a(l.jsx(r,{data:e,onClose:()=>{}}))}else if(t.mode==="link"&&t.href){const r=typeof t.href=="function"?t.href(e):t.href;window.open(r,"_blank")}},[e,n,a]);return!s||s.length===0?null:l.jsx("td",{className:"bt-td bt-actions-cell",children:l.jsx("div",{className:"bt-actions-wrapper",children:s.map(t=>{if(t.visible&&!t.visible(e))return null;const r=t.disabled?t.disabled(e):!1;if(t.mode==="link"&&t.href){const d=typeof t.href=="function"?t.href(e):t.href;return l.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:S("bt-action-btn",t.variant&&`bt-variant-${t.variant}`),"aria-label":t.label,children:t.icon&&l.jsx("span",{className:"bt-action-icon",children:t.icon})},t.id)}return l.jsx("button",{className:S("bt-action-btn",t.variant&&`bt-variant-${t.variant}`),onClick:()=>i(t),disabled:r,"aria-label":t.label,title:t.label,type:"button",children:t.icon&&l.jsx("span",{className:"bt-action-icon",children:t.icon})},t.id)})})})}const Xe=c.memo(We);function Ye({row:e,rowIndex:n}){const{columns:s,selectable:a,rowActions:i,isSelected:t,toggleRow:r,striped:d,hoverable:b,onRowClick:u,onRowDoubleClick:f}=T(),g=s.filter(y=>!y.hidden),p=i&&i.length>0,h=a&&t(e,n),m=!!u,v=c.useCallback(()=>{u==null||u(e,n)},[e,n,u]),N=c.useCallback(()=>{f==null||f(e,n)},[e,n,f]),P=c.useCallback(()=>{r(e,n)},[e,n,r]),C=c.useCallback(y=>{y.key==="Enter"&&u&&v()},[v,u]);return l.jsxs("tr",{className:S("bt-tr",d&&"bt-striped",b&&"bt-hoverable",h&&"bt-selected",m&&"bt-clickable"),onClick:m?v:void 0,onDoubleClick:f?N:void 0,onKeyDown:m?C:void 0,tabIndex:m?0:void 0,role:m?"button":void 0,"aria-selected":a?h:void 0,children:[a&&l.jsx("td",{className:"bt-td bt-checkbox-cell",children:l.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:h,onChange:P,onClick:y=>y.stopPropagation(),"aria-label":`Select row ${n+1}`})}),g.map(y=>l.jsx(Ue,{row:e,column:y,rowIndex:n},y.id)),p&&l.jsx(Xe,{row:e,rowIndex:n})]})}const Ze=c.memo(Ye);function et(){const{processedData:e,rowKey:n}=T(),s=(a,i)=>{if(typeof n=="function")return n(a,i);const t=a[n];return String(t!==void 0?t:i)};return l.jsx("tbody",{className:"bt-tbody",children:e.map((a,i)=>l.jsx(Ze,{row:a,rowIndex:i},s(a,i)))})}const tt=et;function st(){const{page:e,pageSize:n,totalPages:s,totalItems:a,goToPage:i,nextPage:t,prevPage:r,changePageSize:d,hasNextPage:b,hasPrevPage:u,startIndex:f,endIndex:g,paginationEnabled:p,pageSizeOptions:h,showSizeChanger:m,locale:v,classNames:N}=T(),P=c.useCallback(o=>{d(Number(o.target.value))},[d]),C=c.useCallback(o=>{if(o.key==="Enter"){const x=parseInt(o.target.value,10);!isNaN(x)&&x>=1&&x<=s&&i(x)}},[i,s]),y=c.useMemo(()=>{const o=[];if(s<=5)for(let j=1;j<=s;j++)o.push(j);else{o.push(1),e>3&&o.push("ellipsis");const j=Math.max(2,e-1),k=Math.min(s-1,e+1);for(let D=j;D<=k;D++)o.push(D);e<s-2&&o.push("ellipsis"),s>1&&o.push(s)}return o},[e,s]);return p?l.jsxs("div",{className:`bt-pagination ${N.pagination||""}`,children:[l.jsx("div",{className:"bt-pagination-info",children:a>0?`${f}-${g} ${v.of} ${a} ${v.items}`:`0 ${v.items}`}),l.jsxs("div",{className:"bt-pagination-controls",children:[m&&l.jsxs("div",{className:"bt-page-size",children:[l.jsxs("span",{className:"bt-page-size-label",children:[v.rowsPerPage,":"]}),l.jsx("select",{className:"bt-page-size-select",value:n,onChange:P,"aria-label":v.rowsPerPage,children:h.map(o=>l.jsx("option",{value:o,children:o},o))})]}),l.jsx("button",{className:"bt-pagination-btn",onClick:r,disabled:!u,"aria-label":"Previous page",type:"button",children:"β"}),l.jsx("div",{className:"bt-pagination-pages",children:y.map((o,x)=>o==="ellipsis"?l.jsx("span",{className:"bt-pagination-ellipsis",children:"..."},`ellipsis-${x}`):l.jsx("button",{className:`bt-pagination-btn ${e===o?"bt-active":""}`,onClick:()=>i(o),"aria-label":`${v.page} ${o}`,"aria-current":e===o?"page":void 0,type:"button",children:o},o))}),l.jsx("button",{className:"bt-pagination-btn",onClick:t,disabled:!b,"aria-label":"Next page",type:"button",children:"β"}),l.jsxs("div",{className:"bt-quick-jumper",children:[l.jsxs("span",{className:"bt-quick-jumper-label",children:[v.page,":"]}),l.jsx("input",{type:"number",className:"bt-quick-jumper-input",min:1,max:s,defaultValue:e,onKeyDown:C,"aria-label":"Jump to page"})]})]})]}):null}function at(){const{searchable:e,searchValue:n,handleSearch:s,clearSearch:a,globalActions:i,selectedRows:t,selectedCount:r,deselectAll:d,data:b,locale:u,classNames:f,selectable:g}=T(),p=c.useCallback(m=>{s(m.target.value)},[s]);return e||i&&i.length>0||g&&r>0?l.jsxs("div",{className:`bt-toolbar ${f.toolbar||""}`,children:[l.jsxs("div",{className:"bt-toolbar-left",children:[e&&l.jsxs("div",{className:"bt-search",children:[l.jsx("span",{className:"bt-search-icon",children:"π"}),l.jsx("input",{type:"text",className:"bt-search-input",placeholder:u.searchPlaceholder,value:n,onChange:p,"aria-label":u.search}),n&&l.jsx("button",{className:"bt-search-clear",onClick:a,"aria-label":"Clear search",type:"button",children:"β"})]}),g&&r>0&&l.jsxs("div",{className:"bt-selection-info",children:[l.jsxs("span",{children:[r," ",u.selected]}),l.jsx("button",{className:"bt-selection-clear",onClick:d,type:"button",children:u.deselectAll})]})]}),i&&i.length>0&&l.jsx("div",{className:"bt-toolbar-right",children:l.jsx("div",{className:"bt-global-actions",children:i.map(m=>{const v=m.requiresSelection&&t.length===0;return l.jsxs("button",{className:S("bt-global-btn",m.variant&&`bt-variant-${m.variant}`),onClick:()=>m.onClick(t,b),disabled:v,title:m.label,type:"button",children:[m.icon&&l.jsx("span",{className:"bt-global-icon",children:m.icon}),l.jsx("span",{children:m.label})]},m.id)})})})]}):null}const lt=at;function nt(){const{locale:e,emptyComponent:n,columns:s,selectable:a,rowActions:i}=T(),t=s.filter(b=>!b.hidden),r=i&&i.length>0,d=t.length+(a?1:0)+(r?1:0);return n?l.jsx("tbody",{className:"bt-tbody",children:l.jsx("tr",{className:"bt-tr",children:l.jsx("td",{className:"bt-td",colSpan:d,children:n})})}):l.jsx("tbody",{className:"bt-tbody",children:l.jsx("tr",{className:"bt-tr",children:l.jsx("td",{className:"bt-td",colSpan:d,children:l.jsxs("div",{className:"bt-empty",children:[l.jsx("div",{className:"bt-empty-icon",children:"π"}),l.jsx("div",{className:"bt-empty-text",children:e.noData})]})})})})}function it({show:e}){const{loadingComponent:n,locale:s}=T();return e?l.jsx("div",{className:"bt-loading-overlay",role:"status","aria-live":"polite",children:n||l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"bt-loading-spinner","aria-hidden":"true"}),l.jsx("span",{className:"bt-loading-text",children:s.loading})]})}):null}function rt(){const{isModalOpen:e,modalContent:n,closeModal:s}=T(),a=c.useCallback(t=>{t.target===t.currentTarget&&s()},[s]),i=c.useCallback(t=>{t.key==="Escape"&&s()},[s]);return c.useEffect(()=>(e&&(document.addEventListener("keydown",i),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",i),document.body.style.overflow=""}),[e,i]),!e||!n?null:l.jsx("div",{className:"bt-modal-backdrop",onClick:a,role:"dialog","aria-modal":"true",children:l.jsxs("div",{className:"bt-modal bt-modal-md",children:[l.jsxs("div",{className:"bt-modal-header",children:[l.jsx("h2",{className:"bt-modal-title",children:"Detalles"}),l.jsx("button",{className:"bt-modal-close",onClick:s,"aria-label":"Close modal",type:"button",children:"β"})]}),l.jsx("div",{className:"bt-modal-body",children:n})]})})}function $e({data:e,initialSort:n,controlledSort:s,onSortChange:a}){const[i,t]=c.useState(n??{columnId:null,direction:"asc"}),r=s??i,d=c.useCallback(f=>{const g={columnId:f,direction:r.columnId===f&&r.direction==="asc"?"desc":"asc"};s||t(g),a==null||a(g)},[r,s,a]),b=c.useCallback(()=>{const f={columnId:null,direction:"asc"};s||t(f),a==null||a(f)},[s,a]);return{sortedData:c.useMemo(()=>r.columnId?we(e,r.columnId,r.direction):e,[e,r]),sortState:r,handleSort:d,clearSort:b}}function ze({data:e,columns:n,initialFilters:s,controlledFilters:a,onFilterChange:i}){const[t,r]=c.useState(s??{}),d=a??t,b=c.useCallback((p,h)=>{const m={...d};h==null||h===""?delete m[p]:m[p]=h,a||r(m),i==null||i(m)},[d,a,i]),u=c.useCallback(p=>{const h={...d};delete h[p],a||r(h),i==null||i(h)},[d,a,i]),f=c.useCallback(()=>{a||r({}),i==null||i({})},[a,i]);return{filteredData:c.useMemo(()=>Ae(e,d,n),[e,d,n]),filters:d,setFilter:b,clearFilters:f,clearFilter:u}}function Ie({data:e,config:n,onPageChange:s}){const a=n!==!1,i=n&&typeof n=="object"?n.page??1:1,t=n&&typeof n=="object"?n.pageSize??10:10,r=n&&typeof n=="object"?n.totalItems:void 0,[d,b]=c.useState(i),[u,f]=c.useState(t),g=r??e.length,p=Math.max(1,Math.ceil(g/u)),h=c.useCallback(o=>{const x=Math.max(1,Math.min(o,p));b(x),s==null||s(x,u)},[p,u,s]),m=c.useCallback(()=>{d<p&&h(d+1)},[d,p,h]),v=c.useCallback(()=>{d>1&&h(d-1)},[d,h]),N=c.useCallback(o=>{f(o),b(1),s==null||s(1,o)},[s]),P=c.useMemo(()=>{if(!a||r!==void 0)return e;const o=(d-1)*u;return e.slice(o,o+u)},[e,d,u,a,r]),C=(d-1)*u+1,y=Math.min(d*u,g);return{paginatedData:P,page:d,pageSize:u,totalPages:p,totalItems:g,goToPage:h,nextPage:m,prevPage:v,changePageSize:N,hasNextPage:d<p,hasPrevPage:d>1,startIndex:C,endIndex:y}}function Re({data:e,rowKey:n,mode:s="multiple",initialSelection:a,controlledSelection:i,onSelectionChange:t}){const[r,d]=c.useState(a??[]),b=i??r,u=c.useCallback((o,x)=>typeof n=="function"?n(o,x):String(o[n]),[n]),f=c.useMemo(()=>new Set(b.map((o,x)=>u(o,x))),[b,u]),g=c.useCallback((o,x)=>{const j=u(o,x);return f.has(j)},[u,f]),p=c.useCallback(o=>{i||d(o),t==null||t(o)},[i,t]),h=c.useCallback((o,x)=>{const j=u(o,x);let k;s==="single"?k=f.has(j)?[]:[o]:f.has(j)?k=b.filter((D,A)=>u(D,A)!==j):k=[...b,o],p(k)},[s,f,b,u,p]),m=c.useCallback((o,x)=>{if(!g(o,x)){const j=s==="single"?[o]:[...b,o];p(j)}},[g,s,b,p]),v=c.useCallback((o,x)=>{const j=u(o,x),k=b.filter((D,A)=>u(D,A)!==j);p(k)},[b,u,p]),N=c.useCallback(()=>{s==="multiple"&&p([...e])},[e,s,p]),P=c.useCallback(()=>{p([])},[p]),C=e.length>0&&b.length===e.length,y=b.length>0&&b.length<e.length;return{selectedRows:b,isSelected:g,toggleRow:h,selectRow:m,deselectRow:v,selectAll:N,deselectAll:P,isAllSelected:C,isPartiallySelected:y,selectedCount:b.length}}function Be({data:e,columns:n,searchColumns:s,initialValue:a,controlledValue:i,onSearchChange:t}){const[r,d]=c.useState(a??""),b=i??r,u=c.useCallback(p=>{i===void 0&&d(p),t==null||t(p)},[i,t]),f=c.useCallback(()=>{i===void 0&&d(""),t==null||t("")},[i,t]);return{searchedData:c.useMemo(()=>Me(e,b,n,s),[e,b,n,s]),searchValue:b,handleSearch:u,clearSearch:f}}function ct(e){const{data:n,columns:s,rowKey:a="id",rowActions:i,globalActions:t,pagination:r={pageSize:10},onPageChange:d,sort:b,onSortChange:u,filters:f,onFilterChange:g,searchable:p=!1,searchValue:h,onSearchChange:m,searchColumns:v,selectable:N,selectedRows:P,onSelectionChange:C,selectionMode:y="multiple",loading:o=!1,loadingComponent:x,emptyComponent:j,classNames:k={},styles:D={},locale:A,stickyHeader:R=!1,maxHeight:Le,bordered:$=!1,striped:B=!1,hoverable:L=!0,size:z="medium",onRowClick:O,onRowDoubleClick:E,ariaLabel:Oe,ariaDescribedBy:Ee}=e,q=c.useMemo(()=>N!==void 0?N:(t==null?void 0:t.some(Ve=>Ve.requiresSelection))||C!==void 0,[N,t,C]),K=c.useMemo(()=>({...Ce,...A}),[A]),[H,V]=c.useState(!1),[J,_]=c.useState(null),Q=c.useCallback(Ne=>{_(Ne),V(!0)},[]),F=c.useCallback(()=>{V(!1),_(null)},[]),w=c.useMemo(()=>r===!1?!1:{pageSize:10,pageSizeOptions:[10,20,50,100],showSizeChanger:!1,...r},[r]),{searchedData:qe,searchValue:G,handleSearch:U,clearSearch:W}=Be({data:n,columns:s,searchColumns:v,controlledValue:h,onSearchChange:m}),{filteredData:Ke,filters:X,setFilter:Y,clearFilters:Z}=ze({data:qe,columns:s,controlledFilters:f,onFilterChange:g}),{sortedData:ee,sortState:te,handleSort:se}=$e({data:Ke,controlledSort:b,onSortChange:u}),{selectedRows:ae,isSelected:le,toggleRow:ne,selectAll:ie,deselectAll:re,isAllSelected:ce,isPartiallySelected:oe,selectedCount:de}=Re({data:ee,rowKey:a,mode:y,controlledSelection:P,onSelectionChange:C}),{paginatedData:I,page:be,pageSize:ue,totalPages:fe,totalItems:he,goToPage:pe,nextPage:me,prevPage:ge,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:je,endIndex:ke}=Ie({data:ee,config:w,onPageChange:d}),He=c.useMemo(()=>({data:n,processedData:I,columns:s,rowKey:a,rowActions:i,globalActions:t,sortState:te,handleSort:se,filters:X,setFilter:Y,clearFilters:Z,searchValue:G,handleSearch:U,clearSearch:W,searchable:p,selectedRows:ae,isSelected:le,toggleRow:ne,selectAll:ie,deselectAll:re,isAllSelected:ce,isPartiallySelected:oe,selectable:q,selectionMode:y,selectedCount:de,page:be,pageSize:ue,totalPages:fe,totalItems:he,goToPage:pe,nextPage:me,prevPage:ge,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:je,endIndex:ke,paginationEnabled:r!==!1,pageSizeOptions:w&&typeof w=="object"?w.pageSizeOptions??[10,20,50,100]:[10,20,50,100],showSizeChanger:w&&typeof w=="object"?w.showSizeChanger??!1:!1,loading:o,loadingComponent:x,emptyComponent:j,locale:K,classNames:k,size:z,bordered:$,striped:B,hoverable:L,stickyHeader:R,onRowClick:O,onRowDoubleClick:E,openModal:Q,closeModal:F,modalContent:J,isModalOpen:H}),[n,I,s,a,i,t,te,se,X,Y,Z,G,U,W,p,ae,le,ne,ie,re,ce,oe,q,y,de,be,ue,fe,he,pe,me,ge,xe,ve,ye,je,ke,r,w,o,x,j,K,k,z,$,B,L,R,O,E,Q,F,J,H]),Se=I.length>0;return l.jsx(De,{value:He,children:l.jsxs("div",{className:S("bt-container",`bt-size-${z}`,o&&"bt-container-loading",k.container),style:D.container,children:[l.jsx(lt,{}),l.jsxs("div",{className:S("bt-table-wrapper",$&&"bt-bordered"),style:{maxHeight:Le},children:[l.jsxs("table",{className:S("bt-table",k.table),style:D.table,role:"grid","aria-label":Oe,"aria-describedby":Ee,"aria-busy":o,children:[l.jsx(Fe,{}),Se?l.jsx(tt,{}):l.jsx(nt,{})]}),l.jsx(it,{show:o&&Se})]}),r!==!1&&l.jsx(st,{}),l.jsx(rt,{})]})})}const ot=ct;exports.BetterTable=ot;exports.TableProvider=De;exports.defaultLocale=Ce;exports.filterData=Ae;exports.getValueFromPath=M;exports.searchData=Me;exports.sortData=we;exports.useTableContext=T;exports.useTableFilter=ze;exports.useTablePagination=Ie;exports.useTableSearch=Be;exports.useTableSelection=Re;exports.useTableSort=$e;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),t=require("react/jsx-runtime");require("./styles.cjs");const Ne={search:"Buscar",searchPlaceholder:"Buscar...",noData:"No hay datos",loading:"Cargando...",page:"PΓ‘gina",of:"de",items:"elementos",selected:"seleccionados",rowsPerPage:"Filas por pΓ‘gina",actions:"Acciones",sortAsc:"Ordenar ascendente",sortDesc:"Ordenar descendente",filterBy:"Filtrar por",clearFilters:"Limpiar filtros",selectAll:"Seleccionar todo",deselectAll:"Deseleccionar todo"},De=d.createContext(null);function D(){const e=d.useContext(De);if(!e)throw new Error("useTableContext must be used within a TableProvider");return e}function Te({value:e,children:s}){return t.jsx(De.Provider,{value:e,children:s})}function Pe(e){var s,n,l="";if(typeof e=="string"||typeof e=="number")l+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(s=0;s<r;s++)e[s]&&(n=Pe(e[s]))&&(l&&(l+=" "),l+=n)}else for(n in e)e[n]&&(l&&(l+=" "),l+=n);return l}function S(){for(var e,s,n=0,l="",r=arguments.length;n<r;n++)(e=arguments[n])&&(s=Pe(e))&&(l&&(l+=" "),l+=s);return l}function He({column:e}){const{sortState:s,handleSort:n,filters:l,setFilter:r,locale:a}=D(),i=s.columnId===e.id,u=i?s.direction:null,o=d.useCallback(()=>{e.sortable!==!1&&n(e.id)},[e.id,e.sortable,n]),h=d.useCallback(f=>{const C=f.target.value;e.type==="boolean"?C===""?r(e.id,null):r(e.id,C==="true"):r(e.id,C||null)},[e.id,e.type,r]),p=d.useCallback(f=>{f.key==="Enter"&&e.sortable!==!1&&n(e.id)},[e.id,e.sortable,n]),x=()=>e.sortable===!1||e.type==="custom"?null:t.jsx("button",{className:S("bt-sort-btn",i&&"bt-active"),onClick:o,"aria-label":u==="asc"?a.sortDesc:a.sortAsc,type:"button",children:i?u==="asc"?"β":"β":"β
"}),g=()=>{if(e.filterable===!1||e.type==="custom")return null;const f=l[e.id];return e.type==="boolean"?t.jsxs("select",{className:"bt-filter-select",value:f==null?"":String(f),onChange:h,"aria-label":`${a.filterBy} ${e.header}`,children:[t.jsx("option",{value:"",children:"-"}),t.jsx("option",{value:"true",children:"β
"}),t.jsx("option",{value:"false",children:"β"})]}):t.jsx("input",{type:e.type==="number"?"number":"text",className:"bt-filter-input",placeholder:`${a.filterBy}...`,value:f!=null?String(f):"",onChange:h,"aria-label":`${a.filterBy} ${e.header}`})};return e.headerCell?t.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},children:e.headerCell(e)}):t.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},role:"columnheader","aria-sort":i?u==="asc"?"ascending":"descending":void 0,tabIndex:e.sortable!==!1?0:void 0,onKeyDown:e.sortable!==!1?p:void 0,children:t.jsxs("div",{className:"bt-th-content",children:[t.jsxs("div",{className:"bt-th-header",children:[t.jsx("span",{className:"bt-th-title",children:e.header}),x()]}),e.filterable!==!1&&g()]})})}const _e=d.memo(He);function Je(){const{columns:e,selectable:s,selectionMode:n,rowActions:l,isAllSelected:r,isPartiallySelected:a,selectAll:i,deselectAll:u,locale:o,stickyHeader:h}=D(),p=e.filter(f=>!f.hidden),x=l&&l.length>0,g=()=>{r?u():i()};return t.jsx("thead",{className:S("bt-thead",h&&"bt-sticky"),children:t.jsxs("tr",{className:"bt-tr",children:[s&&t.jsx("th",{className:"bt-th bt-checkbox-cell",children:n==="multiple"&&t.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:r,ref:f=>{f&&(f.indeterminate=a)},onChange:g,"aria-label":r?o.deselectAll:o.selectAll})}),p.map(f=>t.jsx(_e,{column:f},f.id)),x&&t.jsx("th",{className:"bt-th bt-actions-cell",children:o.actions})]})})}const Qe=Je;function M(e,s){if(!e||!s)return;const n=s.split(".");let l=e;for(const r of n){if(l==null)return;if(typeof l=="object")l=l[r];else return}return l}function Ae(e,s,n){return[...e].sort((l,r)=>{const a=M(l,s),i=M(r,s);if(a==null)return n==="asc"?1:-1;if(i==null)return n==="asc"?-1:1;if(typeof a=="string"&&typeof i=="string"){const p=a.localeCompare(i,void 0,{sensitivity:"base",numeric:!0});return n==="asc"?p:-p}if(typeof a=="number"&&typeof i=="number")return n==="asc"?a-i:i-a;if(typeof a=="boolean"&&typeof i=="boolean"){const p=a===i?0:a?-1:1;return n==="asc"?p:-p}if(a instanceof Date&&i instanceof Date){const p=a.getTime()-i.getTime();return n==="asc"?p:-p}const u=String(a),o=String(i),h=u.localeCompare(o);return n==="asc"?h:-h})}function Me(e,s,n){const l=Object.entries(s).filter(([,r])=>r!=null&&r!=="");return l.length===0?e:e.filter(r=>l.every(([a,i])=>{const u=n.find(p=>p.id===a);if(!u)return!0;const o=M(r,String(u.accessor));if(o==null)return!1;switch(u.type??"string"){case"boolean":return o===i;case"number":return String(o)===String(i);case"date":if(o instanceof Date&&i){const p=new Date(String(i));return o.toDateString()===p.toDateString()}return String(o).includes(String(i));default:return String(o).toLowerCase().includes(String(i).toLowerCase())}}))}function we(e,s,n,l){if(!s.trim())return e;const r=s.toLowerCase().trim(),a=l?n.filter(i=>l.includes(i.id)):n.filter(i=>i.type!=="custom");return e.filter(i=>a.some(u=>{const o=M(i,String(u.accessor));return o==null?!1:String(o).toLowerCase().includes(r)}))}function Ge({row:e,column:s,rowIndex:n}){const l=M(e,String(s.accessor)),a=(()=>{if(s.cell)return s.cell(l,e,n);if(l==null)return t.jsx("span",{className:"bt-cell-empty",children:"β"});switch(s.type){case"boolean":return l?"β
":"β";case"date":if(l instanceof Date)return l.toLocaleDateString();const i=new Date(String(l));return isNaN(i.getTime())?String(l):i.toLocaleDateString();case"number":return typeof l=="number"?l.toLocaleString():l;default:return String(l)}})();return t.jsx("td",{className:S("bt-td",s.align&&`bt-align-${s.align}`),style:{width:s.width},children:a})}const Ue=d.memo(Ge);function We({row:e,rowIndex:s}){const{rowActions:n,openModal:l}=D(),r=d.useCallback(a=>{if(a.mode==="callback"&&a.onClick)a.onClick(e,s);else if(a.mode==="modal"&&a.modalContent){const i=a.modalContent;l(t.jsx(i,{data:e,onClose:()=>{}}))}else if(a.mode==="link"&&a.href){const i=typeof a.href=="function"?a.href(e):a.href;window.open(i,"_blank")}},[e,s,l]);return!n||n.length===0?null:t.jsx("td",{className:"bt-td bt-actions-cell",children:t.jsx("div",{className:"bt-actions-wrapper",children:n.map(a=>{if(a.visible&&!a.visible(e))return null;const i=a.disabled?a.disabled(e):!1;if(a.mode==="link"&&a.href){const u=typeof a.href=="function"?a.href(e):a.href;return t.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:S("bt-action-btn",a.variant&&`bt-variant-${a.variant}`),"aria-label":a.label,children:a.icon&&t.jsx("span",{className:"bt-action-icon",children:a.icon})},a.id)}return t.jsx("button",{className:S("bt-action-btn",a.variant&&`bt-variant-${a.variant}`),onClick:()=>r(a),disabled:i,"aria-label":a.label,title:a.label,type:"button",children:a.icon&&t.jsx("span",{className:"bt-action-icon",children:a.icon})},a.id)})})})}const Xe=d.memo(We);function Ye({row:e,rowIndex:s}){const{columns:n,selectable:l,rowActions:r,isSelected:a,toggleRow:i,striped:u,hoverable:o,onRowClick:h,onRowDoubleClick:p}=D(),x=n.filter(j=>!j.hidden),g=r&&r.length>0,f=l&&a(e,s),C=!!h,y=d.useCallback(()=>{h?.(e,s)},[e,s,h]),k=d.useCallback(()=>{p?.(e,s)},[e,s,p]),P=d.useCallback(()=>{i(e,s)},[e,s,i]),N=d.useCallback(j=>{j.key==="Enter"&&h&&y()},[y,h]);return t.jsxs("tr",{className:S("bt-tr",u&&"bt-striped",o&&"bt-hoverable",f&&"bt-selected",C&&"bt-clickable"),onClick:C?y:void 0,onDoubleClick:p?k:void 0,onKeyDown:C?N:void 0,tabIndex:C?0:void 0,role:C?"button":void 0,"aria-selected":l?f:void 0,children:[l&&t.jsx("td",{className:"bt-td bt-checkbox-cell",children:t.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:f,onChange:P,onClick:j=>j.stopPropagation(),"aria-label":`Select row ${s+1}`})}),x.map(j=>t.jsx(Ue,{row:e,column:j,rowIndex:s},j.id)),g&&t.jsx(Xe,{row:e,rowIndex:s})]})}const Ze=d.memo(Ye);function et(){const{processedData:e,rowKey:s}=D(),n=(l,r)=>{if(typeof s=="function")return s(l,r);const a=l[s];return String(a!==void 0?a:r)};return t.jsx("tbody",{className:"bt-tbody",children:e.map((l,r)=>t.jsx(Ze,{row:l,rowIndex:r},n(l,r)))})}const tt=et;function st({row:e,rowIndex:s}){const{columns:n,selectable:l,rowActions:r,isSelected:a,toggleRow:i,hoverable:u,onRowClick:o,openModal:h}=D(),p=n.filter(c=>!c.hidden),x=r&&r.length>0,g=l&&a(e,s),f=p[0],C=p.slice(1),y=d.useCallback(()=>{i(e,s)},[e,s,i]),k=d.useCallback(()=>{o?.(e,s)},[e,s,o]),P=d.useCallback(c=>{c.key==="Enter"&&o&&k()},[k,o]),N=d.useCallback(c=>{if(c.mode==="callback"&&c.onClick)c.onClick(e,s);else if(c.mode==="modal"&&c.modalContent){const m=c.modalContent;h(t.jsx(m,{data:e,onClose:()=>{}}))}else if(c.mode==="link"&&c.href){const m=typeof c.href=="function"?c.href(e):c.href;window.open(m,"_blank")}},[e,s,h]),j=(c,m)=>{if(c.cell)return c.cell(m,e,s);if(m==null)return t.jsx("span",{className:"bt-card-value-empty",children:"β"});switch(c.type){case"boolean":return m?"β
":"β";case"date":if(m instanceof Date)return m.toLocaleDateString();const v=new Date(String(m));return isNaN(v.getTime())?String(m):v.toLocaleDateString();case"number":return typeof m=="number"?m.toLocaleString():String(m);default:return String(m)}},b=f?M(e,String(f.accessor)):"";return t.jsxs("div",{className:S("bt-card",u&&"bt-hoverable",g&&"bt-selected",o&&"bt-clickable"),onClick:o?k:void 0,onKeyDown:o?P:void 0,tabIndex:o?0:void 0,role:o?"button":void 0,"aria-selected":l?g:void 0,children:[t.jsxs("div",{className:"bt-card-header",children:[l&&t.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:g,onChange:y,onClick:c=>c.stopPropagation(),"aria-label":`Select row ${s+1}`}),t.jsx("span",{className:"bt-card-title",children:f?j(f,b):`Item ${s+1}`})]}),C.map(c=>{const m=M(e,String(c.accessor)),v=j(c,m);return t.jsxs("div",{className:"bt-card-row",children:[t.jsx("span",{className:"bt-card-label",children:c.header}),t.jsx("span",{className:"bt-card-value",children:v})]},c.id)}),x&&t.jsx("div",{className:"bt-card-actions",children:r.map(c=>{if(c.visible&&!c.visible(e))return null;const m=c.disabled?c.disabled(e):!1;if(c.mode==="link"&&c.href){const v=typeof c.href=="function"?c.href(e):c.href;return t.jsxs("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:S("bt-action-btn",c.variant&&`bt-variant-${c.variant}`),onClick:T=>T.stopPropagation(),children:[c.icon&&t.jsx("span",{className:"bt-action-icon",children:c.icon}),t.jsx("span",{children:c.label})]},c.id)}return t.jsxs("button",{className:S("bt-action-btn",c.variant&&`bt-variant-${c.variant}`),onClick:v=>{v.stopPropagation(),N(c)},disabled:m,type:"button",children:[c.icon&&t.jsx("span",{className:"bt-action-icon",children:c.icon}),t.jsx("span",{children:c.label})]},c.id)})})]})}const at=d.memo(st);function lt(){const{processedData:e,rowKey:s}=D(),n=(l,r)=>{if(typeof s=="function")return s(l,r);const a=l[s];return String(a!==void 0?a:r)};return t.jsx("div",{className:"bt-cards",children:e.map((l,r)=>t.jsx(at,{row:l,rowIndex:r},n(l,r)))})}const nt=lt;function rt(){const{page:e,pageSize:s,totalPages:n,totalItems:l,goToPage:r,nextPage:a,prevPage:i,changePageSize:u,hasNextPage:o,hasPrevPage:h,startIndex:p,endIndex:x,paginationEnabled:g,pageSizeOptions:f,showSizeChanger:C,locale:y,classNames:k}=D(),P=d.useCallback(b=>{u(Number(b.target.value))},[u]),N=d.useCallback(b=>{if(b.key==="Enter"){const c=parseInt(b.target.value,10);!isNaN(c)&&c>=1&&c<=n&&r(c)}},[r,n]),j=d.useMemo(()=>{const b=[];if(n<=5)for(let m=1;m<=n;m++)b.push(m);else{b.push(1),e>3&&b.push("ellipsis");const m=Math.max(2,e-1),v=Math.min(n-1,e+1);for(let T=m;T<=v;T++)b.push(T);e<n-2&&b.push("ellipsis"),n>1&&b.push(n)}return b},[e,n]);return g?t.jsxs("div",{className:`bt-pagination ${k.pagination||""}`,children:[t.jsx("div",{className:"bt-pagination-info",children:l>0?`${p}-${x} ${y.of} ${l} ${y.items}`:`0 ${y.items}`}),t.jsxs("div",{className:"bt-pagination-controls",children:[C&&t.jsxs("div",{className:"bt-page-size",children:[t.jsxs("span",{className:"bt-page-size-label",children:[y.rowsPerPage,":"]}),t.jsx("select",{className:"bt-page-size-select",value:s,onChange:P,"aria-label":y.rowsPerPage,children:f.map(b=>t.jsx("option",{value:b,children:b},b))})]}),t.jsx("button",{className:"bt-pagination-btn",onClick:i,disabled:!h,"aria-label":"Previous page",type:"button",children:"β"}),t.jsx("div",{className:"bt-pagination-pages",children:j.map((b,c)=>b==="ellipsis"?t.jsx("span",{className:"bt-pagination-ellipsis",children:"..."},`ellipsis-${c}`):t.jsx("button",{className:`bt-pagination-btn ${e===b?"bt-active":""}`,onClick:()=>r(b),"aria-label":`${y.page} ${b}`,"aria-current":e===b?"page":void 0,type:"button",children:b},b))}),t.jsx("button",{className:"bt-pagination-btn",onClick:a,disabled:!o,"aria-label":"Next page",type:"button",children:"β"}),t.jsxs("div",{className:"bt-quick-jumper",children:[t.jsxs("span",{className:"bt-quick-jumper-label",children:[y.page,":"]}),t.jsx("input",{type:"number",className:"bt-quick-jumper-input",min:1,max:n,defaultValue:e,onKeyDown:N,"aria-label":"Jump to page"})]})]})]}):null}function it(){const{searchable:e,searchValue:s,handleSearch:n,clearSearch:l,globalActions:r,selectedRows:a,selectedCount:i,deselectAll:u,data:o,locale:h,classNames:p,selectable:x}=D(),g=d.useCallback(C=>{n(C.target.value)},[n]);return e||r&&r.length>0||x&&i>0?t.jsxs("div",{className:`bt-toolbar ${p.toolbar||""}`,children:[t.jsxs("div",{className:"bt-toolbar-left",children:[e&&t.jsxs("div",{className:"bt-search",children:[t.jsx("span",{className:"bt-search-icon",children:"π"}),t.jsx("input",{type:"text",className:"bt-search-input",placeholder:h.searchPlaceholder,value:s,onChange:g,"aria-label":h.search}),s&&t.jsx("button",{className:"bt-search-clear",onClick:l,"aria-label":"Clear search",type:"button",children:"β"})]}),x&&i>0&&t.jsxs("div",{className:"bt-selection-info",children:[t.jsxs("span",{children:[i," ",h.selected]}),t.jsx("button",{className:"bt-selection-clear",onClick:u,type:"button",children:h.deselectAll})]})]}),r&&r.length>0&&t.jsx("div",{className:"bt-toolbar-right",children:t.jsx("div",{className:"bt-global-actions",children:r.map(C=>{const y=C.requiresSelection&&a.length===0;return t.jsxs("button",{className:S("bt-global-btn",C.variant&&`bt-variant-${C.variant}`),onClick:()=>C.onClick(a,o),disabled:y,title:C.label,type:"button",children:[C.icon&&t.jsx("span",{className:"bt-global-icon",children:C.icon}),t.jsx("span",{children:C.label})]},C.id)})})})]}):null}const ct=it;function ot(){const{locale:e,emptyComponent:s,columns:n,selectable:l,rowActions:r}=D(),a=n.filter(o=>!o.hidden),i=r&&r.length>0,u=a.length+(l?1:0)+(i?1:0);return s?t.jsx("tbody",{className:"bt-tbody",children:t.jsx("tr",{className:"bt-tr",children:t.jsx("td",{className:"bt-td",colSpan:u,children:s})})}):t.jsx("tbody",{className:"bt-tbody",children:t.jsx("tr",{className:"bt-tr",children:t.jsx("td",{className:"bt-td",colSpan:u,children:t.jsxs("div",{className:"bt-empty",children:[t.jsx("div",{className:"bt-empty-icon",children:"π"}),t.jsx("div",{className:"bt-empty-text",children:e.noData})]})})})})}function dt({show:e}){const{loadingComponent:s,locale:n}=D();return e?t.jsx("div",{className:"bt-loading-overlay",role:"status","aria-live":"polite",children:s||t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bt-loading-spinner","aria-hidden":"true"}),t.jsx("span",{className:"bt-loading-text",children:n.loading})]})}):null}function bt(){const{isModalOpen:e,modalContent:s,closeModal:n}=D(),l=d.useCallback(a=>{a.target===a.currentTarget&&n()},[n]),r=d.useCallback(a=>{a.key==="Escape"&&n()},[n]);return d.useEffect(()=>(e&&(document.addEventListener("keydown",r),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",r),document.body.style.overflow=""}),[e,r]),!e||!s?null:t.jsx("div",{className:"bt-modal-backdrop",onClick:l,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"bt-modal bt-modal-md",children:[t.jsxs("div",{className:"bt-modal-header",children:[t.jsx("h2",{className:"bt-modal-title",children:"Detalles"}),t.jsx("button",{className:"bt-modal-close",onClick:n,"aria-label":"Close modal",type:"button",children:"β"})]}),t.jsx("div",{className:"bt-modal-body",children:s})]})})}function $e({data:e,initialSort:s,controlledSort:n,onSortChange:l}){const[r,a]=d.useState(s??{columnId:null,direction:"asc"}),i=n??r,u=d.useCallback(p=>{const x={columnId:p,direction:i.columnId===p&&i.direction==="asc"?"desc":"asc"};n||a(x),l?.(x)},[i,n,l]),o=d.useCallback(()=>{const p={columnId:null,direction:"asc"};n||a(p),l?.(p)},[n,l]);return{sortedData:d.useMemo(()=>i.columnId?Ae(e,i.columnId,i.direction):e,[e,i]),sortState:i,handleSort:u,clearSort:o}}function Re({data:e,columns:s,initialFilters:n,controlledFilters:l,onFilterChange:r}){const[a,i]=d.useState(n??{}),u=l??a,o=d.useCallback((g,f)=>{const C={...u};f==null||f===""?delete C[g]:C[g]=f,l||i(C),r?.(C)},[u,l,r]),h=d.useCallback(g=>{const f={...u};delete f[g],l||i(f),r?.(f)},[u,l,r]),p=d.useCallback(()=>{l||i({}),r?.({})},[l,r]);return{filteredData:d.useMemo(()=>Me(e,u,s),[e,u,s]),filters:u,setFilter:o,clearFilters:p,clearFilter:h}}function ze({data:e,config:s,onPageChange:n}){const l=s!==!1,r=s&&typeof s=="object"?s.page??1:1,a=s&&typeof s=="object"?s.pageSize??10:10,i=s&&typeof s=="object"?s.totalItems:void 0,[u,o]=d.useState(r),[h,p]=d.useState(a),x=i??e.length,g=Math.max(1,Math.ceil(x/h)),f=d.useCallback(b=>{const c=Math.max(1,Math.min(b,g));o(c),n?.(c,h)},[g,h,n]),C=d.useCallback(()=>{u<g&&f(u+1)},[u,g,f]),y=d.useCallback(()=>{u>1&&f(u-1)},[u,f]),k=d.useCallback(b=>{p(b),o(1),n?.(1,b)},[n]),P=d.useMemo(()=>{if(!l||i!==void 0)return e;const b=(u-1)*h;return e.slice(b,b+h)},[e,u,h,l,i]),N=(u-1)*h+1,j=Math.min(u*h,x);return{paginatedData:P,page:u,pageSize:h,totalPages:g,totalItems:x,goToPage:f,nextPage:C,prevPage:y,changePageSize:k,hasNextPage:u<g,hasPrevPage:u>1,startIndex:N,endIndex:j}}function Le({data:e,rowKey:s,mode:n="multiple",initialSelection:l,controlledSelection:r,onSelectionChange:a}){const[i,u]=d.useState(l??[]),o=r??i,h=d.useCallback((b,c)=>typeof s=="function"?s(b,c):String(b[s]),[s]),p=d.useMemo(()=>new Set(o.map((b,c)=>h(b,c))),[o,h]),x=d.useCallback((b,c)=>{const m=h(b,c);return p.has(m)},[h,p]),g=d.useCallback(b=>{r||u(b),a?.(b)},[r,a]),f=d.useCallback((b,c)=>{const m=h(b,c);let v;n==="single"?v=p.has(m)?[]:[b]:p.has(m)?v=o.filter((T,w)=>h(T,w)!==m):v=[...o,b],g(v)},[n,p,o,h,g]),C=d.useCallback((b,c)=>{if(!x(b,c)){const m=n==="single"?[b]:[...o,b];g(m)}},[x,n,o,g]),y=d.useCallback((b,c)=>{const m=h(b,c),v=o.filter((T,w)=>h(T,w)!==m);g(v)},[o,h,g]),k=d.useCallback(()=>{n==="multiple"&&g([...e])},[e,n,g]),P=d.useCallback(()=>{g([])},[g]),N=e.length>0&&o.length===e.length,j=o.length>0&&o.length<e.length;return{selectedRows:o,isSelected:x,toggleRow:f,selectRow:C,deselectRow:y,selectAll:k,deselectAll:P,isAllSelected:N,isPartiallySelected:j,selectedCount:o.length}}function Ie({data:e,columns:s,searchColumns:n,initialValue:l,controlledValue:r,onSearchChange:a}){const[i,u]=d.useState(l??""),o=r??i,h=d.useCallback(g=>{r===void 0&&u(g),a?.(g)},[r,a]),p=d.useCallback(()=>{r===void 0&&u(""),a?.("")},[r,a]);return{searchedData:d.useMemo(()=>we(e,o,s,n),[e,o,s,n]),searchValue:o,handleSearch:h,clearSearch:p}}function ut(e){const{data:s,columns:n,rowKey:l="id",rowActions:r,globalActions:a,pagination:i={pageSize:10},onPageChange:u,sort:o,onSortChange:h,filters:p,onFilterChange:x,searchable:g=!1,searchValue:f,onSearchChange:C,searchColumns:y,selectable:k,selectedRows:P,onSelectionChange:N,selectionMode:j="multiple",loading:b=!1,loadingComponent:c,emptyComponent:m,classNames:v={},styles:T={},locale:w,stickyHeader:E=!1,maxHeight:Be,bordered:$=!1,striped:R=!1,hoverable:z=!0,size:L="medium",onRowClick:F,onRowDoubleClick:K,ariaLabel:Ee,ariaDescribedBy:Fe}=e,O=d.useMemo(()=>k!==void 0?k:a?.some(qe=>qe.requiresSelection)||N!==void 0,[k,a,N]),V=d.useMemo(()=>({...Ne,...w}),[w]),[q,H]=d.useState(!1),[_,J]=d.useState(null),Q=d.useCallback(Se=>{J(Se),H(!0)},[]),G=d.useCallback(()=>{H(!1),J(null)},[]),A=d.useMemo(()=>i===!1?!1:{pageSize:10,pageSizeOptions:[10,20,50,100],showSizeChanger:!1,...i},[i]),{searchedData:Ke,searchValue:U,handleSearch:W,clearSearch:X}=Ie({data:s,columns:n,searchColumns:y,controlledValue:f,onSearchChange:C}),{filteredData:Oe,filters:Y,setFilter:Z,clearFilters:ee}=Re({data:Ke,columns:n,controlledFilters:p,onFilterChange:x}),{sortedData:te,sortState:se,handleSort:ae}=$e({data:Oe,controlledSort:o,onSortChange:h}),{selectedRows:le,isSelected:ne,toggleRow:re,selectAll:ie,deselectAll:ce,isAllSelected:oe,isPartiallySelected:de,selectedCount:be}=Le({data:te,rowKey:l,mode:j,controlledSelection:P,onSelectionChange:N}),{paginatedData:I,page:ue,pageSize:he,totalPages:fe,totalItems:pe,goToPage:ge,nextPage:me,prevPage:Ce,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:je,endIndex:ke}=ze({data:te,config:A,onPageChange:u}),Ve=d.useMemo(()=>({data:s,processedData:I,columns:n,rowKey:l,rowActions:r,globalActions:a,sortState:se,handleSort:ae,filters:Y,setFilter:Z,clearFilters:ee,searchValue:U,handleSearch:W,clearSearch:X,searchable:g,selectedRows:le,isSelected:ne,toggleRow:re,selectAll:ie,deselectAll:ce,isAllSelected:oe,isPartiallySelected:de,selectable:O,selectionMode:j,selectedCount:be,page:ue,pageSize:he,totalPages:fe,totalItems:pe,goToPage:ge,nextPage:me,prevPage:Ce,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:je,endIndex:ke,paginationEnabled:i!==!1,pageSizeOptions:A&&typeof A=="object"?A.pageSizeOptions??[10,20,50,100]:[10,20,50,100],showSizeChanger:A&&typeof A=="object"?A.showSizeChanger??!1:!1,loading:b,loadingComponent:c,emptyComponent:m,locale:V,classNames:v,size:L,bordered:$,striped:R,hoverable:z,stickyHeader:E,onRowClick:F,onRowDoubleClick:K,openModal:Q,closeModal:G,modalContent:_,isModalOpen:q}),[s,I,n,l,r,a,se,ae,Y,Z,ee,U,W,X,g,le,ne,re,ie,ce,oe,de,O,j,be,ue,he,fe,pe,ge,me,Ce,xe,ve,ye,je,ke,i,A,b,c,m,V,v,L,$,R,z,E,F,K,Q,G,_,q]),B=I.length>0;return t.jsx(Te,{value:Ve,children:t.jsxs("div",{className:S("bt-container",`bt-size-${L}`,R&&"bt-striped",$&&"bt-bordered",z&&"bt-hoverable",b&&"bt-container-loading",v.container),style:T.container,children:[t.jsx(ct,{}),t.jsxs("div",{className:"bt-table-wrapper",style:{maxHeight:Be},children:[t.jsxs("table",{className:S("bt-table",v.table),style:T.table,role:"grid","aria-label":Ee,"aria-describedby":Fe,"aria-busy":b,children:[t.jsx(Qe,{}),B?t.jsx(tt,{}):t.jsx(ot,{})]}),B&&t.jsx(nt,{}),t.jsx(dt,{show:b&&B})]}),i!==!1&&t.jsx(rt,{}),t.jsx(bt,{})]})})}const ht=ut;exports.BetterTable=ht;exports.TableProvider=Te;exports.defaultLocale=Ne;exports.filterData=Me;exports.getValueFromPath=M;exports.searchData=we;exports.sortData=Ae;exports.useTableContext=D;exports.useTableFilter=Re;exports.useTablePagination=ze;exports.useTableSearch=Ie;exports.useTableSelection=Le;exports.useTableSort=$e;
|
|
2
2
|
//# sourceMappingURL=better-table.cjs.js.map
|