@taiga-ui/kit
Version:
Taiga UI Angular main components kit
16 lines (14 loc) • 10.7 kB
JavaScript
!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/providers"),require("@taiga-ui/kit/tokens"),require("@taiga-ui/kit/utils/mask"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("@taiga-ui/kit/directives"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/input-time",["exports","@angular/core","@angular/forms","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/providers","@taiga-ui/kit/tokens","@taiga-ui/kit/utils/mask","rxjs","rxjs/operators","@angular/common","@taiga-ui/kit/directives","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-time"]={}),e.ng.core,e.ng.forms,e.cdk,e.core$1,e["taiga-ui"].kit.providers,e["taiga-ui"].kit.tokens,e["taiga-ui"].kit.utils.mask,e.rxjs,e.rxjs.operators,e.ng.common,e["taiga-ui"].kit.directives,e.angular2TextMask)}(this,(function(e,t,i,n,o,r,u,a,s,l,c,p,d){"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 f=function(e,t){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function m(e,t,i,n){var o,r=arguments.length,u=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(u=(r<3?o(u):r>3?o(t,i,u):o(t,i))||u);return r>3&&u&&Object.defineProperty(t,i,u),u}function h(e,t){return function(i,n){t(i,n,e)}}var g=function(e){function c(t,i,o,r){var u=e.call(this,t,i)||this;return u.textfieldSize=o,u.timeTexts$=r,u.disabledItemHandler=n.ALWAYS_FALSE_HANDLER,u.items=[],u.itemSize="m",u.strict=!1,u.mode="HH:MM",u.open=!1,u}var p;return function(e,t){function i(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(c,e),p=c,Object.defineProperty(c.prototype,"nativeFocusableElement",{get:function(){return this.textfield?this.textfield.nativeFocusableElement:null},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"focused",{get:function(){return n.isNativeFocused(this.nativeFocusableElement)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"filtered",{get:function(){return this.filter(this.items,this.mode,this.computedSearch)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"textMaskOptions",{get:function(){return this.calculateMask(this.mode)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"computedValue",{get:function(){return this.value?this.value.toString(this.mode):this.nativeValue},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"computedSearch",{get:function(){return this.computedValue.length!==this.mode.length?this.computedValue:""},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"interactive",{get:function(){return!this.disabled&&!this.readOnly},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"innerPseudoFocused",{get:function(){return!1!==this.pseudoFocused&&(!(!this.open&&!this.computedFocused)||null)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"icon",{get:function(){return o.sizeBigger(this.textfieldSize.size)?"tuiIconTimeLarge":"tuiIconTime"},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"nativeValue",{get:function(){return this.nativeFocusableElement?this.nativeFocusableElement.value:""},set:function(e){this.nativeFocusableElement&&(this.nativeFocusableElement.value=e)},enumerable:!0,configurable:!0}),c.prototype.getFiller$=function(e){return this.timeTexts$.pipe(l.map((function(t){return t[e]})))},c.prototype.onValueChange=function(e){this.open=!!this.items.length,e&&this.control&&this.control.updateValueAndValidity();var t=this.getMatch(e);if(void 0===t)if(e.length===this.mode.length){var i=n.TuiTime.fromString(e);this.updateValue(this.strict?this.findNearestTimeFromItems(i):i)}else this.updateValue(null);else this.updateValue(t)},c.prototype.onFocused=function(e){var t=this;if(this.updateFocused(e),!e&&null===this.value&&""!==this.nativeValue&&"HH:MM"!==this.mode){var i=n.TuiTime.fromString(this.nativeValue);this.updateValue(i),setTimeout((function(){(t.nativeValue.endsWith(".")||t.nativeValue.endsWith(":"))&&(t.nativeValue=t.nativeValue.slice(0,-1))}))}},c.prototype.onHovered=function(e){this.updateHovered(e)},c.prototype.onArrowUp=function(e){this.items.length||this.processArrow(e,1)},c.prototype.onArrowDown=function(e){this.items.length||this.processArrow(e,-1)},c.prototype.onClick=function(){this.open=!this.open},c.prototype.onMenuClick=function(e){this.focusInput(),this.updateValue(e)},c.prototype.onOpen=function(e){this.open=e},c.prototype.writeValue=function(t){e.prototype.writeValue.call(this,t),this.nativeValue=t?this.computedValue:""},c.prototype.findNearestTimeFromItems=function(e){return this.items.reduce((function(t,i){return Math.abs(i.toAbsoluteMilliseconds()-e.toAbsoluteMilliseconds())<Math.abs(t.toAbsoluteMilliseconds()-e.toAbsoluteMilliseconds())?i:t}))},c.prototype.getMatch=function(e){return this.items.find((function(t){return n.TUI_STRICT_MATCHER(t,e)}))},c.prototype.close=function(){this.open=!1},c.prototype.processArrow=function(e,t){var i=e.target;if(!this.readOnly&&i instanceof HTMLInputElement){var n=i.selectionStart||0;this.shiftTime(this.calculateShift(n,t)),i.setSelectionRange(n,n),e.preventDefault()}},c.prototype.calculateShift=function(e,t){return e<=2?{hours:t}:e<=5?{minutes:t}:e<=8?{seconds:t}:{ms:t}},c.prototype.shiftTime=function(e){if(null!==this.value){var t=this.value.shift(e);this.nativeValue=t.toString(this.mode),this.updateValue(t)}},c.prototype.focusInput=function(e){void 0===e&&(e=!1),this.nativeFocusableElement&&(n.setNativeFocused(this.nativeFocusableElement,!0,e),this.close())},c.prototype.calculateMask=function(e){return{mask:a.tuiCreateTimeMask(e),pipe:a.tuiCreateAutoCorrectedTimePipe(e),guide:!1}},c.prototype.filter=function(e,t,i){return e.filter((function(e){return e.toString(t).includes(i)}))},c.ctorParameters=function(){return[{type:i.NgControl,decorators:[{type:t.Optional},{type:t.Self},{type:t.Inject,args:[i.NgControl]}]},{type:t.ChangeDetectorRef,decorators:[{type:t.Inject,args:[t.ChangeDetectorRef]}]},{type:o.TuiTextfieldSizeDirective,decorators:[{type:t.Inject,args:[o.TUI_TEXTFIELD_SIZE]}]},{type:s.Observable,decorators:[{type:t.Inject,args:[u.TUI_TIME_TEXTS]}]}]},m([t.Input(),n.tuiDefaultProp()],c.prototype,"disabledItemHandler",void 0),m([t.Input(),n.tuiDefaultProp()],c.prototype,"items",void 0),m([t.Input(),n.tuiDefaultProp()],c.prototype,"itemSize",void 0),m([t.Input(),n.tuiDefaultProp()],c.prototype,"strict",void 0),m([t.Input(),n.tuiDefaultProp()],c.prototype,"mode",void 0),m([t.ViewChild(o.TuiPrimitiveTextfieldComponent)],c.prototype,"textfield",void 0),m([n.tuiPure],c.prototype,"getFiller$",null),m([t.HostListener("click")],c.prototype,"onClick",null),m([n.tuiPure],c.prototype,"calculateMask",null),m([n.tuiPure],c.prototype,"filter",null),c=p=m([t.Component({selector:"tui-input-time",template:'<tui-hosted-dropdown\n class="wrapper"\n [canOpen]="interactive && !!filtered.length"\n [content]="dropdownContent"\n [open]="open && !!filtered.length"\n (openChange)="onOpen($event)"\n (focusedChange)="onFocused($event)"\n>\n <tui-primitive-textfield\n class="textfield"\n tuiValueAccessor\n [filler]="getFiller$(mode) | async"\n [nativeId]="nativeId"\n [pseudoFocused]="innerPseudoFocused"\n [pseudoHovered]="pseudoHovered"\n [pseudoPressed]="pseudoPressed"\n [invalid]="computedInvalid"\n [focusable]="focusable"\n [disabled]="disabled"\n [readOnly]="readOnly"\n [textMask]="textMaskOptions"\n [iconContent]="icon"\n [value]="computedValue"\n (valueChange)="onValueChange($event)"\n (hoveredChange)="onHovered($event)"\n (keydown.arrowUp)="onArrowUp($event)"\n (keydown.arrowDown)="onArrowDown($event)"\n >\n <ng-content></ng-content>\n </tui-primitive-textfield>\n</tui-hosted-dropdown>\n<ng-template #dropdownContent>\n <tui-data-list automation-id="tui-input-time__dropdown">\n <button\n *ngFor="let item of filtered"\n tuiOption\n automation-id="tui-input-time__item"\n [size]="itemSize"\n [disabled]="disabledItemHandler(item)"\n (click)="onMenuClick(item)"\n >\n {{item}}\n </button>\n </tui-data-list>\n</ng-template>\n',changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:n.TUI_FOCUSABLE_ITEM_ACCESSOR,useExisting:t.forwardRef((function(){return p}))},r.FIXED_DROPDOWN_CONTROLLER_PROVIDER],styles:[":host{display:block;border-radius:var(--tui-radius-m)}:host._disabled{pointer-events:none}.wrapper{display:block;border-radius:inherit}.textfield{border-radius:inherit}"]}),h(0,t.Optional()),h(0,t.Self()),h(0,t.Inject(i.NgControl)),h(1,t.Inject(t.ChangeDetectorRef)),h(2,t.Inject(o.TUI_TEXTFIELD_SIZE)),h(3,t.Inject(u.TUI_TIME_TEXTS))],c)}(n.AbstractTuiNullableControl),v=function(){function e(){}return e=m([t.NgModule({imports:[c.CommonModule,d.TextMaskModule,o.TuiDataListModule,o.TuiHostedDropdownModule,o.TuiPrimitiveTextfieldModule,p.TuiValueAccessorModule],declarations:[g],exports:[g]})],e)}();e.TuiInputTimeComponent=g,e.TuiInputTimeModule=v,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=taiga-ui-kit-components-input-time.umd.min.js.map