@nccirtu/tablefy 0.8.2 → 0.8.3

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
@@ -1544,6 +1544,164 @@ class SelectColumn extends BaseColumn {
1544
1544
  }
1545
1545
  }
1546
1546
 
1547
+ class TextColumn extends BaseColumn {
1548
+ static make(accessor) {
1549
+ return new TextColumn(accessor);
1550
+ }
1551
+ formatter(fn) {
1552
+ this.config.formatter = fn;
1553
+ return this;
1554
+ }
1555
+ prefix(prefix) {
1556
+ this.config.prefix = prefix;
1557
+ return this;
1558
+ }
1559
+ suffix(suffix) {
1560
+ this.config.suffix = suffix;
1561
+ return this;
1562
+ }
1563
+ placeholder(placeholder) {
1564
+ this.config.placeholder = placeholder;
1565
+ return this;
1566
+ }
1567
+ // Shortcuts für gängige Formatierungen
1568
+ uppercase() {
1569
+ const existingFormatter = this.config.formatter;
1570
+ this.config.formatter = (value, row) => {
1571
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1572
+ return typeof result === "string"
1573
+ ? result.toUpperCase()
1574
+ : result;
1575
+ };
1576
+ return this;
1577
+ }
1578
+ lowercase() {
1579
+ const existingFormatter = this.config.formatter;
1580
+ this.config.formatter = (value, row) => {
1581
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1582
+ return typeof result === "string"
1583
+ ? result.toLowerCase()
1584
+ : result;
1585
+ };
1586
+ return this;
1587
+ }
1588
+ limit(chars) {
1589
+ const existingFormatter = this.config.formatter;
1590
+ this.config.formatter = (value, row) => {
1591
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1592
+ if (typeof result === "string" && result.length > chars) {
1593
+ return result.slice(0, chars) + "...";
1594
+ }
1595
+ return result;
1596
+ };
1597
+ return this;
1598
+ }
1599
+ build() {
1600
+ const { accessor, label, sortable, prefix, suffix, placeholder, formatter, visibleByDefault, visibilityLabel, } = this.config;
1601
+ return {
1602
+ accessorKey: accessor,
1603
+ meta: {
1604
+ visibleByDefault,
1605
+ visibilityLabel: visibilityLabel || label || String(accessor),
1606
+ },
1607
+ header: ({ column }) => {
1608
+ const displayLabel = label || String(accessor);
1609
+ if (!sortable) {
1610
+ return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
1611
+ }
1612
+ return (jsxRuntime.jsxs(button.Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: utils.cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsxRuntime.jsx(lucideReact.ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
1613
+ },
1614
+ cell: ({ row, getValue }) => {
1615
+ let value = getValue();
1616
+ // Custom Formatter anwenden
1617
+ if (formatter) {
1618
+ value = formatter(value, row);
1619
+ }
1620
+ // Placeholder wenn leer
1621
+ if (value === null || value === undefined || value === "") {
1622
+ return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
1623
+ }
1624
+ // Prefix/Suffix hinzufügen
1625
+ const displayValue = `${prefix || ""}${value}${suffix || ""}`;
1626
+ return (jsxRuntime.jsx("span", { className: utils.cn(this.getAlignmentClass(), this.config.cellClassName), children: displayValue }));
1627
+ },
1628
+ };
1629
+ }
1630
+ }
1631
+
1632
+ class ActionsColumn {
1633
+ config = {
1634
+ actions: [],
1635
+ label: "Aktionen",
1636
+ };
1637
+ static make() {
1638
+ return new ActionsColumn();
1639
+ }
1640
+ label(label) {
1641
+ this.config.label = label;
1642
+ return this;
1643
+ }
1644
+ triggerIcon(icon) {
1645
+ this.config.triggerIcon = icon;
1646
+ return this;
1647
+ }
1648
+ // Action hinzufügen
1649
+ action(action) {
1650
+ this.config.actions.push(action);
1651
+ return this;
1652
+ }
1653
+ // Shortcuts für gängige Actions
1654
+ view(onClick) {
1655
+ return this.action({ label: "Anzeigen", onClick });
1656
+ }
1657
+ edit(onClick) {
1658
+ return this.action({ label: "Bearbeiten", onClick });
1659
+ }
1660
+ delete(onClick) {
1661
+ return this.action({
1662
+ label: "Löschen",
1663
+ onClick,
1664
+ variant: "destructive",
1665
+ separator: true,
1666
+ });
1667
+ }
1668
+ link(label, href) {
1669
+ return this.action({ label, href });
1670
+ }
1671
+ separator() {
1672
+ if (this.config.actions.length > 0) {
1673
+ this.config.actions[this.config.actions.length - 1].separator = true;
1674
+ }
1675
+ return this;
1676
+ }
1677
+ build() {
1678
+ const { actions, label, triggerIcon } = this.config;
1679
+ return {
1680
+ id: "actions",
1681
+ header: () => jsxRuntime.jsx("span", { className: "sr-only", children: label }),
1682
+ cell: ({ row }) => {
1683
+ const data = row.original;
1684
+ const visibleActions = actions.filter((action) => !action.hidden || !action.hidden(data));
1685
+ if (visibleActions.length === 0)
1686
+ return null;
1687
+ return (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsxs(button.Button, { variant: "ghost", className: "h-10 w-10 p-0", children: [jsxRuntime.jsx("span", { className: "sr-only", children: label }), triggerIcon || jsxRuntime.jsx(lucideReact.MoreHorizontal, { className: "h-8 w-8" })] }) }), jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { align: "end", children: visibleActions.map((action, index) => (jsxRuntime.jsxs("div", { children: [action.render ? (
1688
+ // Custom render function takes priority
1689
+ action.render(data)) : (
1690
+ // Standard menu item
1691
+ jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { disabled: action.disabled?.(data), className: utils.cn(action.variant === "destructive" &&
1692
+ "text-destructive focus:text-destructive"), onClick: () => {
1693
+ if (action.href) {
1694
+ window.location.href = action.href(data);
1695
+ }
1696
+ else if (action.onClick) {
1697
+ action.onClick(data);
1698
+ }
1699
+ }, children: [action.icon && (jsxRuntime.jsx("span", { className: "mr-2", children: action.icon })), action.label] })), action.separator && index < visibleActions.length - 1 && (jsxRuntime.jsx(dropdownMenu.DropdownMenuSeparator, {}))] }, index))) })] }));
1700
+ },
1701
+ };
1702
+ }
1703
+ }
1704
+
1547
1705
  class EnumColumn extends BaseColumn {
1548
1706
  constructor(accessor) {
1549
1707
  super(accessor);
@@ -1678,6 +1836,7 @@ function ConfirmProvider({ children }) {
1678
1836
  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: [jsxRuntime.jsx(alertDialog.AlertDialogTitle, { className: "text-center", children: title || "Bestätigung erforderlich" }), description && (jsxRuntime.jsx(alertDialog.AlertDialogDescription, { className: "text-center", children: description }))] }), image && (jsxRuntime.jsx("div", { className: "flex justify-center py-4", children: jsxRuntime.jsx("img", { src: image, alt: "Confirmation", className: "h-24 w-24 object-contain" }) })), icon && !image && (jsxRuntime.jsx("div", { className: "flex justify-center py-4 text-6xl", children: icon })), jsxRuntime.jsxs(alertDialog.AlertDialogFooter, { className: "flex flex-row !justify-between w-full", children: [jsxRuntime.jsx(alertDialog.AlertDialogCancel, { onClick: handleCancel, className: "mt-0", children: cancelLabel || "Abbrechen" }), jsxRuntime.jsx(alertDialog.AlertDialogAction, { onClick: handleConfirm, variant: variant === "destructive" ? "destructive" : "default", children: confirmLabel || "Bestätigen" })] })] }) })] }));
