UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 3.14 kB
LocalFile=function(i,t,e,l,s,n){DrawioFile.call(this,i,t),this.title=e,this.mode=l?null:App.MODE_DEVICE,this.fileHandle=s,this.desc=n},mxUtils.extend(LocalFile,DrawioFile),LocalFile.prototype.isAutosave=function(){return null!=this.fileHandle&&!this.invalidFileHandle&&DrawioFile.prototype.isAutosave.apply(this,arguments)},LocalFile.prototype.isAutosaveOptional=function(){return null!=this.fileHandle},LocalFile.prototype.getMode=function(){return this.mode},LocalFile.prototype.getTitle=function(){return this.title},LocalFile.prototype.isRenamable=function(){return!0},LocalFile.prototype.save=function(i,t,e){this.saveAs(this.title,t,e)},LocalFile.prototype.saveAs=function(i,t,e){this.saveFile(i,!1,t,e)},LocalFile.prototype.saveAs=function(i,t,e){this.saveFile(i,!1,t,e)},LocalFile.prototype.getDescriptor=function(){return this.desc},LocalFile.prototype.setDescriptor=function(i){this.desc=i},LocalFile.prototype.getLatestVersion=function(i,t){null==this.fileHandle?i(null):this.ui.loadFileSystemEntry(this.fileHandle,i,t)},LocalFile.prototype.saveFile=function(i,t,e,l,s){i!=this.title&&(this.fileHandle=null,this.desc=null),this.title=i,s||this.updateFileData();var n=this.ui.useCanvasForExport&&/(\.png)$/i.test(this.getTitle());this.setShadowModified(!1);var o=this.getData(),a=mxUtils.bind(this,(function(){this.setModified(this.getShadowModified()),this.contentChanged(),null!=e&&e()})),h=mxUtils.bind(this,(function(t){if(null!=this.fileHandle){if(!this.savingFile){this.savingFileTime=new Date,this.savingFile=!0;var e=mxUtils.bind(this,(function(i){this.savingFile=!1,null!=l&&l({error:i})}));this.saveDraft(),this.fileHandle.createWritable().then(mxUtils.bind(this,(function(i){this.fileHandle.getFile().then(mxUtils.bind(this,(function(l){this.invalidFileHandle=null,this.desc.lastModified==l.lastModified?i.write(n?this.ui.base64ToBlob(t,"image/png"):t).then(mxUtils.bind(this,(function(){i.close().then(mxUtils.bind(this,(function(){this.fileHandle.getFile().then(mxUtils.bind(this,(function(i){try{var t=this.desc;this.savingFile=!1,this.desc=i,this.fileSaved(o,t,a,e),this.removeDraft()}catch(i){e(i)}})),e)})),e)})),e):(this.inConflictState=!0,e())})),mxUtils.bind(this,(function(i){this.invalidFileHandle=!0,e(i)})))})),e)}}else{if(this.ui.isOfflineApp()||this.ui.isLocalFileSave())this.ui.doSaveLocalFile(t,i,n?"image/png":"text/xml",n);else if(t.length<MAX_REQUEST_SIZE){var s=i.lastIndexOf("."),h=s>0?i.substring(s+1):"xml";new mxXmlRequest(SAVE_URL,"format="+h+"&xml="+encodeURIComponent(t)+"&filename="+encodeURIComponent(i)+(n?"&binary=1":"")).simulate(document,"_blank")}else this.ui.handleError({message:mxResources.get("drawingTooLarge")},mxResources.get("error"),mxUtils.bind(this,(function(){mxUtils.popup(t)})));a()}}));if(n){var r=this.ui.getPngFileProperties(this.ui.fileNode);this.ui.getEmbeddedPng(mxUtils.bind(this,(function(i){h(i)})),l,this.ui.getCurrentFile()!=this?o:null,r.scale,r.border)}else h(o)},LocalFile.prototype.rename=function(i,t,e){this.title=i,this.descriptorChanged(),null!=t&&t()},LocalFile.prototype.open=function(){this.ui.setFileData(this.getData()),this.installListeners()};