@tanstack/cta-ui 0.30.0 → 0.32.0

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.
@@ -329,5 +329,5 @@ function alsShim(): PluginOption {
329
329
  };
330
330
  }
331
331
  `;function fW(n,e){let t=e;return n==="vite.config.ts"&&(t+=uW,t=t.replace("plugins: [",`${lW}plugins: [alsShim(),`)),t}console.log(">>> startup");const IQ=n=>{let e=n;return e=e.replace(/\u001b\[[0-9;]*[a-zA-Z]/g,""),e=e.replace(/\u001b\][0-9;]*;[^\u0007]*\u0007/g,""),e=e.replace(/\u001b[=>]/g,""),e=e.replace(/\r/g,""),e=e.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/g,""),e=e.replace(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/g,""),e=e.replace(/[▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏]/g,""),e=e.replace(/[░▒▓]/g,""),e=e.trim(),e.length>0?e:""};let YO=null;function hW(n){return YO||(YO=Yr.boot()),eC((t,i)=>({webContainer:YO,ready:!1,setupStep:"mounting",statusMessage:"",terminalOutput:[],previewUrl:null,error:null,devProcess:null,projectFiles:[],isInstalling:!1,teardown:()=>{t({webContainer:null,ready:!1})},addTerminalOutput:r=>{t(({terminalOutput:s})=>({terminalOutput:[...s,r]}))},setTerminalOutput:r=>{t({terminalOutput:r})},startDevServer:async()=>{const{devProcess:r,webContainer:s,addTerminalOutput:a}=i();if(!s)throw new Error("WebContainer not found");try{const c=await s;if(!c)throw new Error("WebContainer not found");r&&(console.log("Killing existing dev process..."),r.kill(),t({devProcess:null})),t({setupStep:"starting",statusMessage:"Starting development server..."}),a("🚀 Starting dev server..."),c.on("server-ready",(p,m)=>{console.log("Server ready on port",p,"at",m);const O=i();t({previewUrl:m,setupStep:"ready",statusMessage:"Development server running",terminalOutput:[...O.terminalOutput,`✅ Server ready at ${m}`]})});const u=await c.spawn("pnpm",["dev"]);t({devProcess:u}),u.output.pipeTo(new WritableStream({write(p){const m=IQ(p);if(m&&m.length>3){console.log("[DEV]",m);const O=i();t({terminalOutput:[...O.terminalOutput,m]})}}}));const h=await u.exit;h!==0&&(a(`❌ Dev server exited with code ${h}`),t({error:`Dev server exited with code ${h}`}))}catch(c){console.error("Dev server start error:",c),a(`❌ Dev server error: ${c.message}`),t({error:c.message,setupStep:"error"})}},updateProjectFiles:async r=>{const{projectFiles:s,addTerminalOutput:a,installDependencies:c,webContainer:u}=i();if(!u)throw console.error("WebContainer not found in updateProjectFiles"),new Error("WebContainer not found");try{const O=await u;if(!O)throw console.error("WebContainer resolved to null"),new Error("WebContainer not found");console.log("WebContainer booted successfully!",O)}catch(O){throw console.error("WebContainer boot failed:",O),t({error:`WebContainer boot failed: ${O.message}`,setupStep:"error"}),O}const h=await u;let p=!1;const m={};if(s.length===0){const O={};for(const{path:v,content:b}of r){const x=v.replace(/^\.?\//,""),w=x.split("/");let k=O;for(let $=0;$<w.length-1;$++){const R=w[$];k[R]||(k[R]={directory:{}}),k=k[R].directory}const T=w[w.length-1],A=fW(T,b);if(A.startsWith("base64::")){const $=A.replace("base64::","");try{const R=$.replace(/\s/g,""),_=atob(R),D=new Uint8Array(_.length);for(let j=0;j<_.length;j++)D[j]=_.charCodeAt(j)&255;m[x]=D}catch(R){console.error(`[BINARY ERROR] Failed to convert ${x}:`,R)}}else k[T]={file:{contents:String(A)}}}await h.mount(O);for(const[v,b]of Object.entries(m))await h.fs.writeFile(v,b);p=!0}else{const O=new Map;for(const{path:w,content:k}of s)O.set(w,k);const v=new Map;for(const{path:w,content:k}of r)v.set(w,k);const b=[];for(const{path:w,content:k}of r)O.has(w)?O.get(w)!==k&&b.push({path:w,content:k}):b.push({path:w,content:k});const x=[];for(const{path:w}of s)v.has(w)||x.push(w);if(b.length>0||x.length>0){const{devProcess:w}=i();w&&(console.log("Stopping dev server before file update..."),a("⏸️ Stopping dev server before updating files..."),w.kill(),t({devProcess:null,previewUrl:null}));for(const{path:k,content:T}of b)await h.fs.writeFile(k,T);for(const k of x)await h.fs.rm(k);a("📁 Files updated successfully"),b.some(({path:k})=>k==="./package.json")&&(p=!0)}}t({projectFiles:r}),p&&(a("📦 Package.json changed, reinstalling dependencies..."),await c())},installDependencies:async()=>{const{webContainer:r,addTerminalOutput:s,startDevServer:a,isInstalling:c}=i();if(c){console.log("Install already in progress, skipping");return}if(!r)throw new Error("WebContainer not found");t({isInstalling:!0});try{const u=await r;if(!u)throw t({isInstalling:!1}),new Error("WebContainer not found");t({setupStep:"installing",statusMessage:"Installing dependencies..."}),console.log("Starting pnpm install..."),s("📦 Running pnpm install..."),s("⏳ This may take a minute...");let h;try{h=await u.spawn("pnpm",["install"]),console.log("pnpm install process spawned successfully")}catch(x){throw console.error("Failed to spawn pnpm install:",x),x}let p=0,m=Date.now(),O=[],v=setInterval(()=>{const x=Math.floor((Date.now()-m)/1e3);console.log(`[INSTALL] Still running... (${x}s, ${p} output chunks)`)},5e3);h.output.pipeTo(new WritableStream({write(x){p++,O.push(x);const w=IQ(x);if(w&&w.length>3){const k=w.includes("added")||w.includes("removed")||w.includes("changed")||w.includes("audited")||w.includes("packages")||w.includes("error")||w.includes("warn")||w.includes("ERR")||w.includes("FAIL");k&&(console.log("[INSTALL]",w),s(w),k&&v&&(clearInterval(v),v=void 0))}}})),console.log("Waiting for install to complete...");const b=await h.exit;if(v&&clearInterval(v),console.log("Install exit code:",b),console.log("Total output lines:",p),b!==0){console.error("[INSTALL ERROR] All output:",O.join(`
332
- `));const x=`pnpm install failed with exit code ${b}`;throw s(`❌ ${x}`),s("💡 Check console for detailed error output"),t({error:x,setupStep:"error"}),new Error(x)}s("✅ Dependencies installed successfully"),await a()}catch(u){throw console.error("Install error:",u),s(`❌ Install error: ${u.message}`),t({error:u.message,setupStep:"error"}),u}finally{t({isInstalling:!1})}}}))}const CE=C.createContext(null);function dW({children:n,projectFiles:e}){console.log("WebContainerProvider rendering with",e.length,"files");const[t]=C.useState(()=>hW()),i=Ki(t,r=>r.updateProjectFiles);return C.useEffect(()=>{console.log("WebContainerProvider useEffect triggered with",e.length,"files"),i(e)},[i,e]),S.jsx(CE.Provider,{value:t,children:n})}function pW(){const n=C.useContext(CE);if(!n)throw new Error("WebContainerContext not found");const e=Ki(n,b=>b.webContainer),t=Ki(n,b=>b.setupStep),i=Ki(n,b=>b.statusMessage),r=Ki(n,b=>b.terminalOutput),s=Ki(n,b=>b.error),a=Ki(n,b=>b.previewUrl),c=Ki(n,b=>b.startDevServer),u=Ki(n,b=>b.setTerminalOutput),[h,p]=C.useState(!1),m=C.useRef(null);C.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[r]);const O=b=>{switch(b){case"mounting":return"📁";case"installing":return"📦";case"starting":return"🚀";case"ready":return"✅";case"error":return"❌"}},v=b=>{switch(b){case"error":return"text-red-500";case"ready":return"text-green-500";default:return"text-blue-500"}};return!e||t==="error"||t!=="ready"||!a?S.jsx("div",{className:"flex items-center justify-center h-full bg-gray-50 dark:bg-gray-900",children:S.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8 max-w-2xl w-full mx-4 border-2 border-blue-500",children:[S.jsx("h2",{className:"text-2xl font-bold mb-6 text-center",children:t==="error"?"Setup Failed":"Preparing Preview"}),t==="error"?S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-4xl mb-4",children:"❌"}),S.jsx("div",{className:"text-lg font-medium text-red-600 mb-2",children:"An error occurred"}),S.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:s}),S.jsx("button",{onClick:c,className:"px-4 py-2 text-sm bg-orange-500 text-white rounded hover:bg-orange-600 transition-colors",children:"🔄 Retry"})]}):S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"space-y-4 mb-6",children:[S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:"text-2xl",children:O("mounting")}),S.jsx("div",{className:`flex-1 ${v(t==="mounting"?"mounting":t==="installing"||t==="starting"||t==="ready"?"ready":"mounting")}`,children:"Mount Files"}),(t==="installing"||t==="starting"||t==="ready")&&"✓"]}),S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:"text-2xl",children:O("installing")}),S.jsx("div",{className:`flex-1 ${v(t==="installing"?"installing":t==="starting"||t==="ready"?"ready":"mounting")}`,children:"Install Dependencies"}),(t==="starting"||t==="ready")&&"✓"]}),S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:"text-2xl",children:O("starting")}),S.jsx("div",{className:`flex-1 ${v(t==="starting"?"starting":t==="ready"?"ready":"mounting")}`,children:"Start Server"}),t==="ready"&&"✓"]})]}),S.jsx("div",{className:"text-center text-sm text-gray-600 dark:text-gray-400",children:i||"Preparing your application..."})]})]})}):S.jsxs("div",{className:"flex flex-col h-full",children:[S.jsx("div",{className:"flex-1",children:a?S.jsx("iframe",{src:a,className:"w-full h-full border-0",title:"Application Preview",onLoad:()=>console.log("Iframe loaded successfully"),onError:b=>console.error("Iframe load error:",b)}):S.jsx("div",{className:"flex items-center justify-center h-full bg-gray-100 dark:bg-gray-800",children:S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-2xl mb-2",children:"🔄"}),S.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Preview not available"})]})})}),S.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 bg-black text-green-400 flex flex-col flex-shrink-0",children:[S.jsxs("div",{className:"p-2 border-b border-gray-700 bg-gray-900 flex items-center justify-between cursor-pointer hover:bg-gray-800 transition-colors",onClick:()=>p(!h),children:[S.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[S.jsx("button",{className:"text-gray-400 hover:text-gray-200",children:h?S.jsx(yC,{className:"w-4 h-4"}):S.jsx(vD,{className:"w-4 h-4"})}),S.jsx("div",{className:"text-xs font-medium text-gray-300",children:"Terminal Output"}),t==="ready"&&a&&S.jsx("div",{className:"text-xs text-green-500",children:"● Server Running"})]}),S.jsxs("div",{className:"flex items-center gap-2",onClick:b=>b.stopPropagation(),children:[a&&S.jsx("button",{onClick:()=>window.open(a,"_blank"),className:"px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors",children:"Open in New Tab"}),S.jsx("button",{onClick:c,disabled:!e,className:"px-2 py-1 text-xs bg-orange-500 text-white rounded hover:bg-orange-600 transition-colors disabled:opacity-50",children:"🔄 Restart"}),S.jsx("button",{onClick:()=>u([]),className:"text-xs text-gray-400 hover:text-gray-200 transition-colors",children:"Clear"})]})]}),h&&S.jsx("div",{ref:m,className:"font-mono text-xs p-2 overflow-y-auto overflow-x-hidden",style:{maxHeight:"200px"},children:r.length>0?r.map((b,x)=>S.jsx("div",{className:"mb-1 leading-tight whitespace-pre-wrap break-words",children:b},x)):S.jsx("div",{className:"text-gray-500",children:"No output yet..."})})]})]})}var Mp="Tabs",[mW,UW]=Ni(Mp,[Sl]),TE=Sl(),[gW,hb]=mW(Mp),PE=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,onValueChange:r,defaultValue:s,orientation:a="horizontal",dir:c,activationMode:u="automatic",...h}=n,p=Eu(c),[m,O]=Zi({prop:i,onChange:r,defaultProp:s??"",caller:Mp});return S.jsx(gW,{scope:t,baseId:Ir(),value:m,onValueChange:O,orientation:a,dir:p,activationMode:u,children:S.jsx(ze.div,{dir:p,"data-orientation":a,...h,ref:e})})});PE.displayName=Mp;var AE="TabsList",ME=C.forwardRef((n,e)=>{const{__scopeTabs:t,loop:i=!0,...r}=n,s=hb(AE,t),a=TE(t);return S.jsx(Gy,{asChild:!0,...a,orientation:s.orientation,dir:s.dir,loop:i,children:S.jsx(ze.div,{role:"tablist","aria-orientation":s.orientation,...r,ref:e})})});ME.displayName=AE;var RE="TabsTrigger",$E=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,disabled:r=!1,...s}=n,a=hb(RE,t),c=TE(t),u=DE(a.baseId,i),h=jE(a.baseId,i),p=i===a.value;return S.jsx(Iy,{asChild:!0,...c,focusable:!r,active:p,children:S.jsx(ze.button,{type:"button",role:"tab","aria-selected":p,"aria-controls":h,"data-state":p?"active":"inactive","data-disabled":r?"":void 0,disabled:r,id:u,...s,ref:e,onMouseDown:Ae(n.onMouseDown,m=>{!r&&m.button===0&&m.ctrlKey===!1?a.onValueChange(i):m.preventDefault()}),onKeyDown:Ae(n.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&a.onValueChange(i)}),onFocus:Ae(n.onFocus,()=>{const m=a.activationMode!=="manual";!p&&!r&&m&&a.onValueChange(i)})})})});$E.displayName=RE;var EE="TabsContent",_E=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,forceMount:r,children:s,...a}=n,c=hb(EE,t),u=DE(c.baseId,i),h=jE(c.baseId,i),p=i===c.value,m=C.useRef(p);return C.useEffect(()=>{const O=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(O)},[]),S.jsx(yr,{present:r||p,children:({present:O})=>S.jsx(ze.div,{"data-state":p?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!O,id:h,tabIndex:0,...a,ref:e,style:{...n.style,animationDuration:m.current?"0s":void 0},children:O&&s})})});_E.displayName=EE;function DE(n,e){return`${n}-trigger-${e}`}function jE(n,e){return`${n}-content-${e}`}var OW=PE,yW=ME,vW=$E,bW=_E;function xW({className:n,...e}){return S.jsx(OW,{"data-slot":"tabs",className:Ie("flex flex-col gap-2",n),...e})}function SW({className:n,...e}){return S.jsx(yW,{"data-slot":"tabs-list",className:Ie("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",n),...e})}function WQ({className:n,...e}){return S.jsx(vW,{"data-slot":"tabs-trigger",className:Ie("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),...e})}function HQ({className:n,...e}){return S.jsx(bW,{"data-slot":"tabs-content",className:Ie("flex-1 outline-none",n),...e})}function wW(){const{includedFiles:n,toggleFilter:e}=gC();return S.jsxs("div",{className:"bg-white dark:bg-black/40 shadow-xl p-4 rounded-lg flex flex-row items-center gap-4 mb-2",children:[S.jsx("h3",{className:"font-medium whitespace-nowrap",children:"File Filters"}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"unchanged",checked:n.includes("unchanged"),onCheckedChange:()=>e("unchanged"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"unchanged",className:Da.unchanged,children:"Unchanged"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"added",checked:n.includes("added"),onCheckedChange:()=>e("added"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"added",className:Da.added,children:"Added"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"modified",checked:n.includes("modified"),onCheckedChange:()=>e("modified"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"modified",className:Da.modified,children:"Modified"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"deleted",checked:n.includes("deleted"),onCheckedChange:()=>e("deleted"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"deleted",className:Da.deleted,children:"Deleted"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"overwritten",checked:n.includes("overwritten"),onCheckedChange:()=>e("overwritten"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"overwritten",className:Da.overwritten,children:"Overwritten"})]})]})}function kW(){const[n,e]=C.useState("./package.json"),t=H_(),i=W_(),r=sD(),s=Or(),a=r.files,c=s==="setup"?r.files:t?.files,u=r.deletedFiles,[h,p]=C.useState(),[m,O]=C.useState(),{includedFiles:v}=gC(),b=C.useMemo(()=>{const k=[];return!c||!i||Array.from(new Set([...Object.keys(a),...Object.keys(i),...Object.keys(c)])).sort().forEach(A=>{const $=A.replace("./",""),R=$.split("/");let _=k;R.forEach((D,j)=>{const Y=_.find(J=>J.name===D);if(Y)_=Y.children||[];else{const J=WX(A,a,c,i,u);if(j===R.length-1&&!v.includes(J.fileClass))return;j===R.length-1&&A===n&&(O(J.modifiedFile),p(J.originalFile));const I={id:R.slice(0,j+1).join("/"),name:D,fullPath:$,children:j<R.length-1?[]:void 0,icon:j<R.length-1?()=>S.jsx(bC,{className:"w-4 h-4 mr-2"}):()=>S.jsx(vC,{className:"w-4 h-4 mr-2"}),onClick:j===R.length-1?()=>{e(A),O(J.modifiedFile),p(J.originalFile)}:void 0,className:Da[J.fileClass],...J,contents:a[A]||i[A]||c[A]};_.push(I),_=I.children}})}),k},[a,c,i,v]),x=gr(),w=C.useMemo(()=>{if(console.log("Preparing WebContainer files, tree:",a),!a)return console.log("Tree is empty, returning empty array"),[];const k=Object.entries(a).map(([T,A])=>({path:T,content:A}));return console.log("WebContainer files prepared:",k.length,"files"),k},[a]);return x?S.jsx(dW,{projectFiles:w,children:S.jsxs("div",{className:"bg-white dark:bg-black/50 rounded-lg p-2 sm:p-4",children:[s==="add"&&S.jsx(wW,{}),S.jsxs(xW,{defaultValue:"files",className:"w-full",children:[S.jsxs(SW,{className:"mb-1 h-7 p-0.5 bg-transparent border border-gray-300 dark:border-gray-700",children:[S.jsx(WQ,{value:"files",className:"text-xs h-6 px-3 py-0 data-[state=active]:bg-gray-200 dark:data-[state=active]:bg-gray-800",children:"Files"}),S.jsx(WQ,{value:"preview",className:"text-xs h-6 px-3 py-0 data-[state=active]:bg-gray-200 dark:data-[state=active]:bg-gray-800",children:"Preview"})]}),S.jsx(HQ,{value:"files",className:"mt-0",children:S.jsxs("div",{className:"flex flex-row @container",children:[S.jsx("div",{className:"w-1/3 @6xl:w-1/4 bg-gray-500/10 rounded-l-lg",children:S.jsx(EI,{selectedFile:n,tree:b})}),S.jsx("div",{className:"w-2/3 @6xl:w-3/4",children:n&&m?S.jsx(dI,{filePath:n,originalFile:h,modifiedFile:m}):null})]})}),S.jsx(HQ,{value:"preview",className:"mt-0",children:S.jsx("div",{className:"h-[800px]",children:S.jsx(pW,{})})})]})]})}):null}function QW(){const n=Or(),e=ky(),{open:t,setOpen:i,dontShowAgain:r,setDontShowAgain:s}=oD();if(n!=="setup"||!e||e?.starters?.length===0)return null;async function a(c){const u=await dC(c);"error"in u?Py.error("Failed to load starter",{description:u.error}):(JO(u),i(!1))}return S.jsx(jo,{modal:!0,open:t,onOpenChange:i,children:S.jsxs(No,{className:"sm:min-w-[425px] sm:max-w-fit",children:[S.jsx(yl,{children:S.jsx(vl,{className:"text-center text-2xl font-bold",children:"Would you like to use a starter project?"})}),S.jsx("div",{children:S.jsx(NP,{onImport:a})}),S.jsxs($u,{className:"flex sm:justify-between w-full",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Ur,{id:"show-startup-dialog",checked:r,onCheckedChange:s}),S.jsx(Ji,{htmlFor:"show-startup-dialog",children:"Don't show this again"})]}),S.jsx(Oi,{onClick:()=>i(!1),children:"No, I want to start from scratch"})]})]})})}var CW=(n,e,t,i,r,s,a,c)=>{let u=document.documentElement,h=["light","dark"];function p(v){(Array.isArray(n)?n:[n]).forEach(b=>{let x=b==="class",w=x&&s?r.map(k=>s[k]||k):r;x?(u.classList.remove(...w),u.classList.add(s&&s[v]?s[v]:v)):u.setAttribute(b,v)}),m(v)}function m(v){c&&h.includes(v)&&(u.style.colorScheme=v)}function O(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(i)p(i);else try{let v=localStorage.getItem(e)||t,b=a&&v==="system"?O():v;p(b)}catch{}},TW=C.createContext(void 0),PW={setTheme:n=>{},themes:[]},AW=()=>{var n;return(n=C.useContext(TW))!=null?n:PW};C.memo(({forcedTheme:n,storageKey:e,attribute:t,enableSystem:i,enableColorScheme:r,defaultTheme:s,value:a,themes:c,nonce:u,scriptProps:h})=>{let p=JSON.stringify([t,e,s,n,c,a,i,r]).slice(1,-1);return C.createElement("script",{...h,suppressHydrationWarning:!0,nonce:typeof window>"u"?u:"",dangerouslySetInnerHTML:{__html:`(${CW.toString()})(${p})`}})});const MW=({...n})=>{const{theme:e="system"}=AW();return S.jsx(yj,{theme:e,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...n})};function RW({children:n}){const[e]=C.useState(()=>new S_);return S.jsx(T_,{client:e,children:n})}function $W({children:n}){return fD(),S.jsxs(S.Fragment,{children:[n,S.jsx(MW,{})]})}function EW({children:n}){return S.jsx(RW,{children:S.jsx($W,{children:n})})}const _W={header:S.jsx(VX,{}),sidebar:S.jsx(qX,{}),fileNavigator:S.jsx(kW,{}),startupDialog:S.jsx(QW,{})};function DW(n){const e=Object.assign({},_W,n.slots);return S.jsx(EW,{children:S.jsxs("main",{className:"min-w-[1280px]",children:[S.jsx(GX,{}),S.jsxs("div",{className:"min-h-dvh p-2 sm:p-4 space-y-2 sm:space-y-4 @container",children:[e.header,S.jsxs("div",{className:"flex flex-row",children:[S.jsx("div",{className:"w-1/3 @8xl:w-1/4 pr-2",children:e.sidebar}),S.jsx("div",{className:"w-2/3 @8xl:w-3/4 pl-2",children:e.fileNavigator})]})]}),e.startupDialog]})})}const FQ=document.getElementById("root");FQ&&t_.createRoot(FQ).render(S.jsx(DW,{}));
333
- //# sourceMappingURL=index-DheH_mx5.js.map
332
+ `));const x=`pnpm install failed with exit code ${b}`;throw s(`❌ ${x}`),s("💡 Check console for detailed error output"),t({error:x,setupStep:"error"}),new Error(x)}s("✅ Dependencies installed successfully"),await a()}catch(u){throw console.error("Install error:",u),s(`❌ Install error: ${u.message}`),t({error:u.message,setupStep:"error"}),u}finally{t({isInstalling:!1})}}}))}const CE=C.createContext(null);function dW({children:n,projectFiles:e}){console.log("WebContainerProvider rendering with",e.length,"files");const[t]=C.useState(()=>hW()),i=Ki(t,r=>r.updateProjectFiles);return C.useEffect(()=>{console.log("WebContainerProvider useEffect triggered with",e.length,"files"),i(e)},[i,e]),S.jsx(CE.Provider,{value:t,children:n})}function pW(){const n=C.useContext(CE);if(!n)throw new Error("WebContainerContext not found");const e=Ki(n,b=>b.webContainer),t=Ki(n,b=>b.setupStep),i=Ki(n,b=>b.statusMessage),r=Ki(n,b=>b.terminalOutput),s=Ki(n,b=>b.error),a=Ki(n,b=>b.previewUrl),c=Ki(n,b=>b.startDevServer),u=Ki(n,b=>b.setTerminalOutput),[h,p]=C.useState(!1),m=C.useRef(null);C.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[r]);const O=b=>{switch(b){case"mounting":return"📁";case"installing":return"📦";case"starting":return"🚀";case"ready":return"✅";case"error":return"❌"}},v=b=>{switch(b){case"error":return"text-red-500";case"ready":return"text-green-500";default:return"text-blue-500"}};return!e||t==="error"||t!=="ready"||!a?S.jsx("div",{className:"flex items-center justify-center h-full bg-gray-50 dark:bg-gray-900",children:S.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl p-8 max-w-2xl w-full mx-4 border-2 border-blue-500",children:[S.jsx("h2",{className:"text-2xl font-bold mb-6 text-center",children:t==="error"?"Setup Failed":"Preparing Preview"}),t==="error"?S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-4xl mb-4",children:"❌"}),S.jsx("div",{className:"text-lg font-medium text-red-600 mb-2",children:"An error occurred"}),S.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:s}),S.jsx("button",{onClick:c,className:"px-4 py-2 text-sm bg-orange-500 text-white rounded hover:bg-orange-600 transition-colors",children:"🔄 Retry"})]}):S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"space-y-4 mb-6",children:[S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:`text-2xl ${t==="mounting"?"animate-pulse":""}`,children:O("mounting")}),S.jsx("div",{className:`flex-1 ${v(t==="mounting"?"mounting":t==="installing"||t==="starting"||t==="ready"?"ready":"mounting")}`,children:"Mount Files"}),(t==="installing"||t==="starting"||t==="ready")&&"✓"]}),S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:`text-2xl ${t==="installing"?"animate-spin":""}`,children:O("installing")}),S.jsx("div",{className:`flex-1 ${v(t==="installing"?"installing":t==="starting"||t==="ready"?"ready":"mounting")}`,children:"Install Dependencies"}),(t==="starting"||t==="ready")&&"✓"]}),S.jsxs("div",{className:"flex items-center gap-3",children:[S.jsx("div",{className:`text-2xl ${t==="starting"?"animate-bounce":""}`,children:O("starting")}),S.jsx("div",{className:`flex-1 ${v(t==="starting"?"starting":t==="ready"?"ready":"mounting")}`,children:"Start Server"}),t==="ready"&&"✓"]})]}),S.jsx("div",{className:"text-center text-sm text-gray-600 dark:text-gray-400",children:i||"Preparing your application..."})]})]})}):S.jsxs("div",{className:"flex flex-col h-full",children:[S.jsx("div",{className:"flex-1",children:a?S.jsx("iframe",{src:a,className:"w-full h-full border-0",title:"Application Preview",onLoad:()=>console.log("Iframe loaded successfully"),onError:b=>console.error("Iframe load error:",b)}):S.jsx("div",{className:"flex items-center justify-center h-full bg-gray-100 dark:bg-gray-800",children:S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-2xl mb-2",children:"🔄"}),S.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Preview not available"})]})})}),S.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 bg-black text-green-400 flex flex-col flex-shrink-0",children:[S.jsxs("div",{className:"p-2 border-b border-gray-700 bg-gray-900 flex items-center justify-between cursor-pointer hover:bg-gray-800 transition-colors",onClick:()=>p(!h),children:[S.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[S.jsx("button",{className:"text-gray-400 hover:text-gray-200",children:h?S.jsx(yC,{className:"w-4 h-4"}):S.jsx(vD,{className:"w-4 h-4"})}),S.jsx("div",{className:"text-xs font-medium text-gray-300",children:"Terminal Output"}),t==="ready"&&a&&S.jsx("div",{className:"text-xs text-green-500",children:"● Server Running"})]}),S.jsxs("div",{className:"flex items-center gap-2",onClick:b=>b.stopPropagation(),children:[a&&S.jsx("button",{onClick:()=>window.open(a,"_blank"),className:"px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors",children:"Open in New Tab"}),S.jsx("button",{onClick:c,disabled:!e,className:"px-2 py-1 text-xs bg-orange-500 text-white rounded hover:bg-orange-600 transition-colors disabled:opacity-50",children:"🔄 Restart"}),S.jsx("button",{onClick:()=>u([]),className:"text-xs text-gray-400 hover:text-gray-200 transition-colors",children:"Clear"})]})]}),h&&S.jsx("div",{ref:m,className:"font-mono text-xs p-2 overflow-y-auto overflow-x-hidden",style:{maxHeight:"200px"},children:r.length>0?r.map((b,x)=>S.jsx("div",{className:"mb-1 leading-tight whitespace-pre-wrap break-words",children:b},x)):S.jsx("div",{className:"text-gray-500",children:"No output yet..."})})]})]})}var Mp="Tabs",[mW,UW]=Ni(Mp,[Sl]),TE=Sl(),[gW,hb]=mW(Mp),PE=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,onValueChange:r,defaultValue:s,orientation:a="horizontal",dir:c,activationMode:u="automatic",...h}=n,p=Eu(c),[m,O]=Zi({prop:i,onChange:r,defaultProp:s??"",caller:Mp});return S.jsx(gW,{scope:t,baseId:Ir(),value:m,onValueChange:O,orientation:a,dir:p,activationMode:u,children:S.jsx(ze.div,{dir:p,"data-orientation":a,...h,ref:e})})});PE.displayName=Mp;var AE="TabsList",ME=C.forwardRef((n,e)=>{const{__scopeTabs:t,loop:i=!0,...r}=n,s=hb(AE,t),a=TE(t);return S.jsx(Gy,{asChild:!0,...a,orientation:s.orientation,dir:s.dir,loop:i,children:S.jsx(ze.div,{role:"tablist","aria-orientation":s.orientation,...r,ref:e})})});ME.displayName=AE;var RE="TabsTrigger",$E=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,disabled:r=!1,...s}=n,a=hb(RE,t),c=TE(t),u=DE(a.baseId,i),h=jE(a.baseId,i),p=i===a.value;return S.jsx(Iy,{asChild:!0,...c,focusable:!r,active:p,children:S.jsx(ze.button,{type:"button",role:"tab","aria-selected":p,"aria-controls":h,"data-state":p?"active":"inactive","data-disabled":r?"":void 0,disabled:r,id:u,...s,ref:e,onMouseDown:Ae(n.onMouseDown,m=>{!r&&m.button===0&&m.ctrlKey===!1?a.onValueChange(i):m.preventDefault()}),onKeyDown:Ae(n.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&a.onValueChange(i)}),onFocus:Ae(n.onFocus,()=>{const m=a.activationMode!=="manual";!p&&!r&&m&&a.onValueChange(i)})})})});$E.displayName=RE;var EE="TabsContent",_E=C.forwardRef((n,e)=>{const{__scopeTabs:t,value:i,forceMount:r,children:s,...a}=n,c=hb(EE,t),u=DE(c.baseId,i),h=jE(c.baseId,i),p=i===c.value,m=C.useRef(p);return C.useEffect(()=>{const O=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(O)},[]),S.jsx(yr,{present:r||p,children:({present:O})=>S.jsx(ze.div,{"data-state":p?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!O,id:h,tabIndex:0,...a,ref:e,style:{...n.style,animationDuration:m.current?"0s":void 0},children:O&&s})})});_E.displayName=EE;function DE(n,e){return`${n}-trigger-${e}`}function jE(n,e){return`${n}-content-${e}`}var OW=PE,yW=ME,vW=$E,bW=_E;function xW({className:n,...e}){return S.jsx(OW,{"data-slot":"tabs",className:Ie("flex flex-col gap-2",n),...e})}function SW({className:n,...e}){return S.jsx(yW,{"data-slot":"tabs-list",className:Ie("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",n),...e})}function WQ({className:n,...e}){return S.jsx(vW,{"data-slot":"tabs-trigger",className:Ie("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),...e})}function HQ({className:n,...e}){return S.jsx(bW,{"data-slot":"tabs-content",className:Ie("flex-1 outline-none",n),...e})}function wW(){const{includedFiles:n,toggleFilter:e}=gC();return S.jsxs("div",{className:"bg-white dark:bg-black/40 shadow-xl p-4 rounded-lg flex flex-row items-center gap-4 mb-2",children:[S.jsx("h3",{className:"font-medium whitespace-nowrap",children:"File Filters"}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"unchanged",checked:n.includes("unchanged"),onCheckedChange:()=>e("unchanged"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"unchanged",className:Da.unchanged,children:"Unchanged"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"added",checked:n.includes("added"),onCheckedChange:()=>e("added"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"added",className:Da.added,children:"Added"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"modified",checked:n.includes("modified"),onCheckedChange:()=>e("modified"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"modified",className:Da.modified,children:"Modified"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"deleted",checked:n.includes("deleted"),onCheckedChange:()=>e("deleted"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"deleted",className:Da.deleted,children:"Deleted"})]}),S.jsxs("div",{className:"flex flex-row items-center",children:[S.jsx(Ur,{id:"overwritten",checked:n.includes("overwritten"),onCheckedChange:()=>e("overwritten"),className:"mr-2"}),S.jsx(Ji,{htmlFor:"overwritten",className:Da.overwritten,children:"Overwritten"})]})]})}function kW(){const[n,e]=C.useState("./package.json"),t=H_(),i=W_(),r=sD(),s=Or(),a=r.files,c=s==="setup"?r.files:t?.files,u=r.deletedFiles,[h,p]=C.useState(),[m,O]=C.useState(),{includedFiles:v}=gC(),b=C.useMemo(()=>{const k=[];return!c||!i||Array.from(new Set([...Object.keys(a),...Object.keys(i),...Object.keys(c)])).sort().forEach(A=>{const $=A.replace("./",""),R=$.split("/");let _=k;R.forEach((D,j)=>{const Y=_.find(J=>J.name===D);if(Y)_=Y.children||[];else{const J=WX(A,a,c,i,u);if(j===R.length-1&&!v.includes(J.fileClass))return;j===R.length-1&&A===n&&(O(J.modifiedFile),p(J.originalFile));const I={id:R.slice(0,j+1).join("/"),name:D,fullPath:$,children:j<R.length-1?[]:void 0,icon:j<R.length-1?()=>S.jsx(bC,{className:"w-4 h-4 mr-2"}):()=>S.jsx(vC,{className:"w-4 h-4 mr-2"}),onClick:j===R.length-1?()=>{e(A),O(J.modifiedFile),p(J.originalFile)}:void 0,className:Da[J.fileClass],...J,contents:a[A]||i[A]||c[A]};_.push(I),_=I.children}})}),k},[a,c,i,v]),x=gr(),w=C.useMemo(()=>{if(console.log("Preparing WebContainer files, tree:",a),!a)return console.log("Tree is empty, returning empty array"),[];const k=Object.entries(a).map(([T,A])=>({path:T,content:A}));return console.log("WebContainer files prepared:",k.length,"files"),k},[a]);return x?S.jsx(dW,{projectFiles:w,children:S.jsxs("div",{className:"bg-white dark:bg-black/50 rounded-lg p-2 sm:p-4",children:[s==="add"&&S.jsx(wW,{}),S.jsxs(xW,{defaultValue:"files",className:"w-full",children:[S.jsxs(SW,{className:"mb-1 h-7 p-0.5 bg-transparent border border-gray-300 dark:border-gray-700",children:[S.jsx(WQ,{value:"files",className:"text-xs h-6 px-3 py-0 data-[state=active]:bg-gray-200 dark:data-[state=active]:bg-gray-800",children:"Files"}),S.jsx(WQ,{value:"preview",className:"text-xs h-6 px-3 py-0 data-[state=active]:bg-gray-200 dark:data-[state=active]:bg-gray-800",children:"Preview"})]}),S.jsx(HQ,{value:"files",className:"mt-0",children:S.jsxs("div",{className:"flex flex-row @container",children:[S.jsx("div",{className:"w-1/3 @6xl:w-1/4 bg-gray-500/10 rounded-l-lg",children:S.jsx(EI,{selectedFile:n,tree:b})}),S.jsx("div",{className:"w-2/3 @6xl:w-3/4",children:n&&m?S.jsx(dI,{filePath:n,originalFile:h,modifiedFile:m}):null})]})}),S.jsx(HQ,{value:"preview",className:"mt-0",children:S.jsx("div",{className:"h-[800px]",children:S.jsx(pW,{})})})]})]})}):null}function QW(){const n=Or(),e=ky(),{open:t,setOpen:i,dontShowAgain:r,setDontShowAgain:s}=oD();if(n!=="setup"||!e||e?.starters?.length===0)return null;async function a(c){const u=await dC(c);"error"in u?Py.error("Failed to load starter",{description:u.error}):(JO(u),i(!1))}return S.jsx(jo,{modal:!0,open:t,onOpenChange:i,children:S.jsxs(No,{className:"sm:min-w-[425px] sm:max-w-fit",children:[S.jsx(yl,{children:S.jsx(vl,{className:"text-center text-2xl font-bold",children:"Would you like to use a starter project?"})}),S.jsx("div",{children:S.jsx(NP,{onImport:a})}),S.jsxs($u,{className:"flex sm:justify-between w-full",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Ur,{id:"show-startup-dialog",checked:r,onCheckedChange:s}),S.jsx(Ji,{htmlFor:"show-startup-dialog",children:"Don't show this again"})]}),S.jsx(Oi,{onClick:()=>i(!1),children:"No, I want to start from scratch"})]})]})})}var CW=(n,e,t,i,r,s,a,c)=>{let u=document.documentElement,h=["light","dark"];function p(v){(Array.isArray(n)?n:[n]).forEach(b=>{let x=b==="class",w=x&&s?r.map(k=>s[k]||k):r;x?(u.classList.remove(...w),u.classList.add(s&&s[v]?s[v]:v)):u.setAttribute(b,v)}),m(v)}function m(v){c&&h.includes(v)&&(u.style.colorScheme=v)}function O(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(i)p(i);else try{let v=localStorage.getItem(e)||t,b=a&&v==="system"?O():v;p(b)}catch{}},TW=C.createContext(void 0),PW={setTheme:n=>{},themes:[]},AW=()=>{var n;return(n=C.useContext(TW))!=null?n:PW};C.memo(({forcedTheme:n,storageKey:e,attribute:t,enableSystem:i,enableColorScheme:r,defaultTheme:s,value:a,themes:c,nonce:u,scriptProps:h})=>{let p=JSON.stringify([t,e,s,n,c,a,i,r]).slice(1,-1);return C.createElement("script",{...h,suppressHydrationWarning:!0,nonce:typeof window>"u"?u:"",dangerouslySetInnerHTML:{__html:`(${CW.toString()})(${p})`}})});const MW=({...n})=>{const{theme:e="system"}=AW();return S.jsx(yj,{theme:e,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...n})};function RW({children:n}){const[e]=C.useState(()=>new S_);return S.jsx(T_,{client:e,children:n})}function $W({children:n}){return fD(),S.jsxs(S.Fragment,{children:[n,S.jsx(MW,{})]})}function EW({children:n}){return S.jsx(RW,{children:S.jsx($W,{children:n})})}const _W={header:S.jsx(VX,{}),sidebar:S.jsx(qX,{}),fileNavigator:S.jsx(kW,{}),startupDialog:S.jsx(QW,{})};function DW(n){const e=Object.assign({},_W,n.slots);return S.jsx(EW,{children:S.jsxs("main",{className:"min-w-[1280px]",children:[S.jsx(GX,{}),S.jsxs("div",{className:"min-h-dvh p-2 sm:p-4 space-y-2 sm:space-y-4 @container",children:[e.header,S.jsxs("div",{className:"flex flex-row",children:[S.jsx("div",{className:"w-1/3 @8xl:w-1/4 pr-2",children:e.sidebar}),S.jsx("div",{className:"w-2/3 @8xl:w-3/4 pl-2",children:e.fileNavigator})]})]}),e.startupDialog]})})}const FQ=document.getElementById("root");FQ&&t_.createRoot(FQ).render(S.jsx(DW,{}));
333
+ //# sourceMappingURL=index-BMNLJ_vl.js.map