control-freak-ide/Code/client/build/wcDocker/xace/views/AceDiff.js
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

27 lines
12 KiB
JavaScript

//>>built
define("xace/views/AceDiff",["dojo/_base/declare","dojo/_base/lang"],function(K,Q){function v(a,b){var d=a.options.mode;b===h.EDITOR_LEFT&&null!==a.options.left.mode&&(d=a.options.left.mode);b===h.EDITOR_RIGHT&&null!==a.options.right.mode&&(d=a.options.right.mode);return d}function L(a){var b=(new Date).getTime(),d=(new Date).getTime(),c;a.editors.left.ace.getSession().on("changeScrollTop",function(b){c=(new Date).getTime();d+50<c&&(q(a),t(a),w(a))});a.editors.right.ace.getSession().on("changeScrollTop",
function(f){c=(new Date).getTime();b+50<c&&(q(a),t(a),w(a))});var e=a.diff.bind(a);a.editors.left.ace.on("change",e);a.editors.right.ace.on("change",e);a.options.left.copyLinkEnabled&&x("#"+a.options.classes.gutterID,"click","."+a.options.classes.newCodeConnectorLink,function(b){y(a,b,h.LTR)});a.options.right.copyLinkEnabled&&x("#"+a.options.classes.gutterID,"click","."+a.options.classes.deletedCodeConnectorLink,function(b){y(a,b,h.RTL)});e=M(function(){a.editors.availableHeight=a.options.leftAce.offsetHeight;
a.diff()},250);window.addEventListener("resize",e)}function y(a,b,d){b=parseInt(b.target.getAttribute("data-diff-index"),10);b=a.diffs[b];var c,e,f,g,k;d===h.LTR?(c=a.editors.left,d=a.editors.right,e=b.leftStartLine,f=b.leftEndLine,g=b.rightStartLine,k=b.rightEndLine):(c=a.editors.right,d=a.editors.left,e=b.rightStartLine,f=b.rightEndLine,g=b.leftStartLine,k=b.leftEndLine);for(b="";e<f;e++)b+=l(c,e)+"\n";c="";for(e=0;e<g;e++)c+=l(d,e)+"\n";g="";f=d.ace.getSession().getLength();for(e=k;e<f;e++)g+=
l(d,e),e<f-1&&(g+="\n");g=g.replace(/\s*$/,"");k=d.ace.getSession().getScrollTop();d.ace.getSession().setValue(c+b+g);d.ace.getSession().setScrollTop(parseInt(k));a.diff()}function z(a){var b=[];a.ace.getSession().doc.getAllLines().forEach(function(a){b.push(a.length+1)});return b}function A(a,b,d,c,e){b=a.editors[b];c<d&&(c=d);a=e+" "+(c>d?"lines":"targetOnly");c--;b.markers.push(b.ace.session.addMarker(new B(d,0,c,1),a,"fullLine"))}function q(a){a.editors.left.markers.forEach(function(a){this.editors.left.ace.getSession().removeMarker(a)},
a);a.editors.right.markers.forEach(function(a){this.editors.right.ace.getSession().removeMarker(a)},a)}function w(a){var b=a.editors.left.ace.getSession().getScrollTop(),d=a.editors.right.ace.getSession().getScrollTop();a.copyRightContainer.style.cssText="top: "+-b+"px";a.copyLeftContainer.style.cssText="top: "+-d+"px"}function C(a,b,d,c,e){var f={},g=/^\n/.test(e);if(b===h.DIFF_INSERT){b=D(a.editors.left,d,e);var k=E(a.editors.right,c),f=l(a.editors.right,k).length;d=l(a.editors.left,b.startLine).length;
var n=l(a.editors.left,b.startLine).length,m=k;0===n&&g&&(g=!1);0===b.startChar&&F(a.editors.right,c,g)&&(m=k+1);a=b.startLine===b.endLine;g=0;(0<b.startChar||a&&e.length<d)&&0<f&&b.startChar<d&&g++;f={leftStartLine:b.startLine,leftEndLine:b.endLine+1,rightStartLine:m,rightEndLine:m+g}}else b=D(a.editors.right,c,e),k=E(a.editors.left,d),f=l(a.editors.left,k).length,c=l(a.editors.right,b.startLine).length,n=l(a.editors.right,b.startLine).length,m=k,0===n&&g&&(g=!1),0===b.startChar&&F(a.editors.left,
d,g)&&(m=k+1),a=b.startLine===b.endLine,g=0,(0<b.startChar||a&&e.length<c)&&0<f&&b.startChar<c&&g++,f={leftStartLine:m,leftEndLine:m+g,rightStartLine:b.startLine,rightEndLine:b.endLine+1};return f}function D(a,b,d){var c={startLine:0,startChar:0,endLine:0,endChar:0},e=b+d.length,f=0,g=!1,k=!1;a.lineLengths.forEach(function(a,d){f+=a;!g&&b<f&&(c.startLine=d,c.startChar=b-f+a,g=!0);!k&&e<=f&&(c.endLine=d,c.endChar=e-f+a,k=!0)});0<c.startChar&&l(a,c.startLine).length===c.startChar&&(c.startLine++,c.startChar=
0);0===c.endChar&&c.endLine--;a=/\n$/.test(d);0<c.startChar&&a&&c.endLine++;return c}function l(a,b){return a.ace.getSession().doc.getLine(b)}function E(a,b){for(var d=a.ace.getSession().doc.getAllLines(),c=0,e=0,f=0;f<d.length;f++)if(e+=d[f].length+1,b<=e){c=f;break}return c}function F(a,b,d){a=a.ace.getSession().doc.getAllLines();for(var c=0,e=!1,f=0;f<a.length;f++){var g=c+=a[f].length+1;d&&g--;if(b===g){e=!0;break}}return e}function G(a){var b=document.createElement("div"),d={"class":a.className,
style:"top:"+a.topOffset+"px",title:a.tooltip,"data-diff-index":a.diffIndex},c;for(c in d)b.setAttribute(c,d[c]);b.innerHTML=a.arrowContent;return b}function H(a){if(document.getElementById(a.options.classes.gutterID)){a.gutterHeight=document.getElementById(a.options.classes.gutterID).clientHeight;a.gutterWidth=document.getElementById(a.options.classes.gutterID).clientWidth;var b=I(a,h.EDITOR_LEFT),d=I(a,h.EDITOR_RIGHT),b=Math.max(b,d,a.gutterHeight);a.gutterSVG=document.createElementNS(h.SVG_NS,
"svg");a.gutterSVG.setAttribute("width",a.gutterWidth);a.gutterSVG.setAttribute("height",b);document.getElementById(a.options.classes.gutterID).appendChild(a.gutterSVG)}else console.error("strange, gutter is gone")}function I(a,b){return(b===h.EDITOR_LEFT?a.editors.left:a.editors.right).ace.getSession().getLength()*a.lineHeight}function N(a){var b=document.getElementById(a.options.classes.gutterID);b&&b.removeChild(a.gutterSVG);H(a)}function O(a){a.copyLeftContainer.innerHTML="";a.copyRightContainer.innerHTML=
""}function P(a,b){function d(b){return a.options.diffGranularity===h.DIFF_GRANULARITY_SPECIFIC?1>b:1>=b}var c=[];b.forEach(function(a,b){if(0===b)c.push(a);else{for(var f=!1,e=0;e<c.length;e++)if(d(Math.abs(a.leftStartLine-c[e].leftEndLine))&&d(Math.abs(a.rightStartLine-c[e].rightEndLine))){c[e].leftStartLine=Math.min(a.leftStartLine,c[e].leftStartLine);c[e].rightStartLine=Math.min(a.rightStartLine,c[e].rightStartLine);c[e].leftEndLine=Math.max(a.leftEndLine,c[e].leftEndLine);c[e].rightEndLine=Math.max(a.rightEndLine,
c[e].rightEndLine);f=!0;break}f||c.push(a)}});var e=[];c.forEach(function(a){a.leftStartLine===a.leftEndLine&&a.rightStartLine===a.rightEndLine||e.push(a)});return e}function t(a){N(a);O(a);a.diffs.forEach(function(a,d){if(this.options.showDiffs){A(this,h.EDITOR_LEFT,a.leftStartLine,a.leftEndLine,this.options.classes.diff);A(this,h.EDITOR_RIGHT,a.rightStartLine,a.rightEndLine,this.options.classes.diff);if(this.options.showConnectors){var b=a.leftStartLine,e=a.leftEndLine,f=a.rightStartLine,g=a.rightEndLine,
k=this.editors.left.ace.getSession().getScrollTop(),n=this.editors.right.ace.getSession().getScrollTop();this.connectorYOffset=1;var b=b*this.lineHeight-k,m=this.gutterWidth+1,f=f*this.lineHeight-n,e=e*this.lineHeight-k+this.connectorYOffset,k=this.gutterWidth+1,g=g*this.lineHeight-n+this.connectorYOffset,n=J(-1,b,m,f),r=J(k,g,-1,e),b=n+" "+("L"+m+","+f+" "+k+","+g)+" "+r+" "+("L-1,"+e+" -1,"+b),m=document.createElementNS(h.SVG_NS,"path");m.setAttribute("d",b);m.setAttribute("class",this.options.classes.connector);
this.gutterSVG.appendChild(m)}a.leftEndLine>a.leftStartLine&&this.options.left.copyLinkEnabled&&(b=G({className:this.options.classes.newCodeConnectorLink,topOffset:a.leftStartLine*this.lineHeight,tooltip:"Copy to right",diffIndex:d,arrowContent:this.options.classes.newCodeConnectorLinkContent}),this.copyRightContainer.appendChild(b));a.rightEndLine>a.rightStartLine&&this.options.right.copyLinkEnabled&&(b=G({className:this.options.classes.deletedCodeConnectorLink,topOffset:a.rightStartLine*this.lineHeight,
tooltip:"Copy to left",diffIndex:d,arrowContent:this.options.classes.deletedCodeConnectorLinkContent}),this.copyLeftContainer.appendChild(b))}},a)}function u(){var a,b,d,c,e,f=arguments[0]||{},g=1,k=arguments.length,h=!1,m=Object.prototype.toString,r=Object.prototype.hasOwnProperty,l={"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regexp","[object Object]":"object"},
p={isFunction:function(a){return"function"===p.type(a)},isArray:Array.isArray||function(a){return"array"===p.type(a)},isWindow:function(a){return null!==a&&a===a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return null===a?String(a):l[m.call(a)]||"object"},isPlainObject:function(a){if(!a||"object"!==p.type(a)||a.nodeType)return!1;try{if(a.constructor&&!r.call(a,"constructor")&&!r.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(R){return!1}for(var b in a);
return void 0===b||r.call(a,b)}};"boolean"===typeof f&&(h=f,f=arguments[1]||{},g=2);"object"===typeof f||p.isFunction(f)||(f={});k===g&&(f=this,--g);for(g;g<k;g++)if(null!==(a=arguments[g]))for(b in a)d=f[b],c=a[b],f!==c&&(h&&c&&(p.isPlainObject(c)||(e=p.isArray(c)))?(e?(e=!1,d=d&&p.isArray(d)?d:[]):d=d&&p.isPlainObject(d)?d:{},f[b]=u(h,d,c)):void 0!==c&&(f[b]=c));return f}function J(a,b,d,c){var e=a+(d-a)/2;return"M "+a+" "+b+" C "+e+","+b+" "+e+","+c+" "+d+","+c}function x(a,b,d,c){var e="document"===
a?document:document.querySelector(a);e.addEventListener(b,function(a){for(var b=e.querySelectorAll(d),f=a.target,h=0,m=b.length;h<m;h++)for(var l=f,q=b[h];l&&l!==e;){if(l===q)return c.call(q,a);l=l.parentNode}})}function M(a,b,d){var c;return function(){var e=this,f=arguments,g=d&&!c;clearTimeout(c);c=setTimeout(function(){c=null;d||a.apply(e,f)},b);g&&a.apply(e,f)}}var B=null,h={DIFF_EQUAL:0,DIFF_DELETE:-1,DIFF_INSERT:1,EDITOR_RIGHT:"right",EDITOR_LEFT:"left",RTL:"rtl",LTR:"ltr",SVG_NS:"http://www.w3.org/2000/svg",
DIFF_GRANULARITY_SPECIFIC:"specific",DIFF_GRANULARITY_BROAD:"broad"};return K("xide.views.AceDiff",null,{setOptions:function(a){u(!0,this.options,a);this.diff()},getNumDiffs:function(){return this.diffs.length},getEditors:function(){return{left:this.editors.left.ace,right:this.editors.right.ace}},diff:function(){var a=new diff_match_patch,b=this.editors.left.ace.getSession().getValue(),d=this.editors.right.ace.getSession().getValue(),b=a.diff_main(d,b);a.diff_cleanupSemantic(b);this.editors.left.lineLengths=
z(this.editors.left);this.editors.right.lineLengths=z(this.editors.right);var c=[],e=0,f=0;b.forEach(function(a){var b=a[0];a=a[1];0!==a.length&&(b===h.DIFF_EQUAL?(e+=a.length,f+=a.length):b===h.DIFF_DELETE?(c.push(C(this,h.DIFF_DELETE,e,f,a)),f+=a.length):b===h.DIFF_INSERT&&(c.push(C(this,h.DIFF_INSERT,e,f,a)),e+=a.length))},this);this.diffs=P(this,c);this.diffs.length>this.options.maxDiffs||(q(this),t(this))},destroy:function(){var a=this.editors.left.ace.getValue();this.editors.left.ace.destroy();
var b=this.editors.left.ace.container,d=b.cloneNode(!1);d.textContent=a;b.parentNode.replaceChild(d,b);a=this.editors.right.ace.getValue();this.editors.right.ace.destroy();b=this.editors.right.ace.container;d=b.cloneNode(!1);d.textContent=a;b.parentNode.replaceChild(d,b);document.getElementById(this.options.classes.gutterID).innerHTML=""},create:function(a){B=ace.require("ace/range").Range;this.options={};u(!0,this.options,{mode:null,theme:null,diffGranularity:h.DIFF_GRANULARITY_BROAD,lockScrolling:!1,
showDiffs:!0,showConnectors:!0,maxDiffs:5E3,left:{id:"acediff-left-editor",content:null,mode:null,theme:null,editable:!0,copyLinkEnabled:!0},right:{id:"acediff-right-editor",content:null,mode:null,theme:null,editable:!0,copyLinkEnabled:!0},classes:{gutterID:"acediff-gutter",diff:"acediff-diff",connector:"acediff-connector",newCodeConnectorLink:"acediff-new-code-connector-copy",newCodeConnectorLinkContent:"\x26#8594;",deletedCodeConnectorLink:"acediff-deleted-code-connector-copy",deletedCodeConnectorLinkContent:"\x26#8592;",
copyRightContainer:"acediff-copy-right",copyLeftContainer:"acediff-copy-left"},connectorYOffset:0},a);this.editors={left:{ace:a.leftAce||ace.edit(this.options.left.id),markers:[],lineLengths:[]},right:{ace:a.rightAce||ace.edit(this.options.right.id),markers:[],lineLengths:[]},editorHeight:null};L(this);this.lineHeight=this.editors.left.ace.renderer.lineHeight;this.editors.left.ace.getSession().setMode(v(this,h.EDITOR_LEFT));this.editors.right.ace.getSession().setMode(v(this,h.EDITOR_RIGHT));this.editors.left.ace.setReadOnly(!this.options.left.editable);
this.editors.right.ace.setReadOnly(!this.options.right.editable);this.copyRightContainer=document.createElement("div");this.copyRightContainer.setAttribute("class",this.options.classes.copyRightContainer);this.copyLeftContainer=document.createElement("div");this.copyLeftContainer.setAttribute("class",this.options.classes.copyLeftContainer);document.getElementById(this.options.classes.gutterID).appendChild(this.copyRightContainer);document.getElementById(this.options.classes.gutterID).appendChild(this.copyLeftContainer);
H(this);this.options.left.content&&this.editors.left.ace.setValue(this.options.left.content,-1);this.options.right.content&&this.editors.right.ace.setValue(this.options.right.content,-1);this.editors.editorHeight=this.options.leftAce.container.offsetHeight;this.diff()}})});
//# sourceMappingURL=AceDiff.js.map