[ACS-8959] Introduce new takeUntilDestroyed operator (#4237)

This commit is contained in:
dominikiwanekhyland
2024-11-21 10:49:49 +01:00
committed by GitHub
parent dec6c41e5c
commit adda597f15
52 changed files with 876 additions and 916 deletions

View File

@@ -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 {

View File

@@ -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';