Add clipboard image paste feature #168

This commit is contained in:
Ivan Diaz 2018-10-05 02:15:53 -03:00
parent 621c44e28c
commit 7740952956
2 changed files with 25 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.idea
.jshintrc
client/package-lock.json
tests/Gemfile.lock
server/composer.lock
server/vendor

View File

@ -51,7 +51,7 @@ class TextEditor extends React.Component {
render() {
return (
<div className={this.getClass()}>
<div className={this.getClass()} onPaste={this.onPaste.bind(this)}>
{isIE() ? this.renderTextArea() : this.renderQuill()}
</div>
);
@ -141,6 +141,29 @@ class TextEditor extends React.Component {
}
}
onPaste(event) {
let items = event.nativeEvent && event.nativeEvent.clipboardData.items;
for (let index in items) {
let item = items[index];
if (item.kind === 'file') {
let blob = item.getAsFile();
let reader = new FileReader();
reader.onload = (event) => {
this.props.onChange({
target: {
value: (
this.props.value
+ `<img src="${event.target.result}" />`
)
}
});
};
reader.readAsDataURL(blob);
}
}
}
focus() {
if (this.refs.editor) {
this.refs.editor.focus();