@ngx-dropzone/cdk
Version:
CDK with basic dropzone functionality.
194 lines (185 loc) • 8.51 kB
TypeScript
import * as i0 from '@angular/core';
import { OnInit, OnChanges, DoCheck, OnDestroy, EventEmitter, ElementRef, AfterContentInit, ChangeDetectorRef } from '@angular/core';
import { ValidatorFn, ControlValueAccessor, NgControl } from '@angular/forms';
import { Subject, BehaviorSubject } from 'rxjs';
type BooleanInput = boolean | string | number | null | undefined;
/** Inspired by the Angular Material library, we check our input properties. */
declare function coerceBoolean(value?: BooleanInput): boolean;
/** Allows filtering `null` and `undefined` elements from arrays. */
declare function nonNullable<T>(value: T | null): value is T;
/**
* To achieve a consistent behavior when dropping directories,
* we add an additional property to the `File` object.
* This will only work with the `webkitdirectories` attribute.
*/
type File$1 = globalThis.File & {
relativePath?: string;
};
/**
* A file input element can either be empty,
* hold a single file or hold multiple files.
*/
type FileInputValue = File$1 | File$1[] | null;
/**
* The file input mode controls the value setting strategy.
* - `replace`: Replace the current value with the new value.
* - `append`: Append the new value to the current value if `multiple` is `true`.
*/
type FileInputMode = 'replace' | 'append';
declare class AcceptService {
/**
* Returns `true` if all files match the provided `accept` parameter.
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept)
* for more information.
*/
accepts(fileValue: FileInputValue, accept: string): boolean;
private isAcceptedByExtension;
private isAcceptedByMimeType;
private parseAttribute;
private isValidMimeType;
private isValidExtension;
private isValidToken;
private isAscii;
static ɵfac: i0.ɵɵFactoryDeclaration<AcceptService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<AcceptService>;
}
declare class FileInputValidators {
/**
* Checks if the file size is equal or greater than the minimum size.
* Validates every file within array or single file. Returns no error when null.
*/
static minSize(min: number): ValidatorFn;
/**
* Checks if the file size is equal or smaller than the allowed size.
* Validates every file within array or single file. Returns no error when null.
*/
static maxSize(max: number): ValidatorFn;
/** Checks if all provided files match the specified `accept` value. */
static accept(accept: string): ValidatorFn;
private static validate;
}
declare class FileInputDirective implements ControlValueAccessor, OnInit, OnChanges, DoCheck, OnDestroy {
private _value;
private _parent;
private _focused;
private _touched;
private _errorState;
private _onChange;
private _onTouched;
/** Emits whenever the parent dropzone should re-render. */
readonly stateChanges: Subject<void>;
/** The value of the file input control. */
get _fileValue(): FileInputValue;
set _fileValue(newValue: FileInputValue);
/** Returns the selected value of the file input control (alias as syntactic sugar). */
get value(): FileInputValue;
/** Returns true if the file input has no selected item. */
get empty(): boolean;
/** Returns the error state. */
get errorState(): boolean;
/** Returns true if the file input element is focused. */
get focused(): boolean;
/** Returns true if the `multiple` attribute is present on the input element. */
get multiple(): boolean;
/** Controls the accepted file types. */
get accept(): string;
set accept(value: string);
private _accept;
/** Controls the value setting strategy. */
get mode(): FileInputMode;
set mode(value: FileInputMode);
private _mode;
/** The disabled state of the file input control. */
get disabled(): boolean;
set disabled(value: BooleanInput);
/** Event emitted when the selected files have been changed by the user. */
readonly selectionChange: EventEmitter<FileInputValue>;
static ngAcceptInputType_disabled: BooleanInput;
private _acceptService;
private _parentForm;
private _parentFormGroup;
elementRef: ElementRef<any>;
ngControl: NgControl | null;
constructor();
ngOnInit(): void;
ngOnChanges(): void;
ngDoCheck(): void;
ngOnDestroy(): void;
/** Opens the native OS file picker. */
openFilePicker(): void;
/** Handles the native (change) event. */
_handleChange(fileList: FileList): void;
/** Handles the drop of a file array. */
handleFileDrop(files: File[]): void;
/** Sets the selected files value as required by the `ControlValueAccessor` interface. */
writeValue(value: FileInputValue): void;
/** Registers the change handler as required by `ControlValueAccessor`. */
registerOnChange(fn: (value: FileInputValue) => void): void;
/** Registers the touched handler as required by `ControlValueAccessor`. */
registerOnTouched(fn: () => void): void;
/** Implements the disabled state setter from `ControlValueAccessor`. */
setDisabledState(disabled: boolean): void;
/** Called when the input element is focused or blurred. */
_focusChanged(focused: boolean): void;
/**
* On directory drops, the readonly `webkitRelativePath` property is not available.
* We manually set the `relativePath` property for dropped file trees instead.
* To achieve a consistent behavior when using the file picker, we copy the value.
*/
private _copyRelativePaths;
/** Asserts that the provided value type matches the input element's multiple attribute. */
private _assertMultipleValue;
private _appendOrReplace;
private _canAppend;
private _updateErrorState;
static ɵfac: i0.ɵɵFactoryDeclaration<FileInputDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<FileInputDirective, "input[fileInput]", ["fileInput"], { "_fileValue": { "alias": "value"; "required": false; }; "accept": { "alias": "accept"; "required": false; }; "mode": { "alias": "mode"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; }, { "selectionChange": "selectionChange"; }, never, never, true, never>;
}
declare class DropzoneService {
/**
* Returns a `File[]` from a `DragEvent`. Accepts a list of files or folders.
*/
getFiles(event: DragEvent): Promise<File$1[]>;
private _toFileSystemEntry;
private _getFilesFromEntry;
/**
* In Chrome >= 77, the `readEntries` method returns only 100 files.
* To achieve a consistent behavior across browsers and not restrict user interaction,
* we break the limit by recursively calling `readEntries`.
*/
private _readDirectoryWithoutLimit;
private _isFile;
private _isDirectory;
private _flattenFiles;
private _readFilePromise;
private _readDirectoryPromise;
static ɵfac: i0.ɵɵFactoryDeclaration<DropzoneService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DropzoneService>;
}
declare class DropzoneComponent implements AfterContentInit, OnDestroy {
protected _destroy$: Subject<void>;
protected _changeDetectorRef: ChangeDetectorRef;
protected _dropzoneService: DropzoneService;
readonly fileInputDirective: FileInputDirective | null;
readonly dragover$: BehaviorSubject<boolean>;
get isDragover(): boolean;
get disabled(): boolean;
get focused(): boolean;
get errorState(): boolean;
get value(): FileInputValue;
set value(newValue: FileInputValue);
ngAfterContentInit(): void;
ngOnDestroy(): void;
/** Opens the native OS file picker. */
openFilePicker(): void;
/** Forwards styling property from control to host element. */
_forwardProp(prop: keyof NgControl): boolean;
_onDragOver: (event: DragEvent) => void;
_onDragEnter: (event: DragEvent) => void;
_onDragLeave: (event: DragEvent) => void;
_onDrop: (event: DragEvent) => Promise<void>;
static ɵfac: i0.ɵɵFactoryDeclaration<DropzoneComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<DropzoneComponent, "ngx-dropzone", ["dropzone"], { "value": { "alias": "value"; "required": false; }; }, {}, ["fileInputDirective"], ["*"], true, never>;
}
export { AcceptService, DropzoneComponent, DropzoneService, FileInputDirective, FileInputValidators, coerceBoolean, nonNullable };
export type { BooleanInput, File$1 as File, FileInputMode, FileInputValue };