@facter/ds-core 1.22.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.d.mts CHANGED
@@ -304,6 +304,8 @@ interface DataTableProps<TData extends object> {
304
304
  * Quando true, a tabela não faz paginação local e depende do servidor.
305
305
  */
306
306
  manualPagination?: boolean;
307
+ /** Número inicial de items por página (default: 10) */
308
+ initialPageSize?: number;
307
309
  /**
308
310
  * Total de páginas (obrigatório se manualPagination=true).
309
311
  * Usado para calcular navegação quando dados vêm do servidor.
@@ -396,11 +398,15 @@ interface DataTableContentProps {
396
398
  /**
397
399
  * Habilita scroll vertical com altura calculada automaticamente.
398
400
  * O header das colunas fica sticky e apenas as rows fazem scroll.
399
- * O bottomOffset controla a margem inferior (default: 16px).
400
401
  */
401
402
  scrollable?: boolean;
402
- /** Margem inferior em px para o cálculo de altura automática (default: 16) */
403
+ /** Margem inferior em px para o cálculo de altura automática (default: 68) */
403
404
  scrollBottomOffset?: number;
405
+ /**
406
+ * Calcula automaticamente o número de rows por página baseado na altura disponível.
407
+ * Mede do início do tbody até o final do viewport, descontando pagination e margem.
408
+ */
409
+ autoPageSize?: boolean;
404
410
  /** Custom className */
405
411
  className?: string;
406
412
  }
@@ -541,7 +547,7 @@ declare const DENSITY_CONFIG: {
541
547
  };
542
548
  };
543
549
 
