@withwiz/toolkit 0.1.4 → 0.2.1

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.
Files changed (41) hide show
  1. package/dist/auth/index.js +3 -3
  2. package/dist/chunk-6JZQE7ZQ.js +225 -0
  3. package/dist/chunk-7IY3RQQL.js +151 -0
  4. package/dist/{chunk-SLG26KHZ.js → chunk-FH6E36YZ.js} +1 -1
  5. package/dist/chunk-IPXPCBDO.js +127 -0
  6. package/dist/chunk-KHYY4KCV.js +110 -0
  7. package/dist/chunk-MAATEX2R.js +81 -0
  8. package/dist/chunk-NY5QXT33.js +31 -0
  9. package/dist/chunk-SEZJN4TC.js +136 -0
  10. package/dist/components/ui/DataTable.d.ts +8 -103
  11. package/dist/components/ui/DataTable.js +17 -602
  12. package/dist/components/ui/data-table/DataTable.d.ts +2 -0
  13. package/dist/components/ui/data-table/DataTable.js +22 -0
  14. package/dist/components/ui/data-table/DataTableBody.d.ts +19 -0
  15. package/dist/components/ui/data-table/DataTableBody.js +10 -0
  16. package/dist/components/ui/data-table/DataTableBulkActions.d.ts +17 -0
  17. package/dist/components/ui/data-table/DataTableBulkActions.js +12 -0
  18. package/dist/components/ui/data-table/DataTableFilters.d.ts +15 -0
  19. package/dist/components/ui/data-table/DataTableFilters.js +13 -0
  20. package/dist/components/ui/data-table/DataTablePagination.d.ts +10 -0
  21. package/dist/components/ui/data-table/DataTablePagination.js +11 -0
  22. package/dist/components/ui/data-table/DataTableSearch.d.ts +24 -0
  23. package/dist/components/ui/data-table/DataTableSearch.js +12 -0
  24. package/dist/components/ui/data-table/index.d.ts +13 -0
  25. package/dist/components/ui/data-table/types.d.ts +115 -0
  26. package/dist/constants/index.js +13 -13
  27. package/dist/error/hooks/index.js +2 -2
  28. package/dist/error/hooks/useErrorHandler.js +2 -2
  29. package/dist/error/index.js +25 -25
  30. package/dist/error/recovery/index.js +7 -7
  31. package/dist/geolocation/index.js +4 -4
  32. package/dist/geolocation/providers/index.js +4 -4
  33. package/dist/hooks/useDataTable.d.ts +45 -0
  34. package/dist/hooks/useDataTable.js +13 -11
  35. package/dist/middleware/error-handler.js +2 -2
  36. package/dist/middleware/index.js +3 -3
  37. package/dist/middleware/wrappers.js +3 -3
  38. package/package.json +3 -1
  39. package/dist/{chunk-TMVS4F7E.js → chunk-5OWZKYWQ.js} +3 -3
  40. package/dist/{chunk-IAJNC34M.js → chunk-6UAYU5NU.js} +3 -3
  41. package/dist/{chunk-QF6FH4GZ.js → chunk-S73334QY.js} +3 -3
