@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 29.5 kB
JavaScript
function DiagramPage(e,t){this.node=e,null!=t?this.node.setAttribute("id",t):null==this.getId()&&this.node.setAttribute("id",Editor.guid())}function RenamePage(e,t,i){this.ui=e,this.page=t,this.name=i,this.previous=i}function MovePage(e,t,i){this.ui=e,this.oldIndex=t,this.newIndex=i}function SelectPage(e,t,i){this.ui=e,this.page=t,this.previousPage=t,this.neverShown=!0,null!=t&&(this.neverShown=null==t.viewState,this.ui.updatePageRoot(t),null!=i&&(t.viewState=i,this.neverShown=!1))}function ChangePage(e,t,i,a,n){SelectPage.call(this,e,i),this.relatedPage=t,this.index=a,this.previousIndex=null,this.noSelect=n}DiagramPage.prototype.node=null,DiagramPage.prototype.root=null,DiagramPage.prototype.viewState=null,DiagramPage.prototype.getId=function(){return this.node.getAttribute("id")},DiagramPage.prototype.getName=function(){return this.node.getAttribute("name")},DiagramPage.prototype.setName=function(e){null==e?this.node.removeAttribute("name"):this.node.setAttribute("name",e)},RenamePage.prototype.execute=function(){var e=this.page.getName();this.page.setName(this.previous),this.name=this.previous,this.previous=e,this.ui.editor.graph.updatePlaceholders(),this.ui.editor.fireEvent(new mxEventObject("pageRenamed"))},MovePage.prototype.execute=function(){this.ui.pages.splice(this.newIndex,0,this.ui.pages.splice(this.oldIndex,1)[0]);var e=this.oldIndex;this.oldIndex=this.newIndex,this.newIndex=e,this.ui.editor.graph.updatePlaceholders(),this.ui.editor.fireEvent(new mxEventObject("pageMoved"))},SelectPage.prototype.execute=function(){var e=mxUtils.indexOf(this.ui.pages,this.previousPage);if(null!=this.page&&e>=0){var t=this.ui.currentPage,i=this.ui.editor,a=i.graph,n=Graph.compressNode(i.getGraphXml(!0));mxUtils.setTextContent(t.node,n),t.viewState=a.getViewState(),t.root=a.model.root,null!=t.model&&t.model.rootChanged(t.root),a.view.clear(t.root,!0),a.clearSelection(),this.ui.currentPage=this.previousPage,this.previousPage=t,t=this.ui.currentPage,a.model.prefix=Editor.guid()+"-",a.model.rootChanged(t.root),a.setViewState(t.viewState),a.gridEnabled=a.gridEnabled&&(!this.ui.editor.isChromelessView()||"1"==urlParams.grid),i.updateGraphComponents(),a.view.validate(),a.blockMathRender=!0,a.sizeDidChange(),a.blockMathRender=!1,this.neverShown&&(this.neverShown=!1,a.selectUnlockedLayer()),i.graph.fireEvent(new mxEventObject(mxEvent.ROOT)),i.fireEvent(new mxEventObject("pageSelected","change",this))}},mxUtils.extend(ChangePage,SelectPage),ChangePage.prototype.execute=function(){if(this.ui.editor.fireEvent(new mxEventObject("beforePageChange","change",this)),this.previousIndex=this.index,null==this.index){var e=mxUtils.indexOf(this.ui.pages,this.relatedPage);this.ui.pages.splice(e,1),this.index=e}else this.ui.pages.splice(this.index,0,this.relatedPage),this.index=null;this.noSelect||SelectPage.prototype.execute.apply(this,arguments)},EditorUi.prototype.tabContainerHeight=38,EditorUi.prototype.getSelectedPageIndex=function(){return this.getPageIndex(this.currentPage)},EditorUi.prototype.getPageIndex=function(e){var t=null;if(null!=this.pages&&null!=e)for(var i=0;i<this.pages.length;i++)if(this.pages[i]==e){t=i;break}return t},EditorUi.prototype.getPageById=function(e){if(null!=this.pages)for(var t=0;t<this.pages.length;t++)if(this.pages[t].getId()==e)return this.pages[t];return null},EditorUi.prototype.createImageForPageLink=function(e,t,i){var a=e.indexOf(","),n=null;if(a>0){var r=this.getPageById(e.substring(a+1));null!=r&&r!=t&&((n=this.getImageForPage(r,t,i)).originalSrc=e)}return null==n&&(n={originalSrc:e}),n},EditorUi.prototype.getImageForPage=function(e,t,i){var a=(i=null!=i?i:this.editor.graph).getGlobalVariable,n=this.createTemporaryGraph(i.getStylesheet());n.defaultPageBackgroundColor=i.defaultPageBackgroundColor,n.shapeBackgroundColor=i.shapeBackgroundColor,n.shapeForegroundColor=i.shapeForegroundColor;var r=this.getPageIndex(null!=t?t:this.currentPage);n.getGlobalVariable=function(e){return"pagenumber"==e?r+1:"page"==e&&null!=t?t.getName():a.apply(this,arguments)},this.ui.container.appendChild(n.container)||document.body.appendChild(n.container),this.updatePageRoot(e),n.model.setRoot(e.root);var s=n.getSvg(null,null,null,null,null,null,null,null,null,null,null,!0),o=n.getGraphBounds();return document.body.removeChild(n.container),new mxImage(Editor.createSvgDataUri(mxUtils.getXml(s)),o.width,o.height,o.x,o.y)},EditorUi.prototype.initPages=function(){if(!this.editor.graph.standalone){this.actions.addAction("previousPage",mxUtils.bind(this,(function(){this.selectNextPage(!1)}))),this.actions.addAction("nextPage",mxUtils.bind(this,(function(){this.selectNextPage(!0)}))),this.isPagesEnabled()&&(this.keyHandler.bindAction(33,!0,"previousPage",!0),this.keyHandler.bindAction(34,!0,"nextPage",!0));var e=this.editor.graph,t=e.view.validateBackground;e.view.validateBackground=mxUtils.bind(this,(function(){if(null!=this.tabContainer){var i=this.tabContainer.style.height;null==this.fileNode||null==this.pages||1==this.pages.length&&"0"==urlParams.pages?this.tabContainer.style.height="0px":this.tabContainer.style.height=this.tabContainerHeight+"px",i!=this.tabContainer.style.height&&this.refresh(!1)}t.apply(e.view,arguments)}));var i=null,a=mxUtils.bind(this,(function(){this.updateTabContainer();var t=this.currentPage;null!=t&&t!=i&&(null==t.viewState||null==t.viewState.scrollLeft?(this.resetScrollbars(),e.isLightboxView()&&this.lightboxFit(),null!=this.chromelessResize&&(e.container.scrollLeft=0,e.container.scrollTop=0,this.chromelessResize())):(e.container.scrollLeft=e.view.translate.x*e.view.scale+t.viewState.scrollLeft,e.container.scrollTop=e.view.translate.y*e.view.scale+t.viewState.scrollTop),i=t),null!=this.actions.layersWindow&&this.actions.layersWindow.refreshLayers(),"undefined"!=typeof MathJax&&void 0!==MathJax.Hub?1!=MathJax.Hub.queue.pending||null==this.editor||this.editor.graph.mathEnabled||MathJax.Hub.Queue(mxUtils.bind(this,(function(){null!=this.editor&&this.editor.graph.refresh()}))):void 0===Editor.MathJaxClear||null!=this.editor&&this.editor.graph.mathEnabled||Editor.MathJaxClear()}));this.editor.graph.model.addListener(mxEvent.CHANGE,mxUtils.bind(this,(function(e,t){for(var i=t.getProperty("edit").changes,n=0;n<i.length;n++)if(i[n]instanceof SelectPage||i[n]instanceof RenamePage||i[n]instanceof MovePage||i[n]instanceof mxRootChange){a();break}}))),null!=this.toolbar&&this.editor.addListener("pageSelected",this.toolbar.updateZoom)}},EditorUi.prototype.restoreViewState=function(e,t,i){var a=null!=e?this.getPageById(e.getId()):null,n=this.editor.graph;null!=a&&null!=this.currentPage&&null!=this.pages&&(a!=this.currentPage?this.selectPage(a,!0,t):(n.setViewState(t),this.editor.updateGraphComponents(),n.view.revalidate(),n.sizeDidChange()),n.container.scrollLeft=n.view.translate.x*n.view.scale+t.scrollLeft,n.container.scrollTop=n.view.translate.y*n.view.scale+t.scrollTop,n.restoreSelection(i))},Graph.prototype.createViewState=function(e){var t=e.getAttribute("page"),i=parseFloat(e.getAttribute("pageScale")),a=parseFloat(e.getAttribute("pageWidth")),n=parseFloat(e.getAttribute("pageHeight")),r=e.getAttribute("background"),s=this.parseBackgroundImage(e.getAttribute("backgroundImage")),o=e.getAttribute("extFonts");if(o)try{o=o.split("|").map((function(e){var t=e.split("^");return{name:t[0],url:t[1]}}))}catch(e){console.log("ExtFonts format error: "+e.message)}return{gridEnabled:"0"!=e.getAttribute("grid"),gridSize:parseFloat(e.getAttribute("gridSize"))||mxGraph.prototype.gridSize,guidesEnabled:"0"!=e.getAttribute("guides"),foldingEnabled:"0"!=e.getAttribute("fold"),shadowVisible:"1"==e.getAttribute("shadow"),pageVisible:!this.isLightboxView()&&(null!=t?"0"!=t:this.defaultPageVisible),background:null!=r&&r.length>0?r:null,backgroundImage:s,pageScale:isNaN(i)?mxGraph.prototype.pageScale:i,pageFormat:isNaN(a)||isNaN(n)?"undefined"==typeof mxSettings||null!=this.defaultPageFormat?mxGraph.prototype.pageFormat:mxSettings.getPageFormat():new mxRectangle(0,0,a,n),tooltips:"0"!=e.getAttribute("tooltips"),connect:"0"!=e.getAttribute("connect"),arrows:"0"!=e.getAttribute("arrows"),mathEnabled:"1"==e.getAttribute("math"),selectionCells:null,defaultParent:null,scrollbars:this.defaultScrollbars,scale:1,hiddenTags:[],extFonts:o||[]}},Graph.prototype.saveViewState=function(e,t,i,a){i||(t.setAttribute("grid",null==e||e.gridEnabled?"1":"0"),t.setAttribute("gridSize",null!=e?e.gridSize:mxGraph.prototype.gridSize),t.setAttribute("guides",null==e||e.guidesEnabled?"1":"0"),t.setAttribute("tooltips",null==e||e.tooltips?"1":"0"),t.setAttribute("connect",null==e||e.connect?"1":"0"),t.setAttribute("arrows",null==e||e.arrows?"1":"0"),t.setAttribute("page",null==e&&this.defaultPageVisible||null!=e&&e.pageVisible?"1":"0"),t.setAttribute("fold",null==e||e.foldingEnabled?"1":"0")),t.setAttribute("pageScale",null!=e&&null!=e.pageScale?e.pageScale:mxGraph.prototype.pageScale);var n=null!=e?e.pageFormat:"undefined"==typeof mxSettings||null!=this.defaultPageFormat?mxGraph.prototype.pageFormat:mxSettings.getPageFormat();if(null!=n&&(t.setAttribute("pageWidth",n.width),t.setAttribute("pageHeight",n.height)),null!=e){null!=e.background&&t.setAttribute("background",e.background);var r=this.getBackgroundImageObject(e.backgroundImage,a);null!=r&&t.setAttribute("backgroundImage",JSON.stringify(r))}t.setAttribute("math",null!=e&&e.mathEnabled?"1":"0"),t.setAttribute("shadow",null!=e&&e.shadowVisible?"1":"0"),null!=e&&null!=e.extFonts&&e.extFonts.length>0&&t.setAttribute("extFonts",e.extFonts.map((function(e){return e.name+"^"+e.url})).join("|"))},Graph.prototype.getViewState=function(){return{defaultParent:this.defaultParent,currentRoot:this.view.currentRoot,gridEnabled:this.gridEnabled,gridSize:this.gridSize,guidesEnabled:this.graphHandler.guidesEnabled,foldingEnabled:this.foldingEnabled,shadowVisible:this.shadowVisible,scrollbars:this.scrollbars,pageVisible:this.pageVisible,background:this.background,backgroundImage:this.backgroundImage,pageScale:this.pageScale,pageFormat:this.pageFormat,tooltips:this.tooltipHandler.isEnabled(),connect:this.connectionHandler.isEnabled(),arrows:this.connectionArrowsEnabled,scale:this.view.scale,scrollLeft:this.container.scrollLeft-this.view.translate.x*this.view.scale,scrollTop:this.container.scrollTop-this.view.translate.y*this.view.scale,translate:this.view.translate.clone(),lastPasteXml:this.lastPasteXml,pasteCounter:this.pasteCounter,mathEnabled:this.mathEnabled,hiddenTags:this.hiddenTags,extFonts:this.extFonts}},Graph.prototype.setViewState=function(e,t){if(null!=e){this.lastPasteXml=e.lastPasteXml,this.pasteCounter=e.pasteCounter||0,this.mathEnabled=e.mathEnabled,this.gridEnabled=e.gridEnabled,this.gridSize=e.gridSize,this.graphHandler.guidesEnabled=e.guidesEnabled,this.foldingEnabled=e.foldingEnabled,this.setShadowVisible(e.shadowVisible,!1),this.scrollbars=e.scrollbars,this.pageVisible=!this.isViewer()&&e.pageVisible,this.background=e.background,this.pageScale=e.pageScale,this.pageFormat=e.pageFormat,this.view.currentRoot=e.currentRoot,this.defaultParent=e.defaultParent,this.connectionArrowsEnabled=e.arrows,this.setTooltips(e.tooltips),this.setConnectable(e.connect),this.setBackgroundImage(e.backgroundImage),this.hiddenTags=e.hiddenTags;var i=this.extFonts;if(this.extFonts=e.extFonts||[],t&&null!=i)for(var a=0;a<i.length;a++){var n=document.getElementById("extFont_"+i[a].name);null!=n&&n.parentNode.removeChild(n)}for(a=0;a<this.extFonts.length;a++)this.addExtFont(this.extFonts[a].name,this.extFonts[a].url,!0);null!=e.scale?this.view.scale=e.scale:this.view.scale=1,null==this.view.currentRoot||this.model.contains(this.view.currentRoot)||(this.view.currentRoot=null),null==this.defaultParent||this.model.contains(this.defaultParent)||(this.setDefaultParent(null),this.selectUnlockedLayer()),null!=e.translate&&(this.view.translate=e.translate)}else this.view.currentRoot=null,this.view.scale=1,this.gridEnabled=this.defaultGridEnabled,this.gridSize=mxGraph.prototype.gridSize,this.pageScale=mxGraph.prototype.pageScale,this.pageFormat="undefined"==typeof mxSettings||null!=this.defaultPageFormat?mxGraph.prototype.pageFormat:mxSettings.getPageFormat(),this.pageVisible=this.defaultPageVisible,this.background=null,this.backgroundImage=null,this.scrollbars=this.defaultScrollbars,this.graphHandler.guidesEnabled=!0,this.foldingEnabled=!0,this.setShadowVisible(!1,!1),this.defaultParent=null,this.setTooltips(!0),this.setConnectable(!0),this.lastPasteXml=null,this.pasteCounter=0,this.mathEnabled=this.defaultMathEnabled,this.connectionArrowsEnabled=!0,this.hiddenTags=[],this.extFonts=[];this.pageBreaksVisible=this.pageVisible,this.preferPageSize=this.pageVisible,this.fireEvent(new mxEventObject("viewStateChanged","state",e))},Graph.prototype.addExtFont=function(e,t,i){if(e&&t){"1"!=urlParams["ext-fonts"]&&(Graph.recentCustomFonts[e.toLowerCase()]={name:e,url:t});var a="extFont_"+e;if(null==document.getElementById(a))if(0==t.indexOf(Editor.GOOGLE_FONTS))mxClient.link("stylesheet",t,null,a);else{document.getElementsByTagName("head")[0];var n=document.createElement("style");n.appendChild(document.createTextNode('@font-face {\n\tfont-family: "'+e+'";\n\tsrc: url("'+t+'");\n}')),n.setAttribute("id",a),document.getElementsByTagName("head")[0].appendChild(n)}if(!i){null==this.extFonts&&(this.extFonts=[]);for(var r=this.extFonts,s=!0,o=0;o<r.length;o++)if(r[o].name==e){s=!1;break}s&&this.extFonts.push({name:e,url:t})}}},EditorUi.prototype.updatePageRoot=function(e,t){if(null==e.root){var i=this.editor.extractGraphModel(e.node,null,t);if(n=Editor.extractParserError(i))throw new Error(n);if(null!=i){e.graphModelNode=i,e.viewState=this.editor.graph.createViewState(i);var a=new mxCodec(i.ownerDocument);e.root=a.decode(i).root}else e.root=this.editor.graph.model.createRoot()}else if(null==e.viewState){if(null==e.graphModelNode){var n;if(i=this.editor.extractGraphModel(e.node),n=Editor.extractParserError(i))throw new Error(n);null!=i&&(e.graphModelNode=i)}null!=e.graphModelNode&&(e.viewState=this.editor.graph.createViewState(e.graphModelNode))}return e},EditorUi.prototype.selectPage=function(e,t,i){try{if(e!=this.currentPage){this.editor.graph.isEditing()&&this.editor.graph.stopEditing(!1),t=null!=t&&t,this.editor.graph.isMouseDown=!1,this.editor.graph.reset();var a=this.editor.graph.model.createUndoableEdit();a.ignoreEdit=!0;var n=new SelectPage(this,e,i);n.execute(),a.add(n),a.notify(),this.editor.graph.tooltipHandler.hide(),t||this.editor.graph.model.fireEvent(new mxEventObject(mxEvent.UNDO,"edit",a))}}catch(e){this.handleError(e)}},EditorUi.prototype.selectNextPage=function(e){var t=this.currentPage;if(null!=t&&null!=this.pages){var i=mxUtils.indexOf(this.pages,t);e?this.selectPage(this.pages[mxUtils.mod(i+1,this.pages.length)]):e||this.selectPage(this.pages[mxUtils.mod(i-1,this.pages.length)])}},EditorUi.prototype.insertPage=function(e,t){if(this.editor.graph.isEnabled()){this.editor.graph.isEditing()&&this.editor.graph.stopEditing(!1);var i=new ChangePage(this,e=null!=e?e:this.createPage(null,this.createPageId()),e,t=null!=t?t:this.pages.length);this.editor.graph.model.execute(i)}return e},EditorUi.prototype.createPageId=function(){var e=null;do{e=Editor.guid()}while(null!=this.getPageById(e));return e},EditorUi.prototype.createPage=function(e,t){var i=new DiagramPage(this.fileNode.ownerDocument.createElement("diagram"),t);return i.setName(null!=e?e:this.createPageName()),i},EditorUi.prototype.createPageName=function(){for(var e={},t=0;t<this.pages.length;t++){var i=this.pages[t].getName();null!=i&&i.length>0&&(e[i]=i)}var a=this.pages.length,n=null;do{n=mxResources.get("pageWithNumber",[++a])}while(null!=e[n]);return n},EditorUi.prototype.removePage=function(e){try{var t=this.editor.graph,i=mxUtils.indexOf(this.pages,e);if(t.isEnabled()&&i>=0){this.editor.graph.isEditing()&&this.editor.graph.stopEditing(!1),t.model.beginUpdate();try{var a=this.currentPage;a==e&&this.pages.length>1?(i==this.pages.length-1?i--:i++,a=this.pages[i]):this.pages.length<=1&&(a=this.insertPage(),t.model.execute(new RenamePage(this,a,mxResources.get("pageWithNumber",[1])))),t.model.execute(new ChangePage(this,e,a))}finally{t.model.endUpdate()}}}catch(e){this.handleError(e)}return e},EditorUi.prototype.duplicatePage=function(e,t){var i=null;try{var a=this.editor.graph;if(a.isEnabled()){a.isEditing()&&a.stopEditing();var n=e.node.cloneNode(!1);n.removeAttribute("id");var r=new Object,s=a.createCellLookup([a.model.root]);(i=new DiagramPage(n)).root=a.cloneCell(a.model.root,null,r),i.viewState=a.getViewState(),i.viewState.scale=1,i.viewState.scrollLeft=null,i.viewState.scrollTop=null,i.viewState.currentRoot=null,i.viewState.defaultParent=null,i.setName(t),i=this.insertPage(i,mxUtils.indexOf(this.pages,e)+1),a.updateCustomLinks(a.createCellMapping(r,s),[i.root])}}catch(e){this.handleError(e)}return i},EditorUi.prototype.renamePage=function(e){if(this.editor.graph.isEnabled()){var t=new FilenameDialog(this,e.getName(),mxResources.get("rename"),mxUtils.bind(this,(function(t){null!=t&&t.length>0&&this.editor.graph.model.execute(new RenamePage(this,e,t))})),mxResources.get("rename"));this.showDialog(t.container,300,80,!0,!0),t.init()}return e},EditorUi.prototype.movePage=function(e,t){this.editor.graph.model.execute(new MovePage(this,e,t))},EditorUi.prototype.createTabContainer=function(){var e=document.createElement("div");return e.className="geTabContainer",e.style.position="absolute",e.style.whiteSpace="nowrap",e.style.overflow="hidden",e.style.height="0px",e},EditorUi.prototype.updateTabContainer=function(){if(null!=this.tabContainer&&null!=this.pages){var e=this.editor.graph,t=document.createElement("div");t.style.position="relative",t.style.display="inline-block",t.style.verticalAlign="top",t.style.height=this.tabContainer.style.height,t.style.whiteSpace="nowrap",t.style.overflow="hidden",t.style.fontSize="13px",t.style.marginLeft="30px";for(var i=this.editor.isChromelessView()?29:59,a=Math.min(140,Math.max(20,(this.tabContainer.clientWidth-i)/this.pages.length)+1),n=null,r=0;r<this.pages.length;r++)mxUtils.bind(this,(function(i,a){this.pages[i]==this.currentPage?(a.className="geActivePage",a.style.backgroundColor=Editor.isDarkMode()?Editor.darkColor:"#fff"):a.className="geInactivePage",a.setAttribute("draggable","true"),mxEvent.addListener(a,"dragstart",mxUtils.bind(this,(function(t){e.isEnabled()?(mxClient.IS_FF&&t.dataTransfer.setData("Text","<diagram/>"),n=i):mxEvent.consume(t)}))),mxEvent.addListener(a,"dragend",mxUtils.bind(this,(function(e){n=null,e.stopPropagation(),e.preventDefault()}))),mxEvent.addListener(a,"dragover",mxUtils.bind(this,(function(e){null!=n&&(e.dataTransfer.dropEffect="move"),e.stopPropagation(),e.preventDefault()}))),mxEvent.addListener(a,"drop",mxUtils.bind(this,(function(e){null!=n&&i!=n&&this.movePage(n,i),e.stopPropagation(),e.preventDefault()}))),t.appendChild(a)}))(r,this.createTabForPage(this.pages[r],a,this.pages[r]!=this.currentPage,r+1));this.tabContainer.innerHTML="",this.tabContainer.appendChild(t);var s=this.createPageMenuTab();this.tabContainer.appendChild(s);var o=null;if(this.isPageInsertTabVisible()&&(o=this.createPageInsertTab(),this.tabContainer.appendChild(o)),t.clientWidth>this.tabContainer.clientWidth-i){null!=o&&(o.style.position="absolute",o.style.right="0px",t.style.marginRight="30px");var l=this.createControlTab(4," ❮ ");l.style.position="absolute",l.style.right=this.editor.chromeless?"29px":"55px",l.style.fontSize="13pt",this.tabContainer.appendChild(l);var d=this.createControlTab(4," ❯");d.style.position="absolute",d.style.right=this.editor.chromeless?"0px":"29px",d.style.fontSize="13pt",this.tabContainer.appendChild(d);var h=Math.max(0,this.tabContainer.clientWidth-(this.editor.chromeless?86:116));t.style.width=h+"px";var u=50;mxEvent.addListener(l,"click",mxUtils.bind(this,(function(e){t.scrollLeft-=Math.max(20,h-20),mxUtils.setOpacity(l,t.scrollLeft>0?100:u),mxUtils.setOpacity(d,t.scrollLeft<t.scrollWidth-t.clientWidth?100:u),mxEvent.consume(e)}))),mxUtils.setOpacity(l,t.scrollLeft>0?100:u),mxUtils.setOpacity(d,t.scrollLeft<t.scrollWidth-t.clientWidth?100:u),mxEvent.addListener(d,"click",mxUtils.bind(this,(function(e){t.scrollLeft+=Math.max(20,h-20),mxUtils.setOpacity(l,t.scrollLeft>0?100:u),mxUtils.setOpacity(d,t.scrollLeft<t.scrollWidth-t.clientWidth?100:u),mxEvent.consume(e)})))}}},EditorUi.prototype.isPageInsertTabVisible=function(){return 1==urlParams.embed||null!=this.getCurrentFile()&&this.getCurrentFile().isEditable()},EditorUi.prototype.createTab=function(e){var t=document.createElement("div");return t.style.display="inline-block",t.style.whiteSpace="nowrap",t.style.boxSizing="border-box",t.style.position="relative",t.style.overflow="hidden",t.style.textAlign="center",t.style.marginLeft="-1px",t.style.height=this.tabContainer.clientHeight+"px",t.style.padding="12px 4px 8px 4px",t.style.border=Editor.isDarkMode()?"1px solid #505759":"1px solid #e8eaed",t.style.borderTopStyle="none",t.style.borderBottomStyle="none",t.style.backgroundColor=this.tabContainer.style.backgroundColor,t.style.cursor="move",t.style.color="gray",e&&(mxEvent.addListener(t,"mouseenter",mxUtils.bind(this,(function(e){this.editor.graph.isMouseDown||(t.style.backgroundColor=Editor.isDarkMode()?"black":"#e8eaed",mxEvent.consume(e))}))),mxEvent.addListener(t,"mouseleave",mxUtils.bind(this,(function(e){t.style.backgroundColor=this.tabContainer.style.backgroundColor,mxEvent.consume(e)})))),t},EditorUi.prototype.createControlTab=function(e,t,i){var a=this.createTab(null==i||i);return a.style.lineHeight=this.tabContainerHeight+"px",a.style.paddingTop=e+"px",a.style.cursor="pointer",a.style.width="30px",a.innerHTML=t,null!=a.firstChild&&null!=a.firstChild.style&&mxUtils.setOpacity(a.firstChild,40),a},EditorUi.prototype.createPageMenuTab=function(e){var t=this.createControlTab(3,'<div class="geSprite geSprite-dots"></div>',e);t.setAttribute("title",mxResources.get("pages")),t.style.position="absolute",t.style.marginLeft="0px",t.style.top="0px",t.style.left="1px";var i=t.getElementsByTagName("div")[0];return i.style.display="inline-block",i.style.marginTop="5px",i.style.width="21px",i.style.height="21px",mxEvent.addListener(t,"click",mxUtils.bind(this,(function(e){this.editor.graph.popupMenuHandler.hideMenu();var t=new mxPopupMenu(mxUtils.bind(this,(function(e,t){for(var i=0;i<this.pages.length;i++)mxUtils.bind(this,(function(i){var a=e.addItem(this.pages[i].getName(),null,mxUtils.bind(this,(function(){this.selectPage(this.pages[i])})),t),n=this.pages[i].getId();a.setAttribute("title",this.pages[i].getName()+(null!=n?" ("+n+")":"")+" ["+(i+1)+"]"),this.pages[i]==this.currentPage&&e.addCheckmark(a,Editor.checkmarkImage)}))(i);if(this.editor.graph.isEnabled()){e.addSeparator(t),e.addItem(mxResources.get("insertPage"),null,mxUtils.bind(this,(function(){this.insertPage()})),t);var a=this.currentPage;if(null!=a){e.addSeparator(t);var n=a.getName();e.addItem(mxResources.get("removeIt",[n]),null,mxUtils.bind(this,(function(){this.removePage(a)})),t),e.addItem(mxResources.get("renameIt",[n]),null,mxUtils.bind(this,(function(){this.renamePage(a,a.getName())})),t),e.addSeparator(t),e.addItem(mxResources.get("duplicateIt",[n]),null,mxUtils.bind(this,(function(){this.duplicatePage(a,mxResources.get("copyOf",[a.getName()]))})),t)}}})));t.div.className+=" geMenubarMenu",t.smartSeparators=!0,t.showDisabled=!0,t.autoExpand=!0,t.hideMenu=mxUtils.bind(this,(function(){mxPopupMenu.prototype.hideMenu.apply(t,arguments),t.destroy()}));var i=mxEvent.getClientX(e),a=mxEvent.getClientY(e);t.popup(i,a,null,e),this.setCurrentMenu(t),mxEvent.consume(e)}))),t},EditorUi.prototype.createPageInsertTab=function(){var e=this.createControlTab(4,'<div class="geSprite geSprite-plus"></div>');e.setAttribute("title",mxResources.get("insertPage")),this.editor.graph,mxEvent.addListener(e,"click",mxUtils.bind(this,(function(e){this.insertPage(),mxEvent.consume(e)})));var t=e.getElementsByTagName("div")[0];return t.style.display="inline-block",t.style.width="21px",t.style.height="21px",e},EditorUi.prototype.createTabForPage=function(e,t,i,a){var n=this.createTab(i),r=e.getName()||mxResources.get("untitled"),s=e.getId();return n.setAttribute("title",r+(null!=s?" ("+s+")":"")+" ["+a+"]"),mxUtils.write(n,r),n.style.maxWidth=t+"px",n.style.width=t+"px",this.addTabListeners(e,n),t>42&&(n.style.textOverflow="ellipsis"),n},EditorUi.prototype.addTabListeners=function(e,t){mxEvent.disableContextMenu(t);var i=this.editor.graph;i.model,mxEvent.addListener(t,"dblclick",mxUtils.bind(this,(function(t){this.renamePage(e),mxEvent.consume(t)})));var a=!1,n=!1;mxEvent.addGestureListeners(t,mxUtils.bind(this,(function(t){a=null!=this.currentMenu,n=e==this.currentPage,i.isMouseDown||n||this.selectPage(e)})),null,mxUtils.bind(this,(function(r){if(i.isEnabled()&&!i.isMouseDown&&(mxEvent.isTouchEvent(r)&&n||mxEvent.isPopupTrigger(r))){if(i.popupMenuHandler.hideMenu(),this.hideCurrentMenu(),!mxEvent.isTouchEvent(r)||!a){var s=new mxPopupMenu(this.createPageMenu(e));s.div.className+=" geMenubarMenu",s.smartSeparators=!0,s.showDisabled=!0,s.autoExpand=!0,s.hideMenu=mxUtils.bind(this,(function(){mxPopupMenu.prototype.hideMenu.apply(s,arguments),this.resetCurrentMenu(),s.destroy()}));var o=mxEvent.getClientX(r),l=mxEvent.getClientY(r);s.popup(o,l,null,r),this.setCurrentMenu(s,t)}mxEvent.consume(r)}})))},EditorUi.prototype.getLinkForPage=function(e,t,i){if(!mxClient.IS_CHROMEAPP&&!EditorUi.isElectronApp){var a=this.getCurrentFile();if(null!=a&&a.constructor!=LocalFile&&"draw.io"==this.getServiceName()){var n=this.getSearch(["create","title","mode","url","drive","splash","state","clibs","ui","viewbox","hide-pages"]);return n+=(0==n.length?"?":"&")+"page-id="+e.getId(),null!=t&&(n+="&"+t.join("&")),(i&&"1"!=urlParams.dev?EditorUi.lightboxHost:mxClient.IS_CHROMEAPP||EditorUi.isElectronApp||!/.*\.draw\.io$/.test(window.location.hostname)?EditorUi.drawHost:"https://"+window.location.host)+"/"+n+"#"+a.getHash()}}return null},EditorUi.prototype.createPageMenu=function(e,t){return mxUtils.bind(this,(function(i,a){var n=this.editor.graph;n.model,i.addItem(mxResources.get("insert"),null,mxUtils.bind(this,(function(){this.insertPage(null,mxUtils.indexOf(this.pages,e)+1)})),a),i.addItem(mxResources.get("delete"),null,mxUtils.bind(this,(function(){this.removePage(e)})),a),i.addItem(mxResources.get("rename"),null,mxUtils.bind(this,(function(){this.renamePage(e,t)})),a),null!=this.getLinkForPage(e)&&(i.addSeparator(a),i.addItem(mxResources.get("link"),null,mxUtils.bind(this,(function(){this.showPublishLinkDialog(mxResources.get("url"),!0,null,null,mxUtils.bind(this,(function(t,i,a,r,s,o){var l=this.createUrlParameters(t,i,a,r,s,o);if(a||l.push("hide-pages=1"),!n.isSelectionEmpty()){var d=n.getBoundingBox(n.getSelectionCells()),h=n.view.translate,u=n.view.scale;d.width/=u,d.height/=u,d.x=d.x/u-h.x,d.y=d.y/u-h.y,l.push("viewbox="+encodeURIComponent(JSON.stringify({x:Math.round(d.x),y:Math.round(d.y),width:Math.round(d.width),height:Math.round(d.height),border:100})))}var g=new EmbedDialog(this,this.getLinkForPage(e,l,r));this.showDialog(g.container,450,240,!0,!0),g.init()})))})))),i.addSeparator(a),i.addItem(mxResources.get("duplicate"),null,mxUtils.bind(this,(function(){this.duplicatePage(e,mxResources.get("copyOf",[e.getName()]))})),a)}))},function(){var e=EditorUi.prototype.refresh;EditorUi.prototype.refresh=function(t){e.apply(this,arguments),this.updateTabContainer()}}(),mxCodecRegistry.getCodec(ChangePageSetup).exclude.push("page"),function(){var e=new mxObjectCodec(new MovePage,["ui"]);e.beforeDecode=function(e,t,i){return i.ui=e.ui,t},e.afterDecode=function(e,t,i){var a=i.oldIndex;return i.oldIndex=i.newIndex,i.newIndex=a,i},mxCodecRegistry.register(e)}(),function(){var e=new mxObjectCodec(new RenamePage,["ui","page"]);e.beforeDecode=function(e,t,i){return i.ui=e.ui,t},e.afterDecode=function(e,t,i){var a=i.previous;return i.previous=i.name,i.name=a,i},mxCodecRegistry.register(e)}(),function(){var e=new mxObjectCodec(new ChangePage,["ui","relatedPage","index","neverShown","page","previousPage"]),t=["defaultParent","currentRoot","scrollLeft","scrollTop","scale","translate","lastPasteXml","pasteCounter"];e.afterEncode=function(e,i,a){return a.setAttribute("relatedPage",i.relatedPage.getId()),null==i.index&&(a.setAttribute("name",i.relatedPage.getName()),null!=i.relatedPage.viewState&&a.setAttribute("viewState",JSON.stringify(i.relatedPage.viewState,(function(e,i){return mxUtils.indexOf(t,e)<0?i:void 0}))),null!=i.relatedPage.root&&e.encodeCell(i.relatedPage.root,a)),a},e.beforeDecode=function(e,t,i){if(i.ui=e.ui,i.relatedPage=i.ui.getPageById(t.getAttribute("relatedPage")),null==i.relatedPage){var a=t.ownerDocument.createElement("diagram");a.setAttribute("id",t.getAttribute("relatedPage")),a.setAttribute("name",t.getAttribute("name")),i.relatedPage=new DiagramPage(a);var n=t.getAttribute("viewState");null!=n&&(i.relatedPage.viewState=JSON.parse(n),t.removeAttribute("viewState"));var r=(t=t.cloneNode(!0)).firstChild;if(null!=r){i.relatedPage.root=e.decodeCell(r,!1);var s=r.nextSibling;for(r.parentNode.removeChild(r),r=s;null!=r;){if(s=r.nextSibling,r.nodeType==mxConstants.NODETYPE_ELEMENT){var o=r.getAttribute("id");null==e.lookup(o)&&e.decodeCell(r)}r.parentNode.removeChild(r),r=s}}}return t},e.afterDecode=function(e,t,i){return i.index=i.previousIndex,i},mxCodecRegistry.register(e)}();