@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.d.ts CHANGED
@@ -12,11 +12,9 @@ export { ImageColumn } from "./columns/image-column";
12
12
  export { InputColumn, InputColumn as inputColumn, } from "./columns/input-column";
13
13
  export { LinkColumn } from "./columns/link-column";
14
14
  export { NumberColumn } from "./columns/number-column";
15
- export { ProgressColumn, ProgressColumn as progressColumn, } from "./columns/progress-column";
16
- export { SelectColumn, SelectColumn as selectColumn, } from "./columns/select-column";
17
- export { TextColumn, TextColumn as textColumn } from "./columns/text-column";
18
- export { ActionsColumn } from "./columns/actions-column";
19
- export type { ActionItem } from "./columns/actions-column";
15
+ export { ProgressColumn, SelectColumn } from "./columns";
16
+ export { EnumColumn, EnumColumn as enumColumn } from "./columns/enum-column";
17
+ export type { EnumOption } from "./columns/enum-column";
20
18
  export { ConfirmProvider, confirm } from "./confirm";
21
19
  export type { ConfirmOptions } from "./confirm";
22
20
  export type { DataTableConfig, EmptyStateConfig, FilterConfig, HeaderAction, PaginationConfig, SearchConfig, } from "./types";
package/dist/index.esm.js CHANGED
@@ -5,8 +5,8 @@ import { Table, TableHeader, TableRow, TableHead, TableBody, TableCell } from '@
5
5
  import { cn } from '@/lib/utils';
6
6
  import { Button } from '@/components/ui/button';
7
7
  import { Input } from '@/components/ui/input';
8
- import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from '@/components/ui/dropdown-menu';
9
- import { Search, X, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink, MoreHorizontal } from 'lucide-react';
8
+ import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu';
9
+ import { Search, X, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink } from 'lucide-react';
10
10
  import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
11
11
  import { Badge } from '@/components/ui/badge';
12
12
  import { Checkbox } from '@/components/ui/checkbox';
@@ -1596,60 +1596,70 @@ class SelectColumn extends BaseColumn {
1596
1596
  }
1597
1597
  }
1598
1598
 
