blob: 6fb62267a52d91dc41bfda1eabd1d0ad53c9bdd9 [file] [log] [blame]
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/material/icon"),require("@angular/material/button"),require("@angular/cdk/coercion"),require("@angular/cdk/portal"),require("@covalent/core/common"),require("@angular/forms"),require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("@covalent/core/file",["exports","@angular/common","@angular/material/icon","@angular/material/button","@angular/cdk/coercion","@angular/cdk/portal","@covalent/core/common","@angular/forms","@angular/core","rxjs"],t):t((e.covalent=e.covalent||{},e.covalent.core=e.covalent.core||{},e.covalent.core.file={}),e.ng.common,e.ng.material.icon,e.ng.material.button,e.ng.cdk.coercion,e.ng.cdk.portal,e.covalent.core.common,e.ng.forms,e.ng.core,e.rxjs)}(this,function(e,t,n,r,o,i,l,a,p,u){"use strict";var c=(Object.defineProperty(s.prototype,"multiple",{set:function(e){this._multiple=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"multipleBinding",{get:function(){return this._multiple?"":undefined},enumerable:!0,configurable:!0}),s.prototype.onChange=function(e){if(e.target instanceof HTMLInputElement){var t=e.target.files;if(t.length){var n=this._multiple&&1<t.length?t:t[0];this.model?this.model.update.emit(n):this.onFileSelect.emit(n)}}},s.decorators=[{type:p.Directive,args:[{selector:"[tdFileSelect]"}]}],s.ctorParameters=function(){return[{type:a.NgModel,decorators:[{type:p.Optional},{type:p.Host}]}]},s.propDecorators={multiple:[{type:p.Input,args:["multiple"]}],onFileSelect:[{type:p.Output,args:["fileSelect"]}],multipleBinding:[{type:p.HostBinding,args:["attr.multiple"]}],onChange:[{type:p.HostListener,args:["change",["$event"]]}]},s);function s(e){this.model=e,this._multiple=!1,this.onFileSelect=new p.EventEmitter}var d=function(e,t){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function f(e,t){function n(){this.constructor=e}d(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function m(){}var g,h=l.mixinDisabled(m),y=(f(v,g=h),Object.defineProperty(v.prototype,"multiple",{set:function(e){this._multiple=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"multipleBinding",{get:function(){return this._multiple?"":undefined},enumerable:!0,configurable:!0}),Object.defineProperty(v.prototype,"disabledBinding",{get:function(){return this.disabled?"":undefined},enumerable:!0,configurable:!0}),v.prototype.onDrop=function(e){if(!this.disabled){var t=e.dataTransfer.files;if(t.length){var n=this._multiple&&1<t.length?t:t[0];this.onFileDrop.emit(n)}}this._renderer.removeClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},v.prototype.onDragOver=function(e){var t=e.dataTransfer;t.dropEffect=this._typeCheck(t.types),this.disabled||!this._multiple&&(t.items&&1<t.items.length||1<t.mozItemCount)?t.dropEffect="none":t.dropEffect="copy",this._stopEvent(e)},v.prototype.onDragEnter=function(e){this.disabled||this._renderer.addClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},v.prototype.onDragLeave=function(e){this._renderer.removeClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},v.prototype._typeCheck=function(e){var t="none";return e&&(e.contains&&e.contains("Files")||e.indexOf&&-1!==e.indexOf("Files"))&&(t="copy"),t},v.prototype._stopEvent=function(e){e.preventDefault(),e.stopPropagation()},v.decorators=[{type:p.Directive,args:[{selector:"[tdFileDrop]",inputs:["disabled"]}]}],v.ctorParameters=function(){return[{type:p.Renderer2},{type:p.ElementRef}]},v.propDecorators={multiple:[{type:p.Input,args:["multiple"]}],onFileDrop:[{type:p.Output,args:["fileDrop"]}],multipleBinding:[{type:p.HostBinding,args:["attr.multiple"]}],disabledBinding:[{type:p.HostBinding,args:["attr.disabled"]}],onDrop:[{type:p.HostListener,args:["drop",["$event"]]}],onDragOver:[{type:p.HostListener,args:["dragover",["$event"]]}],onDragEnter:[{type:p.HostListener,args:["dragenter",["$event"]]}],onDragLeave:[{type:p.HostListener,args:["dragleave",["$event"]]}]},v);function v(e,t){var n=g.call(this)||this;return n._renderer=e,n._element=t,n._multiple=!1,n.onFileDrop=new p.EventEmitter,n}var b,_=(f(D,b=i.TemplatePortalDirective),D.decorators=[{type:p.Directive,args:[{selector:"[td-file-input-label]ng-template"}]}],D.ctorParameters=function(){return[{type:p.TemplateRef},{type:p.ViewContainerRef}]},D);function D(e,t){return b.call(this,e,t)||this}function C(e){this._changeDetectorRef=e}var E,O=l.mixinControlValueAccessor(l.mixinDisabled(C)),x=(f(P,E=O),Object.defineProperty(P.prototype,"inputElement",{get:function(){return this._inputElement.nativeElement},enumerable:!0,configurable:!0}),Object.defineProperty(P.prototype,"multiple",{get:function(){return this._multiple},set:function(e){this._multiple=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),P.prototype.handleSelect=function(e){this.writeValue(e),this.onSelect.emit(e)},P.prototype.clear=function(){this.writeValue(undefined),this._renderer.setProperty(this.inputElement,"value","")},P.prototype.onDisabledChange=function(e){e&&this.clear()},P.prototype.setDisabledState=function(e){this.disabled=e},P.decorators=[{type:p.Component,args:[{changeDetection:p.ChangeDetectionStrategy.OnPush,providers:[{provide:a.NG_VALUE_ACCESSOR,useExisting:p.forwardRef(function(){return P}),multi:!0}],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}"]}]}],P.ctorParameters=function(){return[{type:p.Renderer2},{type:p.ChangeDetectorRef}]},P.propDecorators={_inputElement:[{type:p.ViewChild,args:["fileInput"]}],color:[{type:p.Input,args:["color"]}],multiple:[{type:p.Input,args:["multiple"]}],accept:[{type:p.Input,args:["accept"]}],onSelect:[{type:p.Output,args:["select"]}]},P);function P(e,t){var n=E.call(this,t)||this;return n._renderer=e,n._multiple=!1,n.onSelect=new p.EventEmitter,n}function S(e){this._changeDetectorRef=e}var I,F=l.mixinControlValueAccessor(l.mixinDisabled(S)),j=(f(w,I=F),Object.defineProperty(w.prototype,"multiple",{get:function(){return this._multiple},set:function(e){this._multiple=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"required",{get:function(){return this._required},set:function(e){this._required=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),w.prototype.uploadPressed=function(){this.value&&this.onUpload.emit(this.value)},w.prototype.handleSelect=function(e){this.value=e,this.onSelect.emit(e)},w.prototype.cancel=function(){this.value=undefined,this.onCancel.emit(undefined),this.fileInput&&this.fileInput.clear()},w.prototype.onDisabledChange=function(e){e&&this.cancel()},w.decorators=[{type:p.Component,args:[{changeDetection:p.ChangeDetectionStrategy.OnPush,providers:[{provide:a.NG_VALUE_ACCESSOR,useExisting:p.forwardRef(function(){return w}),multi:!0}],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}"]}]}],w.ctorParameters=function(){return[{type:p.ChangeDetectorRef}]},w.propDecorators={fileInput:[{type:p.ViewChild,args:[x]}],inputLabel:[{type:p.ContentChild,args:[_]}],defaultColor:[{type:p.Input,args:["defaultColor"]}],activeColor:[{type:p.Input,args:["activeColor"]}],cancelColor:[{type:p.Input,args:["cancelColor"]}],multiple:[{type:p.Input,args:["multiple"]}],required:[{type:p.Input,args:["required"]}],accept:[{type:p.Input,args:["accept"]}],onSelect:[{type:p.Output,args:["select"]}],onUpload:[{type:p.Output,args:["upload"]}],onCancel:[{type:p.Output,args:["cancel"]}]},w);function w(e){var t=I.call(this,e)||this;return t._multiple=!1,t._required=!1,t.defaultColor="primary",t.activeColor="accent",t.cancelColor="warn",t.onSelect=new p.EventEmitter,t.onUpload=new p.EventEmitter,t.onCancel=new p.EventEmitter,t}var B=(Object.defineProperty(q.prototype,"progress",{get:function(){return this._progressObservable},enumerable:!0,configurable:!0}),q.prototype.upload=function(o){var i=this;return new u.Observable(function(e){var t=new XMLHttpRequest,n=new FormData;if(o.file!==undefined)n.append("file",o.file);else{if(o.formData===undefined)return e.error("For [IUploadOptions] you have to set either the [file] or the [formData] property.");n=o.formData}if(t.upload.onprogress=function(e){var t=0;e.lengthComputable&&(t=Math.round(e.loaded/e.total*100)),i._progressSubject.next(t)},t.onreadystatechange=function(){4===t.readyState&&(200<=t.status&&t.status<300?(e.next(t.response),e.complete()):e.error(t.response))},t.open(o.method,o.url,!0),t.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.headers)for(var r in o.headers)t.setRequestHeader(r,o.headers[r]);t.send(n)})},q.decorators=[{type:p.Injectable}],q.ctorParameters=function(){return[]},q);function q(){this._progressSubject=new u.Subject,this._progressObservable=this._progressSubject.asObservable()}var k=[c,y,j,x,_],M=(R.decorators=[{type:p.NgModule,args:[{imports:[a.FormsModule,t.CommonModule,n.MatIconModule,r.MatButtonModule,i.PortalModule],declarations:[k],exports:[k],providers:[B]}]}],R);function R(){}e.CovalentFileModule=M,e.TdFileDropBase=m,e._TdFileDropMixinBase=h,e.TdFileDropDirective=y,e.TdFileSelectDirective=c,e.TdFileInputLabelDirective=_,e.TdFileInputBase=C,e._TdFileInputMixinBase=O,e.TdFileInputComponent=x,e.TdFileUploadBase=S,e._TdFileUploadMixinBase=F,e.TdFileUploadComponent=j,e.TdFileService=B,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=covalent-core-file.umd.min.js.map