@marimo-team/frontend 0.25.3-dev129 → 0.25.3-dev134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dist/assets/{CellStatus-6xDEj3Hs.js → CellStatus-DC6FFQOg.js} +1 -1
  2. package/dist/assets/{ConnectedDataExplorerComponent-DCcLAktu.js → ConnectedDataExplorerComponent-BV1mVpaE.js} +1 -1
  3. package/dist/assets/{ErrorBoundary-98Xo04DS.js → ErrorBoundary-Ce-Ujlwj.js} +2 -2
  4. package/dist/assets/{JsonOutput-V47aiTIK.js → JsonOutput-CfEBzaqW.js} +4 -4
  5. package/dist/assets/{MarimoErrorOutput-DeWZNBgL.js → MarimoErrorOutput-Bh6o9zle.js} +1 -1
  6. package/dist/assets/{RenderHTML-Bjvcs70-.js → RenderHTML-COGZsXQV.js} +1 -1
  7. package/dist/assets/{RunButton-CnvvXD9d.js → RunButton-DQ51plUv.js} +1 -1
  8. package/dist/assets/{add-cell-with-ai-BbuqzITi.js → add-cell-with-ai-D7gtGUsg.js} +1 -1
  9. package/dist/assets/{add-connection-dialog-DIC7owvZ.js → add-connection-dialog-CpMCc97S.js} +1 -1
  10. package/dist/assets/{agent-panel-D8hO2P1x.js → agent-panel-BSFYqJ9B.js} +2 -2
  11. package/dist/assets/{ai-model-dropdown-DgmiG_5j.js → ai-model-dropdown-D575Vid8.js} +3 -3
  12. package/dist/assets/{app-config-button-UZHv1Iim.js → app-config-button-Cfcg_5Bz.js} +1 -1
  13. package/dist/assets/{blob-BPknzzkY.js → blob-CszMu60N.js} +1 -1
  14. package/dist/assets/{cell-editor-CM-K1_wq.js → cell-editor-BLpOlLnM.js} +2 -2
  15. package/dist/assets/cell-link-Cj0gGaMV.js +1 -0
  16. package/dist/assets/{cells-BypTg035.js → cells-SvbLY10y.js} +1 -1
  17. package/dist/assets/{chat-display-BRLNOoTF.js → chat-display-D43_g3TX.js} +1 -1
  18. package/dist/assets/{chat-panel-D02Rk9we.js → chat-panel-B_HAJMwx.js} +1 -1
  19. package/dist/assets/{chat-ui-DFN_RwxF.js → chat-ui-BEcYCphu.js} +2 -2
  20. package/dist/assets/{column-preview-85ORMhfB.js → column-preview-CrzaJKk8.js} +1 -1
  21. package/dist/assets/{command-palette-CtyjjdsA.js → command-palette-Bm9yIVcD.js} +1 -1
  22. package/dist/assets/{common-J265II7i.js → common-BJyUxCzv.js} +1 -1
  23. package/dist/assets/{components-Bd3Dpi92.js → components-D1f_Cz4i.js} +1 -1
  24. package/dist/assets/{datasource-Dy4rzzSP.js → datasource-C8KSVfSD.js} +1 -1
  25. package/dist/assets/{dependency-graph-panel-ByGFFT4E.js → dependency-graph-panel-BhmyJbUl.js} +1 -1
  26. package/dist/assets/{documentation-panel-LxuJCY3M.js → documentation-panel-DcVG0Q0d.js} +1 -1
  27. package/dist/assets/{download-BsBJWH_j.js → download-Bx52VRE4.js} +1 -1
  28. package/dist/assets/{edit-page--d6X-OO9.js → edit-page-DUrwOHR-.js} +6 -6
  29. package/dist/assets/{error-entries-0wTSSuK9.js → error-entries-11OuHzUF.js} +1 -1
  30. package/dist/assets/{error-panel-ZNdbE3Fo.js → error-panel-XJy5S25F.js} +1 -1
  31. package/dist/assets/{feedback-button-C6asPmsh.js → feedback-button-B7jh_B4w.js} +1 -1
  32. package/dist/assets/feedback-button-C-eKtxXE.js +1 -0
  33. package/dist/assets/{file-explorer-panel-0fUP_ptL.js → file-explorer-panel-CnVxbF4A.js} +1 -1
  34. package/dist/assets/{file-name-input-B8lzI5iS.js → file-name-input-BJuqjQqH.js} +2 -2
  35. package/dist/assets/floating-outline-8yyZ-MOJ.js +1 -0
  36. package/dist/assets/{gallery-page-ClR8U-km.js → gallery-page-DJvGHePf.js} +1 -1
  37. package/dist/assets/{glide-data-editor-B6QQBQwS.js → glide-data-editor-Cyc8DHZx.js} +1 -1
  38. package/dist/assets/{home-page-CJnqDcT9.js → home-page-tRZJmSU6.js} +1 -1
  39. package/dist/assets/{hooks-CCek4i9f.js → hooks-CxGwybGw.js} +1 -1
  40. package/dist/assets/index-CoxbqhGH.js +30 -0
  41. package/dist/assets/index-u08m0hQE.css +2 -0
  42. package/dist/assets/{layout-66Urh4Zg.js → layout-DvXJxBiL.js} +5 -5
  43. package/dist/assets/{logs-panel-DFhkIcge.js → logs-panel-KtsY7TrR.js} +1 -1
  44. package/dist/assets/{markdown-renderer-mYYQYD2m.js → markdown-renderer-DUgV7_fm.js} +1 -1
  45. package/dist/assets/{name-cell-input-Crcu3i2z.js → name-cell-input-C3-Cj-Ek.js} +1 -1
  46. package/dist/assets/{outline-panel-BFIPK0H_.js → outline-panel-BzyY4JA6.js} +1 -1
  47. package/dist/assets/{packages-panel-B4KtjgkF.js → packages-panel-DxosbWko.js} +1 -1
  48. package/dist/assets/{panel-accordion-state-D6KtwSF8.js → panel-accordion-state-BRbTib2B.js} +1 -1
  49. package/dist/assets/panels-Da3071Q4.js +1 -0
  50. package/dist/assets/{process-output-DDvMd6Jh.js → process-output-CSwx7rvo.js} +1 -1
  51. package/dist/assets/{readonly-code-display-VDqYn2d0.js → readonly-code-display-B9y9423Y.js} +1 -1
  52. package/dist/assets/{readonly-python-code-CZUKLXJ4.js → readonly-python-code-Dgw6trlk.js} +1 -1
  53. package/dist/assets/{reveal-component-BMmDU1uN.js → reveal-component-B9A4wkG-.js} +1 -1
  54. package/dist/assets/{run-page-BmOPPh2Y.js → run-page-C1MQ5b_A.js} +1 -1
  55. package/dist/assets/{runtime-details-state-CipqynUD.js → runtime-details-state-D_hOQL9T.js} +1 -1
  56. package/dist/assets/scratchpad-panel-CBCsPmMW.js +1 -0
  57. package/dist/assets/secrets-panel-ConQpchl.js +1 -0
  58. package/dist/assets/session-panel-CiHCKPlx.js +1 -0
  59. package/dist/assets/snippets-panel-C0VDE_4i.js +1 -0
  60. package/dist/assets/{state-QfGh3m2G.js → state-DrraMmqz.js} +1 -1
  61. package/dist/assets/{state-BLGvzMB6.js → state-DvU2AiFx.js} +22 -22
  62. package/dist/assets/tracing-C5d51Nmi.js +1 -0
  63. package/dist/assets/{tracing-panel-CsHuzRGP.js → tracing-panel-B89R8dWE.js} +2 -2
  64. package/dist/assets/{tree-actions-BQw_utcj.js → tree-actions-Cph8FVzh.js} +1 -1
  65. package/dist/assets/{useAddCell-_b8InOZC.js → useAddCell-VPkB72pn.js} +1 -1
  66. package/dist/assets/{useCellActionButton-BbgMzBdk.js → useCellActionButton--zI3GFnt.js} +1 -1
  67. package/dist/assets/{useDeleteCell-DhoFbEkU.js → useDeleteCell-CjewKeSr.js} +1 -1
  68. package/dist/assets/{useDependencyPanelTab-COTULhoH.js → useDependencyPanelTab-Bt_ka-wl.js} +1 -1
  69. package/dist/assets/{useNotebookActions-xnA_l3nY.js → useNotebookActions-DV2S6KaG.js} +1 -1
  70. package/dist/assets/{useRunCells-VBCe6CLn.js → useRunCells-BupCZpzk.js} +1 -1
  71. package/dist/assets/{useSplitCell-AvSpVAmq.js → useSplitCell-CaLIR0TS.js} +1 -1
  72. package/dist/index.html +21 -21
  73. package/package.json +1 -1
  74. package/src/__tests__/module-entry.test.ts +32 -0
  75. package/src/components/ai/__tests__/ai-model-dropdown.test.tsx +63 -0
  76. package/src/components/ai/ai-model-dropdown.tsx +11 -6
  77. package/src/components/chat/acp/__tests__/session-tabs.test.tsx +43 -0
  78. package/src/components/chat/acp/blocks.tsx +1 -0
  79. package/src/components/chat/acp/session-tabs.tsx +8 -3
  80. package/src/components/data-table/TableTopBar.tsx +2 -0
  81. package/src/components/data-table/__tests__/data-table.test.tsx +1 -0
  82. package/src/components/data-table/__tests__/keyboard-selection.test.tsx +188 -0
  83. package/src/components/data-table/data-table.tsx +6 -0
  84. package/src/components/data-table/range-focus/atoms.ts +4 -6
  85. package/src/components/data-table/range-focus/use-cell-range-selection.ts +65 -38
  86. package/src/components/data-table/range-focus/use-scroll-into-view.ts +21 -2
  87. package/src/components/data-table/renderers.tsx +16 -7
  88. package/src/components/data-table/row-viewer-panel/__tests__/row-viewer.test.tsx +24 -1
  89. package/src/components/data-table/row-viewer-panel/row-viewer.tsx +2 -2
  90. package/src/components/datasources/datasources.tsx +1 -0
  91. package/src/components/editor/__tests__/package-alert.test.tsx +22 -1
  92. package/src/components/editor/cell/collapse.tsx +5 -3
  93. package/src/components/editor/chrome/panels/outline/__tests__/outline-keyboard.test.tsx +84 -0
  94. package/src/components/editor/chrome/panels/outline/floating-outline.tsx +39 -14
  95. package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +3 -2
  96. package/src/components/editor/chrome/panels/secrets-panel.tsx +1 -0
  97. package/src/components/editor/chrome/panels/snippets-panel.tsx +5 -1
  98. package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +4 -4
  99. package/src/components/editor/controls/__tests__/keyboard-shortcuts.test.tsx +61 -0
  100. package/src/components/editor/controls/keyboard-shortcuts.tsx +14 -5
  101. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +4 -4
  102. package/src/components/editor/file-tree/__tests__/file-explorer-navigation.test.tsx +47 -0
  103. package/src/components/editor/file-tree/file-explorer.tsx +35 -3
  104. package/src/components/editor/file-tree/file-name-input.tsx +1 -0
  105. package/src/components/editor/header/status.tsx +28 -5
  106. package/src/components/editor/links/__tests__/cell-link.test.tsx +146 -0
  107. package/src/components/editor/links/cell-link.tsx +14 -5
  108. package/src/components/editor/navigation/focus-utils.ts +4 -4
  109. package/src/components/editor/notebook-cell.tsx +11 -2
  110. package/src/components/editor/output/MarimoTracebackOutput.tsx +17 -15
  111. package/src/components/editor/output/__tests__/traceback.test.tsx +27 -1
  112. package/src/components/editor/package-alert.tsx +8 -3
  113. package/src/components/scratchpad/scratchpad.test.tsx +95 -0
  114. package/src/components/scratchpad/scratchpad.tsx +14 -1
  115. package/src/components/tracing/tracing-keyboard.test.tsx +85 -0
  116. package/src/components/tracing/tracing.tsx +43 -39
  117. package/src/components/ui/__tests__/draggable-popover.test.tsx +24 -0
  118. package/src/components/ui/draggable-popover.tsx +24 -2
  119. package/src/core/attachments/state.ts +2 -2
  120. package/src/core/document/__tests__/codemirror.test.ts +3 -1
  121. package/src/core/document/__tests__/hooks.test.tsx +7 -7
  122. package/src/core/document/__tests__/model.test.ts +44 -11
  123. package/src/core/document/__tests__/scenario-fixture.ts +2 -1
  124. package/src/core/document/__tests__/test-notebook.ts +19 -9
  125. package/src/core/document/draft.ts +1 -1
  126. package/src/core/document/index.ts +3 -10
  127. package/src/core/document/model.ts +14 -11
  128. package/src/core/document/state.ts +1 -1
  129. package/src/core/document/sync.ts +24 -18
  130. package/src/core/host/AGENTS.md +3 -7
  131. package/src/core/host/__tests__/fixtures.ts +30 -0
  132. package/src/core/host/__tests__/{notebook-client.test.ts → replica.test.ts} +42 -74
  133. package/src/core/host/__tests__/wasm.test.ts +8 -0
  134. package/src/core/host/backend.ts +4 -0
  135. package/src/core/host/index.ts +14 -0
  136. package/src/core/host/{notebook-client.ts → replica.ts} +75 -86
  137. package/src/core/host/static.ts +2 -0
  138. package/src/core/host/wasm.ts +10 -1
  139. package/src/core/wasm/bridge.ts +1 -1
  140. package/src/core/websocket/__tests__/backend.test.ts +111 -22
  141. package/src/core/websocket/__tests__/useNotebookReplica.hook.test.tsx +141 -0
  142. package/src/core/websocket/__tests__/useNotebookSession.hook.test.tsx +4 -4
  143. package/src/core/websocket/backend.ts +43 -5
  144. package/src/core/websocket/connection-state.ts +1 -1
  145. package/src/core/websocket/state.ts +3 -3
  146. package/src/core/websocket/transports/__tests__/notebook.test.ts +11 -21
  147. package/src/core/websocket/types.ts +2 -2
  148. package/src/core/websocket/useNotebookReplica.ts +69 -0
  149. package/src/core/websocket/useNotebookSession.tsx +6 -6
  150. package/src/plugins/impl/chat/chat-ui.tsx +2 -1
  151. package/src/plugins/impl/data-explorer/components/column-summary.tsx +4 -2
  152. package/src/plugins/impl/data-frames/__tests__/sidebar.test.tsx +160 -0
  153. package/src/plugins/impl/data-frames/panel.tsx +43 -16
  154. package/dist/assets/cell-link-CAjuFcLK.js +0 -1
  155. package/dist/assets/feedback-button-Bt89tGG2.js +0 -1
  156. package/dist/assets/floating-outline-CRpmOv32.js +0 -1
  157. package/dist/assets/index-B5pWkt7a.js +0 -30
  158. package/dist/assets/index-BnhSnwvB.css +0 -2
  159. package/dist/assets/panels-DiwGKPzK.js +0 -1
  160. package/dist/assets/scratchpad-panel-Drr_kuwb.js +0 -1
  161. package/dist/assets/secrets-panel-D-W1PL76.js +0 -1
  162. package/dist/assets/session-panel-W7JOcog_.js +0 -1
  163. package/dist/assets/snippets-panel-cUPEdm66.js +0 -1
  164. package/dist/assets/tracing-BNFynaTu.js +0 -1
  165. package/src/core/websocket/__tests__/useNotebookClient.hook.test.tsx +0 -228
  166. package/src/core/websocket/useNotebookClient.ts +0 -89
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t}from"./useEvent-BDjgaBtz.js";import{t as n}from"./react-DVplv7_D.js";import{$t as r,Bn as i,En as a,On as o,Xt as s,Yt as c,Zt as l,cn as u,dn as d,en as f,nn as p,tn as m,un as h}from"./cells-BypTg035.js";import{t as g}from"./compiler-runtime-BrajqUja.js";import{D as _,O as v,S as y}from"./config-CXnC3MRv.js";import{M as b}from"./config-7IjqNuVp.js";import{t as x}from"./jsx-runtime-B74pBk57.js";import{o as S}from"./alert-dialog-8YiYLrfr.js";import{l as C}from"./select-CgWQvW1F.js";import{c as w}from"./switch-D2gdC_ep.js";import{t as T}from"./tooltip-B5lAA_jn.js";import{t as E}from"./button-Cl7haVNh.js";import{t as D}from"./createLucideIcon-DfJ2oMlA.js";import{d as O,f as k,i as A,k as j,n as M,u as N}from"./ai-model-dropdown-DgmiG_5j.js";import{r as P}from"./useNumberFormatter-D7O_26UI.js";import{b as F,p as I}from"./write-secret-modal-CBi2vNK_.js";import{Jt as L,Yt as R,nn as ee,r as z,tn as B}from"./input-DLA5Dhn3.js";import{t as V}from"./settings-BpdQZRgT.js";import{t as te}from"./use-toast-Wu434mLr.js";import{s as H}from"./arrays-0R2reF2y.js";import{r as U}from"./requests-BIFR-h4M.js";import{r as ne}from"./useDebounce-DwTQ_1Pu.js";import{t as W}from"./kbd-pdKBv96t.js";import{t as G}from"./Inputs-BsQm29hD.js";var K=D(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),q=g(),J=x(),Y=e=>{let t=(0,q.c)(15),{description:n,disabled:r,tooltip:i}=e,a=r!==void 0&&r,o=i===void 0?`Shutdown`:i,{openConfirm:s,closeModal:c}=F(),{sendShutdown:l}=U(),u;t[0]===l?u=t[1]:(u=()=>{l(),setTimeout(X,200)},t[0]=l,t[1]=u);let d=u;if(b())return null;let f=a?`disabled`:`red`,p;t[2]!==c||t[3]!==n||t[4]!==d||t[5]!==s?(p=e=>{e.stopPropagation(),s({title:`Shutdown`,description:n,variant:`destructive`,confirmAction:(0,J.jsx)(S,{onClick:()=>{d(),c()},"aria-label":`Confirm Shutdown`,children:`Shutdown`})})},t[2]=c,t[3]=n,t[4]=d,t[5]=s,t[6]=p):p=t[6];let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(P,{strokeWidth:1}),t[7]=m):m=t[7];let h;t[8]!==a||t[9]!==f||t[10]!==p?(h=(0,J.jsx)(G,{"aria-label":`Shutdown`,"data-testid":`shutdown-button`,shape:`circle`,size:`small`,color:f,className:`h-[27px] w-[27px]`,disabled:a,onClick:p,children:m}),t[8]=a,t[9]=f,t[10]=p,t[11]=h):h=t[11];let g;return t[12]!==h||t[13]!==o?(g=(0,J.jsx)(T,{content:o,children:h}),t[12]=h,t[13]=o,t[14]=g):g=t[14],g};function X(){window.close()}var Z=e(n(),1),re=100,ie=()=>{let e=(0,q.c)(37),[t,n]=y(),{saveAppConfig:u}=U(),d=(0,Z.useId)(),h=(0,Z.useId)(),g;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=a(_),e[0]=g):g=e[0];let v;e[1]===t?v=e[2]:(v={resolver:g,defaultValues:t},e[1]=t,e[2]=v);let b=o(v),x;e[3]!==u||e[4]!==n?(x=async e=>{await u({config:e}).then(()=>{n(e)}).catch(()=>{n(e)})},e[3]=u,e[4]=n,e[5]=x):x=e[5];let S=x,C;e[6]===S?C=e[7]:(C=e=>{S(e)},e[6]=S,e[7]=C);let w=ne(C,re),T;e[8]===t.width?T=e[9]:(T=[t.width],e[8]=t.width,e[9]=T),(0,Z.useEffect)(ae,T);let E;e[10]!==w||e[11]!==b?(E=b.handleSubmit(w),e[10]=w,e[11]=b,e[12]=E):E=e[12];let D;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,J.jsxs)(`div`,{children:[(0,J.jsx)(k,{children:`Notebook Settings`}),(0,J.jsx)(O,{children:`Configure how your notebook or application looks and behaves.`})]}),e[13]=D):D=e[13];let A;e[14]===b.control?A=e[15]:(A=(0,J.jsxs)(Q,{title:`Display`,children:[(0,J.jsx)(r,{control:b.control,name:`width`,render:se}),(0,J.jsx)(r,{control:b.control,name:`app_title`,render:$})]}),e[14]=b.control,e[15]=A);let j;e[16]===b.control?j=e[17]:(j=(0,J.jsxs)(Q,{title:`Custom Files`,children:[(0,J.jsx)(r,{control:b.control,name:`css_file`,render:ce}),(0,J.jsx)(r,{control:b.control,name:`html_head_file`,render:le})]}),e[16]=b.control,e[17]=j);let M;e[18]===b.control?M=e[19]:(M=(0,J.jsx)(Q,{title:`Data`,children:(0,J.jsx)(r,{control:b.control,name:`sql_output`,render:de})}),e[18]=b.control,e[19]=M);let N;e[20]!==d||e[21]!==h?(N=e=>{let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(s,{children:(0,J.jsxs)(`div`,{className:`flex gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:d,"data-testid":`html-checkbox`,checked:t.value.includes(`html`),onCheckedChange:()=>{t.onChange(H(t.value,`html`))}}),(0,J.jsx)(m,{htmlFor:d,children:`HTML`})]}),(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:h,"data-testid":`ipynb-checkbox`,checked:t.value.includes(`ipynb`),onCheckedChange:()=>{t.onChange(H(t.value,`ipynb`))}}),(0,J.jsx)(m,{htmlFor:h,children:`IPYNB`})]})]})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`When enabled, marimo will periodically save this notebook in your selected formats (HTML, IPYNB) to a folder named`,` `,(0,J.jsx)(W,{className:`inline`,children:`__marimo__`}),` next to your notebook file.`]})]})},e[20]=d,e[21]=h,e[22]=N):N=e[22];let P;e[23]!==b.control||e[24]!==N?(P=(0,J.jsx)(Q,{title:`Exporting outputs`,children:(0,J.jsx)(r,{control:b.control,name:`auto_download`,render:N})}),e[23]=b.control,e[24]=N,e[25]=P):P=e[25];let F;e[26]!==P||e[27]!==A||e[28]!==j||e[29]!==M?(F=(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-8 gap-y-4`,children:[A,j,M,P]}),e[26]=P,e[27]=A,e[28]=j,e[29]=M,e[30]=F):F=e[30];let I;e[31]!==F||e[32]!==E?(I=(0,J.jsxs)(`form`,{onChange:E,className:`flex flex-col gap-6`,children:[D,F]}),e[31]=F,e[32]=E,e[33]=I):I=e[33];let L;return e[34]!==b||e[35]!==I?(L=(0,J.jsx)(c,{...b,children:I}),e[34]=b,e[35]=I,e[36]=L):L=e[36],L},Q=e=>{let t=(0,q.c)(5),{title:n,children:r}=e,i;t[0]===n?i=t[1]:(i=(0,J.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[i,r]}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a};function ae(){window.dispatchEvent(new Event(`resize`))}function oe(e){return(0,J.jsx)(`option`,{value:e,children:e},e)}function se(e){let{field:t}=e;return(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`Width`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`app-width-select`,onChange:e=>t.onChange(e.target.value),value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:j().map(oe)})}),(0,J.jsx)(p,{})]})}function $(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`App title`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,onChange:e=>{t.onChange(e.target.value),v.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`The application title is put in the title tag in the HTML code and typically displayed in the title bar of the browser window.`})]})}function ce(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`Custom CSS`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`custom.css`,onChange:e=>{t.onChange(e.target.value),v.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`A filepath to a custom css file to be injected into the notebook.`})]})}function le(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`HTML Head`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`head.html`,onChange:e=>{t.onChange(e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`A filepath to an HTML file to be injected into the`,` `,(0,J.jsx)(W,{className:`inline`,children:`<head/>`}),` section of the notebook. Use this to add analytics, custom fonts, meta tags, or external scripts.`]})]})}function ue(e){return(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value)}function de(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`SQL Output Type`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`sql-output-select`,onChange:e=>{t.onChange(e.target.value),te({title:`Kernel Restart Required`,description:`This change requires a kernel restart to take effect.`})},value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:N.map(ue)})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`The Python type returned by a SQL cell. For best performance with large datasets, we recommend using`,` `,(0,J.jsx)(W,{className:`inline`,children:`native`}),`. See the`,` `,(0,J.jsx)(I,{href:`https://docs.marimo.io/guides/working_with_data/sql`,children:`SQL guide`}),` `,`for more information.`]})]})}var fe=e=>{let n=(0,q.c)(32),{showAppConfig:r,disabled:i,tooltip:a}=e,o=r===void 0||r,s=i!==void 0&&i,c=a===void 0?`Settings`:a,[l,f]=t(M),p=s?`disabled`:`hint-green`,m;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(V,{strokeWidth:1.8}),n[0]=m):m=n[0];let g;n[1]===c?g=n[2]:(g=(0,J.jsx)(T,{content:c,children:m}),n[1]=c,n[2]=g);let _;n[3]!==s||n[4]!==p||n[5]!==g?(_=(0,J.jsx)(G,{"aria-label":`Config`,"data-testid":`app-config-button`,shape:`circle`,size:`small`,className:`h-[27px] w-[27px]`,disabled:s,color:p,children:g}),n[3]=s,n[4]=p,n[5]=g,n[6]=_):_=n[6];let v=_,y;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsxs)(R,{className:`w-[90vw] h-[90vh] overflow-hidden sm:max-w-5xl top-[5vh] p-0`,children:[(0,J.jsx)(w,{children:(0,J.jsx)(B,{children:`User settings`})}),(0,J.jsx)(A,{})]}),n[7]=y):y=n[7];let b=y;if(!o){let e;n[8]===v?e=n[9]:(e=(0,J.jsx)(ee,{children:v}),n[8]=v,n[9]=e);let t;return n[10]!==f||n[11]!==l||n[12]!==e?(t=(0,J.jsxs)(L,{open:l,onOpenChange:f,children:[e,b]}),n[10]=f,n[11]=l,n[12]=e,n[13]=t):t=n[13],t}let x;n[14]===v?x=n[15]:(x=(0,J.jsx)(d,{asChild:!0,children:v}),n[14]=v,n[15]=x);let S,C;n[16]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,J.jsx)(ie,{}),C=(0,J.jsx)(`div`,{className:`h-px bg-border my-2`}),n[16]=S,n[17]=C):(S=n[16],C=n[17]);let D;n[18]===f?D=n[19]:(D=()=>f(!0),n[18]=f,n[19]=D);let O;n[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(V,{strokeWidth:1.8,className:`w-4 h-4 mr-2`}),n[20]=O):O=n[20];let k;n[21]===D?k=n[22]:(k=(0,J.jsxs)(h,{className:`w-[650px] overflow-auto max-h-[80vh] max-w-[80vw]`,align:`end`,side:`bottom`,onFocusOutside:pe,children:[S,C,(0,J.jsxs)(E,{onClick:D,variant:`link`,className:`px-0`,children:[O,`User settings`]})]}),n[21]=D,n[22]=k);let j;n[23]!==k||n[24]!==x?(j=(0,J.jsxs)(u,{children:[x,k]}),n[23]=k,n[24]=x,n[25]=j):j=n[25];let N;n[26]!==f||n[27]!==l?(N=(0,J.jsx)(L,{open:l,onOpenChange:f,children:b}),n[26]=f,n[27]=l,n[28]=N):N=n[28];let P;return n[29]!==j||n[30]!==N?(P=(0,J.jsxs)(J.Fragment,{children:[j,N]}),n[29]=j,n[30]=N,n[31]=P):P=n[31],P};function pe(e){return e.preventDefault()}export{Y as n,K as r,fe as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t}from"./useEvent-BDjgaBtz.js";import{t as n}from"./react-DVplv7_D.js";import{$t as r,Bn as i,En as a,On as o,Xt as s,Yt as c,Zt as l,cn as u,dn as d,en as f,nn as p,tn as m,un as h}from"./cells-SvbLY10y.js";import{t as g}from"./compiler-runtime-BrajqUja.js";import{D as _,O as v,S as y}from"./config-CXnC3MRv.js";import{M as b}from"./config-7IjqNuVp.js";import{t as x}from"./jsx-runtime-B74pBk57.js";import{o as S}from"./alert-dialog-8YiYLrfr.js";import{l as C}from"./select-CgWQvW1F.js";import{c as w}from"./switch-D2gdC_ep.js";import{t as T}from"./tooltip-B5lAA_jn.js";import{t as E}from"./button-Cl7haVNh.js";import{t as D}from"./createLucideIcon-DfJ2oMlA.js";import{d as O,f as k,i as A,k as j,n as M,u as N}from"./ai-model-dropdown-D575Vid8.js";import{r as P}from"./useNumberFormatter-D7O_26UI.js";import{b as F,p as I}from"./write-secret-modal-CBi2vNK_.js";import{Jt as L,Yt as R,nn as ee,r as z,tn as B}from"./input-DLA5Dhn3.js";import{t as V}from"./settings-BpdQZRgT.js";import{t as te}from"./use-toast-Wu434mLr.js";import{s as H}from"./arrays-0R2reF2y.js";import{r as U}from"./requests-BIFR-h4M.js";import{r as ne}from"./useDebounce-DwTQ_1Pu.js";import{t as W}from"./kbd-pdKBv96t.js";import{t as G}from"./Inputs-BsQm29hD.js";var K=D(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),q=g(),J=x(),Y=e=>{let t=(0,q.c)(15),{description:n,disabled:r,tooltip:i}=e,a=r!==void 0&&r,o=i===void 0?`Shutdown`:i,{openConfirm:s,closeModal:c}=F(),{sendShutdown:l}=U(),u;t[0]===l?u=t[1]:(u=()=>{l(),setTimeout(X,200)},t[0]=l,t[1]=u);let d=u;if(b())return null;let f=a?`disabled`:`red`,p;t[2]!==c||t[3]!==n||t[4]!==d||t[5]!==s?(p=e=>{e.stopPropagation(),s({title:`Shutdown`,description:n,variant:`destructive`,confirmAction:(0,J.jsx)(S,{onClick:()=>{d(),c()},"aria-label":`Confirm Shutdown`,children:`Shutdown`})})},t[2]=c,t[3]=n,t[4]=d,t[5]=s,t[6]=p):p=t[6];let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(P,{strokeWidth:1}),t[7]=m):m=t[7];let h;t[8]!==a||t[9]!==f||t[10]!==p?(h=(0,J.jsx)(G,{"aria-label":`Shutdown`,"data-testid":`shutdown-button`,shape:`circle`,size:`small`,color:f,className:`h-[27px] w-[27px]`,disabled:a,onClick:p,children:m}),t[8]=a,t[9]=f,t[10]=p,t[11]=h):h=t[11];let g;return t[12]!==h||t[13]!==o?(g=(0,J.jsx)(T,{content:o,children:h}),t[12]=h,t[13]=o,t[14]=g):g=t[14],g};function X(){window.close()}var Z=e(n(),1),re=100,ie=()=>{let e=(0,q.c)(37),[t,n]=y(),{saveAppConfig:u}=U(),d=(0,Z.useId)(),h=(0,Z.useId)(),g;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=a(_),e[0]=g):g=e[0];let v;e[1]===t?v=e[2]:(v={resolver:g,defaultValues:t},e[1]=t,e[2]=v);let b=o(v),x;e[3]!==u||e[4]!==n?(x=async e=>{await u({config:e}).then(()=>{n(e)}).catch(()=>{n(e)})},e[3]=u,e[4]=n,e[5]=x):x=e[5];let S=x,C;e[6]===S?C=e[7]:(C=e=>{S(e)},e[6]=S,e[7]=C);let w=ne(C,re),T;e[8]===t.width?T=e[9]:(T=[t.width],e[8]=t.width,e[9]=T),(0,Z.useEffect)(ae,T);let E;e[10]!==w||e[11]!==b?(E=b.handleSubmit(w),e[10]=w,e[11]=b,e[12]=E):E=e[12];let D;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,J.jsxs)(`div`,{children:[(0,J.jsx)(k,{children:`Notebook Settings`}),(0,J.jsx)(O,{children:`Configure how your notebook or application looks and behaves.`})]}),e[13]=D):D=e[13];let A;e[14]===b.control?A=e[15]:(A=(0,J.jsxs)(Q,{title:`Display`,children:[(0,J.jsx)(r,{control:b.control,name:`width`,render:se}),(0,J.jsx)(r,{control:b.control,name:`app_title`,render:$})]}),e[14]=b.control,e[15]=A);let j;e[16]===b.control?j=e[17]:(j=(0,J.jsxs)(Q,{title:`Custom Files`,children:[(0,J.jsx)(r,{control:b.control,name:`css_file`,render:ce}),(0,J.jsx)(r,{control:b.control,name:`html_head_file`,render:le})]}),e[16]=b.control,e[17]=j);let M;e[18]===b.control?M=e[19]:(M=(0,J.jsx)(Q,{title:`Data`,children:(0,J.jsx)(r,{control:b.control,name:`sql_output`,render:de})}),e[18]=b.control,e[19]=M);let N;e[20]!==d||e[21]!==h?(N=e=>{let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(s,{children:(0,J.jsxs)(`div`,{className:`flex gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:d,"data-testid":`html-checkbox`,checked:t.value.includes(`html`),onCheckedChange:()=>{t.onChange(H(t.value,`html`))}}),(0,J.jsx)(m,{htmlFor:d,children:`HTML`})]}),(0,J.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,J.jsx)(i,{id:h,"data-testid":`ipynb-checkbox`,checked:t.value.includes(`ipynb`),onCheckedChange:()=>{t.onChange(H(t.value,`ipynb`))}}),(0,J.jsx)(m,{htmlFor:h,children:`IPYNB`})]})]})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`When enabled, marimo will periodically save this notebook in your selected formats (HTML, IPYNB) to a folder named`,` `,(0,J.jsx)(W,{className:`inline`,children:`__marimo__`}),` next to your notebook file.`]})]})},e[20]=d,e[21]=h,e[22]=N):N=e[22];let P;e[23]!==b.control||e[24]!==N?(P=(0,J.jsx)(Q,{title:`Exporting outputs`,children:(0,J.jsx)(r,{control:b.control,name:`auto_download`,render:N})}),e[23]=b.control,e[24]=N,e[25]=P):P=e[25];let F;e[26]!==P||e[27]!==A||e[28]!==j||e[29]!==M?(F=(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-8 gap-y-4`,children:[A,j,M,P]}),e[26]=P,e[27]=A,e[28]=j,e[29]=M,e[30]=F):F=e[30];let I;e[31]!==F||e[32]!==E?(I=(0,J.jsxs)(`form`,{onChange:E,className:`flex flex-col gap-6`,children:[D,F]}),e[31]=F,e[32]=E,e[33]=I):I=e[33];let L;return e[34]!==b||e[35]!==I?(L=(0,J.jsx)(c,{...b,children:I}),e[34]=b,e[35]=I,e[36]=L):L=e[36],L},Q=e=>{let t=(0,q.c)(5),{title:n,children:r}=e,i;t[0]===n?i=t[1]:(i=(0,J.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[i,r]}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a};function ae(){window.dispatchEvent(new Event(`resize`))}function oe(e){return(0,J.jsx)(`option`,{value:e,children:e},e)}function se(e){let{field:t}=e;return(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`Width`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`app-width-select`,onChange:e=>t.onChange(e.target.value),value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:j().map(oe)})}),(0,J.jsx)(p,{})]})}function $(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`App title`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,onChange:e=>{t.onChange(e.target.value),v.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`The application title is put in the title tag in the HTML code and typically displayed in the title bar of the browser window.`})]})}function ce(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`Custom CSS`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`custom.css`,onChange:e=>{t.onChange(e.target.value),v.safeParse(e.target.value).success&&(document.title=e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsx)(l,{children:`A filepath to a custom css file to be injected into the notebook.`})]})}function le(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{className:`shrink-0`,children:`HTML Head`}),(0,J.jsx)(s,{children:(0,J.jsx)(z,{...t,value:t.value??``,placeholder:`head.html`,onChange:e=>{t.onChange(e.target.value)}})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`A filepath to an HTML file to be injected into the`,` `,(0,J.jsx)(W,{className:`inline`,children:`<head/>`}),` section of the notebook. Use this to add analytics, custom fonts, meta tags, or external scripts.`]})]})}function ue(e){return(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value)}function de(e){let{field:t}=e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-1`,children:[(0,J.jsxs)(f,{className:`flex flex-row items-center space-x-1 space-y-0`,children:[(0,J.jsx)(m,{children:`SQL Output Type`}),(0,J.jsx)(s,{children:(0,J.jsx)(C,{"data-testid":`sql-output-select`,onChange:e=>{t.onChange(e.target.value),te({title:`Kernel Restart Required`,description:`This change requires a kernel restart to take effect.`})},value:t.value,disabled:t.disabled,className:`inline-flex mr-2`,children:N.map(ue)})}),(0,J.jsx)(p,{})]}),(0,J.jsxs)(l,{children:[`The Python type returned by a SQL cell. For best performance with large datasets, we recommend using`,` `,(0,J.jsx)(W,{className:`inline`,children:`native`}),`. See the`,` `,(0,J.jsx)(I,{href:`https://docs.marimo.io/guides/working_with_data/sql`,children:`SQL guide`}),` `,`for more information.`]})]})}var fe=e=>{let n=(0,q.c)(32),{showAppConfig:r,disabled:i,tooltip:a}=e,o=r===void 0||r,s=i!==void 0&&i,c=a===void 0?`Settings`:a,[l,f]=t(M),p=s?`disabled`:`hint-green`,m;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,J.jsx)(V,{strokeWidth:1.8}),n[0]=m):m=n[0];let g;n[1]===c?g=n[2]:(g=(0,J.jsx)(T,{content:c,children:m}),n[1]=c,n[2]=g);let _;n[3]!==s||n[4]!==p||n[5]!==g?(_=(0,J.jsx)(G,{"aria-label":`Config`,"data-testid":`app-config-button`,shape:`circle`,size:`small`,className:`h-[27px] w-[27px]`,disabled:s,color:p,children:g}),n[3]=s,n[4]=p,n[5]=g,n[6]=_):_=n[6];let v=_,y;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,J.jsxs)(R,{className:`w-[90vw] h-[90vh] overflow-hidden sm:max-w-5xl top-[5vh] p-0`,children:[(0,J.jsx)(w,{children:(0,J.jsx)(B,{children:`User settings`})}),(0,J.jsx)(A,{})]}),n[7]=y):y=n[7];let b=y;if(!o){let e;n[8]===v?e=n[9]:(e=(0,J.jsx)(ee,{children:v}),n[8]=v,n[9]=e);let t;return n[10]!==f||n[11]!==l||n[12]!==e?(t=(0,J.jsxs)(L,{open:l,onOpenChange:f,children:[e,b]}),n[10]=f,n[11]=l,n[12]=e,n[13]=t):t=n[13],t}let x;n[14]===v?x=n[15]:(x=(0,J.jsx)(d,{asChild:!0,children:v}),n[14]=v,n[15]=x);let S,C;n[16]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,J.jsx)(ie,{}),C=(0,J.jsx)(`div`,{className:`h-px bg-border my-2`}),n[16]=S,n[17]=C):(S=n[16],C=n[17]);let D;n[18]===f?D=n[19]:(D=()=>f(!0),n[18]=f,n[19]=D);let O;n[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,J.jsx)(V,{strokeWidth:1.8,className:`w-4 h-4 mr-2`}),n[20]=O):O=n[20];let k;n[21]===D?k=n[22]:(k=(0,J.jsxs)(h,{className:`w-[650px] overflow-auto max-h-[80vh] max-w-[80vw]`,align:`end`,side:`bottom`,onFocusOutside:pe,children:[S,C,(0,J.jsxs)(E,{onClick:D,variant:`link`,className:`px-0`,children:[O,`User settings`]})]}),n[21]=D,n[22]=k);let j;n[23]!==k||n[24]!==x?(j=(0,J.jsxs)(u,{children:[x,k]}),n[23]=k,n[24]=x,n[25]=j):j=n[25];let N;n[26]!==f||n[27]!==l?(N=(0,J.jsx)(L,{open:l,onOpenChange:f,children:b}),n[26]=f,n[27]=l,n[28]=N):N=n[28];let P;return n[29]!==j||n[30]!==N?(P=(0,J.jsxs)(J.Fragment,{children:[j,N]}),n[29]=j,n[30]=N,n[31]=P):P=n[31],P};function pe(e){return e.preventDefault()}export{Y as n,K as r,fe as t};
@@ -1 +1 @@
1
- import{a as e}from"./markdown-renderer-mYYQYD2m.js";function t(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{t(e.target?.result)},r.onerror=e=>{n(Error(`Failed to read blob: ${e.type}`))},r.readAsDataURL(e)})}function n(e){let[t,n]=e.split(`,`,2),r=/^data:(.+);base64$/.exec(t)?.[1],i=atob(n),a=i.length,o=new Uint8Array(a);for(let e=0;e<a;e++)o[e]=i.charCodeAt(e);return new Blob([o],{type:r})}function r({contents:t,mimeType:r,isBase64:i}){return i?n(e(t,r)):new Blob([t],{type:r})}export{r as n,t as r,n as t};
1
+ import{a as e}from"./markdown-renderer-DUgV7_fm.js";function t(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{t(e.target?.result)},r.onerror=e=>{n(Error(`Failed to read blob: ${e.type}`))},r.readAsDataURL(e)})}function n(e){let[t,n]=e.split(`,`,2),r=/^data:(.+);base64$/.exec(t)?.[1],i=atob(n),a=i.length,o=new Uint8Array(a);for(let e=0;e<a;e++)o[e]=i.charCodeAt(e);return new Blob([o],{type:r})}function r({contents:t,mimeType:r,isBase64:i}){return i?n(e(t,r)):new Blob([t],{type:r})}export{r as n,t as r,n as t};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./loro_wasm_bg-C2Fqi8D-.js","./loro_wasm_bg-Ctp2cNI9.js","./rolldown-runtime-B0Z9INg1.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-BDjgaBtz.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-BypTg035.js";import{t as _t}from"./react-dom-_LrxgvjW.js";import{C as vt,I as yt,M as bt,N as xt,O as St,R as Ct,S as wt,b as Tt}from"./schemas-ChRqMOTL.js";import{t as Et}from"./compiler-runtime-BrajqUja.js";import{t as Dt}from"./debounce-aFmHgJZY.js";import{E as Ot,_ as kt,c as At,g as jt,h as Mt,s as Nt}from"./config-CXnC3MRv.js";import{_ as Pt,c as Ft,g as It,m as Lt,t as Rt}from"./useEventListener-DPOTkksd.js";import{t as zt}from"./invariant-Ci2dTZ72.js";import{s as Bt}from"./config-BC32AAdw.js";import{d as Vt,m as Ht,t as Ut}from"./session-BHgGkjDm.js";import{D as Wt,M as Gt,S as Kt,T as qt,_ as Jt,o as Yt,p as Xt,r as Zt}from"./config-7IjqNuVp.js";import{c as Qt}from"./state-ClBFtZxn.js";import{t as $t}from"./ErrorBoundary-98Xo04DS.js";import{t as en}from"./cn-ldLVeaqm.js";import{t as tn}from"./jsx-runtime-B74pBk57.js";import{X as nn,Z as rn}from"./JsonOutput-V47aiTIK.js";import{d as an}from"./select-CgWQvW1F.js";import{n as on}from"./download-BsBJWH_j.js";import{t as sn}from"./switch-D2gdC_ep.js";import{t as cn}from"./tooltip-B5lAA_jn.js";import{r as ln,t as un}from"./button-Cl7haVNh.js";import{t as dn}from"./createLucideIcon-DfJ2oMlA.js";import{i as fn,n as pn}from"./paths-bkIFVj8h.js";import{r as mn}from"./layout-66Urh4Zg.js";import{A as hn,C as gn,D as _n,_ as vn,j as yn,t as bn,v as xn,y as Sn}from"./ai-model-dropdown-DgmiG_5j.js";import{r as Cn}from"./useNumberFormatter-D7O_26UI.js";import{t as wn}from"./circle-check-BCurAHEb.js";import{B as Tn,F as En,G as Dn,I as On,L as kn,M as An,R as jn,T as Mn,V as Nn,W as Pn,c as Fn,f as In,i as Ln,n as Rn,o as zn,r as Bn,s as Vn,w as Hn,z as Un}from"./add-cell-with-ai-BbuqzITi.js";import{t as Wn}from"./database-zap-B_PMVg8T.js";import{r as Gn,t as Kn}from"./file-icons-CdJgUy-I.js";import{t as qn}from"./components-9p_w2C6e.js";import{b as Jn}from"./write-secret-modal-CBi2vNK_.js";import{n as Yn}from"./spinner-DyNE-o8o.js";import{n as Xn,o as Zn,r as Qn}from"./readonly-python-code-CZUKLXJ4.js";import{n as $n,t as er}from"./useDeleteCell-DhoFbEkU.js";import{t as tr}from"./save-Dgoim6QF.js";import{G as nr,I as rr,Ut as ir,Xt as ar,Yt as or,Zt as sr,tn as cr}from"./input-DLA5Dhn3.js";import{n as lr}from"./copy-74EjuZso.js";import{t as ur}from"./use-toast-Wu434mLr.js";import{t as dr}from"./preload-helper-uBIymjUX.js";import{$t as fr,Ct as pr,Dt as mr,E as hr,Et as gr,Ft as _r,Gt as vr,H as yr,I as br,It as xr,Jt as Sr,Kt as Cr,Ot as wr,P as Tr,Qt as I,St as Er,Ut as Dr,V as Or,Vt as kr,Wt as Ar,Xt as jr,_ as Mr,at as L,dt as Nr,gt as Pr,ht as Fr,in as Ir,jt as Lr,lt as Rr,m as zr,ot as Br,st as R,tn as Vr,ut as Hr,w as Ur,wt as Wr,zt as Gr}from"./dist-Cny7_yZb.js";import{C as Kr,E as qr,I as Jr,O as Yr,S as Xr,a as Zr,c as Qr,n as $r,r as ei,w as ti}from"./dist-DBMV4gqt.js";import{o as ni}from"./arrays-0R2reF2y.js";import{n as ri}from"./once-6KNTRW0u.js";import{t as ii}from"./createReducer-B04CIO-e.js";import{a as ai,c as oi,f as si,h as ci,i as li,l as ui,n as di,o as fi,t as pi}from"./dist-qhAY4L2r.js";import{r as mi}from"./strings-3lNX212T.js";import{r as hi,t as gi}from"./requests-BIFR-h4M.js";import{t as _i}from"./badge-crT3E0Rm.js";import{a as vi}from"./dist-DusFODSa.js";import{r as yi}from"./useTheme-C2dnh2vM.js";import{t as bi}from"./I18nProvider-Cg2I_s1_.js";import{i as xi}from"./numbers-DJK15_4S.js";import{n as Si}from"./useAsyncData-qvoPYHtx.js";import{a as Ci}from"./useRunCells-VBCe6CLn.js";import{l as wi}from"./useInstallPackage-BfNKN33w.js";import{a as Ti}from"./errors-CNsgAw6m.js";import{t as z}from"./extends-CvVTau-c.js";import{t as Ei}from"./objectWithoutPropertiesLoose-Do6ywDBO.js";import{t as Di}from"./kbd-pdKBv96t.js";import{a as Oi,n as ki}from"./state-QfGh3m2G.js";import{a as Ai,o as ji}from"./cell-link-CAjuFcLK.js";import{a as Mi}from"./renderShortcut-Bxv9ZLnD.js";import{n as Ni,t as Pi}from"./icons-CiZ_8zS-.js";import{n as Fi}from"./esm-CI_o7NhW.js";import{t as Ii}from"./dist-AelfNxj6.js";import{t as Li}from"./skeleton-Cqh4O9g1.js";import{t as Ri}from"./requests-DuLJN9Tf.js";import{n as zi}from"./formatting-DW2u7HXI.js";import{t as Bi}from"./useSplitCell-AvSpVAmq.js";import{n as Vi,r as Hi,t as Ui}from"./panel-accordion-state-D6KtwSF8.js";import{Bo as Wi,Fo as Gi,Ho as Ki,Io as qi,Lo as Ji,No as Yi,Po as Xi,Ro as Zi,Uo as Qi,Vo as $i,ut as ea,zo as ta}from"./loro_wasm_bg-Ctp2cNI9.js";import{t as na}from"./Inputs-BsQm29hD.js";import{n as ra}from"./hooks-CCek4i9f.js";var ia=dn(`file-pen`,[[`path`,{d:`M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34`,key:`o6klzx`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z`,key:`zhnas1`}]]),aa={showInput:`Mod-l`,acceptEdit:`Mod-y`,rejectEdit:`Mod-u`},oa=300,sa=Cr.define({combine:e=>Ir(e,{onError:console.error,inputDebounceTime:oa,keymaps:aa},{onError:(e,t)=>e&&t,inputDebounceTime:(e,t)=>e&&t,keymaps:(e,t)=>e&&t})}),ca=I.define(),la=fr.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let e of t.effects)if(e.is(ca))return e.value;return e}}),ua=I.define(),da=I.define(),fa=fr.define({create(){return{shouldFocus:!1,inputValue:``}},update(e,t){let n=e;for(let e of t.effects)e.is(ua)&&(n={...n,inputValue:e.value}),e.is(da)&&(n={...n,shouldFocus:e.value});return n}}),pa=I.define(),ma=fr.define({create(){return null},update(e,t){for(let e of t.effects)if(e.is(pa))return e.value;return e}}),ha=I.define(),ga=fr.define({create(){return!1},update(e,t){for(let e of t.effects)if(e.is(ha))return e.value;return e}}),_a=1,va=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,i=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(i.from,a.to).trim().length<_a)return!1;let o=Math.max(1,Math.min(i.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[ca.of({show:!0,lineFrom:o,lineTo:s}),da.of(!0),ua.of(``)],selection:Ar.cursor(i.from)}),!0},ya=e=>e.state.field(ma)?(e.dispatch({effects:[pa.of(null),ca.of({show:!1,lineFrom:0,lineTo:0}),da.of(!1),ua.of(``),ha.of(!1)]}),!0):!1,ba=e=>{let t=e.state.field(ma);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[pa.of(null),ca.of({show:!1,lineFrom:0,lineTo:0}),da.of(!1),ua.of(``),ha.of(!1)]}),!0):!1},xa=fr.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Sa));if(!t.docChanged&&!n&&!t.selection)return e;if(n&&t.state.doc===n.value.doc&&t.state.selection.main.head===n.value.pos)return{suggestion:n.value.text};if(e.suggestion&&t.docChanged&&t.startState.selection.ranges.length===1&&t.startState.selection.main.empty&&t.state.selection.ranges.length===1&&t.state.selection.main.empty){let n=t.startState.selection.main.head,r=``,i=0,a=!0;if(t.changes.iterChanges((e,t,o,s,c)=>{i++,a&&=e===n&&t===n,r=c.toString()}),a&&i===1&&r&&e.suggestion.startsWith(r)&&t.state.selection.main.head===n+r.length)return{suggestion:e.suggestion.slice(r.length)||null}}return{suggestion:null}}}),Sa=I.define();function Ca(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new wa(t),side:1});return r.push(i.range(n)),L.set(r)}var wa=class extends Nr{suggestion;constructor(e){super(),this.suggestion=e}toDOM(){let e=document.createElement(`span`);return e.style.opacity=`0.4`,e.className=`cm-inline-suggestion`,e.textContent=this.suggestion,e.setAttribute(`role`,`suggestion`),e.setAttribute(`aria-label`,`Suggestion: ${this.suggestion}`),e}get lineBreaks(){return this.suggestion.split(`
2
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{c as t,d as n,f as r,l as i,o as a,r as o,s,t as c,u as l}from"./useEvent-BDjgaBtz.js";import{t as u}from"./react-DVplv7_D.js";import{$i as d,Bn as f,Br as p,Bt as m,Ca as h,Ci as g,Co as _,Cr as v,D as y,Dr as b,Fr as x,H as S,I as C,Ir as w,K as T,Lr as E,Lt as D,Ni as O,Nn as ee,Nr as k,Pr as te,Qi as ne,Ri as re,Rr as A,Si as j,U as ie,Ur as M,V as N,Vn as P,W as ae,Wr as oe,Yn as se,Zn as ce,_i as le,_n as ue,_t as de,ai as fe,ar as pe,at as me,b as he,ba as ge,bi as _e,bt as ve,ca as ye,ci as be,cn as xe,cr as Se,d as Ce,dt as we,fi as Te,fn as Ee,fo as De,ft as Oe,ga as ke,gn as Ae,gt as je,h as Me,ha as Ne,ht as Pe,i as Fe,it as Ie,jo as Le,jr as Re,li as ze,lr as Be,mn as Ve,mt as He,ni as Ue,nr as We,or as Ge,ot as Ke,pi as qe,pt as Je,qa as Ye,ri as Xe,rr as Ze,sa as Qe,si as $e,sr as et,ti as tt,tr as nt,tt as rt,u as it,ui as at,un as ot,vn as st,vr as ct,vt as lt,wa as ut,wi as dt,xa as ft,xi as pt,xo as mt,yi as ht,za as gt,zr as F}from"./cells-SvbLY10y.js";import{t as _t}from"./react-dom-_LrxgvjW.js";import{C as vt,I as yt,M as bt,N as xt,O as St,R as Ct,S as wt,b as Tt}from"./schemas-ChRqMOTL.js";import{t as Et}from"./compiler-runtime-BrajqUja.js";import{t as Dt}from"./debounce-aFmHgJZY.js";import{E as Ot,_ as kt,c as At,g as jt,h as Mt,s as Nt}from"./config-CXnC3MRv.js";import{_ as Pt,c as Ft,g as It,m as Lt,t as Rt}from"./useEventListener-DPOTkksd.js";import{t as zt}from"./invariant-Ci2dTZ72.js";import{s as Bt}from"./config-BC32AAdw.js";import{d as Vt,m as Ht,t as Ut}from"./session-BHgGkjDm.js";import{D as Wt,M as Gt,S as Kt,T as qt,_ as Jt,o as Yt,p as Xt,r as Zt}from"./config-7IjqNuVp.js";import{c as Qt}from"./state-ClBFtZxn.js";import{t as $t}from"./ErrorBoundary-Ce-Ujlwj.js";import{t as en}from"./cn-ldLVeaqm.js";import{t as tn}from"./jsx-runtime-B74pBk57.js";import{Q as nn,Z as rn}from"./JsonOutput-CfEBzaqW.js";import{d as an}from"./select-CgWQvW1F.js";import{n as on}from"./download-Bx52VRE4.js";import{t as sn}from"./switch-D2gdC_ep.js";import{t as cn}from"./tooltip-B5lAA_jn.js";import{r as ln,t as un}from"./button-Cl7haVNh.js";import{t as dn}from"./createLucideIcon-DfJ2oMlA.js";import{i as fn,n as pn}from"./paths-bkIFVj8h.js";import{r as mn}from"./layout-DvXJxBiL.js";import{A as hn,C as gn,D as _n,_ as vn,j as yn,t as bn,v as xn,y as Sn}from"./ai-model-dropdown-D575Vid8.js";import{r as Cn}from"./useNumberFormatter-D7O_26UI.js";import{t as wn}from"./circle-check-BCurAHEb.js";import{B as Tn,F as En,G as Dn,I as On,L as kn,M as An,R as jn,T as Mn,V as Nn,W as Pn,c as Fn,f as In,i as Ln,n as Rn,o as zn,r as Bn,s as Vn,w as Hn,z as Un}from"./add-cell-with-ai-D7gtGUsg.js";import{t as Wn}from"./database-zap-B_PMVg8T.js";import{r as Gn,t as Kn}from"./file-icons-CdJgUy-I.js";import{t as qn}from"./components-9p_w2C6e.js";import{b as Jn}from"./write-secret-modal-CBi2vNK_.js";import{n as Yn}from"./spinner-DyNE-o8o.js";import{n as Xn,o as Zn,r as Qn}from"./readonly-python-code-Dgw6trlk.js";import{n as $n,t as er}from"./useDeleteCell-CjewKeSr.js";import{t as tr}from"./save-Dgoim6QF.js";import{G as nr,I as rr,Ut as ir,Xt as ar,Yt as or,Zt as sr,tn as cr}from"./input-DLA5Dhn3.js";import{n as lr}from"./copy-74EjuZso.js";import{t as ur}from"./use-toast-Wu434mLr.js";import{t as dr}from"./preload-helper-uBIymjUX.js";import{$t as fr,Ct as pr,Dt as mr,E as hr,Et as gr,Ft as _r,Gt as vr,H as yr,I as br,It as xr,Jt as Sr,Kt as Cr,Ot as wr,P as Tr,Qt as I,St as Er,Ut as Dr,V as Or,Vt as kr,Wt as Ar,Xt as jr,_ as Mr,at as L,dt as Nr,gt as Pr,ht as Fr,in as Ir,jt as Lr,lt as Rr,m as zr,ot as Br,st as R,tn as Vr,ut as Hr,w as Ur,wt as Wr,zt as Gr}from"./dist-Cny7_yZb.js";import{C as Kr,E as qr,I as Jr,O as Yr,S as Xr,a as Zr,c as Qr,n as $r,r as ei,w as ti}from"./dist-DBMV4gqt.js";import{o as ni}from"./arrays-0R2reF2y.js";import{n as ri}from"./once-6KNTRW0u.js";import{t as ii}from"./createReducer-B04CIO-e.js";import{a as ai,c as oi,f as si,h as ci,i as li,l as ui,n as di,o as fi,t as pi}from"./dist-qhAY4L2r.js";import{r as mi}from"./strings-3lNX212T.js";import{r as hi,t as gi}from"./requests-BIFR-h4M.js";import{t as _i}from"./badge-crT3E0Rm.js";import{a as vi}from"./dist-DusFODSa.js";import{r as yi}from"./useTheme-C2dnh2vM.js";import{t as bi}from"./I18nProvider-Cg2I_s1_.js";import{i as xi}from"./numbers-DJK15_4S.js";import{n as Si}from"./useAsyncData-qvoPYHtx.js";import{a as Ci}from"./useRunCells-BupCZpzk.js";import{l as wi}from"./useInstallPackage-BfNKN33w.js";import{a as Ti}from"./errors-CNsgAw6m.js";import{t as z}from"./extends-CvVTau-c.js";import{t as Ei}from"./objectWithoutPropertiesLoose-Do6ywDBO.js";import{t as Di}from"./kbd-pdKBv96t.js";import{a as Oi,n as ki}from"./state-DrraMmqz.js";import{a as Ai,o as ji}from"./cell-link-Cj0gGaMV.js";import{a as Mi}from"./renderShortcut-Bxv9ZLnD.js";import{n as Ni,t as Pi}from"./icons-CiZ_8zS-.js";import{n as Fi}from"./esm-CI_o7NhW.js";import{t as Ii}from"./dist-AelfNxj6.js";import{t as Li}from"./skeleton-Cqh4O9g1.js";import{t as Ri}from"./requests-DuLJN9Tf.js";import{n as zi}from"./formatting-DW2u7HXI.js";import{t as Bi}from"./useSplitCell-CaLIR0TS.js";import{n as Vi,r as Hi,t as Ui}from"./panel-accordion-state-BRbTib2B.js";import{Bo as Wi,Fo as Gi,Ho as Ki,Io as qi,Lo as Ji,No as Yi,Po as Xi,Ro as Zi,Uo as Qi,Vo as $i,ut as ea,zo as ta}from"./loro_wasm_bg-Ctp2cNI9.js";import{t as na}from"./Inputs-BsQm29hD.js";import{n as ra}from"./hooks-CxGwybGw.js";var ia=dn(`file-pen`,[[`path`,{d:`M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34`,key:`o6klzx`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z`,key:`zhnas1`}]]),aa={showInput:`Mod-l`,acceptEdit:`Mod-y`,rejectEdit:`Mod-u`},oa=300,sa=Cr.define({combine:e=>Ir(e,{onError:console.error,inputDebounceTime:oa,keymaps:aa},{onError:(e,t)=>e&&t,inputDebounceTime:(e,t)=>e&&t,keymaps:(e,t)=>e&&t})}),ca=I.define(),la=fr.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let e of t.effects)if(e.is(ca))return e.value;return e}}),ua=I.define(),da=I.define(),fa=fr.define({create(){return{shouldFocus:!1,inputValue:``}},update(e,t){let n=e;for(let e of t.effects)e.is(ua)&&(n={...n,inputValue:e.value}),e.is(da)&&(n={...n,shouldFocus:e.value});return n}}),pa=I.define(),ma=fr.define({create(){return null},update(e,t){for(let e of t.effects)if(e.is(pa))return e.value;return e}}),ha=I.define(),ga=fr.define({create(){return!1},update(e,t){for(let e of t.effects)if(e.is(ha))return e.value;return e}}),_a=1,va=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,i=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(i.from,a.to).trim().length<_a)return!1;let o=Math.max(1,Math.min(i.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[ca.of({show:!0,lineFrom:o,lineTo:s}),da.of(!0),ua.of(``)],selection:Ar.cursor(i.from)}),!0},ya=e=>e.state.field(ma)?(e.dispatch({effects:[pa.of(null),ca.of({show:!1,lineFrom:0,lineTo:0}),da.of(!1),ua.of(``),ha.of(!1)]}),!0):!1,ba=e=>{let t=e.state.field(ma);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[pa.of(null),ca.of({show:!1,lineFrom:0,lineTo:0}),da.of(!1),ua.of(``),ha.of(!1)]}),!0):!1},xa=fr.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(e=>e.is(Sa));if(!t.docChanged&&!n&&!t.selection)return e;if(n&&t.state.doc===n.value.doc&&t.state.selection.main.head===n.value.pos)return{suggestion:n.value.text};if(e.suggestion&&t.docChanged&&t.startState.selection.ranges.length===1&&t.startState.selection.main.empty&&t.state.selection.ranges.length===1&&t.state.selection.main.empty){let n=t.startState.selection.main.head,r=``,i=0,a=!0;if(t.changes.iterChanges((e,t,o,s,c)=>{i++,a&&=e===n&&t===n,r=c.toString()}),a&&i===1&&r&&e.suggestion.startsWith(r)&&t.state.selection.main.head===n+r.length)return{suggestion:e.suggestion.slice(r.length)||null}}return{suggestion:null}}}),Sa=I.define();function Ca(e,t){let n=e.state.selection.main.head,r=[],i=L.widget({widget:new wa(t),side:1});return r.push(i.range(n)),L.set(r)}var wa=class extends Nr{suggestion;constructor(e){super(),this.suggestion=e}toDOM(){let e=document.createElement(`span`);return e.style.opacity=`0.4`,e.className=`cm-inline-suggestion`,e.textContent=this.suggestion,e.setAttribute(`role`,`suggestion`),e.setAttribute(`aria-label`,`Suggestion: ${this.suggestion}`),e}get lineBreaks(){return this.suggestion.split(`
3
3
  `).length-1}},Ta=class{cache=new Map;timeout;constructor(e){this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){if(t){for(let[e,t]of this.cache)Date.now()-t.timestamp>this.timeout&&this.cache.delete(e);if(this.cache.delete(e),this.cache.set(e,{result:t,timestamp:Date.now()}),this.cache.size>20){let e=this.cache.keys().next().value;e!==void 0&&this.cache.delete(e)}}}},Ea=(e,t)=>Hr.fromClass(class{abortController=null;timer=null;cache;constructor(){this.cache=new Ta(t.cacheTimeout??1e3)}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null,this.abortController?.abort(),this.abortController=null}update(n){let r=n.transactions.some(e=>e.effects.some(e=>e.is(Sa)&&e.value.text===null));if(!n.docChanged&&!n.selectionSet&&!r&&!(n.focusChanged&&!n.view.hasFocus)||(this.cancel(),!n.docChanged||n.state.field(xa).suggestion||!n.state.selection.main.empty||n.state.selection.ranges.length!==1||t.events?.beforeSuggestionFetch?.(n.view)===!1))return;let i=new AbortController;this.abortController=i;let a=n.state.doc,o=n.state.selection.main.head,s=JSON.stringify([a.toString(),o]),c=this.cache.get(s),l=async()=>{if(!i.signal.aborted)try{let r=c??await e(n.state,i.signal,n.view);if(i.signal.aborted||n.view.state.doc!==a||n.view.state.selection.main.head!==o||t.events?.shouldShowSuggestion?.(n.view,r)===!1)return;this.cache.set(s,r),n.view.dispatch({effects:Sa.of({text:r,doc:a,pos:o})})}catch(e){!i.signal.aborted&&e instanceof Error&&e.name!==`AbortError`&&console.error(`Suggestion fetch error:`,e)}};this.timer=setTimeout(l,c?0:t.delay??500)}destroy(){this.cancel()}}),Da=Hr.fromClass(class{decorations;constructor(){this.decorations=L.none}update(e){let t=e.state.field(xa)?.suggestion;if(!t){this.decorations=L.none;return}this.decorations=Ca(e.view,t)}},{decorations:e=>e.decorations});function Oa(e,t,n,r){return{...e.changeByRange(i=>{if(i===e.selection.main)return{changes:{from:n,to:r,insert:t},range:Ar.cursor(n+t.length)};let a=r-n;return!i.empty||a&&e.sliceDoc(i.from-a,i.from)!==e.sliceDoc(n,r)?{range:i}:{changes:{from:i.from-a,to:i.from,insert:t},range:Ar.cursor(i.from-a+t.length)}}),userEvent:`input.complete`}}var ka=e=>{let t=e.state.field(xa)?.suggestion;if(!t)return!1;let n=e.state.facet(Ma);return e.dispatch({...Oa(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),n.events?.onSuggestionAccepted?.(e,t),!0},Aa=e=>{let t=e.state.field(xa)?.suggestion;if(!t)return!1;let n=e.state.facet(Ma);return e.dispatch({effects:Sa.of({text:null,doc:e.state.doc,pos:e.state.selection.main.head})}),n.events?.onSuggestionRejected?.(e,t),!0},ja=gr.of([{key:`Tab`,run:ka},{key:`Escape`,run:Aa}]),Ma=Cr.define({combine:e=>e.at(-1)});function Na(e){let{includeKeymap:t=!0}=e;return[xa,Ma.of(e),Ea(e.fetchFn,e),Da,t?ja:[]]}var Pa=R.baseTheme({".cm-ai-input-container":{display:`flex`,flexDirection:`column`,gap:`4px`,width:`min(calc(100% + 7px), 500px)`,padding:`5px 5px`,margin:`0 -6px`,backgroundColor:`light-dark(rgb(241, 243, 245), rgb(40, 40, 40))`},".cm-ai-input":{display:`block`,width:`100%`,padding:`3px 8px`,border:`2px solid rgb(51, 154, 240)`,borderRadius:`5px`,fontSize:`12px`},".cm-ai-help-info-button":{fontSize:`10px`,paddingLeft:`10px`,height:`18px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,display:`block`,marginRight:`auto`},".cm-ai-help-info-button:hover":{color:`light-dark(rgb(89, 97, 105), rgb(190, 190, 190))`},".cm-ai-generate-button":{background:`#0E639C`,border:`none`,padding:`2px 6px`,color:`#ffffff`,cursor:`pointer`,font:`inherit`,borderRadius:`4px`,"&:hover":{backgroundColor:`#1177bb`}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:`light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important`},".cm-line:has(.cm-new-code-line)":{backgroundColor:`light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important`},".cm-old-code-container":{backgroundColor:`light-dark(rgb(255, 205, 205), rgb(100, 40, 40))`,position:`relative`,display:`flex`,paddingTop:`0`,width:`100%`,alignItems:`center`},".cm-code-button":{position:`absolute`,right:`5px`,top:`50%`,transform:`translateY(-50%)`,background:`none`,border:`none`,cursor:`pointer`,fontSize:`16px`},".cm-floating-buttons":{fontFamily:`sans-serif`,position:`absolute`,top:`-20px`,left:`5px`,display:`flex`},".cm-floating-button":{fontFamily:`sans-serif`,padding:`2px 5px`,fontSize:`10px`,cursor:`pointer`,fontWeight:`700`},".cm-floating-accept":{backgroundColor:`light-dark(rgb(55, 125, 34), rgb(40, 80, 25))`,borderTopLeftRadius:`5px`,borderBottomLeftRadius:`5px`,color:`white`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".cm-floating-reject":{backgroundColor:`light-dark(rgb(220, 53, 69), rgb(180, 40, 50))`,color:`white`,borderTopRightRadius:`5px`,borderBottomRightRadius:`5px`,filter:`brightness(90%)`,"&:hover":{filter:`brightness(100%)`}},".hotkey":{display:`inline-block`,padding:`0 4px`,borderRadius:`3px`,backgroundColor:`rgba(255, 255, 255, 0.1)`,fontSize:`90%`},".cm-ai-loading-indicator":{fontStyle:`italic`,fontSize:`10px`,paddingLeft:`12px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,opacity:`0`,transition:`opacity 0.3s ease-in-out`,"&::after":{content:`""`,display:`inline-block`,animation:`ellipsis-pulse 1.5s steps(4, end) infinite`},"&:not(:empty)":{opacity:`1`}},".cm-ai-input:disabled":{opacity:`0.5`},"@keyframes ellipsis-pulse":{"0%":{content:`'.'`},"25%":{content:`'..'`},"50%":{content:`'...'`},"75%":{content:`''`}},".cm-ai-loading-container":{display:`flex`,alignItems:`center`,padding:`0 8px`},".cm-ai-cancel-button":{padding:`2px 8px`,fontSize:`10px`,borderRadius:`4px`,color:`light-dark(rgb(109, 117, 125), rgb(170, 170, 170))`,cursor:`pointer`,"&:hover":{background:`light-dark(rgb(223, 227, 232), rgb(50, 50, 50))`}},".hidden":{display:`none`}}),Fa={mac:`⌘`,windows:`Ctrl`,default:`Ctrl`};function Ia(){return navigator.platform.startsWith(`Mac`)?Fa.mac:navigator.platform.startsWith(`Win`)?Fa.windows:Fa.default}function La(e){return e.replace(`Mod`,Ia()).replace(`-`,` `).toUpperCase()}function B(e,t){let n=document.createElement(e);return n.className=t,n}function Ra(e){let t=e.state.facet(sa),n={...aa,...t.keymaps},r=e.state.facet(za),i=B(`div`,`cm-ai-tooltip`).appendChild(B(`div`,`cm-ai-tooltip-button`)),a=i.appendChild(document.createElement(`span`));a.textContent=`${r.label} `;let o=a.appendChild(document.createElement(`span`));return o.className=`hotkey`,o.textContent=La(n.showInput),i.querySelector(`span`)?.addEventListener(`mousedown`,e=>{e.stopPropagation(),e.button===0&&e.preventDefault()}),i.querySelector(`span`)?.addEventListener(`click`,t=>{t.preventDefault(),va(e)}),i}var za=Cr.define({combine(e){return Ir(e,{render:Ra,hideOnBlur:!1,label:`Edit with AI`})}}),Ba=Hr.fromClass(class{view;suppress;dom;mousedown=()=>{this.suppress=!0};mouseup=()=>{this.suppress=!1,this.display(this.view)};scroll=()=>{this.display(this.view)};windowScroll=()=>{this.display(this.view)};constructor(e){this.view=e;let t=e.state.facet(za);this.suppress=!1,document.addEventListener(`mousedown`,this.mousedown),document.addEventListener(`mouseup`,this.mouseup),e.scrollDOM.addEventListener(`scroll`,this.scroll),window.addEventListener(`scroll`,this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(la).show){this.dom.style.display=`none`;return}if(e.state.facet(za).hideOnBlur&&!e.hasFocus){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}e.requestMeasure({read:this.#e})}#e=e=>{let t=e.state.selection.ranges.find(e=>!e.empty);if(t&&!this.suppress){let n=e.coordsAtPos(t.from),r=e.coordsAtPos(t.to);if(!n||!r)return;let i=e.dom.getBoundingClientRect(),a=e.dom.parentElement?.getBoundingClientRect(),o=e=>e.top>=i.top&&e.top<=i.bottom&&e.left>=i.left&&e.left<=i.right,s=e=>!a||e.top>=a.top&&e.top<=a.bottom&&e.left>=a.left&&e.left<=a.right,c=o(n)||o(r),l=s(n)||s(r);if(!c||!l){this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`);return}this.dom.style.display=`flex`,this.dom.setAttribute(`aria-hidden`,`false`);let u=this.dom.getBoundingClientRect(),d=o(n)?n:r,f=i.right-u.width,p=Math.min(d.left,f),m=d.top-u.height,h=a?a.y:-1/0;m<h&&(m=r.bottom),this.dom.style.left=`${p}px`,this.dom.style.top=`${m}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute(`aria-hidden`,`false`)})}else this.dom.style.display=`none`,this.dom.setAttribute(`aria-hidden`,`true`)};destroy(){document.removeEventListener(`mousedown`,this.mousedown),document.removeEventListener(`mouseup`,this.mouseup),this.view.scrollDOM.removeEventListener(`scroll`,this.scroll),window.removeEventListener(`scroll`,this.windowScroll,!0),this.dom.remove()}}),Va=R.baseTheme({".cm-ai-tooltip-button":{userSelect:`none`,fontFamily:`system-ui, -apple-system, sans-serif`,position:`fixed`,display:`flex`,boxSizing:`border-box`,padding:`2px 6px`,borderRadius:`4px`,fontSize:`12px`,backgroundColor:`#0E639C`,color:`#ffffff`,border:`1px solid transparent`,boxShadow:`0 2px 4px rgba(0,0,0,0.1)`,zIndex:`999`,transition:`opacity 0.5s`,"&[aria-hidden='true']":{opacity:`0`},"&[aria-hidden='false']":{opacity:`1`},"& > span":{pointerEvents:`auto`,cursor:`pointer`,display:`inline-block`,padding:`2px`},"&:hover":{backgroundColor:`#1177bb`}}});function Ha(){return[Ba,Va]}var Ua=class extends Nr{oldCode;constructor(e){super(),this.oldCode=e}toDOM(e){let t=B(`div`,`cm-old-code-container`);t.setAttribute(`role`,`region`),t.setAttribute(`aria-label`,`Previous code version`);let n=B(`div`,`cm-old-code cm-line`);n.textContent=this.oldCode;let r=B(`div`,`cm-floating-buttons`),i=e.state.facet(sa),a={...aa,...i.keymaps},o=B(`button`,`cm-floating-button cm-floating-accept`);o.innerHTML=`<span class="hotkey">${La(a.acceptEdit)}</span> Accept`,o.setAttribute(`aria-label`,`Accept changes`),o.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),ya(e)});let s=B(`button`,`cm-floating-button cm-floating-reject`);return s.innerHTML=`<span class="hotkey">${La(a.rejectEdit)}</span> Reject`,s.setAttribute(`aria-label`,`Reject changes`),s.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e.focus(),ba(e)}),r.append(o,s),t.append(n,r),t}updateDOM(e,t){return!0}},Wa=class extends Nr{complete;abortController=null;dom=null;input=null;loadingContainer=null;helpInfo=null;inputContainer=null;form=null;view=null;constructor(e){super(),this.complete=e}toDOM(e){if(this.dom)return this.dom;this.view=e;let t=e.state.field(fa),n=e.state.field(ga),r=B(`div`,`cm-ai-input-container`);this.inputContainer=r,this.dom=r;let i=B(`form`,`cm-ai-input-form`);this.form=i,i.setAttribute(`role`,`search`),i.setAttribute(`aria-label`,`AI editing instructions`),i.addEventListener(`submit`,e=>e.preventDefault());let a=B(`input`,`cm-ai-input`);this.input=a,i.append(a),a.placeholder=`Editing instructions...`,a.setAttribute(`aria-label`,`AI editing instructions`),a.setAttribute(`autocomplete`,`off`),a.setAttribute(`spellcheck`,`true`),a.value=t.inputValue;let o=B(`div`,`cm-ai-loading-container`);this.loadingContainer=o;let s=B(`div`,`cm-ai-loading-indicator`);s.setAttribute(`role`,`status`),s.setAttribute(`aria-live`,`polite`),s.textContent=`Generating`;let c=B(`button`,`cm-ai-cancel-button`);c.textContent=`Cancel`,c.setAttribute(`aria-label`,`Cancel code generation`),c.addEventListener(`click`,this.onCancel),o.append(c,s);let l=B(`div`,`cm-ai-help-info`);this.helpInfo=l;let u=l.appendChild(document.createElement(`button`));u.className=`cm-ai-help-info-button`,u.textContent=`Esc to close`,u.addEventListener(`click`,this.onCancel);let d=B(`button`,`cm-ai-generate-button`);d.textContent=`⏎ Generate`,d.setAttribute(`aria-label`,`Generate code`),d.addEventListener(`click`,this.handleSubmit),this.toggleLoading(n),t.shouldFocus&&requestAnimationFrame(()=>{a.value=t.inputValue,a.focus(),e.dispatch({effects:da.of(!1)})}),f(a.value),a.addEventListener(`input`,m),a.addEventListener(`keydown`,this.onKeyDown);function f(e){l.replaceChildren(e?d:u)}let p=``;function m(){e.dispatch({effects:ua.of(a.value)});let t=a.value.trim();t!==p&&(p=t,f(t))}return r}toggleLoading(e){this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&this.inputContainer?.replaceChildren(this.form,e?this.loadingContainer:this.helpInfo)}onKeyDown=async e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),await this.handleSubmit()):e.key===`Escape`&&this.onCancel()};onCancel=()=>{this.cleanup();let e=this.view;e&&(e.dispatch({effects:[ca.of({show:!1,lineFrom:0,lineTo:0}),ha.of(!1)]}),e.focus())};handleSubmit=async e=>{let t=this.view;if(!t)return;let n=t.state.facet(sa);e?.stopPropagation();let r=t.state.field(la),{input:i}=this;if(!i)return;let a=i.value.trim();if(!r.show||!a)return;let o=t.state.doc.line(r.lineFrom),s=t.state.doc.line(r.lineTo),c=o.from,l=s.to,u=t.state.sliceDoc(c,l),d=t.state.sliceDoc(0,c),f=t.state.sliceDoc(l);this.abortController=new AbortController,t.dispatch({effects:ha.of(!0)}),this.toggleLoading(!0);try{let e=await this.complete({prompt:a,selection:u,codeBefore:d,codeAfter:f,editorView:t,signal:this.abortController.signal});if(!t.state.field(la).show)return;if(!e||typeof e!=`string`)throw Error(`Invalid completion result`);t.dispatch({changes:{from:c,to:l,insert:e},effects:[ca.of({show:!1,lineFrom:0,lineTo:0}),pa.of({from:c,to:c+e.length,oldCode:u,newCode:e}),ha.of(!1)]})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;n.onError?.(e)}finally{this.cleanup(),this.toggleLoading(!1),t.focus()}};updateDOM(e,t){return this.dom=e,this.input=e.querySelector(`.cm-ai-input`),!0}cleanup(){this.abortController?.abort(),this.abortController=null,this.dom?.remove(),this.input?.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function Ga(e){if(!e.prompt)throw Error(`prompt function is required`);let t={...aa,...e.keymaps};return[sa.of(e),la,fa,ma,ga,Ha(),Pa,gr.of([{key:t.showInput,run:va}]),Sr.highest([gr.of([{key:t.acceptEdit,run:ya},{key:t.rejectEdit,run:ba}])]),Ka,qa,Ja,Ya]}var Ka=R.updateListener.of(e=>{let t=e.state.field(la);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,i=!1;e.changes.iterChanges((t,a,o,s)=>{let c=e.state.doc.lineAt(t).number;if(c<n){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;n+=t,r+=t,i=!0}else if(c<=r){let t=e.state.doc.lineAt(s).number-e.state.doc.lineAt(o).number;r+=t,i=!0}}),i&&e.view.dispatch({effects:[ca.of({show:!0,lineFrom:n,lineTo:r})]})}),qa=R.decorations.of(e=>{let t=e.state.field(ma);return t?L.set([L.mark({class:`cm-new-code-line`}).range(t.from,t.to)]):L.none}),Ja=R.decorations.compute([la],e=>{let t=e.field(la),n=e.facet(sa),r=[];if(t.show){let i=t.lineFrom,a=t.lineTo;for(let t=i;t<=a;t++){let a=e.doc.line(t).from;r.push(L.line({class:`cm-ai-selection`}).range(a)),t===i&&r.push(L.widget({widget:new Wa(n.prompt),side:-1}).range(a))}}return L.set(r)}),Ya=fr.define({create(e){return L.none},update(e,t){let n=t.state.field(ma);return n?L.set([L.widget({widget:new Ua(n.oldCode),block:!0}).range(n.from)]):L.none},provide:e=>R.decorations.from(e)}),V=e(u(),1),H=Et(),Xa=()=>({entries:new Map}),{valueAtom:Za,useActions:Qa}=ii(Xa,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:i,store:a}=t,o=a.get(he),s=a.get(tt),c=new Set(o.cellIds.inOrderIds.filter(e=>o.cellData[e].code.trim()===``)),l=new Map;for(let e of n){if(c.has(e)){l.set(e,{cellId:e,type:`simple`});continue}let t=o.cellRuntime[e],n=new Map;for(let t of Object.values(s)){let r=t.declaredBy.includes(e),i=t.usedBy.some(e=>!c.has(e));r&&i&&n.set(t.name,t.usedBy)}let r;t?.runElapsedTimeMs&&t.runElapsedTimeMs>2e3&&(r=t.runElapsedTimeMs),n.size===0&&r===void 0?l.set(e,{cellId:e,type:`simple`}):l.set(e,{cellId:e,type:`expensive`,executionDurationMs:r,defs:n})}let u=[...l.values()].every(e=>e.type===`simple`);return l.size>0&&u?(l.size===1?r({cellId:[...l.values()][0].cellId}):i({cellIds:[...l.values()].map(e=>e.cellId)}),Xa()):{...e,entries:l}},clear:()=>Xa()});function $a(){let e=(0,H.c)(10),t=n(),{submit:r,clear:a}=Qa(),{entries:o}=i(Za),s=er(),c=$n(),l;e[0]!==s||e[1]!==c||e[2]!==t||e[3]!==r?(l=e=>{r({cellIds:e,deleteCell:s,deleteManyCells:c,store:t})},e[0]=s,e[1]=c,e[2]=t,e[3]=r,e[4]=l):l=e[4];let u=o.size===0,d=o.size>1,f;return e[5]!==a||e[6]!==l||e[7]!==u||e[8]!==d?(f={submit:l,clear:a,idle:u,shouldConfirmDelete:d},e[5]=a,e[6]=l,e[7]=u,e[8]=d,e[9]=f):f=e[9],f}function eo(e){let t=(0,H.c)(16),n=i(Za),r=Qa(),a=$n(),o;t[0]!==e||t[1]!==n.entries?(o=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=o):o=t[2];let s=o;if(!s){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={isPending:!1},t[3]=e):e=t[3],e}if(n.entries.size!==1){let e;return t[4]===s?e=t[5]:(e={isPending:!0,shouldConfirmDelete:!1,...s},t[4]=s,t[5]=e),e}let c;t[6]!==r||t[7]!==a||t[8]!==n.entries?(c=()=>{a({cellIds:[...n.entries.values()].map(to)}),r.clear()},t[6]=r,t[7]=a,t[8]=n.entries,t[9]=c):c=t[9];let l;t[10]===r?l=t[11]:(l=()=>r.clear(),t[10]=r,t[11]=l);let u;return t[12]!==s||t[13]!==c||t[14]!==l?(u={isPending:!0,...s,shouldConfirmDelete:!0,confirm:c,cancel:l},t[12]=s,t[13]=c,t[14]=l,t[15]=u):u=t[15],u}function to(e){return e.cellId}async function no(e){if(!e.ok)throw Error(await e.text());if(!e.body)throw Error(`Failed to get response body`);let t=null,n=!1;if(await Nn({stream:Dn({stream:e.body,schema:Pn}).pipeThrough(new TransformStream({transform(e){if(!e.success)throw e.error;let r=e.value;if(kn(r)&&r.type===En)t=On.parse(r.data).code;else if(r.type===`error`)throw Error(r.errorText);else r.type===`finish`&&(n=r.finishReason===`stop`)}})),onError:e=>{throw e}}),!n)throw Error(`AI completion ended before final validation`);if(t===null)throw Error(`AI completion returned no cell code`);return t}async function ro(e){let t=`
4
4
  ${e.codeBefore}
5
5
  <rewrite_this>
@@ -39,4 +39,4 @@ const partysocket = new PartySocket({
39
39
  `),df=!0);let r=this._options.WebSocket||WebSocket;this._debug(`connect`,{url:e,protocols:n}),this._ws=n?new r(e,n):new r(e),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t)}).catch(e=>{this._connectLock=!1,this._handleError(new nf.ErrorEvent(Error(e.message),this))})}_handleTimeout(){this._debug(`timeout event`),this._handleError(new nf.ErrorEvent(Error(`TIMEOUT`),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),this._ws){this._removeListeners();try{(this._ws.readyState===this.OPEN||this._ws.readyState===this.CONNECTING)&&this._ws.close(e,t),this._handleClose(new nf.CloseEvent(e,t,this))}catch{}}}_acceptOpen(){this._debug(`accept open`),this._retryCount=0}_handleOpen=e=>{this._debug(`open event`);let{minUptime:t=uf.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),rf(this._ws,`WebSocket is not defined`),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(e=>{this._ws?.send(e)}),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent(lf(e))};_handleMessage=e=>{this._debug(`message event`),this.onmessage&&this.onmessage(e),this.dispatchEvent(lf(e))};_handleError=e=>{this._debug(`error event`,e.message),this._disconnect(void 0,e.message===`TIMEOUT`?`timeout`:void 0),this.onerror&&this.onerror(e),this._debug(`exec error listeners`),this.dispatchEvent(lf(e)),this._connect()};_handleClose=e=>{this._debug(`close event`),this._clearTimeouts(),this._options.shouldReconnectOnClose&&!this._options.shouldReconnectOnClose(e)&&(this._shouldReconnect=!1),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent(lf(e))};_removeListeners(){this._ws&&(this._debug(`removeListeners`),this._ws.removeEventListener(`open`,this._handleOpen),this._ws.removeEventListener(`close`,this._handleClose),this._ws.removeEventListener(`message`,this._handleMessage),this._ws.removeEventListener(`error`,this._handleError),this._ws.addEventListener(`error`,ff))}_addListeners(){this._ws&&(this._debug(`addListeners`),this._ws.addEventListener(`open`,this._handleOpen),this._ws.addEventListener(`close`,this._handleClose),this._ws.addEventListener(`message`,this._handleMessage),this._ws.addEventListener(`error`,this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}},mf=R.baseTheme({".loro-cursor":{position:`absolute`,width:`2px`,display:`inline-block`,height:`1.2em`},".loro-cursor::before":{position:`absolute`,top:`1.3em`,left:`0`,content:`var(--rtc-name)`,padding:`2px 6px`,fontSize:`12px`,borderRadius:`3px`,whiteSpace:`nowrap`,userSelect:`none`,backgroundColor:`inherit`,opacity:`0.7`},".loro-selection":{opacity:`0.5`}});Gr.define();var hf=I.define(),gf=fr.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(hf))switch(n.value.type){case`update`:{let{peer:t,user:r,cursor:i}=n.value;e.remoteCursors.set(t,{uid:t,cursor:i,user:r});break}case`delete`:e.remoteCursors.delete(n.value.peer);break;case`checkout`:e.isCheckout=n.value.checkout}return e}}),_f=e=>{let t=e.transactions.flatMap(e=>e.effects).filter(e=>e.is(hf));return e.docChanged||e.viewportChanged||t.length>0},vf=()=>mr({above:!0,class:`loro-cursor-layer`,update:_f,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(gf);return n?[]:[...t.values()].flatMap(t=>{let n=Ar.cursor(t.cursor.anchor);return bf.createCursor(e,n,t.user?.name||`unknown`,t.user?.colorClassName||``)})}}),yf=()=>mr({above:!1,class:`loro-selection-layer`,update:_f,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(gf);return n?[]:[...t.entries()].filter(([,e])=>e.cursor.head!==void 0&&e.cursor.anchor!==e.cursor.head).flatMap(([,t])=>{let n=Ar.range(t.cursor.anchor,t.cursor.head);return Rr.forRange(e,`loro-selection ${t.user?.colorClassName||``}`,n)})}}),bf=class e{left;top;height;name;colorClassName;constructor({left:e,top:t,height:n,name:r,colorClassName:i}){this.left=e,this.top=t,this.height=n,this.name=r,this.colorClassName=i}draw(){let e=document.createElement(`div`);return this.adjust(e),e}update(e){return this.adjust(e),!0}adjust(e){e.style.left=`${this.left}px`,e.style.top=`${this.top}px`,e.style.height=`${this.height}px`,e.className=`loro-cursor ${this.colorClassName}`,e.style.setProperty(`--rtc-name`,`"${this.name}"`)}eq(e){return this.left===e.left&&this.top===e.top&&this.height===e.height&&this.name===e.name}static createCursor(t,n,r,i){let a=e.calculateAbsoluteCursorPosition(n,t);if(!a)return[];let o=t.scrollDOM.getBoundingClientRect(),s=(t.textDirection===Br.LTR?o.left:o.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,c=o.top-t.scrollDOM.scrollTop;return[new e({left:a.left-s,top:a.top-c,height:a.bottom-a.top,name:r,colorClassName:i})]}static calculateAbsoluteCursorPosition(e,t){let n=Math.max(0,Math.min(t.state.doc.length,e.anchor));return t.coordsAtPos(n,e.assoc||1)}},xf=(e,t,n,r)=>{let i=[],{updated:a,added:o}=n;for(let n of[...a,...o]){let a=Sf(e,t,n,r);a&&i.push(a)}return i},Sf=(e,t,n,r)=>{let i=t.getAllStates()[n];if(!i||n===e.peerIdStr||i.scopeId!==r)return;if(i.type===`delete`)return hf.of({type:`delete`,peer:i.uid,scopeId:i.scopeId});let a=Xi.decode(i.cursor.anchor),o=e.getCursorPos(a)?.offset??0,s=o;if(i.cursor.head){let t=Xi.decode(i.cursor.head);s=e.getCursorPos(t)?.offset??0}return hf.of({type:`update`,peer:i.uid,scopeId:i.scopeId,cursor:{anchor:o,head:s},user:i.user})},Cf=class{sub;view;doc;user;awareness;getTextFromDoc;scopeId;getUserId;constructor(e,{doc:t,user:n,awareness:r,getTextFromDoc:i,scopeId:a,getUserId:o}){this.view=e,this.doc=t,this.user=n,this.awareness=r,this.getTextFromDoc=i,this.scopeId=a,this.getUserId=o,this.sub=this.doc.subscribe(e=>{if(e.by===`local`){let e=[];for(let t of this.awareness.peers()){let n=Sf(this.doc,this.awareness,t,this.scopeId);n&&e.push(n)}this.view.dispatch({effects:e})}else e.by===`checkout`&&this.view.dispatch({effects:[hf.of({type:`checkout`,checkout:this.doc.isDetached()})]})})}update(e){if(!e.selectionSet&&!e.focusChanged&&!e.docChanged)return;let t=e.state.selection.main;if(this.view.hasFocus&&!this.doc.isDetached()){let e=Tf({doc:this.doc,getTextFromDoc:this.getTextFromDoc,anchor:t.anchor,head:t.head});this.awareness.setLocalState({type:`update`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId,cursor:e,user:this.user})}else this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}destroy(){this.sub?.(),this.awareness.setLocalState({type:`delete`,uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}},wf=class{_awarenessListener;view;doc;awareness;scopeId;constructor(e,t,n,r){this.view=e,this.doc=t,this.awareness=n,this.scopeId=r;let i=async(e,t)=>{t!==`local`&&this.view.dispatch({effects:xf(this.doc,this.awareness,e,this.scopeId)})};this._awarenessListener=i,this.awareness.addListener(i)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},Tf=({doc:e,getTextFromDoc:t,anchor:n,head:r})=>{n===r&&(r=void 0);let i=t(e).getCursor(n)?.encode();if(!i)throw Error(`cursor head not found`);let a;return r!==void 0&&(a=t(e).getCursor(r)?.encode()),{anchor:i,head:a}},Ef=[`bg-(--amber-6)`,`bg-(--blue-6)`,`bg-(--crimson-6)`,`bg-(--cyan-6)`,`bg-(--grass-6)`,`bg-(--gray-6)`,`bg-(--green-6)`,`bg-(--lime-6)`,`bg-(--orange-6)`,`bg-(--purple-6)`,`bg-(--red-6)`,`bg-(--sage-6)`,`bg-(--sky-6)`,`bg-(--slate-6)`],Df=e=>{if(typeof e==`string`){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t=Math.trunc(t);return Ef[Math.abs(t)%Ef.length]}return Ef[e%Ef.length]},Q=It.get(`rtc`),Of=Q.get(`awareness`).disabled(),kf=`awareness:`;function Af(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function jf(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function Mf(e,t){return e.slice(t.length)}var Nf=r(void 0),$=new qi,Pf=new Xd($.peerIdStr),Ff=ri(()=>{Q.debug(`creating websocket`);let e=new pf(Zt().getWsSyncURL(Ut()).toString(),void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await Kt(),Vt()===`edit`&&e.reconnect()}),e.addEventListener(`message`,async e=>{let t=await e.data.arrayBuffer(),n=new Uint8Array(t);if(jf(n,kf)){let e=Mf(n,kf);Pf.apply(e),Of.debug(`applied awareness update`);return}$.import(n),Q.debug(`imported doc change. new doc:`,$.toJSON()),o.get(Nf)!==$&&o.set(Nf,$)}),e.addEventListener(`open`,()=>{Q.debug(`websocket open`)}),e.addEventListener(`close`,e=>{Q.warn(`websocket close`,e),o.get(Nf)===$&&o.set(Nf,void 0)}),e});me()&&Ff(),$.subscribeLocalUpdates(e=>{Q.debug(`local update, sending to server`),Ff().send(new Uint8Array(e))}),Pf.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t===`local`&&(Of.debug(`awareness changes`,n),Ff().send(Af(kf,Pf.encode(n))))});function If(e,t,n=``){if(Gt())return{extension:[],code:n};let r=$.getByPath(`codes/${e}`)!==void 0,i=$.getMap(`codes`).getOrCreateContainer(e,new Zi);return r||(Q.log(`initializing code for new cell`,n),i.insert(0,n)),{code:n.toString(),extension:[Lf(e),Rf(e),zf({doc:$,awareness:Pf,user:{get name(){return o.get(Ke)||`Anonymous`},get colorClassName(){return Df(this.name)}},getTextFromDoc:()=>i,cellId:e}),be($,[`codes`,e],()=>i)]}}function Lf(e){let t=(e,t)=>{let n=e.state.field(Pe).type,r=t.toString();r&&r!==n&&(Q.debug(`[incoming] setting language type: ${n} -> ${r}`),lt(e,{language:r,keepCodeAsIs:!0}))},n=(e,t)=>{let n=e.state.field(nt),r=t.toJSON();a(n,r)||e.dispatch({effects:[Ze.of(r)],annotations:[$e.of(!0)]})};return Hr.define(r=>{let i;return Promise.resolve().then(()=>{let a=$.getByPath(`languages/${e}`);if(!a){Q.error(`no language container found for cell`,e);return}zt(a instanceof Zi,`language type is not a LoroText`);let o=$.getByPath(`language_metadata/${e}`);if(!o){Q.error(`no language metadata container found for cell`,e);return}zt(o instanceof Ji,`language metadata is not a LoroMap`),t(r,a),n(r,o),i=$.subscribe(e=>{if(e.origin===`local`)return;let i=e.events.some(e=>e.target===a.id),s=e.events.some(e=>e.target===o.id);i&&t(r,a),s&&n(r,o)})}),{destroy(){i()}}})}function Rf(e){let t=$.getMap(`languages`).getOrCreateContainer(e,new Zi),n=$.getMap(`language_metadata`).getOrCreateContainer(e,new Ji);return R.updateListener.of(e=>{let r=t.toString()!==``;if(!e.docChanged&&r)return;if(!r){let r=He(e.state).type;lt(e.view,{language:r}),Q.debug(`no initial language, setting default to`,r),t.delete(0,t.length),t.insert(0,r),Q.debug(`no initial language metadata, setting default to`,e.state.field(nt));let i=e.state.field(nt);for(let e of Object.keys(i))n.set(e,i[e]);$.commit();return}let i=!1;for(let r of e.transactions)if(!r.annotation($e)){for(let e of r.effects)if(e.is(de)&&t.toString()!==e.value.type&&(Q.debug(`[outgoing] language change: ${t} -> ${e.value.type}`),t.delete(0,t.length),t.insert(0,e.value.type),i=!0),e.is(Ze)||e.is(We)){let t=e.value;e.is(We)?(Q.debug(`[outgoing] setting language metadata: `,t),n.clear()):Q.debug(`[outgoing] updating language metadata: `,t);for(let e of Object.keys(t))n.set(e,t[e]);i=!0}}i&&$.commit()})}function zf({doc:e,awareness:t,user:n,getTextFromDoc:r,cellId:i,getUserId:a}){let o=`loro:cell:${i}`;return[gf,vf(),yf(),Hr.define(i=>new Cf(i,{doc:e,user:n,awareness:t,getTextFromDoc:r,scopeId:o,getUserId:a})),Hr.define(n=>new wf(n,e,t,o)),mf]}var Bf=De,Vf=e=>{let t=(0,H.c)(41),{resetOnBlur:n,placeholderText:r,initialValue:i,flexibleWidth:a,onNameChange:o,className:s}=e,c=n!==void 0&&n,l=i===void 0?null:i,u=a!==void 0&&a,{sendListFiles:d}=hi(),[f,p]=(0,V.useState)(l),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[0]=m):m=t[0];let[h,g]=(0,V.useState)(m),[_,v]=(0,V.useState)(!1),y=(0,V.useRef)(null),b=(0,V.useRef)(!1),x,S;t[1]===l?(x=t[2],S=t[3]):(x=()=>{p(l)},S=[l],t[1]=l,t[2]=x,t[3]=S),(0,V.useEffect)(x,S);let C;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{v(!0)},t[4]=C):C=t[4];let w=C,T;t[5]!==l||t[6]!==c?(T=e=>{e.relatedTarget?.closest(`.filename-input`)||(v(!1),c&&p(l))},t[5]=l,t[6]=c,t[7]=T):T=t[7];let E=T,D;t[8]===f?D=t[9]:(D=pn.dirname(f||``),t[8]=f,t[9]=D);let O=D,ee=pn.basename(f||``),k=h.filter(e=>pn.basename(e.path).startsWith(ee)),te;t[10]!==O||t[11]!==_||t[12]!==d?(te=async()=>{if(!_){g([]);return}let e=await d({path:O});g(e.files)},t[10]=O,t[11]=_,t[12]=d,t[13]=te):te=t[13];let ne;t[14]!==O||t[15]!==_?(ne=[O,_],t[14]=O,t[15]=_,t[16]=ne):ne=t[16];let{isPending:re}=Si(te,ne),A=Hf(f,h,l),j=(A||k.length>0)&&(0,U.jsxs)(st,{className:`font-mono`,children:[!re&&(0,U.jsx)(Ve,{children:`No files`}),A&&(0,U.jsxs)(ue,{variant:`success`,className:`py-2 px-3`,onSelect:()=>{A&&(b.current=!0,o(A),y.current?.blur())},children:[(0,U.jsx)(ia,{className:`w-4 h-4 mr-2`}),` `,(0,U.jsxs)(`span`,{className:`text-sm`,children:[l?`Rename to: `:`Save as: `,(0,U.jsx)(`span`,{className:`font-medium text-sm`,children:pn.basename(A)})]})]},`_rename_`),k.map(e=>{let t=e.isDirectory?`directory`:Gn(e.path),n=Kn[t];return(0,U.jsxs)(ue,{variant:e.isDirectory?`default`:`muted`,className:`py-2 px-3`,onSelect:()=>{e.isDirectory?p(`${e.path}/`):p(e.path)},children:[(0,U.jsx)(n,{className:`w-4 h-4 mr-2`}),` `,pn.basename(e.path)]},e.path)})]}),ie=Math.max(20,f?.length||r?.length||0)*10,M=_?f||``:l||``,N;t[17]!==u||t[18]!==ie?(N=u?{maxWidth:ie}:void 0,t[17]=u,t[18]=ie,t[19]=N):N=t[19];let P;t[20]===s?P=t[21]:(P=en(s,`w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60`),t[20]=s,t[21]=P);let ae;t[22]!==r||t[23]!==M||t[24]!==N||t[25]!==P?(ae=(0,U.jsx)(Bf,{children:(0,U.jsx)(Ae,{"data-testid":`dir-completion-input`,tabIndex:-1,rootClassName:`border-none justify-center px-1`,spellCheck:`false`,value:M,onKeyDown:Uf,icon:null,ref:y,onValueChange:p,placeholder:r,autoComplete:`off`,style:N,className:P})}),t[22]=r,t[23]=M,t[24]=N,t[25]=P,t[26]=ae):ae=t[26];let oe=j&&`group-focus-within:block`,se;t[27]===oe?se=t[28]:(se=en(`p-0 w-full min-w-80 max-w-80vw hidden`,oe),t[27]=oe,t[28]=se);let ce;t[29]!==j||t[30]!==se?(ce=(0,U.jsx)(ot,{side:`bottom`,className:se,portal:!1,children:j}),t[29]=j,t[30]=se,t[31]=ce):ce=t[31];let le;t[32]!==ae||t[33]!==ce?(le=(0,U.jsxs)(st,{children:[ae,ce]}),t[32]=ae,t[33]=ce,t[34]=le):le=t[34];let de;t[35]!==E||t[36]!==le?(de=(0,U.jsx)(Ee,{onFocus:w,onBlur:E,shouldFilter:!1,id:`filename-input`,className:`bg-transparent group filename-input`,children:le}),t[35]=E,t[36]=le,t[37]=de):de=t[37];let fe;return t[38]!==_||t[39]!==de?(fe=(0,U.jsx)($t,{children:(0,U.jsx)(xe,{open:_,modal:!1,children:de})}),t[38]=_,t[39]=de,t[40]=fe):fe=t[40],fe};function Hf(e,t,n){if(e&&!e.endsWith(`/`)&&((fe(`markdown`)?new Set([`py`,`md`,`markdown`,`qmd`]):new Set([`py`])).has(pn.extension(e))||(e=e.endsWith(`.`)?`${e}py`:e.endsWith(`.p`)?`${e}y`:`${e}.py`),!t.some(t=>t.path===e||pn.basename(t.path)===e)&&!(n&&(n===e||pn.basename(n)===e))))return e}function Uf(e){e.key===`Escape`&&e.currentTarget.blur()}var Wf=e=>{let t=(0,H.c)(33),n=()=>{on(new Blob([r()],{type:`text/plain`}),`${e.proposedName}.json`)},r=c(qf),i;t[0]!==n||t[1]!==e?(i=t=>{t.preventDefault(),n(),e.closeModal()},t[0]=n,t[1]=e,t[2]=i):i=t[2];let a;t[3]===e?a=t[4]:(a=t=>{t.key===`Escape`&&e.closeModal()},t[3]=e,t[4]=a);let o;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,U.jsx)(cr,{className:`text-accent-foreground mb-6`,children:`Download unsaved changes?`}),t[5]=o):o=t[5];let s;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(s={wordBreak:`break-word`},t[6]=s):s=t[6];let l,u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(`p`,{children:`This app has unsaved changes. To recover:`}),u={paddingBottom:`10px`},t[7]=l,t[8]=u):(l=t[7],u=t[8]);let d;t[9]===e.proposedName?d=t[10]:(d=(0,U.jsxs)(`li`,{style:u,children:[`Click the "Download" button. This will download a file called\xA0`,(0,U.jsxs)(`code`,{children:[e.proposedName,`.json`]}),`. This file contains your code.`]}),t[9]=e.proposedName,t[10]=d);let f;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(f={paddingBottom:`10px`},t[11]=f):f=t[11];let p;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(p={display:`block`,padding:`10px`},t[12]=p):p=t[12];let m;t[13]===e.proposedName?m=t[14]:(m=(0,U.jsxs)(`code`,{style:p,children:[`marimo recover `,e.proposedName,`.json `,`>`,` `,e.proposedName,`.py`]}),t[13]=e.proposedName,t[14]=m);let h;t[15]===e.proposedName?h=t[16]:(h=(0,U.jsxs)(`code`,{children:[e.proposedName,`.py`]}),t[15]=e.proposedName,t[16]=h);let g;t[17]!==h||t[18]!==m?(g=(0,U.jsxs)(`li`,{style:f,children:[`In your terminal, type`,m,`to overwrite `,h,` with the recovered changes.`]}),t[17]=h,t[18]=m,t[19]=g):g=t[19];let _;t[20]!==g||t[21]!==d?(_=(0,U.jsx)(ar,{className:`markdown wrap-break-word`,style:s,children:(0,U.jsxs)(`div`,{className:`prose dark:prose-invert`,children:[l,(0,U.jsxs)(`ol`,{children:[d,g]})]})}),t[20]=g,t[21]=d,t[22]=_):_=t[22];let v;t[23]===e.closeModal?v=t[24]:(v=(0,U.jsx)(un,{"aria-label":`Cancel`,variant:`secondary`,"data-testid":`cancel-recovery-button`,onClick:e.closeModal,children:`Cancel`}),t[23]=e.closeModal,t[24]=v);let y;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,U.jsx)(un,{"data-testid":`download-recovery-button`,"aria-label":`Download`,variant:`default`,type:`submit`,children:`Download`}),t[25]=y):y=t[25];let b;t[26]===v?b=t[27]:(b=(0,U.jsxs)(sr,{children:[v,y]}),t[26]=v,t[27]=b);let x;return t[28]!==i||t[29]!==a||t[30]!==_||t[31]!==b?(x=(0,U.jsx)(or,{className:`w-fit`,children:(0,U.jsxs)(`form`,{onSubmit:i,onKeyDown:a,children:[o,_,b]})}),t[28]=i,t[29]=a,t[30]=_,t[31]=b,t[32]=x):x=t[32],x},Gf=e=>{let t=(0,H.c)(12),{filename:n,needsSave:r}=e,{openModal:i,closeModal:a}=Jn(),o;t[0]===n?o=t[1]:(o=n===null?`app`:pn.basename(n).split(`.`)[0],t[0]=n,t[1]=o);let s=o,c;t[2]!==a||t[3]!==r||t[4]!==i||t[5]!==s?(c=()=>{r&&i((0,U.jsx)(Wf,{proposedName:s,closeModal:a}))},t[2]=a,t[3]=r,t[4]=i,t[5]=s,t[6]=c):c=t[6];let l=c;_n(`global.save`,l);let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=Mi(`global.save`),t[7]=u):u=t[7];let d=r?`yellow`:`gray`,f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(tr,{strokeWidth:1.5,size:18}),t[8]=f):f=t[8];let p;return t[9]!==l||t[10]!==d?(p=(0,U.jsx)(cn,{content:u,children:(0,U.jsx)(na,{onClick:l,id:`save-button`,"aria-label":`Save`,className:`rectangle`,color:d,children:f})}),t[9]=l,t[10]=d,t[11]=p):p=t[11],p};function Kf(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function qf(){let e=Me(),t=ye(e),n={version:`1`,metadata:{marimo_version:Qt()},cells:t.map(Kf)};return JSON.stringify(n,null,2)}var Jf=r(void 0),Yf=r(e=>{let t=e(Jf);return Xf({state:e(he),layout:e(Zn),lastSavedNotebook:t})});function Xf({state:e,layout:t,lastSavedNotebook:n}){if(!n)return!1;let{cellIds:r,cellData:i}=e,o=r.inOrderIds.map(e=>i[e]),s=o.map(e=>e.code),c=o.map(e=>e.config),l=o.map(e=>e.name);return!ni(s,n.codes)||!ni(l,n.names)||!a(c,n.configs)||!a(t.selectedLayout,n.layout.selectedLayout)||!a(t.layoutData,n.layout.layoutData)}function Zf(e){let t=(0,H.c)(21),{codes:n,cellConfigs:r,config:i,connStatus:a,cellNames:o,needsSave:s,kioskMode:c,onSave:l}=e,u=(0,V.useRef)(null),d;t[0]===n?d=t[1]:(d=n.join(`:`),t[0]=n,t[1]=d);let f=d,p;t[2]===r?p=t[3]:(p=r.map(Qf).join(`:`),t[2]=r,t[3]=p);let m=p,h;t[4]===o?h=t[5]:(h=o.join(`:`),t[4]=o,t[5]=h);let g=h,_;t[6]!==i||t[7]!==a.state||t[8]!==c||t[9]!==s||t[10]!==l?(_=()=>{if(!c)return i.autosave===`after_delay`&&(u.current!==null&&clearTimeout(u.current),s&&a.state===qt.OPEN&&(u.current=setTimeout(l,i.autosave_delay))),()=>{u.current!==null&&clearTimeout(u.current)}},t[6]=i,t[7]=a.state,t[8]=c,t[9]=s,t[10]=l,t[11]=_):_=t[11];let v;t[12]!==m||t[13]!==g||t[14]!==f||t[15]!==i||t[16]!==a.state||t[17]!==c||t[18]!==s||t[19]!==l?(v=[f,m,g,i,a.state,l,c,s],t[12]=m,t[13]=g,t[14]=f,t[15]=i,t[16]=a.state,t[17]=c,t[18]=s,t[19]=l,t[20]=v):v=t[20],(0,V.useEffect)(_,v)}function Qf(e){return JSON.stringify(e)}var $f=Promise.resolve();function ep(e){let t=$f.then(e);return $f=t.then(()=>void 0,()=>void 0),t}var tp=e=>{let t=(0,H.c)(15),{kioskMode:n}=e,r=Ai(),a=i(Yf),o=i(Jt).state===qt.CLOSED,{saveOrNameNotebook:s,saveIfNotebookIsPersistent:c}=np(),l;t[0]!==n||t[1]!==c?(l={onSave:c,kioskMode:n},t[0]=n,t[1]=c,t[2]=l):l=t[2],sp(l),ra();let u;t[3]===a?u=t[4]:(u=e=>{if(a)return e.preventDefault(),e.returnValue=`You have unsaved changes. Are you sure you want to leave?`,e.returnValue},t[3]=a,t[4]=u),Rt(window,`beforeunload`,u);let d;t[5]===s?d=t[6]:(d=e=>{e.preventDefault(),e.stopPropagation(),s()},t[5]=s,t[6]=d);let f=d;if(_n(`global.save`,s),o){let e;return t[7]!==r||t[8]!==a?(e=(0,U.jsx)(Gf,{filename:r,needsSave:a}),t[7]=r,t[8]=a,t[9]=e):e=t[9],e}let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=Mi(`global.save`),t[10]=p):p=t[10];let m=a?`yellow`:`hint-green`,h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(tr,{strokeWidth:1.5,size:18}),t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==m?(g=(0,U.jsx)(cn,{content:p,children:(0,U.jsx)(na,{"data-testid":`save-button`,id:`save-button`,shape:`rectangle`,color:m,onClick:f,children:h})}),t[12]=f,t[13]=m,t[14]=g):g=t[14],g};function np(){let e=(0,H.c)(21),{sendSave:t}=hi(),{openModal:r,closeModal:i,openAlert:a}=Jn(),o=l(Jf),s=ji(),u=n(),d;e[0]!==a||e[1]!==t||e[2]!==o||e[3]!==u?(d=(e,n)=>ep(async()=>{let r=u.get(Jt),i=u.get(At);if(u.get(Ht))return;if(r.state!==qt.OPEN){a(`Failed to save notebook: not connected to a kernel.`);return}if(It.log(`saving to `,e),n&&i.format_on_save&&(It.log(`formatting notebook (onSave)`),await le()),ye(Me()).length===0)return;let s=await rt(async()=>{let n=Me(),r=ye(n),i=r.map(ap),a=r.map(ip),o=r.map(rp),s=Ce(n),c=u.get(Zn);return await t({cellIds:i,codes:a,names:o,filename:e,configs:s,layout:mn(),persist:!0}),{names:o,codes:a,configs:s,layout:c}});o(s)}),e[0]=a,e[1]=t,e[2]=o,e[3]=u,e[4]=d):d=e[4];let f=c(d),p;e[5]!==f||e[6]!==u?(p=e=>{let t=e!==void 0&&e,n=u.get(gt),r=u.get(Jt);op(n)&&r.state===qt.OPEN&&f(n,t)},e[5]=f,e[6]=u,e[7]=p):p=e[7];let m=c(p),h;e[8]!==f||e[9]!==s?(h=e=>{s(e).then(e=>{e!==null&&f(e,!0)})},e[8]=f,e[9]=s,e[10]=h):h=e[10];let g=h,_;e[11]!==i||e[12]!==g||e[13]!==r||e[14]!==m||e[15]!==u?(_=()=>{let e=u.get(gt),t=u.get(Jt);m(!0),!op(e)&&t.state!==qt.CLOSED&&r((0,U.jsx)(up,{onClose:i,onSave:g}))},e[11]=i,e[12]=g,e[13]=r,e[14]=m,e[15]=u,e[16]=_):_=e[16];let v=c(_),y;return e[17]!==m||e[18]!==f||e[19]!==v?(y={saveOrNameNotebook:v,saveIfNotebookIsPersistent:m,saveNotebook:f},e[17]=m,e[18]=f,e[19]=v,e[20]=y):y=e[20],y}function rp(e){return e.name}function ip(e){return e.code}function ap(e){return e.id}function op(e){return e!==null&&!e.startsWith(`/tmp/`)&&!e.startsWith(`/var/folders`)&&!e.includes(`AppData\\Local\\Temp`)}function sp(e){let n=(0,H.c)(14),r=i(At),a=C(),[o]=t(Jt),s=i(Yf),c,l;if(n[0]!==a){let e=ye(a);c=e.map(lp),l=e.map(cp),n[0]=a,n[1]=c,n[2]=l}else c=n[1],l=n[2];let u=l,d;n[3]===a?d=n[4]:(d=Ce(a),n[3]=a,n[4]=d);let f=d,p;n[5]!==r||n[6]!==u||n[7]!==c||n[8]!==f||n[9]!==o||n[10]!==s||n[11]!==e.kioskMode||n[12]!==e.onSave?(p={onSave:e.onSave,needsSave:s,codes:c,cellConfigs:f,cellNames:u,connStatus:o,config:r,kioskMode:e.kioskMode},n[5]=r,n[6]=u,n[7]=c,n[8]=f,n[9]=o,n[10]=s,n[11]=e.kioskMode,n[12]=e.onSave,n[13]=p):p=n[13],Zf(p)}function cp(e){return e.name}function lp(e){return e.code}var up=e=>{let t=(0,H.c)(17),{onClose:n,onSave:r}=e,[i,a]=(0,V.useState)(),o;t[0]!==n||t[1]!==r?(o=e=>{a(e),e.trim()&&(r(e),n())},t[0]=n,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,U.jsx)(cr,{children:`Save notebook`}),t[3]=c):c=t[3];let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,U.jsx)(an,{className:`text-md pt-6 px-1`,children:`Save as`}),t[4]=l):l=t[4];let u;t[5]===s?u=t[6]:(u=(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[l,(0,U.jsx)(Vf,{onNameChange:s,placeholderText:`filename`,className:`missing-filename`})]}),t[5]=s,t[6]=u);let d;t[7]===n?d=t[8]:(d=(0,U.jsx)(un,{"data-testid":`cancel-save-dialog-button`,"aria-label":`Cancel`,variant:`secondary`,onClick:n,children:`Cancel`}),t[7]=n,t[8]=d);let f=!i,p;t[9]===f?p=t[10]:(p=(0,U.jsx)(un,{"data-testid":`submit-save-dialog-button`,"aria-label":`Save`,variant:`default`,disabled:f,type:`submit`,children:`Save`}),t[9]=f,t[10]=p);let m;t[11]!==d||t[12]!==p?(m=(0,U.jsxs)(sr,{children:[d,p]}),t[11]=d,t[12]=p,t[13]=m):m=t[13];let h;return t[14]!==u||t[15]!==m?(h=(0,U.jsxs)(or,{children:[c,u,m]}),t[14]=u,t[15]=m,t[16]=h):h=t[16],h};function dp(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var fp={modified:{doc:``},original:{doc:``}},pp=(0,V.createContext)(fp);function mp(e,t){return z({},e,t,{modified:z({},e.modified,t.modified),original:z({},e.original,t.original)})}var hp=()=>(0,V.useContext)(pp),gp=e=>{var t=e.children,n=e.theme,r=(0,V.useReducer)(mp,z({},fp,{theme:n})),i=r[0],a=r[1];return(0,V.useEffect)(()=>a({theme:n}),[n]),(0,U.jsx)(pp.Provider,{value:z({},i,{dispatch:a}),children:t})},_p=[`extensions`,`value`,`selection`,`onChange`],vp=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,_p),s=hp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>l({original:{doc:r,selection:i,extensions:[...u,...n]},originalExtension:{onChange:a,option:o,extension:[n]}}),[e]),null};vp.displayName=`CodeMirrorMerge.Original`;var yp=[`extensions`,`value`,`selection`,`onChange`],bp=e=>{var t=e.extensions,n=t===void 0?[]:t,r=e.value,i=e.selection,a=e.onChange,o=Ei(e,yp),s=hp(),c=s.theme,l=s.dispatch,u=Fi(z({},o,{theme:c}));return(0,V.useEffect)(()=>{l({modified:{doc:r,selection:i,extensions:[...u,...n]},modifiedExtension:{onChange:a,option:o,extension:[n]}})},[e]),null};bp.displayName=`CodeMirrorMerge.Modified`;var xp=[`className`,`children`,`orientation`,`revertControls`,`highlightChanges`,`gutter`,`collapseUnchanged`,`destroyRerender`,`renderRevertControl`,`diffConfig`,`root`],Sp=[`modified`,`modifiedExtension`,`original`,`originalExtension`,`theme`,`dispatch`],Cp=V.forwardRef((e,t)=>{var n=e.className,r=e.children,i=e.orientation,a=e.revertControls,o=e.highlightChanges,s=e.gutter,c=e.collapseUnchanged,l=e.destroyRerender,u=l===void 0||l,d=e.renderRevertControl,f=e.diffConfig,p=e.root,m=Ei(e,xp),h=hp(),g=h.modified,_=h.modifiedExtension,v=h.original,y=h.originalExtension,b=h.theme,x=h.dispatch,S=Ei(h,Sp),C=(0,V.useRef)(null),w=(0,V.useRef)(),T={orientation:i,revertControls:a,highlightChanges:o,gutter:s,collapseUnchanged:c,renderRevertControl:d,diffConfig:f,root:p};(0,V.useImperativeHandle)(t,()=>({container:C.current,view:w.current,modified:g,original:v,config:z({a:v,b:g,parent:C.current},T)}),[C,w,g,v,T]);var E=R.updateListener.of(e=>{if(e.docChanged&&typeof y?.onChange==`function`){var t=e.state.doc.toString();y?.onChange(t,e)}}),D=R.updateListener.of(e=>{if(e.docChanged&&typeof _?.onChange==`function`){var t=e.state.doc.toString();_?.onChange(t,e)}});return(0,V.useEffect)(()=>{!w.current&&C.current&&y&&_&&(w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b})),E]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b})),D]}),parent:C.current},T)),x({view:w.current}))},[w,C,y,_]),(0,V.useEffect)(()=>{if(v&&v.doc&&w.current){var e=w.current?.a.state.doc.toString();if(e!==v.doc){var t;(t=w.current)==null||t.a.dispatch({changes:{from:0,to:e.length,insert:v.doc||``}})}}if(g&&g.doc&&w.current){var n=w.current?.b.state.doc.toString();if(n!==g.doc){var r;(r=w.current)==null||r.b.dispatch({changes:{from:0,to:n.length,insert:g.doc||``}})}}if(u&&w.current){var i=w.current.a.state.selection.ranges[0].from,a=w.current.b.state.selection.ranges[0].from;w.current.destroy(),w.current=new Ii(z({a:z({},v,{extensions:[...y?.extension||[],...Fi(z({},y?.option,{theme:b}))]}),b:z({},g,{extensions:[..._?.extension||[],...Fi(z({},_?.option,{theme:b}))]}),parent:C.current},T)),i&&(w.current.a.focus(),w.current.a.dispatch({selection:{anchor:i,head:i}})),a&&(w.current.b.focus(),w.current.b.dispatch({selection:{anchor:a,head:a}}))}},[w,b,C.current,v,g,y,_,u]),(0,V.useEffect)(()=>()=>w.current&&w.current.destroy(),[]),(0,V.useEffect)(()=>{if(w.current){var e={};S.orientation!==i&&(e.orientation=i),S.revertControls!==a&&(e.revertControls=a),S.highlightChanges!==o&&(e.highlightChanges=o),S.gutter!==s&&(e.gutter=s),S.collapseUnchanged!==c&&(e.collapseUnchanged=c),S.renderRevertControl!==d&&(e.collapseUnchanged=c),Object.keys(e).length&&x&&w.current&&(w.current.reconfigure(z({},e)),x(z({},e)))}},[x,w,i,a,o,s,c,d]),(0,U.jsx)(`div`,z({ref:C,className:`cm-merge-theme`+(n?` `+n:``)},m,{children:r}))});Cp.displayName=`CodeMirrorMerge.Internal`;var wp=[`theme`],Tp=V.forwardRef((e,t)=>{var n=e.theme,r=Ei(e,wp);return(0,U.jsx)(gp,{theme:n,children:(0,U.jsx)(Cp,z({},r,{ref:t}))})});Tp.Original=vp,Tp.Modified=bp,Tp.displayName=`CodeMirrorMerge`;var Ep=Tp.Original,Dp=Tp.Modified,Op=[se(),R.lineWrapping],kp=({cellId:e,aiCompletionCell:n,className:r,onChange:i,currentLanguageAdapter:a,currentCode:o,declineChange:s,acceptChange:c,runCell:l,outputArea:u,children:d})=>{let[p,m]=(0,V.useState)(!1),[h,g]=t(Oi),_=(0,V.useId)(),v=Yt(),{initialPrompt:y,triggerImmediately:x,cellId:C}=n??{},w=C===e,T=An(e),E;T?.type===`update_cell`&&(E=T.previousCode);let[D,O]=(0,V.useState)(``),[ee,k]=(0,V.useState)(y??``),te=V.useMemo(()=>new Tn({api:v.getAiURL(`completion`).toString(),headers:()=>v.headers(),prepareSendMessagesRequest:({body:e,id:t})=>({body:{...e,id:t}})}),[v]),{sendMessage:ne,stop:re,status:A}=Un({throttle:100,transport:te,onData:e=>{if(e.type===En){let t=On.parse(e.data);O(t.code.trimEnd())}},onError:e=>{O(``),ur({title:`Completion failed`,description:Ti(e)})},onFinish:({isAbort:e,isDisconnect:t,isError:n,finishReason:r})=>{(e||t||n||r!==`stop`)&&O(``)}}),j=A===`submitted`||A===`streaming`,ie=(0,V.useCallback)(()=>{O(``),re()},[re]),M=(0,V.useCallback)(async e=>{await re(),O(``);let t={...Mn({input:e}),prompt:e,includeOtherCode:h?ce(o):``,code:o,language:a??`python`};await ne({text:e},{body:t})},[o,a,h,ne,re]),N=(0,V.useCallback)(()=>{M(ee)},[M,ee]),P=V.useRef(null),ae=(0,V.useCallback)(()=>{x&&!j&&y&&M(y)},[x]);(0,V.useEffect)(()=>{w&&(S(()=>{let e=P.current;return e?.view?(e.view.focus(),ae(),!0):!1},{retries:3,delay:100,initialDelay:100}),b(P.current?.view))},[w,ae]),(0,V.useEffect)(()=>{w&&k(y||``)},[w,y,k]);let{theme:oe}=yi(),se=()=>{c(D),O(``)},le=()=>{ie(),m(!0),P.current?.view?.focus()},ue=w&&x&&(D||j);u??=`below`;let de=w&&(!x||p),fe=(0,U.jsx)(`div`,{className:en(`w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden`,ue?`max-h-20 opacity-100 translate-y-0`:`max-h-0 opacity-0 -translate-y-2`),children:(0,U.jsx)(Ap,{status:j?`loading`:`generated`,onAccept:se,onReject:le,showInputPrompt:p,setShowInputPrompt:m,runCell:l,className:`mt-4 mb-3 w-lg`})}),pe=(e,t)=>(0,U.jsxs)(Tp,{className:`cm`,theme:oe,children:[(0,U.jsx)(Ep,{onChange:i,value:e,extensions:Op}),(0,U.jsx)(Dp,{value:t,editable:!1,readOnly:!0,extensions:Op})]}),me=()=>{if(D&&w)return pe(o,D);if(!D&&E)return pe(E,o)},he=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ln,{isLoading:j,onAccept:se,size:`xs`,multipleCompletions:!1,label:Bn.accept,acceptShortcut:`Mod-↵`,runCell:l}),(0,U.jsx)(zn,{onDecline:le,size:`xs`,multipleCompletions:!1,label:Bn.decline,declineShortcut:`Shift-Mod-Delete`})]});return(0,U.jsxs)(`div`,{"data-ai-input-open":de,className:en(`flex flex-col w-full rounded-[inherit]`,r),children:[(0,U.jsx)(`div`,{className:en(`flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300`,de&&`max-h-[400px] border-b min-h-11 visible`,!de&&`max-h-0 min-h-0 invisible`),children:w&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Ye,{className:`text-(--blue-10) shrink-0`,size:16}),(0,U.jsx)(Rn,{inputRef:P,className:`h-full my-0 py-2 flex items-center`,onClose:()=>{ie(),s()},value:ee,onChange:k,onSubmit:()=>{j||(P.current?.view&&jn(P.current.view),N())},onKeyDown:Vn({handleAcceptCompletion:se,handleDeclineCompletion:le,isLoading:j,hasCompletion:D.trim().length>0})}),(0,U.jsxs)(`div`,{className:`-mr-1.5 py-1.5`,children:[(0,U.jsxs)(`div`,{className:`flex flex-row items-center justify-end gap-0.5`,children:[(0,U.jsx)(In,{isLoading:j,onStop:ie,onSendClick:N,isEmpty:!ee.trim(),showStopLabel:!0}),(0,U.jsx)(Fn,{handleAddContext:()=>Hn(P),isLoading:j}),(0,U.jsx)(bn,{triggerClassName:`h-7 text-xs`,iconSize:`small`,forRole:`edit`,displayIconOnly:!0,placeholder:`Edit model`})]}),D&&(0,U.jsx)(`div`,{className:`mt-1 flex items-center gap-1`,children:he})]}),(0,U.jsx)(`div`,{className:`h-full w-px bg-border mx-2`}),(0,U.jsx)(cn,{content:`Include code from other cells`,children:(0,U.jsxs)(`div`,{className:`flex flex-row items-start gap-1 overflow-hidden`,children:[(0,U.jsx)(f,{"data-testid":`include-other-cells-checkbox`,id:_,checked:h,onCheckedChange:e=>g(!!e)}),(0,U.jsx)(an,{htmlFor:_,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`All code`})]})}),(0,U.jsx)(un,{"aria-label":`Discard AI completion`,"data-testid":`decline-completion-button`,variant:`text`,size:`icon`,disabled:j,onClick:()=>{ie(),s()},children:(0,U.jsx)(Cn,{className:`text-(--red-10)`,size:16})})]})}),u===`above`&&fe,me(),(!D||!w)&&!E&&d,u===`below`&&fe]})},Ap=e=>{let t=(0,H.c)(27),{status:n,onAccept:r,onReject:i,className:a,showInputPrompt:o,setShowInputPrompt:s,runCell:c}=e,l=n===`loading`,u;t[0]===a?u=t[1]:(u=en(`flex flex-row items-center gap-6 rounded-md py-2 px-2.5 text-sm border border-border bg-(--gray-2) dark:bg-(--gray-3)`,a),t[0]=a,t[1]=u);let d;t[2]===l?d=t[3]:(d=l?(0,U.jsx)(Yn,{className:`animate-spin text-blue-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Generating fix`}):(0,U.jsx)(wn,{className:`text-green-600 mb-px`,size:15,strokeWidth:2,"aria-label":`Fix generated`}),t[2]=l,t[3]=d);let f=l?`Generating fix...`:`Showing fix`,p;t[4]===f?p=t[5]:(p=(0,U.jsx)(`p`,{className:`transition-opacity duration-200 text-muted-foreground`,children:f}),t[4]=f,t[5]=p);let m;t[6]!==d||t[7]!==p?(m=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2`,children:[d,p]}),t[6]=d,t[7]=p,t[8]=m):m=t[8];let h;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(an,{htmlFor:`show-input-prompt`,className:`text-muted-foreground text-xs whitespace-nowrap ellipsis`,children:`Show prompt`}),t[9]=h):h=t[9];let g;t[10]!==s||t[11]!==o?(g=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-1`,children:[h,(0,U.jsx)(sn,{checked:o,onCheckedChange:s,size:`xs`})]}),t[10]=s,t[11]=o,t[12]=g):g=t[12];let _;t[13]!==l||t[14]!==r||t[15]!==c?(_=(0,U.jsx)(Ln,{isLoading:l,onAccept:r,size:`xs`,label:Bn.accept,runCell:c}),t[13]=l,t[14]=r,t[15]=c,t[16]=_):_=t[16];let v;t[17]===i?v=t[18]:(v=(0,U.jsx)(zn,{onDecline:i,size:`xs`,label:Bn.decline}),t[17]=i,t[18]=v);let y;t[19]!==_||t[20]!==v?(y=(0,U.jsxs)(`div`,{className:`flex flex-row items-center gap-2 ml-auto`,children:[_,v]}),t[19]=_,t[20]=v,t[21]=y):y=t[21];let b;return t[22]!==u||t[23]!==y||t[24]!==m||t[25]!==g?(b=(0,U.jsxs)(`div`,{className:u,children:[m,g,y]}),t[22]=u,t[23]=y,t[24]=m,t[25]=g,t[26]=b):b=t[26],b},jp=`web application/x-marimo-cell`,Mp=xt({cells:wt(xt({code:yt(),name:yt().optional(),config:xt({column:Ct([bt(),Tt()]).optional(),disabled:vt().optional(),hide_code:vt().optional(),expand_output:vt().optional()}).optional()})),version:St(`1.0`)});function Np(e){return e.map(e=>e.code).join(`
40
40
 
41
41
  `)}async function Pp(e){let t={cells:e.map(e=>({code:e.code,name:e.name,config:e.config})),version:`1.0`},n=new Bp().add(jp,t).add(`text/plain`,Np(e)).build();await navigator.clipboard.write([n])}function Fp(){let e=(0,H.c)(13),t=y(),n=Te(),r=qe(),i;e[0]===n?i=e[1]:(i=async e=>{let t=Me(),r=e.map(e=>t.cellData[e]).filter(Boolean);if(r.length!==0)try{await Pp(r),n.clear(),Ip(r.length)}catch(e){let t=e;It.error(`Failed to copy cells to clipboard`,t);try{await lr(Np(r)),n.clear(),Ip(r.length)}catch{Lp()}}},e[0]=n,e[1]=i);let a=c(i),o;e[2]===n?o=e[3]:(o=async e=>{let t=Me(),r=e.filter(e=>t.cellData[e]),i=r.map(e=>t.cellData[e]);if(i.length!==0)try{await Pp(i),n.markForCut({cellIds:r})}catch(e){let t=e;It.error(`Failed to cut cells to clipboard`,t);try{await lr(Np(i)),n.markForCut({cellIds:r})}catch{Lp()}}},e[2]=n,e[3]=o);let s=c(o),l;e[4]!==t||e[5]!==n||e[6]!==r.cellIds?(l=async(e,i)=>{let{before:a}=i??{},o=a!==void 0&&a;if(r.cellIds.size>0){let i=[...r.cellIds],a=Me(),s=i.map(e=>{let t=a.cellIds.findWithId(e);return{columnId:t.id,index:t.indexOfOrThrow(e)}});t.moveCellsRelativeTo({cellIds:i,targetCellId:e,position:o?`before`:`after`,previousPlacements:s}),n.clear();return}try{let n=await navigator.clipboard.read();for(let r of n)if(r.types.includes(jp)){let n=await(await r.getType(jp)).text();try{let r=Mp.parse(JSON.parse(n));if(r.cells.length===0)break;let i=e,a=r.cells.toReversed();for(let e of a)t.createNewCell({cellId:i,before:o,code:e.code,name:e.name,config:e.config,hideCode:e.config?.hide_code,autoFocus:!0});return}catch(e){let t=e;It.warn(`Failed to parse clipboard cell data`,t)}}let r=await navigator.clipboard.readText();r.trim()?t.createNewCell({cellId:e,before:o,code:r,autoFocus:!0}):Rp()}catch(e){let t=e;It.error(`Failed to paste from clipboard`,t),zp()}},e[4]=t,e[5]=n,e[6]=r.cellIds,e[7]=l):l=e[7];let u=c(l),d;return e[8]!==a||e[9]!==s||e[10]!==u||e[11]!==n.clear?(d={copyCells:a,cutCells:s,pasteAtCell:u,clearPendingCut:n.clear},e[8]=a,e[9]=s,e[10]=u,e[11]=n.clear,e[12]=d):d=e[12],d}var Ip=e=>{let t=e===1?`Cell`:`${e} cells`;ur({title:`${t} copied`,description:`${t} ${e===1?`has`:`have`} been copied to clipboard.`})},Lp=()=>{ur({title:`Copy failed`,description:`Failed to copy cells to clipboard.`,variant:`danger`})},Rp=()=>{ur({title:`Nothing to paste`,description:`No cell or text found in clipboard.`,variant:`danger`})},zp=()=>{ur({title:`Paste failed`,description:`Failed to read from clipboard`,variant:`danger`})},Bp=class{items={};add(e,t){return ClipboardItem.supports(e)?typeof t==`string`?(this.items[e]=new Blob([t],{type:e}),this):(this.items[e]=new Blob([JSON.stringify(t)],{type:e}),this):(It.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}};function Vp(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:Hp,createActions:Up,valueAtom:Wp,useActions:Gp}=ii(Vp,{select:(e,t)=>({selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])}),extend:(e,t)=>{if(!e.selectionStart)return{selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])};let{cellId:n,allCellIds:r}=t;try{let t=r.findWithId(e.selectionStart),i=t.indexOfOrThrow(e.selectionStart),a=t.indexOfOrThrow(n),[o,s]=i<a?[i,a]:[a,i],c=t.slice(o,s+1);return{selectionStart:e.selectionStart,selectionEnd:n,selected:new Set(c)}}catch{return{selectionStart:n,selectionEnd:n,selected:new Set([n])}}},clear:e=>e.selected.size===0?e:Vp()}),Kp=()=>i(Wp);function qp(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=r(t=>t(Wp).selected.has(e)),t[0]=e,t[1]=n),i(n)}function Jp(){return Gp()}function Yp(e){return e.get(Wp).selected}var{valueAtom:Xp,useActions:Zp}=ii(()=>new Set,{add:(e,t)=>{if(e.has(t))return e;let n=new Set(e);return n.add(t),n},remove:(e,t)=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),T(()=>{let e=document.activeElement;if(!e)return;let t=mt.findElementThroughShadowDOMs(e);t&&N(mt.parse(t.id))}),n}}),Qp=e=>r(t=>t(Xp).has(e));function $p(e){let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=Qp(e),t[0]=e,t[1]=n),i(n)}var em=new WeakMap,tm=500;function nm(e){if(e.ctrlKey||e.metaKey||e.altKey)return``;let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function rm(e,t){let n=nm(e),r=e.target;if(!n||!r)return!1;let i=em.get(r),a=n;i?.timeout&&clearTimeout(i.timeout),i&&(a=`${i.sequence} ${n}`);let o=t[a];if(o)return em.delete(r),o();if(!i){let e=t[n];if(e)return e()}if(Object.keys(t).some(e=>e.startsWith(`${a} `))){let e=window.setTimeout(()=>{em.delete(r)},tm);return em.set(r,{sequence:a,timeout:e}),!0}return em.delete(r),!1}function im(e){return{handle:t=>e(t),bulkHandle:t=>{let n=!0;try{for(let r of t)n&&=e(r);return n}catch{return!1}}}}function am(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function om(e,t){let n=(0,H.c)(12),r=D(),i=y(),a=Zp(),o;n[0]!==e||n[1]!==r?(o=()=>{r.focusCell({cellId:e})},n[0]=e,n[1]=r,n[2]=o):o=n[2];let s;n[3]!==i||n[4]!==e||n[5]!==t||n[6]!==r||n[7]!==a?(s=n=>{sm(n.relatedTarget)||sm(n.target)||cm(n.relatedTarget)!==e&&cm(n.relatedTarget?.closest(`[data-for-cell-id]`))!==e&&(a.remove(e),i.markTouched({cellId:e}),r.blurCell(),t.current&&pm(t.current))},n[3]=i,n[4]=e,n[5]=t,n[6]=r,n[7]=a,n[8]=s):s=n[8];let c;n[9]!==o||n[10]!==s?(c={onFocusWithin:o,onBlurWithin:s},n[9]=o,n[10]=s,n[11]=c):c=n[11];let{focusWithinProps:l}=rr(c);return l}function sm(e){return e?e instanceof HTMLElement&&e.closest(`.cm-vim-panel`)!==null:!1}function cm(e){return e&&e.getAttribute(ee)||null}function lm(e,t){let r=(0,H.c)(34),{canMoveX:a,editorView:o,cellActionDropdownRef:s}=t,{saveOrNameNotebook:c}=np(),{saveCellConfig:u}=hi(),d=l(ki),f=y(),p=n(),h=Zp(),g=Ci(),_=i(kt),{copyCells:v,pasteAtCell:b,cutCells:x}=Fp(),S=Jp(),C=qp(e),w=$a(),T=$n(),E=i(Ot),D;r[0]===E?D=r[1]:(D=jt(E),r[0]=E,r[1]=D);let O=D,ee;r[2]!==w||r[3]!==S?(ee={clear:()=>{w.clear(),S.clear()},extend:e=>{w.clear(),S.extend(e)},select:e=>{w.clear(),S.select(e)}},r[2]=w,r[3]=S,r[4]=ee):ee=r[4];let k=ee,te=i(Mt),ne;r[5]===te?ne=r[6]:(ne=(e,t)=>Lt(te.getHotkey(e).key)(t.nativeEvent||t),r[5]=te,r[6]=ne);let re=ne,A=om(e,o),j;r[7]!==f||r[8]!==O||r[9]!==a||r[10]!==s||r[11]!==e||r[12]!==v||r[13]!==x||r[14]!==T||r[15]!==o||r[16]!==C||r[17]!==re||r[18]!==_||r[19]!==b||r[20]!==w||r[21]!==g||r[22]!==u||r[23]!==c||r[24]!==k||r[25]!==d||r[26]!==p||r[27]!==h||r[28]!==E?(j={onKeyDown:t=>{if(ln.fromInput(t)){t.continuePropagation();return}let n={"Mod+ArrowUp":()=>(f.focusTopCell(),k.clear(),!0),"Mod+ArrowDown":()=>(f.focusBottomCell(),k.clear(),!0),ArrowUp:()=>(f.focusCell({cellId:e,where:`before`}),k.clear(),!0),ArrowDown:()=>(f.focusCell({cellId:e,where:`after`}),k.clear(),!0),ArrowLeft:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r-1);if(i&&i.length>0){let t=fm(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},ArrowRight:()=>{if(a){let t=p.get(he),n=t.cellIds.findWithId(e),r=t.cellIds.indexOf(n),i=t.cellIds.at(r+1);if(i&&i.length>0){let t=fm(e,i);return f.focusCell({cellId:t,where:`exact`}),k.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).before(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`before`}),!0},"Shift+ArrowDown":()=>{let t=p.get(Fe);k.extend({cellId:e,allCellIds:t});let n=t.findWithId(e).after(e);return n&&k.extend({cellId:n,allCellIds:t}),f.focusCell({cellId:e,where:`after`}),!0},Escape:()=>p.get(at).size>0?(p.set(ze),!0):C?(k.clear(),!0):!1,Enter:()=>(h.add(e),ae(p,e),k.clear(),!0),s:()=>(c(),!0)};for(let[e,r]of Object.entries(n))if(Lt(e)(t)&&r()){t.preventDefault();return}let r={"cell.run":am(e=>(g(e),!0)),"cell.runAndNewBelow":am(e=>{g(e);let t=e[e.length-1];return f.moveToNextCell({cellId:t,before:!1}),!0}),"cell.runAndNewAbove":am(e=>{g(e);let t=e[0];return f.moveToNextCell({cellId:t,before:!0}),!0}),"cell.createAbove":e=>(f.createNewCell({cellId:e,before:!0}),!0),"cell.createBelow":e=>(f.createNewCell({cellId:e,before:!1}),!0),"cell.moveUp":am(e=>{let t=e[0];return p.get(he).cellIds.findWithId(t).first()!==t&&(e.forEach(e=>{f.moveCell({cellId:e,before:!0})}),!0)}),"cell.moveDown":am(e=>{let t=e[e.length-1];return p.get(he).cellIds.findWithId(t).last()!==t&&(e.toReversed().forEach(e=>{f.moveCell({cellId:e,before:!1})}),!0)}),"cell.moveLeft":im(e=>a?(f.moveCell({cellId:e,direction:`left`}),!0):!1),"cell.moveRight":im(e=>a?(f.moveCell({cellId:e,direction:`right`}),!0):!1),"cell.hideCode":am(e=>{let t=!e.map(e=>p.get(he).cellData[e]?.config||null).every(um);u({configs:Object.fromEntries(e.map(e=>[e,{hide_code:t}]))});for(let n of e)f.updateCellConfig({cellId:n,config:{hide_code:t}});if(e.length===1){let n=e[0];f.focusCell({cellId:n,where:`after`}),t?(o.current?.contentDOM.blur(),ie(n)):ae(p,n)}return!0}),"cell.focusDown":e=>(f.focusCell({cellId:e,where:`after`}),!0),"cell.focusUp":e=>(f.focusCell({cellId:e,where:`before`}),!0),"cell.sendToBottom":am(e=>(e.forEach(e=>{f.sendToBottom({cellId:e})}),!0)),"cell.sendToTop":am(e=>(e.toReversed().forEach(e=>{f.sendToTop({cellId:e})}),!0)),"cell.aiCompletion":e=>{if(!O)return!1;let t=!1;return d(n=>n?.cellId===e?(t=!0,null):{cellId:e}),t&&o.current?.focus(),!0},"cell.cellActions":()=>(s.current?.toggle(),!0),"command.copyCell":am(e=>(v(e),!0)),"command.cutCell":am(e=>(x(e),!0)),"command.pasteCell":e=>(b(e),!0),"command.createCellBefore":e=>!ln.hasModifier(t)&&(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),"command.createCellAfter":e=>!ln.hasModifier(t)&&(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"command.createSqlCellAfter":e=>!ln.hasModifier(t)&&(m({autoInstantiate:!0,createNewCell:f.createNewCell,fromCellId:e,before:!0}),f.createNewCell({cellId:e,before:!1,autoFocus:!0,code:P.sql.defaultCode}),!0),"cell.delete":()=>{if(!E.keymap.destructive_delete)return!1;let t=i.size>=2?[...i]:[e],n=p.get(he);return t.some(e=>{let{status:t}=n.cellRuntime[e];return t===`running`||t===`queued`})?!1:w.idle?(w.submit(t),!0):(T({cellIds:t}),w.clear(),!0)}},i=Yp(p);if(_===`vim`&&rm(t.nativeEvent||t,{j:n.ArrowDown,k:n.ArrowUp,h:n.ArrowLeft,l:n.ArrowRight,i:n.Enter,"shift+j":n[`Shift+ArrowDown`],"shift+k":n[`Shift+ArrowUp`],"g g":n[`Mod+ArrowUp`],"shift+g":n[`Mod+ArrowDown`],"d d":()=>r[`cell.delete`](),"y y":()=>(v(i.size>=2?[...i]:[e]),!0),p:()=>(b(e,{before:!1}),!0),"shift+p":()=>(b(e,{before:!0}),!0),o:()=>(f.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"shift+o":()=>(f.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),u:()=>(f.undoDeleteCell(),!0)})){t.preventDefault();return}for(let[n,a]of Object.entries(r))if(re(n,t)){if(typeof a==`function`){if(a(e)){t.preventDefault();return}}else if(i.size>=2?a.bulkHandle([...i]):a.handle(e)){t.preventDefault();return}return}t.continuePropagation()}},r[7]=f,r[8]=O,r[9]=a,r[10]=s,r[11]=e,r[12]=v,r[13]=x,r[14]=T,r[15]=o,r[16]=C,r[17]=re,r[18]=_,r[19]=b,r[20]=w,r[21]=g,r[22]=u,r[23]=c,r[24]=k,r[25]=d,r[26]=p,r[27]=h,r[28]=E,r[29]=j):j=r[29];let{keyboardProps:M}=nr(j),N;return r[30]!==A||r[31]!==C||r[32]!==M?(N=ir(A,M,{"data-selected":C,className:`data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1`}),r[30]=A,r[31]=C,r[32]=M,r[33]=N):N=r[33],N}function um(e){return e?.hide_code}function dm(e,t){let n=(0,H.c)(12),r=Zp(),a=i(kt),o=i(Mt),s;if(n[0]!==o){let e=o.getHotkey(`command.vimEnterCommandMode`);s=Lt(e.key),n[0]=o,n[1]=s}else s=n[1];let c=s,l;n[2]!==e||n[3]!==r?(l=()=>{r.remove(e),ie(e),T(()=>{N(e)})},n[2]=e,n[3]=r,n[4]=l):l=n[4];let u=l,d;n[5]!==t||n[6]!==u?(d=()=>{if(!t.current){u();return}let e=t.current,n=e.state;if(Jr(e))return;let r=!!n.field(ft,!1)||!!n.field(Se,!1),i=ui(n)!==null;r&&pm(e),i&&fi(e),!(r||i)&&u()},n[5]=t,n[6]=u,n[7]=d):d=n[7];let f=d,p;n[8]!==f||n[9]!==a||n[10]!==c?(p={onKeyDown:e=>{a===`vim`?c(e)&&f():e.key===`Escape`&&f(),e.continuePropagation()}},n[8]=f,n[9]=a,n[10]=c,n[11]=p):p=n[11];let{keyboardProps:m}=nr(p);return m}function fm(e,t){let n=document.getElementById(mt.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let e of t.topLevelIds){let t=document.getElementById(mt.create(e));if(t){let n=t.getBoundingClientRect();if(r.top<=n.bottom&&r.bottom>=n.top)return e}}return t.last()}function pm(e){e.state.field(ft,!1)&&e.dispatch({effects:ge.of(null)}),et(e)}var mm=50,hm=4,gm=60;function _m(e){return Math.min(gm,Math.max(hm,e))}var vm=e=>{let t=(0,H.c)(13),{code:n,className:r}=e,i,a,o,s;if(t[0]!==r||t[1]!==n){let e=n.split(`
42
- `,mm);t[6]===r?i=t[7]:(i=en(`cm`,`mo-code-placeholder`,r),t[6]=r,t[7]=i),a=`cell-editor-placeholder`,o=!0,s=e.map(ym),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s}else i=t[2],a=t[3],o=t[4],s=t[5];let c;return t[8]!==i||t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,U.jsx)(`div`,{className:i,"data-testid":a,"aria-hidden":o,children:s}),t[8]=i,t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c};function ym(e,t){let n=e.trimEnd().length;return(0,U.jsx)(`div`,{className:`mo-code-placeholder-line`,children:n>0&&(0,U.jsx)(Li,{className:`mo-code-placeholder-bar`,style:{width:`${_m(n)}ch`}})},t)}var bm=e=>{let t=(0,H.c)(25),{editorViewRef:n,code:r,currentLanguageAdapter:i,onAfterToggle:a,className:o}=e,s=o===void 0?`absolute right-3 top-2 z-20 flex hover-action gap-1`:o,c;t[0]===r?c=t[1]:(c=P.markdown.isSupported(r)||r.trim()===``,t[0]=r,t[1]=c);let l=c,u;t[2]===r?u=t[3]:(u=P.sql.isSupported(r)||r.trim()===``,t[2]=r,t[3]=u);let d=u&&i===`python`,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(fn,{color:`var(--sky-11)`,strokeWidth:2.5,className:`w-4 h-4`}),t[4]=f):f=t[4];let p;t[5]!==i||t[6]!==n||t[7]!==a||t[8]!==d?(p=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:d,icon:f,toType:`sql`,displayName:`SQL`,onAfterToggle:a}),t[5]=i,t[6]=n,t[7]=a,t[8]=d,t[9]=p):p=t[9];let m=l&&i===`python`,h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(Pi,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[10]=h):h=t[10];let g;t[11]!==i||t[12]!==n||t[13]!==a||t[14]!==m?(g=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:m,icon:h,toType:`markdown`,displayName:`Markdown`,onAfterToggle:a}),t[11]=i,t[12]=n,t[13]=a,t[14]=m,t[15]=g):g=t[15];let _;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,U.jsx)(Ni,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[16]=_):_=t[16];let v;t[17]!==i||t[18]!==n?(v=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:!0,icon:_,toType:`python`,displayName:`Python`,onAfterToggle:Pt.NOOP}),t[17]=i,t[18]=n,t[19]=v):v=t[19];let y;return t[20]!==s||t[21]!==v||t[22]!==p||t[23]!==g?(y=(0,U.jsxs)(`div`,{className:s,children:[p,g,v]}),t[20]=s,t[21]=v,t[22]=p,t[23]=g,t[24]=y):y=t[24],y},xm=e=>{let t=(0,H.c)(10),{editorViewRef:n,currentLanguageAdapter:r,canSwitchToLanguage:i,icon:a,toType:o,displayName:s,onAfterToggle:c}=e,l;t[0]!==n||t[1]!==c||t[2]!==o?(l=()=>{let e=n.current;e&&(lt(e,{language:o}),c())},t[0]=n,t[1]=c,t[2]=o,t[3]=l):l=t[3];let u=l;if(!i||r===o)return null;let d=`View as ${s}`,f;t[4]!==u||t[5]!==a?(f=(0,U.jsx)(un,{"data-testid":`language-toggle-button`,variant:`text`,size:`xs`,className:`opacity-80 px-1`,onClick:u,children:a}),t[4]=u,t[5]=a,t[6]=f):f=t[6];let p;return t[7]!==d||t[8]!==f?(p=(0,U.jsx)(cn,{content:d,children:f}),t[7]=d,t[8]=f,t[9]=p):p=t[9],p};function Sm(e,t,n){return n?{code:n.code,extensions:[...t,n.extension]}:{code:e,extensions:t}}var Cm=({theme:e,showPlaceholder:n,id:r,config:a,code:o,status:s,serializedEditorState:l,setEditorView:u,runCell:d,userConfig:f,editorViewRef:p,editorViewParentRef:h,hidden:g,hasOutput:v,showHiddenCode:b,languageAdapter:x,setLanguageAdapter:S,showLanguageToggles:C=!0,inlineAiTooltip:w,outputArea:T,tooltipParentSelector:E})=>{let[D,O]=t(ki),ee=er(),{saveOrNameNotebook:k}=np(),te=$a(),{saveCellConfig:ne}=hi(),re=s===`running`||s===`queued`,A=y(),j=Bi(),ie=x===`markdown`,M=c(()=>re?!1:te.idle&&f.keymap.destructive_delete?(te.submit([r]),!0):(ee({cellId:r}),!0)),N=c(()=>!re&&(d(),p.current&&pm(p.current),!0)),P=c(()=>{let e=!a.hide_code;return ne({configs:{[r]:{hide_code:e}}}),A.updateCellConfig({cellId:r,config:{hide_code:e}}),e}),ae=i(Nt),oe=i(yn),se=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell}),a.hide_code||(ne({configs:{[r]:{hide_code:!0}}}),A.updateCellConfig({cellId:r,config:{hide_code:!0}}),A.markUntouched({cellId:r}))}),ce=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell})}),le=jt(f),ue=(0,V.useMemo)(()=>{let t=Vd({cellId:r,showPlaceholder:n,enableAI:le,cellActions:{...A,afterToggleMarkdown:se,afterToggleSQL:ce,onRun:N,deleteCell:M,saveNotebook:k,createManyBelow:e=>{for(let t of e.toReversed())A.createNewCell({code:t,before:!1,cellId:r,skipIfCodeExists:!0})},addOrAppendSetupCell:e=>{let t=Me();if(!t.cellIds.setupCellExists()){A.addSetupCellIfDoesntExist({code:e});return}let n=Qe(t)[_],r=n?we(n):t.cellData[_].code,i=r.trim()?`${r.trimEnd()}\n\n${e}`:e;n&&Oe(n,i),A.updateCellCode({cellId:_,code:i,formattingChange:!1})},splitCell:j,toggleHideCode:P,aiCellCompletion:()=>{if(!le)return!1;let e=!1;return O(t=>t?.cellId===r?(e=!0,null):{cellId:r}),e}},completionConfig:f.completion,acceptCompletionOnEnter:oe,keymapConfig:f.keymap,lspConfig:f.language_servers,theme:e,hotkeys:new Ft(f.keymap.overrides??{}),diagnosticsConfig:f.diagnostics,displayConfig:f.display,inlineAiTooltip:w??f.ai?.inline_tooltip??!1,tooltipParentSelector:E});return t.push(Hr.define(e=>(S(e.state.field(Pe).type),{update(e){S(e.state.field(Pe).type)}})),R.updateListener.of(e=>{e.selectionSet&&e.state.selection.ranges.some(e=>e.from!==e.to)&&b({focus:!1})}),R.domEventHandlers({focus:()=>{b({focus:!1})}})),t},[r,oe,f.keymap,f.completion,f.language_servers,f.display,f.diagnostics,f.ai?.inline_tooltip,w,E,le,e,n,A,j,P,M,N,O,se,ce,S,b,k]),de=me()&&Ie(r),fe=e=>{if(!de)return Sm(o,ue,void 0);let t=If(r,e=>{A.updateCellCode({cellId:r,code:e,formattingChange:!0})},e);return Sm(o,ue,t)},pe=c(()=>{let e=fe(o),t=new R({state:vr.create({doc:e.code,extensions:e.extensions})});u(t),de||lt(t,{language:He(t.state).type})}),he=c(()=>{zt(p.current!==null,`Editor view is not initialized`);let e=fe();p.current.dispatch({effects:[I.reconfigure.of([e.extensions]),je(p.current,{completionConfig:f.completion,hotkeysProvider:new Ft(f.keymap.overrides??{}),lspConfig:{...f.language_servers,diagnostics:f.diagnostics}})]})}),ge=c(()=>{zt(l,`Editor view is not initialized`);let e=fe(o),t=new R({state:vr.fromJSON(l,{doc:e.code,extensions:e.extensions},{history:Kr})});de||lt(t,{language:He(t.state).type}),u(t),A.clearSerializedEditorState({cellId:r})}),[_e,ve]=(0,V.useState)(l!==null);(0,V.useEffect)(()=>{if(p.current!==null){ve(!0);return}if(ve(!1),l!==null){ge(),ve(!0);return}return ut.request(r,()=>{p.current===null&&(pe(),ve(!0))}),()=>ut.cancel(r)},[r,p,ge,pe,l]),(0,V.useEffect)(()=>{p.current!==null&&he()},[he,ue,p]),(0,V.useEffect)(()=>()=>{p.current?.destroy(),p.current=null},[p]);let[ye,be]=rn({rootMargin:`300px 0px`,threshold:0});(0,V.useEffect)(()=>{_e||(be?.isIntersecting?ut.prioritize(r):ut.deprioritize(r))},[_e,be?.isIntersecting,r]);let xe=dm(r,p),Se=``;return ie&&g&&v?Se=`h-0 overflow-hidden`:g&&(Se=`opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden`),(0,U.jsx)(kp,{cellId:r,aiCompletionCell:D,currentCode:p.current?.state.doc.toString()??o,currentLanguageAdapter:x,declineChange:c(()=>{O(null),p.current?.focus()}),onChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}})}),acceptChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}}),p.current?.focus(),O(null)}),runCell:N,outputArea:T,children:(0,U.jsxs)(`div`,{className:`relative w-full`,ref:ye,...xe,children:[_e?(0,U.jsx)(wm,{className:Se,editorView:p.current,ref:h,hidden:g,showHiddenCode:b}):(0,U.jsx)(vm,{code:o,className:Se}),!g&&C&&(0,U.jsx)(`div`,{className:`absolute top-1 right-5`,children:(0,U.jsx)(bm,{code:o,editorViewRef:p,currentLanguageAdapter:x,onAfterToggle:se})})]})})},wm=V.forwardRef((e,t)=>{let n=(0,H.c)(14),{className:r,editorView:i,hidden:a,showHiddenCode:o}=e,s=(0,V.useRef)(null),c,l;n[0]===i?(c=n[1],l=n[2]):(c=()=>{i!==null&&s.current!==null&&s.current.children.length===0&&s.current.append(i.dom)},l=[i,s],n[0]=i,n[1]=c,n[2]=l),(0,V.useEffect)(c,l);let u;n[3]===r?u=n[4]:(u=en(`cm mathjax_ignore`,r),n[3]=r,n[4]=u);let d;n[5]!==a||n[6]!==o?(d=e=>{a&&o&&(e.stopPropagation(),o({focus:!0}))},n[5]=a,n[6]=o,n[7]=d):d=n[7];let f;n[8]===t?f=n[9]:(f=e=>{t?dp(t,s)(e):dp(s)(e)},n[8]=t,n[9]=f);let p;return n[10]!==u||n[11]!==d||n[12]!==f?(p=(0,U.jsx)(`div`,{className:u,onDoubleClick:d,ref:f,"data-testid":`cell-editor`}),n[10]=u,n[11]=d,n[12]=f,n[13]=p):p=n[13],p});wm.displayName=`CellCodeMirrorEditor`;function Tm(e){let n=n=>{let r=(0,H.c)(5),a=i(Jt),[o,s]=t(Nf);if(me()&&Ie(n.id)&&(Xt(a.state)||o===void 0)){let e;r[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,U.jsx)(`span`,{children:`Waiting for real-time collaboration connection...`}),r[0]=e):e=r[0];let t;return r[1]===s?t=r[2]:(t=(0,U.jsx)(`div`,{className:`flex h-full w-full items-baseline p-4`,children:(0,U.jsxs)(nn,{milliseconds:1e3,fallback:null,children:[e,(0,U.jsx)(un,{variant:`link`,onClick:()=>{s(`disabled`)},children:`Turn off real-time collaboration`})]})}),r[1]=s,r[2]=t),t}let c;return r[3]===n?c=r[4]:(c=(0,U.jsx)(e,{...n}),r[3]=n,r[4]=c),c};return n.displayName=`WithWaitUntilConnected(${e.displayName})`,n}var Em=me()?Tm((0,V.memo)(Cm)):(0,V.memo)(Cm);export{fd as _,Zp as a,$a as b,dp as c,Jf as d,Vf as f,dd as g,hd as h,$p as i,tp as l,gd as m,bm as n,Jp as o,Nf as p,lm as r,Kp as s,Em as t,np as u,ud as v,eo as y};
42
+ `,mm);t[6]===r?i=t[7]:(i=en(`cm`,`mo-code-placeholder`,r),t[6]=r,t[7]=i),a=`cell-editor-placeholder`,o=!0,s=e.map(ym),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s}else i=t[2],a=t[3],o=t[4],s=t[5];let c;return t[8]!==i||t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,U.jsx)(`div`,{className:i,"data-testid":a,"aria-hidden":o,children:s}),t[8]=i,t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c};function ym(e,t){let n=e.trimEnd().length;return(0,U.jsx)(`div`,{className:`mo-code-placeholder-line`,children:n>0&&(0,U.jsx)(Li,{className:`mo-code-placeholder-bar`,style:{width:`${_m(n)}ch`}})},t)}var bm=e=>{let t=(0,H.c)(25),{editorViewRef:n,code:r,currentLanguageAdapter:i,onAfterToggle:a,className:o}=e,s=o===void 0?`absolute right-3 top-2 z-20 flex hover-action gap-1`:o,c;t[0]===r?c=t[1]:(c=P.markdown.isSupported(r)||r.trim()===``,t[0]=r,t[1]=c);let l=c,u;t[2]===r?u=t[3]:(u=P.sql.isSupported(r)||r.trim()===``,t[2]=r,t[3]=u);let d=u&&i===`python`,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,U.jsx)(fn,{color:`var(--sky-11)`,strokeWidth:2.5,className:`w-4 h-4`}),t[4]=f):f=t[4];let p;t[5]!==i||t[6]!==n||t[7]!==a||t[8]!==d?(p=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:d,icon:f,toType:`sql`,displayName:`SQL`,onAfterToggle:a}),t[5]=i,t[6]=n,t[7]=a,t[8]=d,t[9]=p):p=t[9];let m=l&&i===`python`,h;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,U.jsx)(Pi,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[10]=h):h=t[10];let g;t[11]!==i||t[12]!==n||t[13]!==a||t[14]!==m?(g=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:m,icon:h,toType:`markdown`,displayName:`Markdown`,onAfterToggle:a}),t[11]=i,t[12]=n,t[13]=a,t[14]=m,t[15]=g):g=t[15];let _;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,U.jsx)(Ni,{fill:`var(--sky-11)`,color:`black`,className:`w-4 h-4`}),t[16]=_):_=t[16];let v;t[17]!==i||t[18]!==n?(v=(0,U.jsx)(xm,{editorViewRef:n,currentLanguageAdapter:i,canSwitchToLanguage:!0,icon:_,toType:`python`,displayName:`Python`,onAfterToggle:Pt.NOOP}),t[17]=i,t[18]=n,t[19]=v):v=t[19];let y;return t[20]!==s||t[21]!==v||t[22]!==p||t[23]!==g?(y=(0,U.jsxs)(`div`,{className:s,children:[p,g,v]}),t[20]=s,t[21]=v,t[22]=p,t[23]=g,t[24]=y):y=t[24],y},xm=e=>{let t=(0,H.c)(10),{editorViewRef:n,currentLanguageAdapter:r,canSwitchToLanguage:i,icon:a,toType:o,displayName:s,onAfterToggle:c}=e,l;t[0]!==n||t[1]!==c||t[2]!==o?(l=()=>{let e=n.current;e&&(lt(e,{language:o}),c())},t[0]=n,t[1]=c,t[2]=o,t[3]=l):l=t[3];let u=l;if(!i||r===o)return null;let d=`View as ${s}`,f;t[4]!==u||t[5]!==a?(f=(0,U.jsx)(un,{"data-testid":`language-toggle-button`,variant:`text`,size:`xs`,className:`opacity-80 px-1`,onClick:u,children:a}),t[4]=u,t[5]=a,t[6]=f):f=t[6];let p;return t[7]!==d||t[8]!==f?(p=(0,U.jsx)(cn,{content:d,children:f}),t[7]=d,t[8]=f,t[9]=p):p=t[9],p};function Sm(e,t,n){return n?{code:n.code,extensions:[...t,n.extension]}:{code:e,extensions:t}}var Cm=({theme:e,showPlaceholder:n,id:r,config:a,code:o,status:s,serializedEditorState:l,setEditorView:u,runCell:d,userConfig:f,editorViewRef:p,editorViewParentRef:h,hidden:g,hasOutput:v,showHiddenCode:b,languageAdapter:x,setLanguageAdapter:S,showLanguageToggles:C=!0,inlineAiTooltip:w,outputArea:T,tooltipParentSelector:E})=>{let[D,O]=t(ki),ee=er(),{saveOrNameNotebook:k}=np(),te=$a(),{saveCellConfig:ne}=hi(),re=s===`running`||s===`queued`,A=y(),j=Bi(),ie=x===`markdown`,M=c(()=>re?!1:te.idle&&f.keymap.destructive_delete?(te.submit([r]),!0):(ee({cellId:r}),!0)),N=c(()=>!re&&(d(),p.current&&pm(p.current),!0)),P=c(()=>{let e=!a.hide_code;return ne({configs:{[r]:{hide_code:e}}}),A.updateCellConfig({cellId:r,config:{hide_code:e}}),e}),ae=i(Nt),oe=i(yn),se=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell}),a.hide_code||(ne({configs:{[r]:{hide_code:!0}}}),A.updateCellConfig({cellId:r,config:{hide_code:!0}}),A.markUntouched({cellId:r}))}),ce=c(()=>{m({autoInstantiate:ae,createNewCell:A.createNewCell})}),le=jt(f),ue=(0,V.useMemo)(()=>{let t=Vd({cellId:r,showPlaceholder:n,enableAI:le,cellActions:{...A,afterToggleMarkdown:se,afterToggleSQL:ce,onRun:N,deleteCell:M,saveNotebook:k,createManyBelow:e=>{for(let t of e.toReversed())A.createNewCell({code:t,before:!1,cellId:r,skipIfCodeExists:!0})},addOrAppendSetupCell:e=>{let t=Me();if(!t.cellIds.setupCellExists()){A.addSetupCellIfDoesntExist({code:e});return}let n=Qe(t)[_],r=n?we(n):t.cellData[_].code,i=r.trim()?`${r.trimEnd()}\n\n${e}`:e;n&&Oe(n,i),A.updateCellCode({cellId:_,code:i,formattingChange:!1})},splitCell:j,toggleHideCode:P,aiCellCompletion:()=>{if(!le)return!1;let e=!1;return O(t=>t?.cellId===r?(e=!0,null):{cellId:r}),e}},completionConfig:f.completion,acceptCompletionOnEnter:oe,keymapConfig:f.keymap,lspConfig:f.language_servers,theme:e,hotkeys:new Ft(f.keymap.overrides??{}),diagnosticsConfig:f.diagnostics,displayConfig:f.display,inlineAiTooltip:w??f.ai?.inline_tooltip??!1,tooltipParentSelector:E});return t.push(Hr.define(e=>(S(e.state.field(Pe).type),{update(e){S(e.state.field(Pe).type)}})),R.updateListener.of(e=>{e.selectionSet&&e.state.selection.ranges.some(e=>e.from!==e.to)&&b({focus:!1})}),R.domEventHandlers({focus:()=>{b({focus:!1})}})),t},[r,oe,f.keymap,f.completion,f.language_servers,f.display,f.diagnostics,f.ai?.inline_tooltip,w,E,le,e,n,A,j,P,M,N,O,se,ce,S,b,k]),de=me()&&Ie(r),fe=e=>{if(!de)return Sm(o,ue,void 0);let t=If(r,e=>{A.updateCellCode({cellId:r,code:e,formattingChange:!0})},e);return Sm(o,ue,t)},pe=c(()=>{let e=fe(o),t=new R({state:vr.create({doc:e.code,extensions:e.extensions})});u(t),de||lt(t,{language:He(t.state).type})}),he=c(()=>{zt(p.current!==null,`Editor view is not initialized`);let e=fe();p.current.dispatch({effects:[I.reconfigure.of([e.extensions]),je(p.current,{completionConfig:f.completion,hotkeysProvider:new Ft(f.keymap.overrides??{}),lspConfig:{...f.language_servers,diagnostics:f.diagnostics}})]})}),ge=c(()=>{zt(l,`Editor view is not initialized`);let e=fe(o),t=new R({state:vr.fromJSON(l,{doc:e.code,extensions:e.extensions},{history:Kr})});de||lt(t,{language:He(t.state).type}),u(t),A.clearSerializedEditorState({cellId:r})}),[_e,ve]=(0,V.useState)(l!==null);(0,V.useEffect)(()=>{if(p.current!==null){ve(!0);return}if(ve(!1),l!==null){ge(),ve(!0);return}return ut.request(r,()=>{p.current===null&&(pe(),ve(!0))}),()=>ut.cancel(r)},[r,p,ge,pe,l]),(0,V.useEffect)(()=>{p.current!==null&&he()},[he,ue,p]),(0,V.useEffect)(()=>()=>{p.current?.destroy(),p.current=null},[p]);let[ye,be]=nn({rootMargin:`300px 0px`,threshold:0});(0,V.useEffect)(()=>{_e||(be?.isIntersecting?ut.prioritize(r):ut.deprioritize(r))},[_e,be?.isIntersecting,r]);let xe=dm(r,p),Se=``;return ie&&g&&v?Se=`h-0 overflow-hidden`:g&&(Se=`opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden`),(0,U.jsx)(kp,{cellId:r,aiCompletionCell:D,currentCode:p.current?.state.doc.toString()??o,currentLanguageAdapter:x,declineChange:c(()=>{O(null),p.current?.focus()}),onChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}})}),acceptChange:c(e=>{p.current?.dispatch({changes:{from:0,to:p.current.state.doc.length,insert:e}}),p.current?.focus(),O(null)}),runCell:N,outputArea:T,children:(0,U.jsxs)(`div`,{className:`relative w-full`,ref:ye,...xe,children:[_e?(0,U.jsx)(wm,{className:Se,editorView:p.current,ref:h,hidden:g,showHiddenCode:b}):(0,U.jsx)(vm,{code:o,className:Se}),!g&&C&&(0,U.jsx)(`div`,{className:`absolute top-1 right-5`,children:(0,U.jsx)(bm,{code:o,editorViewRef:p,currentLanguageAdapter:x,onAfterToggle:se})})]})})},wm=V.forwardRef((e,t)=>{let n=(0,H.c)(14),{className:r,editorView:i,hidden:a,showHiddenCode:o}=e,s=(0,V.useRef)(null),c,l;n[0]===i?(c=n[1],l=n[2]):(c=()=>{i!==null&&s.current!==null&&s.current.children.length===0&&s.current.append(i.dom)},l=[i,s],n[0]=i,n[1]=c,n[2]=l),(0,V.useEffect)(c,l);let u;n[3]===r?u=n[4]:(u=en(`cm mathjax_ignore`,r),n[3]=r,n[4]=u);let d;n[5]!==a||n[6]!==o?(d=e=>{a&&o&&(e.stopPropagation(),o({focus:!0}))},n[5]=a,n[6]=o,n[7]=d):d=n[7];let f;n[8]===t?f=n[9]:(f=e=>{t?dp(t,s)(e):dp(s)(e)},n[8]=t,n[9]=f);let p;return n[10]!==u||n[11]!==d||n[12]!==f?(p=(0,U.jsx)(`div`,{className:u,onDoubleClick:d,ref:f,"data-testid":`cell-editor`}),n[10]=u,n[11]=d,n[12]=f,n[13]=p):p=n[13],p});wm.displayName=`CellCodeMirrorEditor`;function Tm(e){let n=n=>{let r=(0,H.c)(5),a=i(Jt),[o,s]=t(Nf);if(me()&&Ie(n.id)&&(Xt(a.state)||o===void 0)){let e;r[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,U.jsx)(`span`,{children:`Waiting for real-time collaboration connection...`}),r[0]=e):e=r[0];let t;return r[1]===s?t=r[2]:(t=(0,U.jsx)(`div`,{className:`flex h-full w-full items-baseline p-4`,children:(0,U.jsxs)(rn,{milliseconds:1e3,fallback:null,children:[e,(0,U.jsx)(un,{variant:`link`,onClick:()=>{s(`disabled`)},children:`Turn off real-time collaboration`})]})}),r[1]=s,r[2]=t),t}let c;return r[3]===n?c=r[4]:(c=(0,U.jsx)(e,{...n}),r[3]=n,r[4]=c),c};return n.displayName=`WithWaitUntilConnected(${e.displayName})`,n}var Em=me()?Tm((0,V.memo)(Cm)):(0,V.memo)(Cm);export{fd as _,Zp as a,$a as b,dp as c,Jf as d,Vf as f,dd as g,hd as h,$p as i,tp as l,gd as m,bm as n,Jp as o,Nf as p,lm as r,Kp as s,Em as t,np as u,ud as v,eo as y};
@@ -0,0 +1 @@
1
+ import{c as e,l as t,t as n,u as r}from"./useEvent-BDjgaBtz.js";import{D as i,In as a,M as o,P as s,U as c,gr as l,xo as u,za as d}from"./cells-SvbLY10y.js";import{t as f}from"./compiler-runtime-BrajqUja.js";import{p}from"./config-CXnC3MRv.js";import{g as m}from"./useEventListener-DPOTkksd.js";import{i as h}from"./utils-B4K466FK.js";import{c as g}from"./session-BHgGkjDm.js";import{T as _,_ as v}from"./config-7IjqNuVp.js";import{t as y}from"./cn-ldLVeaqm.js";import{t as b}from"./jsx-runtime-B74pBk57.js";import{r as x}from"./button-Cl7haVNh.js";import{n as S}from"./paths-bkIFVj8h.js";import{b as C}from"./write-secret-modal-CBi2vNK_.js";import{r as w}from"./requests-BIFR-h4M.js";var T=f();function E(){return t(d)}function D(){let t=(0,T.c)(5),[i]=e(v),a=r(d),{openAlert:o}=C(),{sendRename:s}=w(),c;return t[0]!==i.state||t[1]!==o||t[2]!==s||t[3]!==a?(c=async e=>{let t=p();return i.state===_.OPEN?(g(t=>{e===null?t.delete(h.filePath):t.set(h.filePath,e)}),s({filename:e}).then(()=>(a(e),document.title=t.app_title||S.basename(e)||`Untitled Notebook`,e)).catch(e=>(o(e.message),null))):(o(`Failed to save notebook: not connected to a kernel.`),null)},t[0]=i.state,t[1]=o,t[2]=s,t[3]=a,t[4]=c):c=t[4],n(c)}var O=b(),k=e=>{let t=(0,T.c)(15),{className:n,cellId:r,variant:l,onClick:d,formatCellName:f,skipScroll:p}=e,m=s()[r]??``,h=o().inOrderIds.indexOf(r),{showCellIfHidden:g}=i(),_=f??N,v;t[0]===r?v=t[1]:(v=r===`__scratch__`?void 0:`#${u.create(r)}`,t[0]=r,t[1]=v);let b;t[2]===n?b=t[3]:(b=y(`inline-block cursor-pointer text-left text-link hover:underline focus-visible:outline focus-visible:outline-ring`,n),t[2]=n,t[3]=b);let S;t[4]!==r||t[5]!==d||t[6]!==g||t[7]!==p||t[8]!==l?(S=e=>{if(!(e.defaultPrevented||e.button!==0||x.hasModifier(e))){if(r===`__scratch__`)return!1;g({cellId:r}),e.stopPropagation(),e.preventDefault(),requestAnimationFrame(()=>{M(r,l,p)&&(c(r,{preventScroll:!0}),d?.())})}},t[4]=r,t[5]=d,t[6]=g,t[7]=p,t[8]=l,t[9]=S):S=t[9];let C=_(a(m,h)),w;return t[10]!==v||t[11]!==b||t[12]!==S||t[13]!==C?(w=(0,O.jsx)(`a`,{href:v,className:b,onClick:S,children:C}),t[10]=v,t[11]=b,t[12]=S,t[13]=C,t[14]=w):w=t[14],w},A=e=>{let t=(0,T.c)(2),n;return t[0]===e?n=t[1]:(n=(0,O.jsx)(k,{...e,variant:`destructive`}),t[0]=e,t[1]=n),n},j=e=>{let t=(0,T.c)(10),{cellId:n,lineNumber:r}=e,i=E(),a;t[0]!==n||t[1]!==r?(a=()=>l(n,r),t[0]=n,t[1]=r,t[2]=a):a=t[2];let o;t[3]!==n||t[4]!==i?(o=e=>n===`__scratch__`?`scratch`:`marimo://${i||`untitled`}#cell=${e}`,t[3]=n,t[4]=i,t[5]=o):o=t[5];let s;return t[6]!==n||t[7]!==a||t[8]!==o?(s=(0,O.jsx)(k,{cellId:n,onClick:a,skipScroll:!0,variant:`destructive`,className:`traceback-cell-link`,formatCellName:o}),t[6]=n,t[7]=a,t[8]=o,t[9]=s):s=t[9],s};function M(e,t,n){let r=u.create(e),i=document.getElementById(r),a=i?.classList.contains(`has-error`);return i===null?(m.error(`Cell ${r} not found on page.`),!1):(n||i.scrollIntoView({behavior:`smooth`,block:`center`}),(t===`destructive`||a&&t===void 0)&&(i.classList.add(`error-outline`),setTimeout(()=>{i.classList.remove(`error-outline`)},2e3)),(t===`focus`||!a&&t===void 0)&&(i.classList.add(`focus-outline`),setTimeout(()=>{i.classList.remove(`focus-outline`)},2e3)),!0)}function N(e){return e}export{E as a,M as i,A as n,D as o,j as r,k as t};
@@ -217,4 +217,4 @@ mark line col
217
217
  )
