@omnigrid/react 0.1.22 → 0.1.24

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.js CHANGED
@@ -19,6 +19,19 @@ function getCellValue(row, column) {
19
19
  return undefined;
20
20
  }
21
21
  const SLOT_POSITIONS = ["start", "center", "end"];
22
+ /**
23
+ * Scroll velocity (px/ms) above which a scroll is treated as "fast".
24
+ * Mouse wheel and trackpad scrolls typically range 0.05–0.2 px/ms, while
25
+ * scrollbar thumb drags and page jumps exceed 10 px/ms.
26
+ */
27
+ const FAST_SCROLL_VELOCITY = 2.0;
28
+ /**
29
+ * How long (ms) after the last processed scroll frame the fast-scroll state
30
+ * is kept. The velocity is only sampled on scroll frames, so it has to be
31
+ * aged out explicitly — otherwise a single fast flick would keep the grid in
32
+ * fast-scroll mode forever.
33
+ */
34
+ const FAST_SCROLL_WINDOW = 150;
22
35
  function createRowLayerState() {
23
36
  return {
24
37
  pool: null,
@@ -31,6 +44,7 @@ function createRowLayerState() {
31
44
  processed: null,
32
45
  originX: 0,
33
46
  rowWidth: 0,
47
+ viewport: null,
34
48
  };
35
49
  }
36
50
  /**
@@ -62,6 +76,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
62
76
  const { grid, state, viewportData } = useGrid(options);
63
77
  const viewportRef = useRef(null);
64
78
  const layoutRef = useRef(null);
79
+ /** Scrollable content wrapper — its height is the total height of all rows. */
80
+ const contentRef = useRef(null);
65
81
  const rowsLayerRef = useRef(null);
66
82
  const pinnedLeftRowsLayerRef = useRef(null);
67
83
  const pinnedRightRowsLayerRef = useRef(null);
@@ -69,8 +85,34 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
69
85
  const [scrollbarInsets, setScrollbarInsets] = useState({ right: 0, bottom: 0 });
70
86
  const scrollFrameRef = useRef({ id: 0, top: 0, left: 0, lastTop: 0, lastTime: 0 });
71
87
  const scrollVelocityRef = useRef(0);
88
+ /** Timestamp of the last processed scroll frame — used to age out the velocity. */
89
+ const lastScrollTimeRef = useRef(0);
90
+ /** Anchoring correction accumulated while a fast scroll was in progress. */
91
+ const pendingAnchorRef = useRef(0);
92
+ /** Timer that applies the accumulated anchoring correction after the scroll settles. */
93
+ const anchorTimerRef = useRef(null);
94
+ /** Number of row heights measured since the last geometry flush. */
95
+ const pendingHeightCountRef = useRef(0);
96
+ /** Anchoring correction of the row heights measured since the last flush. */
97
+ const pendingHeightCorrectionRef = useRef(0);
98
+ /** rAF handle of the scheduled row-height flush. */
99
+ const heightFlushRef = useRef(null);
100
+ /**
101
+ * Scrollable content height frozen at the start of a user scroll gesture.
102
+ *
103
+ * While the user drags the scrollbar thumb, measured row heights keep
104
+ * replacing estimates and `totalHeight` changes every frame. Rewriting the
105
+ * content height mid-drag makes the browser reposition the native
106
+ * scrollbar thumb (`scrollTop / (scrollHeight - clientHeight)`), so the
107
+ * thumb detaches from the mouse on the very first scroll of a
108
+ * variable-height grid. The height is therefore frozen to this snapshot
109
+ * for the duration of the gesture — row positions still use the measured
110
+ * offsets — and the real height is reapplied once the scroll settles.
111
+ */
72
112
  const optionsRef = useRef(options);
73
113
  const columnWindowKeyRef = useRef("");
114
+ /** Content size the scrollbar insets were measured for. */
115
+ const contentSizeKeyRef = useRef("");
74
116
  const scrollbarWidthRef = useRef(0);
75
117
  const slotComponentsRef = useRef({});
76
118
  const layersRef = useRef(null);
@@ -110,6 +152,37 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
110
152
  const headerRowCount = viewportData.headerRowCount;
111
153
  const hasGroups = headerRowCount > 0;
112
154
  const headerHeight = (headerRowCount + 1) * rowHeight;
155
+ /**
156
+ * Writes the scrollable content height (and the height of the row
157
+ * layers) into the DOM.
158
+ *
159
+ * The total height changes with every measured row. Writing it through
160
+ * React would re-render the whole grid per measurement — during a fast
161
+ * scroll that starves the frame budget and the grid lags behind the
162
+ * native scroll position. The imperative write keeps the scroll range
163
+ * correct without a re-render.
164
+ */
165
+ const applyContentHeight = (totalHeight) => {
166
+ const layerHeight = `${totalHeight}px`;
167
+ for (const ref of [rowsLayerRef, pinnedLeftRowsLayerRef, pinnedRightRowsLayerRef]) {
168
+ const element = ref.current;
169
+ if (element && element.style.height !== layerHeight)
170
+ element.style.height = layerHeight;
171
+ }
172
+ const contentHeight = `${totalHeight + headerHeight}px`;
173
+ const content = contentRef.current;
174
+ if (content && content.style.height !== contentHeight)
175
+ content.style.height = contentHeight;
176
+ if (autoHeight) {
177
+ // Auto-height grids grow with their content. React renders the
178
+ // height from the state, which is only updated on a re-render —
179
+ // the measured heights do not trigger one — so the viewport height
180
+ // is written here as well.
181
+ const viewport = viewportRef.current;
182
+ if (viewport && viewport.style.height !== contentHeight)
183
+ viewport.style.height = contentHeight;
184
+ }
185
+ };
113
186
  /**
114
187
  * For each leaf column, `columnGroupDepth` maps its flat visible index to the
115
188
  * deepest group depth that covers it.
@@ -317,11 +390,120 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
317
390
  columnPresentationCacheRef.current.set(column.id, { revision, data: processedData, presentation });
318
391
  return presentation;
319
392
  };
393
+ /**
394
+ * Whether the user is currently fast-scrolling.
395
+ *
396
+ * The velocity is sampled on scroll frames only, so it is aged out: when
397
+ * the last scroll frame is older than `FAST_SCROLL_WINDOW` the scroll has
398
+ * settled and the grid returns to its normal (fully bound) mode.
399
+ */
400
+ function isFastScrolling() {
401
+ if (scrollVelocityRef.current <= FAST_SCROLL_VELOCITY)
402
+ return false;
403
+ return performance.now() - lastScrollTimeRef.current < FAST_SCROLL_WINDOW;
404
+ }
405
+ /**
406
+ * Applies the anchoring corrections that were deferred during a fast scroll.
407
+ *
408
+ * A row ABOVE the viewport that changes its height shifts the content
409
+ * below it. While the user drags the scrollbar that correction fights the
410
+ * input (the scroll position jumps back and forth), so it is accumulated
411
+ * instead of applied. As soon as the scroll settles the accumulated offset
412
+ * is applied in one step — the anchored row stays where it was.
413
+ */
414
+ function flushPendingAnchor() {
415
+ anchorTimerRef.current = null;
416
+ const pending = pendingAnchorRef.current;
417
+ if (pending === 0)
418
+ return;
419
+ if (isFastScrolling()) {
420
+ // The user started scrolling again — the correction stays pending.
421
+ anchorTimerRef.current = window.setTimeout(flushPendingAnchor, FAST_SCROLL_WINDOW);
422
+ return;
423
+ }
424
+ pendingAnchorRef.current = 0;
425
+ const element = viewportRef.current;
426
+ const current = element ? element.scrollTop : grid.getScrollPosition().scrollTop;
427
+ grid.scrollTo({ scrollTop: Math.max(0, current + pending) });
428
+ }
429
+ /** Schedules the deferred anchoring flush after the scroll has settled. */
430
+ function scheduleAnchorFlush() {
431
+ if (anchorTimerRef.current !== null)
432
+ window.clearTimeout(anchorTimerRef.current);
433
+ anchorTimerRef.current = window.setTimeout(flushPendingAnchor, FAST_SCROLL_WINDOW);
434
+ }
435
+ /**
436
+ * Applies the row heights measured during the current frame.
437
+ *
438
+ * The measured heights are pushed into the virtualizer as soon as they
439
+ * arrive, but the DOM geometry is updated HERE — once per frame, after
440
+ * every measurement of the frame has been read.
441
+ *
442
+ * Measuring a row reads the DOM (`scrollHeight`), which forces a layout.
443
+ * A DOM write between two measurements invalidates that layout, so the
444
+ * next measurement forces it again: 30 measured rows would then cost 30
445
+ * full layouts of the grid (hundreds of milliseconds — the grid freezes
446
+ * for a second when the scrollbar thumb is dragged). Batching the writes
447
+ * keeps the cost at one layout per frame.
448
+ */
449
+ function flushPendingHeights() {
450
+ heightFlushRef.current = null;
451
+ const measured = pendingHeightCountRef.current;
452
+ if (measured === 0)
453
+ return;
454
+ pendingHeightCountRef.current = 0;
455
+ const fast = isFastScrolling();
456
+ const correction = pendingHeightCorrectionRef.current;
457
+ pendingHeightCorrectionRef.current = 0;
458
+ if (correction !== 0) {
459
+ if (fast) {
460
+ // The correction fights the user's input while they are
461
+ // scrolling — it is applied once the scroll settles.
462
+ pendingAnchorRef.current += correction;
463
+ scheduleAnchorFlush();
464
+ }
465
+ else {
466
+ const element = viewportRef.current;
467
+ const current = element ? element.scrollTop : grid.getScrollPosition().scrollTop;
468
+ grid.scrollTo({ scrollTop: Math.max(0, current + correction) });
469
+ }
470
+ }
471
+ // The measured heights changed the offsets of the rows below: push the
472
+ // new geometry into the pools.
473
+ syncPool(false, fast);
474
+ }
475
+ /** Schedules the row-height flush for the next frame. */
476
+ function scheduleHeightFlush() {
477
+ if (heightFlushRef.current !== null)
478
+ return;
479
+ heightFlushRef.current = window.requestAnimationFrame(flushPendingHeights);
480
+ }
320
481
  /** Row panel callbacks: close over grid/options, never over DOM. */
321
482
  function buildRowCallbacks(bridgeArg) {
322
483
  const current = () => optionsRef.current;
323
484
  return {
324
485
  rowHeight,
486
+ onRowHeightChange: (rowIndex, height) => {
487
+ // The measured height goes into the virtualizer right away —
488
+ // it does NOT touch the DOM, so the measurements of the
489
+ // current frame stay readable without a forced layout in
490
+ // between (see `flushPendingHeights`).
491
+ //
492
+ // `anchor: false` — the scroll anchoring correction is
493
+ // collected and applied in one step by the flush: applying it
494
+ // per measurement would move the scroll position several
495
+ // times per frame and fight the user's input.
496
+ //
497
+ // `notify: false` — the row heights are geometry, not grid
498
+ // state. A Store notification would re-render the whole grid
499
+ // (header included) for every measured row; the geometry is
500
+ // written to the DOM imperatively instead.
501
+ const correction = grid.setRowHeight(rowIndex, height, { anchor: false, notify: false });
502
+ if (correction !== 0)
503
+ pendingHeightCorrectionRef.current += correction;
504
+ pendingHeightCountRef.current += 1;
505
+ scheduleHeightFlush();
506
+ },
325
507
  renderCellContent: (info) => {
326
508
  const column = info.column;
327
509
  const value = getCellValue(info.data, column);
@@ -438,7 +620,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
438
620
  // widths come from the span origin's summed geometry and
439
621
  // covered leaves are skipped — no clipping or overlap when
440
622
  // a span crosses the virtual window boundary.
441
- const viewport = grid.getViewportData();
623
+ const viewport = layer.viewport;
624
+ if (!viewport)
625
+ return;
442
626
  const spans = getCachedRowSpans(viewport, row.data, row.index);
443
627
  const isLeft = layer === layers.left;
444
628
  const isRight = layer === layers.right;
@@ -449,6 +633,16 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
449
633
  const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
450
634
  pane.bind(row, layer.columns, layer.originX, sliced);
451
635
  },
636
+ resizeRow: (host, height) => {
637
+ const pane = paneMap.get(host);
638
+ if (pane)
639
+ pane.resize(height);
640
+ },
641
+ updateRowIndex: (host, rowIndex) => {
642
+ const pane = paneMap.get(host);
643
+ if (pane)
644
+ pane.setRowIndex(rowIndex);
645
+ },
452
646
  transformRow: (host, offsetY) => {
453
647
  const pane = paneMap.get(host);
454
648
  if (pane)
@@ -485,10 +679,15 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
485
679
  layer.processed = processed;
486
680
  pool.invalidate();
487
681
  }
682
+ // Cached for the row binds below — the viewport data of THIS sync.
683
+ layer.viewport = viewportData;
488
684
  pool.update({
489
685
  data: processed,
490
686
  rowRange: viewportData.rowRange,
491
687
  rowHeight: state.rowHeight,
688
+ rowOffsets: viewportData.rowOffsets,
689
+ rowHeights: viewportData.rowHeights,
690
+ visibleRowRange: viewportData.visibleRowRange,
492
691
  rowWidth: layer.rowWidth,
493
692
  skipBind,
494
693
  });
@@ -510,6 +709,22 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
510
709
  const syncPool = (synchronousColumnWindow = false, skipContentBind = false) => {
511
710
  const state = grid.getState();
512
711
  const currentViewportData = grid.getViewportData();
712
+ // The scrollable content height follows the measured row heights.
713
+ // It is written imperatively: a Store notification per measured row
714
+ // would re-render the whole grid, and the grid would then lag behind
715
+ // the native scroll position (the user sees the previous rows).
716
+ //
717
+ // During an active user scroll gesture the height is frozen to the
718
+ // snapshot taken at gesture start (see `handleScroll`). Otherwise the
719
+ // browser recomputes the scrollbar thumb (`scrollTop /
720
+ // (scrollHeight - clientHeight)`) every time a measured row height
721
+ // replaces an estimate and `totalHeight` changes mid-drag — on the
722
+ // first scroll of a variable-height grid the thumb then lags behind
723
+ // the mouse pointer. Row positions still use the live measured
724
+ // offsets; only the scrollbar range is frozen until the scroll
725
+ // settles.
726
+ const effectiveTotalHeight = currentViewportData.totalHeight;
727
+ applyContentHeight(effectiveTotalHeight);
513
728
  const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
514
729
  const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
515
730
  const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
@@ -643,11 +858,19 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
643
858
  measureViewport();
644
859
  return () => observer.disconnect();
645
860
  }, [grid, measureViewport, syncScrollbarInsets]);
646
- // Scrollbars can appear or disappear after any render (content or column changes).
861
+ // Scrollbars can appear or disappear when the CONTENT size changes (the
862
+ // rows are measured, a column is resized). Measuring the insets after
863
+ // EVERY render forces a synchronous layout of the whole page — during a
864
+ // fast scroll that alone blows the frame budget, and the grid then lags
865
+ // behind the native scroll (the user sees the previous rows).
866
+ const contentSizeKey = `${viewportData.totalWidth}x${viewportData.totalHeight}`;
647
867
  useLayoutEffect(() => {
868
+ if (contentSizeKeyRef.current === contentSizeKey)
869
+ return;
870
+ contentSizeKeyRef.current = contentSizeKey;
648
871
  if (viewportRef.current)
649
872
  syncScrollbarInsets(viewportRef.current);
650
- });
873
+ }, [contentSizeKey]);
651
874
  useLayoutEffect(() => {
652
875
  if (autoHeight)
653
876
  return;
@@ -665,6 +888,12 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
665
888
  });
