mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 17:38:19 +08:00
ui: preferredEditor: monaco
This commit is contained in:
1 parent
b82a26c903
commit
f29dc43fec
12 files changed
+55
-15
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>;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user