UNPKG

ng-zorro-antd

Version:

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

1,076 lines (1,066 loc) 88.1 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser/animations'), require('ng-zorro-antd/core/polyfill'), require('@angular/cdk/a11y'), require('@angular/cdk/bidi'), require('@angular/cdk/coercion'), require('@angular/cdk/keycodes'), require('@angular/cdk/overlay'), require('rxjs'), require('rxjs/operators'), require('ng-zorro-antd/core/resize-observers'), require('ng-zorro-antd/core/util'), require('@angular/router'), require('ng-zorro-antd/core/logger'), require('@angular/cdk/observers'), require('@angular/cdk/platform'), require('@angular/cdk/scrolling'), require('@angular/common'), require('ng-zorro-antd/core/outlet'), require('ng-zorro-antd/dropdown'), require('ng-zorro-antd/icon'), require('ng-zorro-antd/core/config')) : typeof define === 'function' && define.amd ? define('ng-zorro-antd/tabs', ['exports', '@angular/core', '@angular/platform-browser/animations', 'ng-zorro-antd/core/polyfill', '@angular/cdk/a11y', '@angular/cdk/bidi', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/cdk/overlay', 'rxjs', 'rxjs/operators', 'ng-zorro-antd/core/resize-observers', 'ng-zorro-antd/core/util', '@angular/router', 'ng-zorro-antd/core/logger', '@angular/cdk/observers', '@angular/cdk/platform', '@angular/cdk/scrolling', '@angular/common', 'ng-zorro-antd/core/outlet', 'ng-zorro-antd/dropdown', 'ng-zorro-antd/icon', 'ng-zorro-antd/core/config'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd'].tabs = {}), global.ng.core, global.ng.platformBrowser.animations, global['ng-zorro-antd'].core.polyfill, global.ng.cdk.a11y, global.ng.cdk.bidi, global.ng.cdk.coercion, global.ng.cdk.keycodes, global.ng.cdk.overlay, global.rxjs, global.rxjs.operators, global['ng-zorro-antd'].core['resize-observers'], global['ng-zorro-antd'].core.util, global.ng.router, global['ng-zorro-antd'].core.logger, global.ng.cdk.observers, global.ng.cdk.platform, global.ng.cdk.scrolling, global.ng.common, global['ng-zorro-antd'].core.outlet, global['ng-zorro-antd'].dropdown, global['ng-zorro-antd'].icon, global['ng-zorro-antd'].core.config)); }(this, (function (exports, core, animations, polyfill, a11y, bidi, coercion, keycodes, overlay, rxjs, operators, resizeObservers, util, router, logger, observers, platform, scrolling, common, outlet, dropdown, icon, config) { 'use strict'; /** * 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 NzTabAddButtonComponent = /** @class */ (function () { function NzTabAddButtonComponent(elementRef) { this.elementRef = elementRef; this.addIcon = 'plus'; this.element = this.elementRef.nativeElement; } NzTabAddButtonComponent.prototype.getElementWidth = function () { var _a; return ((_a = this.element) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0; }; NzTabAddButtonComponent.prototype.getElementHeight = function () { var _a; return ((_a = this.element) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0; }; return NzTabAddButtonComponent; }()); NzTabAddButtonComponent.decorators = [ { type: core.Component, args: [{ selector: 'nz-tab-add-button, button[nz-tab-add-button]', template: "\n <ng-container *nzStringTemplateOutlet=\"addIcon; let icon\">\n <i nz-icon [nzType]=\"icon\" nzTheme=\"outline\"></i>\n </ng-container>\n ", host: { class: 'ant-tabs-nav-add', 'aria-label': 'Add tab', type: 'button' } },] } ]; NzTabAddButtonComponent.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; NzTabAddButtonComponent.propDecorators = { addIcon: [{ type: core.Input }] }; /** * 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 NzTabsInkBarDirective = /** @class */ (function () { function NzTabsInkBarDirective(elementRef, ngZone, animationMode) { this.elementRef = elementRef; this.ngZone = ngZone; this.animationMode = animationMode; this.position = 'horizontal'; this.animated = true; } Object.defineProperty(NzTabsInkBarDirective.prototype, "_animated", { get: function () { return this.animationMode !== 'NoopAnimations' && this.animated; }, enumerable: false, configurable: true }); NzTabsInkBarDirective.prototype.alignToElement = function (element) { var _this = this; this.ngZone.runOutsideAngular(function () { polyfill.reqAnimFrame(function () { return _this.setStyles(element); }); }); }; NzTabsInkBarDirective.prototype.setStyles = function (element) { var inkBar = this.elementRef.nativeElement; if (this.position === 'horizontal') { inkBar.style.top = ''; inkBar.style.height = ''; inkBar.style.left = this.getLeftPosition(element); inkBar.style.width = this.getElementWidth(element); } else { inkBar.style.left = ''; inkBar.style.width = ''; inkBar.style.top = this.getTopPosition(element); inkBar.style.height = this.getElementHeight(element); } }; NzTabsInkBarDirective.prototype.getLeftPosition = function (element) { return element ? (element.offsetLeft || 0) + 'px' : '0'; }; NzTabsInkBarDirective.prototype.getElementWidth = function (element) { return element ? (element.offsetWidth || 0) + 'px' : '0'; }; NzTabsInkBarDirective.prototype.getTopPosition = function (element) { return element ? (element.offsetTop || 0) + 'px' : '0'; }; NzTabsInkBarDirective.prototype.getElementHeight = function (element) { return element ? (element.offsetHeight || 0) + 'px' : '0'; }; return NzTabsInkBarDirective; }()); NzTabsInkBarDirective.decorators = [ { type: core.Directive, args: [{ selector: 'nz-tabs-ink-bar, [nz-tabs-ink-bar]', host: { class: 'ant-tabs-ink-bar', '[class.ant-tabs-ink-bar-animated]': '_animated' } },] } ]; NzTabsInkBarDirective.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.NgZone }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] } ]; }; NzTabsInkBarDirective.propDecorators = { position: [{ type: core.Input }], animated: [{ type: core.Input }] }; /*! ***************************************************************************** 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) { 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; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } 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 __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 NzTabNavItemDirective = /** @class */ (function () { function NzTabNavItemDirective(elementRef) { this.elementRef = elementRef; this.disabled = false; this.active = false; this.el = elementRef.nativeElement; this.parentElement = this.el.parentElement; } NzTabNavItemDirective.prototype.focus = function () { this.el.focus(); }; Object.defineProperty(NzTabNavItemDirective.prototype, "width", { get: function () { return this.parentElement.offsetWidth; }, enumerable: false, configurable: true }); Object.defineProperty(NzTabNavItemDirective.prototype, "height", { get: function () { return this.parentElement.offsetHeight; }, enumerable: false, configurable: true }); Object.defineProperty(NzTabNavItemDirective.prototype, "left", { get: function () { return this.parentElement.offsetLeft; }, enumerable: false, configurable: true }); Object.defineProperty(NzTabNavItemDirective.prototype, "top", { get: function () { return this.parentElement.offsetTop; }, enumerable: false, configurable: true }); return NzTabNavItemDirective; }()); NzTabNavItemDirective.decorators = [ { type: core.Directive, args: [{ selector: '[nzTabNavItem]' },] } ]; NzTabNavItemDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; NzTabNavItemDirective.propDecorators = { disabled: [{ type: core.Input }], tab: [{ type: core.Input }], active: [{ type: core.Input }] }; /** * 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 NzTabNavOperationComponent = /** @class */ (function () { function NzTabNavOperationComponent(cdr, elementRef) { this.cdr = cdr; this.elementRef = elementRef; this.items = []; this.addable = false; this.addIcon = 'plus'; this.addClicked = new core.EventEmitter(); this.selected = new core.EventEmitter(); this.closeAnimationWaitTimeoutId = -1; this.menuOpened = false; this.element = this.elementRef.nativeElement; } NzTabNavOperationComponent.prototype.onSelect = function (item) { if (!item.disabled) { // ignore nzCanDeactivate item.tab.nzClick.emit(); this.selected.emit(item); } }; NzTabNavOperationComponent.prototype.onContextmenu = function (item, e) { if (!item.disabled) { item.tab.nzContextmenu.emit(e); } }; NzTabNavOperationComponent.prototype.showItems = function () { clearTimeout(this.closeAnimationWaitTimeoutId); this.menuOpened = true; this.cdr.markForCheck(); }; NzTabNavOperationComponent.prototype.menuVisChange = function (visible) { var _this = this; if (!visible) { this.closeAnimationWaitTimeoutId = setTimeout(function () { _this.menuOpened = false; _this.cdr.markForCheck(); }, 150); } }; NzTabNavOperationComponent.prototype.getElementWidth = function () { var _a; return ((_a = this.element) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0; }; NzTabNavOperationComponent.prototype.getElementHeight = function () { var _a; return ((_a = this.element) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0; }; NzTabNavOperationComponent.prototype.ngOnDestroy = function () { clearTimeout(this.closeAnimationWaitTimeoutId); }; return NzTabNavOperationComponent; }()); NzTabNavOperationComponent.decorators = [ { type: core.Component, args: [{ selector: 'nz-tab-nav-operation', exportAs: 'nzTabNavOperation', preserveWhitespaces: false, changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, template: "\n <button\n nz-dropdown\n class=\"ant-tabs-nav-more\"\n type=\"button\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n nzOverlayClassName=\"nz-tabs-dropdown\"\n #dropdownTrigger=\"nzDropdown\"\n [nzDropdownMenu]=\"menu\"\n [nzOverlayStyle]=\"{ minWidth: '46px' }\"\n [nzMatchWidthElement]=\"null\"\n (nzVisibleChange)=\"menuVisChange($event)\"\n (mouseenter)=\"showItems()\"\n >\n <i nz-icon nzType=\"ellipsis\"></i>\n </button>\n <nz-dropdown-menu #menu=\"nzDropdownMenu\">\n <ul nz-menu *ngIf=\"menuOpened\">\n <li\n nz-menu-item\n *ngFor=\"let item of items\"\n class=\"ant-tabs-dropdown-menu-item\"\n [class.ant-tabs-dropdown-menu-item-disabled]=\"item.disabled\"\n [nzSelected]=\"item.active\"\n [nzDisabled]=\"item.disabled\"\n (click)=\"onSelect(item)\"\n (contextmenu)=\"onContextmenu(item, $event)\"\n >\n <ng-container *nzStringTemplateOutlet=\"item.tab.label; context: { visible: false }\">{{ item.tab.label }}</ng-container>\n </li>\n </ul>\n </nz-dropdown-menu>\n <button *ngIf=\"addable\" nz-tab-add-button [addIcon]=\"addIcon\" (click)=\"addClicked.emit()\"></button>\n ", host: { class: 'ant-tabs-nav-operations', '[class.ant-tabs-nav-operations-hidden]': 'items.length === 0' } },] } ]; NzTabNavOperationComponent.ctorParameters = function () { return [ { type: core.ChangeDetectorRef }, { type: core.ElementRef } ]; }; NzTabNavOperationComponent.propDecorators = { items: [{ type: core.Input }], addable: [{ type: core.Input }], addIcon: [{ type: core.Input }], addClicked: [{ type: core.Output }], selected: [{ type: core.Output }] }; var RESIZE_SCHEDULER = typeof requestAnimationFrame !== 'undefined' ? rxjs.animationFrameScheduler : rxjs.asapScheduler; var CSS_TRANSFORM_TIME = 150; var NzTabNavBarComponent = /** @class */ (function () { function NzTabNavBarComponent(cdr, ngZone, viewportRuler, nzResizeObserver, dir) { this.cdr = cdr; this.ngZone = ngZone; this.viewportRuler = viewportRuler; this.nzResizeObserver = nzResizeObserver; this.dir = dir; this.indexFocused = new core.EventEmitter(); this.selectFocusedIndex = new core.EventEmitter(); this.addClicked = new core.EventEmitter(); this.tabScroll = new core.EventEmitter(); this.position = 'horizontal'; this.addable = false; this.hideBar = false; this.addIcon = 'plus'; this.inkBarAnimated = true; this.translate = null; this.transformX = 0; this.transformY = 0; this.pingLeft = false; this.pingRight = false; this.pingTop = false; this.pingBottom = false; this.hiddenItems = []; this.destroy$ = new rxjs.Subject(); this._selectedIndex = 0; this.wrapperWidth = 0; this.wrapperHeight = 0; this.scrollListWidth = 0; this.scrollListHeight = 0; this.operationWidth = 0; this.operationHeight = 0; this.addButtonWidth = 0; this.addButtonHeight = 0; this.selectedIndexChanged = false; this.lockAnimationTimeoutId = -1; this.cssTransformTimeWaitingId = -1; } Object.defineProperty(NzTabNavBarComponent.prototype, "selectedIndex", { get: function () { return this._selectedIndex; }, set: function (value) { var newValue = coercion.coerceNumberProperty(value); if (this._selectedIndex !== newValue) { this._selectedIndex = value; this.selectedIndexChanged = true; if (this.keyManager) { this.keyManager.updateActiveItem(value); } } }, enumerable: false, configurable: true }); Object.defineProperty(NzTabNavBarComponent.prototype, "focusIndex", { /** Tracks which element has focus; used for keyboard navigation */ get: function () { return this.keyManager ? this.keyManager.activeItemIndex : 0; }, /** When the focus index is set, we must manually send focus to the correct label */ set: function (value) { if (!this.isValidIndex(value) || this.focusIndex === value || !this.keyManager) { return; } this.keyManager.setActiveItem(value); }, enumerable: false, configurable: true }); Object.defineProperty(NzTabNavBarComponent.prototype, "showAddButton", { get: function () { return this.hiddenItems.length === 0 && this.addable; }, enumerable: false, configurable: true }); NzTabNavBarComponent.prototype.ngOnInit = function () { }; NzTabNavBarComponent.prototype.ngAfterViewInit = function () { var _this = this; var dirChange = this.dir ? this.dir.change : rxjs.of(null); var resize = this.viewportRuler.change(150); var realign = function () { _this.updateScrollListPosition(); _this.alignInkBarToSelectedTab(); }; this.keyManager = new a11y.FocusKeyManager(this.items) .withHorizontalOrientation(this.getLayoutDirection()) .withWrap(); this.keyManager.updateActiveItem(0); polyfill.reqAnimFrame(realign); rxjs.merge(this.nzResizeObserver.observe(this.navWarpRef), this.nzResizeObserver.observe(this.navListRef)) .pipe(operators.takeUntil(this.destroy$), operators.auditTime(16, RESIZE_SCHEDULER)) .subscribe(function () { realign(); }); rxjs.merge(dirChange, resize, this.items.changes) .pipe(operators.takeUntil(this.destroy$)) .subscribe(function () { Promise.resolve().then(realign); _this.keyManager.withHorizontalOrientation(_this.getLayoutDirection()); }); this.keyManager.change.pipe(operators.takeUntil(this.destroy$)).subscribe(function (newFocusIndex) { _this.indexFocused.emit(newFocusIndex); _this.setTabFocus(newFocusIndex); _this.scrollToTab(_this.keyManager.activeItem); }); }; NzTabNavBarComponent.prototype.ngAfterContentChecked = function () { if (this.selectedIndexChanged) { this.updateScrollListPosition(); this.alignInkBarToSelectedTab(); this.selectedIndexChanged = false; this.cdr.markForCheck(); } }; NzTabNavBarComponent.prototype.ngOnDestroy = function () { clearTimeout(this.lockAnimationTimeoutId); clearTimeout(this.cssTransformTimeWaitingId); this.destroy$.next(); this.destroy$.complete(); }; NzTabNavBarComponent.prototype.onSelectedFromMenu = function (tab) { var tabIndex = this.items.toArray().findIndex(function (e) { return e === tab; }); if (tabIndex !== -1) { this.keyManager.updateActiveItem(tabIndex); if (this.focusIndex !== this.selectedIndex) { this.selectFocusedIndex.emit(this.focusIndex); this.scrollToTab(tab); } } }; NzTabNavBarComponent.prototype.onOffsetChange = function (e) { if (this.position === 'horizontal') { if (this.lockAnimationTimeoutId === -1) { if (this.transformX >= 0 && e.x > 0) { return; } if (this.transformX <= this.wrapperWidth - this.scrollListWidth && e.x < 0) { return; } } e.event.preventDefault(); this.transformX = this.clampTransformX(this.transformX + e.x); this.setTransform(this.transformX, 0); } else { if (this.lockAnimationTimeoutId === -1) { if (this.transformY >= 0 && e.y > 0) { return; } if (this.transformY <= this.wrapperHeight - this.scrollListHeight && e.y < 0) { return; } } e.event.preventDefault(); this.transformY = this.clampTransformY(this.transformY + e.y); this.setTransform(0, this.transformY); } this.lockAnimation(); this.setVisibleRange(); this.setPingStatus(); }; NzTabNavBarComponent.prototype.handleKeydown = function (event) { var inNavigationList = this.navWarpRef.nativeElement.contains(event.target); if (keycodes.hasModifierKey(event) || !inNavigationList) { return; } switch (event.keyCode) { case keycodes.LEFT_ARROW: case keycodes.UP_ARROW: case keycodes.RIGHT_ARROW: case keycodes.DOWN_ARROW: this.lockAnimation(); this.keyManager.onKeydown(event); break; case keycodes.ENTER: case keycodes.SPACE: if (this.focusIndex !== this.selectedIndex) { this.selectFocusedIndex.emit(this.focusIndex); } break; default: this.keyManager.onKeydown(event); } }; NzTabNavBarComponent.prototype.isValidIndex = function (index) { if (!this.items) { return true; } var tab = this.items ? this.items.toArray()[index] : null; return !!tab && !tab.disabled; }; NzTabNavBarComponent.prototype.scrollToTab = function (tab) { var _this = this; if (!this.items.find(function (e) { return e === tab; })) { return; } var tabs = this.items.toArray(); if (this.position === 'horizontal') { var newTransform = this.transformX; if (this.getLayoutDirection() === 'rtl') { var right = tabs[0].left + tabs[0].width - tab.left - tab.width; if (right < this.transformX) { newTransform = right; } else if (right + tab.width > this.transformX + this.wrapperWidth) { newTransform = right + tab.width - this.wrapperWidth; } } else if (tab.left < -this.transformX) { newTransform = -tab.left; } else if (tab.left + tab.width > -this.transformX + this.wrapperWidth) { newTransform = -(tab.left + tab.width - this.wrapperWidth); } this.transformX = newTransform; this.transformY = 0; this.setTransform(newTransform, 0); } else { var newTransform = this.transformY; if (tab.top < -this.transformY) { newTransform = -tab.top; } else if (tab.top + tab.height > -this.transformY + this.wrapperHeight) { newTransform = -(tab.top + tab.height - this.wrapperHeight); } this.transformY = newTransform; this.transformX = 0; this.setTransform(0, newTransform); } clearTimeout(this.cssTransformTimeWaitingId); this.cssTransformTimeWaitingId = setTimeout(function () { _this.setVisibleRange(); }, CSS_TRANSFORM_TIME); }; NzTabNavBarComponent.prototype.lockAnimation = function () { var _this = this; if (this.lockAnimationTimeoutId === -1) { this.ngZone.runOutsideAngular(function () { _this.navListRef.nativeElement.style.transition = 'none'; _this.lockAnimationTimeoutId = setTimeout(function () { _this.navListRef.nativeElement.style.transition = ''; _this.lockAnimationTimeoutId = -1; }, CSS_TRANSFORM_TIME); }); } }; NzTabNavBarComponent.prototype.setTransform = function (x, y) { this.navListRef.nativeElement.style.transform = "translate(" + x + "px, " + y + "px)"; }; NzTabNavBarComponent.prototype.clampTransformX = function (transform) { var scrollWidth = this.wrapperWidth - this.scrollListWidth; if (this.getLayoutDirection() === 'rtl') { return Math.max(Math.min(scrollWidth, transform), 0); } else { return Math.min(Math.max(scrollWidth, transform), 0); } }; NzTabNavBarComponent.prototype.clampTransformY = function (transform) { return Math.min(Math.max(this.wrapperHeight - this.scrollListHeight, transform), 0); }; NzTabNavBarComponent.prototype.updateScrollListPosition = function () { this.resetSizes(); this.transformX = this.clampTransformX(this.transformX); this.transformY = this.clampTransformY(this.transformY); this.setVisibleRange(); this.setPingStatus(); if (this.keyManager) { this.keyManager.updateActiveItem(this.keyManager.activeItemIndex); if (this.keyManager.activeItem) { this.scrollToTab(this.keyManager.activeItem); } } }; NzTabNavBarComponent.prototype.resetSizes = function () { this.addButtonWidth = this.addBtnRef ? this.addBtnRef.getElementWidth() : 0; this.addButtonHeight = this.addBtnRef ? this.addBtnRef.getElementHeight() : 0; this.operationWidth = this.operationRef.getElementWidth(); this.operationHeight = this.operationRef.getElementHeight(); this.wrapperWidth = this.navWarpRef.nativeElement.offsetWidth || 0; this.wrapperHeight = this.navWarpRef.nativeElement.offsetHeight || 0; this.scrollListHeight = this.navListRef.nativeElement.offsetHeight || 0; this.scrollListWidth = this.navListRef.nativeElement.offsetWidth || 0; }; NzTabNavBarComponent.prototype.alignInkBarToSelectedTab = function () { var selectedItem = this.items && this.items.length ? this.items.toArray()[this.selectedIndex] : null; var selectedItemElement = selectedItem ? selectedItem.elementRef.nativeElement : null; if (selectedItemElement) { /** * .ant-tabs-nav-list - Target offset parent element * └──.ant-tabs-tab * └──.ant-tabs-tab-btn - Currently focused element */ this.inkBar.alignToElement(selectedItemElement.parentElement); } }; NzTabNavBarComponent.prototype.setPingStatus = function () { var ping = { top: false, right: false, bottom: false, left: false }; var navWarp = this.navWarpRef.nativeElement; if (this.position === 'horizontal') { if (this.getLayoutDirection() === 'rtl') { ping.right = this.transformX > 0; ping.left = this.transformX + this.wrapperWidth < this.scrollListWidth; } else { ping.left = this.transformX < 0; ping.right = -this.transformX + this.wrapperWidth < this.scrollListWidth; } } else { ping.top = this.transformY < 0; ping.bottom = -this.transformY + this.wrapperHeight < this.scrollListHeight; } Object.keys(ping).forEach(function (pos) { var className = "ant-tabs-nav-wrap-ping-" + pos; if (ping[pos]) { navWarp.classList.add(className); } else { navWarp.classList.remove(className); } }); }; NzTabNavBarComponent.prototype.setVisibleRange = function () { var unit; var position; var transformSize; var basicSize; var tabContentSize; var addSize; var tabs = this.items.toArray(); var DEFAULT_SIZE = { width: 0, height: 0, left: 0, top: 0, right: 0 }; var getOffset = function (index) { var offset; var size = tabs[index] || DEFAULT_SIZE; if (position === 'right') { offset = tabs[0].left + tabs[0].width - tabs[index].left - tabs[index].width; } else { offset = size[position]; } return offset; }; if (this.position === 'horizontal') { unit = 'width'; basicSize = this.wrapperWidth; tabContentSize = this.scrollListWidth - (this.hiddenItems.length ? this.operationWidth : 0); addSize = this.addButtonWidth; transformSize = Math.abs(this.transformX); if (this.getLayoutDirection() === 'rtl') { position = 'right'; this.pingRight = this.transformX > 0; this.pingLeft = this.transformX + this.wrapperWidth < this.scrollListWidth; } else { this.pingLeft = this.transformX < 0; this.pingRight = -this.transformX + this.wrapperWidth < this.scrollListWidth; position = 'left'; } } else { unit = 'height'; basicSize = this.wrapperHeight; tabContentSize = this.scrollListHeight - (this.hiddenItems.length ? this.operationHeight : 0); addSize = this.addButtonHeight; position = 'top'; transformSize = -this.transformY; this.pingTop = this.transformY < 0; this.pingBottom = -this.transformY + this.wrapperHeight < this.scrollListHeight; } var mergedBasicSize = basicSize; if (tabContentSize + addSize > basicSize) { mergedBasicSize = basicSize - addSize; } if (!tabs.length) { this.hiddenItems = []; this.cdr.markForCheck(); return; } var len = tabs.length; var endIndex = len; for (var i = 0; i < len; i += 1) { var offset = getOffset(i); var size = tabs[i] || DEFAULT_SIZE; if (offset + size[unit] > transformSize + mergedBasicSize) { endIndex = i - 1; break; } } var startIndex = 0; for (var i = len - 1; i >= 0; i -= 1) { var offset = getOffset(i); if (offset < transformSize) { startIndex = i + 1; break; } } var startHiddenTabs = tabs.slice(0, startIndex); var endHiddenTabs = tabs.slice(endIndex + 1); this.hiddenItems = __spread(startHiddenTabs, endHiddenTabs); this.cdr.markForCheck(); }; NzTabNavBarComponent.prototype.getLayoutDirection = function () { return this.dir && this.dir.value === 'rtl' ? 'rtl' : 'ltr'; }; NzTabNavBarComponent.prototype.setTabFocus = function (_tabIndex) { }; NzTabNavBarComponent.prototype.ngOnChanges = function (changes) { var position = changes.position; // The first will be aligning in ngAfterViewInit if (position && !position.isFirstChange()) { this.alignInkBarToSelectedTab(); this.lockAnimation(); this.updateScrollListPosition(); } }; return NzTabNavBarComponent; }()); NzTabNavBarComponent.decorators = [ { type: core.Component, args: [{ selector: 'nz-tabs-nav', exportAs: 'nzTabsNav', preserveWhitespaces: false, changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, template: "\n <div\n class=\"ant-tabs-nav-wrap\"\n [class.ant-tabs-nav-wrap-ping-left]=\"pingLeft\"\n [class.ant-tabs-nav-wrap-ping-right]=\"pingRight\"\n [class.ant-tabs-nav-wrap-ping-top]=\"pingTop\"\n [class.ant-tabs-nav-wrap-ping-bottom]=\"pingBottom\"\n #navWarp\n >\n <div class=\"ant-tabs-nav-list\" #navList nzTabScrollList (offsetChange)=\"onOffsetChange($event)\" (tabScroll)=\"tabScroll.emit($event)\">\n <ng-content></ng-content>\n <button *ngIf=\"showAddButton\" nz-tab-add-button [addIcon]=\"addIcon\" (click)=\"addClicked.emit()\"></button>\n <div nz-tabs-ink-bar [hidden]=\"hideBar\" [position]=\"position\" [animated]=\"inkBarAnimated\"></div>\n </div>\n </div>\n <nz-tab-nav-operation\n (addClicked)=\"addClicked.emit()\"\n (selected)=\"onSelectedFromMenu($event)\"\n [addIcon]=\"addIcon\"\n [addable]=\"addable\"\n [items]=\"hiddenItems\"\n ></nz-tab-nav-operation>\n <div class=\"ant-tabs-extra-content\" *ngIf=\"extraTemplate\">\n <ng-template [ngTemplateOutlet]=\"extraTemplate\"></ng-template>\n </div>\n ", host: { role: 'tablist', class: 'ant-tabs-nav', '(keydown)': 'handleKeydown($event)' } },] } ]; NzTabNavBarComponent.ctorParameters = function () { return [ { type: core.ChangeDetectorRef }, { type: core.NgZone }, { type: overlay.ViewportRuler }, { type: resizeObservers.NzResizeObserver }, { type: bidi.Directionality, decorators: [{ type: core.Optional }] } ]; }; NzTabNavBarComponent.propDecorators = { indexFocused: [{ type: core.Output }], selectFocusedIndex: [{ type: core.Output }], addClicked: [{ type: core.Output }], tabScroll: [{ type: core.Output }], position: [{ type: core.Input }], addable: [{ type: core.Input }], hideBar: [{ type: core.Input }], addIcon: [{ type: core.Input }], inkBarAnimated: [{ type: core.Input }], extraTemplate: [{ type: core.Input }], selectedIndex: [{ type: core.Input }], navWarpRef: [{ type: core.ViewChild, args: ['navWarp', { static: true },] }], navListRef: [{ type: core.ViewChild, args: ['navList', { static: true },] }], operationRef: [{ type: core.ViewChild, args: [NzTabNavOperationComponent, { static: true },] }], addBtnRef: [{ type: core.ViewChild, args: [NzTabAddButtonComponent, { static: false },] }], inkBar: [{ type: core.ViewChild, args: [NzTabsInkBarDirective, { static: true },] }], items: [{ type: core.ContentChildren, args: [NzTabNavItemDirective, { descendants: true },] }] }; /** * 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 NzTabBodyComponent = /** @class */ (function () { function NzTabBodyComponent() { this.content = null; this.active = false; this.tabPaneAnimated = true; this.forceRender = false; } return NzTabBodyComponent; }()); NzTabBodyComponent.decorators = [ { type: core.Component, args: [{ selector: '[nz-tab-body]', exportAs: 'nzTabBody', preserveWhitespaces: false, encapsulation: core.ViewEncapsulation.None, changeDetection: core.ChangeDetectionStrategy.OnPush, template: "\n <ng-container *ngIf=\"active || forceRender\">\n <ng-template [ngTemplateOutlet]=\"content\"></ng-template>\n </ng-container>\n ", host: { class: 'ant-tabs-tabpane', '[class.ant-tabs-tabpane-active]': 'active', '[attr.tabindex]': 'active ? 0 : -1', '[attr.aria-hidden]': '!active', '[style.visibility]': 'tabPaneAnimated ? active ? null : "hidden" : null', '[style.height]': 'tabPaneAnimated ? active ? null : 0 : null', '[style.overflow-y]': 'tabPaneAnimated ? active ? null : "none" : null', '[style.display]': '!tabPaneAnimated ? active ? null : "none" : null' } },] } ]; NzTabBodyComponent.propDecorators = { content: [{ type: core.Input }], active: [{ type: core.Input }], tabPaneAnimated: [{ type: core.Input }], forceRender: [{ type: core.Input }] }; /** * 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 MIN_SWIPE_DISTANCE = 0.1; var STOP_SWIPE_DISTANCE = 0.01; var REFRESH_INTERVAL = 20; var SPEED_OFF_MU