@marimo-team/islands 0.26.1-dev8 → 0.26.1-dev84

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 (325) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DtwVgVpX.js → ConnectedDataExplorerComponent-CO9uVewH.js} +15 -15
  2. package/dist/{ErrorBoundary-DgwX53fT.js → ErrorBoundary-T8CwNebX.js} +7 -7
  3. package/dist/{abnfDiagram-VCTEODGH-BbZOIueZ.js → abnfDiagram-VCTEODGH-Ba0MYVW8.js} +2 -2
  4. package/dist/{any-language-editor-yG-YmLaK.js → any-language-editor-BNe8do3C.js} +5 -5
  5. package/dist/{architectureDiagram-5GKGNRK7-qjLjxapm.js → architectureDiagram-5GKGNRK7-7MqAehef.js} +1 -1
  6. package/dist/{assertNever-DywGMo-S.js → assertNever-5vhHGKOK.js} +14 -14
  7. package/dist/{button-qQhINE7z.js → button-Z2R2272J.js} +34 -31
  8. package/dist/{capabilities-DKqMqBzm.js → capabilities-ba3Dyv8n.js} +1 -1
  9. package/dist/{chat-ui-D5YPIONI.js → chat-ui-CjZbdpzb.js} +117 -117
  10. package/dist/{check-jchHMCfs.js → check-DUIc04aK.js} +1 -1
  11. package/dist/{chunk-IMKFNOWR-BzDY1_I7.js → chunk-IMKFNOWR-CAWA0HGB.js} +1 -1
  12. package/dist/{chunk-SHT3W25Y-DbHsMKdo.js → chunk-SHT3W25Y-BIwVQjG5.js} +1 -1
  13. package/dist/{chunk-SVP7TREG-CtwnwAE6.js → chunk-SVP7TREG-Cux251TB.js} +1 -1
  14. package/dist/{chunk-TICWLB2K-C5Z5QMbO.js → chunk-TICWLB2K-DJVQ6khO.js} +1 -1
  15. package/dist/{classDiagram-ZZMXUADV-B8E5Hn78.js → classDiagram-ZZMXUADV-Cwve77ev.js} +2 -2
  16. package/dist/{classDiagram-v2-VYDZK3BY-DeGsK9bT.js → classDiagram-v2-VYDZK3BY-BAeHKXmD.js} +2 -2
  17. package/dist/{code-visibility-BRw-I8KK.js → code-visibility-BBgRhs2A.js} +17 -17
  18. package/dist/{common-CsAoQn5h.js → common-BF30ifb8.js} +6102 -6047
  19. package/dist/{config-qTaTHnpE.js → config-CShkLThS.js} +43 -42
  20. package/dist/{copy-icon-BI7vZHEW.js → copy-icon-CmNLxT5_.js} +3 -3
  21. package/dist/{createReducer-DdSLRfBT.js → createReducer-BUQhgLOI.js} +6 -6
  22. package/dist/{cynefinDiagram-5FMLGOSQ-NDedRwsw.js → cynefinDiagram-5FMLGOSQ-t4eEkPJh.js} +1 -1
  23. package/dist/{dagre-GXQ25YYZ-De0sSZO7.js → dagre-GXQ25YYZ-IuZuI28B.js} +1 -1
  24. package/dist/{data-grid-overlay-editor-DeWsTtac.js → data-grid-overlay-editor-ChntsIBb.js} +1 -1
  25. package/dist/{diagram-S7CK7UJ4-wBtVl61y.js → diagram-S7CK7UJ4-D8R5Q_ok.js} +1 -1
  26. package/dist/{diagram-UQ7AKVKN-CKWE3c1T.js → diagram-UQ7AKVKN-BGuMPsr-.js} +1 -1
  27. package/dist/{diagram-VX7I27RA-D2Ac5198.js → diagram-VX7I27RA-BkTtpO8P.js} +1 -1
  28. package/dist/{diagram-Z3DM3KII-CYaFOQcI.js → diagram-Z3DM3KII-C0__Mxfm.js} +1 -1
  29. package/dist/{dialog-Ic6dh09m.js → dialog-BvjfalZ9.js} +28 -28
  30. package/dist/{dist-BvZpdAuG.js → dist-6B1_Ttbh.js} +1 -1
  31. package/dist/{dist-D1D56-GS.js → dist-B28poF32.js} +2 -2
  32. package/dist/{dist-BozTF_gH.js → dist-BBZ7lnMw.js} +2 -2
  33. package/dist/{dist-BfrgytDR.js → dist-BD8ZKF5t.js} +3 -3
  34. package/dist/{dist-DNkrY12t.js → dist-BG-7Qpaj.js} +3 -3
  35. package/dist/{dist-D92tYjLc.js → dist-BIaGGUbU.js} +13 -11
  36. package/dist/{dist-BagHbFqG.js → dist-BR5PU2Ph.js} +3 -3
  37. package/dist/{dist-DpYpG8Yc.js → dist-BidYR5m4.js} +3 -3
  38. package/dist/{dist-D95Cd4xm.js → dist-BkGYCvFX.js} +3 -3
  39. package/dist/{dist-DneeBk3K.js → dist-BmEyXT7K.js} +2 -2
  40. package/dist/{dist-BdUitvVW.js → dist-Bt0Wt6m9.js} +2 -2
  41. package/dist/{dist-CEomphG1.js → dist-CG2Sl0D4.js} +2 -2
  42. package/dist/{dist-BMz__bo5.js → dist-CQfpgadU.js} +3 -3
  43. package/dist/{dist-BreKIQqQ.js → dist-CVOPvfzN.js} +3 -3
  44. package/dist/{dist-BEcpQbZa.js → dist-Cm0iCeQQ.js} +3 -3
  45. package/dist/{dist-CDVvitRS.js → dist-Cnc14jEq.js} +2 -2
  46. package/dist/{dist-ChcBm3jk.js → dist-D3KPC38e.js} +4 -4
  47. package/dist/{dist-B1qu3Bez.js → dist-D7BXk27E.js} +3 -3
  48. package/dist/{dist-BsE4gQHj.js → dist-D9Qhvxvg.js} +1 -1
  49. package/dist/{dist-OmeAz0fR.js → dist-DJKajXDB.js} +3 -3
  50. package/dist/{dist-ObeTgSmf.js → dist-DYbNRTYG.js} +4 -4
  51. package/dist/{dist-Cshl6jBw.js → dist-DhtDWnzK.js} +2 -2
  52. package/dist/{dist-BunZKA_9.js → dist-_x2Jks2R.js} +2 -2
  53. package/dist/{dist-MggMo7OR.js → dist-m0MWV-aw.js} +1 -1
  54. package/dist/{dist-TGSwzj8a.js → dist-pPbYNVjd.js} +4 -4
  55. package/dist/{dropdown-menu-Dhv4fcNl.js → dropdown-menu-D0DeN-aL.js} +2108 -2108
  56. package/dist/{ebnfDiagram-PWID7BFC-Ds7f42dj.js → ebnfDiagram-PWID7BFC-CSESPZoz.js} +2 -2
  57. package/dist/{erDiagram-RLTQ6QDP-b58Sz2Mc.js → erDiagram-RLTQ6QDP-DsDTtabH.js} +1 -1
  58. package/dist/{error-banner-CJVLr5_a.js → error-banner-CXLjTW24.js} +75 -80
  59. package/dist/{error-entries-BKlEsuk4.js → error-entries-CsXAdy1j.js} +1032 -867
  60. package/dist/{esm-B9n0caHs.js → esm-DY8dGAjJ.js} +23 -23
  61. package/dist/{esm-Bwp_FHP0.js → esm-Dw2ZydG_.js} +3 -3
  62. package/dist/{feedback-button-DBJ87u8R.js → feedback-button-nmOvfn22.js} +123 -123
  63. package/dist/{flowDiagram-HODETNUW-BH9U7VZK.js → flowDiagram-HODETNUW-qxDPYbfV.js} +2 -2
  64. package/dist/{formats-BLNFWWhV.js → formats-BRDSQgKN.js} +3 -3
  65. package/dist/{glide-data-editor-CQQvTuRa.js → glide-data-editor-SkR9hqZZ.js} +43 -43
  66. package/dist/{glide-utils-Ze_7l_91.js → glide-utils-CD8BaFTm.js} +3 -3
  67. package/dist/{globals-KyhCA8uY.js → globals-BjiU5aEs.js} +3 -3
  68. package/dist/{html-to-image-CNM0ZSFD.js → html-to-image-CwpapHNl.js} +24212 -24090
  69. package/dist/{infoDiagram-27XIBGKW-xbjwrcNi.js → infoDiagram-27XIBGKW-B5hq8RM_.js} +1 -1
  70. package/dist/{ishikawaDiagram-5VMMS53U-DKtukhGS.js → ishikawaDiagram-5VMMS53U-DkHc_9ET.js} +1 -1
  71. package/dist/{kanban-definition-UXKFOSKX-BEhlkZBb.js → kanban-definition-UXKFOSKX-CqkTFXmU.js} +1 -1
  72. package/dist/{loader-Bin_dutt.js → loader-qPmiRXZd.js} +1 -1
  73. package/dist/main.js +8865 -8747
  74. package/dist/{mermaid-D1CZDNoB.js → mermaid-pmVHDUQA.js} +35 -35
  75. package/dist/{mindmap-definition-YA3MSWOX-DQcnJPcV.js → mindmap-definition-YA3MSWOX-D6cNa__z.js} +1 -1
  76. package/dist/{number-overlay-editor-Bul3xvgs.js → number-overlay-editor-GjrMTG9X.js} +1 -1
  77. package/dist/{pegDiagram-XKGWAZYB-BFQuPYfI.js → pegDiagram-XKGWAZYB-CmWJX_s1.js} +2 -2
  78. package/dist/{pencil-DVYzq-iR.js → pencil-CxMgOe04.js} +1 -1
  79. package/dist/{pieDiagram-E7YTZNPT-l7aqNrem.js → pieDiagram-E7YTZNPT-CAQAxHah.js} +1 -1
  80. package/dist/{process-output-DthYR2Te.js → process-output-ztSj9cDn.js} +4 -4
  81. package/dist/{railroadDiagram-O6MQD6OU-6R3C1lwQ.js → railroadDiagram-O6MQD6OU-jlSsiQg3.js} +2 -2
  82. package/dist/{requirementDiagram-BXWQKSXE-DdWYu8fn.js → requirementDiagram-BXWQKSXE-DkDjfPhn.js} +1 -1
  83. package/dist/{reveal-component-CYrENlgq.js → reveal-component-BrZbx6s7.js} +1017 -1017
  84. package/dist/{select-CDUxhHZg.js → select-CEnB18uc.js} +364 -364
  85. package/dist/{sequenceDiagram-WJ2MYXX4-Dzp0dgRc.js → sequenceDiagram-WJ2MYXX4-DLywsGCW.js} +1 -1
  86. package/dist/{spec-ZAt4P01J.js → spec-Dz-Avv1m.js} +4 -4
  87. package/dist/{stateDiagram-D77RDMKH-BGnTUhFJ.js → stateDiagram-D77RDMKH-DUmlKwYU.js} +2 -2
  88. package/dist/{stateDiagram-v2-MP3YSRHH-DsJbmDf1.js → stateDiagram-v2-MP3YSRHH-D646KiXs.js} +2 -2
  89. package/dist/{static-state-C4bAlKTU.js → static-state-DhVFm8Z6.js} +4 -4
  90. package/dist/style.css +1 -1
  91. package/dist/{swimlanes-42K2YHIH-Bd4Bzh9r.js → swimlanes-42K2YHIH-L7B1GphF.js} +1 -1
  92. package/dist/{swimlanesDiagram-VR7AAH4N-BlY12Jf6.js → swimlanesDiagram-VR7AAH4N-DEu2wxtC.js} +2 -2
  93. package/dist/{swiper-component-DTdNB9wg.js → swiper-component-B2O8hF7b.js} +2 -2
  94. package/dist/{timeline-definition-24CTP7MA-m0LanyCH.js → timeline-definition-24CTP7MA-DDPyx1yG.js} +1 -1
  95. package/dist/{toast-U3NpO2x3.js → toast-BTjH6fIf.js} +197 -197
  96. package/dist/{tooltip-UzJukb3F.js → tooltip-DyLdBIM4.js} +81 -81
  97. package/dist/{use-restore-focus-DaTVz6S6.js → use-restore-focus-DJ_-uSn_.js} +2006 -1997
  98. package/dist/{useDateFormatter-LQNtoXyh.js → useDateFormatter-HpKD0jEC.js} +2 -2
  99. package/dist/{useDeepCompareMemoize-CmNbQ9TT.js → useDeepCompareMemoize-CHx-NxMl.js} +1 -1
  100. package/dist/{useIframeCapabilities-HTZiVlGV.js → useIframeCapabilities-_0KX0nu_.js} +1 -1
  101. package/dist/{useLifecycle-DTMczKkf.js → useLifecycle-tPpAt-OE.js} +2 -2
  102. package/dist/{vega-component-ZTdbCcwI.js → vega-component-BxJFcD2G.js} +19 -19
  103. package/dist/{vennDiagram-4TSXK5OY-BJ7vqDmn.js → vennDiagram-4TSXK5OY-CRwWeb7g.js} +1 -1
  104. package/dist/{wardleyDiagram-VM6X3IG4-D5kWacsn.js → wardleyDiagram-VM6X3IG4-DVlG9eoq.js} +1 -1
  105. package/dist/{xychartDiagram-S5SC5T6Z-gr15Ws_z.js → xychartDiagram-S5SC5T6Z-CM32AISp.js} +1 -1
  106. package/package.json +3 -3
  107. package/src/__mocks__/animation-frames.ts +31 -0
  108. package/src/__mocks__/executions.ts +51 -23
  109. package/src/__mocks__/intersection-observer.ts +45 -0
  110. package/src/__mocks__/notebook.ts +1 -1
  111. package/src/__tests__/branded.ts +4 -0
  112. package/src/__tests__/notebook-analysis.ts +48 -0
  113. package/src/__tests__/render-tracker.ts +15 -0
  114. package/src/__tests__/setup.ts +3 -0
  115. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +30 -0
  116. package/src/components/app-config/ai-config.tsx +5 -3
  117. package/src/components/app-config/user-config-form.tsx +1 -1
  118. package/src/components/data-table/__tests__/export-actions.test.tsx +79 -0
  119. package/src/components/data-table/export-actions.tsx +64 -19
  120. package/src/components/data-table/schemas.ts +1 -0
  121. package/src/components/databases/engine-variable.tsx +2 -2
  122. package/src/components/dependency-graph/panels.tsx +2 -2
  123. package/src/components/editor/__tests__/cell-renders.test.tsx +116 -0
  124. package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -1
  125. package/src/components/editor/actions/useCellActionButton.tsx +2 -8
  126. package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
  127. package/src/components/editor/cell/CreateCellButton.tsx +69 -40
  128. package/src/components/editor/cell/__tests__/CreateCellButton.test.tsx +49 -0
  129. package/src/components/editor/cell/__tests__/cell-context-menu.test.tsx +126 -0
  130. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +5 -5
  131. package/src/components/editor/cell/cell-context-menu.tsx +202 -111
  132. package/src/components/editor/cell/code/__tests__/code-placeholder.test.tsx +40 -0
  133. package/src/components/editor/cell/code/cell-editor.tsx +49 -108
  134. package/src/components/editor/cell/code/code-placeholder.css +61 -11
  135. package/src/components/editor/cell/code/code-placeholder.tsx +52 -27
  136. package/src/components/editor/cell/collapse.tsx +6 -3
  137. package/src/components/editor/cell/useSplitCell.tsx +2 -2
  138. package/src/components/editor/chrome/panels/__tests__/secrets-panel.test.tsx +57 -0
  139. package/src/components/editor/chrome/panels/secrets-panel.tsx +36 -9
  140. package/src/components/editor/chrome/panels/secrets-utils.ts +20 -0
  141. package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +5 -2
  142. package/src/components/editor/chrome/wrapper/__tests__/pending-ai-cells.test.tsx +6 -10
  143. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +240 -93
  144. package/src/components/editor/errors/auto-fix.tsx +8 -7
  145. package/src/components/editor/errors/send-error-report-button.tsx +139 -41
  146. package/src/components/editor/header/status.tsx +5 -2
  147. package/src/components/editor/navigation/__tests__/navigation.test.ts +3 -16
  148. package/src/components/editor/navigation/focus-utils.ts +20 -8
  149. package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +3 -11
  150. package/src/components/editor/navigation/navigation.ts +2 -2
  151. package/src/components/editor/notebook-cell.tsx +15 -24
  152. package/src/components/editor/output/MarimoTracebackOutput.tsx +2 -2
  153. package/src/components/editor/output/console/ConsoleOutput.tsx +77 -50
  154. package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +28 -0
  155. package/src/components/editor/renderers/cells-renderer.tsx +3 -2
  156. package/src/components/editor/renderers/vertical-layout/__tests__/useFocusFirstEditor.test.ts +6 -9
  157. package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +2 -5
  158. package/src/components/find-replace/find-replace.tsx +3 -7
  159. package/src/components/icons/__tests__/large-spinner.test.tsx +5 -4
  160. package/src/components/scratchpad/scratchpad.tsx +2 -2
  161. package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
  162. package/src/components/ui/__tests__/button-shortcut.test.tsx +22 -0
  163. package/src/components/ui/__tests__/fullscreen.test.tsx +83 -1
  164. package/src/components/ui/button.tsx +5 -1
  165. package/src/components/ui/fullscreen.tsx +43 -89
  166. package/src/components/variables/__tests__/variables-table.test.tsx +1 -2
  167. package/src/core/MarimoApp.tsx +1 -1
  168. package/src/core/__tests__/MarimoApp.test.tsx +147 -0
  169. package/src/core/ai/__tests__/staged-cells.test.ts +6 -39
  170. package/src/core/ai/context/providers/__tests__/error.test.ts +6 -3
  171. package/src/core/ai/staged-cells.ts +8 -35
  172. package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +15 -13
  173. package/src/core/ai/tools/edit-notebook-tool.ts +13 -8
  174. package/src/core/cells/__tests__/actions.test.ts +2 -2
  175. package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
  176. package/src/core/cells/__tests__/arrange.test.ts +1 -1
  177. package/src/core/cells/__tests__/cell-editor-view.test.ts +44 -0
  178. package/src/core/cells/__tests__/cells.test.ts +0 -1
  179. package/src/core/cells/__tests__/focus.test.ts +1 -7
  180. package/src/core/cells/__tests__/harness.ts +9 -8
  181. package/src/core/cells/__tests__/layout.test.ts +1 -1
  182. package/src/core/cells/__tests__/pending-delete-service.test.tsx +121 -11
  183. package/src/core/cells/__tests__/runs.test.ts +14 -14
  184. package/src/core/cells/__tests__/utils.test.ts +3 -2
  185. package/src/core/cells/actions.ts +6 -6
  186. package/src/core/cells/add-missing-import.ts +2 -3
  187. package/src/core/cells/cells.ts +40 -27
  188. package/src/core/cells/document.ts +1 -2
  189. package/src/core/cells/execution-console.ts +10 -5
  190. package/src/core/cells/focus.ts +1 -1
  191. package/src/core/cells/ids.ts +2 -4
  192. package/src/core/cells/pending-delete-service.ts +97 -85
  193. package/src/core/cells/runs.ts +7 -5
  194. package/src/core/cells/scrollCellIntoView.ts +4 -14
  195. package/src/core/cells/session.ts +8 -5
  196. package/src/core/cells/utils.ts +0 -13
  197. package/src/core/codemirror/__tests__/cell-documents.test.ts +79 -0
  198. package/src/core/codemirror/__tests__/debounced-editor-update.test.ts +72 -0
  199. package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +75 -105
  200. package/src/core/codemirror/__tests__/format.test.ts +85 -63
  201. package/src/core/codemirror/__tests__/setup.test.ts +61 -1
  202. package/src/core/codemirror/__tests__/use-lazy-editor-mount.test.tsx +198 -0
  203. package/src/core/codemirror/cell-documents.ts +132 -0
  204. package/src/core/codemirror/cells/debugger-decorations.ts +22 -18
  205. package/src/core/codemirror/cells/line-timing-decorations.ts +13 -11
  206. package/src/core/codemirror/cells/traceback-decorations.ts +10 -11
  207. package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
  208. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +38 -12
  209. package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
  210. package/src/core/codemirror/code-lens/extension.ts +21 -13
  211. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -14
  212. package/src/core/codemirror/copilot/getCodes.ts +3 -14
  213. package/src/core/codemirror/debounced-editor-update.ts +41 -0
  214. package/src/core/codemirror/editor-mount-scheduler.ts +41 -48
  215. package/src/core/codemirror/extensions.ts +2 -2
  216. package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +42 -16
  217. package/src/core/codemirror/find-replace/__tests__/search-highlight.test.ts +30 -0
  218. package/src/core/codemirror/find-replace/__tests__/unmounted-cells.test.ts +145 -0
  219. package/src/core/codemirror/find-replace/navigate.ts +88 -129
  220. package/src/core/codemirror/find-replace/search-highlight.ts +3 -1
  221. package/src/core/codemirror/find-replace/state.ts +7 -2
  222. package/src/core/codemirror/format.ts +25 -31
  223. package/src/core/codemirror/go-to-definition/__tests__/underline.test.ts +58 -0
  224. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +24 -44
  225. package/src/core/codemirror/go-to-definition/extension.ts +9 -7
  226. package/src/core/codemirror/go-to-definition/underline.ts +39 -48
  227. package/src/core/codemirror/language/__tests__/sql.test.ts +36 -0
  228. package/src/core/codemirror/language/cell-code.ts +7 -0
  229. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
  230. package/src/core/codemirror/language/languages/sql/sql.ts +3 -0
  231. package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +25 -0
  232. package/src/core/codemirror/lsp/notebook-lsp.ts +6 -16
  233. package/src/core/codemirror/placeholder/extensions.ts +26 -24
  234. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +54 -0
  235. package/src/core/codemirror/reactive-references/extension.ts +30 -21
  236. package/src/core/codemirror/use-lazy-editor-mount.ts +70 -0
  237. package/src/core/codemirror/utils.ts +2 -6
  238. package/src/core/datasets/__tests__/data-source.test.ts +15 -17
  239. package/src/core/datasets/data-source-connections.ts +8 -11
  240. package/src/core/datasets/state.ts +7 -12
  241. package/src/core/dom/__tests__/uiregistry.test.ts +27 -0
  242. package/src/core/dom/uiregistry.ts +9 -7
  243. package/src/core/executions/__tests__/atoms.test.ts +211 -5
  244. package/src/core/executions/__tests__/freshness.test.ts +65 -56
  245. package/src/core/executions/__tests__/interrupt.test.ts +5 -3
  246. package/src/core/executions/__tests__/output-lifecycle.test.ts +95 -7
  247. package/src/core/executions/__tests__/output.test.ts +5 -3
  248. package/src/core/executions/__tests__/run.test.ts +4 -4
  249. package/src/core/executions/__tests__/select.test.ts +108 -69
  250. package/src/core/executions/atoms.ts +248 -83
  251. package/src/core/executions/freshness.ts +7 -7
  252. package/src/core/executions/hooks.ts +15 -59
  253. package/src/core/executions/index.ts +2 -0
  254. package/src/core/executions/output.ts +49 -35
  255. package/src/core/executions/select.ts +90 -37
  256. package/src/core/export/__tests__/hooks.test.ts +1 -1
  257. package/src/core/islands/__tests__/bridge.test.ts +1 -1
  258. package/src/core/islands/bootstrap.ts +7 -7
  259. package/src/core/islands/bridge.ts +1 -1
  260. package/src/core/meta/__tests__/code-visibility.test.tsx +3 -2
  261. package/src/core/notebook/document/__tests__/codemirror.test.ts +8 -6
  262. package/src/core/notebook/document/__tests__/draft.test.ts +56 -58
  263. package/src/core/notebook/document/__tests__/fixtures.ts +8 -7
  264. package/src/core/notebook/document/__tests__/hooks.test.tsx +39 -35
  265. package/src/core/notebook/document/__tests__/lifecycle-scenarios.test.ts +8 -5
  266. package/src/core/notebook/document/__tests__/model.test.ts +8 -5
  267. package/src/core/notebook/document/__tests__/protocol-fixtures.ts +2 -2
  268. package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +37 -32
  269. package/src/core/notebook/document/__tests__/scenarios.test.ts +49 -45
  270. package/src/core/notebook/document/__tests__/state.test.ts +59 -56
  271. package/src/core/notebook/document/__tests__/submission.test.ts +15 -12
  272. package/src/core/notebook/document/__tests__/test-host.ts +3 -2
  273. package/src/core/notebook/document/__tests__/user.ts +7 -3
  274. package/src/core/notebook/document/draft.ts +29 -11
  275. package/src/core/notebook/document/state.ts +7 -6
  276. package/src/core/notebook/replica/__tests__/document.test.ts +9 -5
  277. package/src/core/notebook/replica/__tests__/executions.test.ts +90 -25
  278. package/src/core/notebook/replica/__tests__/fixtures.ts +7 -2
  279. package/src/core/notebook/replica/__tests__/frame.test.ts +206 -0
  280. package/src/core/notebook/replica/__tests__/once-per-frame.test.ts +95 -0
  281. package/src/core/notebook/replica/__tests__/replica.test.ts +53 -9
  282. package/src/core/notebook/replica/__tests__/results.test.ts +27 -29
  283. package/src/core/notebook/replica/backend.ts +4 -1
  284. package/src/core/notebook/replica/execution-state.ts +2 -2
  285. package/src/core/notebook/replica/frame.ts +54 -0
  286. package/src/core/notebook/replica/index.ts +1 -0
  287. package/src/core/notebook/replica/once-per-frame.ts +60 -0
  288. package/src/core/notebook/replica/replica.ts +27 -6
  289. package/src/core/notebook/replica/resources/analysis.ts +1 -1
  290. package/src/core/notebook/replica/resources/document.ts +9 -8
  291. package/src/core/notebook/replica/resources/executions.ts +197 -78
  292. package/src/core/notebook/replica/resources/results.ts +8 -14
  293. package/src/core/saving/__tests__/document.test.tsx +1 -1
  294. package/src/core/saving/__tests__/state.test.ts +2 -2
  295. package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +55 -9
  296. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +230 -12
  297. package/src/core/session/active-notebook.ts +10 -1
  298. package/src/core/session/useNotebookReplica.ts +15 -2
  299. package/src/core/session/useNotebookSession.tsx +38 -46
  300. package/src/core/state/__tests__/atom-with-selected-inputs.test.ts +48 -0
  301. package/src/core/state/__tests__/create-keyed-selector-hook.test.tsx +137 -0
  302. package/src/core/state/atom-with-selected-inputs.ts +24 -0
  303. package/src/core/state/create-keyed-atom-hook.ts +18 -0
  304. package/src/core/state/create-keyed-selector-hook.ts +22 -0
  305. package/src/core/storage/__tests__/state.test.ts +6 -9
  306. package/src/core/storage/state.ts +5 -8
  307. package/src/core/transports/__tests__/static.test.ts +24 -20
  308. package/src/core/transports/static.ts +3 -2
  309. package/src/core/variables/state.ts +73 -68
  310. package/src/core/variables/types.ts +2 -2
  311. package/src/core/vscode/__tests__/is-in-vscode.test.ts +36 -0
  312. package/src/core/vscode/is-in-vscode.ts +2 -2
  313. package/src/core/wasm/__tests__/bridge.test.ts +73 -1
  314. package/src/core/wasm/bridge.ts +5 -4
  315. package/src/plugins/impl/TextInputPlugin.tsx +2 -1
  316. package/src/plugins/impl/__test__/text-labels.test.tsx +46 -1
  317. package/src/utils/__tests__/lazy.test.tsx +33 -0
  318. package/src/utils/__tests__/shared-intersection-observer.test.ts +49 -0
  319. package/src/utils/__tests__/shared-resource.test.ts +107 -0
  320. package/src/utils/arrays.ts +4 -1
  321. package/src/utils/lazy.tsx +74 -0
  322. package/src/utils/shared-intersection-observer.ts +53 -0
  323. package/src/utils/shared-resource.ts +59 -0
  324. package/src/core/variables/__tests__/state.test.ts +0 -148
  325. package/src/utils/lazy.ts +0 -35
