@nccirtu/tablefy 0.8.0 → 0.8.2

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,5 +1,2 @@
1
1
  export { TableSchema } from "./table-schema";
2
2
  export { EmptyStateBuilder } from "./empty-state";
3
- export { HeaderActions } from "./header-actions";
4
- export { HeaderActionGroup } from "./header-action-group";
5
- export type { HeaderActionItem } from "./header-actions";
@@ -2,48 +2,9 @@ import { ColumnDef } from "@tanstack/react-table";
2
2
  import { DataTableConfig } from "../types/table";
3
3
  import { HeaderAction } from "../types/actions";
4
4
  import { EmptyStateConfig } from "../types/empty-state";
5
- import React from "react";
6
5
  type ColumnBuilder<TData> = {
7
6
  build(): ColumnDef<TData, unknown>;
8
7
  };
9
- /**
10
- * Header Actions Builder
11
- * Fluent API for building header actions
12
- */
13
- declare class HeaderActionsBuilder<TData> {
14
- private actions;
15
- create(config: {
16
- label: string;
17
- href?: string;
18
- onClick?: () => void;
19
- icon?: React.ReactNode;
20
- }): this;
21
- export(config: {
22
- label: string;
23
- icon?: React.ReactNode;
24
- formats?: Array<{
25
- label: string;
26
- onClick: () => void;
27
- }>;
28
- }): this;
29
- import(config: {
30
- label: string;
31
- icon?: React.ReactNode;
32
- onClick?: () => void;
33
- }): this;
34
- bulkExport(config: {
35
- label: string;
36
- icon?: React.ReactNode;
37
- onExport: (rows: TData[]) => void;
38
- }): this;
39
- bulkDelete(config: {
40
- label: string;
41
- icon?: React.ReactNode;
42
- onDelete: (rows: TData[]) => void;
43
- }): this;
44
- custom(action: HeaderAction<TData>): this;
45
- build(): HeaderAction<TData>[];
46
- }
47
8
  /**
48
9
  * Table Schema Builder
49
10
  * Fluent API for building complete table configurations
@@ -54,7 +15,7 @@ export declare class TableSchema<TData> {
54
15
  static make<TData>(): TableSchema<TData>;
55
16
  description(text: string): this;
56
17
  title(text: string): this;
57
- headerActions(builder: (b: HeaderActionsBuilder<TData>) => HeaderActionsBuilder<TData>): this;
18
+ headerActions(actions: HeaderAction<TData>[]): this;
58
19
  emptyState(config: EmptyStateConfig): this;
59
20
  searchEmptyState(config: EmptyStateConfig): this;
60
21
  filterEmptyState(config: EmptyStateConfig): this;
@@ -1,5 +1,2 @@
1
1
  export { TableSchema } from "./table-schema";
2
2
  export { EmptyStateBuilder } from "./empty-state";
3
- export { HeaderActions } from "./header-actions";
4
- export { HeaderActionGroup } from "./header-action-group";
5
- export type { HeaderActionItem } from "./header-actions";
@@ -2,48 +2,9 @@ import { ColumnDef } from "@tanstack/react-table";
2
2
  import { DataTableConfig } from "../types/table";
3
3
  import { HeaderAction } from "../types/actions";
4
4
  import { EmptyStateConfig } from "../types/empty-state";
5
- import React from "react";
6
5
  type ColumnBuilder<TData> = {
7
6
  build(): ColumnDef<TData, unknown>;
8
7
  };
9
- /**
10
- * Header Actions Builder
11
- * Fluent API for building header actions
12
- */
13
- declare class HeaderActionsBuilder<TData> {
14
- private actions;
15
- create(config: {
16
- label: string;
17
- href?: string;
18
- onClick?: () => void;
19
- icon?: React.ReactNode;
20
- }): this;
21
- export(config: {
22
- label: string;
23
- icon?: React.ReactNode;
24
- formats?: Array<{
25
- label: string;
26
- onClick: () => void;
27
- }>;
28
- }): this;
29
- import(config: {
30
- label: string;
31
- icon?: React.ReactNode;
32
- onClick?: () => void;
33
- }): this;
34
- bulkExport(config: {
35
- label: string;
36
- icon?: React.ReactNode;
37
- onExport: (rows: TData[]) => void;
38
- }): this;
39
- bulkDelete(config: {
40
- label: string;
41
- icon?: React.ReactNode;
42
- onDelete: (rows: TData[]) => void;
43
- }): this;
44
- custom(action: HeaderAction<TData>): this;
45
- build(): HeaderAction<TData>[];
46
- }
47
8
  /**
48
9
  * Table Schema Builder
49
10
  * Fluent API for building complete table configurations
@@ -54,7 +15,7 @@ export declare class TableSchema<TData> {
54
15
  static make<TData>(): TableSchema<TData>;
55
16
  description(text: string): this;
56
17
  title(text: string): this;
57
- headerActions(builder: (b: HeaderActionsBuilder<TData>) => HeaderActionsBuilder<TData>): this;
18
+ headerActions(actions: HeaderAction<TData>[]): this;
58
19
  emptyState(config: EmptyStateConfig): this;
59
20
  searchEmptyState(config: EmptyStateConfig): this;
60
21
  filterEmptyState(config: EmptyStateConfig): this;
@@ -1,7 +1,6 @@
1
1
  export { DataTable } from "./tablefy/data-table";
2
2
  export { DataTableSchema } from "./tablefy/data-table-schema";
3
- export { TableSchema, EmptyStateBuilder, HeaderActions, HeaderActionGroup, } from "./builders";
4
- export type { HeaderActionItem } from "./builders";
3
+ export { TableSchema, EmptyStateBuilder } from "./builders";
5
4
  export { AvatarGroupColumn, AvatarGroupColumn as avatarGroupColumn, } from "./columns/avatar-group-column";
6
5
  export { BadgeColumn, BadgeColumn as badgeColumn, } from "./columns/badge-column";
7
6
  export { ButtonColumn, ButtonColumn as buttonColumn, } from "./columns/button-column";
@@ -4,8 +4,8 @@ import { ReactNode } from "react";
4
4
  * Defines actions that can be displayed in the table header
5
5
  */
