laif-ds 0.1.82 → 0.1.83
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/dist/components/ui/data-table.js +92 -89
- package/package.json +1 -1
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as n, jsxs as h } from "react/jsx-runtime";
|
|
3
3
|
import { useReactTable as ce, flexRender as $ } from "../../node_modules/@tanstack/react-table/build/lib/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useRef as G, useState as m, useMemo as se, useEffect as R } from "react";
|
|
5
5
|
import { cn as re } from "../../lib/utils.js";
|
|
6
6
|
import { createCustomFilterFns as de, ELogicalFilterOperator as me, debounce as ue, createMultiValueFilterFn as fe, updatePageSizeFromContainer as he } from "./data-table.service.js";
|
|
7
|
-
import { Pagination as pe, PaginationContent as xe, PaginationItem as
|
|
7
|
+
import { Pagination as pe, PaginationContent as xe, PaginationItem as b, PaginationFirst as we, PaginationPrevious as Ce, PaginationLink as be, PaginationNext as Pe, PaginationLast as Se } from "./pagination.js";
|
|
8
8
|
import { Checkbox as E } from "./checkbox.js";
|
|
9
9
|
import { Input as Ie } from "./input.js";
|
|
10
10
|
import { ScrollArea as W, ScrollBar as F } from "./scroll-area.js";
|
|
11
11
|
import { AppMultipleSelectDropdown as Re } from "./app-multiple-select-dropdown.js";
|
|
12
|
-
import { Table as
|
|
12
|
+
import { Table as Ne, TableHeader as Me, TableRow as N, TableHead as ze, TableBody as ye, TableCell as H } from "./table.js";
|
|
13
13
|
import { Skeleton as ke } from "./skeleton.js";
|
|
14
|
-
import { getPaginationRowModel as Fe, getFilteredRowModel as He, getSortedRowModel as De, getCoreRowModel as
|
|
14
|
+
import { getPaginationRowModel as Fe, getFilteredRowModel as He, getSortedRowModel as De, getCoreRowModel as Ve } from "../../node_modules/@tanstack/table-core/build/lib/index.js";
|
|
15
15
|
function Ue({
|
|
16
16
|
columns: P,
|
|
17
17
|
data: D,
|
|
18
|
-
loading:
|
|
19
|
-
emptyComponent:
|
|
18
|
+
loading: _ = !1,
|
|
19
|
+
emptyComponent: J,
|
|
20
20
|
className: K,
|
|
21
21
|
rowSelection: q = {},
|
|
22
|
-
onRowSelectionChange:
|
|
22
|
+
onRowSelectionChange: V,
|
|
23
23
|
checkable: S = !1,
|
|
24
|
-
onCheckedRowsChange:
|
|
24
|
+
onCheckedRowsChange: M,
|
|
25
25
|
notFoundMessage: Q = "Nessun risultato trovato.",
|
|
26
26
|
searchBar: u = void 0,
|
|
27
27
|
dropdownFilters: d = void 0,
|
|
28
|
-
totalItems:
|
|
28
|
+
totalItems: z = void 0,
|
|
29
29
|
datatableSizes: p = {
|
|
30
30
|
rowHeight: 32.5,
|
|
31
31
|
// default table row height in pixels
|
|
@@ -38,10 +38,10 @@ function Ue({
|
|
|
38
38
|
serverOptions: r = void 0,
|
|
39
39
|
setServerOptions: g = void 0
|
|
40
40
|
}) {
|
|
41
|
-
const
|
|
41
|
+
const y = G(null), v = G(void 0), [U, X] = m([]), [Y, Z] = m([]), [B, O] = m({}), [C, ee] = m(""), [w, k] = m({
|
|
42
42
|
pageIndex: 0,
|
|
43
43
|
pageSize: 10
|
|
44
|
-
}), [
|
|
44
|
+
}), [te, j] = m(0), [ne, ie] = m({}), L = V ? q : ne, le = V || ie, [I, ae] = m({}), c = !!r, oe = se(() => S ? [
|
|
45
45
|
{
|
|
46
46
|
id: "select",
|
|
47
47
|
header: ({ table: e }) => /* @__PURE__ */ n(
|
|
@@ -75,15 +75,15 @@ function Ue({
|
|
|
75
75
|
}), ge = {
|
|
76
76
|
data: D,
|
|
77
77
|
columns: oe,
|
|
78
|
-
getCoreRowModel:
|
|
78
|
+
getCoreRowModel: Ve(),
|
|
79
79
|
onSortingChange: X,
|
|
80
80
|
getSortedRowModel: De(),
|
|
81
81
|
onColumnVisibilityChange: O,
|
|
82
|
-
onRowSelectionChange:
|
|
82
|
+
onRowSelectionChange: le,
|
|
83
83
|
getFilteredRowModel: He(),
|
|
84
|
-
globalFilterFn: (e, t, l) => c || !l ? !0 : u?.columns.some((
|
|
85
|
-
const
|
|
86
|
-
return String(
|
|
84
|
+
globalFilterFn: (e, t, l) => c || !l ? !0 : u?.columns.some((o) => {
|
|
85
|
+
const a = e.getValue(o);
|
|
86
|
+
return String(a).toLowerCase().includes(l.toLowerCase());
|
|
87
87
|
}) ?? !1,
|
|
88
88
|
filterFns: {
|
|
89
89
|
multiValue: (e, t, l) => fe(
|
|
@@ -96,46 +96,46 @@ function Ue({
|
|
|
96
96
|
...de(d ?? [], r)
|
|
97
97
|
},
|
|
98
98
|
onPaginationChange: (e) => {
|
|
99
|
-
c ? typeof e == "object" && g && g((t) => ({
|
|
99
|
+
c ? typeof e == "object" && g && g?.((t) => ({
|
|
100
100
|
...t,
|
|
101
101
|
pagination: {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
...t.pagination,
|
|
103
|
+
pageIndex: e.pageIndex
|
|
104
104
|
}
|
|
105
|
-
})) :
|
|
105
|
+
})) : k(e);
|
|
106
106
|
},
|
|
107
107
|
getPaginationRowModel: Fe(),
|
|
108
108
|
manualPagination: c,
|
|
109
|
-
pageCount:
|
|
109
|
+
pageCount: te,
|
|
110
110
|
state: {
|
|
111
111
|
sorting: U,
|
|
112
112
|
columnFilters: Y,
|
|
113
113
|
columnVisibility: B,
|
|
114
|
-
rowSelection:
|
|
115
|
-
globalFilter:
|
|
116
|
-
pagination: r?.pagination ??
|
|
114
|
+
rowSelection: L,
|
|
115
|
+
globalFilter: C,
|
|
116
|
+
pagination: r?.pagination ?? w
|
|
117
117
|
}
|
|
118
118
|
}, i = ce(ge);
|
|
119
119
|
R(() => {
|
|
120
120
|
let e;
|
|
121
|
-
if (u &&
|
|
122
|
-
value:
|
|
121
|
+
if (u && C && (e || (e = {}), e.searchbarFilters = {
|
|
122
|
+
value: C,
|
|
123
123
|
columns: u.columns
|
|
124
124
|
}), d && Object.keys(I).length > 0) {
|
|
125
|
-
const
|
|
125
|
+
const a = {};
|
|
126
126
|
for (const s of d) {
|
|
127
127
|
const f = I[s.column];
|
|
128
|
-
f && f.length > 0 && (
|
|
128
|
+
f && f.length > 0 && (a[s.column] = {
|
|
129
129
|
column: s.column,
|
|
130
130
|
value: f,
|
|
131
131
|
logic: s.innerFiltersMode || me.OR
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
Object.keys(
|
|
134
|
+
Object.keys(a).length > 0 && (e || (e = {}), e.dropdownFilters = a);
|
|
135
135
|
}
|
|
136
|
-
const t =
|
|
137
|
-
JSON.stringify(t ?? {}) !== JSON.stringify(l ?? {}) && g && (
|
|
138
|
-
...
|
|
136
|
+
const t = v.current, l = e;
|
|
137
|
+
JSON.stringify(t ?? {}) !== JSON.stringify(l ?? {}) && g && (v.current = l, g((a) => ({
|
|
138
|
+
...a,
|
|
139
139
|
pagination: {
|
|
140
140
|
pageIndex: 0,
|
|
141
141
|
pageSize: r?.pagination.pageSize ?? 10
|
|
@@ -146,7 +146,7 @@ function Ue({
|
|
|
146
146
|
d,
|
|
147
147
|
I,
|
|
148
148
|
u,
|
|
149
|
-
|
|
149
|
+
C,
|
|
150
150
|
r,
|
|
151
151
|
g
|
|
152
152
|
]);
|
|
@@ -155,47 +155,50 @@ function Ue({
|
|
|
155
155
|
if (c)
|
|
156
156
|
j(
|
|
157
157
|
Math.ceil(
|
|
158
|
-
(
|
|
158
|
+
(z ?? 0) / (r.pagination?.pageSize || w.pageSize || 10)
|
|
159
159
|
)
|
|
160
160
|
);
|
|
161
161
|
else {
|
|
162
162
|
const e = T.rows.length;
|
|
163
|
-
j(Math.ceil(e /
|
|
163
|
+
j(Math.ceil(e / w.pageSize));
|
|
164
164
|
}
|
|
165
165
|
}, [
|
|
166
166
|
c,
|
|
167
|
-
|
|
168
|
-
r?.pagination,
|
|
167
|
+
z,
|
|
168
|
+
r?.pagination.pageSize,
|
|
169
|
+
r?.pagination.pageIndex,
|
|
169
170
|
i,
|
|
170
171
|
T,
|
|
171
|
-
|
|
172
|
+
w.pageSize
|
|
172
173
|
]), R(() => {
|
|
173
174
|
const e = ue(() => {
|
|
174
|
-
const t =
|
|
175
|
+
const t = y.current;
|
|
175
176
|
t && he(t, {
|
|
176
177
|
rowHeight: p.rowHeight,
|
|
177
178
|
headerHeight: p.headerHeight,
|
|
178
179
|
containerHeight: p.containerHeight,
|
|
179
|
-
onPageChange: c ? (l,
|
|
180
|
-
g?.((
|
|
181
|
-
...
|
|
182
|
-
pagination: {
|
|
180
|
+
onPageChange: c ? (l, o) => {
|
|
181
|
+
g?.((a) => ({
|
|
182
|
+
...a,
|
|
183
|
+
pagination: {
|
|
184
|
+
...a.pagination,
|
|
185
|
+
pageIndex: l
|
|
186
|
+
}
|
|
183
187
|
}));
|
|
184
|
-
} : (l,
|
|
185
|
-
|
|
188
|
+
} : (l, o) => {
|
|
189
|
+
k({ pageIndex: l, pageSize: o });
|
|
186
190
|
},
|
|
187
191
|
setPagination: (l) => {
|
|
188
|
-
const
|
|
189
|
-
c ? g?.((
|
|
190
|
-
...
|
|
192
|
+
const o = typeof l == "function" ? l({ pageIndex: 0, pageSize: 10 }) : l;
|
|
193
|
+
c ? g?.((a) => ({
|
|
194
|
+
...a,
|
|
191
195
|
pagination: {
|
|
192
|
-
...
|
|
193
|
-
pageIndex:
|
|
194
|
-
pageSize: a.pageSize
|
|
196
|
+
...a.pagination,
|
|
197
|
+
pageIndex: o.pageIndex
|
|
195
198
|
}
|
|
196
|
-
})) :
|
|
197
|
-
pageIndex:
|
|
198
|
-
pageSize:
|
|
199
|
+
})) : k({
|
|
200
|
+
pageIndex: o.pageIndex,
|
|
201
|
+
pageSize: o.pageSize
|
|
199
202
|
});
|
|
200
203
|
}
|
|
201
204
|
});
|
|
@@ -208,15 +211,15 @@ function Ue({
|
|
|
208
211
|
p.containerHeight,
|
|
209
212
|
p.headerHeight,
|
|
210
213
|
p.rowHeight,
|
|
211
|
-
|
|
214
|
+
y,
|
|
212
215
|
g
|
|
213
216
|
// should be stable, but include for clarity
|
|
214
217
|
]), R(() => {
|
|
215
|
-
if (
|
|
218
|
+
if (M && S) {
|
|
216
219
|
const e = i.getFilteredSelectedRowModel().rows.map((t) => t.original);
|
|
217
|
-
|
|
220
|
+
M(e);
|
|
218
221
|
}
|
|
219
|
-
}, [i,
|
|
222
|
+
}, [i, M, S, L]), /* @__PURE__ */ h(
|
|
220
223
|
"div",
|
|
221
224
|
{
|
|
222
225
|
className: re(
|
|
@@ -230,7 +233,7 @@ function Ue({
|
|
|
230
233
|
{
|
|
231
234
|
iconLeft: "Search",
|
|
232
235
|
placeholder: u.placeholder ?? "Cerca...",
|
|
233
|
-
value:
|
|
236
|
+
value: C,
|
|
234
237
|
onChange: (e) => {
|
|
235
238
|
ee(e.target.value);
|
|
236
239
|
},
|
|
@@ -249,17 +252,17 @@ function Ue({
|
|
|
249
252
|
value: l,
|
|
250
253
|
placeholder: e.placeholder,
|
|
251
254
|
label: e.label,
|
|
252
|
-
onChange: (
|
|
253
|
-
|
|
254
|
-
...
|
|
255
|
-
[e.column]:
|
|
256
|
-
})), Z((
|
|
257
|
-
const s =
|
|
255
|
+
onChange: (o) => {
|
|
256
|
+
ae((a) => ({
|
|
257
|
+
...a,
|
|
258
|
+
[e.column]: o
|
|
259
|
+
})), Z((a) => {
|
|
260
|
+
const s = a.filter(
|
|
258
261
|
(f) => f.id !== e.column
|
|
259
262
|
);
|
|
260
|
-
return
|
|
263
|
+
return o.length === 0 ? s : [
|
|
261
264
|
...s,
|
|
262
|
-
{ id: e.column, value:
|
|
265
|
+
{ id: e.column, value: o }
|
|
263
266
|
];
|
|
264
267
|
});
|
|
265
268
|
}
|
|
@@ -273,13 +276,13 @@ function Ue({
|
|
|
273
276
|
"div",
|
|
274
277
|
{
|
|
275
278
|
className: "flex max-h-full min-h-0 max-w-full min-w-0 flex-1",
|
|
276
|
-
ref:
|
|
279
|
+
ref: y,
|
|
277
280
|
children: /* @__PURE__ */ h(W, { className: "border-d-border h-full min-h-0 w-full rounded-md border", children: [
|
|
278
281
|
/* @__PURE__ */ n(F, { orientation: "horizontal" }),
|
|
279
282
|
/* @__PURE__ */ n(F, { orientation: "vertical" }),
|
|
280
|
-
/* @__PURE__ */ h(
|
|
281
|
-
/* @__PURE__ */ n(
|
|
282
|
-
|
|
283
|
+
/* @__PURE__ */ h(Ne, { children: [
|
|
284
|
+
/* @__PURE__ */ n(Me, { children: i.getHeaderGroups().map((e) => /* @__PURE__ */ n(N, { children: e.headers.map((t) => /* @__PURE__ */ n(
|
|
285
|
+
ze,
|
|
283
286
|
{
|
|
284
287
|
className: `bg-d-secondary sticky top-0 z-10 ${t.column.columnDef.sticky ? "left-0" : ""}`,
|
|
285
288
|
children: t.isPlaceholder ? null : $(
|
|
@@ -289,15 +292,15 @@ function Ue({
|
|
|
289
292
|
},
|
|
290
293
|
t.id
|
|
291
294
|
)) }, e.id)) }),
|
|
292
|
-
/* @__PURE__ */ n(ye, { children:
|
|
295
|
+
/* @__PURE__ */ n(ye, { children: _ ? Array.from({ length: D.length || 8 }).map((e, t) => /* @__PURE__ */ n(N, { children: i.getHeaderGroups()[0].headers.map((l, o) => /* @__PURE__ */ n(
|
|
293
296
|
H,
|
|
294
297
|
{
|
|
295
298
|
className: `w-full ${l.column.columnDef.sticky ? "bg-d-background sticky left-0 z-10" : ""}`,
|
|
296
299
|
children: /* @__PURE__ */ n(ke, { className: "h-6 w-full" })
|
|
297
300
|
},
|
|
298
|
-
`skeleton-cell-${t}-${
|
|
301
|
+
`skeleton-cell-${t}-${o}`
|
|
299
302
|
)) }, `skeleton-row-${t}`)) : i.getRowModel().rows?.length ? i.getRowModel().rows.map((e) => /* @__PURE__ */ n(
|
|
300
|
-
|
|
303
|
+
N,
|
|
301
304
|
{
|
|
302
305
|
"data-state": e.getIsSelected() && "selected",
|
|
303
306
|
children: e.getVisibleCells().map((t) => /* @__PURE__ */ n(
|
|
@@ -313,12 +316,12 @@ function Ue({
|
|
|
313
316
|
))
|
|
314
317
|
},
|
|
315
318
|
e.id
|
|
316
|
-
)) : /* @__PURE__ */ n(
|
|
319
|
+
)) : /* @__PURE__ */ n(N, { children: /* @__PURE__ */ n(
|
|
317
320
|
H,
|
|
318
321
|
{
|
|
319
322
|
colSpan: P.length,
|
|
320
323
|
className: "pt-4 text-center",
|
|
321
|
-
children:
|
|
324
|
+
children: J || Q
|
|
322
325
|
}
|
|
323
326
|
) }) })
|
|
324
327
|
] })
|
|
@@ -327,12 +330,12 @@ function Ue({
|
|
|
327
330
|
),
|
|
328
331
|
/* @__PURE__ */ h(pe, { className: "h-9", children: [
|
|
329
332
|
/* @__PURE__ */ n("div", { className: "flex h-full flex-1 items-center align-middle", children: /* @__PURE__ */ n("div", { className: "text-d-foreground hidden text-sm md:flex", children: Math.min(
|
|
330
|
-
r?.pagination?.pageSize ??
|
|
333
|
+
r?.pagination?.pageSize ?? w.pageSize,
|
|
331
334
|
i.getFilteredRowModel().rows.length ?? 9999
|
|
332
|
-
) + " / " + (r ?
|
|
335
|
+
) + " / " + (r ? z ?? "missing totalItems" : i.getFilteredRowModel().rows.length) + " " + (x?.rows ?? "Righe") }) }),
|
|
333
336
|
/* @__PURE__ */ h(xe, { children: [
|
|
334
|
-
/* @__PURE__ */ n(
|
|
335
|
-
|
|
337
|
+
/* @__PURE__ */ n(b, { children: /* @__PURE__ */ n(
|
|
338
|
+
we,
|
|
336
339
|
{
|
|
337
340
|
size: "sm",
|
|
338
341
|
isDisabled: !i.getCanPreviousPage(),
|
|
@@ -349,8 +352,8 @@ function Ue({
|
|
|
349
352
|
"aria-label": "Go to first page"
|
|
350
353
|
}
|
|
351
354
|
) }),
|
|
352
|
-
/* @__PURE__ */ n(
|
|
353
|
-
|
|
355
|
+
/* @__PURE__ */ n(b, { children: /* @__PURE__ */ n(
|
|
356
|
+
Ce,
|
|
354
357
|
{
|
|
355
358
|
size: "sm",
|
|
356
359
|
isDisabled: !i.getCanPreviousPage(),
|
|
@@ -358,7 +361,7 @@ function Ue({
|
|
|
358
361
|
onClick: () => {
|
|
359
362
|
if (i.getCanPreviousPage())
|
|
360
363
|
if (c) {
|
|
361
|
-
const e = r?.pagination.pageIndex ??
|
|
364
|
+
const e = r?.pagination.pageIndex ?? w.pageIndex, t = Math.max(e - 1, 0);
|
|
362
365
|
g?.((l) => ({
|
|
363
366
|
...l,
|
|
364
367
|
pagination: {
|
|
@@ -373,12 +376,12 @@ function Ue({
|
|
|
373
376
|
) }),
|
|
374
377
|
(() => {
|
|
375
378
|
const e = i.getState().pagination.pageIndex, t = i.getPageCount(), l = 5;
|
|
376
|
-
let
|
|
379
|
+
let o = Math.max(
|
|
377
380
|
0,
|
|
378
381
|
e - Math.floor(l / 2)
|
|
379
|
-
),
|
|
380
|
-
return
|
|
381
|
-
|
|
382
|
+
), a = o + l;
|
|
383
|
+
return a > t && (a = t, o = Math.max(0, a - l)), i.getPageOptions().slice(o, a).map((s, f) => /* @__PURE__ */ n(b, { children: /* @__PURE__ */ n(
|
|
384
|
+
be,
|
|
382
385
|
{
|
|
383
386
|
size: "icon",
|
|
384
387
|
isActive: e === s,
|
|
@@ -399,7 +402,7 @@ function Ue({
|
|
|
399
402
|
}
|
|
400
403
|
) }, f));
|
|
401
404
|
})(),
|
|
402
|
-
/* @__PURE__ */ n(
|
|
405
|
+
/* @__PURE__ */ n(b, { children: /* @__PURE__ */ n(
|
|
403
406
|
Pe,
|
|
404
407
|
{
|
|
405
408
|
size: "sm",
|
|
@@ -416,7 +419,7 @@ function Ue({
|
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
) }),
|
|
419
|
-
/* @__PURE__ */ n(
|
|
422
|
+
/* @__PURE__ */ n(b, { children: /* @__PURE__ */ n(
|
|
420
423
|
Se,
|
|
421
424
|
{
|
|
422
425
|
size: "sm",
|