@omnigrid/react 0.1.24 → 0.1.25
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/OmniGrid.d.ts +10 -0
- package/dist/OmniGrid.js +76 -14
- package/dist/pooledRow.js +10 -0
- package/package.json +1 -1
package/dist/OmniGrid.d.ts
CHANGED
|
@@ -12,6 +12,16 @@ type OverlayComponent<T> = ComponentType<CoreOverlayComponentProps<T>> | CoreOve
|
|
|
12
12
|
export interface GridProps<T> extends Omit<GridOptions<T>, "overlayComponents"> {
|
|
13
13
|
className?: string;
|
|
14
14
|
style?: CSSProperties;
|
|
15
|
+
/**
|
|
16
|
+
* Minimum grid height in rows when `style.height` is not set (auto-height
|
|
17
|
+
* mode). The viewport will be at least `headerHeight + minHeight *
|
|
18
|
+
* rowHeight` tall so the grid does not collapse when it has few or no
|
|
19
|
+
* rows. Set to `0` to disable.
|
|
20
|
+
*
|
|
21
|
+
* @api
|
|
22
|
+
* @default 3
|
|
23
|
+
*/
|
|
24
|
+
minHeight?: number;
|
|
15
25
|
slotComponents?: SlotRendererRegistry<T>;
|
|
16
26
|
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
17
27
|
}
|
package/dist/OmniGrid.js
CHANGED
|
@@ -97,6 +97,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
97
97
|
const pendingHeightCorrectionRef = useRef(0);
|
|
98
98
|
/** rAF handle of the scheduled row-height flush. */
|
|
99
99
|
const heightFlushRef = useRef(null);
|
|
100
|
+
/** Latest `syncPool` — read imperatively from `measureViewport`/ResizeObserver so the callback stays stable. */
|
|
101
|
+
const syncPoolRef = useRef(null);
|
|
100
102
|
/**
|
|
101
103
|
* Scrollable content height frozen at the start of a user scroll gesture.
|
|
102
104
|
*
|
|
@@ -131,6 +133,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
131
133
|
// of the header — row DOM nodes remain managed by the DomPool and are
|
|
132
134
|
// never touched by React's reconciliation.
|
|
133
135
|
const [, setColumnWindowVersion] = useState(0);
|
|
136
|
+
/** Set to `true` once the viewport dimensions have been measured against
|
|
137
|
+
* the real DOM element. Before that the grid content is hidden so the
|
|
138
|
+
* user never sees flex columns collapsed to minWidth at width === 0. */
|
|
139
|
+
const [isViewportMeasured, setIsViewportMeasured] = useState(false);
|
|
134
140
|
optionsRef.current = options;
|
|
135
141
|
slotComponentsRef.current = slotComponents ?? {};
|
|
136
142
|
// Memoized render context for header cells, group cells, and slot content.
|
|
@@ -152,6 +158,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
152
158
|
const headerRowCount = viewportData.headerRowCount;
|
|
153
159
|
const hasGroups = headerRowCount > 0;
|
|
154
160
|
const headerHeight = (headerRowCount + 1) * rowHeight;
|
|
161
|
+
const minHeightRows = options.minHeight ?? 3;
|
|
162
|
+
const minViewportHeight = autoHeight ? headerHeight + minHeightRows * rowHeight : 0;
|
|
155
163
|
/**
|
|
156
164
|
* Writes the scrollable content height (and the height of the row
|
|
157
165
|
* layers) into the DOM.
|
|
@@ -199,9 +207,20 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
199
207
|
*/
|
|
200
208
|
const measuredHeight = viewportData.totalHeight + headerHeight;
|
|
201
209
|
const hasVerticalOverflow = !autoHeight && measuredHeight > state.viewport.height;
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
// Use "auto" instead of "stable" so the viewport does not reserve space for
|
|
211
|
+
// a vertical scrollbar before it actually appears. With "stable" the header
|
|
212
|
+
// container is drawn narrower than full width on first render, then jumps
|
|
213
|
+
// when the scrollbar materializes. "auto" keeps the header full width and
|
|
214
|
+
// only cedes space to the scrollbar once it is really needed.
|
|
215
|
+
const verticalScrollbarGutter = "auto";
|
|
204
216
|
const suppressRowHoverHighlight = options.suppressRowHoverHighlight ?? false;
|
|
217
|
+
const cellFlashRaw = options.cellFlash;
|
|
218
|
+
const cellFlashDurationMs = cellFlashRaw === true ? 1000 : typeof cellFlashRaw === "number" && cellFlashRaw > 0 ? cellFlashRaw : false;
|
|
219
|
+
const viewportStyle = {
|
|
220
|
+
...style,
|
|
221
|
+
height: autoHeight ? measuredHeight : style?.height,
|
|
222
|
+
...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
|
|
223
|
+
};
|
|
205
224
|
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null].filter(Boolean).join(" ");
|
|
206
225
|
const overlayState = state.overlay;
|
|
207
226
|
const filterModelSnapshot = grid.getFilterModel();
|
|
@@ -550,12 +569,36 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
550
569
|
return (currentOptions.plugins ?? []).reduce((styleAcc, plugin) => ({ ...styleAcc, ...(plugin.getRowStyle?.(rowParams) ?? {}) }), baseRowStyle);
|
|
551
570
|
},
|
|
552
571
|
resolveCellClasses: (info) => {
|
|
553
|
-
const
|
|
572
|
+
const flashedCells = grid.getState().flashedCells;
|
|
573
|
+
const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
574
|
+
const isFlashed = cellFlashDurationMs !== false && flashTimestamp !== undefined && Date.now() - flashTimestamp <= cellFlashDurationMs;
|
|
575
|
+
const cellParams = {
|
|
576
|
+
id: info.rowId,
|
|
577
|
+
index: info.rowIndex,
|
|
578
|
+
data: info.data,
|
|
579
|
+
column: info.column,
|
|
580
|
+
isFlashed,
|
|
581
|
+
flashTimestamp,
|
|
582
|
+
};
|
|
554
583
|
const columnPresentation = getColumnPresentation(info.column);
|
|
555
|
-
|
|
584
|
+
let classes = resolveCellClasses(info.column, cellParams, columnPresentation.classes);
|
|
585
|
+
if (isFlashed) {
|
|
586
|
+
classes = classes ? `${classes} omnigrid-cell-flashed` : "omnigrid-cell-flashed";
|
|
587
|
+
}
|
|
588
|
+
return classes;
|
|
556
589
|
},
|
|
557
590
|
resolveCellStyle: (info) => {
|
|
558
|
-
const
|
|
591
|
+
const flashedCells = grid.getState().flashedCells;
|
|
592
|
+
const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
593
|
+
const isFlashed = cellFlashDurationMs !== false && flashTimestamp !== undefined && Date.now() - flashTimestamp <= cellFlashDurationMs;
|
|
594
|
+
const cellParams = {
|
|
595
|
+
id: info.rowId,
|
|
596
|
+
index: info.rowIndex,
|
|
597
|
+
data: info.data,
|
|
598
|
+
column: info.column,
|
|
599
|
+
isFlashed,
|
|
600
|
+
flashTimestamp,
|
|
601
|
+
};
|
|
559
602
|
const columnPresentation = getColumnPresentation(info.column);
|
|
560
603
|
return resolveCellStyle(info.column, cellParams, columnPresentation.style);
|
|
561
604
|
},
|
|
@@ -809,6 +852,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
809
852
|
}
|
|
810
853
|
}
|
|
811
854
|
};
|
|
855
|
+
syncPoolRef.current = syncPool;
|
|
812
856
|
/**
|
|
813
857
|
* Measures viewport dimensions from the DOM and syncs them to the core.
|
|
814
858
|
* Called on mount and on ResizeObserver events.
|
|
@@ -833,10 +877,22 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
833
877
|
scrollbarWidthRef.current = scrollbarWidth;
|
|
834
878
|
const width = element.clientWidth;
|
|
835
879
|
const height = element.clientHeight;
|
|
836
|
-
if (width === 0
|
|
880
|
+
if (width === 0) {
|
|
881
|
+
// Layout may not be computed yet on the first paint. Retry on the
|
|
882
|
+
// next animation frame so flex columns are sized against the real
|
|
883
|
+
// client width instead of collapsing to minWidth at width === 0.
|
|
884
|
+
requestAnimationFrame(() => {
|
|
885
|
+
measureViewport();
|
|
886
|
+
});
|
|
837
887
|
return;
|
|
838
|
-
|
|
839
|
-
|
|
888
|
+
}
|
|
889
|
+
grid.setViewport({
|
|
890
|
+
width,
|
|
891
|
+
...(height > 0 ? { height } : {}),
|
|
892
|
+
});
|
|
893
|
+
syncPoolRef.current?.(false, false);
|
|
894
|
+
setIsViewportMeasured(true);
|
|
895
|
+
}, [grid, syncScrollbarInsets, setIsViewportMeasured]);
|
|
840
896
|
useEffect(() => {
|
|
841
897
|
const element = viewportRef.current;
|
|
842
898
|
if (!element)
|
|
@@ -853,11 +909,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
853
909
|
if (width === 0 || height === 0)
|
|
854
910
|
return;
|
|
855
911
|
grid.setViewport({ width, height });
|
|
912
|
+
syncPoolRef.current?.(false, false);
|
|
913
|
+
setIsViewportMeasured(true);
|
|
856
914
|
});
|
|
857
915
|
observer.observe(element, { box: "content-box" });
|
|
858
916
|
measureViewport();
|
|
859
917
|
return () => observer.disconnect();
|
|
860
|
-
}, [grid, measureViewport, syncScrollbarInsets]);
|
|
918
|
+
}, [grid, measureViewport, syncScrollbarInsets, setIsViewportMeasured]);
|
|
861
919
|
// Scrollbars can appear or disappear when the CONTENT size changes (the
|
|
862
920
|
// rows are measured, a column is resized). Measuring the insets after
|
|
863
921
|
// EVERY render forces a synchronous layout of the whole page — during a
|
|
@@ -872,10 +930,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
872
930
|
syncScrollbarInsets(viewportRef.current);
|
|
873
931
|
}, [contentSizeKey]);
|
|
874
932
|
useLayoutEffect(() => {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
//
|
|
878
|
-
//
|
|
933
|
+
// Measure the viewport on mount so flex column widths are computed
|
|
934
|
+
// against the real client width before the first paint. Without this
|
|
935
|
+
// the header cells render with viewport.width === 0 (flex columns fall
|
|
936
|
+
// back to minWidth) and only snap to the correct size after the
|
|
937
|
+
// ResizeObserver-driven useEffect runs — a visible flash on first load.
|
|
879
938
|
measureViewport();
|
|
880
939
|
}, [autoHeight, hasVerticalOverflow, measureViewport, overlayScope]);
|
|
881
940
|
useEffect(() => {
|
|
@@ -1102,6 +1161,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1102
1161
|
top: fullHeight ? -(gapRows * rowHeight) : 0,
|
|
1103
1162
|
bottom: 0,
|
|
1104
1163
|
touchAction: "none",
|
|
1164
|
+
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1105
1165
|
width: item.width,
|
|
1106
1166
|
};
|
|
1107
1167
|
return (_jsx("div", { role: "columnheader", className: className, "data-sort": item.column.sortState, "data-sort-index": item.column.sortIndex, "data-sortable": item.column.sortable === true ? "true" : undefined, "aria-sort": item.column.sortState === "asc" ? "ascending" : item.column.sortState === "desc" ? "descending" : "none", onClick: (event) => item.column.stopHeaderClick
|
|
@@ -1148,6 +1208,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1148
1208
|
left: Math.round(segment.left),
|
|
1149
1209
|
top: 0,
|
|
1150
1210
|
bottom: 0,
|
|
1211
|
+
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1151
1212
|
width: segment.width,
|
|
1152
1213
|
};
|
|
1153
1214
|
return (_jsx("div", { role: "columnheader", className: className, "aria-colspan": segment.columnCount, title: segment.group.header ?? segment.group.id, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
|
|
@@ -1191,6 +1252,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1191
1252
|
overflow: "hidden",
|
|
1192
1253
|
position: "absolute",
|
|
1193
1254
|
top: headerHeight,
|
|
1255
|
+
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1194
1256
|
width,
|
|
1195
1257
|
} }));
|
|
1196
1258
|
return (_jsxs("div", { className: "omnigrid-layout", ref: layoutRef, style: { ...style, position: "relative", ...(isFullOverlay ? { overflow: "hidden" } : {}) }, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { className: "omnigrid-viewport-container", style: {
|
|
@@ -1203,7 +1265,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1203
1265
|
...viewportStyle,
|
|
1204
1266
|
flex: "1 1 0",
|
|
1205
1267
|
height: autoHeight ? measuredHeight : "100%",
|
|
1206
|
-
minHeight:
|
|
1268
|
+
minHeight: minViewportHeight,
|
|
1207
1269
|
minWidth: 0,
|
|
1208
1270
|
overflowX: overlayBlocksHorizontalScroll ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
|
|
1209
1271
|
overflowY: overlayScope || autoHeight ? "hidden" : "auto",
|
package/dist/pooledRow.js
CHANGED
|
@@ -328,6 +328,16 @@ export class PooledRowPane {
|
|
|
328
328
|
}
|
|
329
329
|
applyCellPresentation(cell, cellInfo) {
|
|
330
330
|
const cellClasses = this.callbacks.resolveCellClasses(cellInfo);
|
|
331
|
+
// When a cell is re-flashed, the CSS class is the same
|
|
332
|
+
// (omnigrid-cell-flashed) so the selector matches continuously and
|
|
333
|
+
// the browser does not restart the animation. Reset it imperatively:
|
|
334
|
+
// remove the flash class, force a reflow, then apply the new one.
|
|
335
|
+
const hasFlashClass = cell.element.classList.contains("omnigrid-cell-flashed");
|
|
336
|
+
const nextHasFlashClass = /omnigrid-cell-flashed/.test(cellClasses ?? "");
|
|
337
|
+
if (hasFlashClass && nextHasFlashClass) {
|
|
338
|
+
cell.element.classList.remove("omnigrid-cell-flashed");
|
|
339
|
+
cell.element.offsetHeight; // force reflow
|
|
340
|
+
}
|
|
331
341
|
cell.element.className = cellClasses ?? "";
|
|
332
342
|
for (const key of cell.appliedStyleKeys)
|
|
333
343
|
cell.element.style.removeProperty(cssPropertyName(key));
|