| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051 |
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __metadata = (this && this.__metadata) || function (k, v) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var scrolling_1 = require("@angular/cdk/scrolling");
- var core_1 = require("@angular/core");
- var animations_1 = require("@angular/animations");
- var common_1 = require("@angular/common");
- var shared_1 = require("../common/shared");
- var domhandler_1 = require("../dom/domhandler");
- var objectutils_1 = require("../utils/objectutils");
- var forms_1 = require("@angular/forms");
- var filterutils_1 = require("../utils/filterutils");
- var tooltip_1 = require("../tooltip/tooltip");
- exports.DROPDOWN_VALUE_ACCESSOR = {
- provide: forms_1.NG_VALUE_ACCESSOR,
- useExisting: core_1.forwardRef(function () { return Dropdown; }),
- multi: true
- };
- var DropdownItem = /** @class */ (function () {
- function DropdownItem() {
- this.onClick = new core_1.EventEmitter();
- }
- DropdownItem.prototype.onOptionClick = function (event) {
- this.onClick.emit({
- originalEvent: event,
- option: this.option
- });
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], DropdownItem.prototype, "option", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], DropdownItem.prototype, "selected", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], DropdownItem.prototype, "disabled", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], DropdownItem.prototype, "visible", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], DropdownItem.prototype, "itemSize", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", core_1.TemplateRef)
- ], DropdownItem.prototype, "template", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], DropdownItem.prototype, "onClick", void 0);
- DropdownItem = __decorate([
- core_1.Component({
- selector: 'p-dropdownItem',
- template: "\n <li (click)=\"onOptionClick($event)\" role=\"option\"\n [attr.aria-label]=\"option.label\"\n [ngStyle]=\"{'height': itemSize + 'px'}\"\n [ngClass]=\"{'ui-dropdown-item ui-corner-all':true,\n 'ui-state-highlight': selected,\n 'ui-state-disabled':(option.disabled),\n 'ui-dropdown-item-empty': !option.label||option.label.length === 0}\">\n <span *ngIf=\"!template\">{{option.label||'empty'}}</span>\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: option}\"></ng-container>\n </li>\n "
- })
- ], DropdownItem);
- return DropdownItem;
- }());
- exports.DropdownItem = DropdownItem;
- var Dropdown = /** @class */ (function () {
- function Dropdown(el, renderer, cd, zone) {
- this.el = el;
- this.renderer = renderer;
- this.cd = cd;
- this.zone = zone;
- this.scrollHeight = '200px';
- this.filterBy = 'label';
- this.resetFilterOnHide = false;
- this.dropdownIcon = 'pi pi-chevron-down';
- this.autoDisplayFirst = true;
- this.emptyFilterMessage = 'No results found';
- this.autoZIndex = true;
- this.baseZIndex = 0;
- this.showTransitionOptions = '225ms ease-out';
- this.hideTransitionOptions = '195ms ease-in';
- this.filterMatchMode = "contains";
- this.tooltip = '';
- this.tooltipPosition = 'right';
- this.tooltipPositionStyle = 'absolute';
- this.onChange = new core_1.EventEmitter();
- this.onFocus = new core_1.EventEmitter();
- this.onBlur = new core_1.EventEmitter();
- this.onClick = new core_1.EventEmitter();
- this.onShow = new core_1.EventEmitter();
- this.onHide = new core_1.EventEmitter();
- this.onModelChange = function () { };
- this.onModelTouched = function () { };
- this.viewPortOffsetTop = 0;
- }
- Object.defineProperty(Dropdown.prototype, "autoWidth", {
- get: function () {
- return this._autoWidth;
- },
- set: function (_autoWidth) {
- this._autoWidth = _autoWidth;
- console.log("Setting autoWidth has no effect as automatic width calculation is removed for better perfomance.");
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Dropdown.prototype, "disabled", {
- get: function () {
- return this._disabled;
- },
- set: function (_disabled) {
- if (_disabled)
- this.focused = false;
- this._disabled = _disabled;
- if (!this.cd.destroyed) {
- this.cd.detectChanges();
- }
- },
- enumerable: true,
- configurable: true
- });
- ;
- Dropdown.prototype.ngAfterContentInit = function () {
- var _this = this;
- this.templates.forEach(function (item) {
- switch (item.getType()) {
- case 'item':
- _this.itemTemplate = item.template;
- break;
- case 'selectedItem':
- _this.selectedItemTemplate = item.template;
- break;
- case 'group':
- _this.groupTemplate = item.template;
- break;
- default:
- _this.itemTemplate = item.template;
- break;
- }
- });
- };
- Dropdown.prototype.ngOnInit = function () {
- this.optionsToDisplay = this.options;
- this.updateSelectedOption(null);
- };
- Object.defineProperty(Dropdown.prototype, "options", {
- get: function () {
- return this._options;
- },
- set: function (val) {
- var opts = this.optionLabel ? objectutils_1.ObjectUtils.generateSelectItems(val, this.optionLabel) : val;
- this._options = opts;
- this.optionsToDisplay = this._options;
- this.updateSelectedOption(this.value);
- this.optionsChanged = true;
- if (this.filterValue && this.filterValue.length) {
- this.activateFilter();
- }
- },
- enumerable: true,
- configurable: true
- });
- Dropdown.prototype.ngAfterViewInit = function () {
- if (this.editable) {
- this.updateEditableLabel();
- }
- };
- Object.defineProperty(Dropdown.prototype, "label", {
- get: function () {
- return (this.selectedOption ? this.selectedOption.label : null);
- },
- enumerable: true,
- configurable: true
- });
- Dropdown.prototype.updateEditableLabel = function () {
- if (this.editableInputViewChild && this.editableInputViewChild.nativeElement) {
- this.editableInputViewChild.nativeElement.value = (this.selectedOption ? this.selectedOption.label : this.value || '');
- }
- };
- Dropdown.prototype.onItemClick = function (event) {
- var _this = this;
- var option = event.option;
- this.itemClick = true;
- if (!option.disabled) {
- this.selectItem(event, option);
- this.focusViewChild.nativeElement.focus();
- }
- setTimeout(function () {
- _this.hide(event);
- }, 150);
- };
- Dropdown.prototype.selectItem = function (event, option) {
- var _this = this;
- if (this.selectedOption != option) {
- this.selectedOption = option;
- this.value = option.value;
- this.filled = true;
- this.onModelChange(this.value);
- this.updateEditableLabel();
- this.onChange.emit({
- originalEvent: event.originalEvent,
- value: this.value
- });
- if (this.virtualScroll) {
- setTimeout(function () {
- _this.viewPortOffsetTop = _this.viewPort.measureScrollOffset();
- }, 1);
- }
- }
- };
- Dropdown.prototype.ngAfterViewChecked = function () {
- var _this = this;
- if (this.optionsChanged && this.overlayVisible) {
- this.optionsChanged = false;
- if (this.virtualScroll) {
- this.updateVirtualScrollSelectedIndex(true);
- }
- this.zone.runOutsideAngular(function () {
- setTimeout(function () {
- _this.alignOverlay();
- }, 1);
- });
- }
- if (this.selectedOptionUpdated && this.itemsWrapper) {
- if (this.virtualScroll && this.viewPort) {
- var range = this.viewPort.getRenderedRange();
- this.updateVirtualScrollSelectedIndex(false);
- if (range.start > this.virtualScrollSelectedIndex || range.end < this.virtualScrollSelectedIndex) {
- this.viewPort.scrollToIndex(this.virtualScrollSelectedIndex);
- }
- }
- var selectedItem = domhandler_1.DomHandler.findSingle(this.overlay, 'li.ui-state-highlight');
- if (selectedItem) {
- domhandler_1.DomHandler.scrollInView(this.itemsWrapper, domhandler_1.DomHandler.findSingle(this.overlay, 'li.ui-state-highlight'));
- }
- this.selectedOptionUpdated = false;
- }
- };
- Dropdown.prototype.writeValue = function (value) {
- if (this.filter) {
- this.resetFilter();
- }
- this.value = value;
- this.updateSelectedOption(value);
- this.updateEditableLabel();
- this.updateFilledState();
- this.cd.markForCheck();
- };
- Dropdown.prototype.resetFilter = function () {
- if (this.filterViewChild && this.filterViewChild.nativeElement) {
- this.filterValue = null;
- this.filterViewChild.nativeElement.value = '';
- }
- this.optionsToDisplay = this.options;
- };
- Dropdown.prototype.updateSelectedOption = function (val) {
- this.selectedOption = this.findOption(val, this.optionsToDisplay);
- if (this.autoDisplayFirst && !this.placeholder && !this.selectedOption && this.optionsToDisplay && this.optionsToDisplay.length && !this.editable) {
- this.selectedOption = this.optionsToDisplay[0];
- }
- this.selectedOptionUpdated = true;
- };
- Dropdown.prototype.registerOnChange = function (fn) {
- this.onModelChange = fn;
- };
- Dropdown.prototype.registerOnTouched = function (fn) {
- this.onModelTouched = fn;
- };
- Dropdown.prototype.setDisabledState = function (val) {
- this.disabled = val;
- };
- Dropdown.prototype.onMouseclick = function (event) {
- if (this.disabled || this.readonly) {
- return;
- }
- this.onClick.emit(event);
- this.selfClick = true;
- this.clearClick = domhandler_1.DomHandler.hasClass(event.target, 'ui-dropdown-clear-icon');
- if (!this.itemClick && !this.clearClick) {
- this.focusViewChild.nativeElement.focus();
- if (this.overlayVisible)
- this.hide(event);
- else
- this.show();
- this.cd.detectChanges();
- }
- };
- Dropdown.prototype.onEditableInputClick = function (event) {
- this.itemClick = true;
- this.bindDocumentClickListener();
- };
- Dropdown.prototype.onEditableInputFocus = function (event) {
- this.focused = true;
- this.hide(event);
- this.onFocus.emit(event);
- };
- Dropdown.prototype.onEditableInputChange = function (event) {
- this.value = event.target.value;
- this.updateSelectedOption(this.value);
- this.onModelChange(this.value);
- this.onChange.emit({
- originalEvent: event,
- value: this.value
- });
- };
- Dropdown.prototype.show = function () {
- this.overlayVisible = true;
- };
- Dropdown.prototype.onOverlayAnimationStart = function (event) {
- switch (event.toState) {
- case 'visible':
- this.overlay = event.element;
- var itemsWrapperSelector = this.virtualScroll ? '.cdk-virtual-scroll-viewport' : '.ui-dropdown-items-wrapper';
- this.itemsWrapper = domhandler_1.DomHandler.findSingle(this.overlay, itemsWrapperSelector);
- this.appendOverlay();
- if (this.autoZIndex) {
- this.overlay.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
- }
- this.alignOverlay();
- this.bindDocumentClickListener();
- this.bindDocumentResizeListener();
- if (this.options && this.options.length) {
- if (!this.virtualScroll) {
- var selectedListItem = domhandler_1.DomHandler.findSingle(this.itemsWrapper, '.ui-dropdown-item.ui-state-highlight');
- if (selectedListItem) {
- domhandler_1.DomHandler.scrollInView(this.itemsWrapper, selectedListItem);
- }
- }
- }
- if (this.filterViewChild && this.filterViewChild.nativeElement) {
- this.filterViewChild.nativeElement.focus();
- }
- this.onShow.emit(event);
- break;
- case 'void':
- this.onOverlayHide();
- break;
- }
- };
- Dropdown.prototype.scrollToSelectedVirtualScrollElement = function () {
- if (!this.virtualAutoScrolled) {
- if (this.viewPortOffsetTop) {
- this.viewPort.scrollToOffset(this.viewPortOffsetTop);
- }
- else if (this.virtualScrollSelectedIndex > -1) {
- this.viewPort.scrollToIndex(this.virtualScrollSelectedIndex);
- }
- }
- this.virtualAutoScrolled = true;
- };
- Dropdown.prototype.updateVirtualScrollSelectedIndex = function (resetOffset) {
- if (this.selectedOption && this.optionsToDisplay && this.optionsToDisplay.length) {
- if (resetOffset) {
- this.viewPortOffsetTop = 0;
- }
- this.virtualScrollSelectedIndex = this.findOptionIndex(this.selectedOption.value, this.optionsToDisplay);
- }
- };
- Dropdown.prototype.appendOverlay = function () {
- if (this.appendTo) {
- if (this.appendTo === 'body')
- document.body.appendChild(this.overlay);
- else
- domhandler_1.DomHandler.appendChild(this.overlay, this.appendTo);
- this.overlay.style.minWidth = domhandler_1.DomHandler.getWidth(this.containerViewChild.nativeElement) + 'px';
- }
- };
- Dropdown.prototype.restoreOverlayAppend = function () {
- if (this.overlay && this.appendTo) {
- this.el.nativeElement.appendChild(this.overlay);
- }
- };
- Dropdown.prototype.hide = function (event) {
- this.overlayVisible = false;
- if (this.filter && this.resetFilterOnHide) {
- this.resetFilter();
- }
- if (this.virtualScroll) {
- this.virtualAutoScrolled = false;
- }
- this.cd.markForCheck();
- this.onHide.emit(event);
- };
- Dropdown.prototype.alignOverlay = function () {
- if (this.overlay) {
- if (this.appendTo)
- domhandler_1.DomHandler.absolutePosition(this.overlay, this.containerViewChild.nativeElement);
- else
- domhandler_1.DomHandler.relativePosition(this.overlay, this.containerViewChild.nativeElement);
- }
- };
- Dropdown.prototype.onInputFocus = function (event) {
- this.focused = true;
- this.onFocus.emit(event);
- };
- Dropdown.prototype.onInputBlur = function (event) {
- this.focused = false;
- this.onModelTouched();
- this.onBlur.emit(event);
- };
- Dropdown.prototype.findPrevEnabledOption = function (index) {
- var prevEnabledOption;
- if (this.optionsToDisplay && this.optionsToDisplay.length) {
- for (var i = (index - 1); 0 <= i; i--) {
- var option = this.optionsToDisplay[i];
- if (option.disabled) {
- continue;
- }
- else {
- prevEnabledOption = option;
- break;
- }
- }
- if (!prevEnabledOption) {
- for (var i = this.optionsToDisplay.length - 1; i >= index; i--) {
- var option = this.optionsToDisplay[i];
- if (option.disabled) {
- continue;
- }
- else {
- prevEnabledOption = option;
- break;
- }
- }
- }
- }
- return prevEnabledOption;
- };
- Dropdown.prototype.findNextEnabledOption = function (index) {
- var nextEnabledOption;
- if (this.optionsToDisplay && this.optionsToDisplay.length) {
- for (var i = (index + 1); index < (this.optionsToDisplay.length - 1); i++) {
- var option = this.optionsToDisplay[i];
- if (option.disabled) {
- continue;
- }
- else {
- nextEnabledOption = option;
- break;
- }
- }
- if (!nextEnabledOption) {
- for (var i = 0; i < index; i++) {
- var option = this.optionsToDisplay[i];
- if (option.disabled) {
- continue;
- }
- else {
- nextEnabledOption = option;
- break;
- }
- }
- }
- }
- return nextEnabledOption;
- };
- Dropdown.prototype.onKeydown = function (event, search) {
- if (this.readonly || !this.optionsToDisplay || this.optionsToDisplay.length === null) {
- return;
- }
- switch (event.which) {
- //down
- case 40:
- if (!this.overlayVisible && event.altKey) {
- this.show();
- }
- else {
- if (this.group) {
- var selectedItemIndex = this.selectedOption ? this.findOptionGroupIndex(this.selectedOption.value, this.optionsToDisplay) : -1;
- if (selectedItemIndex !== -1) {
- var nextItemIndex = selectedItemIndex.itemIndex + 1;
- if (nextItemIndex < (this.optionsToDisplay[selectedItemIndex.groupIndex].items.length)) {
- this.selectItem(event, this.optionsToDisplay[selectedItemIndex.groupIndex].items[nextItemIndex]);
- this.selectedOptionUpdated = true;
- }
- else if (this.optionsToDisplay[selectedItemIndex.groupIndex + 1]) {
- this.selectItem(event, this.optionsToDisplay[selectedItemIndex.groupIndex + 1].items[0]);
- this.selectedOptionUpdated = true;
- }
- }
- else {
- this.selectItem(event, this.optionsToDisplay[0].items[0]);
- }
- }
- else {
- var selectedItemIndex = this.selectedOption ? this.findOptionIndex(this.selectedOption.value, this.optionsToDisplay) : -1;
- var nextEnabledOption = this.findNextEnabledOption(selectedItemIndex);
- if (nextEnabledOption) {
- this.selectItem(event, nextEnabledOption);
- this.selectedOptionUpdated = true;
- }
- }
- }
- event.preventDefault();
- break;
- //up
- case 38:
- if (this.group) {
- var selectedItemIndex = this.selectedOption ? this.findOptionGroupIndex(this.selectedOption.value, this.optionsToDisplay) : -1;
- if (selectedItemIndex !== -1) {
- var prevItemIndex = selectedItemIndex.itemIndex - 1;
- if (prevItemIndex >= 0) {
- this.selectItem(event, this.optionsToDisplay[selectedItemIndex.groupIndex].items[prevItemIndex]);
- this.selectedOptionUpdated = true;
- }
- else if (prevItemIndex < 0) {
- var prevGroup = this.optionsToDisplay[selectedItemIndex.groupIndex - 1];
- if (prevGroup) {
- this.selectItem(event, prevGroup.items[prevGroup.items.length - 1]);
- this.selectedOptionUpdated = true;
- }
- }
- }
- }
- else {
- var selectedItemIndex = this.selectedOption ? this.findOptionIndex(this.selectedOption.value, this.optionsToDisplay) : -1;
- var prevEnabledOption = this.findPrevEnabledOption(selectedItemIndex);
- if (prevEnabledOption) {
- this.selectItem(event, prevEnabledOption);
- this.selectedOptionUpdated = true;
- }
- }
- event.preventDefault();
- break;
- //space
- case 32:
- case 32:
- if (!this.overlayVisible) {
- this.show();
- event.preventDefault();
- }
- break;
- //enter
- case 13:
- if (!this.filter || (this.optionsToDisplay && this.optionsToDisplay.length > 0)) {
- this.hide(event);
- }
- event.preventDefault();
- break;
- //escape and tab
- case 27:
- case 9:
- this.hide(event);
- break;
- //search item based on keyboard input
- default:
- if (search) {
- this.search(event);
- }
- break;
- }
- };
- Dropdown.prototype.search = function (event) {
- var _this = this;
- if (this.searchTimeout) {
- clearTimeout(this.searchTimeout);
- }
- var char = event.key;
- this.previousSearchChar = this.currentSearchChar;
- this.currentSearchChar = char;
- if (this.previousSearchChar === this.currentSearchChar)
- this.searchValue = this.currentSearchChar;
- else
- this.searchValue = this.searchValue ? this.searchValue + char : char;
- var newOption;
- if (this.group) {
- var searchIndex = this.selectedOption ? this.findOptionGroupIndex(this.selectedOption.value, this.optionsToDisplay) : { groupIndex: 0, itemIndex: 0 };
- newOption = this.searchOptionWithinGroup(searchIndex);
- }
- else {
- var searchIndex = this.selectedOption ? this.findOptionIndex(this.selectedOption.value, this.optionsToDisplay) : -1;
- newOption = this.searchOption(++searchIndex);
- }
- if (newOption) {
- this.selectItem(event, newOption);
- this.selectedOptionUpdated = true;
- }
- this.searchTimeout = setTimeout(function () {
- _this.searchValue = null;
- }, 250);
- };
- Dropdown.prototype.searchOption = function (index) {
- var option;
- if (this.searchValue) {
- option = this.searchOptionInRange(index, this.optionsToDisplay.length);
- if (!option) {
- option = this.searchOptionInRange(0, index);
- }
- }
- return option;
- };
- Dropdown.prototype.searchOptionInRange = function (start, end) {
- for (var i = start; i < end; i++) {
- var opt = this.optionsToDisplay[i];
- if (opt.label.toLowerCase().startsWith(this.searchValue.toLowerCase())) {
- return opt;
- }
- }
- return null;
- };
- Dropdown.prototype.searchOptionWithinGroup = function (index) {
- var option;
- if (this.searchValue) {
- for (var i = index.groupIndex; i < this.optionsToDisplay.length; i++) {
- for (var j = (index.groupIndex === i) ? (index.itemIndex + 1) : 0; j < this.optionsToDisplay[i].items.length; j++) {
- var opt = this.optionsToDisplay[i].items[j];
- if (opt.label.toLowerCase().startsWith(this.searchValue.toLowerCase())) {
- return opt;
- }
- }
- }
- if (!option) {
- for (var i = 0; i <= index.groupIndex; i++) {
- for (var j = 0; j < ((index.groupIndex === i) ? index.itemIndex : this.optionsToDisplay[i].items.length); j++) {
- var opt = this.optionsToDisplay[i].items[j];
- if (opt.label.toLowerCase().startsWith(this.searchValue.toLowerCase())) {
- return opt;
- }
- }
- }
- }
- }
- return null;
- };
- Dropdown.prototype.findOptionIndex = function (val, opts) {
- var index = -1;
- if (opts) {
- for (var i = 0; i < opts.length; i++) {
- if ((val == null && opts[i].value == null) || objectutils_1.ObjectUtils.equals(val, opts[i].value, this.dataKey)) {
- index = i;
- break;
- }
- }
- }
- return index;
- };
- Dropdown.prototype.findOptionGroupIndex = function (val, opts) {
- var groupIndex, itemIndex;
- if (opts) {
- for (var i = 0; i < opts.length; i++) {
- groupIndex = i;
- itemIndex = this.findOptionIndex(val, opts[i].items);
- if (itemIndex !== -1) {
- break;
- }
- }
- }
- if (itemIndex !== -1) {
- return { groupIndex: groupIndex, itemIndex: itemIndex };
- }
- else {
- return -1;
- }
- };
- Dropdown.prototype.findOption = function (val, opts, inGroup) {
- if (this.group && !inGroup) {
- var opt = void 0;
- if (opts && opts.length) {
- for (var _i = 0, opts_1 = opts; _i < opts_1.length; _i++) {
- var optgroup = opts_1[_i];
- opt = this.findOption(val, optgroup.items, true);
- if (opt) {
- break;
- }
- }
- }
- return opt;
- }
- else {
- var index = this.findOptionIndex(val, opts);
- return (index != -1) ? opts[index] : null;
- }
- };
- Dropdown.prototype.onFilter = function (event) {
- var inputValue = event.target.value;
- if (inputValue && inputValue.length) {
- this.filterValue = inputValue;
- this.activateFilter();
- }
- else {
- this.filterValue = null;
- this.optionsToDisplay = this.options;
- }
- this.optionsChanged = true;
- };
- Dropdown.prototype.activateFilter = function () {
- var searchFields = this.filterBy.split(',');
- if (this.options && this.options.length) {
- if (this.group) {
- var filteredGroups = [];
- for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
- var optgroup = _a[_i];
- var filteredSubOptions = filterutils_1.FilterUtils.filter(optgroup.items, searchFields, this.filterValue, this.filterMatchMode);
- if (filteredSubOptions && filteredSubOptions.length) {
- filteredGroups.push({
- label: optgroup.label,
- value: optgroup.value,
- items: filteredSubOptions
- });
- }
- }
- this.optionsToDisplay = filteredGroups;
- }
- else {
- this.optionsToDisplay = filterutils_1.FilterUtils.filter(this.options, searchFields, this.filterValue, this.filterMatchMode);
- }
- this.optionsChanged = true;
- }
- };
- Dropdown.prototype.applyFocus = function () {
- if (this.editable)
- domhandler_1.DomHandler.findSingle(this.el.nativeElement, '.ui-dropdown-label.ui-inputtext').focus();
- else
- domhandler_1.DomHandler.findSingle(this.el.nativeElement, 'input[readonly]').focus();
- };
- Dropdown.prototype.focus = function () {
- this.applyFocus();
- };
- Dropdown.prototype.bindDocumentClickListener = function () {
- var _this = this;
- if (!this.documentClickListener) {
- this.documentClickListener = this.renderer.listen('document', 'click', function (event) {
- if (!_this.selfClick && !_this.itemClick) {
- _this.hide(event);
- _this.unbindDocumentClickListener();
- }
- _this.clearClickState();
- _this.cd.markForCheck();
- });
- }
- };
- Dropdown.prototype.clearClickState = function () {
- this.selfClick = false;
- this.itemClick = false;
- };
- Dropdown.prototype.unbindDocumentClickListener = function () {
- if (this.documentClickListener) {
- this.documentClickListener();
- this.documentClickListener = null;
- }
- };
- Dropdown.prototype.bindDocumentResizeListener = function () {
- this.documentResizeListener = this.onWindowResize.bind(this);
- window.addEventListener('resize', this.documentResizeListener);
- };
- Dropdown.prototype.unbindDocumentResizeListener = function () {
- if (this.documentResizeListener) {
- window.removeEventListener('resize', this.documentResizeListener);
- this.documentResizeListener = null;
- }
- };
- Dropdown.prototype.onWindowResize = function () {
- if (!domhandler_1.DomHandler.isAndroid()) {
- this.hide(event);
- }
- };
- Dropdown.prototype.updateFilledState = function () {
- this.filled = (this.selectedOption != null);
- };
- Dropdown.prototype.clear = function (event) {
- this.clearClick = true;
- this.value = null;
- this.onModelChange(this.value);
- this.onChange.emit({
- originalEvent: event,
- value: this.value
- });
- this.updateSelectedOption(this.value);
- this.updateEditableLabel();
- this.updateFilledState();
- };
- Dropdown.prototype.onOverlayHide = function () {
- this.unbindDocumentClickListener();
- this.unbindDocumentResizeListener();
- this.overlay = null;
- this.itemsWrapper = null;
- };
- Dropdown.prototype.ngOnDestroy = function () {
- this.restoreOverlayAppend();
- this.onOverlayHide();
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "scrollHeight", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "filter", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "name", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Dropdown.prototype, "style", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Dropdown.prototype, "panelStyle", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "styleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "panelStyleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "readonly", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "required", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "editable", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Dropdown.prototype, "appendTo", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Dropdown.prototype, "tabindex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "placeholder", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "filterPlaceholder", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "inputId", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "selectId", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "dataKey", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "filterBy", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "autofocus", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "resetFilterOnHide", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "dropdownIcon", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "optionLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "autoDisplayFirst", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "group", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "showClear", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "emptyFilterMessage", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "virtualScroll", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Dropdown.prototype, "itemSize", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Dropdown.prototype, "autoZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Dropdown.prototype, "baseZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "showTransitionOptions", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "hideTransitionOptions", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "ariaFilterLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "filterMatchMode", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Dropdown.prototype, "maxlength", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "tooltip", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "tooltipPosition", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "tooltipPositionStyle", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Dropdown.prototype, "tooltipStyleClass", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onChange", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onFocus", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onBlur", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onClick", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onShow", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Dropdown.prototype, "onHide", void 0);
- __decorate([
- core_1.ViewChild('container', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Dropdown.prototype, "containerViewChild", void 0);
- __decorate([
- core_1.ViewChild('filter', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Dropdown.prototype, "filterViewChild", void 0);
- __decorate([
- core_1.ViewChild('in', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Dropdown.prototype, "focusViewChild", void 0);
- __decorate([
- core_1.ViewChild(scrolling_1.CdkVirtualScrollViewport, { static: false }),
- __metadata("design:type", scrolling_1.CdkVirtualScrollViewport)
- ], Dropdown.prototype, "viewPort", void 0);
- __decorate([
- core_1.ViewChild('editableInput', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Dropdown.prototype, "editableInputViewChild", void 0);
- __decorate([
- core_1.ContentChildren(shared_1.PrimeTemplate),
- __metadata("design:type", core_1.QueryList)
- ], Dropdown.prototype, "templates", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean),
- __metadata("design:paramtypes", [Boolean])
- ], Dropdown.prototype, "autoWidth", null);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean),
- __metadata("design:paramtypes", [Boolean])
- ], Dropdown.prototype, "disabled", null);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Array),
- __metadata("design:paramtypes", [Array])
- ], Dropdown.prototype, "options", null);
- Dropdown = __decorate([
- core_1.Component({
- selector: 'p-dropdown',
- template: "\n <div #container [ngClass]=\"{'ui-dropdown ui-widget ui-state-default ui-corner-all ui-helper-clearfix':true,\n 'ui-state-disabled':disabled, 'ui-dropdown-open':overlayVisible, 'ui-state-focus':focused, 'ui-dropdown-clearable': showClear && !disabled}\"\n (click)=\"onMouseclick($event)\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #in [attr.id]=\"inputId\" type=\"text\" [attr.aria-label]=\"selectedOption ? selectedOption.label : ' '\" readonly (focus)=\"onInputFocus($event)\" aria-haspopup=\"listbox\"\n (blur)=\"onInputBlur($event)\" (keydown)=\"onKeydown($event, true)\" [disabled]=\"disabled\" [attr.tabindex]=\"tabindex\" [attr.autofocus]=\"autofocus\">\n </div>\n <div class=\"ui-helper-hidden-accessible ui-dropdown-hidden-select\">\n <select [attr.required]=\"required\" [attr.name]=\"name\" tabindex=\"-1\" aria-hidden=\"true\">\n <option *ngIf=\"placeholder\" value=\"\">{{placeholder}}</option>\n <option *ngIf=\"selectedOption\" [value]=\"selectedOption.value\" [selected]=\"true\">{{selectedOption.label}}</option>\n </select>\n </div>\n <div class=\"ui-dropdown-label-container\" [pTooltip]=\"tooltip\" [tooltipPosition]=\"tooltipPosition\" [positionStyle]=\"tooltipPositionStyle\" [tooltipStyleClass]=\"tooltipStyleClass\">\n <label [ngClass]=\"{'ui-dropdown-label ui-inputtext ui-corner-all':true,'ui-dropdown-label-empty':(label == null || label.length === 0)}\" *ngIf=\"!editable && (label != null)\">\n <ng-container *ngIf=\"!selectedItemTemplate\">{{label||'empty'}}</ng-container>\n <ng-container *ngTemplateOutlet=\"selectedItemTemplate; context: {$implicit: selectedOption}\"></ng-container>\n </label>\n <label [ngClass]=\"{'ui-dropdown-label ui-inputtext ui-corner-all ui-placeholder':true,'ui-dropdown-label-empty': (placeholder == null || placeholder.length === 0)}\" *ngIf=\"!editable && (label == null)\">{{placeholder||'empty'}}</label>\n <input #editableInput type=\"text\" [attr.maxlength]=\"maxlength\" [attr.aria-label]=\"selectedOption ? selectedOption.label : ' '\" class=\"ui-dropdown-label ui-inputtext ui-corner-all\" *ngIf=\"editable\" [disabled]=\"disabled\" [attr.placeholder]=\"placeholder\"\n (click)=\"onEditableInputClick($event)\" (input)=\"onEditableInputChange($event)\" (focus)=\"onEditableInputFocus($event)\" (blur)=\"onInputBlur($event)\">\n <i class=\"ui-dropdown-clear-icon pi pi-times\" (click)=\"clear($event)\" *ngIf=\"value != null && showClear && !disabled\"></i>\n </div>\n <div class=\"ui-dropdown-trigger ui-state-default ui-corner-right\">\n <span class=\"ui-dropdown-trigger-icon ui-clickable\" [ngClass]=\"dropdownIcon\"></span>\n </div>\n <div *ngIf=\"overlayVisible\" [ngClass]=\"'ui-dropdown-panel ui-widget ui-widget-content ui-corner-all ui-shadow'\" [@overlayAnimation]=\"{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\" [ngStyle]=\"panelStyle\" [class]=\"panelStyleClass\">\n <div *ngIf=\"filter\" class=\"ui-dropdown-filter-container\" (click)=\"$event.stopPropagation()\">\n <input #filter type=\"text\" autocomplete=\"off\" [value]=\"filterValue||''\" class=\"ui-dropdown-filter ui-inputtext ui-widget ui-state-default ui-corner-all\" [attr.placeholder]=\"filterPlaceholder\"\n (keydown.enter)=\"$event.preventDefault()\" (keydown)=\"onKeydown($event, false)\" (input)=\"onFilter($event)\" [attr.aria-label]=\"ariaFilterLabel\">\n <span class=\"ui-dropdown-filter-icon pi pi-search\"></span>\n </div>\n <div class=\"ui-dropdown-items-wrapper\" [style.max-height]=\"virtualScroll ? 'auto' : (scrollHeight||'auto')\">\n <ul class=\"ui-dropdown-items ui-dropdown-list ui-widget-content ui-widget ui-corner-all ui-helper-reset\" role=\"listbox\">\n <ng-container *ngIf=\"group\">\n <ng-template ngFor let-optgroup [ngForOf]=\"optionsToDisplay\">\n <li class=\"ui-dropdown-item-group\">\n <span *ngIf=\"!groupTemplate\">{{optgroup.label||'empty'}}</span>\n <ng-container *ngTemplateOutlet=\"groupTemplate; context: {$implicit: optgroup}\"></ng-container>\n </li>\n <ng-container *ngTemplateOutlet=\"itemslist; context: {$implicit: optgroup.items, selectedOption: selectedOption}\"></ng-container>\n </ng-template>\n </ng-container>\n <ng-container *ngIf=\"!group\">\n <ng-container *ngTemplateOutlet=\"itemslist; context: {$implicit: optionsToDisplay, selectedOption: selectedOption}\"></ng-container>\n </ng-container>\n <ng-template #itemslist let-options let-selectedOption=\"selectedOption\">\n\n <ng-container *ngIf=\"!virtualScroll; else virtualScrollList\">\n <ng-template ngFor let-option let-i=\"index\" [ngForOf]=\"options\">\n <p-dropdownItem [option]=\"option\" [selected]=\"selectedOption == option\" \n (onClick)=\"onItemClick($event)\"\n [template]=\"itemTemplate\"></p-dropdownItem>\n </ng-template>\n </ng-container>\n <ng-template #virtualScrollList>\n <cdk-virtual-scroll-viewport (scrolledIndexChange)=\"scrollToSelectedVirtualScrollElement()\" #viewport [ngStyle]=\"{'height': scrollHeight}\" [itemSize]=\"itemSize\" *ngIf=\"virtualScroll && optionsToDisplay && optionsToDisplay.length\">\n <ng-container *cdkVirtualFor=\"let option of options; let i = index; let c = count; let f = first; let l = last; let e = even; let o = odd\"> \n <p-dropdownItem [option]=\"option\" [selected]=\"selectedOption == option\"\n (onClick)=\"onItemClick($event)\"\n [template]=\"itemTemplate\"></p-dropdownItem>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n </ng-template>\n </ng-template>\n <li *ngIf=\"filter && optionsToDisplay && optionsToDisplay.length === 0\" class=\"ui-dropdown-empty-message\">{{emptyFilterMessage}}</li>\n </ul>\n </div>\n </div>\n </div>\n ",
- animations: [
- animations_1.trigger('overlayAnimation', [
- animations_1.state('void', animations_1.style({
- transform: 'translateY(5%)',
- opacity: 0
- })),
- animations_1.state('visible', animations_1.style({
- transform: 'translateY(0)',
- opacity: 1
- })),
- animations_1.transition('void => visible', animations_1.animate('{{showTransitionParams}}')),
- animations_1.transition('visible => void', animations_1.animate('{{hideTransitionParams}}'))
- ])
- ],
- host: {
- '[class.ui-inputwrapper-filled]': 'filled',
- '[class.ui-inputwrapper-focus]': 'focused'
- },
- providers: [exports.DROPDOWN_VALUE_ACCESSOR]
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer2, core_1.ChangeDetectorRef, core_1.NgZone])
- ], Dropdown);
- return Dropdown;
- }());
- exports.Dropdown = Dropdown;
- var DropdownModule = /** @class */ (function () {
- function DropdownModule() {
- }
- DropdownModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule, shared_1.SharedModule, scrolling_1.ScrollingModule, tooltip_1.TooltipModule],
- exports: [Dropdown, shared_1.SharedModule, scrolling_1.ScrollingModule],
- declarations: [Dropdown, DropdownItem]
- })
- ], DropdownModule);
- return DropdownModule;
- }());
- exports.DropdownModule = DropdownModule;
- //# sourceMappingURL=dropdown.js.map
|