primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 8.55 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).primeng=e.primeng||{},e.primeng.chips={}),e.ng.core,e.ng.common,e.primeng.api,e.primeng.inputtext,e.ng.forms)}(this,(function(e,t,i,n,l,a){"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.
***************************************************************************** */Object.create;function o(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,l,a=i.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(e){l={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(l)throw l.error}}return o}function p(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}Object.create;var u={provide:a.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return s})),multi:!0},s=function(){function e(e,i){this.el=e,this.cd=i,this.allowDuplicate=!0,this.onAdd=new t.EventEmitter,this.onRemove=new t.EventEmitter,this.onFocus=new t.EventEmitter,this.onBlur=new t.EventEmitter,this.onChipClick=new t.EventEmitter,this.onModelChange=function(){},this.onModelTouched=function(){}}return e.prototype.ngAfterContentInit=function(){var e=this;this.templates.forEach((function(t){switch(t.getType()){case"item":default:e.itemTemplate=t.template}}))},e.prototype.onClick=function(){this.inputViewChild.nativeElement.focus()},e.prototype.onInput=function(){this.updateFilledState()},e.prototype.onPaste=function(e){var t=this;this.separator&&((e.clipboardData||window.clipboardData).getData("Text").split(this.separator).forEach((function(i){t.addItem(e,i,!0)})),this.inputViewChild.nativeElement.value="");this.updateFilledState()},e.prototype.updateFilledState=function(){this.value&&0!==this.value.length?this.filled=!0:this.filled=this.inputViewChild.nativeElement&&""!=this.inputViewChild.nativeElement.value},e.prototype.onItemClick=function(e,t){this.onChipClick.emit({originalEvent:e,value:t})},e.prototype.writeValue=function(e){this.value=e,this.updateMaxedOut(),this.cd.markForCheck()},e.prototype.registerOnChange=function(e){this.onModelChange=e},e.prototype.registerOnTouched=function(e){this.onModelTouched=e},e.prototype.setDisabledState=function(e){this.disabled=e,this.cd.markForCheck()},e.prototype.resolveFieldData=function(e,t){if(e&&t){if(-1==t.indexOf("."))return e[t];for(var i=t.split("."),n=e,l=0,a=i.length;l<a;++l)n=n[i[l]];return n}return null},e.prototype.onInputFocus=function(e){this.focus=!0,this.onFocus.emit(e)},e.prototype.onInputBlur=function(e){this.focus=!1,this.addOnBlur&&this.inputViewChild.nativeElement.value&&this.addItem(e,this.inputViewChild.nativeElement.value,!1),this.onModelTouched(),this.onBlur.emit(e)},e.prototype.removeItem=function(e,t){if(!this.disabled){var i=this.value[t];this.value=this.value.filter((function(e,i){return i!=t})),this.onModelChange(this.value),this.onRemove.emit({originalEvent:e,value:i}),this.updateFilledState(),this.updateMaxedOut()}},e.prototype.addItem=function(e,t,i){this.value=this.value||[],t&&t.trim().length&&(this.allowDuplicate||-1===this.value.indexOf(t))&&(this.value=p(this.value,[t]),this.onModelChange(this.value),this.onAdd.emit({originalEvent:e,value:t})),this.updateFilledState(),this.updateMaxedOut(),this.inputViewChild.nativeElement.value="",i&&e.preventDefault()},e.prototype.onKeydown=function(e){switch(e.which){case 8:if(0===this.inputViewChild.nativeElement.value.length&&this.value&&this.value.length>0){this.value=p(this.value);var t=this.value.pop();this.onModelChange(this.value),this.onRemove.emit({originalEvent:e,value:t}),this.updateFilledState()}break;case 13:this.addItem(e,this.inputViewChild.nativeElement.value,!0);break;case 9:this.addOnTab&&""!==this.inputViewChild.nativeElement.value&&this.addItem(e,this.inputViewChild.nativeElement.value,!0);break;default:this.max&&this.value&&this.max===this.value.length?e.preventDefault():this.separator&&","===this.separator&&188===e.which&&this.addItem(e,this.inputViewChild.nativeElement.value,!0)}},e.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)},e}();s.decorators=[{type:t.Component,args:[{selector:"p-chips",template:'\n <div [ngClass]="\'p-chips p-component\'" [ngStyle]="style" [class]="styleClass" (click)="onClick()">\n <ul [ngClass]="{\'p-inputtext p-chips-multiple-container\':true,\'p-focus\':focus,\'p-disabled\':disabled}">\n <li #token *ngFor="let item of value; let i = index;" class="p-chips-token" (click)="onItemClick($event, item)">\n <ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: item}"></ng-container>\n <span *ngIf="!itemTemplate" class="p-chips-token-label">{{field ? resolveFieldData(item,field) : item}}</span>\n <span *ngIf="!disabled" class="p-chips-token-icon pi pi-times-circle" (click)="removeItem($event,i)"></span>\n </li>\n <li class="p-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.p-inputwrapper-filled]":"filled","[class.p-inputwrapper-focus]":"focus"},providers:[u],changeDetection:t.ChangeDetectionStrategy.OnPush,encapsulation:t.ViewEncapsulation.None,styles:[".p-chips{display:inline-flex}.p-chips-multiple-container{align-items:center;cursor:text;display:flex;flex-wrap:wrap;list-style-type:none;margin:0;overflow:hidden;padding:0}.p-chips-token{align-items:center;cursor:default;display:inline-flex;flex:0 0 auto}.p-chips-input-token{display:inline-flex;flex:1 1 auto}.p-chips-token-icon{cursor:pointer}.p-chips-input-token input{background-color:transparent;border:0;border-radius:0;box-shadow:none;margin:0;outline:0 none;padding:0;width:100%}.p-fluid .p-chips{display:flex}"]}]}],s.ctorParameters=function(){return[{type:t.ElementRef},{type:t.ChangeDetectorRef}]},s.propDecorators={style:[{type:t.Input}],styleClass:[{type:t.Input}],disabled:[{type:t.Input}],field:[{type:t.Input}],placeholder:[{type:t.Input}],max:[{type:t.Input}],ariaLabelledBy:[{type:t.Input}],tabindex:[{type:t.Input}],inputId:[{type:t.Input}],allowDuplicate:[{type:t.Input}],inputStyle:[{type:t.Input}],inputStyleClass:[{type:t.Input}],addOnTab:[{type:t.Input}],addOnBlur:[{type:t.Input}],separator:[{type:t.Input}],onAdd:[{type:t.Output}],onRemove:[{type:t.Output}],onFocus:[{type:t.Output}],onBlur:[{type:t.Output}],onChipClick:[{type:t.Output}],inputViewChild:[{type:t.ViewChild,args:["inputtext"]}],templates:[{type:t.ContentChildren,args:[n.PrimeTemplate]}]};var r=function(){};r.decorators=[{type:t.NgModule,args:[{imports:[i.CommonModule,l.InputTextModule,n.SharedModule],exports:[s,l.InputTextModule,n.SharedModule],declarations:[s]}]}],e.CHIPS_VALUE_ACCESSOR=u,e.Chips=s,e.ChipsModule=r,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=primeng-chips.umd.min.js.map