@marimo-team/islands 0.23.10-dev2 → 0.23.10-dev20

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.
Files changed (47) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CyV83R2m.js → ConnectedDataExplorerComponent-DdeG-Hi-.js} +23 -23
  2. package/dist/{any-language-editor-DfdpyDv_.js → any-language-editor-CiES2a2h.js} +2 -2
  3. package/dist/{chat-ui-ar37brtL.js → chat-ui-BTobdMRF.js} +61 -61
  4. package/dist/{code-visibility-B88v1No3.js → code-visibility-51MFr9ZL.js} +1212 -1046
  5. package/dist/{copy-BuQpJEzp.js → copy-5jQ_kGE1.js} +32 -32
  6. package/dist/{esm-BfhQmZjp.js → esm-CCuYCd3R.js} +1 -1
  7. package/dist/{extends-BgdxCfYu.js → extends-CkydH1Q5.js} +1 -1
  8. package/dist/{glide-data-editor-BOmK9ETQ.js → glide-data-editor-CRvL2R9l.js} +7 -7
  9. package/dist/{html-to-image-Cp8O1OWB.js → html-to-image-CjsdUYrb.js} +2258 -2238
  10. package/dist/{input-_2sjvfne.js → input-DVkbXbIX.js} +183 -181
  11. package/dist/main.js +1564 -1362
  12. package/dist/{process-output-CaUUWhh8.js → process-output-CI8a-CUx.js} +2 -2
  13. package/dist/{reveal-component-CfFoUPFg.js → reveal-component-ZPJ8w6yK.js} +5 -5
  14. package/dist/{spec-B96zNUEA.js → spec-DMRQmLOc.js} +2 -2
  15. package/dist/{strings-Bu3vlb6W.js → strings-GCJA9n6d.js} +25 -24
  16. package/dist/style.css +1 -1
  17. package/dist/{useDateFormatter-BA4FCquG.js → useDateFormatter-BRcO_TGJ.js} +1 -1
  18. package/package.json +2 -2
  19. package/src/components/data-table/__tests__/data-table.test.tsx +154 -12
  20. package/src/components/data-table/hover-tooltip/__tests__/content.test.ts +60 -0
  21. package/src/components/data-table/hover-tooltip/content.ts +44 -0
  22. package/src/components/data-table/hover-tooltip/hover-tooltip.tsx +55 -0
  23. package/src/components/data-table/hover-tooltip/use-table-hover-tooltip.ts +159 -0
  24. package/src/components/data-table/renderers.tsx +27 -43
  25. package/src/components/datasources/__tests__/filter-empty.test.ts +183 -0
  26. package/src/components/datasources/datasources.tsx +92 -3
  27. package/src/components/editor/cell/cell-context-menu.tsx +15 -2
  28. package/src/components/editor/documentation.css +16 -0
  29. package/src/components/editor/file-tree/file-explorer.tsx +8 -18
  30. package/src/components/editor/file-tree/tree-actions.tsx +46 -1
  31. package/src/components/slides/__tests__/minimap-actions.test.tsx +166 -0
  32. package/src/components/slides/minimap.tsx +127 -10
  33. package/src/components/storage/__tests__/storage-inspector.test.ts +53 -0
  34. package/src/components/storage/storage-inspector.tsx +68 -48
  35. package/src/components/ui/__tests__/use-toast.test.ts +75 -0
  36. package/src/components/ui/use-toast.ts +33 -13
  37. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +0 -28
  38. package/src/core/cells/__tests__/cell.test.ts +29 -2
  39. package/src/core/cells/cell.ts +5 -1
  40. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +37 -0
  41. package/src/core/codemirror/go-to-definition/commands.ts +17 -9
  42. package/src/core/codemirror/go-to-definition/utils.ts +1 -0
  43. package/src/core/codemirror/language/languages/sql/utils.ts +3 -1
  44. package/src/core/datasets/data-source-connections.ts +2 -0
  45. package/src/core/network/__tests__/requests-static.test.ts +30 -0
  46. package/src/core/network/requests-static.ts +14 -10
  47. package/src/plugins/layout/DownloadPlugin.tsx +1 -1
