@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev391
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-_mFP3LkM.js → ErrorBoundary-DNRG0xHi.js} +1 -1
- package/dist/{chat-ui-BKSYhGMh.js → chat-ui-CWVNPm2l.js} +769 -769
- package/dist/{code-visibility-DkMNjdNe.js → code-visibility-Ca8sDptK.js} +10 -10
- package/dist/{common-Ces9ooG_.js → common-B3NYpak4.js} +4910 -4902
- package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-Cz7uMmtm.js} +1 -1
- package/dist/{error-entries-rtPWQkJk.js → error-entries-CnXf4kpP.js} +821 -686
- package/dist/{feedback-button-i960qUnq.js → feedback-button-BQbnZsf5.js} +7 -7
- package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-Bxc30klU.js} +3 -3
- package/dist/{globals-DKkjIolp.js → globals-CDatnx0Y.js} +1 -1
- package/dist/{html-to-image-B5nTOeMI.js → html-to-image-Bu_-vH_Y.js} +4782 -4765
- package/dist/main.js +6233 -6172
- package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-ChGu5C-s.js} +1 -1
- package/dist/{process-output-DNxpsd4n.js → process-output-Rbqr1aYD.js} +2 -2
- package/dist/{reveal-component-BM9TozVQ.js → reveal-component-CSxWJFAP.js} +32 -32
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +48 -8
- package/src/__mocks__/notebook.ts +20 -42
- package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
- package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
- package/src/components/app-config/ai-config.tsx +20 -24
- package/src/components/app-config/model-discovery.tsx +118 -184
- package/src/components/app-config/model-provider-config.ts +25 -0
- package/src/components/editor/Output.tsx +5 -4
- package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
- package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
- package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
- package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
- package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
- package/src/components/editor/cell/cell-context-menu.tsx +3 -2
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
- package/src/components/editor/notebook-cell.tsx +15 -10
- package/src/components/editor/output/console/process-output.ts +4 -2
- package/src/components/editor/renderers/cells-renderer.tsx +3 -1
- package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
- package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
- package/src/components/editor/renderers/types.ts +2 -2
- package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
- package/src/components/scratchpad/scratchpad.tsx +6 -2
- package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
- package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
- package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
- package/src/components/slides/slide-cell-view.tsx +1 -3
- package/src/components/slides/slide.tsx +3 -3
- package/src/core/ai/context/__tests__/registry.test.ts +7 -11
- package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
- package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
- package/src/core/ai/context/providers/cell-output.ts +11 -6
- package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
- package/src/core/cells/__tests__/cells.test.ts +40 -292
- package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
- package/src/core/cells/__tests__/harness.ts +14 -12
- package/src/core/cells/__tests__/layout.test.ts +20 -26
- package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
- package/src/core/cells/__tests__/session.test.ts +26 -146
- package/src/core/cells/actions.ts +49 -9
- package/src/core/cells/cell.ts +0 -13
- package/src/core/cells/cells.ts +53 -62
- package/src/core/cells/focus.ts +6 -1
- package/src/core/cells/layout.ts +2 -3
- package/src/core/cells/outputs.ts +2 -2
- package/src/core/cells/session.ts +3 -38
- package/src/core/cells/types.ts +6 -8
- package/src/core/cells/utils.ts +4 -3
- package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
- package/src/core/errors/__tests__/error-entries.test.ts +52 -18
- package/src/core/errors/error-entries.ts +21 -11
- package/src/core/executions/__tests__/freshness.test.ts +7 -4
- package/src/core/executions/__tests__/hooks.test.tsx +5 -1
- package/src/core/executions/__tests__/interrupt.test.ts +2 -0
- package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
- package/src/core/executions/__tests__/output.test.ts +87 -3
- package/src/core/executions/__tests__/select.test.ts +17 -10
- package/src/core/executions/atoms.ts +73 -15
- package/src/core/executions/freshness.ts +1 -1
- package/src/core/executions/hooks.ts +18 -8
- package/src/core/executions/index.ts +6 -0
- package/src/core/executions/output.ts +122 -38
- package/src/core/executions/select.ts +2 -2
- package/src/core/export/__tests__/hooks.test.ts +20 -29
- package/src/core/export/hooks.ts +7 -9
- package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
- package/src/core/islands/__tests__/main.test.ts +17 -0
- package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
- package/src/core/islands/components/output-wrapper.tsx +15 -20
- package/src/core/islands/iframe-resizer.ts +38 -0
- package/src/core/islands/main.ts +3 -0
- package/src/core/lifecycle/render-policy.ts +7 -4
- package/src/core/network/__tests__/ai.test.ts +41 -0
- package/src/core/network/ai.ts +12 -0
- package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
- package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
- package/src/core/notebook/replica/index.ts +1 -1
- package/src/core/notebook/replica/replica.ts +19 -4
- package/src/core/notebook/replica/resources/executions.ts +100 -9
- package/src/core/notebook/replica/resources/results.ts +46 -31
- package/src/core/transports/__tests__/static.test.ts +5 -3
- package/src/stories/cell.stories.tsx +40 -30
- package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
|
@@ -11,6 +11,7 @@ import { EditorView } from "@codemirror/view";
|
|
|
11
11
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
12
12
|
import { createStore } from "jotai";
|
|
13
13
|
import { mockDocumentModel } from "@/__mocks__/document";
|
|
14
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
14
15
|
import type { CellId } from "@/core/cells/ids";
|
|
15
16
|
import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
|
|
16
17
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
@@ -35,6 +36,8 @@ export function setupNotebook(
|
|
|
35
36
|
);
|
|
36
37
|
const controller = new AbortController();
|
|
37
38
|
stops.push(stop, () => controller.abort());
|
|
39
|
+
/** What the host shows for each cell, by cell id. */
|
|
40
|
+
const results = new Map<string, Protocol.Execution>();
|
|
38
41
|
followDocument({
|
|
39
42
|
store,
|
|
40
43
|
model,
|
|
@@ -88,18 +91,17 @@ export function setupNotebook(
|
|
|
88
91
|
};
|
|
89
92
|
return view;
|
|
90
93
|
},
|
|
91
|
-
/** Give a cell's output a heading, as the
|
|
92
|
-
heading: (id: string, level: number) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})),
|
|
94
|
+
/** Give a cell's output a heading, as the host would report it. */
|
|
95
|
+
heading: (id: string, level: number) => {
|
|
96
|
+
results.set(
|
|
97
|
+
id,
|
|
98
|
+
MockExecutions.shown(id, {
|
|
99
|
+
mimetype: "text/html",
|
|
100
|
+
data: `<h${level} id="${id}">H${level}</h${level}>`,
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
MockExecutions.seed(store, [...results.values()]);
|
|
104
|
+
},
|
|
103
105
|
visible: () => store.get(layoutAtom).columns[0].visible,
|
|
104
106
|
/** Apply a reducer action, as `useReducerActions()` does. */
|
|
105
107
|
dispatch: (action: Parameters<typeof notebookReducer>[1]) =>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import type * as Protocol from "@marimo-team/client/protocol";
|
|
3
4
|
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
4
6
|
import { cellId } from "@/__tests__/branded";
|
|
5
7
|
import type { CellColumnId } from "@/core/cells/layout";
|
|
6
8
|
import type { CellId } from "../ids";
|
|
@@ -131,45 +133,37 @@ describe("layoutAtom", () => {
|
|
|
131
133
|
const [c1, c2] = ["c1", "c2"].map(cellId);
|
|
132
134
|
|
|
133
135
|
/** Deliver `html` as a cell's output, as the kernel's message does. */
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
html: string
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
channel: "output",
|
|
145
|
-
mimetype: "text/html",
|
|
146
|
-
data: html,
|
|
147
|
-
timestamp: 1,
|
|
148
|
-
},
|
|
149
|
-
console: null,
|
|
150
|
-
status: "idle",
|
|
151
|
-
timestamp: 1,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
136
|
+
/** Report what the host shows for a cell, keeping the other cells' outputs. */
|
|
137
|
+
function reporter(store: ReturnType<typeof setupNotebook>["store"]) {
|
|
138
|
+
const results = new Map<CellId, Protocol.Execution>();
|
|
139
|
+
return (id: CellId, html: string) => {
|
|
140
|
+
results.set(
|
|
141
|
+
id,
|
|
142
|
+
MockExecutions.shown(id, { mimetype: "text/html", data: html }),
|
|
143
|
+
);
|
|
144
|
+
MockExecutions.seed(store, [...results.values()]);
|
|
145
|
+
};
|
|
154
146
|
}
|
|
155
147
|
|
|
156
148
|
it("is the same layout after output that changes no heading", () => {
|
|
157
|
-
const { store
|
|
158
|
-
output
|
|
149
|
+
const { store } = setupNotebook(stops);
|
|
150
|
+
const output = reporter(store);
|
|
151
|
+
output(c1, "<h1>Title</h1>");
|
|
159
152
|
const layout = store.get(layoutAtom);
|
|
160
153
|
|
|
161
|
-
output(
|
|
162
|
-
output(
|
|
154
|
+
output(c2, "<p>1</p>");
|
|
155
|
+
output(c1, "<h1>Title</h1>");
|
|
163
156
|
|
|
164
157
|
expect(store.get(layoutAtom)).toBe(layout);
|
|
165
158
|
});
|
|
166
159
|
|
|
167
160
|
it("follows a heading arriving in a cell's output", () => {
|
|
168
|
-
const { store
|
|
161
|
+
const { store } = setupNotebook(stops);
|
|
162
|
+
const output = reporter(store);
|
|
169
163
|
store.set(collapsedAtom, new Set([c1]));
|
|
170
164
|
expect(store.get(layoutAtom).columns[0].folds.size).toBe(0);
|
|
171
165
|
|
|
172
|
-
output(
|
|
166
|
+
output(c1, "<h1>Title</h1>");
|
|
173
167
|
|
|
174
168
|
expect(store.get(layoutAtom).columns[0].folds.get(c1)).toEqual([c2]);
|
|
175
169
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { createStore } from "jotai";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { MockExecutions } from "@/__mocks__/executions";
|
|
5
6
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
6
7
|
import { cellId } from "@/__tests__/branded";
|
|
7
8
|
import { CONFIG } from "@/core/notebook/document/__tests__/fixtures";
|
|
@@ -11,16 +12,17 @@ import {
|
|
|
11
12
|
notebookOutline,
|
|
12
13
|
notebookReducer,
|
|
13
14
|
} from "../cells";
|
|
14
|
-
import type { Outline } from "../outline";
|
|
15
15
|
|
|
16
16
|
const first = cellId("first");
|
|
17
17
|
const second = cellId("second");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
|
|
19
|
+
/** A completed execution that showed `html`. */
|
|
20
|
+
function showed(id: string, html: string) {
|
|
21
|
+
return MockExecutions.shown(id, { mimetype: "text/html", data: html });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const firstItem = { name: "First", level: 1, by: { id: "first" } };
|
|
25
|
+
const secondItem = { name: "Second", level: 2, by: { id: "second" } };
|
|
24
26
|
|
|
25
27
|
function setup() {
|
|
26
28
|
const store = createStore();
|
|
@@ -28,19 +30,32 @@ function setup() {
|
|
|
28
30
|
notebookAtom,
|
|
29
31
|
MockNotebook.notebookState({
|
|
30
32
|
cellData: { [first]: { code: "x = 1" }, [second]: {} },
|
|
31
|
-
cellRuntime: {
|
|
32
|
-
[first]: { outline: firstOutline },
|
|
33
|
-
[second]: { outline: secondOutline },
|
|
34
|
-
},
|
|
35
33
|
}),
|
|
36
34
|
);
|
|
35
|
+
const replica = MockExecutions.seed(store, [
|
|
36
|
+
showed(first, '<h1 id="first">First</h1>'),
|
|
37
|
+
showed(second, '<h2 id="second">Second</h2>'),
|
|
38
|
+
]);
|
|
37
39
|
const actions = createNotebookActions((action) =>
|
|
38
40
|
store.set(notebookAtom, (state) => notebookReducer(state, action)),
|
|
39
41
|
);
|
|
40
|
-
|
|
42
|
+
/** Replace what the host reports for the cells. */
|
|
43
|
+
const report = (records: ReturnType<typeof showed>[]) => {
|
|
44
|
+
const next = MockExecutions.inputs(records);
|
|
45
|
+
store.set(replica.executionsAtom, next.executions);
|
|
46
|
+
store.set(replica.resultsAtom, next.results);
|
|
47
|
+
};
|
|
48
|
+
return { store, actions, report };
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
describe("notebookOutline", () => {
|
|
52
|
+
it("reads headings from the host's outputs in cell order", () => {
|
|
53
|
+
const { store } = setup();
|
|
54
|
+
expect(store.get(notebookOutline)).toEqual({
|
|
55
|
+
items: [firstItem, secondItem],
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
44
59
|
it("does not notify outline subscribers when cell code changes", () => {
|
|
45
60
|
const { store } = setup();
|
|
46
61
|
const initial = store.get(notebookOutline);
|
|
@@ -60,24 +75,19 @@ describe("notebookOutline", () => {
|
|
|
60
75
|
unsubscribe();
|
|
61
76
|
});
|
|
62
77
|
|
|
63
|
-
it("updates headings when
|
|
64
|
-
const { store } = setup();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}));
|
|
77
|
-
expect(store.get(notebookOutline)).toEqual({
|
|
78
|
-
items: [...(outline?.items ?? []), ...secondOutline.items],
|
|
79
|
-
});
|
|
80
|
-
}
|
|
78
|
+
it("updates headings when outputs change or are removed", () => {
|
|
79
|
+
const { store, report } = setup();
|
|
80
|
+
|
|
81
|
+
report([
|
|
82
|
+
showed(first, '<h1 id="updated">Updated</h1>'),
|
|
83
|
+
showed(second, '<h2 id="second">Second</h2>'),
|
|
84
|
+
]);
|
|
85
|
+
expect(store.get(notebookOutline)).toEqual({
|
|
86
|
+
items: [{ name: "Updated", level: 1, by: { id: "updated" } }, secondItem],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
report([showed(second, '<h2 id="second">Second</h2>')]);
|
|
90
|
+
expect(store.get(notebookOutline)).toEqual({ items: [secondItem] });
|
|
81
91
|
});
|
|
82
92
|
|
|
83
93
|
it("keeps headings in cell order after moving and deleting cells", () => {
|
|
@@ -90,7 +100,7 @@ describe("notebookOutline", () => {
|
|
|
90
100
|
]),
|
|
91
101
|
});
|
|
92
102
|
expect(store.get(notebookOutline)).toEqual({
|
|
93
|
-
items: [
|
|
103
|
+
items: [secondItem, firstItem],
|
|
94
104
|
});
|
|
95
105
|
|
|
96
106
|
actions.reconcileDocument({
|
|
@@ -99,24 +109,20 @@ describe("notebookOutline", () => {
|
|
|
99
109
|
[first, { id: first, code: "x = 1", name: "_", config: CONFIG }],
|
|
100
110
|
]),
|
|
101
111
|
});
|
|
102
|
-
expect(store.get(notebookOutline)).toEqual(
|
|
112
|
+
expect(store.get(notebookOutline)).toEqual({ items: [firstItem] });
|
|
103
113
|
});
|
|
104
114
|
|
|
105
|
-
it("
|
|
106
|
-
const { store } = setup();
|
|
115
|
+
it("leaves subscribers alone when a run shows the same output again", () => {
|
|
116
|
+
const { store, report } = setup();
|
|
107
117
|
const listener = vi.fn();
|
|
108
118
|
const unsubscribe = store.sub(notebookOutline, listener);
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
[first]: { ...state.cellRuntime[first], outline: { ...firstOutline } },
|
|
115
|
-
},
|
|
116
|
-
}));
|
|
120
|
+
report([
|
|
121
|
+
showed(first, '<h1 id="first">First</h1>'),
|
|
122
|
+
showed(second, '<h2 id="second">Second</h2>'),
|
|
123
|
+
]);
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
expect(listener).toHaveBeenCalledOnce();
|
|
125
|
+
expect(listener).not.toHaveBeenCalled();
|
|
120
126
|
unsubscribe();
|
|
121
127
|
});
|
|
122
128
|
});
|
|
@@ -5,7 +5,6 @@ import type * as api from "@marimo-team/marimo-api";
|
|
|
5
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import { Mocks } from "@/__mocks__/common";
|
|
7
7
|
import { cellId } from "@/__tests__/branded";
|
|
8
|
-
import { parseOutline } from "@/core/dom/outline";
|
|
9
8
|
import { invariant } from "@/utils/invariant";
|
|
10
9
|
import { Logger } from "@/utils/Logger";
|
|
11
10
|
import { SETUP_CELL_ID } from "../ids";
|
|
@@ -14,10 +13,6 @@ import { readExport } from "../session";
|
|
|
14
13
|
// Mock dependencies
|
|
15
14
|
vi.mock("@/utils/Logger", () => ({ Logger: Mocks.quietLogger() }));
|
|
16
15
|
|
|
17
|
-
vi.mock("@/core/dom/outline", () => ({
|
|
18
|
-
parseOutline: vi.fn(),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
16
|
type SessionCell = api.Session["NotebookSessionV1"]["cells"][0];
|
|
22
17
|
type NotebookCell = api.Notebook["NotebookV1"]["cells"][0];
|
|
23
18
|
|
|
@@ -179,15 +174,6 @@ describe("readExport", () => {
|
|
|
179
174
|
: { mimetype: "text/plain", data: expectedTraceback },
|
|
180
175
|
}),
|
|
181
176
|
});
|
|
182
|
-
expect(result.cellRuntime[cellId("c1")].output?.data).toEqual([
|
|
183
|
-
{
|
|
184
|
-
type: "exception",
|
|
185
|
-
exception_type: "ValueError",
|
|
186
|
-
msg: "bad",
|
|
187
|
-
raising_cell: null,
|
|
188
|
-
traceback: expectedTraceback,
|
|
189
|
-
},
|
|
190
|
-
]);
|
|
191
177
|
},
|
|
192
178
|
);
|
|
193
179
|
});
|
|
@@ -327,21 +313,17 @@ describe("readExport", () => {
|
|
|
327
313
|
appConfig: {},
|
|
328
314
|
});
|
|
329
315
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
raising_cell: null,
|
|
339
|
-
traceback: "Traceback line 1",
|
|
340
|
-
},
|
|
341
|
-
],
|
|
342
|
-
mimetype: "application/vnd.marimo+error",
|
|
343
|
-
timestamp: 0,
|
|
316
|
+
expect(result.snapshot?.results[0]?.outcome).toEqual({
|
|
317
|
+
kind: "error",
|
|
318
|
+
error: expect.objectContaining({
|
|
319
|
+
kind: "exception",
|
|
320
|
+
name: "ValueError",
|
|
321
|
+
message: "Something went wrong",
|
|
322
|
+
traceback: { mimetype: "text/plain", data: "Traceback line 1" },
|
|
323
|
+
}),
|
|
344
324
|
});
|
|
325
|
+
|
|
326
|
+
invariant(result.snapshot, "no snapshot");
|
|
345
327
|
});
|
|
346
328
|
|
|
347
329
|
it("restores matching code from the session", () => {
|
|
@@ -377,17 +359,6 @@ describe("readExport", () => {
|
|
|
377
359
|
appConfig: {},
|
|
378
360
|
});
|
|
379
361
|
invariant(state.snapshot, "no snapshot");
|
|
380
|
-
expect(state.cellRuntime[CELL_1].output).toMatchObject({
|
|
381
|
-
code,
|
|
382
|
-
data: [
|
|
383
|
-
{
|
|
384
|
-
type: "exception",
|
|
385
|
-
exception_type: "ValueError",
|
|
386
|
-
msg: "cached failure",
|
|
387
|
-
traceback: "Traceback\nValueError: cached failure",
|
|
388
|
-
},
|
|
389
|
-
],
|
|
390
|
-
});
|
|
391
362
|
expect(state.cellRuntime[CELL_1].consoleOutputs[0].code).toBe(code);
|
|
392
363
|
expect(state.cellRuntime[CELL_1].consoleOutputs[0]).toMatchObject({
|
|
393
364
|
traceback_format: "text",
|
|
@@ -412,13 +383,12 @@ describe("readExport", () => {
|
|
|
412
383
|
appConfig: {},
|
|
413
384
|
});
|
|
414
385
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
data: "Hello World",
|
|
419
|
-
mimetype: "text/plain",
|
|
420
|
-
timestamp: 0,
|
|
386
|
+
expect(result.snapshot?.results[0]?.outcome).toEqual({
|
|
387
|
+
kind: "value",
|
|
388
|
+
display: { mimetype: "text/plain", data: "Hello World" },
|
|
421
389
|
});
|
|
390
|
+
|
|
391
|
+
invariant(result.snapshot, "no snapshot");
|
|
422
392
|
});
|
|
423
393
|
|
|
424
394
|
it("handles console outputs in session cell", () => {
|
|
@@ -462,48 +432,6 @@ describe("readExport", () => {
|
|
|
462
432
|
},
|
|
463
433
|
]);
|
|
464
434
|
});
|
|
465
|
-
|
|
466
|
-
it("calls parseOutline when output exists", () => {
|
|
467
|
-
const mockOutline = { items: [] };
|
|
468
|
-
vi.mocked(parseOutline).mockReturnValue(mockOutline);
|
|
469
|
-
|
|
470
|
-
const dataOutput = {
|
|
471
|
-
type: "data" as const,
|
|
472
|
-
data: { "text/html": "<h1>Title</h1>" },
|
|
473
|
-
};
|
|
474
|
-
const session = createSession([
|
|
475
|
-
createSessionCell("cell-1", [dataOutput]),
|
|
476
|
-
]);
|
|
477
|
-
const result = readExport({
|
|
478
|
-
session: session,
|
|
479
|
-
notebook: null,
|
|
480
|
-
filename: null,
|
|
481
|
-
appConfig: {},
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
expect(parseOutline).toHaveBeenCalledWith({
|
|
485
|
-
channel: "output",
|
|
486
|
-
data: "<h1>Title</h1>",
|
|
487
|
-
mimetype: "text/html",
|
|
488
|
-
timestamp: 0,
|
|
489
|
-
});
|
|
490
|
-
invariant(result.snapshot, "no snapshot");
|
|
491
|
-
expect(result.cellRuntime[CELL_1].outline).toBe(mockOutline);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it("sets outline to null when no output exists", () => {
|
|
495
|
-
const session = createSession([createSessionCell("cell-1")]);
|
|
496
|
-
const result = readExport({
|
|
497
|
-
session: session,
|
|
498
|
-
notebook: null,
|
|
499
|
-
filename: null,
|
|
500
|
-
appConfig: {},
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
expect(parseOutline).not.toHaveBeenCalled();
|
|
504
|
-
invariant(result.snapshot, "no snapshot");
|
|
505
|
-
expect(result.cellRuntime[CELL_1].outline).toBeNull();
|
|
506
|
-
});
|
|
507
435
|
});
|
|
508
436
|
|
|
509
437
|
describe("notebook only scenarios", () => {
|
|
@@ -790,9 +718,7 @@ describe("readExport", () => {
|
|
|
790
718
|
});
|
|
791
719
|
|
|
792
720
|
invariant(result.snapshot, "no snapshot");
|
|
793
|
-
expect(result.cellRuntime[CELL_1].output).toBeNull();
|
|
794
721
|
expect(result.cellRuntime[CELL_1].consoleOutputs).toEqual([]);
|
|
795
|
-
expect(result.cellRuntime[CELL_1].outline).toBeNull();
|
|
796
722
|
});
|
|
797
723
|
|
|
798
724
|
it("handles session cell with empty console array", () => {
|
|
@@ -821,12 +747,9 @@ describe("readExport", () => {
|
|
|
821
747
|
appConfig: {},
|
|
822
748
|
});
|
|
823
749
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
data: "First",
|
|
828
|
-
mimetype: "text/plain",
|
|
829
|
-
timestamp: 0,
|
|
750
|
+
expect(result.snapshot?.results[0]?.outcome).toEqual({
|
|
751
|
+
kind: "value",
|
|
752
|
+
display: { mimetype: "text/plain", data: "First" },
|
|
830
753
|
});
|
|
831
754
|
});
|
|
832
755
|
|
|
@@ -848,13 +771,12 @@ describe("readExport", () => {
|
|
|
848
771
|
appConfig: {},
|
|
849
772
|
});
|
|
850
773
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
data: "Plain text",
|
|
855
|
-
mimetype: "text/plain",
|
|
856
|
-
timestamp: 0,
|
|
774
|
+
expect(result.snapshot?.results[0]?.outcome).toEqual({
|
|
775
|
+
kind: "value",
|
|
776
|
+
display: { mimetype: "text/plain", data: "Plain text" },
|
|
857
777
|
});
|
|
778
|
+
|
|
779
|
+
invariant(result.snapshot, "no snapshot");
|
|
858
780
|
});
|
|
859
781
|
|
|
860
782
|
it("handles data output with empty data object", () => {
|
|
@@ -872,12 +794,9 @@ describe("readExport", () => {
|
|
|
872
794
|
appConfig: {},
|
|
873
795
|
});
|
|
874
796
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
data: undefined,
|
|
879
|
-
mimetype: undefined,
|
|
880
|
-
timestamp: 0,
|
|
797
|
+
expect(result.snapshot?.results[0]?.outcome).toEqual({
|
|
798
|
+
kind: "value",
|
|
799
|
+
display: null,
|
|
881
800
|
});
|
|
882
801
|
});
|
|
883
802
|
|
|
@@ -1020,12 +939,6 @@ describe("readExport", () => {
|
|
|
1020
939
|
for (const code of ["a", "b", "c", "d", "e", "f"]) {
|
|
1021
940
|
const cid = cellId(`cell-${code}`);
|
|
1022
941
|
expect(cellIn(result, cid).code).toBe(code);
|
|
1023
|
-
expect(result.cellRuntime[cid].output).toEqual({
|
|
1024
|
-
channel: "output",
|
|
1025
|
-
data: `${code.toUpperCase()}!`,
|
|
1026
|
-
mimetype: "text/plain",
|
|
1027
|
-
timestamp: 0,
|
|
1028
|
-
});
|
|
1029
942
|
}
|
|
1030
943
|
});
|
|
1031
944
|
|
|
@@ -1137,28 +1050,8 @@ describe("readExport", () => {
|
|
|
1137
1050
|
expect(cellIn(result, "cell-g").code).toBe("g");
|
|
1138
1051
|
|
|
1139
1052
|
// Should have session outputs for matching cells (a, c, e)
|
|
1140
|
-
expect(result.cellRuntime[cellId("cell-a")].output).toEqual({
|
|
1141
|
-
channel: "output",
|
|
1142
|
-
data: "A!",
|
|
1143
|
-
mimetype: "text/plain",
|
|
1144
|
-
timestamp: 0,
|
|
1145
|
-
});
|
|
1146
|
-
expect(result.cellRuntime[cellId("cell-c")].output).toEqual({
|
|
1147
|
-
channel: "output",
|
|
1148
|
-
data: "C!",
|
|
1149
|
-
mimetype: "text/plain",
|
|
1150
|
-
timestamp: 0,
|
|
1151
|
-
});
|
|
1152
|
-
expect(result.cellRuntime[cellId("cell-e")].output).toEqual({
|
|
1153
|
-
channel: "output",
|
|
1154
|
-
data: "E!",
|
|
1155
|
-
mimetype: "text/plain",
|
|
1156
|
-
timestamp: 0,
|
|
1157
|
-
});
|
|
1158
1053
|
|
|
1159
1054
|
// Should have no output for new cells (z, g) - they get stub session cells
|
|
1160
|
-
expect(result.cellRuntime[cellId("cell-z")].output).toBeNull();
|
|
1161
|
-
expect(result.cellRuntime[cellId("cell-g")].output).toBeNull();
|
|
1162
1055
|
|
|
1163
1056
|
// Should log warning about different cells
|
|
1164
1057
|
expect(Logger.warn).toHaveBeenCalledWith(
|
|
@@ -1274,24 +1167,11 @@ describe("readExport", () => {
|
|
|
1274
1167
|
expect(cellIn(result, "cell-3").code).toBe("x = mo.ui.slider(0, 10)");
|
|
1275
1168
|
|
|
1276
1169
|
// cell-1: No matching session cell (hash is null), gets stub session cell
|
|
1277
|
-
expect(result.cellRuntime[cellId("cell-1")].output).toBeNull();
|
|
1278
1170
|
expect(result.cellRuntime[cellId("cell-1")].consoleOutputs).toEqual([]);
|
|
1279
1171
|
|
|
1280
1172
|
// cell-2: Matches session cell-1 by hash (moMd), gets its output
|
|
1281
|
-
expect(result.cellRuntime[cellId("cell-2")].output).toEqual({
|
|
1282
|
-
channel: "output",
|
|
1283
|
-
data: "Welcome to marimo!",
|
|
1284
|
-
mimetype: "text/markdown",
|
|
1285
|
-
timestamp: 0,
|
|
1286
|
-
});
|
|
1287
1173
|
|
|
1288
1174
|
// cell-3: Matches session cell-2 by hash (slider), gets its output
|
|
1289
|
-
expect(result.cellRuntime[cellId("cell-3")].output).toEqual({
|
|
1290
|
-
channel: "output",
|
|
1291
|
-
data: "",
|
|
1292
|
-
mimetype: "text/plain",
|
|
1293
|
-
timestamp: 0,
|
|
1294
|
-
});
|
|
1295
1175
|
|
|
1296
1176
|
// Should log warning about different cells (merge had edit distance > 0)
|
|
1297
1177
|
expect(Logger.warn).toHaveBeenCalledWith(
|
|
@@ -6,7 +6,12 @@ import { historyField } from "@codemirror/commands";
|
|
|
6
6
|
import { atom, type Getter, type Setter, useSetAtom } from "jotai";
|
|
7
7
|
import { useMemo } from "react";
|
|
8
8
|
import { scrollAndHighlightCell } from "@/components/editor/links/cell-link";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
cellExecutionInputsAtom,
|
|
11
|
+
cellOutlineAtom,
|
|
12
|
+
clearCellOutputs,
|
|
13
|
+
runningCellIds,
|
|
14
|
+
} from "@/core/executions";
|
|
10
15
|
import type { EditableDocument } from "@/core/notebook/document";
|
|
11
16
|
import { Logger } from "@/utils/Logger";
|
|
12
17
|
import { clamp } from "@/utils/math";
|
|
@@ -196,7 +201,7 @@ export const splitCellAtom = atom(
|
|
|
196
201
|
tx.setCode(cellId, beforeCursorCode);
|
|
197
202
|
tx.createCell({ id, code: afterCursorCode }, { after: cellId });
|
|
198
203
|
});
|
|
199
|
-
clearOutput(set, cellId);
|
|
204
|
+
clearOutput(get, set, cellId);
|
|
200
205
|
focusWhenMounted(set, id);
|
|
201
206
|
return id;
|
|
202
207
|
},
|
|
@@ -227,17 +232,47 @@ export const undoSplitCellAtom = atom(
|
|
|
227
232
|
}
|
|
228
233
|
});
|
|
229
234
|
releaseCellAtoms(newCellId);
|
|
230
|
-
clearOutput(set, cellId);
|
|
235
|
+
clearOutput(get, set, cellId);
|
|
231
236
|
},
|
|
232
237
|
);
|
|
233
238
|
|
|
234
239
|
/** The output belonged to the code before the change; neither version has run. */
|
|
235
|
-
function clearOutput(set: Setter, cellId: CellId): void {
|
|
236
|
-
|
|
237
|
-
|
|
240
|
+
function clearOutput(get: Getter, set: Setter, cellId: CellId): void {
|
|
241
|
+
clearOutputs({ get, set }, [cellId]);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Hide what `cellIds` show, in the output area and the console.
|
|
246
|
+
*
|
|
247
|
+
* The output stays hidden until a newer result lands. A prompt the kernel
|
|
248
|
+
* is still waiting on stays, since the cell cannot finish without it.
|
|
249
|
+
*/
|
|
250
|
+
function clearOutputs(
|
|
251
|
+
store: { get: Getter; set: Setter },
|
|
252
|
+
cellIds: readonly CellId[],
|
|
253
|
+
): void {
|
|
254
|
+
clearCellOutputs(store, cellIds);
|
|
255
|
+
store.set(notebookAtom, (state) =>
|
|
256
|
+
notebookReducer(state, {
|
|
257
|
+
type: "clearCellConsoleOutputs",
|
|
258
|
+
payload: { cellIds },
|
|
259
|
+
}),
|
|
238
260
|
);
|
|
239
261
|
}
|
|
240
262
|
|
|
263
|
+
/** Clear one cell's output. */
|
|
264
|
+
export const clearCellOutputAtom = atom(
|
|
265
|
+
null,
|
|
266
|
+
(get, set, { cellId }: { cellId: CellId }): void => {
|
|
267
|
+
clearOutputs({ get, set }, [cellId]);
|
|
268
|
+
},
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
/** Clear every cell's output. */
|
|
272
|
+
export const clearAllCellOutputsAtom = atom(null, (get, set): void => {
|
|
273
|
+
clearOutputs({ get, set }, get(notebookAtom).cellIds);
|
|
274
|
+
});
|
|
275
|
+
|
|
241
276
|
/**
|
|
242
277
|
* Focus the cell before or after `cellId`. Past the edge of the column,
|
|
243
278
|
* create one there, unless `create` is false.
|
|
@@ -350,7 +385,7 @@ function unfoldSections(set: Setter, headers: readonly CellId[]): void {
|
|
|
350
385
|
export const collapseCellAtom = atom(
|
|
351
386
|
null,
|
|
352
387
|
(get, set, { cellId }: { cellId: CellId }): void => {
|
|
353
|
-
if (!canCollapseOutline(get(
|
|
388
|
+
if (!canCollapseOutline(get(cellOutlineAtom(cellId)))) {
|
|
354
389
|
return;
|
|
355
390
|
}
|
|
356
391
|
set(collapsedAtom, (collapsed) => new Set([...collapsed, cellId]));
|
|
@@ -369,11 +404,12 @@ export const expandCellAtom = atom(
|
|
|
369
404
|
|
|
370
405
|
/** Fold every section in the notebook. */
|
|
371
406
|
export const collapseAllCellsAtom = atom(null, (get, set): void => {
|
|
372
|
-
const { cellIds, cellRuntime } = get(notebookAtom);
|
|
373
407
|
set(
|
|
374
408
|
collapsedAtom,
|
|
375
409
|
new Set(
|
|
376
|
-
cellIds.filter((id) =>
|
|
410
|
+
get(notebookAtom).cellIds.filter((id) =>
|
|
411
|
+
canCollapseOutline(get(cellOutlineAtom(id))),
|
|
412
|
+
),
|
|
377
413
|
),
|
|
378
414
|
);
|
|
379
415
|
});
|
|
@@ -619,6 +655,8 @@ export function useCellActions() {
|
|
|
619
655
|
const expandCell = useSetAtom(expandCellAtom);
|
|
620
656
|
const collapseAllCells = useSetAtom(collapseAllCellsAtom);
|
|
621
657
|
const expandAllCells = useSetAtom(expandAllCellsAtom);
|
|
658
|
+
const clearCellOutput = useSetAtom(clearCellOutputAtom);
|
|
659
|
+
const clearAllCellOutputs = useSetAtom(clearAllCellOutputsAtom);
|
|
622
660
|
const showCellIfHidden = useSetAtom(showCellIfHiddenAtom);
|
|
623
661
|
const moveCell = useSetAtom(moveCellAtom);
|
|
624
662
|
const moveCellToIndex = useSetAtom(moveCellToIndexAtom);
|
|
@@ -668,6 +706,8 @@ export function useCellActions() {
|
|
|
668
706
|
expandCell,
|
|
669
707
|
collapseAllCells,
|
|
670
708
|
expandAllCells,
|
|
709
|
+
clearCellOutput,
|
|
710
|
+
clearAllCellOutputs,
|
|
671
711
|
showCellIfHidden,
|
|
672
712
|
}),
|
|
673
713
|
// The reducer's actions and the atom setters are stable for the store's lifetime.
|