azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 6.03 kB
JavaScript
import{__spreadArray}from"tslib";import{ObservableArray}from"../Core/Observable";import{ListBoxItemType}from"../ListBox";var GroupedItemProvider=function(){function e(e,t,r,i){this.listItems=new ObservableArray,this.internalGroups=__spreadArray([],t,!0),this.groupedItems=[[]];for(var s=0;s<this.internalGroups.length;s++)this.groupedItems.push([]);this.addItems(e);for(s=0;s<this.internalGroups.length;s++)this.internalGroups[s].loading&&this.setGroupLoading(this.internalGroups[s].id,!0,this.internalGroups[s].loadingItem);this.omitDividers=!!i,r&&this.addHeaders(1,this.groups.length),this.manageHeaders=!!r}return Object.defineProperty(e.prototype,"groups",{get:function(){return this.internalGroups},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.listItems.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.listItems.value},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e,t){return this.listItems.subscribe(e,t)},e.prototype.unsubscribe=function(e,t){return this.listItems.unsubscribe(e,t)},e.prototype.push=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.addItems(e),e.length},e.prototype.pushGroups=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.addGroups.apply(this,__spreadArray([this.internalGroups.length],e,!1)),this.internalGroups.length},e.prototype.pop=function(){var e=this.listItems.pop();return e&&this.removeItems([e]),e},e.prototype.removeAll=function(e){e=this.listItems.removeAll(e);return this.removeItems(e,!1),e},e.prototype.splice=function(e,t){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];var s=this.listItems.splice(e,t);return this.removeItems(s,!1),this.addItems(r,!0,e),s},e.prototype.change=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var i=this.listItems.value.slice(e,t.length);return this.removeItems(i,!1),this.addItems(t,!1),(i=this.listItems).change.apply(i,__spreadArray([e],t,!1)),t.length},e.prototype.spliceGroups=function(e,t){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];for(var s=0;s<t;s++){var o,n=e+s+1;this.groupedItems.length>n&&(this.removeItems(__spreadArray([],this.groupedItems[n],!0)),this.manageHeaders&&0<(o=this.groupedItems.findIndex(function(e){return 0<e.length}))&&this.groupedItems[o][0].type===ListBoxItemType.Divider&&this.removeItems([this.groupedItems[o][0]]),this.groupedItems.splice(n,1))}var p=this.internalGroups.splice(e,t);return this.addGroups.apply(this,__spreadArray([e],r,!1)),p},e.prototype.setGroupLoading=function(t,e,r){var i,s,o=this.groups.findIndex(function(e){return e.id===t});o<0||(i=(s=this.groupedItems[++o]).findIndex(function(e){return e.type===ListBoxItemType.Loading}),!e&&s.length&&-1<i?this.removeItems([s[i]]):e&&-1===i&&(s=r||{id:t+"-loading",type:ListBoxItemType.Loading,groupId:t},this.addItems([s])),this.groups[o-1].loading=e)},e.prototype.addHeaders=function(e,t){void 0===t&&(t=1);for(var i=this,r=e;r<e+t;r++)!function(r){var e,t=i.groups[r-1];0<i.groupedItems[r].length&&(i.groupedItems[r].find(function(e){return e.type===ListBoxItemType.Header})||i.addItems([{id:t.id+"-header",text:t.name||t.id,type:ListBoxItemType.Header,groupId:t.id}]),!i.groupedItems.some(function(e,t){return t<r&&0<e.length})||i.groupedItems[r].find(function(e){return e.type===ListBoxItemType.Divider})||i.omitDividers||i.addItems([{id:t.id+"-divider",type:ListBoxItemType.Divider,groupId:t.id}]),0<(e=i.groupedItems.findIndex(function(e,t){return r<t&&0<e.length})))&&!i.groupedItems[e].find(function(e){return e.type===ListBoxItemType.Divider})&&!i.omitDividers&&(t=i.groups[e-1],i.addItems([{id:t.id+"-divider",type:ListBoxItemType.Divider,groupId:t.id}]))}(r)},e.prototype.addGroups=function(e){for(var t,r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];(t=this.internalGroups).splice.apply(t,__spreadArray([e,0],r,!1));for(var s=[],o=0;o<r.length;o++){this.groupedItems.splice(e+o+1,0,[]);for(var n,p=this.groupedItems[0].length-1;0<=p;p--)this.groupedItems[0][p].groupId===r[o].id&&(n=this.groupedItems[0].splice(p,1)[0],this.listItems.splice(p,1),s.unshift(n))}this.addItems(s),this.manageHeaders&&this.addHeaders(e+1,r.length);for(o=0;o<r.length;o++)r[o].loading&&this.setGroupLoading(r[o].id,!0,r[o].loadingItem)},e.prototype.addItems=function(e,t,r){if(void 0===t&&(t=!0),void 0!==r)for(var i=e.length-1;0<=i;i--)this.addItem(e[i],r);else for(i=0;i<e.length;i++)this.addItem(e[i],r);t&&this.addToListItems()},e.prototype.addToListItems=function(){for(var e,t=[],r=0;r<this.groupedItems.length;r++)t.push.apply(t,this.groupedItems[r]);for(var i,s=0,o={},n=0;n<t.length;n++)this.listItems.value[s]===t[n]?(s++,i=void 0):void 0!==i?o[i].push(t[n]):o[i=s]=[t[n]];for(var p=Object.keys(o),r=p.length-1;0<=r;r--)(e=this.listItems).splice.apply(e,__spreadArray([parseInt(p[r]),0],o[parseInt(p[r])],!1))},e.prototype.addItem=function(e,t){var r=0,i=0,s=e.groupId;void 0!==s&&(r=this.internalGroups.findIndex(function(e){return e.id===s})+1);for(var o,n=0;n<r;n++)i+=this.groupedItems[n].length;e.type===ListBoxItemType.Divider?this.groupedItems[r].unshift(e):e.type===ListBoxItemType.Header?this.groupedItems[r].length&&this.groupedItems[r][0].type===ListBoxItemType.Divider?(this.groupedItems[r].splice(1,0,e),i++):this.groupedItems[r].unshift(e):(o=this.groupedItems[r].length,void 0!==t&&i<=t&&t<=i+this.groupedItems[r].length?(o=t-i,i=t):void 0!==t&&t<i?o=0:i+=this.groupedItems[r].length,this.groupedItems[r].splice(o,0,e),0<r&&1===this.groupedItems[r].length&&this.manageHeaders&&this.addHeaders(r))},e.prototype.removeItems=function(n,p){void 0===p&&(p=!0);for(var d=this,e=0;e<n.length;e++)!function(e){var t=0,r=0,i=n[e].groupId;void 0!==i&&(t=d.internalGroups.findIndex(function(e){return e.id===i})+1);for(var s=0;s<t;s++)r+=d.groupedItems[s].length;var o=d.groupedItems[t],e=o.indexOf(n[e]);o.splice(e,1),p&&d.listItems.splice(r+e,1)}(e)},e}();export{GroupedItemProvider};