@omnigrid/react 0.1.29 → 0.1.31

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
@@ -1,62 +1,66 @@
1
- # @omnigrid/react
2
-
3
- React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
4
-
5
- ## What it provides
6
-
7
- - **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
8
- - **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
9
- - **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
10
- - **Styles and default theme** — required structural styles and light/dark default colors are included automatically
11
- - **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
12
-
13
- ## Usage
14
-
15
- ```tsx
16
- import { OmniGrid } from "@omnigrid/react";
17
- import { useMemo } from "react";
18
-
19
- const columns = useMemo(() => [...], []);
20
- const data = [...];
21
-
22
- <OmniGrid columns={columns} data={data} />;
23
- ```
24
-
25
- ## Overlays
26
-
27
- Automatic loading, no-rows, and no-matching-rows overlays cover the body below the sticky
28
- header. They hide vertical scrolling while preserving its gutter, so columns do not shift;
29
- horizontal scrolling remains available. Automatic error overlays cover the full grid.
30
- Any active overlay hides vertical scrolling and preserves its gutter, regardless of scope.
31
- Manual overlays default to body-only, except errors default to full-grid; set `scope` to
32
- `"bodyOnly"` or `"full"` to choose the placement. `blockScroll: true` locks horizontal
33
- scrolling; vertical scrolling is always locked while an overlay is active.
34
-
35
- ```tsx
36
- import { OmniGrid, type OverlayComponentProps } from "@omnigrid/react";
37
-
38
- function LoadError<T>({ message }: OverlayComponentProps<T>) {
39
- return <div role="alert">{message ?? "Unable to load rows"}</div>;
40
- }
41
-
42
- <OmniGrid
43
- columns={columns}
44
- data={data}
45
- overlayComponents={{ error: LoadError }}
46
- onGridReady={(grid) => grid.showOverlay({ type: "error", message: "Please retry" })}
47
- />;
48
- ```
49
-
50
- To customize the table's color style, install a compatible `@omnigrid/*-theme`
51
- package and import it in the application after `@omnigrid/react`. Theme packages
52
- include their own light and dark variants; they are not light/dark mode toggles.
53
-
54
- ## Links
55
-
56
- - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
57
- - **Demo:** https://omnigrid-demo.vercel.app/
58
- - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
59
-
60
- ## License
61
-
62
- MIT © KRZK Apps
1
+ # @omnigrid/react
2
+
3
+ React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
4
+
5
+ ## What it provides
6
+
7
+ - **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
8
+ - **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
9
+ - **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
10
+ - **Styles and default theme** — required structural styles and light/dark default colors are included automatically
11
+ - **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { OmniGrid } from "@omnigrid/react";
17
+ import { useMemo } from "react";
18
+
19
+ const columns = useMemo(() => [...], []);
20
+ const data = [...];
21
+
22
+ <OmniGrid columns={columns} data={data} />;
23
+ ```
24
+
25
+ Column `headerRenderer` callbacks provide the header's primary content. The adapter owns the
26
+ shared header layout and keeps sorting, filtering, and registered plugin extensions alongside it,
27
+ so plugins can add controls without replacing or duplicating the header renderer.
28
+
29
+ ## Overlays
30
+
31
+ Automatic loading, no-rows, and no-matching-rows overlays cover the body below the sticky
32
+ header. They hide vertical scrolling while preserving its gutter, so columns do not shift;
33
+ horizontal scrolling remains available. Automatic error overlays cover the full grid.
34
+ Any active overlay hides vertical scrolling and preserves its gutter, regardless of scope.
35
+ Manual overlays default to body-only, except errors default to full-grid; set `scope` to
36
+ `"bodyOnly"` or `"full"` to choose the placement. `blockScroll: true` locks horizontal
37
+ scrolling; vertical scrolling is always locked while an overlay is active.
38
+
39
+ ```tsx
40
+ import { OmniGrid, type OverlayComponentProps } from "@omnigrid/react";
41
+
42
+ function LoadError<T>({ message }: OverlayComponentProps<T>) {
43
+ return <div role="alert">{message ?? "Unable to load rows"}</div>;
44
+ }
45
+
46
+ <OmniGrid
47
+ columns={columns}
48
+ data={data}
49
+ overlayComponents={{ error: LoadError }}
50
+ onGridReady={(grid) => grid.showOverlay({ type: "error", message: "Please retry" })}
51
+ />;
52
+ ```
53
+
54
+ To customize the table's color style, install a compatible `@omnigrid/*-theme`
55
+ package and import it in the application after `@omnigrid/react`. Theme packages
56
+ include their own light and dark variants; they are not light/dark mode toggles.
57
+
58
+ ## Links
59
+
60
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
61
+ - **Demo:** https://omnigrid-demo.vercel.app/
62
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
63
+
64
+ ## License
65
+
66
+ MIT © KRZK Apps
@@ -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
@@ -1,15 +1,16 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
3
3
  import { flushSync } from "react-dom";
4
- import { DomPool, isActiveCondition } from "@omnigrid/core";
4
+ import { DomPool, flattenColumns, isActiveCondition } from "@omnigrid/core";
5
+ import { CellTooltipLayer } from "./cellTooltip";
5
6
  import { contentToReactNode, hasRenderableContent } from "./content";
7
+ import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder, } from "./groupCell";
6
8
  import { computeGroupSegments } from "./groupHeader";
7
- import { getCollapsedGroupDisplay, getGroupColumnRole, isGroupRowNode, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
8
- import { getRowRenderParams } from "./rowRenderParams";
9
- import { PooledRowPane } from "./pooledRow";
10
- import { createCellRoot } from "./reactRoot";
11
9
  import { renderDefaultOverlay } from "./overlays";
10
+ import { PooledRowPane } from "./pooledRow";
12
11
  import { PopupHost } from "./popup";
12
+ import { createCellRoot } from "./reactRoot";
13
+ import { getRowRenderParams } from "./rowRenderParams";
13
14
  import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
14
15
  import { useGrid } from "./useGrid";
15
16
  function getCellValue(row, column) {
@@ -78,8 +79,22 @@ 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);
84
+ const columnTooltipOptions = useMemo(() => {
85
+ const result = new Map();
86
+ for (const column of flattenColumns(state.columns)) {
87
+ const columnWithTooltip = column;
88
+ if (columnWithTooltip.cellTooltipRenderer !== undefined ||
89
+ columnWithTooltip.cellTooltipClassName !== undefined) {
90
+ result.set(column.id, {
91
+ renderer: columnWithTooltip.cellTooltipRenderer,
92
+ className: columnWithTooltip.cellTooltipClassName,
93
+ });
94
+ }
95
+ }
96
+ return result;
97
+ }, [state.columns]);
83
98
  const viewportRef = useRef(null);
84
99
  const layoutRef = useRef(null);
85
100
  /** Scrollable content wrapper — its height is the total height of all rows. */
