|
1362 | 1362 | const dl = fmt => { |
1363 | 1363 | if (!S.ctx) { toast('Generate first', 'warning'); return; } |
1364 | 1364 | try { |
1365 | | - if (isFolder) { |
1366 | | - return { |
1367 | | - type: 'svg', |
1368 | | - url: 'public/folder.svg', // Use your preferred folder icon SVG |
1369 | | - color: '', |
1370 | | - cls: 'folder-icon' |
1371 | | - }; |
1372 | | - } |
1373 | | - // File icon by extension |
1374 | | - const ext = name.split('.').pop().toLowerCase(); |
1375 | | - let url = ''; |
1376 | | - if (ext === 'js') url = 'public/js.svg'; |
1377 | | - else if (ext === 'html') url = 'public/html.svg'; |
1378 | | - else if (ext === 'css') url = 'public/css.svg'; |
1379 | | - else if (ext === 'py') url = 'public/python.svg'; |
1380 | | - else if (ext === 'md') url = 'public/markdown.svg'; |
1381 | | - else url = 'public/file.svg'; |
1382 | | - // You can add more mappings for other extensions if you add more icons |
1383 | | - return { |
1384 | | - type: 'svg', |
1385 | | - url, |
1386 | | - color: '', |
1387 | | - cls: '' |
1388 | | - }; |
1389 | | - S.ctx = null; |
1390 | | - S.isArray = false; |
| 1365 | + const text = S.isArray ? S.ctx.join('') : S.ctx; |
| 1366 | + const blob = new Blob([text], { type: 'text/plain' }); |
| 1367 | + const url = URL.createObjectURL(blob); |
| 1368 | + const a = document.createElement('a'); |
| 1369 | + a.href = url; |
| 1370 | + a.download = `${S.root}-context.${fmt}`; |
| 1371 | + a.click(); |
| 1372 | + URL.revokeObjectURL(url); |
| 1373 | + toast('Downloaded!', 'success'); |
1391 | 1374 | } catch (e) { |
1392 | 1375 | console.error('Download error:', e); |
1393 | 1376 | toast('Download failed: ' + e.message, 'error'); |
|
1397 | 1380 | // EVENTS |
1398 | 1381 | // ============================================================================ |
1399 | 1382 | const setup = () => { |
| 1383 | + console.log('Setting up event handlers...'); |
1400 | 1384 | D.tog.onclick = () => D.side.classList.toggle('collapsed'); |
1401 | | - D.sel.onclick = () => inp.click(); |
| 1385 | + D.sel.onclick = () => { |
| 1386 | + console.log('Select folder clicked'); |
| 1387 | + inp.click(); |
| 1388 | + }; |
1402 | 1389 | // Model selector event |
1403 | 1390 | if (D.model) { |
1404 | 1391 | D.model.onchange = () => { |
|
0 commit comments