mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACS-8959] Introduce new takeUntilDestroyed
operator (#4237)
This commit is contained in:
committed by
GitHub
parent
dec6c41e5c
commit
adda597f15
@@ -22,31 +22,28 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Directive, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
|
||||
import { fromEvent, Subscription } from 'rxjs';
|
||||
import { DestroyRef, Directive, EventEmitter, inject, OnInit, Output } from '@angular/core';
|
||||
import { fromEvent } from 'rxjs';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
|
||||
@Directive({
|
||||
standalone: true,
|
||||
selector: '[acaContextMenuOutsideEvent]'
|
||||
})
|
||||
export class OutsideEventDirective implements OnInit, OnDestroy {
|
||||
private subscriptions: Subscription[] = [];
|
||||
|
||||
export class OutsideEventDirective implements OnInit {
|
||||
@Output()
|
||||
clickOutside: EventEmitter<void> = new EventEmitter();
|
||||
|
||||
ngOnInit() {
|
||||
this.subscriptions = this.subscriptions.concat([
|
||||
fromEvent(document.body, 'click')
|
||||
.pipe(filter((event) => !this.findAncestor(event.target as Element)))
|
||||
.subscribe(() => this.clickOutside.next())
|
||||
]);
|
||||
}
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
|
||||
this.subscriptions = [];
|
||||
ngOnInit() {
|
||||
fromEvent(document.body, 'click')
|
||||
.pipe(
|
||||
filter((event) => !this.findAncestor(event.target as Element)),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
)
|
||||
.subscribe(() => this.clickOutside.next());
|
||||
}
|
||||
|
||||
private findAncestor(el: Element): boolean {
|
||||
|
@@ -22,7 +22,7 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, ViewEncapsulation, OnInit, AfterViewInit, Inject, inject, DestroyRef } from '@angular/core';
|
||||
import { AfterViewInit, Component, DestroyRef, inject, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { DynamicExtensionComponent } from '@alfresco/adf-extensions';
|
||||
import { ContextMenuOverlayRef } from './context-menu-overlay';
|
||||
|
Reference in New Issue
Block a user