666
889
  return unsubscribe;
667
890
  }, [grid]);
891
+ useEffect(() => () => {
892
+ if (anchorTimerRef.current !== null)
893
+ window.clearTimeout(anchorTimerRef.current);
894
+ if (heightFlushRef.current !== null)
895
+ window.cancelAnimationFrame(heightFlushRef.current);
896
+ }, []);
668
897
  /**
669
898
  * Sync the DomPool after every structural re-render.
670
899
  *
@@ -675,16 +904,22 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
675
904
  * in the rAF already handled the DomPool sync and a redundant invalidate()
676
905
  * here would force-rebind every visible row for no reason.
677
906
  *
678
- * Adapter options (rowClassRules closures, getRowStyle, plugins) can
679
- * change between renders WITHOUT touching the grid revision or the data
680
- * reference — e.g. a rule toggled by a useState in the host component.
681
- * Force-rebind the visible nodes so row classes/styles are re-evaluated
682
- * with the fresh options on structural re-renders.
907
+ * The pools are invalidated only when the grid's STRUCTURAL revision
908
+ * changed. Row-height updates (variable-height mode) also notify the
909
+ * Store, but they are pure geometry changes: re-binding every visible row
910
+ * for them would re-render every cell and re-trigger the row measurement
911
+ * — a feedback loop that starves the scroll frame budget and leaves the
912
+ * grid with overlapping rows while scrolling.
683
913
  */
