MultiImageCompressormain.tsx13 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
45interface CompressedImage {
1112function ImageCompressor() {
13const [images, setImages] = React.useState<CompressedImage[]>([]);
14const [totalCompressed, setTotalCompressed] = React.useState(0);
15const canvasRef = React.useRef<HTMLCanvasElement>(null);
1617// Add useEffect to clean up object URLs
18React.useEffect(() => {
19return () => {
20images.forEach(image => {
26}, [images]);
2728const generatePreview = React.useCallback((file: File): Promise<string> => {
29return new Promise((resolve, reject) => {
30// Try multiple methods to generate preview
64}, []);
6566const compressImage = React.useCallback(async (file: File): Promise<File> => {
67return new Promise((resolve, reject) => {
68const reader = new FileReader();
140}, []);
141142const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
143const files = event.target.files;
144if (!files) return;
342<script src="https://esm.town/v/std/catch"></script>
343<script type="module">
344import React from "https://esm.sh/react@18.2.0";
345import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
346
347const App = (await import(import.meta.url)).default;
348
349createRoot(document.getElementById("root")).render(
350React.createElement(App)
351);
352</script>
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
3import ReactDOM from "https://esm.sh/react-dom@18.2.0";
4import { LiveProvider, LiveEditor, LiveError, LivePreview } from "https://esm.sh/react-live@4.1.0";
5import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter@15.5.0";
6import { atomDark } from "https://esm.sh/react-syntax-highlighter@15.5.0/dist/esm/styles/prism";
78// Error Boundary Component
9class ErrorBoundary extends React.Component {
10constructor(props) {
11super(props);
40const [parsedComponent, setParsedComponent] = useState(null);
4142const generateComponent = async (e: React.FormEvent) => {
43e.preventDefault();
44setIsLoading(true);
62try {
63// eslint-disable-next-line no-new-func
64const ComponentFunc = new Function('React', `return (${code})`)();
65setParsedComponent(() => ComponentFunc);
66} catch (parseError) {
94<div className="max-w-4xl mx-auto p-6 bg-gray-900 min-h-screen">
95<h1 className="text-3xl font-bold text-white mb-6 text-center">
96React Component Generator
97</h1>
98
103value={prompt}
104onChange={(e) => setPrompt(e.target.value)}
105placeholder="Describe your React component (e.g., 'A todo list with add and delete functionality')"
106className="flex-grow p-3 rounded-l-lg bg-gray-800 text-white"
107/>
142{parsedComponent ? (
143<div className="bg-white p-6 rounded-lg">
144{React.createElement(parsedComponent)}
145</div>
146) : (
164const root = document.getElementById("root");
165if (root) {
166ReactDOM.createRoot(root).render(
167<React.StrictMode>
168<App />
169</React.StrictMode>
170);
171}
185{
186role: "system",
187content: `You are an expert React component generator.
188Generate a complete, functional React component based on the user's description.
189- Use modern React with functional components and hooks
190- Include necessary imports (import React from 'react')
191- Provide a fully working component
192- Use inline styles or tailwind if styling is needed
229<html>
230<head>
231<title>React Component Generator</title>
232<script src="https://cdn.tailwindcss.com"></script>
233</head>
cerebras_codermain.tsx11 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import Cerebras from "https://esm.sh/@cerebras/cerebras_cloud_sdk";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client?deps=react@18.2.0";
4import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter?deps=react@18.2.0,react-dom@18.2.0";
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
6import { STARTER_PROMPTS } from "https://esm.town/v/stevekrouse/cerebras_coder_prompts";
7const [uploadedImage, setUploadedImage] = useState<string | null>(null);
8const fileInputRef = React.useRef<HTMLInputElement>(null);
910// random 3 prompts from STARTER_PROMPTS
82}: {
83prompt: string;
84setPrompt: React.Dispatch<React.SetStateAction<string>>;
85handleSubmit: (e: React.FormEvent) => void;
86handleStarterPromptClick: (promptItem: PromptItem) => void;
87}) {
171172function App() {
173const previewRef = React.useRef<HTMLDivElement>(null);
174const [prompt, setPrompt] = useState("");
175const [projectId, setProjectId] = useState<number | null>(null);
229}
230231async function handleSubmit(e: React.FormEvent | string) {
232if (typeof e !== "string") {
233e.preventDefault();
735</div>
736<div className="bg-white w-full h-full flex flex-col grow rounded-xl border-2 border-white overflow-hidden">
737<React.Fragment key={iframeKey}>
738<iframe
739srcDoc={code}
741className="w-full grow"
742/>
743</React.Fragment>
744</div>
745</div>
cerebrasTemplatemain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
4import { email } from "https://esm.town/v/std/email";
5
cerebrasTemplatemain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useState } from "https://esm.sh/react@18.2.0";
45function App() {
cerebrasTemplatemain.tsx3 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useState } from "https://esm.sh/react@18.2.0";
45function App() {
stunningChocolateApemain.tsx2 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 **/
2import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
34export default (req: Request) => {
hopefulGoldChinchillamain.tsx10 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import Cerebras from "https://esm.sh/@cerebras/cerebras_cloud_sdk";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client?deps=react@18.2.0";
4import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter?deps=react@18.2.0,react-dom@18.2.0";
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
6import { STARTER_PROMPTS } from "https://esm.town/v/stevekrouse/cerebras_coder_prompts";
780}: {
81prompt: string;
82setPrompt: React.Dispatch<React.SetStateAction<string>>;
83handleSubmit: (e: React.FormEvent) => void;
84handleStarterPromptClick: (promptItem: PromptItem) => void;
85}) {
169170function App() {
171const previewRef = React.useRef<HTMLDivElement>(null);
172const [prompt, setPrompt] = useState("");
173const [projectId, setProjectId] = useState<number | null>(null);
227}
228229async function handleSubmit(e: React.FormEvent | string) {
230if (typeof e !== "string") {
231e.preventDefault();
733</div>
734<div className="bg-white w-full h-full flex flex-col grow rounded-xl border-2 border-white overflow-hidden">
735<React.Fragment key={iframeKey}>
736<iframe
737srcDoc={code}
739className="w-full grow"
740/>
741</React.Fragment>
742</div>
743</div>
cerebras_codermain.tsx10 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import Cerebras from "https://esm.sh/@cerebras/cerebras_cloud_sdk";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client?deps=react@18.2.0";
4import { Prism as SyntaxHighlighter } from "https://esm.sh/react-syntax-highlighter?deps=react@18.2.0,react-dom@18.2.0";
5import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
6import { STARTER_PROMPTS } from "https://esm.town/v/stevekrouse/cerebras_coder_prompts";
733}: {
34prompt: string;
35setPrompt: React.Dispatch<React.SetStateAction<string>>;
36handleSubmit: (e: React.FormEvent) => void;
37handleStarterPromptClick: (promptItem: PromptItem) => void;
38}) {
122123function App() {
124const previewRef = React.useRef<HTMLDivElement>(null);
125const [prompt, setPrompt] = useState("");
126const [projectId, setProjectId] = useState<number | null>(null);
180}
181182async function handleSubmit(e: React.FormEvent | string) {
183if (typeof e !== "string") {
184e.preventDefault();
679</div>
680<div className="bg-white w-full h-full flex flex-col grow rounded-xl border-2 border-white overflow-hidden">
681<React.Fragment key={iframeKey}>
682<iframe
683srcDoc={code}
685className="w-full grow"
686/>
687</React.Fragment>
688</div>
689</div>
gentleMagentaLizardmain.tsx2 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 **/
2import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
34export default (req: Request) => {