import { Directive, ViewContainerRef, Input, Injectable, Component, Renderer2, ElementRef, HostBinding, EventEmitter, Output, TemplateRef, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NgTranscludeDirective { /** * @param {?} viewRef */ constructor(viewRef) { this.viewRef = viewRef; } /** * @param {?} templateRef * @return {?} */ set ngTransclude(templateRef) { this._ngTransclude = templateRef; if (templateRef) { this.viewRef.createEmbeddedView(templateRef); } } /* tslint:disable-next-line:no-any */ /** * @return {?} */ get ngTransclude() { return this._ngTransclude; } } NgTranscludeDirective.decorators = [ { type: Directive, args: [{ selector: '[ngTransclude]' },] } ]; /** @nocollapse */ NgTranscludeDirective.ctorParameters = () => [ { type: ViewContainerRef } ]; NgTranscludeDirective.propDecorators = { ngTransclude: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class TabsetConfig { constructor() { /** * provides default navigation context class: 'tabs' or 'pills' */ this.type = 'tabs'; } } TabsetConfig.decorators = [ { type: Injectable } ]; /** * @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 class TabsetComponent { /** * @param {?} config * @param {?} renderer * @param {?} elementRef */ constructor(config, renderer, elementRef) { this.renderer = renderer; this.elementRef = elementRef; this.clazz = true; this.tabs = []; this.classMap = {}; Object.assign(this, config); } /** * if true tabs will be placed vertically * @return {?} */ get vertical() { return this._vertical; } /** * @param {?} value * @return {?} */ set vertical(value) { this._vertical = value; this.setClassMap(); } /** * if true tabs fill the container and have a consistent width * @return {?} */ get justified() { return this._justified; } /** * @param {?} value * @return {?} */ set justified(value) { this._justified = value; this.setClassMap(); } /** * navigation context class: 'tabs' or 'pills' * @return {?} */ get type() { return this._type; } /** * @param {?} value * @return {?} */ set type(value) { this._type = value; this.setClassMap(); } /** * @return {?} */ ngOnDestroy() { this.isDestroyed = true; } /** * @param {?} tab * @return {?} */ addTab(tab) { this.tabs.push(tab); tab.active = this.tabs.length === 1 && typeof tab.active === 'undefined'; } /** * @param {?} tab * @param {?=} options * @return {?} */ removeTab(tab, options = { reselect: true, emit: true }) { /** @type {?} */ const 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 {?} */ const 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 */ /** * @param {?} event * @param {?} index * @return {?} */ keyNavActions(event, index) { /** @type {?} */ const 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 {?} */ const currentTab = list[(index) % list.length]; currentTab.click(); return; } // tslint:disable-next-line:deprecation if (event.keyCode === 39 || event.key === 'RightArrow') { /** @type {?} */ let nextTab; /** @type {?} */ let 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 {?} */ let previousTab; /** @type {?} */ let shift = 1; /** @type {?} */ let 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 {?} */ let firstTab; /** @type {?} */ let 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 {?} */ let lastTab; /** @type {?} */ let shift = 1; /** @type {?} */ let 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 {?} */ getClosestTabIndex(index) { /** @type {?} */ const tabsLength = this.tabs.length; if (!tabsLength) { return -1; } for (let step = 1; step <= tabsLength; step += 1) { /** @type {?} */ const prevIndex = index - step; /** @type {?} */ const 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 {?} */ hasAvailableTabs(index) { /** @type {?} */ const tabsLength = this.tabs.length; if (!tabsLength) { return false; } for (let i = 0; i < tabsLength; i += 1) { if (!this.tabs[i].disabled && i !== index) { return true; } } return false; } /** * @protected * @return {?} */ setClassMap() { this.classMap = { 'nav-stacked': this.vertical, 'flex-column': this.vertical, 'nav-justified': this.justified, [`nav-${this.type}`]: true }; } } TabsetComponent.decorators = [ { type: Component, args: [{ selector: 'tabset', template: "