Spaces:
Configuration error
Configuration error
Commit Β·
eb69de5
1
Parent(s): 5b4b486
commit initial 09-12-2025 017
Browse filesFiles changed (2)
- src/App.css+43
- src/App.js+102-120
405 unmodified lines406407408405 unmodified lineswidth: auto;}}405 unmodified lines406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451405 unmodified lineswidth: auto;}}/* ---------- progress bar under menubar ---------- */.ide-progress-wrap {height: 3px;background: transparent;width: 100%;position: relative;overflow: hidden;}.ide-progress {position: absolute;height: 3px;width: 30%;left: -30%;top: 0;background: linear-gradient(90deg, #0e9, #08f);animation: progress-slide 1.2s linear infinite;border-radius: 2px;}@keyframes progress-slide {0% { left: -30%; width: 30%; }50% { left: 35%; width: 40%; }100% { left: 100%; width: 30%; }}/* ---------- small inline spinner (optional) ---------- */.button-spinner {display: inline-block;width: 12px;height: 12px;border: 2px solid rgba(255,255,255,0.25);border-top-color: rgba(255,255,255,0.95);border-radius: 50%;animation: spin 0.8s linear infinite;margin-left: 6px;vertical-align: middle;}@keyframes spin {to { transform: rotate(360deg); }}
48 unmodified lines49505152535414 unmodified lines69707172737475767 unmodified lines848586878889905 unmodified lines969798991001011021031041051061073 unmodified lines1111121131141151161173 unmodified lines1211221231241251261271 unmodified line1291301311321331341359 unmodified lines14514614714814915015115215315412 unmodified lines1671681691701711721731741751761771781791801811822 unmodified lines1851861871881891901911926 unmodified lines1992002012022032042052062072 unmodified lines2102112122132142152162172182192202212 unmodified lines22422522622722822923023123223323423523623723823924024124224324424524624713 unmodified lines26126226326426526626712 unmodified lines28028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833919 unmodified lines3593603613623633643653663673683693703713723732 unmodified lines37637737837938038138238338438538638714 unmodified lines4024034044054064074084094104114124134144154164174188 unmodified lines42742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047148 unmodified linesconst editorRef = useRef(null);const fileInputRef = useRef(null);// Always persist tree on changeuseEffect(() => {saveTree(tree);14 unmodified lines};// ---------- File / Folder actions ----------// Create a new file inside selected folder (or root)const handleNewFile = () => {const filename = window.prompt("Filename (with extension):", "untitled.js");if (!filename) return;7 unmodified linesparentPath = parts.join("/");}// Offer user to choose another parent folderconst folders = collectFolderPaths(tree);const suggestion = parentPath || folders[0] || "";const chosen = window.prompt(5 unmodified linesconst updated = addFile(tree, filename, targetParent);setTree(updated);// Set active to newly created fileconst newPath = (targetParent ? targetParent + "/" : "") + filename;setActivePath(newPath);};// Create a folder under selected folder or rootconst handleNewFolder = () => {const name = window.prompt("Folder name:", "new_folder");if (!name) return;3 unmodified linessetTree(updated);};// Rename selected node (file or folder)const handleRename = () => {if (!activePath) return;const node = getNodeByPath(tree, activePath);3 unmodified linesconst updated = renameNode(tree, activePath, newName);setTree(updated);// compute new activePath (preserve parent)const parts = activePath.split("/");parts.pop();const parent = parts.join("/");1 unmodified linesetActivePath(newPath);};// Delete selected node (confirm if folder not empty)const handleDelete = () => {if (!activePath) return;const node = getNodeByPath(tree, activePath);9 unmodified linesconst updated = deleteNode(tree, activePath);setTree(updated);setActivePath(""); // deselect / fallback};// Download single fileconst downloadFile = () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") return;12 unmodified linesif (!f) return;const text = await f.text();// decide parent folderconst selected = getNodeByPath(tree, activePath);let parentPath = "";if (selected?.type === "folder") parentPath = selected.path; // fallback// (above line intentionally split to maintain code clarity)// compute parent path correctly:if (selected?.type === "folder") parentPath = selected.path;else if (selected?.type === "file") parentPath = selected.path.split("/").slice(0, -1).join("");// create file under parent and write contentconst updated = addFile(tree, f.name, parentPath);const newPath = (parentPath ? parentPath + "/" : "") + f.name;const finalTree = updateFileContent(updated, newPath, text);2 unmodified linese.target.value = "";};// ---------- Run & Agent ----------const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {6 unmodified linesreturn;}const res = await runCode(node.content, selectedLang, stdin);setOutput(res.output || "");setProblems(res.error ? parseProblems(res.output) : []);};const handleAskFix = async () => {2 unmodified linessetOutput("Select a file to apply fix.");return;}const userHint = prompt.trim() ? `User request: ${prompt}` : "";const reply = await askAgent(`Improve, debug, or refactor this ${LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id || "file"} file.\n${userHint}\nReturn ONLY updated code, no explanation.\n\nCODE:\n${node.content}`);const updatedTree = updateFileContent(tree, node.path, reply);setTree(updatedTree);};const handleExplainSelection = async () => {2 unmodified linessetExplanation("Select a file to explain.");return;}const editor = editorRef.current;let selectedCode = "";try {selectedCode = editor?.getModel()?.getValueInRange(editor.getSelection()) || "";} catch {}const code = selectedCode.trim() || node.content;const userHint = prompt.trim() ? `Focus on: ${prompt}` : "Give a clear and simple explanation.";const reply = await askAgent(`Explain what this code does, any risks, and improvements.\n${userHint}\n\nCODE:\n${code}`);setExplanation(reply);};// AI suggestions for continuation (simple)const fetchAiSuggestions = async (code) => {if (!code?.trim()) return;const reply = await askAgent(`Suggest possible next lines for continuation. Return 3 short snippets.\n${code}`);setAiSuggestions(reply.split("\n").filter((l) => l.trim()));};// ---------- Search ----------13 unmodified linessetTree(updated);};// ---------- Render Tree (moved inside component so it sees activePath) ----------const renderTree = (node, depth = 0) => {const isActive = node.path === activePath;return (12 unmodified lines<span className="ide-file-name">{node.name}</span></div>{node.children &&node.children.map((c) => renderTree(c, depth + 1))}</div>);};// ---------- JSX UI ----------return (<div className={`ide-root ${theme === "vs-dark" ? "ide-dark" : "ide-light"}`}>{/* Hidden file input for import */}<inputref={fileInputRef}id="file-import-input"type="file"style={{ display: "none" }}onChange={handleFileInputChange}/>{/* Top menu */}<div className="ide-menubar"><div className="ide-menubar-left"><span className="ide-logo">βοΈ DevMate IDE</span><button onClick={handleNewFile}>π New File</button><button onClick={handleNewFolder}>π New Folder</button><button onClick={handleRename}>βοΈ Rename</button><button onClick={handleDelete}>π Delete</button><button onClick={downloadFile}>π₯ Download</button><button onClick={() => downloadProjectZip()}>π¦ ZIP</button><button onClick={handleImportFileClick}>π€ Import File</button></div><div className="ide-menubar-right"><button onClick={handleSearchToggle}>π Search</button><button onClick={handleRun}>βΆ Run</button><button onClick={handleAskFix}>π€ Fix</button><button onClick={handleExplainSelection}>π Explain</button><button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))}>{theme === "vs-dark" ? "βοΈ" : "π"}</button></div></div>{/* Body */}<div className="ide-body">{/* Sidebar */}<div className="ide-sidebar"><div className="ide-sidebar-header"><span>EXPLORER</span><button className="ide-icon-button" onClick={handleNewFile} title="New File">οΌ</button></div><div className="ide-file-list" style={{ padding: 6 }}>{renderTree(tree)}</div></div>{/* Main (editor + bottom panels) */}19 unmodified lines{aiSuggestions.length > 0 && (<div className="ai-popup">{aiSuggestions.map((s, i) => (<divkey={i}className="ai-suggest"onClick={() =>updateActiveFileContent((currentNode?.content || "") + "\n" + s)}>{s}</div>))}</div>)}2 unmodified lines<div className="ide-panels"><pre className="ide-output">{output}</pre><inputclassName="ide-input-box"placeholder="Program input..."value={stdin}onChange={(e) => setStdin(e.target.value)}/>{problems.length > 0 && (<div className="ide-problems-panel">14 unmodified lines<div className="ide-ai-section"><label className="ide-ai-label">Instruction</label><textareaclassName="ide-agent-textarea"placeholder="Ask the AI (optimize, add tests, convert, etc.)"value={prompt}onChange={(e) => setPrompt(e.target.value)}/></div><div className="ide-ai-buttons"><button onClick={handleAskFix}>π‘ Apply Fix</button><button onClick={handleExplainSelection}>π Explain Code</button></div>{explanation && (8 unmodified lines{/* Search dialog */}{searchOpen && (<div className="search-dialog"><inputplaceholder="Search text..."onChange={(e) => setSearchQuery(e.target.value)}/><button onClick={handleSearchNow}>Search</button></div>)}{/* Context menu */}{contextMenu && (<divclassName="ide-context-menu"style={{ top: contextMenu.y, left: contextMenu.x }}onMouseLeave={() => setContextMenu(null)}><divonClick={() => {setContextMenu(null);handleRename();}}>βοΈ Rename</div><divonClick={() => {setContextMenu(null);handleDelete();}}>π Delete</div><divonClick={() => {setContextMenu(null);downloadFile();}}>π₯ Download</div></div>)}</div>48 unmodified lines495051525354555657585914 unmodified lines7475767778797 unmodified lines8788899091925 unmodified lines98991001011021031041051061073 unmodified lines1111121131141151163 unmodified lines1201211221231241251 unmodified line1271281291301311329 unmodified lines14214314414514614714814915012 unmodified lines1631641651661671681691701711721732 unmodified lines1761771781791801811826 unmodified lines1891901911921931941951961971981992002012022032042052062 unmodified lines2092102112122132142152162172182192202212222232242252262272 unmodified lines23023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326413 unmodified lines27827928028128228328412 unmodified lines29729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636719 unmodified lines3873883893903913923932 unmodified lines39639739839940040140214 unmodified lines4174184194204214224234244254264274288 unmodified lines43743843944044144244344444544644744844945045145245348 unmodified linesconst editorRef = useRef(null);const fileInputRef = useRef(null);// NEW: loading statesconst [isRunning, setIsRunning] = useState(false);const [isFixing, setIsFixing] = useState(false);const [isExplaining, setIsExplaining] = useState(false);// Always persist tree on changeuseEffect(() => {saveTree(tree);14 unmodified lines};// ---------- File / Folder actions ----------const handleNewFile = () => {const filename = window.prompt("Filename (with extension):", "untitled.js");if (!filename) return;7 unmodified linesparentPath = parts.join("/");}const folders = collectFolderPaths(tree);const suggestion = parentPath || folders[0] || "";const chosen = window.prompt(5 unmodified linesconst updated = addFile(tree, filename, targetParent);setTree(updated);const newPath = (targetParent ? targetParent + "/" : "") + filename;setActivePath(newPath);};const handleNewFolder = () => {const name = window.prompt("Folder name:", "new_folder");if (!name) return;3 unmodified linessetTree(updated);};const handleRename = () => {if (!activePath) return;const node = getNodeByPath(tree, activePath);3 unmodified linesconst updated = renameNode(tree, activePath, newName);setTree(updated);const parts = activePath.split("/");parts.pop();const parent = parts.join("/");1 unmodified linesetActivePath(newPath);};const handleDelete = () => {if (!activePath) return;const node = getNodeByPath(tree, activePath);9 unmodified linesconst updated = deleteNode(tree, activePath);setTree(updated);setActivePath("");};const downloadFile = () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") return;12 unmodified linesif (!f) return;const text = await f.text();const selected = getNodeByPath(tree, activePath);let parentPath = "";if (selected?.type === "folder") parentPath = selected.path;else if (selected?.type === "file") parentPath = selected.path.split("/").slice(0, -1).join("");const updated = addFile(tree, f.name, parentPath);const newPath = (parentPath ? parentPath + "/" : "") + f.name;const finalTree = updateFileContent(updated, newPath, text);2 unmodified linese.target.value = "";};// ---------- Run & Agent (with progress flags) ----------const handleRun = async () => {const node = getNodeByPath(tree, activePath);if (!node || node.type !== "file") {6 unmodified linesreturn;}setIsRunning(true);setOutput(""); // clear previoussetProblems([]);try {const res = await runCode(node.content, selectedLang, stdin);setOutput(res.output || "");setProblems(res.error ? parseProblems(res.output) : []);} catch (err) {setOutput(String(err));} finally {setIsRunning(false);}};const handleAskFix = async () => {2 unmodified linessetOutput("Select a file to apply fix.");return;}setIsFixing(true);try {const userHint = prompt.trim() ? `User request: ${prompt}` : "";const reply = await askAgent(`Improve, debug, or refactor this ${LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id || "file"} file.\n${userHint}\nReturn ONLY updated code, no explanation.\n\nCODE:\n${node.content}`);const updatedTree = updateFileContent(tree, node.path, reply);setTree(updatedTree);} catch (err) {setOutput(String(err));} finally {setIsFixing(false);}};const handleExplainSelection = async () => {2 unmodified linessetExplanation("Select a file to explain.");return;}setIsExplaining(true);try {const editor = editorRef.current;let selectedCode = "";try {selectedCode = editor?.getModel()?.getValueInRange(editor.getSelection()) || "";} catch {}const code = selectedCode.trim() || node.content;const userHint = prompt.trim() ? `Focus on: ${prompt}` : "Give a clear and simple explanation.";const reply = await askAgent(`Explain what this code does, any risks, and improvements.\n${userHint}\n\nCODE:\n${code}`);setExplanation(reply);} catch (err) {setExplanation(String(err));} finally {setIsExplaining(false);}};// AI suggestions for continuation (simple)const fetchAiSuggestions = async (code) => {if (!code?.trim()) return;try {const reply = await askAgent(`Suggest possible next lines for continuation. Return 3 short snippets.\n${code}`);setAiSuggestions(reply.split("\n").filter((l) => l.trim()));} catch {// ignore suggestion errors}};// ---------- Search ----------13 unmodified linessetTree(updated);};// ---------- Render Tree (inside component) ----------const renderTree = (node, depth = 0) => {const isActive = node.path === activePath;return (12 unmodified lines<span className="ide-file-name">{node.name}</span></div>{node.children && node.children.map((c) => renderTree(c, depth + 1))}</div>);};// any loading?const anyLoading = isRunning || isFixing || isExplaining;// ---------- JSX UI ----------return (<div className={`ide-root ${theme === "vs-dark" ? "ide-dark" : "ide-light"}`}>{/* Hidden file input for import */}<input ref={fileInputRef} id="file-import-input" type="file" style={{ display: "none" }} onChange={handleFileInputChange} />{/* Top menu */}<div className="ide-menubar"><div className="ide-menubar-left"><span className="ide-logo">βοΈ DevMate IDE</span><button onClick={handleNewFile} disabled={anyLoading}>π New File</button><button onClick={handleNewFolder} disabled={anyLoading}>π New Folder</button><button onClick={handleRename} disabled={anyLoading}>βοΈ Rename</button><button onClick={handleDelete} disabled={anyLoading}>π Delete</button><button onClick={downloadFile} disabled={anyLoading}>π₯ Download</button><button onClick={() => downloadProjectZip()} disabled={anyLoading}>π¦ ZIP</button><button onClick={handleImportFileClick} disabled={anyLoading}>π€ Import File</button></div><div className="ide-menubar-right"><button onClick={handleSearchToggle} disabled={anyLoading}>π Search</button><button onClick={handleRun} disabled={isRunning || anyLoading}>{isRunning ? "β³ Running..." : "βΆ Run"}</button><button onClick={handleAskFix} disabled={isFixing || anyLoading}>{isFixing ? "β³ Fixing..." : "π€ Fix"}</button><button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}>{isExplaining ? "β³ Explaining..." : "π Explain"}</button><button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))} disabled={anyLoading}>{theme === "vs-dark" ? "βοΈ" : "π"}</button></div></div>{/* Indeterminate progress bar under menubar when busy */}{anyLoading && (<div className="ide-progress-wrap"><div className="ide-progress" /></div>)}{/* Body */}<div className="ide-body">{/* Sidebar */}<div className="ide-sidebar"><div className="ide-sidebar-header"><span>EXPLORER</span><button className="ide-icon-button" onClick={handleNewFile} title="New File" disabled={anyLoading}>οΌ</button></div><div className="ide-file-list" style={{ padding: 6 }}>{renderTree(tree)}</div></div>{/* Main (editor + bottom panels) */}19 unmodified lines{aiSuggestions.length > 0 && (<div className="ai-popup">{aiSuggestions.map((s, i) => (<div key={i} className="ai-suggest" onClick={() => updateActiveFileContent((currentNode?.content || "") + "\n" + s)}>{s}</div>))}</div>)}2 unmodified lines<div className="ide-panels"><pre className="ide-output">{output}</pre><input className="ide-input-box" placeholder="Program input..." value={stdin} onChange={(e) => setStdin(e.target.value)} />{problems.length > 0 && (<div className="ide-problems-panel">14 unmodified lines<div className="ide-ai-section"><label className="ide-ai-label">Instruction</label><textarea className="ide-agent-textarea" placeholder="Ask the AI (optimize, add tests, convert, etc.)" value={prompt} onChange={(e) => setPrompt(e.target.value)} /></div><div className="ide-ai-buttons"><button onClick={handleAskFix} disabled={isFixing || anyLoading}>{isFixing ? "β³ Apply Fix" : "π‘ Apply Fix"}</button><button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}>{isExplaining ? "β³ Explaining" : "π Explain Code"}</button></div>{explanation && (8 unmodified lines{/* Search dialog */}{searchOpen && (<div className="search-dialog"><input placeholder="Search text..." onChange={(e) => setSearchQuery(e.target.value)} /><button onClick={handleSearchNow}>Search</button></div>)}{/* Context menu */}{contextMenu && (<div className="ide-context-menu" style={{ top: contextMenu.y, left: contextMenu.x }} onMouseLeave={() => setContextMenu(null)}><div onClick={() => { setContextMenu(null); handleRename(); }}>βοΈ Rename</div><div onClick={() => { setContextMenu(null); handleDelete(); }}>π Delete</div><div onClick={() => { setContextMenu(null); downloadFile(); }}>π₯ Download</div></div>)}</div>
src/App.css+43
src/App.js+102-120