@marimo-team/islands 0.26.1-dev108 → 0.26.1-dev112

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 (38) hide show
  1. package/dist/{ErrorBoundary-BW4TciqU.js → ErrorBoundary-pNKOBKXw.js} +1 -1
  2. package/dist/{chat-ui-Be9X-W22.js → chat-ui-C9NZA-bk.js} +3 -3
  3. package/dist/{code-visibility-BKmktPMd.js → code-visibility-B9s3Hl8z.js} +2 -2
  4. package/dist/{common-CSJAjJGa.js → common-Bn3jx0X6.js} +6 -4
  5. package/dist/{data-grid-overlay-editor-DTibdR4H.js → data-grid-overlay-editor-mxwwRaQy.js} +1 -1
  6. package/dist/{error-entries-23Z_1oDM.js → error-entries-1DC4BiYB.js} +166 -155
  7. package/dist/{feedback-button-CPu5SV3b.js → feedback-button-BrzbnRTT.js} +3 -3
  8. package/dist/{glide-data-editor-CC9_NDNi.js → glide-data-editor-Cnsv3NcI.js} +3 -3
  9. package/dist/{globals-BFlYTNoR.js → globals-BGqfFPx8.js} +1 -1
  10. package/dist/{html-to-image-Cw7o1IbE.js → html-to-image-CsvAOgd3.js} +1 -1
  11. package/dist/main.js +10 -10
  12. package/dist/{number-overlay-editor-qDcRKPE0.js → number-overlay-editor-DuSCOMTK.js} +1 -1
  13. package/dist/{process-output-DdBM0lmd.js → process-output-CtfJ_Gbp.js} +2 -2
  14. package/dist/{reveal-component-BE1xhtNc.js → reveal-component-DzmiQyN9.js} +2 -2
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/components/editor/__tests__/cell-renders.test.tsx +327 -1
  18. package/src/components/editor/ai/__tests__/completion-utils.test.ts +12 -20
  19. package/src/components/editor/ai/ai-completion-editor.tsx +391 -289
  20. package/src/components/editor/ai/completion-utils.ts +9 -7
  21. package/src/components/editor/cell/CellDeleteShoulder.tsx +82 -0
  22. package/src/components/editor/cell/DeleteButton.tsx +11 -2
  23. package/src/components/editor/cell/__tests__/CellDeleteShoulder.test.tsx +181 -0
  24. package/src/components/editor/cell/code/cell-editor.tsx +15 -25
  25. package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +26 -2
  26. package/src/components/editor/chrome/panels/logs-panel.tsx +27 -11
  27. package/src/components/editor/notebook-cell.tsx +20 -40
  28. package/src/core/ai/state.ts +6 -0
  29. package/src/core/cells/__tests__/cells.test.ts +34 -20
  30. package/src/core/cells/cell-log-chunks.ts +31 -0
  31. package/src/core/cells/cells.ts +10 -6
  32. package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +1 -1
  33. package/src/core/codemirror/lsp/__tests__/transports.test.ts +1 -1
  34. package/src/core/islands/__tests__/bridge.test.ts +2 -5
  35. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +10 -1
  36. package/src/css/common.css +11 -0
  37. package/src/hooks/useFinePointer.ts +30 -0
  38. package/src/stories/log-viewer.stories.tsx +48 -44
@@ -17,10 +17,6 @@ import { Logger } from "@/utils/Logger";
17
17
 
18
18
  export const CONTEXT_TRIGGER = "@";
19
19
 