544
- declare function DataTableRoot<TData extends object>({ children, data, columns, getRowId, manualPagination, pageCount, className, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
550
+ declare function DataTableRoot<TData extends object>({ children, data, columns, getRowId, manualPagination, pageCount, initialPageSize, className, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
545
551
  declare namespace DataTableRoot {
546
552
  var displayName: string;
547
553
  }
@@ -2716,15 +2722,11 @@ declare function useAvailableHeight<T extends HTMLElement = HTMLDivElement>(opti
2716
2722
  };
2717
2723
 
2718
2724
  interface UseAutoPageSizeOptions {
2719
- /** Height of each row in pixels (default: 49 — default density + border) */
2725
+ /** Height of each row in pixels (default: 49) */
2720
2726
  rowHeight?: number;
2721
- /** Height of the column header in pixels (default: 41) */
2722
- headerHeight?: number;
2723
- /** Height of the pagination bar in pixels (default: 52) */
2724
- paginationHeight?: number;
2725
- /** Extra bottom offset in pixels (default: 16) */
2727
+ /** Extra offset below the table in pixels — pagination, margins, etc (default: 64) */
2726
2728
  bottomOffset?: number;
2727
- /** Minimum rows per page (default: 5) */
2729
+ /** Minimum rows per page (default: 3) */
2728
2730
  minRows?: number;
2729
2731
  /** Maximum rows per page (default: 50) */
2730
2732
  maxRows?: number;
@@ -2735,22 +2737,11 @@ interface UseAutoPageSizeOptions {
2735
2737
  * Hook that calculates the optimal number of rows per page
2736
2738
  * based on the available viewport height.
2737
2739
  *
2738
- * Returns the calculated perPage as default. If the user manually
2739
- * changes the page size, respects their choice.
2740
+ * The ref should point to the element where rows START (e.g. tbody container).
2741
+ * The hook measures from ref.top to viewport bottom, subtracts bottomOffset,
2742
+ * and divides by rowHeight.
2740
2743
  *
2741
- * @example
2742
- * ```tsx
2743
- * function MyTable() {
2744
- * const { ref, perPage, setPerPage } = useAutoPageSize()
2745
- * return (
2746
- * <div ref={ref}>
2747
- * <DataTable data={data} columns={columns}>
2748
- * <DataTable.Pagination onPageSizeChange={setPerPage} />
2749
- * </DataTable>
2750
- * </div>
2751
- * )
2752
- * }
2753
- * ```
2744
+ * If the user manually changes page size, their choice is respected.
2754
2745
  */
2755
2746
  declare function useAutoPageSize<T extends HTMLElement = HTMLDivElement>(options?: UseAutoPageSizeOptions): {
2756
2747
  ref: React$1.RefObject<T | null>;
@@ -2758,7 +2749,6 @@ declare function useAutoPageSize<T extends HTMLElement = HTMLDivElement>(options
2758
2749
  setPerPage: (size: number) => void;
2759
2750
  autoPerPage: number;
2760
2751
  isAutoSized: boolean;
2761
- isReady: boolean;
2762
2752
  };
2763
2753
 
2764
2754
  type Theme = 'dark' | 'light' | 'system';
package/dist/index.d.ts CHANGED
@@ -304,6 +304,8 @@ interface DataTableProps<TData extends object> {
304
304
  * Quando true, a tabela não faz paginação local e depende do servidor.
305
305
  */
306
306
  manualPagination?: boolean;
307
+ /** Número inicial de items por página (default: 10) */
308
+ initialPageSize?: number;
307
309
  /**
308
310
  * Total de páginas (obrigatório se manualPagination=true).
309
311
  * Usado para calcular navegação quando dados vêm do servidor.
@@ -396,11 +398,15 @@ interface DataTableContentProps {
396
398
  /**
397
399
  * Habilita scroll vertical com altura calculada automaticamente.
398
400
  * O header das colunas fica sticky e apenas as rows fazem scroll.
399
- * O bottomOffset controla a margem inferior (default: 16px).
400
401
  */
401
402
  scrollable?: boolean;
402
- /** Margem inferior em px para o cálculo de altura automática (default: 16) */
403
+ /** Margem inferior em px para o cálculo de altura automática (default: 68) */
403
404
  scrollBottomOffset?: number;
405
+ /**
406
+ * Calcula automaticamente o número de rows por página baseado na altura disponível.
407
+ * Mede do início do tbody até o final do viewport, descontando pagination e margem.
408
+ */
409
+ autoPageSize?: boolean;
404
410
  /** Custom className */
405
411
  className?: string;
406
412
  }
@@ -541,7 +547,7 @@ declare const DENSITY_CONFIG: {
541
547
  };
542
548
  };
543
549
 
544
- declare function DataTableRoot<TData extends object>({ children, data, columns, getRowId, manualPagination, pageCount, className, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
550
+ declare function DataTableRoot<TData extends object>({ children, data, columns, getRowId, manualPagination, pageCount, initialPageSize, className, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
545
551
  declare namespace DataTableRoot {
546
552
  var displayName: string;
547
553
  }
@@ -2716,15 +2722,11 @@ declare function useAvailableHeight<T extends HTMLElement = HTMLDivElement>(opti
2716
2722
  };
2717
2723
 
2718
2724
  interface UseAutoPageSizeOptions {
2719
- /** Height of each row in pixels (default: 49 — default density + border) */
2725
+ /** Height of each row in pixels (default: 49) */
2720
2726
  rowHeight?: number;
2721
- /** Height of the column header in pixels (default: 41) */
2722
- headerHeight?: number;
2723
- /** Height of the pagination bar in pixels (default: 52) */
2724
- paginationHeight?: number;
2725
- /** Extra bottom offset in pixels (default: 16) */
2727
+ /** Extra offset below the table in pixels — pagination, margins, etc (default: 64) */
2726
2728
  bottomOffset?: number;
2727
- /** Minimum rows per page (default: 5) */
2729
+ /** Minimum rows per page (default: 3) */
2728
2730
  minRows?: number;
2729
2731
  /** Maximum rows per page (default: 50) */
2730
2732
  maxRows?: number;
@@ -2735,22 +2737,11 @@ interface UseAutoPageSizeOptions {
2735
2737
  * Hook that calculates the optimal number of rows per page
2736
2738
  * based on the available viewport height.
2737
2739
  *
2738
- * Returns the calculated perPage as default. If the user manually
2739
- * changes the page size, respects their choice.
2740
+ * The ref should point to the element where rows START (e.g. tbody container).
2741
+ * The hook measures from ref.top to viewport bottom, subtracts bottomOffset,
2742
+ * and divides by rowHeight.
2740
2743
  *
2741
- * @example
2742
- * ```tsx
2743
- * function MyTable() {
2744
- * const { ref, perPage, setPerPage } = useAutoPageSize()
2745
- * return (
2746
- * <div ref={ref}>
2747
- * <DataTable data={data} columns={columns}>
2748
- * <DataTable.Pagination onPageSizeChange={setPerPage} />
2749
- * </DataTable>
2750
- * </div>
2751
- * )
2752
- * }
2753
- * ```
2744
+ * If the user manually changes page size, their choice is respected.
2754
2745
  */
2755
2746
  declare function useAutoPageSize<T extends HTMLElement = HTMLDivElement>(options?: UseAutoPageSizeOptions): {
2756
2747
  ref: React$1.RefObject<T | null>;
@@ -2758,7 +2749,6 @@ declare function useAutoPageSize<T extends HTMLElement = HTMLDivElement>(options
2758
2749
  setPerPage: (size: number) => void;
2759
2750
  autoPerPage: number;
2760
2751
  isAutoSized: boolean;
2761
- isReady: boolean;
2762
2752
  };
2763
2753
 
2764
2754
  type Theme = 'dark' | 'light' | 'system';
package/dist/index.js CHANGED
@@ -1141,7 +1141,8 @@ function useDataTableInternal({
1141
1141
  columns,
1142
1142
  getRowId,
1143
1143
  manualPagination = false,
1144
- pageCount: externalPageCount
1144
+ pageCount: externalPageCount,
1145
+ initialPageSize = 10
1145
1146
  }) {
1146
1147
  const [rowSelection, setRowSelection] = React10__namespace.useState({});
1147
1148
  const [columnVisibility, setColumnVisibility] = React10__namespace.useState({});
@@ -1151,7 +1152,7 @@ function useDataTableInternal({
1151
1152
  const [density, setDensity] = React10__namespace.useState("default");
1152
1153
  const [pagination, setPagination] = React10__namespace.useState({
1153
1154
  pageIndex: 0,
1154
- pageSize: 10
1155
+ pageSize: initialPageSize
1155
1156
  });
1156
1157
  const table = reactTable.useReactTable({
1157
1158
  data,
@@ -1374,6 +1375,7 @@ function DataTableRoot({
1374
1375
  getRowId,
1375
1376
  manualPagination,
1376
1377
  pageCount,
1378
+ initialPageSize,
1377
1379
  className
1378
1380
  }) {
1379
1381
  const { table, meta, density, setDensity, pageIndex, pageSize } = useDataTableInternal({
@@ -1381,7 +1383,8 @@ function DataTableRoot({
1381
1383
  columns,
1382
1384
  getRowId,
1383
1385
  manualPagination,
1384
- pageCount
1386
+ pageCount,
1387
+ initialPageSize
1385
1388
  });
1386
1389
  return /* @__PURE__ */ jsxRuntime.jsx(
1387
1390
  DataTableProvider,
@@ -1452,27 +1455,23 @@ function useAvailableHeight(options = {}) {
1452
1455
  function useAutoPageSize(options = {}) {
1453
1456
  const {
1454
1457
  rowHeight = 49,
1455
- headerHeight = 41,
1456
- paginationHeight = 52,
1457
- bottomOffset = 16,
1458
- minRows = 5,
1458
+ bottomOffset = 64,
1459
+ minRows = 3,
1459
1460
  maxRows = 50,
1460
1461
  enabled = true
1461
1462
  } = options;
1462
1463
  const ref = React10.useRef(null);
1463
1464
  const [autoPerPage, setAutoPerPage] = React10.useState(minRows);
1464
1465
  const [userOverride, setUserOverride] = React10.useState(null);
1465
- const hasCalculated = React10.useRef(false);
1466
1466
  const calculate = React10.useCallback(() => {
1467
1467
  const el = ref.current;
1468
1468
  if (!el || !enabled) return;
1469
1469
  const rect = el.getBoundingClientRect();
1470
- const availableHeight = window.innerHeight - rect.top - headerHeight - paginationHeight - bottomOffset;
1470
+ const availableHeight = window.innerHeight - rect.top - bottomOffset;
1471
1471
  const rows = Math.floor(availableHeight / rowHeight);
1472
1472
  const clamped = Math.max(minRows, Math.min(maxRows, rows));
1473
1473
  setAutoPerPage(clamped);
1474
- hasCalculated.current = true;
1475
- }, [rowHeight, headerHeight, paginationHeight, bottomOffset, minRows, maxRows, enabled]);
1474
+ }, [rowHeight, bottomOffset, minRows, maxRows, enabled]);
1476
1475
  React10.useEffect(() => {
1477
1476
  if (!enabled) return;
1478
1477
  const frame = requestAnimationFrame(calculate);
@@ -1485,14 +1484,12 @@ function useAutoPageSize(options = {}) {
1485
1484
  const setPerPage = React10.useCallback((size) => {
1486
1485
  setUserOverride(size);
1487
1486
  }, []);
1488
- const perPage = userOverride ?? autoPerPage;
1489
1487
  return {
1490
1488
  ref,
1491
- perPage,
1489
+ perPage: userOverride ?? autoPerPage,
1492
1490
  setPerPage,
1493
1491
  autoPerPage,
1494
- isAutoSized: userOverride === null,
1495
- isReady: hasCalculated.current
1492
+ isAutoSized: userOverride === null
1496
1493
  };
1497
1494
  }
1498
1495
  var Table = React10__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -1580,6 +1577,7 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1580
1577
  onRowClick,
1581
1578
  scrollable = false,
1582
1579
  scrollBottomOffset = 68,
1580
+ autoPageSize = false,
1583
1581
  className
1584
1582
  }) {
1585
1583
  const table = useDataTable();
@@ -1587,15 +1585,36 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1587
1585
  const { density } = useDataTableDensity();
1588
1586
  const { config: emptyStateConfig } = useDataTableEmptyStateConfig();
1589
1587
  const { isLoading, skeletonRows } = useDataTableLoadingState();
1590
- const { ref, style: scrollStyle } = useAvailableHeight({
1588
+ const { setPageSize } = useDataTablePagination();
1589
+ const tbodyRef = React10__namespace.useRef(null);
1590
+ const { ref: scrollRef, style: scrollStyle } = useAvailableHeight({
1591
1591
  bottomOffset: scrollBottomOffset,
1592
1592
  enabled: scrollable
1593
1593
  });
1594
1594
  const densityStyles = DENSITY_CONFIG[density];
1595
+ const rowHeight = densityStyles.rowHeight + 1;
1595
1596
  const cellClasses = cn(densityStyles.padding, densityStyles.fontSize);
1596
1597
  const columnCount = table.getVisibleLeafColumns().length;
1597
1598
  const hasRows = table.getRowModel().rows?.length > 0;
1598
1599
  const effectiveStickyHeader = stickyHeader || scrollable;
1600
+ React10__namespace.useEffect(() => {
1601
+ if (!autoPageSize) return;
1602
+ const calculate = () => {
1603
+ const tbody = tbodyRef.current;
1604
+ if (!tbody) return;
1605
+ const rect = tbody.getBoundingClientRect();
1606
+ const available = window.innerHeight - rect.top - 68;
1607
+ const rows = Math.floor(available / rowHeight);
1608
+ const clamped = Math.max(3, Math.min(50, rows));
1609
+ setPageSize(clamped);
1610
+ };
1611
+ const frame = requestAnimationFrame(calculate);
1612
+ window.addEventListener("resize", calculate);
1613
+ return () => {
1614
+ cancelAnimationFrame(frame);
1615
+ window.removeEventListener("resize", calculate);
1616
+ };
1617
+ }, [autoPageSize, rowHeight, setPageSize]);
1599
1618
  if (!hasRows && isEmpty && !isLoading) {
1600
1619
  return /* @__PURE__ */ jsxRuntime.jsx(
1601
1620
  EmptyState,
@@ -1610,7 +1629,7 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1610
1629
  return /* @__PURE__ */ jsxRuntime.jsx(
1611
1630
  "div",
1612
1631
  {
1613
- ref,
1632
+ ref: scrollRef,
1614
1633
  className: cn("rounded-md overflow-auto bg-card", className),
1615
1634
  style: scrollStyle,
1616
1635
  children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { children: [
@@ -1634,7 +1653,7 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1634
1653
  )) }, headerGroup.id))
1635
1654
  }
1636
1655
  ),
1637
- /* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: isLoading ? Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columnCount || 4 }).map((_2, colIndex) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: cellClasses, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, colIndex)) }, `skeleton-${index}`)) : table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsxRuntime.jsx(
1656
+ /* @__PURE__ */ jsxRuntime.jsx(TableBody, { ref: tbodyRef, children: isLoading ? Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columnCount || 4 }).map((_2, colIndex) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: cellClasses, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, colIndex)) }, `skeleton-${index}`)) : table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsxRuntime.jsx(
1638
1657
  TableRow,
1639
1658
  {
1640
1659
  "data-state": row.getIsSelected() && "selected",
@@ -1814,7 +1833,6 @@ var DataTablePagination = React10__namespace.memo(function DataTablePagination2(
1814
1833
  firstPage,
1815
1834
  lastPage
1816
1835
  } = paginationHook;
1817
- console.log("[DataTablePagination] render", { mode, pageIndex, pageSize, externalPageCount, internalPageCount });
1818
1836
  const pageCount = mode === "server" && externalPageCount !== void 0 ? externalPageCount : internalPageCount;
1819
1837
  const canGoPrevious = pageIndex > 0;
1820
1838
  const canGoNext = pageIndex < pageCount - 1;
@@ -1892,11 +1910,7 @@ var DataTablePagination = React10__namespace.memo(function DataTablePagination2(
1892
1910
  variant: "outline",
1893
1911
  size: "icon-sm",
1894
1912
  className: "h-8 w-8 p-0",
1895
- onClick: () => {
1896
- console.log("[DataTablePagination] nextPage clicked, current pageIndex:", pageIndex);
1897
- nextPage();
1898
- console.log("[DataTablePagination] nextPage called");
1899
- },
1913
+ onClick: nextPage,
1900
1914
  disabled: !canGoNext,
1901
1915
  "aria-label": "Pr\xF3xima p\xE1gina",
1902
1916
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "h-4 w-4" })