914
+ const lastStructuralRevisionRef = useRef(-1);
684
915
  useEffect(() => {
685
- for (const layer of [layers.left, layers.central, layers.right]) {
686
- if (layer.pool)
687
- layer.pool.invalidate();
916
+ const revision = grid.getRevision();
917
+ if (revision !== lastStructuralRevisionRef.current) {
918
+ lastStructuralRevisionRef.current = revision;
919
+ for (const layer of [layers.left, layers.central, layers.right]) {
920
+ if (layer.pool)
921
+ layer.pool.invalidate();
922
+ }
688
923
  }
689
924
  syncPool(false, false); // skipContentBind=false: structural changes always bind fully
690
925
  }, [state]);
@@ -708,17 +943,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
708
943
  const frame = scrollFrameRef.current;
709
944
  frame.top = element.scrollTop;
710
945
  frame.left = element.scrollLeft;
711
- // Detect scrollbar appearance/disappearance. When the vertical
712
- // scrollbar appears it reduces clientWidth; if the grid previously
713
- // measured without the scrollbar, we re-measure to avoid a phantom
714
- // horizontal scrollbar. (With `scrollbar-gutter: stable` this is a
715
- // no-op in modern browsers.)
716
- const scrollbarWidth = element.offsetWidth - element.clientWidth;
717
- if (scrollbarWidth !== scrollbarWidthRef.current) {
718
- scrollbarWidthRef.current = scrollbarWidth;
719
- syncScrollbarInsets(element);
720
- grid.setViewport({ width: element.clientWidth });
721
- }
946
+ // The scrollbar width is NOT measured here: reading `offsetWidth` /
947
+ // clientWidth forces a synchronous layout of the whole page, and a
948
+ // scroll event fires several times per frame during a thumb drag.
949
+ // The ResizeObserver reports the content box size instead — it fires
950
+ // exactly when the scrollbar appears or disappears.
722
951
  if (frame.id)
723
952
  return;
724
953
  frame.id = window.requestAnimationFrame(() => {
@@ -742,11 +971,17 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
742
971
  scrollVelocityRef.current = deltaT > 8 ? Math.abs(scrollTop - frame.lastTop) / deltaT : 0;
743
972
  frame.lastTop = scrollTop;
744
973
  frame.lastTime = now;
974
+ lastScrollTimeRef.current = now;
745
975
  // setViewport with scroll-only updates does NOT notify the Store,
746
976
  // so this does NOT trigger a React re-render. The DomPool is
747
977
  // updated imperatively below.
748
978
  grid.setViewport({ scrollTop, scrollLeft });
749
- const skipContentBind = scrollVelocityRef.current > 2.0;
979
+ const skipContentBind = scrollVelocityRef.current > FAST_SCROLL_VELOCITY;
980
+ if (!skipContentBind && pendingAnchorRef.current !== 0) {
981
+ // The scroll settled — the deferred anchoring correction can be
982
+ // applied now without fighting the user's input.
983
+ flushPendingAnchor();
984
+ }
750
985
  syncPool(true, skipContentBind);
751
986
  });
752
987
  };