@@ -233,7 +248,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
233
248
  height: autoHeight ? measuredHeight : style?.height,
234
249
  ...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
235
250
  };
236
- const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null].filter(Boolean).join(" ");
251
+ const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null]
252
+ .filter(Boolean)
253
+ .join(" ");
237
254
  const overlayState = state.overlay;
238
255
  const filterModelSnapshot = grid.getFilterModel();
239
256
  const isColumnFiltered = (column) => {
@@ -545,14 +562,31 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
545
562
  // show the grouping field's value in the group column instead of
546
563
  // the row's own field value.
547
564
  const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
548
- const value = collapsedGroupDisplay !== undefined ? collapsedGroupDisplay.value : getCellValue(rawData, info.column);
565
+ const value = collapsedGroupDisplay !== undefined
566
+ ? collapsedGroupDisplay.value
567
+ : getCellValue(rawData, info.column);
549
568
  const content = info.column.cellRenderer
550
- ? info.column.cellRenderer({ value, data: rawData, column: info.column, id: info.rowId, index: info.rowIndex })
569
+ ? info.column.cellRenderer({
570
+ value,
571
+ data: rawData,
572
+ column: info.column,
573
+ id: info.rowId,
574
+ index: info.rowIndex,
575
+ })
551
576
  : info.column.valueFormatter
552
577
  ? info.column.valueFormatter(value)
553
578
  : String(value ?? "");
554
579
  if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
555
- return createElement("span", { style: { paddingLeft: collapsedGroupDisplay.level * 20 } }, contentToReactNode(content, bridgeArg));
580
+ return createElement("span", {
581
+ className: "omnigrid-cell-truncated",
582
+ style: {
583
+ display: "block",
584
+ overflow: "hidden",
585
+ paddingLeft: collapsedGroupDisplay.level * 20,
586
+ textOverflow: "ellipsis",
587
+ whiteSpace: "nowrap",
588
+ },
589
+ }, contentToReactNode(content, bridgeArg));
556
590
  }
557
591
  return content;
558
592
  },
@@ -565,7 +599,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
565
599
  ? info.data.data
566
600
  : info.data);
567
601
  const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
568
- const value = collapsedGroupDisplay !== undefined ? collapsedGroupDisplay.value : getCellValue(rawData, info.column);
602
+ const value = collapsedGroupDisplay !== undefined
603
+ ? collapsedGroupDisplay.value
604
+ : getCellValue(rawData, info.column);
569
605
  if (info.column.valueFormatter)
570
606
  return info.column.valueFormatter(value);
571
607
  const valueType = typeof value;
@@ -578,7 +614,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
578
614
  const base = isGroup ? "omnigrid-row omnigrid-row-group" : "omnigrid-row";
579
615
  const rowParams = getRowRenderParams(row);
580
616
  const currentOptions = current();
581
- const rowClass = typeof currentOptions.rowClass === "function" ? currentOptions.rowClass(rowParams) : currentOptions.rowClass;
617
+ const rowClass = typeof currentOptions.rowClass === "function"
618
+ ? currentOptions.rowClass(rowParams)
619
+ : currentOptions.rowClass;
582
620
  const dynamicRowClass = currentOptions.getRowClass?.(rowParams);
583
621
  const ruleClasses = Object.entries(currentOptions.rowClassRules ?? {})
584
622
  .filter(([, predicate]) => predicate(rowParams))
@@ -599,8 +637,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
599
637
  },
