@omnigrid/react 0.1.29 → 0.1.30

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.
@@ -24,4 +24,4 @@ import type { GridProps } from "./types";
24
24
  * core's headless content; React components in slots are connected via
25
25
  * `slotComponents`.
26
26
  */
27
- export declare function OmniGrid<T>({ className, style, slotComponents, ...options }: GridProps<T>): import("react").JSX.Element;
27
+ export declare function OmniGrid<T>({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }: GridProps<T>): import("react").JSX.Element;
package/dist/OmniGrid.js CHANGED
@@ -3,6 +3,7 @@ import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef
3
3
  import { flushSync } from "react-dom";
4
4
  import { DomPool, isActiveCondition } from "@omnigrid/core";
5
5
  import { contentToReactNode, hasRenderableContent } from "./content";
6
+ import { CellTooltipLayer } from "./cellTooltip";
6
7
  import { computeGroupSegments } from "./groupHeader";
7
8
  import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
8
9
  import { getRowRenderParams } from "./rowRenderParams";
@@ -78,7 +79,7 @@ function createRowLayerState() {
78
79
  * core's headless content; React components in slots are connected via
79
80
  * `slotComponents`.
80
81
  */
81
- export function OmniGrid({ className, style, slotComponents, ...options }) {
82
+ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
82
83
  const { grid, state, viewportData } = useGrid(options);
83
84
  const viewportRef = useRef(null);
84
85
  const layoutRef = useRef(null);
@@ -552,7 +553,16 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
552
553
  ? info.column.valueFormatter(value)
553
554
  : String(value ?? "");
554
555
  if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
555
- return createElement("span", { style: { paddingLeft: collapsedGroupDisplay.level * 20 } }, contentToReactNode(content, bridgeArg));
556
+ return createElement("span", {
557
+ className: "omnigrid-cell-truncated",
558
+ style: {
559
+ display: "block",
560
+ overflow: "hidden",
561
+ paddingLeft: collapsedGroupDisplay.level * 20,
562
+ textOverflow: "ellipsis",
563
+ whiteSpace: "nowrap",
564
+ },
565
+ }, contentToReactNode(content, bridgeArg));
556
566
  }
557
567
  return content;
558
568
  },
@@ -1257,7 +1267,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1257
1267
  visibility: isViewportMeasured ? undefined : "hidden",
1258
1268
  width: segment.width,
1259
1269
  };