6
6
  export interface HeaderAction<TData = unknown> {
7
- id: string;
8
- label: string;
7
+ id?: string;
8
+ label?: string;
9
9
  icon?: ReactNode;
10
10
  variant?: "default" | "secondary" | "outline" | "ghost" | "destructive";
11
11
  size?: "default" | "sm" | "lg" | "icon";
@@ -16,5 +16,6 @@ export interface HeaderAction<TData = unknown> {
16
16
  bulk?: boolean;
17
17
  bulkOnClick?: (selectedRows: TData[]) => void;
18
18
  hidden?: boolean;
19
+ render?: () => ReactNode;
19
20
  children?: Omit<HeaderAction<TData>, "children" | "bulk">[];
20
21
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { DataTable } from "./tablefy/data-table";
2
2
  export { DataTableSchema } from "./tablefy/data-table-schema";
3
- export { TableSchema, EmptyStateBuilder, HeaderActions, HeaderActionGroup, } from "./builders";
4
- export type { HeaderActionItem } from "./builders";
3
+ export { TableSchema, EmptyStateBuilder } from "./builders";
5
4
  export { AvatarGroupColumn, AvatarGroupColumn as avatarGroupColumn, } from "./columns/avatar-group-column";
6
5
  export { BadgeColumn, BadgeColumn as badgeColumn, } from "./columns/badge-column";
7
6
  export { ButtonColumn, ButtonColumn as buttonColumn, } from "./columns/button-column";
package/dist/index.esm.js CHANGED
@@ -24,6 +24,10 @@ function DataTableHeader({ title, description, actions = [], search, searchValue
24
24
  return table.getFilteredSelectedRowModel().rows.map((row) => row.original);
25
25
  };
26
26
  const renderAction = (action, index) => {
27
+ // Custom render function takes priority
28
+ if (action.render) {
29
+ return jsx("div", { children: action.render() }, action.id || index);
30
+ }
27
31
  if (action.children && action.children.length > 0) {
28
32
  return (jsxs(DropdownMenu, { children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsxs(Button, { variant: action.variant || "outline", size: action.size || "default", disabled: action.disabled || action.loading, children: [action.icon, jsx("span", { className: cn(action.icon ? "ml-2" : ""), children: action.label }), jsx(ChevronDown, { className: "ml-2 h-4 w-4" })] }) }), jsx(DropdownMenuContent, { align: "end", children: action.children.map((child, childIndex) => (jsxs(DropdownMenuItem, { onClick: child.onClick, className: cn(child.variant === "destructive" &&
29
33
  "text-destructive focus:text-destructive"), children: [child.icon && jsx("span", { className: "mr-2", children: child.icon }), child.label] }, child.id || childIndex))) })] }, action.id || index));
@@ -73,87 +77,6 @@ function DataTablePagination({ table, config, className, }) {
73
77
  : 0, " ", "von ", Math.max(table.getPageCount(), 0)] })), jsxs("div", { className: "flex items-center gap-1", children: [jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(0), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronsLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Erste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.previousPage(), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Vorherige Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.nextPage(), disabled: !table.getCanNextPage(), children: [jsx(ChevronRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "N\u00E4chste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(table.getPageCount() - 1), disabled: !table.getCanNextPage(), children: [jsx(ChevronsRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Letzte Seite" })] })] })] })] }));
