{"version":3,"file":"CodeFormatter-BxgaA_LP.js","sources":["../../components/features/CodeFormatter.tsx"],"sourcesContent":["import React, { useState, useCallback } from 'react';\nimport { formatCodeStream } from '../../services/geminiService.ts';\nimport { CodeBracketSquareIcon } from '../icons/FeatureIcons.tsx';\nimport { LoadingSpinner } from '../shared/LoadingSpinner.tsx';\nimport { MarkdownRenderer } from '../shared/MarkdownRenderer.tsx';\n\nconst exampleCode = `const MyComponent = (props) => {\n const {name, items}=props\n if(!items || items.length === 0){\n return

No items found for {name}

;\n }\n return \n}`;\n\nexport const CodeFormatter: React.FC = () => {\n const [inputCode, setInputCode] = useState(exampleCode);\n const [formattedCode, setFormattedCode] = useState('');\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState('');\n\n const handleFormat = useCallback(async () => {\n if (!inputCode.trim()) {\n setError('Please enter some code to format.');\n return;\n }\n setIsLoading(true);\n setError('');\n setFormattedCode('');\n try {\n const stream = formatCodeStream(inputCode);\n let fullResponse = '';\n for await (const chunk of stream) {\n fullResponse += chunk;\n setFormattedCode(fullResponse);\n }\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n setError(`Failed to format code: ${errorMessage}`);\n } finally {\n setIsLoading(false);\n }\n }, [inputCode]);\n \n return (\n
\n
\n

\n \n AI Code Formatter\n

\n

Clean up your code with AI-powered formatting, like a smart Prettier.

\n
\n
\n
\n
\n \n setInputCode(e.target.value)}\n placeholder=\"Paste your unformatted code here...\"\n className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm\"\n />\n
\n
\n \n
\n {isLoading && !formattedCode && (\n
\n \n
\n )}\n {error &&

{error}

}\n {formattedCode && }\n {!isLoading && !formattedCode && !error && (\n
\n Formatted code will appear here.\n
\n )}\n
\n
\n
\n \n {isLoading ? : 'Format Code'}\n \n
\n
\n );\n};\n"],"names":["exampleCode","CodeFormatter","inputCode","setInputCode","useState","formattedCode","setFormattedCode","isLoading","setIsLoading","error","setError","handleFormat","useCallback","stream","formatCodeStream","fullResponse","chunk","err","errorMessage","jsxs","jsx","CodeBracketSquareIcon","e","LoadingSpinner","MarkdownRenderer"],"mappings":"wRAMA,MAAMA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAQPC,EAA0B,IAAM,CACzC,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAiBJ,CAAW,EACxD,CAACK,EAAeC,CAAgB,EAAIF,EAAAA,SAAiB,EAAE,EACvD,CAACG,EAAWC,CAAY,EAAIJ,EAAAA,SAAkB,EAAK,EACnD,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAAiB,EAAE,EAEvCO,EAAeC,EAAAA,YAAY,SAAY,CACzC,GAAI,CAACV,EAAU,OAAQ,CACnBQ,EAAS,mCAAmC,EAC5C,MACJ,CACAF,EAAa,EAAI,EACjBE,EAAS,EAAE,EACXJ,EAAiB,EAAE,EACnB,GAAI,CACA,MAAMO,EAASC,EAAiBZ,CAAS,EACzC,IAAIa,EAAe,GACnB,gBAAiBC,KAASH,EACtBE,GAAgBC,EAChBV,EAAiBS,CAAY,CAErC,OAASE,EAAK,CACV,MAAMC,EAAeD,aAAe,MAAQA,EAAI,QAAU,6BAC1DP,EAAS,0BAA0BQ,CAAY,EAAE,CACrD,QAAA,CACIV,EAAa,EAAK,CACtB,CACJ,EAAG,CAACN,CAAS,CAAC,EAEd,OACIiB,EAAAA,KAAC,MAAA,CAAI,UAAU,2DACX,SAAA,CAAAA,EAAAA,KAAC,SAAA,CAAO,UAAU,OACd,SAAA,CAAAA,EAAAA,KAAC,KAAA,CAAG,UAAU,uCACV,SAAA,CAAAC,EAAAA,IAACC,EAAA,EAAsB,EACvBD,EAAAA,IAAC,OAAA,CAAK,UAAU,OAAO,SAAA,mBAAA,CAAiB,CAAA,EAC5C,EACAA,EAAAA,IAAC,IAAA,CAAE,UAAU,2BAA2B,SAAA,uEAAA,CAAqE,CAAA,EACjH,EACAD,EAAAA,KAAC,MAAA,CAAI,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