laif-ds 0.1.48 → 0.1.49

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.
@@ -1,56 +1,57 @@
1
1
  "use client";
2
2
  import { jsxs as d, jsx as o } from "react/jsx-runtime";
3
- import { useState as f, useEffect as W, useCallback as w, useMemo as O, useRef as De } from "react";
4
- import { useReactTable as Ee, flexRender as ee } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
5
- import { useVirtualizer as $e } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
6
- import { TableSkeleton as je } from "../../table-skeleton.js";
3
+ import { useState as f, useEffect as W, useCallback as w, useMemo as O, useRef as $e } from "react";
4
+ import { useReactTable as je, flexRender as ee } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
5
+ import { useVirtualizer as De } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
6
+ import { TableSkeleton as Ie } from "../../table-skeleton.js";
7
7
  import { TruncatedText as k } from "./truncated-text.js";
8
- import { useDataCrossTable as Ie } from "./data-cross-table-context.js";
8
+ import { useDataCrossTable as Ke } from "./data-cross-table-context.js";
9
+ import { cn as te } from "../../../../lib/utils.js";
9
10
  import { Button as N } from "../../button.js";
10
11
  import { Icon as Y } from "../../icon.js";
11
- import { Popover as Ke, PopoverTrigger as Me, PopoverContent as Ve } from "../../popover.js";
12
- import { TableRow as U, TableCell as te, Table as Re, TableHeader as Le, TableHead as Ae, TableBody as Pe } from "../../table.js";
13
- import { getSortedRowModel as Be, getCoreRowModel as Fe } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
14
- function lt({
15
- crossTableData: D,
16
- filterable: y = !1,
17
- loading: le = !1,
18
- emptyComponent: ne,
19
- className: E,
20
- notFoundMessage: oe = "Nessun risultato trovato.",
21
- cornerHeaderFrom: $ = "Da",
22
- cornerHeaderTo: j = "A",
23
- maxHeaderLength: b = 15,
12
+ import { Popover as Me, PopoverTrigger as Ve, PopoverContent as Re } from "../../popover.js";
13
+ import { TableRow as U, TableCell as le, Table as Le, TableHeader as Ae, TableHead as Pe, TableBody as Be } from "../../table.js";
14
+ import { getSortedRowModel as Fe, getCoreRowModel as Oe } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
15
+ function ot({
16
+ crossTableData: E,
17
+ filterable: b = !1,
18
+ loading: re = !1,
19
+ emptyComponent: oe,
20
+ className: $,
21
+ notFoundMessage: ne = "Nessun risultato trovato.",
22
+ cornerHeaderFrom: j = "Da",
23
+ cornerHeaderTo: D = "A",
24
+ maxHeaderLength: y = 15,
24
25
  minWidthCell: I = 160,
25
- editable: re = !1,
26
- editMode: se = !1,
26
+ editable: se = !1,
27
+ editMode: ie = !1,
27
28
  onEditModeChange: K,
28
29
  onSelectedRow: X,
29
30
  selectedRow: u,
30
- rowSortAsc: ie = !0
31
+ rowSortAsc: ae = !0
31
32
  }) {
32
33
  var J, Q;
33
- const [ae, ce] = f([]), p = D.headerTop, m = D.headerLeft, g = D.data, [C, M] = f(
34
+ const [ce, de] = f([]), p = E.headerTop, m = E.headerLeft, v = E.data, [C, M] = f(
34
35
  (u == null ? void 0 : u.id) ?? null
35
- ), [V, R] = f(ie);
36
+ ), [V, R] = f(ae);
36
37
  let c = null;
37
38
  try {
38
- c = Ie();
39
+ c = Ke();
39
40
  } catch {
40
41
  c = null;
41
42
  }
42
- const [de, Oe] = f(re && se), [ue, fe] = f({}), [me, pe] = f({}), L = (c == null ? void 0 : c.editMode) ?? de, _ = (c == null ? void 0 : c.editedCells) ?? ue, A = (c == null ? void 0 : c.setEditedCells) ?? fe, P = (c == null ? void 0 : c.toDefaultCells) ?? me, B = (c == null ? void 0 : c.setToDefaultCells) ?? pe;
43
+ const [ue, Ye] = f(se && ie), [fe, me] = f({}), [pe, he] = f({}), L = (c == null ? void 0 : c.editMode) ?? ue, _ = (c == null ? void 0 : c.editedCells) ?? fe, A = (c == null ? void 0 : c.setEditedCells) ?? me, P = (c == null ? void 0 : c.toDefaultCells) ?? pe, B = (c == null ? void 0 : c.setToDefaultCells) ?? he;
43
44
  W(() => {
44
45
  K && K(!!L);
45
46
  }, [L, K]), W(() => {
46
47
  u != null && u.id && M(u.id);
47
48
  }, [u]);
48
- const [l, he] = f(null), [ve, x] = f(!1), [S, T] = f(null), ge = w(
49
+ const [l, ge] = f(null), [ve, x] = f(!1), [S, T] = f(null), xe = w(
49
50
  (t) => {
50
51
  t && l && T(l.value), x(t);
51
52
  },
52
53
  [l]
53
- ), xe = w(() => {
54
+ ), be = w(() => {
54
55
  l && S !== null ? (A((t) => ({
55
56
  ...t,
56
57
  [l.cellKey]: {
@@ -71,7 +72,7 @@ function lt({
71
72
  const e = { ...t };
72
73
  return e[l.cellKey] && delete e[l.cellKey], e;
73
74
  })), x(!1);
74
- }, [l]), be = w(() => {
75
+ }, [l]), Ce = w(() => {
75
76
  l && (A((t) => {
76
77
  const e = { ...t };
77
78
  return e[l.cellKey] && delete e[l.cellKey], e;
@@ -82,49 +83,49 @@ function lt({
82
83
  cell: l.cellData
83
84
  }
84
85
  }))), x(!1);
85
- }, [l]), Ce = w(
86
+ }, [l]), we = w(
86
87
  (t) => {
87
88
  T(t.target.value);
88
89
  },
89
90
  []
90
- ), we = (t) => t && typeof t == "object" && "value" in t ? t.value : t, h = O(() => {
91
- if (!C || !m.find((n) => n.id === C)) return p;
91
+ ), Ne = (t) => t && typeof t == "object" && "value" in t ? t.value : t, h = O(() => {
92
+ if (!C || !m.find((r) => r.id === C)) return p;
92
93
  const e = m.findIndex(
93
- (n) => n.id === C
94
+ (r) => r.id === C
94
95
  );
95
96
  if (e === -1) return p;
96
- const r = p.map((n, i) => {
97
- var v;
98
- const s = ((v = g[e]) == null ? void 0 : v[i]) ?? null, a = we(s);
99
- return { header: n, value: a };
97
+ const s = p.map((r, i) => {
98
+ var g;
99
+ const n = ((g = v[e]) == null ? void 0 : g[i]) ?? null, a = Ne(n);
100
+ return { header: r, value: a };
100
101
  });
101
- return r.sort((n, i) => {
102
- if (typeof n.value == "number" && typeof i.value == "number")
103
- return V ? n.value - i.value : i.value - n.value;
104
- const s = String(n.value ?? ""), a = String(i.value ?? "");
105
- return V ? s.localeCompare(a) : a.localeCompare(s);
106
- }), r.map((n) => n.header);
107
- }, [p, m, g, C, V]), Ne = O(() => {
102
+ return s.sort((r, i) => {
103
+ if (typeof r.value == "number" && typeof i.value == "number")
104
+ return V ? r.value - i.value : i.value - r.value;
105
+ const n = String(r.value ?? ""), a = String(i.value ?? "");
106
+ return V ? n.localeCompare(a) : a.localeCompare(n);
107
+ }), s.map((r) => r.header);
108
+ }, [p, m, v, C, V]), Se = O(() => {
108
109
  const t = [
109
110
  {
110
111
  id: "cross-header",
111
112
  header: () => /* @__PURE__ */ d("div", { className: "relative", children: [
112
- /* @__PURE__ */ o("div", { className: "absolute top-0 left-2 text-xs", children: $ }),
113
- /* @__PURE__ */ o("div", { className: "absolute right-2 bottom-0 text-xs", children: j })
113
+ /* @__PURE__ */ o("div", { className: "absolute top-0 left-2 text-xs", children: j }),
114
+ /* @__PURE__ */ o("div", { className: "absolute right-2 bottom-0 text-xs", children: D })
114
115
  ] }),
115
116
  accessorFn: (e) => e.item,
116
117
  cell: (e) => {
117
- const r = e.getValue();
118
- if (!y)
118
+ const s = e.getValue();
119
+ if (!b)
119
120
  return /* @__PURE__ */ o(
120
121
  k,
121
122
  {
122
- text: r.label,
123
- maxLength: b,
123
+ text: s.label,
124
+ maxLength: y,
124
125
  className: "w-full"
125
126
  }
126
127
  );
127
- const n = C === r.id;
128
+ const r = C === s.id;
128
129
  return /* @__PURE__ */ o(
129
130
  N,
130
131
  {
@@ -133,9 +134,9 @@ function lt({
133
134
  iconLeft: "ArrowLeftRight",
134
135
  className: "text-right",
135
136
  onClick: () => {
136
- y && (n ? R((i) => !i) : (M(m[e.row.index].id), R(!0), X && X(m[e.row.index])));
137
+ b && (r ? R((i) => !i) : (M(m[e.row.index].id), R(!0), X && X(m[e.row.index])));
137
138
  },
138
- children: /* @__PURE__ */ o(k, { text: r.label, maxLength: b })
139
+ children: /* @__PURE__ */ o(k, { text: s.label, maxLength: y })
139
140
  }
140
141
  );
141
142
  }
@@ -144,96 +145,96 @@ function lt({
144
145
  return h.forEach((e) => {
145
146
  t.push({
146
147
  id: e.id,
147
- accessorFn: (r) => r[e.id],
148
- header: ({ column: r }) => y ? /* @__PURE__ */ o(
148
+ accessorFn: (s) => s[e.id],
149
+ header: ({ column: s }) => b ? /* @__PURE__ */ o(
149
150
  N,
150
151
  {
151
152
  variant: "ghost",
152
153
  size: "sm",
153
154
  iconLeft: "ArrowUpDown",
154
- onClick: y ? () => r.toggleSorting(r.getIsSorted() === "asc") : void 0,
155
- children: /* @__PURE__ */ o(k, { text: e.label, maxLength: b })
155
+ onClick: b ? () => s.toggleSorting(s.getIsSorted() === "asc") : void 0,
156
+ children: /* @__PURE__ */ o(k, { text: e.label, maxLength: y })
156
157
  }
157
158
  ) : /* @__PURE__ */ o(
158
159
  k,
159
160
  {
160
161
  text: e.label,
161
- maxLength: b,
162
+ maxLength: y,
162
163
  className: "font-medium"
163
164
  }
164
165
  ),
165
- sortingFn: (r, n, i) => {
166
- let s = r.getValue(i), a = n.getValue(i);
167
- return s == null && a == null ? 0 : s == null ? 1 : a == null ? -1 : (s && typeof s == "object" && "value" in s && (s = s.value), a && typeof a == "object" && "value" in a && (a = a.value), typeof s == "number" && typeof a == "number" ? s - a : String(s).localeCompare(String(a)));
166
+ sortingFn: (s, r, i) => {
167
+ let n = s.getValue(i), a = r.getValue(i);
168
+ return n == null && a == null ? 0 : n == null ? 1 : a == null ? -1 : (n && typeof n == "object" && "value" in n && (n = n.value), a && typeof a == "object" && "value" in a && (a = a.value), typeof n == "number" && typeof a == "number" ? n - a : String(n).localeCompare(String(a)));
168
169
  },
169
- cell: (r) => {
170
- const n = r.getValue();
171
- return n ? n.render ? n.render(n.fromId, n.toId, n.id) : /* @__PURE__ */ o("div", { children: n.value }) : null;
170
+ cell: (s) => {
171
+ const r = s.getValue();
172
+ return r ? r.render ? r.render(r.fromId, r.toId, r.id) : /* @__PURE__ */ o("div", { children: r.value }) : null;
172
173
  }
173
174
  });
174
175
  }), t;
175
176
  }, [
176
177
  h,
177
- $,
178
178
  j,
179
+ D,
179
180
  u,
180
- y,
181
181
  b,
182
+ y,
182
183
  M,
183
184
  R
184
- ]), Se = O(() => m.map((t, e) => {
185
- const r = { item: t };
186
- return h.forEach((n) => {
187
- var s;
188
- const i = p.findIndex((a) => a.id === n.id);
189
- r[n.id] = i !== -1 ? ((s = g[e]) == null ? void 0 : s[i]) ?? null : null;
190
- }), r;
191
- }), [m, h, g, p]), F = Ee({
192
- data: Se,
193
- columns: Ne,
194
- state: { sorting: ae },
195
- onSortingChange: ce,
196
- getCoreRowModel: Fe(),
197
- getSortedRowModel: Be()
185
+ ]), Te = O(() => m.map((t, e) => {
186
+ const s = { item: t };
187
+ return h.forEach((r) => {
188
+ var n;
189
+ const i = p.findIndex((a) => a.id === r.id);
190
+ s[r.id] = i !== -1 ? ((n = v[e]) == null ? void 0 : n[i]) ?? null : null;
191
+ }), s;
192
+ }), [m, h, v, p]), F = je({
193
+ data: Te,
194
+ columns: Se,
195
+ state: { sorting: ce },
196
+ onSortingChange: de,
197
+ getCoreRowModel: Oe(),
198
+ getSortedRowModel: Fe()
198
199
  });
199
- if (!g || g.length === 0)
200
- return /* @__PURE__ */ o("div", { className: E, children: /* @__PURE__ */ o(U, { children: /* @__PURE__ */ o(te, { colSpan: h.length + 1, children: ne || oe }) }) });
201
- if (le)
200
+ if (!v || v.length === 0)
201
+ return /* @__PURE__ */ o("div", { className: $, children: /* @__PURE__ */ o(U, { children: /* @__PURE__ */ o(le, { colSpan: h.length + 1, children: oe || ne }) }) });
202
+ if (re)
202
203
  return /* @__PURE__ */ o(
203
- je,
204
+ Ie,
204
205
  {
205
206
  headerRow: h.map((t) => t.label),
206
207
  rowCount: m.length || 5,
207
208
  columnCount: h.length || 5,
208
- className: E,
209
- cornerHeaderFrom: $,
210
- cornerHeaderTo: j
209
+ className: $,
210
+ cornerHeaderFrom: j,
211
+ cornerHeaderTo: D
211
212
  }
212
213
  );
213
- const Te = (t) => {
214
- const e = t.column.id === "cross-header", r = e, n = ["bg-d-secondary"];
215
- e || n.push("border-r"), e && n.push("sticky left-0"), n.push("sticky top-0 z-20"), r ? n.push("z-40") : e && n.push("z-30");
214
+ const ze = (t) => {
215
+ const e = t.column.id === "cross-header", s = e, r = ["bg-d-secondary"];
216
+ e || r.push("border-r"), e && r.push("sticky left-0"), r.push("sticky top-0 z-20"), s ? r.push("z-40") : e && r.push("z-30");
216
217
  let i = "none";
217
218
  return e && (i = "inset -1px 0 0 0 var(--d-border), 0 1px 0 0 var(--d-border)"), {
218
- className: n.join(" "),
219
+ className: r.join(" "),
219
220
  style: { boxShadow: i, width: `${I}px` }
220
221
  };
221
- }, q = De(null), G = $e({
222
+ }, q = $e(null), G = De({
222
223
  count: F.getRowModel().rows.length,
223
224
  getScrollElement: () => q.current,
224
225
  estimateSize: () => 40,
225
226
  overscan: 5,
226
227
  measureElement: typeof window < "u" ? (t) => t.getBoundingClientRect().height : void 0
227
228
  });
228
- return /* @__PURE__ */ d("div", { className: `w-[900px] ${E || ""}`, children: [
229
+ return /* @__PURE__ */ d("div", { className: `${te("w-[900px]", $ || "")}`, children: [
229
230
  /* @__PURE__ */ o(
230
231
  "div",
231
232
  {
232
233
  ref: q,
233
- className: "max-h-[600px] overflow-auto rounded-md border",
234
- children: /* @__PURE__ */ d(Re, { className: "relative w-full table-fixed border-collapse", children: [
234
+ className: "border-d-border h-fit max-h-full min-h-0 overflow-auto rounded-md border",
235
+ children: /* @__PURE__ */ d(Le, { className: "relative w-full table-fixed border-collapse", children: [
235
236
  /* @__PURE__ */ o(
236
- Le,
237
+ Ae,
237
238
  {
238
239
  className: "bg-d-secondary sticky top-0 z-20 w-full",
239
240
  style: { boxShadow: "0 1px 0 0 var(--d-border)" },
@@ -242,12 +243,12 @@ function lt({
242
243
  {
243
244
  className: "bg-d-secondary sticky top-0 z-20",
244
245
  children: t.headers.map((e) => {
245
- const r = Te(e);
246
+ const s = ze(e);
246
247
  return /* @__PURE__ */ o(
247
- Ae,
248
+ Pe,
248
249
  {
249
- className: r.className,
250
- style: r.style,
250
+ className: s.className,
251
+ style: s.style,
251
252
  children: e.isPlaceholder ? null : ee(
252
253
  e.column.columnDef.header,
253
254
  e.getContext()
@@ -262,7 +263,7 @@ function lt({
262
263
  }
263
264
  ),
264
265
  /* @__PURE__ */ o(
265
- Pe,
266
+ Be,
266
267
  {
267
268
  style: {
268
269
  height: `${G.getTotalSize()}px`,
@@ -284,42 +285,43 @@ function lt({
284
285
  height: `${t.size}px`,
285
286
  display: "flex"
286
287
  },
287
- children: e.getVisibleCells().map((r, n) => {
288
- const i = n === 0, s = r.getValue(), a = i ? "var(--d-secondary)" : (s == null ? void 0 : s.color) || "transparent";
288
+ children: e.getVisibleCells().map((s, r) => {
289
+ const i = r === 0, n = s.getValue(), a = i ? "var(--d-secondary)" : (n == null ? void 0 : n.bgColor) || "transparent";
289
290
  return /* @__PURE__ */ o(
290
- te,
291
+ le,
291
292
  {
292
- className: `text-center ${i ? "sticky left-0 z-10" : "border-r"}`,
293
+ className: `${te("border-d-border text-center", i ? "sticky left-0 z-10" : "border-r")}`,
293
294
  style: {
294
295
  boxShadow: i ? "inset -1px 0 0 0 var(--d-border)" : "none",
295
296
  backgroundColor: a,
296
- width: `${I}px`,
297
- flex: i ? "0 0 auto" : `1 0 ${I}px`,
297
+ color: (n == null ? void 0 : n.textColor) || "inherit",
298
+ minWidth: `${I}px`,
299
+ flex: `1 0 ${I}px`,
298
300
  display: "flex",
299
301
  alignItems: "center",
300
302
  justifyContent: "center"
301
303
  },
302
- children: i || !L || !s ? (
304
+ children: i || !L || !n ? (
303
305
  // Rendering normale per la prima colonna o quando non siamo in modalità edit
304
306
  ee(
305
- r.column.columnDef.cell,
306
- r.getContext()
307
+ s.column.columnDef.cell,
308
+ s.getContext()
307
309
  )
308
310
  ) : (
309
311
  // Rendering con cella modificabile
310
312
  (() => {
311
- const v = `${e.index}-${r.column.id}`, z = v in _ ? _[v].value : s.value || "", ze = z !== s.value, Z = v in P;
313
+ const g = `${e.index}-${s.column.id}`, z = g in _ ? _[g].value : n.value || "", ke = z !== n.value, Z = g in P;
312
314
  return /* @__PURE__ */ o(
313
315
  "div",
314
316
  {
315
317
  className: "flex w-full cursor-pointer items-center justify-center",
316
- onClick: (ke) => {
317
- const H = ke.currentTarget.getBoundingClientRect();
318
- he({
319
- cellKey: v,
318
+ onClick: (Ee) => {
319
+ const H = Ee.currentTarget.getBoundingClientRect();
320
+ ge({
321
+ cellKey: g,
320
322
  value: z,
321
- originalValue: s.value || "",
322
- cellData: s,
323
+ originalValue: n.value || "",
324
+ cellData: n,
323
325
  position: {
324
326
  top: H.bottom + window.scrollY + 5,
325
327
  left: H.left + window.scrollX
@@ -328,7 +330,7 @@ function lt({
328
330
  },
329
331
  children: /* @__PURE__ */ d("div", { className: "relative w-full flex-1 items-center justify-center text-center", children: [
330
332
  z || "",
331
- ze && !Z && /* @__PURE__ */ o(
333
+ ke && !Z && /* @__PURE__ */ o(
332
334
  "div",
333
335
  {
334
336
  className: "bg-d-primary absolute top-0 left-0 rounded p-1",
@@ -356,7 +358,7 @@ function lt({
356
358
  })()
357
359
  )
358
360
  },
359
- r.id
361
+ s.id
360
362
  );
361
363
  })
362
364
  },
@@ -368,10 +370,10 @@ function lt({
368
370
  ] })
369
371
  }
370
372
  ),
371
- /* @__PURE__ */ d(Ke, { open: ve, onOpenChange: ge, children: [
372
- /* @__PURE__ */ o(Me, { asChild: !0, children: /* @__PURE__ */ o("div", { style: { display: "none" } }) }),
373
+ /* @__PURE__ */ d(Me, { open: ve, onOpenChange: xe, children: [
374
+ /* @__PURE__ */ o(Ve, { asChild: !0, children: /* @__PURE__ */ o("div", { style: { display: "none" } }) }),
373
375
  /* @__PURE__ */ o(
374
- Ve,
376
+ Re,
375
377
  {
376
378
  className: "w-[400px] p-4",
377
379
  style: {
@@ -391,7 +393,7 @@ function lt({
391
393
  type: "text",
392
394
  className: "bg-d-secondary w-full rounded border p-2",
393
395
  value: S || "",
394
- onChange: Ce,
396
+ onChange: we,
395
397
  autoFocus: !0
396
398
  }
397
399
  ),
@@ -401,7 +403,7 @@ function lt({
401
403
  {
402
404
  variant: "destructive",
403
405
  size: "sm",
404
- onClick: be,
406
+ onClick: Ce,
405
407
  className: "text-xs",
406
408
  title: "Ripristina il valore originale e segna la cella come da ripristinare",
407
409
  children: [
@@ -426,7 +428,7 @@ function lt({
426
428
  N,
427
429
  {
428
430
  size: "sm",
429
- onClick: xe,
431
+ onClick: be,
430
432
  className: "text-xs",
431
433
  title: "Conferma le modifiche e salva",
432
434
  children: [
@@ -444,5 +446,5 @@ function lt({
444
446
  ] });
445
447
  }
446
448
  export {
447
- lt as DataCrossTable
449
+ ot as DataCrossTable
448
450
  };
package/dist/index.d.ts CHANGED
@@ -566,7 +566,8 @@ declare type CopyButtonProps = {
566
566
  export declare interface CrossTableCell {
567
567
  render?: (fromId: string, toId: string, id?: string) => ReactNode;
568
568
  value?: number | string | null;
569
- color?: string;
569
+ bgColor?: string;
570
+ textColor?: string;
570
571
  fromId: string;
571
572
  toId: string;
572
573
  id?: string;