Skip to content

Commit 73b84f9

Browse files
committed
feat: Refactor download logic to use Blob for file downloads and improve event logging
1 parent fa2b4c1 commit 73b84f9

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

index.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,32 +1362,15 @@
13621362
const dl = fmt => {
13631363
if (!S.ctx) { toast('Generate first', 'warning'); return; }
13641364
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');
13911374
} catch (e) {
13921375
console.error('Download error:', e);
13931376
toast('Download failed: ' + e.message, 'error');
@@ -1397,8 +1380,12 @@
13971380
// EVENTS
13981381
// ============================================================================
13991382
const setup = () => {
1383+
console.log('Setting up event handlers...');
14001384
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+
};
14021389
// Model selector event
14031390
if (D.model) {
14041391
D.model.onchange = () => {

0 commit comments

Comments
 (0)