@nccirtu/tablefy 0.7.1 → 0.7.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
@@ -1598,60 +1598,70 @@ class SelectColumn extends BaseColumn {
1598
1598
  }
1599
1599
  }
1600
1600
 
1601
- class TextColumn extends BaseColumn {
1601
+ class EnumColumn extends BaseColumn {
1602
+ constructor(accessor) {
1603
+ super(accessor);
1604
+ this.config.asBadge = true;
1605
+ this.config.showIcon = true;
1606
+ this.config.iconPosition = "left";
1607
+ }
1602
1608
  static make(accessor) {
1603
- return new TextColumn(accessor);
1609
+ return new EnumColumn(accessor);
1604
1610
  }
1605
- formatter(fn) {
1606
- this.config.formatter = fn;
1611
+ /**
1612
+ * Define the enum options with labels, icons, and colors
1613
+ */
1614
+ options(options) {
1615
+ this.config.options = options;
1607
1616
  return this;
1608
1617
  }
1609
- prefix(prefix) {
1610
- this.config.prefix = prefix;
1618
+ /**
1619
+ * Display as plain text instead of badge
1620
+ */
1621
+ asText() {
1622
+ this.config.asBadge = false;
1611
1623
  return this;
1612
1624
  }
1613
- suffix(suffix) {
1614
- this.config.suffix = suffix;
1625
+ /**
1626
+ * Display as badge (default)
1627
+ */
1628
+ asBadge() {
1629
+ this.config.asBadge = true;
1615
1630
  return this;
1616
1631
  }
1617
- placeholder(placeholder) {
1618
- this.config.placeholder = placeholder;
1632
+ /**
1633
+ * Hide icons
1634
+ */
1635
+ hideIcon() {
1636
+ this.config.showIcon = false;
1619
1637
  return this;
1620
1638
  }
1621
- // Shortcuts für gängige Formatierungen
1622
- uppercase() {
1623
- const existingFormatter = this.config.formatter;
1624
- this.config.formatter = (value, row) => {
1625
- const result = existingFormatter ? existingFormatter(value, row) : value;
1626
- return typeof result === "string"
1627
- ? result.toUpperCase()
1628
- : result;
1629
- };
1639
+ /**
1640
+ * Show icons (default)
1641
+ */
1642
+ showIcon() {
1643
+ this.config.showIcon = true;
1630
1644
  return this;
1631
1645
  }
1632
- lowercase() {
1633
- const existingFormatter = this.config.formatter;
1634
- this.config.formatter = (value, row) => {
1635
- const result = existingFormatter ? existingFormatter(value, row) : value;
1636
- return typeof result === "string"
1637
- ? result.toLowerCase()
1638
- : result;
1639
- };
1646
+ /**
1647
+ * Set icon position
1648
+ */
1649
+ iconPosition(position) {
1650
+ this.config.iconPosition = position;
1640
1651
  return this;
1641
1652
  }
1642
- limit(chars) {
1643
- const existingFormatter = this.config.formatter;
1644
- this.config.formatter = (value, row) => {
1645
- const result = existingFormatter ? existingFormatter(value, row) : value;
1646
- if (typeof result === "string" && result.length > chars) {
1647
- return result.slice(0, chars) + "...";
1648
- }
1649
- return result;
1650
- };
1653
+ /**
1654
+ * Placeholder for unknown values
1655
+ */
1656
+ placeholder(placeholder) {
1657
+ this.config.placeholder = placeholder;
1651
1658
  return this;
1652
1659
  }
1653
1660
  build() {
1654
- const { accessor, label, sortable, prefix, suffix, placeholder, formatter, } = this.config;
1661
+ const { accessor, label, sortable, options, asBadge, showIcon, iconPosition, placeholder, } = this.config;
1662
+ if (!options || options.length === 0) {
1663
+ throw new Error(`EnumColumn "${String(accessor)}" requires options to be defined`);
1664
+ }
1655
1665
  return {
1656
1666
  accessorKey: accessor,
1657
1667
  header: ({ column }) => {
@@ -1661,92 +1671,22 @@ class TextColumn extends BaseColumn {
1661
1671
  }
1662
1672
  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" })] }));
1663
1673
  },
1664
- cell: ({ row, getValue }) => {
1665
- let value = getValue();
1666
- // Custom Formatter anwenden
1667
- if (formatter) {
1668
- value = formatter(value, row);
1669
- }
1670
- // Placeholder wenn leer
1671
- if (value === null || value === undefined || value === "") {
1674
+ cell: ({ getValue }) => {
1675
+ const value = getValue();
1676
+ // Find matching option
1677
+ const option = options.find((opt) => opt.value === value);
1678
+ // Handle unknown values
1679
+ if (!option) {
1672
1680
  return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
1673
1681
  }
1674
- // Prefix/Suffix hinzufügen
1675
- const displayValue = `${prefix || ""}${value}${suffix || ""}`;
1676
- return (jsxRuntime.jsx("span", { className: utils.cn(this.getAlignmentClass(), this.config.cellClassName), children: displayValue }));
1677
- },
1678
- };
1679
- }
1680
- }
1681
-
1682
- class ActionsColumn {
1683
- config = {
1684
- actions: [],
1685
- label: "Aktionen",
1686
- };
1687
- static make() {
1688
- return new ActionsColumn();
1689
- }
1690
- label(label) {
1691
- this.config.label = label;
1692
- return this;
1693
- }
1694
- triggerIcon(icon) {
1695
- this.config.triggerIcon = icon;
1696
- return this;
1697
- }
1698
- // Action hinzufügen
1699
- action(action) {
1700
- this.config.actions.push(action);
1701
- return this;
1702
- }
1703
- // Shortcuts für gängige Actions
1704
- view(onClick) {
1705
- return this.action({ label: "Anzeigen", onClick });
1706
- }
1707
- edit(onClick) {
1708
- return this.action({ label: "Bearbeiten", onClick });
1709
- }
1710
- delete(onClick) {
1711
- return this.action({
1712
- label: "Löschen",
1713
- onClick,
1714
- variant: "destructive",
1715
- separator: true,
1716
- });
1717
- }
1718
- link(label, href) {
1719
- return this.action({ label, href });
1720
- }
1721
- separator() {
1722
- if (this.config.actions.length > 0) {
1723
- this.config.actions[this.config.actions.length - 1].separator = true;
1724
- }
1725
- return this;
1726
- }
1727
- build() {
1728
- const { actions, label, triggerIcon } = this.config;
1729
- return {
1730
- id: "actions",
1731
- header: () => jsxRuntime.jsx("span", { className: "sr-only", children: label }),
1732
- cell: ({ row }) => {
1733
- const data = row.original;
1734
- const visibleActions = actions.filter((action) => !action.hidden || !action.hidden(data));
1735
- if (visibleActions.length === 0)
1736
- return null;
1737
- 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 ? (
1738
- // Custom render function takes priority
1739
- action.render(data)) : (
1740
- // Standard menu item
1741
- jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { disabled: action.disabled?.(data), className: utils.cn(action.variant === "destructive" &&
1742
- "text-destructive focus:text-destructive"), onClick: () => {
1743
- if (action.href) {
1744
- window.location.href = action.href(data);
1745
- }
1746
- else if (action.onClick) {
1747
- action.onClick(data);
1748
- }
1749
- }, 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))) })] }));
1682
+ const Icon = option.icon;
1683
+ const iconElement = showIcon && Icon ? jsxRuntime.jsx(Icon, { className: "h-4 w-4" }) : null;
1684
+ // Render as Badge
1685
+ if (asBadge) {
1686
+ return (jsxRuntime.jsx("div", { className: utils.cn(this.getAlignmentClass(), this.config.cellClassName), children: jsxRuntime.jsxs(badge.Badge, { variant: option.color || "default", className: utils.cn("inline-flex items-center gap-1.5", option.className), children: [iconPosition === "left" && iconElement, option.label, iconPosition === "right" && iconElement] }) }));
1687
+ }
1688
+ // Render as plain text with icon
1689
+ return (jsxRuntime.jsxs("div", { className: utils.cn("inline-flex items-center gap-2", this.getAlignmentClass(), this.config.cellClassName, option.className), children: [iconPosition === "left" && iconElement, jsxRuntime.jsx("span", { children: option.label }), iconPosition === "right" && iconElement] }));
1750
1690
  },
1751
1691
  };
1752
1692
  }
@@ -1768,7 +1708,6 @@ function ConfirmProvider({ children }) {
1768
1708
  const currentRequest = queue[0];
1769
1709
  react.useEffect(() => {
1770
1710
  registerConfirm(async (options) => {
1771
- console.log("ConfirmProvider received options:", options);
1772
1711
  return new Promise((resolve) => {
1773
1712
  setQueue((q) => [...q, { options, resolve }]);
1774
1713
  });
@@ -1792,7 +1731,6 @@ function ConfirmProvider({ children }) {
1792
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" })] })] }) })] }));
1793
1732
  }
1794
1733
 
1795
- exports.ActionsColumn = ActionsColumn;
1796
1734
  exports.AvatarGroupColumn = AvatarGroupColumn;
1797
1735
  exports.BadgeColumn = BadgeColumn;
1798
1736
  exports.ButtonColumn = ButtonColumn;
@@ -1803,6 +1741,7 @@ exports.DataTableSchema = DataTableSchema;
1803
1741
  exports.DateColumn = DateColumn;
1804
1742
  exports.DropdownColumn = DropdownColumn;
1805
1743
  exports.EmptyStateBuilder = EmptyStateBuilder;
1744
+ exports.EnumColumn = EnumColumn;
1806
1745
  exports.IconColumn = IconColumn;
1807
1746
  exports.ImageColumn = ImageColumn;
1808
1747
  exports.InputColumn = InputColumn;
@@ -1811,7 +1750,6 @@ exports.NumberColumn = NumberColumn;
1811
1750
  exports.ProgressColumn = ProgressColumn;
1812
1751
  exports.SelectColumn = SelectColumn;
1813
1752
  exports.TableSchema = TableSchema;
1814
- exports.TextColumn = TextColumn;
1815
1753
  exports.avatarGroupColumn = AvatarGroupColumn;
1816
1754
  exports.badgeColumn = BadgeColumn;
1817
1755
  exports.buttonColumn = ButtonColumn;
@@ -1819,9 +1757,7 @@ exports.checkboxColumn = CheckboxColumn;
1819
1757
  exports.confirm = confirm;
1820
1758
  exports.dateColumn = DateColumn;
1821
1759
  exports.dropdownColumn = DropdownColumn;
1760
+ exports.enumColumn = EnumColumn;
1822
1761
  exports.iconColumn = IconColumn;
1823
1762
  exports.inputColumn = InputColumn;
1824
- exports.progressColumn = ProgressColumn;
1825
- exports.selectColumn = SelectColumn;
1826
- exports.textColumn = TextColumn;
1827
1763
  //# sourceMappingURL=index.js.map