UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 11.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/constants"),require("@taiga-ui/kit/providers"),require("@taiga-ui/kit/tokens"),require("@taiga-ui/kit/utils/mask"),require("@taiga-ui/kit/utils/miscellaneous"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("@taiga-ui/kit/directives"),require("@tinkoff/ng-polymorpheus"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/input-date-time",["exports","@angular/core","@angular/forms","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/constants","@taiga-ui/kit/providers","@taiga-ui/kit/tokens","@taiga-ui/kit/utils/mask","@taiga-ui/kit/utils/miscellaneous","rxjs","rxjs/operators","@angular/common","@taiga-ui/kit/directives","@tinkoff/ng-polymorpheus","angular2-text-mask"],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["input-date-time"]={}),e.ng.core,e.ng.forms,e.cdk,e.core$1,e["taiga-ui"].kit.constants,e["taiga-ui"].kit.providers,e["taiga-ui"].kit.tokens,e["taiga-ui"].kit.utils.mask,e["taiga-ui"].kit.utils.miscellaneous,e.rxjs,e.rxjs.operators,e.ng.common,e["taiga-ui"].kit.directives,e.ngPolymorpheus,e.angular2TextMask)}(this,(function(e,t,n,i,o,r,a,u,l,s,c,p,d,f,h,g){"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. ***************************************************************************** */var m=function(e,t){return(m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function y(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a}function v(e,t){return function(n,i){t(n,i,e)}}function T(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,o,r=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function b(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(T(arguments[t]));return e}var I=s.TuiReplayControlValueChangesFactory,k=function(e){function s(t,n,o,r,a){var u=e.call(this,t,n)||this;return u.textfieldSize=o,u.dateFiller=r,u.timeTexts$=a,u.min=i.TUI_FIRST_DAY,u.max=i.TUI_LAST_DAY,u.disabledItemHandler=i.ALWAYS_FALSE_HANDLER,u.defaultActiveYearMonth=i.TuiMonth.currentLocal(),u.timeMode="HH:MM",u.open=!1,u.month=null,u}var d;return function(e,t){function n(){this.constructor=e}m(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(s,e),d=s,Object.defineProperty(s.prototype,"fillerLength",{get:function(){return this.dateFiller.length+r.DATE_TIME_SEPARATOR.length+this.timeMode.length},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"textMaskOptions",{get:function(){return this.calculateMask(this.value[0],this.min,this.max,this.timeMode,this.dateFiller)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"nativeFocusableElement",{get:function(){return this.textfield?this.textfield.nativeFocusableElement:null},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"focused",{get:function(){return!!this.textfield&&this.textfield.focused},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"calendarIcon",{get:function(){return o.sizeBigger(this.textfieldSize.size)?"tuiIconCalendarLarge":"tuiIconCalendar"},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"computedValue",{get:function(){var e=this.value,t=this.nativeValue,n=this.focused,i=this.touched,o=T(e,2),a=o[0],u=o[1];return a&&!t||a&&t.length===this.dateFiller.length||a&&u?""+a.toString()+r.DATE_TIME_SEPARATOR+(u?u.toString(this.timeMode):""):i||n?t:null!==a?a.toString():""},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"calendarValue",{get:function(){return this.value[0]},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"computedActiveYearMonth",{get:function(){return this.month||this.value[0]||this.defaultActiveYearMonth},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"nativeValue",{get:function(){return this.nativeFocusableElement?this.nativeFocusableElement.value:""},set:function(e){this.nativeFocusableElement&&(this.nativeFocusableElement.value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"canOpen",{get:function(){return!this.computedDisabled&&!this.readOnly},enumerable:!0,configurable:!0}),s.prototype.getFiller$=function(e,t){return this.timeTexts$.pipe(p.map((function(n){return""+e+r.DATE_TIME_SEPARATOR+n[t]})))},s.prototype.onClick=function(){this.open=!this.open},s.prototype.onValueChange=function(e){if(e.length<this.dateFiller.length)this.updateValue([null,null]);else{var t=T(e.split(r.DATE_TIME_SEPARATOR),2),n=t[0],o=t[1],a=i.TuiDay.normalizeParse(n),u=o&&o.length===this.timeMode.length?i.TuiTime.fromString(o):null;null!==a&&(this.open=!1),this.updateValue([a,u])}},s.prototype.onDayClick=function(e){this.updateValue([e,this.value[1]]),this.open=!1},s.prototype.onHovered=function(e){this.updateHovered(e)},s.prototype.onMonthChange=function(e){this.month=e},s.prototype.onOpenChange=function(e){this.open=e},s.prototype.onFocused=function(e){var t=this;if(this.updateFocused(e),!(e||null===this.value[0]||null!==this.value[1]||this.nativeValue.length<=this.fillerLength+r.DATE_TIME_SEPARATOR.length||"HH:MM"===this.timeMode)){var n=T(this.nativeValue.split(r.DATE_TIME_SEPARATOR),2)[1];if(n){var o=i.TuiTime.fromString(n);this.updateValue([this.value[0],o]),setTimeout((function(){(t.nativeValue.endsWith(".")||t.nativeValue.endsWith(":"))&&(t.nativeValue=t.nativeValue.slice(0,-1))}))}}},s.prototype.setDisabledState=function(){e.prototype.setDisabledState.call(this),this.open=!1},s.prototype.writeValue=function(t){e.prototype.writeValue.call(this,t),this.nativeValue=t&&(t[0]||t[1])?this.computedValue:""},s.prototype.getFallbackValue=function(){return[null,null]},s.prototype.valueIdenticalComparator=function(e,t){return i.nullableSame(e[0],t[0],(function(e,t){return e.daySame(t)}))&&i.nullableSame(e[1],t[1],(function(e,t){return e.toString()===t.toString()}))},s.prototype.calculateMask=function(e,t,n,i,o){return{mask:b(r.TUI_DATE_MASK,[","," "],l.tuiCreateTimeMask(i)),pipe:l.tuiCreateAutoCorrectedDateTimePipe({value:e,min:t,max:n,filler:o},i),guide:!1}},s.ctorParameters=function(){return[{type:n.NgControl,decorators:[{type:t.Optional},{type:t.Self},{type:t.Inject,args:[n.NgControl]}]},{type:t.ChangeDetectorRef,decorators:[{type:t.Inject,args:[t.ChangeDetectorRef]}]},{type:o.TuiTextfieldSizeDirective,decorators:[{type:t.Inject,args:[o.TUI_TEXTFIELD_SIZE]}]},{type:String,decorators:[{type:t.Inject,args:[i.TUI_DATE_FILLER]}]},{type:c.Observable,decorators:[{type:t.Inject,args:[u.TUI_TIME_TEXTS]}]}]},y([t.Input(),i.tuiDefaultProp()],s.prototype,"min",void 0),y([t.Input(),i.tuiDefaultProp()],s.prototype,"max",void 0),y([t.Input(),i.tuiDefaultProp()],s.prototype,"disabledItemHandler",void 0),y([t.Input(),i.tuiDefaultProp()],s.prototype,"defaultActiveYearMonth",void 0),y([t.Input(),i.tuiDefaultProp()],s.prototype,"timeMode",void 0),y([t.ViewChild(o.TuiPrimitiveTextfieldComponent)],s.prototype,"textfield",void 0),y([i.tuiPure],s.prototype,"getFiller$",null),y([t.HostListener("click")],s.prototype,"onClick",null),y([i.tuiPure],s.prototype,"calculateMask",null),s=d=y([t.Component({selector:"tui-input-date-time",template:'<tui-hosted-dropdown\n class="hosted"\n [canOpen]="canOpen"\n [content]="dropdown"\n [open]="open && canOpen"\n (openChange)="onOpenChange($event)"\n>\n <tui-primitive-textfield\n class="textfield"\n tuiValueAccessor\n [pseudoFocused]="pseudoFocused"\n [pseudoHovered]="pseudoHovered"\n [invalid]="computedInvalid"\n [filler]="getFiller$(dateFiller, timeMode) | async"\n [nativeId]="nativeId"\n [readOnly]="readOnly"\n [iconContent]="calendarIcon"\n [disabled]="disabled"\n [textMask]="textMaskOptions"\n [value]="computedValue"\n (valueChange)="onValueChange($event)"\n (hoveredChange)="onHovered($event)"\n (focusedChange)="onFocused($event)"\n >\n <ng-content></ng-content>\n </tui-primitive-textfield>\n\n <ng-template #dropdown="polymorpheus" polymorpheus>\n <tui-calendar\n tuiPreventDefault="mousedown"\n [min]="min"\n [max]="max"\n [disabledItemHandler]="disabledItemHandler"\n [month]="computedActiveYearMonth"\n [value]="calendarValue"\n (dayClick)="onDayClick($event)"\n (monthChange)="onMonthChange($event)"\n ></tui-calendar>\n </ng-template>\n</tui-hosted-dropdown>\n',changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:i.TUI_FOCUSABLE_ITEM_ACCESSOR,useExisting:t.forwardRef((function(){return d}))},{provide:u.TUI_CALENDAR_DATA_STREAM,deps:[[new t.Optional,new t.Self,n.NgControl]],useFactory:I},a.LEFT_ALIGNED_DROPDOWN_CONTROLLER_PROVIDER],styles:[":host{display:block;border-radius:var(--tui-radius-m)}.hosted{display:block;border-radius:inherit}.textfield{border-radius:inherit}.icon{position:relative;cursor:pointer}.button{display:flex;height:44px;justify-content:center;box-shadow:inset 0 1px var(--tui-base-03)}"]}),v(0,t.Optional()),v(0,t.Self()),v(0,t.Inject(n.NgControl)),v(1,t.Inject(t.ChangeDetectorRef)),v(2,t.Inject(o.TUI_TEXTFIELD_SIZE)),v(3,t.Inject(i.TUI_DATE_FILLER)),v(4,t.Inject(u.TUI_TIME_TEXTS))],s)}(i.AbstractTuiControl),M=function(){function e(){}return e=y([t.NgModule({imports:[d.CommonModule,g.TextMaskModule,h.PolymorpheusModule,i.TuiPreventDefaultModule,o.TuiCalendarModule,o.TuiSvgModule,o.TuiLinkModule,o.TuiHostedDropdownModule,o.TuiPrimitiveTextfieldModule,f.TuiValueAccessorModule],declarations:[k],exports:[k]})],e)}();e.TuiInputDateTimeComponent=k,e.TuiInputDateTimeModule=M,e.ɵ0=I,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-components-input-date-time.umd.min.js.map