Icard/angular-clarity-master(work.../node_modules/primeng/fesm2022/primeng-overlaypanel.mjs

544 lines
24 KiB
JavaScript
Raw Normal View History

2024-07-16 15:23:22 +00:00
import { trigger, state, style, transition, animate } from '@angular/animations';
import * as i2 from '@angular/common';
import { isPlatformBrowser, DOCUMENT, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { EventEmitter, PLATFORM_ID, booleanAttribute, numberAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Inject, Input, Output, ContentChildren, HostListener, NgModule } from '@angular/core';
import * as i1 from 'primeng/api';
import { PrimeTemplate, SharedModule } from 'primeng/api';
import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom';
import { TimesIcon } from 'primeng/icons/times';
import * as i3 from 'primeng/ripple';
import { RippleModule } from 'primeng/ripple';
import { ZIndexUtils } from 'primeng/utils';
/**
* OverlayPanel is a container component positioned as connected to its target.
* @group Components
*/
class OverlayPanel {
document;
platformId;
el;
renderer;
cd;
zone;
config;
overlayService;
/**
* Defines a string that labels the input for accessibility.
* @group Props
*/
ariaLabel;
/**
* Establishes relationships between the component and label(s) where its value should be one or more element IDs.
* @group Props
*/
ariaLabelledBy;
/**
* Enables to hide the overlay when outside is clicked.
* @group Props
*/
dismissable = true;
/**
* When enabled, displays a close icon at top right corner.
* @group Props
*/
showCloseIcon;
/**
* Inline style of the component.
* @group Props
*/
style;
/**
* Style class of the component.
* @group Props
*/
styleClass;
/**
* Target element to attach the panel, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
* @group Props
*/
appendTo = 'body';
/**
* Whether to automatically manage layering.
* @group Props
*/
autoZIndex = true;
/**
* Aria label of the close icon.
* @group Props
*/
ariaCloseLabel;
/**
* Base zIndex value to use in layering.
* @group Props
*/
baseZIndex = 0;
/**
* When enabled, first button receives focus on show.
* @group Props
*/
focusOnShow = true;
/**
* Transition options of the show animation.
* @group Props
*/
showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)';
/**
* Transition options of the hide animation.
* @group Props
*/
hideTransitionOptions = '.1s linear';
/**
* Callback to invoke when an overlay becomes visible.
* @group Emits
*/
onShow = new EventEmitter();
/**
* Callback to invoke when an overlay gets hidden.
* @group Emits
*/
onHide = new EventEmitter();
templates;
container;
overlayVisible = false;
render = false;
isOverlayAnimationInProgress = false;
selfClick = false;
documentClickListener;
target;
willHide;
scrollHandler;
documentResizeListener;
contentTemplate;
closeIconTemplate;
destroyCallback;
overlayEventListener;
overlaySubscription;
constructor(document, platformId, el, renderer, cd, zone, config, overlayService) {
this.document = document;
this.platformId = platformId;
this.el = el;
this.renderer = renderer;
this.cd = cd;
this.zone = zone;
this.config = config;
this.overlayService = overlayService;
}
ngAfterContentInit() {
this.templates?.forEach((item) => {
switch (item.getType()) {
case 'content':
this.contentTemplate = item.template;
break;
case 'closeicon':
this.closeIconTemplate = item.template;
break;
default:
this.contentTemplate = item.template;
break;
}
this.cd.markForCheck();
});
}
bindDocumentClickListener() {
if (isPlatformBrowser(this.platformId)) {
if (!this.documentClickListener && this.dismissable) {
let documentEvent = DomHandler.isIOS() ? 'touchstart' : 'click';
const documentTarget = this.el ? this.el.nativeElement.ownerDocument : this.document;
this.documentClickListener = this.renderer.listen(documentTarget, documentEvent, (event) => {
if (!this.container?.contains(event.target) && this.target !== event.target && !this.target.contains(event.target) && !this.selfClick) {
this.hide();
}
this.selfClick = false;
this.cd.markForCheck();
});
}
}
}
unbindDocumentClickListener() {
if (this.documentClickListener) {
this.documentClickListener();
this.documentClickListener = null;
this.selfClick = false;
}
}
/**
* Toggles the visibility of the panel.
* @param {Event} event - Browser event
* @param {Target} target - Target element.
* @group Method
*/
toggle(event, target) {
if (this.isOverlayAnimationInProgress) {
return;
}
if (this.overlayVisible) {
if (this.hasTargetChanged(event, target)) {
this.destroyCallback = () => {
this.show(null, target || event.currentTarget || event.target);
};
}
this.hide();
}
else {
this.show(event, target);
}
}
/**
* Displays the panel.
* @param {Event} event - Browser event
* @param {Target} target - Target element.
* @group Method
*/
show(event, target) {
target && event && event.stopPropagation();
if (this.isOverlayAnimationInProgress) {
return;
}
this.target = target || event.currentTarget || event.target;
this.overlayVisible = true;
this.render = true;
this.cd.markForCheck();
}
onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
this.selfClick = true;
}
onContentClick(event) {
const targetElement = event.target;
this.selfClick = event.offsetX < targetElement.clientWidth && event.offsetY < targetElement.clientHeight;
}
hasTargetChanged(event, target) {
return this.target != null && this.target !== (target || event.currentTarget || event.target);
}
appendContainer() {
if (this.appendTo) {
if (this.appendTo === 'body')
this.renderer.appendChild(this.document.body, this.container);
else
DomHandler.appendChild(this.container, this.appendTo);
}
}
restoreAppend() {
if (this.container && this.appendTo) {
this.renderer.appendChild(this.el.nativeElement, this.container);
}
}
align() {
if (this.autoZIndex) {
ZIndexUtils.set('overlay', this.container, this.baseZIndex + this.config.zIndex.overlay);
}
DomHandler.absolutePosition(this.container, this.target, false);
const containerOffset = DomHandler.getOffset(this.container);
const targetOffset = DomHandler.getOffset(this.target);
const borderRadius = this.document.defaultView?.getComputedStyle(this.container).getPropertyValue('border-radius');
let arrowLeft = 0;
if (containerOffset.left < targetOffset.left) {
arrowLeft = targetOffset.left - containerOffset.left - parseFloat(borderRadius) * 2;
}
this.container?.style.setProperty('--overlayArrowLeft', `${arrowLeft}px`);
if (containerOffset.top < targetOffset.top) {
DomHandler.addClass(this.container, 'p-overlaypanel-flipped');
if (this.showCloseIcon) {
this.renderer.setStyle(this.container, 'margin-top', '-30px');
}
}
}
onAnimationStart(event) {
if (event.toState === 'open') {
this.container = event.element;
this.appendContainer();
this.align();
this.bindDocumentClickListener();
this.bindDocumentResizeListener();
this.bindScrollListener();
if (this.focusOnShow) {
this.focus();
}
this.overlayEventListener = (e) => {
if (this.container && this.container.contains(e.target)) {
this.selfClick = true;
}
};
this.overlaySubscription = this.overlayService.clickObservable.subscribe(this.overlayEventListener);
this.onShow.emit(null);
}
this.isOverlayAnimationInProgress = true;
}
onAnimationEnd(event) {
switch (event.toState) {
case 'void':
if (this.destroyCallback) {
this.destroyCallback();
this.destroyCallback = null;
}
if (this.overlaySubscription) {
this.overlaySubscription.unsubscribe();
}
break;
case 'close':
if (this.autoZIndex) {
ZIndexUtils.clear(this.container);
}
if (this.overlaySubscription) {
this.overlaySubscription.unsubscribe();
}
this.onContainerDestroy();
this.onHide.emit({});
this.render = false;
break;
}
this.isOverlayAnimationInProgress = false;
}
focus() {
let focusable = DomHandler.findSingle(this.container, '[autofocus]');
if (focusable) {
this.zone.runOutsideAngular(() => {
setTimeout(() => focusable.focus(), 5);
});
}
}
/**
* Hides the panel.
* @group Method
*/
hide() {
this.overlayVisible = false;
this.cd.markForCheck();
}
onCloseClick(event) {
this.hide();
event.preventDefault();
}
onEscapeKeydown(event) {
this.hide();
}
onWindowResize() {
if (this.overlayVisible && !DomHandler.isTouchDevice()) {
this.hide();
}
}
bindDocumentResizeListener() {
if (isPlatformBrowser(this.platformId)) {
if (!this.documentResizeListener) {
const window = this.document.defaultView;
this.documentResizeListener = this.renderer.listen(window, 'resize', this.onWindowResize.bind(this));
}
}
}
unbindDocumentResizeListener() {
if (this.documentResizeListener) {
this.documentResizeListener();
this.documentResizeListener = null;
}
}
bindScrollListener() {
if (isPlatformBrowser(this.platformId)) {
if (!this.scrollHandler) {
this.scrollHandler = new ConnectedOverlayScrollHandler(this.target, () => {
if (this.overlayVisible) {
this.hide();
}
});
}
this.scrollHandler.bindScrollListener();
}
}
unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
}
onContainerDestroy() {
if (!this.cd.destroyed) {
this.target = null;
}
this.unbindDocumentClickListener();
this.unbindDocumentResizeListener();
this.unbindScrollListener();
}
ngOnDestroy() {
if (this.scrollHandler) {
this.scrollHandler.destroy();
this.scrollHandler = null;
}
if (this.container && this.autoZIndex) {
ZIndexUtils.clear(this.container);
}
if (!this.cd.destroyed) {
this.target = null;
}
this.destroyCallback = null;
if (this.container) {
this.restoreAppend();
this.onContainerDestroy();
}
if (this.overlaySubscription) {
this.overlaySubscription.unsubscribe();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanel, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i1.PrimeNGConfig }, { token: i1.OverlayService }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: OverlayPanel, selector: "p-overlayPanel", inputs: { ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy", dismissable: ["dismissable", "dismissable", booleanAttribute], showCloseIcon: ["showCloseIcon", "showCloseIcon", booleanAttribute], style: "style", styleClass: "styleClass", appendTo: "appendTo", autoZIndex: ["autoZIndex", "autoZIndex", booleanAttribute], ariaCloseLabel: "ariaCloseLabel", baseZIndex: ["baseZIndex", "baseZIndex", numberAttribute], focusOnShow: ["focusOnShow", "focusOnShow", booleanAttribute], showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, outputs: { onShow: "onShow", onHide: "onHide" }, host: { listeners: { "document:keydown.escape": "onEscapeKeydown($event)" }, classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: `
<div
*ngIf="render"
[ngClass]="'p-overlaypanel p-component'"
[ngStyle]="style"
[class]="styleClass"
(click)="onOverlayClick($event)"
[@animation]="{ value: overlayVisible ? 'open' : 'close', params: { showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions } }"
(@animation.start)="onAnimationStart($event)"
(@animation.done)="onAnimationEnd($event)"
role="dialog"
[attr.aria-modal]="overlayVisible"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledBy]="ariaLabelledBy"
>
<div class="p-overlaypanel-content" (click)="onContentClick($event)" (mousedown)="onContentClick($event)">
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
<button *ngIf="showCloseIcon" type="button" class="p-overlaypanel-close p-link" (click)="onCloseClick($event)" (keydown.enter)="hide()" [attr.aria-label]="ariaCloseLabel" pRipple>
<TimesIcon *ngIf="!closeIconTemplate" [styleClass]="'p-overlaypanel-close-icon'" />
<span class="p-overlaypanel-close-icon" *ngIf="closeIconTemplate">
<ng-template *ngTemplateOutlet="closeIconTemplate"></ng-template>
</span>
</button>
</div>
`, isInline: true, styles: ["@layer primeng{.p-overlaypanel{position:absolute;margin-top:10px;top:0;left:0}.p-overlaypanel-flipped{margin-top:0;margin-bottom:10px}.p-overlaypanel-close{display:flex;justify-content:center;align-items:center;overflow:hidden;position:relative}.p-overlaypanel:after,.p-overlaypanel:before{bottom:100%;left:calc(var(--overlayArrowLeft, 0) + 1.25rem);content:\" \";height:0;width:0;position:absolute;pointer-events:none}.p-overlaypanel:after{border-width:8px;margin-left:-8px}.p-overlaypanel:before{border-width:10px;margin-left:-10px}.p-overlaypanel-shifted:after,.p-overlaypanel-shifted:before{left:auto;right:1.25em;margin-left:auto}.p-overlaypanel-flipped:after,.p-overlaypanel-flipped:before{bottom:auto;top:100%}.p-overlaypanel.p-overlaypanel-flipped:after{border-bottom-color:transparent}.p-overlaypanel.p-overlaypanel-flipped:before{border-bottom-color:transparent}}\n"], dependencies: [{ kind: "directive", type: i0.forwardRef(() => i2.NgClass), selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgIf), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgTemplateOutlet), selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgStyle), selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i0.forwardRef(() => i3.Ripple), selector: "[pRipple]" }, { kind: "component", type: i0.forwardRef(() => TimesIcon), selector: "TimesIcon" }], animations: [
trigger('animation', [
state('void', style({
transform: 'scaleY(0.8)',
opacity: 0
})),
state('close', style({
opacity: 0
})),
state('open', style({
transform: 'translateY(0)',
opacity: 1
})),
transition('void => open', animate('{{showTransitionParams}}')),
transition('open => close', animate('{{hideTransitionParams}}'))
])
], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanel, decorators: [{
type: Component,
args: [{ selector: 'p-overlayPanel', template: `
<div
*ngIf="render"
[ngClass]="'p-overlaypanel p-component'"
[ngStyle]="style"
[class]="styleClass"
(click)="onOverlayClick($event)"
[@animation]="{ value: overlayVisible ? 'open' : 'close', params: { showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions } }"
(@animation.start)="onAnimationStart($event)"
(@animation.done)="onAnimationEnd($event)"
role="dialog"
[attr.aria-modal]="overlayVisible"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledBy]="ariaLabelledBy"
>
<div class="p-overlaypanel-content" (click)="onContentClick($event)" (mousedown)="onContentClick($event)">
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
<button *ngIf="showCloseIcon" type="button" class="p-overlaypanel-close p-link" (click)="onCloseClick($event)" (keydown.enter)="hide()" [attr.aria-label]="ariaCloseLabel" pRipple>
<TimesIcon *ngIf="!closeIconTemplate" [styleClass]="'p-overlaypanel-close-icon'" />
<span class="p-overlaypanel-close-icon" *ngIf="closeIconTemplate">
<ng-template *ngTemplateOutlet="closeIconTemplate"></ng-template>
</span>
</button>
</div>
`, animations: [
trigger('animation', [
state('void', style({
transform: 'scaleY(0.8)',
opacity: 0
})),
state('close', style({
opacity: 0
})),
state('open', style({
transform: 'translateY(0)',
opacity: 1
})),
transition('void => open', animate('{{showTransitionParams}}')),
transition('open => close', animate('{{hideTransitionParams}}'))
])
], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
class: 'p-element'
}, styles: ["@layer primeng{.p-overlaypanel{position:absolute;margin-top:10px;top:0;left:0}.p-overlaypanel-flipped{margin-top:0;margin-bottom:10px}.p-overlaypanel-close{display:flex;justify-content:center;align-items:center;overflow:hidden;position:relative}.p-overlaypanel:after,.p-overlaypanel:before{bottom:100%;left:calc(var(--overlayArrowLeft, 0) + 1.25rem);content:\" \";height:0;width:0;position:absolute;pointer-events:none}.p-overlaypanel:after{border-width:8px;margin-left:-8px}.p-overlaypanel:before{border-width:10px;margin-left:-10px}.p-overlaypanel-shifted:after,.p-overlaypanel-shifted:before{left:auto;right:1.25em;margin-left:auto}.p-overlaypanel-flipped:after,.p-overlaypanel-flipped:before{bottom:auto;top:100%}.p-overlaypanel.p-overlaypanel-flipped:after{border-bottom-color:transparent}.p-overlaypanel.p-overlaypanel-flipped:before{border-bottom-color:transparent}}\n"] }]
}], ctorParameters: () => [{ type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: undefined, decorators: [{
type: Inject,
args: [PLATFORM_ID]
}] }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i1.PrimeNGConfig }, { type: i1.OverlayService }], propDecorators: { ariaLabel: [{
type: Input
}], ariaLabelledBy: [{
type: Input
}], dismissable: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], showCloseIcon: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], style: [{
type: Input
}], styleClass: [{
type: Input
}], appendTo: [{
type: Input
}], autoZIndex: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], ariaCloseLabel: [{
type: Input
}], baseZIndex: [{
type: Input,
args: [{ transform: numberAttribute }]
}], focusOnShow: [{
type: Input,
args: [{ transform: booleanAttribute }]
}], showTransitionOptions: [{
type: Input
}], hideTransitionOptions: [{
type: Input
}], onShow: [{
type: Output
}], onHide: [{
type: Output
}], templates: [{
type: ContentChildren,
args: [PrimeTemplate]
}], onEscapeKeydown: [{
type: HostListener,
args: ['document:keydown.escape', ['$event']]
}] } });
class OverlayPanelModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanelModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanelModule, declarations: [OverlayPanel], imports: [CommonModule, RippleModule, SharedModule, TimesIcon], exports: [OverlayPanel, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanelModule, imports: [CommonModule, RippleModule, SharedModule, TimesIcon, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: OverlayPanelModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule, RippleModule, SharedModule, TimesIcon],
exports: [OverlayPanel, SharedModule],
declarations: [OverlayPanel]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { OverlayPanel, OverlayPanelModule };
//# sourceMappingURL=primeng-overlaypanel.mjs.map