mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2025-12-21 21:22:25 +00:00
feat: add export and import functionality for snippets with UI controls
This commit is contained in:
@@ -13,4 +13,31 @@ export class StorageManager {
|
||||
saveSnippets(snippets) {
|
||||
localStorage.setItem(this.SNIPPETS_KEY, JSON.stringify(snippets));
|
||||
}
|
||||
|
||||
exportSnippets() {
|
||||
const snippets = this.loadSnippets();
|
||||
const blob = new Blob([JSON.stringify(snippets, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'astrolabe-snippets.json';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async importSnippets(file) {
|
||||
try {
|
||||
const text = await file.text();
|
||||
const snippets = JSON.parse(text);
|
||||
if (!Array.isArray(snippets)) {
|
||||
throw new Error('Invalid snippets format');
|
||||
}
|
||||
this.saveSnippets(snippets);
|
||||
return snippets;
|
||||
} catch (err) {
|
||||
throw new Error('Failed to import snippets: ' + err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user