@marimo-team/frontend 0.19.8-dev7 → 0.19.8-dev9
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.
- package/dist/assets/{JsonOutput-DT5cq5VJ.js → JsonOutput-BTXiwFjF.js} +1 -1
- package/dist/assets/{agent-panel-BcW46iQe.js → agent-panel-CCs3ktma.js} +1 -1
- package/dist/assets/{cell-editor-Uy3yV7H0.js → cell-editor-COnUMHxW.js} +1 -1
- package/dist/assets/{column-preview-DsINQLcy.js → column-preview-t0CyBVJf.js} +1 -1
- package/dist/assets/{command-palette-Cz8h81mi.js → command-palette-DJg1FMo6.js} +1 -1
- package/dist/assets/{edit-page-C3g76WMW.js → edit-page-1kpZH_Tj.js} +3 -3
- package/dist/assets/{file-explorer-panel-CAm65Xwe.js → file-explorer-panel-d9LDZt_k.js} +1 -1
- package/dist/assets/{hooks-T4-_AFet.js → hooks-jQB62wos.js} +1 -1
- package/dist/assets/{index-Dlg8GjKO.js → index-BL9e2vk6.js} +10 -10
- package/dist/assets/{layout-DeO-Ppt-.js → layout-BztBqV-1.js} +1 -1
- package/dist/assets/{panels-BdSNXi2d.js → panels-vsOIbBB6.js} +1 -1
- package/dist/assets/{run-page--5xaW5m2.js → run-page-nX90i6hX.js} +1 -1
- package/dist/assets/{scratchpad-panel-DN5qbbIL.js → scratchpad-panel-BFFeceHa.js} +1 -1
- package/dist/assets/{session-panel-DSLj3C81.js → session-panel-IeLEqwsB.js} +1 -1
- package/dist/assets/{useNotebookActions-bMdZvJyI.js → useNotebookActions-DRVyh52j.js} +1 -1
- package/dist/assets/{utilities.esm-Buwqinna.js → utilities.esm-8Diy8be3.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/src/components/data-table/__tests__/data-table.test.tsx +94 -2
- package/src/core/MarimoApp.tsx +12 -8
- package/src/plugins/core/registerReactComponent.tsx +9 -1
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +164 -0
- package/src/utils/__tests__/mime-types.test.ts +8 -10
- package/src/utils/mime-types.ts +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as de}from"./chunk-LvLJmgfZ.js";import{d as D,l as Oe,p as Be,u as ee}from"./useEvent-BhXAndur.js";import{t as Ue}from"./react-Bj1aDYRI.js";import{Kn as Ye,Un as $e,Vn as Fe,Zn as Ge,_r as Ke,cn as Je,g as Ze,jt as Xe,ln as Qe,m as ce,pn as he,ri as te,sn as et,t as tt,w as pe}from"./cells-DdLMh4kY.js";import{t as W}from"./compiler-runtime-B3qBwwSJ.js";import{n as at}from"./assertNever-CBU83Y6o.js";import{s as me}from"./useLifecycle-ClI_npeg.js";import{n as ot}from"./add-database-form-CUZKNC1e.js";import{n as nt,x as it}from"./ai-model-dropdown-C_Fhvna-.js";import{a as ue,d as I}from"./hotkeys-BHHWjLlp.js";import{y as lt}from"./utils-YqBXNpsM.js";import{n as _,t as fe}from"./constants-B6Cb__3x.js";import{S as ye,h as st,x as rt}from"./config-D2-Bw6QC.js";import{t as dt}from"./jsx-runtime-ZmTK25f3.js";import{r as ct,t as ae}from"./button-CZ3Cs4qb.js";import{r as P}from"./requests-B4FYHTZl.js";import{t as h}from"./createLucideIcon-BCdY6lG5.js";import{a as be,f as ht,i as ke,m as pt,p as xe,u as we}from"./layout-DeO-Ppt-.js";import{t as ge}from"./check-Dr3SxUsb.js";import{c as mt,d as je,n as ut,o as ft,r as ve,t as yt}from"./download-BodpSpiQ.js";import{f as bt}from"./maps-D2_Mq1pZ.js";import{r as kt}from"./useCellActionButton-DUpWwYW8.js";import{t as xt}from"./copy-D-8y6iMN.js";import{t as wt}from"./download-Dg7clfkc.js";import{t as gt}from"./eye-off-AK_9uodG.js";import{t as jt}from"./file-plus-corner-CvAy4H5W.js";import{t as vt}from"./file-Ch78NKWp.js";import{i as Ct,n as zt,r as Mt,t as Wt}from"./youtube--tNPNRy6.js";import{n as _t,t as St}from"./house-BI81AWSn.js";import{n as At}from"./play-GLWQQs7F.js";import{t as Nt}from"./link-DxicfMbs.js";import{r as Dt}from"./input-DHHmNa19.js";import{t as It}from"./settings-OBbrbhij.js";import{y as Pt}from"./textarea-BFfMAEaQ.js";import{t as Et}from"./square-DPZjfUaq.js";import{t as C}from"./use-toast-T0_cQDma.js";import{n as Ce,t as Tt}from"./paths-Dfii2bN8.js";import{o as Ht}from"./session-fBtIbMpB.js";import{a as Lt,c as qt,i as Rt,n as Vt,r as Ot,s as Bt,t as Ut}from"./select-B7bfltkI.js";import{t as Yt}from"./tooltip-C_WgOOcZ.js";import{a as ze,i as $t,r as Ft}from"./mode-BfhhQnCm.js";import{o as Gt}from"./alert-dialog-Ctz24SMn.js";import{a as Kt,c as Jt,i as Zt,n as Xt,r as Qt}from"./dialog-tQELcltn.js";import{n as oe}from"./ImperativeModal-DZr52ffu.js";import{r as ea,t as ta}from"./share-rXkgGlhr.js";import{t as U}from"./copy-DHrHayPa.js";import{r as aa}from"./useRunCells-CmbQTUeO.js";import{a as oa}from"./cell-link-OwIbBa8Q.js";import{a as Me}from"./renderShortcut-B1jzzLJw.js";import{t as na}from"./icons-DjR3qLG_.js";import{t as ia}from"./links-DgZx-VxW.js";import{r as la,t as sa}from"./hooks-T4-_AFet.js";import{t as We}from"./types-DZmRsGZN.js";var ra=h("circle-chevron-down",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 10-4 4-4-4",key:"894hmk"}]]),da=h("circle-chevron-right",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m10 8 4 4-4 4",key:"1wy4r4"}]]),_e=h("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),Se=h("command",[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]]),Ae=h("diamond-plus",[["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41L13.7 2.71a2.41 2.41 0 0 0-3.41 0z",key:"1ey20j"}],["path",{d:"M8 12h8",key:"1wcyev"}]]),ca=h("fast-forward",[["path",{d:"M12 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 12 18z",key:"b19h5q"}],["path",{d:"M2 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 2 18z",key:"h7h5ge"}]]),ha=h("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),pa=h("keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]),Ne=h("layout-template",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]),ma=h("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),ua=h("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),De=h("presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),fa=h("share-2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),ya=h("square-power",[["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M7.998 9.003a5 5 0 1 0 8-.005",key:"1pek45"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),Ie=h("undo-2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Pe=W(),ne=de(Ue(),1),a=de(dt(),1),Y="https://static.marimo.app";const ba=e=>{let t=(0,Pe.c)(25),{onClose:n}=e,[o,l]=(0,ne.useState)(""),{exportAsHTML:r}=P(),s=`${o}-${Math.random().toString(36).slice(2,6)}`,i=`${Y}/static/${s}`,d;t[0]!==r||t[1]!==n||t[2]!==s?(d=async v=>{v.preventDefault(),n();let S=await r({download:!1,includeCode:!0,files:ht.INSTANCE.filenames()}),z=C({title:"Uploading static notebook...",description:"Please wait."});await fetch(`${Y}/api/static`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:S,path:s})}).catch(()=>{z.dismiss(),C({title:"Error uploading static page",description:(0,a.jsxs)("div",{children:["Please try again later. If the problem persists, please file a bug report on"," ",(0,a.jsx)("a",{href:_.issuesPage,target:"_blank",className:"underline",children:"GitHub"}),"."]})})}),z.dismiss(),C({title:"Static page uploaded!",description:(0,a.jsxs)("div",{children:["The URL has been copied to your clipboard.",(0,a.jsx)("br",{}),"You can share it with anyone."]})})},t[0]=r,t[1]=n,t[2]=s,t[3]=d):d=t[3];let p;t[4]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)(Jt,{children:"Share static notebook"}),t[4]=p):p=t[4];let w;t[5]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)(Kt,{children:[p,(0,a.jsxs)(Qt,{children:["You can publish a static, non-interactive version of this notebook to the public web. We will create a link for you that lives on"," ",(0,a.jsx)("a",{href:Y,target:"_blank",children:Y}),"."]})]}),t[5]=w):w=t[5];let g;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{l(v.target.value.toLowerCase().replaceAll(/\s/g,"-").replaceAll(/[^\da-z-]/g,""))},t[6]=g):g=t[6];let m;t[7]===o?m=t[8]:(m=(0,a.jsx)(Dt,{"data-testid":"slug-input",id:"slug",autoFocus:!0,value:o,placeholder:"Notebook slug",onChange:g,required:!0,autoComplete:"off"}),t[7]=o,t[8]=m);let u;t[9]===i?u=t[10]:(u=(0,a.jsxs)("div",{className:"font-semibold text-sm text-muted-foreground gap-2 flex flex-col",children:["Anyone will be able to access your notebook at this URL:",(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ka,{text:i}),(0,a.jsx)("span",{className:"text-primary",children:i})]})]}),t[9]=i,t[10]=u);let f;t[11]!==m||t[12]!==u?(f=(0,a.jsxs)("div",{className:"flex flex-col gap-6 py-4",children:[m,u]}),t[11]=m,t[12]=u,t[13]=f):f=t[13];let y;t[14]===n?y=t[15]:(y=(0,a.jsx)(ae,{"data-testid":"cancel-share-static-notebook-button",variant:"secondary",onClick:n,children:"Cancel"}),t[14]=n,t[15]=y);let b;t[16]===i?b=t[17]:(b=(0,a.jsx)(ae,{"data-testid":"share-static-notebook-button","aria-label":"Save",variant:"default",type:"submit",onClick:async()=>{await U(i)},children:"Create"}),t[16]=i,t[17]=b);let k;t[18]!==y||t[19]!==b?(k=(0,a.jsxs)(Zt,{children:[y,b]}),t[18]=y,t[19]=b,t[20]=k):k=t[20];let j;return t[21]!==d||t[22]!==k||t[23]!==f?(j=(0,a.jsx)(Xt,{className:"w-fit",children:(0,a.jsxs)("form",{onSubmit:d,children:[w,f,k]})}),t[21]=d,t[22]=k,t[23]=f,t[24]=j):j=t[24],j};var ka=e=>{let t=(0,Pe.c)(8),[n,o]=ne.useState(!1),l;t[0]===e.text?l=t[1]:(l=ct.stopPropagation(async p=>{p.preventDefault(),await U(e.text),o(!0),setTimeout(()=>o(!1),2e3)}),t[0]=e.text,t[1]=l);let r=l,s;t[2]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsx)(xt,{size:14,strokeWidth:1.5}),t[2]=s):s=t[2];let i;t[3]===r?i=t[4]:(i=(0,a.jsx)(ae,{"data-testid":"copy-static-notebook-url-button",onClick:r,size:"xs",variant:"secondary",children:s}),t[3]=r,t[4]=i);let d;return t[5]!==n||t[6]!==i?(d=(0,a.jsx)(Yt,{content:"Copied!",open:n,children:i}),t[5]=n,t[6]=i,t[7]=d):d=t[7],d},xa=W();function wa(){let e=document.getElementsByClassName(fe.outputArea);for(let t of e){let n=t.getBoundingClientRect();if(n.bottom>0&&n.top<window.innerHeight){let o=te.findElement(t);if(!o){I.warn("Could not find HTMLCellId for visible output area",t);continue}return{cellId:te.parse(o.id)}}}return I.warn("No visible output area found for scroll anchor"),null}function ga(e){if(!e){I.warn("No scroll anchor provided to restore scroll position");return}let t=document.getElementById(te.create(e.cellId));if(!t){I.warn("Could not find cell element to restore scroll position",e.cellId);return}if(!t.querySelector(`.${fe.outputArea}`)){I.warn("Could not find output area to restore scroll position",e.cellId);return}t.scrollIntoView({block:"start",behavior:"auto"})}function Ee(){let e=(0,xa.c)(2),t=D(ze),n;return e[0]===t?n=e[1]:(n=()=>{let o=wa();t(l=>({mode:$t(l.mode),cellAnchor:(o==null?void 0:o.cellId)??null})),requestAnimationFrame(()=>{requestAnimationFrame(()=>{ga(o)})})},e[0]=t,e[1]=n),n}const Te=Be(!1);var ja=W();const va=()=>{let e=(0,ja.c)(7),{selectedLayout:t}=be(),{setLayoutView:n}=ke();if(ye()&&!he("wasm_layouts"))return null;let o;e[0]===n?o=e[1]:(o=i=>n(i),e[0]=n,e[1]=o);let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=(0,a.jsx)(Bt,{className:"min-w-[110px] border-border bg-background","data-testid":"layout-select",children:(0,a.jsx)(qt,{placeholder:"Select a view"})}),e[2]=l):l=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)(Vt,{children:(0,a.jsxs)(Ot,{children:[(0,a.jsx)(Lt,{children:"View as"}),We.map(za)]})}),e[3]=r):r=e[3];let s;return e[4]!==t||e[5]!==o?(s=(0,a.jsxs)(Ut,{"data-testid":"layout-select",value:t,onValueChange:o,children:[l,r]}),e[4]=t,e[5]=o,e[6]=s):s=e[6],s};function Ca(e){return(0,a.jsx)(He(e),{className:"h-4 w-4"})}function He(e){switch(e){case"vertical":return ma;case"grid":return Mt;case"slides":return De;default:return at(e),Et}}function Le(e){return me(e)}function za(e){return(0,a.jsx)(Rt,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 leading-5",children:[Ca(e),(0,a.jsx)("span",{children:Le(e)})]})},e)}var Ma=W();function Wa(e){let t=(0,Ma.c)(5),{openPrompt:n,closeModal:o}=oe(),{sendCopy:l}=P(),r;return t[0]!==o||t[1]!==n||t[2]!==l||t[3]!==e?(r=()=>{if(!e)return null;let s=Tt.guessDeliminator(e);n({title:"Copy notebook",description:"Enter a new filename for the notebook copy.",defaultValue:`_${Ce.basename(e)}`,confirmText:"Copy notebook",spellCheck:!1,onConfirm:i=>{let d=s.join(Ce.dirname(e),i);l({source:e,destination:d}).then(()=>{o(),C({title:"Notebook copied",description:"A copy of the notebook has been created."}),ia(d)})}})},t[0]=o,t[1]=n,t[2]=l,t[3]=e,t[4]=r):r=t[4],r}const _a=()=>{let{updateCellConfig:e}=pe(),{saveCellConfig:t}=P();return(0,ne.useCallback)(async()=>{let n=new Xe,o=ce(),l=o.cellIds.inOrderIds,r={};for(let i of l){if(o.cellData[i]===void 0)continue;let{code:d,config:p}=o.cellData[i];p.hide_code||n.isSupported(d)&&(r[i]={hide_code:!0})}let s=ue.entries(r);if(s.length!==0){await t({configs:r});for(let[i,d]of s)e({cellId:i,config:d})}},[e])};var Sa=W();function qe(){let e=(0,Sa.c)(4),{openConfirm:t}=oe(),n=D(st),{sendRestart:o}=P(),l;return e[0]!==t||e[1]!==o||e[2]!==n?(l=()=>{t({title:"Restart Kernel",description:"This will restart the Python kernel. You'll lose all data that's in memory. You will also lose any unsaved changes, so make sure to save your work before restarting.",variant:"destructive",confirmAction:(0,a.jsx)(Gt,{onClick:async()=>{n({state:rt.CLOSING}),await o(),ea()},"aria-label":"Confirm Restart",children:"Restart"})})},e[0]=t,e[1]=o,e[2]=n,e[3]=l):l=e[3],l}var Aa=W(),E=e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()};function Na(){var se,re;let e=(0,Aa.c)(40),t=oa(),{openModal:n,closeModal:o}=oe(),{toggleApplication:l}=et(),{selectedPanel:r}=Je(),[s]=Oe(ze),i=ee(Ft),d=_a(),[p]=lt(),{updateCellConfig:w,undoDeleteCell:g,clearAllCellOutputs:m,addSetupCellIfDoesntExist:u,collapseAllCells:f,expandAllCells:y}=pe(),b=qe(),k=aa(),j=Wa(t),v=D(Te),S=D(nt),z=D(it),{exportAsMarkdown:$,readCode:A,saveCellConfig:F,updateCellOutputs:G}=P(),K=ee(Ze),J=ee(tt),{selectedLayout:Z}=be(),{setLayoutView:X}=ke(),T=Ee(),Q=la(),H=((se=p.sharing)==null?void 0:se.html)??!0,L=((re=p.sharing)==null?void 0:re.wasm)??!0,q;e[0]===Symbol.for("react.memo_cache_sentinel")?(q=he("server_side_pdf_export"),e[0]=q):q=e[0];let le=q,R=le||s.mode==="present",Re=Ga,V;e[1]===Symbol.for("react.memo_cache_sentinel")?(V=(0,a.jsx)(wt,{size:14,strokeWidth:1.5}),e[1]=V):V=e[1];let O;e[2]===Symbol.for("react.memo_cache_sentinel")?(O=(0,a.jsx)(xe,{size:14,strokeWidth:1.5}),e[2]=O):O=e[2];let M;e[3]===t?M=e[4]:(M=async()=>{if(!t){ie();return}await we({filename:t,includeCode:!0})},e[3]=t,e[4]=M);let B;return e[5]!==u||e[6]!==J||e[7]!==m||e[8]!==o||e[9]!==f||e[10]!==j||e[11]!==y||e[12]!==$||e[13]!==t||e[14]!==K||e[15]!==d||e[16]!==i||e[17]!==n||e[18]!==R||e[19]!==A||e[20]!==b||e[21]!==k||e[22]!==F||e[23]!==Z||e[24]!==r||e[25]!==v||e[26]!==z||e[27]!==X||e[28]!==S||e[29]!==H||e[30]!==L||e[31]!==M||e[32]!==Q||e[33]!==l||e[34]!==T||e[35]!==g||e[36]!==w||e[37]!==G||e[38]!==s.mode?(B=[{icon:V,label:"Download",handle:E,dropdown:[{icon:O,label:"Download as HTML",handle:M},{icon:(0,a.jsx)(xe,{size:14,strokeWidth:1.5}),label:"Download as HTML (exclude code)",handle:async()=>{if(!t){ie();return}await we({filename:t,includeCode:!1})}},{icon:(0,a.jsx)(na,{strokeWidth:1.5,style:{width:14,height:14}}),label:"Download as Markdown",handle:async()=>{let c=await $({download:!1});ve(new Blob([c],{type:"text/plain"}),je.toMarkdown(document.title))}},{icon:(0,a.jsx)(pt,{size:14,strokeWidth:1.5}),label:"Download Python code",handle:async()=>{let c=await A();ve(new Blob([c.contents],{type:"text/plain"}),je.toPY(document.title))}},{divider:!0,icon:(0,a.jsx)(At,{size:14,strokeWidth:1.5}),label:"Download as PNG",disabled:s.mode!=="present",tooltip:s.mode==="present"?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",Me("global.hideCode",!1)]}),handle:Fa},{icon:(0,a.jsx)(vt,{size:14,strokeWidth:1.5}),label:"Download as PDF",disabled:!R,tooltip:R?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",Me("global.hideCode",!1)]}),handle:async()=>{if(le){if(!t){ie();return}await mt("Downloading PDF...",async N=>{await sa({takeScreenshots:()=>Q({progress:N}),updateCellOutputs:G}),await ut({filename:t,webpdf:!1})});return}let c=new Event("export-beforeprint"),x=new Event("export-afterprint");(function(){window.dispatchEvent(c),setTimeout($a,0),setTimeout(()=>window.dispatchEvent(x),0)})()}}]},{icon:(0,a.jsx)(fa,{size:14,strokeWidth:1.5}),label:"Share",handle:E,hidden:!H&&!L,dropdown:[{icon:(0,a.jsx)(_t,{size:14,strokeWidth:1.5}),label:"Publish HTML to web",hidden:!H,handle:async()=>{n((0,a.jsx)(ba,{onClose:o}))}},{icon:(0,a.jsx)(Nt,{size:14,strokeWidth:1.5}),label:"Create WebAssembly link",hidden:!L,handle:async()=>{await U(ta({code:(await A()).contents})),C({title:"Copied",description:"Link copied to clipboard."})}}]},{icon:(0,a.jsx)(ua,{size:14,strokeWidth:1.5}),label:"Helper panel",redundant:!0,handle:E,dropdown:Qe.flatMap(c=>{let{type:x,Icon:N,hidden:Ve}=c;return Ve?[]:{label:me(x),rightElement:Re(r===x),icon:(0,a.jsx)(N,{size:14,strokeWidth:1.5}),handle:()=>l(x)}})},{icon:(0,a.jsx)(De,{size:14,strokeWidth:1.5}),label:"Present as",handle:E,dropdown:[{icon:s.mode==="present"?(0,a.jsx)(Pt,{size:14,strokeWidth:1.5}):(0,a.jsx)(Ne,{size:14,strokeWidth:1.5}),label:"Toggle app view",hotkey:"global.hideCode",handle:()=>{T()}},...We.map((c,x)=>{let N=He(c);return{divider:x===0,label:Le(c),icon:(0,a.jsx)(N,{size:14,strokeWidth:1.5}),rightElement:(0,a.jsx)("div",{className:"w-8 flex justify-end",children:Z===c&&(0,a.jsx)(ge,{size:14})}),handle:()=>{X(c),s.mode==="edit"&&T()}}})]},{icon:(0,a.jsx)(ha,{size:14,strokeWidth:1.5}),label:"Duplicate notebook",hidden:!t||ye(),handle:j},{icon:(0,a.jsx)(_e,{size:14,strokeWidth:1.5}),label:"Copy code to clipboard",hidden:!t,handle:async()=>{await U((await A()).contents),C({title:"Copied",description:"Code copied to clipboard."})}},{icon:(0,a.jsx)(kt,{size:14,strokeWidth:1.5}),label:"Enable all cells",hidden:!K||i,handle:async()=>{let c=Ke(ce());await F({configs:ue.fromEntries(c.map(Ya))});for(let x of c)w({cellId:x,config:{disabled:!1}})}},{divider:!0,icon:(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),label:"Add setup cell",handle:()=>{u({})}},{icon:(0,a.jsx)($e,{size:14,strokeWidth:1.5}),label:"Add database connection",handle:()=>{n((0,a.jsx)(ot,{onClose:o}))}},{icon:(0,a.jsx)(Ie,{size:14,strokeWidth:1.5}),label:"Undo cell deletion",hidden:!J||i,handle:()=>{g()}},{icon:(0,a.jsx)(ya,{size:14,strokeWidth:1.5}),label:"Restart kernel",variant:"danger",handle:b},{icon:(0,a.jsx)(ca,{size:14,strokeWidth:1.5}),label:"Re-run all cells",redundant:!0,hotkey:"global.runAll",handle:async()=>{k()}},{icon:(0,a.jsx)(Ye,{size:14,strokeWidth:1.5}),label:"Clear all outputs",redundant:!0,handle:()=>{m()}},{icon:(0,a.jsx)(gt,{size:14,strokeWidth:1.5}),label:"Hide all markdown code",handle:d,redundant:!0},{icon:(0,a.jsx)(da,{size:14,strokeWidth:1.5}),label:"Collapse all sections",hotkey:"global.collapseAllSections",handle:f,redundant:!0},{icon:(0,a.jsx)(ra,{size:14,strokeWidth:1.5}),label:"Expand all sections",hotkey:"global.expandAllSections",handle:y,redundant:!0},{divider:!0,icon:(0,a.jsx)(Se,{size:14,strokeWidth:1.5}),label:"Command palette",hotkey:"global.commandPalette",handle:()=>v(Ua)},{icon:(0,a.jsx)(pa,{size:14,strokeWidth:1.5}),label:"Keyboard shortcuts",hotkey:"global.showHelp",handle:()=>z(Ba)},{icon:(0,a.jsx)(It,{size:14,strokeWidth:1.5}),label:"User settings",handle:()=>S(Oa),redundant:!0},{icon:(0,a.jsx)(bt,{size:14,strokeWidth:1.5}),label:"Resources",handle:E,dropdown:[{icon:(0,a.jsx)(Ge,{size:14,strokeWidth:1.5}),label:"Documentation",handle:Va},{icon:(0,a.jsx)(Ct,{size:14,strokeWidth:1.5}),label:"GitHub",handle:Ra},{icon:(0,a.jsx)(zt,{size:14,strokeWidth:1.5}),label:"Discord Community",handle:qa},{icon:(0,a.jsx)(Wt,{size:14,strokeWidth:1.5}),label:"YouTube",handle:La},{icon:(0,a.jsx)(Fe,{size:14,strokeWidth:1.5}),label:"Changelog",handle:Ha}]},{divider:!0,icon:(0,a.jsx)(St,{size:14,strokeWidth:1.5}),label:"Return home",hidden:!location.search.includes("file"),handle:Ta},{icon:(0,a.jsx)(jt,{size:14,strokeWidth:1.5}),label:"New notebook",hidden:!location.search.includes("file"),handle:Ea}].filter(Pa).map(Da),e[5]=u,e[6]=J,e[7]=m,e[8]=o,e[9]=f,e[10]=j,e[11]=y,e[12]=$,e[13]=t,e[14]=K,e[15]=d,e[16]=i,e[17]=n,e[18]=R,e[19]=A,e[20]=b,e[21]=k,e[22]=F,e[23]=Z,e[24]=r,e[25]=v,e[26]=z,e[27]=X,e[28]=S,e[29]=H,e[30]=L,e[31]=M,e[32]=Q,e[33]=l,e[34]=T,e[35]=g,e[36]=w,e[37]=G,e[38]=s.mode,e[39]=B):B=e[39],B}function Da(e){return e.dropdown?{...e,dropdown:e.dropdown.filter(Ia)}:e}function Ia(e){return!e.hidden}function Pa(e){return!e.hidden}function Ea(){let e=Ht();window.open(e,"_blank")}function Ta(){let e=document.baseURI.split("?")[0];window.open(e,"_self")}function Ha(){window.open(_.releasesPage,"_blank")}function La(){window.open(_.youtube,"_blank")}function qa(){window.open(_.discordLink,"_blank")}function Ra(){window.open(_.githubPage,"_blank")}function Va(){window.open(_.docsPage,"_blank")}function Oa(e){return!e}function Ba(e){return!e}function Ua(e){return!e}function Ya(e){return[e,{disabled:!1}]}function $a(){return window.print()}async function Fa(){let e=document.getElementById("App");e&&await ft({element:e,filename:document.title,prepare:yt})}function Ga(e){return(0,a.jsx)("div",{className:"w-8 flex justify-end",children:e&&(0,a.jsx)(ge,{size:14})})}function ie(){C({title:"Error",description:"Notebooks must be named to be exported.",variant:"danger"})}export{Ee as a,Ae as c,Te as i,Se as l,qe as n,Ie as o,va as r,Ne as s,Na as t,_e as u};
|
|
1
|
+
import{s as de}from"./chunk-LvLJmgfZ.js";import{d as D,l as Oe,p as Be,u as ee}from"./useEvent-BhXAndur.js";import{t as Ue}from"./react-Bj1aDYRI.js";import{Kn as Ye,Un as $e,Vn as Fe,Zn as Ge,_r as Ke,cn as Je,g as Ze,jt as Xe,ln as Qe,m as ce,pn as he,ri as te,sn as et,t as tt,w as pe}from"./cells-DdLMh4kY.js";import{t as W}from"./compiler-runtime-B3qBwwSJ.js";import{n as at}from"./assertNever-CBU83Y6o.js";import{s as me}from"./useLifecycle-ClI_npeg.js";import{n as ot}from"./add-database-form-CUZKNC1e.js";import{n as nt,x as it}from"./ai-model-dropdown-C_Fhvna-.js";import{a as ue,d as I}from"./hotkeys-BHHWjLlp.js";import{y as lt}from"./utils-YqBXNpsM.js";import{n as _,t as fe}from"./constants-B6Cb__3x.js";import{S as ye,h as st,x as rt}from"./config-D2-Bw6QC.js";import{t as dt}from"./jsx-runtime-ZmTK25f3.js";import{r as ct,t as ae}from"./button-CZ3Cs4qb.js";import{r as P}from"./requests-B4FYHTZl.js";import{t as h}from"./createLucideIcon-BCdY6lG5.js";import{a as be,f as ht,i as ke,m as pt,p as xe,u as we}from"./layout-BztBqV-1.js";import{t as ge}from"./check-Dr3SxUsb.js";import{c as mt,d as je,n as ut,o as ft,r as ve,t as yt}from"./download-BodpSpiQ.js";import{f as bt}from"./maps-D2_Mq1pZ.js";import{r as kt}from"./useCellActionButton-DUpWwYW8.js";import{t as xt}from"./copy-D-8y6iMN.js";import{t as wt}from"./download-Dg7clfkc.js";import{t as gt}from"./eye-off-AK_9uodG.js";import{t as jt}from"./file-plus-corner-CvAy4H5W.js";import{t as vt}from"./file-Ch78NKWp.js";import{i as Ct,n as zt,r as Mt,t as Wt}from"./youtube--tNPNRy6.js";import{n as _t,t as St}from"./house-BI81AWSn.js";import{n as At}from"./play-GLWQQs7F.js";import{t as Nt}from"./link-DxicfMbs.js";import{r as Dt}from"./input-DHHmNa19.js";import{t as It}from"./settings-OBbrbhij.js";import{y as Pt}from"./textarea-BFfMAEaQ.js";import{t as Et}from"./square-DPZjfUaq.js";import{t as C}from"./use-toast-T0_cQDma.js";import{n as Ce,t as Tt}from"./paths-Dfii2bN8.js";import{o as Ht}from"./session-fBtIbMpB.js";import{a as Lt,c as qt,i as Rt,n as Vt,r as Ot,s as Bt,t as Ut}from"./select-B7bfltkI.js";import{t as Yt}from"./tooltip-C_WgOOcZ.js";import{a as ze,i as $t,r as Ft}from"./mode-BfhhQnCm.js";import{o as Gt}from"./alert-dialog-Ctz24SMn.js";import{a as Kt,c as Jt,i as Zt,n as Xt,r as Qt}from"./dialog-tQELcltn.js";import{n as oe}from"./ImperativeModal-DZr52ffu.js";import{r as ea,t as ta}from"./share-rXkgGlhr.js";import{t as U}from"./copy-DHrHayPa.js";import{r as aa}from"./useRunCells-CmbQTUeO.js";import{a as oa}from"./cell-link-OwIbBa8Q.js";import{a as Me}from"./renderShortcut-B1jzzLJw.js";import{t as na}from"./icons-DjR3qLG_.js";import{t as ia}from"./links-DgZx-VxW.js";import{r as la,t as sa}from"./hooks-jQB62wos.js";import{t as We}from"./types-DZmRsGZN.js";var ra=h("circle-chevron-down",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 10-4 4-4-4",key:"894hmk"}]]),da=h("circle-chevron-right",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m10 8 4 4-4 4",key:"1wy4r4"}]]),_e=h("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]),Se=h("command",[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]]),Ae=h("diamond-plus",[["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41L13.7 2.71a2.41 2.41 0 0 0-3.41 0z",key:"1ey20j"}],["path",{d:"M8 12h8",key:"1wcyev"}]]),ca=h("fast-forward",[["path",{d:"M12 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 12 18z",key:"b19h5q"}],["path",{d:"M2 6a2 2 0 0 1 3.414-1.414l6 6a2 2 0 0 1 0 2.828l-6 6A2 2 0 0 1 2 18z",key:"h7h5ge"}]]),ha=h("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),pa=h("keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]),Ne=h("layout-template",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]),ma=h("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),ua=h("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),De=h("presentation",[["path",{d:"M2 3h20",key:"91anmk"}],["path",{d:"M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3",key:"2k9sn8"}],["path",{d:"m7 21 5-5 5 5",key:"bip4we"}]]),fa=h("share-2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),ya=h("square-power",[["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M7.998 9.003a5 5 0 1 0 8-.005",key:"1pek45"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),Ie=h("undo-2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Pe=W(),ne=de(Ue(),1),a=de(dt(),1),Y="https://static.marimo.app";const ba=e=>{let t=(0,Pe.c)(25),{onClose:n}=e,[o,l]=(0,ne.useState)(""),{exportAsHTML:r}=P(),s=`${o}-${Math.random().toString(36).slice(2,6)}`,i=`${Y}/static/${s}`,d;t[0]!==r||t[1]!==n||t[2]!==s?(d=async v=>{v.preventDefault(),n();let S=await r({download:!1,includeCode:!0,files:ht.INSTANCE.filenames()}),z=C({title:"Uploading static notebook...",description:"Please wait."});await fetch(`${Y}/api/static`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:S,path:s})}).catch(()=>{z.dismiss(),C({title:"Error uploading static page",description:(0,a.jsxs)("div",{children:["Please try again later. If the problem persists, please file a bug report on"," ",(0,a.jsx)("a",{href:_.issuesPage,target:"_blank",className:"underline",children:"GitHub"}),"."]})})}),z.dismiss(),C({title:"Static page uploaded!",description:(0,a.jsxs)("div",{children:["The URL has been copied to your clipboard.",(0,a.jsx)("br",{}),"You can share it with anyone."]})})},t[0]=r,t[1]=n,t[2]=s,t[3]=d):d=t[3];let p;t[4]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)(Jt,{children:"Share static notebook"}),t[4]=p):p=t[4];let w;t[5]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)(Kt,{children:[p,(0,a.jsxs)(Qt,{children:["You can publish a static, non-interactive version of this notebook to the public web. We will create a link for you that lives on"," ",(0,a.jsx)("a",{href:Y,target:"_blank",children:Y}),"."]})]}),t[5]=w):w=t[5];let g;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{l(v.target.value.toLowerCase().replaceAll(/\s/g,"-").replaceAll(/[^\da-z-]/g,""))},t[6]=g):g=t[6];let m;t[7]===o?m=t[8]:(m=(0,a.jsx)(Dt,{"data-testid":"slug-input",id:"slug",autoFocus:!0,value:o,placeholder:"Notebook slug",onChange:g,required:!0,autoComplete:"off"}),t[7]=o,t[8]=m);let u;t[9]===i?u=t[10]:(u=(0,a.jsxs)("div",{className:"font-semibold text-sm text-muted-foreground gap-2 flex flex-col",children:["Anyone will be able to access your notebook at this URL:",(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ka,{text:i}),(0,a.jsx)("span",{className:"text-primary",children:i})]})]}),t[9]=i,t[10]=u);let f;t[11]!==m||t[12]!==u?(f=(0,a.jsxs)("div",{className:"flex flex-col gap-6 py-4",children:[m,u]}),t[11]=m,t[12]=u,t[13]=f):f=t[13];let y;t[14]===n?y=t[15]:(y=(0,a.jsx)(ae,{"data-testid":"cancel-share-static-notebook-button",variant:"secondary",onClick:n,children:"Cancel"}),t[14]=n,t[15]=y);let b;t[16]===i?b=t[17]:(b=(0,a.jsx)(ae,{"data-testid":"share-static-notebook-button","aria-label":"Save",variant:"default",type:"submit",onClick:async()=>{await U(i)},children:"Create"}),t[16]=i,t[17]=b);let k;t[18]!==y||t[19]!==b?(k=(0,a.jsxs)(Zt,{children:[y,b]}),t[18]=y,t[19]=b,t[20]=k):k=t[20];let j;return t[21]!==d||t[22]!==k||t[23]!==f?(j=(0,a.jsx)(Xt,{className:"w-fit",children:(0,a.jsxs)("form",{onSubmit:d,children:[w,f,k]})}),t[21]=d,t[22]=k,t[23]=f,t[24]=j):j=t[24],j};var ka=e=>{let t=(0,Pe.c)(8),[n,o]=ne.useState(!1),l;t[0]===e.text?l=t[1]:(l=ct.stopPropagation(async p=>{p.preventDefault(),await U(e.text),o(!0),setTimeout(()=>o(!1),2e3)}),t[0]=e.text,t[1]=l);let r=l,s;t[2]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsx)(xt,{size:14,strokeWidth:1.5}),t[2]=s):s=t[2];let i;t[3]===r?i=t[4]:(i=(0,a.jsx)(ae,{"data-testid":"copy-static-notebook-url-button",onClick:r,size:"xs",variant:"secondary",children:s}),t[3]=r,t[4]=i);let d;return t[5]!==n||t[6]!==i?(d=(0,a.jsx)(Yt,{content:"Copied!",open:n,children:i}),t[5]=n,t[6]=i,t[7]=d):d=t[7],d},xa=W();function wa(){let e=document.getElementsByClassName(fe.outputArea);for(let t of e){let n=t.getBoundingClientRect();if(n.bottom>0&&n.top<window.innerHeight){let o=te.findElement(t);if(!o){I.warn("Could not find HTMLCellId for visible output area",t);continue}return{cellId:te.parse(o.id)}}}return I.warn("No visible output area found for scroll anchor"),null}function ga(e){if(!e){I.warn("No scroll anchor provided to restore scroll position");return}let t=document.getElementById(te.create(e.cellId));if(!t){I.warn("Could not find cell element to restore scroll position",e.cellId);return}if(!t.querySelector(`.${fe.outputArea}`)){I.warn("Could not find output area to restore scroll position",e.cellId);return}t.scrollIntoView({block:"start",behavior:"auto"})}function Ee(){let e=(0,xa.c)(2),t=D(ze),n;return e[0]===t?n=e[1]:(n=()=>{let o=wa();t(l=>({mode:$t(l.mode),cellAnchor:(o==null?void 0:o.cellId)??null})),requestAnimationFrame(()=>{requestAnimationFrame(()=>{ga(o)})})},e[0]=t,e[1]=n),n}const Te=Be(!1);var ja=W();const va=()=>{let e=(0,ja.c)(7),{selectedLayout:t}=be(),{setLayoutView:n}=ke();if(ye()&&!he("wasm_layouts"))return null;let o;e[0]===n?o=e[1]:(o=i=>n(i),e[0]=n,e[1]=o);let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=(0,a.jsx)(Bt,{className:"min-w-[110px] border-border bg-background","data-testid":"layout-select",children:(0,a.jsx)(qt,{placeholder:"Select a view"})}),e[2]=l):l=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)(Vt,{children:(0,a.jsxs)(Ot,{children:[(0,a.jsx)(Lt,{children:"View as"}),We.map(za)]})}),e[3]=r):r=e[3];let s;return e[4]!==t||e[5]!==o?(s=(0,a.jsxs)(Ut,{"data-testid":"layout-select",value:t,onValueChange:o,children:[l,r]}),e[4]=t,e[5]=o,e[6]=s):s=e[6],s};function Ca(e){return(0,a.jsx)(He(e),{className:"h-4 w-4"})}function He(e){switch(e){case"vertical":return ma;case"grid":return Mt;case"slides":return De;default:return at(e),Et}}function Le(e){return me(e)}function za(e){return(0,a.jsx)(Rt,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5 leading-5",children:[Ca(e),(0,a.jsx)("span",{children:Le(e)})]})},e)}var Ma=W();function Wa(e){let t=(0,Ma.c)(5),{openPrompt:n,closeModal:o}=oe(),{sendCopy:l}=P(),r;return t[0]!==o||t[1]!==n||t[2]!==l||t[3]!==e?(r=()=>{if(!e)return null;let s=Tt.guessDeliminator(e);n({title:"Copy notebook",description:"Enter a new filename for the notebook copy.",defaultValue:`_${Ce.basename(e)}`,confirmText:"Copy notebook",spellCheck:!1,onConfirm:i=>{let d=s.join(Ce.dirname(e),i);l({source:e,destination:d}).then(()=>{o(),C({title:"Notebook copied",description:"A copy of the notebook has been created."}),ia(d)})}})},t[0]=o,t[1]=n,t[2]=l,t[3]=e,t[4]=r):r=t[4],r}const _a=()=>{let{updateCellConfig:e}=pe(),{saveCellConfig:t}=P();return(0,ne.useCallback)(async()=>{let n=new Xe,o=ce(),l=o.cellIds.inOrderIds,r={};for(let i of l){if(o.cellData[i]===void 0)continue;let{code:d,config:p}=o.cellData[i];p.hide_code||n.isSupported(d)&&(r[i]={hide_code:!0})}let s=ue.entries(r);if(s.length!==0){await t({configs:r});for(let[i,d]of s)e({cellId:i,config:d})}},[e])};var Sa=W();function qe(){let e=(0,Sa.c)(4),{openConfirm:t}=oe(),n=D(st),{sendRestart:o}=P(),l;return e[0]!==t||e[1]!==o||e[2]!==n?(l=()=>{t({title:"Restart Kernel",description:"This will restart the Python kernel. You'll lose all data that's in memory. You will also lose any unsaved changes, so make sure to save your work before restarting.",variant:"destructive",confirmAction:(0,a.jsx)(Gt,{onClick:async()=>{n({state:rt.CLOSING}),await o(),ea()},"aria-label":"Confirm Restart",children:"Restart"})})},e[0]=t,e[1]=o,e[2]=n,e[3]=l):l=e[3],l}var Aa=W(),E=e=>{e==null||e.preventDefault(),e==null||e.stopPropagation()};function Na(){var se,re;let e=(0,Aa.c)(40),t=oa(),{openModal:n,closeModal:o}=oe(),{toggleApplication:l}=et(),{selectedPanel:r}=Je(),[s]=Oe(ze),i=ee(Ft),d=_a(),[p]=lt(),{updateCellConfig:w,undoDeleteCell:g,clearAllCellOutputs:m,addSetupCellIfDoesntExist:u,collapseAllCells:f,expandAllCells:y}=pe(),b=qe(),k=aa(),j=Wa(t),v=D(Te),S=D(nt),z=D(it),{exportAsMarkdown:$,readCode:A,saveCellConfig:F,updateCellOutputs:G}=P(),K=ee(Ze),J=ee(tt),{selectedLayout:Z}=be(),{setLayoutView:X}=ke(),T=Ee(),Q=la(),H=((se=p.sharing)==null?void 0:se.html)??!0,L=((re=p.sharing)==null?void 0:re.wasm)??!0,q;e[0]===Symbol.for("react.memo_cache_sentinel")?(q=he("server_side_pdf_export"),e[0]=q):q=e[0];let le=q,R=le||s.mode==="present",Re=Ga,V;e[1]===Symbol.for("react.memo_cache_sentinel")?(V=(0,a.jsx)(wt,{size:14,strokeWidth:1.5}),e[1]=V):V=e[1];let O;e[2]===Symbol.for("react.memo_cache_sentinel")?(O=(0,a.jsx)(xe,{size:14,strokeWidth:1.5}),e[2]=O):O=e[2];let M;e[3]===t?M=e[4]:(M=async()=>{if(!t){ie();return}await we({filename:t,includeCode:!0})},e[3]=t,e[4]=M);let B;return e[5]!==u||e[6]!==J||e[7]!==m||e[8]!==o||e[9]!==f||e[10]!==j||e[11]!==y||e[12]!==$||e[13]!==t||e[14]!==K||e[15]!==d||e[16]!==i||e[17]!==n||e[18]!==R||e[19]!==A||e[20]!==b||e[21]!==k||e[22]!==F||e[23]!==Z||e[24]!==r||e[25]!==v||e[26]!==z||e[27]!==X||e[28]!==S||e[29]!==H||e[30]!==L||e[31]!==M||e[32]!==Q||e[33]!==l||e[34]!==T||e[35]!==g||e[36]!==w||e[37]!==G||e[38]!==s.mode?(B=[{icon:V,label:"Download",handle:E,dropdown:[{icon:O,label:"Download as HTML",handle:M},{icon:(0,a.jsx)(xe,{size:14,strokeWidth:1.5}),label:"Download as HTML (exclude code)",handle:async()=>{if(!t){ie();return}await we({filename:t,includeCode:!1})}},{icon:(0,a.jsx)(na,{strokeWidth:1.5,style:{width:14,height:14}}),label:"Download as Markdown",handle:async()=>{let c=await $({download:!1});ve(new Blob([c],{type:"text/plain"}),je.toMarkdown(document.title))}},{icon:(0,a.jsx)(pt,{size:14,strokeWidth:1.5}),label:"Download Python code",handle:async()=>{let c=await A();ve(new Blob([c.contents],{type:"text/plain"}),je.toPY(document.title))}},{divider:!0,icon:(0,a.jsx)(At,{size:14,strokeWidth:1.5}),label:"Download as PNG",disabled:s.mode!=="present",tooltip:s.mode==="present"?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",Me("global.hideCode",!1)]}),handle:Fa},{icon:(0,a.jsx)(vt,{size:14,strokeWidth:1.5}),label:"Download as PDF",disabled:!R,tooltip:R?void 0:(0,a.jsxs)("span",{children:["Only available in app view. ",(0,a.jsx)("br",{}),"Toggle with: ",Me("global.hideCode",!1)]}),handle:async()=>{if(le){if(!t){ie();return}await mt("Downloading PDF...",async N=>{await sa({takeScreenshots:()=>Q({progress:N}),updateCellOutputs:G}),await ut({filename:t,webpdf:!1})});return}let c=new Event("export-beforeprint"),x=new Event("export-afterprint");(function(){window.dispatchEvent(c),setTimeout($a,0),setTimeout(()=>window.dispatchEvent(x),0)})()}}]},{icon:(0,a.jsx)(fa,{size:14,strokeWidth:1.5}),label:"Share",handle:E,hidden:!H&&!L,dropdown:[{icon:(0,a.jsx)(_t,{size:14,strokeWidth:1.5}),label:"Publish HTML to web",hidden:!H,handle:async()=>{n((0,a.jsx)(ba,{onClose:o}))}},{icon:(0,a.jsx)(Nt,{size:14,strokeWidth:1.5}),label:"Create WebAssembly link",hidden:!L,handle:async()=>{await U(ta({code:(await A()).contents})),C({title:"Copied",description:"Link copied to clipboard."})}}]},{icon:(0,a.jsx)(ua,{size:14,strokeWidth:1.5}),label:"Helper panel",redundant:!0,handle:E,dropdown:Qe.flatMap(c=>{let{type:x,Icon:N,hidden:Ve}=c;return Ve?[]:{label:me(x),rightElement:Re(r===x),icon:(0,a.jsx)(N,{size:14,strokeWidth:1.5}),handle:()=>l(x)}})},{icon:(0,a.jsx)(De,{size:14,strokeWidth:1.5}),label:"Present as",handle:E,dropdown:[{icon:s.mode==="present"?(0,a.jsx)(Pt,{size:14,strokeWidth:1.5}):(0,a.jsx)(Ne,{size:14,strokeWidth:1.5}),label:"Toggle app view",hotkey:"global.hideCode",handle:()=>{T()}},...We.map((c,x)=>{let N=He(c);return{divider:x===0,label:Le(c),icon:(0,a.jsx)(N,{size:14,strokeWidth:1.5}),rightElement:(0,a.jsx)("div",{className:"w-8 flex justify-end",children:Z===c&&(0,a.jsx)(ge,{size:14})}),handle:()=>{X(c),s.mode==="edit"&&T()}}})]},{icon:(0,a.jsx)(ha,{size:14,strokeWidth:1.5}),label:"Duplicate notebook",hidden:!t||ye(),handle:j},{icon:(0,a.jsx)(_e,{size:14,strokeWidth:1.5}),label:"Copy code to clipboard",hidden:!t,handle:async()=>{await U((await A()).contents),C({title:"Copied",description:"Code copied to clipboard."})}},{icon:(0,a.jsx)(kt,{size:14,strokeWidth:1.5}),label:"Enable all cells",hidden:!K||i,handle:async()=>{let c=Ke(ce());await F({configs:ue.fromEntries(c.map(Ya))});for(let x of c)w({cellId:x,config:{disabled:!1}})}},{divider:!0,icon:(0,a.jsx)(Ae,{size:14,strokeWidth:1.5}),label:"Add setup cell",handle:()=>{u({})}},{icon:(0,a.jsx)($e,{size:14,strokeWidth:1.5}),label:"Add database connection",handle:()=>{n((0,a.jsx)(ot,{onClose:o}))}},{icon:(0,a.jsx)(Ie,{size:14,strokeWidth:1.5}),label:"Undo cell deletion",hidden:!J||i,handle:()=>{g()}},{icon:(0,a.jsx)(ya,{size:14,strokeWidth:1.5}),label:"Restart kernel",variant:"danger",handle:b},{icon:(0,a.jsx)(ca,{size:14,strokeWidth:1.5}),label:"Re-run all cells",redundant:!0,hotkey:"global.runAll",handle:async()=>{k()}},{icon:(0,a.jsx)(Ye,{size:14,strokeWidth:1.5}),label:"Clear all outputs",redundant:!0,handle:()=>{m()}},{icon:(0,a.jsx)(gt,{size:14,strokeWidth:1.5}),label:"Hide all markdown code",handle:d,redundant:!0},{icon:(0,a.jsx)(da,{size:14,strokeWidth:1.5}),label:"Collapse all sections",hotkey:"global.collapseAllSections",handle:f,redundant:!0},{icon:(0,a.jsx)(ra,{size:14,strokeWidth:1.5}),label:"Expand all sections",hotkey:"global.expandAllSections",handle:y,redundant:!0},{divider:!0,icon:(0,a.jsx)(Se,{size:14,strokeWidth:1.5}),label:"Command palette",hotkey:"global.commandPalette",handle:()=>v(Ua)},{icon:(0,a.jsx)(pa,{size:14,strokeWidth:1.5}),label:"Keyboard shortcuts",hotkey:"global.showHelp",handle:()=>z(Ba)},{icon:(0,a.jsx)(It,{size:14,strokeWidth:1.5}),label:"User settings",handle:()=>S(Oa),redundant:!0},{icon:(0,a.jsx)(bt,{size:14,strokeWidth:1.5}),label:"Resources",handle:E,dropdown:[{icon:(0,a.jsx)(Ge,{size:14,strokeWidth:1.5}),label:"Documentation",handle:Va},{icon:(0,a.jsx)(Ct,{size:14,strokeWidth:1.5}),label:"GitHub",handle:Ra},{icon:(0,a.jsx)(zt,{size:14,strokeWidth:1.5}),label:"Discord Community",handle:qa},{icon:(0,a.jsx)(Wt,{size:14,strokeWidth:1.5}),label:"YouTube",handle:La},{icon:(0,a.jsx)(Fe,{size:14,strokeWidth:1.5}),label:"Changelog",handle:Ha}]},{divider:!0,icon:(0,a.jsx)(St,{size:14,strokeWidth:1.5}),label:"Return home",hidden:!location.search.includes("file"),handle:Ta},{icon:(0,a.jsx)(jt,{size:14,strokeWidth:1.5}),label:"New notebook",hidden:!location.search.includes("file"),handle:Ea}].filter(Pa).map(Da),e[5]=u,e[6]=J,e[7]=m,e[8]=o,e[9]=f,e[10]=j,e[11]=y,e[12]=$,e[13]=t,e[14]=K,e[15]=d,e[16]=i,e[17]=n,e[18]=R,e[19]=A,e[20]=b,e[21]=k,e[22]=F,e[23]=Z,e[24]=r,e[25]=v,e[26]=z,e[27]=X,e[28]=S,e[29]=H,e[30]=L,e[31]=M,e[32]=Q,e[33]=l,e[34]=T,e[35]=g,e[36]=w,e[37]=G,e[38]=s.mode,e[39]=B):B=e[39],B}function Da(e){return e.dropdown?{...e,dropdown:e.dropdown.filter(Ia)}:e}function Ia(e){return!e.hidden}function Pa(e){return!e.hidden}function Ea(){let e=Ht();window.open(e,"_blank")}function Ta(){let e=document.baseURI.split("?")[0];window.open(e,"_self")}function Ha(){window.open(_.releasesPage,"_blank")}function La(){window.open(_.youtube,"_blank")}function qa(){window.open(_.discordLink,"_blank")}function Ra(){window.open(_.githubPage,"_blank")}function Va(){window.open(_.docsPage,"_blank")}function Oa(e){return!e}function Ba(e){return!e}function Ua(e){return!e}function Ya(e){return[e,{disabled:!1}]}function $a(){return window.print()}async function Fa(){let e=document.getElementById("App");e&&await ft({element:e,filename:document.title,prepare:yt})}function Ga(e){return(0,a.jsx)("div",{className:"w-8 flex justify-end",children:e&&(0,a.jsx)(ge,{size:14})})}function ie(){C({title:"Error",description:"Notebooks must be named to be exported.",variant:"danger"})}export{Ee as a,Ae as c,Te as i,Se as l,qe as n,Ie as o,va as r,Ne as s,Na as t,_e as u};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var it=Object.defineProperty;var ot=(t,e,n)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>ot(t,typeof e!="symbol"?e+"":e,n);var j;import{s as ce}from"./chunk-LvLJmgfZ.js";import{i as Q,l as D,o as lt,p as q,u as ut}from"./useEvent-BhXAndur.js";import{t as ct}from"./react-Bj1aDYRI.js";import{$r as dt,Hr as ft,Jr as mt,b as pt,ei as z,y as ht}from"./cells-DdLMh4kY.js";import{B as gt,C as de,D as yt,I as bt,N as wt,P as O,R as fe,k as W,w as me}from"./zod-H_cgTO0M.js";import{t as pe}from"./compiler-runtime-B3qBwwSJ.js";import{t as vt}from"./get-6uJrSKbw.js";import{t as xt}from"./assertNever-CBU83Y6o.js";import{t as Et}from"./debounce-B3mjKxHe.js";import{t as Ct}from"./_baseSet-5Rdwpmr3.js";import{d as E,p as y}from"./hotkeys-BHHWjLlp.js";import{t as _t}from"./invariant-CAG_dYON.js";import{S as kt}from"./utils-YqBXNpsM.js";import{S as Rt}from"./config-D2-Bw6QC.js";import{a as Ft}from"./switch-D-TxHKpg.js";import{n as he}from"./globals-BgJBhxFI.js";import{t as ge}from"./ErrorBoundary-B9Ifj8Jf.js";import{t as Nt}from"./jsx-runtime-ZmTK25f3.js";import{t as St}from"./button-CZ3Cs4qb.js";import{t as qt}from"./cn-BKtXLv3a.js";import{Z as Pt}from"./JsonOutput-DT5cq5VJ.js";import{t as Mt}from"./createReducer-B3rBsy4P.js";import{t as ye}from"./requests-B4FYHTZl.js";import{t as be}from"./createLucideIcon-BCdY6lG5.js";import{t as jt}from"./x-ZP5cObgf.js";import{a as It,l as At,r as Tt}from"./markdown-renderer-Dy-FX527.js";import{t as Lt}from"./DeferredRequestRegistry-tv0PqJZ0.js";import{t as J}from"./Deferred-CrO5-0RA.js";import{t as we}from"./uuid-DercMavo.js";import{t as Ut}from"./use-toast-T0_cQDma.js";import{t as ve}from"./tooltip-C_WgOOcZ.js";import{t as xe}from"./mode-BfhhQnCm.js";import{n as zt,r as Ot,t as Wt}from"./share-rXkgGlhr.js";import{r as Dt,t as Ht}from"./react-resizable-panels.browser.esm-Mq45xjWt.js";import{t as Ee}from"./toggle-CriARMQK.js";function Bt(t,e,n){return t==null?t:Ct(t,e,n)}var H=Bt,Vt=be("crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]),$t=be("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);function Xt(t){return{all:t||(t=new Map),on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(s){s(n)}),(r=t.get("*"))&&r.slice().map(function(s){s(e,n)})}}}var u=ce(ct(),1),K=(0,u.createContext)(null),Yt=t=>{let{controller:e}=(0,u.useContext)(K),n=u.useRef(Symbol("fill"));return(0,u.useEffect)(()=>(e.mount({name:t.name,ref:n.current,children:t.children}),()=>{e.unmount({name:t.name,ref:n.current})}),[]),(0,u.useEffect)(()=>{e.update({name:t.name,ref:n.current,children:t.children})}),null},Gt=Object.defineProperty,Qt=(t,e,n)=>e in t?Gt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ce=(t,e,n)=>(Qt(t,typeof e=="symbol"?e:e+"",n),n),_e=console,Jt=class{constructor(t){Ce(this,"_bus"),Ce(this,"_db"),this._bus=t,this.handleFillMount=this.handleFillMount.bind(this),this.handleFillUpdated=this.handleFillUpdated.bind(this),this.handleFillUnmount=this.handleFillUnmount.bind(this),this._db={byName:new Map,byFill:new Map}}mount(){this._bus.on("fill-mount",this.handleFillMount),this._bus.on("fill-updated",this.handleFillUpdated),this._bus.on("fill-unmount",this.handleFillUnmount)}unmount(){this._bus.off("fill-mount",this.handleFillMount),this._bus.off("fill-updated",this.handleFillUpdated),this._bus.off("fill-unmount",this.handleFillUnmount)}handleFillMount({fill:t}){let e=u.Children.toArray(t.children),n=t.name,r={fill:t,children:e,name:n},s=this._db.byName.get(n);s?(s.components.push(r),s.listeners.forEach(i=>i([...s.components]))):this._db.byName.set(n,{listeners:[],components:[r]}),this._db.byFill.set(t.ref,r)}handleFillUpdated({fill:t}){let e=this._db.byFill.get(t.ref),n=u.Children.toArray(t.children);if(e){e.children=n;let r=this._db.byName.get(e.name);if(r)r.listeners.forEach(s=>s([...r.components]));else throw Error("registration was expected to be defined")}else{_e.error("[handleFillUpdated] component was expected to be defined");return}}handleFillUnmount({fill:t}){let e=this._db.byFill.get(t.ref);if(!e){_e.error("[handleFillUnmount] component was expected to be defined");return}let n=e.name,r=this._db.byName.get(n);if(!r)throw Error("registration was expected to be defined");r.components=r.components.filter(s=>s!==e),this._db.byFill.delete(t.ref),r.listeners.length===0&&r.components.length===0?this._db.byName.delete(n):r.listeners.forEach(s=>s([...r.components]))}onComponentsChange(t,e){let n=this._db.byName.get(t);n?(n.listeners.push(e),e(n.components)):(this._db.byName.set(t,{listeners:[e],components:[]}),e([]))}getFillsByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.fill):[]}getChildrenByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.children).reduce((n,r)=>n.concat(r),[]):[]}removeOnComponentsChange(t,e){let n=this._db.byName.get(t);if(!n)throw Error("expected registration to be defined");let r=n.listeners;r.splice(r.indexOf(e),1)}},Kt=Object.defineProperty,Zt=(t,e,n)=>e in t?Kt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,en=(t,e,n)=>(Zt(t,typeof e=="symbol"?e:e+"",n),n),ke=class{constructor(){en(this,"bus",Xt())}mount(t){this.bus.emit("fill-mount",{fill:t})}unmount(t){this.bus.emit("fill-unmount",{fill:t})}update(t){this.bus.emit("fill-updated",{fill:t})}};function tn(t){let e=t||new ke;return{controller:e,manager:new Jt(e.bus)}}var nn=({controller:t,children:e})=>{let[n]=u.useState(()=>{let r=tn(t);return r.manager.mount(),r});return u.useEffect(()=>()=>{n.manager.unmount()},[]),u.createElement(K.Provider,{value:n},e)};function Z(t,e){let[n,r]=(0,u.useState)([]),{manager:s}=(0,u.useContext)(K);return(0,u.useEffect)(()=>(s.onComponentsChange(t,r),()=>{s.removeOnComponentsChange(t,r)}),[t]),n.flatMap((i,d)=>{let{children:l}=i;return l.map((p,b)=>{if(typeof p=="number"||typeof p=="string")throw Error("Only element children will work here");return u.cloneElement(p,{key:d.toString()+b.toString(),...e})})})}var Re=t=>{let e=Z(t.name,t.childProps);if(typeof t.children=="function"){let n=t.children(e);if(u.isValidElement(n)||n===null)return n;throw Error("Slot rendered with function must return a valid React Element.")}return e};const rn=q(null);var{valueAtom:sn,useActions:an}=Mt(()=>({banners:[]}),{addBanner:(t,e)=>({...t,banners:[...t.banners,{...e,id:we()}]}),removeBanner:(t,e)=>({...t,banners:t.banners.filter(n=>n.id!==e)}),clearBanners:t=>({...t,banners:[]})});const on=()=>ut(sn);function ln(){return an()}const un=new ke,B={SIDEBAR:"sidebar",CONTEXT_AWARE_PANEL:"context-aware-panel"};var cn=class{constructor(){a(this,"subscriptions",new Map)}addSubscription(t,e){var n;this.subscriptions.has(t)||this.subscriptions.set(t,new Set),(n=this.subscriptions.get(t))==null||n.add(e)}removeSubscription(t,e){var n;(n=this.subscriptions.get(t))==null||n.delete(e)}notify(t,e){for(let n of this.subscriptions.get(t)??[])n(e)}},Fe=class ue{constructor(e){a(this,"subscriptions",new cn);this.producer=e}static withProducerCallback(e){return new ue(e)}static empty(){return new ue}startProducer(){this.producer&&this.producer(e=>{this.subscriptions.notify("message",e)})}connect(){return new Promise(e=>setTimeout(e,0)).then(()=>{this.subscriptions.notify("open",new Event("open"))})}get readyState(){return WebSocket.OPEN}reconnect(e,n){this.close(),this.connect()}close(){this.subscriptions.notify("close",new Event("close"))}send(e){return this.subscriptions.notify("message",new MessageEvent("message",{data:e})),Promise.resolve()}addEventListener(e,n){this.subscriptions.addSubscription(e,n),e==="open"&&n(new Event("open")),e==="message"&&this.startProducer()}removeEventListener(e,n){this.subscriptions.removeSubscription(e,n)}},dn=1e10,fn=1e3;function V(t,e){let n=t.map(r=>`"${r}"`).join(", ");return Error(`This RPC instance cannot ${e} because the transport did not provide one or more of these methods: ${n}`)}function mn(t={}){let e={};function n(o){e=o}let r={};function s(o){var f;r.unregisterHandler&&r.unregisterHandler(),r=o,(f=r.registerHandler)==null||f.call(r,U)}let i;function d(o){if(typeof o=="function"){i=o;return}i=(f,g)=>{let c=o[f];if(c)return c(g);let h=o._;if(!h)throw Error(`The requested method has no handler: ${f}`);return h(f,g)}}let{maxRequestTime:l=fn}=t;t.transport&&s(t.transport),t.requestHandler&&d(t.requestHandler),t._debugHooks&&n(t._debugHooks);let p=0;function b(){return p<=dn?++p:p=0}let x=new Map,w=new Map;function C(o,...f){let g=f[0];return new Promise((c,h)=>{var A;if(!r.send)throw V(["send"],"make requests");let S=b(),M={type:"request",id:S,method:o,params:g};x.set(S,{resolve:c,reject:h}),l!==1/0&&w.set(S,setTimeout(()=>{w.delete(S),h(Error("RPC request timed out."))},l)),(A=e.onSend)==null||A.call(e,M),r.send(M)})}let F=new Proxy(C,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>C(f,c)}),_=F;function k(o,...f){var h;let g=f[0];if(!r.send)throw V(["send"],"send messages");let c={type:"message",id:o,payload:g};(h=e.onSend)==null||h.call(e,c),r.send(c)}let R=new Proxy(k,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>k(f,c)}),v=R,N=new Map,P=new Set;function I(o,f){var g;if(!r.registerHandler)throw V(["registerHandler"],"register message listeners");if(o==="*"){P.add(f);return}N.has(o)||N.set(o,new Set),(g=N.get(o))==null||g.add(f)}function L(o,f){var g,c;if(o==="*"){P.delete(f);return}(g=N.get(o))==null||g.delete(f),((c=N.get(o))==null?void 0:c.size)===0&&N.delete(o)}async function U(o){var f,g;if((f=e.onReceive)==null||f.call(e,o),!("type"in o))throw Error("Message does not contain a type.");if(o.type==="request"){if(!r.send||!i)throw V(["send","requestHandler"],"handle requests");let{id:c,method:h,params:S}=o,M;try{M={type:"response",id:c,success:!0,payload:await i(h,S)}}catch(A){if(!(A instanceof Error))throw A;M={type:"response",id:c,success:!1,error:A.message}}(g=e.onSend)==null||g.call(e,M),r.send(M);return}if(o.type==="response"){let c=w.get(o.id);c!=null&&clearTimeout(c);let{resolve:h,reject:S}=x.get(o.id)??{};o.success?h==null||h(o.payload):S==null||S(Error(o.error));return}if(o.type==="message"){for(let h of P)h(o.id,o.payload);let c=N.get(o.id);if(!c)return;for(let h of c)h(o.payload);return}throw Error(`Unexpected RPC message type: ${o.type}`)}return{setTransport:s,setRequestHandler:d,request:F,requestProxy:_,send:R,sendProxy:v,addMessageListener:I,removeMessageListener:L,proxy:{send:v,request:_},_setDebugHooks:n}}function pn(t){return mn(t)}var Ne="[transport-id]";function hn(t,e){let{transportId:n}=e;return n==null?t:{[Ne]:n,data:t}}function gn(t,e){let{transportId:n,filter:r}=e,s=r==null?void 0:r();if(n!=null&&s!=null)throw Error("Cannot use both `transportId` and `filter` at the same time");let i=t;if(n){if(t[Ne]!==n)return[!0];i=t.data}return s===!1?[!0]:[!1,i]}function yn(t,e={}){let{transportId:n,filter:r,remotePort:s}=e,i=t,d=s??t,l;return{send(p){d.postMessage(hn(p,{transportId:n}))},registerHandler(p){l=b=>{let x=b.data,[w,C]=gn(x,{transportId:n,filter:()=>r==null?void 0:r(b)});w||p(C)},i.addEventListener("message",l)},unregisterHandler(){l&&i.removeEventListener("message",l)}}}function bn(t,e){return yn(t,e)}function Se(t){return pn({transport:bn(t,{transportId:"marimo-transport"}),maxRequestTime:2e4,_debugHooks:{onSend:e=>{E.debug("[rpc] Parent -> Worker",e)},onReceive:e=>{E.debug("[rpc] Worker -> Parent",e)}}})}const qe=q("Initializing..."),wn=q(t=>{let e=t(ht),n=Object.values(e.cellRuntime);return n.some(r=>!At(r.output))?!0:n.every(r=>r.status==="idle")});var Pe=zt(),Me="marimo:file",je=new ft(null);const vn={saveFile(t){je.set(Me,t)},readFile(){return je.get(Me)}};var xn={saveFile(t){z.setCodeForHash((0,Pe.compressToEncodedURIComponent)(t))},readFile(){let t=z.getCodeFromHash()||z.getCodeFromSearchParam();return t?(0,Pe.decompressFromEncodedURIComponent)(t):null}};const En={saveFile(t){},readFile(){let t=document.querySelector("marimo-code");return t?decodeURIComponent(t.textContent||"").trim():null}};var Cn={saveFile(t){},readFile(){if(window.location.hostname!=="marimo.app")return null;let t=new URL("files/wasm-intro.py",document.baseURI);return fetch(t.toString()).then(e=>e.ok?e.text():null).catch(()=>null)}},_n={saveFile(t){},readFile(){return["import marimo","app = marimo.App()","","@app.cell","def __():"," return","",'if __name__ == "__main__":'," app.run()"].join(`
|
|
1
|
+
var it=Object.defineProperty;var ot=(t,e,n)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>ot(t,typeof e!="symbol"?e+"":e,n);var j;import{s as ce}from"./chunk-LvLJmgfZ.js";import{i as Q,l as D,o as lt,p as q,u as ut}from"./useEvent-BhXAndur.js";import{t as ct}from"./react-Bj1aDYRI.js";import{$r as dt,Hr as ft,Jr as mt,b as pt,ei as z,y as ht}from"./cells-DdLMh4kY.js";import{B as gt,C as de,D as yt,I as bt,N as wt,P as O,R as fe,k as W,w as me}from"./zod-H_cgTO0M.js";import{t as pe}from"./compiler-runtime-B3qBwwSJ.js";import{t as vt}from"./get-6uJrSKbw.js";import{t as xt}from"./assertNever-CBU83Y6o.js";import{t as Et}from"./debounce-B3mjKxHe.js";import{t as Ct}from"./_baseSet-5Rdwpmr3.js";import{d as E,p as y}from"./hotkeys-BHHWjLlp.js";import{t as _t}from"./invariant-CAG_dYON.js";import{S as kt}from"./utils-YqBXNpsM.js";import{S as Rt}from"./config-D2-Bw6QC.js";import{a as Ft}from"./switch-D-TxHKpg.js";import{n as he}from"./globals-BgJBhxFI.js";import{t as ge}from"./ErrorBoundary-B9Ifj8Jf.js";import{t as Nt}from"./jsx-runtime-ZmTK25f3.js";import{t as St}from"./button-CZ3Cs4qb.js";import{t as qt}from"./cn-BKtXLv3a.js";import{Z as Pt}from"./JsonOutput-BTXiwFjF.js";import{t as Mt}from"./createReducer-B3rBsy4P.js";import{t as ye}from"./requests-B4FYHTZl.js";import{t as be}from"./createLucideIcon-BCdY6lG5.js";import{t as jt}from"./x-ZP5cObgf.js";import{a as It,l as At,r as Tt}from"./markdown-renderer-Dy-FX527.js";import{t as Lt}from"./DeferredRequestRegistry-tv0PqJZ0.js";import{t as J}from"./Deferred-CrO5-0RA.js";import{t as we}from"./uuid-DercMavo.js";import{t as Ut}from"./use-toast-T0_cQDma.js";import{t as ve}from"./tooltip-C_WgOOcZ.js";import{t as xe}from"./mode-BfhhQnCm.js";import{n as zt,r as Ot,t as Wt}from"./share-rXkgGlhr.js";import{r as Dt,t as Ht}from"./react-resizable-panels.browser.esm-Mq45xjWt.js";import{t as Ee}from"./toggle-CriARMQK.js";function Bt(t,e,n){return t==null?t:Ct(t,e,n)}var H=Bt,Vt=be("crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]),$t=be("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);function Xt(t){return{all:t||(t=new Map),on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(s){s(n)}),(r=t.get("*"))&&r.slice().map(function(s){s(e,n)})}}}var u=ce(ct(),1),K=(0,u.createContext)(null),Yt=t=>{let{controller:e}=(0,u.useContext)(K),n=u.useRef(Symbol("fill"));return(0,u.useEffect)(()=>(e.mount({name:t.name,ref:n.current,children:t.children}),()=>{e.unmount({name:t.name,ref:n.current})}),[]),(0,u.useEffect)(()=>{e.update({name:t.name,ref:n.current,children:t.children})}),null},Gt=Object.defineProperty,Qt=(t,e,n)=>e in t?Gt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ce=(t,e,n)=>(Qt(t,typeof e=="symbol"?e:e+"",n),n),_e=console,Jt=class{constructor(t){Ce(this,"_bus"),Ce(this,"_db"),this._bus=t,this.handleFillMount=this.handleFillMount.bind(this),this.handleFillUpdated=this.handleFillUpdated.bind(this),this.handleFillUnmount=this.handleFillUnmount.bind(this),this._db={byName:new Map,byFill:new Map}}mount(){this._bus.on("fill-mount",this.handleFillMount),this._bus.on("fill-updated",this.handleFillUpdated),this._bus.on("fill-unmount",this.handleFillUnmount)}unmount(){this._bus.off("fill-mount",this.handleFillMount),this._bus.off("fill-updated",this.handleFillUpdated),this._bus.off("fill-unmount",this.handleFillUnmount)}handleFillMount({fill:t}){let e=u.Children.toArray(t.children),n=t.name,r={fill:t,children:e,name:n},s=this._db.byName.get(n);s?(s.components.push(r),s.listeners.forEach(i=>i([...s.components]))):this._db.byName.set(n,{listeners:[],components:[r]}),this._db.byFill.set(t.ref,r)}handleFillUpdated({fill:t}){let e=this._db.byFill.get(t.ref),n=u.Children.toArray(t.children);if(e){e.children=n;let r=this._db.byName.get(e.name);if(r)r.listeners.forEach(s=>s([...r.components]));else throw Error("registration was expected to be defined")}else{_e.error("[handleFillUpdated] component was expected to be defined");return}}handleFillUnmount({fill:t}){let e=this._db.byFill.get(t.ref);if(!e){_e.error("[handleFillUnmount] component was expected to be defined");return}let n=e.name,r=this._db.byName.get(n);if(!r)throw Error("registration was expected to be defined");r.components=r.components.filter(s=>s!==e),this._db.byFill.delete(t.ref),r.listeners.length===0&&r.components.length===0?this._db.byName.delete(n):r.listeners.forEach(s=>s([...r.components]))}onComponentsChange(t,e){let n=this._db.byName.get(t);n?(n.listeners.push(e),e(n.components)):(this._db.byName.set(t,{listeners:[e],components:[]}),e([]))}getFillsByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.fill):[]}getChildrenByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.children).reduce((n,r)=>n.concat(r),[]):[]}removeOnComponentsChange(t,e){let n=this._db.byName.get(t);if(!n)throw Error("expected registration to be defined");let r=n.listeners;r.splice(r.indexOf(e),1)}},Kt=Object.defineProperty,Zt=(t,e,n)=>e in t?Kt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,en=(t,e,n)=>(Zt(t,typeof e=="symbol"?e:e+"",n),n),ke=class{constructor(){en(this,"bus",Xt())}mount(t){this.bus.emit("fill-mount",{fill:t})}unmount(t){this.bus.emit("fill-unmount",{fill:t})}update(t){this.bus.emit("fill-updated",{fill:t})}};function tn(t){let e=t||new ke;return{controller:e,manager:new Jt(e.bus)}}var nn=({controller:t,children:e})=>{let[n]=u.useState(()=>{let r=tn(t);return r.manager.mount(),r});return u.useEffect(()=>()=>{n.manager.unmount()},[]),u.createElement(K.Provider,{value:n},e)};function Z(t,e){let[n,r]=(0,u.useState)([]),{manager:s}=(0,u.useContext)(K);return(0,u.useEffect)(()=>(s.onComponentsChange(t,r),()=>{s.removeOnComponentsChange(t,r)}),[t]),n.flatMap((i,d)=>{let{children:l}=i;return l.map((p,b)=>{if(typeof p=="number"||typeof p=="string")throw Error("Only element children will work here");return u.cloneElement(p,{key:d.toString()+b.toString(),...e})})})}var Re=t=>{let e=Z(t.name,t.childProps);if(typeof t.children=="function"){let n=t.children(e);if(u.isValidElement(n)||n===null)return n;throw Error("Slot rendered with function must return a valid React Element.")}return e};const rn=q(null);var{valueAtom:sn,useActions:an}=Mt(()=>({banners:[]}),{addBanner:(t,e)=>({...t,banners:[...t.banners,{...e,id:we()}]}),removeBanner:(t,e)=>({...t,banners:t.banners.filter(n=>n.id!==e)}),clearBanners:t=>({...t,banners:[]})});const on=()=>ut(sn);function ln(){return an()}const un=new ke,B={SIDEBAR:"sidebar",CONTEXT_AWARE_PANEL:"context-aware-panel"};var cn=class{constructor(){a(this,"subscriptions",new Map)}addSubscription(t,e){var n;this.subscriptions.has(t)||this.subscriptions.set(t,new Set),(n=this.subscriptions.get(t))==null||n.add(e)}removeSubscription(t,e){var n;(n=this.subscriptions.get(t))==null||n.delete(e)}notify(t,e){for(let n of this.subscriptions.get(t)??[])n(e)}},Fe=class ue{constructor(e){a(this,"subscriptions",new cn);this.producer=e}static withProducerCallback(e){return new ue(e)}static empty(){return new ue}startProducer(){this.producer&&this.producer(e=>{this.subscriptions.notify("message",e)})}connect(){return new Promise(e=>setTimeout(e,0)).then(()=>{this.subscriptions.notify("open",new Event("open"))})}get readyState(){return WebSocket.OPEN}reconnect(e,n){this.close(),this.connect()}close(){this.subscriptions.notify("close",new Event("close"))}send(e){return this.subscriptions.notify("message",new MessageEvent("message",{data:e})),Promise.resolve()}addEventListener(e,n){this.subscriptions.addSubscription(e,n),e==="open"&&n(new Event("open")),e==="message"&&this.startProducer()}removeEventListener(e,n){this.subscriptions.removeSubscription(e,n)}},dn=1e10,fn=1e3;function V(t,e){let n=t.map(r=>`"${r}"`).join(", ");return Error(`This RPC instance cannot ${e} because the transport did not provide one or more of these methods: ${n}`)}function mn(t={}){let e={};function n(o){e=o}let r={};function s(o){var f;r.unregisterHandler&&r.unregisterHandler(),r=o,(f=r.registerHandler)==null||f.call(r,U)}let i;function d(o){if(typeof o=="function"){i=o;return}i=(f,g)=>{let c=o[f];if(c)return c(g);let h=o._;if(!h)throw Error(`The requested method has no handler: ${f}`);return h(f,g)}}let{maxRequestTime:l=fn}=t;t.transport&&s(t.transport),t.requestHandler&&d(t.requestHandler),t._debugHooks&&n(t._debugHooks);let p=0;function b(){return p<=dn?++p:p=0}let x=new Map,w=new Map;function C(o,...f){let g=f[0];return new Promise((c,h)=>{var A;if(!r.send)throw V(["send"],"make requests");let S=b(),M={type:"request",id:S,method:o,params:g};x.set(S,{resolve:c,reject:h}),l!==1/0&&w.set(S,setTimeout(()=>{w.delete(S),h(Error("RPC request timed out."))},l)),(A=e.onSend)==null||A.call(e,M),r.send(M)})}let F=new Proxy(C,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>C(f,c)}),_=F;function k(o,...f){var h;let g=f[0];if(!r.send)throw V(["send"],"send messages");let c={type:"message",id:o,payload:g};(h=e.onSend)==null||h.call(e,c),r.send(c)}let R=new Proxy(k,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>k(f,c)}),v=R,N=new Map,P=new Set;function I(o,f){var g;if(!r.registerHandler)throw V(["registerHandler"],"register message listeners");if(o==="*"){P.add(f);return}N.has(o)||N.set(o,new Set),(g=N.get(o))==null||g.add(f)}function L(o,f){var g,c;if(o==="*"){P.delete(f);return}(g=N.get(o))==null||g.delete(f),((c=N.get(o))==null?void 0:c.size)===0&&N.delete(o)}async function U(o){var f,g;if((f=e.onReceive)==null||f.call(e,o),!("type"in o))throw Error("Message does not contain a type.");if(o.type==="request"){if(!r.send||!i)throw V(["send","requestHandler"],"handle requests");let{id:c,method:h,params:S}=o,M;try{M={type:"response",id:c,success:!0,payload:await i(h,S)}}catch(A){if(!(A instanceof Error))throw A;M={type:"response",id:c,success:!1,error:A.message}}(g=e.onSend)==null||g.call(e,M),r.send(M);return}if(o.type==="response"){let c=w.get(o.id);c!=null&&clearTimeout(c);let{resolve:h,reject:S}=x.get(o.id)??{};o.success?h==null||h(o.payload):S==null||S(Error(o.error));return}if(o.type==="message"){for(let h of P)h(o.id,o.payload);let c=N.get(o.id);if(!c)return;for(let h of c)h(o.payload);return}throw Error(`Unexpected RPC message type: ${o.type}`)}return{setTransport:s,setRequestHandler:d,request:F,requestProxy:_,send:R,sendProxy:v,addMessageListener:I,removeMessageListener:L,proxy:{send:v,request:_},_setDebugHooks:n}}function pn(t){return mn(t)}var Ne="[transport-id]";function hn(t,e){let{transportId:n}=e;return n==null?t:{[Ne]:n,data:t}}function gn(t,e){let{transportId:n,filter:r}=e,s=r==null?void 0:r();if(n!=null&&s!=null)throw Error("Cannot use both `transportId` and `filter` at the same time");let i=t;if(n){if(t[Ne]!==n)return[!0];i=t.data}return s===!1?[!0]:[!1,i]}function yn(t,e={}){let{transportId:n,filter:r,remotePort:s}=e,i=t,d=s??t,l;return{send(p){d.postMessage(hn(p,{transportId:n}))},registerHandler(p){l=b=>{let x=b.data,[w,C]=gn(x,{transportId:n,filter:()=>r==null?void 0:r(b)});w||p(C)},i.addEventListener("message",l)},unregisterHandler(){l&&i.removeEventListener("message",l)}}}function bn(t,e){return yn(t,e)}function Se(t){return pn({transport:bn(t,{transportId:"marimo-transport"}),maxRequestTime:2e4,_debugHooks:{onSend:e=>{E.debug("[rpc] Parent -> Worker",e)},onReceive:e=>{E.debug("[rpc] Worker -> Parent",e)}}})}const qe=q("Initializing..."),wn=q(t=>{let e=t(ht),n=Object.values(e.cellRuntime);return n.some(r=>!At(r.output))?!0:n.every(r=>r.status==="idle")});var Pe=zt(),Me="marimo:file",je=new ft(null);const vn={saveFile(t){je.set(Me,t)},readFile(){return je.get(Me)}};var xn={saveFile(t){z.setCodeForHash((0,Pe.compressToEncodedURIComponent)(t))},readFile(){let t=z.getCodeFromHash()||z.getCodeFromSearchParam();return t?(0,Pe.decompressFromEncodedURIComponent)(t):null}};const En={saveFile(t){},readFile(){let t=document.querySelector("marimo-code");return t?decodeURIComponent(t.textContent||"").trim():null}};var Cn={saveFile(t){},readFile(){if(window.location.hostname!=="marimo.app")return null;let t=new URL("files/wasm-intro.py",document.baseURI);return fetch(t.toString()).then(e=>e.ok?e.text():null).catch(()=>null)}},_n={saveFile(t){},readFile(){return["import marimo","app = marimo.App()","","@app.cell","def __():"," return","",'if __name__ == "__main__":'," app.run()"].join(`
|
|
2
2
|
`)}},Ie=class{constructor(t){this.stores=t}insert(t,e){this.stores.splice(t,0,e)}saveFile(t){this.stores.forEach(e=>e.saveFile(t))}readFile(){for(let t of this.stores){let e=t.readFile();if(e)return e}return null}};const $=new Ie([En,xn]),ee=new Ie([vn,Cn,_n]);var Ae=class st{constructor(){a(this,"initialized",new J);a(this,"sendRename",async({filename:e})=>(e===null||(z.setFilename(e),await this.rpc.proxy.request.bridge({functionName:"rename_file",payload:e})),null));a(this,"sendSave",async e=>{if(!this.saveRpc)return E.warn("Save RPC not initialized"),null;await this.saveRpc.saveNotebook(e);let n=await this.readCode();return n.contents&&($.saveFile(n.contents),ee.saveFile(n.contents)),this.rpc.proxy.request.saveNotebook(e).catch(r=>{E.error(r)}),null});a(this,"sendCopy",async()=>{y()});a(this,"sendStdin",async e=>(await this.rpc.proxy.request.bridge({functionName:"put_input",payload:e.text}),null));a(this,"sendPdb",async()=>{y()});a(this,"sendRun",async e=>(await this.rpc.proxy.request.loadPackages(e.codes.join(`
|
|
3
3
|
`)),await this.putControlRequest({type:"execute-cells",...e}),null));a(this,"sendRunScratchpad",async e=>(await this.rpc.proxy.request.loadPackages(e.code),await this.putControlRequest({type:"execute-scratchpad",...e}),null));a(this,"sendInterrupt",async()=>(this.interruptBuffer!==void 0&&(this.interruptBuffer[0]=2),null));a(this,"sendShutdown",async()=>(window.close(),null));a(this,"sendFormat",async e=>await this.rpc.proxy.request.bridge({functionName:"format",payload:e}));a(this,"sendDeleteCell",async e=>(await this.putControlRequest({type:"delete-cell",...e}),null));a(this,"sendInstallMissingPackages",async e=>(this.putControlRequest({type:"install-packages",...e}),null));a(this,"sendCodeCompletionRequest",async e=>(Q.get(pt)||await this.rpc.proxy.request.bridge({functionName:"code_complete",payload:e}),null));a(this,"saveUserConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_user_config",payload:e}),Ft.post("/kernel/save_user_config",e,{baseUrl:"/"}).catch(n=>(E.error(n),null))));a(this,"saveAppConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_app_config",payload:e}),null));a(this,"saveCellConfig",async e=>(await this.putControlRequest({type:"update-cell-config",...e}),null));a(this,"sendRestart",async()=>{let e=await this.readCode();return e.contents&&($.saveFile(e.contents),ee.saveFile(e.contents)),Ot(),null});a(this,"readCode",async()=>this.saveRpc?{contents:await this.saveRpc.readNotebook()}:(E.warn("Save RPC not initialized"),{contents:""}));a(this,"readSnippets",async()=>await this.rpc.proxy.request.bridge({functionName:"read_snippets",payload:void 0}));a(this,"openFile",async({path:e})=>{let n=Wt({code:null,baseUrl:window.location.origin});return window.open(n,"_blank"),null});a(this,"sendListFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"list_files",payload:e}));a(this,"sendSearchFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"search_files",payload:e}));a(this,"sendComponentValues",async e=>(await this.putControlRequest({type:"update-ui-element",...e,token:we()}),null));a(this,"sendInstantiate",async e=>null);a(this,"sendFunctionRequest",async e=>(await this.putControlRequest({type:"invoke-function",...e}),null));a(this,"sendCreateFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"create_file_or_directory",payload:e}));a(this,"sendDeleteFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"delete_file_or_directory",payload:e}));a(this,"sendRenameFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"move_file_or_directory",payload:e}));a(this,"sendUpdateFile",async e=>await this.rpc.proxy.request.bridge({functionName:"update_file",payload:e}));a(this,"sendFileDetails",async e=>await this.rpc.proxy.request.bridge({functionName:"file_details",payload:e}));a(this,"exportAsHTML",async e=>await this.rpc.proxy.request.bridge({functionName:"export_html",payload:e}));a(this,"exportAsMarkdown",async e=>await this.rpc.proxy.request.bridge({functionName:"export_markdown",payload:e}));a(this,"previewDatasetColumn",async e=>(await this.putControlRequest({type:"preview-dataset-column",...e}),null));a(this,"previewSQLTable",async e=>(await this.putControlRequest({type:"preview-sql-table",...e}),null));a(this,"previewSQLTableList",async e=>(await this.putControlRequest({type:"list-sql-tables",...e}),null));a(this,"previewDataSourceConnection",async e=>(await this.putControlRequest({type:"list-data-source-connection",...e}),null));a(this,"validateSQL",async e=>(await this.putControlRequest({type:"validate-sql",...e}),null));a(this,"sendModelValue",async e=>(await this.putControlRequest({type:"update-widget-model",...e}),null));a(this,"syncCellIds",()=>Promise.resolve(null));a(this,"addPackage",async e=>this.rpc.proxy.request.addPackage(e));a(this,"removePackage",async e=>this.rpc.proxy.request.removePackage(e));a(this,"getPackageList",async()=>await this.rpc.proxy.request.listPackages());a(this,"getDependencyTree",async()=>({tree:{dependencies:[],name:"",tags:[],version:null}}));a(this,"listSecretKeys",async e=>(await this.putControlRequest({type:"list-secret-keys",...e}),null));a(this,"getUsageStats",y);a(this,"openTutorial",y);a(this,"getRecentFiles",y);a(this,"getWorkspaceFiles",y);a(this,"getRunningNotebooks",y);a(this,"shutdownSession",y);a(this,"exportAsPDF",y);a(this,"autoExportAsHTML",y);a(this,"autoExportAsMarkdown",y);a(this,"autoExportAsIPYNB",y);a(this,"updateCellOutputs",y);a(this,"writeSecret",y);a(this,"invokeAiTool",y);a(this,"clearCache",y);a(this,"getCacheInfo",y);Rt()&&(this.rpc=Se(new Worker(new URL(""+new URL("worker-CyCdlLVf.js",import.meta.url).href,""+import.meta.url),{type:"module",name:he()})),this.rpc.addMessageListener("ready",()=>{this.startSession()}),this.rpc.addMessageListener("initialized",()=>{this.saveRpc=this.getSaveWorker(),this.setInterruptBuffer(),this.initialized.resolve()}),this.rpc.addMessageListener("initializingMessage",({message:e})=>{Q.set(qe,e)}),this.rpc.addMessageListener("initializedError",({error:e})=>{this.initialized.status==="resolved"&&(E.error(e),Ut({title:"Error initializing",description:e,variant:"danger"})),this.initialized.reject(Error(e))}),this.rpc.addMessageListener("kernelMessage",({message:e})=>{var n;(n=this.messageConsumer)==null||n.call(this,new MessageEvent("message",{data:e}))}))}static get INSTANCE(){let e="_marimo_private_PyodideBridge";return window[e]||(window[e]=new st),window[e]}getSaveWorker(){return xe()==="read"?(E.debug("Skipping SaveWorker in read-mode"),{readFile:y,readNotebook:y,saveNotebook:y}):Se(new Worker(new URL(""+new URL("save-worker-CtJsIYIM.js",import.meta.url).href,""+import.meta.url),{type:"module",name:he()})).proxy.request}async startSession(){let e=await $.readFile(),n=await ee.readFile(),r=z.getFilename(),s=Q.get(kt),i={},d=new URLSearchParams(window.location.search);for(let l of d.keys()){let p=d.getAll(l);i[l]=p.length===1?p[0]:p}await this.rpc.proxy.request.startSession({queryParameters:i,code:e||n||"",filename:r,userConfig:{...s,runtime:{...s.runtime,auto_instantiate:xe()==="read"?!0:s.runtime.auto_instantiate}}})}setInterruptBuffer(){crossOriginIsolated?(this.interruptBuffer=new Uint8Array(new SharedArrayBuffer(1)),this.rpc.proxy.request.setInterruptBuffer(this.interruptBuffer)):E.warn("Not running in a secure context; interrupts are not available.")}attachMessageConsumer(e){this.messageConsumer=e,this.rpc.proxy.send.consumerReady({})}async putControlRequest(e){await this.rpc.proxy.request.bridge({functionName:"put_control_request",payload:e})}};function kn(){return Fe.withProducerCallback(t=>{Ae.INSTANCE.attachMessageConsumer(t)})}const Te=q({isInstantiated:!1,error:null});function Rn(){return lt(Te,t=>t.isInstantiated)}function X(t){return()=>({TYPE:t,is(e){return e.type===t},create(e){return new CustomEvent(t,e)}})}const Le=X("marimo-value-input")(),Ue=X("marimo-value-update")(),ze=X("marimo-value-ready")(),Oe=X("marimo-incoming-message")();function Fn(t,e){return Le.create({bubbles:!0,composed:!0,detail:{value:t,element:e}})}var We=class at{static get INSTANCE(){let e="_marimo_private_UIElementRegistry";return window[e]||(window[e]=new at),window[e]}constructor(){this.entries=new Map}has(e){return this.entries.has(e)}set(e,n){if(this.entries.has(e))throw Error(`UIElement ${e} already registered`);this.entries.set(e,{objectId:e,value:n,elements:new Set})}registerInstance(e,n){let r=this.entries.get(e);r===void 0?this.entries.set(e,{objectId:e,value:dt(n,this),elements:new Set([n])}):r.elements.add(n)}removeInstance(e,n){let r=this.entries.get(e);r!=null&&r.elements.has(n)&&r.elements.delete(n)}removeElementsByCell(e){[...this.entries.keys()].filter(n=>n.startsWith(`${e}-`)).forEach(n=>{this.entries.delete(n)})}lookupValue(e){let n=this.entries.get(e);return n===void 0?void 0:n.value}broadcastMessage(e,n,r){let s=this.entries.get(e);s===void 0?E.warn("UIElementRegistry missing entry",e):s.elements.forEach(i=>{i.dispatchEvent(Oe.create({bubbles:!1,composed:!0,detail:{objectId:e,message:n,buffers:r}}))})}broadcastValueUpdate(e,n,r){let s=this.entries.get(n);s===void 0?E.warn("UIElementRegistry missing entry",n):(s.value=r,s.elements.forEach(i=>{i!==e&&i.dispatchEvent(Ue.create({bubbles:!1,composed:!0,detail:{value:r,element:i}}))}),document.dispatchEvent(ze.create({bubbles:!0,composed:!0,detail:{objectId:n}})))}};const Nn=We.INSTANCE,Sn=new Lt("function-call-result",async(t,e)=>{await ye().sendFunctionRequest({functionCallId:t,...e})}),qn="68px";var Pn="288px";const Mn=t=>t?/^\d+$/.test(t)?`${t}px`:t:Pn,jn=mt({isOpen:!0},(t,e)=>{if(!e)return t;switch(e.type){case"toggle":return{...t,isOpen:e.isOpen??t.isOpen};case"setWidth":return{...t,width:e.width};default:return t}});function te(t,e=[]){let n=[];if(t instanceof DataView)n.push(e);else if(Array.isArray(t))for(let[r,s]of t.entries())n.push(...te(s,[...e,r]));else if(typeof t=="object"&&t)for(let[r,s]of Object.entries(t))n.push(...te(s,[...e,r]));return n}function ne(t){let e=te(t);if(e.length===0)return{state:t,buffers:[],bufferPaths:[]};let n=structuredClone(t),r=[],s=[];for(let i of e){let d=vt(t,i);if(d instanceof DataView){let l=It(d);r.push(l),s.push(i),H(n,i,l)}}return{state:n,buffers:r,bufferPaths:s}}function In(t){return typeof t=="object"&&!!t&&"state"in t&&"bufferPaths"in t&&"buffers"in t}function Y(t){let{state:e,bufferPaths:n,buffers:r}=t;if(!n||n.length===0)return e;r&&_t(r.length===n.length,"Buffers and buffer paths not the same length");let s=structuredClone(e);for(let[i,d]of n.entries()){let l=r==null?void 0:r[i];if(l==null){E.warn("[anywidget] Could not find buffer at path",d);continue}typeof l=="string"?H(s,d,Tt(l)):H(s,d,l)}return s}const De=new class{constructor(t=1e4){a(this,"models",new Map);this.timeout=t}get(t){let e=this.models.get(t);return e||(e=new J,this.models.set(t,e),setTimeout(()=>{e.status==="pending"&&(e.reject(Error(`Model not found for key: ${t}`)),this.models.delete(t))},this.timeout)),e.promise}set(t,e){let n=this.models.get(t);n||(n=new J,this.models.set(t,n)),n.resolve(e)}delete(t){this.models.delete(t)}};var He=(j=class{constructor(e,n,r,s){a(this,"ANY_CHANGE_EVENT","change");a(this,"listeners",{});a(this,"widget_manager",{async get_model(e){let n=await j._modelManager.get(e);if(!n)throw Error(`Model not found with id: ${e}. This is likely because the model was not registered.`);return n}});a(this,"emitAnyChange",Et(()=>{var e;(e=this.listeners[this.ANY_CHANGE_EVENT])==null||e.forEach(n=>n())},0));this.data=e,this.onChange=n,this.sendToWidget=r,this.dirtyFields=new Map([...s].map(i=>[i,this.data[i]]))}off(e,n){var r;if(!e){this.listeners={};return}if(!n){this.listeners[e]=new Set;return}(r=this.listeners[e])==null||r.delete(n)}send(e,n,r){let{state:s,bufferPaths:i,buffers:d}=ne(e);this.sendToWidget({content:{state:s,bufferPaths:i},buffers:d}).then(n)}get(e){return this.data[e]}set(e,n){this.data={...this.data,[e]:n},this.dirtyFields.set(e,n),this.emit(`change:${e}`,n),this.emitAnyChange()}save_changes(){if(this.dirtyFields.size===0)return;let e=Object.fromEntries(this.dirtyFields.entries());this.dirtyFields.clear(),this.onChange(e)}updateAndEmitDiffs(e){e!=null&&Object.keys(e).forEach(n=>{let r=n;this.data[r]!==e[r]&&this.set(r,e[r])})}receiveCustomMessage(e,n=[]){var s;let r=Be.safeParse(e);if(r.success){let i=r.data;switch(i.method){case"update":this.updateAndEmitDiffs(Y({state:i.state,bufferPaths:i.buffer_paths??[],buffers:n}));break;case"custom":(s=this.listeners["msg:custom"])==null||s.forEach(d=>d(i.content,n));break;case"open":this.updateAndEmitDiffs(Y({state:i.state,bufferPaths:i.buffer_paths??[],buffers:n}));break;case"echo_update":break;default:E.error("[anywidget] Unknown message method",i.method);break}}else E.error("Failed to parse message",r.error),E.error("Message",e)}on(e,n){this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(n)}emit(e,n){this.listeners[e]&&this.listeners[e].forEach(r=>r(n))}},a(j,"_modelManager",De),j),re=me(me(gt([fe(),wt()]))),se=bt(fe(),de()),Be=yt("method",[O({method:W("open"),state:se,buffer_paths:re.optional()}),O({method:W("update"),state:se,buffer_paths:re.optional()}),O({method:W("custom"),content:de()}),O({method:W("echo_update"),buffer_paths:re,state:se}),O({method:W("close")})]);function An(t){return t==null?!1:Be.safeParse(t).success}async function Tn({modelId:t,msg:e,buffers:n,modelManager:r}){if(e.method==="echo_update")return;if(e.method==="custom"){(await r.get(t)).receiveCustomMessage(e,n);return}if(e.method==="close"){r.delete(t);return}let{method:s,state:i,buffer_paths:d=[]}=e,l=Y({state:i,bufferPaths:d,buffers:n});if(s==="open"){let p=new He(l,b=>{let{state:x,buffers:w,bufferPaths:C}=ne(b);ye().sendModelValue({modelId:t,message:{state:x,bufferPaths:C},buffers:w})},y,new Set);r.set(t,p);return}if(s==="update"){(await r.get(t)).updateAndEmitDiffs(l);return}xt(s)}const Ve=q(null),Ln=q(null),$e=q(!1),Un=q(!1),Xe=q(!1);var zn=pe();const Ye=t=>{let e=(0,zn.c)(8),{onResize:n,startingWidth:r,minWidth:s,maxWidth:i}=t,d=(0,u.useRef)(null),l=(0,u.useRef)(null),p=(0,u.useRef)(null),b,x;e[0]!==i||e[1]!==s||e[2]!==n?(b=()=>{let _=d.current,k=l.current,R=p.current;if(!_||!k&&!R)return;let v=Number.parseInt(window.getComputedStyle(_).width,10),N=0,P=!1,I=null,L=c=>{if(!_||!P||!I)return;let h=c.clientX-N;N=c.clientX,v=I==="left"?v-h:v+h,s&&(v=Math.max(s,v)),i&&(v=Math.min(i,v)),_.style.width=`${v}px`},U=()=>{P&&(n==null||n(v),P=!1,I=null),document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",U)},o=(c,h)=>{c.preventDefault(),P=!0,I=h,N=c.clientX,document.addEventListener("mousemove",L),document.addEventListener("mouseup",U)},f=c=>o(c,"left"),g=c=>o(c,"right");return k&&k.addEventListener("mousedown",f),R&&R.addEventListener("mousedown",g),()=>{k&&k.removeEventListener("mousedown",f),R&&R.removeEventListener("mousedown",g),document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",U)}},x=[s,i,n],e[0]=i,e[1]=s,e[2]=n,e[3]=b,e[4]=x):(b=e[3],x=e[4]),(0,u.useEffect)(b,x);let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w={left:l,right:p},e[5]=w):w=e[5];let C=r==="contentWidth"?"var(--content-width-medium)":`${r}px`,F;return e[6]===C?F=e[7]:(F={resizableDivRef:d,handleRefs:w,style:{width:C}},e[6]=C,e[7]=F),F};function Ge(t){t||window.dispatchEvent(new Event("resize"))}var Qe=pe(),m=ce(Nt(),1);const On=()=>{let t=(0,Qe.c)(16),[e,n]=D(Ve),[r,s]=D($e),[i,d]=D(Un),[l,p]=D(Xe),b;t[0]!==s||t[1]!==n?(b=()=>{n(null),s(!1)},t[0]=s,t[1]=n,t[2]=b):b=t[2];let x=b;if(Z(B.CONTEXT_AWARE_PANEL).length===0||!e||!r)return null;let w;t[3]!==l||t[4]!==i||t[5]!==p||t[6]!==d?(w=()=>(0,m.jsxs)("div",{className:"flex flex-row items-center gap-3",children:[(0,m.jsx)(ve,{content:i?"Unpin panel":"Pin panel",children:(0,m.jsx)(Ee,{size:"xs",onPressedChange:()=>d(!i),pressed:i,"aria-label":i?"Unpin panel":"Pin panel",children:i?(0,m.jsx)($t,{className:"w-4 h-4"}):(0,m.jsx)(Pt,{className:"w-4 h-4"})})}),(0,m.jsx)(ve,{content:l?(0,m.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,m.jsx)("span",{children:"Follow focused table"}),(0,m.jsx)("span",{className:"text-xs text-muted-foreground w-64",children:"The panel updates as cells that output tables are focused. Click to fix to the current cell."})]}):(0,m.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,m.jsx)("span",{children:"Focus on current table"}),(0,m.jsx)("span",{className:"text-xs text-muted-foreground w-64",children:"The panel is focused on the current table. Click to update based on which cell is focused."})]}),children:(0,m.jsx)(Ee,{size:"xs",onPressedChange:()=>p(!l),pressed:l,"aria-label":l?"Follow focused cell":"Fixed",children:(0,m.jsx)(Vt,{className:qt("w-4 h-4",l&&"text-primary")})})})]}),t[3]=l,t[4]=i,t[5]=p,t[6]=d,t[7]=w):w=t[7];let C=w,F;t[8]!==x||t[9]!==C?(F=()=>(0,m.jsxs)("div",{className:"mt-2 pb-7 mb-4 h-full overflow-auto",children:[(0,m.jsxs)("div",{className:"flex flex-row justify-between items-center mx-2",children:[C(),(0,m.jsx)(St,{variant:"linkDestructive",size:"icon",onClick:x,"aria-label":"Close selection panel",children:(0,m.jsx)(jt,{className:"w-4 h-4"})})]}),(0,m.jsx)(ge,{children:(0,m.jsx)(Re,{name:B.CONTEXT_AWARE_PANEL})})]}),t[8]=x,t[9]=C,t[10]=F):F=t[10];let _=F;if(!i){let v;return t[11]===_?v=t[12]:(v=(0,m.jsx)(Dn,{children:_()}),t[11]=_,t[12]=v),v}let k;t[13]===Symbol.for("react.memo_cache_sentinel")?(k=(0,m.jsx)(Dt,{onDragging:Ge,className:"resize-handle border-border z-20 print:hidden border-l"}),t[13]=k):k=t[13];let R;return t[14]===_?R=t[15]:(R=(0,m.jsxs)(m.Fragment,{children:[k,(0,m.jsx)(Ht,{defaultSize:20,minSize:15,maxSize:80,children:_()})]}),t[14]=_,t[15]=R),R},Wn=t=>{let e=(0,Qe.c)(2),{children:n}=t,r;return e[0]===n?r=e[1]:(r=(0,m.jsx)(ge,{children:(0,m.jsx)(Yt,{name:B.CONTEXT_AWARE_PANEL,children:n})}),e[0]=n,e[1]=r),r};var Dn=({children:t})=>{let{resizableDivRef:e,handleRefs:n,style:r}=Ye({startingWidth:400,minWidth:300,maxWidth:1500});return(0,m.jsxs)("div",{className:"absolute z-40 right-0 h-full bg-background flex flex-row",children:[(0,m.jsx)("div",{ref:n.left,className:"w-1 h-full cursor-col-resize border-l"}),(0,m.jsx)("div",{ref:e,style:r,children:t})]})};function Hn(){var t=[...arguments];return(0,u.useMemo)(()=>e=>{t.forEach(n=>n(e))},t)}var Je=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0;function G(t){let e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function ae(t){return"nodeType"in t}function T(t){var e;return t?G(t)?t:ae(t)?((e=t.ownerDocument)==null?void 0:e.defaultView)??window:window:window}function Ke(t){let{Document:e}=T(t);return t instanceof e}function Ze(t){return G(t)?!1:t instanceof T(t).HTMLElement}function et(t){return t instanceof T(t).SVGElement}function Bn(t){return t?G(t)?t.document:ae(t)?Ke(t)?t:Ze(t)||et(t)?t.ownerDocument:document:document:document}var ie=Je?u.useLayoutEffect:u.useEffect;function tt(t){let e=(0,u.useRef)(t);return ie(()=>{e.current=t}),(0,u.useCallback)(function(){var n=[...arguments];return e.current==null?void 0:e.current(...n)},[])}function Vn(){let t=(0,u.useRef)(null);return[(0,u.useCallback)((e,n)=>{t.current=setInterval(e,n)},[]),(0,u.useCallback)(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[])]}function $n(t,e){e===void 0&&(e=[t]);let n=(0,u.useRef)(t);return ie(()=>{n.current!==t&&(n.current=t)},e),n}function Xn(t,e){let n=(0,u.useRef)();return(0,u.useMemo)(()=>{let r=t(n.current);return n.current=r,r},[...e])}function Yn(t){let e=tt(t),n=(0,u.useRef)(null);return[n,(0,u.useCallback)(r=>{r!==n.current&&(e==null||e(r,n.current)),n.current=r},[])]}function Gn(t){let e=(0,u.useRef)();return(0,u.useEffect)(()=>{e.current=t},[t]),e.current}var oe={};function Qn(t,e){return(0,u.useMemo)(()=>{if(e)return e;let n=oe[t]==null?0:oe[t]+1;return oe[t]=n,t+"-"+n},[t,e])}function nt(t){return function(e){return[...arguments].slice(1).reduce((n,r)=>{let s=Object.entries(r);for(let[i,d]of s){let l=n[i];l!=null&&(n[i]=l+t*d)}return n},{...e})}}var Jn=nt(1),Kn=nt(-1);function Zn(t){return"clientX"in t&&"clientY"in t}function er(t){if(!t)return!1;let{KeyboardEvent:e}=T(t.target);return e&&t instanceof e}function tr(t){if(!t)return!1;let{TouchEvent:e}=T(t.target);return e&&t instanceof e}function nr(t){if(tr(t)){if(t.touches&&t.touches.length){let{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){let{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return Zn(t)?{x:t.clientX,y:t.clientY}:null}var le=Object.freeze({Translate:{toString(t){if(!t)return;let{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;let{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[le.Translate.toString(t),le.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),rt="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function rr(t){return t.matches(rt)?t:t.querySelector(rt)}export{kn as $,Ln as A,Mn as B,Qn as C,Ye as D,Ge as E,An as F,Oe as G,Sn as H,Y as I,Ue as J,Le as K,In as L,De as M,He as N,$e as O,Tn as P,Ae as Q,ne as R,Gn as S,Wn as T,We as U,jn as V,Nn as W,Te as X,Fn as Y,Rn as Z,Vn as _,nr as a,un as at,Xn as b,Ke as c,ln as ct,ae as d,Z as dt,$ as et,et as f,H as ft,tt as g,Hn as h,rr as i,B as it,Xe as j,Ve as k,Ze as l,nn as lt,Kn as m,Jn as n,qe as nt,Bn as o,rn as ot,G as p,ze as q,Je as r,Fe as rt,T as s,on as st,le as t,wn as tt,er as u,Re as ut,ie as v,On as w,Yn as x,$n as y,qn as z};
|
package/dist/index.html
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
|
|
67
67
|
<!-- /TODO -->
|
|
68
68
|
<title>{{ title }}</title>
|
|
69
|
-
<script type="module" crossorigin src="./assets/index-
|
|
69
|
+
<script type="module" crossorigin src="./assets/index-BL9e2vk6.js"></script>
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-DItdS47A.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="./assets/clsx-D8GwTfvk.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="./assets/cn-BKtXLv3a.js">
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
<link rel="modulepreload" crossorigin href="./assets/useDateFormatter-CieT0-H-.js">
|
|
208
208
|
<link rel="modulepreload" crossorigin href="./assets/range-D2UKkEg-.js">
|
|
209
209
|
<link rel="modulepreload" crossorigin href="./assets/table-CfDbAm78.js">
|
|
210
|
-
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-
|
|
210
|
+
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-BTXiwFjF.js">
|
|
211
211
|
<link rel="modulepreload" crossorigin href="./assets/file-Ch78NKWp.js">
|
|
212
212
|
<link rel="modulepreload" crossorigin href="./assets/play-GLWQQs7F.js">
|
|
213
213
|
<link rel="modulepreload" crossorigin href="./assets/chat-components-jnrAy95o.js">
|
|
@@ -223,13 +223,13 @@
|
|
|
223
223
|
<link rel="modulepreload" crossorigin href="./assets/chart-no-axes-column-qvVRjhv1.js">
|
|
224
224
|
<link rel="modulepreload" crossorigin href="./assets/square-function-B6mgCeFJ.js">
|
|
225
225
|
<link rel="modulepreload" crossorigin href="./assets/spec-Ch0xnJY4.js">
|
|
226
|
-
<link rel="modulepreload" crossorigin href="./assets/column-preview-
|
|
226
|
+
<link rel="modulepreload" crossorigin href="./assets/column-preview-t0CyBVJf.js">
|
|
227
227
|
<link rel="modulepreload" crossorigin href="./assets/toggle-CriARMQK.js">
|
|
228
228
|
<link rel="modulepreload" crossorigin href="./assets/globals-BgJBhxFI.js">
|
|
229
229
|
<link rel="modulepreload" crossorigin href="./assets/share-rXkgGlhr.js">
|
|
230
230
|
<link rel="modulepreload" crossorigin href="./assets/_baseSet-5Rdwpmr3.js">
|
|
231
231
|
<link rel="modulepreload" crossorigin href="./assets/react-resizable-panels.browser.esm-Mq45xjWt.js">
|
|
232
|
-
<link rel="modulepreload" crossorigin href="./assets/utilities.esm-
|
|
232
|
+
<link rel="modulepreload" crossorigin href="./assets/utilities.esm-8Diy8be3.js">
|
|
233
233
|
<link rel="modulepreload" crossorigin href="./assets/floating-outline-C8UBGhNL.js">
|
|
234
234
|
<link rel="modulepreload" crossorigin href="./assets/useAddCell-Bc2_jloT.js">
|
|
235
235
|
<link rel="modulepreload" crossorigin href="./assets/eye-off-AK_9uodG.js">
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
ColumnDef,
|
|
4
|
+
PaginationState,
|
|
5
|
+
RowSelectionState,
|
|
6
|
+
SortingState,
|
|
7
|
+
} from "@tanstack/react-table";
|
|
8
|
+
import { render, screen, within } from "@testing-library/react";
|
|
4
9
|
import { describe, expect, it, vi } from "vitest";
|
|
5
10
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
6
11
|
import { DataTable } from "../data-table";
|
|
@@ -95,4 +100,91 @@ describe("DataTable", () => {
|
|
|
95
100
|
expect(rows[1]).toHaveAttribute("title", "Michael Scott");
|
|
96
101
|
expect(rows[2]).toHaveAttribute("title", "Jim Halpert");
|
|
97
102
|
});
|
|
103
|
+
|
|
104
|
+
it("should display updated data after rerender with manual sorting and pagination", () => {
|
|
105
|
+
// Simulates the bug from issue #8023:
|
|
106
|
+
// When a user sorts a table, rows that moved from page 2 to page 1
|
|
107
|
+
// don't visually refresh after the underlying data is updated.
|
|
108
|
+
|
|
109
|
+
interface RowData {
|
|
110
|
+
id: number;
|
|
111
|
+
status: string;
|
|
112
|
+
value: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Initial data: 4 rows, page_size=3
|
|
116
|
+
const initialData: RowData[] = [
|
|
117
|
+
{ id: 4, status: "pending", value: 40 },
|
|
118
|
+
{ id: 3, status: "pending", value: 30 },
|
|
119
|
+
{ id: 2, status: "pending", value: 20 },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const columns: ColumnDef<RowData>[] = [
|
|
123
|
+
{ id: "id", accessorFn: (row) => row.id, header: "id" },
|
|
124
|
+
{ id: "status", accessorFn: (row) => row.status, header: "status" },
|
|
125
|
+
{ id: "value", accessorFn: (row) => row.value, header: "value" },
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
// Simulate sorted state (value descending) - manual sorting means
|
|
129
|
+
// data comes pre-sorted from backend
|
|
130
|
+
const sorting: SortingState = [{ id: "value", desc: true }];
|
|
131
|
+
const setSorting = vi.fn();
|
|
132
|
+
|
|
133
|
+
const paginationState: PaginationState = { pageIndex: 0, pageSize: 3 };
|
|
134
|
+
const setPaginationState = vi.fn();
|
|
135
|
+
|
|
136
|
+
const commonProps = {
|
|
137
|
+
columns,
|
|
138
|
+
selection: null as "single" | "multi" | null,
|
|
139
|
+
totalRows: 4,
|
|
140
|
+
totalColumns: 3,
|
|
141
|
+
pagination: true,
|
|
142
|
+
manualPagination: true,
|
|
143
|
+
paginationState,
|
|
144
|
+
setPaginationState,
|
|
145
|
+
manualSorting: true,
|
|
146
|
+
sorting,
|
|
147
|
+
setSorting,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const { rerender } = render(
|
|
151
|
+
<TooltipProvider>
|
|
152
|
+
<DataTable {...commonProps} data={initialData} />
|
|
153
|
+
</TooltipProvider>,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// Verify initial data is displayed - look for "pending" in cells
|
|
157
|
+
const rows = screen.getAllByRole("row");
|
|
158
|
+
// Row 0 is header, rows 1-3 are data rows
|
|
159
|
+
expect(rows).toHaveLength(4); // 1 header + 3 data rows
|
|
160
|
+
// All rows should show "pending"
|
|
161
|
+
expect(within(rows[1]).getByText("pending")).toBeTruthy();
|
|
162
|
+
expect(within(rows[2]).getByText("pending")).toBeTruthy();
|
|
163
|
+
expect(within(rows[3]).getByText("pending")).toBeTruthy();
|
|
164
|
+
|
|
165
|
+
// Now simulate data update: row with id=4 is now "approved"
|
|
166
|
+
// Backend returns sorted data with the update applied
|
|
167
|
+
const updatedData: RowData[] = [
|
|
168
|
+
{ id: 4, status: "approved", value: 40 },
|
|
169
|
+
{ id: 3, status: "pending", value: 30 },
|
|
170
|
+
{ id: 2, status: "pending", value: 20 },
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
// Rerender with updated data (same sorting, same pagination)
|
|
174
|
+
rerender(
|
|
175
|
+
<TooltipProvider>
|
|
176
|
+
<DataTable {...commonProps} data={updatedData} />
|
|
177
|
+
</TooltipProvider>,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// BUG: The row should show "approved" but might show stale "pending"
|
|
181
|
+
const updatedRows = screen.getAllByRole("row");
|
|
182
|
+
expect(updatedRows).toHaveLength(4);
|
|
183
|
+
|
|
184
|
+
// The first data row (id=4) should now show "approved"
|
|
185
|
+
expect(within(updatedRows[1]).getByText("approved")).toBeTruthy();
|
|
186
|
+
// Other rows should still show "pending"
|
|
187
|
+
expect(within(updatedRows[2]).getByText("pending")).toBeTruthy();
|
|
188
|
+
expect(within(updatedRows[3]).getByText("pending")).toBeTruthy();
|
|
189
|
+
});
|
|
98
190
|
});
|
package/src/core/MarimoApp.tsx
CHANGED
|
@@ -39,14 +39,18 @@ const LazyGalleryPage = reactLazyWithPreload(
|
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
export function preloadPage(mode: string) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
switch (mode) {
|
|
43
|
+
case "home":
|
|
44
|
+
LazyHomePage.preload();
|
|
45
|
+
break;
|
|
46
|
+
case "gallery":
|
|
47
|
+
LazyGalleryPage.preload();
|
|
48
|
+
break;
|
|
49
|
+
case "read":
|
|
50
|
+
LazyRunPage.preload();
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
LazyEditPage.preload();
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
@@ -101,10 +101,17 @@ function PluginSlotInternal<T>(
|
|
|
101
101
|
return plugin.validator.safeParse(parseDataset(hostElement));
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
// Incremented on each reset to invalidate memoized function references.
|
|
105
|
+
// This ensures that plugin functions (e.g., search) are re-created when
|
|
106
|
+
// the underlying UI element instance changes (new object-id), even if
|
|
107
|
+
// the element's data attributes haven't changed.
|
|
108
|
+
const [resetNonce, setResetNonce] = useState(0);
|
|
109
|
+
|
|
104
110
|
useImperativeHandle(ref, () => ({
|
|
105
111
|
reset: () => {
|
|
106
112
|
setValue(getInitialValue());
|
|
107
113
|
setParsedResult(plugin.validator.safeParse(parseDataset(hostElement)));
|
|
114
|
+
setResetNonce((n) => n + 1);
|
|
108
115
|
},
|
|
109
116
|
setChildren: (children) => {
|
|
110
117
|
setChildNodes(children);
|
|
@@ -224,7 +231,8 @@ function PluginSlotInternal<T>(
|
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
return methods;
|
|
227
|
-
|
|
234
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
235
|
+
}, [plugin.functions, hostElement, resetNonce]);
|
|
228
236
|
|
|
229
237
|
// If we failed to parse the initial value, render an error
|
|
230
238
|
if (!parsedResult.success) {
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { TooltipProvider } from "@radix-ui/react-tooltip";
|
|
4
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import { Provider } from "jotai";
|
|
6
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { DownloadAsArgs } from "@/components/data-table/schemas";
|
|
8
|
+
import type { FieldTypesWithExternalType } from "@/components/data-table/types";
|
|
9
|
+
import { store } from "@/core/state/jotai";
|
|
10
|
+
import {
|
|
11
|
+
type GetDataUrl,
|
|
12
|
+
type GetRowIds,
|
|
13
|
+
LoadingDataTableComponent,
|
|
14
|
+
} from "../DataTablePlugin";
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
global.ResizeObserver = class ResizeObserver {
|
|
18
|
+
observe() {
|
|
19
|
+
// do nothing
|
|
20
|
+
}
|
|
21
|
+
unobserve() {
|
|
22
|
+
// do nothing
|
|
23
|
+
}
|
|
24
|
+
disconnect() {
|
|
25
|
+
// do nothing
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("LoadingDataTableComponent", () => {
|
|
31
|
+
/**
|
|
32
|
+
* Regression test for https://github.com/marimo-team/marimo/issues/8023
|
|
33
|
+
*
|
|
34
|
+
* When a table is replaced via mo.output.replace() with updated data,
|
|
35
|
+
* but the initial page data (unsorted first page) hasn't changed,
|
|
36
|
+
* the useAsyncData hook's deps may all remain the same.
|
|
37
|
+
* Previously, the `search` function reference was memoized on
|
|
38
|
+
* [plugin.functions, hostElement] and wouldn't change on reset(),
|
|
39
|
+
* so the useAsyncData effect wouldn't re-fire.
|
|
40
|
+
*
|
|
41
|
+
* The fix adds a resetNonce to the functionMethods memo deps,
|
|
42
|
+
* so when the plugin is reset (table instance changes), the search
|
|
43
|
+
* function reference changes, triggering useAsyncData to re-fetch.
|
|
44
|
+
*
|
|
45
|
+
* This test verifies that when the search function reference changes
|
|
46
|
+
* (simulating reset()), the component re-fetches data even if
|
|
47
|
+
* props.data hasn't changed.
|
|
48
|
+
*/
|
|
49
|
+
it("should refetch data when search function reference changes", async () => {
|
|
50
|
+
const host = document.createElement("div");
|
|
51
|
+
const setValue = vi.fn();
|
|
52
|
+
|
|
53
|
+
// The initial page data string - identical for both renders.
|
|
54
|
+
// This simulates the case where only a row on page 2 changed,
|
|
55
|
+
// so the first page data is the same.
|
|
56
|
+
const initialPageData = JSON.stringify([
|
|
57
|
+
{ id: 1, status: "pending", value: 10 },
|
|
58
|
+
{ id: 2, status: "pending", value: 20 },
|
|
59
|
+
{ id: 3, status: "pending", value: 30 },
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const searchResult = {
|
|
63
|
+
data: [
|
|
64
|
+
{ id: 1, status: "pending", value: 10 },
|
|
65
|
+
{ id: 2, status: "pending", value: 20 },
|
|
66
|
+
{ id: 3, status: "pending", value: 30 },
|
|
67
|
+
],
|
|
68
|
+
total_rows: 4,
|
|
69
|
+
cell_styles: null,
|
|
70
|
+
cell_hover_texts: null,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const searchFn1 = vi.fn().mockResolvedValue(searchResult);
|
|
74
|
+
const searchFn2 = vi.fn().mockResolvedValue(searchResult);
|
|
75
|
+
|
|
76
|
+
const fieldTypes: FieldTypesWithExternalType = [
|
|
77
|
+
["id", ["integer", "integer"]],
|
|
78
|
+
["status", ["string", "string"]],
|
|
79
|
+
["value", ["integer", "integer"]],
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const commonProps = {
|
|
83
|
+
label: null,
|
|
84
|
+
totalRows: 4,
|
|
85
|
+
pagination: true,
|
|
86
|
+
pageSize: 3,
|
|
87
|
+
selection: "single" as const,
|
|
88
|
+
showDownload: false,
|
|
89
|
+
showFilters: false,
|
|
90
|
+
showColumnSummaries: false as const,
|
|
91
|
+
showDataTypes: false,
|
|
92
|
+
showPageSizeSelector: false,
|
|
93
|
+
showColumnExplorer: false,
|
|
94
|
+
showRowExplorer: false,
|
|
95
|
+
showChartBuilder: false,
|
|
96
|
+
rowHeaders: [] as FieldTypesWithExternalType,
|
|
97
|
+
fieldTypes,
|
|
98
|
+
totalColumns: 3,
|
|
99
|
+
maxColumns: "all" as const,
|
|
100
|
+
hasStableRowId: false,
|
|
101
|
+
lazy: false,
|
|
102
|
+
host,
|
|
103
|
+
enableSearch: true,
|
|
104
|
+
value: [] as (number | string | { rowId: string; columnName?: string })[],
|
|
105
|
+
setValue,
|
|
106
|
+
download_as: vi.fn() as DownloadAsArgs,
|
|
107
|
+
get_column_summaries: vi.fn().mockResolvedValue({
|
|
108
|
+
data: null,
|
|
109
|
+
stats: {},
|
|
110
|
+
bin_values: {},
|
|
111
|
+
value_counts: {},
|
|
112
|
+
show_charts: false,
|
|
113
|
+
}),
|
|
114
|
+
get_data_url: vi.fn() as GetDataUrl,
|
|
115
|
+
get_row_ids: vi.fn() as GetRowIds,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
119
|
+
<Provider store={store}>
|
|
120
|
+
<TooltipProvider>{children}</TooltipProvider>
|
|
121
|
+
</Provider>
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Render with first search function
|
|
125
|
+
const { rerender } = render(
|
|
126
|
+
<Wrapper>
|
|
127
|
+
<LoadingDataTableComponent
|
|
128
|
+
{...commonProps}
|
|
129
|
+
data={initialPageData}
|
|
130
|
+
search={searchFn1}
|
|
131
|
+
/>
|
|
132
|
+
</Wrapper>,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Wait for the table to render with data
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(screen.getAllByRole("row").length).toBeGreaterThan(1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Search was called on initial load (fire-and-forget for canShowInitialPage)
|
|
141
|
+
expect(searchFn1).toHaveBeenCalled();
|
|
142
|
+
|
|
143
|
+
// Now rerender with the same data but a NEW search function reference.
|
|
144
|
+
// This simulates what happens after reset() when resetNonce increments
|
|
145
|
+
// and functionMethods is recreated.
|
|
146
|
+
await act(async () => {
|
|
147
|
+
rerender(
|
|
148
|
+
<Wrapper>
|
|
149
|
+
<LoadingDataTableComponent
|
|
150
|
+
{...commonProps}
|
|
151
|
+
data={initialPageData}
|
|
152
|
+
search={searchFn2}
|
|
153
|
+
/>
|
|
154
|
+
</Wrapper>,
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// The new search function should be called because the search
|
|
159
|
+
// dependency changed in useAsyncData.
|
|
160
|
+
await waitFor(() => {
|
|
161
|
+
expect(searchFn2).toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|