@omnigrid/react 0.1.31 → 0.1.33

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 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
@@ -4,7 +4,7 @@ import { flushSync } from "react-dom";
4
4
  import { DomPool, flattenColumns, isActiveCondition } from "@omnigrid/core";
5
5
  import { CellTooltipLayer } from "./cellTooltip";
6
6
  import { contentToReactNode, hasRenderableContent } from "./content";
7
- import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
7
+ import { getCollapsedGroupDisplay, getGroupColumnRole, getTreeDataLeafIndent, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
8
8
  import { computeGroupSegments } from "./groupHeader";
9
9
  import { renderDefaultOverlay } from "./overlays";
10
10
  import { PooledRowPane } from "./pooledRow";
@@ -27,18 +27,11 @@ function getPoolData(grid) {
27
27
  }
28
28
  const SLOT_POSITIONS = ["start", "center", "end"];
29
29
  /**
30
- * Scroll velocity (px/ms) above which a scroll is treated as "fast".
31
- * Mouse wheel and trackpad scrolls typically range 0.05–0.2 px/ms, while
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 FAST_SCROLL_VELOCITY = 2.0;
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
- const scrollVelocityRef = useRef(0);
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 a fast scroll was in progress. */
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
- * Whether the user is currently fast-scrolling.
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 during a fast scroll.
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 (isFastScrolling()) {
436
+ if (isScrollActive()) {
466
437
  // The user started scrolling again — the correction stays pending.
467
- anchorTimerRef.current = window.setTimeout(flushPendingAnchor, FAST_SCROLL_WINDOW);
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 deferred anchoring flush after the scroll has settled. */
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, FAST_SCROLL_WINDOW);
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 fast = isFastScrolling();
472
+ const scrolling = isScrollActive();
502
473
  const correction = pendingHeightCorrectionRef.current;
503
474
  pendingHeightCorrectionRef.current = 0;
504
475
  if (correction !== 0) {
505
- if (fast) {
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, fast);
490
+ syncPool(false);
520
491
  }
521
492
  /** Schedules the row-height flush for the next frame. */
522
493
  function scheduleHeightFlush() {
@@ -576,6 +547,19 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
576
547
  : info.column.valueFormatter
577
548
  ? info.column.valueFormatter(value)
578
549
  : String(value ?? "");
550
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
551
+ if (treeDataLeafIndent !== undefined) {
552
+ return createElement("span", {
553
+ className: "omnigrid-cell-truncated",
554
+ style: {
555
+ display: "block",
556
+ overflow: "hidden",
557
+ paddingLeft: treeDataLeafIndent,
558
+ textOverflow: "ellipsis",
559
+ whiteSpace: "nowrap",
560
+ },
561
+ }, contentToReactNode(content, bridgeArg));
562
+ }
579
563
  if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
580
564
  return createElement("span", {
581
565
  className: "omnigrid-cell-truncated",
@@ -602,11 +586,20 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
602
586
  const value = collapsedGroupDisplay !== undefined
603
587
  ? collapsedGroupDisplay.value
604
588
  : getCellValue(rawData, info.column);
605
- if (info.column.valueFormatter)
606
- return info.column.valueFormatter(value);
607
- const valueType = typeof value;
608
- if (valueType === "string" || valueType === "number" || valueType === "boolean")
609
- return String(value);
589
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
590
+ let placeholder;
591
+ if (info.column.valueFormatter) {
592
+ placeholder = info.column.valueFormatter(value);
593
+ }
594
+ else {
595
+ const valueType = typeof value;
596
+ placeholder = valueType === "string" || valueType === "number" || valueType === "boolean" ? String(value) : null;
597
+ }
598
+ if (placeholder !== null && treeDataLeafIndent !== undefined) {
599
+ return `${"\u00a0".repeat(Math.ceil(treeDataLeafIndent / 4))}${placeholder}`;
600
+ }
601
+ if (placeholder !== null)
602
+ return placeholder;
610
603
  return null;
611
604
  },
612
605
  resolveRowClasses: (row) => {
@@ -759,6 +752,9 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
759
752
  // (scrollable) while pinned layers render their full group.
760
753
  const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
761
754
  pane.bind(paneRow, layer.columns, layer.originX, sliced);
755
+ const previousOffsetY = layer.animationPositions?.get(row.rowId);
756
+ if (previousOffsetY !== undefined)
757
+ pane.animateFrom(previousOffsetY);
762
758
  },
763
759
  resizeRow: (host, height) => {
764
760
  const pane = paneMap.get(host);
@@ -791,7 +787,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
791
787
  * Receives the pre-computed `viewportData` from `syncPool` to avoid redundant
792
788
  * getViewportData() calls — each layer no longer recomputes column geometry.
793
789
  */
794
- const syncRowLayer = (layer, viewportData, rowsLayerRef, skipBind = false) => {
790
+ const syncRowLayer = (layer, viewportData, rowsLayerRef) => {
795
791
  const bridge = ensureLayerContext();
796
792
  ensureLayerPool(layer, rowsLayerRef.current, bridge);
797
793
  const pool = layer.pool;
@@ -799,9 +795,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
799
795
  return;
800
796
  const state = grid.getState();
801
797
  const processed = getPoolData(grid);
802
- const changed = layer.revision !== grid.getRevision() ||
803
- layer.totalWidth !== viewportData.totalWidth ||
804
- layer.processed !== processed;
798
+ const processedChanged = layer.processed !== processed;
799
+ const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || processedChanged;
800
+ const shouldAnimate = Boolean(options.animateRows && layer.processed !== null && processedChanged);
801
+ const animationPositions = shouldAnimate
802
+ ? new Map(layer.panes.flatMap((pane) => {
803
+ const row = pane.getRow();
804
+ return row ? [[row.rowId, pane.getOffsetY()]] : [];
805
+ }))
806
+ : null;
805
807
  if (changed) {
806
808
  layer.revision = grid.getRevision();
807
809
  layer.totalWidth = viewportData.totalWidth;
@@ -810,6 +812,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
810
812
  }
811
813
  // Cached for the row binds below — the viewport data of THIS sync.
812
814
  layer.viewport = viewportData;
815
+ layer.animationPositions = animationPositions;
813
816
  pool.update({
814
817
  data: processed,
815
818
  rowRange: viewportData.rowRange,
@@ -818,8 +821,8 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
818
821
  rowHeights: viewportData.rowHeights,
819
822
  visibleRowRange: viewportData.visibleRowRange,
820
823
  rowWidth: layer.rowWidth,
821
- skipBind,
822
824
  });
825
+ layer.animationPositions = null;
823
826
  };
824
827
  /**
825
828
  * Synchronises the DomPools with the grid. Idempotent — called both from
@@ -829,31 +832,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
829
832
  * @param synchronousColumnWindow — when `true`, the rAF-driven scroll path
830
833
  * triggers a `flushSync` for the column window header update so headers
831
834
  * 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
835
  */
838
- const syncPool = (synchronousColumnWindow = false, skipContentBind = false) => {
836
+ const syncPool = (synchronousColumnWindow = false) => {
839
837
  const state = grid.getState();
840
838
  const currentViewportData = grid.getViewportData();
841
839
  // The scrollable content height follows the measured row heights.
842
840
  // It is written imperatively: a Store notification per measured row
843
841
  // would re-render the whole grid, and the grid would then lag behind
844
842
  // 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);
843
+ applyContentHeight(currentViewportData.totalHeight);
857
844
  const pinnedLeftWidth = currentViewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
858
845
  const pinnedRightWidth = currentViewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
859
846
  const scrollableWidth = Math.max(0, currentViewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
@@ -871,28 +858,14 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
871
858
  layers.right.rowWidth = pinnedRightWidth;
872
859
  // Cell content rendering (root.render) is async under React concurrent
873
860
  // mode — without flushSync, rows are repositioned but their cell content
874
- // stays stale for one frame, causing visible jitter on custom-renderer
875
- // cells. Wrap ONLY the DOM binding in flushSync to force cell roots to
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.
861
+ // stays stale for one frame. Wrap only the DOM binding in flushSync so
862
+ // cell roots commit before paint.
890
863
  const bindLayers = () => {
891
- syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef, skipContentBind);
892
- syncRowLayer(layers.central, currentViewportData, rowsLayerRef, skipContentBind);
893
- syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef, skipContentBind);
864
+ syncRowLayer(layers.left, currentViewportData, pinnedLeftRowsLayerRef);
865
+ syncRowLayer(layers.central, currentViewportData, rowsLayerRef);
866
+ syncRowLayer(layers.right, currentViewportData, pinnedRightRowsLayerRef);
894
867
  };
895
- if (synchronousColumnWindow && !skipContentBind) {
868
+ if (synchronousColumnWindow) {
896
869
  flushSync(bindLayers);
897
870
  }
898
871
  else {
@@ -904,37 +877,31 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
904
877
  // Pinned panes hold all their columns at once — they only rebind via
905
878
  // the structural path above (revision bump).
906
879
  //
907
- // Skip column window updates during fast scroll (skipContentBind) —
908
- // the columns themselves haven't changed, and forcing a header re-render
909
- // during fast scroll would cause frame drops. The column window will
910
- // be updated on the next slow-scroll frame or structural update.
911
- if (!skipContentBind) {
912
- const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
913
- if (columnWindowKey !== columnWindowKeyRef.current) {
914
- columnWindowKeyRef.current = columnWindowKey;
915
- const updateColumnWindow = () => {
916
- // Span-aware: each pane resolves its own row's layout so
917
- // merged cells keep their summed width while the window
918
- // slides — covered leaves stay parked off-screen.
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));
880
+ const columnWindowKey = `${currentViewportData.columnRange.start}:${currentViewportData.columnRange.end}:${state.viewport.width}:${pinnedLeftWidth}:${pinnedRightWidth}`;
881
+ if (columnWindowKey !== columnWindowKeyRef.current) {
882
+ columnWindowKeyRef.current = columnWindowKey;
883
+ const updateColumnWindow = () => {
884
+ // Span-aware: each pane resolves its own row's layout so
885
+ // merged cells keep their summed width while the window
886
+ // slides — covered leaves stay parked off-screen.
887
+ for (const pane of layers.central.panes) {
888
+ const paneRow = pane.getRow();
889
+ if (!paneRow) {
890
+ pane.updateColumns(layers.central.columns, layers.central.originX, null);
891
+ continue;
927
892
  }
928
- setColumnWindowVersion((v) => v + 1);
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();
893
+ const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
894
+ pane.updateColumns(layers.central.columns, layers.central.originX, sliceSpanLayoutForLayer(currentViewportData, layers.central.columns, true, spans.central));
937
895
  }
896
+ setColumnWindowVersion((v) => v + 1);
897
+ };
898
+ if (synchronousColumnWindow) {
899
+ // Keep React-rendered cell content and headers in step with the
900
+ // imperative cell repositioning before the browser paints.
901
+ flushSync(updateColumnWindow);
902
+ }
903
+ else {
904
+ updateColumnWindow();
938
905
  }
939
906
  }
940
907
  };
@@ -976,7 +943,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
976
943
  width,
977
944
  ...(height > 0 ? { height } : {}),
978
945
  });
979
- syncPoolRef.current?.(false, false);
946
+ syncPoolRef.current?.(false);
980
947
  setIsViewportMeasured(true);
981
948
  }, [grid, syncScrollbarInsets, setIsViewportMeasured]);
982
949
  useEffect(() => {
@@ -995,7 +962,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
995
962
  if (width === 0 || height === 0)
996
963
  return;
997
964
  grid.setViewport({ width, height });
998
- syncPoolRef.current?.(false, false);
965
+ syncPoolRef.current?.(false);
999
966
  setIsViewportMeasured(true);
1000
967
  });
1001
968
  observer.observe(element, { box: "content-box" });
@@ -1066,12 +1033,22 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1066
1033
  layer.pool.invalidate();
1067
1034
  }
1068
1035
  }
1069
- syncPool(false, false); // skipContentBind=false: structural changes always bind fully
1036
+ syncPool(false);
1070
1037
  }, [state]);
1038
+ useLayoutEffect(() => {
1039
+ if (options.animateRows)
1040
+ return;
1041
+ for (const layer of [layers.left, layers.central, layers.right]) {
1042
+ for (const pane of layer.panes)
1043
+ pane.cancelAnimation();
1044
+ }
1045
+ }, [options.animateRows]);
1071
1046
  useEffect(() => {
1072
1047
  return () => {
1073
- if (scrollFrameRef.current.id)
1048
+ if (scrollFrameRef.current.id) {
1074
1049
  cancelAnimationFrame(scrollFrameRef.current.id);
1050
+ scrollFrameRef.current.id = 0;
1051
+ }
1075
1052
  for (const layer of [layers.left, layers.central, layers.right]) {
1076
1053
  layer.pool?.destroy();
1077
1054
  layer.pool = null;
@@ -1088,6 +1065,13 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1088
1065
  const frame = scrollFrameRef.current;
1089
1066
  frame.top = element.scrollTop;
1090
1067
  frame.left = element.scrollLeft;
1068
+ lastScrollTimeRef.current = performance.now();
1069
+ if (options.animateRows) {
1070
+ for (const layer of [layers.left, layers.central, layers.right]) {
1071
+ for (const pane of layer.panes)
1072
+ pane.cancelAnimation();
1073
+ }
1074
+ }
1091
1075
  // The scrollbar width is NOT measured here: reading `offsetWidth` /
1092
1076
  // clientWidth forces a synchronous layout of the whole page, and a
1093
1077
  // scroll event fires several times per frame during a thumb drag.
@@ -1105,29 +1089,16 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1105
1089
  const element = viewportRef.current;
1106
1090
  const scrollTop = element ? element.scrollTop : frame.top;
1107
1091
  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
1092
  // setViewport with scroll-only updates does NOT notify the Store,
1121
1093
  // so this does NOT trigger a React re-render. The DomPool is
1122
1094
  // updated imperatively below.
1123
1095
  grid.setViewport({ scrollTop, scrollLeft });
1124
- const skipContentBind = scrollVelocityRef.current > FAST_SCROLL_VELOCITY;
1125
- if (!skipContentBind && pendingAnchorRef.current !== 0) {
1096
+ if (!isScrollActive() && pendingAnchorRef.current !== 0) {
1126
1097
  // The scroll settled — the deferred anchoring correction can be
1127
1098
  // applied now without fighting the user's input.
1128
1099
  flushPendingAnchor();
1129
1100
  }
1130
- syncPool(true, skipContentBind);
1101
+ syncPool(true);
1131
1102
  });
1132
1103
  };
1133
1104
  /** Resolves headless slot content into a ReactNode (see contentToReactNode). */
@@ -1297,13 +1268,39 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1297
1268
  minWidth: 0,
1298
1269
  overflow: "hidden",
1299
1270
  };
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"
1271
+ 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
1272
  ? "ascending"
1302
1273
  : item.column.sortState === "desc"
1303
1274
  ? "descending"
1304
1275
  : "none", onClick: (event) => item.column.stopHeaderClick
1305
1276
  ? event.stopPropagation()
1306
- : grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey), onKeyDown: (event) => {
1277
+ : grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey), onDragStart: (event) => {
1278
+ if (item.column.movable !== true) {
1279
+ event.preventDefault();
1280
+ return;
1281
+ }
1282
+ event.dataTransfer.effectAllowed = "move";
1283
+ event.dataTransfer.setData(COLUMN_DRAG_TYPE, item.column.id);
1284
+ grid.emit("columnDragStart", { columnId: item.column.id });
1285
+ }, onDragOver: (event) => {
1286
+ if (!Array.from(event.dataTransfer.types).includes(COLUMN_DRAG_TYPE))
1287
+ return;
1288
+ event.preventDefault();
1289
+ event.dataTransfer.dropEffect = "move";
1290
+ }, onDragEnd: () => grid.emit("columnDragEnd", { columnId: item.column.id }), onDrop: (event) => {
1291
+ const sourceColumnId = event.dataTransfer.getData(COLUMN_DRAG_TYPE);
1292
+ if (!sourceColumnId)
1293
+ return;
1294
+ event.preventDefault();
1295
+ event.stopPropagation();
1296
+ const bounds = event.currentTarget.getBoundingClientRect();
1297
+ const position = event.clientX < bounds.left + bounds.width / 2 ? "before" : "after";
1298
+ grid.emit("columnDrop", {
1299
+ sourceColumnId,
1300
+ targetColumnId: item.column.id,
1301
+ position,
1302
+ });
1303
+ }, onKeyDown: (event) => {
1307
1304
  if (event.key === "Enter" || event.key === " ")
1308
1305
  grid.headerClick(item.column.id);
1309
1306
  }, 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 +1352,33 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1355
1352
  visibility: isViewportMeasured ? undefined : "hidden",
1356
1353
  width: segment.width,
1357
1354
  };
