@marimo-team/frontend 0.14.18-dev4 → 0.14.18-dev40

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 (1271) hide show
  1. package/dist/assets/{ConnectedDataExplorerComponent-s7RGpPDV.js → ConnectedDataExplorerComponent-Dluf8clT.js} +1 -1
  2. package/dist/assets/{ImageComparisonComponent-CnrulJpr.js → ImageComparisonComponent-CK_fmBK6.js} +1 -1
  3. package/dist/assets/{VegaLite-C2fs5zc3.js → VegaLite-GAUrkYuV.js} +1 -1
  4. package/dist/assets/{_baseEach-c_dyjc-O.js → _baseEach-C0Sqwj1Y.js} +1 -1
  5. package/dist/assets/_baseMap-wbAXOiz5.js +1 -0
  6. package/dist/assets/{_baseUniq-MHRYxaEh.js → _baseUniq-C6CtZ9jJ.js} +1 -1
  7. package/dist/assets/{_createAggregator-BRrHJm-S.js → _createAggregator-DCg3aG5g.js} +1 -1
  8. package/dist/assets/{any-language-editor-BvO3QFMF.js → any-language-editor-C1hAvQU_.js} +1 -1
  9. package/dist/assets/{architectureDiagram-SUXI7LT5-NdrSJuvB.js → architectureDiagram-SUXI7LT5-CY6ZXfK5.js} +1 -1
  10. package/dist/assets/{blockDiagram-6J76NXCF-ftx5RUcT.js → blockDiagram-6J76NXCF-BfT_qzzN.js} +1 -1
  11. package/dist/assets/{c4Diagram-6F6E4RAY-BulMqa-Y.js → c4Diagram-6F6E4RAY-BNmm8mbN.js} +1 -1
  12. package/dist/assets/channel-p2n1Ehs7.js +1 -0
  13. package/dist/assets/{chunk-353BL4L5-D5H2iwN7.js → chunk-353BL4L5-BD1eYYEv.js} +1 -1
  14. package/dist/assets/{chunk-67H74DCK-LK08G4lc.js → chunk-67H74DCK-D32ZcVIe.js} +1 -1
  15. package/dist/assets/{chunk-AACKK3MU-B9JAiO5u.js → chunk-AACKK3MU-VRjqE2eS.js} +1 -1
  16. package/dist/assets/{chunk-BFAMUDN2-CZKcG7Hk.js → chunk-BFAMUDN2-C-cJmQLf.js} +1 -1
  17. package/dist/assets/{chunk-E2GYISFI-CIXtdUNn.js → chunk-E2GYISFI-BVyg2Fo6.js} +1 -1
  18. package/dist/assets/{chunk-OW32GOEJ-C4FCmwnP.js → chunk-OW32GOEJ-CJAy1Ibj.js} +6 -6
  19. package/dist/assets/{chunk-SKB7J2MH-BaSlr3jl.js → chunk-SKB7J2MH-CNnoGuDT.js} +1 -1
  20. package/dist/assets/{chunk-SZ463SBG-BwDfdiOo.js → chunk-SZ463SBG-B-DyRJ-t.js} +1 -1
  21. package/dist/assets/{circle-play-JsgbRX6G.js → circle-play-DlcQmjy-.js} +1 -1
  22. package/dist/assets/classDiagram-M3E45YP4-CvCuraNp.js +1 -0
  23. package/dist/assets/classDiagram-v2-YAWTLIQI-CvCuraNp.js +1 -0
  24. package/dist/assets/clone-CglRxjPg.js +1 -0
  25. package/dist/assets/common-keywords-Dg3Y2cJS.js +1 -0
  26. package/dist/assets/{compile-BGbhA30T.js → compile-Da_Fjkgs.js} +1 -1
  27. package/dist/assets/{dagre-JOIXM2OF-B8vUNw1G.js → dagre-JOIXM2OF-B6XR4pJX.js} +1 -1
  28. package/dist/assets/{data-grid-overlay-editor-5lo5J1Vt.js → data-grid-overlay-editor-v4eNCtyj.js} +1 -1
  29. package/dist/assets/{diagram-5UYTHUR4-PLDgwO4x.js → diagram-5UYTHUR4-fJ5HfR4m.js} +1 -1
  30. package/dist/assets/{diagram-VMROVX33-B5-7SLna.js → diagram-VMROVX33-j3xejCo0.js} +1 -1
  31. package/dist/assets/{diagram-ZTM2IBQH-BnKr5V6h.js → diagram-ZTM2IBQH-dkgnTPsZ.js} +1 -1
  32. package/dist/assets/duckdb-keywords-CFYiiNsB.js +1 -0
  33. package/dist/assets/edit-page-CmCSSEmo.js +163 -0
  34. package/dist/assets/{erDiagram-3M52JZNH-Dk0Y_2Is.js → erDiagram-3M52JZNH-pjMXU-CR.js} +1 -1
  35. package/dist/assets/{flowDiagram-KYDEHFYC-DM8J3haJ.js → flowDiagram-KYDEHFYC-RFXKcK0k.js} +1 -1
  36. package/dist/assets/{ganttDiagram-EK5VF46D-B7MEeaeb.js → ganttDiagram-EK5VF46D-BgmOCQC2.js} +1 -1
  37. package/dist/assets/{gitGraphDiagram-GW3U2K7C-ciOWHdK1.js → gitGraphDiagram-GW3U2K7C-DQPA3IzE.js} +1 -1
  38. package/dist/assets/{glide-data-editor-CeJNWkGL.js → glide-data-editor-DWBodoS3.js} +11 -11
  39. package/dist/assets/{graph-IzuQV5TV.js → graph-DacIO-UV.js} +1 -1
  40. package/dist/assets/{home-page-P0hOk_Lu.js → home-page-CRXrPrxk.js} +2 -2
  41. package/dist/assets/{index-D86OE7I-.js → index-8RrfVV3p.js} +1 -1
  42. package/dist/assets/{index-ZMOxgO0o.js → index-BC3mHcN4.js} +1 -1
  43. package/dist/assets/{index-DzmGiDPv.js → index-BDUp_sLz.js} +1 -1
  44. package/dist/assets/{index-Bw4_53VL.js → index-BHV0wUT7.js} +211 -201
  45. package/dist/assets/{index-DzcdkCgc.js → index-BQF1L3gh.js} +1 -1
  46. package/dist/assets/{index-CTxIrFfM.js → index-BRCKCYPN.js} +1 -1
  47. package/dist/assets/{index-CvNa254z.js → index-BXCylVut.js} +1 -1
  48. package/dist/assets/{index-BtVdSmBr.js → index-Bg24ojRl.js} +1 -1
  49. package/dist/assets/{index-BqqAIR7p.js → index-BoaOUG3q.js} +1 -1
  50. package/dist/assets/{index-DL31Tmv6.js → index-BxSZURSP.js} +1 -1
  51. package/dist/assets/{index-DVgehULr.js → index-BxjU6sz1.js} +1 -1
  52. package/dist/assets/{index--eqo3Nr1.js → index-C8_gM-Yh.js} +1 -1
  53. package/dist/assets/{index-CrnLkrsN.js → index-CRoIS0e_.js} +1 -1
  54. package/dist/assets/index-CrH6PPjG.css +1 -0
  55. package/dist/assets/{index-DKlX9VbD.js → index-D-j7DlKu.js} +1 -1
  56. package/dist/assets/{index-DyGhL8pb.js → index-D6Npa4_9.js} +1 -1
  57. package/dist/assets/{index-VEO6hI2a.js → index-M577h3xO.js} +1 -1
  58. package/dist/assets/{index-vOKQtqij.js → index-PXlQy2IY.js} +1 -1
  59. package/dist/assets/{index-ABc3l5O5.js → index-dlPsVpRk.js} +1 -1
  60. package/dist/assets/index-i68zQEWD.js +68 -0
  61. package/dist/assets/{index-DWbP9NKv.js → index-txOE5caF.js} +1 -1
  62. package/dist/assets/infoDiagram-LHK5PUON-BQo83J9q.js +2 -0
  63. package/dist/assets/{journeyDiagram-EWQZEKCU-D-rWvB9c.js → journeyDiagram-EWQZEKCU--vn5uP9G.js} +1 -1
  64. package/dist/assets/{kanban-definition-ZSS6B67P-BPrv-lG3.js → kanban-definition-ZSS6B67P-BsAtaVBp.js} +1 -1
  65. package/dist/assets/{layout-C3NQCD38.js → layout-D89ZmFuH.js} +1 -1
  66. package/dist/assets/{linear-Dcz3lyvf.js → linear--2JfAOS_.js} +1 -1
  67. package/dist/assets/links-DHuoq13s.js +17 -0
  68. package/dist/assets/{mermaid-BjMqU7B7.js → mermaid-BbIb2iAQ.js} +26 -26
  69. package/dist/assets/min-B719_H4j.js +1 -0
  70. package/dist/assets/{mindmap-definition-6CBA2TL7-BZsnMx2y.js → mindmap-definition-6CBA2TL7-DbrwDtvS.js} +1 -1
  71. package/dist/assets/{number-overlay-editor-CzX-JKBj.js → number-overlay-editor-VjmSOKWj.js} +2 -2
  72. package/dist/assets/{pieDiagram-NIOCPIFQ-BjbDT3_7.js → pieDiagram-NIOCPIFQ-DDr_8e6N.js} +3 -3
  73. package/dist/assets/{quadrantDiagram-2OG54O6I-DwvUEn5y.js → quadrantDiagram-2OG54O6I-TFsW3qDt.js} +1 -1
  74. package/dist/assets/{react-plotly-DsUGZTQl.js → react-plotly-BJBcptDR.js} +1 -1
  75. package/dist/assets/{requirementDiagram-QOLK2EJ7-DnqQ02xB.js → requirementDiagram-QOLK2EJ7-D5BaSClp.js} +1 -1
  76. package/dist/assets/{run-page-Dh1_LBex.js → run-page-D1TeIIYq.js} +1 -1
  77. package/dist/assets/{sankeyDiagram-4UZDY2LN-CGiEg-KK.js → sankeyDiagram-4UZDY2LN-B-zmPQdl.js} +1 -1
  78. package/dist/assets/{sequenceDiagram-SKLFT4DO-Du_9Bhah.js → sequenceDiagram-SKLFT4DO-Dw--eukV.js} +1 -1
  79. package/dist/assets/{slides-component-DbRb2vqt.js → slides-component-CUV-ryNw.js} +1 -1
  80. package/dist/assets/sortBy-C9K5SL89.js +1 -0
  81. package/dist/assets/{stateDiagram-MI5ZYTHO-x_vUiEQz.js → stateDiagram-MI5ZYTHO-WTQoQzCe.js} +1 -1
  82. package/dist/assets/stateDiagram-v2-5AN5P6BG-CoRRGWzU.js +1 -0
  83. package/dist/assets/storage-BgxGjrlK.js +26 -0
  84. package/dist/assets/{terminal-xOuxdYpY.js → terminal-BRsJ5bg0.js} +1 -1
  85. package/dist/assets/time-Wo8mRr4h.js +1 -0
  86. package/dist/assets/{timeline-definition-MYPXXCX6-8Kv4fcyB.js → timeline-definition-MYPXXCX6-DUiBvKXW.js} +1 -1
  87. package/dist/assets/{tracing-BAj6E74_.js → tracing-DkTh5bjk.js} +2 -2
  88. package/dist/assets/{trash-65Vbt3F6.js → trash-_cwoDPy1.js} +1 -1
  89. package/dist/assets/{treemap-75Q7IDZK-DtSMjk1Y.js → treemap-75Q7IDZK-DndwJIAY.js} +1 -1
  90. package/dist/assets/{vega-component-C3aywWbx.js → vega-component-BQrEMxr7.js} +1 -1
  91. package/dist/assets/{xychartDiagram-H2YORKM3-D33F1MLE.js → xychartDiagram-H2YORKM3-Cn7nHPc6.js} +1 -1
  92. package/dist/index.html +2 -2
  93. package/package.json +12 -6
  94. package/src/README.md +18 -0
  95. package/src/__mocks__/common.ts +160 -0
  96. package/src/__mocks__/notebook.ts +76 -0
  97. package/src/__mocks__/requests.ts +72 -0
  98. package/src/__mocks__/tracebacks.ts +32 -0
  99. package/src/__tests__/CellStatus.test.tsx +263 -0
  100. package/src/__tests__/__snapshots__/CellStatus.test.tsx.snap +523 -0
  101. package/src/__tests__/chat-utils.test.ts +234 -0
  102. package/src/__tests__/lru.test.ts +74 -0
  103. package/src/__tests__/main.test.tsx +174 -0
  104. package/src/__tests__/setup.ts +17 -0
  105. package/src/__tests__/test-helpers.ts +24 -0
  106. package/src/assets/circle-check.ico +0 -0
  107. package/src/assets/circle-play.ico +0 -0
  108. package/src/assets/circle-x.ico +0 -0
  109. package/src/assets/gradient.png +0 -0
  110. package/src/assets/icon-16x16.png +0 -0
  111. package/src/assets/icon-32x32.png +0 -0
  112. package/src/assets/noise.png +0 -0
  113. package/src/components/ai/ai-model-dropdown.tsx +280 -0
  114. package/src/components/ai/ai-provider-icon.tsx +52 -0
  115. package/src/components/app-config/ai-config.tsx +855 -0
  116. package/src/components/app-config/app-config-button.tsx +100 -0
  117. package/src/components/app-config/app-config-form.tsx +307 -0
  118. package/src/components/app-config/common.tsx +48 -0
  119. package/src/components/app-config/constants.ts +13 -0
  120. package/src/components/app-config/incorrect-model-id.tsx +43 -0
  121. package/src/components/app-config/is-overridden.tsx +119 -0
  122. package/src/components/app-config/optional-features.tsx +251 -0
  123. package/src/components/app-config/state.ts +18 -0
  124. package/src/components/app-config/user-config-form.tsx +1361 -0
  125. package/src/components/audio/audio-recorder.tsx +63 -0
  126. package/src/components/buttons/clear-button.tsx +23 -0
  127. package/src/components/buttons/undo-button.tsx +35 -0
  128. package/src/components/chat/chat-panel.tsx +715 -0
  129. package/src/components/chat/markdown-renderer.tsx +217 -0
  130. package/src/components/chat/reasoning-accordion.tsx +50 -0
  131. package/src/components/chat/tool-call-accordion.tsx +118 -0
  132. package/src/components/data-table/SearchBar.tsx +66 -0
  133. package/src/components/data-table/TableActions.tsx +183 -0
  134. package/src/components/data-table/__tests__/__snapshots__/chart-spec-model.test.ts.snap +1079 -0
  135. package/src/components/data-table/__tests__/chart-spec-model.test.ts +707 -0
  136. package/src/components/data-table/__tests__/column_formatting.test.ts +115 -0
  137. package/src/components/data-table/__tests__/columns.test.tsx +341 -0
  138. package/src/components/data-table/__tests__/data-table.test.tsx +60 -0
  139. package/src/components/data-table/__tests__/pagination.test.tsx +152 -0
  140. package/src/components/data-table/__tests__/types.test.ts +44 -0
  141. package/src/components/data-table/__tests__/url-detector.test.tsx +169 -0
  142. package/src/components/data-table/__tests__/useColumnPinning.test.ts +76 -0
  143. package/src/components/data-table/cell-selection/__tests__/feature.test.ts +187 -0
  144. package/src/components/data-table/cell-selection/feature.ts +123 -0
  145. package/src/components/data-table/cell-selection/types.ts +49 -0
  146. package/src/components/data-table/cell-styling/feature.ts +40 -0
  147. package/src/components/data-table/cell-styling/types.ts +26 -0
  148. package/src/components/data-table/charts/README.md +65 -0
  149. package/src/components/data-table/charts/__tests__/__snapshots__/spec-snapshot.test.ts.snap +47 -0
  150. package/src/components/data-table/charts/__tests__/altair-generator.test.ts +425 -0
  151. package/src/components/data-table/charts/__tests__/renderer.test.ts +20 -0
  152. package/src/components/data-table/charts/__tests__/spec-snapshot.test.ts +83 -0
  153. package/src/components/data-table/charts/__tests__/spec.test.ts +997 -0
  154. package/src/components/data-table/charts/__tests__/storage.test.ts +103 -0
  155. package/src/components/data-table/charts/chart-spec/altair-generator.ts +162 -0
  156. package/src/components/data-table/charts/chart-spec/encodings.ts +173 -0
  157. package/src/components/data-table/charts/chart-spec/spec.ts +345 -0
  158. package/src/components/data-table/charts/chart-spec/tooltips.ts +168 -0
  159. package/src/components/data-table/charts/chart-spec/types.ts +77 -0
  160. package/src/components/data-table/charts/charts.tsx +492 -0
  161. package/src/components/data-table/charts/components/chart-items.tsx +369 -0
  162. package/src/components/data-table/charts/components/chart-states.tsx +37 -0
  163. package/src/components/data-table/charts/components/form-fields.tsx +872 -0
  164. package/src/components/data-table/charts/components/layouts.tsx +118 -0
  165. package/src/components/data-table/charts/constants.ts +159 -0
  166. package/src/components/data-table/charts/context.ts +20 -0
  167. package/src/components/data-table/charts/forms/common-chart.tsx +202 -0
  168. package/src/components/data-table/charts/forms/heatmap.tsx +44 -0
  169. package/src/components/data-table/charts/forms/pie.tsx +70 -0
  170. package/src/components/data-table/charts/lazy-chart.tsx +56 -0
  171. package/src/components/data-table/charts/schemas.ts +140 -0
  172. package/src/components/data-table/charts/storage.ts +88 -0
  173. package/src/components/data-table/charts/types.ts +124 -0
  174. package/src/components/data-table/column-explorer-panel/column-explorer.tsx +227 -0
  175. package/src/components/data-table/column-formatting/feature.ts +247 -0
  176. package/src/components/data-table/column-formatting/types.ts +54 -0
  177. package/src/components/data-table/column-header.tsx +672 -0
  178. package/src/components/data-table/column-summary/chart-skeleton.tsx +57 -0
  179. package/src/components/data-table/column-summary/chart-spec-model.tsx +916 -0
  180. package/src/components/data-table/column-summary/column-summary.tsx +166 -0
  181. package/src/components/data-table/column-summary/legacy-chart-spec.ts +242 -0
  182. package/src/components/data-table/column-summary/utils.ts +142 -0
  183. package/src/components/data-table/column-wrapping/feature.ts +62 -0
  184. package/src/components/data-table/column-wrapping/types.ts +29 -0
  185. package/src/components/data-table/columns.tsx +528 -0
  186. package/src/components/data-table/copy-column/feature.ts +27 -0
  187. package/src/components/data-table/copy-column/types.ts +19 -0
  188. package/src/components/data-table/data-table.tsx +298 -0
  189. package/src/components/data-table/date-popover.tsx +146 -0
  190. package/src/components/data-table/download-actions.tsx +186 -0
  191. package/src/components/data-table/filter-pills.tsx +120 -0
  192. package/src/components/data-table/filters.ts +202 -0
  193. package/src/components/data-table/focus-row/feature.ts +41 -0
  194. package/src/components/data-table/focus-row/types.ts +32 -0
  195. package/src/components/data-table/header-items.tsx +295 -0
  196. package/src/components/data-table/hooks/use-column-pinning.ts +51 -0
  197. package/src/components/data-table/hooks/use-panel-ownership.ts +98 -0
  198. package/src/components/data-table/loading-table.tsx +56 -0
  199. package/src/components/data-table/mime-cell.tsx +68 -0
  200. package/src/components/data-table/pagination.tsx +329 -0
  201. package/src/components/data-table/range-focus/__tests__/atoms.test.ts +907 -0
  202. package/src/components/data-table/range-focus/__tests__/utils.test.ts +316 -0
  203. package/src/components/data-table/range-focus/atoms.ts +380 -0
  204. package/src/components/data-table/range-focus/cell-selection-indicator.tsx +37 -0
  205. package/src/components/data-table/range-focus/provider.tsx +13 -0
  206. package/src/components/data-table/range-focus/use-cell-range-selection.ts +119 -0
  207. package/src/components/data-table/range-focus/use-scroll-into-view.ts +46 -0
  208. package/src/components/data-table/range-focus/utils.ts +105 -0
  209. package/src/components/data-table/renderers.tsx +247 -0
  210. package/src/components/data-table/row-viewer-panel/__tests__/filter-rows.test.ts +82 -0
  211. package/src/components/data-table/row-viewer-panel/__tests__/row-viewer.test.tsx +58 -0
  212. package/src/components/data-table/row-viewer-panel/row-viewer.tsx +371 -0
  213. package/src/components/data-table/types.ts +81 -0
  214. package/src/components/data-table/uniformSample.tsx +19 -0
  215. package/src/components/data-table/url-detector.tsx +111 -0
  216. package/src/components/data-table/utils.ts +46 -0
  217. package/src/components/databases/display.tsx +66 -0
  218. package/src/components/databases/engine-variable.tsx +51 -0
  219. package/src/components/databases/icon.tsx +91 -0
  220. package/src/components/databases/icons/clickhouse.svg +1 -0
  221. package/src/components/databases/icons/databricks.svg +1 -0
  222. package/src/components/databases/icons/datafusion.png +0 -0
  223. package/src/components/databases/icons/duckdb.svg +1 -0
  224. package/src/components/databases/icons/googlebigquery.svg +1 -0
  225. package/src/components/databases/icons/iceberg.png +0 -0
  226. package/src/components/databases/icons/motherduck.svg +9 -0
  227. package/src/components/databases/icons/mysql.svg +1 -0
  228. package/src/components/databases/icons/postgresql.svg +1 -0
  229. package/src/components/databases/icons/redshift.svg +1 -0
  230. package/src/components/databases/icons/snowflake.svg +1 -0
  231. package/src/components/databases/icons/spark.svg +1 -0
  232. package/src/components/databases/icons/sqlalchemy.svg +1 -0
  233. package/src/components/databases/icons/sqlite.svg +1 -0
  234. package/src/components/databases/icons/timeplus.svg +17 -0
  235. package/src/components/databases/icons/trino.svg +1 -0
  236. package/src/components/datasets/icons.tsx +55 -0
  237. package/src/components/datasources/__tests__/install-package-button.test.tsx +85 -0
  238. package/src/components/datasources/__tests__/utils.test.ts +171 -0
  239. package/src/components/datasources/column-preview.tsx +269 -0
  240. package/src/components/datasources/components.tsx +100 -0
  241. package/src/components/datasources/datasources.tsx +782 -0
  242. package/src/components/datasources/install-package-button.tsx +46 -0
  243. package/src/components/datasources/utils.ts +62 -0
  244. package/src/components/debug/indicator.tsx +19 -0
  245. package/src/components/debugger/debugger-code.css +3 -0
  246. package/src/components/debugger/debugger-code.tsx +222 -0
  247. package/src/components/dependency-graph/custom-node.tsx +89 -0
  248. package/src/components/dependency-graph/dependency-graph-minimap.tsx +197 -0
  249. package/src/components/dependency-graph/dependency-graph-tree.tsx +181 -0
  250. package/src/components/dependency-graph/dependency-graph.css +17 -0
  251. package/src/components/dependency-graph/dependency-graph.tsx +66 -0
  252. package/src/components/dependency-graph/elements.ts +185 -0
  253. package/src/components/dependency-graph/panels.tsx +279 -0
  254. package/src/components/dependency-graph/types.ts +21 -0
  255. package/src/components/dependency-graph/utils/changes.ts +54 -0
  256. package/src/components/dependency-graph/utils/layout.ts +45 -0
  257. package/src/components/dependency-graph/utils/useFitToViewOnDimensionChange.ts +25 -0
  258. package/src/components/editor/Cell.tsx +1175 -0
  259. package/src/components/editor/Disconnected.tsx +72 -0
  260. package/src/components/editor/Output.tsx +462 -0
  261. package/src/components/editor/RecoveryButton.tsx +161 -0
  262. package/src/components/editor/SortableCell.tsx +161 -0
  263. package/src/components/editor/__tests__/data-attributes.test.tsx +173 -0
  264. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +183 -0
  265. package/src/components/editor/actions/name-cell-input.tsx +137 -0
  266. package/src/components/editor/actions/types.ts +53 -0
  267. package/src/components/editor/actions/useCellActionButton.tsx +422 -0
  268. package/src/components/editor/actions/useConfigActions.tsx +182 -0
  269. package/src/components/editor/actions/useCopyNotebook.tsx +41 -0
  270. package/src/components/editor/actions/useHideAllMarkdownCode.ts +53 -0
  271. package/src/components/editor/actions/useNotebookActions.tsx +556 -0
  272. package/src/components/editor/actions/useRestartKernel.tsx +36 -0
  273. package/src/components/editor/ai/__tests__/completion-utils.test.ts +379 -0
  274. package/src/components/editor/ai/add-cell-with-ai.tsx +423 -0
  275. package/src/components/editor/ai/ai-completion-editor.tsx +261 -0
  276. package/src/components/editor/ai/completion-utils.ts +95 -0
  277. package/src/components/editor/ai/merge-editor.css +9 -0
  278. package/src/components/editor/alerts/connecting-alert.tsx +46 -0
  279. package/src/components/editor/alerts/floating-alert.tsx +47 -0
  280. package/src/components/editor/alerts/stdin-blocking-alert.tsx +61 -0
  281. package/src/components/editor/app-container.tsx +53 -0
  282. package/src/components/editor/boundary/ErrorBoundary.tsx +41 -0
  283. package/src/components/editor/cell/CellStatus.tsx +371 -0
  284. package/src/components/editor/cell/CreateCellButton.tsx +132 -0
  285. package/src/components/editor/cell/DeleteButton.tsx +58 -0
  286. package/src/components/editor/cell/PendingDeleteConfirmation.tsx +126 -0
  287. package/src/components/editor/cell/RunButton.tsx +109 -0
  288. package/src/components/editor/cell/StopButton.tsx +36 -0
  289. package/src/components/editor/cell/TinyCode.css +10 -0
  290. package/src/components/editor/cell/TinyCode.tsx +53 -0
  291. package/src/components/editor/cell/cell-actions.tsx +185 -0
  292. package/src/components/editor/cell/cell-context-menu.tsx +243 -0
  293. package/src/components/editor/cell/cell-status.css +21 -0
  294. package/src/components/editor/cell/code/cell-editor.tsx +546 -0
  295. package/src/components/editor/cell/code/icons.tsx +31 -0
  296. package/src/components/editor/cell/code/language-toggle.tsx +140 -0
  297. package/src/components/editor/cell/collapse.tsx +100 -0
  298. package/src/components/editor/cell/toolbar.tsx +89 -0
  299. package/src/components/editor/cell/useAddCell.ts +29 -0
  300. package/src/components/editor/cell/useDeleteCell.tsx +89 -0
  301. package/src/components/editor/cell/useRunCells.ts +86 -0
  302. package/src/components/editor/cell/useShouldShowInterrupt.ts +26 -0
  303. package/src/components/editor/cell/useSplitCell.tsx +41 -0
  304. package/src/components/editor/chrome/components/contribute-snippet-button.tsx +138 -0
  305. package/src/components/editor/chrome/components/feedback-button.tsx +105 -0
  306. package/src/components/editor/chrome/panels/__tests__/write-secret-modal.test.ts +43 -0
  307. package/src/components/editor/chrome/panels/constants.ts +2 -0
  308. package/src/components/editor/chrome/panels/context-aware-panel/atoms.ts +28 -0
  309. package/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx +167 -0
  310. package/src/components/editor/chrome/panels/datasources-panel.tsx +6 -0
  311. package/src/components/editor/chrome/panels/dependency-graph-panel.tsx +23 -0
  312. package/src/components/editor/chrome/panels/documentation-panel.tsx +29 -0
  313. package/src/components/editor/chrome/panels/empty-state.tsx +28 -0
  314. package/src/components/editor/chrome/panels/error-panel.tsx +35 -0
  315. package/src/components/editor/chrome/panels/file-explorer-panel.tsx +33 -0
  316. package/src/components/editor/chrome/panels/logs-panel.tsx +97 -0
  317. package/src/components/editor/chrome/panels/outline/floating-outline.tsx +129 -0
  318. package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +172 -0
  319. package/src/components/editor/chrome/panels/outline-panel.css +6 -0
  320. package/src/components/editor/chrome/panels/outline-panel.tsx +39 -0
  321. package/src/components/editor/chrome/panels/packages-panel.tsx +635 -0
  322. package/src/components/editor/chrome/panels/packages-state.ts +5 -0
  323. package/src/components/editor/chrome/panels/scratchpad-panel.tsx +8 -0
  324. package/src/components/editor/chrome/panels/secrets-panel.tsx +155 -0
  325. package/src/components/editor/chrome/panels/snippets-panel.css +11 -0
  326. package/src/components/editor/chrome/panels/snippets-panel.tsx +230 -0
  327. package/src/components/editor/chrome/panels/tracing-panel.tsx +28 -0
  328. package/src/components/editor/chrome/panels/variable-panel.tsx +31 -0
  329. package/src/components/editor/chrome/panels/write-secret-modal.tsx +190 -0
  330. package/src/components/editor/chrome/state.ts +102 -0
  331. package/src/components/editor/chrome/types.ts +133 -0
  332. package/src/components/editor/chrome/wrapper/__tests__/minimap-state.test.ts +209 -0
  333. package/src/components/editor/chrome/wrapper/__tests__/storage.test.ts +41 -0
  334. package/src/components/editor/chrome/wrapper/app-chrome.css +22 -0
  335. package/src/components/editor/chrome/wrapper/app-chrome.tsx +256 -0
  336. package/src/components/editor/chrome/wrapper/footer-item.tsx +43 -0
  337. package/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx +47 -0
  338. package/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx +111 -0
  339. package/src/components/editor/chrome/wrapper/footer-items/copilot-status.tsx +125 -0
  340. package/src/components/editor/chrome/wrapper/footer-items/machine-stats.tsx +185 -0
  341. package/src/components/editor/chrome/wrapper/footer-items/minimap-status.tsx +21 -0
  342. package/src/components/editor/chrome/wrapper/footer-items/rtc-status.tsx +65 -0
  343. package/src/components/editor/chrome/wrapper/footer-items/runtime-settings.tsx +370 -0
  344. package/src/components/editor/chrome/wrapper/footer.tsx +90 -0
  345. package/src/components/editor/chrome/wrapper/minimap-state.ts +164 -0
  346. package/src/components/editor/chrome/wrapper/minimap.tsx +443 -0
  347. package/src/components/editor/chrome/wrapper/panels.tsx +10 -0
  348. package/src/components/editor/chrome/wrapper/sidebar.tsx +100 -0
  349. package/src/components/editor/chrome/wrapper/storage.ts +56 -0
  350. package/src/components/editor/chrome/wrapper/utils.ts +8 -0
  351. package/src/components/editor/code/readonly-python-code.tsx +160 -0
  352. package/src/components/editor/columns/__tests__/storage.test.ts +104 -0
  353. package/src/components/editor/columns/cell-column.tsx +105 -0
  354. package/src/components/editor/columns/sortable-column.tsx +175 -0
  355. package/src/components/editor/columns/storage.ts +56 -0
  356. package/src/components/editor/common.ts +20 -0
  357. package/src/components/editor/controls/Controls.tsx +225 -0
  358. package/src/components/editor/controls/command-palette-button.tsx +27 -0
  359. package/src/components/editor/controls/command-palette.tsx +210 -0
  360. package/src/components/editor/controls/keyboard-shortcuts.tsx +309 -0
  361. package/src/components/editor/controls/notebook-menu-dropdown.tsx +157 -0
  362. package/src/components/editor/controls/shutdown-button.tsx +70 -0
  363. package/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap +659 -0
  364. package/src/components/editor/database/__tests__/as-code.test.ts +598 -0
  365. package/src/components/editor/database/__tests__/secrets.test.ts +38 -0
  366. package/src/components/editor/database/add-database-form.tsx +395 -0
  367. package/src/components/editor/database/as-code.ts +786 -0
  368. package/src/components/editor/database/form-renderers.tsx +211 -0
  369. package/src/components/editor/database/schemas.ts +485 -0
  370. package/src/components/editor/database/secrets.ts +25 -0
  371. package/src/components/editor/documentation.css +139 -0
  372. package/src/components/editor/dynamic-favicon.tsx +126 -0
  373. package/src/components/editor/errors/auto-fix.tsx +61 -0
  374. package/src/components/editor/file-tree/__tests__/requesting-tree.test.ts +321 -0
  375. package/src/components/editor/file-tree/file-explorer.tsx +679 -0
  376. package/src/components/editor/file-tree/file-viewer.tsx +283 -0
  377. package/src/components/editor/file-tree/renderers.tsx +83 -0
  378. package/src/components/editor/file-tree/requesting-tree.tsx +228 -0
  379. package/src/components/editor/file-tree/state.tsx +26 -0
  380. package/src/components/editor/file-tree/types.ts +118 -0
  381. package/src/components/editor/file-tree/upload.tsx +101 -0
  382. package/src/components/editor/header/app-header.tsx +28 -0
  383. package/src/components/editor/header/filename-form.tsx +27 -0
  384. package/src/components/editor/header/filename-input.css +21 -0
  385. package/src/components/editor/header/filename-input.tsx +244 -0
  386. package/src/components/editor/header/status.tsx +72 -0
  387. package/src/components/editor/inputs/Inputs.css +118 -0
  388. package/src/components/editor/inputs/Inputs.styles.ts +66 -0
  389. package/src/components/editor/inputs/Inputs.tsx +34 -0
  390. package/src/components/editor/kiosk-mode.tsx +25 -0
  391. package/src/components/editor/links/cell-link-list.tsx +74 -0
  392. package/src/components/editor/links/cell-link.tsx +128 -0
  393. package/src/components/editor/navigation/__tests__/clipboard.test.ts +466 -0
  394. package/src/components/editor/navigation/__tests__/navigation.test.ts +1743 -0
  395. package/src/components/editor/navigation/__tests__/selection.test.ts +194 -0
  396. package/src/components/editor/navigation/clipboard.ts +205 -0
  397. package/src/components/editor/navigation/focus-utils.ts +48 -0
  398. package/src/components/editor/navigation/multi-cell-action-toolbar.tsx +499 -0
  399. package/src/components/editor/navigation/navigation.ts +698 -0
  400. package/src/components/editor/navigation/selection.ts +114 -0
  401. package/src/components/editor/navigation/state.ts +5 -0
  402. package/src/components/editor/navigation/vim-bindings.test.ts +109 -0
  403. package/src/components/editor/navigation/vim-bindings.ts +90 -0
  404. package/src/components/editor/notebook-banner.tsx +75 -0
  405. package/src/components/editor/output/CalloutOutput.styles.ts +22 -0
  406. package/src/components/editor/output/CalloutOutput.tsx +19 -0
  407. package/src/components/editor/output/ConsoleOutput.tsx +276 -0
  408. package/src/components/editor/output/EmotionCacheProvider.tsx +32 -0
  409. package/src/components/editor/output/HtmlOutput.tsx +25 -0
  410. package/src/components/editor/output/ImageOutput.tsx +25 -0
  411. package/src/components/editor/output/JsonOutput.tsx +424 -0
  412. package/src/components/editor/output/MarimoErrorOutput.tsx +511 -0
  413. package/src/components/editor/output/MarimoTracebackOutput.tsx +233 -0
  414. package/src/components/editor/output/Outputs.css +102 -0
  415. package/src/components/editor/output/TextOutput.tsx +42 -0
  416. package/src/components/editor/output/VideoOutput.tsx +11 -0
  417. package/src/components/editor/output/__tests__/ansi.test.ts +39 -0
  418. package/src/components/editor/output/__tests__/json-output.test.ts +269 -0
  419. package/src/components/editor/output/__tests__/traceback.test.tsx +105 -0
  420. package/src/components/editor/output/useWrapText.ts +14 -0
  421. package/src/components/editor/package-alert.tsx +596 -0
  422. package/src/components/editor/renderMimeIcon.tsx +38 -0
  423. package/src/components/editor/renderers/CellArray.tsx +352 -0
  424. package/src/components/editor/renderers/cells-renderer.tsx +96 -0
  425. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +650 -0
  426. package/src/components/editor/renderers/grid-layout/plugin.tsx +146 -0
  427. package/src/components/editor/renderers/grid-layout/styles.css +31 -0
  428. package/src/components/editor/renderers/grid-layout/types.ts +89 -0
  429. package/src/components/editor/renderers/layout-select.tsx +86 -0
  430. package/src/components/editor/renderers/plugins.ts +31 -0
  431. package/src/components/editor/renderers/slides-layout/plugin.tsx +31 -0
  432. package/src/components/editor/renderers/slides-layout/slides-layout.tsx +74 -0
  433. package/src/components/editor/renderers/slides-layout/types.ts +12 -0
  434. package/src/components/editor/renderers/types.ts +75 -0
  435. package/src/components/editor/renderers/vertical-layout/__tests__/useDelayVisibility.test.ts +87 -0
  436. package/src/components/editor/renderers/vertical-layout/__tests__/useFocusFirstEditor.test.ts +123 -0
  437. package/src/components/editor/renderers/vertical-layout/__tests__/vertical-layout.test.ts +173 -0
  438. package/src/components/editor/renderers/vertical-layout/sidebar/__tests__/sidebar.test.tsx +56 -0
  439. package/src/components/editor/renderers/vertical-layout/sidebar/sheet-sidebar.tsx +32 -0
  440. package/src/components/editor/renderers/vertical-layout/sidebar/sidebar-slot.tsx +10 -0
  441. package/src/components/editor/renderers/vertical-layout/sidebar/sidebar.css +20 -0
  442. package/src/components/editor/renderers/vertical-layout/sidebar/sidebar.tsx +30 -0
  443. package/src/components/editor/renderers/vertical-layout/sidebar/state.ts +46 -0
  444. package/src/components/editor/renderers/vertical-layout/sidebar/toggle.tsx +25 -0
  445. package/src/components/editor/renderers/vertical-layout/sidebar/wrapped-with-sidebar.tsx +38 -0
  446. package/src/components/editor/renderers/vertical-layout/useDelayVisibility.ts +32 -0
  447. package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +107 -0
  448. package/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx +46 -0
  449. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +451 -0
  450. package/src/components/editor/stdin-blocking-alert.tsx +83 -0
  451. package/src/components/export/export-output-button.tsx +14 -0
  452. package/src/components/find-replace/find-replace.tsx +293 -0
  453. package/src/components/forms/__tests__/form-utils.test.ts +104 -0
  454. package/src/components/forms/form-utils.ts +90 -0
  455. package/src/components/forms/form.tsx +817 -0
  456. package/src/components/forms/options.ts +59 -0
  457. package/src/components/forms/switchable-multi-select.tsx +134 -0
  458. package/src/components/home/components.tsx +189 -0
  459. package/src/components/home/state.ts +30 -0
  460. package/src/components/icons/copy-icon.tsx +59 -0
  461. package/src/components/icons/github-copilot.tsx +17 -0
  462. package/src/components/icons/large-spinner.tsx +39 -0
  463. package/src/components/icons/loading-ellipsis.tsx +46 -0
  464. package/src/components/icons/multi-icon.css +9 -0
  465. package/src/components/icons/multi-icon.tsx +30 -0
  466. package/src/components/icons/spinner.tsx +38 -0
  467. package/src/components/layout/toolbar.tsx +26 -0
  468. package/src/components/modal/ImperativeModal.tsx +187 -0
  469. package/src/components/pages/edit-page.tsx +37 -0
  470. package/src/components/pages/home-page.tsx +514 -0
  471. package/src/components/pages/run-page.tsx +55 -0
  472. package/src/components/scratchpad/scratchpad-history.ts +28 -0
  473. package/src/components/scratchpad/scratchpad.tsx +280 -0
  474. package/src/components/shortcuts/renderShortcut.tsx +208 -0
  475. package/src/components/slides/slides-component.tsx +132 -0
  476. package/src/components/slides/slides.css +100 -0
  477. package/src/components/sort/SortableCellsProvider.tsx +242 -0
  478. package/src/components/static-html/share-modal.tsx +181 -0
  479. package/src/components/static-html/static-banner.tsx +164 -0
  480. package/src/components/terminal/terminal.tsx +110 -0
  481. package/src/components/terminal/xterm.css +3 -0
  482. package/src/components/tracing/tracing-spec.ts +118 -0
  483. package/src/components/tracing/tracing.test.tsx +66 -0
  484. package/src/components/tracing/tracing.tsx +410 -0
  485. package/src/components/ui/accordion.tsx +70 -0
  486. package/src/components/ui/alert-dialog.tsx +176 -0
  487. package/src/components/ui/alert.tsx +64 -0
  488. package/src/components/ui/aria-popover.tsx +43 -0
  489. package/src/components/ui/badge.tsx +41 -0
  490. package/src/components/ui/button.tsx +156 -0
  491. package/src/components/ui/calendar.tsx +231 -0
  492. package/src/components/ui/card.tsx +83 -0
  493. package/src/components/ui/checkbox.tsx +33 -0
  494. package/src/components/ui/combobox.tsx +278 -0
  495. package/src/components/ui/command.tsx +165 -0
  496. package/src/components/ui/context-menu.tsx +193 -0
  497. package/src/components/ui/date-input.tsx +127 -0
  498. package/src/components/ui/date-picker.tsx +188 -0
  499. package/src/components/ui/dialog.tsx +155 -0
  500. package/src/components/ui/draggable-popover.tsx +68 -0
  501. package/src/components/ui/dropdown-menu.tsx +189 -0
  502. package/src/components/ui/field.tsx +90 -0
  503. package/src/components/ui/form.tsx +224 -0
  504. package/src/components/ui/fullscreen.tsx +38 -0
  505. package/src/components/ui/input.tsx +208 -0
  506. package/src/components/ui/kbd.tsx +22 -0
  507. package/src/components/ui/label.tsx +26 -0
  508. package/src/components/ui/links.tsx +23 -0
  509. package/src/components/ui/menu-items.tsx +101 -0
  510. package/src/components/ui/native-select.tsx +39 -0
  511. package/src/components/ui/navigation.tsx +154 -0
  512. package/src/components/ui/number-field.tsx +99 -0
  513. package/src/components/ui/popover.tsx +63 -0
  514. package/src/components/ui/progress.tsx +28 -0
  515. package/src/components/ui/radio-group.tsx +44 -0
  516. package/src/components/ui/range-slider.tsx +102 -0
  517. package/src/components/ui/scroll-area.tsx +47 -0
  518. package/src/components/ui/select.tsx +167 -0
  519. package/src/components/ui/sheet.tsx +143 -0
  520. package/src/components/ui/skeleton.tsx +16 -0
  521. package/src/components/ui/slider.tsx +80 -0
  522. package/src/components/ui/switch.tsx +54 -0
  523. package/src/components/ui/table.tsx +122 -0
  524. package/src/components/ui/tabs.tsx +55 -0
  525. package/src/components/ui/textarea.tsx +104 -0
  526. package/src/components/ui/toast.tsx +133 -0
  527. package/src/components/ui/toaster.tsx +30 -0
  528. package/src/components/ui/toggle.tsx +49 -0
  529. package/src/components/ui/tooltip.tsx +87 -0
  530. package/src/components/ui/typography.tsx +207 -0
  531. package/src/components/ui/use-restore-focus.ts +28 -0
  532. package/src/components/ui/use-toast.ts +224 -0
  533. package/src/components/utils/delay-mount.tsx +81 -0
  534. package/src/components/utils/lazy-mount.tsx +24 -0
  535. package/src/components/variables/common.tsx +37 -0
  536. package/src/components/variables/variables-table.tsx +335 -0
  537. package/src/core/MarimoApp.tsx +103 -0
  538. package/src/core/ai/__tests__/model-registry.test.ts +357 -0
  539. package/src/core/ai/chat-utils.ts +71 -0
  540. package/src/core/ai/config.ts +76 -0
  541. package/src/core/ai/context/__tests__/registry.test.ts +516 -0
  542. package/src/core/ai/context/context.ts +16 -0
  543. package/src/core/ai/context/providers/__tests__/__snapshots__/tables.test.ts.snap +291 -0
  544. package/src/core/ai/context/providers/__tests__/__snapshots__/variable.test.ts.snap +378 -0
  545. package/src/core/ai/context/providers/__tests__/tables.test.ts +271 -0
  546. package/src/core/ai/context/providers/__tests__/variable.test.ts +312 -0
  547. package/src/core/ai/context/providers/common.ts +7 -0
  548. package/src/core/ai/context/providers/tables.ts +208 -0
  549. package/src/core/ai/context/providers/variable.ts +72 -0
  550. package/src/core/ai/context/registry.ts +180 -0
  551. package/src/core/ai/ids/__tests__/ids.test.ts +193 -0
  552. package/src/core/ai/ids/ids.ts +70 -0
  553. package/src/core/ai/model-registry.ts +164 -0
  554. package/src/core/ai/state.ts +58 -0
  555. package/src/core/alerts/state.ts +75 -0
  556. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +1312 -0
  557. package/src/core/cells/__tests__/add-missing-import.test.ts +78 -0
  558. package/src/core/cells/__tests__/cell.test.ts +193 -0
  559. package/src/core/cells/__tests__/cells.test.ts +2664 -0
  560. package/src/core/cells/__tests__/collapseConsoleOutputs.test.ts +239 -0
  561. package/src/core/cells/__tests__/focus.test.ts +271 -0
  562. package/src/core/cells/__tests__/ids.test.ts +90 -0
  563. package/src/core/cells/__tests__/names.test.ts +62 -0
  564. package/src/core/cells/__tests__/pending-delete-service.test.tsx +202 -0
  565. package/src/core/cells/__tests__/runs.test.ts +453 -0
  566. package/src/core/cells/__tests__/session.test.ts +757 -0
  567. package/src/core/cells/__tests__/utils.test.ts +428 -0
  568. package/src/core/cells/actions.ts +21 -0
  569. package/src/core/cells/add-missing-import.ts +114 -0
  570. package/src/core/cells/cell.ts +243 -0
  571. package/src/core/cells/cells.ts +1751 -0
  572. package/src/core/cells/collapseConsoleOutputs.tsx +133 -0
  573. package/src/core/cells/effects.ts +42 -0
  574. package/src/core/cells/focus.ts +128 -0
  575. package/src/core/cells/ids.ts +124 -0
  576. package/src/core/cells/logs.ts +114 -0
  577. package/src/core/cells/names.ts +107 -0
  578. package/src/core/cells/outline.ts +30 -0
  579. package/src/core/cells/outputs.ts +34 -0
  580. package/src/core/cells/pending-delete-service.ts +183 -0
  581. package/src/core/cells/runs.ts +196 -0
  582. package/src/core/cells/scrollCellIntoView.ts +133 -0
  583. package/src/core/cells/session.ts +281 -0
  584. package/src/core/cells/types.ts +128 -0
  585. package/src/core/cells/utils.ts +141 -0
  586. package/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap +216 -0
  587. package/src/core/codemirror/__tests__/extensions.test.ts +117 -0
  588. package/src/core/codemirror/__tests__/format.test.ts +227 -0
  589. package/src/core/codemirror/__tests__/setup.test.ts +178 -0
  590. package/src/core/codemirror/ai/request.ts +72 -0
  591. package/src/core/codemirror/ai/resources.ts +90 -0
  592. package/src/core/codemirror/cells/extensions.ts +387 -0
  593. package/src/core/codemirror/cells/state.ts +32 -0
  594. package/src/core/codemirror/cells/traceback-decorations.ts +111 -0
  595. package/src/core/codemirror/cm.ts +267 -0
  596. package/src/core/codemirror/compat/__tests__/jupyter.test.ts +136 -0
  597. package/src/core/codemirror/compat/jupyter.tsx +244 -0
  598. package/src/core/codemirror/completion/Autocompleter.ts +172 -0
  599. package/src/core/codemirror/completion/__tests__/hints.test.ts +84 -0
  600. package/src/core/codemirror/completion/__tests__/keymap.test.ts +44 -0
  601. package/src/core/codemirror/completion/completer.ts +58 -0
  602. package/src/core/codemirror/completion/hints.ts +143 -0
  603. package/src/core/codemirror/completion/keymap.ts +70 -0
  604. package/src/core/codemirror/completion/utils.ts +18 -0
  605. package/src/core/codemirror/completion/variable-completions.ts +100 -0
  606. package/src/core/codemirror/config/extension.ts +63 -0
  607. package/src/core/codemirror/config/types.ts +10 -0
  608. package/src/core/codemirror/copilot/__tests__/copilot.test.ts +260 -0
  609. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +209 -0
  610. package/src/core/codemirror/copilot/__tests__/trim-utils.test.ts +291 -0
  611. package/src/core/codemirror/copilot/client.ts +123 -0
  612. package/src/core/codemirror/copilot/copilot-config.tsx +285 -0
  613. package/src/core/codemirror/copilot/extension.ts +285 -0
  614. package/src/core/codemirror/copilot/getCodes.ts +130 -0
  615. package/src/core/codemirror/copilot/language-server.ts +255 -0
  616. package/src/core/codemirror/copilot/state.ts +66 -0
  617. package/src/core/codemirror/copilot/trim-utils.ts +33 -0
  618. package/src/core/codemirror/copilot/types.ts +41 -0
  619. package/src/core/codemirror/editing/__tests__/commands.test.ts +106 -0
  620. package/src/core/codemirror/editing/__tests__/debugging.test.ts +193 -0
  621. package/src/core/codemirror/editing/commands.ts +25 -0
  622. package/src/core/codemirror/editing/debugging.ts +58 -0
  623. package/src/core/codemirror/editing/extensions.ts +4 -0
  624. package/src/core/codemirror/extensions.ts +95 -0
  625. package/src/core/codemirror/facet.ts +19 -0
  626. package/src/core/codemirror/find-replace/__tests__/navigate.test.ts +695 -0
  627. package/src/core/codemirror/find-replace/extension.ts +41 -0
  628. package/src/core/codemirror/find-replace/navigate.ts +221 -0
  629. package/src/core/codemirror/find-replace/query.ts +31 -0
  630. package/src/core/codemirror/find-replace/search-highlight.ts +148 -0
  631. package/src/core/codemirror/find-replace/state.ts +167 -0
  632. package/src/core/codemirror/format.ts +120 -0
  633. package/src/core/codemirror/go-to-definition/__tests__/commands.test.ts +205 -0
  634. package/src/core/codemirror/go-to-definition/commands.ts +80 -0
  635. package/src/core/codemirror/go-to-definition/extension.ts +23 -0
  636. package/src/core/codemirror/go-to-definition/underline.ts +223 -0
  637. package/src/core/codemirror/go-to-definition/utils.ts +126 -0
  638. package/src/core/codemirror/keymaps/__tests__/keymaps.test.ts +43 -0
  639. package/src/core/codemirror/keymaps/__tests__/vimrc.test.ts +121 -0
  640. package/src/core/codemirror/keymaps/keymaps.ts +163 -0
  641. package/src/core/codemirror/keymaps/vim.ts +348 -0
  642. package/src/core/codemirror/keymaps/vimrc.ts +149 -0
  643. package/src/core/codemirror/language/LanguageAdapters.ts +23 -0
  644. package/src/core/codemirror/language/__tests__/ast.test.ts +124 -0
  645. package/src/core/codemirror/language/__tests__/extension.test.ts +260 -0
  646. package/src/core/codemirror/language/__tests__/indentOneTab.test.ts +31 -0
  647. package/src/core/codemirror/language/__tests__/markdown.test.ts +495 -0
  648. package/src/core/codemirror/language/__tests__/sql.test.ts +1640 -0
  649. package/src/core/codemirror/language/__tests__/utils.test.ts +166 -0
  650. package/src/core/codemirror/language/commands.ts +59 -0
  651. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +163 -0
  652. package/src/core/codemirror/language/embedded/embedded-python.ts +131 -0
  653. package/src/core/codemirror/language/embedded/latex.ts +257 -0
  654. package/src/core/codemirror/language/extension.ts +322 -0
  655. package/src/core/codemirror/language/languages/markdown.ts +261 -0
  656. package/src/core/codemirror/language/languages/python.ts +329 -0
  657. package/src/core/codemirror/language/languages/sql/completion-sources.tsx +99 -0
  658. package/src/core/codemirror/language/languages/sql/completion-store.ts +191 -0
  659. package/src/core/codemirror/language/languages/sql/sql.ts +545 -0
  660. package/src/core/codemirror/language/languages/sql/utils.ts +42 -0
  661. package/src/core/codemirror/language/metadata.ts +71 -0
  662. package/src/core/codemirror/language/panel/markdown.tsx +63 -0
  663. package/src/core/codemirror/language/panel/panel.tsx +197 -0
  664. package/src/core/codemirror/language/panel/sql.tsx +132 -0
  665. package/src/core/codemirror/language/types.ts +41 -0
  666. package/src/core/codemirror/language/utils/ast.ts +84 -0
  667. package/src/core/codemirror/language/utils/indentOneTab.ts +9 -0
  668. package/src/core/codemirror/language/utils/quotes.ts +18 -0
  669. package/src/core/codemirror/language/utils.ts +78 -0
  670. package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +860 -0
  671. package/src/core/codemirror/lsp/federated-lsp.ts +235 -0
  672. package/src/core/codemirror/lsp/lens.ts +130 -0
  673. package/src/core/codemirror/lsp/notebook-lsp.ts +604 -0
  674. package/src/core/codemirror/lsp/transports.ts +31 -0
  675. package/src/core/codemirror/lsp/types.ts +55 -0
  676. package/src/core/codemirror/lsp/utils.ts +11 -0
  677. package/src/core/codemirror/markdown/__tests__/commands.test.ts +522 -0
  678. package/src/core/codemirror/markdown/commands.ts +478 -0
  679. package/src/core/codemirror/markdown/completions.ts +273 -0
  680. package/src/core/codemirror/markdown/extension.ts +106 -0
  681. package/src/core/codemirror/misc/__tests__/dnd.test.ts +111 -0
  682. package/src/core/codemirror/misc/__tests__/paste.test.ts +239 -0
  683. package/src/core/codemirror/misc/dnd.ts +48 -0
  684. package/src/core/codemirror/misc/paste.ts +181 -0
  685. package/src/core/codemirror/placeholder/__tests__/extensions.test.ts +132 -0
  686. package/src/core/codemirror/placeholder/extensions.ts +99 -0
  687. package/src/core/codemirror/react-dom/createPanel.tsx +39 -0
  688. package/src/core/codemirror/reactive-references/__tests__/analyzer.test.ts +1222 -0
  689. package/src/core/codemirror/reactive-references/analyzer.ts +608 -0
  690. package/src/core/codemirror/reactive-references/extension.ts +154 -0
  691. package/src/core/codemirror/readonly/__tests__/extension.test.ts +55 -0
  692. package/src/core/codemirror/readonly/extension.ts +187 -0
  693. package/src/core/codemirror/rtc/extension.ts +450 -0
  694. package/src/core/codemirror/rtc/loro/awareness.ts +496 -0
  695. package/src/core/codemirror/rtc/loro/colors.ts +38 -0
  696. package/src/core/codemirror/rtc/loro/sync.ts +159 -0
  697. package/src/core/codemirror/theme/__tests__/light.test.ts +136 -0
  698. package/src/core/codemirror/theme/dark.ts +50 -0
  699. package/src/core/codemirror/theme/light.ts +58 -0
  700. package/src/core/codemirror/types.ts +5 -0
  701. package/src/core/codemirror/utils.ts +103 -0
  702. package/src/core/codemirror/vim/cursor-visibility.ts +58 -0
  703. package/src/core/config/__tests__/config-schema.test.ts +232 -0
  704. package/src/core/config/capabilities.ts +15 -0
  705. package/src/core/config/config-schema.ts +296 -0
  706. package/src/core/config/config.ts +109 -0
  707. package/src/core/config/feature-flag.tsx +62 -0
  708. package/src/core/config/if-capability.tsx +19 -0
  709. package/src/core/config/widths.ts +5 -0
  710. package/src/core/constants.ts +52 -0
  711. package/src/core/datasets/__tests__/all-tables.test.ts +466 -0
  712. package/src/core/datasets/__tests__/data-source.test.ts +461 -0
  713. package/src/core/datasets/data-source-connections.ts +334 -0
  714. package/src/core/datasets/engines.ts +10 -0
  715. package/src/core/datasets/request-registry.ts +34 -0
  716. package/src/core/datasets/state.ts +143 -0
  717. package/src/core/datasets/types.ts +38 -0
  718. package/src/core/debugger/state.ts +10 -0
  719. package/src/core/documentation/state.ts +13 -0
  720. package/src/core/dom/__tests__/htmlUtils.test.ts +22 -0
  721. package/src/core/dom/__tests__/outline.test.ts +370 -0
  722. package/src/core/dom/defineCustomElement.ts +23 -0
  723. package/src/core/dom/events.ts +94 -0
  724. package/src/core/dom/htmlUtils.ts +75 -0
  725. package/src/core/dom/outline.ts +123 -0
  726. package/src/core/dom/ui-element.css +8 -0
  727. package/src/core/dom/ui-element.ts +249 -0
  728. package/src/core/dom/uiregistry.ts +209 -0
  729. package/src/core/edit-app.tsx +189 -0
  730. package/src/core/errors/__tests__/errors.test.ts +62 -0
  731. package/src/core/errors/__tests__/utils.test.ts +108 -0
  732. package/src/core/errors/errors.ts +96 -0
  733. package/src/core/errors/state.ts +44 -0
  734. package/src/core/errors/utils.ts +67 -0
  735. package/src/core/export/hooks.ts +60 -0
  736. package/src/core/functions/FunctionRegistry.ts +18 -0
  737. package/src/core/hotkeys/__tests__/shortcuts.test.ts +166 -0
  738. package/src/core/hotkeys/actions.ts +38 -0
  739. package/src/core/hotkeys/hotkeys.ts +503 -0
  740. package/src/core/hotkeys/shortcuts.ts +117 -0
  741. package/src/core/islands/__tests__/parse.test.ts +89 -0
  742. package/src/core/islands/bridge.ts +196 -0
  743. package/src/core/islands/components/output-wrapper.tsx +154 -0
  744. package/src/core/islands/components/web-components.tsx +120 -0
  745. package/src/core/islands/islands.css +14 -0
  746. package/src/core/islands/main.ts +200 -0
  747. package/src/core/islands/parse.ts +161 -0
  748. package/src/core/islands/state.ts +30 -0
  749. package/src/core/islands/toast.ts +41 -0
  750. package/src/core/islands/utils.ts +5 -0
  751. package/src/core/islands/worker/controller.ts +52 -0
  752. package/src/core/islands/worker/worker.tsx +178 -0
  753. package/src/core/kernel/RuntimeState.ts +94 -0
  754. package/src/core/kernel/__tests__/RuntimeState.test.ts +57 -0
  755. package/src/core/kernel/__tests__/handlers.test.ts +61 -0
  756. package/src/core/kernel/__tests__/session.test.ts +10 -0
  757. package/src/core/kernel/handlers.ts +159 -0
  758. package/src/core/kernel/messages.ts +54 -0
  759. package/src/core/kernel/queryParamHandlers.ts +39 -0
  760. package/src/core/kernel/session.ts +50 -0
  761. package/src/core/layout/layout.ts +99 -0
  762. package/src/core/layout/useTogglePresenting.ts +50 -0
  763. package/src/core/meta/globals.ts +25 -0
  764. package/src/core/meta/state.ts +25 -0
  765. package/src/core/mime.ts +9 -0
  766. package/src/core/mode.ts +80 -0
  767. package/src/core/network/DeferredRequestRegistry.ts +71 -0
  768. package/src/core/network/__tests__/DeferredRequestRegistry.test.ts +37 -0
  769. package/src/core/network/__tests__/api.test.ts +80 -0
  770. package/src/core/network/api.ts +145 -0
  771. package/src/core/network/auth.ts +13 -0
  772. package/src/core/network/connection.ts +33 -0
  773. package/src/core/network/requests-network.ts +398 -0
  774. package/src/core/network/requests-static.ts +88 -0
  775. package/src/core/network/requests-toasting.ts +91 -0
  776. package/src/core/network/requests.ts +24 -0
  777. package/src/core/network/resolve.ts +17 -0
  778. package/src/core/network/types.ts +188 -0
  779. package/src/core/packages/toast-components.tsx +88 -0
  780. package/src/core/packages/useInstallPackage.ts +46 -0
  781. package/src/core/rtc/state.ts +20 -0
  782. package/src/core/run-app.tsx +69 -0
  783. package/src/core/runtime/__tests__/config.test.ts +173 -0
  784. package/src/core/runtime/__tests__/createWsUrl.test.ts +61 -0
  785. package/src/core/runtime/__tests__/runtime.test.ts +603 -0
  786. package/src/core/runtime/config.ts +45 -0
  787. package/src/core/runtime/runtime.ts +277 -0
  788. package/src/core/runtime/types.ts +7 -0
  789. package/src/core/runtime/utils.ts +9 -0
  790. package/src/core/saving/file-state.ts +15 -0
  791. package/src/core/saving/filename.ts +55 -0
  792. package/src/core/saving/save-component.tsx +274 -0
  793. package/src/core/saving/state.ts +51 -0
  794. package/src/core/saving/useAutoSave.ts +68 -0
  795. package/src/core/secrets/request-registry.ts +16 -0
  796. package/src/core/slots/slots.ts +9 -0
  797. package/src/core/state/__tests__/jotai.test.ts +25 -0
  798. package/src/core/state/jotai.ts +69 -0
  799. package/src/core/state/observable.ts +23 -0
  800. package/src/core/static/__tests__/download-html.test.ts +41 -0
  801. package/src/core/static/__tests__/files.test.ts +494 -0
  802. package/src/core/static/__tests__/virtual-file-tracker.test.ts +92 -0
  803. package/src/core/static/download-html.ts +59 -0
  804. package/src/core/static/files.ts +150 -0
  805. package/src/core/static/static-state.ts +19 -0
  806. package/src/core/static/types.ts +8 -0
  807. package/src/core/static/virtual-file-tracker.ts +83 -0
  808. package/src/core/variables/__tests__/state.test.ts +148 -0
  809. package/src/core/variables/state.ts +81 -0
  810. package/src/core/variables/types.ts +22 -0
  811. package/src/core/vscode/vscode-bindings.ts +176 -0
  812. package/src/core/wasm/PyodideLoader.tsx +72 -0
  813. package/src/core/wasm/__tests__/router.test.ts +57 -0
  814. package/src/core/wasm/__tests__/share.test.ts +35 -0
  815. package/src/core/wasm/__tests__/state.test.ts +124 -0
  816. package/src/core/wasm/__tests__/store.test.ts +55 -0
  817. package/src/core/wasm/bridge.ts +622 -0
  818. package/src/core/wasm/router.ts +39 -0
  819. package/src/core/wasm/rpc.ts +32 -0
  820. package/src/core/wasm/share.ts +15 -0
  821. package/src/core/wasm/state.ts +21 -0
  822. package/src/core/wasm/store.ts +122 -0
  823. package/src/core/wasm/utils.ts +12 -0
  824. package/src/core/wasm/worker/bootstrap.ts +223 -0
  825. package/src/core/wasm/worker/constants.ts +2 -0
  826. package/src/core/wasm/worker/fs.ts +90 -0
  827. package/src/core/wasm/worker/getController.ts +16 -0
  828. package/src/core/wasm/worker/getFS.ts +9 -0
  829. package/src/core/wasm/worker/getMarimoWheel.ts +15 -0
  830. package/src/core/wasm/worker/getPyodideVersion.ts +10 -0
  831. package/src/core/wasm/worker/message-buffer.ts +32 -0
  832. package/src/core/wasm/worker/save-worker.ts +107 -0
  833. package/src/core/wasm/worker/tracer.ts +7 -0
  834. package/src/core/wasm/worker/types.ts +97 -0
  835. package/src/core/wasm/worker/worker.ts +375 -0
  836. package/src/core/websocket/StaticWebsocket.ts +61 -0
  837. package/src/core/websocket/connection-utils.ts +59 -0
  838. package/src/core/websocket/types.ts +43 -0
  839. package/src/core/websocket/useMarimoWebSocket.tsx +386 -0
  840. package/src/core/websocket/useWebSocket.tsx +88 -0
  841. package/src/css/admonition.css +127 -0
  842. package/src/css/app/App.css +77 -0
  843. package/src/css/app/Cell.css +433 -0
  844. package/src/css/app/Header.css +25 -0
  845. package/src/css/app/codemirror-completions.css +308 -0
  846. package/src/css/app/codemirror.css +136 -0
  847. package/src/css/app/fonts.css +50 -0
  848. package/src/css/app/print.css +86 -0
  849. package/src/css/app/reset.css +18 -0
  850. package/src/css/codehilite.css +354 -0
  851. package/src/css/common.css +45 -0
  852. package/src/css/globals.css +176 -0
  853. package/src/css/index.css +10 -0
  854. package/src/css/katex-fonts.css +214 -0
  855. package/src/css/katex.min.css +1182 -0
  856. package/src/css/md-tooltip.css +52 -0
  857. package/src/css/md.css +365 -0
  858. package/src/css/progress.css +93 -0
  859. package/src/css/table.css +45 -0
  860. package/src/custom.d.ts +24 -0
  861. package/src/fonts/Fira_Mono/FiraMono-Bold.ttf +0 -0
  862. package/src/fonts/Fira_Mono/FiraMono-Medium.ttf +0 -0
  863. package/src/fonts/Fira_Mono/FiraMono-Regular.ttf +0 -0
  864. package/src/fonts/KaTeX/KaTeX_AMS-Regular.ttf +0 -0
  865. package/src/fonts/KaTeX/KaTeX_AMS-Regular.woff +0 -0
  866. package/src/fonts/KaTeX/KaTeX_AMS-Regular.woff2 +0 -0
  867. package/src/fonts/KaTeX/KaTeX_Caligraphic-Bold.ttf +0 -0
  868. package/src/fonts/KaTeX/KaTeX_Caligraphic-Bold.woff +0 -0
  869. package/src/fonts/KaTeX/KaTeX_Caligraphic-Bold.woff2 +0 -0
  870. package/src/fonts/KaTeX/KaTeX_Caligraphic-Regular.ttf +0 -0
  871. package/src/fonts/KaTeX/KaTeX_Caligraphic-Regular.woff +0 -0
  872. package/src/fonts/KaTeX/KaTeX_Caligraphic-Regular.woff2 +0 -0
  873. package/src/fonts/KaTeX/KaTeX_Fraktur-Bold.ttf +0 -0
  874. package/src/fonts/KaTeX/KaTeX_Fraktur-Bold.woff +0 -0
  875. package/src/fonts/KaTeX/KaTeX_Fraktur-Bold.woff2 +0 -0
  876. package/src/fonts/KaTeX/KaTeX_Fraktur-Regular.ttf +0 -0
  877. package/src/fonts/KaTeX/KaTeX_Fraktur-Regular.woff +0 -0
  878. package/src/fonts/KaTeX/KaTeX_Fraktur-Regular.woff2 +0 -0
  879. package/src/fonts/KaTeX/KaTeX_Main-Bold.ttf +0 -0
  880. package/src/fonts/KaTeX/KaTeX_Main-Bold.woff +0 -0
  881. package/src/fonts/KaTeX/KaTeX_Main-Bold.woff2 +0 -0
  882. package/src/fonts/KaTeX/KaTeX_Main-BoldItalic.ttf +0 -0
  883. package/src/fonts/KaTeX/KaTeX_Main-BoldItalic.woff +0 -0
  884. package/src/fonts/KaTeX/KaTeX_Main-BoldItalic.woff2 +0 -0
  885. package/src/fonts/KaTeX/KaTeX_Main-Italic.ttf +0 -0
  886. package/src/fonts/KaTeX/KaTeX_Main-Italic.woff +0 -0
  887. package/src/fonts/KaTeX/KaTeX_Main-Italic.woff2 +0 -0
  888. package/src/fonts/KaTeX/KaTeX_Main-Regular.ttf +0 -0
  889. package/src/fonts/KaTeX/KaTeX_Main-Regular.woff +0 -0
  890. package/src/fonts/KaTeX/KaTeX_Main-Regular.woff2 +0 -0
  891. package/src/fonts/KaTeX/KaTeX_Math-BoldItalic.ttf +0 -0
  892. package/src/fonts/KaTeX/KaTeX_Math-BoldItalic.woff +0 -0
  893. package/src/fonts/KaTeX/KaTeX_Math-BoldItalic.woff2 +0 -0
  894. package/src/fonts/KaTeX/KaTeX_Math-Italic.ttf +0 -0
  895. package/src/fonts/KaTeX/KaTeX_Math-Italic.woff +0 -0
  896. package/src/fonts/KaTeX/KaTeX_Math-Italic.woff2 +0 -0
  897. package/src/fonts/KaTeX/KaTeX_SansSerif-Bold.ttf +0 -0
  898. package/src/fonts/KaTeX/KaTeX_SansSerif-Bold.woff +0 -0
  899. package/src/fonts/KaTeX/KaTeX_SansSerif-Bold.woff2 +0 -0
  900. package/src/fonts/KaTeX/KaTeX_SansSerif-Italic.ttf +0 -0
  901. package/src/fonts/KaTeX/KaTeX_SansSerif-Italic.woff +0 -0
  902. package/src/fonts/KaTeX/KaTeX_SansSerif-Italic.woff2 +0 -0
  903. package/src/fonts/KaTeX/KaTeX_SansSerif-Regular.ttf +0 -0
  904. package/src/fonts/KaTeX/KaTeX_SansSerif-Regular.woff +0 -0
  905. package/src/fonts/KaTeX/KaTeX_SansSerif-Regular.woff2 +0 -0
  906. package/src/fonts/KaTeX/KaTeX_Script-Regular.ttf +0 -0
  907. package/src/fonts/KaTeX/KaTeX_Script-Regular.woff +0 -0
  908. package/src/fonts/KaTeX/KaTeX_Script-Regular.woff2 +0 -0
  909. package/src/fonts/KaTeX/KaTeX_Size1-Regular.ttf +0 -0
  910. package/src/fonts/KaTeX/KaTeX_Size1-Regular.woff +0 -0
  911. package/src/fonts/KaTeX/KaTeX_Size1-Regular.woff2 +0 -0
  912. package/src/fonts/KaTeX/KaTeX_Size2-Regular.ttf +0 -0
  913. package/src/fonts/KaTeX/KaTeX_Size2-Regular.woff +0 -0
  914. package/src/fonts/KaTeX/KaTeX_Size2-Regular.woff2 +0 -0
  915. package/src/fonts/KaTeX/KaTeX_Size3-Regular.ttf +0 -0
  916. package/src/fonts/KaTeX/KaTeX_Size3-Regular.woff +0 -0
  917. package/src/fonts/KaTeX/KaTeX_Size3-Regular.woff2 +0 -0
  918. package/src/fonts/KaTeX/KaTeX_Size4-Regular.ttf +0 -0
  919. package/src/fonts/KaTeX/KaTeX_Size4-Regular.woff +0 -0
  920. package/src/fonts/KaTeX/KaTeX_Size4-Regular.woff2 +0 -0
  921. package/src/fonts/KaTeX/KaTeX_Typewriter-Regular.ttf +0 -0
  922. package/src/fonts/KaTeX/KaTeX_Typewriter-Regular.woff +0 -0
  923. package/src/fonts/KaTeX/KaTeX_Typewriter-Regular.woff2 +0 -0
  924. package/src/fonts/Lora/Lora-Italic-VariableFont_wght.ttf +0 -0
  925. package/src/fonts/Lora/Lora-VariableFont_wght.ttf +0 -0
  926. package/src/fonts/Lora/static/Lora-Bold.ttf +0 -0
  927. package/src/fonts/Lora/static/Lora-BoldItalic.ttf +0 -0
  928. package/src/fonts/Lora/static/Lora-Italic.ttf +0 -0
  929. package/src/fonts/Lora/static/Lora-Medium.ttf +0 -0
  930. package/src/fonts/Lora/static/Lora-MediumItalic.ttf +0 -0
  931. package/src/fonts/Lora/static/Lora-Regular.ttf +0 -0
  932. package/src/fonts/Lora/static/Lora-SemiBold.ttf +0 -0
  933. package/src/fonts/Lora/static/Lora-SemiBoldItalic.ttf +0 -0
  934. package/src/fonts/PT_Sans/PTSans-Bold.ttf +0 -0
  935. package/src/fonts/PT_Sans/PTSans-BoldItalic.ttf +0 -0
  936. package/src/fonts/PT_Sans/PTSans-Italic.ttf +0 -0
  937. package/src/fonts/PT_Sans/PTSans-Regular.ttf +0 -0
  938. package/src/hooks/__tests__/useBoolean.test.tsx +33 -0
  939. package/src/hooks/__tests__/useDebounce.test.tsx +182 -0
  940. package/src/hooks/__tests__/useEffectSkipFirstRender.test.tsx +42 -0
  941. package/src/hooks/__tests__/useEventListener.test.tsx +148 -0
  942. package/src/hooks/__tests__/useInternalStateWithSync.test.tsx +76 -0
  943. package/src/hooks/__tests__/useInterval.test.tsx +70 -0
  944. package/src/hooks/__tests__/usePackageMetadata.test.tsx +219 -0
  945. package/src/hooks/__tests__/useResizeHandle.test.tsx +240 -0
  946. package/src/hooks/__tests__/useResizeObserver.test.tsx +86 -0
  947. package/src/hooks/__tests__/useTimer.test.tsx +62 -0
  948. package/src/hooks/debug.ts +116 -0
  949. package/src/hooks/useAsyncData.ts +392 -0
  950. package/src/hooks/useAudioRecorder.ts +89 -0
  951. package/src/hooks/useAutoGrowInputProps.ts +56 -0
  952. package/src/hooks/useBoolean.ts +26 -0
  953. package/src/hooks/useCellRenderCount.ts +15 -0
  954. package/src/hooks/useDebounce.ts +95 -0
  955. package/src/hooks/useDeepCompareMemoize.ts +22 -0
  956. package/src/hooks/useEffectSkipFirstRender.ts +24 -0
  957. package/src/hooks/useElapsedTime.ts +25 -0
  958. package/src/hooks/useEvent.ts +2 -0
  959. package/src/hooks/useEventListener.ts +68 -0
  960. package/src/hooks/useHotkey.ts +77 -0
  961. package/src/hooks/useInternalStateWithSync.ts +26 -0
  962. package/src/hooks/useInterval.ts +49 -0
  963. package/src/hooks/useIsDragging.tsx +39 -0
  964. package/src/hooks/useLifecycle.ts +20 -0
  965. package/src/hooks/useLocalStorage.ts +22 -0
  966. package/src/hooks/useNonce.ts +9 -0
  967. package/src/hooks/usePackageMetadata.ts +52 -0
  968. package/src/hooks/useRecentCommands.ts +25 -0
  969. package/src/hooks/useResizeHandle.ts +110 -0
  970. package/src/hooks/useResizeObserver.ts +101 -0
  971. package/src/hooks/useScript.ts +90 -0
  972. package/src/hooks/useSelectAllContent.ts +42 -0
  973. package/src/hooks/useTimer.ts +48 -0
  974. package/src/main.tsx +20 -0
  975. package/src/mount.tsx +331 -0
  976. package/src/plugins/core/BadPlugin.tsx +72 -0
  977. package/src/plugins/core/RenderHTML.tsx +136 -0
  978. package/src/plugins/core/__test__/RenderHTML.test.ts +146 -0
  979. package/src/plugins/core/builder.ts +59 -0
  980. package/src/plugins/core/registerReactComponent.tsx +535 -0
  981. package/src/plugins/core/rpc.ts +55 -0
  982. package/src/plugins/core/sidebar-element.tsx +104 -0
  983. package/src/plugins/impl/ButtonPlugin.tsx +95 -0
  984. package/src/plugins/impl/CheckboxPlugin.tsx +56 -0
  985. package/src/plugins/impl/CodeEditorPlugin.tsx +119 -0
  986. package/src/plugins/impl/DataEditorPlugin.tsx +181 -0
  987. package/src/plugins/impl/DataTablePlugin.tsx +948 -0
  988. package/src/plugins/impl/DatePickerPlugin.tsx +74 -0
  989. package/src/plugins/impl/DateRangePlugin.tsx +82 -0
  990. package/src/plugins/impl/DateTimePickerPlugin.tsx +76 -0
  991. package/src/plugins/impl/DictPlugin.tsx +80 -0
  992. package/src/plugins/impl/DropdownPlugin.tsx +102 -0
  993. package/src/plugins/impl/FileBrowserPlugin.tsx +500 -0
  994. package/src/plugins/impl/FileUploadPlugin.tsx +302 -0
  995. package/src/plugins/impl/FormPlugin.tsx +294 -0
  996. package/src/plugins/impl/MicrophonePlugin.tsx +58 -0
  997. package/src/plugins/impl/MultiselectPlugin.tsx +207 -0
  998. package/src/plugins/impl/NumberPlugin.tsx +84 -0
  999. package/src/plugins/impl/RadioPlugin.tsx +77 -0
  1000. package/src/plugins/impl/RangeSliderPlugin.tsx +163 -0
  1001. package/src/plugins/impl/RefreshPlugin.tsx +158 -0
  1002. package/src/plugins/impl/SearchableSelect.tsx +122 -0
  1003. package/src/plugins/impl/SliderPlugin.tsx +166 -0
  1004. package/src/plugins/impl/SwitchPlugin.tsx +48 -0
  1005. package/src/plugins/impl/TabsPlugin.tsx +83 -0
  1006. package/src/plugins/impl/TextAreaPlugin.tsx +131 -0
  1007. package/src/plugins/impl/TextInputPlugin.tsx +169 -0
  1008. package/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx +45 -0
  1009. package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +178 -0
  1010. package/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts +41 -0
  1011. package/src/plugins/impl/__tests__/NumberPlugin.test.tsx +144 -0
  1012. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +269 -0
  1013. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +181 -0
  1014. package/src/plugins/impl/anywidget/__tests__/model.test.ts +370 -0
  1015. package/src/plugins/impl/anywidget/model.ts +314 -0
  1016. package/src/plugins/impl/chat/ChatPlugin.tsx +98 -0
  1017. package/src/plugins/impl/chat/chat-ui.tsx +713 -0
  1018. package/src/plugins/impl/chat/types.ts +39 -0
  1019. package/src/plugins/impl/code/LazyAnyLanguageCodeMirror.tsx +6 -0
  1020. package/src/plugins/impl/code/any-language-editor.tsx +68 -0
  1021. package/src/plugins/impl/common/error-banner.tsx +111 -0
  1022. package/src/plugins/impl/common/intent.ts +18 -0
  1023. package/src/plugins/impl/common/labeled.tsx +69 -0
  1024. package/src/plugins/impl/data-editor/__tests__/data-utils.test.ts +876 -0
  1025. package/src/plugins/impl/data-editor/__tests__/glide-utils.test.ts +452 -0
  1026. package/src/plugins/impl/data-editor/components.tsx +179 -0
  1027. package/src/plugins/impl/data-editor/data-utils.ts +123 -0
  1028. package/src/plugins/impl/data-editor/glide-data-editor.tsx +651 -0
  1029. package/src/plugins/impl/data-editor/glide-utils.ts +200 -0
  1030. package/src/plugins/impl/data-editor/themes.ts +49 -0
  1031. package/src/plugins/impl/data-editor/types.ts +44 -0
  1032. package/src/plugins/impl/data-explorer/ConnectedDataExplorerComponent.tsx +268 -0
  1033. package/src/plugins/impl/data-explorer/DataExplorerPlugin.tsx +31 -0
  1034. package/src/plugins/impl/data-explorer/components/column-summary.tsx +174 -0
  1035. package/src/plugins/impl/data-explorer/components/icons.tsx +30 -0
  1036. package/src/plugins/impl/data-explorer/components/query-form.tsx +296 -0
  1037. package/src/plugins/impl/data-explorer/encoding.ts +107 -0
  1038. package/src/plugins/impl/data-explorer/functions/function.ts +83 -0
  1039. package/src/plugins/impl/data-explorer/functions/types.ts +32 -0
  1040. package/src/plugins/impl/data-explorer/marks.ts +21 -0
  1041. package/src/plugins/impl/data-explorer/queries/field-suggestion.ts +65 -0
  1042. package/src/plugins/impl/data-explorer/queries/histograms.ts +41 -0
  1043. package/src/plugins/impl/data-explorer/queries/queries.ts +204 -0
  1044. package/src/plugins/impl/data-explorer/queries/removeUndefined.ts +11 -0
  1045. package/src/plugins/impl/data-explorer/queries/types.ts +54 -0
  1046. package/src/plugins/impl/data-explorer/queries/utils.ts +85 -0
  1047. package/src/plugins/impl/data-explorer/spec.ts +28 -0
  1048. package/src/plugins/impl/data-explorer/state/reducer.ts +92 -0
  1049. package/src/plugins/impl/data-explorer/state/types.ts +28 -0
  1050. package/src/plugins/impl/data-frames/DataFramePlugin.tsx +303 -0
  1051. package/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap +1600 -0
  1052. package/src/plugins/impl/data-frames/forms/__tests__/form.test.tsx +67 -0
  1053. package/src/plugins/impl/data-frames/forms/context.ts +13 -0
  1054. package/src/plugins/impl/data-frames/forms/datatype-icon.tsx +43 -0
  1055. package/src/plugins/impl/data-frames/forms/renderers.tsx +518 -0
  1056. package/src/plugins/impl/data-frames/panel.tsx +308 -0
  1057. package/src/plugins/impl/data-frames/schema.ts +211 -0
  1058. package/src/plugins/impl/data-frames/types.ts +91 -0
  1059. package/src/plugins/impl/data-frames/utils/__tests__/getUpdatedColumnTypes.test.ts +191 -0
  1060. package/src/plugins/impl/data-frames/utils/__tests__/operators.test.ts +116 -0
  1061. package/src/plugins/impl/data-frames/utils/getUpdatedColumnTypes.ts +67 -0
  1062. package/src/plugins/impl/data-frames/utils/operators.ts +202 -0
  1063. package/src/plugins/impl/image-comparison/ImageComparisonComponent.tsx +39 -0
  1064. package/src/plugins/impl/multiselectFilterFn.tsx +22 -0
  1065. package/src/plugins/impl/panel/PanelPlugin.tsx +266 -0
  1066. package/src/plugins/impl/panel/__tests__/utils.test.ts +119 -0
  1067. package/src/plugins/impl/panel/utils.ts +104 -0
  1068. package/src/plugins/impl/plotly/PlotlyPlugin.tsx +300 -0
  1069. package/src/plugins/impl/plotly/__tests__/parse-from-template.test.ts +73 -0
  1070. package/src/plugins/impl/plotly/mapbox.css +359 -0
  1071. package/src/plugins/impl/plotly/parse-from-template.ts +58 -0
  1072. package/src/plugins/impl/plotly/plotly.css +280 -0
  1073. package/src/plugins/impl/vega/VegaPlugin.tsx +40 -0
  1074. package/src/plugins/impl/vega/__tests__/__snapshots__/make-selectable.test.ts.snap +1210 -0
  1075. package/src/plugins/impl/vega/__tests__/encodings.test.ts +172 -0
  1076. package/src/plugins/impl/vega/__tests__/loader.test.ts +73 -0
  1077. package/src/plugins/impl/vega/__tests__/make-selectable.test.ts +575 -0
  1078. package/src/plugins/impl/vega/__tests__/params.test.ts +52 -0
  1079. package/src/plugins/impl/vega/__tests__/resolve-data.test.ts +236 -0
  1080. package/src/plugins/impl/vega/__tests__/vega.test.ts +603 -0
  1081. package/src/plugins/impl/vega/batched.ts +41 -0
  1082. package/src/plugins/impl/vega/encodings.ts +111 -0
  1083. package/src/plugins/impl/vega/fix-relative-url.ts +15 -0
  1084. package/src/plugins/impl/vega/formats.ts +25 -0
  1085. package/src/plugins/impl/vega/loader.ts +320 -0
  1086. package/src/plugins/impl/vega/make-selectable.ts +248 -0
  1087. package/src/plugins/impl/vega/marks.ts +36 -0
  1088. package/src/plugins/impl/vega/params.ts +192 -0
  1089. package/src/plugins/impl/vega/resolve-data.ts +101 -0
  1090. package/src/plugins/impl/vega/types.ts +32 -0
  1091. package/src/plugins/impl/vega/utils.ts +46 -0
  1092. package/src/plugins/impl/vega/vega-component.tsx +271 -0
  1093. package/src/plugins/impl/vega/vega-loader.ts +53 -0
  1094. package/src/plugins/impl/vega/vega.css +31 -0
  1095. package/src/plugins/layout/AccordionPlugin.tsx +63 -0
  1096. package/src/plugins/layout/CalloutPlugin.tsx +34 -0
  1097. package/src/plugins/layout/DownloadPlugin.tsx +136 -0
  1098. package/src/plugins/layout/ImageComparisonPlugin.tsx +35 -0
  1099. package/src/plugins/layout/JsonOutputPlugin.tsx +47 -0
  1100. package/src/plugins/layout/LazyPlugin.tsx +98 -0
  1101. package/src/plugins/layout/MimeRenderPlugin.tsx +45 -0
  1102. package/src/plugins/layout/NavigationMenuPlugin.tsx +219 -0
  1103. package/src/plugins/layout/ProgressPlugin.tsx +175 -0
  1104. package/src/plugins/layout/RoutesPlugin.tsx +81 -0
  1105. package/src/plugins/layout/StatPlugin.tsx +100 -0
  1106. package/src/plugins/layout/TexPlugin.tsx +102 -0
  1107. package/src/plugins/layout/__test__/ProgressPlugin.test.ts +26 -0
  1108. package/src/plugins/layout/carousel/CarouselPlugin.tsx +48 -0
  1109. package/src/plugins/layout/mermaid/MermaidPlugin.tsx +26 -0
  1110. package/src/plugins/layout/mermaid/mermaid.tsx +94 -0
  1111. package/src/plugins/layout/navigation-menu.css +37 -0
  1112. package/src/plugins/plugins.ts +116 -0
  1113. package/src/plugins/stateless-plugin.ts +29 -0
  1114. package/src/plugins/types.ts +82 -0
  1115. package/src/stories/__fixtures__/vega.ts +225 -0
  1116. package/src/stories/accordion.stories.tsx +100 -0
  1117. package/src/stories/alert-dialog.mdx +42 -0
  1118. package/src/stories/app-chrome.stories.tsx +26 -0
  1119. package/src/stories/button.stories.tsx +90 -0
  1120. package/src/stories/callout.stories.tsx +73 -0
  1121. package/src/stories/cell-status.stories.tsx +145 -0
  1122. package/src/stories/cell.stories.tsx +336 -0
  1123. package/src/stories/checkbox.stories.tsx +44 -0
  1124. package/src/stories/colors.stories.tsx +156 -0
  1125. package/src/stories/combobox.stories.tsx +133 -0
  1126. package/src/stories/context-menu.mdx +23 -0
  1127. package/src/stories/data-explorer.stories.tsx +30 -0
  1128. package/src/stories/data-table.stories.tsx +130 -0
  1129. package/src/stories/dataframe.stories.tsx +46 -0
  1130. package/src/stories/debugger.stories.tsx +34 -0
  1131. package/src/stories/dialog.stories.tsx +80 -0
  1132. package/src/stories/dropdown-menu.mdx +159 -0
  1133. package/src/stories/editor-inputs.stories.tsx +47 -0
  1134. package/src/stories/editor.stories.tsx +91 -0
  1135. package/src/stories/file-upload.stories.tsx +103 -0
  1136. package/src/stories/form-wrapper.stories.tsx +147 -0
  1137. package/src/stories/input.stories.tsx +56 -0
  1138. package/src/stories/label.mdx +9 -0
  1139. package/src/stories/log-viewer.stories.tsx +74 -0
  1140. package/src/stories/number-field.mdx +17 -0
  1141. package/src/stories/number-field.stories.tsx +41 -0
  1142. package/src/stories/progress-component.stories.tsx +74 -0
  1143. package/src/stories/progress.stories.tsx +33 -0
  1144. package/src/stories/radio-group.mdx +54 -0
  1145. package/src/stories/select-native.stories.tsx +49 -0
  1146. package/src/stories/select.stories.tsx +92 -0
  1147. package/src/stories/slider.stories.tsx +27 -0
  1148. package/src/stories/stat.stories.tsx +123 -0
  1149. package/src/stories/switch.mdx +20 -0
  1150. package/src/stories/switchable-multi-select.stories.tsx +31 -0
  1151. package/src/stories/tabs.mdx +59 -0
  1152. package/src/stories/textarea.stories.tsx +58 -0
  1153. package/src/stories/theme.stories.tsx +111 -0
  1154. package/src/stories/tooltip.mdx +32 -0
  1155. package/src/stories/typography.stories.tsx +80 -0
  1156. package/src/stories/variables.stories.tsx +58 -0
  1157. package/src/stories/vega.stories.tsx +57 -0
  1158. package/src/theme/ThemeProvider.tsx +32 -0
  1159. package/src/theme/namespace.tsx +23 -0
  1160. package/src/theme/useTheme.ts +89 -0
  1161. package/src/utils/Deferred.ts +20 -0
  1162. package/src/utils/Logger.ts +91 -0
  1163. package/src/utils/__tests__/Deferred.test.ts +38 -0
  1164. package/src/utils/__tests__/arrays.test.ts +130 -0
  1165. package/src/utils/__tests__/batch-requests.test.ts +60 -0
  1166. package/src/utils/__tests__/blob.test.ts +52 -0
  1167. package/src/utils/__tests__/cell-urls.test.ts +92 -0
  1168. package/src/utils/__tests__/createReducer.test.ts +184 -0
  1169. package/src/utils/__tests__/data-views.test.ts +112 -0
  1170. package/src/utils/__tests__/dates.test.ts +188 -0
  1171. package/src/utils/__tests__/edit-distance.test.ts +302 -0
  1172. package/src/utils/__tests__/errors.test.ts +54 -0
  1173. package/src/utils/__tests__/filenames.test.ts +30 -0
  1174. package/src/utils/__tests__/id-tree.test.ts +1994 -0
  1175. package/src/utils/__tests__/json-parser.test.ts +79 -0
  1176. package/src/utils/__tests__/local-storage.test.ts +77 -0
  1177. package/src/utils/__tests__/lru.test.ts +74 -0
  1178. package/src/utils/__tests__/maps.test.ts +91 -0
  1179. package/src/utils/__tests__/math.test.ts +29 -0
  1180. package/src/utils/__tests__/multi-map.test.ts +295 -0
  1181. package/src/utils/__tests__/numbers.test.ts +76 -0
  1182. package/src/utils/__tests__/path.test.ts +170 -0
  1183. package/src/utils/__tests__/pluralize.test.ts +47 -0
  1184. package/src/utils/__tests__/routes.test.ts +134 -0
  1185. package/src/utils/__tests__/sets.test.ts +41 -0
  1186. package/src/utils/__tests__/shallow-compare.test.ts +55 -0
  1187. package/src/utils/__tests__/strings.test.ts +68 -0
  1188. package/src/utils/__tests__/time.test.ts +61 -0
  1189. package/src/utils/__tests__/timed-cache.test.ts +142 -0
  1190. package/src/utils/__tests__/timeout.test.ts +153 -0
  1191. package/src/utils/__tests__/traceback.test.ts +34 -0
  1192. package/src/utils/__tests__/url.test.ts +100 -0
  1193. package/src/utils/__tests__/urls.test.ts +10 -0
  1194. package/src/utils/__tests__/versions.test.ts +63 -0
  1195. package/src/utils/__tests__/waitForWs.test.ts +76 -0
  1196. package/src/utils/arrays.ts +75 -0
  1197. package/src/utils/assertExists.ts +12 -0
  1198. package/src/utils/assertNever.ts +20 -0
  1199. package/src/utils/batch-requests.ts +28 -0
  1200. package/src/utils/blob.ts +45 -0
  1201. package/src/utils/cell-urls.ts +31 -0
  1202. package/src/utils/cn.ts +8 -0
  1203. package/src/utils/copy.ts +17 -0
  1204. package/src/utils/createReducer.ts +137 -0
  1205. package/src/utils/data-views.ts +54 -0
  1206. package/src/utils/dates.ts +145 -0
  1207. package/src/utils/dereference.ts +10 -0
  1208. package/src/utils/download.ts +47 -0
  1209. package/src/utils/edit-distance.ts +141 -0
  1210. package/src/utils/errors.ts +63 -0
  1211. package/src/utils/events.ts +85 -0
  1212. package/src/utils/fileToBase64.ts +30 -0
  1213. package/src/utils/filenames.ts +29 -0
  1214. package/src/utils/functions.ts +24 -0
  1215. package/src/utils/id-tree.tsx +1032 -0
  1216. package/src/utils/idle.ts +19 -0
  1217. package/src/utils/invariant.ts +37 -0
  1218. package/src/utils/json/__tests__/base64.test.ts +100 -0
  1219. package/src/utils/json/base64.ts +51 -0
  1220. package/src/utils/json/json-parser.ts +65 -0
  1221. package/src/utils/lazy.ts +30 -0
  1222. package/src/utils/links.ts +11 -0
  1223. package/src/utils/localStorage.ts +132 -0
  1224. package/src/utils/lru.ts +68 -0
  1225. package/src/utils/maps.ts +65 -0
  1226. package/src/utils/math.ts +6 -0
  1227. package/src/utils/mergeRefs.ts +14 -0
  1228. package/src/utils/multi-map.ts +71 -0
  1229. package/src/utils/numbers.ts +124 -0
  1230. package/src/utils/objects.ts +105 -0
  1231. package/src/utils/once.ts +17 -0
  1232. package/src/utils/pathUtils.test.ts +113 -0
  1233. package/src/utils/pathUtils.ts +76 -0
  1234. package/src/utils/paths.ts +67 -0
  1235. package/src/utils/pluralize.ts +35 -0
  1236. package/src/utils/python-poet/__tests__/poet.test.ts +286 -0
  1237. package/src/utils/python-poet/poet.ts +196 -0
  1238. package/src/utils/reload-safe.ts +15 -0
  1239. package/src/utils/repl.ts +23 -0
  1240. package/src/utils/routes.ts +36 -0
  1241. package/src/utils/scroll.ts +38 -0
  1242. package/src/utils/sets.ts +30 -0
  1243. package/src/utils/shallow-compare.ts +30 -0
  1244. package/src/utils/staticImplements.ts +7 -0
  1245. package/src/utils/strings.ts +64 -0
  1246. package/src/utils/time.ts +39 -0
  1247. package/src/utils/timed-cache.ts +52 -0
  1248. package/src/utils/timeout.ts +42 -0
  1249. package/src/utils/traceback.ts +104 -0
  1250. package/src/utils/tracer.ts +106 -0
  1251. package/src/utils/typed.ts +17 -0
  1252. package/src/utils/url.ts +12 -0
  1253. package/src/utils/urls.ts +33 -0
  1254. package/src/utils/uuid.ts +8 -0
  1255. package/src/utils/versions.ts +66 -0
  1256. package/src/utils/vitals.ts +30 -0
  1257. package/src/utils/waitForWs.ts +31 -0
  1258. package/dist/assets/_baseMap-CRSErap7.js +0 -1
  1259. package/dist/assets/channel-DkujgbuA.js +0 -1
  1260. package/dist/assets/classDiagram-M3E45YP4-C27KFaf-.js +0 -1
  1261. package/dist/assets/classDiagram-v2-YAWTLIQI-C27KFaf-.js +0 -1
  1262. package/dist/assets/clone-BcaRetEG.js +0 -1
  1263. package/dist/assets/edit-page-CyEUf7VL.js +0 -163
  1264. package/dist/assets/index-BlxPam9h.css +0 -1
  1265. package/dist/assets/infoDiagram-LHK5PUON-DM8xmmD0.js +0 -2
  1266. package/dist/assets/links-UdVi9TCH.js +0 -17
  1267. package/dist/assets/min-DsZNGHWk.js +0 -1
  1268. package/dist/assets/sortBy-DRXBnSF7.js +0 -1
  1269. package/dist/assets/stateDiagram-v2-5AN5P6BG-BmONtexb.js +0 -1
  1270. package/dist/assets/storage-C6lB9RSO.js +0 -26
  1271. package/dist/assets/time-CjxeuzoW.js +0 -1
