@superdangerous/app-framework 4.14.0 → 4.15.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 (38) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/middleware/validation.d.ts +12 -12
  6. package/dist/services/emailService.d.ts +146 -0
  7. package/dist/services/emailService.d.ts.map +1 -0
  8. package/dist/services/emailService.js +649 -0
  9. package/dist/services/emailService.js.map +1 -0
  10. package/dist/services/index.d.ts +2 -0
  11. package/dist/services/index.d.ts.map +1 -1
  12. package/dist/services/index.js +2 -0
  13. package/dist/services/index.js.map +1 -1
  14. package/package.json +9 -1
  15. package/src/index.ts +14 -0
  16. package/src/services/emailService.ts +812 -0
  17. package/src/services/index.ts +14 -0
  18. package/ui/data-table/components/BatchActionsBar.tsx +53 -0
  19. package/ui/data-table/components/ColumnVisibility.tsx +111 -0
  20. package/ui/data-table/components/DataTable.tsx +492 -0
  21. package/ui/data-table/components/DataTablePage.tsx +238 -0
  22. package/ui/data-table/components/Pagination.tsx +203 -0
  23. package/ui/data-table/components/PaginationControls.tsx +122 -0
  24. package/ui/data-table/components/TableFilters.tsx +139 -0
  25. package/ui/data-table/components/index.ts +41 -0
  26. package/ui/data-table/components/types.ts +181 -0
  27. package/ui/data-table/hooks/index.ts +17 -0
  28. package/ui/data-table/hooks/useColumnOrder.ts +233 -0
  29. package/ui/data-table/hooks/useColumnVisibility.ts +128 -0
  30. package/ui/data-table/hooks/usePagination.ts +160 -0
  31. package/ui/data-table/hooks/useResizableColumns.ts +280 -0
  32. package/ui/data-table/index.ts +84 -0
  33. package/ui/dist/index.d.mts +207 -5
  34. package/ui/dist/index.d.ts +207 -5
  35. package/ui/dist/index.js +36 -43
  36. package/ui/dist/index.js.map +1 -1
  37. package/ui/dist/index.mjs +36 -43
  38. package/ui/dist/index.mjs.map +1 -1
