| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- import { Directive, ViewContainerRef, Input, Injectable, Component, Renderer2, ElementRef, HostBinding, Output, EventEmitter, TemplateRef, NgModule } from '@angular/core';
- import { CommonModule } from '@angular/common';
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var NgTranscludeDirective = /** @class */ (function () {
- function NgTranscludeDirective(viewRef) {
- this.viewRef = viewRef;
- }
- Object.defineProperty(NgTranscludeDirective.prototype, "ngTransclude", {
- /* tslint:disable-next-line:no-any */
- get: /* tslint:disable-next-line:no-any */
- /**
- * @return {?}
- */
- function () {
- return this._ngTransclude;
- },
- set: /**
- * @param {?} templateRef
- * @return {?}
- */
- function (templateRef) {
- this._ngTransclude = templateRef;
- if (templateRef) {
- this.viewRef.createEmbeddedView(templateRef);
- }
- },
- enumerable: true,
- configurable: true
- });
- NgTranscludeDirective.decorators = [
- { type: Directive, args: [{
- selector: '[ngTransclude]'
- },] }
- ];
- /** @nocollapse */
- NgTranscludeDirective.ctorParameters = function () { return [
- { type: ViewContainerRef }
- ]; };
- NgTranscludeDirective.propDecorators = {
- ngTransclude: [{ type: Input }]
- };
- return NgTranscludeDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var TabsetConfig = /** @class */ (function () {
- function TabsetConfig() {
- /**
- * provides default navigation context class: 'tabs' or 'pills'
- */
- this.type = 'tabs';
- }
- TabsetConfig.decorators = [
- { type: Injectable }
- ];
- return TabsetConfig;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- // todo: add active event to tab
- // todo: fix? mixing static and dynamic tabs position tabs in order of creation
- var TabsetComponent = /** @class */ (function () {
- function TabsetComponent(config, renderer, elementRef) {
- this.renderer = renderer;
- this.elementRef = elementRef;
- this.clazz = true;
- this.tabs = [];
- this.classMap = {};
- Object.assign(this, config);
- }
- Object.defineProperty(TabsetComponent.prototype, "vertical", {
- /** if true tabs will be placed vertically */
- get: /**
- * if true tabs will be placed vertically
- * @return {?}
- */
- function () {
- return this._vertical;
- },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._vertical = value;
- this.setClassMap();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TabsetComponent.prototype, "justified", {
- /** if true tabs fill the container and have a consistent width */
- get: /**
- * if true tabs fill the container and have a consistent width
- * @return {?}
- */
- function () {
- return this._justified;
- },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._justified = value;
- this.setClassMap();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TabsetComponent.prototype, "type", {
- /** navigation context class: 'tabs' or 'pills' */
- get: /**
- * navigation context class: 'tabs' or 'pills'
- * @return {?}
- */
- function () {
- return this._type;
- },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._type = value;
- this.setClassMap();
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @return {?}
- */
- TabsetComponent.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- this.isDestroyed = true;
- };
- /**
- * @param {?} tab
- * @return {?}
- */
- TabsetComponent.prototype.addTab = /**
- * @param {?} tab
- * @return {?}
- */
- function (tab) {
- this.tabs.push(tab);
- tab.active = this.tabs.length === 1 && typeof tab.active === 'undefined';
- };
- /**
- * @param {?} tab
- * @param {?=} options
- * @return {?}
- */
- TabsetComponent.prototype.removeTab = /**
- * @param {?} tab
- * @param {?=} options
- * @return {?}
- */
- function (tab, options) {
- if (options === void 0) { options = { reselect: true, emit: true }; }
- /** @type {?} */
- var index = this.tabs.indexOf(tab);
- if (index === -1 || this.isDestroyed) {
- return;
- }
- // Select a new tab if the tab to be removed is selected and not destroyed
- if (options.reselect && tab.active && this.hasAvailableTabs(index)) {
- /** @type {?} */
- var newActiveIndex = this.getClosestTabIndex(index);
- this.tabs[newActiveIndex].active = true;
- }
- if (options.emit) {
- tab.removed.emit(tab);
- }
- this.tabs.splice(index, 1);
- if (tab.elementRef.nativeElement.parentNode) {
- this.renderer.removeChild(tab.elementRef.nativeElement.parentNode, tab.elementRef.nativeElement);
- }
- };
- /* tslint:disable-next-line: cyclomatic-complexity */
- /* tslint:disable-next-line: cyclomatic-complexity */
- /**
- * @param {?} event
- * @param {?} index
- * @return {?}
- */
- TabsetComponent.prototype.keyNavActions = /* tslint:disable-next-line: cyclomatic-complexity */
- /**
- * @param {?} event
- * @param {?} index
- * @return {?}
- */
- function (event, index) {
- /** @type {?} */
- var list = Array.from(this.elementRef.nativeElement.querySelectorAll('.nav-link'));
- // const activeElList = list.filter((el: HTMLElement) => !el.classList.contains('disabled'));
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 13 || event.key === 'Enter' || event.keyCode === 32 || event.key === 'Space') {
- event.preventDefault();
- /** @type {?} */
- var currentTab = list[(index) % list.length];
- currentTab.click();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 39 || event.key === 'RightArrow') {
- /** @type {?} */
- var nextTab = void 0;
- /** @type {?} */
- var shift = 1;
- do {
- nextTab = list[(index + shift) % list.length];
- shift++;
- } while (nextTab.classList.contains('disabled'));
- nextTab.focus();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 37 || event.key === 'LeftArrow') {
- /** @type {?} */
- var previousTab = void 0;
- /** @type {?} */
- var shift = 1;
- /** @type {?} */
- var i = index;
- do {
- if ((i - shift) < 0) {
- i = list.length - 1;
- previousTab = list[i];
- shift = 0;
- }
- else {
- previousTab = list[i - shift];
- }
- shift++;
- } while (previousTab.classList.contains('disabled'));
- previousTab.focus();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 36 || event.key === 'Home') {
- event.preventDefault();
- /** @type {?} */
- var firstTab = void 0;
- /** @type {?} */
- var shift = 0;
- do {
- firstTab = list[shift % list.length];
- shift++;
- } while (firstTab.classList.contains('disabled'));
- firstTab.focus();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 35 || event.key === 'End') {
- event.preventDefault();
- /** @type {?} */
- var lastTab = void 0;
- /** @type {?} */
- var shift = 1;
- /** @type {?} */
- var i = index;
- do {
- if ((i - shift) < 0) {
- i = list.length - 1;
- lastTab = list[i];
- shift = 0;
- }
- else {
- lastTab = list[i - shift];
- }
- shift++;
- } while (lastTab.classList.contains('disabled'));
- lastTab.focus();
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 46 || event.key === 'Delete') {
- if (this.tabs[index].removable) {
- this.removeTab(this.tabs[index]);
- if (list[index + 1]) {
- list[(index + 1) % list.length].focus();
- return;
- }
- if (list[list.length - 1]) {
- list[0].focus();
- }
- }
- }
- };
- /**
- * @protected
- * @param {?} index
- * @return {?}
- */
- TabsetComponent.prototype.getClosestTabIndex = /**
- * @protected
- * @param {?} index
- * @return {?}
- */
- function (index) {
- /** @type {?} */
- var tabsLength = this.tabs.length;
- if (!tabsLength) {
- return -1;
- }
- for (var step = 1; step <= tabsLength; step += 1) {
- /** @type {?} */
- var prevIndex = index - step;
- /** @type {?} */
- var nextIndex = index + step;
- if (this.tabs[prevIndex] && !this.tabs[prevIndex].disabled) {
- return prevIndex;
- }
- if (this.tabs[nextIndex] && !this.tabs[nextIndex].disabled) {
- return nextIndex;
- }
- }
- return -1;
- };
- /**
- * @protected
- * @param {?} index
- * @return {?}
- */
- TabsetComponent.prototype.hasAvailableTabs = /**
- * @protected
- * @param {?} index
- * @return {?}
- */
- function (index) {
- /** @type {?} */
- var tabsLength = this.tabs.length;
- if (!tabsLength) {
- return false;
- }
- for (var i = 0; i < tabsLength; i += 1) {
- if (!this.tabs[i].disabled && i !== index) {
- return true;
- }
- }
- return false;
- };
- /**
- * @protected
- * @return {?}
- */
- TabsetComponent.prototype.setClassMap = /**
- * @protected
- * @return {?}
- */
- function () {
- var _a;
- this.classMap = (_a = {
- 'nav-stacked': this.vertical,
- 'flex-column': this.vertical,
- 'nav-justified': this.justified
- },
- _a["nav-" + this.type] = true,
- _a);
- };
- TabsetComponent.decorators = [
- { type: Component, args: [{
- selector: 'tabset',
- template: "<ul class=\"nav\" [ngClass]=\"classMap\" (click)=\"$event.preventDefault()\">\n <li *ngFor=\"let tabz of tabs; let i = index\" [ngClass]=\"['nav-item', tabz.customClass || '']\"\n [class.active]=\"tabz.active\" [class.disabled]=\"tabz.disabled\" (keydown)=\"keyNavActions($event, i)\">\n <a href=\"javascript:void(0);\" class=\"nav-link\"\n [attr.id]=\"tabz.id ? tabz.id + '-link' : ''\"\n [class.active]=\"tabz.active\" [class.disabled]=\"tabz.disabled\"\n (click)=\"tabz.active = true\">\n <span [ngTransclude]=\"tabz.headingRef\">{{ tabz.heading }}</span>\n <span *ngIf=\"tabz.removable\" (click)=\"$event.preventDefault(); removeTab(tabz);\" class=\"bs-remove-tab\"> ❌</span>\n </a>\n </li>\n</ul>\n<div class=\"tab-content\">\n <ng-content></ng-content>\n</div>\n",
- styles: [":host .nav-tabs .nav-item.disabled a.disabled{cursor:default}"]
- }] }
- ];
- /** @nocollapse */
- TabsetComponent.ctorParameters = function () { return [
- { type: TabsetConfig },
- { type: Renderer2 },
- { type: ElementRef }
- ]; };
- TabsetComponent.propDecorators = {
- vertical: [{ type: Input }],
- justified: [{ type: Input }],
- type: [{ type: Input }],
- clazz: [{ type: HostBinding, args: ['class.tab-container',] }]
- };
- return TabsetComponent;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var TabDirective = /** @class */ (function () {
- function TabDirective(tabset, elementRef, renderer) {
- this.elementRef = elementRef;
- this.renderer = renderer;
- /**
- * fired when tab became active, $event:Tab equals to selected instance of Tab component
- */
- this.selectTab = new EventEmitter();
- /**
- * fired when tab became inactive, $event:Tab equals to deselected instance of Tab component
- */
- this.deselect = new EventEmitter();
- /**
- * fired before tab will be removed, $event:Tab equals to instance of removed tab
- */
- this.removed = new EventEmitter();
- this.addClass = true;
- this.tabset = tabset;
- this.tabset.addTab(this);
- }
- Object.defineProperty(TabDirective.prototype, "customClass", {
- /** if set, will be added to the tab's class attribute. Multiple classes are supported. */
- get: /**
- * if set, will be added to the tab's class attribute. Multiple classes are supported.
- * @return {?}
- */
- function () {
- return this._customClass;
- },
- set: /**
- * @param {?} customClass
- * @return {?}
- */
- function (customClass) {
- var _this = this;
- if (this.customClass) {
- this.customClass.split(' ').forEach((/**
- * @param {?} cssClass
- * @return {?}
- */
- function (cssClass) {
- _this.renderer.removeClass(_this.elementRef.nativeElement, cssClass);
- }));
- }
- this._customClass = customClass ? customClass.trim() : null;
- if (this.customClass) {
- this.customClass.split(' ').forEach((/**
- * @param {?} cssClass
- * @return {?}
- */
- function (cssClass) {
- _this.renderer.addClass(_this.elementRef.nativeElement, cssClass);
- }));
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TabDirective.prototype, "active", {
- /** tab active state toggle */
- get: /**
- * tab active state toggle
- * @return {?}
- */
- function () {
- return this._active;
- },
- set: /**
- * @param {?} active
- * @return {?}
- */
- function (active) {
- var _this = this;
- if (this._active === active) {
- return;
- }
- if ((this.disabled && active) || !active) {
- if (this._active && !active) {
- this.deselect.emit(this);
- this._active = active;
- }
- return;
- }
- this._active = active;
- this.selectTab.emit(this);
- this.tabset.tabs.forEach((/**
- * @param {?} tab
- * @return {?}
- */
- function (tab) {
- if (tab !== _this) {
- tab.active = false;
- }
- }));
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @return {?}
- */
- TabDirective.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- this.removable = this.removable;
- };
- /**
- * @return {?}
- */
- TabDirective.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- this.tabset.removeTab(this, { reselect: false, emit: false });
- };
- TabDirective.decorators = [
- { type: Directive, args: [{ selector: 'tab, [tab]' },] }
- ];
- /** @nocollapse */
- TabDirective.ctorParameters = function () { return [
- { type: TabsetComponent },
- { type: ElementRef },
- { type: Renderer2 }
- ]; };
- TabDirective.propDecorators = {
- heading: [{ type: Input }],
- id: [{ type: HostBinding, args: ['attr.id',] }, { type: Input }],
- disabled: [{ type: Input }],
- removable: [{ type: Input }],
- customClass: [{ type: Input }],
- active: [{ type: HostBinding, args: ['class.active',] }, { type: Input }],
- selectTab: [{ type: Output }],
- deselect: [{ type: Output }],
- removed: [{ type: Output }],
- addClass: [{ type: HostBinding, args: ['class.tab-pane',] }]
- };
- return TabDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * Should be used to mark <ng-template> element as a template for tab heading
- */
- var TabHeadingDirective = /** @class */ (function () {
- /* tslint:disable-next-line:no-any */
- function TabHeadingDirective(templateRef, tab) {
- tab.headingRef = templateRef;
- }
- TabHeadingDirective.decorators = [
- { type: Directive, args: [{ selector: '[tabHeading]' },] }
- ];
- /** @nocollapse */
- TabHeadingDirective.ctorParameters = function () { return [
- { type: TemplateRef },
- { type: TabDirective }
- ]; };
- return TabHeadingDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var TabsModule = /** @class */ (function () {
- function TabsModule() {
- }
- /**
- * @return {?}
- */
- TabsModule.forRoot = /**
- * @return {?}
- */
- function () {
- return {
- ngModule: TabsModule,
- providers: [TabsetConfig]
- };
- };
- TabsModule.decorators = [
- { type: NgModule, args: [{
- imports: [CommonModule],
- declarations: [
- NgTranscludeDirective,
- TabDirective,
- TabsetComponent,
- TabHeadingDirective
- ],
- exports: [
- TabDirective,
- TabsetComponent,
- TabHeadingDirective,
- NgTranscludeDirective
- ]
- },] }
- ];
- return TabsModule;
- }());
- export { NgTranscludeDirective, TabDirective, TabHeadingDirective, TabsModule, TabsetComponent, TabsetConfig };
- //# sourceMappingURL=ngx-bootstrap-tabs.js.map
|