@@ -1,606 +1,21 @@
1
- "use client";
2
1
  import {
3
- LoadingBar
4
- } from "../../chunk-34WAGUT5.js";
5
- import {
6
- Input
7
- } from "../../chunk-RJUVBBZG.js";
8
- import {
9
- Label
10
- } from "../../chunk-IJEZ7G7S.js";
11
- import {
12
- Pagination,
13
- PaginationContent,
14
- PaginationEllipsis,
15
- PaginationItem,
16
- PaginationLink,
17
- PaginationNext,
18
- PaginationPrevious
19
- } from "../../chunk-YJWLWUFK.js";
20
- import {
21
- Select,
22
- SelectContent,
23
- SelectItem,
24
- SelectTrigger,
25
- SelectValue
26
- } from "../../chunk-WDUFQFDP.js";
27
- import {
28
- Alert,
29
- AlertDescription
30
- } from "../../chunk-F6LCSFSU.js";
31
- import {
32
- Button
33
- } from "../../chunk-L25BNU3E.js";
34
- import {
35
- cn
36
- } from "../../chunk-62FLBG6B.js";
37
- import {
38
- __spreadProps,
39
- __spreadValues
40
- } from "../../chunk-ORMEWXMH.js";
41
-
42
- // src/components/ui/DataTable.tsx
43
- import { useState, useRef, useEffect, isValidElement } from "react";
44
- import { Filter, CheckSquare, Square, RefreshCw, Loader2 } from "lucide-react";
45
- import { jsx, jsxs } from "react/jsx-runtime";
46
- var DEFAULT_LABELS = {
47
- search: "Search",
48
- filter: "Filter",
49
- filterActive: "Active",
50
- clearFilters: "Clear Filters",
51
- selectAll: "Select All",
52
- selectAllShort: "All",
53
- selected: "{count} / {total} selected",
54
- processing: "Processing...",
55
- processingItems: "Processing {count} items...",
56
- loading: "Loading data...",
57
- perPage: "{size} per page",
58
- all: "All",
59
- min: "Min",
60
- max: "Max",
61
- previous: "Previous",
62
- next: "Next",
63
- showing: "Showing {start} to {end} of {total} results"
64
- };
65
- function formatLabel(template, values) {
66
- return Object.entries(values).reduce(
67
- (result, [key, value]) => result.replace(new RegExp(`\\{${key}\\}`, "g"), String(value)),
68
- template
69
- );
70
- }
71
- function DataTable({
72
- data,
73
- columns,
74
- loading = false,
75
- error = null,
76
- pagination,
77
- sort,
78
- bulkActions = [],
79
- filters = [],
80
- filterValues = {},
81
- onFilterChange,
82
- onClearFilters,
83
- selectable = false,
84
- onSelectionChange,
85
- selectedIds = [],
86
- getRowId,
87
- className,
88
- emptyMessage = "No data",
89
- searchPlaceholder = "Search...",
90
- onSearch,
91
- onSearchValueChange,
92
- searchValue = "",
93
- showFilters = false,
94
- onToggleFilters,
95
- createButton,
96
- labels: customLabels
97
- }) {
98
- const labels = __spreadValues(__spreadValues({}, DEFAULT_LABELS), customLabels);
99
- const [localSelectedIds, setLocalSelectedIds] = useState(selectedIds);
100
- const [bulkActionLoading, setBulkActionLoading] = useState(null);
101
- const selectAllRef = useRef(null);
102
- useEffect(() => {
103
- setLocalSelectedIds(selectedIds);
104
- }, [selectedIds]);
105
- useEffect(() => {
106
- if (selectAllRef.current) {
107
- selectAllRef.current.indeterminate = localSelectedIds.length > 0 && localSelectedIds.length < data.length;
108
- }
109
- }, [localSelectedIds, data.length]);
110
- const hasActiveFilters = (() => {
111
- if (searchValue && searchValue.trim()) return true;
112
- for (const [key, value] of Object.entries(filterValues)) {
113
- if (value === void 0 || value === null || value === "") continue;
114
- if (value === "all") continue;
115
- if (typeof value === "object" && value !== null) {
116
- if (key === "dateRange" && (value.start || value.end)) return true;
117
- if (key === "clickRange" && (value.min || value.max)) return true;
118
- if (key === "lastClickedRange" && (value.start || value.end)) return true;
119
- } else {
120
- if (key === "activeFilter" && value !== "all") return true;
121
- if (key === "publicFilter" && value !== "all") return true;
122
- if (key === "expirationFilter" && value !== "all") return true;
123
- }
124
- }
125
- return false;
126
- })();
127
- const handleSelectAll = (checked) => {
128
- const newSelection = checked ? data.map((item) => getRowId(item)) : [];
129
- setLocalSelectedIds(newSelection);
130
- onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
131
- };
132
- const handleSelect = (id, checked) => {
133
- const newSelection = checked ? [...localSelectedIds, id] : localSelectedIds.filter((item) => item !== id);
134
- setLocalSelectedIds(newSelection);
135
- onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
136
- };
137
- const handleSort = (columnKey) => {
138
- if (!sort) return;
139
- if (sort.sort === columnKey) {
140
- sort.onSortChange(columnKey, sort.order === "asc" ? "desc" : "asc");
141
- } else {
142
- sort.onSortChange(columnKey, "asc");
143
- }
144
- };
145
- const handleSearch = (e) => {
146
- if (e.key === "Enter" && onSearch) {
147
- onSearch(searchValue);
148
- }
149
- };
150
- const handleSearchClick = () => {
151
- if (onSearch) {
152
- onSearch(searchValue);
153
- }
154
- };
155
- const handleSearchInputChange = (value) => {
156
- if (onSearchValueChange) {
157
- onSearchValueChange(value);
158
- }
159
- };
160
- const handleBulkAction = async (action) => {
161
- if (localSelectedIds.length === 0 || bulkActionLoading) return;
162
- setBulkActionLoading(action.key);
163
- try {
164
- await action.onClick(localSelectedIds);
165
- } finally {
166
- setBulkActionLoading(null);
167
- }
168
- };
169
- const visibleColumns = columns.filter((col) => !col.hidden);
170
- return /* @__PURE__ */ jsxs("div", { className: cn("space-y-4", className), children: [
171
- (onSearch || createButton) && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3 p-3 bg-muted rounded-lg", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2", children: [
172
- onSearch && /* @__PURE__ */ jsxs("div", { className: "relative flex-1 min-w-0", children: [
173
- /* @__PURE__ */ jsx(
174
- Input,
175
- {
176
- "data-testid": "search-input",
177
- placeholder: searchPlaceholder,
178
- value: searchValue,
179
- onChange: (e) => handleSearchInputChange(e.target.value),
180
- onKeyPress: handleSearch,
181
- className: "min-w-0 pr-20 h-10"
182
- }
183
- ),
184
- /* @__PURE__ */ jsx(
185
- Button,
186
- {
187
- "data-testid": "search-btn",
188
- size: "sm",
189
- onClick: handleSearchClick,
190
- className: "absolute right-1 top-1/2 transform -translate-y-1/2 h-8 px-3 text-sm",
191
- children: labels.search
192
- }
193
- )
194
- ] }),
195
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-shrink-0", children: [
196
- filters.length > 0 && onToggleFilters && /* @__PURE__ */ jsxs(
197
- Button,
198
- {
199
- "data-testid": "filter-toggle-btn",
200
- variant: "outline",
201
- size: "sm",
202
- onClick: () => onToggleFilters(!showFilters),
203
- className: "flex items-center gap-1 h-10 px-3",
204
- children: [
205
- /* @__PURE__ */ jsx(Filter, { className: "h-4 w-4" }),
206
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: labels.filter }),
207
- hasActiveFilters && /* @__PURE__ */ jsx("span", { className: "ml-1 bg-primary text-primary-foreground text-xs px-1.5 py-0.5 rounded-full", children: labels.filterActive })
208
- ]
209
- }
210
- ),
211
- pagination && /* @__PURE__ */ jsx(
212
- "select",
213
- {
214
- "data-testid": "page-size-select",
215
- value: pagination.pageSize,
216
- onChange: (e) => pagination.onPageSizeChange(Number(e.target.value)),
217
- className: "border rounded px-3 py-2 text-sm bg-background h-10 min-w-[100px]",
218
- children: (pagination.pageSizeOptions || [10, 20, 50]).map((size) => /* @__PURE__ */ jsx("option", { value: size, children: formatLabel(labels.perPage, { size }) }, size))
219
- }
220
- ),
221
- createButton && (isValidElement(createButton) ? createButton : /* @__PURE__ */ jsx(
222
- Button,
223
- {
224
- "data-testid": "create-btn",
225
- onClick: createButton.onClick,
226
- variant: "default",
227
- size: "sm",
228
- className: "flex-shrink-0 h-10 px-3",
229
- children: createButton.label
230
- }
231
- ))
232
- ] })
233
- ] }) }),
234
- showFilters && filters.length > 0 && /* @__PURE__ */ jsxs("div", { className: "p-2 bg-muted/50 rounded-lg space-y-2", children: [
235
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4", children: filters.map((filter) => {
236
- var _a, _b, _c, _d, _e;
237
- return /* @__PURE__ */ jsxs("div", { className: cn("space-y-1", filter.className), children: [
238
- /* @__PURE__ */ jsx(Label, { className: "text-sm font-medium", children: filter.label }),
239
- filter.type === "text" && /* @__PURE__ */ jsx(
240
- Input,
241
- {
242
- "data-testid": `filter-${filter.key}`,
243
- type: "text",
244
- value: filterValues[filter.key] || "",
245
- onChange: (e) => onFilterChange == null ? void 0 : onFilterChange(filter.key, e.target.value),
246
- placeholder: filter.placeholder,
247
- className: "text-xs"
248
- }
249
- ),
250
- filter.type === "select" && /* @__PURE__ */ jsxs(
251
- Select,
252
- {
253
- value: filterValues[filter.key] || "all",
254
- onValueChange: (value) => onFilterChange == null ? void 0 : onFilterChange(filter.key, value),
255
- children: [
256
- /* @__PURE__ */ jsx(SelectTrigger, { "data-testid": `filter-${filter.key}`, className: "text-xs w-full h-9", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: filter.placeholder }) }),
257
- /* @__PURE__ */ jsxs(SelectContent, { children: [
258
- /* @__PURE__ */ jsx(SelectItem, { value: "all", children: labels.all }),
259
- (_a = filter.options) == null ? void 0 : _a.map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option.value, children: option.label }, option.value))
260
- ] })
261
- ]
262
- }
263
- ),
264
- filter.type === "date" && /* @__PURE__ */ jsx(
265
- Input,
266
- {
267
- type: "date",
268
- value: filterValues[filter.key] || "",
269
- onChange: (e) => onFilterChange == null ? void 0 : onFilterChange(filter.key, e.target.value),
270
- className: "text-xs"
271
- }
272
- ),
273
- filter.type === "number" && /* @__PURE__ */ jsx(
274
- Input,
275
- {
276
- type: "number",
277
- value: filterValues[filter.key] || "",
278
- onChange: (e) => onFilterChange == null ? void 0 : onFilterChange(filter.key, e.target.value),
279
- placeholder: filter.placeholder,
280
- className: "text-xs"
281
- }
282
- ),
283
- filter.type === "range" && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
284
- /* @__PURE__ */ jsx(
285
- Input,
286
- {
287
- type: filter.inputType || "text",
288
- value: ((_b = filterValues[filter.key]) == null ? void 0 : _b.min) || ((_c = filterValues[filter.key]) == null ? void 0 : _c.start) || "",
289
- onChange: (e) => {
290
- const currentValue = filterValues[filter.key] || {};
291
- const newValue = filter.key.includes("date") || filter.key.includes("Date") ? __spreadProps(__spreadValues({}, currentValue), { start: e.target.value }) : __spreadProps(__spreadValues({}, currentValue), { min: e.target.value });
292
- onFilterChange == null ? void 0 : onFilterChange(filter.key, newValue);
293
- },
294
- className: "text-xs",
295
- placeholder: filter.minPlaceholder || labels.min
296
- }
297
- ),
298
- /* @__PURE__ */ jsx(
299
- Input,
300
- {
301
- type: filter.inputType || "text",
302
- value: ((_d = filterValues[filter.key]) == null ? void 0 : _d.max) || ((_e = filterValues[filter.key]) == null ? void 0 : _e.end) || "",
303
- onChange: (e) => {
304
- const currentValue = filterValues[filter.key] || {};
305
- const newValue = filter.key.includes("date") || filter.key.includes("Date") ? __spreadProps(__spreadValues({}, currentValue), { end: e.target.value }) : __spreadProps(__spreadValues({}, currentValue), { max: e.target.value });
306
- onFilterChange == null ? void 0 : onFilterChange(filter.key, newValue);
307
- },
308
- className: "text-xs",
309
- placeholder: filter.maxPlaceholder || labels.max
310
- }
311
- )
312
- ] })
313
- ] }, filter.key);
314
- }) }),
315
- hasActiveFilters && onClearFilters && /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxs(
316
- Button,
317
- {
318
- "data-testid": "clear-filters-btn",
319
- variant: "outline",
320
- size: "sm",
321
- onClick: onClearFilters,
322
- className: "flex items-center gap-2",
323
- children: [
324
- /* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4" }),
325
- labels.clearFilters
326
- ]
327
- }
328
- ) })
329
- ] }),
330
- selectable && bulkActions.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 p-3 bg-muted rounded-lg", children: [
331
- /* @__PURE__ */ jsx("div", { className: "flex flex-col sm:flex-row items-start sm:items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
332
- /* @__PURE__ */ jsxs(
333
- Button,
334
- {
335
- "data-testid": "select-all-btn",
336
- variant: "outline",
337
- size: "sm",
338
- onClick: () => {
339
- const allSelected = localSelectedIds.length === data.length && data.length > 0;
340
- handleSelectAll(!allSelected);
341
- },
342
- className: "flex items-center gap-1 h-9 px-3",
343
- children: [
344
- localSelectedIds.length === data.length && data.length > 0 ? /* @__PURE__ */ jsx(CheckSquare, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Square, { className: "h-4 w-4" }),
345
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: labels.selectAll }),
346
- /* @__PURE__ */ jsx("span", { className: "sm:hidden", children: labels.selectAllShort })
347
- ]
348
- }
349
- ),
350
- /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: formatLabel(labels.selected, { count: localSelectedIds.length, total: data.length }) })
351
- ] }) }),
352
- localSelectedIds.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2", children: bulkActions.map((action) => {
353
- var _a;
354
- const isLoading = bulkActionLoading === action.key;
355
- const isDisabled = !!bulkActionLoading || ((_a = action.disabled) == null ? void 0 : _a.call(action, localSelectedIds)) || localSelectedIds.length === 0;
356
- return /* @__PURE__ */ jsxs(
357
- Button,
358
- {
359
- "data-testid": `bulk-action-${action.key}`,
360
- variant: action.variant || "outline",
361
- size: "sm",
362
- onClick: () => handleBulkAction(action),
363
- disabled: isDisabled,
364
- className: "flex items-center gap-1 h-9 text-xs",
365
- children: [
366
- isLoading ? /* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }) : action.icon,
367
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: isLoading ? labels.processing : action.label }),
368
- /* @__PURE__ */ jsx("span", { className: "sm:hidden", children: isLoading ? "..." : action.label.split(" ")[0] })
369
- ]
370
- },
371
- action.key
372
- );
373
- }) })
374
- ] }),
375
- bulkActionLoading && /* @__PURE__ */ jsxs("div", { className: "p-3 bg-muted/50 rounded-lg", children: [
376
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
377
- /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-primary" }),
378
- /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: formatLabel(labels.processingItems, { count: localSelectedIds.length }) })
379
- ] }),
380
- /* @__PURE__ */ jsx(LoadingBar, { size: "sm", variant: "primary", className: "mt-2" })
381
- ] }),
382
- error && /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: error }) }),
383
- /* @__PURE__ */ jsx("div", { className: "border rounded-lg overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "overflow-x-auto max-w-full", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm min-w-full", children: [
384
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b bg-muted/50", children: [
385
- selectable && /* @__PURE__ */ jsx("th", { className: "px-1 py-2 text-left font-medium w-8", children: /* @__PURE__ */ jsx(
386
- "input",
387
- {
388
- "data-testid": "select-all-checkbox",
389
- type: "checkbox",
390
- ref: selectAllRef,
391
- checked: data.length > 0 && localSelectedIds.length === data.length,
392
- onChange: (e) => handleSelectAll(e.target.checked),
393
- className: "h-4 w-4"
394
- }
395
- ) }),
396
- visibleColumns.map((column) => {
397
- var _a, _b, _c, _d;
398
- const width = column.width === "auto" ? void 0 : column.width;
399
- const minWidth = column.minWidth;
400
- return /* @__PURE__ */ jsx(
401
- "th",
402
- {
403
- className: cn(
404
- "px-2 py-2 font-medium",
405
- column.sortable && "cursor-pointer",
406
- column.className,
407
- ((_a = column.responsive) == null ? void 0 : _a.sm) && "hidden sm:table-cell",
408
- ((_b = column.responsive) == null ? void 0 : _b.md) && "hidden md:table-cell",
409
- ((_c = column.responsive) == null ? void 0 : _c.lg) && "hidden lg:table-cell",
410
- ((_d = column.responsive) == null ? void 0 : _d.xl) && "hidden xl:table-cell"
411
- ),
412
- style: {
413
- width,
414
- minWidth: minWidth || width || void 0,
415
- maxWidth: column.maxWidth || void 0
416
- },
417
- onClick: column.sortable ? () => handleSort(column.key) : void 0,
418
- children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-1", children: [
419
- column.header,
420
- column.sortable && sort && sort.sort === column.key && /* @__PURE__ */ jsx("span", { children: sort.order === "asc" ? "\u25B2" : "\u25BC" })
421
- ] })
422
- },
423
- column.key
424
- );
425
- })
426
- ] }) }),
427
- /* @__PURE__ */ jsx("tbody", { children: loading ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
428
- "td",
429
- {
430
- colSpan: visibleColumns.length + (selectable ? 1 : 0),
431
- className: "text-center py-8",
432
- children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center space-y-3", children: [
433
- /* @__PURE__ */ jsx(LoadingBar, { size: "md", variant: "primary", className: "w-64" }),
434
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: labels.loading })
435
- ] })
436
- }
437
- ) }) : error ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
438
- "td",
439
- {
440
- colSpan: visibleColumns.length + (selectable ? 1 : 0),
441
- className: "text-center py-8 text-destructive",
442
- children: error
443
- }
444
- ) }) : data.length === 0 ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
445
- "td",
446
- {
447
- colSpan: visibleColumns.length + (selectable ? 1 : 0),
448
- className: "text-center py-8 text-muted-foreground",
449
- children: emptyMessage
450
- }
451
- ) }) : data.map((item) => {
452
- const rowId = getRowId(item);
453
- return /* @__PURE__ */ jsxs(
454
- "tr",
455
- {
456
- className: cn(
457
- "border-b last:border-0 hover:bg-muted/30",
458
- localSelectedIds.includes(rowId) && "bg-primary/5"
459
- ),
460
- children: [
461
- selectable && /* @__PURE__ */ jsx("td", { className: "px-1 py-2 w-8", children: /* @__PURE__ */ jsx(
462
- "input",
463
- {
464
- "data-testid": `row-checkbox-${rowId}`,
465
- type: "checkbox",
466
- checked: localSelectedIds.includes(rowId),
467
- onChange: (e) => handleSelect(rowId, e.target.checked),
468
- className: "h-4 w-4"
469
- }
470
- ) }),
471
- visibleColumns.map((column) => {
472
- var _a, _b, _c, _d;
473
- return /* @__PURE__ */ jsx(
474
- "td",
475
- {
476
- className: cn(
477
- "px-2 py-3 overflow-hidden",
478
- column.className,
479
- ((_a = column.responsive) == null ? void 0 : _a.sm) && "hidden sm:table-cell",
480
- ((_b = column.responsive) == null ? void 0 : _b.md) && "hidden md:table-cell",
481
- ((_c = column.responsive) == null ? void 0 : _c.lg) && "hidden lg:table-cell",
482
- ((_d = column.responsive) == null ? void 0 : _d.xl) && "hidden xl:table-cell"
483
- ),
484
- style: {
485
- maxWidth: column.maxWidth || column.width || void 0
486
- },
487
- children: column.cell ? column.cell(item) : column.accessorKey ? String(item[column.accessorKey] || "") : ""
488
- },
489
- column.key
490
- );
491
- })
492
- ]
493
- },
494
- rowId
495
- );
496
- }) })
497
- ] }) }) }),
498
- pagination && pagination.total > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-col sm:flex-row items-center justify-between gap-3 p-3 bg-muted/50 rounded-lg", children: /* @__PURE__ */ jsx(Pagination, { className: "w-full", children: /* @__PURE__ */ jsxs(PaginationContent, { className: "flex-wrap gap-1 justify-between w-full items-center", children: [
499
- /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground text-center sm:text-left whitespace-nowrap", children: formatLabel(labels.showing, {
500
- start: (pagination.page - 1) * pagination.pageSize + 1,
501
- end: Math.min(pagination.page * pagination.pageSize, pagination.total),
502
- total: pagination.total
503
- }) }),
504
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
505
- PaginationPrevious,
506
- {
507
- href: "#",
508
- onClick: (e) => {
509
- e.preventDefault();
510
- if (pagination.page > 1) pagination.onPageChange(pagination.page - 1);
511
- },
512
- className: pagination.page <= 1 ? "pointer-events-none opacity-50" : "",
513
- children: [
514
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: labels.previous }),
515
- /* @__PURE__ */ jsx("span", { className: "sm:hidden", children: "\u2190" })
516
- ]
517
- }
518
- ) }),
519
- /* @__PURE__ */ jsx("div", { className: "hidden sm:flex", children: (() => {
520
- const totalPages = Math.ceil(pagination.total / pagination.pageSize);
521
- const pages = [];
522
- if (pagination.page > 3) {
523
- pages.push(
524
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
525
- PaginationLink,
526
- {
527
- href: "#",
528
- onClick: (e) => {
529
- e.preventDefault();
530
- pagination.onPageChange(1);
531
- },
532
- children: "1"
533
- }
534
- ) }, 1)
535
- );
536
- if (pagination.page > 4) {
537
- pages.push(
538
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis1")
539
- );
540
- }
541
- }
542
- for (let i = Math.max(1, pagination.page - 2); i <= Math.min(totalPages, pagination.page + 2); i++) {
543
- pages.push(
544
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
545
- PaginationLink,
546
- {
547
- href: "#",
548
- isActive: i === pagination.page,
549
- onClick: (e) => {
550
- e.preventDefault();
551
- pagination.onPageChange(i);
552
- },
553
- children: i
554
- }
555
- ) }, i)
556
- );
557
- }
558
- if (pagination.page < totalPages - 2) {
559
- if (pagination.page < totalPages - 3) {
560
- pages.push(
561
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }, "ellipsis2")
562
- );
563
- }
564
- pages.push(
565
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(
566
- PaginationLink,
567
- {
568
- href: "#",
569
- onClick: (e) => {
570
- e.preventDefault();
571
- pagination.onPageChange(totalPages);
572
- },
573
- children: totalPages
574
- }
575
- ) }, totalPages)
576
- );
577
- }
578
- return pages;
579
- })() }),
580
- /* @__PURE__ */ jsx("div", { className: "sm:hidden", children: /* @__PURE__ */ jsxs("span", { className: "px-3 py-2 text-sm font-medium", children: [
581
- pagination.page,
582
- " / ",
583
- Math.ceil(pagination.total / pagination.pageSize)
584
- ] }) }),
585
- /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs(
586
- PaginationNext,
587
- {
588
- href: "#",
589
- onClick: (e) => {
590
- e.preventDefault();
591
- const totalPages = Math.ceil(pagination.total / pagination.pageSize);
592
- if (pagination.page < totalPages) pagination.onPageChange(pagination.page + 1);
593
- },
594
- className: pagination.page >= Math.ceil(pagination.total / pagination.pageSize) ? "pointer-events-none opacity-50" : "",
595
- children: [
596
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: labels.next }),
597
- /* @__PURE__ */ jsx("span", { className: "sm:hidden", children: "\u2192" })
598
- ]
599
- }
600
- ) })
601
- ] }) }) })
602
- ] });
603
- }
2
+ DataTable
3
+ } from "../../chunk-6JZQE7ZQ.js";
4
+ import "../../chunk-7IY3RQQL.js";
5
+ import "../../chunk-MAATEX2R.js";
6
+ import "../../chunk-SEZJN4TC.js";
7
+ import "../../chunk-IPXPCBDO.js";
8
+ import "../../chunk-KHYY4KCV.js";
9
+ import "../../chunk-NY5QXT33.js";
10
+ import "../../chunk-34WAGUT5.js";
11
+ import "../../chunk-RJUVBBZG.js";
12
+ import "../../chunk-IJEZ7G7S.js";
13
+ import "../../chunk-YJWLWUFK.js";
14
+ import "../../chunk-WDUFQFDP.js";
15
+ import "../../chunk-F6LCSFSU.js";
16
+ import "../../chunk-L25BNU3E.js";
17
+ import "../../chunk-62FLBG6B.js";
18
+ import "../../chunk-ORMEWXMH.js";
604
19
  export {
605
20
  DataTable
606
21
  };
