UNPKG

@taiga-ui/kit

Version:

Taiga UI Angular main components kit

82 lines (76 loc) 3.42 kB
import * as i0 from '@angular/core'; import { inject, INJECTOR, Component, ChangeDetectionStrategy } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; import { TuiDialogService } from '@taiga-ui/core/components/dialog'; import { PolymorpheusComponent } from '@taiga-ui/polymorpheus'; import { from, of, switchMap } from 'rxjs'; function tuiGenerateDialogableRoute(component, { path = '', outlet = '', ...dialogOptions } = {}) { return { path, outlet, loadComponent: async () => Promise.resolve().then(function () { return routableDialog_component; }), data: { dialog: component, backUrl: path .split('/') .map(() => '..') .join('/'), isLazy: path === '', dialogOptions, }, }; } class TuiRoutableDialog { constructor() { this.route = inject(ActivatedRoute); this.router = inject(Router); this.injector = inject(INJECTOR); this.initialUrl = this.router.url; this.dialog = inject(TuiDialogService); const dialog = this.route.snapshot.data['dialog']; from(isClass(dialog) ? of(dialog) : dialog().then((m) => m.default ?? m)) .pipe(switchMap((dialog) => this.dialog.open(new PolymorpheusComponent(dialog, this.injector), this.route.snapshot.data['dialogOptions'])), takeUntilDestroyed()) .subscribe({ complete: () => this.onDialogClosing() }); } get lazyLoadedBackUrl() { return (this.route.parent?.snapshot.url || []).map(() => '..').join('/'); } onDialogClosing() { if (this.initialUrl === this.router.url) { this.navigateToParent(); } } navigateToParent() { const backUrl = this.route.snapshot.data['isLazy'] ? this.lazyLoadedBackUrl : this.route.snapshot.data['backUrl']; void this.router.navigate([backUrl], { relativeTo: this.route, }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiRoutableDialog, deps: [], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TuiRoutableDialog, isStandalone: true, selector: "tui-routable-dialog", ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiRoutableDialog, decorators: [{ type: Component, args: [{ standalone: true, selector: 'tui-routable-dialog', template: '', changeDetection: ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return []; } }); function isClass(fn) { return (typeof fn === 'function' && Object.getOwnPropertyDescriptor(fn, 'prototype')?.writable === false); } var routableDialog_component = /*#__PURE__*/Object.freeze({ __proto__: null, default: TuiRoutableDialog }); /** * Generated bundle index. Do not edit. */ export { tuiGenerateDialogableRoute }; //# sourceMappingURL=taiga-ui-kit-components-routable-dialog.mjs.map