@marimo-team/frontend 0.21.2-dev58 → 0.21.2-dev59

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/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-DC6PpQWW.js"></script>
69
+ <script type="module" crossorigin src="./assets/index-BrQynBQn.js"></script>
70
70
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-y72bE5iF.js">
71
71
  <link rel="modulepreload" crossorigin href="./assets/clsx-BDxNtGmi.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/cn-BoaCR37F.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.21.2-dev58",
3
+ "version": "0.21.2-dev59",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -62,9 +62,11 @@ import type { FileInfo } from "@/core/network/types";
62
62
  import { isWasm } from "@/core/wasm/utils";
63
63
  import { useAsyncData } from "@/hooks/useAsyncData";
64
64
  import { ErrorBanner } from "@/plugins/impl/common/error-banner";
65
+ import { deserializeBlob } from "@/utils/blob";
65
66
  import { cn } from "@/utils/cn";
66
67
  import { copyToClipboard } from "@/utils/copy";
67
68
  import { downloadBlob } from "@/utils/download";
69
+ import { type Base64String, base64ToDataURL } from "@/utils/json/base64";
68
70
  import { openNotebook } from "@/utils/links";
69
71
  import type { FilePath } from "@/utils/paths";
70
72
  import { fileSplit } from "@/utils/pathUtils";
@@ -650,8 +652,20 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
650
652
  <DropdownMenuItem
651
653
  onSelect={async () => {
652
654
  const details = await sendFileDetails({ path: node.data.path });
653
- const contents = details.contents || "";
654
- downloadBlob(new Blob([contents]), node.data.name);
655
+ if (details.isBase64 && details.contents) {
656
+ const blob = deserializeBlob(
657
+ base64ToDataURL(
658
+ details.contents as Base64String,
659
+ details.mimeType || "application/octet-stream",
660
+ ),
661
+ );
662
+ downloadBlob(blob, node.data.name);
663
+ } else {
664
+ downloadBlob(
665
+ new Blob([details.contents || ""]),
666
+ node.data.name,
667
+ );
668
+ }
655
669
  }}
656
670
  >
657
671
  <DownloadIcon className={ic} />
@@ -21,6 +21,7 @@ import { filenameAtom } from "@/core/saving/file-state";
21
21
  import { isWasm } from "@/core/wasm/utils";
22
22
  import { useAsyncData } from "@/hooks/useAsyncData";
23
23
  import { ErrorBanner } from "@/plugins/impl/common/error-banner";
24
+ import { deserializeBlob } from "@/utils/blob";
24
25
  import { copyToClipboard } from "@/utils/copy";
25
26
  import { downloadBlob, downloadByURL } from "@/utils/download";
26
27
  import { type Base64String, base64ToDataURL } from "@/utils/json/base64";
@@ -121,9 +122,22 @@ export const FileViewer: React.FC<Props> = ({ file, onOpenNotebook }) => {
121
122
  }
122
123
 
