@marimo-team/islands 0.26.1-dev108 → 0.26.1-dev118
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/dist/{ErrorBoundary-BW4TciqU.js → ErrorBoundary-Gr2Kt5kj.js} +1 -1
- package/dist/{chat-ui-Be9X-W22.js → chat-ui-CMKYvKUz.js} +3 -3
- package/dist/{code-visibility-BKmktPMd.js → code-visibility-BFFe0rT7.js} +2 -2
- package/dist/{common-CSJAjJGa.js → common-7eNIhSN-.js} +4766 -4747
- package/dist/{data-grid-overlay-editor-DTibdR4H.js → data-grid-overlay-editor-B37-1-8n.js} +1 -1
- package/dist/{error-entries-23Z_1oDM.js → error-entries-B4LgfizR.js} +772 -751
- package/dist/{feedback-button-CPu5SV3b.js → feedback-button-CpQcgVuz.js} +3 -3
- package/dist/{formats-Y52bg800.js → formats-CeuXJ_1f.js} +32 -25
- package/dist/{glide-data-editor-CC9_NDNi.js → glide-data-editor-BxTlDHV5.js} +3 -3
- package/dist/{globals-BFlYTNoR.js → globals-ljOLdTJr.js} +1 -1
- package/dist/{html-to-image-Cw7o1IbE.js → html-to-image-CIkwg7mv.js} +1 -1
- package/dist/main.js +69 -66
- package/dist/{number-overlay-editor-qDcRKPE0.js → number-overlay-editor-DGKTstav.js} +1 -1
- package/dist/{process-output-DdBM0lmd.js → process-output-PS9YSLNu.js} +2 -2
- package/dist/{reveal-component-BE1xhtNc.js → reveal-component-BLJMkx2N.js} +2 -2
- package/dist/{useDeepCompareMemoize-Dn-ZJVTd.js → semaphore-8KhQouXt.js} +5 -15
- package/dist/style.css +1 -1
- package/dist/{vega-component-BIq0qzhQ.js → vega-component-CoJiBCaS.js} +11 -11
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +1 -1
- package/src/__mocks__/intersection-observer.ts +5 -5
- package/src/components/editor/Output.tsx +3 -21
- package/src/components/editor/__tests__/cell-renders.test.tsx +327 -1
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +27 -0
- package/src/components/editor/actions/pair-with-agent-modal.tsx +8 -1
- package/src/components/editor/ai/__tests__/completion-utils.test.ts +12 -20
- package/src/components/editor/ai/ai-completion-editor.tsx +391 -289
- package/src/components/editor/ai/completion-utils.ts +9 -7
- package/src/components/editor/cell/CellDeleteShoulder.tsx +82 -0
- package/src/components/editor/cell/DeleteButton.tsx +11 -2
- package/src/components/editor/cell/__tests__/CellDeleteShoulder.test.tsx +181 -0
- package/src/components/editor/cell/code/cell-editor.tsx +15 -25
- package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +26 -2
- package/src/components/editor/chrome/panels/logs-panel.tsx +27 -11
- package/src/components/editor/notebook-cell.tsx +20 -40
- package/src/components/editor/output/VegaOutput.tsx +35 -0
- package/src/components/find-replace/find-replace.tsx +1 -7
- package/src/core/ai/state.ts +6 -0
- package/src/core/cells/__tests__/cell-errors.test.tsx +179 -0
- package/src/core/cells/__tests__/cells.test.ts +34 -20
- package/src/core/cells/cell-log-chunks.ts +31 -0
- package/src/core/cells/cells.ts +34 -33
- package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +18 -15
- package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +90 -2
- package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +44 -10
- package/src/core/codemirror/find-replace/navigate.ts +4 -1
- package/src/core/codemirror/find-replace/search-highlight.ts +54 -58
- package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +1 -1
- package/src/core/codemirror/lsp/__tests__/transports.test.ts +1 -1
- package/src/core/executions/__tests__/atoms.test.ts +0 -2
- package/src/core/executions/__tests__/output-lifecycle.test.ts +16 -0
- package/src/core/executions/atoms.ts +33 -36
- package/src/core/export/__tests__/output-snapshot.test.tsx +240 -0
- package/src/core/export/__tests__/output-subscription.test.tsx +79 -0
- package/src/core/export/hooks.ts +29 -13
- package/src/core/islands/__tests__/bridge.test.ts +2 -5
- package/src/core/notebook/replica/frame.ts +8 -2
- package/src/core/notebook/replica/index.ts +5 -1
- package/src/core/notebook/replica/once-per-frame.ts +4 -3
- package/src/core/notebook/replica/resources/executions.ts +16 -1
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +10 -1
- package/src/css/common.css +11 -0
- package/src/hooks/useFinePointer.ts +30 -0
- package/src/stories/log-viewer.stories.tsx +48 -44
- package/src/utils/shared-intersection-observer.ts +2 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { Suspense, useState } from "react";
|
|
4
|
+
import type { VegaEmbedProps } from "react-vega";
|
|
5
|
+
import { LazyVegaEmbed } from "@/components/charts/lazy";
|
|
6
|
+
import { tooltipHandler } from "@/components/charts/tooltip";
|
|
7
|
+
import { ChartLoadingState } from "@/components/data-table/charts/components/chart-states";
|
|
8
|
+
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
|
|
9
|
+
import type { TopLevelFacetedUnitSpec } from "@/plugins/impl/data-explorer/queries/types";
|
|
10
|
+
import { getContainerWidth } from "@/plugins/impl/vega/utils";
|
|
11
|
+
import { useTheme } from "@/theme/useTheme";
|
|
12
|
+
|
|
13
|
+
export function VegaOutput({ spec }: { spec: TopLevelFacetedUnitSpec }) {
|
|
14
|
+
const { theme } = useTheme();
|
|
15
|
+
const embed = useDeepCompareMemoize({
|
|
16
|
+
spec,
|
|
17
|
+
options: {
|
|
18
|
+
theme: theme === "dark" ? "dark" : undefined,
|
|
19
|
+
mode: "vega-lite",
|
|
20
|
+
tooltip: tooltipHandler.call,
|
|
21
|
+
renderer: "canvas",
|
|
22
|
+
},
|
|
23
|
+
} satisfies VegaEmbedProps);
|
|
24
|
+
const [rendered, setRendered] = useState<typeof embed>();
|
|
25
|
+
return (
|
|
26
|
+
<Suspense fallback={<ChartLoadingState />}>
|
|
27
|
+
<LazyVegaEmbed
|
|
28
|
+
{...embed}
|
|
29
|
+
onEmbed={() => setRendered(embed)}
|
|
30
|
+
data-marimo-vega-ready={rendered === embed || undefined}
|
|
31
|
+
data-container-width={getContainerWidth(spec)}
|
|
32
|
+
/>
|
|
33
|
+
</Suspense>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -18,10 +18,6 @@ import {
|
|
|
18
18
|
replaceAll,
|
|
19
19
|
replaceNext,
|
|
20
20
|
} from "@/core/codemirror/find-replace/navigate";
|
|
21
|
-
import {
|
|
22
|
-
clearGlobalSearchQuery,
|
|
23
|
-
setGlobalSearchQuery,
|
|
24
|
-
} from "@/core/codemirror/find-replace/search-highlight";
|
|
25
21
|
import {
|
|
26
22
|
findReplaceAtom,
|
|
27
23
|
openFindReplacePanel,
|
|
@@ -68,18 +64,15 @@ export const FindReplace: React.FC = () => {
|
|
|
68
64
|
|
|
69
65
|
useEffect(() => {
|
|
70
66
|
if (!state.isOpen) {
|
|
71
|
-
clearGlobalSearchQuery();
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
if (state.findText === "") {
|
|
76
71
|
setMatches(undefined);
|
|
77
|
-
clearGlobalSearchQuery();
|
|
78
72
|
return;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
resetMatches();
|
|
82
|
-
setGlobalSearchQuery();
|
|
83
76
|
}, [
|
|
84
77
|
// Re-search when any of these change
|
|
85
78
|
state.findText,
|
|
@@ -245,6 +238,7 @@ export const FindReplace: React.FC = () => {
|
|
|
245
238
|
data-testid="undo-replace-all-button"
|
|
246
239
|
onClick={() => {
|
|
247
240
|
undo();
|
|
241
|
+
resetMatches();
|
|
248
242
|
dismiss();
|
|
249
243
|
}}
|
|
250
244
|
/>
|
package/src/core/ai/state.ts
CHANGED
|
@@ -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.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, render, screen } from "@testing-library/react";
|
|
4
|
+
import { createStore, Provider } from "jotai";
|
|
5
|
+
import { Profiler } from "react";
|
|
6
|
+
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
|
7
|
+
import { mockAnimationFrames } from "@/__mocks__/animation-frames";
|
|
8
|
+
import { type ExecutionEntries, MockExecutions } from "@/__mocks__/executions";
|
|
9
|
+
import { MockNotebook } from "@/__mocks__/notebook";
|
|
10
|
+
import { cellId } from "@/__tests__/branded";
|
|
11
|
+
import { createRenderTracker } from "@/__tests__/render-tracker";
|
|
12
|
+
import { cellOutputAtom, clearCellOutputs } from "@/core/executions";
|
|
13
|
+
import {
|
|
14
|
+
cell,
|
|
15
|
+
document as documentOf,
|
|
16
|
+
withCells,
|
|
17
|
+
} from "@/core/notebook/document/__tests__/fixtures";
|
|
18
|
+
import { createReplicaFrame } from "@/core/notebook/replica";
|
|
19
|
+
import { activeNotebookFrameAtom } from "@/core/session/active-notebook";
|
|
20
|
+
import {
|
|
21
|
+
cellErrorCount,
|
|
22
|
+
cellErrorsAtom,
|
|
23
|
+
getNotebookActionsForStore,
|
|
24
|
+
useCellErrors,
|
|
25
|
+
} from "../cells";
|
|
26
|
+
|
|
27
|
+
const first = cellId("c1");
|
|
28
|
+
const second = cellId("c2");
|
|
29
|
+
const third = cellId("c3");
|
|
30
|
+
const firstError = MockExecutions.failed(first);
|
|
31
|
+
const secondError = MockExecutions.failed(second);
|
|
32
|
+
const ancestorError = MockExecutions.completed(second, {
|
|
33
|
+
kind: "skipped",
|
|
34
|
+
reason: "upstream-stopped",
|
|
35
|
+
message: "The upstream cell stopped",
|
|
36
|
+
related: [{ cell_id: first, range: null, message: "Stopped here" }],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function setup(size: number, ...entries: ExecutionEntries) {
|
|
40
|
+
const store = createStore();
|
|
41
|
+
const actions = getNotebookActionsForStore(store);
|
|
42
|
+
const order = Array.from({ length: size }, (_, i) => cellId(`c${i + 1}`));
|
|
43
|
+
const confirmed = withCells(
|
|
44
|
+
documentOf(),
|
|
45
|
+
Object.fromEntries(order.map((id) => [id, cell(id, "pass", { name: id })])),
|
|
46
|
+
);
|
|
47
|
+
const cells = new Map(confirmed.cells);
|
|
48
|
+
actions.reconcileDocument({ order, cells });
|
|
49
|
+
const replica = MockExecutions.seed(store, entries, null, confirmed);
|
|
50
|
+
const receive = (records: ExecutionEntries) => {
|
|
51
|
+
const next = MockExecutions.inputs(records);
|
|
52
|
+
store.set(replica.executionsAtom, next.executions);
|
|
53
|
+
store.set(replica.resultsAtom, next.results);
|
|
54
|
+
};
|
|
55
|
+
return { store, actions, order, cells, replica, receive };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ErrorNames() {
|
|
59
|
+
const names = useCellErrors().map((error) => error.cellName);
|
|
60
|
+
return <output>{names.join(", ")}</output>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe("cellErrorsAtom", () => {
|
|
64
|
+
it.each([5, 500])("skips unrelated updates with %i cells", (size) => {
|
|
65
|
+
const { store, actions, order, cells, replica, receive } = setup(
|
|
66
|
+
size,
|
|
67
|
+
firstError,
|
|
68
|
+
);
|
|
69
|
+
const advanceFrame = mockAnimationFrames();
|
|
70
|
+
const lifetime = new AbortController();
|
|
71
|
+
onTestFinished(() => lifetime.abort());
|
|
72
|
+
store.set(
|
|
73
|
+
activeNotebookFrameAtom,
|
|
74
|
+
createReplicaFrame(store, replica, { signal: lifetime.signal }),
|
|
75
|
+
);
|
|
76
|
+
const read = vi.spyOn(cellErrorsAtom, "read");
|
|
77
|
+
onTestFinished(() => read.mockRestore());
|
|
78
|
+
const renders = createRenderTracker();
|
|
79
|
+
render(
|
|
80
|
+
<Provider store={store}>
|
|
81
|
+
<Profiler id="errors" onRender={renders.onRender}>
|
|
82
|
+
<ErrorNames />
|
|
83
|
+
</Profiler>
|
|
84
|
+
</Provider>,
|
|
85
|
+
);
|
|
86
|
+
const before = store.get(cellErrorsAtom);
|
|
87
|
+
renders.reset();
|
|
88
|
+
read.mockClear();
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
actions.startCellConsole({ cellId: second });
|
|
92
|
+
cells.set(first, cell(first, "fixed()", { name: first }));
|
|
93
|
+
cells.set(second, cell(second, "pass", { name: "renamed" }));
|
|
94
|
+
actions.reconcileDocument({ order, cells });
|
|
95
|
+
});
|
|
96
|
+
act(() => {
|
|
97
|
+
receive([
|
|
98
|
+
firstError,
|
|
99
|
+
MockExecutions.shown(second, { mimetype: "text/plain", data: "42" }),
|
|
100
|
+
]);
|
|
101
|
+
advanceFrame();
|
|
102
|
+
});
|
|
103
|
+
expect(store.get(cellOutputAtom(second))?.data).toBe("42");
|
|
104
|
+
act(() => {
|
|
105
|
+
receive([firstError, ancestorError]);
|
|
106
|
+
advanceFrame();
|
|
107
|
+
});
|
|
108
|
+
expect(store.get(cellOutputAtom(second))?.data).toEqual([
|
|
109
|
+
expect.objectContaining({ type: "ancestor-stopped" }),
|
|
110
|
+
]);
|
|
111
|
+
expect(read).not.toHaveBeenCalled();
|
|
112
|
+
expect(renders.counts()).toEqual({});
|
|
113
|
+
expect(store.get(cellErrorsAtom)).toBe(before);
|
|
114
|
+
|
|
115
|
+
act(() => {
|
|
116
|
+
receive([firstError, secondError]);
|
|
117
|
+
advanceFrame();
|
|
118
|
+
});
|
|
119
|
+
expect(read).toHaveBeenCalledOnce();
|
|
120
|
+
expect(renders.counts()).toEqual({ errors: 1 });
|
|
121
|
+
expect(screen.getByRole("status").textContent).toBe("c1, renamed");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("tracks order, names, clear, and cell lifetime within each store", () => {
|
|
125
|
+
const { store, actions, cells, order } = setup(3, firstError, secondError);
|
|
126
|
+
const other = setup(2, firstError).store;
|
|
127
|
+
const otherErrors = other.get(cellErrorsAtom);
|
|
128
|
+
const names = () =>
|
|
129
|
+
store.get(cellErrorsAtom).map((error) => error.cellName);
|
|
130
|
+
expect(names()).toEqual([first, second]);
|
|
131
|
+
|
|
132
|
+
cells.set(first, cell(first, "pass", { name: "renamed" }));
|
|
133
|
+
actions.reconcileDocument({ order, cells });
|
|
134
|
+
expect(names()).toEqual(["renamed", second]);
|
|
135
|
+
const before = store.get(cellErrorsAtom);
|
|
136
|
+
actions.reconcileDocument({ order: [third, first, second], cells });
|
|
137
|
+
expect(store.get(cellErrorsAtom)).toBe(before);
|
|
138
|
+
actions.reconcileDocument({ order: [third, second, first], cells });
|
|
139
|
+
expect(names()).toEqual([second, "renamed"]);
|
|
140
|
+
clearCellOutputs(store, [second]);
|
|
141
|
+
expect(store.get(cellErrorCount)).toBe(1);
|
|
142
|
+
cells.delete(first);
|
|
143
|
+
actions.reconcileDocument({ order: [third, second], cells });
|
|
144
|
+
expect(names()).toEqual([]);
|
|
145
|
+
|
|
146
|
+
cells.set(first, cell(first, "pass", { name: "restored" }));
|
|
147
|
+
actions.reconcileDocument({ order, cells });
|
|
148
|
+
expect(names()).toEqual(["restored"]);
|
|
149
|
+
expect(other.get(cellErrorsAtom)).toBe(otherErrors);
|
|
150
|
+
expect(otherErrors.map((error) => error.cellName)).toEqual([first]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("keeps actionable errors in a mixed output", () => {
|
|
154
|
+
const { store } = setup(2);
|
|
155
|
+
const actionable = [
|
|
156
|
+
MockNotebook.errors.exception("Division by zero"),
|
|
157
|
+
MockNotebook.errors.syntax("Invalid syntax"),
|
|
158
|
+
];
|
|
159
|
+
const output = {
|
|
160
|
+
channel: "marimo-error",
|
|
161
|
+
mimetype: "application/vnd.marimo+error",
|
|
162
|
+
timestamp: 1,
|
|
163
|
+
data: [
|
|
164
|
+
...actionable,
|
|
165
|
+
{
|
|
166
|
+
type: "ancestor-stopped",
|
|
167
|
+
raising_cell: second,
|
|
168
|
+
msg: "Upstream stop",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
} as const;
|
|
172
|
+
const read = vi
|
|
173
|
+
.spyOn(cellOutputAtom(first), "read")
|
|
174
|
+
.mockReturnValue(output);
|
|
175
|
+
onTestFinished(() => read.mockRestore());
|
|
176
|
+
expect(store.get(cellErrorsAtom)[0]?.output.data).toEqual(actionable);
|
|
177
|
+
expect(store.get(cellErrorCount)).toBe(1);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -21,6 +21,8 @@ import { MockExecutions } from "@/__mocks__/executions";
|
|
|
21
21
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
22
22
|
import { cellId } from "@/__tests__/branded";
|
|
23
23
|
import type { CellHandle } from "@/components/editor/notebook-cell";
|
|
24
|
+
import { LOG_CHUNK_SIZE } from "../cell-log-chunks";
|
|
25
|
+
import type { CellLog } from "../logs";
|
|
24
26
|
import { CellId, SCRATCH_CELL_ID } from "@/core/cells/ids";
|
|
25
27
|
import { foldAllBulk, unfoldAllBulk } from "@/core/codemirror/editing/commands";
|
|
26
28
|
import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
|
|
@@ -235,23 +237,33 @@ describe("cell reducer", () => {
|
|
|
235
237
|
expect(unfoldAllBulk).toHaveBeenCalled();
|
|
236
238
|
});
|
|
237
239
|
|
|
238
|
-
it("
|
|
239
|
-
|
|
240
|
-
{
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
it("retains ordered log batches across appends and runtime resets until cleared", () => {
|
|
241
|
+
const logs = Array.from(
|
|
242
|
+
{ length: 3 * LOG_CHUNK_SIZE + 2 },
|
|
243
|
+
(_, i): CellLog => ({
|
|
244
|
+
level: i % 2 === 0 ? "stdout" : "stderr",
|
|
245
|
+
message: String(i),
|
|
246
|
+
timestamp: i,
|
|
244
247
|
source: { type: "cell", cellId: firstCellId },
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
actions.addLogs({ logs: logs.slice(0, LOG_CHUNK_SIZE + 1) });
|
|
251
|
+
const previous = state;
|
|
252
|
+
actions.addLogs({ logs: [] });
|
|
253
|
+
expect(state).toBe(previous);
|
|
254
|
+
actions.addLogs({ logs: logs.slice(LOG_CHUNK_SIZE + 1, -1) });
|
|
255
|
+
actions.addLogs({ logs: logs.slice(-1) });
|
|
256
|
+
const appended = state.cellLogs;
|
|
257
|
+
expect(appended[0]).toBe(previous.cellLogs[0]);
|
|
258
|
+
expect(previous.cellLogs.flat()).toEqual(logs.slice(0, LOG_CHUNK_SIZE + 1));
|
|
259
|
+
expect(appended.flat()).toEqual(logs);
|
|
260
|
+
actions.resetCellRuntimes(false);
|
|
261
|
+
expect(state.cellLogs).toBe(appended);
|
|
253
262
|
actions.clearLogs();
|
|
254
263
|
expect(state.cellLogs).toEqual([]);
|
|
264
|
+
actions.addLogs({ logs: logs.slice(-1) });
|
|
265
|
+
expect(state.cellLogs.flat()).toEqual(logs.slice(-1));
|
|
266
|
+
expect(appended.flat()).toEqual(logs);
|
|
255
267
|
});
|
|
256
268
|
|
|
257
269
|
describe("releaseCellAtoms", () => {
|
|
@@ -289,12 +301,14 @@ it("keeps layout cells stable when only a notebook log changes", () => {
|
|
|
289
301
|
store.set(notebookAtom, {
|
|
290
302
|
...notebook,
|
|
291
303
|
cellLogs: [
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
[
|
|
305
|
+
{
|
|
306
|
+
level: "stderr",
|
|
307
|
+
message: "log",
|
|
308
|
+
timestamp: 0,
|
|
309
|
+
source: { type: "cell", cellId: id },
|
|
310
|
+
},
|
|
311
|
+
],
|
|
298
312
|
],
|
|
299
313
|
});
|
|
300
314
|
expect(store.get(renderedNotebookCellsAtom)).toBe(cells);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import type { CellLog } from "./logs";
|
|
4
|
+
|
|
5
|
+
export type CellLogChunks = readonly (readonly CellLog[])[];
|
|
6
|
+
export const LOG_CHUNK_SIZE = 128;
|
|
7
|
+
|
|
8
|
+
/** Full chunks stay shared with previous notebook snapshots. */
|
|
9
|
+
export function appendCellLogs(
|
|
10
|
+
chunks: CellLogChunks,
|
|
11
|
+
logs: readonly CellLog[],
|
|
12
|
+
): CellLogChunks {
|
|
13
|
+
if (logs.length === 0) {
|
|
14
|
+
return chunks;
|
|
15
|
+
}
|
|
16
|
+
const next = [...chunks];
|
|
17
|
+
const last = next.at(-1);
|
|
18
|
+
let offset = 0;
|
|
19
|
+
if (last && last.length < LOG_CHUNK_SIZE) {
|
|
20
|
+
const tail = [...last];
|
|
21
|
+
while (offset < logs.length && tail.length < LOG_CHUNK_SIZE) {
|
|
22
|
+
tail.push(logs[offset]);
|
|
23
|
+
offset++;
|
|
24
|
+
}
|
|
25
|
+
next[next.length - 1] = tail;
|
|
26
|
+
}
|
|
27
|
+
for (; offset < logs.length; offset += LOG_CHUNK_SIZE) {
|
|
28
|
+
next.push(logs.slice(offset, offset + LOG_CHUNK_SIZE));
|
|
29
|
+
}
|
|
30
|
+
return next;
|
|
31
|
+
}
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
releaseCellOutputAtoms,
|
|
19
19
|
} from "@/core/executions";
|
|
20
20
|
import type { CellColumnId } from "./layout";
|
|
21
|
+
import { arrayShallowEquals } from "@/utils/arrays";
|
|
21
22
|
import { Functions } from "@/utils/functions";
|
|
22
23
|
import { invariant } from "@/utils/invariant";
|
|
23
24
|
import { Logger } from "@/utils/Logger";
|
|
@@ -40,6 +41,7 @@ import { consoleExecution, consoleView } from "./execution-console";
|
|
|
40
41
|
import { applyDocument } from "./document";
|
|
41
42
|
import { isCodeHidden, shownHiddenCodeAtom } from "./editor";
|
|
42
43
|
import { type CellId, SCRATCH_CELL_ID } from "./ids";
|
|
44
|
+
import { appendCellLogs, type CellLogChunks } from "./cell-log-chunks";
|
|
43
45
|
import { type CellLog, getCellLogsForMessage } from "./logs";
|
|
44
46
|
import type { NotebookOutlineItem, Outline } from "./outline";
|
|
45
47
|
import { focusAndScrollCellIntoView } from "./scrollCellIntoView";
|
|
@@ -120,7 +122,7 @@ export interface NotebookState {
|
|
|
120
122
|
/**
|
|
121
123
|
* Logs of all cell messages
|
|
122
124
|
*/
|
|
123
|
-
cellLogs:
|
|
125
|
+
cellLogs: CellLogChunks;
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
function withScratchCell(notebookState: NotebookState): NotebookState {
|
|
@@ -203,10 +205,10 @@ const {
|
|
|
203
205
|
? next
|
|
204
206
|
: {
|
|
205
207
|
...next,
|
|
206
|
-
cellLogs:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
cellLogs: appendCellLogs(
|
|
209
|
+
next.cellLogs,
|
|
210
|
+
getCellLogsForMessage({ cell_id, console: entries }),
|
|
211
|
+
),
|
|
210
212
|
};
|
|
211
213
|
},
|
|
212
214
|
hideConsoleInputs: (
|
|
@@ -250,9 +252,12 @@ const {
|
|
|
250
252
|
return { ...state, cellRuntime };
|
|
251
253
|
},
|
|
252
254
|
addLogs: (state, action: { logs: CellLog[] }) => {
|
|
255
|
+
if (action.logs.length === 0) {
|
|
256
|
+
return state;
|
|
257
|
+
}
|
|
253
258
|
return {
|
|
254
259
|
...state,
|
|
255
|
-
cellLogs:
|
|
260
|
+
cellLogs: appendCellLogs(state.cellLogs, action.logs),
|
|
256
261
|
};
|
|
257
262
|
},
|
|
258
263
|
/** Follow the host document's cells and order. */
|
|
@@ -446,36 +451,31 @@ export const runReasonAtom = atom((get) =>
|
|
|
446
451
|
|
|
447
452
|
export const needsRunAtom = atom((get) => get(runReasonAtom) !== null);
|
|
448
453
|
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const output = get(cellOutputAtom(cellId));
|
|
454
|
-
const { name } = cellData[cellId];
|
|
455
|
-
if (output !== null && isErrorMime(output.mimetype)) {
|
|
456
|
-
// Filter out ancestor-stopped errors
|
|
457
|
-
// These are errors that are caused by a cell that was stopped,
|
|
458
|
-
// but nothing the user can take action on.
|
|
459
|
-
invariant(Array.isArray(output.data), "Expected array data");
|
|
460
|
-
const nonAncestorErrors = output.data.filter(
|
|
461
|
-
(error) => !error.type.includes("ancestor"),
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
if (nonAncestorErrors.length > 0) {
|
|
465
|
-
return {
|
|
466
|
-
output: { ...output, data: nonAncestorErrors },
|
|
467
|
-
cellId: cellId,
|
|
468
|
-
cellName: name,
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
454
|
+
const cellErrorAtom = atomFamily((cellId: CellId) => {
|
|
455
|
+
const errorOutputAtom = atom((get) => {
|
|
456
|
+
const output = get(cellOutputAtom(cellId));
|
|
457
|
+
if (output === null || !isErrorMime(output.mimetype)) {
|
|
473
458
|
return null;
|
|
474
|
-
}
|
|
475
|
-
.
|
|
476
|
-
|
|
459
|
+
}
|
|
460
|
+
invariant(Array.isArray(output.data), "Expected array data");
|
|
461
|
+
const data = output.data.filter(
|
|
462
|
+
(error) => !error.type.includes("ancestor"),
|
|
463
|
+
);
|
|
464
|
+
return data.length > 0 ? { ...output, data } : null;
|
|
465
|
+
});
|
|
466
|
+
const nameAtom = atom((get) => get(cellDataAtom(cellId))?.name);
|
|
467
|
+
return atom((get) => {
|
|
468
|
+
const output = get(errorOutputAtom);
|
|
469
|
+
return output && { output, cellId, cellName: get(nameAtom) };
|
|
470
|
+
});
|
|
477
471
|
});
|
|
478
472
|
|
|
473
|
+
export const cellErrorsAtom = selectAtom(
|
|
474
|
+
atom((get) => get(cellIdsAtom).map((id) => get(cellErrorAtom(id)))),
|
|
475
|
+
(entries) => entries.filter(Boolean),
|
|
476
|
+
arrayShallowEquals,
|
|
477
|
+
);
|
|
478
|
+
|
|
479
479
|
// Layout needs lookup by cell ID. Navigation needs the same headings in document order.
|
|
480
480
|
const orderedCellOutlines = selectAtom(
|
|
481
481
|
atom((get) => {
|
|
@@ -616,6 +616,7 @@ export const cellHandleAtom = atomFamily((cellId: CellId) =>
|
|
|
616
616
|
* @see https://jotai.org/docs/utilities/family#caveat-memory-leaks
|
|
617
617
|
*/
|
|
618
618
|
export function releaseCellAtoms(cellId: CellId) {
|
|
619
|
+
cellErrorAtom.remove(cellId);
|
|
619
620
|
cellDataAtom.remove(cellId);
|
|
620
621
|
cellRuntimeAtom.remove(cellId);
|
|
621
622
|
cellHandleAtom.remove(cellId);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { EditorState, Text } from "@codemirror/state";
|
|
3
|
+
import { EditorSelection, EditorState, Text } from "@codemirror/state";
|
|
4
4
|
import type { EditorView } from "@codemirror/view";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import { cellId } from "@/__tests__/branded";
|
|
@@ -138,23 +138,26 @@ describe("navigate", () => {
|
|
|
138
138
|
expect(state.currentView?.range).toEqual({ from: 0, to: 5 });
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it("
|
|
142
|
-
|
|
143
|
-
store.set(findReplaceAtom, {
|
|
144
|
-
type: "setCurrentView",
|
|
145
|
-
view: view1,
|
|
146
|
-
range: { from: 30, to: 35 },
|
|
147
|
-
});
|
|
141
|
+
it("skips a selection dispatch when the preceding editor is already reset", () => {
|
|
142
|
+
store.set(findReplaceAtom, { type: "setFind", find: "Different" });
|
|
148
143
|
|
|
149
|
-
|
|
144
|
+
expect(findNext()).toMatchObject({ from: 14, to: 23 });
|
|
145
|
+
expect(view1.dispatch).not.toHaveBeenCalled();
|
|
146
|
+
expect(view2.dispatch).toHaveBeenCalledOnce();
|
|
147
|
+
expect(store.get(findReplaceAtom).currentView?.cellId).toBe(cell2);
|
|
148
|
+
});
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
it("clears the preceding editor's selection when moving to another editor", () => {
|
|
151
|
+
view1 = createMockView(
|
|
152
|
+
view1.state.update({ selection: EditorSelection.single(0, 5) }).state,
|
|
153
|
+
);
|
|
154
|
+
mockGetAllEditorViews.mockReturnValue([view1, view2]);
|
|
155
|
+
store.set(findReplaceAtom, { type: "setFind", find: "Different" });
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
expect(
|
|
157
|
+
expect(findNext()).toMatchObject({ from: 14, to: 23 });
|
|
158
|
+
expect(view1.dispatch).toHaveBeenCalledExactlyOnceWith({
|
|
159
|
+
selection: EditorSelection.single(0),
|
|
160
|
+
});
|
|
158
161
|
});
|
|
159
162
|
|
|
160
163
|
it("should wrap around to beginning when reaching end", () => {
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
|
-
import {
|
|
3
|
+
import { EditorView } from "@codemirror/view";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
import { mockIntersectionObservers } from "@/__mocks__/intersection-observer";
|
|
4
6
|
import { store } from "@/core/state/jotai";
|
|
5
|
-
import { searchState } from "../search-highlight";
|
|
7
|
+
import { searchHighlighter, searchState } from "../search-highlight";
|
|
6
8
|
import { findReplaceAtom } from "../state";
|
|
7
9
|
|
|
10
|
+
const views: EditorView[] = [];
|
|
11
|
+
|
|
8
12
|
afterEach(() => {
|
|
13
|
+
for (const view of views.splice(0)) {
|
|
14
|
+
view.destroy();
|
|
15
|
+
}
|
|
16
|
+
vi.unstubAllGlobals();
|
|
17
|
+
store.set(findReplaceAtom, { type: "setRegex", regexp: false });
|
|
9
18
|
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: false });
|
|
10
19
|
store.set(findReplaceAtom, { type: "setFind", find: "" });
|
|
11
20
|
});
|
|
@@ -28,3 +37,82 @@ it("does not highlight a previous search in an editor built after the panel clos
|
|
|
28
37
|
|
|
29
38
|
expect(searchOfNewEditor()).toBe("");
|
|
30
39
|
});
|
|
40
|
+
|
|
41
|
+
it("dispatches only to visible editors and applies the latest query on return", () => {
|
|
42
|
+
const observers = mockIntersectionObservers();
|
|
43
|
+
const createView = () => {
|
|
44
|
+
const view = new EditorView({
|
|
45
|
+
parent: document.body,
|
|
46
|
+
doc: "alpha beta gamma",
|
|
47
|
+
extensions: [searchState, searchHighlighter],
|
|
48
|
+
});
|
|
49
|
+
views.push(view);
|
|
50
|
+
return view;
|
|
51
|
+
};
|
|
52
|
+
const visible = createView();
|
|
53
|
+
const offscreen = Array.from({ length: 20 }, createView);
|
|
54
|
+
const [returning, touchingViewport] = offscreen;
|
|
55
|
+
const [viewport] = observers;
|
|
56
|
+
expect(viewport.observe).toHaveBeenCalledTimes(21);
|
|
57
|
+
viewport.emit(visible.dom, true);
|
|
58
|
+
viewport.emit(returning.dom, true);
|
|
59
|
+
viewport.emit(returning.dom, false);
|
|
60
|
+
viewport.emit(touchingViewport.dom, true, 0);
|
|
61
|
+
const visibleDispatch = vi.spyOn(visible, "dispatch");
|
|
62
|
+
const offscreenDispatches = offscreen.map((view) =>
|
|
63
|
+
vi.spyOn(view, "dispatch"),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
67
|
+
for (const find of ["alpha", "beta", "g.mma"]) {
|
|
68
|
+
store.set(findReplaceAtom, { type: "setFind", find });
|
|
69
|
+
}
|
|
70
|
+
store.set(findReplaceAtom, { type: "setRegex", regexp: true });
|
|
71
|
+
|
|
72
|
+
expect(visibleDispatch).toHaveBeenCalledTimes(4);
|
|
73
|
+
expect(visible.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
74
|
+
"gamma",
|
|
75
|
+
);
|
|
76
|
+
for (const dispatch of offscreenDispatches) {
|
|
77
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
viewport.emit(returning.dom, true);
|
|
81
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledOnce();
|
|
82
|
+
expect(returning.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
83
|
+
"gamma",
|
|
84
|
+
);
|
|
85
|
+
viewport.emit(returning.dom, false);
|
|
86
|
+
|
|
87
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: false });
|
|
88
|
+
expect(visible.dom.querySelector(".cm-searchMatch")).toBeNull();
|
|
89
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledOnce();
|
|
90
|
+
viewport.emit(returning.dom, true);
|
|
91
|
+
expect(offscreenDispatches[0]).toHaveBeenCalledTimes(2);
|
|
92
|
+
expect(returning.dom.querySelector(".cm-searchMatch")).toBeNull();
|
|
93
|
+
|
|
94
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
95
|
+
expect(returning.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
96
|
+
"gamma",
|
|
97
|
+
);
|
|
98
|
+
expect(visible.dom.querySelector(".cm-searchMatch")?.textContent).toBe(
|
|
99
|
+
"gamma",
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("unsubscribes a destroyed visible editor from viewport and query updates", () => {
|
|
104
|
+
const observers = mockIntersectionObservers();
|
|
105
|
+
const view = new EditorView({ extensions: [searchState, searchHighlighter] });
|
|
106
|
+
const [viewport] = observers;
|
|
107
|
+
viewport.emit(view.dom, true);
|
|
108
|
+
const dispatch = vi.spyOn(view, "dispatch");
|
|
109
|
+
|
|
110
|
+
view.destroy();
|
|
111
|
+
viewport.emit(view.dom, true);
|
|
112
|
+
store.set(findReplaceAtom, { type: "setIsOpen", isOpen: true });
|
|
113
|
+
store.set(findReplaceAtom, { type: "setFind", find: "alpha" });
|
|
114
|
+
|
|
115
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
116
|
+
expect(viewport.unobserve).toHaveBeenCalledExactlyOnceWith(view.dom);
|
|
117
|
+
expect(viewport.disconnect).toHaveBeenCalledOnce();
|
|
118
|
+
});
|