@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/grid.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flattenColumns, getColumnGroups } 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
|
});
|
|
@@ -153,11 +162,34 @@ export class Grid {
|
|
|
153
162
|
const scrollableWidth = scrollableOffsets.reduce((sum, item) => sum + item.size, 0);
|
|
154
163
|
const totalWidth = pinnedLeftWidth + scrollableWidth + pinnedRightWidth;
|
|
155
164
|
// Virtual range for the scrollable section only.
|
|
165
|
+
//
|
|
156
166
|
// Pass pre-computed scrollableOffsets to avoid a second (iterative)
|
|
157
167
|
// flex-distribution pass — getColumnRange would otherwise recompute
|
|
158
168
|
// all column widths from scratch via getColumnOffsets.
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
//
|
|
170
|
+
// Span-aware expansion: a `colSpan` origin may sit BEFORE the window
|
|
171
|
+
// while covering into it, and a span starting inside may extend PAST
|
|
172
|
+
// the right edge. Expand the shared window left (bounded lookback for
|
|
173
|
+
// origins) and right (max declared static span) so every visible row
|
|
174
|
+
// can anchor its spans without clipping. Per-row dynamic spans that
|
|
175
|
+
// reach further are handled by the adapter via `getRowSpans` over the
|
|
176
|
+
// full `leafColumns` below.
|
|
177
|
+
const baseColumnRange = scrollable.length
|
|
178
|
+
? this.virtualizer.getColumnRange(scrollable, scrollLeft, scrollableViewWidth, scrollableOffsets)
|
|
179
|
+
: { start: 0, end: 0 };
|
|
180
|
+
const columnRange = Grid.expandColumnRangeForSpans(scrollable, baseColumnRange);
|
|
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;
|
|
161
193
|
// Offset composition:
|
|
162
194
|
// pinned-left: absolute from 0
|
|
163
195
|
// scrollable: shifted by pinnedLeftWidth
|
|
@@ -188,20 +220,111 @@ export class Grid {
|
|
|
188
220
|
return {
|
|
189
221
|
rows: processedData.slice(rowRange.start, rowRange.end).map((data, index) => {
|
|
190
222
|
const rowIndex = rowRange.start + index;
|
|
191
|
-
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
|
+
};
|
|
192
230
|
}),
|
|
193
231
|
columns,
|
|
194
232
|
pinnedLeftColumns,
|
|
195
233
|
pinnedRightColumns,
|
|
234
|
+
leafColumns: scrollable,
|
|
235
|
+
pinnedLeftLeafColumns: pinnedLeft,
|
|
236
|
+
pinnedRightLeafColumns: pinnedRight,
|
|
237
|
+
columnOffsets: scrollableOffsets,
|
|
238
|
+
pinnedLeftOffsets,
|
|
239
|
+
pinnedRightOffsets,
|
|
196
240
|
columnGroups,
|
|
197
241
|
headerRowCount,
|
|
198
242
|
columnGroupDepth,
|
|
199
243
|
rowRange,
|
|
244
|
+
visibleRowRange,
|
|
200
245
|
columnRange,
|
|
246
|
+
rowOffsets,
|
|
247
|
+
rowHeights,
|
|
201
248
|
totalWidth,
|
|
202
249
|
totalHeight: this.virtualizer.getTotalHeight(processedData.length),
|
|
203
250
|
};
|
|
204
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Expands the shared scrollable column window so `colSpan` origins stay
|
|
254
|
+
* anchored during horizontal scrolling.
|
|
255
|
+
*
|
|
256
|
+
* Left: bounded lookback (`MAX_SPAN_LOOKBACK`) while any visible leaf
|
|
257
|
+
* declares `colSpan` — covers spans that start before the window and
|
|
258
|
+
* bleed into it. Right: extends past the window by the largest declared
|
|
259
|
+
* static span minus one, so a span starting on the last visible leaf is
|
|
260
|
+
* not clipped. Dynamic per-row spans beyond these bounds resolve in the
|
|
261
|
+
* adapter via `getRowSpans` over the full `leafColumns`.
|
|
262
|
+
*
|
|
263
|
+
* @param scrollable - Ordered scrollable leaf columns.
|
|
264
|
+
* @param range - Base virtual window from the virtualizer.
|
|
265
|
+
* @returns Expanded `[start, end)` window, clamped to the group.
|
|
266
|
+
*/
|
|
267
|
+
static expandColumnRangeForSpans(scrollable, range) {
|
|
268
|
+
if (scrollable.length === 0)
|
|
269
|
+
return { start: 0, end: 0 };
|
|
270
|
+
let hasSpan = false;
|
|
271
|
+
let maxStaticSpan = 1;
|
|
272
|
+
for (let i = 0; i < scrollable.length; i += 1) {
|
|
273
|
+
const declared = scrollable[i].colSpan;
|
|
274
|
+
if (declared === undefined)
|
|
275
|
+
continue;
|
|
276
|
+
hasSpan = true;
|
|
277
|
+
if (typeof declared === "number" && Number.isFinite(declared)) {
|
|
278
|
+
const span = Math.floor(declared);
|
|
279
|
+
if (span > maxStaticSpan)
|
|
280
|
+
maxStaticSpan = span;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!hasSpan)
|
|
284
|
+
return { start: range.start, end: range.end };
|
|
285
|
+
const lookback = 64;
|
|
286
|
+
const start = Math.max(0, range.start - lookback);
|
|
287
|
+
const end = Math.min(scrollable.length, Math.max(range.end, range.end + maxStaticSpan - 1));
|
|
288
|
+
return { start, end };
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Resolves the per-row span layout for one pin group of the body.
|
|
292
|
+
*
|
|
293
|
+
* Thin entry point over `getRowSpans` bound to this grid's row identity
|
|
294
|
+
* (`getRowId`): computes merged widths and covered cells for the given
|
|
295
|
+
* row across the FULL leaf group (`ViewportData.leafColumns` /
|
|
296
|
+
* `columnOffsets` for the scrollable section, pinned siblings likewise).
|
|
297
|
+
* Adapters call this per visible row instead of re-implementing span math;
|
|
298
|
+
* results are memoized per row/column-set by the caller for 60 FPS scroll.
|
|
299
|
+
*
|
|
300
|
+
* @param data - Raw row data object.
|
|
301
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
302
|
+
* @param columns - Full ordered leaves of one pin group.
|
|
303
|
+
* @param offsets - Pre-computed absolute geometry for `columns`.
|
|
304
|
+
* @returns Per-row span layout for the group.
|
|
305
|
+
* @api
|
|
306
|
+
*/
|
|
307
|
+
getRowSpans(data, index, columns, offsets) {
|
|
308
|
+
return getRowSpans(data, index, (row, rowIndex) => this.getRowId(row, rowIndex), columns, offsets);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Resolves the normalized horizontal span of a single body cell.
|
|
312
|
+
*
|
|
313
|
+
* Entry point over `resolveColSpan` bound to this grid's row identity:
|
|
314
|
+
* clips the declared `colSpan` to the pin group (`columnCount` leaves)
|
|
315
|
+
* and falls back to `1` for invalid declarations or resolver errors.
|
|
316
|
+
*
|
|
317
|
+
* @param data - Raw row data object.
|
|
318
|
+
* @param index - Zero-based row index in the processed dataset.
|
|
319
|
+
* @param column - Column definition being evaluated.
|
|
320
|
+
* @param columnIndex - Position of the column in the visible leaf layout.
|
|
321
|
+
* @param columnCount - Total number of visible leaves in the pin group.
|
|
322
|
+
* @returns Normalized span width in columns (`1` = no merge).
|
|
323
|
+
* @api
|
|
324
|
+
*/
|
|
325
|
+
resolveColSpan(data, index, column, columnIndex, columnCount) {
|
|
326
|
+
return resolveColSpan(data, index, (row, rowIndex) => this.getRowId(row, rowIndex), column, columnIndex, columnCount);
|
|
327
|
+
}
|
|
205
328
|
getProcessedData() {
|
|
206
329
|
// Pipeline: raw data -> filter engine -> processors (sort, ...) -> virtualization.
|
|
207
330
|
// Cache is invalidated by setData / setColumns / filter changes / processor
|
|
@@ -335,6 +458,81 @@ export class Grid {
|
|
|
335
458
|
getRowId(row, index) {
|
|
336
459
|
return this.resolveRowId(row, index);
|
|
337
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
|
+
}
|
|
338
536
|
setData(data) {
|
|
339
537
|
this.assertActive();
|
|
340
538
|
this.loadError = undefined;
|
|
@@ -342,6 +540,7 @@ export class Grid {
|
|
|
342
540
|
const nextData = data ?? [];
|
|
343
541
|
this.filteredDataCache = null;
|
|
344
542
|
this.processedDataCache = null;
|
|
543
|
+
this.virtualizer.resetAllRowHeights();
|
|
345
544
|
this.revision += 1;
|
|
346
545
|
this.store.setState({ data: nextData });
|
|
347
546
|
this.events.emit("dataChange", nextData);
|
|
@@ -428,7 +627,7 @@ export class Grid {
|
|
|
428
627
|
this.filteredDataCache = null;
|
|
429
628
|
this.processedDataCache = null;
|
|
430
629
|
this.revision += 1;
|
|
431
|
-
this.store.setState({ columns });
|
|
630
|
+
this.store.setState({ columns: applyWrapText(columns, this.wrapTextAll) });
|
|
432
631
|
this.recomputeOverlay();
|
|
433
632
|
}
|
|
434
633
|
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, CheckboxControl, CheckboxRenderParams, 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, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
15
|
-
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
|
|
16
|
-
export { Virtualizer } from "./virtualizer";
|
|
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, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
15
|
+
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
|
|
16
|
+
export { Virtualizer, RowHeightRegistry } from "./virtualizer";
|
package/dist/index.js
CHANGED
|
@@ -7,5 +7,5 @@ export { Grid as GridCore } from "./grid";
|
|
|
7
7
|
export { SlotManager } from "./slots";
|
|
8
8
|
export { Store } from "./store";
|
|
9
9
|
export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
|
|
10
|
-
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
|
|
11
|
-
export { Virtualizer } from "./virtualizer";
|
|
10
|
+
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
|
|
11
|
+
export { Virtualizer, RowHeightRegistry } from "./virtualizer";
|