import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ContentChildren, ViewChild, NgModule } from '@angular/core'; import * as i2 from '@angular/router'; import { RouterModule } from '@angular/router'; import { PrimeTemplate, SharedModule } from 'primeng/api'; import * as i3 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; import * as i4 from 'primeng/tooltip'; import { TooltipModule } from 'primeng/tooltip'; import { UniqueComponentId, ObjectUtils } from 'primeng/utils'; import { DomHandler } from 'primeng/dom'; /** * Dock is a navigation component consisting of menuitems. * @group Components */ class Dock { el; cd; /** * Current id state as a string. * @group Props */ id; /** * Inline style of the element. * @group Props */ style; /** * Class of the element. * @group Props */ styleClass; /** * MenuModel instance to define the action items. * @group Props */ model = null; /** * Position of element. * @group Props */ position = 'bottom'; /** * Defines a string that labels the input for accessibility. * @group Props */ ariaLabel; /** * Defines a string that labels the dropdown button for accessibility. * @group Props */ ariaLabelledBy; /** * Callback to execute when button is focused. * @param {FocusEvent} event - Focus event. * @group Emits */ onFocus = new EventEmitter(); /** * Callback to invoke when the component loses focus. * @param {FocusEvent} event - Focus event. * @group Emits */ onBlur = new EventEmitter(); templates; listViewChild; itemTemplate; currentIndex; tabindex = 0; focused = false; focusedOptionIndex = -1; get focusedOptionId() { return this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : null; } constructor(el, cd) { this.el = el; this.cd = cd; this.currentIndex = -3; } ngOnInit() { this.id = this.id || UniqueComponentId(); } ngAfterContentInit() { this.templates?.forEach((item) => { switch (item.getType()) { case 'item': this.itemTemplate = item.template; break; default: this.itemTemplate = item.template; break; } }); } getItemId(item, index) { return item && item?.id ? item.id : `${index}`; } getItemProp(processedItem, name) { return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name]) : undefined; } disabled(item) { return typeof item.disabled === 'function' ? item.disabled() : item.disabled; } isItemActive(id) { return id === this.focusedOptionIndex; } onListMouseLeave() { this.currentIndex = -3; this.cd.markForCheck(); } onItemMouseEnter(index) { this.currentIndex = index; if (index === 1) { } this.cd.markForCheck(); } onItemClick(e, item) { if (item.command) { item.command({ originalEvent: e, item }); } } onListFocus(event) { this.focused = true; this.changeFocusedOptionIndex(0); this.onFocus.emit(event); } onListBlur(event) { this.focused = false; this.focusedOptionIndex = -1; this.onBlur.emit(event); } onListKeyDown(event) { switch (event.code) { case 'ArrowDown': { if (this.position === 'left' || this.position === 'right') this.onArrowDownKey(); event.preventDefault(); break; } case 'ArrowUp': { if (this.position === 'left' || this.position === 'right') this.onArrowUpKey(); event.preventDefault(); break; } case 'ArrowRight': { if (this.position === 'top' || this.position === 'bottom') this.onArrowDownKey(); event.preventDefault(); break; } case 'ArrowLeft': { if (this.position === 'top' || this.position === 'bottom') this.onArrowUpKey(); event.preventDefault(); break; } case 'Home': { this.onHomeKey(); event.preventDefault(); break; } case 'End': { this.onEndKey(); event.preventDefault(); break; } case 'Enter': case 'Space': { this.onSpaceKey(); event.preventDefault(); break; } default: break; } } onArrowDownKey() { const optionIndex = this.findNextOptionIndex(this.focusedOptionIndex); this.changeFocusedOptionIndex(optionIndex); } onArrowUpKey() { const optionIndex = this.findPrevOptionIndex(this.focusedOptionIndex); this.changeFocusedOptionIndex(optionIndex); } onHomeKey() { this.changeFocusedOptionIndex(0); } onEndKey() { this.changeFocusedOptionIndex(DomHandler.find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]').length - 1); } onSpaceKey() { const element = DomHandler.findSingle(this.listViewChild.nativeElement, `li[id="${`${this.focusedOptionIndex}`}"]`); const anchorElement = element && DomHandler.findSingle(element, '[data-pc-section="action"]'); anchorElement ? anchorElement.click() : element && element.click(); } findNextOptionIndex(index) { const menuitems = DomHandler.find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]'); const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === index); return matchedOptionIndex > -1 ? matchedOptionIndex + 1 : 0; } changeFocusedOptionIndex(index) { const menuitems = DomHandler.find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]'); let order = index >= menuitems.length ? menuitems.length - 1 : index < 0 ? 0 : index; this.focusedOptionIndex = menuitems[order].getAttribute('id'); } findPrevOptionIndex(index) { const menuitems = DomHandler.find(this.listViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]'); const matchedOptionIndex = [...menuitems].findIndex((link) => link.id === index); return matchedOptionIndex > -1 ? matchedOptionIndex - 1 : 0; } get containerClass() { return { ['p-dock p-component ' + ` p-dock-${this.position}`]: true }; } isClickableRouterLink(item) { return item.routerLink && !item.disabled; } itemClass(item, index) { return { 'p-dock-item': true, 'p-dock-item-second-prev': this.currentIndex - 2 === index, 'p-dock-item-prev': this.currentIndex - 1 === index, 'p-dock-item-current': this.currentIndex === index, 'p-dock-item-next': this.currentIndex + 1 === index, 'p-dock-item-second-next': this.currentIndex + 2 === index, 'p-focus': this.isItemActive(this.getItemId(item, index)) }; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Dock, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.7", type: Dock, selector: "p-dock", inputs: { id: "id", style: "style", styleClass: "styleClass", model: "model", position: "position", ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy" }, outputs: { onFocus: "onFocus", onBlur: "onBlur" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "listViewChild", first: true, predicate: ["list"], descendants: true }], ngImport: i0, template: `