better-table 1.0.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.
Files changed (41) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/better-table.cjs.js +2 -0
  4. package/dist/better-table.cjs.js.map +1 -0
  5. package/dist/better-table.css +1 -0
  6. package/dist/better-table.es.js +1182 -0
  7. package/dist/better-table.es.js.map +1 -0
  8. package/dist/components/BetterTable/components/Table.d.ts +4 -0
  9. package/dist/components/BetterTable/components/TableActions.d.ts +8 -0
  10. package/dist/components/BetterTable/components/TableBody.d.ts +4 -0
  11. package/dist/components/BetterTable/components/TableCell.d.ts +9 -0
  12. package/dist/components/BetterTable/components/TableEmpty.d.ts +1 -0
  13. package/dist/components/BetterTable/components/TableHeader.d.ts +4 -0
  14. package/dist/components/BetterTable/components/TableHeaderCell.d.ts +7 -0
  15. package/dist/components/BetterTable/components/TableLoading.d.ts +6 -0
  16. package/dist/components/BetterTable/components/TableModal.d.ts +1 -0
  17. package/dist/components/BetterTable/components/TablePagination.d.ts +1 -0
  18. package/dist/components/BetterTable/components/TableRow.d.ts +8 -0
  19. package/dist/components/BetterTable/components/TableToolbar.d.ts +4 -0
  20. package/dist/components/BetterTable/components/index.d.ts +12 -0
  21. package/dist/components/BetterTable/context/TableContext.d.ts +68 -0
  22. package/dist/components/BetterTable/context/index.d.ts +2 -0
  23. package/dist/components/BetterTable/hooks/index.d.ts +5 -0
  24. package/dist/components/BetterTable/hooks/useTableFilter.d.ts +17 -0
  25. package/dist/components/BetterTable/hooks/useTablePagination.d.ts +23 -0
  26. package/dist/components/BetterTable/hooks/useTableSearch.d.ts +18 -0
  27. package/dist/components/BetterTable/hooks/useTableSelection.d.ts +23 -0
  28. package/dist/components/BetterTable/hooks/useTableSort.d.ts +15 -0
  29. package/dist/components/BetterTable/index.d.ts +13 -0
  30. package/dist/components/BetterTable/types.d.ts +236 -0
  31. package/dist/components/BetterTable/utils/filterData.d.ts +18 -0
  32. package/dist/components/BetterTable/utils/getValueFromPath.d.ts +7 -0
  33. package/dist/components/BetterTable/utils/index.d.ts +3 -0
  34. package/dist/components/BetterTable/utils/sortData.d.ts +9 -0
  35. package/dist/index.d.ts +19 -0
  36. package/dist/styles.cjs +2 -0
  37. package/dist/styles.cjs.map +1 -0
  38. package/dist/styles.d.ts +0 -0
  39. package/dist/styles.js +2 -0
  40. package/dist/styles.js.map +1 -0
  41. package/package.json +99 -0
