@facter/ds-core 1.23.0 → 1.24.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
@@ -1424,27 +1424,23 @@ function useAvailableHeight(options = {}) {
1424
1424
  function useAutoPageSize(options = {}) {
1425
1425
  const {
1426
1426
  rowHeight = 49,
1427
- headerHeight = 41,
1428
- paginationHeight = 52,
1429
- bottomOffset = 16,
1430
- minRows = 5,
1427
+ bottomOffset = 64,
1428
+ minRows = 3,
1431
1429
  maxRows = 50,
1432
1430
  enabled = true
1433
1431
  } = options;
1434
1432
  const ref = useRef(null);
1435
1433
  const [autoPerPage, setAutoPerPage] = useState(minRows);
1436
1434
  const [userOverride, setUserOverride] = useState(null);
1437
- const hasCalculated = useRef(false);
1438
1435
  const calculate = useCallback(() => {
1439
1436
  const el = ref.current;
1440
1437
  if (!el || !enabled) return;
1441
1438
  const rect = el.getBoundingClientRect();
1442
- const availableHeight = window.innerHeight - rect.top - headerHeight - paginationHeight - bottomOffset;
1439
+ const availableHeight = window.innerHeight - rect.top - bottomOffset;
1443
1440
  const rows = Math.floor(availableHeight / rowHeight);
1444
1441
  const clamped = Math.max(minRows, Math.min(maxRows, rows));
1445
1442
  setAutoPerPage(clamped);
1446
- hasCalculated.current = true;
1447
- }, [rowHeight, headerHeight, paginationHeight, bottomOffset, minRows, maxRows, enabled]);
1443
+ }, [rowHeight, bottomOffset, minRows, maxRows, enabled]);
1448
1444
  useEffect(() => {
1449
1445
  if (!enabled) return;
1450
1446
  const frame = requestAnimationFrame(calculate);
@@ -1457,14 +1453,12 @@ function useAutoPageSize(options = {}) {
1457
1453
  const setPerPage = useCallback((size) => {
1458
1454
  setUserOverride(size);
1459
1455
  }, []);
1460
- const perPage = userOverride ?? autoPerPage;
1461
1456
  return {
1462
1457
  ref,
1463
- perPage,
1458
+ perPage: userOverride ?? autoPerPage,
1464
1459
  setPerPage,
1465
1460
  autoPerPage,
1466
- isAutoSized: userOverride === null,
1467
- isReady: hasCalculated.current
1461
+ isAutoSized: userOverride === null
1468
1462
  };
1469
1463
  }
1470
1464
  var Table = React10.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
@@ -1552,6 +1546,7 @@ var DataTableContent = React10.memo(function DataTableContent2({
1552
1546
  onRowClick,
1553
1547
  scrollable = false,
1554
1548
  scrollBottomOffset = 68,
1549
+ autoPageSize = false,
1555
1550
  className
1556
1551
  }) {
1557
1552
  const table = useDataTable();
@@ -1559,15 +1554,36 @@ var DataTableContent = React10.memo(function DataTableContent2({
1559
1554
  const { density } = useDataTableDensity();
1560
1555
  const { config: emptyStateConfig } = useDataTableEmptyStateConfig();
1561
1556
  const { isLoading, skeletonRows } = useDataTableLoadingState();
1562
- const { ref, style: scrollStyle } = useAvailableHeight({
1557
+ const { setPageSize } = useDataTablePagination();
1558
+ const tbodyRef = React10.useRef(null);
1559
+ const { ref: scrollRef, style: scrollStyle } = useAvailableHeight({
1563
1560
  bottomOffset: scrollBottomOffset,
1564
1561
  enabled: scrollable
1565
1562
  });
1566
1563
  const densityStyles = DENSITY_CONFIG[density];
1564
+ const rowHeight = densityStyles.rowHeight + 1;
1567
1565
  const cellClasses = cn(densityStyles.padding, densityStyles.fontSize);
1568
1566
  const columnCount = table.getVisibleLeafColumns().length;
1569
1567
  const hasRows = table.getRowModel().rows?.length > 0;
1570
1568
  const effectiveStickyHeader = stickyHeader || scrollable;
1569
+ React10.useEffect(() => {
1570
+ if (!autoPageSize) return;
1571
+ const calculate = () => {
1572
+ const tbody = tbodyRef.current;
1573
+ if (!tbody) return;
1574
+ const rect = tbody.getBoundingClientRect();
1575
+ const available = window.innerHeight - rect.top - 68;
1576
+ const rows = Math.floor(available / rowHeight);
1577
+ const clamped = Math.max(3, Math.min(50, rows));
1578
+ setPageSize(clamped);
1579
+ };
1580
+ const frame = requestAnimationFrame(calculate);
1581
+ window.addEventListener("resize", calculate);
1582
+ return () => {
1583
+ cancelAnimationFrame(frame);
1584
+ window.removeEventListener("resize", calculate);
1585
+ };
1586
+ }, [autoPageSize, rowHeight, setPageSize]);
1571
1587
  if (!hasRows && isEmpty && !isLoading) {
1572
1588
  return /* @__PURE__ */ jsx(
1573
1589
  EmptyState,
@@ -1582,7 +1598,7 @@ var DataTableContent = React10.memo(function DataTableContent2({
1582
1598
  return /* @__PURE__ */ jsx(
1583
1599
  "div",
1584
1600
  {
1585
- ref,
1601
+ ref: scrollRef,
1586
1602
  className: cn("rounded-md overflow-auto bg-card", className),
1587
1603
  style: scrollStyle,
1588
1604
  children: /* @__PURE__ */ jsxs(Table, { children: [
@@ -1606,7 +1622,7 @@ var DataTableContent = React10.memo(function DataTableContent2({
1606
1622
  )) }, headerGroup.id))
1607
1623
  }
1608
1624
  ),
1609
- /* @__PURE__ */ jsx(TableBody, { children: isLoading ? Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columnCount || 4 }).map((_2, colIndex) => /* @__PURE__ */ jsx(TableCell, { className: cellClasses, children: /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, colIndex)) }, `skeleton-${index}`)) : table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsx(
1625
+ /* @__PURE__ */ jsx(TableBody, { ref: tbodyRef, children: isLoading ? Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columnCount || 4 }).map((_2, colIndex) => /* @__PURE__ */ jsx(TableCell, { className: cellClasses, children: /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, colIndex)) }, `skeleton-${index}`)) : table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsx(
1610
1626
  TableRow,
1611
1627
  {
1612
1628
  "data-state": row.getIsSelected() && "selected",