@omnigrid/core 0.1.20 → 0.1.22
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 +23 -0
- package/dist/columns.d.ts +67 -1
- package/dist/columns.js +147 -0
- package/dist/dom-pool.d.ts +1 -0
- package/dist/dom-pool.js +51 -8
- package/dist/grid.d.ts +96 -1
- package/dist/grid.js +205 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/types.d.ts +307 -1
- package/dist/virtualizer.d.ts +138 -2
- package/dist/virtualizer.js +390 -4
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -28,11 +28,94 @@ export type ColumnDataType = "text" | "number" | "date" | "boolean";
|
|
|
28
28
|
* @api
|
|
29
29
|
*/
|
|
30
30
|
export type ColumnFilterType = "text" | "number" | "date" | "boolean" | "set" | "custom";
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Row identity and position metadata passed to row-aware callbacks.
|
|
33
|
+
*
|
|
34
|
+
* `RowNode` is a lightweight view over a single processed row: the stable
|
|
35
|
+
* `id` (from `getRowId`), the zero-based `index` in the processed dataset,
|
|
36
|
+
* and the raw `data` object itself.
|
|
37
|
+
*
|
|
38
|
+
* @api
|
|
39
|
+
*/
|
|
40
|
+
export interface RowNode<T> {
|
|
41
|
+
/** Stable row identifier (from `getRowId`, defaults to row index). */
|
|
32
42
|
id: RowId;
|
|
43
|
+
/** Zero-based index of the row in the processed dataset. */
|
|
33
44
|
index: number;
|
|
45
|
+
/** Raw row data object. */
|
|
46
|
+
data: T;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Context passed to the `colSpan` resolver of a column.
|
|
50
|
+
*
|
|
51
|
+
* Mirrors the data-bearing fields of `RowNode` plus the column being
|
|
52
|
+
* evaluated, so span decisions can depend on row values, row position,
|
|
53
|
+
* or column identity.
|
|
54
|
+
*
|
|
55
|
+
* @api
|
|
56
|
+
*/
|
|
57
|
+
export interface CellSpanningParams<T> {
|
|
58
|
+
/** Raw row data object. */
|
|
34
59
|
data: T;
|
|
60
|
+
/** Row identity and position metadata. */
|
|
61
|
+
node: RowNode<T>;
|
|
62
|
+
/** Column definition being evaluated for spanning. */
|
|
63
|
+
column: ColumnLeafDef<T>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Horizontal span declared on a leaf column.
|
|
67
|
+
*
|
|
68
|
+
* A static number merges that many consecutive visible columns starting at
|
|
69
|
+
* the current column; a function computes the span per row from
|
|
70
|
+
* `CellSpanningParams`. Values are normalized to integers `>= 1`
|
|
71
|
+
* (`1` = no spanning, the default).
|
|
72
|
+
*
|
|
73
|
+
* @api
|
|
74
|
+
*/
|
|
75
|
+
export type ColSpanDef<T> = number | ((params: CellSpanningParams<T>) => number);
|
|
76
|
+
/**
|
|
77
|
+
* Normalized horizontal span of a single body cell.
|
|
78
|
+
*
|
|
79
|
+
* Produced per visible row by `getRowSpans`: `span` is the merged width in
|
|
80
|
+
* columns (`1` = plain cell), `covered` marks cells hidden underneath a span
|
|
81
|
+
* started at an earlier column.
|
|
82
|
+
*
|
|
83
|
+
* @api
|
|
84
|
+
*/
|
|
85
|
+
export interface CellSpan {
|
|
86
|
+
/** Merged width in visible columns (`1` = no spanning). */
|
|
87
|
+
span: number;
|
|
88
|
+
/** Whether this cell is covered by a span that starts to its left. */
|
|
89
|
+
covered: boolean;
|
|
35
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Per-row span layout for one pin group of the body.
|
|
93
|
+
*
|
|
94
|
+
* `spans` is indexed by position in the visible leaf group: `spans[i]`
|
|
95
|
+
* describes the cell at that leaf for this row. `widths[i]` / `offsets[i]`
|
|
96
|
+
* are the aggregated pixel geometry — the `left` of a span origin and the
|
|
97
|
+
* summed width of the `span` covered columns.
|
|
98
|
+
*
|
|
99
|
+
* @api
|
|
100
|
+
*/
|
|
101
|
+
export interface RowSpanLayout {
|
|
102
|
+
/** Per-leaf span descriptors, indexed by position in the pin group. */
|
|
103
|
+
spans: CellSpan[];
|
|
104
|
+
/** Aggregated pixel width per leaf (span origins carry the summed width). */
|
|
105
|
+
widths: number[];
|
|
106
|
+
/** Pixel `left` per leaf (span origins align with the starting column). */
|
|
107
|
+
offsets: number[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Context passed to every row-level callback (`getRowStyle`, `getRowClass`,
|
|
111
|
+
* `rowClassRules`, `checkboxDisabled`, ...).
|
|
112
|
+
*
|
|
113
|
+
* Alias of `RowNode`: the stable row id, the zero-based index in the
|
|
114
|
+
* processed dataset, and the raw row data object.
|
|
115
|
+
*
|
|
116
|
+
* @api
|
|
117
|
+
*/
|
|
118
|
+
export type RowRenderParams<T> = RowNode<T>;
|
|
36
119
|
export interface RowStyle {
|
|
37
120
|
[property: string]: string | number | undefined;
|
|
38
121
|
}
|
|
@@ -222,12 +305,27 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
|
|
|
222
305
|
}>;
|
|
223
306
|
/** Horizontal alignment of cell content. */
|
|
224
307
|
align?: CellAlign;
|
|
308
|
+
/** Enables automatic text wrapping instead of ellipsis truncation. @default false @api */
|
|
309
|
+
wrapText?: boolean;
|
|
225
310
|
/** Initial sort direction used by SortingPlugin. */
|
|
226
311
|
sortState?: SortDirection;
|
|
227
312
|
/** 1-based sort priority, set only while multiple columns are sorted. */
|
|
228
313
|
sortIndex?: number;
|
|
229
314
|
/** Compares values for this column, overriding the sorting plugin default. */
|
|
230
315
|
comparator?: (left: unknown, right: unknown, column: ColumnLeafDef<T>) => number;
|
|
316
|
+
/**
|
|
317
|
+
* Horizontal cell merging declared on the column.
|
|
318
|
+
*
|
|
319
|
+
* A static number merges that many consecutive visible columns starting
|
|
320
|
+
* at this column; a function computes the span per row from
|
|
321
|
+
* `CellSpanningParams`. Normalized to an integer `>= 1` (`1` = no merge).
|
|
322
|
+
* Spans are clipped to the visible leaf layout (pinned groups never
|
|
323
|
+
* merge) and covered cells are skipped during rendering.
|
|
324
|
+
*
|
|
325
|
+
* @default 1
|
|
326
|
+
* @api
|
|
327
|
+
*/
|
|
328
|
+
colSpan?: ColSpanDef<T>;
|
|
231
329
|
/** Prevents clicks in this column's cells from triggering row-click behavior. */
|
|
232
330
|
stopRowClick?: boolean;
|
|
233
331
|
/** Prevents clicks on this column's header from triggering header-click behavior. */
|
|
@@ -306,6 +404,32 @@ export interface OverlayComponentProps<T> {
|
|
|
306
404
|
* @api
|
|
307
405
|
*/
|
|
308
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
|
+
}
|
|
309
433
|
export interface GridOptions<T> {
|
|
310
434
|
/** Row data; omitted or null means an initial load is pending. */
|
|
311
435
|
data?: T[] | null;
|
|
@@ -313,6 +437,29 @@ export interface GridOptions<T> {
|
|
|
313
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. */
|
|
314
438
|
getRowId?: (row: T, index: number) => RowId;
|
|
315
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;
|
|
316
463
|
/** Rows to render beyond the visible viewport (top + bottom buffer). @default 5 */
|
|
317
464
|
rowOverscan?: number;
|
|
318
465
|
/** Columns to render beyond the visible viewport (left + right buffer). @default 2 */
|
|
@@ -395,6 +542,7 @@ export interface ViewportData<T> {
|
|
|
395
542
|
data: T;
|
|
396
543
|
index: number;
|
|
397
544
|
offset: number;
|
|
545
|
+
height?: number;
|
|
398
546
|
}>;
|
|
399
547
|
/** Scrollable (virtualized) leaf columns of the current horizontal window. */
|
|
400
548
|
columns: Array<{
|
|
@@ -417,6 +565,27 @@ export interface ViewportData<T> {
|
|
|
417
565
|
offset: number;
|
|
418
566
|
width: number;
|
|
419
567
|
}>;
|
|
568
|
+
/**
|
|
569
|
+
* Full ordered leaf columns of each pin group (scrollable or pinned),
|
|
570
|
+
* independent of the current virtual window. Adapters use these together
|
|
571
|
+
* with `getRowSpans` (or `Grid.getRowSpans`) to resolve per-row spanning:
|
|
572
|
+
* the windowed `columns` / `pinned*Columns` above only carry the visible
|
|
573
|
+
* slice, while a span origin may sit before the window and cover into it.
|
|
574
|
+
*/
|
|
575
|
+
leafColumns: ColumnLeafDef<T>[];
|
|
576
|
+
/** Full ordered leaf columns of the left-pinned group. See `leafColumns`. */
|
|
577
|
+
pinnedLeftLeafColumns: ColumnLeafDef<T>[];
|
|
578
|
+
/** Full ordered leaf columns of the right-pinned group. See `leafColumns`. */
|
|
579
|
+
pinnedRightLeafColumns: ColumnLeafDef<T>[];
|
|
580
|
+
/**
|
|
581
|
+
* Pre-computed absolute geometry (`offset`/`size`) for every entry of
|
|
582
|
+
* `leafColumns`, aligned by position. Backs span width aggregation.
|
|
583
|
+
*/
|
|
584
|
+
columnOffsets: VirtualItem[];
|
|
585
|
+
/** Pre-computed absolute geometry for `pinnedLeftLeafColumns`, aligned by position. */
|
|
586
|
+
pinnedLeftOffsets: VirtualItem[];
|
|
587
|
+
/** Pre-computed absolute geometry for `pinnedRightLeafColumns`, aligned by position. */
|
|
588
|
+
pinnedRightOffsets: VirtualItem[];
|
|
420
589
|
/**
|
|
421
590
|
* Column groups (definitions with leaf spans) — the data needed to render
|
|
422
591
|
* stacked group header rows. Empty when no groups are defined.
|
|
@@ -439,7 +608,29 @@ export interface ViewportData<T> {
|
|
|
439
608
|
*/
|
|
440
609
|
columnGroupDepth: Map<number, number>;
|
|
441
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;
|
|
442
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[];
|
|
443
634
|
totalWidth: number;
|
|
444
635
|
totalHeight: number;
|
|
445
636
|
}
|
|
@@ -512,6 +703,34 @@ export interface DomPoolBindings<T> {
|
|
|
512
703
|
bindRow(host: RowHost<T>, row: PooledRow<T>): void;
|
|
513
704
|
transformRow(host: RowHost<T>, offsetY: number): void;
|
|
514
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;
|
|
515
734
|
}
|
|
516
735
|
/**
|
|
517
736
|
* Options passed to `DomPool.update()` to control binding behavior.
|
|
@@ -525,6 +744,27 @@ export interface DomPoolUpdateOptions<T> {
|
|
|
525
744
|
rowRange: Range;
|
|
526
745
|
/** Pixel height of each row. */
|
|
527
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;
|
|
528
768
|
/** Pixel width of each row (sum of all column widths). */
|
|
529
769
|
rowWidth: number;
|
|
530
770
|
/**
|
|
@@ -668,6 +908,33 @@ export interface GridApi<T> {
|
|
|
668
908
|
getColumnWidth(columnId: string): number | undefined;
|
|
669
909
|
getProcessedData(): T[];
|
|
670
910
|
getRowId(row: T, index: number): RowId;
|
|
911
|
+
/**
|
|
912
|
+
* Resolves the normalized horizontal span of a single body cell.
|
|
913
|
+
* Clips the declared `colSpan` to the pin group and falls back to `1`
|
|
914
|
+
* for invalid declarations or resolver errors.
|
|
915
|
+
* @param data - Raw row data object.
|
|
916
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
917
|
+
* @param column - Column definition being evaluated.
|
|
918
|
+
* @param columnIndex - Position of the column in the visible leaf layout.
|
|
919
|
+
* @param columnCount - Total number of visible leaves in the pin group.
|
|
920
|
+
* @returns Normalized span width in columns (`1` = no merge).
|
|
921
|
+
* @api
|
|
922
|
+
*/
|
|
923
|
+
resolveColSpan(data: T, index: number, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
|
|
924
|
+
/**
|
|
925
|
+
* Resolves the per-row span layout for one pin group of the body.
|
|
926
|
+
* Computes merged widths and covered cells across the FULL leaf group.
|
|
927
|
+
* @param data - Raw row data object.
|
|
928
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
929
|
+
* @param columns - Full ordered leaves of one pin group.
|
|
930
|
+
* @param offsets - Pre-computed absolute geometry for `columns`.
|
|
931
|
+
* @returns Per-row span layout for the group.
|
|
932
|
+
* @api
|
|
933
|
+
*/
|
|
934
|
+
getRowSpans(data: T, index: number, columns: ColumnLeafDef<T>[], offsets: {
|
|
935
|
+
offset: number;
|
|
936
|
+
size: number;
|
|
937
|
+
}[]): RowSpanLayout;
|
|
671
938
|
setData(data: T[] | null | undefined): void;
|
|
672
939
|
/**
|
|
673
940
|
* Chunk-append API for incremental data loading (infinite scroll, live
|
|
@@ -679,6 +946,45 @@ export interface GridApi<T> {
|
|
|
679
946
|
* @api
|
|
680
947
|
*/
|
|
681
948
|
appendData(rows: T[] | null | undefined): void;
|
|
949
|
+
/**
|
|
950
|
+
* Records the measured DOM height of a row (variable-height mode).
|
|
951
|
+
* Heights below 1px delta are ignored to prevent feedback loops between
|
|
952
|
+
* measurement and layout. Switching the height of rows above the current
|
|
953
|
+
* scroll position keeps the anchored row visually stable: the returned
|
|
954
|
+
* value is the scrollTop correction (px, may be negative) the adapter
|
|
955
|
+
* must apply to its scroll container to prevent viewport jumps.
|
|
956
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
957
|
+
* @param height - Measured row height in pixels (must be finite and > 0).
|
|
958
|
+
* @param options - Optional anchoring control.
|
|
959
|
+
* @returns ScrollTop adjustment in pixels (`0` = no anchoring needed).
|
|
960
|
+
* @api
|
|
961
|
+
*/
|
|
962
|
+
setRowHeight(rowIndex: number, height: number, options?: RowHeightUpdateOptions): number;
|
|
963
|
+
/**
|
|
964
|
+
* Removes a measured row height (e.g. when row content collapses back to
|
|
965
|
+
* the estimate). Returns the scrollTop correction like `setRowHeight`.
|
|
966
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
967
|
+
* @param options - Optional anchoring control.
|
|
968
|
+
* @returns ScrollTop adjustment in pixels (`0` = no anchoring needed).
|
|
969
|
+
* @api
|
|
970
|
+
*/
|
|
971
|
+
resetRowHeight(rowIndex: number, options?: RowHeightUpdateOptions): number;
|
|
972
|
+
/** Removes all measured row heights (e.g. after `setColumns`). @api */
|
|
973
|
+
resetAllRowHeights(): void;
|
|
974
|
+
/**
|
|
975
|
+
* Returns the absolute vertical offset (px) of the top of a row,
|
|
976
|
+
* accounting for variable heights. Falls back to `index * rowHeight`
|
|
977
|
+
* when no measurements exist.
|
|
978
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
979
|
+
* @api
|
|
980
|
+
*/
|
|
981
|
+
getRowTop(rowIndex: number): number;
|
|
982
|
+
/**
|
|
983
|
+
* Returns the current (measured, resolved, or estimated) height of a row.
|
|
984
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
985
|
+
* @api
|
|
986
|
+
*/
|
|
987
|
+
getRowHeight(rowIndex: number): number;
|
|
682
988
|
setViewport(viewport: Partial<ViewportState>): void;
|
|
683
989
|
refresh(): void;
|
|
684
990
|
subscribe(listener: () => void): () => void;
|
package/dist/virtualizer.d.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|