UNPKG

@ng-select/ng-select

Version:

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

824 lines 164 kB
import { Component, forwardRef, Input, Output, EventEmitter, ContentChild, TemplateRef, ViewEncapsulation, HostListener, HostBinding, ViewChild, ChangeDetectionStrategy, Inject, ContentChildren, InjectionToken, Attribute, booleanAttribute, numberAttribute } 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 { 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 { NgDropdownPanelService } from './ng-dropdown-panel.service'; import * as i0 from "@angular/core"; import * as i1 from "./config.service"; import * as i2 from "./console.service"; import * as i3 from "@angular/common"; import * as i4 from "./ng-dropdown-panel.component"; import * as i5 from "./ng-templates.directive"; export const SELECTION_MODEL_FACTORY = new InjectionToken('ng-select-selection-model'); export class NgSelectComponent { get items() { return this._items; } ; set items(value) { this._itemsAreUsed = true; this._items = value ?? []; } ; get compareWith() { return this._compareWith; } set compareWith(fn) { if (fn !== undefined && fn !== null && !isFunction(fn)) { throw Error('`compareWith` must be a function.'); } this._compareWith = fn; } get clearSearchOnAdd() { if (isDefined(this._clearSearchOnAdd)) { return this._clearSearchOnAdd; } else if (isDefined(this.config.clearSearchOnAdd)) { return this.config.clearSearchOnAdd; } return this.closeOnSelect; } ; set clearSearchOnAdd(value) { this._clearSearchOnAdd = value; } ; get deselectOnClick() { if (isDefined(this._deselectOnClick)) { return this._deselectOnClick; } else if (isDefined(this.config.deselectOnClick)) { return this.config.deselectOnClick; } return this.multiple; } ; set deselectOnClick(value) { this._deselectOnClick = value; } ; get disabled() { return this.readonly || this._disabled; } ; get filtered() { return (!!this.searchTerm && this.searchable || this._isComposing); } ; get single() { return !this.multiple; } ; get _editableSearchTerm() { return this.editableSearchTerm && !this.multiple; } constructor(classes, autoFocus, config, newSelectionModel, _elementRef, _cd, _console) { this.classes = classes; this.autoFocus = autoFocus; this.config = config; 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.editableSearchTerm = false; this.keyDownFn = (_) => 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.useDefaultClass = true; 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 = (_) => { }; this._onTouched = () => { }; this.clearItem = (item) => { const option = this.selectedItems.find(x => x.value === item); this.unselect(option); }; this.trackByOption = (_, item) => { if (this.trackByFn) { return this.trackByFn(item.value); } return item; }; this._mergeGlobalConfig(config); this.itemsList = new ItemsList(this, newSelectionModel()); this.element = _elementRef.nativeElement; } get selectedItems() { return this.itemsList.selectedItems; } get selectedValues() { return this.selectedItems.map(x => x.value); } get hasValue() { return this.selectedItems.length > 0; } get currentPanelPosition() { if (this.dropdownPanel) { return this.dropdownPanel.currentPosition; } return undefined; } ngOnInit() { this._handleKeyPresses(); this._setInputAttributes(); } 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); } } ngAfterViewInit() { if (!this._itemsAreUsed) { this.escapeHTML = false; this._setItemsFromNgOptions(); } if (isDefined(this.autoFocus)) { this.focus(); } } ngOnDestroy() { this._destroy$.next(); this._destroy$.complete(); } handleKeyDown($event) { 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()); } } handleKeyCode($event) { const target = $event.target; if (this.clearButton && this.clearButton.nativeElement === target) { this.handleKeyCodeClear($event); } else { this.handleKeyCodeInput($event); } } handleKeyCodeInput($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; } } handleKeyCodeClear($event) { switch ($event.which) { case KeyCode.Enter: this.handleClearClick(); $event.preventDefault(); break; } } handleMousedown($event) { const target = $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(); } } handleArrowClick() { if (this.isOpen) { this.close(); } else { this.open(); } } handleClearClick() { if (this.hasValue) { this.itemsList.clearSelected(true); this._updateNgModel(); } this._clearSearch(); this.focus(); this.clearEvent.emit(); this._onSelectionChanged(); } clearModel() { if (!this.clearable) { return; } this.itemsList.clearSelected(); this._updateNgModel(); } writeValue(value) { this.itemsList.clearSelected(); this._handleWriteValue(value); this._cd.markForCheck(); } registerOnChange(fn) { this._onChange = fn; } registerOnTouched(fn) { this._onTouched = fn; } setDisabledState(state) { this._disabled = state; this._cd.markForCheck(); } toggle() { if (!this.isOpen) { this.open(); } else { this.close(); } } open() { if (this.disabled || this.isOpen || 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(); } close() { if (!this.isOpen || this._manualOpen) { return; } this.isOpen = false; this._isComposing = false; if (!this._editableSearchTerm) { this._clearSearch(); } else { this.itemsList.resetFilteredItems(); } this.itemsList.unmarkItem(); this._onTouched(); this.closeEvent.emit(); this._cd.markForCheck(); } toggleItem(item) { if (!item || item.disabled || this.disabled) { return; } if (this.deselectOnClick && item.selected) { this.unselect(item); } else { this.select(item); } if (this._editableSearchTerm) { this._setSearchTermFromItems(); } this._onSelectionChanged(); } select(item) { if (!item.selected) { this.itemsList.select(item); if (this.clearSearchOnAdd && !this._editableSearchTerm) { this._clearSearch(); } this._updateNgModel(); if (this.multiple) { this.addEvent.emit(item.value); } } if (this.closeOnSelect || this.itemsList.noItemsToSelect) { this.close(); } } focus() { this.searchInput.nativeElement.focus(); } blur() { this.searchInput.nativeElement.blur(); } unselect(item) { if (!item) { return; } this.itemsList.unselect(item); this.focus(); this._updateNgModel(); this.removeEvent.emit(item.value); } selectTag() { let tag; if (isFunction(this.addTag)) { tag = this.addTag(this.searchTerm); } else { tag = this._primitive ? this.searchTerm : { [this.bindLabel]: this.searchTerm }; } const handleTag = (item) => this._isTypeahead || !this.isOpen ? this.itemsList.mapItem(item, null) : this.itemsList.addItem(item); if (isPromise(tag)) { tag.then(item => this.select(handleTag(item))).catch(() => { }); } else if (tag) { this.select(handleTag(tag)); } } showClear() { return this.clearable && (this.hasValue || this.searchTerm) && !this.disabled; } focusOnClear() { this.blur(); if (this.clearButton) { this.clearButton.nativeElement.focus(); } } get showAddTag() { if (!this._validTerm) { return false; } const term = this.searchTerm.toLowerCase().trim(); return this.addTag && (!this.itemsList.filteredItems.some(x => x.label.toLowerCase() === term) && (!this.hideSelected && this.isOpen || !this.selectedItems.some(x => x.label.toLowerCase() === term))) && !this.loading; } showNoItemsFound() { const empty = this.itemsList.filteredItems.length === 0; return ((empty && !this._isTypeahead && !this.loading) || (empty && this._isTypeahead && this._validTerm && !this.loading)) && !this.showAddTag; } showTypeToSearch() { const empty = this.itemsList.filteredItems.length === 0; return empty && this._isTypeahead && !this._validTerm && !this.loading; } onCompositionStart() { this._isComposing = true; } onCompositionEnd(term) { this._isComposing = false; if (this.searchWhileComposing) { return; } this.filter(term); } filter(term) { if (this._isComposing && !this.searchWhileComposing) { return; } this.searchTerm = term; if (this._isTypeahead && (this._validTerm || this.minTermLength === 0)) { 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(x => x.value) }); this.open(); } onInputFocus($event) { if (this.focused) { return; } if (this._editableSearchTerm) { this._setSearchTermFromItems(); } this.element.classList.add('ng-select-focused'); this.focusEvent.emit($event); this.focused = true; } onInputBlur($event) { this.element.classList.remove('ng-select-focused'); this.blurEvent.emit($event); if (!this.isOpen && !this.disabled) { this._onTouched(); } if (this._editableSearchTerm) { this._setSearchTermFromItems(); } this.focused = false; } onItemHover(item) { if (item.disabled) { return; } this.itemsList.markItem(item); } detectChanges() { if (!this._cd.destroyed) { this._cd.detectChanges(); } } _setSearchTermFromItems() { const selected = this.selectedItems && this.selectedItems[0]; this.searchTerm = (selected && selected.label) || null; } _setItems(items) { 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); } } _setItemsFromNgOptions() { const mapNgOptions = (options) => { this.items = options.map(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(); }; const handleOptionChange = () => { const changedOrDestroyed = merge(this.ngOptions.changes, this._destroy$); merge(...this.ngOptions.map(option => option.stateChange$)) .pipe(takeUntil(changedOrDestroyed)) .subscribe(option => { 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(options => { this.bindLabel = this._defaultLabel; mapNgOptions(options); handleOptionChange(); }); } _isValidWriteValue(value) { if (!isDefined(value) || (this.multiple && value === '') || Array.isArray(value) && value.length === 0) { return false; } const validateBinding = (item) => { if (!isDefined(this.compareWith) && isObject(item) && this.bindValue) { this._console.warn(`Setting object(${JSON.stringify(item)}) as your model with bindValue is not allowed unless [compareWith] is used.`); 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(item => validateBinding(item)); } else { return validateBinding(value); } } _handleWriteValue(ngModel) { if (!this._isValidWriteValue(ngModel)) { return; } const select = (val) => { let item = this.itemsList.findItem(val); if (item) { this.itemsList.select(item); } else { const isValObject = isObject(val); 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) { ngModel.forEach(item => select(item)); } else { select(ngModel); } } _handleKeyPresses() { if (this.searchable) { return; } this._keyPress$ .pipe(takeUntil(this._destroy$), tap(letter => this._pressedKeys.push(letter)), debounceTime(200), filter(() => this._pressedKeys.length > 0), map(() => this._pressedKeys.join(''))) .subscribe(term => { const item = this.itemsList.findByLabel(term); if (item) { if (this.isOpen) { this.itemsList.markItem(item); this._scrollToMarked(); this._cd.markForCheck(); } else { this.select(item); } } this._pressedKeys = []; }); } _setInputAttributes() { const input = this.searchInput.nativeElement; const attributes = { 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]); } } _updateNgModel() { const model = []; for (const item of this.selectedItems) { if (this.bindValue) { let value = null; if (item.children) { const groupKey = this.groupValue ? this.bindValue : this.groupBy; value = item.value[groupKey || this.groupBy]; } else { value = this.itemsList.resolveNested(item.value, this.bindValue); } model.push(value); } else { model.push(item.value); } } const selected = this.selectedItems.map(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(); } _clearSearch() { if (!this.searchTerm) { return; } this._changeSearch(null); this.itemsList.resetFilteredItems(); } _changeSearch(searchTerm) { this.searchTerm = searchTerm; if (this._isTypeahead) { this.typeahead.next(searchTerm); } } _scrollToMarked() { if (!this.isOpen || !this.dropdownPanel) { return; } this.dropdownPanel.scrollTo(this.itemsList.markedItem); } _scrollToTag() { if (!this.isOpen || !this.dropdownPanel) { return; } this.dropdownPanel.scrollToTag(); } _onSelectionChanged() { if (this.isOpen && this.deselectOnClick && this.appendTo) { // Make sure items are rendered. this._cd.detectChanges(); this.dropdownPanel.adjustPosition(); } } _handleTab($event) { if (this.isOpen === false) { if (this.showClear() && !$event.shiftKey) { this.focusOnClear(); $event.preventDefault(); } else if (!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(); } } _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(); } _handleSpace($event) { if (this.isOpen || this._manualOpen) { return; } this.open(); $event.preventDefault(); } _handleArrowDown($event) { if (this._nextItemIsTag(+1)) { this.itemsList.unmarkItem(); this._scrollToTag(); } else { this.itemsList.markNextItem(); this._scrollToMarked(); } this.open(); $event.preventDefault(); } _handleArrowUp($event) { if (!this.isOpen) { return; } if (this._nextItemIsTag(-1)) { this.itemsList.unmarkItem(); this._scrollToTag(); } else { this.itemsList.markPreviousItem(); this._scrollToMarked(); } $event.preventDefault(); } _nextItemIsTag(nextStep) { const nextIndex = this.itemsList.markedIndex + nextStep; return this.addTag && this.searchTerm && this.itemsList.markedItem && (nextIndex < 0 || nextIndex === this.itemsList.filteredItems.length); } _handleBackspace() { if (this.searchTerm || !this.clearable || !this.clearOnBackspace || !this.hasValue) { return; } if (this.multiple) { this.unselect(this.itemsList.lastSelectedItem); } else { this.clearModel(); } } get _isTypeahead() { return this.typeahead && this.typeahead.observers.length > 0; } get _validTerm() { const term = this.searchTerm && this.searchTerm.trim(); return term && term.length >= this.minTermLength; } _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.bindLabel = this.bindLabel || config.bindLabel; this.appearance = this.appearance || config.appearance; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: NgSelectComponent, deps: [{ token: 'class', attribute: true }, { token: 'autofocus', attribute: true }, { token: i1.NgSelectConfig }, { token: SELECTION_MODEL_FACTORY }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i2.ConsoleService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.0.0", type: NgSelectComponent, selector: "ng-select", inputs: { bindLabel: "bindLabel", bindValue: "bindValue", markFirst: ["markFirst", "markFirst", booleanAttribute], placeholder: "placeholder", notFoundText: "notFoundText", typeToSearchText: "typeToSearchText", addTagText: "addTagText", loadingText: "loadingText", clearAllText: "clearAllText", appearance: "appearance", dropdownPosition: "dropdownPosition", appendTo: "appendTo", loading: ["loading", "loading", booleanAttribute], closeOnSelect: ["closeOnSelect", "closeOnSelect", booleanAttribute], hideSelected: ["hideSelected", "hideSelected", booleanAttribute], selectOnTab: ["selectOnTab", "selectOnTab", booleanAttribute], openOnEnter: ["openOnEnter", "openOnEnter", booleanAttribute], maxSelectedItems: ["maxSelectedItems", "maxSelectedItems", numberAttribute], groupBy: "groupBy", groupValue: "groupValue", bufferAmount: ["bufferAmount", "bufferAmount", numberAttribute], virtualScroll: ["virtualScroll", "virtualScroll", booleanAttribute], selectableGroup: ["selectableGroup", "selectableGroup", booleanAttribute], selectableGroupAsModel: ["selectableGroupAsModel", "selectableGroupAsModel", booleanAttribute], searchFn: "searchFn", trackByFn: "trackByFn", clearOnBackspace: ["clearOnBackspace", "clearOnBackspace", booleanAttribute], labelForId: "labelForId", inputAttrs: "inputAttrs", tabIndex: ["tabIndex", "tabIndex", numberAttribute], readonly: ["readonly", "readonly", booleanAttribute], searchWhileComposing: ["searchWhileComposing", "searchWhileComposing", booleanAttribute], minTermLength: ["minTermLength", "minTermLength", numberAttribute], editableSearchTerm: ["editableSearchTerm", "editableSearchTerm", booleanAttribute], keyDownFn: "keyDownFn", typeahead: "typeahead", multiple: ["multiple", "multiple", booleanAttribute], addTag: "addTag", searchable: ["searchable", "searchable", booleanAttribute], clearable: ["clearable", "clearable", booleanAttribute], isOpen: ["isOpen", "isOpen", booleanAttribute], items: "items", compareWith: "compareWith", clearSearchOnAdd: "clearSearchOnAdd", deselectOnClick: "deselectOnClick" }, outputs: { blurEvent: "blur", focusEvent: "focus", changeEvent: "change", openEvent: "open", closeEvent: "close", searchEvent: "search", clearEvent: "clear", addEvent: "add", removeEvent: "remove", scroll: "scroll", scrollToEnd: "scrollToEnd" }, host: { listeners: { "keydown": "handleKeyDown($event)" }, properties: { "class.ng-select-typeahead": "this.typeahead", "class.ng-select-multiple": "this.multiple", "class.ng-select-taggable": "this.addTag", "class.ng-select-searchable": "this.searchable", "class.ng-select-clearable": "this.clearable", "class.ng-select-opened": "this.isOpen", "class.ng-select": "this.useDefaultClass", "class.ng-select-disabled": "this.disabled", "class.ng-select-filtered": "this.filtered", "class.ng-select-single": "this.single" } }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NgSelectComponent), multi: true }, NgDropdownPanelService], queries: [{ propertyName: "optionTemplate", first: true, predicate: NgOptionTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "optgroupTemplate", first: true, predicate: NgOptgroupTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "labelTemplate", first: true, predicate: NgLabelTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "multiLabelTemplate", first: true, predicate: NgMultiLabelTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "headerTemplate", first: true, predicate: NgHeaderTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "footerTemplate", first: true, predicate: NgFooterTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "notFoundTemplate", first: true, predicate: NgNotFoundTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "typeToSearchTemplate", first: true, predicate: NgTypeToSearchTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "loadingTextTemplate", first: true, predicate: NgLoadingTextTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "tagTemplate", first: true, predicate: NgTagTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "loadingSpinnerTemplate", first: true, predicate: NgLoadingSpinnerTemplateDirective, descendants: true, read: TemplateRef }, { propertyName: "ngOptions", predicate: NgOptionComponent, descendants: true }], viewQueries: [{ propertyName: "dropdownPanel", first: true, predicate: i0.forwardRef(() => NgDropdownPanelComponent), descendants: true }, { propertyName: "searchInput", first: true, predicate: ["searchInput"], descendants: true, static: true }, { propertyName: "clearButton", first: true, predicate: ["clearButton"], descendants: true }], usesOnChanges: true, ngImport: i0, 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 @if ((!multiLabelTemplate || !multiple) && selectedItems.length > 0) {\n @for (item of selectedItems; track trackByOption($index, item)) {\n <div [class.ng-value-disabled]=\"item.disabled\" class=\"ng-value\">\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 <ng-template\n [ngTemplateOutlet]=\"labelTemplate || defaultLabelTemplate\"\n [ngTemplateOutletContext]=\"{ item: item.value, clear: clearItem, label: item.label }\">\n </ng-template>\n </div>\n }\n }\n\n @if (multiple && multiLabelTemplate && selectedValues.length > 0) {\n <ng-template\n [ngTemplateOutlet]=\"multiLabelTemplate\"\n [ngTemplateOutletContext]=\"{ items: selectedValues, clear: clearItem }\">\n </ng-template>\n }\n\n <div class=\"ng-input\"\n role=\"combobox\" \n [attr.aria-expanded]=\"isOpen\" \n [attr.aria-owns]=\"isOpen ? dropdownId : null\" \n aria-haspopup=\"listbox\">\n\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 [attr.aria-activedescendant]=\"isOpen ? itemsList?.markedItem?.htmlId : null\"\n aria-autocomplete=\"list\"\n [attr.aria-controls]=\"isOpen ? dropdownId : null\">\n </div>\n </div>\n\n @if (loading) {\n <ng-template #defaultLoadingSpinnerTemplate>\n <div class=\"ng-spinner-loader\"></div>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"loadingSpinnerTemplate || defaultLoadingSpinnerTemplate\">\n </ng-template>\n }\n\n @if (showClear()) {\n <span class=\"ng-clear-wrapper\" tabindex=\"0\" title=\"{{clearAllText}}\" #clearButton>\n <span class=\"ng-clear\" aria-hidden=\"true\">\u00D7</span>\n </span>\n }\n\n <span class=\"ng-arrow-wrapper\">\n <span class=\"ng-arrow\"></span>\n </span>\n</div>\n\n@if (isOpen) {\n <ng-dropdown-panel\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 role=\"listbox\"\n aria-label=\"Options list\">\n <ng-container>\n @for (item of viewPortItems; track trackByOption($index, item)) {\n <div class=\"ng-option\" [attr.role]=\"item.children ? 'group' : 'option'\" (click)=\"toggleItem(item)\"\n (mouseover)=\"onItemHover(item)\"\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 <ng-template #defaultOptionTemplate>\n <span class=\"ng-option-label\" [ngItemLabel]=\"item.label\" [escape]=\"escapeHTML\"></span>\n </ng-template>\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 @if (showAddTag) {\n <div class=\"ng-option\" [class.ng-option-marked]=\"!itemsList.markedItem\"\n (mouseover)=\"itemsList.unmarkItem()\" role=\"option\" (click)=\"selectTag()\">\n <ng-template #defaultTagTemplate>\n <span><span class=\"ng-tag-label\">{{ addTagText }}</span>\"{{ searchTerm }}\"</span>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"tagTemplate || defaultTagTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n </div>\n }\n </ng-container>\n @if (showNoItemsFound()) {\n <ng-template #defaultNotFoundTemplate>\n <div class=\"ng-option ng-option-disabled\">{{ notFoundText }}</div>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"notFoundTemplate || defaultNotFoundTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n }\n @if (showTypeToSearch()) {\n <ng-template #defaultTypeToSearchTemplate>\n <div class=\"ng-option ng-option-disabled\">{{ typeToSearchText }}</div>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"typeToSearchTemplate || defaultTypeToSearchTemplate\">\n </ng-template>\n }\n @if (loading && itemsList.filteredItems.length === 0) {\n <ng-template #defaultLoadingTextTemplate>\n <div class=\"ng-option ng-option-disabled\">{{ loadingText }}</div>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"loadingTextTemplate || defaultLoadingTextTemplate\"\n [ngTemplateOutletContext]=\"{ searchTerm: searchTerm }\">\n </ng-template>\n }\n </ng-dropdown-panel>\n}\n", styles: ["@charset \"UTF-8\";.ng-select{position:relative;display:block;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.ng-select div,.ng-select input,.ng-select span{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;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;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{cursor:default;display:flex;outline:none;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 transparent;border:0 none;box-shadow:none;outline:none;padding: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;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-placeholder{position:absolute}.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{z-index:1}.ng-select .ng-clear-wrapper{cursor:pointer;position:relative;width:17px;-webkit-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;transform:translateZ(0);animation:load8 .8s infinite linear}.ng-select .ng-spinner-loader:after{border-radius:50%;width:17px;height:17px}@-webkit-keyframes load8{0%{-webkit-transform:rotate(0deg);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes load8{0%{-webkit-transform:rotate(0deg);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}.ng-select .ng-arrow-wrapper{cursor:pointer;position:relative;text-align:center;-webkit-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;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;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 .ng-option-label:empty:before{content:\"\\200b\"}.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}\n"], dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: i4.NgDropdownPanelComponent, selector: "ng-dropdown-panel", inputs: ["items", "markedItem", "position", "appendTo", "bufferAmount", "virtualScroll", "headerTemplate", "footerTemplate", "filterValue"], outputs: ["update", "scroll", "scrollToEnd", "outsideClick"] }, { kind: "directive", type: i5.NgItemLabelDirective, selector: "[ngItemLabel]", inputs: ["ngItemLabel", "escape"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: NgSelectComponent, decorators: [{ type: Component, args: [{ selector: 'ng-select', providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NgSelectComponent), multi: true }, NgDropdownPanelService], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, 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 @if ((!multiLabelTemplate || !multiple) && selectedItems.length > 0) {\n @for (item of selectedItems; track trackByOption($index, item)) {\n <div [class.ng-value-disabled]=\"item.disabled\" class=\"ng-value\">\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 <ng-template\n [ngTemplateOutlet]=\"labelTemplate || defaultLabelTemplate\"\n [ngTemplateOutletContext]=\"{ item: item.value, clear: clearItem, label: item.label }\">\n </ng-template>\n </div>\n }\n }\n\n @if (multiple && multiLabelTemplate && selectedValues.length > 0) {\n <ng-template\n [ngTemplateOutlet]=\"multiLabelTemplate\"\n [ngTemplateOutletContext]=\"{ items: selectedValues, clear: clearItem }\">\n </ng-template>\n }\n\n <div class=\"ng-input\"\n role=\"combobox\" \n [attr.aria-expanded]=\"isOpen\" \n [attr.aria-owns]=\"isOpen ? dropdownId : null\" \n aria-haspopup=\"listbox\">\n\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 [attr.aria-activedescendant]=\"isOpen ? itemsList?.markedItem?.htmlId : null\"\n aria-autocomplete=\"list\"\n [attr.aria-controls]=\"isOpen ? dropdownId : null\">\n </div>\n </div>\n\n @if (loading) {\n <ng-template #defaultLoadingSpinnerTemplate>\n <div class=\"ng-spinner-loader\"></div>\n </ng-template>\n <ng-template\n [ngTemplateOutlet]=\"loadingSpinnerTemplate || defaultLoadingSpinnerTemplate\">\n </ng-template>\n }\n\n @if (showClear()) {\n <span class=\"ng-clear-wrapper\" tabindex=\"0\" title=\"{{clearAllText}}\" #clearButton>\n <span class=\"ng-clear\" aria-hidden=\"true\">\u00D7</span>\n </span>\n }\n\n <span class=\"ng-arrow-wrapper\">\n <span class=\"ng-arrow\"></span>\n </span>\n</div>\n\n@if (isOpen) {\n <ng-dropdown-panel\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\"