UNPKG

@ng-select/ng-select

Version:

Angular ng-select - All in One UI Select, Multiselect and Autocomplete

1,267 lines 133 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import { Component, forwardRef, ChangeDetectorRef, Input, Output, EventEmitter, ContentChild, TemplateRef, ViewEncapsulation, HostListener, HostBinding, ViewChild, ElementRef, ChangeDetectionStrategy, Inject, ContentChildren, QueryList, InjectionToken, Attribute } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { takeUntil, startWith, tap, debounceTime, map, filter } from 'rxjs/operators'; import { Subject, merge } from 'rxjs'; import { NgOptionTemplateDirective, NgLabelTemplateDirective, NgHeaderTemplateDirective, NgFooterTemplateDirective, NgOptgroupTemplateDirective, NgNotFoundTemplateDirective, NgTypeToSearchTemplateDirective, NgLoadingTextTemplateDirective, NgMultiLabelTemplateDirective, NgTagTemplateDirective, NgLoadingSpinnerTemplateDirective } from './ng-templates.directive'; import { ConsoleService } from './console.service'; import { isDefined, isFunction, isPromise, isObject } from './value-utils'; import { ItemsList } from './items-list'; import { KeyCode } from './ng-select.types'; import { newId } from './id'; import { NgDropdownPanelComponent } from './ng-dropdown-panel.component'; import { NgOptionComponent } from './ng-option.component'; import { NgSelectConfig } from './config.service'; import { NgDropdownPanelService } from './ng-dropdown-panel.service'; /** @type {?} */ export const SELECTION_MODEL_FACTORY = new InjectionToken('ng-select-selection-model'); export class NgSelectComponent { /** * @param {?} classes * @param {?} autoFocus * @param {?} config * @param {?} newSelectionModel * @param {?} _elementRef * @param {?} _cd * @param {?} _console */ constructor(classes, autoFocus, config, newSelectionModel, _elementRef, _cd, _console) { this.classes = classes; this.autoFocus = autoFocus; this._cd = _cd; this._console = _console; this.markFirst = true; this.dropdownPosition = 'auto'; this.loading = false; this.closeOnSelect = true; this.hideSelected = false; this.selectOnTab = false; this.bufferAmount = 4; this.selectableGroup = false; this.selectableGroupAsModel = true; this.searchFn = null; this.trackByFn = null; this.clearOnBackspace = true; this.labelForId = null; this.inputAttrs = {}; this.readonly = false; this.searchWhileComposing = true; this.minTermLength = 0; this.keyDownFn = (/** * @param {?} _ * @return {?} */ (_) => true); this.multiple = false; this.addTag = false; this.searchable = true; this.clearable = true; this.isOpen = false; // output events this.blurEvent = new EventEmitter(); this.focusEvent = new EventEmitter(); this.changeEvent = new EventEmitter(); this.openEvent = new EventEmitter(); this.closeEvent = new EventEmitter(); this.searchEvent = new EventEmitter(); this.clearEvent = new EventEmitter(); this.addEvent = new EventEmitter(); this.removeEvent = new EventEmitter(); this.scroll = new EventEmitter(); this.scrollToEnd = new EventEmitter(); this.viewPortItems = []; this.searchTerm = null; this.dropdownId = newId(); this.escapeHTML = true; this._items = []; this._defaultLabel = 'label'; this._pressedKeys = []; this._isComposing = false; this._destroy$ = new Subject(); this._keyPress$ = new Subject(); this._onChange = (/** * @param {?} _ * @return {?} */ (_) => { }); this._onTouched = (/** * @return {?} */ () => { }); this.clearItem = (/** * @param {?} item * @return {?} */ (item) => { /** @type {?} */ const option = this.selectedItems.find((/** * @param {?} x * @return {?} */ x => x.value === item)); this.unselect(option); }); this.trackByOption = (/** * @param {?} _ * @param {?} item * @return {?} */ (_, item) => { if (this.trackByFn) { return this.trackByFn(item.value); } return item; }); this._mergeGlobalConfig(config); this.itemsList = new ItemsList(this, newSelectionModel()); this.element = _elementRef.nativeElement; } /** * @return {?} */ get items() { return this._items; } ; /** * @param {?} value * @return {?} */ set items(value) { this._itemsAreUsed = true; this._items = value; } ; /** * @return {?} */ get compareWith() { return this._compareWith; } /** * @param {?} fn * @return {?} */ set compareWith(fn) { if (!isFunction(fn)) { throw Error('`compareWith` must be a function.'); } this._compareWith = fn; } /** * @return {?} */ get clearSearchOnAdd() { return isDefined(this._clearSearchOnAdd) ? this._clearSearchOnAdd : this.closeOnSelect; } ; /** * @param {?} value * @return {?} */ set clearSearchOnAdd(value) { this._clearSearchOnAdd = value; } ; /** * @return {?} */ get disabled() { return this.readonly || this._disabled; } ; /** * @return {?} */ get filtered() { return (!!this.searchTerm && this.searchable || this._isComposing); } ; /** * @return {?} */ get selectedItems() { return this.itemsList.selectedItems; } /** * @return {?} */ get selectedValues() { return this.selectedItems.map((/** * @param {?} x * @return {?} */ x => x.value)); } /** * @return {?} */ get hasValue() { return this.selectedItems.length > 0; } /** * @return {?} */ get currentPanelPosition() { if (this.dropdownPanel) { return this.dropdownPanel.currentPosition; } return undefined; } /** * @return {?} */ ngOnInit() { this._handleKeyPresses(); this._setInputAttributes(); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.multiple) { this.itemsList.clearSelected(); } if (changes.items) { this._setItems(changes.items.currentValue || []); } if (changes.isOpen) { this._manualOpen = isDefined(changes.isOpen.currentValue); } } /** * @return {?} */ ngAfterViewInit() { if (!this._itemsAreUsed) { this.escapeHTML = false; this._setItemsFromNgOptions(); } if (isDefined(this.autoFocus)) { this.focus(); } } /** * @return {?} */ ngOnDestroy() { this._destroy$.next(); this._destroy$.complete(); } /** * @param {?} $event * @return {?} */ handleKeyDown($event) { /** @type {?} */ const keyCode = KeyCode[$event.which]; if (keyCode) { if (this.keyDownFn($event) === false) { return; } this.handleKeyCode($event); } else if ($event.key && $event.key.length === 1) { this._keyPress$.next($event.key.toLocaleLowerCase()); } } /** * @param {?} $event * @return {?} */ handleKeyCode($event) { switch ($event.which) { case KeyCode.ArrowDown: this._handleArrowDown($event); break; case KeyCode.ArrowUp: this._handleArrowUp($event); break; case KeyCode.Space: this._handleSpace($event); break; case KeyCode.Enter: this._handleEnter($event); break; case KeyCode.Tab: this._handleTab($event); break; case KeyCode.Esc: this.close(); $event.preventDefault(); break; case KeyCode.Backspace: this._handleBackspace(); break; } } /** * @param {?} $event * @return {?} */ handleMousedown($event) { /** @type {?} */ const target = (/** @type {?} */ ($event.target)); if (target.tagName !== 'INPUT') { $event.preventDefault(); } if (target.classList.contains('ng-clear-wrapper')) { this.handleClearClick(); return; } if (target.classList.contains('ng-arrow-wrapper')) { this.handleArrowClick(); return; } if (target.classList.contains('ng-value-icon')) { return; } if (!this.focused) { this.focus(); } if (this.searchable) { this.open(); } else { this.toggle(); } } /** * @return {?} */ handleArrowClick() { if (this.isOpen) { this.close(); } else { this.open(); } } /** * @return {?} */ handleClearClick() { if (this.hasValue) { this.itemsList.clearSelected(true); this._updateNgModel(); } this._clearSearch(); this.focus(); this.clearEvent.emit(); this._onSelectionChanged(); } /** * @return {?} */ clearModel() { if (!this.clearable) { return; } this.itemsList.clearSelected(); this._updateNgModel(); } /** * @param {?} value * @return {?} */ writeValue(value) { this.itemsList.clearSelected(); this._handleWriteValue(value); this._cd.markForCheck(); } /** * @param {?} fn * @return {?} */ registerOnChange(fn) { this._onChange = fn; } /** * @param {?} fn * @return {?} */ registerOnTouched(fn) { this._onTouched = fn; } /** * @param {?} state * @return {?} */ setDisabledState(state) { this._disabled = state; this._cd.markForCheck(); } /** * @return {?} */ toggle() { if (!this.isOpen) { this.open(); } else { this.close(); } } /** * @return {?} */ open() { if (this.disabled || this.isOpen || this.itemsList.maxItemsSelected || this._manualOpen) { return; } if (!this._isTypeahead && !this.addTag && this.itemsList.noItemsToSelect) { return; } this.isOpen = true; this.itemsList.markSelectedOrDefault(this.markFirst); this.openEvent.emit(); if (!this.searchTerm) { this.focus(); } this.detectChanges(); } /** * @return {?} */ close() { if (!this.isOpen || this._manualOpen) { return; } this.isOpen = false; this._clearSearch(); this.itemsList.unmarkItem(); this._onTouched(); this.closeEvent.emit(); this._cd.markForCheck(); } /** * @param {?} item * @return {?} */ toggleItem(item) { if (!item || item.disabled || this.disabled) { return; } if (this.multiple && item.selected) { this.unselect(item); } else { this.select(item); } this._onSelectionChanged(); } /** * @param {?} item * @return {?} */ select(item) { if (!item.selected) { this.itemsList.select(item); if (this.clearSearchOnAdd) { this._clearSearch(); } this._updateNgModel(); if (this.multiple) { this.addEvent.emit(item.value); } } if (this.closeOnSelect || this.itemsList.noItemsToSelect) { this.close(); } } /** * @return {?} */ focus() { this.searchInput.nativeElement.focus(); } /** * @return {?} */ blur() { this.searchInput.nativeElement.blur(); } /** * @param {?} item * @return {?} */ unselect(item) { if (!item) { return; } this.itemsList.unselect(item); this.focus(); this._updateNgModel(); this.removeEvent.emit(item); } /** * @return {?} */ selectTag() { /** @type {?} */ let tag; if (isFunction(this.addTag)) { tag = ((/** @type {?} */ (this.addTag)))(this.searchTerm); } else { tag = this._primitive ? this.searchTerm : { [this.bindLabel]: this.searchTerm }; } /** @type {?} */ const handleTag = (/** * @param {?} item * @return {?} */ (item) => this._isTypeahead || !this.isOpen ? this.itemsList.mapItem(item, null) : this.itemsList.addItem(item)); if (isPromise(tag)) { tag.then((/** * @param {?} item * @return {?} */ item => this.select(handleTag(item)))).catch((/** * @return {?} */ () => { })); } else if (tag) { this.select(handleTag(tag)); } } /** * @return {?} */ showClear() { return this.clearable && (this.hasValue || this.searchTerm) && !this.disabled; } /** * @return {?} */ get showAddTag() { if (!this._validTerm) { return false; } /** @type {?} */ const term = this.searchTerm.toLowerCase().trim(); return this.addTag && (!this.itemsList.filteredItems.some((/** * @param {?} x * @return {?} */ x => x.label.toLowerCase() === term)) && (!this.hideSelected && this.isOpen || !this.selectedItems.some((/** * @param {?} x * @return {?} */ x => x.label.toLowerCase() === term)))) && !this.loading; } /** * @return {?} */ showNoItemsFound() { /** @type {?} */ const empty = this.itemsList.filteredItems.length === 0; return ((empty && !this._isTypeahead && !this.loading) || (empty && this._isTypeahead && this._validTerm && !this.loading)) && !this.showAddTag; } /** * @return {?} */ showTypeToSearch() { /** @type {?} */ const empty = this.itemsList.filteredItems.length === 0; return empty && this._isTypeahead && !this._validTerm && !this.loading; } /** * @return {?} */ onCompositionStart() { this._isComposing = true; } /** * @param {?} term * @return {?} */ onCompositionEnd(term) { this._isComposing = false; if (this.searchWhileComposing) { return; } this.filter(term); } /** * @param {?} term * @return {?} */ filter(term) { if (this._isComposing && !this.searchWhileComposing) { return; } this.searchTerm = term; if (this._isTypeahead && this._validTerm) { this.typeahead.next(term); } if (!this._isTypeahead) { this.itemsList.filter(this.searchTerm); if (this.isOpen) { this.itemsList.markSelectedOrDefault(this.markFirst); } } this.searchEvent.emit({ term, items: this.itemsList.filteredItems.map((/** * @param {?} x * @return {?} */ x => x.value)) }); this.open(); } /** * @param {?} $event * @return {?} */ onInputFocus($event) { if (this.focused) { return; } this.element.classList.add('ng-select-focused'); this.focusEvent.emit($event); this.focused = true; } /** * @param {?} $event * @return {?} */ onInputBlur($event) { this.element.classList.remove('ng-select-focused'); this.blurEvent.emit($event); if (!this.isOpen && !this.disabled) { this._onTouched(); } this.focused = false; } /** * @param {?} item * @return {?} */ onItemHover(item) { if (item.disabled) { return; } this.itemsList.markItem(item); } /** * @return {?} */ detectChanges() { if (!((/** @type {?} */ (this._cd))).destroyed) { this._cd.detectChanges(); } } /** * @private * @param {?} items * @return {?} */ _setItems(items) { /** @type {?} */ const firstItem = items[0]; this.bindLabel = this.bindLabel || this._defaultLabel; this._primitive = isDefined(firstItem) ? !isObject(firstItem) : this._primitive || this.bindLabel === this._defaultLabel; this.itemsList.setItems(items); if (items.length > 0 && this.hasValue) { this.itemsList.mapSelectedItems(); } if (this.isOpen && isDefined(this.searchTerm) && !this._isTypeahead) { this.itemsList.filter(this.searchTerm); } if (this._isTypeahead || this.isOpen) { this.itemsList.markSelectedOrDefault(this.markFirst); } } /** * @private * @return {?} */ _setItemsFromNgOptions() { /** @type {?} */ const mapNgOptions = (/** * @param {?} options * @return {?} */ (options) => { this.items = options.map((/** * @param {?} option * @return {?} */ option => ({ $ngOptionValue: option.value, $ngOptionLabel: option.elementRef.nativeElement.innerHTML, disabled: option.disabled }))); this.itemsList.setItems(this.items); if (this.hasValue) { this.itemsList.mapSelectedItems(); } this.detectChanges(); }); /** @type {?} */ const handleOptionChange = (/** * @return {?} */ () => { /** @type {?} */ const changedOrDestroyed = merge(this.ngOptions.changes, this._destroy$); merge(...this.ngOptions.map((/** * @param {?} option * @return {?} */ option => option.stateChange$))) .pipe(takeUntil(changedOrDestroyed)) .subscribe((/** * @param {?} option * @return {?} */ option => { /** @type {?} */ const item = this.itemsList.findItem(option.value); item.disabled = option.disabled; item.label = option.label || item.label; this._cd.detectChanges(); })); }); this.ngOptions.changes .pipe(startWith(this.ngOptions), takeUntil(this._destroy$)) .subscribe((/** * @param {?} options * @return {?} */ options => { this.bindLabel = this._defaultLabel; mapNgOptions(options); handleOptionChange(); })); } /** * @private * @param {?} value * @return {?} */ _isValidWriteValue(value) { if (!isDefined(value) || (this.multiple && value === '') || Array.isArray(value) && value.length === 0) { return false; } /** @type {?} */ const validateBinding = (/** * @param {?} item * @return {?} */ (item) => { if (!isDefined(this.compareWith) && isObject(item) && this.bindValue) { this._console.warn(`Binding object(${JSON.stringify(item)}) with bindValue is not allowed.`); return false; } return true; }); if (this.multiple) { if (!Array.isArray(value)) { this._console.warn('Multiple select ngModel should be array.'); return false; } return value.every((/** * @param {?} item * @return {?} */ item => validateBinding(item))); } else { return validateBinding(value); } } /** * @private * @param {?} ngModel * @return {?} */ _handleWriteValue(ngModel) { if (!this._isValidWriteValue(ngModel)) { return; } /** @type {?} */ const select = (/** * @param {?} val * @return {?} */ (val) => { /** @type {?} */ let item = this.itemsList.findItem(val); if (item) { this.itemsList.select(item); } else { /** @type {?} */ const isValObject = isObject(val); /** @type {?} */ const isPrimitive = !isValObject && !this.bindValue; if ((isValObject || isPrimitive)) { this.itemsList.select(this.itemsList.mapItem(val, null)); } else if (this.bindValue) { item = { [this.bindLabel]: null, [this.bindValue]: val }; this.itemsList.select(this.itemsList.mapItem(item, null)); } } }); if (this.multiple) { ((/** @type {?} */ (ngModel))).forEach((/** * @param {?} item * @return {?} */ item => select(item))); } else { select(ngModel); } } /** * @private * @return {?} */ _handleKeyPresses() { if (this.searchable) { return; } this._keyPress$ .pipe(takeUntil(this._destroy$), tap((/** * @param {?} letter * @return {?} */ letter => this._pressedKeys.push(letter))), debounceTime(200), filter((/** * @return {?} */ () => this._pressedKeys.length > 0)), map((/** * @return {?} */ () => this._pressedKeys.join('')))) .subscribe((/** * @param {?} term * @return {?} */ term => { /** @type {?} */ const item = this.itemsList.findByLabel(term); if (item) { if (this.isOpen) { this.itemsList.markItem(item); this._cd.markForCheck(); } else { this.select(item); } } this._pressedKeys = []; })); } /** * @private * @return {?} */ _setInputAttributes() { /** @type {?} */ const input = this.searchInput.nativeElement; /** @type {?} */ const attributes = Object.assign({ type: 'text', autocorrect: 'off', autocapitalize: 'off', autocomplete: this.labelForId ? 'off' : this.dropdownId }, this.inputAttrs); for (const key of Object.keys(attributes)) { input.setAttribute(key, attributes[key]); } } /** * @private * @return {?} */ _updateNgModel() { /** @type {?} */ const model = []; for (const item of this.selectedItems) { if (this.bindValue) { /** @type {?} */ let value = null; if (item.children) { /** @type {?} */ const groupKey = this.groupValue ? this.bindValue : (/** @type {?} */ (this.groupBy)); value = item.value[groupKey || (/** @type {?} */ (this.groupBy))]; } else { value = this.itemsList.resolveNested(item.value, this.bindValue); } model.push(value); } else { model.push(item.value); } } /** @type {?} */ const selected = this.selectedItems.map((/** * @param {?} x * @return {?} */ x => x.value)); if (this.multiple) { this._onChange(model); this.changeEvent.emit(selected); } else { this._onChange(isDefined(model[0]) ? model[0] : null); this.changeEvent.emit(selected[0]); } this._cd.markForCheck(); } /** * @private * @return {?} */ _clearSearch() { if (!this.searchTerm) { return; } this._changeSearch(null); this.itemsList.resetFilteredItems(); } /** * @private * @param {?} searchTerm * @return {?} */ _changeSearch(searchTerm) { this.searchTerm = searchTerm; if (this._isTypeahead) { this.typeahead.next(searchTerm); } } /** * @private * @return {?} */ _scrollToMarked() { if (!this.isOpen || !this.dropdownPanel) { return; } this.dropdownPanel.scrollTo(this.itemsList.markedItem); } /** * @private * @return {?} */ _scrollToTag() { if (!this.isOpen || !this.dropdownPanel) { return; } this.dropdownPanel.scrollToTag(); } /** * @private * @return {?} */ _onSelectionChanged() { if (this.isOpen && this.multiple && this.appendTo) { // Make sure items are rendered. this._cd.detectChanges(); this.dropdownPanel.adjustPosition(); } } /** * @private * @param {?} $event * @return {?} */ _handleTab($event) { if (this.isOpen === false && !this.addTag) { return; } if (this.selectOnTab) { if (this.itemsList.markedItem) { this.toggleItem(this.itemsList.markedItem); $event.preventDefault(); } else if (this.showAddTag) { this.selectTag(); $event.preventDefault(); } else { this.close(); } } else { this.close(); } } /** * @private * @param {?} $event * @return {?} */ _handleEnter($event) { if (this.isOpen || this._manualOpen) { if (this.itemsList.markedItem) { this.toggleItem(this.itemsList.markedItem); } else if (this.showAddTag) { this.selectTag(); } } else if (this.openOnEnter) { this.open(); } else { return; } $event.preventDefault(); } /** * @private * @param {?} $event * @return {?} */ _handleSpace($event) { if (this.isOpen || this._manualOpen) { return; } this.open(); $event.preventDefault(); } /** * @private * @param {?} $event * @return {?} */ _handleArrowDown($event) { if (this._nextItemIsTag(+1)) { this.itemsList.unmarkItem(); this._scrollToTag(); } else { this.itemsList.markNextItem(); this._scrollToMarked(); } this.open(); $event.preventDefault(); } /** * @private * @param {?} $event * @return {?} */ _handleArrowUp($event) { if (!this.isOpen) { return; } if (this._nextItemIsTag(-1)) { this.itemsList.unmarkItem(); this._scrollToTag(); } else { this.itemsList.markPreviousItem(); this._scrollToMarked(); } $event.preventDefault(); } /** * @private * @param {?} nextStep * @return {?} */ _nextItemIsTag(nextStep) { /** @type {?} */ const nextIndex = this.itemsList.markedIndex + nextStep; return this.addTag && this.searchTerm && this.itemsList.markedItem && (nextIndex < 0 || nextIndex === this.itemsList.filteredItems.length); } /** * @private * @return {?} */ _handleBackspace() { if (this.searchTerm || !this.clearable || !this.clearOnBackspace || !this.hasValue) { return; } if (this.multiple) { this.unselect(this.itemsList.lastSelectedItem); } else { this.clearModel(); } } /** * @private * @return {?} */ get _isTypeahead() { return this.typeahead && this.typeahead.observers.length > 0; } /** * @private * @return {?} */ get _validTerm() { /** @type {?} */ const term = this.searchTerm && this.searchTerm.trim(); return term && term.length >= this.minTermLength; } /** * @private * @param {?} config * @return {?} */ _mergeGlobalConfig(config) { this.placeholder = this.placeholder || config.placeholder; this.notFoundText = this.notFoundText || config.notFoundText; this.typeToSearchText = this.typeToSearchText || config.typeToSearchText; this.addTagText = this.addTagText || config.addTagText; this.loadingText = this.loadingText || config.loadingText; this.clearAllText = this.clearAllText || config.clearAllText; this.virtualScroll = isDefined(this.virtualScroll) ? this.virtualScroll : isDefined(config.disableVirtualScroll) ? !config.disableVirtualScroll : false; this.openOnEnter = isDefined(this.openOnEnter) ? this.openOnEnter : config.openOnEnter; this.appendTo = this.appendTo || config.appendTo; this.bindValue = this.bindValue || config.bindValue; this.appearance = this.appearance || config.appearance; } } NgSelectComponent.decorators = [ { type: Component, args: [{ selector: 'ng-select', template: "<div\n (mousedown)=\"handleMousedown($event)\"\n [class.ng-appearance-outline]=\"appearance === 'outline'\"\n [class.ng-has-value]=\"hasValue\"\n class=\"ng-select-container\">\n\n <div class=\"ng-value-container\">\n <div class=\"ng-placeholder\">{{placeholder}}</div>\n\n <ng-container *ngIf=\"!multiLabelTemplate && selectedItems.length > 0\">\n <div [class.ng-value-disabled]=\"item.disabled\" class=\"ng-value\" *ngFor=\"let item of selectedItems; trackBy: trackByOption\">\n <ng-template #defaultLabelTemplate>\n <span class=\"ng-value-icon left\" (click)=\"unselect(item);\" aria-hidden=\"true\">\u00D7</span>\n <span class=\"ng-value-label\" [ngItemLabel]=\"item.label\" [escape]=\"escapeHTML\"></span>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"labelTemplate || defaultLabelTemplate\"\n [ngTemplateOutletContext]=\"{ item: item.value, clear: clearItem, label: item.label }\">\n </ng-template>\n </div>\n </ng-container>\n\n <ng-template *ngIf=\"multiLabelTemplate && selectedValues.length > 0\"\n [ngTemplateOutlet]=\"multiLabelTemplate\"\n [ngTemplateOutletContext]=\"{ items: selectedValues, clear: clearItem }\">\n </ng-template>\n\n <div class=\"ng-input\">\n <input #searchInput\n [attr.id]=\"labelForId\"\n [attr.tabindex]=\"tabIndex\"\n [readOnly]=\"!searchable || itemsList.maxItemsSelected\"\n [disabled]=\"disabled\"\n [value]=\"searchTerm ? searchTerm : ''\"\n (input)=\"filter(searchInput.value)\"\n (compositionstart)=\"onCompositionStart()\"\n (compositionend)=\"onCompositionEnd(searchInput.value)\"\n (focus)=\"onInputFocus($event)\"\n (blur)=\"onInputBlur($event)\"\n (change)=\"$event.stopPropagation()\"\n role=\"combobox\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-owns]=\"isOpen ? dropdownId : null\"\n [attr.aria-activedescendant]=\"isOpen ? itemsList?.markedItem?.htmlId : null\">\n </div>\n </div>\n\n <ng-container *ngIf=\"loading\">\n <ng-template #defaultLoadingSpinnerTemplate>\n <div class=\"ng-spinner-loader\"></div>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"loadingSpinnerTemplate || defaultLoadingSpinnerTemplate\">\n </ng-template>\n </ng-container>\n\n <span *ngIf=\"showClear()\" class=\"ng-clear-wrapper\" title=\"{{clearAllText}}\">\n <span class=\"ng-clear\" aria-hidden=\"true\">\u00D7</span>\n </span>\n\n <span class=\"ng-arrow-wrapper\">\n <span class=\"ng-arrow\"></span>\n </span>\n</div>\n\n<ng-dropdown-panel *ngIf=\"isOpen\"\n class=\"ng-dropdown-panel\"\n [virtualScroll]=\"virtualScroll\"\n [bufferAmount]=\"bufferAmount\"\n [appendTo]=\"appendTo\"\n [position]=\"dropdownPosition\"\n [headerTemplate]=\"headerTemplate\"\n [footerTemplate]=\"footerTemplate\"\n [filterValue]=\"searchTerm\"\n [items]=\"itemsList.filteredItems\"\n [markedItem]=\"itemsList.markedItem\"\n (update)=\"viewPortItems = $event\"\n (scroll)=\"scroll.emit($event)\"\n (scrollToEnd)=\"scrollToEnd.emit($event)\"\n (outsideClick)=\"close()\"\n [class.ng-select-multiple]=\"multiple\"\n [ngClass]=\"appendTo ? classes : null\"\n [id]=\"dropdownId\">\n\n <ng-container>\n <div class=\"ng-option\" [attr.role]=\"item.children ? 'group' : 'option'\" (click)=\"toggleItem(item)\" (mouseover)=\"onItemHover(item)\"\n *ngFor=\"let item of viewPortItems; trackBy: trackByOption\"\n [class.ng-option-disabled]=\"item.disabled\"\n [class.ng-option-selected]=\"item.selected\"\n [class.ng-optgroup]=\"item.children\"\n [class.ng-option]=\"!item.children\"\n [class.ng-option-child]=\"!!item.parent\"\n [class.ng-option-marked]=\"item === itemsList.markedItem\"\n [attr.aria-selected]=\"item.selected\"\n [attr.id]=\"item?.htmlId\">\n\n <ng-template #defaultOptionTemplate>\n <span class=\"ng-option-label\" [ngItemLabel]=\"item.label\" [escape]=\"escapeHTML\"></span>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"item.children ? (optgroupTemplate || defaultOptionTemplate) : (optionTemplate || defaultOptionTemplate)\"\n [ngTemplateOutletContext]=\"{ item: item.value, item$:item, index: item.index, searchTerm: searchTerm }\">\n </ng-template>\n </div>\n\n <div class=\"ng-option\" [class.ng-option-marked]=\"!itemsList.markedItem\" (mouseover)=\"itemsList.unmarkItem()\" role=\"option\" (click)=\"selectTag()\" *ngIf=\"showAddTag\">\n <ng-template #defaultTagTemplate>\n <span><span class=\"ng-tag-label\">{{addTagText}}</span>\"{{searchTerm}}\"</span>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"tagTemplate || defaultTagTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n </div>\n </ng-container>\n\n <ng-container *ngIf=\"showNoItemsFound()\">\n <ng-template #defaultNotFoundTemplate>\n <div class=\"ng-option ng-option-disabled\">{{notFoundText}}</div>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"notFoundTemplate || defaultNotFoundTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n </ng-container>\n\n <ng-container *ngIf=\"showTypeToSearch()\">\n <ng-template #defaultTypeToSearchTemplate>\n <div class=\"ng-option ng-option-disabled\">{{typeToSearchText}}</div>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"typeToSearchTemplate || defaultTypeToSearchTemplate\">\n </ng-template>\n </ng-container>\n\n <ng-container *ngIf=\"loading && itemsList.filteredItems.length === 0\">\n <ng-template #defaultLoadingTextTemplate>\n <div class=\"ng-option ng-option-disabled\">{{loadingText}}</div>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"loadingTextTemplate || defaultLoadingTextTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n </ng-container>\n\n</ng-dropdown-panel>\n", providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => NgSelectComponent)), multi: true }, NgDropdownPanelService], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, host: { 'role': 'listbox', 'class': 'ng-select', '[class.ng-select-single]': '!multiple', }, styles: [".ng-select{position:relative;display:block;box-sizing:border-box}.ng-select div,.ng-select input,.ng-select span{box-sizing:border-box}.ng-select [hidden]{display:none}.ng-select.ng-select-searchable .ng-select-container .ng-value-container .ng-input{opacity:1}.ng-select.ng-select-opened .ng-select-container{z-index:1001}.ng-select.ng-select-disabled .ng-select-container .ng-value-container .ng-placeholder,.ng-select.ng-select-disabled .ng-select-container .ng-value-container .ng-value{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.ng-select.ng-select-disabled .ng-arrow-wrapper{cursor:default}.ng-select.ng-select-filtered .ng-placeholder{display:none}.ng-select .ng-select-container{color:#333;cursor:default;display:-webkit-box;display:flex;outline:0;overflow:hidden;position:relative;width:100%}.ng-select .ng-select-container .ng-value-container{display:-webkit-box;display:flex;-webkit-box-flex:1;flex:1}.ng-select .ng-select-container .ng-value-container .ng-input{opacity:0}.ng-select .ng-select-container .ng-value-container .ng-input>input{box-sizing:content-box;background:none;border:0;box-shadow:none;outline:0;cursor:default;width:100%}.ng-select .ng-select-container .ng-value-container .ng-input>input::-ms-clear{display:none}.ng-select .ng-select-container .ng-value-container .ng-input>input[readonly]{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:0;padding:0}.ng-select.ng-select-single.ng-select-filtered .ng-select-container .ng-value-container .ng-value{visibility:hidden}.ng-select.ng-select-single .ng-select-container .ng-value-container,.ng-select.ng-select-single .ng-select-container .ng-value-container .ng-value{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ng-select.ng-select-single .ng-select-container .ng-value-container .ng-value .ng-value-icon{display:none}.ng-select.ng-select-single .ng-select-container .ng-value-container .ng-input{position:absolute;left:0;width:100%}.ng-select.ng-select-multiple.ng-select-disabled>.ng-select-container .ng-value-container .ng-value .ng-value-icon{display:none}.ng-select.ng-select-multiple .ng-select-container .ng-value-container{flex-wrap:wrap}.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value{white-space:nowrap}.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value.ng-value-disabled .ng-value-icon{display:none}.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon{cursor:pointer}.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-input{-webkit-box-flex:1;flex:1;z-index:2}.ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-placeholder{position:absolute;z-index:1}.ng-select .ng-clear-wrapper{cursor:pointer;position:relative;width:17px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ng-select .ng-clear-wrapper .ng-clear{display:inline-block;font-size:18px;line-height:1;pointer-events:none}.ng-select .ng-spinner-loader{border-radius:50%;width:17px;height:17px;margin-right:5px;font-size:10px;position:relative;text-indent:-9999em;border-top:2px solid rgba(66,66,66,.2);border-right:2px solid rgba(66,66,66,.2);border-bottom:2px solid rgba(66,66,66,.2);border-left:2px solid #424242;-webkit-transform:translateZ(0);transform:translateZ(0);-webkit-animation:.8s linear infinite load8;animation:.8s linear infinite load8}.ng-select .ng-spinner-loader:after{border-radius:50%;width:17px;height:17px}@-webkit-keyframes load8{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes load8{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}.ng-select .ng-arrow-wrapper{cursor:pointer;position:relative;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ng-select .ng-arrow-wrapper .ng-arrow{pointer-events:none;display:inline-block;height:0;width:0;position:relative}.ng-dropdown-panel{box-sizing:border-box;position:absolute;opacity:0;width:100%;z-index:1050;-webkit-overflow-scrolling:touch}.ng-dropdown-panel .ng-dropdown-panel-items{display:block;height:auto;box-sizing:border-box;max-height:240px;overflow-y:auto}.ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ng-dropdown-panel .ng-dropdown-panel-items .ng-option{box-sizing:border-box;cursor:pointer;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ng-dropdown-panel .ng-dropdown-panel-items .ng-option .highlighted{font-weight:700;text-decoration:underline}.ng-dropdown-panel .ng-dropdown-panel-items .ng-option.disabled{cursor:default}.ng-dropdown-panel .scroll-host{overflow:hidden;overflow-y:auto;position:relative;display:block;-webkit-overflow-scrolling:touch}.ng-dropdown-panel .scrollable-content{top:0;left:0;width:100%;height:100%;position:absolute}.ng-dropdown-panel .total-padding{width:1px;opacity:0}"] }] } ]; /** @nocollapse */ NgSelectComponent.ctorParameters = () => [ { type: String, decorators: [{ type: Attribute, args: ['class',] }] }, { type: undefined, decorators: [{ type: Attribute, args: ['autofocus',] }] }, { type: NgSelectConfig }, { type: undefined, decorators: [{ type: Inject, args: [SELECTION_MODEL_FACTORY,] }] }, { type: ElementRef }, { type: ChangeDetectorRef }, { type: ConsoleService } ]; NgSelectComponent.propDecorators = { bindLabel: [{ type: Input }], bindValue: [{ type: Input }], markFirst: [{ type: Input }], placeholder: [{ type: Input }], notFoundText: [{ type: Input }], typeToSearchText: [{ type: Input }], addTagText: [{ type: Input }], loadingText: [{ type: Input }], clearAllText: [{ type: Input }], appearance: [{ type: Input }], dropdownPosition: [{ type: Input }], appendTo: [{ type: Input }], loading: [{ type: Input }], closeOnSelect: [{ type: Input }], hideSelected: [{ type: Input }], selectOnTab: [{ type: Input }], openOnEnter: [{ type: Input }], maxSelectedItems: [{ type: Input }], groupBy: [{ type: Input }], groupValue: [{ type: Input }], bufferAmount: [{ type: Input }], virtualScroll: [{ type: Input }], selectableGroup: [{ type: Input }], selectableGroupAsModel: [{ type: Input }], searchFn: [{ type: Input }], trackByFn: [{ type: Input }], clearOnBackspace: [{ type: Input }], labelForId: [{ type: Input }], inputAttrs: [{ type: Input }], tabIndex: [{ type: Input }], readonly: [{ type: Input }], searchWhileComposing: [{ type: Input }], minTermLength: [{ type: Input }], keyDownFn: [{ type: Input }], typeahead: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-typeahead',] }], multiple: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-multiple',] }], addTag: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-taggable',] }], searchable: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-searchable',] }], clearable: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-clearable',] }], isOpen: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-opened',] }], items: [{ type: Input }], compareWith: [{ type: Input }], clearSearchOnAdd: [{ type: Input }], blurEvent: [{ type: Output, args: ['blur',] }], focusEvent: [{ type: Output, args: ['focus',] }], changeEvent: [{ type: Output, args: ['change',] }], openEvent: [{ type: Output, args: ['open',] }], closeEvent: [{ type: Output, args: ['close',] }], searchEvent: [{ type: Output, args: ['search',] }], clearEvent: [{ type: Output, args: ['clear',] }], addEvent: [{ type: Output, args: ['add',] }], removeEvent: [{ type: Output, args: ['remove',] }], scroll: [{ type: Output, args: ['scroll',] }], scrollToEnd: [{ type: Output, args: ['scrollToEnd',] }], optionTemplate: [{ type: ContentChild, args: [NgOptionTemplateDirective, { read: TemplateRef, static: false },] }], optgroupTemplate: [{ type: ContentChild, args: [NgOptgroupTemplateDirective, { read: TemplateRef, static: false },] }], labelTemplate: [{ type: ContentChild, args: [NgLabelTemplateDirective, { read: TemplateRef, static: false },] }], multiLabelTemplate: [{ type: ContentChild, args: [NgMultiLabelTemplateDirective, { read: TemplateRef, static: false },] }], headerTemplate: [{ type: ContentChild, args: [NgHeaderTemplateDirective, { read: TemplateRef, static: false },] }], footerTemplate: [{ type: ContentChild, args: [NgFooterTemplateDirective, { read: TemplateRef, static: false },] }], notFoundTemplate: [{ type: ContentChild, args: [NgNotFoundTemplateDirective, { read: TemplateRef, static: false },] }], typeToSearchTemplate: [{ type: ContentChild, args: [NgTypeToSearchTemplateDirective, { read: TemplateRef, static: false },] }], loadingTextTemplate: [{ type: ContentChild, args: [NgLoadingTextTemplateDirective, { read: TemplateRef, static: false },] }], tagTemplate: [{ type: ContentChild, args: [NgTagTemplateDirective, { read: TemplateRef, static: false },] }], loadingSpinnerTemplate: [{ type: ContentChild, args: [NgLoadingSpinnerTemplateDirective, { read: TemplateRef, static: false },] }], dropdownPanel: [{ type: ViewChild, args: [forwardRef((/** * @return {?} */ () => NgDropdownPanelComponent)), { static: false },] }], searchInput: [{ type: ViewChild, args: ['searchInput', { static: true },] }], ngOptions: [{ type: ContentChildren, args: [NgOptionComponent, { descendants: true },] }], disabled: [{ type: HostBinding, args: ['class.ng-select-disabled',] }], filtered: [{ type: HostBinding, args: ['class.ng-select-filtered',] }], handleKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }] }; if (false) { /** @type {?} */ NgSelectComponent.prototype.bindLabel; /** @type {?} */ NgSelectComponent.prototype.bindValue; /** @type {?} */ NgSelectComponent.prototype.markFirst; /** @type {?} */ NgSelectComponent.prototype.placeholder; /** @type {?} */ NgSelectComponent.prototype.notFoundText; /** @type {?} */ NgSelectComponent.prototype.typeToSearchText; /** @type {?} */ NgSelectComponent.prototype.addTagText; /** @type {?} */ NgSelectComponent.prototype.loadingText; /** @type {?} */ NgSelectComponent.prototype.clearAllText; /** @type {?} */ NgSelectComponent.prototype.appearance; /** @type {?} */ NgSelectComponent.prototype.dropdownPosition; /** @type {?} */ NgSelectComponent.prototype.appendTo; /** @type {?} */ NgSelectComponent.prototype.loading; /** @type {?} */ NgSelectComponent.prototype.closeOnSelect; /** @type {?} */ NgSelectComponent.prototype.hideSelected; /** @type {?} */ NgSelectComponent.prototype.se