1679
1837
  }
1680
1838
 
1839
+ exports.ActionsColumn = ActionsColumn;
1681
1840
  exports.AvatarGroupColumn = AvatarGroupColumn;
1682
1841
  exports.BadgeColumn = BadgeColumn;
1683
1842
  exports.ButtonColumn = ButtonColumn;
@@ -1697,6 +1856,8 @@ exports.NumberColumn = NumberColumn;
1697
1856
  exports.ProgressColumn = ProgressColumn;
1698
1857
  exports.SelectColumn = SelectColumn;
1699
1858
  exports.TableSchema = TableSchema;
1859
+ exports.TextColumn = TextColumn;
1860
+ exports.actionsColumn = ActionsColumn;
1700
1861
  exports.avatarGroupColumn = AvatarGroupColumn;
1701
1862
  exports.badgeColumn = BadgeColumn;
1702
1863
  exports.buttonColumn = ButtonColumn;
@@ -1707,4 +1868,5 @@ exports.dropdownColumn = DropdownColumn;
1707
1868
  exports.enumColumn = EnumColumn;
1708
1869
  exports.iconColumn = IconColumn;
1709
1870
  exports.inputColumn = InputColumn;
1871
+ exports.textColumn = TextColumn;
1710
1872
  //# sourceMappingURL=index.js.map