dropperx
Version:
File drop target
3 lines (2 loc) • 1.45 kB
JavaScript
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=t(require("react")),r=t(require("react-dropzone")),n="DATA_URL",o="TEXT",i={outline:"none"};var a=function(t){function a(){for(var e=this,r=[],i=arguments.length;i--;)r[i]=arguments[i];t.apply(this,r),this.state={lastContent:null,history:[]},this.handleDrop=function(t){if(t[0]){var r=new FileReader;Promise.all(t.filter(e.props.filter).map(function(t){return new Promise(function(e){r.onload=function(r){t.content=r.target.result,e(t)},function(t){if(""===t.type)return n;switch(t.type.split("/")[0]){case"application":case"text":return o;case"image":case"video":return n;default:return o}}(t)===n?r.readAsDataURL(t):r.readAsText(t,"UTF-8")})})).then(function(t){e.setState(function(e){return{lastContent:t,history:[t].concat(e.history)}}),e.props.onDrop(t)})}}}return t&&(a.__proto__=t),(a.prototype=Object.create(t&&t.prototype)).constructor=a,a.prototype.render=function(){var t=this;return e.createElement(r,{onDrop:this.handleDrop,accept:this.props.accept,minSize:this.props.minSize,maxSize:this.props.maxSize},function(r){var n=r.isDragActive,o=r.isDragAccept,a=(0,r.getRootProps)();return e.createElement("div",Object.assign({},a,{style:i}),t.props.children({isOver:n,canDrop:o,files:t.state.lastContent,history:t.state.history}))})},a}(e.Component);a.defaultProps={filter:function(t){return t},onDrop:function(){}},module.exports=a;
//# sourceMappingURL=index.js.map