@marimo-team/islands 0.25.3-dev170 → 0.25.3-dev175

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 (196) hide show
  1. package/dist/{ConnectedDataExplorerComponent-BbSXV-Xa.js → ConnectedDataExplorerComponent-Le_OBfmt.js} +9 -9
  2. package/dist/{ErrorBoundary-NE86qEWZ.js → ErrorBoundary-DNvcAIsP.js} +8 -8
  3. package/dist/{abnfDiagram-VCTEODGH-D7n07nXf.js → abnfDiagram-VCTEODGH-Tf1ghyQQ.js} +2 -2
  4. package/dist/{any-language-editor-3E24SnCV.js → any-language-editor-BVFHDDQ3.js} +4 -4
  5. package/dist/{architectureDiagram-5GKGNRK7-D6CjRib5.js → architectureDiagram-5GKGNRK7-xlnbTG0T.js} +1 -1
  6. package/dist/{chat-ui-CC7GekpG.js → chat-ui-X-cWrL9u.js} +1218 -1218
  7. package/dist/{check-SpOMoCLP.js → check-C9Mp9eCK.js} +1 -1
  8. package/dist/{chunk-IMKFNOWR-6dtPz7uS.js → chunk-IMKFNOWR-Cmd4a5jy.js} +1 -1
  9. package/dist/{chunk-SHT3W25Y-BwnFNKDA.js → chunk-SHT3W25Y-mSNp-WpO.js} +1 -1
  10. package/dist/{chunk-SVP7TREG-D2eV4vBJ.js → chunk-SVP7TREG-CWC49D8X.js} +1 -1
  11. package/dist/{chunk-TICWLB2K-BDs4-_-r.js → chunk-TICWLB2K-De9FINtG.js} +1 -1
  12. package/dist/{classDiagram-ZZMXUADV-DCJnf_8v.js → classDiagram-ZZMXUADV-DweTkYdp.js} +2 -2
  13. package/dist/{classDiagram-v2-VYDZK3BY-BOmSzPBD.js → classDiagram-v2-VYDZK3BY-A6MR2TiE.js} +2 -2
  14. package/dist/{code-visibility-Bzvc6ajl.js → code-visibility-CH1lmM1h.js} +5 -5
  15. package/dist/{common-Ciw4zkh2.js → common-DIrS1UR9.js} +1081 -1085
  16. package/dist/{copy-icon-C1trdvVt.js → copy-icon-De584pZ4.js} +2 -2
  17. package/dist/{cynefinDiagram-5FMLGOSQ-Bln_Soky.js → cynefinDiagram-5FMLGOSQ-BSvo5le-.js} +1 -1
  18. package/dist/{dagre-GXQ25YYZ-D-nf7WzW.js → dagre-GXQ25YYZ-tXRQslO6.js} +1 -1
  19. package/dist/{data-grid-overlay-editor-AQREmxI7.js → data-grid-overlay-editor-DFLZvFK0.js} +1 -1
  20. package/dist/{diagram-S7CK7UJ4-PsgSMkY2.js → diagram-S7CK7UJ4-r3t5VtwI.js} +1 -1
  21. package/dist/{diagram-UQ7AKVKN-DfwfUuSw.js → diagram-UQ7AKVKN-qgbC8YnT.js} +1 -1
  22. package/dist/{diagram-VX7I27RA-C9_e-oMc.js → diagram-VX7I27RA-CiHxEwtp.js} +1 -1
  23. package/dist/{diagram-Z3DM3KII-CWLa5tuY.js → diagram-Z3DM3KII-D95u15Ev.js} +1 -1
  24. package/dist/{dialog-DgeqyrEZ.js → dialog-DVRfQuhD.js} +24 -24
  25. package/dist/{dist-F8Ep36rk.js → dist-B1M0bGO3.js} +1 -1
  26. package/dist/{dist-D6d86eNJ.js → dist-BA13RJj5.js} +1 -1
  27. package/dist/{dist-Bvs24R_E.js → dist-BJtmSgcE.js} +48 -48
  28. package/dist/{dist-CN_BeG2I.js → dist-Ba2VIn1K.js} +53 -53
  29. package/dist/{dist-PXYI_yuP.js → dist-Bj4bmwUm.js} +12 -12
  30. package/dist/{dist-DoE4XJBC.js → dist-BmS-ZGjl.js} +8626 -8626
  31. package/dist/{dist-BorMD-uX.js → dist-Bzogh7CW.js} +87 -87
  32. package/dist/{dist-CN8zI-XC.js → dist-CThPVKaP.js} +1385 -1382
  33. package/dist/{dist-DiDibOYr.js → dist-CTi5FTiV.js} +87 -87
  34. package/dist/{dist-diIx5qJW.js → dist-Ck_C32ye.js} +2 -2
  35. package/dist/{dist-BLfKmR-l.js → dist-D1fnFp1J.js} +1 -1
  36. package/dist/{dist-OR1OnN-y.js → dist-D3x9__Fu.js} +46 -46
  37. package/dist/{dist-BMQf5zIS.js → dist-D7mrh5sO.js} +36 -36
  38. package/dist/{dist-CSJ0MDRw.js → dist-D9Q3xjiP.js} +1 -1
  39. package/dist/{dist-BuaRHxOc.js → dist-DP60Ubh8.js} +2 -2
  40. package/dist/{dist-CSbh1PNP.js → dist-DTv9KkpW.js} +12 -12
  41. package/dist/{dist-D-wwqlzJ.js → dist-DVVwOfrD.js} +109 -109
  42. package/dist/{dist-C8fAKSH1.js → dist-DYXM73-k.js} +36 -36
  43. package/dist/{dist-DBtSl3sf.js → dist-DjeybPOb.js} +1 -1
  44. package/dist/{dist-CrSP_H1M.js → dist-DtGn9N4h.js} +197 -197
  45. package/dist/{dist-CLdpGQVr.js → dist-KN80qWCP.js} +2 -2
  46. package/dist/{dist-Cg7gzw-a.js → dist-O0qFpEJh.js} +56 -56
  47. package/dist/{dist-CkTTIdBe.js → dist-OUle2RT7.js} +207 -207
  48. package/dist/{dist-BK4Oj99o.js → dist-T5rh6JvL.js} +1 -1
  49. package/dist/{dropdown-menu-B6ftyzOg.js → dropdown-menu-DCMbbQ35.js} +691 -691
  50. package/dist/{ebnfDiagram-PWID7BFC-B1QRM58v.js → ebnfDiagram-PWID7BFC-P7e4bryK.js} +2 -2
  51. package/dist/{erDiagram-RLTQ6QDP-DJK_FqvW.js → erDiagram-RLTQ6QDP-CUHZcmRj.js} +1 -1
  52. package/dist/{error-banner-D40pmfQQ.js → error-banner-DxJ3s8YO.js} +57 -57
  53. package/dist/{error-entries-DgK3wUJR.js → error-entries-mpoD5t79.js} +4985 -5006
  54. package/dist/{esm-D2gTsXEV.js → esm-Bbw_Njjx.js} +575 -575
  55. package/dist/{esm-AMFssoNp.js → esm-mDQNEFe_.js} +354 -354
  56. package/dist/{feedback-button-8a6SETmT.js → feedback-button-DL0DJ-LB.js} +30 -30
  57. package/dist/{flowDiagram-HODETNUW-Uxc25XSJ.js → flowDiagram-HODETNUW-BGZ95AzI.js} +2 -2
  58. package/dist/{formats-DQCyPd5Z.js → formats-DI7HEVv7.js} +1 -1
  59. package/dist/{glide-data-editor-B70oke_v.js → glide-data-editor-n4wnx19S.js} +10 -10
  60. package/dist/{glide-utils-Dz_F4pAY.js → glide-utils-D98laidb.js} +2 -2
  61. package/dist/{globals-Cxd5hNlI.js → globals-NCsYyjpB.js} +3 -3
  62. package/dist/{html-to-image-D4yG5Ru0.js → html-to-image-BoZthB4P.js} +467 -458
  63. package/dist/{infoDiagram-27XIBGKW-DmjxqwL0.js → infoDiagram-27XIBGKW-BF0YX70D.js} +1 -1
  64. package/dist/{ishikawaDiagram-5VMMS53U-NgCLHqQi.js → ishikawaDiagram-5VMMS53U-_itsAAn-.js} +1 -1
  65. package/dist/{kanban-definition-UXKFOSKX-CZaG-iam.js → kanban-definition-UXKFOSKX-VNW2Beqh.js} +1 -1
  66. package/dist/{label-D9_-zSg-.js → label-Qvw1E97W.js} +1 -1
  67. package/dist/main.js +8257 -6606
  68. package/dist/{mermaid-CSvw7c71.js → mermaid-CZ6FrClS.js} +35 -35
  69. package/dist/{mindmap-definition-YA3MSWOX-DJYQBDH_.js → mindmap-definition-YA3MSWOX-DR4ripvd.js} +1 -1
  70. package/dist/{number-overlay-editor-ChK-SKUk.js → number-overlay-editor-rlvo4mo3.js} +1 -1
  71. package/dist/{pegDiagram-XKGWAZYB-CHKO_dAe.js → pegDiagram-XKGWAZYB-CFr3XlGl.js} +2 -2
  72. package/dist/{pieDiagram-E7YTZNPT-DVevbMAo.js → pieDiagram-E7YTZNPT-j91XYSLY.js} +1 -1
  73. package/dist/{process-output-DxvBAeL3.js → process-output-DLS4Mqg_.js} +4 -4
  74. package/dist/{railroadDiagram-O6MQD6OU-Detj1kcB.js → railroadDiagram-O6MQD6OU-Cd47ZV9E.js} +2 -2
  75. package/dist/{requirementDiagram-BXWQKSXE-BLFD0T_Z.js → requirementDiagram-BXWQKSXE-eJH6gLtX.js} +1 -1
  76. package/dist/{reveal-component-CXMXeDZD.js → reveal-component-BJfmRUzb.js} +9 -9
  77. package/dist/{select-CkF_GBxO.js → select-2KOiReNY.js} +324 -324
  78. package/dist/{sequenceDiagram-WJ2MYXX4-BZBgatQV.js → sequenceDiagram-WJ2MYXX4-DdfFEIrm.js} +1 -1
  79. package/dist/{spec-Mnkn3XEr.js → spec-h69nC3SI.js} +4 -4
  80. package/dist/{stateDiagram-D77RDMKH-4BZW9-6_.js → stateDiagram-D77RDMKH-DkjDvip8.js} +2 -2
  81. package/dist/{stateDiagram-v2-MP3YSRHH-C4sKC8Iq.js → stateDiagram-v2-MP3YSRHH-DBHACnOo.js} +2 -2
  82. package/dist/{swimlanes-42K2YHIH-SL5yeGe2.js → swimlanes-42K2YHIH-ogImlOmp.js} +1 -1
  83. package/dist/{swimlanesDiagram-VR7AAH4N-DqPmAYUv.js → swimlanesDiagram-VR7AAH4N-D6x-zsci.js} +2 -2
  84. package/dist/{timeline-definition-24CTP7MA-BfXUMWkq.js → timeline-definition-24CTP7MA-DQpLtsHD.js} +1 -1
  85. package/dist/{toDate-TMubKIVL.js → toDate-CDzoofJo.js} +2 -2
  86. package/dist/{toast-Btbve3Lm.js → toast-B5t9o6s_.js} +47 -47
  87. package/dist/{tooltip-CJ4Rqasp.js → tooltip-s4zZxwKe.js} +67 -67
  88. package/dist/{use-restore-focus-CmGwRNId.js → use-restore-focus-BgDTd2tc.js} +1 -1
  89. package/dist/{useAsyncData-DjMGFzFy.js → useAsyncData-Bn8SxUqM.js} +1 -1
  90. package/dist/{useDateFormatter-eCL_SdeG.js → useDateFormatter-D3Tkfzej.js} +2 -2
  91. package/dist/{useDeepCompareMemoize-BQR5TJot.js → useDeepCompareMemoize-CC2tnPCk.js} +1 -1
  92. package/dist/{useLifecycle-C_GvKWbQ.js → useLifecycle-BJlxHqWa.js} +2 -2
  93. package/dist/{useTheme-Bns2gJZ6.js → useTheme-DMfQYmlG.js} +85 -85
  94. package/dist/{vega-component-BsVptuhz.js → vega-component-CovWHi60.js} +7 -7
  95. package/dist/{vennDiagram-4TSXK5OY-CH65znGa.js → vennDiagram-4TSXK5OY-BD-SL_vq.js} +1 -1
  96. package/dist/{wardleyDiagram-VM6X3IG4-z9pWKb2_.js → wardleyDiagram-VM6X3IG4-BDgJV4ah.js} +1 -1
  97. package/dist/{xychartDiagram-S5SC5T6Z-MxyaWjjq.js → xychartDiagram-S5SC5T6Z-1hIHN6Rl.js} +1 -1
  98. package/package.json +1 -1
  99. package/src/__mocks__/document.tsx +54 -0
  100. package/src/__mocks__/notebook.ts +2 -1
  101. package/src/__mocks__/requests.ts +0 -2
  102. package/src/components/chat/chat-panel.tsx +3 -3
  103. package/src/components/datasources/__tests__/column-preview.test.tsx +6 -8
  104. package/src/components/datasources/column-preview.tsx +4 -8
  105. package/src/components/datasources/datasources.tsx +4 -3
  106. package/src/components/dependency-graph/minimap-content.tsx +2 -6
  107. package/src/components/dependency-graph/panels.tsx +2 -1
  108. package/src/components/editor/__tests__/Output.test.tsx +50 -32
  109. package/src/components/editor/__tests__/data-attributes.test.tsx +22 -11
  110. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -1
  111. package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +69 -0
  112. package/src/components/editor/actions/name-cell-input.tsx +4 -3
  113. package/src/components/editor/actions/useCellActionButton.tsx +20 -26
  114. package/src/components/editor/actions/useNotebookActions.tsx +13 -18
  115. package/src/components/editor/actions/useSetCodeVisibility.ts +10 -11
  116. package/src/components/editor/actions/useSetOutputsExpanded.ts +13 -18
  117. package/src/components/editor/cell/CreateCellButton.tsx +5 -9
  118. package/src/components/editor/cell/__tests__/StagedAICell.test.tsx +3 -1
  119. package/src/components/editor/cell/code/cell-editor.tsx +13 -20
  120. package/src/components/editor/cell/useAddCell.ts +4 -8
  121. package/src/components/editor/cell/useDeleteCell.tsx +10 -36
  122. package/src/components/editor/cell/useRunCells.ts +2 -5
  123. package/src/components/editor/cell/useSplitCell.tsx +2 -1
  124. package/src/components/editor/chrome/panels/logs-panel.tsx +2 -1
  125. package/src/components/editor/chrome/panels/snippets-panel.tsx +5 -11
  126. package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +3 -1
  127. package/src/components/editor/columns/sortable-column.tsx +1 -1
  128. package/src/components/editor/connections/components.tsx +4 -9
  129. package/src/components/editor/controls/Controls.tsx +1 -1
  130. package/src/components/editor/controls/__tests__/notebook-menu-dropdown.test.tsx +9 -3
  131. package/src/components/editor/documentation.css +34 -11
  132. package/src/components/editor/errors/auto-fix.tsx +4 -8
  133. package/src/components/editor/file-tree/file-explorer.tsx +3 -7
  134. package/src/components/editor/links/__tests__/cell-link.test.tsx +3 -1
  135. package/src/components/editor/links/cell-link.tsx +2 -1
  136. package/src/components/editor/navigation/__tests__/clipboard.test.ts +60 -38
  137. package/src/components/editor/navigation/__tests__/navigation.test.ts +73 -64
  138. package/src/components/editor/navigation/clipboard.ts +12 -11
  139. package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +11 -20
  140. package/src/components/editor/navigation/navigation.ts +20 -28
  141. package/src/components/editor/notebook-cell.tsx +7 -10
  142. package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +125 -69
  143. package/src/components/editor/renderers/cell-array.tsx +10 -17
  144. package/src/components/markdown/markdown-renderer.tsx +4 -8
  145. package/src/components/pages/edit-page.tsx +32 -17
  146. package/src/components/scratchpad/scratchpad.test.tsx +3 -1
  147. package/src/components/scratchpad/scratchpad.tsx +4 -7
  148. package/src/components/slides/__tests__/minimap-actions.test.tsx +9 -25
  149. package/src/components/slides/minimap.tsx +7 -3
  150. package/src/components/slides/slide-cell-view.tsx +3 -3
  151. package/src/components/sort/SortableCellsProvider.tsx +2 -1
  152. package/src/core/ai/__tests__/staged-cells.test.ts +18 -20
  153. package/src/core/ai/staged-cells.ts +8 -16
  154. package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +2 -2
  155. package/src/core/ai/tools/__tests__/run-cells-tool.test.ts +2 -2
  156. package/src/core/ai/tools/base.ts +2 -2
  157. package/src/core/ai/tools/edit-notebook-tool.ts +13 -21
  158. package/src/core/cells/__tests__/actions.test.ts +474 -34
  159. package/src/core/cells/__tests__/add-missing-import.test.ts +7 -8
  160. package/src/core/cells/__tests__/cells.test.ts +251 -861
  161. package/src/core/cells/__tests__/document.test.ts +42 -38
  162. package/src/core/cells/__tests__/notebook-outline.test.ts +7 -1
  163. package/src/core/cells/__tests__/outputs.test.tsx +71 -53
  164. package/src/core/cells/actions.ts +391 -3
  165. package/src/core/cells/add-missing-import.ts +46 -42
  166. package/src/core/cells/cells.ts +73 -444
  167. package/src/core/cells/document.ts +38 -6
  168. package/src/core/cells/outputs.ts +12 -28
  169. package/src/core/codemirror/cells/extensions.ts +6 -6
  170. package/src/core/codemirror/cells/state.ts +1 -1
  171. package/src/core/codemirror/keymaps/vim.ts +2 -2
  172. package/src/core/edit-app.tsx +20 -25
  173. package/src/core/islands/__tests__/bootstrap.test.ts +56 -0
  174. package/src/core/islands/__tests__/bridge.test.ts +42 -0
  175. package/src/core/islands/bootstrap.ts +24 -1
  176. package/src/core/islands/bridge.ts +46 -5
  177. package/src/core/kernel/__tests__/handlers.test.ts +7 -153
  178. package/src/core/kernel/handlers.ts +18 -59
  179. package/src/core/network/__tests__/requests-lazy.test.ts +1 -3
  180. package/src/core/network/requests-lazy.ts +0 -2
  181. package/src/core/network/requests-network.ts +0 -16
  182. package/src/core/network/requests-static.ts +0 -2
  183. package/src/core/network/requests-toasting.tsx +0 -2
  184. package/src/core/network/types.ts +0 -7
  185. package/src/core/notebook/document/__tests__/codemirror.test.ts +5 -0
  186. package/src/core/notebook/document/__tests__/draft.test.ts +41 -0
  187. package/src/core/notebook/document/__tests__/state.test.ts +21 -0
  188. package/src/core/notebook/document/draft.ts +35 -5
  189. package/src/core/notebook/document/index.ts +1 -0
  190. package/src/core/notebook/document/state.ts +6 -2
  191. package/src/core/run-app.tsx +1 -7
  192. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +0 -6
  193. package/src/core/session/useNotebookSession.tsx +28 -35
  194. package/src/core/wasm/bridge.ts +0 -16
  195. package/src/css/globals.css +56 -22
  196. package/src/stories/runtime-story.tsx +22 -15
