diff --git a/src/main/webapp/components/preview/diagram/preview-diagram.js b/src/main/webapp/components/preview/diagram/preview-diagram.js index 73c5d82..16ac198 100644 --- a/src/main/webapp/components/preview/diagram/preview-diagram.js +++ b/src/main/webapp/components/preview/diagram/preview-diagram.js @@ -57,21 +57,27 @@ async function setDiagram(type, encodedDiagram, index) { setVisibility(pdf, type === "pdf"); } // update diagram - if (type === "png") { - png.src = buildUrl("png", encodedDiagram, index); - const map = await requestDiagram("map", encodedDiagram, index); - setDiagramMap(map); - } else if (type === "svg") { - const svg = await requestDiagram("svg", encodedDiagram, index); - setSvgDiagram(svg); - } else if (type === "txt") { - txt.innerHTML = await requestDiagram("txt", encodedDiagram, index); - } else if (type === "pdf") { - pdf.data = buildUrl("pdf", encodedDiagram, index); - } else { - const message = "unknown diagram type: " + type; - (console.error || console.log)(message); - return Promise.reject(message); + try { + if (type === "png") { + png.src = buildUrl("png", encodedDiagram, index); + const map = await requestDiagram("map", encodedDiagram, index); + setDiagramMap(map); + } else if (type === "svg") { + const svg = await requestDiagram("svg", encodedDiagram, index); + setSvgDiagram(svg); + } else if (type === "txt") { + txt.innerHTML = await requestDiagram("txt", encodedDiagram, index); + } else if (type === "pdf") { + pdf.data = buildUrl("pdf", encodedDiagram, index); + } else { + const message = "unknown diagram type: " + type; + (console.error || console.log)(message); + return Promise.reject(message); + } + setDiagramVisibility(type); + } catch (e) { + // This should only happen if for example a broken diagram is requested. + // Therefore, since the error message is already included in the response image, prevent further error messages. + //(console.error || console.log)(e); } - setDiagramVisibility(type); } diff --git a/src/main/webapp/min/plantuml.min.js b/src/main/webapp/min/plantuml.min.js index 075a507..8555579 100644 --- a/src/main/webapp/min/plantuml.min.js +++ b/src/main/webapp/min/plantuml.min.js @@ -52,10 +52,11 @@ function initSettings(){function a(){setVisibility(document.getElementById("sett Object.assign({},{language:"json"},document.appConfig.editorCreateOptions));b.addEventListener("change",function(e){e=e.target.value;var f=document.settingsEditor.getValue();setEditorValue(document.settingsEditor,f.replace(new RegExp('("theme"\\s*:\\s*)"'+("dark"===e?"vs":"vs-dark")+'"',"gm"),'$1"'+("dark"===e?"vs-dark":"vs")+'"'))});document.getElementById("settings-ok-btn").addEventListener("click",function(){var e=Object.assign({},document.appConfig);e.theme=b.value;e.editorWatcherTimeout=d.value; e.diagramPreviewType=c.value;e.editorCreateOptions=JSON.parse(document.settingsEditor.getValue());updateConfig(e);closeModal("settings")});window.addEventListener("keydown",function(e){","===e.key&&(isMac?e.metaKey:e.ctrlKey)&&(e.preventDefault(),isModalOpen("settings")||a())},!1);registerModalListener("settings",a)} function initializeDiagram(){return $jscomp.asyncExecutePromiseGeneratorProgram(function(a){if("png"!==document.appConfig.diagramPreviewType)return a.return(setDiagram(document.appConfig.diagramPreviewType,document.appData.encodedDiagram,document.appData.index));a.jumpToEnd()})} -function setDiagram(a,b,c){function d(k,n,q){return $jscomp.asyncExecutePromiseGeneratorProgram(function(r){return r.return(makeRequest("GET",buildUrl(k,n,q)))})}var e,f,g,m,l,h,t,p;return $jscomp.asyncExecutePromiseGeneratorProgram(function(k){switch(k.nextAddress){case 1:e=document.getElementById("diagram");f=document.getElementById("diagram-png");g=document.getElementById("diagram-txt");m=document.getElementById("diagram-pdf");if("png"===a)return f.src=buildUrl("png",b,c),k.yield(d("map",b,c), -9);if("svg"===a)return k.yield(d("svg",b,c),8);if("txt"!==a){if("pdf"===a)m.data=buildUrl("pdf",b,c);else return l="unknown diagram type: "+a,(console.error||console.log)(l),k.return(Promise.reject(l));k.jumpTo(3);break}h=g;return k.yield(d("txt",b,c),7);case 7:h.innerHTML=k.yieldResult;k.jumpTo(3);break;case 8:t=k.yieldResult;var n=document.getElementById("diagram-svg"),q=document.createElement("div");q.innerHTML=t;q=q.querySelector("svg");q.id="diagram-svg";q.classList=n.classList;q.style.cssText= -n.style.cssText;n.parentNode.replaceChild(q,n);k.jumpTo(3);break;case 9:if(p=k.yieldResult,n=document.getElementById("plantuml_map"),q=document.getElementById("map-diagram-link"),p){var r=document.createElement("div");r.innerHTML=p;n.parentNode.replaceChild(r.firstChild,n);setVisibility(q,!0)}else removeChildren(n),setVisibility(q,!1);case 3:n=document.getElementById("plantuml_map"),q=document.getElementById("diagram-svg"),e.setAttribute("data-diagram-type",a),setVisibility(f,"png"===a),setVisibility(n, -"png"===a),setVisibility(q,"svg"===a),setVisibility(g,"txt"===a),setVisibility(m,"pdf"===a),k.jumpToEnd()}})}function getNumberOfDiagramPagesFromCode(a){var b;return(null==(b=a.match(/^\s*newpage\s?.*$/gm))?void 0:b.length)+1||1}function updatePaginatorSelection(){var a=document.getElementById("paginator"),b=document.appData.index;if(void 0===b||a.childNodes.length<=b)for(a=$jscomp.makeIterator(a.childNodes),b=a.next();!b.done;b=a.next())b.value.checked=!1;else a.childNodes[b].checked=!0} +function setDiagram(a,b,c){function d(k,n,q){return $jscomp.asyncExecutePromiseGeneratorProgram(function(r){return r.return(makeRequest("GET",buildUrl(k,n,q)))})}var e,f,g,m,l,h,t,p;return $jscomp.asyncExecutePromiseGeneratorProgram(function(k){switch(k.nextAddress){case 1:e=document.getElementById("diagram");f=document.getElementById("diagram-png");g=document.getElementById("diagram-txt");m=document.getElementById("diagram-pdf");k.setCatchFinallyBlocks(2);if("png"===a)return f.src=buildUrl("png", +b,c),k.yield(d("map",b,c),11);if("svg"===a)return k.yield(d("svg",b,c),10);if("txt"!==a){if("pdf"===a)m.data=buildUrl("pdf",b,c);else return l="unknown diagram type: "+a,(console.error||console.log)(l),k.return(Promise.reject(l));k.jumpTo(5);break}h=g;return k.yield(d("txt",b,c),9);case 9:h.innerHTML=k.yieldResult;k.jumpTo(5);break;case 10:t=k.yieldResult;var n=document.getElementById("diagram-svg"),q=document.createElement("div");q.innerHTML=t;q=q.querySelector("svg");q.id="diagram-svg";q.classList= +n.classList;q.style.cssText=n.style.cssText;n.parentNode.replaceChild(q,n);k.jumpTo(5);break;case 11:if(p=k.yieldResult,n=document.getElementById("plantuml_map"),q=document.getElementById("map-diagram-link"),p){var r=document.createElement("div");r.innerHTML=p;n.parentNode.replaceChild(r.firstChild,n);setVisibility(q,!0)}else removeChildren(n),setVisibility(q,!1);case 5:n=document.getElementById("plantuml_map");q=document.getElementById("diagram-svg");e.setAttribute("data-diagram-type",a);setVisibility(f, +"png"===a);setVisibility(n,"png"===a);setVisibility(q,"svg"===a);setVisibility(g,"txt"===a);setVisibility(m,"pdf"===a);k.leaveTryBlock(0);break;case 2:k.enterCatchBlock(),k.jumpToEnd()}})}function getNumberOfDiagramPagesFromCode(a){var b;return(null==(b=a.match(/^\s*newpage\s?.*$/gm))?void 0:b.length)+1||1} +function updatePaginatorSelection(){var a=document.getElementById("paginator"),b=document.appData.index;if(void 0===b||a.childNodes.length<=b)for(a=$jscomp.makeIterator(a.childNodes),b=a.next();!b.done;b=a.next())b.value.checked=!1;else a.childNodes[b].checked=!0} var updatePaginator=function(){function a(b,c){for(;b.childElementCount>c;)b.removeChild(b.lastChild);for(;b.childElementCount