@krosoft/react 0.0.228 → 0.0.230

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 (32) hide show
  1. package/dist/DataTable-DYp_uFEn.js +638 -0
  2. package/dist/{SearchInput-Y-iBtCCc.js → SearchInput-Dkvaei9K.js} +38 -38
  3. package/dist/{TableFilter-CJrFjUod.js → TableFilter-BXD7Es8j.js} +1 -1
  4. package/dist/components/core/filters/index.js +1 -1
  5. package/dist/components/core/index.js +67 -62
  6. package/dist/components/core/inputs/index.js +1 -1
  7. package/dist/components/core/table/DataTable.d.ts +2 -1
  8. package/dist/components/core/table/DataTable.d.ts.map +1 -1
  9. package/dist/components/core/table/TableBody.d.ts +3 -1
  10. package/dist/components/core/table/TableBody.d.ts.map +1 -1
  11. package/dist/components/core/table/TableHeader.d.ts +5 -1
  12. package/dist/components/core/table/TableHeader.d.ts.map +1 -1
  13. package/dist/components/core/table/columnAlignment.d.ts +13 -0
  14. package/dist/components/core/table/columnAlignment.d.ts.map +1 -0
  15. package/dist/components/core/table/fixedColumns.d.ts +19 -0
  16. package/dist/components/core/table/fixedColumns.d.ts.map +1 -0
  17. package/dist/components/core/table/index.d.ts +2 -0
  18. package/dist/components/core/table/index.d.ts.map +1 -1
  19. package/dist/components/core/table/index.js +13 -8
  20. package/dist/components/index.js +189 -184
  21. package/dist/hooks/index.js +11 -10
  22. package/dist/hooks/ui/index.d.ts +2 -0
  23. package/dist/hooks/ui/index.d.ts.map +1 -1
  24. package/dist/hooks/ui/index.js +16 -15
  25. package/dist/hooks/ui/useFixedColumns.d.ts +23 -0
  26. package/dist/hooks/ui/useFixedColumns.d.ts.map +1 -0
  27. package/dist/types/ColumnDef.d.ts +2 -0
  28. package/dist/types/ColumnDef.d.ts.map +1 -1
  29. package/dist/useFixedColumns-CKZyu4PD.js +161 -0
  30. package/package.json +1 -1
  31. package/dist/DataTable-DSrsTb_t.js +0 -553
  32. package/dist/useDataTable-CxcA5S-s.js +0 -126
