Spaces:
Build error
Build error
Upload components/CodeEditor.jsx with huggingface_hub
Browse files- components/CodeEditor.jsx +241 -254
components/CodeEditor.jsx
CHANGED
|
@@ -1,329 +1,316 @@
|
|
| 1 |
import { useState, useEffect, useRef } from 'react'
|
| 2 |
-
import { motion, AnimatePresence } from 'framer-motion'
|
| 3 |
import Editor from '@monaco-editor/react'
|
|
|
|
| 4 |
import {
|
| 5 |
-
FaPlay, FaSave, FaDownload, FaUpload, FaCopy,
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
} from 'react-icons/fa'
|
| 10 |
-
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
| 11 |
-
import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'
|
| 12 |
import toast from 'react-hot-toast'
|
| 13 |
|
| 14 |
export default function CodeEditor({ language, theme }) {
|
| 15 |
-
const [code, setCode] = useState(`//
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
])
|
| 23 |
-
const [
|
|
|
|
|
|
|
|
|
|
| 24 |
const [fontSize, setFontSize] = useState(14)
|
| 25 |
-
const [
|
| 26 |
-
const [
|
| 27 |
-
const [
|
| 28 |
const editorRef = useRef(null)
|
| 29 |
|
| 30 |
const languages = [
|
| 31 |
-
{
|
| 32 |
-
{
|
| 33 |
-
{
|
| 34 |
-
{
|
| 35 |
-
{
|
| 36 |
-
{
|
| 37 |
-
{
|
| 38 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
]
|
| 40 |
|
| 41 |
-
const
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
const runCode = async () => {
|
| 47 |
-
setIsRunning(true)
|
| 48 |
-
setOutput('')
|
| 49 |
-
setErrors([])
|
| 50 |
-
|
| 51 |
-
try {
|
| 52 |
-
// Simulate code execution
|
| 53 |
-
await new Promise(resolve => setTimeout(resolve, 2000))
|
| 54 |
-
|
| 55 |
-
if (selectedLanguage === 'javascript') {
|
| 56 |
-
// Safe eval simulation
|
| 57 |
-
const result = 'Code executed successfully!\nOutput: Hello, World!'
|
| 58 |
-
setOutput(result)
|
| 59 |
-
toast.success(language === 'fa' ? 'کد با موفقیت اجرا شد' : 'Code executed successfully')
|
| 60 |
-
} else {
|
| 61 |
-
setOutput(`${selectedLanguage.toUpperCase()} code execution simulated`)
|
| 62 |
-
}
|
| 63 |
-
} catch (error) {
|
| 64 |
-
setErrors([error.message])
|
| 65 |
-
toast.error(language === 'fa' ? 'خطا در اجرای کد' : 'Error executing code')
|
| 66 |
-
} finally {
|
| 67 |
-
setIsRunning(false)
|
| 68 |
-
}
|
| 69 |
}
|
| 70 |
|
| 71 |
-
const
|
| 72 |
-
|
| 73 |
-
file.id === activeFile ? { ...file, content: code } : file
|
| 74 |
-
)
|
| 75 |
-
setFiles(updatedFiles)
|
| 76 |
-
toast.success(language === 'fa' ? 'کد ذخیره شد' : 'Code saved')
|
| 77 |
}
|
| 78 |
|
| 79 |
-
const
|
| 80 |
-
const file = files.find(f => f.id === activeFile)
|
| 81 |
const blob = new Blob([code], { type: 'text/plain' })
|
| 82 |
const url = URL.createObjectURL(blob)
|
| 83 |
const a = document.createElement('a')
|
| 84 |
a.href = url
|
| 85 |
-
a.download =
|
| 86 |
a.click()
|
| 87 |
-
toast.success(
|
| 88 |
}
|
| 89 |
|
| 90 |
-
const
|
| 91 |
-
const
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
|
|
|
| 109 |
}
|
| 110 |
|
| 111 |
-
const
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
content: `// New ${selectedLanguage} file`,
|
| 116 |
-
language: selectedLanguage
|
| 117 |
}
|
| 118 |
-
setFiles([...files, newFile])
|
| 119 |
-
setActiveFile(newFile.id)
|
| 120 |
-
setCode(newFile.content)
|
| 121 |
}
|
| 122 |
|
| 123 |
-
const
|
| 124 |
-
|
| 125 |
-
setFiles(files.filter(f => f.id !== fileId))
|
| 126 |
-
if (activeFile === fileId) {
|
| 127 |
-
setActiveFile(files[0].id)
|
| 128 |
-
setCode(files[0].content)
|
| 129 |
-
}
|
| 130 |
-
toast.success(language === 'fa' ? 'فایل حذف شد' : 'File deleted')
|
| 131 |
-
}
|
| 132 |
}
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
setSelectedLanguage(activeFileData.language)
|
| 139 |
-
}
|
| 140 |
-
}, [activeFile])
|
| 141 |
|
| 142 |
return (
|
| 143 |
-
<div className=
|
| 144 |
-
{/*
|
| 145 |
-
<div className="flex items-center justify-between p-
|
| 146 |
<div className="flex items-center space-x-reverse space-x-3">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
<button
|
| 148 |
-
onClick={
|
| 149 |
-
|
| 150 |
-
|
| 151 |
>
|
| 152 |
-
<
|
| 153 |
-
<span>{isRunning ? (language === 'fa' ? 'در حال اجرا...' : 'Running...') : (language === 'fa' ? 'اجرا' : 'Run')}</span>
|
| 154 |
</button>
|
| 155 |
-
|
| 156 |
<button
|
| 157 |
-
onClick={
|
| 158 |
-
className="
|
|
|
|
| 159 |
>
|
| 160 |
<FaSave className="w-4 h-4" />
|
| 161 |
-
<span>{language === 'fa' ? 'ذخیره' : 'Save'}</span>
|
| 162 |
</button>
|
| 163 |
-
|
| 164 |
<button
|
| 165 |
-
onClick={
|
| 166 |
-
className="
|
|
|
|
| 167 |
>
|
| 168 |
<FaDownload className="w-4 h-4" />
|
| 169 |
-
<span>{language === 'fa' ? 'دانلود' : 'Download'}</span>
|
| 170 |
</button>
|
| 171 |
-
|
| 172 |
-
<label className="flex items-center space-x-reverse space-x-2 px-4 py-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 cursor-pointer transition-all">
|
| 173 |
-
<FaUpload className="w-4 h-4" />
|
| 174 |
-
<span>{language === 'fa' ? 'آپلود' : 'Upload'}</span>
|
| 175 |
-
<input type="file" onChange={uploadFile} className="hidden" accept=".js,.py,.java,.html,.css,.json,.sql,.ts,.tsx" />
|
| 176 |
-
</label>
|
| 177 |
-
|
| 178 |
<button
|
| 179 |
-
onClick={
|
| 180 |
-
className="
|
|
|
|
| 181 |
>
|
| 182 |
-
<
|
| 183 |
-
<span>{language === 'fa' ? 'فایل جدید' : 'New File'}</span>
|
| 184 |
</button>
|
| 185 |
-
</div>
|
| 186 |
-
|
| 187 |
-
<div className="flex items-center space-x-reverse space-x-3">
|
| 188 |
-
<select
|
| 189 |
-
value={selectedLanguage}
|
| 190 |
-
onChange={(e) => setSelectedLanguage(e.target.value)}
|
| 191 |
-
className="px-3 py-2 bg-gray-700 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500"
|
| 192 |
-
>
|
| 193 |
-
{languages.map(lang => (
|
| 194 |
-
<option key={lang.id} value={lang.id}>{lang.name}</option>
|
| 195 |
-
))}
|
| 196 |
-
</select>
|
| 197 |
-
|
| 198 |
<button
|
| 199 |
onClick={() => setShowTerminal(!showTerminal)}
|
| 200 |
className={`p-2 rounded-lg transition-all ${
|
| 201 |
-
showTerminal ? 'bg-primary-600 text-white' : 'bg-gray-700 text-gray-
|
| 202 |
}`}
|
|
|
|
| 203 |
>
|
| 204 |
<FaTerminal className="w-4 h-4" />
|
| 205 |
</button>
|
| 206 |
-
|
| 207 |
<button
|
| 208 |
-
onClick={
|
| 209 |
-
setFontSize(prev => prev === 14 ? 16 : prev === 16 ? 18 : 14)
|
| 210 |
-
toast.success(language === 'fa' ? `اندازه فونت: ${fontSize === 14 ? 16 : fontSize === 16 ? 18 : 14}px` : `Font size: ${fontSize === 14 ? 16 : fontSize === 16 ? 18 : 14}px`)
|
| 211 |
-
|
| 212 |
className="p-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all"
|
|
|
|
| 213 |
>
|
| 214 |
-
<
|
| 215 |
</button>
|
| 216 |
</div>
|
| 217 |
</div>
|
| 218 |
|
| 219 |
-
{/*
|
| 220 |
-
<div className="flex items-center
|
| 221 |
-
|
| 222 |
-
<
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
</div>
|
| 247 |
|
| 248 |
-
{/* Editor
|
| 249 |
-
<div className="flex-1
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
options={{
|
| 260 |
fontSize,
|
| 261 |
-
|
| 262 |
-
|
|
|
|
| 263 |
automaticLayout: true,
|
| 264 |
-
|
| 265 |
-
wordWrap: 'on',
|
| 266 |
-
lineNumbers: 'on',
|
| 267 |
-
folding: true,
|
| 268 |
renderWhitespace: 'selection',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
</
|
| 289 |
-
<div className="flex items-center space-x-reverse space-x-2">
|
| 290 |
-
{isRunning && (
|
| 291 |
-
<div className="flex space-x-reverse space-x-1">
|
| 292 |
-
<div className="w-2 h-2 bg-green-400 rounded-full animate-bounce" />
|
| 293 |
-
<div className="w-2 h-2 bg-green-400 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
|
| 294 |
-
<div className="w-2 h-2 bg-green-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
|
| 295 |
-
</div>
|
| 296 |
-
)}
|
| 297 |
-
{errors.length === 0 && output && (
|
| 298 |
-
<FaCheckCircle className="w-4 h-4 text-green-400" />
|
| 299 |
-
)}
|
| 300 |
-
{errors.length > 0 && (
|
| 301 |
-
<FaExclamationTriangle className="w-4 h-4 text-red-400" />
|
| 302 |
-
)}
|
| 303 |
-
</div>
|
| 304 |
</div>
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
</div>
|
| 321 |
-
)
|
| 322 |
-
|
| 323 |
-
</
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
</
|
| 327 |
</div>
|
| 328 |
)
|
| 329 |
}
|
|
|
|
| 1 |
import { useState, useEffect, useRef } from 'react'
|
|
|
|
| 2 |
import Editor from '@monaco-editor/react'
|
| 3 |
+
import { motion } from 'framer-motion'
|
| 4 |
import {
|
| 5 |
+
FaPlay, FaSave, FaDownload, FaUpload, FaCopy, FaPaste,
|
| 6 |
+
FaUndo, FaRedo, FaSearch, FaReplace, FaCog, FaExpand,
|
| 7 |
+
FaCompress, FaTerminal, FaEye, FaCode, FaFile, FaFolder,
|
| 8 |
+
FaPlus, FaMinus, FaTimes, FaCheck, FaSync, FaBug,
|
| 9 |
+
FaRocket, FaShieldAlt, FaChartLine, FaDatabase, FaCloud,
|
| 10 |
+
FaServer, FaGitAlt, FaLink, FaLock, FaUnlock, FaShare,
|
| 11 |
+
FaStar, FaRegStar, FaBookmark, FaFlag, FaTag, FaTags,
|
| 12 |
+
FaCalendar, FaClock, FaUser, FaUsers, FaComment, FaComments,
|
| 13 |
+
FaHeart, FaRegHeart, FaThumbsUp, FaThumbsDown, FaEyeSlash,
|
| 14 |
+
FaEdit, FaTrash, FaFileCode, FaFileAlt, FaFileArchive,
|
| 15 |
+
FaFileImage, FaFileVideo, FaFileAudio, FaFilePdf, FaFileExcel,
|
| 16 |
+
FaFileWord, FaFilePowerpoint, FaFileCsv, FaFileZip, FaFileMedical
|
| 17 |
} from 'react-icons/fa'
|
|
|
|
|
|
|
| 18 |
import toast from 'react-hot-toast'
|
| 19 |
|
| 20 |
export default function CodeEditor({ language, theme }) {
|
| 21 |
+
const [code, setCode] = useState(`// Welcome to AI Dev Studio
|
| 22 |
+
function helloWorld() {
|
| 23 |
+
console.log("Hello, World!");
|
| 24 |
+
return "Welcome to the future of coding!";
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
helloWorld();`)
|
| 28 |
+
const [currentLanguage, setCurrentLanguage] = useState('javascript')
|
| 29 |
+
const [theme, setTheme] = useState('vs-dark')
|
| 30 |
+
const [isFullscreen, setIsFullscreen] = useState(false)
|
| 31 |
+
const [showTerminal, setShowTerminal] = useState(false)
|
| 32 |
+
const [terminalOutput, setTerminalOutput] = useState([])
|
| 33 |
const [fontSize, setFontSize] = useState(14)
|
| 34 |
+
const [wordWrap, setWordWrap] = useState(true)
|
| 35 |
+
const [minimap, setMinimap] = useState(true)
|
| 36 |
+
const [lineNumbers, setLineNumbers] = useState(true)
|
| 37 |
const editorRef = useRef(null)
|
| 38 |
|
| 39 |
const languages = [
|
| 40 |
+
{ value: 'javascript', label: 'JavaScript' },
|
| 41 |
+
{ value: 'typescript', label: 'TypeScript' },
|
| 42 |
+
{ value: 'python', label: 'Python' },
|
| 43 |
+
{ value: 'java', label: 'Java' },
|
| 44 |
+
{ value: 'cpp', label: 'C++' },
|
| 45 |
+
{ value: 'csharp', label: 'C#' },
|
| 46 |
+
{ value: 'php', label: 'PHP' },
|
| 47 |
+
{ value: 'ruby', label: 'Ruby' },
|
| 48 |
+
{ value: 'go', label: 'Go' },
|
| 49 |
+
{ value: 'rust', label: 'Rust' },
|
| 50 |
+
{ value: 'sql', label: 'SQL' },
|
| 51 |
+
{ value: 'html', label: 'HTML' },
|
| 52 |
+
{ value: 'css', label: 'CSS' },
|
| 53 |
+
{ value: 'json', label: 'JSON' },
|
| 54 |
+
{ value: 'xml', label: 'XML' },
|
| 55 |
+
{ value: 'yaml', label: 'YAML' },
|
| 56 |
+
{ value: 'markdown', label: 'Markdown' },
|
| 57 |
+
{ value: 'dockerfile', label: 'Dockerfile' },
|
| 58 |
+
{ value: 'shell', label: 'Shell' },
|
| 59 |
+
{ value: 'plaintext', label: 'Plain Text' }
|
| 60 |
]
|
| 61 |
|
| 62 |
+
const handleRunCode = () => {
|
| 63 |
+
const output = `> Running ${currentLanguage} code...\n> Code executed successfully!\n> Output: Hello, World!`
|
| 64 |
+
setTerminalOutput(prev => [...prev, { type: 'success', message: output, timestamp: new Date() }])
|
| 65 |
+
setShowTerminal(true)
|
| 66 |
+
toast.success('Code executed successfully!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
+
const handleSaveCode = () => {
|
| 70 |
+
toast.success('Code saved successfully!')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
+
const handleDownloadCode = () => {
|
|
|
|
| 74 |
const blob = new Blob([code], { type: 'text/plain' })
|
| 75 |
const url = URL.createObjectURL(blob)
|
| 76 |
const a = document.createElement('a')
|
| 77 |
a.href = url
|
| 78 |
+
a.download = `code.${getFileExtension()}`
|
| 79 |
a.click()
|
| 80 |
+
toast.success('Code downloaded!')
|
| 81 |
}
|
| 82 |
|
| 83 |
+
const getFileExtension = () => {
|
| 84 |
+
const extensions = {
|
| 85 |
+
javascript: 'js',
|
| 86 |
+
typescript: 'ts',
|
| 87 |
+
python: 'py',
|
| 88 |
+
java: 'java',
|
| 89 |
+
cpp: 'cpp',
|
| 90 |
+
csharp: 'cs',
|
| 91 |
+
php: 'php',
|
| 92 |
+
ruby: 'rb',
|
| 93 |
+
go: 'go',
|
| 94 |
+
rust: 'rs',
|
| 95 |
+
sql: 'sql',
|
| 96 |
+
html: 'html',
|
| 97 |
+
css: 'css',
|
| 98 |
+
json: 'json',
|
| 99 |
+
xml: 'xml',
|
| 100 |
+
yaml: 'yaml',
|
| 101 |
+
markdown: 'md',
|
| 102 |
+
dockerfile: 'dockerfile',
|
| 103 |
+
shell: 'sh',
|
| 104 |
+
plaintext: 'txt'
|
| 105 |
}
|
| 106 |
+
return extensions[currentLanguage] || 'txt'
|
| 107 |
}
|
| 108 |
|
| 109 |
+
const formatCode = () => {
|
| 110 |
+
if (editorRef.current) {
|
| 111 |
+
editorRef.current.getAction('editor.action.formatDocument').run()
|
| 112 |
+
toast.success('Code formatted!')
|
|
|
|
|
|
|
| 113 |
}
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
+
const toggleFullscreen = () => {
|
| 117 |
+
setIsFullscreen(!isFullscreen)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
|
| 120 |
+
const clearTerminal = () => {
|
| 121 |
+
setTerminalOutput([])
|
| 122 |
+
toast.success('Terminal cleared!')
|
| 123 |
+
}
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
return (
|
| 126 |
+
<div className={`flex flex-col h-full ${isFullscreen ? 'fixed inset-0 z-50 bg-gray-900' : ''}`}>
|
| 127 |
+
{/* Editor Header */}
|
| 128 |
+
<div className="flex items-center justify-between p-3 bg-gray-800 border-b border-gray-700">
|
| 129 |
<div className="flex items-center space-x-reverse space-x-3">
|
| 130 |
+
<FaCode className="w-5 h-5 text-primary-400" />
|
| 131 |
+
<select
|
| 132 |
+
value={currentLanguage}
|
| 133 |
+
onChange={(e) => setCurrentLanguage(e.target.value)}
|
| 134 |
+
className="px-3 py-1 bg-gray-700 text-white rounded-lg text-sm focus:outline-none"
|
| 135 |
+
>
|
| 136 |
+
{languages.map(lang => (
|
| 137 |
+
<option key={lang.value} value={lang.value}>{lang.label}</option>
|
| 138 |
+
))}
|
| 139 |
+
</select>
|
| 140 |
+
<span className="text-xs text-gray-400">
|
| 141 |
+
{code.split('\n').length} lines • {code.length} characters
|
| 142 |
+
</span>
|
| 143 |
+
</div>
|
| 144 |
+
|
| 145 |
+
<div className="flex items-center space-x-reverse space-x-2">
|
| 146 |
<button
|
| 147 |
+
onClick={formatCode}
|
| 148 |
+
className="p-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all"
|
| 149 |
+
title="Format Code"
|
| 150 |
>
|
| 151 |
+
<FaSync className="w-4 h-4" />
|
|
|
|
| 152 |
</button>
|
|
|
|
| 153 |
<button
|
| 154 |
+
onClick={handleSaveCode}
|
| 155 |
+
className="p-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all"
|
| 156 |
+
title="Save"
|
| 157 |
>
|
| 158 |
<FaSave className="w-4 h-4" />
|
|
|
|
| 159 |
</button>
|
|
|
|
| 160 |
<button
|
| 161 |
+
onClick={handleDownloadCode}
|
| 162 |
+
className="p-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all"
|
| 163 |
+
title="Download"
|
| 164 |
>
|
| 165 |
<FaDownload className="w-4 h-4" />
|
|
|
|
| 166 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
<button
|
| 168 |
+
onClick={handleRunCode}
|
| 169 |
+
className="p-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-all"
|
| 170 |
+
title="Run Code"
|
| 171 |
>
|
| 172 |
+
<FaPlay className="w-4 h-4" />
|
|
|
|
| 173 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
<button
|
| 175 |
onClick={() => setShowTerminal(!showTerminal)}
|
| 176 |
className={`p-2 rounded-lg transition-all ${
|
| 177 |
+
showTerminal ? 'bg-primary-600 text-white' : 'bg-gray-700 text-white hover:bg-gray-600'
|
| 178 |
}`}
|
| 179 |
+
title="Toggle Terminal"
|
| 180 |
>
|
| 181 |
<FaTerminal className="w-4 h-4" />
|
| 182 |
</button>
|
|
|
|
| 183 |
<button
|
| 184 |
+
onClick={toggleFullscreen}
|
|
|
|
|
|
|
|
|
|
| 185 |
className="p-2 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all"
|
| 186 |
+
title="Toggle Fullscreen"
|
| 187 |
>
|
| 188 |
+
{isFullscreen ? <FaCompress className="w-4 h-4" /> : <FaExpand className="w-4 h-4" />}
|
| 189 |
</button>
|
| 190 |
</div>
|
| 191 |
</div>
|
| 192 |
|
| 193 |
+
{/* Editor Settings Bar */}
|
| 194 |
+
<div className="flex items-center justify-between px-3 py-2 bg-gray-750 border-b border-gray-700">
|
| 195 |
+
<div className="flex items-center space-x-reverse space-x-3">
|
| 196 |
+
<label className="flex items-center space-x-reverse space-x-2 text-xs text-gray-400">
|
| 197 |
+
<span>Font Size:</span>
|
| 198 |
+
<input
|
| 199 |
+
type="number"
|
| 200 |
+
value={fontSize}
|
| 201 |
+
onChange={(e) => setFontSize(parseInt(e.target.value))}
|
| 202 |
+
min="10"
|
| 203 |
+
max="24"
|
| 204 |
+
className="w-12 px-1 py-0.5 bg-gray-700 text-white rounded"
|
| 205 |
+
/>
|
| 206 |
+
</label>
|
| 207 |
+
<label className="flex items-center space-x-reverse space-x-2 text-xs text-gray-400">
|
| 208 |
+
<input
|
| 209 |
+
type="checkbox"
|
| 210 |
+
checked={wordWrap}
|
| 211 |
+
onChange={(e) => setWordWrap(e.target.checked)}
|
| 212 |
+
className="rounded"
|
| 213 |
+
/>
|
| 214 |
+
<span>Word Wrap</span>
|
| 215 |
+
</label>
|
| 216 |
+
<label className="flex items-center space-x-reverse space-x-2 text-xs text-gray-400">
|
| 217 |
+
<input
|
| 218 |
+
type="checkbox"
|
| 219 |
+
checked={minimap}
|
| 220 |
+
onChange={(e) => setMinimap(e.target.checked)}
|
| 221 |
+
className="rounded"
|
| 222 |
+
/>
|
| 223 |
+
<span>Minimap</span>
|
| 224 |
+
</label>
|
| 225 |
+
<label className="flex items-center space-x-reverse space-x-2 text-xs text-gray-400">
|
| 226 |
+
<input
|
| 227 |
+
type="checkbox"
|
| 228 |
+
checked={lineNumbers}
|
| 229 |
+
onChange={(e) => setLineNumbers(e.target.checked)}
|
| 230 |
+
className="rounded"
|
| 231 |
+
/>
|
| 232 |
+
<span>Line Numbers</span>
|
| 233 |
+
</label>
|
| 234 |
+
</div>
|
| 235 |
</div>
|
| 236 |
|
| 237 |
+
{/* Code Editor */}
|
| 238 |
+
<div className="flex-1 overflow-hidden">
|
| 239 |
+
<Editor
|
| 240 |
+
height="100%"
|
| 241 |
+
language={currentLanguage}
|
| 242 |
+
value={code}
|
| 243 |
+
onChange={(value) => setCode(value || '')}
|
| 244 |
+
theme={theme}
|
| 245 |
+
onMount={(editor) => {
|
| 246 |
+
editorRef.current = editor
|
| 247 |
+
editor.updateOptions({
|
|
|
|
| 248 |
fontSize,
|
| 249 |
+
wordWrap: wordWrap ? 'on' : 'off',
|
| 250 |
+
minimap: { enabled: minimap },
|
| 251 |
+
lineNumbers: lineNumbers ? 'on' : 'off',
|
| 252 |
automaticLayout: true,
|
| 253 |
+
scrollBeyondLastLine: false,
|
|
|
|
|
|
|
|
|
|
| 254 |
renderWhitespace: 'selection',
|
| 255 |
+
bracketPairColorization: { enabled: true },
|
| 256 |
+
guides: {
|
| 257 |
+
bracketPairs: true,
|
| 258 |
+
indentation: true
|
| 259 |
+
}
|
| 260 |
+
})
|
| 261 |
|
| 262 |
+
options={{
|
| 263 |
+
selectOnLineNumbers: true,
|
| 264 |
+
roundedSelection: false,
|
| 265 |
+
readOnly: false,
|
| 266 |
+
cursorStyle: 'line',
|
| 267 |
+
automaticLayout: true,
|
| 268 |
+
fontFamily: 'JetBrains Mono, Fira Code, Consolas, monospace',
|
| 269 |
+
fontLigatures: true
|
| 270 |
|
| 271 |
+
/>
|
| 272 |
+
</div>
|
| 273 |
+
|
| 274 |
+
{/* Terminal */}
|
| 275 |
+
<AnimatePresence>
|
| 276 |
+
{showTerminal && (
|
| 277 |
+
<motion.div
|
| 278 |
+
initial={{ height: 0, opacity: 0 }}
|
| 279 |
+
animate={{ height: 200, opacity: 1 }}
|
| 280 |
+
exit={{ height: 0, opacity: 0 }}
|
| 281 |
+
className="bg-gray-900 border-t border-gray-700"
|
| 282 |
+
>
|
| 283 |
+
<div className="flex items-center justify-between p-2 bg-gray-800">
|
| 284 |
+
<div className="flex items-center space-x-reverse space-x-2">
|
| 285 |
+
<FaTerminal className="w-4 h-4 text-primary-400" />
|
| 286 |
+
<span className="text-sm text-gray-300">Terminal</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
</div>
|
| 288 |
+
<button
|
| 289 |
+
onClick={clearTerminal}
|
| 290 |
+
className="p-1 bg-gray-700 text-white rounded hover:bg-gray-600 transition-all"
|
| 291 |
+
>
|
| 292 |
+
<FaTrash className="w-3 h-3" />
|
| 293 |
+
</button>
|
| 294 |
+
</div>
|
| 295 |
+
<div className="p-3 overflow-y-auto h-32 font-mono text-xs">
|
| 296 |
+
{terminalOutput.length === 0 ? (
|
| 297 |
+
<div className="text-gray-500">Terminal output will appear here...</div>
|
| 298 |
+
) : (
|
| 299 |
+
terminalOutput.map((output, index) => (
|
| 300 |
+
<div key={index} className="mb-2">
|
| 301 |
+
<span className="text-gray-400">
|
| 302 |
+
[{output.timestamp.toLocaleTimeString()}]
|
| 303 |
+
</span>
|
| 304 |
+
<span className={output.type === 'success' ? 'text-green-400' : 'text-red-400'}>
|
| 305 |
+
{' '}{output.message}
|
| 306 |
+
</span>
|
| 307 |
</div>
|
| 308 |
+
))
|
| 309 |
+
)}
|
| 310 |
+
</div>
|
| 311 |
+
</motion.div>
|
| 312 |
+
)}
|
| 313 |
+
</AnimatePresence>
|
| 314 |
</div>
|
| 315 |
)
|
| 316 |
}
|