ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1,171 lines (1,156 loc) • 40.2 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Injectable, SkipSelf, Optional, Directive, Renderer2, ElementRef, Input, ContentChildren, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, Host, Output, ViewChild, NgModule } from '@angular/core';
import { BehaviorSubject, Subject, combineLatest, merge, EMPTY } from 'rxjs';
import { map, tap, auditTime, distinctUntilChanged, takeUntil, filter, startWith, flatMap } from 'rxjs/operators';
import { NzMenuBaseService, isNotNil, NzUpdateHostClassService, InputBoolean, DEFAULT_SUBMENU_POSITIONS, getPlacementName, POSITION_MAP, collapseMotion, zoomBigMotion, slideMotion, NzNoAnimationDirective, NzDropdownHigherOrderServiceToken, NzNoAnimationModule, NzAddOnModule } from 'ng-zorro-antd/core';
import { NavigationEnd, RouterLink, RouterLinkWithHref, Router } from '@angular/router';
import { CdkConnectedOverlay, CdkOverlayOrigin, OverlayModule } from '@angular/cdk/overlay';
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzIconModule } from 'ng-zorro-antd/icon';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzMenuService extends NzMenuBaseService {
constructor() {
super(...arguments);
this.isInDropDown = false;
}
}
NzMenuService.decorators = [
{ type: Injectable }
];
if (false) {
/** @type {?} */
NzMenuService.prototype.isInDropDown;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSubmenuService {
/**
* @param {?} nzHostSubmenuService
* @param {?} nzMenuService
*/
constructor(nzHostSubmenuService, nzMenuService) {
this.nzHostSubmenuService = nzHostSubmenuService;
this.nzMenuService = nzMenuService;
this.disabled = false;
this.mode = 'vertical';
this.mode$ = this.nzMenuService.mode$.pipe(map((/**
* @param {?} mode
* @return {?}
*/
mode => {
if (mode === 'inline') {
return 'inline';
}
else if (mode === 'vertical' || this.nzHostSubmenuService) {
return 'vertical';
}
else {
return 'horizontal';
}
})), tap((/**
* @param {?} mode
* @return {?}
*/
mode => (this.mode = (/** @type {?} */ (mode))))));
this.level = 1;
this.level$ = new BehaviorSubject(1);
this.subMenuOpen$ = new BehaviorSubject(false);
this.open$ = new BehaviorSubject(false);
this.mouseEnterLeave$ = new Subject();
this.menuOpen$ = combineLatest(this.subMenuOpen$, this.mouseEnterLeave$).pipe(map((/**
* @param {?} value
* @return {?}
*/
value => value[0] || value[1])), auditTime(150), distinctUntilChanged(), tap((/**
* @param {?} data
* @return {?}
*/
data => {
this.setOpenState(data);
if (this.nzHostSubmenuService) {
this.nzHostSubmenuService.subMenuOpen$.next(data);
}
})));
if (this.nzHostSubmenuService) {
this.setLevel(this.nzHostSubmenuService.level + 1);
}
}
/**
* @param {?} value
* @return {?}
*/
setOpenState(value) {
this.open$.next(value);
}
/**
* @return {?}
*/
onMenuItemClick() {
this.setMouseEnterState(false);
}
/**
* @param {?} value
* @return {?}
*/
setLevel(value) {
this.level$.next(value);
this.level = value;
}
/**
* @param {?} value
* @return {?}
*/
setMouseEnterState(value) {
if ((this.mode === 'horizontal' || this.mode === 'vertical' || this.nzMenuService.isInDropDown) && !this.disabled) {
this.mouseEnterLeave$.next(value);
}
}
}
NzSubmenuService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
NzSubmenuService.ctorParameters = () => [
{ type: NzSubmenuService, decorators: [{ type: SkipSelf }, { type: Optional }] },
{ type: NzMenuService }
];
if (false) {
/** @type {?} */
NzSubmenuService.prototype.disabled;
/** @type {?} */
NzSubmenuService.prototype.mode;
/** @type {?} */
NzSubmenuService.prototype.mode$;
/** @type {?} */
NzSubmenuService.prototype.level;
/** @type {?} */
NzSubmenuService.prototype.level$;
/** @type {?} */
NzSubmenuService.prototype.subMenuOpen$;
/** @type {?} */
NzSubmenuService.prototype.open$;
/** @type {?} */
NzSubmenuService.prototype.mouseEnterLeave$;
/** @type {?} */
NzSubmenuService.prototype.menuOpen$;
/**
* @type {?}
* @private
*/
NzSubmenuService.prototype.nzHostSubmenuService;
/** @type {?} */
NzSubmenuService.prototype.nzMenuService;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzMenuItemDirective {
/**
* @param {?} nzUpdateHostClassService
* @param {?} nzMenuService
* @param {?} nzSubmenuService
* @param {?} renderer
* @param {?} elementRef
* @param {?=} routerLink
* @param {?=} routerLinkWithHref
* @param {?=} router
*/
constructor(nzUpdateHostClassService, nzMenuService, nzSubmenuService, renderer, elementRef, routerLink, routerLinkWithHref, router) {
this.nzUpdateHostClassService = nzUpdateHostClassService;
this.nzMenuService = nzMenuService;
this.nzSubmenuService = nzSubmenuService;
this.renderer = renderer;
this.elementRef = elementRef;
this.routerLink = routerLink;
this.routerLinkWithHref = routerLinkWithHref;
this.router = router;
this.el = this.elementRef.nativeElement;
this.destroy$ = new Subject();
this.originalPadding = null;
this.selected$ = new Subject();
this.nzDisabled = false;
this.nzSelected = false;
this.nzMatchRouterExact = false;
this.nzMatchRouter = false;
if (router) {
(/** @type {?} */ (this.router)).events.pipe(takeUntil(this.destroy$), filter((/**
* @param {?} e
* @return {?}
*/
e => e instanceof NavigationEnd))).subscribe((/**
* @return {?}
*/
() => {
this.updateRouterActive();
}));
}
}
/**
* clear all item selected status except this
* @param {?} e
* @return {?}
*/
clickMenuItem(e) {
if (this.nzDisabled) {
e.preventDefault();
e.stopPropagation();
return;
}
this.nzMenuService.onMenuItemClick(this);
if (this.nzSubmenuService) {
this.nzSubmenuService.onMenuItemClick();
}
}
/**
* @return {?}
*/
setClassMap() {
/** @type {?} */
const prefixName = this.nzMenuService.isInDropDown ? 'ant-dropdown-menu-item' : 'ant-menu-item';
this.nzUpdateHostClassService.updateHostClass(this.el, {
[`${prefixName}`]: true,
[`${prefixName}-selected`]: this.nzSelected,
[`${prefixName}-disabled`]: this.nzDisabled
});
}
/**
* @param {?} value
* @return {?}
*/
setSelectedState(value) {
this.nzSelected = value;
this.selected$.next(value);
this.setClassMap();
}
/**
* @private
* @return {?}
*/
updateRouterActive() {
if (!this.listOfRouterLink ||
!this.listOfRouterLinkWithHref ||
!this.router ||
!this.router.navigated ||
!this.nzMatchRouter) {
return;
}
Promise.resolve().then((/**
* @return {?}
*/
() => {
/** @type {?} */
const hasActiveLinks = this.hasActiveLinks();
if (this.nzSelected !== hasActiveLinks) {
this.nzSelected = hasActiveLinks;
this.setSelectedState(this.nzSelected);
}
}));
}
/**
* @private
* @return {?}
*/
hasActiveLinks() {
/** @type {?} */
const isActiveCheckFn = this.isLinkActive((/** @type {?} */ (this.router)));
return ((this.routerLink && isActiveCheckFn(this.routerLink)) ||
(this.routerLinkWithHref && isActiveCheckFn(this.routerLinkWithHref)) ||
this.listOfRouterLink.some(isActiveCheckFn) ||
this.listOfRouterLinkWithHref.some(isActiveCheckFn));
}
/**
* @private
* @param {?} router
* @return {?}
*/
isLinkActive(router) {
return (/**
* @param {?} link
* @return {?}
*/
(link) => router.isActive(link.urlTree, this.nzMatchRouterExact));
}
/**
* @return {?}
*/
ngOnInit() {
/**
* store origin padding in padding
* @type {?}
*/
const paddingLeft = this.el.style.paddingLeft;
if (paddingLeft) {
this.originalPadding = parseInt(paddingLeft, 10);
}
merge(this.nzMenuService.mode$, this.nzMenuService.inlineIndent$, this.nzSubmenuService ? this.nzSubmenuService.level$ : EMPTY)
.pipe(takeUntil(this.destroy$))
.subscribe((/**
* @return {?}
*/
() => {
/** @type {?} */
let padding = null;
if (this.nzMenuService.mode === 'inline') {
if (isNotNil(this.nzPaddingLeft)) {
padding = this.nzPaddingLeft;
}
else {
/** @type {?} */
const level = this.nzSubmenuService ? this.nzSubmenuService.level + 1 : 1;
padding = level * this.nzMenuService.inlineIndent;
}
}
else {
padding = this.originalPadding;
}
if (padding) {
this.renderer.setStyle(this.el, 'padding-left', `${padding}px`);
}
else {
this.renderer.removeStyle(this.el, 'padding-left');
}
}));
this.setClassMap();
}
/**
* @return {?}
*/
ngAfterContentInit() {
this.listOfRouterLink.changes.pipe(takeUntil(this.destroy$)).subscribe((/**
* @return {?}
*/
() => this.updateRouterActive()));
this.listOfRouterLinkWithHref.changes.pipe(takeUntil(this.destroy$)).subscribe((/**
* @return {?}
*/
() => this.updateRouterActive()));
this.updateRouterActive();
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.nzSelected) {
this.setSelectedState(this.nzSelected);
}
if (changes.nzDisabled) {
this.setClassMap();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzMenuItemDirective.decorators = [
{ type: Directive, args: [{
selector: '[nz-menu-item]',
exportAs: 'nzMenuItem',
providers: [NzUpdateHostClassService],
host: {
'(click)': 'clickMenuItem($event)'
}
},] }
];
/** @nocollapse */
NzMenuItemDirective.ctorParameters = () => [
{ type: NzUpdateHostClassService },
{ type: NzMenuBaseService },
{ type: NzSubmenuService, decorators: [{ type: Optional }] },
{ type: Renderer2 },
{ type: ElementRef },
{ type: RouterLink, decorators: [{ type: Optional }] },
{ type: RouterLinkWithHref, decorators: [{ type: Optional }] },
{ type: Router, decorators: [{ type: Optional }] }
];
NzMenuItemDirective.propDecorators = {
nzDisabled: [{ type: Input }],
nzSelected: [{ type: Input }],
nzPaddingLeft: [{ type: Input }],
nzMatchRouterExact: [{ type: Input }],
nzMatchRouter: [{ type: Input }],
listOfRouterLink: [{ type: ContentChildren, args: [RouterLink, { descendants: true },] }],
listOfRouterLinkWithHref: [{ type: ContentChildren, args: [RouterLinkWithHref, { descendants: true },] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzDisabled", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzSelected", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzMatchRouterExact", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzMatchRouter", void 0);
if (false) {
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.el;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.destroy$;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.originalPadding;
/** @type {?} */
NzMenuItemDirective.prototype.selected$;
/** @type {?} */
NzMenuItemDirective.prototype.nzDisabled;
/** @type {?} */
NzMenuItemDirective.prototype.nzSelected;
/** @type {?} */
NzMenuItemDirective.prototype.nzPaddingLeft;
/** @type {?} */
NzMenuItemDirective.prototype.nzMatchRouterExact;
/** @type {?} */
NzMenuItemDirective.prototype.nzMatchRouter;
/** @type {?} */
NzMenuItemDirective.prototype.listOfRouterLink;
/** @type {?} */
NzMenuItemDirective.prototype.listOfRouterLinkWithHref;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.nzUpdateHostClassService;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.nzMenuService;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.nzSubmenuService;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.renderer;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.elementRef;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.routerLink;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.routerLinkWithHref;
/**
* @type {?}
* @private
*/
NzMenuItemDirective.prototype.router;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
/**
* @param {?} higherOrderService
* @param {?} menuService
* @return {?}
*/
function NzMenuServiceFactory(higherOrderService, menuService) {
return higherOrderService ? higherOrderService : menuService;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzSubMenuComponent {
/**
* @param {?} elementRef
* @param {?} nzMenuService
* @param {?} cdr
* @param {?} nzSubmenuService
* @param {?} nzUpdateHostClassService
* @param {?} platform
* @param {?=} noAnimation
*/
constructor(elementRef, nzMenuService, cdr, nzSubmenuService, nzUpdateHostClassService, platform, noAnimation) {
this.elementRef = elementRef;
this.nzMenuService = nzMenuService;
this.cdr = cdr;
this.nzSubmenuService = nzSubmenuService;
this.nzUpdateHostClassService = nzUpdateHostClassService;
this.platform = platform;
this.noAnimation = noAnimation;
this.nzOpen = false;
this.nzDisabled = false;
this.nzOpenChange = new EventEmitter();
this.placement = 'rightTop';
this.expandState = 'collapsed';
this.overlayPositions = [...DEFAULT_SUBMENU_POSITIONS];
this.destroy$ = new Subject();
this.isChildMenuSelected = false;
this.isMouseHover = false;
}
/**
* @param {?} open
* @return {?}
*/
setOpenState(open) {
this.nzSubmenuService.setOpenState(open);
}
/**
* @return {?}
*/
clickSubMenuTitle() {
if (this.nzSubmenuService.mode === 'inline' && !this.nzMenuService.isInDropDown && !this.nzDisabled) {
this.setOpenState(!this.nzOpen);
}
}
/**
* @param {?} value
* @return {?}
*/
setMouseEnterState(value) {
this.isMouseHover = value;
this.setClassMap();
this.nzSubmenuService.setMouseEnterState(value);
}
/**
* @return {?}
*/
setTriggerWidth() {
if (this.nzSubmenuService.mode === 'horizontal' && this.platform.isBrowser) {
this.triggerWidth = this.cdkOverlayOrigin.nativeElement.getBoundingClientRect().width;
}
}
/**
* @param {?} position
* @return {?}
*/
onPositionChange(position) {
this.placement = (/** @type {?} */ (getPlacementName(position)));
this.cdr.markForCheck();
}
/**
* @return {?}
*/
setClassMap() {
/** @type {?} */
const prefixName = this.nzMenuService.isInDropDown ? 'ant-dropdown-menu-submenu' : 'ant-menu-submenu';
this.nzUpdateHostClassService.updateHostClass(this.elementRef.nativeElement, {
[`${prefixName}`]: true,
[`${prefixName}-disabled`]: this.nzDisabled,
[`${prefixName}-open`]: this.nzOpen,
[`${prefixName}-selected`]: this.isChildMenuSelected,
[`${prefixName}-${this.nzSubmenuService.mode}`]: true,
[`${prefixName}-active`]: this.isMouseHover && !this.nzDisabled
});
}
/**
* @return {?}
*/
ngOnInit() {
combineLatest([this.nzSubmenuService.mode$, this.nzSubmenuService.open$])
.pipe(takeUntil(this.destroy$))
.subscribe((/**
* @param {?} __0
* @return {?}
*/
([mode, open]) => {
if (open && mode === 'inline') {
this.expandState = 'expanded';
}
else if (open && mode === 'horizontal') {
this.expandState = 'bottom';
}
else if (open && mode === 'vertical') {
this.expandState = 'active';
}
else {
this.isMouseHover = false;
this.expandState = 'collapsed';
}
this.overlayPositions =
mode === 'horizontal' ? [POSITION_MAP.bottomLeft] : [POSITION_MAP.rightTop, POSITION_MAP.leftTop];
if (open !== this.nzOpen) {
this.setTriggerWidth();
this.nzOpen = open;
this.nzOpenChange.emit(this.nzOpen);
}
this.setClassMap();
}));
this.nzSubmenuService.menuOpen$.pipe(takeUntil(this.destroy$)).subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.nzMenuService.menuOpen$.next(data);
}));
merge(this.nzMenuService.mode$, this.nzMenuService.inlineIndent$, this.nzSubmenuService.level$, this.nzSubmenuService.open$, this.nzSubmenuService.mode$)
.pipe(takeUntil(this.destroy$))
.subscribe((/**
* @return {?}
*/
() => {
this.cdr.markForCheck();
}));
}
/**
* @return {?}
*/
ngAfterContentInit() {
this.setTriggerWidth();
this.listOfNzMenuItemDirective.changes
.pipe(startWith(true), flatMap((/**
* @return {?}
*/
() => merge(this.listOfNzMenuItemDirective.changes, ...this.listOfNzMenuItemDirective.map((/**
* @param {?} menu
* @return {?}
*/
menu => menu.selected$))))), startWith(true), map((/**
* @return {?}
*/
() => this.listOfNzMenuItemDirective.some((/**
* @param {?} e
* @return {?}
*/
e => e.nzSelected)))), takeUntil(this.destroy$))
.subscribe((/**
* @param {?} selected
* @return {?}
*/
selected => {
this.isChildMenuSelected = selected;
this.setClassMap();
}));
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.nzOpen) {
this.nzSubmenuService.setOpenState(this.nzOpen);
this.setTriggerWidth();
}
if (changes.nzDisabled) {
this.nzSubmenuService.disabled = this.nzDisabled;
this.setClassMap();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzSubMenuComponent.decorators = [
{ type: Component, args: [{
selector: '[nz-submenu]',
exportAs: 'nzSubmenu',
providers: [NzSubmenuService, NzUpdateHostClassService],
animations: [collapseMotion, zoomBigMotion, slideMotion],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
template: "<div cdkOverlayOrigin\n #origin=\"cdkOverlayOrigin\"\n [class.ant-dropdown-menu-submenu-title]=\"nzMenuService.isInDropDown\"\n [class.ant-menu-submenu-title]=\"!nzMenuService.isInDropDown\"\n [style.paddingLeft.px]=\"nzMenuService.mode === 'inline'? (nzPaddingLeft ? nzPaddingLeft : nzSubmenuService.level * nzMenuService.inlineIndent) : null\"\n (mouseenter)=\"setMouseEnterState(true)\"\n (mouseleave)=\"setMouseEnterState(false)\"\n (click)=\"clickSubMenuTitle()\">\n <i nz-icon [nzType]=\"nzIcon\" *ngIf=\"nzIcon\"></i>\n <ng-container *nzStringTemplateOutlet=\"nzTitle\"><span>{{ nzTitle }}</span></ng-container>\n <ng-content select=\"[title]\" *ngIf=\"!nzTitle\"></ng-content>\n <span *ngIf=\"nzMenuService.isInDropDown; else notDropdownTpl\" class=\"ant-dropdown-menu-submenu-arrow\">\n <i nz-icon nzType=\"right\" class=\"anticon-right ant-dropdown-menu-submenu-arrow-icon\"></i>\n </span>\n <ng-template #notDropdownTpl>\n <i class=\"ant-menu-submenu-arrow\"></i>\n </ng-template>\n</div>\n<ul *ngIf=\"nzMenuService.mode === 'inline'\"\n [@collapseMotion]=\"expandState\"\n [@.disabled]=\"noAnimation?.nzNoAnimation\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n [ngClass]=\"nzMenuClassName\"\n class=\"ant-menu ant-menu-inline ant-menu-sub\">\n <ng-template [ngTemplateOutlet]=\"subMenuTemplate\"></ng-template>\n</ul>\n<ng-template cdkConnectedOverlay\n (positionChange)=\"onPositionChange($event)\"\n [cdkConnectedOverlayPositions]=\"overlayPositions\"\n [cdkConnectedOverlayOrigin]=\"origin\"\n [cdkConnectedOverlayWidth]=\"triggerWidth\"\n [cdkConnectedOverlayOpen]=\"nzOpen && nzMenuService.mode !== 'inline'\">\n <div class=\"ant-menu-submenu ant-menu-submenu-popup\"\n [@slideMotion]=\"expandState\"\n [@zoomBigMotion]=\"expandState\"\n [@.disabled]=\"noAnimation?.nzNoAnimation\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n [class.ant-menu-light]=\"nzMenuService.theme === 'light'\"\n [class.ant-menu-dark]=\"nzMenuService.theme === 'dark'\"\n [class.ant-menu-submenu-placement-bottomLeft]=\"nzSubmenuService.mode === 'horizontal'\"\n [class.ant-menu-submenu-placement-rightTop]=\"nzSubmenuService.mode === 'vertical' && placement === 'rightTop'\"\n [class.ant-menu-submenu-placement-leftTop]=\"nzSubmenuService.mode === 'vertical' && placement === 'leftTop'\"\n (mouseleave)=\"setMouseEnterState(false)\"\n (mouseenter)=\"setMouseEnterState(true)\">\n <ul [class.ant-dropdown-menu]=\"nzMenuService.isInDropDown\"\n [class.ant-menu]=\"!nzMenuService.isInDropDown\"\n [class.ant-dropdown-menu-vertical]=\"nzMenuService.isInDropDown\"\n [class.ant-menu-vertical]=\"!nzMenuService.isInDropDown\"\n [class.ant-dropdown-menu-sub]=\"nzMenuService.isInDropDown\"\n [class.ant-menu-sub]=\"!nzMenuService.isInDropDown\"\n [ngClass]=\"nzMenuClassName\">\n <ng-template [ngTemplateOutlet]=\"subMenuTemplate\"></ng-template>\n </ul>\n </div>\n</ng-template>\n\n<ng-template #subMenuTemplate>\n <ng-content></ng-content>\n</ng-template>\n",
styles: [`
:root .ant-menu-submenu.ant-menu-submenu-placement-bottomLeft {
top: 6px;
position: relative;
}
:root .ant-menu-submenu.ant-menu-submenu-placement-rightTop {
left: 4px;
position: relative;
}
:root .ant-menu-submenu.ant-menu-submenu-placement-leftTop {
right: 4px;
position: relative;
}
`]
}] }
];
/** @nocollapse */
NzSubMenuComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: NzMenuBaseService },
{ type: ChangeDetectorRef },
{ type: NzSubmenuService },
{ type: NzUpdateHostClassService },
{ type: Platform },
{ type: NzNoAnimationDirective, decorators: [{ type: Host }, { type: Optional }] }
];
NzSubMenuComponent.propDecorators = {
nzMenuClassName: [{ type: Input }],
nzPaddingLeft: [{ type: Input }],
nzTitle: [{ type: Input }],
nzIcon: [{ type: Input }],
nzOpen: [{ type: Input }],
nzDisabled: [{ type: Input }],
nzOpenChange: [{ type: Output }],
cdkConnectedOverlay: [{ type: ViewChild, args: [CdkConnectedOverlay, { static: true },] }],
cdkOverlayOrigin: [{ type: ViewChild, args: [CdkOverlayOrigin, { static: true, read: ElementRef },] }],
listOfNzSubMenuComponent: [{ type: ContentChildren, args: [NzSubMenuComponent, { descendants: true },] }],
listOfNzMenuItemDirective: [{ type: ContentChildren, args: [NzMenuItemDirective, { descendants: true },] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSubMenuComponent.prototype, "nzOpen", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzSubMenuComponent.prototype, "nzDisabled", void 0);
if (false) {
/** @type {?} */
NzSubMenuComponent.prototype.nzMenuClassName;
/** @type {?} */
NzSubMenuComponent.prototype.nzPaddingLeft;
/** @type {?} */
NzSubMenuComponent.prototype.nzTitle;
/** @type {?} */
NzSubMenuComponent.prototype.nzIcon;
/** @type {?} */
NzSubMenuComponent.prototype.nzOpen;
/** @type {?} */
NzSubMenuComponent.prototype.nzDisabled;
/** @type {?} */
NzSubMenuComponent.prototype.nzOpenChange;
/** @type {?} */
NzSubMenuComponent.prototype.cdkConnectedOverlay;
/** @type {?} */
NzSubMenuComponent.prototype.cdkOverlayOrigin;
/** @type {?} */
NzSubMenuComponent.prototype.listOfNzSubMenuComponent;
/** @type {?} */
NzSubMenuComponent.prototype.listOfNzMenuItemDirective;
/** @type {?} */
NzSubMenuComponent.prototype.placement;
/** @type {?} */
NzSubMenuComponent.prototype.triggerWidth;
/** @type {?} */
NzSubMenuComponent.prototype.expandState;
/** @type {?} */
NzSubMenuComponent.prototype.overlayPositions;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.destroy$;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.isChildMenuSelected;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.isMouseHover;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.elementRef;
/** @type {?} */
NzSubMenuComponent.prototype.nzMenuService;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.cdr;
/** @type {?} */
NzSubMenuComponent.prototype.nzSubmenuService;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.nzUpdateHostClassService;
/**
* @type {?}
* @private
*/
NzSubMenuComponent.prototype.platform;
/** @type {?} */
NzSubMenuComponent.prototype.noAnimation;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
const ɵ0 = NzMenuServiceFactory;
class NzMenuDirective {
/**
* @param {?} elementRef
* @param {?} nzMenuService
* @param {?} nzUpdateHostClassService
*/
constructor(elementRef, nzMenuService, nzUpdateHostClassService) {
this.elementRef = elementRef;
this.nzMenuService = nzMenuService;
this.nzUpdateHostClassService = nzUpdateHostClassService;
this.destroy$ = new Subject();
this.listOfOpenedNzSubMenuComponent = [];
this.nzInlineIndent = 24;
this.nzTheme = 'light';
this.nzMode = 'vertical';
this.nzInDropDown = false;
this.nzInlineCollapsed = false;
this.nzSelectable = !this.nzMenuService.isInDropDown;
this.nzClick = new EventEmitter();
}
/**
* @return {?}
*/
updateInlineCollapse() {
if (this.listOfNzMenuItemDirective) {
if (this.nzInlineCollapsed) {
this.listOfOpenedNzSubMenuComponent = this.listOfNzSubMenuComponent.filter((/**
* @param {?} submenu
* @return {?}
*/
submenu => submenu.nzOpen));
this.listOfNzSubMenuComponent.forEach((/**
* @param {?} submenu
* @return {?}
*/
submenu => submenu.setOpenState(false)));
this.nzMode = 'vertical';
}
else {
this.listOfOpenedNzSubMenuComponent.forEach((/**
* @param {?} submenu
* @return {?}
*/
submenu => submenu.setOpenState(true)));
this.listOfOpenedNzSubMenuComponent = [];
this.nzMode = this.cacheMode;
}
this.nzMenuService.setMode(this.nzMode);
}
}
/**
* @return {?}
*/
setClassMap() {
/** @type {?} */
const prefixName = this.nzMenuService.isInDropDown ? 'ant-dropdown-menu' : 'ant-menu';
this.nzUpdateHostClassService.updateHostClass(this.elementRef.nativeElement, {
[`${prefixName}`]: true,
[`${prefixName}-root`]: true,
[`${prefixName}-${this.nzTheme}`]: true,
[`${prefixName}-${this.nzMode}`]: true,
[`${prefixName}-inline-collapsed`]: this.nzInlineCollapsed
});
}
/**
* @return {?}
*/
ngOnInit() {
this.setClassMap();
this.nzMenuService.menuItemClick$.pipe(takeUntil(this.destroy$)).subscribe((/**
* @param {?} menu
* @return {?}
*/
menu => {
this.nzClick.emit(menu);
if (this.nzSelectable) {
this.listOfNzMenuItemDirective.forEach((/**
* @param {?} item
* @return {?}
*/
item => item.setSelectedState(item === menu)));
}
}));
}
/**
* @return {?}
*/
ngAfterContentInit() {
this.cacheMode = this.nzMode;
this.updateInlineCollapse();
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.nzInlineCollapsed) {
this.updateInlineCollapse();
}
if (changes.nzInlineIndent) {
this.nzMenuService.setInlineIndent(this.nzInlineIndent);
}
if (changes.nzInDropDown) {
this.nzMenuService.isInDropDown = this.nzInDropDown;
}
if (changes.nzTheme) {
this.nzMenuService.setTheme(this.nzTheme);
}
if (changes.nzMode) {
this.nzMenuService.setMode(this.nzMode);
if (!changes.nzMode.isFirstChange() && this.listOfNzSubMenuComponent) {
this.listOfNzSubMenuComponent.forEach((/**
* @param {?} submenu
* @return {?}
*/
submenu => submenu.setOpenState(false)));
}
}
if (changes.nzTheme || changes.nzMode || changes.nzInlineCollapsed) {
this.setClassMap();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzMenuDirective.decorators = [
{ type: Directive, args: [{
selector: '[nz-menu]',
exportAs: 'nzMenu',
providers: [
NzUpdateHostClassService,
NzMenuService,
{
provide: NzMenuBaseService,
useFactory: ɵ0,
deps: [[new SkipSelf(), new Optional(), NzDropdownHigherOrderServiceToken], NzMenuService]
}
]
},] }
];
/** @nocollapse */
NzMenuDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: NzMenuBaseService },
{ type: NzUpdateHostClassService }
];
NzMenuDirective.propDecorators = {
listOfNzMenuItemDirective: [{ type: ContentChildren, args: [NzMenuItemDirective, { descendants: true },] }],
listOfNzSubMenuComponent: [{ type: ContentChildren, args: [NzSubMenuComponent, { descendants: true },] }],
nzInlineIndent: [{ type: Input }],
nzTheme: [{ type: Input }],
nzMode: [{ type: Input }],
nzInDropDown: [{ type: Input }],
nzInlineCollapsed: [{ type: Input }],
nzSelectable: [{ type: Input }],
nzClick: [{ type: Output }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuDirective.prototype, "nzInDropDown", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuDirective.prototype, "nzInlineCollapsed", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzMenuDirective.prototype, "nzSelectable", void 0);
if (false) {
/**
* @type {?}
* @private
*/
NzMenuDirective.prototype.destroy$;
/**
* @type {?}
* @private
*/
NzMenuDirective.prototype.cacheMode;
/**
* @type {?}
* @private
*/
NzMenuDirective.prototype.listOfOpenedNzSubMenuComponent;
/** @type {?} */
NzMenuDirective.prototype.listOfNzMenuItemDirective;
/** @type {?} */
NzMenuDirective.prototype.listOfNzSubMenuComponent;
/** @type {?} */
NzMenuDirective.prototype.nzInlineIndent;
/** @type {?} */
NzMenuDirective.prototype.nzTheme;
/** @type {?} */
NzMenuDirective.prototype.nzMode;
/** @type {?} */
NzMenuDirective.prototype.nzInDropDown;
/** @type {?} */
NzMenuDirective.prototype.nzInlineCollapsed;
/** @type {?} */
NzMenuDirective.prototype.nzSelectable;
/** @type {?} */
NzMenuDirective.prototype.nzClick;
/** @type {?} */
NzMenuDirective.prototype.elementRef;
/**
* @type {?}
* @private
*/
NzMenuDirective.prototype.nzMenuService;
/**
* @type {?}
* @private
*/
NzMenuDirective.prototype.nzUpdateHostClassService;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzMenuGroupComponent {
/**
* @param {?} elementRef
* @param {?} renderer
*/
constructor(elementRef, renderer) {
this.elementRef = elementRef;
this.renderer = renderer;
this.renderer.addClass(elementRef.nativeElement, 'ant-menu-item-group');
}
}
NzMenuGroupComponent.decorators = [
{ type: Component, args: [{
selector: '[nz-menu-group]',
exportAs: 'nzMenuGroup',
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
template: "<div class=\"ant-menu-item-group-title\">\n <ng-container *nzStringTemplateOutlet=\"nzTitle\">{{ nzTitle }}</ng-container>\n <ng-content select=\"[title]\" *ngIf=\"!nzTitle\"></ng-content>\n</div>\n<ul class=\"ant-menu-item-group-list\">\n <ng-content></ng-content>\n</ul>",
preserveWhitespaces: false
}] }
];
/** @nocollapse */
NzMenuGroupComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: Renderer2 }
];
NzMenuGroupComponent.propDecorators = {
nzTitle: [{ type: Input }]
};
if (false) {
/** @type {?} */
NzMenuGroupComponent.prototype.nzTitle;
/** @type {?} */
NzMenuGroupComponent.prototype.elementRef;
/**
* @type {?}
* @private
*/
NzMenuGroupComponent.prototype.renderer;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzMenuDividerDirective {
/**
* @param {?} elementRef
* @param {?} renderer
*/
constructor(elementRef, renderer) {
this.elementRef = elementRef;
this.renderer = renderer;
this.renderer.addClass(elementRef.nativeElement, 'ant-dropdown-menu-item-divider');
}
}
NzMenuDividerDirective.decorators = [
{ type: Directive, args: [{
selector: '[nz-menu-divider]',
exportAs: 'nzMenuDivider'
},] }
];
/** @nocollapse */
NzMenuDividerDirective.ctorParameters = () => [
{ type: ElementRef },
{ type: Renderer2 }
];
if (false) {
/** @type {?} */
NzMenuDividerDirective.prototype.elementRef;
/**
* @type {?}
* @private
*/
NzMenuDividerDirective.prototype.renderer;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzMenuModule {
}
NzMenuModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule,
FormsModule,
PlatformModule,
NzButtonModule,
OverlayModule,
NzIconModule,
NzNoAnimationModule,
NzAddOnModule
],
declarations: [
NzMenuDirective,
NzMenuItemDirective,
NzSubMenuComponent,
NzMenuDividerDirective,
NzMenuGroupComponent
],
exports: [NzMenuDirective, NzMenuItemDirective, NzSubMenuComponent, NzMenuDividerDirective, NzMenuGroupComponent]
},] }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzMenuDirective, NzMenuDividerDirective, NzMenuGroupComponent, NzMenuItemDirective, NzMenuModule, NzMenuService, NzMenuServiceFactory, NzSubMenuComponent, NzSubmenuService };
//# sourceMappingURL=ng-zorro-antd-menu.js.map