600
638
  resolveCellClasses: (info) => {
601
639
  const flashedCells = grid.getState().flashedCells;
602
- const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
603
- const isFlashed = cellFlashDurationMs !== false && flashTimestamp !== undefined && Date.now() - flashTimestamp <= cellFlashDurationMs;
640
+ const flashTimestamp = info.column.cellFlash === false ? undefined : flashedCells.get(`${info.rowId}:${info.column.id}`);
641
+ const isFlashed = cellFlashDurationMs !== false &&
642
+ flashTimestamp !== undefined &&
643
+ Date.now() - flashTimestamp <= cellFlashDurationMs;
604
644
  const cellParams = {
605
645
  id: info.rowId,
606
646
  index: info.rowIndex,
@@ -618,8 +658,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
618
658
  },
619
659
  resolveCellStyle: (info) => {
620
660
  const flashedCells = grid.getState().flashedCells;
621
- const flashTimestamp = flashedCells.get(`${info.rowId}:${info.column.id}`);
622
- const isFlashed = cellFlashDurationMs !== false && flashTimestamp !== undefined && Date.now() - flashTimestamp <= cellFlashDurationMs;
661
+ const flashTimestamp = info.column.cellFlash === false ? undefined : flashedCells.get(`${info.rowId}:${info.column.id}`);
662
+ const isFlashed = cellFlashDurationMs !== false &&
663
+ flashTimestamp !== undefined &&
664
+ Date.now() - flashTimestamp <= cellFlashDurationMs;
623
665
  const cellParams = {
624
666
  id: info.rowId,
625
667
  index: info.rowIndex,
@@ -757,7 +799,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
757
799
  return;
758
800
  const state = grid.getState();
759
801
  const processed = getPoolData(grid);
760
- const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || layer.processed !== processed;
802
+ const changed = layer.revision !== grid.getRevision() ||
803
+ layer.totalWidth !== viewportData.totalWidth ||
804
+ layer.processed !== processed;
761
805
  if (changed) {
762
806
  layer.revision = grid.getRevision();
763
807
  layer.totalWidth = viewportData.totalWidth;
@@ -908,7 +952,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
908
952
  const syncScrollbarInsets = useCallback((element) => {
909
953
  const right = Math.max(0, element.offsetWidth - element.clientWidth - element.clientLeft * 2);
910
954
  const bottom = Math.max(0, element.offsetHeight - element.clientHeight - element.clientTop * 2);
911
- setScrollbarInsets((previous) => (previous.right === right && previous.bottom === bottom ? previous : { right, bottom }));
955
+ setScrollbarInsets((previous) => previous.right === right && previous.bottom === bottom ? previous : { right, bottom });
912
956
  }, []);
913
957
  const measureViewport = useCallback(() => {
914
958
  const element = viewportRef.current;
@@ -1108,7 +1152,9 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1108
1152
  const groups = renderSlotGroups(mounts, context);
1109
1153
  if (groups.every((group) => group === null))
1110
1154
  return null;
1111
- const slotClass = slot === "down" ? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down" : `omnigrid-slot omnigrid-slot-${slot}`;
1155
+ const slotClass = slot === "down"
1156
+ ? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down"
1157
+ : `omnigrid-slot omnigrid-slot-${slot}`;
1112
1158
  return _jsx("div", { className: slotClass, children: groups });
1113
1159
  };
1114
1160
  /** Renders slots that overlay the table body (absolute positioning, no layout shift). */
@@ -1139,7 +1185,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1139
1185
  const registeredRenderer = typeof overlay.component === "string"
1140
1186
  ? optionsRef.current.overlayComponents?.[overlay.component]
1141
1187
  : optionsRef.current.overlayComponents?.[overlay.type];
1142
- const component = typeof overlay.component === "function" || (typeof overlay.component === "object" && overlay.component !== null)
1188
+ const component = typeof overlay.component === "function" ||
1189
+ (typeof overlay.component === "object" && overlay.component !== null)
1143
1190
  ? overlay.component
1144
1191
  : registeredRenderer;
1145
1192
  const isLegacyRenderer = typeof component === "function" && component.length >= 2;
@@ -1183,6 +1230,20 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1183
1230
  // correctly on the horizontal axis because sticky positioning is not
1184
1231
  // affected by the clip.
1185
1232
  const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
1233
+ const renderHeaderExtensions = (item, position) => {
1234
+ const params = { column: item.column, index: item.index };
1235
+ return grid.getHeaderExtensions(position).map((extension) => {
1236
+ const content = contentToReactNode(extension.render(params), {
1237
+ registry: slotComponentsRef.current,
1238
+ context: buildRenderContext,
1239
+ });
1240
+ if (!hasRenderableContent(content))
1241
+ return null;
1242
+ const wrapper = position === "overlay" ? "div" : "span";
1243
+ const className = position === "overlay" ? "omnigrid-header-overlay-item" : "omnigrid-header-extension";
1244
+ return createElement(wrapper, { key: extension.id, className }, content);
1245
+ });
1246
+ };
1186
1247
  const renderHeaderCells = (columns, originX) => columns.map((item) => {
1187
1248
  const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
1188
1249
  const gapRows = headerRowCount - 1 - deepestDepth;
@@ -1190,6 +1251,28 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1190
1251
  const headerParams = { column: item.column, index: item.index };
1191
1252
  const className = resolveHeaderClasses(item.column, headerParams, fullHeight);
1192
1253
  const customHeaderStyle = resolveHeaderStyle(item.column, headerParams);
1254
+ const headerAlign = item.column.headerAlign;
1255
+ const headerJustify = headerAlign === "center"
1256
+ ? "center"
1257
+ : headerAlign === "right"
1258
+ ? "flex-end"
1259
+ : headerAlign === "left"
1260
+ ? "flex-start"
1261
+ : undefined;
1262
+ const headerStartExtensions = renderHeaderExtensions(item, "start");
1263
+ const headerEndExtensions = renderHeaderExtensions(item, "end");
1264
+ const headerOverlayExtensions = renderHeaderExtensions(item, "overlay");
1265
+ const hasFilterTrigger = grid.hasFilterMenu() && item.column.filterable !== false;
1266
+ const hasHeaderTools = Boolean(item.column.sortState) || hasFilterTrigger || headerEndExtensions.length > 0;
1267
+ const headerContent = item.column.headerRenderer
1268
+ ? contentToReactNode(item.column.headerRenderer(item.column), {
1269
+ registry: slotComponentsRef.current,
1270
+ context: buildRenderContext,
1271
+ })
1272
+ : getGroupColumnRole(item.column, grid.getState().groupBy, grid.getState().groupColumnMode)
1273
+ .isGroupColumn && grid.getState().groupColumnMode === "single"
1274
+ ? grid.getState().groupColumnHeader
1275
+ : (item.column.header ?? item.column.id);
1193
1276
  const headerCellLayout = {
1194
1277
  alignItems: "center",
1195
1278
  display: "flex",
@@ -1206,31 +1289,44 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1206
1289
  visibility: isViewportMeasured ? undefined : "hidden",
1207
1290
  width: item.width,
1208
1291
  };
1209
- return (_jsx("div", { role: "columnheader", className: className, "data-sort": item.column.sortState, "data-sort-index": item.column.sortIndex, "data-sortable": item.column.sortable === true ? "true" : undefined, "aria-sort": item.column.sortState === "asc" ? "ascending" : item.column.sortState === "desc" ? "descending" : "none", onClick: (event) => item.column.stopHeaderClick
1292
+ const headerContentLayout = {
1293
+ alignItems: "center",
1294
+ display: "flex",
1295
+ flex: "1 1 auto",
1296
+ justifyContent: headerJustify,
1297
+ minWidth: 0,
1298
+ overflow: "hidden",
1299
+ };
1300
+ return (_jsxs("div", { role: "columnheader", className: className, "data-sort": item.column.sortState, "data-sort-index": item.column.sortIndex, "data-sortable": item.column.sortable === true ? "true" : undefined, "aria-sort": item.column.sortState === "asc"
1301
+ ? "ascending"
1302
+ : item.column.sortState === "desc"
1303
+ ? "descending"
1304
+ : "none", onClick: (event) => item.column.stopHeaderClick
1210
1305
  ? event.stopPropagation()
1211
1306
  : grid.headerClick(item.column.id, event.shiftKey || event.ctrlKey || event.metaKey), onKeyDown: (event) => {
1212
1307
  if (event.key === "Enter" || event.key === " ")
1213
1308
  grid.headerClick(item.column.id);
1214
- }, tabIndex: 0, style: headerCellLayout, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
1215
- registry: slotComponentsRef.current,
1216
- context: buildRenderContext,
1217
- })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: getGroupColumnRole(item.column, grid.getState().groupBy, grid.getState().groupColumnMode).isGroupColumn &&
1218
- grid.getState().groupColumnMode === "single"
1219
- ? grid.getState().groupColumnHeader
1220
- : (item.column.header ?? item.column.id) }), _jsxs("span", { className: "omnigrid-header-tools", children: [item.column.sortState && (_jsxs("span", { className: "omnigrid-sort-indicator", "aria-hidden": "true", children: [contentToReactNode(item.column.sortState === "asc" ? grid.icons.get("arrow-up") : grid.icons.get("arrow-down"), {
1221
- registry: slotComponentsRef.current,
1222
- context: buildRenderContext,
1223
- }), item.column.sortIndex !== undefined && _jsx("span", { className: "omnigrid-sort-priority", children: item.column.sortIndex })] })), grid.hasFilterMenu() && item.column.filterable !== false && (_jsx("button", { type: "button", className: "omnigrid-filter-trigger", "data-omnigrid-filter-trigger": "", "data-active": isColumnFiltered(item.column) ? "true" : undefined, "aria-label": `Filter ${item.column.header ?? item.column.id}`, "aria-haspopup": "dialog", tabIndex: -1, onClick: (event) => {
1224
- event.stopPropagation();
1225
- const rect = event.currentTarget.getBoundingClientRect();
1226
- const layoutRect = layoutRef.current?.getBoundingClientRect() ?? { left: 0, top: 0, width: 0, height: 0 };
1227
- grid.requestFilterMenu(item.column.id, {
1228
- x: rect.left - layoutRect.left,
1229
- y: rect.top - layoutRect.top,
1230
- width: rect.width,
1231
- height: rect.height,
1232
- });
1233
- }, onKeyDown: (event) => event.stopPropagation(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "12", height: "12", fill: "currentColor", "aria-hidden": "true", children: _jsx("path", { d: "M3 4h18l-7 8.5V20l-4-2v-5.5z" }) }) }))] })] })) }, item.column.id));
1309
+ }, tabIndex: 0, style: headerCellLayout, children: [headerStartExtensions.length > 0 && (_jsx("span", { className: "omnigrid-header-start", children: headerStartExtensions })), _jsx("div", { className: "omnigrid-header-main", style: headerContentLayout, children: item.column.headerRenderer ? (headerContent) : (_jsx("span", { className: "omnigrid-header-label", style: {
1310
+ flex: "1 1 auto",
1311
+ minWidth: 0,
1312
+ textAlign: headerAlign ?? "left",
1313
+ }, children: headerContent })) }), hasHeaderTools && (_jsxs("span", { className: "omnigrid-header-tools", children: [item.column.sortState && (_jsxs("span", { className: "omnigrid-sort-indicator", "aria-hidden": "true", children: [contentToReactNode(item.column.sortState === "asc"
1314
+ ? grid.icons.get("arrow-up")
1315
+ : grid.icons.get("arrow-down"), {
1316
+ registry: slotComponentsRef.current,
1317
+ context: buildRenderContext,
1318
+ }), item.column.sortIndex !== undefined && (_jsx("span", { className: "omnigrid-sort-priority", children: item.column.sortIndex }))] })), hasFilterTrigger && (_jsx("button", { type: "button", className: "omnigrid-filter-trigger", "data-omnigrid-filter-trigger": "", "data-active": isColumnFiltered(item.column) ? "true" : undefined, "aria-label": `Filter ${item.column.header ?? item.column.id}`, "aria-haspopup": "dialog", tabIndex: -1, onClick: (event) => {
1319
+ event.stopPropagation();
1320
+ const rect = event.currentTarget.getBoundingClientRect();
1321
+ const layoutRect = layoutRef.current?.getBoundingClientRect() ??
1322
+ { left: 0, top: 0, width: 0, height: 0 };
1323
+ grid.requestFilterMenu(item.column.id, {
1324
+ x: rect.left - layoutRect.left,
1325
+ y: rect.top - layoutRect.top,
1326
+ width: rect.width,
1327
+ height: rect.height,
1328
+ });
1329
+ }, onKeyDown: (event) => event.stopPropagation(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "12", height: "12", fill: "currentColor", "aria-hidden": "true", children: _jsx("path", { d: "M3 4h18l-7 8.5V20l-4-2v-5.5z" }) }) })), headerEndExtensions] })), headerOverlayExtensions.length > 0 && (_jsx("div", { className: "omnigrid-header-overlay", children: headerOverlayExtensions }))] }, item.column.id));
1234
1330
  });