1260
- return (_jsx("div", { role: "columnheader", className: className, "aria-colspan": segment.columnCount, title: segment.group.header ?? segment.group.id, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
1270
+ return (_jsx("div", { role: "columnheader", className: className, "aria-colspan": segment.columnCount, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
1261
1271
  registry: slotComponentsRef.current,
1262
1272
  context: buildRenderContext,
1263
1273
  })) : (_jsx("span", { className: "omnigrid-header-label", children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
@@ -1352,5 +1362,5 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1352
1362
  top: headerHeight,
1353
1363
  width: "100%",
1354
1364
  zIndex: 4,
1355
- }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
1365
+ }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), _jsx(CellTooltipLayer, { viewportRef: viewportRef, renderer: cellTooltipRenderer, className: cellTooltipClassName }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
1356
1366
  }
@@ -0,0 +1,13 @@
1
+ import { type ReactNode, type RefObject } from "react";
2
+ import type { CellTooltipRenderer } from "./types";
3
+ /** Props for the delegated tooltip layer mounted by the grid. */
4
+ export interface CellTooltipLayerProps {
5
+ /** Viewport whose cell and header descendants are checked on pointer entry. */
6
+ viewportRef: RefObject<HTMLDivElement | null>;
7
+ /** Optional renderer for the truncated cell or header's full text. */
8
+ renderer?: CellTooltipRenderer;
9
+ /** Additional CSS class applied to the tooltip element. */
10
+ className?: string;
11
+ }
12
+ /** Displays a tooltip only when hovered cell or header content exceeds its visible bounds. */
13
+ export declare function CellTooltipLayer({ viewportRef, renderer, className }: CellTooltipLayerProps): ReactNode;
@@ -0,0 +1,109 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ function isOverflowed(element) {
5
+ if (element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight)
6
+ return true;
7
+ if (getComputedStyle(element).textOverflow !== "ellipsis")
8
+ return false;
9
+ const range = document.createRange();
10
+ range.selectNodeContents(element);
11
+ return range.getBoundingClientRect().width > element.getBoundingClientRect().width;
12
+ }
13
+ /** Displays a tooltip only when hovered cell or header content exceeds its visible bounds. */
14
+ export function CellTooltipLayer({ viewportRef, renderer, className }) {
15
+ const [tooltip, setTooltip] = useState(null);
16
+ const tooltipRef = useRef(null);
17
+ const rendererRef = useRef(renderer);
18
+ const classNameRef = useRef(className);
19
+ rendererRef.current = renderer;
20
+ classNameRef.current = className;
21
+ useEffect(() => {
22
+ const viewport = viewportRef.current;
23
+ if (!viewport)
24
+ return;
25
+ let activeContainer = null;
26
+ let activeHoverTarget = null;
27
+ const dismiss = () => {
28
+ activeContainer = null;
29
+ activeHoverTarget = null;
30
+ setTooltip(null);
31
+ };
32
+ const handlePointerOver = (event) => {
33
+ if (!(event.target instanceof Element))
34
+ return;
35
+ const container = event.target.closest('[role="cell"], [role="columnheader"]');
36
+ if (!container || !viewport.contains(container)) {
37
+ dismiss();
38
+ return;
39
+ }
40
+ if (activeContainer === container) {
41
+ if (!activeHoverTarget?.contains(event.target))
42
+ dismiss();
43
+ return;
44
+ }
45
+ const isCell = container.getAttribute("role") === "cell";
46
+ const content = isCell
47
+ ? container.querySelector(".omnigrid-cell-content")
48
+ : container.querySelector(".omnigrid-header-label") ?? container;
49
+ if (!content) {
50
+ dismiss();
51
+ return;
52
+ }
53
+ if (!isCell && !content.contains(event.target)) {
54
+ dismiss();
55
+ return;
56
+ }
57
+ const nestedTruncation = isCell ? content.querySelector(".omnigrid-cell-truncated") : null;
58
+ const overflowTarget = nestedTruncation && isOverflowed(nestedTruncation) ? nestedTruncation : isOverflowed(content) ? content : null;
59
+ if (!overflowTarget) {
60
+ dismiss();
61
+ return;
62
+ }
63
+ const text = content.textContent ?? "";
64
+ if (!text) {
65
+ dismiss();
66
+ return;
67
+ }
68
+ const rect = overflowTarget.getBoundingClientRect();
69
+ activeContainer = container;
70
+ activeHoverTarget = overflowTarget;
71
+ setTooltip({ text, left: rect.left, top: rect.bottom });
72
+ };
73
+ const handlePointerOut = (event) => {
74
+ if (!activeContainer || !(event.target instanceof Node) || !activeContainer.contains(event.target))
75
+ return;
76
+ if (event.relatedTarget instanceof Node && activeContainer.contains(event.relatedTarget))
77
+ return;
78
+ dismiss();
79
+ };
80
+ viewport.addEventListener("pointerover", handlePointerOver);
81
+ viewport.addEventListener("pointerout", handlePointerOut);
82
+ viewport.addEventListener("scroll", dismiss, { passive: true });
83
+ window.addEventListener("scroll", dismiss, true);
84
+ window.addEventListener("resize", dismiss);
85
+ return () => {
86
+ viewport.removeEventListener("pointerover", handlePointerOver);
87
+ viewport.removeEventListener("pointerout", handlePointerOut);
88
+ viewport.removeEventListener("scroll", dismiss);
89
+ window.removeEventListener("scroll", dismiss, true);
90
+ window.removeEventListener("resize", dismiss);
91
+ };
92
+ }, [viewportRef]);
93
+ useLayoutEffect(() => {
94
+ const element = tooltipRef.current;
95
+ if (!element || !tooltip)
96
+ return;
97
+ const rect = element.getBoundingClientRect();
98
+ const left = Math.max(8, Math.min(tooltip.left, window.innerWidth - rect.width - 8));
99
+ const belowTop = tooltip.top + 6;
100
+ const top = belowTop + rect.height <= window.innerHeight - 8 ? belowTop : Math.max(8, tooltip.top - rect.height - 6);
101
+ element.style.left = `${left}px`;
102
+ element.style.top = `${top}px`;
103
+ }, [tooltip]);
104
+ if (!tooltip)
105
+ return null;
106
+ const content = rendererRef.current ? rendererRef.current(tooltip.text) : tooltip.text;
107
+ const tooltipClassName = ["omnigrid-cell-tooltip", classNameRef.current].filter(Boolean).join(" ");
108
+ return createPortal(_jsx("div", { ref: tooltipRef, className: tooltipClassName, role: "tooltip", style: { left: 0, top: 0 }, children: content }), document.body);
109
+ }
package/dist/groupCell.js CHANGED
@@ -108,14 +108,14 @@ export function renderGroupCellContent(info, bridgeArg, grid) {
108
108
  }
109
109
  if (showChildCount) {
110
110
  return createElement("span", {
111
- style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
112
- title: String(node.key),
113
- }, toggleButton, " ", node.key, " (", node.childrenCount, ")");
111
+ className: "omnigrid-group-cell-content",
112
+ style: { paddingLeft: mode === "single" ? level * 20 : 0 },
113
+ }, toggleButton, createElement("span", { className: "omnigrid-group-cell-label omnigrid-cell-truncated" }, node.key), createElement("span", { className: "omnigrid-group-cell-count" }, `(${node.childrenCount})`));
114
114
  }
115
115
  return createElement("span", {
116
- style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
117
- title: String(node.key),
118
- }, toggleButton, " ", node.key);
116
+ className: "omnigrid-group-cell-content",
117
+ style: { paddingLeft: mode === "single" ? level * 20 : 0 },
118
+ }, toggleButton, createElement("span", { className: "omnigrid-group-cell-label omnigrid-cell-truncated" }, node.key));
119
119
  }
