[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { EventEmitter, forwardRef, Component, ViewEncapsulation, Inject, Input, Output, ViewChild, ChangeDetectionStrategy, NgModule } from '@angular/core';
|
---|
| 3 | import * as i1 from '@angular/common';
|
---|
| 4 | import { CommonModule } from '@angular/common';
|
---|
| 5 | import { DomHandler } from 'primeng/dom';
|
---|
| 6 | import * as i5 from 'primeng/api';
|
---|
| 7 | import { ContextMenuService } from 'primeng/api';
|
---|
| 8 | import * as i3 from 'primeng/ripple';
|
---|
| 9 | import { RippleModule } from 'primeng/ripple';
|
---|
| 10 | import { ZIndexUtils } from 'primeng/utils';
|
---|
| 11 | import * as i4 from '@angular/router';
|
---|
| 12 | import { RouterModule } from '@angular/router';
|
---|
| 13 | import { Subject } from 'rxjs';
|
---|
| 14 | import { takeUntil } from 'rxjs/operators';
|
---|
| 15 | import * as i2 from 'primeng/tooltip';
|
---|
| 16 | import { TooltipModule } from 'primeng/tooltip';
|
---|
| 17 |
|
---|
| 18 | class ContextMenuSub {
|
---|
| 19 | constructor(contextMenu) {
|
---|
| 20 | this.leafClick = new EventEmitter();
|
---|
| 21 | this.contextMenu = contextMenu;
|
---|
| 22 | }
|
---|
| 23 | ngOnInit() {
|
---|
| 24 | this.activeItemKeyChangeSubscription = this.contextMenu.contextMenuService.activeItemKeyChange$.pipe(takeUntil(this.contextMenu.ngDestroy$)).subscribe((activeItemKey) => {
|
---|
| 25 | this.activeItemKey = activeItemKey;
|
---|
| 26 | if (this.isActive(this.parentItemKey) && DomHandler.hasClass(this.sublistViewChild.nativeElement, 'p-submenu-list-active')) {
|
---|
| 27 | this.contextMenu.positionSubmenu(this.sublistViewChild.nativeElement);
|
---|
| 28 | }
|
---|
| 29 | this.contextMenu.cd.markForCheck();
|
---|
| 30 | });
|
---|
| 31 | }
|
---|
| 32 | onItemMouseEnter(event, item, key) {
|
---|
| 33 | if (this.hideTimeout) {
|
---|
| 34 | clearTimeout(this.hideTimeout);
|
---|
| 35 | this.hideTimeout = null;
|
---|
| 36 | }
|
---|
| 37 | if (item.disabled) {
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 | if (item.items) {
|
---|
| 41 | let childSublist = DomHandler.findSingle(event.currentTarget, '.p-submenu-list');
|
---|
| 42 | DomHandler.addClass(childSublist, 'p-submenu-list-active');
|
---|
| 43 | }
|
---|
| 44 | this.contextMenu.contextMenuService.changeKey(key);
|
---|
| 45 | }
|
---|
| 46 | onItemMouseLeave(event, item) {
|
---|
| 47 | if (item.disabled) {
|
---|
| 48 | return;
|
---|
| 49 | }
|
---|
| 50 | if (this.contextMenu.el.nativeElement.contains(event.toElement)) {
|
---|
| 51 | if (item.items) {
|
---|
| 52 | this.contextMenu.removeActiveFromSubLists(event.currentTarget);
|
---|
| 53 | }
|
---|
| 54 | if (!this.root) {
|
---|
| 55 | this.contextMenu.contextMenuService.changeKey(this.parentItemKey);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | onItemClick(event, item, menuitem, key) {
|
---|
| 60 | if (item.disabled) {
|
---|
| 61 | event.preventDefault();
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
| 64 | if (!item.url && !item.routerLink) {
|
---|
| 65 | event.preventDefault();
|
---|
| 66 | }
|
---|
| 67 | if (item.command) {
|
---|
| 68 | item.command({
|
---|
| 69 | originalEvent: event,
|
---|
| 70 | item: item
|
---|
| 71 | });
|
---|
| 72 | }
|
---|
| 73 | if (item.items) {
|
---|
| 74 | let childSublist = DomHandler.findSingle(menuitem, '.p-submenu-list');
|
---|
| 75 | if (childSublist) {
|
---|
| 76 | if (this.isActive(key) && DomHandler.hasClass(childSublist, 'p-submenu-list-active')) {
|
---|
| 77 | this.contextMenu.removeActiveFromSubLists(menuitem);
|
---|
| 78 | }
|
---|
| 79 | else {
|
---|
| 80 | DomHandler.addClass(childSublist, 'p-submenu-list-active');
|
---|
| 81 | }
|
---|
| 82 | this.contextMenu.contextMenuService.changeKey(key);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | if (!item.items) {
|
---|
| 86 | this.onLeafClick();
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | onLeafClick() {
|
---|
| 90 | if (this.root) {
|
---|
| 91 | this.contextMenu.hide();
|
---|
| 92 | }
|
---|
| 93 | this.leafClick.emit();
|
---|
| 94 | }
|
---|
| 95 | getKey(index) {
|
---|
| 96 | return this.root ? String(index) : this.parentItemKey + '_' + index;
|
---|
| 97 | }
|
---|
| 98 | isActive(key) {
|
---|
| 99 | return (this.activeItemKey && (this.activeItemKey.startsWith(key + '_') || this.activeItemKey === key));
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | ContextMenuSub.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuSub, deps: [{ token: forwardRef(() => ContextMenu) }], target: i0.ɵɵFactoryTarget.Component });
|
---|
| 103 | ContextMenuSub.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: ContextMenuSub, selector: "p-contextMenuSub", inputs: { item: "item", root: "root", parentItemKey: "parentItemKey" }, outputs: { leafClick: "leafClick" }, host: { classAttribute: "p-element" }, viewQueries: [{ propertyName: "sublistViewChild", first: true, predicate: ["sublist"], descendants: true }, { propertyName: "menuitemViewChild", first: true, predicate: ["menuitem"], descendants: true }], ngImport: i0, template: `
|
---|
| 104 | <ul #sublist [ngClass]="{'p-submenu-list':!root}">
|
---|
| 105 | <ng-template ngFor let-child let-index="index" [ngForOf]="(root ? item : item.items)">
|
---|
| 106 | <li *ngIf="child.separator" #menuitem class="p-menu-separator" [ngClass]="{'p-hidden': child.visible === false}" role="separator">
|
---|
| 107 | <li *ngIf="!child.separator" #menuitem [ngClass]="{'p-menuitem':true,'p-menuitem-active': isActive(getKey(index)),'p-hidden': child.visible === false}" [ngStyle]="child.style" [class]="child.styleClass" pTooltip [tooltipOptions]="child.tooltipOptions"
|
---|
| 108 | (mouseenter)="onItemMouseEnter($event,child,getKey(index))" (mouseleave)="onItemMouseLeave($event,child)" role="none" [attr.data-ik]="getKey(index)">
|
---|
| 109 | <a *ngIf="!child.routerLink" [attr.href]="child.url ? child.url : null" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id"
|
---|
| 110 | [attr.tabindex]="child.disabled ? null : '0'" (click)="onItemClick($event, child, menuitem, getKey(index))" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" pRipple
|
---|
| 111 | [attr.aria-haspopup]="item.items != null" [attr.aria-expanded]="isActive(getKey(index))">
|
---|
| 112 | <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
---|
| 113 | <span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlLabel">{{child.label}}</span>
|
---|
| 114 | <ng-template #htmlLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
|
---|
| 115 | <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span>
|
---|
| 116 | </a>
|
---|
| 117 | <a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" role="menuitem"
|
---|
| 118 | [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'"
|
---|
| 119 | (click)="onItemClick($event, child, menuitem, getKey(index))" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}"
|
---|
| 120 | pRipple [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state">
|
---|
| 121 | <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
---|
| 122 | <span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlRouteLabel">{{child.label}}</span>
|
---|
| 123 | <ng-template #htmlRouteLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
|
---|
| 124 | <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span>
|
---|
| 125 | </a>
|
---|
| 126 | <p-contextMenuSub [parentItemKey]="getKey(index)" [item]="child" *ngIf="child.items" (leafClick)="onLeafClick()"></p-contextMenuSub>
|
---|
| 127 | </li>
|
---|
| 128 | </ng-template>
|
---|
| 129 | </ul>
|
---|
| 130 | `, isInline: true, components: [{ type: ContextMenuSub, selector: "p-contextMenuSub", inputs: ["item", "root", "parentItemKey"], outputs: ["leafClick"] }], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "appendTo", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "pTooltip", "tooltipDisabled", "tooltipOptions"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i3.Ripple, selector: "[pRipple]" }, { type: i4.RouterLinkWithHref, selector: "a[routerLink],area[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "preserveFragment", "skipLocationChange", "replaceUrl", "state", "relativeTo", "routerLink"] }, { type: i4.RouterLinkActive, selector: "[routerLinkActive]", inputs: ["routerLinkActiveOptions", "routerLinkActive"], outputs: ["isActiveChange"], exportAs: ["routerLinkActive"] }], encapsulation: i0.ViewEncapsulation.None });
|
---|
| 131 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuSub, decorators: [{
|
---|
| 132 | type: Component,
|
---|
| 133 | args: [{
|
---|
| 134 | selector: 'p-contextMenuSub',
|
---|
| 135 | template: `
|
---|
| 136 | <ul #sublist [ngClass]="{'p-submenu-list':!root}">
|
---|
| 137 | <ng-template ngFor let-child let-index="index" [ngForOf]="(root ? item : item.items)">
|
---|
| 138 | <li *ngIf="child.separator" #menuitem class="p-menu-separator" [ngClass]="{'p-hidden': child.visible === false}" role="separator">
|
---|
| 139 | <li *ngIf="!child.separator" #menuitem [ngClass]="{'p-menuitem':true,'p-menuitem-active': isActive(getKey(index)),'p-hidden': child.visible === false}" [ngStyle]="child.style" [class]="child.styleClass" pTooltip [tooltipOptions]="child.tooltipOptions"
|
---|
| 140 | (mouseenter)="onItemMouseEnter($event,child,getKey(index))" (mouseleave)="onItemMouseLeave($event,child)" role="none" [attr.data-ik]="getKey(index)">
|
---|
| 141 | <a *ngIf="!child.routerLink" [attr.href]="child.url ? child.url : null" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id"
|
---|
| 142 | [attr.tabindex]="child.disabled ? null : '0'" (click)="onItemClick($event, child, menuitem, getKey(index))" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}" pRipple
|
---|
| 143 | [attr.aria-haspopup]="item.items != null" [attr.aria-expanded]="isActive(getKey(index))">
|
---|
| 144 | <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
---|
| 145 | <span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlLabel">{{child.label}}</span>
|
---|
| 146 | <ng-template #htmlLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
|
---|
| 147 | <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span>
|
---|
| 148 | </a>
|
---|
| 149 | <a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'" role="menuitem"
|
---|
| 150 | [routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'"
|
---|
| 151 | (click)="onItemClick($event, child, menuitem, getKey(index))" [ngClass]="{'p-menuitem-link':true,'p-disabled':child.disabled}"
|
---|
| 152 | pRipple [fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state">
|
---|
| 153 | <span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
---|
| 154 | <span class="p-menuitem-text" *ngIf="child.escape !== false; else htmlRouteLabel">{{child.label}}</span>
|
---|
| 155 | <ng-template #htmlRouteLabel><span class="p-menuitem-text" [innerHTML]="child.label"></span></ng-template>
|
---|
| 156 | <span class="p-submenu-icon pi pi-angle-right" *ngIf="child.items"></span>
|
---|
| 157 | </a>
|
---|
| 158 | <p-contextMenuSub [parentItemKey]="getKey(index)" [item]="child" *ngIf="child.items" (leafClick)="onLeafClick()"></p-contextMenuSub>
|
---|
| 159 | </li>
|
---|
| 160 | </ng-template>
|
---|
| 161 | </ul>
|
---|
| 162 | `,
|
---|
| 163 | encapsulation: ViewEncapsulation.None,
|
---|
| 164 | host: {
|
---|
| 165 | 'class': 'p-element'
|
---|
| 166 | }
|
---|
| 167 | }]
|
---|
| 168 | }], ctorParameters: function () {
|
---|
| 169 | return [{ type: undefined, decorators: [{
|
---|
| 170 | type: Inject,
|
---|
| 171 | args: [forwardRef(() => ContextMenu)]
|
---|
| 172 | }] }];
|
---|
| 173 | }, propDecorators: { item: [{
|
---|
| 174 | type: Input
|
---|
| 175 | }], root: [{
|
---|
| 176 | type: Input
|
---|
| 177 | }], parentItemKey: [{
|
---|
| 178 | type: Input
|
---|
| 179 | }], leafClick: [{
|
---|
| 180 | type: Output
|
---|
| 181 | }], sublistViewChild: [{
|
---|
| 182 | type: ViewChild,
|
---|
| 183 | args: ['sublist']
|
---|
| 184 | }], menuitemViewChild: [{
|
---|
| 185 | type: ViewChild,
|
---|
| 186 | args: ['menuitem']
|
---|
| 187 | }] } });
|
---|
| 188 | class ContextMenu {
|
---|
| 189 | constructor(el, renderer, cd, zone, contextMenuService, config) {
|
---|
| 190 | this.el = el;
|
---|
| 191 | this.renderer = renderer;
|
---|
| 192 | this.cd = cd;
|
---|
| 193 | this.zone = zone;
|
---|
| 194 | this.contextMenuService = contextMenuService;
|
---|
| 195 | this.config = config;
|
---|
| 196 | this.autoZIndex = true;
|
---|
| 197 | this.baseZIndex = 0;
|
---|
| 198 | this.triggerEvent = 'contextmenu';
|
---|
| 199 | this.onShow = new EventEmitter();
|
---|
| 200 | this.onHide = new EventEmitter();
|
---|
| 201 | this.ngDestroy$ = new Subject();
|
---|
| 202 | }
|
---|
| 203 | ngAfterViewInit() {
|
---|
| 204 | if (this.global) {
|
---|
| 205 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 206 | this.triggerEventListener = this.renderer.listen(documentTarget, this.triggerEvent, (event) => {
|
---|
| 207 | this.show(event);
|
---|
| 208 | event.preventDefault();
|
---|
| 209 | });
|
---|
| 210 | }
|
---|
| 211 | else if (this.target) {
|
---|
| 212 | this.triggerEventListener = this.renderer.listen(this.target, this.triggerEvent, (event) => {
|
---|
| 213 | this.show(event);
|
---|
| 214 | event.preventDefault();
|
---|
| 215 | event.stopPropagation();
|
---|
| 216 | });
|
---|
| 217 | }
|
---|
| 218 | if (this.appendTo) {
|
---|
| 219 | if (this.appendTo === 'body')
|
---|
| 220 | document.body.appendChild(this.containerViewChild.nativeElement);
|
---|
| 221 | else
|
---|
| 222 | DomHandler.appendChild(this.containerViewChild.nativeElement, this.appendTo);
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | show(event) {
|
---|
| 226 | this.clearActiveItem();
|
---|
| 227 | this.position(event);
|
---|
| 228 | this.moveOnTop();
|
---|
| 229 | this.containerViewChild.nativeElement.style.display = 'block';
|
---|
| 230 | DomHandler.fadeIn(this.containerViewChild.nativeElement, 250);
|
---|
| 231 | this.bindGlobalListeners();
|
---|
| 232 | if (event) {
|
---|
| 233 | event.preventDefault();
|
---|
| 234 | }
|
---|
| 235 | this.onShow.emit();
|
---|
| 236 | }
|
---|
| 237 | hide() {
|
---|
| 238 | this.containerViewChild.nativeElement.style.display = 'none';
|
---|
| 239 | if (this.autoZIndex) {
|
---|
| 240 | ZIndexUtils.clear(this.containerViewChild.nativeElement);
|
---|
| 241 | }
|
---|
| 242 | this.unbindGlobalListeners();
|
---|
| 243 | this.onHide.emit();
|
---|
| 244 | }
|
---|
| 245 | moveOnTop() {
|
---|
| 246 | if (this.autoZIndex && this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'block') {
|
---|
| 247 | ZIndexUtils.set('menu', this.containerViewChild.nativeElement, this.baseZIndex + this.config.zIndex.menu);
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 | toggle(event) {
|
---|
| 251 | if (this.containerViewChild.nativeElement.offsetParent)
|
---|
| 252 | this.hide();
|
---|
| 253 | else
|
---|
| 254 | this.show(event);
|
---|
| 255 | }
|
---|
| 256 | position(event) {
|
---|
| 257 | if (event) {
|
---|
| 258 | let left = event.pageX + 1;
|
---|
| 259 | let top = event.pageY + 1;
|
---|
| 260 | let width = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetWidth : DomHandler.getHiddenElementOuterWidth(this.containerViewChild.nativeElement);
|
---|
| 261 | let height = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetHeight : DomHandler.getHiddenElementOuterHeight(this.containerViewChild.nativeElement);
|
---|
| 262 | let viewport = DomHandler.getViewport();
|
---|
| 263 | //flip
|
---|
| 264 | if (left + width - document.body.scrollLeft > viewport.width) {
|
---|
| 265 | left -= width;
|
---|
| 266 | }
|
---|
| 267 | //flip
|
---|
| 268 | if (top + height - document.body.scrollTop > viewport.height) {
|
---|
| 269 | top -= height;
|
---|
| 270 | }
|
---|
| 271 | //fit
|
---|
| 272 | if (left < document.body.scrollLeft) {
|
---|
| 273 | left = document.body.scrollLeft;
|
---|
| 274 | }
|
---|
| 275 | //fit
|
---|
| 276 | if (top < document.body.scrollTop) {
|
---|
| 277 | top = document.body.scrollTop;
|
---|
| 278 | }
|
---|
| 279 | this.containerViewChild.nativeElement.style.left = left + 'px';
|
---|
| 280 | this.containerViewChild.nativeElement.style.top = top + 'px';
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 | positionSubmenu(sublist) {
|
---|
| 284 | let parentMenuItem = sublist.parentElement.parentElement;
|
---|
| 285 | let viewport = DomHandler.getViewport();
|
---|
| 286 | let sublistWidth = sublist.offsetParent ? sublist.offsetWidth : DomHandler.getHiddenElementOuterWidth(sublist);
|
---|
| 287 | let sublistHeight = sublist.offsetHeight ? sublist.offsetHeight : DomHandler.getHiddenElementOuterHeight(sublist);
|
---|
| 288 | let itemOuterWidth = DomHandler.getOuterWidth(parentMenuItem.children[0]);
|
---|
| 289 | let itemOuterHeight = DomHandler.getOuterHeight(parentMenuItem.children[0]);
|
---|
| 290 | let containerOffset = DomHandler.getOffset(parentMenuItem.parentElement);
|
---|
| 291 | sublist.style.zIndex = ++DomHandler.zindex;
|
---|
| 292 | if ((parseInt(containerOffset.top) + itemOuterHeight + sublistHeight) > (viewport.height - DomHandler.calculateScrollbarHeight())) {
|
---|
| 293 | sublist.style.removeProperty('top');
|
---|
| 294 | sublist.style.bottom = '0px';
|
---|
| 295 | }
|
---|
| 296 | else {
|
---|
| 297 | sublist.style.removeProperty('bottom');
|
---|
| 298 | sublist.style.top = '0px';
|
---|
| 299 | }
|
---|
| 300 | if ((parseInt(containerOffset.left) + itemOuterWidth + sublistWidth) > (viewport.width - DomHandler.calculateScrollbarWidth())) {
|
---|
| 301 | sublist.style.left = -sublistWidth + 'px';
|
---|
| 302 | }
|
---|
| 303 | else {
|
---|
| 304 | sublist.style.left = itemOuterWidth + 'px';
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | isItemMatched(menuitem) {
|
---|
| 308 | return DomHandler.hasClass(menuitem, 'p-menuitem') && !DomHandler.hasClass(menuitem.children[0], 'p-disabled');
|
---|
| 309 | }
|
---|
| 310 | findNextItem(menuitem, isRepeated) {
|
---|
| 311 | let nextMenuitem = menuitem.nextElementSibling;
|
---|
| 312 | if (nextMenuitem) {
|
---|
| 313 | return this.isItemMatched(nextMenuitem) ? nextMenuitem : this.findNextItem(nextMenuitem, isRepeated);
|
---|
| 314 | }
|
---|
| 315 | else {
|
---|
| 316 | let firstItem = menuitem.parentElement.children[0];
|
---|
| 317 | return this.isItemMatched(firstItem) ? firstItem : (!isRepeated ? this.findNextItem(firstItem, true) : null);
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 | findPrevItem(menuitem, isRepeated) {
|
---|
| 321 | let prevMenuitem = menuitem.previousElementSibling;
|
---|
| 322 | if (prevMenuitem) {
|
---|
| 323 | return this.isItemMatched(prevMenuitem) ? prevMenuitem : this.findPrevItem(prevMenuitem, isRepeated);
|
---|
| 324 | }
|
---|
| 325 | else {
|
---|
| 326 | let lastItem = menuitem.parentElement.children[menuitem.parentElement.children.length - 1];
|
---|
| 327 | return this.isItemMatched(lastItem) ? lastItem : (!isRepeated ? this.findPrevItem(lastItem, true) : null);
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 | getActiveItem() {
|
---|
| 331 | let activeItemKey = this.contextMenuService.activeItemKey;
|
---|
| 332 | return activeItemKey == null ? null : DomHandler.findSingle(this.containerViewChild.nativeElement, '.p-menuitem[data-ik="' + activeItemKey + '"]');
|
---|
| 333 | }
|
---|
| 334 | clearActiveItem() {
|
---|
| 335 | if (this.contextMenuService.activeItemKey) {
|
---|
| 336 | this.removeActiveFromSubLists(this.containerViewChild.nativeElement);
|
---|
| 337 | this.contextMenuService.reset();
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
| 340 | removeActiveFromSubLists(el) {
|
---|
| 341 | let sublists = DomHandler.find(el, '.p-submenu-list-active');
|
---|
| 342 | for (let sublist of sublists) {
|
---|
| 343 | DomHandler.removeClass(sublist, 'p-submenu-list-active');
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 | removeActiveFromSublist(menuitem) {
|
---|
| 347 | if (menuitem) {
|
---|
| 348 | let sublist = DomHandler.findSingle(menuitem, '.p-submenu-list');
|
---|
| 349 | if (sublist && DomHandler.hasClass(menuitem, 'p-submenu-list-active')) {
|
---|
| 350 | DomHandler.removeClass(menuitem, 'p-submenu-list-active');
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | bindGlobalListeners() {
|
---|
| 355 | if (!this.documentClickListener) {
|
---|
| 356 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 357 | this.documentClickListener = this.renderer.listen(documentTarget, 'click', (event) => {
|
---|
| 358 | if (this.containerViewChild.nativeElement.offsetParent && this.isOutsideClicked(event) && !event.ctrlKey && event.button !== 2) {
|
---|
| 359 | this.hide();
|
---|
| 360 | }
|
---|
| 361 | });
|
---|
| 362 | }
|
---|
| 363 | this.zone.runOutsideAngular(() => {
|
---|
| 364 | if (!this.windowResizeListener) {
|
---|
| 365 | this.windowResizeListener = this.onWindowResize.bind(this);
|
---|
| 366 | window.addEventListener('resize', this.windowResizeListener);
|
---|
| 367 | }
|
---|
| 368 | });
|
---|
| 369 | if (!this.documentKeydownListener) {
|
---|
| 370 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 371 | this.documentKeydownListener = this.renderer.listen(documentTarget, 'keydown', (event) => {
|
---|
| 372 | let activeItem = this.getActiveItem();
|
---|
| 373 | switch (event.key) {
|
---|
| 374 | case 'ArrowDown':
|
---|
| 375 | if (activeItem) {
|
---|
| 376 | this.removeActiveFromSublist(activeItem);
|
---|
| 377 | activeItem = this.findNextItem(activeItem);
|
---|
| 378 | }
|
---|
| 379 | else {
|
---|
| 380 | let firstItem = DomHandler.findSingle(this.containerViewChild.nativeElement, '.p-menuitem-link').parentElement;
|
---|
| 381 | activeItem = this.isItemMatched(firstItem) ? firstItem : this.findNextItem(firstItem);
|
---|
| 382 | }
|
---|
| 383 | if (activeItem) {
|
---|
| 384 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 385 | }
|
---|
| 386 | event.preventDefault();
|
---|
| 387 | break;
|
---|
| 388 | case 'ArrowUp':
|
---|
| 389 | if (activeItem) {
|
---|
| 390 | this.removeActiveFromSublist(activeItem);
|
---|
| 391 | activeItem = this.findPrevItem(activeItem);
|
---|
| 392 | }
|
---|
| 393 | else {
|
---|
| 394 | let sublist = DomHandler.findSingle(this.containerViewChild.nativeElement, 'ul');
|
---|
| 395 | let lastItem = sublist.children[sublist.children.length - 1];
|
---|
| 396 | activeItem = this.isItemMatched(lastItem) ? lastItem : this.findPrevItem(lastItem);
|
---|
| 397 | }
|
---|
| 398 | if (activeItem) {
|
---|
| 399 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 400 | }
|
---|
| 401 | event.preventDefault();
|
---|
| 402 | break;
|
---|
| 403 | case 'ArrowRight':
|
---|
| 404 | if (activeItem) {
|
---|
| 405 | let sublist = DomHandler.findSingle(activeItem, '.p-submenu-list');
|
---|
| 406 | if (sublist) {
|
---|
| 407 | DomHandler.addClass(sublist, 'p-submenu-list-active');
|
---|
| 408 | activeItem = DomHandler.findSingle(sublist, '.p-menuitem-link:not(.p-disabled)').parentElement;
|
---|
| 409 | if (activeItem) {
|
---|
| 410 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | event.preventDefault();
|
---|
| 415 | break;
|
---|
| 416 | case 'ArrowLeft':
|
---|
| 417 | if (activeItem) {
|
---|
| 418 | let sublist = activeItem.parentElement;
|
---|
| 419 | if (sublist && DomHandler.hasClass(sublist, 'p-submenu-list-active')) {
|
---|
| 420 | DomHandler.removeClass(sublist, 'p-submenu-list-active');
|
---|
| 421 | activeItem = sublist.parentElement.parentElement;
|
---|
| 422 | if (activeItem) {
|
---|
| 423 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 | event.preventDefault();
|
---|
| 428 | break;
|
---|
| 429 | case 'Escape':
|
---|
| 430 | this.hide();
|
---|
| 431 | event.preventDefault();
|
---|
| 432 | break;
|
---|
| 433 | case 'Enter':
|
---|
| 434 | if (activeItem) {
|
---|
| 435 | this.handleItemClick(event, this.findModelItemFromKey(this.contextMenuService.activeItemKey), activeItem);
|
---|
| 436 | }
|
---|
| 437 | event.preventDefault();
|
---|
| 438 | break;
|
---|
| 439 | default:
|
---|
| 440 | break;
|
---|
| 441 | }
|
---|
| 442 | });
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 | findModelItemFromKey(key) {
|
---|
| 446 | if (key == null || !this.model) {
|
---|
| 447 | return null;
|
---|
| 448 | }
|
---|
| 449 | let indexes = key.split('_');
|
---|
| 450 | return indexes.reduce((item, currentIndex) => {
|
---|
| 451 | return item ? item.items[currentIndex] : this.model[currentIndex];
|
---|
| 452 | }, null);
|
---|
| 453 | }
|
---|
| 454 | handleItemClick(event, item, menuitem) {
|
---|
| 455 | if (!item || item.disabled) {
|
---|
| 456 | return;
|
---|
| 457 | }
|
---|
| 458 | if (item.command) {
|
---|
| 459 | item.command({
|
---|
| 460 | originalEvent: event,
|
---|
| 461 | item: item
|
---|
| 462 | });
|
---|
| 463 | }
|
---|
| 464 | if (item.items) {
|
---|
| 465 | let childSublist = DomHandler.findSingle(menuitem, '.p-submenu-list');
|
---|
| 466 | if (childSublist) {
|
---|
| 467 | if (DomHandler.hasClass(childSublist, 'p-submenu-list-active')) {
|
---|
| 468 | this.removeActiveFromSubLists(menuitem);
|
---|
| 469 | }
|
---|
| 470 | else {
|
---|
| 471 | DomHandler.addClass(childSublist, 'p-submenu-list-active');
|
---|
| 472 | this.positionSubmenu(childSublist);
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | if (!item.items) {
|
---|
| 477 | this.hide();
|
---|
| 478 | }
|
---|
| 479 | }
|
---|
| 480 | unbindGlobalListeners() {
|
---|
| 481 | if (this.documentClickListener) {
|
---|
| 482 | this.documentClickListener();
|
---|
| 483 | this.documentClickListener = null;
|
---|
| 484 | }
|
---|
| 485 | if (this.windowResizeListener) {
|
---|
| 486 | window.removeEventListener('resize', this.windowResizeListener);
|
---|
| 487 | this.windowResizeListener = null;
|
---|
| 488 | }
|
---|
| 489 | if (this.documentKeydownListener) {
|
---|
| 490 | this.documentKeydownListener();
|
---|
| 491 | this.documentKeydownListener = null;
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 | onWindowResize(event) {
|
---|
| 495 | if (this.containerViewChild.nativeElement.offsetParent) {
|
---|
| 496 | this.hide();
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
| 499 | isOutsideClicked(event) {
|
---|
| 500 | return !(this.containerViewChild.nativeElement.isSameNode(event.target) || this.containerViewChild.nativeElement.contains(event.target));
|
---|
| 501 | }
|
---|
| 502 | ngOnDestroy() {
|
---|
| 503 | this.unbindGlobalListeners();
|
---|
| 504 | if (this.triggerEventListener) {
|
---|
| 505 | this.triggerEventListener();
|
---|
| 506 | }
|
---|
| 507 | if (this.containerViewChild && this.autoZIndex) {
|
---|
| 508 | ZIndexUtils.clear(this.containerViewChild.nativeElement);
|
---|
| 509 | }
|
---|
| 510 | if (this.appendTo) {
|
---|
| 511 | this.el.nativeElement.appendChild(this.containerViewChild.nativeElement);
|
---|
| 512 | }
|
---|
| 513 | this.ngDestroy$.next(true);
|
---|
| 514 | this.ngDestroy$.complete();
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
| 517 | ContextMenu.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenu, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i5.ContextMenuService }, { token: i5.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component });
|
---|
| 518 | ContextMenu.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: ContextMenu, selector: "p-contextMenu", inputs: { model: "model", global: "global", target: "target", style: "style", styleClass: "styleClass", appendTo: "appendTo", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", triggerEvent: "triggerEvent" }, outputs: { onShow: "onShow", onHide: "onHide" }, host: { classAttribute: "p-element" }, viewQueries: [{ propertyName: "containerViewChild", first: true, predicate: ["container"], descendants: true }], ngImport: i0, template: `
|
---|
| 519 | <div #container [ngClass]="'p-contextmenu p-component'" [class]="styleClass" [ngStyle]="style">
|
---|
| 520 | <p-contextMenuSub [item]="model" [root]="true"></p-contextMenuSub>
|
---|
| 521 | </div>
|
---|
| 522 | `, isInline: true, styles: [".p-contextmenu{position:absolute;display:none}.p-contextmenu ul{margin:0;padding:0;list-style:none}.p-contextmenu .p-submenu-list{position:absolute;min-width:100%;z-index:1;display:none}.p-contextmenu .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden;position:relative}.p-contextmenu .p-menuitem-text{line-height:1}.p-contextmenu .p-menuitem{position:relative}.p-contextmenu .p-menuitem-link .p-submenu-icon{margin-left:auto}.p-contextmenu .p-menuitem-active>p-contextmenusub>.p-submenu-list.p-submenu-list-active{display:block!important}\n"], components: [{ type: ContextMenuSub, selector: "p-contextMenuSub", inputs: ["item", "root", "parentItemKey"], outputs: ["leafClick"] }], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
---|
| 523 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenu, decorators: [{
|
---|
| 524 | type: Component,
|
---|
| 525 | args: [{ selector: 'p-contextMenu', template: `
|
---|
| 526 | <div #container [ngClass]="'p-contextmenu p-component'" [class]="styleClass" [ngStyle]="style">
|
---|
| 527 | <p-contextMenuSub [item]="model" [root]="true"></p-contextMenuSub>
|
---|
| 528 | </div>
|
---|
| 529 | `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
---|
| 530 | 'class': 'p-element'
|
---|
| 531 | }, styles: [".p-contextmenu{position:absolute;display:none}.p-contextmenu ul{margin:0;padding:0;list-style:none}.p-contextmenu .p-submenu-list{position:absolute;min-width:100%;z-index:1;display:none}.p-contextmenu .p-menuitem-link{cursor:pointer;display:flex;align-items:center;text-decoration:none;overflow:hidden;position:relative}.p-contextmenu .p-menuitem-text{line-height:1}.p-contextmenu .p-menuitem{position:relative}.p-contextmenu .p-menuitem-link .p-submenu-icon{margin-left:auto}.p-contextmenu .p-menuitem-active>p-contextmenusub>.p-submenu-list.p-submenu-list-active{display:block!important}\n"] }]
|
---|
| 532 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i5.ContextMenuService }, { type: i5.PrimeNGConfig }]; }, propDecorators: { model: [{
|
---|
| 533 | type: Input
|
---|
| 534 | }], global: [{
|
---|
| 535 | type: Input
|
---|
| 536 | }], target: [{
|
---|
| 537 | type: Input
|
---|
| 538 | }], style: [{
|
---|
| 539 | type: Input
|
---|
| 540 | }], styleClass: [{
|
---|
| 541 | type: Input
|
---|
| 542 | }], appendTo: [{
|
---|
| 543 | type: Input
|
---|
| 544 | }], autoZIndex: [{
|
---|
| 545 | type: Input
|
---|
| 546 | }], baseZIndex: [{
|
---|
| 547 | type: Input
|
---|
| 548 | }], triggerEvent: [{
|
---|
| 549 | type: Input
|
---|
| 550 | }], onShow: [{
|
---|
| 551 | type: Output
|
---|
| 552 | }], onHide: [{
|
---|
| 553 | type: Output
|
---|
| 554 | }], containerViewChild: [{
|
---|
| 555 | type: ViewChild,
|
---|
| 556 | args: ['container']
|
---|
| 557 | }] } });
|
---|
| 558 | class ContextMenuModule {
|
---|
| 559 | }
|
---|
| 560 | ContextMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 561 | ContextMenuModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, declarations: [ContextMenu, ContextMenuSub], imports: [CommonModule, RouterModule, RippleModule, TooltipModule], exports: [ContextMenu, RouterModule, TooltipModule] });
|
---|
| 562 | ContextMenuModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, providers: [ContextMenuService], imports: [[CommonModule, RouterModule, RippleModule, TooltipModule], RouterModule, TooltipModule] });
|
---|
| 563 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, decorators: [{
|
---|
| 564 | type: NgModule,
|
---|
| 565 | args: [{
|
---|
| 566 | imports: [CommonModule, RouterModule, RippleModule, TooltipModule],
|
---|
| 567 | exports: [ContextMenu, RouterModule, TooltipModule],
|
---|
| 568 | declarations: [ContextMenu, ContextMenuSub],
|
---|
| 569 | providers: [ContextMenuService]
|
---|
| 570 | }]
|
---|
| 571 | }] });
|
---|
| 572 |
|
---|
| 573 | /**
|
---|
| 574 | * Generated bundle index. Do not edit.
|
---|
| 575 | */
|
---|
| 576 |
|
---|
| 577 | export { ContextMenu, ContextMenuModule, ContextMenuSub };
|
---|