UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

1,546 lines 124 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import * as tslib_1 from "tslib"; import { BACKSPACE, DOWN_ARROW, ENTER, ESCAPE, LEFT_ARROW, RIGHT_ARROW, UP_ARROW } from '@angular/cdk/keycodes'; import { CdkConnectedOverlay } from '@angular/cdk/overlay'; import { forwardRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, Host, HostListener, Input, Optional, Output, QueryList, Renderer2, TemplateRef, ViewChild, ViewChildren, ViewEncapsulation } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { slideMotion } from '../core/animation/slide'; import { NzNoAnimationDirective } from '../core/no-animation/nz-no-animation.directive'; import { DEFAULT_CASCADER_POSITIONS } from '../core/overlay/overlay-position'; import { arraysEqual, toArray } from '../core/util/array'; import { InputBoolean } from '../core/util/convert'; import { NzCascaderOptionComponent } from './nz-cascader-li.component'; /** @type {?} */ var defaultDisplayRender = (/** * @param {?} label * @return {?} */ function (label) { return label.join(' / '); }); var ɵ0 = defaultDisplayRender; var NzCascaderComponent = /** @class */ (function () { function NzCascaderComponent(elementRef, cdr, renderer, noAnimation) { this.elementRef = elementRef; this.cdr = cdr; this.noAnimation = noAnimation; this.nzShowInput = true; this.nzShowArrow = true; this.nzAllowClear = true; this.nzAutoFocus = false; this.nzChangeOnSelect = false; this.nzDisabled = false; this.nzExpandTrigger = 'click'; this.nzValueProperty = 'value'; this.nzLabelProperty = 'label'; this.nzSize = 'default'; this.nzPlaceHolder = 'Please select'; this.nzMouseEnterDelay = 150; // ms // ms this.nzMouseLeaveDelay = 150; // ms // ms this.nzTriggerAction = (/** @type {?} */ (['click'])); this.nzSelectionChange = new EventEmitter(); this.nzSelect = new EventEmitter(); this.nzClear = new EventEmitter(); this.nzVisibleChange = new EventEmitter(); // Not exposed, only for test // Not exposed, only for test this.nzChange = new EventEmitter(); // Not exposed, only for test // Not exposed, only for test this.el = this.elementRef.nativeElement; this.dropDownPosition = 'bottom'; this.menuVisible = false; this.isLoading = false; this.labelRenderContext = {}; this.columns = []; this.onChange = Function.prototype; this.onTouched = Function.prototype; this.positions = tslib_1.__spread(DEFAULT_CASCADER_POSITIONS); this.isSearching = false; this.isFocused = false; this.isOpening = false; this.selectedOptions = []; this.activatedOptions = []; this._inputValue = ''; renderer.addClass(elementRef.nativeElement, 'ant-cascader'); renderer.addClass(elementRef.nativeElement, 'ant-cascader-picker'); } Object.defineProperty(NzCascaderComponent.prototype, "nzOptions", { get: /** * @return {?} */ function () { return this.columns[0]; }, set: /** * @param {?} options * @return {?} */ function (options) { this.columnsSnapshot = this.columns = options && options.length ? [options] : []; if (!this.isSearching) { if (this.defaultValue && this.columns.length) { this.initOptions(0); } } else { this.prepareSearchValue(); } }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "inputValue", { get: /** * @return {?} */ function () { return this._inputValue; }, set: /** * @param {?} inputValue * @return {?} */ function (inputValue) { this._inputValue = inputValue; this.toggleSearchMode(); }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "menuCls", { get: /** * @return {?} */ function () { var _a; return _a = {}, _a["" + this.nzMenuClassName] = !!this.nzMenuClassName, _a; }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "menuColumnCls", { get: /** * @return {?} */ function () { var _a; return _a = {}, _a["" + this.nzColumnClassName] = !!this.nzColumnClassName, _a; }, enumerable: true, configurable: true }); //#region Menu //#region Menu /** * @param {?} visible * @param {?} delay * @param {?=} setOpening * @return {?} */ NzCascaderComponent.prototype.delaySetMenuVisible = //#region Menu /** * @param {?} visible * @param {?} delay * @param {?=} setOpening * @return {?} */ function (visible, delay, setOpening) { var _this = this; if (setOpening === void 0) { setOpening = false; } this.clearDelayMenuTimer(); if (delay) { if (visible && setOpening) { this.isOpening = true; } this.delayMenuTimer = setTimeout((/** * @return {?} */ function () { _this.setMenuVisible(visible); _this.cdr.detectChanges(); _this.clearDelayMenuTimer(); if (visible) { setTimeout((/** * @return {?} */ function () { _this.isOpening = false; }), 100); } }), delay); } else { this.setMenuVisible(visible); } }; /** * @param {?} visible * @return {?} */ NzCascaderComponent.prototype.setMenuVisible = /** * @param {?} visible * @return {?} */ function (visible) { if (this.nzDisabled) { return; } if (this.menuVisible !== visible) { this.menuVisible = visible; this.cdr.detectChanges(); if (visible) { this.loadRootOptions(); } this.nzVisibleChange.emit(visible); } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.clearDelayMenuTimer = /** * @private * @return {?} */ function () { if (this.delayMenuTimer) { clearTimeout(this.delayMenuTimer); this.delayMenuTimer = null; } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.loadRootOptions = /** * @private * @return {?} */ function () { if (!this.columns.length) { /** @type {?} */ var root = {}; this.loadChildrenAsync(root, -1); } }; //#endregion //#region Init //#endregion //#region Init /** * @private * @param {?} index * @return {?} */ NzCascaderComponent.prototype.isLoaded = //#endregion //#region Init /** * @private * @param {?} index * @return {?} */ function (index) { return this.columns[index] && this.columns[index].length > 0; }; /** * @private * @param {?} option * @param {?} index * @return {?} */ NzCascaderComponent.prototype.findOption = /** * @private * @param {?} option * @param {?} index * @return {?} */ function (option, index) { var _this = this; /** @type {?} */ var options = this.columns[index]; if (options) { /** @type {?} */ var value_1 = typeof option === 'object' ? this.getOptionValue(option) : option; return options.find((/** * @param {?} o * @return {?} */ function (o) { return value_1 === _this.getOptionValue(o); })); } return null; }; // tslint:disable-next-line:no-any // tslint:disable-next-line:no-any /** * @private * @param {?} index * @param {?} value * @return {?} */ NzCascaderComponent.prototype.activateOnInit = // tslint:disable-next-line:no-any /** * @private * @param {?} index * @param {?} value * @return {?} */ function (index, value) { var _a; /** @type {?} */ var option = this.findOption(value, index); if (!option) { option = typeof value === 'object' ? value : (_a = {}, _a["" + this.nzValueProperty] = value, _a["" + this.nzLabelProperty] = value, _a); } this.setOptionActivated(option, index, false, false); }; /** * @private * @param {?} index * @return {?} */ NzCascaderComponent.prototype.initOptions = /** * @private * @param {?} index * @return {?} */ function (index) { var _this = this; /** @type {?} */ var vs = this.defaultValue; /** @type {?} */ var lastIndex = vs.length - 1; /** @type {?} */ var load = (/** * @return {?} */ function () { _this.activateOnInit(index, vs[index]); if (index < lastIndex) { _this.initOptions(index + 1); } if (index === lastIndex) { _this.afterWriteValue(); } }); if (this.isLoaded(index) || !this.nzLoadData) { load(); } else { /** @type {?} */ var node = this.activatedOptions[index - 1] || {}; this.loadChildrenAsync(node, index - 1, load, this.afterWriteValue); } }; //#endregion //#region Mutating data //#endregion //#region Mutating data /** * @private * @param {?} option * @param {?} columnIndex * @param {?=} select * @param {?=} loadChildren * @return {?} */ NzCascaderComponent.prototype.setOptionActivated = //#endregion //#region Mutating data /** * @private * @param {?} option * @param {?} columnIndex * @param {?=} select * @param {?=} loadChildren * @return {?} */ function (option, columnIndex, select, loadChildren) { if (select === void 0) { select = false; } if (loadChildren === void 0) { loadChildren = true; } if (!option || option.disabled) { return; } this.activatedOptions[columnIndex] = option; // Set parent option and all ancestor options as active. for (var i = columnIndex - 1; i >= 0; i--) { if (!this.activatedOptions[i]) { this.activatedOptions[i] = this.activatedOptions[i + 1].parent; } } // Set child options and all success options as inactive. if (columnIndex < this.activatedOptions.length - 1) { this.activatedOptions = this.activatedOptions.slice(0, columnIndex + 1); } // Load child options. if (option.children && option.children.length && !option.isLeaf) { option.children.forEach((/** * @param {?} child * @return {?} */ function (child) { return child.parent = option; })); this.setColumnData(option.children, columnIndex + 1); } else if (!option.isLeaf && loadChildren) { this.loadChildrenAsync(option, columnIndex); } if (select) { this.setOptionSelected(option, columnIndex); } this.cdr.detectChanges(); this.reposition(); }; /** * @private * @param {?} option * @param {?} columnIndex * @param {?=} success * @param {?=} failure * @return {?} */ NzCascaderComponent.prototype.loadChildrenAsync = /** * @private * @param {?} option * @param {?} columnIndex * @param {?=} success * @param {?=} failure * @return {?} */ function (option, columnIndex, success, failure) { var _this = this; if (this.nzLoadData) { this.isLoading = columnIndex < 0; option.loading = true; this.nzLoadData(option, columnIndex).then((/** * @return {?} */ function () { if (option.children) { option.children.forEach((/** * @param {?} child * @return {?} */ function (child) { return child.parent = columnIndex < 0 ? undefined : option; })); _this.setColumnData(option.children, columnIndex + 1); } if (success) { success(); } option.loading = _this.isLoading = false; // Need to check children. _this.checkChildren(); // Reposition in the next tick, because we use markForCheck above. Promise.resolve().then((/** * @return {?} */ function () { return _this.reposition(); })); }), (/** * @return {?} */ function () { option.loading = _this.isLoading = false; option.isLeaf = true; _this.cdr.detectChanges(); if (failure) { failure(); } })); } }; /** * @private * @param {?} option * @param {?} columnIndex * @return {?} */ NzCascaderComponent.prototype.setOptionSelected = /** * @private * @param {?} option * @param {?} columnIndex * @return {?} */ function (option, columnIndex) { var _this = this; /** @type {?} */ var shouldPerformSelection = (/** * @param {?} o * @param {?} i * @return {?} */ function (o, i) { return typeof _this.nzChangeOn === 'function' ? _this.nzChangeOn(o, i) === true : false; }); this.nzSelect.emit({ option: option, index: columnIndex }); if (option.isLeaf || this.nzChangeOnSelect || shouldPerformSelection(option, columnIndex)) { this.selectedOptions = this.activatedOptions; this.buildDisplayLabel(); this.onValueChange(); } if (option.isLeaf) { this.delaySetMenuVisible(false, this.nzMouseLeaveDelay); } }; /** * @private * @param {?} options * @param {?} columnIndex * @return {?} */ NzCascaderComponent.prototype.setColumnData = /** * @private * @param {?} options * @param {?} columnIndex * @return {?} */ function (options, columnIndex) { if (!arraysEqual(this.columns[columnIndex], options)) { this.columns[columnIndex] = options; if (columnIndex < this.columns.length - 1) { this.columns = this.columns.slice(0, columnIndex + 1); } } }; /** * @param {?=} event * @return {?} */ NzCascaderComponent.prototype.clearSelection = /** * @param {?=} event * @return {?} */ function (event) { if (event) { event.preventDefault(); event.stopPropagation(); } this.labelRenderText = ''; this.labelRenderContext = {}; this.selectedOptions = []; this.activatedOptions = []; this.inputValue = ''; this.setMenuVisible(false); this.onValueChange(); }; // tslint:disable-next-line:no-any // tslint:disable-next-line:no-any /** * @return {?} */ NzCascaderComponent.prototype.getSubmitValue = // tslint:disable-next-line:no-any /** * @return {?} */ function () { var _this = this; /** @type {?} */ var values = []; this.selectedOptions.forEach((/** * @param {?} option * @return {?} */ function (option) { values.push(_this.getOptionValue(option)); })); return values; }; /** * @private * @return {?} */ NzCascaderComponent.prototype.onValueChange = /** * @private * @return {?} */ function () { /** @type {?} */ var value = this.getSubmitValue(); if (!arraysEqual(this.value, value)) { this.defaultValue = null; this.value = value; this.onChange(value); if (value.length === 0) { this.nzClear.emit(); } this.nzSelectionChange.emit(this.selectedOptions); this.nzChange.emit(value); } }; /** * @return {?} */ NzCascaderComponent.prototype.afterWriteValue = /** * @return {?} */ function () { this.selectedOptions = this.activatedOptions; this.value = this.getSubmitValue(); this.buildDisplayLabel(); }; //#endregion //#region Mouse and keyboard event handles, view children //#endregion //#region Mouse and keyboard event handles, view children /** * @return {?} */ NzCascaderComponent.prototype.focus = //#endregion //#region Mouse and keyboard event handles, view children /** * @return {?} */ function () { if (!this.isFocused) { (this.input ? this.input.nativeElement : this.el).focus(); this.isFocused = true; } }; /** * @return {?} */ NzCascaderComponent.prototype.blur = /** * @return {?} */ function () { if (this.isFocused) { (this.input ? this.input.nativeElement : this.el).blur(); this.isFocused = false; } }; /** * @return {?} */ NzCascaderComponent.prototype.handleInputBlur = /** * @return {?} */ function () { this.menuVisible ? this.focus() : this.blur(); }; /** * @return {?} */ NzCascaderComponent.prototype.handleInputFocus = /** * @return {?} */ function () { this.focus(); }; /** * @param {?} event * @return {?} */ NzCascaderComponent.prototype.onKeyDown = /** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var keyCode = event.keyCode; if (keyCode !== DOWN_ARROW && keyCode !== UP_ARROW && keyCode !== LEFT_ARROW && keyCode !== RIGHT_ARROW && keyCode !== ENTER && keyCode !== BACKSPACE && keyCode !== ESCAPE) { return; } // Press any keys above to reopen menu. if (!this.menuVisible && keyCode !== BACKSPACE && keyCode !== ESCAPE) { return this.setMenuVisible(true); } // Make these keys work as default in searching mode. if (this.isSearching && (keyCode === BACKSPACE || keyCode === LEFT_ARROW || keyCode === RIGHT_ARROW)) { return; } // Interact with the component. if (this.menuVisible) { event.preventDefault(); if (keyCode === DOWN_ARROW) { this.moveUpOrDown(false); } else if (keyCode === UP_ARROW) { this.moveUpOrDown(true); } else if (keyCode === LEFT_ARROW) { this.moveLeft(); } else if (keyCode === RIGHT_ARROW) { this.moveRight(); } else if (keyCode === ENTER) { this.onEnter(); } } }; /** * @return {?} */ NzCascaderComponent.prototype.onTriggerClick = /** * @return {?} */ function () { if (this.nzDisabled) { return; } if (this.nzShowSearch) { this.focus(); } if (this.isActionTrigger('click')) { this.delaySetMenuVisible(!this.menuVisible, 100); } this.onTouched(); }; /** * @return {?} */ NzCascaderComponent.prototype.onTriggerMouseEnter = /** * @return {?} */ function () { if (this.nzDisabled) { return; } if (this.isActionTrigger('hover')) { this.delaySetMenuVisible(true, this.nzMouseEnterDelay, true); } }; /** * @param {?} event * @return {?} */ NzCascaderComponent.prototype.onTriggerMouseLeave = /** * @param {?} event * @return {?} */ function (event) { if (this.nzDisabled) { return; } if (!this.menuVisible || this.isOpening) { event.preventDefault(); return; } if (this.isActionTrigger('hover')) { /** @type {?} */ var mouseTarget = (/** @type {?} */ (event.relatedTarget)); /** @type {?} */ var hostEl = this.el; /** @type {?} */ var menuEl = this.menu && (/** @type {?} */ (this.menu.nativeElement)); if (hostEl.contains(mouseTarget) || (menuEl && menuEl.contains(mouseTarget))) { return; } this.delaySetMenuVisible(false, this.nzMouseLeaveDelay); } }; /** * @private * @param {?} action * @return {?} */ NzCascaderComponent.prototype.isActionTrigger = /** * @private * @param {?} action * @return {?} */ function (action) { return typeof this.nzTriggerAction === 'string' ? this.nzTriggerAction === action : this.nzTriggerAction.indexOf(action) !== -1; }; /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ NzCascaderComponent.prototype.onOptionClick = /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ function (option, columnIndex, event) { if (event) { event.preventDefault(); } if (option && option.disabled) { return; } this.el.focus(); this.isSearching ? this.setSearchOptionActivated((/** @type {?} */ (option)), event) : this.setOptionActivated(option, columnIndex, true); }; /** * @private * @return {?} */ NzCascaderComponent.prototype.onEnter = /** * @private * @return {?} */ function () { /** @type {?} */ var columnIndex = Math.max(this.activatedOptions.length - 1, 0); /** @type {?} */ var option = this.activatedOptions[columnIndex]; if (option && !option.disabled) { this.isSearching ? this.setSearchOptionActivated((/** @type {?} */ (option)), null) : this.setOptionSelected(option, columnIndex); } }; /** * @private * @param {?} isUp * @return {?} */ NzCascaderComponent.prototype.moveUpOrDown = /** * @private * @param {?} isUp * @return {?} */ function (isUp) { /** @type {?} */ var columnIndex = Math.max(this.activatedOptions.length - 1, 0); /** @type {?} */ var activeOption = this.activatedOptions[columnIndex]; /** @type {?} */ var options = this.columns[columnIndex] || []; /** @type {?} */ var length = options.length; /** @type {?} */ var nextIndex = -1; if (!activeOption) { // Not selected options in this column nextIndex = isUp ? length : -1; } else { nextIndex = options.indexOf(activeOption); } while (true) { nextIndex = isUp ? nextIndex - 1 : nextIndex + 1; if (nextIndex < 0 || nextIndex >= length) { break; } /** @type {?} */ var nextOption = options[nextIndex]; if (!nextOption || nextOption.disabled) { continue; } this.setOptionActivated(nextOption, columnIndex); break; } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.moveLeft = /** * @private * @return {?} */ function () { /** @type {?} */ var options = this.activatedOptions; if (options.length) { options.pop(); // Remove the last one } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.moveRight = /** * @private * @return {?} */ function () { /** @type {?} */ var length = this.activatedOptions.length; /** @type {?} */ var options = this.columns[length]; if (options && options.length) { /** @type {?} */ var nextOpt = options.find((/** * @param {?} o * @return {?} */ function (o) { return !o.disabled; })); if (nextOpt) { this.setOptionActivated(nextOpt, length); } } }; /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ NzCascaderComponent.prototype.onOptionMouseEnter = /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ function (option, columnIndex, event) { event.preventDefault(); if (this.nzExpandTrigger === 'hover' && !option.isLeaf) { this.delaySelectOption(option, columnIndex, true); } }; /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ NzCascaderComponent.prototype.onOptionMouseLeave = /** * @param {?} option * @param {?} columnIndex * @param {?} event * @return {?} */ function (option, columnIndex, event) { event.preventDefault(); if (this.nzExpandTrigger === 'hover' && !option.isLeaf) { this.delaySelectOption(option, columnIndex, false); } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.clearDelaySelectTimer = /** * @private * @return {?} */ function () { if (this.delaySelectTimer) { clearTimeout(this.delaySelectTimer); this.delaySelectTimer = null; } }; /** * @private * @param {?} option * @param {?} index * @param {?} doSelect * @return {?} */ NzCascaderComponent.prototype.delaySelectOption = /** * @private * @param {?} option * @param {?} index * @param {?} doSelect * @return {?} */ function (option, index, doSelect) { var _this = this; this.clearDelaySelectTimer(); if (doSelect) { this.delaySelectTimer = setTimeout((/** * @return {?} */ function () { _this.setOptionActivated(option, index); _this.delaySelectTimer = null; }), 150); } }; //#endregion //#region Search //#endregion //#region Search /** * @private * @return {?} */ NzCascaderComponent.prototype.toggleSearchMode = //#endregion //#region Search /** * @private * @return {?} */ function () { /** @type {?} */ var willBeInSearch = !!this._inputValue; // Take a snapshot before entering search mode. if (!this.isSearching && willBeInSearch) { this.isSearching = true; this.activatedOptionsSnapshot = this.activatedOptions; this.activatedOptions = []; this.labelRenderText = ''; if (this.input) { /** @type {?} */ var width = this.input.nativeElement.offsetWidth; this.dropdownWidthStyle = width + "px"; } } // Restore the snapshot after leaving search mode. if (this.isSearching && !willBeInSearch) { this.isSearching = false; this.activatedOptions = this.activatedOptionsSnapshot; this.columns = this.columnsSnapshot; this.dropdownWidthStyle = ''; if (this.activatedOptions) { this.buildDisplayLabel(); } } if (this.isSearching) { this.prepareSearchValue(); } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.prepareSearchValue = /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var results = []; /** @type {?} */ var path = []; /** @type {?} */ var defaultFilter = (/** * @param {?} inputValue * @param {?} p * @return {?} */ function (inputValue, p) { return p.some((/** * @param {?} n * @return {?} */ function (n) { /** @type {?} */ var label = _this.getOptionLabel(n); return label && label.indexOf(inputValue) !== -1; })); }); /** @type {?} */ var filter = this.nzShowSearch instanceof Object && ((/** @type {?} */ (this.nzShowSearch))).filter ? ((/** @type {?} */ (this.nzShowSearch))).filter : defaultFilter; /** @type {?} */ var sorter = this.nzShowSearch instanceof Object && ((/** @type {?} */ (this.nzShowSearch))).sorter; /** @type {?} */ var loopParent = (/** * @param {?} node * @param {?=} forceDisabled * @return {?} */ function (node, forceDisabled) { if (forceDisabled === void 0) { forceDisabled = false; } /** @type {?} */ var disabled = forceDisabled || node.disabled; path.push(node); node.children.forEach((/** * @param {?} sNode * @return {?} */ function (sNode) { if (!sNode.parent) { sNode.parent = node; } // Build parent reference when doing searching if (!sNode.isLeaf) { loopParent(sNode, disabled); } if (sNode.isLeaf || !sNode.children || !sNode.children.length) { loopChild(sNode, disabled); } })); path.pop(); }); /** @type {?} */ var loopChild = (/** * @param {?} node * @param {?=} forceDisabled * @return {?} */ function (node, forceDisabled) { if (forceDisabled === void 0) { forceDisabled = false; } var _a; path.push(node); /** @type {?} */ var cPath = Array.from(path); if (filter(_this._inputValue, cPath)) { /** @type {?} */ var disabled = forceDisabled || node.disabled; /** @type {?} */ var option = (_a = { disabled: disabled, isLeaf: true, path: cPath }, _a[_this.nzLabelProperty] = cPath.map((/** * @param {?} p * @return {?} */ function (p) { return _this.getOptionLabel(p); })).join(' / '), _a); results.push(option); } path.pop(); }); if (!this.columnsSnapshot.length) { this.columns = [[]]; return; } this.columnsSnapshot[0].forEach((/** * @param {?} node * @return {?} */ function (node) { return (node.isLeaf || !node.children || !node.children.length) ? loopChild(node) : loopParent(node); })); if (sorter) { results.sort((/** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { return sorter(a.path, b.path, _this._inputValue); })); } this.columns = [results]; }; /** * @param {?} result * @param {?} event * @return {?} */ NzCascaderComponent.prototype.setSearchOptionActivated = /** * @param {?} result * @param {?} event * @return {?} */ function (result, event) { var _this = this; this.activatedOptions = [result]; this.delaySetMenuVisible(false, 200); setTimeout((/** * @return {?} */ function () { _this.inputValue = ''; /** @type {?} */ var index = result.path.length - 1; /** @type {?} */ var destinationNode = result.path[index]; // NOTE: optimize this. /** @type {?} */ var mockClickParent = (/** * @param {?} node * @param {?} columnIndex * @return {?} */ function (node, columnIndex) { if (node && node.parent) { mockClickParent(node.parent, columnIndex - 1); } _this.onOptionClick(node, columnIndex, event); }); mockClickParent(destinationNode, index); }), 300); }; Object.defineProperty(NzCascaderComponent.prototype, "hasInput", { //#endregion //#region Helpers get: //#endregion //#region Helpers /** * @private * @return {?} */ function () { return !!this.inputValue; }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "hasValue", { get: /** * @private * @return {?} */ function () { return !!this.value && !!this.value.length; }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "showPlaceholder", { get: /** * @return {?} */ function () { return !(this.hasInput || this.hasValue); }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "clearIconVisible", { get: /** * @return {?} */ function () { return this.nzAllowClear && !this.nzDisabled && (this.hasValue || this.hasInput); }, enumerable: true, configurable: true }); Object.defineProperty(NzCascaderComponent.prototype, "isLabelRenderTemplate", { get: /** * @return {?} */ function () { return !!this.nzLabelRender; }, enumerable: true, configurable: true }); // tslint:disable-next-line:no-any // tslint:disable-next-line:no-any /** * @param {?} option * @return {?} */ NzCascaderComponent.prototype.getOptionLabel = // tslint:disable-next-line:no-any /** * @param {?} option * @return {?} */ function (option) { return option[this.nzLabelProperty || 'label']; }; // tslint:disable-next-line:no-any // tslint:disable-next-line:no-any /** * @param {?} option * @return {?} */ NzCascaderComponent.prototype.getOptionValue = // tslint:disable-next-line:no-any /** * @param {?} option * @return {?} */ function (option) { return option[this.nzValueProperty || 'value']; }; /** * @param {?} option * @param {?} index * @return {?} */ NzCascaderComponent.prototype.isOptionActivated = /** * @param {?} option * @param {?} index * @return {?} */ function (option, index) { /** @type {?} */ var activeOpt = this.activatedOptions[index]; return activeOpt === option; }; /** * @private * @return {?} */ NzCascaderComponent.prototype.buildDisplayLabel = /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var selectedOptions = this.selectedOptions; /** @type {?} */ var labels = selectedOptions.map((/** * @param {?} o * @return {?} */ function (o) { return _this.getOptionLabel(o); })); if (this.isLabelRenderTemplate) { this.labelRenderContext = { labels: labels, selectedOptions: selectedOptions }; } else { this.labelRenderText = defaultDisplayRender.call(this, labels, selectedOptions); } // When components inits with default value, this would make display label appear correctly. this.cdr.detectChanges(); }; //#endregion //#endregion /** * @param {?} isDisabled * @return {?} */ NzCascaderComponent.prototype.setDisabledState = //#endregion /** * @param {?} isDisabled * @return {?} */ function (isDisabled) { if (isDisabled) { this.closeMenu(); } this.nzDisabled = isDisabled; }; /** * @return {?} */ NzCascaderComponent.prototype.closeMenu = /** * @return {?} */ function () { this.blur(); this.clearDelayMenuTimer(); this.setMenuVisible(false); }; /** * @return {?} */ NzCascaderComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.clearDelayMenuTimer(); this.clearDelaySelectTimer(); }; /** * @param {?} fn * @return {?} */ NzCascaderComponent.prototype.registerOnChange = /** * @param {?} fn * @return {?} */ function (fn) { this.onChange = fn; }; /** * @param {?} fn * @return {?} */ NzCascaderComponent.prototype.registerOnTouched = /** * @param {?} fn * @return {?} */ function (fn) { this.onTouched = fn; }; // tslint:disable-next-line:no-any // tslint:disable-next-line:no-any /** * @param {?} value * @return {?} */ NzCascaderComponent.prototype.writeValue = // tslint:disable-next-line:no-any /** * @param {?} value * @return {?} */ function (value) { /** @type {?} */ var vs = this.defaultValue = toArray(value); if (vs.length) { this.initOptions(0); } else { this.value = vs; this.activatedOptions = []; this.afterWriteValue(); } }; /** * @param {?} position * @return {?} */ NzCascaderComponent.prototype.onPositionChange = /** * @param {?} position * @return {?} */ function (position) { /** @type {?} */ var newValue = position.connectionPair.originY === 'bottom' ? 'bottom' : 'top'; if (this.dropDownPosition !== newValue) { this.dropDownPosition = newValue; this.cdr.detectChanges(); } }; /** * Reposition the cascader panel. When a menu opens, the cascader expands * and may exceed the browser boundary. */ /** * Reposition the cascader panel. When a menu opens, the cascader expands * and may exceed the browser boundary. * @private * @return {?} */ NzCascaderComponent.prototype.reposition = /** * Reposition the cascader panel. When a menu opens, the cascader expands * and may exceed the browser boundary. * @private * @return {?} */ function () { var _this = this; if (this.overlay && this.overlay.overlayRef && this.menuVisible) { Promise.resolve().then((/** * @return {?} */ function () { _this.overlay.overlayRef.updatePosition(); })); } }; /** * @private * @return {?} */ NzCascaderComponent.prototype.checkChildren = /** * @private * @return {?} */ function () { this.cascaderItems.forEach((/** * @param {?} item * @return {?} */ function (item) { return item.markForCheck(); })); }; NzCascaderComponent.decorators = [ { type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, selector: 'nz-cascader,[nz-cascader]', preserveWhitespaces: false, template: "<div\n cdkOverlayOrigin\n #origin=\"cdkOverlayOrigin\"\n #trigger>\n <div *ngIf=\"nzShowInput\">\n <input\n #input\n nz-input\n class=\"ant-cascader-input\"\n [class.ant-cascader-input-disabled]=\"nzDisabled\"\n [class.ant-cascader-input-lg]=\"nzSize === 'large'\"\n [class.ant-cascader-input-sm]=\"nzSize === 'small'\"\n [attr.autoComplete]=\"'off'\"\n [attr.placeholder]=\"showPlaceholder ? nzPlaceHolder : null\"\n [attr.autofocus]=\"nzAutoFocus ? 'autofocus' : null\"\n [readonly]=\"!nzShowSearch\"\n [disabled]=\"nzDisabled\"\n [nzSize]=\"nzSize\"\n [(ngModel)]=\"inputValue\"\n (blur)=\"handleInputBlur()\"\n (focus)=\"handleInputFocus()\"\n (change)=\"$event.stopPropagation()\">\n <i *ngIf=\"clearIconVisible\"\n nz-icon\n type=\"close-circle\"\n theme=\"fill\"\n class=\"ant-cascader-picker-clear\"\n (click)=\"clearSelection($event)\"></i>\n <i *ngIf=\"nzShowArrow && !isLoading\"\n nz-icon\n type=\"down\"\n class=\"ant-cascader-picker-arrow\"\n [class.ant-cascader-picker-arrow-expand]=\"menuVisible\">\n </i>\n <i *ngIf=\"isLoading\" nz-icon type=\"loading\" class=\"ant-cascader-picker-arrow\"></i>\n <span\n class=\"ant-cascader-picker-label\"\n [class.ant-cascader-show-search]=\"!!nzShowSearch\"\n [class.ant-focusd]=\"!!nzShowSearch && isFocused && !inputValue\">\n <ng-container *ngIf=\"!isLabelRenderTemplate; else labelTemplate\">{{ labelRenderText }}</ng-container>\n <ng-template #labelTemplate>\n <ng-template [ngTemplateOutlet]=\"nzLabelRender\" [ngTemplateOutletContext]=\"labelRenderContext\"></ng-template>\n </ng-template>\n </span>\n </div>\n <ng-content></ng-content>\n</div>\n<ng-template\n cdkConnectedOverlay\n nzConnectedOverlay\n cdkConnectedOverlayHasBackdrop\n [cdkConnectedOverlayOrigin]=\"origin\"\n [cdkConnectedOverlayPositions]=\"positions\"\n (backdropClick)=\"closeMenu()\"\n (detach)=\"closeMenu()\"\n (positionChange)=\"onPositionChange($event)\"\n [cdkConnectedOverlayOpen]=\"menuVisible\">\n <div\n #menu\n class=\"ant-cascader-menus\"\n *ngIf=\"nzOptions && nzOptions.length || isSearching\"\n [class.ant-cascader-menus-hidden]=\"!menuVisible\"\n [ngClass]=\"menuCls\"\n [ngStyle]=\"nzMenuStyle\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n [@slideMotion]=\"dropDownPosition\"\n (mouseleave)=\"onTriggerMouseLeave($event)\">\n <ul *ngFor=\"let options of columns; let i = index;\" class=\"ant-cascader-menu\"\n [ngClass]=\"menuColumnCls\"\n [style.height]=\"isSearching && !columns[0].length ? 'auto': ''\"\n [style.width]=\"dropdownWidthStyle\">\n <li\n nz-cascader-option\n *ngFor=\"let option of options\"\n [nzLabelProperty]=\"nzLabelProperty\"\n [activated]=\"isOptionActivated(option, i)\"\n [highlightText]=\"isSearching ? inputValue : ''\"\n [option]=\"option\"\n (mouseenter)=\"onOptionMouseEnter(option, i, $event)\"\n (mouseleave)=\"onOptionMouseLeave(option, i, $event)\"\n (click)=\"onOptionClick(option, i, $event)\">\n </li>\n <li *ngIf=\"isSearching && !columns[0].length\"\n class=\"ant-cascader-menu-item ant-cascader-menu-item-expanded ant-cascader-menu-item-disabled\">\n <nz-embed-empty [nzComponentName]=\"'cascader'\" [specificContent]=\"nzNotFoundContent\"></nz-embed-empty>\n </li>\n </ul>\n </div>\n</ng-template>\n", animations: [slideMotion], providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ function () { return NzCascaderComponent; })), multi: true } ], host: { '[attr.tabIndex]': '"0"', '[class.ant-cascader-lg]': 'nzSize === "large"', '[class.ant-cascader-sm]': 'nzSize === "small"', '[class.ant-cascader-picker-disabled]': 'nzDisabled', '[class.ant-cascader-picker-open]': 'menuVisible', '[class.ant-cascader-picker-with-value]': '!!inputValue', '[class.ant-cascader-focused]': 'isFocused' }, styles: ["\n .ant-cascader-menus {\n margin-top: 4px;\n margin-bottom: 4px;\n top: 100%;\n left: 0;\n position: relative;\n width: 100%;\n }\n "] }] } ]; /** @nocollapse */ NzCascaderComponent.ctorParameters = function () { return [ { type: ElementRef }, { type: ChangeDetectorRef }, { type: Renderer2 }, { type: NzNoAnimationDirective, decorators: [{ type: Host }, { type: Optional }] } ]; }; NzCascaderComponent.propDecorators = { input: [{ type: ViewChild, args: ['input',] }], menu: [{ type: ViewChild, args: ['menu',] }], overlay: [{ type: ViewChild, args: [CdkConnectedOverlay,] }], cascaderItems: [{ type: ViewChildren, args: [NzCascaderOptionComponent,] }], nzShowInput: [{ type: Input }], nzShowArrow: [{ type: Input }], nzAllowClear: [{ type: Input }], nzAutoFocus: [{ type: Input }], nzChangeOnSelect: [{ type: Input }], nzDisabled: [{ type: Input }], nzColumnClassName: [{ type: Input }], nzExpandTrigger: [{ type: Input }], nzValueProperty: [{ type: Input }], nzLabelRender: [{ type: Input }], nzLabelProperty: [{ type: Input }], nzNotFoundContent: [{ type: Input }], nzSize: [{ type: Input }], nzShowSearch: [{ type: Input }], nzPlaceHolder: [{ type: Input }], nzMenuClassName: [{ type: Input }], nzMenuStyle: [{ type: Input }], nzMouseEnterDelay: [{ type: Input }], nzMouseLeaveDelay: [{ type: Input }], nzTriggerAction: [{ type: Input }], nzChangeOn: [{ type: Input }], nzLoadData: [{ type: Input }], nzOptions: [{ type: Input }], nzSelectionChange: [{ type: Output }], nzSelect: [{ type: Output }], nzClear: [{ type: Output }], nzVisibleChange: [{ type: Output }], nzChange: [{ type: Output }], onKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }], onTriggerClick: [{ type: HostListener, args: ['click',] }], onTriggerMouseEnter: [{ type: HostListener, args: ['mouseenter',] }], onTriggerMouseLeave: [{ type: HostListener, args: ['mouseleave', ['$event'],] }] }; tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzShowInput", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzShowArrow", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzAllowClear", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzAutoFocus", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzChangeOnSelect", void 0); tslib_1.__decorate([ InputBoolean(), tslib_1.__metadata("design:type", Object) ], NzCascaderComponent.prototype, "nzDisabled", void 0); return NzCascaderComponent; }()); export { NzCascaderComponent }; if (false) { /** @type {?} */ NzCascaderComponent.prototype.input; /** @type {?} */ NzCascaderComponent.prototype.menu; /** @type {?} */ NzCascaderComponent.prototype.overlay; /** @type {?} */ NzCascaderComponent.prototype.cascaderIt