-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
427 lines (389 loc) · 21.8 KB
/
index.html
File metadata and controls
427 lines (389 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Code Editor</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script>
<style>
body {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
color: #f8fafc;
font-family: 'Fira Code', monospace;
}
#editor-container {
height: calc(100vh - 200px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 0.5rem;
background: rgba(255, 255, 255, 0.2);
}
.custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.1);
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.4);
border-radius: 4px;
}
.file-tab {
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-explorer {
width: 250px;
border-right: 1px solid rgba(255, 255, 255, 0.2);
}
#terminal {
height: 200px;
overflow-y: auto;
font-family: 'Fira Code', monospace;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 0.5rem;
}
</style>
</head>
<body class="min-h-screen flex">
<div class="file-explorer bg-gray-800 p-4 overflow-y-auto custom-scrollbar">
<div class="flex items-center justify-between mb-4">
<h2 class="font-bold">Explorer</h2>
<button id="new-file-btn" class="text-gray-400 hover:text-white">
<i class="bi bi-plus-lg"></i>
</button>
</div>
<div id="folder-list" class="space-y-2">
<!-- Folders will be listed here -->
</div>
<div id="file-list" class="space-y-2">
<!-- Files will be listed here -->
</div>
</div>
<div class="flex-1 flex flex-col bg-gray-900">
<div class="bg-gray-800 p-4 flex items-center justify-between">
<div class="flex items-center space-x-4">
<select id="language-selector"
class="bg-gray-700 text-gray-100 px-4 py-2 rounded-lg border border-gray-600">
<option data-icon="bi bi-filetype-js" value="javascript">JavaScript</option>
<option data-icon="bi bi-filetype-py" value="python">Python</option>
<option data-icon="bi bi-filetype-cpp" value="cpp">C++</option>
<option data-icon="bi bi-filetype-java" value="java">Java</option>
<option data-icon="bi bi-filetype-rb" value="ruby">Ruby</option>
<option data-icon="bi bi-filetype-go" value="golang">Go</option>
<option data-icon="bi bi-filetype-rs" value="rust">Rust</option>
<option data-icon="bi bi-filetype-ts" value="typescript">TypeScript</option>
<option data-icon="bi bi-filetype-php" value="php">PHP</option>
<option data-icon="bi bi-filetype-cs" value="csharp">C#</option>
<option data-icon="bi bi-filetype-sw" value="swift">Swift</option>
<option data-icon="bi bi-filetype-kt" value="kotlin">Kotlin</option>
<option data-icon="bi bi-filetype-html" value="html">HTML</option>
<option data-icon="bi bi-filetype-css" value="css">CSS</option>
<option data-icon="bi bi-filetype-md" value="markdown">Markdown</option>
</select>
<button id="run-btn"
class="bg-green-600 hover:bg-green-700 px-6 py-2 rounded-lg flex items-center space-x-2">
<i class="bi bi-play-fill"></i>
<span>Run</span>
</button>
<button id="save-btn"
class="bg-blue-600 hover:bg-blue-700 px-6 py-2 rounded-lg flex items-center space-x-2">
<i class="bi bi-save"></i>
<span>Save</span>
</button>
</div>
<button id="settings-btn"
class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded-lg flex items-center space-x-2">
<i class="bi bi-gear"></i>
<span>Settings</span>
</button>
</div>
<div id="tabs" class="bg-gray-800 border-b border-gray-700 flex overflow-x-auto custom-scrollbar">
<!-- Tabs will be added here -->
</div>
<div id="editor-container"></div>
<div id="terminal" class="bg-gray-800 p-4 text-sm custom-scrollbar">
<div class="text-gray-400">Terminal ready...</div>
</div>
</div>
<div id="settings-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center">
<div class="bg-gray-800 p-6 rounded-lg w-[600px]">
<h2 class="text-xl font-bold mb-4">Editor Settings</h2>
<div class="grid grid-cols-2 gap-6">
<div class="space-y-4">
<div>
<label class="block mb-2">Theme</label>
<select id="theme-selector" class="w-full bg-gray-700 px-3 py-2 rounded">
<option value="vs-dark">Dark</option>
<option value="vs-light">Light</option>
<option value="hc-black">High Contrast Dark</option>
<option value="hc-light">High Contrast Light</option>
<option value="my-custom-theme">Custom Theme</option>
</select>
</div>
<div>
<label class="block mb-2">Font Family</label>
<select id="font-family" class="w-full bg-gray-700 px-3 py-2 rounded">
<option value="'Fira Code'">Fira Code</option>
<option value="Consolas">Consolas</option>
<option value="'Source Code Pro'">Source Code Pro</option>
<option value="'JetBrains Mono'">JetBrains Mono</option>
</select>
</div>
</div>
<div class="space-y-4">
<div>
<label class="block mb-2">Font Size</label>
<input type="number" id="font-size" value="14" min="8" max="32"
class="w-full bg-gray-700 px-3 py-2 rounded">
</div>
<div>
<label class="block mb-2">Tab Size</label>
<input type="number" id="tab-size" value="4" min="2" max="8"
class="w-full bg-gray-700 px-3 py-2 rounded">
</div>
<div>
<label class="block mb-2">Line Numbers</label>
<select id="line-numbers" class="w-full bg-gray-700 px-3 py-2 rounded">
<option value="on">On</option>
<option value="off">Off</option>
<option value="relative">Relative</option>
</select>
</div>
</div>
</div>
<div class="flex justify-end space-x-4 mt-6">
<button id="close-settings"
class="bg-gray-600 hover:bg-gray-500 px-4 py-2 rounded">Cancel</button>
<button id="save-settings" class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded">Save</button>
</div>
</div>
</div>
<div id="new-file-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center">
<div class="bg-gray-800 p-6 rounded-lg w-96">
<h2 class="text-xl font-bold mb-4">New File</h2>
<input type="text" id="new-file-name" placeholder="Enter file name"
class="w-full bg-gray-700 px-3 py-2 rounded mb-4">
<div class="flex justify-end space-x-4">
<button id="cancel-new-file"
class="bg-gray-600 hover:bg-gray-500 px-4 py-2 rounded">Cancel</button>
<button id="create-new-file"
class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded">Create</button>
</div>
</div>
</div>
<script>
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs' } });
require(['vs/editor/editor.main'], function () {
let currentFile = null;
let files = {};
let editor;
editor = monaco.editor.create(document.getElementById('editor-container'), {
value: '// Start coding here...',
language: 'javascript',
theme: 'vs-dark',
fontSize: 14,
fontFamily: "'Fira Code', monospace",
minimap: { enabled: true },
automaticLayout: true,
lineNumbers: 'on',
renderWhitespace: 'all',
tabSize: 4
});
const savedSettings = JSON.parse(localStorage.getItem('editorSettings') || '{}');
if (Object.keys(savedSettings).length) {
editor.updateOptions(savedSettings);
monaco.editor.setTheme(savedSettings.theme || 'vs-dark');
}
function createNewFile(filename) {
if (!filename.includes('.')) filename += '.js';
files[filename] = { content: '', language: getLanguageFromExtension(filename) };
addFileToExplorer(filename);
openFile(filename);
}
function getLanguageFromExtension(filename) {
const ext = filename.split('.').pop();
const languageMap = {
'js': 'javascript',
'py': 'python',
'cpp': 'cpp',
'java': 'java',
'rb': 'ruby',
'go': 'golang',
'rs': 'rust',
'ts': 'typescript',
'php': 'php',
'cs': 'csharp',
'html': 'html',
'css': 'css',
'md': 'markdown'
};
return languageMap[ext] || 'plaintext';
}
function addFileToExplorer(filename) {
const fileList = document.getElementById('file-list');
const fileElement = document.createElement('div');
fileElement.className = 'flex items-center justify-between p-2 hover:bg-gray-700 rounded cursor-pointer';
fileElement.innerHTML = `
<span class="flex items-center">
<i class="bi ${getLanguageIcon(filename)} mr-2"></i>
${filename}
</span>
<button class="delete-file text-gray-400 hover:text-red-500">
<i class="bi bi-trash"></i>
</button>
`;
fileElement.onclick = () => openFile(filename);
fileElement.querySelector('.delete-file').onclick = (e) => {
e.stopPropagation();
deleteFile(filename);
};
fileList.appendChild(fileElement);
}
function getLanguageIcon(filename) {
const ext = filename.split('.').pop();
const iconMap = {
'js': 'bi-filetype-js',
'py': 'bi-filetype-py',
'cpp': 'bi-filetype-cpp',
'java': 'bi-filetype-java',
'rb': 'bi-filetype-rb',
'go': 'bi-filetype-go',
'rs': 'bi-filetype-rs',
'ts': 'bi-filetype-ts',
'php': 'bi-filetype-php',
'cs': 'bi-filetype-cs',
'html': 'bi-filetype-html',
'css': 'bi-filetype-css',
'md': 'bi-filetype-md'
};
return iconMap[ext] || 'bi-file-earmark';
}
function openFile(filename) {
if (currentFile) {
files[currentFile].content = editor.getValue();
}
currentFile = filename;
editor.setValue(files[filename].content);
monaco.editor.setModelLanguage(editor.getModel(), files[filename].language);
updateTabs();
}
function deleteFile(filename) {
if (confirm(`Are you sure you want to delete ${filename}?`)) {
delete files[filename];
document.getElementById('file-list').innerHTML = '';
Object.keys(files).forEach(addFileToExplorer);
if (currentFile === filename) {
currentFile = null;
editor.setValue('// Start coding here...');
}
updateTabs();
}
}
function updateTabs() {
const tabsContainer = document.getElementById('tabs');
tabsContainer.innerHTML = '';
Object.keys(files).forEach(filename => {
const tab = document.createElement('div');
tab.className = `file-tab px-4 py-2 border-r border-gray-700 flex items-center space-x-2 cursor-pointer ${currentFile === filename ? 'bg-gray-700' : 'bg-gray-800 hover:bg-gray-700'}`;
tab.innerHTML = `
<span>${filename}</span>
<button class="text-gray-400 hover:text-red-500">×</button>
`;
tab.onclick = () => openFile(filename);
tab.querySelector('button').onclick = (e) => {
e.stopPropagation();
deleteFile(filename);
};
tabsContainer.appendChild(tab);
});
}
document.getElementById('new-file-btn').onclick = () => {
document.getElementById('new-file-modal').classList.remove('hidden');
};
document.getElementById('create-new-file').onclick = () => {
const filename = document.getElementById('new-file-name').value.trim();
if (filename) {
createNewFile(filename);
document.getElementById('new-file-modal').classList.add('hidden');
document.getElementById('new-file-name').value = '';
}
};
document.getElementById('cancel-new-file').onclick = () => {
document.getElementById('new-file-modal').classList.add('hidden');
document.getElementById('new-file-name').value = '';
};
document.getElementById('settings-btn').onclick = () => {
document.getElementById('settings-modal').classList.remove('hidden');
};
document.getElementById('close-settings').onclick = () => {
document.getElementById('settings-modal').classList.add('hidden');
};
document.getElementById('save-settings').onclick = () => {
const settings = {
fontSize: parseInt(document.getElementById('font-size').value),
tabSize: parseInt(document.getElementById('tab-size').value),
theme: document.getElementById('theme-selector').value,
fontFamily: document.getElementById('font-family').value,
lineNumbers: document.getElementById('line-numbers').value
};
editor.updateOptions(settings);
monaco.editor.setTheme(settings.theme);
localStorage.setItem('editorSettings', JSON.stringify(settings));
document.getElementById('settings-modal').classList.add('hidden');
};
document.getElementById('run-btn').onclick = () => {
const terminal = document.getElementById('terminal');
terminal.innerHTML = '<div class="text-green-400">Running code...</div>';
const code = editor.getValue();
const language = files[currentFile].language;
fetch('https://api.jdoodle.com/v1/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
script: code,
language: language,
versionIndex: "0",
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
})
}).then(response => response.json())
.then(data => {
terminal.innerHTML += `<div class="text-gray-300">${data.output || data.error}</div>`;
terminal.scrollTop = terminal.scrollHeight;
}).catch(error => {
terminal.innerHTML += `<div class="text-red-400">Error: ${error.message}</div>`;
});
};
document.getElementById('save-btn').onclick = () => {
if (currentFile) {
files[currentFile].content = editor.getValue();
const terminal = document.getElementById('terminal');
terminal.innerHTML += `<div class="text-green-400">Saved ${currentFile}</div>`;
terminal.scrollTop = terminal.scrollHeight;
}
};
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
document.getElementById('save-btn').click();
}
if (e.ctrlKey && e.key === 'Enter') {
e.preventDefault();
document.getElementById('run-btn').click();
}
});
// Create initial file
createNewFile('main.js');
});
</script>
</body>
</html>