@ng-select/ng-select
Version:
Angular ng-select - All in One UI Select, Multiselect and Autocomplete
1,276 lines • 115 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import * as tslib_1 from "tslib";
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 } 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';
/** @type {?} */
export var NG_SELECT_DEFAULT_CONFIG = new InjectionToken('ng-select-default-options');
/** @type {?} */
export var SELECTION_MODEL_FACTORY = new InjectionToken('ng-select-selection-model');
/** @typedef {?} */
var DropdownPosition;
export { DropdownPosition };
/** @typedef {?} */
var AddTagFn;
export { AddTagFn };
/** @typedef {?} */
var CompareWithFn;
export { CompareWithFn };
var NgSelectComponent = /** @class */ (function () {
function NgSelectComponent(classes, tabIndex, config, newSelectionModel, _elementRef, _cd, _console) {
var _this = this;
this.classes = classes;
this.tabIndex = tabIndex;
this._cd = _cd;
this._console = _console;
// inputs
this.items = [];
this.clearable = true;
this.markFirst = true;
this.dropdownPosition = 'auto';
this.loading = false;
this.closeOnSelect = true;
this.hideSelected = false;
this.selectOnTab = false;
this.bufferAmount = 4;
this.virtualScroll = false;
this.selectableGroup = false;
this.selectableGroupAsModel = true;
this.searchFn = null;
this.clearSearchOnAdd = true;
this.labelForId = null;
this.multiple = false;
this.addTag = false;
this.searchable = 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.disabled = false;
this.viewPortItems = [];
this.filterValue = null;
this.dropdownId = newId();
this.selectedItemId = 0;
this._defaultLabel = 'label';
this._pressedKeys = [];
this._destroy$ = new Subject();
this._keyPress$ = new Subject();
this._onChange = function (_) { };
this._onTouched = function () { };
this.clearItem = function (item) {
/** @type {?} */
var option = _this.selectedItems.find(function (x) { return x.value === item; });
_this.unselect(option);
};
this._mergeGlobalConfig(config);
this.itemsList = new ItemsList(this, newSelectionModel());
this.element = _elementRef.nativeElement;
}
Object.defineProperty(NgSelectComponent.prototype, "compareWith", {
get: /**
* @return {?}
*/
function () { return this._compareWith; },
set: /**
* @param {?} fn
* @return {?}
*/
function (fn) {
if (!isFunction(fn)) {
throw Error('`compareWith` must be a function.');
}
this._compareWith = fn;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgSelectComponent.prototype, "filtered", {
get: /**
* @return {?}
*/
function () { return !!this.filterValue && this.searchable; },
enumerable: true,
configurable: true
});
;
Object.defineProperty(NgSelectComponent.prototype, "selectedItems", {
get: /**
* @return {?}
*/
function () {
return this.itemsList.selectedItems;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgSelectComponent.prototype, "selectedValues", {
get: /**
* @return {?}
*/
function () {
return this.selectedItems.map(function (x) { return x.value; });
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgSelectComponent.prototype, "hasValue", {
get: /**
* @return {?}
*/
function () {
return this.selectedItems.length > 0;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NgSelectComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
this._handleKeyPresses();
};
/**
* @param {?} changes
* @return {?}
*/
NgSelectComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes["multiple"]) {
this.itemsList.clearSelected();
}
if (changes["items"]) {
this._setItems(changes["items"].currentValue || []);
}
if (changes["isOpen"]) {
this._manualOpen = true;
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
if (this.items && this.items.length === 0) {
this._setItemsFromNgOptions();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this._destroy$.next();
this._destroy$.complete();
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype.handleKeyDown = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (KeyCode[$event.which]) {
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();
$event.stopPropagation();
break;
case KeyCode.Backspace:
this._handleBackspace();
break;
}
}
else if ($event.key && $event.key.length === 1) {
this._keyPress$.next($event.key.toLocaleLowerCase());
}
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype.handleMousedown = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
/** @type {?} */
var target = /** @type {?} */ ($event.target);
if (target.tagName !== 'INPUT') {
$event.preventDefault();
}
$event.stopPropagation();
if (target.className === 'ng-clear') {
this.handleClearClick();
return;
}
if (target.className === 'ng-arrow-wrapper') {
this.handleArrowClick();
return;
}
if (target.className.includes('ng-value-icon')) {
return;
}
if (!this.focused) {
this.focus();
}
if (this.searchable) {
this.open();
}
else {
this.toggle();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.handleArrowClick = /**
* @return {?}
*/
function () {
if (this.isOpen) {
this.close();
}
else {
this.open();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.handleClearClick = /**
* @return {?}
*/
function () {
if (this.hasValue) {
this.clearModel();
}
this._clearSearch();
this.focus();
if (this._isTypeahead) {
this.typeahead.next(null);
}
this.clearEvent.emit();
};
/**
* @return {?}
*/
NgSelectComponent.prototype.clearModel = /**
* @return {?}
*/
function () {
if (!this.clearable) {
return;
}
this.itemsList.clearSelected();
this._updateNgModel();
};
/**
* @param {?} value
* @return {?}
*/
NgSelectComponent.prototype.writeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
this.itemsList.clearSelected();
this._handleWriteValue(value);
this._cd.markForCheck();
};
/**
* @param {?} fn
* @return {?}
*/
NgSelectComponent.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this._onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
NgSelectComponent.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this._onTouched = fn;
};
/**
* @param {?} isDisabled
* @return {?}
*/
NgSelectComponent.prototype.setDisabledState = /**
* @param {?} isDisabled
* @return {?}
*/
function (isDisabled) {
this.disabled = isDisabled;
this._cd.markForCheck();
};
/**
* @return {?}
*/
NgSelectComponent.prototype.toggle = /**
* @return {?}
*/
function () {
if (!this.isOpen) {
this.open();
}
else {
this.close();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.open = /**
* @return {?}
*/
function () {
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.filterValue) {
this.focus();
}
this.detectChanges();
};
/**
* @return {?}
*/
NgSelectComponent.prototype.close = /**
* @return {?}
*/
function () {
if (!this.isOpen || this._manualOpen) {
return;
}
this.isOpen = false;
this._clearSearch();
this._onTouched();
this.closeEvent.emit();
this._cd.markForCheck();
};
/**
* @param {?} item
* @return {?}
*/
NgSelectComponent.prototype.toggleItem = /**
* @param {?} item
* @return {?}
*/
function (item) {
if (!item || item.disabled || this.disabled) {
return;
}
if (this.multiple && item.selected) {
this.unselect(item);
}
else {
this.select(item);
}
};
/**
* @param {?} item
* @return {?}
*/
NgSelectComponent.prototype.select = /**
* @param {?} item
* @return {?}
*/
function (item) {
if (!item.selected) {
this.itemsList.select(item);
if (this.clearSearchOnAdd) {
this._clearSearch();
}
if (this.multiple) {
this.addEvent.emit(item.value);
}
this._updateNgModel();
}
if (this.closeOnSelect || this.itemsList.noItemsToSelect) {
this.close();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.focus = /**
* @return {?}
*/
function () {
this.filterInput.nativeElement.focus();
};
/**
* @param {?} item
* @return {?}
*/
NgSelectComponent.prototype.unselect = /**
* @param {?} item
* @return {?}
*/
function (item) {
this.itemsList.unselect(item);
this.focus();
this._updateNgModel();
this.removeEvent.emit(item);
};
/**
* @return {?}
*/
NgSelectComponent.prototype.selectTag = /**
* @return {?}
*/
function () {
var _this = this;
var _a;
/** @type {?} */
var tag;
if (isFunction(this.addTag)) {
tag = (/** @type {?} */ (this.addTag))(this.filterValue);
}
else {
tag = this._primitive ? this.filterValue : (_a = {}, _a[this.bindLabel] = this.filterValue, _a);
}
/** @type {?} */
var handleTag = function (item) { return _this._isTypeahead ? _this.itemsList.mapItem(item, null) : _this.itemsList.addItem(item); };
if (isPromise(tag)) {
tag.then(function (item) { return _this.select(handleTag(item)); }).catch(function () { });
}
else if (tag) {
this.select(handleTag(tag));
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.showClear = /**
* @return {?}
*/
function () {
return this.clearable && (this.hasValue || this.filterValue) && !this.disabled;
};
Object.defineProperty(NgSelectComponent.prototype, "showAddTag", {
get: /**
* @return {?}
*/
function () {
if (!this.filterValue) {
return false;
}
/** @type {?} */
var term = this.filterValue.toLowerCase();
return this.addTag &&
(!this.itemsList.filteredItems.some(function (x) { return x.label.toLowerCase() === term; }) &&
(!this.hideSelected || !this.selectedItems.some(function (x) { return x.label.toLowerCase() === term; }))) &&
!this.loading;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NgSelectComponent.prototype.showNoItemsFound = /**
* @return {?}
*/
function () {
/** @type {?} */
var empty = this.itemsList.filteredItems.length === 0;
return ((empty && !this._isTypeahead && !this.loading) ||
(empty && this._isTypeahead && this.filterValue && !this.loading)) &&
!this.showAddTag;
};
/**
* @return {?}
*/
NgSelectComponent.prototype.showTypeToSearch = /**
* @return {?}
*/
function () {
/** @type {?} */
var empty = this.itemsList.filteredItems.length === 0;
return empty && this._isTypeahead && !this.filterValue && !this.loading;
};
/**
* @param {?} term
* @return {?}
*/
NgSelectComponent.prototype.filter = /**
* @param {?} term
* @return {?}
*/
function (term) {
this.filterValue = term;
this.open();
if (this._isTypeahead) {
this.typeahead.next(this.filterValue);
}
else {
this.itemsList.filter(this.filterValue);
if (this.isOpen) {
this.itemsList.markSelectedOrDefault(this.markFirst);
}
}
this.searchEvent.emit(term);
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype.onInputFocus = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (this.focused) {
return;
}
this.element.classList.add('ng-select-focused');
this.focusEvent.emit($event);
this.focused = true;
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype.onInputBlur = /**
* @param {?} $event
* @return {?}
*/
function ($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 {?}
*/
NgSelectComponent.prototype.onItemHover = /**
* @param {?} item
* @return {?}
*/
function (item) {
if (item.disabled) {
return;
}
this.itemsList.markItem(item);
};
/**
* @return {?}
*/
NgSelectComponent.prototype.detectChanges = /**
* @return {?}
*/
function () {
if (!(/** @type {?} */ (this._cd)).destroyed) {
this._cd.detectChanges();
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype.updateDropdownPosition = /**
* @return {?}
*/
function () {
if (this.dropdownPanel) {
this.dropdownPanel.updateDropdownPosition();
}
};
/**
* @param {?} items
* @return {?}
*/
NgSelectComponent.prototype._setItems = /**
* @param {?} items
* @return {?}
*/
function (items) {
/** @type {?} */
var firstItem = items[0];
this.bindLabel = this.bindLabel || this._defaultLabel;
this._primitive = !firstItem ? this._primitive : !isObject(firstItem);
this.itemsList.setItems(items);
if (items.length > 0 && this.hasValue) {
this.itemsList.mapSelectedItems();
}
if (this.isOpen && isDefined(this.filterValue) && !this._isTypeahead) {
this.itemsList.filter(this.filterValue);
}
if (this._isTypeahead || this.isOpen) {
this.itemsList.markSelectedOrDefault(this.markFirst);
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype._setItemsFromNgOptions = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var handleNgOptions = function (options) {
_this.items = options.map(function (option) { return ({
$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 {?} */
var handleOptionChange = function () {
/** @type {?} */
var changedOrDestroyed = merge(_this.ngOptions.changes, _this._destroy$);
merge.apply(void 0, tslib_1.__spread(_this.ngOptions.map(function (option) { return option.stateChange$; }))).pipe(takeUntil(changedOrDestroyed))
.subscribe(function (option) {
/** @type {?} */
var item = _this.itemsList.findItem(option.value);
item.disabled = option.disabled;
_this._cd.markForCheck();
});
};
this.ngOptions.changes
.pipe(startWith(this.ngOptions), takeUntil(this._destroy$), filter(function (items) { return !!items.length; }))
.subscribe(function (options) {
_this.bindLabel = _this._defaultLabel;
handleNgOptions(options);
handleOptionChange();
});
};
/**
* @param {?} value
* @return {?}
*/
NgSelectComponent.prototype._isValidWriteValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
var _this = this;
if (!isDefined(value) ||
(this.multiple && value === '') ||
Array.isArray(value) && value.length === 0) {
return false;
}
/** @type {?} */
var validateBinding = function (item) {
if (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(function (item) { return validateBinding(item); });
}
else {
return validateBinding(value);
}
};
/**
* @param {?} ngModel
* @return {?}
*/
NgSelectComponent.prototype._handleWriteValue = /**
* @param {?} ngModel
* @return {?}
*/
function (ngModel) {
var _this = this;
if (!this._isValidWriteValue(ngModel)) {
return;
}
/** @type {?} */
var select = function (val) {
var _a;
/** @type {?} */
var item = _this.itemsList.findItem(val);
if (item) {
_this.itemsList.select(item);
}
else {
/** @type {?} */
var isValObject = isObject(val);
/** @type {?} */
var isPrimitive = !isValObject && !_this.bindValue;
if ((isValObject || isPrimitive)) {
_this.itemsList.select(_this.itemsList.mapItem(val, null));
}
else if (_this.bindValue) {
item = (_a = {},
_a[_this.bindLabel] = null,
_a[_this.bindValue] = val,
_a);
_this.itemsList.select(_this.itemsList.mapItem(item, null));
}
}
};
if (this.multiple) {
(/** @type {?} */ (ngModel)).forEach(function (item) { return select(item); });
}
else {
select(ngModel);
}
};
/**
* @return {?}
*/
NgSelectComponent.prototype._handleKeyPresses = /**
* @return {?}
*/
function () {
var _this = this;
if (this.searchable) {
return;
}
this._keyPress$
.pipe(takeUntil(this._destroy$), tap(function (letter) { return _this._pressedKeys.push(letter); }), debounceTime(200), filter(function () { return _this._pressedKeys.length > 0; }), map(function () { return _this._pressedKeys.join(''); }))
.subscribe(function (term) {
/** @type {?} */
var item = _this.itemsList.findByLabel(term);
if (item) {
if (_this.isOpen) {
_this.itemsList.markItem(item);
_this._cd.markForCheck();
}
else {
_this.select(item);
}
}
_this._pressedKeys = [];
});
};
/**
* @return {?}
*/
NgSelectComponent.prototype._updateNgModel = /**
* @return {?}
*/
function () {
var e_1, _a;
/** @type {?} */
var model = [];
try {
for (var _b = tslib_1.__values(this.selectedItems), _c = _b.next(); !_c.done; _c = _b.next()) {
var item = _c.value;
if (this.bindValue) {
/** @type {?} */
var resolvedValue = null;
if (item.children) {
resolvedValue = item.value[this.groupBy];
}
else {
resolvedValue = this.itemsList.resolveNested(item.value, this.bindValue);
}
model.push(resolvedValue);
}
else {
model.push(item.value);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
/** @type {?} */
var selected = this.selectedItems.map(function (x) { return 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();
};
/**
* @return {?}
*/
NgSelectComponent.prototype._clearSearch = /**
* @return {?}
*/
function () {
if (!this.filterValue) {
return;
}
this.filterValue = null;
this.itemsList.resetFilteredItems();
};
/**
* @return {?}
*/
NgSelectComponent.prototype._scrollToMarked = /**
* @return {?}
*/
function () {
if (!this.isOpen || !this.dropdownPanel) {
return;
}
this.dropdownPanel.scrollInto(this.itemsList.markedItem);
};
/**
* @return {?}
*/
NgSelectComponent.prototype._scrollToTag = /**
* @return {?}
*/
function () {
if (!this.isOpen || !this.dropdownPanel) {
return;
}
this.dropdownPanel.scrollIntoTag();
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype._handleTab = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (!this.isOpen) {
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();
}
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype._handleEnter = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (this.isOpen || this._manualOpen) {
if (this.itemsList.markedItem) {
this.toggleItem(this.itemsList.markedItem);
}
else if (this.showAddTag) {
this.selectTag();
}
}
else {
this.open();
}
$event.preventDefault();
$event.stopPropagation();
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype._handleSpace = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (this.isOpen || this._manualOpen) {
return;
}
this.open();
$event.preventDefault();
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype._handleArrowDown = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (this._nextItemIsTag(+1)) {
this.itemsList.unmarkItem();
this._scrollToTag();
}
else {
this.itemsList.markNextItem();
this._scrollToMarked();
}
this.open();
$event.preventDefault();
};
/**
* @param {?} $event
* @return {?}
*/
NgSelectComponent.prototype._handleArrowUp = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (!this.isOpen) {
return;
}
if (this._nextItemIsTag(-1)) {
this.itemsList.unmarkItem();
this._scrollToTag();
}
else {
this.itemsList.markPreviousItem();
this._scrollToMarked();
}
$event.preventDefault();
};
/**
* @param {?} nextStep
* @return {?}
*/
NgSelectComponent.prototype._nextItemIsTag = /**
* @param {?} nextStep
* @return {?}
*/
function (nextStep) {
/** @type {?} */
var nextIndex = this.itemsList.markedIndex + nextStep;
return this.addTag && this.filterValue
&& this.itemsList.markedItem
&& (nextIndex < 0 || nextIndex === this.itemsList.filteredItems.length);
};
/**
* @return {?}
*/
NgSelectComponent.prototype._handleBackspace = /**
* @return {?}
*/
function () {
if (this.filterValue || !this.clearable || !this.hasValue) {
return;
}
if (this.multiple) {
this.unselect(this.itemsList.lastSelectedItem);
}
else {
this.clearModel();
}
};
Object.defineProperty(NgSelectComponent.prototype, "_isTypeahead", {
get: /**
* @return {?}
*/
function () {
return this.typeahead && this.typeahead.observers.length > 0;
},
enumerable: true,
configurable: true
});
/**
* @param {?} config
* @return {?}
*/
NgSelectComponent.prototype._mergeGlobalConfig = /**
* @param {?} config
* @return {?}
*/
function (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;
};
NgSelectComponent.decorators = [
{ type: Component, args: [{
selector: 'ng-select',
template: "<div (mousedown)=\"handleMousedown($event)\" [class.ng-has-value]=\"hasValue\" class=\"ng-select-container\">\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\">\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\">{{item.label}}</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 #filterInput\n type=\"text\"\n autocomplete=\"{{dropdownId}}\"\n [attr.id]=\"labelForId\"\n [attr.tabindex]=\"tabIndex\"\n [readOnly]=\"!searchable\"\n [disabled]=\"disabled\"\n [value]=\"filterValue\"\n (input)=\"filter(filterInput.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 <div class=\"ng-spinner-loader\" *ngIf=\"loading\"></div>\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 [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]=\"classes\"\n [id]=\"dropdownId\">\n\n <ng-container>\n <div class=\"ng-option\" [attr.role]=\"item.children ? 'group' : 'option'\" (click)=\"toggleItem(item)\" (mousedown)=\"$event.preventDefault()\" (mouseover)=\"onItemHover(item)\"\n *ngFor=\"let item of viewPortItems\"\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.id]=\"item?.htmlId\">\n\n <ng-template #defaultOptionTemplate>\n <span class=\"ng-option-label\">{{item.label}}</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: filterValue }\">\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>\"{{filterValue}}\"</span>\n </ng-template>\n\n <ng-template\n [ngTemplateOutlet]=\"tagTemplate || defaultTagTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: filterValue }\">\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: filterValue }\">\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: filterValue }\">\n </ng-template>\n </ng-container>\n\n</ng-dropdown-panel>\n",
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return NgSelectComponent; }),
multi: true
}],
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:flex;outline:0;overflow:hidden;position:relative;width:100%}.ng-select .ng-select-container .ng-value-container{display:flex;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{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}.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}"]
}] }
];
/** @nocollapse */
NgSelectComponent.ctorParameters = function () { return [
{ type: String, decorators: [{ type: Attribute, args: ['class',] }] },
{ type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
{ type: undefined, decorators: [{ type: Inject, args: [NG_SELECT_DEFAULT_CONFIG,] }] },
{ type: undefined, decorators: [{ type: Inject, args: [SELECTION_MODEL_FACTORY,] }] },
{ type: ElementRef },
{ type: ChangeDetectorRef },
{ type: ConsoleService }
]; };
NgSelectComponent.propDecorators = {
items: [{ type: Input }],
bindLabel: [{ type: Input }],
bindValue: [{ type: Input }],
clearable: [{ type: Input }],
markFirst: [{ type: Input }],
placeholder: [{ type: Input }],
notFoundText: [{ type: Input }],
typeToSearchText: [{ type: Input }],
addTagText: [{ type: Input }],
loadingText: [{ type: Input }],
clearAllText: [{ type: Input }],
dropdownPosition: [{ type: Input }],
appendTo: [{ type: Input }],
loading: [{ type: Input }],
closeOnSelect: [{ type: Input }],
hideSelected: [{ type: Input }],
selectOnTab: [{ type: Input }],
maxSelectedItems: [{ type: Input }],
groupBy: [{ type: Input }],
bufferAmount: [{ type: Input }],
virtualScroll: [{ type: Input }],
selectableGroup: [{ type: Input }],
selectableGroupAsModel: [{ type: Input }],
searchFn: [{ type: Input }],
clearSearchOnAdd: [{ type: Input }],
labelForId: [{ 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',] }],
isOpen: [{ type: Input }, { type: HostBinding, args: ['class.ng-select-opened',] }],
compareWith: [{ 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 },] }],
optgroupTemplate: [{ type: ContentChild, args: [NgOptgroupTemplateDirective, { read: TemplateRef },] }],
labelTemplate: [{ type: ContentChild, args: [NgLabelTemplateDirective, { read: TemplateRef },] }],
multiLabelTemplate: [{ type: ContentChild, args: [NgMultiLabelTemplateDirective, { read: TemplateRef },] }],
headerTemplate: [{ type: ContentChild, args: [NgHeaderTemplateDirective, { read: TemplateRef },] }],
footerTemplate: [{ type: ContentChild, args: [NgFooterTemplateDirective, { read: TemplateRef },] }],
notFoundTemplate: [{ type: ContentChild, args: [NgNotFoundTemplateDirective, { read: TemplateRef },] }],
typeToSearchTemplate: [{ type: ContentChild, args: [NgTypeToSearchTemplateDirective, { read: TemplateRef },] }],
loadingTextTemplate: [{ type: ContentChild, args: [NgLoadingTextTemplateDirective, { read: TemplateRef },] }],
tagTemplate: [{ type: ContentChild, args: [NgTagTemplateDirective, { read: TemplateRef },] }],
dropdownPanel: [{ type: ViewChild, args: [forwardRef(function () { return NgDropdownPanelComponent; }),] }],
ngOptions: [{ type: ContentChildren, args: [NgOptionComponent, { descendants: true },] }],
filterInput: [{ type: ViewChild, args: ['filterInput',] }],
disabled: [{ type: HostBinding, args: ['class.ng-select-disabled',] }],
filtered: [{ type: HostBinding, args: ['class.ng-select-filtered',] }],
handleKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }]
};
return NgSelectComponent;
}());
export { NgSelectComponent };
if (false) {
/** @type {?} */
NgSelectComponent.prototype.items;
/** @type {?} */
NgSelectComponent.prototype.bindLabel;
/** @type {?} */
NgSelectComponent.prototype.bindValue;
/** @type {?} */
NgSelectComponent.prototype.clearable;
/** @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.dropdownPosition;
/** @type {?} */
NgSelectComponent.prototype.appendTo;
/** @type {?} */
NgSelectComponent.prototype.loading;
/** @type {?} */
NgSelectComponent.prototype.closeOnSelect;
/** @type {?} */
NgSelectComponent.prototype.hideSelected;
/** @type {?} */
NgSelectComponent.prototype.selectOnTab;
/** @type {?} */
NgSelectComponent.prototype.maxSelectedItems;
/** @type {?} */
NgSelectComponent.prototype.groupBy;
/** @type {?} */
NgSelectComponent.prototype.bufferAmount;
/** @type {?} */
NgSelectComponent.prototype.virtualScroll;
/** @type {?} */
NgSelectComponent.prototype.selectableGroup;
/** @type {?} */
NgSelectComponent.prototype.selectableGroupAsModel;
/** @type {?} */
NgSelectComponent.prototype.searchFn;
/** @type {?} */
NgSelectComponent.prototype.clearSearchOnAdd;
/** @type {?} */
NgSelectComponent.prototype.labelForId;
/** @type {?} */
NgSelectComponent.prototype.typeahead;
/** @type {?} */
NgSelectComponent.prototype.multiple;
/** @type {?} */
NgSelectComponent.prototype.addTag;
/** @type {?} */
NgSelectComponent.prototype.searchable;
/** @type {?} */
NgSelectComponent.prototype.isOpen;
/** @type {?} */
NgSelectComponent.prototype.blurEvent;
/** @type {?} */
NgSelectComponent.prototype.focusEvent;
/** @type {?} */
NgSelectComponent.prototype.changeEvent;
/** @type {?} */
NgSelectComponent.prototype.openEvent;
/** @type {?} */
NgSelectComponent.prototype.closeEvent;
/** @type {?} */
NgSelectComponent.prototype.searchEvent;
/** @type {?} */
NgSelectComponent.prototype.clearEvent;
/** @type {?} */
NgSelectComponent.prototype.addEvent;
/** @type {?} */
NgSelectComponent.prototype.removeEvent;
/** @type {?} */
NgSelectComponent.prototype.scroll;
/** @type {?} */
NgSelectComponent.prototype.scrollToEnd;
/** @type {?} */
NgSelectComponent.prototype.optionTemplate;
/** @type {?} */
NgSelectComponent.prototype.optgroupTemplate;
/** @type {?} */
NgSelectComponent.prototype.labelTemplate;
/** @type {?} */
NgSelectComponent.prototype.multiLabelTemplate;
/** @type {?} */
NgSelectComponent.prototype.headerTemplate;
/** @type {?} */
NgSelectComponent.prototype.footerTemplate;
/** @type {?} */
NgSelectComponent.prototype.notFoundTemplate;
/** @type {?} */
NgSelectComponent.prototype.typeToSearchTemplate;
/** @type {?} */
NgSelectComponent.prototype.loadingTextTemplate;
/** @type {?} */
NgSelectComponent.prototype.tagTemplate;
/** @type {?} */
NgSelectComponent.prototype.dropdownPanel;
/** @type {?} */
NgSelectComponent.prototype.ngOptions;
/** @type {?} */
NgSelectComponent.prototype.filterInput;
/** @type {?} */
NgSelectComponent.prototype.disabled;
/**