@@ -847,7 +1082,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
847
1082
  // correctly on the horizontal axis because sticky positioning is not
848
1083
  // affected by the clip.
849
1084
  const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
850
- const overlayHeight = Math.max(0, (autoHeight ? measuredHeight : state.viewport.height) - headerHeight);
851
1085
  const renderHeaderCells = (columns, originX) => columns.map((item) => {
852
1086
  const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
853
1087
  const gapRows = headerRowCount - 1 - deepestDepth;
@@ -928,7 +1162,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
928
1162
  */
929
1163
  const renderHeader = (columns, originX, width, isPinned = false) => (_jsxs("div", { className: "omnigrid-header", style: {
930
1164
  height: headerHeight,
931
- overflow: "hidden",
1165
+ overflow: "visible",
932
1166
  position: "sticky",
933
1167
  top: 0,
934
1168
  zIndex: isPinned ? 4 : 2,
@@ -943,12 +1177,15 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
943
1177
  }, children: renderGroupCells(depth, columns, originX) }, `group-row-${depth}`))), _jsx("div", { role: "row", className: "omnigrid-header-row", style: {
944
1178
  height: rowHeight,
945
1179
  left: 0,
946
- overflow: hasGroups ? "visible" : "hidden",
1180
+ overflow: "visible",
947
1181
  position: "absolute",
948
1182
  top: headerRowCount * rowHeight,
949
1183
  width: "100%",
950
1184
  }, children: renderHeaderCells(columns, originX) })] }));
