@omnigrid/react 0.1.14 → 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 +111 -38
- package/dist/pooledRow.d.ts +10 -0
- package/dist/pooledRow.js +22 -6
- package/package.json +1 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -64,7 +64,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
64
64
|
const pinnedLeftRowsLayerRef = useRef(null);
|
|
65
65
|
const pinnedRightRowsLayerRef = useRef(null);
|
|
66
66
|
const [isMeasured, setIsMeasured] = useState(false);
|
|
67
|
-
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);
|
|
68
69
|
const optionsRef = useRef(options);
|
|
69
70
|
const columnWindowKeyRef = useRef("");
|
|
70
71
|
const scrollbarWidthRef = useRef(0);
|
|
@@ -176,6 +177,21 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
176
177
|
}
|
|
177
178
|
return column.valueFormatter ? column.valueFormatter(value) : String(value ?? "");
|
|
178
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
|
+
},
|
|
179
195
|
resolveRowClasses: (row) => {
|
|
180
196
|
const rowParams = { id: row.rowId, index: row.index, data: row.data };
|
|
181
197
|
const currentOptions = current();
|
|
@@ -283,36 +299,48 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
283
299
|
* Synchronises a single column-group layer with the grid: lazily creates its
|
|
284
300
|
* DomPool, invalidates on structural changes, then pushes the current row
|
|
285
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.
|
|
286
305
|
*/
|
|
287
|
-
const syncRowLayer = (layer, rowsLayerRef) => {
|
|
306
|
+
const syncRowLayer = (layer, viewportData, rowsLayerRef, skipBind = false) => {
|
|
288
307
|
const bridge = ensureLayerContext();
|
|
289
308
|
ensureLayerPool(layer, rowsLayerRef.current, bridge);
|
|
290
309
|
const pool = layer.pool;
|
|
291
310
|
if (!pool || grid.isDestroyed())
|
|
292
311
|
return;
|
|
293
312
|
const state = grid.getState();
|
|
294
|
-
const currentViewportData = grid.getViewportData();
|
|
295
313
|
const processed = grid.getProcessedData();
|
|
296
|
-
const changed = layer.revision !== grid.getRevision() || layer.totalWidth !==
|
|
314
|
+
const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || layer.processed !== processed;
|
|
297
315
|
if (changed) {
|
|
298
316
|
layer.revision = grid.getRevision();
|
|
299
|
-
layer.totalWidth =
|
|
317
|
+
layer.totalWidth = viewportData.totalWidth;
|
|
300
318
|
layer.processed = processed;
|
|
301
319
|
pool.invalidate();
|
|
302
320
|
}
|
|
303
321
|
pool.update({
|
|
304
322
|
data: processed,
|
|
305
|
-
rowRange:
|
|
323
|
+
rowRange: viewportData.rowRange,
|
|
306
324
|
rowHeight: state.rowHeight,
|
|
307
325
|
rowWidth: layer.rowWidth,
|
|
326
|
+
skipBind,
|
|
308
327
|
});
|
|
309
328
|
};
|
|
310
329
|
/**
|
|
311
330
|
* Synchronises the DomPools with the grid. Idempotent — called both from
|
|
312
331
|
* React effects (structural changes) and directly from the scroll rAF
|
|
313
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.
|
|
314
342
|
*/
|
|
315
|
-
const syncPool = (synchronousColumnWindow = false) => {
|
|
343
|
+
const syncPool = (synchronousColumnWindow = false, skipContentBind = false) => {
|
|
316
344
|
const state = grid.getState();
|
|
317
345
|
const currentViewportData = grid.getViewportData();
|
|
318
346
|
const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
@@ -330,29 +358,62 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
330
358
|
layers.right.columns = currentViewportData.pinnedRightColumns;
|
|
331
359
|
layers.right.originX = pinnedLeftWidth + scrollableWidth;
|
|
332
360
|
layers.right.rowWidth = pinnedRightWidth;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
+
}
|
|
336
390
|
// The horizontal column window changes infrequently (only when
|
|
337
391
|
// crossing column boundaries). When it does, update central row cells
|
|
338
392
|
// imperatively AND trigger a targeted React re-render for the header.
|
|
339
393
|
// Pinned panes hold all their columns at once — they only rebind via
|
|
340
394
|
// the structural path above (revision bump).
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
+
}
|
|
356
417
|
}
|
|
357
418
|
}
|
|
358
419
|
};
|
|
@@ -409,22 +470,27 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
409
470
|
}, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport, overlayScope]);
|
|
410
471
|
/**
|
|
411
472
|
* Sync the DomPool after every structural re-render.
|
|
412
|
-
*
|
|
413
|
-
*
|
|
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.
|
|
414
480
|
*
|
|
415
481
|
* Adapter options (rowClassRules closures, getRowStyle, plugins) can
|
|
416
482
|
* change between renders WITHOUT touching the grid revision or the data
|
|
417
483
|
* reference — e.g. a rule toggled by a useState in the host component.
|
|
418
484
|
* Force-rebind the visible nodes so row classes/styles are re-evaluated
|
|
419
|
-
* with the fresh options on
|
|
485
|
+
* with the fresh options on structural re-renders.
|
|
420
486
|
*/
|
|
421
487
|
useEffect(() => {
|
|
422
488
|
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
423
489
|
if (layer.pool)
|
|
424
490
|
layer.pool.invalidate();
|
|
425
491
|
}
|
|
426
|
-
syncPool();
|
|
427
|
-
});
|
|
492
|
+
syncPool(false, false); // skipContentBind=false: structural changes always bind fully
|
|
493
|
+
}, [state]);
|
|
428
494
|
useEffect(() => {
|
|
429
495
|
return () => {
|
|
430
496
|
if (scrollFrameRef.current.id)
|
|
@@ -467,16 +533,23 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
467
533
|
const element = viewportRef.current;
|
|
468
534
|
const scrollTop = element ? element.scrollTop : frame.top;
|
|
469
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;
|
|
470
547
|
// setViewport with scroll-only updates does NOT notify the Store,
|
|
471
548
|
// so this does NOT trigger a React re-render. The DomPool is
|
|
472
|
-
// updated imperatively below
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
flushSync(() => {
|
|
477
|
-
grid.setViewport({ scrollTop, scrollLeft });
|
|
478
|
-
syncPool(true);
|
|
479
|
-
});
|
|
549
|
+
// updated imperatively below.
|
|
550
|
+
grid.setViewport({ scrollTop, scrollLeft });
|
|
551
|
+
const skipContentBind = scrollVelocityRef.current > 2.0;
|
|
552
|
+
syncPool(true, skipContentBind);
|
|
480
553
|
});
|
|
481
554
|
};
|
|
482
555
|
if (!isMeasured) {
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -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
|
-
|
|
114
|
-
|
|
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
|
-
|
|
254
|
-
root
|
|
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) {
|