@@ -46,3 +46,17 @@ export type {
46
46
  // Queue Service
47
47
  export { default as QueueService } from "./queueService.js";
48
48
  export type { QueueJob, QueueConfig, JobHandler } from "./queueService.js";
49
+
50
+ // Email Service
51
+ export {
52
+ EmailService,
53
+ getEmailService,
54
+ createEmailService,
55
+ } from "./emailService.js";
56
+ export type {
57
+ EmailConfig,
58
+ EmailOptions,
59
+ EmailServiceStatus,
60
+ NotificationEvent,
61
+ NotificationEventType,
62
+ } from "./emailService.js";
@@ -0,0 +1,53 @@
1
+ import { type ReactNode } from 'react';
2
+ import { X } from 'lucide-react';
3
+ import { Card } from '../../components/base/card';
4
+ import { Button } from '../../components/base/button';
5
+ import { cn } from '../../src/utils/cn';
6
+
7
+ export interface BatchActionsBarProps {
8
+ /** Number of selected items */
9
+ selectedCount: number;
10
+ /** Callback to clear selection */
11
+ onClear: () => void;
12
+ /** Action buttons to display on the right side */
13
+ children: ReactNode;
14
+ /** Label for the selected items (default: "item"/"items") */
15
+ itemLabel?: string;
16
+ /** Additional CSS classes */
17
+ className?: string;
18
+ }
19
+
20
+ /**
21
+ * A horizontal bar that appears when items are selected,
22
+ * showing the count and providing batch action buttons.
23
+ */
24
+ export function BatchActionsBar({
25
+ selectedCount,
26
+ onClear,
27
+ children,
28
+ itemLabel,
29
+ className,
30
+ }: BatchActionsBarProps) {
31
+ if (selectedCount === 0) return null;
32
+
33
+ const label = itemLabel ?? (selectedCount === 1 ? 'item' : 'items');
34
+
35
+ return (
36
+ <Card className={cn("p-3 bg-primary/5 border-primary/20", className)}>
37
+ <div className="flex items-center justify-between">
38
+ <div className="flex items-center gap-3">
39
+ <span className="font-medium text-sm" role="status" aria-live="polite">
40
+ {selectedCount} {label} selected
41
+ </span>
42
+ <Button variant="ghost" size="sm" onClick={onClear} aria-label="Clear selection">
43
+ <X className="h-4 w-4 mr-1" aria-hidden="true" />
44
+ Clear
45
+ </Button>
46
+ </div>
47
+ <div className="flex items-center gap-2" role="group" aria-label="Batch actions">
48
+ {children}
49
+ </div>
50
+ </div>
51
+ </Card>
52
+ );
53
+ }
@@ -0,0 +1,111 @@
1
+ import { Columns3, Check, Eye, EyeOff } from 'lucide-react';
2
+ import { Button } from '../../components/base/button';
3
+ import {
4
+ DropdownMenu,
5
+ DropdownMenuContent,
6
+ DropdownMenuItem,
7
+ DropdownMenuLabel,
8
+ DropdownMenuSeparator,
9
+ DropdownMenuTrigger,
10
+ } from '../../components/base/dropdown-menu';
11
+ import { cn } from '../../src/utils/cn';
12
+ import type { ColumnConfig } from '../hooks/useColumnVisibility';
13
+
14
+ interface ColumnVisibilityProps {
15
+ columns: ColumnConfig[];
16
+ isColumnVisible: (columnId: string) => boolean;
17
+ toggleColumn: (columnId: string) => void;
18
+ showAllColumns: () => void;
19
+ hideAllColumns: () => void;
20
+ }
21
+
22
+ export function ColumnVisibility({
23
+ columns,
24
+ isColumnVisible,
25
+ toggleColumn,
26
+ showAllColumns,
27
+ hideAllColumns,
28
+ }: ColumnVisibilityProps) {
29
+ const visibleCount = columns.filter(c => isColumnVisible(c.id)).length;
30
+ const toggleableColumns = columns.filter(c => !c.locked);
31
+
32
+ return (
33
+ <DropdownMenu>
34
+ <DropdownMenuTrigger asChild>
35
+ <Button variant="outline" size="sm" className="gap-2">
36
+ <Columns3 className="h-4 w-4" />
37
+ Columns
38
+ <span className="text-muted-foreground text-xs">
39
+ ({visibleCount}/{columns.length})
40
+ </span>
41
+ </Button>
42
+ </DropdownMenuTrigger>
43
+ <DropdownMenuContent align="end" className="w-48">
44
+ <DropdownMenuLabel className="font-normal text-xs text-muted-foreground">
45
+ Toggle columns
46
+ </DropdownMenuLabel>
47
+ <DropdownMenuSeparator />
48
+
49
+ {columns.map(column => {
50
+ const visible = isColumnVisible(column.id);
51
+ const isLocked = column.locked === true;
52
+
53
+ return (
54
+ <DropdownMenuItem
55
+ key={column.id}
56
+ onClick={(e) => {
57
+ e.preventDefault();
58
+ if (!isLocked) {
59
+ toggleColumn(column.id);
60
+ }
61
+ }}
62
+ className={cn(
63
+ 'gap-2 cursor-pointer',
64
+ isLocked && 'opacity-50 cursor-not-allowed'
65
+ )}
66
+ disabled={isLocked}
67
+ >
68
+ <div className="w-4 h-4 flex items-center justify-center">
69
+ {visible ? (
70
+ <Check className="h-3.5 w-3.5 text-primary" />
71
+ ) : (
72
+ <div className="h-3.5 w-3.5" />
73
+ )}
74
+ </div>
75
+ <span className="flex-1">{column.label}</span>
76
+ {isLocked && (
77
+ <span className="text-xs text-muted-foreground">Required</span>
78
+ )}
79
+ </DropdownMenuItem>
80
+ );
81
+ })}
82
+
83
+ {toggleableColumns.length > 1 && (
84
+ <>
85
+ <DropdownMenuSeparator />
86
+ <DropdownMenuItem
87
+ onClick={(e) => {
88
+ e.preventDefault();
89
+ showAllColumns();
90
+ }}
91
+ className="gap-2 cursor-pointer"
92
+ >
93
+ <Eye className="h-4 w-4" />
94
+ Show All
95
+ </DropdownMenuItem>
96
+ <DropdownMenuItem
97
+ onClick={(e) => {
98
+ e.preventDefault();
99
+ hideAllColumns();
100
+ }}
101
+ className="gap-2 cursor-pointer"
102
+ >
103
+ <EyeOff className="h-4 w-4" />
104
+ Hide Optional
105
+ </DropdownMenuItem>
106
+ </>
107
+ )}
108
+ </DropdownMenuContent>
109
+ </DropdownMenu>
110
+ );
111
+ }
@@ -0,0 +1,492 @@
1
+ import { useMemo, useCallback, useState, useEffect } from 'react';
2
+ import {
3
+ Table,
4
+ TableBody,
5
+ TableCell,
6
+ TableHead,
7
+ TableHeader,
8
+ TableRow,
9
+ } from '../../shadcn/table';
10
+ import { TooltipProvider } from '../../shadcn/tooltip';
11
+ import { ChevronUp, ChevronDown, ArrowUpDown, Loader2, Check, Eye, EyeOff } from 'lucide-react';
12
+ import { cn } from '../../utils';
13
+ import { useResizableColumns } from '../hooks/useResizableColumns';
14
+ import { useColumnVisibility } from '../hooks/useColumnVisibility';
15
+ import { useColumnOrder, useColumnDragDrop } from '../hooks/useColumnOrder';
16
+ import { usePagination } from '../hooks/usePagination';
17
+ import { Pagination } from './Pagination';
18
+ import type {
19
+ DataTableProps,
20
+ ColumnDef,
21
+ ColumnConfigCompat,
22
+ ColumnSizeConfig,
23
+ } from './types';
24
+
25
+ /**
26
+ * DataTable - Generic data table with full feature set
27
+ *
28
+ * Features:
29
+ * - Column resizing (drag handles)
30
+ * - Column reordering (drag-drop)
31
+ * - Column visibility toggle
32
+ * - Row selection with checkboxes
33
+ * - Sorting
34
+ * - Pagination
35
+ * - Sticky actions column
36
+ * - Context menu support
37
+ * - Header context menu for column visibility
38
+ */
39
+ export function DataTable<T>({
40
+ data,
41
+ columns,
42
+ storageKey,
43
+ getRowId,
44
+ selectable = false,
45
+ selectedIds,
46
+ onSelectionChange,
47
+ onRowClick,
48
+ onRowContextMenu,
49
+ sortField,
50
+ sortOrder,
51
+ onSort,
52
+ actionsColumn,
53
+ actionsColumnWidth = 80,
54
+ pageSize = 25,
55
+ pagination: externalPagination,
56
+ hidePagination = false,
57
+ className,
58
+ rowClassName,
59
+ enableHeaderContextMenu = true,
60
+ lockedColumns = [],
61
+ defaultColumnOrder,
62
+ loading = false,
63
+ emptyState,
64
+ }: DataTableProps<T>) {
65
+ // Build column configs for hooks
66
+ const columnSizeConfig = useMemo<ColumnSizeConfig[]>(() => {
67
+ const configs: ColumnSizeConfig[] = [];
68
+
69
+ if (selectable) {
70
+ configs.push({ key: 'select', defaultWidth: 40, minWidth: 40 });
71
+ }
72
+
73
+ columns.forEach((col) => {
74
+ configs.push({
75
+ key: col.id,
76
+ defaultWidth: col.width?.default ?? 150,
77
+ minWidth: col.width?.min ?? 80,
78
+ maxWidth: col.width?.max,
79
+ });
80
+ });
81
+
82
+ if (actionsColumn) {
83
+ configs.push({ key: 'actions', defaultWidth: actionsColumnWidth, minWidth: 60 });
84
+ }
85
+
86
+ return configs;
87
+ }, [columns, selectable, actionsColumn, actionsColumnWidth]);
88
+
89
+ const columnVisibilityConfig = useMemo<ColumnConfigCompat[]>(() => {
90
+ return columns.map((col) => ({
91
+ id: col.id,
92
+ label: typeof col.header === 'string' ? col.header : col.id,
93
+ defaultVisible: col.visibility?.default ?? true,
94
+ locked: col.visibility?.locked,
95
+ }));
96
+ }, [columns]);
97
+
98
+ const defaultOrder = useMemo(() => {
99
+ if (defaultColumnOrder) return defaultColumnOrder;
100
+ const order: string[] = [];
101
+ if (selectable) order.push('select');
102
+ columns.forEach((col) => order.push(col.id));
103
+ if (actionsColumn) order.push('actions');
104
+ return order;
105
+ }, [defaultColumnOrder, columns, selectable, actionsColumn]);
106
+
107
+ // Initialize hooks
108
+ const {
109
+ getResizeHandleProps,
110
+ getColumnStyle,
111
+ getTableStyle,
112
+ } = useResizableColumns({
113
+ tableId: storageKey,
114
+ columns: columnSizeConfig,
115
+ });
116
+
117
+ const columnVisibility = useColumnVisibility({
118
+ columns: columnVisibilityConfig,
119
+ storageKey,
120
+ });
121
+
122
+ const { columnOrder, moveColumn } = useColumnOrder({
123
+ storageKey: `${storageKey}-order`,
124
+ defaultOrder,
125
+ });
126
+
127
+ const { dragState, getDragHandleProps, showDropIndicator } = useColumnDragDrop(
128
+ columnOrder,
129
+ moveColumn,
130
+ [...lockedColumns, 'select', 'actions']
131
+ );
132
+
133
+ // Use external pagination if provided, otherwise use internal
134
+ const internalPagination = usePagination({
135
+ data,
136
+ pageSize,
137
+ storageKey,
138
+ });
139
+
140
+ const pagination = externalPagination || internalPagination;
141
+
142
+ // Header context menu state
143
+ const [headerContextMenu, setHeaderContextMenu] = useState<{ x: number; y: number } | null>(null);
144
+
145
+ const handleHeaderContextMenu = useCallback((e: React.MouseEvent) => {
146
+ if (!enableHeaderContextMenu) return;
147
+ e.preventDefault();
148
+ setHeaderContextMenu({ x: e.clientX, y: e.clientY });
149
+ }, [enableHeaderContextMenu]);
150
+
151
+ // Close header context menu on click outside
152
+ useEffect(() => {
153
+ if (!headerContextMenu) return;
154
+ const close = () => setHeaderContextMenu(null);
155
+ window.addEventListener('click', close);
156
+ return () => {
157
+ window.removeEventListener('click', close);
158
+ };
159
+ }, [headerContextMenu]);
160
+
161
+ // Selection helpers
162
+ const isAllSelected = useMemo(() => {
163
+ if (!selectable || !selectedIds || pagination.paginatedData.length === 0) return false;
164
+ return pagination.paginatedData.every((item) => selectedIds.has(getRowId(item)));
165
+ }, [selectable, selectedIds, pagination.paginatedData, getRowId]);
166
+
167
+ const isSomeSelected = useMemo(() => {
168
+ if (!selectable || !selectedIds) return false;
169
+ const selected = pagination.paginatedData.filter((item) => selectedIds.has(getRowId(item)));
170
+ return selected.length > 0 && selected.length < pagination.paginatedData.length;
171
+ }, [selectable, selectedIds, pagination.paginatedData, getRowId]);
172
+
173
+ const toggleSelection = useCallback((itemId: string) => {
174
+ if (!onSelectionChange || !selectedIds) return;
175
+ const next = new Set(selectedIds);
176
+ if (next.has(itemId)) {
177
+ next.delete(itemId);
178
+ } else {
179
+ next.add(itemId);
180
+ }
181
+ onSelectionChange(next);
182
+ }, [selectedIds, onSelectionChange]);
183
+
184
+ const selectAll = useCallback(() => {
185
+ if (!onSelectionChange) return;
186
+ const ids = new Set(pagination.paginatedData.map(getRowId));
187
+ onSelectionChange(ids);
188
+ }, [pagination.paginatedData, getRowId, onSelectionChange]);
189
+
190
+ const clearSelection = useCallback(() => {
191
+ if (!onSelectionChange) return;
192
+ onSelectionChange(new Set());
193
+ }, [onSelectionChange]);
194
+
195
+ // Get sort icon
196
+ const getSortIcon = useCallback((field: string) => {
197
+ if (sortField !== field) {
198
+ return <ArrowUpDown className="h-3.5 w-3.5 text-muted-foreground" />;
199
+ }
200
+ return sortOrder === 'asc'
201
+ ? <ChevronUp className="h-3.5 w-3.5" />
202
+ : <ChevronDown className="h-3.5 w-3.5" />;
203
+ }, [sortField, sortOrder]);
204
+
205
+ // Find column def by id
206
+ const getColumnDef = useCallback((id: string): ColumnDef<T> | undefined => {
207
+ return columns.find((col) => col.id === id);
208
+ }, [columns]);
209
+
210
+ // Render header cell content
211
+ const renderHeaderContent = useCallback((col: ColumnDef<T>) => {
212
+ const headerProps = {
213
+ columnId: col.id,
214
+ isSorted: sortField === col.sortKey,
215
+ sortDirection: sortField === col.sortKey ? sortOrder : undefined,
216
+ };
217
+
218
+ if (typeof col.header === 'function') {
219
+ return col.header(headerProps);
220
+ }
221
+
222
+ if (col.sortKey && onSort) {
223
+ return (
224
+ <button
225
+ onClick={() => onSort(col.sortKey!)}
226
+ className={cn(
227
+ 'flex items-center gap-1 hover:text-foreground transition-colors',
228
+ sortField === col.sortKey && 'text-primary font-medium'
229
+ )}
230
+ >
231
+ {col.header}
232
+ {getSortIcon(col.sortKey)}
233
+ </button>
234
+ );
235
+ }
236
+
237
+ return col.header;
238
+ }, [sortField, sortOrder, onSort, getSortIcon]);
239
+
240
+ return (
241
+ <TooltipProvider>
242
+ <>
243
+ {/* Table - scrolling handled by parent container */}
244
+ <Table
245
+ style={getTableStyle()}
246
+ className={cn('resizable-table sticky-actions-table', className)}
247
+ >
248
+ <TableHeader>
249
+ <TableRow onContextMenu={handleHeaderContextMenu}>
250
+ {columnOrder.map((colKey) => {
251
+ // Select column (sticky on left)
252
+ if (colKey === 'select' && selectable) {
253
+ return (
254
+ <TableHead
255
+ key="select"
256
+ className="sticky-select-header w-10 sticky left-0 z-20 bg-muted relative after:absolute after:right-0 after:top-0 after:bottom-0 after:w-px after:bg-border"
257
+ >
258
+ <input
259
+ type="checkbox"
260
+ checked={isAllSelected}
261
+ ref={(el) => {
262
+ if (el) el.indeterminate = isSomeSelected;
263
+ }}
264
+ onChange={(e) => e.target.checked ? selectAll() : clearSelection()}
265
+ className="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary cursor-pointer"
266
+ title={isAllSelected ? 'Deselect all' : 'Select all visible'}
267
+ />
268
+ </TableHead>
269
+ );
270
+ }
271
+
272
+ // Data columns
273
+ const col = getColumnDef(colKey);
274
+ if (!col) return null;
275
+ if (!columnVisibility.isColumnVisible(colKey)) return null;
276
+
277
+ return (
278
+ <TableHead
279
+ key={colKey}
280
+ style={getColumnStyle(colKey)}
281
+ {...getDragHandleProps(colKey)}
282
+ className={cn(
283
+ 'cursor-grab relative',
284
+ dragState.draggedId === colKey && 'column-dragging opacity-50',
285
+ showDropIndicator(colKey) && 'drop-indicator'
286
+ )}
287
+ >
288
+ {renderHeaderContent(col)}
289
+ <div {...getResizeHandleProps(colKey)} />
290
+ </TableHead>
291
+ );
292
+ })}
293
+
294
+ {/* Actions column header */}
295
+ {actionsColumn && (
296
+ <TableHead
297
+ className="sticky right-0 z-20 bg-muted text-center relative before:absolute before:left-0 before:top-0 before:bottom-0 before:w-px before:bg-border"
298
+ style={{ width: actionsColumnWidth, minWidth: actionsColumnWidth, maxWidth: actionsColumnWidth }}
299
+ >
300
+ Actions
301
+ </TableHead>
302
+ )}
303
+ </TableRow>
304
+ </TableHeader>
305
+
306
+ <TableBody>
307
+ {loading ? (
308
+ <TableRow>
309
+ <TableCell
310
+ colSpan={columnOrder.length + (actionsColumn ? 1 : 0)}
311
+ className="!p-0 h-32"
312
+ >
313
+ <div className="sticky left-0 w-screen max-w-full h-full bg-white flex justify-center items-center">
314
+ <div className="flex items-center gap-2 text-muted-foreground">
315
+ <Loader2 className="h-5 w-5 animate-spin" />
316
+ Loading...
317
+ </div>
318
+ </div>
319
+ </TableCell>
320
+ </TableRow>
321
+ ) : pagination.paginatedData.length === 0 ? null : (
322
+ pagination.paginatedData.map((item) => {
323
+ const rowId = getRowId(item);
324
+ const isSelected = selectedIds?.has(rowId) ?? false;
325
+
326
+ return (
327
+ <TableRow
328
+ key={rowId}
329
+ className={cn(
330
+ 'cursor-pointer bg-white hover:bg-muted/50',
331
+ isSelected && 'bg-primary/5',
332
+ rowClassName?.(item)
333
+ )}
334
+ onClick={() => onRowClick?.(item)}
335
+ onContextMenu={(e) => {
336
+ if (onRowContextMenu) {
337
+ e.preventDefault();
338
+ onRowContextMenu(item, { x: e.clientX, y: e.clientY });
339
+ }
340
+ }}
341
+ >
342
+ {columnOrder.map((colKey) => {
343
+ // Select cell (sticky on left)
344
+ if (colKey === 'select' && selectable) {
345
+ return (
346
+ <TableCell
347
+ key="select"
348
+ className={cn(
349
+ 'sticky-select-cell w-10 sticky left-0 z-10 relative after:absolute after:right-0 after:top-0 after:bottom-0 after:w-px after:bg-border',
350
+ isSelected ? 'bg-primary/5' : 'bg-white'
351
+ )}
352
+ onClick={(e) => e.stopPropagation()}
353
+ >
354
+ <input
355
+ type="checkbox"
356
+ checked={isSelected}
357
+ onChange={() => toggleSelection(rowId)}
358
+ className="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary cursor-pointer"
359
+ />
360
+ </TableCell>
361
+ );
362
+ }
363
+
364
+ // Data cells
365
+ const col = getColumnDef(colKey);
366
+ if (!col) return null;
367
+ if (!columnVisibility.isColumnVisible(colKey)) return null;
368
+
369
+ const cellProps = {
370
+ columnId: colKey,
371
+ isDragging: dragState.draggedId === colKey,
372
+ };
373
+
374
+ return (
375
+ <TableCell
376
+ key={colKey}
377
+ style={getColumnStyle(colKey)}
378
+ className={cn(
379
+ col.className,
380
+ dragState.draggedId === colKey && 'column-dragging'
381
+ )}
382
+ >
383
+ {col.cell(item, cellProps)}
384
+ </TableCell>
385
+ );
386
+ })}
387
+
388
+ {/* Actions cell */}
389
+ {actionsColumn && (
390
+ <TableCell
391
+ className={cn(
392
+ 'sticky right-0 z-10 text-center relative before:absolute before:left-0 before:top-0 before:bottom-0 before:w-px before:bg-border',
393
+ isSelected ? 'bg-primary/5' : 'bg-white'
394
+ )}
395
+ style={{ width: actionsColumnWidth, minWidth: actionsColumnWidth, maxWidth: actionsColumnWidth }}
396
+ onClick={(e) => e.stopPropagation()}
397
+ >
398
+ {actionsColumn(item)}
399
+ </TableCell>
400
+ )}
401
+ </TableRow>
402
+ );
403
+ })
404
+ )}
405
+ </TableBody>
406
+ </Table>
407
+
408
+ {/* Empty state - rendered outside table for proper positioning */}
409
+ {!loading && pagination.paginatedData.length === 0 && (
410
+ <div className="empty-state-container flex-1 flex items-center justify-center bg-white">
411
+ {emptyState || <span className="block text-center text-muted-foreground py-8">No data</span>}
412
+ </div>
413
+ )}
414
+
415
+ {/* Pagination (hidden when using external pagination controls) */}
416
+ {!hidePagination && !loading && pagination.totalPages > 1 && (
417
+ <Pagination
418
+ page={pagination.page}
419
+ pageSize={pagination.pageSize}
420
+ totalItems={pagination.totalItems}
421
+ totalPages={pagination.totalPages}
422
+ startIndex={pagination.startIndex}
423
+ endIndex={pagination.endIndex}
424
+ canGoPrev={pagination.canGoPrev}
425
+ canGoNext={pagination.canGoNext}
426
+ onPageChange={pagination.setPage}
427
+ onPageSizeChange={pagination.setPageSize}
428
+ onNextPage={pagination.nextPage}
429
+ onPrevPage={pagination.prevPage}
430
+ onFirstPage={'firstPage' in pagination ? (pagination as { firstPage: () => void }).firstPage : () => pagination.setPage(1)}
431
+ onLastPage={'lastPage' in pagination ? (pagination as { lastPage: () => void }).lastPage : () => pagination.setPage(pagination.totalPages)}
432
+ pageSizeOptions={pagination.pageSizeOptions}
433
+ />
434
+ )}
435
+
436
+ {/* Header Context Menu for Column Visibility */}
437
+ {headerContextMenu && (
438
+ <div
439
+ className="fixed z-50 min-w-[200px] overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95"
440
+ style={{
441
+ top: headerContextMenu.y,
442
+ left: headerContextMenu.x,
443
+ maxHeight: `calc(100vh - ${headerContextMenu.y}px - 20px)`,
444
+ }}
445
+ onClick={(e) => e.stopPropagation()}
446
+ >
447
+ <div className="px-2 py-1.5 text-xs font-medium text-muted-foreground">
448
+ Toggle columns
449
+ </div>
450
+ <div className="h-px bg-border my-1" />
451
+ {columnVisibility.columns.map(column => {
452
+ const visible = columnVisibility.isColumnVisible(column.id);
453
+ const isLocked = column.locked === true;
454
+ return (
455
+ <button
456
+ key={column.id}
457
+ onClick={() => !isLocked && columnVisibility.toggleColumn(column.id)}
458
+ disabled={isLocked}
459
+ className={cn(
460
+ 'flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded-sm hover:bg-accent',
461
+ isLocked && 'opacity-50 cursor-not-allowed'
462
+ )}
463
+ >
464
+ <div className="w-4 h-4 flex items-center justify-center">
465
+ {visible && <Check className="h-3.5 w-3.5 text-primary" />}
466
+ </div>
467
+ <span className="flex-1 text-left">{column.label}</span>
468
+ {isLocked && <span className="text-xs text-muted-foreground">Required</span>}
469
+ </button>
470
+ );
471
+ })}
472
+ <div className="h-px bg-border my-1" />
473
+ <button
474
+ onClick={() => columnVisibility.showAllColumns()}
475
+ className="flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded-sm hover:bg-accent"
476
+ >
477
+ <Eye className="h-4 w-4" />
478
+ Show All
479
+ </button>
480
+ <button
481
+ onClick={() => columnVisibility.hideAllColumns()}
482
+ className="flex items-center gap-2 w-full px-2 py-1.5 text-sm rounded-sm hover:bg-accent"
483
+ >
484
+ <EyeOff className="h-4 w-4" />
485
+ Hide Optional
486
+ </button>
487
+ </div>
488
+ )}
489
+ </>
490
+ </TooltipProvider>
491
+ );
492
+ }