@versini/ui-datagrid 0.1.0 → 0.1.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/README.md +3 -43
- package/dist/DataGrid/DataGrid.js +29 -35
- package/dist/DataGrid/DataGridContext.js +1 -1
- package/dist/DataGrid/index.js +1 -1
- package/dist/DataGrid/utilities.d.ts +11 -3
- package/dist/DataGrid/utilities.js +32 -12
- package/dist/DataGridAnimated/AnimatedWrapper.js +1 -1
- package/dist/DataGridAnimated/index.js +1 -1
- package/dist/DataGridAnimated/useAnimatedHeight.js +1 -1
- package/dist/DataGridBody/DataGridBody.js +8 -3
- package/dist/DataGridBody/index.js +1 -1
- package/dist/DataGridCell/DataGridCell.d.ts +2 -5
- package/dist/DataGridCell/DataGridCell.js +27 -18
- package/dist/DataGridCell/index.js +1 -1
- package/dist/DataGridCellSort/DataGridCellSort.d.ts +1 -1
- package/dist/DataGridCellSort/DataGridCellSort.js +16 -11
- package/dist/DataGridCellSort/index.js +1 -1
- package/dist/DataGridConstants/DataGridConstants.js +1 -1
- package/dist/DataGridConstants/index.js +1 -1
- package/dist/DataGridFooter/DataGridFooter.js +4 -3
- package/dist/DataGridFooter/index.js +1 -1
- package/dist/DataGridHeader/DataGridHeader.d.ts +2 -1
- package/dist/DataGridHeader/DataGridHeader.js +18 -28
- package/dist/DataGridHeader/index.js +1 -1
- package/dist/DataGridInfinite/InfiniteScrollMarker.d.ts +2 -6
- package/dist/DataGridInfinite/InfiniteScrollMarker.js +7 -6
- package/dist/DataGridInfinite/index.js +1 -1
- package/dist/DataGridInfinite/useInfiniteScroll.d.ts +12 -1
- package/dist/DataGridInfinite/useInfiniteScroll.js +23 -4
- package/dist/DataGridRow/DataGridRow.js +23 -8
- package/dist/DataGridRow/index.js +1 -1
- package/dist/DataGridSorting/index.js +1 -1
- package/dist/DataGridSorting/sortingUtils.js +1 -1
- package/package.json +2 -7
- package/dist/DataGridVirtual/VirtualDataGrid.d.ts +0 -114
- package/dist/DataGridVirtual/VirtualDataGrid.js +0 -181
- package/dist/DataGridVirtual/index.d.ts +0 -6
- package/dist/DataGridVirtual/index.js +0 -22
- package/dist/DataGridVirtual/useVirtualDataGrid.d.ts +0 -112
- package/dist/DataGridVirtual/useVirtualDataGrid.js +0 -89
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
@versini/ui-datagrid v0.1.0
|
|
3
|
-
© 2026 gizmette.com
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import clsx from "clsx";
|
|
8
|
-
import { useCallback, useMemo } from "react";
|
|
9
|
-
import { DataGridContext } from "../DataGrid/DataGridContext.js";
|
|
10
|
-
import { getDataGridClasses } from "../DataGrid/utilities.js";
|
|
11
|
-
import { BlurEffects } from "../DataGridConstants/DataGridConstants.js";
|
|
12
|
-
import { getHeaderClasses } from "../DataGridHeader/DataGridHeader.js";
|
|
13
|
-
import { useVirtualDataGrid } from "./useVirtualDataGrid.js";
|
|
14
|
-
|
|
15
|
-
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
16
|
-
|
|
17
|
-
;// CONCATENATED MODULE: external "clsx"
|
|
18
|
-
|
|
19
|
-
;// CONCATENATED MODULE: external "react"
|
|
20
|
-
|
|
21
|
-
;// CONCATENATED MODULE: external "../DataGrid/DataGridContext.js"
|
|
22
|
-
|
|
23
|
-
;// CONCATENATED MODULE: external "../DataGrid/utilities.js"
|
|
24
|
-
|
|
25
|
-
;// CONCATENATED MODULE: external "../DataGridConstants/DataGridConstants.js"
|
|
26
|
-
|
|
27
|
-
;// CONCATENATED MODULE: external "../DataGridHeader/DataGridHeader.js"
|
|
28
|
-
|
|
29
|
-
;// CONCATENATED MODULE: external "./useVirtualDataGrid.js"
|
|
30
|
-
|
|
31
|
-
;// CONCATENATED MODULE: ./src/DataGridVirtual/VirtualDataGrid.tsx
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A virtualized data grid component for rendering large datasets.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```tsx
|
|
45
|
-
* <VirtualDataGrid
|
|
46
|
-
* data={items}
|
|
47
|
-
* height="500px"
|
|
48
|
-
* columns={[
|
|
49
|
-
* { id: 'name', header: 'Name', cell: (item) => item.name },
|
|
50
|
-
* { id: 'date', header: 'Date', cell: (item) => formatDate(item.date) },
|
|
51
|
-
* ]}
|
|
52
|
-
* getRowKey={(item) => item.id}
|
|
53
|
-
* />
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
*/ function VirtualDataGrid({ data, columns, height, mode = "system", compact = false, stickyHeader = true, blurEffect = BlurEffects.NONE, caption, wrapperClassName, className, getRowKey, onRowClick, activeRowIndex, estimateSize = 40, overscan = 5, useFlushSync = true }) {
|
|
57
|
-
// Memoize the getItemKey function to prevent infinite re-renders.
|
|
58
|
-
const getItemKey = useCallback((index)=>getRowKey ? getRowKey(data[index], index) : index, [
|
|
59
|
-
getRowKey,
|
|
60
|
-
data
|
|
61
|
-
]);
|
|
62
|
-
const { scrollContainerRef, totalSize, virtualItems, measureElement } = useVirtualDataGrid({
|
|
63
|
-
data,
|
|
64
|
-
estimateSize,
|
|
65
|
-
overscan,
|
|
66
|
-
getItemKey,
|
|
67
|
-
useFlushSync
|
|
68
|
-
});
|
|
69
|
-
const classes = useMemo(()=>getDataGridClasses({
|
|
70
|
-
mode,
|
|
71
|
-
className,
|
|
72
|
-
wrapperClassName,
|
|
73
|
-
stickyHeader,
|
|
74
|
-
stickyFooter: false,
|
|
75
|
-
disabled: false
|
|
76
|
-
}), [
|
|
77
|
-
mode,
|
|
78
|
-
className,
|
|
79
|
-
wrapperClassName,
|
|
80
|
-
stickyHeader
|
|
81
|
-
]);
|
|
82
|
-
const headerClasses = useMemo(()=>getHeaderClasses({
|
|
83
|
-
stickyHeader,
|
|
84
|
-
mode,
|
|
85
|
-
blurEffect
|
|
86
|
-
}), [
|
|
87
|
-
stickyHeader,
|
|
88
|
-
mode,
|
|
89
|
-
blurEffect
|
|
90
|
-
]);
|
|
91
|
-
const contextValue = useMemo(()=>({
|
|
92
|
-
mode,
|
|
93
|
-
compact
|
|
94
|
-
}), [
|
|
95
|
-
mode,
|
|
96
|
-
compact
|
|
97
|
-
]);
|
|
98
|
-
const containerStyle = useMemo(()=>({
|
|
99
|
-
height: typeof height === "number" ? `${height}px` : height,
|
|
100
|
-
overflow: "auto"
|
|
101
|
-
}), [
|
|
102
|
-
height
|
|
103
|
-
]);
|
|
104
|
-
/**
|
|
105
|
-
* The tbody needs relative positioning for absolute row children and a height
|
|
106
|
-
* equal to the total virtualized size.
|
|
107
|
-
*/ const tbodyStyle = useMemo(()=>({
|
|
108
|
-
display: "block",
|
|
109
|
-
height: `${totalSize}px`,
|
|
110
|
-
position: "relative"
|
|
111
|
-
}), [
|
|
112
|
-
totalSize
|
|
113
|
-
]);
|
|
114
|
-
// Header row needs to be display: table to maintain column widths.
|
|
115
|
-
const theadStyle = useMemo(()=>({
|
|
116
|
-
display: "table",
|
|
117
|
-
width: "100%",
|
|
118
|
-
tableLayout: "fixed"
|
|
119
|
-
}), []);
|
|
120
|
-
return /*#__PURE__*/ jsx(DataGridContext.Provider, {
|
|
121
|
-
value: contextValue,
|
|
122
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
123
|
-
className: classes.wrapper,
|
|
124
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
125
|
-
ref: scrollContainerRef,
|
|
126
|
-
style: containerStyle,
|
|
127
|
-
children: /*#__PURE__*/ jsxs("table", {
|
|
128
|
-
className: classes.table,
|
|
129
|
-
"aria-label": caption,
|
|
130
|
-
children: [
|
|
131
|
-
caption && /*#__PURE__*/ jsx("caption", {
|
|
132
|
-
className: classes.caption,
|
|
133
|
-
children: caption
|
|
134
|
-
}),
|
|
135
|
-
/*#__PURE__*/ jsx("thead", {
|
|
136
|
-
className: headerClasses,
|
|
137
|
-
style: theadStyle,
|
|
138
|
-
children: /*#__PURE__*/ jsx("tr", {
|
|
139
|
-
children: columns.map((column)=>/*#__PURE__*/ jsx("th", {
|
|
140
|
-
style: {
|
|
141
|
-
width: column.width
|
|
142
|
-
},
|
|
143
|
-
className: clsx("px-4 py-3 font-semibold", column.className),
|
|
144
|
-
children: column.header
|
|
145
|
-
}, column.id))
|
|
146
|
-
})
|
|
147
|
-
}),
|
|
148
|
-
/*#__PURE__*/ jsx("tbody", {
|
|
149
|
-
style: tbodyStyle,
|
|
150
|
-
children: virtualItems.map((virtualRow)=>{
|
|
151
|
-
const isActive = activeRowIndex === virtualRow.index;
|
|
152
|
-
return /*#__PURE__*/ jsx("tr", {
|
|
153
|
-
ref: measureElement,
|
|
154
|
-
"data-index": virtualRow.index,
|
|
155
|
-
onClick: onRowClick ? ()=>onRowClick(virtualRow.data, virtualRow.index) : undefined,
|
|
156
|
-
className: clsx("absolute flex w-full", {
|
|
157
|
-
"cursor-pointer": !!onRowClick,
|
|
158
|
-
"bg-action-dark/10 dark:bg-action-light/10": isActive
|
|
159
|
-
}),
|
|
160
|
-
style: {
|
|
161
|
-
height: `${virtualRow.size}px`,
|
|
162
|
-
transform: `translateY(${virtualRow.start}px)`
|
|
163
|
-
},
|
|
164
|
-
children: columns.map((column)=>/*#__PURE__*/ jsx("td", {
|
|
165
|
-
className: clsx(compact ? "px-2 py-1" : "px-4 py-3", column.className),
|
|
166
|
-
style: {
|
|
167
|
-
width: column.width
|
|
168
|
-
},
|
|
169
|
-
children: column.cell(virtualRow.data, virtualRow.index)
|
|
170
|
-
}, column.id))
|
|
171
|
-
}, virtualRow.key);
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
]
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export { VirtualDataGrid };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { VirtualItem, Virtualizer } from "@tanstack/react-virtual";
|
|
2
|
-
export { useVirtualizer, useWindowVirtualizer } from "@tanstack/react-virtual";
|
|
3
|
-
export type { UseVirtualDataGridOptions, UseVirtualDataGridReturn, } from "./useVirtualDataGrid";
|
|
4
|
-
export { useVirtualDataGrid } from "./useVirtualDataGrid";
|
|
5
|
-
export type { VirtualDataGridColumn, VirtualDataGridProps, } from "./VirtualDataGrid";
|
|
6
|
-
export { VirtualDataGrid } from "./VirtualDataGrid";
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
@versini/ui-datagrid v0.1.0
|
|
3
|
-
© 2026 gizmette.com
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useVirtualizer, useWindowVirtualizer } from "@tanstack/react-virtual";
|
|
7
|
-
import { useVirtualDataGrid } from "./useVirtualDataGrid.js";
|
|
8
|
-
import { VirtualDataGrid } from "./VirtualDataGrid.js";
|
|
9
|
-
|
|
10
|
-
;// CONCATENATED MODULE: external "@tanstack/react-virtual"
|
|
11
|
-
|
|
12
|
-
;// CONCATENATED MODULE: external "./useVirtualDataGrid.js"
|
|
13
|
-
|
|
14
|
-
;// CONCATENATED MODULE: external "./VirtualDataGrid.js"
|
|
15
|
-
|
|
16
|
-
;// CONCATENATED MODULE: ./src/DataGridVirtual/index.ts
|
|
17
|
-
// Re-export from @tanstack/react-virtual for convenience.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export { VirtualDataGrid, useVirtualDataGrid, useVirtualizer, useWindowVirtualizer };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { type Virtualizer } from "@tanstack/react-virtual";
|
|
2
|
-
export type UseVirtualDataGridOptions<T = unknown> = {
|
|
3
|
-
/**
|
|
4
|
-
* Array of data items.
|
|
5
|
-
*/
|
|
6
|
-
data: T[];
|
|
7
|
-
/**
|
|
8
|
-
* Estimated height of each row in pixels.
|
|
9
|
-
* @default 40
|
|
10
|
-
*/
|
|
11
|
-
estimateSize?: number | ((index: number) => number);
|
|
12
|
-
/**
|
|
13
|
-
* Number of rows to render above/below the visible area.
|
|
14
|
-
* @default 5
|
|
15
|
-
*/
|
|
16
|
-
overscan?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Function to get a unique key for each item.
|
|
19
|
-
*/
|
|
20
|
-
getItemKey: (index: number) => string | number;
|
|
21
|
-
/**
|
|
22
|
-
* Whether virtualization is enabled.
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Whether to use React's flushSync for synchronous updates. Set to false for
|
|
28
|
-
* React 19 compatibility.
|
|
29
|
-
* @default true
|
|
30
|
-
*/
|
|
31
|
-
useFlushSync?: boolean;
|
|
32
|
-
};
|
|
33
|
-
export type UseVirtualDataGridReturn<T = unknown> = {
|
|
34
|
-
/**
|
|
35
|
-
* Ref to attach to the scroll container.
|
|
36
|
-
*/
|
|
37
|
-
scrollContainerRef: React.RefObject<HTMLDivElement | null>;
|
|
38
|
-
/**
|
|
39
|
-
* Total height of all rows (for container sizing).
|
|
40
|
-
*/
|
|
41
|
-
totalSize: number;
|
|
42
|
-
/**
|
|
43
|
-
* Virtual items to render.
|
|
44
|
-
*/
|
|
45
|
-
virtualItems: {
|
|
46
|
-
index: number;
|
|
47
|
-
key: string | number | bigint;
|
|
48
|
-
size: number;
|
|
49
|
-
start: number;
|
|
50
|
-
data: T;
|
|
51
|
-
}[];
|
|
52
|
-
/**
|
|
53
|
-
* Scroll to a specific row index.
|
|
54
|
-
*/
|
|
55
|
-
scrollToIndex: (index: number, options?: {
|
|
56
|
-
align?: "start" | "center" | "end" | "auto";
|
|
57
|
-
behavior?: "auto" | "smooth";
|
|
58
|
-
}) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Whether the list is currently being scrolled.
|
|
61
|
-
*/
|
|
62
|
-
isScrolling: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* The virtualizer instance for advanced usage.
|
|
65
|
-
*/
|
|
66
|
-
virtualizer: Virtualizer<HTMLDivElement, Element>;
|
|
67
|
-
/**
|
|
68
|
-
* Measure a row element (for dynamic sizing).
|
|
69
|
-
*/
|
|
70
|
-
measureElement: (element: Element | null) => void;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Hook for virtualizing a data grid with TanStack Virtual.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```tsx
|
|
77
|
-
* const {
|
|
78
|
-
* scrollContainerRef,
|
|
79
|
-
* totalSize,
|
|
80
|
-
* virtualItems,
|
|
81
|
-
* scrollToIndex,
|
|
82
|
-
* } = useVirtualDataGrid({
|
|
83
|
-
* data: items,
|
|
84
|
-
* estimateSize: 48,
|
|
85
|
-
* overscan: 10,
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* return (
|
|
89
|
-
* <div ref={scrollContainerRef} style={{ height: '500px', overflow: 'auto' }}>
|
|
90
|
-
* <div style={{ height: totalSize }}>
|
|
91
|
-
* <table>
|
|
92
|
-
* <tbody>
|
|
93
|
-
* {virtualItems.map((virtualRow) => (
|
|
94
|
-
* <tr
|
|
95
|
-
* key={virtualRow.key}
|
|
96
|
-
* style={{
|
|
97
|
-
* height: virtualRow.size,
|
|
98
|
-
* transform: `translateY(${virtualRow.start}px)`,
|
|
99
|
-
* }}
|
|
100
|
-
* >
|
|
101
|
-
* {renderCells(virtualRow.data)}
|
|
102
|
-
* </tr>
|
|
103
|
-
* ))}
|
|
104
|
-
* </tbody>
|
|
105
|
-
* </table>
|
|
106
|
-
* </div>
|
|
107
|
-
* </div>
|
|
108
|
-
* );
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
*/
|
|
112
|
-
export declare function useVirtualDataGrid<T>({ data, estimateSize, overscan, getItemKey, enabled, useFlushSync, }: UseVirtualDataGridOptions<T>): UseVirtualDataGridReturn<T>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
@versini/ui-datagrid v0.1.0
|
|
3
|
-
© 2026 gizmette.com
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
7
|
-
import { useCallback, useRef } from "react";
|
|
8
|
-
|
|
9
|
-
;// CONCATENATED MODULE: external "@tanstack/react-virtual"
|
|
10
|
-
|
|
11
|
-
;// CONCATENATED MODULE: external "react"
|
|
12
|
-
|
|
13
|
-
;// CONCATENATED MODULE: ./src/DataGridVirtual/useVirtualDataGrid.ts
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const DEFAULT_ESTIMATE_SIZE = 40;
|
|
17
|
-
const DEFAULT_OVERSCAN = 5;
|
|
18
|
-
/**
|
|
19
|
-
* Hook for virtualizing a data grid with TanStack Virtual.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* const {
|
|
24
|
-
* scrollContainerRef,
|
|
25
|
-
* totalSize,
|
|
26
|
-
* virtualItems,
|
|
27
|
-
* scrollToIndex,
|
|
28
|
-
* } = useVirtualDataGrid({
|
|
29
|
-
* data: items,
|
|
30
|
-
* estimateSize: 48,
|
|
31
|
-
* overscan: 10,
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* return (
|
|
35
|
-
* <div ref={scrollContainerRef} style={{ height: '500px', overflow: 'auto' }}>
|
|
36
|
-
* <div style={{ height: totalSize }}>
|
|
37
|
-
* <table>
|
|
38
|
-
* <tbody>
|
|
39
|
-
* {virtualItems.map((virtualRow) => (
|
|
40
|
-
* <tr
|
|
41
|
-
* key={virtualRow.key}
|
|
42
|
-
* style={{
|
|
43
|
-
* height: virtualRow.size,
|
|
44
|
-
* transform: `translateY(${virtualRow.start}px)`,
|
|
45
|
-
* }}
|
|
46
|
-
* >
|
|
47
|
-
* {renderCells(virtualRow.data)}
|
|
48
|
-
* </tr>
|
|
49
|
-
* ))}
|
|
50
|
-
* </tbody>
|
|
51
|
-
* </table>
|
|
52
|
-
* </div>
|
|
53
|
-
* </div>
|
|
54
|
-
* );
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
*/ function useVirtualDataGrid({ data, estimateSize = DEFAULT_ESTIMATE_SIZE, overscan = DEFAULT_OVERSCAN, getItemKey, enabled = true, useFlushSync = true }) {
|
|
58
|
-
const scrollContainerRef = useRef(null);
|
|
59
|
-
const estimateSizeFn = useCallback((index)=>typeof estimateSize === "function" ? estimateSize(index) : estimateSize, [
|
|
60
|
-
estimateSize
|
|
61
|
-
]);
|
|
62
|
-
const virtualizer = useVirtualizer({
|
|
63
|
-
count: data.length,
|
|
64
|
-
getScrollElement: ()=>scrollContainerRef.current,
|
|
65
|
-
estimateSize: estimateSizeFn,
|
|
66
|
-
overscan,
|
|
67
|
-
getItemKey,
|
|
68
|
-
enabled,
|
|
69
|
-
useFlushSync
|
|
70
|
-
});
|
|
71
|
-
const virtualItems = virtualizer.getVirtualItems().map((virtualItem)=>({
|
|
72
|
-
index: virtualItem.index,
|
|
73
|
-
key: virtualItem.key,
|
|
74
|
-
size: virtualItem.size,
|
|
75
|
-
start: virtualItem.start,
|
|
76
|
-
data: data[virtualItem.index]
|
|
77
|
-
}));
|
|
78
|
-
return {
|
|
79
|
-
scrollContainerRef,
|
|
80
|
-
totalSize: virtualizer.getTotalSize(),
|
|
81
|
-
virtualItems,
|
|
82
|
-
scrollToIndex: virtualizer.scrollToIndex,
|
|
83
|
-
isScrolling: virtualizer.isScrolling,
|
|
84
|
-
virtualizer,
|
|
85
|
-
measureElement: virtualizer.measureElement
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { useVirtualDataGrid };
|