laif-ds 0.2.41 → 0.2.42

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,59 +1,61 @@
1
1
  "use client";
2
- import { jsx as c, jsxs as ne } from "react/jsx-runtime";
3
- import { useReactTable as Ue } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
4
- import { cn as Xe } from "../../../../lib/utils.js";
5
- import { useRef as h, useState as u, useEffect as H, useMemo as F } from "react";
6
- import { Button as Qe } from "../../button.js";
7
- import { Checkbox as xe } from "../../checkbox.js";
8
- import { DataTableBody as Ye } from "./components/data-table-body.js";
9
- import { DataTableColumnVisibility as Ze } from "./components/data-table-column-visibility.js";
10
- import { DataTableFilters as $e } from "./components/data-table-filters.js";
11
- import { DataTablePaginationComponent as et } from "./components/data-table-pagination.js";
12
- import { DataTableSearchbar as tt } from "./components/data-table-searchbar.js";
13
- import { DataTableSortingComponent as nt } from "./components/data-table-sorting.js";
14
- import { applySearchFilterToRow as Ce, debounce as rt, buildSearchFilter as ot, updatePageSizeFromContainer as at, createDefaultAdvancedFilter as lt, createBadgeFilterFromHeader as it } from "./data-table.service.js";
15
- import { DataTableActionsComponent as st } from "./components/data-table-actions.js";
16
- import { defaultDataTableI18n as ct } from "./data-table-i18n.js";
17
- import { getPaginationRowModel as ut, getFilteredRowModel as dt, getSortedRowModel as mt, getCoreRowModel as gt } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
18
- function _t({
2
+ import { jsx as c, jsxs as ae } from "react/jsx-runtime";
3
+ import { useReactTable as Ye } from "../../../../node_modules/@tanstack/react-table/build/lib/index.js";
4
+ import { cn as Ze } from "../../../../lib/utils.js";
5
+ import { useRef as p, useState as u, useEffect as N, useMemo as C } from "react";
6
+ import { Button as $e } from "../../button.js";
7
+ import { Checkbox as ye } from "../../checkbox.js";
8
+ import { DataTableBody as et } from "./components/data-table-body.js";
9
+ import { DataTableColumnVisibility as tt } from "./components/data-table-column-visibility.js";
10
+ import { DataTableFilters as nt } from "./components/data-table-filters.js";
11
+ import { DataTablePaginationComponent as rt } from "./components/data-table-pagination.js";
12
+ import { DataTableSearchbar as ot } from "./components/data-table-searchbar.js";
13
+ import { DataTableSortingComponent as at } from "./components/data-table-sorting.js";
14
+ import { applySearchFilterToRow as Re, debounce as it, buildSearchFilter as st, updatePageSizeFromContainer as lt, createDefaultAdvancedFilter as ct, createBadgeFilterFromHeader as ut } from "./data-table.service.js";
15
+ import { DataTableActionsComponent as dt } from "./components/data-table-actions.js";
16
+ import { defaultDataTableI18n as mt } from "./data-table-i18n.js";
17
+ import { getPaginationRowModel as gt, getFilteredRowModel as pt, getSortedRowModel as ft, getCoreRowModel as ht } from "../../../../node_modules/@tanstack/table-core/build/lib/index.js";
18
+ function Nt({
19
19
  columns: Q,
20
- data: j,
21
- loading: V = !1,
22
- emptyComponent: we,
23
- className: ye,
24
- rowSelection: Re = {},
25
- onRowSelectionChange: re,
26
- checkable: q = !1,
20
+ data: P,
21
+ loading: B = !1,
22
+ emptyComponent: Ie,
23
+ className: Se,
24
+ rowSelection: Te = {},
25
+ onRowSelectionChange: ie,
26
+ checkable: V = !1,
27
27
  onCheckedRowsChange: Y,
28
- actions: Se = [],
29
- hidePagination: Ie = !1,
30
- hideActionsRow: Te = !1,
31
- i18n: p = ct,
32
- maxSortedColumns: oe = 2,
28
+ actions: ze = [],
29
+ hidePagination: ve = !1,
30
+ hideActionsRow: Be = !1,
31
+ i18n: f = mt,
32
+ maxSortedColumns: se = 2,
33
33
  initialState: m,
34
34
  // New mode-based API
35
35
  serverMode: a = !1,
36
36
  serverConfig: d,
37
- disableAutoPageSize: y = !1
37
+ disableAutoPageSize: F = !1
38
38
  }) {
39
- const P = h(null), ae = (e) => !e || !e.sort_by || !e.sort_order ? [] : e.sort_by.map((t, o) => ({
39
+ const q = p(null), le = (e) => !e || !e.sort_by || !e.sort_order ? [] : e.sort_by.map((t, o) => ({
40
40
  id: t,
41
41
  desc: e.sort_order[o] === "desc"
42
- })), ve = (e) => {
43
- const t = ae(e?.sorting), o = {
44
- sort_by: t.map((s) => s.id),
45
- sort_order: t.map((s) => s.desc ? "desc" : "asc")
42
+ })), Me = (e) => {
43
+ const t = le(e?.sorting), o = {
44
+ sort_by: t.map((l) => l.id),
45
+ sort_order: t.map((l) => l.desc ? "desc" : "asc")
46
46
  };
47
47
  return {
48
48
  computedSorting: t.length > 0 ? o : void 0,
49
49
  computedFilter: e?.computedFilter
50
50
  // Use provided value or undefined
51
51
  };
52
- }, [N, ze] = u(() => ae(m?.sorting)), [Be] = u([]), [Me, _e] = u({}), [f, De] = u(() => m?.filters?.searchbarFilter), [E, O] = u(() => m?.pagination ?? { pageIndex: 0, pageSize: 10 }), le = h(d);
53
- le.current = d;
54
- const W = h(d?.onStateChange);
52
+ }, [O, _e] = u(() => le(m?.sorting)), [De] = u([]), [He, Ne] = u({}), [h, Oe] = u(() => m?.filters?.searchbarFilter), [E, G] = u(() => m?.pagination ?? { pageIndex: 0, pageSize: 10 }), ce = p(d);
53
+ ce.current = d;
54
+ const W = p(d?.onStateChange);
55
55
  W.current = d?.onStateChange;
56
- const J = h(null), B = h(null), He = h(0), ie = h(!1), se = h(null), K = h({}), ce = h(null), A = (e) => {
56
+ const J = p(null), M = p(null), Ge = p(0), ue = p(!1), de = p(null), K = p({}), me = p(null), Z = p(B);
57
+ Z.current = B;
58
+ const L = (e) => {
57
59
  e.computedFilter && (K.current.computedFilter = e.computedFilter), e.computedSorting && (K.current.computedSorting = e.computedSorting);
58
60
  const t = {
59
61
  ...e,
@@ -61,20 +63,20 @@ function _t({
61
63
  computedFilter: e.computedFilter || K.current.computedFilter,
62
64
  computedSorting: e.computedSorting || K.current.computedSorting
63
65
  };
64
- J.current = t, B.current && clearTimeout(B.current), B.current = setTimeout(() => {
65
- J.current && W.current && (He.current = Date.now(), W.current(J.current), J.current = null, B.current = null);
66
+ J.current = t, M.current && clearTimeout(M.current), M.current = setTimeout(() => {
67
+ J.current && W.current && (Ge.current = Date.now(), W.current(J.current), J.current = null, M.current = null);
66
68
  }, 400);
67
69
  };
68
- H(() => {
70
+ N(() => {
69
71
  const e = setTimeout(() => {
70
- ie.current = !0;
72
+ ue.current = !0;
71
73
  }, 100);
72
74
  return () => {
73
- clearTimeout(e), B.current && clearTimeout(B.current);
75
+ clearTimeout(e), M.current && clearTimeout(M.current);
74
76
  };
75
77
  }, []);
76
- const [r, G] = u(() => {
77
- const { computedSorting: e, computedFilter: t } = ve(m);
78
+ const [n, k] = u(() => {
79
+ const { computedSorting: e, computedFilter: t } = Me(m);
78
80
  return {
79
81
  pagination: m?.pagination ?? { pageIndex: 0, pageSize: 10 },
80
82
  sorting: m?.sorting,
@@ -84,9 +86,9 @@ function _t({
84
86
  };
85
87
  });
86
88
  a && !d && console.warn("DataTable: Server mode requires serverConfig");
87
- const [Ne, ue] = u(0), [Oe, de] = u(0), [Ae, Ge] = u({}), me = re ? Re : Ae, Le = re || Ge, [R, Z] = u(
89
+ const [Le, ge] = u(0), [ke, pe] = u(0), [Ae, je] = u({}), fe = ie ? Te : Ae, Pe = ie || je, [I, $] = u(
88
90
  () => m?.filters?.filterBadges ?? []
89
- ), [S, $] = u(() => m?.filters?.advancedFilterBadge), [U, ke] = u(""), [ge, pe] = u([]), fe = F(() => q ? [
91
+ ), [S, ee] = u(() => m?.filters?.advancedFilterBadge), [U, Ve] = u(""), [he, be] = u([]), Fe = C(() => V ? [
90
92
  {
91
93
  id: "data-table-integrated-checkbox-column",
92
94
  size: 24,
@@ -98,12 +100,12 @@ function _t({
98
100
  className: "flex w-6 max-w-6 min-w-6 items-center justify-center",
99
101
  style: { width: "24px", minWidth: "24px", maxWidth: "24px" },
100
102
  children: /* @__PURE__ */ c(
101
- xe,
103
+ ye,
102
104
  {
103
105
  className: "cursor-pointer",
104
106
  checked: e.getIsAllPageRowsSelected(),
105
107
  onCheckedChange: (t) => e.toggleAllPageRowsSelected(!!t),
106
- "aria-label": p.selectAll
108
+ "aria-label": f.selectAll
107
109
  }
108
110
  )
109
111
  }
@@ -114,12 +116,12 @@ function _t({
114
116
  className: "flex w-6 max-w-6 min-w-6 items-center justify-center",
115
117
  style: { width: "24px", minWidth: "24px", maxWidth: "24px" },
116
118
  children: /* @__PURE__ */ c(
117
- xe,
119
+ ye,
118
120
  {
119
121
  className: "cursor-pointer",
120
122
  checked: e.getIsSelected(),
121
123
  onCheckedChange: (t) => e.toggleSelected(!!t),
122
- "aria-label": p.selectRow
124
+ "aria-label": f.selectRow
123
125
  }
124
126
  )
125
127
  }
@@ -137,169 +139,175 @@ function _t({
137
139
  }
138
140
  },
139
141
  ...Q
140
- ] : Q, [Q, q]), I = F(() => fe.map(
142
+ ] : Q, [Q, V]), T = C(() => Fe.map(
141
143
  (e) => e
142
- ), [fe]);
143
- H(() => {
144
- const e = (I ?? []).map((i) => i?.id ?? i?.accessorKey).filter(Boolean), t = new Set(ge), o = new Set(e);
145
- t.size === o.size && [...t].every((i) => o.has(i)) || pe(e);
146
- }, [I]);
147
- const M = F(() => I.filter(
144
+ ), [Fe]);
145
+ N(() => {
146
+ const e = (T ?? []).map((s) => s?.id ?? s?.accessorKey).filter(Boolean), t = new Set(he), o = new Set(e);
147
+ t.size === o.size && [...t].every((s) => o.has(s)) || be(e);
148
+ }, [T]);
149
+ const _ = C(() => T.filter(
148
150
  (e) => !!e?.meta?.searchable
149
- ), [I]), T = F(() => M.map((e) => e.id ?? e.accessorKey).filter(Boolean), [M]), [X, je] = u(() => m?.computedFilter ?? {}), Ve = {
150
- data: F(() => a || Object.keys(X).length === 0 ? j : j.filter((e) => Ce({
151
+ ), [T]), z = C(() => _.map((e) => e.id ?? e.accessorKey).filter(Boolean), [_]), [X, qe] = u(() => m?.computedFilter ?? {}), Ee = {
152
+ data: C(() => a || Object.keys(X).length === 0 ? P : P.filter((e) => Re({
151
153
  original: e,
152
154
  getValue: (o) => e[o]
153
- }, X)), [j, X, a]),
154
- columns: I,
155
- getCoreRowModel: gt(),
155
+ }, X)), [P, X, a]),
156
+ columns: T,
157
+ getCoreRowModel: ht(),
156
158
  onSortingChange: (e) => {
157
- const t = typeof e == "function" ? e(N) : e;
158
- ze(t);
159
+ const t = typeof e == "function" ? e(O) : e;
160
+ _e(t);
159
161
  },
160
- getSortedRowModel: mt(),
162
+ getSortedRowModel: ft(),
161
163
  manualSorting: a,
162
- onColumnVisibilityChange: _e,
163
- onRowSelectionChange: Le,
164
- onColumnOrderChange: pe,
165
- getFilteredRowModel: dt(),
164
+ onColumnVisibilityChange: Ne,
165
+ onRowSelectionChange: Pe,
166
+ onColumnOrderChange: be,
167
+ getFilteredRowModel: pt(),
166
168
  manualFiltering: a,
167
- globalFilterFn: (e, t, o) => a || !o ? !0 : (T ?? []).some((s) => {
168
- const i = e.getValue(s);
169
- return Array.isArray(i) ? i.some(
169
+ globalFilterFn: (e, t, o) => a || !o ? !0 : (z ?? []).some((l) => {
170
+ const s = e.getValue(l);
171
+ return Array.isArray(s) ? s.some(
170
172
  (g) => String(g).toLowerCase().includes(o.toLowerCase())
171
- ) : String(i).toLowerCase().includes(o.toLowerCase());
173
+ ) : String(s).toLowerCase().includes(o.toLowerCase());
172
174
  }) ?? !1,
173
175
  filterFns: {
174
- advancedFilter: (e) => a ? !0 : Ce(e, X)
176
+ advancedFilter: (e) => a ? !0 : Re(e, X)
175
177
  },
176
178
  onPaginationChange: (e) => {
177
179
  if (a && d) {
178
180
  if (typeof e == "object") {
179
- const t = y ? {
180
- ...r.pagination,
181
+ const t = F ? {
182
+ ...n.pagination,
181
183
  pageIndex: e.pageIndex
182
184
  } : {
183
- ...r.pagination,
185
+ ...n.pagination,
184
186
  pageIndex: e.pageIndex,
185
187
  pageSize: e.pageSize
186
188
  }, o = {
187
- ...r,
189
+ ...n,
188
190
  pagination: t,
189
191
  // Preserve computed values if they exist
190
- computedFilter: r.computedFilter,
191
- computedSorting: r.computedSorting
192
+ computedFilter: n.computedFilter,
193
+ computedSorting: n.computedSorting
192
194
  };
193
- G(o), A(o);
195
+ k(o), L(o);
194
196
  }
195
197
  } else
196
- O(
197
- typeof e == "object" ? (t) => y ? { ...t, pageIndex: e.pageIndex } : {
198
+ G(
199
+ typeof e == "object" ? (t) => F ? { ...t, pageIndex: e.pageIndex } : {
198
200
  pageIndex: e.pageIndex,
199
201
  pageSize: e.pageSize
200
202
  } : e
201
203
  );
202
204
  },
203
- getPaginationRowModel: ut(),
205
+ getPaginationRowModel: gt(),
204
206
  manualPagination: a,
205
- pageCount: a && V ? Oe : Ne,
207
+ pageCount: a && B ? ke : Le,
206
208
  state: {
207
- sorting: N,
208
- columnFilters: Be,
209
- columnVisibility: Me,
210
- rowSelection: me,
211
- globalFilter: f,
212
- pagination: a ? r.pagination : E,
213
- columnOrder: ge
209
+ sorting: O,
210
+ columnFilters: De,
211
+ columnVisibility: He,
212
+ rowSelection: fe,
213
+ globalFilter: h,
214
+ pagination: a ? n.pagination : E,
215
+ columnOrder: he
214
216
  },
215
217
  // Prevent implicit resets on data/columns changes so filters/sorting persist
216
218
  autoResetPageIndex: !1
217
- }, l = Ue(Ve), ee = l.getFilteredRowModel();
218
- H(() => {
219
+ }, i = Ye(Ee), te = i.getFilteredRowModel();
220
+ N(() => {
219
221
  if (a && d) {
220
222
  const e = Math.ceil(
221
- d.totalItems / (r.pagination.pageSize || 10)
223
+ d.totalItems / (n.pagination.pageSize || 10)
222
224
  );
223
- ue(e), !V && e > 0 && de(e);
225
+ ge(e), !B && e > 0 && pe(e);
224
226
  } else {
225
- const e = ee.rows.length, t = Math.ceil(e / E.pageSize);
226
- ue(t), de(t);
227
+ const e = te.rows.length, t = Math.ceil(e / E.pageSize);
228
+ ge(t), pe(t);
227
229
  }
228
230
  }, [
229
231
  a,
230
232
  d?.totalItems,
231
- r.pagination.pageSize,
232
- r.pagination.pageIndex,
233
- l,
234
- ee,
233
+ n.pagination.pageSize,
234
+ n.pagination.pageIndex,
235
+ i,
236
+ te,
235
237
  E.pageSize,
236
- V
237
- ]), H(() => {
238
- if (y) return;
238
+ B
239
+ ]), N(() => {
240
+ if (F) return;
239
241
  const e = () => {
240
- const x = P.current;
241
- if (!x) return;
242
- const _ = x.querySelector(
242
+ const w = q.current;
243
+ if (!w) return;
244
+ const D = w.querySelector(
243
245
  "thead tr"
244
- ), n = x.querySelector(
246
+ ), r = w.querySelector(
245
247
  "tbody tr"
246
- ), C = _?.getBoundingClientRect().height ?? 40;
247
- if (!!!n?.querySelector("td")) return;
248
- const v = n?.getBoundingClientRect().height ?? 32.5;
249
- at(x, {
248
+ ), y = D?.getBoundingClientRect().height ?? 40;
249
+ if (!!!r?.querySelector("td")) return;
250
+ const v = r?.getBoundingClientRect().height ?? 32.5;
251
+ lt(w, {
250
252
  rowHeight: v,
251
- headerHeight: C,
252
- onPageChange: a ? (w, b) => {
253
- if (d && ie.current) {
254
- const z = y ? {
255
- ...r.pagination,
256
- pageIndex: w
253
+ headerHeight: y,
254
+ onPageChange: a ? (R, x) => {
255
+ if (d && ue.current) {
256
+ const b = F ? {
257
+ ...n.pagination,
258
+ pageIndex: R
257
259
  } : {
258
- ...r.pagination,
259
- pageIndex: w,
260
- pageSize: b
261
- }, k = {
262
- ...r,
263
- pagination: z,
260
+ ...n.pagination,
261
+ pageIndex: R,
262
+ pageSize: x
263
+ }, re = b.pageIndex === n.pagination.pageIndex, oe = F || b.pageSize === n.pagination.pageSize;
264
+ if (re && oe)
265
+ return;
266
+ const j = {
267
+ ...n,
268
+ pagination: b,
264
269
  // Preserve computed values if they exist
265
- computedFilter: r.computedFilter,
266
- computedSorting: r.computedSorting
270
+ computedFilter: n.computedFilter,
271
+ computedSorting: n.computedSorting
267
272
  };
268
- G(k), A(k);
273
+ k(j), Z.current || L(j);
269
274
  }
270
- } : (w, b) => {
271
- O(
272
- (z) => y ? { ...z, pageIndex: w } : { pageIndex: w, pageSize: b }
275
+ } : (R, x) => {
276
+ G(
277
+ (b) => F ? { ...b, pageIndex: R } : { pageIndex: R, pageSize: x }
273
278
  );
274
279
  },
275
- setPagination: (w) => {
276
- const b = typeof w == "function" ? w(r.pagination) : w;
280
+ setPagination: (R) => {
281
+ const x = typeof R == "function" ? R(n.pagination) : R;
277
282
  if (a && d) {
278
- const z = y ? {
279
- ...r.pagination,
280
- pageIndex: b.pageIndex
283
+ const b = F ? {
284
+ ...n.pagination,
285
+ pageIndex: x.pageIndex
281
286
  } : {
282
- ...r.pagination,
283
- pageIndex: b.pageIndex,
284
- pageSize: b.pageSize
285
- }, k = {
286
- ...r,
287
- pagination: z,
287
+ ...n.pagination,
288
+ pageIndex: x.pageIndex,
289
+ pageSize: x.pageSize
290
+ }, re = b.pageIndex === n.pagination.pageIndex, oe = F || b.pageSize === n.pagination.pageSize;
291
+ if (re && oe)
292
+ return;
293
+ const j = {
294
+ ...n,
295
+ pagination: b,
288
296
  // Preserve computed values if they exist
289
- computedFilter: r.computedFilter,
290
- computedSorting: r.computedSorting
297
+ computedFilter: n.computedFilter,
298
+ computedSorting: n.computedSorting
291
299
  };
292
- G(k), A(k);
300
+ k(j), Z.current || L(j);
293
301
  } else
294
- O(
295
- (z) => y ? { ...z, pageIndex: b.pageIndex } : {
296
- pageIndex: b.pageIndex,
297
- pageSize: b.pageSize
302
+ G(
303
+ (b) => F ? { ...b, pageIndex: x.pageIndex } : {
304
+ pageIndex: x.pageIndex,
305
+ pageSize: x.pageSize
298
306
  }
299
307
  );
300
308
  }
301
309
  });
302
- }, t = rt(() => {
310
+ }, t = it(() => {
303
311
  requestAnimationFrame(() => {
304
312
  e();
305
313
  });
@@ -309,235 +317,236 @@ function _t({
309
317
  e();
310
318
  });
311
319
  });
312
- const o = setTimeout(e, 200), s = document.fonts;
313
- s && typeof s.ready?.then == "function" && s.ready.then(() => e()), window.addEventListener("resize", t);
314
- const i = P.current, g = typeof ResizeObserver < "u" ? new ResizeObserver((x) => {
315
- const _ = x[0];
316
- if (!_) return;
317
- const n = _.contentRect.height, C = ce.current;
318
- (C === null || Math.abs(n - C) > 0.5) && (ce.current = n, t());
320
+ const o = setTimeout(e, 200), l = document.fonts;
321
+ l && typeof l.ready?.then == "function" && l.ready.then(() => e()), window.addEventListener("resize", t);
322
+ const s = q.current, g = typeof ResizeObserver < "u" ? new ResizeObserver((w) => {
323
+ const D = w[0];
324
+ if (!D) return;
325
+ const r = D.contentRect.height, y = me.current;
326
+ (y === null || Math.abs(r - y) > 0.5) && (me.current = r, t());
319
327
  }) : null;
320
- return i && g && g.observe(i), () => {
328
+ return s && g && g.observe(s), () => {
321
329
  window.removeEventListener("resize", t), clearTimeout(o), g && g.disconnect(), clearTimeout(o);
322
330
  };
323
331
  }, [
324
332
  a,
325
- P,
326
- y,
333
+ q,
334
+ F,
327
335
  // Recalculate when the rendered rows count changes; helps when data arrives async
328
- ee.rows.length
329
- ]), H(() => {
330
- if (Y && q) {
331
- const e = l.getFilteredSelectedRowModel().rows.map((t) => t.original);
336
+ te.rows.length
337
+ ]), N(() => {
338
+ if (Y && V) {
339
+ const e = i.getFilteredSelectedRowModel().rows.map((t) => t.original);
332
340
  Y(e);
333
341
  }
334
- }, [l, Y, q, me]);
335
- const qe = F(() => {
336
- const e = l.getHeaderGroups()[0], t = e ? e.headers : [];
337
- return (l.getState().sorting || []).map((i) => t.find((g) => g.column.id === i.id)).filter(Boolean);
342
+ }, [i, Y, V, fe]);
343
+ const We = C(() => {
344
+ const e = i.getHeaderGroups()[0], t = e ? e.headers : [];
345
+ return (i.getState().sorting || []).map((s) => t.find((g) => g.column.id === s.id)).filter(Boolean);
338
346
  }, [
339
- l.getHeaderGroups,
340
- l.getState().sorting,
341
- I
342
- ]), te = F(() => l.getHeaderGroups()[0].headers.filter((e) => e.column.columnDef.meta?.sortable), [l.getHeaderGroups, I]), L = F(() => l.getHeaderGroups()[0].headers.filter((e) => e.column.columnDef.meta?.filterable), [l.getHeaderGroups, I]), Pe = F(() => U ? L.filter((e) => (e.column.columnDef.header?.toString().toLowerCase() || "").includes(U.toLowerCase())) : L, [L, U]), he = (e) => {
343
- Z((t) => [...t, it(e)]);
344
- }, Ee = () => {
345
- $(lt());
346
- }, We = F(() => R.sort((e, t) => e.value === void 0 || e.value === "" ? 1 : t.value === void 0 || t.value === "" ? -1 : 1), [R]), be = h({
347
+ i.getHeaderGroups,
348
+ i.getState().sorting,
349
+ T
350
+ ]), ne = C(() => i.getHeaderGroups()[0].headers.filter((e) => e.column.columnDef.meta?.sortable), [i.getHeaderGroups, T]), A = C(() => i.getHeaderGroups()[0].headers.filter((e) => e.column.columnDef.meta?.filterable), [i.getHeaderGroups, T]), Je = C(() => U ? A.filter((e) => (e.column.columnDef.header?.toString().toLowerCase() || "").includes(U.toLowerCase())) : A, [A, U]), xe = (e) => {
351
+ $((t) => [...t, ut(e)]);
352
+ }, Ke = () => {
353
+ ee(ct());
354
+ }, Ue = C(() => I.sort((e, t) => e.value === void 0 || e.value === "" ? 1 : t.value === void 0 || t.value === "" ? -1 : 1), [I]), Ce = p({
347
355
  filterBadges: [],
348
356
  advancedFilterBadge: void 0,
349
357
  searchbarGlobalFilter: void 0
350
358
  });
351
- H(() => {
352
- const e = ot(
353
- R,
359
+ N(() => {
360
+ const e = st(
361
+ I,
354
362
  S ?? void 0
355
- ), t = f && T.length > 0 ? T.length === 1 ? (() => {
356
- const n = T[0], D = M.find(
357
- (v) => (v.id ?? v.accessorKey) === n
363
+ ), t = h && z.length > 0 ? z.length === 1 ? (() => {
364
+ const r = z[0], H = _.find(
365
+ (v) => (v.id ?? v.accessorKey) === r
358
366
  )?.meta?.type;
359
- return D === "list_multi_select" || D === "list_single_select" ? {
360
- [n]: {
367
+ return H === "list_multi_select" || H === "list_single_select" ? {
368
+ [r]: {
361
369
  operator: "array_overlap",
362
- value: [f]
370
+ value: [h]
363
371
  }
364
372
  } : {
365
- [n]: {
373
+ [r]: {
366
374
  operator: "like",
367
- value: f
375
+ value: h
368
376
  }
369
377
  };
370
378
  })() : {
371
- _or: T.map((n) => {
372
- const D = M.find(
373
- (v) => (v.id ?? v.accessorKey) === n
379
+ _or: z.map((r) => {
380
+ const H = _.find(
381
+ (v) => (v.id ?? v.accessorKey) === r
374
382
  )?.meta?.type;
375
- return D === "list_multi_select" || D === "list_single_select" ? {
376
- [n]: {
383
+ return H === "list_multi_select" || H === "list_single_select" ? {
384
+ [r]: {
377
385
  operator: "array_overlap",
378
- value: [f]
386
+ value: [h]
379
387
  }
380
388
  } : {
381
- [n]: {
389
+ [r]: {
382
390
  operator: "like",
383
- value: f
391
+ value: h
384
392
  }
385
393
  };
386
394
  })
387
395
  } : null, o = [
388
396
  ...e && Object.keys(e).length > 0 ? [e] : [],
389
397
  ...t ? [t] : []
390
- ], s = o.length === 0 ? {} : o.length === 1 ? o[0] : { _and: o }, i = {
391
- sort_by: N.map((n) => n.id),
392
- sort_order: N.map((n) => n.desc ? "desc" : "asc")
393
- }, g = be.current, x = JSON.stringify(R) !== JSON.stringify(g.filterBadges) || JSON.stringify(S) !== JSON.stringify(g.advancedFilterBadge) || f !== g.searchbarGlobalFilter;
394
- be.current = {
395
- filterBadges: [...R],
398
+ ], l = o.length === 0 ? {} : o.length === 1 ? o[0] : { _and: o }, s = {
399
+ sort_by: O.map((r) => r.id),
400
+ sort_order: O.map((r) => r.desc ? "desc" : "asc")
401
+ }, g = Ce.current, w = JSON.stringify(I) !== JSON.stringify(g.filterBadges) || JSON.stringify(S) !== JSON.stringify(g.advancedFilterBadge) || h !== g.searchbarGlobalFilter;
402
+ Ce.current = {
403
+ filterBadges: [...I],
396
404
  advancedFilterBadge: S ? { ...S } : void 0,
397
- searchbarGlobalFilter: f
405
+ searchbarGlobalFilter: h
398
406
  };
399
- const _ = le.current;
400
- if (je(s), a && W.current && _) {
401
- const n = {
402
- ...r,
403
- computedFilter: s,
407
+ const D = ce.current;
408
+ if (qe(l), a && W.current && D) {
409
+ const r = {
410
+ ...n,
411
+ computedFilter: l,
404
412
  // Emit only computedSorting. Use empty arrays to signal "no sorting" when cleared.
405
- computedSorting: i,
413
+ computedSorting: s,
406
414
  filters: {
407
- filterBadges: R,
415
+ filterBadges: I,
408
416
  advancedFilterBadge: S,
409
- searchbarFilter: f
417
+ searchbarFilter: h
410
418
  },
411
419
  pagination: {
412
- ...r.pagination,
420
+ ...n.pagination,
413
421
  // Only reset pageIndex to 0 when filters actually changed, not when just sorting changed
414
- pageIndex: x ? 0 : r.pagination.pageIndex
422
+ pageIndex: w ? 0 : n.pagination.pageIndex
415
423
  }
416
424
  };
417
- G(n);
418
- const C = JSON.stringify({
419
- computedFilter: n.computedFilter,
420
- computedSorting: n.computedSorting,
421
- filters: n.filters,
422
- pagination: n.pagination
425
+ k(r);
426
+ const y = JSON.stringify({
427
+ computedFilter: r.computedFilter,
428
+ computedSorting: r.computedSorting,
429
+ filters: r.filters,
430
+ pagination: r.pagination
423
431
  });
424
- se.current !== C && (se.current = C, A(n));
432
+ de.current !== y && (de.current = y, L(r));
425
433
  } else
426
- x && O((n) => ({
427
- ...n,
434
+ w && G((r) => ({
435
+ ...r,
428
436
  pageIndex: 0
429
437
  }));
430
438
  }, [
431
- R,
439
+ I,
432
440
  S,
433
- f,
434
- T,
435
- M,
436
- N,
441
+ h,
442
+ z,
443
+ _,
444
+ O,
437
445
  a
438
446
  ]);
439
- const Fe = l.getAllLeafColumns(), Je = Fe.filter((e) => e.getIsVisible()), Ke = Fe.filter((e) => !e.getIsVisible());
440
- return /* @__PURE__ */ ne(
447
+ const we = i.getAllLeafColumns(), Xe = we.filter((e) => e.getIsVisible()), Qe = we.filter((e) => !e.getIsVisible());
448
+ return /* @__PURE__ */ ae(
441
449
  "div",
442
450
  {
443
- className: Xe(
451
+ className: Ze(
444
452
  "flex h-full max-h-full min-h-[250px] w-full max-w-full min-w-0 flex-col gap-2",
445
- ye
453
+ Se
446
454
  ),
447
455
  children: [
448
- !Te && /* @__PURE__ */ ne("div", { className: "flex w-full items-center justify-between gap-1", children: [
449
- /* @__PURE__ */ ne("div", { className: "flex min-w-0 flex-1 items-center gap-1 overflow-x-auto", children: [
450
- te.length > 0 && /* @__PURE__ */ c(
451
- nt,
456
+ !Be && /* @__PURE__ */ ae("div", { className: "flex w-full items-center justify-between gap-1", children: [
457
+ /* @__PURE__ */ ae("div", { className: "flex min-w-0 flex-1 items-center gap-1 overflow-x-auto", children: [
458
+ ne.length > 0 && /* @__PURE__ */ c(
459
+ at,
452
460
  {
453
- table: l,
454
- sortedColumns: qe,
455
- sortableColumns: te,
456
- i18n: p,
457
- maxSortedColumns: oe
461
+ table: i,
462
+ sortedColumns: We,
463
+ sortableColumns: ne,
464
+ i18n: f,
465
+ maxSortedColumns: se
458
466
  }
459
467
  ),
460
- te.length > 0 && L.length > 0 && /* @__PURE__ */ c("div", { className: "border-d-border h-4 min-h-4 w-[1px] border-r" }),
468
+ ne.length > 0 && A.length > 0 && /* @__PURE__ */ c("div", { className: "border-d-border h-4 min-h-4 w-[1px] border-r" }),
461
469
  /* @__PURE__ */ c(
462
- $e,
470
+ nt,
463
471
  {
464
472
  advancedFilterBadge: S,
465
- setAdvancedFilterBadge: $,
466
- filterableColumns: L,
467
- sortedFilterBadges: We,
468
- setFilterBadges: Z,
473
+ setAdvancedFilterBadge: ee,
474
+ filterableColumns: A,
475
+ sortedFilterBadges: Ue,
476
+ setFilterBadges: $,
469
477
  filterSearch: U,
470
- setFilterSearch: ke,
471
- filteredColumns: Pe,
472
- handleAddFilter: he,
473
- handleAddAdvancedFilter: Ee,
474
- i18n: p
478
+ setFilterSearch: Ve,
479
+ filteredColumns: Je,
480
+ handleAddFilter: xe,
481
+ handleAddAdvancedFilter: Ke,
482
+ i18n: f
475
483
  }
476
484
  )
477
485
  ] }),
478
486
  /* @__PURE__ */ c("div", { className: "border-d-border h-4 min-h-4 w-[1px] border-r" }),
479
- (R.length || S) && /* @__PURE__ */ c(
480
- Qe,
487
+ (I.length || S) && /* @__PURE__ */ c(
488
+ $e,
481
489
  {
482
490
  className: "h-6 text-xs",
483
491
  iconLeft: "FunnelX",
484
492
  size: "sm",
485
493
  variant: "ghost-destructive",
486
494
  onClick: () => {
487
- Z([]), $(void 0);
495
+ $([]), ee(void 0);
488
496
  },
489
- children: p.reset
497
+ children: f.reset
490
498
  }
491
499
  ),
492
- T.length > 0 && /* @__PURE__ */ c(
493
- tt,
500
+ z.length > 0 && /* @__PURE__ */ c(
501
+ ot,
494
502
  {
495
503
  debounceMs: 300,
496
- onSearch: De,
497
- i18n: p,
498
- initialValue: f ?? "",
499
- searchableColumnsHeaders: M.map(
504
+ onSearch: Oe,
505
+ i18n: f,
506
+ initialValue: h ?? "",
507
+ searchableColumnsHeaders: _.map(
500
508
  (e) => e.header ? e.header.toString() : e.id?.toString() ?? "-"
501
509
  )
502
510
  }
503
511
  ),
504
512
  /* @__PURE__ */ c(
505
- Ze,
513
+ tt,
506
514
  {
507
- table: l,
508
- visibleColumns: Je,
509
- hiddenColumns: Ke,
510
- i18n: p
515
+ table: i,
516
+ visibleColumns: Xe,
517
+ hiddenColumns: Qe,
518
+ i18n: f
511
519
  }
512
520
  ),
513
- /* @__PURE__ */ c(st, { actions: Se, i18n: p })
521
+ /* @__PURE__ */ c(dt, { actions: ze, i18n: f })
514
522
  ] }),
515
523
  /* @__PURE__ */ c(
516
- Ye,
524
+ et,
517
525
  {
518
- table: l,
519
- tableContainerRef: P,
520
- loading: V,
521
- data: j,
522
- emptyComponent: we,
523
- notFoundMessage: p?.notFoundMessage ?? "N/A",
524
- onAddFilter: he,
525
- maxSortedColumns: oe,
526
- i18n: p
526
+ table: i,
527
+ tableContainerRef: q,
528
+ loading: B,
529
+ data: P,
530
+ emptyComponent: Ie,
531
+ notFoundMessage: f?.notFoundMessage ?? "N/A",
532
+ onAddFilter: xe,
533
+ maxSortedColumns: se,
534
+ i18n: f,
535
+ isServerSide: a
527
536
  }
528
537
  ),
529
- !Ie && /* @__PURE__ */ c(
530
- et,
538
+ !ve && /* @__PURE__ */ c(
539
+ rt,
531
540
  {
532
- table: l,
541
+ table: i,
533
542
  isServerSide: a,
534
543
  clientPagination: E,
535
- serverState: a ? r : void 0,
544
+ serverState: a ? n : void 0,
536
545
  onServerStateChange: a && d ? (e) => {
537
- G(e), A(e);
546
+ k(e), L(e);
538
547
  } : void 0,
539
548
  totalItems: d?.totalItems,
540
- i18n: p
549
+ i18n: f
541
550
  }
542
551
  )
543
552
  ]
@@ -545,5 +554,5 @@ function _t({
545
554
  );
546
555
  }
547
556
  export {
548
- _t as DataTable
557
+ Nt as DataTable
549
558
  };