Githubgemini / assets /AiFeatureBuilder-qJcM7Vps.js
admin08077's picture
Upload 204 files
d4e36ef verified
import{r,j as e}from"./react-DKy9e2uO.js";import{c as O,g as D,s as I,a as P,b as A,C as $,D as w,B as G,G as B,L as v,d as L,M as N}from"./index-Ck8YGBbR.js";import"./bottleneck-Cpj98o6Y.js";import"./react-dom-CpxHE_eW.js";import"./scheduler-DYLXRpC5.js";import"./idb-Dob3nYDb.js";import"./@google-D80DdW2m.js";import"./marked-CesSW9Du.js";import"./jszip-s56H2EZ-.js";const V=()=>{const[i,S]=r.useState('A simple "Hello World" React component with a button that shows an alert.'),[f,x]=r.useState([]),[p,u]=r.useState(""),[h,b]=r.useState(""),[n,c]=r.useState(null),[d,g]=r.useState(!1),[j,m]=r.useState(""),[o,l]=r.useState("CODE");r.useEffect(()=>{(async()=>{const s=await L();x(s),s.length>0&&c(s[0])})()},[]);const k=r.useCallback(async()=>{if(!i.trim()){m("Please enter a feature description.");return}g(!0),m(""),await O(),x([]),u(""),b(""),c(null),l("CODE");try{const t=await D(i);for(const s of t)await I(s);if(x(t),t.length>0){const s=t.find(a=>a.filePath.endsWith(".tsx")||a.filePath.endsWith(".jsx"));if(c(s||t[0]),s){const a=P(s.content);let C="";for await(const M of a)C+=M,u(C)}const T=t.map(a=>`File: ${a.filePath}
${a.content}`).join(`
---
`),E=A(T);let y="";for await(const a of E)y+=a,b(y)}}catch(t){const s=t instanceof Error?t.message:"An unknown error occurred.";m(`Failed to generate feature: ${s}`)}finally{g(!1)}},[i]),F=()=>{switch(o){case"TESTS":return e.jsx(N,{content:p});case"COMMIT":return e.jsx("pre",{className:"w-full h-full p-4 whitespace-pre-wrap font-sans text-sm text-text-primary",children:h});case"CODE":default:return n?e.jsx(N,{content:`\`\`\`tsx
${n.content}
\`\`\``}):e.jsx("div",{className:"flex items-center justify-center h-full text-text-secondary",children:"Select a file to view its content."})}};return e.jsxs("div",{className:"h-full flex flex-col text-text-primary bg-surface",children:[e.jsx("header",{className:"p-4 border-b border-border flex-shrink-0",children:e.jsxs("h1",{className:"text-xl font-bold flex items-center",children:[e.jsx($,{}),e.jsx("span",{className:"ml-3",children:"AI Feature Builder"})]})}),e.jsxs("div",{className:"flex-grow flex min-h-0",children:[e.jsxs("aside",{className:"w-64 bg-surface border-r border-border p-4 flex flex-col",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-secondary mb-2",children:"Generated Files"}),e.jsx("div",{className:"overflow-y-auto space-y-1",children:f.map(t=>e.jsxs("div",{onClick:()=>{c(t),l("CODE")},className:`flex items-center space-x-2 p-2 rounded-md cursor-pointer text-sm ${(n==null?void 0:n.filePath)===t.filePath&&o==="CODE"?"bg-primary/10 text-primary":"hover:bg-gray-100"}`,children:[e.jsx(w,{}),e.jsx("span",{children:t.filePath.split("/").pop()})]},t.filePath))})]}),e.jsxs("main",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex-grow flex flex-col bg-background",children:[e.jsxs("div",{className:"border-b border-border flex items-center bg-surface",children:[e.jsxs("button",{onClick:()=>l("CODE"),className:`flex items-center gap-2 px-4 py-2 text-sm ${o==="CODE"?"bg-background border-b-2 border-primary text-text-primary":"text-text-secondary hover:bg-gray-50"}`,children:[e.jsx(w,{})," Code"]}),p&&e.jsxs("button",{onClick:()=>l("TESTS"),className:`flex items-center gap-2 px-4 py-2 text-sm ${o==="TESTS"?"bg-background border-b-2 border-primary text-text-primary":"text-text-secondary hover:bg-gray-50"}`,children:[e.jsx(G,{})," Tests"]}),h&&e.jsxs("button",{onClick:()=>l("COMMIT"),className:`flex items-center gap-2 px-4 py-2 text-sm ${o==="COMMIT"?"bg-background border-b-2 border-primary text-text-primary":"text-text-secondary hover:bg-gray-50"}`,children:[e.jsx(B,{})," Commit"]})]}),e.jsx("div",{className:"flex-grow p-2 overflow-auto",children:d&&!f.length?e.jsx("div",{className:"flex justify-center items-center h-full",children:e.jsx(v,{})}):F()})]}),e.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-border bg-surface",children:[e.jsx("textarea",{value:i,onChange:t=>S(t.target.value),placeholder:"e.g., A user profile card with an avatar, name, and bio.",className:"w-full p-2 bg-background border border-border rounded-md resize-none text-sm h-20"}),e.jsx("button",{onClick:k,disabled:d,className:"btn-primary mt-2 w-full flex items-center justify-center gap-2 px-4 py-2",children:d?e.jsxs(e.Fragment,{children:[e.jsx(v,{})," Generating..."]}):"Generate Feature"}),j&&e.jsx("p",{className:"text-red-600 text-xs mt-2 text-center",children:j})]})]})]})]})};export{V as AiFeatureBuilder};
//# sourceMappingURL=AiFeatureBuilder-qJcM7Vps.js.map