@eztrak/shared 0.14.0 → 0.15.0

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.
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/components/index.ts
31
31
  var components_exports = {};
32
32
  __export(components_exports, {
33
+ ActionMenuItem: () => ActionMenuItem,
33
34
  CardSkeleton: () => CardSkeleton,
34
35
  CustomCellEditor: () => CustomCellEditor,
35
36
  CustomPagination: () => CustomPagination,
@@ -38,14 +39,20 @@ __export(components_exports, {
38
39
  Loader: () => Loader,
39
40
  Modal: () => Modal,
40
41
  PopupCellRenderer: () => PopupCellRenderer,
42
+ ROW_ACTION_DEFAULT_ICON_SIZE: () => ROW_ACTION_DEFAULT_ICON_SIZE,
43
+ ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE: () => ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE,
44
+ ROW_ACTION_ITEM_HOVER_CLASS: () => ROW_ACTION_ITEM_HOVER_CLASS,
45
+ ROW_ACTION_PRESETS: () => ROW_ACTION_PRESETS,
41
46
  ResetColumnsButton: () => ResetColumnsButton,
42
47
  ResetFiltersButton: () => ResetFiltersButton,
48
+ RowActions: () => RowActions,
43
49
  SearchInput: () => SearchInput,
44
50
  TableErrorBoundary: () => TableErrorBoundary,
45
51
  TableLayoutToolbarControls: () => TableLayoutToolbarControls,
46
52
  ToolTip: () => ToolTip,
47
53
  TooltipText: () => TooltipText,
48
- dropdownStyles: () => dropdownStyles
54
+ dropdownStyles: () => dropdownStyles,
55
+ resolveActions: () => resolveActions
49
56
  });
50
57
  module.exports = __toCommonJS(components_exports);
51
58
 
@@ -1749,7 +1756,8 @@ function PopupCellRenderer({
1749
1756
  params,
1750
1757
  onAction,
1751
1758
  placement = "bottom-end",
1752
- tippyProps
1759
+ tippyProps,
1760
+ ariaLabel = "Row actions"
1753
1761
  }) {
1754
1762
  const [visible, setVisible] = (0, import_react7.useState)(false);
1755
1763
  const show = () => setVisible(true);
@@ -1785,7 +1793,7 @@ function PopupCellRenderer({
1785
1793
  "flex items-center justify-center gap-2 rounded-full text-gray-500 hover:text-gray-800",
1786
1794
  className
1787
1795
  ),
1788
- "aria-label": "Row actions",
1796
+ "aria-label": ariaLabel,
1789
1797
  children: [
1790
1798
  !hideTitle && title,
1791
1799
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ActionIcon, { "aria-hidden": true })
@@ -1796,10 +1804,296 @@ function PopupCellRenderer({
1796
1804
  ) });
1797
1805
  }
1798
1806
 
1807
+ // src/components/row-actions/presets.ts
1808
+ var import_fa2 = require("react-icons/fa");
1809
+ var ROW_ACTION_ITEM_HOVER_CLASS = "hover:bg-primary-50 hover:text-primary-150";
1810
+ var ROW_ACTION_DEFAULT_ICON_SIZE = 16;
1811
+ var ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE = {
1812
+ zIndex: 1e4
1813
+ };
1814
+ var ROW_ACTION_PRESETS = {
1815
+ edit: { label: "Edit", icon: import_fa2.FaEdit },
1816
+ delete: { label: "Delete", icon: import_fa2.FaTrashAlt, danger: true },
1817
+ view: { label: "View", icon: import_fa2.FaEye },
1818
+ notes: { label: "Notes", icon: import_fa2.FaFileAlt },
1819
+ history: { label: "History", icon: import_fa2.FaHistory },
1820
+ download: { label: "Download", icon: import_fa2.FaDownload },
1821
+ archive: { label: "Archive", icon: import_fa2.FaArchive },
1822
+ resolve: { label: "Resolve", icon: import_fa2.FaCheckCircle }
1823
+ };
1824
+
1825
+ // src/components/row-actions/ActionMenuItem.tsx
1826
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1827
+ function ActionMenuItem({
1828
+ label,
1829
+ icon: Icon,
1830
+ iconSize = ROW_ACTION_DEFAULT_ICON_SIZE,
1831
+ iconClassName,
1832
+ tooltip,
1833
+ tooltipPlacement = "top",
1834
+ tooltipDelayShow,
1835
+ tooltipDelayHide,
1836
+ tooltipClassName,
1837
+ tooltipStyle,
1838
+ disabled = false,
1839
+ danger = false,
1840
+ highlight = false,
1841
+ showLabel = true,
1842
+ className,
1843
+ onClick
1844
+ }) {
1845
+ const tooltipText = tooltip ?? label;
1846
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1847
+ ToolTip,
1848
+ {
1849
+ text: tooltipText,
1850
+ disabled: !tooltipText,
1851
+ placement: tooltipPlacement,
1852
+ delayShow: tooltipDelayShow,
1853
+ delayHide: tooltipDelayHide,
1854
+ tooltipClassName,
1855
+ tooltipStyle: { ...ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE, ...tooltipStyle },
1856
+ className: showLabel ? "block w-full" : "inline-flex",
1857
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1858
+ "button",
1859
+ {
1860
+ type: "button",
1861
+ disabled,
1862
+ "aria-label": label,
1863
+ onClick: (event) => {
1864
+ event.stopPropagation();
1865
+ if (disabled) return;
1866
+ onClick();
1867
+ },
1868
+ className: cn(
1869
+ "flex items-center gap-2 text-sm transition-colors duration-150",
1870
+ showLabel ? "w-full rounded-xl px-3 py-2 text-left" : "justify-center rounded-md p-1",
1871
+ disabled ? "cursor-not-allowed opacity-50" : ROW_ACTION_ITEM_HOVER_CLASS,
1872
+ danger && "text-red-500",
1873
+ highlight && !danger && "text-primary-150",
1874
+ className
1875
+ ),
1876
+ children: [
1877
+ Icon ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1878
+ Icon,
1879
+ {
1880
+ className: cn("shrink-0", iconClassName),
1881
+ "aria-hidden": true,
1882
+ size: iconSize
1883
+ }
1884
+ ) : null,
1885
+ showLabel ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: label }) : null
1886
+ ]
1887
+ }
1888
+ )
1889
+ }
1890
+ );
1891
+ }
1892
+
1893
+ // src/components/row-actions/resolveActions.ts
1894
+ function evalFlag(flag, data) {
1895
+ if (typeof flag === "function") return Boolean(flag(data));
1896
+ return Boolean(flag);
1897
+ }
1898
+ function mergePreset(name, overrides) {
1899
+ if (!name) return void 0;
1900
+ const base = ROW_ACTION_PRESETS[name];
1901
+ const extra = overrides?.[name];
1902
+ if (!extra) return base;
1903
+ return { ...base, ...extra };
1904
+ }
1905
+ function resolveActions(actions, data, hasPermission, presets) {
1906
+ const list = typeof actions === "function" ? actions(data) : actions;
1907
+ return list.flatMap((action, index) => {
1908
+ const type = action.type ?? "item";
1909
+ const preset = mergePreset(action.preset, presets);
1910
+ const key = action.key ?? action.preset ?? `action-${index}`;
1911
+ const label = action.label ?? preset?.label ?? key;
1912
+ if (action.permission && hasPermission && !hasPermission(action.permission)) {
1913
+ return [];
1914
+ }
1915
+ if (evalFlag(action.hidden, data)) {
1916
+ return [];
1917
+ }
1918
+ const tooltip = action.tooltip === false ? void 0 : action.tooltip ?? (type === "divider" ? void 0 : label);
1919
+ const resolved = {
1920
+ key,
1921
+ type,
1922
+ label,
1923
+ icon: action.icon ?? preset?.icon,
1924
+ iconSize: action.iconSize,
1925
+ content: action.content,
1926
+ onClick: action.onClick,
1927
+ disabled: evalFlag(action.disabled, data),
1928
+ danger: action.danger ?? preset?.danger ?? false,
1929
+ highlight: evalFlag(action.highlight, data),
1930
+ tooltip,
1931
+ tooltipPlacement: action.tooltipPlacement,
1932
+ confirm: action.confirm,
1933
+ closeOnClick: action.closeOnClick !== false,
1934
+ className: action.className
1935
+ };
1936
+ return [resolved];
1937
+ });
1938
+ }
1939
+
1940
+ // src/components/row-actions/RowActions.tsx
1941
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1942
+ function runAction(action, data, hide, confirmFn = confirmationAlert) {
1943
+ if (!action.onClick) {
1944
+ if (action.closeOnClick) hide?.();
1945
+ return;
1946
+ }
1947
+ const execute = () => action.onClick?.(data);
1948
+ if (action.confirm) {
1949
+ confirmFn?.(execute, action.confirm);
1950
+ } else {
1951
+ execute();
1952
+ }
1953
+ if (action.closeOnClick) {
1954
+ hide?.();
1955
+ }
1956
+ }
1957
+ function RowActions({
1958
+ actions,
1959
+ data,
1960
+ mode = "menu",
1961
+ actionIcon,
1962
+ className,
1963
+ menuClassName,
1964
+ itemClassName,
1965
+ itemIconClassName,
1966
+ iconSize = ROW_ACTION_DEFAULT_ICON_SIZE,
1967
+ triggerTooltip = "Actions",
1968
+ triggerAriaLabel = "Row actions",
1969
+ hasPermission,
1970
+ placement = "bottom-end",
1971
+ tippyProps,
1972
+ presets,
1973
+ confirmFn = confirmationAlert,
1974
+ tooltipPlacement = "top",
1975
+ tooltipDelayShow,
1976
+ tooltipDelayHide,
1977
+ tooltipClassName,
1978
+ tooltipStyle,
1979
+ renderItem,
1980
+ renderMenu,
1981
+ renderTrigger
1982
+ }) {
1983
+ const resolved = resolveActions(actions, data, hasPermission, presets);
1984
+ if (resolved.length === 0) {
1985
+ return null;
1986
+ }
1987
+ const mergedTooltipStyle = {
1988
+ ...ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE,
1989
+ ...tooltipStyle
1990
+ };
1991
+ const renderDefaultItem = (action, hide, showLabel = true) => {
1992
+ if (action.type === "divider") {
1993
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1994
+ "div",
1995
+ {
1996
+ role: "separator",
1997
+ className: cn("my-1 h-px bg-gray-100", action.className)
1998
+ },
1999
+ action.key
2000
+ );
2001
+ }
2002
+ if (action.content) {
2003
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: action.className, children: action.content }, action.key);
2004
+ }
2005
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2006
+ ActionMenuItem,
2007
+ {
2008
+ label: action.label,
2009
+ icon: action.icon,
2010
+ iconSize: action.iconSize ?? iconSize,
2011
+ iconClassName: itemIconClassName,
2012
+ tooltip: action.tooltip,
2013
+ tooltipPlacement: action.tooltipPlacement ?? tooltipPlacement,
2014
+ tooltipDelayShow,
2015
+ tooltipDelayHide,
2016
+ tooltipClassName,
2017
+ tooltipStyle: mergedTooltipStyle,
2018
+ disabled: action.disabled,
2019
+ danger: action.danger,
2020
+ highlight: action.highlight,
2021
+ showLabel,
2022
+ className: cn(itemClassName, action.className),
2023
+ onClick: () => runAction(action, data, hide, confirmFn)
2024
+ },
2025
+ action.key
2026
+ );
2027
+ };
2028
+ const renderItems = (hide, showLabel = true) => resolved.map((action) => {
2029
+ const defaultItem = renderDefaultItem(action, hide, showLabel);
2030
+ if (!renderItem) return defaultItem;
2031
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { children: renderItem(action, { data, hide: hide ?? (() => void 0), defaultItem }) }, action.key);
2032
+ });
2033
+ if (mode === "inline") {
2034
+ const inlineItems = renderItems(void 0, false);
2035
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: cn("flex h-full items-center justify-center gap-1", className), children: inlineItems });
2036
+ }
2037
+ const triggerTooltipText = triggerTooltip === false ? void 0 : triggerTooltip;
2038
+ const buildMenu = (hide) => {
2039
+ const defaultMenu = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2040
+ "div",
2041
+ {
2042
+ className: cn(
2043
+ "flex min-w-[180px] flex-col rounded-lg border border-gray-100 bg-white p-2 shadow-lg",
2044
+ menuClassName
2045
+ ),
2046
+ children: renderItems(hide, true)
2047
+ }
2048
+ );
2049
+ if (!renderMenu) return defaultMenu;
2050
+ return renderMenu({
2051
+ data,
2052
+ actions: resolved,
2053
+ hide,
2054
+ defaultMenu
2055
+ });
2056
+ };
2057
+ if (renderTrigger) {
2058
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: renderTrigger({
2059
+ data,
2060
+ actions: resolved,
2061
+ hide: () => void 0,
2062
+ defaultMenu: buildMenu(() => void 0)
2063
+ }) });
2064
+ }
2065
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2066
+ ToolTip,
2067
+ {
2068
+ text: triggerTooltipText,
2069
+ disabled: !triggerTooltipText,
2070
+ placement: tooltipPlacement,
2071
+ delayShow: tooltipDelayShow,
2072
+ delayHide: tooltipDelayHide,
2073
+ tooltipClassName,
2074
+ tooltipStyle,
2075
+ className: "flex h-full items-center justify-center",
2076
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2077
+ PopupCellRenderer,
2078
+ {
2079
+ params: { data },
2080
+ actionIcon,
2081
+ hideTitle: true,
2082
+ className,
2083
+ placement,
2084
+ tippyProps,
2085
+ ariaLabel: triggerAriaLabel,
2086
+ dropDownContent: (handleAction) => buildMenu(() => handleAction("close"))
2087
+ }
2088
+ )
2089
+ }
2090
+ );
2091
+ }
2092
+
1799
2093
  // src/components/table-error-boundary/TableErrorBoundary.tsx
