@omnigrid/core 0.1.19 → 0.1.21

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 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?
@@ -40,3 +40,62 @@ export declare function getColumnGroups<T>(columns: ColumnDef<T>[], isVisible?:
40
40
  * @api
41
41
  */
42
42
  export declare function getCellValue<T>(row: T, column: ColumnLeafDef<T>): unknown;
43
+ /**
44
+ * Builds the `CellSpanningParams` context for a single row.
45
+ *
46
+ * Shared by every span entry point so resolver functions always observe the
47
+ * same row identity (`id` / `index` / `data` shape as `RowNode`).
48
+ *
49
+ * @param data - Raw row data object.
50
+ * @param index - Zero-based index of the row in the processed dataset.
51
+ * @param getRowId - Stable id resolver (defaults to the row index).
52
+ * @param column - Column definition being evaluated.
53
+ * @returns Span context handed to `colSpan` resolver functions.
54
+ * @api
55
+ */
56
+ export declare function getCellSpanningParams<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, column: ColumnLeafDef<T>): CellSpanningParams<T>;
57
+ /**
58
+ * Resolves the normalized horizontal span of one cell.
59
+ *
60
+ * Static numbers are used directly; functions are evaluated with
61
+ * `getCellSpanningParams`. The result is floored to an integer, clamped to
62
+ * `>= 1`, and clipped so the span never runs past `columnCount` leaves.
63
+ * Resolver exceptions fall back to `1` (no merge) so a single bad callback
64
+ * cannot break the viewport.
65
+ *
66
+ * @param data - Raw row data object.
67
+ * @param index - Zero-based row index in the processed dataset.
68
+ * @param getRowId - Stable id resolver.
69
+ * @param column - Column definition being evaluated.
70
+ * @param columnIndex - Position of the column in the visible leaf layout.
71
+ * @param columnCount - Total number of visible leaves in the pin group.
72
+ * @returns Normalized span width in columns (`1` = no merge).
73
+ * @api
74
+ */
75
+ export declare function resolveColSpan<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
76
+ /**
77
+ * Resolves the per-row span layout for a pin group of visible leaves.
78
+ *
79
+ * Walks the leaves left to right: span origins keep their (possibly
80
+ * resolver-computed) width and mark the following `span - 1` leaves as
81
+ * covered; covered leaves contribute zero width so adapters can skip them
82
+ * without overlap. Pixel geometry is aggregated from the pre-computed
83
+ * `offsets` items (`offset`/`size` per leaf), so a span origin's width is
84
+ * the exact sum of its covered columns and its `left` matches the starting
85
+ * column.
86
+ *
87
+ * Static-heavy rows short-circuit: when no visible leaf declares `colSpan`,
88
+ * the layout is the identity mapping (no resolver runs).
89
+ *
90
+ * @param data - Raw row data object.
91
+ * @param index - Zero-based row index in the processed dataset.
92
+ * @param getRowId - Stable id resolver.
93
+ * @param columns - Visible leaves of one pin group (scrollable or pinned).
94
+ * @param offsets - Pre-computed `VirtualItem` geometry for `columns`.
95
+ * @returns Per-row span layout for the group.
96
+ * @api
97
+ */
98
+ export declare function getRowSpans<T>(data: T, index: number, getRowId: (row: T, index: number) => RowId, columns: ColumnLeafDef<T>[], offsets: {
99
+ offset: number;
100
+ size: number;
101
+ }[]): RowSpanLayout;
package/dist/columns.js CHANGED
@@ -90,3 +90,133 @@ export function getCellValue(row, column) {
90
90
  return row[column.field];
91
91
  return undefined;
92
92
  }
