laif-ds 0.1.37 → 0.1.39

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,6 +1,3 @@
1
1
  "use client";
2
- import { __require as r } from "../node_modules/use-sync-external-store/shim/index.js";
3
- var i = r();
4
- export {
5
- i as s
6
- };
2
+ import { __require as e } from "../node_modules/react-is/index.js";
3
+ e();
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- var e = { exports: {} };
2
+ import { __require as r } from "../node_modules/use-sync-external-store/shim/index.js";
3
+ var i = r();
3
4
  export {
4
- e as __module
5
+ i as s
5
6
  };
@@ -1,3 +1,5 @@
1
1
  "use client";
2
- import { __require as e } from "../node_modules/react-is/index.js";
3
- e();
2
+ var e = { exports: {} };
3
+ export {
4
+ e as __module
5
+ };
@@ -1,329 +1,409 @@
1
1
  "use client";
2
- import { jsxs as O, jsx as i } from "react/jsx-runtime";
3
- import { useState as g, useEffect as Y, useMemo as B, useRef as ce } from "react";
4
- import { useReactTable as fe, flexRender as q } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
5
- import { useVirtualizer as me } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
6
- import { TableSkeleton as pe } from "../../table-skeleton.js";
7
- import { TruncatedText as I } from "./truncated-text.js";
8
- import { EditControls as ge } from "./edit-controls.js";
9
- import { EditableInput as he } from "./editable-input.js";
10
- import { Button as G } from "../../button.js";
11
- import { TableRow as F, TableCell as J, Table as xe, TableHeader as be, TableHead as ve, TableBody as ye } from "../../table.js";
12
- import { getSortedRowModel as Ce, getCoreRowModel as Se } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
13
- function De({
14
- crossTableData: N,
15
- filterable: h = !1,
16
- loading: Q = !1,
17
- emptyComponent: X,
18
- className: z,
19
- notFoundMessage: Z = "Nessun risultato trovato.",
20
- cornerHeaderFrom: T = "Da",
21
- cornerHeaderTo: j = "A",
22
- maxHeaderLength: x = 15,
23
- minWidthCell: k = 160,
24
- editable: V = !1,
25
- editMode: H = !1,
26
- editConfirmLabel: W = "Conferma",
27
- editCancelLabel: ee = "Annulla",
28
- onConfirmedCells: R,
29
- onEditModeChange: E,
30
- onSelectedRow: _,
31
- selectedRow: a,
32
- rowSortAsc: te = !0
2
+ import { jsxs as c, jsx as o } from "react/jsx-runtime";
3
+ import { useState as u, useEffect as ee, useCallback as I, useMemo as Y, useRef as ke } from "react";
4
+ import { useReactTable as Ve, flexRender as te } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
5
+ import { useVirtualizer as je } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
6
+ import { TableSkeleton as ze } from "../../table-skeleton.js";
7
+ import { TruncatedText as R } from "./truncated-text.js";
8
+ import { EditControls as Te } from "./edit-controls.js";
9
+ import { Icon as U } from "../../icon.js";
10
+ import { Popover as De, PopoverTrigger as Re, PopoverContent as $e } from "../../popover.js";
11
+ import { Button as k } from "../../button.js";
12
+ import { TableRow as X, TableCell as le, Table as Ae, TableHeader as Ke, TableHead as Me, TableBody as Ee } from "../../table.js";
13
+ import { getSortedRowModel as Oe, getCoreRowModel as Le } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
14
+ function We({
15
+ crossTableData: $,
16
+ filterable: b = !1,
17
+ loading: ne = !1,
18
+ emptyComponent: oe,
19
+ className: A,
20
+ notFoundMessage: re = "Nessun risultato trovato.",
21
+ cornerHeaderFrom: K = "Da",
22
+ cornerHeaderTo: M = "A",
23
+ maxHeaderLength: C = 15,
24
+ minWidthCell: E = 160,
25
+ editable: O = !1,
26
+ editMode: se = !1,
27
+ editConfirmLabel: ie = "Conferma",
28
+ editCancelLabel: ae = "Annulla",
29
+ onConfirmedCells: V,
30
+ onEditModeChange: L,
31
+ onSelectedRow: q,
32
+ selectedRow: d,
33
+ rowSortAsc: ce = !0
33
34
  }) {
34
- const [re, oe] = g([]), u = N.headerTop, d = N.headerLeft, f = N.data, [b, $] = g(
35
- (a == null ? void 0 : a.id) ?? null
36
- ), [A, M] = g(te), [S, ne] = g(V && H);
37
- Y(() => {
38
- E && E(!!S);
39
- }, [S, E]), Y(() => {
40
- a != null && a.id && $(a.id);
41
- }, [a]);
42
- const [v, w] = g({}), [K, D] = g({}), le = (l) => l && typeof l == "object" && "value" in l ? l.value : l, c = B(() => {
43
- if (!b || !d.find((e) => e.id === b)) return u;
44
- const t = d.findIndex(
45
- (e) => e.id === b
35
+ var Q, Z;
36
+ const [de, ue] = u([]), m = $.headerTop, f = $.headerLeft, v = $.data, [w, P] = u(
37
+ (d == null ? void 0 : d.id) ?? null
38
+ ), [B, F] = u(ce), [j, fe] = u(O && se);
39
+ ee(() => {
40
+ L && L(!!j);
41
+ }, [j, L]), ee(() => {
42
+ d != null && d.id && P(d.id);
43
+ }, [d]);
44
+ const [N, S] = u({}), [p, x] = u({}), [l, me] = u(null), [pe, y] = u(!1), [z, T] = u(null), he = I(
45
+ (t) => {
46
+ t && l && T(l.value), y(t);
47
+ },
48
+ [l]
49
+ ), ge = I(() => {
50
+ l && z !== null ? (S((t) => ({
51
+ ...t,
52
+ [l.cellKey]: {
53
+ value: z,
54
+ cell: l.cellData
55
+ }
56
+ })), p[l.cellKey] && x((t) => {
57
+ const e = { ...t };
58
+ return delete e[l.cellKey], e;
59
+ }), setTimeout(() => {
60
+ y(!1);
61
+ }, 300)) : y(!1);
62
+ }, [l, z, p]), ve = I(() => {
63
+ l && (T(l.originalValue), S((t) => {
64
+ const e = { ...t };
65
+ return e[l.cellKey] && delete e[l.cellKey], e;
66
+ }), x((t) => {
67
+ const e = { ...t };
68
+ return e[l.cellKey] && delete e[l.cellKey], e;
69
+ })), y(!1);
70
+ }, [l]), xe = I(() => {
71
+ l && (S((t) => {
72
+ const e = { ...t };
73
+ return e[l.cellKey] && delete e[l.cellKey], e;
74
+ }), x((t) => ({
75
+ ...t,
76
+ [l.cellKey]: {
77
+ value: l.originalValue,
78
+ cell: l.cellData
79
+ }
80
+ }))), y(!1);
81
+ }, [l]), ye = I(
82
+ (t) => {
83
+ T(t.target.value);
84
+ },
85
+ []
86
+ ), be = (t) => t && typeof t == "object" && "value" in t ? t.value : t, h = Y(() => {
87
+ if (!w || !f.find((n) => n.id === w)) return m;
88
+ const e = f.findIndex(
89
+ (n) => n.id === w
46
90
  );
47
- if (t === -1) return u;
48
- const r = u.map((e, s) => {
49
- var m;
50
- const o = ((m = f[t]) == null ? void 0 : m[s]) ?? null, n = le(o);
51
- return { header: e, value: n };
91
+ if (e === -1) return m;
92
+ const r = m.map((n, i) => {
93
+ var g;
94
+ const s = ((g = v[e]) == null ? void 0 : g[i]) ?? null, a = be(s);
95
+ return { header: n, value: a };
52
96
  });
53
- return r.sort((e, s) => {
54
- if (typeof e.value == "number" && typeof s.value == "number")
55
- return A ? e.value - s.value : s.value - e.value;
56
- const o = String(e.value ?? ""), n = String(s.value ?? "");
57
- return A ? o.localeCompare(n) : n.localeCompare(o);
58
- }), r.map((e) => e.header);
59
- }, [u, d, f, b, A]), se = B(() => {
60
- const l = [
97
+ return r.sort((n, i) => {
98
+ if (typeof n.value == "number" && typeof i.value == "number")
99
+ return B ? n.value - i.value : i.value - n.value;
100
+ const s = String(n.value ?? ""), a = String(i.value ?? "");
101
+ return B ? s.localeCompare(a) : a.localeCompare(s);
102
+ }), r.map((n) => n.header);
103
+ }, [m, f, v, w, B]), Ce = Y(() => {
104
+ const t = [
61
105
  {
62
106
  id: "cross-header",
63
- header: () => /* @__PURE__ */ O("div", { className: "relative", children: [
64
- /* @__PURE__ */ i("div", { className: "absolute top-0 left-2 text-xs", children: T }),
65
- /* @__PURE__ */ i("div", { className: "absolute right-2 bottom-0 text-xs", children: j })
107
+ header: () => /* @__PURE__ */ c("div", { className: "relative", children: [
108
+ /* @__PURE__ */ o("div", { className: "absolute top-0 left-2 text-xs", children: K }),
109
+ /* @__PURE__ */ o("div", { className: "absolute right-2 bottom-0 text-xs", children: M })
66
110
  ] }),
67
- accessorFn: (t) => t.item,
68
- cell: (t) => {
69
- const r = t.getValue();
70
- if (!h)
71
- return /* @__PURE__ */ i(
72
- I,
111
+ accessorFn: (e) => e.item,
112
+ cell: (e) => {
113
+ const r = e.getValue();
114
+ if (!b)
115
+ return /* @__PURE__ */ o(
116
+ R,
73
117
  {
74
118
  text: r.label,
75
- maxLength: x,
119
+ maxLength: C,
76
120
  className: "w-full"
77
121
  }
78
122
  );
79
- const e = b === r.id;
80
- return /* @__PURE__ */ i(
81
- G,
123
+ const n = w === r.id;
124
+ return /* @__PURE__ */ o(
125
+ k,
82
126
  {
83
127
  variant: "ghost",
84
128
  size: "sm",
85
129
  iconLeft: "ArrowLeftRight",
86
130
  className: "text-right",
87
131
  onClick: () => {
88
- h && (e ? M((s) => !s) : ($(d[t.row.index].id), M(!0), _ && _(d[t.row.index])));
132
+ b && (n ? F((i) => !i) : (P(f[e.row.index].id), F(!0), q && q(f[e.row.index])));
89
133
  },
90
- children: /* @__PURE__ */ i(I, { text: r.label, maxLength: x })
134
+ children: /* @__PURE__ */ o(R, { text: r.label, maxLength: C })
91
135
  }
92
136
  );
93
137
  }
94
138
  }
95
139
  ];
96
- return c.forEach((t) => {
97
- l.push({
98
- id: t.id,
99
- accessorFn: (r) => r[t.id],
100
- header: ({ column: r }) => h ? /* @__PURE__ */ i(
101
- G,
140
+ return h.forEach((e) => {
141
+ t.push({
142
+ id: e.id,
143
+ accessorFn: (r) => r[e.id],
144
+ header: ({ column: r }) => b ? /* @__PURE__ */ o(
145
+ k,
102
146
  {
103
147
  variant: "ghost",
104
148
  size: "sm",
105
149
  iconLeft: "ArrowUpDown",
106
- onClick: h ? () => r.toggleSorting(r.getIsSorted() === "asc") : void 0,
107
- children: /* @__PURE__ */ i(I, { text: t.label, maxLength: x })
150
+ onClick: b ? () => r.toggleSorting(r.getIsSorted() === "asc") : void 0,
151
+ children: /* @__PURE__ */ o(R, { text: e.label, maxLength: C })
108
152
  }
109
- ) : /* @__PURE__ */ i(
110
- I,
153
+ ) : /* @__PURE__ */ o(
154
+ R,
111
155
  {
112
- text: t.label,
113
- maxLength: x,
156
+ text: e.label,
157
+ maxLength: C,
114
158
  className: "font-medium"
115
159
  }
116
160
  ),
117
- sortingFn: (r, e, s) => {
118
- let o = r.getValue(s), n = e.getValue(s);
119
- return o == null && n == null ? 0 : o == null ? 1 : n == null ? -1 : (o && typeof o == "object" && "value" in o && (o = o.value), n && typeof n == "object" && "value" in n && (n = n.value), typeof o == "number" && typeof n == "number" ? o - n : String(o).localeCompare(String(n)));
161
+ sortingFn: (r, n, i) => {
162
+ let s = r.getValue(i), a = n.getValue(i);
163
+ 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)));
120
164
  },
121
165
  cell: (r) => {
122
- const e = r.getValue();
123
- return e ? e.render ? e.render(e.fromId, e.toId, e.id) : /* @__PURE__ */ i("div", { children: e.value }) : null;
166
+ const n = r.getValue();
167
+ return n ? n.render ? n.render(n.fromId, n.toId, n.id) : /* @__PURE__ */ o("div", { children: n.value }) : null;
124
168
  }
125
169
  });
126
- }), l;
170
+ }), t;
127
171
  }, [
128
- c,
129
- T,
130
- j,
131
- a,
132
172
  h,
133
- x,
134
- $,
135
- M
136
- ]), ie = B(() => d.map((l, t) => {
137
- const r = { item: l };
138
- return c.forEach((e) => {
139
- var o;
140
- const s = u.findIndex((n) => n.id === e.id);
141
- r[e.id] = s !== -1 ? ((o = f[t]) == null ? void 0 : o[s]) ?? null : null;
173
+ K,
174
+ M,
175
+ d,
176
+ b,
177
+ C,
178
+ P,
179
+ F
180
+ ]), we = Y(() => f.map((t, e) => {
181
+ const r = { item: t };
182
+ return h.forEach((n) => {
183
+ var s;
184
+ const i = m.findIndex((a) => a.id === n.id);
185
+ r[n.id] = i !== -1 ? ((s = v[e]) == null ? void 0 : s[i]) ?? null : null;
142
186
  }), r;
143
- }), [d, c, f, u]), L = fe({
144
- data: ie,
145
- columns: se,
146
- state: { sorting: re },
147
- onSortingChange: oe,
148
- getCoreRowModel: Se(),
149
- getSortedRowModel: Ce()
187
+ }), [f, h, v, m]), _ = Ve({
188
+ data: we,
189
+ columns: Ce,
190
+ state: { sorting: de },
191
+ onSortingChange: ue,
192
+ getCoreRowModel: Le(),
193
+ getSortedRowModel: Oe()
150
194
  });
151
- if (!f || f.length === 0)
152
- return /* @__PURE__ */ i("div", { className: z, children: /* @__PURE__ */ i(F, { children: /* @__PURE__ */ i(J, { colSpan: c.length + 1, children: X || Z }) }) });
153
- if (Q)
154
- return /* @__PURE__ */ i(
155
- pe,
195
+ if (!v || v.length === 0)
196
+ return /* @__PURE__ */ o("div", { className: A, children: /* @__PURE__ */ o(X, { children: /* @__PURE__ */ o(le, { colSpan: h.length + 1, children: oe || re }) }) });
197
+ if (ne)
198
+ return /* @__PURE__ */ o(
199
+ ze,
156
200
  {
157
- headerRow: c.map((l) => l.label),
158
- rowCount: d.length || 5,
159
- columnCount: c.length || 5,
160
- className: z,
161
- cornerHeaderFrom: T,
162
- cornerHeaderTo: j
201
+ headerRow: h.map((t) => t.label),
202
+ rowCount: f.length || 5,
203
+ columnCount: h.length || 5,
204
+ className: A,
205
+ cornerHeaderFrom: K,
206
+ cornerHeaderTo: M
163
207
  }
164
208
  );
165
- const ae = (l) => {
166
- const t = l.column.id === "cross-header", r = t, e = ["bg-d-secondary"];
167
- t || e.push("border-r"), t && e.push("sticky left-0"), e.push("sticky top-0 z-20"), r ? e.push("z-40") : t && e.push("z-30");
168
- let s = "none";
169
- return t && (s = "inset -1px 0 0 0 var(--d-border), 0 1px 0 0 var(--d-border)"), {
170
- className: e.join(" "),
171
- style: { boxShadow: s, width: `${k}px` }
209
+ const Ne = (t) => {
210
+ const e = t.column.id === "cross-header", r = e, n = ["bg-d-secondary"];
211
+ 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");
212
+ let i = "none";
213
+ return e && (i = "inset -1px 0 0 0 var(--d-border), 0 1px 0 0 var(--d-border)"), {
214
+ className: n.join(" "),
215
+ style: { boxShadow: i, width: `${E}px` }
172
216
  };
173
- }, P = ce(null), U = me({
174
- count: L.getRowModel().rows.length,
175
- getScrollElement: () => P.current,
217
+ }, G = ke(null), J = je({
218
+ count: _.getRowModel().rows.length,
219
+ getScrollElement: () => G.current,
176
220
  estimateSize: () => 40,
177
221
  overscan: 5,
178
- measureElement: typeof window < "u" ? (l) => l.getBoundingClientRect().height : void 0
222
+ measureElement: typeof window < "u" ? (t) => t.getBoundingClientRect().height : void 0
179
223
  });
180
- return /* @__PURE__ */ O("div", { className: `w-[900px] ${z || ""}`, children: [
181
- V && /* @__PURE__ */ i(
182
- ge,
224
+ return /* @__PURE__ */ c("div", { className: `w-[900px] ${A || ""}`, children: [
225
+ O && /* @__PURE__ */ o(
226
+ Te,
183
227
  {
184
- editable: V,
185
- editConfirmLabel: W,
186
- editCancelLabel: ee,
187
- editMode: S,
188
- setEditMode: ne,
189
- editedCount: Object.keys(v).length,
228
+ editable: O,
229
+ editConfirmLabel: ie,
230
+ editCancelLabel: ae,
231
+ editRestoreDefaultLabel: "Ripristina Default",
232
+ editMode: j,
233
+ setEditMode: fe,
234
+ editedCount: Object.keys(N).length,
235
+ defaultCount: Object.keys(p).length,
236
+ restoreDefault: () => {
237
+ if (V) {
238
+ const t = Object.entries(p).map(
239
+ ([r, { value: n, cell: i }]) => ({
240
+ fromId: i.fromId,
241
+ toId: i.toId,
242
+ id: i.id,
243
+ value: n
244
+ })
245
+ );
246
+ V({
247
+ editedCells: [],
248
+ toDefaultCells: t
249
+ });
250
+ }
251
+ x({});
252
+ },
190
253
  confirmAll: () => {
191
- if (R && (Object.keys(v).length > 0 || Object.keys(K).length > 0)) {
192
- const t = Object.entries(v).map(
193
- ([s, { value: o, cell: n }]) => ({
194
- fromId: n.fromId,
195
- toId: n.toId,
196
- id: n.id,
197
- value: o
254
+ if (V && (Object.keys(N).length > 0 || Object.keys(p).length > 0)) {
255
+ const e = Object.entries(N).map(
256
+ ([i, { value: s, cell: a }]) => ({
257
+ fromId: a.fromId,
258
+ toId: a.toId,
259
+ id: a.id,
260
+ value: s
198
261
  })
199
- ), r = Object.entries(K).map(
200
- ([s, { value: o, cell: n }]) => ({
201
- fromId: n.fromId,
202
- toId: n.toId,
203
- id: n.id,
204
- value: o
262
+ ), r = Object.entries(p).map(
263
+ ([i, { value: s, cell: a }]) => ({
264
+ fromId: a.fromId,
265
+ toId: a.toId,
266
+ id: a.id,
267
+ value: s
205
268
  })
206
269
  );
207
- R({
208
- editedCells: t,
270
+ V({
271
+ editedCells: e,
209
272
  toDefaultCells: r
210
273
  });
211
274
  }
212
- w({}), D({});
275
+ S({}), x({});
213
276
  },
214
277
  cancelAll: () => {
215
- w({}), D({});
278
+ S({}), x({});
216
279
  }
217
280
  }
218
281
  ),
219
- /* @__PURE__ */ i(
282
+ /* @__PURE__ */ o(
220
283
  "div",
221
284
  {
222
- ref: P,
285
+ ref: G,
223
286
  className: "max-h-[600px] overflow-auto rounded-md border",
224
- children: /* @__PURE__ */ O(xe, { className: "relative w-full table-fixed border-collapse", children: [
225
- /* @__PURE__ */ i(
226
- be,
287
+ children: /* @__PURE__ */ c(Ae, { className: "relative w-full table-fixed border-collapse", children: [
288
+ /* @__PURE__ */ o(
289
+ Ke,
227
290
  {
228
291
  className: "bg-d-secondary sticky top-0 z-20",
229
292
  style: { boxShadow: "0 1px 0 0 var(--d-border)" },
230
- children: L.getHeaderGroups().map((l) => /* @__PURE__ */ i(
231
- F,
293
+ children: _.getHeaderGroups().map((t) => /* @__PURE__ */ o(
294
+ X,
232
295
  {
233
296
  className: "bg-d-secondary sticky top-0 z-20",
234
- children: l.headers.map((t) => {
235
- const r = ae(t);
236
- return /* @__PURE__ */ i(
237
- ve,
297
+ children: t.headers.map((e) => {
298
+ const r = Ne(e);
299
+ return /* @__PURE__ */ o(
300
+ Me,
238
301
  {
239
302
  className: r.className,
240
303
  style: r.style,
241
- children: t.isPlaceholder ? null : q(
242
- t.column.columnDef.header,
243
- t.getContext()
304
+ children: e.isPlaceholder ? null : te(
305
+ e.column.columnDef.header,
306
+ e.getContext()
244
307
  )
245
308
  },
246
- t.id
309
+ e.id
247
310
  );
248
311
  })
249
312
  },
250
- l.id
313
+ t.id
251
314
  ))
252
315
  }
253
316
  ),
254
- /* @__PURE__ */ i(
255
- ye,
317
+ /* @__PURE__ */ o(
318
+ Ee,
256
319
  {
257
320
  style: {
258
- height: `${U.getTotalSize()}px`,
321
+ height: `${J.getTotalSize()}px`,
259
322
  position: "relative",
260
323
  width: "100%"
261
324
  },
262
- children: U.getVirtualItems().map((l) => {
263
- const t = L.getRowModel().rows[l.index];
264
- return /* @__PURE__ */ i(
265
- F,
325
+ children: J.getVirtualItems().map((t) => {
326
+ const e = _.getRowModel().rows[t.index];
327
+ return /* @__PURE__ */ o(
328
+ X,
266
329
  {
267
- "data-index": l.index,
330
+ "data-index": t.index,
268
331
  style: {
269
332
  position: "absolute",
270
333
  top: 0,
271
334
  left: 0,
272
- transform: `translateY(${l.start}px)`,
335
+ transform: `translateY(${t.start}px)`,
273
336
  width: "100%",
274
- height: `${l.size}px`,
337
+ height: `${t.size}px`,
275
338
  display: "flex"
276
339
  },
277
- children: t.getVisibleCells().map((r, e) => {
278
- const s = e === 0, o = r.getValue(), n = s ? "var(--d-secondary)" : (o == null ? void 0 : o.color) || "transparent";
279
- return /* @__PURE__ */ i(
280
- J,
340
+ children: e.getVisibleCells().map((r, n) => {
341
+ const i = n === 0, s = r.getValue(), a = i ? "var(--d-secondary)" : (s == null ? void 0 : s.color) || "transparent";
342
+ return /* @__PURE__ */ o(
343
+ le,
281
344
  {
282
- className: `text-center ${s ? "sticky left-0 z-10" : "border-r"}`,
345
+ className: `text-center ${i ? "sticky left-0 z-10" : "border-r"}`,
283
346
  style: {
284
- boxShadow: s ? "inset -1px 0 0 0 var(--d-border)" : "none",
285
- backgroundColor: n,
286
- width: `${k}px`,
287
- flex: s ? "0 0 auto" : `1 0 ${k}px`,
347
+ boxShadow: i ? "inset -1px 0 0 0 var(--d-border)" : "none",
348
+ backgroundColor: a,
349
+ width: `${E}px`,
350
+ flex: i ? "0 0 auto" : `1 0 ${E}px`,
288
351
  display: "flex",
289
352
  alignItems: "center",
290
353
  justifyContent: "center"
291
354
  },
292
- children: s || !S || !o ? (
355
+ children: i || !j || !s ? (
293
356
  // Rendering normale per la prima colonna o quando non siamo in modalità edit
294
- q(
357
+ te(
295
358
  r.column.columnDef.cell,
296
359
  r.getContext()
297
360
  )
298
361
  ) : (
299
- // Rendering con EditableInput per le celle modificabili
362
+ // Rendering con cella modificabile
300
363
  (() => {
301
- const m = `${t.index}-${r.column.id}`, de = m in v ? v[m].value : o.value || "";
302
- return /* @__PURE__ */ i(
303
- he,
364
+ const g = `${e.index}-${r.column.id}`, D = g in N ? N[g].value : s.value || "", Se = D !== s.value, H = g in p;
365
+ return /* @__PURE__ */ o(
366
+ "div",
304
367
  {
305
- value: de,
306
- originalValue: o.value || "",
307
- cellKey: m,
308
- cellData: o,
309
- onChange: (y, C) => {
310
- w((p) => ({
311
- ...p,
312
- [y]: { value: C, cell: o }
313
- }));
314
- },
315
- resetCell: (y) => {
316
- w((C) => {
317
- const p = { ...C };
318
- return delete p[y], p;
319
- });
368
+ className: "flex w-full cursor-pointer items-center justify-center",
369
+ onClick: (Ie) => {
370
+ const W = Ie.currentTarget.getBoundingClientRect();
371
+ me({
372
+ cellKey: g,
373
+ value: D,
374
+ originalValue: s.value || "",
375
+ cellData: s,
376
+ position: {
377
+ top: W.bottom + window.scrollY + 5,
378
+ left: W.left + window.scrollX
379
+ }
380
+ }), T(D), y(!0);
320
381
  },
321
- resetToDefault: (y, C, p) => {
322
- D((ue) => ({
323
- ...ue,
324
- [y]: { value: C, cell: p }
325
- }));
326
- }
382
+ children: /* @__PURE__ */ c("div", { className: "relative w-full flex-1 items-center justify-center text-center", children: [
383
+ D || "",
384
+ Se && !H && /* @__PURE__ */ o(
385
+ "div",
386
+ {
387
+ className: "bg-d-primary absolute top-0 left-0 rounded p-1",
388
+ title: "Valore modificato"
389
+ }
390
+ ),
391
+ H && /* @__PURE__ */ o(
392
+ "div",
393
+ {
394
+ className: "bg-d-destructive absolute top-0 right-0 rounded p-1",
395
+ title: "Ripristino richiesto"
396
+ }
397
+ ),
398
+ /* @__PURE__ */ o("span", { className: "text-d-muted-foreground ml-1 inline-flex items-center", children: /* @__PURE__ */ o(
399
+ U,
400
+ {
401
+ name: "Pencil",
402
+ size: "sm",
403
+ className: "h-3 w-3"
404
+ }
405
+ ) })
406
+ ] })
327
407
  }
328
408
  );
329
409
  })()
@@ -333,16 +413,89 @@ function De({
333
413
  );
334
414
  })
335
415
  },
336
- t.id
416
+ e.id
337
417
  );
338
418
  })
339
419
  }
340
420
  )
341
421
  ] })
342
422
  }
343
- )
423
+ ),
424
+ /* @__PURE__ */ c(De, { open: pe, onOpenChange: he, children: [
425
+ /* @__PURE__ */ o(Re, { asChild: !0, children: /* @__PURE__ */ o("div", { style: { display: "none" } }) }),
426
+ /* @__PURE__ */ o(
427
+ $e,
428
+ {
429
+ className: "w-[400px] p-4",
430
+ style: {
431
+ position: l != null && l.position ? "absolute" : "fixed",
432
+ top: (Q = l == null ? void 0 : l.position) != null && Q.top ? `${l.position.top}px` : "50%",
433
+ left: (Z = l == null ? void 0 : l.position) != null && Z.left ? `${l.position.left}px` : "50%",
434
+ transform: l != null && l.position ? "none" : "translate(-50%, -50%)"
435
+ },
436
+ children: /* @__PURE__ */ c("div", { className: "space-y-4", children: [
437
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between", children: [
438
+ /* @__PURE__ */ o("div", { className: "font-medium", children: "Modifica valore" }),
439
+ l && l.value !== l.originalValue && /* @__PURE__ */ o("div", { className: "text-d-muted-foreground text-xs", children: "Valore modificato" })
440
+ ] }),
441
+ /* @__PURE__ */ o(
442
+ "input",
443
+ {
444
+ type: "text",
445
+ className: "bg-d-secondary w-full rounded border p-2",
446
+ value: z || "",
447
+ onChange: ye,
448
+ autoFocus: !0
449
+ }
450
+ ),
451
+ /* @__PURE__ */ c("div", { className: "flex items-center justify-between", children: [
452
+ /* @__PURE__ */ c(
453
+ k,
454
+ {
455
+ variant: "destructive",
456
+ size: "sm",
457
+ onClick: xe,
458
+ className: "text-xs",
459
+ title: "Ripristina il valore originale e segna la cella come da ripristinare",
460
+ children: [
461
+ /* @__PURE__ */ o(U, { name: "RotateCcw", className: "mr-1 h-3 w-3" }),
462
+ "Ripristina"
463
+ ]
464
+ }
465
+ ),
466
+ /* @__PURE__ */ c("div", { className: "flex space-x-2", children: [
467
+ /* @__PURE__ */ o(
468
+ k,
469
+ {
470
+ variant: "ghost",
471
+ size: "sm",
472
+ onClick: ve,
473
+ className: "text-xs",
474
+ title: "Annulla le modifiche correnti e chiudi",
475
+ children: "Annulla"
476
+ }
477
+ ),
478
+ /* @__PURE__ */ c(
479
+ k,
480
+ {
481
+ size: "sm",
482
+ onClick: ge,
483
+ className: "text-xs",
484
+ title: "Conferma le modifiche e salva",
485
+ children: [
486
+ /* @__PURE__ */ o(U, { name: "Check", className: "mr-1 h-3 w-3" }),
487
+ "Conferma"
488
+ ]
489
+ }
490
+ )
491
+ ] })
492
+ ] })
493
+ ] })
494
+ }
495
+ )
496
+ ] })
344
497
  ] });
345
498
  }
346
499
  export {
347
- De as DataCrossTable
500
+ We as DataCrossTable
348
501
  };
@@ -1,47 +1,38 @@
1
1
  "use client";
2
- import { jsxs as o, jsx as r, Fragment as h } from "react/jsx-runtime";
3
- import { memo as l } from "react";
4
- import { Switch as u } from "../../switch.js";
5
- import { Button as m } from "../../button.js";
6
- const f = l(
7
- ({
8
- onClick: e,
9
- label: t,
10
- count: n
11
- }) => /* @__PURE__ */ o(m, { size: "sm", onClick: e, children: [
12
- t,
13
- " ",
14
- n > 0 && `(${n})`
15
- ] })
16
- ), p = l(
17
- ({ onClick: e, label: t }) => /* @__PURE__ */ r(m, { variant: "ghost", size: "sm", onClick: e, children: t })
18
- );
19
- function k({
20
- editConfirmLabel: e,
21
- editCancelLabel: t,
22
- editMode: n,
23
- setEditMode: c,
24
- editedCount: i,
25
- confirmAll: s,
26
- cancelAll: a,
27
- editable: d
2
+ import { jsxs as r, jsx as c, Fragment as l } from "react/jsx-runtime";
3
+ import { Switch as x } from "../../switch.js";
4
+ import { Button as n } from "../../button.js";
5
+ function z({
6
+ editConfirmLabel: t,
7
+ editCancelLabel: o,
8
+ editRestoreDefaultLabel: h = "Restore Default",
9
+ editMode: s,
10
+ setEditMode: a,
11
+ editedCount: e,
12
+ defaultCount: i = 0,
13
+ confirmAll: d,
14
+ cancelAll: k,
15
+ restoreDefault: m,
16
+ editable: p
28
17
  }) {
29
- return d ? /* @__PURE__ */ o("div", { className: "mb-2 flex items-center gap-2", children: [
30
- /* @__PURE__ */ r(u, { id: "edit-mode", checked: n, onCheckedChange: c }),
31
- /* @__PURE__ */ r("label", { htmlFor: "edit-mode", className: "text-sm select-none", children: "Edit mode" }),
32
- n && i > 0 && /* @__PURE__ */ o(h, { children: [
33
- /* @__PURE__ */ r(
34
- f,
35
- {
36
- onClick: s,
37
- label: e,
38
- count: i
39
- }
40
- ),
41
- /* @__PURE__ */ r(p, { onClick: a, label: t })
18
+ return p ? /* @__PURE__ */ r("div", { className: "mb-2 flex items-center gap-2", children: [
19
+ /* @__PURE__ */ c(x, { id: "edit-mode", checked: s, onCheckedChange: a }),
20
+ /* @__PURE__ */ c("label", { htmlFor: "edit-mode", className: "text-sm select-none", children: "Edit mode" }),
21
+ s && /* @__PURE__ */ r(l, { children: [
22
+ e > 0 && /* @__PURE__ */ c(l, { children: /* @__PURE__ */ r(n, { size: "sm", onClick: d, children: [
23
+ t,
24
+ " ",
25
+ e > 0 && `(${e})`
26
+ ] }) }),
27
+ i > 0 && m && /* @__PURE__ */ r(n, { size: "sm", onClick: m, variant: "destructive", children: [
28
+ h,
29
+ " ",
30
+ i > 0 && `(${i})`
31
+ ] }),
32
+ (e > 0 || i > 0) && /* @__PURE__ */ c(n, { size: "sm", variant: "ghost", onClick: k, children: o })
42
33
  ] })
43
34
  ] }) : null;
44
35
  }
45
36
  export {
46
- k as EditControls
37
+ z as EditControls
47
38
  };
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { s as e } from "../../../../_virtual/index.js";
2
+ import { s as e } from "../../../../_virtual/index2.js";
3
3
  function s() {
4
4
  return e.useSyncExternalStore(
5
5
  r,
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { __module as e } from "../../_virtual/index4.js";
2
+ import { __module as e } from "../../_virtual/index3.js";
3
3
  import { __require as t } from "./cjs/react-is.production.min.js";
4
4
  import { __require as o } from "./cjs/react-is.development.js";
5
5
  var r;
@@ -5,7 +5,7 @@ import "../../../../_virtual/isString.js";
5
5
  import f from "../../../../_virtual/isFunction.js";
6
6
  import s from "../../../../_virtual/isObject.js";
7
7
  import { isValidElement as d } from "react";
8
- import "../../../../_virtual/index3.js";
8
+ import "../../../../_virtual/index.js";
9
9
  import { SVGElementPropKeys as m, EventKeys as p, FilteredElementKeyMap as o } from "./types.js";
10
10
  var h = function(i) {
11
11
  return typeof i == "string" ? i : i ? i.displayName || i.name || "Component" : "";
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { __module as e } from "../../../_virtual/index2.js";
2
+ import { __module as e } from "../../../_virtual/index4.js";
3
3
  import { __require as i } from "../cjs/use-sync-external-store-shim.production.js";
4
4
  import { __require as o } from "../cjs/use-sync-external-store-shim.development.js";
5
5
  var r;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "laif-ds",
3
3
  "private": false,
4
- "version": "0.1.37",
4
+ "version": "0.1.39",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",
7
7
  "module": "dist/index.es.js",
@@ -1,100 +0,0 @@
1
- "use client";
2
- import { jsxs as t, jsx as e } from "react/jsx-runtime";
3
- import { memo as k, useState as v, useCallback as o } from "react";
4
- import { Popover as z, PopoverTrigger as I, PopoverContent as P } from "../../popover.js";
5
- import { Icon as h } from "../../icon.js";
6
- import { Button as p } from "../../button.js";
7
- const E = k(
8
- ({
9
- value: i,
10
- onChange: u,
11
- resetCell: a,
12
- resetToDefault: l,
13
- cellKey: n,
14
- originalValue: s,
15
- cellData: m
16
- }) => {
17
- const [N, r] = v(!1), [d, f] = v(i), C = (c) => {
18
- c && f(i), r(c);
19
- }, g = o(
20
- (c) => {
21
- f(c.target.value);
22
- },
23
- []
24
- ), w = o(() => {
25
- u(n, d), r(!1);
26
- }, [u, n, d]), b = o(() => {
27
- f(s ?? null), a(n), r(!1);
28
- }, [s, a, n]), j = o(() => {
29
- a(n), m && l && l(n, s, m), r(!1);
30
- }, [l, a, n, s, m]), x = i !== s;
31
- return /* @__PURE__ */ t(z, { open: N, onOpenChange: C, children: [
32
- /* @__PURE__ */ e(I, { asChild: !0, children: /* @__PURE__ */ e("div", { className: "flex w-full cursor-pointer items-center justify-center", children: /* @__PURE__ */ t("div", { className: "relative w-full flex-1 items-center justify-center text-center", children: [
33
- i || "",
34
- x && /* @__PURE__ */ e("div", { className: "bg-d-primary text-d-primary-foreground absolute top-0 left-0 rounded p-1" }),
35
- /* @__PURE__ */ e("span", { className: "text-d-muted-foreground ml-1 inline-flex items-center", children: /* @__PURE__ */ e(h, { name: "Pencil", size: "sm", className: "h-3 w-3" }) })
36
- ] }) }) }),
37
- /* @__PURE__ */ e(P, { className: "w-[400px] p-4", children: /* @__PURE__ */ t("div", { className: "space-y-4", children: [
38
- /* @__PURE__ */ t("div", { className: "flex items-center justify-between", children: [
39
- /* @__PURE__ */ e("div", { className: "font-medium", children: "Modifica valore" }),
40
- x && /* @__PURE__ */ e("div", { className: "text-d-muted-foreground text-xs", children: "Valore modificato" })
41
- ] }),
42
- /* @__PURE__ */ e(
43
- "input",
44
- {
45
- type: "text",
46
- className: "bg-d-secondary w-full rounded border p-2",
47
- value: d || "",
48
- onChange: g,
49
- autoFocus: !0
50
- }
51
- ),
52
- /* @__PURE__ */ t("div", { className: "flex items-center justify-between", children: [
53
- /* @__PURE__ */ t(
54
- p,
55
- {
56
- variant: "destructive",
57
- size: "sm",
58
- onClick: j,
59
- className: "text-xs",
60
- title: "Ripristina il valore originale e segna la cella come da ripristinare",
61
- children: [
62
- /* @__PURE__ */ e(h, { name: "RotateCcw", className: "mr-1 h-3 w-3" }),
63
- "Ripristina"
64
- ]
65
- }
66
- ),
67
- /* @__PURE__ */ t("div", { className: "flex space-x-2", children: [
68
- /* @__PURE__ */ e(
69
- p,
70
- {
71
- variant: "ghost",
72
- size: "sm",
73
- onClick: b,
74
- className: "text-xs",
75
- title: "Annulla le modifiche correnti e chiudi",
76
- children: "Annulla"
77
- }
78
- ),
79
- /* @__PURE__ */ t(
80
- p,
81
- {
82
- size: "sm",
83
- onClick: w,
84
- className: "text-xs",
85
- title: "Conferma le modifiche e salva",
86
- children: [
87
- /* @__PURE__ */ e(h, { name: "Check", className: "mr-1 h-3 w-3" }),
88
- "Conferma"
89
- ]
90
- }
91
- )
92
- ] })
93
- ] })
94
- ] }) })
95
- ] });
96
- }
97
- );
98
- export {
99
- E as EditableInput
100
- };