UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 9.1 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/constants"),require("@taiga-ui/kit/tokens"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("@taiga-ui/kit/internal/primitive-calendar-range")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/calendar-range",["exports","@angular/core","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/constants","@taiga-ui/kit/tokens","rxjs","rxjs/operators","@angular/common","@taiga-ui/kit/internal/primitive-calendar-range"],t):t(((e=e||self)["taiga-ui"]=e["taiga-ui"]||{},e["taiga-ui"].kit=e["taiga-ui"].kit||{},e["taiga-ui"].kit.components=e["taiga-ui"].kit.components||{},e["taiga-ui"].kit.components["calendar-range"]={}),e.ng.core,e.cdk,e.core$1,e["taiga-ui"].kit.constants,e["taiga-ui"].kit.tokens,e.rxjs,e.rxjs.operators,e.ng.common,e["taiga-ui"].kit.internal["primitive-calendar-range"])}(this,(function(e,t,n,a,i,r,o,u,l,p){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function d(e,t,n,a){var i,r=arguments.length,o=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,a);else for(var u=e.length-1;u>=0;u--)(i=e[u])&&(o=(r<3?i(o):r>3?i(t,n,o):i(t,n))||o);return r>3&&o&&Object.defineProperty(t,n,o),o}function c(e,t){return function(n,a){t(n,a,e)}}function m(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var a,i,r=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(a=r.next()).done;)o.push(a.value)}catch(e){i={error:e}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return o}var s=function(){function e(e,r,o,l){var p=this;this.otherDateText$=l,this.defaultViewedMonth=n.TuiMonth.currentLocal(),this.disabledItemHandler=n.ALWAYS_FALSE_HANDLER,this.markerHandler=a.TUI_DEFAULT_MARKER_HANDLER,this.items=[],this.min=n.TUI_FIRST_DAY,this.max=n.TUI_LAST_DAY,this.minLength=null,this.maxLength=null,this.rangeChange=new t.EventEmitter,this.value=null,this.maxLengthMapper=i.MAX_DAY_RANGE_LENGTH_MAPPER,this.monthShiftMapper=function(e){return e.append({month:1})},this.mapper=function(e,t,n,a,i){return function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(m(arguments[t]));return e}(e.filter((function(e){return(null===a||e.range.from.append(a).daySameOrBefore(e.range.to))&&e.range.to.daySameOrAfter(t)&&(null===n||e.range.from.daySameOrBefore(n))})),[i])},e&&e.pipe(n.watch(r),u.takeUntil(o)).subscribe((function(e){p.value=e}))}return Object.defineProperty(e.prototype,"calculatedDisabledItemHandler",{get:function(){return this.calculateDisabledItemHandler(this.disabledItemHandler,this.value,this.minLength)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"computedMonth",{get:function(){return this.value?this.value.to:this.defaultViewedMonth},enumerable:!0,configurable:!0}),e.prototype.isItemActive=function(e){var t=this.activePeriod;return"string"==typeof e&&null===t||t===e},e.prototype.onRangeChange=function(e){this.updateValue(e)},e.prototype.onDayClick=function(e){var t=this.value;null!==t&&t.isSingleDay?this.updateValue(n.TuiDayRange.sort(t.from,e)):this.value=new n.TuiDayRange(e,e)},e.prototype.onItemSelect=function(e){"string"==typeof e?null!==this.activePeriod&&this.updateValue(null):this.updateValue(e.range.dayLimit(this.min,this.max))},e.prototype.updateValue=function(e){this.value=e,this.rangeChange.emit(e)},Object.defineProperty(e.prototype,"activePeriod",{get:function(){var e=this;return this.items.find((function(t){return n.nullableSame(e.value,t.range,(function(t,n){return t.from.daySame(n.from.dayLimit(e.min,e.max))&&t.to.daySame(n.to.dayLimit(e.min,e.max))}))}))||null},enumerable:!0,configurable:!0}),e.prototype.calculateDisabledItemHandler=function(e,t,n){return function(a){if(!t||!t.isSingleDay||!n)return e(a);var i=t.from.append(n,!0).append({day:1}),r=t.from.append(n).append({day:-1});return i.dayBefore(a)&&r.dayAfter(a)||e(a)}},e.ctorParameters=function(){return[{type:o.Observable,decorators:[{type:t.Inject,args:[r.TUI_CALENDAR_DATA_STREAM]},{type:t.Optional}]},{type:t.ChangeDetectorRef,decorators:[{type:t.Inject,args:[t.ChangeDetectorRef]}]},{type:n.TuiDestroyService,decorators:[{type:t.Inject,args:[n.TuiDestroyService]}]},{type:o.Observable,decorators:[{type:t.Inject,args:[r.TUI_OTHER_DATE_TEXT]}]}]},d([t.Input(),n.tuiDefaultProp()],e.prototype,"defaultViewedMonth",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"disabledItemHandler",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"markerHandler",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"items",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"min",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"max",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"minLength",void 0),d([t.Input(),n.tuiDefaultProp()],e.prototype,"maxLength",void 0),d([t.Output()],e.prototype,"rangeChange",void 0),d([n.tuiPure],e.prototype,"calculateDisabledItemHandler",null),e=d([t.Component({selector:"tui-calendar-range",template:'<tui-primitive-calendar-range\n *ngIf="!items.length; else presets"\n automation-id="tui-calendar-range__calendars"\n tuiPreventDefault="mousedown"\n [markerHandler]="markerHandler"\n [min]="min | tuiMapper: maxLengthMapper: value: maxLength: true"\n [max]="max | tuiMapper: maxLengthMapper: value: maxLength: false"\n [defaultViewedMonthFirst]="defaultViewedMonth"\n [defaultViewedMonthSecond]="defaultViewedMonth | tuiMapper : monthShiftMapper"\n [disabledItemHandler]="calculatedDisabledItemHandler"\n [value]="value"\n (dayClick)="onDayClick($event)"\n></tui-primitive-calendar-range>\n<ng-template #presets>\n <div class="wrapper">\n <tui-calendar\n automation-id="tui-calendar-range__calendar"\n tuiPreventDefault="mousedown"\n [value]="value"\n [markerHandler]="markerHandler"\n [min]="min | tuiMapper: maxLengthMapper: value: maxLength: true"\n [max]="max | tuiMapper: maxLengthMapper: value: maxLength: false"\n [month]="computedMonth"\n [disabledItemHandler]="calculatedDisabledItemHandler"\n (dayClick)="onDayClick($event)"\n ></tui-calendar>\n <tui-data-list\n role="menu"\n automation-id="tui-calendar-range__menu"\n class="menu"\n >\n <button\n *ngFor="let item of items | tuiMapper : mapper : min : max : minLength : (otherDateText$ | async)"\n tuiOption\n tuiPreventDefault="mousedown"\n role="menuitemradio"\n automation-id="tui-calendar-range__menu__item"\n [attr.aria-checked]="isItemActive(item)"\n (keydown.enter.prevent)="onItemSelect(item)"\n (keydown.space.prevent)="onItemSelect(item)"\n (click)="onItemSelect(item)"\n >\n {{item}}\n <tui-svg\n *ngIf="isItemActive(item)"\n automation-id="tui-calendar-range__checkmark"\n class="checkmark"\n src="tuiIconCheck"\n ></tui-svg>\n </button>\n </tui-data-list>\n </div>\n</ng-template>\n',changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[n.TuiDestroyService],styles:[":host{display:block}.wrapper{display:flex}.menu{width:176px;border-left:1px solid var(--tui-base-03)}.checkmark{margin-left:auto;width:16px;height:16px}"]}),c(0,t.Inject(r.TUI_CALENDAR_DATA_STREAM)),c(0,t.Optional()),c(1,t.Inject(t.ChangeDetectorRef)),c(2,t.Inject(n.TuiDestroyService)),c(3,t.Inject(r.TUI_OTHER_DATE_TEXT))],e)}(),f=function(){function e(){}return e=d([t.NgModule({imports:[l.CommonModule,n.TuiMapperPipeModule,n.TuiPreventDefaultModule,a.TuiCalendarModule,a.TuiCalendarModule,a.TuiSvgModule,a.TuiDataListModule,p.TuiPrimitiveCalendarRangeModule],declarations:[s],exports:[s]})],e)}();e.TuiCalendarRangeComponent=s,e.TuiCalendarRangeModule=f,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-components-calendar-range.umd.min.js.map