better-table 1.0.1 β 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 +847 -692
- 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 +1 -1
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"),s=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"},Pe=c.createContext(null);function P(){const e=c.useContext(Pe);if(!e)throw new Error("useTableContext must be used within a TableProvider");return e}function Te({value:e,children:a}){return s.jsx(Pe.Provider,{value:e,children:a})}function De(e){var a,l,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(a=0;a<r;a++)e[a]&&(l=De(e[a]))&&(n&&(n+=" "),n+=l)}else for(l in e)e[l]&&(n&&(n+=" "),n+=l);return n}function S(){for(var e,a,l=0,n="",r=arguments.length;l<r;l++)(e=arguments[l])&&(a=De(e))&&(n&&(n+=" "),n+=a);return n}function Ve({column:e}){const{sortState:a,handleSort:l,filters:n,setFilter:r,locale:t}=P(),i=a.columnId===e.id,d=i?a.direction:null,b=c.useCallback(()=>{e.sortable!==!1&&l(e.id)},[e.id,e.sortable,l]),u=c.useCallback(f=>{const g=f.target.value;e.type==="boolean"?g===""?r(e.id,null):r(e.id,g==="true"):r(e.id,g||null)},[e.id,e.type,r]),h=c.useCallback(f=>{f.key==="Enter"&&e.sortable!==!1&&l(e.id)},[e.id,e.sortable,l]),m=()=>e.sortable===!1||e.type==="custom"?null:s.jsx("button",{className:S("bt-sort-btn",i&&"bt-active"),onClick:b,"aria-label":d==="asc"?t.sortDesc:t.sortAsc,type:"button",children:i?d==="asc"?"β":"β":"β
"}),p=()=>{if(e.filterable===!1||e.type==="custom")return null;const f=n[e.id];return e.type==="boolean"?s.jsxs("select",{className:"bt-filter-select",value:f==null?"":String(f),onChange:u,"aria-label":`${t.filterBy} ${e.header}`,children:[s.jsx("option",{value:"",children:"-"}),s.jsx("option",{value:"true",children:"β
"}),s.jsx("option",{value:"false",children:"β"})]}):s.jsx("input",{type:e.type==="number"?"number":"text",className:"bt-filter-input",placeholder:`${t.filterBy}...`,value:f!=null?String(f):"",onChange:u,"aria-label":`${t.filterBy} ${e.header}`})};return e.headerCell?s.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},children:e.headerCell(e)}):s.jsx("th",{className:S("bt-th",e.align&&`bt-align-${e.align}`),style:{width:e.width},role:"columnheader","aria-sort":i?d==="asc"?"ascending":"descending":void 0,tabIndex:e.sortable!==!1?0:void 0,onKeyDown:e.sortable!==!1?h:void 0,children:s.jsxs("div",{className:"bt-th-content",children:[s.jsxs("div",{className:"bt-th-header",children:[s.jsx("span",{className:"bt-th-title",children:e.header}),m()]}),e.filterable!==!1&&p()]})})}const Je=c.memo(Ve);function _e(){const{columns:e,selectable:a,selectionMode:l,rowActions:n,isAllSelected:r,isPartiallySelected:t,selectAll:i,deselectAll:d,locale:b,stickyHeader:u}=P(),h=e.filter(f=>!f.hidden),m=n&&n.length>0,p=()=>{r?d():i()};return s.jsx("thead",{className:S("bt-thead",u&&"bt-sticky"),children:s.jsxs("tr",{className:"bt-tr",children:[a&&s.jsx("th",{className:"bt-th bt-checkbox-cell",children:l==="multiple"&&s.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:r,ref:f=>{f&&(f.indeterminate=t)},onChange:p,"aria-label":r?b.deselectAll:b.selectAll})}),h.map(f=>s.jsx(Je,{column:f},f.id)),m&&s.jsx("th",{className:"bt-th bt-actions-cell",children:b.actions})]})})}const Qe=_e;function M(e,a){if(!e||!a)return;const l=a.split(".");let n=e;for(const r of l){if(n==null)return;if(typeof n=="object")n=n[r];else return}return n}function we(e,a,l){return[...e].sort((n,r)=>{const t=M(n,a),i=M(r,a);if(t==null)return l==="asc"?1:-1;if(i==null)return l==="asc"?-1:1;if(typeof t=="string"&&typeof i=="string"){const h=t.localeCompare(i,void 0,{sensitivity:"base",numeric:!0});return l==="asc"?h:-h}if(typeof t=="number"&&typeof i=="number")return l==="asc"?t-i:i-t;if(typeof t=="boolean"&&typeof i=="boolean"){const h=t===i?0:t?-1:1;return l==="asc"?h:-h}if(t instanceof Date&&i instanceof Date){const h=t.getTime()-i.getTime();return l==="asc"?h:-h}const d=String(t),b=String(i),u=d.localeCompare(b);return l==="asc"?u:-u})}function Ae(e,a,l){const n=Object.entries(a).filter(([,r])=>r!=null&&r!=="");return n.length===0?e:e.filter(r=>n.every(([t,i])=>{const d=l.find(h=>h.id===t);if(!d)return!0;const b=M(r,String(d.accessor));if(b==null)return!1;switch(d.type??"string"){case"boolean":return b===i;case"number":return String(b)===String(i);case"date":if(b instanceof Date&&i){const h=new Date(String(i));return b.toDateString()===h.toDateString()}return String(b).includes(String(i));default:return String(b).toLowerCase().includes(String(i).toLowerCase())}}))}function Me(e,a,l,n){if(!a.trim())return e;const r=a.toLowerCase().trim(),t=n?l.filter(i=>n.includes(i.id)):l.filter(i=>i.type!=="custom");return e.filter(i=>t.some(d=>{const b=M(i,String(d.accessor));return b==null?!1:String(b).toLowerCase().includes(r)}))}function Ge({row:e,column:a,rowIndex:l}){const n=M(e,String(a.accessor)),t=(()=>{if(a.cell)return a.cell(n,e,l);if(n==null)return s.jsx("span",{className:"bt-cell-empty",children:"β"});switch(a.type){case"boolean":return n?"β
":"β";case"date":if(n instanceof Date)return n.toLocaleDateString();const i=new Date(String(n));return isNaN(i.getTime())?String(n):i.toLocaleDateString();case"number":return typeof n=="number"?n.toLocaleString():n;default:return String(n)}})();return s.jsx("td",{className:S("bt-td",a.align&&`bt-align-${a.align}`),style:{width:a.width},children:t})}const Ue=c.memo(Ge);function We({row:e,rowIndex:a}){const{rowActions:l,openModal:n}=P(),r=c.useCallback(t=>{if(t.mode==="callback"&&t.onClick)t.onClick(e,a);else if(t.mode==="modal"&&t.modalContent){const i=t.modalContent;n(s.jsx(i,{data:e,onClose:()=>{}}))}else if(t.mode==="link"&&t.href){const i=typeof t.href=="function"?t.href(e):t.href;window.open(i,"_blank")}},[e,a,n]);return!l||l.length===0?null:s.jsx("td",{className:"bt-td bt-actions-cell",children:s.jsx("div",{className:"bt-actions-wrapper",children:l.map(t=>{if(t.visible&&!t.visible(e))return null;const i=t.disabled?t.disabled(e):!1;if(t.mode==="link"&&t.href){const d=typeof t.href=="function"?t.href(e):t.href;return s.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&&s.jsx("span",{className:"bt-action-icon",children:t.icon})},t.id)}return s.jsx("button",{className:S("bt-action-btn",t.variant&&`bt-variant-${t.variant}`),onClick:()=>r(t),disabled:i,"aria-label":t.label,title:t.label,type:"button",children:t.icon&&s.jsx("span",{className:"bt-action-icon",children:t.icon})},t.id)})})})}const Xe=c.memo(We);function Ye({row:e,rowIndex:a}){const{columns:l,selectable:n,rowActions:r,isSelected:t,toggleRow:i,striped:d,hoverable:b,onRowClick:u,onRowDoubleClick:h}=P(),m=l.filter(y=>!y.hidden),p=r&&r.length>0,f=n&&t(e,a),g=!!u,v=c.useCallback(()=>{u?.(e,a)},[e,a,u]),k=c.useCallback(()=>{h?.(e,a)},[e,a,h]),D=c.useCallback(()=>{i(e,a)},[e,a,i]),N=c.useCallback(y=>{y.key==="Enter"&&u&&v()},[v,u]);return s.jsxs("tr",{className:S("bt-tr",d&&"bt-striped",b&&"bt-hoverable",f&&"bt-selected",g&&"bt-clickable"),onClick:g?v:void 0,onDoubleClick:h?k:void 0,onKeyDown:g?N:void 0,tabIndex:g?0:void 0,role:g?"button":void 0,"aria-selected":n?f:void 0,children:[n&&s.jsx("td",{className:"bt-td bt-checkbox-cell",children:s.jsx("input",{type:"checkbox",className:"bt-checkbox",checked:f,onChange:D,onClick:y=>y.stopPropagation(),"aria-label":`Select row ${a+1}`})}),m.map(y=>s.jsx(Ue,{row:e,column:y,rowIndex:a},y.id)),p&&s.jsx(Xe,{row:e,rowIndex:a})]})}const Ze=c.memo(Ye);function et(){const{processedData:e,rowKey:a}=P(),l=(n,r)=>{if(typeof a=="function")return a(n,r);const t=n[a];return String(t!==void 0?t:r)};return s.jsx("tbody",{className:"bt-tbody",children:e.map((n,r)=>s.jsx(Ze,{row:n,rowIndex:r},l(n,r)))})}const tt=et;function st(){const{page:e,pageSize:a,totalPages:l,totalItems:n,goToPage:r,nextPage:t,prevPage:i,changePageSize:d,hasNextPage:b,hasPrevPage:u,startIndex:h,endIndex:m,paginationEnabled:p,pageSizeOptions:f,showSizeChanger:g,locale:v,classNames:k}=P(),D=c.useCallback(o=>{d(Number(o.target.value))},[d]),N=c.useCallback(o=>{if(o.key==="Enter"){const x=parseInt(o.target.value,10);!isNaN(x)&&x>=1&&x<=l&&r(x)}},[r,l]),y=c.useMemo(()=>{const o=[];if(l<=5)for(let C=1;C<=l;C++)o.push(C);else{o.push(1),e>3&&o.push("ellipsis");const C=Math.max(2,e-1),j=Math.min(l-1,e+1);for(let T=C;T<=j;T++)o.push(T);e<l-2&&o.push("ellipsis"),l>1&&o.push(l)}return o},[e,l]);return p?s.jsxs("div",{className:`bt-pagination ${k.pagination||""}`,children:[s.jsx("div",{className:"bt-pagination-info",children:n>0?`${h}-${m} ${v.of} ${n} ${v.items}`:`0 ${v.items}`}),s.jsxs("div",{className:"bt-pagination-controls",children:[g&&s.jsxs("div",{className:"bt-page-size",children:[s.jsxs("span",{className:"bt-page-size-label",children:[v.rowsPerPage,":"]}),s.jsx("select",{className:"bt-page-size-select",value:a,onChange:D,"aria-label":v.rowsPerPage,children:f.map(o=>s.jsx("option",{value:o,children:o},o))})]}),s.jsx("button",{className:"bt-pagination-btn",onClick:i,disabled:!u,"aria-label":"Previous page",type:"button",children:"β"}),s.jsx("div",{className:"bt-pagination-pages",children:y.map((o,x)=>o==="ellipsis"?s.jsx("span",{className:"bt-pagination-ellipsis",children:"..."},`ellipsis-${x}`):s.jsx("button",{className:`bt-pagination-btn ${e===o?"bt-active":""}`,onClick:()=>r(o),"aria-label":`${v.page} ${o}`,"aria-current":e===o?"page":void 0,type:"button",children:o},o))}),s.jsx("button",{className:"bt-pagination-btn",onClick:t,disabled:!b,"aria-label":"Next page",type:"button",children:"β"}),s.jsxs("div",{className:"bt-quick-jumper",children:[s.jsxs("span",{className:"bt-quick-jumper-label",children:[v.page,":"]}),s.jsx("input",{type:"number",className:"bt-quick-jumper-input",min:1,max:l,defaultValue:e,onKeyDown:N,"aria-label":"Jump to page"})]})]})]}):null}function at(){const{searchable:e,searchValue:a,handleSearch:l,clearSearch:n,globalActions:r,selectedRows:t,selectedCount:i,deselectAll:d,data:b,locale:u,classNames:h,selectable:m}=P(),p=c.useCallback(g=>{l(g.target.value)},[l]);return e||r&&r.length>0||m&&i>0?s.jsxs("div",{className:`bt-toolbar ${h.toolbar||""}`,children:[s.jsxs("div",{className:"bt-toolbar-left",children:[e&&s.jsxs("div",{className:"bt-search",children:[s.jsx("span",{className:"bt-search-icon",children:"π"}),s.jsx("input",{type:"text",className:"bt-search-input",placeholder:u.searchPlaceholder,value:a,onChange:p,"aria-label":u.search}),a&&s.jsx("button",{className:"bt-search-clear",onClick:n,"aria-label":"Clear search",type:"button",children:"β"})]}),m&&i>0&&s.jsxs("div",{className:"bt-selection-info",children:[s.jsxs("span",{children:[i," ",u.selected]}),s.jsx("button",{className:"bt-selection-clear",onClick:d,type:"button",children:u.deselectAll})]})]}),r&&r.length>0&&s.jsx("div",{className:"bt-toolbar-right",children:s.jsx("div",{className:"bt-global-actions",children:r.map(g=>{const v=g.requiresSelection&&t.length===0;return s.jsxs("button",{className:S("bt-global-btn",g.variant&&`bt-variant-${g.variant}`),onClick:()=>g.onClick(t,b),disabled:v,title:g.label,type:"button",children:[g.icon&&s.jsx("span",{className:"bt-global-icon",children:g.icon}),s.jsx("span",{children:g.label})]},g.id)})})})]}):null}const lt=at;function nt(){const{locale:e,emptyComponent:a,columns:l,selectable:n,rowActions:r}=P(),t=l.filter(b=>!b.hidden),i=r&&r.length>0,d=t.length+(n?1:0)+(i?1:0);return a?s.jsx("tbody",{className:"bt-tbody",children:s.jsx("tr",{className:"bt-tr",children:s.jsx("td",{className:"bt-td",colSpan:d,children:a})})}):s.jsx("tbody",{className:"bt-tbody",children:s.jsx("tr",{className:"bt-tr",children:s.jsx("td",{className:"bt-td",colSpan:d,children:s.jsxs("div",{className:"bt-empty",children:[s.jsx("div",{className:"bt-empty-icon",children:"π"}),s.jsx("div",{className:"bt-empty-text",children:e.noData})]})})})})}function it({show:e}){const{loadingComponent:a,locale:l}=P();return e?s.jsx("div",{className:"bt-loading-overlay",role:"status","aria-live":"polite",children:a||s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"bt-loading-spinner","aria-hidden":"true"}),s.jsx("span",{className:"bt-loading-text",children:l.loading})]})}):null}function rt(){const{isModalOpen:e,modalContent:a,closeModal:l}=P(),n=c.useCallback(t=>{t.target===t.currentTarget&&l()},[l]),r=c.useCallback(t=>{t.key==="Escape"&&l()},[l]);return c.useEffect(()=>(e&&(document.addEventListener("keydown",r),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",r),document.body.style.overflow=""}),[e,r]),!e||!a?null:s.jsx("div",{className:"bt-modal-backdrop",onClick:n,role:"dialog","aria-modal":"true",children:s.jsxs("div",{className:"bt-modal bt-modal-md",children:[s.jsxs("div",{className:"bt-modal-header",children:[s.jsx("h2",{className:"bt-modal-title",children:"Detalles"}),s.jsx("button",{className:"bt-modal-close",onClick:l,"aria-label":"Close modal",type:"button",children:"β"})]}),s.jsx("div",{className:"bt-modal-body",children:a})]})})}function $e({data:e,initialSort:a,controlledSort:l,onSortChange:n}){const[r,t]=c.useState(a??{columnId:null,direction:"asc"}),i=l??r,d=c.useCallback(h=>{const m={columnId:h,direction:i.columnId===h&&i.direction==="asc"?"desc":"asc"};l||t(m),n?.(m)},[i,l,n]),b=c.useCallback(()=>{const h={columnId:null,direction:"asc"};l||t(h),n?.(h)},[l,n]);return{sortedData:c.useMemo(()=>i.columnId?we(e,i.columnId,i.direction):e,[e,i]),sortState:i,handleSort:d,clearSort:b}}function ze({data:e,columns:a,initialFilters:l,controlledFilters:n,onFilterChange:r}){const[t,i]=c.useState(l??{}),d=n??t,b=c.useCallback((p,f)=>{const g={...d};f==null||f===""?delete g[p]:g[p]=f,n||i(g),r?.(g)},[d,n,r]),u=c.useCallback(p=>{const f={...d};delete f[p],n||i(f),r?.(f)},[d,n,r]),h=c.useCallback(()=>{n||i({}),r?.({})},[n,r]);return{filteredData:c.useMemo(()=>Ae(e,d,a),[e,d,a]),filters:d,setFilter:b,clearFilters:h,clearFilter:u}}function Re({data:e,config:a,onPageChange:l}){const n=a!==!1,r=a&&typeof a=="object"?a.page??1:1,t=a&&typeof a=="object"?a.pageSize??10:10,i=a&&typeof a=="object"?a.totalItems:void 0,[d,b]=c.useState(r),[u,h]=c.useState(t),m=i??e.length,p=Math.max(1,Math.ceil(m/u)),f=c.useCallback(o=>{const x=Math.max(1,Math.min(o,p));b(x),l?.(x,u)},[p,u,l]),g=c.useCallback(()=>{d<p&&f(d+1)},[d,p,f]),v=c.useCallback(()=>{d>1&&f(d-1)},[d,f]),k=c.useCallback(o=>{h(o),b(1),l?.(1,o)},[l]),D=c.useMemo(()=>{if(!n||i!==void 0)return e;const o=(d-1)*u;return e.slice(o,o+u)},[e,d,u,n,i]),N=(d-1)*u+1,y=Math.min(d*u,m);return{paginatedData:D,page:d,pageSize:u,totalPages:p,totalItems:m,goToPage:f,nextPage:g,prevPage:v,changePageSize:k,hasNextPage:d<p,hasPrevPage:d>1,startIndex:N,endIndex:y}}function Ie({data:e,rowKey:a,mode:l="multiple",initialSelection:n,controlledSelection:r,onSelectionChange:t}){const[i,d]=c.useState(n??[]),b=r??i,u=c.useCallback((o,x)=>typeof a=="function"?a(o,x):String(o[a]),[a]),h=c.useMemo(()=>new Set(b.map((o,x)=>u(o,x))),[b,u]),m=c.useCallback((o,x)=>{const C=u(o,x);return h.has(C)},[u,h]),p=c.useCallback(o=>{r||d(o),t?.(o)},[r,t]),f=c.useCallback((o,x)=>{const C=u(o,x);let j;l==="single"?j=h.has(C)?[]:[o]:h.has(C)?j=b.filter((T,A)=>u(T,A)!==C):j=[...b,o],p(j)},[l,h,b,u,p]),g=c.useCallback((o,x)=>{if(!m(o,x)){const C=l==="single"?[o]:[...b,o];p(C)}},[m,l,b,p]),v=c.useCallback((o,x)=>{const C=u(o,x),j=b.filter((T,A)=>u(T,A)!==C);p(j)},[b,u,p]),k=c.useCallback(()=>{l==="multiple"&&p([...e])},[e,l,p]),D=c.useCallback(()=>{p([])},[p]),N=e.length>0&&b.length===e.length,y=b.length>0&&b.length<e.length;return{selectedRows:b,isSelected:m,toggleRow:f,selectRow:g,deselectRow:v,selectAll:k,deselectAll:D,isAllSelected:N,isPartiallySelected:y,selectedCount:b.length}}function Be({data:e,columns:a,searchColumns:l,initialValue:n,controlledValue:r,onSearchChange:t}){const[i,d]=c.useState(n??""),b=r??i,u=c.useCallback(p=>{r===void 0&&d(p),t?.(p)},[r,t]),h=c.useCallback(()=>{r===void 0&&d(""),t?.("")},[r,t]);return{searchedData:c.useMemo(()=>Me(e,b,a,l),[e,b,a,l]),searchValue:b,handleSearch:u,clearSearch:h}}function ct(e){const{data:a,columns:l,rowKey:n="id",rowActions:r,globalActions:t,pagination:i={pageSize:10},onPageChange:d,sort:b,onSortChange:u,filters:h,onFilterChange:m,searchable:p=!1,searchValue:f,onSearchChange:g,searchColumns:v,selectable:k,selectedRows:D,onSelectionChange:N,selectionMode:y="multiple",loading:o=!1,loadingComponent:x,emptyComponent:C,classNames:j={},styles:T={},locale:A,stickyHeader:I=!1,maxHeight:Le,bordered:$=!1,striped:B=!1,hoverable:L=!0,size:z="medium",onRowClick:F,onRowDoubleClick:O,ariaLabel:Fe,ariaDescribedBy:Oe}=e,E=c.useMemo(()=>k!==void 0?k:t?.some(He=>He.requiresSelection)||N!==void 0,[k,t,N]),q=c.useMemo(()=>({...Ne,...A}),[A]),[K,H]=c.useState(!1),[V,J]=c.useState(null),_=c.useCallback(ke=>{J(ke),H(!0)},[]),Q=c.useCallback(()=>{H(!1),J(null)},[]),w=c.useMemo(()=>i===!1?!1:{pageSize:10,pageSizeOptions:[10,20,50,100],showSizeChanger:!1,...i},[i]),{searchedData:Ee,searchValue:G,handleSearch:U,clearSearch:W}=Be({data:a,columns:l,searchColumns:v,controlledValue:f,onSearchChange:g}),{filteredData:qe,filters:X,setFilter:Y,clearFilters:Z}=ze({data:Ee,columns:l,controlledFilters:h,onFilterChange:m}),{sortedData:ee,sortState:te,handleSort:se}=$e({data:qe,controlledSort:b,onSortChange:u}),{selectedRows:ae,isSelected:le,toggleRow:ne,selectAll:ie,deselectAll:re,isAllSelected:ce,isPartiallySelected:oe,selectedCount:de}=Ie({data:ee,rowKey:n,mode:y,controlledSelection:D,onSelectionChange:N}),{paginatedData:R,page:be,pageSize:ue,totalPages:he,totalItems:fe,goToPage:pe,nextPage:ge,prevPage:me,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:Ce,endIndex:je}=Re({data:ee,config:w,onPageChange:d}),Ke=c.useMemo(()=>({data:a,processedData:R,columns:l,rowKey:n,rowActions:r,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:E,selectionMode:y,selectedCount:de,page:be,pageSize:ue,totalPages:he,totalItems:fe,goToPage:pe,nextPage:ge,prevPage:me,changePageSize:xe,hasNextPage:ve,hasPrevPage:ye,startIndex:Ce,endIndex:je,paginationEnabled:i!==!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:C,locale:q,classNames:j,size:z,bordered:$,striped:B,hoverable:L,stickyHeader:I,onRowClick:F,onRowDoubleClick:O,openModal:_,closeModal:Q,modalContent:V,isModalOpen:K}),[a,R,l,n,r,t,te,se,X,Y,Z,G,U,W,p,ae,le,ne,ie,re,ce,oe,E,y,de,be,ue,he,fe,pe,ge,me,xe,ve,ye,Ce,je,i,w,o,x,C,q,j,z,$,B,L,I,F,O,_,Q,V,K]),Se=R.length>0;return s.jsx(Te,{value:Ke,children:s.jsxs("div",{className:S("bt-container",`bt-size-${z}`,o&&"bt-container-loading",j.container),style:T.container,children:[s.jsx(lt,{}),s.jsxs("div",{className:S("bt-table-wrapper",$&&"bt-bordered"),style:{maxHeight:Le},children:[s.jsxs("table",{className:S("bt-table",j.table),style:T.table,role:"grid","aria-label":Fe,"aria-describedby":Oe,"aria-busy":o,children:[s.jsx(Qe,{}),Se?s.jsx(tt,{}):s.jsx(nt,{})]}),s.jsx(it,{show:o&&Se})]}),i!==!1&&s.jsx(st,{}),s.jsx(rt,{})]})})}const ot=ct;exports.BetterTable=ot;exports.TableProvider=Te;exports.defaultLocale=Ne;exports.filterData=Ae;exports.getValueFromPath=M;exports.searchData=Me;exports.sortData=we;exports.useTableContext=P;exports.useTableFilter=ze;exports.useTablePagination=Re;exports.useTableSearch=Be;exports.useTableSelection=Ie;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
|