UNPKG

@lxlib/seed

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

16 lines (14 loc) 3.86 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@lxlib/theme"),require("file-saver"),require("@angular/common")):"function"==typeof define&&define.amd?define("@lxlib/seed/down-file",["exports","@angular/core","@lxlib/theme","file-saver","@angular/common"],t):t(((e=e||self).lxlib=e.lxlib||{},e.lxlib.seed=e.lxlib.seed||{},e.lxlib.seed["down-file"]={}),e.ng.core,e.lxlib.theme,e.saveAs,e.ng.common)}(this,(function(e,t,r,i,o){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function n(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,o,n=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function s(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(n(arguments[t]));return e}var l=function(){function e(e,r){this.el=e,this._http=r,this.isFileSaverSupported=!0,this.httpMethod="get",this.success=new t.EventEmitter,this.error=new t.EventEmitter;var i=!1;try{i=!!new Blob}catch(e){}this.isFileSaverSupported=i,i||e.nativeElement.classList.add("down-file__not-support")}return e.prototype.getDisposition=function(e){return(e||"").split(";").filter((function(e){return e.includes("=")})).map((function(e){var t,r=e.split("="),i=r[1];return i.startsWith("UTF-8''")&&(i=i.substr("UTF-8''".length)),(t={})[r[0].trim()]=i,t})).reduce((function(e,t){return t}),{})},e.prototype.setDisabled=function(e){var t=this.el.nativeElement;t.disabled=e,t.classList[e?"add":"remove"]("down-file__disabled")},e.prototype._click=function(){var e=this;this.isFileSaverSupported&&(this.setDisabled(!0),this._http.request(this.httpMethod,this.httpUrl,{params:this.httpData||{},responseType:"blob",observe:"response",body:this.httpBody}).subscribe((function(t){if(200!==t.status||t.body.size<=0)e.error.emit(t);else{var r=e.getDisposition(t.headers.get("content-disposition")),o=e.fileName;"function"==typeof o&&(o=o(t)),o=o||r["filename*"]||r.filename||t.headers.get("filename")||t.headers.get("x-filename"),i.saveAs(t.body,decodeURI(o)),e.success.emit(t)}}),(function(t){return e.error.emit(t)}),(function(){return e.setDisabled(!1)})))},e.decorators=[{type:t.Directive,args:[{selector:"[down-file]",exportAs:"downFile",host:{"(click)":"_click()"}}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:r._HttpClient}]},e.propDecorators={httpData:[{type:t.Input,args:["http-data"]}],httpBody:[{type:t.Input,args:["http-body"]}],httpMethod:[{type:t.Input,args:["http-method"]}],httpUrl:[{type:t.Input,args:["http-url"]}],fileName:[{type:t.Input,args:["file-name"]}],success:[{type:t.Output}],error:[{type:t.Output}]},e}();var a=[l],u=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[o.CommonModule,r.LxlibThemeModule],declarations:s(a),exports:s(a)}]}],e}();e.DownFileDirective=l,e.DownFileModule=u,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=downFile.umd.min.js.map