UNPKG

17.2 kBSource Map (JSON)View Raw
1{"version":3,"file":"ngx-bootstrap-popover.js","sources":["../../../../src/popover/popover.config.ts","../../../../src/popover/popover-container.component.ts","../../../../src/popover/popover.directive.ts","../../../../src/popover/popover.module.ts","../../../../src/popover/ngx-bootstrap-popover.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n/**\n * Configuration service for the Popover directive.\n * You can inject this service, typically in your root component, and customize\n * the values of its properties in order to provide default values for all the\n * popovers used in the application.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class PopoverConfig {\n /** sets disable adaptive position */\n adaptivePosition = true;\n /**\n * Placement of a popover. Accepts: \"top\", \"bottom\", \"left\", \"right\", \"auto\"\n */\n placement = 'top';\n /**\n * Specifies events that should trigger. Supports a space separated list of\n * event names.\n */\n triggers = 'click';\n\n outsideClick = false;\n /**\n * A selector specifying the element the popover should be appended to.\n */\n container?: string;\n /** delay before showing the tooltip */\n delay = 0;\n}\n","import { ChangeDetectionStrategy, Input, Component } from '@angular/core';\nimport { PopoverConfig } from './popover.config';\nimport { getBsVer, IBsVersion } from 'ngx-bootstrap/utils';\nimport { PlacementForBs5, checkMargins, AvailbleBSPositions } from 'ngx-bootstrap/positioning';\n\n@Component({\n selector: 'popover-container',\n changeDetection: ChangeDetectionStrategy.OnPush,\n // eslint-disable-next-line @angular-eslint/no-host-metadata-property\n host: {\n '[attr.id]': 'popoverId',\n '[class]':\n '\"popover in popover-\" + _placement + \" \" + \"bs-popover-\" + _placement + \" \" + _placement + \" \" + containerClass + checkMarginNecessity()',\n '[class.show]': '!_bsVersions.isBs3',\n '[class.bs3]': '_bsVersions.isBs3',\n role: 'tooltip',\n style: 'display:block;'\n },\n styles: [\n `\n :host.bs3.popover-top {\n margin-bottom: 10px;\n }\n :host.bs3.popover.top>.arrow {\n margin-left: -2px;\n }\n :host.bs3.popover.top {\n margin-bottom: 10px;\n }\n :host.popover.bottom>.arrow {\n margin-left: -4px;\n }\n :host.bs3.bs-popover-left {\n margin-right: .5rem;\n }\n :host.bs3.bs-popover-right .arrow, :host.bs3.bs-popover-left .arrow{\n margin: .3rem 0;\n }\n `\n ],\n templateUrl: './popover-container.component.html'\n})\nexport class PopoverContainerComponent {\n @Input() set placement(value: AvailbleBSPositions) {\n if (!this._bsVersions.isBs5) {\n this._placement = value;\n } else {\n this._placement = PlacementForBs5[value as keyof typeof PlacementForBs5];\n }\n };\n\n @Input() title?: string;\n\n containerClass?: string;\n popoverId?: string;\n _placement = 'top';\n\n get _bsVersions(): IBsVersion {\n return getBsVer();\n }\n\n constructor(config: PopoverConfig) {\n Object.assign(this, config);\n }\n\n checkMarginNecessity(): string {\n return checkMargins(this._placement);\n }\n}\n","import {\n Directive, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output,\n Renderer2, TemplateRef, ViewContainerRef\n} from '@angular/core';\nimport { PopoverConfig } from './popover.config';\nimport { ComponentLoader, ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';\nimport { PopoverContainerComponent } from './popover-container.component';\nimport { PositioningService, AvailbleBSPositions } from 'ngx-bootstrap/positioning';\nimport { timer } from 'rxjs';\nimport { parseTriggers, Trigger } from 'ngx-bootstrap/utils';\n\nlet id = 0;\n\n/**\n * A lightweight, extensible directive for fancy popover creation.\n */\n@Directive({selector: '[popover]', exportAs: 'bs-popover'})\nexport class PopoverDirective implements OnInit, OnDestroy {\n /** unique id popover - use for aria-describedby */\n popoverId = id++;\n /** sets disable adaptive position */\n @Input() adaptivePosition = true;\n /**\n * Content to be displayed as popover.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n @Input() popover?: string | TemplateRef<any>;\n /**\n * Context to be used if popover is a template.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n @Input() popoverContext: any;\n /**\n * Title of a popover.\n */\n @Input() popoverTitle?: string;\n /**\n * Placement of a popover. Accepts: \"top\", \"bottom\", \"left\", \"right\"\n */\n @Input() placement: AvailbleBSPositions = 'top';\n /**\n * Close popover on outside click\n */\n @Input() outsideClick = false;\n /**\n * Specifies events that should trigger. Supports a space separated list of\n * event names.\n */\n @Input() triggers = 'click';\n /**\n * A selector specifying the element the popover should be appended to.\n */\n @Input() container?: string;\n\n /**\n * Css class for popover container\n */\n @Input() containerClass = '';\n\n /**\n * Returns whether or not the popover is currently being shown\n */\n @Input()\n get isOpen(): boolean {\n return this._popover.isShown;\n }\n\n set isOpen(value: boolean) {\n if (value) {\n this.show();\n } else {\n this.hide();\n }\n }\n\n /**\n * Delay before showing the tooltip\n */\n @Input() delay = 0;\n\n /**\n * Emits an event when the popover is shown\n */\n @Output() onShown: EventEmitter<unknown>;\n /**\n * Emits an event when the popover is hidden\n */\n @Output() onHidden: EventEmitter<unknown>;\n\n protected _popoverCancelShowFn?: () => void;\n\n protected _delayTimeoutId?: number;\n\n private _popover: ComponentLoader<PopoverContainerComponent>;\n private _isInited = false;\n private _ariaDescribedby?: string;\n\n constructor(\n _config: PopoverConfig,\n private _elementRef: ElementRef,\n private _renderer: Renderer2,\n _viewContainerRef: ViewContainerRef,\n cis: ComponentLoaderFactory,\n private _positionService: PositioningService\n ) {\n this._popover = cis\n .createLoader<PopoverContainerComponent>(\n _elementRef,\n _viewContainerRef,\n _renderer\n )\n .provide({provide: PopoverConfig, useValue: _config});\n\n Object.assign(this, _config);\n\n this.onShown = this._popover.onShown;\n this.onHidden = this._popover.onHidden;\n\n // fix: no focus on button on Mac OS #1795\n if (typeof window !== 'undefined') {\n _elementRef.nativeElement.addEventListener('click', function () {\n try {\n _elementRef.nativeElement.focus();\n } catch (err) {\n return;\n }\n });\n }\n }\n\n /**\n * Set attribute aria-describedBy for element directive and\n * set id for the popover\n */\n setAriaDescribedBy(): void {\n this._ariaDescribedby = this.isOpen ? `ngx-popover-${this.popoverId}` : void 0;\n if (this._ariaDescribedby) {\n if (this._popover.instance) {\n this._popover.instance.popoverId = this._ariaDescribedby;\n }\n this._renderer.setAttribute(this._elementRef.nativeElement, 'aria-describedby', this._ariaDescribedby);\n } else {\n this._renderer.removeAttribute(this._elementRef.nativeElement, 'aria-describedby');\n }\n }\n\n /**\n * Opens an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n show(): void {\n if (this._popover.isShown || !this.popover || this._delayTimeoutId) {\n return;\n }\n\n this._positionService.setOptions({\n modifiers: {\n flip: {\n enabled: this.adaptivePosition\n },\n preventOverflow: {\n enabled: this.adaptivePosition\n }\n }\n });\n\n const showPopover = () => {\n if (this._delayTimeoutId) {\n this._delayTimeoutId = undefined;\n }\n\n this._popover\n .attach(PopoverContainerComponent)\n .to(this.container)\n .position({attachment: this.placement})\n .show({\n content: this.popover,\n context: this.popoverContext,\n placement: this.placement,\n title: this.popoverTitle,\n containerClass: this.containerClass\n });\n\n if (!this.adaptivePosition && this._popover._componentRef) {\n this._positionService.calcPosition();\n this._positionService.deletePositionElement(this._popover._componentRef.location);\n }\n\n this.isOpen = true;\n this.setAriaDescribedBy();\n };\n\n const cancelDelayedTooltipShowing = () => {\n if (this._popoverCancelShowFn) {\n this._popoverCancelShowFn();\n }\n };\n\n if (this.delay) {\n const _timer = timer(this.delay).subscribe(() => {\n showPopover();\n cancelDelayedTooltipShowing();\n });\n\n if (this.triggers) {\n parseTriggers(this.triggers)\n .forEach((trigger: Trigger) => {\n if (!trigger.close) {\n return;\n }\n\n this._popoverCancelShowFn = this._renderer.listen(\n this._elementRef.nativeElement,\n trigger.close,\n () => {\n _timer.unsubscribe();\n cancelDelayedTooltipShowing();\n }\n );\n });\n }\n } else {\n showPopover();\n }\n }\n\n /**\n * Closes an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n hide(): void {\n if (this._delayTimeoutId) {\n clearTimeout(this._delayTimeoutId);\n this._delayTimeoutId = undefined;\n }\n\n if (this.isOpen) {\n this._popover.hide();\n this.setAriaDescribedBy();\n this.isOpen = false;\n }\n }\n\n /**\n * Toggles an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n toggle(): void {\n if (this.isOpen) {\n return this.hide();\n }\n\n this.show();\n }\n\n ngOnInit(): void {\n // fix: seems there are an issue with `routerLinkActive`\n // which result in duplicated call ngOnInit without call to ngOnDestroy\n // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885\n if (this._isInited) {\n return;\n }\n this._isInited = true;\n\n this._popover.listen({\n triggers: this.triggers,\n outsideClick: this.outsideClick,\n show: () => this.show(),\n hide: () => this.hide()\n });\n }\n\n ngOnDestroy(): void {\n this._popover.dispose();\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\nimport { CommonModule } from '@angular/common';\n\nimport { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';\nimport { PositioningService } from 'ngx-bootstrap/positioning';\nimport { PopoverDirective } from './popover.directive';\nimport { PopoverContainerComponent } from './popover-container.component';\n\n@NgModule({\n imports: [CommonModule],\n declarations: [PopoverDirective, PopoverContainerComponent],\n exports: [PopoverDirective],\n entryComponents: [PopoverContainerComponent]\n})\nexport class PopoverModule {\n static forRoot(): ModuleWithProviders<PopoverModule> {\n return {\n ngModule: PopoverModule,\n providers: [ComponentLoaderFactory, PositioningService]\n };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;MASa,aAAa;IAH1B;;QAKE,qBAAgB,GAAG,IAAI,CAAC;;;;QAIxB,cAAS,GAAG,KAAK,CAAC;;;;;QAKlB,aAAQ,GAAG,OAAO,CAAC;QAEnB,iBAAY,GAAG,KAAK,CAAC;;QAMrB,UAAK,GAAG,CAAC,CAAC;KACX;;;;YAvBA,UAAU,SAAC;gBACV,UAAU,EAAE,MAAM;aACnB;;;MCgCY,yBAAyB;IAmBpC,YAAY,MAAqB;QANjC,eAAU,GAAG,KAAK,CAAC;QAOjB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KAC7B;IApBD,IAAa,SAAS,CAAC,KAA0B;QAC/C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;YAC3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