aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-02-24 01:06:34 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-02-24 14:20:49 +0100
commitfc08a98532eed84db73e4193e7c02b3e8f0fe545 (patch)
tree743cf5ecdd971501e65a02743eb473e53c4ed54e
parentbuild(web): remove extraneous console output (diff)
downloadrefinery-fc08a98532eed84db73e4193e7c02b3e8f0fe545.tar.gz
refinery-fc08a98532eed84db73e4193e7c02b3e8f0fe545.tar.zst
refinery-fc08a98532eed84db73e4193e7c02b3e8f0fe545.zip
refactor(frontend): improve save dialog label
-rw-r--r--subprojects/frontend/src/graph/export/exportDiagram.tsx36
-rw-r--r--subprojects/frontend/src/utils/fileIO.ts26
2 files changed, 37 insertions, 25 deletions
diff --git a/subprojects/frontend/src/graph/export/exportDiagram.tsx b/subprojects/frontend/src/graph/export/exportDiagram.tsx
index 685b6ace..d2af52d9 100644
--- a/subprojects/frontend/src/graph/export/exportDiagram.tsx
+++ b/subprojects/frontend/src/graph/export/exportDiagram.tsx
@@ -340,7 +340,17 @@ export default async function exportDiagram(
340 340
341 if (settings.format === 'pdf') { 341 if (settings.format === 'pdf') {
342 const pdf = await serializePDF(copyOfSVG, settings); 342 const pdf = await serializePDF(copyOfSVG, settings);
343 await saveBlob(pdf, 'graph.pdf', 'application/pdf', EXPORT_ID); 343 await saveBlob(pdf, 'graph.pdf', {
344 id: EXPORT_ID,
345 types: [
346 {
347 description: 'PDF files',
348 accept: {
349 'application/pdf': ['.pdf', '.PDF'],
350 },
351 },
352 ],
353 });
344 return; 354 return;
345 } 355 }
346 const serializedSVG = serializeSVG(svgDocument); 356 const serializedSVG = serializeSVG(svgDocument);
@@ -349,11 +359,31 @@ export default async function exportDiagram(
349 if (mode === 'copy') { 359 if (mode === 'copy') {
350 await copyBlob(png); 360 await copyBlob(png);
351 } else { 361 } else {
352 await saveBlob(png, 'graph.png', PNG_CONTENT_TYPE, EXPORT_ID); 362 await saveBlob(png, 'graph.png', {
363 id: EXPORT_ID,
364 types: [
365 {
366 description: 'PNG graphics',
367 accept: {
368 [PNG_CONTENT_TYPE]: ['.png', '.PNG'],
369 },
370 },
371 ],
372 });
353 } 373 }
354 } else if (mode === 'copy') { 374 } else if (mode === 'copy') {
355 await copyBlob(serializedSVG); 375 await copyBlob(serializedSVG);
356 } else { 376 } else {
357 await saveBlob(serializedSVG, 'graph.svg', SVG_CONTENT_TYPE, EXPORT_ID); 377 await saveBlob(serializedSVG, 'graph.svg', {
378 id: EXPORT_ID,
379 types: [
380 {
381 description: 'SVG graphics',
382 accept: {
383 [SVG_CONTENT_TYPE]: ['.svg', '.SVG'],
384 },
385 },
386 ],
387 });
358 } 388 }
359} 389}
diff --git a/subprojects/frontend/src/utils/fileIO.ts b/subprojects/frontend/src/utils/fileIO.ts
index abcc43eb..4f376882 100644
--- a/subprojects/frontend/src/utils/fileIO.ts
+++ b/subprojects/frontend/src/utils/fileIO.ts
@@ -7,28 +7,13 @@
7export async function saveBlob( 7export async function saveBlob(
8 blob: Blob, 8 blob: Blob,
9 name: string, 9 name: string,
10 mimeType: string, 10 options: FilePickerOptions,
11 id?: string,
12): Promise<void> { 11): Promise<void> {
13 if ('showSaveFilePicker' in window) { 12 if ('showSaveFilePicker' in window) {
14 const options: FilePickerOptions = { 13 const handle = await window.showSaveFilePicker({
14 ...options,
15 suggestedName: name, 15 suggestedName: name,
16 }; 16 });
17 if (id !== undefined) {
18 options.id = id;
19 }
20 const extensionIndex = name.lastIndexOf('.');
21 if (extensionIndex >= 0) {
22 options.types = [
23 {
24 description: `${name.substring(extensionIndex + 1)} files`,
25 accept: {
26 [mimeType]: [name.substring(extensionIndex)],
27 },
28 },
29 ];
30 }
31 const handle = await window.showSaveFilePicker(options);
32 const writable = await handle.createWritable(); 17 const writable = await handle.createWritable();
33 try { 18 try {
34 await writable.write(blob); 19 await writable.write(blob);
@@ -42,12 +27,9 @@ export async function saveBlob(
42 try { 27 try {
43 link.href = url; 28 link.href = url;
44 link.download = name; 29 link.download = name;
45 link.style.display = 'none';
46 document.body.appendChild(link);
47 link.click(); 30 link.click();
48 } finally { 31 } finally {
49 window.URL.revokeObjectURL(url); 32 window.URL.revokeObjectURL(url);
50 document.body.removeChild(link);
51 } 33 }
52} 34}
53 35