@omnigrid/react 0.1.38 → 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.
@@ -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-window changes (header only).
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
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-window changes (header only).
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
@@ -127,7 +126,7 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
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 columnWindowKeyRef = useRef("");
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, height, sizingMode: sizingModeProp,
142
141
  }
143
142
  const layers = layersRef.current;
144
143
  const layerContextRef = useRef(null);
145
- // `columnWindowVersion` is a simple counter that increments each time the
146
- // horizontal column window changes (i.e., when scrollLeft crosses a
147
- // column boundary). It exists solely to trigger a targeted React re-render
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
@@ -201,8 +198,8 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
201
198
  * Keeps the spacer height and visible row-layer height in sync without
202
199
  * re-rendering the grid for every measured row.
203
200
  */
204
- const applyContentHeight = (totalHeight) => {
205
- const layerHeight = `${autoHeight ? totalHeight : Math.max(0, state.viewport.height - headerHeight)}px`;
201
+ const applyContentHeight = (totalHeight, viewportHeight) => {
202
+ const layerHeight = `${autoHeight ? totalHeight : Math.max(0, viewportHeight - headerHeight)}px`;
206
203
  for (const ref of [rowsLayerRef, pinnedLeftRowsLayerRef, pinnedRightRowsLayerRef]) {
207
204
  const element = ref.current;
208
205
  if (element && element.style.height !== layerHeight)
@@ -821,7 +818,7 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
821
818
  const state = grid.getState();
822
819
  const processed = getPoolData(grid);
823
820
  const processedChanged = layer.processed !== processed;
824
- const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || processedChanged;
821
+ const changed = layer.revision !== grid.getRevision() || processedChanged;
825
822
  const shouldAnimate = Boolean(options.animateRows && layer.processed !== null && processedChanged);
826
823
  const animationPositions = shouldAnimate
827
824
  ? new Map(layer.panes.flatMap((pane) => {
@@ -831,7 +828,6 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
831
828
  : null;
832
829
  if (changed) {
833
830
  layer.revision = grid.getRevision();
834
- layer.totalWidth = viewportData.totalWidth;
835
831
  layer.processed = processed;
836
832
  pool.invalidate();
837
833
  }
@@ -847,11 +843,19 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
847
843
  visibleRowRange: viewportData.visibleRowRange,
848
844
  rowWidth: layer.rowWidth,
849
845
  });
850
- for (const pane of layer.panes) {
851
- const row = pane.getRow();
852
- if (!row)
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)
853
852
  continue;
854
- const offsetY = Math.round(row.offsetY - layer.scrollTop);
853
+ const rowIndex = Number(rowIndexValue);
854
+ const rangeIndex = rowIndex - viewportData.rowRange.start;
855
+ const rowOffset = viewportData.rows[rangeIndex]?.offset;
856
+ if (rowOffset === undefined)
857
+ continue;
858
+ const offsetY = Math.round(rowOffset - layer.scrollTop);
855
859
  if (pane.getOffsetY() !== offsetY)
856
860
  pane.setOffsetY(offsetY);
857
861
  }
@@ -873,7 +877,7 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
873
877
  // It is written imperatively: a Store notification per measured row
874
878
  // would re-render the whole grid, and the grid would then lag behind
875
879
  // the native scroll position (the user sees the previous rows).
876
- applyContentHeight(currentViewportData.totalHeight);
880
+ applyContentHeight(currentViewportData.totalHeight, state.viewport.height);
877
881
  const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
878
882
  const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
879
883
  const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
@@ -908,28 +912,43 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
908
912
  else {
909
913
  bindLayers();
910
914
  }
911
- // The horizontal column window changes infrequently (only when
912
- // crossing column boundaries). When it does, update central row cells
913
- // imperatively AND trigger a targeted React re-render for the header.
914
- // Pinned panes hold all their columns at once — they only rebind via
915
- // the structural path above (revision bump).
916
- //
917
- const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
918
- if (columnWindowKey !== columnWindowKeyRef.current) {
919
- columnWindowKeyRef.current = columnWindowKey;
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;
920
931
  const updateColumnWindow = () => {
921
- // Span-aware: each pane resolves its own row's layout so
922
- // merged cells keep their summed width while the window
923
- // slides — covered leaves stay parked off-screen.
924
- for (const pane of layers.central.panes) {
925
- const paneRow = pane.getRow();
926
- if (!paneRow) {
927
- pane.updateColumns(layers.central.columns, layers.central.originX, null);
928
- continue;
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);
929
947
  }
930
- const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
931
- pane.updateColumns(layers.central.columns, layers.central.originX, sliceSpanLayoutForLayer(currentViewportData, layers.central.columns, true, spans.central));
932
- }
948
+ };
949
+ updateLayerColumns(layers.left, leftGeometryKey, false);
950
+ updateLayerColumns(layers.central, centralGeometryKey, true);
951
+ updateLayerColumns(layers.right, rightGeometryKey, false);
933
952
  setColumnWindowVersion((v) => v + 1);
934
953
  };
935
954
  if (synchronousColumnWindow) {
@@ -967,22 +986,24 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
967
986
  scrollbarWidthRef.current = scrollbarWidth;
968
987
  const width = element.clientWidth;
969
988
  const height = element.clientHeight;
970
- if (width === 0) {
989
+ if (width === 0 || height <= headerHeight) {
971
990
  // Layout may not be computed yet on the first paint. Retry on the
972
- // next animation frame so flex columns are sized against the real
973
- // client width instead of collapsing to minWidth at width === 0.
974
- requestAnimationFrame(() => {
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;
975
996
  measureViewport();
976
997
  });
977
998
  return;
978
999
  }
979
1000
  grid.setViewport({
980
1001
  width,
981
- ...(height > 0 ? { height } : {}),
1002
+ height,
982
1003
  });
983
1004
  syncPoolRef.current?.(false);
984
1005
  setIsViewportMeasured(true);
985
- }, [grid, syncScrollbarInsets, setIsViewportMeasured]);
1006
+ }, [grid, headerHeight, syncScrollbarInsets, setIsViewportMeasured]);
986
1007
  useEffect(() => {
987
1008
  const element = viewportRef.current;
988
1009
  if (!element)
@@ -996,7 +1017,7 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
996
1017
  scrollbarWidthRef.current = scrollbarWidth;
997
1018
  const width = element.clientWidth;
998
1019
  const height = element.clientHeight;
999
- if (width === 0 || height === 0)
1020
+ if (width === 0 || height <= headerHeight)
1000
1021
  return;
1001
1022
  grid.setViewport({ width, height });
1002
1023
  syncPoolRef.current?.(false);
@@ -1037,6 +1058,16 @@ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp,
1037
1058
  });
1038
1059
  return unsubscribe;
1039
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]);
1040
1071
  useEffect(() => () => {
1041
1072
  if (anchorTimerRef.current !== null)
1042
1073
  window.clearTimeout(anchorTimerRef.current);
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",