UNPKG

12.7 kBSource Map (JSON)View Raw
1{"version":3,"file":"popover.directive.js","sourceRoot":"","sources":["../../../../src/popover/popover.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAqB,MAAM,EACrE,SAAS,EAAe,gBAAgB,EACzC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAmB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAuB,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAW,MAAM,qBAAqB,CAAC;AAE7D,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX;;GAEG;AAEH,MAAM,OAAO,gBAAgB;IAgF3B,YACE,OAAsB,EACd,WAAuB,EACvB,SAAoB,EAC5B,iBAAmC,EACnC,GAA2B,EACnB,gBAAoC;QAJpC,gBAAW,GAAX,WAAW,CAAY;QACvB,cAAS,GAAT,SAAS,CAAW;QAGpB,qBAAgB,GAAhB,gBAAgB,CAAoB;QArF9C,mDAAmD;QACnD,cAAS,GAAG,EAAE,EAAE,CAAC;QACjB,qCAAqC;QAC5B,qBAAgB,GAAG,IAAI,CAAC;QAejC;;WAEG;QACM,cAAS,GAAwB,KAAK,CAAC;QAChD;;WAEG;QACM,iBAAY,GAAG,KAAK,CAAC;QAC9B;;;WAGG;QACM,aAAQ,GAAG,OAAO,CAAC;QAM5B;;WAEG;QACM,mBAAc,GAAG,EAAE,CAAC;QAkB7B;;WAEG;QACM,UAAK,GAAG,CAAC,CAAC;QAgBX,cAAS,GAAG,KAAK,CAAC;QAWxB,IAAI,CAAC,QAAQ,GAAG,GAAG;aAChB,YAAY,CACX,WAAW,EACX,iBAA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E,CAAC;YACrB,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;SACrB;IACH,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;SACpB;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,QAAQ;QACN,wDAAwD;QACxD,uEAAuE;QACvE,yEAAyE;QACzE,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO;SACR;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;YACvB,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;SACxB,CAAC,CAAC;IACL,CAAC;IAED,WAAW;QACT,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;;;YAlQF,SAAS,SAAC,EAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAC;;;YAZjD,aAAa;YAHT,UAAU;YACrB,SAAS;YAAe,gBAAgB;YAGhB,sBAAsB;YAEvC,kBAAkB;;;+BAcxB,KAAK;sBAKL,KAAK;6BAKL,KAAK;2BAIL,KAAK;wBAIL,KAAK;2BAIL,KAAK;uBAKL,KAAK;wBAIL,KAAK;6BAKL,KAAK;qBAKL,KAAK;oBAgBL,KAAK;sBAKL,MAAM;uBAIN,MAAM","sourcesContent":["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"]}
\No newline at end of file