@@ -1,6 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { useAtomValue, useStore } from "jotai";
4
+ import { selectAtom } from "jotai/utils";
4
5
  import {
5
6
  useDeleteCellCallback,
6
7
  useDeleteManyCellsCallback,
@@ -8,6 +9,7 @@ import {
8
9
  import { notebookAtom } from "@/core/cells/cells";
9
10
  import type { CellId } from "@/core/cells/ids";
10
11
  import { cellExecutionInputsAtom, cellExecutionView } from "@/core/executions";
12
+ import { createKeyedSelectorHook } from "@/core/state/create-keyed-selector-hook";
11
13
  import type { JotaiStore } from "@/core/state/jotai";
12
14
  import { variablesAtom } from "@/core/variables/state";
13
15
  import type { VariableName } from "@/core/variables/types";
@@ -33,98 +35,102 @@ const initialState = (): PendingDeleteState => ({
33
35
  entries: new Map(),
34
36
  });
35
37
 
36
- const { valueAtom: pendingDeleteStateAtom, useActions } = createReducerAndAtoms(
37
- initialState,
38
- {
39
- submit: (
40
- state,
41
- action: {
42
- cellIds: CellId[];
43
- deleteCell: (args: { cellId: CellId }) => void;
44
- deleteManyCells: (args: { cellIds: CellId[] }) => void;
45
- store: JotaiStore;
46
- },
47
- ) => {
48
- const { cellIds, deleteCell, deleteManyCells, store } = action;
49
- const notebook = store.get(notebookAtom);
50
- const executions = store.get(cellExecutionInputsAtom);
51
- const variables = store.get(variablesAtom);
52
-
53
- const emptyCells = new Set(
54
- notebook.cellIds.filter(
55
- (id) => notebook.cellData[id].code.trim() === "",
56
- ),
57
- );
58
-
59
- const entries = new Map<CellId, PendingDeleteEntry>();
60
- for (const cellId of cellIds) {
61
- if (emptyCells.has(cellId)) {
62
- // Empty cells indicate user intent to delete already
63
- entries.set(cellId, { cellId, type: "simple" });
64
- continue;
65
- }
66
-
67
- // Build defs map for this cell
68
- const defs = new Map<VariableName, readonly CellId[]>();
69
- for (const variable of Object.values(variables)) {
70
- const declaredByThisCell = variable.declaredBy.includes(cellId);
71
- const usedByNonEmptyCell = variable.usedBy.some(
72
- (cellId) => !emptyCells.has(cellId),
73
- );
74
- if (declaredByThisCell && usedByNonEmptyCell) {
75
- defs.set(variable.name, variable.usedBy);
76
- }
77
- }
38
+ const {
39
+ valueAtom: pendingDeleteStateAtom,
40
+ useActions,
41
+ reducer,
42
+ } = createReducerAndAtoms(initialState, {
43
+ submit: (
44
+ state,
45
+ action: {
46
+ cellIds: CellId[];
47
+ deleteCell: (args: { cellId: CellId }) => void;
48
+ deleteManyCells: (args: { cellIds: CellId[] }) => void;
49
+ store: JotaiStore;
50
+ },
51
+ ) => {
52
+ const { cellIds, deleteCell, deleteManyCells, store } = action;
53
+ const notebook = store.get(notebookAtom);
54
+ const executions = store.get(cellExecutionInputsAtom);
55
+ const variables = store.get(variablesAtom);
56
+
57
+ const emptyCells = new Set(
58
+ notebook.cellIds.filter((id) => notebook.cellData[id].code.trim() === ""),
59
+ );
60
+
61
+ const entries = new Map<CellId, PendingDeleteEntry>();
62
+ for (const cellId of cellIds) {
63
+ if (emptyCells.has(cellId)) {
64
+ // Empty cells indicate user intent to delete already
65
+ entries.set(cellId, { cellId, type: "simple" });
66
+ continue;
67
+ }
78
68
 
79
- let executionDurationMs: number | undefined;
80
- const { duration } = cellExecutionView(executions, cellId);
81
- if (duration !== null && duration > 2000) {
82
- executionDurationMs = duration;
69
+ // Build defs map for this cell
70
+ const defs = new Map<VariableName, readonly CellId[]>();
71
+ for (const variable of Object.values(variables)) {
72
+ const declaredByThisCell = variable.declaredBy.includes(cellId);
73
+ const usedByNonEmptyCell = variable.usedBy.some(
74
+ (cellId) => !emptyCells.has(cellId),
75
+ );
76
+ if (declaredByThisCell && usedByNonEmptyCell) {
77
+ defs.set(variable.name, variable.usedBy);
83
78
  }
79
+ }
84
80
 
85
- if (defs.size === 0 && executionDurationMs === undefined) {
86
- entries.set(cellId, { cellId, type: "simple" });
87
- } else {
88
- entries.set(cellId, {
89
- cellId,
90
- type: "expensive",
91
- executionDurationMs,
92
- defs,
93
- });
94
- }
81
+ let executionDurationMs: number | undefined;
82
+ const { duration } = cellExecutionView(executions, cellId);
83
+ if (duration !== null && duration > 2000) {
84
+ executionDurationMs = duration;
95
85
  }
96
86
 
97
- // Auto-delete if all are "simple" cells
98
- const allSimple = [...entries.values()].every(
99
- (entry) => entry.type === "simple",
100
- );
101
- if (entries.size > 0 && allSimple) {
102
- // Perform the deletion immediately
103
- if (entries.size === 1) {
104
- deleteCell({ cellId: [...entries.values()][0].cellId });
105
- } else {
106
- deleteManyCells({
107
- cellIds: [...entries.values()].map((e) => e.cellId),
108
- });
109
- }
110
- // Return empty state since we auto-deleted
111
- return initialState();
87
+ if (defs.size === 0 && executionDurationMs === undefined) {
88
+ entries.set(cellId, { cellId, type: "simple" });
89
+ } else {
90
+ entries.set(cellId, {
91
+ cellId,
92
+ type: "expensive",
93
+ executionDurationMs,
94
+ defs,
95
+ });
112
96
  }
97
+ }
113
98
 
114
- return {
115
- ...state,
116
- entries,
117
- };
118
- },
99
+ // Auto-delete if all are "simple" cells
100
+ const allSimple = [...entries.values()].every(
101
+ (entry) => entry.type === "simple",
102
+ );
103
+ if (entries.size > 0 && allSimple) {
104
+ // Perform the deletion immediately
105
+ if (entries.size === 1) {
106
+ deleteCell({ cellId: [...entries.values()][0].cellId });
107
+ } else {
108
+ deleteManyCells({
109
+ cellIds: [...entries.values()].map((e) => e.cellId),
110
+ });
111
+ }
112
+ // Return empty state since we auto-deleted
113
+ return initialState();
114
+ }
119
115
 
120
- clear: () => initialState(),
116
+ return {
117
+ ...state,
118
+ entries,
119
+ };
121
120
  },
121
+
122
+ clear: (state) => (state.entries.size === 0 ? state : initialState()),
123
+ });
124
+
125
+ const pendingDeleteCountAtom = selectAtom(
126
+ pendingDeleteStateAtom,
127
+ (state) => state.entries.size,
122
128
  );
123
129
 
124
130
  export function usePendingDeleteService() {
125
131
  const store = useStore();
126
132
  const { submit, clear } = useActions();
127
- const { entries } = useAtomValue(pendingDeleteStateAtom);
133
+ const count = useAtomValue(pendingDeleteCountAtom);
128
134
  const deleteCell = useDeleteCellCallback();
129
135
  const deleteManyCells = useDeleteManyCellsCallback();
130
136
  return {
@@ -132,23 +138,27 @@ export function usePendingDeleteService() {
132
138
  submit({ cellIds, deleteCell, deleteManyCells, store });
133
139
  },
134
140
  clear,
135
- idle: entries.size === 0,
136
- shouldConfirmDelete: entries.size > 1,
141
+ idle: count === 0,
142
+ shouldConfirmDelete: count > 1,
137
143
  };
138
144
  }
139
145
 
146
+ const usePendingDeleteEntry = createKeyedSelectorHook(
147
+ pendingDeleteStateAtom,
148
+ (state, cellId: CellId) => state.entries.get(cellId),
149
+ );
150
+
140
151
  export function usePendingDelete(cellId: CellId) {
141
- const state = useAtomValue(pendingDeleteStateAtom);
152
+ const entry = usePendingDeleteEntry(cellId);
153
+ const count = useAtomValue(pendingDeleteCountAtom);
142
154
  const actions = useActions();
143
155
  const deleteManyCells = useDeleteManyCellsCallback();
144
156
 
145
- const entry = state.entries.get(cellId);
146
-
147
157
  if (!entry) {
148
158
  return { isPending: false as const };
149
159
  }
150
160
 
151
- const canConfirmDelete = state.entries.size === 1;
161
+ const canConfirmDelete = count === 1;
152
162
 
153
163
  if (!canConfirmDelete) {
154
164
  return {
@@ -164,10 +174,12 @@ export function usePendingDelete(cellId: CellId) {
164
174
  shouldConfirmDelete: true as const,
165
175
  confirm: () => {
166
176
  deleteManyCells({
167
- cellIds: [...state.entries.values()].map((e) => e.cellId),
177
+ cellIds: [entry.cellId],
168
178
  });
169
179
  actions.clear();
170
180
  },
171
181
  cancel: () => actions.clear(),
172
182
  };
173
183
  }
184
+
185
+ export const visibleForTesting = { reducer, initialState };
@@ -1,10 +1,12 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import { createReducerAndAtoms } from "@/utils/createReducer";
3
- import type { TypedString } from "@/utils/typed";
4
- import type { Execution } from "@marimo-team/client/protocol";
3
+ import type {
4
+ ExecutionOutput as Execution,
5
+ RunId,
6
+ } from "@marimo-team/client/protocol";
5
7
  import { completedAt, startedAt } from "@/core/notebook/replica";
6
8
  import type { CellId } from "./ids";
7
- export type RunId = TypedString<"RunId">;
9
+ export type { RunId };
8
10
 
9
11
  export interface CellRun {
10
12
  cellId: CellId;
@@ -75,8 +77,8 @@ const {
75
77
  if (record.run_id === null || record.cell_id === null) {
76
78
  return state;
77
79
  }
78
- const runId = record.run_id as RunId;
79
- const cellId = record.cell_id as CellId;
80
+ const runId = record.run_id;
81
+ const cellId = record.cell_id;
80
82
  const previous = state.runMap.get(runId);
81
83
  if (previous === undefined && code !== undefined && isPureMarkdown(code)) {
82
84
  return state;
@@ -1,11 +1,11 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import type { RefObject } from "react";
3
3
  import {
4
+ focusEditor,
4
5
  isAnyCellFocused,
5
6
  tryFocus,
6
7
  } from "@/components/editor/navigation/focus-utils";
7
8
  import type { CellHandle } from "@/components/editor/notebook-cell";
8
- import { retryWithTimeout } from "@/utils/timeout";
9
9
  import { Logger } from "../../utils/Logger";
10
10
  import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
11
11
  import { scrollActiveLineIntoView } from "../codemirror/extensions";
@@ -49,8 +49,8 @@ export function focusAndScrollCellIntoView({
49
49
  // https://github.com/marimo-team/marimo/issues/2940
50
50
  tryFocus(element);
51
51
  } else {
52
- // Build this cell's editor now if it is still queued, so focus can land in
53
- // it instead of the placeholder.
52
+ // Build this cell's editor now if it is still dormant, so focus can land
53
+ // in it instead of the placeholder.
54
54
  editorMountScheduler.promote(cellId);
55
55
  const editor = cell.current?.editorView;
56
56
  if (!editor) {
@@ -63,17 +63,7 @@ export function focusAndScrollCellIntoView({
63
63
  return;
64
64
  }
65
65
 
66
- // Try to focus a few times
67
- retryWithTimeout(
68
- () => {
69
- editor.focus();
70
- return editor.hasFocus;
71
- },
72
- {
73
- retries: 5,
74
- delay: 20,
75
- },
76
- );
66
+ focusEditor(editor);
77
67
 
78
68
  if (codeFocus === "top") {
79
69
  // If codeFocus is top, move the cursor to the top of the editor.
@@ -16,6 +16,9 @@ import { type CellRuntimeState, createCellRuntimeState } from "./types";
16
16
 
17
17
  /** The identity of a snapshot the page carries. A host's own stream replaces it. */
18
18
  export const EMBEDDED = "embedded";
19
+ // SAFETY: This snapshot assigns one synthetic run ID to all its restored
20
+ // executions. The fixed suffix satisfies RunId's nonempty-string requirement.
21
+ const EMBEDDED_RUN_ID = `${EMBEDDED}:run` as Protocol.RunId;
19
22
 
20
23
  // Constants
21
24
  const DEFAULT_TIMESTAMP = 0;
@@ -168,7 +171,7 @@ function createEmptySessionCell(): SessionCell {
168
171
  }
169
172
 
170
173
  /** The cell as a host would describe it. A snapshot never changes, so its etags only need to be distinct. */
171
- function cellRecord(cellId: CellId, cell: NotebookCell): Protocol.Cell {
174
+ function cellRecord(cellId: CellId, cell: NotebookCell): Protocol.CellOutput {
172
175
  return {
173
176
  id: cellId,
174
177
  notebook_id: EMBEDDED,
@@ -214,12 +217,12 @@ function normalizeTraceback(lines: readonly string[]): string | null {
214
217
  * current, with no runtime behind it.
215
218
  */
216
219
  function resultRecord(
217
- cell: Protocol.Cell,
220
+ cell: Protocol.CellOutput,
218
221
  sessionCell: SessionCell | null | undefined,
219
222
  ): StaticResult | null {
220
223
  const primary = primaryOutputOf(sessionCell);
221
224
  const id = `${EMBEDDED}:${cell.id}:result`;
222
- let outcome: Protocol.ExecutionOutcome;
225
+ let outcome: Protocol.ExecutionOutcomeOutput;
223
226
  let output: Protocol.Output | null = null;
224
227
  if (primary === undefined) {
225
228
  return null;
@@ -261,7 +264,7 @@ function resultRecord(
261
264
  return {
262
265
  execution: {
263
266
  id,
264
- run_id: `${EMBEDDED}:run`,
267
+ run_id: EMBEDDED_RUN_ID,
265
268
  runtime_id: EMBEDDED,
266
269
  caused_by_id: null,
267
270
  cell_id: cell.id,
@@ -352,7 +355,7 @@ export function readExport({
352
355
  return { snapshot: null, cellRuntime: {} };
353
356
  }
354
357
 
355
- const cells: Protocol.Cell[] = [];
358
+ const cells: Protocol.CellOutput[] = [];
356
359
  const results: StaticResult[] = [];
357
360
  const cellRuntime: Record<CellId, CellRuntimeState> = {};
358
361
  for (const cellId of cellIds) {
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import type { EditorView } from "@codemirror/view";
4
3
  import {
5
4
  type CellError,
6
5
  type CellExecutionInputs,
@@ -11,7 +10,6 @@ import {
11
10
  cellExecutionView,
12
11
  } from "@/core/executions";
13
12
  import type { Executions } from "@/core/notebook/replica";
14
- import { Objects } from "@/utils/objects";
15
13
  import { isErrorMime } from "../mime";
16
14
  import type { NotebookState } from "./cells";
17
15
  import type { CellId } from "./ids";
@@ -21,17 +19,6 @@ export function notebookCells(state: NotebookState) {
21
19
  return state.cellIds.map((cellId) => state.cellData[cellId]);
22
20
  }
23
21
 
24
- export function notebookCellEditorViews({ cellHandles }: NotebookState) {
25
- const views: Record<CellId, EditorView> = {};
26
- for (const [cell, ref] of Objects.entries(cellHandles)) {
27
- if (!ref.current?.editorView) {
28
- continue;
29
- }
30
- views[cell] = ref.current.editorView;
31
- }
32
- return views;
33
- }
34
-
35
22
  export function disabledCellIds(state: NotebookState) {
36
23
  const { cellIds, cellData } = state;
37
24
  const disabledCells: CellId[] = [];
@@ -0,0 +1,79 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { EditorView } from "@codemirror/view";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { cellId } from "@/__tests__/branded";
5
+ import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
6
+ import { createCell } from "@/core/cells/types";
7
+ import { store } from "@/core/state/jotai";
8
+ import { getCellDocuments, writeCellCode } from "../cell-documents";
9
+
10
+ const { writes } = vi.hoisted(() => ({ writes: vi.fn() }));
11
+ vi.mock("@/core/cells/actions", async () => {
12
+ const { atom } = await import("jotai");
13
+ return { setCellCodeAtom: atom(null, (_get, _set, w) => writes(w)) };
14
+ });
15
+
16
+ const id = cellId("cell");
17
+
18
+ function setNotebook(code: string, view: EditorView | null) {
19
+ store.set(notebookAtom, {
20
+ ...initialNotebookState(),
21
+ cellIds: [id],
22
+ cellData: { [id]: createCell({ id, code }) },
23
+ cellHandles: {
24
+ [id]: {
25
+ current: { editorView: view },
26
+ },
27
+ },
28
+ });
29
+ }
30
+
31
+ afterEach(() => {
32
+ writes.mockClear();
33
+ store.set(notebookAtom, initialNotebookState());
34
+ });
35
+
36
+ it("derives a document from the stored code when the cell has no editor", () => {
37
+ setNotebook('mo.md(r"""# Title""")', null);
38
+
39
+ const [document] = getCellDocuments();
40
+
41
+ expect(document.view).toBeNull();
42
+ expect(document.state.doc.toString()).toBe("# Title");
43
+ expect(document.code).toBe('mo.md(r"""# Title""")');
44
+ });
45
+
46
+ it("reads a mounted editor's document and Python code", () => {
47
+ const view = new EditorView({ doc: "x = 1" });
48
+ setNotebook("x = 1", view);
49
+
50
+ const [document] = getCellDocuments();
51
+
52
+ expect(document.view).toBe(view);
53
+ expect(document.state).toBe(view.state);
54
+ expect(document.code).toBe("x = 1");
55
+ view.destroy();
56
+ });
57
+
58
+ it("writes document changes back as the cell's Python code", () => {
59
+ setNotebook('mo.md(r"""# Title""")', null);
60
+ const [document] = getCellDocuments();
61
+
62
+ document.applyChanges({ from: 2, to: 7, insert: "Heading" }, "input");
63
+
64
+ expect(writes).toHaveBeenCalledExactlyOnceWith({
65
+ cellId: id,
66
+ code: expect.stringContaining("# Heading"),
67
+ });
68
+ expect(writes.mock.lastCall?.[0].code).toMatch(/^mo\.md\(/);
69
+ });
70
+
71
+ it("does not write code the cell already has", () => {
72
+ setNotebook("x = 1", null);
73
+
74
+ writeCellCode(id, "x = 1");
75
+ expect(writes).not.toHaveBeenCalled();
76
+
77
+ writeCellCode(id, "x = 2");
78
+ expect(writes).toHaveBeenCalledExactlyOnceWith({ cellId: id, code: "x = 2" });
79
+ });
@@ -0,0 +1,72 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { EditorView } from "@codemirror/view";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { createDebouncedEditorUpdate } from "../debounced-editor-update";
5
+
6
+ describe("debounced editor updates", () => {
7
+ let view: EditorView;
8
+ beforeEach(() => {
9
+ vi.useFakeTimers();
10
+ view = new EditorView({ doc: "initial" });
11
+ });
12
+ afterEach(() => {
13
+ view.destroy();
14
+ vi.useRealTimers();
15
+ });
16
+
17
+ it("coalesces invalidations and reads the latest state at dispatch time", async () => {
18
+ const compute = vi.fn(() => ({
19
+ selection: { anchor: view.state.doc.length },
20
+ }));
21
+ const update = createDebouncedEditorUpdate(view, compute);
22
+ const dispatch = vi.spyOn(view, "dispatch");
23
+ for (let i = 0; i < 500; i++) {
24
+ update.schedule();
25
+ }
26
+ vi.advanceTimersByTime(300);
27
+ expect(compute).not.toHaveBeenCalled();
28
+ view.dispatch({
29
+ changes: { from: 0, to: view.state.doc.length, insert: "latest" },
30
+ });
31
+ dispatch.mockClear();
32
+ await Promise.resolve();
33
+ expect(compute).toHaveBeenCalledOnce();
34
+ expect(dispatch).toHaveBeenCalledOnce();
35
+ expect(view.state.selection.main.anchor).toBe(6);
36
+ update.destroy();
37
+ });
38
+
39
+ it.each([false, true])(
40
+ "cancels work on destroy (already queued: %s)",
41
+ async (queued) => {
42
+ const compute = vi.fn(() => ({}));
43
+ const update = createDebouncedEditorUpdate(view, compute);
44
+ update.schedule();
45
+ if (queued) {
46
+ vi.advanceTimersByTime(300);
47
+ }
48
+ update.destroy();
49
+ update.destroy();
50
+ update.schedule();
51
+ vi.advanceTimersByTime(300);
52
+ await Promise.resolve();
53
+ expect(compute).not.toHaveBeenCalled();
54
+ },
55
+ );
56
+
57
+ it("supersedes queued work when invalidated again", async () => {
58
+ const compute = vi.fn(() => undefined);
59
+ const update = createDebouncedEditorUpdate(view, compute);
60
+ const dispatch = vi.spyOn(view, "dispatch");
61
+ update.schedule();
62
+ vi.advanceTimersByTime(300);
63
+ update.schedule();
64
+ await Promise.resolve();
65
+ expect(compute).not.toHaveBeenCalled();
66
+ vi.advanceTimersByTime(300);
67
+ await Promise.resolve();
68
+ expect(compute).toHaveBeenCalledOnce();
69
+ expect(dispatch).not.toHaveBeenCalled();
70
+ update.destroy();
71
+ });
72
+ });