/
Editor.tsx
116 lines (109 loc) · 2.75 KB
/
Editor.tsx
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {
Editor as TuiEditor,
Viewer as TuiViewer
} from "@toast-ui/react-editor";
import "codemirror/lib/codemirror.css";
import "highlight.js/styles/gml.css";
import React from "react";
import "tui-editor/dist/tui-editor-contents.min.css";
import "tui-editor/dist/tui-editor-extChart";
import "tui-editor/dist/tui-editor-extColorSyntax";
import "tui-editor/dist/tui-editor-extScrollSync";
import "tui-editor/dist/tui-editor-extTable";
import "tui-editor/dist/tui-editor-extUML";
import "tui-editor/dist/tui-editor.min.css";
interface Hooks {
previewBeforeHook: (...args: any[]) => void;
addImageBlobHook: (
fileOrBlob: File | Blob,
callback: (...args: any[]) => void,
source: string
) => void;
}
interface ToMarkOptions {
gfm?: boolean;
renderer?: any;
}
interface Converter {
getMarkdownitHighlightRenderer(): markdownit;
initHtmlSanitizer(): void;
toHTML(makrdown: string): string;
toHTMLWithCodeHightlight(markdown: string): string;
toMarkdown(html: string, toMarkdownOptions: ToMarkOptions): string;
}
interface EditorProps {
height?: string;
minHeight?: string;
initialValue?: string;
previewStyle?: "tab" | "vertical";
initialEditType?: "markdown" | "wysiwyg";
onLoad?: (...args: any[]) => void;
onChange?: (...args: any[]) => void;
onStateChange?: (...args: any[]) => void;
onFocus?: (...args: any[]) => void;
onBlur?: (...args: any[]) => void;
hooks?: Array<Hooks>;
language?: string;
useCommandShortcut?: boolean;
useDefaultHTMLSanitizer?: boolean;
codeBlockLanguages?: Array<string>;
usageStatistics?: boolean;
toolbarItems?: string;
hideModeSwitch?: boolean;
exts?: Array<any>;
customConvertor?: Converter;
placeholder?: string;
previewDelayTime?: string;
linkAttribute?: any;
}
interface ViewerProps {
initialValue?: string;
onLoad?: (...args: any[]) => void;
onChange?: (...args: any[]) => void;
onStateChange?: (...args: any[]) => void;
onFocus?: (...args: any[]) => void;
onBlur?: (...args: any[]) => void;
hooks?: Array<Hooks>;
exts?: Array<any>;
}
export const Editor = React.forwardRef<any, EditorProps>((props, ref) => (
<TuiEditor
ref={ref}
usageStatistics={false}
exts={[
{
name: "chart",
minWidth: 100,
maxWidth: 600,
minHeight: 100,
maxHeight: 300
},
"scrollSync",
"colorSyntax",
"uml",
"mark",
"table"
]}
{...props}
/>
));
export const Viewer = React.forwardRef<any, ViewerProps>((props, ref) => (
<TuiViewer
ref={ref}
exts={[
{
name: "chart",
minWidth: 100,
maxWidth: 600,
minHeight: 100,
maxHeight: 300
},
"scrollSync",
"colorSyntax",
"uml",
"mark",
"table"
]}
{...props}
/>
));