saving / viewing canvas revisions

This commit is contained in:
zadam
2023-10-02 15:24:40 +02:00
parent 62ccf798ee
commit 5be61e6142
5 changed files with 94 additions and 33 deletions

View File

@@ -274,26 +274,11 @@ export default class RevisionsDialog extends BasicWidget {
this.$content.html($table);
} else if (revisionItem.type === 'canvas') {
/**
* FIXME: We load a font called Virgil.wof2, which originates from excalidraw.com
* REMOVE external dependency!!!! This is defined in the svg in defs.style
*/
const content = fullRevision.content;
const sanitizedTitle = revisionItem.title.replace(/[^a-z0-9-.]/gi, "");
try {
const data = JSON.parse(content)
const svg = data.svg || "no svg present."
/**
* maxWidth: 100% use full width of container but do not enlarge!
* height:auto to ensure that height scales with width
*/
const $svgHtml = $(svg).css({maxWidth: "100%", height: "auto"});
this.$content.html($('<div>').append($svgHtml));
} catch (err) {
console.error("error parsing fullRevision.content as JSON", fullRevision.content, err);
this.$content.html($("<div>").text("Error parsing content. Please check console.error() for more details."));
}
this.$content.html($("<img>")
.attr("src", `api/revisions/${revisionItem.revisionId}/image/${sanitizedTitle}?${Math.random()}`)
.css("max-width", "100%"));
} else {
this.$content.text("Preview isn't available for this note type.");
}