pam-grid 1.0.8 → 1.1.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.
package/dist/index.mjs CHANGED
@@ -53,7 +53,7 @@ function AdvanceFilter({
53
53
  );
54
54
  };
55
55
  if (!type) return null;
56
- return /* @__PURE__ */ jsxs("div", { style: { width: 240 }, onClick: (e) => e.stopPropagation(), children: [
56
+ return /* @__PURE__ */ jsxs("div", { style: { width: 270 }, onClick: (e) => e.stopPropagation(), children: [
57
57
  /* @__PURE__ */ jsxs("div", { className: "mb-2", children: [
58
58
  /* @__PURE__ */ jsx("label", { className: "form-label", children: "Condition" }),
59
59
  /* @__PURE__ */ jsxs(
@@ -111,6 +111,15 @@ function AdvanceFilter({
111
111
 
112
112
  // src/core/utils.ts
113
113
  import { useEffect as useEffect2, useState as useState2 } from "react";
114
+ var EDGE_SIZE = 8;
115
+ var getResizeSide = (e, index) => {
116
+ const rect = e.currentTarget.getBoundingClientRect();
117
+ const nearRight = rect.right - e.clientX < EDGE_SIZE;
118
+ const nearLeft = e.clientX - rect.left < EDGE_SIZE;
119
+ if (nearRight) return "right";
120
+ if (nearLeft && index > 0) return "left";
121
+ return null;
122
+ };
114
123
  function getAdvancedFilterType(column) {
115
124
  const f = column.enableAdvancedFilter;
116
125
  if (!f) return null;
@@ -178,6 +187,9 @@ function useLocalStorageState(key, initialValue) {
178
187
  }, [key]);
179
188
  return [value, updateValue];
180
189
  }
190
+ var resolveValue = (value, row) => {
191
+ return typeof value === "function" ? value(row) : value;
192
+ };
181
193
 
182
194
  // src/components/FacetFilter.tsx
183
195
  import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
@@ -1266,6 +1278,7 @@ var PamGrid = ({
1266
1278
  isDropdown = false,
1267
1279
  maxHeight = "80vh",
1268
1280
  isFetching = false,
1281
+ customeDiv,
1269
1282
  addNew,
1270
1283
  renderExpanded
1271
1284
  }) => {
@@ -1307,16 +1320,25 @@ var PamGrid = ({
1307
1320
  advanceFilters,
1308
1321
  setColumnAdvanceFilter
1309
1322
  } = grid ?? safeGridHandle;
1310
- const onResizeMouseDown = (e, key) => {
1323
+ const onResizeMouseDown = (e, key, side = "right") => {
1311
1324
  e.preventDefault();
1312
1325
  const startX = e.clientX;
1313
- const col = colState.find((c) => c.key === key);
1314
- if (!col) return;
1315
- const startWidth = col.width || 120;
1326
+ const colIndex = colState.findIndex((c) => c.key === key);
1327
+ if (colIndex === -1) return;
1328
+ let targetIndex = colIndex;
1329
+ if (side === "left" && colIndex > 0) {
1330
+ targetIndex = colIndex - 1;
1331
+ }
1332
+ const targetCol = colState[targetIndex];
1333
+ if (!targetCol) return;
1334
+ const startWidth = targetCol.width || 120;
1316
1335
  const onMove = (ev) => {
1317
- const diff = ev.clientX - startX;
1336
+ let diff = ev.clientX - startX;
1337
+ if (side === "left") {
1338
+ diff = -diff;
1339
+ }
1318
1340
  const newWidth = Math.max(60, startWidth + diff);
1319
- updateColumn(key, { width: newWidth });
1341
+ updateColumn(targetCol.key, { width: newWidth });
1320
1342
  };
1321
1343
  const onUp = () => {
1322
1344
  document.removeEventListener("mousemove", onMove);
@@ -1423,9 +1445,10 @@ var PamGrid = ({
1423
1445
  ]
1424
1446
  }
1425
1447
  ),
1426
- /* @__PURE__ */ jsx13("div", { className: "flex-shrink-0", children: isFullScreen ? /* @__PURE__ */ jsx13(Minimize_default, { onClick: () => setFullScreen(!isFullScreen) }) : /* @__PURE__ */ jsx13(Compress_default, { onClick: () => setFullScreen(!isFullScreen) }) })
1448
+ /* @__PURE__ */ jsx13("div", { className: `flex-shrink-0 ${features.fullScreen ? "" : "d-none"}`, children: isFullScreen ? /* @__PURE__ */ jsx13(Minimize_default, { onClick: () => setFullScreen(!isFullScreen) }) : /* @__PURE__ */ jsx13(Compress_default, { onClick: () => setFullScreen(!isFullScreen) }) })
1427
1449
  ] }) })
1428
1450
  ] }),
1451
+ customeDiv && customeDiv,
1429
1452
  /* @__PURE__ */ jsxs10("div", { className: "d-flex flex-row gap-1", children: [
1430
1453
  selected.size > 0 && features.bulkActionsConfig && /* @__PURE__ */ jsx13(BulkAction_default, { records: selected, actions: features.bulkActionsConfig }),
1431
1454
  /* @__PURE__ */ jsx13(
@@ -1478,7 +1501,7 @@ var PamGrid = ({
1478
1501
  )
1479
1502
  }
1480
1503
  ),
1481
- visibleColumns.map((col) => {
1504
+ visibleColumns.map((col, index) => {
1482
1505
  const style = {
1483
1506
  minWidth: col.width || 120,
1484
1507
  width: col.width,
@@ -1501,18 +1524,41 @@ var PamGrid = ({
1501
1524
  onDragEnd: () => setDraggingCol(null),
1502
1525
  onDragOver: (e) => e.preventDefault(),
1503
1526
  onDrop: (e) => onDrop(e, col.key),
1527
+ onMouseMove: (e) => {
1528
+ const side = getResizeSide(e, index);
1529
+ if (side) {
1530
+ e.currentTarget.style.cursor = "col-resize";
1531
+ } else if (draggingCol === col.key) {
1532
+ e.currentTarget.style.cursor = "grabbing";
1533
+ } else if (features.reorder) {
1534
+ e.currentTarget.style.cursor = "grab";
1535
+ } else {
1536
+ e.currentTarget.style.cursor = "default";
1537
+ }
1538
+ },
1539
+ onMouseLeave: (e) => {
1540
+ e.currentTarget.style.cursor = "default";
1541
+ },
1542
+ onMouseDown: (e) => {
1543
+ const side = getResizeSide(e, index);
1544
+ if (!side) return;
1545
+ e.stopPropagation();
1546
+ onResizeMouseDown(e, col.key, side);
1547
+ },
1504
1548
  className: `pms-col-header vs-th
1505
- ${features.reorder ? "cursor-grab" : ""}
1506
- ${draggingCol === col.key ? "cursor-grabbing" : ""}
1507
- ${col.pinned ? `pinned pinned-${col.pinned}` : ""}
1508
- `,
1549
+ ${col.pinned ? `pinned pinned-${col.pinned}` : ""}
1550
+ `,
1509
1551
  style,
1510
- children: /* @__PURE__ */ jsxs10(
1511
- "div",
1512
- {
1513
- className: `d-flex align-items-center justify-content-${col.align ?? "between"} px-1 rounded ${col.pinned ? "z-6" : ""}`,
1514
- children: [
1515
- /* @__PURE__ */ jsxs10(
1552
+ children: /* @__PURE__ */ jsxs10("div", { className: "d-flex align-items-center w-100 px-1", children: [
1553
+ /* @__PURE__ */ jsx13(
1554
+ "div",
1555
+ {
1556
+ className: `flex-grow-1 d-flex align-items-center
1557
+ ${col.align === "center" ? "justify-content-center" : ""}
1558
+ ${col.align === "end" ? "justify-content-end" : ""}
1559
+ ${!col.align || col.align === "start" ? "justify-content-start" : ""}
1560
+ `,
1561
+ children: /* @__PURE__ */ jsxs10(
1516
1562
  "div",
1517
1563
  {
1518
1564
  onClick: () => col.sortable && changeSort(String(col.key)),
@@ -1522,31 +1568,23 @@ var PamGrid = ({
1522
1568
  sortBy.key === col.key && /* @__PURE__ */ jsx13(
1523
1569
  "i",
1524
1570
  {
1525
- className: `bx bx-sm ${sortBy.dir === "asc" ? "bxs-chevron-up" : "bxs-chevron-down"} cursor-pointer`
1571
+ className: `bx bx-sm ${sortBy.dir === "asc" ? "bxs-chevron-up" : "bxs-chevron-down"}`
1526
1572
  }
1527
- ),
1528
- col.pinned === col.key && /* @__PURE__ */ jsx13("i", { className: "bx bx-x cursor-pointer" })
1573
+ )
1529
1574
  ]
1530
1575
  }
1531
- ),
1532
- /* @__PURE__ */ jsx13(
1533
- "i",
1534
- {
1535
- className: "bx bx-move-horizontal text-white cursor-resize",
1536
- onMouseDown: (e) => onResizeMouseDown(e, col.key)
1537
- }
1538
- ),
1539
- /* @__PURE__ */ jsx13("div", { className: "d-flex align-items-center gap-1", children: features.pinning && /* @__PURE__ */ jsx13(
1540
- PamHeaderOption_default,
1541
- {
1542
- currentColumn: col,
1543
- gridFetaures: features,
1544
- grid
1545
- }
1546
- ) })
1547
- ]
1548
- }
1549
- )
1576
+ )
1577
+ }
1578
+ ),
1579
+ /* @__PURE__ */ jsx13("div", { className: "d-flex align-items-center gap-1 flex-shrink-0", children: features.pinning && /* @__PURE__ */ jsx13(
1580
+ PamHeaderOption_default,
1581
+ {
1582
+ currentColumn: col,
1583
+ gridFetaures: features,
1584
+ grid
1585
+ }
1586
+ ) })
1587
+ ] })
1550
1588
  },
1551
1589
  String(col.key)
1552
1590
  );
@@ -1554,7 +1592,7 @@ var PamGrid = ({
1554
1592
  features.actions && /* @__PURE__ */ jsx13(
1555
1593
  "th",
1556
1594
  {
1557
- className: "text-center sticky-action-column vs-th bg-white fw-semibold th-lastChild",
1595
+ className: "text-center sticky-action-column vs-th bg-white th-lastChild",
1558
1596
  style: { position: "sticky", right: 0, zIndex: 10 },
1559
1597
  children: "Action"
1560
1598
  }
@@ -1592,7 +1630,7 @@ var PamGrid = ({
1592
1630
  className: "text-start pinned pinned-left tr-group",
1593
1631
  children: [
1594
1632
  /* @__PURE__ */ jsx13("strong", { children: g.displayLabel }),
1595
- features.aggregation && Object.keys(g.aggregates).length > 0 && /* @__PURE__ */ jsx13("small", { className: "ms-3 text-muted ", children: Object.entries(g.aggregates).map(([k, v]) => `${k}: ${v}`).join(" | ") })
1633
+ features.aggregation && Object.keys(g.aggregates).length > 0 && /* @__PURE__ */ jsx13("small", { className: "ms-3 text-secondary text-capitalize ", children: Object.entries(g.aggregates).map(([k, v]) => `${k}: ${v}`).join(" | ") })
1596
1634
  ]
1597
1635
  }
1598
1636
  ) }),
@@ -1713,34 +1751,58 @@ var PamGrid = ({
1713
1751
  width: "1%",
1714
1752
  whiteSpace: "nowrap"
1715
1753
  },
1716
- children: isDropdown ? /* @__PURE__ */ jsx13("div", { className: "text-center ", children: /* @__PURE__ */ jsx13(TableAction, { gridFetaures: features, row }) }) : /* @__PURE__ */ jsx13(
1754
+ children: isDropdown ? /* @__PURE__ */ jsx13("div", { className: "text-center", children: /* @__PURE__ */ jsx13(TableAction, { gridFetaures: features, row }) }) : /* @__PURE__ */ jsx13(
1717
1755
  "div",
1718
1756
  {
1719
1757
  className: "d-inline-flex justify-content-center align-items-center gap-2",
1720
1758
  style: { minWidth: "fit-content", padding: "0 4px" },
1721
1759
  children: Array.isArray(features.actions) ? features.actions.filter((act) => {
1722
- if (typeof act.isVisible === "function") {
1723
- return act.isVisible(row);
1724
- }
1725
- if (typeof act.isVisible === "boolean") {
1726
- return act.isVisible;
1727
- }
1728
- return true;
1729
- }).map((act, i) => /* @__PURE__ */ jsx13(
1730
- "i",
1731
- {
1732
- title: act.label,
1733
- onClick: (e) => {
1734
- e.stopPropagation();
1735
- act.onClick && act.onClick(row);
1760
+ const visible = resolveValue(
1761
+ act.isVisible ?? true,
1762
+ row
1763
+ );
1764
+ return visible;
1765
+ }).map((act, i) => {
1766
+ const label = resolveValue(act.label, row);
1767
+ const icon = resolveValue(act.icon, row);
1768
+ const className = resolveValue(act.className, row);
1769
+ const disabled = resolveValue(
1770
+ act.disabled ?? false,
1771
+ row
1772
+ );
1773
+ return act.onlyIcon ? /* @__PURE__ */ jsx13(
1774
+ "i",
1775
+ {
1776
+ title: label,
1777
+ onClick: (e) => {
1778
+ e.stopPropagation();
1779
+ if (!disabled) act.onClick?.(row);
1780
+ },
1781
+ className: `${icon} ${disabled ? "opacity-50" : ""}`,
1782
+ style: {
1783
+ cursor: disabled ? "not-allowed" : "pointer"
1784
+ },
1785
+ onMouseMove: (e) => typeof label === "string" && showTooltip(label, e.clientX, e.clientY),
1786
+ onMouseLeave: hideTooltip
1787
+ },
1788
+ i
1789
+ ) : /* @__PURE__ */ jsxs10(
1790
+ "button",
1791
+ {
1792
+ className,
1793
+ disabled,
1794
+ onClick: (e) => {
1795
+ e.stopPropagation();
1796
+ if (!disabled) act.onClick?.(row);
1797
+ },
1798
+ children: [
1799
+ icon && /* @__PURE__ */ jsx13("i", { className: `${icon} me-1` }),
1800
+ label
1801
+ ]
1736
1802
  },
1737
- className: `${act.icon}`,
1738
- onMouseEnter: (e) => showTooltip(act.label, e.clientX, e.clientY),
1739
- onMouseMove: (e) => showTooltip(act.label, e.clientX, e.clientY),
1740
- onMouseLeave: hideTooltip
1741
- },
1742
- i
1743
- )) : typeof features.actions === "function" ? features.actions(row, toggleExpand) : null
1803
+ i
1804
+ );
1805
+ }) : typeof features.actions === "function" ? features.actions(row, toggleExpand) : null
1744
1806
  }
1745
1807
  )
1746
1808
  }