@lxlib/seed
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
1,787 lines (1,780 loc) • 70.1 kB
JavaScript
import { __assign, __spread, __decorate, __metadata } from 'tslib';
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ElementRef, Injectable, Directive, Injector, ɵɵdefineInjectable, ɵɵinject, INJECTOR, ChangeDetectorRef, Renderer2, Optional, Inject, NgModule } from '@angular/core';
import { LxlibLocaleService, ScrollService, MenuService, LXLIB_I18N_TOKEN, LxlibLocaleModule } from '@lxlib/theme';
import { Subject, Subscription, BehaviorSubject } from 'rxjs';
import { ConnectionPositionPair, Overlay, OverlayModule } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { DOCUMENT, CommonModule } from '@angular/common';
import { ActivatedRoute, Router, ROUTER_CONFIGURATION, NavigationStart, NavigationEnd, RouterModule } from '@angular/router';
import { InputBoolean, InputNumber } from '@lxlib/util';
import { takeUntil, filter, debounceTime } from 'rxjs/operators';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzMenuModule } from 'ng-zorro-antd/menu';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab-context-menu.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ReuseTabContextMenuComponent = /** @class */ (function () {
function ReuseTabContextMenuComponent(i18nSrv) {
this.i18nSrv = i18nSrv;
// tslint:disable-next-line:no-output-native
this.close = new EventEmitter();
}
Object.defineProperty(ReuseTabContextMenuComponent.prototype, "i18n", {
get: /**
* @return {?}
*/
function () {
return this._i18n;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._i18n = __assign(__assign({}, this.i18nSrv.getData('reuseTab')), value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabContextMenuComponent.prototype, "includeNonCloseable", {
get: /**
* @return {?}
*/
function () {
return this.event.ctrlKey;
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {?} type
* @return {?}
*/
ReuseTabContextMenuComponent.prototype.notify = /**
* @private
* @param {?} type
* @return {?}
*/
function (type) {
this.close.next({
type: type,
item: this.item,
includeNonCloseable: this.includeNonCloseable,
});
};
/**
* @return {?}
*/
ReuseTabContextMenuComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (this.includeNonCloseable)
this.item.closable = true;
};
/**
* @param {?} e
* @param {?} type
* @param {?=} custom
* @return {?}
*/
ReuseTabContextMenuComponent.prototype.click = /**
* @param {?} e
* @param {?} type
* @param {?=} custom
* @return {?}
*/
function (e, type, custom) {
e.preventDefault();
e.stopPropagation();
if (type === 'close' && !this.item.closable)
return;
if (type === 'closeRight' && this.item.last)
return;
if (custom) {
if (this.isDisabled(custom))
return;
custom.fn(this.item, custom);
}
this.notify(type);
};
/**
* @param {?} custom
* @return {?}
*/
ReuseTabContextMenuComponent.prototype.isDisabled = /**
* @param {?} custom
* @return {?}
*/
function (custom) {
return custom.disabled ? custom.disabled(this.item) : false;
};
/**
* @param {?} event
* @return {?}
*/
ReuseTabContextMenuComponent.prototype.closeMenu = /**
* @param {?} event
* @return {?}
*/
function (event) {
if (event.type === 'click' && event.button === 2)
return;
this.notify(null);
};
ReuseTabContextMenuComponent.decorators = [
{ type: Component, args: [{
selector: 'reuse-tab-context-menu',
template: "<ul nz-menu>\n <li nz-menu-item\n (click)=\"click($event, 'close')\"\n data-type=\"close\"\n [nzDisabled]=\"!item.closable\"\n [innerHTML]=\"i18n.close\"></li>\n <li nz-menu-item\n (click)=\"click($event, 'closeOther')\"\n data-type=\"closeOther\"\n [innerHTML]=\"i18n.closeOther\"></li>\n <li nz-menu-item\n (click)=\"click($event, 'closeRight')\"\n data-type=\"closeRight\"\n [nzDisabled]=\"item.last\"\n [innerHTML]=\"i18n.closeRight\"></li>\n <li nz-menu-item\n (click)=\"click($event, 'clear')\"\n data-type=\"clear\"\n [innerHTML]=\"i18n.clear\"></li>\n <ng-container *ngIf=\"customContextMenu!.length > 0\">\n <li nz-menu-divider></li>\n <li *ngFor=\"let i of customContextMenu\"\n nz-menu-item\n [attr.data-type]=\"i.id\"\n [nzDisabled]=\"isDisabled(i)\"\n (click)=\"click($event, 'custom', i)\"\n [innerHTML]=\"i.title\"></li>\n </ng-container>\n</ul>\n",
host: {
'(document:click)': 'closeMenu($event)',
'(document:contextmenu)': 'closeMenu($event)',
},
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
}] }
];
/** @nocollapse */
ReuseTabContextMenuComponent.ctorParameters = function () { return [
{ type: LxlibLocaleService }
]; };
ReuseTabContextMenuComponent.propDecorators = {
i18n: [{ type: Input }],
item: [{ type: Input }],
event: [{ type: Input }],
customContextMenu: [{ type: Input }],
close: [{ type: Output }]
};
return ReuseTabContextMenuComponent;
}());
if (false) {
/**
* @type {?}
* @private
*/
ReuseTabContextMenuComponent.prototype._i18n;
/** @type {?} */
ReuseTabContextMenuComponent.prototype.item;
/** @type {?} */
ReuseTabContextMenuComponent.prototype.event;
/** @type {?} */
ReuseTabContextMenuComponent.prototype.customContextMenu;
/** @type {?} */
ReuseTabContextMenuComponent.prototype.close;
/**
* @type {?}
* @private
*/
ReuseTabContextMenuComponent.prototype.i18nSrv;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab-context.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ReuseTabContextService = /** @class */ (function () {
function ReuseTabContextService(overlay) {
this.overlay = overlay;
this.show = new Subject();
this.close = new Subject();
}
/**
* @return {?}
*/
ReuseTabContextService.prototype.remove = /**
* @return {?}
*/
function () {
if (!this.ref)
return;
this.ref.detach();
this.ref.dispose();
this.ref = null;
};
/**
* @param {?} context
* @return {?}
*/
ReuseTabContextService.prototype.open = /**
* @param {?} context
* @return {?}
*/
function (context) {
var _this = this;
this.remove();
var event = context.event, item = context.item, customContextMenu = context.customContextMenu;
/** @type {?} */
var fakeElement = new ElementRef({
getBoundingClientRect: (/**
* @return {?}
*/
function () { return ({
bottom: event.clientY,
height: 0,
left: event.clientX,
right: event.clientX,
top: event.clientY,
width: 0,
}); }),
});
/** @type {?} */
var positions = [
new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }),
new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' }),
];
/** @type {?} */
var positionStrategy = this.overlay.position().flexibleConnectedTo(fakeElement).withPositions(positions);
this.ref = this.overlay.create({
positionStrategy: positionStrategy,
panelClass: 'reuse-tab__cm',
scrollStrategy: this.overlay.scrollStrategies.close(),
});
/** @type {?} */
var comp = this.ref.attach(new ComponentPortal(ReuseTabContextMenuComponent));
/** @type {?} */
var instance = comp.instance;
instance.i18n = this.i18n;
instance.item = __assign({}, item);
instance.customContextMenu = (/** @type {?} */ (customContextMenu));
instance.event = event;
/** @type {?} */
var sub$ = new Subscription();
sub$.add(instance.close.subscribe((/**
* @param {?} res
* @return {?}
*/
function (res) {
_this.close.next(res);
_this.remove();
})));
comp.onDestroy((/**
* @return {?}
*/
function () { return sub$.unsubscribe(); }));
};
ReuseTabContextService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
ReuseTabContextService.ctorParameters = function () { return [
{ type: Overlay }
]; };
return ReuseTabContextService;
}());
if (false) {
/**
* @type {?}
* @private
*/
ReuseTabContextService.prototype.ref;
/** @type {?} */
ReuseTabContextService.prototype.i18n;
/** @type {?} */
ReuseTabContextService.prototype.show;
/** @type {?} */
ReuseTabContextService.prototype.close;
/**
* @type {?}
* @private
*/
ReuseTabContextService.prototype.overlay;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab-context.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ReuseTabContextComponent = /** @class */ (function () {
function ReuseTabContextComponent(srv) {
var _this = this;
this.srv = srv;
this.sub$ = new Subscription();
// tslint:disable-next-line:no-output-native
this.change = new EventEmitter();
this.sub$.add(srv.show.subscribe((/**
* @param {?} context
* @return {?}
*/
function (context) { return _this.srv.open(context); })));
this.sub$.add(srv.close.subscribe((/**
* @param {?} res
* @return {?}
*/
function (res) { return _this.change.emit(res); })));
}
Object.defineProperty(ReuseTabContextComponent.prototype, "i18n", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this.srv.i18n = value;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
ReuseTabContextComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.sub$.unsubscribe();
};
ReuseTabContextComponent.decorators = [
{ type: Component, args: [{
selector: 'reuse-tab-context',
template: ""
}] }
];
/** @nocollapse */
ReuseTabContextComponent.ctorParameters = function () { return [
{ type: ReuseTabContextService }
]; };
ReuseTabContextComponent.propDecorators = {
i18n: [{ type: Input }],
change: [{ type: Output }]
};
return ReuseTabContextComponent;
}());
if (false) {
/**
* @type {?}
* @private
*/
ReuseTabContextComponent.prototype.sub$;
/** @type {?} */
ReuseTabContextComponent.prototype.change;
/**
* @type {?}
* @private
*/
ReuseTabContextComponent.prototype.srv;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab-context.directive.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ReuseTabContextDirective = /** @class */ (function () {
function ReuseTabContextDirective(srv) {
this.srv = srv;
}
/**
* @param {?} event
* @return {?}
*/
ReuseTabContextDirective.prototype._onContextMenu = /**
* @param {?} event
* @return {?}
*/
function (event) {
this.srv.show.next({
event: event,
item: this.item,
customContextMenu: this.customContextMenu,
});
event.preventDefault();
event.stopPropagation();
};
ReuseTabContextDirective.decorators = [
{ type: Directive, args: [{
selector: '[reuse-tab-context-menu]',
exportAs: 'reuseTabContextMenu',
host: {
'(contextmenu)': '_onContextMenu($event)',
},
},] }
];
/** @nocollapse */
ReuseTabContextDirective.ctorParameters = function () { return [
{ type: ReuseTabContextService }
]; };
ReuseTabContextDirective.propDecorators = {
item: [{ type: Input, args: ['reuse-tab-context-menu',] }],
customContextMenu: [{ type: Input }]
};
return ReuseTabContextDirective;
}());
if (false) {
/** @type {?} */
ReuseTabContextDirective.prototype.item;
/** @type {?} */
ReuseTabContextDirective.prototype.customContextMenu;
/**
* @type {?}
* @private
*/
ReuseTabContextDirective.prototype.srv;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab.interfaces.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var ReuseTabMatchMode = {
/**
* (推荐)按菜单 `Menu` 配置
*
* 可复用:
* - `{ text:'Dashboard' }`
* - `{ text:'Dashboard', reuse: true }`
*
* 不可复用:
* - `{ text:'Dashboard', reuse: false }`
*/
Menu: 0,
/**
* 按菜单 `Menu` 强制配置
*
* 可复用:
* - `{ text:'Dashboard', reuse: true }`
*
* 不可复用:
* - `{ text:'Dashboard' }`
* - `{ text:'Dashboard', reuse: false }`
*/
MenuForce: 1,
/**
* 对所有路由有效,可以配合 `excludes` 过滤无须复用路由
*/
URL: 2,
};
ReuseTabMatchMode[ReuseTabMatchMode.Menu] = 'Menu';
ReuseTabMatchMode[ReuseTabMatchMode.MenuForce] = 'MenuForce';
ReuseTabMatchMode[ReuseTabMatchMode.URL] = 'URL';
/**
* @record
*/
function ReuseTitle() { }
if (false) {
/** @type {?|undefined} */
ReuseTitle.prototype.text;
/** @type {?|undefined} */
ReuseTitle.prototype.i18n;
}
/**
* @record
*/
function ReuseTabCached() { }
if (false) {
/** @type {?} */
ReuseTabCached.prototype.title;
/** @type {?} */
ReuseTabCached.prototype.url;
/**
* 是否允许关闭,默认:`true`
* @type {?|undefined}
*/
ReuseTabCached.prototype.closable;
/**
* 当前滚动条位置
* @type {?|undefined}
*/
ReuseTabCached.prototype.position;
/** @type {?} */
ReuseTabCached.prototype._snapshot;
/** @type {?} */
ReuseTabCached.prototype._handle;
}
/**
* @record
*/
function ReuseTabNotify() { }
if (false) {
/**
* 事件类型
* @type {?}
*/
ReuseTabNotify.prototype.active;
/* Skipping unhandled member: [key: string]: any;*/
}
/**
* @record
*/
function ReuseItem() { }
if (false) {
/** @type {?} */
ReuseItem.prototype.url;
/** @type {?} */
ReuseItem.prototype.title;
/** @type {?} */
ReuseItem.prototype.closable;
/** @type {?} */
ReuseItem.prototype.index;
/** @type {?} */
ReuseItem.prototype.active;
/** @type {?} */
ReuseItem.prototype.last;
}
/**
* @record
*/
function ReuseContextEvent() { }
if (false) {
/** @type {?} */
ReuseContextEvent.prototype.event;
/** @type {?} */
ReuseContextEvent.prototype.item;
/** @type {?|undefined} */
ReuseContextEvent.prototype.comp;
/** @type {?|undefined} */
ReuseContextEvent.prototype.customContextMenu;
}
/**
* @record
*/
function ReuseContextCloseEvent() { }
if (false) {
/** @type {?} */
ReuseContextCloseEvent.prototype.type;
/** @type {?} */
ReuseContextCloseEvent.prototype.item;
/** @type {?} */
ReuseContextCloseEvent.prototype.includeNonCloseable;
}
/**
* @record
*/
function ReuseContextI18n() { }
if (false) {
/** @type {?|undefined} */
ReuseContextI18n.prototype.close;
/** @type {?|undefined} */
ReuseContextI18n.prototype.closeOther;
/** @type {?|undefined} */
ReuseContextI18n.prototype.closeRight;
/** @type {?|undefined} */
ReuseContextI18n.prototype.clear;
}
/**
* @record
*/
function ReuseCustomContextMenu() { }
if (false) {
/** @type {?} */
ReuseCustomContextMenu.prototype.id;
/** @type {?} */
ReuseCustomContextMenu.prototype.title;
/** @type {?} */
ReuseCustomContextMenu.prototype.fn;
/** @type {?|undefined} */
ReuseCustomContextMenu.prototype.disabled;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* 路由复用类,提供复用所需要一些基本接口
*
* **注:** 所有缓存数据来源于路由离开后才会产生
*/
var ReuseTabService = /** @class */ (function () {
// #endregion
function ReuseTabService(injector, menuService) {
this.injector = injector;
this.menuService = menuService;
this._inited = false;
this._max = 10;
this._keepingScroll = false;
this._cachedChange = new BehaviorSubject(null);
this._cached = [];
this._titleCached = {};
this._closableCached = {};
this.positionBuffer = {};
this.debug = false;
this.mode = ReuseTabMatchMode.Menu;
/**
* 排除规则,限 `mode=URL`
*/
this.excludes = [];
}
Object.defineProperty(ReuseTabService.prototype, "snapshot", {
get: /**
* @private
* @return {?}
*/
function () {
return this.injector.get(ActivatedRoute).snapshot;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "inited", {
// #region public
get:
// #region public
/**
* @return {?}
*/
function () {
return this._inited;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "curUrl", {
/** 当前路由地址 */
get: /**
* 当前路由地址
* @return {?}
*/
function () {
return this.getUrl(this.snapshot);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "max", {
/** 允许最多复用多少个页面,取值范围 `2-100`,值发生变更时会强制关闭且忽略可关闭条件 */
set: /**
* 允许最多复用多少个页面,取值范围 `2-100`,值发生变更时会强制关闭且忽略可关闭条件
* @param {?} value
* @return {?}
*/
function (value) {
this._max = Math.min(Math.max(value, 2), 100);
for (var i = this._cached.length; i > this._max; i--) {
this._cached.pop();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "keepingScroll", {
get: /**
* @return {?}
*/
function () {
return this._keepingScroll;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._keepingScroll = value;
this.initScroll();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "items", {
/** 获取已缓存的路由 */
get: /**
* 获取已缓存的路由
* @return {?}
*/
function () {
return this._cached;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "count", {
/** 获取当前缓存的路由总数 */
get: /**
* 获取当前缓存的路由总数
* @return {?}
*/
function () {
return this._cached.length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "change", {
/** 订阅缓存变更通知 */
get: /**
* 订阅缓存变更通知
* @return {?}
*/
function () {
return this._cachedChange.asObservable(); // .pipe(filter(w => w !== null));
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "title", {
/** 自定义当前标题 */
set: /**
* 自定义当前标题
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var url = this.curUrl;
if (typeof value === 'string')
value = { text: value };
this._titleCached[url] = value;
this.di('update current tag title: ', value);
this._cachedChange.next({
active: 'title',
title: value,
list: this._cached,
});
},
enumerable: true,
configurable: true
});
/** 获取指定路径缓存所在位置,`-1` 表示无缓存 */
/**
* 获取指定路径缓存所在位置,`-1` 表示无缓存
* @param {?} url
* @return {?}
*/
ReuseTabService.prototype.index = /**
* 获取指定路径缓存所在位置,`-1` 表示无缓存
* @param {?} url
* @return {?}
*/
function (url) {
return this._cached.findIndex((/**
* @param {?} w
* @return {?}
*/
function (w) { return w.url === url; }));
};
/** 获取指定路径缓存是否存在 */
/**
* 获取指定路径缓存是否存在
* @param {?} url
* @return {?}
*/
ReuseTabService.prototype.exists = /**
* 获取指定路径缓存是否存在
* @param {?} url
* @return {?}
*/
function (url) {
return this.index(url) !== -1;
};
/** 获取指定路径缓存 */
/**
* 获取指定路径缓存
* @param {?=} url
* @return {?}
*/
ReuseTabService.prototype.get = /**
* 获取指定路径缓存
* @param {?=} url
* @return {?}
*/
function (url) {
return url ? this._cached.find((/**
* @param {?} w
* @return {?}
*/
function (w) { return w.url === url; })) || null : null;
};
/**
* @private
* @param {?} url
* @param {?} includeNonCloseable
* @return {?}
*/
ReuseTabService.prototype.remove = /**
* @private
* @param {?} url
* @param {?} includeNonCloseable
* @return {?}
*/
function (url, includeNonCloseable) {
/** @type {?} */
var idx = typeof url === 'string' ? this.index(url) : url;
/** @type {?} */
var item = idx !== -1 ? this._cached[idx] : null;
if (!item || (!includeNonCloseable && !item.closable))
return false;
this.destroy(item._handle);
this._cached.splice(idx, 1);
delete this._titleCached[url];
return true;
};
/**
* 根据URL移除标签
*
* @param [includeNonCloseable=false] 是否强制包含不可关闭
*/
/**
* 根据URL移除标签
*
* @param {?} url
* @param {?=} includeNonCloseable
* @return {?}
*/
ReuseTabService.prototype.close = /**
* 根据URL移除标签
*
* @param {?} url
* @param {?=} includeNonCloseable
* @return {?}
*/
function (url, includeNonCloseable) {
if (includeNonCloseable === void 0) { includeNonCloseable = false; }
this.removeUrlBuffer = url;
this.remove(url, includeNonCloseable);
this._cachedChange.next({ active: 'close', url: url, list: this._cached });
this.di('close tag', url);
return true;
};
/**
* 清除右边
*
* @param [includeNonCloseable=false] 是否强制包含不可关闭
*/
/**
* 清除右边
*
* @param {?} url
* @param {?=} includeNonCloseable
* @return {?}
*/
ReuseTabService.prototype.closeRight = /**
* 清除右边
*
* @param {?} url
* @param {?=} includeNonCloseable
* @return {?}
*/
function (url, includeNonCloseable) {
if (includeNonCloseable === void 0) { includeNonCloseable = false; }
/** @type {?} */
var start = this.index(url);
for (var i = this.count - 1; i > start; i--) {
this.remove(i, includeNonCloseable);
}
this.removeUrlBuffer = null;
this._cachedChange.next({ active: 'closeRight', url: url, list: this._cached });
this.di('close right tages', url);
return true;
};
/**
* 清除所有缓存
*
* @param [includeNonCloseable=false] 是否强制包含不可关闭
*/
/**
* 清除所有缓存
*
* @param {?=} includeNonCloseable
* @return {?}
*/
ReuseTabService.prototype.clear = /**
* 清除所有缓存
*
* @param {?=} includeNonCloseable
* @return {?}
*/
function (includeNonCloseable) {
var _this = this;
if (includeNonCloseable === void 0) { includeNonCloseable = false; }
this._cached.forEach((/**
* @param {?} w
* @return {?}
*/
function (w) {
if (!includeNonCloseable && w.closable)
_this.destroy(w._handle);
}));
this._cached = this._cached.filter((/**
* @param {?} w
* @return {?}
*/
function (w) { return !includeNonCloseable && !w.closable; }));
this.removeUrlBuffer = null;
this._cachedChange.next({ active: 'clear', list: this._cached });
this.di('clear all catch');
};
/**
* 移动缓存数据
* @param url 要移动的URL地址
* @param position 新位置,下标从 `0` 开始
*
* @example
* ```
* // source
* [ '/a/1', '/a/2', '/a/3', '/a/4', '/a/5' ]
* move('/a/1', 2);
* // output
* [ '/a/2', '/a/3', '/a/1', '/a/4', '/a/5' ]
* move('/a/1', -1);
* // output
* [ '/a/2', '/a/3', '/a/4', '/a/5', '/a/1' ]
* ```
*/
/**
* 移动缓存数据
* \@example
* ```
* // source
* [ '/a/1', '/a/2', '/a/3', '/a/4', '/a/5' ]
* move('/a/1', 2);
* // output
* [ '/a/2', '/a/3', '/a/1', '/a/4', '/a/5' ]
* move('/a/1', -1);
* // output
* [ '/a/2', '/a/3', '/a/4', '/a/5', '/a/1' ]
* ```
* @param {?} url 要移动的URL地址
* @param {?} position 新位置,下标从 `0` 开始
*
* @return {?}
*/
ReuseTabService.prototype.move = /**
* 移动缓存数据
* \@example
* ```
* // source
* [ '/a/1', '/a/2', '/a/3', '/a/4', '/a/5' ]
* move('/a/1', 2);
* // output
* [ '/a/2', '/a/3', '/a/1', '/a/4', '/a/5' ]
* move('/a/1', -1);
* // output
* [ '/a/2', '/a/3', '/a/4', '/a/5', '/a/1' ]
* ```
* @param {?} url 要移动的URL地址
* @param {?} position 新位置,下标从 `0` 开始
*
* @return {?}
*/
function (url, position) {
/** @type {?} */
var start = this._cached.findIndex((/**
* @param {?} w
* @return {?}
*/
function (w) { return w.url === url; }));
if (start === -1)
return;
/** @type {?} */
var data = this._cached.slice();
data.splice(position < 0 ? data.length + position : position, 0, data.splice(start, 1)[0]);
this._cached = data;
this._cachedChange.next({
active: 'move',
url: url,
position: position,
list: this._cached,
});
};
/**
* 强制关闭当前路由(包含不可关闭状态),并重新导航至 `newUrl` 路由
*/
/**
* 强制关闭当前路由(包含不可关闭状态),并重新导航至 `newUrl` 路由
* @param {?} newUrl
* @return {?}
*/
ReuseTabService.prototype.replace = /**
* 强制关闭当前路由(包含不可关闭状态),并重新导航至 `newUrl` 路由
* @param {?} newUrl
* @return {?}
*/
function (newUrl) {
/** @type {?} */
var url = this.curUrl;
if (this.exists(url)) {
this.close(url, true);
}
else {
this.removeUrlBuffer = url;
}
this.injector.get(Router).navigateByUrl(newUrl);
};
/**
* 获取标题,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.title = 'new title'` 重新指定文本
* 2. 路由配置中 data 属性中包含 titleI18n > title
* 3. 菜单数据中 text 属性
*
* @param url 指定URL
* @param route 指定路由快照
*/
/**
* 获取标题,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.title = 'new title'` 重新指定文本
* 2. 路由配置中 data 属性中包含 titleI18n > title
* 3. 菜单数据中 text 属性
*
* @param {?} url 指定URL
* @param {?=} route 指定路由快照
* @return {?}
*/
ReuseTabService.prototype.getTitle = /**
* 获取标题,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.title = 'new title'` 重新指定文本
* 2. 路由配置中 data 属性中包含 titleI18n > title
* 3. 菜单数据中 text 属性
*
* @param {?} url 指定URL
* @param {?=} route 指定路由快照
* @return {?}
*/
function (url, route) {
if (this._titleCached[url]) {
return this._titleCached[url];
}
if (route && route.data && (route.data.titleI18n || route.data.title)) {
return (/** @type {?} */ ({
text: route.data.title,
i18n: route.data.titleI18n,
}));
}
/** @type {?} */
var menu = this.getMenu(url);
return menu ? { text: menu.text, i18n: menu.i18n } : { text: url };
};
/**
* 清除标题缓存
*/
/**
* 清除标题缓存
* @return {?}
*/
ReuseTabService.prototype.clearTitleCached = /**
* 清除标题缓存
* @return {?}
*/
function () {
this._titleCached = {};
};
Object.defineProperty(ReuseTabService.prototype, "closable", {
/** 自定义当前 `closable` 状态 */
set: /**
* 自定义当前 `closable` 状态
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var url = this.curUrl;
this._closableCached[url] = value;
this.di('update current tag closable: ', value);
this._cachedChange.next({
active: 'closable',
closable: value,
list: this._cached,
});
},
enumerable: true,
configurable: true
});
/**
* 获取 `closable` 状态,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.closable = true` 重新指定 `closable` 状态
* 2. 路由配置中 data 属性中包含 `reuseClosable`
* 3. 菜单数据中 `reuseClosable` 属性
*
* @param url 指定URL
* @param route 指定路由快照
*/
/**
* 获取 `closable` 状态,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.closable = true` 重新指定 `closable` 状态
* 2. 路由配置中 data 属性中包含 `reuseClosable`
* 3. 菜单数据中 `reuseClosable` 属性
*
* @param {?} url 指定URL
* @param {?=} route 指定路由快照
* @return {?}
*/
ReuseTabService.prototype.getClosable = /**
* 获取 `closable` 状态,顺序如下:
*
* 1. 组件内使用 `ReuseTabService.closable = true` 重新指定 `closable` 状态
* 2. 路由配置中 data 属性中包含 `reuseClosable`
* 3. 菜单数据中 `reuseClosable` 属性
*
* @param {?} url 指定URL
* @param {?=} route 指定路由快照
* @return {?}
*/
function (url, route) {
if (typeof this._closableCached[url] !== 'undefined')
return this._closableCached[url];
if (route && route.data && typeof route.data.reuseClosable === 'boolean')
return route.data.reuseClosable;
/** @type {?} */
var menu = this.mode !== ReuseTabMatchMode.URL ? this.getMenu(url) : null;
if (menu && typeof menu.reuseClosable === 'boolean')
return menu.reuseClosable;
return true;
};
/**
* 清空 `closable` 缓存
*/
/**
* 清空 `closable` 缓存
* @return {?}
*/
ReuseTabService.prototype.clearClosableCached = /**
* 清空 `closable` 缓存
* @return {?}
*/
function () {
this._closableCached = {};
};
/**
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.getTruthRoute = /**
* @param {?} route
* @return {?}
*/
function (route) {
/** @type {?} */
var next = route;
while (next.firstChild)
next = next.firstChild;
return next;
};
/**
* 根据快照获取URL地址
*/
/**
* 根据快照获取URL地址
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.getUrl = /**
* 根据快照获取URL地址
* @param {?} route
* @return {?}
*/
function (route) {
/** @type {?} */
var next = this.getTruthRoute(route);
/** @type {?} */
var segments = [];
while (next) {
segments.push(next.url.join('/'));
next = (/** @type {?} */ (next.parent));
}
/** @type {?} */
var url = '/' +
segments
.filter((/**
* @param {?} i
* @return {?}
*/
function (i) { return i; }))
.reverse()
.join('/');
return url;
};
/**
* 检查快照是否允许被复用
*/
/**
* 检查快照是否允许被复用
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.can = /**
* 检查快照是否允许被复用
* @param {?} route
* @return {?}
*/
function (route) {
/** @type {?} */
var url = this.getUrl(route);
if (url === this.removeUrlBuffer)
return false;
if (route.data && typeof route.data.reuse === 'boolean')
return route.data.reuse;
if (this.mode !== ReuseTabMatchMode.URL) {
/** @type {?} */
var menu = this.getMenu(url);
if (!menu)
return false;
if (this.mode === ReuseTabMatchMode.Menu) {
if (menu.reuse === false)
return false;
}
else {
if (!menu.reuse || menu.reuse !== true)
return false;
}
return true;
}
return this.excludes.findIndex((/**
* @param {?} r
* @return {?}
*/
function (r) { return r.test(url); })) === -1;
};
/**
* 刷新,触发一个 refresh 类型事件
*/
/**
* 刷新,触发一个 refresh 类型事件
* @param {?=} data
* @return {?}
*/
ReuseTabService.prototype.refresh = /**
* 刷新,触发一个 refresh 类型事件
* @param {?=} data
* @return {?}
*/
function (data) {
this._cachedChange.next({ active: 'refresh', data: data });
};
// #endregion
// #region privates
// #endregion
// #region privates
/**
* @private
* @param {?} _handle
* @return {?}
*/
ReuseTabService.prototype.destroy =
// #endregion
// #region privates
/**
* @private
* @param {?} _handle
* @return {?}
*/
function (_handle) {
if (_handle && _handle.componentRef && _handle.componentRef.destroy)
_handle.componentRef.destroy();
};
/**
* @private
* @param {...?} args
* @return {?}
*/
ReuseTabService.prototype.di = /**
* @private
* @param {...?} args
* @return {?}
*/
function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (!this.debug)
return;
// tslint:disable-next-line:no-console
console.warn.apply(console, __spread(args));
};
/**
* @return {?}
*/
ReuseTabService.prototype.init = /**
* @return {?}
*/
function () {
this.initScroll();
this._inited = true;
};
/**
* @private
* @param {?} url
* @return {?}
*/
ReuseTabService.prototype.getMenu = /**
* @private
* @param {?} url
* @return {?}
*/
function (url) {
/** @type {?} */
var menus = this.menuService.getPathByUrl(url);
if (!menus || menus.length === 0)
return null;
return menus.pop();
};
/**
* @private
* @param {?} method
* @param {?} _url
* @param {?} comp
* @return {?}
*/
ReuseTabService.prototype.runHook = /**
* @private
* @param {?} method
* @param {?} _url
* @param {?} comp
* @return {?}
*/
function (method, _url, comp) {
if (comp.instance && typeof comp.instance[method] === 'function')
comp.instance[method]();
};
/**
* @private
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.hasInValidRoute = /**
* @private
* @param {?} route
* @return {?}
*/
function (route) {
return !route.routeConfig || route.routeConfig.loadChildren || route.routeConfig.children;
};
/**
* 决定是否允许路由复用,若 `true` 会触发 `store`
*/
/**
* 决定是否允许路由复用,若 `true` 会触发 `store`
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.shouldDetach = /**
* 决定是否允许路由复用,若 `true` 会触发 `store`
* @param {?} route
* @return {?}
*/
function (route) {
if (this.hasInValidRoute(route))
return false;
this.di('#shouldDetach', this.can(route), this.getUrl(route));
return this.can(route);
};
/**
* 存储
*/
/**
* 存储
* @param {?} _snapshot
* @param {?} _handle
* @return {?}
*/
ReuseTabService.prototype.store = /**
* 存储
* @param {?} _snapshot
* @param {?} _handle
* @return {?}
*/
function (_snapshot, _handle) {
/** @type {?} */
var url = this.getUrl(_snapshot);
/** @type {?} */
var idx = this.index(url);
/** @type {?} */
var item = {
title: this.getTitle(url, _snapshot),
closable: this.getClosable(url, _snapshot),
position: this.getKeepingScroll(url, _snapshot) ? this.positionBuffer[url] : null,
url: url,
_snapshot: _snapshot,
_handle: _handle,
};
if (idx === -1) {
if (this.count >= this._max) {
// Get the oldest closable location
/** @type {?} */
var closeIdx = this._cached.findIndex((/**
* @param {?} w
* @return {?}
*/
function (w) { return (/** @type {?} */ (w.closable)); }));
if (closeIdx !== -1)
this.remove(closeIdx, false);
}
this._cached.push(item);
}
else {
this._cached[idx] = item;
}
this.removeUrlBuffer = null;
this.di('#store', idx === -1 ? '[new]' : '[override]', url);
if (_handle && _handle.componentRef) {
this.runHook('_onReuseDestroy', url, _handle.componentRef);
}
this._cachedChange.next({ active: 'add', item: item, list: this._cached });
};
/**
* 决定是否允许应用缓存数据
*/
/**
* 决定是否允许应用缓存数据
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.shouldAttach = /**
* 决定是否允许应用缓存数据
* @param {?} route
* @return {?}
*/
function (route) {
if (this.hasInValidRoute(route))
return false;
/** @type {?} */
var url = this.getUrl(route);
/** @type {?} */
var data = this.get(url);
/** @type {?} */
var ret = !!(data && data._handle);
this.di('#shouldAttach', ret, url);
if (ret && (/** @type {?} */ (data))._handle.componentRef) {
this.runHook('_onReuseInit', url, (/** @type {?} */ (data))._handle.componentRef);
}
return ret;
};
/**
* 提取复用数据
*/
/**
* 提取复用数据
* @param {?} route
* @return {?}
*/
ReuseTabService.prototype.retrieve = /**
* 提取复用数据
* @param {?} route
* @return {?}
*/
function (route) {
if (this.hasInValidRoute(route))
return null;
/** @type {?} */
var url = this.getUrl(route);
/** @type {?} */
var data = this.get(url);
/** @type {?} */
var ret = (data && data._handle) || null;
this.di('#retrieve', url, ret);
return ret;
};
/**
* 决定是否应该进行复用路由处理
*/
/**
* 决定是否应该进行复用路由处理
* @param {?} future
* @param {?} curr
* @return {?}
*/
ReuseTabService.prototype.shouldReuseRoute = /**
* 决定是否应该进行复用路由处理
* @param {?} future
* @param {?} curr
* @return {?}
*/
function (future, curr) {
/** @type {?} */
var ret = future.routeConfig === curr.routeConfig;
if (!ret)
return false;
/** @type {?} */
var path = (/** @type {?} */ (((future.routeConfig && future.routeConfig.path) || '')));
if (path.length > 0 && ~path.indexOf(':')) {
/** @type {?} */
var futureUrl = this.getUrl(future);
/** @type {?} */
var currUrl = this.getUrl(curr);
ret = futureUrl === currUrl;
}
this.di('=====================');
this.di('#shouldReuseRoute', ret, this.getUrl(curr) + "=>" + this.getUrl(future), future, curr);
return ret;
};
// #region scroll
/**
* 获取 `keepingScroll` 状态,顺序如下:
*
* 1. 路由配置中 data 属性中包含 `keepingScroll`
* 2. 菜单数据中 `keepingScroll` 属性
* 3. 组件 `keepingScroll` 值
*/
// #region scroll
/**
* 获取 `keepingScroll` 状态,顺序如下:
*
* 1. 路由配置中 data 属性中包含 `keepingScroll`
* 2. 菜单数据中 `keepingScroll` 属性
* 3. 组件 `keepingScroll` 值
* @param {?} url
* @param {?=} route
* @return {?}
*/
ReuseTabService.prototype.getKeepingScroll =
// #region scroll
/**
* 获取 `keepingScroll` 状态,顺序如下:
*
* 1. 路由配置中 data 属性中包含 `keepingScroll`
* 2. 菜单数据中 `keepingScroll` 属性
* 3. 组件 `keepingScroll` 值
* @param {?} url
* @param {?=} route
* @return {?}
*/
function (url, route) {
if (route && route.data && typeof route.data.keepingScroll === 'boolean')
return route.data.keepingScroll;
/** @type {?} */
var menu = this.mode !== ReuseTabMatchMode.URL ? this.getMenu(url) : null;
if (menu && typeof menu.keepingScroll === 'boolean')
return menu.keepingScroll;
return this.keepingScroll;
};
Object.defineProperty(ReuseTabService.prototype, "isDisabledInRouter", {
get: /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var routerConfig = this.injector.get(ROUTER_CONFIGURATION, (/** @type {?} */ ({})));
return routerConfig.scrollPositionRestoration === 'disabled';
},
enumerable: true,
configurable: true
});
Object.defineProperty(ReuseTabService.prototype, "ss", {
get: /**
* @private
* @return {?}
*/
function () {
return this.injector.get(ScrollService);
},
enumerable: true,
configurable: true
});
/**
* @private
* @return {?}
*/
ReuseTabService.prototype.initScroll = /**
* @private
* @return {?}
*/
function () {
var _this = this;
if (this._router$) {
this._router$.unsubscribe();
}
this._router$ = this.injector.get(Router).events.subscribe((/**
* @param {?} e
* @return {?}
*/
function (e) {
if (e instanceof NavigationStart) {
/** @type {?} */
var url = _this.curUrl;
if (_this.getKeepingScroll(url, _this.getTruthRoute(_this.snapshot))) {
_this.positionBuffer[url] = _this.ss.getScrollPosition(_this.keepingScrollContainer);
}
else {
delete _this.positionBuffer[url];
}
}
else if (e instanceof NavigationEnd) {
/** @type {?} */
var url = _this.curUrl;
/** @type {?} */
var item_1 = _this.get(url);
if (item_1 && item_1.position && _this.getKeepingScroll(url, _this.getTruthRoute(_this.snapshot))) {
if (_this.isDisabledInRouter) {
_this.ss.scrollToPosition(_this.keepingScrollContainer, item_1.position);
}
else {
setTimeout((/**
* @return {?}
*/
function () { return _this.ss.scrollToPosition(_this.keepingScrollContainer, (/** @type {?} */ (item_1.position))); }), 1);
}
}
}
}));
};
// #endregion
// #endregion
/**
* @return {?}
*/
ReuseTabService.prototype.ngOnDestroy =
// #endregion
/**
* @return {?}
*/
function () {
var _a = this, _cachedChange = _a._cachedChange, _router$ = _a._router$;
this.clear();
this._cached = [];
_cachedChange.complete();
if (_router$) {
_router$.unsubscribe();
}
};
ReuseTabService.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] }
];
/** @nocollapse */
ReuseTabService.ctorParameters = function () { return [
{ type: Injector },
{ type: MenuService }
]; };
/** @nocollapse */ ReuseTabService.ɵprov = ɵɵdefineInjectable({ factory: function ReuseTabService_Factory() { return new ReuseTabService(ɵɵinject(INJECTOR), ɵɵinject(MenuService)); }, token: ReuseTabService, providedIn: "root" });
return ReuseTabService;
}());
if (false) {
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._inited;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._max;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._keepingScroll;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._cachedChange;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._cached;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._titleCached;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._closableCached;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype._router$;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype.removeUrlBuffer;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype.positionBuffer;
/** @type {?} */
ReuseTabService.prototype.debug;
/** @type {?} */
ReuseTabService.prototype.mode;
/**
* 排除规则,限 `mode=URL`
* @type {?}
*/
ReuseTabService.prototype.excludes;
/** @type {?} */
ReuseTabService.prototype.keepingScrollContainer;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype.injector;
/**
* @type {?}
* @private
*/
ReuseTabService.prototype.menuService;
}
/**
* @fileoverview added by tsickle
* Generated from: reuse-tab.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ReuseTabComponent = /** @class */ (function () {
// #endregion
function ReuseTabComponent(el, srv, cdr, router, route, render, i18nSrv, doc) {
this.srv = srv;
this.cdr = cdr;
this.router = router;
this.route = route;
this.render = render;
this.i18nSrv = i18nSrv;
this.doc = doc;
this.unsubscribe$ = new Subject();
this.list = [];
this.pos = 0;
// #region fields
this.mode = ReuseTabMatchMode.Menu;
this.debug = false;
this.allowClose = true;
this.showCurrent = true;
this.keepingScroll = false;
this.customContextMenu = [];
this.tabType = 'line';
// tslint:disable-next-line:no-output-native
this.change = new EventEmitter();
// tslint:disable-next-line:no-output-native
this.close = new EventEmitter();
this.el = el.nativeElement;
}
Object.defineProperty(ReuseTabComponent.prototype, "keepingScrollContainer", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._keepingScrollContainer = typeof value === 'string' ? this.doc.querySelector(value) : value;
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {?} title
* @return {?}
*/
ReuseTabComponent.prototype.genTit = /**
* @private
* @param {?} title
* @return {?}
*/
function (title) {
return title.i18n && this.i18nSrv ? this.i18nSrv.fanyi(title.i18n) : (/** @type {?} */ (title.text));
};
/**
* @private
* @param {?=} notify
* @return {?}
*/
ReuseTabComponent.prototype.genList = /**
* @private
* @param {?=} notify
* @return {?}
*/
function (notify) {
var _this = this;
/** @type {?} */
var isClosed =