@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev394

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 (166) hide show
  1. package/dist/{ConnectedDataExplorerComponent-BpCrAeX0.js → ConnectedDataExplorerComponent-1DGGwl88.js} +9 -9
  2. package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DDIASniH.js} +6 -6
  3. package/dist/{abnfDiagram-VCTEODGH-ZqNgGZlz.js → abnfDiagram-VCTEODGH-CeQEbVik.js} +2 -2
  4. package/dist/{any-language-editor-CFbAr7vc.js → any-language-editor-C_s_ZoaK.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-BEUaR96d.js → architectureDiagram-5GKGNRK7-C8xUpTAb.js} +1 -1
  6. package/dist/{assertNever-5uYEbJc8.js → assertNever-DXGfUmPW.js} +2 -2
  7. package/dist/assets/__vite-browser-external-C9HF3uHE.js +1 -0
  8. package/dist/assets/worker-B4Cpvr8b.js +171 -0
  9. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-B6bY_0LF.js} +774 -774
  10. package/dist/{check-BbhVyViy.js → check-ywinAQy6.js} +1 -1
  11. package/dist/{chunk-IMKFNOWR-BdEPmWQI.js → chunk-IMKFNOWR-DY7AWyNi.js} +1 -1
  12. package/dist/{chunk-SHT3W25Y-IvvXM3xf.js → chunk-SHT3W25Y-D4epY9MY.js} +1 -1
  13. package/dist/{chunk-SVP7TREG-C_qpJUv1.js → chunk-SVP7TREG-CKsl2Q6r.js} +1 -1
  14. package/dist/{chunk-TICWLB2K-C4agYVWP.js → chunk-TICWLB2K-CMsD2y0F.js} +1 -1
  15. package/dist/{classDiagram-ZZMXUADV-CT2iq8uF.js → classDiagram-ZZMXUADV-C4FsLnvt.js} +2 -2
  16. package/dist/{classDiagram-v2-VYDZK3BY-Coe_dD0r.js → classDiagram-v2-VYDZK3BY-BJRuFZeI.js} +2 -2
  17. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-CByYqwFv.js} +13 -13
  18. package/dist/{common-Ces9ooG_.js → common-KkgATX2Y.js} +4918 -4910
  19. package/dist/{config-DJ8M-gPL.js → config-DOwBtRkI.js} +3 -3
  20. package/dist/{copy-icon-xWvA8ybp.js → copy-icon-BKcX0ltw.js} +2 -2
  21. package/dist/{createReducer-fp0gX_9U.js → createReducer-Bjx6kuxh.js} +1 -1
  22. package/dist/{cynefinDiagram-5FMLGOSQ-D0LKziUu.js → cynefinDiagram-5FMLGOSQ-DyI_lSsn.js} +1 -1
  23. package/dist/{dagre-GXQ25YYZ-Cmgziaw8.js → dagre-GXQ25YYZ-Buoy6sX-.js} +1 -1
  24. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-BHrTJhN3.js} +1 -1
  25. package/dist/{diagram-S7CK7UJ4-D-lZsALU.js → diagram-S7CK7UJ4-CbSD1DUy.js} +1 -1
  26. package/dist/{diagram-UQ7AKVKN-TcbdsFoT.js → diagram-UQ7AKVKN-Dapj2rQm.js} +1 -1
  27. package/dist/{diagram-VX7I27RA-D5BqZi1q.js → diagram-VX7I27RA-CxA3txtC.js} +1 -1
  28. package/dist/{diagram-Z3DM3KII-MNc7jqvr.js → diagram-Z3DM3KII-BEZqz916.js} +1 -1
  29. package/dist/{dialog-Cm0VGdxc.js → dialog-mwa6XN15.js} +2 -2
  30. package/dist/{dropdown-menu-DfamXjVI.js → dropdown-menu-CmgUseHo.js} +5 -5
  31. package/dist/duckdb-keywords-CdzX4o33.js +3 -0
  32. package/dist/{ebnfDiagram-PWID7BFC-Cxt6ywyX.js → ebnfDiagram-PWID7BFC-Dmw-1JV3.js} +2 -2
  33. package/dist/{erDiagram-RLTQ6QDP-BLF-askI.js → erDiagram-RLTQ6QDP-DZpG4cbm.js} +1 -1
  34. package/dist/{error-banner-k06CAftu.js → error-banner-CHPLqogX.js} +1 -1
  35. package/dist/{error-entries-rtPWQkJk.js → error-entries-Bk96zt4w.js} +825 -690
  36. package/dist/{feedback-button-i960qUnq.js → feedback-button-2FaWjlaR.js} +12 -12
  37. package/dist/{flowDiagram-HODETNUW-CsLw2mWn.js → flowDiagram-HODETNUW-B02oHnBv.js} +2 -2
  38. package/dist/{formats-DQ-qq-dU.js → formats-BDqe9cfr.js} +1 -1
  39. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-B9Yq6Wg1.js} +11 -11
  40. package/dist/{glide-utils-CHrghEu-.js → glide-utils-DYKWS2YV.js} +2 -2
  41. package/dist/{globals-DKkjIolp.js → globals-S4D5AVKN.js} +3 -3
  42. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-BauFF9F_.js} +4842 -4821
  43. package/dist/{infoDiagram-27XIBGKW-CdSApBWg.js → infoDiagram-27XIBGKW-BPbQHO9m.js} +1 -1
  44. package/dist/{ishikawaDiagram-5VMMS53U-BnzQ8SI5.js → ishikawaDiagram-5VMMS53U-DmnKSNi7.js} +1 -1
  45. package/dist/{kanban-definition-UXKFOSKX-D2llTpeX.js → kanban-definition-UXKFOSKX-u5PZbsBe.js} +1 -1
  46. package/dist/main.js +6236 -6175
  47. package/dist/{mermaid-BcNMyKmf.js → mermaid-ffopDjig.js} +34 -34
  48. package/dist/{mindmap-definition-YA3MSWOX-uoEsfD5R.js → mindmap-definition-YA3MSWOX-CX187lhP.js} +1 -1
  49. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-l7DB2HCO.js} +1 -1
  50. package/dist/{pegDiagram-XKGWAZYB-DTWrE0S4.js → pegDiagram-XKGWAZYB-Bj6HGPak.js} +2 -2
  51. package/dist/{pencil-weySvN0N.js → pencil-CijoRsa3.js} +1 -1
  52. package/dist/{pieDiagram-E7YTZNPT-COME2oGN.js → pieDiagram-E7YTZNPT-C_wIgDJM.js} +1 -1
  53. package/dist/{process-output-DNxpsd4n.js → process-output-Deae7dX1.js} +4 -4
  54. package/dist/{railroadDiagram-O6MQD6OU-CUeFcNTY.js → railroadDiagram-O6MQD6OU-CwoJvnvC.js} +2 -2
  55. package/dist/{requirementDiagram-BXWQKSXE-BUR4lDZG.js → requirementDiagram-BXWQKSXE-C8JuhLLL.js} +1 -1
  56. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-VR4UzAUv.js} +37 -37
  57. package/dist/{select-Ca-POp4c.js → select-DW32QOzC.js} +4 -4
  58. package/dist/{sequenceDiagram-WJ2MYXX4-CSPmml3q.js → sequenceDiagram-WJ2MYXX4-RbrRdoiV.js} +1 -1
  59. package/dist/{spec-BgSMwzks.js → spec-Ww0JjShW.js} +4 -4
  60. package/dist/{stateDiagram-D77RDMKH-BDUC8Pi9.js → stateDiagram-D77RDMKH-DWdIvCnU.js} +2 -2
  61. package/dist/{stateDiagram-v2-MP3YSRHH-BH-qyk8a.js → stateDiagram-v2-MP3YSRHH-BG0j9crW.js} +2 -2
  62. package/dist/{static-state-Cqzv5X7B.js → static-state-CnQdTBTW.js} +1 -1
  63. package/dist/style.css +1 -1
  64. package/dist/{swimlanes-42K2YHIH-CLE9Kiir.js → swimlanes-42K2YHIH-B6zUw4gq.js} +1 -1
  65. package/dist/{swimlanesDiagram-VR7AAH4N-Cv8kWAeA.js → swimlanesDiagram-VR7AAH4N-DjVEnsIG.js} +2 -2
  66. package/dist/{timeline-definition-24CTP7MA-fbRGX21i.js → timeline-definition-24CTP7MA-DSAxwqnC.js} +1 -1
  67. package/dist/{toast-0xspcdmv.js → toast-Crofa36R.js} +3 -3
  68. package/dist/{tooltip-BwlFTaNy.js → tooltip-Bg-SDCwa.js} +1 -1
  69. package/dist/{use-restore-focus-fKgXR0nb.js → use-restore-focus-CE9Sflmg.js} +1298 -1283
  70. package/dist/{useDateFormatter-B7LvPmsw.js → useDateFormatter-D5fsC9ot.js} +2 -2
  71. package/dist/{useDeepCompareMemoize-OhBYt-q2.js → useDeepCompareMemoize-Bvrue1iy.js} +1 -1
  72. package/dist/{useLifecycle-D9xcFAIN.js → useLifecycle-Ctr5lECo.js} +1 -1
  73. package/dist/{vega-component-Chak9Aon.js → vega-component-DQZhTzVQ.js} +6 -6
  74. package/dist/{vennDiagram-4TSXK5OY-BzKtg8gL.js → vennDiagram-4TSXK5OY-FAGYRdBj.js} +1 -1
  75. package/dist/{wardleyDiagram-VM6X3IG4-R0SgDvz1.js → wardleyDiagram-VM6X3IG4-BlB973r1.js} +1 -1
  76. package/dist/{xychartDiagram-S5SC5T6Z-DRskTHEM.js → xychartDiagram-S5SC5T6Z-CywvmjIK.js} +1 -1
  77. package/package.json +2 -2
  78. package/src/__mocks__/executions.ts +48 -8
  79. package/src/__mocks__/notebook.ts +20 -42
  80. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  81. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  82. package/src/components/app-config/ai-config.tsx +20 -24
  83. package/src/components/app-config/model-discovery.tsx +118 -184
  84. package/src/components/app-config/model-provider-config.ts +25 -0
  85. package/src/components/editor/Output.tsx +5 -4
  86. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  87. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  88. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  89. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  90. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  91. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  92. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  93. package/src/components/editor/notebook-cell.tsx +15 -10
  94. package/src/components/editor/output/console/process-output.ts +4 -2
  95. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  96. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  97. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  98. package/src/components/editor/renderers/types.ts +2 -2
  99. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  100. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  101. package/src/components/scratchpad/scratchpad.tsx +6 -2
  102. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  103. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  104. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  105. package/src/components/slides/slide-cell-view.tsx +1 -3
  106. package/src/components/slides/slide.tsx +3 -3
  107. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  108. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  109. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  110. package/src/core/ai/context/providers/cell-output.ts +11 -6
  111. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  112. package/src/core/cells/__tests__/cells.test.ts +40 -292
  113. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  114. package/src/core/cells/__tests__/harness.ts +14 -12
  115. package/src/core/cells/__tests__/layout.test.ts +20 -26
  116. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  117. package/src/core/cells/__tests__/session.test.ts +26 -146
  118. package/src/core/cells/actions.ts +49 -9
  119. package/src/core/cells/cell.ts +0 -13
  120. package/src/core/cells/cells.ts +53 -62
  121. package/src/core/cells/focus.ts +6 -1
  122. package/src/core/cells/layout.ts +2 -3
  123. package/src/core/cells/outputs.ts +2 -2
  124. package/src/core/cells/session.ts +3 -38
  125. package/src/core/cells/types.ts +6 -8
  126. package/src/core/cells/utils.ts +4 -3
  127. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  128. package/src/core/config/config-schema.ts +15 -0
  129. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  130. package/src/core/errors/error-entries.ts +21 -11
  131. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  132. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  133. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  134. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  135. package/src/core/executions/__tests__/output.test.ts +87 -3
  136. package/src/core/executions/__tests__/select.test.ts +17 -10
  137. package/src/core/executions/atoms.ts +73 -15
  138. package/src/core/executions/freshness.ts +1 -1
  139. package/src/core/executions/hooks.ts +18 -8
  140. package/src/core/executions/index.ts +6 -0
  141. package/src/core/executions/output.ts +122 -38
  142. package/src/core/executions/select.ts +2 -2
  143. package/src/core/export/__tests__/hooks.test.ts +20 -29
  144. package/src/core/export/hooks.ts +7 -9
  145. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  146. package/src/core/islands/__tests__/main.test.ts +17 -0
  147. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  148. package/src/core/islands/components/output-wrapper.tsx +15 -20
  149. package/src/core/islands/iframe-resizer.ts +38 -0
  150. package/src/core/islands/main.ts +3 -0
  151. package/src/core/lifecycle/render-policy.ts +7 -4
  152. package/src/core/network/__tests__/ai.test.ts +41 -0
  153. package/src/core/network/ai.ts +12 -0
  154. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  155. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  156. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  157. package/src/core/notebook/replica/index.ts +1 -1
  158. package/src/core/notebook/replica/replica.ts +19 -4
  159. package/src/core/notebook/replica/resources/executions.ts +100 -9
  160. package/src/core/notebook/replica/resources/results.ts +46 -31
  161. package/src/core/transports/__tests__/static.test.ts +5 -3
  162. package/src/stories/cell.stories.tsx +40 -30
  163. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
  164. package/dist/assets/__vite-browser-external-C5NhJPNJ.js +0 -1
  165. package/dist/assets/worker-D-n8vtGi.js +0 -171
  166. package/dist/duckdb-keywords-BGArYVVK.js +0 -3
