@omnigrid/react 0.1.26 → 0.1.28

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 CHANGED
@@ -11,6 +11,12 @@ import { renderDefaultOverlay } from "./overlays";
11
11
  import { PopupHost } from "./popup";
12
12
  import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
13
13
  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
+ }
14
20
  function getCellValue(row, column) {
15
21
  if (column.valueGetter)
16
22
  return column.valueGetter(row);
@@ -573,9 +579,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
573
579
  return null;
574
580
  },
575
581
  resolveRowClasses: (row) => {
576
- const isGroup = Boolean(row.data && typeof row.data === "object" && "type" in row.data && row.data.type === "group");
582
+ const isGroup = row.type === "group";
577
583
  const base = isGroup ? "omnigrid-row omnigrid-row-group" : "omnigrid-row";
578
- const rowParams = { id: row.rowId, index: row.index, data: row.data };
584
+ const rowParams = getRowRenderParams(row);
579
585
  const currentOptions = current();
580
586
  const rowClass = typeof currentOptions.rowClass === "function" ? currentOptions.rowClass(rowParams) : currentOptions.rowClass;
581
587
  const dynamicRowClass = currentOptions.getRowClass?.(rowParams);
@@ -588,7 +594,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
588
594
  return [base, rowClass, ...ruleClasses, dynamicRowClass, ...pluginClasses].filter(Boolean).join(" ");
589
595
  },
590
596
  resolveRowStyle: (row) => {
591
- const rowParams = { id: row.rowId, index: row.index, data: row.data };
597
+ const rowParams = getRowRenderParams(row);
592
598
  const currentOptions = current();
593
599
  const baseRowStyle = {
594
600
  ...(currentOptions.rowStyle ?? {}),
@@ -631,15 +637,16 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
631
637
  return resolveCellStyle(info.column, cellParams, columnPresentation.style);
632
638
  },
633
639
  onRowClick: (row, modifiers) => {
634
- if (row.data && typeof row.data === "object" && "type" in row.data && row.data.type === "group") {
635
- if (typeof grid.toggleGroup === "function") {
636
- grid.toggleGroup(row.data.id);
640
+ if (row.type === "group") {
641
+ if (row.group && typeof grid.toggleGroup === "function") {
642
+ grid.toggleGroup(row.group.id);
637
643
  }
638
644
  return;
639
645
  }
640
646
  grid.rowClick({
641
647
  id: row.rowId,
642
648
  index: row.index,
649
+ rowType: "leaf",
643
650
  data: row.data,
644
651
  ctrlKey: modifiers.ctrlKey,
645
652
  shiftKey: modifiers.shiftKey,
@@ -648,20 +655,21 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
648
655
  onRowHover: (row, hovered) => {
649
656
  const rowElements = viewportRef.current?.querySelectorAll(`[data-row-index="${row.index}"]`);
650
657
  rowElements?.forEach((element) => element.classList.toggle("omnigrid-row-hover", hovered));
651
- grid.rowHover({ id: row.rowId, index: row.index, data: row.data, hovered });
658
+ grid.rowHover({ ...getRowRenderParams(row), hovered });
652
659
  },
653
660
  onCellClick: (row, column, modifiers) => {
654
661
  if (column.stopRowClick)
655
662
  return;
656
- if (row.data && typeof row.data === "object" && "type" in row.data && row.data.type === "group") {
657
- if (typeof grid.toggleGroup === "function") {
658
- grid.toggleGroup(row.data.id);
663
+ if (row.type === "group") {
664
+ if (row.group && typeof grid.toggleGroup === "function") {
665
+ grid.toggleGroup(row.group.id);
659
666
  }
660
667
  return;
661
668
  }
662
669
  grid.rowClick({
663
670
  id: row.rowId,
664
671
  index: row.index,
672
+ rowType: "leaf",
665
673
  data: row.data,
666
674
  ctrlKey: modifiers.ctrlKey,
667
675
  shiftKey: modifiers.shiftKey,
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
- }, icon, " ", node.key, " (", node.childrenCount, ")");
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
- }, icon, " ", node.key);
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",