UNPKG

ng-zorro-antd

Version:

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

186 lines 24.1 kB
import { __decorate } from "tslib"; import { DOCUMENT } from '@angular/common'; import { Directive, Inject, Input, Optional } from '@angular/core'; import { fromEvent, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { WithConfig } from 'ng-zorro-antd/core/config'; import { InputBoolean } from 'ng-zorro-antd/core/util'; import { NZ_DEFAULT_SCALE_STEP } from './image-preview.component'; import * as i0 from "@angular/core"; import * as i1 from "ng-zorro-antd/core/config"; import * as i2 from "./image.service"; import * as i3 from "./image-group.component"; import * as i4 from "@angular/cdk/bidi"; const NZ_CONFIG_MODULE_NAME = 'image'; export class NzImageDirective { get previewable() { return !this.nzDisablePreview && this.status !== 'error'; } constructor(document, nzConfigService, elementRef, nzImageService, cdr, parentGroup, directionality) { this.document = document; this.nzConfigService = nzConfigService; this.elementRef = elementRef; this.nzImageService = nzImageService; this.cdr = cdr; this.parentGroup = parentGroup; this.directionality = directionality; this._nzModuleName = NZ_CONFIG_MODULE_NAME; this.nzSrc = ''; this.nzSrcset = ''; this.nzDisablePreview = false; this.nzFallback = null; this.nzPlaceholder = null; this.nzScaleStep = null; this.status = 'normal'; this.backLoadDestroy$ = new Subject(); this.destroy$ = new Subject(); } ngOnInit() { this.backLoad(); if (this.parentGroup) { this.parentGroup.addImage(this); } if (this.directionality) { this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => { this.dir = direction; this.cdr.detectChanges(); }); this.dir = this.directionality.value; } } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } onPreview() { if (!this.previewable) { return; } if (this.parentGroup) { // preview inside image group const previewAbleImages = this.parentGroup.images.filter(e => e.previewable); const previewImages = previewAbleImages.map(e => ({ src: e.nzSrc, srcset: e.nzSrcset })); const previewIndex = previewAbleImages.findIndex(el => this === el); const scaleStepMap = new Map(); previewAbleImages.forEach(imageDirective => { scaleStepMap.set(imageDirective.nzSrc ?? imageDirective.nzSrcset, imageDirective.nzScaleStep ?? this.parentGroup.nzScaleStep ?? this.nzScaleStep ?? NZ_DEFAULT_SCALE_STEP); }); const previewRef = this.nzImageService.preview(previewImages, { nzDirection: this.dir }, scaleStepMap); previewRef.switchTo(previewIndex); } else { // preview not inside image group const previewImages = [{ src: this.nzSrc, srcset: this.nzSrcset }]; this.nzImageService.preview(previewImages, { nzDirection: this.dir, nzScaleStep: this.nzScaleStep ?? NZ_DEFAULT_SCALE_STEP }); } } getElement() { return this.elementRef; } ngOnChanges(changes) { const { nzSrc } = changes; if (nzSrc) { this.getElement().nativeElement.src = nzSrc.currentValue; this.backLoad(); } } /** * use internal Image object handle fallback & placeholder * * @private */ backLoad() { this.backLoadImage = this.document.createElement('img'); this.backLoadImage.src = this.nzSrc; this.backLoadImage.srcset = this.nzSrcset; this.status = 'loading'; // unsubscribe last backLoad this.backLoadDestroy$.next(); this.backLoadDestroy$.complete(); this.backLoadDestroy$ = new Subject(); if (this.backLoadImage.complete) { this.status = 'normal'; this.getElement().nativeElement.src = this.nzSrc; this.getElement().nativeElement.srcset = this.nzSrcset; } else { if (this.nzPlaceholder) { this.getElement().nativeElement.src = this.nzPlaceholder; this.getElement().nativeElement.srcset = ''; } else { this.getElement().nativeElement.src = this.nzSrc; this.getElement().nativeElement.srcset = this.nzSrcset; } // The `nz-image` directive can be destroyed before the `load` or `error` event is dispatched, // so there's no sense to keep capturing `this`. fromEvent(this.backLoadImage, 'load') .pipe(takeUntil(this.backLoadDestroy$), takeUntil(this.destroy$)) .subscribe(() => { this.status = 'normal'; this.getElement().nativeElement.src = this.nzSrc; this.getElement().nativeElement.srcset = this.nzSrcset; }); fromEvent(this.backLoadImage, 'error') .pipe(takeUntil(this.backLoadDestroy$), takeUntil(this.destroy$)) .subscribe(() => { this.status = 'error'; if (this.nzFallback) { this.getElement().nativeElement.src = this.nzFallback; this.getElement().nativeElement.srcset = ''; } }); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzImageDirective, deps: [{ token: DOCUMENT }, { token: i1.NzConfigService }, { token: i0.ElementRef }, { token: i2.NzImageService }, { token: i0.ChangeDetectorRef }, { token: i3.NzImageGroupComponent, optional: true }, { token: i4.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.4", type: NzImageDirective, isStandalone: true, selector: "img[nz-image]", inputs: { nzSrc: "nzSrc", nzSrcset: "nzSrcset", nzDisablePreview: "nzDisablePreview", nzFallback: "nzFallback", nzPlaceholder: "nzPlaceholder", nzScaleStep: "nzScaleStep" }, host: { listeners: { "click": "onPreview()" } }, exportAs: ["nzImage"], usesOnChanges: true, ngImport: i0 }); } } __decorate([ InputBoolean(), WithConfig() ], NzImageDirective.prototype, "nzDisablePreview", void 0); __decorate([ WithConfig() ], NzImageDirective.prototype, "nzFallback", void 0); __decorate([ WithConfig() ], NzImageDirective.prototype, "nzPlaceholder", void 0); __decorate([ WithConfig() ], NzImageDirective.prototype, "nzScaleStep", void 0); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzImageDirective, decorators: [{ type: Directive, args: [{ selector: 'img[nz-image]', exportAs: 'nzImage', host: { '(click)': 'onPreview()' }, standalone: true }] }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT] }] }, { type: i1.NzConfigService }, { type: i0.ElementRef }, { type: i2.NzImageService }, { type: i0.ChangeDetectorRef }, { type: i3.NzImageGroupComponent, decorators: [{ type: Optional }] }, { type: i4.Directionality, decorators: [{ type: Optional }] }], propDecorators: { nzSrc: [{ type: Input }], nzSrcset: [{ type: Input }], nzDisablePreview: [{ type: Input }], nzFallback: [{ type: Input }], nzPlaceholder: [{ type: Input }], nzScaleStep: [{ type: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1hZ2UuZGl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