UNPKG

7.79 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("primeng/api"),require("primeng/inputtext"),require("@angular/forms")):"function"==typeof define&&define.amd?define("primeng/chips",["exports","@angular/core","@angular/common","primeng/api","primeng/inputtext","@angular/forms"],e):e(((t=t||self).primeng=t.primeng||{},t.primeng.chips={}),t.ng.core,t.ng.common,t.primeng.api,t.primeng.inputtext,t.ng.forms)}(this,(function(t,e,i,n,o,l){"use strict";var a=this&&this.__decorate||function(t,e,i,n){var o,l=arguments.length,a=l<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(a=(l<3?o(a):l>3?o(e,i,a):o(e,i))||a);return l>3&&a&&Object.defineProperty(e,i,a),a},u=this&&this.__read||function(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,o,l=i.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=l.next()).done;)a.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(i=l.return)&&i.call(l)}finally{if(o)throw o.error}}return a},p=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(u(arguments[e]));return t},r={provide:l.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return s})),multi:!0},s=function(){function t(t){this.el=t,this.allowDuplicate=!0,this.onAdd=new e.EventEmitter,this.onRemove=new e.EventEmitter,this.onFocus=new e.EventEmitter,this.onBlur=new e.EventEmitter,this.onChipClick=new e.EventEmitter,this.onModelChange=function(){},this.onModelTouched=function(){}}return t.prototype.ngAfterContentInit=function(){var t=this;this.templates.forEach((function(e){switch(e.getType()){case"item":default:t.itemTemplate=e.template}}))},t.prototype.onClick=function(){this.inputViewChild.nativeElement.focus()},t.prototype.onInput=function(){this.updateFilledState()},t.prototype.onPaste=function(t){var e=this;this.separator&&((t.clipboardData||window.clipboardData).getData("Text").split(this.separator).forEach((function(i){e.addItem(t,i,!0)})),this.inputViewChild.nativeElement.value="");this.updateFilledState()},t.prototype.updateFilledState=function(){this.value&&0!==this.value.length?this.filled=!0:this.filled=this.inputViewChild.nativeElement&&""!=this.inputViewChild.nativeElement.value},t.prototype.onItemClick=function(t,e){this.onChipClick.emit({originalEvent:t,value:e})},t.prototype.writeValue=function(t){this.value=t,this.updateMaxedOut()},t.prototype.registerOnChange=function(t){this.onModelChange=t},t.prototype.registerOnTouched=function(t){this.onModelTouched=t},t.prototype.setDisabledState=function(t){this.disabled=t},t.prototype.resolveFieldData=function(t,e){if(t&&e){if(-1==e.indexOf("."))return t[e];for(var i=e.split("."),n=t,o=0,l=i.length;o<l;++o)n=n[i[o]];return n}return null},t.prototype.onInputFocus=function(t){this.focus=!0,this.onFocus.emit(t)},t.prototype.onInputBlur=function(t){this.focus=!1,this.addOnBlur&&this.inputViewChild.nativeElement.value&&this.addItem(t,this.inputViewChild.nativeElement.value,!1),this.onModelTouched(),this.onBlur.emit(t)},t.prototype.removeItem=function(t,e){if(!this.disabled){var i=this.value[e];this.value=this.value.filter((function(t,i){return i!=e})),this.onModelChange(this.value),this.onRemove.emit({originalEvent:t,value:i}),this.updateFilledState(),this.updateMaxedOut()}},t.prototype.addItem=function(t,e,i){this.value=this.value||[],e&&e.trim().length&&(this.allowDuplicate||-1===this.value.indexOf(e))&&(this.value=p(this.value,[e]),this.onModelChange(this.value),this.onAdd.emit({originalEvent:t,value:e})),this.updateFilledState(),this.updateMaxedOut(),this.inputViewChild.nativeElement.value="",i&&t.preventDefault()},t.prototype.onKeydown=function(t){switch(t.which){case 8:if(0===this.inputViewChild.nativeElement.value.length&&this.value&&this.value.length>0){this.value=p(this.value);var e=this.value.pop();this.onModelChange(this.value),this.onRemove.emit({originalEvent:t,value:e}),this.updateFilledState()}break;case 13:this.addItem(t,this.inputViewChild.nativeElement.value,!0);break;case 9:this.addOnTab&&""!==this.inputViewChild.nativeElement.value&&this.addItem(t,this.inputViewChild.nativeElement.value,!0);break;default:this.max&&this.value&&this.max===this.value.length?t.preventDefault():this.separator&&","===this.separator&&188===t.which&&this.addItem(t,this.inputViewChild.nativeElement.value,!0)}},t.prototype.updateMaxedOut=function(){this.inputViewChild&&this.inputViewChild.nativeElement&&(this.max&&this.value&&this.max===this.value.length?this.inputViewChild.nativeElement.disabled=!0:this.inputViewChild.nativeElement.disabled=this.disabled||!1)},t.ctorParameters=function(){return[{type:e.ElementRef}]},a([e.Input()],t.prototype,"style",void 0),a([e.Input()],t.prototype,"styleClass",void 0),a([e.Input()],t.prototype,"disabled",void 0),a([e.Input()],t.prototype,"field",void 0),a([e.Input()],t.prototype,"placeholder",void 0),a([e.Input()],t.prototype,"max",void 0),a([e.Input()],t.prototype,"ariaLabelledBy",void 0),a([e.Input()],t.prototype,"tabindex",void 0),a([e.Input()],t.prototype,"inputId",void 0),a([e.Input()],t.prototype,"allowDuplicate",void 0),a([e.Input()],t.prototype,"inputStyle",void 0),a([e.Input()],t.prototype,"inputStyleClass",void 0),a([e.Input()],t.prototype,"addOnTab",void 0),a([e.Input()],t.prototype,"addOnBlur",void 0),a([e.Input()],t.prototype,"separator",void 0),a([e.Output()],t.prototype,"onAdd",void 0),a([e.Output()],t.prototype,"onRemove",void 0),a([e.Output()],t.prototype,"onFocus",void 0),a([e.Output()],t.prototype,"onBlur",void 0),a([e.Output()],t.prototype,"onChipClick",void 0),a([e.ViewChild("inputtext")],t.prototype,"inputViewChild",void 0),a([e.ContentChildren(n.PrimeTemplate)],t.prototype,"templates",void 0),t=a([e.Component({selector:"p-chips",template:'\n <div [ngClass]="\'ui-chips ui-widget\'" [ngStyle]="style" [class]="styleClass" (click)="onClick()">\n <ul [ngClass]="{\'ui-inputtext ui-state-default ui-corner-all\':true,\'ui-state-focus\':focus,\'ui-state-disabled\':disabled}">\n <li #token *ngFor="let item of value; let i = index;" class="ui-chips-token ui-state-highlight ui-corner-all" (click)="onItemClick($event, item)">\n <span *ngIf="!disabled" class="ui-chips-token-icon pi pi-fw pi-times" (click)="removeItem($event,i)"></span>\n <span *ngIf="!itemTemplate" class="ui-chips-token-label">{{field ? resolveFieldData(item,field) : item}}</span>\n <ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: item}"></ng-container>\n </li>\n <li class="ui-chips-input-token">\n <input #inputtext type="text" [attr.id]="inputId" [attr.placeholder]="(value && value.length ? null : placeholder)" [attr.tabindex]="tabindex" (keydown)="onKeydown($event)"\n (input)="onInput()" (paste)="onPaste($event)" [attr.aria-labelledby]="ariaLabelledBy" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" [disabled]="disabled" [ngStyle]="inputStyle" [class]="inputStyleClass">\n </li>\n </ul>\n </div>\n ',host:{"[class.ui-inputwrapper-filled]":"filled","[class.ui-inputwrapper-focus]":"focus"},providers:[r],changeDetection:e.ChangeDetectionStrategy.Default})],t)}(),d=function(){function t(){}return t=a([e.NgModule({imports:[i.CommonModule,o.InputTextModule,n.SharedModule],exports:[s,o.InputTextModule,n.SharedModule],declarations:[s]})],t)}();t.CHIPS_VALUE_ACCESSOR=r,t.Chips=s,t.ChipsModule=d,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=primeng-chips.umd.min.js.map
\No newline at end of file