74
78
  }
75
79
 
76
- /**
77
- * Header Actions Builder
78
- * Fluent API for building header actions
79
- */
80
- class HeaderActionsBuilder {
81
- actions = [];
82
- create(config) {
83
- this.actions.push({
84
- id: "create",
85
- label: config.label,
86
- href: config.href,
87
- onClick: config.onClick,
88
- icon: config.icon,
89
- variant: "default",
90
- });
91
- return this;
92
- }
93
- export(config) {
94
- if (config.formats && config.formats.length > 0) {
95
- this.actions.push({
96
- id: "export",
97
- label: config.label,
98
- icon: config.icon,
99
- variant: "outline",
100
- children: config.formats.map((format, index) => ({
101
- id: `export-${index}`,
102
- label: format.label,
103
- onClick: format.onClick,
104
- })),
105
- });
106
- }
107
- else {
108
- this.actions.push({
109
- id: "export",
110
- label: config.label,
111
- icon: config.icon,
112
- variant: "outline",
113
- });
114
- }
115
- return this;
116
- }
117
- import(config) {
118
- this.actions.push({
119
- id: "import",
120
- label: config.label,
121
- icon: config.icon,
122
- onClick: config.onClick,
123
- variant: "outline",
124
- });
125
- return this;
126
- }
127
- bulkExport(config) {
128
- this.actions.push({
129
- id: "bulk-export",
130
- label: config.label,
131
- icon: config.icon,
132
- bulk: true,
133
- bulkOnClick: config.onExport,
134
- variant: "outline",
135
- });
136
- return this;
137
- }
138
- bulkDelete(config) {
139
- this.actions.push({
140
- id: "bulk-delete",
141
- label: config.label,
142
- icon: config.icon,
143
- bulk: true,
144
- bulkOnClick: config.onDelete,
145
- variant: "destructive",
146
- });
147
- return this;
148
- }
149
- custom(action) {
150
- this.actions.push(action);
151
- return this;
152
- }
153
- build() {
154
- return this.actions;
155
- }
156
- }
157
80
  /**
158
81
  * Table Schema Builder
159
82
  * Fluent API for building complete table configurations
@@ -173,9 +96,8 @@ class TableSchema {
173
96
  this.config.title = text;
174
97
  return this;
175
98
  }
176
- headerActions(builder) {
177
- const actionsBuilder = new HeaderActionsBuilder();
178
- this.config.headerActions = builder(actionsBuilder).build();
99
+ headerActions(actions) {
100
+ this.config.headerActions = actions;
179
101
  return this;
180
102
  }
181
103
  emptyState(config) {
@@ -378,183 +300,6 @@ class EmptyStateBuilder {
378
300
  }
379
301
  }
380
302
 
381
- class HeaderActions {
382
- config = {
383
- actions: [],
384
- };
385
- static make() {
386
- return new HeaderActions();
387
- }
388
- label(label) {
389
- if (this.config.actions.length > 0) {
390
- this.config.actions[this.config.actions.length - 1].label = label;
391
- }
392
- return this;
393
- }
394
- icon(icon) {
395
- if (this.config.actions.length > 0) {
396
- this.config.actions[this.config.actions.length - 1].icon = icon;
397
- }
398
- return this;
399
- }
400
- variant(variant) {
401
- if (this.config.actions.length > 0) {
402
- this.config.actions[this.config.actions.length - 1].variant = variant;
403
- }
404
- return this;
405
- }
406
- size(size) {
407
- if (this.config.actions.length > 0) {
408
- this.config.actions[this.config.actions.length - 1].size = size;
409
- }
410
- return this;
411
- }
412
- disabled(disabled = true) {
413
- if (this.config.actions.length > 0) {
414
- this.config.actions[this.config.actions.length - 1].disabled = disabled;
415
- }
416
- return this;
417
- }
418
- loading(loading = true) {
419
- if (this.config.actions.length > 0) {
420
- this.config.actions[this.config.actions.length - 1].loading = loading;
421
- }
422
- return this;
423
- }
424
- hidden(hidden = true) {
425
- if (this.config.actions.length > 0) {
426
- this.config.actions[this.config.actions.length - 1].hidden = hidden;
427
- }
428
- return this;
429
- }
430
- action(action) {
431
- this.config.actions.push(action);
432
- return this;
433
- }
434
- onClick(handler) {
435
- if (this.config.actions.length > 0) {
436
- this.config.actions[this.config.actions.length - 1].onClick = handler;
437
- }
438
- return this;
439
- }
440
- href(url) {
441
- if (this.config.actions.length > 0) {
442
- this.config.actions[this.config.actions.length - 1].href = url;
443
- }
444
- return this;
445
- }
446
- bulk(handler) {
447
- if (this.config.actions.length > 0) {
448
- this.config.actions[this.config.actions.length - 1].bulk = true;
449
- this.config.actions[this.config.actions.length - 1].bulkOnClick = handler;
450
- }
451
- return this;
452
- }
453
- create(config) {
454
- return this.action({
455
- label: config.label,
456
- href: config.href,
457
- onClick: config.onClick,
458
- icon: config.icon,
459
- variant: "default",
460
- });
461
- }
462
- export(config) {
463
- return this.action({
464
- label: config.label,
465
- icon: config.icon,
466
- onClick: config.onClick,
467
- variant: "outline",
468
- });
469
- }
470
- import(config) {
471
- return this.action({
472
- label: config.label,
473
- icon: config.icon,
474
- onClick: config.onClick,
475
- variant: "outline",
476
- });
477
- }
478
- bulkExport(config) {
479
- return this.action({
480
- label: config.label,
481
- icon: config.icon,
482
- bulk: true,
483
- bulkOnClick: config.onExport,
484
- variant: "outline",
485
- });
486
- }
487
- bulkDelete(config) {
488
- return this.action({
489
- label: config.label,
490
- icon: config.icon,
491
- bulk: true,
492
- bulkOnClick: config.onDelete,
493
- variant: "destructive",
494
- });
495
- }
496
- build() {
497
- return this.config.actions;
498
- }
499
- buildLegacy() {
500
- return this.config.actions.map((action, index) => ({
501
- id: `action-${index}`,
502
- label: action.label || "",
503
- icon: action.icon,
504
- onClick: action.onClick,
505
- href: action.href,
506
- variant: action.variant,
507
- size: action.size,
508
- disabled: action.disabled,
509
- loading: action.loading,
510
- hidden: action.hidden,
511
- bulk: action.bulk,
512
- bulkOnClick: action.bulkOnClick,
513
- }));
514
- }
515
- }
516
-
517
- function HeaderActionGroup({ actions, selectedRows = [], label = "Aktionen", icon, variant = "outline", }) {
518
- const visibleActions = actions.filter((action) => !action.hidden);
519
- if (visibleActions.length === 0)
520
- return null;
521
- // If only one action, render it directly
522
- if (visibleActions.length === 1) {
523
- const action = visibleActions[0];
524
- if (action.render) {
525
- return jsx(Fragment, { children: action.render(selectedRows) });
526
- }
527
- return (jsxs(Button, { variant: action.variant || variant, size: action.size || "default", disabled: action.disabled, onClick: () => {
528
- if (action.bulk && action.bulkOnClick) {
529
- action.bulkOnClick(selectedRows);
530
- }
531
- else if (action.onClick) {
532
- action.onClick();
533
- }
534
- else if (action.href) {
535
- window.location.href = action.href;
536
- }
537
- }, children: [action.icon && jsx("span", { className: "mr-2", children: action.icon }), action.label] }));
538
- }
539
- // Multiple actions - render as dropdown
540
- return (jsxs(DropdownMenu, { children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsxs(Button, { variant: variant, size: "default", children: [icon && jsx("span", { className: "mr-2", children: icon }), label, jsx(ChevronDown, { className: "ml-2 h-4 w-4" })] }) }), jsx(DropdownMenuContent, { align: "end", children: visibleActions.map((action, index) => {
541
- if (action.render) {
542
- return jsx("div", { children: action.render(selectedRows) }, index);
543
- }
544
- return (jsxs(DropdownMenuItem, { disabled: action.disabled, onClick: () => {
545
- if (action.bulk && action.bulkOnClick) {
546
- action.bulkOnClick(selectedRows);
547
- }
548
- else if (action.onClick) {
549
- action.onClick();
550
- }
551
- else if (action.href) {
552
- window.location.href = action.href;
553
- }
554
- }, children: [action.icon && jsx("span", { className: "mr-2", children: action.icon }), action.label] }, index));
555
- }) })] }));
556
- }
557
-
558
303
  function DataTable({ columns, data, config = {}, className, isLoading = false, isError = false, onRetry, }) {
559
304
  const [sorting, setSorting] = useState(config.defaultSort ? [config.defaultSort] : []);
560
305
  const [columnFilters, setColumnFilters] = useState([]);
@@ -1931,5 +1676,5 @@ function ConfirmProvider({ children }) {
1931
1676
  return (jsxs(Fragment, { children: [children, jsx(AlertDialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxs(AlertDialogContent, { className: "max-w-md", children: [jsxs(AlertDialogHeader, { children: [jsx(AlertDialogTitle, { className: "text-center", children: title || "Bestätigung erforderlich" }), description && (jsx(AlertDialogDescription, { className: "text-center", children: description }))] }), image && (jsx("div", { className: "flex justify-center py-4", children: jsx("img", { src: image, alt: "Confirmation", className: "h-24 w-24 object-contain" }) })), icon && !image && (jsx("div", { className: "flex justify-center py-4 text-6xl", children: icon })), jsxs(AlertDialogFooter, { className: "flex flex-row !justify-between w-full", children: [jsx(AlertDialogCancel, { onClick: handleCancel, className: "mt-0", children: cancelLabel || "Abbrechen" }), jsx(AlertDialogAction, { onClick: handleConfirm, variant: variant === "destructive" ? "destructive" : "default", children: confirmLabel || "Bestätigen" })] })] }) })] }));
1932
1677
  }
1933
1678
 
1934
- export { AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DropdownColumn, EmptyStateBuilder, EnumColumn, HeaderActionGroup, HeaderActions, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TableSchema, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, EnumColumn as enumColumn, IconColumn as iconColumn, InputColumn as inputColumn };
1679
+ export { AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DropdownColumn, EmptyStateBuilder, EnumColumn, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TableSchema, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, EnumColumn as enumColumn, IconColumn as iconColumn, InputColumn as inputColumn };
1935
1680
  //# sourceMappingURL=index.esm.js.map