UNPKG

@delon/abc

Version:

Common business components of ng-alain.

132 lines (127 loc) 6.32 kB
import { Directionality } from '@angular/cdk/bidi'; import { Platform } from '@angular/cdk/platform'; import { DOCUMENT, CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { inject, ElementRef, ChangeDetectorRef, DestroyRef, numberAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, NgModule } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { interval } from 'rxjs'; import { NzIconDirective, NzIconModule } from 'ng-zorro-antd/icon'; import * as i1 from '@delon/util/config'; class ErrorCollectComponent { constructor(configSrv) { this.el = inject(ElementRef).nativeElement; this.cdr = inject(ChangeDetectorRef); this.doc = inject(DOCUMENT); this.directionality = inject(Directionality); this.platform = inject(Platform); this.destroy$ = inject(DestroyRef); this.formEl = null; this._hiden = true; this.count = 0; this.dir = 'ltr'; configSrv.attach(this, 'errorCollect', { freq: 500, offsetTop: 65 + 64 + 8 * 2 }); } get errEls() { return this.formEl.querySelectorAll('.ant-form-item-has-error'); } update() { const count = this.errEls.length; if (count === this.count) return; this.count = count; this._hiden = count === 0; this.cdr.markForCheck(); } _click() { if (this.count === 0) return false; // nz-form-control const els = this.errEls; const formItemEl = this.findParent(els[0], '[nz-form-control]') || els[0]; formItemEl.scrollIntoView(true); // fix header height this.doc.documentElement.scrollTop -= this.offsetTop; return true; } install() { this.dir = this.directionality.value; this.directionality.change.pipe(takeUntilDestroyed(this.destroy$)).subscribe(direction => { this.dir = direction; this.cdr.detectChanges(); }); interval(this.freq) .pipe(takeUntilDestroyed(this.destroy$)) .subscribe(() => this.update()); this.update(); } findParent(el, selector) { let retEl = null; while (el) { if (el.querySelector(selector)) { retEl = el; break; } el = el.parentElement; } return retEl; } ngOnInit() { if (!this.platform.isBrowser) return; this.formEl = this.findParent(this.el, 'form'); if (this.formEl === null) throw new Error('No found form element'); this.install(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectComponent, deps: [{ token: i1.AlainConfigService }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "18.0.5", type: ErrorCollectComponent, isStandalone: true, selector: "error-collect, [error-collect]", inputs: { freq: ["freq", "freq", numberAttribute], offsetTop: ["offsetTop", "offsetTop", numberAttribute] }, host: { listeners: { "click": "_click()" }, properties: { "class.error-collect": "true", "class.error-collect-rtl": "dir === 'rtl'", "class.d-none": "_hiden" } }, exportAs: ["errorCollect"], ngImport: i0, template: ` <i nz-icon nzType="exclamation-circle"></i> <span class="error-collect__count">{{ count }}</span> `, isInline: true, dependencies: [{ kind: "directive", type: NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectComponent, decorators: [{ type: Component, args: [{ selector: 'error-collect, [error-collect]', exportAs: 'errorCollect', template: ` <i nz-icon nzType="exclamation-circle"></i> <span class="error-collect__count">{{ count }}</span> `, host: { '[class.error-collect]': 'true', '[class.error-collect-rtl]': `dir === 'rtl'`, '[class.d-none]': '_hiden', '(click)': '_click()' }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, standalone: true, imports: [NzIconDirective] }] }], ctorParameters: () => [{ type: i1.AlainConfigService }], propDecorators: { freq: [{ type: Input, args: [{ transform: numberAttribute }] }], offsetTop: [{ type: Input, args: [{ transform: numberAttribute }] }] } }); const COMPONENTS = [ErrorCollectComponent]; class ErrorCollectModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectModule, imports: [CommonModule, NzIconModule, ErrorCollectComponent], exports: [ErrorCollectComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectModule, imports: [CommonModule, NzIconModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.5", ngImport: i0, type: ErrorCollectModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, NzIconModule, ...COMPONENTS], exports: COMPONENTS }] }] }); /** * Generated bundle index. Do not edit. */ export { ErrorCollectComponent, ErrorCollectModule }; //# sourceMappingURL=error-collect.mjs.map