-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathexample.js
More file actions
85 lines (70 loc) · 2.08 KB
/
Copy pathexample.js
File metadata and controls
85 lines (70 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2016, Globo.com (https://github.com/globocom)
*
* License: MIT
*/
import React, { useState, useEffect } from "react";
import { MegadraftEditor } from "../../src/Megadraft";
import { editorStateToJSON, editorStateFromRaw } from "../../src/utils";
import { highlightCode } from "./highlightCode";
import INITIAL_CONTENT from "./contentExample";
import relatedArticles from "megadraft-related-articles-plugin";
import image from "../../src/plugins/image/plugin";
import video from "../../src/plugins/video/plugin";
const initialEditorState = editorStateFromRaw(INITIAL_CONTENT);
const keyBindings = [
{
name: "save",
isKeyBound: e => e.keyCode === 83 && e.ctrlKey,
action: () => console.log("save")
}
];
function Editor(props) {
const { editorState, onChange } = props;
function onAction(args) {
console.log("onAction fired with args:", args);
}
return (
<div className="tab-container-editor">
<MegadraftEditor
plugins={[image, video, relatedArticles]}
editorState={editorState}
placeholder="Text"
onChange={onChange}
keyBindings={keyBindings}
resetStyleNewLine={true}
maxSidebarButtons={null}
onAction={onAction}
movableBlocks={true}
/>
</div>
);
}
function JSONPreview(props) {
const { editorState } = props;
return (
<div>
<link
rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/gruvbox-dark.min.css"
/>
<div className="tab-container-json">
<pre className="jsonpreview">
<code className="json hljs">{editorStateToJSON(editorState)}</code>
</pre>
</div>
</div>
);
}
export default function Example(props) {
const { activeContent } = props;
const [editorState, setEditorState] = useState(initialEditorState);
useEffect(() => highlightCode(), []);
return activeContent ? (
<Editor editorState={editorState} onChange={setEditorState} />
) : (
<JSONPreview editorState={editorState} />
);
}
/* global hljs */
hljs.initHighlightingOnLoad();