fix(Map): Unified settings. Second part: Import/Export

This commit is contained in:
DanSylvest
2025-07-07 16:57:06 +03:00
parent df49939990
commit fe7a98098f
17 changed files with 697 additions and 49 deletions

View File

@@ -0,0 +1,36 @@
export function saveTextFile(filename: string, content: string) {
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
// эмулируем клик
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// освобождаем URL
URL.revokeObjectURL(url);
}
export async function saveTextFileInteractive(filename: string, content: string) {
if (!('showSaveFilePicker' in window)) {
throw new Error('File System Access API is not supported in this browser.');
}
const handle = await (window as any).showSaveFilePicker({
suggestedName: filename,
types: [
{
description: 'Text Files',
accept: { 'text/plain': ['.txt', '.json'] },
},
],
});
const writable = await handle.createWritable();
await writable.write(content);
await writable.close();
}