|
|
@ -1,23 +1,21 @@
|
|
|
|
const { createElement, Component } = require('react')
|
|
|
|
import { createElement, Component } from 'react'
|
|
|
|
const { DropTarget } = require('react-dnd')
|
|
|
|
import { DropTarget } from 'react-dnd'
|
|
|
|
const { NativeTypes } = require('react-dnd-html5-backend')
|
|
|
|
import { NativeTypes } from 'react-dnd-html5-backend'
|
|
|
|
|
|
|
|
|
|
|
|
const spec = {
|
|
|
|
const spec = {
|
|
|
|
drop(props, monitor, component) {
|
|
|
|
drop(props, monitor, component) {
|
|
|
|
const { files } = monitor.getItem()
|
|
|
|
const { files } = monitor.getItem()
|
|
|
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
Promise.all(
|
|
|
|
Promise.all(
|
|
|
|
files
|
|
|
|
files
|
|
|
|
.filter(props.filter || (i => i))
|
|
|
|
.filter(props.filter || (i => i))
|
|
|
|
.map(file => {
|
|
|
|
.map(file => new Promise((resolve, reject) => {
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
reader.onload = event => {
|
|
|
|
reader.onload = event => {
|
|
|
|
file.content = event.target.result
|
|
|
|
file.content = event.target.result
|
|
|
|
resolve(file)
|
|
|
|
resolve(file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
reader.readAsText(file, 'UTF-8')
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
).then(files => {
|
|
|
|
).then(files => {
|
|
|
|
component.setState(state => ({
|
|
|
|
component.setState(state => ({
|
|
|
|
lastContent: files,
|
|
|
|
lastContent: files,
|
|
|
@ -54,11 +52,11 @@ class ReadFileDropContainer extends Component {
|
|
|
|
isOver: this.props.isOver,
|
|
|
|
isOver: this.props.isOver,
|
|
|
|
canDrop: this.props.canDrop,
|
|
|
|
canDrop: this.props.canDrop,
|
|
|
|
files: this.state.lastContent,
|
|
|
|
files: this.state.lastContent,
|
|
|
|
history: this.state.history,
|
|
|
|
history: this.state.history
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = exports.default = DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer)
|
|
|
|
export default DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer)
|
|
|
|