@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.mjs CHANGED
@@ -1122,7 +1122,6 @@ function useDataTableInternal({
1122
1122
  pageIndex: 0,
1123
1123
  pageSize: 10
1124
1124
  });
1125
- console.log("[useDataTableInternal] pagination state", pagination);
1126
1125
  const table = useReactTable({
1127
1126
  data,
1128
1127
  columns,
@@ -1176,6 +1175,7 @@ function useDataTableInternal({
1176
1175
  pageSize: pagination.pageSize
1177
1176
  };
1178
1177
  }
1178
+ var DataTableLoadingContext = React10.createContext(null);
1179
1179
  var DataTableEmptyStateConfigContext = React10.createContext(null);
1180
1180
  var DataTableInstanceContext = React10.createContext(null);
1181
1181
  DataTableInstanceContext.displayName = "DataTableInstanceContext";
@@ -1194,6 +1194,12 @@ function DataTableProvider({
1194
1194
  pageIndex,
1195
1195
  pageSize
1196
1196
  }) {
1197
+ const [isLoading, setIsLoading] = React10.useState(false);
1198
+ const [skeletonRows, setSkeletonRows] = React10.useState(5);
1199
+ const loadingValue = React10.useMemo(
1200
+ () => ({ isLoading, setIsLoading, skeletonRows, setSkeletonRows }),
1201
+ [isLoading, skeletonRows]
1202
+ );
1197
1203
  const [emptyStateConfig, setEmptyStateConfig] = React10.useState({});
1198
1204
  const emptyStateValue = React10.useMemo(
1199
1205
  () => ({ config: emptyStateConfig, setConfig: setEmptyStateConfig }),
@@ -1212,7 +1218,7 @@ function DataTableProvider({
1212
1218
  [pageIndex, pageSize]
1213
1219
  );
1214
1220
  const tableValue = table;
1215
- return /* @__PURE__ */ jsx(DataTableEmptyStateConfigContext.Provider, { value: emptyStateValue, children: /* @__PURE__ */ jsx(DataTableInstanceContext.Provider, { value: tableValue, children: /* @__PURE__ */ jsx(DataTableMetaContext.Provider, { value: metaValue, children: /* @__PURE__ */ jsx(DataTableDensityContext.Provider, { value: densityValue, children: /* @__PURE__ */ jsx(DataTablePaginationContext.Provider, { value: paginationValue, children }) }) }) }) });
1221
+ return /* @__PURE__ */ jsx(DataTableLoadingContext.Provider, { value: loadingValue, children: /* @__PURE__ */ jsx(DataTableEmptyStateConfigContext.Provider, { value: emptyStateValue, children: /* @__PURE__ */ jsx(DataTableInstanceContext.Provider, { value: tableValue, children: /* @__PURE__ */ jsx(DataTableMetaContext.Provider, { value: metaValue, children: /* @__PURE__ */ jsx(DataTableDensityContext.Provider, { value: densityValue, children: /* @__PURE__ */ jsx(DataTablePaginationContext.Provider, { value: paginationValue, children }) }) }) }) }) });
1216
1222
  }
1217
1223
  function useDataTable() {
1218
1224
  const context = React10.useContext(DataTableInstanceContext);
@@ -1310,6 +1316,15 @@ function useDataTableColumnVisibility() {
1310
1316
  getAllColumns: () => table.getAllColumns().filter((col) => col.getCanHide())
1311
1317
  }), [table, columnVisibility]);
1312
1318
  }
1319
+ function useDataTableLoadingState() {
1320
+ const context = React10.useContext(DataTableLoadingContext);
1321
+ if (!context) {
1322
+ throw new Error(
1323
+ "useDataTableLoadingState must be used within <DataTable>."
1324
+ );
1325
+ }
1326
+ return context;
1327
+ }
1313
1328
  function useDataTableEmptyStateConfig() {
1314
1329
  const context = React10.useContext(DataTableEmptyStateConfigContext);
1315
1330
  if (!context) {
@@ -1466,10 +1481,12 @@ var DataTableContent = React10.memo(function DataTableContent2({
1466
1481
  const { isEmpty } = useDataTableMeta();
1467
1482
  const { density } = useDataTableDensity();
1468
1483
  const { config: emptyStateConfig } = useDataTableEmptyStateConfig();
1484
+ const { isLoading, skeletonRows } = useDataTableLoadingState();
1469
1485
  const densityStyles = DENSITY_CONFIG[density];
1470
1486
  const cellClasses = cn(densityStyles.padding, densityStyles.fontSize);
1487
+ const columnCount = table.getVisibleLeafColumns().length;
1471
1488
  const hasRows = table.getRowModel().rows?.length > 0;
1472
- if (!hasRows && isEmpty) {
1489
+ if (!hasRows && isEmpty && !isLoading) {
1473
1490
  return /* @__PURE__ */ jsx(
1474
1491
  EmptyState,
1475
1492
  {
@@ -1493,7 +1510,7 @@ var DataTableContent = React10.memo(function DataTableContent2({
1493
1510
  },
1494
1511
  header.id
1495
1512
  )) }, headerGroup.id)) }),
1496
- /* @__PURE__ */ jsx(TableBody, { children: table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsx(
1513
+ /* @__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(
1497
1514
  TableRow,
1498
1515
  {
1499
1516
  "data-state": row.getIsSelected() && "selected",
@@ -1778,24 +1795,19 @@ var DataTableEmptyState = React10.memo(function DataTableEmptyState2({
1778
1795
  return null;
1779
1796
  });
1780
1797
  DataTableEmptyState.displayName = "DataTable.EmptyState";
1781
- function SkeletonRow({ columns }) {
1782
- return /* @__PURE__ */ jsx(TableRow, { className: "animate-pulse", children: Array.from({ length: columns }).map((_, index) => /* @__PURE__ */ jsx(TableCell, { className: "py-4", children: /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-3/4" }) }, index)) });
1783
- }
1784
1798
  function DataTableLoading({
1785
1799
  visible,
1786
- skeleton,
1787
- skeletonRows = 5,
1788
- className
1800
+ skeletonRows = 5
1789
1801
  }) {
1790
- const table = useDataTable();
1791
- const columnCount = table.getVisibleLeafColumns().length;
1792
- if (!visible) {
1793
- return null;
1794
- }
1795
- if (skeleton) {
1796
- return /* @__PURE__ */ jsx("div", { className: cn("w-full", className), children: skeleton });
1797
- }
1798
- return /* @__PURE__ */ jsx("div", { className: cn("w-full", className), children: /* @__PURE__ */ jsx("div", { className: "rounded-md border", children: /* @__PURE__ */ jsx("table", { className: "w-full", children: /* @__PURE__ */ jsx("tbody", { children: Array.from({ length: skeletonRows }).map((_, index) => /* @__PURE__ */ jsx(SkeletonRow, { columns: columnCount || 4 }, index)) }) }) }) });
1802
+ const { setIsLoading, setSkeletonRows } = useDataTableLoadingState();
1803
+ React10.useLayoutEffect(() => {
1804
+ setIsLoading(visible);
1805
+ return () => setIsLoading(false);
1806
+ }, [visible, setIsLoading]);
1807
+ React10.useLayoutEffect(() => {
1808
+ setSkeletonRows(skeletonRows);
1809
+ }, [skeletonRows, setSkeletonRows]);
1810
+ return null;
1799
1811
  }
1800
1812
  DataTableLoading.displayName = "DataTable.Loading";
1801
1813
  function DataTableColumnHeader({