@omnigrid/react 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/dist/OmniGrid.js +173 -4
- package/dist/controls.js +8 -0
- package/dist/pooledRow.d.ts +10 -3
- package/dist/pooledRow.js +32 -7
- package/package.json +2 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -154,6 +154,151 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
const columnPresentationCacheRef = useRef(new Map());
|
|
157
|
+
/**
|
|
158
|
+
* Memoized per-row span layouts, keyed by row index within one viewport
|
|
159
|
+
* commit. `getRowSpans` walks the full leaf group per visible row; the
|
|
160
|
+
* cache keeps horizontal scroll at 60 FPS by reusing the layout while the
|
|
161
|
+
* column set, offsets, and revision are unchanged. Cleared whenever the
|
|
162
|
+
* column window or structural revision changes (see `syncPool`).
|
|
163
|
+
*/
|
|
164
|
+
const spanCacheRef = useRef({
|
|
165
|
+
revision: -1,
|
|
166
|
+
columns: null,
|
|
167
|
+
offsets: null,
|
|
168
|
+
pinnedLeftColumns: null,
|
|
169
|
+
pinnedLeftOffsets: null,
|
|
170
|
+
pinnedRightColumns: null,
|
|
171
|
+
pinnedRightOffsets: null,
|
|
172
|
+
layouts: new Map(),
|
|
173
|
+
});
|
|
174
|
+
const getCachedRowSpans = (viewport, rowData, rowIndex) => {
|
|
175
|
+
const revision = grid.getRevision();
|
|
176
|
+
const cache = spanCacheRef.current;
|
|
177
|
+
const sameWindow = cache.revision === revision &&
|
|
178
|
+
cache.columns === viewport.leafColumns &&
|
|
179
|
+
cache.offsets === viewport.columnOffsets &&
|
|
180
|
+
cache.pinnedLeftColumns === viewport.pinnedLeftLeafColumns &&
|
|
181
|
+
cache.pinnedLeftOffsets === viewport.pinnedLeftOffsets &&
|
|
182
|
+
cache.pinnedRightColumns === viewport.pinnedRightLeafColumns &&
|
|
183
|
+
cache.pinnedRightOffsets === viewport.pinnedRightOffsets;
|
|
184
|
+
if (!sameWindow) {
|
|
185
|
+
cache.revision = revision;
|
|
186
|
+
cache.columns = viewport.leafColumns;
|
|
187
|
+
cache.offsets = viewport.columnOffsets;
|
|
188
|
+
cache.pinnedLeftColumns = viewport.pinnedLeftLeafColumns;
|
|
189
|
+
cache.pinnedLeftOffsets = viewport.pinnedLeftOffsets;
|
|
190
|
+
cache.pinnedRightColumns = viewport.pinnedRightLeafColumns;
|
|
191
|
+
cache.pinnedRightOffsets = viewport.pinnedRightOffsets;
|
|
192
|
+
cache.layouts.clear();
|
|
193
|
+
}
|
|
194
|
+
const cached = cache.layouts.get(rowIndex);
|
|
195
|
+
if (cached)
|
|
196
|
+
return cached;
|
|
197
|
+
const resolve = (columns, offsets) => {
|
|
198
|
+
if (columns.length === 0)
|
|
199
|
+
return null;
|
|
200
|
+
let hasSpan = false;
|
|
201
|
+
for (let i = 0; i < columns.length; i += 1) {
|
|
202
|
+
if (columns[i].colSpan !== undefined) {
|
|
203
|
+
hasSpan = true;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!hasSpan)
|
|
208
|
+
return null;
|
|
209
|
+
return grid.getRowSpans(rowData, rowIndex, columns, offsets);
|
|
210
|
+
};
|
|
211
|
+
const entry = {
|
|
212
|
+
central: resolve(viewport.leafColumns, viewport.columnOffsets),
|
|
213
|
+
left: resolve(viewport.pinnedLeftLeafColumns, viewport.pinnedLeftOffsets),
|
|
214
|
+
right: resolve(viewport.pinnedRightLeafColumns, viewport.pinnedRightOffsets),
|
|
215
|
+
};
|
|
216
|
+
cache.layouts.set(rowIndex, entry);
|
|
217
|
+
return entry;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Slices a full-group span layout down to the windowed columns a layer
|
|
221
|
+
* renders. The scrollable layer renders `columnRange` over `leafColumns`;
|
|
222
|
+
* pinned layers render their whole group. Spans that start before the
|
|
223
|
+
* window and cover into it surface as a leading origin whose `left`
|
|
224
|
+
* already matches the starting column — no clipping. Returns `null`
|
|
225
|
+
* when the row carries no spans so the pane takes the fast path.
|
|
226
|
+
*/
|
|
227
|
+
const sliceSpanLayoutForLayer = (viewport, layerColumns, isCentral, layout) => {
|
|
228
|
+
if (!layout)
|
|
229
|
+
return null;
|
|
230
|
+
const start = isCentral ? viewport.columnRange.start : 0;
|
|
231
|
+
const spans = [];
|
|
232
|
+
const widths = [];
|
|
233
|
+
const offsets = [];
|
|
234
|
+
// Full-group span origins before the window that still cover into
|
|
235
|
+
// it: surface the FIRST visible covered leaf as the rendered origin
|
|
236
|
+
// with the REMAINING width (origin left + covered prefix clipped).
|
|
237
|
+
for (let slot = 0; slot < layerColumns.length; slot += 1) {
|
|
238
|
+
const globalIndex = start + slot;
|
|
239
|
+
const cell = layout.spans[globalIndex];
|
|
240
|
+
const leafOffset = layerColumns[slot]?.offset ?? 0;
|
|
241
|
+
if (!cell) {
|
|
242
|
+
spans.push({ span: 1, covered: false });
|
|
243
|
+
widths.push(layerColumns[slot]?.width ?? 0);
|
|
244
|
+
offsets.push(leafOffset);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (cell.covered) {
|
|
248
|
+
// Find the origin: walk back while covered. When the origin
|
|
249
|
+
// itself is before the window, the first visible covered leaf
|
|
250
|
+
// becomes the rendered origin (width = remaining span width).
|
|
251
|
+
let origin = globalIndex;
|
|
252
|
+
while (origin > 0 && layout.spans[origin]?.covered)
|
|
253
|
+
origin -= 1;
|
|
254
|
+
const originCovered = layout.spans[origin]?.covered ?? true;
|
|
255
|
+
if (!originCovered && origin < start) {
|
|
256
|
+
// Only the FIRST visible covered leaf renders; later ones
|
|
257
|
+
// stay covered (skipped) so the merged cell paints once.
|
|
258
|
+
if (slot > 0 && layout.spans[globalIndex - 1]?.covered && globalIndex - 1 >= start) {
|
|
259
|
+
spans.push({ span: 1, covered: true });
|
|
260
|
+
widths.push(0);
|
|
261
|
+
offsets.push(leafOffset);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const originSpan = layout.spans[origin]?.span ?? 1;
|
|
265
|
+
const originEnd = origin + originSpan;
|
|
266
|
+
// Visible remainder: from the window's left edge at this
|
|
267
|
+
// slot to the span end (clipped to rendered leaves).
|
|
268
|
+
let remaining = 0;
|
|
269
|
+
let visibleSpan = 0;
|
|
270
|
+
for (let k = slot; k < layerColumns.length; k += 1) {
|
|
271
|
+
const colIndex = start + k;
|
|
272
|
+
if (colIndex >= originEnd)
|
|
273
|
+
break;
|
|
274
|
+
remaining += layerColumns[k]?.width ?? 0;
|
|
275
|
+
visibleSpan += 1;
|
|
276
|
+
}
|
|
277
|
+
spans.push({ span: Math.max(1, visibleSpan), covered: false });
|
|
278
|
+
widths.push(remaining);
|
|
279
|
+
offsets.push(leafOffset);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
spans.push({ span: 1, covered: true });
|
|
283
|
+
widths.push(0);
|
|
284
|
+
offsets.push(leafOffset);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
// Origin inside the window: clip the width to the rendered
|
|
288
|
+
// leaves so a span running past the right edge does not overlap
|
|
289
|
+
// the pinned-right pane or overflow the scrollable layer.
|
|
290
|
+
let clipped = 0;
|
|
291
|
+
let visibleSpan = 0;
|
|
292
|
+
for (let k = 0; k < cell.span && slot + k < layerColumns.length; k += 1) {
|
|
293
|
+
clipped += layerColumns[slot + k]?.width ?? 0;
|
|
294
|
+
visibleSpan += 1;
|
|
295
|
+
}
|
|
296
|
+
spans.push({ span: Math.max(1, visibleSpan), covered: false });
|
|
297
|
+
widths.push(clipped);
|
|
298
|
+
offsets.push(leafOffset);
|
|
299
|
+
}
|
|
300
|
+
return { spans, widths, offsets };
|
|
301
|
+
};
|
|
157
302
|
const getColumnPresentation = (column) => {
|
|
158
303
|
const revision = grid.getRevision();
|
|
159
304
|
const processedData = grid.getProcessedData();
|
|
@@ -287,8 +432,22 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
287
432
|
},
|
|
288
433
|
bindRow: (host, row) => {
|
|
289
434
|
const pane = paneMap.get(host);
|
|
290
|
-
if (pane)
|
|
291
|
-
|
|
435
|
+
if (!pane)
|
|
436
|
+
return;
|
|
437
|
+
// Per-row span layout over the FULL leaf group: merged
|
|
438
|
+
// widths come from the span origin's summed geometry and
|
|
439
|
+
// covered leaves are skipped — no clipping or overlap when
|
|
440
|
+
// a span crosses the virtual window boundary.
|
|
441
|
+
const viewport = grid.getViewportData();
|
|
442
|
+
const spans = getCachedRowSpans(viewport, row.data, row.index);
|
|
443
|
+
const isLeft = layer === layers.left;
|
|
444
|
+
const isRight = layer === layers.right;
|
|
445
|
+
const layout = isLeft ? spans.left : isRight ? spans.right : spans.central;
|
|
446
|
+
// Slice the full-group layout down to the windowed columns
|
|
447
|
+
// this layer renders: `columnRange` addresses `leafColumns`
|
|
448
|
+
// (scrollable) while pinned layers render their full group.
|
|
449
|
+
const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
|
|
450
|
+
pane.bind(row, layer.columns, layer.originX, sliced);
|
|
292
451
|
},
|
|
293
452
|
transformRow: (host, offsetY) => {
|
|
294
453
|
const pane = paneMap.get(host);
|
|
@@ -410,8 +569,18 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
410
569
|
if (columnWindowKey !== columnWindowKeyRef.current) {
|
|
411
570
|
columnWindowKeyRef.current = columnWindowKey;
|
|
412
571
|
const updateColumnWindow = () => {
|
|
413
|
-
|
|
414
|
-
|
|
572
|
+
// Span-aware: each pane resolves its own row's layout so
|
|
573
|
+
// merged cells keep their summed width while the window
|
|
574
|
+
// slides — covered leaves stay parked off-screen.
|
|
575
|
+
for (const pane of layers.central.panes) {
|
|
576
|
+
const paneRow = pane.getRow();
|
|
577
|
+
if (!paneRow) {
|
|
578
|
+
pane.updateColumns(layers.central.columns, layers.central.originX, null);
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
const spans = getCachedRowSpans(currentViewportData, paneRow.data, paneRow.index);
|
|
582
|
+
pane.updateColumns(layers.central.columns, layers.central.originX, sliceSpanLayoutForLayer(currentViewportData, layers.central.columns, true, spans.central));
|
|
583
|
+
}
|
|
415
584
|
setColumnWindowVersion((v) => v + 1);
|
|
416
585
|
};
|
|
417
586
|
if (synchronousColumnWindow) {
|
package/dist/controls.js
CHANGED
|
@@ -289,6 +289,13 @@ function MultiSelectControl({ descriptor }) {
|
|
|
289
289
|
return descriptor.options.filter((opt) => opt.label.toLowerCase().includes(term) || opt.value.toLowerCase().includes(term));
|
|
290
290
|
}, [descriptor.options, searchTerm]);
|
|
291
291
|
const allChecked = useMemo(() => descriptor.options.length > 0 && descriptor.options.every((opt) => opt.checked), [descriptor.options]);
|
|
292
|
+
const someChecked = useMemo(() => descriptor.options.length > 0 && !allChecked && descriptor.options.some((opt) => opt.checked), [descriptor.options, allChecked]);
|
|
293
|
+
const selectAllRef = useRef(null);
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
if (selectAllRef.current) {
|
|
296
|
+
selectAllRef.current.indeterminate = someChecked;
|
|
297
|
+
}
|
|
298
|
+
}, [someChecked]);
|
|
292
299
|
const toggleAll = (checked) => {
|
|
293
300
|
if (checked) {
|
|
294
301
|
descriptor.onChange(descriptor.options.map((opt) => opt.value));
|
|
@@ -324,6 +331,7 @@ function MultiSelectControl({ descriptor }) {
|
|
|
324
331
|
setSearchTerm("");
|
|
325
332
|
},
|
|
326
333
|
}, "×")), createElement("div", { className: "omnigrid-multi-select-actions" }, createElement("label", { className: "omnigrid-multi-select-item" }, createElement("input", {
|
|
334
|
+
ref: selectAllRef,
|
|
327
335
|
type: "checkbox",
|
|
328
336
|
className: "omnigrid-checkbox",
|
|
329
337
|
checked: allChecked,
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnLeafDef, PooledRow, RowId, RowStyle, ViewportData } from "@omnigrid/core";
|
|
1
|
+
import type { ColumnLeafDef, PooledRow, RowId, RowSpanLayout, RowStyle, ViewportData } from "@omnigrid/core";
|
|
2
2
|
import { type ContentBridge } from "./content";
|
|
3
3
|
import type { CellRoot } from "./reactRoot";
|
|
4
4
|
/** Column within the pool: definition + geometry from the virtual window. */
|
|
@@ -9,6 +9,11 @@ export interface PooledCellRenderInfo<T> {
|
|
|
9
9
|
columnIndex: number;
|
|
10
10
|
rowId: RowId;
|
|
11
11
|
rowIndex: number;
|
|
12
|
+
/**
|
|
13
|
+
* Normalized horizontal span of this cell (`1` = plain cell).
|
|
14
|
+
* Span origins render the merged width; covered cells are skipped.
|
|
15
|
+
*/
|
|
16
|
+
colSpan: number;
|
|
12
17
|
}
|
|
13
18
|
export interface PooledRowModifiers {
|
|
14
19
|
ctrlKey: boolean;
|
|
@@ -68,9 +73,11 @@ export declare class PooledRowPane<T> {
|
|
|
68
73
|
private originX;
|
|
69
74
|
constructor(host: HTMLDivElement, callbacks: PooledRowCallbacks<T>, bridge: ContentBridge<T>);
|
|
70
75
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
71
|
-
bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number): void;
|
|
76
|
+
bind(row: PooledRow<T>, columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
77
|
+
/** Returns the currently bound row, if any. */
|
|
78
|
+
getRow(): PooledRow<T> | null;
|
|
72
79
|
/** Re-layouts cells for a new horizontal column window. */
|
|
73
|
-
updateColumns(columns: PooledColumn<T>[], originX?: number): void;
|
|
80
|
+
updateColumns(columns: PooledColumn<T>[], originX?: number, spans?: RowSpanLayout | null): void;
|
|
74
81
|
/** Single row positioning operation — transform only (no reflow). */
|
|
75
82
|
setOffsetY(offsetY: number): void;
|
|
76
83
|
/** Moves an unused row far off-screen (outside viewport). */
|
package/dist/pooledRow.js
CHANGED
|
@@ -69,7 +69,7 @@ export class PooledRowPane {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
/** Binds a row to the panel and fully rebuilds content. */
|
|
72
|
-
bind(row, columns, originX = 0) {
|
|
72
|
+
bind(row, columns, originX = 0, spans) {
|
|
73
73
|
const hovered = this.host.matches(":hover");
|
|
74
74
|
if (hovered && this.row)
|
|
75
75
|
this.callbacks.onRowHover(this.row, false);
|
|
@@ -82,18 +82,22 @@ export class PooledRowPane {
|
|
|
82
82
|
// copies the row background colour onto each existing cell. If it ran
|
|
83
83
|
// first, newly created cells would keep the default CSS background
|
|
84
84
|
// until the next bind (i.e. until scrolling).
|
|
85
|
-
this.mapColumns(columns, true);
|
|
85
|
+
this.mapColumns(columns, true, spans);
|
|
86
86
|
this.applyRowPresentation(row);
|
|
87
87
|
if (hovered)
|
|
88
88
|
this.callbacks.onRowHover(row, true);
|
|
89
89
|
}
|
|
90
|
+
/** Returns the currently bound row, if any. */
|
|
91
|
+
getRow() {
|
|
92
|
+
return this.row;
|
|
93
|
+
}
|
|
90
94
|
/** Re-layouts cells for a new horizontal column window. */
|
|
91
|
-
updateColumns(columns, originX = 0) {
|
|
95
|
+
updateColumns(columns, originX = 0, spans) {
|
|
92
96
|
this.originX = originX;
|
|
93
97
|
const row = this.row;
|
|
94
98
|
if (row)
|
|
95
99
|
this.applyRowSizing(row);
|
|
96
|
-
this.mapColumns(columns, false);
|
|
100
|
+
this.mapColumns(columns, false, spans);
|
|
97
101
|
}
|
|
98
102
|
/** Single row positioning operation — transform only (no reflow). */
|
|
99
103
|
setOffsetY(offsetY) {
|
|
@@ -121,7 +125,7 @@ export class PooledRowPane {
|
|
|
121
125
|
while (this.cells.length < count)
|
|
122
126
|
this.cells.push(this.createCell());
|
|
123
127
|
}
|
|
124
|
-
mapColumns(columns, forceContent) {
|
|
128
|
+
mapColumns(columns, forceContent, spans) {
|
|
125
129
|
this.ensureCells(columns.length);
|
|
126
130
|
for (let slot = 0; slot < this.cells.length; slot += 1) {
|
|
127
131
|
const cell = this.cells[slot];
|
|
@@ -137,12 +141,31 @@ export class PooledRowPane {
|
|
|
137
141
|
}
|
|
138
142
|
continue;
|
|
139
143
|
}
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
// Spanned rows: covered leaves render nothing — the span origin
|
|
145
|
+
// owns the merged width. Park the node off-screen so recycled
|
|
146
|
+
// nodes never overlap the merged cell.
|
|
147
|
+
const covered = spans?.spans[slot]?.covered ?? false;
|
|
148
|
+
if (covered) {
|
|
149
|
+
if (cell.column !== null) {
|
|
150
|
+
this.clearContent(cell);
|
|
151
|
+
cell.column = null;
|
|
152
|
+
cell.columnIndex = -1;
|
|
153
|
+
}
|
|
154
|
+
cell.offsetX = null;
|
|
155
|
+
cell.width = null;
|
|
156
|
+
cell.element.style.transform = `translate3d(${OFFSCREEN_X}px, 0, 0)`;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const spanWidth = spans?.widths[slot];
|
|
160
|
+
const spanOffset = spans?.offsets[slot];
|
|
161
|
+
const effective = spanWidth !== undefined && spanOffset !== undefined ? { ...layout, width: spanWidth, offset: spanOffset } : layout;
|
|
162
|
+
const columnChanged = cell.column !== layout.column || cell.columnIndex !== layout.index || cell.span !== (spans?.spans[slot]?.span ?? 1);
|
|
163
|
+
this.layoutCell(cell, effective);
|
|
142
164
|
if (columnChanged)
|
|
143
165
|
cell.columnIndex = layout.index;
|
|
144
166
|
if (columnChanged || forceContent) {
|
|
145
167
|
cell.column = layout.column;
|
|
168
|
+
cell.span = spans?.spans[slot]?.span ?? 1;
|
|
146
169
|
this.renderContent(cell);
|
|
147
170
|
}
|
|
148
171
|
}
|
|
@@ -175,6 +198,7 @@ export class PooledRowPane {
|
|
|
175
198
|
element,
|
|
176
199
|
column: null,
|
|
177
200
|
columnIndex: -1,
|
|
201
|
+
span: 1,
|
|
178
202
|
root: null,
|
|
179
203
|
offsetX: null,
|
|
180
204
|
width: null,
|
|
@@ -204,6 +228,7 @@ export class PooledRowPane {
|
|
|
204
228
|
columnIndex: cell.columnIndex,
|
|
205
229
|
rowId: row.rowId,
|
|
206
230
|
rowIndex: row.index,
|
|
231
|
+
colSpan: cell.span,
|
|
207
232
|
};
|
|
208
233
|
this.applyCellPresentation(cell, cellInfo);
|
|
209
234
|
const content = this.callbacks.renderCellContent(cellInfo);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigrid/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "React adapter and renderer for OmniGrid",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omnigrid",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@omnigrid/default-theme": "^0.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@omnigrid/column-filter-plugin": "*",
|
|
48
49
|
"@omnigrid/quick-filter-plugin": "*",
|
|
49
50
|
"@types/react": "^19.0.0",
|
|
50
51
|
"@types/react-dom": "^19.0.0"
|