@omnigrid/core 0.1.12 → 0.1.13
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/dom-pool.d.ts +13 -21
- package/dist/dom-pool.js +85 -13
- package/dist/grid.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/virtualizer.d.ts +6 -1
- package/dist/virtualizer.js +29 -7
- package/package.json +1 -1
package/dist/dom-pool.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DomPoolBindings, DomPoolUpdate,
|
|
1
|
+
import type { DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, RowHost, RowId } from "./types";
|
|
2
2
|
export interface DomPoolOptions<T> {
|
|
3
3
|
rowHeight: number;
|
|
4
4
|
getRowId?: (row: T, index: number) => RowId;
|
|
@@ -8,31 +8,19 @@ export interface DomPoolOptions<T> {
|
|
|
8
8
|
*/
|
|
9
9
|
bindings: DomPoolBindings<T>;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Viewport frame for the DomPool.
|
|
13
|
-
*
|
|
14
|
-
* The `rowRange` and `columnRanges` are computed by the Grid's single
|
|
15
|
-
* Virtualizer (see `Grid.getViewportData()`). The DomPool does NOT virtualize
|
|
16
|
-
* on its own — it trusts the range provided by the core.
|
|
17
|
-
*/
|
|
18
|
-
export interface DomPoolViewport<T> {
|
|
19
|
-
/** Inclusive start, exclusive end of visible rows (from Virtualizer). */
|
|
20
|
-
rowRange: Range;
|
|
21
|
-
/** Full (post-processing) array of rows. */
|
|
22
|
-
data: T[];
|
|
23
|
-
/** Pixel height of each row. */
|
|
24
|
-
rowHeight: number;
|
|
25
|
-
/** Pixel width of each row (sum of all column widths). */
|
|
26
|
-
rowWidth: number;
|
|
27
|
-
}
|
|
28
11
|
/**
|
|
29
12
|
* Pool of reusable row nodes.
|
|
30
13
|
*
|
|
31
14
|
* The core maintains a fixed-size set of node hosts (`hosts[]`) and maps
|
|
32
|
-
*
|
|
15
|
+
* each row to a pool slot via a RING mapping: `slot = rowIndex % poolSize`.
|
|
16
|
+
* On scroll nodes are NOT created or destroyed —
|
|
33
17
|
* a node simply changes `transform: translateY` (position) and, if its row
|
|
34
18
|
* index changed, receives new data via `bindings.bindRow`. Text/content is
|
|
35
|
-
* updated in-place without recreating elements.
|
|
19
|
+
* updated in-place without recreating elements. Because the slot a row
|
|
20
|
+
* occupies is derived from the row index itself (not from the window
|
|
21
|
+
* position), content travels with its row: scrolling by k rows recycles
|
|
22
|
+
* only the k slots of rows that left the window instead of invalidating
|
|
23
|
+
* the entire pool.
|
|
36
24
|
*
|
|
37
25
|
* The row range is provided by the caller (the Grid's single Virtualizer),
|
|
38
26
|
* ensuring there is exactly one source of truth for virtualization.
|
|
@@ -42,7 +30,11 @@ export declare class DomPool<T> {
|
|
|
42
30
|
private readonly bindings;
|
|
43
31
|
private readonly hosts;
|
|
44
32
|
private readonly hostRowIndex;
|
|
33
|
+
/** Whether slot i's content (bindRow) has been bound since its last position change. */
|
|
34
|
+
private readonly hostContentBound;
|
|
45
35
|
private readonly hostOffsetY;
|
|
36
|
+
/** Scratch flags: whether slot i was claimed by the current window (ring mapping). */
|
|
37
|
+
private readonly slotActive;
|
|
46
38
|
/** Data changed — force-rebind visible nodes on the next frame. */
|
|
47
39
|
private forceRebind;
|
|
48
40
|
private lastData;
|
|
@@ -56,7 +48,7 @@ export declare class DomPool<T> {
|
|
|
56
48
|
* ONLY for nodes that have actually changed and returns an info
|
|
57
49
|
* report describing the update.
|
|
58
50
|
*/
|
|
59
|
-
update(viewport:
|
|
51
|
+
update(viewport: DomPoolUpdateOptions<T>): DomPoolUpdate<T>;
|
|
60
52
|
/**
|
|
61
53
|
* Force-rebinds all visible nodes on the next frame.
|
|
62
54
|
* Used by the adapter on `refresh()` or data replacement when
|
package/dist/dom-pool.js
CHANGED
|
@@ -4,10 +4,15 @@ const OFFSCREEN_Y = -200000;
|
|
|
4
4
|
* Pool of reusable row nodes.
|
|
5
5
|
*
|
|
6
6
|
* The core maintains a fixed-size set of node hosts (`hosts[]`) and maps
|
|
7
|
-
*
|
|
7
|
+
* each row to a pool slot via a RING mapping: `slot = rowIndex % poolSize`.
|
|
8
|
+
* On scroll nodes are NOT created or destroyed —
|
|
8
9
|
* a node simply changes `transform: translateY` (position) and, if its row
|
|
9
10
|
* index changed, receives new data via `bindings.bindRow`. Text/content is
|
|
10
|
-
* updated in-place without recreating elements.
|
|
11
|
+
* updated in-place without recreating elements. Because the slot a row
|
|
12
|
+
* occupies is derived from the row index itself (not from the window
|
|
13
|
+
* position), content travels with its row: scrolling by k rows recycles
|
|
14
|
+
* only the k slots of rows that left the window instead of invalidating
|
|
15
|
+
* the entire pool.
|
|
11
16
|
*
|
|
12
17
|
* The row range is provided by the caller (the Grid's single Virtualizer),
|
|
13
18
|
* ensuring there is exactly one source of truth for virtualization.
|
|
@@ -16,7 +21,11 @@ export class DomPool {
|
|
|
16
21
|
constructor(options) {
|
|
17
22
|
this.hosts = [];
|
|
18
23
|
this.hostRowIndex = [];
|
|
24
|
+
/** Whether slot i's content (bindRow) has been bound since its last position change. */
|
|
25
|
+
this.hostContentBound = [];
|
|
19
26
|
this.hostOffsetY = [];
|
|
27
|
+
/** Scratch flags: whether slot i was claimed by the current window (ring mapping). */
|
|
28
|
+
this.slotActive = [];
|
|
20
29
|
/** Data changed — force-rebind visible nodes on the next frame. */
|
|
21
30
|
this.forceRebind = false;
|
|
22
31
|
this.lastData = null;
|
|
@@ -38,7 +47,7 @@ export class DomPool {
|
|
|
38
47
|
*/
|
|
39
48
|
update(viewport) {
|
|
40
49
|
this.assertActive();
|
|
41
|
-
const { data, rowRange, rowHeight, rowWidth } = viewport;
|
|
50
|
+
const { data, rowRange, rowHeight, rowWidth, skipBind } = viewport;
|
|
42
51
|
if (data !== this.lastData) {
|
|
43
52
|
this.lastData = data;
|
|
44
53
|
this.forceRebind = true;
|
|
@@ -52,16 +61,66 @@ export class DomPool {
|
|
|
52
61
|
const host = this.bindings.createRow();
|
|
53
62
|
this.hosts.push(host);
|
|
54
63
|
this.hostRowIndex.push(null);
|
|
64
|
+
this.hostContentBound.push(false);
|
|
55
65
|
this.hostOffsetY.push(OFFSCREEN_Y);
|
|
56
66
|
}
|
|
57
67
|
const bound = [];
|
|
58
68
|
const positioned = [];
|
|
59
69
|
const recycled = [];
|
|
60
|
-
|
|
70
|
+
// Gradual re-bind: when transitioning from skip-bind mode to normal
|
|
71
|
+
// (content was not bound during fast scroll), spread the binding of
|
|
72
|
+
// stale slots across frames rather than binding all at once — which
|
|
73
|
+
// would cause a frame drop. Each frame binds at most
|
|
74
|
+
// `REBIND_PER_FRAME` stale slots, then resumes normal binding for
|
|
75
|
+
// new rows.
|
|
76
|
+
//
|
|
77
|
+
// With RING mapping the quota rarely engages during slow scroll:
|
|
78
|
+
// scrolling by k rows reassigns only k slots (the ones recycled from
|
|
79
|
+
// rows that left the window), so steady scrolling performs O(k) binds
|
|
80
|
+
// per frame instead of O(windowSize). The quota only matters when
|
|
81
|
+
// recovering from fast scroll (skipBind) or a teleport, where many
|
|
82
|
+
// slots carry stale content at once.
|
|
83
|
+
//
|
|
84
|
+
// When forceRebind is set (from invalidate(), e.g. structural changes),
|
|
85
|
+
// bind everything immediately — set quota to Infinity.
|
|
86
|
+
const REBIND_PER_FRAME = Math.max(1, Math.floor(windowSize / 3));
|
|
87
|
+
const rebindQuota = skipBind ? 0 : this.forceRebind ? Infinity : REBIND_PER_FRAME;
|
|
88
|
+
let quota = rebindQuota;
|
|
89
|
+
// RING MAPPING: slot = rowIndex % poolSize. The slot a row occupies is
|
|
90
|
+
// derived from the row index itself, not from the position inside the
|
|
91
|
+
// window. Consequence: scrolling by k rows touches only the k slots of
|
|
92
|
+
// rows entering/leaving the window; every other node keeps its bound
|
|
93
|
+
// content and only receives a new `transform`. This eliminates the
|
|
94
|
+
// slow-scroll "row jump" produced by the old positional mapping
|
|
95
|
+
// (slot i ↔ range.start + i), where EVERY slot changed its row index
|
|
96
|
+
// on each frame and the rebind quota left the visible rows showing
|
|
97
|
+
// stale content for several frames.
|
|
98
|
+
const poolSize = this.hosts.length;
|
|
99
|
+
for (let slot = 0; slot < poolSize; slot += 1)
|
|
100
|
+
this.slotActive[slot] = false;
|
|
101
|
+
// Iterate the window in ascending row order so the rebind quota, when
|
|
102
|
+
// it engages, always refreshes from the top of the window downward.
|
|
103
|
+
for (let rowIndex = range.start; rowIndex < range.end; rowIndex += 1) {
|
|
104
|
+
const slot = rowIndex % poolSize;
|
|
105
|
+
this.slotActive[slot] = true;
|
|
61
106
|
const host = this.hosts[slot];
|
|
62
|
-
const rowIndex = range.start + slot;
|
|
63
107
|
const offsetY = rowIndex * rowHeight;
|
|
64
|
-
|
|
108
|
+
// Position is always updated — we need the transform to keep rows
|
|
109
|
+
// at the correct offset regardless of whether content is bound.
|
|
110
|
+
if (this.hostOffsetY[slot] !== offsetY) {
|
|
111
|
+
this.hostOffsetY[slot] = offsetY;
|
|
112
|
+
this.bindings.transformRow(host, offsetY);
|
|
113
|
+
positioned.push({ host, offsetY });
|
|
114
|
+
}
|
|
115
|
+
const indexChanged = this.hostRowIndex[slot] !== rowIndex;
|
|
116
|
+
const isNewSlot = this.hostRowIndex[slot] === null;
|
|
117
|
+
const needsBind = indexChanged || this.forceRebind || !this.hostContentBound[slot];
|
|
118
|
+
// New slots (never been bound) must always bind — empty rows at the
|
|
119
|
+
// viewport edge are visible as empty space, worse than a one-frame
|
|
120
|
+
// bind cost. During fast scroll (skipBind), only DEFER rebinding
|
|
121
|
+
// slots that already had content at a different row index.
|
|
122
|
+
const mustBind = isNewSlot || this.forceRebind || (needsBind && !skipBind && quota > 0);
|
|
123
|
+
if (needsBind && mustBind) {
|
|
65
124
|
const dataRow = data[rowIndex];
|
|
66
125
|
const row = {
|
|
67
126
|
index: rowIndex,
|
|
@@ -72,22 +131,33 @@ export class DomPool {
|
|
|
72
131
|
width: rowWidth,
|
|
73
132
|
};
|
|
74
133
|
this.hostRowIndex[slot] = rowIndex;
|
|
134
|
+
this.hostContentBound[slot] = true;
|
|
75
135
|
this.bindings.bindRow(host, row);
|
|
76
136
|
bound.push({ host, row });
|
|
137
|
+
if (!isNewSlot && !this.forceRebind)
|
|
138
|
+
quota -= 1;
|
|
77
139
|
}
|
|
78
|
-
if (this.
|
|
79
|
-
this
|
|
80
|
-
|
|
81
|
-
|
|
140
|
+
else if (indexChanged || this.forceRebind) {
|
|
141
|
+
// Index changed but we can't bind this frame (skipBind or
|
|
142
|
+
// quota exhausted) — update rowIndex for position tracking
|
|
143
|
+
// but defer content binding. The row shows previous content
|
|
144
|
+
// at the correct new position until the next slow frame.
|
|
145
|
+
this.hostRowIndex[slot] = rowIndex;
|
|
146
|
+
this.hostContentBound[slot] = false;
|
|
82
147
|
}
|
|
83
148
|
}
|
|
84
|
-
//
|
|
85
|
-
// and move them off-screen, but keep the nodes for
|
|
86
|
-
|
|
149
|
+
// Slots not claimed by the current window (their row left the window):
|
|
150
|
+
// clear their content and move them off-screen, but keep the nodes for
|
|
151
|
+
// the next frame. With ring mapping these slots are scattered across
|
|
152
|
+
// the pool rather than forming a tail.
|
|
153
|
+
for (let slot = 0; slot < poolSize; slot += 1) {
|
|
154
|
+
if (this.slotActive[slot])
|
|
155
|
+
continue;
|
|
87
156
|
if (this.hostRowIndex[slot] === null)
|
|
88
157
|
continue;
|
|
89
158
|
const host = this.hosts[slot];
|
|
90
159
|
this.hostRowIndex[slot] = null;
|
|
160
|
+
this.hostContentBound[slot] = false;
|
|
91
161
|
this.hostOffsetY[slot] = OFFSCREEN_Y;
|
|
92
162
|
this.bindings.recycleRow(host);
|
|
93
163
|
this.bindings.transformRow(host, OFFSCREEN_Y);
|
|
@@ -124,7 +194,9 @@ export class DomPool {
|
|
|
124
194
|
}
|
|
125
195
|
this.hosts.length = 0;
|
|
126
196
|
this.hostRowIndex.length = 0;
|
|
197
|
+
this.hostContentBound.length = 0;
|
|
127
198
|
this.hostOffsetY.length = 0;
|
|
199
|
+
this.slotActive.length = 0;
|
|
128
200
|
this.lastData = null;
|
|
129
201
|
this.destroyed = true;
|
|
130
202
|
}
|
package/dist/grid.js
CHANGED
|
@@ -135,7 +135,10 @@ export class Grid {
|
|
|
135
135
|
const scrollableWidth = scrollableOffsets.reduce((sum, item) => sum + item.size, 0);
|
|
136
136
|
const totalWidth = pinnedLeftWidth + scrollableWidth + pinnedRightWidth;
|
|
137
137
|
// Virtual range for the scrollable section only.
|
|
138
|
-
|
|
138
|
+
// Pass pre-computed scrollableOffsets to avoid a second (iterative)
|
|
139
|
+
// flex-distribution pass — getColumnRange would otherwise recompute
|
|
140
|
+
// all column widths from scratch via getColumnOffsets.
|
|
141
|
+
const columnRange = scrollable.length ? this.virtualizer.getColumnRange(scrollable, scrollLeft, scrollableViewWidth, scrollableOffsets) : { start: 0, end: 0 };
|
|
139
142
|
const rowRange = this.virtualizer.getRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height);
|
|
140
143
|
// Offset composition:
|
|
141
144
|
// pinned-left: absolute from 0
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export { Grid as GridCore } from "./grid";
|
|
|
8
8
|
export { SlotManager } from "./slots";
|
|
9
9
|
export { Store } from "./store";
|
|
10
10
|
export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
|
|
11
|
-
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
11
|
+
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
12
12
|
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
|
|
13
13
|
export { Virtualizer } from "./virtualizer";
|
package/dist/types.d.ts
CHANGED
|
@@ -249,7 +249,9 @@ export interface GridOptions<T> {
|
|
|
249
249
|
columns: ColumnDef<T>[];
|
|
250
250
|
getRowId?: (row: T, index: number) => RowId;
|
|
251
251
|
rowHeight?: number;
|
|
252
|
+
/** Rows to render beyond the visible viewport (top + bottom buffer). @default 5 */
|
|
252
253
|
rowOverscan?: number;
|
|
254
|
+
/** Columns to render beyond the visible viewport (left + right buffer). @default 2 */
|
|
253
255
|
columnOverscan?: number;
|
|
254
256
|
suppressRowHoverHighlight?: boolean;
|
|
255
257
|
rowStyle?: RowStyle;
|
|
@@ -416,6 +418,30 @@ export interface DomPoolBindings<T> {
|
|
|
416
418
|
transformRow(host: RowHost<T>, offsetY: number): void;
|
|
417
419
|
recycleRow(host: RowHost<T>): void;
|
|
418
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Options passed to `DomPool.update()` to control binding behavior.
|
|
423
|
+
*
|
|
424
|
+
* @api
|
|
425
|
+
*/
|
|
426
|
+
export interface DomPoolUpdateOptions<T> {
|
|
427
|
+
/** Full (post-processing) array of rows. */
|
|
428
|
+
data: T[];
|
|
429
|
+
/** Inclusive start, exclusive end of visible rows (from Virtualizer). */
|
|
430
|
+
rowRange: Range;
|
|
431
|
+
/** Pixel height of each row. */
|
|
432
|
+
rowHeight: number;
|
|
433
|
+
/** Pixel width of each row (sum of all column widths). */
|
|
434
|
+
rowWidth: number;
|
|
435
|
+
/**
|
|
436
|
+
* When `true`, row position (transform) is updated but content binding
|
|
437
|
+
* (`bindRow`) is skipped — the row displays previous content at the
|
|
438
|
+
* correct new position. Used during fast scroll to avoid synchronous
|
|
439
|
+
* React commits that exceed the 16ms frame budget.
|
|
440
|
+
*
|
|
441
|
+
* @default false
|
|
442
|
+
*/
|
|
443
|
+
skipBind?: boolean;
|
|
444
|
+
}
|
|
419
445
|
/** Result of a viewport frame update (informational for tests/debugging). */
|
|
420
446
|
export interface DomPoolUpdate<T> {
|
|
421
447
|
windowStart: number;
|
package/dist/virtualizer.d.ts
CHANGED
|
@@ -15,8 +15,13 @@ export declare class Virtualizer<T> {
|
|
|
15
15
|
/**
|
|
16
16
|
* Column geometry works on the FLAT working set of leaf columns only —
|
|
17
17
|
* groups never reach the Virtualizer (see `Grid.getViewportData()`).
|
|
18
|
+
*
|
|
19
|
+
* Pass pre-computed `offsets` (from a prior `getColumnOffsets` call) to skip
|
|
20
|
+
* the redundant width/offset computation — `getViewportData` already has
|
|
21
|
+
* them in hand.
|
|
18
22
|
*/
|
|
19
|
-
getColumnRange(columns: ColumnLeafDef<T>[], scrollLeft: number, viewportWidth: number): Range;
|
|
23
|
+
getColumnRange(columns: ColumnLeafDef<T>[], scrollLeft: number, viewportWidth: number, offsets?: VirtualItem[]): Range;
|
|
24
|
+
private readonly widthsCache;
|
|
20
25
|
getColumnOffsets(columns: ColumnLeafDef<T>[], viewportWidth?: number): VirtualItem[];
|
|
21
26
|
getTotalHeight(rowCount: number): number;
|
|
22
27
|
getTotalWidth(columns: ColumnLeafDef<T>[], viewportWidth?: number): number;
|
package/dist/virtualizer.js
CHANGED
|
@@ -4,6 +4,7 @@ export class Virtualizer {
|
|
|
4
4
|
this.lastRowRange = null;
|
|
5
5
|
this.lastRowCount = 0;
|
|
6
6
|
this.lastRowViewportHeight = 0;
|
|
7
|
+
this.widthsCache = new WeakMap();
|
|
7
8
|
this.options = options;
|
|
8
9
|
}
|
|
9
10
|
getRowRange(count, scrollTop, viewportHeight) {
|
|
@@ -65,11 +66,15 @@ export class Virtualizer {
|
|
|
65
66
|
/**
|
|
66
67
|
* Column geometry works on the FLAT working set of leaf columns only —
|
|
67
68
|
* groups never reach the Virtualizer (see `Grid.getViewportData()`).
|
|
69
|
+
*
|
|
70
|
+
* Pass pre-computed `offsets` (from a prior `getColumnOffsets` call) to skip
|
|
71
|
+
* the redundant width/offset computation — `getViewportData` already has
|
|
72
|
+
* them in hand.
|
|
68
73
|
*/
|
|
69
|
-
getColumnRange(columns, scrollLeft, viewportWidth) {
|
|
70
|
-
const
|
|
71
|
-
const start = this.findStart(
|
|
72
|
-
const end = this.findEnd(
|
|
74
|
+
getColumnRange(columns, scrollLeft, viewportWidth, offsets) {
|
|
75
|
+
const computed = offsets ?? this.getColumnOffsets(columns, viewportWidth);
|
|
76
|
+
const start = this.findStart(computed, scrollLeft);
|
|
77
|
+
const end = this.findEnd(computed, scrollLeft + viewportWidth);
|
|
73
78
|
return {
|
|
74
79
|
start: Math.max(0, start - this.options.columnOverscan),
|
|
75
80
|
end: Math.min(columns.length, end + 1 + this.options.columnOverscan),
|
|
@@ -102,6 +107,17 @@ export class Virtualizer {
|
|
|
102
107
|
};
|
|
103
108
|
}
|
|
104
109
|
getColumnWidths(columns, viewportWidth) {
|
|
110
|
+
// Cache by first column identity + viewportWidth. Column objects are stable
|
|
111
|
+
// across scroll frames (replaced atomically on setColumns), so this avoids
|
|
112
|
+
// re-running the expensive flex-distribution loop on every scroll frame
|
|
113
|
+
// for the three column partitions (pinnedLeft, scrollable, pinnedRight).
|
|
114
|
+
if (columns.length > 0) {
|
|
115
|
+
const cacheKey = columns[0];
|
|
116
|
+
const cached = this.widthsCache.get(cacheKey);
|
|
117
|
+
if (cached && cached.viewportWidth === viewportWidth && cached.length === columns.length) {
|
|
118
|
+
return cached.widths;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
105
121
|
const widths = columns.map((column) => this.getBaseColumnWidth(column));
|
|
106
122
|
const flexIndexes = columns
|
|
107
123
|
.map((column, index) => (column.flex && column.flex > 0 && column.width === undefined ? index : -1))
|
|
@@ -132,7 +148,11 @@ export class Virtualizer {
|
|
|
132
148
|
break;
|
|
133
149
|
remaining -= distributed;
|
|
134
150
|
}
|
|
135
|
-
|
|
151
|
+
const result = this.quantizeWidths(widths);
|
|
152
|
+
if (columns.length > 0) {
|
|
153
|
+
this.widthsCache.set(columns[0], { viewportWidth, length: columns.length, widths: result });
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
136
156
|
}
|
|
137
157
|
/**
|
|
138
158
|
* Snaps fractional (flex-distributed) widths to whole pixels while keeping
|
|
@@ -186,9 +206,11 @@ export class Virtualizer {
|
|
|
186
206
|
return Math.max(this.getMinColumnWidth(column), column.maxWidth ?? Infinity);
|
|
187
207
|
}
|
|
188
208
|
findStart(items, offset) {
|
|
189
|
-
|
|
209
|
+
const index = items.findIndex((item) => item.offset + item.size > offset);
|
|
210
|
+
return index === -1 ? items.length : index;
|
|
190
211
|
}
|
|
191
212
|
findEnd(items, offset) {
|
|
192
|
-
|
|
213
|
+
const index = items.findIndex((item) => item.offset >= offset);
|
|
214
|
+
return index === -1 ? items.length : index;
|
|
193
215
|
}
|
|
194
216
|
}
|