UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 4.51 kB
StorageFile=function(t,e,i){DrawioFile.call(this,t,e),this.title=i},mxUtils.extend(StorageFile,DrawioFile),StorageFile.prototype.autosaveDelay=2e3,StorageFile.prototype.maxAutosaveDelay=2e4,StorageFile.prototype.type="F",StorageFile.prototype.getMode=function(){return App.MODE_BROWSER},StorageFile.prototype.isAutosaveOptional=function(){return!0},StorageFile.prototype.getHash=function(){return"L"+encodeURIComponent(this.getTitle())},StorageFile.prototype.getTitle=function(){return this.title},StorageFile.prototype.isRenamable=function(){return!0},StorageFile.prototype.save=function(t,e,i){this.saveAs(this.getTitle(),e,i)},StorageFile.prototype.saveAs=function(t,e,i){DrawioFile.prototype.save.apply(this,arguments),this.saveFile(t,!1,e,i)},StorageFile.insertFile=function(t,e,i,l,o){var a=mxUtils.bind(this,(function(a){var n=function(){var a=new StorageFile(t,i,e);a.saveFile(e,!1,(function(){l(a)}),o)};a?t.confirm(mxResources.get("replaceIt",[e]),n,o):n()}));StorageFile.getFileContent(t,e,(function(t){a(null!=t)}),(function(){a(!1)}))},StorageFile.getFileContent=function(t,e,i,l){t.getDatabaseItem(e,(function(t){i(null!=t?t.data:null)}),mxUtils.bind(this,(function(){null==t.database?t.getLocalData(e,i):null!=l&&l()})),"files")},StorageFile.getFileInfo=function(t,e,i,l){t.getDatabaseItem(e,(function(t){i(t)}),mxUtils.bind(this,(function(){null==t.database?t.getLocalData(e,(function(t){i(null!=t?{title:e}:null)})):null!=l&&l()})),"filesInfo")},StorageFile.prototype.saveFile=function(t,e,i,l){if(this.isEditable()){var o=mxUtils.bind(this,(function(){this.isRenamable()&&(this.title=t);try{var e=mxUtils.bind(this,(function(){this.setModified(this.getShadowModified()),this.contentChanged(),null!=i&&i()}));this.setShadowModified(!1);var o=this.getData();this.ui.setDatabaseItem(null,[{title:this.title,size:o.length,lastModified:Date.now(),type:this.type},{title:this.title,data:o}],e,mxUtils.bind(this,(function(){null==this.ui.database?this.ui.setLocalData(this.title,o,e):null!=l&&l()})),["filesInfo","files"])}catch(t){null!=l&&l(t)}}));this.isRenamable()&&"."==t.charAt(0)&&null!=l?l({message:mxResources.get("invalidName")}):StorageFile.getFileInfo(this.ui,t,mxUtils.bind(this,(function(e){this.isRenamable()&&this.getTitle()!=t&&null!=e?this.ui.confirm(mxResources.get("replaceIt",[t]),o,l):o()})),l)}else null!=i&&i()},StorageFile.prototype.rename=function(t,e,i){var l=this.getTitle();l!=t?StorageFile.getFileInfo(this.ui,t,mxUtils.bind(this,(function(o){var a=mxUtils.bind(this,(function(){this.title=t,this.hasSameExtension(l,t)||this.setData(this.ui.getFileData()),this.saveFile(t,!1,mxUtils.bind(this,(function(){this.ui.removeLocalData(l,e)})),i)}));null!=o?this.ui.confirm(mxResources.get("replaceIt",[t]),a,i):a()})),i):e()},StorageFile.prototype.open=function(){DrawioFile.prototype.open.apply(this,arguments),this.saveFile(this.getTitle())},StorageFile.prototype.getLatestVersion=function(t,e){StorageFile.getFileContent(this.ui,this.title,mxUtils.bind(this,(function(e){t(new StorageFile(this.ui,e,this.title))})),e)},StorageFile.prototype.destroy=function(){DrawioFile.prototype.destroy.apply(this,arguments),null!=this.storageListener&&(mxEvent.removeListener(window,"storage",this.storageListener),this.storageListener=null)},StorageFile.listLocalStorageFiles=function(t){for(var e=[],i=0;i<localStorage.length;i++){var l=localStorage.key(i),o=localStorage.getItem(l);if(l.length>0&&"."!=l.charAt(0)&&o.length>0){var a=!(null!=t&&"F"!=t||"<mxfile "!==o.substring(0,8)&&"<?xml"!==o.substring(0,5)&&"\x3c!--[if IE]>"!==o.substring(0,12)),n=(null==t||"L"==t)&&"<mxlibrary>"===o.substring(0,11);(a||n)&&e.push({title:l,type:a?"F":"L",size:o.length,lastModified:Date.now()})}}return e},StorageFile.migrate=function(t){var e=StorageFile.listLocalStorageFiles();e.push({title:".scratchpad",type:"L"});for(var i=t.transaction(["files","filesInfo"],"readwrite"),l=i.objectStore("files"),o=i.objectStore("filesInfo"),a=0;a<e.length;a++){var n=e[a],s=localStorage.getItem(n.title);l.add({title:n.title,data:s}),o.add(n)}},StorageFile.listFiles=function(t,e,i,l){t.getDatabaseItems((function(t){var l=[];if(null!=t)for(var o=0;o<t.length;o++)"."==t[o].title.charAt(0)||null!=e&&t[o].type!=e||l.push(t[o]);i(l)}),(function(){null==t.database?i(StorageFile.listLocalStorageFiles(e)):null!=l&&l()}),"filesInfo")},StorageFile.deleteFile=function(t,e,i,l){t.removeDatabaseItem([e,e],i,(function(){null==t.database?(localStorage.removeItem(e),i()):null!=l&&l()}),["files","filesInfo"])};