93
+ /**
94
+ * Builds the `CellSpanningParams` context for a single row.
95
+ *
96
+ * Shared by every span entry point so resolver functions always observe the
97
+ * same row identity (`id` / `index` / `data` shape as `RowNode`).
98
+ *
99
+ * @param data - Raw row data object.
100
+ * @param index - Zero-based index of the row in the processed dataset.
101
+ * @param getRowId - Stable id resolver (defaults to the row index).
102
+ * @param column - Column definition being evaluated.
103
+ * @returns Span context handed to `colSpan` resolver functions.
104
+ * @api
105
+ */
106
+ export function getCellSpanningParams(data, index, getRowId, column) {
107
+ const node = { id: getRowId(data, index), index, data };
108
+ return { data, node, column };
109
+ }
110
+ /**
111
+ * Resolves the normalized horizontal span of one cell.
112
+ *
113
+ * Static numbers are used directly; functions are evaluated with
114
+ * `getCellSpanningParams`. The result is floored to an integer, clamped to
115
+ * `>= 1`, and clipped so the span never runs past `columnCount` leaves.
116
+ * Resolver exceptions fall back to `1` (no merge) so a single bad callback
117
+ * cannot break the viewport.
118
+ *
119
+ * @param data - Raw row data object.
120
+ * @param index - Zero-based row index in the processed dataset.
121
+ * @param getRowId - Stable id resolver.
122
+ * @param column - Column definition being evaluated.
123
+ * @param columnIndex - Position of the column in the visible leaf layout.
124
+ * @param columnCount - Total number of visible leaves in the pin group.
125
+ * @returns Normalized span width in columns (`1` = no merge).
126
+ * @api
127
+ */
128
+ export function resolveColSpan(data, index, getRowId, column, columnIndex, columnCount) {
129
+ const declared = column.colSpan;
130
+ if (declared === undefined)
131
+ return 1;
132
+ let raw = 1;
133
+ if (typeof declared === "function") {
134
+ try {
135
+ raw = declared(getCellSpanningParams(data, index, getRowId, column));
136
+ }
137
+ catch {
138
+ return 1;
139
+ }
140
+ }
141
+ else {
142
+ raw = declared;
143
+ }
144
+ if (!Number.isFinite(raw))
145
+ return 1;
146
+ const span = Math.floor(raw);
147
+ if (span <= 1)
148
+ return 1;
149
+ const remaining = columnCount - columnIndex;
150
+ if (remaining <= 1)
151
+ return 1;
152
+ return Math.min(span, remaining);
153
+ }
154
+ /**
155
+ * Resolves the per-row span layout for a pin group of visible leaves.
156
+ *
157
+ * Walks the leaves left to right: span origins keep their (possibly
158
+ * resolver-computed) width and mark the following `span - 1` leaves as
159
+ * covered; covered leaves contribute zero width so adapters can skip them
160
+ * without overlap. Pixel geometry is aggregated from the pre-computed
161
+ * `offsets` items (`offset`/`size` per leaf), so a span origin's width is
162
+ * the exact sum of its covered columns and its `left` matches the starting
163
+ * column.
164
+ *
165
+ * Static-heavy rows short-circuit: when no visible leaf declares `colSpan`,
166
+ * the layout is the identity mapping (no resolver runs).
167
+ *
168
+ * @param data - Raw row data object.
169
+ * @param index - Zero-based row index in the processed dataset.
170
+ * @param getRowId - Stable id resolver.
171
+ * @param columns - Visible leaves of one pin group (scrollable or pinned).
172
+ * @param offsets - Pre-computed `VirtualItem` geometry for `columns`.
173
+ * @returns Per-row span layout for the group.
174
+ * @api
175
+ */
176
+ export function getRowSpans(data, index, getRowId, columns, offsets) {
177
+ const count = columns.length;
178
+ const spans = new Array(count);
179
+ const widths = new Array(count);
180
+ const layoutOffsets = new Array(count);
181
+ let hasSpan = false;
182
+ for (let i = 0; i < count; i += 1) {
183
+ if (columns[i].colSpan !== undefined) {
184
+ hasSpan = true;
185
+ break;
186
+ }
187
+ }
188
+ if (!hasSpan) {
189
+ for (let i = 0; i < count; i += 1) {
190
+ spans[i] = { span: 1, covered: false };
191
+ widths[i] = offsets[i]?.size ?? 0;
192
+ layoutOffsets[i] = offsets[i]?.offset ?? 0;
193
+ }
194
+ return { spans, widths, offsets: layoutOffsets };
195
+ }
196
+ let i = 0;
197
+ while (i < count) {
198
+ const span = resolveColSpan(data, index, getRowId, columns[i], i, count);
199
+ if (span <= 1) {
200
+ spans[i] = { span: 1, covered: false };
201
+ widths[i] = offsets[i]?.size ?? 0;
202
+ layoutOffsets[i] = offsets[i]?.offset ?? 0;
203
+ i += 1;
204
+ continue;
205
+ }
206
+ const originOffset = offsets[i]?.offset ?? 0;
207
+ const end = Math.min(count, i + span);
208
+ let total = 0;
209
+ for (let k = i; k < end; k += 1)
210
+ total += offsets[k]?.size ?? 0;
211
+ spans[i] = { span: end - i, covered: false };
212
+ widths[i] = total;
213
+ layoutOffsets[i] = originOffset;
214
+ for (let k = i + 1; k < end; k += 1) {
215
+ spans[k] = { span: 1, covered: true };
216
+ widths[k] = 0;
217
+ layoutOffsets[k] = originOffset;
218
+ }
219
+ i = end;
220
+ }
221
+ return { spans, widths, offsets: layoutOffsets };
222
+ }
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, 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;
@@ -57,6 +57,59 @@ export declare class Grid<T> implements GridApi<T> {
57
57
  */
58
58
  scrollTo(position: Partial<ScrollPosition>): void;
59
59
  getViewportData(): ViewportData<T>;
60
+ /**
61
+ * Expands the shared scrollable column window so `colSpan` origins stay
62
+ * anchored during horizontal scrolling.
63
+ *
64
+ * Left: bounded lookback (`MAX_SPAN_LOOKBACK`) while any visible leaf
65
+ * declares `colSpan` — covers spans that start before the window and
66
+ * bleed into it. Right: extends past the window by the largest declared
67
+ * static span minus one, so a span starting on the last visible leaf is
68
+ * not clipped. Dynamic per-row spans beyond these bounds resolve in the
69
+ * adapter via `getRowSpans` over the full `leafColumns`.
70
+ *
71
+ * @param scrollable - Ordered scrollable leaf columns.
72
+ * @param range - Base virtual window from the virtualizer.
73
+ * @returns Expanded `[start, end)` window, clamped to the group.
74
+ */
75
+ private static expandColumnRangeForSpans;
76
+ /**
77
+ * Resolves the per-row span layout for one pin group of the body.
78
+ *
79
+ * Thin entry point over `getRowSpans` bound to this grid's row identity
80
+ * (`getRowId`): computes merged widths and covered cells for the given
81
+ * row across the FULL leaf group (`ViewportData.leafColumns` /
82
+ * `columnOffsets` for the scrollable section, pinned siblings likewise).
83
+ * Adapters call this per visible row instead of re-implementing span math;
84
+ * results are memoized per row/column-set by the caller for 60 FPS scroll.
85
+ *
86
+ * @param data - Raw row data object.
87
+ * @param index - Zero-based row index in the processed dataset.
88
+ * @param columns - Full ordered leaves of one pin group.
89
+ * @param offsets - Pre-computed absolute geometry for `columns`.
90
+ * @returns Per-row span layout for the group.
91
+ * @api
92
+ */
93
+ getRowSpans(data: T, index: number, columns: ColumnLeafDef<T>[], offsets: {
94
+ offset: number;
95
+ size: number;
96
+ }[]): RowSpanLayout;
97
+ /**
98
+ * Resolves the normalized horizontal span of a single body cell.
99
+ *
100
+ * Entry point over `resolveColSpan` bound to this grid's row identity:
101
+ * clips the declared `colSpan` to the pin group (`columnCount` leaves)
102
+ * and falls back to `1` for invalid declarations or resolver errors.
103
+ *
104
+ * @param data - Raw row data object.
105
+ * @param index - Zero-based row index in the processed dataset.
106
+ * @param column - Column definition being evaluated.
107
+ * @param columnIndex - Position of the column in the visible leaf layout.
108
+ * @param columnCount - Total number of visible leaves in the pin group.
109
+ * @returns Normalized span width in columns (`1` = no merge).
110
+ * @api
111
+ */
112
+ resolveColSpan(data: T, index: number, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
60
113
  getProcessedData(): T[];
61
114
  private getFilteredData;
62
115
  private static cloneFilterModel;
package/dist/grid.js CHANGED
@@ -1,4 +1,4 @@
1
- import { flattenColumns, getColumnGroups } from "./columns";
1
+ import { 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";
@@ -153,10 +153,22 @@ export class Grid {
153
153
  const scrollableWidth = scrollableOffsets.reduce((sum, item) => sum + item.size, 0);
154
154
  const totalWidth = pinnedLeftWidth + scrollableWidth + pinnedRightWidth;
155
155
  // Virtual range for the scrollable section only.
156
+ //
156
157
  // Pass pre-computed scrollableOffsets to avoid a second (iterative)
157
158
  // flex-distribution pass — getColumnRange would otherwise recompute
158
159
  // all column widths from scratch via getColumnOffsets.
159
- const columnRange = scrollable.length ? this.virtualizer.getColumnRange(scrollable, scrollLeft, scrollableViewWidth, scrollableOffsets) : { start: 0, end: 0 };
160
+ //
161
+ // Span-aware expansion: a `colSpan` origin may sit BEFORE the window
162
+ // while covering into it, and a span starting inside may extend PAST
163
+ // the right edge. Expand the shared window left (bounded lookback for
164
+ // origins) and right (max declared static span) so every visible row
165
+ // can anchor its spans without clipping. Per-row dynamic spans that
166
+ // reach further are handled by the adapter via `getRowSpans` over the
167
+ // full `leafColumns` below.
168
+ const baseColumnRange = scrollable.length
169
+ ? this.virtualizer.getColumnRange(scrollable, scrollLeft, scrollableViewWidth, scrollableOffsets)
170
+ : { start: 0, end: 0 };
171
+ const columnRange = Grid.expandColumnRangeForSpans(scrollable, baseColumnRange);
160
172
  const rowRange = this.virtualizer.getRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height);
161
173
  // Offset composition:
162
174
  // pinned-left: absolute from 0
@@ -193,6 +205,12 @@ export class Grid {
193
205
  columns,
194
206
  pinnedLeftColumns,
195
207
  pinnedRightColumns,
208
+ leafColumns: scrollable,
209
+ pinnedLeftLeafColumns: pinnedLeft,
210
+ pinnedRightLeafColumns: pinnedRight,
211
+ columnOffsets: scrollableOffsets,
212
+ pinnedLeftOffsets,
213
+ pinnedRightOffsets,
196
214
  columnGroups,
197
215
  headerRowCount,
198
216
  columnGroupDepth,
@@ -202,6 +220,82 @@ export class Grid {
202
220
  totalHeight: this.virtualizer.getTotalHeight(processedData.length),
203
221
  };
204
222
  }
223
+ /**
224
+ * Expands the shared scrollable column window so `colSpan` origins stay
225
+ * anchored during horizontal scrolling.
226
+ *
227
+ * Left: bounded lookback (`MAX_SPAN_LOOKBACK`) while any visible leaf
228
+ * declares `colSpan` — covers spans that start before the window and
229
+ * bleed into it. Right: extends past the window by the largest declared
230
+ * static span minus one, so a span starting on the last visible leaf is
231
+ * not clipped. Dynamic per-row spans beyond these bounds resolve in the
232
+ * adapter via `getRowSpans` over the full `leafColumns`.
233
+ *
234
+ * @param scrollable - Ordered scrollable leaf columns.
235
+ * @param range - Base virtual window from the virtualizer.
236
+ * @returns Expanded `[start, end)` window, clamped to the group.
237
+ */
238
+ static expandColumnRangeForSpans(scrollable, range) {
239
+ if (scrollable.length === 0)
240
+ return { start: 0, end: 0 };
241
+ let hasSpan = false;
242
+ let maxStaticSpan = 1;
243
+ for (let i = 0; i < scrollable.length; i += 1) {
244
+ const declared = scrollable[i].colSpan;
245
+ if (declared === undefined)
246
+ continue;
247
+ hasSpan = true;
248
+ if (typeof declared === "number" && Number.isFinite(declared)) {
249
+ const span = Math.floor(declared);
250
+ if (span > maxStaticSpan)
251
+ maxStaticSpan = span;
252
+ }
253
+ }
254
+ if (!hasSpan)
255
+ return { start: range.start, end: range.end };
256
+ const lookback = 64;
257
+ const start = Math.max(0, range.start - lookback);
258
+ const end = Math.min(scrollable.length, Math.max(range.end, range.end + maxStaticSpan - 1));
259
+ return { start, end };
260
+ }
261
+ /**
262
+ * Resolves the per-row span layout for one pin group of the body.
263
+ *
264
+ * Thin entry point over `getRowSpans` bound to this grid's row identity
265
+ * (`getRowId`): computes merged widths and covered cells for the given
266
+ * row across the FULL leaf group (`ViewportData.leafColumns` /
267
+ * `columnOffsets` for the scrollable section, pinned siblings likewise).
268
+ * Adapters call this per visible row instead of re-implementing span math;
269
+ * results are memoized per row/column-set by the caller for 60 FPS scroll.
270
+ *
271
+ * @param data - Raw row data object.
272
+ * @param index - Zero-based row index in the processed dataset.
273
+ * @param columns - Full ordered leaves of one pin group.
274
+ * @param offsets - Pre-computed absolute geometry for `columns`.
275
+ * @returns Per-row span layout for the group.
276
+ * @api
277
+ */
278
+ getRowSpans(data, index, columns, offsets) {
279
+ return getRowSpans(data, index, (row, rowIndex) => this.getRowId(row, rowIndex), columns, offsets);
280
+ }
281
+ /**
282
+ * Resolves the normalized horizontal span of a single body cell.
283
+ *
284
+ * Entry point over `resolveColSpan` bound to this grid's row identity:
285
+ * clips the declared `colSpan` to the pin group (`columnCount` leaves)
286
+ * and falls back to `1` for invalid declarations or resolver errors.
287
+ *
288
+ * @param data - Raw row data object.
289
+ * @param index - Zero-based row index in the processed dataset.
290
+ * @param column - Column definition being evaluated.
291
+ * @param columnIndex - Position of the column in the visible leaf layout.
292
+ * @param columnCount - Total number of visible leaves in the pin group.
293
+ * @returns Normalized span width in columns (`1` = no merge).
294
+ * @api
295
+ */
296
+ resolveColSpan(data, index, column, columnIndex, columnCount) {
297
+ return resolveColSpan(data, index, (row, rowIndex) => this.getRowId(row, rowIndex), column, columnIndex, columnCount);
298
+ }
205
299
  getProcessedData() {
206
300
  // Pipeline: raw data -> filter engine -> processors (sort, ...) -> virtualization.
207
301
  // Cache is invalidated by setData / setColumns / filter changes / 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";
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";
15
+ export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
16
16
  export { Virtualizer } 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";
10
+ export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
11
11
  export { Virtualizer } from "./virtualizer";
package/dist/types.d.ts CHANGED
@@ -28,11 +28,94 @@ export type ColumnDataType = "text" | "number" | "date" | "boolean";
28
28
  * @api
29
29
  */
30
30
  export type ColumnFilterType = "text" | "number" | "date" | "boolean" | "set" | "custom";
31
- export interface RowRenderParams<T> {
31
+ /**
32
+ * Row identity and position metadata passed to row-aware callbacks.
33
+ *
34
+ * `RowNode` is a lightweight view over a single processed row: the stable
35
+ * `id` (from `getRowId`), the zero-based `index` in the processed dataset,
36
+ * and the raw `data` object itself.
37
+ *
38
+ * @api
39
+ */
40
+ export interface RowNode<T> {
41
+ /** Stable row identifier (from `getRowId`, defaults to row index). */
32
42
  id: RowId;
43
+ /** Zero-based index of the row in the processed dataset. */
33
44
  index: number;
45
+ /** Raw row data object. */
34
46
  data: T;
35
47
  }
48
+ /**
49
+ * Context passed to the `colSpan` resolver of a column.
50
+ *
51
+ * Mirrors the data-bearing fields of `RowNode` plus the column being
52
+ * evaluated, so span decisions can depend on row values, row position,
53
+ * or column identity.
54
+ *
55
+ * @api
56
+ */
57
+ export interface CellSpanningParams<T> {
58
+ /** Raw row data object. */
59
+ data: T;
60
+ /** Row identity and position metadata. */
61
+ node: RowNode<T>;
62
+ /** Column definition being evaluated for spanning. */
63
+ column: ColumnLeafDef<T>;
64
+ }
65
+ /**
66
+ * Horizontal span declared on a leaf column.
67
+ *
68
+ * A static number merges that many consecutive visible columns starting at
69
+ * the current column; a function computes the span per row from
70
+ * `CellSpanningParams`. Values are normalized to integers `>= 1`
71
+ * (`1` = no spanning, the default).
72
+ *
73
+ * @api
74
+ */
75
+ export type ColSpanDef<T> = number | ((params: CellSpanningParams<T>) => number);
76
+ /**
77
+ * Normalized horizontal span of a single body cell.
78
+ *
79
+ * Produced per visible row by `getRowSpans`: `span` is the merged width in
80
+ * columns (`1` = plain cell), `covered` marks cells hidden underneath a span
81
+ * started at an earlier column.
82
+ *
83
+ * @api
84
+ */
85
+ export interface CellSpan {
86
+ /** Merged width in visible columns (`1` = no spanning). */
87
+ span: number;
88
+ /** Whether this cell is covered by a span that starts to its left. */
89
+ covered: boolean;
90
+ }
91
+ /**
92
+ * Per-row span layout for one pin group of the body.
93
+ *
94
+ * `spans` is indexed by position in the visible leaf group: `spans[i]`
95
+ * describes the cell at that leaf for this row. `widths[i]` / `offsets[i]`
96
+ * are the aggregated pixel geometry — the `left` of a span origin and the
97
+ * summed width of the `span` covered columns.
98
+ *
99
+ * @api
100
+ */
101
+ export interface RowSpanLayout {
102
+ /** Per-leaf span descriptors, indexed by position in the pin group. */
103
+ spans: CellSpan[];
104
+ /** Aggregated pixel width per leaf (span origins carry the summed width). */
105
+ widths: number[];
106
+ /** Pixel `left` per leaf (span origins align with the starting column). */
107
+ offsets: number[];
108
+ }
109
+ /**
110
+ * Context passed to every row-level callback (`getRowStyle`, `getRowClass`,
111
+ * `rowClassRules`, `checkboxDisabled`, ...).
112
+ *
113
+ * Alias of `RowNode`: the stable row id, the zero-based index in the
114
+ * processed dataset, and the raw row data object.
115
+ *
116
+ * @api
117
+ */
118
+ export type RowRenderParams<T> = RowNode<T>;
36
119
  export interface RowStyle {
37
120
  [property: string]: string | number | undefined;
38
121
  }
@@ -228,6 +311,19 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
228
311
  sortIndex?: number;
229
312
  /** Compares values for this column, overriding the sorting plugin default. */
230
313
  comparator?: (left: unknown, right: unknown, column: ColumnLeafDef<T>) => number;
314
+ /**
315
+ * Horizontal cell merging declared on the column.
316
+ *
317
+ * A static number merges that many consecutive visible columns starting
318
+ * at this column; a function computes the span per row from
319
+ * `CellSpanningParams`. Normalized to an integer `>= 1` (`1` = no merge).
320
+ * Spans are clipped to the visible leaf layout (pinned groups never
321
+ * merge) and covered cells are skipped during rendering.
322
+ *
323
+ * @default 1
324
+ * @api
325
+ */
326
+ colSpan?: ColSpanDef<T>;
231
327
  /** Prevents clicks in this column's cells from triggering row-click behavior. */
232
328
  stopRowClick?: boolean;
233
329
  /** Prevents clicks on this column's header from triggering header-click behavior. */
@@ -310,6 +406,7 @@ export interface GridOptions<T> {
310
406
  /** Row data; omitted or null means an initial load is pending. */
311
407
  data?: T[] | null;
312
408
  columns: ColumnDef<T>[];
409
+ /** Returns a stable row ID; defaults to the row's current index. Use a stable ID to preserve row identity when rows are reordered. */
313
410
  getRowId?: (row: T, index: number) => RowId;
314
411
  rowHeight?: number;
315
412
  /** Rows to render beyond the visible viewport (top + bottom buffer). @default 5 */
@@ -416,6 +513,27 @@ export interface ViewportData<T> {
416
513
  offset: number;
417
514
  width: number;
418
515
  }>;
516
+ /**
517
+ * Full ordered leaf columns of each pin group (scrollable or pinned),
518
+ * independent of the current virtual window. Adapters use these together
519
+ * with `getRowSpans` (or `Grid.getRowSpans`) to resolve per-row spanning:
520
+ * the windowed `columns` / `pinned*Columns` above only carry the visible
521
+ * slice, while a span origin may sit before the window and cover into it.
522
+ */
523
+ leafColumns: ColumnLeafDef<T>[];
524
+ /** Full ordered leaf columns of the left-pinned group. See `leafColumns`. */
525
+ pinnedLeftLeafColumns: ColumnLeafDef<T>[];
526
+ /** Full ordered leaf columns of the right-pinned group. See `leafColumns`. */
527
+ pinnedRightLeafColumns: ColumnLeafDef<T>[];
528
+ /**
529
+ * Pre-computed absolute geometry (`offset`/`size`) for every entry of
530
+ * `leafColumns`, aligned by position. Backs span width aggregation.
531
+ */
532
+ columnOffsets: VirtualItem[];
533
+ /** Pre-computed absolute geometry for `pinnedLeftLeafColumns`, aligned by position. */
534
+ pinnedLeftOffsets: VirtualItem[];
535
+ /** Pre-computed absolute geometry for `pinnedRightLeafColumns`, aligned by position. */
536
+ pinnedRightOffsets: VirtualItem[];
419
537
  /**
420
538
  * Column groups (definitions with leaf spans) — the data needed to render
421
539
  * stacked group header rows. Empty when no groups are defined.
@@ -667,6 +785,33 @@ export interface GridApi<T> {
667
785
  getColumnWidth(columnId: string): number | undefined;
668
786
  getProcessedData(): T[];
669
787
  getRowId(row: T, index: number): RowId;
788
+ /**
789
+ * Resolves the normalized horizontal span of a single body cell.
790
+ * Clips the declared `colSpan` to the pin group and falls back to `1`
791
+ * for invalid declarations or resolver errors.
792
+ * @param data - Raw row data object.
793
+ * @param index - Zero-based row index in the processed dataset.
794
+ * @param column - Column definition being evaluated.
795
+ * @param columnIndex - Position of the column in the visible leaf layout.
796
+ * @param columnCount - Total number of visible leaves in the pin group.
797
+ * @returns Normalized span width in columns (`1` = no merge).
798
+ * @api
799
+ */
800
+ resolveColSpan(data: T, index: number, column: ColumnLeafDef<T>, columnIndex: number, columnCount: number): number;
801
+ /**
802
+ * Resolves the per-row span layout for one pin group of the body.
803
+ * Computes merged widths and covered cells across the FULL leaf group.
804
+ * @param data - Raw row data object.
805
+ * @param index - Zero-based row index in the processed dataset.
806
+ * @param columns - Full ordered leaves of one pin group.
807
+ * @param offsets - Pre-computed absolute geometry for `columns`.
808
+ * @returns Per-row span layout for the group.
809
+ * @api
810
+ */
811
+ getRowSpans(data: T, index: number, columns: ColumnLeafDef<T>[], offsets: {
812
+ offset: number;
813
+ size: number;
814
+ }[]): RowSpanLayout;
670
815
  setData(data: T[] | null | undefined): void;
671
816
  /**
672
817
  * Chunk-append API for incremental data loading (infinite scroll, live
@@ -107,14 +107,14 @@ export class Virtualizer {
107
107
  };
108
108
  }
109
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).
110
+ // Column objects are stable across scroll frames, so validate each
111
+ // identity before reusing cached widths. Checking only the first column
112
+ // misses updates to other columns when setColumns replaces them.
114
113
  if (columns.length > 0) {
115
114
  const cacheKey = columns[0];
116
115
  const cached = this.widthsCache.get(cacheKey);
117
- if (cached && cached.viewportWidth === viewportWidth && cached.length === columns.length) {
116
+ const columnsUnchanged = cached?.columns.length === columns.length && cached.columns.every((column, index) => column === columns[index]);
117
+ if (cached && cached.viewportWidth === viewportWidth && columnsUnchanged) {
118
118
  return cached.widths;
119
119
  }
120
120
  }
@@ -150,7 +150,7 @@ export class Virtualizer {
150
150
  }
151
151
  const result = this.quantizeWidths(widths);
152
152
  if (columns.length > 0) {
153
- this.widthsCache.set(columns[0], { viewportWidth, length: columns.length, widths: result });
153
+ this.widthsCache.set(columns[0], { viewportWidth, columns: [...columns], widths: result });
154
154
  }
155
155
  return result;
156
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",