1599
- class TextColumn extends BaseColumn {
1599
+ class EnumColumn extends BaseColumn {
1600
+ constructor(accessor) {
1601
+ super(accessor);
1602
+ this.config.asBadge = true;
1603
+ this.config.showIcon = true;
1604
+ this.config.iconPosition = "left";
1605
+ }
1600
1606
  static make(accessor) {
1601
- return new TextColumn(accessor);
1607
+ return new EnumColumn(accessor);
1602
1608
  }
1603
- formatter(fn) {
1604
- this.config.formatter = fn;
1609
+ /**
1610
+ * Define the enum options with labels, icons, and colors
1611
+ */
1612
+ options(options) {
1613
+ this.config.options = options;
1605
1614
  return this;
1606
1615
  }
1607
- prefix(prefix) {
1608
- this.config.prefix = prefix;
1616
+ /**
1617
+ * Display as plain text instead of badge
1618
+ */
1619
+ asText() {
1620
+ this.config.asBadge = false;
1609
1621
  return this;
1610
1622
  }
1611
- suffix(suffix) {
1612
- this.config.suffix = suffix;
1623
+ /**
1624
+ * Display as badge (default)
1625
+ */
1626
+ asBadge() {
1627
+ this.config.asBadge = true;
1613
1628
  return this;
1614
1629
  }
1615
- placeholder(placeholder) {
1616
- this.config.placeholder = placeholder;
1630
+ /**
1631
+ * Hide icons
1632
+ */
1633
+ hideIcon() {
1634
+ this.config.showIcon = false;
1617
1635
  return this;
1618
1636
  }
1619
- // Shortcuts für gängige Formatierungen
1620
- uppercase() {
1621
- const existingFormatter = this.config.formatter;
1622
- this.config.formatter = (value, row) => {
1623
- const result = existingFormatter ? existingFormatter(value, row) : value;
1624
- return typeof result === "string"
1625
- ? result.toUpperCase()
1626
- : result;
1627
- };
1637
+ /**
1638
+ * Show icons (default)
1639
+ */
1640
+ showIcon() {
1641
+ this.config.showIcon = true;
1628
1642
  return this;
1629
1643
  }
1630
- lowercase() {
1631
- const existingFormatter = this.config.formatter;
1632
- this.config.formatter = (value, row) => {
1633
- const result = existingFormatter ? existingFormatter(value, row) : value;
1634
- return typeof result === "string"
1635
- ? result.toLowerCase()
1636
- : result;
1637
- };
1644
+ /**
1645
+ * Set icon position
1646
+ */
1647
+ iconPosition(position) {
1648
+ this.config.iconPosition = position;
1638
1649
  return this;
1639
1650
  }
1640
- limit(chars) {
1641
- const existingFormatter = this.config.formatter;
1642
- this.config.formatter = (value, row) => {
1643
- const result = existingFormatter ? existingFormatter(value, row) : value;
1644
- if (typeof result === "string" && result.length > chars) {
1645
- return result.slice(0, chars) + "...";
1646
- }
1647
- return result;
1648
- };
1651
+ /**
1652
+ * Placeholder for unknown values
1653
+ */
1654
+ placeholder(placeholder) {
1655
+ this.config.placeholder = placeholder;
1649
1656
  return this;
1650
1657
  }
1651
1658
  build() {
1652
- const { accessor, label, sortable, prefix, suffix, placeholder, formatter, } = this.config;
1659
+ const { accessor, label, sortable, options, asBadge, showIcon, iconPosition, placeholder, } = this.config;
1660
+ if (!options || options.length === 0) {
1661
+ throw new Error(`EnumColumn "${String(accessor)}" requires options to be defined`);
1662
+ }
1653
1663
  return {
1654
1664
  accessorKey: accessor,
1655
1665
  header: ({ column }) => {
@@ -1659,92 +1669,22 @@ class TextColumn extends BaseColumn {
1659
1669
  }
1660
1670
  return (jsxs(Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsx(ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
1661
1671
  },
1662
- cell: ({ row, getValue }) => {
1663
- let value = getValue();
1664
- // Custom Formatter anwenden
1665
- if (formatter) {
1666
- value = formatter(value, row);
1667
- }
1668
- // Placeholder wenn leer
1669
- if (value === null || value === undefined || value === "") {
1672
+ cell: ({ getValue }) => {
1673
+ const value = getValue();
1674
+ // Find matching option
1675
+ const option = options.find((opt) => opt.value === value);
1676
+ // Handle unknown values
1677
+ if (!option) {
1670
1678
  return (jsx("span", { className: cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
1671
1679
  }
1672
- // Prefix/Suffix hinzufügen
1673
- const displayValue = `${prefix || ""}${value}${suffix || ""}`;
1674
- return (jsx("span", { className: cn(this.getAlignmentClass(), this.config.cellClassName), children: displayValue }));
1675
- },
1676
- };
1677
- }
1678
- }
1679
-
1680
- class ActionsColumn {
1681
- config = {
1682
- actions: [],
1683
- label: "Aktionen",
1684
- };
1685
- static make() {
1686
- return new ActionsColumn();
1687
- }
1688
- label(label) {
1689
- this.config.label = label;
1690
- return this;
1691
- }
1692
- triggerIcon(icon) {
1693
- this.config.triggerIcon = icon;
1694
- return this;
1695
- }
1696
- // Action hinzufügen
1697
- action(action) {
1698
- this.config.actions.push(action);
1699
- return this;
1700
- }
1701
- // Shortcuts für gängige Actions
1702
- view(onClick) {
1703
- return this.action({ label: "Anzeigen", onClick });
1704
- }
1705
- edit(onClick) {
1706
- return this.action({ label: "Bearbeiten", onClick });
1707
- }
1708
- delete(onClick) {
1709
- return this.action({
1710
- label: "Löschen",
1711
- onClick,
1712
- variant: "destructive",
1713
- separator: true,
1714
- });
1715
- }
1716
- link(label, href) {
1717
- return this.action({ label, href });
1718
- }
1719
- separator() {
1720
- if (this.config.actions.length > 0) {
1721
- this.config.actions[this.config.actions.length - 1].separator = true;
1722
- }
1723
- return this;
1724
- }
1725
- build() {
1726
- const { actions, label, triggerIcon } = this.config;
1727
- return {
1728
- id: "actions",
1729
- header: () => jsx("span", { className: "sr-only", children: label }),
1730
- cell: ({ row }) => {
1731
- const data = row.original;
1732
- const visibleActions = actions.filter((action) => !action.hidden || !action.hidden(data));
1733
- if (visibleActions.length === 0)
1734
- return null;
1735
- return (jsxs(DropdownMenu, { children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsxs(Button, { variant: "ghost", className: "h-10 w-10 p-0", children: [jsx("span", { className: "sr-only", children: label }), triggerIcon || jsx(MoreHorizontal, { className: "h-8 w-8" })] }) }), jsx(DropdownMenuContent, { align: "end", children: visibleActions.map((action, index) => (jsxs("div", { children: [action.render ? (
1736
- // Custom render function takes priority
1737
- action.render(data)) : (
1738
- // Standard menu item
1739
- jsxs(DropdownMenuItem, { disabled: action.disabled?.(data), className: cn(action.variant === "destructive" &&
1740
- "text-destructive focus:text-destructive"), onClick: () => {
1741
- if (action.href) {
1742
- window.location.href = action.href(data);
1743
- }
1744
- else if (action.onClick) {
1745
- action.onClick(data);
1746
- }
1747
- }, children: [action.icon && (jsx("span", { className: "mr-2", children: action.icon })), action.label] })), action.separator && index < visibleActions.length - 1 && (jsx(DropdownMenuSeparator, {}))] }, index))) })] }));
1680
+ const Icon = option.icon;
1681
+ const iconElement = showIcon && Icon ? jsx(Icon, { className: "h-4 w-4" }) : null;
1682
+ // Render as Badge
1683
+ if (asBadge) {
1684
+ return (jsx("div", { className: cn(this.getAlignmentClass(), this.config.cellClassName), children: jsxs(Badge, { variant: option.color || "default", className: cn("inline-flex items-center gap-1.5", option.className), children: [iconPosition === "left" && iconElement, option.label, iconPosition === "right" && iconElement] }) }));
1685
+ }
1686
+ // Render as plain text with icon
1687
+ return (jsxs("div", { className: cn("inline-flex items-center gap-2", this.getAlignmentClass(), this.config.cellClassName, option.className), children: [iconPosition === "left" && iconElement, jsx("span", { children: option.label }), iconPosition === "right" && iconElement] }));
1748
1688
  },
1749
1689
  };
1750
1690
  }
@@ -1766,7 +1706,6 @@ function ConfirmProvider({ children }) {
1766
1706
  const currentRequest = queue[0];
1767
1707
  useEffect(() => {
1768
1708
  registerConfirm(async (options) => {
1769
- console.log("ConfirmProvider received options:", options);
1770
1709
  return new Promise((resolve) => {
1771
1710
  setQueue((q) => [...q, { options, resolve }]);
1772
1711
  });
@@ -1790,5 +1729,5 @@ function ConfirmProvider({ children }) {
1790
1729
  return (jsxs(Fragment, { children: [children, jsx(Dialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxs(DialogContent, { children: [jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: currentRequest?.options?.title || "Bestätigung erforderlich" }), currentRequest?.options?.description && (jsx(DialogDescription, { children: currentRequest.options.description }))] }), jsxs(DialogFooter, { children: [jsx(Button, { variant: "outline", onClick: handleCancel, children: currentRequest?.options.cancelLabel || "Abbrechen" }), jsx(Button, { variant: currentRequest?.options.variant || "default", onClick: handleConfirm, children: currentRequest?.options.confirmLabel || "Bestätigen" })] })] }) })] }));
1791
1730
  }
1792
1731
 
1793
- export { ActionsColumn, AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DropdownColumn, EmptyStateBuilder, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TableSchema, TextColumn, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, IconColumn as iconColumn, InputColumn as inputColumn, ProgressColumn as progressColumn, SelectColumn as selectColumn, TextColumn as textColumn };
1732
+ 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 };
1794
1733
  //# sourceMappingURL=index.esm.js.map