@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.
- package/dist/builders/index.d.ts +0 -3
- package/dist/builders/table-schema.d.ts +1 -40
- package/dist/columns/builders/index.d.ts +0 -3
- package/dist/columns/builders/table-schema.d.ts +1 -40
- package/dist/columns/index.d.ts +1 -2
- package/dist/columns/types/actions.d.ts +3 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +7 -262
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -263
- package/dist/index.js.map +1 -1
- package/dist/types/actions.d.ts +3 -2
- package/package.json +11 -7
package/dist/index.js
CHANGED
|
@@ -26,6 +26,10 @@ function DataTableHeader({ title, description, actions = [], search, searchValue
|
|
|
26
26
|
return table.getFilteredSelectedRowModel().rows.map((row) => row.original);
|
|
27
27
|
};
|
|
28
28
|
const renderAction = (action, index) => {
|
|
29
|
+
// Custom render function takes priority
|
|
30
|
+
if (action.render) {
|
|
31
|
+
return jsxRuntime.jsx("div", { children: action.render() }, action.id || index);
|
|
32
|
+
}
|
|
29
33
|
if (action.children && action.children.length > 0) {
|
|
30
34
|
return (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsxs(button.Button, { variant: action.variant || "outline", size: action.size || "default", disabled: action.disabled || action.loading, children: [action.icon, jsxRuntime.jsx("span", { className: utils.cn(action.icon ? "ml-2" : ""), children: action.label }), jsxRuntime.jsx(lucideReact.ChevronDown, { className: "ml-2 h-4 w-4" })] }) }), jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { align: "end", children: action.children.map((child, childIndex) => (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: child.onClick, className: utils.cn(child.variant === "destructive" &&
|
|
31
35
|
"text-destructive focus:text-destructive"), children: [child.icon && jsxRuntime.jsx("span", { className: "mr-2", children: child.icon }), child.label] }, child.id || childIndex))) })] }, action.id || index));
|
|
@@ -75,87 +79,6 @@ function DataTablePagination({ table, config, className, }) {
|
|
|
75
79
|
: 0, " ", "von ", Math.max(table.getPageCount(), 0)] })), jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [jsxRuntime.jsxs(button.Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(0), disabled: !table.getCanPreviousPage(), children: [jsxRuntime.jsx(lucideReact.ChevronsLeft, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "sr-only", children: "Erste Seite" })] }), jsxRuntime.jsxs(button.Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.previousPage(), disabled: !table.getCanPreviousPage(), children: [jsxRuntime.jsx(lucideReact.ChevronLeft, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "sr-only", children: "Vorherige Seite" })] }), jsxRuntime.jsxs(button.Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.nextPage(), disabled: !table.getCanNextPage(), children: [jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "sr-only", children: "N\u00E4chste Seite" })] }), jsxRuntime.jsxs(button.Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(table.getPageCount() - 1), disabled: !table.getCanNextPage(), children: [jsxRuntime.jsx(lucideReact.ChevronsRight, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "sr-only", children: "Letzte Seite" })] })] })] })] }));
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
/**
|
|
79
|
-
* Header Actions Builder
|
|
80
|
-
* Fluent API for building header actions
|
|
81
|
-
*/
|
|
82
|
-
class HeaderActionsBuilder {
|
|
83
|
-
actions = [];
|
|
84
|
-
create(config) {
|
|
85
|
-
this.actions.push({
|
|
86
|
-
id: "create",
|
|
87
|
-
label: config.label,
|
|
88
|
-
href: config.href,
|
|
89
|
-
onClick: config.onClick,
|
|
90
|
-
icon: config.icon,
|
|
91
|
-
variant: "default",
|
|
92
|
-
});
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
export(config) {
|
|
96
|
-
if (config.formats && config.formats.length > 0) {
|
|
97
|
-
this.actions.push({
|
|
98
|
-
id: "export",
|
|
99
|
-
label: config.label,
|
|
100
|
-
icon: config.icon,
|
|
101
|
-
variant: "outline",
|
|
102
|
-
children: config.formats.map((format, index) => ({
|
|
103
|
-
id: `export-${index}`,
|
|
104
|
-
label: format.label,
|
|
105
|
-
onClick: format.onClick,
|
|
106
|
-
})),
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.actions.push({
|
|
111
|
-
id: "export",
|
|
112
|
-
label: config.label,
|
|
113
|
-
icon: config.icon,
|
|
114
|
-
variant: "outline",
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
import(config) {
|
|
120
|
-
this.actions.push({
|
|
121
|
-
id: "import",
|
|
122
|
-
label: config.label,
|
|
123
|
-
icon: config.icon,
|
|
124
|
-
onClick: config.onClick,
|
|
125
|
-
variant: "outline",
|
|
126
|
-
});
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
bulkExport(config) {
|
|
130
|
-
this.actions.push({
|
|
131
|
-
id: "bulk-export",
|
|
132
|
-
label: config.label,
|
|
133
|
-
icon: config.icon,
|
|
134
|
-
bulk: true,
|
|
135
|
-
bulkOnClick: config.onExport,
|
|
136
|
-
variant: "outline",
|
|
137
|
-
});
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
bulkDelete(config) {
|
|
141
|
-
this.actions.push({
|
|
142
|
-
id: "bulk-delete",
|
|
143
|
-
label: config.label,
|
|
144
|
-
icon: config.icon,
|
|
145
|
-
bulk: true,
|
|
146
|
-
bulkOnClick: config.onDelete,
|
|
147
|
-
variant: "destructive",
|
|
148
|
-
});
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
custom(action) {
|
|
152
|
-
this.actions.push(action);
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
build() {
|
|
156
|
-
return this.actions;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
82
|
/**
|
|
160
83
|
* Table Schema Builder
|
|
161
84
|
* Fluent API for building complete table configurations
|
|
@@ -175,9 +98,8 @@ class TableSchema {
|
|
|
175
98
|
this.config.title = text;
|
|
176
99
|
return this;
|
|
177
100
|
}
|
|
178
|
-
headerActions(
|
|
179
|
-
|
|
180
|
-
this.config.headerActions = builder(actionsBuilder).build();
|
|
101
|
+
headerActions(actions) {
|
|
102
|
+
this.config.headerActions = actions;
|
|
181
103
|
return this;
|
|
182
104
|
}
|
|
183
105
|
emptyState(config) {
|
|
@@ -380,183 +302,6 @@ class EmptyStateBuilder {
|
|
|
380
302
|
}
|
|
381
303
|
}
|
|
382
304
|
|
|
383
|
-
class HeaderActions {
|
|
384
|
-
config = {
|
|
385
|
-
actions: [],
|
|
386
|
-
};
|
|
387
|
-
static make() {
|
|
388
|
-
return new HeaderActions();
|
|
389
|
-
}
|
|
390
|
-
label(label) {
|
|
391
|
-
if (this.config.actions.length > 0) {
|
|
392
|
-
this.config.actions[this.config.actions.length - 1].label = label;
|
|
393
|
-
}
|
|
394
|
-
return this;
|
|
395
|
-
}
|
|
396
|
-
icon(icon) {
|
|
397
|
-
if (this.config.actions.length > 0) {
|
|
398
|
-
this.config.actions[this.config.actions.length - 1].icon = icon;
|
|
399
|
-
}
|
|
400
|
-
return this;
|
|
401
|
-
}
|
|
402
|
-
variant(variant) {
|
|
403
|
-
if (this.config.actions.length > 0) {
|
|
404
|
-
this.config.actions[this.config.actions.length - 1].variant = variant;
|
|
405
|
-
}
|
|
406
|
-
return this;
|
|
407
|
-
}
|
|
408
|
-
size(size) {
|
|
409
|
-
if (this.config.actions.length > 0) {
|
|
410
|
-
this.config.actions[this.config.actions.length - 1].size = size;
|
|
411
|
-
}
|
|
412
|
-
return this;
|
|
413
|
-
}
|
|
414
|
-
disabled(disabled = true) {
|
|
415
|
-
if (this.config.actions.length > 0) {
|
|
416
|
-
this.config.actions[this.config.actions.length - 1].disabled = disabled;
|
|
417
|
-
}
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
loading(loading = true) {
|
|
421
|
-
if (this.config.actions.length > 0) {
|
|
422
|
-
this.config.actions[this.config.actions.length - 1].loading = loading;
|
|
423
|
-
}
|
|
424
|
-
return this;
|
|
425
|
-
}
|
|
426
|
-
hidden(hidden = true) {
|
|
427
|
-
if (this.config.actions.length > 0) {
|
|
428
|
-
this.config.actions[this.config.actions.length - 1].hidden = hidden;
|
|
429
|
-
}
|
|
430
|
-
return this;
|
|
431
|
-
}
|
|
432
|
-
action(action) {
|
|
433
|
-
this.config.actions.push(action);
|
|
434
|
-
return this;
|
|
435
|
-
}
|
|
436
|
-
onClick(handler) {
|
|
437
|
-
if (this.config.actions.length > 0) {
|
|
438
|
-
this.config.actions[this.config.actions.length - 1].onClick = handler;
|
|
439
|
-
}
|
|
440
|
-
return this;
|
|
441
|
-
}
|
|
442
|
-
href(url) {
|
|
443
|
-
if (this.config.actions.length > 0) {
|
|
444
|
-
this.config.actions[this.config.actions.length - 1].href = url;
|
|
445
|
-
}
|
|
446
|
-
return this;
|
|
447
|
-
}
|
|
448
|
-
bulk(handler) {
|
|
449
|
-
if (this.config.actions.length > 0) {
|
|
450
|
-
this.config.actions[this.config.actions.length - 1].bulk = true;
|
|
451
|
-
this.config.actions[this.config.actions.length - 1].bulkOnClick = handler;
|
|
452
|
-
}
|
|
453
|
-
return this;
|
|
454
|
-
}
|
|
455
|
-
create(config) {
|
|
456
|
-
return this.action({
|
|
457
|
-
label: config.label,
|
|
458
|
-
href: config.href,
|
|
459
|
-
onClick: config.onClick,
|
|
460
|
-
icon: config.icon,
|
|
461
|
-
variant: "default",
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
export(config) {
|
|
465
|
-
return this.action({
|
|
466
|
-
label: config.label,
|
|
467
|
-
icon: config.icon,
|
|
468
|
-
onClick: config.onClick,
|
|
469
|
-
variant: "outline",
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
import(config) {
|
|
473
|
-
return this.action({
|
|
474
|
-
label: config.label,
|
|
475
|
-
icon: config.icon,
|
|
476
|
-
onClick: config.onClick,
|
|
477
|
-
variant: "outline",
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
bulkExport(config) {
|
|
481
|
-
return this.action({
|
|
482
|
-
label: config.label,
|
|
483
|
-
icon: config.icon,
|
|
484
|
-
bulk: true,
|
|
485
|
-
bulkOnClick: config.onExport,
|
|
486
|
-
variant: "outline",
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
bulkDelete(config) {
|
|
490
|
-
return this.action({
|
|
491
|
-
label: config.label,
|
|
492
|
-
icon: config.icon,
|
|
493
|
-
bulk: true,
|
|
494
|
-
bulkOnClick: config.onDelete,
|
|
495
|
-
variant: "destructive",
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
build() {
|
|
499
|
-
return this.config.actions;
|
|
500
|
-
}
|
|
501
|
-
buildLegacy() {
|
|
502
|
-
return this.config.actions.map((action, index) => ({
|
|
503
|
-
id: `action-${index}`,
|
|
504
|
-
label: action.label || "",
|
|
505
|
-
icon: action.icon,
|
|
506
|
-
onClick: action.onClick,
|
|
507
|
-
href: action.href,
|
|
508
|
-
variant: action.variant,
|
|
509
|
-
size: action.size,
|
|
510
|
-
disabled: action.disabled,
|
|
511
|
-
loading: action.loading,
|
|
512
|
-
hidden: action.hidden,
|
|
513
|
-
bulk: action.bulk,
|
|
514
|
-
bulkOnClick: action.bulkOnClick,
|
|
515
|
-
}));
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
function HeaderActionGroup({ actions, selectedRows = [], label = "Aktionen", icon, variant = "outline", }) {
|
|
520
|
-
const visibleActions = actions.filter((action) => !action.hidden);
|
|
521
|
-
if (visibleActions.length === 0)
|
|
522
|
-
return null;
|
|
523
|
-
// If only one action, render it directly
|
|
524
|
-
if (visibleActions.length === 1) {
|
|
525
|
-
const action = visibleActions[0];
|
|
526
|
-
if (action.render) {
|
|
527
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: action.render(selectedRows) });
|
|
528
|
-
}
|
|
529
|
-
return (jsxRuntime.jsxs(button.Button, { variant: action.variant || variant, size: action.size || "default", disabled: action.disabled, onClick: () => {
|
|
530
|
-
if (action.bulk && action.bulkOnClick) {
|
|
531
|
-
action.bulkOnClick(selectedRows);
|
|
532
|
-
}
|
|
533
|
-
else if (action.onClick) {
|
|
534
|
-
action.onClick();
|
|
535
|
-
}
|
|
536
|
-
else if (action.href) {
|
|
537
|
-
window.location.href = action.href;
|
|
538
|
-
}
|
|
539
|
-
}, children: [action.icon && jsxRuntime.jsx("span", { className: "mr-2", children: action.icon }), action.label] }));
|
|
540
|
-
}
|
|
541
|
-
// Multiple actions - render as dropdown
|
|
542
|
-
return (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsxs(button.Button, { variant: variant, size: "default", children: [icon && jsxRuntime.jsx("span", { className: "mr-2", children: icon }), label, jsxRuntime.jsx(lucideReact.ChevronDown, { className: "ml-2 h-4 w-4" })] }) }), jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { align: "end", children: visibleActions.map((action, index) => {
|
|
543
|
-
if (action.render) {
|
|
544
|
-
return jsxRuntime.jsx("div", { children: action.render(selectedRows) }, index);
|
|
545
|
-
}
|
|
546
|
-
return (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { disabled: action.disabled, onClick: () => {
|
|
547
|
-
if (action.bulk && action.bulkOnClick) {
|
|
548
|
-
action.bulkOnClick(selectedRows);
|
|
549
|
-
}
|
|
550
|
-
else if (action.onClick) {
|
|
551
|
-
action.onClick();
|
|
552
|
-
}
|
|
553
|
-
else if (action.href) {
|
|
554
|
-
window.location.href = action.href;
|
|
555
|
-
}
|
|
556
|
-
}, children: [action.icon && jsxRuntime.jsx("span", { className: "mr-2", children: action.icon }), action.label] }, index));
|
|
557
|
-
}) })] }));
|
|
558
|
-
}
|
|
559
|
-
|
|
560
305
|
function DataTable({ columns, data, config = {}, className, isLoading = false, isError = false, onRetry, }) {
|
|
561
306
|
const [sorting, setSorting] = react.useState(config.defaultSort ? [config.defaultSort] : []);
|
|
562
307
|
const [columnFilters, setColumnFilters] = react.useState([]);
|
|
@@ -1944,8 +1689,6 @@ exports.DateColumn = DateColumn;
|
|
|
1944
1689
|
exports.DropdownColumn = DropdownColumn;
|
|
1945
1690
|
exports.EmptyStateBuilder = EmptyStateBuilder;
|
|
1946
1691
|
exports.EnumColumn = EnumColumn;
|
|
1947
|
-
exports.HeaderActionGroup = HeaderActionGroup;
|
|
1948
|
-
exports.HeaderActions = HeaderActions;
|
|
1949
1692
|
exports.IconColumn = IconColumn;
|
|
1950
1693
|
exports.ImageColumn = ImageColumn;
|
|
1951
1694
|
exports.InputColumn = InputColumn;
|