blob: 80a890bde75bb43d40867cf3d38f8b55e67048be [file] [log] [blame]
import { CommonModule } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { __extends } from 'tslib';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { TemplatePortalDirective, PortalModule } from '@angular/cdk/portal';
import { mixinDisabled, mixinControlValueAccessor } from '@covalent/core/common';
import { NgModel, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { Directive, Input, Output, EventEmitter, HostListener, HostBinding, Host, Optional, ElementRef, Renderer2, Component, ChangeDetectionStrategy, ViewChild, TemplateRef, ViewContainerRef, ChangeDetectorRef, forwardRef, ContentChild, Injectable, NgModule } from '@angular/core';
import { Observable, Subject } from 'rxjs';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var TdFileSelectDirective = /** @class */ (function () {
function TdFileSelectDirective(model) {
this.model = model;
this._multiple = false;
/**
* fileSelect?: function
* Event emitted when a file or files are selected in host [HTMLInputElement].
* Emits a [FileList | File] object.
* Alternative to not use [(ngModel)].
*/
this.onFileSelect = new EventEmitter();
}
Object.defineProperty(TdFileSelectDirective.prototype, "multiple", {
/**
* multiple?: boolean
* Sets whether multiple files can be selected at once in host element, or just a single file.
* Can also be 'multiple' native attribute.
*/
set: /**
* multiple?: boolean
* Sets whether multiple files can be selected at once in host element, or just a single file.
* Can also be 'multiple' native attribute.
* @param {?} multiple
* @return {?}
*/
function (multiple) {
this._multiple = coerceBooleanProperty(multiple);
},
enumerable: true,
configurable: true
});
Object.defineProperty(TdFileSelectDirective.prototype, "multipleBinding", {
/**
* Binds native 'multiple' attribute if [multiple] property is 'true'.
*/
get: /**
* Binds native 'multiple' attribute if [multiple] property is 'true'.
* @return {?}
*/
function () {
return this._multiple ? '' : undefined;
},
enumerable: true,
configurable: true
});
/**
* Listens to 'change' host event to get [HTMLInputElement] files.
* Emits the 'onFileSelect' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Uses [(ngModel)] if declared, instead of emitting 'onFileSelect' event.
*/
/**
* Listens to 'change' host event to get [HTMLInputElement] files.
* Emits the 'onFileSelect' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Uses [(ngModel)] if declared, instead of emitting 'onFileSelect' event.
* @param {?} event
* @return {?}
*/
TdFileSelectDirective.prototype.onChange = /**
* Listens to 'change' host event to get [HTMLInputElement] files.
* Emits the 'onFileSelect' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Uses [(ngModel)] if declared, instead of emitting 'onFileSelect' event.
* @param {?} event
* @return {?}
*/
function (event) {
if (event.target instanceof HTMLInputElement) {
/** @type {?} */
var fileInputEl = ((/** @type {?} */ (event.target)));
/** @type {?} */
var files = fileInputEl.files;
if (files.length) {
/** @type {?} */
var value = this._multiple ? (files.length > 1 ? files : files[0]) : files[0];
this.model ? this.model.update.emit(value) : this.onFileSelect.emit(value);
}
}
};
TdFileSelectDirective.decorators = [
{ type: Directive, args: [{
selector: '[tdFileSelect]',
},] }
];
/** @nocollapse */
TdFileSelectDirective.ctorParameters = function () { return [
{ type: NgModel, decorators: [{ type: Optional }, { type: Host }] }
]; };
TdFileSelectDirective.propDecorators = {
multiple: [{ type: Input, args: ['multiple',] }],
onFileSelect: [{ type: Output, args: ['fileSelect',] }],
multipleBinding: [{ type: HostBinding, args: ['attr.multiple',] }],
onChange: [{ type: HostListener, args: ['change', ['$event'],] }]
};
return TdFileSelectDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var TdFileDropBase = /** @class */ (function () {
function TdFileDropBase() {
}
return TdFileDropBase;
}());
/* tslint:disable-next-line */
/** @type {?} */
var _TdFileDropMixinBase = mixinDisabled(TdFileDropBase);
var TdFileDropDirective = /** @class */ (function (_super) {
__extends(TdFileDropDirective, _super);
function TdFileDropDirective(_renderer, _element) {
var _this = _super.call(this) || this;
_this._renderer = _renderer;
_this._element = _element;
_this._multiple = false;
/**
* fileDrop?: function
* Event emitted when a file or files are dropped in host element after being validated.
* Emits a [FileList | File] object.
*/
_this.onFileDrop = new EventEmitter();
return _this;
}
Object.defineProperty(TdFileDropDirective.prototype, "multiple", {
/**
* multiple?: boolean
* Sets whether multiple files can be dropped at once in host element, or just a single file.
* Can also be 'multiple' native attribute.
*/
set: /**
* multiple?: boolean
* Sets whether multiple files can be dropped at once in host element, or just a single file.
* Can also be 'multiple' native attribute.
* @param {?} multiple
* @return {?}
*/
function (multiple) {
this._multiple = coerceBooleanProperty(multiple);
},
enumerable: true,
configurable: true
});
Object.defineProperty(TdFileDropDirective.prototype, "multipleBinding", {
/**
* Binds native 'multiple' attribute if [multiple] property is 'true'.
*/
get: /**
* Binds native 'multiple' attribute if [multiple] property is 'true'.
* @return {?}
*/
function () {
return this._multiple ? '' : undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TdFileDropDirective.prototype, "disabledBinding", {
/**
* Binds native 'disabled' attribute if [disabled] property is 'true'.
*/
get: /**
* Binds native 'disabled' attribute if [disabled] property is 'true'.
* @return {?}
*/
function () {
return this.disabled ? '' : undefined;
},
enumerable: true,
configurable: true
});
/**
* Listens to 'drop' host event to get validated transfer items.
* Emits the 'onFileDrop' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Stops event propagation and default action from browser for 'drop' event.
*/
/**
* Listens to 'drop' host event to get validated transfer items.
* Emits the 'onFileDrop' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Stops event propagation and default action from browser for 'drop' event.
* @param {?} event
* @return {?}
*/
TdFileDropDirective.prototype.onDrop = /**
* Listens to 'drop' host event to get validated transfer items.
* Emits the 'onFileDrop' event with a [FileList] or [File] depending if 'multiple' attr exists in host.
* Stops event propagation and default action from browser for 'drop' event.
* @param {?} event
* @return {?}
*/
function (event) {
if (!this.disabled) {
/** @type {?} */
var transfer = ((/** @type {?} */ (event))).dataTransfer;
/** @type {?} */
var files = transfer.files;
if (files.length) {
/** @type {?} */
var value = this._multiple ? (files.length > 1 ? files : files[0]) : files[0];
this.onFileDrop.emit(value);
}
}
this._renderer.removeClass(this._element.nativeElement, 'drop-zone');
this._stopEvent(event);
};
/**
* Listens to 'dragover' host event to validate transfer items.
* Checks if 'multiple' attr exists in host to allow multiple file drops.
* Stops event propagation and default action from browser for 'dragover' event.
*/
/**
* Listens to 'dragover' host event to validate transfer items.
* Checks if 'multiple' attr exists in host to allow multiple file drops.
* Stops event propagation and default action from browser for 'dragover' event.
* @param {?} event
* @return {?}
*/
TdFileDropDirective.prototype.onDragOver = /**
* Listens to 'dragover' host event to validate transfer items.
* Checks if 'multiple' attr exists in host to allow multiple file drops.
* Stops event propagation and default action from browser for 'dragover' event.
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var transfer = ((/** @type {?} */ (event))).dataTransfer;
transfer.dropEffect = this._typeCheck(transfer.types);
if (this.disabled || (!this._multiple &&
((transfer.items && transfer.items.length > 1) || ((/** @type {?} */ (transfer))).mozItemCount > 1))) {
transfer.dropEffect = 'none';
}
else {
transfer.dropEffect = 'copy';
}
this._stopEvent(event);
};
/**
* Listens to 'dragenter' host event to add animation class 'drop-zone' which can be overriden in host.
* Stops event propagation and default action from browser for 'dragenter' event.
*/
/**
* Listens to 'dragenter' host event to add animation class 'drop-zone' which can be overriden in host.
* Stops event propagation and default action from browser for 'dragenter' event.
* @param {?} event
* @return {?}
*/
TdFileDropDirective.prototype.onDragEnter = /**
* Listens to 'dragenter' host event to add animation class 'drop-zone' which can be overriden in host.
* Stops event propagation and default action from browser for 'dragenter' event.
* @param {?} event
* @return {?}
*/
function (event) {
if (!this.disabled) {
this._renderer.addClass(this._element.nativeElement, 'drop-zone');
}
this._stopEvent(event);
};
/**
* Listens to 'dragleave' host event to remove animation class 'drop-zone'.
* Stops event propagation and default action from browser for 'dragleave' event.
*/
/**
* Listens to 'dragleave' host event to remove animation class 'drop-zone'.
* Stops event propagation and default action from browser for 'dragleave' event.
* @param {?} event
* @return {?}
*/
TdFileDropDirective.prototype.onDragLeave = /**
* Listens to 'dragleave' host event to remove animation class 'drop-zone'.
* Stops event propagation and default action from browser for 'dragleave' event.
* @param {?} event
* @return {?}
*/
function (event) {
this._renderer.removeClass(this._element.nativeElement, 'drop-zone');
this._stopEvent(event);
};
/**
* Validates if the transfer item types are 'Files'.
*/
/**
* Validates if the transfer item types are 'Files'.
* @param {?} types
* @return {?}
*/
TdFileDropDirective.prototype._typeCheck = /**
* Validates if the transfer item types are 'Files'.
* @param {?} types
* @return {?}
*/
function (types) {
/** @type {?} */
var dropEffect = 'none';
if (types) {
if ((((/** @type {?} */ (types))).contains && ((/** @type {?} */ (types))).contains('Files'))
|| (((/** @type {?} */ (types))).indexOf && ((/** @type {?} */ (types))).indexOf('Files') !== -1)) {
dropEffect = 'copy';
}
}
return dropEffect;
};
/**
* @param {?} event
* @return {?}
*/
TdFileDropDirective.prototype._stopEvent = /**
* @param {?} event
* @return {?}
*/
function (event) {
event.preventDefault();
event.stopPropagation();
};
TdFileDropDirective.decorators = [
{ type: Directive, args: [{
selector: '[tdFileDrop]',
inputs: ['disabled'],
},] }
];
/** @nocollapse */
TdFileDropDirective.ctorParameters = function () { return [
{ type: Renderer2 },
{ type: ElementRef }
]; };
TdFileDropDirective.propDecorators = {
multiple: [{ type: Input, args: ['multiple',] }],
onFileDrop: [{ type: Output, args: ['fileDrop',] }],
multipleBinding: [{ type: HostBinding, args: ['attr.multiple',] }],
disabledBinding: [{ type: HostBinding, args: ['attr.disabled',] }],
onDrop: [{ type: HostListener, args: ['drop', ['$event'],] }],
onDragOver: [{ type: HostListener, args: ['dragover', ['$event'],] }],
onDragEnter: [{ type: HostListener, args: ['dragenter', ['$event'],] }],
onDragLeave: [{ type: HostListener, args: ['dragleave', ['$event'],] }]
};
return TdFileDropDirective;
}(_TdFileDropMixinBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var TdFileInputLabelDirective = /** @class */ (function (_super) {
__extends(TdFileInputLabelDirective, _super);
function TdFileInputLabelDirective(templateRef, viewContainerRef) {
return _super.call(this, templateRef, viewContainerRef) || this;
}
TdFileInputLabelDirective.decorators = [
{ type: Directive, args: [{
selector: '[td-file-input-label]ng-template',
},] }
];
/** @nocollapse */
TdFileInputLabelDirective.ctorParameters = function () { return [
{ type: TemplateRef },
{ type: ViewContainerRef }
]; };
return TdFileInputLabelDirective;
}(TemplatePortalDirective));
var TdFileInputBase = /** @class */ (function () {
function TdFileInputBase(_changeDetectorRef) {
this._changeDetectorRef = _changeDetectorRef;
}
return TdFileInputBase;
}());
/* tslint:disable-next-line */
/** @type {?} */
var _TdFileInputMixinBase = mixinControlValueAccessor(mixinDisabled(TdFileInputBase));
var TdFileInputComponent = /** @class */ (function (_super) {
__extends(TdFileInputComponent, _super);
function TdFileInputComponent(_renderer, _changeDetectorRef) {
var _this = _super.call(this, _changeDetectorRef) || this;
_this._renderer = _renderer;
_this._multiple = false;
/**
* select?: function
* Event emitted a file is selected
* Emits a [File | FileList] object.
*/
_this.onSelect = new EventEmitter();
return _this;
}
Object.defineProperty(TdFileInputComponent.prototype, "inputElement", {
get: /**
* @return {?}
*/
function () {
return this._inputElement.nativeElement;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TdFileInputComponent.prototype, "multiple", {
get: /**
* @return {?}
*/
function () {
return this._multiple;
},
/**
* multiple?: boolean
* Sets if multiple files can be dropped/selected at once in [TdFileInputComponent].
*/
set: /**
* multiple?: boolean
* Sets if multiple files can be dropped/selected at once in [TdFileInputComponent].
* @param {?} multiple
* @return {?}
*/
function (multiple) {
this._multiple = coerceBooleanProperty(multiple);
},
enumerable: true,
configurable: true
});
/**
* Method executed when a file is selected.
*/
/**
* Method executed when a file is selected.
* @param {?} files
* @return {?}
*/
TdFileInputComponent.prototype.handleSelect = /**
* Method executed when a file is selected.
* @param {?} files
* @return {?}
*/
function (files) {
this.writeValue(files);
this.onSelect.emit(files);
};
/**
* Used to clear the selected files from the [TdFileInputComponent].
*/
/**
* Used to clear the selected files from the [TdFileInputComponent].
* @return {?}
*/
TdFileInputComponent.prototype.clear = /**
* Used to clear the selected files from the [TdFileInputComponent].
* @return {?}
*/
function () {
this.writeValue(undefined);
this._renderer.setProperty(this.inputElement, 'value', '');
};
/** Method executed when the disabled value changes */
/**
* Method executed when the disabled value changes
* @param {?} v
* @return {?}
*/
TdFileInputComponent.prototype.onDisabledChange = /**
* Method executed when the disabled value changes
* @param {?} v
* @return {?}
*/
function (v) {
if (v) {
this.clear();
}
};
/**
* Sets disable to the component. Implemented as part of ControlValueAccessor.
*/
/**
* Sets disable to the component. Implemented as part of ControlValueAccessor.
* @param {?} isDisabled
* @return {?}
*/
TdFileInputComponent.prototype.setDisabledState = /**
* Sets disable to the component. Implemented as part of ControlValueAccessor.
* @param {?} isDisabled
* @return {?}
*/
function (isDisabled) {
this.disabled = isDisabled;
};
TdFileInputComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return TdFileInputComponent; }),
multi: true,
}],
selector: 'td-file-input',
inputs: ['disabled', 'value'],
template: "<div>\n <button mat-raised-button\n class=\"td-file-input\"\n type=\"button\"\n [color]=\"color\" \n [multiple]=\"multiple\" \n [disabled]=\"disabled\"\n (keyup.enter)=\"fileInput.click()\"\n (click)=\"fileInput.click()\"\n (fileDrop)=\"handleSelect($event)\"\n tdFileDrop>\n <ng-content></ng-content>\n </button>\n <input #fileInput \n class=\"td-file-input-hidden\" \n type=\"file\"\n [attr.accept]=\"accept\" \n (fileSelect)=\"handleSelect($event)\"\n [multiple]=\"multiple\" \n [disabled]=\"disabled\"\n tdFileSelect>\n</div>",
styles: [":host .td-file-input{padding-left:8px;padding-right:8px}:host input.td-file-input-hidden{display:none}:host .drop-zone{border-radius:3px}:host .drop-zone *{pointer-events:none}"]
}] }
];
/** @nocollapse */
TdFileInputComponent.ctorParameters = function () { return [
{ type: Renderer2 },
{ type: ChangeDetectorRef }
]; };
TdFileInputComponent.propDecorators = {
_inputElement: [{ type: ViewChild, args: ['fileInput',] }],
color: [{ type: Input, args: ['color',] }],
multiple: [{ type: Input, args: ['multiple',] }],
accept: [{ type: Input, args: ['accept',] }],
onSelect: [{ type: Output, args: ['select',] }]
};
return TdFileInputComponent;
}(_TdFileInputMixinBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var TdFileUploadBase = /** @class */ (function () {
function TdFileUploadBase(_changeDetectorRef) {
this._changeDetectorRef = _changeDetectorRef;
}
return TdFileUploadBase;
}());
/* tslint:disable-next-line */
/** @type {?} */
var _TdFileUploadMixinBase = mixinControlValueAccessor(mixinDisabled(TdFileUploadBase));
var TdFileUploadComponent = /** @class */ (function (_super) {
__extends(TdFileUploadComponent, _super);
function TdFileUploadComponent(_changeDetectorRef) {
var _this = _super.call(this, _changeDetectorRef) || this;
_this._multiple = false;
_this._required = false;
/**
* defaultColor?: string
* Sets browse button color. Uses same color palette accepted as [MatButton] and defaults to 'primary'.
*/
_this.defaultColor = 'primary';
/**
* activeColor?: string
* Sets upload button color. Uses same color palette accepted as [MatButton] and defaults to 'accent'.
*/
_this.activeColor = 'accent';
/**
* cancelColor?: string
* Sets cancel button color. Uses same color palette accepted as [MatButton] and defaults to 'warn'.
*/
_this.cancelColor = 'warn';
/**
* select?: function
* Event emitted when a file is selected.
* Emits a [File | FileList] object.
*/
_this.onSelect = new EventEmitter();
/**
* upload?: function
* Event emitted when upload button is clicked.
* Emits a [File | FileList] object.
*/
_this.onUpload = new EventEmitter();
/**
* cancel?: function
* Event emitted when cancel button is clicked.
*/
_this.onCancel = new EventEmitter();
return _this;
}
Object.defineProperty(TdFileUploadComponent.prototype, "multiple", {
get: /**
* @return {?}
*/
function () {
return this._multiple;
},
/**
* multiple?: boolean
* Sets if multiple files can be dropped/selected at once in [TdFileUploadComponent].
*/
set: /**
* multiple?: boolean
* Sets if multiple files can be dropped/selected at once in [TdFileUploadComponent].
* @param {?} multiple
* @return {?}
*/
function (multiple) {
this._multiple = coerceBooleanProperty(multiple);
},
enumerable: true,
configurable: true
});
Object.defineProperty(TdFileUploadComponent.prototype, "required", {
get: /**
* @return {?}
*/
function () {
return this._required;
},
/**
* required?: boolean
* Forces at least one file upload.
* Defaults to 'false'
*/
set: /**
* required?: boolean
* Forces at least one file upload.
* Defaults to 'false'
* @param {?} required
* @return {?}
*/
function (required) {
this._required = coerceBooleanProperty(required);
},
enumerable: true,
configurable: true
});
/**
* Method executed when upload button is clicked.
*/
/**
* Method executed when upload button is clicked.
* @return {?}
*/
TdFileUploadComponent.prototype.uploadPressed = /**
* Method executed when upload button is clicked.
* @return {?}
*/
function () {
if (this.value) {
this.onUpload.emit(this.value);
}
};
/**
* Method executed when a file is selected.
*/
/**
* Method executed when a file is selected.
* @param {?} value
* @return {?}
*/
TdFileUploadComponent.prototype.handleSelect = /**
* Method executed when a file is selected.
* @param {?} value
* @return {?}
*/
function (value) {
this.value = value;
this.onSelect.emit(value);
};
/**
* Methods executed when cancel button is clicked.
* Clears files.
*/
/**
* Methods executed when cancel button is clicked.
* Clears files.
* @return {?}
*/
TdFileUploadComponent.prototype.cancel = /**
* Methods executed when cancel button is clicked.
* Clears files.
* @return {?}
*/
function () {
this.value = undefined;
this.onCancel.emit(undefined);
// check if the file input is rendered before clearing it
if (this.fileInput) {
this.fileInput.clear();
}
};
/** Method executed when the disabled value changes */
/**
* Method executed when the disabled value changes
* @param {?} v
* @return {?}
*/
TdFileUploadComponent.prototype.onDisabledChange = /**
* Method executed when the disabled value changes
* @param {?} v
* @return {?}
*/
function (v) {
if (v) {
this.cancel();
}
};
TdFileUploadComponent.decorators = [
{ type: Component, args: [{
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return TdFileUploadComponent; }),
multi: true,
}],
selector: 'td-file-upload',
inputs: ['disabled', 'value'],
template: "<td-file-input *ngIf=\"!value\"\n [(ngModel)]=\"value\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n [accept]=\"accept\"\n [color]=\"defaultColor\"\n (select)=\"handleSelect($event)\">\n <ng-template [cdkPortalOutlet]=\"inputLabel\" [ngIf]=\"true\"></ng-template>\n</td-file-input>\n<div *ngIf=\"value\">\n <button #fileUpload\n class=\"td-file-upload\"\n mat-raised-button\n type=\"button\"\n [color]=\"activeColor\"\n (keyup.delete)=\"cancel()\"\n (keyup.backspace)=\"cancel()\"\n (keyup.escape)=\"cancel()\"\n (click)=\"uploadPressed()\"> \n <ng-content></ng-content>\n </button>\n <button mat-icon-button\n type=\"button\"\n class=\"td-file-upload-cancel\"\n [color]=\"cancelColor\" \n (click)=\"cancel()\">\n <mat-icon>cancel</mat-icon>\n </button>\n</div>",
styles: [".td-file-upload{padding-left:8px;padding-right:8px}.td-file-upload-cancel{height:24px;width:24px;position:relative;top:24px;left:-12px}::ng-deep [dir=rtl] .td-file-upload-cancel{right:-12px;left:0}.td-file-upload-cancel mat-icon{border-radius:12px;vertical-align:baseline}.drop-zone{border-radius:3px}.drop-zone *{pointer-events:none}"]
}] }
];
/** @nocollapse */
TdFileUploadComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef }
]; };
TdFileUploadComponent.propDecorators = {
fileInput: [{ type: ViewChild, args: [TdFileInputComponent,] }],
inputLabel: [{ type: ContentChild, args: [TdFileInputLabelDirective,] }],
defaultColor: [{ type: Input, args: ['defaultColor',] }],
activeColor: [{ type: Input, args: ['activeColor',] }],
cancelColor: [{ type: Input, args: ['cancelColor',] }],
multiple: [{ type: Input, args: ['multiple',] }],
required: [{ type: Input, args: ['required',] }],
accept: [{ type: Input, args: ['accept',] }],
onSelect: [{ type: Output, args: ['select',] }],
onUpload: [{ type: Output, args: ['upload',] }],
onCancel: [{ type: Output, args: ['cancel',] }]
};
return TdFileUploadComponent;
}(_TdFileUploadMixinBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var TdFileService = /** @class */ (function () {
function TdFileService() {
this._progressSubject = new Subject();
this._progressObservable = this._progressSubject.asObservable();
}
Object.defineProperty(TdFileService.prototype, "progress", {
/**
* Gets progress observable to keep track of the files being uploaded.
* Needs to be supported by backend.
*/
get: /**
* Gets progress observable to keep track of the files being uploaded.
* Needs to be supported by backend.
* @return {?}
*/
function () {
return this._progressObservable;
},
enumerable: true,
configurable: true
});
/**
* params:
* - options: IUploadOptions {
* url: string,
* method: 'post' | 'put',
* file?: File,
* headers?: {[key: string]: string},
* formData?: FormData
* }
*
* Uses underlying [XMLHttpRequest] to upload a file to a url.
* Will be depricated when Angular fixes [Http] to allow [FormData] as body.
*/
/**
* params:
* - options: IUploadOptions {
* url: string,
* method: 'post' | 'put',
* file?: File,
* headers?: {[key: string]: string},
* formData?: FormData
* }
*
* Uses underlying [XMLHttpRequest] to upload a file to a url.
* Will be depricated when Angular fixes [Http] to allow [FormData] as body.
* @param {?} options
* @return {?}
*/
TdFileService.prototype.upload = /**
* params:
* - options: IUploadOptions {
* url: string,
* method: 'post' | 'put',
* file?: File,
* headers?: {[key: string]: string},
* formData?: FormData
* }
*
* Uses underlying [XMLHttpRequest] to upload a file to a url.
* Will be depricated when Angular fixes [Http] to allow [FormData] as body.
* @param {?} options
* @return {?}
*/
function (options) {
var _this = this;
return new Observable(function (subscriber) {
/** @type {?} */
var xhr = new XMLHttpRequest();
/** @type {?} */
var formData = new FormData();
if (options.file !== undefined) {
formData.append('file', options.file);
}
else if (options.formData !== undefined) {
formData = options.formData;
}
else {
return subscriber.error('For [IUploadOptions] you have to set either the [file] or the [formData] property.');
}
xhr.upload.onprogress = function (event) {
/** @type {?} */
var progress = 0;
if (event.lengthComputable) {
progress = Math.round(event.loaded / event.total * 100);
}
_this._progressSubject.next(progress);
};
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300) {
subscriber.next(xhr.response);
subscriber.complete();
}
else {
subscriber.error(xhr.response);
}
}
};
xhr.open(options.method, options.url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if (options.headers) {
for (var key in options.headers) {
xhr.setRequestHeader(key, options.headers[key]);
}
}
xhr.send(formData);
});
};
TdFileService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
TdFileService.ctorParameters = function () { return []; };
return TdFileService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/** @type {?} */
var TD_FILE = [
TdFileSelectDirective,
TdFileDropDirective,
TdFileUploadComponent,
TdFileInputComponent,
TdFileInputLabelDirective,
];
var CovalentFileModule = /** @class */ (function () {
function CovalentFileModule() {
}
CovalentFileModule.decorators = [
{ type: NgModule, args: [{
imports: [
FormsModule,
CommonModule,
MatIconModule,
MatButtonModule,
PortalModule,
],
declarations: [
TD_FILE,
],
exports: [
TD_FILE,
],
providers: [
TdFileService,
],
},] }
];
return CovalentFileModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
export { CovalentFileModule, TdFileDropBase, _TdFileDropMixinBase, TdFileDropDirective, TdFileSelectDirective, TdFileInputLabelDirective, TdFileInputBase, _TdFileInputMixinBase, TdFileInputComponent, TdFileUploadBase, _TdFileUploadMixinBase, TdFileUploadComponent, TdFileService };
//# sourceMappingURL=covalent-core-file.js.map