@lxlib/seed
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
630 lines (624 loc) • 22.5 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { DOCUMENT, CommonModule } from '@angular/common';
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Renderer2, ChangeDetectorRef, NgZone, Inject, Input, Output, NgModule } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { NavigationEnd, Router, RouterModule } from '@angular/router';
import { MenuService, SettingsService, WINDOW } from '@lxlib/theme';
import { InputBoolean, LxlibUtilModule } from '@lxlib/util';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
/**
* @fileoverview added by tsickle
* Generated from: sidebar-nav.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SHOWCLS = 'sidebar-nav__floating-show';
/** @type {?} */
var FLOATINGCLS = 'sidebar-nav__floating';
var SidebarNavComponent = /** @class */ (function () {
function SidebarNavComponent(menuSrv, settings, router, render, cdr, ngZone, sanitizer, doc, win) {
this.menuSrv = menuSrv;
this.settings = settings;
this.router = router;
this.render = render;
this.cdr = cdr;
this.ngZone = ngZone;
this.sanitizer = sanitizer;
this.doc = doc;
this.win = win;
this.unsubscribe$ = new Subject();
this.list = [];
this.disabledAcl = false;
this.autoCloseUnderPad = true;
this.recursivePath = true;
this.openStrictly = false;
// tslint:disable-next-line:no-output-native
this.select = new EventEmitter();
}
Object.defineProperty(SidebarNavComponent.prototype, "collapsed", {
get: /**
* @return {?}
*/
function () {
return this.settings.layout.collapsed;
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {?} node
* @return {?}
*/
SidebarNavComponent.prototype.getLinkNode = /**
* @private
* @param {?} node
* @return {?}
*/
function (node) {
node = node.nodeName === 'A' ? node : ((/** @type {?} */ (node.parentNode)));
return node.nodeName !== 'A' ? null : node;
};
/**
* @private
* @param {?} e
* @return {?}
*/
SidebarNavComponent.prototype.floatingAreaClickHandle = /**
* @private
* @param {?} e
* @return {?}
*/
function (e) {
e.stopPropagation();
/** @type {?} */
var linkNode = this.getLinkNode((/** @type {?} */ (e.target)));
if (linkNode == null) {
return false;
}
/** @type {?} */
var id = +(/** @type {?} */ ((/** @type {?} */ (linkNode.dataset)).id));
// Should be ingore children title trigger event
if (isNaN(id)) {
return false;
}
/** @type {?} */
var item;
this.menuSrv.visit(this.list, (/**
* @param {?} i
* @return {?}
*/
function (i) {
if (!item && i.__id === id) {
item = i;
}
}));
this.to((/** @type {?} */ (item)));
this.hideAll();
e.preventDefault();
return false;
};
/**
* @private
* @return {?}
*/
SidebarNavComponent.prototype.clearFloatingContainer = /**
* @private
* @return {?}
*/
function () {
if (!this.floatingEl)
return;
this.floatingEl.removeEventListener('click', this.floatingAreaClickHandle.bind(this));
// fix ie: https://github.com/ng-alain/lxlib/issues/52
if (this.floatingEl.hasOwnProperty('remove')) {
this.floatingEl.remove();
}
else if (this.floatingEl.parentNode) {
this.floatingEl.parentNode.removeChild(this.floatingEl);
}
};
/**
* @private
* @return {?}
*/
SidebarNavComponent.prototype.genFloatingContainer = /**
* @private
* @return {?}
*/
function () {
this.clearFloatingContainer();
this.floatingEl = this.render.createElement('div');
this.floatingEl.classList.add(FLOATINGCLS + '-container');
this.floatingEl.addEventListener('click', this.floatingAreaClickHandle.bind(this), false);
this.bodyEl.appendChild(this.floatingEl);
};
/**
* @private
* @param {?} linkNode
* @param {?} item
* @return {?}
*/
SidebarNavComponent.prototype.genSubNode = /**
* @private
* @param {?} linkNode
* @param {?} item
* @return {?}
*/
function (linkNode, item) {
/** @type {?} */
var id = "_sidebar-nav-" + item.__id;
/** @type {?} */
var childNode = item.badge ? (/** @type {?} */ ((/** @type {?} */ (linkNode.nextElementSibling)).nextElementSibling)) : (/** @type {?} */ (linkNode.nextElementSibling));
/** @type {?} */
var node = (/** @type {?} */ (childNode.cloneNode(true)));
node.id = id;
node.classList.add(FLOATINGCLS);
node.addEventListener('mouseleave', (/**
* @return {?}
*/
function () {
node.classList.remove(SHOWCLS);
}), false);
this.floatingEl.appendChild(node);
return node;
};
/**
* @private
* @return {?}
*/
SidebarNavComponent.prototype.hideAll = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var allNode = this.floatingEl.querySelectorAll('.' + FLOATINGCLS);
// tslint:disable-next-line:prefer-for-of
for (var i = 0; i < allNode.length; i++) {
allNode[i].classList.remove(SHOWCLS);
}
};
// calculate the node position values.
// calculate the node position values.
/**
* @private
* @param {?} linkNode
* @param {?} node
* @return {?}
*/
SidebarNavComponent.prototype.calPos =
// calculate the node position values.
/**
* @private
* @param {?} linkNode
* @param {?} node
* @return {?}
*/
function (linkNode, node) {
/** @type {?} */
var rect = linkNode.getBoundingClientRect();
// bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/14721015/
/** @type {?} */
var scrollTop = Math.max(this.doc.documentElement.scrollTop, this.bodyEl.scrollTop);
/** @type {?} */
var docHeight = Math.max(this.doc.documentElement.clientHeight, this.bodyEl.clientHeight);
/** @type {?} */
var offsetHeight = 0;
if (docHeight < rect.top + node.clientHeight) {
offsetHeight = rect.top + node.clientHeight - docHeight;
}
node.style.top = rect.top + scrollTop - offsetHeight + "px";
node.style.left = rect.right + 5 + "px";
};
/**
* @param {?} e
* @param {?} item
* @return {?}
*/
SidebarNavComponent.prototype.showSubMenu = /**
* @param {?} e
* @param {?} item
* @return {?}
*/
function (e, item) {
var _this = this;
if (this.collapsed !== true) {
return;
}
this.ngZone.runOutsideAngular((/**
* @return {?}
*/
function () {
e.preventDefault();
/** @type {?} */
var linkNode = (/** @type {?} */ (e.target));
_this.genFloatingContainer();
/** @type {?} */
var subNode = _this.genSubNode((/** @type {?} */ (linkNode)), item);
_this.hideAll();
subNode.classList.add(SHOWCLS);
_this.calPos((/** @type {?} */ (linkNode)), subNode);
}));
};
/**
* @param {?} item
* @return {?}
*/
SidebarNavComponent.prototype.to = /**
* @param {?} item
* @return {?}
*/
function (item) {
var _this = this;
this.select.emit(item);
if (item.disabled)
return;
if (item.externalLink) {
if (item.target === '_blank') {
this.win.open(item.externalLink);
}
else {
this.win.location.href = item.externalLink;
}
return;
}
this.ngZone.run((/**
* @return {?}
*/
function () { return _this.router.navigateByUrl((/** @type {?} */ (item.link))); }));
};
/**
* @param {?} item
* @return {?}
*/
SidebarNavComponent.prototype.toggleOpen = /**
* @param {?} item
* @return {?}
*/
function (item) {
if (!this.openStrictly) {
this.menuSrv.visit(this.list, (/**
* @param {?} i
* @return {?}
*/
function (i) {
if (i !== item)
i._open = false;
}));
/** @type {?} */
var pItem = item.__parent;
while (pItem) {
pItem._open = true;
pItem = pItem.__parent;
}
}
item._open = !item._open;
this.cdr.markForCheck();
};
/**
* @return {?}
*/
SidebarNavComponent.prototype._click = /**
* @return {?}
*/
function () {
if (this.isPad && this.collapsed) {
this.openAside(false);
this.hideAll();
}
};
/**
* @return {?}
*/
SidebarNavComponent.prototype._docClick = /**
* @return {?}
*/
function () {
if (this.collapsed) {
this.hideAll();
}
};
/**
* @private
* @param {?} url
* @return {?}
*/
SidebarNavComponent.prototype.openedByUrl = /**
* @private
* @param {?} url
* @return {?}
*/
function (url) {
var _a = this, menuSrv = _a.menuSrv, recursivePath = _a.recursivePath, openStrictly = _a.openStrictly;
/** @type {?} */
var findItem = menuSrv.getHit(this.menuSrv.menus, (/** @type {?} */ (url)), recursivePath, (/**
* @param {?} i
* @return {?}
*/
function (i) {
i._selected = false;
if (!openStrictly) {
i._open = false;
}
}));
if (findItem == null)
return;
do {
findItem._selected = true;
if (!openStrictly) {
findItem._open = true;
}
findItem = findItem.__parent;
} while (findItem);
};
/**
* @return {?}
*/
SidebarNavComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
var _a = this, doc = _a.doc, router = _a.router, unsubscribe$ = _a.unsubscribe$, menuSrv = _a.menuSrv, cdr = _a.cdr;
this.bodyEl = doc.querySelector('body');
this.openedByUrl(router.url);
this.ngZone.runOutsideAngular((/**
* @return {?}
*/
function () { return _this.genFloatingContainer(); }));
menuSrv.change.pipe(takeUntil(unsubscribe$)).subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
menuSrv.visit(data, (/**
* @param {?} i
* @param {?} _p
* @param {?} depth
* @return {?}
*/
function (i, _p, depth) {
i._text = _this.sanitizer.bypassSecurityTrustHtml((/** @type {?} */ (i.text)));
i._needIcon = (/** @type {?} */ (depth)) <= 3 && !!i.icon;
if (!i._aclResult) {
if (_this.disabledAcl) {
i.disabled = true;
}
else {
i._hidden = true;
}
}
if (_this.openStrictly) {
i._open = i.open != null ? i.open : false;
}
}));
_this.list = menuSrv.menus;
cdr.detectChanges();
}));
router.events.pipe(takeUntil(unsubscribe$)).subscribe((/**
* @param {?} e
* @return {?}
*/
function (e) {
if (e instanceof NavigationEnd) {
_this.openedByUrl(e.urlAfterRedirects);
_this.underPad();
_this.cdr.detectChanges();
}
}));
this.underPad();
};
/**
* @return {?}
*/
SidebarNavComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
var unsubscribe$ = this.unsubscribe$;
unsubscribe$.next();
unsubscribe$.complete();
this.clearFloatingContainer();
};
Object.defineProperty(SidebarNavComponent.prototype, "isPad", {
// #region Under pad
get:
// #region Under pad
/**
* @private
* @return {?}
*/
function () {
return window.innerWidth < 768;
},
enumerable: true,
configurable: true
});
/**
* @private
* @return {?}
*/
SidebarNavComponent.prototype.underPad = /**
* @private
* @return {?}
*/
function () {
var _this = this;
if (this.autoCloseUnderPad && this.isPad && !this.collapsed) {
setTimeout((/**
* @return {?}
*/
function () { return _this.openAside(true); }));
}
};
/**
* @private
* @param {?} status
* @return {?}
*/
SidebarNavComponent.prototype.openAside = /**
* @private
* @param {?} status
* @return {?}
*/
function (status) {
this.settings.setLayout('collapsed', status);
};
SidebarNavComponent.decorators = [
{ type: Component, args: [{
selector: 'sidebar-nav',
exportAs: 'sidebarNav',
template: "<ng-template #icon let-i>\n <ng-container *ngIf=\"i\" [ngSwitch]=\"i.type\">\n <i *ngSwitchCase=\"'icon'\" class=\"sidebar-nav__item-icon\" nz-icon [nzType]=\"i.value\" [nzTheme]=\"i.theme\"\n [nzSpin]=\"i.spin\" [nzTwotoneColor]=\"i.twoToneColor\" [nzIconfont]=\"i.iconfont\"></i>\n <i *ngSwitchCase=\"'iconfont'\" class=\"sidebar-nav__item-icon\" nz-icon [nzIconfont]=\"i.iconfont\"></i>\n <img *ngSwitchCase=\"'img'\" [src]=\"i.value\" class=\"sidebar-nav__item-icon sidebar-nav__item-img\">\n <i *ngSwitchDefault class=\"sidebar-nav__item-icon {{ i.value }}\"></i>\n </ng-container>\n</ng-template>\n<ng-template #item let-i>\n <!-- link -->\n <a *ngIf=\"i._type <= 2\" (click)=\"to(i)\" [attr.data-id]=\"i.__id\" class=\"sidebar-nav__item-link\"\n [ngClass]=\"{'sidebar-nav__item-disabled': i.disabled}\">\n <ng-container *ngIf=\"i._needIcon\">\n <ng-container *ngIf=\"!collapsed\">\n <ng-template [ngTemplateOutlet]=\"icon\" [ngTemplateOutletContext]=\"{$implicit: i.icon}\"></ng-template>\n </ng-container>\n <span *ngIf=\"collapsed\" nz-tooltip nzTooltipPlacement=\"right\" [nzTooltipTitle]=\"i.text\">\n <ng-template [ngTemplateOutlet]=\"icon\" [ngTemplateOutletContext]=\"{$implicit: i.icon}\"></ng-template>\n </span>\n </ng-container>\n <span class=\"sidebar-nav__item-text\" [innerHTML]=\"i._text\"></span>\n </a>\n <!-- has children link -->\n <a *ngIf=\"i._type === 3\" (click)=\"toggleOpen(i)\" (mouseenter)=\"showSubMenu($event, i)\" class=\"sidebar-nav__item-link\">\n <ng-template [ngTemplateOutlet]=\"icon\" [ngTemplateOutletContext]=\"{$implicit: i.icon}\"></ng-template>\n <span class=\"sidebar-nav__item-text\" [innerHTML]=\"i._text\"></span>\n <i class=\"sidebar-nav__sub-arrow\"></i>\n </a>\n <!-- badge -->\n <div *ngIf=\"i.badge\" [attr.title]=\"i.badge\" class=\"badge badge-{{i.badgeStatus}}\" [class.badge-dot]=\"i.badgeDot\">\n <em>{{i.badge}}</em>\n </div>\n</ng-template>\n<ul class=\"sidebar-nav\">\n <ng-container *ngFor=\"let group of list\">\n <ng-container *ngIf=\"group._hidden !== true\">\n <li class=\"sidebar-nav__item sidebar-nav__group-title\" *ngIf=\"group.group\">\n <span [innerHTML]=\"group._text\"></span>\n </li>\n <ng-container *ngFor=\"let child1 of group.children\">\n <li *ngIf=\"child1._hidden !== true\" class=\"sidebar-nav__item\" [class.sidebar-nav__selected]=\"child1._selected\"\n [class.sidebar-nav__open]=\"child1._open\">\n <ng-template [ngTemplateOutlet]=\"item\" [ngTemplateOutletContext]=\"{$implicit: child1}\"></ng-template>\n <!-- Level 2 -->\n <ul *ngIf=\"child1._type === 3\" class=\"sidebar-nav sidebar-nav__sub sidebar-nav__depth{{child1._depth}}\">\n <ng-container *ngFor=\"let child2 of child1.children\">\n <li *ngIf=\"child2._hidden !== true\" class=\"sidebar-nav__item\"\n [class.sidebar-nav__selected]=\"child2._selected\" [class.sidebar-nav__open]=\"child2._open\">\n <ng-template [ngTemplateOutlet]=\"item\" [ngTemplateOutletContext]=\"{$implicit: child2}\"></ng-template>\n <!-- Level 3 -->\n <ul *ngIf=\"child2._type === 3\" class=\"sidebar-nav sidebar-nav__sub sidebar-nav__depth{{child2._depth}}\">\n <ng-container *ngFor=\"let child3 of child2.children\">\n <li *ngIf=\"child3._hidden !== true\" class=\"sidebar-nav__item\"\n [class.sidebar-nav__selected]=\"child3._selected\" [class.sidebar-nav__open]=\"child3._open\">\n <ng-template [ngTemplateOutlet]=\"item\" [ngTemplateOutletContext]=\"{$implicit: child3}\">\n </ng-template>\n </li>\n </ng-container>\n </ul>\n </li>\n </ng-container>\n </ul>\n </li>\n </ng-container>\n </ng-container>\n </ng-container>\n</ul>\n",
host: {
'(click)': '_click()',
'(document:click)': '_docClick()',
},
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
}] }
];
/** @nocollapse */
SidebarNavComponent.ctorParameters = function () { return [
{ type: MenuService },
{ type: SettingsService },
{ type: Router },
{ type: Renderer2 },
{ type: ChangeDetectorRef },
{ type: NgZone },
{ type: DomSanitizer },
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
{ type: Window, decorators: [{ type: Inject, args: [WINDOW,] }] }
]; };
SidebarNavComponent.propDecorators = {
disabledAcl: [{ type: Input }],
autoCloseUnderPad: [{ type: Input }],
recursivePath: [{ type: Input }],
openStrictly: [{ type: Input }],
select: [{ type: Output }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], SidebarNavComponent.prototype, "disabledAcl", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], SidebarNavComponent.prototype, "autoCloseUnderPad", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], SidebarNavComponent.prototype, "recursivePath", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], SidebarNavComponent.prototype, "openStrictly", void 0);
return SidebarNavComponent;
}());
if (false) {
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.bodyEl;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.unsubscribe$;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.floatingEl;
/** @type {?} */
SidebarNavComponent.prototype.list;
/** @type {?} */
SidebarNavComponent.prototype.disabledAcl;
/** @type {?} */
SidebarNavComponent.prototype.autoCloseUnderPad;
/** @type {?} */
SidebarNavComponent.prototype.recursivePath;
/** @type {?} */
SidebarNavComponent.prototype.openStrictly;
/** @type {?} */
SidebarNavComponent.prototype.select;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.menuSrv;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.settings;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.router;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.render;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.cdr;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.ngZone;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.sanitizer;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.doc;
/**
* @type {?}
* @private
*/
SidebarNavComponent.prototype.win;
}
/**
* @fileoverview added by tsickle
* Generated from: sidebar-nav.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var SidebarNavModule = /** @class */ (function () {
function SidebarNavModule() {
}
SidebarNavModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, RouterModule, NzIconModule, NzToolTipModule, LxlibUtilModule],
declarations: [SidebarNavComponent],
exports: [SidebarNavComponent],
},] }
];
return SidebarNavModule;
}());
/**
* @fileoverview added by tsickle
* Generated from: public_api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: sidebarNav.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { SidebarNavComponent, SidebarNavModule };
//# sourceMappingURL=sidebarNav.js.map