You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebviewMessageHandler.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {actions, messages} from './const';
  2. export const MessageConverter = (action) => {
  3. switch(action.type) {
  4. case `${actions.init}`:
  5. return 'zss_editor.init();';
  6. case `${actions.setPlatform}`:
  7. return `zss_editor.setPlatform('${action.data}');`;
  8. case `${actions.enableOnChange}`:
  9. return 'zss_editor.enableOnChange()';
  10. case `${actions.setTitleHtml}`:
  11. return `zss_editor.setTitleHTML('${action.data}');`;
  12. case `${actions.toggleTitle}`:
  13. return `zss_editor.toggleTitle('${action.data}');`;
  14. case `${actions.hideTitle}`:
  15. return `zss_editor.hideTitle('${action.data}');`;
  16. case `${actions.showTitle}`:
  17. return `zss_editor.showTitle('${action.data}');`;
  18. case `${actions.setContentHtml}`:
  19. return `zss_editor.setContentHTML('${action.data}');`;
  20. case `${actions.blurTitleEditor}`:
  21. return `zss_editor.blurTitleEditor();`;
  22. case `${actions.blurContentEditor}`:
  23. return `zss_editor.blurContentEditor();`;
  24. case `${actions.setBold}`:
  25. return `zss_editor.setBold();`;
  26. case `${actions.setItalic}`:
  27. return `zss_editor.setItalic();`;
  28. case `${actions.setUnderline}`:
  29. return `zss_editor.setUnderline();`;
  30. case `${actions.heading1}`:
  31. return `zss_editor.setHeading('h1');`;
  32. case `${actions.heading2}`:
  33. return `zss_editor.setHeading('h2');`;
  34. case `${actions.heading3}`:
  35. return `zss_editor.setHeading('h3');`;
  36. case `${actions.heading4}`:
  37. return `zss_editor.setHeading('h4');`;
  38. case `${actions.heading5}`:
  39. return `zss_editor.setHeading('h5');`;
  40. case `${actions.heading6}`:
  41. return `zss_editor.setHeading('h6');`;
  42. case `${actions.setParagraph}`:
  43. return `zss_editor.setParagraph();`;
  44. case `${actions.removeFormat}`:
  45. return `zss_editor.removeFormating();`;
  46. case `${actions.alignLeft}`:
  47. return `zss_editor.setJustifyLeft();`;
  48. case `${actions.alignCenter}`:
  49. return `zss_editor.setJustifyCenter();`;
  50. case `${actions.alignRight}`:
  51. return `zss_editor.setJustifyRight();`;
  52. case `${actions.alignFull}`:
  53. return `zss_editor.setJustifyFull();`;
  54. case `${actions.insertBulletsList}`:
  55. return `zss_editor.setUnorderedList();`;
  56. case `${actions.insertOrderedList}`:
  57. return `zss_editor.setOrderedList();`;
  58. case `${actions.insertLink}`:
  59. return `zss_editor.insertLink('${action.data.url}, ${action.data.title}');`;
  60. case `${actions.updateLink}`:
  61. return `zss_editor.updateLink('${action.data.url}, ${action.data.title}');`;
  62. case `${actions.insertImage}`:
  63. return `zss_editor.insertImage('${action.data}');`;
  64. case `${actions.setSubscript}`:
  65. return `zss_editor.setSubscript();`;
  66. case `${actions.setSuperscript}`:
  67. return `zss_editor.setSuperscript();`;
  68. case `${actions.setStrikethrough}`:
  69. return `zss_editor.setStrikeThrough();`;
  70. case `${actions.setHR}`:
  71. return `zss_editor.setHorizontalRule();`;
  72. case `${actions.setIndent}`:
  73. return `zss_editor.setIndent();`;
  74. case `${actions.setOutdent}`:
  75. return `zss_editor.setOutdent();`;
  76. case `${actions.setTitlePlaceholder}`:
  77. return `zss_editor.setTitlePlaceholder('${action.data}');`;
  78. case `${actions.setContentPlaceholder}`:
  79. return `zss_editor.setContentPlaceholder('${action.data}');`;
  80. case `${actions.focusContent}`:
  81. return `zss_editor.focusContent();`;
  82. case `${actions.focusTitle}`:
  83. return `zss_editor.focusTitle();`;
  84. case `${actions.prepareInsert}`:
  85. return `zss_editor.prepareInsert();`;
  86. case `${actions.restoreSelection}`:
  87. return `zss_editor.restorerange();`;
  88. case `${actions.setCustomCSS}`:
  89. return `zss_editor.setCustomCSS('${action.data}');`;
  90. case `${actions.setTextColor}`:
  91. return `zss_editor.setTextColor('${action.data}');`;
  92. case `${actions.setFontSize}`:
  93. return `zss_editor.setFontSize('${action.data}');`;
  94. case `${actions.setBackgroundColor}`:
  95. return `zss_editor.setBackgroundColor('${action.data}');`;
  96. case `${actions.setEditorHeight}`:
  97. return `zss_editor.setEditorHeight('${action.data}');`;
  98. case `${actions.setFooterHeight}`:
  99. return `zss_editor.setFooterHeight('${action.data}');`;
  100. case `${actions.setTitleFocusHandler}`:
  101. return `zss_editor.setTitleFocusHandler();`;
  102. case `${actions.setContentFocusHandler}`:
  103. return `zss_editor.setContentFocusHandler();`;
  104. case `${actions.getTitleHtml}`:
  105. return `var html = zss_editor.getTitleHTML();
  106. ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));`
  107. case `${actions.getTitleText}`:
  108. return `var html = zss_editor.getTitleText();
  109. ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));`
  110. case `${actions.getContentHtml}`:
  111. return `var html = zss_editor.getContentHTML();
  112. ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));`
  113. case `${actions.getSelectedText}`:
  114. return `var selectedText = getSelection().toString();
  115. ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.SELECTED_TEXT_RESPONSE}', data: selectedText}));`
  116. }
  117. };