2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.fileupload=function(e,t,n,o,l,s,i,a){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=r(t);function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function c(e){if(Array.isArray(e))return u(e)}function f(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function d(e,t){if(e){if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}}function h(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(e){return c(e)||f(e)||d(e)||h()}function y(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function v(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function b(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){return g=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},g(e,t)}function E(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&g(e,t)}function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function k(e,t){if(t&&("object"===S(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return b(e)}function O(e){return O=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},O(e)}function B(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=w(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,l=function(){};return{s:l,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:l}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){a=!0,s=e},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw s}}}}function w(e,t){if(e){if("string"==typeof e)return F(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(e,t):void 0}}function F(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function I(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var D,N,C,L=function(e){E(h,e);var t,r,u,c,f,d=(t=h,r=I(),function(){var e,n=O(t);if(r){var o=O(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return k(this,e)});function h(e){var t;return y(this,h),(t=d.call(this,e)).state={files:[],msgs:[],focused:!1,progress:0},t.choose=t.choose.bind(b(t)),t.upload=t.upload.bind(b(t)),t.clear=t.clear.bind(b(t)),t.onFileSelect=t.onFileSelect.bind(b(t)),t.onDragEnter=t.onDragEnter.bind(b(t)),t.onDragOver=t.onDragOver.bind(b(t)),t.onDragLeave=t.onDragLeave.bind(b(t)),t.onDrop=t.onDrop.bind(b(t)),t.onKeyDown=t.onKeyDown.bind(b(t)),t.onFocus=t.onFocus.bind(b(t)),t.onBlur=t.onBlur.bind(b(t)),t.onSimpleUploaderClick=t.onSimpleUploaderClick.bind(b(t)),t.duplicateIEEvent=!1,t}return u=h,(c=[{key:"hasFiles",value:function(){return this.state.files&&this.state.files.length>0}},{key:"isImage",value:function(e){return/^image\//.test(e.type)}},{key:"chooseDisabled",value:function(){return this.props.disabled||this.props.fileLimit&&this.props.fileLimit<=this.state.files.length+this.uploadedFileCount}},{key:"uploadDisabled",value:function(){return this.props.disabled||!this.hasFiles()}},{key:"cancelDisabled",value:function(){return this.props.disabled||!this.hasFiles()}},{key:"chooseButtonLabel",value:function(){return this.props.chooseLabel||this.props.chooseOptions.label||a.localeOption("choose")}},{key:"uploadButtonLabel",value:function(){return this.props.uploadLabel||this.props.uploadOptions.label||a.localeOption("upload")}},{key:"cancelButtonLabel",value:function(){return this.props.cancelLabel||this.props.cancelOptions.label||a.localeOption("cancel")}},{key:"remove",value:function(e,t){this.clearInputElement();var n=m(this.state.files),o=this.state.files[t];n.splice(t,1),this.setState({files:n}),this.props.onRemove&&this.props.onRemove({originalEvent:e,file:o})}},{key:"clearInputElement",value:function(){this.fileInput&&(this.fileInput.value="")}},{key:"clearIEInput",value:function(){this.fileInput&&(this.duplicateIEEvent=!0,this.fileInput.value="")}},{key:"formatSize",value:function(e){if(0===e)return"0 B";var t=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,t)).toFixed(3))+" "+["B","KB","MB","GB","TB","PB","EB","ZB","YB"][t]}},{key:"onFileSelect",value:function(e){var t=this;if("drop"!==e.type&&this.isIE11()&&this.duplicateIEEvent)this.duplicateIEEvent=!1;else{this.setState({msgs:[]}),this.files=this.state.files?m(this.state.files):[];for(var n=e.dataTransfer?e.dataTransfer.files:e.target.files,o=0;o<n.length;o++){var l=n[o];this.isFileSelected(l)||this.validate(l)&&(this.isImage(l)&&(l.objectURL=window.URL.createObjectURL(l)),this.files.push(l))}this.setState({files:this.files},(function(){t.hasFiles()&&t.props.auto&&t.upload()})),this.props.onSelect&&this.props.onSelect({originalEvent:e,files:n}),"drop"!==e.type&&this.isIE11()?this.clearIEInput():this.clearInputElement(),"basic"===this.props.mode&&this.files.length>0&&(this.fileInput.style.display="none")}}},{key:"isFileSelected",value:function(e){var t,n=B(this.state.files);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.name+o.type+o.size===e.name+e.type+e.size)return!0}}catch(e){n.e(e)}finally{n.f()}return!1}},{key:"isIE11",value:function(){return!!window.MSInputMethodContext&&!!document.documentMode}},{key:"validate",value:function(e){if(this.props.maxFileSize&&e.size>this.props.maxFileSize){var t={severity:"error",summary:this.props.invalidFileSizeMessageSummary.replace("{0}",e.name),detail:this.props.invalidFileSizeMessageDetail.replace("{0}",this.formatSize(this.props.maxFileSize))};return"advanced"===this.props.mode&&this.messagesUI.show(t),this.props.onValidationFail&&this.props.onValidationFail(e),!1}return!0}},{key:"upload",value:function(){var e=this;if(this.props.customUpload)this.props.fileLimit&&(this.uploadedFileCount+=this.state.files.length),this.props.uploadHandler&&this.props.uploadHandler({files:this.state.files,options:{clear:this.clear,props:this.props}});else{this.setState({msgs:[]});var t=new XMLHttpRequest,n=new FormData;this.props.onBeforeUpload&&this.props.onBeforeUpload({xhr:t,formData:n});var o,l=B(this.state.files);try{for(l.s();!(o=l.n()).done;){var s=o.value;n.append(this.props.name,s,s.name)}}catch(e){l.e(e)}finally{l.f()}t.upload.addEventListener("progress",(function(t){t.lengthComputable&&e.setState({progress:Math.round(100*t.loaded/t.total)},(function(){e.props.onProgress&&e.props.onProgress({originalEvent:t,progress:e.state.progress})}))})),t.onreadystatechange=function(){4===t.readyState&&(e.setState({progress:0}),t.status>=200&&t.status<300?(e.props.fileLimit&&(e.uploadedFileCount+=e.state.files.length),e.props.onUpload&&e.props.onUpload({xhr:t,files:e.state.files})):e.props.onError&&e.props.onError({xhr:t,files:e.state.files}),e.clear())},t.open("POST",this.props.url,!0),this.props.onBeforeSend&&this.props.onBeforeSend({xhr:t,formData:n}),t.withCredentials=this.props.withCredentials,t.send(n)}}},{key:"clear",value:function(){this.setState({files:[]}),this.props.onClear&&this.props.onClear(),this.clearInputElement()}},{key:"choose",value:function(){this.fileInput.click()}},{key:"onFocus",value:function(){this.setState({focused:!0})}},{key:"onBlur",value:function(){this.setState({focused:!1})}},{key:"onKeyDown",value:function(e){13===e.which&&this.choose()}},{key:"onDragEnter",value:function(e){this.props.disabled||(e.dataTransfer.dropEffect="copy",e.stopPropagation(),e.preventDefault())}},{key:"onDragOver",value:function(e){this.props.disabled||(e.dataTransfer.dropEffect="copy",s.DomHandler.addClass(this.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault())}},{key:"onDragLeave",value:function(e){this.props.disabled||(e.dataTransfer.dropEffect="copy",s.DomHandler.removeClass(this.content,"p-fileupload-highlight"))}},{key:"onDrop",value:function(e){if(!this.props.disabled){s.DomHandler.removeClass(this.content,"p-fileupload-highlight"),e.stopPropagation(),e.preventDefault();var t=e.dataTransfer?e.dataTransfer.files:e.target.files;(this.props.multiple||t&&0===t.length)&&this.onFileSelect(e)}}},{key:"onSimpleUploaderClick",value:function(){this.hasFiles()?this.upload():this.fileInput.click()}},{key:"renderChooseButton",value:function(){var e=this,t=this.props.chooseOptions,n=t.style,o=t.icon,l=t.iconOnly,a=s.classNames("p-button p-fileupload-choose p-component",{"p-disabled":this.props.disabled,"p-focus":this.state.focused,"p-button-icon-only":l},t.className),r="p-button-label p-clickable",u=l?p.default.createElement("span",{className:r,dangerouslySetInnerHTML:{__html:" "}}):p.default.createElement("span",{className:r},this.chooseButtonLabel());return p.default.createElement("span",{className:a,style:n,onClick:this.choose,onKeyDown:this.onKeyDown,onFocus:this.onFocus,onBlur:this.onBlur,tabIndex:0},p.default.createElement("input",{ref:function(t){return e.fileInput=t},type:"file",onChange:this.onFileSelect,multiple:this.props.multiple,accept:this.props.accept,disabled:this.chooseDisabled()}),s.IconUtils.getJSXIcon(o||"pi pi-fw pi-plus",{className:"p-button-icon p-button-icon-left p-clickable"},{props:this.props}),u,p.default.createElement(i.Ripple,null))}},{key:"renderFile",value:function(e,t){var o=this,l=this.isImage(e)?p.default.createElement("div",null,p.default.createElement("img",{alt:e.name,role:"presentation",src:e.objectURL,width:this.props.previewWidth})):null,i=p.default.createElement("div",{className:"p-fileupload-filename"},e.name),a=p.default.createElement("div",null,this.formatSize(e.size)),r=p.default.createElement("div",null,p.default.createElement(n.Button,{type:"button",icon:"pi pi-times",onClick:function(e){return o.remove(e,t)}})),u=p.default.createElement(p.default.Fragment,null,l,i,a,r);if(this.props.itemTemplate){var c={onRemove:function(e){return o.remove(e,t)},previewElement:l,fileNameElement:i,sizeElement:a,removeElement:r,formatSize:this.formatSize(e.size),files:this.state.files,index:t,element:u,props:this.props};u=s.ObjectUtils.getJSXElement(this.props.itemTemplate,e,c)}return p.default.createElement("div",{className:"p-fileupload-row",key:e.name+e.type+e.size},u)}},{key:"renderFiles",value:function(){var e=this;return p.default.createElement("div",{className:"p-fileupload-files"},this.state.files.map((function(t,n){return e.renderFile(t,n)})))}},{key:"renderEmptyContent",value:function(){return this.props.emptyTemplate&&!this.hasFiles()?s.ObjectUtils.getJSXElement(this.props.emptyTemplate,this.props):null}},{key:"renderProgressBarContent",value:function(){return this.props.progressBarTemplate?s.ObjectUtils.getJSXElement(this.props.progressBarTemplate,this.props):p.default.createElement(l.ProgressBar,{value:this.state.progress,showValue:!1})}},{key:"renderAdvanced",value:function(){var e,t,l,i,a=this,r=s.classNames("p-fileupload p-fileupload-advanced p-component",this.props.className),u=s.classNames("p-fileupload-buttonbar",this.props.headerClassName),c=s.classNames("p-fileupload-content",this.props.contentClassName),f=this.renderChooseButton(),d=this.renderEmptyContent();if(!this.props.auto){var h=this.props.uploadOptions,m=this.props.cancelOptions,y=h.iconOnly?"":this.uploadButtonLabel(),v=m.iconOnly?"":this.cancelButtonLabel();e=p.default.createElement(n.Button,{type:"button",label:y,icon:h.icon||"pi pi-upload",onClick:this.upload,disabled:this.uploadDisabled(),style:h.style,className:h.className}),t=p.default.createElement(n.Button,{type:"button",label:v,icon:m.icon||"pi pi-times",onClick:this.clear,disabled:this.cancelDisabled(),style:m.style,className:m.className})}this.hasFiles()&&(l=this.renderFiles(),i=this.renderProgressBarContent());var b=p.default.createElement("div",{className:u,style:this.props.headerStyle},f,e,t);return this.props.headerTemplate&&(b=s.ObjectUtils.getJSXElement(this.props.headerTemplate,{className:u,chooseButton:f,uploadButton:e,cancelButton:t,element:b,props:this.props})),p.default.createElement("div",{id:this.props.id,className:r,style:this.props.style},b,p.default.createElement("div",{ref:function(e){a.content=e},className:c,style:this.props.contentStyle,onDragEnter:this.onDragEnter,onDragOver:this.onDragOver,onDragLeave:this.onDragLeave,onDrop:this.onDrop},i,p.default.createElement(o.Messages,{ref:function(e){return a.messagesUI=e}}),l,d))}},{key:"renderBasic",value:function(){var e=this,t=this.hasFiles(),n=this.props.chooseOptions,l=s.classNames("p-fileupload p-fileupload-basic p-component",this.props.className),a=s.classNames("p-button p-component p-fileupload-choose",{"p-fileupload-choose-selected":t,"p-disabled":this.props.disabled,"p-focus":this.state.focused},n.className),r=n.icon||s.classNames({"pi pi-plus":!n.icon&&(!t||this.props.auto),"pi pi-upload":!n.icon&&t&&!this.props.auto}),u="p-button-label p-clickable",c=n.iconOnly?p.default.createElement("span",{className:u,dangerouslySetInnerHTML:{__html:" "}}):p.default.createElement("span",{className:u},this.chooseButtonLabel()),f=this.props.auto?c:p.default.createElement("span",{className:u},t?this.state.files[0].name:c),d=s.IconUtils.getJSXIcon(r,{className:"p-button-icon p-button-icon-left"},{props:this.props,hasFiles:t});return p.default.createElement("div",{className:l,style:this.props.style},p.default.createElement(o.Messages,{ref:function(t){return e.messagesUI=t}}),p.default.createElement("span",{className:a,style:n.style,onMouseUp:this.onSimpleUploaderClick,onKeyDown:this.onKeyDown,onFocus:this.onFocus,onBlur:this.onBlur,tabIndex:0},d,f,!t&&p.default.createElement("input",{ref:function(t){return e.fileInput=t},type:"file",accept:this.props.accept,multiple:this.props.multiple,disabled:this.props.disabled,onChange:this.onFileSelect}),p.default.createElement(i.Ripple,null)))}},{key:"render",value:function(){return"advanced"===this.props.mode?this.renderAdvanced():"basic"===this.props.mode?this.renderBasic():void 0}}])&&v(u.prototype,c),f&&v(u,f),Object.defineProperty(u,"prototype",{writable:!1}),h}(t.Component);return C={id:null,name:null,url:null,mode:"advanced",multiple:!1,accept:null,disabled:!1,auto:!1,maxFileSize:null,invalidFileSizeMessageSummary:"{0}: Invalid file size, ",invalidFileSizeMessageDetail:"maximum upload size is {0}.",style:null,className:null,widthCredentials:!1,previewWidth:50,chooseLabel:null,uploadLabel:null,cancelLabel:null,chooseOptions:{label:null,icon:null,iconOnly:!1,className:null,style:null},uploadOptions:{label:null,icon:null,iconOnly:!1,className:null,style:null},cancelOptions:{label:null,icon:null,iconOnly:!1,className:null,style:null},customUpload:!1,headerClassName:null,headerStyle:null,contentClassName:null,contentStyle:null,headerTemplate:null,itemTemplate:null,emptyTemplate:null,progressBarTemplate:null,onBeforeUpload:null,onBeforeSend:null,onUpload:null,onError:null,onClear:null,onSelect:null,onProgress:null,onValidationFail:null,uploadHandler:null,onRemove:null},(N="defaultProps")in(D=L)?Object.defineProperty(D,N,{value:C,enumerable:!0,configurable:!0,writable:!0}):D[N]=C,e.FileUpload=L,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.button,primereact.messages,primereact.progressbar,primereact.utils,primereact.ripple,primereact.api);
|