-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Mason
committed
Apr 6, 2020
1 parent
586b636
commit f19dd81
Showing
6 changed files
with
419 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/components/EditorPane/MarkdownEditor/MarkdownEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { Component, useCallback } from 'react'; | ||
import {Controlled as ReactCodeMirror} from 'react-codemirror2'; | ||
import { debounce } from "lodash"; | ||
var HyperMD = require('hypermd') | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { } from "@fortawesome/free-regular-svg-icons"; | ||
import { } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
import 'codemirror/lib/codemirror'; | ||
|
||
import 'codemirror/mode/javascript/javascript'; | ||
import 'codemirror/mode/xml/xml'; | ||
import 'codemirror/mode/markdown/markdown'; | ||
import 'codemirror/mode/gfm/gfm'; | ||
|
||
import 'hypermd/core'; | ||
import 'hypermd/mode/hypermd'; | ||
|
||
import 'hypermd/addon/hide-token'; | ||
import 'hypermd/addon/cursor-debounce'; | ||
import 'hypermd/addon/fold'; | ||
import 'hypermd/addon/read-link'; | ||
import 'hypermd/addon/click'; | ||
import 'hypermd/addon/hover'; | ||
import 'hypermd/addon/paste'; | ||
import 'hypermd/addon/insert-file'; | ||
import 'hypermd/addon/mode-loader'; | ||
import 'hypermd/addon/table-align'; | ||
|
||
const handler = f => useCallback(debounce(f, 2000), []); | ||
|
||
class MarkdownEditor extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
content: props.note.content, | ||
} | ||
this.codeMirrorRef = React.createRef(); | ||
|
||
|
||
} | ||
|
||
updateContent | ||
|
||
render() { | ||
const updateContent=(editor, data, value)=> { | ||
console.log("updateContent editor",editor) | ||
console.log("updateContent data",data) | ||
console.log("updateContent value",value) | ||
// handler(()=>this.props.noteActions.updateNote(this.props.note._id, {content: value})) | ||
// console.log(value) | ||
// this.props.noteActions.updateNote(this.props.note._id, {content: value}) | ||
// this.setState({content:value}) | ||
this.setState({content:value}) ; | ||
clearTimeout(this.timeout) | ||
this.timeout = setTimeout(()=> {this.props.noteActions.updateNote(this.props.note._id, {content: value})}, 5000) | ||
} | ||
const options = { | ||
mode: 'hypermd', | ||
// mode: 'gfm', | ||
theme: 'hypermd-light', | ||
|
||
hmdFold: { | ||
image: true, | ||
link: true, | ||
math: true, | ||
}, | ||
hmdHideToken: true, | ||
hmdCursorDebounce: true, | ||
hmdPaste: true, | ||
hmdClick: false, | ||
hmdHover: true, | ||
hmdTableAlign: true | ||
}; | ||
return <ReactCodeMirror value={this.state.content} ref={this.codeMirrorRef} | ||
className="code-mirror_editor" | ||
options={options} | ||
onBeforeChange={(editor, data, value) => { | ||
this.setState({content: value}); | ||
}} | ||
onChange={updateContent} />; | ||
} | ||
} | ||
export default MarkdownEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.