Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Add unified input pane for code generation
Claude30ec98f3b2e6
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 269ea4f2..b2c122ff 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -22,7 +22,6 @@ import { GenerationSettings } from "./components/settings/GenerationSettings";import StartPane from "./components/start-pane/StartPane";import { Commit } from "./components/commits/types";import { createCommit } from "./components/commits/utils";-import GenerateFromText from "./components/generate-from-text/GenerateFromText";function App() {const {@@ -397,10 +396,6 @@ function App() {{IS_RUNNING_ON_CLOUD && !settings.openAiApiKey && <OnboardingNote />}- {appState === AppState.INITIAL && (- <GenerateFromText doCreateFromText={doCreateFromText} />- )}-{/* Rest of the sidebar when we're not in the initial state */}{(appState === AppState.CODING ||appState === AppState.CODE_READY) && (@@ -418,6 +413,7 @@ function App() {{appState === AppState.INITIAL && (<StartPanedoCreate={doCreate}+ doCreateFromText={doCreateFromText}importFromCode={importFromCode}settings={settings}/>diff --git a/frontend/src/components/start-pane/StartPane.tsx b/frontend/src/components/start-pane/StartPane.tsxindex 9b6a52ea..168522f9 100644--- a/frontend/src/components/start-pane/StartPane.tsx+++ b/frontend/src/components/start-pane/StartPane.tsx@@ -1,9 +1,7 @@-import React, { useState } from "react";-import ImageUpload from "../ImageUpload";-import { UrlInputSection } from "../UrlInputSection";-import ImportCodeSection from "../ImportCodeSection";+import React from "react";import { Settings } from "../../types";import { Stack } from "../../lib/stacks";+import UnifiedInputPane from "../unified-input/UnifiedInputPane";interface Props {doCreate: (@@ -11,28 +9,25 @@ interface Props {inputMode: "image" | "video",textPrompt?: string) => void;+ doCreateFromText: (text: string) => void;importFromCode: (code: string, stack: Stack) => void;settings: Settings;}-const StartPane: React.FC<Props> = ({ doCreate, importFromCode, settings }) => {- const [hasImageUpload, setHasImageUpload] = useState(false);-+const StartPane: React.FC<Props> = ({+ doCreate,+ doCreateFromText,+ importFromCode,+ settings,+}) => {return (- <div className="flex flex-col justify-center items-center gap-y-10">- <ImageUpload- setReferenceImages={doCreate}- onUploadStateChange={setHasImageUpload}+ <div className="flex flex-col justify-center items-center py-8">+ <UnifiedInputPane+ doCreate={doCreate}+ doCreateFromText={doCreateFromText}+ importFromCode={importFromCode}+ settings={settings}/>- {!hasImageUpload && (- <>- <UrlInputSection- doCreate={doCreate}- screenshotOneApiKey={settings.screenshotOneApiKey}- />- <ImportCodeSection importFromCode={importFromCode} />- </>- )}</div>);};diff --git a/frontend/src/components/unified-input/UnifiedInputPane.tsx b/frontend/src/components/unified-input/UnifiedInputPane.tsxnew file mode 100644index 00000000..6fcc2aa9--- /dev/null+++ b/frontend/src/components/unified-input/UnifiedInputPane.tsx@@ -0,0 +1,158 @@+import { useState } from "react";+import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";+import { Stack } from "../../lib/stacks";+import { Settings } from "../../types";+import UploadTab from "./tabs/UploadTab";+import UrlTab from "./tabs/UrlTab";+import TextTab from "./tabs/TextTab";+import ImportTab from "./tabs/ImportTab";++interface Props {+ doCreate: (+ images: string[],+ inputMode: "image" | "video",+ textPrompt?: string+ ) => void;+ doCreateFromText: (text: string) => void;+ importFromCode: (code: string, stack: Stack) => void;+ settings: Settings;+}++type InputTab = "upload" | "url" | "text" | "import";++function UnifiedInputPane({+ doCreate,+ doCreateFromText,+ importFromCode,+ settings,+}: Props) {+ const [activeTab, setActiveTab] = useState<InputTab>("upload");++ return (+ <div className="w-full max-w-4xl mx-auto px-4">+ <Tabs+ value={activeTab}+ onValueChange={(value) => setActiveTab(value as InputTab)}+ className="w-full"+ >+ <TabsList className="grid w-full grid-cols-4 mb-6">+ <TabsTrigger value="upload" className="flex items-center gap-2">+ <UploadIcon />+ <span className="hidden sm:inline">Upload</span>+ </TabsTrigger>+ <TabsTrigger value="url" className="flex items-center gap-2">+ <UrlIcon />+ <span className="hidden sm:inline">URL</span>+ </TabsTrigger>+ <TabsTrigger value="text" className="flex items-center gap-2">+ <TextIcon />+ <span className="hidden sm:inline">Text</span>+ </TabsTrigger>+ <TabsTrigger value="import" className="flex items-center gap-2">+ <ImportIcon />+ <span className="hidden sm:inline">Import</span>+ </TabsTrigger>+ </TabsList>++ <TabsContent value="upload" className="mt-0">+ <UploadTab doCreate={doCreate} />+ </TabsContent>++ <TabsContent value="url" className="mt-0">+ <UrlTab+ doCreate={doCreate}+ screenshotOneApiKey={settings.screenshotOneApiKey}+ />+ </TabsContent>++ <TabsContent value="text" className="mt-0">+ <TextTab doCreateFromText={doCreateFromText} />+ </TabsContent>++ <TabsContent value="import" className="mt-0">+ <ImportTab importFromCode={importFromCode} />+ </TabsContent>+ </Tabs>+ </div>+ );+}++function UploadIcon() {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="16"+ height="16"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />+ <polyline points="17 8 12 3 7 8" />+ <line x1="12" y1="3" x2="12" y2="15" />+ </svg>+ );+}++function UrlIcon() {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="16"+ height="16"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />+ <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />+ </svg>+ );+}++function TextIcon() {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="16"+ height="16"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="M17 6.1H3" />+ <path d="M21 12.1H3" />+ <path d="M15.1 18H3" />+ </svg>+ );+}++function ImportIcon() {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="16"+ height="16"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <polyline points="16 18 22 12 16 6" />+ <polyline points="8 6 2 12 8 18" />+ </svg>+ );+}++export default UnifiedInputPane;diff --git a/frontend/src/components/unified-input/tabs/ImportTab.tsx b/frontend/src/components/unified-input/tabs/ImportTab.tsxnew file mode 100644index 00000000..adb51276--- /dev/null+++ b/frontend/src/components/unified-input/tabs/ImportTab.tsx@@ -0,0 +1,104 @@+import { useState, useRef, useEffect } from "react";+import { Button } from "../../ui/button";+import { Textarea } from "../../ui/textarea";+import OutputSettingsSection from "../../settings/OutputSettingsSection";+import toast from "react-hot-toast";+import { Stack } from "../../../lib/stacks";++interface Props {+ importFromCode: (code: string, stack: Stack) => void;+}++function ImportTab({ importFromCode }: Props) {+ const [code, setCode] = useState("");+ const [stack, setStack] = useState<Stack | undefined>(undefined);+ const textareaRef = useRef<HTMLTextAreaElement>(null);++ useEffect(() => {+ textareaRef.current?.focus();+ }, []);++ const doImport = () => {+ if (code === "") {+ toast.error("Please paste in some code");+ return;+ }++ if (stack === undefined) {+ toast.error("Please select your stack");+ return;+ }++ importFromCode(code, stack);+ };++ const handleKeyDown = (e: React.KeyboardEvent) => {+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {+ e.preventDefault();+ doImport();+ }+ };++ return (+ <div className="flex flex-col items-center gap-6">+ <div className="w-full max-w-lg">+ <div className="flex flex-col gap-6 p-8 border border-gray-200 rounded-xl bg-gray-50/50">+ <div className="flex flex-col items-center gap-3">+ <div className="w-16 h-16 rounded-full bg-gray-100 flex items-center justify-center">+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="28"+ height="28"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="text-gray-400"+ >+ <polyline points="16 18 22 12 16 6" />+ <polyline points="8 6 2 12 8 18" />+ </svg>+ </div>++ <div className="text-center">+ <h3 className="text-gray-700 font-medium">Import Existing Code</h3>+ <p className="text-sm text-gray-500 mt-1">+ Paste your HTML code to iterate on it with AI+ </p>+ </div>+ </div>++ <div className="space-y-4">+ <Textarea+ ref={textareaRef}+ value={code}+ onChange={(e) => setCode(e.target.value)}+ onKeyDown={handleKeyDown}+ className="w-full h-48 font-mono text-sm resize-none"+ placeholder="Paste your HTML code here..."+ />++ <OutputSettingsSection+ stack={stack}+ setStack={(config: Stack) => setStack(config)}+ label="Stack:"+ shouldDisableUpdates={false}+ />++ <Button onClick={doImport} className="w-full" size="lg">+ Import Code+ </Button>++ <p className="text-xs text-gray-400 text-center">+ Press Cmd/Ctrl + Enter to import+ </p>+ </div>+ </div>+ </div>+ </div>+ );+}++export default ImportTab;diff --git a/frontend/src/components/unified-input/tabs/TextTab.tsx b/frontend/src/components/unified-input/tabs/TextTab.tsxnew file mode 100644index 00000000..0b865b94--- /dev/null+++ b/frontend/src/components/unified-input/tabs/TextTab.tsx@@ -0,0 +1,118 @@+import { useState, useRef, useEffect } from "react";+import { Button } from "../../ui/button";+import { Textarea } from "../../ui/textarea";+import toast from "react-hot-toast";++interface Props {+ doCreateFromText: (text: string) => void;+}++const EXAMPLE_PROMPTS = [+ "A SaaS admin dashboard with charts and user management",+ "A modern e-commerce product page with reviews",+ "A landing page for a mobile app with pricing",+ "A social media profile page with posts and followers",+];++function TextTab({ doCreateFromText }: Props) {+ const [text, setText] = useState("");+ const textareaRef = useRef<HTMLTextAreaElement>(null);++ useEffect(() => {+ textareaRef.current?.focus();+ }, []);++ const handleGenerate = () => {+ if (text.trim() === "") {+ toast.error("Please enter a description");+ return;+ }+ doCreateFromText(text);+ };++ const handleKeyDown = (e: React.KeyboardEvent) => {+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {+ e.preventDefault();+ handleGenerate();+ }+ };++ const handleExampleClick = (example: string) => {+ setText(example);+ textareaRef.current?.focus();+ };++ return (+ <div className="flex flex-col items-center gap-6">+ <div className="w-full max-w-lg">+ <div className="flex flex-col gap-6 p-8 border border-gray-200 rounded-xl bg-gray-50/50">+ <div className="flex flex-col items-center gap-3">+ <div className="w-16 h-16 rounded-full bg-gray-100 flex items-center justify-center">+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="28"+ height="28"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="text-gray-400"+ >+ <path d="M17 6.1H3" />+ <path d="M21 12.1H3" />+ <path d="M15.1 18H3" />+ </svg>+ </div>++ <div className="text-center">+ <h3 className="text-gray-700 font-medium">Generate from Text</h3>+ <p className="text-sm text-gray-500 mt-1">+ Describe what you want to build+ </p>+ </div>+ </div>++ <div className="space-y-4">+ <Textarea+ ref={textareaRef}+ rows={4}+ placeholder="Describe the UI you want to create..."+ className="w-full resize-none"+ value={text}+ onChange={(e) => setText(e.target.value)}+ onKeyDown={handleKeyDown}+ />++ <div className="flex flex-col gap-2">+ <p className="text-xs text-gray-500">Try an example:</p>+ <div className="flex flex-wrap gap-2">+ {EXAMPLE_PROMPTS.map((example, index) => (+ <button+ key={index}+ onClick={() => handleExampleClick(example)}+ className="text-xs px-2.5 py-1.5 rounded-full bg-gray-100 text-gray-600 hover:bg-gray-200 transition-colors truncate max-w-[200px]"+ title={example}+ >+ {example.length > 30 ? example.slice(0, 30) + "..." : example}+ </button>+ ))}+ </div>+ </div>++ <Button onClick={handleGenerate} className="w-full" size="lg">+ Generate Code+ </Button>++ <p className="text-xs text-gray-400 text-center">+ Press Cmd/Ctrl + Enter to generate+ </p>+ </div>+ </div>+ </div>+ </div>+ );+}++export default TextTab;diff --git a/frontend/src/components/unified-input/tabs/UploadTab.tsx b/frontend/src/components/unified-input/tabs/UploadTab.tsxnew file mode 100644index 00000000..be2b7fbf--- /dev/null+++ b/frontend/src/components/unified-input/tabs/UploadTab.tsx@@ -0,0 +1,318 @@+import { useState, useEffect, useMemo, useRef, useCallback } from "react";+import { useDropzone } from "react-dropzone";+import { toast } from "react-hot-toast";+import { Button } from "../../ui/button";+import { ScreenRecorderState } from "../../../types";+import ScreenRecorder from "../../recording/ScreenRecorder";++function fileToDataURL(file: File): Promise<string> {+ return new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = () => {+ const result = reader.result as string;+ if (result.startsWith("data:application/octet-stream") && file.type) {+ const correctedResult = result.replace(+ "data:application/octet-stream",+ `data:${file.type}`+ );+ resolve(correctedResult);+ } else {+ resolve(result);+ }+ };+ reader.onerror = (error) => reject(error);+ reader.readAsDataURL(file);+ });+}++type FileWithPreview = {+ preview: string;+} & File;++interface Props {+ doCreate: (+ referenceImages: string[],+ inputMode: "image" | "video",+ textPrompt?: string+ ) => void;+}++function UploadTab({ doCreate }: Props) {+ const [files, setFiles] = useState<FileWithPreview[]>([]);+ const [uploadedDataUrls, setUploadedDataUrls] = useState<string[]>([]);+ const [uploadedInputMode, setUploadedInputMode] = useState<+ "image" | "video"+ >("image");+ const [textPrompt, setTextPrompt] = useState("");+ const [showTextPrompt, setShowTextPrompt] = useState(false);+ const textInputRef = useRef<HTMLTextAreaElement>(null);+ const [screenRecorderState, setScreenRecorderState] =+ useState<ScreenRecorderState>(ScreenRecorderState.INITIAL);++ const hasUploadedFile = uploadedDataUrls.length > 0;++ const handleGenerate = useCallback(() => {+ if (uploadedDataUrls.length > 0) {+ doCreate(uploadedDataUrls, uploadedInputMode, textPrompt);+ }+ }, [uploadedDataUrls, uploadedInputMode, textPrompt, doCreate]);++ useEffect(() => {+ if (!hasUploadedFile) return;++ const handleGlobalKeyDown = (e: KeyboardEvent) => {+ if (e.key === "Enter" && !e.shiftKey) {+ if (document.activeElement === textInputRef.current) return;+ e.preventDefault();+ handleGenerate();+ }+ };++ document.addEventListener("keydown", handleGlobalKeyDown);+ return () => document.removeEventListener("keydown", handleGlobalKeyDown);+ }, [hasUploadedFile, handleGenerate]);++ const handleClear = () => {+ setUploadedDataUrls([]);+ setFiles([]);+ setTextPrompt("");+ setShowTextPrompt(false);+ };++ const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {+ if (e.key === "Enter" && !e.shiftKey) {+ e.preventDefault();+ handleGenerate();+ }+ };++ const { getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } =+ useDropzone({+ maxFiles: 1,+ maxSize: 1024 * 1024 * 20,+ accept: {+ "image/png": [".png"],+ "image/jpeg": [".jpeg"],+ "image/jpg": [".jpg"],+ "video/quicktime": [".mov"],+ "video/mp4": [".mp4"],+ "video/webm": [".webm"],+ },+ onDrop: (acceptedFiles) => {+ setFiles(+ acceptedFiles.map((file: File) =>+ Object.assign(file, {+ preview: URL.createObjectURL(file),+ })+ ) as FileWithPreview[]+ );++ const firstFile = acceptedFiles[0];+ const isVideo =+ firstFile?.type?.startsWith("video/") ||+ [".mp4", ".mov", ".webm"].some((ext) =>+ firstFile?.name?.toLowerCase().endsWith(ext)+ );++ Promise.all(acceptedFiles.map((file) => fileToDataURL(file)))+ .then((dataUrls) => {+ if (dataUrls.length > 0) {+ const inputMode =+ isVideo || (dataUrls[0] as string).startsWith("data:video")+ ? "video"+ : "image";+ setUploadedDataUrls(dataUrls as string[]);+ setUploadedInputMode(inputMode);+ setTimeout(() => textInputRef.current?.focus(), 100);+ }+ })+ .catch((error) => {+ toast.error("Error reading files" + error);+ console.error("Error reading files:", error);+ });+ },+ onDropRejected: (rejectedFiles) => {+ toast.error(rejectedFiles[0].errors[0].message);+ },+ });++ useEffect(() => {+ return () => files.forEach((file) => URL.revokeObjectURL(file.preview));+ }, [files]);++ const style = useMemo(() => {+ const baseStyle: React.CSSProperties = {+ flex: 1,+ width: "100%",+ minHeight: "320px",+ display: "flex",+ flexDirection: "column",+ alignItems: "center",+ justifyContent: "center",+ padding: "20px",+ borderWidth: 2,+ borderRadius: 12,+ borderColor: "#e5e7eb",+ borderStyle: "dashed",+ backgroundColor: "#fafafa",+ color: "#6b7280",+ outline: "none",+ transition: "all 0.2s ease-in-out",+ cursor: "pointer",+ };++ if (isFocused) {+ return { ...baseStyle, borderColor: "#3b82f6", backgroundColor: "#eff6ff" };+ }+ if (isDragAccept) {+ return { ...baseStyle, borderColor: "#22c55e", backgroundColor: "#f0fdf4" };+ }+ if (isDragReject) {+ return { ...baseStyle, borderColor: "#ef4444", backgroundColor: "#fef2f2" };+ }+ return baseStyle;+ }, [isFocused, isDragAccept, isDragReject]);++ const handleScreenRecorderGenerate = (+ images: string[],+ inputMode: "image" | "video"+ ) => {+ doCreate(images, inputMode, "");+ };++ return (+ <div className="flex flex-col items-center gap-6">+ {screenRecorderState === ScreenRecorderState.INITIAL && !hasUploadedFile && (+ <div {...getRootProps({ style })}>+ <input {...getInputProps()} />+ <div className="flex flex-col items-center gap-3">+ <div className="w-16 h-16 rounded-full bg-gray-100 flex items-center justify-center">+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="28"+ height="28"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="text-gray-400"+ >+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />+ <polyline points="17 8 12 3 7 8" />+ <line x1="12" y1="3" x2="12" y2="15" />+ </svg>+ </div>+ <div className="text-center">+ <p className="text-gray-700 font-medium">+ Drop a screenshot or video here+ </p>+ <p className="text-sm text-gray-500 mt-1">+ or click to browse+ </p>+ </div>+ <p className="text-xs text-gray-400 mt-2">+ Supports PNG, JPG, MP4, MOV, WebM (max 20MB)+ </p>+ </div>+ </div>+ )}++ {hasUploadedFile && (+ <div className="flex flex-col items-center gap-4 w-full">+ <div className="relative w-full max-w-2xl">+ {uploadedInputMode === "video" ? (+ <video+ src={files[0]?.preview}+ className="w-full h-auto max-h-[400px] object-contain rounded-lg border border-gray-200"+ controls+ />+ ) : (+ <img+ src={files[0]?.preview}+ alt="Uploaded screenshot"+ className="w-full h-auto max-h-[400px] object-contain rounded-lg border border-gray-200"+ />+ )}+ <button+ onClick={handleClear}+ className="absolute top-2 right-2 bg-white rounded-full p-1.5 shadow-md hover:bg-gray-100 transition-colors"+ aria-label="Remove file"+ >+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className="h-4 w-4 text-gray-600"+ viewBox="0 0 20 20"+ fill="currentColor"+ >+ <path+ fillRule="evenodd"+ d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"+ clipRule="evenodd"+ />+ </svg>+ </button>+ </div>++ {!showTextPrompt ? (+ <button+ onClick={() => {+ setShowTextPrompt(true);+ setTimeout(() => textInputRef.current?.focus(), 50);+ }}+ className="text-sm text-gray-500 hover:text-gray-700 underline"+ >+ Add instructions (optional)+ </button>+ ) : (+ <div className="w-full max-w-lg">+ <textarea+ ref={textInputRef}+ value={textPrompt}+ onChange={(e) => setTextPrompt(e.target.value)}+ onKeyDown={handleKeyDown}+ placeholder="Describe any specific requirements..."+ className="w-full p-3 text-sm border border-gray-200 rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-gray-300 focus:border-transparent"+ rows={2}+ />+ </div>+ )}++ <div className="flex flex-col items-center gap-1 w-full max-w-md">+ <Button onClick={handleGenerate} className="w-full" size="lg">+ Generate Code+ </Button>+ <p className="text-xs text-gray-400">Press Enter to generate</p>+ </div>+ </div>+ )}++ {screenRecorderState === ScreenRecorderState.INITIAL && !hasUploadedFile && (+ <div className="flex flex-col items-center gap-3">+ <div className="flex items-center gap-2 text-sm text-gray-500">+ <div className="h-px w-12 bg-gray-300" />+ <span>or</span>+ <div className="h-px w-12 bg-gray-300" />+ </div>+ <ScreenRecorder+ screenRecorderState={screenRecorderState}+ setScreenRecorderState={setScreenRecorderState}+ generateCode={handleScreenRecorderGenerate}+ />+ </div>+ )}++ {!hasUploadedFile &&+ screenRecorderState !== ScreenRecorderState.INITIAL && (+ <ScreenRecorder+ screenRecorderState={screenRecorderState}+ setScreenRecorderState={setScreenRecorderState}+ generateCode={handleScreenRecorderGenerate}+ />+ )}+ </div>+ );+}++export default UploadTab;diff --git a/frontend/src/components/unified-input/tabs/UrlTab.tsx b/frontend/src/components/unified-input/tabs/UrlTab.tsxnew file mode 100644index 00000000..bad4f3c4--- /dev/null+++ b/frontend/src/components/unified-input/tabs/UrlTab.tsx@@ -0,0 +1,147 @@+import { useState } from "react";+import { HTTP_BACKEND_URL } from "../../../config";+import { Button } from "../../ui/button";+import { Input } from "../../ui/input";+import { toast } from "react-hot-toast";++interface Props {+ screenshotOneApiKey: string | null;+ doCreate: (+ urls: string[],+ inputMode: "image" | "video",+ textPrompt?: string+ ) => void;+}++function UrlTab({ doCreate, screenshotOneApiKey }: Props) {+ const [isLoading, setIsLoading] = useState(false);+ const [referenceUrl, setReferenceUrl] = useState("");++ async function takeScreenshot() {+ if (!screenshotOneApiKey) {+ toast.error(+ "Please add a ScreenshotOne API key in Settings. You can also upload screenshots directly in the Upload tab.",+ { duration: 6000 }+ );+ return;+ }++ if (!referenceUrl) {+ toast.error("Please enter a URL");+ return;+ }++ try {+ setIsLoading(true);+ const response = await fetch(`${HTTP_BACKEND_URL}/api/screenshot`, {+ method: "POST",+ body: JSON.stringify({+ url: referenceUrl,+ apiKey: screenshotOneApiKey,+ }),+ headers: {+ "Content-Type": "application/json",+ },+ });++ if (!response.ok) {+ throw new Error("Failed to capture screenshot");+ }++ const res = await response.json();+ doCreate([res.url], "image");+ } catch (error) {+ console.error(error);+ toast.error("Failed to capture screenshot. Check console for details.");+ } finally {+ setIsLoading(false);+ }+ }++ return (+ <div className="flex flex-col items-center gap-6">+ <div className="w-full max-w-lg">+ <div className="flex flex-col items-center gap-6 p-8 border border-gray-200 rounded-xl bg-gray-50/50">+ <div className="w-16 h-16 rounded-full bg-gray-100 flex items-center justify-center">+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="28"+ height="28"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="text-gray-400"+ >+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />+ <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />+ </svg>+ </div>++ <div className="text-center">+ <h3 className="text-gray-700 font-medium">Screenshot from URL</h3>+ <p className="text-sm text-gray-500 mt-1">+ Enter a website URL to capture and generate code+ </p>+ </div>++ <div className="w-full space-y-3">+ <Input+ placeholder="https://example.com"+ onChange={(e) => setReferenceUrl(e.target.value)}+ value={referenceUrl}+ onKeyDown={(e) => {+ if (e.key === "Enter" && !isLoading) {+ takeScreenshot();+ }+ }}+ className="w-full"+ />+ <Button+ onClick={takeScreenshot}+ disabled={isLoading}+ className="w-full"+ size="lg"+ >+ {isLoading ? (+ <span className="flex items-center gap-2">+ <svg+ className="animate-spin h-4 w-4"+ xmlns="http://www.w3.org/2000/svg"+ fill="none"+ viewBox="0 0 24 24"+ >+ <circle+ className="opacity-25"+ cx="12"+ cy="12"+ r="10"+ stroke="currentColor"+ strokeWidth="4"+ />+ <path+ className="opacity-75"+ fill="currentColor"+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"+ />+ </svg>+ Capturing...+ </span>+ ) : (+ "Capture & Generate"+ )}+ </Button>+ </div>++ <p className="text-xs text-gray-400 text-center">+ Press Enter to capture. Requires ScreenshotOne API key.+ </p>+ </div>+ </div>+ </div>+ );+}++export default UrlTab;