@facter/ds-core 1.8.0 → 1.8.1

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
@@ -534,13 +534,7 @@ declare namespace DataTableRoot {
534
534
  var displayName: string;
535
535
  }
536
536
 
537
- /**
538
- * DataTable.Loading - Componente de loading state
539
- *
540
- * Renderiza um skeleton ou overlay quando visible=true.
541
- * Não renderiza nada quando visible=false.
542
- */
543
- declare function DataTableLoading({ visible, skeleton, skeletonRows, className, }: DataTableLoadingProps): react_jsx_runtime.JSX.Element | null;
537
+ declare function DataTableLoading({ visible, skeletonRows, }: DataTableLoadingProps): null;
544
538
  declare namespace DataTableLoading {
545
539
  var displayName: string;
546
540
  }
package/dist/index.d.ts CHANGED
@@ -534,13 +534,7 @@ declare namespace DataTableRoot {
534
534
  var displayName: string;
535
535
  }
536
536
 
537
- /**
538
- * DataTable.Loading - Componente de loading state
539
- *
540
- * Renderiza um skeleton ou overlay quando visible=true.
541
- * Não renderiza nada quando visible=false.
542
- */
543
- declare function DataTableLoading({ visible, skeleton, skeletonRows, className, }: DataTableLoadingProps): react_jsx_runtime.JSX.Element | null;
537
+ declare function DataTableLoading({ visible, skeletonRows, }: DataTableLoadingProps): null;
544
538
  declare namespace DataTableLoading {
545
539
  var displayName: string;
546
540
  }
package/dist/index.js CHANGED
@@ -1153,7 +1153,6 @@ function useDataTableInternal({
1153
1153
  pageIndex: 0,
1154
1154
  pageSize: 10
1155
1155
  });
1156
- console.log("[useDataTableInternal] pagination state", pagination);
1157
1156
  const table = reactTable.useReactTable({
1158
1157
  data,
1159
1158
  columns,
@@ -1207,6 +1206,7 @@ function useDataTableInternal({
1207
1206
  pageSize: pagination.pageSize
1208
1207
  };
1209
1208
  }
1209
+ var DataTableLoadingContext = React10__namespace.createContext(null);
1210
1210
  var DataTableEmptyStateConfigContext = React10__namespace.createContext(null);
1211
1211
  var DataTableInstanceContext = React10__namespace.createContext(null);
1212
1212
  DataTableInstanceContext.displayName = "DataTableInstanceContext";
@@ -1225,6 +1225,12 @@ function DataTableProvider({
1225
1225
  pageIndex,
1226
1226
  pageSize
1227
1227
  }) {
1228
+ const [isLoading, setIsLoading] = React10__namespace.useState(false);
1229
+ const [skeletonRows, setSkeletonRows] = React10__namespace.useState(5);
1230
+ const loadingValue = React10__namespace.useMemo(
1231
+ () => ({ isLoading, setIsLoading, skeletonRows, setSkeletonRows }),
1232
+ [isLoading, skeletonRows]
1233
+ );
1228
1234
  const [emptyStateConfig, setEmptyStateConfig] = React10__namespace.useState({});
1229
1235
  const emptyStateValue = React10__namespace.useMemo(
1230
1236
  () => ({ config: emptyStateConfig, setConfig: setEmptyStateConfig }),
@@ -1243,7 +1249,7 @@ function DataTableProvider({
1243
1249
  [pageIndex, pageSize]
1244
1250
  );
1245
1251
  const tableValue = table;
1246
- return /* @__PURE__ */ jsxRuntime.jsx(DataTableEmptyStateConfigContext.Provider, { value: emptyStateValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableInstanceContext.Provider, { value: tableValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableMetaContext.Provider, { value: metaValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableDensityContext.Provider, { value: densityValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTablePaginationContext.Provider, { value: paginationValue, children }) }) }) }) });
1252
+ return /* @__PURE__ */ jsxRuntime.jsx(DataTableLoadingContext.Provider, { value: loadingValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableEmptyStateConfigContext.Provider, { value: emptyStateValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableInstanceContext.Provider, { value: tableValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableMetaContext.Provider, { value: metaValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTableDensityContext.Provider, { value: densityValue, children: /* @__PURE__ */ jsxRuntime.jsx(DataTablePaginationContext.Provider, { value: paginationValue, children }) }) }) }) }) });
1247
1253
  }
