ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1,422 lines (1,413 loc) • 46.6 kB
JavaScript
import { OverlayConfig, ConnectionPositionPair, Overlay, OverlayModule } from '@angular/cdk/overlay';
import { DOCUMENT, CommonModule } from '@angular/common';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, Input, EventEmitter, ChangeDetectorRef, ElementRef, Optional, Output, NgZone, Host, ContentChildren, ViewChildren, ViewChild, TemplateRef, forwardRef, Directive, ViewContainerRef, Inject, NgModule } from '@angular/core';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { NzNoAnimationDirective, NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzInputGroupWhitSuffixOrPrefixDirective, NzInputModule } from 'ng-zorro-antd/input';
import { __decorate, __metadata, __spread } from 'tslib';
import { scrollIntoView, InputBoolean } from 'ng-zorro-antd/core/util';
import { UP_ARROW, DOWN_ARROW, ESCAPE, TAB, ENTER } from '@angular/cdk/keycodes';
import { TemplatePortal } from '@angular/cdk/portal';
import { Subscription, defer, merge, fromEvent } from 'rxjs';
import { take, switchMap, filter, tap, delay, map, distinct } from 'rxjs/operators';
import { slideMotion } from 'ng-zorro-antd/core/animation';
/**
* @fileoverview added by tsickle
* Generated from: autocomplete-optgroup.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzAutocompleteOptgroupComponent = /** @class */ (function () {
function NzAutocompleteOptgroupComponent() {
}
NzAutocompleteOptgroupComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-auto-optgroup',
exportAs: 'nzAutoOptgroup',
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: "\n <div class=\"ant-select-item ant-select-item-group\">\n <ng-container *nzStringTemplateOutlet=\"nzLabel\">{{ nzLabel }}</ng-container>\n </div>\n <ng-content select=\"nz-auto-option\"></ng-content>\n "
}] }
];
/** @nocollapse */
NzAutocompleteOptgroupComponent.ctorParameters = function () { return []; };
NzAutocompleteOptgroupComponent.propDecorators = {
nzLabel: [{ type: Input }]
};
return NzAutocompleteOptgroupComponent;
}());
if (false) {
/** @type {?} */
NzAutocompleteOptgroupComponent.prototype.nzLabel;
}
/**
* @fileoverview added by tsickle
* Generated from: autocomplete-option.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzOptionSelectionChange = /** @class */ (function () {
function NzOptionSelectionChange(source, isUserInput) {
if (isUserInput === void 0) { isUserInput = false; }
this.source = source;
this.isUserInput = isUserInput;
}
return NzOptionSelectionChange;
}());
if (false) {
/** @type {?} */
NzOptionSelectionChange.prototype.source;
/** @type {?} */
NzOptionSelectionChange.prototype.isUserInput;
}
var NzAutocompleteOptionComponent = /** @class */ (function () {
function NzAutocompleteOptionComponent(changeDetectorRef, element, nzAutocompleteOptgroupComponent) {
this.changeDetectorRef = changeDetectorRef;
this.element = element;
this.nzAutocompleteOptgroupComponent = nzAutocompleteOptgroupComponent;
this.nzDisabled = false;
this.selectionChange = new EventEmitter();
this.mouseEntered = new EventEmitter();
this.active = false;
this.selected = false;
}
/**
* @param {?=} emit
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.select = /**
* @param {?=} emit
* @return {?}
*/
function (emit) {
if (emit === void 0) { emit = true; }
this.selected = true;
this.changeDetectorRef.markForCheck();
if (emit) {
this.emitSelectionChangeEvent();
}
};
/**
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.onMouseEnter = /**
* @return {?}
*/
function () {
this.mouseEntered.emit(this);
};
/**
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.deselect = /**
* @return {?}
*/
function () {
this.selected = false;
this.changeDetectorRef.markForCheck();
this.emitSelectionChangeEvent();
};
/** Git display label */
/**
* Git display label
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.getLabel = /**
* Git display label
* @return {?}
*/
function () {
return this.nzLabel || this.nzValue.toString();
};
/** Set active (only styles) */
/**
* Set active (only styles)
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.setActiveStyles = /**
* Set active (only styles)
* @return {?}
*/
function () {
if (!this.active) {
this.active = true;
this.changeDetectorRef.markForCheck();
}
};
/** Unset active (only styles) */
/**
* Unset active (only styles)
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.setInactiveStyles = /**
* Unset active (only styles)
* @return {?}
*/
function () {
if (this.active) {
this.active = false;
this.changeDetectorRef.markForCheck();
}
};
/**
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.scrollIntoViewIfNeeded = /**
* @return {?}
*/
function () {
scrollIntoView(this.element.nativeElement);
};
/**
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.selectViaInteraction = /**
* @return {?}
*/
function () {
if (!this.nzDisabled) {
this.selected = !this.selected;
if (this.selected) {
this.setActiveStyles();
}
else {
this.setInactiveStyles();
}
this.emitSelectionChangeEvent(true);
this.changeDetectorRef.markForCheck();
}
};
/**
* @private
* @param {?=} isUserInput
* @return {?}
*/
NzAutocompleteOptionComponent.prototype.emitSelectionChangeEvent = /**
* @private
* @param {?=} isUserInput
* @return {?}
*/
function (isUserInput) {
if (isUserInput === void 0) { isUserInput = false; }
this.selectionChange.emit(new NzOptionSelectionChange(this, isUserInput));
};
NzAutocompleteOptionComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-auto-option',
exportAs: 'nzAutoOption',
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: "\n <div class=\"ant-select-item-option-content\">\n <ng-content></ng-content>\n </div>\n ",
host: {
role: 'menuitem',
class: 'ant-select-item ant-select-item-option',
'[class.ant-select-item-option-grouped]': 'nzAutocompleteOptgroupComponent',
'[class.ant-select-item-option-selected]': 'selected',
'[class.ant-select-item-option-active]': 'active',
'[class.ant-select-item-option-disabled]': 'nzDisabled',
'[attr.aria-selected]': 'selected.toString()',
'[attr.aria-disabled]': 'nzDisabled.toString()',
'(click)': 'selectViaInteraction()',
'(mouseenter)': 'onMouseEnter()',
'(mousedown)': '$event.preventDefault()'
}
}] }
];
/** @nocollapse */
NzAutocompleteOptionComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef },
{ type: ElementRef },
{ type: NzAutocompleteOptgroupComponent, decorators: [{ type: Optional }] }
]; };
NzAutocompleteOptionComponent.propDecorators = {
nzValue: [{ type: Input }],
nzLabel: [{ type: Input }],
nzDisabled: [{ type: Input }],
selectionChange: [{ type: Output }],
mouseEntered: [{ type: Output }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzAutocompleteOptionComponent.prototype, "nzDisabled", void 0);
return NzAutocompleteOptionComponent;
}());
if (false) {
/** @type {?} */
NzAutocompleteOptionComponent.ngAcceptInputType_nzDisabled;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.nzValue;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.nzLabel;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.nzDisabled;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.selectionChange;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.mouseEntered;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.active;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.selected;
/**
* @type {?}
* @private
*/
NzAutocompleteOptionComponent.prototype.changeDetectorRef;
/**
* @type {?}
* @private
*/
NzAutocompleteOptionComponent.prototype.element;
/** @type {?} */
NzAutocompleteOptionComponent.prototype.nzAutocompleteOptgroupComponent;
}
/**
* @fileoverview added by tsickle
* Generated from: autocomplete.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function AutocompleteDataSourceItem() { }
if (false) {
/** @type {?} */
AutocompleteDataSourceItem.prototype.value;
/** @type {?} */
AutocompleteDataSourceItem.prototype.label;
}
var NzAutocompleteComponent = /** @class */ (function () {
function NzAutocompleteComponent(changeDetectorRef, ngZone, noAnimation) {
var _this = this;
this.changeDetectorRef = changeDetectorRef;
this.ngZone = ngZone;
this.noAnimation = noAnimation;
this.nzOverlayClassName = '';
this.nzOverlayStyle = {};
this.nzDefaultActiveFirstOption = true;
this.nzBackfill = false;
this.compareWith = (/**
* @param {?} o1
* @param {?} o2
* @return {?}
*/
function (o1, o2) { return o1 === o2; });
this.selectionChange = new EventEmitter();
this.showPanel = true;
this.isOpen = false;
this.dropDownPosition = 'bottom';
this.activeItemIndex = -1;
this.selectionChangeSubscription = Subscription.EMPTY;
this.optionMouseEnterSubscription = Subscription.EMPTY;
this.dataSourceChangeSubscription = Subscription.EMPTY;
/**
* Options changes listener
*/
this.optionSelectionChanges = defer((/**
* @return {?}
*/
function () {
if (_this.options) {
return merge.apply(void 0, __spread(_this.options.map((/**
* @param {?} option
* @return {?}
*/
function (option) { return option.selectionChange; }))));
}
return _this.ngZone.onStable.asObservable().pipe(take(1), switchMap((/**
* @return {?}
*/
function () { return _this.optionSelectionChanges; })));
}));
this.optionMouseEnter = defer((/**
* @return {?}
*/
function () {
if (_this.options) {
return merge.apply(void 0, __spread(_this.options.map((/**
* @param {?} option
* @return {?}
*/
function (option) { return option.mouseEntered; }))));
}
return _this.ngZone.onStable.asObservable().pipe(take(1), switchMap((/**
* @return {?}
*/
function () { return _this.optionMouseEnter; })));
}));
}
Object.defineProperty(NzAutocompleteComponent.prototype, "options", {
/**
* Options accessor, its source may be content or dataSource
*/
get: /**
* Options accessor, its source may be content or dataSource
* @return {?}
*/
function () {
// first dataSource
if (this.nzDataSource) {
return this.fromDataSourceOptions;
}
else {
return this.fromContentOptions;
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.ngAfterContentInit = /**
* @return {?}
*/
function () {
if (!this.nzDataSource) {
this.optionsInit();
}
};
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
if (this.nzDataSource) {
this.optionsInit();
}
};
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.dataSourceChangeSubscription.unsubscribe();
this.selectionChangeSubscription.unsubscribe();
this.optionMouseEnterSubscription.unsubscribe();
};
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.setVisibility = /**
* @return {?}
*/
function () {
this.showPanel = !!this.options.length;
this.changeDetectorRef.markForCheck();
};
/**
* @param {?} index
* @return {?}
*/
NzAutocompleteComponent.prototype.setActiveItem = /**
* @param {?} index
* @return {?}
*/
function (index) {
/** @type {?} */
var activeItem = this.options.toArray()[index];
if (activeItem && !activeItem.active) {
this.activeItem = activeItem;
this.activeItemIndex = index;
this.clearSelectedOptions(this.activeItem);
this.activeItem.setActiveStyles();
this.changeDetectorRef.markForCheck();
}
};
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.setNextItemActive = /**
* @return {?}
*/
function () {
/** @type {?} */
var nextIndex = this.activeItemIndex + 1 <= this.options.length - 1 ? this.activeItemIndex + 1 : 0;
this.setActiveItem(nextIndex);
};
/**
* @return {?}
*/
NzAutocompleteComponent.prototype.setPreviousItemActive = /**
* @return {?}
*/
function () {
/** @type {?} */
var previousIndex = this.activeItemIndex - 1 < 0 ? this.options.length - 1 : this.activeItemIndex - 1;
this.setActiveItem(previousIndex);
};
/**
* @param {?} value
* @return {?}
*/
NzAutocompleteComponent.prototype.getOptionIndex = /**
* @param {?} value
* @return {?}
*/
function (value) {
var _this = this;
return (/** @type {?} */ (this.options.reduce((/**
* @param {?} result
* @param {?} current
* @param {?} index
* @return {?}
*/
function (result, current, index) {
return result === -1 ? (_this.compareWith(value, current.nzValue) ? index : -1) : result;
}), -1)));
};
/**
* @param {?} value
* @return {?}
*/
NzAutocompleteComponent.prototype.getOption = /**
* @param {?} value
* @return {?}
*/
function (value) {
var _this = this;
return this.options.find((/**
* @param {?} item
* @return {?}
*/
function (item) { return _this.compareWith(value, item.nzValue); })) || null;
};
/**
* @param {?} position
* @return {?}
*/
NzAutocompleteComponent.prototype.updatePosition = /**
* @param {?} position
* @return {?}
*/
function (position) {
this.dropDownPosition = position;
this.changeDetectorRef.markForCheck();
};
/**
* @private
* @return {?}
*/
NzAutocompleteComponent.prototype.optionsInit = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this.setVisibility();
this.subscribeOptionChanges();
/** @type {?} */
var changes = this.nzDataSource ? this.fromDataSourceOptions.changes : this.fromContentOptions.changes;
// async
this.dataSourceChangeSubscription = changes.subscribe((/**
* @param {?} e
* @return {?}
*/
function (e) {
if (!e.dirty && _this.isOpen) {
setTimeout((/**
* @return {?}
*/
function () { return _this.setVisibility(); }));
}
_this.subscribeOptionChanges();
}));
};
/**
* Clear the status of options
*/
/**
* Clear the status of options
* @param {?=} skip
* @param {?=} deselect
* @return {?}
*/
NzAutocompleteComponent.prototype.clearSelectedOptions = /**
* Clear the status of options
* @param {?=} skip
* @param {?=} deselect
* @return {?}
*/
function (skip, deselect) {
if (deselect === void 0) { deselect = false; }
this.options.forEach((/**
* @param {?} option
* @return {?}
*/
function (option) {
if (option !== skip) {
if (deselect) {
option.deselect();
}
option.setInactiveStyles();
}
}));
};
/**
* @private
* @return {?}
*/
NzAutocompleteComponent.prototype.subscribeOptionChanges = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this.selectionChangeSubscription.unsubscribe();
this.selectionChangeSubscription = this.optionSelectionChanges
.pipe(filter((/**
* @param {?} event
* @return {?}
*/
function (event) { return event.isUserInput; })))
.subscribe((/**
* @param {?} event
* @return {?}
*/
function (event) {
event.source.select();
event.source.setActiveStyles();
_this.activeItem = event.source;
_this.activeItemIndex = _this.getOptionIndex(_this.activeItem.nzValue);
_this.clearSelectedOptions(event.source, true);
_this.selectionChange.emit(event.source);
}));
this.optionMouseEnterSubscription.unsubscribe();
this.optionMouseEnterSubscription = this.optionMouseEnter.subscribe((/**
* @param {?} event
* @return {?}
*/
function (event) {
event.setActiveStyles();
_this.activeItem = event;
_this.activeItemIndex = _this.getOptionIndex(_this.activeItem.nzValue);
_this.clearSelectedOptions(event);
}));
};
NzAutocompleteComponent.decorators = [
{ type: Component, args: [{
selector: 'nz-autocomplete',
exportAs: 'nzAutocomplete',
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: "\n <ng-template>\n <div\n #panel\n class=\"ant-select-dropdown ant-select-dropdown-placement-bottomLeft\"\n [class.ant-select-dropdown-hidden]=\"!showPanel\"\n [ngClass]=\"nzOverlayClassName\"\n [ngStyle]=\"nzOverlayStyle\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n [@slideMotion]=\"dropDownPosition\"\n [@.disabled]=\"noAnimation?.nzNoAnimation\"\n >\n <div style=\"max-height: 256px; overflow-y: auto; overflow-anchor: none;\">\n <div style=\"display: flex; flex-direction: column;\">\n <ng-template *ngTemplateOutlet=\"nzDataSource ? optionsTemplate : contentTemplate\"></ng-template>\n </div>\n </div>\n </div>\n <ng-template #contentTemplate>\n <ng-content></ng-content>\n </ng-template>\n <ng-template #optionsTemplate>\n <nz-auto-option\n *ngFor=\"let option of nzDataSource\"\n [nzValue]=\"option\"\n [nzLabel]=\"option && option.label ? option.label : $any(option)\"\n >\n {{ option && option.label ? option.label : option }}\n </nz-auto-option>\n </ng-template>\n </ng-template>\n ",
animations: [slideMotion]
}] }
];
/** @nocollapse */
NzAutocompleteComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef },
{ type: NgZone },
{ type: NzNoAnimationDirective, decorators: [{ type: Host }, { type: Optional }] }
]; };
NzAutocompleteComponent.propDecorators = {
nzWidth: [{ type: Input }],
nzOverlayClassName: [{ type: Input }],
nzOverlayStyle: [{ type: Input }],
nzDefaultActiveFirstOption: [{ type: Input }],
nzBackfill: [{ type: Input }],
compareWith: [{ type: Input }],
nzDataSource: [{ type: Input }],
selectionChange: [{ type: Output }],
fromContentOptions: [{ type: ContentChildren, args: [NzAutocompleteOptionComponent, { descendants: true },] }],
fromDataSourceOptions: [{ type: ViewChildren, args: [NzAutocompleteOptionComponent,] }],
template: [{ type: ViewChild, args: [TemplateRef, { static: false },] }],
panel: [{ type: ViewChild, args: ['panel', { static: false },] }],
content: [{ type: ViewChild, args: ['content', { static: false },] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzAutocompleteComponent.prototype, "nzDefaultActiveFirstOption", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzAutocompleteComponent.prototype, "nzBackfill", void 0);
return NzAutocompleteComponent;
}());
if (false) {
/** @type {?} */
NzAutocompleteComponent.ngAcceptInputType_nzDefaultActiveFirstOption;
/** @type {?} */
NzAutocompleteComponent.ngAcceptInputType_nzBackfill;
/** @type {?} */
NzAutocompleteComponent.prototype.nzWidth;
/** @type {?} */
NzAutocompleteComponent.prototype.nzOverlayClassName;
/** @type {?} */
NzAutocompleteComponent.prototype.nzOverlayStyle;
/** @type {?} */
NzAutocompleteComponent.prototype.nzDefaultActiveFirstOption;
/** @type {?} */
NzAutocompleteComponent.prototype.nzBackfill;
/** @type {?} */
NzAutocompleteComponent.prototype.compareWith;
/** @type {?} */
NzAutocompleteComponent.prototype.nzDataSource;
/** @type {?} */
NzAutocompleteComponent.prototype.selectionChange;
/** @type {?} */
NzAutocompleteComponent.prototype.showPanel;
/** @type {?} */
NzAutocompleteComponent.prototype.isOpen;
/** @type {?} */
NzAutocompleteComponent.prototype.activeItem;
/** @type {?} */
NzAutocompleteComponent.prototype.dropDownPosition;
/**
* Provided by content
* @type {?}
*/
NzAutocompleteComponent.prototype.fromContentOptions;
/**
* Provided by dataSource
* @type {?}
*/
NzAutocompleteComponent.prototype.fromDataSourceOptions;
/**
* cdk-overlay
* @type {?}
*/
NzAutocompleteComponent.prototype.template;
/** @type {?} */
NzAutocompleteComponent.prototype.panel;
/** @type {?} */
NzAutocompleteComponent.prototype.content;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.activeItemIndex;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.selectionChangeSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.optionMouseEnterSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.dataSourceChangeSubscription;
/**
* Options changes listener
* @type {?}
*/
NzAutocompleteComponent.prototype.optionSelectionChanges;
/** @type {?} */
NzAutocompleteComponent.prototype.optionMouseEnter;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.changeDetectorRef;
/**
* @type {?}
* @private
*/
NzAutocompleteComponent.prototype.ngZone;
/** @type {?} */
NzAutocompleteComponent.prototype.noAnimation;
}
/**
* @fileoverview added by tsickle
* Generated from: autocomplete-trigger.directive.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var NZ_AUTOCOMPLETE_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef((/**
* @return {?}
*/
function () { return NzAutocompleteTriggerDirective; })),
multi: true
};
/**
* @return {?}
*/
function getNzAutocompleteMissingPanelError() {
return Error('Attempting to open an undefined instance of `nz-autocomplete`. ' +
'Make sure that the id passed to the `nzAutocomplete` is correct and that ' +
"you're attempting to open it after the ngAfterContentInit hook.");
}
var NzAutocompleteTriggerDirective = /** @class */ (function () {
function NzAutocompleteTriggerDirective(elementRef, overlay, viewContainerRef, ngZone, nzInputGroupWhitSuffixOrPrefixDirective, document) {
this.elementRef = elementRef;
this.overlay = overlay;
this.viewContainerRef = viewContainerRef;
this.ngZone = ngZone;
this.nzInputGroupWhitSuffixOrPrefixDirective = nzInputGroupWhitSuffixOrPrefixDirective;
this.document = document;
this.onChange = (/**
* @return {?}
*/
function () { });
this.onTouched = (/**
* @return {?}
*/
function () { });
this.panelOpen = false;
}
Object.defineProperty(NzAutocompleteTriggerDirective.prototype, "activeOption", {
/** Current active option */
get: /**
* Current active option
* @return {?}
*/
function () {
if (this.nzAutocomplete && this.nzAutocomplete.options.length) {
return this.nzAutocomplete.activeItem;
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroyPanel();
};
/**
* @param {?} value
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.writeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
var _this = this;
Promise.resolve(null).then((/**
* @return {?}
*/
function () { return _this.setTriggerValue(value); }));
};
/**
* @param {?} fn
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onTouched = fn;
};
/**
* @param {?} isDisabled
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.setDisabledState = /**
* @param {?} isDisabled
* @return {?}
*/
function (isDisabled) {
/** @type {?} */
var element = this.elementRef.nativeElement;
element.disabled = isDisabled;
this.closePanel();
};
/**
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.openPanel = /**
* @return {?}
*/
function () {
this.previousValue = this.elementRef.nativeElement.value;
this.attachOverlay();
this.updateStatus();
};
/**
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.closePanel = /**
* @return {?}
*/
function () {
if (this.panelOpen) {
this.nzAutocomplete.isOpen = this.panelOpen = false;
if (this.overlayRef && this.overlayRef.hasAttached()) {
this.selectionChangeSubscription.unsubscribe();
this.overlayBackdropClickSubscription.unsubscribe();
this.overlayPositionChangeSubscription.unsubscribe();
this.optionsChangeSubscription.unsubscribe();
this.overlayRef.detach();
this.overlayRef = null;
this.portal = null;
}
}
};
/**
* @param {?} event
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.handleKeydown = /**
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var keyCode = event.keyCode;
/** @type {?} */
var isArrowKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW;
if (keyCode === ESCAPE) {
event.preventDefault();
}
if (this.panelOpen && (keyCode === ESCAPE || keyCode === TAB)) {
// Reset value when tab / ESC close
if (this.activeOption && this.activeOption.getLabel() !== this.previousValue) {
this.setTriggerValue(this.previousValue);
}
this.closePanel();
}
else if (this.panelOpen && keyCode === ENTER) {
if (this.nzAutocomplete.showPanel && this.activeOption) {
event.preventDefault();
this.activeOption.selectViaInteraction();
}
}
else if (this.panelOpen && isArrowKey && this.nzAutocomplete.showPanel) {
event.stopPropagation();
event.preventDefault();
if (keyCode === UP_ARROW) {
this.nzAutocomplete.setPreviousItemActive();
}
else {
this.nzAutocomplete.setNextItemActive();
}
if (this.activeOption) {
this.activeOption.scrollIntoViewIfNeeded();
}
this.doBackfill();
}
};
/**
* @param {?} event
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.handleInput = /**
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var target = (/** @type {?} */ (event.target));
/** @type {?} */
var document = (/** @type {?} */ (this.document));
/** @type {?} */
var value = target.value;
if (target.type === 'number') {
value = value === '' ? null : parseFloat(value);
}
if (this.previousValue !== value) {
this.previousValue = value;
this.onChange(value);
if (this.canOpen() && document.activeElement === event.target) {
this.openPanel();
}
}
};
/**
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.handleFocus = /**
* @return {?}
*/
function () {
if (this.canOpen()) {
this.openPanel();
}
};
/**
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.handleBlur = /**
* @return {?}
*/
function () {
this.onTouched();
};
/**
* Subscription data source changes event
*/
/**
* Subscription data source changes event
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.subscribeOptionsChange = /**
* Subscription data source changes event
* @private
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var firstStable = this.ngZone.onStable.asObservable().pipe(take(1));
/** @type {?} */
var optionChanges = this.nzAutocomplete.options.changes.pipe(tap((/**
* @return {?}
*/
function () { return _this.positionStrategy.reapplyLastPosition(); })), delay(0));
return merge(firstStable, optionChanges).subscribe((/**
* @return {?}
*/
function () {
_this.resetActiveItem();
if (_this.panelOpen) {
(/** @type {?} */ (_this.overlayRef)).updatePosition();
}
}));
};
/**
* Subscription option changes event and set the value
*/
/**
* Subscription option changes event and set the value
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.subscribeSelectionChange = /**
* Subscription option changes event and set the value
* @private
* @return {?}
*/
function () {
var _this = this;
return this.nzAutocomplete.selectionChange.subscribe((/**
* @param {?} option
* @return {?}
*/
function (option) {
_this.setValueAndClose(option);
}));
};
/**
* Subscription external click and close panel
*/
/**
* Subscription external click and close panel
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.subscribeOverlayBackdropClick = /**
* Subscription external click and close panel
* @private
* @return {?}
*/
function () {
var _this = this;
return merge(fromEvent(this.document, 'click'), fromEvent(this.document, 'touchend')).subscribe((/**
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var clickTarget = (/** @type {?} */ (event.target));
// Make sure is not self
if (clickTarget !== _this.elementRef.nativeElement && !(/** @type {?} */ (_this.overlayRef)).overlayElement.contains(clickTarget) && _this.panelOpen) {
_this.closePanel();
}
}));
};
/**
* Subscription overlay position changes and reset dropdown position
*/
/**
* Subscription overlay position changes and reset dropdown position
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.subscribeOverlayPositionChange = /**
* Subscription overlay position changes and reset dropdown position
* @private
* @return {?}
*/
function () {
var _this = this;
return this.positionStrategy.positionChanges
.pipe(map((/**
* @param {?} position
* @return {?}
*/
function (position) { return position.connectionPair.originY; })), distinct(), delay(0))
.subscribe((/**
* @param {?} position
* @return {?}
*/
function (position) {
_this.nzAutocomplete.updatePosition(position);
}));
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.attachOverlay = /**
* @private
* @return {?}
*/
function () {
if (!this.nzAutocomplete) {
throw getNzAutocompleteMissingPanelError();
}
if (!this.portal) {
this.portal = new TemplatePortal(this.nzAutocomplete.template, this.viewContainerRef);
}
if (!this.overlayRef) {
this.overlayRef = this.overlay.create(this.getOverlayConfig());
}
if (this.overlayRef && !this.overlayRef.hasAttached()) {
this.overlayRef.attach(this.portal);
this.overlayPositionChangeSubscription = this.subscribeOverlayPositionChange();
this.selectionChangeSubscription = this.subscribeSelectionChange();
this.overlayBackdropClickSubscription = this.subscribeOverlayBackdropClick();
this.optionsChangeSubscription = this.subscribeOptionsChange();
}
this.nzAutocomplete.isOpen = this.panelOpen = true;
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.updateStatus = /**
* @private
* @return {?}
*/
function () {
if (this.overlayRef) {
this.overlayRef.updateSize({ width: this.nzAutocomplete.nzWidth || this.getHostWidth() });
}
this.nzAutocomplete.setVisibility();
this.resetActiveItem();
if (this.activeOption) {
this.activeOption.scrollIntoViewIfNeeded();
}
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.destroyPanel = /**
* @private
* @return {?}
*/
function () {
if (this.overlayRef) {
this.closePanel();
}
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.getOverlayConfig = /**
* @private
* @return {?}
*/
function () {
return new OverlayConfig({
positionStrategy: this.getOverlayPosition(),
disposeOnNavigation: true,
scrollStrategy: this.overlay.scrollStrategies.reposition(),
// default host element width
width: this.nzAutocomplete.nzWidth || this.getHostWidth()
});
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.getConnectedElement = /**
* @private
* @return {?}
*/
function () {
return this.nzInputGroupWhitSuffixOrPrefixDirective ? this.nzInputGroupWhitSuffixOrPrefixDirective.elementRef : this.elementRef;
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.getHostWidth = /**
* @private
* @return {?}
*/
function () {
return this.getConnectedElement().nativeElement.getBoundingClientRect().width;
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.getOverlayPosition = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var positions = [
new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }),
new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' })
];
this.positionStrategy = this.overlay
.position()
.flexibleConnectedTo(this.getConnectedElement())
.withFlexibleDimensions(false)
.withPush(false)
.withPositions(positions);
return this.positionStrategy;
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.resetActiveItem = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var index = this.nzAutocomplete.getOptionIndex(this.previousValue);
this.nzAutocomplete.clearSelectedOptions(null, true);
if (index !== -1) {
this.nzAutocomplete.setActiveItem(index);
this.nzAutocomplete.activeItem.select(false);
}
else {
this.nzAutocomplete.setActiveItem(this.nzAutocomplete.nzDefaultActiveFirstOption ? 0 : -1);
}
};
/**
* @private
* @param {?} option
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.setValueAndClose = /**
* @private
* @param {?} option
* @return {?}
*/
function (option) {
/** @type {?} */
var value = option.nzValue;
this.setTriggerValue(option.getLabel());
this.onChange(value);
this.elementRef.nativeElement.focus();
this.closePanel();
};
/**
* @private
* @param {?} value
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.setTriggerValue = /**
* @private
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var option = this.nzAutocomplete.getOption(value);
/** @type {?} */
var displayValue = option ? option.getLabel() : value;
this.elementRef.nativeElement.value = displayValue != null ? displayValue : '';
if (!this.nzAutocomplete.nzBackfill) {
this.previousValue = displayValue;
}
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.doBackfill = /**
* @private
* @return {?}
*/
function () {
if (this.nzAutocomplete.nzBackfill && this.nzAutocomplete.activeItem) {
this.setTriggerValue(this.nzAutocomplete.activeItem.getLabel());
}
};
/**
* @private
* @return {?}
*/
NzAutocompleteTriggerDirective.prototype.canOpen = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var element = this.elementRef.nativeElement;
return !element.readOnly && !element.disabled;
};
NzAutocompleteTriggerDirective.decorators = [
{ type: Directive, args: [{
selector: "input[nzAutocomplete], textarea[nzAutocomplete]",
exportAs: 'nzAutocompleteTrigger',
providers: [NZ_AUTOCOMPLETE_VALUE_ACCESSOR],
host: {
autocomplete: 'off',
'aria-autocomplete': 'list',
'(focusin)': 'handleFocus()',
'(blur)': 'handleBlur()',
'(input)': 'handleInput($event)',
'(keydown)': 'handleKeydown($event)'
}
},] }
];
/** @nocollapse */
NzAutocompleteTriggerDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: Overlay },
{ type: ViewContainerRef },
{ type: NgZone },
{ type: NzInputGroupWhitSuffixOrPrefixDirective, decorators: [{ type: Optional }] },
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
]; };
NzAutocompleteTriggerDirective.propDecorators = {
nzAutocomplete: [{ type: Input }]
};
return NzAutocompleteTriggerDirective;
}());
if (false) {
/**
* Bind nzAutocomplete component
* @type {?}
*/
NzAutocompleteTriggerDirective.prototype.nzAutocomplete;
/** @type {?} */
NzAutocompleteTriggerDirective.prototype.onChange;
/** @type {?} */
NzAutocompleteTriggerDirective.prototype.onTouched;
/** @type {?} */
NzAutocompleteTriggerDirective.prototype.panelOpen;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.overlayRef;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.portal;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.positionStrategy;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.previousValue;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.selectionChangeSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.optionsChangeSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.overlayBackdropClickSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.overlayPositionChangeSubscription;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.elementRef;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.overlay;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.viewContainerRef;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.ngZone;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.nzInputGroupWhitSuffixOrPrefixDirective;
/**
* @type {?}
* @private
*/
NzAutocompleteTriggerDirective.prototype.document;
}
/**
* @fileoverview added by tsickle
* Generated from: autocomplete.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzAutocompleteModule = /** @class */ (function () {
function NzAutocompleteModule() {
}
NzAutocompleteModule.decorators = [
{ type: NgModule, args: [{
declarations: [NzAutocompleteComponent, NzAutocompleteOptionComponent, NzAutocompleteTriggerDirective, NzAutocompleteOptgroupComponent],
exports: [NzAutocompleteComponent, NzAutocompleteOptionComponent, NzAutocompleteTriggerDirective, NzAutocompleteOptgroupComponent],
imports: [CommonModule, OverlayModule, FormsModule, NzOutletModule, NzNoAnimationModule, NzInputModule]
},] }
];
return NzAutocompleteModule;
}());
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-auto-complete.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NZ_AUTOCOMPLETE_VALUE_ACCESSOR, NzAutocompleteComponent, NzAutocompleteModule, NzAutocompleteOptgroupComponent, NzAutocompleteOptionComponent, NzAutocompleteTriggerDirective, NzOptionSelectionChange, getNzAutocompleteMissingPanelError };
//# sourceMappingURL=ng-zorro-antd-auto-complete.js.map