@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 28.8 kB
JavaScript
DrawioFile=function(t,e){mxEventSource.call(this),this.ui=t,this.data=e||"",this.shadowData=this.data,this.shadowPages=null,this.created=(new Date).getTime(),this.stats={opened:0,merged:0,fileMerged:0,fileReloaded:0,conflicts:0,timeouts:0,saved:0,closed:0,destroyed:0,joined:0,checksumErrors:0,bytesSent:0,bytesReceived:0,msgSent:0,msgReceived:0,cacheHits:0,cacheMiss:0,cacheFail:0}},DrawioFile.SYNC=urlParams.sync||"auto",DrawioFile.LAST_WRITE_WINS=!0,mxUtils.extend(DrawioFile,mxEventSource),DrawioFile.prototype.allChangesSavedKey="allChangesSaved",DrawioFile.prototype.savingSpinnerKey="saving",DrawioFile.prototype.savingStatusKey="saving",DrawioFile.prototype.autosaveDelay=1500,DrawioFile.prototype.maxAutosaveDelay=3e4,DrawioFile.prototype.optimisticSyncDelay=300,DrawioFile.prototype.autosaveThread=null,DrawioFile.prototype.lastAutosave=null,DrawioFile.prototype.lastSaved=null,DrawioFile.prototype.lastChanged=null,DrawioFile.prototype.opened=null,DrawioFile.prototype.modified=!1,DrawioFile.prototype.shadowModified=!1,DrawioFile.prototype.data=null,DrawioFile.prototype.shadowData=null,DrawioFile.prototype.shadowPages=null,DrawioFile.prototype.changeListenerEnabled=!0,DrawioFile.prototype.lastAutosaveRevision=null,DrawioFile.prototype.maxAutosaveRevisionDelay=3e5,DrawioFile.prototype.inConflictState=!1,DrawioFile.prototype.invalidChecksum=!1,DrawioFile.prototype.errorReportsEnabled=!1,DrawioFile.prototype.ageStart=null,DrawioFile.prototype.getSize=function(){return null!=this.data?this.data.length:0},DrawioFile.prototype.synchronizeFile=function(t,e){this.savingFile?null!=e&&e({message:mxResources.get("busy")}):null!=this.sync?this.sync.fileChanged(t,e):this.updateFile(t,e)},DrawioFile.prototype.updateFile=function(t,e,i,s){null!=i&&i()||(this.ui.getCurrentFile()!=this||this.invalidChecksum?null!=e&&e():this.getLatestVersion(mxUtils.bind(this,(function(n){try{null!=i&&i()||(this.ui.getCurrentFile()!=this||this.invalidChecksum?null!=e&&e():null!=n?this.mergeFile(n,t,e,s):this.reloadFile(t,e))}catch(t){null!=e&&e(t)}})),e))},DrawioFile.prototype.mergeFile=function(t,e,i,s){var n=!0;try{this.stats.fileMerged++;var o=null!=this.shadowPages?this.shadowPages:this.ui.getPagesForNode(mxUtils.parseXml(this.shadowData).documentElement),r=this.ui.getPagesForNode(mxUtils.parseXml(t.data).documentElement);if(!(null!=r&&r.length>0))throw n=!1,new Error(mxResources.get("notADiagramFile"));this.shadowPages=r,this.backupPatch=this.isModified()?this.ui.diffPages(o,this.ui.pages):null;var a=[this.ui.diffPages(null!=s?s:o,this.shadowPages)];if(!this.ignorePatches(a)){var l=this.ui.patchPages(o,a[0]),h={},u=this.ui.getHashValueForPages(l,h),d={},c=this.ui.getHashValueForPages(this.shadowPages,d);if("1"==urlParams.test&&EditorUi.debug("File.mergeFile",[this],"backup",this.backupPatch,"patches",a,"checksum",c==u,u),null!=u&&u!=c){var g=this.compressReportData(this.getAnonymizedXmlForPages(r)),p=this.compressReportData(this.getAnonymizedXmlForPages(l)),m=this.ui.hashValue(t.getCurrentEtag()),f=this.ui.hashValue(this.getCurrentEtag());return void this.checksumError(i,a,"Shadow Details: "+JSON.stringify(h)+"\nChecksum: "+u+"\nCurrent: "+c+"\nCurrent Details: "+JSON.stringify(d)+"\nFrom: "+m+"\nTo: "+f+"\n\nFile Data:\n"+g+"\nPatched Shadow:\n"+p,null,"mergeFile")}this.patch(a,DrawioFile.LAST_WRITE_WINS?this.backupPatch:null)}this.invalidChecksum=!1,this.inConflictState=!1,this.setDescriptor(t.getDescriptor()),this.descriptorChanged(),this.backupPatch=null,null!=e&&e()}catch(t){this.inConflictState=!0,this.invalidChecksum=!0,this.descriptorChanged(),null!=i&&i(t);try{if(n)if(this.errorReportsEnabled)this.sendErrorReport("Error in mergeFile",null,t);else{var y=this.getCurrentUser(),w=null!=y?y.id:"unknown";EditorUi.logError("Error in mergeFile",null,this.getMode()+"."+this.getId(),w,t)}}catch(t){}}},DrawioFile.prototype.getAnonymizedXmlForPages=function(t){var e=new mxCodec(mxUtils.createXmlDocument()),i=e.document.createElement("mxfile");if(null!=t)for(var s=0;s<t.length;s++){var n=e.encode(new mxGraphModel(t[s].root));"1"!=urlParams.dev&&(n=this.ui.anonymizeNode(n,!0)),n.setAttribute("id",t[s].getId()),t[s].viewState&&this.ui.editor.graph.saveViewState(t[s].viewState,n,!0),i.appendChild(n)}return mxUtils.getPrettyXml(i)},DrawioFile.prototype.compressReportData=function(t,e,i){return e=null!=e?e:1e4,null!=i&&null!=t&&t.length>i?t=t.substring(0,i)+"[...]":null!=t&&t.length>e&&(t=Graph.compress(t)+"\n"),t},DrawioFile.prototype.checksumError=function(t,e,i,s,n){this.stats.checksumErrors++,this.inConflictState=!0,this.invalidChecksum=!0,this.descriptorChanged(),null!=this.sync&&this.sync.updateOnlineState(),null!=t&&t();try{if(this.errorReportsEnabled){if(null!=e)for(var o=0;o<e.length;o++)this.ui.anonymizePatch(e[o]);var r=mxUtils.bind(this,(function(t){var s=this.compressReportData(JSON.stringify(e,null,2)),o=null!=t?this.compressReportData(this.getAnonymizedXmlForPages(this.ui.getPagesForNode(mxUtils.parseXml(t.data).documentElement)),25e3):"n/a";this.sendErrorReport("Checksum Error in "+n+" "+this.getHash(),(null!=i?i:"")+"\n\nPatches:\n"+s+(null!=o?"\n\nRemote:\n"+o:""),null,7e4)}));null==s?r(null):this.getLatestVersion(mxUtils.bind(this,(function(t){null!=t&&t.getCurrentEtag()==s?r(t):r(null)})),(function(){}))}else{var a=this.getCurrentUser(),l=null!=a?a.id:"unknown";EditorUi.logError("Checksum Error in "+n+" "+this.getId(),null,this.getMode()+"."+this.getId(),"user_"+l+(null!=this.sync?"-client_"+this.sync.clientId:"-nosync"));try{EditorUi.logEvent({category:"CHECKSUM-ERROR-SYNC-FILE-"+this.getHash(),action:n,label:"user_"+l+(null!=this.sync?"-client_"+this.sync.clientId:"-nosync")})}catch(t){}}}catch(t){}},DrawioFile.prototype.sendErrorReport=function(t,e,i,s){try{var n=this.compressReportData(this.getAnonymizedXmlForPages(this.shadowPages),25e3),o=this.compressReportData(this.getAnonymizedXmlForPages(this.ui.pages),25e3),r=this.getCurrentUser(),a=null!=r?this.ui.hashValue(r.id):"unknown",l=null!=this.sync?"-client_"+this.sync.clientId:"-nosync",h=this.getTitle(),u=h.lastIndexOf("."),d="xml";u>0&&(d=h.substring(u));var c=null!=i?i.stack:(new Error).stack;EditorUi.sendReport(t+" "+(new Date).toISOString()+":\n\nAppVersion="+navigator.appVersion+"\nFile="+this.ui.hashValue(this.getId())+" ("+this.getMode()+")"+(this.isModified()?" modified":"")+"\nSize/Type="+this.getSize()+" ("+d+")\nUser="+a+l+"\nPrefix="+this.ui.editor.graph.model.prefix+"\nSync="+DrawioFile.SYNC+(null!=this.sync?(this.sync.enabled?" enabled":"")+(this.sync.isConnected()?" connected":""):"")+"\nPlugins="+(null!=mxSettings.settings?mxSettings.getPlugins():"null")+"\n\nStats:\n"+JSON.stringify(this.stats,null,2)+(null!=e?"\n\n"+e:"")+(null!=i?"\n\nError: "+i.message:"")+"\n\nStack:\n"+c+"\n\nShadow:\n"+n+"\n\nData:\n"+o,s)}catch(t){}},DrawioFile.prototype.reloadFile=function(t,e){try{this.ui.spinner.stop();var i=mxUtils.bind(this,(function(){this.stats.fileReloaded++;var e=this.ui.editor.graph.getViewState(),i=this.ui.editor.graph.getSelectionCells(),s=this.ui.currentPage;this.ui.loadFile(this.getHash(),!0,null,mxUtils.bind(this,(function(){if(null==this.ui.fileLoadedError){this.ui.restoreViewState(s,e,i),null!=this.backupPatch&&this.patch([this.backupPatch]);var n=this.ui.getCurrentFile();null!=n&&(n.stats=this.stats),null!=t&&t()}})),!0)}));this.isModified()&&null==this.backupPatch?this.ui.confirm(mxResources.get("allChangesLost"),mxUtils.bind(this,(function(){this.handleFileSuccess("manual"==DrawioFile.SYNC)})),i,mxResources.get("cancel"),mxResources.get("discardChanges")):i()}catch(t){null!=e&&e(t)}},DrawioFile.prototype.copyFile=function(t,e){this.ui.editor.editAsNew(this.ui.getFileData(!0),this.ui.getCopyFilename(this))},DrawioFile.prototype.ignorePatches=function(t){for(var e=!0,i=0;i<t.length&&e;i++)e=e&&0==Object.keys(t[i]).length;return e},DrawioFile.prototype.patch=function(t,e,i){var s=this.ui.editor.undoManager,n=s.history.slice(),o=s.indexOfNextAdd,r=this.ui.editor.graph;r.container.style.visibility="hidden";var a=this.changeListenerEnabled;this.changeListenerEnabled=i;var l=r.foldingEnabled,h=r.mathEnabled,u=r.cellRenderer.redraw;r.cellRenderer.redraw=function(t){t.view.graph.isEditing(t.cell)&&(t.view.graph.scrollCellToVisible(t.cell),t.view.graph.cellEditor.resize()),u.apply(this,arguments)},r.model.beginUpdate();try{for(var d=0;d<t.length;d++)this.ui.pages=this.ui.patchPages(this.ui.pages,t[d],!0,e,this.isModified());0==this.ui.pages.length&&this.ui.pages.push(this.ui.createPage()),mxUtils.indexOf(this.ui.pages,this.ui.currentPage)<0&&this.ui.selectPage(this.ui.pages[0],!0)}finally{r.container.style.visibility="",r.model.endUpdate(),r.cellRenderer.redraw=u,this.changeListenerEnabled=a,i||(s.history=n,s.indexOfNextAdd=o,s.fireEvent(new mxEventObject(mxEvent.CLEAR))),(null==this.ui.currentPage||this.ui.currentPage.needsUpdate)&&(h!=r.mathEnabled?(this.ui.editor.updateGraphComponents(),r.refresh()):(l!=r.foldingEnabled?r.view.revalidate():r.view.validate(),r.sizeDidChange())),this.ui.updateTabContainer(),this.ui.editor.fireEvent(new mxEventObject("pagesPatched","patches",t))}},DrawioFile.prototype.save=function(t,e,i,s,n,o){try{if(this.isEditable())if(!n&&this.invalidChecksum){if(null==i)throw new Error(mxResources.get("checksum"));i({message:mxResources.get("checksum")})}else this.updateFileData(),this.clearAutosave(),null!=e&&e();else{if(null==i)throw new Error(mxResources.get("readOnly"));i({message:mxResources.get("readOnly")})}}catch(t){if(null==i)throw t;i(t)}},DrawioFile.prototype.updateFileData=function(){this.setData(this.ui.getFileData(null,null,null,null,null,null,null,null,this,!this.isCompressed()))},DrawioFile.prototype.isCompressedStorage=function(){return!0},DrawioFile.prototype.isCompressed=function(){var t=null!=this.ui.fileNode?this.ui.fileNode.getAttribute("compressed"):null;return null!=t?"false"!=t:this.isCompressedStorage()&&Editor.compressXml},DrawioFile.prototype.saveAs=function(t,e,i){},DrawioFile.prototype.saveFile=function(t,e,i,s){},DrawioFile.prototype.getPublicUrl=function(t){t(null)},DrawioFile.prototype.isRestricted=function(){return!1},DrawioFile.prototype.isModified=function(){return this.modified},DrawioFile.prototype.getShadowModified=function(){return this.shadowModified},DrawioFile.prototype.setShadowModified=function(t){this.shadowModified=t},DrawioFile.prototype.setModified=function(t){this.modified=t,this.shadowModified=t},DrawioFile.prototype.isAutosaveOptional=function(){return!1},DrawioFile.prototype.isAutosave=function(){return!this.inConflictState&&this.ui.editor.autosave},DrawioFile.prototype.isRenamable=function(){return!1},DrawioFile.prototype.rename=function(t,e,i){},DrawioFile.prototype.isMovable=function(){return!1},DrawioFile.prototype.isTrashed=function(){return!1},DrawioFile.prototype.move=function(t,e,i){},DrawioFile.prototype.share=function(){this.ui.alert(mxResources.get("sharingAvailable"),null,380)},DrawioFile.prototype.getHash=function(){return""},DrawioFile.prototype.getId=function(){return""},DrawioFile.prototype.isEditable=function(){return!this.ui.editor.isChromelessView()||this.ui.editor.editable},DrawioFile.prototype.getUi=function(){return this.ui},DrawioFile.prototype.getTitle=function(){return""},DrawioFile.prototype.setData=function(t){this.data=t},DrawioFile.prototype.getData=function(){return this.data},DrawioFile.prototype.open=function(){this.stats.opened++;var t=this.getData();if(null!=t){function e(t){for(var e=0;null!=t&&e<t.length;e++){var i=t[e];null!=i.id&&0==i.id.indexOf("extFont_")&&i.parentNode.removeChild(i)}}e(document.querySelectorAll("head > style[id]")),e(document.querySelectorAll("head > link[id]")),this.ui.setFileData(t),this.isModified()||(this.shadowData=mxUtils.getXml(this.ui.getXmlFileData()),this.shadowPages=null)}this.installListeners(),this.isSyncSupported()&&this.startSync()},DrawioFile.prototype.isSyncSupported=function(){return!1},DrawioFile.prototype.isRevisionHistorySupported=function(){return!1},DrawioFile.prototype.getRevisions=function(t,e){t(null)},DrawioFile.prototype.loadDescriptor=function(t,e){t(null)},DrawioFile.prototype.loadPatchDescriptor=function(t,e){this.loadDescriptor(mxUtils.bind(this,(function(e){t(e)})),e)},DrawioFile.prototype.patchDescriptor=function(t,e){this.setDescriptorEtag(t,this.getDescriptorEtag(e)),this.descriptorChanged()},DrawioFile.prototype.startSync=function(){"auto"!=DrawioFile.SYNC||"1"==urlParams.stealth||"1"!=urlParams.rt&&this.ui.editor.chromeless&&!this.ui.editor.editable||(null==this.sync&&(this.sync=new DrawioFileSync(this)),this.sync.start())},DrawioFile.prototype.isConflict=function(){return!1},DrawioFile.prototype.getChannelId=function(){return Graph.compress(this.getHash()).replace(/[\/ +]/g,"_")},DrawioFile.prototype.getChannelKey=function(t){return null},DrawioFile.prototype.getCurrentUser=function(){return null},DrawioFile.prototype.getLatestVersion=function(t,e){t(null)},DrawioFile.prototype.getLastModifiedDate=function(){return new Date},DrawioFile.prototype.setCurrentRevisionId=function(t){this.setDescriptorRevisionId(this.getDescriptor(),t)},DrawioFile.prototype.getCurrentRevisionId=function(){return this.getDescriptorRevisionId(this.getDescriptor())},DrawioFile.prototype.setCurrentEtag=function(t){this.setDescriptorEtag(this.getDescriptor(),t)},DrawioFile.prototype.getCurrentEtag=function(){return this.getDescriptorEtag(this.getDescriptor())},DrawioFile.prototype.getDescriptor=function(){return null},DrawioFile.prototype.setDescriptor=function(){},DrawioFile.prototype.setDescriptorRevisionId=function(t,e){this.setDescriptorEtag(t,e)},DrawioFile.prototype.getDescriptorRevisionId=function(t){return this.getDescriptorEtag(t)},DrawioFile.prototype.setDescriptorEtag=function(t,e){},DrawioFile.prototype.getDescriptorEtag=function(t){return null},DrawioFile.prototype.getDescriptorSecret=function(t){return null},DrawioFile.prototype.installListeners=function(){null==this.changeListener&&(this.changeListener=mxUtils.bind(this,(function(t,e){var i=null!=e?e.getProperty("edit"):null;!this.changeListenerEnabled||!this.isEditable()||null!=i&&i.ignoreEdit||this.fileChanged()})),this.ui.editor.graph.model.addListener(mxEvent.CHANGE,this.changeListener),this.ui.editor.graph.addListener("gridSizeChanged",this.changeListener),this.ui.editor.graph.addListener("shadowVisibleChanged",this.changeListener),this.ui.addListener("pageFormatChanged",this.changeListener),this.ui.addListener("pageScaleChanged",this.changeListener),this.ui.addListener("backgroundColorChanged",this.changeListener),this.ui.addListener("backgroundImageChanged",this.changeListener),this.ui.addListener("foldingEnabledChanged",this.changeListener),this.ui.addListener("mathEnabledChanged",this.changeListener),this.ui.addListener("gridEnabledChanged",this.changeListener),this.ui.addListener("guidesEnabledChanged",this.changeListener),this.ui.addListener("tooltipsEnabledChanged",this.changeListener),this.ui.addListener("pageViewChanged",this.changeListener),this.ui.addListener("connectionPointsChanged",this.changeListener),this.ui.addListener("connectionArrowsChanged",this.changeListener))},DrawioFile.prototype.addAllSavedStatus=function(t){if(null!=this.ui.statusContainer&&this.ui.getCurrentFile()==this){t=null!=t?t:mxUtils.htmlEntities(mxResources.get(this.allChangesSavedKey)),this.ui.editor.setStatus('<div title="'+t+'">'+t+"</div>");var e=this.ui.statusContainer.getElementsByTagName("div");e.length>0&&this.isRevisionHistorySupported()&&(e[0].style.cursor="pointer",e[0].style.textDecoration="underline",mxEvent.addListener(e[0],"click",mxUtils.bind(this,(function(){this.ui.actions.get("revisionHistory").funct()}))))}},DrawioFile.prototype.saveDraft=function(){try{null==this.draftId&&(this.draftId=Editor.guid());var t={type:"draft",created:this.created,modified:(new Date).getTime(),data:this.ui.getFileData(),title:this.getTitle(),fileObject:this.fileObject,aliveCheck:this.ui.draftAliveCheck};this.ui.setDatabaseItem(".draft_"+this.draftId,JSON.stringify(t)),EditorUi.debug("draft saved",this.draftId,t)}catch(t){this.removeDraft()}},DrawioFile.prototype.removeDraft=function(){try{null!=this.draftId&&(this.ui.removeDatabaseItem(".draft_"+this.draftId),EditorUi.debug("draft deleted",".draft_"+this.draftId))}catch(t){}},DrawioFile.prototype.addUnsavedStatus=function(t){if(!this.inConflictState&&null!=this.ui.statusContainer&&this.ui.getCurrentFile()==this)if(t instanceof Error&&null!=t.message&&""!=t.message){var e=mxUtils.htmlEntities(mxResources.get("unsavedChanges"));this.ui.editor.setStatus('<div title="'+e+'" class="geStatusAlert">'+e+" ("+mxUtils.htmlEntities(t.message)+")</div>")}else{var i=this.getErrorMessage(t);if(null==i&&null!=this.lastSaved){var s=this.ui.timeSince(new Date(this.lastSaved));null!=s&&(i=mxResources.get("lastSaved",[s]))}null!=i&&i.length>60&&(i=i.substring(0,60)+"..."),e=mxUtils.htmlEntities(mxResources.get("unsavedChangesClickHereToSave"))+(null!=i&&""!=i?" ("+mxUtils.htmlEntities(i)+")":""),this.ui.editor.setStatus('<div title="'+e+'" class="geStatusAlertOrange">'+e+' <img src="'+Editor.saveImage+'"/></div>');var n=this.ui.statusContainer.getElementsByTagName("div");null!=n&&n.length>0?(n[0].style.cursor="pointer",mxEvent.addListener(n[0],"click",mxUtils.bind(this,(function(){this.ui.actions.get(null!=this.ui.mode&&this.isEditable()?"save":"saveAs").funct()})))):(e=mxUtils.htmlEntities(mxResources.get("unsavedChanges")),this.ui.editor.setStatus('<div title="'+e+'" class="geStatusAlert">'+e+" ("+mxUtils.htmlEntities(t.message)+")</div>")),EditorUi.enableDrafts&&(null==this.getMode()||EditorUi.isElectronApp)&&(null!=this.saveDraftThread&&window.clearTimeout(this.saveDraftThread),this.saveDraftThread=window.setTimeout(mxUtils.bind(this,(function(){this.saveDraft()})),0))}},DrawioFile.prototype.addConflictStatus=function(t,e){this.invalidChecksum&&null==e&&(e=mxResources.get("checksum")),this.setConflictStatus(mxUtils.htmlEntities(mxResources.get("fileChangedSync"))+(null!=e&&""!=e?" ("+mxUtils.htmlEntities(e)+")":"")),this.ui.spinner.stop(),this.clearAutosave();var i=null!=this.ui.statusContainer?this.ui.statusContainer.getElementsByTagName("div"):null;null!=i&&i.length>0?(i[0].style.cursor="pointer",mxEvent.addListener(i[0],"click",mxUtils.bind(this,(function(e){"IMG"!=mxEvent.getSource(e).nodeName&&t()})))):this.ui.alert(mxUtils.htmlEntities(mxResources.get("fileChangedSync")),t)},DrawioFile.prototype.setConflictStatus=function(t){this.ui.editor.setStatus('<div title="'+t+'" class="geStatusAlert">'+t+' <a href="https://www.diagrams.net/doc/faq/synchronize" title="'+mxResources.get("help")+'" target="_blank"><img src="'+Editor.helpImage+'"/></a></div>')},DrawioFile.prototype.showRefreshDialog=function(t,e,i){null==i&&(i=mxResources.get("checksum")),this.ui.editor.isChromelessView()&&!this.ui.editor.editable?this.ui.alert(mxResources.get("fileChangedSync"),mxUtils.bind(this,(function(){this.reloadFile(t,e)}))):(this.addConflictStatus(mxUtils.bind(this,(function(){this.showRefreshDialog(t,e)})),i),this.ui.showError(mxResources.get("error")+" ("+i+")",mxResources.get("fileChangedSyncDialog"),mxResources.get("makeCopy"),mxUtils.bind(this,(function(){this.copyFile(t,e)})),null,mxResources.get("synchronize"),mxUtils.bind(this,(function(){this.reloadFile(t,e)})),mxResources.get("cancel"),mxUtils.bind(this,(function(){this.ui.hideDialog()})),360,150))},DrawioFile.prototype.showCopyDialog=function(t,e,i){this.inConflictState=!1,this.invalidChecksum=!1,this.addUnsavedStatus(),this.ui.showError(mxResources.get("externalChanges"),mxResources.get("fileChangedOverwriteDialog"),mxResources.get("makeCopy"),mxUtils.bind(this,(function(){this.copyFile(t,e)})),null,mxResources.get("overwrite"),i,mxResources.get("cancel"),mxUtils.bind(this,(function(){this.ui.hideDialog()})),360,150)},DrawioFile.prototype.showConflictDialog=function(t,e){this.ui.showError(mxResources.get("externalChanges"),mxResources.get("fileChangedSyncDialog"),mxResources.get("overwrite"),t,null,mxResources.get("synchronize"),e,mxResources.get("cancel"),mxUtils.bind(this,(function(){this.ui.hideDialog(),this.handleFileError(null,!1)})),340,150)},DrawioFile.prototype.redirectToNewApp=function(t,e){if(this.ui.spinner.stop(),!this.redirectDialogShowing){this.redirectDialogShowing=!0;var i=window.location.protocol+"//"+window.location.host+"/"+this.ui.getSearch(["create","title","mode","url","drive","splash","state"])+"#"+this.getHash(),s=mxResources.get("redirectToNewApp");null!=e&&(s+=" ("+e+")");var n=mxUtils.bind(this,(function(){var e=mxUtils.bind(this,(function(){this.redirectDialogShowing=!1,window.location.href==i?window.location.reload():window.location.href=i}));null==t&&this.isModified()?this.ui.confirm(mxResources.get("allChangesLost"),mxUtils.bind(this,(function(){this.redirectDialogShowing=!1})),e,mxResources.get("cancel"),mxResources.get("discardChanges")):e()}));null!=t?this.isModified()?this.ui.confirm(s,mxUtils.bind(this,(function(){this.redirectDialogShowing=!1,t()})),n,mxResources.get("cancel"),mxResources.get("discardChanges")):this.ui.confirm(s,n,mxUtils.bind(this,(function(){this.redirectDialogShowing=!1,t()}))):this.ui.alert(mxResources.get("redirectToNewApp"),n)}},DrawioFile.prototype.handleFileSuccess=function(t){this.ui.spinner.stop(),this.ui.getCurrentFile()==this&&(this.isModified()?this.fileChanged():t?(this.isTrashed()?this.addAllSavedStatus(mxUtils.htmlEntities(mxResources.get(this.allChangesSavedKey))+" ("+mxUtils.htmlEntities(mxResources.get("fileMovedToTrash"))+")"):this.addAllSavedStatus(),null!=this.sync&&(this.sync.resetUpdateStatusThread(),this.sync.remoteFileChanged&&(this.sync.remoteFileChanged=!1,this.sync.fileChangedNotify()))):this.ui.editor.setStatus(""))},DrawioFile.prototype.handleFileError=function(t,e){if(this.ui.spinner.stop(),this.ui.getCurrentFile()==this)if(this.inConflictState)this.handleConflictError(t,e);else if(this.isModified()&&this.addUnsavedStatus(t),e)this.ui.handleError(t,null!=t?mxResources.get("errorSavingFile"):null);else if(!this.isModified()){var i=this.getErrorMessage(t);null!=i&&i.length>60&&(i=i.substring(0,60)+"..."),this.ui.editor.setStatus('<div class="geStatusAlert">'+mxUtils.htmlEntities(mxResources.get("error"))+(null!=i?" ("+mxUtils.htmlEntities(i)+")":"")+"</div>")}},DrawioFile.prototype.handleConflictError=function(t,e){var i=mxUtils.bind(this,(function(){this.handleFileSuccess(!0)})),s=mxUtils.bind(this,(function(t){this.handleFileError(t,!0)})),n=mxUtils.bind(this,(function(){if(this.ui.spinner.spin(document.body,mxResources.get(this.savingSpinnerKey))){this.ui.editor.setStatus("");var e=this.constructor==GitHubFile||this.constructor==GitLabFile;this.save(!0,i,s,null,!0,e&&null!=t?t.commitMessage:null)}})),o=mxUtils.bind(this,(function(){this.ui.spinner.spin(document.body,mxResources.get("updatingDocument"))&&this.synchronizeFile(mxUtils.bind(this,(function(){if(this.ui.spinner.stop(),this.ui.spinner.spin(document.body,mxResources.get(this.savingSpinnerKey))){var e=this.constructor==GitHubFile||this.constructor==GitLabFile;this.save(!0,i,s,null,null,e&&null!=t?t.commitMessage:null)}})),s)}));"none"==DrawioFile.SYNC?this.showCopyDialog(i,s,n):this.invalidChecksum?this.showRefreshDialog(i,s,this.getErrorMessage(t)):e?this.showConflictDialog(n,o):this.addConflictStatus(mxUtils.bind(this,(function(){this.ui.editor.setStatus(mxUtils.htmlEntities(mxResources.get("updatingDocument"))),this.synchronizeFile(i,s)})),this.getErrorMessage(t))},DrawioFile.prototype.getErrorMessage=function(t){var e=null!=t?null!=t.error?t.error.message:t.message:null;return null==e&&null!=t&&t.code==App.ERROR_TIMEOUT&&(e=mxResources.get("timeout")),e},DrawioFile.prototype.isOverdue=function(){return null!=this.ageStart&&Date.now()-this.ageStart.getTime()>=this.ui.warnInterval},DrawioFile.prototype.fileChanged=function(){this.lastChanged=new Date,this.setModified(!0),this.isAutosave()?(null!=this.savingStatusKey&&this.addAllSavedStatus(mxUtils.htmlEntities(mxResources.get(this.savingStatusKey))+"..."),this.ui.scheduleSanityCheck(),null==this.ageStart&&(this.ageStart=new Date),this.sendFileChanges(),this.autosave(this.autosaveDelay,this.maxAutosaveDelay,mxUtils.bind(this,(function(t){this.ui.stopSanityCheck(),null==this.autosaveThread?(this.handleFileSuccess(!0),this.ageStart=null):this.isModified()&&(this.ui.scheduleSanityCheck(),this.ageStart=this.lastChanged)})),mxUtils.bind(this,(function(t){this.handleFileError(t)})))):(this.ageStart=null,this.isAutosaveOptional()&&this.ui.editor.autosave||this.inConflictState||this.addUnsavedStatus())},DrawioFile.prototype.isOptimisticSync=function(){return!1},DrawioFile.prototype.createSecret=function(t){var e=Editor.guid(32);null==this.sync||this.isOptimisticSync()?t(e):this.sync.createToken(e,mxUtils.bind(this,(function(i){t(e,i)})),mxUtils.bind(this,(function(){t(e)})))},DrawioFile.prototype.fileSaving=function(){null!=this.sync&&this.isOptimisticSync()&&this.sync.fileSaving(),"1"==urlParams.test&&EditorUi.debug("DrawioFile.fileSaving",[this])},DrawioFile.prototype.sendFileChanges=function(){try{null!=this.p2pCollab&&null!=this.sync&&(this.updateFileData(),this.sync.sendFileChanges(this.ui.getPagesForNode(mxUtils.parseXml(this.getData()).documentElement),this.desc),"1"==urlParams.test&&EditorUi.debug("DrawioFile.sendFileChanges",[this]))}catch(t){console.log(t)}},DrawioFile.prototype.fileSaved=function(t,e,i,s,n){this.lastSaved=new Date,this.ageStart=null;try{this.stats.saved++,this.inConflictState=!1,this.invalidChecksum=!1,null==this.sync||this.isOptimisticSync()?(this.shadowData=t,this.shadowPages=null,null!=this.sync&&(this.sync.lastModified=this.getLastModifiedDate(),this.sync.resetUpdateStatusThread()),null!=i&&i()):this.sync.fileSaved(this.ui.getPagesForNode(mxUtils.parseXml(t).documentElement),e,i,s,n)}catch(t){this.inConflictState=!0,this.invalidChecksum=!0,this.descriptorChanged(),null!=s&&s(t);try{if(this.errorReportsEnabled)this.sendErrorReport("Error in fileSaved",null,t);else{var o=this.getCurrentUser(),r=null!=o?o.id:"unknown";EditorUi.logError("Error in fileSaved",null,this.getMode()+"."+this.getId(),r,t)}}catch(t){}}"1"==urlParams.test&&EditorUi.debug("DrawioFile.fileSaved",[this])},DrawioFile.prototype.autosave=function(t,e,i,s){null==this.lastAutosave&&(this.lastAutosave=Date.now());var n=Date.now()-this.lastAutosave<e?t:0;this.clearAutosave();var o=window.setTimeout(mxUtils.bind(this,(function(){if(this.lastAutosave=null,this.autosaveThread==o&&(this.autosaveThread=null),this.isModified()&&this.isAutosaveNow()){var t=this.isAutosaveRevision();t&&(this.lastAutosaveRevision=(new Date).getTime()),this.save(t,mxUtils.bind(this,(function(t){this.autosaveCompleted(),null!=i&&i(t)})),mxUtils.bind(this,(function(t){null!=s&&s(t)})))}else this.isModified()||this.ui.editor.setStatus(""),null!=i&&i(null)})),n);this.autosaveThread=o},DrawioFile.prototype.isAutosaveNow=function(){return!0},DrawioFile.prototype.autosaveCompleted=function(){},DrawioFile.prototype.clearAutosave=function(){null!=this.autosaveThread&&(window.clearTimeout(this.autosaveThread),this.autosaveThread=null)},DrawioFile.prototype.isAutosaveRevision=function(){var t=(new Date).getTime();return null==this.lastAutosaveRevision||t-this.lastAutosaveRevision>this.maxAutosaveRevisionDelay},DrawioFile.prototype.descriptorChanged=function(){this.fireEvent(new mxEventObject("descriptorChanged"))},DrawioFile.prototype.contentChanged=function(){this.fireEvent(new mxEventObject("contentChanged"))},DrawioFile.prototype.close=function(t){this.updateFileData(),this.stats.closed++,this.isAutosave()&&this.isModified()&&this.save(this.isAutosaveRevision(),null,null,t),this.destroy()},DrawioFile.prototype.hasSameExtension=function(t,e){if(null!=t&&null!=e){var i=t.lastIndexOf(".");return(i>0?t.substring(i):"")===((i=e.lastIndexOf("."))>0?e.substring(i):"")}return t==e},DrawioFile.prototype.removeListeners=function(){null!=this.changeListener&&(this.ui.editor.graph.model.removeListener(this.changeListener),this.ui.editor.graph.removeListener(this.changeListener),this.ui.removeListener(this.changeListener),this.changeListener=null)},DrawioFile.prototype.destroy=function(){this.clearAutosave(),this.removeListeners(),this.stats.destroyed++,null!=this.sync&&(this.sync.destroy(),this.sync=null)},DrawioFile.prototype.commentsSupported=function(){return!1},DrawioFile.prototype.commentsRefreshNeeded=function(){return!0},DrawioFile.prototype.commentsSaveNeeded=function(){return!1},DrawioFile.prototype.getComments=function(t,e){t([])},DrawioFile.prototype.addComment=function(t,e,i){e(Date.now())},DrawioFile.prototype.canReplyToReplies=function(){return!0},DrawioFile.prototype.canComment=function(){return!0},DrawioFile.prototype.newComment=function(t,e){return new DrawioComment(this,null,t,Date.now(),Date.now(),!1,e)};