ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
943 lines (934 loc) • 70.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/bidi'), require('@angular/core'), require('ng-zorro-antd/core/util'), require('rxjs'), require('rxjs/operators'), require('@angular/router'), require('@angular/cdk/overlay'), require('@angular/cdk/platform'), require('ng-zorro-antd/core/no-animation'), require('ng-zorro-antd/core/overlay'), require('ng-zorro-antd/core/animation'), require('@angular/common'), require('ng-zorro-antd/core/outlet'), require('ng-zorro-antd/icon')) :
typeof define === 'function' && define.amd ? define('ng-zorro-antd/menu', ['exports', '@angular/cdk/bidi', '@angular/core', 'ng-zorro-antd/core/util', 'rxjs', 'rxjs/operators', '@angular/router', '@angular/cdk/overlay', '@angular/cdk/platform', 'ng-zorro-antd/core/no-animation', 'ng-zorro-antd/core/overlay', 'ng-zorro-antd/core/animation', '@angular/common', 'ng-zorro-antd/core/outlet', 'ng-zorro-antd/icon'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd'].menu = {}), global.ng.cdk.bidi, global.ng.core, global['ng-zorro-antd'].core.util, global.rxjs, global.rxjs.operators, global.ng.router, global.ng.cdk.overlay, global.ng.cdk.platform, global['ng-zorro-antd'].core['no-animation'], global['ng-zorro-antd'].core.overlay, global['ng-zorro-antd'].core.animation, global.ng.common, global['ng-zorro-antd'].core.outlet, global['ng-zorro-antd'].icon));
}(this, (function (exports, bidi, core, util, rxjs, operators, router, overlay$1, platform, noAnimation, overlay, animation, common, outlet, icon) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
/**
* 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
*/
var MenuService = /** @class */ (function () {
function MenuService() {
/** all descendant menu click **/
this.descendantMenuItemClick$ = new rxjs.Subject();
/** child menu item click **/
this.childMenuItemClick$ = new rxjs.Subject();
this.theme$ = new rxjs.BehaviorSubject('light');
this.mode$ = new rxjs.BehaviorSubject('vertical');
this.inlineIndent$ = new rxjs.BehaviorSubject(24);
this.isChildSubMenuOpen$ = new rxjs.BehaviorSubject(false);
}
MenuService.prototype.onDescendantMenuItemClick = function (menu) {
this.descendantMenuItemClick$.next(menu);
};
MenuService.prototype.onChildMenuItemClick = function (menu) {
this.childMenuItemClick$.next(menu);
};
MenuService.prototype.setMode = function (mode) {
this.mode$.next(mode);
};
MenuService.prototype.setTheme = function (theme) {
this.theme$.next(theme);
};
MenuService.prototype.setInlineIndent = function (indent) {
this.inlineIndent$.next(indent);
};
return MenuService;
}());
MenuService.decorators = [
{ type: core.Injectable }
];
/**
* 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
*/
var NzIsMenuInsideDropDownToken = new core.InjectionToken('NzIsInDropDownMenuToken');
var NzMenuServiceLocalToken = new core.InjectionToken('NzMenuServiceLocalToken');
var NzSubmenuService = /** @class */ (function () {
function NzSubmenuService(nzHostSubmenuService, nzMenuService, isMenuInsideDropDown) {
var _this = this;
this.nzHostSubmenuService = nzHostSubmenuService;
this.nzMenuService = nzMenuService;
this.isMenuInsideDropDown = isMenuInsideDropDown;
this.mode$ = this.nzMenuService.mode$.pipe(operators.map(function (mode) {
if (mode === 'inline') {
return 'inline';
/** if inside another submenu, set the mode to vertical **/
}
else if (mode === 'vertical' || _this.nzHostSubmenuService) {
return 'vertical';
}
else {
return 'horizontal';
}
}));
this.level = 1;
this.isCurrentSubMenuOpen$ = new rxjs.BehaviorSubject(false);
this.isChildSubMenuOpen$ = new rxjs.BehaviorSubject(false);
/** submenu title & overlay mouse enter status **/
this.isMouseEnterTitleOrOverlay$ = new rxjs.Subject();
this.childMenuItemClick$ = new rxjs.Subject();
this.destroy$ = new rxjs.Subject();
if (this.nzHostSubmenuService) {
this.level = this.nzHostSubmenuService.level + 1;
}
/** close if menu item clicked **/
var isClosedByMenuItemClick = this.childMenuItemClick$.pipe(operators.mergeMap(function () { return _this.mode$; }), operators.filter(function (mode) { return mode !== 'inline' || _this.isMenuInsideDropDown; }), operators.mapTo(false));
var isCurrentSubmenuOpen$ = rxjs.merge(this.isMouseEnterTitleOrOverlay$, isClosedByMenuItemClick);
/** combine the child submenu status with current submenu status to calculate host submenu open **/
var isSubMenuOpenWithDebounce$ = rxjs.combineLatest([this.isChildSubMenuOpen$, isCurrentSubmenuOpen$]).pipe(operators.map(function (_a) {
var _b = __read(_a, 2), isChildSubMenuOpen = _b[0], isCurrentSubmenuOpen = _b[1];
return isChildSubMenuOpen || isCurrentSubmenuOpen;
}), operators.auditTime(150), operators.distinctUntilChanged(), operators.takeUntil(this.destroy$));
isSubMenuOpenWithDebounce$.pipe(operators.distinctUntilChanged()).subscribe(function (data) {
_this.setOpenStateWithoutDebounce(data);
if (_this.nzHostSubmenuService) {
/** set parent submenu's child submenu open status **/
_this.nzHostSubmenuService.isChildSubMenuOpen$.next(data);
}
else {
_this.nzMenuService.isChildSubMenuOpen$.next(data);
}
});
}
/**
* menu item inside submenu clicked
* @param menu
*/
NzSubmenuService.prototype.onChildMenuItemClick = function (menu) {
this.childMenuItemClick$.next(menu);
};
NzSubmenuService.prototype.setOpenStateWithoutDebounce = function (value) {
this.isCurrentSubMenuOpen$.next(value);
};
NzSubmenuService.prototype.setMouseEnterTitleOrOverlayState = function (value) {
this.isMouseEnterTitleOrOverlay$.next(value);
};
NzSubmenuService.prototype.ngOnDestroy = function () {
this.destroy$.next();
this.destroy$.complete();
};
return NzSubmenuService;
}());
NzSubmenuService.decorators = [
{ type: core.Injectable }
];
NzSubmenuService.ctorParameters = function () { return [
{ type: NzSubmenuService, decorators: [{ type: core.SkipSelf }, { type: core.Optional }] },
{ type: MenuService },
{ type: Boolean, decorators: [{ type: core.Inject, args: [NzIsMenuInsideDropDownToken,] }] }
]; };
var NzMenuItemDirective = /** @class */ (function () {
function NzMenuItemDirective(nzMenuService, cdr, nzSubmenuService, isMenuInsideDropDown, directionality, routerLink, routerLinkWithHref, router$1) {
var _this = this;
this.nzMenuService = nzMenuService;
this.cdr = cdr;
this.nzSubmenuService = nzSubmenuService;
this.isMenuInsideDropDown = isMenuInsideDropDown;
this.directionality = directionality;
this.routerLink = routerLink;
this.routerLinkWithHref = routerLinkWithHref;
this.router = router$1;
this.destroy$ = new rxjs.Subject();
this.level = this.nzSubmenuService ? this.nzSubmenuService.level + 1 : 1;
this.selected$ = new rxjs.Subject();
this.inlinePaddingLeft = null;
this.dir = 'ltr';
this.nzDisabled = false;
this.nzSelected = false;
this.nzDanger = false;
this.nzMatchRouterExact = false;
this.nzMatchRouter = false;
if (router$1) {
this.router.events.pipe(operators.takeUntil(this.destroy$), operators.filter(function (e) { return e instanceof router.NavigationEnd; })).subscribe(function () {
_this.updateRouterActive();
});
}
}
/** clear all item selected status except this */
NzMenuItemDirective.prototype.clickMenuItem = function (e) {
if (this.nzDisabled) {
e.preventDefault();
e.stopPropagation();
}
else {
this.nzMenuService.onDescendantMenuItemClick(this);
if (this.nzSubmenuService) {
/** menu item inside the submenu **/
this.nzSubmenuService.onChildMenuItemClick(this);
}
else {
/** menu item inside the root menu **/
this.nzMenuService.onChildMenuItemClick(this);
}
}
};
NzMenuItemDirective.prototype.setSelectedState = function (value) {
this.nzSelected = value;
this.selected$.next(value);
};
NzMenuItemDirective.prototype.updateRouterActive = function () {
var _this = this;
if (!this.listOfRouterLink || !this.listOfRouterLinkWithHref || !this.router || !this.router.navigated || !this.nzMatchRouter) {
return;
}
Promise.resolve().then(function () {
var hasActiveLinks = _this.hasActiveLinks();
if (_this.nzSelected !== hasActiveLinks) {
_this.nzSelected = hasActiveLinks;
_this.setSelectedState(_this.nzSelected);
_this.cdr.markForCheck();
}
});
};
NzMenuItemDirective.prototype.hasActiveLinks = function () {
var isActiveCheckFn = this.isLinkActive(this.router);
return ((this.routerLink && isActiveCheckFn(this.routerLink)) ||
(this.routerLinkWithHref && isActiveCheckFn(this.routerLinkWithHref)) ||
this.listOfRouterLink.some(isActiveCheckFn) ||
this.listOfRouterLinkWithHref.some(isActiveCheckFn));
};
NzMenuItemDirective.prototype.isLinkActive = function (router) {
var _this = this;
return function (link) { return router.isActive(link.urlTree, _this.nzMatchRouterExact); };
};
NzMenuItemDirective.prototype.ngOnInit = function () {
var _this = this;
var _a;
/** store origin padding in padding */
rxjs.combineLatest([this.nzMenuService.mode$, this.nzMenuService.inlineIndent$])
.pipe(operators.takeUntil(this.destroy$))
.subscribe(function (_b) {
var _c = __read(_b, 2), mode = _c[0], inlineIndent = _c[1];
_this.inlinePaddingLeft = mode === 'inline' ? _this.level * inlineIndent : null;
});
this.dir = this.directionality.value;
(_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(operators.takeUntil(this.destroy$)).subscribe(function (direction) {
_this.dir = direction;
});
};
NzMenuItemDirective.prototype.ngAfterContentInit = function () {
var _this = this;
this.listOfRouterLink.changes.pipe(operators.takeUntil(this.destroy$)).subscribe(function () { return _this.updateRouterActive(); });
this.listOfRouterLinkWithHref.changes.pipe(operators.takeUntil(this.destroy$)).subscribe(function () { return _this.updateRouterActive(); });
this.updateRouterActive();
};
NzMenuItemDirective.prototype.ngOnChanges = function (changes) {
if (changes.nzSelected) {
this.setSelectedState(this.nzSelected);
}
};
NzMenuItemDirective.prototype.ngOnDestroy = function () {
this.destroy$.next();
this.destroy$.complete();
};
return NzMenuItemDirective;
}());
NzMenuItemDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[nz-menu-item]',
exportAs: 'nzMenuItem',
host: {
'[class.ant-dropdown-menu-item]': "isMenuInsideDropDown",
'[class.ant-dropdown-menu-item-selected]': "isMenuInsideDropDown && nzSelected",
'[class.ant-dropdown-menu-item-danger]': "isMenuInsideDropDown && nzDanger",
'[class.ant-dropdown-menu-item-disabled]': "isMenuInsideDropDown && nzDisabled",
'[class.ant-menu-item]': "!isMenuInsideDropDown",
'[class.ant-menu-item-selected]': "!isMenuInsideDropDown && nzSelected",
'[class.ant-menu-item-danger]': "!isMenuInsideDropDown && nzDanger",
'[class.ant-menu-item-disabled]': "!isMenuInsideDropDown && nzDisabled",
'[style.paddingLeft.px]': "dir === 'rtl' ? null : nzPaddingLeft || inlinePaddingLeft",
'[style.paddingRight.px]': "dir === 'rtl' ? nzPaddingLeft || inlinePaddingLeft : null",
'(click)': 'clickMenuItem($event)'
}
},] }
];
NzMenuItemDirective.ctorParameters = function () { return [
{ type: MenuService },
{ type: core.ChangeDetectorRef },
{ type: NzSubmenuService, decorators: [{ type: core.Optional }] },
{ type: Boolean, decorators: [{ type: core.Inject, args: [NzIsMenuInsideDropDownToken,] }] },
{ type: bidi.Directionality, decorators: [{ type: core.Optional }] },
{ type: router.RouterLink, decorators: [{ type: core.Optional }] },
{ type: router.RouterLinkWithHref, decorators: [{ type: core.Optional }] },
{ type: router.Router, decorators: [{ type: core.Optional }] }
]; };
NzMenuItemDirective.propDecorators = {
nzPaddingLeft: [{ type: core.Input }],
nzDisabled: [{ type: core.Input }],
nzSelected: [{ type: core.Input }],
nzDanger: [{ type: core.Input }],
nzMatchRouterExact: [{ type: core.Input }],
nzMatchRouter: [{ type: core.Input }],
listOfRouterLink: [{ type: core.ContentChildren, args: [router.RouterLink, { descendants: true },] }],
listOfRouterLinkWithHref: [{ type: core.ContentChildren, args: [router.RouterLinkWithHref, { descendants: true },] }]
};
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzDisabled", void 0);
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzSelected", void 0);
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzDanger", void 0);
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzMatchRouterExact", void 0);
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzMenuItemDirective.prototype, "nzMatchRouter", void 0);
var listOfVerticalPositions = [
overlay.POSITION_MAP.rightTop,
overlay.POSITION_MAP.right,
overlay.POSITION_MAP.rightBottom,
overlay.POSITION_MAP.leftTop,
overlay.POSITION_MAP.left,
overlay.POSITION_MAP.leftBottom
];
var listOfHorizontalPositions = [overlay.POSITION_MAP.bottomLeft];
var NzSubMenuComponent = /** @class */ (function () {
function NzSubMenuComponent(nzMenuService, cdr, nzSubmenuService, platform, isMenuInsideDropDown, directionality, noAnimation) {
this.nzMenuService = nzMenuService;
this.cdr = cdr;
this.nzSubmenuService = nzSubmenuService;
this.platform = platform;
this.isMenuInsideDropDown = isMenuInsideDropDown;
this.directionality = directionality;
this.noAnimation = noAnimation;
this.nzMenuClassName = '';
this.nzPaddingLeft = null;
this.nzTitle = null;
this.nzIcon = null;
this.nzOpen = false;
this.nzDisabled = false;
this.nzOpenChange = new core.EventEmitter();
this.cdkOverlayOrigin = null;
this.listOfNzSubMenuComponent = null;
this.listOfNzMenuItemDirective = null;
this.level = this.nzSubmenuService.level;
this.destroy$ = new rxjs.Subject();
this.position = 'right';
this.triggerWidth = null;
this.theme = 'light';
this.mode = 'vertical';
this.inlinePaddingLeft = null;
this.overlayPositions = listOfVerticalPositions;
this.isSelected = false;
this.isActive = false;
this.dir = 'ltr';
}
/** set the submenu host open status directly **/
NzSubMenuComponent.prototype.setOpenStateWithoutDebounce = function (open) {
this.nzSubmenuService.setOpenStateWithoutDebounce(open);
};
NzSubMenuComponent.prototype.toggleSubMenu = function () {
this.setOpenStateWithoutDebounce(!this.nzOpen);
};
NzSubMenuComponent.prototype.setMouseEnterState = function (value) {
this.isActive = value;
if (this.mode !== 'inline') {
this.nzSubmenuService.setMouseEnterTitleOrOverlayState(value);
}
};
NzSubMenuComponent.prototype.setTriggerWidth = function () {
if (this.mode === 'horizontal' && this.platform.isBrowser && this.cdkOverlayOrigin) {
/** TODO: fast dom **/
this.triggerWidth = this.cdkOverlayOrigin.nativeElement.getBoundingClientRect().width;
}
};
NzSubMenuComponent.prototype.onPositionChange = function (position) {
var placement = overlay.getPlacementName(position);
if (placement === 'rightTop' || placement === 'rightBottom' || placement === 'right') {
this.position = 'right';
}
else if (placement === 'leftTop' || placement === 'leftBottom' || placement === 'left') {
this.position = 'left';
}
this.cdr.markForCheck();
};
NzSubMenuComponent.prototype.ngOnInit = function () {
var _this = this;
var _a;
/** submenu theme update **/
this.nzMenuService.theme$.pipe(operators.takeUntil(this.destroy$)).subscribe(function (theme) {
_this.theme = theme;
_this.cdr.markForCheck();
});
/** submenu mode update **/
this.nzSubmenuService.mode$.pipe(operators.takeUntil(this.destroy$)).subscribe(function (mode) {
_this.mode = mode;
if (mode === 'horizontal') {
_this.overlayPositions = listOfHorizontalPositions;
}
else if (mode === 'vertical') {
_this.overlayPositions = listOfVerticalPositions;
}
_this.cdr.markForCheck();
});
/** inlineIndent update **/
rxjs.combineLatest([this.nzSubmenuService.mode$, this.nzMenuService.inlineIndent$])
.pipe(operators.takeUntil(this.destroy$))
.subscribe(function (_b) {
var _c = __read(_b, 2), mode = _c[0], inlineIndent = _c[1];
_this.inlinePaddingLeft = mode === 'inline' ? _this.level * inlineIndent : null;
_this.cdr.markForCheck();
});
/** current submenu open status **/
this.nzSubmenuService.isCurrentSubMenuOpen$.pipe(operators.takeUntil(this.destroy$)).subscribe(function (open) {
_this.isActive = open;
if (open !== _this.nzOpen) {
_this.setTriggerWidth();
_this.nzOpen = open;
_this.nzOpenChange.emit(_this.nzOpen);
_this.cdr.markForCheck();
}
});
this.dir = this.directionality.value;
(_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(operators.takeUntil(this.destroy$)).subscribe(function (direction) {
_this.dir = direction;
_this.cdr.markForCheck();
});
};
NzSubMenuComponent.prototype.ngAfterContentInit = function () {
var _this = this;
this.setTriggerWidth();
var listOfNzMenuItemDirective = this.listOfNzMenuItemDirective;
var changes = listOfNzMenuItemDirective.changes;
var mergedObservable = rxjs.merge.apply(void 0, __spread([changes], listOfNzMenuItemDirective.map(function (menu) { return menu.selected$; })));
changes
.pipe(operators.startWith(listOfNzMenuItemDirective), operators.switchMap(function () { return mergedObservable; }), operators.startWith(true), operators.map(function () { return listOfNzMenuItemDirective.some(function (e) { return e.nzSelected; }); }), operators.takeUntil(this.destroy$))
.subscribe(function (selected) {
_this.isSelected = selected;
_this.cdr.markForCheck();
});
};
NzSubMenuComponent.prototype.ngOnChanges = function (changes) {
var nzOpen = changes.nzOpen;
if (nzOpen) {
this.nzSubmenuService.setOpenStateWithoutDebounce(this.nzOpen);
this.setTriggerWidth();
}
};
NzSubMenuComponent.prototype.ngOnDestroy = function () {
this.destroy$.next();
this.destroy$.complete();
};
return NzSubMenuComponent;
}());
NzSubMenuComponent.decorators = [
{ type: core.Component, args: [{
selector: '[nz-submenu]',
exportAs: 'nzSubmenu',
providers: [NzSubmenuService],
encapsulation: core.ViewEncapsulation.None,
changeDetection: core.ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
template: "\n <div\n nz-submenu-title\n cdkOverlayOrigin\n #origin=\"cdkOverlayOrigin\"\n [nzIcon]=\"nzIcon\"\n [nzTitle]=\"nzTitle\"\n [mode]=\"mode\"\n [nzDisabled]=\"nzDisabled\"\n [isMenuInsideDropDown]=\"isMenuInsideDropDown\"\n [paddingLeft]=\"nzPaddingLeft || inlinePaddingLeft\"\n (subMenuMouseState)=\"setMouseEnterState($event)\"\n (toggleSubMenu)=\"toggleSubMenu()\"\n >\n <ng-content select=\"[title]\" *ngIf=\"!nzTitle\"></ng-content>\n </div>\n <div\n *ngIf=\"mode === 'inline'; else nonInlineTemplate\"\n nz-submenu-inline-child\n [mode]=\"mode\"\n [nzOpen]=\"nzOpen\"\n [@.disabled]=\"noAnimation?.nzNoAnimation\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n [menuClass]=\"nzMenuClassName\"\n [templateOutlet]=\"subMenuTemplate\"\n ></div>\n <ng-template #nonInlineTemplate>\n <ng-template\n cdkConnectedOverlay\n (positionChange)=\"onPositionChange($event)\"\n [cdkConnectedOverlayPositions]=\"overlayPositions\"\n [cdkConnectedOverlayOrigin]=\"origin\"\n [cdkConnectedOverlayWidth]=\"triggerWidth!\"\n [cdkConnectedOverlayOpen]=\"nzOpen\"\n [cdkConnectedOverlayTransformOriginOn]=\"'.ant-menu-submenu'\"\n >\n <div\n nz-submenu-none-inline-child\n [theme]=\"theme\"\n [mode]=\"mode\"\n [nzOpen]=\"nzOpen\"\n [position]=\"position\"\n [nzDisabled]=\"nzDisabled\"\n [isMenuInsideDropDown]=\"isMenuInsideDropDown\"\n [templateOutlet]=\"subMenuTemplate\"\n [menuClass]=\"nzMenuClassName\"\n [@.disabled]=\"noAnimation?.nzNoAnimation\"\n [nzNoAnimation]=\"noAnimation?.nzNoAnimation\"\n (subMenuMouseState)=\"setMouseEnterState($event)\"\n ></div>\n </ng-template>\n </ng-template>\n\n <ng-template #subMenuTemplate>\n <ng-content></ng-content>\n </ng-template>\n ",
host: {
'[class.ant-dropdown-menu-submenu]': "isMenuInsideDropDown",
'[class.ant-dropdown-menu-submenu-disabled]': "isMenuInsideDropDown && nzDisabled",
'[class.ant-dropdown-menu-submenu-open]': "isMenuInsideDropDown && nzOpen",
'[class.ant-dropdown-menu-submenu-selected]': "isMenuInsideDropDown && isSelected",
'[class.ant-dropdown-menu-submenu-vertical]': "isMenuInsideDropDown && mode === 'vertical'",
'[class.ant-dropdown-menu-submenu-horizontal]': "isMenuInsideDropDown && mode === 'horizontal'",
'[class.ant-dropdown-menu-submenu-inline]': "isMenuInsideDropDown && mode === 'inline'",
'[class.ant-dropdown-menu-submenu-active]': "isMenuInsideDropDown && isActive",
'[class.ant-menu-submenu]': "!isMenuInsideDropDown",
'[class.ant-menu-submenu-disabled]': "!isMenuInsideDropDown && nzDisabled",
'[class.ant-menu-submenu-open]': "!isMenuInsideDropDown && nzOpen",
'[class.ant-menu-submenu-selected]': "!isMenuInsideDropDown && isSelected",
'[class.ant-menu-submenu-vertical]': "!isMenuInsideDropDown && mode === 'vertical'",
'[class.ant-menu-submenu-horizontal]': "!isMenuInsideDropDown && mode === 'horizontal'",
'[class.ant-menu-submenu-inline]': "!isMenuInsideDropDown && mode === 'inline'",
'[class.ant-menu-submenu-active]': "!isMenuInsideDropDown && isActive",
'[class.ant-menu-submenu-rtl]': "dir === 'rtl'"
}
},] }
];
NzSubMenuComponent.ctorParameters = function () { return [
{ type: MenuService },
{ type: core.ChangeDetectorRef },
{ type: NzSubmenuService },
{ type: platform.Platform },
{ type: Boolean, decorators: [{ type: core.Inject, args: [NzIsMenuInsideDropDownToken,] }] },
{ type: bidi.Directionality, decorators: [{ type: core.Optional }] },
{ type: noAnimation.NzNoAnimationDirective, decorators: [{ type: core.Host }, { type: core.Optional }] }
]; };
NzSubMenuComponent.propDecorators = {
nzMenuClassName: [{ type: core.Input }],
nzPaddingLeft: [{ type: core.Input }],
nzTitle: [{ type: core.Input }],
nzIcon: [{ type: core.Input }],
nzOpen: [{ type: core.Input }],
nzDisabled: [{ type: core.Input }],
nzOpenChange: [{ type: core.Output }],
cdkOverlayOrigin: [{ type: core.ViewChild, args: [overlay$1.CdkOverlayOrigin, { static: true, read: core.ElementRef },] }],
listOfNzSubMenuComponent: [{ type: core.ContentChildren, args: [NzSubMenuComponent, { descendants: true },] }],
listOfNzMenuItemDirective: [{ type: core.ContentChildren, args: [NzMenuItemDirective, { descendants: true },] }]
};
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzSubMenuComponent.prototype, "nzOpen", void 0);
__decorate([
util.InputBoolean(),
__metadata("design:type", Object)
], NzSubMenuComponent.prototype, "nzDisabled", void 0);
function MenuServiceFactory(serviceInsideDropDown, serviceOutsideDropDown) {
return serviceInsideDropDown ? serviceInsideDropDown : serviceOutsideDropDown;
}
function MenuDropDownTokenFactory(isMenuInsideDropDownToken) {
return isMenuInsideDropDownToken ? isMenuInsideDropDownToken : false;
}
var NzMenuDirective = /** @class */ (function () {
function NzMenuDirective(nzMenuService, isMenuInsideDropDown, cdr, directionality) {
this.nzMenuService = nzMenuService;
this.isMenuInsideDropDown = isMenuInsideDropDown;
this.cdr = cdr;
this.directionality = directionality;
this.nzInlineIndent = 24;
this.nzTheme = 'light';
this.nzMode = 'vertical';
this.nzInlineCollapsed = false;
this.nzSelectable = !this.isMenuInsideDropDown;
this.nzClick = new core.EventEmitter();
this.actualMode = 'vertical';
this.dir = 'ltr';
this.inlineCollapsed$ = new rxjs.BehaviorSubject(this.nzInlineCollapsed);
this.mode$ = new rxjs.BehaviorSubject(this.nzMode);
this.destroy$ = new rxjs.Subject();
this.listOfOpenedNzSubMenuComponent = [];
}
NzMenuDirective.prototype.setInlineCollapsed = function (inlineCollapsed) {
this.nzInlineCollapsed = inlineCollapsed;
this.inlineCollapsed$.next(inlineCollapsed);
};
NzMenuDirective.prototype.updateInlineCollapse = function () {
if (this.listOfNzMenuItemDirective) {
if (this.nzInlineCollapsed) {
this.listOfOpenedNzSubMenuComponent = this.listOfNzSubMenuComponent.filter(function (submenu) { return submenu.nzOpen; });
this.listOfNzSubMenuComponent.forEach(function (submenu) { return submenu.setOpenStateWithoutDebounce(false); });
}
else {
this.listOfOpenedNzSubMenuComponent.forEach(function (submenu) { return submenu.setOpenStateWithoutDebounce(true); });
this.listOfOpenedNzSubMenuComponent = [];
}
}
};
NzMenuDirective.prototype.ngOnInit = function () {
var _this = this;
var _a;
rxjs.combineLatest([this.inlineCollapsed$, this.mode$])
.pipe(operators.takeUntil(this.destroy$))
.subscribe(function (_b) {
var _c = __read(_b, 2), inlineCollapsed = _c[0], mode = _c[1];
_this.actualMode = inlineCollapsed ? 'vertical' : mode;
_this.nzMenuService.setMode(_this.actualMode);
_this.cdr.markForCheck();
});
this.nzMenuService.descendantMenuItemClick$.pipe(operators.takeUntil(this.destroy$)).subscribe(function (menu) {
_this.nzClick.emit(menu);
if (_this.nzSelectable && !menu.nzMatchRouter) {
_this.listOfNzMenuItemDirective.forEach(function (item) { return item.setSelectedState(item === menu); });
}
});
this.dir = this.directionality.value;
(_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(operators.takeUntil(this.destroy$)).subscribe(function (direction) {
_this.dir = direction;
_this.nzMenuService.setMode(_this.actualMode);
_this.cdr.markForCheck();
});
};
NzMenuDirective.prototype.ngAfterContentInit = function () {
var _this = this;
this.inlineCollapsed$.pipe(operators.takeUntil(this.destroy$)).subscribe(function () {
_this.updateInlineCollapse();
_this.cdr.markForCheck();
});
};
NzMenuDirective.prototype.ngOnChanges = function (changes) {
var nzInlineCollapsed = changes.nzInlineCollapsed, nzInlineIndent = changes.nzInlineIndent, nzTheme = changes.nzTheme, nzMode = changes.nzMode;
if (nzInlineCollapsed) {
this.inlineCollapsed$.next(this.nzInlineCollapsed);
}
if (nzInlineIndent) {
this.nzMenuService.setInlineIndent(this.nzInlineIndent);
}
if (nzTheme) {
this.nzMenuService.setTheme(this.nzTheme);
}
if (nzMode) {
this.mode$.next(this.nzMode);
if (!changes.nzMode.isFirstChange() && this.listOfNzSubMenuComponent) {
this.listOfNzSubMenuComponent.forEach(function (submenu) { return submenu.setOpenStateWithoutDebounce(false); });
}
}
};
NzMenuDirective.prototype.ngOnDestroy = function () {
this.destroy$.next();
this.destroy$.complete();
};
return NzMenuDirective;
}());
NzMenuDirective.decorators = [
{ type: core.Directive, args: [{
selector: '[nz-menu]',
exportAs: 'nzMenu',
providers: [
{
provide: NzMenuServiceLocalToken,
useClass: MenuService
},
/** use the top level service **/
{
provide: MenuService,
useFactory: MenuServiceFactory,
deps: [[new core.SkipSelf(), new core.Optional(), MenuService], NzMenuServiceLocalToken]
},
/** check if menu inside dropdown-menu component **/
{
provide: NzIsMenuInsideDropDownToken,
useFactory: MenuDropDownTokenFactory,
deps: [[new core.SkipSelf(), new core.Optional(), NzIsMenuInsideDropDownToken]]
}
],
host: {
'[class.ant-dropdown-menu]': "isMenuInsideDropDown",
'[class.ant-dropdown-menu-root]': "isMenuInsideDropDown",
'[class.ant-dropdown-menu-light]': "isMenuInsideDropDown && nzTheme === 'light'",
'[class.ant-dropdown-menu-dark]': "isMenuInsideDropDown && nzTheme === 'dark'",
'[class.ant-dropdown-menu-vertical]': "isMenuInsideDropDown && actualMode === 'vertical'",
'[class.ant-dropdown-menu-horizontal]': "isMenuInsideDropDown && actualMode === 'horizontal'",
'[class.ant-dropdown-menu-inline]': "isMenuInsideDropDown && actualMode === 'inline'",
'[class.ant-dropdown-menu-inline-collapsed]': "isMenuInsideDropDown && nzInlineCollapsed",
'[class.ant-menu]': "!isMenuInsideDropDown",
'[class.ant-menu-root]': "!isMenuInsideDropDown",
'[class.ant-menu-light]': "!isMenuInsideDropDown && nzTheme === 'light'",
'[class.ant-menu-dark]': "!isMenuInsideDropDown && nzTheme === 'dark'",
'[class.ant-menu-vertical]': "!isMenuInsideDropDown && actualMode === 'vertical'",
'[class.ant-menu-horizontal]': "!isMenuInsideDropDown && actualMode === 'horizontal'",
'[class.ant-menu-inline]': "!isMenuInsideDropDown && actualMode === 'inline'",
'[class.ant-menu-inline-collapsed]': "!isMenuInsideDropDown && nzInlineCollapsed",
'[class.ant-menu-rtl]': "dir === 'rtl'"
}
},] }
];
NzMenuDirective.ctorParameters = function () { return [
{ type: MenuService },
{ type: Boolean, decorators: [{ type: core.Inject, args: [NzIsMenuInsideDropDownToken,] }] },
{ type: core.ChangeDetectorRef },
{ type: bidi.Directionality, decorators: [{ type: core.Optional }] }
]; };
NzMenuDirective.propDec