@omnigrid/react 0.1.32 → 0.1.33

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
@@ -4,7 +4,7 @@ import { flushSync } from "react-dom";
4
4
  import { DomPool, flattenColumns, isActiveCondition } from "@omnigrid/core";
5
5
  import { CellTooltipLayer } from "./cellTooltip";
6
6
  import { contentToReactNode, hasRenderableContent } from "./content";
7
- import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
7
+ import { getCollapsedGroupDisplay, getGroupColumnRole, getTreeDataLeafIndent, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
8
8
  import { computeGroupSegments } from "./groupHeader";
9
9
  import { renderDefaultOverlay } from "./overlays";
10
10
  import { PooledRowPane } from "./pooledRow";
@@ -547,6 +547,19 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
547
547
  : info.column.valueFormatter
548
548
  ? info.column.valueFormatter(value)
549
549
  : String(value ?? "");
550
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
551
+ if (treeDataLeafIndent !== undefined) {
552
+ return createElement("span", {
553
+ className: "omnigrid-cell-truncated",
554
+ style: {
555
+ display: "block",
556
+ overflow: "hidden",
557
+ paddingLeft: treeDataLeafIndent,
558
+ textOverflow: "ellipsis",
559
+ whiteSpace: "nowrap",
560
+ },
561
+ }, contentToReactNode(content, bridgeArg));
562
+ }
550
563
  if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
551
564
  return createElement("span", {
552
565
  className: "omnigrid-cell-truncated",
@@ -573,11 +586,20 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
573
586
  const value = collapsedGroupDisplay !== undefined
574
587
  ? collapsedGroupDisplay.value
575
588
  : getCellValue(rawData, info.column);
576
- if (info.column.valueFormatter)
577
- return info.column.valueFormatter(value);
578
- const valueType = typeof value;
579
- if (valueType === "string" || valueType === "number" || valueType === "boolean")
580
- return String(value);
589
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
590
+ let placeholder;
591
+ if (info.column.valueFormatter) {
592
+ placeholder = info.column.valueFormatter(value);
593
+ }
594
+ else {
595
+ const valueType = typeof value;
596
+ placeholder = valueType === "string" || valueType === "number" || valueType === "boolean" ? String(value) : null;
597
+ }
598
+ if (placeholder !== null && treeDataLeafIndent !== undefined) {
599
+ return `${"\u00a0".repeat(Math.ceil(treeDataLeafIndent / 4))}${placeholder}`;
600
+ }
601
+ if (placeholder !== null)
602
+ return placeholder;
581
603
  return null;
582
604
  },
583
605
  resolveRowClasses: (row) => {
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { ColumnLeafDef, GridApi, GroupRowNode, RowId } from "@omnigrid/core";
3
3
  import { type ContentBridge } from "./content";
4
+ export declare function getTreeDataLeafIndent<T>(row: unknown, column: ColumnLeafDef<T>, grid: GridApi<T>): number | undefined;
4
5
  /**
5
6
  * Checks whether an arbitrary row node represents a grouping tree node.
6
7
  *
package/dist/groupCell.js CHANGED
@@ -1,8 +1,27 @@
1
1
  import { createElement } from "react";
2
2
  import { contentToReactNode } from "./content";
3
+ const TREE_DATA_LEVEL_INDENT = 20;
4
+ // Align leaf labels with group labels after the 24px toggle and 6px gap.
5
+ const TREE_DATA_LEAF_CONTROL_OFFSET = 30;
3
6
  function isToggleGroupMethod(method) {
4
7
  return typeof method === "function";
5
8
  }
9
+ function hasTreeDataRowModel(grid) {
10
+ return typeof grid.methods.getTreeRows === "function";
11
+ }
12
+ export function getTreeDataLeafIndent(row, column, grid) {
13
+ if (!hasTreeDataRowModel(grid) || !row || typeof row !== "object" || !("type" in row) || row.type !== "leaf") {
14
+ return undefined;
15
+ }
16
+ if (!("level" in row) || typeof row.level !== "number")
17
+ return undefined;
18
+ const state = grid.getState();
19
+ const groupBy = state.groupBy ?? [];
20
+ const mode = state.groupColumnMode ?? "single";
21
+ if (!getGroupColumnRole(column, groupBy, mode).isGroupColumn)
22
+ return undefined;
23
+ return row.level * TREE_DATA_LEVEL_INDENT + TREE_DATA_LEAF_CONTROL_OFFSET;
24
+ }
6
25
  /**
7
26
  * Checks whether an arbitrary row node represents a grouping tree node.
8
27
  *
@@ -139,7 +158,7 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
139
158
  }
140
159
  if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
141
160
  return undefined;
142
- if (groupBy.length > 0 && mode === "single") {
161
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "single") {
143
162
  const role = getGroupColumnRole(column, groupBy, mode);
144
163
  if (role.isGroupColumn) {
145
164
  return createElement("span", { style: { paddingLeft: node.level * 20 } });
@@ -149,7 +168,7 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
149
168
  return createElement("span");
150
169
  }
151
170
  }
152
- if (groupBy.length > 0 && mode === "perLevel") {
171
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "perLevel") {
153
172
  const role = getGroupColumnRole(column, groupBy, mode);
154
173
  if (role.isGroupColumn && !showGroupValues) {
155
174
  return createElement("span");
@@ -203,7 +222,7 @@ export function renderGroupCellPlaceholder(info, grid) {
203
222
  }
204
223
  if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
205
224
  return undefined;
206
- if (groupBy.length > 0 && mode === "single") {
225
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "single") {
207
226
  const role = getGroupColumnRole(column, groupBy, mode);
208
227
  if (role.isGroupColumn)
209
228
  return "";
@@ -211,7 +230,7 @@ export function renderGroupCellPlaceholder(info, grid) {
211
230
  if (isGroupField)
212
231
  return "";
213
232
  }
214
- if (groupBy.length > 0 && mode === "perLevel") {
233
+ if (!hasTreeDataRowModel(grid) && groupBy.length > 0 && mode === "perLevel") {
215
234
  const role = getGroupColumnRole(column, groupBy, mode);
216
235
  if (role.isGroupColumn && !showGroupValues)
217
236
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",