1235
1331
  const renderGroupCells = (depth, columns, originX) => computeGroupSegments(viewportData.columnGroups, columns, depth, originX).map((segment, index) => {
1236
1332
  const groupParams = {
@@ -1241,11 +1337,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1241
1337
  };
1242
1338
  const className = resolveGroupHeaderClasses(segment.group, groupParams);
1243
1339
  const customGroupStyle = resolveGroupHeaderStyle(segment.group, groupParams);
1340
+ const groupHeaderAlign = segment.group.headerAlign;
1341
+ const groupJustify = groupHeaderAlign === "left" ? "flex-start" : groupHeaderAlign === "right" ? "flex-end" : "center";
1244
1342
  const groupCellLayout = {
1245
1343
  alignItems: "center",
1246
1344
  display: "flex",
1247
1345
  fontWeight: 600,
1248
- justifyContent: "center",
1346
+ justifyContent: groupJustify,
1249
1347
  overflow: "hidden",
1250
1348
  padding: "0 12px",
1251
1349
  whiteSpace: "nowrap",
@@ -1257,10 +1355,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1257
1355
  visibility: isViewportMeasured ? undefined : "hidden",
1258
1356
  width: segment.width,
1259
1357
  };
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), {
1358
+ return (_jsx("div", { role: "columnheader", className: className, "aria-colspan": segment.columnCount, style: groupCellLayout, children: segment.group.headerRenderer ? (contentToReactNode(segment.group.headerRenderer(segment.group), {
1261
1359
  registry: slotComponentsRef.current,
1262
1360
  context: buildRenderContext,
1263
- })) : (_jsx("span", { className: "omnigrid-header-label", children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
1361
+ })) : (_jsx("span", { className: "omnigrid-header-label", style: { textAlign: groupHeaderAlign ?? "center" }, children: segment.group.header ?? segment.group.id })) }, `${depth}:${index}:${segment.group.id}`));
1264
1362
  });
