|
|
@ -4,24 +4,26 @@ const { NativeTypes } = require('react-dnd-html5-backend')
|
|
|
|
|
|
|
|
|
|
|
|
const spec = {
|
|
|
|
const spec = {
|
|
|
|
drop(props, monitor, component) {
|
|
|
|
drop(props, monitor, component) {
|
|
|
|
const bundle = monitor.getItem()
|
|
|
|
const {files} = monitor.getItem()
|
|
|
|
Promise.all(
|
|
|
|
Promise.all(
|
|
|
|
bundle.files
|
|
|
|
files
|
|
|
|
.filter(props.filter || (i => i))
|
|
|
|
.filter(props.filter || (i => i))
|
|
|
|
.map(file => {
|
|
|
|
.map(file => {
|
|
|
|
const reader = new FileReader()
|
|
|
|
const reader = new FileReader()
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
reader.onload = event => resolve(event.target.result)
|
|
|
|
reader.onload = event => {
|
|
|
|
|
|
|
|
file.content = event.target.result
|
|
|
|
|
|
|
|
resolve(file)
|
|
|
|
|
|
|
|
}
|
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
).then(contents => {
|
|
|
|
).then(files => {
|
|
|
|
bundle.contents = contents
|
|
|
|
|
|
|
|
component.setState(state => ({
|
|
|
|
component.setState(state => ({
|
|
|
|
lastContent: contents,
|
|
|
|
lastContent: files,
|
|
|
|
history: [bundle, ...state.history]
|
|
|
|
history: [files, ...state.history]
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
props.onDrop(contents)
|
|
|
|
props.onDrop(files)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -51,7 +53,7 @@ class ReadFileDropContainer extends Component {
|
|
|
|
__monitor__: this.props.monitor,
|
|
|
|
__monitor__: this.props.monitor,
|
|
|
|
isOver: this.props.isOver,
|
|
|
|
isOver: this.props.isOver,
|
|
|
|
canDrop: this.props.canDrop,
|
|
|
|
canDrop: this.props.canDrop,
|
|
|
|
content: this.state.lastContent,
|
|
|
|
files: this.state.lastContent,
|
|
|
|
history: this.state.history,
|
|
|
|
history: this.state.history,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|