@omnigrid/react 0.1.30 → 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 +77 -62
- package/dist/OmniGrid.js +275 -182
- package/dist/cellTooltip.d.ts +6 -2
- package/dist/cellTooltip.js +38 -8
- package/dist/controls.js +36 -8
- package/dist/index.d.ts +2 -2
- package/dist/pooledRow.d.ts +8 -0
- package/dist/pooledRow.js +36 -1
- package/dist/popup.d.ts +1 -0
- package/dist/popup.js +18 -9
- package/dist/reactColumnDef.d.ts +30 -0
- package/dist/types.d.ts +8 -7
- package/package.json +1 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
3
3
|
import { flushSync } from "react-dom";
|
|
4
|
-
import { DomPool, isActiveCondition } from "@omnigrid/core";
|
|
5
|
-
import { contentToReactNode, hasRenderableContent } from "./content";
|
|
4
|
+
import { DomPool, flattenColumns, isActiveCondition } from "@omnigrid/core";
|
|
6
5
|
import { CellTooltipLayer } from "./cellTooltip";
|
|
6
|
+
import { contentToReactNode, hasRenderableContent } from "./content";
|
|
7
|
+
import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
|
|
7
8
|
import { computeGroupSegments } from "./groupHeader";
|
|
8
|
-
import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
|
|
9
|
-
import { getRowRenderParams } from "./rowRenderParams";
|
|
10
|
-
import { PooledRowPane } from "./pooledRow";
|
|
11
|
-
import { createCellRoot } from "./reactRoot";
|
|
12
9
|
import { renderDefaultOverlay } from "./overlays";
|
|
10
|
+
import { PooledRowPane } from "./pooledRow";
|
|
13
11
|
import { PopupHost } from "./popup";
|
|
12
|
+
import { createCellRoot } from "./reactRoot";
|
|
13
|
+
import { getRowRenderParams } from "./rowRenderParams";
|
|
14
14
|
import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
|
15
15
|
import { useGrid } from "./useGrid";
|
|
16
16
|
function getCellValue(row, column) {
|
|
@@ -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
|
}
|
|
@@ -81,6 +75,20 @@ function createRowLayerState() {
|
|
|
81
75
|
*/
|
|
82
76
|
export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
|
|
83
77
|
const { grid, state, viewportData } = useGrid(options);
|
|
78
|
+
const columnTooltipOptions = useMemo(() => {
|
|
79
|
+
const result = new Map();
|
|
80
|
+
for (const column of flattenColumns(state.columns)) {
|
|
81
|
+
const columnWithTooltip = column;
|
|
82
|
+
if (columnWithTooltip.cellTooltipRenderer !== undefined ||
|
|
83
|
+
columnWithTooltip.cellTooltipClassName !== undefined) {
|
|
84
|
+
result.set(column.id, {
|
|
85
|
+
renderer: columnWithTooltip.cellTooltipRenderer,
|
|
86
|
+
className: columnWithTooltip.cellTooltipClassName,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}, [state.columns]);
|
|
84
92
|
const viewportRef = useRef(null);
|
|
85
93
|
const layoutRef = useRef(null);
|
|
86
94
|
/** Scrollable content wrapper — its height is the total height of all rows. */
|
|
@@ -94,13 +102,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
94
102
|
id: 0,
|
|
95
103
|
top: 0,
|
|
96
104
|
left: 0,
|
|
97
|
-
lastTop: 0,
|
|
98
|
-
lastTime: 0,
|
|
99
105
|
});
|
|
100
|
-
|
|
101
|
-
/** 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. */
|
|
102
107
|
const lastScrollTimeRef = useRef(0);
|
|
103
|
-
/** Anchoring correction accumulated while
|
|
108
|
+
/** Anchoring correction accumulated while the user is scrolling. */
|
|
104
109
|
const pendingAnchorRef = useRef(0);
|
|
105
110
|
/** Timer that applies the accumulated anchoring correction after the scroll settles. */
|
|
106
111
|
const anchorTimerRef = useRef(null);
|
|
@@ -112,18 +117,6 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
112
117
|
const heightFlushRef = useRef(null);
|
|
113
118
|
/** Latest `syncPool` — read imperatively from `measureViewport`/ResizeObserver so the callback stays stable. */
|
|
114
119
|
const syncPoolRef = useRef(null);
|
|
115
|
-
/**
|
|
116
|
-
* Scrollable content height frozen at the start of a user scroll gesture.
|
|
117
|
-
*
|
|
118
|
-
* While the user drags the scrollbar thumb, measured row heights keep
|
|
119
|
-
* replacing estimates and `totalHeight` changes every frame. Rewriting the
|
|
120
|
-
* content height mid-drag makes the browser reposition the native
|
|
121
|
-
* scrollbar thumb (`scrollTop / (scrollHeight - clientHeight)`), so the
|
|
122
|
-
* thumb detaches from the mouse on the very first scroll of a
|
|
123
|
-
* variable-height grid. The height is therefore frozen to this snapshot
|
|
124
|
-
* for the duration of the gesture — row positions still use the measured
|
|
125
|
-
* offsets — and the real height is reapplied once the scroll settles.
|
|
126
|
-
*/
|
|
127
120
|
const optionsRef = useRef(options);
|
|
128
121
|
const columnWindowKeyRef = useRef("");
|
|
129
122
|
/** Content size the scrollbar insets were measured for. */
|
|
@@ -234,7 +227,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
234
227
|
height: autoHeight ? measuredHeight : style?.height,
|
|
235
228
|
...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
|
|
236
229
|
};
|
|
237
|
-
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null]
|
|
230
|
+
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null]
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.join(" ");
|
|
238
233
|
const overlayState = state.overlay;
|
|
239
234
|
const filterModelSnapshot = grid.getFilterModel();
|
|
240
235
|
const isColumnFiltered = (column) => {
|
|
@@ -420,20 +415,12 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
420
415
|
columnPresentationCacheRef.current.set(column.id, { revision, data: processedData, presentation });
|
|
421
416
|
return presentation;
|
|
422
417
|
};
|
|
423
|
-
/**
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
* The velocity is sampled on scroll frames only, so it is aged out: when
|
|
427
|
-
* the last scroll frame is older than `FAST_SCROLL_WINDOW` the scroll has
|
|
428
|
-
* settled and the grid returns to its normal (fully bound) mode.
|
|
429
|
-
*/
|
|
430
|
-
function isFastScrolling() {
|
|
431
|
-
if (scrollVelocityRef.current <= FAST_SCROLL_VELOCITY)
|
|
432
|
-
return false;
|
|
433
|
-
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;
|
|
434
421
|
}
|
|
435
422
|
/**
|
|
436
|
-
* Applies the anchoring corrections that were deferred
|
|
423
|
+
* Applies the anchoring corrections that were deferred while scrolling.
|
|
437
424
|
*
|
|
438
425
|
* A row ABOVE the viewport that changes its height shifts the content
|
|
439
426
|
* below it. While the user drags the scrollbar that correction fights the
|
|
@@ -446,9 +433,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
446
433
|
const pending = pendingAnchorRef.current;
|
|
447
434
|
if (pending === 0)
|
|
448
435
|
return;
|
|
449
|
-
if (
|
|
436
|
+
if (isScrollActive()) {
|
|
450
437
|
// The user started scrolling again — the correction stays pending.
|
|
451
|
-
anchorTimerRef.current = window.setTimeout(flushPendingAnchor,
|
|
438
|
+
anchorTimerRef.current = window.setTimeout(flushPendingAnchor, SCROLL_IDLE_WINDOW);
|
|
452
439
|
return;
|
|
453
440
|
}
|
|
454
441
|
pendingAnchorRef.current = 0;
|
|
@@ -456,11 +443,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
456
443
|
const current = element ? element.scrollTop : grid.getScrollPosition().scrollTop;
|
|
457
444
|
grid.scrollTo({ scrollTop: Math.max(0, current + pending) });
|
|
458
445
|
}
|
|
459
|
-
/** Schedules the
|
|
446
|
+
/** Schedules the anchoring flush after scrolling has settled. */
|
|
460
447
|
function scheduleAnchorFlush() {
|
|
461
448
|
if (anchorTimerRef.current !== null)
|
|
462
449
|
window.clearTimeout(anchorTimerRef.current);
|
|
463
|
-
anchorTimerRef.current = window.setTimeout(flushPendingAnchor,
|
|
450
|
+
anchorTimerRef.current = window.setTimeout(flushPendingAnchor, SCROLL_IDLE_WINDOW);
|
|
464
451
|
}
|
|
465
452
|
/**
|
|
466
453
|
* Applies the row heights measured during the current frame.
|
|
@@ -482,11 +469,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
482
469
|
if (measured === 0)
|
|
483
470
|
return;
|
|
484
471
|
pendingHeightCountRef.current = 0;
|
|
485
|
-
const
|
|
472
|
+
const scrolling = isScrollActive();
|
|
486
473
|
const correction = pendingHeightCorrectionRef.current;
|
|
487
474
|
pendingHeightCorrectionRef.current = 0;
|
|
488
475
|
if (correction !== 0) {
|
|
489
|
-
if (
|
|
476
|
+
if (scrolling) {
|
|
490
477
|
// The correction fights the user's input while they are
|
|
491
478
|
// scrolling — it is applied once the scroll settles.
|
|
492
479
|
pendingAnchorRef.current += correction;
|
|
@@ -500,7 +487,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
500
487
|
}
|
|
501
488
|
// The measured heights changed the offsets of the rows below: push the
|
|
502
489
|
// new geometry into the pools.
|
|
503
|
-
syncPool(false
|
|
490
|
+
syncPool(false);
|
|
504
491
|
}
|
|
505
492
|
/** Schedules the row-height flush for the next frame. */
|
|
506
493
|
function scheduleHeightFlush() {
|
|
@@ -546,9 +533,17 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
546
533
|
// show the grouping field's value in the group column instead of
|
|
547
534
|
// the row's own field value.
|
|
548
535
|
const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
|
|
549
|
-
const value = collapsedGroupDisplay !== undefined
|
|
536
|
+
const value = collapsedGroupDisplay !== undefined
|
|
537
|
+
? collapsedGroupDisplay.value
|
|
538
|
+
: getCellValue(rawData, info.column);
|
|
550
539
|
const content = info.column.cellRenderer
|
|
551
|
-
? info.column.cellRenderer({
|
|
540
|
+
? info.column.cellRenderer({
|
|
541
|
+
value,
|
|
542
|
+
data: rawData,
|
|
543
|
+
column: info.column,
|
|
544
|
+
id: info.rowId,
|
|
545
|
+
index: info.rowIndex,
|
|
546
|
+
})
|
|
552
547
|
: info.column.valueFormatter
|
|
553
548
|
? info.column.valueFormatter(value)
|
|
554
549
|
: String(value ?? "");
|
|
@@ -575,7 +570,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
575
570
|
? info.data.data
|
|
576
571
|
: info.data);
|
|
577
572
|
const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
|
|
578
|
-
const value = collapsedGroupDisplay !== undefined
|
|
573
|
+
const value = collapsedGroupDisplay !== undefined
|
|
574
|
+
? collapsedGroupDisplay.value
|
|
575
|
+
: getCellValue(rawData, info.column);
|
|
579
576
|
if (info.column.valueFormatter)
|
|
580
577
|
return info.column.valueFormatter(value);
|
|
581
578
|
const valueType = typeof value;
|
|
@@ -588,7 +585,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
588
585
|
const base = isGroup ? "omnigrid-row omnigrid-row-group" : "omnigrid-row";
|
|
589
586
|
const rowParams = getRowRenderParams(row);
|
|
590
587
|
const currentOptions = current();
|
|
591
|
-
const rowClass = typeof currentOptions.rowClass === "function"
|
|
588
|
+
const rowClass = typeof currentOptions.rowClass === "function"
|
|
589
|
+
? currentOptions.rowClass(rowParams)
|
|
590
|
+
: currentOptions.rowClass;
|
|
592
591
|
const dynamicRowClass = currentOptions.getRowClass?.(rowParams);
|
|
593
592
|
const ruleClasses = Object.entries(currentOptions.rowClassRules ?? {})
|
|
594
593
|
.filter(([, predicate]) => predicate(rowParams))
|
|
@@ -609,8 +608,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
609
608
|
},
|
|
610
609
|
resolveCellClasses: (info) => {
|
|
611
610
|
const flashedCells = grid.getState().flashedCells;
|
|
612
|
-
const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
613
|
-
const isFlashed = cellFlashDurationMs !== false &&
|
|
611
|
+
const flashTimestamp = info.column.cellFlash === false ? undefined : flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
612
|
+
const isFlashed = cellFlashDurationMs !== false &&
|
|
613
|
+
flashTimestamp !== undefined &&
|
|
614
|
+
Date.now() - flashTimestamp <= cellFlashDurationMs;
|
|
614
615
|
const cellParams = {
|
|
615
616
|
id: info.rowId,
|
|
616
617
|
index: info.rowIndex,
|
|
@@ -628,8 +629,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
628
629
|
},
|
|
629
630
|
resolveCellStyle: (info) => {
|
|
630
631
|
const flashedCells = grid.getState().flashedCells;
|
|
631
|
-
const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
632
|
-
const isFlashed = cellFlashDurationMs !== false &&
|
|
632
|
+
const flashTimestamp = info.column.cellFlash === false ? undefined : flashedCells.get(`${info.rowId}:${info.column.id}`);
|
|
633
|
+
const isFlashed = cellFlashDurationMs !== false &&
|
|
634
|
+
flashTimestamp !== undefined &&
|
|
635
|
+
Date.now() - flashTimestamp <= cellFlashDurationMs;
|
|
633
636
|
const cellParams = {
|
|
634
637
|
id: info.rowId,
|
|
635
638
|
index: info.rowIndex,
|
|
@@ -727,6 +730,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
727
730
|
// (scrollable) while pinned layers render their full group.
|
|
728
731
|
const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
|
|
729
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);
|
|
730
736
|
},
|
|
731
737
|
resizeRow: (host, height) => {
|
|
732
738
|
const pane = paneMap.get(host);
|
|
@@ -759,7 +765,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
759
765
|
* Receives the pre-computed `viewportData` from `syncPool` to avoid redundant
|
|
760
766
|
* getViewportData() calls — each layer no longer recomputes column geometry.
|
|
761
767
|
*/
|
|
762
|
-
const syncRowLayer = (layer, viewportData, rowsLayerRef
|
|
768
|
+
const syncRowLayer = (layer, viewportData, rowsLayerRef) => {
|
|
763
769
|
const bridge = ensureLayerContext();
|
|
764
770
|
ensureLayerPool(layer, rowsLayerRef.current, bridge);
|
|
765
771
|
const pool = layer.pool;
|
|
@@ -767,7 +773,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
767
773
|
return;
|
|
768
774
|
const state = grid.getState();
|
|
769
775
|
const processed = getPoolData(grid);
|
|
770
|
-
const
|
|
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;
|
|
771
785
|
if (changed) {
|
|
772
786
|
layer.revision = grid.getRevision();
|
|
773
787
|
layer.totalWidth = viewportData.totalWidth;
|
|
@@ -776,6 +790,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
776
790
|
}
|
|
777
791
|
// Cached for the row binds below — the viewport data of THIS sync.
|
|
778
792
|
layer.viewport = viewportData;
|
|
793
|
+
layer.animationPositions = animationPositions;
|
|
779
794
|
pool.update({
|
|
780
795
|
data: processed,
|
|
781
796
|
rowRange: viewportData.rowRange,
|
|
@@ -784,8 +799,8 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
784
799
|
rowHeights: viewportData.rowHeights,
|
|
785
800
|
visibleRowRange: viewportData.visibleRowRange,
|
|
786
801
|
rowWidth: layer.rowWidth,
|
|
787
|
-
skipBind,
|
|
788
802
|
});
|
|
803
|
+
layer.animationPositions = null;
|
|
789
804
|
};
|
|
790
805
|
/**
|
|
791
806
|
* Synchronises the DomPools with the grid. Idempotent — called both from
|
|
@@ -795,31 +810,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
795
810
|
* @param synchronousColumnWindow — when `true`, the rAF-driven scroll path
|
|
796
811
|
* triggers a `flushSync` for the column window header update so headers
|
|
797
812
|
* stay in step with the imperatively repositioned cells before paint.
|
|
798
|
-
* @param skipContentBind — when `true` (fast scroll), row positions are
|
|
799
|
-
* updated but `bindRow` is deferred to the next slow-scroll frame. This
|
|
800
|
-
* avoids synchronous React commits (~200 cell roots) that exceed the 16ms
|
|
801
|
-
* frame budget, causing flicker/frame drops. Rows remain visible with
|
|
802
|
-
* previous content at the correct new position.
|
|
803
813
|
*/
|
|
804
|
-
const syncPool = (synchronousColumnWindow = false
|
|
814
|
+
const syncPool = (synchronousColumnWindow = false) => {
|
|
805
815
|
const state = grid.getState();
|
|
806
816
|
const currentViewportData = grid.getViewportData();
|
|
807
817
|
// The scrollable content height follows the measured row heights.
|
|
808
818
|
// It is written imperatively: a Store notification per measured row
|
|
809
819
|
// would re-render the whole grid, and the grid would then lag behind
|
|
810
820
|
// the native scroll position (the user sees the previous rows).
|
|
811
|
-
|
|
812
|
-
// During an active user scroll gesture the height is frozen to the
|
|
813
|
-
// snapshot taken at gesture start (see `handleScroll`). Otherwise the
|
|
814
|
-
// browser recomputes the scrollbar thumb (`scrollTop /
|
|
815
|
-
// (scrollHeight - clientHeight)`) every time a measured row height
|
|
816
|
-
// replaces an estimate and `totalHeight` changes mid-drag — on the
|
|
817
|
-
// first scroll of a variable-height grid the thumb then lags behind
|
|
818
|
-
// the mouse pointer. Row positions still use the live measured
|
|
819
|
-
// offsets; only the scrollbar range is frozen until the scroll
|
|
820
|
-
// settles.
|
|
821
|
-
const effectiveTotalHeight = currentViewportData.totalHeight;
|
|
822
|
-
applyContentHeight(effectiveTotalHeight);
|
|
821
|
+
applyContentHeight(currentViewportData.totalHeight);
|
|
823
822
|
const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
824
823
|
const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
825
824
|
const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
@@ -837,28 +836,14 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
837
836
|
layers.right.rowWidth = pinnedRightWidth;
|
|
838
837
|
// Cell content rendering (root.render) is async under React concurrent
|
|
839
838
|
// mode — without flushSync, rows are repositioned but their cell content
|
|
840
|
-
// stays stale for one frame
|
|
841
|
-
//
|
|
842
|
-
// commit before paint.
|
|
843
|
-
//
|
|
844
|
-
// Velocity-based: during fast scroll (scrollbar thumb drag), many scroll
|
|
845
|
-
// events fire but rAF throttles to ~60fps. Calling flushSync on every frame
|
|
846
|
-
// forces a synchronous React commit for ALL cell roots (~200 calls), which
|
|
847
|
-
// can exceed the 16ms frame budget and cause frame drops — appearing as
|
|
848
|
-
// flickering/emptying. During fast scroll, we skip flushSync: rows stay
|
|
849
|
-
// at correct positions with previous content (we don't clear content on
|
|
850
|
-
// recycle), so the table is never empty — just 1-frame stale, which is
|
|
851
|
-
// imperceptible during rapid scroll. When velocity drops, flushSync resumes
|
|
852
|
-
// for frame-perfect content. The structural path (useEffect) always uses
|
|
853
|
-
// flushSync for correctness.
|
|
854
|
-
// getViewportData() above runs outside flushSync since column geometry
|
|
855
|
-
// 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.
|
|
856
841
|
const bindLayers = () => {
|
|
857
|
-
syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef
|
|
858
|
-
syncRowLayer(layers.central, currentViewportData, rowsLayerRef
|
|
859
|
-
syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef
|
|
842
|
+
syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef);
|
|
843
|
+
syncRowLayer(layers.central, currentViewportData, rowsLayerRef);
|
|
844
|
+
syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef);
|
|
860
845
|
};
|
|
861
|
-
if (synchronousColumnWindow
|
|
846
|
+
if (synchronousColumnWindow) {
|
|
862
847
|
flushSync(bindLayers);
|
|
863
848
|
}
|
|
864
849
|
else {
|
|
@@ -870,37 +855,31 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
870
855
|
// Pinned panes hold all their columns at once — they only rebind via
|
|
871
856
|
// the structural path above (revision bump).
|
|
872
857
|
//
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
for (const pane of layers.central.panes) {
|
|
886
|
-
const paneRow = pane.getRow();
|
|
887
|
-
if (!paneRow) {
|
|
888
|
-
pane.updateColumns(layers.central.columns, layers.central.originX, null);
|
|
889
|
-
continue;
|
|
890
|
-
}
|
|
891
|
-
const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
|
|
892
|
-
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;
|
|
893
870
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (synchronousColumnWindow) {
|
|
897
|
-
// Keep React-rendered cell content and headers in step with the
|
|
898
|
-
// imperative cell repositioning before the browser paints.
|
|
899
|
-
flushSync(updateColumnWindow);
|
|
900
|
-
}
|
|
901
|
-
else {
|
|
902
|
-
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));
|
|
903
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();
|
|
904
883
|
}
|
|
905
884
|
}
|
|
906
885
|
};
|
|
@@ -918,7 +897,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
918
897
|
const syncScrollbarInsets = useCallback((element) => {
|
|
919
898
|
const right = Math.max(0, element.offsetWidth - element.clientWidth - element.clientLeft * 2);
|
|
920
899
|
const bottom = Math.max(0, element.offsetHeight - element.clientHeight - element.clientTop * 2);
|
|
921
|
-
setScrollbarInsets((previous) =>
|
|
900
|
+
setScrollbarInsets((previous) => previous.right === right && previous.bottom === bottom ? previous : { right, bottom });
|
|
922
901
|
}, []);
|
|
923
902
|
const measureViewport = useCallback(() => {
|
|
924
903
|
const element = viewportRef.current;
|
|
@@ -942,7 +921,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
942
921
|
width,
|
|
943
922
|
...(height > 0 ? { height } : {}),
|
|
944
923
|
});
|
|
945
|
-
syncPoolRef.current?.(false
|
|
924
|
+
syncPoolRef.current?.(false);
|
|
946
925
|
setIsViewportMeasured(true);
|
|
947
926
|
}, [grid, syncScrollbarInsets, setIsViewportMeasured]);
|
|
948
927
|
useEffect(() => {
|
|
@@ -961,7 +940,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
961
940
|
if (width === 0 || height === 0)
|
|
962
941
|
return;
|
|
963
942
|
grid.setViewport({ width, height });
|
|
964
|
-
syncPoolRef.current?.(false
|
|
943
|
+
syncPoolRef.current?.(false);
|
|
965
944
|
setIsViewportMeasured(true);
|
|
966
945
|
});
|
|
967
946
|
observer.observe(element, { box: "content-box" });
|
|
@@ -1032,12 +1011,22 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1032
1011
|
layer.pool.invalidate();
|
|
1033
1012
|
}
|
|
1034
1013
|
}
|
|
1035
|
-
syncPool(false
|
|
1014
|
+
syncPool(false);
|
|
1036
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]);
|
|
1037
1024
|
useEffect(() => {
|
|
1038
1025
|
return () => {
|
|
1039
|
-
if (scrollFrameRef.current.id)
|
|
1026
|
+
if (scrollFrameRef.current.id) {
|
|
1040
1027
|
cancelAnimationFrame(scrollFrameRef.current.id);
|
|
1028
|
+
scrollFrameRef.current.id = 0;
|
|
1029
|
+
}
|
|
1041
1030
|
for (const layer of [layers.left, layers.central, layers.right]) {
|
|
1042
1031
|
layer.pool?.destroy();
|
|
1043
1032
|
layer.pool = null;
|
|
@@ -1054,6 +1043,13 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1054
1043
|
const frame = scrollFrameRef.current;
|
|
1055
1044
|
frame.top = element.scrollTop;
|
|
1056
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
|
+
}
|
|
1057
1053
|
// The scrollbar width is NOT measured here: reading `offsetWidth` /
|
|
1058
1054
|
// clientWidth forces a synchronous layout of the whole page, and a
|
|
1059
1055
|
// scroll event fires several times per frame during a thumb drag.
|
|
@@ -1071,29 +1067,16 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1071
1067
|
const element = viewportRef.current;
|
|
1072
1068
|
const scrollTop = element ? element.scrollTop : frame.top;
|
|
1073
1069
|
const scrollLeft = element ? element.scrollLeft : frame.left;
|
|
1074
|
-
// Velocity detection: px/ms. Threshold at 2.0 px/ms — mouse wheel
|
|
1075
|
-
// and trackpad scrolls typically range 0.05–0.2 px/ms, while
|
|
1076
|
-
// scrollbar thumb drags and shift-click page jumps can exceed 10 px/ms.
|
|
1077
|
-
// When velocity exceeds the threshold, skipContentBind is passed to
|
|
1078
|
-
// syncPool: rows are repositioned but content binding is deferred,
|
|
1079
|
-
// avoiding synchronous React commits that exceed the 16ms frame budget.
|
|
1080
|
-
const now = performance.now();
|
|
1081
|
-
const deltaT = now - frame.lastTime;
|
|
1082
|
-
scrollVelocityRef.current = deltaT > 8 ? Math.abs(scrollTop - frame.lastTop) / deltaT : 0;
|
|
1083
|
-
frame.lastTop = scrollTop;
|
|
1084
|
-
frame.lastTime = now;
|
|
1085
|
-
lastScrollTimeRef.current = now;
|
|
1086
1070
|
// setViewport with scroll-only updates does NOT notify the Store,
|
|
1087
1071
|
// so this does NOT trigger a React re-render. The DomPool is
|
|
1088
1072
|
// updated imperatively below.
|
|
1089
1073
|
grid.setViewport({ scrollTop, scrollLeft });
|
|
1090
|
-
|
|
1091
|
-
if (!skipContentBind && pendingAnchorRef.current !== 0) {
|
|
1074
|
+
if (!isScrollActive() && pendingAnchorRef.current !== 0) {
|
|
1092
1075
|
// The scroll settled — the deferred anchoring correction can be
|
|
1093
1076
|
// applied now without fighting the user's input.
|
|
1094
1077
|
flushPendingAnchor();
|
|
1095
1078
|
}
|
|
1096
|
-
syncPool(true
|
|
1079
|
+
syncPool(true);
|
|
1097
1080
|
});
|
|
1098
1081
|
};
|
|
1099
1082
|
/** Resolves headless slot content into a ReactNode (see contentToReactNode). */
|
|
@@ -1118,7 +1101,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1118
1101
|
const groups = renderSlotGroups(mounts, context);
|
|
1119
1102
|
if (groups.every((group) => group === null))
|
|
1120
1103
|
return null;
|
|
1121
|
-
const slotClass = slot === "down"
|
|
1104
|
+
const slotClass = slot === "down"
|
|
1105
|
+
? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down"
|
|
1106
|
+
: `omnigrid-slot omnigrid-slot-${slot}`;
|
|
1122
1107
|
return _jsx("div", { className: slotClass, children: groups });
|
|
1123
1108
|
};
|
|
1124
1109
|
/** Renders slots that overlay the table body (absolute positioning, no layout shift). */
|
|
@@ -1149,7 +1134,8 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1149
1134
|
const registeredRenderer = typeof overlay.component === "string"
|
|
1150
1135
|
? optionsRef.current.overlayComponents?.[overlay.component]
|
|
1151
1136
|
: optionsRef.current.overlayComponents?.[overlay.type];
|
|
1152
|
-
const component = typeof overlay.component === "function" ||
|
|
1137
|
+
const component = typeof overlay.component === "function" ||
|
|
1138
|
+
(typeof overlay.component === "object" && overlay.component !== null)
|
|
1153
1139
|
? overlay.component
|
|
1154
1140
|
: registeredRenderer;
|
|
1155
1141
|
const isLegacyRenderer = typeof component === "function" && component.length >= 2;
|
|
@@ -1193,6 +1179,20 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1193
1179
|
// correctly on the horizontal axis because sticky positioning is not
|
|
1194
1180
|
// affected by the clip.
|
|
1195
1181
|
const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
|
|
1182
|
+
const renderHeaderExtensions = (item, position) => {
|
|
1183
|
+
const params = { column: item.column, index: item.index };
|
|
1184
|
+
return grid.getHeaderExtensions(position).map((extension) => {
|
|
1185
|
+
const content = contentToReactNode(extension.render(params), {
|
|
1186
|
+
registry: slotComponentsRef.current,
|
|
1187
|
+
context: buildRenderContext,
|
|
1188
|
+
});
|
|
1189
|
+
if (!hasRenderableContent(content))
|
|
1190
|
+
return null;
|
|
1191
|
+
const wrapper = position === "overlay" ? "div" : "span";
|
|
1192
|
+
const className = position === "overlay" ? "omnigrid-header-overlay-item" : "omnigrid-header-extension";
|
|
1193
|
+
return createElement(wrapper, { key: extension.id, className }, content);
|
|
1194
|
+
});
|
|
1195
|
+
};
|
|
1196
1196
|
const renderHeaderCells = (columns, originX) => columns.map((item) => {
|
|
1197
1197
|
const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
|
|
1198
1198
|
const gapRows = headerRowCount - 1 - deepestDepth;
|
|
@@ -1200,6 +1200,28 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1200
1200
|
const headerParams = { column: item.column, index: item.index };
|
|
1201
1201
|
const className = resolveHeaderClasses(item.column, headerParams, fullHeight);
|
|
1202
1202
|
const customHeaderStyle = resolveHeaderStyle(item.column, headerParams);
|
|
1203
|
+
const headerAlign = item.column.headerAlign;
|
|
1204
|
+
const headerJustify = headerAlign === "center"
|
|
1205
|
+
? "center"
|
|
1206
|
+
: headerAlign === "right"
|
|
1207
|
+
? "flex-end"
|
|
1208
|
+
: headerAlign === "left"
|
|
1209
|
+
? "flex-start"
|
|
1210
|
+
: undefined;
|
|
1211
|
+
const headerStartExtensions = renderHeaderExtensions(item, "start");
|
|
1212
|
+
const headerEndExtensions = renderHeaderExtensions(item, "end");
|
|
1213
|
+
const headerOverlayExtensions = renderHeaderExtensions(item, "overlay");
|
|
1214
|
+
const hasFilterTrigger = grid.hasFilterMenu() && item.column.filterable !== false;
|
|
1215
|
+
const hasHeaderTools = Boolean(item.column.sortState) || hasFilterTrigger || headerEndExtensions.length > 0;
|
|
1216
|
+
const headerContent = item.column.headerRenderer
|
|
1217
|
+
? contentToReactNode(item.column.headerRenderer(item.column), {
|
|
1218
|
+
registry: slotComponentsRef.current,
|
|
1219
|
+
context: buildRenderContext,
|
|
1220
|
+
})
|
|
1221
|
+
: getGroupColumnRole(item.column, grid.getState().groupBy, grid.getState().groupColumnMode)
|
|
1222
|
+
.isGroupColumn && grid.getState().groupColumnMode === "single"
|
|
1223
|
+
? grid.getState().groupColumnHeader
|
|
1224
|
+
: (item.column.header ?? item.column.id);
|
|
1203
1225
|
const headerCellLayout = {
|
|
1204
1226
|
alignItems: "center",
|
|
1205
1227
|
display: "flex",
|
|
@@ -1216,31 +1238,70 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1216
1238
|
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1217
1239
|
width: item.width,
|
|
1218
1240
|
};
|
|
1219
|
-
|
|
1241
|
+
const headerContentLayout = {
|
|
1242
|
+
alignItems: "center",
|
|
1243
|
+
display: "flex",
|
|
1244
|
+
flex: "1 1 auto",
|
|
1245
|
+
justifyContent: headerJustify,
|
|
1246
|
+
minWidth: 0,
|
|
1247
|
+
overflow: "hidden",
|
|
1248
|
+
};
|
|
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"
|
|
1250
|
+
? "ascending"
|
|
1251
|
+
: item.column.sortState === "desc"
|
|
1252
|
+
? "descending"
|
|
1253
|
+
: "none", onClick: (event) => item.column.stopHeaderClick
|
|
1220
1254
|
? event.stopPropagation()
|
|
1221
|
-
: 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) => {
|
|
1222
1282
|
if (event.key === "Enter" || event.key === " ")
|
|
1223
1283
|
grid.headerClick(item.column.id);
|
|
1224
|
-
}, tabIndex: 0, style: headerCellLayout, children:
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
}
|
|
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: {
|
|
1285
|
+
flex: "1 1 auto",
|
|
1286
|
+
minWidth: 0,
|
|
1287
|
+
textAlign: headerAlign ?? "left",
|
|
1288
|
+
}, children: headerContent })) }), hasHeaderTools && (_jsxs("span", { className: "omnigrid-header-tools", children: [item.column.sortState && (_jsxs("span", { className: "omnigrid-sort-indicator", "aria-hidden": "true", children: [contentToReactNode(item.column.sortState === "asc"
|
|
1289
|
+
? grid.icons.get("arrow-up")
|
|
1290
|
+
: grid.icons.get("arrow-down"), {
|
|
1291
|
+
registry: slotComponentsRef.current,
|
|
1292
|
+
context: buildRenderContext,
|
|
1293
|
+
}), item.column.sortIndex !== undefined && (_jsx("span", { className: "omnigrid-sort-priority", children: item.column.sortIndex }))] })), hasFilterTrigger && (_jsx("button", { type: "button", className: "omnigrid-filter-trigger", "data-omnigrid-filter-trigger": "", "data-active": isColumnFiltered(item.column) ? "true" : undefined, "aria-label": `Filter ${item.column.header ?? item.column.id}`, "aria-haspopup": "dialog", tabIndex: -1, onClick: (event) => {
|
|
1294
|
+
event.stopPropagation();
|
|
1295
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1296
|
+
const layoutRect = layoutRef.current?.getBoundingClientRect() ??
|
|
1297
|
+
{ left: 0, top: 0, width: 0, height: 0 };
|
|
1298
|
+
grid.requestFilterMenu(item.column.id, {
|
|
1299
|
+
x: rect.left - layoutRect.left,
|
|
1300
|
+
y: rect.top - layoutRect.top,
|
|
1301
|
+
width: rect.width,
|
|
1302
|
+
height: rect.height,
|
|
1303
|
+
});
|
|
1304
|
+
}, onKeyDown: (event) => event.stopPropagation(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "12", height: "12", fill: "currentColor", "aria-hidden": "true", children: _jsx("path", { d: "M3 4h18l-7 8.5V20l-4-2v-5.5z" }) }) })), headerEndExtensions] })), headerOverlayExtensions.length > 0 && (_jsx("div", { className: "omnigrid-header-overlay", children: headerOverlayExtensions }))] }, item.column.id));
|
|
1244
1305
|
});
|
|
1245
1306
|
const renderGroupCells = (depth, columns, originX) => computeGroupSegments(viewportData.columnGroups, columns, depth, originX).map((segment, index) => {
|
|
1246
1307
|
const groupParams = {
|
|
@@ -1251,11 +1312,13 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1251
1312
|
};
|
|
1252
1313
|
const className = resolveGroupHeaderClasses(segment.group, groupParams);
|
|
1253
1314
|
const customGroupStyle = resolveGroupHeaderStyle(segment.group, groupParams);
|
|
1315
|
+
const groupHeaderAlign = segment.group.headerAlign;
|
|
1316
|
+
const groupJustify = groupHeaderAlign === "left" ? "flex-start" : groupHeaderAlign === "right" ? "flex-end" : "center";
|
|
1254
1317
|
const groupCellLayout = {
|
|
1255
1318
|
alignItems: "center",
|
|
1256
1319
|
display: "flex",
|
|
1257
1320
|
fontWeight: 600,
|
|
1258
|
-
justifyContent:
|
|
1321
|
+
justifyContent: groupJustify,
|
|
1259
1322
|
overflow: "hidden",
|
|
1260
1323
|
padding: "0 12px",
|
|
1261
1324
|
whiteSpace: "nowrap",
|
|
@@ -1267,10 +1330,36 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1267
1330
|
visibility: isViewportMeasured ? undefined : "hidden",
|
|
1268
1331
|
width: segment.width,
|
|
1269
1332
|
};
|
|
1270
|
-
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), {
|
|
1271
1360
|
registry: slotComponentsRef.current,
|
|
1272
1361
|
context: buildRenderContext,
|
|
1273
|
-
})) : (_jsx("span", { className: "omnigrid-header-label", children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
|
|
1362
|
+
})) : (_jsx("span", { className: "omnigrid-header-label", style: { textAlign: groupHeaderAlign ?? "center" }, children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
|
|
1274
1363
|
});
|
|
1275
1364
|
/**
|
|
1276
1365
|
* Sticky header stack: `headerRowCount` group rows (one per depth) above the
|
|
@@ -1323,7 +1412,11 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1323
1412
|
height: autoHeight ? measuredHeight : "100%",
|
|
1324
1413
|
minHeight: minViewportHeight,
|
|
1325
1414
|
minWidth: 0,
|
|
1326
|
-
overflowX: overlayBlocksHorizontalScroll
|
|
1415
|
+
overflowX: overlayBlocksHorizontalScroll
|
|
1416
|
+
? "hidden"
|
|
1417
|
+
: needsHorizontalScroll
|
|
1418
|
+
? "auto"
|
|
1419
|
+
: "hidden",
|
|
1327
1420
|
overflowY: overlayScope || autoHeight ? "hidden" : "auto",
|
|
1328
1421
|
position: "relative",
|
|
1329
1422
|
scrollbarGutter: verticalScrollbarGutter,
|
|
@@ -1362,5 +1455,5 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
|
|
|
1362
1455
|
top: headerHeight,
|
|
1363
1456
|
width: "100%",
|
|
1364
1457
|
zIndex: 4,
|
|
1365
|
-
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), _jsx(CellTooltipLayer, { viewportRef: viewportRef, renderer: cellTooltipRenderer, className: cellTooltipClassName }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
|
|
1458
|
+
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), _jsx(CellTooltipLayer, { viewportRef: viewportRef, renderer: cellTooltipRenderer, className: cellTooltipClassName, resolveCellTooltip: (columnId) => columnTooltipOptions.get(columnId) }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
|
|
1366
1459
|
}
|