Spaces:
Running
Running
Download components/CodeEditor.js from powerllm/anycoder-3dfb5929: direct link, hf CLI and curl.
- Browser
- Download file 3.27 kB
-
https://huggingface.co/spaces/powerllm/anycoder-3dfb5929/resolve/main/components/CodeEditor.js
- Command line
-
hf download hf://spaces/powerllm/anycoder-3dfb5929/components/CodeEditor.js
-
curl -L -o CodeEditor.js https://huggingface.co/spaces/powerllm/anycoder-3dfb5929/resolve/main/components/CodeEditor.js
3.27 kB
| import React from 'react'; | |
| const CodeEditor = ({ file, onCommit, onDiscard }) => { | |
| if (!file) { | |
| return ( | |
| <div className="flex-1 flex flex-col items-center justify-center text-app-muted bg-app-bg"> | |
| <i className="fa-regular fa-folder-open text-6xl mb-6 opacity-20"></i> | |
| <h3 className="text-xl font-semibold mb-2">Select a file to view changes</h3> | |
| <p className="max-w-md text-center">Review the diffs and commit your work to the repository.</p> | |
| </div> | |
| ); | |
| } | |
| const lines = file.content.split('\n'); | |
| const getStatusClass = (line) => { | |
| if (line.includes('+') && !line.includes('import')) return 'bg-status-added/10 border-l-2 border-status-added'; | |
| if (line.includes('-') && !line.includes('import')) return 'bg-status-deleted/10 line-through opacity-60 border-l-2 border-status-deleted'; | |
| return 'hover:bg-app-panel/50'; | |
| }; | |
| return ( | |
| <div className="flex-1 flex flex-col bg-app-bg h-full"> | |
| <div className="h-16 border-b border-app-border flex items-center justify-between px-6 bg-app-bg"> | |
| <div className="flex items-center gap-2 font-mono text-sm text-app-muted"> | |
| <span>root</span> | |
| <i className="fa-solid fa-chevron-right text-xs opacity-50"></i> | |
| <span className="text-app-text font-medium">{file.name}</span> | |
| </div> | |
| <div className="flex items-center gap-3"> | |
| <button | |
| onClick={onDiscard} | |
| className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-app-muted hover:text-status-deleted transition-colors" | |
| > | |
| <i className="fa-solid fa-rotate-left"></i> Discard | |
| </button> | |
| <button | |
| onClick={onCommit} | |
| className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-blue-600 rounded-md shadow-lg shadow-accent-primary/20 transition-all transform active:scale-95" | |
| > | |
| <i className="fa-solid fa-check"></i> Commit Changes | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex-1 overflow-auto p-6 font-mono text-sm leading-7 text-gray-300"> | |
| {lines.map((line, idx) => { | |
| // Simple syntax highlighting simulation | |
| let processedLine = line | |
| .replace(/(const|let|var|function|return|import|from)/g, '<span class="text-pink-400 font-bold">$1</span>') | |
| .replace(/('.*?')/g, '<span class="text-cyan-300">$1</span>') | |
| .replace(/(\/\/.*)/g, '<span class="text-gray-500 italic">$1</span>'); | |
| // Mark added/removed lines visually | |
| const isAdded = line.includes('+') && !line.includes('import'); | |
| const isRemoved = line.includes('-') && !line.includes('import'); | |
| return ( | |
| <div key={idx} className={`flex group ${isAdded ? 'bg-status-added/10' : isRemoved ? 'bg-status-deleted/10' : 'hover:bg-app-panel/30'}`}> | |
| <div className="w-10 pr-4 text-right text-gray-600 select-none text-xs border-r border-gray-800 mr-4"> | |
| {idx + 1} | |
| </div> | |
| <div className="flex-1 whitespace-pre pl-2" dangerouslySetInnerHTML={{ __html: processedLine }} /> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| ); | |
| }; |