CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
PromptCraftPad-DjlPLQ1N.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"PromptCraftPad-DjlPLQ1N.js","sources":["../../components/features/PromptCraftPad.tsx"],"sourcesContent":["import React, { useState, useEffect, useMemo } from 'react';\nimport { SparklesIcon } from '../icons.tsx';\nimport { useLocalStorage } from '../../hooks/useLocalStorage.ts';\n\ninterface Prompt {\n    id: number;\n    name: string;\n    text: string;\n}\n\nexport const PromptCraftPad: React.FC = () => {\n    const [prompts, setPrompts] = useLocalStorage<Prompt[]>('devcore_prompts', [\n        { id: 1, name: 'React Component Generator', text: 'Generate a React component named {name} that {description}. Style it with Tailwind CSS.'}\n    ]);\n    const [activePrompt, setActivePrompt] = useState<Prompt | null>(prompts[0] || null);\n    const [editingId, setEditingId] = useState<number | null>(null);\n    const [tempName, setTempName] = useState('');\n    const [variables, setVariables] = useState<Record<string, string>>({});\n\n    const variableNames = useMemo(() => {\n        if (!activePrompt) return [];\n        return [...activePrompt.text.matchAll(/\\{(\\w+)\\}/g)].map(match => match[1]);\n    }, [activePrompt]);\n\n    const renderedPrompt = useMemo(() => {\n        if (!activePrompt) return '';\n        return variableNames.reduce((acc, varName) => {\n            return acc.replace(new RegExp(`\\\\{${varName}\\\\}`, 'g'), variables[varName] || `{${varName}}`);\n        }, activePrompt.text);\n    }, [activePrompt, variables, variableNames]);\n    \n    useEffect(() => {\n        if(!activePrompt && prompts.length > 0) setActivePrompt(prompts[0]);\n        if (activePrompt) setActivePrompt(prompts.find((p: Prompt) => p.id === activePrompt.id) || null);\n    }, [prompts, activePrompt]);\n\n    const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n        if (!activePrompt) return;\n        const updatedPrompt = { ...activePrompt, text: e.target.value };\n        setPrompts(prompts.map((p: Prompt) => p.id === updatedPrompt.id ? updatedPrompt : p));\n    };\n    \n    const handleNameUpdate = (id: number, newName: string) => {\n        setPrompts(prompts.map((p: Prompt) => p.id === id ? {...p, name: newName} : p));\n        setEditingId(null);\n    };\n\n    const handleAddNew = () => {\n        const newPrompt = { id: Date.now(), name: 'New Untitled Prompt', text: '' };\n        setPrompts([...prompts, newPrompt]);\n        setActivePrompt(newPrompt);\n    };\n    \n    const handleDelete = (id: number) => {\n        setPrompts(prompts.filter((p: Prompt) => p.id !== id));\n        if(activePrompt?.id === id) setActivePrompt(prompts.length > 1 ? prompts[0] : null);\n    }\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6\"><h1 className=\"text-3xl font-bold flex items-center\"><SparklesIcon /><span className=\"ml-3\">Prompt Craft Pad</span></h1><p className=\"text-text-secondary mt-1\">Create, save, and manage your favorite AI prompts.</p></header>\n            <div className=\"flex-grow flex gap-6 min-h-0\">\n                <aside className=\"w-1/3 bg-surface border border-border p-4 rounded-lg flex flex-col\">\n                    <h3 className=\"font-bold mb-2\">My Prompts</h3>\n                    <ul className=\"space-y-2 flex-grow overflow-y-auto\">{prompts.map((p: Prompt) => (<li key={p.id} className=\"group flex items-center justify-between\"><div className={`w-full text-left rounded-md ${activePrompt?.id === p.id ? 'bg-primary/10' : ''}`}><button onClick={() => setActivePrompt(p)} onDoubleClick={() => {setEditingId(p.id); setTempName(p.name);}} className={`w-full text-left px-3 py-2 ${activePrompt?.id === p.id ? 'text-primary' : 'hover:bg-gray-100'}`}> {editingId === p.id ? <input autoFocus value={tempName} onChange={e => setTempName(e.target.value)} onBlur={() => handleNameUpdate(p.id, tempName)} onKeyDown={e => e.key === 'Enter' && handleNameUpdate(p.id, tempName)} className=\"bg-gray-100 text-text-primary w-full\"/> : p.name} </button></div><button onClick={() => handleDelete(p.id)} className=\"ml-2 p-1 text-text-secondary hover:text-red-500 opacity-0 group-hover:opacity-100\">&times;</button></li>))}</ul>\n                    <div className=\"mt-4 pt-4 border-t border-border\"><button onClick={handleAddNew} className=\"btn-primary w-full text-sm py-2\">Add New Prompt</button></div>\n                </aside>\n                <main className=\"w-2/3 flex flex-col gap-4\">\n                    {activePrompt ? (<>\n                        <textarea value={activePrompt.text} onChange={handleTextChange} className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm focus:ring-2 focus:ring-primary focus:outline-none\"/>\n                        {variableNames.length > 0 && <div className=\"flex-shrink-0 bg-surface border border-border p-4 rounded-lg\"><h4 className=\"font-bold mb-2\">Test Variables</h4><div className=\"grid grid-cols-2 gap-2\">{variableNames.map(v => (<div key={v}><label className=\"text-xs\">{v}</label><input type=\"text\" value={variables[v] || ''} onChange={e => setVariables({...variables, [v]: e.target.value})} className=\"w-full bg-background border border-border px-2 py-1 rounded text-sm\"/></div>))}</div><h4 className=\"font-bold mt-4 mb-2\">Live Preview</h4><p className=\"text-sm p-2 bg-background rounded border border-border\">{renderedPrompt}</p></div>}\n                    </>) : (<div className=\"flex-grow flex items-center justify-center bg-background rounded-lg text-text-secondary border border-border\">Select a prompt or create a new one.</div>)}\n                </main>\n            </div>\n        </div>\n    );\n};"],"names":["PromptCraftPad","prompts","setPrompts","useLocalStorage","activePrompt","setActivePrompt","useState","editingId","setEditingId","tempName","setTempName","variables","setVariables","variableNames","useMemo","match","renderedPrompt","acc","varName","useEffect","p","handleTextChange","updatedPrompt","handleNameUpdate","id","newName","handleAddNew","newPrompt","handleDelete","jsxs","jsx","SparklesIcon","e","Fragment","v"],"mappings":"gTAUO,MAAMA,EAA2B,IAAM,CAC1C,KAAM,CAACC,EAASC,CAAU,EAAIC,EAA0B,kBAAmB,CACvE,CAAE,GAAI,EAAG,KAAM,4BAA6B,KAAM,yFAAA,CAAyF,CAC9I,EACK,CAACC,EAAcC,CAAe,EAAIC,EAAAA,SAAwBL,EAAQ,CAAC,GAAK,IAAI,EAC5E,CAACM,EAAWC,CAAY,EAAIF,EAAAA,SAAwB,IAAI,EACxD,CAACG,EAAUC,CAAW,EAAIJ,EAAAA,SAAS,EAAE,EACrC,CAAC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