1265
1363
  /**
1266
1364
  * Sticky header stack: `headerRowCount` group rows (one per depth) above the
@@ -1313,7 +1411,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1313
1411
  height: autoHeight ? measuredHeight : "100%",
1314
1412
  minHeight: minViewportHeight,
1315
1413
  minWidth: 0,
1316
- overflowX: overlayBlocksHorizontalScroll ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
1414
+ overflowX: overlayBlocksHorizontalScroll
1415
+ ? "hidden"
1416
+ : needsHorizontalScroll
1417
+ ? "auto"
1418
+ : "hidden",
1317
1419
  overflowY: overlayScope || autoHeight ? "hidden" : "auto",
1318
1420
  position: "relative",
1319
1421
  scrollbarGutter: verticalScrollbarGutter,
@@ -1352,5 +1454,5 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
1352
1454
  top: headerHeight,
1353
1455
  width: "100%",
1354
1456
  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) }))] }));
1457
+ }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), _jsx(CellTooltipLayer, { viewportRef: viewportRef, renderer: cellTooltipRenderer, className: cellTooltipClassName, resolveCellTooltip: (columnId) => columnTooltipOptions.get(columnId) }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
1356
1458
  }
@@ -0,0 +1,17 @@
1
+ import { type ReactNode, type RefObject } from "react";
2
+ import type { CellTooltipRenderer } from "./reactColumnDef";
3
+ import type { CellTooltipOptions } from "./types";
4
+ export declare function isTextOverflowed(textWidth: number, containerWidth: number): boolean;
5
+ /** Props for the delegated tooltip layer mounted by the grid. */
6
+ export interface CellTooltipLayerProps {
7
+ /** Viewport whose cell and header descendants are checked on pointer entry. */
8
+ viewportRef: RefObject<HTMLDivElement | null>;
9
+ /** Optional renderer for the truncated cell or header's full text. */
10
+ renderer?: CellTooltipRenderer;
11
+ /** Additional CSS class applied to the tooltip element. */
12
+ className?: string;
13
+ /** Resolves per-column tooltip overrides for hovered data cells. */
14
+ resolveCellTooltip?: (columnId: string) => CellTooltipOptions | undefined;
15
+ }
16
+ /** Displays a tooltip only when hovered cell or header content exceeds its visible bounds. */
17
+ export declare function CellTooltipLayer({ viewportRef, renderer, className, resolveCellTooltip }: CellTooltipLayerProps): ReactNode;
@@ -0,0 +1,139 @@
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 isTextOverflowed(range.getBoundingClientRect().width, element.getBoundingClientRect().width);
12
+ }
13
+ export function isTextOverflowed(textWidth, containerWidth) {
14
+ return textWidth - containerWidth > 1;
15
+ }
16
+ /** Displays a tooltip only when hovered cell or header content exceeds its visible bounds. */
17
+ export function CellTooltipLayer({ viewportRef, renderer, className, resolveCellTooltip }) {
18
+ const [tooltip, setTooltip] = useState(null);
19
+ const tooltipRef = useRef(null);
20
+ const rendererRef = useRef(renderer);
21
+ const classNameRef = useRef(className);
22
+ const resolveCellTooltipRef = useRef(resolveCellTooltip);
23
+ rendererRef.current = renderer;
24
+ classNameRef.current = className;
25
+ resolveCellTooltipRef.current = resolveCellTooltip;
26
+ useEffect(() => {
27
+ const viewport = viewportRef.current;
28
+ if (!viewport)
29
+ return;
30
+ let activeContainer = null;
31
+ let activeHoverTarget = null;
32
+ const dismiss = () => {
33
+ activeContainer = null;
34
+ activeHoverTarget = null;
35
+ setTooltip(null);
36
+ };
37
+ const handlePointerOver = (event) => {
38
+ if (!(event.target instanceof Element))
39
+ return;
40
+ const container = event.target.closest('[role="cell"], [role="columnheader"]');
41
+ if (!container || !viewport.contains(container)) {
42
+ dismiss();
43
+ return;
44
+ }
45
+ if (activeContainer === container) {
46
+ if (!activeHoverTarget?.contains(event.target))
47
+ dismiss();
48
+ return;
49
+ }
50
+ const isCell = container.getAttribute("role") === "cell";
51
+ const content = isCell
52
+ ? container.querySelector(".omnigrid-cell-content")
53
+ : container.querySelector(".omnigrid-header-label") ?? container;
54
+ if (!content) {
55
+ dismiss();
56
+ return;
57
+ }
58
+ if (!isCell && !content.contains(event.target)) {
59
+ dismiss();
60
+ return;
61
+ }
62
+ const nestedTruncation = isCell ? content.querySelector(".omnigrid-cell-truncated") : null;
63
+ const overflowTarget = nestedTruncation && isOverflowed(nestedTruncation) ? nestedTruncation : isOverflowed(content) ? content : null;
64
+ if (!overflowTarget) {
65
+ dismiss();
66
+ return;
67
+ }
68
+ const text = content.textContent ?? "";
69
+ if (!text) {
70
+ dismiss();
71
+ return;
72
+ }
73
+ const rect = overflowTarget.getBoundingClientRect();
74
+ activeContainer = container;
75
+ activeHoverTarget = overflowTarget;
76
+ const columnTooltip = isCell && container.dataset.columnId ? resolveCellTooltipRef.current?.(container.dataset.columnId) : undefined;
77
+ setTooltip({
78
+ text,
79
+ anchorRect: rect,
80
+ pointer: { clientX: event.clientX, clientY: event.clientY },
81
+ source: isCell ? "cell" : "header",
82
+ columnId: isCell ? container.dataset.columnId : undefined,
83
+ placement: "bottom",
84
+ renderer: columnTooltip?.renderer ?? rendererRef.current,
85
+ className: columnTooltip?.className ?? classNameRef.current,
86
+ });
87
+ };
88
+ const handlePointerOut = (event) => {
89
+ if (!activeContainer || !(event.target instanceof Node) || !activeContainer.contains(event.target))
90
+ return;
91
+ if (event.relatedTarget instanceof Node && activeContainer.contains(event.relatedTarget))
92
+ return;
93
+ dismiss();
94
+ };
95
+ viewport.addEventListener("pointerover", handlePointerOver);
96
+ viewport.addEventListener("pointerout", handlePointerOut);
97
+ viewport.addEventListener("scroll", dismiss, { passive: true });
98
+ window.addEventListener("scroll", dismiss, true);
99
+ window.addEventListener("resize", dismiss);
100
+ return () => {
101
+ viewport.removeEventListener("pointerover", handlePointerOver);
102
+ viewport.removeEventListener("pointerout", handlePointerOut);
103
+ viewport.removeEventListener("scroll", dismiss);
104
+ window.removeEventListener("scroll", dismiss, true);
105
+ window.removeEventListener("resize", dismiss);
106
+ };
107
+ }, [viewportRef]);
108
+ useLayoutEffect(() => {
109
+ const element = tooltipRef.current;
110
+ if (!element || !tooltip)
111
+ return;
112
+ const rect = element.getBoundingClientRect();
113
+ const left = Math.max(8, Math.min(tooltip.anchorRect.left, window.innerWidth - rect.width - 8));
114
+ const belowTop = tooltip.anchorRect.bottom + 6;
115
+ const placement = belowTop + rect.height <= window.innerHeight - 8 ? "bottom" : "top";
116
+ const top = placement === "bottom" ? belowTop : Math.max(8, tooltip.anchorRect.top - rect.height - 6);
117
+ element.style.left = `${left}px`;
118
+ element.style.top = `${top}px`;
119
+ element.dataset.placement = placement;
120
+ const arrowX = tooltip.pointer?.clientX ?? tooltip.anchorRect.left + tooltip.anchorRect.width / 2;
121
+ element.style.setProperty("--omnigrid-tooltip-arrow-x", `${Math.max(8, Math.min(arrowX - left, rect.width - 8))}px`);
122
+ element.style.setProperty("--omnigrid-tooltip-arrow-y", placement === "bottom" ? "0px" : `${rect.height}px`);
123
+ if (tooltip.placement !== placement) {
124
+ setTooltip((current) => (current === tooltip ? { ...current, placement } : current));
125
+ }
126
+ }, [tooltip]);
127
+ if (!tooltip)
128
+ return null;
129
+ const renderContext = {
130
+ anchorRect: tooltip.anchorRect,
131
+ pointer: tooltip.pointer,
132
+ source: tooltip.source,
133
+ columnId: tooltip.columnId,
134
+ placement: tooltip.placement,
135
+ };
136
+ const content = tooltip.renderer ? tooltip.renderer(tooltip.text, renderContext) : tooltip.text;
137
+ const tooltipClassName = ["omnigrid-cell-tooltip", tooltip.className].filter(Boolean).join(" ");
138
+ return createPortal(_jsx("div", { ref: tooltipRef, className: tooltipClassName, role: "tooltip", style: { left: 0, top: 0 }, children: content }), document.body);
139
+ }
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
@@ -1,7 +1,7 @@
1
1
  import "@omnigrid/style";
