@omnigrid/react 0.1.27 → 0.1.29
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 +9 -17
- package/dist/groupCell.js +21 -2
- package/dist/pooledRow.js +2 -0
- package/dist/rowRenderParams.d.ts +5 -0
- package/dist/rowRenderParams.js +26 -0
- package/package.json +1 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -4,19 +4,14 @@ import { flushSync } from "react-dom";
|
|
|
4
4
|
import { DomPool, isActiveCondition } from "@omnigrid/core";
|
|
5
5
|
import { contentToReactNode, hasRenderableContent } from "./content";
|
|
6
6
|
import { computeGroupSegments } from "./groupHeader";
|
|
7
|
-
import { getCollapsedGroupDisplay, getGroupColumnRole, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
|
|
7
|
+
import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
|
|
8
|
+
import { getRowRenderParams } from "./rowRenderParams";
|
|
8
9
|
import { PooledRowPane } from "./pooledRow";
|
|
9
10
|
import { createCellRoot } from "./reactRoot";
|
|
10
11
|
import { renderDefaultOverlay } from "./overlays";
|
|
11
12
|
import { PopupHost } from "./popup";
|
|
12
13
|
import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
|
13
14
|
import { useGrid } from "./useGrid";
|
|
14
|
-
function getRowRenderParams(row) {
|
|
15
|
-
if (row.type === "group") {
|
|
16
|
-
return { id: row.rowId, index: row.index, rowType: "group" };
|
|
17
|
-
}
|
|
18
|
-
return { id: row.rowId, index: row.index, rowType: "leaf", data: row.data };
|
|
19
|
-
}
|
|
20
15
|
function getCellValue(row, column) {
|
|
21
16
|
if (column.valueGetter)
|
|
22
17
|
return column.valueGetter(row);
|
|
@@ -644,16 +639,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
644
639
|
return;
|
|
645
640
|
}
|
|
646
641
|
grid.rowClick({
|
|
647
|
-
|
|
648
|
-
index: row.index,
|
|
649
|
-
rowType: "leaf",
|
|
650
|
-
data: row.data,
|
|
642
|
+
...getRowRenderParams(row),
|
|
651
643
|
ctrlKey: modifiers.ctrlKey,
|
|
652
644
|
shiftKey: modifiers.shiftKey,
|
|
653
645
|
});
|
|
654
646
|
},
|
|
655
647
|
onRowHover: (row, hovered) => {
|
|
656
|
-
const rowElements =
|
|
648
|
+
const rowElements = document.querySelectorAll(`[data-row-index="${row.index}"]`);
|
|
657
649
|
rowElements?.forEach((element) => element.classList.toggle("omnigrid-row-hover", hovered));
|
|
658
650
|
grid.rowHover({ ...getRowRenderParams(row), hovered });
|
|
659
651
|
},
|
|
@@ -667,10 +659,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
667
659
|
return;
|
|
668
660
|
}
|
|
669
661
|
grid.rowClick({
|
|
670
|
-
|
|
671
|
-
index: row.index,
|
|
672
|
-
rowType: "leaf",
|
|
673
|
-
data: row.data,
|
|
662
|
+
...getRowRenderParams(row),
|
|
674
663
|
ctrlKey: modifiers.ctrlKey,
|
|
675
664
|
shiftKey: modifiers.shiftKey,
|
|
676
665
|
});
|
|
@@ -717,6 +706,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
717
706
|
if (!viewport)
|
|
718
707
|
return;
|
|
719
708
|
const spans = getCachedRowSpans(viewport, row.data, row.index);
|
|
709
|
+
const paneRow = isGroupRowNode(row.data)
|
|
710
|
+
? { ...row, type: "group", group: row.data }
|
|
711
|
+
: { ...row, type: "leaf" };
|
|
720
712
|
const isLeft = layer === layers.left;
|
|
721
713
|
const isRight = layer === layers.right;
|
|
722
714
|
const layout = isLeft ? spans.left : isRight ? spans.right : spans.central;
|
|
@@ -724,7 +716,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
724
716
|
// this layer renders: `columnRange` addresses `leafColumns`
|
|
725
717
|
// (scrollable) while pinned layers render their full group.
|
|
726
718
|
const sliced = sliceSpanLayoutForLayer(viewport, layer.columns, !isLeft && !isRight, layout);
|
|
727
|
-
pane.bind(
|
|
719
|
+
pane.bind(paneRow, layer.columns, layer.originX, sliced);
|
|
728
720
|
},
|
|
729
721
|
resizeRow: (host, height) => {
|
|
730
722
|
const pane = paneMap.get(host);
|
package/dist/groupCell.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createElement } from "react";
|
|
2
2
|
import { contentToReactNode } from "./content";
|
|
3
|
+
function isToggleGroupMethod(method) {
|
|
4
|
+
return typeof method === "function";
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Checks whether an arbitrary row node represents a grouping tree node.
|
|
5
8
|
*
|
|
@@ -76,6 +79,22 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
|
|
|
76
79
|
return null;
|
|
77
80
|
const chevronName = node.expanded ? "chevron-down" : "chevron-right";
|
|
78
81
|
const icon = contentToReactNode(bridgeArg.context().api.icons.get(chevronName), bridgeArg);
|
|
82
|
+
const toggleButton = createElement("button", {
|
|
83
|
+
type: "button",
|
|
84
|
+
className: "omnigrid-icon-button",
|
|
85
|
+
"data-omnigrid-group-toggle": "",
|
|
86
|
+
"aria-label": `${node.expanded ? "Collapse" : "Expand"} ${String(node.key)} group`,
|
|
87
|
+
"aria-expanded": node.expanded,
|
|
88
|
+
onClick: (event) => {
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
const gridWithToggleGroup = grid;
|
|
91
|
+
const toggleGroup = grid.methods.toggleGroup ?? gridWithToggleGroup.toggleGroup;
|
|
92
|
+
if (!isToggleGroupMethod(toggleGroup)) {
|
|
93
|
+
throw new Error("Cannot toggle group: the grid does not expose a group toggle method.");
|
|
94
|
+
}
|
|
95
|
+
toggleGroup.call(grid, node.id);
|
|
96
|
+
},
|
|
97
|
+
}, icon);
|
|
79
98
|
if (groupRowRenderer) {
|
|
80
99
|
const rendered = groupRowRenderer({
|
|
81
100
|
node: node,
|
|
@@ -91,12 +110,12 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
|
|
|
91
110
|
return createElement("span", {
|
|
92
111
|
style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
|
|
93
112
|
title: String(node.key),
|
|
94
|
-
},
|
|
113
|
+
}, toggleButton, " ", node.key, " (", node.childrenCount, ")");
|
|
95
114
|
}
|
|
96
115
|
return createElement("span", {
|
|
97
116
|
style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
|
|
98
117
|
title: String(node.key),
|
|
99
|
-
},
|
|
118
|
+
}, toggleButton, " ", node.key);
|
|
100
119
|
}
|
|
101
120
|
if (column.cellRenderer) {
|
|
102
121
|
const value = node.aggregations[column.id];
|
package/dist/pooledRow.js
CHANGED
|
@@ -299,6 +299,8 @@ export class PooledRowPane {
|
|
|
299
299
|
};
|
|
300
300
|
element.addEventListener("click", (event) => {
|
|
301
301
|
event.stopPropagation();
|
|
302
|
+
if (event.target instanceof Element && event.target.closest("[data-omnigrid-group-toggle]"))
|
|
303
|
+
return;
|
|
302
304
|
const row = this.row;
|
|
303
305
|
const column = cell.column;
|
|
304
306
|
if (!row || !column)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PooledRow, RowRenderParams } from "@omnigrid/core";
|
|
2
|
+
type RowRenderInput<T> = Pick<PooledRow<T>, "type" | "rowId" | "index" | "data">;
|
|
3
|
+
/** Converts a pooled row to the public shape used by row callbacks and events. */
|
|
4
|
+
export declare function getRowRenderParams<T>(row: RowRenderInput<T>): RowRenderParams<T>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function isDataRowNode(row) {
|
|
2
|
+
if (typeof row !== "object" || row === null || !("type" in row) || row.type !== "leaf" || !("data" in row) || !("level" in row) || !("parent" in row)) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const parent = row.parent;
|
|
6
|
+
return (typeof row.level === "number" &&
|
|
7
|
+
typeof parent === "object" &&
|
|
8
|
+
parent !== null &&
|
|
9
|
+
"type" in parent &&
|
|
10
|
+
parent.type === "group");
|
|
11
|
+
}
|
|
12
|
+
/** Converts a pooled row to the public shape used by row callbacks and events. */
|
|
13
|
+
export function getRowRenderParams(row) {
|
|
14
|
+
if (row.type === "group") {
|
|
15
|
+
return { id: row.rowId, index: row.index, rowType: "group", isCollapsedGroup: false };
|
|
16
|
+
}
|
|
17
|
+
const node = isDataRowNode(row.data) ? row.data : undefined;
|
|
18
|
+
return {
|
|
19
|
+
id: row.rowId,
|
|
20
|
+
index: row.index,
|
|
21
|
+
rowType: "leaf",
|
|
22
|
+
data: node ? node.data : row.data,
|
|
23
|
+
isCollapsedGroup: node?.collapsedGroup !== undefined,
|
|
24
|
+
parentGroup: node?.parentGroup,
|
|
25
|
+
};
|
|
26
|
+
}
|