@@ -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 kernel's outline would. */
92
- heading: (id: string, level: number) =>
93
- store.set(notebookAtom, (state) => ({
94
- ...state,
95
- cellRuntime: {
96
- ...state.cellRuntime,
97
- [id]: {
98
- ...state.cellRuntime[id as never],
99
- outline: { items: [{ name: `H${level}`, level, by: { id } }] },
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
- function output(
135
- dispatch: ReturnType<typeof setupNotebook>["dispatch"],
136
- id: CellId,
137
- html: string,
138
- ) {
139
- dispatch({
140
- type: "handleCellMessage",
141
- payload: {
142
- cell_id: id,
143
- output: {
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, dispatch } = setupNotebook(stops);
158
- output(dispatch, c1, "<h1>Title</h1>");
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(dispatch, c2, "<p>1</p>");
162
- output(dispatch, c1, "<h1>Title</h1>");
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, dispatch } = setupNotebook(stops);
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(dispatch, c1, "<h1>Title</h1>");
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
- const firstOutline: Outline = {
19
- items: [{ name: "First", level: 1, by: { id: "first" } }],
20
- };
21
- const secondOutline: Outline = {
22
- items: [{ name: "Second", level: 2, by: { id: "second" } }],
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
- return { store, actions };
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 runtime outlines change or are removed", () => {
64
- const { store } = setup();
65
- const updated: Outline = {
66
- items: [{ name: "Updated", level: 1, by: { id: "updated" } }],
67
- };
68
-
69
- for (const outline of [updated, null]) {
70
- store.set(notebookAtom, (state) => ({
71
- ...state,
72
- cellRuntime: {
73
- ...state.cellRuntime,
74
- [first]: { ...state.cellRuntime[first], outline },
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: [...secondOutline.items, ...firstOutline.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(firstOutline);
112
+ expect(store.get(notebookOutline)).toEqual({ items: [firstItem] });
103
113
  });
104
114
 
105
- it("notifies subscribers when output is replaced with the same headings", () => {
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
- store.set(notebookAtom, (state) => ({
111
- ...state,
112
- cellRuntime: {
113
- ...state.cellRuntime,
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
- // Consumers must reconnect to replacement heading elements in the DOM.
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
- invariant(result.snapshot, "no snapshot");
331
- expect(result.cellRuntime[CELL_1].output).toEqual({
332
- channel: "marimo-error",
333
- data: [
334
- {
335
- type: "exception",
336
- exception_type: "ValueError",
337
- msg: "Something went wrong",
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
- invariant(result.snapshot, "no snapshot");
416
- expect(result.cellRuntime[CELL_1].output).toEqual({
417
- channel: "output",
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
- invariant(result.snapshot, "no snapshot");
825
- expect(result.cellRuntime[CELL_1].output).toEqual({
826
- channel: "output",
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
- invariant(result.snapshot, "no snapshot");
852
- expect(result.cellRuntime[CELL_1].output).toEqual({
853
- channel: "output",
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
- invariant(result.snapshot, "no snapshot");
876
- expect(result.cellRuntime[CELL_1].output).toEqual({
877
- channel: "output",
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 { cellExecutionInputsAtom, runningCellIds } from "@/core/executions";
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
- set(notebookAtom, (state) =>
237
- notebookReducer(state, { type: "clearCellOutput", payload: { cellId } }),
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(notebookAtom).cellRuntime[cellId]?.outline)) {
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) => canCollapseOutline(cellRuntime[id]?.outline)),
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.