@omnigrid/react 0.1.32 → 0.1.34

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/README.md CHANGED
@@ -69,7 +69,7 @@ include their own light and dark variants; they are not light/dark mode toggles.
69
69
  ## Links
70
70
 
71
71
  - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
72
- - **Demo:** https://omnigrid-demo.vercel.app/
72
+ - **Demo:** https://omnigrid.cc/
73
73
  - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
74
74
 
75
75
  ## License
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";
@@ -156,6 +156,20 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
156
156
  useEffect(() => {
157
157
  onGridReadyRef.current?.(grid);
158
158
  }, [grid]);
159
+ // Row class rules are resolved when pooled rows rebind (grid revision
160
+ // change), not on every React render. When the `rowClassRules` prop
161
+ // reference changes, bump the revision so every visible row re-evaluates
162
+ // its predicates in a single batch. `rowClassRules` must be referentially
163
+ // stable between renders unless its dependencies actually changed
164
+ // (memoize with `useMemo`); otherwise this effect re-fires every render.
165
+ const prevRowClassRulesRef = useRef(undefined);
166
+ useEffect(() => {
167
+ const next = options.rowClassRules;
168
+ if (next !== prevRowClassRulesRef.current) {
169
+ prevRowClassRulesRef.current = next;
170
+ grid.refresh();
171
+ }
172
+ }, [grid, options.rowClassRules]);
159
173
  const autoHeight = style?.height === undefined;
160
174
  const rowHeight = grid.getState().rowHeight;
161
175
  // Column-group header stack: `headerRowCount` group rows (one per depth) above
@@ -220,6 +234,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
220
234
  // only cedes space to the scrollbar once it is really needed.
221
235
  const verticalScrollbarGutter = "auto";
222
236
  const suppressRowHoverHighlight = options.suppressRowHoverHighlight ?? false;
237
+ const suppressColumnBorders = options.suppressColumnBorders ?? false;
223
238
  const cellFlashRaw = options.cellFlash;
224
239
  const cellFlashDurationMs = cellFlashRaw === true ? 1000 : typeof cellFlashRaw === "number" && cellFlashRaw > 0 ? cellFlashRaw : false;
225
240
  const viewportStyle = {
@@ -227,7 +242,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
227
242
  height: autoHeight ? measuredHeight : style?.height,
228
243
  ...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
229
244
  };
230
- const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null]
245
+ const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null, suppressColumnBorders ? "omnigrid-no-column-borders" : null]
231
246
  .filter(Boolean)
232
247
  .join(" ");
233
248
  const overlayState = state.overlay;
@@ -547,6 +562,19 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
547
562
  : info.column.valueFormatter
548
563
  ? info.column.valueFormatter(value)
549
564
  : String(value ?? "");
565
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
566
+ if (treeDataLeafIndent !== undefined) {
567
+ return createElement("span", {
568
+ className: "omnigrid-cell-truncated",
569
+ style: {
570
+ display: "block",
571
+ overflow: "hidden",
572
+ paddingLeft: treeDataLeafIndent,
573
+ textOverflow: "ellipsis",
574
+ whiteSpace: "nowrap",
575
+ },
576
+ }, contentToReactNode(content, bridgeArg));
577
+ }
550
578
  if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
551
579
  return createElement("span", {
552
580
  className: "omnigrid-cell-truncated",
@@ -573,11 +601,20 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
573
601
  const value = collapsedGroupDisplay !== undefined
574
602
  ? collapsedGroupDisplay.value
575
603
  : 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);
604
+ const treeDataLeafIndent = getTreeDataLeafIndent(info.data, info.column, grid);
605
+ let placeholder;
606
+ if (info.column.valueFormatter) {
607
+ placeholder = info.column.valueFormatter(value);
608
+ }
609
+ else {
610
+ const valueType = typeof value;
611
+ placeholder = valueType === "string" || valueType === "number" || valueType === "boolean" ? String(value) : null;
612
+ }
613
+ if (placeholder !== null && treeDataLeafIndent !== undefined) {
614
+ return `${"\u00a0".repeat(Math.ceil(treeDataLeafIndent / 4))}${placeholder}`;
615
+ }
616
+ if (placeholder !== null)
617
+ return placeholder;
581
618
  return null;
582
619
  },
583
620
  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.34",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",