Browse Source

doc: 添加文档

node 6 years ago
parent
commit
4a974a1a20
1 changed files with 92 additions and 5 deletions
  1. 92
    5
      README.md

+ 92
- 5
README.md View File

12
 
12
 
13
 ## 使用
13
 ## 使用
14
 
14
 
15
+#### RichEditor
16
+
15
 ```js
17
 ```js
16
 import React from 'react'
18
 import React from 'react'
17
 import { RichEditor } from 'editor';
19
 import { RichEditor } from 'editor';
18
 
20
 
19
-export default class RichEditor extends React.Component {
21
+const { EditorState } = RichEditor;
22
+
23
+export default class RichEditorDemo extends React.Component {
20
 
24
 
21
     state = {
25
     state = {
22
         // 创建一个空的editorState作为初始值
26
         // 创建一个空的editorState作为初始值
25
 
29
 
26
     async componentDidMount () {
30
     async componentDidMount () {
27
         // 假设此处从服务端获取html格式的编辑器内容
31
         // 假设此处从服务端获取html格式的编辑器内容
28
-        // const htmlContent = await fetchEditorContent()
32
+        const htmlContent = await fetchEditorContent()
29
         const htmlContent = '<h1>ss</h1>'
33
         const htmlContent = '<h1>ss</h1>'
30
         // 使用EditorState.createFrom将html字符串转换为编辑器需要的editorState数据
34
         // 使用EditorState.createFrom将html字符串转换为编辑器需要的editorState数据
31
         this.setState({
35
         this.setState({
37
         // 在编辑器获得焦点时按下ctrl+s会执行此方法
41
         // 在编辑器获得焦点时按下ctrl+s会执行此方法
38
         // 编辑器内容提交到服务端之前,可直接调用editorState.toHTML()来获取HTML格式的内容
42
         // 编辑器内容提交到服务端之前,可直接调用editorState.toHTML()来获取HTML格式的内容
39
         const htmlContent = this.state.editorState.toHTML()
43
         const htmlContent = this.state.editorState.toHTML()
40
-        console.log('htmlContent: ', htmlContent)
41
-        // const result = await saveEditorContent(htmlContent)
44
+        const result = await saveEditorContent(htmlContent)
42
     }
45
     }
43
 
46
 
44
     handleEditorChange = (editorState) => {
47
     handleEditorChange = (editorState) => {
50
         const { editorState } = this.state
53
         const { editorState } = this.state
51
         return (
54
         return (
52
             <div>
55
             <div>
53
-                <BraftEditor
56
+                <RichEditor
54
                     value={editorState}
57
                     value={editorState}
55
                     onChange={this.handleEditorChange}
58
                     onChange={this.handleEditorChange}
56
                     onSave={this.submitContent}
59
                     onSave={this.submitContent}
62
 
65
 
63
 }
66
 }
64
 
67
 
68
+```
69
+
70
+- defaultProps:
71
+
72
+|props|type|value|
73
+|:-:|:-:|:-:|
74
+|controls|array||
75
+
76
+
77
+```js
78
+const controls = [ 'headings', 'text-color', 'bold', 'italic', 'underline', 'strike-through', 'separator',
79
+      'superscript', 'subscript', 'remove-styles', 'emoji', 'text-align', 'separator',
80
+            'list-ul', 'list-ol', 'blockquote', 'code', 'separator',
81
+                'link', 'separator', 'hr', 'separator',
82
+                'media', 'separator',  'undo', 'redo' ]
83
+```
84
+
85
+
86
+
87
+#### MarkdownEditor
88
+
89
+```js
90
+import React from "react";
91
+import { MarkdownEditor } from 'editor';
92
+
93
+export default class MarkdownEditorDemo extends React.Component {
94
+
95
+    constructor(props) {
96
+        super(props);
97
+        this.state = {
98
+            mdeState: null,
99
+        };
100
+        this.converter = new Showdown.Converter({tables: true, simplifiedAutoLink: true});
101
+    }
102
+
103
+    handleValueChange = (mdeState) => {
104
+        this.setState({mdeState});
105
+    }
106
+
107
+    render() {
108
+        return (
109
+            <MarkdownEditor
110
+                onChange={this.handleValueChange}
111
+                editorState={this.state.mdeState}
112
+            />
113
+        );
114
+    }
115
+}
116
+```
117
+
118
+- default props:
119
+
120
+|props|type|value|
121
+|:-:|:-:|:-:|
122
+|layout|string|'horizontal'|
123
+|buttonContentOptions|object||
124
+|generateMarkdownPreview|func||
125
+
126
+```js
127
+
128
+const icons = {
129
+    "bold": <FontAwesomeIcon icon="bold" />,
130
+    "heading": <FontAwesomeIcon icon="heading" />,
131
+    "italic": <FontAwesomeIcon icon="italic" />,
132
+    "strikethrough": <FontAwesomeIcon icon="strikethrough" />,
133
+    "link": <FontAwesomeIcon icon="link" />,
134
+    "quote-right": <FontAwesomeIcon icon="quote-right" />,
135
+    "code": <FontAwesomeIcon icon="code" />,
136
+    "image": <FontAwesomeIcon icon="image" />,
137
+    "list-ul": <FontAwesomeIcon icon="list-ul" />,
138
+    "list-ol": <FontAwesomeIcon icon="list-ol" />,
139
+    "tasks": <FontAwesomeIcon icon="tasks" />,
140
+  };
141
+
142
+const iconProvider = (name) => {
143
+  return icons[name] || "❓";
144
+};
145
+  
146
+
147
+const defaultProps = {
148
+        layout: 'horizontal',
149
+        buttonContentOptions: { iconProvider },
150
+        generateMarkdownPreview: (markdown) => Promise.resolve(this.converter.makeHtml(markdown)),
151
+}
65
 ```
152
 ```