[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 () { return [{ type: undefined, decorators: [{
|
---|
| 169 | type: Inject,
|
---|
| 170 | args: [forwardRef(() => ContextMenu)]
|
---|
| 171 | }] }]; }, propDecorators: { item: [{
|
---|
| 172 | type: Input
|
---|
| 173 | }], root: [{
|
---|
| 174 | type: Input
|
---|
| 175 | }], parentItemKey: [{
|
---|
| 176 | type: Input
|
---|
| 177 | }], leafClick: [{
|
---|
| 178 | type: Output
|
---|
| 179 | }], sublistViewChild: [{
|
---|
| 180 | type: ViewChild,
|
---|
| 181 | args: ['sublist']
|
---|
| 182 | }], menuitemViewChild: [{
|
---|
| 183 | type: ViewChild,
|
---|
| 184 | args: ['menuitem']
|
---|
| 185 | }] } });
|
---|
| 186 | class ContextMenu {
|
---|
| 187 | constructor(el, renderer, cd, zone, contextMenuService, config) {
|
---|
| 188 | this.el = el;
|
---|
| 189 | this.renderer = renderer;
|
---|
| 190 | this.cd = cd;
|
---|
| 191 | this.zone = zone;
|
---|
| 192 | this.contextMenuService = contextMenuService;
|
---|
| 193 | this.config = config;
|
---|
| 194 | this.autoZIndex = true;
|
---|
| 195 | this.baseZIndex = 0;
|
---|
| 196 | this.triggerEvent = 'contextmenu';
|
---|
| 197 | this.onShow = new EventEmitter();
|
---|
| 198 | this.onHide = new EventEmitter();
|
---|
| 199 | this.ngDestroy$ = new Subject();
|
---|
| 200 | }
|
---|
| 201 | ngAfterViewInit() {
|
---|
| 202 | if (this.global) {
|
---|
| 203 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 204 | this.triggerEventListener = this.renderer.listen(documentTarget, this.triggerEvent, (event) => {
|
---|
| 205 | this.show(event);
|
---|
| 206 | event.preventDefault();
|
---|
| 207 | });
|
---|
| 208 | }
|
---|
| 209 | else if (this.target) {
|
---|
| 210 | this.triggerEventListener = this.renderer.listen(this.target, this.triggerEvent, (event) => {
|
---|
| 211 | this.show(event);
|
---|
| 212 | event.preventDefault();
|
---|
| 213 | event.stopPropagation();
|
---|
| 214 | });
|
---|
| 215 | }
|
---|
| 216 | if (this.appendTo) {
|
---|
| 217 | if (this.appendTo === 'body')
|
---|
| 218 | document.body.appendChild(this.containerViewChild.nativeElement);
|
---|
| 219 | else
|
---|
| 220 | DomHandler.appendChild(this.containerViewChild.nativeElement, this.appendTo);
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | show(event) {
|
---|
| 224 | this.clearActiveItem();
|
---|
| 225 | this.position(event);
|
---|
| 226 | this.moveOnTop();
|
---|
| 227 | this.containerViewChild.nativeElement.style.display = 'block';
|
---|
| 228 | DomHandler.fadeIn(this.containerViewChild.nativeElement, 250);
|
---|
| 229 | this.bindGlobalListeners();
|
---|
| 230 | if (event) {
|
---|
| 231 | event.preventDefault();
|
---|
| 232 | }
|
---|
| 233 | this.onShow.emit();
|
---|
| 234 | }
|
---|
| 235 | hide() {
|
---|
| 236 | this.containerViewChild.nativeElement.style.display = 'none';
|
---|
| 237 | if (this.autoZIndex) {
|
---|
| 238 | ZIndexUtils.clear(this.containerViewChild.nativeElement);
|
---|
| 239 | }
|
---|
| 240 | this.unbindGlobalListeners();
|
---|
| 241 | this.onHide.emit();
|
---|
| 242 | }
|
---|
| 243 | moveOnTop() {
|
---|
| 244 | if (this.autoZIndex && this.containerViewChild && this.containerViewChild.nativeElement.style.display !== 'block') {
|
---|
| 245 | ZIndexUtils.set('menu', this.containerViewChild.nativeElement, this.baseZIndex + this.config.zIndex.menu);
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 | toggle(event) {
|
---|
| 249 | if (this.containerViewChild.nativeElement.offsetParent)
|
---|
| 250 | this.hide();
|
---|
| 251 | else
|
---|
| 252 | this.show(event);
|
---|
| 253 | }
|
---|
| 254 | position(event) {
|
---|
| 255 | if (event) {
|
---|
| 256 | let left = event.pageX + 1;
|
---|
| 257 | let top = event.pageY + 1;
|
---|
| 258 | let width = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetWidth : DomHandler.getHiddenElementOuterWidth(this.containerViewChild.nativeElement);
|
---|
| 259 | let height = this.containerViewChild.nativeElement.offsetParent ? this.containerViewChild.nativeElement.offsetHeight : DomHandler.getHiddenElementOuterHeight(this.containerViewChild.nativeElement);
|
---|
| 260 | let viewport = DomHandler.getViewport();
|
---|
| 261 | //flip
|
---|
| 262 | if (left + width - document.body.scrollLeft > viewport.width) {
|
---|
| 263 | left -= width;
|
---|
| 264 | }
|
---|
| 265 | //flip
|
---|
| 266 | if (top + height - document.body.scrollTop > viewport.height) {
|
---|
| 267 | top -= height;
|
---|
| 268 | }
|
---|
| 269 | //fit
|
---|
| 270 | if (left < document.body.scrollLeft) {
|
---|
| 271 | left = document.body.scrollLeft;
|
---|
| 272 | }
|
---|
| 273 | //fit
|
---|
| 274 | if (top < document.body.scrollTop) {
|
---|
| 275 | top = document.body.scrollTop;
|
---|
| 276 | }
|
---|
| 277 | this.containerViewChild.nativeElement.style.left = left + 'px';
|
---|
| 278 | this.containerViewChild.nativeElement.style.top = top + 'px';
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | positionSubmenu(sublist) {
|
---|
| 282 | let parentMenuItem = sublist.parentElement.parentElement;
|
---|
| 283 | let viewport = DomHandler.getViewport();
|
---|
| 284 | let sublistWidth = sublist.offsetParent ? sublist.offsetWidth : DomHandler.getHiddenElementOuterWidth(sublist);
|
---|
| 285 | let sublistHeight = sublist.offsetHeight ? sublist.offsetHeight : DomHandler.getHiddenElementOuterHeight(sublist);
|
---|
| 286 | let itemOuterWidth = DomHandler.getOuterWidth(parentMenuItem.children[0]);
|
---|
| 287 | let itemOuterHeight = DomHandler.getOuterHeight(parentMenuItem.children[0]);
|
---|
| 288 | let containerOffset = DomHandler.getOffset(parentMenuItem.parentElement);
|
---|
| 289 | sublist.style.zIndex = ++DomHandler.zindex;
|
---|
| 290 | if ((parseInt(containerOffset.top) + itemOuterHeight + sublistHeight) > (viewport.height - DomHandler.calculateScrollbarHeight())) {
|
---|
| 291 | sublist.style.removeProperty('top');
|
---|
| 292 | sublist.style.bottom = '0px';
|
---|
| 293 | }
|
---|
| 294 | else {
|
---|
| 295 | sublist.style.removeProperty('bottom');
|
---|
| 296 | sublist.style.top = '0px';
|
---|
| 297 | }
|
---|
| 298 | if ((parseInt(containerOffset.left) + itemOuterWidth + sublistWidth) > (viewport.width - DomHandler.calculateScrollbarWidth())) {
|
---|
| 299 | sublist.style.left = -sublistWidth + 'px';
|
---|
| 300 | }
|
---|
| 301 | else {
|
---|
| 302 | sublist.style.left = itemOuterWidth + 'px';
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 | isItemMatched(menuitem) {
|
---|
| 306 | return DomHandler.hasClass(menuitem, 'p-menuitem') && !DomHandler.hasClass(menuitem.children[0], 'p-disabled');
|
---|
| 307 | }
|
---|
| 308 | findNextItem(menuitem, isRepeated) {
|
---|
| 309 | let nextMenuitem = menuitem.nextElementSibling;
|
---|
| 310 | if (nextMenuitem) {
|
---|
| 311 | return this.isItemMatched(nextMenuitem) ? nextMenuitem : this.findNextItem(nextMenuitem, isRepeated);
|
---|
| 312 | }
|
---|
| 313 | else {
|
---|
| 314 | let firstItem = menuitem.parentElement.children[0];
|
---|
| 315 | return this.isItemMatched(firstItem) ? firstItem : (!isRepeated ? this.findNextItem(firstItem, true) : null);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | findPrevItem(menuitem, isRepeated) {
|
---|
| 319 | let prevMenuitem = menuitem.previousElementSibling;
|
---|
| 320 | if (prevMenuitem) {
|
---|
| 321 | return this.isItemMatched(prevMenuitem) ? prevMenuitem : this.findPrevItem(prevMenuitem, isRepeated);
|
---|
| 322 | }
|
---|
| 323 | else {
|
---|
| 324 | let lastItem = menuitem.parentElement.children[menuitem.parentElement.children.length - 1];
|
---|
| 325 | return this.isItemMatched(lastItem) ? lastItem : (!isRepeated ? this.findPrevItem(lastItem, true) : null);
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 | getActiveItem() {
|
---|
| 329 | let activeItemKey = this.contextMenuService.activeItemKey;
|
---|
| 330 | return activeItemKey == null ? null : DomHandler.findSingle(this.containerViewChild.nativeElement, '.p-menuitem[data-ik="' + activeItemKey + '"]');
|
---|
| 331 | }
|
---|
| 332 | clearActiveItem() {
|
---|
| 333 | if (this.contextMenuService.activeItemKey) {
|
---|
| 334 | this.removeActiveFromSubLists(this.containerViewChild.nativeElement);
|
---|
| 335 | this.contextMenuService.reset();
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 | removeActiveFromSubLists(el) {
|
---|
| 339 | let sublists = DomHandler.find(el, '.p-submenu-list-active');
|
---|
| 340 | for (let sublist of sublists) {
|
---|
| 341 | DomHandler.removeClass(sublist, 'p-submenu-list-active');
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 | removeActiveFromSublist(menuitem) {
|
---|
| 345 | if (menuitem) {
|
---|
| 346 | let sublist = DomHandler.findSingle(menuitem, '.p-submenu-list');
|
---|
| 347 | if (sublist && DomHandler.hasClass(menuitem, 'p-submenu-list-active')) {
|
---|
| 348 | DomHandler.removeClass(menuitem, 'p-submenu-list-active');
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | bindGlobalListeners() {
|
---|
| 353 | if (!this.documentClickListener) {
|
---|
| 354 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 355 | this.documentClickListener = this.renderer.listen(documentTarget, 'click', (event) => {
|
---|
| 356 | if (this.containerViewChild.nativeElement.offsetParent && this.isOutsideClicked(event) && !event.ctrlKey && event.button !== 2) {
|
---|
| 357 | this.hide();
|
---|
| 358 | }
|
---|
| 359 | });
|
---|
| 360 | }
|
---|
| 361 | this.zone.runOutsideAngular(() => {
|
---|
| 362 | if (!this.windowResizeListener) {
|
---|
| 363 | this.windowResizeListener = this.onWindowResize.bind(this);
|
---|
| 364 | window.addEventListener('resize', this.windowResizeListener);
|
---|
| 365 | }
|
---|
| 366 | });
|
---|
| 367 | if (!this.documentKeydownListener) {
|
---|
| 368 | const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
---|
| 369 | this.documentKeydownListener = this.renderer.listen(documentTarget, 'keydown', (event) => {
|
---|
| 370 | let activeItem = this.getActiveItem();
|
---|
| 371 | switch (event.key) {
|
---|
| 372 | case 'ArrowDown':
|
---|
| 373 | if (activeItem) {
|
---|
| 374 | this.removeActiveFromSublist(activeItem);
|
---|
| 375 | activeItem = this.findNextItem(activeItem);
|
---|
| 376 | }
|
---|
| 377 | else {
|
---|
| 378 | let firstItem = DomHandler.findSingle(this.containerViewChild.nativeElement, '.p-menuitem-link').parentElement;
|
---|
| 379 | activeItem = this.isItemMatched(firstItem) ? firstItem : this.findNextItem(firstItem);
|
---|
| 380 | }
|
---|
| 381 | if (activeItem) {
|
---|
| 382 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 383 | }
|
---|
| 384 | event.preventDefault();
|
---|
| 385 | break;
|
---|
| 386 | case 'ArrowUp':
|
---|
| 387 | if (activeItem) {
|
---|
| 388 | this.removeActiveFromSublist(activeItem);
|
---|
| 389 | activeItem = this.findPrevItem(activeItem);
|
---|
| 390 | }
|
---|
| 391 | else {
|
---|
| 392 | let sublist = DomHandler.findSingle(this.containerViewChild.nativeElement, 'ul');
|
---|
| 393 | let lastItem = sublist.children[sublist.children.length - 1];
|
---|
| 394 | activeItem = this.isItemMatched(lastItem) ? lastItem : this.findPrevItem(lastItem);
|
---|
| 395 | }
|
---|
| 396 | if (activeItem) {
|
---|
| 397 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 398 | }
|
---|
| 399 | event.preventDefault();
|
---|
| 400 | break;
|
---|
| 401 | case 'ArrowRight':
|
---|
| 402 | if (activeItem) {
|
---|
| 403 | let sublist = DomHandler.findSingle(activeItem, '.p-submenu-list');
|
---|
| 404 | if (sublist) {
|
---|
| 405 | DomHandler.addClass(sublist, 'p-submenu-list-active');
|
---|
| 406 | activeItem = DomHandler.findSingle(sublist, '.p-menuitem-link:not(.p-disabled)').parentElement;
|
---|
| 407 | if (activeItem) {
|
---|
| 408 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | event.preventDefault();
|
---|
| 413 | break;
|
---|
| 414 | case 'ArrowLeft':
|
---|
| 415 | if (activeItem) {
|
---|
| 416 | let sublist = activeItem.parentElement;
|
---|
| 417 | if (sublist && DomHandler.hasClass(sublist, 'p-submenu-list-active')) {
|
---|
| 418 | DomHandler.removeClass(sublist, 'p-submenu-list-active');
|
---|
| 419 | activeItem = sublist.parentElement.parentElement;
|
---|
| 420 | if (activeItem) {
|
---|
| 421 | this.contextMenuService.changeKey(activeItem.getAttribute('data-ik'));
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 | event.preventDefault();
|
---|
| 426 | break;
|
---|
| 427 | case 'Escape':
|
---|
| 428 | this.hide();
|
---|
| 429 | event.preventDefault();
|
---|
| 430 | break;
|
---|
| 431 | case 'Enter':
|
---|
| 432 | if (activeItem) {
|
---|
| 433 | this.handleItemClick(event, this.findModelItemFromKey(this.contextMenuService.activeItemKey), activeItem);
|
---|
| 434 | }
|
---|
| 435 | event.preventDefault();
|
---|
| 436 | break;
|
---|
| 437 | default:
|
---|
| 438 | break;
|
---|
| 439 | }
|
---|
| 440 | });
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | findModelItemFromKey(key) {
|
---|
| 444 | if (key == null || !this.model) {
|
---|
| 445 | return null;
|
---|
| 446 | }
|
---|
| 447 | let indexes = key.split('_');
|
---|
| 448 | return indexes.reduce((item, currentIndex) => {
|
---|
| 449 | return item ? item.items[currentIndex] : this.model[currentIndex];
|
---|
| 450 | }, null);
|
---|
| 451 | }
|
---|
| 452 | handleItemClick(event, item, menuitem) {
|
---|
| 453 | if (!item || item.disabled) {
|
---|
| 454 | return;
|
---|
| 455 | }
|
---|
| 456 | if (item.command) {
|
---|
| 457 | item.command({
|
---|
| 458 | originalEvent: event,
|
---|
| 459 | item: item
|
---|
| 460 | });
|
---|
| 461 | }
|
---|
| 462 | if (item.items) {
|
---|
| 463 | let childSublist = DomHandler.findSingle(menuitem, '.p-submenu-list');
|
---|
| 464 | if (childSublist) {
|
---|
| 465 | if (DomHandler.hasClass(childSublist, 'p-submenu-list-active')) {
|
---|
| 466 | this.removeActiveFromSubLists(menuitem);
|
---|
| 467 | }
|
---|
| 468 | else {
|
---|
| 469 | DomHandler.addClass(childSublist, 'p-submenu-list-active');
|
---|
| 470 | this.positionSubmenu(childSublist);
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | if (!item.items) {
|
---|
| 475 | this.hide();
|
---|
| 476 | }
|
---|
| 477 | }
|
---|
| 478 | unbindGlobalListeners() {
|
---|
| 479 | if (this.documentClickListener) {
|
---|
| 480 | this.documentClickListener();
|
---|
| 481 | this.documentClickListener = null;
|
---|
| 482 | }
|
---|
| 483 | if (this.windowResizeListener) {
|
---|
| 484 | window.removeEventListener('resize', this.windowResizeListener);
|
---|
| 485 | this.windowResizeListener = null;
|
---|
| 486 | }
|
---|
| 487 | if (this.documentKeydownListener) {
|
---|
| 488 | this.documentKeydownListener();
|
---|
| 489 | this.documentKeydownListener = null;
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 | onWindowResize(event) {
|
---|
| 493 | if (this.containerViewChild.nativeElement.offsetParent) {
|
---|
| 494 | this.hide();
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 | isOutsideClicked(event) {
|
---|
| 498 | return !(this.containerViewChild.nativeElement.isSameNode(event.target) || this.containerViewChild.nativeElement.contains(event.target));
|
---|
| 499 | }
|
---|
| 500 | ngOnDestroy() {
|
---|
| 501 | this.unbindGlobalListeners();
|
---|
| 502 | if (this.triggerEventListener) {
|
---|
| 503 | this.triggerEventListener();
|
---|
| 504 | }
|
---|
| 505 | if (this.containerViewChild && this.autoZIndex) {
|
---|
| 506 | ZIndexUtils.clear(this.containerViewChild.nativeElement);
|
---|
| 507 | }
|
---|
| 508 | if (this.appendTo) {
|
---|
| 509 | this.el.nativeElement.appendChild(this.containerViewChild.nativeElement);
|
---|
| 510 | }
|
---|
| 511 | this.ngDestroy$.next(true);
|
---|
| 512 | this.ngDestroy$.complete();
|
---|
| 513 | }
|
---|
| 514 | }
|
---|
| 515 | 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 });
|
---|
| 516 | 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: `
|
---|
| 517 | <div #container [ngClass]="'p-contextmenu p-component'" [class]="styleClass" [ngStyle]="style">
|
---|
| 518 | <p-contextMenuSub [item]="model" [root]="true"></p-contextMenuSub>
|
---|
| 519 | </div>
|
---|
| 520 | `, 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 });
|
---|
| 521 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenu, decorators: [{
|
---|
| 522 | type: Component,
|
---|
| 523 | args: [{ selector: 'p-contextMenu', template: `
|
---|
| 524 | <div #container [ngClass]="'p-contextmenu p-component'" [class]="styleClass" [ngStyle]="style">
|
---|
| 525 | <p-contextMenuSub [item]="model" [root]="true"></p-contextMenuSub>
|
---|
| 526 | </div>
|
---|
| 527 | `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
---|
| 528 | 'class': 'p-element'
|
---|
| 529 | }, 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"] }]
|
---|
| 530 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i5.ContextMenuService }, { type: i5.PrimeNGConfig }]; }, propDecorators: { model: [{
|
---|
| 531 | type: Input
|
---|
| 532 | }], global: [{
|
---|
| 533 | type: Input
|
---|
| 534 | }], target: [{
|
---|
| 535 | type: Input
|
---|
| 536 | }], style: [{
|
---|
| 537 | type: Input
|
---|
| 538 | }], styleClass: [{
|
---|
| 539 | type: Input
|
---|
| 540 | }], appendTo: [{
|
---|
| 541 | type: Input
|
---|
| 542 | }], autoZIndex: [{
|
---|
| 543 | type: Input
|
---|
| 544 | }], baseZIndex: [{
|
---|
| 545 | type: Input
|
---|
| 546 | }], triggerEvent: [{
|
---|
| 547 | type: Input
|
---|
| 548 | }], onShow: [{
|
---|
| 549 | type: Output
|
---|
| 550 | }], onHide: [{
|
---|
| 551 | type: Output
|
---|
| 552 | }], containerViewChild: [{
|
---|
| 553 | type: ViewChild,
|
---|
| 554 | args: ['container']
|
---|
| 555 | }] } });
|
---|
| 556 | class ContextMenuModule {
|
---|
| 557 | }
|
---|
| 558 | ContextMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 559 | 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] });
|
---|
| 560 | 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] });
|
---|
| 561 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: ContextMenuModule, decorators: [{
|
---|
| 562 | type: NgModule,
|
---|
| 563 | args: [{
|
---|
| 564 | imports: [CommonModule, RouterModule, RippleModule, TooltipModule],
|
---|
| 565 | exports: [ContextMenu, RouterModule, TooltipModule],
|
---|
| 566 | declarations: [ContextMenu, ContextMenuSub],
|
---|
| 567 | providers: [ContextMenuService]
|
---|
| 568 | }]
|
---|
| 569 | }] });
|
---|
| 570 |
|
---|
| 571 | /**
|
---|
| 572 | * Generated bundle index. Do not edit.
|
---|
| 573 | */
|
---|
| 574 |
|
---|
| 575 | export { ContextMenu, ContextMenuModule, ContextMenuSub };
|
---|