UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

1 lines 96.1 kB
{"version":3,"file":"primeng-contextmenu.mjs","sources":["../../src/contextmenu/style/contextmenustyle.ts","../../src/contextmenu/contextmenu.ts","../../src/contextmenu/primeng-contextmenu.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { BaseStyle } from 'primeng/base';\n\nconst theme = ({ dt }) => `\n.p-contextmenu {\n position: absolute;\n background: ${dt('contextmenu.background')};\n color: ${dt('contextmenu.color')};\n border: 1px solid ${dt('contextmenu.border.color')};\n border-radius: ${dt('contextmenu.border.radius')};\n box-shadow: ${dt('contextmenu.shadow')};\n min-width: 12.5rem;\n}\n\n.p-contextmenu-root-list,\n.p-contextmenu-submenu {\n margin: 0;\n padding: ${dt('contextmenu.list.padding')};\n list-style: none;\n outline: 0 none;\n display: flex;\n flex-direction: column;\n gap: ${dt('contextmenu.list.gap')};\n}\n\n.p-contextmenu-submenu {\n position: absolute;\n display: flex;\n flex-direction: column;\n min-width: 100%;\n z-index: 1;\n background: ${dt('contextmenu.background')};\n color: ${dt('contextmenu.color')};\n border: 1px solid ${dt('contextmenu.border.color')};\n border-radius: ${dt('contextmenu.border.radius')};\n box-shadow: ${dt('contextmenu.shadow')};\n}\n\n.p-contextmenu-item {\n position: relative;\n}\n\n.p-contextmenu-item-content {\n transition: background ${dt('contextmenu.transition.duration')}, color ${dt('contextmenu.transition.duration')};\n border-radius: ${dt('contextmenu.item.border.radius')};\n color: ${dt('contextmenu.item.color')};\n}\n\n.p-contextmenu-item-link {\n cursor: pointer;\n display: flex;\n align-items: center;\n text-decoration: none;\n overflow: hidden;\n position: relative;\n color: inherit;\n padding: ${dt('contextmenu.item.padding')};\n gap: ${dt('contextmenu.item.gap')};\n user-select: none;\n}\n\n.p-contextmenu-item-label {\n line-height: 1;\n}\n\n.p-contextmenu-item-icon {\n color: ${dt('contextmenu.item.icon.color')};\n}\n\n.p-contextmenu-submenu-icon {\n color: ${dt('contextmenu.submenu.icon.color')};\n margin-left: auto;\n font-size: ${dt('contextmenu.submenu.icon.size')};\n width: ${dt('contextmenu.submenu.icon.size')};\n height: ${dt('contextmenu.submenu.icon.size')};\n}\n\n.p-contextmenu-submenu-icon:dir(rtl) {\n margin-left: 0;\n margin-right: auto;\n}\n\n.p-contextmenu-item.p-focus > .p-contextmenu-item-content {\n color: ${dt('contextmenu.item.focus.color')};\n background: ${dt('contextmenu.item.focus.background')};\n}\n\n.p-contextmenu-item.p-focus > .p-contextmenu-item-content .p-contextmenu-item-icon {\n color: ${dt('contextmenu.item.icon.focus.color')};\n}\n\n.p-contextmenu-item.p-focus > .p-contextmenu-item-content .p-contextmenu-submenu-icon {\n color: ${dt('contextmenu.submenu.icon.focus.color')};\n}\n\n.p-contextmenu-item:not(.p-disabled) > .p-contextmenu-item-content:hover {\n color: ${dt('contextmenu.item.focus.color')};\n background: ${dt('contextmenu.item.focus.background')};\n}\n\n.p-contextmenu-item:not(.p-disabled) > .p-contextmenu-item-content:hover .p-contextmenu-item-icon {\n color: ${dt('contextmenu.item.icon.focus.color')};\n}\n\n.p-contextmenu-item:not(.p-disabled) > .p-contextmenu-item-content:hover .p-contextmenu-submenu-icon {\n color: ${dt('contextmenu.submenu.icon.focus.color')};\n}\n\n.p-contextmenu-item-active > .p-contextmenu-item-content {\n color: ${dt('contextmenu.item.active.color')};\n background: ${dt('contextmenu.item.active.background')};\n}\n\n.p-contextmenu-item-active > .p-contextmenu-item-content .p-contextmenu-item-icon {\n color: ${dt('contextmenu.item.icon.active.color')};\n}\n\n.p-contextmenu-item-active > .p-contextmenu-item-content .p-contextmenu-submenu-icon {\n color: ${dt('contextmenu.submenu.icon.active.color')};\n}\n\n.p-contextmenu-separator {\n border-top: 1px solid ${dt('contextmenu.separator.border.color')};\n}\n\n.p-contextmenu-enter-from,\n.p-contextmenu-leave-active {\n opacity: 0;\n}\n\n.p-contextmenu-enter-active {\n transition: opacity 250ms;\n}\n\n.p-contextmenu-mobile .p-contextmenu-submenu {\n position: static;\n box-shadow: none;\n border: 0 none;\n padding-left: ${dt('tieredmenu.submenu.mobile.indent')};\n padding-right: 0;\n}\n\n.p-contextmenu-mobile .p-contextmenu-submenu-icon {\n transition: transform 0.2s;\n transform: rotate(90deg);\n}\n\n.p-contextmenu-mobile .p-contextmenu-item-active > .p-contextmenu-item-content .p-contextmenu-submenu-icon {\n transform: rotate(-90deg);\n}\n\n/* For PrimeNG */\n.p-contextmenu-submenu-icon.p-iconwrapper {\n margin-left: auto;\n}\n\n.p-contextmenu-submenu-icon.p-iconwrapper:dir(rtl) {\n margin-left: 0;\n margin-right: auto;\n}\n`;\n\nconst classes = {\n root: 'p-contextmenu p-component',\n rootList: 'p-contextmenu-root-list',\n item: ({ instance, processedItem }) => [\n 'p-contextmenu-item',\n {\n 'p-contextmenu-item-active': instance.isItemActive(processedItem),\n 'p-focus': instance.isItemFocused(processedItem),\n 'p-disabled': instance.isItemDisabled(processedItem)\n }\n ],\n itemContent: 'p-contextmenu-item-content',\n itemLink: 'p-contextmenu-item-link',\n itemIcon: 'p-contextmenu-item-icon',\n itemLabel: 'p-contextmenu-item-label',\n submenuIcon: 'p-contextmenu-submenu-icon',\n submenu: 'p-contextmenu-submenu',\n separator: 'p-contextmenu-separator'\n};\n\n@Injectable()\nexport class ContextMenuStyle extends BaseStyle {\n name = 'contextmenu';\n\n theme = theme;\n\n classes = classes;\n}\n\n/**\n *\n * ContextMenu displays an overlay menu on right click of its target. Note that components like DataTable has special integration with ContextMenu.\n * Refer to documentation of the individual documentation of the with context menu support.\n *\n * [Live Demo](https://www.primeng.org/contextmenu/)\n *\n * @module contextmenustyle\n *\n */\nexport enum ContextMenuClasses {\n /**\n * Class name of the root element\n */\n root = 'p-contextmenu',\n /**\n * Class name of the root list element\n */\n rootList = 'p-contextmenu-root-list',\n /**\n * Class name of the item element\n */\n item = 'p-contextmenu-item',\n /**\n * Class name of the item content element\n */\n itemContent = 'p-contextmenu-item-content',\n /**\n * Class name of the item link element\n */\n itemLink = 'p-contextmenu-item-link',\n /**\n * Class name of the item icon element\n */\n itemIcon = 'p-contextmenu-item-icon',\n /**\n * Class name of the item label element\n */\n itemLabel = 'p-contextmenu-item-label',\n /**\n * Class name of the submenu icon element\n */\n submenuIcon = 'p-contextmenu-submenu-icon',\n /**\n * Class name of the submenu element\n */\n submenu = 'p-contextmenu-submenu',\n /**\n * Class name of the separator element\n */\n separator = 'p-contextmenu-separator'\n}\n\nexport interface ContextMenuStyle extends BaseStyle {}\n","import { animate, AnimationEvent, style, transition, trigger } from '@angular/animations';\nimport { CommonModule, isPlatformBrowser } from '@angular/common';\nimport {\n AfterContentInit,\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n ContentChild,\n ContentChildren,\n effect,\n ElementRef,\n EventEmitter,\n forwardRef,\n Inject,\n inject,\n Input,\n NgModule,\n numberAttribute,\n OnDestroy,\n OnInit,\n Output,\n QueryList,\n signal,\n TemplateRef,\n ViewChild,\n ViewEncapsulation,\n ViewRef\n} from '@angular/core';\nimport { RouterModule } from '@angular/router';\nimport {\n appendChild,\n calculateScrollbarWidth,\n findLastIndex,\n findSingle,\n focus,\n getHiddenElementOuterHeight,\n getHiddenElementOuterWidth,\n getOffset,\n getOuterWidth,\n getViewport,\n isAndroid,\n isEmpty,\n isIOS,\n isNotEmpty,\n isPrintableCharacter,\n removeChild,\n resolve,\n uuid\n} from '@primeuix/utils';\nimport { MenuItem, OverlayService, PrimeTemplate, SharedModule } from 'primeng/api';\nimport { BadgeModule } from 'primeng/badge';\nimport { BaseComponent } from 'primeng/basecomponent';\nimport { AngleRightIcon } from 'primeng/icons';\nimport { Ripple } from 'primeng/ripple';\nimport { TooltipModule } from 'primeng/tooltip';\nimport { VoidListener } from 'primeng/ts-helpers';\nimport { ZIndexUtils } from 'primeng/utils';\nimport { ContextMenuStyle } from './style/contextmenustyle';\n\n@Component({\n selector: 'p-contextMenuSub, p-contextmenu-sub',\n standalone: true,\n imports: [CommonModule, RouterModule, Ripple, TooltipModule, AngleRightIcon, BadgeModule, SharedModule],\n template: `\n <ul\n *ngIf=\"root ? true : visible\"\n #sublist\n role=\"menu\"\n [ngClass]=\"{ 'p-contextmenu-submenu': !root, 'p-contextmenu-root-list': root }\"\n [@overlayAnimation]=\"visible\"\n (@overlayAnimation.start)=\"onEnter($event, sublist)\"\n [attr.id]=\"menuId + '_list'\"\n [tabindex]=\"tabindex\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledBy]=\"ariaLabelledBy\"\n [attr.aria-activedescendant]=\"focusedItemId\"\n [attr.aria-orientation]=\"'vertical'\"\n [attr.data-pc-section]=\"'menu'\"\n (keydown)=\"menuKeydown.emit($event)\"\n (focus)=\"menuFocus.emit($event)\"\n (blur)=\"menuBlur.emit($event)\"\n >\n <ng-template ngFor let-processedItem [ngForOf]=\"items\" let-index=\"index\">\n <li\n *ngIf=\"isItemVisible(processedItem) && getItemProp(processedItem, 'separator')\"\n [attr.id]=\"getItemId(processedItem)\"\n [style]=\"getItemProp(processedItem, 'style')\"\n [ngClass]=\"getSeparatorItemClass(processedItem)\"\n role=\"separator\"\n [attr.data-pc-section]=\"'separator'\"\n ></li>\n <li\n #listItem\n *ngIf=\"isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')\"\n role=\"menuitem\"\n [attr.id]=\"getItemId(processedItem)\"\n [attr.data-pc-section]=\"'menuitem'\"\n [attr.data-p-highlight]=\"isItemActive(processedItem)\"\n [attr.data-p-focused]=\"isItemFocused(processedItem)\"\n [attr.data-p-disabled]=\"isItemDisabled(processedItem)\"\n [attr.aria-label]=\"getItemLabel(processedItem)\"\n [attr.aria-disabled]=\"isItemDisabled(processedItem) || undefined\"\n [attr.aria-haspopup]=\"isItemGroup(processedItem) && !getItemProp(processedItem, 'to') ? 'menu' : undefined\"\n [attr.aria-expanded]=\"isItemGroup(processedItem) ? isItemActive(processedItem) : undefined\"\n [attr.aria-level]=\"level + 1\"\n [attr.aria-setsize]=\"getAriaSetSize()\"\n [attr.aria-posinset]=\"getAriaPosInset(index)\"\n [ngStyle]=\"getItemProp(processedItem, 'style')\"\n [ngClass]=\"getItemClass(processedItem)\"\n [class]=\"getItemProp(processedItem, 'styleClass')\"\n pTooltip\n [tooltipOptions]=\"getItemProp(processedItem, 'tooltipOptions')\"\n >\n <div [attr.data-pc-section]=\"'content'\" class=\"p-contextmenu-item-content\" (click)=\"onItemClick($event, processedItem)\" (mouseenter)=\"onItemMouseEnter({ $event, processedItem })\">\n <ng-container *ngIf=\"!itemTemplate\">\n <a\n *ngIf=\"!getItemProp(processedItem, 'routerLink')\"\n [attr.href]=\"getItemProp(processedItem, 'url')\"\n [attr.aria-hidden]=\"true\"\n [attr.data-automationid]=\"getItemProp(processedItem, 'automationId')\"\n [attr.data-pc-section]=\"'action'\"\n [target]=\"getItemProp(processedItem, 'target')\"\n [ngClass]=\"{ 'p-contextmenu-item-link': true }\"\n [attr.tabindex]=\"-1\"\n pRipple\n >\n <span\n *ngIf=\"getItemProp(processedItem, 'icon')\"\n class=\"p-contextmenu-item-icon\"\n [ngClass]=\"getItemProp(processedItem, 'icon')\"\n [ngStyle]=\"getItemProp(processedItem, 'iconStyle')\"\n [attr.data-pc-section]=\"'icon'\"\n [attr.aria-hidden]=\"true\"\n [attr.tabindex]=\"-1\"\n >\n </span>\n <span *ngIf=\"getItemProp(processedItem, 'escape'); else htmlLabel\" class=\"p-contextmenu-item-label\" [attr.data-pc-section]=\"'label'\">\n {{ getItemLabel(processedItem) }}\n </span>\n <ng-template #htmlLabel>\n <span class=\"p-contextmenu-item-label\" [innerHTML]=\"getItemLabel(processedItem)\" [attr.data-pc-section]=\"'label'\"></span>\n </ng-template>\n <p-badge *ngIf=\"getItemProp(processedItem, 'badge')\" [styleClass]=\"getItemProp(processedItem, 'badgeStyleClass')\" [value]=\"getItemProp(processedItem, 'badge')\" />\n <ng-container *ngIf=\"isItemGroup(processedItem)\">\n <AngleRightIcon *ngIf=\"!contextMenu.submenuIconTemplate && !contextMenu._submenuIconTemplate\" [class]=\"'p-contextmenu-submenu-icon'\" [attr.data-pc-section]=\"'submenuicon'\" [attr.aria-hidden]=\"true\" />\n <ng-template\n *ngTemplateOutlet=\"contextMenu.submenuIconTemplate || contextMenu._submenuIconTemplate; context: { class: 'p-contextmenu-submenu-icon' }\"\n [attr.data-pc-section]=\"'submenuicon'\"\n [attr.aria-hidden]=\"true\"\n ></ng-template>\n </ng-container>\n </a>\n <a\n *ngIf=\"getItemProp(processedItem, 'routerLink')\"\n [routerLink]=\"getItemProp(processedItem, 'routerLink')\"\n [attr.data-automationid]=\"getItemProp(processedItem, 'automationId')\"\n [attr.tabindex]=\"-1\"\n [attr.aria-hidden]=\"true\"\n [attr.data-pc-section]=\"'action'\"\n [queryParams]=\"getItemProp(processedItem, 'queryParams')\"\n [routerLinkActiveOptions]=\"getItemProp(processedItem, 'routerLinkActiveOptions') || { exact: false }\"\n [target]=\"getItemProp(processedItem, 'target')\"\n [ngClass]=\"{ 'p-contextmenu-item-link': true, 'p-disabled': getItemProp(processedItem, 'disabled') }\"\n [fragment]=\"getItemProp(processedItem, 'fragment')\"\n [queryParamsHandling]=\"getItemProp(processedItem, 'queryParamsHandling')\"\n [preserveFragment]=\"getItemProp(processedItem, 'preserveFragment')\"\n [skipLocationChange]=\"getItemProp(processedItem, 'skipLocationChange')\"\n [replaceUrl]=\"getItemProp(processedItem, 'replaceUrl')\"\n [state]=\"getItemProp(processedItem, 'state')\"\n pRipple\n >\n <span\n *ngIf=\"getItemProp(processedItem, 'icon')\"\n class=\"p-contextmenu-item-icon\"\n [ngClass]=\"getItemProp(processedItem, 'icon')\"\n [ngStyle]=\"getItemProp(processedItem, 'iconStyle')\"\n [attr.data-pc-section]=\"'icon'\"\n [attr.aria-hidden]=\"true\"\n [attr.tabindex]=\"-1\"\n >\n </span>\n <span *ngIf=\"getItemProp(processedItem, 'escape'); else htmlLabel\" class=\"p-contextmenu-item-label\" [attr.data-pc-section]=\"'label'\">\n {{ getItemLabel(processedItem) }}\n </span>\n <ng-template #htmlLabel>\n <span class=\"p-contextmenu-item-label\" [innerHTML]=\"getItemLabel(processedItem)\" [attr.data-pc-section]=\"'label'\"></span>\n </ng-template>\n <p-badge *ngIf=\"getItemProp(processedItem, 'badge')\" [styleClass]=\"getItemProp(processedItem, 'badgeStyleClass')\" [value]=\"getItemProp(processedItem, 'badge')\" />\n <ng-container *ngIf=\"isItemGroup(processedItem)\">\n <AngleRightIcon *ngIf=\"!contextMenu.submenuIconTemplate && !contextMenu._submenuIconTemplate\" [class]=\"'p-contextmenu-submenu-icon'\" [attr.data-pc-section]=\"'submenuicon'\" [attr.aria-hidden]=\"true\" />\n <ng-template\n *ngTemplateOutlet=\"!contextMenu.submenuIconTemplate || !contextMenu._submenuIconTemplate; context: { class: 'p-contextmenu-submenu-icon' }\"\n [attr.data-pc-section]=\"'submenuicon'\"\n [attr.aria-hidden]=\"true\"\n ></ng-template>\n </ng-container>\n </a>\n </ng-container>\n <ng-container *ngIf=\"itemTemplate\">\n <ng-template *ngTemplateOutlet=\"itemTemplate; context: { $implicit: processedItem.item }\"></ng-template>\n </ng-container>\n </div>\n\n <p-contextmenu-sub\n *ngIf=\"isItemVisible(processedItem) && isItemGroup(processedItem)\"\n [items]=\"processedItem.items\"\n [itemTemplate]=\"itemTemplate\"\n [menuId]=\"menuId\"\n [visible]=\"isItemActive(processedItem) && isItemGroup(processedItem)\"\n [activeItemPath]=\"activeItemPath\"\n [focusedItemId]=\"focusedItemId\"\n [level]=\"level + 1\"\n (itemClick)=\"itemClick.emit($event)\"\n (itemMouseEnter)=\"onItemMouseEnter($event)\"\n />\n </li>\n </ng-template>\n </ul>\n `,\n animations: [trigger('overlayAnimation', [transition(':enter', [style({ opacity: 0 })]), transition(':leave', [style({ opacity: 0 })])])],\n encapsulation: ViewEncapsulation.None\n})\nexport class ContextMenuSub extends BaseComponent {\n @Input({ transform: booleanAttribute }) visible: boolean = false;\n\n @Input() items: any[];\n\n @Input() itemTemplate: TemplateRef<any> | undefined;\n\n @Input({ transform: booleanAttribute }) root: boolean | undefined = false;\n\n @Input({ transform: booleanAttribute }) autoZIndex: boolean = true;\n\n @Input({ transform: numberAttribute }) baseZIndex: number = 0;\n\n @Input({ transform: booleanAttribute }) popup: boolean | undefined;\n\n @Input() menuId: string | undefined;\n\n @Input() ariaLabel: string | undefined;\n\n @Input() ariaLabelledBy: string | undefined;\n\n @Input({ transform: numberAttribute }) level: number = 0;\n\n @Input() focusedItemId: string | undefined;\n\n @Input() activeItemPath: any[];\n\n @Input({ transform: numberAttribute }) tabindex: number = 0;\n\n @Output() itemClick: EventEmitter<any> = new EventEmitter();\n\n @Output() itemMouseEnter: EventEmitter<any> = new EventEmitter();\n\n @Output() menuFocus: EventEmitter<any> = new EventEmitter();\n\n @Output() menuBlur: EventEmitter<any> = new EventEmitter();\n\n @Output() menuKeydown: EventEmitter<any> = new EventEmitter();\n\n @ViewChild('sublist') sublistViewChild: ElementRef;\n\n constructor(@Inject(forwardRef(() => ContextMenu)) public contextMenu: ContextMenu) {\n super();\n }\n\n getItemProp(processedItem: any, name: string, params: any | null = null) {\n return processedItem && processedItem.item ? resolve(processedItem.item[name], params) : undefined;\n }\n\n getItemId(processedItem: any): string {\n return processedItem.item && processedItem.item?.id ? processedItem.item.id : `${this.menuId}_${processedItem.key}`;\n }\n\n getItemKey(processedItem: any): string {\n return this.getItemId(processedItem);\n }\n\n getItemClass(processedItem: any) {\n return {\n ...this.getItemProp(processedItem, 'class'),\n 'p-contextmenu-item': true,\n 'p-contextmenu-item-active': this.isItemActive(processedItem),\n 'p-focus': this.isItemFocused(processedItem),\n 'p-disabled': this.isItemDisabled(processedItem)\n };\n }\n\n getItemLabel(processedItem: any): string {\n return this.getItemProp(processedItem, 'label');\n }\n\n getSeparatorItemClass(processedItem: any) {\n return {\n ...this.getItemProp(processedItem, 'class'),\n 'p-contextmenu-separator': true\n };\n }\n\n getAriaSetSize() {\n return this.items.filter((processedItem) => this.isItemVisible(processedItem) && !this.getItemProp(processedItem, 'separator')).length;\n }\n\n getAriaPosInset(index: number) {\n return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1;\n }\n\n isItemVisible(processedItem: any): boolean {\n return this.getItemProp(processedItem, 'visible') !== false;\n }\n\n isItemActive(processedItem: any): boolean {\n if (this.activeItemPath) {\n return this.activeItemPath.some((path) => path.key === processedItem.key);\n }\n }\n\n isItemDisabled(processedItem: any): boolean {\n return this.getItemProp(processedItem, 'disabled');\n }\n\n isItemFocused(processedItem: any): boolean {\n return this.focusedItemId === this.getItemId(processedItem);\n }\n\n isItemGroup(processedItem: any): boolean {\n return isNotEmpty(processedItem.items);\n }\n\n onItemMouseEnter(param: any) {\n const { event, processedItem } = param;\n this.itemMouseEnter.emit({ originalEvent: event, processedItem });\n }\n\n onItemClick(event: any, processedItem: any) {\n this.getItemProp(processedItem, 'command', { originalEvent: event, item: processedItem.item });\n this.itemClick.emit({ originalEvent: event, processedItem, isFocus: true });\n }\n\n onEnter(event, sublist) {\n if (event.fromState === 'void' && event.toState) {\n const sublist = event.element;\n this.position(sublist);\n }\n }\n\n position(sublist) {\n const parentItem = sublist.parentElement.parentElement;\n const containerOffset = <any>getOffset(sublist.parentElement.parentElement);\n const viewport = getViewport();\n const sublistWidth = sublist.offsetParent ? sublist.offsetWidth : getHiddenElementOuterWidth(sublist);\n const itemOuterWidth = <any>getOuterWidth(parentItem.children[0]);\n\n sublist.style.top = '0px';\n\n if (parseInt(containerOffset.left, 10) + itemOuterWidth + sublistWidth > viewport.width - calculateScrollbarWidth()) {\n sublist.style.left = -1 * sublistWidth + 'px';\n } else {\n sublist.style.left = itemOuterWidth + 'px';\n }\n }\n}\n/**\n * ContextMenu displays an overlay menu on right click of its target. Note that components like Table has special integration with ContextMenu.\n * @group Components\n */\n@Component({\n selector: 'p-contextMenu, p-contextmenu, p-context-menu',\n standalone: true,\n imports: [CommonModule, ContextMenuSub, RouterModule, TooltipModule, BadgeModule, SharedModule],\n template: `\n <div\n #container\n [attr.data-pc-section]=\"'root'\"\n [attr.data-pc-name]=\"'contextmenu'\"\n [attr.id]=\"id\"\n [ngClass]=\"{ 'p-contextmenu p-component': true, 'p-contextmenu-mobile': queryMatches }\"\n [class]=\"styleClass\"\n [ngStyle]=\"style\"\n [@overlayAnimation]=\"{ value: 'visible' }\"\n (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\"\n (@overlayAnimation.done)=\"onOverlayAnimationEnd($event)\"\n *ngIf=\"visible()\"\n >\n <p-contextmenu-sub\n #rootmenu\n [root]=\"true\"\n [items]=\"processedItems\"\n [itemTemplate]=\"itemTemplate || _itemTemplate\"\n [menuId]=\"id\"\n [tabindex]=\"!disabled ? tabindex : -1\"\n [ariaLabel]=\"ariaLabel\"\n [ariaLabelledBy]=\"ariaLabelledBy\"\n [baseZIndex]=\"baseZIndex\"\n [autoZIndex]=\"autoZIndex\"\n [visible]=\"submenuVisible()\"\n [focusedItemId]=\"focused ? focusedItemId : undefined\"\n [activeItemPath]=\"activeItemPath()\"\n (itemClick)=\"onItemClick($event)\"\n (menuFocus)=\"onMenuFocus($event)\"\n (menuBlur)=\"onMenuBlur($event)\"\n (menuKeydown)=\"onKeyDown($event)\"\n (itemMouseEnter)=\"onItemMouseEnter($event)\"\n />\n </div>\n `,\n animations: [trigger('overlayAnimation', [transition(':enter', [style({ opacity: 0 }), animate('250ms')]), transition(':leave', [animate('.1s linear', style({ opacity: 0 }))])])],\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n providers: [ContextMenuStyle]\n})\nexport class ContextMenu extends BaseComponent implements OnInit, AfterContentInit, OnDestroy {\n /**\n * An array of menuitems.\n * @group Props\n */\n @Input() set model(value: MenuItem[] | undefined) {\n this._model = value;\n this._processedItems = this.createProcessedItems(this._model || []);\n }\n get model(): MenuItem[] | undefined {\n return this._model;\n }\n /**\n * Event for which the menu must be displayed.\n * @group Props\n */\n @Input() triggerEvent: string = 'contextmenu';\n /**\n * Local template variable name of the element to attach the context menu.\n * @group Props\n */\n @Input() target: HTMLElement | string | undefined;\n /**\n * Attaches the menu to document instead of a particular item.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) global: boolean;\n /**\n * Inline style of the component.\n * @group Props\n */\n @Input() style: { [klass: string]: any } | null | undefined;\n /**\n * Style class of the component.\n * @group Props\n */\n @Input() styleClass: string | undefined;\n /**\n * Target element to attach the overlay, valid values are \"body\" or a local ng-template variable of another element.\n * @group Props\n */\n @Input() appendTo: HTMLElement | ElementRef | TemplateRef<any> | string | null | undefined | any;\n /**\n * Whether to automatically manage layering.\n * @group Props\n */\n @Input({ transform: booleanAttribute }) autoZIndex: boolean = true;\n /**\n * Base zIndex value to use in layering.\n * @group Props\n */\n @Input({ transform: numberAttribute }) baseZIndex: number = 0;\n /**\n * Current id state as a string.\n * @group Props\n */\n @Input() id: string | undefined;\n /**\n * The breakpoint to define the maximum width boundary.\n * @group Props\n */\n @Input() breakpoint: string = '960px';\n /**\n * Defines a string value that labels an interactive element.\n * @group Props\n */\n @Input() ariaLabel: string | undefined;\n /**\n * Identifier of the underlying input element.\n * @group Props\n */\n @Input() ariaLabelledBy: string | undefined;\n /**\n * Press delay in touch devices as miliseconds.\n * @group Props\n */\n @Input({ transform: numberAttribute }) pressDelay: number | undefined = 500;\n /**\n * Callback to invoke when overlay menu is shown.\n * @group Emits\n */\n @Output() onShow: EventEmitter<null> = new EventEmitter<null>();\n /**\n * Callback to invoke when overlay menu is hidden.\n * @group Emits\n */\n @Output() onHide: EventEmitter<null> = new EventEmitter<null>();\n\n @ViewChild('rootmenu') rootmenu: ContextMenuSub | undefined;\n\n @ViewChild('container') containerViewChild: ElementRef<any> | undefined;\n\n container: HTMLDivElement | undefined;\n\n outsideClickListener: VoidListener;\n\n resizeListener: VoidListener;\n\n triggerEventListener: VoidListener;\n\n documentClickListener: VoidListener;\n\n documentTriggerListener: VoidListener;\n\n touchEndListener: VoidListener;\n\n pageX: number;\n\n pageY: number;\n\n visible = signal(false);\n\n relativeAlign: boolean | undefined;\n\n private window: Window;\n\n focused: boolean = false;\n\n activeItemPath = signal<any>([]);\n\n focusedItemInfo = signal<any>({ index: -1, level: 0, parentKey: '', item: null });\n\n submenuVisible = signal<boolean>(false);\n\n searchValue: string = '';\n\n searchTimeout: any;\n\n _processedItems: any[];\n\n _model: MenuItem[] | undefined;\n\n pressTimer: any;\n\n private matchMediaListener: () => void;\n\n private query: MediaQueryList;\n\n public queryMatches: boolean;\n\n _componentStyle = inject(ContextMenuStyle);\n\n get visibleItems() {\n const processedItem = this.activeItemPath().find((p) => p.key === this.focusedItemInfo().parentKey);\n\n return processedItem ? processedItem.items : this.processedItems;\n }\n\n get processedItems() {\n if (!this._processedItems || !this._processedItems.length) {\n this._processedItems = this.createProcessedItems(this.model || []);\n }\n return this._processedItems;\n }\n\n get focusedItemId() {\n const focusedItem = this.focusedItemInfo();\n return focusedItem.item && focusedItem.item?.id ? focusedItem.item.id : focusedItem.index !== -1 ? `${this.id}${isNotEmpty(focusedItem.parentKey) ? '_' + focusedItem.parentKey : ''}_${focusedItem.index}` : null;\n }\n\n constructor(public overlayService: OverlayService) {\n super();\n effect(() => {\n const path = this.activeItemPath();\n\n if (isNotEmpty(path)) {\n this.bindGlobalListeners();\n } else if (!this.visible()) {\n this.unbindGlobalListeners();\n }\n });\n }\n\n ngOnInit() {\n super.ngOnInit();\n this.id = this.id || uuid('pn_id_');\n this.bindMatchMediaListener();\n this.bindTriggerEventListener();\n }\n\n isMobile() {\n return isIOS() || isAndroid();\n }\n\n bindTriggerEventListener() {\n if (isPlatformBrowser(this.platformId)) {\n if (!this.triggerEventListener) {\n if (!this.isMobile()) {\n if (this.global) {\n this.triggerEventListener = this.renderer.listen(this.document, this.triggerEvent, (event) => {\n this.show(event);\n });\n } else if (this.target) {\n this.triggerEventListener = this.renderer.listen(this.target, this.triggerEvent, (event) => {\n this.show(event);\n });\n }\n } else {\n if (this.global) {\n this.triggerEventListener = this.renderer.listen(this.document, 'touchstart', this.onTouchStart.bind(this));\n this.touchEndListener = this.renderer.listen(this.document, 'touchend', this.onTouchEnd.bind(this));\n } else if (this.target) {\n this.triggerEventListener = this.renderer.listen(this.target, 'touchstart', this.onTouchStart.bind(this));\n this.touchEndListener = this.renderer.listen(this.target, 'touchend', this.onTouchEnd.bind(this));\n }\n }\n }\n }\n }\n\n bindGlobalListeners() {\n if (isPlatformBrowser(this.platformId)) {\n if (!this.documentClickListener) {\n const documentTarget: any = this.el ? this.el.nativeElement.ownerDocument : 'document';\n\n this.documentClickListener = this.renderer.listen(documentTarget, 'click', (event) => {\n if (this.containerViewChild.nativeElement.offsetParent && this.isOutsideClicked(event) && !event.ctrlKey && event.button !== 2 && this.triggerEvent !== 'click') {\n this.hide();\n }\n });\n\n this.documentTriggerListener = this.renderer.listen(documentTarget, this.triggerEvent, (event) => {\n if (this.containerViewChild.nativeElement.offsetParent && this.isOutsideClicked(event)) {\n this.hide();\n }\n });\n }\n if (!this.resizeListener) {\n this.resizeListener = this.renderer.listen(this.document.defaultView, 'resize', (event) => {\n this.hide();\n });\n }\n }\n }\n /**\n * Defines template option for item.\n * @group Templates\n */\n @ContentChild('item', { descendants: false }) itemTemplate: TemplateRef<any> | undefined;\n\n /**\n * Defines template option for submenuIcon.\n * @group Templates\n */\n @ContentChild('submenuicon', { descendants: false }) submenuIconTemplate: TemplateRef<any> | undefined;\n\n @ContentChildren(PrimeTemplate) templates: QueryList<PrimeTemplate> | undefined;\n\n _submenuIconTemplate: TemplateRef<any> | undefined;\n\n _itemTemplate: TemplateRef<any> | undefined;\n\n ngAfterContentInit() {\n this.templates?.forEach((item) => {\n switch (item.getType()) {\n case 'submenuicon':\n this._submenuIconTemplate = item.template;\n break;\n case 'item':\n this._itemTemplate = item.template;\n break;\n default:\n this._itemTemplate = item.template;\n break;\n }\n });\n }\n\n createProcessedItems(items: any, level: number = 0, parent: any = {}, parentKey: any = '') {\n const processedItems = [];\n\n items &&\n items.forEach((item, index) => {\n const key = (parentKey !== '' ? parentKey + '_' : '') + index;\n const newItem = {\n item,\n index,\n level,\n key,\n parent,\n parentKey\n };\n\n newItem['items'] = this.createProcessedItems(item.items, level + 1, newItem, key);\n processedItems.push(newItem);\n });\n\n return processedItems;\n }\n\n bindMatchMediaListener() {\n if (isPlatformBrowser(this.platformId)) {\n if (!this.matchMediaListener) {\n const query = window.matchMedia(`(max-width: ${this.breakpoint})`);\n\n this.query = query;\n this.queryMatches = query.matches;\n\n this.matchMediaListener = () => {\n this.queryMatches = query.matches;\n };\n\n query.addEventListener('change', this.matchMediaListener);\n }\n }\n }\n\n unbindMatchMediaListener() {\n if (this.matchMediaListener) {\n this.query.removeEventListener('change', this.matchMediaListener);\n this.matchMediaListener = null;\n }\n }\n\n getItemProp(item: any, name: string) {\n return item ? resolve(item[name]) : undefined;\n }\n\n getProccessedItemLabel(processedItem: any) {\n return processedItem ? this.getItemLabel(processedItem.item) : undefined;\n }\n\n getItemLabel(item: any) {\n return this.getItemProp(item, 'label');\n }\n\n isProcessedItemGroup(processedItem: any): boolean {\n return processedItem && isNotEmpty(processedItem.items);\n }\n\n isSelected(processedItem: any): boolean {\n return this.activeItemPath().some((p) => p.key === processedItem.key);\n }\n\n isValidSelectedItem(processedItem: any): boolean {\n return this.isValidItem(processedItem) && this.isSelected(processedItem);\n }\n\n isValidItem(processedItem: any): boolean {\n return !!processedItem && !this.isItemDisabled(processedItem.item) && !this.isItemSeparator(processedItem.item);\n }\n\n isItemDisabled(item: any): boolean {\n return this.getItemProp(item, 'disabled');\n }\n\n isItemSeparator(item: any): boolean {\n return this.getItemProp(item, 'separator');\n }\n\n isItemMatched(processedItem: any): boolean {\n return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem).toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());\n }\n\n isProccessedItemGroup(processedItem: any): boolean {\n return processedItem && isNotEmpty(processedItem.items);\n }\n\n onItemClick(event: any) {\n const { processedItem } = event;\n const grouped = this.isProcessedItemGroup(processedItem);\n const selected = this.isSelected(processedItem);\n\n if (selected) {\n const { index, key, level, parentKey, item } = processedItem;\n\n this.activeItemPath.set(this.activeItemPath().filter((p) => key !== p.key && key.startsWith(p.key)));\n this.focusedItemInfo.set({ index, level, parentKey, item });\n\n focus(this.rootmenu.sublistViewChild.nativeElement);\n } else {\n grouped ? this.onItemChange(event) : this.hide();\n }\n }\n\n onItemMouseEnter(event: any) {\n this.onItemChange(event, 'hover');\n }\n\n onKeyDown(event: KeyboardEvent) {\n const metaKey = event.metaKey || event.ctrlKey;\n\n switch (event.code) {\n case 'ArrowDown':\n this.onArrowDownKey(event);\n break;\n\n case 'ArrowUp':\n this.onArrowUpKey(event);\n break;\n\n case 'ArrowLeft':\n this.onArrowLeftKey(event);\n break;\n\n case 'ArrowRight':\n this.onArrowRightKey(event);\n break;\n\n case 'Home':\n this.onHomeKey(event);\n break;\n\n case 'End':\n this.onEndKey(event);\n break;\n\n case 'Space':\n this.onSpaceKey(event);\n break;\n\n case 'Enter':\n this.onEnterKey(event);\n break;\n\n case 'Escape':\n this.onEscapeKey(event);\n break;\n\n case 'Tab':\n this.onTabKey(event);\n break;\n\n case 'PageDown':\n case 'PageUp':\n case 'Backspace':\n case 'ShiftLeft':\n case 'ShiftRight':\n //NOOP\n break;\n\n default:\n if (!metaKey && isPrintableCharacter(event.key)) {\n this.searchItems(event, event.key);\n }\n\n break;\n }\n }\n\n onArrowDownKey(event: KeyboardEvent) {\n const itemIndex = this.focusedItemInfo().index !== -1 ? this.findNextItemIndex(this.focusedItemInfo().index) : this.findFirstFocusedItemIndex();\n\n this.changeFocusedItemIndex(event, itemIndex);\n event.preventDefault();\n }\n\n onArrowRightKey(event: KeyboardEvent) {\n const processedItem = this.visibleItems[this.focusedItemInfo().index];\n const grouped = this.isProccessedItemGroup(processedItem);\n\n if (grouped) {\n this.onItemChange({ originalEvent: event, processedItem });\n this.focusedItemInfo.set({ index: -1, parentKey: processedItem.key, item: processedItem.item });\n this.searchValue = '';\n this.onArrowDownKey(event);\n }\n\n event.preventDefault();\n }\n\n onArrowUpKey(event: KeyboardEvent) {\n if (event.altKey) {\n if (this.focusedItemInfo().index !== -1) {\n const processedItem = this.visibleItems[this.focusedItemInfo().index];\n const grouped = this.isProccessedItemGroup(processedItem);\n\n !grouped && this.onItemChange({ originalEvent: event, processedItem });\n }\n\n this.hide();\n event.preventDefault();\n } else {\n const itemIndex = this.focusedItemInfo().index !== -1 ? this.findPrevItemIndex(this.focusedItemInfo().index) : this.findLastFocusedItemIndex();\n\n this.changeFocusedItemIndex(event, itemIndex);\n event.preventDefault();\n }\n }\n\n onArrowLeftKey(event: KeyboardEvent) {\n const processedItem = this.visibleItems[this.focusedItemInfo().index];\n const parentItem = this.activeItemPath().find((p) => p.key === processedItem.parentKey);\n const root = isEmpty(processedItem.parent);\n\n if (!root) {\n this.focusedItemInfo.set({ index: -1, parentKey: parentItem ? parentItem.parentKey : '', item: processedItem.item });\n this.searchValue = '';\n this.onArrowDownKey(event);\n }\n\n const activeItemPath = this.activeItemPath().filter((p) => p.parentKey !== this.focusedItemInfo().parentKey);\n this.activeItemPath.set(activeItemPath);\n\n event.preventDefault();\n }\n\n onHomeKey(event: KeyboardEvent) {\n this.changeFocusedItemIndex(event, this.findFirstItemIndex());\n event.preventDefault();\n }\n\n onEndKey(event: KeyboardEvent) {\n this.changeFocusedItemIndex(event, this.findLastItemIndex());\n event.preventDefault();\n }\n\n onSpaceKey(event: KeyboardEvent) {\n this.onEnterKey(event);\n }\n\n onEscapeKey(event: KeyboardEvent) {\n this.hide();\n const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex());\n const focusedItemInfo = this.focusedItemInfo();\n this.focusedItemInfo.set({ ...focusedItemInfo, index: this.findFirstFocusedItemIndex(), item: processedItem.item });\n\n event.preventDefault();\n }\n\n onTabKey(event: KeyboardEvent) {\n if (this.focusedItemInfo().index !== -1) {\n const processedItem = this.visibleItems[this.focusedItemInfo().index];\n const grouped = this.isProccessedItemGroup(processedItem);\n\n !grouped && this.onItemChange({ originalEvent: event, processedItem });\n }\n\n this.hide();\n }\n\n onEnterKey(event: KeyboardEvent) {\n if (this.focusedItemInfo().index !== -1) {\n const element = <any>findSingle(this.rootmenu.el.nativeElement, `li[id=\"${`${this.focusedItemId}`}\"]`);\n const anchorElement = element && <any>findSingle(element, 'a[data-pc-section=\"action\"]');\n\n anchorElement ? anchorElement.click() : element && element.click();\n\n const processedItem = this.visibleItems[this.focusedItemInfo().index];\n const grouped = this.isProccessedItemGroup(processedItem);\n\n if (!grouped) {\n const focusedItemInfo = this.focusedItemInfo();\n this.focusedItemInfo.set({ ...focusedItemInfo, index: this.findFirstFocusedItemIndex() });\n }\n }\n\n event.preventDefault();\n }\n\n onItemChange(event: any, type?: string | undefined) {\n const { processedItem, isFocus } = event;\n if (isEmpty(processedItem)) return;\n\n const { index, key, level, parentKey, items } = processedItem;\n const grouped = isNotEmpty(items);\n const activeItemPath = this.activeItemPath().filter((p) => p.parentKey !== parentKey && p.parentKey !== key);\n\n if (grouped) {\n activeItemPath.push(processedItem);\n this.submenuVisible.set(true);\n }\n this.focusedItemInfo.set({ index, level, parentKey, item: processedItem.item });\n isFocus && focus(this.rootmenu.sublistViewChild.nativeElement);\n\n if (type === 'hover' && this.queryMatches) {\n return;\n }\n\n this.activeItemPath.set(activeItemPath);\n }\n\n onMenuFocus(event: any) {\n this.focused = true;\n const focusedItemInfo = this.focusedItemInfo().index !== -1 ? this.focusedItemInfo() : { index: -1, level: 0, parentKey: '', item: null };\n\n this.focusedItemInfo.set(focusedItemInfo);\n }\n\n onMenuBlur(event: any) {\n this.focused = false;\n this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null });\n this.searchValue = '';\n }\n\n onOverlayAnimationStart(event: AnimationEvent) {\n switch (event.toState) {\n case 'visible':\n this.container = event.element;\n this.position();\n this.moveOnTop();\n this.appendOverlay();\n this.bindGlobalListeners();\n focus(this.rootmenu.sublistViewChild.nativeElement);\n break;\n }\n }\n\n onOverlayAnimationEnd(event: AnimationEvent) {\n switch (event.toState) {\n case 'void':\n this.onOverlayHide();\n break;\n }\n }\n\n appendOverlay() {\n if (this.appendTo) {\n if (this.appendTo === 'body') this.renderer.appendChild(this.document.body, this.containerViewChild.nativeElement);\n else appendChild(this.appendTo, this.containerViewChild.nativeElement);\n }\n }\n\n moveOnTop() {\n if (this.autoZIndex && this.containerViewChild) {\n ZIndexUtils.set('menu', this.containerViewChild.nativeElement, this.baseZIndex + this.config.zIndex.menu);\n }\n }\n\n onOverlayHide() {\n this.unbindGlobalListeners();\n\n if (!(this.cd as ViewRef).destroyed) {\n this.target = null;\n }\n\n if (this.container && this.autoZIndex) {\n ZIndexUtils.clear(this.container);\n }\n\n this.container = null;\n }\n\n onTouchStart(event: MouseEvent) {\n this.pressTimer = setTimeout(() => {\n this.show(event);\n }, this.pressDelay);\n }\n\n onTouchEnd() {\n clearTimeout(this.pressTimer);\n }\n\n hide() {\n this.visible.set(false);\n this.onHide.emit();\n this.activeItemPath.set([]);\n this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null });\n }\n\n toggle(event?: any) {\n this.visible() ? this.hide() : this.show(event);\n }\n\n show(event: any) {\n this.activeItemPath.set([]);\n this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null });\n\n this.pageX = event.pageX;\n this.pageY = event.pageY;\n\n this.onShow.emit();\n this.visible() ? this.position() : this.visible.set(true);\n\n event.stopPropagation();\n event.preventDefault();\n }\n\n position() {\n let left = this.pageX + 1;\n let top = this.pageY + 1;\n let width = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetWidth : getHiddenElementOuterWidth(this.containerViewChild.nativeElement);\n let height = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetHeight : getHidd