@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/README.md
CHANGED
|
@@ -236,9 +236,32 @@ See [@omnigrid/react](../../adapters/react/README.md).
|
|
|
236
236
|
## Exported helpers
|
|
237
237
|
|
|
238
238
|
- `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
|
|
239
|
+
- `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
|
|
240
|
+
(`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
|
|
239
241
|
- `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
|
|
240
242
|
(mostly used internally; public for advanced integrations/tests).
|
|
241
243
|
|
|
244
|
+
### Column spanning (`colSpan`)
|
|
245
|
+
|
|
246
|
+
A leaf column may merge horizontally across consecutive visible columns:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
const columns: ColumnDef<Row>[] = [
|
|
250
|
+
{ id: "title", width: 200, colSpan: 2 }, // static: always 2
|
|
251
|
+
{ id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
|
|
252
|
+
];
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
`resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
|
|
256
|
+
pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
|
|
257
|
+
aggregates a whole row — the origin carries the summed pixel width aligned to
|
|
258
|
+
the starting column, covered cells are skipped. `Grid.getViewportData`
|
|
259
|
+
additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
|
|
260
|
+
pinned siblings likewise) and expands the shared column window so spans
|
|
261
|
+
crossing the viewport boundary are never clipped. The React adapter resolves
|
|
262
|
+
per-row layouts (memoized per viewport commit) and paints merged widths via
|
|
263
|
+
`translateX` without breaking node recycling.
|
|
264
|
+
|
|
242
265
|
## Links
|
|
243
266
|
|
|
244
267
|
- **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
|
package/dist/columns.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef } from "./types";
|
|
1
|
+
import type { CellSpanningParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, RowId, RowSpanLayout } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Runtime narrowing: does the column definition describe a GROUP
|
|
4
4
|
* (it carries `children`) rather than a leaf column?
|
|
@@ -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
|
*
|
|
@@ -40,3 +47,62 @@ export declare function getColumnGroups<T>(columns: ColumnDef<T>[], isVisible?:
|
|
|
40
47
|
* @api
|
|
41
48
|
*/
|
|
42
49
|
export declare function getCellValue<T>(row: T, column: ColumnLeafDef<T>): unknown;
|
|
50
|
+
/**
|
|
51
|
+
* Builds the `CellSpanningParams` context for a single row.
|
|
52
|
+
*
|
|
53
|
+
* Shared by every span entry point so resolver functions always observe the
|
|
54
|
+
* same row identity (`id` / `index` / `data` shape as `RowNode`).
|
|
55
|
+
*
|
|
56
|
+
* @param data - Raw row data object.
|
|
57
|
+
* @param index - Zero-based index of the row in the processed dataset.
|
|
58
|
+
* @param getRowId - Stable id resolver (defaults to the row index).
|
|
59
|
+
* @param column - Column definition being evaluated.
|
|
60
|
+
* @returns Span context handed to `colSpan` resolver functions.
|
|
61
|
+
* @api
|
|
62
|
+
*/
|
|
63
|
+
export declare function getCellSpanningParams<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, column: ColumnLeafDef<T>): CellSpanningParams<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the normalized horizontal span of one cell.
|
|
66
|
+
*
|
|
67
|
+
* Static numbers are used directly; functions are evaluated with
|
|
68
|
+
* `getCellSpanningParams`. The result is floored to an integer, clamped to
|
|
69
|
+
* `>= 1`, and clipped so the span never runs past `columnCount` leaves.
|
|
70
|
+
* Resolver exceptions fall back to `1` (no merge) so a single bad callback
|
|
71
|
+
* cannot break the viewport.
|
|
72
|
+
*
|
|
73
|
+
* @param data - Raw row data object.
|
|
74
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
75
|
+
* @param getRowId - Stable id resolver.
|
|
76
|
+
* @param column - Column definition being evaluated.
|
|
77
|
+
* @param columnIndex - Position of the column in the visible leaf layout.
|
|
78
|
+
* @param columnCount - Total number of visible leaves in the pin group.
|
|
79
|
+
* @returns Normalized span width in columns (`1` = no merge).
|
|
80
|
+
* @api
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveColSpan<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves the per-row span layout for a pin group of visible leaves.
|
|
85
|
+
*
|
|
86
|
+
* Walks the leaves left to right: span origins keep their (possibly
|
|
87
|
+
* resolver-computed) width and mark the following `span - 1` leaves as
|
|
88
|
+
* covered; covered leaves contribute zero width so adapters can skip them
|
|
89
|
+
* without overlap. Pixel geometry is aggregated from the pre-computed
|
|
90
|
+
* `offsets` items (`offset`/`size` per leaf), so a span origin's width is
|
|
91
|
+
* the exact sum of its covered columns and its `left` matches the starting
|
|
92
|
+
* column.
|
|
93
|
+
*
|
|
94
|
+
* Static-heavy rows short-circuit: when no visible leaf declares `colSpan`,
|
|
95
|
+
* the layout is the identity mapping (no resolver runs).
|
|
96
|
+
*
|
|
97
|
+
* @param data - Raw row data object.
|
|
98
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
99
|
+
* @param getRowId - Stable id resolver.
|
|
100
|
+
* @param columns - Visible leaves of one pin group (scrollable or pinned).
|
|
101
|
+
* @param offsets - Pre-computed `VirtualItem` geometry for `columns`.
|
|
102
|
+
* @returns Per-row span layout for the group.
|
|
103
|
+
* @api
|
|
104
|
+
*/
|
|
105
|
+
export declare function getRowSpans<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, columns: ColumnLeafDef<T>[], offsets: {
|
|
106
|
+
offset: number;
|
|
107
|
+
size: number;
|
|
108
|
+
}[]): RowSpanLayout;
|
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
|
*
|
|
@@ -90,3 +107,133 @@ export function getCellValue(row, column) {
|
|
|
90
107
|
return row[column.field];
|
|
91
108
|
return undefined;
|
|
92
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Builds the `CellSpanningParams` context for a single row.
|
|
112
|
+
*
|
|
113
|
+
* Shared by every span entry point so resolver functions always observe the
|
|
114
|
+
* same row identity (`id` / `index` / `data` shape as `RowNode`).
|
|
115
|
+
*
|
|
116
|
+
* @param data - Raw row data object.
|
|
117
|
+
* @param index - Zero-based index of the row in the processed dataset.
|
|
118
|
+
* @param getRowId - Stable id resolver (defaults to the row index).
|
|
119
|
+
* @param column - Column definition being evaluated.
|
|
120
|
+
* @returns Span context handed to `colSpan` resolver functions.
|
|
121
|
+
* @api
|
|
122
|
+
*/
|
|
123
|
+
export function getCellSpanningParams(data, index, getRowId, column) {
|
|
124
|
+
const node = { id: getRowId(data, index), index, data };
|
|
125
|
+
return { data, node, column };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolves the normalized horizontal span of one cell.
|
|
129
|
+
*
|
|
130
|
+
* Static numbers are used directly; functions are evaluated with
|
|
131
|
+
* `getCellSpanningParams`. The result is floored to an integer, clamped to
|
|
132
|
+
* `>= 1`, and clipped so the span never runs past `columnCount` leaves.
|
|
133
|
+
* Resolver exceptions fall back to `1` (no merge) so a single bad callback
|
|
134
|
+
* cannot break the viewport.
|
|
135
|
+
*
|
|
136
|
+
* @param data - Raw row data object.
|
|
137
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
138
|
+
* @param getRowId - Stable id resolver.
|
|
139
|
+
* @param column - Column definition being evaluated.
|
|
140
|
+
* @param columnIndex - Position of the column in the visible leaf layout.
|
|
141
|
+
* @param columnCount - Total number of visible leaves in the pin group.
|
|
142
|
+
* @returns Normalized span width in columns (`1` = no merge).
|
|
143
|
+
* @api
|
|
144
|
+
*/
|
|
145
|
+
export function resolveColSpan(data, index, getRowId, column, columnIndex, columnCount) {
|
|
146
|
+
const declared = column.colSpan;
|
|
147
|
+
if (declared === undefined)
|
|
148
|
+
return 1;
|
|
149
|
+
let raw = 1;
|
|
150
|
+
if (typeof declared === "function") {
|
|
151
|
+
try {
|
|
152
|
+
raw = declared(getCellSpanningParams(data, index, getRowId, column));
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
raw = declared;
|
|
160
|
+
}
|
|
161
|
+
if (!Number.isFinite(raw))
|
|
162
|
+
return 1;
|
|
163
|
+
const span = Math.floor(raw);
|
|
164
|
+
if (span <= 1)
|
|
165
|
+
return 1;
|
|
166
|
+
const remaining = columnCount - columnIndex;
|
|
167
|
+
if (remaining <= 1)
|
|
168
|
+
return 1;
|
|
169
|
+
return Math.min(span, remaining);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Resolves the per-row span layout for a pin group of visible leaves.
|
|
173
|
+
*
|
|
174
|
+
* Walks the leaves left to right: span origins keep their (possibly
|
|
175
|
+
* resolver-computed) width and mark the following `span - 1` leaves as
|
|
176
|
+
* covered; covered leaves contribute zero width so adapters can skip them
|
|
177
|
+
* without overlap. Pixel geometry is aggregated from the pre-computed
|
|
178
|
+
* `offsets` items (`offset`/`size` per leaf), so a span origin's width is
|
|
179
|
+
* the exact sum of its covered columns and its `left` matches the starting
|
|
180
|
+
* column.
|
|
181
|
+
*
|
|
182
|
+
* Static-heavy rows short-circuit: when no visible leaf declares `colSpan`,
|
|
183
|
+
* the layout is the identity mapping (no resolver runs).
|
|
184
|
+
*
|
|
185
|
+
* @param data - Raw row data object.
|
|
186
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
187
|
+
* @param getRowId - Stable id resolver.
|
|
188
|
+
* @param columns - Visible leaves of one pin group (scrollable or pinned).
|
|
189
|
+
* @param offsets - Pre-computed `VirtualItem` geometry for `columns`.
|
|
190
|
+
* @returns Per-row span layout for the group.
|
|
191
|
+
* @api
|
|
192
|
+
*/
|
|
193
|
+
export function getRowSpans(data, index, getRowId, columns, offsets) {
|
|
194
|
+
const count = columns.length;
|
|
195
|
+
const spans = new Array(count);
|
|
196
|
+
const widths = new Array(count);
|
|
197
|
+
const layoutOffsets = new Array(count);
|
|
198
|
+
let hasSpan = false;
|
|
199
|
+
for (let i = 0; i < count; i += 1) {
|
|
200
|
+
if (columns[i].colSpan !== undefined) {
|
|
201
|
+
hasSpan = true;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!hasSpan) {
|
|
206
|
+
for (let i = 0; i < count; i += 1) {
|
|
207
|
+
spans[i] = { span: 1, covered: false };
|
|
208
|
+
widths[i] = offsets[i]?.size ?? 0;
|
|
209
|
+
layoutOffsets[i] = offsets[i]?.offset ?? 0;
|
|
210
|
+
}
|
|
211
|
+
return { spans, widths, offsets: layoutOffsets };
|
|
212
|
+
}
|
|
213
|
+
let i = 0;
|
|
214
|
+
while (i < count) {
|
|
215
|
+
const span = resolveColSpan(data, index, getRowId, columns[i], i, count);
|
|
216
|
+
if (span <= 1) {
|
|
217
|
+
spans[i] = { span: 1, covered: false };
|
|
218
|
+
widths[i] = offsets[i]?.size ?? 0;
|
|
219
|
+
layoutOffsets[i] = offsets[i]?.offset ?? 0;
|
|
220
|
+
i += 1;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const originOffset = offsets[i]?.offset ?? 0;
|
|
224
|
+
const end = Math.min(count, i + span);
|
|
225
|
+
let total = 0;
|
|
226
|
+
for (let k = i; k < end; k += 1)
|
|
227
|
+
total += offsets[k]?.size ?? 0;
|
|
228
|
+
spans[i] = { span: end - i, covered: false };
|
|
229
|
+
widths[i] = total;
|
|
230
|
+
layoutOffsets[i] = originOffset;
|
|
231
|
+
for (let k = i + 1; k < end; k += 1) {
|
|
232
|
+
spans[k] = { span: 1, covered: true };
|
|
233
|
+
widths[k] = 0;
|
|
234
|
+
layoutOffsets[k] = originOffset;
|
|
235
|
+
}
|
|
236
|
+
i = end;
|
|
237
|
+
}
|
|
238
|
+
return { spans, widths, offsets: layoutOffsets };
|
|
239
|
+
}
|
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 { DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHoverEvent, RowId, 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, 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
|
*
|
|
@@ -57,6 +59,59 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
57
59
|
*/
|
|
58
60
|
scrollTo(position: Partial<ScrollPosition>): void;
|
|
59
61
|
getViewportData(): ViewportData<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Expands the shared scrollable column window so `colSpan` origins stay
|
|
64
|
+
* anchored during horizontal scrolling.
|
|
65
|
+
*
|
|
66
|
+
* Left: bounded lookback (`MAX_SPAN_LOOKBACK`) while any visible leaf
|
|
67
|
+
* declares `colSpan` — covers spans that start before the window and
|
|
68
|
+
* bleed into it. Right: extends past the window by the largest declared
|
|
69
|
+
* static span minus one, so a span starting on the last visible leaf is
|
|
70
|
+
* not clipped. Dynamic per-row spans beyond these bounds resolve in the
|
|
71
|
+
* adapter via `getRowSpans` over the full `leafColumns`.
|
|
72
|
+
*
|
|
73
|
+
* @param scrollable - Ordered scrollable leaf columns.
|
|
74
|
+
* @param range - Base virtual window from the virtualizer.
|
|
75
|
+
* @returns Expanded `[start, end)` window, clamped to the group.
|
|
76
|
+
*/
|
|
77
|
+
private static expandColumnRangeForSpans;
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the per-row span layout for one pin group of the body.
|
|
80
|
+
*
|
|
81
|
+
* Thin entry point over `getRowSpans` bound to this grid's row identity
|
|
82
|
+
* (`getRowId`): computes merged widths and covered cells for the given
|
|
83
|
+
* row across the FULL leaf group (`ViewportData.leafColumns` /
|
|
84
|
+
* `columnOffsets` for the scrollable section, pinned siblings likewise).
|
|
85
|
+
* Adapters call this per visible row instead of re-implementing span math;
|
|
86
|
+
* results are memoized per row/column-set by the caller for 60 FPS scroll.
|
|
87
|
+
*
|
|
88
|
+
* @param data - Raw row data object.
|
|
89
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
90
|
+
* @param columns - Full ordered leaves of one pin group.
|
|
91
|
+
* @param offsets - Pre-computed absolute geometry for `columns`.
|
|
92
|
+
* @returns Per-row span layout for the group.
|
|
93
|
+
* @api
|
|
94
|
+
*/
|
|
95
|
+
getRowSpans(data: T, index: number, columns: ColumnLeafDef<T>[], offsets: {
|
|
96
|
+
offset: number;
|
|
97
|
+
size: number;
|
|
98
|
+
}[]): RowSpanLayout;
|
|
99
|
+
/**
|
|
100
|
+
* Resolves the normalized horizontal span of a single body cell.
|
|
101
|
+
*
|
|
102
|
+
* Entry point over `resolveColSpan` bound to this grid's row identity:
|
|
103
|
+
* clips the declared `colSpan` to the pin group (`columnCount` leaves)
|
|
104
|
+
* and falls back to `1` for invalid declarations or resolver errors.
|
|
105
|
+
*
|
|
106
|
+
* @param data - Raw row data object.
|
|
107
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
108
|
+
* @param column - Column definition being evaluated.
|
|
109
|
+
* @param columnIndex - Position of the column in the visible leaf layout.
|
|
110
|
+
* @param columnCount - Total number of visible leaves in the pin group.
|
|
111
|
+
* @returns Normalized span width in columns (`1` = no merge).
|
|
112
|
+
* @api
|
|
113
|
+
*/
|
|
114
|
+
resolveColSpan(data: T, index: number, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
|
|
60
115
|
getProcessedData(): T[];
|
|
61
116
|
private getFilteredData;
|
|
62
117
|
private static cloneFilterModel;
|
|
@@ -86,6 +141,46 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
86
141
|
closePopup(): void;
|
|
87
142
|
getPopup(): UIPopupDescriptor | null;
|
|
88
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;
|
|
89
184
|
setData(data: T[] | null | undefined): void;
|
|
90
185
|
/**
|
|
91
186
|
* Chunk-append API for incremental data loading (infinite scroll, live
|