@@ -0,0 +1,2 @@
1
+ import type { DataTableProps } from "./types";
2
+ export declare function DataTable<T>({ data, columns, loading, error, pagination, sort, bulkActions, filters, filterValues, onFilterChange, onClearFilters, selectable, onSelectionChange, selectedIds, getRowId, className, emptyMessage, searchPlaceholder, onSearch, onSearchValueChange, searchValue, showFilters, onToggleFilters, createButton, labels: customLabels, syncWithUrl, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import {
3
+ DataTable
4
+ } from "../../../chunk-6JZQE7ZQ.js";
5
+ import "../../../chunk-7IY3RQQL.js";
6
+ import "../../../chunk-MAATEX2R.js";
7
+ import "../../../chunk-SEZJN4TC.js";
8
+ import "../../../chunk-IPXPCBDO.js";
9
+ import "../../../chunk-KHYY4KCV.js";
10
+ import "../../../chunk-NY5QXT33.js";
11
+ import "../../../chunk-34WAGUT5.js";
12
+ import "../../../chunk-RJUVBBZG.js";
13
+ import "../../../chunk-IJEZ7G7S.js";
14
+ import "../../../chunk-YJWLWUFK.js";
15
+ import "../../../chunk-WDUFQFDP.js";
16
+ import "../../../chunk-F6LCSFSU.js";
17
+ import "../../../chunk-L25BNU3E.js";
18
+ import "../../../chunk-62FLBG6B.js";
19
+ import "../../../chunk-ORMEWXMH.js";
20
+ export {
21
+ DataTable
22
+ };
@@ -0,0 +1,19 @@
1
+ import type { ColumnDef, SortConfig } from "./types";
2
+ export interface DataTableBodyProps<T> {
3
+ data: T[];
4
+ visibleColumns: ColumnDef<T>[];
5
+ loading: boolean;
6
+ error: string | null;
7
+ emptyMessage: string;
8
+ selectable: boolean;
9
+ localSelectedIds: string[];
10
+ getRowId: (item: T) => string;
11
+ onSelectAll: (checked: boolean) => void;
12
+ onSelect: (id: string, checked: boolean) => void;
13
+ sort?: SortConfig;
14
+ onSort: (columnKey: string) => void;
15
+ labels: {
16
+ loading: string;
17
+ };
18
+ }
19
+ export declare function DataTableBody<T>({ data, visibleColumns, loading, error, emptyMessage, selectable, localSelectedIds, getRowId, onSelectAll, onSelect, sort, onSort, labels, }: DataTableBodyProps<T>): import("react/jsx-runtime").JSX.Element;