node 6 anos atrás
pai
commit
2391a04b40
6 arquivos alterados com 1490 adições e 2548 exclusões
  1. 2
    2484
      README.md
  2. 9
    2
      package.json
  3. 52
    0
      src/MarkdownEditor/index.js
  4. 13
    0
      src/RichEditor/index.js
  5. 33
    7
      src/index.js
  6. 1381
    55
      yarn.lock

+ 2
- 2484
README.md
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 9
- 2
package.json Ver arquivo

@@ -2,10 +2,17 @@
2 2
   "name": "editor",
3 3
   "version": "0.1.0",
4 4
   "private": true,
5
+  "main": "dist/index.js",
5 6
   "dependencies": {
7
+    "@fortawesome/fontawesome-svg-core": "^1.2.4",
8
+    "@fortawesome/free-solid-svg-icons": "^5.3.1",
9
+    "@fortawesome/react-fontawesome": "^0.1.3",
10
+    "braft-editor": "^2.0.5",
6 11
     "react": "^16.5.0",
7 12
     "react-dom": "^16.5.0",
8
-    "react-scripts": "1.1.5"
13
+    "react-mde": "^5.8.0",
14
+    "react-scripts": "1.1.5",
15
+    "showdown": "^1.8.6"
9 16
   },
10 17
   "scripts": {
11 18
     "start": "react-scripts start",
@@ -13,4 +20,4 @@
13 20
     "test": "react-scripts test --env=jsdom",
14 21
     "eject": "react-scripts eject"
15 22
   }
16
-}
23
+}

+ 52
- 0
src/MarkdownEditor/index.js Ver arquivo

@@ -0,0 +1,52 @@
1
+import * as React from "react";
2
+import ReactMde from 'react-mde';
3
+import * as Showdown from "showdown";
4
+import 'react-mde/lib/styles/css/react-mde-all.css';
5
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
6
+
7
+
8
+const icons = {
9
+    "bold": <FontAwesomeIcon icon="bold" />,
10
+    "heading": <FontAwesomeIcon icon="heading" />,
11
+    "italic": <FontAwesomeIcon icon="italic" />,
12
+    "strikethrough": <FontAwesomeIcon icon="strikethrough" />,
13
+    "link": <FontAwesomeIcon icon="link" />,
14
+    "quote-right": <FontAwesomeIcon icon="quote-right" />,
15
+    "code": <FontAwesomeIcon icon="code" />,
16
+    "image": <FontAwesomeIcon icon="image" />,
17
+    "list-ul": <FontAwesomeIcon icon="list-ul" />,
18
+    "list-ol": <FontAwesomeIcon icon="list-ol" />,
19
+    "tasks": <FontAwesomeIcon icon="tasks" />,
20
+  };
21
+
22
+  const iconProvider = (name) => {
23
+    return icons[name] || "❓";
24
+  };
25
+  
26
+
27
+export default class MarkdownEditor extends React.Component {
28
+
29
+    constructor(props) {
30
+        super(props);
31
+        this.converter = new Showdown.Converter({tables: true, simplifiedAutoLink: true});
32
+    }
33
+
34
+    handleValueChange = (mdeState) => {
35
+        this.setState({mdeState});
36
+    }
37
+
38
+    render() {
39
+      const defaultProps = {
40
+        layout: 'horizontal',
41
+        buttonContentOptions: { iconProvider },
42
+        generateMarkdownPreview: (markdown) => Promise.resolve(this.converter.makeHtml(markdown)),
43
+      }
44
+      const props=  {
45
+        ...this.props,
46
+        ...defaultProps,
47
+      }
48
+        return (
49
+          <ReactMde {...props} />
50
+        );
51
+    }
52
+}

+ 13
- 0
src/RichEditor/index.js Ver arquivo

@@ -0,0 +1,13 @@
1
+import React from 'react'
2
+// 引入编辑器以及EditorState子模块
3
+import BraftEditor from 'braft-editor'
4
+// 引入编辑器样式
5
+import 'braft-editor/dist/index.css'
6
+
7
+export default class RichEditor extends React.Component {
8
+    render () {
9
+        return (
10
+          <BraftEditor {...this.props} />
11
+        )
12
+    }
13
+}

+ 33
- 7
src/index.js Ver arquivo

@@ -1,8 +1,34 @@
1
-import React from 'react';
2
-import ReactDOM from 'react-dom';
3
-import './index.css';
4
-import App from './App';
5
-import registerServiceWorker from './registerServiceWorker';
1
+import { library } from '@fortawesome/fontawesome-svg-core'
2
+import { 
3
+    faBold, 
4
+    faHeading,
5
+    faItalic,
6
+    faStrikethrough,
7
+    faLink,
8
+    faQuoteRight,
9
+    faCode,
10
+    faImage,
11
+    faListUl,
12
+    faListOl,
13
+    faTasks,
14
+ } from '@fortawesome/free-solid-svg-icons'
15
+ import RichEditor from './RichEditor';
16
+ import MarkdownEditor from './MarkdownEditor';
6 17
 
7
-ReactDOM.render(<App />, document.getElementById('root'));
8
-registerServiceWorker();
18
+
19
+library.add(faBold)
20
+library.add(faHeading)
21
+library.add(faItalic)
22
+library.add(faStrikethrough)
23
+library.add(faLink)
24
+library.add(faQuoteRight)
25
+library.add(faCode)
26
+library.add(faImage)
27
+library.add(faListUl)
28
+library.add(faListOl)
29
+library.add(faTasks)
30
+
31
+export default { 
32
+  RichEditor,
33
+  MarkdownEditor,
34
+ }

+ 1381
- 55
yarn.lock
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo