@omnigrid/react 0.1.13 → 0.1.15

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
@@ -7,6 +7,7 @@ import { computeGroupSegments } from "./groupHeader";
7
7
  import { PooledRowPane } from "./pooledRow";
8
8
  import { createCellRoot } from "./reactRoot";
9
9
  import { renderDefaultOverlay } from "./overlays";
10
+ import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
10
11
  import { useGrid } from "./useGrid";
11
12
  function getCellValue(row, column) {
12
13
  if (column.valueGetter)
@@ -63,7 +64,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
63
64
  const pinnedLeftRowsLayerRef = useRef(null);
64
65
  const pinnedRightRowsLayerRef = useRef(null);
65
66
  const [isMeasured, setIsMeasured] = useState(false);
66
- const scrollFrameRef = useRef({ id: 0, top: 0, left: 0 });
67
+ const scrollFrameRef = useRef({ id: 0, top: 0, left: 0, lastTop: 0, lastTime: 0 });
68
+ const scrollVelocityRef = useRef(0);
67
69
  const optionsRef = useRef(options);
68
70
  const columnWindowKeyRef = useRef("");
69
71
  const scrollbarWidthRef = useRef(0);
@@ -143,6 +145,25 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
143
145
  context: buildRenderContext,
144
146
  };
145
147
  }
148
+ const columnPresentationCacheRef = useRef(new Map());
149
+ const getColumnPresentation = (column) => {
150
+ const revision = grid.getRevision();
151
+ const processedData = grid.getProcessedData();
152
+ const cached = columnPresentationCacheRef.current.get(column.id);
153
+ if (cached && cached.revision === revision && cached.data === processedData) {
154
+ return cached.presentation;
155
+ }
156
+ const values = processedData.map((row) => getCellValue(row, column));
157
+ const params = {
158
+ column,
159
+ values,
160
+ api: grid,
161
+ state: grid.getState(),
162
+ };
163
+ const presentation = resolveColumnPresentation(column, params);
164
+ columnPresentationCacheRef.current.set(column.id, { revision, data: processedData, presentation });
165
+ return presentation;
166
+ };
146
167
  /** Row panel callbacks: close over grid/options, never over DOM. */
147
168
  function buildRowCallbacks(bridgeArg) {
148
169
  const current = () => optionsRef.current;
@@ -156,6 +177,21 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
156
177
  }
157
178
  return column.valueFormatter ? column.valueFormatter(value) : String(value ?? "");
158
179
  },
180
+ renderCellPlaceholder: (info) => {
181
+ // Cheap scalar preview mirroring the renderCellContent pipeline
182
+ // minus the (possibly expensive) cellRenderer: same value source,
183
+ // same formatter. Skipped when the raw value is not scalar and no
184
+ // formatter exists (e.g. CheckboxControl sources) — the cell
185
+ // stays empty for the one commit rather than showing garbage.
186
+ const column = info.column;
187
+ const value = getCellValue(info.data, column);
188
+ if (column.valueFormatter)
189
+ return column.valueFormatter(value);
190
+ const valueType = typeof value;
191
+ if (valueType === "string" || valueType === "number" || valueType === "boolean")
192
+ return String(value);
193
+ return null;
194
+ },
159
195
  resolveRowClasses: (row) => {
160
196
  const rowParams = { id: row.rowId, index: row.index, data: row.data };
161
197
  const currentOptions = current();
@@ -180,21 +216,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
180
216
  },
181
217
  resolveCellClasses: (info) => {
182
218
  const cellParams = { id: info.rowId, index: info.rowIndex, data: info.data, column: info.column };
183
- const column = info.column;
184
- const cellClass = typeof column.cellClass === "function" ? column.cellClass(cellParams) : column.cellClass;
185
- const dynamicCellClass = column.getCellClass?.(cellParams);
186
- const ruleClasses = Object.entries(column.cellClassRules ?? {})
187
- .filter(([, predicate]) => predicate(cellParams))
188
- .map(([ruleClass]) => ruleClass);
189
- return [cellClass, ...ruleClasses, dynamicCellClass].filter(Boolean).join(" ");
219
+ const columnPresentation = getColumnPresentation(info.column);
220
+ return resolveCellClasses(info.column, cellParams, columnPresentation.classes);
190
221
  },
191
222
  resolveCellStyle: (info) => {
192
223
  const cellParams = { id: info.rowId, index: info.rowIndex, data: info.data, column: info.column };
193
- const column = info.column;
194
- return {
195
- ...(column.cellStyle ?? {}),
196
- ...(column.getCellStyle?.(cellParams) ?? {}),
197
- };
224
+ const columnPresentation = getColumnPresentation(info.column);
225
+ return resolveCellStyle(info.column, cellParams, columnPresentation.style);
198
226
  },
199
227
  onRowClick: (row, modifiers) => grid.rowClick({
200
228
  id: row.rowId,
@@ -271,36 +299,48 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
271
299
  * Synchronises a single column-group layer with the grid: lazily creates its
272
300
  * DomPool, invalidates on structural changes, then pushes the current row
273
301
  * range and per-row width.
302
+ *
303
+ * Receives the pre-computed `viewportData` from `syncPool` to avoid redundant
304
+ * getViewportData() calls — each layer no longer recomputes column geometry.
274
305
  */
275
- const syncRowLayer = (layer, rowsLayerRef) => {
306
+ const syncRowLayer = (layer, viewportData, rowsLayerRef, skipBind = false) => {
276
307
  const bridge = ensureLayerContext();
277
308
  ensureLayerPool(layer, rowsLayerRef.current, bridge);
278
309
  const pool = layer.pool;
279
310
  if (!pool || grid.isDestroyed())
280
311
  return;
281
312
  const state = grid.getState();
282
- const currentViewportData = grid.getViewportData();
283
313
  const processed = grid.getProcessedData();
284
- const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== currentViewportData.totalWidth || layer.processed !== processed;
314
+ const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || layer.processed !== processed;
285
315
  if (changed) {
286
316
  layer.revision = grid.getRevision();
287
- layer.totalWidth = currentViewportData.totalWidth;
317
+ layer.totalWidth = viewportData.totalWidth;
288
318
  layer.processed = processed;
289
319
  pool.invalidate();
290
320
  }
291
321
  pool.update({
292
322
  data: processed,
293
- rowRange: currentViewportData.rowRange,
323
+ rowRange: viewportData.rowRange,
294
324
  rowHeight: state.rowHeight,
295
325
  rowWidth: layer.rowWidth,
326
+ skipBind,
296
327
  });
297
328
  };
298
329
  /**
299
330
  * Synchronises the DomPools with the grid. Idempotent — called both from
300
331
  * React effects (structural changes) and directly from the scroll rAF
301
332
  * handler (imperative, no React re-render).
333
+ *
334
+ * @param synchronousColumnWindow — when `true`, the rAF-driven scroll path
335
+ * triggers a `flushSync` for the column window header update so headers
336
+ * stay in step with the imperatively repositioned cells before paint.
337
+ * @param skipContentBind — when `true` (fast scroll), row positions are
338
+ * updated but `bindRow` is deferred to the next slow-scroll frame. This
339
+ * avoids synchronous React commits (~200 cell roots) that exceed the 16ms
340
+ * frame budget, causing flicker/frame drops. Rows remain visible with
341
+ * previous content at the correct new position.
302
342
  */
303
- const syncPool = (synchronousColumnWindow = false) => {
343
+ const syncPool = (synchronousColumnWindow = false, skipContentBind = false) => {
304
344
  const state = grid.getState();
305
345
  const currentViewportData = grid.getViewportData();
306
346
  const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
@@ -318,29 +358,62 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
318
358
  layers.right.columns = currentViewportData.pinnedRightColumns;
319
359
  layers.right.originX = pinnedLeftWidth + scrollableWidth;
320
360
  layers.right.rowWidth = pinnedRightWidth;
321
- syncRowLayer(layers.left, pinnedLeftRowsLayerRef);
322
- syncRowLayer(layers.central, rowsLayerRef);
323
- syncRowLayer(layers.right, pinnedRightRowsLayerRef);
361
+ // Cell content rendering (root.render) is async under React concurrent
362
+ // mode — without flushSync, rows are repositioned but their cell content
363
+ // stays stale for one frame, causing visible jitter on custom-renderer
364
+ // cells. Wrap ONLY the DOM binding in flushSync to force cell roots to
365
+ // commit before paint.
366
+ //
367
+ // Velocity-based: during fast scroll (scrollbar thumb drag), many scroll
368
+ // events fire but rAF throttles to ~60fps. Calling flushSync on every frame
369
+ // forces a synchronous React commit for ALL cell roots (~200 calls), which
370
+ // can exceed the 16ms frame budget and cause frame drops — appearing as
371
+ // flickering/emptying. During fast scroll, we skip flushSync: rows stay
372
+ // at correct positions with previous content (we don't clear content on
373
+ // recycle), so the table is never empty — just 1-frame stale, which is
374
+ // imperceptible during rapid scroll. When velocity drops, flushSync resumes
375
+ // for frame-perfect content. The structural path (useEffect) always uses
376
+ // flushSync for correctness.
377
+ // getViewportData() above runs outside flushSync since column geometry
378
+ // caching makes it fast, avoiding blocking on computation.
379
+ const bindLayers = () => {
380
+ syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef, skipContentBind);
381
+ syncRowLayer(layers.central, currentViewportData, rowsLayerRef, skipContentBind);
382
+ syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef, skipContentBind);
383
+ };
384
+ if (synchronousColumnWindow && !skipContentBind) {
385
+ flushSync(bindLayers);
386
+ }
387
+ else {
388
+ bindLayers();
389
+ }
324
390
  // The horizontal column window changes infrequently (only when
325
391
  // crossing column boundaries). When it does, update central row cells
326
392
  // imperatively AND trigger a targeted React re-render for the header.
327
393
  // Pinned panes hold all their columns at once — they only rebind via
328
394
  // the structural path above (revision bump).
329
- const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
330
- if (columnWindowKey !== columnWindowKeyRef.current) {
331
- columnWindowKeyRef.current = columnWindowKey;
332
- const updateColumnWindow = () => {
333
- for (const pane of layers.central.panes)
334
- pane.updateColumns(layers.central.columns, layers.central.originX);
335
- setColumnWindowVersion((v) => v + 1);
336
- };
337
- if (synchronousColumnWindow) {
338
- // Keep React-rendered cell content and headers in step with the
339
- // imperative cell repositioning before the browser paints.
340
- flushSync(updateColumnWindow);
341
- }
342
- else {
343
- updateColumnWindow();
395
+ //
396
+ // Skip column window updates during fast scroll (skipContentBind) —
397
+ // the columns themselves haven't changed, and forcing a header re-render
398
+ // during fast scroll would cause frame drops. The column window will
399
+ // be updated on the next slow-scroll frame or structural update.
400
+ if (!skipContentBind) {
401
+ const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
402
+ if (columnWindowKey !== columnWindowKeyRef.current) {
403
+ columnWindowKeyRef.current = columnWindowKey;
404
+ const updateColumnWindow = () => {
405
+ for (const pane of layers.central.panes)
406
+ pane.updateColumns(layers.central.columns, layers.central.originX);
407
+ setColumnWindowVersion((v) => v + 1);
408
+ };
409
+ if (synchronousColumnWindow) {
410
+ // Keep React-rendered cell content and headers in step with the
411
+ // imperative cell repositioning before the browser paints.
412
+ flushSync(updateColumnWindow);
413
+ }
414
+ else {
415
+ updateColumnWindow();
416
+ }
344
417
  }
345
418
  }
346
419
  };
@@ -397,22 +470,27 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
397
470
  }, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport, overlayScope]);
398
471
  /**
399
472
  * Sync the DomPool after every structural re-render.
400
- * This runs only when React actually re-renders (data / columns /
401
- * dimensions / column-window changes), never on scroll.
473
+ *
474
+ * Depends on `state` (from useSyncExternalStore) — the Store only notifies
475
+ * on structural changes (data / columns / dimensions / overlay), NOT on
476
+ * scroll-only updates or column-window version changes. This prevents the
477
+ * effect from running on horizontal-scroll re-renders, where syncPool(true)
478
+ * in the rAF already handled the DomPool sync and a redundant invalidate()
479
+ * here would force-rebind every visible row for no reason.
402
480
  *
403
481
  * Adapter options (rowClassRules closures, getRowStyle, plugins) can
404
482
  * change between renders WITHOUT touching the grid revision or the data
405
483
  * reference — e.g. a rule toggled by a useState in the host component.
406
484
  * Force-rebind the visible nodes so row classes/styles are re-evaluated
407
- * with the fresh options on every render.
485
+ * with the fresh options on structural re-renders.
408
486
  */
409
487
  useEffect(() => {
410
488
  for (const layer of [layers.left, layers.central, layers.right]) {
411
489
  if (layer.pool)
412
490
  layer.pool.invalidate();
413
491
  }
414
- syncPool();
415
- });
492
+ syncPool(false, false); // skipContentBind=false: structural changes always bind fully
493
+ }, [state]);
416
494
  useEffect(() => {
417
495
  return () => {
418
496
  if (scrollFrameRef.current.id)
@@ -455,16 +533,23 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
455
533
  const element = viewportRef.current;
456
534
  const scrollTop = element ? element.scrollTop : frame.top;
457
535
  const scrollLeft = element ? element.scrollLeft : frame.left;
536
+ // Velocity detection: px/ms. Threshold at 2.0 px/ms — mouse wheel
537
+ // and trackpad scrolls typically range 0.05–0.2 px/ms, while
538
+ // scrollbar thumb drags and shift-click page jumps can exceed 10 px/ms.
539
+ // When velocity exceeds the threshold, skipContentBind is passed to
540
+ // syncPool: rows are repositioned but content binding is deferred,
541
+ // avoiding synchronous React commits that exceed the 16ms frame budget.
542
+ const now = performance.now();
543
+ const deltaT = now - frame.lastTime;
544
+ scrollVelocityRef.current = deltaT > 8 ? Math.abs(scrollTop - frame.lastTop) / deltaT : 0;
545
+ frame.lastTop = scrollTop;
546
+ frame.lastTime = now;
458
547
  // setViewport with scroll-only updates does NOT notify the Store,
459
548
  // so this does NOT trigger a React re-render. The DomPool is
460
- // updated imperatively below, and both the row-column rebind and the
461
- // header window update must flush in the same React paint to avoid
462
- // one-frame horizontal/vertical jumps when custom cell renderers are
463
- // mounted into pooled DOM nodes.
464
- flushSync(() => {
465
- grid.setViewport({ scrollTop, scrollLeft });
466
- syncPool(true);
467
- });
549
+ // updated imperatively below.
550
+ grid.setViewport({ scrollTop, scrollLeft });
551
+ const skipContentBind = scrollVelocityRef.current > 2.0;
552
+ syncPool(true, skipContentBind);
468
553
  });
469
554
  };
470
555
  if (!isMeasured) {
@@ -552,48 +637,65 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
552
637
  const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
553
638
  const gapRows = headerRowCount - 1 - deepestDepth;
554
639
  const fullHeight = gapRows > 0;
555
- return (_jsx("div", { role: "columnheader", className: `omnigrid-header-cell${fullHeight ? " omnigrid-header-cell-full-height" : ""}`, "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
640
+ const headerParams = { column: item.column, index: item.index };
641
+ const className = resolveHeaderClasses(item.column, headerParams, fullHeight);
642
+ const customHeaderStyle = resolveHeaderStyle(item.column, headerParams);
643
+ const headerCellLayout = {
644
+ alignItems: "center",
645
+ display: "flex",
646
+ fontWeight: 600,
647
+ overflow: "hidden",
648
+ padding: "0 12px",
649
+ whiteSpace: "nowrap",
650
+ ...customHeaderStyle,
651
+ position: "absolute",
652
+ left: Math.round(item.offset - originX),
653
+ top: fullHeight ? -(gapRows * rowHeight) : 0,
654
+ bottom: 0,
655
+ touchAction: "none",
656
+ width: item.width,
657
+ };
658
+ 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
556
659
  ? event.stopPropagation()
557
660
  : grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey), onKeyDown: (event) => {
558
661
  if (event.key === "Enter" || event.key === " ")
559
662
  grid.headerClick(item.column.id);
560
- }, tabIndex: 0, style: {
561
- alignItems: "center",
562
- display: "flex",
563
- fontWeight: 600,
564
- overflow: "hidden",
565
- padding: "0 12px",
566
- position: "absolute",
567
- left: Math.round(item.offset - originX),
568
- top: fullHeight ? -(gapRows * rowHeight) : 0,
569
- bottom: 0,
570
- touchAction: "none",
571
- whiteSpace: "nowrap",
572
- width: item.width,
573
- }, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
663
+ }, tabIndex: 0, style: headerCellLayout, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
574
664
  registry: slotComponentsRef.current,
575
665
  context: buildRenderContext,
576
666
  })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: item.column.header ?? item.column.id }), _jsx("span", { className: "omnigrid-header-tools", children: item.column.sortState && (_jsxs("span", { className: "omnigrid-sort-indicator", "aria-hidden": "true", children: [contentToReactNode(item.column.sortState === "asc"
577
667
  ? grid.icons.get("arrow-up")
578
668
  : grid.icons.get("arrow-down"), { registry: slotComponentsRef.current, context: buildRenderContext }), item.column.sortIndex !== undefined && (_jsx("span", { className: "omnigrid-sort-priority", children: item.column.sortIndex }))] })) })] })) }, item.column.id));
579
669
  });
580
- const renderGroupCells = (depth, columns, originX) => computeGroupSegments(viewportData.columnGroups, columns, depth, originX).map((segment, index) => (_jsx("div", { role: "columnheader", className: "omnigrid-header-cell omnigrid-header-group-cell", "aria-colspan": segment.columnCount, title: segment.group.header ?? segment.group.id, style: {
670
+ const renderGroupCells = (depth, columns, originX) => computeGroupSegments(viewportData.columnGroups, columns, depth, originX).map((segment, index) => {
671
+ const groupParams = {
672
+ group: segment.group,
673
+ column: segment.group,
674
+ depth,
675
+ columnCount: segment.columnCount,
676
+ };
677
+ const className = resolveGroupHeaderClasses(segment.group, groupParams);
678
+ const customGroupStyle = resolveGroupHeaderStyle(segment.group, groupParams);
679
+ const groupCellLayout = {
581
680
  alignItems: "center",
582
681
  display: "flex",
583
682
  fontWeight: 600,
584
683
  justifyContent: "center",
585
- left: Math.round(segment.left),
586
684
  overflow: "hidden",
587
685
  padding: "0 12px",
686
+ whiteSpace: "nowrap",
687
+ ...customGroupStyle,
588
688
  position: "absolute",
689
+ left: Math.round(segment.left),
589
690
  top: 0,
590
691
  bottom: 0,
591
- whiteSpace: "nowrap",
592
692
  width: segment.width,
593
- }, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
594
- registry: slotComponentsRef.current,
595
- context: buildRenderContext,
596
- })) : (_jsx("span", { className: "omnigrid-header-label", children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`)));
693
+ };
694
+ 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), {
695
+ registry: slotComponentsRef.current,
696
+ context: buildRenderContext,
697
+ })) : (_jsx("span", { className: "omnigrid-header-label", children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
698
+ });
597
699
  /**
598
700
  * Sticky header stack: `headerRowCount` group rows (one per depth) above the
599
701
  * leaf header row. Each pane renders its own stack with the same geometry;
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export { OmniGrid } from "./OmniGrid";
7
7
  export type { GridProps, OverlayComponentProps, SlotRendererRegistry } from "./OmniGrid";
8
8
  export { useGrid } from "./useGrid";
9
9
  export type { UseGridResult } from "./useGrid";
10
+ export { type ResolvedColumnPresentation, resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export * from "@omnigrid/core";
4
4
  export { PooledRowPane } from "./pooledRow";
5
5
  export { OmniGrid } from "./OmniGrid";
6
6
  export { useGrid } from "./useGrid";
7
+ export { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
@@ -30,6 +30,16 @@ export interface PooledRowCallbacks<T> {
30
30
  onRowHover(row: PooledRow<T>, hovered: boolean): void;
31
31
  onCellClick(row: PooledRow<T>, column: ColumnLeafDef<T>, modifiers: PooledRowModifiers): void;
32
32
  createRoot(container: HTMLDivElement): CellRoot;
33
+ /**
34
+ * Returns a cheap scalar preview of the cell value, painted synchronously
35
+ * into a blank cell while its first React commit (complex content) is
36
+ * pending — keeps the grid from showing empty cells during fast scroll
37
+ * ("staging" placeholder; React's first commit replaces it entirely).
38
+ * Return `null` to skip staging for this cell.
39
+ *
40
+ * @api
41
+ */
42
+ renderCellPlaceholder?(info: PooledCellRenderInfo<T>): string | null;
33
43
  }
34
44
  /**
35
45
  * Reusable row panel: holds a fixed set of cells, lays them out for the
package/dist/pooledRow.js CHANGED
@@ -110,8 +110,11 @@ export class PooledRowPane {
110
110
  this.row = null;
111
111
  delete this.host.dataset.rowIndex;
112
112
  this.host.classList.remove("omnigrid-row-hover");
113
- for (const cell of this.cells)
114
- this.clearContent(cell);
113
+ // Do NOT clear cell content here — React roots stay mounted so the next
114
+ // bind() re-renders via root.render(newContent) as an in-place update,
115
+ // avoiding the async gap between clearing and re-rendering that causes
116
+ // visible jitter on cells with custom renderers. Roots are eventually
117
+ // GC'd by React when the row host is destroyed.
115
118
  this.hide();
116
119
  }
117
120
  ensureCells(count) {
@@ -204,7 +207,7 @@ export class PooledRowPane {
204
207
  };
205
208
  this.applyCellPresentation(cell, cellInfo);
206
209
  const content = this.callbacks.renderCellContent(cellInfo);
207
- this.applyContent(cell, content);
210
+ this.applyContent(cell, content, cellInfo);
208
211
  }
209
212
  applyCellPresentation(cell, cellInfo) {
210
213
  const cellClasses = this.callbacks.resolveCellClasses(cellInfo);
@@ -222,7 +225,7 @@ export class PooledRowPane {
222
225
  }
223
226
  }
224
227
  }
225
- applyContent(cell, content) {
228
+ applyContent(cell, content, cellInfo) {
226
229
  if (content == null) {
227
230
  this.clearContent(cell);
228
231
  return;
@@ -250,8 +253,21 @@ export class PooledRowPane {
250
253
  }
251
254
  // Everything complex (React components, CheckboxControl, SlotNode):
252
255
  // render through an isolated root. The cell node is NOT recreated.
253
- const root = cell.root ?? (cell.root = this.callbacks.createRoot(cell.element));
254
- root.render(contentToReactNode(content, this.bridge));
256
+ //
257
+ // The first commit into a fresh root is ASYNC (concurrent mode) — on
258
+ // fast scroll a newly created cell would be visibly empty for a frame
259
+ // or two. Staging: synchronously paint a cheap scalar preview first;
260
+ // React's first commit replaces the container contents entirely (see
261
+ // createRoot docs), so the placeholder never outlives the real content.
262
+ // Cells that already hold a committed root keep their (stale) content
263
+ // instead — never empty, so no placeholder is needed there.
264
+ if (!cell.root) {
265
+ const placeholder = this.callbacks.renderCellPlaceholder?.(cellInfo);
266
+ if (placeholder)
267
+ cell.element.textContent = placeholder;
268
+ cell.root = this.callbacks.createRoot(cell.element);
269
+ }
270
+ cell.root.render(contentToReactNode(content, this.bridge));
255
271
  }
256
272
  clearContent(cell) {
257
273
  if (cell.root) {
@@ -0,0 +1,94 @@
1
+ import type { CellRenderParams, ColumnGroupDef, ColumnLeafDef, ColumnStyle, ColumnStyleParams, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, RowStyle } from "@omnigrid/core";
2
+ /**
3
+ * Pre-resolved presentation (classes and inline styles) for a column data body.
4
+ * Evaluated once per column across the dataset, then applied to each rendered cell in O(1).
5
+ *
6
+ * @api
7
+ */
8
+ export interface ResolvedColumnPresentation {
9
+ /** Space-separated CSS class names for the column body. */
10
+ classes: string;
11
+ /** Combined inline styles for the column body. */
12
+ style: ColumnStyle;
13
+ }
14
+ /**
15
+ * Resolves column-level presentation once for the entire column across the entire dataset.
16
+ *
17
+ * Evaluates `getColumnStyle`, `getColumnClass`, and `columnClassRules`.
18
+ *
19
+ * @param column - Leaf column definition.
20
+ * @param params - Contextual column presentation parameters with full column values.
21
+ * @returns Pre-resolved classes and styles for the column.
22
+ * @api
23
+ */
24
+ export declare function resolveColumnPresentation<T>(column: ColumnLeafDef<T>, params: ColumnStyleParams<T>): ResolvedColumnPresentation;
25
+ /**
26
+ * Resolves the combined CSS classes for a leaf cell by combining the precomputed
27
+ * column classes with per-cell class definitions.
28
+ *
29
+ * Precedence / concatenation order:
30
+ * 1. Precomputed column classes (`getColumnClass`, `columnClassRules`)
31
+ * 2. `cellClass` (static or function)
32
+ * 3. `cellClassRules`
33
+ * 4. `getCellClass`
34
+ *
35
+ * @param column - Leaf column definition.
36
+ * @param params - Contextual cell render parameters.
37
+ * @param precomputedColumnClasses - Pre-resolved column classes (optional).
38
+ * @returns Space-separated list of CSS class names.
39
+ * @api
40
+ */
41
+ export declare function resolveCellClasses<T>(column: ColumnLeafDef<T>, params: CellRenderParams<T>, precomputedColumnClasses?: string): string;
42
+ /**
43
+ * Resolves the inline styles for a leaf cell by cascading precomputed column styles
44
+ * and cell-level style definitions. Cell-level styles take precedence over column styles.
45
+ *
46
+ * Merge order:
47
+ * 1. Precomputed column style (`getColumnStyle`)
48
+ * 2. `cellStyle`
49
+ * 3. `getCellStyle`
50
+ *
51
+ * @param column - Leaf column definition.
52
+ * @param params - Contextual cell render parameters.
53
+ * @param precomputedColumnStyle - Pre-resolved column style (optional).
54
+ * @returns Combined inline style object.
55
+ * @api
56
+ */
57
+ export declare function resolveCellStyle<T>(column: ColumnLeafDef<T>, params: CellRenderParams<T>, precomputedColumnStyle?: ColumnStyle): RowStyle;
58
+ /**
59
+ * Resolves the CSS classes for a leaf column header cell.
60
+ *
61
+ * @param column - Leaf column definition.
62
+ * @param params - Contextual header render parameters.
63
+ * @param fullHeight - Whether the header cell spans multiple group rows.
64
+ * @returns Space-separated list of CSS class names.
65
+ * @api
66
+ */
67
+ export declare function resolveHeaderClasses<T>(column: ColumnLeafDef<T>, params: HeaderRenderParams<T>, fullHeight?: boolean): string;
68
+ /**
69
+ * Resolves the inline styles for a leaf column header cell.
70
+ *
71
+ * @param column - Leaf column definition.
72
+ * @param params - Contextual header render parameters.
73
+ * @returns Combined header style object.
74
+ * @api
75
+ */
76
+ export declare function resolveHeaderStyle<T>(column: ColumnLeafDef<T>, params: HeaderRenderParams<T>): HeaderStyle;
77
+ /**
78
+ * Resolves the CSS classes for a column group header cell.
79
+ *
80
+ * @param group - Column group definition.
81
+ * @param params - Contextual group header render parameters.
82
+ * @returns Space-separated list of CSS class names.
83
+ * @api
84
+ */
85
+ export declare function resolveGroupHeaderClasses<T>(group: ColumnGroupDef<T>, params: HeaderGroupRenderParams<T>): string;
86
+ /**
87
+ * Resolves the inline styles for a column group header cell.
88
+ *
89
+ * @param group - Column group definition.
90
+ * @param params - Contextual group header render parameters.
91
+ * @returns Combined group header style object.
92
+ * @api
93
+ */
94
+ export declare function resolveGroupHeaderStyle<T>(group: ColumnGroupDef<T>, params: HeaderGroupRenderParams<T>): HeaderStyle;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Resolves column-level presentation once for the entire column across the entire dataset.
3
+ *
4
+ * Evaluates `getColumnStyle`, `getColumnClass`, and `columnClassRules`.
5
+ *
6
+ * @param column - Leaf column definition.
7
+ * @param params - Contextual column presentation parameters with full column values.
8
+ * @returns Pre-resolved classes and styles for the column.
9
+ * @api
10
+ */
11
+ export function resolveColumnPresentation(column, params) {
12
+ const dynamicColumnClass = column.getColumnClass?.(params);
13
+ const ruleClasses = Object.entries(column.columnClassRules ?? {})
14
+ .filter(([, predicate]) => predicate(params))
15
+ .map(([ruleClass]) => ruleClass);
16
+ const classes = [...ruleClasses, dynamicColumnClass].filter(Boolean).join(" ");
17
+ const style = {
18
+ ...(column.getColumnStyle?.(params) ?? {}),
19
+ };
20
+ return { classes, style };
21
+ }
22
+ /**
23
+ * Resolves the combined CSS classes for a leaf cell by combining the precomputed
24
+ * column classes with per-cell class definitions.
25
+ *
26
+ * Precedence / concatenation order:
27
+ * 1. Precomputed column classes (`getColumnClass`, `columnClassRules`)
28
+ * 2. `cellClass` (static or function)
29
+ * 3. `cellClassRules`
30
+ * 4. `getCellClass`
31
+ *
32
+ * @param column - Leaf column definition.
33
+ * @param params - Contextual cell render parameters.
34
+ * @param precomputedColumnClasses - Pre-resolved column classes (optional).
35
+ * @returns Space-separated list of CSS class names.
36
+ * @api
37
+ */
38
+ export function resolveCellClasses(column, params, precomputedColumnClasses) {
39
+ const columnClasses = precomputedColumnClasses;
40
+ const cellClass = typeof column.cellClass === "function" ? column.cellClass(params) : column.cellClass;
41
+ const dynamicCellClass = column.getCellClass?.(params);
42
+ const cellRuleClasses = Object.entries(column.cellClassRules ?? {})
43
+ .filter(([, predicate]) => predicate(params))
44
+ .map(([ruleClass]) => ruleClass);
45
+ return [columnClasses, cellClass, ...cellRuleClasses, dynamicCellClass]
46
+ .filter(Boolean)
47
+ .join(" ");
48
+ }
49
+ /**
50
+ * Resolves the inline styles for a leaf cell by cascading precomputed column styles
51
+ * and cell-level style definitions. Cell-level styles take precedence over column styles.
52
+ *
53
+ * Merge order:
54
+ * 1. Precomputed column style (`getColumnStyle`)
55
+ * 2. `cellStyle`
56
+ * 3. `getCellStyle`
57
+ *
58
+ * @param column - Leaf column definition.
59
+ * @param params - Contextual cell render parameters.
60
+ * @param precomputedColumnStyle - Pre-resolved column style (optional).
61
+ * @returns Combined inline style object.
62
+ * @api
63
+ */
64
+ export function resolveCellStyle(column, params, precomputedColumnStyle) {
65
+ const baseColumnStyle = precomputedColumnStyle;
66
+ return {
67
+ ...(baseColumnStyle ?? {}),
68
+ ...(column.cellStyle ?? {}),
69
+ ...(column.getCellStyle?.(params) ?? {}),
70
+ };
71
+ }
72
+ /**
73
+ * Resolves the CSS classes for a leaf column header cell.
74
+ *
75
+ * @param column - Leaf column definition.
76
+ * @param params - Contextual header render parameters.
77
+ * @param fullHeight - Whether the header cell spans multiple group rows.
78
+ * @returns Space-separated list of CSS class names.
79
+ * @api
80
+ */
81
+ export function resolveHeaderClasses(column, params, fullHeight = false) {
82
+ const headerClass = typeof column.headerClass === "function" ? column.headerClass(params) : column.headerClass;
83
+ const dynamicHeaderClass = column.getHeaderClass?.(params);
84
+ const ruleClasses = Object.entries(column.headerClassRules ?? {})
85
+ .filter(([, predicate]) => predicate(params))
86
+ .map(([ruleClass]) => ruleClass);
87
+ return [
88
+ "omnigrid-header-cell",
89
+ fullHeight ? "omnigrid-header-cell-full-height" : undefined,
90
+ headerClass,
91
+ ...ruleClasses,
92
+ dynamicHeaderClass,
93
+ ]
94
+ .filter(Boolean)
95
+ .join(" ");
96
+ }
97
+ /**
98
+ * Resolves the inline styles for a leaf column header cell.
99
+ *
100
+ * @param column - Leaf column definition.
101
+ * @param params - Contextual header render parameters.
102
+ * @returns Combined header style object.
103
+ * @api
104
+ */
105
+ export function resolveHeaderStyle(column, params) {
106
+ return {
107
+ ...(column.headerStyle ?? {}),
108
+ ...(column.getHeaderStyle?.(params) ?? {}),
109
+ };
110
+ }
111
+ /**
112
+ * Resolves the CSS classes for a column group header cell.
113
+ *
114
+ * @param group - Column group definition.
115
+ * @param params - Contextual group header render parameters.
116
+ * @returns Space-separated list of CSS class names.
117
+ * @api
118
+ */
119
+ export function resolveGroupHeaderClasses(group, params) {
120
+ const groupClass = typeof group.headerClass === "function" ? group.headerClass(params) : group.headerClass;
121
+ const dynamicGroupClass = group.getHeaderClass?.(params);
122
+ const ruleClasses = Object.entries(group.headerClassRules ?? {})
123
+ .filter(([, predicate]) => predicate(params))
124
+ .map(([ruleClass]) => ruleClass);
125
+ return [
126
+ "omnigrid-header-cell",
127
+ "omnigrid-header-group-cell",
128
+ groupClass,
129
+ ...ruleClasses,
130
+ dynamicGroupClass,
131
+ ]
132
+ .filter(Boolean)
133
+ .join(" ");
134
+ }
135
+ /**
136
+ * Resolves the inline styles for a column group header cell.
137
+ *
138
+ * @param group - Column group definition.
139
+ * @param params - Contextual group header render parameters.
140
+ * @returns Combined group header style object.
141
+ * @api
142
+ */
143
+ export function resolveGroupHeaderStyle(group, params) {
144
+ return {
145
+ ...(group.headerStyle ?? {}),
146
+ ...(group.getHeaderStyle?.(params) ?? {}),
147
+ };
148
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",