@nccirtu/tablefy 0.8.2 → 0.8.4

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
@@ -601,8 +601,18 @@ class BadgeColumn extends BaseColumn {
601
601
  this.config.variants = variants;
602
602
  return this;
603
603
  }
604
+ // Dynamische Variante basierend auf Row-Daten
605
+ variantFn(fn) {
606
+ this.config.variantFn = fn;
607
+ return this;
608
+ }
609
+ // Dynamische className basierend auf Row-Daten
610
+ classNameFn(fn) {
611
+ this.config.classNameFn = fn;
612
+ return this;
613
+ }
604
614
  build() {
605
- const { accessor, label, sortable, variants } = this.config;
615
+ const { accessor, label, sortable, variants, variantFn, classNameFn } = this.config;
606
616
  return {
607
617
  accessorKey: accessor,
608
618
  header: ({ column }) => {
@@ -612,18 +622,31 @@ class BadgeColumn extends BaseColumn {
612
622
  }
613
623
  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" })] }));
614
624
  },
615
- cell: ({ getValue }) => {
616
- const value = String(getValue());
617
- const variantConfig = variants?.[value];
618
- if (!variantConfig) {
619
- return (jsxRuntime.jsx(badge.Badge, { variant: "outline", className: this.config.cellClassName, children: value }));
625
+ cell: ({ getValue, row }) => {
626
+ const value = getValue();
627
+ const stringValue = String(value);
628
+ // Priority 1: Dynamic variantFn (highest priority)
629
+ if (variantFn) {
630
+ const dynamicConfig = variantFn(value, row.original);
631
+ return (jsxRuntime.jsxs(badge.Badge, { variant: dynamicConfig.variant === "success" ||
632
+ dynamicConfig.variant === "warning" ||
633
+ dynamicConfig.variant === "info" ||
634
+ dynamicConfig.variant === "muted"
635
+ ? "default"
636
+ : dynamicConfig.variant || "default", className: utils.cn(dynamicConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [dynamicConfig.icon, dynamicConfig.label || stringValue] }));
637
+ }
638
+ // Priority 2: Static variants lookup
639
+ const variantConfig = variants?.[stringValue];
640
+ if (variantConfig) {
641
+ return (jsxRuntime.jsxs(badge.Badge, { variant: variantConfig.variant === "success" ||
642
+ variantConfig.variant === "warning" ||
643
+ variantConfig.variant === "info" ||
644
+ variantConfig.variant === "muted"
645
+ ? "default"
646
+ : variantConfig.variant || "default", className: utils.cn(variantConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || stringValue] }));
620
647
  }
621
- return (jsxRuntime.jsxs(badge.Badge, { variant: variantConfig.variant === "success" ||
622
- variantConfig.variant === "warning" ||
623
- variantConfig.variant === "info" ||
624
- variantConfig.variant === "muted"
625
- ? "default"
626
- : variantConfig.variant || "default", className: utils.cn(variantConfig.className, this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || value] }));
648
+ // Priority 3: Default badge with optional dynamic className
649
+ return (jsxRuntime.jsx(badge.Badge, { variant: "outline", className: utils.cn(classNameFn?.(value, row.original), this.config.cellClassName), children: stringValue }));
627
650
  },
628
651
  };
629
652
  }
@@ -1544,6 +1567,164 @@ class SelectColumn extends BaseColumn {
1544
1567
  }
1545
1568
  }
1546
1569
 
1570
+ class TextColumn extends BaseColumn {
1571
+ static make(accessor) {
1572
+ return new TextColumn(accessor);
1573
+ }
1574
+ formatter(fn) {
1575
+ this.config.formatter = fn;
1576
+ return this;
1577
+ }
1578
+ prefix(prefix) {
1579
+ this.config.prefix = prefix;
1580
+ return this;
1581
+ }
1582
+ suffix(suffix) {
1583
+ this.config.suffix = suffix;
1584
+ return this;
1585
+ }
1586
+ placeholder(placeholder) {
1587
+ this.config.placeholder = placeholder;
1588
+ return this;
1589
+ }
1590
+ // Shortcuts für gängige Formatierungen
1591
+ uppercase() {
1592
+ const existingFormatter = this.config.formatter;
1593
+ this.config.formatter = (value, row) => {
1594
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1595
+ return typeof result === "string"
1596
+ ? result.toUpperCase()
1597
+ : result;
1598
+ };
1599
+ return this;
1600
+ }
1601
+ lowercase() {
1602
+ const existingFormatter = this.config.formatter;
1603
+ this.config.formatter = (value, row) => {
1604
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1605
+ return typeof result === "string"
1606
+ ? result.toLowerCase()
1607
+ : result;
1608
+ };
1609
+ return this;
1610
+ }
1611
+ limit(chars) {
1612
+ const existingFormatter = this.config.formatter;
1613
+ this.config.formatter = (value, row) => {
1614
+ const result = existingFormatter ? existingFormatter(value, row) : value;
1615
+ if (typeof result === "string" && result.length > chars) {
1616
+ return result.slice(0, chars) + "...";
1617
+ }
1618
+ return result;
1619
+ };
1620
+ return this;
1621
+ }
1622
+ build() {
1623
+ const { accessor, label, sortable, prefix, suffix, placeholder, formatter, visibleByDefault, visibilityLabel, } = this.config;
1624
+ return {
1625
+ accessorKey: accessor,
1626
+ meta: {
1627
+ visibleByDefault,
1628
+ visibilityLabel: visibilityLabel || label || String(accessor),
1629
+ },
1630
+ header: ({ column }) => {
1631
+ const displayLabel = label || String(accessor);
1632
+ if (!sortable) {
1633
+ return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
1634
+ }
1635
+ 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" })] }));
1636
+ },
1637
+ cell: ({ row, getValue }) => {
1638
+ let value = getValue();
1639
+ // Custom Formatter anwenden
1640
+ if (formatter) {
1641
+ value = formatter(value, row);
1642
+ }
1643
+ // Placeholder wenn leer
1644
+ if (value === null || value === undefined || value === "") {
1645
+ return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
1646
+ }
1647
+ // Prefix/Suffix hinzufügen
1648
+ const displayValue = `${prefix || ""}${value}${suffix || ""}`;
1649
+ return (jsxRuntime.jsx("span", { className: utils.cn(this.getAlignmentClass(), this.config.cellClassName), children: displayValue }));
1650
+ },
1651
+ };
1652
+ }
1653
+ }
1654
+
1655
+ class ActionsColumn {
1656
+ config = {
1657
+ actions: [],
1658
+ label: "Aktionen",
1659
+ };
1660
+ static make() {
1661
+ return new ActionsColumn();
1662
+ }
1663
+ label(label) {
1664
+ this.config.label = label;
1665
+ return this;
1666
+ }
1667
+ triggerIcon(icon) {
1668
+ this.config.triggerIcon = icon;
1669
+ return this;
1670
+ }
1671
+ // Action hinzufügen
1672
+ action(action) {
1673
+ this.config.actions.push(action);
1674
+ return this;
1675
+ }
1676
+ // Shortcuts für gängige Actions
1677
+ view(onClick) {
1678
+ return this.action({ label: "Anzeigen", onClick });
1679
+ }
1680
+ edit(onClick) {
1681
+ return this.action({ label: "Bearbeiten", onClick });
1682
+ }
1683
+ delete(onClick) {
1684
+ return this.action({
1685
+ label: "Löschen",
1686
+ onClick,
1687
+ variant: "destructive",
1688
+ separator: true,
1689
+ });
1690
+ }
1691
+ link(label, href) {
1692
+ return this.action({ label, href });
1693
+ }
1694
+ separator() {
1695
+ if (this.config.actions.length > 0) {
1696
+ this.config.actions[this.config.actions.length - 1].separator = true;
1697
+ }
1698
+ return this;
1699
+ }
1700
+ build() {
1701
+ const { actions, label, triggerIcon } = this.config;
1702
+ return {
1703
+ id: "actions",
1704
+ header: () => jsxRuntime.jsx("span", { className: "sr-only", children: label }),
1705
+ cell: ({ row }) => {
1706
+ const data = row.original;
1707
+ const visibleActions = actions.filter((action) => !action.hidden || !action.hidden(data));
1708
+ if (visibleActions.length === 0)
1709
+ return null;
1710
+ 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 ? (
1711
+ // Custom render function takes priority
1712
+ action.render(data)) : (
1713
+ // Standard menu item
1714
+ jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { disabled: action.disabled?.(data), className: utils.cn(action.variant === "destructive" &&
1715
+ "text-destructive focus:text-destructive"), onClick: () => {
1716
+ if (action.href) {
1717
+ window.location.href = action.href(data);
1718
+ }
1719
+ else if (action.onClick) {
1720
+ action.onClick(data);
1721
+ }
1722
+ }, 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))) })] }));
1723
+ },
1724
+ };
1725
+ }
1726
+ }
1727
+
1547
1728
  class EnumColumn extends BaseColumn {
1548
1729
  constructor(accessor) {
1549
1730
  super(accessor);
@@ -1678,6 +1859,7 @@ function ConfirmProvider({ children }) {
1678
1859
  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
1860
  }
1680
1861
 
1862
+ exports.ActionsColumn = ActionsColumn;
1681
1863
  exports.AvatarGroupColumn = AvatarGroupColumn;
1682
1864
  exports.BadgeColumn = BadgeColumn;
1683
1865
  exports.ButtonColumn = ButtonColumn;
@@ -1697,6 +1879,8 @@ exports.NumberColumn = NumberColumn;
1697
1879
  exports.ProgressColumn = ProgressColumn;
1698
1880
  exports.SelectColumn = SelectColumn;
1699
1881
  exports.TableSchema = TableSchema;
1882
+ exports.TextColumn = TextColumn;
1883
+ exports.actionsColumn = ActionsColumn;
1700
1884
  exports.avatarGroupColumn = AvatarGroupColumn;
1701
1885
  exports.badgeColumn = BadgeColumn;
1702
1886
  exports.buttonColumn = ButtonColumn;
@@ -1707,4 +1891,5 @@ exports.dropdownColumn = DropdownColumn;
1707
1891
  exports.enumColumn = EnumColumn;
1708
1892
  exports.iconColumn = IconColumn;
1709
1893
  exports.inputColumn = InputColumn;
1894
+ exports.textColumn = TextColumn;
1710
1895
  //# sourceMappingURL=index.js.map