@@ -1,553 +0,0 @@
1
- import { jsxs as n, jsx as e, Fragment as le } from "react/jsx-runtime";
2
- import { u as de } from "./useDataTable-CxcA5S-s.js";
3
- import "date-fns/locale";
4
- import "react-i18next";
5
- import { u as B } from "./useKrosoftTranslation-DtdbUewZ.js";
6
- import { a3 as L, ah as V, a5 as O, a7 as ce, E as H, a4 as oe } from "./toggle-group-DLLrEwv2.js";
7
- import "./alert-B9F1N9Qk.js";
8
- import "@radix-ui/react-aspect-ratio";
9
- import { B as b } from "./tooltip-DVeqVwqV.js";
10
- import "./chart-DntJZGxB.js";
11
- import "@radix-ui/react-collapsible";
12
- import "./sheet-tuC_C3M3.js";
13
- import { MoreVerticalIcon as he, Loader2Icon as me, AlertTriangleIcon as ge, GripVerticalIcon as ue, ArrowUpIcon as fe, ArrowDownIcon as pe, ArrowUpDownIcon as xe, ChevronLeftIcon as ve, ChevronRightIcon as ye, SettingsIcon as be } from "lucide-react";
14
- import "react-resizable-panels";
15
- import "clsx";
16
- import "tailwind-merge";
17
- import { S as Ne, h as ke, i as Se, a as we, c as ze } from "./select-BpjFWqAY.js";
18
- import "next-themes";
19
- import "sonner";
20
- import "react";
21
- const R = [5, 10, 30, 50, 100], Ce = R[1];
22
- function De({ actions: l, row: a }) {
23
- const s = l.filter((r) => r.visible === void 0 || r.visible(a));
24
- if (s.length === 0)
25
- return null;
26
- const d = s.filter((r) => r.overflow !== !0), m = s.filter((r) => r.overflow === !0);
27
- return /* @__PURE__ */ n("div", { className: "flex items-center justify-center gap-1", children: [
28
- d.map((r, c) => {
29
- var o;
30
- const h = r.icon;
31
- return /* @__PURE__ */ n(
32
- b,
33
- {
34
- variant: r.variant ?? "ghost",
35
- size: "sm",
36
- disabled: ((o = r.disabled) == null ? void 0 : o.call(r, a)) ?? !1,
37
- className: `h-7 px-2 text-muted-foreground hover:text-foreground ${r.className ?? ""}`,
38
- onClick: (f) => {
39
- f.stopPropagation(), r.onClick(a);
40
- },
41
- children: [
42
- h !== void 0 && /* @__PURE__ */ e(h, { className: "size-3.5" }),
43
- r.label
44
- ]
45
- },
46
- c
47
- );
48
- }),
49
- m.length > 0 && /* @__PURE__ */ n(L, { children: [
50
- /* @__PURE__ */ e(V, { asChild: !0, children: /* @__PURE__ */ e(b, { variant: "ghost", size: "icon", className: "h-7 w-7 text-muted-foreground hover:text-foreground", children: /* @__PURE__ */ e(he, { className: "size-3.5" }) }) }),
51
- /* @__PURE__ */ e(
52
- O,
53
- {
54
- align: "end",
55
- onClick: (r) => {
56
- r.stopPropagation();
57
- },
58
- children: m.map((r, c) => {
59
- var o;
60
- const h = r.icon;
61
- return /* @__PURE__ */ n(
62
- ce,
63
- {
64
- disabled: ((o = r.disabled) == null ? void 0 : o.call(r, a)) ?? !1,
65
- onClick: () => {
66
- r.onClick(a);
67
- },
68
- className: r.className,
69
- children: [
70
- h !== void 0 && /* @__PURE__ */ e("span", { className: "mr-2 size-4 flex items-center justify-center", children: /* @__PURE__ */ e(h, { className: "size-4" }) }),
71
- r.label
72
- ]
73
- },
74
- c
75
- );
76
- })
77
- }
78
- )
79
- ] })
80
- ] });
81
- }
82
- function Ie({
83
- isLoading: l,
84
- error: a,
85
- colSpanCount: s,
86
- noDataMessage: d,
87
- paginatedData: m,
88
- getRowId: r,
89
- onRowClick: c,
90
- hasBulkActions: h,
91
- selectedRows: o,
92
- toggleRowSelection: f,
93
- visibleColumnsArray: y,
94
- columnWidths: i,
95
- hasActions: N,
96
- actions: k,
97
- columns: I,
98
- bordered: w = !1,
99
- resizableColumns: z = !1
100
- }) {
101
- const { t: C } = B(), S = (u, p) => {
102
- const t = I.find((v) => v.key === p);
103
- if ((t == null ? void 0 : t.renderCell) !== void 0)
104
- return t.renderCell(u);
105
- const x = u[p];
106
- return /* @__PURE__ */ e("span", { className: "text-sm truncate", children: x != null ? String(x) : "-" });
107
- };
108
- return l ? /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: s, className: "py-8 text-center", children: /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center gap-2 text-muted-foreground", children: [
109
- /* @__PURE__ */ e(me, { className: "h-6 w-6 animate-spin text-primary" }),
110
- /* @__PURE__ */ e("span", { className: "text-sm", children: C("states.loading") })
111
- ] }) }) }) }) : a ? /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: s, className: "py-8 text-center", children: /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center gap-2 text-destructive", children: [
112
- /* @__PURE__ */ e(ge, { className: "h-6 w-6" }),
113
- /* @__PURE__ */ e("span", { className: "text-sm", children: a })
114
- ] }) }) }) }) : m.length === 0 ? /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: s, className: "py-8 text-center text-sm text-muted-foreground", children: d ?? C("states.noResult") }) }) }) : /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: m.map((u) => {
115
- const p = r(u);
116
- return /* @__PURE__ */ n(
117
- "tr",
118
- {
119
- className: `group hover:bg-muted/50 dark:hover:bg-gray-900/50 transition-colors ${c !== void 0 ? "cursor-pointer" : ""}`,
120
- onClick: (t) => c == null ? void 0 : c(u, t),
121
- children: [
122
- h ? /* @__PURE__ */ e(
123
- "td",
124
- {
125
- className: "p-1 text-center align-middle",
126
- style: { width: "32px", minWidth: "32px", maxWidth: "32px" },
127
- onClick: (t) => {
128
- t.stopPropagation();
129
- },
130
- children: /* @__PURE__ */ e("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ e(
131
- H,
132
- {
133
- checked: o.includes(p),
134
- onCheckedChange: () => {
135
- f(p);
136
- }
137
- }
138
- ) })
139
- }
140
- ) : null,
141
- y.map((t, x) => {
142
- const v = x === y.length - 1;
143
- return /* @__PURE__ */ e(
144
- "td",
145
- {
146
- className: `px-2 py-2 relative ${w && !v ? "border-r border-gray-100 dark:border-gray-800" : ""} ${t.className ?? ""}`,
147
- style: z ? { width: i[t.key] } : { minWidth: i[t.key] },
148
- children: /* @__PURE__ */ e("div", { className: "w-full h-full", children: S(u, t.key) })
149
- },
150
- t.key
151
- );
152
- }),
153
- N ? /* @__PURE__ */ e(
154
- "td",
155
- {
156
- className: "p-1 text-center align-middle whitespace-nowrap",
157
- style: { minWidth: "32px" },
158
- onClick: (t) => {
159
- t.stopPropagation();
160
- },
161
- children: k !== void 0 && k.length > 0 ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ e(De, { actions: k, row: u }) }) : null
162
- }
163
- ) : null
164
- ]
165
- },
166
- p
167
- );
168
- }) });
169
- }
170
- function je({ selectedRows: l, setSelectedRows: a, bulkActions: s }) {
171
- return /* @__PURE__ */ n("div", { className: "bg-muted/60 dark:bg-gray-900/60 border border-border px-3 py-1.5 flex items-center justify-between rounded-surface", children: [
172
- /* @__PURE__ */ n("div", { className: "flex items-center gap-4", children: [
173
- /* @__PURE__ */ n("span", { className: "text-sm font-medium text-primary ml-1", children: [
174
- l.length,
175
- " sélectionné(s)"
176
- ] }),
177
- /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: s.map((d, m) => {
178
- const r = d.icon;
179
- return /* @__PURE__ */ n(
180
- b,
181
- {
182
- variant: "outline",
183
- size: "sm",
184
- onClick: () => {
185
- d.onClick(l, () => {
186
- a([]);
187
- });
188
- },
189
- className: `h-7 bg-background shadow-sm text-xs px-2.5 ${d.variant === "destructive" ? "text-destructive border-destructive/30 hover:bg-destructive/10 hover:text-destructive" : "text-foreground"}`,
190
- children: [
191
- r !== void 0 && /* @__PURE__ */ e("span", { className: "mr-1.5 flex items-center justify-center", children: /* @__PURE__ */ e(r, { className: "h-3.5 w-3.5" }) }),
192
- d.label
193
- ]
194
- },
195
- m
196
- );
197
- }) })
198
- ] }),
199
- /* @__PURE__ */ e(
200
- b,
201
- {
202
- variant: "ghost",
203
- size: "sm",
204
- onClick: () => {
205
- a([]);
206
- },
207
- className: "text-xs text-muted-foreground hover:text-foreground h-7 px-2",
208
- children: "Désélectionner"
209
- }
210
- )
211
- ] });
212
- }
213
- function Te({
214
- hasBulkActions: l,
215
- selectedRows: a,
216
- totalItems: s,
217
- toggleSelectAll: d,
218
- visibleColumnsArray: m,
219
- draggableColumns: r,
220
- resizableColumns: c,
221
- columnWidths: h,
222
- sortColumn: o,
223
- sortDirection: f,
224
- handleSort: y,
225
- handleDragStart: i,
226
- handleDragOver: N,
227
- handleDrop: k,
228
- handleMouseDown: I,
229
- hasActions: w,
230
- settingsNode: z,
231
- bordered: C = !1
232
- }) {
233
- let S = !1;
234
- a.length === s && s > 0 ? S = !0 : a.length > 0 && (S = "indeterminate");
235
- const u = (t) => t.sortable !== !0 ? null : o === t.key ? f === "asc" ? /* @__PURE__ */ e(fe, { className: "size-3.5 text-foreground" }) : /* @__PURE__ */ e(pe, { className: "size-3.5 text-foreground" }) : /* @__PURE__ */ e(xe, { className: "size-3.5 text-muted-foreground/50 group-hover:text-muted-foreground transition-colors" }), p = (t, x) => {
236
- const v = x !== !1, T = t.sortable === !0;
237
- return /* @__PURE__ */ n(
238
- "th",
239
- {
240
- className: [
241
- "px-2 py-2 text-left text-sm font-medium text-gray-900 dark:text-gray-100 relative group",
242
- C ? "border-r border-gray-200 dark:border-gray-800" : "",
243
- T ? "cursor-pointer select-none" : "",
244
- t.className ?? ""
245
- ].filter(Boolean).join(" "),
246
- style: c ? { width: h[t.key] } : { minWidth: h[t.key] },
247
- draggable: v,
248
- onClick: () => {
249
- y(t.key);
250
- },
251
- onDragStart: (g) => {
252
- v ? i(g, t.key) : g.preventDefault();
253
- },
254
- onDragOver: (g) => {
255
- N(g, t.key);
256
- },
257
- onDrop: (g) => {
258
- k(g, t.key);
259
- },
260
- children: [
261
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between pr-2", children: [
262
- /* @__PURE__ */ n("div", { className: "flex items-center gap-1", children: [
263
- v ? /* @__PURE__ */ e(ue, { className: "size-4 text-gray-400 cursor-grab dark:text-gray-300 shrink-0" }) : null,
264
- /* @__PURE__ */ e("span", { className: "truncate", children: t.label })
265
- ] }),
266
- /* @__PURE__ */ e("div", { className: "ml-1 shrink-0", children: u(t) })
267
- ] }),
268
- c ? /* @__PURE__ */ e(
269
- "div",
270
- {
271
- className: "absolute right-0 top-0 bottom-0 w-2 cursor-col-resize hover:bg-blue-500 opacity-0 group-hover:opacity-50 transition-opacity",
272
- onMouseDown: (g) => {
273
- I(g, t.key);
274
- }
275
- }
276
- ) : null
277
- ]
278
- },
279
- t.key
280
- );
281
- };
282
- return /* @__PURE__ */ e("thead", { className: "bg-muted/50 dark:bg-gray-900/50 border-b border-gray-200 dark:border-gray-800", children: /* @__PURE__ */ n("tr", { children: [
283
- l ? /* @__PURE__ */ e("th", { className: "p-1 flex-shrink-0 text-center align-middle", style: { width: "32px", minWidth: "32px", maxWidth: "32px" }, children: /* @__PURE__ */ e("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ e(H, { checked: S, onCheckedChange: d }) }) }) : null,
284
- m.map((t) => p(t, r)),
285
- w || z !== void 0 ? /* @__PURE__ */ e("th", { className: "p-1 text-center align-middle", style: { minWidth: "32px" }, children: z }) : null
286
- ] }) });
287
- }
288
- const D = "…";
289
- function j(l, a) {
290
- return Array.from({ length: a - l + 1 }, (s, d) => l + d);
291
- }
292
- function Me(l, a, s = 1) {
293
- if (s * 2 + 5 >= a)
294
- return j(1, a);
295
- const m = Math.max(l - s, 1), r = Math.min(l + s, a), c = m > 2, h = r < a - 1;
296
- if (!c && h)
297
- return [...j(1, s + 2), D, a];
298
- if (c && !h) {
299
- const o = j(a - (s + 2) + 1, a);
300
- return [1, D, ...o];
301
- }
302
- return [1, D, ...j(m, r), D, a];
303
- }
304
- function Ae({
305
- totalItems: l,
306
- startIndex: a,
307
- endIndex: s,
308
- pageSize: d,
309
- setPageSize: m,
310
- currentPage: r,
311
- setCurrentPage: c,
312
- pageSizeOptions: h,
313
- totalPages: o
314
- }) {
315
- const { t: f } = B(), y = Me(r, o);
316
- return /* @__PURE__ */ n("div", { className: "px-4 py-2 border-t border-gray-200 dark:border-gray-800 flex flex-col sm:grid sm:grid-cols-3 items-center gap-2 bg-muted/50 dark:bg-gray-900/50", children: [
317
- /* @__PURE__ */ n("div", { className: "text-sm text-muted-foreground justify-self-start", children: [
318
- l === 0 ? "0" : `${String(a + 1)} - ${String(s)}`,
319
- " sur ",
320
- l
321
- ] }),
322
- /* @__PURE__ */ e("div", { className: "flex items-center justify-center gap-1", children: o > 1 && /* @__PURE__ */ n(le, { children: [
323
- /* @__PURE__ */ e(
324
- b,
325
- {
326
- variant: "ghost",
327
- size: "icon",
328
- className: "h-8 w-8 rounded-control",
329
- onClick: () => {
330
- c((i) => Math.max(1, i - 1));
331
- },
332
- disabled: r === 1,
333
- "aria-label": f("table.previousPage"),
334
- children: /* @__PURE__ */ e(ve, { className: "size-4" })
335
- }
336
- ),
337
- y.map(
338
- (i, N) => i === D ? /* @__PURE__ */ e("span", { className: "flex h-8 w-8 items-center justify-center text-sm text-muted-foreground", children: D }, `dots-${String(N)}`) : /* @__PURE__ */ e(
339
- b,
340
- {
341
- variant: i === r ? "default" : "ghost",
342
- size: "icon",
343
- className: "h-8 w-8 rounded-control text-sm",
344
- onClick: () => {
345
- c(i);
346
- },
347
- "aria-current": i === r ? "page" : void 0,
348
- children: i
349
- },
350
- i
351
- )
352
- ),
353
- /* @__PURE__ */ e(
354
- b,
355
- {
356
- variant: "ghost",
357
- size: "icon",
358
- className: "h-8 w-8 rounded-control",
359
- onClick: () => {
360
- c((i) => Math.min(o, i + 1));
361
- },
362
- disabled: r === o,
363
- "aria-label": f("table.nextPage"),
364
- children: /* @__PURE__ */ e(ye, { className: "size-4" })
365
- }
366
- )
367
- ] }) }),
368
- /* @__PURE__ */ e("div", { className: "justify-self-end", children: /* @__PURE__ */ n(
369
- Ne,
370
- {
371
- value: String(d),
372
- onValueChange: (i) => {
373
- m(Number(i)), c(1);
374
- },
375
- children: [
376
- /* @__PURE__ */ e(ke, { className: "h-8 w-[110px] text-sm", children: /* @__PURE__ */ e(Se, {}) }),
377
- /* @__PURE__ */ e(we, { children: h.map((i) => /* @__PURE__ */ n(ze, { value: String(i), children: [
378
- i,
379
- " / page"
380
- ] }, i)) })
381
- ]
382
- }
383
- ) })
384
- ] });
385
- }
386
- function $e({ columns: l, visibleColumns: a, toggleColumnVisibility: s }) {
387
- return /* @__PURE__ */ n(L, { children: [
388
- /* @__PURE__ */ e(V, { asChild: !0, children: /* @__PURE__ */ e(b, { variant: "outline", size: "sm", className: "size-7 p-0 bg-white hover:bg-gray-100 dark:bg-gray-900 shadow-sm border-gray-200 dark:border-gray-800", children: /* @__PURE__ */ e(be, { className: "size-3.5 text-gray-600 dark:text-gray-300" }) }) }),
389
- /* @__PURE__ */ e(O, { align: "end", className: "w-56", children: l.map((d) => /* @__PURE__ */ e(
390
- oe,
391
- {
392
- checked: a.has(d.key),
393
- onCheckedChange: () => {
394
- s(d.key);
395
- },
396
- children: d.label
397
- },
398
- d.key
399
- )) })
400
- ] });
401
- }
402
- function er({
403
- data: l,
404
- columns: a,
405
- getRowId: s,
406
- onRowClick: d,
407
- actions: m,
408
- bulkActions: r,
409
- draggableColumns: c = !1,
410
- resizableColumns: h = !1,
411
- columnVisibility: o = !1,
412
- isLoading: f = !1,
413
- error: y = null,
414
- bordered: i = !1,
415
- noDataMessage: N,
416
- defaultPageSize: k = Ce,
417
- pageSizeOptions: I = R,
418
- totalRows: w,
419
- currentPage: z,
420
- pageSize: C,
421
- onPageChange: S,
422
- onPageSizeChange: u,
423
- sortColumn: p,
424
- sortDirection: t,
425
- onSortChange: x
426
- }) {
427
- const {
428
- sortColumn: v,
429
- sortDirection: T,
430
- selectedRows: g,
431
- setSelectedRows: U,
432
- visibleColumns: E,
433
- columnWidths: M,
434
- safeCurrentPage: F,
435
- totalPages: G,
436
- startIndex: _,
437
- endIndex: q,
438
- tableRef: J,
439
- hasActions: A,
440
- hasBulkActions: $,
441
- visibleColumnsArray: W,
442
- colSpanCount: K,
443
- paginatedData: P,
444
- handleSort: Q,
445
- handleMouseDown: X,
446
- handleDragStart: Y,
447
- handleDragOver: Z,
448
- handleDrop: ee,
449
- toggleColumnVisibility: re,
450
- toggleRowSelection: te,
451
- toggleSelectAll: ae,
452
- pageSize: se,
453
- setPageSize: ie,
454
- setCurrentPage: ne
455
- } = de({
456
- data: l,
457
- columns: a,
458
- getRowId: s,
459
- defaultPageSize: k,
460
- actions: m,
461
- bulkActions: r,
462
- columnVisibility: o,
463
- totalRows: w,
464
- currentPage: z,
465
- pageSize: C,
466
- onPageChange: S,
467
- onPageSizeChange: u,
468
- sortColumn: p,
469
- sortDirection: t,
470
- onSortChange: x
471
- });
472
- return (
473
- // Le tableau suit le preset de l'application — square reste square — mais
474
- // bascule sur les valeurs plafonnées : ni ses contrôles ni son cadre ne
475
- // prennent la forme capsule. Le scope couvre le cadre, les actions
476
- // groupées et la pagination. Les fallbacks correspondent au preset "soft".
477
- /* @__PURE__ */ n("div", { className: "space-y-4 [--k-radius-control:var(--k-radius-control-dense,0.5rem)] [--k-radius-surface:var(--k-radius-surface-dense,0.75rem)]", children: [
478
- g.length > 0 && r !== void 0 && r.length > 0 && /* @__PURE__ */ e(je, { selectedRows: g, setSelectedRows: U, bulkActions: r }),
479
- /* @__PURE__ */ n("div", { className: "w-full bg-card dark:bg-gray-950 rounded-surface border border-gray-200 dark:border-gray-800 overflow-hidden", children: [
480
- /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ n("table", { ref: J, className: "w-full", children: [
481
- /* @__PURE__ */ e(
482
- Te,
483
- {
484
- hasBulkActions: $,
485
- selectedRows: g,
486
- totalItems: l.length,
487
- toggleSelectAll: ae,
488
- visibleColumnsArray: W,
489
- draggableColumns: c,
490
- resizableColumns: h,
491
- columnWidths: M,
492
- sortColumn: v,
493
- sortDirection: T,
494
- handleSort: Q,
495
- handleDragStart: Y,
496
- handleDragOver: Z,
497
- handleDrop: ee,
498
- handleMouseDown: X,
499
- hasActions: A,
500
- bordered: i,
501
- settingsNode: o ? /* @__PURE__ */ e($e, { columns: a, visibleColumns: E, toggleColumnVisibility: re }) : void 0
502
- }
503
- ),
504
- /* @__PURE__ */ e(
505
- Ie,
506
- {
507
- bordered: i,
508
- isLoading: f,
509
- error: y,
510
- colSpanCount: K,
511
- noDataMessage: N,
512
- paginatedData: P,
513
- getRowId: s,
514
- onRowClick: d,
515
- hasBulkActions: $,
516
- selectedRows: g,
517
- toggleRowSelection: te,
518
- visibleColumnsArray: W,
519
- columnWidths: M,
520
- hasActions: A || o,
521
- actions: m,
522
- columns: a,
523
- resizableColumns: h
524
- }
525
- )
526
- ] }) }),
527
- /* @__PURE__ */ e(
528
- Ae,
529
- {
530
- totalItems: w ?? l.length,
531
- startIndex: _,
532
- endIndex: q,
533
- pageSize: se,
534
- setPageSize: ie,
535
- currentPage: F,
536
- setCurrentPage: ne,
537
- pageSizeOptions: I,
538
- totalPages: G
539
- }
540
- )
541
- ] })
542
- ] })
543
- );
544
- }
545
- export {
546
- er as D,
547
- De as T,
548
- Ie as a,
549
- je as b,
550
- Te as c,
551
- Ae as d,
552
- $e as e
553
- };
@@ -1,126 +0,0 @@
1
- import { useState as c, useRef as g, useMemo as M, useCallback as u } from "react";
2
- function Ve({
3
- data: l,
4
- columns: o,
5
- getRowId: Y,
6
- defaultPageSize: Z,
7
- actions: E,
8
- bulkActions: I,
9
- columnVisibility: _ = !0,
10
- totalRows: p,
11
- currentPage: $,
12
- pageSize: K,
13
- onPageChange: V,
14
- onPageSizeChange: k,
15
- sortColumn: T,
16
- sortDirection: ee,
17
- onSortChange: h
18
- }) {
19
- var Q;
20
- const [te, ne] = c(((Q = o.find((e) => e.sortable === !0)) == null ? void 0 : Q.key) ?? null), i = T !== void 0 ? T : te, [re, se] = c("asc"), a = ee ?? re, [m, v] = c([]), [x, oe] = c(new Set(o.filter((e) => e.defaultVisible !== !1).map((e) => e.key))), [L, le] = c(o.map((e) => e.key)), [w, ie] = c(o.reduce((e, t) => ({ ...e, [t.key]: t.minWidth ?? 100 }), {})), [ce, R] = c(1), S = $ ?? ce, [ue, ae] = c(Z), d = K ?? ue, de = g(null), y = g(null), X = g(0), U = g(0), f = g(null), B = g(null), F = E !== void 0 && E.length > 0, j = I !== void 0 && I.length > 0, z = M(() => L.map((e) => o.find((t) => t.key === e)).filter((e) => e !== void 0), [L, o]), q = M(() => z.filter((e) => x.has(e.key)), [z, x]), fe = q.length + (j ? 1 : 0) + (F || _ ? 1 : 0), G = p ?? l.length, O = Math.max(1, Math.ceil(G / d)), H = S > O ? O : S, C = G === 0 ? 0 : (H - 1) * d, W = p !== void 0 ? Math.min(C + l.length, p) : Math.min(C + d, l.length), D = u(
21
- (e) => {
22
- V ? V(e) : R(e);
23
- },
24
- [V]
25
- ), J = u(
26
- (e) => {
27
- k ? k(e) : (ae(e), R(1));
28
- },
29
- [k]
30
- ), ge = u(
31
- (e) => {
32
- const t = typeof e == "function" ? e(S) : e;
33
- D(t);
34
- },
35
- [S, D]
36
- ), pe = u(
37
- (e) => {
38
- const t = typeof e == "function" ? e(d) : e;
39
- J(t);
40
- },
41
- [d, J]
42
- ), he = u(
43
- (e) => {
44
- const t = o.find((r) => r.key === e);
45
- if ((t == null ? void 0 : t.sortable) !== !0) return;
46
- let n = "asc";
47
- i === e && (n = a === "asc" ? "desc" : "asc"), h ? h(e, n) : (ne(e), se(n), D(1));
48
- },
49
- [o, i, a, h, D]
50
- ), P = u((e) => {
51
- const t = y.current;
52
- if (t === null) return;
53
- const n = e.clientX - X.current, r = Math.max(80, U.current + n);
54
- ie((s) => ({
55
- ...s,
56
- [t]: r
57
- }));
58
- }, []), N = u(
59
- function e() {
60
- y.current = null, document.removeEventListener("mousemove", P), document.removeEventListener("mouseup", e);
61
- },
62
- [P]
63
- ), me = u(
64
- (e, t) => {
65
- e.preventDefault(), e.stopPropagation(), y.current = t, X.current = e.clientX, U.current = w[t], document.addEventListener("mousemove", P), document.addEventListener("mouseup", N);
66
- },
67
- [w, P, N]
68
- ), ve = (e, t) => {
69
- f.current = t, e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/html", t);
70
- }, Se = (e, t) => {
71
- e.preventDefault(), e.dataTransfer.dropEffect = "move", B.current = t;
72
- }, Ce = (e, t) => {
73
- if (e.preventDefault(), f.current === null || f.current === t) return;
74
- const n = [...L], r = n.indexOf(f.current), s = n.indexOf(t);
75
- n.splice(r, 1), n.splice(s, 0, f.current), le(n), f.current = null, B.current = null;
76
- }, A = M(() => h !== void 0 ? l : [...l].sort((e, t) => {
77
- if (i === null) return 0;
78
- const n = o.find((b) => b.key === i), r = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(e) : e[i], s = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(t) : t[i];
79
- if (typeof r == "string" && typeof s == "string") {
80
- const b = r.localeCompare(s);
81
- return a === "asc" ? b : -b;
82
- }
83
- return r === s ? 0 : r == null ? 1 : s == null ? -1 : r < s ? a === "asc" ? -1 : 1 : r > s ? a === "asc" ? 1 : -1 : 0;
84
- }), [l, i, a, o, h]), xe = M(() => p !== void 0 ? A : A.slice(C, W), [A, C, W, p]);
85
- return {
86
- sortColumn: i,
87
- sortDirection: a,
88
- selectedRows: m,
89
- setSelectedRows: v,
90
- visibleColumns: x,
91
- columnWidths: w,
92
- currentPage: S,
93
- setCurrentPage: ge,
94
- pageSize: d,
95
- setPageSize: pe,
96
- totalPages: O,
97
- safeCurrentPage: H,
98
- startIndex: C,
99
- endIndex: W,
100
- tableRef: de,
101
- hasActions: F,
102
- hasBulkActions: j,
103
- orderedColumns: z,
104
- visibleColumnsArray: q,
105
- colSpanCount: fe,
106
- paginatedData: xe,
107
- handleSort: he,
108
- handleMouseDown: me,
109
- handleDragStart: ve,
110
- handleDragOver: Se,
111
- handleDrop: Ce,
112
- toggleColumnVisibility: (e) => {
113
- const t = new Set(x);
114
- t.has(e) ? t.delete(e) : t.add(e), oe(t);
115
- },
116
- toggleRowSelection: (e) => {
117
- m.includes(e) ? v(m.filter((t) => t !== e)) : v([...m, e]);
118
- },
119
- toggleSelectAll: () => {
120
- m.length === l.length ? v([]) : v(l.map((e) => Y(e)));
121
- }
122
- };
123
- }
124
- export {
125
- Ve as u
126
- };