Files

257 lines
38 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
import { ChangeDetectionStrategy, Component, Directive, EventEmitter, Inject, Input, Output, TemplateRef, ViewEncapsulation, } from '@angular/core';
import { DOCUMENT, NgIf, NgTemplateOutlet } from '@angular/common';
import { listenToTriggers } from '../util/triggers';
import { ngbAutoClose } from '../util/autoclose';
import { ngbPositioning } from '../util/positioning';
import { PopupService } from '../util/popup';
import { isString } from '../util/util';
import { addPopperOffset } from '../util/positioning-util';
import * as i0 from "@angular/core";
import * as i1 from "./popover-config";
let nextId = 0;
export class NgbPopoverWindow {
isTitleTemplate() {
return this.title instanceof TemplateRef;
}
}
NgbPopoverWindow.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbPopoverWindow, deps: [], target: i0.ɵɵFactoryTarget.Component });
NgbPopoverWindow.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.0", type: NgbPopoverWindow, isStandalone: true, selector: "ngb-popover-window", inputs: { animation: "animation", title: "title", id: "id", popoverClass: "popoverClass", context: "context" }, host: { attributes: { "role": "tooltip" }, properties: { "class": "\"popover\" + (popoverClass ? \" \" + popoverClass : \"\")", "class.fade": "animation", "id": "id" }, styleAttribute: "position: absolute;" }, ngImport: i0, template: ` <div class="popover-arrow" data-popper-arrow></div>
<h3 class="popover-header" *ngIf="title">
<ng-template #simpleTitle>{{ title }}</ng-template>
<ng-template
[ngTemplateOutlet]="isTitleTemplate() ? $any(title) : simpleTitle"
[ngTemplateOutletContext]="context"
></ng-template>
</h3>
<div class="popover-body"><ng-content></ng-content></div>`, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbPopoverWindow, decorators: [{
type: Component,
args: [{
selector: 'ngb-popover-window',
standalone: true,
imports: [NgTemplateOutlet, NgIf],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class]': '"popover" + (popoverClass ? " " + popoverClass : "")',
'[class.fade]': 'animation',
role: 'tooltip',
'[id]': 'id',
style: 'position: absolute;',
},
template: ` <div class="popover-arrow" data-popper-arrow></div>
<h3 class="popover-header" *ngIf="title">
<ng-template #simpleTitle>{{ title }}</ng-template>
<ng-template
[ngTemplateOutlet]="isTitleTemplate() ? $any(title) : simpleTitle"
[ngTemplateOutletContext]="context"
></ng-template>
</h3>
<div class="popover-body"><ng-content></ng-content></div>`,
}]
}], propDecorators: { animation: [{
type: Input
}], title: [{
type: Input
}], id: [{
type: Input
}], popoverClass: [{
type: Input
}], context: [{
type: Input
}] } });
/**
* A lightweight and extensible directive for fancy popover creation.
*/
export class NgbPopover {
constructor(_elementRef, _renderer, injector, viewContainerRef, config, _ngZone, _document, _changeDetector, applicationRef) {
this._elementRef = _elementRef;
this._renderer = _renderer;
this._ngZone = _ngZone;
this._document = _document;
this._changeDetector = _changeDetector;
/**
* An event emitted when the popover opening animation has finished. Contains no payload.
*/
this.shown = new EventEmitter();
/**
* An event emitted when the popover closing animation has finished. Contains no payload.
*
* At this point popover is not in the DOM anymore.
*/
this.hidden = new EventEmitter();
this._ngbPopoverWindowId = `ngb-popover-${nextId++}`;
this._windowRef = null;
this.animation = config.animation;
this.autoClose = config.autoClose;
this.placement = config.placement;
this.popperOptions = config.popperOptions;
this.triggers = config.triggers;
this.container = config.container;
this.disablePopover = config.disablePopover;
this.popoverClass = config.popoverClass;
this.openDelay = config.openDelay;
this.closeDelay = config.closeDelay;
this._positioning = ngbPositioning();
this._popupService = new PopupService(NgbPopoverWindow, injector, viewContainerRef, _renderer, this._ngZone, applicationRef);
}
_isDisabled() {
if (this.disablePopover) {
return true;
}
if (!this.ngbPopover && !this.popoverTitle) {
return true;
}
return false;
}
/**
* Opens the popover.
*
* This is considered to be a "manual" triggering.
* The `context` is an optional value to be injected into the popover template when it is created.
*/
open(context) {
if (!this._windowRef && !this._isDisabled()) {
// this type assertion is safe because otherwise _isDisabled would return true
const { windowRef, transition$ } = this._popupService.open(this.ngbPopover, context, this.animation);
this._windowRef = windowRef;
this._windowRef.setInput('animation', this.animation);
this._windowRef.setInput('title', this.popoverTitle);
this._windowRef.setInput('context', context);
this._windowRef.setInput('popoverClass', this.popoverClass);
this._windowRef.setInput('id', this._ngbPopoverWindowId);
this._renderer.setAttribute(this._getPositionTargetElement(), 'aria-describedby', this._ngbPopoverWindowId);
if (this.container === 'body') {
this._document.querySelector(this.container).appendChild(this._windowRef.location.nativeElement);
}
// We need to detect changes, because we don't know where .open() might be called from.
// Ex. opening popover from one of lifecycle hooks that run after the CD
// (say from ngAfterViewInit) will result in 'ExpressionHasChanged' exception
this._windowRef.changeDetectorRef.detectChanges();
// We need to mark for check, because popover won't work inside the OnPush component.
// Ex. when we use expression like `{{ popover.isOpen() : 'opened' : 'closed' }}`
// inside the template of an OnPush component and we change the popover from
// open -> closed, the expression in question won't be updated unless we explicitly
// mark the parent component to be checked.
this._windowRef.changeDetectorRef.markForCheck();
// Setting up popper and scheduling updates when zone is stable
this._ngZone.runOutsideAngular(() => {
this._positioning.createPopper({
hostElement: this._getPositionTargetElement(),
targetElement: this._windowRef.location.nativeElement,
placement: this.placement,
appendToBody: this.container === 'body',
baseClass: 'bs-popover',
updatePopperOptions: (options) => this.popperOptions(addPopperOffset([0, 8])(options)),
});
Promise.resolve().then(() => {
// This update is required for correct arrow placement
this._positioning.update();
this._zoneSubscription = this._ngZone.onStable.subscribe(() => this._positioning.update());
});
});
ngbAutoClose(this._ngZone, this._document, this.autoClose, () => this.close(), this.hidden, [
this._windowRef.location.nativeElement,
]);
transition$.subscribe(() => this.shown.emit());
}
}
/**
* Closes the popover.
*
* This is considered to be a "manual" triggering of the popover.
*/
close(animation = this.animation) {
if (this._windowRef) {
this._renderer.removeAttribute(this._getPositionTargetElement(), 'aria-describedby');
this._popupService.close(animation).subscribe(() => {
this._windowRef = null;
this._positioning.destroy();
this._zoneSubscription?.unsubscribe();
this.hidden.emit();
this._changeDetector.markForCheck();
});
}
}
/**
* Toggles the popover.
*
* This is considered to be a "manual" triggering of the popover.
*/
toggle() {
if (this._windowRef) {
this.close();
}
else {
this.open();
}
}
/**
* Returns `true`, if the popover is currently shown.
*/
isOpen() {
return this._windowRef != null;
}
ngOnInit() {
this._unregisterListenersFn = listenToTriggers(this._renderer, this._elementRef.nativeElement, this.triggers, this.isOpen.bind(this), this.open.bind(this), this.close.bind(this), +this.openDelay, +this.closeDelay);
}
ngOnChanges({ ngbPopover, popoverTitle, disablePopover, popoverClass }) {
if (popoverClass && this.isOpen()) {
this._windowRef.instance.popoverClass = popoverClass.currentValue;
}
// close popover if title and content become empty, or disablePopover set to true
if ((ngbPopover || popoverTitle || disablePopover) && this._isDisabled()) {
this.close();
}
}
ngOnDestroy() {
this.close(false);
// This check is needed as it might happen that ngOnDestroy is called before ngOnInit
// under certain conditions, see: https://github.com/ng-bootstrap/ng-bootstrap/issues/2199
this._unregisterListenersFn?.();
}
_getPositionTargetElement() {
return ((isString(this.positionTarget) ? this._document.querySelector(this.positionTarget) : this.positionTarget) ||
this._elementRef.nativeElement);
}
}
NgbPopover.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbPopover, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.Injector }, { token: i0.ViewContainerRef }, { token: i1.NgbPopoverConfig }, { token: i0.NgZone }, { token: DOCUMENT }, { token: i0.ChangeDetectorRef }, { token: i0.ApplicationRef }], target: i0.ɵɵFactoryTarget.Directive });
NgbPopover.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbPopover, isStandalone: true, selector: "[ngbPopover]", inputs: { animation: "animation", autoClose: "autoClose", ngbPopover: "ngbPopover", popoverTitle: "popoverTitle", placement: "placement", popperOptions: "popperOptions", triggers: "triggers", positionTarget: "positionTarget", container: "container", disablePopover: "disablePopover", popoverClass: "popoverClass", openDelay: "openDelay", closeDelay: "closeDelay" }, outputs: { shown: "shown", hidden: "hidden" }, exportAs: ["ngbPopover"], usesOnChanges: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbPopover, decorators: [{
type: Directive,
args: [{ selector: '[ngbPopover]', exportAs: 'ngbPopover', standalone: true }]
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.Injector }, { type: i0.ViewContainerRef }, { type: i1.NgbPopoverConfig }, { type: i0.NgZone }, { type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: i0.ChangeDetectorRef }, { type: i0.ApplicationRef }]; }, propDecorators: { animation: [{
type: Input
}], autoClose: [{
type: Input
}], ngbPopover: [{
type: Input
}], popoverTitle: [{
type: Input
}], placement: [{
type: Input
}], popperOptions: [{
type: Input
}], triggers: [{
type: Input
}], positionTarget: [{
type: Input
}], container: [{
type: Input
}], disablePopover: [{
type: Input
}], popoverClass: [{
type: Input
}], openDelay: [{
type: Input
}], closeDelay: [{
type: Input
}], shown: [{
type: Output
}], hidden: [{
type: Output
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicG9wb3Zlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9wb3BvdmVyL3BvcG92ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUVOLHVCQUF1QixFQUV2QixTQUFTLEVBRVQsU0FBUyxF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