1800
2094
  var import_react9 = require("react");
1801
2095
  var import_fa6 = require("react-icons/fa6");
1802
- var import_jsx_runtime13 = require("react/jsx-runtime");
2096
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1803
2097
  var TableErrorBoundary = ({
1804
2098
  isError,
1805
2099
  isLoading = false,
@@ -1816,7 +2110,7 @@ var TableErrorBoundary = ({
1816
2110
  return "Unable to load table data. Please try again.";
1817
2111
  }, [error, errorMessage]);
1818
2112
  if (isLoading && !isError) {
1819
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2113
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1820
2114
  "div",
1821
2115
  {
1822
2116
  className: cn(
@@ -1827,12 +2121,12 @@ var TableErrorBoundary = ({
1827
2121
  role: "status",
1828
2122
  "aria-live": "polite",
1829
2123
  "aria-busy": "true",
1830
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Loader, { size: "40px" })
2124
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Loader, { size: "40px" })
1831
2125
  }
1832
2126
  );
1833
2127
  }
1834
2128
  if (isError) {
1835
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
2129
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1836
2130
  "div",
1837
2131
  {
1838
2132
  className: cn(
@@ -1843,7 +2137,7 @@ var TableErrorBoundary = ({
1843
2137
  role: "alert",
1844
2138
  "aria-live": "assertive",
1845
2139
  children: [
1846
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2140
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1847
2141
  import_fa6.FaTriangleExclamation,
1848
2142
  {
1849
2143
  className: "text-red-500",
@@ -1851,11 +2145,11 @@ var TableErrorBoundary = ({
1851
2145
  "aria-hidden": true
1852
2146
  }
1853
2147
  ),
1854
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "max-w-md space-y-1", children: [
1855
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-base font-semibold text-gray-800", children: "Failed to load data" }),
1856
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-sm text-gray-600", children: message })
2148
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "max-w-md space-y-1", children: [
2149
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-base font-semibold text-gray-800", children: "Failed to load data" }),
2150
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-sm text-gray-600", children: message })
1857
2151
  ] }),
1858
- refetch && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
2152
+ refetch && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1859
2153
  "button",
1860
2154
  {
1861
2155
  type: "button",
@@ -1863,7 +2157,7 @@ var TableErrorBoundary = ({
1863
2157
  disabled: isLoading,
1864
2158
  className: "inline-flex items-center gap-2 rounded-lg bg-primary-150 px-4 py-2 text-sm font-medium text-white transition-colors hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",
1865
2159
  children: [
1866
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_fa6.FaArrowsRotate, { className: cn(isLoading && "animate-spin") }),
2160
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_fa6.FaArrowsRotate, { className: cn(isLoading && "animate-spin") }),
1867
2161
  isLoading ? "Retrying..." : "Try again"
1868
2162
  ]
1869
2163
  }
@@ -1872,10 +2166,11 @@ var TableErrorBoundary = ({
1872
2166
  }
1873
2167
  );
1874
2168
  }
1875
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children });
2169
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
1876
2170
  };
1877
2171
  // Annotate the CommonJS export names for ESM import in node:
1878
2172
  0 && (module.exports = {
2173
+ ActionMenuItem,
1879
2174
  CardSkeleton,
1880
2175
  CustomCellEditor,
1881
2176
  CustomPagination,
@@ -1884,13 +2179,19 @@ var TableErrorBoundary = ({
1884
2179
  Loader,
1885
2180
  Modal,
1886
2181
  PopupCellRenderer,
2182
+ ROW_ACTION_DEFAULT_ICON_SIZE,
2183
+ ROW_ACTION_DEFAULT_MENU_TOOLTIP_STYLE,
2184
+ ROW_ACTION_ITEM_HOVER_CLASS,
2185
+ ROW_ACTION_PRESETS,
1887
2186
  ResetColumnsButton,
1888
2187
  ResetFiltersButton,
2188
+ RowActions,
1889
2189
  SearchInput,
1890
2190
  TableErrorBoundary,
1891
2191
  TableLayoutToolbarControls,
1892
2192
  ToolTip,
1893
2193
  TooltipText,
1894
- dropdownStyles
2194
+ dropdownStyles,
2195
+ resolveActions
1895
2196
  });
1896
2197
  //# sourceMappingURL=index.js.map