Yedidya Kennard 8 anni fa
parent
commit
b39facc829
3 ha cambiato i file con 75 aggiunte e 18 eliminazioni
  1. 21
    16
      src/RichTextEditor.js
  2. 39
    0
      src/WebviewMessageHandler.js
  3. 15
    2
      src/const.js

+ 21
- 16
src/RichTextEditor.js Vedi File

@@ -48,13 +48,13 @@ export default class RichTextEditor extends Component {
48 48
     );
49 49
   }
50 50
 
51
-  //-------------------------------------------------------------------------------
52
-  //--------------- Public API
53
-
54 51
   _sendAction(action, data) {
55 52
     this.webviewBridge.sendToBridge(JSON.stringify({type: action, data}));
56 53
   }
57 54
 
55
+  //-------------------------------------------------------------------------------
56
+  //--------------- Public API
57
+  
58 58
   setHTML(html) {
59 59
     this._sendAction(actions.setHtml, html);
60 60
   }
@@ -104,49 +104,54 @@ export default class RichTextEditor extends Component {
104 104
   }
105 105
 
106 106
   removeFormat() {
107
-    this.refs.webviewbridge.sendToBridge(`zss_editor.removeFormating();`);
107
+    this._sendAction(actions.removeFormat);
108 108
   }
109 109
 
110 110
   alignLeft() {
111
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setJustifyLeft();`);
111
+    this._sendAction(actions.alignLeft);
112 112
   }
113 113
 
114 114
   alignCenter() {
115
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setJustifyCenter();`);
115
+    this._sendAction(actions.alignCenter);
116 116
   }
117 117
 
118 118
   alignRight() {
119
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setJustifyRight();`);
119
+    this._sendAction(actions.alignRight);
120 120
   }
121 121
 
122 122
   alignFull() {
123
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setJustifyFull();`);
123
+    this._sendAction(actions.alignFull);
124 124
   }
125 125
 
126 126
   insertBulletsList() {
127
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setUnorderedList();`);
127
+    this._sendAction(actions.insertBulletsList);
128 128
   }
129 129
 
130 130
   insertOrderedList() {
131
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setOrderedList();`);
131
+    this._sendAction(actions.insertOrderedList);
132 132
   }
133 133
 
134 134
   setSubscript() {
135
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setSubscript();`);
135
+    this._sendAction(actions.setSubscript);
136 136
   }
137
+
137 138
   setSuperscript() {
138
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setSuperscript();`);
139
+    this._sendAction(actions.setSuperscript);
139 140
   }
141
+
140 142
   setStrikethrough() {
141
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setStrikeThrough();`);
143
+    this._sendAction(actions.setStrikethrough);
142 144
   }
145
+
143 146
   setHR() {
144
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setHorizontalRule();`);
147
+    this._sendAction(actions.setHR);
145 148
   }
149
+
146 150
   setIndent() {
147
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setIndent();`);
151
+    this._sendAction(actions.setIndent);
148 152
   }
153
+
149 154
   setOutdent() {
150
-    this.refs.webviewbridge.sendToBridge(`zss_editor.setOutdent();`);
155
+    this._sendAction(actions.setOutdent);
151 156
   }
152 157
 }

+ 39
- 0
src/WebviewMessageHandler.js Vedi File

@@ -41,6 +41,45 @@ export const InjectedMessageHandler = `
41 41
         case '${actions.setParagraph}':
42 42
           zss_editor.setParagraph()
43 43
           break;
44
+        case '${actions.removeFormat}':
45
+          zss_editor.removeFormating();
46
+          break;
47
+        case '${actions.alignLeft}':
48
+          zss_editor.setJustifyLeft();
49
+          break;
50
+        case '${actions.alignCenter}':
51
+          zss_editor.setJustifyCenter();
52
+          break;
53
+        case '${actions.alignRight}':
54
+          zss_editor.setJustifyRight();
55
+          break;
56
+        case '${actions.alignFull}':
57
+          zss_editor.setJustifyFull();
58
+          break;
59
+        case '${actions.insertBulletsList}':
60
+          zss_editor.setUnorderedList();
61
+          break;
62
+        case '${actions.insertOrderedList}':
63
+          zss_editor.setOrderedList();
64
+          break;
65
+        case '${actions.setSubscript}':
66
+          zss_editor.setSubscript();
67
+          break;
68
+        case '${actions.setSuperscript}':
69
+          zss_editor.setSuperscript();
70
+          break;
71
+        case '${actions.setStrikethrough}':
72
+          zss_editor.setStrikethrough();
73
+          break;
74
+        case '${actions.setHR}':
75
+          zss_editor.setHorizontalRule();
76
+          break;
77
+        case '${actions.setIndent}':
78
+          zss_editor.setIndent();
79
+          break;
80
+        case '${actions.setOutdent}':
81
+          zss_editor.setOutdent();
82
+          break;
44 83
       }
45 84
     };
46 85
   }

+ 15
- 2
src/const.js Vedi File

@@ -10,5 +10,18 @@ export const actions = {
10 10
   heading4: 'HEADING4',
11 11
   heading5: 'HEADING5',
12 12
   heading6: 'HEADING6',
13
-  setParagraph: 'SET_PARAGRAPH'
14
-}
13
+  setParagraph: 'SET_PARAGRAPH',
14
+  removeFormat: 'REMOVE_FORMAT',
15
+  alignLeft: 'ALIGN_LEFT',
16
+  alignCenter: 'ALIGN_CENTER',
17
+  alignRight: 'ALIGN_RIGHT',
18
+  alignFull: 'ALIGN_FULL',
19
+  insertBulletsList: 'INST_BULLETS',
20
+  insertOrderedList: 'INST_ORDERED',
21
+  setSubscript: 'SET_SUB',
22
+  setSuperscript: 'SET_SUPER',
23
+  setStrikethrough: 'SET_STRIKETHRU',
24
+  setHR: 'SET_HR',
25
+  setIndent: 'SET_INDENT',
26
+  setOutdent: 'SET_OUTDENT'
27
+};