2
2
  import "@omnigrid/default-theme";
3
3
  export * from "@omnigrid/core";
4
- export type { ReactCellRenderer, ReactColumnDef, ReactColumnDef as ColumnDef, ReactColumnGroupDef, ReactColumnGroupDef as ColumnGroupDef, ReactColumnLeafDef, ReactColumnLeafDef as ColumnLeafDef, ReactGridOptions, ReactGridOptions as GridOptions, } from "./reactColumnDef";
4
+ export type { CellTooltipRenderer, CellTooltipRenderContext, ReactCellRenderer, ReactColumnDef, ReactColumnDef as ColumnDef, ReactColumnGroupDef, ReactColumnGroupDef as ColumnGroupDef, ReactColumnLeafDef, ReactColumnLeafDef as ColumnLeafDef, ReactGridOptions, ReactGridOptions as GridOptions, } from "./reactColumnDef";
5
5
  export { PooledRowPane } from "./pooledRow";
6
6
  export type { ContentBridge, PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./types";
7
7
  export { OmniGrid } from "./OmniGrid";
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,
@@ -354,9 +358,17 @@ export class PooledRowPane {
354
358
  cell.appliedStyleKeys.push(key);
355
359
  }
356
360
  }
361
+ cell.element.dataset.columnId = cellInfo.column.id;
357
362
  const flushLayout = cellInfo.column.cellLayout === "flush";
