@omnigrid/react 0.1.36 → 0.1.37
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 +9 -5
- package/dist/OmniGrid.js +57 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,11 +27,15 @@ positions. Row animation uses a separate CSS transform component, so virtualized
|
|
|
27
27
|
positioning and scrolling remain independent. It is disabled by default; provide
|
|
28
28
|
a stable `getRowId` to animate rows reliably across reorderings.
|
|
29
29
|
|
|
30
|
-
During
|
|
31
|
-
|
|
32
|
-
the
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
During vertical scrolling, a viewport-sized sticky row layer is kept separate
|
|
31
|
+
from the full-height spacer that provides the native scrollbar range. This
|
|
32
|
+
keeps the last painted rows visible until the adapter synchronizes the pool,
|
|
33
|
+
avoiding blank frames while the browser processes a fast scrollbar drag. Large
|
|
34
|
+
jumps and transitions into fast scrolling synchronize immediately; ordinary
|
|
35
|
+
scroll events remain frame-coalesced. `rowOverscan` controls the rendered row
|
|
36
|
+
buffer, but cannot pre-render an arbitrary destination on a 100,000-row grid.
|
|
37
|
+
The core tracks live scroll position without store notifications or
|
|
38
|
+
scroll-driven React renders.
|
|
35
39
|
|
|
36
40
|
Column `headerRenderer` callbacks provide the header's primary content. The adapter owns the
|
|
37
41
|
shared header layout and keeps sorting, filtering, and registered plugin extensions alongside it,
|
package/dist/OmniGrid.js
CHANGED
|
@@ -31,6 +31,8 @@ const SLOT_POSITIONS = ["start", "center", "end"];
|
|
|
31
31
|
* deferred, so they cannot fight active user input.
|
|
32
32
|
*/
|
|
33
33
|
const SCROLL_IDLE_WINDOW = 150;
|
|
34
|
+
/** Speed in pixels per millisecond at which scroll updates are committed synchronously. */
|
|
35
|
+
const FAST_SCROLL_VELOCITY = 2;
|
|
34
36
|
const COLUMN_DRAG_TYPE = "application/x-omnigrid-column";
|
|
35
37
|
function createRowLayerState() {
|
|
36
38
|
return {
|
|
@@ -44,6 +46,7 @@ function createRowLayerState() {
|
|
|
44
46
|
processed: null,
|
|
45
47
|
originX: 0,
|
|
46
48
|
rowWidth: 0,
|
|
49
|
+
scrollTop: 0,
|
|
47
50
|
animationPositions: null,
|
|
48
51
|
viewport: null,
|
|
49
52
|
};
|
|
@@ -103,6 +106,12 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
103
106
|
top: 0,
|
|
104
107
|
left: 0,
|
|
105
108
|
});
|
|
109
|
+
const scrollSampleRef = useRef({
|
|
110
|
+
top: 0,
|
|
111
|
+
left: 0,
|
|
112
|
+
time: 0,
|
|
113
|
+
velocity: 0,
|
|
114
|
+
});
|
|
106
115
|
/** Timestamp of the last scroll event, used to defer row-height anchoring until idle. */
|
|
107
116
|
const lastScrollTimeRef = useRef(0);
|
|
108
117
|
/** Anchoring correction accumulated while the user is scrolling. */
|
|
@@ -181,17 +190,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
181
190
|
const minHeightRows = options.minHeight ?? 3;
|
|
182
191
|
const minViewportHeight = autoHeight ? headerHeight + minHeightRows * rowHeight : 0;
|
|
183
192
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* The total height changes with every measured row. Writing it through
|
|
188
|
-
* React would re-render the whole grid per measurement — during a fast
|
|
189
|
-
* scroll that starves the frame budget and the grid lags behind the
|
|
190
|
-
* native scroll position. The imperative write keeps the scroll range
|
|
191
|
-
* correct without a re-render.
|
|
193
|
+
* Keeps the spacer height and visible row-layer height in sync without
|
|
194
|
+
* re-rendering the grid for every measured row.
|
|
192
195
|
*/
|
|
193
196
|
const applyContentHeight = (totalHeight) => {
|
|
194
|
-
const layerHeight = `${totalHeight}px`;
|
|
197
|
+
const layerHeight = `${autoHeight ? totalHeight : Math.max(0, state.viewport.height - headerHeight)}px`;
|
|
195
198
|
for (const ref of [rowsLayerRef, pinnedLeftRowsLayerRef, pinnedRightRowsLayerRef]) {
|
|
196
199
|
const element = ref.current;
|
|
197
200
|
if (element && element.style.height !== layerHeight)
|
|
@@ -784,7 +787,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
784
787
|
transformRow: (host, offsetY) => {
|
|
785
788
|
const pane = paneMap.get(host);
|
|
786
789
|
if (pane)
|
|
787
|
-
pane.setOffsetY(offsetY);
|
|
790
|
+
pane.setOffsetY(offsetY - layer.scrollTop);
|
|
788
791
|
},
|
|
789
792
|
recycleRow: (host) => {
|
|
790
793
|
const pane = paneMap.get(host);
|
|
@@ -837,6 +840,14 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
837
840
|
visibleRowRange: viewportData.visibleRowRange,
|
|
838
841
|
rowWidth: layer.rowWidth,
|
|
839
842
|
});
|
|
843
|
+
for (const pane of layer.panes) {
|
|
844
|
+
const row = pane.getRow();
|
|
845
|
+
if (!row)
|
|
846
|
+
continue;
|
|
847
|
+
const offsetY = Math.round(row.offsetY - layer.scrollTop);
|
|
848
|
+
if (pane.getOffsetY() !== offsetY)
|
|
849
|
+
pane.setOffsetY(offsetY);
|
|
850
|
+
}
|
|
840
851
|
layer.animationPositions = null;
|
|
841
852
|
};
|
|
842
853
|
/**
|
|
@@ -859,18 +870,22 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
859
870
|
const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
860
871
|
const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
861
872
|
const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
873
|
+
const scrollTop = grid.getScrollPosition().scrollTop;
|
|
862
874
|
// Configure each layer: which columns it renders, the table-space origin
|
|
863
875
|
// of its coordinate system (subtracted from core offsets), and the pixel
|
|
864
876
|
// width of its row hosts.
|
|
865
877
|
layers.left.columns = currentViewportData.pinnedLeftColumns;
|
|
866
878
|
layers.left.originX = 0;
|
|
867
879
|
layers.left.rowWidth = pinnedLeftWidth;
|
|
880
|
+
layers.left.scrollTop = scrollTop;
|
|
868
881
|
layers.central.columns = currentViewportData.columns;
|
|
869
882
|
layers.central.originX = pinnedLeftWidth;
|
|
870
883
|
layers.central.rowWidth = Math.max(scrollableWidth, state.viewport.width - pinnedLeftWidth - pinnedRightWidth);
|
|
884
|
+
layers.central.scrollTop = scrollTop;
|
|
871
885
|
layers.right.columns = currentViewportData.pinnedRightColumns;
|
|
872
886
|
layers.right.originX = pinnedLeftWidth + scrollableWidth;
|
|
873
887
|
layers.right.rowWidth = pinnedRightWidth;
|
|
888
|
+
layers.right.scrollTop = scrollTop;
|
|
874
889
|
// Cell content rendering (root.render) is async under React concurrent
|
|
875
890
|
// mode — without flushSync, rows are repositioned but their cell content
|
|
876
891
|
// stays stale for one frame. Wrap only the DOM binding in flushSync so
|
|
@@ -1075,12 +1090,27 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1075
1090
|
pinnedRightRowsLayerRef.current?.replaceChildren();
|
|
1076
1091
|
};
|
|
1077
1092
|
}, []);
|
|
1093
|
+
const syncScrollPosition = (scrollTop, scrollLeft) => {
|
|
1094
|
+
grid.setViewport({ scrollTop, scrollLeft });
|
|
1095
|
+
if (!isScrollActive() && pendingAnchorRef.current !== 0) {
|
|
1096
|
+
// The scroll settled — the deferred anchoring correction can be
|
|
1097
|
+
// applied now without fighting the user's input.
|
|
1098
|
+
flushPendingAnchor();
|
|
1099
|
+
}
|
|
1100
|
+
syncPoolRef.current?.(true);
|
|
1101
|
+
};
|
|
1078
1102
|
const handleScroll = (event) => {
|
|
1079
1103
|
const element = event.currentTarget;
|
|
1080
1104
|
const frame = scrollFrameRef.current;
|
|
1081
1105
|
frame.top = element.scrollTop;
|
|
1082
1106
|
frame.left = element.scrollLeft;
|
|
1083
|
-
|
|
1107
|
+
const now = performance.now();
|
|
1108
|
+
const previousSample = scrollSampleRef.current;
|
|
1109
|
+
const elapsed = Math.max(1, now - previousSample.time);
|
|
1110
|
+
const velocity = Math.max(Math.abs(element.scrollTop - previousSample.top), Math.abs(element.scrollLeft - previousSample.left)) / elapsed;
|
|
1111
|
+
const enteredFastScroll = velocity >= FAST_SCROLL_VELOCITY && previousSample.velocity < FAST_SCROLL_VELOCITY;
|
|
1112
|
+
scrollSampleRef.current = { top: element.scrollTop, left: element.scrollLeft, time: now, velocity };
|
|
1113
|
+
lastScrollTimeRef.current = now;
|
|
1084
1114
|
if (options.animateRows) {
|
|
1085
1115
|
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1086
1116
|
for (const pane of layer.panes)
|
|
@@ -1092,6 +1122,17 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1092
1122
|
// scroll event fires several times per frame during a thumb drag.
|
|
1093
1123
|
// The ResizeObserver reports the content box size instead — it fires
|
|
1094
1124
|
// exactly when the scrollbar appears or disappears.
|
|
1125
|
+
const scrollPosition = grid.getScrollPosition();
|
|
1126
|
+
const largeVerticalJump = element.clientHeight > 0 && Math.abs(element.scrollTop - scrollPosition.scrollTop) >= element.clientHeight;
|
|
1127
|
+
const largeHorizontalJump = element.clientWidth > 0 && Math.abs(element.scrollLeft - scrollPosition.scrollLeft) >= element.clientWidth;
|
|
1128
|
+
if (largeVerticalJump || largeHorizontalJump || enteredFastScroll) {
|
|
1129
|
+
if (frame.id) {
|
|
1130
|
+
window.cancelAnimationFrame(frame.id);
|
|
1131
|
+
frame.id = 0;
|
|
1132
|
+
}
|
|
1133
|
+
syncScrollPosition(element.scrollTop, element.scrollLeft);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1095
1136
|
if (frame.id)
|
|
1096
1137
|
return;
|
|
1097
1138
|
frame.id = window.requestAnimationFrame(() => {
|
|
@@ -1102,18 +1143,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1102
1143
|
// always reflects the most recent scrollTop, even if the last
|
|
1103
1144
|
// onScroll event was at a different intermediate position.
|
|
1104
1145
|
const element = viewportRef.current;
|
|
1105
|
-
|
|
1106
|
-
const scrollLeft = element ? element.scrollLeft : frame.left;
|
|
1107
|
-
// setViewport with scroll-only updates does NOT notify the Store,
|
|
1108
|
-
// so this does NOT trigger a React re-render. The DomPool is
|
|
1109
|
-
// updated imperatively below.
|
|
1110
|
-
grid.setViewport({ scrollTop, scrollLeft });
|
|
1111
|
-
if (!isScrollActive() && pendingAnchorRef.current !== 0) {
|
|
1112
|
-
// The scroll settled — the deferred anchoring correction can be
|
|
1113
|
-
// applied now without fighting the user's input.
|
|
1114
|
-
flushPendingAnchor();
|
|
1115
|
-
}
|
|
1116
|
-
syncPool(true);
|
|
1146
|
+
syncScrollPosition(element ? element.scrollTop : frame.top, element ? element.scrollLeft : frame.left);
|
|
1117
1147
|
});
|
|
1118
1148
|
};
|
|
1119
1149
|
/** Resolves headless slot content into a ReactNode (see contentToReactNode). */
|
|
@@ -1426,13 +1456,12 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1426
1456
|
width: "100%",
|
|
1427
1457
|
}, children: renderHeaderCells(columns, originX) })] }) }));
|
|
1428
1458
|
const renderRowsLayer = (ref, width) => (_jsx("div", { ref: ref, "data-pool-layer": "true", style: {
|
|
1429
|
-
//
|
|
1430
|
-
//
|
|
1431
|
-
|
|
1432
|
-
height: viewportData.totalHeight,
|
|
1459
|
+
// This sticky paint layer stays viewport-sized; the scrollable
|
|
1460
|
+
// content wrapper provides the full height for the scrollbar.
|
|
1461
|
+
height: autoHeight ? viewportData.totalHeight : Math.max(0, state.viewport.height - headerHeight),
|
|
1433
1462
|
left: 0,
|
|
1434
1463
|
overflow: "hidden",
|
|
1435
|
-
position: "
|
|
1464
|
+
position: "sticky",
|
|
1436
1465
|
top: headerHeight,
|
|
1437
1466
|
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1438
1467
|
width,
|