951
1185
  const renderRowsLayer = (ref, width) => (_jsx("div", { ref: ref, "data-pool-layer": "true", style: {
1186
+ // The layer's height follows the measured row heights — it is
1187
+ // updated imperatively (see `syncPool`) so a measurement does
1188
+ // not re-render the whole grid.
952
1189
  height: viewportData.totalHeight,
953
1190
  left: 0,
954
1191
  overflow: "hidden",
@@ -973,13 +1210,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
973
1210
  position: "relative",
974
1211
  scrollbarGutter: verticalScrollbarGutter,
975
1212
  width: "100%",
976
- }, children: _jsxs("div", { style: {
1213
+ }, children: _jsxs("div", { ref: contentRef, style: {
977
1214
  display: "flex",
978
1215
  height: rowTotalHeight,
979
1216
  position: "relative",
980
1217
  width: `max(100%, ${viewportData.totalWidth}px)`,
981
1218
  }, children: [hasPinnedLeft && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-left", style: {
982
- height: rowTotalHeight,
1219
+ height: "100%",
983
1220
  left: 0,
984
1221
  position: "sticky",
985
1222
  top: 0,
@@ -992,14 +1229,14 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
992
1229
  width: centralWidth,
993
1230
  zIndex: 1,
994
1231
  }, children: [renderHeader(viewportData.columns, pinnedLeftWidth, "100%", false), renderRowsLayer(rowsLayerRef, "100%")] }), hasPinnedRight && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-right", style: {
995
- height: rowTotalHeight,
1232
+ height: "100%",
996
1233
  position: "sticky",
997
1234
  right: 0,
998
1235
  top: 0,
999
1236
  width: `${pinnedRightWidth}px`,
1000
1237
  zIndex: 3,
1001
1238
  }, children: [renderHeader(viewportData.pinnedRightColumns, pinnedLeftWidth + scrollableWidth, `${pinnedRightWidth}px`, true), renderRowsLayer(pinnedRightRowsLayerRef, `${pinnedRightWidth}px`)] }))] }) }), renderBodySlot("bodyTop"), renderBodySlot("bodyBottom"), overlayState.type && overlayScope === "bodyOnly" && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-body", role: "status", style: {
1002
- height: overlayHeight,
1239
+ bottom: 0,
1003
1240
  left: 0,
1004
1241
  pointerEvents: "auto",
1005
1242
  position: "absolute",
