import * as i1 from '@angular/common'; import { isPlatformBrowser, DOCUMENT, CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, EventEmitter, booleanAttribute, numberAttribute, Component, ViewEncapsulation, Input, Output, ViewChild, signal, effect, PLATFORM_ID, ChangeDetectionStrategy, Inject, ContentChildren, NgModule } from '@angular/core'; import * as i2 from '@angular/router'; import { RouterModule } from '@angular/router'; import * as i5 from 'primeng/api'; import { PrimeTemplate, SharedModule } from 'primeng/api'; import { DomHandler } from 'primeng/dom'; import { AngleDownIcon } from 'primeng/icons/angledown'; import { AngleRightIcon } from 'primeng/icons/angleright'; import { BarsIcon } from 'primeng/icons/bars'; import * as i3 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; import * as i4 from 'primeng/tooltip'; import { TooltipModule } from 'primeng/tooltip'; import { ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primeng/utils'; import { Subject, interval } from 'rxjs'; import { debounce, filter } from 'rxjs/operators'; class MenubarService { autoHide; autoHideDelay; mouseLeaves = new Subject(); mouseLeft$ = this.mouseLeaves.pipe(debounce(() => interval(this.autoHideDelay)), filter((mouseLeft) => this.autoHide && mouseLeft)); static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarService, decorators: [{ type: Injectable }] }); class MenubarSub { el; renderer; cd; menubarService; items; itemTemplate; root = false; autoZIndex = true; baseZIndex = 0; mobileActive; autoDisplay; menuId; ariaLabel; ariaLabelledBy; level = 0; focusedItemId; activeItemPath; submenuIconTemplate; itemClick = new EventEmitter(); itemMouseEnter = new EventEmitter(); menuFocus = new EventEmitter(); menuBlur = new EventEmitter(); menuKeydown = new EventEmitter(); menubarViewChild; mouseLeaveSubscriber; constructor(el, renderer, cd, menubarService) { this.el = el; this.renderer = renderer; this.cd = cd; this.menubarService = menubarService; } ngOnInit() { this.mouseLeaveSubscriber = this.menubarService.mouseLeft$.subscribe(() => { this.cd.markForCheck(); }); } onItemClick(event, processedItem) { this.getItemProp(processedItem, 'command', { originalEvent: event, item: processedItem.item }); this.itemClick.emit({ originalEvent: event, processedItem, isFocus: true }); } getItemProp(processedItem, name, params = null) { return processedItem && processedItem.item ? ObjectUtils.getItemValue(processedItem.item[name], params) : undefined; } getItemId(processedItem) { return processedItem.item && processedItem.item?.id ? processedItem.item.id : `${this.menuId}_${processedItem.key}`; } getItemKey(processedItem) { return this.getItemId(processedItem); } getItemLabelId(processedItem) { return `${this.menuId}_${processedItem.key}_label`; } getItemClass(processedItem) { return { ...this.getItemProp(processedItem, 'class'), 'p-menuitem': true, 'p-highlight': this.isItemActive(processedItem), 'p-menuitem-active': this.isItemActive(processedItem), 'p-focus': this.isItemFocused(processedItem), 'p-disabled': this.isItemDisabled(processedItem) }; } getItemLabel(processedItem) { return this.getItemProp(processedItem, 'label'); } getSeparatorItemClass(processedItem) { return { ...this.getItemProp(processedItem, 'class'), 'p-menuitem-separator': true }; } isItemVisible(processedItem) { return this.getItemProp(processedItem, 'visible') !== false; } isItemActive(processedItem) { if (this.activeItemPath) { return this.activeItemPath.some((path) => path.key === processedItem.key); } } isItemDisabled(processedItem) { return this.getItemProp(processedItem, 'disabled'); } isItemFocused(processedItem) { return this.focusedItemId === this.getItemId(processedItem); } isItemGroup(processedItem) { return ObjectUtils.isNotEmpty(processedItem.items); } getAriaSetSize() { return this.items.filter((processedItem) => this.isItemVisible(processedItem) && !this.getItemProp(processedItem, 'separator')).length; } getAriaPosInset(index) { return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1; } onItemMouseLeave() { this.menubarService.mouseLeaves.next(true); } onItemMouseEnter(param) { if (this.autoDisplay) { this.menubarService.mouseLeaves.next(false); const { event, processedItem } = param; this.itemMouseEnter.emit({ originalEvent: event, processedItem }); } } ngOnDestroy() { this.mouseLeaveSubscriber?.unsubscribe(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarSub, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: MenubarService }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: MenubarSub, selector: "p-menubarSub", inputs: { items: "items", itemTemplate: "itemTemplate", root: ["root", "root", booleanAttribute], autoZIndex: ["autoZIndex", "autoZIndex", booleanAttribute], baseZIndex: ["baseZIndex", "baseZIndex", numberAttribute], mobileActive: ["mobileActive", "mobileActive", booleanAttribute], autoDisplay: ["autoDisplay", "autoDisplay", booleanAttribute], menuId: "menuId", ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy", level: ["level", "level", numberAttribute], focusedItemId: "focusedItemId", activeItemPath: "activeItemPath", submenuIconTemplate: "submenuIconTemplate" }, outputs: { itemClick: "itemClick", itemMouseEnter: "itemMouseEnter", menuFocus: "menuFocus", menuBlur: "menuBlur", menuKeydown: "menuKeydown" }, host: { classAttribute: "p-element" }, viewQueries: [{ propertyName: "menubarViewChild", first: true, predicate: ["menubar"], descendants: true, static: true }], ngImport: i0, template: ` `, isInline: true, dependencies: [{ kind: "directive", type: i0.forwardRef(() => i1.NgClass), selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgForOf), selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgIf), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgTemplateOutlet), selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgStyle), selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i0.forwardRef(() => i2.RouterLink), selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: i0.forwardRef(() => i2.RouterLinkActive), selector: "[routerLinkActive]", inputs: ["routerLinkActiveOptions", "ariaCurrentWhenActive", "routerLinkActive"], outputs: ["isActiveChange"], exportAs: ["routerLinkActive"] }, { kind: "directive", type: i0.forwardRef(() => i3.Ripple), selector: "[pRipple]" }, { kind: "directive", type: i0.forwardRef(() => i4.Tooltip), selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "appendTo", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "pTooltip", "tooltipDisabled", "tooltipOptions"] }, { kind: "component", type: i0.forwardRef(() => AngleDownIcon), selector: "AngleDownIcon" }, { kind: "component", type: i0.forwardRef(() => AngleRightIcon), selector: "AngleRightIcon" }, { kind: "component", type: i0.forwardRef(() => MenubarSub), selector: "p-menubarSub", inputs: ["items", "itemTemplate", "root", "autoZIndex", "baseZIndex", "mobileActive", "autoDisplay", "menuId", "ariaLabel", "ariaLabelledBy", "level", "focusedItemId", "activeItemPath", "submenuIconTemplate"], outputs: ["itemClick", "itemMouseEnter", "menuFocus", "menuBlur", "menuKeydown"] }], encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarSub, decorators: [{ type: Component, args: [{ selector: 'p-menubarSub', template: ` `, encapsulation: ViewEncapsulation.None, host: { class: 'p-element' } }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: MenubarService }], propDecorators: { items: [{ type: Input }], itemTemplate: [{ type: Input }], root: [{ type: Input, args: [{ transform: booleanAttribute }] }], autoZIndex: [{ type: Input, args: [{ transform: booleanAttribute }] }], baseZIndex: [{ type: Input, args: [{ transform: numberAttribute }] }], mobileActive: [{ type: Input, args: [{ transform: booleanAttribute }] }], autoDisplay: [{ type: Input, args: [{ transform: booleanAttribute }] }], menuId: [{ type: Input }], ariaLabel: [{ type: Input }], ariaLabelledBy: [{ type: Input }], level: [{ type: Input, args: [{ transform: numberAttribute }] }], focusedItemId: [{ type: Input }], activeItemPath: [{ type: Input }], submenuIconTemplate: [{ type: Input }], itemClick: [{ type: Output }], itemMouseEnter: [{ type: Output }], menuFocus: [{ type: Output }], menuBlur: [{ type: Output }], menuKeydown: [{ type: Output }], menubarViewChild: [{ type: ViewChild, args: ['menubar', { static: true }] }] } }); /** * Menubar is a horizontal menu component. * @group Components */ class Menubar { document; platformId; el; renderer; cd; config; menubarService; /** * An array of menuitems. * @group Props */ set model(value) { this._model = value; this._processedItems = this.createProcessedItems(this._model || []); } get model() { return this._model; } /** * Inline style of the element. * @group Props */ style; /** * Class of the element. * @group Props */ styleClass; /** * Whether to automatically manage layering. * @group Props */ autoZIndex = true; /** * Base zIndex value to use in layering. * @group Props */ baseZIndex = 0; /** * Whether to show a root submenu on mouse over. * @defaultValue true * @group Props */ autoDisplay = true; /** * Whether to hide a root submenu when mouse leaves. * @group Props */ autoHide; /** * Delay to hide the root submenu in milliseconds when mouse leaves. * @group Props */ autoHideDelay = 100; /** * Current id state as a string. * @group Props */ id; /** * Defines a string value that labels an interactive element. * @group Props */ ariaLabel; /** * Identifier of the underlying input element. * @group Props */ ariaLabelledBy; /** * Callback to execute when button is focused. * @param {FocusEvent} event - Focus event. * @group Emits */ onFocus = new EventEmitter(); /** * Callback to execute when button loses focus. * @param {FocusEvent} event - Focus event. * @group Emits */ onBlur = new EventEmitter(); templates; menubutton; rootmenu; startTemplate; endTemplate; menuIconTemplate; submenuIconTemplate; itemTemplate; mobileActive; outsideClickListener; resizeListener; mouseLeaveSubscriber; dirty = false; focused = false; activeItemPath = signal([]); number = signal(0); focusedItemInfo = signal({ index: -1, level: 0, parentKey: '', item: null }); searchValue = ''; searchTimeout; _processedItems; _model; get visibleItems() { const processedItem = this.activeItemPath().find((p) => p.key === this.focusedItemInfo().parentKey); return processedItem ? processedItem.items : this.processedItems; } get processedItems() { if (!this._processedItems || !this._processedItems.length) { this._processedItems = this.createProcessedItems(this.model || []); } return this._processedItems; } get focusedItemId() { const focusedItem = this.focusedItemInfo(); return focusedItem.item && focusedItem.item?.id ? focusedItem.item.id : focusedItem.index !== -1 ? `${this.id}${ObjectUtils.isNotEmpty(focusedItem.parentKey) ? '_' + focusedItem.parentKey : ''}_${focusedItem.index}` : null; } constructor(document, platformId, el, renderer, cd, config, menubarService) { this.document = document; this.platformId = platformId; this.el = el; this.renderer = renderer; this.cd = cd; this.config = config; this.menubarService = menubarService; effect(() => { const path = this.activeItemPath(); if (ObjectUtils.isNotEmpty(path)) { this.bindOutsideClickListener(); this.bindResizeListener(); } else { this.unbindOutsideClickListener(); this.unbindResizeListener(); } }); } ngOnInit() { this.menubarService.autoHide = this.autoHide; this.menubarService.autoHideDelay = this.autoHideDelay; this.mouseLeaveSubscriber = this.menubarService.mouseLeft$.subscribe(() => this.unbindOutsideClickListener()); this.id = this.id || UniqueComponentId(); } ngAfterContentInit() { this.templates?.forEach((item) => { switch (item.getType()) { case 'start': this.startTemplate = item.template; break; case 'end': this.endTemplate = item.template; break; case 'menuicon': this.menuIconTemplate = item.template; break; case 'submenuicon': this.submenuIconTemplate = item.template; break; case 'item': this.itemTemplate = item.template; break; default: this.itemTemplate = item.template; break; } }); } createProcessedItems(items, level = 0, parent = {}, parentKey = '') { const processedItems = []; items && items.forEach((item, index) => { const key = (parentKey !== '' ? parentKey + '_' : '') + index; const newItem = { item, index, level, key, parent, parentKey }; newItem['items'] = this.createProcessedItems(item.items, level + 1, newItem, key); processedItems.push(newItem); }); return processedItems; } getItemProp(item, name) { return item ? ObjectUtils.getItemValue(item[name]) : undefined; } menuButtonClick(event) { this.toggle(event); } menuButtonKeydown(event) { (event.code === 'Enter' || event.code === 'Space') && this.menuButtonClick(event); } onItemClick(event) { const { originalEvent, processedItem } = event; const grouped = this.isProcessedItemGroup(processedItem); const root = ObjectUtils.isEmpty(processedItem.parent); const selected = this.isSelected(processedItem); if (selected) { const { index, key, level, parentKey, item } = processedItem; this.activeItemPath.set(this.activeItemPath().filter((p) => key !== p.key && key.startsWith(p.key))); this.focusedItemInfo.set({ index, level, parentKey, item }); this.dirty = !root; DomHandler.focus(this.rootmenu.menubarViewChild.nativeElement); } else { if (grouped) { this.onItemChange(event); } else { const rootProcessedItem = root ? processedItem : this.activeItemPath().find((p) => p.parentKey === ''); this.hide(originalEvent); this.changeFocusedItemIndex(originalEvent, rootProcessedItem ? rootProcessedItem.index : -1); this.mobileActive = false; DomHandler.focus(this.rootmenu.menubarViewChild.nativeElement); } } } onItemMouseEnter(event) { if (!DomHandler.isTouchDevice()) { if (!this.mobileActive) { this.onItemChange(event); } } } changeFocusedItemIndex(event, index) { const processedItem = this.findVisibleItem(index); if (this.focusedItemInfo().index !== index) { const focusedItemInfo = this.focusedItemInfo(); this.focusedItemInfo.set({ ...focusedItemInfo, item: processedItem.item, index }); this.scrollInView(); } } scrollInView(index = -1) { const id = index !== -1 ? `${this.id}_${index}` : this.focusedItemId; const element = DomHandler.findSingle(this.rootmenu.el.nativeElement, `li[id="${id}"]`); if (element) { element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'nearest' }); } } onItemChange(event) { const { processedItem, isFocus } = event; if (ObjectUtils.isEmpty(processedItem)) return; const { index, key, level, parentKey, items, item } = processedItem; const grouped = ObjectUtils.isNotEmpty(items); const activeItemPath = this.activeItemPath().filter((p) => p.parentKey !== parentKey && p.parentKey !== key); grouped && activeItemPath.push(processedItem); this.focusedItemInfo.set({ index, level, parentKey, item }); this.activeItemPath.set(activeItemPath); grouped && (this.dirty = true); isFocus && DomHandler.focus(this.rootmenu.menubarViewChild.nativeElement); } toggle(event) { if (this.mobileActive) { this.mobileActive = false; ZIndexUtils.clear(this.rootmenu.el.nativeElement); this.hide(); } else { this.mobileActive = true; ZIndexUtils.set('menu', this.rootmenu.el.nativeElement, this.config.zIndex.menu); setTimeout(() => { this.show(); }, 0); } this.cd.markForCheck(); this.bindOutsideClickListener(); event.preventDefault(); } hide(event, isFocus) { if (this.mobileActive) { setTimeout(() => { DomHandler.focus(this.menubutton.nativeElement); }, 0); } this.activeItemPath.set([]); this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null }); isFocus && DomHandler.focus(this.rootmenu?.menubarViewChild.nativeElement); this.dirty = false; } show() { const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex()); this.focusedItemInfo.set({ index: this.findFirstFocusedItemIndex(), level: 0, parentKey: '', item: processedItem?.item }); DomHandler.focus(this.rootmenu?.menubarViewChild.nativeElement); } onMenuFocus(event) { this.focused = true; const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex()); const focusedItemInfo = this.focusedItemInfo().index !== -1 ? this.focusedItemInfo() : { index: this.findFirstFocusedItemIndex(), level: 0, parentKey: '', item: processedItem?.item }; this.focusedItemInfo.set(focusedItemInfo); this.onFocus.emit(event); } onMenuBlur(event) { this.focused = false; this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null }); this.searchValue = ''; this.dirty = false; this.onBlur.emit(event); } onKeyDown(event) { const metaKey = event.metaKey || event.ctrlKey; switch (event.code) { case 'ArrowDown': this.onArrowDownKey(event); break; case 'ArrowUp': this.onArrowUpKey(event); break; case 'ArrowLeft': this.onArrowLeftKey(event); break; case 'ArrowRight': this.onArrowRightKey(event); break; case 'Home': this.onHomeKey(event); break; case 'End': this.onEndKey(event); break; case 'Space': this.onSpaceKey(event); break; case 'Enter': this.onEnterKey(event); break; case 'Escape': this.onEscapeKey(event); break; case 'Tab': this.onTabKey(event); break; case 'PageDown': case 'PageUp': case 'Backspace': case 'ShiftLeft': case 'ShiftRight': //NOOP break; default: if (!metaKey && ObjectUtils.isPrintableCharacter(event.key)) { this.searchItems(event, event.key); } break; } } findVisibleItem(index) { return ObjectUtils.isNotEmpty(this.visibleItems) ? this.visibleItems[index] : null; } findFirstFocusedItemIndex() { const selectedIndex = this.findSelectedItemIndex(); return selectedIndex < 0 ? this.findFirstItemIndex() : selectedIndex; } findFirstItemIndex() { return this.visibleItems.findIndex((processedItem) => this.isValidItem(processedItem)); } findSelectedItemIndex() { return this.visibleItems.findIndex((processedItem) => this.isValidSelectedItem(processedItem)); } isProcessedItemGroup(processedItem) { return processedItem && ObjectUtils.isNotEmpty(processedItem.items); } isSelected(processedItem) { return this.activeItemPath().some((p) => p.key === processedItem.key); } isValidSelectedItem(processedItem) { return this.isValidItem(processedItem) && this.isSelected(processedItem); } isValidItem(processedItem) { return !!processedItem && !this.isItemDisabled(processedItem.item) && !this.isItemSeparator(processedItem.item); } isItemDisabled(item) { return this.getItemProp(item, 'disabled'); } isItemSeparator(item) { return this.getItemProp(item, 'separator'); } isItemMatched(processedItem) { return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem).toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase()); } isProccessedItemGroup(processedItem) { return processedItem && ObjectUtils.isNotEmpty(processedItem.items); } searchItems(event, char) { this.searchValue = (this.searchValue || '') + char; let itemIndex = -1; let matched = false; if (this.focusedItemInfo().index !== -1) { itemIndex = this.visibleItems.slice(this.focusedItemInfo().index).findIndex((processedItem) => this.isItemMatched(processedItem)); itemIndex = itemIndex === -1 ? this.visibleItems.slice(0, this.focusedItemInfo().index).findIndex((processedItem) => this.isItemMatched(processedItem)) : itemIndex + this.focusedItemInfo().index; } else { itemIndex = this.visibleItems.findIndex((processedItem) => this.isItemMatched(processedItem)); } if (itemIndex !== -1) { matched = true; } if (itemIndex === -1 && this.focusedItemInfo().index === -1) { itemIndex = this.findFirstFocusedItemIndex(); } if (itemIndex !== -1) { this.changeFocusedItemIndex(event, itemIndex); } if (this.searchTimeout) { clearTimeout(this.searchTimeout); } this.searchTimeout = setTimeout(() => { this.searchValue = ''; this.searchTimeout = null; }, 500); return matched; } getProccessedItemLabel(processedItem) { return processedItem ? this.getItemLabel(processedItem.item) : undefined; } getItemLabel(item) { return this.getItemProp(item, 'label'); } onArrowDownKey(event) { const processedItem = this.visibleItems[this.focusedItemInfo().index]; const root = processedItem ? ObjectUtils.isEmpty(processedItem.parent) : null; if (root) { const grouped = this.isProccessedItemGroup(processedItem); if (grouped) { this.onItemChange({ originalEvent: event, processedItem }); this.focusedItemInfo.set({ index: -1, parentKey: processedItem.key, item: processedItem.item }); this.onArrowRightKey(event); } } else { const itemIndex = this.focusedItemInfo().index !== -1 ? this.findNextItemIndex(this.focusedItemInfo().index) : this.findFirstFocusedItemIndex(); this.changeFocusedItemIndex(event, itemIndex); event.preventDefault(); } } onArrowRightKey(event) { const processedItem = this.visibleItems[this.focusedItemInfo().index]; const parentItem = processedItem ? this.activeItemPath().find((p) => p.key === processedItem.parentKey) : null; if (parentItem) { const grouped = this.isProccessedItemGroup(processedItem); if (grouped) { this.onItemChange({ originalEvent: event, processedItem }); this.focusedItemInfo.set({ index: -1, parentKey: processedItem.key, item: processedItem.item }); this.onArrowDownKey(event); } } else { const itemIndex = this.focusedItemInfo().index !== -1 ? this.findNextItemIndex(this.focusedItemInfo().index) : this.findFirstFocusedItemIndex(); this.changeFocusedItemIndex(event, itemIndex); event.preventDefault(); } } onArrowUpKey(event) { const processedItem = this.visibleItems[this.focusedItemInfo().index]; const root = ObjectUtils.isEmpty(processedItem.parent); if (root) { const grouped = this.isProccessedItemGroup(processedItem); if (grouped) { this.onItemChange({ originalEvent: event, processedItem }); this.focusedItemInfo.set({ index: -1, parentKey: processedItem.key, item: processedItem.item }); const itemIndex = this.findLastItemIndex(); this.changeFocusedItemIndex(event, itemIndex); } } else { const parentItem = this.activeItemPath().find((p) => p.key === processedItem.parentKey); if (this.focusedItemInfo().index === 0) { this.focusedItemInfo.set({ index: -1, parentKey: parentItem ? parentItem.parentKey : '', item: processedItem.item }); this.searchValue = ''; this.onArrowLeftKey(event); const activeItemPath = this.activeItemPath().filter((p) => p.parentKey !== this.focusedItemInfo().parentKey); this.activeItemPath.set(activeItemPath); } else { const itemIndex = this.focusedItemInfo().index !== -1 ? this.findPrevItemIndex(this.focusedItemInfo().index) : this.findLastFocusedItemIndex(); this.changeFocusedItemIndex(event, itemIndex); } } event.preventDefault(); } onArrowLeftKey(event) { const processedItem = this.visibleItems[this.focusedItemInfo().index]; const parentItem = processedItem ? this.activeItemPath().find((p) => p.key === processedItem.parentKey) : null; if (parentItem) { this.onItemChange({ originalEvent: event, processedItem: parentItem }); const activeItemPath = this.activeItemPath().filter((p) => p.parentKey !== this.focusedItemInfo().parentKey); this.activeItemPath.set(activeItemPath); event.preventDefault(); } else { const itemIndex = this.focusedItemInfo().index !== -1 ? this.findPrevItemIndex(this.focusedItemInfo().index) : this.findLastFocusedItemIndex(); this.changeFocusedItemIndex(event, itemIndex); event.preventDefault(); } } onHomeKey(event) { this.changeFocusedItemIndex(event, this.findFirstItemIndex()); event.preventDefault(); } onEndKey(event) { this.changeFocusedItemIndex(event, this.findLastItemIndex()); event.preventDefault(); } onSpaceKey(event) { this.onEnterKey(event); } onEscapeKey(event) { this.hide(event, true); this.focusedItemInfo().index = this.findFirstFocusedItemIndex(); event.preventDefault(); } onTabKey(event) { if (this.focusedItemInfo().index !== -1) { const processedItem = this.visibleItems[this.focusedItemInfo().index]; const grouped = this.isProccessedItemGroup(processedItem); !grouped && this.onItemChange({ originalEvent: event, processedItem }); } this.hide(); } onEnterKey(event) { if (this.focusedItemInfo().index !== -1) { const element = DomHandler.findSingle(this.rootmenu.el.nativeElement, `li[id="${`${this.focusedItemId}`}"]`); const anchorElement = element && DomHandler.findSingle(element, 'a[data-pc-section="action"]'); anchorElement ? anchorElement.click() : element && element.click(); } event.preventDefault(); } findLastFocusedItemIndex() { const selectedIndex = this.findSelectedItemIndex(); return selectedIndex < 0 ? this.findLastItemIndex() : selectedIndex; } findLastItemIndex() { return ObjectUtils.findLastIndex(this.visibleItems, (processedItem) => this.isValidItem(processedItem)); } findPrevItemIndex(index) { const matchedItemIndex = index > 0 ? ObjectUtils.findLastIndex(this.visibleItems.slice(0, index), (processedItem) => this.isValidItem(processedItem)) : -1; return matchedItemIndex > -1 ? matchedItemIndex : index; } findNextItemIndex(index) { const matchedItemIndex = index < this.visibleItems.length - 1 ? this.visibleItems.slice(index + 1).findIndex((processedItem) => this.isValidItem(processedItem)) : -1; return matchedItemIndex > -1 ? matchedItemIndex + index + 1 : index; } bindResizeListener() { if (isPlatformBrowser(this.platformId)) { if (!this.resizeListener) { this.resizeListener = this.renderer.listen(this.document.defaultView, 'resize', (event) => { if (!DomHandler.isTouchDevice()) { this.hide(event, true); } this.mobileActive = false; }); } } } bindOutsideClickListener() { if (isPlatformBrowser(this.platformId)) { if (!this.outsideClickListener) { this.outsideClickListener = this.renderer.listen(this.document, 'click', (event) => { const isOutsideContainer = this.rootmenu.el.nativeElement !== event.target && !this.rootmenu.el.nativeElement.contains(event.target); const isOutsideMenuButton = this.mobileActive && this.menubutton.nativeElement !== event.target && !this.menubutton.nativeElement.contains(event.target); if (isOutsideContainer) { isOutsideMenuButton ? (this.mobileActive = false) : this.hide(); } }); } } } unbindOutsideClickListener() { if (this.outsideClickListener) { this.outsideClickListener(); this.outsideClickListener = null; } } unbindResizeListener() { if (this.resizeListener) { this.resizeListener(); this.resizeListener = null; } } ngOnDestroy() { this.mouseLeaveSubscriber?.unsubscribe(); this.unbindOutsideClickListener(); this.unbindResizeListener(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Menubar, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i5.PrimeNGConfig }, { token: MenubarService }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: Menubar, selector: "p-menubar", inputs: { model: "model", style: "style", styleClass: "styleClass", autoZIndex: ["autoZIndex", "autoZIndex", booleanAttribute], baseZIndex: ["baseZIndex", "baseZIndex", numberAttribute], autoDisplay: ["autoDisplay", "autoDisplay", booleanAttribute], autoHide: ["autoHide", "autoHide", booleanAttribute], autoHideDelay: ["autoHideDelay", "autoHideDelay", numberAttribute], id: "id", ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy" }, outputs: { onFocus: "onFocus", onBlur: "onBlur" }, host: { classAttribute: "p-element" }, providers: [MenubarService], queries: [{ propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "menubutton", first: true, predicate: ["menubutton"], descendants: true }, { propertyName: "rootmenu", first: true, predicate: ["rootmenu"], descendants: true }], ngImport: i0, template: `
`, isInline: true, styles: ["@layer primeng{.p-menubar{display:flex;align-items:center}.p-menubar ul{margin:0;padding:0;list-style:none}.p-menubar .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden;position:relative}.p-menubar .p-menuitem-text{line-height:1}.p-menubar .p-menuitem{position:relative}.p-menubar-root-list{display:flex;align-items:center;flex-wrap:wrap}.p-menubar-root-list>li ul{display:none;z-index:1}.p-menubar-root-list>.p-menuitem-active>p-menubarsub>.p-submenu-list{display:block}.p-menubar .p-submenu-list{display:none;position:absolute;z-index:2}.p-menubar .p-submenu-list>.p-menuitem-active>p-menubarsub>.p-submenu-list{display:block;left:100%;top:0}.p-menubar .p-submenu-list .p-menuitem-link .p-submenu-icon:not(svg){margin-left:auto}.p-menubar .p-menubar-root-list .p-icon-wrapper,.p-menubar .p-submenu-list .p-menuitem-link .p-icon-wrapper{margin-left:auto}.p-menubar .p-menubar-custom,.p-menubar .p-menubar-end{margin-left:auto;align-self:center}.p-menubar-button{display:none;cursor:pointer;align-items:center;justify-content:center}}\n"], dependencies: [{ kind: "directive", type: i0.forwardRef(() => i1.NgClass), selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgIf), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgTemplateOutlet), selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i0.forwardRef(() => i1.NgStyle), selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: i0.forwardRef(() => BarsIcon), selector: "BarsIcon" }, { kind: "component", type: i0.forwardRef(() => MenubarSub), selector: "p-menubarSub", inputs: ["items", "itemTemplate", "root", "autoZIndex", "baseZIndex", "mobileActive", "autoDisplay", "menuId", "ariaLabel", "ariaLabelledBy", "level", "focusedItemId", "activeItemPath", "submenuIconTemplate"], outputs: ["itemClick", "itemMouseEnter", "menuFocus", "menuBlur", "menuKeydown"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Menubar, decorators: [{ type: Component, args: [{ selector: 'p-menubar', template: `
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { class: 'p-element' }, providers: [MenubarService], styles: ["@layer primeng{.p-menubar{display:flex;align-items:center}.p-menubar ul{margin:0;padding:0;list-style:none}.p-menubar .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden;position:relative}.p-menubar .p-menuitem-text{line-height:1}.p-menubar .p-menuitem{position:relative}.p-menubar-root-list{display:flex;align-items:center;flex-wrap:wrap}.p-menubar-root-list>li ul{display:none;z-index:1}.p-menubar-root-list>.p-menuitem-active>p-menubarsub>.p-submenu-list{display:block}.p-menubar .p-submenu-list{display:none;position:absolute;z-index:2}.p-menubar .p-submenu-list>.p-menuitem-active>p-menubarsub>.p-submenu-list{display:block;left:100%;top:0}.p-menubar .p-submenu-list .p-menuitem-link .p-submenu-icon:not(svg){margin-left:auto}.p-menubar .p-menubar-root-list .p-icon-wrapper,.p-menubar .p-submenu-list .p-menuitem-link .p-icon-wrapper{margin-left:auto}.p-menubar .p-menubar-custom,.p-menubar .p-menubar-end{margin-left:auto;align-self:center}.p-menubar-button{display:none;cursor:pointer;align-items:center;justify-content:center}}\n"] }] }], ctorParameters: () => [{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT] }] }, { type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID] }] }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i5.PrimeNGConfig }, { type: MenubarService }], propDecorators: { model: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], autoZIndex: [{ type: Input, args: [{ transform: booleanAttribute }] }], baseZIndex: [{ type: Input, args: [{ transform: numberAttribute }] }], autoDisplay: [{ type: Input, args: [{ transform: booleanAttribute }] }], autoHide: [{ type: Input, args: [{ transform: booleanAttribute }] }], autoHideDelay: [{ type: Input, args: [{ transform: numberAttribute }] }], id: [{ type: Input }], ariaLabel: [{ type: Input }], ariaLabelledBy: [{ type: Input }], onFocus: [{ type: Output }], onBlur: [{ type: Output }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }], menubutton: [{ type: ViewChild, args: ['menubutton'] }], rootmenu: [{ type: ViewChild, args: ['rootmenu'] }] } }); class MenubarModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: MenubarModule, declarations: [Menubar, MenubarSub], imports: [CommonModule, RouterModule, RippleModule, TooltipModule, SharedModule, BarsIcon, AngleDownIcon, AngleRightIcon], exports: [Menubar, RouterModule, TooltipModule, SharedModule] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarModule, imports: [CommonModule, RouterModule, RippleModule, TooltipModule, SharedModule, BarsIcon, AngleDownIcon, AngleRightIcon, RouterModule, TooltipModule, SharedModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MenubarModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, RouterModule, RippleModule, TooltipModule, SharedModule, BarsIcon, AngleDownIcon, AngleRightIcon], exports: [Menubar, RouterModule, TooltipModule, SharedModule], declarations: [Menubar, MenubarSub] }] }] }); /** * Generated bundle index. Do not edit. */ export { Menubar, MenubarModule, MenubarService, MenubarSub }; //# sourceMappingURL=primeng-menubar.mjs.map