@@ -0,0 +1,1182 @@
1
+ import B, { useContext as Ee, createContext as Oe, useCallback as m, useMemo as x, useEffect as Ke, useState as I } from "react";
2
+ import { jsx as r, jsxs as y, Fragment as He } from "react/jsx-runtime";
3
+ import "./styles.js";
4
+ const Ve = {
5
+ search: "Buscar",
6
+ searchPlaceholder: "Buscar...",
7
+ noData: "No hay datos",
8
+ loading: "Cargando...",
9
+ page: "Página",
10
+ of: "de",
11
+ items: "elementos",
12
+ selected: "seleccionados",
13
+ rowsPerPage: "Filas por página",
14
+ actions: "Acciones",
15
+ sortAsc: "Ordenar ascendente",
16
+ sortDesc: "Ordenar descendente",
17
+ filterBy: "Filtrar por",
18
+ clearFilters: "Limpiar filtros",
19
+ selectAll: "Seleccionar todo",
20
+ deselectAll: "Deseleccionar todo"
21
+ }, Ce = Oe(null);
22
+ function C() {
23
+ const e = Ee(Ce);
24
+ if (!e)
25
+ throw new Error("useTableContext must be used within a TableProvider");
26
+ return e;
27
+ }
28
+ function qe({
29
+ value: e,
30
+ children: s
31
+ }) {
32
+ return /* @__PURE__ */ r(Ce.Provider, { value: e, children: s });
33
+ }
34
+ function $e(e) {
35
+ var s, a, l = "";
36
+ if (typeof e == "string" || typeof e == "number") l += e;
37
+ else if (typeof e == "object") if (Array.isArray(e)) {
38
+ var n = e.length;
39
+ for (s = 0; s < n; s++) e[s] && (a = $e(e[s])) && (l && (l += " "), l += a);
40
+ } else for (a in e) e[a] && (l && (l += " "), l += a);
41
+ return l;
42
+ }
43
+ function T() {
44
+ for (var e, s, a = 0, l = "", n = arguments.length; a < n; a++) (e = arguments[a]) && (s = $e(e)) && (l && (l += " "), l += s);
45
+ return l;
46
+ }
47
+ function Je({
48
+ column: e
49
+ }) {
50
+ const {
51
+ sortState: s,
52
+ handleSort: a,
53
+ filters: l,
54
+ setFilter: n,
55
+ locale: t
56
+ } = C(), i = s.columnId === e.id, o = i ? s.direction : null, d = m(() => {
57
+ e.sortable !== !1 && a(e.id);
58
+ }, [e.id, e.sortable, a]), b = m(
59
+ (f) => {
60
+ const p = f.target.value;
61
+ e.type === "boolean" ? p === "" ? n(e.id, null) : n(e.id, p === "true") : n(e.id, p || null);
62
+ },
63
+ [e.id, e.type, n]
64
+ ), u = m(
65
+ (f) => {
66
+ f.key === "Enter" && e.sortable !== !1 && a(e.id);
67
+ },
68
+ [e.id, e.sortable, a]
69
+ ), g = () => e.sortable === !1 || e.type === "custom" ? null : /* @__PURE__ */ r(
70
+ "button",
71
+ {
72
+ className: T("bt-sort-btn", i && "bt-active"),
73
+ onClick: d,
74
+ "aria-label": o === "asc" ? t.sortDesc : t.sortAsc,
75
+ type: "button",
76
+ children: i ? o === "asc" ? "↑" : "↓" : "⇅"
77
+ }
78
+ ), h = () => {
79
+ if (e.filterable === !1 || e.type === "custom")
80
+ return null;
81
+ const f = l[e.id];
82
+ return e.type === "boolean" ? /* @__PURE__ */ y(
83
+ "select",
84
+ {
85
+ className: "bt-filter-select",
86
+ value: f == null ? "" : String(f),
87
+ onChange: b,
88
+ "aria-label": `${t.filterBy} ${e.header}`,
89
+ children: [
90
+ /* @__PURE__ */ r("option", { value: "", children: "-" }),
91
+ /* @__PURE__ */ r("option", { value: "true", children: "✅" }),
92
+ /* @__PURE__ */ r("option", { value: "false", children: "❌" })
93
+ ]
94
+ }
95
+ ) : /* @__PURE__ */ r(
96
+ "input",
97
+ {
98
+ type: e.type === "number" ? "number" : "text",
99
+ className: "bt-filter-input",
100
+ placeholder: `${t.filterBy}...`,
101
+ value: f != null ? String(f) : "",
102
+ onChange: b,
103
+ "aria-label": `${t.filterBy} ${e.header}`
104
+ }
105
+ );
106
+ };
107
+ return e.headerCell ? /* @__PURE__ */ r(
108
+ "th",
109
+ {
110
+ className: T("bt-th", e.align && `bt-align-${e.align}`),
111
+ style: { width: e.width },
112
+ children: e.headerCell(e)
113
+ }
114
+ ) : /* @__PURE__ */ r(
115
+ "th",
116
+ {
117
+ className: T("bt-th", e.align && `bt-align-${e.align}`),
118
+ style: { width: e.width },
119
+ role: "columnheader",
120
+ "aria-sort": i ? o === "asc" ? "ascending" : "descending" : void 0,
121
+ tabIndex: e.sortable !== !1 ? 0 : void 0,
122
+ onKeyDown: e.sortable !== !1 ? u : void 0,
123
+ children: /* @__PURE__ */ y("div", { className: "bt-th-content", children: [
124
+ /* @__PURE__ */ y("div", { className: "bt-th-header", children: [
125
+ /* @__PURE__ */ r("span", { className: "bt-th-title", children: e.header }),
126
+ g()
127
+ ] }),
128
+ e.filterable !== !1 && h()
129
+ ] })
130
+ }
131
+ );
132
+ }
133
+ const _e = B.memo(
134
+ Je
135
+ );
136
+ function Qe() {
137
+ const {
138
+ columns: e,
139
+ selectable: s,
140
+ selectionMode: a,
141
+ rowActions: l,
142
+ isAllSelected: n,
143
+ isPartiallySelected: t,
144
+ selectAll: i,
145
+ deselectAll: o,
146
+ locale: d,
147
+ stickyHeader: b
148
+ } = C(), u = e.filter((f) => !f.hidden), g = l && l.length > 0, h = () => {
149
+ n ? o() : i();
150
+ };
151
+ return /* @__PURE__ */ r("thead", { className: T("bt-thead", b && "bt-sticky"), children: /* @__PURE__ */ y("tr", { className: "bt-tr", children: [
152
+ s && /* @__PURE__ */ r("th", { className: "bt-th bt-checkbox-cell", children: a === "multiple" && /* @__PURE__ */ r(
153
+ "input",
154
+ {
155
+ type: "checkbox",
156
+ className: "bt-checkbox",
157
+ checked: n,
158
+ ref: (f) => {
159
+ f && (f.indeterminate = t);
160
+ },
161
+ onChange: h,
162
+ "aria-label": n ? d.deselectAll : d.selectAll
163
+ }
164
+ ) }),
165
+ u.map((f) => /* @__PURE__ */ r(_e, { column: f }, f.id)),
166
+ g && /* @__PURE__ */ r("th", { className: "bt-th bt-actions-cell", children: d.actions })
167
+ ] }) });
168
+ }
169
+ const Ge = Qe;
170
+ function R(e, s) {
171
+ if (!e || !s) return;
172
+ const a = s.split(".");
173
+ let l = e;
174
+ for (const n of a) {
175
+ if (l == null)
176
+ return;
177
+ if (typeof l == "object")
178
+ l = l[n];
179
+ else
180
+ return;
181
+ }
182
+ return l;
183
+ }
184
+ function Ue(e, s, a) {
185
+ return [...e].sort((l, n) => {
186
+ const t = R(l, s), i = R(n, s);
187
+ if (t == null)
188
+ return a === "asc" ? 1 : -1;
189
+ if (i == null)
190
+ return a === "asc" ? -1 : 1;
191
+ if (typeof t == "string" && typeof i == "string") {
192
+ const u = t.localeCompare(i, void 0, {
193
+ sensitivity: "base",
194
+ numeric: !0
195
+ });
196
+ return a === "asc" ? u : -u;
197
+ }
198
+ if (typeof t == "number" && typeof i == "number")
199
+ return a === "asc" ? t - i : i - t;
200
+ if (typeof t == "boolean" && typeof i == "boolean") {
201
+ const u = t === i ? 0 : t ? -1 : 1;
202
+ return a === "asc" ? u : -u;
203
+ }
204
+ if (t instanceof Date && i instanceof Date) {
205
+ const u = t.getTime() - i.getTime();
206
+ return a === "asc" ? u : -u;
207
+ }
208
+ const o = String(t), d = String(i), b = o.localeCompare(d);
209
+ return a === "asc" ? b : -b;
210
+ });
211
+ }
212
+ function We(e, s, a) {
213
+ const l = Object.entries(s).filter(
214
+ ([, n]) => n != null && n !== ""
215
+ );
216
+ return l.length === 0 ? e : e.filter((n) => l.every(([t, i]) => {
217
+ const o = a.find((u) => u.id === t);
218
+ if (!o) return !0;
219
+ const d = R(
220
+ n,
221
+ String(o.accessor)
222
+ );
223
+ if (d == null)
224
+ return !1;
225
+ switch (o.type ?? "string") {
226
+ case "boolean":
227
+ return d === i;
228
+ case "number":
229
+ return String(d) === String(i);
230
+ case "date":
231
+ if (d instanceof Date && i) {
232
+ const u = new Date(String(i));
233
+ return d.toDateString() === u.toDateString();
234
+ }
235
+ return String(d).includes(String(i));
236
+ case "string":
237
+ default:
238
+ return String(d).toLowerCase().includes(String(i).toLowerCase());
239
+ }
240
+ }));
241
+ }
242
+ function Xe(e, s, a, l) {
243
+ if (!s.trim())
244
+ return e;
245
+ const n = s.toLowerCase().trim(), t = l ? a.filter((i) => l.includes(i.id)) : a.filter((i) => i.type !== "custom");
246
+ return e.filter(
247
+ (i) => t.some((o) => {
248
+ const d = R(
249
+ i,
250
+ String(o.accessor)
251
+ );
252
+ return d == null ? !1 : String(d).toLowerCase().includes(n);
253
+ })
254
+ );
255
+ }
256
+ function Ye({
257
+ row: e,
258
+ column: s,
259
+ rowIndex: a
260
+ }) {
261
+ const l = R(
262
+ e,
263
+ String(s.accessor)
264
+ ), t = (() => {
265
+ if (s.cell)
266
+ return s.cell(l, e, a);
267
+ if (l == null)
268
+ return /* @__PURE__ */ r("span", { className: "bt-cell-empty", children: "—" });
269
+ switch (s.type) {
270
+ case "boolean":
271
+ return l ? "✅" : "❌";
272
+ case "date":
273
+ if (l instanceof Date)
274
+ return l.toLocaleDateString();
275
+ const i = new Date(String(l));
276
+ return isNaN(i.getTime()) ? String(l) : i.toLocaleDateString();
277
+ case "number":
278
+ return typeof l == "number" ? l.toLocaleString() : l;
279
+ case "string":
280
+ default:
281
+ return String(l);
282
+ }
283
+ })();
284
+ return /* @__PURE__ */ r(
285
+ "td",
286
+ {
287
+ className: T("bt-td", s.align && `bt-align-${s.align}`),
288
+ style: { width: s.width },
289
+ children: t
290
+ }
291
+ );
292
+ }
293
+ const Ze = B.memo(Ye);
294
+ function Fe({
295
+ row: e,
296
+ rowIndex: s
297
+ }) {
298
+ const { rowActions: a, openModal: l } = C(), n = m(
299
+ (t) => {
300
+ if (t.mode === "callback" && t.onClick)
301
+ t.onClick(e, s);
302
+ else if (t.mode === "modal" && t.modalContent) {
303
+ const i = t.modalContent;
304
+ l(
305
+ /* @__PURE__ */ r(
306
+ i,
307
+ {
308
+ data: e,
309
+ onClose: () => {
310
+ }
311
+ }
312
+ )
313
+ );
314
+ } else if (t.mode === "link" && t.href) {
315
+ const i = typeof t.href == "function" ? t.href(e) : t.href;
316
+ window.open(i, "_blank");
317
+ }
318
+ },
319
+ [e, s, l]
320
+ );
321
+ return !a || a.length === 0 ? null : /* @__PURE__ */ r("td", { className: "bt-td bt-actions-cell", children: /* @__PURE__ */ r("div", { className: "bt-actions-wrapper", children: a.map((t) => {
322
+ if (t.visible && !t.visible(e))
323
+ return null;
324
+ const i = t.disabled ? t.disabled(e) : !1;
325
+ if (t.mode === "link" && t.href) {
326
+ const o = typeof t.href == "function" ? t.href(e) : t.href;
327
+ return /* @__PURE__ */ r(
328
+ "a",
329
+ {
330
+ href: o,
331
+ target: "_blank",
332
+ rel: "noopener noreferrer",
333
+ className: T(
334
+ "bt-action-btn",
335
+ t.variant && `bt-variant-${t.variant}`
336
+ ),
337
+ "aria-label": t.label,
338
+ children: t.icon && /* @__PURE__ */ r("span", { className: "bt-action-icon", children: t.icon })
339
+ },
340
+ t.id
341
+ );
342
+ }
343
+ return /* @__PURE__ */ r(
344
+ "button",
345
+ {
346
+ className: T(
347
+ "bt-action-btn",
348
+ t.variant && `bt-variant-${t.variant}`
349
+ ),
350
+ onClick: () => n(t),
351
+ disabled: i,
352
+ "aria-label": t.label,
353
+ title: t.label,
354
+ type: "button",
355
+ children: t.icon && /* @__PURE__ */ r("span", { className: "bt-action-icon", children: t.icon })
356
+ },
357
+ t.id
358
+ );
359
+ }) }) });
360
+ }
361
+ const et = B.memo(
362
+ Fe
363
+ );
364
+ function tt({ row: e, rowIndex: s }) {
365
+ const {
366
+ columns: a,
367
+ selectable: l,
368
+ rowActions: n,
369
+ isSelected: t,
370
+ toggleRow: i,
371
+ striped: o,
372
+ hoverable: d,
373
+ onRowClick: b,
374
+ onRowDoubleClick: u
375
+ } = C(), g = a.filter((S) => !S.hidden), h = n && n.length > 0, f = l && t(e, s), p = !!b, N = m(() => {
376
+ b == null || b(e, s);
377
+ }, [e, s, b]), P = m(() => {
378
+ u == null || u(e, s);
379
+ }, [e, s, u]), $ = m(() => {
380
+ i(e, s);
381
+ }, [e, s, i]), w = m(
382
+ (S) => {
383
+ S.key === "Enter" && b && N();
384
+ },
385
+ [N, b]
386
+ );
387
+ return /* @__PURE__ */ y(
388
+ "tr",
389
+ {
390
+ className: T(
391
+ "bt-tr",
392
+ o && "bt-striped",
393
+ d && "bt-hoverable",
394
+ f && "bt-selected",
395
+ p && "bt-clickable"
396
+ ),
397
+ onClick: p ? N : void 0,
398
+ onDoubleClick: u ? P : void 0,
399
+ onKeyDown: p ? w : void 0,
400
+ tabIndex: p ? 0 : void 0,
401
+ role: p ? "button" : void 0,
402
+ "aria-selected": l ? f : void 0,
403
+ children: [
404
+ l && /* @__PURE__ */ r("td", { className: "bt-td bt-checkbox-cell", children: /* @__PURE__ */ r(
405
+ "input",
406
+ {
407
+ type: "checkbox",
408
+ className: "bt-checkbox",
409
+ checked: f,
410
+ onChange: $,
411
+ onClick: (S) => S.stopPropagation(),
412
+ "aria-label": `Select row ${s + 1}`
413
+ }
414
+ ) }),
415
+ g.map((S) => /* @__PURE__ */ r(
416
+ Ze,
417
+ {
418
+ row: e,
419
+ column: S,
420
+ rowIndex: s
421
+ },
422
+ S.id
423
+ )),
424
+ h && /* @__PURE__ */ r(et, { row: e, rowIndex: s })
425
+ ]
426
+ }
427
+ );
428
+ }
429
+ const at = B.memo(tt);
430
+ function lt() {
431
+ const { processedData: e, rowKey: s } = C(), a = (l, n) => {
432
+ if (typeof s == "function")
433
+ return s(l, n);
434
+ const t = l[s];
435
+ return String(t !== void 0 ? t : n);
436
+ };
437
+ return /* @__PURE__ */ r("tbody", { className: "bt-tbody", children: e.map((l, n) => /* @__PURE__ */ r(at, { row: l, rowIndex: n }, a(l, n))) });
438
+ }
439
+ const st = lt;
440
+ function nt() {
441
+ const {
442
+ page: e,
443
+ pageSize: s,
444
+ totalPages: a,
445
+ totalItems: l,
446
+ goToPage: n,
447
+ nextPage: t,
448
+ prevPage: i,
449
+ changePageSize: o,
450
+ hasNextPage: d,
451
+ hasPrevPage: b,
452
+ startIndex: u,
453
+ endIndex: g,
454
+ paginationEnabled: h,
455
+ pageSizeOptions: f,
456
+ showSizeChanger: p,
457
+ locale: N,
458
+ classNames: P
459
+ } = C(), $ = m(
460
+ (c) => {
461
+ o(Number(c.target.value));
462
+ },
463
+ [o]
464
+ ), w = m(
465
+ (c) => {
466
+ if (c.key === "Enter") {
467
+ const v = parseInt(c.target.value, 10);
468
+ !isNaN(v) && v >= 1 && v <= a && n(v);
469
+ }
470
+ },
471
+ [n, a]
472
+ ), S = x(() => {
473
+ const c = [];
474
+ if (a <= 5)
475
+ for (let k = 1; k <= a; k++)
476
+ c.push(k);
477
+ else {
478
+ c.push(1), e > 3 && c.push("ellipsis");
479
+ const k = Math.max(2, e - 1), D = Math.min(a - 1, e + 1);
480
+ for (let A = k; A <= D; A++)
481
+ c.push(A);
482
+ e < a - 2 && c.push("ellipsis"), a > 1 && c.push(a);
483
+ }
484
+ return c;
485
+ }, [e, a]);
486
+ return h ? /* @__PURE__ */ y("div", { className: `bt-pagination ${P.pagination || ""}`, children: [
487
+ /* @__PURE__ */ r("div", { className: "bt-pagination-info", children: l > 0 ? `${u}-${g} ${N.of} ${l} ${N.items}` : `0 ${N.items}` }),
488
+ /* @__PURE__ */ y("div", { className: "bt-pagination-controls", children: [
489
+ p && /* @__PURE__ */ y("div", { className: "bt-page-size", children: [
490
+ /* @__PURE__ */ y("span", { className: "bt-page-size-label", children: [
491
+ N.rowsPerPage,
492
+ ":"
493
+ ] }),
494
+ /* @__PURE__ */ r(
495
+ "select",
496
+ {
497
+ className: "bt-page-size-select",
498
+ value: s,
499
+ onChange: $,
500
+ "aria-label": N.rowsPerPage,
501
+ children: f.map((c) => /* @__PURE__ */ r("option", { value: c, children: c }, c))
502
+ }
503
+ )
504
+ ] }),
505
+ /* @__PURE__ */ r(
506
+ "button",
507
+ {
508
+ className: "bt-pagination-btn",
509
+ onClick: i,
510
+ disabled: !b,
511
+ "aria-label": "Previous page",
512
+ type: "button",
513
+ children: "←"
514
+ }
515
+ ),
516
+ /* @__PURE__ */ r("div", { className: "bt-pagination-pages", children: S.map((c, v) => c === "ellipsis" ? /* @__PURE__ */ r("span", { className: "bt-pagination-ellipsis", children: "..." }, `ellipsis-${v}`) : /* @__PURE__ */ r(
517
+ "button",
518
+ {
519
+ className: `bt-pagination-btn ${e === c ? "bt-active" : ""}`,
520
+ onClick: () => n(c),
521
+ "aria-label": `${N.page} ${c}`,
522
+ "aria-current": e === c ? "page" : void 0,
523
+ type: "button",
524
+ children: c
525
+ },
526
+ c
527
+ )) }),
528
+ /* @__PURE__ */ r(
529
+ "button",
530
+ {
531
+ className: "bt-pagination-btn",
532
+ onClick: t,
533
+ disabled: !d,
534
+ "aria-label": "Next page",
535
+ type: "button",
536
+ children: "→"
537
+ }
538
+ ),
539
+ /* @__PURE__ */ y("div", { className: "bt-quick-jumper", children: [
540
+ /* @__PURE__ */ y("span", { className: "bt-quick-jumper-label", children: [
541
+ N.page,
542
+ ":"
543
+ ] }),
544
+ /* @__PURE__ */ r(
545
+ "input",
546
+ {
547
+ type: "number",
548
+ className: "bt-quick-jumper-input",
549
+ min: 1,
550
+ max: a,
551
+ defaultValue: e,
552
+ onKeyDown: w,
553
+ "aria-label": "Jump to page"
554
+ }
555
+ )
556
+ ] })
557
+ ] })
558
+ ] }) : null;
559
+ }
560
+ function it() {
561
+ const {
562
+ searchable: e,
563
+ searchValue: s,
564
+ handleSearch: a,
565
+ clearSearch: l,
566
+ globalActions: n,
567
+ selectedRows: t,
568
+ selectedCount: i,
569
+ deselectAll: o,
570
+ data: d,
571
+ locale: b,
572
+ classNames: u,
573
+ selectable: g
574
+ } = C(), h = m(
575
+ (p) => {
576
+ a(p.target.value);
577
+ },
578
+ [a]
579
+ );
580
+ return e || n && n.length > 0 || g && i > 0 ? /* @__PURE__ */ y("div", { className: `bt-toolbar ${u.toolbar || ""}`, children: [
581
+ /* @__PURE__ */ y("div", { className: "bt-toolbar-left", children: [
582
+ e && /* @__PURE__ */ y("div", { className: "bt-search", children: [
583
+ /* @__PURE__ */ r("span", { className: "bt-search-icon", children: "🔍" }),
584
+ /* @__PURE__ */ r(
585
+ "input",
586
+ {
587
+ type: "text",
588
+ className: "bt-search-input",
589
+ placeholder: b.searchPlaceholder,
590
+ value: s,
591
+ onChange: h,
592
+ "aria-label": b.search
593
+ }
594
+ ),
595
+ s && /* @__PURE__ */ r(
596
+ "button",
597
+ {
598
+ className: "bt-search-clear",
599
+ onClick: l,
600
+ "aria-label": "Clear search",
601
+ type: "button",
602
+ children: "✕"
603
+ }
604
+ )
605
+ ] }),
606
+ g && i > 0 && /* @__PURE__ */ y("div", { className: "bt-selection-info", children: [
607
+ /* @__PURE__ */ y("span", { children: [
608
+ i,
609
+ " ",
610
+ b.selected
611
+ ] }),
612
+ /* @__PURE__ */ r(
613
+ "button",
614
+ {
615
+ className: "bt-selection-clear",
616
+ onClick: o,
617
+ type: "button",
618
+ children: b.deselectAll
619
+ }
620
+ )
621
+ ] })
622
+ ] }),
623
+ n && n.length > 0 && /* @__PURE__ */ r("div", { className: "bt-toolbar-right", children: /* @__PURE__ */ r("div", { className: "bt-global-actions", children: n.map((p) => {
624
+ const N = p.requiresSelection && t.length === 0;
625
+ return /* @__PURE__ */ y(
626
+ "button",
627
+ {
628
+ className: T(
629
+ "bt-global-btn",
630
+ p.variant && `bt-variant-${p.variant}`
631
+ ),
632
+ onClick: () => p.onClick(t, d),
633
+ disabled: N,
634
+ title: p.label,
635
+ type: "button",
636
+ children: [
637
+ p.icon && /* @__PURE__ */ r("span", { className: "bt-global-icon", children: p.icon }),
638
+ /* @__PURE__ */ r("span", { children: p.label })
639
+ ]
640
+ },
641
+ p.id
642
+ );
643
+ }) }) })
644
+ ] }) : null;
645
+ }
646
+ const rt = it;
647
+ function ct() {
648
+ const { locale: e, emptyComponent: s, columns: a, selectable: l, rowActions: n } = C(), t = a.filter((d) => !d.hidden), i = n && n.length > 0, o = t.length + (l ? 1 : 0) + (i ? 1 : 0);
649
+ return s ? /* @__PURE__ */ r("tbody", { className: "bt-tbody", children: /* @__PURE__ */ r("tr", { className: "bt-tr", children: /* @__PURE__ */ r("td", { className: "bt-td", colSpan: o, children: s }) }) }) : /* @__PURE__ */ r("tbody", { className: "bt-tbody", children: /* @__PURE__ */ r("tr", { className: "bt-tr", children: /* @__PURE__ */ r("td", { className: "bt-td", colSpan: o, children: /* @__PURE__ */ y("div", { className: "bt-empty", children: [
650
+ /* @__PURE__ */ r("div", { className: "bt-empty-icon", children: "📭" }),
651
+ /* @__PURE__ */ r("div", { className: "bt-empty-text", children: e.noData })
652
+ ] }) }) }) });
653
+ }
654
+ function ot({ show: e }) {
655
+ const { loadingComponent: s, locale: a } = C();
656
+ return e ? /* @__PURE__ */ r("div", { className: "bt-loading-overlay", role: "status", "aria-live": "polite", children: s || /* @__PURE__ */ y(He, { children: [
657
+ /* @__PURE__ */ r("div", { className: "bt-loading-spinner", "aria-hidden": "true" }),
658
+ /* @__PURE__ */ r("span", { className: "bt-loading-text", children: a.loading })
659
+ ] }) }) : null;
660
+ }
661
+ function dt() {
662
+ const { isModalOpen: e, modalContent: s, closeModal: a } = C(), l = m(
663
+ (t) => {
664
+ t.target === t.currentTarget && a();
665
+ },
666
+ [a]
667
+ ), n = m(
668
+ (t) => {
669
+ t.key === "Escape" && a();
670
+ },
671
+ [a]
672
+ );
673
+ return Ke(() => (e && (document.addEventListener("keydown", n), document.body.style.overflow = "hidden"), () => {
674
+ document.removeEventListener("keydown", n), document.body.style.overflow = "";
675
+ }), [e, n]), !e || !s ? null : /* @__PURE__ */ r(
676
+ "div",
677
+ {
678
+ className: "bt-modal-backdrop",
679
+ onClick: l,
680
+ role: "dialog",
681
+ "aria-modal": "true",
682
+ children: /* @__PURE__ */ y("div", { className: "bt-modal bt-modal-md", children: [
683
+ /* @__PURE__ */ y("div", { className: "bt-modal-header", children: [
684
+ /* @__PURE__ */ r("h2", { className: "bt-modal-title", children: "Detalles" }),
685
+ /* @__PURE__ */ r(
686
+ "button",
687
+ {
688
+ className: "bt-modal-close",
689
+ onClick: a,
690
+ "aria-label": "Close modal",
691
+ type: "button",
692
+ children: "✕"
693
+ }
694
+ )
695
+ ] }),
696
+ /* @__PURE__ */ r("div", { className: "bt-modal-body", children: s })
697
+ ] })
698
+ }
699
+ );
700
+ }
701
+ function bt({
702
+ data: e,
703
+ initialSort: s,
704
+ controlledSort: a,
705
+ onSortChange: l
706
+ }) {
707
+ const [n, t] = I(
708
+ s ?? { columnId: null, direction: "asc" }
709
+ ), i = a ?? n, o = m(
710
+ (u) => {
711
+ const g = {
712
+ columnId: u,
713
+ direction: i.columnId === u && i.direction === "asc" ? "desc" : "asc"
714
+ };
715
+ a || t(g), l == null || l(g);
716
+ },
717
+ [i, a, l]
718
+ ), d = m(() => {
719
+ const u = { columnId: null, direction: "asc" };
720
+ a || t(u), l == null || l(u);
721
+ }, [a, l]);
722
+ return { sortedData: x(() => i.columnId ? Ue(e, i.columnId, i.direction) : e, [e, i]), sortState: i, handleSort: o, clearSort: d };
723
+ }
724
+ function ut({
725
+ data: e,
726
+ columns: s,
727
+ initialFilters: a,
728
+ controlledFilters: l,
729
+ onFilterChange: n
730
+ }) {
731
+ const [t, i] = I(
732
+ a ?? {}
733
+ ), o = l ?? t, d = m(
734
+ (h, f) => {
735
+ const p = { ...o };
736
+ f == null || f === "" ? delete p[h] : p[h] = f, l || i(p), n == null || n(p);
737
+ },
738
+ [o, l, n]
739
+ ), b = m(
740
+ (h) => {
741
+ const f = { ...o };
742
+ delete f[h], l || i(f), n == null || n(f);
743
+ },
744
+ [o, l, n]
745
+ ), u = m(() => {
746
+ l || i({}), n == null || n({});
747
+ }, [l, n]);
748
+ return { filteredData: x(() => We(e, o, s), [e, o, s]), filters: o, setFilter: d, clearFilters: u, clearFilter: b };
749
+ }
750
+ function ft({
751
+ data: e,
752
+ config: s,
753
+ onPageChange: a
754
+ }) {
755
+ const l = s !== !1, n = s && typeof s == "object" ? s.page ?? 1 : 1, t = s && typeof s == "object" ? s.pageSize ?? 10 : 10, i = s && typeof s == "object" ? s.totalItems : void 0, [o, d] = I(n), [b, u] = I(t), g = i ?? e.length, h = Math.max(1, Math.ceil(g / b)), f = m(
756
+ (c) => {
757
+ const v = Math.max(1, Math.min(c, h));
758
+ d(v), a == null || a(v, b);
759
+ },
760
+ [h, b, a]
761
+ ), p = m(() => {
762
+ o < h && f(o + 1);
763
+ }, [o, h, f]), N = m(() => {
764
+ o > 1 && f(o - 1);
765
+ }, [o, f]), P = m(
766
+ (c) => {
767
+ u(c), d(1), a == null || a(1, c);
768
+ },
769
+ [a]
770
+ ), $ = x(() => {
771
+ if (!l || i !== void 0)
772
+ return e;
773
+ const c = (o - 1) * b;
774
+ return e.slice(c, c + b);
775
+ }, [e, o, b, l, i]), w = (o - 1) * b + 1, S = Math.min(o * b, g);
776
+ return {
777
+ paginatedData: $,
778
+ page: o,
779
+ pageSize: b,
780
+ totalPages: h,
781
+ totalItems: g,
782
+ goToPage: f,
783
+ nextPage: p,
784
+ prevPage: N,
785
+ changePageSize: P,
786
+ hasNextPage: o < h,
787
+ hasPrevPage: o > 1,
788
+ startIndex: w,
789
+ endIndex: S
790
+ };
791
+ }
792
+ function ht({
793
+ data: e,
794
+ rowKey: s,
795
+ mode: a = "multiple",
796
+ initialSelection: l,
797
+ controlledSelection: n,
798
+ onSelectionChange: t
799
+ }) {
800
+ const [i, o] = I(
801
+ l ?? []
802
+ ), d = n ?? i, b = m(
803
+ (c, v) => typeof s == "function" ? s(c, v) : String(c[s]),
804
+ [s]
805
+ ), u = x(() => new Set(d.map((c, v) => b(c, v))), [d, b]), g = m(
806
+ (c, v) => {
807
+ const k = b(c, v);
808
+ return u.has(k);
809
+ },
810
+ [b, u]
811
+ ), h = m(
812
+ (c) => {
813
+ n || o(c), t == null || t(c);
814
+ },
815
+ [n, t]
816
+ ), f = m(
817
+ (c, v) => {
818
+ const k = b(c, v);
819
+ let D;
820
+ a === "single" ? D = u.has(k) ? [] : [c] : u.has(k) ? D = d.filter((A, M) => b(A, M) !== k) : D = [...d, c], h(D);
821
+ },
822
+ [a, u, d, b, h]
823
+ ), p = m(
824
+ (c, v) => {
825
+ if (!g(c, v)) {
826
+ const k = a === "single" ? [c] : [...d, c];
827
+ h(k);
828
+ }
829
+ },
830
+ [g, a, d, h]
831
+ ), N = m(
832
+ (c, v) => {
833
+ const k = b(c, v), D = d.filter(
834
+ (A, M) => b(A, M) !== k
835
+ );
836
+ h(D);
837
+ },
838
+ [d, b, h]
839
+ ), P = m(() => {
840
+ a === "multiple" && h([...e]);
841
+ }, [e, a, h]), $ = m(() => {
842
+ h([]);
843
+ }, [h]), w = e.length > 0 && d.length === e.length, S = d.length > 0 && d.length < e.length;
844
+ return {
845
+ selectedRows: d,
846
+ isSelected: g,
847
+ toggleRow: f,
848
+ selectRow: p,
849
+ deselectRow: N,
850
+ selectAll: P,
851
+ deselectAll: $,
852
+ isAllSelected: w,
853
+ isPartiallySelected: S,
854
+ selectedCount: d.length
855
+ };
856
+ }
857
+ function pt({
858
+ data: e,
859
+ columns: s,
860
+ searchColumns: a,
861
+ initialValue: l,
862
+ controlledValue: n,
863
+ onSearchChange: t
864
+ }) {
865
+ const [i, o] = I(l ?? ""), d = n ?? i, b = m(
866
+ (h) => {
867
+ n === void 0 && o(h), t == null || t(h);
868
+ },
869
+ [n, t]
870
+ ), u = m(() => {
871
+ n === void 0 && o(""), t == null || t("");
872
+ }, [n, t]);
873
+ return { searchedData: x(() => Xe(e, d, s, a), [e, d, s, a]), searchValue: d, handleSearch: b, clearSearch: u };
874
+ }
875
+ function mt(e) {
876
+ const {
877
+ // Data
878
+ data: s,
879
+ columns: a,
880
+ rowKey: l = "id",
881
+ // Actions
882
+ rowActions: n,
883
+ globalActions: t,
884
+ // Pagination
885
+ pagination: i = { pageSize: 10 },
886
+ onPageChange: o,
887
+ // Sort
888
+ sort: d,
889
+ onSortChange: b,
890
+ // Filter
891
+ filters: u,
892
+ onFilterChange: g,
893
+ // Search
894
+ searchable: h = !1,
895
+ searchValue: f,
896
+ onSearchChange: p,
897
+ searchColumns: N,
898
+ // Selection - now auto-inferred if not explicitly set
899
+ selectable: P,
900
+ selectedRows: $,
901
+ onSelectionChange: w,
902
+ selectionMode: S = "multiple",
903
+ // States
904
+ loading: c = !1,
905
+ loadingComponent: v,
906
+ emptyComponent: k,
907
+ // Styling
908
+ classNames: D = {},
909
+ styles: A = {},
910
+ locale: M,
911
+ stickyHeader: O = !1,
912
+ maxHeight: ze,
913
+ bordered: L = !1,
914
+ striped: K = !1,
915
+ hoverable: H = !0,
916
+ size: j = "medium",
917
+ // Callbacks
918
+ onRowClick: V,
919
+ onRowDoubleClick: q,
920
+ // Accessibility
921
+ ariaLabel: Ie,
922
+ ariaDescribedBy: Me
923
+ } = e, J = x(() => P !== void 0 ? P : (t == null ? void 0 : t.some(
924
+ (je) => je.requiresSelection
925
+ )) || w !== void 0, [P, t, w]), _ = x(
926
+ () => ({ ...Ve, ...M }),
927
+ [M]
928
+ ), [Q, G] = I(!1), [U, W] = I(null), X = m((xe) => {
929
+ W(xe), G(!0);
930
+ }, []), Y = m(() => {
931
+ G(!1), W(null);
932
+ }, []), z = x(() => i === !1 ? !1 : {
933
+ pageSize: 10,
934
+ pageSizeOptions: [10, 20, 50, 100],
935
+ showSizeChanger: !1,
936
+ ...i
937
+ }, [i]), {
938
+ searchedData: Re,
939
+ searchValue: Z,
940
+ handleSearch: F,
941
+ clearSearch: ee
942
+ } = pt({
943
+ data: s,
944
+ columns: a,
945
+ searchColumns: N,
946
+ controlledValue: f,
947
+ onSearchChange: p
948
+ }), {
949
+ filteredData: Be,
950
+ filters: te,
951
+ setFilter: ae,
952
+ clearFilters: le
953
+ } = ut({
954
+ data: Re,
955
+ columns: a,
956
+ controlledFilters: u,
957
+ onFilterChange: g
958
+ }), { sortedData: se, sortState: ne, handleSort: ie } = bt({
959
+ data: Be,
960
+ controlledSort: d,
961
+ onSortChange: b
962
+ }), {
963
+ selectedRows: re,
964
+ isSelected: ce,
965
+ toggleRow: oe,
966
+ selectAll: de,
967
+ deselectAll: be,
968
+ isAllSelected: ue,
969
+ isPartiallySelected: fe,
970
+ selectedCount: he
971
+ } = ht({
972
+ data: se,
973
+ rowKey: l,
974
+ mode: S,
975
+ controlledSelection: $,
976
+ onSelectionChange: w
977
+ }), {
978
+ paginatedData: E,
979
+ page: pe,
980
+ pageSize: me,
981
+ totalPages: ge,
982
+ totalItems: ve,
983
+ goToPage: ye,
984
+ nextPage: Ne,
985
+ prevPage: Se,
986
+ changePageSize: ke,
987
+ hasNextPage: De,
988
+ hasPrevPage: Te,
989
+ startIndex: Pe,
990
+ endIndex: we
991
+ } = ft({
992
+ data: se,
993
+ config: z,
994
+ onPageChange: o
995
+ }), Le = x(
996
+ () => ({
997
+ // Data
998
+ data: s,
999
+ processedData: E,
1000
+ columns: a,
1001
+ rowKey: l,
1002
+ // Actions
1003
+ rowActions: n,
1004
+ globalActions: t,
1005
+ // Sort
1006
+ sortState: ne,
1007
+ handleSort: ie,
1008
+ // Filter
1009
+ filters: te,
1010
+ setFilter: ae,
1011
+ clearFilters: le,
1012
+ // Search
1013
+ searchValue: Z,
1014
+ handleSearch: F,
1015
+ clearSearch: ee,
1016
+ searchable: h,
1017
+ // Selection
1018
+ selectedRows: re,
1019
+ isSelected: ce,
1020
+ toggleRow: oe,
1021
+ selectAll: de,
1022
+ deselectAll: be,
1023
+ isAllSelected: ue,
1024
+ isPartiallySelected: fe,
1025
+ selectable: J,
1026
+ selectionMode: S,
1027
+ selectedCount: he,
1028
+ // Pagination
1029
+ page: pe,
1030
+ pageSize: me,
1031
+ totalPages: ge,
1032
+ totalItems: ve,
1033
+ goToPage: ye,
1034
+ nextPage: Ne,
1035
+ prevPage: Se,
1036
+ changePageSize: ke,
1037
+ hasNextPage: De,
1038
+ hasPrevPage: Te,
1039
+ startIndex: Pe,
1040
+ endIndex: we,
1041
+ paginationEnabled: i !== !1,
1042
+ pageSizeOptions: z && typeof z == "object" ? z.pageSizeOptions ?? [10, 20, 50, 100] : [10, 20, 50, 100],
1043
+ showSizeChanger: z && typeof z == "object" ? z.showSizeChanger ?? !1 : !1,
1044
+ // UI State
1045
+ loading: c,
1046
+ loadingComponent: v,
1047
+ emptyComponent: k,
1048
+ // Styling
1049
+ locale: _,
1050
+ classNames: D,
1051
+ size: j,
1052
+ bordered: L,
1053
+ striped: K,
1054
+ hoverable: H,
1055
+ stickyHeader: O,
1056
+ // Callbacks
1057
+ onRowClick: V,
1058
+ onRowDoubleClick: q,
1059
+ // Modal
1060
+ openModal: X,
1061
+ closeModal: Y,
1062
+ modalContent: U,
1063
+ isModalOpen: Q
1064
+ }),
1065
+ [
1066
+ s,
1067
+ E,
1068
+ a,
1069
+ l,
1070
+ n,
1071
+ t,
1072
+ ne,
1073
+ ie,
1074
+ te,
1075
+ ae,
1076
+ le,
1077
+ Z,
1078
+ F,
1079
+ ee,
1080
+ h,
1081
+ re,
1082
+ ce,
1083
+ oe,
1084
+ de,
1085
+ be,
1086
+ ue,
1087
+ fe,
1088
+ J,
1089
+ S,
1090
+ he,
1091
+ pe,
1092
+ me,
1093
+ ge,
1094
+ ve,
1095
+ ye,
1096
+ Ne,
1097
+ Se,
1098
+ ke,
1099
+ De,
1100
+ Te,
1101
+ Pe,
1102
+ we,
1103
+ i,
1104
+ z,
1105
+ c,
1106
+ v,
1107
+ k,
1108
+ _,
1109
+ D,
1110
+ j,
1111
+ L,
1112
+ K,
1113
+ H,
1114
+ O,
1115
+ V,
1116
+ q,
1117
+ X,
1118
+ Y,
1119
+ U,
1120
+ Q
1121
+ ]
1122
+ ), Ae = E.length > 0;
1123
+ return /* @__PURE__ */ r(qe, { value: Le, children: /* @__PURE__ */ y(
1124
+ "div",
1125
+ {
1126
+ className: T(
1127
+ "bt-container",
1128
+ `bt-size-${j}`,
1129
+ c && "bt-container-loading",
1130
+ D.container
1131
+ ),
1132
+ style: A.container,
1133
+ children: [
1134
+ /* @__PURE__ */ r(rt, {}),
1135
+ /* @__PURE__ */ y(
1136
+ "div",
1137
+ {
1138
+ className: T("bt-table-wrapper", L && "bt-bordered"),
1139
+ style: { maxHeight: ze },
1140
+ children: [
1141
+ /* @__PURE__ */ y(
1142
+ "table",
1143
+ {
1144
+ className: T("bt-table", D.table),
1145
+ style: A.table,
1146
+ role: "grid",
1147
+ "aria-label": Ie,
1148
+ "aria-describedby": Me,
1149
+ "aria-busy": c,
1150
+ children: [
1151
+ /* @__PURE__ */ r(Ge, {}),
1152
+ Ae ? /* @__PURE__ */ r(st, {}) : /* @__PURE__ */ r(ct, {})
1153
+ ]
1154
+ }
1155
+ ),
1156
+ /* @__PURE__ */ r(ot, { show: c && Ae })
1157
+ ]
1158
+ }
1159
+ ),
1160
+ i !== !1 && /* @__PURE__ */ r(nt, {}),
1161
+ /* @__PURE__ */ r(dt, {})
1162
+ ]
1163
+ }
1164
+ ) });
1165
+ }
1166
+ const St = mt;
1167
+ export {
1168
+ St as BetterTable,
1169
+ qe as TableProvider,
1170
+ Ve as defaultLocale,
1171
+ We as filterData,
1172
+ R as getValueFromPath,
1173
+ Xe as searchData,
1174
+ Ue as sortData,
1175
+ C as useTableContext,
1176
+ ut as useTableFilter,
1177
+ ft as useTablePagination,
1178
+ pt as useTableSearch,
1179
+ ht as useTableSelection,
1180
+ bt as useTableSort
1181
+ };
1182
+ //# sourceMappingURL=better-table.es.js.map