@omnigrid/core 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -305,6 +305,8 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
305
305
  }>;
306
306
  /** Horizontal alignment of cell content. */
307
307
  align?: CellAlign;
308
+ /** Enables automatic text wrapping instead of ellipsis truncation. @default false @api */
309
+ wrapText?: boolean;
308
310
  /** Initial sort direction used by SortingPlugin. */
309
311
  sortState?: SortDirection;
310
312
  /** 1-based sort priority, set only while multiple columns are sorted. */
@@ -402,6 +404,32 @@ export interface OverlayComponentProps<T> {
402
404
  * @api
403
405
  */
404
406
  export type OverlayComponent<T> = ((props: OverlayComponentProps<T>) => unknown) | ((payload: unknown, state: GridState<T>) => unknown);
407
+ /**
408
+ * Options for a single row-height update.
409
+ *
410
+ * @api
411
+ */
412
+ export interface RowHeightUpdateOptions {
413
+ /**
414
+ * Whether the grid applies the scroll anchoring correction itself.
415
+ * Set to `false` when the adapter wants to defer the correction — e.g.
416
+ * while the user is actively scrolling, where a scrollTop jump fights
417
+ * the user's input. The returned correction stays valid either way.
418
+ * @default true
419
+ */
420
+ anchor?: boolean;
421
+ /**
422
+ * Whether the grid notifies its Store subscribers about the change.
423
+ *
424
+ * The row heights are NOT part of the grid state — the notification only
425
+ * re-renders the host framework. Adapters that update the row geometry
426
+ * imperatively (the DOM pool) can opt out: a re-render per measured row
427
+ * starves the frame budget while the user scrolls, and the grid then
428
+ * lags behind the native scroll position.
429
+ * @default true
430
+ */
431
+ notify?: boolean;
432
+ }
405
433
  export interface GridOptions<T> {
406
434
  /** Row data; omitted or null means an initial load is pending. */
407
435
  data?: T[] | null;
@@ -409,6 +437,29 @@ export interface GridOptions<T> {
409
437
  /** Returns a stable row ID; defaults to the row's current index. Use a stable ID to preserve row identity when rows are reordered. */
410
438
  getRowId?: (row: T, index: number) => RowId;
411
439
  rowHeight?: number;
440
+ /** Enables automatic text wrapping for all cells. @default false @api */
441
+ wrapText?: boolean;
442
+ /**
443
+ * Fallback row height (px) for rows that have not been measured yet.
444
+ * When set (or when `getRowHeight` is set), the grid switches to
445
+ * variable-height mode: each row may have its own height, while unknown
446
+ * rows use this estimate for scrollbar and range math.
447
+ * Defaults to `rowHeight`.
448
+ * @api
449
+ */
450
+ estimatedRowHeight?: number;
451
+ /**
452
+ * Synchronous per-row height resolver. Must be O(1) — it is consulted
453
+ * during virtualization math. Return `undefined` to fall back to the
454
+ * estimated height for that row. Dynamically measured heights (via
455
+ * `setRowHeight`) always win over this resolver.
456
+ *
457
+ * The result is captured when the offset index is (re)built, so the
458
+ * resolver must be stable for a given row index — changing it requires
459
+ * a `setData` / `setColumns` call (or `resetAllRowHeights`).
460
+ * @api
461
+ */
462
+ getRowHeight?: (rowIndex: number, row: T) => number | undefined;
412
463
  /** Rows to render beyond the visible viewport (top + bottom buffer). @default 5 */
413
464
  rowOverscan?: number;
414
465
  /** Columns to render beyond the visible viewport (left + right buffer). @default 2 */
@@ -491,6 +542,7 @@ export interface ViewportData<T> {
491
542
  data: T;
492
543
  index: number;
493
544
  offset: number;
545
+ height?: number;
494
546
  }>;
495
547
  /** Scrollable (virtualized) leaf columns of the current horizontal window. */
496
548
  columns: Array<{
@@ -556,7 +608,29 @@ export interface ViewportData<T> {
556
608
  */
557
609
  columnGroupDepth: Map<number, number>;
558
610
  rowRange: Range;
611
+ /**
612
+ * Rows that intersect the viewport — `rowRange` without the overscan
613
+ * buffer.
614
+ *
615
+ * Adapters must bind these rows eagerly: pooled nodes are recycled in a
616
+ * ring, so a node that was not re-bound shows the data of an unrelated
617
+ * row.
618
+ * @api
619
+ */
620
+ visibleRowRange: Range;
559
621
  columnRange: Range;
622
+ /**
623
+ * Per-row vertical offsets aligned with `rowRange` in variable-height mode.
624
+ * Omitted in fixed-height mode.
625
+ * @api
626
+ */
627
+ rowOffsets?: number[];
628
+ /**
629
+ * Per-row heights aligned with `rowRange` in variable-height mode.
630
+ * Omitted in fixed-height mode.
631
+ * @api
632
+ */
633
+ rowHeights?: number[];
560
634
  totalWidth: number;
561
635
  totalHeight: number;
562
636
  }
@@ -629,6 +703,34 @@ export interface DomPoolBindings<T> {
629
703
  bindRow(host: RowHost<T>, row: PooledRow<T>): void;
630
704
  transformRow(host: RowHost<T>, offsetY: number): void;
631
705
  recycleRow(host: RowHost<T>): void;
706
+ /**
707
+ * Applies a new height to an already bound row node.
708
+ *
709
+ * Called when only the row HEIGHT changed (variable-height mode) while
710
+ * the row itself stayed the same: the content is still valid, so the
711
+ * node only needs a new box. Rebinding instead would re-render every
712
+ * cell of the row and re-trigger its measurement.
713
+ *
714
+ * Optional: when it is not implemented the pool falls back to a full
715
+ * re-bind for height changes.
716
+ * @api
717
+ */
718
+ resizeRow?(host: RowHost<T>, height: number): void;
719
+ /**
720
+ * Updates the row index a node stands for.
721
+ *
722
+ * Called when the node was re-used for a different row but its content
723
+ * could not be re-bound in the same frame (fast scroll, rebind quota).
724
+ * The node keeps the PREVIOUS content until it is bound, but its row
725
+ * index must already describe the NEW row — adapters look rows up by
726
+ * index (e.g. the hover highlight), and a stale index would highlight
727
+ * the wrong node.
728
+ *
729
+ * Optional: when it is not implemented the node keeps its old index
730
+ * until the content is bound.
731
+ * @api
732
+ */
733
+ updateRowIndex?(host: RowHost<T>, rowIndex: number): void;
632
734
  }
633
735
  /**
634
736
  * Options passed to `DomPool.update()` to control binding behavior.
@@ -642,6 +744,27 @@ export interface DomPoolUpdateOptions<T> {
642
744
  rowRange: Range;
643
745
  /** Pixel height of each row. */
644
746
  rowHeight: number;
747
+ /**
748
+ * Per-row geometry for variable-height mode, aligned with `rowRange`:
749
+ * `rowOffsets[i]` / `rowHeights[i]` describe `data[rowRange.start + i]`.
750
+ * When present, the pool positions each row at its own offset and height
751
+ * instead of `rowIndex * rowHeight`. Omitted in fixed-height mode.
752
+ * @api
753
+ */
754
+ rowOffsets?: number[];
755
+ /** Per-row heights aligned with `rowOffsets`. See `rowOffsets`. @api */
756
+ rowHeights?: number[];
757
+ /**
758
+ * Rows that intersect the viewport (a subset of `rowRange`, without the
759
+ * overscan buffer).
760
+ *
761
+ * These rows are bound even when `skipBind` is set: a recycled node that
762
+ * is not re-bound keeps the content of a completely unrelated row, and
763
+ * the user would see the wrong data in the visible area. The off-screen
764
+ * rows follow the rebind quota.
765
+ * @api
766
+ */
767
+ visibleRowRange?: Range;
645
768
  /** Pixel width of each row (sum of all column widths). */
646
769
  rowWidth: number;
647
770
  /**
@@ -682,6 +805,51 @@ export interface GridPlugin<T> {
682
805
  getRowClass?(params: RowRenderParams<T>): string | undefined;
683
806
  getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
684
807
  }
808
+ /**
809
+ * A single targeted row transaction: add, update, or remove rows by their
810
+ * stable identifier (`getRowId`) without recreating the whole data array.
811
+ *
812
+ * Rows are matched against the current dataset by their row id. `add`
813
+ * appends new rows (optionally at `addIndex`), `update` replaces existing
814
+ * rows matched by id, and `remove` drops rows matched by id or by row object
815
+ * reference. Use a stable `getRowId` (a business key, not the row index) so
816
+ * row identity survives reordering and transactions.
817
+ *
818
+ * @api
819
+ */
820
+ export interface RowTransaction<T> {
821
+ /** Rows to add. Each row receives a stable id via `getRowId`. */
822
+ add?: T[];
823
+ /**
824
+ * Zero-based index at which added rows are inserted.
825
+ * Defaults to appending at the end of the dataset.
826
+ * @default dataset length
827
+ * @api
828
+ */
829
+ addIndex?: number;
830
+ /** Rows to update. Each row is matched by id and replaced with the new data. */
831
+ update?: T[];
832
+ /**
833
+ * Rows to remove, given either as row objects (matched by id/reference)
834
+ * or as raw row ids.
835
+ * @api
836
+ */
837
+ remove?: Array<T | RowId>;
838
+ }
839
+ /**
840
+ * Outcome of `Grid.applyTransaction`: the added, updated and removed rows
841
+ * with their resolved ids and indexes in the dataset.
842
+ *
843
+ * @api
844
+ */
845
+ export interface TransactionResult<T> {
846
+ /** Rows that were added, with their resolved id and index. */
847
+ added: RowNode<T>[];
848
+ /** Rows that were updated, with their resolved id and index. */
849
+ updated: RowNode<T>[];
850
+ /** Rows that were removed, with their resolved id and previous index. */
851
+ removed: RowNode<T>[];
852
+ }
685
853
  export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom" | "down";
686
854
  export type SlotPosition = "start" | "center" | "end";
687
855
  /**
@@ -823,6 +991,61 @@ export interface GridApi<T> {
823
991
  * @api
824
992
  */
825
993
  appendData(rows: T[] | null | undefined): void;
994
+ /**
995
+ * Applies a targeted row transaction (add / update / remove) to the State
996
+ * Store without recreating the whole data array.
997
+ *
998
+ * Rows are matched by their stable id (`getRowId`). The pipeline caches
999
+ * (filtered / processed data) are invalidated and the virtualizer's
1000
+ * row-height cache is reset only for the affected rows (or fully when the
1001
+ * dataset size changes), avoiding heavy recomputation.
1002
+ *
1003
+ * Emits a single `dataChange` with the resulting dataset and bumps the
1004
+ * grid revision.
1005
+ * @param transaction - The rows to add, update and/or remove.
1006
+ * @returns The added, updated and removed rows with resolved ids/indexes.
1007
+ * @api
1008
+ */
1009
+ applyTransaction(transaction: RowTransaction<T>): TransactionResult<T>;
1010
+ /**
1011
+ * Records the measured DOM height of a row (variable-height mode).
1012
+ * Heights below 1px delta are ignored to prevent feedback loops between
1013
+ * measurement and layout. Switching the height of rows above the current
1014
+ * scroll position keeps the anchored row visually stable: the returned
1015
+ * value is the scrollTop correction (px, may be negative) the adapter
1016
+ * must apply to its scroll container to prevent viewport jumps.
1017
+ * @param rowIndex - Zero-based index in the processed dataset.
1018
+ * @param height - Measured row height in pixels (must be finite and > 0).
1019
+ * @param options - Optional anchoring control.
1020
+ * @returns ScrollTop adjustment in pixels (`0` = no anchoring needed).
1021
+ * @api
1022
+ */
1023
+ setRowHeight(rowIndex: number, height: number, options?: RowHeightUpdateOptions): number;
1024
+ /**
1025
+ * Removes a measured row height (e.g. when row content collapses back to
1026
+ * the estimate). Returns the scrollTop correction like `setRowHeight`.
1027
+ * @param rowIndex - Zero-based index in the processed dataset.
1028
+ * @param options - Optional anchoring control.
1029
+ * @returns ScrollTop adjustment in pixels (`0` = no anchoring needed).
1030
+ * @api
1031
+ */
1032
+ resetRowHeight(rowIndex: number, options?: RowHeightUpdateOptions): number;
1033
+ /** Removes all measured row heights (e.g. after `setColumns`). @api */
1034
+ resetAllRowHeights(): void;
1035
+ /**
1036
+ * Returns the absolute vertical offset (px) of the top of a row,
1037
+ * accounting for variable heights. Falls back to `index * rowHeight`
1038
+ * when no measurements exist.
1039
+ * @param rowIndex - Zero-based index in the processed dataset.
1040
+ * @api
1041
+ */
1042
+ getRowTop(rowIndex: number): number;
1043
+ /**
1044
+ * Returns the current (measured, resolved, or estimated) height of a row.
1045
+ * @param rowIndex - Zero-based index in the processed dataset.
1046
+ * @api
1047
+ */
1048
+ getRowHeight(rowIndex: number): number;
826
1049
  setViewport(viewport: Partial<ViewportState>): void;
827
1050
  refresh(): void;
828
1051
  subscribe(listener: () => void): () => void;
@@ -1,17 +1,154 @@
1
1
  import type { ColumnLeafDef, Range, VirtualItem } from "./types";
2
2
  export interface VirtualizerOptions {
3
3
  rowHeight: number;
4
+ /** Fallback height for unmeasured rows in variable-height mode. */
5
+ estimatedRowHeight?: number;
6
+ /** Synchronous per-row height resolver. */
7
+ getRowHeight?: (rowIndex: number) => number | undefined;
4
8
  rowOverscan: number;
5
9
  columnOverscan: number;
6
10
  }
11
+ /**
12
+ * Dynamic row-height registry: `rowIndex -> measured px height`.
13
+ *
14
+ * Heights live in a Fenwick tree (binary indexed tree) over the row indexes.
15
+ * A single measurement is applied in O(log n) — the prefix sums are patched
16
+ * in place instead of rebuilding the whole offset table — and row offsets /
17
+ * range lookups are answered with O(log n) prefix queries and searches.
18
+ * Rebuilding the whole table is only needed when the dataset size or the
19
+ * estimate changes, which happens on structural changes only.
20
+ *
21
+ * Rows without a measurement use the resolver value, or the estimate. The
22
+ * resolver result is captured when the index is (re)built, so it must be
23
+ * stable for a given row index.
24
+ */
25
+ export declare class RowHeightRegistry {
26
+ private heights;
27
+ /** Estimated height for rows without a measurement. */
28
+ private estimatedHeight;
29
+ private readonly resolver?;
30
+ private currentVersion;
31
+ /** Fenwick tree of row heights (1-based indexing). */
32
+ private tree;
33
+ /** Raw height of every row the tree covers — mirrors the tree leaves. */
34
+ private leaves;
35
+ /** Number of rows the tree currently covers. */
36
+ private treeCount;
37
+ /** Whether the tree has to be rebuilt before the next query. */
38
+ private treeDirty;
39
+ constructor(estimatedHeight: number, resolver?: (rowIndex: number) => number | undefined);
40
+ /** Total number of rows with an explicit measured height. @api */
41
+ get size(): number;
42
+ /** Monotonically increasing revision number bumped on any measurement or estimate change. @api */
43
+ get version(): number;
44
+ /** Whether any variable-height input exists (resolver or measured heights). @api */
45
+ get hasVariableHeights(): boolean;
46
+ /** Updates the fallback estimated height for unmeasured rows. @api */
47
+ setEstimatedHeight(height: number): void;
48
+ /**
49
+ * Records a measured height. Returns `true` when the value actually
50
+ * changed (delta > 1px); sub-pixel noise is ignored to prevent
51
+ * measurement/layout feedback loops.
52
+ */
53
+ set(rowIndex: number, height: number): boolean;
54
+ /** Removes a single measured height. Returns `true` when one existed. */
55
+ reset(rowIndex: number): boolean;
56
+ /** Removes all measured heights. */
57
+ clear(): void;
58
+ /** Returns the measured height of a row if one has been recorded, or undefined. @api */
59
+ get(rowIndex: number): number | undefined;
60
+ /** Returns the resolved height of a row (measured, dynamic callback, or estimated). */
61
+ getRowHeight(rowIndex: number): number;
62
+ /** Materializes the cumulative offsets table (`offsets[i]` = top of row `i`). @api */
63
+ getOffsets(count: number): number[];
64
+ /** Total scrollable content height for `count` rows. @api */
65
+ getTotalHeight(count: number): number;
66
+ /** Absolute top offset of a row (clamped to the dataset). @api */
67
+ getTop(rowIndex: number, count: number): number;
68
+ /**
69
+ * First row whose bottom edge is strictly below `offset`
70
+ * (binary search over the Fenwick tree).
71
+ * @api
72
+ */
73
+ findStart(count: number, offset: number): number;
74
+ /**
75
+ * First row whose top edge is at or past `offset`
76
+ * (binary search over the Fenwick tree). Used as the exclusive window end.
77
+ * @api
78
+ */
79
+ findEnd(count: number, offset: number): number;
80
+ /** Marks the offset index dirty when the dataset identity changes. @api */
81
+ invalidate(count: number): void;
82
+ /** Resolves the effective height of a row: measured, resolver, or estimate. */
83
+ private resolveHeight;
84
+ /** Rebuilds the Fenwick tree when the dataset size or the estimate changed. */
85
+ private ensureTree;
86
+ /** Patches a single row height into the live tree (O(log n)). */
87
+ private applyDelta;
88
+ /** Sum of the first `count` row heights. */
89
+ private static prefixSum;
90
+ /**
91
+ * Finds the largest row count whose cumulative height does not exceed
92
+ * `offset` — i.e. the number of rows fully above the offset.
93
+ */
94
+ private static findFloor;
95
+ }
7
96
  export declare class Virtualizer<T> {
8
97
  private readonly options;
98
+ private readonly heights;
9
99
  private lastScrollTop;
10
100
  private lastRowRange;
11
101
  private lastRowCount;
12
102
  private lastRowViewportHeight;
103
+ private lastHeightsVersion;
13
104
  constructor(options: VirtualizerOptions);
14
- getRowRange(count: number, scrollTop: number, viewportHeight: number): Range;
105
+ /** Dynamic height registry backing variable-height mode. @api */
106
+ get rowHeights(): RowHeightRegistry;
107
+ /** Estimated height used for rows without a measurement. @api */
108
+ get estimatedRowHeight(): number;
109
+ /** Whether any variable-height input exists (resolver counts or measured heights exist). @api */
110
+ get hasVariableHeights(): boolean;
111
+ /**
112
+ * Visible row range calculation for fixed or variable heights.
113
+ * @api
114
+ */
115
+ getRowRange(count: number, scrollTop: number, viewportHeight: number, variableHeights?: boolean): Range;
116
+ /**
117
+ * Computes the visible row window for variable-height mode using the
118
+ * incremental offset index (binary search over the Fenwick tree).
119
+ * @api
120
+ */
121
+ getVariableRowRange(count: number, scrollTop: number, viewportHeight: number): Range;
122
+ /**
123
+ * Rows that intersect the viewport — the range WITHOUT the overscan
124
+ * buffer.
125
+ *
126
+ * The DOM pool reuses its nodes in a ring: a node that was not re-bound
127
+ * keeps the content of a completely unrelated row. The rows that
128
+ * intersect the viewport must therefore always be bound, even while a
129
+ * fast scroll defers the off-screen (overscan) rows.
130
+ * @api
131
+ */
132
+ getVisibleRowRange(count: number, scrollTop: number, viewportHeight: number): Range;
133
+ /**
134
+ * Absolute vertical offset (px) of the top of a row, accounting for variable heights.
135
+ * @api
136
+ */
137
+ getRowTop(rowIndex: number, count: number): number;
138
+ /** Current (measured, resolved, or estimated) height of a row. @api */
139
+ getRowHeight(rowIndex: number): number;
140
+ /**
141
+ * Records a measured row height and returns the scrollTop correction needed
142
+ * to keep the visually anchored row stable (scroll anchoring).
143
+ * @api
144
+ */
145
+ setRowHeight(rowIndex: number, height: number, scrollTop: number, count: number): number;
146
+ /** Removes a measured row height (falls back to resolver or estimate). @api */
147
+ resetRowHeight(rowIndex: number, scrollTop: number, count: number): number;
148
+ /** Removes all measured row heights (e.g. after `setColumns`). @api */
149
+ resetAllRowHeights(): void;
150
+ /** Total scrollable content height for `count` rows, accounting for variable heights. @api */
151
+ getTotalHeight(count: number): number;
15
152
  /**
16
153
  * Column geometry works on the FLAT working set of leaf columns only —
17
154
  * groups never reach the Virtualizer (see `Grid.getViewportData()`).
@@ -23,7 +160,6 @@ export declare class Virtualizer<T> {
23
160
  getColumnRange(columns: ColumnLeafDef<T>[], scrollLeft: number, viewportWidth: number, offsets?: VirtualItem[]): Range;
24
161
  private readonly widthsCache;
25
162
  getColumnOffsets(columns: ColumnLeafDef<T>[], viewportWidth?: number): VirtualItem[];
26
- getTotalHeight(rowCount: number): number;
27
163
  getTotalWidth(columns: ColumnLeafDef<T>[], viewportWidth?: number): number;
28
164
  private getRange;
29
165
  private getColumnWidths;