UNPKG

file-input-accessor

Version:

Angular directive that provides file input functionality in reactive & template driven Angular forms.

79 lines (74 loc) 3.58 kB
import * as i0 from '@angular/core'; import { Renderer2, ElementRef } from '@angular/core'; import * as i2 from '@angular/forms'; import { ControlValueAccessor, AsyncValidator, AsyncValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms'; import { Observable, ReplaySubject } from 'rxjs'; declare class FileInputAccessor implements ControlValueAccessor, AsyncValidator { private _renderer; private _elementRef; allowedTypes: RegExp | string | string[]; size: number; withMeta: boolean; maxHeight: number; maxWidth: number; minHeight: number; minWidth: number; set allowedExt(value: RegExp | string | string[]); get allowedExt(): RegExp | string | string[]; validator: AsyncValidatorFn; private _allowedExt; onChange: (_: any) => void; onTouched: () => void; constructor(_renderer: Renderer2, _elementRef: ElementRef); writeValue(value: any): void; registerOnChange(fn: (_: any) => {}): void; registerOnTouched(fn: () => {}): void; setDisabledState(isDisabled: boolean): void; validate(c: AbstractControl): Observable<ValidationErrors | null> | Promise<ValidationErrors | null>; /** * Generator method that I used to move the code for the AsyncValidator down here so it didn't * get in my way, way up there ^. */ private generateAsyncValidator; /** * Generator method that returns an onChange handler */ private onChangeGenerator; private generateRegExp; /** * The ICustomFile has a ReplaySubject property for text / image files that will emit * once the file has been loaded. Might get removed later since I haven't found a use for it yet. */ private generateFileMeta; private setImage; private setText; static ɵfac: i0.ɵɵFactoryDeclaration<FileInputAccessor, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<FileInputAccessor, "input[type=file][formControl],input[type=file][formControlName],input[type=file][ngModel]", never, { "allowedTypes": { "alias": "allowedTypes"; "required": false; }; "size": { "alias": "size"; "required": false; }; "withMeta": { "alias": "withMeta"; "required": false; }; "maxHeight": { "alias": "maxHeight"; "required": false; }; "maxWidth": { "alias": "maxWidth"; "required": false; }; "minHeight": { "alias": "minHeight"; "required": false; }; "minWidth": { "alias": "minWidth"; "required": false; }; "allowedExt": { "alias": "allowedExt"; "required": false; }; }, {}, never, never, false, never>; } declare class FileInputAccessorModule { static ɵfac: i0.ɵɵFactoryDeclaration<FileInputAccessorModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<FileInputAccessorModule, [typeof FileInputAccessor], [typeof i2.FormsModule, typeof i2.ReactiveFormsModule], [typeof FileInputAccessor, typeof i2.FormsModule, typeof i2.ReactiveFormsModule]>; static ɵinj: i0.ɵɵInjectorDeclaration<FileInputAccessorModule>; } interface ICustomFile extends File { errors?: { imageWidth?: boolean; imageHeight?: boolean; maxWidth?: boolean; maxHeight?: boolean; minWidth?: boolean; minHeight?: boolean; fileSize?: boolean; fileType?: boolean; fileExt?: boolean; }; imgSrc?: string; imgHeight?: number; imgWidth?: number; isImg?: boolean; imgLoadReplay?: ReplaySubject<[Event, ProgressEvent]>; textContent?: string; textLoadReplay?: ReplaySubject<ProgressEvent>; } export { FileInputAccessor, FileInputAccessorModule }; export type { ICustomFile };