@nccirtu/tablefy 0.7.3 → 0.7.5

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.
package/dist/index.js CHANGED
@@ -14,9 +14,9 @@ var badge = require('@/components/ui/badge');
14
14
  var checkbox = require('@/components/ui/checkbox');
15
15
  var tooltip = require('@/components/ui/tooltip');
16
16
  var progress = require('@/components/ui/progress');
17
- var dialog = require('@/components/ui/dialog');
17
+ var alertDialog = require('@/components/ui/alert-dialog');
18
18
 
19
- function DataTableHeader({ title, description, actions = [], search, searchValue = "", onSearchChange, table, selectedCount = 0, className, }) {
19
+ function DataTableHeader({ title, description, actions = [], search, searchValue = "", onSearchChange, table, selectedCount = 0, enableColumnVisibility = false, columnVisibilityLabel = "Spalten", className, }) {
20
20
  const normalActions = actions.filter((a) => !a.bulk && !a.hidden);
21
21
  const bulkActions = actions.filter((a) => a.bulk && !a.hidden);
22
22
  const showBulkActions = selectedCount > 0 && bulkActions.length > 0;
@@ -50,7 +50,14 @@ function DataTableHeader({ title, description, actions = [], search, searchValue
50
50
  return null;
51
51
  }
52
52
  return (jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col gap-4", className), children: [(title || description) && (jsxRuntime.jsxs("div", { className: "space-y-1", children: [title && (jsxRuntime.jsx("h2", { className: "text-xl font-semibold tracking-tight", children: title })), description && (jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: description }))] })), (search?.enabled || normalActions.length > 0 || showBulkActions) && (jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-4 mb-4", children: [search?.enabled && (jsxRuntime.jsxs("div", { className: "relative max-w-sm flex-1", children: [jsxRuntime.jsx(lucideReact.Search, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }), jsxRuntime.jsx(input.Input, { placeholder: search.placeholder || "Suchen...", value: searchValue, onChange: (e) => onSearchChange?.(e.target.value), className: "pl-9 pr-9" }), searchValue && (jsxRuntime.jsx("button", { onClick: () => onSearchChange?.(""), className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground", children: jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }) }))] })), jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [showBulkActions && (jsxRuntime.jsxs("span", { className: "text-sm text-muted-foreground", children: [selectedCount, " ausgew\u00E4hlt"] })), showBulkActions &&
53
- bulkActions.map((action, index) => renderAction(action, index)), normalActions.length > 0 &&
53
+ bulkActions.map((action, index) => renderAction(action, index)), enableColumnVisibility && table && (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsxs(button.Button, { variant: "outline", size: "default", children: [jsxRuntime.jsx(lucideReact.Columns, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "ml-2", children: columnVisibilityLabel }), jsxRuntime.jsx(lucideReact.ChevronDown, { className: "ml-2 h-4 w-4" })] }) }), jsxRuntime.jsxs(dropdownMenu.DropdownMenuContent, { align: "end", className: "w-[200px]", children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuLabel, { children: columnVisibilityLabel }), jsxRuntime.jsx(dropdownMenu.DropdownMenuSeparator, {}), table
54
+ .getAllColumns()
55
+ .filter((column) => column.getCanHide())
56
+ .map((column) => {
57
+ const meta = column.columnDef.meta;
58
+ const label = meta?.visibilityLabel || column.id;
59
+ return (jsxRuntime.jsx(dropdownMenu.DropdownMenuCheckboxItem, { checked: column.getIsVisible(), onCheckedChange: (value) => column.toggleVisibility(!!value), children: label }, column.id));
60
+ })] })] })), normalActions.length > 0 &&
54
61
  normalActions.map((action, index) => renderAction(action, index))] })] }))] }));
55
62
  }
56
63
 
