UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 11.9 kB
EditorUi.DIFF_INSERT="i",EditorUi.DIFF_REMOVE="r",EditorUi.DIFF_UPDATE="u",EditorUi.prototype.codec=new mxCodec,EditorUi.prototype.viewStateProperties={background:!0,backgroundImage:!0,shadowVisible:!0,foldingEnabled:!0,pageScale:!0,mathEnabled:!0,pageFormat:!0,extFonts:!0},EditorUi.prototype.cellProperties={id:!0,value:!0,xmlValue:!0,vertex:!0,edge:!0,visible:!0,collapsed:!0,connectable:!0,parent:!0,children:!0,previous:!0,source:!0,target:!0,edges:!0,geometry:!0,style:!0,mxObjectId:!0,mxTransient:!0},EditorUi.prototype.patchPages=function(e,t,l,r,i){var n={},o=[],u={},a={},d={},s={};if(null!=r&&null!=r[EditorUi.DIFF_UPDATE])for(var g in r[EditorUi.DIFF_UPDATE])n[g]=r[EditorUi.DIFF_UPDATE][g];if(null!=t[EditorUi.DIFF_REMOVE])for(var p=0;p<t[EditorUi.DIFF_REMOVE].length;p++)a[t[EditorUi.DIFF_REMOVE][p]]=!0;if(null!=t[EditorUi.DIFF_INSERT])for(p=0;p<t[EditorUi.DIFF_INSERT].length;p++)u[t[EditorUi.DIFF_INSERT][p].previous]=t[EditorUi.DIFF_INSERT][p];if(null!=t[EditorUi.DIFF_UPDATE])for(var g in t[EditorUi.DIFF_UPDATE]){var v=t[EditorUi.DIFF_UPDATE][g];null!=v.previous&&(s[v.previous]=g)}if(null!=e){var c="";for(p=0;p<e.length;p++){var E=e[p].getId();d[E]=e[p],null!=s[c]||a[E]||null!=t[EditorUi.DIFF_UPDATE]&&null!=t[EditorUi.DIFF_UPDATE][E]&&null!=t[EditorUi.DIFF_UPDATE][E].previous||(s[c]=E),c=E}}var f={},h=mxUtils.bind(this,(function(e){var r=null!=e?e.getId():"";if(null!=e&&!f[r]){f[r]=!0,o.push(e);var a=null!=t[EditorUi.DIFF_UPDATE]?t[EditorUi.DIFF_UPDATE][r]:null;null!=a&&(this.updatePageRoot(e),null!=a.name&&e.setName(a.name),null!=a.view&&this.patchViewState(e,a.view),null!=a.cells&&this.patchPage(e,a.cells,n[e.getId()],i),!l||null==a.cells&&null==a.view||(e.needsUpdate=!0))}var g=s[r];null!=g&&(delete s[r],h(d[g]));var p=u[r];null!=p&&(delete u[r],U(p))})),U=mxUtils.bind(this,(function(e){var t=mxUtils.parseXml(e.data).documentElement,r=new DiagramPage(t);this.updatePageRoot(r);var i=d[r.getId()];null==i?h(r):(i.root=r.root,this.currentPage==i?this.editor.graph.model.setRoot(i.root):l&&(i.needsUpdate=!0))}));for(var g in h(),s)h(d[s[g]]),delete s[g];for(var g in u)U(u[g]),delete u[g];return o},EditorUi.prototype.patchViewState=function(e,t){if(null!=e.viewState&&null!=t){for(var l in e==this.currentPage&&(e.viewState=this.editor.graph.getViewState()),t)try{e.viewState[l]=JSON.parse(t[l])}catch(e){}e==this.currentPage&&this.editor.graph.setViewState(e.viewState,!0)}},EditorUi.prototype.createParentLookup=function(e,t){var l={};function r(e){var t=l[e];return null==t&&(t={inserted:[],moved:{}},l[e]=t),t}if(null!=t[EditorUi.DIFF_INSERT])for(var i=0;i<t[EditorUi.DIFF_INSERT].length;i++){var n=null!=(a=t[EditorUi.DIFF_INSERT][i]).parent?a.parent:"",o=null!=a.previous?a.previous:"";r(n).inserted[o]=a}if(null!=t[EditorUi.DIFF_UPDATE])for(var u in t[EditorUi.DIFF_UPDATE]){var a;if(null!=(a=t[EditorUi.DIFF_UPDATE][u]).previous){if(null==(n=a.parent)){var d=e.getCell(u);if(null!=d){var s=e.getParent(d);null!=s&&(n=s.getId())}}null!=n&&(r(n).moved[a.previous]=u)}}return l},EditorUi.prototype.patchPage=function(e,t,l,r){var i=e==this.currentPage?this.editor.graph.model:new mxGraphModel(e.root),n=this.createParentLookup(i,t);i.beginUpdate();try{var o=i.updateEdgeParent,u=new mxDictionary,a=[];i.updateEdgeParent=function(e,t){!u.get(e)&&r&&(u.put(e,!0),a.push(e))};var d=n[""],s=null!=d&&null!=d.inserted?d.inserted[""]:null,g=null;if(null!=s&&(g=this.getCellForJson(s)),null==g&&null!=(c=null!=d&&null!=d.moved?d.moved[""]:null)&&(g=i.getCell(c)),null!=g&&(i.setRoot(g),e.root=g),this.patchCellRecursive(e,i,i.root,n,t),null!=t[EditorUi.DIFF_REMOVE])for(var p=0;p<t[EditorUi.DIFF_REMOVE].length;p++)null!=(E=i.getCell(t[EditorUi.DIFF_REMOVE][p]))&&i.remove(E);if(null!=t[EditorUi.DIFF_UPDATE]){var v=null!=l&&null!=l.cells?l.cells[EditorUi.DIFF_UPDATE]:null;for(var c in t[EditorUi.DIFF_UPDATE])this.patchCell(i,i.getCell(c),t[EditorUi.DIFF_UPDATE][c],null!=v?v[c]:null)}if(null!=t[EditorUi.DIFF_INSERT])for(p=0;p<t[EditorUi.DIFF_INSERT].length;p++){var E;s=t[EditorUi.DIFF_INSERT][p],null!=(E=i.getCell(s.id))&&(i.setTerminal(E,i.getCell(s.source),!0),i.setTerminal(E,i.getCell(s.target),!1))}if(i.updateEdgeParent=o,r&&a.length>0)for(p=0;p<a.length;p++)i.contains(a[p])&&i.updateEdgeParent(a[p])}finally{i.endUpdate()}},EditorUi.prototype.patchCellRecursive=function(e,t,l,r,i){if(null!=l){for(var n=r[l.getId()],o=null!=n&&null!=n.inserted?n.inserted:{},u=null!=n&&null!=n.moved?n.moved:{},a=0,d=t.getChildCount(l),s="",g=0;g<d;g++){var p=t.getChildAt(l,g).getId();null==u[s]&&(null==i[EditorUi.DIFF_UPDATE]||null==i[EditorUi.DIFF_UPDATE][p]||null==i[EditorUi.DIFF_UPDATE][p].previous&&null==i[EditorUi.DIFF_UPDATE][p].parent)&&(u[s]=p),s=p}for(var v=mxUtils.bind(this,(function(n,o){var u=null!=n?n.getId():"";if(null!=n&&o){var d=t.getCell(u);null!=d&&d!=n&&(n=null)}return null!=n&&(t.getChildAt(l,a)!=n&&t.add(l,n,a),this.patchCellRecursive(e,t,n,r,i),a++),u})),c=[null];c.length>0;){var E=c.shift(),f=u[U=v(null!=E?E.child:null,null!=E&&E.insert)];null!=f&&(delete u[U],c.push({child:t.getCell(f)}));var h=o[U];if(null!=h&&(delete o[U],c.push({child:this.getCellForJson(h),insert:!0})),0==c.length){for(var U in u)c.push({child:t.getCell(u[U])}),delete u[U];for(var U in o)c.push({child:this.getCellForJson(o[U]),insert:!0}),delete o[U]}}}},EditorUi.prototype.patchCell=function(e,t,l,r){if(null!=t&&null!=l)for(var i in null!=r&&(null!=r.xmlValue||null!=r.value&&""!=r.value)||("value"in l?e.setValue(t,l.value):null!=l.xmlValue&&e.setValue(t,mxUtils.parseXml(l.xmlValue).documentElement)),null!=r&&null!=r.style||null==l.style||e.setStyle(t,l.style),null!=l.visible&&e.setVisible(t,1==l.visible),null!=l.collapsed&&e.setCollapsed(t,1==l.collapsed),null!=l.vertex&&(t.vertex=1==l.vertex),null!=l.edge&&(t.edge=1==l.edge),null!=l.connectable&&(t.connectable=1==l.connectable),null!=l.geometry&&e.setGeometry(t,this.codec.decode(mxUtils.parseXml(l.geometry).documentElement)),null!=l.source&&e.setTerminal(t,e.getCell(l.source),!0),null!=l.target&&e.setTerminal(t,e.getCell(l.target),!1),l)this.cellProperties[i]||(t[i]=l[i])},EditorUi.prototype.getPagesForNode=function(e,t){var l=this.editor.extractGraphModel(e,!0,!0);null!=l&&(e=l);var r=e.getElementsByTagName(t||"diagram"),i=[];if(r.length>0)for(var n=0;n<r.length;n++){var o=new DiagramPage(r[n]);this.updatePageRoot(o,!0),i.push(o)}else"mxGraphModel"==e.nodeName&&(this.editor.graph,(o=new DiagramPage(e.ownerDocument.createElement("diagram"))).setName(mxResources.get("pageWithNumber",[1])),mxUtils.setTextContent(o.node,Graph.compressNode(e,!0)),i.push(o));return i},EditorUi.prototype.diffPages=function(e,t){this.editor.graph;for(var l=[],r=[],i={},n={},o={},u=null,a=0;a<t.length;a++)n[t[a].getId()]={page:t[a],prev:u},u=t[a];for(u=null,a=0;a<e.length;a++){if(null==(v=n[p=e[a].getId()]))r.push(p);else{var d=this.diffPage(e[a],v.page),s={};Object.keys(d).length>0&&(s.cells=d);var g=this.diffViewState(e[a],v.page);Object.keys(g).length>0&&(s.view=g),((null!=v.prev?null==u:null!=u)||null!=u&&null!=v.prev&&u.getId()!=v.prev.getId())&&(s.previous=null!=v.prev?v.prev.getId():""),null!=v.page.getName()&&e[a].getName()!=v.page.getName()&&(s.name=v.page.getName()),Object.keys(s).length>0&&(o[p]=s)}delete n[e[a].getId()],u=e[a]}for(var p in n){var v=n[p];l.push({data:mxUtils.getXml(v.page.node),previous:null!=v.prev?v.prev.getId():""})}return Object.keys(o).length>0&&(i[EditorUi.DIFF_UPDATE]=o),r.length>0&&(i[EditorUi.DIFF_REMOVE]=r),l.length>0&&(i[EditorUi.DIFF_INSERT]=l),i},EditorUi.prototype.createCellLookup=function(e,t,l){(l=null!=l?l:{})[e.getId()]={cell:e,prev:t};var r=e.getChildCount();t=null;for(var i=0;i<r;i++){var n=e.getChildAt(i);this.createCellLookup(n,t,l),t=n}return l},EditorUi.prototype.diffCellRecursive=function(e,t,l,r,i){r=null!=r?r:{};var n=l[e.getId()];if(delete l[e.getId()],null==n)i.push(e.getId());else{var o=this.diffCell(e,n.cell);(null!=o.parent||(null!=n.prev?null==t:null!=t)||null!=t&&null!=n.prev&&t.getId()!=n.prev.getId())&&(o.previous=null!=n.prev?n.prev.getId():""),Object.keys(o).length>0&&(r[e.getId()]=o)}var u=e.getChildCount();t=null;for(var a=0;a<u;a++){var d=e.getChildAt(a);this.diffCellRecursive(d,t,l,r,i),t=d}return r},EditorUi.prototype.diffPage=function(e,t){var l=[],r=[],i={};this.updatePageRoot(e),this.updatePageRoot(t);var n=this.createCellLookup(t.root),o=this.diffCellRecursive(e.root,null,n,o,r);for(var u in n){var a=n[u];l.push(this.getJsonForCell(a.cell,a.prev))}return Object.keys(o).length>0&&(i[EditorUi.DIFF_UPDATE]=o),r.length>0&&(i[EditorUi.DIFF_REMOVE]=r),l.length>0&&(i[EditorUi.DIFF_INSERT]=l),i},EditorUi.prototype.diffViewState=function(e,t){var l=e.viewState,r=t.viewState,i={};if(t==this.currentPage&&(r=this.editor.graph.getViewState()),null!=l&&null!=r)for(var n in this.viewStateProperties){var o=JSON.stringify(l[n]),u=JSON.stringify(r[n]);o!=u&&(i[n]=u)}return i},EditorUi.prototype.getCellForJson=function(e){var t=null!=e.geometry?this.codec.decode(mxUtils.parseXml(e.geometry).documentElement):null,l=e.value;null!=e.xmlValue&&(l=mxUtils.parseXml(e.xmlValue).documentElement);var r=new mxCell(l,t,e.style);for(var i in r.connectable=0!=e.connectable,r.collapsed=1==e.collapsed,r.visible=0!=e.visible,r.vertex=1==e.vertex,r.edge=1==e.edge,r.id=e.id,e)this.cellProperties[i]||(r[i]=e[i]);return r},EditorUi.prototype.getJsonForCell=function(e,t){var l={id:e.getId()};for(var r in e.vertex&&(l.vertex=1),e.edge&&(l.edge=1),e.connectable||(l.connectable=0),null!=e.parent&&(l.parent=e.parent.getId()),null!=t&&(l.previous=t.getId()),null!=e.source&&(l.source=e.source.getId()),null!=e.target&&(l.target=e.target.getId()),null!=e.style&&(l.style=e.style),null!=e.geometry&&(l.geometry=mxUtils.getXml(this.codec.encode(e.geometry))),e.collapsed&&(l.collapsed=1),e.visible||(l.visible=0),null!=e.value&&("object"==typeof e.value&&"number"==typeof e.value.nodeType&&"string"==typeof e.value.nodeName&&"function"==typeof e.value.getAttribute?l.xmlValue=mxUtils.getXml(e.value):l.value=e.value),e)this.cellProperties[r]||"function"==typeof e[r]||(l[r]=e[r]);return l},EditorUi.prototype.diffCell=function(e,t){var l={};function r(e){return null!=e&&"object"==typeof e&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}if(e.vertex!=t.vertex&&(l.vertex=t.vertex?1:0),e.edge!=t.edge&&(l.edge=t.edge?1:0),e.connectable!=t.connectable&&(l.connectable=t.connectable?1:0),((null!=e.parent?null==t.parent:null!=t.parent)||null!=e.parent&&null!=t.parent&&e.parent.getId()!=t.parent.getId())&&(l.parent=null!=t.parent?t.parent.getId():""),((null!=e.source?null==t.source:null!=t.source)||null!=e.source&&null!=t.source&&e.source.getId()!=t.source.getId())&&(l.source=null!=t.source?t.source.getId():""),((null!=e.target?null==t.target:null!=t.target)||null!=e.target&&null!=t.target&&e.target.getId()!=t.target.getId())&&(l.target=null!=t.target?t.target.getId():""),r(e.value)&&r(t.value)?e.value.isEqualNode(t.value)||(l.xmlValue=mxUtils.getXml(t.value)):e.value!=t.value&&(r(t.value)?l.xmlValue=mxUtils.getXml(t.value):l.value=null!=t.value?t.value:null),e.style!=t.style&&(l.style=t.style),e.visible!=t.visible&&(l.visible=t.visible?1:0),e.collapsed!=t.collapsed&&(l.collapsed=t.collapsed?1:0),!this.isObjectEqual(e.geometry,t.geometry,new mxGeometry)){var i=this.codec.encode(t.geometry);null!=i&&(l.geometry=mxUtils.getXml(i))}for(var n in e)this.cellProperties[n]||"function"==typeof e[n]||"function"==typeof t[n]||e[n]==t[n]||(l[n]=void 0===t[n]?null:t[n]);for(var n in t)n in e||this.cellProperties[n]||"function"==typeof e[n]||"function"==typeof t[n]||e[n]==t[n]||(l[n]=void 0===t[n]?null:t[n]);return l},EditorUi.prototype.isObjectEqual=function(e,t,l){if(null==e&&null==t)return!0;if(null!=e?null==t:null!=t)return!1;var r=function(e,t){return null==l||l[e]!=t?!0===t?1:t:void 0};return JSON.stringify(e,r)==JSON.stringify(t,r)};