@@ -29,7 +29,12 @@ import {
29
29
  type NotebookState,
30
30
  notebookReducer,
31
31
  } from "../cells";
32
- import { applyDocument, flushDocument, withDocumentSave } from "../document";
32
+ import {
33
+ applyDocument,
34
+ flushDocument,
35
+ followDocument,
36
+ withDocumentSave,
37
+ } from "../document";
33
38
  import { type CellId, SCRATCH_CELL_ID } from "../ids";
34
39
 
35
40
  vi.mock("../../rtc/state", async (importOriginal) => ({
@@ -102,9 +107,10 @@ describe("applyDocument", () => {
102
107
  expect(state.cellData[a]).toMatchObject({
103
108
  code: "a = 1",
104
109
  name: "_",
105
- edited: false,
110
+ edited: true,
106
111
  lastCodeRun: null,
107
112
  });
113
+ expect(state.cellData[b].edited).toBe(false);
108
114
  expect(state.cellRuntime[a]).toBeDefined();
109
115
  expect(state.cellHandles[a]).toBeDefined();
110
116
  expect(state.cellData[SCRATCH_CELL_ID]).toBeDefined();
@@ -185,7 +191,7 @@ describe("applyDocument", () => {
185
191
  expect(next.cellData[a]).toMatchObject({
186
192
  name: "renamed",
187
193
  config: { hide_code: true },
188
- edited: false,
194
+ edited: true,
189
195
  });
190
196
  });
191
197
 
@@ -277,45 +283,14 @@ describe("documentEditMiddleware", () => {
277
283
  store.set(activeDocumentModelAtom, null);
278
284
  });
279
285
 
280
- it("creates a cell at the end without setting the order", () => {
281
- actions.createNewCell({
282
- cellId: c,
283
- before: false,
284
- code: "d = 1",
285
- newCellId: d,
286
- });
287
-
288
- expect(calls.map((call) => call[0])).toEqual(["createCell"]);
289
- expect(calls[0][1]).toMatchObject({ id: d, code: "d = 1" });
290
- });
291
-
292
- it("creates a cell elsewhere and sets the order", () => {
293
- actions.createNewCell({ cellId: a, before: true, newCellId: d });
294
-
295
- expect(calls.map((call) => call[0])).toEqual(["createCell", "setOrder"]);
296
- expect(calls[1][1]).toEqual([d, a, b, c]);
297
- });
298
-
299
- it("deletes a cell", () => {
300
- actions.deleteCell({ cellId: b });
301
-
302
- expect(calls).toEqual([["deleteCell", b]]);
303
- });
304
-
305
- it("writes code, name, and config", () => {
286
+ it("writes code", () => {
306
287
  actions.updateCellCode({
307
288
  cellId: a,
308
289
  code: "a = 2",
309
290
  formattingChange: false,
310
291
  });
311
- actions.updateCellName({ cellId: a, name: "first" });
312
- actions.updateCellConfig({ cellId: a, config: { hide_code: true } });
313
292
 
314
- expect(calls).toEqual([
315
- ["setCode", a, "a = 2"],
316
- ["setName", a, "first"],
317
- ["updateConfig", a, { hide_code: true }],
318
- ]);
293
+ expect(calls).toEqual([["setCode", a, "a = 2"]]);
319
294
  });
320
295
 
321
296
  it("sets the order when a cell moves", () => {
@@ -349,9 +324,14 @@ describe("documentEditMiddleware", () => {
349
324
  expect(calls).toEqual([["updateConfig", c, { column: null }]]);
350
325
  });
351
326
 
352
- it("ignores the kernel's cells and runtime state", () => {
327
+ it("ignores the document and the kernel's run state", () => {
353
328
  actions.prepareForRun({ cellId: a });
354
- actions.setCells([state.cellData[a]]);
329
+ actions.setLastRun({
330
+ lastCodeRun: { [a]: "a = 0" },
331
+ lastExecutionTime: {},
332
+ });
333
+ actions.resetCellRuntimes();
334
+ actions.reconcileDocument(documentOf([cell(a)]));
355
335
 
356
336
  expect(calls).toEqual([]);
357
337
  });
@@ -367,6 +347,30 @@ describe("documentEditMiddleware", () => {
367
347
  });
368
348
  });
369
349
 
350
+ describe("followDocument", () => {
351
+ it("reconciles the document now and on each change, until aborted", () => {
352
+ const documentAtom = atom<EditableDocument | null>(null);
353
+ const reconcile = vi.fn();
354
+ const controller = new AbortController();
355
+
356
+ followDocument({
357
+ store,
358
+ model: { documentAtom },
359
+ reconcile,
360
+ signal: controller.signal,
361
+ });
362
+ expect(reconcile).not.toHaveBeenCalled();
363
+
364
+ const first = documentOf([cell(a)]);
365
+ store.set(documentAtom, first);
366
+ expect(reconcile).toHaveBeenCalledWith(first);
367
+
368
+ controller.abort();
369
+ store.set(documentAtom, documentOf([cell(b)]));
370
+ expect(reconcile).toHaveBeenCalledOnce();
371
+ });
372
+ });
373
+
370
374
  describe("flushing before host commands", () => {
371
375
  const model = {
372
376
  syncStatusAtom: atom<DocumentSyncStatus>({ status: "idle" }),
@@ -4,6 +4,7 @@ import { createStore } from "jotai";
4
4
  import { describe, expect, it, vi } from "vitest";
5
5
  import { MockNotebook } from "@/__mocks__/notebook";
6
6
  import { cellId } from "@/__tests__/branded";
7
+ import { CONFIG } from "@/core/notebook/document/__tests__/fixtures";
7
8
  import {
8
9
  createNotebookActions,
9
10
  notebookAtom,
@@ -84,7 +85,12 @@ describe("notebookOutline", () => {
84
85
  items: [...secondOutline.items, ...firstOutline.items],
85
86
  });
86
87
 
87
- actions.deleteCell({ cellId: second });
88
+ actions.reconcileDocument({
89
+ order: [first],
90
+ cells: new Map([
91
+ [first, { id: first, code: "x = 1", name: "_", config: CONFIG }],
92
+ ]),
93
+ });
88
94
  expect(store.get(notebookOutline)).toEqual(firstOutline);
89
95
  });
90
96
 
@@ -2,116 +2,134 @@
2
2
 
3
3
  import { act, renderHook } from "@testing-library/react";
4
4
  import { createStore, Provider } from "jotai";
5
- import { beforeEach, describe, expect, it, vi } from "vitest";
6
- import { MockNotebook } from "@/__mocks__/notebook";
7
- import { notebookAtom } from "@/core/cells/cells";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { mockDocumentModel } from "@/__mocks__/document";
8
7
  import { CellId } from "@/core/cells/ids";
8
+ import { DocumentProvider } from "@/core/notebook/document";
9
+ import {
10
+ cell,
11
+ CONFIG,
12
+ document as documentOf,
13
+ withCells,
14
+ } from "@/core/notebook/document/__tests__/fixtures";
9
15
  import { type AppMode, viewStateAtom } from "@/core/mode";
10
16
  import { useExpandedConsoleOutput, useExpandedOutput } from "../outputs";
11
17
 
12
- const saveCellConfig = vi.fn().mockResolvedValue(null);
18
+ const stops: Array<() => void> = [];
13
19
 
14
- vi.mock("@/core/network/requests", () => ({
15
- getRequestClient: () => ({ saveCellConfig }),
16
- }));
20
+ afterEach(() => {
21
+ for (const stop of stops.splice(0)) {
22
+ stop();
23
+ }
24
+ });
17
25
 
18
26
  function setup(opts: { mode: AppMode; expandOutput?: boolean }) {
19
27
  const cellId = CellId.create();
20
28
  const store = createStore();
21
- store.set(
22
- notebookAtom,
23
- MockNotebook.notebookState({
24
- cellData: {
25
- [cellId]: { config: { expand_output: opts.expandOutput ?? false } },
29
+ const { model, stop } = mockDocumentModel(
30
+ store,
31
+ withCells(
32
+ documentOf(),
33
+ {
34
+ c1: null,
35
+ c2: null,
36
+ [cellId]: cell(cellId, "", {
37
+ config: { ...CONFIG, expand_output: opts.expandOutput ?? false },
38
+ }),
26
39
  },
27
- }),
40
+ [cellId],
41
+ ),
28
42
  );
43
+ stops.push(stop);
29
44
  store.set(viewStateAtom, { mode: opts.mode, cellAnchor: null });
30
45
 
31
- const { result } = renderHook(() => useExpandedOutput(cellId), {
32
- wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
33
- });
46
+ const wrapper = ({ children }: { children: React.ReactNode }) => (
47
+ <Provider store={store}>
48
+ <DocumentProvider model={model}>{children}</DocumentProvider>
49
+ </Provider>
50
+ );
51
+ const expanded = () =>
52
+ store.get(model.documentAtom)?.cells.get(cellId)?.config.expand_output;
34
53
 
35
- return { cellId, store, result };
54
+ return { cellId, store, wrapper, expanded };
36
55
  }
37
56
 
38
- const configOf = (store: ReturnType<typeof createStore>, cellId: CellId) =>
39
- store.get(notebookAtom).cellData[cellId].config;
40
-
41
57
  describe("useExpandedOutput", () => {
42
- beforeEach(() => {
43
- vi.clearAllMocks();
44
- });
45
-
46
58
  it("reads the initial state from the cell's expand_output config", () => {
47
- expect(setup({ mode: "edit" }).result.current[0]).toBe(false);
48
- expect(setup({ mode: "edit", expandOutput: true }).result.current[0]).toBe(
49
- true,
50
- );
59
+ const collapsed = setup({ mode: "edit" });
60
+ expect(
61
+ renderHook(() => useExpandedOutput(collapsed.cellId), {
62
+ wrapper: collapsed.wrapper,
63
+ }).result.current[0],
64
+ ).toBe(false);
65
+
66
+ const expanded = setup({ mode: "edit", expandOutput: true });
67
+ expect(
68
+ renderHook(() => useExpandedOutput(expanded.cellId), {
69
+ wrapper: expanded.wrapper,
70
+ }).result.current[0],
71
+ ).toBe(true);
51
72
  });
52
73
 
53
74
  it("persists the toggle to the cell's config in edit mode", () => {
54
- const { cellId, store, result } = setup({ mode: "edit" });
75
+ const { cellId, wrapper, expanded } = setup({ mode: "edit" });
76
+ const { result } = renderHook(() => useExpandedOutput(cellId), {
77
+ wrapper,
78
+ });
55
79
 
56
80
  act(() => result.current[1](true));
57
81
 
58
82
  expect(result.current[0]).toBe(true);
59
- expect(configOf(store, cellId).expand_output).toBe(true);
60
- expect(saveCellConfig).toHaveBeenCalledWith({
61
- configs: { [cellId]: { expand_output: true } },
62
- });
83
+ expect(expanded()).toBe(true);
63
84
  });
64
85
 
65
86
  it("collapses by clearing the config", () => {
66
- const { cellId, store, result } = setup({
87
+ const { cellId, wrapper, expanded } = setup({
67
88
  mode: "edit",
68
89
  expandOutput: true,
69
90
  });
91
+ const { result } = renderHook(() => useExpandedOutput(cellId), {
92
+ wrapper,
93
+ });
70
94
 
71
95
  act(() => result.current[1](false));
72
96
 
73
97
  expect(result.current[0]).toBe(false);
74
- expect(configOf(store, cellId).expand_output).toBe(false);
75
- expect(saveCellConfig).toHaveBeenCalledWith({
76
- configs: { [cellId]: { expand_output: false } },
77
- });
98
+ expect(expanded()).toBe(false);
78
99
  });
79
100
 
80
101
  it("keeps the toggle in memory outside of edit mode", () => {
81
- const { cellId, store, result } = setup({ mode: "read" });
102
+ const { cellId, wrapper, expanded } = setup({ mode: "read" });
103
+ const { result } = renderHook(() => useExpandedOutput(cellId), {
104
+ wrapper,
105
+ });
82
106
 
83
107
  act(() => result.current[1](true));
84
108
 
85
109
  expect(result.current[0]).toBe(true);
86
110
  // Cell configs are read-only outside of edit mode.
87
- expect(configOf(store, cellId).expand_output).toBe(false);
88
- expect(saveCellConfig).not.toHaveBeenCalled();
111
+ expect(expanded()).toBe(false);
89
112
  });
90
113
 
91
114
  it("still honors expand_output outside of edit mode", () => {
92
- const { result } = setup({ mode: "read", expandOutput: true });
115
+ const { cellId, wrapper } = setup({ mode: "read", expandOutput: true });
116
+ const { result } = renderHook(() => useExpandedOutput(cellId), {
117
+ wrapper,
118
+ });
93
119
  expect(result.current[0]).toBe(true);
94
120
  });
95
121
 
96
122
  // `expand_output` covers the cell's output area only. Console output is
97
123
  // clamped independently and stays an in-memory, per-session toggle.
98
124
  it("does not touch the config when console output is expanded", () => {
99
- const cellId = CellId.create();
100
- const store = createStore();
101
- store.set(
102
- notebookAtom,
103
- MockNotebook.notebookState({ cellData: { [cellId]: {} } }),
104
- );
105
- store.set(viewStateAtom, { mode: "edit", cellAnchor: null });
106
-
125
+ const { cellId, wrapper, expanded } = setup({ mode: "edit" });
107
126
  const { result } = renderHook(() => useExpandedConsoleOutput(cellId), {
108
- wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
127
+ wrapper,
109
128
  });
110
129
 
111
130
  act(() => result.current[1](true));
112
131
 
113
132
  expect(result.current[0]).toBe(true);
114
- expect(configOf(store, cellId).expand_output).toBe(false);
115
- expect(saveCellConfig).not.toHaveBeenCalled();
133
+ expect(expanded()).toBe(false);
116
134
  });
117
135
  });