ui: use vditor as default markdown editor

This commit is contained in:
undefined committed 2021-04-17 23:01:13 +08:00
1 parent 981b21160f
commit d7a6e30743
13 files changed
+109 -266

No files matched your search

@@ -0,0 +1,38 @@
import React from 'react';
import Vditor from 'vditor';
import { config } from './index';
export default class MarkdownEditor extends React.PureComponent {
constructor(props) {
super(props);
this.ref = React.createRef();
}
async componentDidMount() {
await new Promise((resolve) => {
this.editor = new Vditor(this.ref.current, {
...config,
after: resolve,
input(value) { this.props.onChange(value); },
cache: { id: Math.random().toString() },
});
});
}
componentWillUnmount() {
this.editor.destory();
this.editor.detach();
}
value() {
return this.editor.getValue();
}
focus() {
return this.editor.focus();
}
render() {
return <div ref={this.ref}></div>;
}
}