@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/columns.d.ts +7 -0
- package/dist/columns.js +17 -0
- package/dist/dom-pool.d.ts +1 -0
- package/dist/dom-pool.js +51 -8
- package/dist/grid.d.ts +59 -1
- package/dist/grid.js +211 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/types.d.ts +223 -0
- package/dist/virtualizer.d.ts +138 -2
- package/dist/virtualizer.js +390 -4
- package/package.json +1 -1
package/dist/columns.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare function isColumnLeaf<T>(column: ColumnDef<T>): column is ColumnL
|
|
|
17
17
|
* the caller's concern.
|
|
18
18
|
*/
|
|
19
19
|
export declare function flattenColumns<T>(columns: ColumnDef<T>[]): ColumnLeafDef<T>[];
|
|
20
|
+
/**
|
|
21
|
+
* Applies the grid-level `wrapText` flag to every leaf column that does not
|
|
22
|
+
* define it explicitly — a column-level `wrapText` always wins.
|
|
23
|
+
*
|
|
24
|
+
* Returns the input untouched when the grid-level flag is not set.
|
|
25
|
+
*/
|
|
26
|
+
export declare function applyWrapText<T>(columns: ColumnDef<T>[], wrapText: boolean | undefined): ColumnDef<T>[];
|
|
20
27
|
/**
|
|
21
28
|
* Projects every group onto the flat VISIBLE leaf layout.
|
|
22
29
|
*
|
package/dist/columns.js
CHANGED
|
@@ -32,6 +32,23 @@ export function flattenColumns(columns) {
|
|
|
32
32
|
}
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Applies the grid-level `wrapText` flag to every leaf column that does not
|
|
37
|
+
* define it explicitly — a column-level `wrapText` always wins.
|
|
38
|
+
*
|
|
39
|
+
* Returns the input untouched when the grid-level flag is not set.
|
|
40
|
+
*/
|
|
41
|
+
export function applyWrapText(columns, wrapText) {
|
|
42
|
+
if (wrapText === undefined)
|
|
43
|
+
return columns;
|
|
44
|
+
const walk = (nodes) => nodes.map((node) => {
|
|
45
|
+
if (isColumnGroup(node)) {
|
|
46
|
+
return { ...node, children: walk(node.children) };
|
|
47
|
+
}
|
|
48
|
+
return node.wrapText === undefined ? { ...node, wrapText } : node;
|
|
49
|
+
});
|
|
50
|
+
return walk(columns);
|
|
51
|
+
}
|
|
35
52
|
/**
|
|
36
53
|
* Projects every group onto the flat VISIBLE leaf layout.
|
|
37
54
|
*
|
package/dist/dom-pool.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare class DomPool<T> {
|
|
|
33
33
|
/** Whether slot i's content (bindRow) has been bound since its last position change. */
|
|
34
34
|
private readonly hostContentBound;
|
|
35
35
|
private readonly hostOffsetY;
|
|
36
|
+
private readonly hostHeight;
|
|
36
37
|
/** Scratch flags: whether slot i was claimed by the current window (ring mapping). */
|
|
37
38
|
private readonly slotActive;
|
|
38
39
|
/** Data changed — force-rebind visible nodes on the next frame. */
|
package/dist/dom-pool.js
CHANGED
|
@@ -24,6 +24,7 @@ export class DomPool {
|
|
|
24
24
|
/** Whether slot i's content (bindRow) has been bound since its last position change. */
|
|
25
25
|
this.hostContentBound = [];
|
|
26
26
|
this.hostOffsetY = [];
|
|
27
|
+
this.hostHeight = [];
|
|
27
28
|
/** Scratch flags: whether slot i was claimed by the current window (ring mapping). */
|
|
28
29
|
this.slotActive = [];
|
|
29
30
|
/** Data changed — force-rebind visible nodes on the next frame. */
|
|
@@ -47,7 +48,7 @@ export class DomPool {
|
|
|
47
48
|
*/
|
|
48
49
|
update(viewport) {
|
|
49
50
|
this.assertActive();
|
|
50
|
-
const { data, rowRange, rowHeight, rowWidth, skipBind } = viewport;
|
|
51
|
+
const { data, rowRange, rowHeight, rowOffsets, rowHeights, visibleRowRange, rowWidth, skipBind } = viewport;
|
|
51
52
|
if (data !== this.lastData) {
|
|
52
53
|
this.lastData = data;
|
|
53
54
|
this.forceRebind = true;
|
|
@@ -63,6 +64,7 @@ export class DomPool {
|
|
|
63
64
|
this.hostRowIndex.push(null);
|
|
64
65
|
this.hostContentBound.push(false);
|
|
65
66
|
this.hostOffsetY.push(OFFSCREEN_Y);
|
|
67
|
+
this.hostHeight.push(-1);
|
|
66
68
|
}
|
|
67
69
|
const bound = [];
|
|
68
70
|
const positioned = [];
|
|
@@ -74,6 +76,10 @@ export class DomPool {
|
|
|
74
76
|
// `REBIND_PER_FRAME` stale slots, then resumes normal binding for
|
|
75
77
|
// new rows.
|
|
76
78
|
//
|
|
79
|
+
// The quota covers the OFF-SCREEN rows only: the rows that intersect
|
|
80
|
+
// the viewport are always bound (see below) — they carry the data the
|
|
81
|
+
// user actually reads.
|
|
82
|
+
//
|
|
77
83
|
// With RING mapping the quota rarely engages during slow scroll:
|
|
78
84
|
// scrolling by k rows reassigns only k slots (the ones recycled from
|
|
79
85
|
// rows that left the window), so steady scrolling performs O(k) binds
|
|
@@ -104,7 +110,9 @@ export class DomPool {
|
|
|
104
110
|
const slot = rowIndex % poolSize;
|
|
105
111
|
this.slotActive[slot] = true;
|
|
106
112
|
const host = this.hosts[slot];
|
|
107
|
-
const
|
|
113
|
+
const rangeIndex = rowIndex - range.start;
|
|
114
|
+
const offsetY = rowOffsets ? (rowOffsets[rangeIndex] ?? rowIndex * rowHeight) : rowIndex * rowHeight;
|
|
115
|
+
const currentHeight = rowHeights ? (rowHeights[rangeIndex] ?? rowHeight) : rowHeight;
|
|
108
116
|
// Position is always updated — we need the transform to keep rows
|
|
109
117
|
// at the correct offset regardless of whether content is bound.
|
|
110
118
|
if (this.hostOffsetY[slot] !== offsetY) {
|
|
@@ -113,13 +121,41 @@ export class DomPool {
|
|
|
113
121
|
positioned.push({ host, offsetY });
|
|
114
122
|
}
|
|
115
123
|
const indexChanged = this.hostRowIndex[slot] !== rowIndex;
|
|
124
|
+
const heightChanged = this.hostHeight[slot] !== currentHeight;
|
|
116
125
|
const isNewSlot = this.hostRowIndex[slot] === null;
|
|
117
|
-
const
|
|
126
|
+
const contentBound = this.hostContentBound[slot];
|
|
127
|
+
// The row BOX follows the virtualizer unconditionally: position AND
|
|
128
|
+
// height are geometry, not content. During a fast scroll the
|
|
129
|
+
// content of a recycled node is stale (it still belongs to the
|
|
130
|
+
// previous row), but the node must get the size of the row it
|
|
131
|
+
// stands for NOW — otherwise a 60px node occupies a 32px slot and
|
|
132
|
+
// the rows overlap (or leave gaps when the height shrinks).
|
|
133
|
+
// `resizeRow` only touches the box, never the content.
|
|
134
|
+
const resizeRow = this.bindings.resizeRow;
|
|
135
|
+
const canResize = resizeRow !== undefined && !this.forceRebind;
|
|
136
|
+
if (heightChanged && canResize && !isNewSlot) {
|
|
137
|
+
this.hostHeight[slot] = currentHeight;
|
|
138
|
+
resizeRow?.(host, currentHeight);
|
|
139
|
+
}
|
|
140
|
+
// A content re-bind is needed when the node shows a different row,
|
|
141
|
+
// when it has no content at all, or on a forced re-bind. A height
|
|
142
|
+
// change alone never invalidates the content — unless the adapter
|
|
143
|
+
// cannot resize a node, in which case the row has to be re-bound
|
|
144
|
+
// to pick up the new height.
|
|
145
|
+
const needsBind = indexChanged || this.forceRebind || !contentBound || (heightChanged && !canResize);
|
|
118
146
|
// New slots (never been bound) must always bind — empty rows at the
|
|
119
147
|
// viewport edge are visible as empty space, worse than a one-frame
|
|
120
|
-
// bind cost.
|
|
121
|
-
//
|
|
122
|
-
|
|
148
|
+
// bind cost.
|
|
149
|
+
//
|
|
150
|
+
// The rows that intersect the viewport must bind as well, even
|
|
151
|
+
// during a fast scroll: the pool recycles its nodes in a ring, so
|
|
152
|
+
// a node that is not re-bound keeps the content of a completely
|
|
153
|
+
// unrelated row — the user would read another row's data (e.g. the
|
|
154
|
+
// wrong ID) in the visible area. Only the off-screen rows (the
|
|
155
|
+
// overscan corridor) follow the rebind quota.
|
|
156
|
+
const inViewport = visibleRowRange !== undefined && rowIndex >= visibleRowRange.start && rowIndex < visibleRowRange.end;
|
|
157
|
+
const quotaBind = needsBind && !skipBind && quota > 0;
|
|
158
|
+
const mustBind = isNewSlot || this.forceRebind || (needsBind && (inViewport || quotaBind));
|
|
123
159
|
if (needsBind && mustBind) {
|
|
124
160
|
const dataRow = data[rowIndex];
|
|
125
161
|
const row = {
|
|
@@ -127,14 +163,15 @@ export class DomPool {
|
|
|
127
163
|
rowId: this.getRowId(dataRow, rowIndex),
|
|
128
164
|
data: dataRow,
|
|
129
165
|
offsetY,
|
|
130
|
-
height:
|
|
166
|
+
height: currentHeight,
|
|
131
167
|
width: rowWidth,
|
|
132
168
|
};
|
|
133
169
|
this.hostRowIndex[slot] = rowIndex;
|
|
170
|
+
this.hostHeight[slot] = currentHeight;
|
|
134
171
|
this.hostContentBound[slot] = true;
|
|
135
172
|
this.bindings.bindRow(host, row);
|
|
136
173
|
bound.push({ host, row });
|
|
137
|
-
if (!isNewSlot && !this.forceRebind)
|
|
174
|
+
if (!isNewSlot && !this.forceRebind && quotaBind)
|
|
138
175
|
quota -= 1;
|
|
139
176
|
}
|
|
140
177
|
else if (indexChanged || this.forceRebind) {
|
|
@@ -144,6 +181,10 @@ export class DomPool {
|
|
|
144
181
|
// at the correct new position until the next slow frame.
|
|
145
182
|
this.hostRowIndex[slot] = rowIndex;
|
|
146
183
|
this.hostContentBound[slot] = false;
|
|
184
|
+
// The node stands for the new row from now on: the adapters
|
|
185
|
+
// look rows up by index (hover highlight), so the index has to
|
|
186
|
+
// follow the position even while the content is still stale.
|
|
187
|
+
this.bindings.updateRowIndex?.(host, rowIndex);
|
|
147
188
|
}
|
|
148
189
|
}
|
|
149
190
|
// Slots not claimed by the current window (their row left the window):
|
|
@@ -157,6 +198,7 @@ export class DomPool {
|
|
|
157
198
|
continue;
|
|
158
199
|
const host = this.hosts[slot];
|
|
159
200
|
this.hostRowIndex[slot] = null;
|
|
201
|
+
this.hostHeight[slot] = -1;
|
|
160
202
|
this.hostContentBound[slot] = false;
|
|
161
203
|
this.hostOffsetY[slot] = OFFSCREEN_Y;
|
|
162
204
|
this.bindings.recycleRow(host);
|
|
@@ -196,6 +238,7 @@ export class DomPool {
|
|
|
196
238
|
this.hostRowIndex.length = 0;
|
|
197
239
|
this.hostContentBound.length = 0;
|
|
198
240
|
this.hostOffsetY.length = 0;
|
|
241
|
+
this.hostHeight.length = 0;
|
|
199
242
|
this.slotActive.length = 0;
|
|
200
243
|
this.lastData = null;
|
|
201
244
|
this.destroyed = true;
|
package/dist/grid.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { FilterCondition, FilterModel } from "./filtering";
|
|
|
2
2
|
import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
|
|
3
3
|
import { IconRegistry } from "./icons";
|
|
4
4
|
import { SlotManager } from "./slots";
|
|
5
|
-
import type { ColumnLeafDef, DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHoverEvent, RowId, RowSpanLayout, ScrollPosition, SlotMount, SlotName, ViewportData, ViewportState } from "./types";
|
|
5
|
+
import type { ColumnLeafDef, DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHoverEvent, RowId, RowSpanLayout, ScrollPosition, SlotMount, SlotName, TransactionResult, RowTransaction, ViewportData, ViewportState } from "./types";
|
|
6
6
|
import type { OverlayOptions, OverlayState } from "./overlays";
|
|
7
7
|
export declare class Grid<T> implements GridApi<T> {
|
|
8
8
|
private readonly store;
|
|
@@ -35,6 +35,8 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
35
35
|
private loadError;
|
|
36
36
|
private overlayState;
|
|
37
37
|
private overlayManual;
|
|
38
|
+
/** Grid-level `wrapText` flag — applied to every column without an explicit one. */
|
|
39
|
+
private wrapTextAll;
|
|
38
40
|
/**
|
|
39
41
|
* Separate ephemeral scroll position that is NOT stored in the Store.
|
|
40
42
|
*
|
|
@@ -139,6 +141,46 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
139
141
|
closePopup(): void;
|
|
140
142
|
getPopup(): UIPopupDescriptor | null;
|
|
141
143
|
getRowId(row: T, index: number): RowId;
|
|
144
|
+
/**
|
|
145
|
+
* Records the measured DOM height of a row (variable-height mode).
|
|
146
|
+
* Returns the scrollTop correction (px) the adapter must apply to keep
|
|
147
|
+
* the anchored row visually stable when rows above the viewport change.
|
|
148
|
+
*
|
|
149
|
+
* A height change is a GEOMETRY change, not a structural one: the row
|
|
150
|
+
* content stays valid, so the grid does not bump its structural revision
|
|
151
|
+
* (which would force the DOM pool to re-bind every visible row).
|
|
152
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
153
|
+
* @param height - Measured row height in pixels (must be finite and > 0).
|
|
154
|
+
* @param options - Set `anchor: false` to suppress the built-in scroll
|
|
155
|
+
* anchoring correction (the caller applies it later).
|
|
156
|
+
* @api
|
|
157
|
+
*/
|
|
158
|
+
setRowHeight(rowIndex: number, height: number, options?: RowHeightUpdateOptions): number;
|
|
159
|
+
/**
|
|
160
|
+
* Removes a measured row height (falls back to the estimate).
|
|
161
|
+
* Returns the scrollTop correction like `setRowHeight`.
|
|
162
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
163
|
+
* @param options - Set `anchor: false` to suppress the built-in scroll
|
|
164
|
+
* anchoring correction (the caller applies it later).
|
|
165
|
+
* @api
|
|
166
|
+
*/
|
|
167
|
+
resetRowHeight(rowIndex: number, options?: RowHeightUpdateOptions): number;
|
|
168
|
+
/** Removes all measured row heights (e.g. after `setColumns`). @api */
|
|
169
|
+
resetAllRowHeights(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Returns the absolute vertical offset (px) of the top of a row,
|
|
172
|
+
* accounting for variable heights. Falls back to `index * rowHeight`
|
|
173
|
+
* when no measurements exist.
|
|
174
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
175
|
+
* @api
|
|
176
|
+
*/
|
|
177
|
+
getRowTop(rowIndex: number): number;
|
|
178
|
+
/**
|
|
179
|
+
* Returns the current (measured, resolved, or estimated) height of a row.
|
|
180
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
181
|
+
* @api
|
|
182
|
+
*/
|
|
183
|
+
getRowHeight(rowIndex: number): number;
|
|
142
184
|
setData(data: T[] | null | undefined): void;
|
|
143
185
|
/**
|
|
144
186
|
* Chunk-append API for incremental data loading (infinite scroll, live
|
|
@@ -148,6 +190,22 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
148
190
|
* missing `rows`.
|
|
149
191
|
*/
|
|
150
192
|
appendData(rows: T[] | null | undefined): void;
|
|
193
|
+
/**
|
|
194
|
+
* Applies a targeted row transaction (add / update / remove) to the State
|
|
195
|
+
* Store without recreating the whole data array.
|
|
196
|
+
*
|
|
197
|
+
* Rows are matched by their stable id (`getRowId`). The pipeline caches
|
|
198
|
+
* (filtered / processed data) are invalidated and the virtualizer's
|
|
199
|
+
* row-height cache is reset only for the affected rows (or fully when the
|
|
200
|
+
* dataset size changes), avoiding heavy recomputation.
|
|
201
|
+
*
|
|
202
|
+
* Emits a single `dataChange` with the resulting dataset and bumps the
|
|
203
|
+
* grid revision.
|
|
204
|
+
* @param transaction - The rows to add, update and/or remove.
|
|
205
|
+
* @returns The added, updated and removed rows with resolved ids/indexes.
|
|
206
|
+
* @api
|
|
207
|
+
*/
|
|
208
|
+
applyTransaction(transaction: RowTransaction<T>): TransactionResult<T>;
|
|
151
209
|
setViewport(viewport: Partial<ViewportState>): void;
|
|
152
210
|
/**
|
|
153
211
|
* Repaints the current viewport: notifies Store subscribers that
|
package/dist/grid.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flattenColumns, getColumnGroups, getRowSpans, resolveColSpan } from "./columns";
|
|
1
|
+
import { applyWrapText, flattenColumns, getColumnGroups, getRowSpans, resolveColSpan } from "./columns";
|
|
2
2
|
import { EventBus } from "./events";
|
|
3
3
|
import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering";
|
|
4
4
|
import { PopupManager } from "./ui";
|
|
@@ -37,7 +37,7 @@ export class Grid {
|
|
|
37
37
|
this.scrollPosition = { scrollTop: 0, scrollLeft: 0 };
|
|
38
38
|
const state = {
|
|
39
39
|
data: options.data ?? [],
|
|
40
|
-
columns: options.columns,
|
|
40
|
+
columns: applyWrapText(options.columns, options.wrapText),
|
|
41
41
|
viewport: { width: 0, height: 0, scrollTop: 0, scrollLeft: 0 },
|
|
42
42
|
rowHeight: options.rowHeight ?? 32,
|
|
43
43
|
rowOverscan: options.rowOverscan ?? 5,
|
|
@@ -50,10 +50,19 @@ export class Grid {
|
|
|
50
50
|
this.resolveRowId = options.getRowId ?? ((_row, index) => index);
|
|
51
51
|
this.loading = options.loading ?? false;
|
|
52
52
|
this.hasData = options.data !== undefined && options.data !== null;
|
|
53
|
+
this.wrapTextAll = options.wrapText;
|
|
53
54
|
if (options.filterModel)
|
|
54
55
|
this.filterModel = Grid.cloneFilterModel(options.filterModel);
|
|
55
56
|
this.virtualizer = new Virtualizer({
|
|
56
57
|
rowHeight: state.rowHeight,
|
|
58
|
+
estimatedRowHeight: options.estimatedRowHeight ?? options.rowHeight,
|
|
59
|
+
getRowHeight: options.getRowHeight
|
|
60
|
+
? (rowIndex) => {
|
|
61
|
+
const data = this.getProcessedData();
|
|
62
|
+
const row = data[rowIndex];
|
|
63
|
+
return row !== undefined ? options.getRowHeight(rowIndex, row) : undefined;
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
57
66
|
rowOverscan: state.rowOverscan,
|
|
58
67
|
columnOverscan: state.columnOverscan,
|
|
59
68
|
});
|
|
@@ -169,7 +178,18 @@ export class Grid {
|
|
|
169
178
|
? this.virtualizer.getColumnRange(scrollable, scrollLeft, scrollableViewWidth, scrollableOffsets)
|
|
170
179
|
: { start: 0, end: 0 };
|
|
171
180
|
const columnRange = Grid.expandColumnRangeForSpans(scrollable, baseColumnRange);
|
|
172
|
-
const
|
|
181
|
+
const hasVariable = this.virtualizer.hasVariableHeights;
|
|
182
|
+
const rowRange = this.virtualizer.getRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height, hasVariable);
|
|
183
|
+
// The rows that actually intersect the viewport (no overscan): the
|
|
184
|
+
// adapter binds them eagerly so a recycled node never shows the data
|
|
185
|
+
// of a different row.
|
|
186
|
+
const visibleRowRange = this.virtualizer.getVisibleRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height);
|
|
187
|
+
const rowOffsets = hasVariable
|
|
188
|
+
? Array.from({ length: rowRange.end - rowRange.start }, (_, i) => this.virtualizer.getRowTop(rowRange.start + i, processedData.length))
|
|
189
|
+
: undefined;
|
|
190
|
+
const rowHeights = hasVariable
|
|
191
|
+
? Array.from({ length: rowRange.end - rowRange.start }, (_, i) => this.virtualizer.getRowHeight(rowRange.start + i))
|
|
192
|
+
: undefined;
|
|
173
193
|
// Offset composition:
|
|
174
194
|
// pinned-left: absolute from 0
|
|
175
195
|
// scrollable: shifted by pinnedLeftWidth
|
|
@@ -200,7 +220,13 @@ export class Grid {
|
|
|
200
220
|
return {
|
|
201
221
|
rows: processedData.slice(rowRange.start, rowRange.end).map((data, index) => {
|
|
202
222
|
const rowIndex = rowRange.start + index;
|
|
203
|
-
return {
|
|
223
|
+
return {
|
|
224
|
+
id: this.getRowId(data, rowIndex),
|
|
225
|
+
data,
|
|
226
|
+
index: rowIndex,
|
|
227
|
+
offset: rowOffsets ? rowOffsets[index] : rowIndex * state.rowHeight,
|
|
228
|
+
height: rowHeights ? rowHeights[index] : state.rowHeight,
|
|
229
|
+
};
|
|
204
230
|
}),
|
|
205
231
|
columns,
|
|
206
232
|
pinnedLeftColumns,
|
|
@@ -215,7 +241,10 @@ export class Grid {
|
|
|
215
241
|
headerRowCount,
|
|
216
242
|
columnGroupDepth,
|
|
217
243
|
rowRange,
|
|
244
|
+
visibleRowRange,
|
|
218
245
|
columnRange,
|
|
246
|
+
rowOffsets,
|
|
247
|
+
rowHeights,
|
|
219
248
|
totalWidth,
|
|
220
249
|
totalHeight: this.virtualizer.getTotalHeight(processedData.length),
|
|
221
250
|
};
|
|
@@ -429,6 +458,81 @@ export class Grid {
|
|
|
429
458
|
getRowId(row, index) {
|
|
430
459
|
return this.resolveRowId(row, index);
|
|
431
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Records the measured DOM height of a row (variable-height mode).
|
|
463
|
+
* Returns the scrollTop correction (px) the adapter must apply to keep
|
|
464
|
+
* the anchored row visually stable when rows above the viewport change.
|
|
465
|
+
*
|
|
466
|
+
* A height change is a GEOMETRY change, not a structural one: the row
|
|
467
|
+
* content stays valid, so the grid does not bump its structural revision
|
|
468
|
+
* (which would force the DOM pool to re-bind every visible row).
|
|
469
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
470
|
+
* @param height - Measured row height in pixels (must be finite and > 0).
|
|
471
|
+
* @param options - Set `anchor: false` to suppress the built-in scroll
|
|
472
|
+
* anchoring correction (the caller applies it later).
|
|
473
|
+
* @api
|
|
474
|
+
*/
|
|
475
|
+
setRowHeight(rowIndex, height, options) {
|
|
476
|
+
this.assertActive();
|
|
477
|
+
const count = this.getProcessedData().length;
|
|
478
|
+
const scrollTop = this.scrollPosition.scrollTop;
|
|
479
|
+
const previousHeight = this.virtualizer.getRowHeight(rowIndex);
|
|
480
|
+
const correction = this.virtualizer.setRowHeight(rowIndex, height, scrollTop, count);
|
|
481
|
+
if (this.virtualizer.getRowHeight(rowIndex) === previousHeight)
|
|
482
|
+
return 0;
|
|
483
|
+
if (options?.notify !== false)
|
|
484
|
+
this.store.setState({});
|
|
485
|
+
if (correction !== 0 && options?.anchor !== false) {
|
|
486
|
+
this.scrollTo({ scrollTop: scrollTop + correction });
|
|
487
|
+
}
|
|
488
|
+
return correction;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Removes a measured row height (falls back to the estimate).
|
|
492
|
+
* Returns the scrollTop correction like `setRowHeight`.
|
|
493
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
494
|
+
* @param options - Set `anchor: false` to suppress the built-in scroll
|
|
495
|
+
* anchoring correction (the caller applies it later).
|
|
496
|
+
* @api
|
|
497
|
+
*/
|
|
498
|
+
resetRowHeight(rowIndex, options) {
|
|
499
|
+
this.assertActive();
|
|
500
|
+
const count = this.getProcessedData().length;
|
|
501
|
+
const scrollTop = this.scrollPosition.scrollTop;
|
|
502
|
+
const correction = this.virtualizer.resetRowHeight(rowIndex, scrollTop, count);
|
|
503
|
+
if (options?.notify !== false)
|
|
504
|
+
this.store.setState({});
|
|
505
|
+
if (correction !== 0 && options?.anchor !== false) {
|
|
506
|
+
this.scrollTo({ scrollTop: scrollTop + correction });
|
|
507
|
+
}
|
|
508
|
+
return correction;
|
|
509
|
+
}
|
|
510
|
+
/** Removes all measured row heights (e.g. after `setColumns`). @api */
|
|
511
|
+
resetAllRowHeights() {
|
|
512
|
+
this.assertActive();
|
|
513
|
+
this.virtualizer.resetAllRowHeights();
|
|
514
|
+
this.revision += 1;
|
|
515
|
+
this.store.setState({});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Returns the absolute vertical offset (px) of the top of a row,
|
|
519
|
+
* accounting for variable heights. Falls back to `index * rowHeight`
|
|
520
|
+
* when no measurements exist.
|
|
521
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
522
|
+
* @api
|
|
523
|
+
*/
|
|
524
|
+
getRowTop(rowIndex) {
|
|
525
|
+
const count = this.getProcessedData().length;
|
|
526
|
+
return this.virtualizer.getRowTop(rowIndex, count);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Returns the current (measured, resolved, or estimated) height of a row.
|
|
530
|
+
* @param rowIndex - Zero-based index in the processed dataset.
|
|
531
|
+
* @api
|
|
532
|
+
*/
|
|
533
|
+
getRowHeight(rowIndex) {
|
|
534
|
+
return this.virtualizer.getRowHeight(rowIndex);
|
|
535
|
+
}
|
|
432
536
|
setData(data) {
|
|
433
537
|
this.assertActive();
|
|
434
538
|
this.loadError = undefined;
|
|
@@ -436,6 +540,7 @@ export class Grid {
|
|
|
436
540
|
const nextData = data ?? [];
|
|
437
541
|
this.filteredDataCache = null;
|
|
438
542
|
this.processedDataCache = null;
|
|
543
|
+
this.virtualizer.resetAllRowHeights();
|
|
439
544
|
this.revision += 1;
|
|
440
545
|
this.store.setState({ data: nextData });
|
|
441
546
|
this.events.emit("dataChange", nextData);
|
|
@@ -462,6 +567,107 @@ export class Grid {
|
|
|
462
567
|
this.events.emit("dataChange", nextData);
|
|
463
568
|
this.recomputeOverlay();
|
|
464
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Applies a targeted row transaction (add / update / remove) to the State
|
|
572
|
+
* Store without recreating the whole data array.
|
|
573
|
+
*
|
|
574
|
+
* Rows are matched by their stable id (`getRowId`). The pipeline caches
|
|
575
|
+
* (filtered / processed data) are invalidated and the virtualizer's
|
|
576
|
+
* row-height cache is reset only for the affected rows (or fully when the
|
|
577
|
+
* dataset size changes), avoiding heavy recomputation.
|
|
578
|
+
*
|
|
579
|
+
* Emits a single `dataChange` with the resulting dataset and bumps the
|
|
580
|
+
* grid revision.
|
|
581
|
+
* @param transaction - The rows to add, update and/or remove.
|
|
582
|
+
* @returns The added, updated and removed rows with resolved ids/indexes.
|
|
583
|
+
* @api
|
|
584
|
+
*/
|
|
585
|
+
applyTransaction(transaction) {
|
|
586
|
+
this.assertActive();
|
|
587
|
+
const currentData = this.store.getState().data;
|
|
588
|
+
const added = [];
|
|
589
|
+
const updated = [];
|
|
590
|
+
const removed = [];
|
|
591
|
+
// Row indexes whose measured height must be discarded because the row
|
|
592
|
+
// content changed (update) or the dataset size changed (add / remove).
|
|
593
|
+
const affectedIndexes = new Set();
|
|
594
|
+
let structuralChange = false;
|
|
595
|
+
// Resolves the id of a row object, preferring its current position so
|
|
596
|
+
// index-based `getRowId` implementations keep matching existing rows.
|
|
597
|
+
const resolveIdOf = (row) => {
|
|
598
|
+
const index = currentData.indexOf(row);
|
|
599
|
+
return this.resolveRowId(row, index >= 0 ? index : -1);
|
|
600
|
+
};
|
|
601
|
+
// ---------- removals ----------
|
|
602
|
+
const removeIds = new Set();
|
|
603
|
+
if (transaction.remove) {
|
|
604
|
+
for (const item of transaction.remove) {
|
|
605
|
+
removeIds.add(typeof item === "object" && item !== null ? resolveIdOf(item) : item);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const afterRemove = [];
|
|
609
|
+
currentData.forEach((row, index) => {
|
|
610
|
+
const id = this.resolveRowId(row, index);
|
|
611
|
+
if (removeIds.has(id)) {
|
|
612
|
+
removed.push({ id, index, data: row });
|
|
613
|
+
affectedIndexes.add(index);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
afterRemove.push(row);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
// ---------- updates ----------
|
|
620
|
+
let nextData = afterRemove;
|
|
621
|
+
if (transaction.update) {
|
|
622
|
+
const updateIdToIndex = new Map();
|
|
623
|
+
afterRemove.forEach((row, index) => updateIdToIndex.set(this.resolveRowId(row, index), index));
|
|
624
|
+
nextData = [...afterRemove];
|
|
625
|
+
for (const row of transaction.update) {
|
|
626
|
+
const id = resolveIdOf(row);
|
|
627
|
+
const index = updateIdToIndex.get(id);
|
|
628
|
+
if (index === undefined)
|
|
629
|
+
continue;
|
|
630
|
+
nextData[index] = row;
|
|
631
|
+
updated.push({ id, index, data: row });
|
|
632
|
+
affectedIndexes.add(index);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
// ---------- adds ----------
|
|
636
|
+
const insertAt = Math.min(Math.max(transaction.addIndex ?? nextData.length, 0), nextData.length);
|
|
637
|
+
if (transaction.add) {
|
|
638
|
+
transaction.add.forEach((row, position) => {
|
|
639
|
+
const index = insertAt + position;
|
|
640
|
+
const id = this.resolveRowId(row, index);
|
|
641
|
+
nextData.splice(index, 0, row);
|
|
642
|
+
added.push({ id, index, data: row });
|
|
643
|
+
affectedIndexes.add(index);
|
|
644
|
+
});
|
|
645
|
+
structuralChange = true;
|
|
646
|
+
}
|
|
647
|
+
if (removed.length > 0)
|
|
648
|
+
structuralChange = true;
|
|
649
|
+
const changed = added.length > 0 || updated.length > 0 || removed.length > 0;
|
|
650
|
+
if (!changed) {
|
|
651
|
+
return { added, updated, removed };
|
|
652
|
+
}
|
|
653
|
+
// ---------- invalidate caches & patch the store ----------
|
|
654
|
+
if (structuralChange) {
|
|
655
|
+
// Adding or removing rows shifts every subsequent index, so the
|
|
656
|
+
// index-based row-height registry can no longer be trusted row by row.
|
|
657
|
+
this.virtualizer.resetAllRowHeights();
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
// Pure update: only the affected rows may have changed height.
|
|
661
|
+
affectedIndexes.forEach((index) => this.virtualizer.rowHeights.reset(index));
|
|
662
|
+
}
|
|
663
|
+
this.filteredDataCache = null;
|
|
664
|
+
this.processedDataCache = null;
|
|
665
|
+
this.revision += 1;
|
|
666
|
+
this.store.setState({ data: nextData });
|
|
667
|
+
this.events.emit("dataChange", nextData);
|
|
668
|
+
this.recomputeOverlay();
|
|
669
|
+
return { added, updated, removed };
|
|
670
|
+
}
|
|
465
671
|
setViewport(viewport) {
|
|
466
672
|
this.assertActive();
|
|
467
673
|
const state = this.store.getState();
|
|
@@ -522,7 +728,7 @@ export class Grid {
|
|
|
522
728
|
this.filteredDataCache = null;
|
|
523
729
|
this.processedDataCache = null;
|
|
524
730
|
this.revision += 1;
|
|
525
|
-
this.store.setState({ columns });
|
|
731
|
+
this.store.setState({ columns: applyWrapText(columns, this.wrapTextAll) });
|
|
526
732
|
this.recomputeOverlay();
|
|
527
733
|
}
|
|
528
734
|
registerDataProcessor(processor) {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelAct
|
|
|
11
11
|
export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering";
|
|
12
12
|
export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui";
|
|
13
13
|
export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
|
|
14
|
-
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnFilterType, 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, RowNode, RowRenderParams, RowSpanLayout, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
14
|
+
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnFilterType, 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, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
15
15
|
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
|
|
16
|
-
export { Virtualizer } from "./virtualizer";
|
|
16
|
+
export { Virtualizer, RowHeightRegistry } from "./virtualizer";
|
package/dist/index.js
CHANGED
|
@@ -8,4 +8,4 @@ export { SlotManager } from "./slots";
|
|
|
8
8
|
export { Store } from "./store";
|
|
9
9
|
export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
|
|
10
10
|
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
|
|
11
|
-
export { Virtualizer } from "./virtualizer";
|
|
11
|
+
export { Virtualizer, RowHeightRegistry } from "./virtualizer";
|