@omnigrid/react 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/dist/OmniGrid.js +177 -19
- package/dist/content.d.ts +2 -0
- package/dist/content.js +16 -1
- package/dist/controls.d.ts +3 -1
- package/dist/controls.js +16 -12
- package/dist/pooledRow.d.ts +10 -3
- package/dist/pooledRow.js +32 -7
- package/dist/popup.js +6 -2
- package/package.json +3 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -65,7 +65,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
65
65
|
const rowsLayerRef = useRef(null);
|
|
66
66
|
const pinnedLeftRowsLayerRef = useRef(null);
|
|
67
67
|
const pinnedRightRowsLayerRef = useRef(null);
|
|
68
|
-
const [isMeasured, setIsMeasured] = useState(false);
|
|
69
68
|
/** Space taken by the viewport's native scrollbars; body slots stay clear of it. */
|
|
70
69
|
const [scrollbarInsets, setScrollbarInsets] = useState({ right: 0, bottom: 0 });
|
|
71
70
|
const scrollFrameRef = useRef({ id: 0, top: 0, left: 0, lastTop: 0, lastTime: 0 });
|
|
@@ -155,6 +154,151 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
155
154
|
};
|
|
156
155
|
}
|
|
157
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
|
+
};
|
|
158
302
|
const getColumnPresentation = (column) => {
|
|
159
303
|
const revision = grid.getRevision();
|
|
160
304
|
const processedData = grid.getProcessedData();
|
|
@@ -288,8 +432,22 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
288
432
|
},
|
|
289
433
|
bindRow: (host, row) => {
|
|
290
434
|
const pane = paneMap.get(host);
|
|
291
|
-
if (pane)
|
|
292
|
-
|
|
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);
|
|
293
451
|
},
|
|
294
452
|
transformRow: (host, offsetY) => {
|
|
295
453
|
const pane = paneMap.get(host);
|
|
@@ -411,8 +569,18 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
411
569
|
if (columnWindowKey !== columnWindowKeyRef.current) {
|
|
412
570
|
columnWindowKeyRef.current = columnWindowKey;
|
|
413
571
|
const updateColumnWindow = () => {
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
}
|
|
416
584
|
setColumnWindowVersion((v) => v + 1);
|
|
417
585
|
};
|
|
418
586
|
if (synchronousColumnWindow) {
|
|
@@ -453,7 +621,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
453
621
|
if (width === 0 || height === 0)
|
|
454
622
|
return;
|
|
455
623
|
grid.setViewport({ width, height });
|
|
456
|
-
setIsMeasured(true);
|
|
457
624
|
}, [grid, syncScrollbarInsets]);
|
|
458
625
|
useEffect(() => {
|
|
459
626
|
const element = viewportRef.current;
|
|
@@ -471,7 +638,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
471
638
|
if (width === 0 || height === 0)
|
|
472
639
|
return;
|
|
473
640
|
grid.setViewport({ width, height });
|
|
474
|
-
setIsMeasured(true);
|
|
475
641
|
});
|
|
476
642
|
observer.observe(element, { box: "content-box" });
|
|
477
643
|
measureViewport();
|
|
@@ -483,12 +649,12 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
483
649
|
syncScrollbarInsets(viewportRef.current);
|
|
484
650
|
});
|
|
485
651
|
useLayoutEffect(() => {
|
|
486
|
-
if (
|
|
652
|
+
if (autoHeight)
|
|
487
653
|
return;
|
|
488
654
|
// Scrollbar and gutter changes alter clientWidth; sync it before paint
|
|
489
655
|
// so columns remain aligned when an overlay locks vertical scrolling.
|
|
490
656
|
measureViewport();
|
|
491
|
-
}, [autoHeight, hasVerticalOverflow,
|
|
657
|
+
}, [autoHeight, hasVerticalOverflow, measureViewport, overlayScope]);
|
|
492
658
|
useEffect(() => {
|
|
493
659
|
const unsubscribe = grid.on("scrollTo", (position) => {
|
|
494
660
|
const element = viewportRef.current;
|
|
@@ -584,15 +750,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
584
750
|
syncPool(true, skipContentBind);
|
|
585
751
|
});
|
|
586
752
|
};
|
|
587
|
-
if (!isMeasured) {
|
|
588
|
-
return (_jsx("div", { ref: viewportRef, className: viewportClassName, style: {
|
|
589
|
-
...viewportStyle,
|
|
590
|
-
overflowX: "auto",
|
|
591
|
-
overflowY: autoHeight ? "hidden" : "auto",
|
|
592
|
-
position: "relative",
|
|
593
|
-
scrollbarGutter: verticalScrollbarGutter,
|
|
594
|
-
} }));
|
|
595
|
-
}
|
|
596
753
|
/** Resolves headless slot content into a ReactNode (see contentToReactNode). */
|
|
597
754
|
const resolveSlotContent = (mount, context) => {
|
|
598
755
|
const raw = typeof mount.content === "function" ? mount.content(context) : mount.content;
|
|
@@ -615,7 +772,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
615
772
|
const groups = renderSlotGroups(mounts, context);
|
|
616
773
|
if (groups.every((group) => group === null))
|
|
617
774
|
return null;
|
|
618
|
-
|
|
775
|
+
const slotClass = slot === "down" ? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down" : `omnigrid-slot omnigrid-slot-${slot}`;
|
|
776
|
+
return (_jsx("div", { className: slotClass, children: groups }));
|
|
619
777
|
};
|
|
620
778
|
/** Renders slots that overlay the table body (absolute positioning, no layout shift). */
|
|
621
779
|
const renderBodySlot = (slot) => {
|
package/dist/content.d.ts
CHANGED
|
@@ -31,5 +31,7 @@ export declare function hasRenderableContent(content: ReactNode): boolean;
|
|
|
31
31
|
* - `SlotComponentContent` → component from the adapter registry;
|
|
32
32
|
* - `SlotHtmlContent` → `<div dangerouslySetInnerHTML>`;
|
|
33
33
|
* - anything else → passthrough (ReactNode from cellRenderer).
|
|
34
|
+
*
|
|
35
|
+
* Control `icon` names are resolved through the grid's icon registry.
|
|
34
36
|
*/
|
|
35
37
|
export declare function contentToReactNode<T>(content: unknown, bridge: ContentBridge<T>): ReactNode;
|
package/dist/content.js
CHANGED
|
@@ -126,6 +126,19 @@ function slotNodeToReact(node, bridge) {
|
|
|
126
126
|
});
|
|
127
127
|
return createElement(node.tag, props, children);
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Builds an icon resolver backed by the grid's `IconRegistry` so control
|
|
131
|
+
* descriptors can declare `icon: "filter"` (and friends) as plain names.
|
|
132
|
+
* Unknown names resolve to `null` instead of throwing, keeping slot renders stable.
|
|
133
|
+
*/
|
|
134
|
+
function createIconResolver(bridge) {
|
|
135
|
+
return (name) => {
|
|
136
|
+
const context = bridge.context();
|
|
137
|
+
if (!context.api.icons.has(name))
|
|
138
|
+
return null;
|
|
139
|
+
return slotNodeToReact(context.api.icons.get(name), bridge);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
129
142
|
/**
|
|
130
143
|
* Materialises the core's headless content into a ReactNode:
|
|
131
144
|
* - `string | number | boolean` → scalar;
|
|
@@ -135,6 +148,8 @@ function slotNodeToReact(node, bridge) {
|
|
|
135
148
|
* - `SlotComponentContent` → component from the adapter registry;
|
|
136
149
|
* - `SlotHtmlContent` → `<div dangerouslySetInnerHTML>`;
|
|
137
150
|
* - anything else → passthrough (ReactNode from cellRenderer).
|
|
151
|
+
*
|
|
152
|
+
* Control `icon` names are resolved through the grid's icon registry.
|
|
138
153
|
*/
|
|
139
154
|
export function contentToReactNode(content, bridge) {
|
|
140
155
|
if (content == null)
|
|
@@ -144,7 +159,7 @@ export function contentToReactNode(content, bridge) {
|
|
|
144
159
|
if (isCheckboxControl(content))
|
|
145
160
|
return renderCheckboxControl(content);
|
|
146
161
|
if (isUIControlDescriptor(content))
|
|
147
|
-
return renderControl(content);
|
|
162
|
+
return renderControl(content, createIconResolver(bridge));
|
|
148
163
|
if (isSlotNodeContent(content))
|
|
149
164
|
return slotNodeToReact(content, bridge);
|
|
150
165
|
if (isSlotComponentContent(content)) {
|
package/dist/controls.d.ts
CHANGED
|
@@ -15,5 +15,7 @@ export declare function DebouncedInput({ descriptor }: DebouncedInputProps): Rea
|
|
|
15
15
|
* Renders one framework-agnostic control descriptor with native HTML elements.
|
|
16
16
|
* Descriptor `id`s become React keys, so re-describing a popup updates
|
|
17
17
|
* elements in place instead of remounting them.
|
|
18
|
+
* @param descriptor - Control descriptor to materialise.
|
|
19
|
+
* @param resolveIcon - Optional resolver mapping `descriptor.icon` names to nodes; backed by the grid icon registry.
|
|
18
20
|
*/
|
|
19
|
-
export declare function renderControl(descriptor: UIControlDescriptor): ReactNode;
|
|
21
|
+
export declare function renderControl(descriptor: UIControlDescriptor, resolveIcon?: (name: string) => ReactNode): ReactNode;
|
package/dist/controls.js
CHANGED
|
@@ -62,7 +62,7 @@ export function DebouncedInput({ descriptor }) {
|
|
|
62
62
|
value: local,
|
|
63
63
|
placeholder: descriptor.placeholder,
|
|
64
64
|
disabled: descriptor.disabled,
|
|
65
|
-
"aria-label": descriptor.label ?? descriptor.placeholder,
|
|
65
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label ?? descriptor.placeholder,
|
|
66
66
|
onChange: handleChange,
|
|
67
67
|
onBlur: flush,
|
|
68
68
|
onKeyDown: handleKeyDown,
|
|
@@ -74,12 +74,14 @@ export function DebouncedInput({ descriptor }) {
|
|
|
74
74
|
onClick: handleClear,
|
|
75
75
|
}, "×"));
|
|
76
76
|
}
|
|
77
|
-
function withLabel(descriptor, field, inline = false) {
|
|
77
|
+
function withLabel(descriptor, field, inline = false, resolveIcon) {
|
|
78
78
|
const className = ["omnigrid-control", `omnigrid-control-${descriptor.type}`].join(" ");
|
|
79
|
+
const icon = descriptor.icon && resolveIcon ? resolveIcon(descriptor.icon) : null;
|
|
80
|
+
const body = icon ? createElement("div", { className: "omnigrid-control-body" }, icon, field) : field;
|
|
79
81
|
if (!descriptor.label)
|
|
80
|
-
return createElement("div", { key: descriptor.id, className },
|
|
82
|
+
return createElement("div", { key: descriptor.id, className }, body);
|
|
81
83
|
const label = createElement("span", { className: "omnigrid-control-label" }, descriptor.label);
|
|
82
|
-
return inline ? createElement("label", { key: descriptor.id, className },
|
|
84
|
+
return inline ? createElement("label", { key: descriptor.id, className }, body, label) : createElement("label", { key: descriptor.id, className }, label, body);
|
|
83
85
|
}
|
|
84
86
|
/**
|
|
85
87
|
* Custom-styled, keyboard-navigable drop-down select. Replaces the native
|
|
@@ -221,7 +223,7 @@ function SelectControl({ descriptor }) {
|
|
|
221
223
|
ref: listboxRef,
|
|
222
224
|
id: listboxId,
|
|
223
225
|
role: "listbox",
|
|
224
|
-
"aria-label": descriptor.label,
|
|
226
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label,
|
|
225
227
|
"data-omnigrid-filter-trigger": "",
|
|
226
228
|
className: "omnigrid-select-listbox",
|
|
227
229
|
onKeyDown: handleListboxKeyDown,
|
|
@@ -263,7 +265,7 @@ function SelectControl({ descriptor }) {
|
|
|
263
265
|
"aria-haspopup": "listbox",
|
|
264
266
|
"aria-expanded": isOpen,
|
|
265
267
|
"aria-controls": listboxId,
|
|
266
|
-
"aria-label": descriptor.label,
|
|
268
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label,
|
|
267
269
|
className: ["omnigrid-select-button", descriptor.disabled ? "omnigrid-select-button-disabled" : null]
|
|
268
270
|
.filter(Boolean)
|
|
269
271
|
.join(" "),
|
|
@@ -337,17 +339,19 @@ function MultiSelectControl({ descriptor }) {
|
|
|
337
339
|
* Renders one framework-agnostic control descriptor with native HTML elements.
|
|
338
340
|
* Descriptor `id`s become React keys, so re-describing a popup updates
|
|
339
341
|
* elements in place instead of remounting them.
|
|
342
|
+
* @param descriptor - Control descriptor to materialise.
|
|
343
|
+
* @param resolveIcon - Optional resolver mapping `descriptor.icon` names to nodes; backed by the grid icon registry.
|
|
340
344
|
*/
|
|
341
|
-
export function renderControl(descriptor) {
|
|
345
|
+
export function renderControl(descriptor, resolveIcon) {
|
|
342
346
|
switch (descriptor.type) {
|
|
343
347
|
case "text":
|
|
344
348
|
case "number":
|
|
345
349
|
case "date":
|
|
346
|
-
return withLabel(descriptor, createElement(DebouncedInput, { descriptor }));
|
|
350
|
+
return withLabel(descriptor, createElement(DebouncedInput, { descriptor }), false, resolveIcon);
|
|
347
351
|
case "select":
|
|
348
|
-
return withLabel(descriptor, createElement(SelectControl, { descriptor }));
|
|
352
|
+
return withLabel(descriptor, createElement(SelectControl, { descriptor }), false, resolveIcon);
|
|
349
353
|
case "multi-select":
|
|
350
|
-
return withLabel(descriptor, createElement(MultiSelectControl, { descriptor }));
|
|
354
|
+
return withLabel(descriptor, createElement(MultiSelectControl, { descriptor }), false, resolveIcon);
|
|
351
355
|
case "checkbox":
|
|
352
356
|
return withLabel(descriptor, createElement("input", {
|
|
353
357
|
type: "checkbox",
|
|
@@ -355,7 +359,7 @@ export function renderControl(descriptor) {
|
|
|
355
359
|
checked: descriptor.checked,
|
|
356
360
|
disabled: descriptor.disabled,
|
|
357
361
|
onChange: (event) => descriptor.onChange(event.target.checked),
|
|
358
|
-
}), true);
|
|
362
|
+
}), true, resolveIcon);
|
|
359
363
|
case "button":
|
|
360
364
|
return createElement("button", {
|
|
361
365
|
key: descriptor.id,
|
|
@@ -374,7 +378,7 @@ export function renderControl(descriptor) {
|
|
|
374
378
|
className: ["omnigrid-control", "omnigrid-control-group", descriptor.direction === "row" ? "omnigrid-control-group-row" : null, descriptor.className]
|
|
375
379
|
.filter(Boolean)
|
|
376
380
|
.join(" "),
|
|
377
|
-
}, descriptor.children.map(renderControl));
|
|
381
|
+
}, descriptor.children.map((child) => renderControl(child, resolveIcon)));
|
|
378
382
|
default:
|
|
379
383
|
return null;
|
|
380
384
|
}
|
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/dist/popup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createElement, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { contentToReactNode } from "./content";
|
|
3
3
|
const VIEWPORT_MARGIN = 8;
|
|
4
4
|
function anchorStyle(popup) {
|
|
5
5
|
const base = { position: "absolute", zIndex: 1000 };
|
|
@@ -66,6 +66,10 @@ export function PopupHost({ grid }) {
|
|
|
66
66
|
}, [popup]);
|
|
67
67
|
if (!popup)
|
|
68
68
|
return null;
|
|
69
|
+
const bridge = {
|
|
70
|
+
registry: {},
|
|
71
|
+
context: () => ({ api: grid, state: grid.getState() }),
|
|
72
|
+
};
|
|
69
73
|
return createElement("div", {
|
|
70
74
|
key: popup.id,
|
|
71
75
|
ref: elementRef,
|
|
@@ -73,5 +77,5 @@ export function PopupHost({ grid }) {
|
|
|
73
77
|
"aria-label": popup.title ?? popup.id,
|
|
74
78
|
className: ["omnigrid-popup", popup.className].filter(Boolean).join(" "),
|
|
75
79
|
style: anchorStyle(popup),
|
|
76
|
-
}, popup.title ? createElement("div", { className: "omnigrid-popup-title" }, popup.title) : null, popup.controls.map(
|
|
80
|
+
}, popup.title ? createElement("div", { className: "omnigrid-popup-title" }, popup.title) : null, popup.controls.map((control) => contentToReactNode(control, bridge)));
|
|
77
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigrid/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "React adapter and renderer for OmniGrid",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omnigrid",
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
"@omnigrid/default-theme": "^0.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@omnigrid/filtering-plugin": "*",
|
|
49
|
+
"@omnigrid/quick-filter-plugin": "*",
|
|
48
50
|
"@types/react": "^19.0.0",
|
|
49
51
|
"@types/react-dom": "^19.0.0"
|
|
50
52
|
},
|