1358
- return (_jsx("div", { role: "columnheader", className: className, "aria-colspan": segment.columnCount, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
1355
+ 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) => {
1356
+ if (segment.group.movable !== true) {
1357
+ event.preventDefault();
1358
+ return;
1359
+ }
1360
+ event.dataTransfer.effectAllowed = "move";
1361
+ event.dataTransfer.setData(COLUMN_DRAG_TYPE, segment.group.id);
1362
+ grid.emit("columnDragStart", { columnId: segment.group.id });
1363
+ }, onDragOver: (event) => {
1364
+ if (!Array.from(event.dataTransfer.types).includes(COLUMN_DRAG_TYPE))
1365
+ return;
1366
+ event.preventDefault();
1367
+ event.dataTransfer.dropEffect = "move";
1368
+ }, onDragEnd: () => grid.emit("columnDragEnd", { columnId: segment.group.id }), onDrop: (event) => {
1369
+ const sourceColumnId = event.dataTransfer.getData(COLUMN_DRAG_TYPE);
1370
+ if (!sourceColumnId)
1371
+ return;
1372
+ event.preventDefault();
1373
+ event.stopPropagation();
1374
+ const bounds = event.currentTarget.getBoundingClientRect();
1375
+ const position = event.clientX < bounds.left + bounds.width / 2 ? "before" : "after";
1376
+ grid.emit("columnDrop", {
1377
+ sourceColumnId,
1378
+ targetColumnId: segment.group.id,
1379
+ position,
1380
+ });
1381
+ }, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
1359
1382
  registry: slotComponentsRef.current,
1360
1383
  context: buildRenderContext,
1361
1384
  })) : (_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(["text", "number", "date", "select", "checkbox", "button", "label", "multi-select", "group"]);
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 ? createElement("label", { key: descriptor.id, className }, body, label) : createElement("label", { key: descriptor.id, className }, label, body);
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" || style.overflowY === "scroll" || style.overflow === "auto" || style.overflow === "scroll") {
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 = (anchorRect &&
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: ["omnigrid-control-button", descriptor.variant === "primary" ? "omnigrid-control-button-primary" : null, descriptor.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", { key: descriptor.id, className: ["omnigrid-control-label", descriptor.className].filter(Boolean).join(" ") }, descriptor.text);
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: ["omnigrid-control", "omnigrid-control-group", descriptor.direction === "row" ? "omnigrid-control-group-row" : null, descriptor.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)));
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { ColumnLeafDef, GridApi, GroupRowNode, RowId } from "@omnigrid/core";
3
3
  import { type ContentBridge } from "./content";
4
+ export declare function getTreeDataLeafIndent<T>(row: unknown, column: ColumnLeafDef<T>, grid: GridApi<T>): number | undefined;
4
5
  /**
5
6
  * Checks whether an arbitrary row node represents a grouping tree node.
6
7
  *
package/dist/groupCell.js CHANGED
@@ -1,8 +1,27 @@
1
1
  import { createElement } from "react";
2
2
  import { contentToReactNode } from "./content";
3
+ const TREE_DATA_LEVEL_INDENT = 20;
4
+ // Align leaf labels with group labels after the 24px toggle and 6px gap.
5
+ const TREE_DATA_LEAF_CONTROL_OFFSET = 30;
3
6
  function isToggleGroupMethod(method) {
4
7
  return typeof method === "function";
5
8
  }
9
+ function hasTreeDataRowModel(grid) {
10
+ return typeof grid.methods.getTreeRows === "function";
11
+ }
12
+ export function getTreeDataLeafIndent(row, column, grid) {
13
+ if (!hasTreeDataRowModel(grid) || !row || typeof row !== "object" || !("type" in row) || row.type !== "leaf") {
14
+ return undefined;
15
+ }
16
+ if (!("level" in row) || typeof row.level !== "number")
17
+ return undefined;
18
+ const state = grid.getState();
19
+ const groupBy = state.groupBy ?? [];
20
+ const mode = state.groupColumnMode ?? "single";
21
+ if (!getGroupColumnRole(column, groupBy, mode).isGroupColumn)
22
+ return undefined;
23
+ return row.level * TREE_DATA_LEVEL_INDENT + TREE_DATA_LEAF_CONTROL_OFFSET;
24
+ }
6
25
  /**
7
26
  * Checks whether an arbitrary row node represents a grouping tree node.
8
27
  *
@@ -139,7 +158,7 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
139
158
  }
140
159
  if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
141
160
  return undefined;
142
- if (groupBy.length > 0 && mode === "single") {
161
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "single") {
143
162
  const role = getGroupColumnRole(column, groupBy, mode);
144
163
  if (role.isGroupColumn) {
145
164
  return createElement("span", { style: { paddingLeft: node.level * 20 } });
@@ -149,7 +168,7 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
149
168
  return createElement("span");
150
169
  }
151
170
  }
152
- if (groupBy.length > 0 && mode === "perLevel") {
171
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "perLevel") {
153
172
  const role = getGroupColumnRole(column, groupBy, mode);
154
173
  if (role.isGroupColumn && !showGroupValues) {
155
174
  return createElement("span");
@@ -203,7 +222,7 @@ export function renderGroupCellPlaceholder(info, grid) {
203
222
  }
204
223
  if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
205
224
  return undefined;
206
- if (groupBy.length > 0 && mode === "single") {
225
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "single") {
207
226
  const role = getGroupColumnRole(column, groupBy, mode);
208
227
  if (role.isGroupColumn)
209
228
  return "";
@@ -211,7 +230,7 @@ export function renderGroupCellPlaceholder(info, grid) {
211
230
  if (isGroupField)
212
231
  return "";
213
232
  }
214
- if (groupBy.length > 0 && mode === "perLevel") {
233
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "perLevel") {
215
234
  const role = getGroupColumnRole(column, groupBy, mode);
216
235
  if (role.isGroupColumn && !showGroupValues)
217
236
  return "";
@@ -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
- this.host.style.transform = `translate3d(0, ${Math.round(offsetY)}px, 0)`;
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",