laif-ds 0.2.41 → 0.2.43

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