|
@@ -1,176 +1,118 @@
|
1
|
1
|
import {actions, messages} from './const';
|
2
|
2
|
|
3
|
|
-export const InjectedMessageHandler = `
|
4
|
|
- if (WebViewBridge) {
|
5
|
|
- WebViewBridge.onMessage = function (message) {
|
6
|
|
-
|
7
|
|
- const action = JSON.parse(message);
|
8
|
|
-
|
9
|
|
- switch(action.type) {
|
10
|
|
- case '${actions.enableOnChange}':
|
11
|
|
- zss_editor.enableOnChange();
|
12
|
|
- break;
|
13
|
|
- case '${actions.setTitleHtml}':
|
14
|
|
- zss_editor.setTitleHTML(action.data);
|
15
|
|
- break;
|
16
|
|
- case '${actions.toggleTitle}':
|
17
|
|
- zss_editor.toggleTitle(action.data);
|
18
|
|
- break;
|
19
|
|
- case '${actions.hideTitle}':
|
20
|
|
- zss_editor.hideTitle(action.data);
|
21
|
|
- break;
|
22
|
|
- case '${actions.showTitle}':
|
23
|
|
- zss_editor.showTitle(action.data);
|
24
|
|
- break;
|
25
|
|
- case '${actions.setContentHtml}':
|
26
|
|
- zss_editor.setContentHTML(action.data);
|
27
|
|
- break;
|
28
|
|
- case '${actions.blurTitleEditor}':
|
29
|
|
- zss_editor.blurTitleEditor();
|
30
|
|
- break;
|
31
|
|
- case '${actions.blurContentEditor}':
|
32
|
|
- zss_editor.blurContentEditor();
|
33
|
|
- break;
|
34
|
|
- case '${actions.setBold}':
|
35
|
|
- zss_editor.setBold();
|
36
|
|
- break;
|
37
|
|
- case '${actions.setItalic}':
|
38
|
|
- zss_editor.setItalic();
|
39
|
|
- break;
|
40
|
|
- case '${actions.setUnderline}':
|
41
|
|
- zss_editor.setUnderline();
|
42
|
|
- break;
|
43
|
|
- case '${actions.heading1}':
|
44
|
|
- zss_editor.setHeading('h1');
|
45
|
|
- break;
|
46
|
|
- case '${actions.heading2}':
|
47
|
|
- zss_editor.setHeading('h2');
|
48
|
|
- break;
|
49
|
|
- case '${actions.heading3}':
|
50
|
|
- zss_editor.setHeading('h3');
|
51
|
|
- break;
|
52
|
|
- case '${actions.heading4}':
|
53
|
|
- zss_editor.setHeading('h4');
|
54
|
|
- break;
|
55
|
|
- case '${actions.heading5}':
|
56
|
|
- zss_editor.setHeading('h5');
|
57
|
|
- break;
|
58
|
|
- case '${actions.heading6}':
|
59
|
|
- zss_editor.setHeading('h6');
|
60
|
|
- break;
|
61
|
|
- case '${actions.setParagraph}':
|
62
|
|
- zss_editor.setParagraph();
|
63
|
|
- break;
|
64
|
|
- case '${actions.removeFormat}':
|
65
|
|
- zss_editor.removeFormating();
|
66
|
|
- break;
|
67
|
|
- case '${actions.alignLeft}':
|
68
|
|
- zss_editor.setJustifyLeft();
|
69
|
|
- break;
|
70
|
|
- case '${actions.alignCenter}':
|
71
|
|
- zss_editor.setJustifyCenter();
|
72
|
|
- break;
|
73
|
|
- case '${actions.alignRight}':
|
74
|
|
- zss_editor.setJustifyRight();
|
75
|
|
- break;
|
76
|
|
- case '${actions.alignFull}':
|
77
|
|
- zss_editor.setJustifyFull();
|
78
|
|
- break;
|
79
|
|
- case '${actions.insertBulletsList}':
|
80
|
|
- zss_editor.setUnorderedList();
|
81
|
|
- break;
|
82
|
|
- case '${actions.insertOrderedList}':
|
83
|
|
- zss_editor.setOrderedList();
|
84
|
|
- break;
|
85
|
|
- case '${actions.insertLink}':
|
86
|
|
- zss_editor.insertLink(action.data.url, action.data.title);
|
87
|
|
- break;
|
88
|
|
- case '${actions.updateLink}':
|
89
|
|
- zss_editor.updateLink(action.data.url, action.data.title);
|
90
|
|
- break;
|
91
|
|
- case '${actions.insertImage}':
|
92
|
|
- zss_editor.insertImage(action.data);
|
93
|
|
- break;
|
94
|
|
- case '${actions.setSubscript}':
|
95
|
|
- zss_editor.setSubscript();
|
96
|
|
- break;
|
97
|
|
- case '${actions.setSuperscript}':
|
98
|
|
- zss_editor.setSuperscript();
|
99
|
|
- break;
|
100
|
|
- case '${actions.setStrikethrough}':
|
101
|
|
- zss_editor.setStrikeThrough();
|
102
|
|
- break;
|
103
|
|
- case '${actions.setHR}':
|
104
|
|
- zss_editor.setHorizontalRule();
|
105
|
|
- break;
|
106
|
|
- case '${actions.setIndent}':
|
107
|
|
- zss_editor.setIndent();
|
108
|
|
- break;
|
109
|
|
- case '${actions.setOutdent}':
|
110
|
|
- zss_editor.setOutdent();
|
111
|
|
- break;
|
112
|
|
- case '${actions.setTitlePlaceholder}':
|
113
|
|
- zss_editor.setTitlePlaceholder(action.data);
|
114
|
|
- break;
|
115
|
|
- case '${actions.setContentPlaceholder}':
|
116
|
|
- zss_editor.setContentPlaceholder(action.data);
|
117
|
|
- break;
|
118
|
|
- case '${actions.getTitleHtml}':
|
119
|
|
- var html = zss_editor.getTitleHTML();
|
120
|
|
- WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));
|
121
|
|
- break;
|
122
|
|
- case '${actions.getTitleText}':
|
123
|
|
- var html = zss_editor.getTitleText();
|
124
|
|
- WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));
|
125
|
|
- break;
|
126
|
|
- case '${actions.getContentHtml}':
|
127
|
|
- var html = zss_editor.getContentHTML();
|
128
|
|
- WebViewBridge.send(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));
|
129
|
|
- break;
|
130
|
|
- case '${actions.setTitleFocusHandler}':
|
131
|
|
- zss_editor.setTitleFocusHandler();
|
132
|
|
- break;
|
133
|
|
- case '${actions.setContentFocusHandler}':
|
134
|
|
- zss_editor.setContentFocusHandler();
|
135
|
|
- break;
|
136
|
|
- case '${actions.getSelectedText}':
|
137
|
|
- var selectedText = getSelection().toString();
|
138
|
|
- WebViewBridge.send(JSON.stringify({type: '${messages.SELECTED_TEXT_RESPONSE}', data: selectedText}));
|
139
|
|
- break;
|
140
|
|
- case '${actions.focusContent}':
|
141
|
|
- zss_editor.focusContent();
|
142
|
|
- break;
|
143
|
|
- case '${actions.focusTitle}':
|
144
|
|
- zss_editor.focusTitle();
|
145
|
|
- break;
|
146
|
|
- case '${actions.prepareInsert}':
|
147
|
|
- zss_editor.prepareInsert();
|
148
|
|
- break;
|
149
|
|
- case '${actions.restoreSelection}':
|
150
|
|
- zss_editor.restorerange();
|
151
|
|
- break;
|
152
|
|
- case '${actions.setCustomCSS}':
|
153
|
|
- zss_editor.setCustomCSS(action.data);
|
154
|
|
- break;
|
155
|
|
- case '${actions.setTextColor}':
|
156
|
|
- zss_editor.setTextColor(action.data);
|
157
|
|
- break;
|
158
|
|
- case '${actions.setBackgroundColor}':
|
159
|
|
- zss_editor.setBackgroundColor(action.data);
|
160
|
|
- break;
|
161
|
|
- case '${actions.init}':
|
162
|
|
- zss_editor.init();
|
163
|
|
- break;
|
164
|
|
- case '${actions.setEditorHeight}':
|
165
|
|
- zss_editor.setEditorHeight(action.data);
|
166
|
|
- break;
|
167
|
|
- case '${actions.setFooterHeight}':
|
168
|
|
- zss_editor.setFooterHeight(action.data);
|
169
|
|
- break;
|
170
|
|
- case '${actions.setPlatform}':
|
171
|
|
- zss_editor.setPlatform(action.data);
|
172
|
|
- break;
|
173
|
|
- }
|
174
|
|
- };
|
|
3
|
+export const MessageConverter = (action) => {
|
|
4
|
+ switch(action.type) {
|
|
5
|
+ case `${actions.init}`:
|
|
6
|
+ return 'zss_editor.init();';
|
|
7
|
+ case `${actions.setPlatform}`:
|
|
8
|
+ return `zss_editor.setPlatform('${action.data}');`;
|
|
9
|
+ case `${actions.enableOnChange}`:
|
|
10
|
+ return 'zss_editor.enableOnChange()';
|
|
11
|
+ case `${actions.setTitleHtml}`:
|
|
12
|
+ return `zss_editor.setTitleHTML('${action.data}');`;
|
|
13
|
+ case `${actions.toggleTitle}`:
|
|
14
|
+ return `zss_editor.toggleTitle('${action.data}');`;
|
|
15
|
+ case `${actions.hideTitle}`:
|
|
16
|
+ return `zss_editor.hideTitle('${action.data}');`;
|
|
17
|
+ case `${actions.showTitle}`:
|
|
18
|
+ return `zss_editor.showTitle('${action.data}');`;
|
|
19
|
+ case `${actions.setContentHtml}`:
|
|
20
|
+ return `zss_editor.setContentHTML('${action.data}');`;
|
|
21
|
+ case `${actions.blurTitleEditor}`:
|
|
22
|
+ return `zss_editor.blurTitleEditor();`;
|
|
23
|
+ case `${actions.blurContentEditor}`:
|
|
24
|
+ return `zss_editor.blurContentEditor();`;
|
|
25
|
+ case `${actions.setBold}`:
|
|
26
|
+ return `zss_editor.setBold();`;
|
|
27
|
+ case `${actions.setItalic}`:
|
|
28
|
+ return `zss_editor.setItalic();`;
|
|
29
|
+ case `${actions.setUnderline}`:
|
|
30
|
+ return `zss_editor.setUnderline();`;
|
|
31
|
+ case `${actions.heading1}`:
|
|
32
|
+ return `zss_editor.setHeading('h1');`;
|
|
33
|
+ case `${actions.heading2}`:
|
|
34
|
+ return `zss_editor.setHeading('h2');`;
|
|
35
|
+ case `${actions.heading3}`:
|
|
36
|
+ return `zss_editor.setHeading('h3');`;
|
|
37
|
+ case `${actions.heading4}`:
|
|
38
|
+ return `zss_editor.setHeading('h4');`;
|
|
39
|
+ case `${actions.heading5}`:
|
|
40
|
+ return `zss_editor.setHeading('h5');`;
|
|
41
|
+ case `${actions.heading6}`:
|
|
42
|
+ return `zss_editor.setHeading('h6');`;
|
|
43
|
+ case `${actions.setParagraph}`:
|
|
44
|
+ return `zss_editor.setParagraph();`;
|
|
45
|
+ case `${actions.removeFormat}`:
|
|
46
|
+ return `zss_editor.removeFormating();`;
|
|
47
|
+ case `${actions.alignLeft}`:
|
|
48
|
+ return `zss_editor.setJustifyLeft();`;
|
|
49
|
+ case `${actions.alignCenter}`:
|
|
50
|
+ return `zss_editor.setJustifyCenter();`;
|
|
51
|
+ case `${actions.alignRight}`:
|
|
52
|
+ return `zss_editor.setJustifyRight();`;
|
|
53
|
+ case `${actions.alignFull}`:
|
|
54
|
+ return `zss_editor.setJustifyFull();`;
|
|
55
|
+ case `${actions.insertBulletsList}`:
|
|
56
|
+ return `zss_editor.setUnorderedList();`;
|
|
57
|
+ case `${actions.insertOrderedList}`:
|
|
58
|
+ return `zss_editor.setOrderedList();`;
|
|
59
|
+ case `${actions.insertLink}`:
|
|
60
|
+ return `zss_editor.insertLink('${action.data.url}, ${action.data.title}');`;
|
|
61
|
+ case `${actions.updateLink}`:
|
|
62
|
+ return `zss_editor.updateLink('${action.data.url}, ${action.data.title}');`;
|
|
63
|
+ case `${actions.insertImage}`:
|
|
64
|
+ return `zss_editor.insertImage('${action.data}');`;
|
|
65
|
+ case `${actions.setSubscript}`:
|
|
66
|
+ return `zss_editor.setSubscript();`;
|
|
67
|
+ case `${actions.setSuperscript}`:
|
|
68
|
+ return `zss_editor.setSuperscript();`;
|
|
69
|
+ case `${actions.setStrikethrough}`:
|
|
70
|
+ return `zss_editor.setStrikeThrough();`;
|
|
71
|
+ case `${actions.setHR}`:
|
|
72
|
+ return `zss_editor.setHorizontalRule();`;
|
|
73
|
+ case `${actions.setIndent}`:
|
|
74
|
+ return `zss_editor.setIndent();`;
|
|
75
|
+ case `${actions.setOutdent}`:
|
|
76
|
+ return `zss_editor.setOutdent();`;
|
|
77
|
+ case `${actions.setTitlePlaceholder}`:
|
|
78
|
+ return `zss_editor.setTitlePlaceholder('${action.data}');`;
|
|
79
|
+ case `${actions.setContentPlaceholder}`:
|
|
80
|
+ return `zss_editor.setContentPlaceholder('${action.data}');`;
|
|
81
|
+ case `${actions.focusContent}`:
|
|
82
|
+ return `zss_editor.focusContent();`;
|
|
83
|
+ case `${actions.focusTitle}`:
|
|
84
|
+ return `zss_editor.focusTitle();`;
|
|
85
|
+ case `${actions.prepareInsert}`:
|
|
86
|
+ return `zss_editor.prepareInsert();`;
|
|
87
|
+ case `${actions.restoreSelection}`:
|
|
88
|
+ return `zss_editor.restorerange();`;
|
|
89
|
+ case `${actions.setCustomCSS}`:
|
|
90
|
+ return `zss_editor.setCustomCSS('${action.data}');`;
|
|
91
|
+ case `${actions.setTextColor}`:
|
|
92
|
+ return `zss_editor.setTextColor('${action.data}');`;
|
|
93
|
+ case `${actions.setFontSize}`:
|
|
94
|
+ return `zss_editor.setFontSize('${action.data}');`;
|
|
95
|
+ case `${actions.setBackgroundColor}`:
|
|
96
|
+ return `zss_editor.setBackgroundColor('${action.data}');`;
|
|
97
|
+ case `${actions.setEditorHeight}`:
|
|
98
|
+ return `zss_editor.setEditorHeight('${action.data}');`;
|
|
99
|
+ case `${actions.setFooterHeight}`:
|
|
100
|
+ return `zss_editor.setFooterHeight('${action.data}');`;
|
|
101
|
+ case `${actions.setTitleFocusHandler}`:
|
|
102
|
+ return `zss_editor.setTitleFocusHandler();`;
|
|
103
|
+ case `${actions.setContentFocusHandler}`:
|
|
104
|
+ return `zss_editor.setContentFocusHandler();`;
|
|
105
|
+ case `${actions.getTitleHtml}`:
|
|
106
|
+ return `var html = zss_editor.getTitleHTML();
|
|
107
|
+ ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));`
|
|
108
|
+ case `${actions.getTitleText}`:
|
|
109
|
+ return `var html = zss_editor.getTitleText();
|
|
110
|
+ ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));`
|
|
111
|
+ case `${actions.getContentHtml}`:
|
|
112
|
+ return `var html = zss_editor.getContentHTML();
|
|
113
|
+ ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));`
|
|
114
|
+ case `${actions.getSelectedText}`:
|
|
115
|
+ return `var selectedText = getSelection().toString();
|
|
116
|
+ ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.SELECTED_TEXT_RESPONSE}', data: selectedText}));`
|
175
|
117
|
}
|
176
|
|
-`;
|
|
118
|
+};
|