Browse Source

send actions

Artal Druk 8 years ago
parent
commit
8f19381d78
3 changed files with 55 additions and 12 deletions
  1. 11
    11
      src/RichTextEditor.js
  2. 33
    0
      src/WebviewMessageHandler.js
  3. 11
    1
      src/const.js

+ 11
- 11
src/RichTextEditor.js View File

@@ -60,47 +60,47 @@ export default class RichTextEditor extends Component {
60 60
   }
61 61
 
62 62
   blurEditor() {
63
-    this.refs.webviewbridge.sendToBridge(`zss_editor.blurEditor();`);
63
+    this._sendAction(actions.blurEditor);
64 64
   }
65 65
 
66 66
   setBold() {
67
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setBold();`);
67
+    this._sendAction(actions.setBold);
68 68
   }
69 69
 
70 70
   setItalic() {
71
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setItalic();`);
71
+    this._sendAction(actions.setItalic);
72 72
   }
73 73
 
74 74
   setUnderline() {
75
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setUnderline();`);
75
+    this._sendAction(actions.setUnderline);
76 76
   }
77 77
 
78 78
   heading1() {
79
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h1');`);
79
+    this._sendAction(actions.heading1);
80 80
   }
81 81
 
82 82
   heading2() {
83
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h2');`);
83
+    this._sendAction(actions.heading2);
84 84
   }
85 85
 
86 86
   heading3() {
87
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h3');`);
87
+    this._sendAction(actions.heading3);
88 88
   }
89 89
 
90 90
   heading4() {
91
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h4');`);
91
+    this._sendAction(actions.heading4);
92 92
   }
93 93
 
94 94
   heading5() {
95
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h5');`);
95
+    this._sendAction(actions.heading5);
96 96
   }
97 97
 
98 98
   heading6() {
99
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHeading('h6');`);
99
+    this._sendAction(actions.heading6);
100 100
   }
101 101
 
102 102
   setParagraph() {
103
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setParagraph();`);
103
+    this._sendAction(actions.setParagraph);
104 104
   }
105 105
 
106 106
   removeFormat() {

+ 33
- 0
src/WebviewMessageHandler.js View File

@@ -8,6 +8,39 @@ export const InjectedMessageHandler = `
8 8
         case '${actions.setHtml}':
9 9
           zss_editor.setHTML(action.data);
10 10
           break;
11
+        case '${actions.blurEditor}':
12
+          zss_editor.blurEditor();
13
+          break;
14
+        case '${actions.setBold}':
15
+          zss_editor.setBold();
16
+          break;
17
+        case '${actions.setItalic}':
18
+          zss_editor.setItalic();
19
+          break;
20
+        case '${actions.setUnderline}':
21
+          zss_editor.setUnderline();
22
+          break;
23
+        case '${actions.heading1}':
24
+          zss_editor.setHeading('h1');
25
+          break;
26
+        case '${actions.heading2}':
27
+          zss_editor.setHeading('h2');
28
+          break;
29
+        case '${actions.heading3}':
30
+          zss_editor.setHeading('h3');
31
+          break;
32
+        case '${actions.heading4}':
33
+          zss_editor.setHeading('h4');
34
+          break;
35
+        case '${actions.heading5}':
36
+          zss_editor.setHeading('h5');
37
+          break;
38
+        case '${actions.heading6}':
39
+          zss_editor.setHeading('h6');
40
+          break;
41
+        case '${actions.setParagraph}':
42
+          zss_editor.setParagraph()
43
+          break;
11 44
       }
12 45
     };
13 46
   }

+ 11
- 1
src/const.js View File

@@ -1,4 +1,14 @@
1 1
 export const actions = {
2 2
   setHtml: 'SET_HTML',
3
-
3
+  blurEditor: 'BLUR_EDITOR',
4
+  setBold: 'SET_BOLD',
5
+  setItalic: 'SET_ITALIC',
6
+  setUnderline: 'SET_UNDERLINE',
7
+  heading1: 'HEADING1',
8
+  heading2: 'HEADING2',
9
+  heading3: 'HEADING3',
10
+  heading4: 'HEADING4',
11
+  heading5: 'HEADING5',
12
+  heading6: 'HEADING6',
13
+  setParagraph: 'SET_PARAGRAPH'
4 14
 }