@omnigrid/react 0.1.21 → 0.1.23
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 +265 -28
- package/dist/controls.js +8 -0
- package/dist/pooledRow.d.ts +23 -0
- package/dist/pooledRow.js +126 -10
- package/package.json +2 -2
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 =
|
|
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
|
|
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
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
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
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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
|
-
//
|
|
712
|
-
//
|
|
713
|
-
//
|
|
714
|
-
//
|
|
715
|
-
//
|
|
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 >
|
|
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;
|
|
@@ -949,6 +1183,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
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:
|
|
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:
|
|
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
|
-
|
|
1239
|
+
bottom: 0,
|
|
1003
1240
|
left: 0,
|
|
1004
1241
|
pointerEvents: "auto",
|
|
1005
1242
|
position: "absolute",
|
package/dist/controls.js
CHANGED
|
@@ -289,6 +289,13 @@ function MultiSelectControl({ descriptor }) {
|
|
|
289
289
|
return descriptor.options.filter((opt) => opt.label.toLowerCase().includes(term) || opt.value.toLowerCase().includes(term));
|
|
290
290
|
}, [descriptor.options, searchTerm]);
|
|
291
291
|
const allChecked = useMemo(() => descriptor.options.length > 0 && descriptor.options.every((opt) => opt.checked), [descriptor.options]);
|
|
292
|
+
const someChecked = useMemo(() => descriptor.options.length > 0 && !allChecked && descriptor.options.some((opt) => opt.checked), [descriptor.options, allChecked]);
|
|
293
|
+
const selectAllRef = useRef(null);
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
if (selectAllRef.current) {
|
|
296
|
+
selectAllRef.current.indeterminate = someChecked;
|
|
297
|
+
}
|
|
298
|
+
}, [someChecked]);
|
|
292
299
|
const toggleAll = (checked) => {
|
|
293
300
|
if (checked) {
|
|
294
301
|
descriptor.onChange(descriptor.options.map((opt) => opt.value));
|
|
@@ -324,6 +331,7 @@ function MultiSelectControl({ descriptor }) {
|
|
|
324
331
|
setSearchTerm("");
|
|
325
332
|
},
|
|
326
333
|
}, "×")), createElement("div", { className: "omnigrid-multi-select-actions" }, createElement("label", { className: "omnigrid-multi-select-item" }, createElement("input", {
|
|
334
|
+
ref: selectAllRef,
|
|
327
335
|
type: "checkbox",
|
|
328
336
|
className: "omnigrid-checkbox",
|
|
329
337
|
checked: allChecked,
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -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,8 @@ export declare class PooledRowPane<T> {
|
|
|
71
72
|
* of the left + scrollable widths.
|
|
72
73
|
*/
|
|
73
74
|
private originX;
|
|
75
|
+
private variableHeight;
|
|
76
|
+
private heightMeasureId;
|
|
74
77
|
constructor(host: HTMLDivElement, callbacks: PooledRowCallbacks<T>, bridge: ContentBridge<T>);
|
|
75
78
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
76
79
|
bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
@@ -80,6 +83,25 @@ export declare class PooledRowPane<T> {
|
|
|
80
83
|
updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
81
84
|
/** Single row positioning operation — transform only (no reflow). */
|
|
82
85
|
setOffsetY(offsetY: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* Updates the row index the node stands for without touching its content.
|
|
88
|
+
*
|
|
89
|
+
* Used by the DOM pool when the node was re-used for a different row but
|
|
90
|
+
* the content could not be re-bound in the same frame (fast scroll, rebind
|
|
91
|
+
* quota): the content stays stale until the next bind, but the index has
|
|
92
|
+
* to describe the new row — the adapters look rows up by index (hover
|
|
93
|
+
* highlight), and a stale index would highlight the wrong node.
|
|
94
|
+
*/
|
|
95
|
+
setRowIndex(rowIndex: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Applies a new height to the bound row without touching its content.
|
|
98
|
+
*
|
|
99
|
+
* Used by the DOM pool when only the row HEIGHT changed (variable-height
|
|
100
|
+
* mode): the row data is still valid, so the node is resized instead of
|
|
101
|
+
* re-bound — re-binding would re-render every cell and re-trigger the
|
|
102
|
+
* height measurement.
|
|
103
|
+
*/
|
|
104
|
+
resize(height: number): void;
|
|
83
105
|
/** Moves an unused row far off-screen (outside viewport). */
|
|
84
106
|
hide(): void;
|
|
85
107
|
/** Clears content and unbinds the row, preserving DOM nodes. */
|
|
@@ -91,6 +113,7 @@ export declare class PooledRowPane<T> {
|
|
|
91
113
|
private renderContent;
|
|
92
114
|
private applyCellPresentation;
|
|
93
115
|
private applyContent;
|
|
116
|
+
private scheduleHeightMeasurement;
|
|
94
117
|
private clearContent;
|
|
95
118
|
private applyRowSizing;
|
|
96
119
|
private applyRowPresentation;
|
package/dist/pooledRow.js
CHANGED
|
@@ -41,6 +41,8 @@ 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;
|
|
44
46
|
host.classList.add("omnigrid-row");
|
|
45
47
|
host.setAttribute("role", "row");
|
|
46
48
|
host.style.position = "absolute";
|
|
@@ -67,6 +69,23 @@ export class PooledRowPane {
|
|
|
67
69
|
if (row)
|
|
68
70
|
this.callbacks.onRowHover(row, false);
|
|
69
71
|
});
|
|
72
|
+
// Variable-height mode only: the row box is resized to the measured
|
|
73
|
+
// content height, so a height change has to be reported back to the
|
|
74
|
+
// grid. In fixed-height mode no observer is installed at all — the
|
|
75
|
+
// measurement would be a pointless layout read on every resize.
|
|
76
|
+
this.variableHeight = Boolean(callbacks.onRowHeightChange);
|
|
77
|
+
if (this.variableHeight) {
|
|
78
|
+
const observer = new ResizeObserver(() => {
|
|
79
|
+
const currentRow = this.row;
|
|
80
|
+
if (!currentRow)
|
|
81
|
+
return;
|
|
82
|
+
const measured = host.scrollHeight;
|
|
83
|
+
if (Math.abs(measured - currentRow.height) < 1)
|
|
84
|
+
return;
|
|
85
|
+
this.callbacks.onRowHeightChange?.(currentRow.index, measured);
|
|
86
|
+
});
|
|
87
|
+
observer.observe(host);
|
|
88
|
+
}
|
|
70
89
|
}
|
|
71
90
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
72
91
|
bind(row, columns, originX = 0, spans) {
|
|
@@ -78,14 +97,13 @@ export class PooledRowPane {
|
|
|
78
97
|
this.host.classList.remove("omnigrid-row-hover");
|
|
79
98
|
this.originX = originX;
|
|
80
99
|
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
100
|
this.mapColumns(columns, true, spans);
|
|
86
101
|
this.applyRowPresentation(row);
|
|
87
102
|
if (hovered)
|
|
88
103
|
this.callbacks.onRowHover(row, true);
|
|
104
|
+
if (this.variableHeight) {
|
|
105
|
+
this.scheduleHeightMeasurement(row);
|
|
106
|
+
}
|
|
89
107
|
}
|
|
90
108
|
/** Returns the currently bound row, if any. */
|
|
91
109
|
getRow() {
|
|
@@ -98,11 +116,41 @@ export class PooledRowPane {
|
|
|
98
116
|
if (row)
|
|
99
117
|
this.applyRowSizing(row);
|
|
100
118
|
this.mapColumns(columns, false, spans);
|
|
119
|
+
if (this.variableHeight && row) {
|
|
120
|
+
this.scheduleHeightMeasurement(row);
|
|
121
|
+
}
|
|
101
122
|
}
|
|
102
123
|
/** Single row positioning operation — transform only (no reflow). */
|
|
103
124
|
setOffsetY(offsetY) {
|
|
104
125
|
this.host.style.transform = `translate3d(0, ${Math.round(offsetY)}px, 0)`;
|
|
105
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Updates the row index the node stands for without touching its content.
|
|
129
|
+
*
|
|
130
|
+
* Used by the DOM pool when the node was re-used for a different row but
|
|
131
|
+
* the content could not be re-bound in the same frame (fast scroll, rebind
|
|
132
|
+
* quota): the content stays stale until the next bind, but the index has
|
|
133
|
+
* to describe the new row — the adapters look rows up by index (hover
|
|
134
|
+
* highlight), and a stale index would highlight the wrong node.
|
|
135
|
+
*/
|
|
136
|
+
setRowIndex(rowIndex) {
|
|
137
|
+
this.host.dataset.rowIndex = String(rowIndex);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Applies a new height to the bound row without touching its content.
|
|
141
|
+
*
|
|
142
|
+
* Used by the DOM pool when only the row HEIGHT changed (variable-height
|
|
143
|
+
* mode): the row data is still valid, so the node is resized instead of
|
|
144
|
+
* re-bound — re-binding would re-render every cell and re-trigger the
|
|
145
|
+
* height measurement.
|
|
146
|
+
*/
|
|
147
|
+
resize(height) {
|
|
148
|
+
const row = this.row;
|
|
149
|
+
if (!row || row.height === height)
|
|
150
|
+
return;
|
|
151
|
+
row.height = height;
|
|
152
|
+
this.applyRowSizing(row);
|
|
153
|
+
}
|
|
106
154
|
/** Moves an unused row far off-screen (outside viewport). */
|
|
107
155
|
hide() {
|
|
108
156
|
this.host.style.transform = `translate3d(0, ${OFFSCREEN_Y}px, 0)`;
|
|
@@ -180,6 +228,20 @@ export class PooledRowPane {
|
|
|
180
228
|
cell.offsetX = offset;
|
|
181
229
|
cell.width = layout.width;
|
|
182
230
|
}
|
|
231
|
+
// Wrapping cells are sized by their CONTENT (the row height is
|
|
232
|
+
// measured from them), every other cell fills the row. The NEW column
|
|
233
|
+
// decides — a pooled cell can be recycled from a wrapping column into
|
|
234
|
+
// a plain one, and the leftover styles would break the row layout.
|
|
235
|
+
// Only the sizing is touched here: alignment and padding stay with the
|
|
236
|
+
// theme.
|
|
237
|
+
if (this.variableHeight && layout.column.wrapText) {
|
|
238
|
+
element.style.height = "auto";
|
|
239
|
+
element.style.minHeight = "100%";
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
element.style.height = "100%";
|
|
243
|
+
element.style.minHeight = "";
|
|
244
|
+
}
|
|
183
245
|
if (cell.justify !== justify) {
|
|
184
246
|
element.style.justifyContent = justify;
|
|
185
247
|
cell.justify = justify;
|
|
@@ -192,7 +254,7 @@ export class PooledRowPane {
|
|
|
192
254
|
element.style.top = "0";
|
|
193
255
|
element.style.left = "0";
|
|
194
256
|
element.style.overflow = "hidden";
|
|
195
|
-
element.style.height =
|
|
257
|
+
element.style.height = "100%";
|
|
196
258
|
this.host.appendChild(element);
|
|
197
259
|
const cell = {
|
|
198
260
|
element,
|
|
@@ -249,6 +311,27 @@ export class PooledRowPane {
|
|
|
249
311
|
cell.appliedStyleKeys.push(key);
|
|
250
312
|
}
|
|
251
313
|
}
|
|
314
|
+
if (cell.column?.wrapText) {
|
|
315
|
+
// Wrapping cell: the text breaks into several lines and the cell
|
|
316
|
+
// grows with it. The theme owns the horizontal padding and the
|
|
317
|
+
// alignment — only the text flow and the vertical padding of the
|
|
318
|
+
// wrapped block are overridden.
|
|
319
|
+
cell.element.style.whiteSpace = "normal";
|
|
320
|
+
cell.element.style.wordBreak = "break-word";
|
|
321
|
+
cell.element.style.overflow = "visible";
|
|
322
|
+
cell.element.style.textOverflow = "clip";
|
|
323
|
+
cell.element.style.paddingBlock = "4px";
|
|
324
|
+
cell.element.style.alignItems = "flex-start";
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
// Reset the wrapping styles: the cell may be pooled from a
|
|
328
|
+
// wrapping column.
|
|
329
|
+
cell.element.style.whiteSpace = "nowrap";
|
|
330
|
+
cell.element.style.overflow = "hidden";
|
|
331
|
+
cell.element.style.textOverflow = "ellipsis";
|
|
332
|
+
cell.element.style.paddingBlock = "";
|
|
333
|
+
cell.element.style.alignItems = "";
|
|
334
|
+
}
|
|
252
335
|
}
|
|
253
336
|
applyContent(cell, content, cellInfo) {
|
|
254
337
|
if (content == null) {
|
|
@@ -294,6 +377,27 @@ export class PooledRowPane {
|
|
|
294
377
|
}
|
|
295
378
|
cell.root.render(contentToReactNode(content, this.bridge));
|
|
296
379
|
}
|
|
380
|
+
scheduleHeightMeasurement(row) {
|
|
381
|
+
const id = ++this.heightMeasureId;
|
|
382
|
+
const measure = () => {
|
|
383
|
+
if (id !== this.heightMeasureId)
|
|
384
|
+
return;
|
|
385
|
+
if (this.row?.index !== row.index)
|
|
386
|
+
return;
|
|
387
|
+
const measured = this.host.scrollHeight;
|
|
388
|
+
if (measured > 0 && Math.abs(measured - this.row.height) > 1) {
|
|
389
|
+
this.callbacks.onRowHeightChange?.(this.row.index, measured);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
// The rAF callback runs before the layout of its frame — reading
|
|
393
|
+
// `scrollHeight` there forces the layout of the freshly bound content.
|
|
394
|
+
// The second pass catches the React commit of complex cell content,
|
|
395
|
+
// which lands a frame later.
|
|
396
|
+
requestAnimationFrame(() => {
|
|
397
|
+
measure();
|
|
398
|
+
requestAnimationFrame(measure);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
297
401
|
clearContent(cell) {
|
|
298
402
|
if (cell.root) {
|
|
299
403
|
// Keep the root mounted while the pooled cell is reused. Calling
|
|
@@ -305,14 +409,26 @@ export class PooledRowPane {
|
|
|
305
409
|
}
|
|
306
410
|
}
|
|
307
411
|
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
412
|
if (row.width > 0)
|
|
313
413
|
this.host.style.width = `${row.width}px`;
|
|
314
|
-
if (
|
|
414
|
+
if (this.variableHeight) {
|
|
415
|
+
// The virtualizer owns the row geometry: the node is sized to the
|
|
416
|
+
// height the virtualizer reserved for this row and CLIPS its
|
|
417
|
+
// content. Content taller than the reserved slot (the measurement
|
|
418
|
+
// has not arrived yet) is cut off instead of bleeding into the
|
|
419
|
+
// next row — otherwise rows overlap and the grid degenerates
|
|
420
|
+
// into a pile of overlapping lines while scrolling.
|
|
315
421
|
this.host.style.height = `${row.height}px`;
|
|
422
|
+
this.host.style.minHeight = "";
|
|
423
|
+
this.host.style.overflow = "hidden";
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.host.style.overflow = "";
|
|
427
|
+
if (row.height > 0) {
|
|
428
|
+
this.host.style.height = `${row.height}px`;
|
|
429
|
+
this.host.style.minHeight = "";
|
|
430
|
+
}
|
|
431
|
+
}
|
|
316
432
|
}
|
|
317
433
|
applyRowPresentation(row) {
|
|
318
434
|
this.host.className = this.callbacks.resolveRowClasses(row) ?? "omnigrid-row";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigrid/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "React adapter and renderer for OmniGrid",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omnigrid",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@omnigrid/default-theme": "^0.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@omnigrid/
|
|
48
|
+
"@omnigrid/column-filter-plugin": "*",
|
|
49
49
|
"@omnigrid/quick-filter-plugin": "*",
|
|
50
50
|
"@types/react": "^19.0.0",
|
|
51
51
|
"@types/react-dom": "^19.0.0"
|