UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 6.16 kB
EmbedDialog.showPreviewOption=!1,DrawIOExtension=function(t){function e(e,n,o){var a=Menus.prototype.init;Menus.prototype.init=function(){a.apply(this,arguments);var s=this.editorUi,l=s.editor.graph,r=mxUtils.bind(l,l.isEnabled);let c,i,u=o&&void 0!==n?n:e,p=o||(void 0!==n?n:e);if(null!=o?(c=this.get(n),i=t.extraActions[e][n][o]):(c=this.get(e),i=void 0!==n?t.extraActions[e][n]:t.extraActions[e]),null!=c){let t=c.funct;c.funct=function(e,n){t.apply(this,arguments),e.addSeparator(n),e.addItem(p,null,(function(){performCustomAction(s,i)}),n)},this.put(u,c).isEnabled=r}else this.put(u,new Menu(mxUtils.bind(this,(function(t,e){t.addSeparator(e),t.addItem(p,null,(function(){performCustomAction(s,i)}),e)})),r))}}void 0!==t&&void 0!==t.extraActions&&Object.keys(t.extraActions).forEach((n=>{void 0!==t.extraActions[n].callback&&"function"==typeof t.extraActions[n].callback?e(n):"object"==typeof t.extraActions[n]&&(console.log("keys",Object.keys(t.extraActions[n])),Object.keys(t.extraActions[n]).forEach((o=>{void 0!==t.extraActions[n][o].callback&&"function"==typeof t.extraActions[n][o].callback?e(n,o):"object"==typeof t.extraActions[n][o]&&Object.keys(t.extraActions[n][o]).forEach((a=>{void 0!==t.extraActions[n][o][a].callback&&"function"==typeof t.extraActions[n][o][a].callback&&e(n,o,a)}))})))}))},DrawIOExtension.prototype.menuList=[],DrawIOExtension.prototype.subMenuList=[],Menus.prototype.createMenubar=function(t){for(var e=new Menubar(this.editorUi,t),n=this.defaultMenuItems,o=0;o<n.length;o++)mxUtils.bind(this,(function(t){DrawIOExtension.prototype.menuList.push(mxResources.get(n[o])||n[o]);var a=e.addMenu(mxResources.get(n[o])||n[o],mxUtils.bind(this,(function(){t.funct.apply(this,arguments)})));this.menuCreated(t,a)}))(this.get(n[o]));return e},Editor.enableExportUrl=!1,Actions.prototype.removeAction=function(t){null!=this.actions[t]&&delete this.actions[t]},DrawIOOverridExport=function(t,e){t.actionsButtons&&Object.keys(t.actionsButtons).forEach((n=>{let o=document.createElement("div");o.className="geBtn gePrimaryBtn",o.style.display="inline-block",o.style.backgroundColor="#F2931E",o.style.borderColor="#F08705",o.style.backgroundImage="none",o.style.padding="2px 10px 0 10px",o.style.marginTop="-10px",o.style.height="28px",o.style.lineHeight="28px",o.style.minWidth="0px",o.style.cssFloat="right",t.actionsButtons[n].style&&Object.assign(o.style,t.actionsButtons[n].style),t.actionsButtons[n].className&&(o.className+=" "+t.actionsButtons[n].className),void 0!==t.actionsButtons[n].title&&o.setAttribute("title",t.actionsButtons[n].title),mxUtils.write(o,n),void 0!==t.actionsButtons[n].callback&&mxEvent.addListener(o,"click",mxUtils.bind(this,(function(){performCustomAction(e,t.actionsButtons[n])}))),e.buttonContainer.appendChild(o)}))},DrawIOEmptyDivCreate=function(t,e,n){null==e&&(e=(Math.random()+1).toString(36).substring(7));var o=document.createElement("div");return n&&(o.style=n),o.className=e,t.appendChild(o),o},DrawIOOverridUpdateBody=function(t,e){},sendErrorResponse=function(t,e){void 0!==t.callbackOnError&&"function"==typeof t.callbackOnError&&t.callbackOnError(e).then((t=>{console.log("sendErrorResponse done")}))},sendSuccessResponse=function(t,e){void 0!==t.callbackOnFinish&&"function"==typeof t.callbackOnFinish&&t.callbackOnFinish(e).then((t=>{console.log("sendSuccessResponse done",t)}))},getGraphXmlData=function(t){var e=t.getCurrentFile(),n={xml:null,name:null};return null!=e?(n.name=null!=e.getTitle()?e.getTitle():this.defaultFilename,n.xml=t.getFileData(!0),n):(console.log("file not found"),{status:"export error",graphData:n})},performCustomAction=function(t,e){switch(e.actionType){case"import_OptIn":try{e.callback().then((n=>{t.importFile(n.graphData.xml,"text/xml",0,0,240,160,n.graphData.name,(function(){console.log("done"),sendSuccessResponse(e,{status:"import successfully",graphData:n.graphData})}),null,!1,void 0,void 0),console.log("import_OptIn",n)}),(t=>{console.log("import_OptIn",t)})).catch((t=>{console.log("import_OptIn",t)}))}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",graphData:null,reason:t})}break;case"export_SvG_OptOut":try{let o=!0,a=!0,s=!0,l=!0;var n=t.editor.graph.getSvg(l?null:"#ffffff",1,"0",!0,null,!0,null,null,null,null,!0,null,"diagram");o&&n.setAttribute("content",t.getFileData(!0,null,null,null,a,s,null,null,null,!1));let r=Graph.xmlDeclaration+"\n"+(o?Graph.svgFileComment+"\n":"")+Graph.svgDoctype+"\n"+mxUtils.getXml(n),c="image/svg+xml",i=btoa(unescape(encodeURIComponent(r))),u={...getGraphXmlData(t),status:"Exported_SVG_AND_Image",svg:r,image:{base64Encoded:i,mimeType:c,getImageSrc:(t,e)=>"data:"+t+";base64,"+e}};e.callback(u).then((t=>{console.log("export_SvG_OptOut",t)}),(t=>{console.log("export_SvG_OptOut",t)})).catch((t=>{console.log("export_SvG_OptOut",t)}))}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",svg:null,image:null,xml:null,name:null,reason:t})}break;case"export_OptOut":try{var o=getGraphXmlData(t);o&&o.xml&&o.name?e.callback(o).then((t=>{console.log("export_OptOut",t)}),(t=>{console.log("export_OptOut",t)})).catch((t=>{console.log("export_OptOut",t)})):sendErrorResponse(e,{status:"export error",graphData:o})}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",graphData:null,reason:t})}break;case"open_OptIn":try{e.callback().then((e=>{console.log("open_OptIn",e),t.openLocalFile(e.graphData.xml,e.graphData.name,!1)}),(t=>{console.log("open_OptIn",t)})).catch((t=>{console.log("open_OptIn",t)}))}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",graphData:null,reason:t})}break;case"new_OptNew":try{e.callback().then((t=>{console.log("new_OptNew",t)}),(t=>{console.log("new_OptNew",t)})).catch((t=>{console.log("new_OptNew",t)}))}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",graphData:null,reason:t})}break;default:try{e.callback().then((t=>{console.log("default-custom",t)}),(t=>{console.log("default-custom",t)})).catch((t=>{console.log("default-custom",t)}))}catch(t){console.log(t),sendErrorResponse(e,{status:"something went wrong",graphData:enull,reason:t})}}};