Skip to content

Commit

Permalink
Merge pull request #132 from xwchris/master
Browse files Browse the repository at this point in the history
fix: pasting image not update value bug
  • Loading branch information
RIP21 authored Jun 23, 2020
2 parents 73f6c27 + 4767ce2 commit 4d7c118
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type CodemirrorEvents =
| "update"
| "renderLine";

type SimpleMdeToCodemirror = {
type SimpleMdeToCodemirror = {
[E in CodemirrorEvents | DOMEvent]?: Editor["on"]
};

Expand Down Expand Up @@ -100,14 +100,28 @@ export default class SimpleMDEEditor extends React.PureComponent<
}
}

// image upload function
imageUploadFunction = (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => {
const imageUpload = this.props.options?.imageUploadFunction
if (imageUpload) {
const _onSuccess = (url: string) => {
onSuccess(url)
// update value when success
this.eventWrapper()
}
imageUpload(file, _onSuccess, onError)
}
}

createEditor = () => {
const SimpleMDE = require("easymde");
const initialOptions = {
element: document.getElementById(this.id),
initialValue: this.props.value
};

const allOptions = Object.assign({}, initialOptions, this.props.options);
const imageUploadFunction = this.props.options?.imageUploadFunction ? this.imageUploadFunction : undefined
const allOptions = Object.assign({}, initialOptions, this.props.options, { imageUploadFunction });
this.simpleMde = new SimpleMDE(allOptions);
};

Expand Down

0 comments on commit 4d7c118

Please sign in to comment.