358
363
  if (flushLayout)
359
364
  cell.element.style.padding = "0";
365
+ const contentElement = cell.contentElement;
366
+ contentElement.className = "omnigrid-cell-content";
367
+ contentElement.style.minWidth = "0";
368
+ contentElement.style.maxWidth = "100%";
369
+ contentElement.style.width = flushLayout ? "100%" : "";
370
+ contentElement.style.textAlign = flushLayout ? cellInfo.column.align ?? "left" : "";
371
+ contentElement.style.overflow = "hidden";
360
372
  if (cell.column?.wrapText) {
361
373
  // Wrapping cell: the text breaks into several lines and the cell
362
374
  // grows with it. The theme owns the horizontal padding and the
@@ -368,6 +380,20 @@ export class PooledRowPane {
368
380
  cell.element.style.textOverflow = "clip";
369
381
  cell.element.style.paddingBlock = flushLayout ? "0" : "4px";
370
382
  cell.element.style.alignItems = "flex-start";
383
+ contentElement.style.whiteSpace = "normal";
384
+ contentElement.style.wordBreak = "break-word";
385
+ contentElement.style.textOverflow = "clip";
386
+ const maxLines = cell.column.maxLines;
387
+ if (maxLines !== undefined && Number.isFinite(maxLines) && Math.floor(maxLines) >= 1) {
388
+ contentElement.style.display = "-webkit-box";
389
+ contentElement.style.setProperty("-webkit-box-orient", "vertical");
390
+ contentElement.style.setProperty("-webkit-line-clamp", String(Math.floor(maxLines)));
391
+ }
392
+ else {
393
+ contentElement.style.display = "";
394
+ contentElement.style.removeProperty("-webkit-box-orient");
395
+ contentElement.style.removeProperty("-webkit-line-clamp");
396
+ }
371
397
  }
372
398
  else {
373
399
  // Reset the wrapping styles: the cell may be pooled from a
@@ -377,6 +403,12 @@ export class PooledRowPane {
377
403
  cell.element.style.textOverflow = "ellipsis";
378
404
  cell.element.style.paddingBlock = flushLayout ? "0" : "";
379
405
  cell.element.style.alignItems = "";
406
+ contentElement.style.whiteSpace = "nowrap";
407
+ contentElement.style.wordBreak = "";
408
+ contentElement.style.textOverflow = "ellipsis";
409
+ contentElement.style.display = "";
410
+ contentElement.style.removeProperty("-webkit-box-orient");
411
+ contentElement.style.removeProperty("-webkit-line-clamp");
380
412
  }
381
413
  }
382
414
  applyContent(cell, content, cellInfo) {
@@ -391,7 +423,7 @@ export class PooledRowPane {
391
423
  cell.root.render(String(content));
392
424
  }
393
425
  else {
394
- cell.element.textContent = String(content);
426
+ cell.contentElement.textContent = String(content);
395
427
  }
396
428
  return;
397
429
  }
@@ -401,7 +433,7 @@ export class PooledRowPane {
401
433
  cell.root.render(contentToReactNode(content, this.bridge));
402
434
  }
403
435
  else {
404
- cell.element.innerHTML = content.html;
436
+ cell.contentElement.innerHTML = content.html;
405
437
  }
406
438
  return;
407
439
  }
@@ -418,8 +450,8 @@ export class PooledRowPane {
418
450
  if (!cell.root) {
419
451
  const placeholder = this.callbacks.renderCellPlaceholder?.(cellInfo);
420
452
  if (placeholder)
421
- cell.element.textContent = placeholder;
422
- cell.root = this.callbacks.createRoot(cell.element);
453
+ cell.contentElement.textContent = placeholder;
454
+ cell.root = this.callbacks.createRoot(cell.contentElement);
423
455
  }
424
456
  cell.root.render(contentToReactNode(content, this.bridge));
425
457
  }
@@ -450,8 +482,8 @@ export class PooledRowPane {
450
482
  // root.unmount() during another React commit causes a race warning.
451
483
  cell.root.render(null);
452
484
  }
453
- else if (cell.element.textContent !== "" || cell.element.childElementCount > 0) {
454
- cell.element.replaceChildren();
485
+ else if (cell.contentElement.textContent !== "" || cell.contentElement.childElementCount > 0) {
486
+ cell.contentElement.replaceChildren();
455
487
  }
456
488
  }