@@ -0,0 +1,1751 @@
1
+ /* Copyright 2024 Marimo. All rights reserved. */
2
+
3
+ import { historyField } from "@codemirror/commands";
4
+ import { type Atom, atom, useAtom, useAtomValue } from "jotai";
5
+ import { atomFamily, selectAtom, splitAtom } from "jotai/utils";
6
+ import { isEqual, zip } from "lodash-es";
7
+ import { createRef, type ReducerWithoutAction } from "react";
8
+ import type { CellHandle } from "@/components/editor/Cell";
9
+ import {
10
+ type CellColumnId,
11
+ type CellIndex,
12
+ MultiColumn,
13
+ } from "@/utils/id-tree";
14
+ import { invariant } from "@/utils/invariant";
15
+ import { Logger } from "@/utils/Logger";
16
+ import { clamp } from "@/utils/math";
17
+ import { Objects } from "@/utils/objects";
18
+ import { extractAllTracebackInfo, type TracebackInfo } from "@/utils/traceback";
19
+ import { createReducerAndAtoms } from "../../utils/createReducer";
20
+ import { foldAllBulk, unfoldAllBulk } from "../codemirror/editing/commands";
21
+ import {
22
+ splitEditor,
23
+ updateEditorCodeFromPython,
24
+ } from "../codemirror/language/utils";
25
+ import { findCollapseRange, mergeOutlines } from "../dom/outline";
26
+ import type { CellMessage } from "../kernel/messages";
27
+ import { isErrorMime } from "../mime";
28
+ import type { CellConfig } from "../network/types";
29
+ import { isRtcEnabled } from "../rtc/state";
30
+ import { createDeepEqualAtom, store } from "../state/jotai";
31
+ import { prepareCellForExecution, transitionCell } from "./cell";
32
+ import { CellId } from "./ids";
33
+ import { type CellLog, getCellLogsForMessage } from "./logs";
34
+ import {
35
+ focusAndScrollCellIntoView,
36
+ scrollToBottom,
37
+ scrollToTop,
38
+ } from "./scrollCellIntoView";
39
+ import {
40
+ type CellData,
41
+ type CellRuntimeState,
42
+ createCell,
43
+ createCellConfig,
44
+ createCellRuntimeState,
45
+ } from "./types";
46
+ import {
47
+ canUndoDeletes,
48
+ disabledCellIds,
49
+ enabledCellIds,
50
+ notebookIsRunning,
51
+ notebookNeedsRun,
52
+ notebookQueueOrRunningCount,
53
+ } from "./utils";
54
+
55
+ export const SCRATCH_CELL_ID = "__scratch__" as CellId;
56
+ export const SETUP_CELL_ID = "setup" as CellId;
57
+
58
+ export function isSetupCell(cellId: CellId): boolean {
59
+ return cellId === SETUP_CELL_ID;
60
+ }
61
+
62
+ /**
63
+ * The state of the notebook.
64
+ */
65
+ export interface NotebookState {
66
+ /**
67
+ * Order of cells on the page.
68
+ */
69
+ cellIds: MultiColumn<CellId>;
70
+ /**
71
+ * Map of cells to their view state
72
+ */
73
+ cellData: Record<CellId, CellData>;
74
+ /**
75
+ * Map of cells to their runtime state
76
+ */
77
+ cellRuntime: Record<CellId, CellRuntimeState>;
78
+ /**
79
+ * Cell handlers
80
+ */
81
+ cellHandles: Record<CellId, React.RefObject<CellHandle | null>>;
82
+ /**
83
+ * Array of deleted cells (with their data and index) so that cell deletion can be undone
84
+ *
85
+ * (CodeMirror types the serialized config as any.)
86
+ */
87
+ history: Array<{
88
+ name: string;
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ serializedEditorState: any;
91
+ column: CellColumnId;
92
+ index: CellIndex;
93
+ isSetupCell: boolean;
94
+ }>;
95
+ /**
96
+ * Key of cell to scroll to; typically set by actions that re-order the cell
97
+ * array. Call the SCROLL_TO_TARGET action to scroll to the specified cell
98
+ * and clear this field.
99
+ */
100
+ scrollKey: CellId | null;
101
+ /**
102
+ * Logs of all cell messages
103
+ */
104
+ cellLogs: CellLog[];
105
+ /**
106
+ * Set of cells that have been created that are initialized with `hide_code`.
107
+ *
108
+ * These start temporarily open until their first blur event.
109
+ */
110
+ untouchedNewCells: Set<CellId>;
111
+ }
112
+
113
+ function withScratchCell(notebookState: NotebookState): NotebookState {
114
+ const config = { column: 0, hide_code: false, disabled: false };
115
+ return {
116
+ ...notebookState,
117
+ cellData: {
118
+ [SCRATCH_CELL_ID]: createCell({ id: SCRATCH_CELL_ID, config: config }),
119
+ ...notebookState.cellData,
120
+ },
121
+ cellRuntime: {
122
+ [SCRATCH_CELL_ID]: createCellRuntimeState(),
123
+ ...notebookState.cellRuntime,
124
+ },
125
+ cellHandles: {
126
+ [SCRATCH_CELL_ID]: createRef(),
127
+ ...notebookState.cellHandles,
128
+ },
129
+ };
130
+ }
131
+
132
+ /**
133
+ * Initial state of the notebook.
134
+ */
135
+ export function initialNotebookState(): NotebookState {
136
+ return withScratchCell({
137
+ cellIds: MultiColumn.from([]),
138
+ cellData: {},
139
+ cellRuntime: {},
140
+ cellHandles: {},
141
+ history: [],
142
+ scrollKey: null,
143
+ cellLogs: [],
144
+ untouchedNewCells: new Set<CellId>(),
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Actions and reducer for the notebook state.
150
+ */
151
+ const {
152
+ reducer,
153
+ createActions,
154
+ useActions,
155
+ valueAtom: notebookAtom,
156
+ } = createReducerAndAtoms(initialNotebookState, {
157
+ createNewCell: (
158
+ state,
159
+ action: {
160
+ /** The target cell ID to create a new cell relative to. Can be:
161
+ * - A CellId string for an existing cell
162
+ * - "__end__" to append at the end of the first column
163
+ * - {type: "__end__", columnId} to append at the end of a specific column
164
+ */
165
+ cellId: CellId | "__end__" | { type: "__end__"; columnId: CellColumnId };
166
+ /** Whether to insert before (true) or after (false) the target cell */
167
+ before: boolean;
168
+ /** Initial code content for the new cell */
169
+ code?: string;
170
+ /** The last executed code for the new cell */
171
+ lastCodeRun?: string;
172
+ /** Timestamp of the last execution */
173
+ lastExecutionTime?: number;
174
+ /** Optional custom ID for the new cell. Auto-generated if not provided */
175
+ newCellId?: CellId;
176
+ /** Whether to focus the new cell after creation */
177
+ autoFocus?: boolean;
178
+ /** If true, skip creation if code already exists */
179
+ skipIfCodeExists?: boolean;
180
+ /** Hide the code in the new cell. This will be initially shown until the cell is blurred for the first time. */
181
+ hideCode?: boolean;
182
+ },
183
+ ) => {
184
+ const {
185
+ cellId,
186
+ before,
187
+ code,
188
+ lastCodeRun = null,
189
+ lastExecutionTime = null,
190
+ autoFocus = true,
191
+ skipIfCodeExists = false,
192
+ hideCode = false,
193
+ } = action;
194
+
195
+ let columnId: CellColumnId;
196
+ let cellIndex: number;
197
+
198
+ // If skipIfCodeExists is true, check if the code already exists in the notebook
199
+ if (skipIfCodeExists) {
200
+ for (const cellId of state.cellIds.inOrderIds) {
201
+ if (state.cellData[cellId]?.code === code) {
202
+ return state;
203
+ }
204
+ }
205
+ }
206
+
207
+ if (cellId === "__end__") {
208
+ const column = state.cellIds.atOrThrow(0);
209
+ columnId = column.id;
210
+ cellIndex = column.length;
211
+ } else if (typeof cellId === "string") {
212
+ const column = state.cellIds.findWithId(cellId);
213
+ columnId = column.id;
214
+ cellIndex = column.topLevelIds.indexOf(cellId);
215
+ } else if (cellId.type === "__end__") {
216
+ const column =
217
+ state.cellIds.get(cellId.columnId) || state.cellIds.atOrThrow(0);
218
+ columnId = column.id;
219
+ cellIndex = column.length;
220
+ } else {
221
+ throw new Error("Invalid cellId");
222
+ }
223
+
224
+ const newCellId = action.newCellId || CellId.create();
225
+ const insertionIndex = before ? cellIndex : cellIndex + 1;
226
+
227
+ return {
228
+ ...state,
229
+ cellIds: state.cellIds.insertId(newCellId, columnId, insertionIndex),
230
+ cellData: {
231
+ ...state.cellData,
232
+ [newCellId]: createCell({
233
+ id: newCellId,
234
+ code,
235
+ lastCodeRun,
236
+ config: createCellConfig({ hide_code: hideCode }),
237
+ lastExecutionTime,
238
+ edited: Boolean(code) && code !== lastCodeRun,
239
+ }),
240
+ },
241
+ cellRuntime: {
242
+ ...state.cellRuntime,
243
+ [newCellId]: createCellRuntimeState(),
244
+ },
245
+ cellHandles: {
246
+ ...state.cellHandles,
247
+ [newCellId]: createRef(),
248
+ },
249
+ scrollKey: autoFocus ? newCellId : null,
250
+ untouchedNewCells: hideCode
251
+ ? new Set([...state.untouchedNewCells, newCellId])
252
+ : state.untouchedNewCells,
253
+ };
254
+ },
255
+ moveCell: (
256
+ state,
257
+ action: {
258
+ cellId: CellId;
259
+ before?: boolean;
260
+ direction?: "left" | "right";
261
+ },
262
+ ) => {
263
+ const { cellId, before, direction } = action;
264
+
265
+ if (before !== undefined && direction !== undefined) {
266
+ Logger.warn(
267
+ "Both before and direction specified for moveCell. Ignoring one.",
268
+ );
269
+ }
270
+
271
+ // Handle left/right movement
272
+ if (direction) {
273
+ const fromColumn = state.cellIds.findWithId(cellId);
274
+ const fromColumnIndex = state.cellIds.indexOf(fromColumn);
275
+ const toColumnIndex =
276
+ direction === "left" ? fromColumnIndex - 1 : fromColumnIndex + 1;
277
+ const toColumn = state.cellIds.at(toColumnIndex);
278
+
279
+ // If no column to move to, return unchanged state
280
+ if (!toColumn) {
281
+ return state;
282
+ }
283
+
284
+ return {
285
+ ...state,
286
+ cellIds: state.cellIds.moveAcrossColumns(
287
+ fromColumn.id,
288
+ cellId,
289
+ toColumn.id,
290
+ undefined,
291
+ ),
292
+ scrollKey: cellId,
293
+ };
294
+ }
295
+
296
+ // Handle up/down movement
297
+ const column = state.cellIds.findWithId(cellId);
298
+ const cellIndex = column.indexOfOrThrow(cellId);
299
+
300
+ if (before && cellIndex === 0) {
301
+ return {
302
+ ...state,
303
+ cellIds: state.cellIds.moveWithinColumn(column.id, cellIndex, 0),
304
+ scrollKey: cellId,
305
+ };
306
+ }
307
+ if (!before && cellIndex === column.length - 1) {
308
+ return {
309
+ ...state,
310
+ cellIds: state.cellIds.moveWithinColumn(
311
+ column.id,
312
+ cellIndex,
313
+ column.length - 1,
314
+ ),
315
+ scrollKey: cellId,
316
+ };
317
+ }
318
+
319
+ return before
320
+ ? {
321
+ ...state,
322
+ cellIds: state.cellIds.moveWithinColumn(
323
+ column.id,
324
+ cellIndex,
325
+ cellIndex - 1,
326
+ ),
327
+ scrollKey: cellId,
328
+ }
329
+ : {
330
+ ...state,
331
+ cellIds: state.cellIds.moveWithinColumn(
332
+ column.id,
333
+ cellIndex,
334
+ cellIndex + 1,
335
+ ),
336
+ scrollKey: cellId,
337
+ };
338
+ },
339
+ dropCellOverCell: (state, action: { cellId: CellId; overCellId: CellId }) => {
340
+ const { cellId, overCellId } = action;
341
+
342
+ const fromColumn = state.cellIds.findWithId(cellId);
343
+ const toColumn = state.cellIds.findWithId(overCellId);
344
+
345
+ const fromIndex = fromColumn.indexOfOrThrow(cellId);
346
+ const toIndex = toColumn.indexOfOrThrow(overCellId);
347
+
348
+ if (fromColumn.id === toColumn.id) {
349
+ if (fromIndex === toIndex) {
350
+ return state;
351
+ }
352
+ return {
353
+ ...state,
354
+ cellIds: state.cellIds.moveWithinColumn(
355
+ fromColumn.id,
356
+ fromIndex,
357
+ toIndex,
358
+ ),
359
+ scrollKey: null,
360
+ };
361
+ }
362
+
363
+ return {
364
+ ...state,
365
+ cellIds: state.cellIds.moveAcrossColumns(
366
+ fromColumn.id,
367
+ cellId,
368
+ toColumn.id,
369
+ overCellId,
370
+ ),
371
+ scrollKey: null,
372
+ };
373
+ },
374
+ dropCellOverColumn: (
375
+ state,
376
+ action: { cellId: CellId; columnId: CellColumnId },
377
+ ) => {
378
+ const { cellId, columnId } = action;
379
+ const fromColumn = state.cellIds.findWithId(cellId);
380
+
381
+ return {
382
+ ...state,
383
+ cellIds: state.cellIds.moveAcrossColumns(
384
+ fromColumn.id,
385
+ cellId,
386
+ columnId,
387
+ undefined,
388
+ ),
389
+ };
390
+ },
391
+ dropOverNewColumn: (state, action: { cellId: CellId }) => {
392
+ const { cellId } = action;
393
+ return {
394
+ ...state,
395
+ cellIds: state.cellIds.moveToNewColumn(cellId),
396
+ };
397
+ },
398
+ moveColumn: (
399
+ state,
400
+ action: {
401
+ column: CellColumnId;
402
+ overColumn: CellColumnId | "_left_" | "_right_";
403
+ },
404
+ ) => {
405
+ if (action.column === action.overColumn) {
406
+ return state;
407
+ }
408
+ return {
409
+ ...state,
410
+ cellIds: state.cellIds.moveColumn(action.column, action.overColumn),
411
+ };
412
+ },
413
+ focusCell: (
414
+ state,
415
+ action: { cellId: CellId; where: "before" | "after" | "exact" },
416
+ ) => {
417
+ const column = state.cellIds.findWithId(action.cellId);
418
+ if (column.length === 0) {
419
+ return state;
420
+ }
421
+
422
+ const { cellId, where } = action;
423
+ const index = column.indexOfOrThrow(cellId);
424
+
425
+ let focusIndex: number;
426
+ if (where === "before") {
427
+ focusIndex = clamp(index - 1, 0, column.length - 1);
428
+ } else if (where === "after") {
429
+ focusIndex = clamp(index + 1, 0, column.length - 1);
430
+ } else {
431
+ focusIndex = index;
432
+ }
433
+ const focusCellId = column.atOrThrow(focusIndex);
434
+ // can scroll immediately, without setting scrollKey in state, because
435
+ // CellArray won't need to re-render
436
+ focusAndScrollCellIntoView({
437
+ cellId: focusCellId,
438
+ cell: state.cellHandles[focusCellId],
439
+ isCodeHidden: isCellCodeHidden(state, focusCellId),
440
+ codeFocus: where === "after" ? "top" : "bottom",
441
+ variableName: undefined,
442
+ });
443
+ return state;
444
+ },
445
+ focusTopCell: (state) => {
446
+ // TODO: focus the existing column, not the first column
447
+ const column = state.cellIds.getColumns().at(0);
448
+ if (column === undefined || column.length === 0) {
449
+ return state;
450
+ }
451
+
452
+ const cellId = column.first();
453
+ focusAndScrollCellIntoView({
454
+ cellId: cellId,
455
+ cell: state.cellHandles[cellId],
456
+ isCodeHidden: isCellCodeHidden(state, cellId),
457
+ codeFocus: undefined,
458
+ variableName: undefined,
459
+ });
460
+ scrollToTop();
461
+ return state;
462
+ },
463
+ focusBottomCell: (state) => {
464
+ // TODO: focus the existing column, not the last column
465
+ const column = state.cellIds.getColumns().at(-1);
466
+ if (column === undefined || column.length === 0) {
467
+ return state;
468
+ }
469
+
470
+ const cellId = column.last();
471
+ focusAndScrollCellIntoView({
472
+ cellId: cellId,
473
+ cell: state.cellHandles[cellId],
474
+ isCodeHidden: isCellCodeHidden(state, cellId),
475
+ codeFocus: undefined,
476
+ variableName: undefined,
477
+ });
478
+ scrollToBottom();
479
+ return state;
480
+ },
481
+ sendToTop: (state, action: { cellId: CellId; scroll?: boolean }) => {
482
+ const column = state.cellIds.findWithId(action.cellId);
483
+ if (column.length === 0) {
484
+ return state;
485
+ }
486
+
487
+ const { cellId, scroll = true } = action;
488
+ const cellIndex = column.indexOfOrThrow(cellId);
489
+ if (cellIndex === 0) {
490
+ return state;
491
+ }
492
+
493
+ return {
494
+ ...state,
495
+ cellIds: state.cellIds.moveWithinColumn(column.id, cellIndex, 0),
496
+ scrollKey: scroll ? cellId : null,
497
+ };
498
+ },
499
+ sendToBottom: (state, action: { cellId: CellId; scroll?: boolean }) => {
500
+ const column = state.cellIds.findWithId(action.cellId);
501
+ if (column.length === 0) {
502
+ return state;
503
+ }
504
+
505
+ const { cellId, scroll = true } = action;
506
+ const cellIndex = column.indexOfOrThrow(cellId);
507
+ const newIndex = column.length - 1;
508
+
509
+ if (cellIndex === newIndex) {
510
+ return state;
511
+ }
512
+
513
+ return {
514
+ ...state,
515
+ cellIds: state.cellIds.moveWithinColumn(column.id, cellIndex, newIndex),
516
+ scrollKey: scroll ? cellId : null,
517
+ };
518
+ },
519
+ addColumn: (state, action: { columnId: CellColumnId }) => {
520
+ // Add column and new cell
521
+ const newCellId = CellId.create();
522
+ return {
523
+ ...state,
524
+ cellIds: state.cellIds.addColumn(action.columnId, [newCellId]),
525
+ cellData: {
526
+ ...state.cellData,
527
+ [newCellId]: createCell({
528
+ id: newCellId,
529
+ }),
530
+ },
531
+ cellRuntime: {
532
+ ...state.cellRuntime,
533
+ [newCellId]: createCellRuntimeState(),
534
+ },
535
+ cellHandles: {
536
+ ...state.cellHandles,
537
+ [newCellId]: createRef(),
538
+ },
539
+ scrollKey: newCellId,
540
+ };
541
+ },
542
+ addColumnBreakpoint: (state, action: { cellId: CellId }) => {
543
+ const { cellId } = action;
544
+ if (state.cellIds.getColumns()[0].inOrderIds[0] === cellId) {
545
+ return state;
546
+ }
547
+ return {
548
+ ...state,
549
+ cellIds: state.cellIds.insertBreakpoint(cellId),
550
+ };
551
+ },
552
+ deleteColumn: (state, action: { columnId: CellColumnId }) => {
553
+ // Move all cells in the column to the previous column
554
+ const { columnId } = action;
555
+ return {
556
+ ...state,
557
+ cellIds: state.cellIds.delete(columnId),
558
+ };
559
+ },
560
+ mergeAllColumns: (state) => {
561
+ return {
562
+ ...state,
563
+ cellIds: state.cellIds.mergeAllColumns(),
564
+ };
565
+ },
566
+ compactColumns: (state) => {
567
+ return {
568
+ ...state,
569
+ cellIds: state.cellIds.compact(),
570
+ };
571
+ },
572
+ deleteCell: (state, action: { cellId: CellId }) => {
573
+ const cellId = action.cellId;
574
+
575
+ // Can't delete the last cell, across all columns
576
+ if (state.cellIds.hasOnlyOneId()) {
577
+ return state;
578
+ }
579
+
580
+ const column = state.cellIds.findWithId(cellId);
581
+ const cellIndex = column.indexOfOrThrow(cellId);
582
+ const focusIndex = cellIndex === 0 ? 1 : cellIndex - 1;
583
+ let scrollKey: CellId | null = null;
584
+ if (column.length > 1) {
585
+ scrollKey = column.atOrThrow(focusIndex);
586
+ }
587
+
588
+ const editorView = state.cellHandles[cellId].current?.editorView;
589
+ const serializedEditorState = editorView?.state.toJSON({
590
+ history: historyField,
591
+ });
592
+ serializedEditorState.doc = state.cellData[cellId].code;
593
+
594
+ // release the granular atom(s) created for this cell
595
+ releaseCellAtoms(cellId);
596
+ return {
597
+ ...state,
598
+ cellIds: state.cellIds.deleteById(cellId),
599
+ history: [
600
+ ...state.history,
601
+ {
602
+ name: state.cellData[cellId].name,
603
+ serializedEditorState: serializedEditorState,
604
+ column: column.id,
605
+ index: cellIndex,
606
+ isSetupCell: cellId === SETUP_CELL_ID,
607
+ },
608
+ ],
609
+ scrollKey: scrollKey,
610
+ };
611
+ },
612
+ undoDeleteCell: (state) => {
613
+ if (state.history.length === 0) {
614
+ return state;
615
+ }
616
+
617
+ const mostRecentlyDeleted = state.history[state.history.length - 1];
618
+
619
+ const {
620
+ name,
621
+ serializedEditorState = { doc: "" },
622
+ column,
623
+ index,
624
+ isSetupCell,
625
+ } = mostRecentlyDeleted;
626
+
627
+ const cellId = isSetupCell ? SETUP_CELL_ID : CellId.create();
628
+ const undoCell = createCell({
629
+ id: cellId,
630
+ name,
631
+ code: serializedEditorState.doc,
632
+ edited: serializedEditorState.doc.trim().length > 0,
633
+ serializedEditorState,
634
+ });
635
+
636
+ return {
637
+ ...state,
638
+ cellIds: state.cellIds.insertId(cellId, column, index),
639
+ cellData: {
640
+ ...state.cellData,
641
+ [cellId]: undoCell,
642
+ },
643
+ cellRuntime: {
644
+ ...state.cellRuntime,
645
+ [cellId]: createCellRuntimeState(),
646
+ },
647
+ cellHandles: {
648
+ ...state.cellHandles,
649
+ [cellId]: createRef(),
650
+ },
651
+ history: state.history.slice(0, -1),
652
+ };
653
+ },
654
+ clearSerializedEditorState: (state, action: { cellId: CellId }) => {
655
+ const { cellId } = action;
656
+ return updateCellData({
657
+ state,
658
+ cellId,
659
+ cellReducer: (cell) => {
660
+ return {
661
+ ...cell,
662
+ serializedEditorState: null,
663
+ };
664
+ },
665
+ });
666
+ },
667
+ updateCellCode: (
668
+ state,
669
+ action: {
670
+ cellId: CellId;
671
+ code: string;
672
+ /**
673
+ * Whether or not the update is a formatting change,
674
+ * if so, the 'edited' state will be handled differently.
675
+ */
676
+ formattingChange: boolean;
677
+ },
678
+ ) => {
679
+ const { cellId, code, formattingChange } = action;
680
+ if (!state.cellData[cellId]) {
681
+ return state;
682
+ }
683
+
684
+ return updateCellData({
685
+ state,
686
+ cellId,
687
+ cellReducer: (cell) => {
688
+ // Formatting-only change means we can re-use the last code run
689
+ // if it was not previously edited. And we don't change the edited state.
690
+ return formattingChange
691
+ ? {
692
+ ...cell,
693
+ code: code,
694
+ lastCodeRun: cell.edited ? cell.lastCodeRun : code,
695
+ }
696
+ : {
697
+ ...cell,
698
+ code: code,
699
+ edited: code.trim() !== cell.lastCodeRun,
700
+ };
701
+ },
702
+ });
703
+ },
704
+ updateCellName: (state, action: { cellId: CellId; name: string }) => {
705
+ const { cellId, name } = action;
706
+ return updateCellData({
707
+ state,
708
+ cellId,
709
+ cellReducer: (cell) => {
710
+ return {
711
+ ...cell,
712
+ name: name,
713
+ };
714
+ },
715
+ });
716
+ },
717
+ updateCellConfig: (
718
+ state,
719
+ action: { cellId: CellId; config: Partial<CellConfig> },
720
+ ) => {
721
+ const { cellId, config } = action;
722
+ return updateCellData({
723
+ state,
724
+ cellId,
725
+ cellReducer: (cell) => {
726
+ return {
727
+ ...cell,
728
+ config: { ...cell.config, ...config },
729
+ };
730
+ },
731
+ });
732
+ },
733
+ prepareForRun: (state, action: { cellId: CellId }) => {
734
+ const newState = updateCellRuntimeState({
735
+ state,
736
+ cellId: action.cellId,
737
+ cellReducer: (cell) => {
738
+ return prepareCellForExecution(cell);
739
+ },
740
+ });
741
+ return updateCellData({
742
+ state: newState,
743
+ cellId: action.cellId,
744
+ cellReducer: (cell) => {
745
+ return {
746
+ ...cell,
747
+ edited: false,
748
+ lastCodeRun: cell.code.trim(),
749
+ };
750
+ },
751
+ });
752
+ },
753
+ handleCellMessage: (state, message: CellMessage) => {
754
+ const cellId = message.cell_id as CellId;
755
+ const nextState = updateCellRuntimeState({
756
+ state,
757
+ cellId,
758
+ cellReducer: (cell) => {
759
+ return transitionCell(cell, message);
760
+ },
761
+ });
762
+ return {
763
+ ...nextState,
764
+ cellLogs: [...nextState.cellLogs, ...getCellLogsForMessage(message)],
765
+ };
766
+ },
767
+ setCellIds: (state, action: { cellIds: CellId[] }) => {
768
+ const isTheSame = isEqual(state.cellIds.inOrderIds, action.cellIds);
769
+ if (isTheSame) {
770
+ return state;
771
+ }
772
+
773
+ // Create new cell data and runtime states for the new cell IDs
774
+ const nextCellData = { ...state.cellData };
775
+ const nextCellRuntime = { ...state.cellRuntime };
776
+ const nextCellHandles = { ...state.cellHandles };
777
+
778
+ for (const cellId of action.cellIds) {
779
+ if (!(cellId in state.cellData)) {
780
+ nextCellData[cellId] = createCell({ id: cellId });
781
+ }
782
+ if (!(cellId in state.cellRuntime)) {
783
+ nextCellRuntime[cellId] = createCellRuntimeState();
784
+ }
785
+ if (!(cellId in state.cellHandles)) {
786
+ nextCellHandles[cellId] = createRef();
787
+ }
788
+ }
789
+
790
+ return {
791
+ ...state,
792
+ cellIds: MultiColumn.fromWithPreviousShape(action.cellIds, state.cellIds),
793
+ cellData: nextCellData,
794
+ cellRuntime: nextCellRuntime,
795
+ cellHandles: nextCellHandles,
796
+ };
797
+ },
798
+ setCellCodes: (
799
+ state,
800
+ action: { codes: string[]; ids: CellId[]; codeIsStale: boolean },
801
+ ) => {
802
+ invariant(
803
+ action.codes.length === action.ids.length,
804
+ "Expected codes and ids to have the same length",
805
+ );
806
+
807
+ let nextState = { ...state };
808
+
809
+ const cellReducer = ({
810
+ cell,
811
+ code,
812
+ cellId,
813
+ }: {
814
+ cell: CellData | undefined;
815
+ code: string;
816
+ cellId: CellId;
817
+ }) => {
818
+ if (!cell) {
819
+ return createCell({
820
+ id: cellId,
821
+ code,
822
+ lastCodeRun: action.codeIsStale ? null : code,
823
+ edited: action.codeIsStale && code.trim().length > 0,
824
+ });
825
+ }
826
+
827
+ // If code is stale, we don't promote it to lastCodeRun
828
+ const lastCodeRun = action.codeIsStale ? cell.lastCodeRun : code;
829
+
830
+ // Mark as edited if the code has changed
831
+ const edited = lastCodeRun
832
+ ? lastCodeRun.trim() !== code.trim()
833
+ : Boolean(code);
834
+
835
+ // No change
836
+ if (cell.code.trim() === code.trim()) {
837
+ return {
838
+ ...cell,
839
+ code: code,
840
+ edited,
841
+ lastCodeRun,
842
+ };
843
+ }
844
+
845
+ // Update codemirror if mounted
846
+ // If RTC is enabled, the editor view will already be updated, so we don't need to do this
847
+ if (!isRtcEnabled()) {
848
+ const cellHandle = nextState.cellHandles[cellId].current;
849
+ if (cellHandle?.editorViewOrNull) {
850
+ updateEditorCodeFromPython(cellHandle.editorViewOrNull, code);
851
+ }
852
+ }
853
+
854
+ return {
855
+ ...cell,
856
+ code: code,
857
+ edited,
858
+ lastCodeRun,
859
+ };
860
+ };
861
+
862
+ for (const [cellId, code] of zip(action.ids, action.codes)) {
863
+ if (cellId === undefined || code === undefined) {
864
+ continue;
865
+ }
866
+ nextState = {
867
+ ...nextState,
868
+ cellData: {
869
+ ...nextState.cellData,
870
+ [cellId]: cellReducer({
871
+ cell: nextState.cellData[cellId],
872
+ code,
873
+ cellId,
874
+ }),
875
+ },
876
+ };
877
+ }
878
+
879
+ return nextState;
880
+ },
881
+ setStdinResponse: (
882
+ state,
883
+ action: { cellId: CellId; response: string; outputIndex: number },
884
+ ) => {
885
+ const { cellId, response, outputIndex } = action;
886
+ return updateCellRuntimeState({
887
+ state,
888
+ cellId,
889
+ cellReducer: (cell) => {
890
+ const consoleOutputs = [...cell.consoleOutputs];
891
+ const stdinOutput = consoleOutputs[outputIndex];
892
+ if (stdinOutput.channel !== "stdin") {
893
+ Logger.warn("Expected stdin output");
894
+ return cell;
895
+ }
896
+
897
+ consoleOutputs[outputIndex] = {
898
+ channel: "stdin",
899
+ mimetype: stdinOutput.mimetype,
900
+ data: stdinOutput.data,
901
+ timestamp: stdinOutput.timestamp,
902
+ response,
903
+ };
904
+
905
+ return {
906
+ ...cell,
907
+ interrupted: false,
908
+ consoleOutputs,
909
+ };
910
+ },
911
+ });
912
+ },
913
+ setCells: (state, cells: CellData[]) => {
914
+ const cellData = Object.fromEntries(cells.map((cell) => [cell.id, cell]));
915
+
916
+ const cellRuntime = Object.fromEntries(
917
+ cells.map((cell) => [cell.id, createCellRuntimeState()]),
918
+ );
919
+
920
+ return withScratchCell({
921
+ ...state,
922
+ cellIds: MultiColumn.fromIdsAndColumns(
923
+ cells.map((cell) => [cell.id, cell.config.column]),
924
+ ),
925
+ cellData: cellData,
926
+ cellRuntime: cellRuntime,
927
+ cellHandles: Object.fromEntries(
928
+ cells.map((cell) => [cell.id, createRef()]),
929
+ ),
930
+ });
931
+ },
932
+ /**
933
+ * Move focus to next cell
934
+ *
935
+ * Creates a new cell if the current cell is the last one in the array.
936
+ *
937
+ * If needed, scrolls newly created or focused cell into view.
938
+ *
939
+ * Replicates Shift+Enter functionality of Jupyter
940
+ */
941
+ moveToNextCell: (
942
+ state,
943
+ action: { cellId: CellId; before: boolean; noCreate?: boolean },
944
+ ) => {
945
+ const { cellId, before, noCreate = false } = action;
946
+
947
+ // Can't move focus of scratch cell
948
+ if (cellId === SCRATCH_CELL_ID) {
949
+ return state;
950
+ }
951
+
952
+ const column = state.cellIds.findWithId(cellId);
953
+ const index = column.indexOfOrThrow(cellId);
954
+ const nextCellIndex = before ? index - 1 : index + 1;
955
+
956
+ const isPastLastCell = nextCellIndex === column.length;
957
+ const isBeforeFirstCell = nextCellIndex === -1;
958
+
959
+ // Create a new cell at the end and set scrollKey to focus it
960
+ if (isPastLastCell && !noCreate) {
961
+ const newCellId = CellId.create();
962
+ return {
963
+ ...state,
964
+ cellIds: state.cellIds.insertId(newCellId, column.id, nextCellIndex),
965
+ cellData: {
966
+ ...state.cellData,
967
+ [newCellId]: createCell({ id: newCellId }),
968
+ },
969
+ cellRuntime: {
970
+ ...state.cellRuntime,
971
+ [newCellId]: createCellRuntimeState(),
972
+ },
973
+ cellHandles: {
974
+ ...state.cellHandles,
975
+ [newCellId]: createRef(),
976
+ },
977
+ scrollKey: newCellId,
978
+ };
979
+ }
980
+
981
+ if (isBeforeFirstCell && !noCreate) {
982
+ const newCellId = CellId.create();
983
+ return {
984
+ ...state,
985
+ cellIds: state.cellIds.insertId(newCellId, column.id, 0),
986
+ cellData: {
987
+ ...state.cellData,
988
+ [newCellId]: createCell({ id: newCellId }),
989
+ },
990
+ cellRuntime: {
991
+ ...state.cellRuntime,
992
+ [newCellId]: createCellRuntimeState(),
993
+ },
994
+ cellHandles: {
995
+ ...state.cellHandles,
996
+ [newCellId]: createRef(),
997
+ },
998
+ scrollKey: newCellId,
999
+ };
1000
+ }
1001
+
1002
+ if ((isPastLastCell || isBeforeFirstCell) && noCreate) {
1003
+ // Trying to move past the last cell or before the first cell
1004
+ // with noCreate=true - do nothing
1005
+ return state;
1006
+ }
1007
+
1008
+ if (nextCellIndex >= 0 && nextCellIndex < column.length) {
1009
+ // Move to valid cell within bounds
1010
+ const nextCellId = column.atOrThrow(nextCellIndex);
1011
+ // Just focus, no state change
1012
+ focusAndScrollCellIntoView({
1013
+ cellId: nextCellId,
1014
+ cell: state.cellHandles[nextCellId],
1015
+ isCodeHidden: isCellCodeHidden(state, nextCellId),
1016
+ codeFocus: before ? "bottom" : "top",
1017
+ variableName: undefined,
1018
+ });
1019
+ }
1020
+
1021
+ return state;
1022
+ },
1023
+ markTouched: (state, action: { cellId: CellId }) => {
1024
+ const { cellId } = action;
1025
+
1026
+ if (state.untouchedNewCells.has(cellId)) {
1027
+ const nextUntouchedNewCells = new Set(state.untouchedNewCells);
1028
+ nextUntouchedNewCells.delete(cellId);
1029
+ return {
1030
+ ...state,
1031
+ untouchedNewCells: nextUntouchedNewCells,
1032
+ };
1033
+ }
1034
+
1035
+ return state;
1036
+ },
1037
+ scrollToTarget: (state) => {
1038
+ // Scroll to the specified cell and clear the scroll key.
1039
+ const scrollKey = state.scrollKey;
1040
+ if (scrollKey === null) {
1041
+ return state;
1042
+ }
1043
+
1044
+ const column = state.cellIds.findWithId(scrollKey);
1045
+ const index = column.indexOfOrThrow(scrollKey);
1046
+
1047
+ const cellId =
1048
+ index === column.length - 1 ? column.last() : column.atOrThrow(index);
1049
+
1050
+ focusAndScrollCellIntoView({
1051
+ cellId: cellId,
1052
+ cell: state.cellHandles[cellId],
1053
+ isCodeHidden: isCellCodeHidden(state, cellId),
1054
+ codeFocus: undefined,
1055
+ variableName: undefined,
1056
+ });
1057
+
1058
+ return {
1059
+ ...state,
1060
+ scrollKey: null,
1061
+ };
1062
+ },
1063
+ foldAll: (state) => {
1064
+ const targets = Object.values(state.cellHandles).map(
1065
+ (handle) => handle.current?.editorView,
1066
+ );
1067
+ foldAllBulk(targets);
1068
+ return state;
1069
+ },
1070
+ unfoldAll: (state) => {
1071
+ const targets = Object.values(state.cellHandles).map(
1072
+ (handle) => handle.current?.editorView,
1073
+ );
1074
+ unfoldAllBulk(targets);
1075
+ return state;
1076
+ },
1077
+ clearLogs: (state) => {
1078
+ return {
1079
+ ...state,
1080
+ cellLogs: [],
1081
+ };
1082
+ },
1083
+ collapseCell: (state, action: { cellId: CellId }) => {
1084
+ const { cellId } = action;
1085
+ const column = state.cellIds.findWithId(cellId);
1086
+
1087
+ // Get all the top-level outlines
1088
+ const outlines = column.topLevelIds.map((id) => {
1089
+ const cell = state.cellRuntime[id];
1090
+ return cell.outline;
1091
+ });
1092
+
1093
+ // Find the start/end of the collapsed range
1094
+ const startIndex = column.indexOfOrThrow(cellId);
1095
+ const range = findCollapseRange(startIndex, outlines);
1096
+ if (!range) {
1097
+ return state;
1098
+ }
1099
+ const endCellId = column.atOrThrow(range[1]);
1100
+
1101
+ return {
1102
+ ...state,
1103
+ // Collapse the range
1104
+ cellIds: state.cellIds.transformWithCellId(cellId, (column) =>
1105
+ column.collapse(cellId, endCellId),
1106
+ ),
1107
+ scrollKey: cellId,
1108
+ };
1109
+ },
1110
+ expandCell: (state, action: { cellId: CellId }) => {
1111
+ const { cellId } = action;
1112
+ return {
1113
+ ...state,
1114
+ cellIds: state.cellIds.transformWithCellId(cellId, (column) =>
1115
+ column.expand(cellId),
1116
+ ),
1117
+ scrollKey: cellId,
1118
+ };
1119
+ },
1120
+ collapseAllCells: (state) => {
1121
+ return {
1122
+ ...state,
1123
+ cellIds: state.cellIds.transformAll((column) => {
1124
+ // Get all the top-level outlines
1125
+ const outlines = column.topLevelIds.map((id) => {
1126
+ const cell = state.cellRuntime[id];
1127
+ return cell.outline;
1128
+ });
1129
+
1130
+ // Find the start/end of the collapsed ranges
1131
+ const nodes = [...column.nodes];
1132
+ const rangeIndexes: Array<{
1133
+ start: CellIndex;
1134
+ end: CellIndex;
1135
+ }> = [];
1136
+ const reversedCollapseRanges = [];
1137
+
1138
+ // Iterate in reverse order (bottom-up) to process children first
1139
+ let i = nodes.length - 1;
1140
+ while (i >= 0) {
1141
+ const range = findCollapseRange(i, outlines);
1142
+ if (range) {
1143
+ const startIndex = i;
1144
+ let endIndex = range[1];
1145
+
1146
+ // Check if the parent's end point is inside any already-collapsed child range
1147
+ const parentEndInChild = rangeIndexes.find(
1148
+ (child) => child.start <= endIndex && child.end === endIndex,
1149
+ );
1150
+
1151
+ if (parentEndInChild) {
1152
+ // Adjust the new endIndex to the child's start
1153
+ endIndex = parentEndInChild.start;
1154
+ }
1155
+
1156
+ // Store this range for future child checks
1157
+ rangeIndexes.push({ start: startIndex, end: endIndex });
1158
+
1159
+ // Add the range to the list of ranges
1160
+ const cellId = column.atOrThrow(startIndex);
1161
+ const until = column.atOrThrow(endIndex);
1162
+ reversedCollapseRanges.push({ id: cellId, until });
1163
+ } else {
1164
+ reversedCollapseRanges.push(null);
1165
+ }
1166
+ i--;
1167
+ }
1168
+
1169
+ const collapseRanges = reversedCollapseRanges.reverse();
1170
+ return column.collapseAll(collapseRanges);
1171
+ }),
1172
+ };
1173
+ },
1174
+ expandAllCells: (state) => {
1175
+ return {
1176
+ ...state,
1177
+ cellIds: state.cellIds.transformAll((column) => column.expandAll()),
1178
+ };
1179
+ },
1180
+ showCellIfHidden: (state, action: { cellId: CellId }) => {
1181
+ const { cellId } = action;
1182
+ const column = state.cellIds.findWithId(cellId);
1183
+ const prev = column;
1184
+ const result = column.findAndExpandDeep(cellId);
1185
+
1186
+ if (result.equals(prev)) {
1187
+ return state;
1188
+ }
1189
+
1190
+ return {
1191
+ ...state,
1192
+ cellIds: state.cellIds.transformWithCellId(cellId, () => result),
1193
+ };
1194
+ },
1195
+ splitCell: (state, action: { cellId: CellId }) => {
1196
+ const { cellId } = action;
1197
+ const column = state.cellIds.findWithId(cellId);
1198
+ const index = column.indexOfOrThrow(cellId);
1199
+ const cell = state.cellData[cellId];
1200
+ const cellHandle = state.cellHandles[cellId].current;
1201
+
1202
+ if (cellHandle?.editorView == null) {
1203
+ return state;
1204
+ }
1205
+
1206
+ const { beforeCursorCode, afterCursorCode } = splitEditor(
1207
+ cellHandle.editorView,
1208
+ );
1209
+
1210
+ updateEditorCodeFromPython(cellHandle.editorView, beforeCursorCode);
1211
+
1212
+ const newCellId = CellId.create();
1213
+
1214
+ return {
1215
+ ...state,
1216
+ cellIds: state.cellIds.insertId(newCellId, column.id, index + 1),
1217
+ cellData: {
1218
+ ...state.cellData,
1219
+ [cellId]: {
1220
+ ...cell,
1221
+ code: beforeCursorCode,
1222
+ edited:
1223
+ Boolean(beforeCursorCode) &&
1224
+ beforeCursorCode.trim() !== cell.lastCodeRun?.trim(),
1225
+ },
1226
+ [newCellId]: createCell({
1227
+ id: newCellId,
1228
+ code: afterCursorCode,
1229
+ edited: Boolean(afterCursorCode),
1230
+ }),
1231
+ },
1232
+ cellRuntime: {
1233
+ ...state.cellRuntime,
1234
+ [cellId]: {
1235
+ ...state.cellRuntime[cellId],
1236
+ output: null,
1237
+ consoleOutputs: [],
1238
+ },
1239
+ [newCellId]: createCellRuntimeState(),
1240
+ },
1241
+ cellHandles: {
1242
+ ...state.cellHandles,
1243
+ [newCellId]: createRef(),
1244
+ },
1245
+ scrollKey: newCellId,
1246
+ };
1247
+ },
1248
+ undoSplitCell: (state, action: { cellId: CellId; snapshot: string }) => {
1249
+ const { cellId, snapshot } = action;
1250
+
1251
+ const cell = state.cellData[cellId];
1252
+ const cellHandle = state.cellHandles[cellId].current;
1253
+
1254
+ if (cellHandle?.editorView == null) {
1255
+ return state;
1256
+ }
1257
+
1258
+ updateEditorCodeFromPython(cellHandle.editorView, snapshot);
1259
+
1260
+ return {
1261
+ ...state,
1262
+ cellIds: state.cellIds.transformWithCellId(cellId, (column) => {
1263
+ const newCellIndex = column.indexOfOrThrow(cellId) + 1;
1264
+ return column.deleteAtIndex(newCellIndex);
1265
+ }),
1266
+ cellData: {
1267
+ ...state.cellData,
1268
+ [cellId]: {
1269
+ ...cell,
1270
+ code: snapshot,
1271
+ edited:
1272
+ Boolean(snapshot) && snapshot?.trim() !== cell.lastCodeRun?.trim(),
1273
+ },
1274
+ },
1275
+ cellRuntime: {
1276
+ ...state.cellRuntime,
1277
+ [cellId]: {
1278
+ ...state.cellRuntime[cellId],
1279
+ output: null,
1280
+ consoleOutputs: [],
1281
+ },
1282
+ },
1283
+ cellHandles: {
1284
+ ...state.cellHandles,
1285
+ },
1286
+ };
1287
+ },
1288
+ clearCellOutput: (state, action: { cellId: CellId }) => {
1289
+ const { cellId } = action;
1290
+ return updateCellRuntimeState({
1291
+ state,
1292
+ cellId,
1293
+ cellReducer: (cell) => ({
1294
+ ...cell,
1295
+ output: null,
1296
+ consoleOutputs: [],
1297
+ }),
1298
+ });
1299
+ },
1300
+ clearCellConsoleOutput: (state, action: { cellId: CellId }) => {
1301
+ const { cellId } = action;
1302
+ return updateCellRuntimeState({
1303
+ state,
1304
+ cellId,
1305
+ cellReducer: (cell) => ({
1306
+ ...cell,
1307
+ // Remove everything except unresponsed stdin
1308
+ consoleOutputs: cell.consoleOutputs.filter(
1309
+ (output) => output.channel === "stdin" && output.response == null,
1310
+ ),
1311
+ }),
1312
+ });
1313
+ },
1314
+ clearAllCellOutputs: (state) => {
1315
+ const newCellRuntime = { ...state.cellRuntime };
1316
+ for (const cellId of state.cellIds.inOrderIds) {
1317
+ newCellRuntime[cellId] = {
1318
+ ...newCellRuntime[cellId],
1319
+ output: null,
1320
+ consoleOutputs: [],
1321
+ };
1322
+ }
1323
+ return {
1324
+ ...state,
1325
+ cellRuntime: newCellRuntime,
1326
+ };
1327
+ },
1328
+ upsertSetupCell: (state, action: { code: string }) => {
1329
+ const { code } = action;
1330
+
1331
+ // First check if setup cell already exists
1332
+ if (SETUP_CELL_ID in state.cellData) {
1333
+ // Update existing setup cell
1334
+ return updateCellData({
1335
+ state,
1336
+ cellId: SETUP_CELL_ID,
1337
+ cellReducer: (cell) => ({
1338
+ ...cell,
1339
+ code,
1340
+ edited: code.trim() !== cell.lastCodeRun?.trim(),
1341
+ }),
1342
+ });
1343
+ }
1344
+
1345
+ return {
1346
+ ...state,
1347
+ cellIds: state.cellIds.insertId(
1348
+ SETUP_CELL_ID,
1349
+ state.cellIds.atOrThrow(0).id,
1350
+ 0,
1351
+ ),
1352
+ cellData: {
1353
+ ...state.cellData,
1354
+ [SETUP_CELL_ID]: createCell({
1355
+ id: SETUP_CELL_ID,
1356
+ name: SETUP_CELL_ID,
1357
+ code,
1358
+ edited: Boolean(code),
1359
+ }),
1360
+ },
1361
+ cellRuntime: {
1362
+ ...state.cellRuntime,
1363
+ [SETUP_CELL_ID]: createCellRuntimeState(),
1364
+ },
1365
+ cellHandles: {
1366
+ ...state.cellHandles,
1367
+ [SETUP_CELL_ID]: createRef(),
1368
+ },
1369
+ };
1370
+ },
1371
+ });
1372
+
1373
+ function isCellCodeHidden(state: NotebookState, cellId: CellId): boolean {
1374
+ return (
1375
+ state.cellData[cellId].config.hide_code &&
1376
+ !state.untouchedNewCells.has(cellId)
1377
+ );
1378
+ }
1379
+
1380
+ // Helper function to update a cell in the array
1381
+ function updateCellRuntimeState({
1382
+ state,
1383
+ cellId,
1384
+ cellReducer,
1385
+ }: {
1386
+ state: NotebookState;
1387
+ cellId: CellId;
1388
+ cellReducer: ReducerWithoutAction<CellRuntimeState>;
1389
+ }) {
1390
+ if (!(cellId in state.cellRuntime)) {
1391
+ Logger.warn(`Cell ${cellId} not found in state`);
1392
+ return state;
1393
+ }
1394
+
1395
+ return {
1396
+ ...state,
1397
+ cellRuntime: {
1398
+ ...state.cellRuntime,
1399
+ [cellId]: cellReducer(state.cellRuntime[cellId]),
1400
+ },
1401
+ };
1402
+ }
1403
+
1404
+ function updateCellData({
1405
+ state,
1406
+ cellId,
1407
+ cellReducer,
1408
+ }: {
1409
+ state: NotebookState;
1410
+ cellId: CellId;
1411
+ cellReducer: ReducerWithoutAction<CellData>;
1412
+ }) {
1413
+ if (!(cellId in state.cellData)) {
1414
+ Logger.warn(`Cell ${cellId} not found in state`);
1415
+ return state;
1416
+ }
1417
+
1418
+ return {
1419
+ ...state,
1420
+ cellData: {
1421
+ ...state.cellData,
1422
+ [cellId]: cellReducer(state.cellData[cellId]),
1423
+ },
1424
+ };
1425
+ }
1426
+
1427
+ export function getCellConfigs(state: NotebookState): CellConfig[] {
1428
+ const cells = state.cellData;
1429
+
1430
+ // We set to null by default to prevent inconsistencies between undefined & null
1431
+ const defaultCellConfig: Partial<CellConfig> = { column: null };
1432
+
1433
+ // Handle the case where there's only one column
1434
+ // We don't want to set the column config
1435
+ const hasMultipleColumns = state.cellIds.getColumns().length > 1;
1436
+ if (!hasMultipleColumns) {
1437
+ return state.cellIds.getColumns().flatMap((column) => {
1438
+ return column.inOrderIds.map((cellId) => {
1439
+ return {
1440
+ ...cells[cellId].config,
1441
+ ...defaultCellConfig,
1442
+ };
1443
+ });
1444
+ });
1445
+ }
1446
+
1447
+ return state.cellIds.getColumns().flatMap((column, columnIndex) => {
1448
+ return column.inOrderIds.map((cellId, cellIndex) => {
1449
+ const config: Partial<CellConfig> = { ...defaultCellConfig };
1450
+
1451
+ // Only set the column index for the first cell in the column
1452
+ if (cellIndex === 0) {
1453
+ config.column = columnIndex;
1454
+ }
1455
+
1456
+ const newConfig = {
1457
+ ...cells[cellId].config,
1458
+ ...config,
1459
+ };
1460
+
1461
+ return newConfig;
1462
+ });
1463
+ });
1464
+ }
1465
+
1466
+ export {
1467
+ createActions as createNotebookActions,
1468
+ reducer as notebookReducer,
1469
+ notebookAtom,
1470
+ };
1471
+
1472
+ /// ATOMS
1473
+
1474
+ export const cellIdsAtom = atom((get) => get(notebookAtom).cellIds);
1475
+
1476
+ export const hasOnlyOneCellAtom = atom((get) =>
1477
+ get(cellIdsAtom).hasOnlyOneId(),
1478
+ );
1479
+
1480
+ export const hasDisabledCellsAtom = atom(
1481
+ (get) => disabledCellIds(get(notebookAtom)).length > 0,
1482
+ );
1483
+ export const hasEnabledCellsAtom = atom(
1484
+ (get) => enabledCellIds(get(notebookAtom)).length > 0,
1485
+ );
1486
+ export const canUndoDeletesAtom = atom((get) =>
1487
+ canUndoDeletes(get(notebookAtom)),
1488
+ );
1489
+
1490
+ export const needsRunAtom = atom((get) => notebookNeedsRun(get(notebookAtom)));
1491
+
1492
+ const cellErrorsAtom = atom((get) => {
1493
+ const { cellIds, cellRuntime, cellData } = get(notebookAtom);
1494
+ const errors = cellIds.inOrderIds
1495
+ .map((cellId) => {
1496
+ const cell = cellRuntime[cellId];
1497
+ const { name } = cellData[cellId];
1498
+ if (isErrorMime(cell.output?.mimetype)) {
1499
+ // Filter out ancestor-stopped errors
1500
+ // These are errors that are caused by a cell that was stopped,
1501
+ // but nothing the user can take action on.
1502
+ invariant(Array.isArray(cell.output.data), "Expected array data");
1503
+ const nonAncestorErrors = cell.output.data.filter(
1504
+ (error) => !error.type.includes("ancestor"),
1505
+ );
1506
+
1507
+ if (nonAncestorErrors.length > 0) {
1508
+ return {
1509
+ output: { ...cell.output, data: nonAncestorErrors },
1510
+ cellId: cellId,
1511
+ cellName: name,
1512
+ };
1513
+ }
1514
+ }
1515
+
1516
+ return null;
1517
+ })
1518
+ .filter(Boolean);
1519
+ return errors;
1520
+ });
1521
+
1522
+ export const notebookOutline = atom((get) => {
1523
+ const { cellIds, cellRuntime } = get(notebookAtom);
1524
+ const outlines = cellIds.inOrderIds.map(
1525
+ (cellId) => cellRuntime[cellId].outline,
1526
+ );
1527
+ return mergeOutlines(outlines);
1528
+ });
1529
+
1530
+ export const cellErrorCount = atom((get) => get(cellErrorsAtom).length);
1531
+
1532
+ export const cellIdToNamesMap = createDeepEqualAtom(
1533
+ atom((get) => {
1534
+ const { cellIds, cellData } = get(notebookAtom);
1535
+ const names: Record<CellId, string | undefined> = Objects.fromEntries(
1536
+ cellIds.inOrderIds.map((cellId) => [cellId, cellData[cellId]?.name]),
1537
+ );
1538
+ return names;
1539
+ }),
1540
+ );
1541
+
1542
+ const scrollKeyAtom = atom((get) => get(notebookAtom).scrollKey);
1543
+
1544
+ /// HOOKS
1545
+
1546
+ /**
1547
+ * React-hook for the array of cells.
1548
+ */
1549
+ export const useNotebook = () => useAtomValue(notebookAtom);
1550
+
1551
+ /**
1552
+ * React-hook for the array of cell IDs.
1553
+ */
1554
+ export const useCellIds = () => useAtomValue(cellIdsAtom);
1555
+
1556
+ /**
1557
+ * React-hook for the dictionary of cell names
1558
+ */
1559
+ export const useCellNames = () => useAtomValue(cellIdToNamesMap);
1560
+
1561
+ /**
1562
+ * React-hook for the array of cell errors.
1563
+ */
1564
+ export const useCellErrors = () => useAtomValue(cellErrorsAtom);
1565
+
1566
+ /**
1567
+ * React-hook for the cell logs.
1568
+ */
1569
+ export const useCellLogs = () => useAtomValue(notebookAtom).cellLogs;
1570
+
1571
+ /**
1572
+ * React-hook for the notebook scrollKey
1573
+ */
1574
+ export const useScrollKey = () => useAtomValue(scrollKeyAtom);
1575
+
1576
+ /// IMPERATIVE GETTERS
1577
+
1578
+ /**
1579
+ * Get the array of cell IDs.
1580
+ */
1581
+ export const getNotebook = () => store.get(notebookAtom);
1582
+
1583
+ /**
1584
+ * Get the array of cell IDs.
1585
+ */
1586
+ export const getCells = () => store.get(notebookAtom).cellIds;
1587
+
1588
+ /**
1589
+ * Get the array of cell names
1590
+ */
1591
+ export const getCellNames = () => {
1592
+ const { cellIds, cellData } = store.get(notebookAtom);
1593
+ return cellIds.inOrderIds.map((id) => cellData[id]?.name).filter(Boolean);
1594
+ };
1595
+
1596
+ const cellDataAtoms = splitAtom(
1597
+ selectAtom(notebookAtom, (cells) =>
1598
+ cells.cellIds.inOrderIds.map((id) => cells.cellData[id]),
1599
+ ),
1600
+ );
1601
+ export const useCellDataAtoms = () => useAtom(cellDataAtoms);
1602
+
1603
+ export const notebookIsRunningAtom = atom((get) =>
1604
+ notebookIsRunning(get(notebookAtom)),
1605
+ );
1606
+ export const notebookQueuedOrRunningCountAtom = atom((get) =>
1607
+ notebookQueueOrRunningCount(get(notebookAtom)),
1608
+ );
1609
+
1610
+ export const numColumnsAtom = atom(
1611
+ (get) => get(notebookAtom).cellIds.colLength,
1612
+ );
1613
+ export const hasCellsAtom = atom(
1614
+ (get) => get(notebookAtom).cellIds.idLength > 0,
1615
+ );
1616
+ export const columnIdsAtom = atom((get) =>
1617
+ get(notebookAtom).cellIds.getColumnIds(),
1618
+ );
1619
+
1620
+ const cellDataAtom = atomFamily((cellId: CellId) =>
1621
+ atom((get) => get(notebookAtom).cellData[cellId]),
1622
+ );
1623
+ const cellRuntimeAtom = atomFamily((cellId: CellId) =>
1624
+ atom((get) => get(notebookAtom).cellRuntime[cellId]),
1625
+ );
1626
+ const cellHandleAtom = atomFamily((cellId: CellId) =>
1627
+ atom((get) => get(notebookAtom).cellHandles[cellId]),
1628
+ );
1629
+ /**
1630
+ * Cleans up atomFamily cache entries for the given cell.
1631
+ *
1632
+ * Jotai's atomFamily retains a cache of created atoms, which can cause memory leaks
1633
+ * if not explicitly removed. This function removes the atoms associated with a specific
1634
+ * cellId to free up memory.
1635
+ *
1636
+ * @param cellId - The cell ID whose atoms should be removed.
1637
+ * @see https://jotai.org/docs/utilities/family#caveat-memory-leaks
1638
+ */
1639
+ export function releaseCellAtoms(cellId: CellId) {
1640
+ cellDataAtom.remove(cellId);
1641
+ cellRuntimeAtom.remove(cellId);
1642
+ cellHandleAtom.remove(cellId);
1643
+ }
1644
+
1645
+ /** Subscribes to reactive updates of the cell's data. */
1646
+ export const useCellData = (cellId: CellId) =>
1647
+ useAtomValue(cellDataAtom(cellId));
1648
+ /** Subscribes to reactive updates of the cell's runtime info. */
1649
+ export const useCellRuntime = (cellId: CellId) =>
1650
+ useAtomValue(cellRuntimeAtom(cellId));
1651
+ /** Subscribes to reactive updates of the cell's handle (e.g. refs or UI bindings). */
1652
+ export const useCellHandle = (cellId: CellId) =>
1653
+ useAtomValue(cellHandleAtom(cellId));
1654
+
1655
+ /**
1656
+ * Get the editor views for all cells.
1657
+ */
1658
+ export const getAllEditorViews = () => {
1659
+ const { cellIds, cellHandles } = store.get(notebookAtom);
1660
+ return cellIds.inOrderIds
1661
+ .map((cellId) => cellHandles[cellId]?.current?.editorViewOrNull)
1662
+ .filter(Boolean);
1663
+ };
1664
+
1665
+ export const getCellEditorView = (cellId: CellId) => {
1666
+ const { cellHandles } = store.get(notebookAtom);
1667
+ return cellHandles[cellId].current?.editorView;
1668
+ };
1669
+
1670
+ export function flattenTopLevelNotebookCells(
1671
+ state: NotebookState,
1672
+ ): Array<CellData & CellRuntimeState> {
1673
+ const { cellIds, cellData, cellRuntime } = state;
1674
+ return cellIds.getColumns().flatMap((column) =>
1675
+ column.topLevelIds.map((cellId) => ({
1676
+ ...cellData[cellId],
1677
+ ...cellRuntime[cellId],
1678
+ })),
1679
+ );
1680
+ }
1681
+
1682
+ export function createUntouchedCellAtom(cellId: CellId): Atom<boolean> {
1683
+ return atom((get) => get(notebookAtom).untouchedNewCells.has(cellId));
1684
+ }
1685
+
1686
+ export function createTracebackInfoAtom(
1687
+ cellId: CellId,
1688
+ ): Atom<TracebackInfo[] | undefined> {
1689
+ // We create an intermediate atom that just computes the string
1690
+ // so it prevents downstream recomputations.
1691
+ const tracebackStringAtom = atom<string | undefined>((get) => {
1692
+ const notebook = get(notebookAtom);
1693
+ const data = notebook.cellRuntime[cellId];
1694
+ if (!data) {
1695
+ return undefined;
1696
+ }
1697
+ // Must be errored and idle
1698
+ if (data.status !== "idle") {
1699
+ return undefined;
1700
+ }
1701
+ const outputs = data.consoleOutputs;
1702
+ // console.warn(notebook);
1703
+ if (!outputs || outputs.length === 0) {
1704
+ return undefined;
1705
+ }
1706
+
1707
+ const firstTraceback = outputs.find(
1708
+ (output) => output.mimetype === "application/vnd.marimo+traceback",
1709
+ );
1710
+ if (!firstTraceback) {
1711
+ return undefined;
1712
+ }
1713
+ const traceback = firstTraceback.data;
1714
+ return traceback as string;
1715
+ });
1716
+
1717
+ return atom((get) => {
1718
+ const traceback = get(tracebackStringAtom);
1719
+ if (!traceback) {
1720
+ return undefined;
1721
+ }
1722
+ return extractAllTracebackInfo(traceback);
1723
+ });
1724
+ }
1725
+
1726
+ /**
1727
+ * Use this hook to dispatch cell actions. This hook will not cause a re-render
1728
+ * when cells change.
1729
+ */
1730
+ export function useCellActions(): CellActions {
1731
+ return useActions();
1732
+ }
1733
+
1734
+ /**
1735
+ * Map of cell actions
1736
+ */
1737
+ export type CellActions = ReturnType<typeof createActions>;
1738
+
1739
+ /**
1740
+ * This is exported for testing purposes only.
1741
+ */
1742
+ export const exportedForTesting = {
1743
+ reducer,
1744
+ createActions,
1745
+ initialNotebookState,
1746
+ isCellCodeHidden,
1747
+ // Export atom families for testing cleanup
1748
+ cellDataAtom,
1749
+ cellRuntimeAtom,
1750
+ cellHandleAtom,
1751
+ };