218
218
  `]));let n=this._buffer.match(this._osc_regex);if(n===null)return e.kind=zj.ESC,e.text=this._buffer.slice(0,1),this._buffer=this._buffer.slice(1),e;e.kind=zj.OSCURL,e.url=n[1],e.text=n[2];var i=n[0].length;return this._buffer=this._buffer.slice(i),e}if(r==`(`)return e.kind=zj.Unknown,this._buffer=this._buffer.slice(3),e}}ansi_to_html(e){this.append_buffer(e);for(var t=[];;){var n=this.get_next_packet();if(n.kind==zj.EOS||n.kind==zj.Incomplete)break;n.kind!=zj.ESC&&n.kind!=zj.Unknown&&(n.kind==zj.Text?t.push(this.transform_to_html(this.with_state(n))):n.kind==zj.SGR?this.process_ansi(n):n.kind==zj.OSCURL&&t.push(this.process_hyperlink(n)))}return t.join(``)}with_state(e){return{bold:this.bold,faint:this.faint,italic:this.italic,underline:this.underline,fg:this.fg,bg:this.bg,text:e.text}}process_ansi(e){let t=e.text.split(`;`);for(;t.length>0;){let e=t.shift(),n=parseInt(e,10);if(isNaN(n)||n===0)this.fg=null,this.bg=null,this.bold=!1,this.faint=!1,this.italic=!1,this.underline=!1;else if(n===1)this.bold=!0;else if(n===2)this.faint=!0;else if(n===3)this.italic=!0;else if(n===4)this.underline=!0;else if(n===21)this.bold=!1;else if(n===22)this.faint=!1,this.bold=!1;else if(n===23)this.italic=!1;else if(n===24)this.underline=!1;else if(n===39)this.fg=null;else if(n===49)this.bg=null;else if(n>=30&&n<38)this.fg=this.ansi_colors[0][n-30];else if(n>=40&&n<48)this.bg=this.ansi_colors[0][n-40];else if(n>=90&&n<98)this.fg=this.ansi_colors[1][n-90];else if(n>=100&&n<108)this.bg=this.ansi_colors[1][n-100];else if((n===38||n===48)&&t.length>0){let e=n===38,r=t.shift();if(r===`5`&&t.length>0){let n=parseInt(t.shift(),10);n>=0&&n<=255&&(e?this.fg=this.palette_256[n]:this.bg=this.palette_256[n])}if(r===`2`&&t.length>2){let n=parseInt(t.shift(),10),r=parseInt(t.shift(),10),i=parseInt(t.shift(),10);if(n>=0&&n<=255&&r>=0&&r<=255&&i>=0&&i<=255){let t={rgb:[n,r,i],class_name:`truecolor`};e?this.fg=t:this.bg=t}}}}}transform_to_html(e){let t=e.text;if(t.length===0||(t=this.escape_txt_for_html(t),!e.bold&&!e.italic&&!e.faint&&!e.underline&&e.fg===null&&e.bg===null))return t;let n=[],r=[],i=e.fg,a=e.bg;e.bold&&n.push(this._boldStyle),e.faint&&n.push(this._faintStyle),e.italic&&n.push(this._italicStyle),e.underline&&n.push(this._underlineStyle),this._use_classes?(i&&(i.class_name===`truecolor`?n.push(`color:rgb(${i.rgb.join(`,`)})`):r.push(`${i.class_name}-fg`)),a&&(a.class_name===`truecolor`?n.push(`background-color:rgb(${a.rgb.join(`,`)})`):r.push(`${a.class_name}-bg`))):(i&&n.push(`color:rgb(${i.rgb.join(`,`)})`),a&&n.push(`background-color:rgb(${a.rgb})`));let o=``,s=``;return r.length&&(o=` class="${r.join(` `)}"`),n.length&&(s=` style="${n.join(`;`)}"`),`<span${s}${o}>${t}</span>`}process_hyperlink(e){let t=e.url.split(`:`);return t.length<1||!this._url_allowlist[t[0]]?``:`<a href="${this.escape_txt_for_html(e.url)}">${this.escape_txt_for_html(e.text)}</a>`}};function Vj(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n)}function Hj(e,...t){let n=e.raw[0].replace(/^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm,``);return new RegExp(n,`g`)}var Uj,Wj,Gj,Kj=new Bj;function qj(e){try{let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).split(`
219
219
  `).map(e=>e.trimEnd()).join(`
220
- `)}catch(t){return R.error(`Error parsing HTML content:`,t),e}}function Jj(e){if(!e)return``;try{return qj(Kj.ansi_to_html(e))}catch(t){return R.error(`Error converting ANSI to plain text:`,t),e}}var Yj=o(null);function Xj(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var Zj=!1;function Qj(e){let t=[],n=[e.console].filter(Boolean).flat();for(let r of n){let n=r.mimetype===`text/plain`,i=r.mimetype===`text/html`||r.mimetype===`application/vnd.marimo+traceback`;if(n||i){let n=r.channel===`stderr`||r.channel===`marimo-error`;switch(r.channel){case`stdout`:case`stderr`:case`marimo-error`:{let a=Vr.asString(r.data),o=i?qj(a):a;t.push({timestamp:r.timestamp||Date.now(),level:n?`stderr`:`stdout`,message:o,source:{type:`cell`,cellId:e.cell_id}});break}}}}if(t.forEach($j.log),n.length===0&&uf(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{$j.log({level:`stderr`,source:{type:`cell`,cellId:e.cell_id},timestamp:e.timestamp??0,message:JSON.stringify(t)})});let t=e.output.data.filter(e=>`type`in e&&e.type===`exception`||e.type===`internal`),n=u.get(fe)===`read`;if(t.length>0&&!Zj&&n){Zj=!0;let e=t.find(e=>e.traceback);sn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:K.createElement(vt,{altText:`View traceback`,onClick:()=>{u.set(Yj,{traceback:e.traceback,errorMessage:e.msg||`An internal error occurred`})}},`View`)}:{title:`An internal error occurred`,description:`See console for details.`,variant:`danger`})}}return t}var $j={log:e=>{let t=e.level===`stdout`?`gray`:e.level===`stderr`?`red`:`orange`,n=e.level.toUpperCase();console.log(`%c[${n}]`,`color:${t}; padding:2px 0; border-radius:2px; font-weight:bold`,`[${eM(e.timestamp)}]`,`(${Xj(e.source)}) ${e.message}`)}};function eM(e){try{return Lj(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function tM(e,t){let n=uN(t);n?n.focus():R.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function nM(e){let t=document.getElementById(Li.create(e));t?aM(t):R.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function rM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function iM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function aM(e){try{e.focus()}catch{R.warn(`[CellFocusManager] element may not be focusable`,e)}}function oM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){R.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function sM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Li.create(e));if(!a){R.warn(`scrollCellIntoView: element not found`);return}if(iM()){aM(a);return}if(n)aM(a);else{Hs.promote(e);let n=t.current?.editorView;if(!n){R.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(oM(()=>(n.focus(),n.hasFocus),{retries:5,delay:20}),r===`top`)n.dispatch({selection:{anchor:0,head:0}});else if(r===`bottom`){let e=n.state.doc.line(n.state.doc.lines);n.dispatch({selection:{anchor:e.from,head:e.from}})}else i&&z_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function cM(e){let t=document.getElementById(Li.create(e));if(!t){R.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function lM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function uM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function dM(e){let t=uN(e);if(t?.hasFocus){wh(t,{behavior:`instant`});return}let n=document.getElementById(Li.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):R.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function fM({id:e,name:t=`_`,code:n=``,lastCodeRun:r=null,lastExecutionTime:i=null,edited:a=!1,config:o,serializedEditorState:s=null}){return{id:e,config:o||{hide_code:!1,disabled:!1,column:null,expand_output:!1},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function pM(e){return{hide_code:!1,disabled:!1,column:null,expand_output:!1,...e}}function mM(e){return{outline:null,output:null,consoleOutputs:[],status:`idle`,staleInputs:!1,interrupted:!1,errored:!1,stopped:!1,runElapsedTimeMs:null,runStartTimestamp:null,lastRunStartTimestamp:null,debuggerActive:!1,...e}}function hM(e){let t={column:0,hide_code:!1,disabled:!1,expand_output:!1};return{...e,cellData:{[Pi]:fM({id:Pi,config:t}),...e.cellData},cellRuntime:{[Pi]:mM(),...e.cellRuntime},cellHandles:{[Pi]:(0,K.createRef)(),...e.cellHandles}}}function gM(){return hM({cellIds:_s.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:_M,addMiddleware:vM,createActions:yM,useActions:bM,valueAtom:xM}=jr(gM,{createNewCell:(e,t)=>{let{cellId:n,before:r,code:i,name:a,config:o,lastCodeRun:s=null,lastExecutionTime:c=null,autoFocus:l=!0,skipIfCodeExists:u=!1,hideCode:d=void 0}=t,f,p;if(u){for(let t of e.cellIds.inOrderIds)if(e.cellData[t]?.code===i)return e}if(n===`__end__`){let t=e.cellIds.atOrThrow(0);f=t.id,p=t.length}else if(typeof n==`string`){let t=e.cellIds.findWithId(n);f=t.id,p=t.topLevelIds.indexOf(n)}else if(n.type===`__end__`){let t=e.cellIds.get(n.columnId)||e.cellIds.atOrThrow(0);f=t.id,p=t.length}else throw Error(`Invalid cellId`);let m=t.newCellId||Ii.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:fM({id:m,code:i,name:a,lastCodeRun:s,config:pM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:mM()},cellHandles:{...e.cellHandles,[m]:(0,K.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&R.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?Er(a-1,0,n.length-1):i===`after`?Er(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return sM({cellId:s,cell:e.cellHandles[s],isCodeHidden:SM(e,s),codeFocus:i===`after`?`top`:`bottom`,variableName:void 0}),e},focusTopCell:e=>{let t=e.cellIds.getColumns().at(0);if(t===void 0||t.length===0)return e;let n=t.first();return sM({cellId:n,cell:e.cellHandles[n],isCodeHidden:SM(e,n),codeFocus:void 0,variableName:void 0}),uM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return sM({cellId:n,cell:e.cellHandles[n],isCodeHidden:SM(e,n),codeFocus:void 0,variableName:void 0}),lM(),e},sendToTop:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r);return a===0?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,0),scrollKey:i?r:null}},sendToBottom:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r),o=n.length-1;return a===o?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,o),scrollKey:i?r:null}},addColumn:(e,t)=>{let n=Ii.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:fM({id:n})},cellRuntime:{...e.cellRuntime,[n]:mM()},cellHandles:{...e.cellHandles,[n]:(0,K.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return R.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:ir});s&&(s.doc=e.cellData[n].code),aN(n);let c=e.cellData[n];return{...e,cellIds:e.cellIds.deleteById(n),history:[...e.history,{type:`delete`,name:c.name,serializedEditorState:s,column:r.id,index:i,isSetupCell:n===Fi,config:c.config}],scrollKey:o}},undoDeleteCell:e=>{if(e.history.length===0)return e;let t=e.history[e.history.length-1];if(t.type===`move`){let{cellIds:n,placements:r}=t;if(n.length===0||r.length!==n.length||n.some(t=>!e.cellData[t]))return{...e,history:e.history.slice(0,-1)};let i=n.map((e,t)=>({id:e,columnId:r[t].columnId,index:r[t].index}));return{...e,cellIds:e.cellIds.placeCells(i),history:e.history.slice(0,-1),scrollKey:n[0]??null}}let{name:n,serializedEditorState:r={doc:``},column:i,index:a,isSetupCell:o,config:s}=t,c=o?Fi:Ii.create(),l=fM({id:c,name:n,code:r.doc,edited:r.doc.trim().length>0,serializedEditorState:r,config:s});return{...e,cellIds:e.cellIds.insertId(c,i,a),cellData:{...e.cellData,[c]:l},cellRuntime:{...e.cellRuntime,[c]:mM()},cellHandles:{...e.cellHandles,[c]:(0,K.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?wM({state:e,cellId:n,cellReducer:e=>i?{...e,code:r,lastCodeRun:e.edited?e.lastCodeRun:r}:{...e,code:r,edited:r.trim()!==e.lastCodeRun}}):e},updateCellName:(e,t)=>{let{cellId:n,name:r}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,config:pM({...e.config,...r})})})},prepareForRun:(e,t)=>wM({state:CM({state:e,cellId:t.cellId,cellReducer:e=>nj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=CM({state:e,cellId:n,cellReducer:e=>tj(e,t)});return t.status===`queued`&&(r=wM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...Qj(t)]}},addLogs:(e,t)=>({...e,cellLogs:[...e.cellLogs,...t.logs]}),setCellIds:(e,t)=>{if(l(e.cellIds.inOrderIds,t.cellIds))return e;let n={...e.cellData},r={...e.cellRuntime},i={...e.cellHandles};for(let a of t.cellIds)a in e.cellData||(n[a]=fM({id:a})),a in e.cellRuntime||(r[a]=mM()),a in e.cellHandles||(i[a]=(0,K.createRef)());return{...e,cellIds:_s.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=_s.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{B(t.codes.length===t.ids.length,`Expected codes and ids to have the same length`);let n={...e},r=({cell:e,code:r,cellId:i,name:a,config:o})=>{if(!e)return fM({id:i,code:r,name:a,config:o,lastCodeRun:t.codeIsStale?null:r,edited:t.codeIsStale&&r.trim().length>0});let s=t.codeIsStale?e.lastCodeRun:r,c=s?s.trim()!==r.trim():!!r;if(e.code.trim()===r.trim())return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}};if(!HA()||!UA(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&kA(e.editorViewOrNull,r)}return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}}};for(let e=0;e<t.ids.length;e++){let i=t.ids[e],a=t.codes[e];if(i===void 0||a===void 0)continue;let o=t.names?.[e],s=t.configs?.[e];n={...n,cellData:{...n.cellData,[i]:r({cell:n.cellData[i],code:a,cellId:i,name:o,config:s})}}}return n},setStdinResponse:(e,t)=>{let{cellId:n,response:r,outputIndex:i}=t;return CM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(R.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,id:n.id,response:n.mimetype===`text/password`?``:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=_e(),i=t=>{if(!r)return mM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:mM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return hM({...e,cellIds:_s.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,K.createRef)()]))})},moveToNextCell:(e,t)=>{let{cellId:n,before:r,noCreate:i=!1}=t;if(n===`__scratch__`)return e;let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=r?o-1:o+1,c=s===a.length,l=s===-1;if(c&&!i){let t=Ii.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:fM({id:t})},cellRuntime:{...e.cellRuntime,[t]:mM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if(l&&!i){let t=Ii.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:fM({id:t})},cellRuntime:{...e.cellRuntime,[t]:mM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);sM({cellId:t,cell:e.cellHandles[t],isCodeHidden:SM(e,t),codeFocus:r?`bottom`:`top`,variableName:void 0})}return e},markTouched:(e,t)=>{let{cellId:n}=t;if(e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.delete(n),{...e,untouchedNewCells:t}}return e},markUntouched:(e,t)=>{let{cellId:n}=t;if(!e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.add(n),{...e,untouchedNewCells:t}}return e},scrollToTarget:e=>{let t=e.scrollKey;if(t===null)return e;let n=e.cellIds.findWithId(t),r=n.indexOfOrThrow(t),i=r===n.length-1?n.last():n.atOrThrow(r);return sM({cellId:i,cell:e.cellHandles[i],isCodeHidden:SM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(Ls(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Rs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),clearLogs:e=>({...e,cellLogs:[]}),collapseCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.topLevelIds.map(t=>e.cellRuntime[t].outline),a=BA(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=BA(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=AA(o.editorView);kA(o.editorView,s);let l=Ii.create();return{...e,cellIds:e.cellIds.insertId(l,r.id,i+1),cellData:{...e.cellData,[n]:{...a,code:s,edited:!!s&&s.trim()!==a.lastCodeRun?.trim()},[l]:fM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:mM()},cellHandles:{...e.cellHandles,[l]:(0,K.createRef)()},scrollKey:l}},undoSplitCell:(e,t)=>{let{cellId:n,snapshot:r}=t,i=e.cellData[n],a=e.cellHandles[n].current;return a?.editorView==null?e:(kA(a.editorView,r),{...e,cellIds:e.cellIds.transformWithCellId(n,e=>{let t=e.indexOfOrThrow(n)+1;return e.deleteAtIndex(t)}),cellData:{...e.cellData,[n]:{...i,code:r,edited:!!r&&r?.trim()!==i.lastCodeRun?.trim()}},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]}},cellHandles:{...e.cellHandles}})},clearCellOutput:(e,t)=>{let{cellId:n}=t;return CM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return CM({state:e,cellId:n,cellReducer:e=>({...e,consoleOutputs:e.consoleOutputs.filter(e=>e.channel===`stdin`&&e.response==null)})})},clearAllCellOutputs:e=>{let t={...e.cellRuntime};for(let n of e.cellIds.inOrderIds)t[n]={...t[n],output:null,consoleOutputs:[]};return{...e,cellRuntime:t}},addSetupCellIfDoesntExist:(e,t)=>{let{code:n}=t;return e.cellIds.setupCellExists()?{...e,scrollKey:Fi}:{...e,cellIds:e.cellIds.insertId(Fi,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Fi]:fM({id:Fi,name:Fi,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Fi]:mM()},cellHandles:{...e.cellHandles,[Fi]:(0,K.createRef)()},scrollKey:Fi}}});vM(Fj);function SM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function CM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(R.warn(`Cell ${t} not found in state`),e)}function wM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(R.warn(`Cell ${t} not found in state`),e)}function TM(e){let t=e.cellData,n={column:null};return e.cellIds.getColumns().length>1?e.cellIds.getColumns().flatMap((e,r)=>e.inOrderIds.map((e,i)=>{let a={...n};return i===0&&(a.column=r),{...t[e].config,...a}})):e.cellIds.getColumns().flatMap(e=>e.inOrderIds.map(e=>({...t[e].config,...n})))}var EM=yM(e=>{u.set(xM,t=>_M(t,e))}).addLogs,DM=o(e=>e(xM).cellIds),OM=o(e=>e(DM).hasOnlyOneId()),kM=o(e=>gf(e(xM)).length>0);o(e=>_f(e(xM)).length>0);var AM=o(e=>vf(e(xM))),jM=o(e=>yf(e(xM))),MM=o(e=>pf(e(xM))),NM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(xM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(uf(t.output?.mimetype)){B(Array.isArray(t.output.data),`Expected array data`);let n=t.output.data.filter(e=>!e.type.includes(`ancestor`));if(n.length>0)return{output:{...t.output,data:n},cellId:e,cellName:i}}return null}).filter(Boolean)}),PM=o(e=>{let t=e(DM),n=e(YM);return LA(t.inOrderIds.map(e=>n[e].outline))}),FM=o(e=>e(NM).length),IM=c(o(e=>{let{cellIds:t,cellData:n}=e(xM);return z.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),LM=o(e=>e(xM).scrollKey),RM=()=>s(xM),zM=()=>s(DM),BM=()=>s(IM),VM=()=>s(NM),HM=()=>s(xM).cellLogs,UM=()=>s(LM),WM=()=>u.get(xM),GM=()=>u.get(xM).cellIds,KM=()=>{let{cellIds:e,cellData:t}=u.get(xM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},qM=be(he(xM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),JM=()=>a(qM),YM=o(e=>e(xM).cellRuntime),XM=o(e=>df(e(xM))),ZM=o(e=>{let{cellRuntime:t}=e(xM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),QM=o(e=>ff(e(xM))),$M=o(e=>e(xM).cellIds.colLength),eN=o(e=>e(xM).cellIds.idLength>0),tN=o(e=>e(xM).cellIds.getColumnIds()),nN=ge(e=>o(t=>t(xM).cellData[e])),rN=ge(e=>o(t=>t(xM).cellRuntime[e])),iN=ge(e=>o(t=>t(xM).cellHandles[e]));function aN(e){nN.remove(e),rN.remove(e),iN.remove(e)}var oN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=nN(e),t[0]=e,t[1]=n),s(n)},sN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=rN(e),t[0]=e,t[1]=n),s(n)},cN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=iN(e),t[0]=e,t[1]=n),s(n)},lN=()=>{let{cellIds:e,cellHandles:t}=u.get(xM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},uN=e=>{let{cellHandles:t}=u.get(xM);return t[e].current?.editorView},dN=e=>(Hs.promote(e),uN(e));function fN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function pN(e){return o(t=>t(xM).untouchedNewCells.has(e))}function mN(e){let t=rN(e);return o(n=>{let r=n(t);if(!r||r.status===`queued`||r.status===`running`)return;let i=[],a=r.consoleOutputs;if(a&&a.length>0){let e=a.find(e=>e.mimetype===`application/vnd.marimo+traceback`);if(e){let t=e.data;i.push(...Fs(t))}}let o=r.output;if(o?.mimetype===`application/vnd.marimo+error`){let t=o.data;if(Array.isArray(t))for(let n of t)n.type===`syntax`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno}),n.type===`import-star`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno})}return i.length>0?i:void 0})}function hN(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n),bM(n)}export{Ij as $,J as $a,Df as $i,Wy as $n,Ah as $r,hO as $t,VM as A,_s as Aa,xp as Ai,DT as An,Si as Ao,v_ as Ar,Sk as At,cM as B,es as Ba,np as Bi,Tw as Bn,ng as Br,XO as Bt,QM as C,du as Ca,Xp as Ci,wD as Cn,Fi as Co,T_ as Cr,qk as Ct,hN as D,Ps as Da,Cp as Di,lE as Dn,Ai as Do,D_ as Dr,Pk as Dt,jM as E,Fs as Ea,Dp as Ei,HE as En,ki as Eo,w_ as Er,Fk as Et,sN as F,os as Fa,yp as Fi,Lw as Fn,mg as Fr,ak as Ft,iM as G,Go as Ga,Xf as Gi,FC as Gn,Bh as Gr,PO as Gt,oM as H,Jo as Ha,Wf as Hi,nw as Hn,Qh as Hr,zO as Ht,RM as I,is as Ia,mp as Ii,kw as In,cg as Ir,rk as It,Xj as J,Bo as Ja,Kf as Ji,LC as Jn,Ph as Jr,DO as Jt,rM as K,Wo as Ka,Vf as Ki,PC as Kn,Xh as Kr,AO as Kt,UM as L,ts as La,ap as Li,Ow as Ln,rg as Lr,nk as Lt,zM as M,ds as Ma,gp as Mi,Pw as Mn,vg as Mr,Tk as Mt,HM as N,ss as Na,hp as Ni,Iw as Nn,dg as Nr,tk as Nt,oN as O,js as Oa,Tp as Oi,ME as On,wi as Oo,l_ as Or,Nk as Ot,BM as P,as as Pa,pp as Pi,Fw as Pn,gg as Pr,ok as Pt,Bj as Q,Io as Qa,zf as Qi,Gy as Qn,Nh as Qr,pO as Qt,fM as R,$o as Ra,rp as Ri,Aw as Rn,tg as Rr,ik as Rt,PM as S,Dd as Sa,Yp as Si,HD as Sn,Pi as So,b_ as Sr,Gk as St,ZM as T,Ns as Ta,Ep as Ti,WE as Tn,Ri as To,S_ as Tr,Ik as Tt,nM as U,qo as Ua,Hf as Ui,zC as Un,qh as Ur,MO as Ut,dM as V,Yo as Va,op as Vi,Cw as Vn,eg as Vr,RO as Vt,tM as W,Ko as Wa,Uf as Wi,NC as Wn,Zh as Wr,NO as Wt,Jj as X,Ro as Xa,Bf as Xi,Fb as Xn,Ih as Xr,bO as Xt,Yj as Y,zo as Ya,Yf as Yi,Xb as Yn,Fh as Yr,fO as Yt,qj as Z,Lo as Za,Rf as Zi,qy as Zn,Mh as Zr,xO as Zt,kM as _,$d as _a,lm as _i,XD as _n,Wi as _o,G_ as _r,yA as _t,YM as a,bf as aa,hh as ai,cO as an,Do as ao,sy as ar,HA as at,xM as b,zd as ba,Rp as bi,ZD as bn,Bi as bo,C_ as br,Wk as bt,dN as c,mf as ca,uh as ci,QD as cn,wo as co,Vv as cr,IA as ct,TM as d,xf as da,ch as di,$D as dn,bo as do,yv as dr,OA as dt,Of as ea,jh as ei,vO as en,Fo as eo,Ay as er,Dj as et,uN as f,uf as fa,sh as fi,UD as fn,ba as fo,ov as fr,kA as ft,eN as g,of as ga,Em as gi,GD as gn,Ui as go,Y_ as gr,DA as gt,WM as h,sf as ha,Ym as hi,JD as hn,Hi as ho,cv as hr,bA as ht,DM as i,_f as ia,xh as ii,sO as in,ko as io,py as ir,UA as it,cN as j,ps as ja,vp as ji,Jw as jn,_i as jo,Sg as jr,xk as jt,JM as k,As as ka,wp as ki,gT as kn,Ti as ko,y_ as kr,Ek as kt,fN as l,Tf as la,oh as li,tO as ln,So as lo,Iv as lr,RA as lt,GM as m,lf as ma,Qm as mi,qD as mn,Gi as mo,$_ as mr,wA as mt,nN as n,wf as na,Ch as ni,SO as nn,Mo as no,Dy as nr,rj as nt,tN as o,Sf as oa,ph as oi,aO as on,Eo as oo,cy as or,VA as ot,KM as p,cf as pa,lh as pi,WD as pn,Pa as po,sv as pr,CA as pt,eM as q,Ho as qa,Gf as qi,IC as qn,Yh as qr,EO as qt,FM as r,gf as ra,yh as ri,CO as rn,Ao as ro,Oy as rr,ij as rt,pN as s,hf as sa,dh as si,oO as sn,To as so,Hv as sr,zA as st,AM as t,Cf as ta,Oh as ti,yO as tn,Po as to,ky as tr,Mj as tt,lN as u,Ef as ua,ah as ui,rO as un,xo as uo,vv as ur,jA as ut,OM as v,Qd as va,cm as vi,KD as vn,Vi as vo,q_ as vr,EA as vt,$M as w,Hs as wa,Hp as wi,UE as wn,zi as wo,E_ as wr,Jk as wt,XM as x,Bd as xa,Lp as xi,VD as xn,Li as xo,x_ as xr,Uk as xt,MM as y,qd as ya,jp as yi,YD as yn,Ii as yo,z_ as yr,Xk as yt,mM as z,Qo as za,ip as zi,Dw as zn,Q as zr,ZO as zt};
220
+ `)}catch(t){return R.error(`Error parsing HTML content:`,t),e}}function Jj(e){if(!e)return``;try{return qj(Kj.ansi_to_html(e))}catch(t){return R.error(`Error converting ANSI to plain text:`,t),e}}var Yj=o(null);function Xj(e){return e.type===`cell`?e.cellId:`lsp:${e.name}`}var Zj=!1;function Qj(e){let t=[],n=[e.console].filter(Boolean).flat();for(let r of n){let n=r.mimetype===`text/plain`,i=r.mimetype===`text/html`||r.mimetype===`application/vnd.marimo+traceback`;if(n||i){let n=r.channel===`stderr`||r.channel===`marimo-error`;switch(r.channel){case`stdout`:case`stderr`:case`marimo-error`:{let a=Vr.asString(r.data),o=i?qj(a):a;t.push({timestamp:r.timestamp||Date.now(),level:n?`stderr`:`stdout`,message:o,source:{type:`cell`,cellId:e.cell_id}});break}}}}if(t.forEach($j.log),n.length===0&&uf(e.output?.mimetype)&&Array.isArray(e.output.data)){e.output.data.forEach(t=>{$j.log({level:`stderr`,source:{type:`cell`,cellId:e.cell_id},timestamp:e.timestamp??0,message:JSON.stringify(t)})});let t=e.output.data.filter(e=>`type`in e&&e.type===`exception`||e.type===`internal`),n=u.get(fe)===`read`;if(t.length>0&&!Zj&&n){Zj=!0;let e=t.find(e=>e.traceback);sn(e?{title:`An internal error occurred`,description:e.msg||`Click 'View' to see traceback`,variant:`danger`,action:K.createElement(vt,{altText:`View traceback`,onClick:()=>{u.set(Yj,{traceback:e.traceback,errorMessage:e.msg||`An internal error occurred`})}},`View`)}:{title:`An internal error occurred`,description:`See console for details.`,variant:`danger`})}}return t}var $j={log:e=>{let t=e.level===`stdout`?`gray`:e.level===`stderr`?`red`:`orange`,n=e.level.toUpperCase();console.log(`%c[${n}]`,`color:${t}; padding:2px 0; border-radius:2px; font-weight:bold`,`[${eM(e.timestamp)}]`,`(${Xj(e.source)}) ${e.message}`)}};function eM(e){try{return Lj(e).toLocaleTimeString(void 0,{hour12:!0,hour:`numeric`,minute:`numeric`,second:`numeric`})}catch{return``}}function tM(e,t){let n=uN(t);n?n.focus():R.warn(`[CellFocusManager] focusCellEditor: element not found: ${t}`)}function nM(e,t){let n=document.getElementById(Li.create(e));n?aM(n,t):R.warn(`[CellFocusManager] focusCell: element not found: ${e}`)}function rM(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}function iM(){return document.activeElement instanceof HTMLElement&&document.activeElement.classList.contains(`marimo-cell`)}function aM(e,t){try{e.focus(t)}catch{R.warn(`[CellFocusManager] element may not be focusable`,e)}}function oM(e,t){let{retries:n,delay:r,initialDelay:i=0}=t,a=0,o=()=>{if(a<n){try{if(e())return}catch(e){R.error(`Error executing function on attempt ${a+1}, retrying`,{error:e})}a++,setTimeout(o,r)}};i>0?setTimeout(o,i):o()}function sM({cellId:e,cell:t,isCodeHidden:n,codeFocus:r,variableName:i}){if(!t)return;let a=document.getElementById(Li.create(e));if(!a){R.warn(`scrollCellIntoView: element not found`);return}if(iM()){aM(a);return}if(n)aM(a);else{Hs.promote(e);let n=t.current?.editorView;if(!n){R.warn(`scrollCellIntoView: editor not found`,e);return}if(n.hasFocus||!document.hasFocus())return;if(oM(()=>(n.focus(),n.hasFocus),{retries:5,delay:20}),r===`top`)n.dispatch({selection:{anchor:0,head:0}});else if(r===`bottom`){let e=n.state.doc.line(n.state.doc.lines);n.dispatch({selection:{anchor:e.from,head:e.from}})}else i&&z_(n,i)}a.scrollIntoView({behavior:`smooth`,block:`nearest`})}function cM(e){let t=document.getElementById(Li.create(e));if(!t){R.warn(`scrollCellIntoView: element not found`);return}t.classList.add(`focus-outline`),setTimeout(()=>{t.classList.remove(`focus-outline`)},2e3),t.scrollIntoView({behavior:`smooth`,block:`center`})}function lM(){let e=document.getElementById(`App`);e?.scrollTo({top:e.scrollHeight,behavior:`smooth`})}function uM(){document.getElementById(`App`)?.scrollTo({top:0,behavior:`smooth`})}function dM(e){let t=uN(e);if(t?.hasFocus){wh(t,{behavior:`instant`});return}let n=document.getElementById(Li.create(e));n?n.scrollIntoView({behavior:`instant`,block:`nearest`}):R.warn(`[CellFocusManager] scrollCellIntoView: element not found: ${e}`)}function fM({id:e,name:t=`_`,code:n=``,lastCodeRun:r=null,lastExecutionTime:i=null,edited:a=!1,config:o,serializedEditorState:s=null}){return{id:e,config:o||{hide_code:!1,disabled:!1,column:null,expand_output:!1},name:t,code:n,edited:a,lastCodeRun:r,lastExecutionTime:i,serializedEditorState:s}}function pM(e){return{hide_code:!1,disabled:!1,column:null,expand_output:!1,...e}}function mM(e){return{outline:null,output:null,consoleOutputs:[],status:`idle`,staleInputs:!1,interrupted:!1,errored:!1,stopped:!1,runElapsedTimeMs:null,runStartTimestamp:null,lastRunStartTimestamp:null,debuggerActive:!1,...e}}function hM(e){let t={column:0,hide_code:!1,disabled:!1,expand_output:!1};return{...e,cellData:{[Pi]:fM({id:Pi,config:t}),...e.cellData},cellRuntime:{[Pi]:mM(),...e.cellRuntime},cellHandles:{[Pi]:(0,K.createRef)(),...e.cellHandles}}}function gM(){return hM({cellIds:_s.from([]),cellData:{},cellRuntime:{},cellHandles:{},history:[],scrollKey:null,cellLogs:[],untouchedNewCells:new Set})}var{reducer:_M,addMiddleware:vM,createActions:yM,useActions:bM,valueAtom:xM}=jr(gM,{createNewCell:(e,t)=>{let{cellId:n,before:r,code:i,name:a,config:o,lastCodeRun:s=null,lastExecutionTime:c=null,autoFocus:l=!0,skipIfCodeExists:u=!1,hideCode:d=void 0}=t,f,p;if(u){for(let t of e.cellIds.inOrderIds)if(e.cellData[t]?.code===i)return e}if(n===`__end__`){let t=e.cellIds.atOrThrow(0);f=t.id,p=t.length}else if(typeof n==`string`){let t=e.cellIds.findWithId(n);f=t.id,p=t.topLevelIds.indexOf(n)}else if(n.type===`__end__`){let t=e.cellIds.get(n.columnId)||e.cellIds.atOrThrow(0);f=t.id,p=t.length}else throw Error(`Invalid cellId`);let m=t.newCellId||Ii.create(),h=r?p:p+1;return{...e,cellIds:e.cellIds.insertId(m,f,h),cellData:{...e.cellData,[m]:fM({id:m,code:i,name:a,lastCodeRun:s,config:pM({...o,...d!=null&&{hide_code:d}}),lastExecutionTime:c,edited:!!i&&i!==s})},cellRuntime:{...e.cellRuntime,[m]:mM()},cellHandles:{...e.cellHandles,[m]:(0,K.createRef)()},scrollKey:l?m:null,untouchedNewCells:d&&l?new Set([...e.untouchedNewCells,m]):e.untouchedNewCells}},moveCell:(e,t)=>{let{cellId:n,before:r,direction:i}=t;if(r!==void 0&&i!==void 0&&R.warn(`Both before and direction specified for moveCell. Ignoring one.`),i){let t=e.cellIds.findWithId(n),r=e.cellIds.indexOf(t),a=i===`left`?r-1:r+1,o=e.cellIds.at(a);return o?{...e,cellIds:e.cellIds.moveAcrossColumns(t.id,n,o.id,void 0),scrollKey:n}:e}let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n);return r&&o===0?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,0),scrollKey:n}:!r&&o===a.length-1?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,a.length-1),scrollKey:n}:r?{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o-1),scrollKey:n}:{...e,cellIds:e.cellIds.moveWithinColumn(a.id,o,o+1),scrollKey:n}},moveCellToIndex:(e,t)=>{let{cellId:n,columnId:r,index:i}=t,a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=e.cellIds.get(r);if(!s)return e;let c=Math.max(0,Math.min(i,s.length)),l=a.id===r&&o<c?c-1:c;if(a.id===r&&o===l)return e;let u=e.cellIds.deleteById(n),d=u.get(r);return d?{...e,cellIds:u.insertId(n,r,Math.max(0,Math.min(l,d.length))),scrollKey:null}:e},dropCellOverCell:(e,t)=>{let{cellId:n,overCellId:r}=t,i=e.cellIds.findWithId(n),a=e.cellIds.findWithId(r),o=i.indexOfOrThrow(n),s=a.indexOfOrThrow(r);return i.id===a.id?o===s?e:{...e,cellIds:e.cellIds.moveWithinColumn(i.id,o,s),scrollKey:null}:{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,a.id,r),scrollKey:null}},moveCellsRelativeTo:(e,t)=>{let{cellIds:n,targetCellId:r,position:i,previousPlacements:a}=t;if(n.length===0)return e;let o=e.cellIds.moveCellsRelativeTo(n,r,i),s=a&&a.length===n.length?[...e.history,{type:`move`,cellIds:n,placements:a}]:e.history;return{...e,cellIds:o,history:s,scrollKey:null}},dropCellOverColumn:(e,t)=>{let{cellId:n,columnId:r}=t,i=e.cellIds.findWithId(n);return{...e,cellIds:e.cellIds.moveAcrossColumns(i.id,n,r,void 0)}},dropOverNewColumn:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.moveToNewColumn(n)}},moveColumn:(e,t)=>t.column===t.overColumn?e:{...e,cellIds:e.cellIds.moveColumn(t.column,t.overColumn)},focusCell:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,where:i}=t,a=n.indexOfOrThrow(r),o;o=i===`before`?Er(a-1,0,n.length-1):i===`after`?Er(a+1,0,n.length-1):a;let s=n.atOrThrow(o);return sM({cellId:s,cell:e.cellHandles[s],isCodeHidden:SM(e,s),codeFocus:i===`after`?`top`:`bottom`,variableName:void 0}),e},focusTopCell:e=>{let t=e.cellIds.getColumns().at(0);if(t===void 0||t.length===0)return e;let n=t.first();return sM({cellId:n,cell:e.cellHandles[n],isCodeHidden:SM(e,n),codeFocus:void 0,variableName:void 0}),uM(),e},focusBottomCell:e=>{let t=e.cellIds.getColumns().at(-1);if(t===void 0||t.length===0)return e;let n=t.last();return sM({cellId:n,cell:e.cellHandles[n],isCodeHidden:SM(e,n),codeFocus:void 0,variableName:void 0}),lM(),e},sendToTop:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r);return a===0?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,0),scrollKey:i?r:null}},sendToBottom:(e,t)=>{let n=e.cellIds.findWithId(t.cellId);if(n.length===0)return e;let{cellId:r,scroll:i=!0}=t,a=n.indexOfOrThrow(r),o=n.length-1;return a===o?e:{...e,cellIds:e.cellIds.moveWithinColumn(n.id,a,o),scrollKey:i?r:null}},addColumn:(e,t)=>{let n=Ii.create();return{...e,cellIds:e.cellIds.addColumn(t.columnId,[n]),cellData:{...e.cellData,[n]:fM({id:n})},cellRuntime:{...e.cellRuntime,[n]:mM()},cellHandles:{...e.cellHandles,[n]:(0,K.createRef)()},scrollKey:n}},addColumnBreakpoint:(e,t)=>{let{cellId:n}=t;return e.cellIds.getColumns()[0].inOrderIds[0]===n?e:{...e,cellIds:e.cellIds.insertBreakpoint(n)}},deleteColumn:(e,t)=>{let{columnId:n}=t;return{...e,cellIds:e.cellIds.delete(n)}},mergeAllColumns:e=>({...e,cellIds:e.cellIds.mergeAllColumns()}),compactColumns:e=>({...e,cellIds:e.cellIds.compact()}),deleteCell:(e,t)=>{let n=t.cellId;if(e.cellIds.hasOnlyOneId())return e;let r;try{r=e.cellIds.findWithId(n)}catch(t){return R.warn(`Skipping delete for missing cellId`,{cellId:n,error:t}),e}let i=r.indexOfOrThrow(n),a=i===0?1:i-1,o=null;r.length>1&&(o=r.atOrThrow(a));let s=(e.cellHandles[n].current?.editorView)?.state.toJSON({history:ir});s&&(s.doc=e.cellData[n].code),aN(n);let c=e.cellData[n];return{...e,cellIds:e.cellIds.deleteById(n),history:[...e.history,{type:`delete`,name:c.name,serializedEditorState:s,column:r.id,index:i,isSetupCell:n===Fi,config:c.config}],scrollKey:o}},undoDeleteCell:e=>{if(e.history.length===0)return e;let t=e.history[e.history.length-1];if(t.type===`move`){let{cellIds:n,placements:r}=t;if(n.length===0||r.length!==n.length||n.some(t=>!e.cellData[t]))return{...e,history:e.history.slice(0,-1)};let i=n.map((e,t)=>({id:e,columnId:r[t].columnId,index:r[t].index}));return{...e,cellIds:e.cellIds.placeCells(i),history:e.history.slice(0,-1),scrollKey:n[0]??null}}let{name:n,serializedEditorState:r={doc:``},column:i,index:a,isSetupCell:o,config:s}=t,c=o?Fi:Ii.create(),l=fM({id:c,name:n,code:r.doc,edited:r.doc.trim().length>0,serializedEditorState:r,config:s});return{...e,cellIds:e.cellIds.insertId(c,i,a),cellData:{...e.cellData,[c]:l},cellRuntime:{...e.cellRuntime,[c]:mM()},cellHandles:{...e.cellHandles,[c]:(0,K.createRef)()},history:e.history.slice(0,-1),scrollKey:c}},clearSerializedEditorState:(e,t)=>{let{cellId:n}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,serializedEditorState:null})})},updateCellCode:(e,t)=>{let{cellId:n,code:r,formattingChange:i}=t;return e.cellData[n]?wM({state:e,cellId:n,cellReducer:e=>i?{...e,code:r,lastCodeRun:e.edited?e.lastCodeRun:r}:{...e,code:r,edited:r.trim()!==e.lastCodeRun}}):e},updateCellName:(e,t)=>{let{cellId:n,name:r}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,name:r})})},updateCellConfig:(e,t)=>{let{cellId:n,config:r}=t;return wM({state:e,cellId:n,cellReducer:e=>({...e,config:pM({...e.config,...r})})})},prepareForRun:(e,t)=>wM({state:CM({state:e,cellId:t.cellId,cellReducer:e=>nj(e)}),cellId:t.cellId,cellReducer:e=>({...e,edited:!1,lastCodeRun:e.code.trim()})}),handleCellMessage:(e,t)=>{let n=t.cell_id,r=CM({state:e,cellId:n,cellReducer:e=>tj(e,t)});return t.status===`queued`&&(r=wM({state:r,cellId:n,cellReducer:e=>({...e,lastCodeRun:e.code.trim(),edited:!1})})),{...r,cellLogs:[...r.cellLogs,...Qj(t)]}},addLogs:(e,t)=>({...e,cellLogs:[...e.cellLogs,...t.logs]}),setCellIds:(e,t)=>{if(l(e.cellIds.inOrderIds,t.cellIds))return e;let n={...e.cellData},r={...e.cellRuntime},i={...e.cellHandles};for(let a of t.cellIds)a in e.cellData||(n[a]=fM({id:a})),a in e.cellRuntime||(r[a]=mM()),a in e.cellHandles||(i[a]=(0,K.createRef)());return{...e,cellIds:_s.fromWithPreviousShape(t.cellIds,e.cellIds),cellData:n,cellRuntime:r,cellHandles:i}},rebuildCellColumns:(e,t)=>{let n=_s.fromIdsAndColumns(t.cellIds.map(t=>[t,e.cellData[t]?.config.column??null]));return{...e,cellIds:n}},setCellCodes:(e,t)=>{B(t.codes.length===t.ids.length,`Expected codes and ids to have the same length`);let n={...e},r=({cell:e,code:r,cellId:i,name:a,config:o})=>{if(!e)return fM({id:i,code:r,name:a,config:o,lastCodeRun:t.codeIsStale?null:r,edited:t.codeIsStale&&r.trim().length>0});let s=t.codeIsStale?e.lastCodeRun:r,c=s?s.trim()!==r.trim():!!r;if(e.code.trim()===r.trim())return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}};if(!HA()||!UA(i)){let e=n.cellHandles[i].current;e?.editorViewOrNull&&kA(e.editorViewOrNull,r)}return{...e,code:r,edited:c,lastCodeRun:s,...a!==void 0&&{name:a},...o!==void 0&&{config:o}}};for(let e=0;e<t.ids.length;e++){let i=t.ids[e],a=t.codes[e];if(i===void 0||a===void 0)continue;let o=t.names?.[e],s=t.configs?.[e];n={...n,cellData:{...n.cellData,[i]:r({cell:n.cellData[i],code:a,cellId:i,name:o,config:s})}}}return n},setStdinResponse:(e,t)=>{let{cellId:n,response:r,outputIndex:i}=t;return CM({state:e,cellId:n,cellReducer:e=>{let t=[...e.consoleOutputs],n=t[i];return n==null||n.channel!==`stdin`?(R.warn(`Expected stdin output`),e):(t[i]={channel:`stdin`,mimetype:n.mimetype,data:n.data,timestamp:n.timestamp,id:n.id,response:n.mimetype===`text/password`?``:r},{...e,interrupted:!1,consoleOutputs:t})}})},setCells:(e,t)=>{let n=Object.fromEntries(t.map(e=>[e.id,e])),r=_e(),i=t=>{if(!r)return mM();let n=e.cellRuntime[t];return n&&(n.output!=null||n.consoleOutputs.length>0)?n:mM()},a=Object.fromEntries(t.map(e=>[e.id,i(e.id)]));return hM({...e,cellIds:_s.fromIdsAndColumns(t.map(e=>[e.id,e.config.column])),cellData:n,cellRuntime:a,cellHandles:Object.fromEntries(t.map(e=>[e.id,(0,K.createRef)()]))})},moveToNextCell:(e,t)=>{let{cellId:n,before:r,noCreate:i=!1}=t;if(n===`__scratch__`)return e;let a=e.cellIds.findWithId(n),o=a.indexOfOrThrow(n),s=r?o-1:o+1,c=s===a.length,l=s===-1;if(c&&!i){let t=Ii.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,s),cellData:{...e.cellData,[t]:fM({id:t})},cellRuntime:{...e.cellRuntime,[t]:mM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if(l&&!i){let t=Ii.create();return{...e,cellIds:e.cellIds.insertId(t,a.id,0),cellData:{...e.cellData,[t]:fM({id:t})},cellRuntime:{...e.cellRuntime,[t]:mM()},cellHandles:{...e.cellHandles,[t]:(0,K.createRef)()},scrollKey:t}}if((c||l)&&i)return e;if(s>=0&&s<a.length){let t=a.atOrThrow(s);sM({cellId:t,cell:e.cellHandles[t],isCodeHidden:SM(e,t),codeFocus:r?`bottom`:`top`,variableName:void 0})}return e},markTouched:(e,t)=>{let{cellId:n}=t;if(e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.delete(n),{...e,untouchedNewCells:t}}return e},markUntouched:(e,t)=>{let{cellId:n}=t;if(!e.untouchedNewCells.has(n)){let t=new Set(e.untouchedNewCells);return t.add(n),{...e,untouchedNewCells:t}}return e},scrollToTarget:e=>{let t=e.scrollKey;if(t===null)return e;let n=e.cellIds.findWithId(t),r=n.indexOfOrThrow(t),i=r===n.length-1?n.last():n.atOrThrow(r);return sM({cellId:i,cell:e.cellHandles[i],isCodeHidden:SM(e,i),codeFocus:void 0,variableName:void 0}),{...e,scrollKey:null}},foldAll:e=>(Ls(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),unfoldAll:e=>(Rs(Object.values(e.cellHandles).map(e=>e.current?.editorView)),e),clearLogs:e=>({...e,cellLogs:[]}),collapseCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.topLevelIds.map(t=>e.cellRuntime[t].outline),a=BA(r.indexOfOrThrow(n),i);if(!a)return e;let o=r.atOrThrow(a[1]);return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.collapse(n,o)),scrollKey:n}},expandCell:(e,t)=>{let{cellId:n}=t;return{...e,cellIds:e.cellIds.transformWithCellId(n,e=>e.expand(n)),scrollKey:n}},collapseAllCells:e=>({...e,cellIds:e.cellIds.transformAll(t=>{let n=t.topLevelIds.map(t=>e.cellRuntime[t].outline),r=[...t.nodes],i=new Map,a=[],o=r.length-1;for(;o>=0;){let e=BA(o,n);if(e){let n=o,r=e[1],s=i.get(r)??r;i.set(r,n);let c=t.atOrThrow(n),l=t.atOrThrow(s);a.push({id:c,until:l})}else a.push(null);o--}let s=a.toReversed();return t.collapseAll(s)})}),expandAllCells:e=>({...e,cellIds:e.cellIds.transformAll(e=>e.expandAll())}),showCellIfHidden:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r,a=r.findAndExpandDeep(n);return a.equals(i)?e:{...e,cellIds:e.cellIds.transformWithCellId(n,()=>a)}},splitCell:(e,t)=>{let{cellId:n}=t,r=e.cellIds.findWithId(n),i=r.indexOfOrThrow(n),a=e.cellData[n],o=e.cellHandles[n].current;if(o?.editorView==null)return e;let{beforeCursorCode:s,afterCursorCode:c}=AA(o.editorView);kA(o.editorView,s);let l=Ii.create();return{...e,cellIds:e.cellIds.insertId(l,r.id,i+1),cellData:{...e.cellData,[n]:{...a,code:s,edited:!!s&&s.trim()!==a.lastCodeRun?.trim()},[l]:fM({id:l,code:c,edited:!!c})},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]},[l]:mM()},cellHandles:{...e.cellHandles,[l]:(0,K.createRef)()},scrollKey:l}},undoSplitCell:(e,t)=>{let{cellId:n,snapshot:r}=t,i=e.cellData[n],a=e.cellHandles[n].current;return a?.editorView==null?e:(kA(a.editorView,r),{...e,cellIds:e.cellIds.transformWithCellId(n,e=>{let t=e.indexOfOrThrow(n)+1;return e.deleteAtIndex(t)}),cellData:{...e.cellData,[n]:{...i,code:r,edited:!!r&&r?.trim()!==i.lastCodeRun?.trim()}},cellRuntime:{...e.cellRuntime,[n]:{...e.cellRuntime[n],output:null,consoleOutputs:[]}},cellHandles:{...e.cellHandles}})},clearCellOutput:(e,t)=>{let{cellId:n}=t;return CM({state:e,cellId:n,cellReducer:e=>({...e,output:null,consoleOutputs:[]})})},clearCellConsoleOutput:(e,t)=>{let{cellId:n}=t;return CM({state:e,cellId:n,cellReducer:e=>({...e,consoleOutputs:e.consoleOutputs.filter(e=>e.channel===`stdin`&&e.response==null)})})},clearAllCellOutputs:e=>{let t={...e.cellRuntime};for(let n of e.cellIds.inOrderIds)t[n]={...t[n],output:null,consoleOutputs:[]};return{...e,cellRuntime:t}},addSetupCellIfDoesntExist:(e,t)=>{let{code:n}=t;return e.cellIds.setupCellExists()?{...e,scrollKey:Fi}:{...e,cellIds:e.cellIds.insertId(Fi,e.cellIds.atOrThrow(0).id,0),cellData:{...e.cellData,[Fi]:fM({id:Fi,name:Fi,code:n,edited:!!n})},cellRuntime:{...e.cellRuntime,[Fi]:mM()},cellHandles:{...e.cellHandles,[Fi]:(0,K.createRef)()},scrollKey:Fi}}});vM(Fj);function SM(e,t){return!!e.cellData[t].config.hide_code&&!e.untouchedNewCells.has(t)}function CM({state:e,cellId:t,cellReducer:n}){return t in e.cellRuntime?{...e,cellRuntime:{...e.cellRuntime,[t]:n(e.cellRuntime[t])}}:(R.warn(`Cell ${t} not found in state`),e)}function wM({state:e,cellId:t,cellReducer:n}){return t in e.cellData?{...e,cellData:{...e.cellData,[t]:n(e.cellData[t])}}:(R.warn(`Cell ${t} not found in state`),e)}function TM(e){let t=e.cellData,n={column:null};return e.cellIds.getColumns().length>1?e.cellIds.getColumns().flatMap((e,r)=>e.inOrderIds.map((e,i)=>{let a={...n};return i===0&&(a.column=r),{...t[e].config,...a}})):e.cellIds.getColumns().flatMap(e=>e.inOrderIds.map(e=>({...t[e].config,...n})))}var EM=yM(e=>{u.set(xM,t=>_M(t,e))}).addLogs,DM=o(e=>e(xM).cellIds),OM=o(e=>e(DM).hasOnlyOneId()),kM=o(e=>gf(e(xM)).length>0);o(e=>_f(e(xM)).length>0);var AM=o(e=>vf(e(xM))),jM=o(e=>yf(e(xM))),MM=o(e=>pf(e(xM))),NM=o(e=>{let{cellIds:t,cellRuntime:n,cellData:r}=e(xM);return t.inOrderIds.map(e=>{let t=n[e],{name:i}=r[e];if(uf(t.output?.mimetype)){B(Array.isArray(t.output.data),`Expected array data`);let n=t.output.data.filter(e=>!e.type.includes(`ancestor`));if(n.length>0)return{output:{...t.output,data:n},cellId:e,cellName:i}}return null}).filter(Boolean)}),PM=o(e=>{let t=e(DM),n=e(YM);return LA(t.inOrderIds.map(e=>n[e].outline))}),FM=o(e=>e(NM).length),IM=c(o(e=>{let{cellIds:t,cellData:n}=e(xM);return z.fromEntries(t.inOrderIds.map(e=>[e,n[e]?.name]))})),LM=o(e=>e(xM).scrollKey),RM=()=>s(xM),zM=()=>s(DM),BM=()=>s(IM),VM=()=>s(NM),HM=()=>s(xM).cellLogs,UM=()=>s(LM),WM=()=>u.get(xM),GM=()=>u.get(xM).cellIds,KM=()=>{let{cellIds:e,cellData:t}=u.get(xM);return e.inOrderIds.map(e=>t[e]?.name).filter(Boolean)},qM=be(he(xM,e=>e.cellIds.inOrderIds.map(t=>e.cellData[t]))),JM=()=>a(qM),YM=o(e=>e(xM).cellRuntime),XM=o(e=>df(e(xM))),ZM=o(e=>{let{cellRuntime:t}=e(xM);return Object.entries(t).every(([e,t])=>t.status!==`running`||e===`__scratch__`)}),QM=o(e=>ff(e(xM))),$M=o(e=>e(xM).cellIds.colLength),eN=o(e=>e(xM).cellIds.idLength>0),tN=o(e=>e(xM).cellIds.getColumnIds()),nN=ge(e=>o(t=>t(xM).cellData[e])),rN=ge(e=>o(t=>t(xM).cellRuntime[e])),iN=ge(e=>o(t=>t(xM).cellHandles[e]));function aN(e){nN.remove(e),rN.remove(e),iN.remove(e)}var oN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=nN(e),t[0]=e,t[1]=n),s(n)},sN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=rN(e),t[0]=e,t[1]=n),s(n)},cN=e=>{let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=iN(e),t[0]=e,t[1]=n),s(n)},lN=()=>{let{cellIds:e,cellHandles:t}=u.get(xM);return e.inOrderIds.map(e=>t[e]?.current?.editorViewOrNull).filter(Boolean)},uN=e=>{let{cellHandles:t}=u.get(xM);return t[e].current?.editorView},dN=e=>(Hs.promote(e),uN(e));function fN(e){let{cellIds:t,cellData:n,cellRuntime:r}=e;return t.getColumns().flatMap(e=>e.topLevelIds.map(e=>({...n[e],...r[e]})))}function pN(e){return o(t=>t(xM).untouchedNewCells.has(e))}function mN(e){let t=rN(e);return o(n=>{let r=n(t);if(!r||r.status===`queued`||r.status===`running`)return;let i=[],a=r.consoleOutputs;if(a&&a.length>0){let e=a.find(e=>e.mimetype===`application/vnd.marimo+traceback`);if(e){let t=e.data;i.push(...Fs(t))}}let o=r.output;if(o?.mimetype===`application/vnd.marimo+error`){let t=o.data;if(Array.isArray(t))for(let n of t)n.type===`syntax`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno}),n.type===`import-star`&&n.lineno!=null&&i.push({kind:`cell`,cellId:e,lineNumber:n.lineno})}return i.length>0?i:void 0})}function hN(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n),bM(n)}export{Ij as $,J as $a,Df as $i,Wy as $n,Ah as $r,hO as $t,VM as A,_s as Aa,xp as Ai,DT as An,Si as Ao,v_ as Ar,Sk as At,cM as B,es as Ba,np as Bi,Tw as Bn,ng as Br,XO as Bt,QM as C,du as Ca,Xp as Ci,wD as Cn,Fi as Co,T_ as Cr,qk as Ct,hN as D,Ps as Da,Cp as Di,lE as Dn,Ai as Do,D_ as Dr,Pk as Dt,jM as E,Fs as Ea,Dp as Ei,HE as En,ki as Eo,w_ as Er,Fk as Et,sN as F,os as Fa,yp as Fi,Lw as Fn,mg as Fr,ak as Ft,iM as G,Go as Ga,Xf as Gi,FC as Gn,Bh as Gr,PO as Gt,oM as H,Jo as Ha,Wf as Hi,nw as Hn,Qh as Hr,zO as Ht,RM as I,is as Ia,mp as Ii,kw as In,cg as Ir,rk as It,Xj as J,Bo as Ja,Kf as Ji,LC as Jn,Ph as Jr,DO as Jt,rM as K,Wo as Ka,Vf as Ki,PC as Kn,Xh as Kr,AO as Kt,UM as L,ts as La,ap as Li,Ow as Ln,rg as Lr,nk as Lt,zM as M,ds as Ma,gp as Mi,Pw as Mn,vg as Mr,Tk as Mt,HM as N,ss as Na,hp as Ni,Iw as Nn,dg as Nr,tk as Nt,oN as O,js as Oa,Tp as Oi,ME as On,wi as Oo,l_ as Or,Nk as Ot,BM as P,as as Pa,pp as Pi,Fw as Pn,gg as Pr,ok as Pt,Bj as Q,Io as Qa,zf as Qi,Gy as Qn,Nh as Qr,pO as Qt,fM as R,$o as Ra,rp as Ri,Aw as Rn,tg as Rr,ik as Rt,PM as S,Dd as Sa,Yp as Si,HD as Sn,Pi as So,b_ as Sr,Gk as St,ZM as T,Ns as Ta,Ep as Ti,WE as Tn,Ri as To,S_ as Tr,Ik as Tt,nM as U,qo as Ua,Hf as Ui,zC as Un,qh as Ur,MO as Ut,dM as V,Yo as Va,op as Vi,Cw as Vn,eg as Vr,RO as Vt,tM as W,Ko as Wa,Uf as Wi,NC as Wn,Zh as Wr,NO as Wt,Jj as X,Ro as Xa,Bf as Xi,Fb as Xn,Ih as Xr,bO as Xt,Yj as Y,zo as Ya,Yf as Yi,Xb as Yn,Fh as Yr,fO as Yt,qj as Z,Lo as Za,Rf as Zi,qy as Zn,Mh as Zr,xO as Zt,kM as _,$d as _a,lm as _i,XD as _n,Wi as _o,G_ as _r,yA as _t,YM as a,bf as aa,hh as ai,cO as an,Do as ao,sy as ar,HA as at,xM as b,zd as ba,Rp as bi,ZD as bn,Bi as bo,C_ as br,Wk as bt,dN as c,mf as ca,uh as ci,QD as cn,wo as co,Vv as cr,IA as ct,TM as d,xf as da,ch as di,$D as dn,bo as do,yv as dr,OA as dt,Of as ea,jh as ei,vO as en,Fo as eo,Ay as er,Dj as et,uN as f,uf as fa,sh as fi,UD as fn,ba as fo,ov as fr,kA as ft,eN as g,of as ga,Em as gi,GD as gn,Ui as go,Y_ as gr,DA as gt,WM as h,sf as ha,Ym as hi,JD as hn,Hi as ho,cv as hr,bA as ht,DM as i,_f as ia,xh as ii,sO as in,ko as io,py as ir,UA as it,cN as j,ps as ja,vp as ji,Jw as jn,_i as jo,Sg as jr,xk as jt,JM as k,As as ka,wp as ki,gT as kn,Ti as ko,y_ as kr,Ek as kt,fN as l,Tf as la,oh as li,tO as ln,So as lo,Iv as lr,RA as lt,GM as m,lf as ma,Qm as mi,qD as mn,Gi as mo,$_ as mr,wA as mt,nN as n,wf as na,Ch as ni,SO as nn,Mo as no,Dy as nr,rj as nt,tN as o,Sf as oa,ph as oi,aO as on,Eo as oo,cy as or,VA as ot,KM as p,cf as pa,lh as pi,WD as pn,Pa as po,sv as pr,CA as pt,eM as q,Ho as qa,Gf as qi,IC as qn,Yh as qr,EO as qt,FM as r,gf as ra,yh as ri,CO as rn,Ao as ro,Oy as rr,ij as rt,pN as s,hf as sa,dh as si,oO as sn,To as so,Hv as sr,zA as st,AM as t,Cf as ta,Oh as ti,yO as tn,Po as to,ky as tr,Mj as tt,lN as u,Ef as ua,ah as ui,rO as un,xo as uo,vv as ur,jA as ut,OM as v,Qd as va,cm as vi,KD as vn,Vi as vo,q_ as vr,EA as vt,$M as w,Hs as wa,Hp as wi,UE as wn,zi as wo,E_ as wr,Jk as wt,XM as x,Bd as xa,Lp as xi,VD as xn,Li as xo,x_ as xr,Uk as xt,MM as y,qd as ya,jp as yi,YD as yn,Ii as yo,z_ as yr,Xk as yt,mM as z,Qo as za,ip as zi,Dw as zn,Q as zr,ZO as zt};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{no as n,oo as r}from"./cells-BypTg035.js";import{C as i,I as a,k as o,x as s}from"./schemas-ChRqMOTL.js";import{t as c}from"./compiler-runtime-BrajqUja.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{g as u}from"./useEventListener-DPOTkksd.js";import{a as d,i as f,o as p,r as m}from"./config-BC32AAdw.js";import{t as h}from"./cn-ldLVeaqm.js";import{t as g}from"./jsx-runtime-B74pBk57.js";import{t as _}from"./button-Cl7haVNh.js";import{t as v}from"./createLucideIcon-DfJ2oMlA.js";import{r as y}from"./paths-bkIFVj8h.js";import{t as b}from"./ban-YzvUro5I.js";import{t as x}from"./bot-message-square-8xmbrehG.js";import{rt as S}from"./ai-model-dropdown-DgmiG_5j.js";import{a as C}from"./useNumberFormatter-D7O_26UI.js";import{t as w}from"./markdown-renderer-mYYQYD2m.js";import{p as T,u as E}from"./add-cell-with-ai-BbuqzITi.js";import{t as D}from"./external-link-UrX9KO36.js";import{n as O}from"./spinner-DyNE-o8o.js";import{l as k}from"./datasource-Dy4rzzSP.js";import{i as A}from"./strings-3lNX212T.js";import{t as j}from"./RenderHTML-Bjvcs70-.js";var M=v(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=v(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=g(),V=e=>{let t=(0,R.c)(13),{reasoning:n,index:r,isStreaming:i}=e,a=r===void 0?0:r,o=i!==void 0&&i,[s,c]=z.useState(``);if(!n&&!o)return null;let l=o?`reasoning`:s,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(x,{className:`h-3 w-3`}),t[0]=u):u=t[0];let h=o?`Thinking`:`View reasoning`,g=n.length>0&&` (${n.length} chars)`,_;t[1]!==h||t[2]!==g?(_=(0,B.jsx)(p,{className:`text-xs text-muted-foreground hover:bg-muted/50 px-2 py-1 h-auto rounded-sm [&[data-state=open]>svg]:rotate-180`,children:(0,B.jsxs)(`span`,{className:`flex items-center gap-2`,children:[u,h,g]})}),t[1]=h,t[2]=g,t[3]=_):_=t[3];let v;t[4]===n?v=t[5]:(v=(0,B.jsx)(f,{className:`pb-2 px-2`,children:(0,B.jsx)(`div`,{className:`bg-muted/30 border border-muted/50 rounded-md p-3 italic text-muted-foreground/90 relative`,children:(0,B.jsx)(`div`,{className:`pr-6`,children:(0,B.jsx)(w,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==_||t[7]!==v?(y=(0,B.jsxs)(d,{value:`reasoning`,className:`border-0`,children:[_,v]}),t[6]=_,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:`w-full mb-2`,value:l,onValueChange:c,children:y},a),t[9]=a,t[10]=l,t[11]=y,t[12]=b):b=t[12],b};function H(e){return e.replace(`tool-`,``)}var U=e=>{let t=(0,R.c)(9),{input:n,label:r}=e,i=r===void 0?`Tool Request`:r;if(n==null)return null;let a;t[0]===i?a=t[1]:(a=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:i}),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=JSON.stringify(n,null,2),t[2]=n,t[3]=o);let s;t[4]===o?s=t[5]:(s=(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:o}),t[4]=o,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,B.jsxs)(`div`,{className:`space-y-2`,children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c},W=e=>{let t=(0,R.c)(27),{toolName:n,input:r,approval:i,onApprove:a,className:o}=e,s;t[0]===o?s=t[1]:(s=h(`rounded-md border border-(--amber-6) bg-(--amber-2) p-3 space-y-3`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=H(n),t[2]=n,t[3]=c);let l=`Approval required for ${c}`,u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(N,{className:`h-4 w-4 text-(--amber-11) mt-0.5 shrink-0`}),t[4]=u):u=t[4];let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Approval required:`}),t[5]=d):d=t[5];let f;t[6]===n?f=t[7]:(f=H(n),t[6]=n,t[7]=f);let p;t[8]===f?p=t[9]:(p=(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[u,(0,B.jsxs)(`div`,{className:`text-xs text-(--amber-11) leading-relaxed`,children:[d,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:f})]})]}),t[8]=f,t[9]=p);let m;t[10]===r?m=t[11]:(m=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=m);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(_,{size:`xs`,variant:`outline`,onClick:()=>a({id:i.id,approved:!1}),children:`Deny`}),t[12]=i.id,t[13]=a,t[14]=g):g=t[14];let v;t[15]!==i.id||t[16]!==a?(v=(0,B.jsx)(_,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=v):v=t[17];let y;t[18]!==v||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,v]}),t[18]=v,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==p||t[25]!==m?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[p,m,y]}),t[21]=s,t[22]=y,t[23]=l,t[24]=p,t[25]=m,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,f;t[0]===o?(d=t[1],f=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},f=[o],t[0]=o,t[1]=d,t[2]=f),z.useEffect(d,f);let p;t[3]===s?p=t[4]:(p=h(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>l(K),t[5]=m):m=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=h(`h-3.5 w-3.5 shrink-0 transition-transform`,b),t[12]=b,t[13]=x);let S;t[14]===x?S=t[15]:(S=(0,B.jsx)(C,{className:x}),t[14]=x,t[15]=S);let w;t[16]!==c||t[17]!==S||t[18]!==y?(w=(0,B.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors`,"aria-expanded":c,children:[g,y,S]}),t[16]=c,t[17]=S,t[18]=y,t[19]=w):w=t[19];let T;t[20]!==a||t[21]!==i||t[22]!==c?(T=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==w||t[25]!==T||t[26]!==p?(E=(0,B.jsxs)(`div`,{className:p,children:[w,T]}),t[24]=w,t[25]=T,t[26]=p,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=o({status:a().default(`success`),auth_required:i().default(!1),action_url:s().optional(),next_steps:s().optional(),meta:s().optional(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(O,{className:`h-3 w-3 animate-spin`}),t[1]=e):e=t[1],e}case`output-available`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(S,{className:`h-3 w-3 text-(--grass-11)`}),t[2]=e):e=t[2],e}case`output-denied`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(b,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{A(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(k,{className:`h-3 w-3`}),t[4]=e):e=t[4],e}}};function re(e){switch(e){case`output-available`:return`text-(--grass-11)/80`;case`output-denied`:return`text-muted-foreground`;case`input-streaming`:case`input-available`:case`approval-responded`:return``;default:return A(e),``}}var Q=e=>{let t=(0,R.c)(34),{toolName:n,state:r,input:i,result:a,approval:o,index:s,className:c,isActive:l}=e,u=s===void 0?0:s,g=l===void 0||l,_;t[0]!==g||t[1]!==r?(_=!g&&te.has(r),t[0]=g,t[1]=r,t[2]=_):_=t[2];let v=_,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=h(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=h(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(p,{className:x,children:E}),t[19]=E,t[20]=x,t[21]=D):D=t[21];let O;t[22]!==o||t[23]!==i||t[24]!==a||t[25]!==r?(O=(0,B.jsx)(f,{className:`py-2 px-2`,children:(0,B.jsx)(ie,{state:r,input:i,result:a,approval:o})}),t[22]=o,t[23]=i,t[24]=a,t[25]=r,t[26]=O):O=t[26];let k;t[27]!==D||t[28]!==O?(k=(0,B.jsxs)(d,{value:`tool-call`,className:`border-0`,children:[D,O]}),t[27]=D,t[28]=O,t[29]=k):k=t[29];let A;return t[30]!==k||t[31]!==y||t[32]!==b?(A=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:b,children:k},y),t[30]=k,t[31]=y,t[32]=b,t[33]=A):A=t[33],A},ie=e=>{let t=(0,R.c)(16),{state:n,input:r,result:i,approval:a}=e;switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[0]===r?e=t[1]:(e=(0,B.jsx)(U,{input:r}),t[0]=r,t[1]=e),e}case`output-available`:{let e;t[2]===r?e=t[3]:(e=(0,B.jsx)(U,{input:r}),t[2]=r,t[3]=e);let n;t[4]===i?n=t[5]:(n=i!=null&&(0,B.jsx)(X,{result:i}),t[4]=i,t[5]=n);let a;return t[6]!==e||t[7]!==n?(a=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,n]}),t[6]=e,t[7]=n,t[8]=a):a=t[8],a}case`output-denied`:{let e;t[9]===r?e=t[10]:(e=(0,B.jsx)(U,{input:r}),t[9]=r,t[10]=e);let n=a?.reason?`: ${a.reason}`:`.`,i;t[11]===n?i=t[12]:(i=(0,B.jsxs)(`div`,{className:`bg-muted/40 border border-border rounded-md p-3 text-xs text-muted-foreground leading-relaxed`,children:[`Tool execution was denied`,n]}),t[11]=n,t[12]=i);let o;return t[13]!==e||t[14]!==i?(o=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,i]}),t[13]=e,t[14]=i,t[15]=o):o=t[15],o}default:return A(n),null}},$=e=>{let t=(0,R.c)(27),{toolName:n,state:r,result:i,errorText:a,input:o,approval:s,onApprove:c,index:l,className:u,isLive:d,isActive:f}=e,p=d===void 0||d,m=f===void 0||f;switch(r){case`approval-requested`:{if(s!=null&&c!=null){let e;return t[0]!==s||t[1]!==u||t[2]!==o||t[3]!==c||t[4]!==n?(e=(0,B.jsx)(W,{toolName:n,input:o,approval:s,onApprove:c,className:u}),t[0]=s,t[1]=u,t[2]=o,t[3]=c,t[4]=n,t[5]=e):e=t[5],e}let e;return t[6]!==u||t[7]!==l||t[8]!==o||t[9]!==m||t[10]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:`input-available`,input:o,index:l,className:u,isActive:m}),t[6]=u,t[7]=l,t[8]=o,t[9]=m,t[10]=n,t[11]=e):e=t[11],e}case`output-error`:{let e;return t[12]!==u||t[13]!==a||t[14]!==o||t[15]!==p||t[16]!==n?(e=(0,B.jsx)(G,{toolName:n,input:o,errorText:a,isLive:p,className:u}),t[12]=u,t[13]=a,t[14]=o,t[15]=p,t[16]=n,t[17]=e):e=t[17],e}case`input-streaming`:case`input-available`:case`approval-responded`:case`output-available`:case`output-denied`:{let e;return t[18]!==s||t[19]!==u||t[20]!==l||t[21]!==o||t[22]!==m||t[23]!==i||t[24]!==r||t[25]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:r,input:o,result:i,approval:s,index:l,className:u,isActive:m}),t[18]=s,t[19]=u,t[20]=l,t[21]=o,t[22]=m,t[23]=i,t[24]=r,t[25]=n,t[26]=e):e=t[26],e}default:return A(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return u.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:a.text})},o):(0,B.jsx)(w,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(E,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(E,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(T,{icon:(0,B.jsx)(y,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(T,{icon:(0,B.jsx)(D,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return A(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{t}from"./react-DVplv7_D.js";import{no as n,oo as r}from"./cells-SvbLY10y.js";import{C as i,I as a,k as o,x as s}from"./schemas-ChRqMOTL.js";import{t as c}from"./compiler-runtime-BrajqUja.js";import{t as l}from"./isEmpty-BJso7_X0.js";import{g as u}from"./useEventListener-DPOTkksd.js";import{a as d,i as f,o as p,r as m}from"./config-BC32AAdw.js";import{t as h}from"./cn-ldLVeaqm.js";import{t as g}from"./jsx-runtime-B74pBk57.js";import{t as _}from"./button-Cl7haVNh.js";import{t as v}from"./createLucideIcon-DfJ2oMlA.js";import{r as y}from"./paths-bkIFVj8h.js";import{t as b}from"./ban-YzvUro5I.js";import{t as x}from"./bot-message-square-8xmbrehG.js";import{rt as S}from"./ai-model-dropdown-D575Vid8.js";import{a as C}from"./useNumberFormatter-D7O_26UI.js";import{t as w}from"./markdown-renderer-DUgV7_fm.js";import{p as T,u as E}from"./add-cell-with-ai-D7gtGUsg.js";import{t as D}from"./external-link-UrX9KO36.js";import{n as O}from"./spinner-DyNE-o8o.js";import{l as k}from"./datasource-C8KSVfSD.js";import{i as A}from"./strings-3lNX212T.js";import{t as j}from"./RenderHTML-COGZsXQV.js";var M=v(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]),N=v(`shield-question-mark`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),P=`user_cancelled`;function F(e){if(e.type===`abort`)return e.reason}function I(e){return e.isAbort?e.streamReason||`user_cancelled`:null}function L(e){switch(e){case P:return`Generation stopped`;case`timeout`:return`Generation stopped: timed out`;default:return`Generation stopped: ${e}`}}var R=c(),z=e(t(),1),B=g(),V=e=>{let t=(0,R.c)(13),{reasoning:n,index:r,isStreaming:i}=e,a=r===void 0?0:r,o=i!==void 0&&i,[s,c]=z.useState(``);if(!n&&!o)return null;let l=o?`reasoning`:s,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(x,{className:`h-3 w-3`}),t[0]=u):u=t[0];let h=o?`Thinking`:`View reasoning`,g=n.length>0&&` (${n.length} chars)`,_;t[1]!==h||t[2]!==g?(_=(0,B.jsx)(p,{className:`text-xs text-muted-foreground hover:bg-muted/50 px-2 py-1 h-auto rounded-sm [&[data-state=open]>svg]:rotate-180`,children:(0,B.jsxs)(`span`,{className:`flex items-center gap-2`,children:[u,h,g]})}),t[1]=h,t[2]=g,t[3]=_):_=t[3];let v;t[4]===n?v=t[5]:(v=(0,B.jsx)(f,{className:`pb-2 px-2`,children:(0,B.jsx)(`div`,{className:`bg-muted/30 border border-muted/50 rounded-md p-3 italic text-muted-foreground/90 relative`,children:(0,B.jsx)(`div`,{className:`pr-6`,children:(0,B.jsx)(w,{content:n})})})}),t[4]=n,t[5]=v);let y;t[6]!==_||t[7]!==v?(y=(0,B.jsxs)(d,{value:`reasoning`,className:`border-0`,children:[_,v]}),t[6]=_,t[7]=v,t[8]=y):y=t[8];let b;return t[9]!==a||t[10]!==l||t[11]!==y?(b=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:`w-full mb-2`,value:l,onValueChange:c,children:y},a),t[9]=a,t[10]=l,t[11]=y,t[12]=b):b=t[12],b};function H(e){return e.replace(`tool-`,``)}var U=e=>{let t=(0,R.c)(9),{input:n,label:r}=e,i=r===void 0?`Tool Request`:r;if(n==null)return null;let a;t[0]===i?a=t[1]:(a=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:i}),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=JSON.stringify(n,null,2),t[2]=n,t[3]=o);let s;t[4]===o?s=t[5]:(s=(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:o}),t[4]=o,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,B.jsxs)(`div`,{className:`space-y-2`,children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c},W=e=>{let t=(0,R.c)(27),{toolName:n,input:r,approval:i,onApprove:a,className:o}=e,s;t[0]===o?s=t[1]:(s=h(`rounded-md border border-(--amber-6) bg-(--amber-2) p-3 space-y-3`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=H(n),t[2]=n,t[3]=c);let l=`Approval required for ${c}`,u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,B.jsx)(N,{className:`h-4 w-4 text-(--amber-11) mt-0.5 shrink-0`}),t[4]=u):u=t[4];let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Approval required:`}),t[5]=d):d=t[5];let f;t[6]===n?f=t[7]:(f=H(n),t[6]=n,t[7]=f);let p;t[8]===f?p=t[9]:(p=(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[u,(0,B.jsxs)(`div`,{className:`text-xs text-(--amber-11) leading-relaxed`,children:[d,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:f})]})]}),t[8]=f,t[9]=p);let m;t[10]===r?m=t[11]:(m=(0,B.jsx)(U,{input:r}),t[10]=r,t[11]=m);let g;t[12]!==i.id||t[13]!==a?(g=(0,B.jsx)(_,{size:`xs`,variant:`outline`,onClick:()=>a({id:i.id,approved:!1}),children:`Deny`}),t[12]=i.id,t[13]=a,t[14]=g):g=t[14];let v;t[15]!==i.id||t[16]!==a?(v=(0,B.jsx)(_,{size:`xs`,onClick:()=>a({id:i.id,approved:!0}),children:`Approve`}),t[15]=i.id,t[16]=a,t[17]=v):v=t[17];let y;t[18]!==v||t[19]!==g?(y=(0,B.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[g,v]}),t[18]=v,t[19]=g,t[20]=y):y=t[20];let b;return t[21]!==s||t[22]!==y||t[23]!==l||t[24]!==p||t[25]!==m?(b=(0,B.jsxs)(`div`,{className:s,role:`alertdialog`,"aria-label":l,children:[p,m,y]}),t[21]=s,t[22]=y,t[23]=l,t[24]=p,t[25]=m,t[26]=b):b=t[26],b},G=e=>{let t=(0,R.c)(28),{toolName:n,input:i,errorText:a,isLive:o,className:s}=e,[c,l]=z.useState(o),u=z.useRef(o),d,f;t[0]===o?(d=t[1],f=t[2]):(d=()=>{u.current&&!o&&l(!1),u.current=o},f=[o],t[0]=o,t[1]=d,t[2]=f),z.useEffect(d,f);let p;t[3]===s?p=t[4]:(p=h(`rounded-md border border-(--red-6) bg-(--red-2)`,s),t[3]=s,t[4]=p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>l(K),t[5]=m):m=t[5];let g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,B.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),t[6]=g):g=t[6];let _;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,B.jsx)(`span`,{className:`font-semibold`,children:`Failed:`}),t[7]=_):_=t[7];let v;t[8]===n?v=t[9]:(v=H(n),t[8]=n,t[9]=v);let y;t[10]===v?y=t[11]:(y=(0,B.jsxs)(`span`,{className:`flex-1 text-left`,children:[_,` `,(0,B.jsx)(`code`,{className:`font-mono`,children:v})]}),t[10]=v,t[11]=y);let b=c&&`rotate-180`,x;t[12]===b?x=t[13]:(x=h(`h-3.5 w-3.5 shrink-0 transition-transform`,b),t[12]=b,t[13]=x);let S;t[14]===x?S=t[15]:(S=(0,B.jsx)(C,{className:x}),t[14]=x,t[15]=S);let w;t[16]!==c||t[17]!==S||t[18]!==y?(w=(0,B.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors`,"aria-expanded":c,children:[g,y,S]}),t[16]=c,t[17]=S,t[18]=y,t[19]=w):w=t[19];let T;t[20]!==a||t[21]!==i||t[22]!==c?(T=c&&(0,B.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3`,children:[(0,B.jsx)(U,{input:i}),a&&(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-(--red-11) mb-1`,children:`Error`}),(0,B.jsx)(`pre`,{className:`bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap`,children:a})]})]}),t[20]=a,t[21]=i,t[22]=c,t[23]=T):T=t[23];let E;return t[24]!==w||t[25]!==T||t[26]!==p?(E=(0,B.jsxs)(`div`,{className:p,children:[w,T]}),t[24]=w,t[25]=T,t[26]=p,t[27]=E):E=t[27],E};function K(e){return!e}function q(e){return e==null||typeof e==`object`&&l(e)}var J=o({status:a().default(`success`),auth_required:i().default(!1),action_url:s().optional(),next_steps:s().optional(),meta:s().optional(),message:a().nullish()}),Y=e=>{let t=(0,R.c)(12),{data:r}=e,i;if(t[0]!==r){let{status:e,auth_required:a,action_url:o,meta:s,next_steps:c,message:l,...u}=r,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,B.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground`,children:`Tool Result`}),t[2]=d):d=t[2];let f;t[3]===e?f=t[4]:(f=(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize`,children:e}),t[3]=e,t[4]=f);let p;t[5]===a?p=t[6]:(p=a&&(0,B.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full`,children:`Auth Required`}),t[5]=a,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,B.jsxs)(`div`,{className:`flex items-center justify-between`,children:[d,(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p]})]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let h;t[10]===l?h=t[11]:(h=l&&(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(n,{className:`h-3 w-3 text-(--blue-11) mt-0.5 shrink-0`}),(0,B.jsx)(`div`,{className:`text-xs text-foreground`,children:l})]}),t[10]=l,t[11]=h),i=(0,B.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[m,h,u&&(0,B.jsx)(`div`,{className:`space-y-3`,children:Object.entries(u).map(Z)})]}),t[0]=r,t[1]=i}else i=t[1];return i},X=e=>{let t=(0,R.c)(8),{result:n}=e,r;t[0]===n?r=t[1]:(r=J.safeParse(n),t[0]=n,t[1]=r);let i=r;if(i.success){let e;return t[2]===i.data?e=t[3]:(e=(0,B.jsx)(Y,{data:i.data}),t[2]=i.data,t[3]=e),e}let a;t[4]===n?a=t[5]:(a=typeof n==`string`?n:JSON.stringify(n,null,2),t[4]=n,t[5]=a);let o;return t[6]===a?o=t[7]:(o=(0,B.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin`,children:a}),t[6]=a,t[7]=o),o};function Z(e){let[t,n]=e;return q(n)?null:(0,B.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}),(0,B.jsx)(`pre`,{className:`bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64`,children:JSON.stringify(n,null,2)})]},t)}var ee={"input-streaming":`Generating`,"input-available":`Running`,"approval-responded":`Awaiting result`,"output-available":`Done`,"output-denied":`Denied`},te=new Set([`input-streaming`,`input-available`,`approval-responded`]),ne=e=>{let t=(0,R.c)(5),{state:n,interrupted:r}=e;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(M,{className:`h-3 w-3 text-muted-foreground`}),t[0]=e):e=t[0],e}switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(O,{className:`h-3 w-3 animate-spin`}),t[1]=e):e=t[1],e}case`output-available`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(S,{className:`h-3 w-3 text-(--grass-11)`}),t[2]=e):e=t[2],e}case`output-denied`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(b,{className:`h-3 w-3 text-muted-foreground`}),t[3]=e):e=t[3],e}default:{A(n);let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,B.jsx)(k,{className:`h-3 w-3`}),t[4]=e):e=t[4],e}}};function re(e){switch(e){case`output-available`:return`text-(--grass-11)/80`;case`output-denied`:return`text-muted-foreground`;case`input-streaming`:case`input-available`:case`approval-responded`:return``;default:return A(e),``}}var Q=e=>{let t=(0,R.c)(34),{toolName:n,state:r,input:i,result:a,approval:o,index:s,className:c,isActive:l}=e,u=s===void 0?0:s,g=l===void 0||l,_;t[0]!==g||t[1]!==r?(_=!g&&te.has(r),t[0]=g,t[1]=r,t[2]=_):_=t[2];let v=_,y=`tool-${u}`,b;t[3]===c?b=t[4]:(b=h(`w-full`,c),t[3]=c,t[4]=b);let x;t[5]!==v||t[6]!==r?(x=h(`h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline`,v?`text-muted-foreground`:re(r)),t[5]=v,t[6]=r,t[7]=x):x=t[7];let S;t[8]!==v||t[9]!==r?(S=(0,B.jsx)(ne,{state:r,interrupted:v}),t[8]=v,t[9]=r,t[10]=S):S=t[10];let C=v?`Interrupted`:ee[r],w;t[11]===n?w=t[12]:(w=H(n),t[11]=n,t[12]=w);let T;t[13]===w?T=t[14]:(T=(0,B.jsx)(`code`,{className:`font-mono text-xs`,children:w}),t[13]=w,t[14]=T);let E;t[15]!==T||t[16]!==S||t[17]!==C?(E=(0,B.jsxs)(`span`,{className:`flex items-center gap-1`,children:[S,C,`:`,T]}),t[15]=T,t[16]=S,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==x?(D=(0,B.jsx)(p,{className:x,children:E}),t[19]=E,t[20]=x,t[21]=D):D=t[21];let O;t[22]!==o||t[23]!==i||t[24]!==a||t[25]!==r?(O=(0,B.jsx)(f,{className:`py-2 px-2`,children:(0,B.jsx)(ie,{state:r,input:i,result:a,approval:o})}),t[22]=o,t[23]=i,t[24]=a,t[25]=r,t[26]=O):O=t[26];let k;t[27]!==D||t[28]!==O?(k=(0,B.jsxs)(d,{value:`tool-call`,className:`border-0`,children:[D,O]}),t[27]=D,t[28]=O,t[29]=k):k=t[29];let A;return t[30]!==k||t[31]!==y||t[32]!==b?(A=(0,B.jsx)(m,{type:`single`,collapsible:!0,className:b,children:k},y),t[30]=k,t[31]=y,t[32]=b,t[33]=A):A=t[33],A},ie=e=>{let t=(0,R.c)(16),{state:n,input:r,result:i,approval:a}=e;switch(n){case`input-streaming`:case`input-available`:case`approval-responded`:{let e;return t[0]===r?e=t[1]:(e=(0,B.jsx)(U,{input:r}),t[0]=r,t[1]=e),e}case`output-available`:{let e;t[2]===r?e=t[3]:(e=(0,B.jsx)(U,{input:r}),t[2]=r,t[3]=e);let n;t[4]===i?n=t[5]:(n=i!=null&&(0,B.jsx)(X,{result:i}),t[4]=i,t[5]=n);let a;return t[6]!==e||t[7]!==n?(a=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,n]}),t[6]=e,t[7]=n,t[8]=a):a=t[8],a}case`output-denied`:{let e;t[9]===r?e=t[10]:(e=(0,B.jsx)(U,{input:r}),t[9]=r,t[10]=e);let n=a?.reason?`: ${a.reason}`:`.`,i;t[11]===n?i=t[12]:(i=(0,B.jsxs)(`div`,{className:`bg-muted/40 border border-border rounded-md p-3 text-xs text-muted-foreground leading-relaxed`,children:[`Tool execution was denied`,n]}),t[11]=n,t[12]=i);let o;return t[13]!==e||t[14]!==i?(o=(0,B.jsxs)(`div`,{className:`space-y-3`,children:[e,i]}),t[13]=e,t[14]=i,t[15]=o):o=t[15],o}default:return A(n),null}},$=e=>{let t=(0,R.c)(27),{toolName:n,state:r,result:i,errorText:a,input:o,approval:s,onApprove:c,index:l,className:u,isLive:d,isActive:f}=e,p=d===void 0||d,m=f===void 0||f;switch(r){case`approval-requested`:{if(s!=null&&c!=null){let e;return t[0]!==s||t[1]!==u||t[2]!==o||t[3]!==c||t[4]!==n?(e=(0,B.jsx)(W,{toolName:n,input:o,approval:s,onApprove:c,className:u}),t[0]=s,t[1]=u,t[2]=o,t[3]=c,t[4]=n,t[5]=e):e=t[5],e}let e;return t[6]!==u||t[7]!==l||t[8]!==o||t[9]!==m||t[10]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:`input-available`,input:o,index:l,className:u,isActive:m}),t[6]=u,t[7]=l,t[8]=o,t[9]=m,t[10]=n,t[11]=e):e=t[11],e}case`output-error`:{let e;return t[12]!==u||t[13]!==a||t[14]!==o||t[15]!==p||t[16]!==n?(e=(0,B.jsx)(G,{toolName:n,input:o,errorText:a,isLive:p,className:u}),t[12]=u,t[13]=a,t[14]=o,t[15]=p,t[16]=n,t[17]=e):e=t[17],e}case`input-streaming`:case`input-available`:case`approval-responded`:case`output-available`:case`output-denied`:{let e;return t[18]!==s||t[19]!==u||t[20]!==l||t[21]!==o||t[22]!==m||t[23]!==i||t[24]!==r||t[25]!==n?(e=(0,B.jsx)(Q,{toolName:n,state:r,input:o,result:i,approval:s,index:l,className:u,isActive:m}),t[18]=s,t[19]=u,t[20]=l,t[21]=o,t[22]=m,t[23]=i,t[24]=r,t[25]=n,t[26]=e):e=t[26],e}default:return A(r),null}},ae=({message:e,isStreamingReasoning:t,isLast:n,isActive:r,addToolApprovalResponse:i})=>{return(0,B.jsx)(B.Fragment,{children:e.parts.map((e,t)=>a(e,t))});function a(a,o){if(oe(a))return(0,B.jsx)($,{index:o,toolName:a.type,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,className:`my-2`,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);if(se(a))return u.debug(`Found data part`,a),null;switch(a.type){case`text`:return a.text.includes(`<marimo-`)?(0,B.jsx)(z.Fragment,{children:j({html:a.text})},o):(0,B.jsx)(w,{content:a.text},o);case`reasoning`:return(0,B.jsx)(V,{reasoning:a.text,index:o,isStreaming:t&&n&&o===(e.parts.length||0)-1},o);case`file`:return(0,B.jsx)(E,{attachment:a},o);case`reasoning-file`:return(0,B.jsx)(E,{attachment:{type:`file`,mediaType:a.mediaType,url:a.url}},o);case`dynamic-tool`:return(0,B.jsx)($,{toolName:a.toolName,result:a.output,errorText:a.state===`output-error`?a.errorText:void 0,state:a.state,input:a.input,approval:a.approval,onApprove:i,isLive:n,isActive:r},o);case`source-document`:return(0,B.jsx)(T,{icon:(0,B.jsx)(y,{className:`h-3 w-3 shrink-0`}),title:a.title,subtitle:a.filename},o);case`source-url`:return(0,B.jsx)(T,{icon:(0,B.jsx)(D,{className:`h-3 w-3 shrink-0`}),title:a.title??a.url,subtitle:a.title?a.url:void 0,href:a.url},o);case`custom`:return(0,B.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:a.kind},o);case`step-start`:return null;default:return A(a),null}}};function oe(e){return e.type.startsWith(`tool-`)}function se(e){return e.type.startsWith(`data-`)}export{I as i,L as n,F as r,ae as t};