123
124
  const handleDownload = () => {
124
- if (isMediaMime(mimeType)) {
125
- const dataURL = base64ToDataURL(data.contents as Base64String, mimeType);
126
- downloadByURL(dataURL, data.file.name);
125
+ if (data.isBase64 && data.contents) {
126
+ if (isMediaMime(mimeType)) {
127
+ const dataURL = base64ToDataURL(
128
+ data.contents as Base64String,
129
+ mimeType,
130
+ );
131
+ downloadByURL(dataURL, data.file.name);
132
+ } else {
133
+ const blob = deserializeBlob(
134
+ base64ToDataURL(
135
+ data.contents as Base64String,
136
+ data.mimeType || "application/octet-stream",
137
+ ),
138
+ );
139
+ downloadBlob(blob, data.file.name);
140
+ }
127
141
  return;
128
142
  }
129
143
 
@@ -1,26 +0,0 @@
1
- var Mt=Object.defineProperty;var Ot=(t,e,n)=>e in t?Mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var V=(t,e,n)=>Ot(t,typeof e!="symbol"?e+"":e,n);import{s as Te}from"./chunk-LvLJmgfZ.js";import{i as $t,l as he,n as L,p as Re,u as se}from"./useEvent-O0nX5vok.js";import{t as Tt}from"./react-Bj1aDYRI.js";import{E as Rt,Sn as At,Tn as Ae,cr as Et,li as Ee,oi as It}from"./cells-DiVpbkA6.js";import"./react-dom-CSu739Rf.js";import{t as ae}from"./compiler-runtime-B3qBwwSJ.js";import"./utils-DnNnBV1N.js";import{i as Ie,r as Lt,t as Le}from"./add-connection-dialog-BvzGJCV7.js";import{h as Vt,m as ge}from"./useEventListener-Dy81QR4n.js";import{t as Bt}from"./invariant-CQUIhlu2.js";import{p as Ht,u as Ve}from"./utils-tNbLd14P.js";import{S as me}from"./config-DqxNMQDN.js";import{t as Ut}from"./jsx-runtime-icT_Ltz2.js";import{n as qt,t as $}from"./button-Ej3vmCIF.js";import{t as W}from"./cn-BoaCR37F.js";import{St as Wt}from"./dist-B_cxg-E4.js";import{a as Gt,i as Be,o as pe}from"./JsonOutput-bhD4i0Fm.js";import"./cjs-BU2qXMKx.js";import"./main-DrBRErTM.js";import"./useNonce-BtW-rR_1.js";import{n as Kt,r as ye}from"./requests-Bgjtqo_1.js";import{t as H}from"./createLucideIcon-Cm-Z7dYr.js";import{a as He,c as Ue,i as qe,n as fe,o as je,r as Jt,t as Yt}from"./state-Dxl7WjW3.js";import{n as Zt}from"./LazyAnyLanguageCodeMirror-C58z97yX.js";import{t as Qt}from"./x-CdLP7-v3.js";import{c as Xt,i as be,r as We}from"./download-UmTPygP7.js";import{f as ve}from"./maps-DQsjfyTy.js";import{n as ea}from"./markdown-renderer-nMv2xwHt.js";import{u as ta}from"./toDate-Cfp9W_O9.js";import{a as O,c as ne,p as Ge,r as Ke,t as Je}from"./dropdown-menu-BehqiLFL.js";import{t as we}from"./copy-D6N1-xc1.js";import{t as Ne}from"./download-nLboiTtW.js";import{t as aa}from"./eye-off-CF3GmvXV.js";import{a as na,i as Ye,n as Ze,r as sa,t as ra}from"./file-icons-BTQcwa4T.js";import{t as Qe}from"./file-plus-corner-ks__N1mr.js";import{t as Xe}from"./file-C-yMeaec.js";import{n as ke,t as la}from"./spinner-pCogyRyo.js";import{t as et}from"./plus-DJ99CUbx.js";import{t as tt}from"./refresh-cw-Dg9tCj4k.js";import{t as ia}from"./save-CUdcv5qm.js";import{t as oa}from"./trash-2-Bc_J7TQO.js";import{t as ca}from"./triangle-alert-CzLrbLGN.js";import{i as da,n as ha,t as ma}from"./es-DKHH3Swu.js";import"./dist-C6ohaMKU.js";import"./dist-BatEf-0f.js";import"./dist-Dm11d0_A.js";import"./dist-BF9S272t.js";import"./dist-Bk1itfBD.js";import{t as A}from"./use-toast-BtZldTi5.js";import{t as Ce}from"./paths-BVwhPRFT.js";import"./session-CByuQ-M-.js";import"./Combination-CSPK4t6z.js";import{t as R}from"./tooltip-CR_izE8Q.js";import"./purify.es-Cf8RQecB.js";import"./dates-CTqMeMGY.js";import{o as pa}from"./alert-dialog-Baw3WWPa.js";import{t as at}from"./context-CqNy_uER.js";import"./popover-BzqPa2Au.js";import{n as nt}from"./ImperativeModal-C5ZzjCQG.js";import{r as fa}from"./errors-iwK4b4VF.js";import{n as xa}from"./blob-C3EfaMOb.js";import"./vega-loader.browser-xq8miGHn.js";import"./defaultLocale-DPBdGRrH.js";import"./defaultLocale-Lfi0pexn.js";import{n as re}from"./copy-CcUDATFX.js";import{t as ua}from"./copy-icon-WvgZ60QO.js";import{n as ga}from"./multi-map-0vmox9BD.js";import{a as ya,i as ja,n as Fe,r as ba,t as va}from"./tree-Duf22i7P.js";import{n as wa,t as Na}from"./alert-NjVFesQm.js";import{n as st}from"./error-banner-BYG94WiL.js";import{n as _e}from"./useAsyncData-D-z1U8-c.js";import{a as ka,o as rt,t as Ca,u as Fa}from"./command-B9VNhm0p.js";import"./chunk-5FQGJX7Z-BSe8eGYF.js";import"./katex-FSdXOW5Y.js";import"./html-to-image-CRCamxYo.js";import{o as _a}from"./focus-BRTg8M44.js";import{a as Sa}from"./renderShortcut-DG5sXSxr.js";import{t as Pa}from"./bundle.esm-_LzfhNmX.js";import{t as lt}from"./useAddCell-fzJF_CdR.js";import{a as Da,c as Se,d as Pe,l as it,u as ot}from"./components-CUetByBv.js";import{t as za}from"./empty-state-BBWqzODS.js";import{t as De}from"./formatting-DBrNlcJ6.js";import{a as Ma,i as Oa,n as ct,r as dt,t as ht}from"./components-BouDP-tv.js";import{n as mt,t as $a}from"./marimo-icons-Cb4NA8Cp.js";import{t as Ta}from"./links-Bfp-iNRX.js";var Ra=H("book-plus",[["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]),Aa=H("copy-minus",[["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),Ea=H("file-symlink",[["path",{d:"M4 11V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h7",key:"huwfnr"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m10 18 3-3-3-3",key:"18f6ys"}]]),pt=H("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),ft=H("list-tree",[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]),Ia=H("pen-line",[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]),La=H("square-play",[["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z",key:"kmsa83"}]]),xt=H("view",[["path",{d:"M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2",key:"mrq65r"}],["path",{d:"M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2",key:"be3xqs"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["path",{d:"M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0",key:"11ak4c"}]]),z=Te(Tt(),1),Va=ae(),a=Te(Ut(),1);const ut=t=>{let e=(0,Va.c)(17),{filename:n,filenameIcon:l,onBack:r,onRefresh:s,onDownload:c,actions:o}=t,h;e[0]===r?h=e[1]:(h=r&&(0,a.jsx)(R,{content:"Back to file list",children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:r,children:(0,a.jsx)(Ue,{className:"h-4 w-4"})})}),e[0]=r,e[1]=h);let i;e[2]!==n||e[3]!==l?(i=n?(0,a.jsxs)("span",{className:"flex items-center gap-1.5 flex-1 min-w-0 text-xs font-semibold truncate",children:[l,n]}):(0,a.jsx)("span",{className:"flex-1"}),e[2]=n,e[3]=l,e[4]=i):i=e[4];let f;e[5]===s?f=e[6]:(f=s&&(0,a.jsx)(R,{content:"Refresh",children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:s,children:(0,a.jsx)(tt,{className:"h-3.5 w-3.5"})})}),e[5]=s,e[6]=f);let x;e[7]===c?x=e[8]:(x=c&&(0,a.jsx)(R,{content:"Download",children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:c,children:(0,a.jsx)(Ne,{className:"h-3.5 w-3.5"})})}),e[7]=c,e[8]=x);let j;e[9]!==o||e[10]!==f||e[11]!==x?(j=(0,a.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[f,o,x]}),e[9]=o,e[10]=f,e[11]=x,e[12]=j):j=e[12];let g;return e[13]!==h||e[14]!==i||e[15]!==j?(g=(0,a.jsxs)("div",{className:"flex items-center shrink-0 border-b px-1 gap-1",children:[h,i,j]}),e[13]=h,e[14]=i,e[15]=j,e[16]=g):g=e[16],g};var Ba=new Set(["http","file","in-memory"]);function ze(t){return JSON.stringify(t).slice(1,-1)}const gt=[{id:"read-file",label:"Insert read snippet",icon:Ra,getCode:t=>{if(t.entry.kind==="directory")return null;let e=ze(t.entry.path);return t.backendType==="obstore"?`_data = ${t.variableName}.get("${e}").bytes()
2
- _data`:`_data = ${t.variableName}.cat_file("${e}")
3
- _data`}},{id:"download-file",label:"Insert download snippet",icon:Ea,getCode:t=>{if(t.entry.kind==="directory")return null;let e=ze(t.entry.path);if(t.backendType==="obstore")return Ba.has(t.protocol)?null:`from datetime import timedelta
4
- from obstore import sign
5
-
6
- signed_url = sign(
7
- ${t.variableName}, "GET", "${e}",
8
- expires_in=timedelta(hours=1),
9
- )
10
- signed_url`;let n=ze(t.entry.path.split("/").pop()||"download");return`${t.variableName}.get("${e}", "${n}")`}}];var Ha=100*1024*1024;function Ua(t){let e=t.endsWith("/")?t.slice(0,-1):t,n=e.split("/");return n[n.length-1]||e}const qa=({entry:t,namespace:e,protocol:n,backendType:l,onBack:r})=>{let{locale:s}=at(),c=lt(),o=Ua(t.path),h=t.mimeType||"text/plain",i=pe(h),f=i&&t.size>Ha&&t.size>0,{data:x,isPending:j,error:g,refetch:m}=_e(async()=>{if(f)return null;let y=await je.request({namespace:e,path:t.path,preview:!i});if(y.error)throw Error(y.error);if(!y.url)throw Error("No URL returned");if(i)return{type:"media",url:y.url};let w=await fetch(y.url);if(!w.ok)throw Error(`Failed to fetch preview: ${w.statusText}`);return{type:"text",content:await w.text()}},[e,t.path,i,f]),N=(0,z.useCallback)(async()=>{try{let y=await je.request({namespace:e,path:t.path});if(y.error){A({title:"Download failed",description:y.error,variant:"danger"});return}y.url&&be(y.url,y.filename??o)}catch(y){ge.error("Failed to download storage entry",y),A({title:"Download failed",description:String(y),variant:"danger"})}},[e,t.path,o]),v=gt.map(y=>{let w=y.getCode({variableName:e,protocol:n,entry:t,backendType:l});if(w===null)return null;let u=y.icon;return(0,a.jsx)(R,{content:y.label,children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:()=>c(w),"aria-label":y.label,children:(0,a.jsx)(u,{className:"h-3.5 w-3.5"})})},y.id)}),p=(0,a.jsx)(ut,{filename:o,filenameIcon:Ye(o),onBack:r,onDownload:N,actions:v}),b=({includeMime:y=!1})=>(0,a.jsxs)("div",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 p-4 text-xs",children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Path"}),(0,a.jsxs)("div",{className:"truncate flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"font-mono text-[11px]",children:t.path}),(0,a.jsx)(ua,{value:t.path,className:"h-3 w-3"})]}),y&&(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Type"}),y&&(0,a.jsx)("span",{children:h}),t.size>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Size"}),(0,a.jsx)("span",{children:De(t.size,s)})]}),t.lastModified!=null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Modified"}),(0,a.jsx)("span",{children:new Date(t.lastModified*1e3).toLocaleString()})]})]});return f?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"px-4 pb-4 text-xs text-muted-foreground italic",children:["File is too large to preview (",De(t.size,s),")."]})]}):j?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({}),(0,a.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground min-h-24",children:[(0,a.jsx)(ke,{className:"h-4 w-4 animate-spin"}),"Loading preview..."]})]}):g?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"px-4 pb-4 text-xs text-destructive",children:["Failed to load preview: ",g.message]}),(0,a.jsx)("div",{className:"px-4 pb-4",children:(0,a.jsxs)($,{variant:"secondary",size:"xs",onClick:m,children:[(0,a.jsx)(tt,{className:"h-3 w-3 mr-1"}),"Retry"]})})]}):x?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({}),(0,a.jsx)(Be,{mimeType:h,contents:x.type==="text"?x.content:void 0,mediaSource:x.type==="media"?{url:x.url}:void 0})]}):(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"p-4 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(Xe,{className:"h-4 w-4"}),"Preview not available for this file type."]})]})};var Me=ae(),Wa=16;function U(t){return{paddingLeft:t*Wa}}function Ga(t,e){return new Date(t*1e3).toLocaleDateString(e,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function yt(t){let e=t.endsWith("/")?t.slice(0,-1):t,n=e.split("/");return n[n.length-1]||e}function Oe(t,e,n,l){let r=n.toLowerCase();if(yt(t.path).toLowerCase().includes(r))return!0;if(t.kind==="directory"){let s=l.get(He(e,t.path));if(s)return s.some(c=>Oe(c,e,n,l))}return!1}function jt(t,e,n,l){return n.trim()?t.filter(r=>Oe(r,e,n,l)):t}var Ka=t=>{let e=(0,Me.c)(36),{namespace:n,protocol:l,rootPath:r,backendType:s,prefix:c,depth:o,locale:h,searchValue:i,onOpenFile:f}=t,{entriesByPath:x}=fe(),{entries:j,isPending:g,error:m}=qe(n,c);if(g){let p;e[0]===o?p=e[1]:(p=U(o),e[0]=o,e[1]=p);let b;e[2]===Symbol.for("react.memo_cache_sentinel")?(b=(0,a.jsx)(ke,{className:"h-3 w-3 animate-spin"}),e[2]=b):b=e[2];let y;return e[3]===p?y=e[4]:(y=(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-xs text-muted-foreground",style:p,children:[b,"Loading..."]}),e[3]=p,e[4]=y),y}if(m){let p;e[5]===o?p=e[6]:(p=U(o),e[5]=o,e[6]=p);let b;return e[7]!==m.message||e[8]!==p?(b=(0,a.jsxs)("div",{className:"py-1 text-xs text-destructive",style:p,children:["Failed to load: ",m.message]}),e[7]=m.message,e[8]=p,e[9]=b):b=e[9],b}if(j.length===0){let p;e[10]===o?p=e[11]:(p=U(o),e[10]=o,e[11]=p);let b;return e[12]===p?b=e[13]:(b=(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:p,children:"Empty"}),e[12]=p,e[13]=b),b}let N;if(e[14]!==s||e[15]!==j||e[16]!==o||e[17]!==x||e[18]!==h||e[19]!==n||e[20]!==f||e[21]!==l||e[22]!==r||e[23]!==i){let p=jt(j,n,i,x),b;e[25]!==s||e[26]!==o||e[27]!==h||e[28]!==n||e[29]!==f||e[30]!==l||e[31]!==r||e[32]!==i?(b=y=>(0,a.jsx)(bt,{entry:y,namespace:n,protocol:l,rootPath:r,backendType:s,depth:o,locale:h,searchValue:i,onOpenFile:f},y.path),e[25]=s,e[26]=o,e[27]=h,e[28]=n,e[29]=f,e[30]=l,e[31]=r,e[32]=i,e[33]=b):b=e[33],N=p.map(b),e[14]=s,e[15]=j,e[16]=o,e[17]=x,e[18]=h,e[19]=n,e[20]=f,e[21]=l,e[22]=r,e[23]=i,e[24]=N}else N=e[24];let v;return e[34]===N?v=e[35]:(v=(0,a.jsx)(a.Fragment,{children:N}),e[34]=N,e[35]=v),v},bt=({entry:t,namespace:e,protocol:n,rootPath:l,backendType:r,depth:s,locale:c,searchValue:o,onOpenFile:h})=>{var w;let[i,f]=(0,z.useState)(!1),{entriesByPath:x}=fe(),j=lt(),g=t.kind==="directory",m=yt(t.path),N=!!o.trim(),v=g&&N&&m.toLowerCase().includes(o.trim().toLowerCase()),p=g&&N&&!!((w=x.get(He(e,t.path)))!=null&&w.some(u=>Oe(u,e,o,x))),b=i||p,y=(0,z.useCallback)(async()=>{try{let u=await je.request({namespace:e,path:t.path});if(u.error){A({title:"Download failed",description:u.error,variant:"danger"});return}u.url&&be(u.url,u.filename??"download")}catch(u){ge.error("Failed to download storage entry",u),A({title:"Download failed",description:String(u),variant:"danger"})}},[e,t.path]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(rt,{className:W("text-xs flex items-center gap-1.5 cursor-pointer rounded-none group h-6.5",g&&"font-medium"),style:U(s),value:`${e}:${t.path}`,onSelect:()=>{g?f(!b):h({entry:t,namespace:e,protocol:n,backendType:r})},children:[g?(0,a.jsx)(Pe,{isExpanded:b,className:"h-3 w-3"}):(0,a.jsx)("span",{className:"w-3 shrink-0"}),g?(0,a.jsx)(na,{className:W("h-3.5 w-3.5 shrink-0",Ze.directory)}):Ye(m),(0,a.jsx)("span",{className:"truncate flex-1 text-left",children:m}),(0,a.jsxs)("div",{className:"flex items-center",children:[t.size>0&&(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground pr-2 opacity-0 group-hover:opacity-100 transition-opacity tabular-nums",children:De(t.size,c)}),t.lastModified!=null&&(0,a.jsx)(R,{content:`Last modified: ${new Date(t.lastModified*1e3).toLocaleString()}`,children:(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground pr-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap",children:Ga(t.lastModified,c)})}),(0,a.jsxs)(Je,{children:[(0,a.jsx)(Ge,{asChild:!0,children:(0,a.jsx)(it,{iconClassName:"h-3 w-3",onClick:u=>u.stopPropagation()})}),(0,a.jsxs)(Ke,{align:"end",onClick:u=>u.stopPropagation(),onCloseAutoFocus:u=>u.preventDefault(),children:[!g&&(0,a.jsxs)(O,{onSelect:()=>h({entry:t,namespace:e,protocol:n,backendType:r}),children:[(0,a.jsx)(xt,{className:"h-3.5 w-3.5 mr-2"}),"View"]}),(0,a.jsxs)(O,{onSelect:async()=>{await re(t.path),A({title:"Copied to clipboard"})},children:[(0,a.jsx)(we,{className:Se}),"Copy path"]}),!g&&(0,a.jsxs)(O,{onSelect:()=>y(),children:[(0,a.jsx)(Ne,{className:"h-3.5 w-3.5 mr-2"}),"Download"]}),(0,a.jsx)(ne,{}),gt.map(u=>{let d=u.getCode({variableName:e,protocol:n,entry:t,backendType:r});if(d===null)return null;let k=u.icon;return(0,a.jsxs)(O,{onSelect:()=>j(d),children:[(0,a.jsx)(k,{className:Se}),u.label]},u.id)})]})]})]})]}),g&&b&&(0,a.jsx)(Ka,{namespace:e,protocol:n,rootPath:l,backendType:r,prefix:t.path,depth:s+1,locale:c,searchValue:v?"":o,onOpenFile:h})]})},Ja=t=>{let e=(0,Me.c)(43),{namespace:n,locale:l,searchValue:r,onOpenFile:s}=t,[c,o]=(0,z.useState)(!0),{entriesByPath:h}=fe(),{clearNamespaceCache:i}=Jt(),f=n.name??n.displayName,{entries:x,isPending:j,error:g,refetch:m}=qe(f),N;e[0]!==i||e[1]!==f||e[2]!==m?(N=y=>{y.stopPropagation(),i(f),m()},e[0]=i,e[1]=f,e[2]=m,e[3]=N):N=e[3];let v=N,p=j?n.storageEntries:x,b;if(e[4]!==p||e[5]!==h||e[6]!==g||e[7]!==v||e[8]!==c||e[9]!==j||e[10]!==l||e[11]!==n.backendType||e[12]!==n.displayName||e[13]!==n.name||e[14]!==n.protocol||e[15]!==n.rootPath||e[16]!==f||e[17]!==s||e[18]!==r){let y=jt(p,f,r,h),w;e[20]===c?w=e[21]:(w=()=>o(!c),e[20]=c,e[21]=w);let u;e[22]===c?u=e[23]:(u=(0,a.jsx)(Pe,{isExpanded:c,className:"h-3 w-3"}),e[22]=c,e[23]=u);let d;e[24]===n.protocol?d=e[25]:(d=(0,a.jsx)(Lt,{protocol:n.protocol}),e[24]=n.protocol,e[25]=d);let k;e[26]===n.displayName?k=e[27]:(k=(0,a.jsx)("span",{children:n.displayName}),e[26]=n.displayName,e[27]=k);let S;e[28]===n.name?S=e[29]:(S=n.name&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground font-normal",children:["(",(0,a.jsx)(Ma,{variableName:n.name}),")"]}),e[28]=n.name,e[29]=S);let F;e[30]===v?F=e[31]:(F=(0,a.jsx)(ot,{onClick:v,tooltip:"Refresh storage connection",className:"p-0",iconClassName:"h-3 w-3"}),e[30]=v,e[31]=F);let P=n.rootPath||"(root)",_;e[32]===P?_=e[33]:(_=(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground font-normal tabular-nums ml-auto",children:P}),e[32]=P,e[33]=_);let D;e[34]!==n.name||e[35]!==_||e[36]!==w||e[37]!==u||e[38]!==d||e[39]!==k||e[40]!==S||e[41]!==F?(D=(0,a.jsxs)(rt,{value:n.name,onSelect:w,className:"flex flex-row font-semibold h-7 text-xs gap-1.5 bg-(--slate-2) text-muted-foreground rounded-none",children:[u,d,k,S,F,_]}),e[34]=n.name,e[35]=_,e[36]=w,e[37]=u,e[38]=d,e[39]=k,e[40]=S,e[41]=F,e[42]=D):D=e[42],b=(0,a.jsxs)(a.Fragment,{children:[D,c&&(0,a.jsxs)(a.Fragment,{children:[j&&p.length===0&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-xs text-muted-foreground",style:U(1),children:[(0,a.jsx)(ke,{className:"h-3 w-3 animate-spin"}),"Loading..."]}),g&&p.length===0&&(0,a.jsx)(Da,{error:g,style:U(1),className:"py-1 text-xs h-auto overflow-auto max-h-32 items-start",showIcon:!1}),!j&&p.length===0&&!g&&(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:U(1),children:"No entries"}),r&&y.length===0&&p.length>0&&(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:U(1),children:"No matches"}),y.map(I=>(0,a.jsx)(bt,{entry:I,namespace:f,protocol:n.protocol,rootPath:n.rootPath,backendType:n.backendType,depth:1,locale:l,searchValue:r,onOpenFile:s},I.path))]})]}),e[4]=p,e[5]=h,e[6]=g,e[7]=v,e[8]=c,e[9]=j,e[10]=l,e[11]=n.backendType,e[12]=n.displayName,e[13]=n.name,e[14]=n.protocol,e[15]=n.rootPath,e[16]=f,e[17]=s,e[18]=r,e[19]=b}else b=e[19];return b};const Ya=()=>{let t=(0,Me.c)(31),{namespaces:e}=fe(),{locale:n}=at(),[l,r]=(0,z.useState)(""),[s,c]=(0,z.useState)(null),o=!!l.trim();if(e.length===0){let w;t[0]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)("span",{children:["Create an obstore or fsspec connection in your notebook. See the"," ",(0,a.jsx)("a",{className:"text-link",href:"https://docs.marimo.io/guides/working_with_data/remote_storage/#quick-start",target:"_blank",rel:"noopener noreferrer",children:"docs"}),"."]}),t[0]=w):w=t[0];let u;return t[1]===Symbol.for("react.memo_cache_sentinel")?(u=(0,a.jsx)(za,{title:"No storage connected",description:w,action:(0,a.jsx)(Le,{defaultTab:"storage",children:(0,a.jsxs)($,{variant:"outline",size:"sm",children:["Add remote storage",(0,a.jsx)(et,{className:"h-4 w-4 ml-2"})]})}),icon:(0,a.jsx)(Ie,{className:"h-8 w-8"})}),t[1]=u):u=t[1],u}let h;t[2]===s?h=t[3]:(h=s&&(0,a.jsx)(qa,{entry:s.entry,namespace:s.namespace,protocol:s.protocol,backendType:s.backendType,onBack:()=>c(null)}),t[2]=s,t[3]=h);let i=s&&"hidden",f;t[4]===i?f=t[5]:(f=W("border-b bg-background rounded-none h-full pb-10 overflow-auto outline-hidden scrollbar-thin",i),t[4]=i,t[5]=f);let x;t[6]===l?x=t[7]:(x=(0,a.jsx)(ka,{placeholder:"Search entries...",className:"h-6 m-1",value:l,onValueChange:r,rootClassName:"flex-1 border-b-0"}),t[6]=l,t[7]=x);let j;t[8]===o?j=t[9]:(j=o&&(0,a.jsx)($,{variant:"text",size:"xs",className:"float-right border-none px-2 m-0 h-full",onClick:()=>r(""),children:(0,a.jsx)(Qt,{className:"h-4 w-4"})}),t[8]=o,t[9]=j);let g;t[10]===Symbol.for("react.memo_cache_sentinel")?(g=(0,a.jsx)(R,{content:"Filters loaded entries only. Expand directories to include their contents in the search.",delayDuration:200,children:(0,a.jsx)(ta,{className:"h-3.5 w-3.5 shrink-0 cursor-help text-muted-foreground hover:text-foreground mr-2"})}),t[10]=g):g=t[10];let m;t[11]===Symbol.for("react.memo_cache_sentinel")?(m=(0,a.jsx)(Le,{defaultTab:"storage",children:(0,a.jsx)($,{variant:"ghost",size:"sm",className:"px-2 border-0 border-l border-muted-background rounded-none focus-visible:ring-0 focus-visible:ring-offset-0",children:(0,a.jsx)(et,{className:"h-4 w-4"})})}),t[11]=m):m=t[11];let N;t[12]!==x||t[13]!==j?(N=(0,a.jsxs)("div",{className:"flex items-center w-full border-b",children:[x,j,g,m]}),t[12]=x,t[13]=j,t[14]=N):N=t[14];let v;if(t[15]!==n||t[16]!==e||t[17]!==l){let w;t[19]!==n||t[20]!==l?(w=u=>(0,a.jsx)(Ja,{namespace:u,locale:n,searchValue:l,onOpenFile:c},u.name??u.displayName),t[19]=n,t[20]=l,t[21]=w):w=t[21],v=e.map(w),t[15]=n,t[16]=e,t[17]=l,t[18]=v}else v=t[18];let p;t[22]===v?p=t[23]:(p=(0,a.jsx)(Fa,{className:"flex flex-col",children:v}),t[22]=v,t[23]=p);let b;t[24]!==f||t[25]!==N||t[26]!==p?(b=(0,a.jsxs)(Ca,{className:f,shouldFilter:!1,children:[N,p]}),t[24]=f,t[25]=N,t[26]=p,t[27]=b):b=t[27];let y;return t[28]!==h||t[29]!==b?(y=(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[h,b]}),t[28]=h,t[29]=b,t[30]=y):y=t[30],y};var vt=ae(),wt=(0,z.createContext)(null);function Za(){return(0,z.useContext)(wt)??void 0}var Qa=t=>{let e=(0,vt.c)(3),{children:n}=t,l=ja(),r;return e[0]!==n||e[1]!==l?(r=(0,a.jsx)(wt.Provider,{value:l,children:n}),e[0]=n,e[1]=l,e[2]=r):r=e[2],r};const Xa=t=>{let e=(0,vt.c)(5),{children:n}=t,[l,r]=(0,z.useState)(null),s;e[0]!==n||e[1]!==l?(s=l&&(0,a.jsx)(ya,{backend:ba,options:{rootElement:l},children:(0,a.jsx)(Qa,{children:n})}),e[0]=n,e[1]=l,e[2]=s):s=e[2];let c;return e[3]===s?c=e[4]:(c=(0,a.jsx)("div",{ref:r,className:"contents",children:s}),e[3]=s,e[4]=c),c};var $e=new Map;const en=({file:t,onOpenNotebook:e})=>{let{sendFileDetails:n,sendUpdateFile:l}=ye(),r=se(Ht),s=se(Ve),c=se(It),[o,h]=(0,z.useState)(""),{data:i,isPending:f,error:x,setData:j,refetch:g}=_e(async()=>{let d=await n({path:t.path}),k=d.contents||"";return h($e.get(t.path)||k),d},[t.path]),m=async()=>{o!==(i==null?void 0:i.contents)&&await l({path:t.path,contents:o}).then(d=>{d.success&&(j(k=>({...k,contents:o})),h(o))})},N=(0,z.useRef)(o);if(N.current=o,(0,z.useEffect)(()=>()=>{if(!(i!=null&&i.contents))return;let d=N.current;d===i.contents?$e.delete(t.path):$e.set(t.path,d)},[t.path,i==null?void 0:i.contents]),x)return(0,a.jsx)(st,{error:x});if(f||!i)return null;let v=i.mimeType||"text/plain",p=v in Gt,b=c&&i.file.isMarimoFile&&(t.path===c||t.path.endsWith(`/${c}`));if(!i.contents&&!p)return(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2 p-6",children:[(0,a.jsx)("div",{className:"font-bold text-muted-foreground",children:"Name"}),(0,a.jsx)("div",{children:i.file.name}),(0,a.jsx)("div",{className:"font-bold text-muted-foreground",children:"Type"}),(0,a.jsx)("div",{children:v})]});let y=(0,a.jsx)(ut,{filename:i.file.name,onRefresh:g,onDownload:s?void 0:()=>{if(pe(v)){be(ea(i.contents,v),i.file.name);return}We(new Blob([i.contents||o],{type:v}),i.file.name)},actions:(0,a.jsxs)(a.Fragment,{children:[t.isMarimoFile&&!me()&&(0,a.jsx)(R,{content:"Open notebook",children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:d=>e(d),children:(0,a.jsx)(ve,{className:"h-3.5 w-3.5"})})}),!pe(v)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(R,{content:"Copy contents to clipboard",children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:async()=>{await re(o)},children:(0,a.jsx)(we,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(R,{content:Sa("global.save"),children:(0,a.jsx)($,{variant:"text",size:"xs",onClick:m,disabled:o===i.contents,children:(0,a.jsx)(ia,{className:"h-3.5 w-3.5"})})})]})]})}),w=pe(v),u=!w&&v!=="text/csv";return(0,a.jsxs)(a.Fragment,{children:[y,u&&b&&(0,a.jsxs)(Na,{variant:"warning",className:"rounded-none",children:[(0,a.jsx)(ca,{className:"h-4 w-4"}),(0,a.jsx)(wa,{children:"Editing the notebook file directly while running in marimo's editor may cause unintended changes. Please use with caution."})]}),(0,a.jsx)(Be,{mimeType:v,contents:w?void 0:u?o:i.contents??void 0,mediaSource:w?{base64:i.contents,mime:v}:void 0,readOnly:!u,onChange:h,extensions:[Wt.of([{key:r.getHotkey("global.save").key,stopPropagation:!0,run:()=>o===i.contents?!1:(m(),!0)}])]})]})};var tn=class{constructor(t){V(this,"delegate",new Fe([]));V(this,"rootPath","");V(this,"onChange",Vt.NOOP);V(this,"path",new Ce("/"));V(this,"initialize",async t=>{if(this.onChange=t,this.delegate.data.length===0)try{let e=await this.callbacks.listFiles({path:this.rootPath});this.delegate=new Fe(e.files),this.rootPath=e.root,this.path=Ce.guessDeliminator(e.root)}catch(e){A({title:"Failed",description:fa(e)})}this.onChange(this.delegate.data)});V(this,"refreshAll",async t=>{let e=[this.rootPath,...t.map(l=>{var r;return(r=this.delegate.find(l))==null?void 0:r.data.path})].filter(Boolean),n=await Promise.all(e.map(l=>this.callbacks.listFiles({path:l}).catch(()=>({files:[]}))));for(let[l,r]of e.entries()){let s=n[l];r===this.rootPath?this.delegate=new Fe(s.files):this.delegate.update({id:r,changes:{children:s.files}})}this.onChange(this.delegate.data)});V(this,"relativeFromRoot",t=>{let e=this.rootPath.endsWith(this.path.deliminator)?this.rootPath:`${this.rootPath}${this.path.deliminator}`;return t.startsWith(e)?t.slice(e.length):t});V(this,"handleResponse",t=>t.success?t:(A({title:"Failed",description:t.message}),null));this.callbacks=t}async expand(t){let e=this.delegate.find(t);if(!e||!e.data.isDirectory)return!1;if(e.children&&e.children.length>0)return!0;let n=await this.callbacks.listFiles({path:e.data.path});return this.delegate.update({id:t,changes:{children:n.files}}),this.onChange(this.delegate.data),!0}async rename(t,e){let n=this.delegate.find(t);if(!n)return;let l=n.data.path,r=this.path.join(this.path.dirname(l),e);await this.callbacks.renameFileOrFolder({path:l,newPath:r}).then(this.handleResponse),this.delegate.update({id:t,changes:{name:e,path:r}}),this.onChange(this.delegate.data),await this.refreshAll([r])}async move(t,e){var l;let n=e?((l=this.delegate.find(e))==null?void 0:l.data.path)??e:this.rootPath;await Promise.all(t.map(r=>{this.delegate.move({id:r,parentId:e,index:0});let s=this.delegate.find(r);if(!s)return Promise.resolve();let c=this.path.join(n,this.path.basename(s.data.path));return this.delegate.update({id:r,changes:{path:c}}),this.callbacks.renameFileOrFolder({path:s.data.path,newPath:c}).then(this.handleResponse)})),this.onChange(this.delegate.data),await this.refreshAll([n])}async createFile(t,e,n="file"){var s;let l=e?((s=this.delegate.find(e))==null?void 0:s.data.path)??e:this.rootPath,r=await this.callbacks.createFileOrFolder({path:l,type:n,name:t}).then(this.handleResponse);r!=null&&r.info&&(this.delegate.create({parentId:e,index:0,data:r.info}),this.onChange(this.delegate.data),await this.refreshAll([l]))}async createFolder(t,e){var r;let n=e?((r=this.delegate.find(e))==null?void 0:r.data.path)??e:this.rootPath,l=await this.callbacks.createFileOrFolder({path:n,type:"directory",name:t}).then(this.handleResponse);l!=null&&l.info&&(this.delegate.create({parentId:e,index:0,data:l.info}),this.onChange(this.delegate.data),await this.refreshAll([n]))}async delete(t){let e=this.delegate.find(t);e&&(await this.callbacks.deleteFileOrFolder({path:e.data.path}).then(this.handleResponse),this.delegate.drop({id:t}),this.onChange(this.delegate.data))}};const Nt=Re(t=>{let e=t(Kt);return Bt(e,"no requestClientAtom set"),new tn({listFiles:e.sendListFiles,createFileOrFolder:e.sendCreateFileOrFolder,deleteFileOrFolder:e.sendDeleteFileOrFolder,renameFileOrFolder:e.sendRenameFileOrFolder})}),an=Re({});async function nn(){await $t.get(Nt).refreshAll([])}var q=" ";const kt={directory:t=>`os.listdir("${t}")`,python:t=>`with open("${t}", "r") as _f:
11
- ${q}...
12
- `,json:t=>`with open("${t}", "r") as _f:
13
- ${q}_data = json.load(_f)
14
- `,code:t=>`with open("${t}", "r") as _f:
15
- ${q}...
16
- `,text:t=>`with open("${t}", "r") as _f:
17
- ${q}...
18
- `,image:t=>`mo.image("${t}")`,audio:t=>`mo.audio("${t}")`,video:t=>`mo.video("${t}")`,pdf:t=>`with open("${t}", "rb") as _f:
19
- ${q}...
20
- `,zip:t=>`with open("${t}", "rb") as _f:
21
- ${q}...
22
- `,data:t=>`with open("${t}", "r") as _f:
23
- ${q}...
24
- `,unknown:t=>`with open("${t}", "r") as _f:
25
- ${q}...
26
- `};var sn=ae(),rn=1024*1024*100;function Ct(t){let e=(0,sn.c)(7),n;e[0]===t?n=e[1]:(n=t===void 0?{}:t,e[0]=t,e[1]=n);let l=n,{sendCreateFileOrFolder:r}=ye(),s;e[2]===r?s=e[3]:(s=async o=>{if(o.length===0)return;let h=o.length===1;await Xt(h?"Uploading file...":"Uploading files...",async i=>{i.addTotal(o.length);for(let f of o){let x=mn(hn(f)),j="";x&&(j=Ce.guessDeliminator(x).dirname(x));let g=(await xa(f)).split(",")[1];await r({path:j,type:"file",name:f.name,contents:g}),i.increment(1)}await nn()},{title:h?"File uploaded":`${o.length} files uploaded`})},e[2]=r,e[3]=s);let c;return e[4]!==l||e[5]!==s?(c={multiple:!0,maxSize:rn,onError:dn,onDropRejected:ln,onDrop:s,...l},e[4]=l,e[5]=s,e[6]=c):c=e[6],ma(c)}function ln(t){A({title:"File upload failed",description:(0,a.jsx)("div",{className:"flex flex-col gap-1",children:t.map(on)}),variant:"danger"})}function on(t){return(0,a.jsxs)("div",{children:[t.file.name," (",t.errors.map(cn).join(", "),")"]},t.file.name)}function cn(t){return t.message}function dn(t){ge.error(t),A({title:"File upload failed",description:t.message,variant:"danger"})}function hn(t){if(t.webkitRelativePath)return t.webkitRelativePath;if("path"in t&&typeof t.path=="string")return t.path;if("relativePath"in t&&typeof t.relativePath=="string")return t.relativePath}function mn(t){if(t)return t.replace(/^\/+/,"")}var le=ae(),pn=Ee("marimo:showHiddenFiles",!0,Ae,{getOnInit:!0}),Ft=z.createContext(null);const fn=t=>{let e=(0,le.c)(72),{height:n}=t,l=(0,z.useRef)(null),r=Za(),[s]=he(Nt),c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];let[o,h]=(0,z.useState)(c),[i,f]=(0,z.useState)(null),[x,j]=he(pn),{openPrompt:g}=nt(),[m,N]=he(an),v;e[1]===s?v=e[2]:(v=()=>s.initialize(h),e[1]=s,e[2]=v);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[],e[3]=p):p=e[3];let{isPending:b,error:y}=_e(v,p),w;e[4]!==m||e[5]!==s?(w=()=>s.refreshAll(Object.keys(m).filter(C=>m[C])),e[4]=m,e[5]=s,e[6]=w):w=e[6];let u=L(w),d;e[7]!==j||e[8]!==x?(d=()=>{j(!x)},e[7]=j,e[8]=x,e[9]=d):d=e[9];let k=L(d),S;e[10]!==g||e[11]!==s?(S=async()=>{g({title:"Folder name",onConfirm:async C=>{s.createFolder(C,null)}})},e[10]=g,e[11]=s,e[12]=S):S=e[12];let F=L(S),P;e[13]!==g||e[14]!==s?(P=async()=>{g({title:"File name",onConfirm:async C=>{s.createFile(C,null)}})},e[13]=g,e[14]=s,e[15]=P):P=e[15];let _=L(P),D;e[16]!==g||e[17]!==s?(D=async()=>{g({title:"Notebook name",onConfirm:async C=>{s.createFile(C,null,"notebook")}})},e[16]=g,e[17]=s,e[18]=D):D=e[18];let I=L(D),M;e[19]===N?M=e[20]:(M=()=>{var C;(C=l.current)==null||C.closeAll(),N({})},e[19]=N,e[20]=M);let B=L(M),ie;e[21]!==o||e[22]!==x?(ie=St(o,x),e[21]=o,e[22]=x,e[23]=ie):ie=e[23];let xe=ie;if(b){let C;return e[24]===Symbol.for("react.memo_cache_sentinel")?(C=(0,a.jsx)(la,{size:"medium",centered:!0}),e[24]=C):C=e[24],C}if(y){let C;return e[25]===y?C=e[26]:(C=(0,a.jsx)(st,{error:y}),e[25]=y,e[26]=C),C}if(i){let C;e[27]===Symbol.for("react.memo_cache_sentinel")?(C=()=>f(null),e[27]=C):C=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=(0,a.jsx)($,{onClick:C,"data-testid":"file-explorer-back-button",variant:"text",size:"xs",className:"mb-0",children:(0,a.jsx)(Ue,{size:16})}),e[28]=T):T=e[28];let E;e[29]===i.name?E=e[30]:(E=(0,a.jsxs)("div",{className:"flex items-center pl-1 pr-3 shrink-0 border-b justify-between",children:[T,(0,a.jsx)("span",{className:"font-bold",children:i.name})]}),e[29]=i.name,e[30]=E);let ee;e[31]!==i.path||e[32]!==s?(ee=zt=>_t(zt,s.relativeFromRoot(i.path)),e[31]=i.path,e[32]=s,e[33]=ee):ee=e[33];let te;e[34]!==i||e[35]!==ee?(te=(0,a.jsx)(z.Suspense,{children:(0,a.jsx)(en,{onOpenNotebook:ee,file:i})}),e[34]=i,e[35]=ee,e[36]=te):te=e[36];let de;return e[37]!==E||e[38]!==te?(de=(0,a.jsxs)(a.Fragment,{children:[E,te]}),e[37]=E,e[38]=te,e[39]=de):de=e[39],de}let G;e[40]!==B||e[41]!==_||e[42]!==F||e[43]!==I||e[44]!==k||e[45]!==u||e[46]!==s?(G=(0,a.jsx)(un,{onRefresh:u,onHidden:k,onCreateFile:_,onCreateNotebook:I,onCreateFolder:F,onCollapseAll:B,tree:s}),e[40]=B,e[41]=_,e[42]=F,e[43]=I,e[44]=k,e[45]=u,e[46]=s,e[47]=G):G=e[47];let ue=n-33,K,J,Y;e[48]===s?(K=e[49],J=e[50],Y=e[51]):(K=async C=>{let{ids:T}=C;for(let E of T)await s.delete(E)},J=async C=>{let{id:T,name:E}=C;await s.rename(T,E)},Y=async C=>{let{dragIds:T,parentId:E}=C;await s.move(T,E)},e[48]=s,e[49]=K,e[50]=J,e[51]=Y);let oe;e[52]===Symbol.for("react.memo_cache_sentinel")?(oe=C=>{let T=C[0];T&&(T.data.isDirectory||f(T.data))},e[52]=oe):oe=e[52];let Z;e[53]!==m||e[54]!==N||e[55]!==s?(Z=async C=>{if(await s.expand(C)){let T=m[C]??!1;N({...m,[C]:!T})}},e[53]=m,e[54]=N,e[55]=s,e[56]=Z):Z=e[56];let Q;e[57]!==r||e[58]!==m||e[59]!==ue||e[60]!==K||e[61]!==J||e[62]!==Y||e[63]!==Z||e[64]!==xe?(Q=(0,a.jsx)(va,{width:"100%",ref:l,height:ue,className:"h-full",data:xe,initialOpenState:m,openByDefault:!1,dndManager:r,renderCursor:wn,disableDrop:Nn,onDelete:K,onRename:J,onMove:Y,onSelect:oe,onToggle:Z,padding:15,rowHeight:30,indent:xn,overscanCount:1e3,disableMultiSelection:!0,children:jn}),e[57]=r,e[58]=m,e[59]=ue,e[60]=K,e[61]=J,e[62]=Y,e[63]=Z,e[64]=xe,e[65]=Q):Q=e[65];let X;e[66]!==Q||e[67]!==s?(X=(0,a.jsx)(Ft,{value:s,children:Q}),e[66]=Q,e[67]=s,e[68]=X):X=e[68];let ce;return e[69]!==G||e[70]!==X?(ce=(0,a.jsxs)(a.Fragment,{children:[G,X]}),e[69]=G,e[70]=X,e[71]=ce):ce=e[71],ce};var xn=15,un=t=>{let e=(0,le.c)(37),{onRefresh:n,onHidden:l,onCreateFile:r,onCreateNotebook:s,onCreateFolder:c,onCollapseAll:o}=t,h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={noDrag:!0,noDragEventsBubbling:!0},e[0]=h):h=e[0];let{getRootProps:i,getInputProps:f}=Ct(h),x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=(0,a.jsx)(mt,{size:16}),e[1]=x):x=e[1];let j;e[2]===s?j=e[3]:(j=(0,a.jsx)(R,{content:"Add notebook",children:(0,a.jsx)($,{"data-testid":"file-explorer-add-notebook-button",onClick:s,variant:"text",size:"xs",children:x})}),e[2]=s,e[3]=j);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=(0,a.jsx)(Qe,{size:16}),e[4]=g):g=e[4];let m;e[5]===r?m=e[6]:(m=(0,a.jsx)(R,{content:"Add file",children:(0,a.jsx)($,{"data-testid":"file-explorer-add-file-button",onClick:r,variant:"text",size:"xs",children:g})}),e[5]=r,e[6]=m);let N;e[7]===Symbol.for("react.memo_cache_sentinel")?(N=(0,a.jsx)(pt,{size:16}),e[7]=N):N=e[7];let v;e[8]===c?v=e[9]:(v=(0,a.jsx)(R,{content:"Add folder",children:(0,a.jsx)($,{"data-testid":"file-explorer-add-folder-button",onClick:c,variant:"text",size:"xs",children:N})}),e[8]=c,e[9]=v);let p;e[10]===i?p=e[11]:(p=i({}),e[10]=i,e[11]=p);let b,y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=qt({variant:"text",size:"xs"}),b=(0,a.jsx)(da,{size:16}),e[12]=b,e[13]=y):(b=e[12],y=e[13]);let w;e[14]===p?w=e[15]:(w=(0,a.jsx)(R,{content:"Upload file",children:(0,a.jsx)("button",{"data-testid":"file-explorer-upload-button",...p,className:y,children:b})}),e[14]=p,e[15]=w);let u;e[16]===f?u=e[17]:(u=f({}),e[16]=f,e[17]=u);let d;e[18]===u?d=e[19]:(d=(0,a.jsx)("input",{...u,type:"file"}),e[18]=u,e[19]=d);let k;e[20]===n?k=e[21]:(k=(0,a.jsx)(ot,{"data-testid":"file-explorer-refresh-button",onClick:n}),e[20]=n,e[21]=k);let S;e[22]===Symbol.for("react.memo_cache_sentinel")?(S=(0,a.jsx)(aa,{size:16}),e[22]=S):S=e[22];let F;e[23]===l?F=e[24]:(F=(0,a.jsx)(R,{content:"Toggle hidden files",children:(0,a.jsx)($,{"data-testid":"file-explorer-hidden-files-button",onClick:l,variant:"text",size:"xs",children:S})}),e[23]=l,e[24]=F);let P;e[25]===Symbol.for("react.memo_cache_sentinel")?(P=(0,a.jsx)(Aa,{size:16}),e[25]=P):P=e[25];let _;e[26]===o?_=e[27]:(_=(0,a.jsx)(R,{content:"Collapse all folders",children:(0,a.jsx)($,{"data-testid":"file-explorer-collapse-button",onClick:o,variant:"text",size:"xs",children:P})}),e[26]=o,e[27]=_);let D;return e[28]!==w||e[29]!==d||e[30]!==k||e[31]!==F||e[32]!==_||e[33]!==j||e[34]!==m||e[35]!==v?(D=(0,a.jsxs)("div",{className:"flex items-center justify-end px-2 shrink-0 border-b",children:[j,m,v,w,d,k,F,_]}),e[28]=w,e[29]=d,e[30]=k,e[31]=F,e[32]=_,e[33]=j,e[34]=m,e[35]=v,e[36]=D):D=e[36],D},gn=t=>{let e=(0,le.c)(9),{node:n,onOpenMarimoFile:l}=t,r;e[0]===n?r=e[1]:(r=o=>{n.data.isDirectory||(o.stopPropagation(),n.select())},e[0]=n,e[1]=r);let s;e[2]!==n.data.isMarimoFile||e[3]!==l?(s=n.data.isMarimoFile&&!me()&&(0,a.jsxs)("span",{className:"shrink-0 ml-2 text-sm hidden group-hover:inline hover:underline",onClick:l,children:["open ",(0,a.jsx)(ve,{className:"inline ml-1",size:12})]}),e[2]=n.data.isMarimoFile,e[3]=l,e[4]=s):s=e[4];let c;return e[5]!==n.data.name||e[6]!==r||e[7]!==s?(c=(0,a.jsxs)("span",{className:"flex-1 overflow-hidden text-ellipsis",onClick:r,children:[n.data.name,s]}),e[5]=n.data.name,e[6]=r,e[7]=s,e[8]=c):c=e[8],c},yn=t=>{let e=(0,le.c)(10),{node:n}=t,l=(0,z.useRef)(null),r,s;e[0]===n.data.name?(r=e[1],s=e[2]):(r=()=>{var i,f;(i=l.current)==null||i.focus(),(f=l.current)==null||f.setSelectionRange(0,n.data.name.lastIndexOf("."))},s=[n.data.name],e[0]=n.data.name,e[1]=r,e[2]=s),(0,z.useEffect)(r,s);let c,o;e[3]===n?(c=e[4],o=e[5]):(c=()=>n.reset(),o=i=>{i.key==="Escape"&&n.reset(),i.key==="Enter"&&n.submit(i.currentTarget.value)},e[3]=n,e[4]=c,e[5]=o);let h;return e[6]!==n.data.name||e[7]!==c||e[8]!==o?(h=(0,a.jsx)("input",{ref:l,className:"flex-1 bg-transparent border border-border text-muted-foreground",defaultValue:n.data.name,onClick:kn,onBlur:c,onKeyDown:o}),e[6]=n.data.name,e[7]=c,e[8]=o,e[9]=h):h=e[9],h},jn=({node:t,style:e,dragHandle:n})=>{let{openFile:l,sendCreateFileOrFolder:r,sendFileDetails:s}=ye(),c=se(Ve),o=t.data.isDirectory?"directory":sa(t.data.name),h=ra[o],{openConfirm:i,openPrompt:f}=nt(),{createNewCell:x}=Rt(),j=_a(),g=d=>{x({code:d,before:!1,cellId:j??"__end__"})},m=(0,z.use)(Ft),N=async d=>{_t(d,m?m.relativeFromRoot(t.data.path):t.data.path)},v=async d=>{d.stopPropagation(),d.preventDefault(),i({title:"Delete file",description:`Are you sure you want to delete ${t.data.name}?`,confirmAction:(0,a.jsx)(pa,{onClick:async()=>{await t.tree.delete(t.id)},"aria-label":"Confirm",children:"Delete"})})},p=L(async()=>{t.open(),f({title:"Folder name",onConfirm:async d=>{m==null||m.createFolder(d,t.id)}})}),b=L(async()=>{t.open(),f({title:"File name",onConfirm:async d=>{m==null||m.createFile(d,t.id)}})}),y=L(async()=>{t.open(),f({title:"Notebook name",onConfirm:async d=>{m==null||m.createFile(d,t.id,"notebook")}})}),w=L(async()=>{var F;if(!m||t.data.isDirectory)return;let[d,k]=ha(t.data.name),S=`${d}_copy${k}`;try{let P=await s({path:t.data.path}),_=((F=t.parent)==null?void 0:F.data.path)||"";await r({path:_,type:"file",name:S,contents:P.contents?btoa(P.contents):void 0}),await m.refreshAll([_])}catch{A({title:"Failed to duplicate file",description:"Unable to create a duplicate of the file",variant:"danger"})}}),u=()=>{let d=Se;return(0,a.jsxs)(Ke,{align:"end",className:"print:hidden w-[220px]",onClick:k=>k.stopPropagation(),onCloseAutoFocus:k=>k.preventDefault(),children:[!t.data.isDirectory&&(0,a.jsxs)(O,{onSelect:()=>t.select(),children:[(0,a.jsx)(xt,{className:d}),"Open file"]}),!t.data.isDirectory&&!me()&&(0,a.jsxs)(O,{onSelect:()=>{l({path:t.data.path})},children:[(0,a.jsx)(ve,{className:d}),"Open file in external editor"]}),t.data.isDirectory&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(O,{onSelect:()=>y(),children:[(0,a.jsx)(mt,{className:d}),"Create notebook"]}),(0,a.jsxs)(O,{onSelect:()=>b(),children:[(0,a.jsx)(Qe,{className:d}),"Create file"]}),(0,a.jsxs)(O,{onSelect:()=>p(),children:[(0,a.jsx)(pt,{className:d}),"Create folder"]}),(0,a.jsx)(ne,{})]}),(0,a.jsxs)(O,{onSelect:()=>t.edit(),children:[(0,a.jsx)(Ia,{className:d}),"Rename"]}),!t.data.isDirectory&&(0,a.jsxs)(O,{onSelect:w,children:[(0,a.jsx)(we,{className:d}),"Duplicate"]}),(0,a.jsxs)(O,{onSelect:async()=>{await re(t.data.path),A({title:"Copied to clipboard"})},children:[(0,a.jsx)(ft,{className:d}),"Copy path"]}),m&&(0,a.jsxs)(O,{onSelect:async()=>{await re(m.relativeFromRoot(t.data.path)),A({title:"Copied to clipboard"})},children:[(0,a.jsx)(ft,{className:d}),"Copy relative path"]}),(0,a.jsx)(ne,{}),(0,a.jsxs)(O,{onSelect:()=>{let{path:k}=t.data;g(kt[o](k))},children:[(0,a.jsx)(Zt,{className:d}),"Insert snippet for reading file"]}),(0,a.jsxs)(O,{onSelect:async()=>{A({title:"Copied to clipboard",description:"Code to open the file has been copied to your clipboard. You can also drag and drop this file into the editor"});let{path:k}=t.data;await re(kt[o](k))},children:[(0,a.jsx)(Et,{className:d}),"Copy snippet for reading file"]}),t.data.isMarimoFile&&!me()&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ne,{}),(0,a.jsxs)(O,{onSelect:N,children:[(0,a.jsx)(La,{className:d}),"Open notebook"]})]}),(0,a.jsx)(ne,{}),!t.data.isDirectory&&!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(O,{onSelect:async()=>{let k=(await s({path:t.data.path})).contents||"";We(new Blob([k]),t.data.name)},children:[(0,a.jsx)(Ne,{className:d}),"Download"]}),(0,a.jsx)(ne,{})]}),(0,a.jsxs)(O,{onSelect:v,variant:"danger",children:[(0,a.jsx)(oa,{className:d}),"Delete"]})]})};return(0,a.jsxs)("div",{style:e,ref:n,className:W("flex items-center cursor-pointer ml-1 text-muted-foreground whitespace-nowrap group"),draggable:!0,onClick:d=>{d.stopPropagation(),t.data.isDirectory&&t.toggle()},children:[(0,a.jsx)(bn,{node:t}),(0,a.jsxs)("span",{className:W("flex items-center pl-1 py-1 cursor-pointer hover:bg-accent/50 hover:text-accent-foreground rounded-l flex-1 overflow-hidden group",t.willReceiveDrop&&t.data.isDirectory&&"bg-accent/80 hover:bg-accent/80 text-accent-foreground"),children:[t.data.isMarimoFile?(0,a.jsx)($a,{className:"w-5 h-5 shrink-0 mr-2",strokeWidth:1.5}):(0,a.jsx)(h,{className:W("w-5 h-5 shrink-0 mr-2",Ze[o]),strokeWidth:1.5}),t.isEditing?(0,a.jsx)(yn,{node:t}):(0,a.jsx)(gn,{node:t,onOpenMarimoFile:N}),(0,a.jsxs)(Je,{modal:!1,children:[(0,a.jsx)(Ge,{asChild:!0,tabIndex:-1,onClick:d=>d.stopPropagation(),children:(0,a.jsx)(it,{"data-testid":"file-explorer-more-button",iconClassName:"w-5 h-5"})}),u()]})]})]})},bn=t=>{let e=(0,le.c)(3),{node:n}=t;if(!n.data.isDirectory){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)("span",{className:"w-4 h-4 shrink-0"}),e[0]=r):r=e[0],r}let l;return e[1]===n.isOpen?l=e[2]:(l=(0,a.jsx)(Pe,{isExpanded:n.isOpen,className:"w-4 h-4"}),e[1]=n.isOpen,e[2]=l),l};function _t(t,e){t.stopPropagation(),t.preventDefault(),Ta(e)}function St(t,e){if(e)return t;let n=[];for(let l of t){if(vn(l.name))continue;let r=l;if(l.children){let s=St(l.children,e);s!==l.children&&(r={...l,children:s})}n.push(r)}return n}function vn(t){return!!t.startsWith(".")}function wn(){return null}function Nn(t){let{parentNode:e}=t;return!e.data.isDirectory}function kn(t){return t.stopPropagation()}var Pt=ae(),Cn=Ee("marimo:file-explorer-panel:state",{openSections:["files"],hasUserInteracted:!1},Ae),Dt=t=>{let e=(0,Pt.c)(20),{height:n}=t,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={noClick:!0,noKeyboard:!0},e[0]=l):l=e[0];let{getRootProps:r,getInputProps:s,isDragActive:c}=Ct(l),o;e[1]===r?o=e[2]:(o=r(),e[1]=r,e[2]=o);let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=W("flex flex-col overflow-hidden relative"),e[3]=h):h=e[3];let i;e[4]===n?i=e[5]:(i={height:n},e[4]=n,e[5]=i);let f;e[6]===s?f=e[7]:(f=s(),e[6]=s,e[7]=f);let x;e[8]===f?x=e[9]:(x=(0,a.jsx)("input",{...f}),e[8]=f,e[9]=x);let j;e[10]===c?j=e[11]:(j=c&&(0,a.jsx)("div",{className:"absolute inset-0 flex items-center uppercase justify-center text-xl font-bold text-primary/90 bg-accent/85 z-10 border-2 border-dashed border-primary/90 rounded-lg pointer-events-none",children:"Drop files here"}),e[10]=c,e[11]=j);let g;e[12]===n?g=e[13]:(g=(0,a.jsx)(fn,{height:n}),e[12]=n,e[13]=g);let m;return e[14]!==o||e[15]!==i||e[16]!==x||e[17]!==j||e[18]!==g?(m=(0,a.jsx)(Xa,{children:(0,a.jsxs)("div",{...o,className:h,style:i,children:[x,j,g]})}),e[14]=o,e[15]=i,e[16]=x,e[17]=j,e[18]=g,e[19]=m):m=e[19],m},Fn=33,_n=()=>{let t=(0,Pt.c)(41),{ref:e,height:n}=Pa(),l=n===void 0?500:n,[r,s]=he(Cn),c=se(Yt).length,o;e:{if(!r.hasUserInteracted&&c>0){if(r.openSections.includes("remote-storage")){o=r.openSections;break e}let M;t[0]===r.openSections?M=t[1]:(M=[...r.openSections,"remote-storage"],t[0]=r.openSections,t[1]=M),o=M;break e}o=r.openSections}let h=o,i;t[2]===s?i=t[3]:(i=M=>{s({openSections:M,hasUserInteracted:!0})},t[2]=s,t[3]=i);let f=i,x=l-Fn*2,j;t[4]===h?j=t[5]:(j=h.includes("remote-storage"),t[4]=h,t[5]=j);let g=j,m;t[6]!==h||t[7]!==g?(m=g&&h.includes("files"),t[6]=h,t[7]=g,t[8]=m):m=t[8];let N=m,v;t[9]!==x||t[10]!==N?(v=N?Math.round(x*.4):x,t[9]=x,t[10]=N,t[11]=v):v=t[11];let p=v,b=Math.max(200,N?x-p:x);if(!At("storage_inspector")){let M;t[12]===l?M=t[13]:(M=(0,a.jsx)(Dt,{height:l}),t[12]=l,t[13]=M);let B;return t[14]!==e||t[15]!==M?(B=(0,a.jsx)("div",{ref:e,className:"h-full overflow-auto",children:M}),t[14]=e,t[15]=M,t[16]=B):B=t[16],B}let y;t[17]===Symbol.for("react.memo_cache_sentinel")?(y=(0,a.jsx)(Ie,{className:"w-4 h-4"}),t[17]=y):y=t[17];let w;t[18]===c?w=t[19]:(w=c>0&&(0,a.jsx)(Oa,{children:c}),t[18]=c,t[19]=w);let u;t[20]===w?u=t[21]:(u=(0,a.jsxs)(dt,{children:[y," Remote storage",w]}),t[20]=w,t[21]=u);let d;t[22]===p?d=t[23]:(d={maxHeight:p},t[22]=p,t[23]=d);let k;t[24]===Symbol.for("react.memo_cache_sentinel")?(k=(0,a.jsx)(Ya,{}),t[24]=k):k=t[24];let S;t[25]===d?S=t[26]:(S=(0,a.jsx)(ht,{className:"overflow-auto",style:d,children:k}),t[25]=d,t[26]=S);let F;t[27]!==S||t[28]!==u?(F=(0,a.jsxs)(ct,{value:"remote-storage",children:[u,S]}),t[27]=S,t[28]=u,t[29]=F):F=t[29];let P;t[30]===Symbol.for("react.memo_cache_sentinel")?(P=(0,a.jsxs)(dt,{children:[(0,a.jsx)(Xe,{className:"w-4 h-4"}),"Files"]}),t[30]=P):P=t[30];let _;t[31]===b?_=t[32]:(_=(0,a.jsxs)(ct,{value:"files",children:[P,(0,a.jsx)(ht,{children:(0,a.jsx)(Dt,{height:b})})]}),t[31]=b,t[32]=_);let D;t[33]!==f||t[34]!==h||t[35]!==F||t[36]!==_?(D=(0,a.jsxs)(ga,{type:"multiple",value:h,onValueChange:f,children:[F,_]}),t[33]=f,t[34]=h,t[35]=F,t[36]=_,t[37]=D):D=t[37];let I;return t[38]!==e||t[39]!==D?(I=(0,a.jsx)("div",{ref:e,className:"h-full overflow-auto",children:D}),t[38]=e,t[39]=D,t[40]=I):I=t[40],I};export{_n as default};