blob: 1d12c11b2b440295cb025d905a0978a5f57dde8c [file] [log] [blame]
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/forms"),require("@angular/cdk/portal"),require("@angular/material/icon"),require("@angular/material/button"),require("@angular/cdk/coercion"),require("@covalent/core/common"),require("@angular/common/http"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@covalent/core/file",["exports","@angular/core","@angular/common","@angular/forms","@angular/cdk/portal","@angular/material/icon","@angular/material/button","@angular/cdk/coercion","@covalent/core/common","@angular/common/http","rxjs","rxjs/operators"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).covalent=e.covalent||{},e.covalent.core=e.covalent.core||{},e.covalent.core.file={}),e.ng.core,e.ng.common,e.ng.forms,e.ng.cdk.portal,e.ng.material.icon,e.ng.material.button,e.ng.cdk.coercion,e.covalent.core.common,e.ng.common.http,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,r,o,i,l,a,p,c,u,s){"use strict";var d=function(){function e(e){this.model=e,this._multiple=!1,this.fileSelect=new t.EventEmitter}return Object.defineProperty(e.prototype,"multiple",{set:function(e){this._multiple=a.coerceBooleanProperty(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"multipleBinding",{get:function(){return this._multiple?"":void 0},enumerable:!1,configurable:!0}),e.prototype.onChange=function(e){if(e.target instanceof HTMLInputElement){var t=e.target.files;if(t.length){var n=this._multiple&&t.length>1?t:t[0];this.model?this.model.update.emit(n):this.fileSelect.emit(n)}}},e}();d.decorators=[{type:t.Directive,args:[{selector:"[tdFileSelect]"}]}],d.ctorParameters=function(){return[{type:r.NgModel,decorators:[{type:t.Optional},{type:t.Host}]}]},d.propDecorators={multiple:[{type:t.Input,args:["multiple"]}],fileSelect:[{type:t.Output}],multipleBinding:[{type:t.HostBinding,args:["attr.multiple"]}],onChange:[{type:t.HostListener,args:["change",["$event"]]}]};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var f=function(e,t){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function m(e,t){function n(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}Object.create;Object.create;var g=function(){},h=p.mixinDisabled(g),y=function(e){function n(n,r){var o=e.call(this)||this;return o._renderer=n,o._element=r,o._multiple=!1,o.fileDrop=new t.EventEmitter,o}return m(n,e),Object.defineProperty(n.prototype,"multiple",{set:function(e){this._multiple=a.coerceBooleanProperty(e)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"multipleBinding",{get:function(){return this._multiple?"":void 0},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"disabledBinding",{get:function(){return this.disabled?"":void 0},enumerable:!1,configurable:!0}),n.prototype.onDrop=function(e){if(!this.disabled){var t=e.dataTransfer.files;if(t.length){var n=this._multiple&&t.length>1?t:t[0];this.fileDrop.emit(n)}}this._renderer.removeClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},n.prototype.onDragOver=function(e){var t=e.dataTransfer;t.dropEffect=this._typeCheck(t.types),this.disabled||!this._multiple&&(t.items&&t.items.length>1||t.mozItemCount>1)?t.dropEffect="none":t.dropEffect="copy",this._stopEvent(e)},n.prototype.onDragEnter=function(e){this.disabled||this._renderer.addClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},n.prototype.onDragLeave=function(e){this._renderer.removeClass(this._element.nativeElement,"drop-zone"),this._stopEvent(e)},n.prototype._typeCheck=function(e){var t="none";return e&&(e.contains&&e.contains("Files")||e.indexOf&&-1!==e.indexOf("Files"))&&(t="copy"),t},n.prototype._stopEvent=function(e){e.preventDefault(),e.stopPropagation()},n}(h);y.decorators=[{type:t.Directive,args:[{selector:"[tdFileDrop]",inputs:["disabled"]}]}],y.ctorParameters=function(){return[{type:t.Renderer2},{type:t.ElementRef}]},y.propDecorators={multiple:[{type:t.Input,args:["multiple"]}],fileDrop:[{type:t.Output}],multipleBinding:[{type:t.HostBinding,args:["attr.multiple"]}],disabledBinding:[{type:t.HostBinding,args:["attr.disabled"]}],onDrop:[{type:t.HostListener,args:["drop",["$event"]]}],onDragOver:[{type:t.HostListener,args:["dragover",["$event"]]}],onDragEnter:[{type:t.HostListener,args:["dragenter",["$event"]]}],onDragLeave:[{type:t.HostListener,args:["dragleave",["$event"]]}]};var v=function(e){function t(t,n){return e.call(this,t,n)||this}return m(t,e),t}(o.TemplatePortalDirective);v.decorators=[{type:t.Directive,args:[{selector:"[td-file-input-label]ng-template"}]}],v.ctorParameters=function(){return[{type:t.TemplateRef},{type:t.ViewContainerRef}]};var b=function(e){this._changeDetectorRef=e};var _=p.mixinControlValueAccessor(p.mixinDisabled(b)),E=function(e){function n(n,r){var o=e.call(this,r)||this;return o._renderer=n,o._multiple=!1,o.select=new t.EventEmitter,o}return m(n,e),Object.defineProperty(n.prototype,"inputElement",{get:function(){return this._inputElement.nativeElement},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"multiple",{get:function(){return this._multiple},set:function(e){this._multiple=a.coerceBooleanProperty(e)},enumerable:!1,configurable:!0}),n.prototype.handleSelect=function(e){this.writeValue(e),this.select.emit(e)},n.prototype.clear=function(){this.writeValue(void 0),this._renderer.setProperty(this.inputElement,"value","")},n.prototype.onDisabledChange=function(e){e&&this.clear()},n.prototype.setDisabledState=function(e){this.disabled=e},n}(_);E.decorators=[{type:t.Component,args:[{changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:r.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return E})),multi:!0}],selector:"td-file-input",inputs:["disabled","value"],template:'<div>\n <button\n 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 >\n <ng-content></ng-content>\n </button>\n <input\n #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 />\n</div>\n',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}"]}]}],E.ctorParameters=function(){return[{type:t.Renderer2},{type:t.ChangeDetectorRef}]},E.propDecorators={_inputElement:[{type:t.ViewChild,args:["fileInput",{static:!0}]}],color:[{type:t.Input}],multiple:[{type:t.Input,args:["multiple"]}],accept:[{type:t.Input}],select:[{type:t.Output}]};var C=function(e){this._changeDetectorRef=e};var D=p.mixinControlValueAccessor(p.mixinDisabled(C)),O=function(e){function n(n){var r=e.call(this,n)||this;return r._multiple=!1,r._required=!1,r.defaultColor="primary",r.activeColor="accent",r.cancelColor="warn",r.select=new t.EventEmitter,r.upload=new t.EventEmitter,r.cancel=new t.EventEmitter,r}return m(n,e),Object.defineProperty(n.prototype,"multiple",{get:function(){return this._multiple},set:function(e){this._multiple=a.coerceBooleanProperty(e)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"required",{get:function(){return this._required},set:function(e){this._required=a.coerceBooleanProperty(e)},enumerable:!1,configurable:!0}),n.prototype.uploadPressed=function(){this.value&&this.upload.emit(this.value)},n.prototype.handleSelect=function(e){this.value=e,this.select.emit(e)},n.prototype._cancel=function(){this.value=void 0,this.cancel.emit(),this.fileInput&&this.fileInput.clear()},n.prototype.onDisabledChange=function(e){e&&this._cancel()},n}(D);O.decorators=[{type:t.Component,args:[{changeDetection:t.ChangeDetectionStrategy.OnPush,providers:[{provide:r.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return O})),multi:!0}],selector:"td-file-upload",inputs:["disabled","value"],template:'<td-file-input\n *ngIf="!value"\n [(ngModel)]="value"\n [multiple]="multiple"\n [disabled]="disabled"\n [accept]="accept"\n [color]="defaultColor"\n (select)="handleSelect($event)"\n>\n <ng-template [cdkPortalOutlet]="inputLabel" [ngIf]="true"></ng-template>\n</td-file-input>\n<div *ngIf="value">\n <button\n #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 >\n <ng-content></ng-content>\n </button>\n <button mat-icon-button type="button" class="td-file-upload-cancel" [color]="cancelColor" (click)="_cancel()">\n <mat-icon>cancel</mat-icon>\n </button>\n</div>\n',styles:[".td-file-upload{padding-left:8px;padding-right:8px}.td-file-upload-cancel{height:24px;left:-12px;position:relative;top:24px;width:24px}::ng-deep [dir=rtl] .td-file-upload-cancel{left:0;right:-12px}.td-file-upload-cancel mat-icon{border-radius:12px;vertical-align:baseline}.drop-zone{border-radius:3px}.drop-zone *{pointer-events:none}"]}]}],O.ctorParameters=function(){return[{type:t.ChangeDetectorRef}]},O.propDecorators={fileInput:[{type:t.ViewChild,args:[E]}],inputLabel:[{type:t.ContentChild,args:[v]}],defaultColor:[{type:t.Input}],activeColor:[{type:t.Input}],cancelColor:[{type:t.Input}],multiple:[{type:t.Input,args:["multiple"]}],required:[{type:t.Input,args:["required"]}],accept:[{type:t.Input}],select:[{type:t.Output}],upload:[{type:t.Output}],cancel:[{type:t.Output}]};var x=function(){function e(e){this._http=e,this._progressSubject=new u.Subject,this._progressObservable=this._progressSubject.asObservable()}return Object.defineProperty(e.prototype,"progress",{get:function(){return this._progressObservable},enumerable:!1,configurable:!0}),e.prototype.send=function(e,t,n,r){var o=this,i=void 0===r?{}:r,l=i.headers,a=i.params;if(!this._http)throw new Error("The HttpClient module needs to be imported at root module level");var p=new c.HttpRequest(t.toUpperCase(),e,n,{reportProgress:!0,headers:new c.HttpHeaders(l||{}),params:new c.HttpParams({fromObject:a||{}})});return this._http.request(p).pipe(s.tap((function(e){return o.handleEvent(e)})))},e.prototype.handleEvent=function(e){switch(e.type){case c.HttpEventType.Sent:this._progressSubject.next(0);break;case c.HttpEventType.UploadProgress:this._progressSubject.next(Math.round(100*e.loaded/e.total));break;case c.HttpEventType.Response:this._progressSubject.next(100)}},e}();x.decorators=[{type:t.Injectable}],x.ctorParameters=function(){return[{type:c.HttpClient,decorators:[{type:t.Optional}]}]};var P=[d,y,O,E,v],j=function(){};j.decorators=[{type:t.NgModule,args:[{imports:[r.FormsModule,n.CommonModule,i.MatIconModule,l.MatButtonModule,o.PortalModule],declarations:[P],exports:[P],providers:[x]}]}],e.CovalentFileModule=j,e.TdFileDropBase=g,e.TdFileDropDirective=y,e.TdFileInputBase=b,e.TdFileInputComponent=E,e.TdFileInputLabelDirective=v,e.TdFileSelectDirective=d,e.TdFileService=x,e.TdFileUploadBase=C,e.TdFileUploadComponent=O,e._TdFileDropMixinBase=h,e._TdFileInputMixinBase=_,e._TdFileUploadMixinBase=D,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=covalent-core-file.umd.min.js.map