@@ -1,7 +1,7 @@
1
1
  import { s as __toESM } from "./chunk-BNovOVIE.js";
2
2
  import { t as require_react } from "./react-DA-nE2FX.js";
3
3
  import { u as createLucideIcon } from "./dist-C1BYNeCR.js";
4
- import { T as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7 } from "./strings-Bu3vlb6W.js";
4
+ import { E as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7 } from "./strings-GCJA9n6d.js";
5
5
  var ChartPie = createLucideIcon("chart-pie", [["path", {
6
6
  d: "M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",
7
7
  key: "pzmjnu"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.10-dev2",
3
+ "version": "0.23.10-dev20",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -57,7 +57,7 @@
57
57
  "@marimo-team/codemirror-ai": "^0.3.7",
58
58
  "@marimo-team/codemirror-languageserver": "^1.16.12",
59
59
  "@marimo-team/codemirror-mcp": "^0.1.5",
60
- "@marimo-team/codemirror-sql": "^0.2.4",
60
+ "@marimo-team/codemirror-sql": "^0.2.8",
61
61
  "@marimo-team/llm-info": "workspace:*",
62
62
  "@marimo-team/marimo-api": "workspace:*",
63
63
  "@marimo-team/react-slotz": "^0.2.0",
@@ -5,8 +5,8 @@ import type {
5
5
  RowSelectionState,
6
6
  SortingState,
7
7
  } from "@tanstack/react-table";
8
- import { fireEvent, render, screen, within } from "@testing-library/react";
9
- import { describe, expect, it, vi } from "vitest";
8
+ import { act, fireEvent, render, screen, within } from "@testing-library/react";
9
+ import { afterEach, describe, expect, it, vi } from "vitest";
10
10
  import { TooltipProvider } from "@/components/ui/tooltip";
11
11
  import { DataTable } from "../data-table";
12
12
 
@@ -16,6 +16,12 @@ interface TestData {
16
16
  }
17
17
 
18
18
  describe("DataTable", () => {
19
+ // Restore real timers unconditionally so a failed assertion in a
20
+ // fake-timer test can't leak fake timers into later tests.
21
+ afterEach(() => {
22
+ vi.useRealTimers();
23
+ });
24
+
19
25
  it("should maintain selection state when remounted", () => {
20
26
  const mockOnRowSelectionChange = vi.fn();
21
27
  const testData: TestData[] = [
@@ -63,17 +69,15 @@ describe("DataTable", () => {
63
69
  expect(commonProps.rowSelection).toEqual(initialRowSelection);
64
70
  });
65
71
 
66
- it("applies hoverTemplate to the row title using row values", () => {
72
+ it("shows the hoverTemplate text as a styled tooltip on hover", async () => {
73
+ vi.useFakeTimers();
67
74
  interface RowData {
68
75
  id: number;
69
76
  first: string;
70
77
  last: string;
71
78
  }
72
79
 
73
- const testData: RowData[] = [
74
- { id: 1, first: "Michael", last: "Scott" },
75
- { id: 2, first: "Jim", last: "Halpert" },
76
- ];
80
+ const testData: RowData[] = [{ id: 1, first: "Michael", last: "Scott" }];
77
81
 
78
82
  const columns: ColumnDef<RowData>[] = [
79
83
  { accessorKey: "first", header: "First" },
@@ -86,7 +90,7 @@ describe("DataTable", () => {
86
90
  data={testData}
87
91
  columns={columns}
88
92
  selection={null}
89
- totalRows={2}
93
+ totalRows={1}
90
94
  totalColumns={2}
91
95
  pagination={false}
92
96
  hoverTemplate={"{{first}} {{last}}"}
@@ -94,11 +98,149 @@ describe("DataTable", () => {
94
98
  </TooltipProvider>,
95
99
  );
96
100
 
97
- // Grab all rows and assert title attribute computed from template
98
101
  const rows = screen.getAllByRole("row");
99
- // The first row is header; subsequent rows correspond to data
100
- expect(rows[1]).toHaveAttribute("title", "Michael Scott");
101
- expect(rows[2]).toHaveAttribute("title", "Jim Halpert");
102
+ // Native title is gone; hover text now comes from the styled tooltip.
103
+ expect(rows[1]).not.toHaveAttribute("title");
104
+
105
+ const cell = within(rows[1]).getAllByRole("cell")[0];
106
+ fireEvent.mouseOver(cell, { buttons: 0 });
107
+ act(() => {
108
+ vi.advanceTimersByTime(400);
109
+ });
110
+
111
+ // Radix renders the content twice (visible + a11y-hidden), so match all.
112
+ expect(screen.getAllByText("Michael Scott").length).toBeGreaterThan(0);
113
+ });
114
+
115
+ it("shows per-cell hover text from cellHoverTexts on hover", () => {
116
+ vi.useFakeTimers();
117
+ const testData: TestData[] = [{ id: 1, name: "Test 1" }];
118
+ const columns: ColumnDef<TestData>[] = [
119
+ { id: "name", accessorKey: "name", header: "Name" },
120
+ ];
121
+
122
+ render(
123
+ <TooltipProvider>
124
+ <DataTable
125
+ data={testData}
126
+ columns={columns}
127
+ selection={null}
128
+ totalRows={1}
129
+ totalColumns={1}
130
+ pagination={false}
131
+ cellHoverTexts={{ "0": { name: "per-cell tip" } }}
132
+ />
133
+ </TooltipProvider>,
134
+ );
135
+
136
+ const cell = within(screen.getAllByRole("row")[1]).getByRole("cell");
137
+ fireEvent.mouseOver(cell, { buttons: 0 });
138
+ act(() => {
139
+ vi.advanceTimersByTime(400);
140
+ });
141
+
142
+ expect(screen.getAllByText("per-cell tip").length).toBeGreaterThan(0);
143
+ });
144
+
145
+ it("links the focused cell to the tooltip content for assistive tech", () => {
146
+ const testData: TestData[] = [{ id: 1, name: "Test 1" }];
147
+ const columns: ColumnDef<TestData>[] = [
148
+ { id: "name", accessorKey: "name", header: "Name" },
149
+ ];
150
+
151
+ render(
152
+ <TooltipProvider>
153
+ <DataTable
154
+ data={testData}
155
+ columns={columns}
156
+ selection={null}
157
+ totalRows={1}
158
+ totalColumns={1}
159
+ pagination={false}
160
+ cellHoverTexts={{ "0": { name: "focus tip" } }}
161
+ />
162
+ </TooltipProvider>,
163
+ );
164
+
165
+ const cell = within(screen.getAllByRole("row")[1]).getByRole("cell");
166
+ fireEvent.focus(cell);
167
+
168
+ const describedBy = cell.getAttribute("aria-describedby");
169
+ expect(describedBy).toBeTruthy();
170
+ expect(document.getElementById(describedBy as string)).toHaveTextContent(
171
+ "focus tip",
172
+ );
173
+
174
+ fireEvent.blur(cell);
175
+ expect(cell).not.toHaveAttribute("aria-describedby");
176
+ });
177
+
178
+ it("does not show a tooltip on pointer-induced focus", () => {
179
+ const testData: TestData[] = [{ id: 1, name: "Test 1" }];
180
+ const columns: ColumnDef<TestData>[] = [
181
+ { id: "name", accessorKey: "name", header: "Name" },
182
+ ];
183
+
184
+ render(
185
+ <TooltipProvider>
186
+ <DataTable
187
+ data={testData}
188
+ columns={columns}
189
+ selection={null}
190
+ totalRows={1}
191
+ totalColumns={1}
192
+ pagination={false}
193
+ cellHoverTexts={{ "0": { name: "click tip" } }}
194
+ />
195
+ </TooltipProvider>,
196
+ );
197
+
198
+ const cell = within(screen.getAllByRole("row")[1]).getByRole("cell");
199
+ // A click focuses the cell; the resulting focus must not show a tooltip.
200
+ fireEvent.mouseDown(cell);
201
+ fireEvent.focus(cell);
202
+
203
+ expect(cell).not.toHaveAttribute("aria-describedby");
204
+ expect(screen.queryByText("click tip")).toBeNull();
205
+ });
206
+
207
+ it("does not let a pending hover timer overwrite a focus tooltip", () => {
208
+ vi.useFakeTimers();
209
+ interface RowData {
210
+ id: number;
211
+ a: string;
212
+ b: string;
213
+ }
214
+ const testData: RowData[] = [{ id: 1, a: "a", b: "b" }];
215
+ const columns: ColumnDef<RowData>[] = [
216
+ { id: "a", accessorKey: "a", header: "A" },
217
+ { id: "b", accessorKey: "b", header: "B" },
218
+ ];
219
+
220
+ render(
221
+ <TooltipProvider>
222
+ <DataTable
223
+ data={testData}
224
+ columns={columns}
225
+ selection={null}
226
+ totalRows={1}
227
+ totalColumns={2}
228
+ pagination={false}
229
+ cellHoverTexts={{ "0": { a: "hover A", b: "focus B" } }}
230
+ />
231
+ </TooltipProvider>,
232
+ );
233
+
234
+ const cells = within(screen.getAllByRole("row")[1]).getAllByRole("cell");
235
+ // Start a pending hover-show on cell A, then focus cell B before it fires.
236
+ fireEvent.mouseOver(cells[0], { buttons: 0 });
237
+ fireEvent.focus(cells[1]);
238
+ act(() => {
239
+ vi.advanceTimersByTime(400);
240
+ });
241
+
242
+ expect(screen.getAllByText("focus B").length).toBeGreaterThan(0);
243
+ expect(screen.queryByText("hover A")).toBeNull();
102
244
  });
103
245
 
104
246
  it("does not virtualize small datasets without pagination", () => {
@@ -0,0 +1,60 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { Cell } from "@tanstack/react-table";
3
+ import { describe, expect, it } from "vitest";
4
+ import { applyHoverTemplate, computeCellTooltipContent } from "../content";
5
+
6
+ function fakeCell(columnId: string, value: unknown, hoverTitle?: string) {
7
+ return {
8
+ column: { id: columnId },
9
+ getValue: () => value,
10
+ getHoverTitle: () => hoverTitle,
11
+ } as unknown as Cell<unknown, unknown>;
12
+ }
13
+
14
+ describe("applyHoverTemplate", () => {
15
+ it("substitutes column placeholders", () => {
16
+ const cells = [fakeCell("first", "Michael"), fakeCell("last", "Scott")];
17
+ expect(applyHoverTemplate("{{first}} {{last}}", cells)).toBe(
18
+ "Michael Scott",
19
+ );
20
+ });
21
+
22
+ it("renders nulls as empty strings", () => {
23
+ const cells = [fakeCell("a", null)];
24
+ expect(applyHoverTemplate("[{{a}}]", cells)).toBe("[]");
25
+ });
26
+
27
+ it("leaves unknown placeholders intact", () => {
28
+ expect(applyHoverTemplate("{{missing}}", [fakeCell("a", 1)])).toBe(
29
+ "{{missing}}",
30
+ );
31
+ });
32
+ });
33
+
34
+ describe("computeCellTooltipContent", () => {
35
+ it("prefers cell-level hover title", () => {
36
+ const cell = fakeCell("a", 1, "cell text");
37
+ expect(computeCellTooltipContent(cell, "{{a}}")).toBe("cell text");
38
+ });
39
+
40
+ it("falls back to row template when no cell title", () => {
41
+ const cell = {
42
+ column: { id: "first" },
43
+ getValue: () => "X",
44
+ getHoverTitle: () => undefined,
45
+ row: {
46
+ getVisibleCells: () => [
47
+ fakeCell("first", "Jim"),
48
+ fakeCell("last", "Halpert"),
49
+ ],
50
+ },
51
+ } as unknown as Cell<unknown, unknown>;
52
+ expect(computeCellTooltipContent(cell, "{{first}} {{last}}")).toBe(
53
+ "Jim Halpert",
54
+ );
55
+ });
56
+
57
+ it("returns undefined with no title and no template", () => {
58
+ expect(computeCellTooltipContent(fakeCell("a", 1), null)).toBeUndefined();
59
+ });
60
+ });
@@ -0,0 +1,44 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { Cell, RowData } from "@tanstack/react-table";
3
+ import type { ReactNode } from "react";
4
+ import { stringifyUnknownValue } from "../utils";
5
+
6
+ export function applyHoverTemplate<TData extends RowData>(
7
+ template: string,
8
+ cells: Cell<TData, unknown>[],
9
+ ): string {
10
+ const variableRegex = /{{(\w+)}}/g;
11
+ const idToValue = new Map<string, string>();
12
+ for (const c of cells) {
13
+ const s = stringifyUnknownValue({
14
+ value: c.getValue(),
15
+ nullAsEmptyString: true,
16
+ });
17
+ idToValue.set(c.column.id, s);
18
+ }
19
+ return template.replaceAll(variableRegex, (_substr, varName: string) => {
20
+ const val = idToValue.get(varName);
21
+ return val === undefined ? `{{${varName}}}` : val;
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Resolve the tooltip content for a hovered cell.
27
+ *
28
+ * Cell-level (callable `hover_template`) takes precedence; otherwise the
29
+ * row-level string template is rendered against the row's visible cells.
30
+ * Returns `undefined` when there is nothing to show.
31
+ */
32
+ export function computeCellTooltipContent<TData extends RowData>(
33
+ cell: Cell<TData, unknown>,
34
+ hoverTemplate: string | null,
35
+ ): ReactNode {
36
+ const cellTitle = cell.getHoverTitle?.();
37
+ if (cellTitle != null && cellTitle !== "") {
38
+ return cellTitle;
39
+ }
40
+ if (hoverTemplate) {
41
+ return applyHoverTemplate(hoverTemplate, cell.row.getVisibleCells());
42
+ }
43
+ return undefined;
44
+ }
@@ -0,0 +1,55 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import {
3
+ TooltipContent,
4
+ TooltipPortal,
5
+ TooltipRoot,
6
+ TooltipTrigger,
7
+ } from "@/components/ui/tooltip";
8
+ import type { HoverTooltipState } from "./use-table-hover-tooltip";
9
+
10
+ interface HoverTooltipProps {
11
+ state: HoverTooltipState | null;
12
+ contentId: string;
13
+ onClose: () => void;
14
+ }
15
+
16
+ /**
17
+ * A single radix tooltip whose anchor is repositioned to the hovered cell.
18
+ * Rendering one instance per table (instead of one per cell) keeps the cost
19
+ * constant regardless of how many cells are on screen.
20
+ */
21
+ export const HoverTooltip = ({
22
+ state,
23
+ contentId,
24
+ onClose,
25
+ }: HoverTooltipProps) => {
26
+ return (
27
+ <TooltipRoot
28
+ open={state != null}
29
+ onOpenChange={(open) => {
30
+ if (!open) {
31
+ onClose();
32
+ }
33
+ }}
34
+ delayDuration={0}
35
+ disableHoverableContent={true}
36
+ >
37
+ <TooltipTrigger asChild={true}>
38
+ <div
39
+ aria-hidden={true}
40
+ style={{
41
+ position: "fixed",
42
+ top: state?.rect.top ?? 0,
43
+ left: state?.rect.left ?? 0,
44
+ width: state?.rect.width ?? 0,
45
+ height: state?.rect.height ?? 0,
46
+ pointerEvents: "none",
47
+ }}
48
+ />
49
+ </TooltipTrigger>
50
+ <TooltipPortal>
51
+ <TooltipContent id={contentId}>{state?.content}</TooltipContent>
52
+ </TooltipPortal>
53
+ </TooltipRoot>
54
+ );
55
+ };
@@ -0,0 +1,159 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { Cell, RowData, Table } from "@tanstack/react-table";
3
+ import {
4
+ type ReactNode,
5
+ useEffect,
6
+ useId,
7
+ useLayoutEffect,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+ import useEvent from "react-use-event-hook";
12
+ import { computeCellTooltipContent } from "./content";
13
+
14
+ // Matches the default TooltipProvider delay (MarimoApp.tsx) for visual parity
15
+ // with the rest of the app's tooltips.
16
+ const TOOLTIP_DELAY_MS = 400;
17
+
18
+ export interface HoverTooltipState {
19
+ rect: { top: number; left: number; width: number; height: number };
20
+ content: ReactNode;
21
+ }
22
+
23
+ export function useTableHoverTooltip<TData extends RowData>({
24
+ table,
25
+ }: {
26
+ table: Table<TData>;
27
+ }) {
28
+ const hoverTemplate = table.getState().cellHoverTemplate || null;
29
+ const [tooltipState, setTooltipState] = useState<HoverTooltipState | null>(
30
+ null,
31
+ );
32
+ const timer = useRef<number | null>(null);
33
+
34
+ // Stable id linking the focused/hovered cell to the tooltip content for
35
+ // assistive tech (the radix trigger is an aria-hidden phantom anchor).
36
+ const tooltipContentId = useId();
37
+ const anchorCell = useRef<HTMLElement | null>(null);
38
+ // Focus fires for pointer interactions too; track pointer state so
39
+ // click/drag-select focus doesn't show a tooltip (keyboard focus still does).
40
+ const pointerDown = useRef(false);
41
+
42
+ const clearTimer = () => {
43
+ if (timer.current != null) {
44
+ clearTimeout(timer.current);
45
+ timer.current = null;
46
+ }
47
+ };
48
+
49
+ const hideTooltip = useEvent(() => {
50
+ clearTimer();
51
+ setTooltipState(null);
52
+ });
53
+
54
+ const showFor = (target: HTMLElement, content: ReactNode) => {
55
+ anchorCell.current = target;
56
+ const r = target.getBoundingClientRect();
57
+ setTooltipState({
58
+ rect: { top: r.top, left: r.left, width: r.width, height: r.height },
59
+ content,
60
+ });
61
+ };
62
+
63
+ // Point the real cell at the tooltip content while it is shown. Done in a
64
+ // layout effect (after commit) so React's re-render from `setTooltipState`
65
+ // can't clobber an imperatively set attribute; cleanup unlinks the previous
66
+ // cell.
67
+ useLayoutEffect(() => {
68
+ if (!tooltipState) {
69
+ return;
70
+ }
71
+ const cell = anchorCell.current;
72
+ cell?.setAttribute("aria-describedby", tooltipContentId);
73
+ return () => cell?.removeAttribute("aria-describedby");
74
+ }, [tooltipState, tooltipContentId]);
75
+
76
+ useEffect(() => {
77
+ const onDown = () => {
78
+ pointerDown.current = true;
79
+ };
80
+ const onUp = () => {
81
+ pointerDown.current = false;
82
+ };
83
+ window.addEventListener("mousedown", onDown, { capture: true });
84
+ window.addEventListener("mouseup", onUp, { capture: true });
85
+ return () => {
86
+ window.removeEventListener("mousedown", onDown, { capture: true });
87
+ window.removeEventListener("mouseup", onUp, { capture: true });
88
+ };
89
+ }, []);
90
+
91
+ const handleCellMouseOver = useEvent(
92
+ (e: React.MouseEvent, cell: Cell<TData, unknown>) => {
93
+ // Suppress while a mouse button is held (range-select drag).
94
+ if (e.buttons !== 0) {
95
+ return;
96
+ }
97
+ const target = e.currentTarget as HTMLElement;
98
+ const content = computeCellTooltipContent(cell, hoverTemplate);
99
+ if (content == null || content === "") {
100
+ hideTooltip();
101
+ return;
102
+ }
103
+ clearTimer();
104
+ timer.current = window.setTimeout(
105
+ () => showFor(target, content),
106
+ TOOLTIP_DELAY_MS,
107
+ );
108
+ },
109
+ );
110
+
111
+ const handleCellMouseLeave = useEvent(() => hideTooltip());
112
+
113
+ // Keyboard parity: cells are tabIndex=0, native `title` showed on focus too.
114
+ const handleCellFocus = useEvent(
115
+ (e: React.FocusEvent, cell: Cell<TData, unknown>) => {
116
+ // Cancel any pending hover-show so a stale timer can't overwrite the
117
+ // focus-triggered tooltip after the delay.
118
+ clearTimer();
119
+ // Focus also fires for click/drag-select; only keyboard focus (no pointer
120
+ // held) should show the tooltip, mirroring the hover drag suppression.
121
+ if (pointerDown.current) {
122
+ return;
123
+ }
124
+ const content = computeCellTooltipContent(cell, hoverTemplate);
125
+ if (content == null || content === "") {
126
+ return;
127
+ }
128
+ showFor(e.currentTarget as HTMLElement, content);
129
+ },
130
+ );
131
+
132
+ const handleCellBlur = useEvent(() => hideTooltip());
133
+
134
+ // The anchor rect is captured at hover time, so any scroll or resize leaves
135
+ // it stale; hide instead of tracking. Capture catches scrolls inside the
136
+ // table's own container too (scroll events don't bubble but do fire in
137
+ // capture).
138
+ useEffect(() => {
139
+ const opts = { passive: true, capture: true } as const;
140
+ window.addEventListener("scroll", hideTooltip, opts);
141
+ window.addEventListener("resize", hideTooltip);
142
+ return () => {
143
+ window.removeEventListener("scroll", hideTooltip, { capture: true });
144
+ window.removeEventListener("resize", hideTooltip);
145
+ };
146
+ }, [hideTooltip]);
147
+
148
+ useEffect(() => clearTimer, []);
149
+
150
+ return {
151
+ tooltipState,
152
+ tooltipContentId,
153
+ hideTooltip,
154
+ handleCellMouseOver,
155
+ handleCellMouseLeave,
156
+ handleCellFocus,
157
+ handleCellBlur,
158
+ };
159
+ }
@@ -24,11 +24,12 @@ import { cn } from "@/utils/cn";
24
24
  import { getCellDomProps } from "./cell-utils";
25
25
  import { COLUMN_WRAPPING_STYLES } from "./column-wrapping/feature";
26
26
  import { DataTableContextMenu } from "./context-menu";
27
+ import { HoverTooltip } from "./hover-tooltip/hover-tooltip";
28
+ import { useTableHoverTooltip } from "./hover-tooltip/use-table-hover-tooltip";
27
29
  import { CellRangeSelectionIndicator } from "./range-focus/cell-selection-indicator";
28
30
  import { useCellRangeSelection } from "./range-focus/use-cell-range-selection";
29
31
  import { useScrollIntoViewOnFocus } from "./range-focus/use-scroll-into-view";
30
32
  import { AUTO_WIDTH_MAX_COLUMNS, TABLE_ROW_HEIGHT_PX } from "./types";
31
- import { stringifyUnknownValue } from "./utils";
32
33
 
33
34
  export function renderTableHeader<TData>(
34
35
  table: Table<TData>,
@@ -135,24 +136,7 @@ export const DataTableBody = <TData,>({
135
136
  contextMenuCell.current = cell;
136
137
  });
137
138
 
138
- function applyHoverTemplate(
139
- template: string,
140
- cells: Cell<TData, unknown>[],
141
- ): string {
142
- const variableRegex = /{{(\w+)}}/g;
143
- // Map column id -> stringified value
144
- const idToValue = new Map<string, string>();
145
- for (const c of cells) {
146
- const v = c.getValue();
147
- // Prefer empty string for nulls to keep tooltip clean
148
- const s = stringifyUnknownValue({ value: v, nullAsEmptyString: true });
149
- idToValue.set(c.column.id, s);
150
- }
151
- return template.replaceAll(variableRegex, (_substr, varName: string) => {
152
- const val = idToValue.get(varName);
153
- return val === undefined ? `{{${varName}}}` : val;
154
- });
155
- }
139
+ const hoverTooltip = useTableHoverTooltip({ table });
156
140
 
157
141
  const renderCells = (cells: Cell<TData, unknown>[]) => {
158
142
  return cells.map((cell) => {
@@ -163,7 +147,6 @@ export const DataTableBody = <TData,>({
163
147
  pinningstyle,
164
148
  );
165
149
 
166
- const title = cell.getHoverTitle?.() ?? undefined;
167
150
  return (
168
151
  <TableCell
169
152
  tabIndex={0}
@@ -178,10 +161,18 @@ export const DataTableBody = <TData,>({
178
161
  className,
179
162
  )}
180
163
  style={style}
181
- title={title}
182
- onMouseDown={(e) => handleCellMouseDown(e, cell)}
164
+ onMouseDown={(e) => {
165
+ handleCellMouseDown(e, cell);
166
+ hoverTooltip.hideTooltip();
167
+ }}
183
168
  onMouseUp={handleCellMouseUp}
184
- onMouseOver={(e) => handleCellMouseOver(e, cell)}
169
+ onMouseOver={(e) => {
170
+ handleCellMouseOver(e, cell);
171
+ hoverTooltip.handleCellMouseOver(e, cell);
172
+ }}
173
+ onMouseLeave={hoverTooltip.handleCellMouseLeave}
174
+ onFocus={(e) => hoverTooltip.handleCellFocus(e, cell)}
175
+ onBlur={hoverTooltip.handleCellBlur}
185
176
  onContextMenu={() => handleContextMenu(cell)}
186
177
  >
187
178
  <CellRangeSelectionIndicator cellId={cell.id} />
@@ -200,8 +191,6 @@ export const DataTableBody = <TData,>({
200
191
  }
201
192
  };
202
193
 
203
- const hoverTemplate = table.getState().cellHoverTemplate || null;
204
-
205
194
  const renderRow = (row: Row<TData>) => {
206
195
  // Only find the row index if the row viewer panel is open
207
196
  const rowIndex = rowViewerPanelOpen
@@ -209,22 +198,10 @@ export const DataTableBody = <TData,>({
209
198
  : undefined;
210
199
  const isRowViewedInPanel = rowViewerPanelOpen && viewedRowIdx === rowIndex;
211
200
 
212
- // Compute hover title once per row using all visible cells
213
- let rowTitle: string | undefined;
214
- if (hoverTemplate) {
215
- const visibleCells = row.getVisibleCells?.() ?? [
216
- ...row.getLeftVisibleCells(),
217
- ...row.getCenterVisibleCells(),
218
- ...row.getRightVisibleCells(),
219
- ];
220
- rowTitle = applyHoverTemplate(hoverTemplate, visibleCells);
221
- }
222
-
223
201
  return (
224
202
  <TableRow
225
203
  key={row.id}
226
204
  data-state={row.getIsSelected() && "selected"}
227
- title={rowTitle}
228
205
  // These classes ensure that empty rows (nulls) still render
229
206
  className={cn(
230
207
  "border-t h-6",
@@ -296,12 +273,19 @@ export const DataTableBody = <TData,>({
296
273
  );
297
274
 
298
275
  return (
299
- <DataTableContextMenu
300
- tableBody={tableBody}
301
- contextMenuRef={contextMenuCell}
302
- tableRef={tableRef}
303
- copyAllCells={handleCopyAllCells}
304
- />
276
+ <>
277
+ <DataTableContextMenu
278
+ tableBody={tableBody}
279
+ contextMenuRef={contextMenuCell}
280
+ tableRef={tableRef}
281
+ copyAllCells={handleCopyAllCells}
282
+ />
283
+ <HoverTooltip
284
+ state={hoverTooltip.tooltipState}
285
+ contentId={hoverTooltip.tooltipContentId}
286
+ onClose={hoverTooltip.hideTooltip}
287
+ />
288
+ </>
305
289
  );
306
290
  };
307
291