4 lines
5.5 KiB
JavaScript
4 lines
5.5 KiB
JavaScript
|
|
(function() {
|
||
|
|
"use strict";function M(){Editor.enableNativeClipboard=!0,EditorUi.prototype.isStandaloneApp=function(){return!0}}function D(){EditorUi.enablePlantUml=!0}function $(o,d){o.loadFile("U"+encodeURIComponent(d),!0)}function C(o){var d=Menus.prototype.init;Menus.prototype.init=function(){d.apply(this,arguments);var r=this.editorUi;r.actions.put("open",new Action(mxResources.get("open"),function(){o.sendMessage("open",null,"open"+new Date().getTime(),(n,s)=>{$(r,n)})})),this.put("file",new Menu(mxUtils.bind(this,function(n,s){this.addMenuItems(n,["new","open","copyLink"],s),this.addSubmenu("openRecent",n,s),this.addMenuItems(n,["-",,"save","saveAs","-","import"],s),this.addSubmenu("exportAs",n,s),n.addSeparator(s),this.addSubmenu("embed",n,s),n.addSeparator(s),this.addMenuItems(n,["newLibrary","openLibrary"],s);var u=r.getCurrentFile();if(u!=null&&r.fileNode!=null){var c=u.getTitle()!=null?u.getTitle():r.defaultFilename;!/(\.html)$/i.test(c)&&!/(\.svg)$/i.test(c)&&this.addMenuItems(n,["-","properties"])}this.addMenuItems(n,["-","pageSetup","print","-","close","-","appVersion","exit"],s)}))),r.actions.get("fullscreen").visible=!0,r.actions.put("appVersion",new Action("v0.1.36",function(n,s){}))}}function I(){const o=new Date,d=o.getFullYear().toString(),r=(o.getMonth()+1).toString().padStart(2,"0"),n=o.getDate().toString().padStart(2,"0"),s=o.getHours().toString().padStart(2,"0"),u=o.getMinutes().toString().padStart(2,"0"),c=o.getSeconds().toString().padStart(2,"0"),t=`${d}${r}${n}${s}${u}${c}`,e="abcdefghijklmnopqrstuvwxyz";let i="";for(let a=0;a<7;a++)i+=e.charAt(Math.floor(Math.random()*e.length));return`${t}-${i}`}function R(o,d){const r=o.split(".");let n=r.pop();r[r.length-1]=="drawio"&&(n="drawio."+n,r.pop());const s=r.join(".");return/^.+-\d{14}-[a-zA-Z0-9]{7}$/.test(s)?o:`${s}-${I()}.${n}`}window.VSD_CONVERT_URL=null;window.EMF_CONVERT_URL=null;window.ICONSEARCH_PATH=null;const v="storage/petal/siyuan-drawio-plugin/",A="assets",N="assets/drawio/";if(window.parent.siyuan){let n=function(){return decodeURIComponent(location.hash.substring(2))},s=function(t){const e=n(),i=e.lastIndexOf("/");return e?i!==-1?e.substring(0,i+1):"":[".drawio.svg",".drawio.png"].some(a=>t.includes(a))?N:v},c=function(t){return/(\.png)$/i.test(t)};const o=window.electron;async function d(t,e,i){const a=new FormData;return a.append("path",t),a.append("isDir",e.toString()),a.append("modTime",Date.now().toString()),a.append("file",i),await fetch("/api/file/putFile",{method:"POST",body:a}).then(p=>p.json())}async function r(t){t.path&&(t.path.startsWith("/")?t.path="/data"+t.path:t.path="/data/"+t.path);const e=await fetch("/api/file/getFile",{body:JSON.stringify(t),method:"POST"});if(e.status===200)return c(t.path)?e.blob().then(i=>new Promise((a,p)=>{const l=new FileReader;l.readAsDataURL(i),l.onloadend=()=>a(l.result),l.onerror=p})):e.text();{const i=await e.json();throw new Error(i.msg)}}async function u(t,e,i){const p="/data/"+s(e),l=R(e),m=typeof t=="object"&&t instanceof Blob?t:new Blob([t],{type:i.mimeType}),g=new File([m],l,{type:i.mimeType}),f=p+l;return(await d(f,!1,g)).code===0?{success:!0,newTitle:l}:{success:!1}}App.mode=App.MODE_DEVICE,App.prototype.showSaveFilePicker=function(t,e,i){t(null,{name:i.suggestedName})},App.prototype.fetchAndShowNotification=function(){},LocalFile.prototype.saveFile=function(t,e,i,a,p,l,m){t!=this.title&&(this.fileHandle=null,this.desc=null,this.editable=null),this.title=t,p||this.updateFileData();var g=c(this.getTitle());this.setShadowModified(!1);var f=this.getData(),S=mxUtils.bind(this,function(){this.setModified(this.getShadowModified()),this.contentChanged(),i!=null&&i()}),b=mxUtils.bind(this,function(w){if(!this.savingFile){this.savingFileTime=new Date,this.savingFile=!0;var y=mxUtils.bind(this,function(h){this.savingFile=!1,a!=null&&a({error:h})});this.saveDraft(f);const E=t.split(".").pop().toLowerCase(),U=this.ui.editor.diagramFileTypes.find(h=>h.extension===E);if(!U)throw new Error(`Unsupported file extension: ${E}`);let T=g?this.ui.base64ToBlob(w,"image/png"):w;u(T,t,U).then(h=>{if(h.success){
|
||
|
|
|
||
|
|
})();
|