120
120
  if (column.cellRenderer) {
121
121
  const value = node.aggregations[column.id];
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { ReactCellRenderer, ReactColumnDef, ReactColumnDef as ColumnDef, Re
5
5
  export { PooledRowPane } from "./pooledRow";
6
6
  export type { ContentBridge, PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./types";
7
7
  export { OmniGrid } from "./OmniGrid";
8
- export type { GridProps, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types";
8
+ export type { CellTooltipRenderer, GridProps, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types";
9
9
  export { useGrid } from "./useGrid";
10
10
  export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls";
11
11
  export type { DebouncedInputProps } from "./controls";
package/dist/pooledRow.js CHANGED
@@ -279,15 +279,19 @@ export class PooledRowPane {
279
279
  }
280
280
  createCell() {
281
281
  const element = document.createElement("div");
282
+ const contentElement = document.createElement("div");
282
283
  element.setAttribute("role", "cell");
283
284
  element.style.position = "absolute";
284
285
  element.style.top = "0";
285
286
  element.style.left = "0";
286
287
  element.style.overflow = "hidden";
287
288
  element.style.height = "100%";
289
+ contentElement.className = "omnigrid-cell-content";
290
+ element.appendChild(contentElement);
288
291
  this.host.appendChild(element);
289
292
  const cell = {
290
293
  element,
294
+ contentElement,
291
295
  column: null,
292
296
  columnIndex: -1,
293
297
  span: 1,
@@ -357,6 +361,13 @@ export class PooledRowPane {
357
361
  const flushLayout = cellInfo.column.cellLayout === "flush";
358
362
  if (flushLayout)
359
363
  cell.element.style.padding = "0";
364
+ const contentElement = cell.contentElement;
365
+ contentElement.className = "omnigrid-cell-content";
366
+ contentElement.style.minWidth = "0";
367
+ contentElement.style.maxWidth = "100%";
368
+ contentElement.style.width = flushLayout ? "100%" : "";
369
+ contentElement.style.textAlign = flushLayout ? cellInfo.column.align ?? "left" : "";
370
+ contentElement.style.overflow = "hidden";
360
371
  if (cell.column?.wrapText) {
361
372
  // Wrapping cell: the text breaks into several lines and the cell
362
373
  // grows with it. The theme owns the horizontal padding and the
@@ -368,6 +379,20 @@ export class PooledRowPane {
368
379
  cell.element.style.textOverflow = "clip";
369
380
  cell.element.style.paddingBlock = flushLayout ? "0" : "4px";
370
381
  cell.element.style.alignItems = "flex-start";
382
+ contentElement.style.whiteSpace = "normal";
383
+ contentElement.style.wordBreak = "break-word";
384
+ contentElement.style.textOverflow = "clip";
385
+ const maxLines = cell.column.maxLines;
386
+ if (maxLines !== undefined && Number.isFinite(maxLines) && Math.floor(maxLines) >= 1) {
387
+ contentElement.style.display = "-webkit-box";
388
+ contentElement.style.setProperty("-webkit-box-orient", "vertical");
389
+ contentElement.style.setProperty("-webkit-line-clamp", String(Math.floor(maxLines)));
390
+ }
391
+ else {
392
+ contentElement.style.display = "";
393
+ contentElement.style.removeProperty("-webkit-box-orient");
394
+ contentElement.style.removeProperty("-webkit-line-clamp");
395
+ }
371
396
  }
372
397
  else {
373
398
  // Reset the wrapping styles: the cell may be pooled from a
@@ -377,6 +402,12 @@ export class PooledRowPane {
377
402
  cell.element.style.textOverflow = "ellipsis";
378
403
  cell.element.style.paddingBlock = flushLayout ? "0" : "";
379
404
  cell.element.style.alignItems = "";
405
+ contentElement.style.whiteSpace = "nowrap";
406
+ contentElement.style.wordBreak = "";
407
+ contentElement.style.textOverflow = "ellipsis";
408
+ contentElement.style.display = "";
409
+ contentElement.style.removeProperty("-webkit-box-orient");
410
+ contentElement.style.removeProperty("-webkit-line-clamp");
380
411
  }
381
412
  }
382
413
  applyContent(cell, content, cellInfo) {
@@ -391,7 +422,7 @@ export class PooledRowPane {
391
422
  cell.root.render(String(content));
392
423
  }
393
424
  else {
394
- cell.element.textContent = String(content);
425
+ cell.contentElement.textContent = String(content);
395
426
  }
396
427
  return;
397
428
  }
@@ -401,7 +432,7 @@ export class PooledRowPane {
401
432
  cell.root.render(contentToReactNode(content, this.bridge));
402
433
  }
403
434
  else {
404
- cell.element.innerHTML = content.html;
435
+ cell.contentElement.innerHTML = content.html;
405
436
  }
406
437
  return;
407
438
  }
@@ -418,8 +449,8 @@ export class PooledRowPane {
418
449
  if (!cell.root) {
419
450
  const placeholder = this.callbacks.renderCellPlaceholder?.(cellInfo);
420
451
  if (placeholder)
421
- cell.element.textContent = placeholder;
422
- cell.root = this.callbacks.createRoot(cell.element);
452
+ cell.contentElement.textContent = placeholder;
453
+ cell.root = this.callbacks.createRoot(cell.contentElement);
423
454
  }
424
455
  cell.root.render(contentToReactNode(content, this.bridge));
425
456
  }
@@ -450,8 +481,8 @@ export class PooledRowPane {
450
481
  // root.unmount() during another React commit causes a race warning.
451
482
  cell.root.render(null);
452
483
  }
453
- else if (cell.element.textContent !== "" || cell.element.childElementCount > 0) {
454
- cell.element.replaceChildren();
484
+ else if (cell.contentElement.textContent !== "" || cell.contentElement.childElementCount > 0) {
485
+ cell.contentElement.replaceChildren();
455
486
  }
456
487
  }
457
488
  applyRowSizing(row) {
@@ -34,6 +34,7 @@ export type ReactColumnDef<T> = ReactColumnLeafDef<T> | ReactColumnGroupDef<T>;
34
34
  *
35
35
  * @api
36
36
  */
37
- export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns"> & {
37
+ export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns" | "defaultColumnDef"> & {
38
38
  columns: ReactColumnDef<T>[];
39
+ defaultColumnDef?: Partial<Omit<ReactColumnLeafDef<T>, "id" | "header">>;
39
40
  };
package/dist/types.d.ts CHANGED
@@ -78,6 +78,12 @@ export interface SlotRendererRegistry<T> {
78
78
  }
79
79
  export type OverlayComponentProps<T> = import("@omnigrid/core").OverlayComponentProps<T>;
80
80
  export type OverlayComponent<T> = import("react").ComponentType<import("@omnigrid/core").OverlayComponentProps<T>> | import("@omnigrid/core").OverlayComponent<T>;
81
+ /**
82
+ * Renders the full text of a truncated cell or header in its hover tooltip.
83
+ *
84
+ * @api
85
+ */
86
+ export type CellTooltipRenderer = (text: string) => ReactNode;
81
87
  export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponents"> {
82
88
  className?: string;
83
89
  style?: import("react").CSSProperties;
@@ -91,6 +97,18 @@ export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponen
91
97
  * @default 3
92
98
  */
93
99
  minHeight?: number;
100
+ /**
101
+ * Custom renderer for the full text shown when a cell or header is truncated.
102
+ *
103
+ * @api
104
+ */
105
+ cellTooltipRenderer?: CellTooltipRenderer;
106
+ /**
107
+ * Additional class applied to truncated cell and header tooltips.
108
+ *
109
+ * @api
110
+ */
111
+ cellTooltipClassName?: string;
94
112
  slotComponents?: SlotRendererRegistry<T>;
95
113
  overlayComponents?: Record<string, import("@omnigrid/core").OverlayComponent<T>>;
96
114
  }
package/dist/useGrid.js CHANGED
@@ -74,18 +74,23 @@ export function useGrid(options) {
74
74
  // plugin state when nothing actually changed.
75
75
  const columnsSyncedRef = useRef(false);
76
76
  const lastSyncedColumnsRef = useRef(undefined);
77
+ const lastSyncedDefaultColumnDefRef = useRef(undefined);
77
78
  useEffect(() => {
78
79
  if (grid.isDestroyed())
79
80
  return;
80
81
  if (!columnsSyncedRef.current) {
81
82
  columnsSyncedRef.current = true;
82
83
  lastSyncedColumnsRef.current = options.columns;
84
+ lastSyncedDefaultColumnDefRef.current = options.defaultColumnDef;
83
85
  return;
84
86
  }
85
87
  const prev = lastSyncedColumnsRef.current ?? [];
86
88
  const next = options.columns ?? [];
87
- if (prev.length !== next.length || prev.some((column, index) => column !== next[index])) {
89
+ const columnsChanged = prev.length !== next.length || prev.some((column, index) => column !== next[index]);
90
+ const defaultColumnDefChanged = lastSyncedDefaultColumnDefRef.current !== options.defaultColumnDef;
91
+ if (columnsChanged || defaultColumnDefChanged) {
88
92
  lastSyncedColumnsRef.current = options.columns;
93
+ lastSyncedDefaultColumnDefRef.current = options.defaultColumnDef;
89
94
  // Merge the user's column definitions into the current (plugin-enriched)
90
95
  // columns instead of replacing them wholesale. Plugins such as the resize
91
96
  // plugin inject properties (e.g. `headerRenderer`) into columns that are
@@ -130,9 +135,9 @@ export function useGrid(options) {
130
135
  if (!currentById.has(userColumn.id))
131
136
  merged.push(userColumn);
132
137
  });
133
- grid.setColumns(merged);
138
+ grid.setColumns(merged, options.defaultColumnDef);
134
139
  }
135
- }, [grid, options.columns]);
140
+ }, [grid, options.columns, options.defaultColumnDef]);
136
141
  // Controlled filter model: applied when the host passes a new reference.
137
142
  // Skipped on the first run — the Grid constructor already applied it.
138
143
  const filterSyncedRef = useRef(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",