@krosoft/react 0.0.161 → 0.0.163

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.
@@ -0,0 +1,506 @@
1
+ import { jsxs as t, jsx as e } from "react/jsx-runtime";
2
+ import { u as ae } from "./useDataTable-CxcA5S-s.js";
3
+ import { ay as P, aM as $, aA as W, aC as se, $ as B, az as ie } from "./toggle-group-BASGy2mQ.js";
4
+ import "./alert-B78CiTYe.js";
5
+ import "@radix-ui/react-aspect-ratio";
6
+ import { B as y } from "./tooltip-BWyFpIxo.js";
7
+ import "@radix-ui/react-collapsible";
8
+ import "./sheet-Gop1cIaU.js";
9
+ import { MoreVerticalIcon as ne, Loader2Icon as le, GripVerticalIcon as de, ArrowUpIcon as oe, ArrowDownIcon as ce, ArrowUpDownIcon as me, ChevronLeftIcon as he, ChevronRightIcon as ge, SettingsIcon as ue } from "lucide-react";
10
+ import "react-resizable-panels";
11
+ import "clsx";
12
+ import "tailwind-merge";
13
+ import "./select-MWzbMBAS.js";
14
+ import "next-themes";
15
+ import "sonner";
16
+ import "react";
17
+ const L = [5, 10, 30, 50, 100], pe = L[1];
18
+ function fe({ actions: d, row: a }) {
19
+ const o = d.filter((r) => r.visible === void 0 || r.visible(a));
20
+ if (o.length === 0)
21
+ return null;
22
+ const s = o.filter((r) => r.overflow !== !0), m = o.filter((r) => r.overflow === !0);
23
+ return /* @__PURE__ */ t("div", { className: "flex items-center justify-center gap-1", children: [
24
+ s.map((r, h) => {
25
+ var c;
26
+ const g = r.icon;
27
+ return /* @__PURE__ */ t(
28
+ y,
29
+ {
30
+ variant: r.variant ?? "ghost",
31
+ size: "sm",
32
+ disabled: ((c = r.disabled) == null ? void 0 : c.call(r, a)) ?? !1,
33
+ className: `h-7 px-2 text-muted-foreground hover:text-foreground ${r.className ?? ""}`,
34
+ onClick: (n) => {
35
+ n.stopPropagation(), r.onClick(a);
36
+ },
37
+ children: [
38
+ g !== void 0 && /* @__PURE__ */ e(g, { className: "size-3.5" }),
39
+ r.label
40
+ ]
41
+ },
42
+ h
43
+ );
44
+ }),
45
+ m.length > 0 && /* @__PURE__ */ t(P, { children: [
46
+ /* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(y, { variant: "ghost", size: "icon", className: "h-7 w-7 text-muted-foreground hover:text-foreground", children: /* @__PURE__ */ e(ne, { className: "size-3.5" }) }) }),
47
+ /* @__PURE__ */ e(
48
+ W,
49
+ {
50
+ align: "end",
51
+ onClick: (r) => {
52
+ r.stopPropagation();
53
+ },
54
+ children: m.map((r, h) => {
55
+ var c;
56
+ const g = r.icon;
57
+ return /* @__PURE__ */ t(
58
+ se,
59
+ {
60
+ disabled: ((c = r.disabled) == null ? void 0 : c.call(r, a)) ?? !1,
61
+ onClick: () => {
62
+ r.onClick(a);
63
+ },
64
+ className: r.className,
65
+ children: [
66
+ g !== void 0 && /* @__PURE__ */ e("span", { className: "mr-2 size-4 flex items-center justify-center", children: /* @__PURE__ */ e(g, { className: "size-4" }) }),
67
+ r.label
68
+ ]
69
+ },
70
+ h
71
+ );
72
+ })
73
+ }
74
+ )
75
+ ] })
76
+ ] });
77
+ }
78
+ function xe({
79
+ isLoading: d,
80
+ colSpanCount: a,
81
+ noDataMessage: o,
82
+ paginatedData: s,
83
+ getRowId: m,
84
+ onRowClick: r,
85
+ hasBulkActions: h,
86
+ selectedRows: g,
87
+ toggleRowSelection: c,
88
+ visibleColumnsArray: n,
89
+ columnWidths: N,
90
+ hasActions: z,
91
+ actions: v,
92
+ columns: w,
93
+ bordered: k = !1
94
+ }) {
95
+ const D = (u, p) => {
96
+ const i = w.find((b) => b.key === p);
97
+ if ((i == null ? void 0 : i.renderCell) !== void 0)
98
+ return i.renderCell(u);
99
+ const x = u[p];
100
+ return /* @__PURE__ */ e("span", { className: "text-sm truncate", children: x != null ? String(x) : "-" });
101
+ };
102
+ return d ? /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: a, className: "py-8 text-center", children: /* @__PURE__ */ t("div", { className: "flex flex-col items-center justify-center gap-2 text-muted-foreground", children: [
103
+ /* @__PURE__ */ e(le, { className: "h-6 w-6 animate-spin text-primary" }),
104
+ /* @__PURE__ */ e("span", { className: "text-sm", children: "Chargement..." })
105
+ ] }) }) }) }) : s.length === 0 ? /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: a, className: "py-8 text-center text-sm text-muted-foreground", children: o }) }) }) : /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-800", children: s.map((u) => {
106
+ const p = m(u);
107
+ return /* @__PURE__ */ t(
108
+ "tr",
109
+ {
110
+ className: `group hover:bg-muted/50 dark:hover:bg-gray-900/50 transition-colors ${r !== void 0 ? "cursor-pointer" : ""}`,
111
+ onClick: () => r == null ? void 0 : r(u),
112
+ children: [
113
+ h ? /* @__PURE__ */ e(
114
+ "td",
115
+ {
116
+ className: "p-1 text-center align-middle",
117
+ style: { width: "32px", minWidth: "32px", maxWidth: "32px" },
118
+ onClick: (i) => {
119
+ i.stopPropagation();
120
+ },
121
+ children: /* @__PURE__ */ e("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ e(
122
+ B,
123
+ {
124
+ checked: g.includes(p),
125
+ onCheckedChange: () => {
126
+ c(p);
127
+ }
128
+ }
129
+ ) })
130
+ }
131
+ ) : null,
132
+ n.map((i, x) => {
133
+ const b = x === n.length - 1;
134
+ return /* @__PURE__ */ e(
135
+ "td",
136
+ {
137
+ className: `px-2 py-2 relative ${k && !b ? "border-r border-gray-100 dark:border-gray-800" : ""} ${i.className ?? ""}`,
138
+ style: { width: N[i.key] },
139
+ children: /* @__PURE__ */ e("div", { className: "w-full h-full", children: D(u, i.key) })
140
+ },
141
+ i.key
142
+ );
143
+ }),
144
+ z ? /* @__PURE__ */ e(
145
+ "td",
146
+ {
147
+ className: "p-1 text-center align-middle whitespace-nowrap",
148
+ style: { minWidth: "32px" },
149
+ onClick: (i) => {
150
+ i.stopPropagation();
151
+ },
152
+ children: v !== void 0 && v.length > 0 ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ e(fe, { actions: v, row: u }) }) : null
153
+ }
154
+ ) : null
155
+ ]
156
+ },
157
+ p
158
+ );
159
+ }) });
160
+ }
161
+ function ve({ selectedRows: d, setSelectedRows: a, bulkActions: o }) {
162
+ return /* @__PURE__ */ t("div", { className: "bg-muted/60 dark:bg-gray-900/60 border border-border px-3 py-1.5 flex items-center justify-between rounded-lg", children: [
163
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-4", children: [
164
+ /* @__PURE__ */ t("span", { className: "text-sm font-medium text-primary ml-1", children: [
165
+ d.length,
166
+ " sélectionné(s)"
167
+ ] }),
168
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: o.map((s, m) => {
169
+ const r = s.icon;
170
+ return /* @__PURE__ */ t(
171
+ y,
172
+ {
173
+ variant: "outline",
174
+ size: "sm",
175
+ onClick: () => {
176
+ s.onClick(d, () => {
177
+ a([]);
178
+ });
179
+ },
180
+ className: `h-7 bg-background shadow-sm text-xs px-2.5 ${s.variant === "destructive" ? "text-destructive border-destructive/30 hover:bg-destructive/10 hover:text-destructive" : "text-foreground"}`,
181
+ children: [
182
+ 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" }) }),
183
+ s.label
184
+ ]
185
+ },
186
+ m
187
+ );
188
+ }) })
189
+ ] }),
190
+ /* @__PURE__ */ e(
191
+ y,
192
+ {
193
+ variant: "ghost",
194
+ size: "sm",
195
+ onClick: () => {
196
+ a([]);
197
+ },
198
+ className: "text-xs text-muted-foreground hover:text-foreground h-7 px-2",
199
+ children: "Désélectionner"
200
+ }
201
+ )
202
+ ] });
203
+ }
204
+ function be({
205
+ hasBulkActions: d,
206
+ selectedRows: a,
207
+ totalItems: o,
208
+ toggleSelectAll: s,
209
+ visibleColumnsArray: m,
210
+ draggableColumns: r,
211
+ resizableColumns: h,
212
+ columnWidths: g,
213
+ sortColumn: c,
214
+ sortDirection: n,
215
+ handleSort: N,
216
+ handleDragStart: z,
217
+ handleDragOver: v,
218
+ handleDrop: w,
219
+ handleMouseDown: k,
220
+ hasActions: D,
221
+ settingsNode: u,
222
+ bordered: p = !1
223
+ }) {
224
+ let i = !1;
225
+ a.length === o && o > 0 ? i = !0 : a.length > 0 && (i = "indeterminate");
226
+ const x = (l) => l.sortable !== !0 ? null : c === l.key ? n === "asc" ? /* @__PURE__ */ e(oe, { className: "size-3.5 text-foreground" }) : /* @__PURE__ */ e(ce, { className: "size-3.5 text-foreground" }) : /* @__PURE__ */ e(me, { className: "size-3.5 text-muted-foreground/50 group-hover:text-muted-foreground transition-colors" }), b = (l, I) => {
227
+ const S = I !== !1, C = l.sortable === !0;
228
+ return /* @__PURE__ */ t(
229
+ "th",
230
+ {
231
+ className: [
232
+ "px-2 py-2 text-left text-sm font-medium text-gray-900 dark:text-gray-100 relative group",
233
+ p ? "border-r border-gray-200 dark:border-gray-800" : "",
234
+ C ? "cursor-pointer select-none" : "",
235
+ l.className ?? ""
236
+ ].filter(Boolean).join(" "),
237
+ style: { width: g[l.key] },
238
+ draggable: S,
239
+ onClick: () => {
240
+ N(l.key);
241
+ },
242
+ onDragStart: (f) => {
243
+ S ? z(f, l.key) : f.preventDefault();
244
+ },
245
+ onDragOver: (f) => {
246
+ v(f, l.key);
247
+ },
248
+ onDrop: (f) => {
249
+ w(f, l.key);
250
+ },
251
+ children: [
252
+ /* @__PURE__ */ t("div", { className: "flex items-center justify-between pr-2", children: [
253
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-1", children: [
254
+ S ? /* @__PURE__ */ e(de, { className: "size-4 text-gray-400 cursor-grab dark:text-gray-300 shrink-0" }) : null,
255
+ /* @__PURE__ */ e("span", { className: "truncate", children: l.label })
256
+ ] }),
257
+ /* @__PURE__ */ e("div", { className: "ml-1 shrink-0", children: x(l) })
258
+ ] }),
259
+ h ? /* @__PURE__ */ e(
260
+ "div",
261
+ {
262
+ 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",
263
+ onMouseDown: (f) => {
264
+ k(f, l.key);
265
+ }
266
+ }
267
+ ) : null
268
+ ]
269
+ },
270
+ l.key
271
+ );
272
+ };
273
+ return /* @__PURE__ */ e("thead", { className: "bg-muted/50 dark:bg-gray-900/50 border-b border-gray-200 dark:border-gray-800", children: /* @__PURE__ */ t("tr", { children: [
274
+ d ? /* @__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(B, { checked: i, onCheckedChange: s }) }) }) : null,
275
+ m.map((l) => b(l, r)),
276
+ D || u !== void 0 ? /* @__PURE__ */ e("th", { className: "p-1 text-center align-middle", style: { minWidth: "32px" }, children: u }) : null
277
+ ] }) });
278
+ }
279
+ function ye({
280
+ totalItems: d,
281
+ startIndex: a,
282
+ endIndex: o,
283
+ pageSize: s,
284
+ setPageSize: m,
285
+ currentPage: r,
286
+ setCurrentPage: h,
287
+ pageSizeOptions: g,
288
+ totalPages: c
289
+ }) {
290
+ return /* @__PURE__ */ t("div", { className: "px-4 py-2 border-t border-gray-200 dark:border-gray-800 flex items-center justify-between bg-muted/50 dark:bg-gray-900/50 flex-wrap gap-2", children: [
291
+ /* @__PURE__ */ t("div", { className: "text-sm text-muted-foreground", children: [
292
+ d === 0 ? "0" : `${String(a + 1)} - ${String(o)}`,
293
+ " sur ",
294
+ d
295
+ ] }),
296
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-4", children: [
297
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
298
+ /* @__PURE__ */ e("span", { className: "text-sm text-muted-foreground", children: "Lignes par page :" }),
299
+ /* @__PURE__ */ e(
300
+ "select",
301
+ {
302
+ value: s,
303
+ onChange: (n) => {
304
+ m(Number(n.target.value)), h(1);
305
+ },
306
+ className: "border border-input bg-background rounded px-2 py-1 text-sm text-foreground",
307
+ children: g.map((n) => /* @__PURE__ */ e("option", { value: n, children: n }, n))
308
+ }
309
+ )
310
+ ] }),
311
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
312
+ /* @__PURE__ */ e(
313
+ y,
314
+ {
315
+ variant: "outline",
316
+ size: "sm",
317
+ className: "h-8 w-8 p-0",
318
+ onClick: () => {
319
+ h((n) => Math.max(1, n - 1));
320
+ },
321
+ disabled: r === 1,
322
+ children: /* @__PURE__ */ e(he, { className: "size-4" })
323
+ }
324
+ ),
325
+ /* @__PURE__ */ t("span", { className: "text-sm text-muted-foreground", children: [
326
+ "Page ",
327
+ r,
328
+ " sur ",
329
+ c
330
+ ] }),
331
+ /* @__PURE__ */ e(
332
+ y,
333
+ {
334
+ variant: "outline",
335
+ size: "sm",
336
+ className: "h-8 w-8 p-0",
337
+ onClick: () => {
338
+ h((n) => Math.min(c, n + 1));
339
+ },
340
+ disabled: r === c,
341
+ children: /* @__PURE__ */ e(ge, { className: "size-4" })
342
+ }
343
+ )
344
+ ] })
345
+ ] })
346
+ ] });
347
+ }
348
+ function Ne({ columns: d, visibleColumns: a, toggleColumnVisibility: o }) {
349
+ return /* @__PURE__ */ t(P, { children: [
350
+ /* @__PURE__ */ e($, { asChild: !0, children: /* @__PURE__ */ e(y, { 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(ue, { className: "size-3.5 text-gray-600 dark:text-gray-300" }) }) }),
351
+ /* @__PURE__ */ e(W, { align: "end", className: "w-56", children: d.map((s) => /* @__PURE__ */ e(
352
+ ie,
353
+ {
354
+ checked: a.has(s.key),
355
+ onCheckedChange: () => {
356
+ o(s.key);
357
+ },
358
+ children: s.label
359
+ },
360
+ s.key
361
+ )) })
362
+ ] });
363
+ }
364
+ function He({
365
+ data: d,
366
+ columns: a,
367
+ getRowId: o,
368
+ onRowClick: s,
369
+ actions: m,
370
+ bulkActions: r,
371
+ draggableColumns: h = !1,
372
+ resizableColumns: g = !1,
373
+ columnVisibility: c = !1,
374
+ isLoading: n = !1,
375
+ bordered: N = !1,
376
+ noDataMessage: z = "Aucun résultat",
377
+ defaultPageSize: v = pe,
378
+ pageSizeOptions: w = L,
379
+ totalRows: k,
380
+ currentPage: D,
381
+ pageSize: u,
382
+ onPageChange: p,
383
+ onPageSizeChange: i,
384
+ sortColumn: x,
385
+ sortDirection: b,
386
+ onSortChange: l
387
+ }) {
388
+ const {
389
+ sortColumn: I,
390
+ sortDirection: S,
391
+ selectedRows: C,
392
+ setSelectedRows: f,
393
+ visibleColumns: H,
394
+ columnWidths: j,
395
+ safeCurrentPage: O,
396
+ totalPages: U,
397
+ startIndex: V,
398
+ endIndex: G,
399
+ tableRef: q,
400
+ hasActions: A,
401
+ hasBulkActions: M,
402
+ visibleColumnsArray: T,
403
+ colSpanCount: E,
404
+ paginatedData: F,
405
+ handleSort: J,
406
+ handleMouseDown: Q,
407
+ handleDragStart: X,
408
+ handleDragOver: Y,
409
+ handleDrop: Z,
410
+ toggleColumnVisibility: _,
411
+ toggleRowSelection: K,
412
+ toggleSelectAll: R,
413
+ pageSize: ee,
414
+ setPageSize: re,
415
+ setCurrentPage: te
416
+ } = ae({
417
+ data: d,
418
+ columns: a,
419
+ getRowId: o,
420
+ defaultPageSize: v,
421
+ actions: m,
422
+ bulkActions: r,
423
+ columnVisibility: c,
424
+ totalRows: k,
425
+ currentPage: D,
426
+ pageSize: u,
427
+ onPageChange: p,
428
+ onPageSizeChange: i,
429
+ sortColumn: x,
430
+ sortDirection: b,
431
+ onSortChange: l
432
+ });
433
+ return /* @__PURE__ */ t("div", { className: "space-y-4", children: [
434
+ C.length > 0 && r !== void 0 && r.length > 0 && /* @__PURE__ */ e(ve, { selectedRows: C, setSelectedRows: f, bulkActions: r }),
435
+ /* @__PURE__ */ t("div", { className: "w-full bg-card dark:bg-gray-950 rounded-md border border-gray-200 dark:border-gray-800 overflow-hidden", children: [
436
+ /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ t("table", { ref: q, className: "w-full", children: [
437
+ /* @__PURE__ */ e(
438
+ be,
439
+ {
440
+ hasBulkActions: M,
441
+ selectedRows: C,
442
+ totalItems: d.length,
443
+ toggleSelectAll: R,
444
+ visibleColumnsArray: T,
445
+ draggableColumns: h,
446
+ resizableColumns: g,
447
+ columnWidths: j,
448
+ sortColumn: I,
449
+ sortDirection: S,
450
+ handleSort: J,
451
+ handleDragStart: X,
452
+ handleDragOver: Y,
453
+ handleDrop: Z,
454
+ handleMouseDown: Q,
455
+ hasActions: A,
456
+ bordered: N,
457
+ settingsNode: c ? /* @__PURE__ */ e(Ne, { columns: a, visibleColumns: H, toggleColumnVisibility: _ }) : void 0
458
+ }
459
+ ),
460
+ /* @__PURE__ */ e(
461
+ xe,
462
+ {
463
+ bordered: N,
464
+ isLoading: n,
465
+ colSpanCount: E,
466
+ noDataMessage: z,
467
+ paginatedData: F,
468
+ getRowId: o,
469
+ onRowClick: s,
470
+ hasBulkActions: M,
471
+ selectedRows: C,
472
+ toggleRowSelection: K,
473
+ visibleColumnsArray: T,
474
+ columnWidths: j,
475
+ hasActions: A || c,
476
+ actions: m,
477
+ columns: a
478
+ }
479
+ )
480
+ ] }) }),
481
+ /* @__PURE__ */ e(
482
+ ye,
483
+ {
484
+ totalItems: k ?? d.length,
485
+ startIndex: V,
486
+ endIndex: G,
487
+ pageSize: ee,
488
+ setPageSize: re,
489
+ currentPage: O,
490
+ setCurrentPage: te,
491
+ pageSizeOptions: w,
492
+ totalPages: U
493
+ }
494
+ )
495
+ ] })
496
+ ] });
497
+ }
498
+ export {
499
+ He as D,
500
+ fe as T,
501
+ xe as a,
502
+ ve as b,
503
+ be as c,
504
+ ye as d,
505
+ Ne as e
506
+ };