20
- interface Opts {
21
- input: string;
22
- }
23
-
24
20
  interface AICompletionBodyWithAttachments {
25
21
  body: Omit<AiCompletionRequest, "language" | "prompt" | "code">;
26
22
  attachments: FileUIPart[];
@@ -31,7 +27,11 @@ interface AICompletionBodyWithAttachments {
31
27
  */
32
28
  export function getAICompletionBody({
33
29
  input,
34
- }: Opts): Omit<AiCompletionRequest, "language" | "prompt" | "code"> {
30
+ includeOtherCode,
31
+ }: {
32
+ input: string;
33
+ includeOtherCode: string;
34
+ }): Omit<AiCompletionRequest, "language" | "prompt" | "code"> {
35
35
  let contextString = "";
36
36
 
37
37
  // Skip if no '@' in the input
@@ -41,7 +41,7 @@ export function getAICompletionBody({
41
41
  }
42
42
 
43
43
  return {
44
- includeOtherCode: getCodes(""),
44
+ includeOtherCode,
45
45
  context: {
46
46
  plainText: contextString,
47
47
  schema: [],
@@ -175,7 +175,9 @@ export async function resolveChatContext(
175
175
  */
176
176
  export async function getAICompletionBodyWithAttachments({
177
177
  input,
178
- }: Opts): Promise<AICompletionBodyWithAttachments> {
178
+ }: {
179
+ input: string;
180
+ }): Promise<AICompletionBodyWithAttachments> {
179
181
  const { plainText, attachments } = await resolveContextAttachments(input);
180
182
 
181
183
  return {
@@ -0,0 +1,82 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { atom, useSetAtom } from "jotai";
4
+ import { useMemo } from "react";
5
+ import { cellFocusAtom } from "@/core/cells/focus";
6
+ import { outputIsLoading } from "@/core/cells/cell";
7
+ import type { CellId } from "@/core/cells/ids";
8
+ import type { CellRunStatus } from "@/core/executions";
9
+ import { isAppInteractionDisabled } from "@/core/session/connection-utils";
10
+ import { createKeyedAtomHook } from "@/core/state/create-keyed-atom-hook";
11
+ import type { ConnectionState } from "@/core/session/types";
12
+ import { useFinePointer } from "@/hooks/useFinePointer";
13
+ import { DeleteButton } from "./DeleteButton";
14
+ import { useDeleteCellCallback } from "./useDeleteCell";
15
+
16
+ const hoveredCellIdAtom = atom<CellId | null>(null);
17
+
18
+ /**
19
+ * Pointer handlers for a cell root. React delegates these events, so cells
20
+ * add no native listeners, and only the hovered cell's shoulder re-renders.
21
+ */
22
+ export function useCellHoverProps(cellId: CellId) {
23
+ const setHoveredCellId = useSetAtom(hoveredCellIdAtom);
24
+ return useMemo(
25
+ () => ({
26
+ onPointerEnter: () => setHoveredCellId(cellId),
27
+ onPointerLeave: () =>
28
+ setHoveredCellId((current) => (current === cellId ? null : current)),
29
+ }),
30
+ [cellId, setHoveredCellId],
31
+ );
32
+ }
33
+
34
+ const useIsCellActive = createKeyedAtomHook((cellId: CellId) =>
35
+ atom(
36
+ (get) =>
37
+ get(hoveredCellIdAtom) === cellId ||
38
+ get(cellFocusAtom).focusedCellId === cellId,
39
+ ),
40
+ );
41
+
42
+ /**
43
+ * The delete control at the bottom corner of a cell.
44
+ *
45
+ * The wrapper always renders, so layout and the hit area stay the same.
46
+ * With a fine pointer, the button mounts only while the cell is hovered or
47
+ * holds focus. Coarse pointers show the button at all times.
48
+ */
49
+ export const CellDeleteShoulder = ({
50
+ cellId,
51
+ status,
52
+ connectionState,
53
+ showButton,
54
+ }: {
55
+ cellId: CellId;
56
+ status: CellRunStatus;
57
+ connectionState: ConnectionState;
58
+ showButton: boolean;
59
+ }) => {
60
+ const deleteCell = useDeleteCellCallback();
61
+ const isFinePointer = useFinePointer();
62
+ const isActive = useIsCellActive(cellId);
63
+
64
+ return (
65
+ <div className="shoulder-bottom hover-action">
66
+ {showButton && (isActive || !isFinePointer) && (
67
+ <DeleteButton
68
+ status={status}
69
+ connectionState={connectionState}
70
+ onClick={() => {
71
+ if (
72
+ !outputIsLoading(status) &&
73
+ !isAppInteractionDisabled(connectionState)
74
+ ) {
75
+ deleteCell({ cellId });
76
+ }
77
+ }}
78
+ />
79
+ )}
80
+ </div>
81
+ );
82
+ };
@@ -46,11 +46,20 @@ export const DeleteButton = (props: {
46
46
  // This is needed to delete cells when the cell editor
47
47
  // is shown temporarily (e.g. when set to `hidden`)
48
48
  onMouseDown={Events.preventFocus}
49
+ onKeyDown={(evt) => {
50
+ // Keep native Enter/Space activation from reaching cell navigation.
51
+ if (
52
+ !Events.hasModifier(evt) &&
53
+ (evt.key === "Enter" || evt.key === " ")
54
+ ) {
55
+ evt.stopPropagation();
56
+ }
57
+ }}
49
58
  className={cn(
50
- "hover:bg-transparent text-destructive/60 hover:text-destructive",
59
+ // shadow-none keeps the focus ring, which an inline boxShadow removes.
60
+ "shadow-none hover:bg-transparent text-destructive/60 hover:text-destructive",
51
61
  (isDisabled || loading) && "inactive-button",
52
62
  )}
53
- style={{ boxShadow: "none" }}
54
63
  >
55
64
  <Trash2Icon size={14} />
56
65
  </Button>
@@ -0,0 +1,181 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { act, fireEvent, render, screen } from "@testing-library/react";
4
+ import { createStore, Provider } from "jotai";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { cellFocusAtom } from "@/core/cells/focus";
7
+ import type { CellId } from "@/core/cells/ids";
8
+ import type { ConnectionState } from "@/core/session/types";
9
+ import { TooltipProvider } from "@/components/ui/tooltip";
10
+ import { CellDeleteShoulder, useCellHoverProps } from "../CellDeleteShoulder";
11
+
12
+ const deleteCell = vi.fn();
13
+ vi.mock("../useDeleteCell", () => ({
14
+ useDeleteCellCallback: () => deleteCell,
15
+ }));
16
+
17
+ const FINE_QUERY = "(hover: hover) and (pointer: fine)";
18
+
19
+ let finePointer = true;
20
+ const listeners = new Set<() => void>();
21
+
22
+ function setFinePointer(value: boolean) {
23
+ finePointer = value;
24
+ act(() => {
25
+ for (const listener of listeners) {
26
+ listener();
27
+ }
28
+ });
29
+ }
30
+
31
+ const CELL_A = "a" as CellId;
32
+ const CELL_B = "b" as CellId;
33
+
34
+ function Cell(props: {
35
+ cellId: CellId;
36
+ status?: "idle" | "running";
37
+ connectionState?: ConnectionState;
38
+ showButton?: boolean;
39
+ onKeyDown?: () => void;
40
+ }) {
41
+ const hoverProps = useCellHoverProps(props.cellId);
42
+ return (
43
+ <TooltipProvider>
44
+ <div
45
+ data-testid={`cell-${props.cellId}`}
46
+ onKeyDown={props.onKeyDown}
47
+ {...hoverProps}
48
+ >
49
+ <CellDeleteShoulder
50
+ cellId={props.cellId}
51
+ status={props.status ?? "idle"}
52
+ connectionState={props.connectionState ?? "OPEN"}
53
+ showButton={props.showButton ?? true}
54
+ />
55
+ </div>
56
+ </TooltipProvider>
57
+ );
58
+ }
59
+
60
+ function renderCells(cells = [CELL_A, CELL_B], store = createStore()) {
61
+ render(
62
+ <Provider store={store}>
63
+ {cells.map((id) => (
64
+ <Cell key={id} cellId={id} />
65
+ ))}
66
+ </Provider>,
67
+ );
68
+ return store;
69
+ }
70
+
71
+ describe("CellDeleteShoulder", () => {
72
+ beforeEach(() => {
73
+ finePointer = true;
74
+ listeners.clear();
75
+ deleteCell.mockClear();
76
+ vi.stubGlobal("matchMedia", (query: string) => ({
77
+ get matches() {
78
+ return query === FINE_QUERY && finePointer;
79
+ },
80
+ addEventListener: (_: string, cb: () => void) => listeners.add(cb),
81
+ removeEventListener: (_: string, cb: () => void) => listeners.delete(cb),
82
+ }));
83
+ });
84
+
85
+ afterEach(() => {
86
+ vi.unstubAllGlobals();
87
+ });
88
+
89
+ it("mounts no delete button while idle with a fine pointer", () => {
90
+ renderCells();
91
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
92
+ });
93
+
94
+ it("mounts the button only in the hovered cell", () => {
95
+ renderCells();
96
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
97
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(1);
98
+ expect(
99
+ screen.getByTestId("cell-a").querySelector("[data-testid=delete-button]"),
100
+ ).not.toBeNull();
101
+
102
+ fireEvent.pointerLeave(screen.getByTestId("cell-a"));
103
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
104
+ });
105
+
106
+ it("keeps the button mounted while the cell holds focus", () => {
107
+ const store = renderCells();
108
+ act(() => {
109
+ store.set(cellFocusAtom, {
110
+ focusedCellId: CELL_B,
111
+ lastFocusedCellId: CELL_B,
112
+ });
113
+ });
114
+ expect(
115
+ screen.getByTestId("cell-b").querySelector("[data-testid=delete-button]"),
116
+ ).not.toBeNull();
117
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(1);
118
+ });
119
+
120
+ it("does not mount the button when it is not allowed", () => {
121
+ render(<Cell cellId={CELL_A} showButton={false} />);
122
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
123
+ expect(screen.queryByTestId("delete-button")).toBeNull();
124
+ });
125
+
126
+ it("always mounts the button for coarse pointers", () => {
127
+ finePointer = false;
128
+ renderCells();
129
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(2);
130
+ });
131
+
132
+ it("follows pointer capability changes", () => {
133
+ renderCells();
134
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
135
+ setFinePointer(false);
136
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(2);
137
+ setFinePointer(true);
138
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
139
+ });
140
+
141
+ it("uses one media query listener for many cells", () => {
142
+ renderCells([CELL_A, CELL_B, "c" as CellId, "d" as CellId]);
143
+ expect(listeners.size).toBe(1);
144
+ });
145
+
146
+ it("deletes the cell on click", () => {
147
+ renderCells();
148
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
149
+ fireEvent.click(screen.getByTestId("delete-button"));
150
+ expect(deleteCell).toHaveBeenCalledWith({ cellId: CELL_A });
151
+ });
152
+
153
+ it("does not delete a running cell", () => {
154
+ render(<Cell cellId={CELL_A} status="running" />);
155
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
156
+ fireEvent.click(screen.getByTestId("delete-button"));
157
+ expect(deleteCell).not.toHaveBeenCalled();
158
+ });
159
+
160
+ it("does not delete while the connection is closed", () => {
161
+ render(<Cell cellId={CELL_A} connectionState="CLOSED" />);
162
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
163
+ fireEvent.click(screen.getByTestId("delete-button"));
164
+ expect(deleteCell).not.toHaveBeenCalled();
165
+ });
166
+
167
+ it("keeps Enter and Space from reaching cell navigation", () => {
168
+ const onKeyDown = vi.fn();
169
+ render(<Cell cellId={CELL_A} onKeyDown={onKeyDown} />);
170
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
171
+ const button = screen.getByTestId("delete-button");
172
+
173
+ fireEvent.keyDown(button, { key: "Enter" });
174
+ fireEvent.keyDown(button, { key: " " });
175
+ expect(onKeyDown).not.toHaveBeenCalled();
176
+
177
+ fireEvent.keyDown(button, { key: "Enter", metaKey: true });
178
+ fireEvent.keyDown(button, { key: "ArrowDown" });
179
+ expect(onKeyDown).toHaveBeenCalledTimes(2);
180
+ });
181
+ });
@@ -2,10 +2,10 @@
2
2
  import { historyField } from "@codemirror/commands";
3
3
  import { EditorState, type Extension, StateEffect } from "@codemirror/state";
4
4
  import { EditorView, ViewPlugin } from "@codemirror/view";
5
- import { useAtom, useAtomValue, useSetAtom } from "jotai";
5
+ import { useAtomValue, useSetAtom } from "jotai";
6
6
  import React, { memo, useEffect, useMemo, useRef } from "react";
7
7
  import useEvent from "react-use-event-hook";
8
- import { aiCompletionCellAtom } from "@/core/ai/state";
8
+ import { aiCompletionCellAtom, useAiCompletionCell } from "@/core/ai/state";
9
9
  import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
10
10
  import { useCellActions } from "@/core/cells/actions";
11
11
  import {
@@ -22,6 +22,7 @@ import type { CellData } from "@/core/cells/types";
22
22
  import type { CellRunStatus } from "@/core/executions";
23
23
  import { setupCodeMirror } from "@/core/codemirror/cm";
24
24
  import { acceptCompletionOnEnterAtom } from "@/core/codemirror/completion/accept-on-enter-atom";
25
+ import { replaceEditorContent } from "@/core/codemirror/replace-editor-content";
25
26
  import { useLazyEditorMount } from "@/core/codemirror/use-lazy-editor-mount";
26
27
  import {
27
28
  getInitialLanguageAdapter,
@@ -120,7 +121,8 @@ const CellEditorInternal = ({
120
121
  tooltipParentSelector,
121
122
  extensions: extraExtensions,
122
123
  }: CellEditorProps) => {
123
- const [aiCompletionCell, setAiCompletionCell] = useAtom(aiCompletionCellAtom);
124
+ const aiCompletionCell = useAiCompletionCell(cellId);
125
+ const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
124
126
  const serializedEditorState = useRestoredEditorState(cellId);
125
127
  const takeRestoredEditorState = useSetAtom(takeRestoredEditorStateAtom);
126
128
  const showHiddenCodeNow = useSetAtom(showHiddenCodeAtom);
@@ -379,7 +381,7 @@ const CellEditorInternal = ({
379
381
  }, [handleReconfigureEditor, extensions, editorViewRef]);
380
382
 
381
383
  // An AI edit applies to the editor, which a dormant cell does not have yet.
382
- const isAiCompletionTarget = aiCompletionCell?.cellId === cellId;
384
+ const isAiCompletionTarget = aiCompletionCell !== null;
383
385
  useEffect(() => {
384
386
  if (isAiCompletionTarget) {
385
387
  promote();
@@ -404,29 +406,17 @@ const CellEditorInternal = ({
404
406
  aiCompletionCell={aiCompletionCell}
405
407
  currentCode={mountedEditorView?.state.doc.toString() ?? code}
406
408
  currentLanguageAdapter={languageAdapter}
407
- declineChange={useEvent(() => {
408
- setAiCompletionCell(null);
409
- editorViewRef.current?.focus();
409
+ close={useEvent(() => {
410
+ setAiCompletionCell((target) =>
411
+ target?.cellId === cellId ? null : target,
412
+ );
410
413
  })}
414
+ focusEditor={useEvent(() => editorViewRef.current?.focus())}
411
415
  onChange={useEvent((newCode) => {
412
- editorViewRef.current?.dispatch({
413
- changes: {
414
- from: 0,
415
- to: editorViewRef.current.state.doc.length,
416
- insert: newCode,
417
- },
418
- });
419
- })}
420
- acceptChange={useEvent((newCode) => {
421
- editorViewRef.current?.dispatch({
422
- changes: {
423
- from: 0,
424
- to: editorViewRef.current.state.doc.length,
425
- insert: newCode,
426
- },
427
- });
428
- editorViewRef.current?.focus();
429
- setAiCompletionCell(null);
416
+ const view = editorViewRef.current;
417
+ if (view) {
418
+ replaceEditorContent(view, newCode);
419
+ }
430
420
  })}
431
421
  runCell={handleRunCell}
432
422
  outputArea={outputArea}
@@ -1,7 +1,9 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { render, screen } from "@testing-library/react";
4
- import { describe, expect, it } from "vitest";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { appendCellLogs, LOG_CHUNK_SIZE } from "@/core/cells/cell-log-chunks";
6
+ import * as cellLogs from "@/core/cells/logs";
5
7
  import type { CellLog } from "@/core/cells/logs";
6
8
  import { LogViewer } from "../logs-panel";
7
9
 
@@ -16,10 +18,32 @@ describe("LogViewer", () => {
16
18
  },
17
19
  ];
18
20
 
19
- render(<LogViewer logs={logs} />);
21
+ render(<LogViewer logs={[logs]} />);
20
22
 
21
23
  expect(screen.getByText("(lsp:pylsp)")).toBeInTheDocument();
22
24
  expect(screen.getByText("pylsp failed to start")).toBeInTheDocument();
23
25
  expect(screen.getByText("STDERR")).toBeInTheDocument();
24
26
  });
27
+
28
+ it("continues row numbers without formatting a full chunk again", () => {
29
+ const log: CellLog = {
30
+ timestamp: 1,
31
+ level: "stdout",
32
+ message: "message",
33
+ source: { type: "lsp", name: "pylsp" },
34
+ };
35
+ const logs = appendCellLogs(
36
+ [],
37
+ Array.from({ length: LOG_CHUNK_SIZE }, () => log),
38
+ );
39
+ const { rerender } = render(<LogViewer logs={logs} />);
40
+ const format = vi.spyOn(cellLogs, "formatLogTimestamp");
41
+ try {
42
+ rerender(<LogViewer logs={appendCellLogs(logs, [log])} />);
43
+ expect(format).toHaveBeenCalledTimes(1);
44
+ expect(screen.getByText(String(LOG_CHUNK_SIZE + 1))).toBeInTheDocument();
45
+ } finally {
46
+ format.mockRestore();
47
+ }
48
+ });
25
49
  });
@@ -3,6 +3,10 @@
3
3
  import { FileTextIcon } from "lucide-react";
4
4
  import React from "react";
5
5
  import { ClearButton } from "@/components/buttons/clear-button";
6
+ import {
7
+ type CellLogChunks,
8
+ LOG_CHUNK_SIZE,
9
+ } from "@/core/cells/cell-log-chunks";
6
10
  import { useCellLogs } from "@/core/cells/cells";
7
11
  import { useCellActions } from "@/core/cells/actions";
8
12
  import {
@@ -16,7 +20,7 @@ import { PanelEmptyState } from "./empty-state";
16
20
 
17
21
  interface Props {
18
22
  className?: string;
19
- logs: CellLog[];
23
+ logs: CellLogChunks;
20
24
  }
21
25
 
22
26
  const LogsPanel: React.FC = () => {
@@ -52,7 +56,6 @@ const LogsPanel: React.FC = () => {
52
56
  export default LogsPanel;
53
57
 
54
58
  export const LogViewer: React.FC<Props> = ({ logs, className }) => {
55
- const hover = "opacity-70 group-hover:bg-(--gray-3) group-hover:opacity-100";
56
59
  return (
57
60
  <div className={cn("flex flex-col", className)}>
58
61
  <pre className="grid text-xs font-mono gap-1 whitespace-break-spaces font-semibold align-left">
@@ -60,15 +63,8 @@ export const LogViewer: React.FC<Props> = ({ logs, className }) => {
60
63
  className="grid grid-cols-[30px_1fr]"
61
64
  style={{ whiteSpace: "pre-wrap" }}
62
65
  >
63
- {logs.map((log, index) => (
64
- <div key={index} className="contents group">
65
- <span className={cn(hover, "text-right col-span-1 py-1 pr-1")}>
66
- {index + 1}
67
- </span>
68
- <span className={cn(hover, "px-2 flex gap-x-1.5 py-1 flex-wrap")}>
69
- {formatLog(log)}
70
- </span>
71
- </div>
66
+ {logs.map((chunk, index) => (
67
+ <LogRows key={index} logs={chunk} offset={index * LOG_CHUNK_SIZE} />
72
68
  ))}
73
69
  </div>
74
70
  </pre>
@@ -76,6 +72,26 @@ export const LogViewer: React.FC<Props> = ({ logs, className }) => {
76
72
  );
77
73
  };
78
74
 
75
+ const LogRows = React.memo(function LogRows({
76
+ logs,
77
+ offset,
78
+ }: {
79
+ logs: readonly CellLog[];
80
+ offset: number;
81
+ }) {
82
+ const hover = "opacity-70 group-hover:bg-(--gray-3) group-hover:opacity-100";
83
+ return logs.map((log, index) => (
84
+ <div key={index} className="contents group">
85
+ <span className={cn(hover, "text-right col-span-1 py-1 pr-1")}>
86
+ {offset + index + 1}
87
+ </span>
88
+ <span className={cn(hover, "px-2 flex gap-x-1.5 py-1 flex-wrap")}>
89
+ {formatLog(log)}
90
+ </span>
91
+ </div>
92
+ ));
93
+ });
94
+
79
95
  function formatLog(log: CellLog) {
80
96
  const timestamp = formatLogTimestamp(log.timestamp);
81
97
 
@@ -70,7 +70,6 @@ import {
70
70
  shouldHidePublishedCell,
71
71
  } from "../../core/cells/utils";
72
72
  import type { UserConfig } from "../../core/config/config-schema";
73
- import { isAppInteractionDisabled } from "../../core/session/connection-utils";
74
73
  import { useCellRenderCount } from "../../hooks/useCellRenderCount";
75
74
  import type { Theme } from "../../theme/useTheme";
76
75
  import { Functions } from "../../utils/functions";
@@ -86,11 +85,13 @@ import {
86
85
  import { CellActionsContextMenu } from "./cell/cell-context-menu";
87
86
  import { CellEditor } from "./cell/code/cell-editor";
88
87
  import { CollapsedCellBanner, CollapseToggle } from "./cell/collapse";
89
- import { DeleteButton } from "./cell/DeleteButton";
88
+ import {
89
+ CellDeleteShoulder,
90
+ useCellHoverProps,
91
+ } from "./cell/CellDeleteShoulder";
90
92
  import { PendingDeleteConfirmation } from "./cell/PendingDeleteConfirmation";
91
93
  import { RunButton } from "./cell/RunButton";
92
94
  import { StagedAIDeletionMarker } from "./cell/StagedAICell";
93
- import { useDeleteCellCallback } from "./cell/useDeleteCell";
94
95
  import { useRunCell } from "./cell/useRunCells";
95
96
  import { cellDomProps } from "./common";
96
97
  import { SqlValidationErrorBanner } from "./errors/sql-validation-errors";
@@ -392,7 +393,6 @@ const EditableCellComponent = ({
392
393
  const actions = useCellActions();
393
394
  const connection = useAtomValue(connectionAtom);
394
395
  const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
395
- const deleteCell = useDeleteCellCallback();
396
396
  const runCell = useRunCell(cellId);
397
397
  const answerPrompt = useAnswerPrompt(cellId);
398
398
  const isPendingCut = useIsPendingCut(cellId);
@@ -410,8 +410,6 @@ const EditableCellComponent = ({
410
410
 
411
411
  const needsRun = cellRunReason(execution, freshness, cellData) !== null;
412
412
 
413
- const loading = outputIsLoading(execution.status);
414
-
415
413
  const isPresenting = mode === "present";
416
414
 
417
415
  // While presenting, the cell may be hidden (matching the read view), but it
@@ -466,6 +464,7 @@ const EditableCellComponent = ({
466
464
  editorView,
467
465
  cellActionDropdownRef,
468
466
  });
467
+ const hoverProps = useCellHoverProps(cellId);
469
468
  const canCollapse = canCollapseOutline(outline);
470
469
  const hasOutput = !isOutputEmpty(output);
471
470
  // While presenting, pending edits do not dim the output as stale,
@@ -638,6 +637,7 @@ const EditableCellComponent = ({
638
637
  <div
639
638
  tabIndex={-1}
640
639
  {...(isPresenting ? undefined : navigationProps)}
640
+ {...(isPresenting ? undefined : hoverProps)}
641
641
  className={cn(
642
642
  className,
643
643
  !isPresenting && navigationProps.className,
@@ -712,22 +712,12 @@ const EditableCellComponent = ({
712
712
  disabled={cellData.config.disabled}
713
713
  />
714
714
  )}
715
- <div className="shoulder-bottom hover-action">
716
- {canDelete && isCellCodeShown && (
717
- <DeleteButton
718
- status={execution.status}
719
- connectionState={connection.state}
720
- onClick={() => {
721
- if (
722
- !loading &&
723
- !isAppInteractionDisabled(connection.state)
724
- ) {
725
- deleteCell({ cellId });
726
- }
727
- }}
728
- />
729
- )}
730
- </div>
715
+ <CellDeleteShoulder
716
+ cellId={cellId}
717
+ status={execution.status}
718
+ connectionState={connection.state}
719
+ showButton={canDelete && isCellCodeShown}
720
+ />
731
721
  </div>
732
722
  {!isPresenting && (
733
723
  <SqlValidationErrorBanner
@@ -978,7 +968,6 @@ const SetupCellComponent = ({
978
968
  const connection = useAtomValue(connectionAtom);
979
969
 
980
970
  const actions = useCellActions();
981
- const deleteCell = useDeleteCellCallback();
982
971
  const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
983
972
  const runCell = useRunCell(cellId);
984
973
  const answerPrompt = useAnswerPrompt(cellId);
@@ -1015,6 +1004,7 @@ const SetupCellComponent = ({
1015
1004
  editorView,
1016
1005
  cellActionDropdownRef,
1017
1006
  });
1007
+ const hoverProps = useCellHoverProps(cellId);
1018
1008
  const hasOutput = !isOutputEmpty(output);
1019
1009
  const hasConsoleOutput = cellRuntime.consoleOutputs.length > 0;
1020
1010
  const isErrorOutput = isErrorMime(output?.mimetype);
@@ -1075,7 +1065,7 @@ const SetupCellComponent = ({
1075
1065
  <div
1076
1066
  data-status={execution.status}
1077
1067
  ref={cellRef}
1078
- {...mergeProps(navigationProps, {
1068
+ {...mergeProps(navigationProps, hoverProps, {
1079
1069
  className: cn(
1080
1070
  className,
1081
1071
  "focus:ring-1 focus:ring-(--slate-8) focus:ring-offset-2",
@@ -1141,22 +1131,12 @@ const SetupCellComponent = ({
1141
1131
  disabled={cellData.config.disabled}
1142
1132
  />
1143
1133
  )}
1144
- <div className="shoulder-bottom hover-action">
1145
- {canDelete && (
1146
- <DeleteButton
1147
- connectionState={connection.state}
1148
- status={execution.status}
1149
- onClick={() => {
1150
- if (
1151
- !loading &&
1152
- !isAppInteractionDisabled(connection.state)
1153
- ) {
1154
- deleteCell({ cellId });
1155
- }
1156
- }}
1157
- />
1158
- )}
1159
- </div>
1134
+ <CellDeleteShoulder
1135
+ cellId={cellId}
1136
+ status={execution.status}
1137
+ connectionState={connection.state}
1138
+ showButton={canDelete}
1139
+ />
1160
1140
  </div>
1161
1141
  <div className="py-1 px-2 flex justify-end gap-2 last:rounded-b">
1162
1142
  <span className="text-muted-foreground text-xs font-bold">
@@ -5,6 +5,7 @@ import type { FileUIPart } from "ai";
5
5
  import { atom } from "jotai";
6
6
  import { atomWithStorage } from "jotai/utils";
7
7
  import { toast } from "@/components/ui/use-toast";
8
+ import { createKeyedSelectorHook } from "@/core/state/create-keyed-selector-hook";
8
9
  import { uniqueBy } from "@/utils/arrays";
9
10
  import { Logger } from "@/utils/Logger";
10
11
  import { adaptForLocalStorage, jotaiJsonStorage } from "@/utils/storage/jotai";
@@ -24,6 +25,11 @@ export interface AiCompletionCell {
24
25
 
25
26
  export const aiCompletionCellAtom = atom<AiCompletionCell | null>(null);
26
27
 
28
+ export const useAiCompletionCell = createKeyedSelectorHook(
29
+ aiCompletionCellAtom,
30
+ (target, cellId: CellId) => (target?.cellId === cellId ? target : null),
31
+ );
32
+
27
33
  /**
28
34
  * A prompt queued to be delivered to the AI assistant panel.
29
35
  * The active panel consumes this on mount/when ready, then clears it.