azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 3.71 kB
JavaScript
import{__assign}from"tslib";import*as React from"react";import{Observable}from"../Core/Observable";!function(t){t.and="and",t.or="or"}(FilterOperatorType=FilterOperatorType||{});var FilterOperatorType,FILTER_CHANGE_EVENT="filter-changed",FILTER_APPLIED_EVENT="filter-applied",FILTER_RESET_EVENT="reset-filters",Filter=function(){function t(t,e){void 0===t&&(t={}),this.observable=e||new Observable,this.applyMode=!!t.useApplyMode,this.defaultState=__assign({},t.defaultState),this.currentState=__assign({},this.defaultState),this.customValueComparers=__assign({},t.customValueComparers),this.applyMode?this.appliedState=__assign({},this.currentState):this.appliedState=this.currentState}return t.prototype.subscribe=function(t,e){return this.observable.subscribe(t,e)},t.prototype.unsubscribe=function(t,e){this.observable.unsubscribe(t,e)},t.prototype.getState=function(){return __assign({},this.currentState)},t.prototype.getAppliedState=function(){return __assign({},this.appliedState)},t.prototype.getDefaultState=function(){return this.defaultState},t.prototype.setDefaultState=function(t){this.defaultState=t},t.prototype.setState=function(t,e){void 0===e&&(e=!1);var r=this.currentState;if(this.currentState=__assign({},t),this.applyMode||(this.appliedState=this.currentState),!e){var i,a=__assign({},t);for(i in r)t.hasOwnProperty(i)||(a[i]=null);this._triggerStateChange(a)}},t.prototype.getFilterItemState=function(t){return this.currentState[t]},t.prototype.getAppliedFilterItemState=function(t){return this.appliedState[t]},t.prototype.getFilterItemValue=function(t){t=this.currentState[t];if(t)return t.value},t.prototype.setFilterItemState=function(t,e){this.currentState[t]=e;var r={};r[t]=e,this._triggerStateChange(r)},t.prototype.reset=function(t){this.setState(this.defaultState,t=void 0===t?!1:t),t||this._raiseEventAndCallListeners(FILTER_RESET_EVENT,{})},t.prototype.resetFilterItemState=function(t){var e=this.defaultState[t];this.setFilterItemState(t,e)},t.prototype.applyChanges=function(){this.appliedState=__assign({},this.currentState),this._raiseEventAndCallListeners(FILTER_APPLIED_EVENT,this.appliedState)},t.prototype.usesApplyMode=function(){return this.applyMode},t.prototype.hasChangesToApply=function(){return!this.statesAreEqual(this.appliedState,this.currentState)},t.prototype.hasChangesToReset=function(){return!this.statesAreEqual(this.defaultState,this.currentState)},t.prototype.statesAreEqual=function(t,e){return this._checkStateEquality(t,e)&&this._checkStateEquality(e,t)},t.prototype.filterItemStatesAreEqual=function(t,e,r){return this._checkFilterItemStateEquality(t,e,r)},t.prototype._triggerStateChange=function(t){this._raiseEventAndCallListeners(FILTER_CHANGE_EVENT,t),this.applyMode||this._raiseEventAndCallListeners(FILTER_APPLIED_EVENT,t)},t.prototype._raiseEventAndCallListeners=function(t,e){this.observable.notify(e,t)},t.prototype._checkStateEquality=function(t,e){for(var r in t)if(!this._checkFilterItemStateEquality(r,t[r],e[r]))return!1;return!0},t.prototype._checkFilterItemStateEquality=function(t,e,r){var i=e&&e.value,a=r&&r.value;if(Array.isArray(i)){if(Array.isArray(a)){if(i.length!==a.length)return!1;for(var s=0;s<i.length;s++)if(!this._checkValueEquality(t,i[s],a[s]))return!1}else if(0!==i.length||a)return!1}else{if(!this._checkValueEquality(t,i,a))return!1;if(Array.isArray(a)&&0!==a.length)return!1}return!0},t.prototype._checkValueEquality=function(t,e,r){return this.customValueComparers[t]?this.customValueComparers[t](e,r):(!e||e===r)&&!!e==!!r},t}(),FilterContext=React.createContext({filter:null,filterToggled:null});export{FilterOperatorType,FILTER_CHANGE_EVENT,FILTER_APPLIED_EVENT,FILTER_RESET_EVENT,Filter,FilterContext};