@@ -35,6 +35,7 @@ export interface PooledRowCallbacks<T> {
35
35
  onRowHover(row: PooledRow<T>, hovered: boolean): void;
36
36
  onCellClick(row: PooledRow<T>, column: ColumnLeafDef<T>, modifiers: PooledRowModifiers): void;
37
37
  createRoot(container: HTMLDivElement): CellRoot;
38
+ onRowHeightChange?(rowIndex: number, height: number): void;
38
39
  /**
39
40
  * Returns a cheap scalar preview of the cell value, painted synchronously
40
41
  * into a blank cell while its first React commit (complex content) is
@@ -71,6 +72,9 @@ export declare class PooledRowPane<T> {
71
72
  * of the left + scrollable widths.
72
73
  */
73
74
  private originX;
75
+ private variableHeight;
76
+ private heightMeasureId;
77
+ private rowHasWrapText;
74
78
  constructor(host: HTMLDivElement, callbacks: PooledRowCallbacks<T>, bridge: ContentBridge<T>);
75
79
  /** Binds a row to the panel and fully rebuilds content. */
76
80
  bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
@@ -80,6 +84,37 @@ export declare class PooledRowPane<T> {
80
84
  updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
81
85
  /** Single row positioning operation — transform only (no reflow). */
82
86
  setOffsetY(offsetY: number): void;
87
+ /**
88
+ * Updates the row index the node stands for without touching its content.
89
+ *
90
+ * Used by the DOM pool when the node was re-used for a different row but
91
+ * the content could not be re-bound in the same frame (fast scroll, rebind
92
+ * quota): the content stays stale until the next bind, but the index has
93
+ * to describe the new row — the adapters look rows up by index (hover
94
+ * highlight), and a stale index would highlight the wrong node.
95
+ */
96
+ setRowIndex(rowIndex: number): void;
97
+ /**
98
+ * Applies a new height to the bound row without touching its content.
99
+ *
100
+ * Used by the DOM pool when only the row HEIGHT changed (variable-height
101
+ * mode): the row data is still valid, so the node is resized instead of
102
+ * re-bound — re-binding would re-render every cell and re-trigger the
103
+ * height measurement.
104
+ */
105
+ resize(height: number): void;
106
+ /**
107
+ * Measures the natural content height of the bound row.
108
+ *
109
+ * The row node is sized to the (possibly stale) reserved row height with
110
+ * `overflow: hidden`, so reading `scrollHeight` on it clamps to that
111
+ * reserved height whenever the content fits inside it. That makes the
112
+ * measurement a one-way ratchet: rows grow when content overflows but can
113
+ * never shrink when a wider column needs fewer wrapped lines. Temporarily
114
+ * releasing the height constraint lets `scrollHeight` reflect the real
115
+ * (wrapped) content height in both directions.
116
+ */
117
+ private measureRowHeight;
83
118
  /** Moves an unused row far off-screen (outside viewport). */
84
119
  hide(): void;
85
120
  /** Clears content and unbinds the row, preserving DOM nodes. */
@@ -91,6 +126,7 @@ export declare class PooledRowPane<T> {
91
126
  private renderContent;
92
127
  private applyCellPresentation;
93
128
  private applyContent;
129
+ private scheduleHeightMeasurement;
94
130
  private clearContent;
95
131
  private applyRowSizing;
96
132
  private applyRowPresentation;
package/dist/pooledRow.js CHANGED
@@ -41,6 +41,9 @@ export class PooledRowPane {
41
41
  * of the left + scrollable widths.
42
42
  */
43
43
  this.originX = 0;
44
+ this.variableHeight = false;
45
+ this.heightMeasureId = 0;
46
+ this.rowHasWrapText = false;
44
47
  host.classList.add("omnigrid-row");
45
48
  host.setAttribute("role", "row");
46
49
  host.style.position = "absolute";
@@ -67,6 +70,26 @@ export class PooledRowPane {
67
70
  if (row)
68
71
  this.callbacks.onRowHover(row, false);
69
72
  });
73
+ // Variable-height mode only: the row box is resized to the measured
74
+ // content height, so a height change has to be reported back to the
75
+ // grid. In fixed-height mode no observer is installed at all — the
76
+ // measurement would be a pointless layout read on every resize.
77
+ this.variableHeight = Boolean(callbacks.onRowHeightChange);
78
+ if (this.variableHeight) {
79
+ const observer = new ResizeObserver(() => {
80
+ const currentRow = this.row;
81
+ if (!currentRow)
82
+ return;
83
+ // Non-wrap rows are single-line and keep the fixed rowHeight;
84
+ // only wrapText rows need the unconstrained natural-height
85
+ // measurement (see measureRowHeight).
86
+ const measured = this.rowHasWrapText ? this.measureRowHeight() : this.host.scrollHeight;
87
+ if (Math.abs(measured - currentRow.height) < 1)
88
+ return;
89
+ this.callbacks.onRowHeightChange?.(currentRow.index, measured);
90
+ });
91
+ observer.observe(this.host);
92
+ }
70
93
  }
71
94
  /** Binds a row to the panel and fully rebuilds content. */
72
95
  bind(row, columns, originX = 0, spans) {
@@ -77,15 +100,15 @@ export class PooledRowPane {
77
100
  this.host.dataset.rowIndex = String(row.index);
78
101
  this.host.classList.remove("omnigrid-row-hover");
79
102
  this.originX = originX;
103
+ this.rowHasWrapText = columns.some((column) => column.column.wrapText);
80
104
  this.applyRowSizing(row);
81
- // Cells must exist BEFORE presentation is applied: applyRowPresentation
82
- // copies the row background colour onto each existing cell. If it ran
83
- // first, newly created cells would keep the default CSS background
84
- // until the next bind (i.e. until scrolling).
85
105
  this.mapColumns(columns, true, spans);
86
106
  this.applyRowPresentation(row);
87
107
  if (hovered)
88
108
  this.callbacks.onRowHover(row, true);
109
+ if (this.variableHeight) {
110
+ this.scheduleHeightMeasurement(row);
111
+ }
89
112
  }
90
113
  /** Returns the currently bound row, if any. */
91
114
  getRow() {
@@ -98,11 +121,66 @@ export class PooledRowPane {
98
121
  if (row)
99
122
  this.applyRowSizing(row);
100
123
  this.mapColumns(columns, false, spans);
124
+ if (this.variableHeight && row) {
125
+ this.scheduleHeightMeasurement(row);
126
+ }
101
127
  }
102
128
  /** Single row positioning operation — transform only (no reflow). */
103
129
  setOffsetY(offsetY) {
104
130
  this.host.style.transform = `translate3d(0, ${Math.round(offsetY)}px, 0)`;
105
131
  }
132
+ /**
133
+ * Updates the row index the node stands for without touching its content.
134
+ *
135
+ * Used by the DOM pool when the node was re-used for a different row but
136
+ * the content could not be re-bound in the same frame (fast scroll, rebind
137
+ * quota): the content stays stale until the next bind, but the index has
138
+ * to describe the new row — the adapters look rows up by index (hover
139
+ * highlight), and a stale index would highlight the wrong node.
140
+ */
141
+ setRowIndex(rowIndex) {
142
+ this.host.dataset.rowIndex = String(rowIndex);
143
+ }
144
+ /**
145
+ * Applies a new height to the bound row without touching its content.
146
+ *
147
+ * Used by the DOM pool when only the row HEIGHT changed (variable-height
148
+ * mode): the row data is still valid, so the node is resized instead of
149
+ * re-bound — re-binding would re-render every cell and re-trigger the
150
+ * height measurement.
151
+ */
152
+ resize(height) {
153
+ const row = this.row;
154
+ if (!row || row.height === height)
155
+ return;
156
+ row.height = height;
157
+ this.applyRowSizing(row);
158
+ }
159
+ /**
160
+ * Measures the natural content height of the bound row.
161
+ *
162
+ * The row node is sized to the (possibly stale) reserved row height with
163
+ * `overflow: hidden`, so reading `scrollHeight` on it clamps to that
164
+ * reserved height whenever the content fits inside it. That makes the
165
+ * measurement a one-way ratchet: rows grow when content overflows but can
166
+ * never shrink when a wider column needs fewer wrapped lines. Temporarily
167
+ * releasing the height constraint lets `scrollHeight` reflect the real
168
+ * (wrapped) content height in both directions.
169
+ */
170
+ measureRowHeight() {
171
+ const host = this.host;
172
+ const prevHeight = host.style.height;
173
+ const prevMinHeight = host.style.minHeight;
174
+ const prevOverflow = host.style.overflow;
175
+ host.style.height = "auto";
176
+ host.style.minHeight = "";
177
+ host.style.overflow = "visible";
178
+ const measured = host.scrollHeight;
179
+ host.style.height = prevHeight;
180
+ host.style.minHeight = prevMinHeight;
181
+ host.style.overflow = prevOverflow;
182
+ return measured;
183
+ }
106
184
  /** Moves an unused row far off-screen (outside viewport). */
107
185
  hide() {
108
186
  this.host.style.transform = `translate3d(0, ${OFFSCREEN_Y}px, 0)`;
@@ -180,6 +258,20 @@ export class PooledRowPane {
180
258
  cell.offsetX = offset;
181
259
  cell.width = layout.width;
182
260
  }
261
+ // Wrapping cells are sized by their CONTENT (the row height is
262
+ // measured from them), every other cell fills the row. The NEW column
263
+ // decides — a pooled cell can be recycled from a wrapping column into
264
+ // a plain one, and the leftover styles would break the row layout.
265
+ // Only the sizing is touched here: alignment and padding stay with the
266
+ // theme.
267
+ if (this.variableHeight && layout.column.wrapText) {
268
+ element.style.height = "auto";
269
+ element.style.minHeight = "100%";
270
+ }
271
+ else {
272
+ element.style.height = "100%";
273
+ element.style.minHeight = "";
274
+ }
183
275
  if (cell.justify !== justify) {
184
276
  element.style.justifyContent = justify;
185
277
  cell.justify = justify;
@@ -192,7 +284,7 @@ export class PooledRowPane {
192
284
  element.style.top = "0";
193
285
  element.style.left = "0";
194
286
  element.style.overflow = "hidden";
195
- element.style.height = `${this.callbacks.rowHeight}px`;
287
+ element.style.height = "100%";
196
288
  this.host.appendChild(element);
197
289
  const cell = {
198
290
  element,
@@ -249,6 +341,27 @@ export class PooledRowPane {
249
341
  cell.appliedStyleKeys.push(key);
250
342
  }
251
343
  }
344
+ if (cell.column?.wrapText) {
345
+ // Wrapping cell: the text breaks into several lines and the cell
346
+ // grows with it. The theme owns the horizontal padding and the
347
+ // alignment — only the text flow and the vertical padding of the
348
+ // wrapped block are overridden.
349
+ cell.element.style.whiteSpace = "normal";
350
+ cell.element.style.wordBreak = "break-word";
351
+ cell.element.style.overflow = "visible";
352
+ cell.element.style.textOverflow = "clip";
353
+ cell.element.style.paddingBlock = "4px";
354
+ cell.element.style.alignItems = "flex-start";
355
+ }
356
+ else {
357
+ // Reset the wrapping styles: the cell may be pooled from a
358
+ // wrapping column.
359
+ cell.element.style.whiteSpace = "nowrap";
360
+ cell.element.style.overflow = "hidden";
361
+ cell.element.style.textOverflow = "ellipsis";
362
+ cell.element.style.paddingBlock = "";
363
+ cell.element.style.alignItems = "";
364
+ }
252
365
  }
253
366
  applyContent(cell, content, cellInfo) {
254
367
  if (content == null) {
@@ -294,6 +407,27 @@ export class PooledRowPane {
294
407
  }
295
408
  cell.root.render(contentToReactNode(content, this.bridge));
296
409
  }
410
+ scheduleHeightMeasurement(row) {
411
+ const id = ++this.heightMeasureId;
412
+ const measure = () => {
413
+ if (id !== this.heightMeasureId)
414
+ return;
415
+ if (this.row?.index !== row.index)
416
+ return;
417
+ const measured = this.rowHasWrapText ? this.measureRowHeight() : this.host.scrollHeight;
418
+ if (measured > 0 && Math.abs(measured - this.row.height) > 1) {
419
+ this.callbacks.onRowHeightChange?.(this.row.index, measured);
420
+ }
421
+ };
422
+ // The rAF callback runs before the layout of its frame — reading
423
+ // `scrollHeight` there forces the layout of the freshly bound content.
424
+ // The second pass catches the React commit of complex cell content,
425
+ // which lands a frame later.
426
+ requestAnimationFrame(() => {
427
+ measure();
428
+ requestAnimationFrame(measure);
429
+ });
430
+ }
297
431
  clearContent(cell) {
298
432
  if (cell.root) {
299
433
  // Keep the root mounted while the pooled cell is reused. Calling
@@ -305,14 +439,26 @@ export class PooledRowPane {
305
439
  }
306
440
  }
307
441
  applyRowSizing(row) {
308
- // The row node is an absolutely-positioned block: without explicit
309
- // dimensions it collapses to 0×0, hiding the row background and row
310
- // hover styles. Width covers the full content (all columns), height
311
- // matches the row height.
312
442
  if (row.width > 0)
313
443
  this.host.style.width = `${row.width}px`;
314
- if (row.height > 0)
444
+ if (this.variableHeight) {
445
+ // The virtualizer owns the row geometry: the node is sized to the
446
+ // height the virtualizer reserved for this row and CLIPS its
447
+ // content. Content taller than the reserved slot (the measurement
448
+ // has not arrived yet) is cut off instead of bleeding into the
449
+ // next row — otherwise rows overlap and the grid degenerates
450
+ // into a pile of overlapping lines while scrolling.
315
451
  this.host.style.height = `${row.height}px`;
452
+ this.host.style.minHeight = "";
453
+ this.host.style.overflow = "hidden";
454
+ }
455
+ else {
456
+ this.host.style.overflow = "";
457
+ if (row.height > 0) {
458
+ this.host.style.height = `${row.height}px`;
459
+ this.host.style.minHeight = "";
460
+ }
461
+ }
316
462
  }
317
463
  applyRowPresentation(row) {
318
464
  this.host.className = this.callbacks.resolveRowClasses(row) ?? "omnigrid-row";
package/dist/useGrid.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isColumnGroup } from '@omnigrid/core';
1
2
  import { Grid } from '@omnigrid/core';
2
3
  import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react';
3
4
  /**
@@ -85,7 +86,51 @@ export function useGrid(options) {
85
86
  const next = options.columns ?? [];
86
87
  if (prev.length !== next.length || prev.some((column, index) => column !== next[index])) {
87
88
  lastSyncedColumnsRef.current = options.columns;
88
- grid.setColumns(options.columns);
89
+ // Merge the user's column definitions into the current (plugin-enriched)
90
+ // columns instead of replacing them wholesale. Plugins such as the resize
91
+ // plugin inject properties (e.g. `headerRenderer`) into columns that are
92
+ // not part of the user's column definitions; replacing columns with the
93
+ // raw definitions would strip them and break e.g. column resize handles.
94
+ const current = grid.getState().columns;
95
+ // Merge the user's column definitions INTO the current (plugin-enriched)
96
+ // columns instead of replacing them wholesale. Iterating over `current`
97
+ // preserves plugin-injected columns (e.g. the selection column prepended
98
+ // by SelectionPlugin) that have no corresponding entry in `options.columns`.
99
+ // Columns are matched by `id` (not by index) because plugin columns may be
100
+ // prepended/appended and shift positions. User column properties are merged
101
+ // on top; plugin-owned metadata that the user did not override is kept.
102
+ // User columns with no match in `current` are appended at the end.
103
+ const currentById = new Map();
104
+ current.forEach((column) => currentById.set(column.id, column));
105
+ const merged = [];
106
+ current.forEach((currentColumn) => {
107
+ const userColumn = next.find((c) => c.id === currentColumn.id);
108
+ if (!userColumn) {
109
+ merged.push(currentColumn);
110
+ return;
111
+ }
112
+ const enriched = { ...userColumn };
113
+ if (userColumn.headerRenderer === undefined && currentColumn.headerRenderer !== undefined) {
114
+ enriched.headerRenderer = currentColumn.headerRenderer;
115
+ }
116
+ if (!isColumnGroup(enriched) && !isColumnGroup(currentColumn) && !isColumnGroup(userColumn)) {
117
+ const leaf = enriched;
118
+ const currentLeaf = currentColumn;
119
+ const userLeaf = userColumn;
120
+ if (userLeaf.sortable === undefined)
121
+ leaf.sortable = currentLeaf.sortable;
122
+ if (userLeaf.sortState === undefined)
123
+ leaf.sortState = currentLeaf.sortState;
124
+ if (userLeaf.sortIndex === undefined)
125
+ leaf.sortIndex = currentLeaf.sortIndex;
126
+ }
127
+ merged.push(enriched);
128
+ });
129
+ next.forEach((userColumn) => {
130
+ if (!currentById.has(userColumn.id))
131
+ merged.push(userColumn);
132
+ });
133
+ grid.setColumns(merged);
89
134
  }
90
135
  }, [grid, options.columns]);
91
136
  // Controlled filter model: applied when the host passes a new reference.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",