@@ -376,7 +383,16 @@ class EmptyStateBuilder {
376
383
  function DataTable({ columns, data, config = {}, className, isLoading = false, isError = false, onRetry, }) {
377
384
  const [sorting, setSorting] = react.useState(config.defaultSort ? [config.defaultSort] : []);
378
385
  const [columnFilters, setColumnFilters] = react.useState([]);
379
- const [columnVisibility, setColumnVisibility] = react.useState({});
386
+ // Initialize column visibility based on visibleByDefault
387
+ const [columnVisibility, setColumnVisibility] = react.useState(() => {
388
+ const initialVisibility = {};
389
+ columns.forEach((column) => {
390
+ if (column.meta?.visibleByDefault === false) {
391
+ initialVisibility[column.accessorKey || column.id] = false;
392
+ }
393
+ });
394
+ return initialVisibility;
395
+ });
380
396
  const [rowSelection, setRowSelection] = react.useState({});
381
397
  const [globalFilter, setGlobalFilter] = react.useState("");
382
398
  const table$1 = reactTable.useReactTable({
@@ -424,7 +440,7 @@ function DataTable({ columns, data, config = {}, className, isLoading = false, i
424
440
  };
425
441
  const selectedCount = table$1.getFilteredSelectedRowModel().rows.length;
426
442
  const hasRows = table$1.getRowModel().rows?.length > 0;
427
- return (jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col", className), children: [jsxRuntime.jsx(DataTableHeader, { title: config.title, description: config.description, actions: config.headerActions, search: config.search, searchValue: globalFilter, onSearchChange: setGlobalFilter, table: table$1, selectedCount: selectedCount }), jsxRuntime.jsx("div", { className: utils.cn("overflow-hidden", config.bordered !== false && "rounded-md border"), children: jsxRuntime.jsxs(table.Table, { className: utils.cn(densityClasses[config.density || "default"], config.striped ? "[&_tr:nth-child(even)]:bg-muted/50" : "", config.hoverable !== false && "[&_tr:hover]:bg-muted/50"), children: [jsxRuntime.jsx(table.TableHeader, { children: table$1.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(table.TableRow, { children: headerGroup.headers.map((header) => (jsxRuntime.jsx(table.TableHead, { children: header.isPlaceholder
443
+ return (jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col", className), children: [jsxRuntime.jsx(DataTableHeader, { title: config.title, description: config.description, actions: config.headerActions, search: config.search, searchValue: globalFilter, onSearchChange: setGlobalFilter, table: table$1, selectedCount: selectedCount, enableColumnVisibility: config.enableColumnVisibility, columnVisibilityLabel: config.columnVisibilityLabel }), jsxRuntime.jsx("div", { className: utils.cn("overflow-hidden", config.bordered !== false && "rounded-md border"), children: jsxRuntime.jsxs(table.Table, { className: utils.cn(densityClasses[config.density || "default"], config.striped ? "[&_tr:nth-child(even)]:bg-muted/50" : "", config.hoverable !== false && "[&_tr:hover]:bg-muted/50"), children: [jsxRuntime.jsx(table.TableHeader, { children: table$1.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(table.TableRow, { children: headerGroup.headers.map((header) => (jsxRuntime.jsx(table.TableHead, { children: header.isPlaceholder
428
444
  ? null
429
445
  : reactTable.flexRender(header.column.columnDef.header, header.getContext()) }, header.id))) }, headerGroup.id))) }), jsxRuntime.jsx(table.TableBody, { children: isLoading ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: columns.length, className: "h-[400px]", children: jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4", children: [jsxRuntime.jsxs("svg", { className: "animate-spin h-8 w-8 text-muted-foreground", viewBox: "0 0 24 24", children: [jsxRuntime.jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4", fill: "none" }), jsxRuntime.jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })] }), jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: "Laden..." })] }) }) }) })) : hasRows ? (table$1.getRowModel().rows.map((row) => (jsxRuntime.jsx(table.TableRow, { "data-state": row.getIsSelected() && "selected", children: row.getVisibleCells().map((cell) => (jsxRuntime.jsx(table.TableCell, { children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))) }, row.id)))) : (jsxRuntime.jsx(DataTableEmpty, { config: getEmptyState(), colSpan: columns.length })) })] }) }), config.pagination?.enabled && hasRows && (jsxRuntime.jsx(DataTablePagination, { table: table$1, config: config.pagination }))] }));
430
446
  }
@@ -466,6 +482,14 @@ class BaseColumn {
466
482
  this.config.hidden = hidden;
467
483
  return this;
468
484
  }
485
+ visibleByDefault(visible = true) {
486
+ this.config.visibleByDefault = visible;
487
+ return this;
488
+ }
489
+ visibilityLabel(label) {
490
+ this.config.visibilityLabel = label;
491
+ return this;
492
+ }
469
493
  alignLeft() {
470
494
  this.config.align = "left";
471
495
  return this;
@@ -1728,7 +1752,10 @@ function ConfirmProvider({ children }) {
1728
1752
  setQueue((q) => q.slice(1));
1729
1753
  }
1730
1754
  };
1731
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(dialog.Dialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxRuntime.jsxs(dialog.DialogContent, { children: [jsxRuntime.jsxs(dialog.DialogHeader, { children: [jsxRuntime.jsx(dialog.DialogTitle, { children: currentRequest?.options?.title || "Bestätigung erforderlich" }), currentRequest?.options?.description && (jsxRuntime.jsx(dialog.DialogDescription, { children: currentRequest.options.description }))] }), jsxRuntime.jsxs(dialog.DialogFooter, { children: [jsxRuntime.jsx(button.Button, { variant: "outline", onClick: handleCancel, children: currentRequest?.options.cancelLabel || "Abbrechen" }), jsxRuntime.jsx(button.Button, { variant: currentRequest?.options.variant || "default", onClick: handleConfirm, children: currentRequest?.options.confirmLabel || "Bestätigen" })] })] }) })] }));
1755
+ const { title, description, confirmLabel, cancelLabel, variant, icon, image, } = currentRequest?.options || {};
1756
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(alertDialog.AlertDialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxRuntime.jsxs(alertDialog.AlertDialogContent, { className: "max-w-md", children: [jsxRuntime.jsxs(alertDialog.AlertDialogHeader, { children: [image && (jsxRuntime.jsx("div", { className: "mb-4 flex justify-center", children: jsxRuntime.jsx("img", { src: image, alt: "Confirmation", className: "h-24 w-24 object-contain" }) })), icon && !image && (jsxRuntime.jsx("div", { className: "mb-4 flex justify-center text-6xl", children: icon })), jsxRuntime.jsx(alertDialog.AlertDialogTitle, { className: "text-center", children: title || "Bestätigung erforderlich" }), description && (jsxRuntime.jsx(alertDialog.AlertDialogDescription, { className: "text-center", children: description }))] }), jsxRuntime.jsxs(alertDialog.AlertDialogFooter, { className: "sm:justify-center", children: [jsxRuntime.jsx(alertDialog.AlertDialogCancel, { onClick: handleCancel, children: cancelLabel || "Abbrechen" }), jsxRuntime.jsx(alertDialog.AlertDialogAction, { onClick: handleConfirm, className: variant === "destructive"
1757
+ ? "bg-destructive text-destructive-foreground hover:bg-destructive/90"
1758
+ : "", children: confirmLabel || "Bestätigen" })] })] }) })] }));
1732
1759
  }
1733
1760
 
1734
1761
  exports.AvatarGroupColumn = AvatarGroupColumn;