457
489
  applyRowSizing(row) {
package/dist/popup.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { PopupHostProps } from "./types";
3
+ export declare function clampPopupLeft(desiredLeft: number, popupWidth: number, minLeft: number, maxRight: number): number;
3
4
  /**
4
5
  * Renders the grid's active `UIPopupDescriptor`. Popup state lives here, so
5
6
  * opening or updating a popup never re-renders the grid body. The popup is
package/dist/popup.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { createElement, useEffect, useLayoutEffect, useRef, useState } from "react";
2
2
  import { contentToReactNode } from "./content";
3
3
  const VIEWPORT_MARGIN = 8;
4
+ export function clampPopupLeft(desiredLeft, popupWidth, minLeft, maxRight) {
5
+ const maxLeft = Math.max(minLeft, maxRight - popupWidth);
6
+ return Math.min(Math.max(desiredLeft, minLeft), maxLeft);
7
+ }
4
8
  function anchorStyle(popup) {
5
9
  const base = { position: "absolute", zIndex: 1000 };
6
10
  const anchor = popup.anchor;
@@ -49,20 +53,25 @@ export function PopupHost({ grid }) {
49
53
  document.removeEventListener("keydown", handleKeyDown);
50
54
  };
51
55
  }, [grid, isOpen, closeOnOutside, closeOnEscape]);
52
- // Keep an anchored popup inside the window: a single measurement per popup change.
56
+ // Keep an anchored popup inside both the grid and the visible window.
53
57
  useLayoutEffect(() => {
54
58
  const element = elementRef.current;
55
59
  if (!element || !popup?.anchor)
56
60
  return;
57
- const rect = element.getBoundingClientRect();
58
61
  const parent = element.parentElement;
59
- const parentRect = parent ? parent.getBoundingClientRect() : { left: 0, top: 0 };
60
- const maxLeft = Math.max(VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - rect.width);
61
- const left = Math.min(Math.max(rect.left, VIEWPORT_MARGIN), maxLeft);
62
- if (left !== rect.left) {
63
- element.style.transform = "none";
64
- element.style.left = `${left - parentRect.left}px`;
65
- }
62
+ const parentRect = parent?.getBoundingClientRect() ?? null;
63
+ const parentLeft = parentRect?.left ?? 0;
64
+ const minLeft = Math.max(VIEWPORT_MARGIN, parentLeft + VIEWPORT_MARGIN);
65
+ const maxRight = Math.min(window.innerWidth - VIEWPORT_MARGIN, (parentRect?.right ?? window.innerWidth) - VIEWPORT_MARGIN);
66
+ const availableWidth = Math.max(0, maxRight - minLeft);
67
+ element.style.maxWidth = `${availableWidth}px`;
68
+ element.style.minWidth = `${Math.min(200, availableWidth)}px`;
69
+ const rect = element.getBoundingClientRect();
70
+ const anchorLeft = parentLeft + popup.anchor.x;
71
+ const desiredLeft = popup.placement === "bottom-end" ? anchorLeft + (popup.anchor.width ?? 0) - rect.width : anchorLeft;
72
+ const left = clampPopupLeft(desiredLeft, rect.width, minLeft, maxRight);
73
+ element.style.transform = "none";
74
+ element.style.left = `${left - parentLeft}px`;
66
75
  }, [popup]);
67
76
  if (!popup)
68
77
  return null;
@@ -6,6 +6,32 @@ import type { CellRenderParams, ColumnGroupDef, ColumnLeafDef, GridOptions } fro
6
6
  * @api
7
7
  */
8
8
  export type ReactCellRenderer<T> = (params: CellRenderParams<T>) => ReactNode;
9
+ /**
10
+ * Context supplied to a custom cell or header tooltip renderer.
11
+ *
12
+ * @api
13
+ */
14
+ export interface CellTooltipRenderContext {
15
+ /** Bounds of the truncated text or header label in viewport coordinates. */
16
+ anchorRect: DOMRectReadOnly;
17
+ /** Pointer position in viewport coordinates, or `null` when unavailable. */
18
+ pointer: {
19
+ clientX: number;
20
+ clientY: number;
21
+ } | null;
22
+ /** Whether the truncated content belongs to a data cell or a header. */
23
+ source: "cell" | "header";
24
+ /** Column identifier for data cells; group headers may not have one. */
25
+ columnId?: string;
26
+ /** Side of the anchor where the tooltip is displayed after viewport collision handling. */
27
+ placement: "top" | "bottom";
28
+ }
29
+ /**
30
+ * Renders the full text of a truncated cell or header in its hover tooltip.
31
+ *
32
+ * @api
33
+ */
34
+ export type CellTooltipRenderer = (text: string, context?: CellTooltipRenderContext) => ReactNode;
9
35
  /**
10
36
  * Leaf column definition with a renderer typed for React content.
11
37
  *
@@ -14,6 +40,10 @@ export type ReactCellRenderer<T> = (params: CellRenderParams<T>) => ReactNode;
14
40
  export type ReactColumnLeafDef<T> = Omit<ColumnLeafDef<T>, "cellRenderer"> & {
15
41
  /** Replaces the default cell content with a React node. */
16
42
  cellRenderer?: ReactCellRenderer<T>;
43
+ /** Overrides the grid-level renderer for this column's truncated cell content. */
44
+ cellTooltipRenderer?: CellTooltipRenderer;
45
+ /** Overrides the grid-level class for this column's truncated cell tooltip. */
46
+ cellTooltipClassName?: string;
17
47
  };
18
48
  /**
19
49
  * Column group definition whose children use React-specific column types.
@@ -34,6 +64,7 @@ export type ReactColumnDef<T> = ReactColumnLeafDef<T> | ReactColumnGroupDef<T>;
34
64
  *
35
65
  * @api
36
66
  */
37
- export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns"> & {
67
+ export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns" | "defaultColumnDef"> & {
38
68
  columns: ReactColumnDef<T>[];
69
+ defaultColumnDef?: Partial<Omit<ReactColumnLeafDef<T>, "id" | "header">>;
39
70
  };
package/dist/types.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { SlotRenderContext, UIInputControl } from "@omnigrid/core";
3
3
  import type { CellRoot } from "./reactRoot";
4
- import type { ReactGridOptions } from "./reactColumnDef";
4
+ import type { CellTooltipRenderer, ReactGridOptions } from "./reactColumnDef";
5
+ /** Tooltip overrides resolved for a particular data column. */
6
+ export interface CellTooltipOptions {
7
+ /** Custom renderer for the truncated cell's full text. */
8
+ renderer?: CellTooltipRenderer;
9
+ /** Additional class applied to the tooltip element. */
10
+ className?: string;
11
+ }
5
12
  /**
6
13
  * Bridge between the core's headless content and native adapter values.
7
14
  * `registry` — registry of React components for `SlotComponentContent`;
@@ -91,6 +98,18 @@ export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponen
91
98
  * @default 3
92
99
  */
93
100
  minHeight?: number;
101
+ /**
102
+ * Custom renderer for the full text shown when a cell or header is truncated.
103
+ *
104
+ * @api
105
+ */
106
+ cellTooltipRenderer?: CellTooltipRenderer;
107
+ /**
108
+ * Additional class applied to truncated cell and header tooltips.
109
+ *
110
+ * @api
111
+ */
112
+ cellTooltipClassName?: string;
94
113
  slotComponents?: SlotRendererRegistry<T>;
95
114
  overlayComponents?: Record<string, import("@omnigrid/core").OverlayComponent<T>>;
96
115
  }
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.31",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",