@nexub/react 5.2.0 → 5.4.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.
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { useVirtualizer } from "@tanstack/react-virtual";
5
+ import { DataTable } from "../DataTable/DataTable.js";
6
+ const Options = React.createContext({ estimate: 49, overscan: 8, height: 600 });
7
+ const useVirtualRows = (count, getScrollElement) => {
8
+ const { estimate, overscan, height } = React.useContext(Options);
9
+ const virtualizer = useVirtualizer({
10
+ count,
11
+ getScrollElement,
12
+ estimateSize: () => estimate,
13
+ overscan,
14
+ // First render (and the server) assumes the full height, so rows show before measuring.
15
+ initialRect: { width: 0, height }
16
+ });
17
+ const items = virtualizer.getVirtualItems();
18
+ const last = items[items.length - 1];
19
+ return {
20
+ indexes: items.map((i) => i.index),
21
+ before: items[0]?.start ?? 0,
22
+ after: last ? virtualizer.getTotalSize() - last.end : 0,
23
+ measure: virtualizer.measureElement,
24
+ virtual: true
25
+ };
26
+ };
27
+ function DataTableVirtual({ estimateRowHeight, overscan = 8, ...props }) {
28
+ const compact = (props.density ?? props.defaultDensity) === "compact";
29
+ const estimate = estimateRowHeight ?? (compact ? 37 : 49);
30
+ const height = typeof props.maxHeight === "number" ? props.maxHeight : 600;
31
+ const options = React.useMemo(() => ({ estimate, overscan, height }), [estimate, overscan, height]);
32
+ return /* @__PURE__ */ jsx(Options.Provider, { value: options, children: /* @__PURE__ */ jsx(DataTable, { ...props, rowWindow: useVirtualRows }) });
33
+ }
34
+ DataTableVirtual.displayName = "DataTableVirtual";
35
+ export {
36
+ DataTableVirtual
37
+ };
@@ -0,0 +1,2 @@
1
+ export { DataTableVirtual } from './DataTableVirtual.js';
2
+ export type { DataTableVirtualProps } from './DataTableVirtual.js';
@@ -0,0 +1,4 @@
1
+ import { DataTableVirtual } from "./DataTableVirtual.js";
2
+ export {
3
+ DataTableVirtual
4
+ };
package/dist/index.d.ts CHANGED
@@ -200,7 +200,7 @@ export { CommandPalette } from './components/CommandPalette/index.js';
200
200
  export type { CommandPaletteRootProps } from './components/CommandPalette/index.js';
201
201
  export { Table } from './components/Table/index.js';
202
202
  export { DataTable } from './components/DataTable/index.js';
203
- export type { DataTableProps } from './components/DataTable/index.js';
203
+ export type { DataTableProps, DataTableDensity } from './components/DataTable/index.js';
204
204
  export { EmptyState } from './components/EmptyState/index.js';
205
205
  export { ErrorState } from './components/ErrorState/index.js';
206
206
  export type { ErrorStateProps } from './components/ErrorState/index.js';