@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 11.9 kB
JavaScript
function mxODPicker(e,t,i,o,n,l,r,d,s,a,c,m,u){var p="";function h(e,t){return(t=t||document).querySelector(e)}null==t&&(t=function(e){if(null!=M)if(M.style.background="transparent",M.innerHTML="",null==e||e.folder||/\.drawiolib$/.test(e.name))t(mxResources.get("noPreview"));else try{null!=e.remoteItem&&(e=e.remoteItem),k=e,g.spin(M),S(e,(function(i){if(g.stop(),k==e)if("mxlibrary"==i.documentElement.nodeName)t(mxResources.get("noPreview"));else{var o=i.getElementsByTagName("diagram");w=AspectDialog.prototype.createViewer(M,0==o.length?i.documentElement:o[0],null,"transparent")}}),(function(){E=null,t(mxResources.get("notADiagramFile"))}))}catch(e){E=null,t(mxResources.get("notADiagramFile"))}function t(e){M.style.background="transparent",M.innerHTML="";var t=document.createElement("div");t.className="odPreviewStatus",mxUtils.write(t,e),M.appendChild(t),g.stop()}},p='<div style="text-align: center;" class="odPreview"></div>'),null==n&&(n=function(){var e=null;try{e=JSON.parse(localStorage.getItem("mxODPickerRecentList"))}catch(e){}return e}),null==l&&(l=function(e){if(null!=e){var t=n()||{};delete e["@microsoft.graph.downloadUrl"],t[e.id]=e,localStorage.setItem("mxODPickerRecentList",JSON.stringify(t))}});var f='<div class="odCatsList"><div class="odCatsListLbl">OneDrive</div><div id="odFiles" class="odCatListTitle odCatSelected">'+mxUtils.htmlEntities(mxResources.get("files"))+'</div><div id="odRecent" class="odCatListTitle">'+mxUtils.htmlEntities(mxResources.get("recent"))+'</div><div id="odShared" class="odCatListTitle">'+mxUtils.htmlEntities(mxResources.get("shared"))+'</div><div id="odSharepoint" class="odCatListTitle">'+mxUtils.htmlEntities(mxResources.get("sharepoint"))+'</div></div><div class="odFilesSec"><div class="searchBar" style="display:none"><input type="search" id="odSearchBox" placeholder="'+mxUtils.htmlEntities(mxResources.get("search"))+'"></div><div class="odFilesBreadcrumb"></div><div id="refreshOD" class="odRefreshButton"><img src="/images/update32.png" width="16" height="16" title="'+mxUtils.htmlEntities(mxResources.get("refresh"))+'Refresh" border="0"/></div><div class="odFilesList"></div></div>'+p+(a?'<div id="odBackBtn" class="odLinkBtn">< '+mxUtils.htmlEntities(mxResources.get("back"))+"</div>":"")+(c?'<button id="odSubmitBtn" class="odSubmitBtn">'+mxUtils.htmlEntities(mxResources.get(s?"save":"open"))+"</button>":""),x=null!=window.Editor&&null!=Editor.isDarkMode&&Editor.isDarkMode(),v=".odCatsList {\tbox-sizing: border-box;\tposition:absolute;\ttop:0px;\tbottom:50%;\twidth:30%;\tborder: 1px solid #CCCCCC;\tborder-bottom:none;\tdisplay: inline-block;\toverflow-x: hidden;\toverflow-y: auto;}.odCatsListLbl {\theight: 17px;\tcolor: #6D6D6D;\tfont-size: 14px;\tfont-weight: bold;\tline-height: 17px;\tmargin: 10px 0 3px 5px;}.odFilesSec {\tbox-sizing: border-box;\tposition:absolute;\tleft:30%;\ttop:0px;\tbottom:50%;\twidth: 70%;\tborder: 1px solid #CCCCCC;\tborder-left:none;\tborder-bottom:none;\tdisplay: inline-block;\toverflow: hidden;}.odFilesBreadcrumb {\tbox-sizing: border-box;\tposition:absolute;\tmin-height: 32px;\tleft:0px;\tright:20px;\ttext-overflow:ellipsis;\toverflow:hidden;\tfont-size: 13px;\tcolor: #6D6D6D;\tpadding: 5px;}.odRefreshButton {\tbox-sizing: border-box;\tposition:absolute;\tright:0px;\ttop:0px;\tpadding: 4px;\tmargin: 1px;\theight:24px;\tcursor:default;}.odRefreshButton>img {\topacity:0.5;}.odRefreshButton:hover {\tbackground-color:#ddd;\tborder-radius:50%;}.odRefreshButton:active {\topacity:0.7;}.odFilesList {\tbox-sizing: border-box;\tposition:absolute;\ttop:32px;\tbottom:0px;\twidth: 100%;\toverflow-x: hidden;\toverflow-y: auto;}.odFileImg {\twidth: 24px;\tpadding-left: 5px;\tpadding-right: 5px;}.odFileTitle {\tcursor: default;\tfont-weight: normal;\tcolor: #666666 !important;\twidth: calc(100% - 20px);\twhite-space: nowrap;\toverflow: hidden;\ttext-overflow: ellipsis;}.odFileListGrid {\twidth: 100%;\twhite-space: nowrap;\tfont-size: 13px; box-sizing: border-box; border-spacing: 0;}.odOddRow {"+(x?"":"\tbackground-color: #eeeeee;")+"}.odEvenRow {"+(x?"":"\tbackground-color: #FFFFFF;")+"}.odRowSelected {\tbackground-color: #cadfff;}.odCatListTitle {\tbox-sizing: border-box;\theight: 17px;\tcursor: default;\tcolor: #666666;\tfont-size: 14px;\tline-height: 17px;\tmargin: 5px 0 5px 0px; padding-left: 10px;}.odCatSelected {\tfont-weight: bold;\tbackground-color: #cadfff;}.odEmptyFolder {\theight: 17px;\tcolor: #6D6D6D;\tfont-size: 14px;\tfont-weight: bold;\tline-height: 17px;\tmargin: 10px 0 3px 5px;\twidth: 100%; text-align: center;}.odBCFolder {\tcursor: pointer;\tcolor: #0432ff;}.odPreviewStatus {\tposition:absolute;\ttext-align:center;\twidth:100%;\ttop:50%;\ttransform: translateY(-50%);\tfont-size:13px;\topacity:0.5;}.odPreview { position:absolute;\t overflow:hidden;\t border: 1px solid #CCCCCC; bottom:0px; top: 50%; left:0px; right:0px;}.odLinkBtn { position: absolute;\tfont-size: 12px;\tcursor: pointer;\tcolor: #6D6D6D;\tleft: 5px;\tbottom: 3px;}.odSubmitBtn { position: absolute;\tcolor: #333;\tright: 5px;\tbottom: 5px;}",g=new Spinner({left:"50%",lines:12,length:8,width:3,radius:5,rotate:0,color:"#000",speed:1,trail:60,shadow:!1,hwaccel:!1,className:"spinner",zIndex:2e9}),b=new Editor,w=null,E=null,C=null,y=!1,R=[],L=null,k=null;function S(e,t,i){if(null==e["@microsoft.graph.downloadUrl"]){if(null!=e.parentReference)return void o(e.id,e.parentReference.driveId,(function(e){S(e,t,i)}),i);i()}var n=new XMLHttpRequest;n.open("GET",e["@microsoft.graph.downloadUrl"]);var l=!!e.file&&"image/png"==e.file.mimeType;n.onreadystatechange=function(){if(4==this.readyState){if(this.status>=200&&this.status<=299)try{var e=n.responseText;l&&(e="data:image/png;base64,"+Editor.base64Encode(e),e=Editor.extractGraphModelFromPng(e));var o=mxUtils.parseXml(e),r="mxlibrary"==o.documentElement.nodeName?o.documentElement:Editor.extractGraphModel(o.documentElement);if(null!=r)return void t(r.ownerDocument)}catch(e){}i()}},l&&n.overrideMimeType&&n.overrideMimeType("text/plain; charset=x-user-defined"),n.send()}function T(){function e(e){r(E,e),l(E)}m&&null!=w?b.exportToCanvas((function(t){e(EditorUi.prototype.createImageDataUri(t,null,"png"))}),400,null,null,(function(e){console.log(e)}),600,null,null,null,null,null,w):e()}function I(){var e=h(".odFilesBreadcrumb");if(null!=e){e.innerHTML="";for(var i=0;i<R.length-1;i++){var o=document.createElement("span");o.className="odBCFolder",o.innerHTML=mxUtils.htmlEntities(R[i].name||mxResources.get("home")),e.appendChild(o),function(e,i){o.addEventListener("click",(function(){t(null),R=R.slice(0,i),D(e.driveId,e.folderId,e.siteId,e.name)}))}(R[i],i);var n=document.createElement("span");n.innerHTML=" > ",e.appendChild(n)}if(null!=R[R.length-1]){var l=document.createElement("span");l.innerHTML=mxUtils.htmlEntities(1==R.length?mxResources.get("officeSelDiag"):R[R.length-1].name||mxResources.get("home")),e.appendChild(l)}}}function F(){if(null!=E&&!y)if("sharepoint"==C)D("site",null,E.id,E.displayName);else if("site"==C)D("subsite",null,E.id,E.name);else{var e=E.folder,t=((E=E.remoteItem?E.remoteItem:E).parentReference?E.parentReference.driveId:null)||C,i=E.id;e?D(t,i,null,E.name):T()}}function D(e,o,l,r,a){if(!y){h(".odCatsList").style.display="block",h(".odFilesSec").style.display="block",null!=M&&(M.innerHTML="",M.style.top="50%"),y=!0;var c=!0,m=0;L=arguments;var u,p=setTimeout((function(){c=!1,y=!1,g.stop(),d(mxResources.get("timeout"))}),2e4),f=h(".odFilesList");switch(f.innerHTML="",g.spin(f),e){case"recent":R=[{name:mxResources.get("recent",null,"Recent"),driveId:e}];var x=n()||{},v=[];for(var b in x)v.push(x[b]);return clearTimeout(p),void w(v);case"shared":u="/me/drive/sharedWithMe",R=[{name:mxResources.get("sharedWithMe",null,"Shared With Me"),driveId:e}];break;case"sharepoint":u="/sites?search=",R=[{name:mxResources.get("sharepointSites",null,"Sharepoint Sites"),driveId:e}],m=1;break;case"site":R.push({name:r,driveId:e,folderId:o,siteId:l}),u="/sites/"+l+"/drives",m=2;break;case"subsite":R.push({name:r,driveId:e,folderId:o,siteId:l}),u="/drives/"+l+(o?"/items/"+o:"/root")+"/children";break;case"search":R=[{driveId:e=C,name:mxResources.get("back",null,"Back")}],a=encodeURIComponent(a.replace(/\'/g,"\\'")),u=e?"/drives/"+e+"/root/search(q='"+a+"')":"/me/drive/root/search(q='"+a+"')";break;default:null==o?R=[{driveId:e}]:R.push({name:r,driveId:e,folderId:o}),u=(e?"/drives/"+e:"/me/drive")+(o?"/items/"+o:"/root")+"/children"}m||(u+=(u.indexOf("?")>0?"&":"?")+"select=id,name,description,parentReference,file,createdBy,lastModifiedBy,lastModifiedDateTime,size,folder,remoteItem,@microsoft.graph.downloadUrl"),i(u,(function(e){if(c){clearTimeout(p);for(var t=e.value||[],i=m?t:[],o=0;!m&&o<t.length;o++){var n=t[o],l=n.file?n.file.mimeType:null;(n.folder||"text/html"==l||"text/xml"==l||"application/xml"==l||"image/png"==l||/\.svg$/.test(n.name)||/\.html$/.test(n.name)||/\.xml$/.test(n.name)||/\.png$/.test(n.name)||/\.drawio$/.test(n.name)||/\.drawiolib$/.test(n.name))&&i.push(n)}w(i)}}),(function(e){if(c){clearTimeout(p);var t=null;try{t=JSON.parse(e.responseText).error.message}catch(e){}d(mxResources.get("errorFetchingFolder",null,"Error fetching folder items")+(null!=t?" ("+t+")":"")),y=!1,g.stop()}}))}function w(i){g.stop();var o=document.createElement("table");o.className="odFileListGrid";for(var n=null,l=0,r=0;null!=i&&r<i.length;r++){var d=i[r];if(1!=m||!d.webUrl||d.webUrl.indexOf("sharepoint.com/sites/")>0||d.webUrl.indexOf("sharepoint.com/")<0){var a=d.displayName||d.name,c=mxUtils.htmlEntities(d.description||a);m&&(d.folder=!0);var u=null!=d.folder;if(!s||u){var p=document.createElement("tr");p.className=l++%2?"odOddRow":"odEvenRow";var h=document.createElement("td");h.style.width="36px";var x=document.createElement("img");x.src="/images/"+(u?"folder.png":"file.png"),x.className="odFileImg",h.appendChild(x),p.appendChild(h),h=document.createElement("td");var v=document.createElement("div");v.className="odFileTitle",v.innerHTML=mxUtils.htmlEntities(a),v.setAttribute("title",c),h.appendChild(v),p.appendChild(h),o.appendChild(p),null==n&&((n=p).className+=" odRowSelected",C=e,t(E=d)),function(i,o){p.addEventListener("dblclick",F),p.addEventListener("click",(function(){n!=o&&(n.className=n.className.replace("odRowSelected",""),(n=o).className+=" odRowSelected",C=e,t(E=i))}))}(d,p)}}}if(0==l){var b=document.createElement("div");b.className="odEmptyFolder",b.innerHTML=mxUtils.htmlEntities(mxResources.get("folderEmpty",null,"Folder is empty!")),f.appendChild(b)}else f.appendChild(o);I(),y=!1}}if(this.getSelectedItem=function(){return null!=E&&l(E),E},null==h("#mxODPickerCss")){var B=document.head||document.getElementsByTagName("head")[0],N=document.createElement("style");B.appendChild(N),N.type="text/css",N.id="mxODPickerCss",N.appendChild(document.createTextNode(v))}e.innerHTML=f;var U,M=h(".odPreview"),z=h("#odFiles"),O=(".odCatListTitle",(U=U||document).querySelectorAll(".odCatListTitle"));function P(e){z.className=z.className.replace("odCatSelected",""),(z=e).className+=" odCatSelected"}for(var H=0;H<O.length;H++)O[H].addEventListener("click",(function(){if(k=null,E=null,!y)switch(P(this),this.id){case"odFiles":D();break;case"odRecent":D("recent");break;case"odShared":D("shared");break;case"odSharepoint":D("sharepoint")}}));var $=null;function q(e){y||($=null,D("search",null,null,null,e))}if(h("#odSearchBox").addEventListener("keyup",(function(e){var t=this;null!=$&&clearTimeout($),13==e.keyCode?q(t.value):$=setTimeout((function(){q(t.value)}),500)})),h("#refreshOD").addEventListener("click",(function(){null!=L&&(t(null),D.apply(this,L))})),a&&h("#odBackBtn").addEventListener("click",a),c&&h("#odSubmitBtn").addEventListener("click",T),null!=u){var A=u.pop();"sharepoint"==u[0].driveId&&P(h("#odSharepoint")),R=u,D(A.driveId,A.folderId,A.siteId,A.name)}else D()}