UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

61 lines 10.7 kB
import { OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; import { ComponentPortal } from '@angular/cdk/portal'; import { Injectable, Injector, Optional } from '@angular/core'; import { NZ_CONFIG_MODULE_NAME } from './image-config'; import { NzImagePreviewOptions } from './image-preview-options'; import { NzImagePreviewRef } from './image-preview-ref'; import { NzImagePreviewComponent } from './image-preview.component'; import * as i0 from "@angular/core"; import * as i1 from "@angular/cdk/overlay"; import * as i2 from "ng-zorro-antd/core/config"; import * as i3 from "@angular/cdk/bidi"; export class NzImageService { constructor(overlay, injector, nzConfigService, directionality) { this.overlay = overlay; this.injector = injector; this.nzConfigService = nzConfigService; this.directionality = directionality; } preview(images, options, zoomMap) { return this.display(images, options, zoomMap); } display(images, config, scaleStepMap) { const configMerged = { ...new NzImagePreviewOptions(), ...(config ?? {}) }; const overlayRef = this.createOverlay(configMerged); const previewComponent = this.attachPreviewComponent(overlayRef, configMerged); previewComponent.setImages(images, scaleStepMap); const previewRef = new NzImagePreviewRef(previewComponent, configMerged, overlayRef); previewComponent.previewRef = previewRef; return previewRef; } attachPreviewComponent(overlayRef, config) { const injector = Injector.create({ parent: this.injector, providers: [ { provide: OverlayRef, useValue: overlayRef }, { provide: NzImagePreviewOptions, useValue: config } ] }); const containerPortal = new ComponentPortal(NzImagePreviewComponent, null, injector); const containerRef = overlayRef.attach(containerPortal); return containerRef.instance; } createOverlay(config) { const globalConfig = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME) || {}; const overLayConfig = new OverlayConfig({ scrollStrategy: this.overlay.scrollStrategies.block(), positionStrategy: this.overlay.position().global(), disposeOnNavigation: config.nzCloseOnNavigation ?? globalConfig.nzCloseOnNavigation ?? true, direction: config.nzDirection || globalConfig.nzDirection || this.directionality.value }); return this.overlay.create(overLayConfig); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzImageService, deps: [{ token: i1.Overlay }, { token: i0.Injector }, { token: i2.NzConfigService }, { token: i3.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzImageService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzImageService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.Overlay }, { type: i0.Injector }, { type: i2.NzConfigService }, { type: i3.Directionality, decorators: [{ type: Optional }] }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1hZ2Uuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL2NvbXBvbmVudHMvaW1hZ2UvaW1hZ2Uuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQVcsYUFBYSxFQUFFLFVBQVUsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQzFFLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN0RCxPQUFPLEVBQUUsVUFBVSxFQUFFLFFBQVEsRUFBRSxRQUFRLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFJL0QsT0FBTyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDdkQsT0FBTyxFQUFXLHFCQUFxQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDekUsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDeEQsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sMkJBQTJCLENBQUM7Ozs7O0FBUXBFLE1BQU0sT0FBTyxjQUFjO0lBQ3pCLFlBQ1UsT0FBZ0IsRUFDaEIsUUFBa0IsRU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