1248
1254
  function useDataTable() {
1249
1255
  const context = React10__namespace.useContext(DataTableInstanceContext);
@@ -1341,6 +1347,15 @@ function useDataTableColumnVisibility() {
1341
1347
  getAllColumns: () => table.getAllColumns().filter((col) => col.getCanHide())
1342
1348
  }), [table, columnVisibility]);
1343
1349
  }
1350
+ function useDataTableLoadingState() {
1351
+ const context = React10__namespace.useContext(DataTableLoadingContext);
1352
+ if (!context) {
1353
+ throw new Error(
1354
+ "useDataTableLoadingState must be used within <DataTable>."
1355
+ );
1356
+ }
1357
+ return context;
1358
+ }
1344
1359
  function useDataTableEmptyStateConfig() {
1345
1360
  const context = React10__namespace.useContext(DataTableEmptyStateConfigContext);
1346
1361
  if (!context) {
@@ -1497,10 +1512,12 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1497
1512
  const { isEmpty } = useDataTableMeta();
1498
1513
  const { density } = useDataTableDensity();
1499
1514
  const { config: emptyStateConfig } = useDataTableEmptyStateConfig();
1515
+ const { isLoading, skeletonRows } = useDataTableLoadingState();
1500
1516
  const densityStyles = DENSITY_CONFIG[density];
1501
1517
  const cellClasses = cn(densityStyles.padding, densityStyles.fontSize);
1518
+ const columnCount = table.getVisibleLeafColumns().length;
1502
1519
  const hasRows = table.getRowModel().rows?.length > 0;
1503
- if (!hasRows && isEmpty) {
1520
+ if (!hasRows && isEmpty && !isLoading) {
1504
1521
  return /* @__PURE__ */ jsxRuntime.jsx(
1505
1522
  EmptyState,
1506
1523
  {
@@ -1524,7 +1541,7 @@ var DataTableContent = React10__namespace.memo(function DataTableContent2({
1524
1541
  },
1525
1542
  header.id
1526
1543
  )) }, headerGroup.id)) }),
1527
- /* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsxRuntime.jsx(
1544
+ /* @__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(
1528
1545
  TableRow,
1529
1546
  {
1530
1547
  "data-state": row.getIsSelected() && "selected",
@@ -1809,24 +1826,19 @@ var DataTableEmptyState = React10__namespace.memo(function DataTableEmptyState2(
1809
1826
  return null;
1810
1827
  });
1811
1828
  DataTableEmptyState.displayName = "DataTable.EmptyState";
1812
- function SkeletonRow({ columns }) {
1813
- return /* @__PURE__ */ jsxRuntime.jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columns }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { className: "py-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, index)) });
1814
- }
1815
1829
  function DataTableLoading({
1816
1830
  visible,
1817
- skeleton,
1818
- skeletonRows = 5,
1819
- className
1831
+ skeletonRows = 5
1820
1832
  }) {
1821
- const table = useDataTable();
1822
- const columnCount = table.getVisibleLeafColumns().length;
1823
- if (!visible) {
1824
- return null;
1825
- }
1826
- if (skeleton) {
1827
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("w-full", className), children: skeleton });
1828
- }
1829
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("w-full", className), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonRow, { columns: columnCount || 4 }, index)) }) }) }) });
1833
+ const { setIsLoading, setSkeletonRows } = useDataTableLoadingState();
1834
+ React10__namespace.useLayoutEffect(() => {
1835
+ setIsLoading(visible);
1836
+ return () => setIsLoading(false);
1837
+ }, [visible, setIsLoading]);
1838
+ React10__namespace.useLayoutEffect(() => {
1839
+ setSkeletonRows(skeletonRows);
1840
+ }, [skeletonRows, setSkeletonRows]);
1841
+ return null;
1830
1842
  }
1831
1843
  DataTableLoading.displayName = "DataTable.Loading";
1832
1844
  function DataTableColumnHeader({