@omnigrid/react 0.1.23 → 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.
@@ -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
- const verticalScrollbarGutter = hasVerticalOverflow ? "stable" : "auto";
203
- const viewportStyle = { ...style, height: autoHeight ? measuredHeight : style?.height };
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 cellParams = { id: info.rowId, index: info.rowIndex, data: info.data, column: info.column };
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
- return resolveCellClasses(info.column, cellParams, columnPresentation.classes);
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 cellParams = { id: info.rowId, index: info.rowIndex, data: info.data, column: info.column };
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 || height === 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
- grid.setViewport({ width, height });
839
- }, [grid, syncScrollbarInsets]);
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
- if (autoHeight)
876
- return;
877
- // Scrollbar and gutter changes alter clientWidth; sync it before paint
878
- // so columns remain aligned when an overlay locks vertical scrolling.
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), {
@@ -1162,7 +1223,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1162
1223
  */
1163
1224
  const renderHeader = (columns, originX, width, isPinned = false) => (_jsxs("div", { className: "omnigrid-header", style: {
1164
1225
  height: headerHeight,
1165
- overflow: "hidden",
1226
+ overflow: "visible",
1166
1227
  position: "sticky",
1167
1228
  top: 0,
1168
1229
  zIndex: isPinned ? 4 : 2,
@@ -1177,7 +1238,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1177
1238
  }, children: renderGroupCells(depth, columns, originX) }, `group-row-${depth}`))), _jsx("div", { role: "row", className: "omnigrid-header-row", style: {
1178
1239
  height: rowHeight,
1179
1240
  left: 0,
1180
- overflow: hasGroups ? "visible" : "hidden",
1241
+ overflow: "visible",
1181
1242
  position: "absolute",
1182
1243
  top: headerRowCount * rowHeight,
1183
1244
  width: "100%",
@@ -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: 0,
1268
+ minHeight: minViewportHeight,
1207
1269
  minWidth: 0,
1208
1270
  overflowX: overlayBlocksHorizontalScroll ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
1209
1271
  overflowY: overlayScope || autoHeight ? "hidden" : "auto",
@@ -74,6 +74,7 @@ export declare class PooledRowPane<T> {
74
74
  private originX;
75
75
  private variableHeight;
76
76
  private heightMeasureId;
77
+ private rowHasWrapText;
77
78
  constructor(host: HTMLDivElement, callbacks: PooledRowCallbacks<T>, bridge: ContentBridge<T>);
78
79
  /** Binds a row to the panel and fully rebuilds content. */
79
80
  bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
@@ -102,6 +103,18 @@ export declare class PooledRowPane<T> {
102
103
  * height measurement.
103
104
  */
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;
105
118
  /** Moves an unused row far off-screen (outside viewport). */
106
119
  hide(): void;
107
120
  /** Clears content and unbinds the row, preserving DOM nodes. */
package/dist/pooledRow.js CHANGED
@@ -43,6 +43,7 @@ export class PooledRowPane {
43
43
  this.originX = 0;
44
44
  this.variableHeight = false;
45
45
  this.heightMeasureId = 0;
46
+ this.rowHasWrapText = false;
46
47
  host.classList.add("omnigrid-row");
47
48
  host.setAttribute("role", "row");
48
49
  host.style.position = "absolute";
@@ -79,12 +80,15 @@ export class PooledRowPane {
79
80
  const currentRow = this.row;
80
81
  if (!currentRow)
81
82
  return;
82
- const measured = host.scrollHeight;
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;
83
87
  if (Math.abs(measured - currentRow.height) < 1)
84
88
  return;
85
89
  this.callbacks.onRowHeightChange?.(currentRow.index, measured);
86
90
  });
87
- observer.observe(host);
91
+ observer.observe(this.host);
88
92
  }
89
93
  }
90
94
  /** Binds a row to the panel and fully rebuilds content. */
@@ -96,6 +100,7 @@ export class PooledRowPane {
96
100
  this.host.dataset.rowIndex = String(row.index);
97
101
  this.host.classList.remove("omnigrid-row-hover");
98
102
  this.originX = originX;
103
+ this.rowHasWrapText = columns.some((column) => column.column.wrapText);
99
104
  this.applyRowSizing(row);
100
105
  this.mapColumns(columns, true, spans);
101
106
  this.applyRowPresentation(row);
@@ -151,6 +156,31 @@ export class PooledRowPane {
151
156
  row.height = height;
152
157
  this.applyRowSizing(row);
153
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
+ }
154
184
  /** Moves an unused row far off-screen (outside viewport). */
155
185
  hide() {
156
186
  this.host.style.transform = `translate3d(0, ${OFFSCREEN_Y}px, 0)`;
@@ -298,6 +328,16 @@ export class PooledRowPane {
298
328
  }
299
329
  applyCellPresentation(cell, cellInfo) {
300
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
+ }
301
341
  cell.element.className = cellClasses ?? "";
302
342
  for (const key of cell.appliedStyleKeys)
303
343
  cell.element.style.removeProperty(cssPropertyName(key));
@@ -384,7 +424,7 @@ export class PooledRowPane {
384
424
  return;
385
425
  if (this.row?.index !== row.index)
386
426
  return;
387
- const measured = this.host.scrollHeight;
427
+ const measured = this.rowHasWrapText ? this.measureRowHeight() : this.host.scrollHeight;
388
428
  if (measured > 0 && Math.abs(measured - this.row.height) > 1) {
389
429
  this.callbacks.onRowHeightChange?.(this.row.index, measured);
390
430
  }
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.23",
3
+ "version": "0.1.25",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",