Spaces:
Running
Running
good now the UI is good but if you can do this it will be better,
Browse files- index.html +172 -4
index.html
CHANGED
|
@@ -228,7 +228,6 @@
|
|
| 228 |
const files = e.target.files;
|
| 229 |
handleFiles(files, 'model');
|
| 230 |
}
|
| 231 |
-
|
| 232 |
function handleFiles(files, type) {
|
| 233 |
for (let i = 0; i < files.length; i++) {
|
| 234 |
const file = files[i];
|
|
@@ -240,6 +239,8 @@
|
|
| 240 |
if (type === 'website') {
|
| 241 |
uploadedFiles.set(file.name, content);
|
| 242 |
updateFileList();
|
|
|
|
|
|
|
| 243 |
} else if (type === 'model') {
|
| 244 |
uploadedModels.set(file.name, {
|
| 245 |
content: content,
|
|
@@ -247,6 +248,8 @@
|
|
| 247 |
});
|
| 248 |
updateModelList();
|
| 249 |
previewModel(file);
|
|
|
|
|
|
|
| 250 |
}
|
| 251 |
};
|
| 252 |
|
|
@@ -258,7 +261,51 @@
|
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
if (uploadedFiles.size === 0) {
|
| 263 |
fileList.innerHTML = '<p class="text-gray-500 text-sm">No files uploaded yet</p>';
|
| 264 |
return;
|
|
@@ -356,10 +403,18 @@
|
|
| 356 |
</div>
|
| 357 |
`;
|
| 358 |
}
|
| 359 |
-
|
| 360 |
// Refresh preview functionality
|
| 361 |
refreshPreviewBtn.addEventListener('click', refreshPreview);
|
| 362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
function refreshPreview() {
|
| 364 |
if (uploadedFiles.size === 0) {
|
| 365 |
previewFrame.srcdoc = '<html><body><div style="display: flex; justify-content: center; align-items: center; height: 100%; color: #666;"><p>Upload website files to see preview</p></div></body></html>';
|
|
@@ -391,10 +446,123 @@
|
|
| 391 |
}
|
| 392 |
});
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
previewFrame.srcdoc = htmlContent;
|
| 395 |
}
|
| 396 |
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
clearAllBtn.addEventListener('click', () => {
|
| 399 |
if (confirm('Are you sure you want to clear all uploaded files and models?')) {
|
| 400 |
uploadedFiles.clear();
|
|
|
|
| 228 |
const files = e.target.files;
|
| 229 |
handleFiles(files, 'model');
|
| 230 |
}
|
|
|
|
| 231 |
function handleFiles(files, type) {
|
| 232 |
for (let i = 0; i < files.length; i++) {
|
| 233 |
const file = files[i];
|
|
|
|
| 239 |
if (type === 'website') {
|
| 240 |
uploadedFiles.set(file.name, content);
|
| 241 |
updateFileList();
|
| 242 |
+
// Auto-refresh preview when new website files are added
|
| 243 |
+
refreshPreview();
|
| 244 |
} else if (type === 'model') {
|
| 245 |
uploadedModels.set(file.name, {
|
| 246 |
content: content,
|
|
|
|
| 248 |
});
|
| 249 |
updateModelList();
|
| 250 |
previewModel(file);
|
| 251 |
+
// Auto-upload to server when model is added
|
| 252 |
+
uploadModelToServer(file);
|
| 253 |
}
|
| 254 |
};
|
| 255 |
|
|
|
|
| 261 |
}
|
| 262 |
}
|
| 263 |
|
| 264 |
+
function uploadModelToServer(file) {
|
| 265 |
+
const formData = new FormData();
|
| 266 |
+
formData.append('model', file);
|
| 267 |
+
|
| 268 |
+
// Show upload status
|
| 269 |
+
const uploadStatus = document.createElement('div');
|
| 270 |
+
uploadStatus.className = 'text-sm text-blue-600 mt-2';
|
| 271 |
+
uploadStatus.innerHTML = `<i data-feather="upload" class="w-3 h-3 mr-1"></i> Uploading ${file.name}...`;
|
| 272 |
+
modelList.appendChild(uploadStatus);
|
| 273 |
+
feather.replace();
|
| 274 |
+
|
| 275 |
+
fetch('/api/upload-model', {
|
| 276 |
+
method: 'POST',
|
| 277 |
+
body: formData
|
| 278 |
+
})
|
| 279 |
+
.then(response => response.json())
|
| 280 |
+
.then(data => {
|
| 281 |
+
if (data.success) {
|
| 282 |
+
uploadStatus.innerHTML = `<i data-feather="check" class="w-3 h-3 mr-1 text-green-600"></i> ${file.name} uploaded successfully`;
|
| 283 |
+
// Store server file path for later use
|
| 284 |
+
uploadedModels.get(file.name).serverPath = data.filePath;
|
| 285 |
+
} else {
|
| 286 |
+
uploadStatus.innerHTML = `<i data-feather="x" class="w-3 h-3 mr-1 text-red-600"></i> Upload failed: ${data.error}`;
|
| 287 |
+
}
|
| 288 |
+
feather.replace();
|
| 289 |
+
|
| 290 |
+
// Remove status message after 5 seconds
|
| 291 |
+
setTimeout(() => {
|
| 292 |
+
if (uploadStatus.parentNode) {
|
| 293 |
+
uploadStatus.remove();
|
| 294 |
+
}
|
| 295 |
+
}, 5000);
|
| 296 |
+
})
|
| 297 |
+
.catch(error => {
|
| 298 |
+
uploadStatus.innerHTML = `<i data-feather="x" class="w-3 h-3 mr-1 text-red-600"></i> Upload error: ${error.message}`;
|
| 299 |
+
feather.replace();
|
| 300 |
+
|
| 301 |
+
setTimeout(() => {
|
| 302 |
+
if (uploadStatus.parentNode) {
|
| 303 |
+
uploadStatus.remove();
|
| 304 |
+
}
|
| 305 |
+
}, 5000);
|
| 306 |
+
});
|
| 307 |
+
}
|
| 308 |
+
function updateFileList() {
|
| 309 |
if (uploadedFiles.size === 0) {
|
| 310 |
fileList.innerHTML = '<p class="text-gray-500 text-sm">No files uploaded yet</p>';
|
| 311 |
return;
|
|
|
|
| 403 |
</div>
|
| 404 |
`;
|
| 405 |
}
|
|
|
|
| 406 |
// Refresh preview functionality
|
| 407 |
refreshPreviewBtn.addEventListener('click', refreshPreview);
|
| 408 |
|
| 409 |
+
// Add export functionality
|
| 410 |
+
const exportBtn = document.createElement('button');
|
| 411 |
+
exportBtn.className = 'bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center';
|
| 412 |
+
exportBtn.innerHTML = '<i data-feather="download" class="w-4 h-4 mr-2"></i> Export Project';
|
| 413 |
+
exportBtn.addEventListener('click', exportProject);
|
| 414 |
+
|
| 415 |
+
// Add export button to the preview controls
|
| 416 |
+
const previewControls = document.querySelector('.mt-4.flex.space-x-3');
|
| 417 |
+
previewControls.appendChild(exportBtn);
|
| 418 |
function refreshPreview() {
|
| 419 |
if (uploadedFiles.size === 0) {
|
| 420 |
previewFrame.srcdoc = '<html><body><div style="display: flex; justify-content: center; align-items: center; height: 100%; color: #666;"><p>Upload website files to see preview</p></div></body></html>';
|
|
|
|
| 446 |
}
|
| 447 |
});
|
| 448 |
|
| 449 |
+
// Inject 3D model integration if models are uploaded
|
| 450 |
+
if (uploadedModels.size > 0) {
|
| 451 |
+
const threeJsScript = `
|
| 452 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 453 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.js"></script>
|
| 454 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
|
| 455 |
+
`;
|
| 456 |
+
|
| 457 |
+
const modelIntegrationScript = `
|
| 458 |
+
<script>
|
| 459 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 460 |
+
// Create 3D scene container
|
| 461 |
+
const container = document.createElement('div');
|
| 462 |
+
container.id = 'threejs-container';
|
| 463 |
+
container.style.position = 'fixed';
|
| 464 |
+
container.style.top = '0';
|
| 465 |
+
container.style.left = '0';
|
| 466 |
+
container.style.width = '100%';
|
| 467 |
+
container.style.height = '100%';
|
| 468 |
+
container.style.zIndex = '1000';
|
| 469 |
+
container.style.pointerEvents = 'none';
|
| 470 |
+
document.body.appendChild(container);
|
| 471 |
+
|
| 472 |
+
// Initialize Three.js
|
| 473 |
+
const scene = new THREE.Scene();
|
| 474 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 475 |
+
const renderer = new THREE.WebGLRenderer({ alpha: true });
|
| 476 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 477 |
+
container.appendChild(renderer.domElement);
|
| 478 |
+
|
| 479 |
+
// Add lights
|
| 480 |
+
const ambientLight = new THREE.AmbientLight(0x404040);
|
| 481 |
+
scene.add(ambientLight);
|
| 482 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
| 483 |
+
directionalLight.position.set(1, 1, 1);
|
| 484 |
+
scene.add(directionalLight);
|
| 485 |
+
|
| 486 |
+
// Load models
|
| 487 |
+
const loader = new THREE.GLTFLoader();
|
| 488 |
+
${Array.from(uploadedModels.values()).map((modelData, index) => `
|
| 489 |
+
loader.load('${modelData.serverPath || URL.createObjectURL(modelData.file)}', function(gltf) {
|
| 490 |
+
const model = gltf.scene;
|
| 491 |
+
model.position.set(${index * 2}, 0, -5);
|
| 492 |
+
scene.add(model);
|
| 493 |
+
});
|
| 494 |
+
`).join('')}
|
| 495 |
+
|
| 496 |
+
camera.position.z = 5;
|
| 497 |
+
|
| 498 |
+
function animate() {
|
| 499 |
+
requestAnimationFrame(animate);
|
| 500 |
+
renderer.render(scene, camera);
|
| 501 |
+
}
|
| 502 |
+
animate();
|
| 503 |
+
|
| 504 |
+
window.addEventListener('resize', function() {
|
| 505 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 506 |
+
camera.updateProjectionMatrix();
|
| 507 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 508 |
+
});
|
| 509 |
+
});
|
| 510 |
+
</script>
|
| 511 |
+
`;
|
| 512 |
+
|
| 513 |
+
htmlContent = htmlContent.replace('</head>', `${threeJsScript}</head>`);
|
| 514 |
+
htmlContent = htmlContent.replace('</body>', `${modelIntegrationScript}</body>`);
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
previewFrame.srcdoc = htmlContent;
|
| 518 |
}
|
| 519 |
|
| 520 |
+
function exportProject() {
|
| 521 |
+
if (uploadedFiles.size === 0 && uploadedModels.size === 0) {
|
| 522 |
+
alert('No files to export');
|
| 523 |
+
return;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
// Create project manifest
|
| 527 |
+
const manifest = {
|
| 528 |
+
version: '1.0',
|
| 529 |
+
timestamp: new Date().toISOString(),
|
| 530 |
+
files: Array.from(uploadedFiles.keys()),
|
| 531 |
+
models: Array.from(uploadedModels.keys()),
|
| 532 |
+
modelServerPaths: Array.from(uploadedModels.values()).map(model => model.serverPath)
|
| 533 |
+
};
|
| 534 |
+
|
| 535 |
+
// Create zip file
|
| 536 |
+
const zip = new JSZip();
|
| 537 |
+
|
| 538 |
+
// Add website files
|
| 539 |
+
uploadedFiles.forEach((content, name) => {
|
| 540 |
+
zip.file(name, content);
|
| 541 |
+
});
|
| 542 |
+
|
| 543 |
+
// Add models
|
| 544 |
+
uploadedModels.forEach((modelData, name) => {
|
| 545 |
+
zip.file(name, modelData.file);
|
| 546 |
+
});
|
| 547 |
+
|
| 548 |
+
// Add manifest
|
| 549 |
+
zip.file('project-manifest.json', JSON.stringify(manifest, null, 2));
|
| 550 |
+
|
| 551 |
+
// Generate and download zip
|
| 552 |
+
zip.generateAsync({type: 'blob'}).then(function(content) {
|
| 553 |
+
const link = document.createElement('a');
|
| 554 |
+
link.href = URL.createObjectURL(content);
|
| 555 |
+
link.download = 'webcraft-project.zip';
|
| 556 |
+
link.click();
|
| 557 |
+
URL.revokeObjectURL(link.href);
|
| 558 |
+
});
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
// Load JSZip library for export functionality
|
| 562 |
+
const script = document.createElement('script');
|
| 563 |
+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js';
|
| 564 |
+
document.head.appendChild(script);
|
| 565 |
+
// Clear all functionality
|
| 566 |
clearAllBtn.addEventListener('click', () => {
|
| 567 |
if (confirm('Are you sure you want to clear all uploaded files and models?')) {
|
| 568 |
uploadedFiles.clear();
|