From a3e5f70621b1c8e6be4d4f4fca1fe69bd92c3801 Mon Sep 17 00:00:00 2001 From: Loren Norman Date: Tue, 29 Jul 2025 14:40:53 -0400 Subject: [PATCH] name block image files --- src/image_exporter.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/image_exporter.js b/src/image_exporter.js index 5f675b8..d37b8c5 100644 --- a/src/image_exporter.js +++ b/src/image_exporter.js @@ -10,7 +10,8 @@ export const imageExportRegistryItems = [ scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, preconditionFn: scope => "enabled", callback: (scope, menuOpenEvent, menuSelectEvent, location) => { - downloadBlockAsSVG(scope.block.id) + const { id, type } = scope.block + downloadBlockAsSVG(id, type) } }, { id: "block-png", @@ -19,7 +20,8 @@ export const imageExportRegistryItems = [ scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, preconditionFn: scope => "enabled", callback: (scope, menuOpenEvent, menuSelectEvent, location) => { - downloadBlockAsPNG(scope.block.id) + const { id, type } = scope.block + downloadBlockAsPNG(id, type) } } ] @@ -75,13 +77,13 @@ const URL.revokeObjectURL(element.href) }, - downloadBlockAsSVG = blockId => { + downloadBlockAsSVG = (blockId, blockType) => { const svgObjectURL = blockToSVGBlob(blockId) - download(svgObjectURL, 'block.svg') + download(svgObjectURL, `${blockType}.svg`) }, - downloadBlockAsPNG = blockId => { + downloadBlockAsPNG = (blockId, blockType) => { const svgObjectURL = blockToSVGBlob(blockId), img = new Image() @@ -95,7 +97,7 @@ const // extract a png object url from the canvas and download it const pngObjectURL = canvas.toDataURL("image/png") - download(pngObjectURL, 'block.png') + download(pngObjectURL, `${blockType}.png`) } img.src = svgObjectURL