@omnigrid/react 0.1.31 → 0.1.32
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/README.md +11 -0
- package/dist/OmniGrid.js +142 -141
- package/dist/controls.js +36 -8
- package/dist/pooledRow.d.ts +8 -0
- package/dist/pooledRow.js +35 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,17 @@ const data = [...];
|
|
|
22
22
|
<OmniGrid columns={columns} data={data} />;
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
Set `animateRows` to animate visible rows when filtering or sorting changes their
|
|
26
|
+
positions. Row animation uses a separate CSS transform component, so virtualized
|
|
27
|
+
positioning and scrolling remain independent. It is disabled by default; provide
|
|
28
|
+
a stable `getRowId` to animate rows reliably across reorderings.
|
|
29
|
+
|
|
30
|
+
During fast vertical scrolling, the React adapter keeps the current row pool
|
|
31
|
+
visually in place while the native scrollbar continues moving. It repositions
|
|
32
|
+
the existing row layers rather than creating a second copy of the rows, then
|
|
33
|
+
updates the pool after scrolling has been idle for 150 ms. The core tracks the
|
|
34
|
+
live scroll position without store notifications or scroll-driven React renders.
|
|
35
|
+
|
|
25
36
|
Column `headerRenderer` callbacks provide the header's primary content. The adapter owns the
|
|
26
37
|
shared header layout and keeps sorting, filtering, and registered plugin extensions alongside it,
|
|
27
38
|
so plugins can add controls without replacing or duplicating the header renderer.
|
package/dist/OmniGrid.js
CHANGED
|
@@ -27,18 +27,11 @@ function getPoolData(grid) {
|
|
|
27
27
|
}
|
|
28
28
|
const SLOT_POSITIONS = ["start", "center", "end"];
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* scrollbar thumb drags and page jumps exceed 10 px/ms.
|
|
30
|
+
* How long after the last scroll event row-height anchoring corrections remain
|
|
31
|
+
* deferred, so they cannot fight active user input.
|
|
33
32
|
*/
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
* How long (ms) after the last processed scroll frame the fast-scroll state
|
|
37
|
-
* is kept. The velocity is only sampled on scroll frames, so it has to be
|
|
38
|
-
* aged out explicitly — otherwise a single fast flick would keep the grid in
|
|
39
|
-
* fast-scroll mode forever.
|
|
40
|
-
*/
|
|
41
|
-
const FAST_SCROLL_WINDOW = 150;
|
|
33
|
+
const SCROLL_IDLE_WINDOW = 150;
|
|
34
|
+
const COLUMN_DRAG_TYPE = "application/x-omnigrid-column";
|
|
42
35
|
function createRowLayerState() {
|
|
43
36
|
return {
|
|
44
37
|
pool: null,
|
|
@@ -51,6 +44,7 @@ function createRowLayerState() {
|
|
|
51
44
|
processed: null,
|
|
52
45
|
originX: 0,
|
|
53
46
|
rowWidth: 0,
|
|
47
|
+
animationPositions: null,
|
|
54
48
|
viewport: null,
|
|
55
49
|
};
|
|
56
50
|
}
|
|
@@ -108,13 +102,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
108
102
|
id: 0,
|
|
109
103
|
top: 0,
|
|
110
104
|
left: 0,
|
|
111
|
-
lastTop: 0,
|
|
112
|
-
lastTime: 0,
|
|
113
105
|
});
|
|
114
|
-
|
|
115
|
-
/** Timestamp of the last processed scroll frame — used to age out the velocity. */
|
|
106
|
+
/** Timestamp of the last scroll event, used to defer row-height anchoring until idle. */
|
|
116
107
|
const lastScrollTimeRef = useRef(0);
|
|
117
|
-
/** Anchoring correction accumulated while
|
|
108
|
+
/** Anchoring correction accumulated while the user is scrolling. */
|
|
118
109
|
const pendingAnchorRef = useRef(0);
|
|
119
110
|
/** Timer that applies the accumulated anchoring correction after the scroll settles. */
|
|
120
111
|
const anchorTimerRef = useRef(null);
|
|
@@ -126,18 +117,6 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
126
117
|
const heightFlushRef = useRef(null);
|
|
127
118
|
/** Latest `syncPool` — read imperatively from `measureViewport`/ResizeObserver so the callback stays stable. */
|
|
128
119
|
const syncPoolRef = useRef(null);
|
|
129
|
-
/**
|
|
130
|
-
* Scrollable content height frozen at the start of a user scroll gesture.
|
|
131
|
-
*
|
|
132
|
-
* While the user drags the scrollbar thumb, measured row heights keep
|
|
133
|
-
* replacing estimates and `totalHeight` changes every frame. Rewriting the
|
|
134
|
-
* content height mid-drag makes the browser reposition the native
|
|
135
|
-
* scrollbar thumb (`scrollTop / (scrollHeight - clientHeight)`), so the
|
|
136
|
-
* thumb detaches from the mouse on the very first scroll of a
|
|
137
|
-
* variable-height grid. The height is therefore frozen to this snapshot
|
|
138
|
-
* for the duration of the gesture — row positions still use the measured
|
|
139
|
-
* offsets — and the real height is reapplied once the scroll settles.
|
|
140
|
-
*/
|
|
141
120
|
const optionsRef = useRef(options);
|
|
142
121
|
const columnWindowKeyRef = useRef("");
|
|
143
122
|
/** Content size the scrollbar insets were measured for. */
|
|
@@ -436,20 +415,12 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
436
415
|
columnPresentationCacheRef.current.set(column.id, { revision, data: processedData, presentation });
|
|
437
416
|
return presentation;
|
|
438
417
|
};
|
|
439
|
-
/**
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
* The velocity is sampled on scroll frames only, so it is aged out: when
|
|
443
|
-
* the last scroll frame is older than `FAST_SCROLL_WINDOW` the scroll has
|
|
444
|
-
* settled and the grid returns to its normal (fully bound) mode.
|
|
445
|
-
*/
|
|
446
|
-
function isFastScrolling() {
|
|
447
|
-
if (scrollVelocityRef.current <= FAST_SCROLL_VELOCITY)
|
|
448
|
-
return false;
|
|
449
|
-
return performance.now() - lastScrollTimeRef.current < FAST_SCROLL_WINDOW;
|
|
418
|
+
/** Whether a scroll event occurred recently enough that anchoring would fight user input. */
|
|
419
|
+
function isScrollActive() {
|
|
420
|
+
return performance.now() - lastScrollTimeRef.current < SCROLL_IDLE_WINDOW;
|
|
450
421
|
}
|
|
451
422
|
/**
|
|
452
|
-
* Applies the anchoring corrections that were deferred
|
|
423
|
+
* Applies the anchoring corrections that were deferred while scrolling.
|
|
453
424
|
*
|
|
454
425
|
* A row ABOVE the viewport that changes its height shifts the content
|
|
455
426
|
* below it. While the user drags the scrollbar that correction fights the
|
|
@@ -462,9 +433,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
462
433
|
const pending = pendingAnchorRef.current;
|
|
463
434
|
if (pending === 0)
|
|
464
435
|
return;
|
|
465
|
-
if (
|
|
436
|
+
if (isScrollActive()) {
|
|
466
437
|
// The user started scrolling again — the correction stays pending.
|
|
467
|
-
anchorTimerRef.current = window.setTimeout(flushPendingAnchor,
|
|
438
|
+
anchorTimerRef.current = window.setTimeout(flushPendingAnchor, SCROLL_IDLE_WINDOW);
|
|
468
439
|
return;
|
|
469
440
|
}
|
|
470
441
|
pendingAnchorRef.current = 0;
|
|
@@ -472,11 +443,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
472
443
|
const current = element ? element.scrollTop : grid.getScrollPosition().scrollTop;
|
|
473
444
|
grid.scrollTo({ scrollTop: Math.max(0, current + pending) });
|
|
474
445
|
}
|
|
475
|
-
/** Schedules the
|
|
446
|
+
/** Schedules the anchoring flush after scrolling has settled. */
|
|
476
447
|
function scheduleAnchorFlush() {
|
|
477
448
|
if (anchorTimerRef.current !== null)
|
|
478
449
|
window.clearTimeout(anchorTimerRef.current);
|
|
479
|
-
anchorTimerRef.current = window.setTimeout(flushPendingAnchor,
|
|
450
|
+
anchorTimerRef.current = window.setTimeout(flushPendingAnchor, SCROLL_IDLE_WINDOW);
|
|
480
451
|
}
|
|
481
452
|
/**
|
|
482
453
|
* Applies the row heights measured during the current frame.
|
|
@@ -498,11 +469,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
498
469
|
if (measured === 0)
|
|
499
470
|
return;
|
|
500
471
|
pendingHeightCountRef.current = 0;
|
|
501
|
-
const
|
|
472
|
+
const scrolling = isScrollActive();
|
|
502
473
|
const correction = pendingHeightCorrectionRef.current;
|
|
503
474
|
pendingHeightCorrectionRef.current = 0;
|
|
504
475
|
if (correction !== 0) {
|
|
505
|
-
if (
|
|
476
|
+
if (scrolling) {
|
|
506
477
|
// The correction fights the user's input while they are
|
|
507
478
|
// scrolling — it is applied once the scroll settles.
|
|
508
479
|
pendingAnchorRef.current += correction;
|
|
@@ -516,7 +487,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
516
487
|
}
|
|
517
488
|
// The measured heights changed the offsets of the rows below: push the
|
|
518
489
|
// new geometry into the pools.
|
|
519
|
-
syncPool(false
|
|
490
|
+
syncPool(false);
|
|
520
491
|
}
|
|
521
492
|
/** Schedules the row-height flush for the next frame. */
|
|
522
493
|
function scheduleHeightFlush() {
|
|
@@ -759,6 +730,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
759
730
|
// (scrollable) while pinned layers render their full group.
|
|
760
731
|
const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
|
|
761
732
|
pane.bind(paneRow, layer.columns, layer.originX, sliced);
|
|
733
|
+
const previousOffsetY = layer.animationPositions?.get(row.rowId);
|
|
734
|
+
if (previousOffsetY !== undefined)
|
|
735
|
+
pane.animateFrom(previousOffsetY);
|
|
762
736
|
},
|
|
763
737
|
resizeRow: (host, height) => {
|
|
764
738
|
const pane = paneMap.get(host);
|
|
@@ -791,7 +765,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
791
765
|
* Receives the pre-computed `viewportData` from `syncPool` to avoid redundant
|
|
792
766
|
* getViewportData() calls — each layer no longer recomputes column geometry.
|
|
793
767
|
*/
|
|
794
|
-
const syncRowLayer = (layer, viewportData, rowsLayerRef
|
|
768
|
+
const syncRowLayer = (layer, viewportData, rowsLayerRef) => {
|
|
795
769
|
const bridge = ensureLayerContext();
|
|
796
770
|
ensureLayerPool(layer, rowsLayerRef.current, bridge);
|
|
797
771
|
const pool = layer.pool;
|
|
@@ -799,9 +773,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
799
773
|
return;
|
|
800
774
|
const state = grid.getState();
|
|
801
775
|
const processed = getPoolData(grid);
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
|
|
776
|
+
const processedChanged = layer.processed !== processed;
|
|
777
|
+
const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || processedChanged;
|
|
778
|
+
const shouldAnimate = Boolean(options.animateRows && layer.processed !== null && processedChanged);
|
|
779
|
+
const animationPositions = shouldAnimate
|
|
780
|
+
? new Map(layer.panes.flatMap((pane) => {
|
|
781
|
+
const row = pane.getRow();
|
|
782
|
+
return row ? [[row.rowId, pane.getOffsetY()]] : [];
|
|
783
|
+
}))
|
|
784
|
+
: null;
|
|
805
785
|
if (changed) {
|
|
806
786
|
layer.revision = grid.getRevision();
|
|
807
787
|
layer.totalWidth = viewportData.totalWidth;
|
|
@@ -810,6 +790,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
810
790
|
}
|
|
811
791
|
// Cached for the row binds below — the viewport data of THIS sync.
|
|
812
792
|
layer.viewport = viewportData;
|
|
793
|
+
layer.animationPositions = animationPositions;
|
|
813
794
|
pool.update({
|
|
814
795
|
data: processed,
|
|
815
796
|
rowRange: viewportData.rowRange,
|
|
@@ -818,8 +799,8 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
818
799
|
rowHeights: viewportData.rowHeights,
|
|
819
800
|
visibleRowRange: viewportData.visibleRowRange,
|
|
820
801
|
rowWidth: layer.rowWidth,
|
|
821
|
-
skipBind,
|
|
822
802
|
});
|
|
803
|
+
layer.animationPositions = null;
|
|
823
804
|
};
|
|
824
805
|
/**
|
|
825
806
|
* Synchronises the DomPools with the grid. Idempotent — called both from
|
|
@@ -829,31 +810,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
829
810
|
* @param synchronousColumnWindow — when `true`, the rAF-driven scroll path
|
|
830
811
|
* triggers a `flushSync` for the column window header update so headers
|
|
831
812
|
* stay in step with the imperatively repositioned cells before paint.
|
|
832
|
-
* @param skipContentBind — when `true` (fast scroll), row positions are
|
|
833
|
-
* updated but `bindRow` is deferred to the next slow-scroll frame. This
|
|
834
|
-
* avoids synchronous React commits (~200 cell roots) that exceed the 16ms
|
|
835
|
-
* frame budget, causing flicker/frame drops. Rows remain visible with
|
|
836
|
-
* previous content at the correct new position.
|
|
837
813
|
*/
|
|
838
|
-
const syncPool = (synchronousColumnWindow = false
|
|
814
|
+
const syncPool = (synchronousColumnWindow = false) => {
|
|
839
815
|
const state = grid.getState();
|
|
840
816
|
const currentViewportData = grid.getViewportData();
|
|
841
817
|
// The scrollable content height follows the measured row heights.
|
|
842
818
|
// It is written imperatively: a Store notification per measured row
|
|
843
819
|
// would re-render the whole grid, and the grid would then lag behind
|
|
844
820
|
// the native scroll position (the user sees the previous rows).
|
|
845
|
-
|
|
846
|
-
// During an active user scroll gesture the height is frozen to the
|
|
847
|
-
// snapshot taken at gesture start (see `handleScroll`). Otherwise the
|
|
848
|
-
// browser recomputes the scrollbar thumb (`scrollTop /
|
|
849
|
-
// (scrollHeight - clientHeight)`) every time a measured row height
|
|
850
|
-
// replaces an estimate and `totalHeight` changes mid-drag — on the
|
|
851
|
-
// first scroll of a variable-height grid the thumb then lags behind
|
|
852
|
-
// the mouse pointer. Row positions still use the live measured
|
|
853
|
-
// offsets; only the scrollbar range is frozen until the scroll
|
|
854
|
-
// settles.
|
|
855
|
-
const effectiveTotalHeight = currentViewportData.totalHeight;
|
|
856
|
-
applyContentHeight(effectiveTotalHeight);
|
|
821
|
+
applyContentHeight(currentViewportData.totalHeight);
|
|
857
822
|
const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
858
823
|
const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
859
824
|
const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
@@ -871,28 +836,14 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
871
836
|
layers.right.rowWidth = pinnedRightWidth;
|
|
872
837
|
// Cell content rendering (root.render) is async under React concurrent
|
|
873
838
|
// mode — without flushSync, rows are repositioned but their cell content
|
|
874
|
-
// stays stale for one frame
|
|
875
|
-
//
|
|
876
|
-
// commit before paint.
|
|
877
|
-
//
|
|
878
|
-
// Velocity-based: during fast scroll (scrollbar thumb drag), many scroll
|
|
879
|
-
// events fire but rAF throttles to ~60fps. Calling flushSync on every frame
|
|
880
|
-
// forces a synchronous React commit for ALL cell roots (~200 calls), which
|
|
881
|
-
// can exceed the 16ms frame budget and cause frame drops — appearing as
|
|
882
|
-
// flickering/emptying. During fast scroll, we skip flushSync: rows stay
|
|
883
|
-
// at correct positions with previous content (we don't clear content on
|
|
884
|
-
// recycle), so the table is never empty — just 1-frame stale, which is
|
|
885
|
-
// imperceptible during rapid scroll. When velocity drops, flushSync resumes
|
|
886
|
-
// for frame-perfect content. The structural path (useEffect) always uses
|
|
887
|
-
// flushSync for correctness.
|
|
888
|
-
// getViewportData() above runs outside flushSync since column geometry
|
|
889
|
-
// caching makes it fast, avoiding blocking on computation.
|
|
839
|
+
// stays stale for one frame. Wrap only the DOM binding in flushSync so
|
|
840
|
+
// cell roots commit before paint.
|
|
890
841
|
const bindLayers = () => {
|
|
891
|
-
syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef
|
|
892
|
-
syncRowLayer(layers.central, currentViewportData, rowsLayerRef
|
|
893
|
-
syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef
|
|
842
|
+
syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef);
|
|
843
|
+
syncRowLayer(layers.central, currentViewportData, rowsLayerRef);
|
|
844
|
+
syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef);
|
|
894
845
|
};
|
|
895
|
-
if (synchronousColumnWindow
|
|
846
|
+
if (synchronousColumnWindow) {
|
|
896
847
|
flushSync(bindLayers);
|
|
897
848
|
}
|
|
898
849
|
else {
|
|
@@ -904,37 +855,31 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
904
855
|
// Pinned panes hold all their columns at once — they only rebind via
|
|
905
856
|
// the structural path above (revision bump).
|
|
906
857
|
//
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
for (const pane of layers.central.panes) {
|
|
920
|
-
const paneRow = pane.getRow();
|
|
921
|
-
if (!paneRow) {
|
|
922
|
-
pane.updateColumns(layers.central.columns, layers.central.originX, null);
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
|
|
926
|
-
pane.updateColumns(layers.central.columns, layers.central.originX, sliceSpanLayoutForLayer(currentViewportData, layers.central.columns, true, spans.central));
|
|
858
|
+
const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
|
|
859
|
+
if (columnWindowKey !== columnWindowKeyRef.current) {
|
|
860
|
+
columnWindowKeyRef.current = columnWindowKey;
|
|
861
|
+
const updateColumnWindow = () => {
|
|
862
|
+
// Span-aware: each pane resolves its own row's layout so
|
|
863
|
+
// merged cells keep their summed width while the window
|
|
864
|
+
// slides — covered leaves stay parked off-screen.
|
|
865
|
+
for (const pane of layers.central.panes) {
|
|
866
|
+
const paneRow = pane.getRow();
|
|
867
|
+
if (!paneRow) {
|
|
868
|
+
pane.updateColumns(layers.central.columns, layers.central.originX, null);
|
|
869
|
+
continue;
|
|
927
870
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if (synchronousColumnWindow) {
|
|
931
|
-
// Keep React-rendered cell content and headers in step with the
|
|
932
|
-
// imperative cell repositioning before the browser paints.
|
|
933
|
-
flushSync(updateColumnWindow);
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
updateColumnWindow();
|
|
871
|
+
const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
|
|
872
|
+
pane.updateColumns(layers.central.columns, layers.central.originX, sliceSpanLayoutForLayer(currentViewportData, layers.central.columns, true, spans.central));
|
|
937
873
|
}
|
|
874
|
+
setColumnWindowVersion((v) => v + 1);
|
|
875
|
+
};
|
|
876
|
+
if (synchronousColumnWindow) {
|
|
877
|
+
// Keep React-rendered cell content and headers in step with the
|
|
878
|
+
// imperative cell repositioning before the browser paints.
|
|
879
|
+
flushSync(updateColumnWindow);
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
updateColumnWindow();
|
|
938
883
|
}
|
|
939
884
|
}
|
|
940
885
|
};
|
|
@@ -976,7 +921,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
976
921
|
width,
|
|
977
922
|
...(height > 0 ? { height } : {}),
|
|
978
923
|
});
|
|
979
|
-
syncPoolRef.current?.(false
|
|
924
|
+
syncPoolRef.current?.(false);
|
|
980
925
|
setIsViewportMeasured(true);
|
|
981
926
|
}, [grid, syncScrollbarInsets, setIsViewportMeasured]);
|
|
982
927
|
useEffect(() => {
|
|
@@ -995,7 +940,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
995
940
|
if (width === 0 || height === 0)
|
|
996
941
|
return;
|
|
997
942
|
grid.setViewport({ width, height });
|
|
998
|
-
syncPoolRef.current?.(false
|
|
943
|
+
syncPoolRef.current?.(false);
|
|
999
944
|
setIsViewportMeasured(true);
|
|
1000
945
|
});
|
|
1001
946
|
observer.observe(element, { box: "content-box" });
|
|
@@ -1066,12 +1011,22 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1066
1011
|
layer.pool.invalidate();
|
|
1067
1012
|
}
|
|
1068
1013
|
}
|
|
1069
|
-
syncPool(false
|
|
1014
|
+
syncPool(false);
|
|
1070
1015
|
}, [state]);
|
|
1016
|
+
useLayoutEffect(() => {
|
|
1017
|
+
if (options.animateRows)
|
|
1018
|
+
return;
|
|
1019
|
+
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1020
|
+
for (const pane of layer.panes)
|
|
1021
|
+
pane.cancelAnimation();
|
|
1022
|
+
}
|
|
1023
|
+
}, [options.animateRows]);
|
|
1071
1024
|
useEffect(() => {
|
|
1072
1025
|
return () => {
|
|
1073
|
-
if (scrollFrameRef.current.id)
|
|
1026
|
+
if (scrollFrameRef.current.id) {
|
|
1074
1027
|
cancelAnimationFrame(scrollFrameRef.current.id);
|
|
1028
|
+
scrollFrameRef.current.id = 0;
|
|
1029
|
+
}
|
|
1075
1030
|
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1076
1031
|
layer.pool?.destroy();
|
|
1077
1032
|
layer.pool = null;
|
|
@@ -1088,6 +1043,13 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1088
1043
|
const frame = scrollFrameRef.current;
|
|
1089
1044
|
frame.top = element.scrollTop;
|
|
1090
1045
|
frame.left = element.scrollLeft;
|
|
1046
|
+
lastScrollTimeRef.current = performance.now();
|
|
1047
|
+
if (options.animateRows) {
|
|
1048
|
+
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1049
|
+
for (const pane of layer.panes)
|
|
1050
|
+
pane.cancelAnimation();
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1091
1053
|
// The scrollbar width is NOT measured here: reading `offsetWidth` /
|
|
1092
1054
|
// clientWidth forces a synchronous layout of the whole page, and a
|
|
1093
1055
|
// scroll event fires several times per frame during a thumb drag.
|
|
@@ -1105,29 +1067,16 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1105
1067
|
const element = viewportRef.current;
|
|
1106
1068
|
const scrollTop = element ? element.scrollTop : frame.top;
|
|
1107
1069
|
const scrollLeft = element ? element.scrollLeft : frame.left;
|
|
1108
|
-
// Velocity detection: px/ms. Threshold at 2.0 px/ms — mouse wheel
|
|
1109
|
-
// and trackpad scrolls typically range 0.05–0.2 px/ms, while
|
|
1110
|
-
// scrollbar thumb drags and shift-click page jumps can exceed 10 px/ms.
|
|
1111
|
-
// When velocity exceeds the threshold, skipContentBind is passed to
|
|
1112
|
-
// syncPool: rows are repositioned but content binding is deferred,
|
|
1113
|
-
// avoiding synchronous React commits that exceed the 16ms frame budget.
|
|
1114
|
-
const now = performance.now();
|
|
1115
|
-
const deltaT = now - frame.lastTime;
|
|
1116
|
-
scrollVelocityRef.current = deltaT > 8 ? Math.abs(scrollTop - frame.lastTop) / deltaT : 0;
|
|
1117
|
-
frame.lastTop = scrollTop;
|
|
1118
|
-
frame.lastTime = now;
|
|
1119
|
-
lastScrollTimeRef.current = now;
|
|
1120
1070
|
// setViewport with scroll-only updates does NOT notify the Store,
|
|
1121
1071
|
// so this does NOT trigger a React re-render. The DomPool is
|
|
1122
1072
|
// updated imperatively below.
|
|
1123
1073
|
grid.setViewport({ scrollTop, scrollLeft });
|
|
1124
|
-
|
|
1125
|
-
if (!skipContentBind && pendingAnchorRef.current !== 0) {
|
|
1074
|
+
if (!isScrollActive() && pendingAnchorRef.current !== 0) {
|
|
1126
1075
|
// The scroll settled — the deferred anchoring correction can be
|
|
1127
1076
|
// applied now without fighting the user's input.
|
|
1128
1077
|
flushPendingAnchor();
|
|
1129
1078
|
}
|
|
1130
|
-
syncPool(true
|
|
1079
|
+
syncPool(true);
|
|
1131
1080
|
});
|
|
1132
1081
|
};
|
|
1133
1082
|
/** Resolves headless slot content into a ReactNode (see contentToReactNode). */
|
|
@@ -1297,13 +1246,39 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1297
1246
|
minWidth: 0,
|
|
1298
1247
|
overflow: "hidden",
|
|
1299
1248
|
};
|
|
1300
|
-
return (_jsxs("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"
|
|
1249
|
+
return (_jsxs("div", { role: "columnheader", className: className, "data-sort": item.column.sortState, "data-sort-index": item.column.sortIndex, "data-sortable": item.column.sortable === true ? "true" : undefined, "data-movable": item.column.movable === true ? "true" : undefined, draggable: item.column.movable === true, "aria-sort": item.column.sortState === "asc"
|
|
1301
1250
|
? "ascending"
|
|
1302
1251
|
: item.column.sortState === "desc"
|
|
1303
1252
|
? "descending"
|
|
1304
1253
|
: "none", onClick: (event) => item.column.stopHeaderClick
|
|
1305
1254
|
? event.stopPropagation()
|
|
1306
|
-
: grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey),
|
|
1255
|
+
: grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey), onDragStart: (event) => {
|
|
1256
|
+
if (item.column.movable !== true) {
|
|
1257
|
+
event.preventDefault();
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
event.dataTransfer.effectAllowed = "move";
|
|
1261
|
+
event.dataTransfer.setData(COLUMN_DRAG_TYPE, item.column.id);
|
|
1262
|
+
grid.emit("columnDragStart", { columnId: item.column.id });
|
|
1263
|
+
}, onDragOver: (event) => {
|
|
1264
|
+
if (!Array.from(event.dataTransfer.types).includes(COLUMN_DRAG_TYPE))
|
|
1265
|
+
return;
|
|
1266
|
+
event.preventDefault();
|
|
1267
|
+
event.dataTransfer.dropEffect = "move";
|
|
1268
|
+
}, onDragEnd: () => grid.emit("columnDragEnd", { columnId: item.column.id }), onDrop: (event) => {
|
|
1269
|
+
const sourceColumnId = event.dataTransfer.getData(COLUMN_DRAG_TYPE);
|
|
1270
|
+
if (!sourceColumnId)
|
|
1271
|
+
return;
|
|
1272
|
+
event.preventDefault();
|
|
1273
|
+
event.stopPropagation();
|
|
1274
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
1275
|
+
const position = event.clientX < bounds.left + bounds.width / 2 ? "before" : "after";
|
|
1276
|
+
grid.emit("columnDrop", {
|
|
1277
|
+
sourceColumnId,
|
|
1278
|
+
targetColumnId: item.column.id,
|
|
1279
|
+
position,
|
|
1280
|
+
});
|
|
1281
|
+
}, onKeyDown: (event) => {
|
|
1307
1282
|
if (event.key === "Enter" || event.key === " ")
|
|
1308
1283
|
grid.headerClick(item.column.id);
|
|
1309
1284
|
}, tabIndex: 0, style: headerCellLayout, children: [headerStartExtensions.length > 0 && (_jsx("span", { className: "omnigrid-header-start", children: headerStartExtensions })), _jsx("div", { className: "omnigrid-header-main", style: headerContentLayout, children: item.column.headerRenderer ? (headerContent) : (_jsx("span", { className: "omnigrid-header-label", style: {
|
|
@@ -1355,7 +1330,33 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1355
1330
|
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1356
1331
|
width: segment.width,
|
|
1357
1332
|
};
|
|
1358
|
-
return (_jsx("div", { role: "columnheader", className: className, "
|
|
1333
|
+
return (_jsx("div", { role: "columnheader", className: className, "data-movable": segment.group.movable === true ? "true" : undefined, draggable: segment.group.movable === true, "aria-colspan": segment.columnCount, onDragStart: (event) => {
|
|
1334
|
+
if (segment.group.movable !== true) {
|
|
1335
|
+
event.preventDefault();
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
event.dataTransfer.effectAllowed = "move";
|
|
1339
|
+
event.dataTransfer.setData(COLUMN_DRAG_TYPE, segment.group.id);
|
|
1340
|
+
grid.emit("columnDragStart", { columnId: segment.group.id });
|
|
1341
|
+
}, onDragOver: (event) => {
|
|
1342
|
+
if (!Array.from(event.dataTransfer.types).includes(COLUMN_DRAG_TYPE))
|
|
1343
|
+
return;
|
|
1344
|
+
event.preventDefault();
|
|
1345
|
+
event.dataTransfer.dropEffect = "move";
|
|
1346
|
+
}, onDragEnd: () => grid.emit("columnDragEnd", { columnId: segment.group.id }), onDrop: (event) => {
|
|
1347
|
+
const sourceColumnId = event.dataTransfer.getData(COLUMN_DRAG_TYPE);
|
|
1348
|
+
if (!sourceColumnId)
|
|
1349
|
+
return;
|
|
1350
|
+
event.preventDefault();
|
|
1351
|
+
event.stopPropagation();
|
|
1352
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
1353
|
+
const position = event.clientX < bounds.left + bounds.width / 2 ? "before" : "after";
|
|
1354
|
+
grid.emit("columnDrop", {
|
|
1355
|
+
sourceColumnId,
|
|
1356
|
+
targetColumnId: segment.group.id,
|
|
1357
|
+
position,
|
|
1358
|
+
});
|
|
1359
|
+
}, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
|
|
1359
1360
|
registry: slotComponentsRef.current,
|
|
1360
1361
|
context: buildRenderContext,
|
|
1361
1362
|
})) : (_jsx("span", { className: "omnigrid-header-label", style: { textAlign: groupHeaderAlign ?? "center" }, children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
|
package/dist/controls.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { createPortal } from "react-dom";
|
|
3
|
-
const CONTROL_TYPES = new Set([
|
|
3
|
+
const CONTROL_TYPES = new Set([
|
|
4
|
+
"text",
|
|
5
|
+
"number",
|
|
6
|
+
"date",
|
|
7
|
+
"select",
|
|
8
|
+
"checkbox",
|
|
9
|
+
"button",
|
|
10
|
+
"label",
|
|
11
|
+
"multi-select",
|
|
12
|
+
"group",
|
|
13
|
+
]);
|
|
4
14
|
/** Type guard for core `UIControlDescriptor` objects. */
|
|
5
15
|
export function isUIControlDescriptor(value) {
|
|
6
16
|
if (typeof value !== "object" || value === null)
|
|
@@ -57,6 +67,7 @@ export function DebouncedInput({ descriptor }) {
|
|
|
57
67
|
flush();
|
|
58
68
|
};
|
|
59
69
|
return createElement("div", { className: "omnigrid-control-input-wrapper" }, createElement("input", {
|
|
70
|
+
id: descriptor.id,
|
|
60
71
|
className: ["omnigrid-control-input", descriptor.className].filter(Boolean).join(" "),
|
|
61
72
|
type: descriptor.type === "number" ? "number" : descriptor.type === "date" ? "date" : "text",
|
|
62
73
|
value: local,
|
|
@@ -81,7 +92,9 @@ function withLabel(descriptor, field, inline = false, resolveIcon) {
|
|
|
81
92
|
if (!descriptor.label)
|
|
82
93
|
return createElement("div", { key: descriptor.id, className }, body);
|
|
83
94
|
const label = createElement("span", { className: "omnigrid-control-label" }, descriptor.label);
|
|
84
|
-
return inline
|
|
95
|
+
return inline
|
|
96
|
+
? createElement("label", { key: descriptor.id, className }, body, label)
|
|
97
|
+
: createElement("label", { key: descriptor.id, className }, label, body);
|
|
85
98
|
}
|
|
86
99
|
/**
|
|
87
100
|
* Custom-styled, keyboard-navigable drop-down select. Replaces the native
|
|
@@ -199,7 +212,10 @@ function SelectControl({ descriptor }) {
|
|
|
199
212
|
let node = buttonRef.current;
|
|
200
213
|
while (node && node !== document.body) {
|
|
201
214
|
const style = window.getComputedStyle(node);
|
|
202
|
-
if (style.overflowY === "auto" ||
|
|
215
|
+
if (style.overflowY === "auto" ||
|
|
216
|
+
style.overflowY === "scroll" ||
|
|
217
|
+
style.overflow === "auto" ||
|
|
218
|
+
style.overflow === "scroll") {
|
|
203
219
|
targets.push(node);
|
|
204
220
|
}
|
|
205
221
|
node = node.parentElement;
|
|
@@ -217,7 +233,7 @@ function SelectControl({ descriptor }) {
|
|
|
217
233
|
}, [isOpen, anchorRect]);
|
|
218
234
|
const currentOption = descriptor.options[selectedIndex === -1 ? 0 : selectedIndex];
|
|
219
235
|
const label = currentOption ? currentOption.label : descriptor.value;
|
|
220
|
-
const listbox =
|
|
236
|
+
const listbox = anchorRect &&
|
|
221
237
|
isOpen &&
|
|
222
238
|
createPortal(createElement("div", {
|
|
223
239
|
ref: listboxRef,
|
|
@@ -255,7 +271,7 @@ function SelectControl({ descriptor }) {
|
|
|
255
271
|
onClick: () => selectOption(index),
|
|
256
272
|
onKeyDown: (event) => handleListboxKeyDown(event),
|
|
257
273
|
}, option.label);
|
|
258
|
-
})), document.body)
|
|
274
|
+
})), document.body);
|
|
259
275
|
return createElement("div", {
|
|
260
276
|
className: ["omnigrid-select-wrapper", descriptor.className].filter(Boolean).join(" "),
|
|
261
277
|
}, createElement("button", {
|
|
@@ -372,18 +388,30 @@ export function renderControl(descriptor, resolveIcon) {
|
|
|
372
388
|
return createElement("button", {
|
|
373
389
|
key: descriptor.id,
|
|
374
390
|
type: "button",
|
|
375
|
-
className: [
|
|
391
|
+
className: [
|
|
392
|
+
"omnigrid-control-button",
|
|
393
|
+
descriptor.variant === "primary" ? "omnigrid-control-button-primary" : null,
|
|
394
|
+
descriptor.className,
|
|
395
|
+
]
|
|
376
396
|
.filter(Boolean)
|
|
377
397
|
.join(" "),
|
|
378
398
|
disabled: descriptor.disabled,
|
|
379
399
|
onClick: () => descriptor.onClick(),
|
|
380
400
|
}, descriptor.text);
|
|
381
401
|
case "label":
|
|
382
|
-
return createElement("div", {
|
|
402
|
+
return createElement("div", {
|
|
403
|
+
key: descriptor.id,
|
|
404
|
+
className: ["omnigrid-control-label", descriptor.className].filter(Boolean).join(" "),
|
|
405
|
+
}, descriptor.text);
|
|
383
406
|
case "group":
|
|
384
407
|
return createElement("div", {
|
|
385
408
|
key: descriptor.id,
|
|
386
|
-
className: [
|
|
409
|
+
className: [
|
|
410
|
+
"omnigrid-control",
|
|
411
|
+
"omnigrid-control-group",
|
|
412
|
+
descriptor.direction === "row" ? "omnigrid-control-group-row" : null,
|
|
413
|
+
descriptor.className,
|
|
414
|
+
]
|
|
387
415
|
.filter(Boolean)
|
|
388
416
|
.join(" "),
|
|
389
417
|
}, descriptor.children.map((child) => renderControl(child, resolveIcon)));
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare class PooledRowPane<T> {
|
|
|
29
29
|
private variableHeight;
|
|
30
30
|
private heightMeasureId;
|
|
31
31
|
private rowHasWrapText;
|
|
32
|
+
private offsetY;
|
|
33
|
+
private rowAnimation;
|
|
32
34
|
constructor(host: HTMLDivElement, callbacks: PooledRowCallbacks<T>, bridge: ContentBridge<T>);
|
|
33
35
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
34
36
|
bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
@@ -38,6 +40,12 @@ export declare class PooledRowPane<T> {
|
|
|
38
40
|
updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
39
41
|
/** Single row positioning operation — transform only (no reflow). */
|
|
40
42
|
setOffsetY(offsetY: number): void;
|
|
43
|
+
/** Returns the current virtualized row position in grid coordinates. */
|
|
44
|
+
getOffsetY(): number;
|
|
45
|
+
/** Animates a row from its previous grid position without changing its scroll transform. */
|
|
46
|
+
animateFrom(previousOffsetY: number): void;
|
|
47
|
+
/** Cancels any active row-position animation. */
|
|
48
|
+
cancelAnimation(): void;
|
|
41
49
|
/**
|
|
42
50
|
* Updates the row index the node stands for without touching its content.
|
|
43
51
|
*
|
package/dist/pooledRow.js
CHANGED
|
@@ -44,6 +44,8 @@ export class PooledRowPane {
|
|
|
44
44
|
this.variableHeight = false;
|
|
45
45
|
this.heightMeasureId = 0;
|
|
46
46
|
this.rowHasWrapText = false;
|
|
47
|
+
this.offsetY = 0;
|
|
48
|
+
this.rowAnimation = null;
|
|
47
49
|
host.classList.add("omnigrid-row");
|
|
48
50
|
host.setAttribute("role", "row");
|
|
49
51
|
host.style.position = "absolute";
|
|
@@ -93,6 +95,7 @@ export class PooledRowPane {
|
|
|
93
95
|
}
|
|
94
96
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
95
97
|
bind(row, columns, originX = 0, spans) {
|
|
98
|
+
this.cancelAnimation();
|
|
96
99
|
const hovered = this.host.matches(":hover");
|
|
97
100
|
if (hovered && this.row)
|
|
98
101
|
this.callbacks.onRowHover(this.row, false);
|
|
@@ -127,7 +130,38 @@ export class PooledRowPane {
|
|
|
127
130
|
}
|
|
128
131
|
/** Single row positioning operation — transform only (no reflow). */
|
|
129
132
|
setOffsetY(offsetY) {
|
|
130
|
-
|
|
133
|
+
const roundedOffsetY = Math.round(offsetY);
|
|
134
|
+
if (this.offsetY !== roundedOffsetY)
|
|
135
|
+
this.cancelAnimation();
|
|
136
|
+
this.offsetY = roundedOffsetY;
|
|
137
|
+
this.host.style.transform = `translate3d(0, ${roundedOffsetY}px, 0)`;
|
|
138
|
+
}
|
|
139
|
+
/** Returns the current virtualized row position in grid coordinates. */
|
|
140
|
+
getOffsetY() {
|
|
141
|
+
return this.offsetY;
|
|
142
|
+
}
|
|
143
|
+
/** Animates a row from its previous grid position without changing its scroll transform. */
|
|
144
|
+
animateFrom(previousOffsetY) {
|
|
145
|
+
this.cancelAnimation();
|
|
146
|
+
const deltaY = previousOffsetY - this.offsetY;
|
|
147
|
+
if (deltaY === 0)
|
|
148
|
+
return;
|
|
149
|
+
const animation = this.host.animate([{ translate: `0px ${deltaY}px` }, { translate: "0px 0px" }], { duration: 180, easing: "ease-out" });
|
|
150
|
+
this.rowAnimation = animation;
|
|
151
|
+
animation.onfinish = () => {
|
|
152
|
+
if (this.rowAnimation === animation)
|
|
153
|
+
this.rowAnimation = null;
|
|
154
|
+
};
|
|
155
|
+
animation.oncancel = () => {
|
|
156
|
+
if (this.rowAnimation === animation)
|
|
157
|
+
this.rowAnimation = null;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** Cancels any active row-position animation. */
|
|
161
|
+
cancelAnimation() {
|
|
162
|
+
const animation = this.rowAnimation;
|
|
163
|
+
this.rowAnimation = null;
|
|
164
|
+
animation?.cancel();
|
|
131
165
|
}
|
|
132
166
|
/**
|
|
133
167
|
* Updates the row index the node stands for without touching its content.
|