text: define("bitbucket/internal/feature/commit/difftree/difftree","module exports @atlassian/aui jquery lodash bitbucket/util/navbuilder bitbucket/util/state bitbucket/internal/feature/commit/difftree/difftree-search bitbucket/internal/feature/file-content/request-change bitbucket/internal/model/content-tree-node-types bitbucket/internal/model/path-and-line bitbucket/internal/util/ajax bitbucket/internal/util/events bitbucket/internal/util/property".split(" "),function(F,q,G,H,I,J,K,L,M,N,O,P,Q,R){function u(a,
  b){function c(a){if(a.metadata.isDirectory){a.state="open";a.data.icon="aui-icon aui-icon-small aui-iconfont-folder-filled";var d,f=a.children.length;for(d=0;d<f&&e<b;d++){var g=a.children[d];c(g)}}else a.metadata.isFile&&(a.children&&0<a.children.length&&(a.state="open"),e+=a.children?a.children.length:1)}b=0<=b?b:200;var e=0;c(a);return a}function z(a,b){return a.children?b.children?a.data.title.toLowerCase()<b.data.title.toLowerCase()?-1:1:-1:b.children?1:a.data.title.toLowerCase()<b.data.title.toLowerCase()?
  -1:1}function v(a){a.childrenByTypeAndComponent=void 0;var b,c=a.children.length,e;for(b=0;b<c;b++){var d=a.children[b];if(d.metadata.isDirectory){for(e=[d.data.title];1===d.children.length&&d.children[0].metadata.isDirectory;)d=d.children[0],e.push(d.data.title);d.data.title=e.join("/");a.children[b]=d;v(d)}}a.children.sort(z)}function A(a,b,c){var e={data:{icon:"aui-icon aui-icon-small aui-iconfont-folder-filled"},state:"closed",metadata:{isDirectory:!0},children:[],childrenByTypeAndComponent:{}},
  d,h=a.length;for(d=0;d<h;d++){var f=a[d];var k=e;var l,w=f.path.components.length;for(l=0;l<w;l++){var m=f.path.components[l];var n=(l+1===w?"F":"D")+m;if(Object.prototype.hasOwnProperty.call(k.childrenByTypeAndComponent,n))k=k.childrenByTypeAndComponent[n];else{var t=l+1===w;m=g.default.escapeHtml(m);if(t){t=!(!f.properties||!f.properties.activeComments);var p=m;f.conflict&&t?p=g.default.I18n.getText("bitbucket.web.pullrequest.tree.commented.and.conflicted.file",m):f.conflict?p=g.default.I18n.getText("bitbucket.web.pullrequest.tree.conflicted.file",
  m):t&&(p=g.default.I18n.getText("bitbucket.web.pullrequest.tree.commented.file",m));var r="aui-icon aui-icon-small ";r=f.conflict?r+"aui-iconfont-warning":f.nodeType===S.default.SUBMODULE?r+"aui-iconfont-devtools-submodule":t?r+"icon-file-commented":r+"aui-iconfont-document";m={data:{title:m,icon:r,attr:{id:"change"+d,class:"difftree-file change-type-"+f.type+(f.conflict?" conflict":""),href:"#"+encodeURI(f.path.toString),title:p}},metadata:babelHelpers.extends({isFile:!0,changeType:f.type,nodeType:f.nodeType,
  path:f.path,srcPath:f.srcPath,conflict:f.conflict,contentId:f.contentId,fromContentId:f.fromContentId,executable:f.executable,srcExecutable:f.srcExecutable},b)}}else m={data:{title:m,icon:"aui-icon aui-icon-small aui-iconfont-folder-filled"},state:"closed",metadata:{isDirectory:!0},children:[],childrenByTypeAndComponent:{}};k.children.push(m);k=k.childrenByTypeAndComponent[n]=m}}}v(e);u(e,c);return e}function T(a,b,c){return U.default.rest().currentRepo().changes(c).withParams({start:a,limit:b})}
  function h(a,b,c,e){e=e||{};this._fileLimit=e.maxChanges||1E3;V.default.getFromProvider("page.max.diff.lines").done(function(a){this._maxDiffLines=a}.bind(this));this._$wrapper=(0,n.default)(a);this._$toolbar=(0,n.default)(b);this._commitRange=c;this._hasOtherParents=!!e.hasOtherParents;this._urlBuilder=e.urlBuilder||T;this._searchUrlBuilder=e.searchUrlBuilder;this._diffViewType=e.diffViewType}function p(a,b){if(!(b=W(a,b))){for(;a&&a.children;)a=a.children[0];b=k.default.get(a,"metadata.isFile")?
  a:null}return b}function W(a,b){if(!b)return null;for(b=b.slice(0);a&&a.children;){for(var c=b.shift(),e=!b.length,d=a.children.length;d--;){var g=a.children[d],f=k.default.unescape(g.data.title);if(c===f&&e===!!g.metadata.isFile){a=g;break}if(!e&&k.default.startsWith(f,c+"/")){for(;1<b.length&&k.default.startsWith(f,c+"/"+b[0]);)c+="/",c+=b.shift();if(f!==c)return null;a=g;break}}if(0>d)return null}return k.default.get(a,"metadata.isFile")?a:null}function x(a,b){if(a===b)return[b];for(var c=a.children?
  a.children.length:0;c--;){var e=x(a.children[c],b);if(e)return e.unshift(a),e}return null}function y(a,b,c){c&&c.length&&!c.hasClass("jstree-leaf")&&(a.open_node(c),c=y(a,b,b.call(a,c)));return c}function B(a,b){b&&!b.hasClass("jstree-leaf")&&(b.hasClass("jstree-closed")?(a.open_node(b),b=y(a,C,C.call(a,b))):b.length&&(b=B(a,a._get_prev(b))));return b}function C(a){return this._get_children(a).filter(".jstree-last")}Object.defineProperty(q,"__esModule",{value:!0});var g=babelHelpers.interopRequireDefault(G),
  n=babelHelpers.interopRequireDefault(H),k=babelHelpers.interopRequireDefault(I),U=babelHelpers.interopRequireDefault(J);babelHelpers.interopRequireDefault(K);var X=babelHelpers.interopRequireDefault(L),D=babelHelpers.interopRequireDefault(M),S=babelHelpers.interopRequireDefault(N),E=babelHelpers.interopRequireDefault(O),Y=babelHelpers.interopRequireDefault(P),l=babelHelpers.interopRequireDefault(Q),V=babelHelpers.interopRequireDefault(R);k.default.assign(h.prototype,l.default.createEventMixin("diffTree",
  {localOnly:!0}));h.prototype.init=function(a){this._destroyables=[];this._selectedPathComponents=a;this._firstCommentAddedHandler=k.default.bind(this._firstCommentAddedHandler,this);this._lastCommentDeletedHandler=k.default.bind(this._lastCommentDeletedHandler,this);this._destroyables.push(l.default.chain().on("bitbucket.internal.feature.comments.firstCommentAdded",this._firstCommentAddedHandler).on("bitbucket.internal.feature.comments.lastCommentDeleted",this._lastCommentDeletedHandler));this._searchUrlBuilder&&
  this._destroyables.push(this._addSearch());return this.data?this.dataReceived(this.data):this.requestData()};h.prototype._addSearch=function(){var a=this,b=[],c=new X.default.DiffTreeSearch,e=this._$wrapper.siblings(".file-tree-header"),d=(0,n.default)(bitbucket.internal.feature.difftree.searchWrapper({includeCollapseButton:!e.length}));d.prepend(c.input.$el);if(e.length)e.after(d),b.push({destroy:function(){return d.remove()}});else{var g=this._$toolbar.find("h4");g.replaceWith(d);b.push({destroy:function(){return d.replaceWith(g)}})}b.push(c);
  b.push(l.default.chainWith(d.find(".search-button-when-collapsed")).on("click",function(){c.focusSearch()}));b.push(l.default.chainWith(c).on("search-focus",k.default.bind(this.trigger,this,"search-focus")));b.push({destroy:c.register(function(b){d.addClass("searching");return Y.default.rest({url:a._searchUrlBuilder({path:"",commitRange:a._commitRange.toJSON()}).withParams({withComments:!1}).withParams(!b||!a._commitRange.getPullRequest()&&50>a._getFileCount(a.data,50)?{}:{filter:b}).build()}).done(function(){return d.removeClass("searching")})},
  function(){return a.data}).onValue(function(b){d.toggleClass("searching",!!b.search);a.data_copy=a.data;a._searchEmpty=0===b.data.children.length;l.default.trigger("bitbucket.internal.feature.diffView.highlightSearch",null,b.search);a.dataReceived(u(b.data)).done(function(){a.data=a.data_copy;a._searchEmpty=null})})});return{destroy:function(){k.default.invokeMap(b,"destroy")}}};h.prototype._getFileCount=function(a,b){function c(a){return k.default.reduce(a.children,function(a,e){return a<b?a+(e.metadata.isFile?
  1:c(e)):a},0)}return c(a)};h.prototype.invalidateCacheForLastUrl=function(){this._lastUrl&&D.default.invalidateCacheForUrl(this._lastUrl)};h.prototype._firstCommentAddedHandler=function(){this.invalidateCacheForLastUrl();this.getSelectedFile().find("a \x3e ins").hide().removeClass("aui-iconfont-document").addClass("icon-file-commented").fadeIn("slow")};h.prototype._lastCommentDeletedHandler=function(){this.invalidateCacheForLastUrl();this.getSelectedFile().find("a \x3e ins").hide().removeClass("icon-file-commented").addClass("aui-iconfont-document").fadeIn("slow")};
  h.prototype.reset=function(){this._request&&(this._request.abort(),this._interrupted=!0);this._rendering&&(this._rendering=!1,this._interrupted=!0);k.default.invokeMap(this._destroyables,"destroy")};h.prototype.requestData=function(){var a=this;this._request&&(this._lastUrl=null,this._request.abort());var b=this._urlBuilder(0,this._fileLimit,this._commitRange).build();this._lastUrl=b;this._request=D.default.getChangesRequestFromUrl(b);return this._request.always(function(){return a._request=null}).then(function(b){if(!b)return b=
  g.default.escapeHtml(g.default.I18n.getText("bitbucket.web.pullrequest.tree.nodata")),a.prependMessage(b,"error"),n.default.Deferred().reject();a._rendering=!0;a._interrupted=!1;a.isTruncated=!b.isLastPage;b=A(b.values,{diffViewType:a._diffViewType});return a.dataReceived(b).done(function(){return a._rendering=!1})})};h.prototype.prependMessage=function(a,b){this._$wrapper.find(".aui-message").remove();b=b||"warning";this._$wrapper.find(".file-tree").before(aui.message[b]({extraClasses:"diff-tree-scm-message",
  content:a}))};h.prototype.dataReceived=function(a){function b(){c._interrupted?e.reject(c):e.resolve(c)}var c=this;this.data=a;var e=n.default.Deferred();a=p(this.data,this._selectedPathComponents);if(a){var d=[a.data.attr.id];a=x(this.data,a)||[];for(a.pop();a.length;)a.pop().state="open"}else d=[];var h=!0,f;this._$wrapper.find(".aui-message").remove();if(this.isTruncated){a="";if(this._commitRange.getPullRequest())a=g.default.escapeHtml(g.default.I18n.getText("bitbucket.web.pullrequest.tree.truncated",
  this._fileLimit));else{a=this._commitRange.getUntilRevision();var k=this._commitRange.getSinceRevision();a=k?"git diff-tree -C -r "+k.getId()+" "+a.getId():"git diff-tree -r --root "+a.getId();a=g.default.escapeHtml(g.default.I18n.getText("bitbucket.web.commit.tree.truncated",this._fileLimit))+'\x3cp class\x3d"scm-command"\x3e'+g.default.escapeHtml(a)+"\x3c/p\x3e"}this.prependMessage(a,"warning")}if(this.data.children.length)this.data.searchTruncated&&c.prependMessage(g.default.escapeHtml(g.default.I18n.getText("bitbucket.web.commit.tree.truncated.search",
  this._maxDiffLines)),"info"),this.$tree=this._$wrapper.children(".file-tree"),this.$tree.fadeOut("fast",function(){c.$tree.empty().off(".jstree").jstree("destroy").on("loaded.jstree",function(){setTimeout(function(){h=!1;b()},0)}).jstree({json_data:{data:c.data.children,progressive_render:!0},core:{html_titles:!0,animation:200},ui:{select_limit:1,selected_parent_close:!1,initially_select:d},plugins:["json_data","ui"]}).on("before.jstree",function(a,b){if("select_node"===b.func)if(a=(0,n.default)(b.args[0]).parent(),
  a.hasClass("jstree-leaf")&&(!f||f[0]!==a[0]))f=a,l.default.trigger("bitbucket.internal.feature.commit.difftree.selectedNodeChanged",c,a,h),c._selectedPathComponents=(new E.default(a.data("path"))).path.getComponents();else if(0<a.length)return c.$tree.jstree("toggle_node",a),!1}).on("open_node.jstree",function(a,b){a=b.args[0];a.data().isDirectory&&a.children("a").children("ins");l.default.trigger("bitbucket.internal.feature.commit.difftree.nodeOpening",c,a)}).on("after_open.jstree",function(a,b){l.default.trigger("bitbucket.internal.feature.commit.difftree.nodeOpened",
  c,b.args[0])}).on("close_node.jstree",function(a,b){a=b.args[0];a.data().isDirectory&&a.children("a").children("ins");l.default.trigger("bitbucket.internal.feature.commit.difftree.nodeClosing",c,a)}).on("after_close.jstree",function(a,b){l.default.trigger("bitbucket.internal.feature.commit.difftree.nodeClosed",c,b.args[0])}).on("loaded.jstree",function(a,b){l.default.trigger("bitbucket.internal.feature.commit.difftree.treeInitialised",c,c)}).fadeIn("fast")});else{this.$tree=void 0;var q=this._$wrapper.children(".file-tree");
  q.fadeOut("fast",function(){q.empty().off(".jstree").jstree("destroy");var a=g.default.escapeHtml(c._searchEmpty&&c.data.searchTruncated?g.default.I18n.getText("bitbucket.web.commit.tree.truncated.search",c._maxDiffLines)+" "+g.default.I18n.getText("bitbucket.web.commit.tree.emptysearch"):c._searchEmpty?g.default.I18n.getText("bitbucket.web.commit.tree.emptysearch"):c._hasOtherParents?g.default.I18n.getText("bitbucket.web.commit.merge.tree.empty"):g.default.I18n.getText("bitbucket.web.commit.tree.empty"));
  c.prependMessage(a,"info");setTimeout(b,0)})}return e.promise().always(function(){c._$wrapper.attr("data-last-updated",(new Date).getTime())})};h.prototype.getSelectedFile=function(){return this.$tree?this.$tree.jstree("get_selected"):null};h.prototype._getSelectedFileOrTree=function(){var a=this.getSelectedFile();return a&&0<a.length?a:this.$tree};h.prototype.selectFile=function(a){if(this.$tree){a=p(this.data,a);var b=this.getSelectedFile();b=(b=b&&b.data("path"))&&p(this.data,(new E.default(b)).path.getComponents());
  a&&a!==b&&this.$tree.jstree("deselect_all").jstree("select_node","#"+a.data.attr.id)}};h.prototype.openNextFile=function(){if(this.$tree){var a=n.default.jstree._reference(this.$tree),b=this._getSelectedFileOrTree();(a=y(a,a._get_next,a._get_next(b)))&&a.length&&a.find("a").focus().click()}};h.prototype.openPrevFile=function(){if(this.$tree){var a=n.default.jstree._reference(this.$tree),b=this._getSelectedFileOrTree();(a=B(a,a._get_prev(b)))&&a.length&&a.find("a").focus().click()}};q.default={_openTree:u,
  DiffTree:h,computeTree:A,flattenTree:v,compareTreeNodes:z,getNodeToSelect:p,getPathFromRoot:x};F.exports=q["default"]});