import * as i0 from '@angular/core'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, ContentChildren, Output, NgModule } from '@angular/core'; import { animation, style, animate, trigger, transition, useAnimation } from '@angular/animations'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i3 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; import { DomHandler } from 'primeng/dom'; import * as i1 from 'primeng/api'; import { PrimeTemplate } from 'primeng/api'; import { ZIndexUtils } from 'primeng/utils'; const showAnimation = animation([ style({ transform: '{{transform}}', opacity: 0 }), animate('{{transition}}') ]); const hideAnimation = animation([ animate('{{transition}}', style({ transform: '{{transform}}', opacity: 0 })) ]); class Sidebar { constructor(el, renderer, cd, config) { this.el = el; this.renderer = renderer; this.cd = cd; this.config = config; this.blockScroll = false; this.autoZIndex = true; this.baseZIndex = 0; this.modal = true; this.dismissible = true; this.showCloseIcon = true; this.closeOnEscape = true; this.transitionOptions = '150ms cubic-bezier(0, 0, 0.2, 1)'; this.onShow = new EventEmitter(); this.onHide = new EventEmitter(); this.visibleChange = new EventEmitter(); this._position = "left"; this._fullScreen = false; this.transformOptions = "translate3d(-100%, 0px, 0px)"; } ngAfterViewInit() { this.initialized = true; } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'content': this.contentTemplate = item.template; break; default: this.contentTemplate = item.template; break; } }); } get visible() { return this._visible; } set visible(val) { this._visible = val; } get position() { return this._position; } ; set position(value) { this._position = value; switch (value) { case 'left': this.transformOptions = "translate3d(-100%, 0px, 0px)"; break; case 'right': this.transformOptions = "translate3d(100%, 0px, 0px)"; break; case 'bottom': this.transformOptions = "translate3d(0px, 100%, 0px)"; break; case 'top': this.transformOptions = "translate3d(0px, -100%, 0px)"; break; } } get fullScreen() { return this._fullScreen; } set fullScreen(value) { this._fullScreen = value; if (value) this.transformOptions = "none"; } show() { if (this.autoZIndex) { ZIndexUtils.set('modal', this.container, this.baseZIndex || this.config.zIndex.modal); } if (this.modal) { this.enableModality(); } this.onShow.emit({}); } hide() { this.onHide.emit({}); if (this.modal) { this.disableModality(); } } close(event) { this.hide(); this.visibleChange.emit(false); event.preventDefault(); } enableModality() { if (!this.mask) { this.mask = document.createElement('div'); this.mask.style.zIndex = String(parseInt(this.container.style.zIndex) - 1); DomHandler.addMultipleClasses(this.mask, 'p-component-overlay p-sidebar-mask p-component-overlay p-component-overlay-enter'); if (this.dismissible) { this.maskClickListener = this.renderer.listen(this.mask, 'click', (event) => { if (this.dismissible) { this.close(event); } }); } document.body.appendChild(this.mask); if (this.blockScroll) { DomHandler.addClass(document.body, 'p-overflow-hidden'); } } } disableModality() { if (this.mask) { DomHandler.addClass(this.mask, 'p-component-overlay-leave'); this.animationEndListener = this.destroyModal.bind(this); this.mask.addEventListener('animationend', this.animationEndListener); } } destroyModal() { this.unbindMaskClickListener(); if (this.mask) { document.body.removeChild(this.mask); } if (this.blockScroll) { DomHandler.removeClass(document.body, 'p-overflow-hidden'); } this.unbindAnimationEndListener(); this.mask = null; } onAnimationStart(event) { switch (event.toState) { case 'visible': this.container = event.element; this.appendContainer(); this.show(); if (this.closeOnEscape) { this.bindDocumentEscapeListener(); } break; } } onAnimationEnd(event) { switch (event.toState) { case 'void': this.hide(); ZIndexUtils.clear(this.container); this.unbindGlobalListeners(); break; } } appendContainer() { if (this.appendTo) { if (this.appendTo === 'body') document.body.appendChild(this.container); else DomHandler.appendChild(this.container, this.appendTo); } } bindDocumentEscapeListener() { const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document'; this.documentEscapeListener = this.renderer.listen(documentTarget, 'keydown', (event) => { if (event.which == 27) { if (parseInt(this.container.style.zIndex) === (DomHandler.zindex + this.baseZIndex)) { this.close(event); } } }); } unbindDocumentEscapeListener() { if (this.documentEscapeListener) { this.documentEscapeListener(); this.documentEscapeListener = null; } } unbindMaskClickListener() { if (this.maskClickListener) { this.maskClickListener(); this.maskClickListener = null; } } unbindGlobalListeners() { this.unbindMaskClickListener(); this.unbindDocumentEscapeListener(); } unbindAnimationEndListener() { if (this.animationEndListener && this.mask) { this.mask.removeEventListener('animationend', this.animationEndListener); this.animationEndListener = null; } } ngOnDestroy() { this.initialized = false; if (this.visible && this.modal) { this.destroyModal(); } if (this.appendTo && this.container) { this.el.nativeElement.appendChild(this.container); } if (this.container && this.autoZIndex) { ZIndexUtils.clear(this.container); } this.container = null; this.unbindGlobalListeners(); this.unbindAnimationEndListener(); } } Sidebar.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Sidebar, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component }); Sidebar.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: Sidebar, selector: "p-sidebar", inputs: { appendTo: "appendTo", blockScroll: "blockScroll", style: "style", styleClass: "styleClass", ariaCloseLabel: "ariaCloseLabel", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", modal: "modal", dismissible: "dismissible", showCloseIcon: "showCloseIcon", closeOnEscape: "closeOnEscape", transitionOptions: "transitionOptions", visible: "visible", position: "position", fullScreen: "fullScreen" }, outputs: { onShow: "onShow", onHide: "onHide", visibleChange: "visibleChange" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: `