@omnigrid/react 0.1.37 → 0.1.39
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 +36 -0
- package/dist/OmniGrid.d.ts +2 -2
- package/dist/OmniGrid.js +102 -50
- package/dist/index.d.ts +1 -1
- package/dist/pooledRow.d.ts +3 -1
- package/dist/pooledRow.js +19 -2
- package/dist/reactColumnDef.d.ts +2 -1
- package/dist/types.d.ts +41 -5
- package/dist/useGrid.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,42 @@ const data = [...];
|
|
|
22
22
|
<OmniGrid columns={columns} data={data} />;
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
`columns` is optional. When omitted, the core creates one leaf column for each
|
|
26
|
+
own property of the first data row. If there are no rows yet, it waits for data.
|
|
27
|
+
The inferred schema stays fixed; call `grid.setColumns` when the schema changes.
|
|
28
|
+
By default, each header is the property key. Set
|
|
29
|
+
`autoColumnHeaderMode="title-case"` to split camel-case keys into capitalized
|
|
30
|
+
words. For custom formatting, use the core's `getColumnHeader` option:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
<OmniGrid
|
|
34
|
+
data={data}
|
|
35
|
+
autoColumnHeaderMode="title-case"
|
|
36
|
+
/>
|
|
37
|
+
<OmniGrid
|
|
38
|
+
data={data}
|
|
39
|
+
getColumnHeader={(field) => field.toUpperCase()}
|
|
40
|
+
/>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The grid fills its parent's available height by default. Give the parent a
|
|
44
|
+
constrained height (for example, in a flex layout) and the adapter measures the
|
|
45
|
+
actual viewport with `ResizeObserver`. Use `height` for a fixed grid height, or
|
|
46
|
+
set `sizingMode="auto"` to grow the grid with its rows. Supplying `height`
|
|
47
|
+
without `sizingMode` selects fixed sizing; explicitly setting
|
|
48
|
+
`sizingMode="fixed"` requires `height`:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
<OmniGrid columns={columns} data={data} height={480} />
|
|
52
|
+
<OmniGrid columns={columns} data={data} sizingMode="auto" />
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`minHeight` applies only to auto-height grids. Auto-height renders the full row
|
|
56
|
+
content and should be avoided for large datasets when vertical virtualization
|
|
57
|
+
is needed. `style` remains available for CSS customization; use `height` and
|
|
58
|
+
`sizingMode` to select the grid's sizing behavior. A legacy `style.height` can
|
|
59
|
+
still size the outer element in fill mode, but it no longer selects auto-height.
|
|
60
|
+
|
|
25
61
|
Set `animateRows` to animate visible rows when filtering or sorting changes their
|
|
26
62
|
positions. Row animation uses a separate CSS transform component, so virtualized
|
|
27
63
|
positioning and scrolling remain independent. It is disabled by default; provide
|
package/dist/OmniGrid.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { GridProps } from "./types.js";
|
|
|
10
10
|
* Scroll position is decoupled from React's render cycle: `Grid.setViewport`
|
|
11
11
|
* for scroll-only updates does NOT notify the Store, so React does NOT
|
|
12
12
|
* re-render on every scroll frame. React re-renders only on structural
|
|
13
|
-
* changes (data, columns, dimensions) and column
|
|
13
|
+
* changes (data, columns, dimensions) and column geometry changes (header only).
|
|
14
14
|
*
|
|
15
15
|
* Horizontally pinned columns each back onto their own `DomPool` whose rows
|
|
16
16
|
* live in a `position: sticky` pane (a sibling of the scrollable content inside
|
|
@@ -24,4 +24,4 @@ import type { GridProps } from "./types.js";
|
|
|
24
24
|
* core's headless content; React components in slots are connected via
|
|
25
25
|
* `slotComponents`.
|
|
26
26
|
*/
|
|
27
|
-
export declare function OmniGrid<T>({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }: GridProps<T>): import("react").JSX.Element;
|
|
27
|
+
export declare function OmniGrid<T>({ className, style, height, sizingMode: sizingModeProp, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }: GridProps<T>): import("react").JSX.Element;
|
package/dist/OmniGrid.js
CHANGED
|
@@ -42,7 +42,6 @@ function createRowLayerState() {
|
|
|
42
42
|
columns: [],
|
|
43
43
|
windowKey: "",
|
|
44
44
|
revision: -1,
|
|
45
|
-
totalWidth: -1,
|
|
46
45
|
processed: null,
|
|
47
46
|
originX: 0,
|
|
48
47
|
rowWidth: 0,
|
|
@@ -62,7 +61,7 @@ function createRowLayerState() {
|
|
|
62
61
|
* Scroll position is decoupled from React's render cycle: `Grid.setViewport`
|
|
63
62
|
* for scroll-only updates does NOT notify the Store, so React does NOT
|
|
64
63
|
* re-render on every scroll frame. React re-renders only on structural
|
|
65
|
-
* changes (data, columns, dimensions) and column
|
|
64
|
+
* changes (data, columns, dimensions) and column geometry changes (header only).
|
|
66
65
|
*
|
|
67
66
|
* Horizontally pinned columns each back onto their own `DomPool` whose rows
|
|
68
67
|
* live in a `position: sticky` pane (a sibling of the scrollable content inside
|
|
@@ -76,7 +75,7 @@ function createRowLayerState() {
|
|
|
76
75
|
* core's headless content; React components in slots are connected via
|
|
77
76
|
* `slotComponents`.
|
|
78
77
|
*/
|
|
79
|
-
export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
|
|
78
|
+
export function OmniGrid({ className, style, height, sizingMode: sizingModeProp, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
|
|
80
79
|
const { grid, state, viewportData } = useGrid(options);
|
|
81
80
|
const columnTooltipOptions = useMemo(() => {
|
|
82
81
|
const result = new Map();
|
|
@@ -127,7 +126,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
127
126
|
/** Latest `syncPool` — read imperatively from `measureViewport`/ResizeObserver so the callback stays stable. */
|
|
128
127
|
const syncPoolRef = useRef(null);
|
|
129
128
|
const optionsRef = useRef(options);
|
|
130
|
-
const
|
|
129
|
+
const columnGeometryKeyRef = useRef("");
|
|
131
130
|
/** Content size the scrollbar insets were measured for. */
|
|
132
131
|
const contentSizeKeyRef = useRef("");
|
|
133
132
|
const scrollbarWidthRef = useRef(0);
|
|
@@ -142,11 +141,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
142
141
|
}
|
|
143
142
|
const layers = layersRef.current;
|
|
144
143
|
const layerContextRef = useRef(null);
|
|
145
|
-
//
|
|
146
|
-
// horizontal column
|
|
147
|
-
//
|
|
148
|
-
// of the header — row DOM nodes remain managed by the DomPool and are
|
|
149
|
-
// never touched by React's reconciliation.
|
|
144
|
+
// This counter triggers a targeted React re-render of the header when
|
|
145
|
+
// horizontal column geometry changes. Row DOM nodes remain managed by the
|
|
146
|
+
// DomPool and are never touched by React's reconciliation.
|
|
150
147
|
const [, setColumnWindowVersion] = useState(0);
|
|
151
148
|
/** Set to `true` once the viewport dimensions have been measured against
|
|
152
149
|
* the real DOM element. Before that the grid content is hidden so the
|
|
@@ -179,7 +176,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
179
176
|
grid.refresh();
|
|
180
177
|
}
|
|
181
178
|
}, [grid, options.rowClassRules]);
|
|
182
|
-
const
|
|
179
|
+
const sizingMode = sizingModeProp ?? (height !== undefined ? "fixed" : "fill");
|
|
180
|
+
if (sizingMode === "fixed" && height === undefined) {
|
|
181
|
+
throw new Error('OmniGrid requires the "height" prop when sizingMode is "fixed".');
|
|
182
|
+
}
|
|
183
|
+
const autoHeight = sizingMode === "auto";
|
|
184
|
+
const styleHeight = style?.height;
|
|
185
|
+
const gridStyle = { ...style };
|
|
186
|
+
delete gridStyle.height;
|
|
187
|
+
const layoutHeight = sizingMode === "fixed" ? height : sizingMode === "fill" ? (styleHeight ?? "100%") : undefined;
|
|
183
188
|
const rowHeight = grid.getState().rowHeight;
|
|
184
189
|
// Column-group header stack: `headerRowCount` group rows (one per depth) above
|
|
185
190
|
// the leaf header row. Without groups `headerRowCount` is 0 and `columnGroupDepth`
|
|
@@ -193,8 +198,8 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
193
198
|
* Keeps the spacer height and visible row-layer height in sync without
|
|
194
199
|
* re-rendering the grid for every measured row.
|
|
195
200
|
*/
|
|
196
|
-
const applyContentHeight = (totalHeight) => {
|
|
197
|
-
const layerHeight = `${autoHeight ? totalHeight : Math.max(0,
|
|
201
|
+
const applyContentHeight = (totalHeight, viewportHeight) => {
|
|
202
|
+
const layerHeight = `${autoHeight ? totalHeight : Math.max(0, viewportHeight - headerHeight)}px`;
|
|
198
203
|
for (const ref of [rowsLayerRef, pinnedLeftRowsLayerRef, pinnedRightRowsLayerRef]) {
|
|
199
204
|
const element = ref.current;
|
|
200
205
|
if (element && element.style.height !== layerHeight)
|
|
@@ -241,8 +246,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
241
246
|
const cellFlashRaw = options.cellFlash;
|
|
242
247
|
const cellFlashDurationMs = cellFlashRaw === true ? 1000 : typeof cellFlashRaw === "number" && cellFlashRaw > 0 ? cellFlashRaw : false;
|
|
243
248
|
const viewportStyle = {
|
|
244
|
-
...
|
|
245
|
-
height: autoHeight ? measuredHeight : style?.height,
|
|
249
|
+
...gridStyle,
|
|
246
250
|
...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
|
|
247
251
|
};
|
|
248
252
|
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null, suppressColumnBorders ? "omnigrid-no-column-borders" : null]
|
|
@@ -814,7 +818,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
814
818
|
const state = grid.getState();
|
|
815
819
|
const processed = getPoolData(grid);
|
|
816
820
|
const processedChanged = layer.processed !== processed;
|
|
817
|
-
const changed = layer.revision !== grid.getRevision() ||
|
|
821
|
+
const changed = layer.revision !== grid.getRevision() || processedChanged;
|
|
818
822
|
const shouldAnimate = Boolean(options.animateRows && layer.processed !== null && processedChanged);
|
|
819
823
|
const animationPositions = shouldAnimate
|
|
820
824
|
? new Map(layer.panes.flatMap((pane) => {
|
|
@@ -824,7 +828,6 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
824
828
|
: null;
|
|
825
829
|
if (changed) {
|
|
826
830
|
layer.revision = grid.getRevision();
|
|
827
|
-
layer.totalWidth = viewportData.totalWidth;
|
|
828
831
|
layer.processed = processed;
|
|
829
832
|
pool.invalidate();
|
|
830
833
|
}
|
|
@@ -840,11 +843,19 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
840
843
|
visibleRowRange: viewportData.visibleRowRange,
|
|
841
844
|
rowWidth: layer.rowWidth,
|
|
842
845
|
});
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
+
// A pooled row's bound offset predates measurements of preceding rows.
|
|
847
|
+
for (const host of pool.getHosts()) {
|
|
848
|
+
const pane = layer.paneMap.get(host);
|
|
849
|
+
const hostElement = host;
|
|
850
|
+
const rowIndexValue = hostElement.dataset.rowIndex;
|
|
851
|
+
if (!pane || rowIndexValue === undefined)
|
|
852
|
+
continue;
|
|
853
|
+
const rowIndex = Number(rowIndexValue);
|
|
854
|
+
const rangeIndex = rowIndex - viewportData.rowRange.start;
|
|
855
|
+
const rowOffset = viewportData.rows[rangeIndex]?.offset;
|
|
856
|
+
if (rowOffset === undefined)
|
|
846
857
|
continue;
|
|
847
|
-
const offsetY = Math.round(
|
|
858
|
+
const offsetY = Math.round(rowOffset - layer.scrollTop);
|
|
848
859
|
if (pane.getOffsetY() !== offsetY)
|
|
849
860
|
pane.setOffsetY(offsetY);
|
|
850
861
|
}
|
|
@@ -866,7 +877,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
866
877
|
// It is written imperatively: a Store notification per measured row
|
|
867
878
|
// would re-render the whole grid, and the grid would then lag behind
|
|
868
879
|
// the native scroll position (the user sees the previous rows).
|
|
869
|
-
applyContentHeight(currentViewportData.totalHeight);
|
|
880
|
+
applyContentHeight(currentViewportData.totalHeight, state.viewport.height);
|
|
870
881
|
const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
871
882
|
const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
872
883
|
const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
@@ -901,28 +912,43 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
901
912
|
else {
|
|
902
913
|
bindLayers();
|
|
903
914
|
}
|
|
904
|
-
//
|
|
905
|
-
//
|
|
906
|
-
//
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
915
|
+
// Column geometry can change without changing the visible window, such
|
|
916
|
+
// as during a resize. Update every pane imperatively so row content is
|
|
917
|
+
// not rebound on each pointer frame.
|
|
918
|
+
const getLayerGeometryKey = (layer, includeWindow) => JSON.stringify([
|
|
919
|
+
includeWindow ? currentViewportData.columnRange : null,
|
|
920
|
+
includeWindow ? state.viewport.width : null,
|
|
921
|
+
layer.originX,
|
|
922
|
+
layer.rowWidth,
|
|
923
|
+
layer.columns.map((item) => [item.column.id, item.offset, item.width]),
|
|
924
|
+
]);
|
|
925
|
+
const leftGeometryKey = getLayerGeometryKey(layers.left, false);
|
|
926
|
+
const centralGeometryKey = getLayerGeometryKey(layers.central, true);
|
|
927
|
+
const rightGeometryKey = getLayerGeometryKey(layers.right, false);
|
|
928
|
+
const columnGeometryKey = JSON.stringify([leftGeometryKey, centralGeometryKey, rightGeometryKey]);
|
|
929
|
+
if (columnGeometryKey !== columnGeometryKeyRef.current) {
|
|
930
|
+
columnGeometryKeyRef.current = columnGeometryKey;
|
|
913
931
|
const updateColumnWindow = () => {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
932
|
+
const updateLayerColumns = (layer, geometryKey, isCentral) => {
|
|
933
|
+
if (layer.windowKey === geometryKey)
|
|
934
|
+
return;
|
|
935
|
+
layer.windowKey = geometryKey;
|
|
936
|
+
const isLeft = layer === layers.left;
|
|
937
|
+
const isRight = layer === layers.right;
|
|
938
|
+
for (const pane of layer.panes) {
|
|
939
|
+
const paneRow = pane.getRow();
|
|
940
|
+
if (!paneRow) {
|
|
941
|
+
pane.updateColumns(layer.columns, layer.originX, null, layer.rowWidth);
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
|
|
945
|
+
const layout = isLeft ? spans.left : isRight ? spans.right : spans.central;
|
|
946
|
+
pane.updateColumns(layer.columns, layer.originX, sliceSpanLayoutForLayer(currentViewportData, layer.columns, isCentral, layout), layer.rowWidth);
|
|
922
947
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
948
|
+
};
|
|
949
|
+
updateLayerColumns(layers.left, leftGeometryKey, false);
|
|
950
|
+
updateLayerColumns(layers.central, centralGeometryKey, true);
|
|
951
|
+
updateLayerColumns(layers.right, rightGeometryKey, false);
|
|
926
952
|
setColumnWindowVersion((v) => v + 1);
|
|
927
953
|
};
|
|
928
954
|
if (synchronousColumnWindow) {
|
|
@@ -960,22 +986,24 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
960
986
|
scrollbarWidthRef.current = scrollbarWidth;
|
|
961
987
|
const width = element.clientWidth;
|
|
962
988
|
const height = element.clientHeight;
|
|
963
|
-
if (width === 0) {
|
|
989
|
+
if (width === 0 || height <= headerHeight) {
|
|
964
990
|
// Layout may not be computed yet on the first paint. Retry on the
|
|
965
|
-
// next
|
|
966
|
-
|
|
967
|
-
|
|
991
|
+
// next frame, but do not reveal a zero-height row layer.
|
|
992
|
+
window.requestAnimationFrame(() => {
|
|
993
|
+
const current = viewportRef.current;
|
|
994
|
+
if (!current || current.clientWidth === 0 || current.clientHeight <= headerHeight)
|
|
995
|
+
return;
|
|
968
996
|
measureViewport();
|
|
969
997
|
});
|
|
970
998
|
return;
|
|
971
999
|
}
|
|
972
1000
|
grid.setViewport({
|
|
973
1001
|
width,
|
|
974
|
-
|
|
1002
|
+
height,
|
|
975
1003
|
});
|
|
976
1004
|
syncPoolRef.current?.(false);
|
|
977
1005
|
setIsViewportMeasured(true);
|
|
978
|
-
}, [grid, syncScrollbarInsets, setIsViewportMeasured]);
|
|
1006
|
+
}, [grid, headerHeight, syncScrollbarInsets, setIsViewportMeasured]);
|
|
979
1007
|
useEffect(() => {
|
|
980
1008
|
const element = viewportRef.current;
|
|
981
1009
|
if (!element)
|
|
@@ -989,7 +1017,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
989
1017
|
scrollbarWidthRef.current = scrollbarWidth;
|
|
990
1018
|
const width = element.clientWidth;
|
|
991
1019
|
const height = element.clientHeight;
|
|
992
|
-
if (width === 0 || height
|
|
1020
|
+
if (width === 0 || height <= headerHeight)
|
|
993
1021
|
return;
|
|
994
1022
|
grid.setViewport({ width, height });
|
|
995
1023
|
syncPoolRef.current?.(false);
|
|
@@ -1019,7 +1047,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1019
1047
|
// back to minWidth) and only snap to the correct size after the
|
|
1020
1048
|
// ResizeObserver-driven useEffect runs — a visible flash on first load.
|
|
1021
1049
|
measureViewport();
|
|
1022
|
-
}, [autoHeight, hasVerticalOverflow, measureViewport, overlayScope]);
|
|
1050
|
+
}, [autoHeight, hasVerticalOverflow, height, measureViewport, overlayScope, sizingMode, styleHeight]);
|
|
1023
1051
|
useEffect(() => {
|
|
1024
1052
|
const unsubscribe = grid.on("scrollTo", (position) => {
|
|
1025
1053
|
const element = viewportRef.current;
|
|
@@ -1030,6 +1058,16 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1030
1058
|
});
|
|
1031
1059
|
return unsubscribe;
|
|
1032
1060
|
}, [grid]);
|
|
1061
|
+
useEffect(() => {
|
|
1062
|
+
const unsubscribe = grid.on("cellsRefresh", ({ columnIds }) => {
|
|
1063
|
+
const columnsToRefresh = columnIds ? new Set(columnIds) : undefined;
|
|
1064
|
+
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1065
|
+
for (const pane of layer.panes)
|
|
1066
|
+
pane.refreshCells(columnsToRefresh);
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
return unsubscribe;
|
|
1070
|
+
}, [grid, layers]);
|
|
1033
1071
|
useEffect(() => () => {
|
|
1034
1072
|
if (anchorTimerRef.current !== null)
|
|
1035
1073
|
window.clearTimeout(anchorTimerRef.current);
|
|
@@ -1440,6 +1478,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1440
1478
|
top: 0,
|
|
1441
1479
|
zIndex: isPinned ? 4 : 2,
|
|
1442
1480
|
width,
|
|
1481
|
+
// Force own compositing layer to fix Edge 1px sticky shift during scroll
|
|
1482
|
+
transform: "translateZ(0)",
|
|
1483
|
+
willChange: "transform",
|
|
1484
|
+
backfaceVisibility: "hidden",
|
|
1443
1485
|
}, children: _jsxs("div", { role: "rowgroup", children: [Array.from({ length: headerRowCount }, (_, depth) => (_jsx("div", { role: "row", className: "omnigrid-header-row omnigrid-header-group-row", style: {
|
|
1444
1486
|
height: rowHeight,
|
|
1445
1487
|
left: 0,
|
|
@@ -1465,8 +1507,18 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1465
1507
|
top: headerHeight,
|
|
1466
1508
|
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1467
1509
|
width,
|
|
1510
|
+
// Force own compositing layer to fix Edge 1px sticky shift during scroll
|
|
1511
|
+
transform: "translateZ(0)",
|
|
1512
|
+
willChange: "transform",
|
|
1513
|
+
backfaceVisibility: "hidden",
|
|
1468
1514
|
} }));
|
|
1469
|
-
return (_jsxs("div", { className: "omnigrid-layout", ref: layoutRef, style: {
|
|
1515
|
+
return (_jsxs("div", { className: "omnigrid-layout", ref: layoutRef, style: {
|
|
1516
|
+
...gridStyle,
|
|
1517
|
+
height: layoutHeight,
|
|
1518
|
+
...(sizingMode === "fill" ? { flex: "1 1 0", minHeight: 0 } : {}),
|
|
1519
|
+
position: "relative",
|
|
1520
|
+
...(isFullOverlay ? { overflow: "hidden" } : {}),
|
|
1521
|
+
}, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { className: "omnigrid-viewport-container", style: {
|
|
1470
1522
|
flex: "1 1 0",
|
|
1471
1523
|
minHeight: 0,
|
|
1472
1524
|
minWidth: 0,
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { CellTooltipRenderer, CellTooltipRenderContext, ReactCellRenderer,
|
|
|
5
5
|
export { PooledRowPane } from "./pooledRow.js";
|
|
6
6
|
export type { ContentBridge, PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./types.js";
|
|
7
7
|
export { OmniGrid } from "./OmniGrid.js";
|
|
8
|
-
export type { GridProps, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types.js";
|
|
8
|
+
export type { GridProps, GridSizingMode, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types.js";
|
|
9
9
|
export { useGrid } from "./useGrid.js";
|
|
10
10
|
export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls.js";
|
|
11
11
|
export type { DebouncedInputProps } from "./controls.js";
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -37,7 +37,9 @@ export declare class PooledRowPane<T> {
|
|
|
37
37
|
/** Returns the currently bound row, if any. */
|
|
38
38
|
getRow(): PooledRow<T> | null;
|
|
39
39
|
/** Re-layouts cells for a new horizontal column window. */
|
|
40
|
-
updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
40
|
+
updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null, rowWidth?: number): void;
|
|
41
|
+
/** Refreshes this row's presentation and the cells in the requested columns. */
|
|
42
|
+
refreshCells(columnIds?: ReadonlySet<string>): void;
|
|
41
43
|
/** Single row positioning operation — transform only (no reflow). */
|
|
42
44
|
setOffsetY(offsetY: number): void;
|
|
43
45
|
/** Returns the current virtualized row position in grid coordinates. */
|
package/dist/pooledRow.js
CHANGED
|
@@ -118,16 +118,33 @@ export class PooledRowPane {
|
|
|
118
118
|
return this.row;
|
|
119
119
|
}
|
|
120
120
|
/** Re-layouts cells for a new horizontal column window. */
|
|
121
|
-
updateColumns(columns, originX = 0, spans) {
|
|
121
|
+
updateColumns(columns, originX = 0, spans, rowWidth) {
|
|
122
122
|
this.originX = originX;
|
|
123
123
|
const row = this.row;
|
|
124
|
-
if (row)
|
|
124
|
+
if (row) {
|
|
125
|
+
if (rowWidth !== undefined)
|
|
126
|
+
row.width = rowWidth;
|
|
125
127
|
this.applyRowSizing(row);
|
|
128
|
+
}
|
|
126
129
|
this.mapColumns(columns, false, spans);
|
|
127
130
|
if (this.variableHeight && row) {
|
|
128
131
|
this.scheduleHeightMeasurement(row);
|
|
129
132
|
}
|
|
130
133
|
}
|
|
134
|
+
/** Refreshes this row's presentation and the cells in the requested columns. */
|
|
135
|
+
refreshCells(columnIds) {
|
|
136
|
+
const row = this.row;
|
|
137
|
+
if (!row)
|
|
138
|
+
return;
|
|
139
|
+
const hovered = this.host.matches(":hover");
|
|
140
|
+
this.applyRowPresentation(row);
|
|
141
|
+
if (hovered)
|
|
142
|
+
this.host.classList.add("omnigrid-row-hover");
|
|
143
|
+
for (const cell of this.cells) {
|
|
144
|
+
if (cell.column && (!columnIds || columnIds.has(cell.column.id)))
|
|
145
|
+
this.renderContent(cell);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
131
148
|
/** Single row positioning operation — transform only (no reflow). */
|
|
132
149
|
setOffsetY(offsetY) {
|
|
133
150
|
const roundedOffsetY = Math.round(offsetY);
|
package/dist/reactColumnDef.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ export type ReactColumnDef<T> = ReactColumnLeafDef<T> | ReactColumnGroupDef<T>;
|
|
|
65
65
|
* @api
|
|
66
66
|
*/
|
|
67
67
|
export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns" | "defaultColumnDef"> & {
|
|
68
|
-
|
|
68
|
+
/** Column definitions; inferred from the first data row when omitted. @api */
|
|
69
|
+
columns?: ReactColumnDef<T>[];
|
|
69
70
|
defaultColumnDef?: Partial<Omit<ReactColumnLeafDef<T>, "id" | "header">>;
|
|
70
71
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -85,14 +85,28 @@ export interface SlotRendererRegistry<T> {
|
|
|
85
85
|
}
|
|
86
86
|
export type OverlayComponentProps<T> = import("@omnigrid/core").OverlayComponentProps<T>;
|
|
87
87
|
export type OverlayComponent<T> = import("react").ComponentType<import("@omnigrid/core").OverlayComponentProps<T>> | import("@omnigrid/core").OverlayComponent<T>;
|
|
88
|
-
|
|
88
|
+
interface GridPropsBase<T> extends Omit<ReactGridOptions<T>, "overlayComponents"> {
|
|
89
89
|
className?: string;
|
|
90
90
|
style?: import("react").CSSProperties;
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
92
|
+
* Height behavior. Defaults to `fill`, unless `height` is provided without
|
|
93
|
+
* an explicit mode, which selects `fixed`.
|
|
94
|
+
*
|
|
95
|
+
* @api
|
|
96
|
+
* @default "fill"
|
|
97
|
+
*/
|
|
98
|
+
sizingMode?: GridSizingMode;
|
|
99
|
+
/**
|
|
100
|
+
* Explicit height for `fixed` sizing. When provided without `sizingMode`,
|
|
101
|
+
* the grid uses `fixed` sizing.
|
|
102
|
+
*
|
|
103
|
+
* @api
|
|
104
|
+
*/
|
|
105
|
+
height?: import("react").CSSProperties["height"];
|
|
106
|
+
/**
|
|
107
|
+
* Minimum grid height in rows in `auto` sizing mode. The viewport will be
|
|
108
|
+
* at least `headerHeight + minHeight * rowHeight` tall so it does not
|
|
109
|
+
* collapse when it has few or no rows. Set to `0` to disable.
|
|
96
110
|
*
|
|
97
111
|
* @api
|
|
98
112
|
* @default 3
|
|
@@ -113,6 +127,27 @@ export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponen
|
|
|
113
127
|
slotComponents?: SlotRendererRegistry<T>;
|
|
114
128
|
overlayComponents?: Record<string, import("@omnigrid/core").OverlayComponent<T>>;
|
|
115
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Controls how the grid obtains its height.
|
|
132
|
+
*
|
|
133
|
+
* @api
|
|
134
|
+
*/
|
|
135
|
+
export type GridSizingMode = "fixed" | "fill" | "auto";
|
|
136
|
+
/**
|
|
137
|
+
* React adapter props with explicit grid sizing.
|
|
138
|
+
*
|
|
139
|
+
* @api
|
|
140
|
+
*/
|
|
141
|
+
export type GridProps<T> = GridPropsBase<T> & ({
|
|
142
|
+
sizingMode: "fixed";
|
|
143
|
+
height: NonNullable<import("react").CSSProperties["height"]>;
|
|
144
|
+
} | {
|
|
145
|
+
sizingMode: "fill" | "auto";
|
|
146
|
+
height?: never;
|
|
147
|
+
} | {
|
|
148
|
+
sizingMode?: undefined;
|
|
149
|
+
height?: import("react").CSSProperties["height"];
|
|
150
|
+
});
|
|
116
151
|
/**
|
|
117
152
|
* Pre-resolved presentation (classes and inline styles) for a column data body.
|
|
118
153
|
* Evaluated once per column across the dataset, then applied to each rendered cell in O(1).
|
|
@@ -125,3 +160,4 @@ export interface ResolvedColumnPresentation {
|
|
|
125
160
|
/** Combined inline styles for the column body. */
|
|
126
161
|
style: import("@omnigrid/core").ColumnStyle;
|
|
127
162
|
}
|
|
163
|
+
export {};
|
package/dist/useGrid.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isColumnGroup } from '@omnigrid/core';
|
|
1
|
+
import { inferColumns, isColumnGroup } from '@omnigrid/core';
|
|
2
2
|
import { Grid } from '@omnigrid/core';
|
|
3
3
|
import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react';
|
|
4
4
|
/**
|
|
@@ -29,6 +29,12 @@ export function useGrid(options) {
|
|
|
29
29
|
const subscribe = useCallback((listener) => grid.subscribe(listener), [grid]);
|
|
30
30
|
const getSnapshot = useCallback(() => grid.getState(), [grid]);
|
|
31
31
|
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
32
|
+
const autoColumnIdsRef = useRef(new Set());
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (options.columns !== undefined || autoColumnIdsRef.current.size > 0 || state.data.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
autoColumnIdsRef.current = new Set(inferColumns(state.data, options.getColumnHeader).map((column) => column.id));
|
|
37
|
+
}, [options.columns, options.getColumnHeader, state.data]);
|
|
32
38
|
// Reconcile plugins when the plugin list changes. Plugins removed from the
|
|
33
39
|
// list are unregistered (their cleanup restores default behavior); new ones
|
|
34
40
|
// are registered. Declared before the data sync so that, on a switch, the
|
|
@@ -62,8 +68,8 @@ export function useGrid(options) {
|
|
|
62
68
|
// Sync columns when the columns reference changes (e.g. dynamic column
|
|
63
69
|
// definitions). Skip on the first run — plugins may have prepended
|
|
64
70
|
// selection/sorting columns during registerPlugin() in the Grid
|
|
65
|
-
// constructor, and calling setColumns here would overwrite those
|
|
66
|
-
// columns. Only sync on subsequent changes to options.columns.
|
|
71
|
+
// constructor, and calling grid.setColumns here would overwrite those
|
|
72
|
+
// injected columns. Only sync on subsequent changes to options.columns.
|
|
67
73
|
//
|
|
68
74
|
// StrictMode note: `options.columns` is a new array reference on every
|
|
69
75
|
// render, but its entries are usually the same column objects (a new
|
|
@@ -89,6 +95,7 @@ export function useGrid(options) {
|
|
|
89
95
|
const columnsChanged = prev.length !== next.length || prev.some((column, index) => column !== next[index]);
|
|
90
96
|
const defaultColumnDefChanged = lastSyncedDefaultColumnDefRef.current !== options.defaultColumnDef;
|
|
91
97
|
if (columnsChanged || defaultColumnDefChanged) {
|
|
98
|
+
const previousColumnsWereAuto = lastSyncedColumnsRef.current === undefined;
|
|
92
99
|
lastSyncedColumnsRef.current = options.columns;
|
|
93
100
|
lastSyncedDefaultColumnDefRef.current = options.defaultColumnDef;
|
|
94
101
|
// Merge the user's column definitions into the current (plugin-enriched)
|
|
@@ -97,6 +104,11 @@ export function useGrid(options) {
|
|
|
97
104
|
// not part of the user's column definitions; replacing columns with the
|
|
98
105
|
// raw definitions would strip them and break e.g. column resize handles.
|
|
99
106
|
const current = grid.getState().columns;
|
|
107
|
+
const autoColumnIds = previousColumnsWereAuto && options.columns !== undefined
|
|
108
|
+
? autoColumnIdsRef.current.size > 0
|
|
109
|
+
? autoColumnIdsRef.current
|
|
110
|
+
: new Set(inferColumns(grid.getState().data, options.getColumnHeader).map((column) => column.id))
|
|
111
|
+
: new Set();
|
|
100
112
|
// Merge the user's column definitions INTO the current (plugin-enriched)
|
|
101
113
|
// columns instead of replacing them wholesale. Iterating over `current`
|
|
102
114
|
// preserves plugin-injected columns (e.g. the selection column prepended
|
|
@@ -111,7 +123,8 @@ export function useGrid(options) {
|
|
|
111
123
|
current.forEach((currentColumn) => {
|
|
112
124
|
const userColumn = next.find((c) => c.id === currentColumn.id);
|
|
113
125
|
if (!userColumn) {
|
|
114
|
-
|
|
126
|
+
if (!autoColumnIds.has(currentColumn.id))
|
|
127
|
+
merged.push(currentColumn);
|
|
115
128
|
return;
|
|
116
129
|
}
|
|
117
130
|
const enriched = { ...userColumn };
|