rn-rich-text-editor 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -131,10 +131,14 @@ exports.RichEditor = (0, react_1.forwardRef)((props, ref) => {
131
131
  },
132
132
  }));
133
133
  return (react_1.default.createElement(react_1.default.Fragment, null,
134
- react_1.default.createElement(react_native_webview_1.WebView, { ref: webRef, originWhitelist: ['*'], javaScriptEnabled: true, scrollEnabled: false, source: (0, createHTML_1.createHTML)(), onMessage: handleMessage, ...props.webViewProps }),
134
+ react_1.default.createElement(react_native_webview_1.WebView, { ref: webRef, originWhitelist: ['*'], javaScriptEnabled: true, scrollEnabled: false, source: (0, createHTML_1.createHTML)(), onMessage: handleMessage, style: [styles.editorWebView, props.style], ...props.webViewProps }),
135
135
  react_native_1.Platform.OS === 'android' && (react_1.default.createElement(react_native_1.TextInput, { ref: inputRef, style: styles.hiddenInput }))));
136
136
  });
137
137
  const styles = react_native_1.StyleSheet.create({
138
+ editorWebView: {
139
+ minHeight: 150,
140
+ backgroundColor: '#fff',
141
+ },
138
142
  hiddenInput: {
139
143
  position: 'absolute',
140
144
  width: 1,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- export declare const defaultActions: ("bold" | "italic" | "underline" | "checkboxList" | "link" | "keyboard")[];
2
+ export declare const defaultActions: ("bold" | "italic" | "underline" | "strikethrough" | "removeFormat" | "checkboxList" | "insertUnorderedList" | "insertOrderedList" | "blockquote" | "code" | "link" | "indent" | "outdent" | "justifyLeft" | "justifyCenter" | "justifyRight" | "justifyFull" | "undo" | "redo" | "keyboard")[];
3
3
  interface RichToolbarProps {
4
4
  editor?: {
5
5
  current: any;
@@ -40,10 +40,24 @@ const react_native_1 = require("react-native");
40
40
  const actions_1 = require("./actions");
41
41
  exports.defaultActions = [
42
42
  actions_1.actions.keyboard,
43
+ actions_1.actions.undo,
44
+ actions_1.actions.redo,
43
45
  actions_1.actions.setBold,
44
46
  actions_1.actions.setItalic,
45
47
  actions_1.actions.setUnderline,
48
+ actions_1.actions.strikethrough,
49
+ actions_1.actions.removeFormat,
50
+ actions_1.actions.insertUnorderedList,
51
+ actions_1.actions.insertOrderedList,
46
52
  actions_1.actions.checkboxList,
53
+ actions_1.actions.blockquote,
54
+ actions_1.actions.code,
55
+ actions_1.actions.indent,
56
+ actions_1.actions.outdent,
57
+ actions_1.actions.justifyLeft,
58
+ actions_1.actions.justifyCenter,
59
+ actions_1.actions.justifyRight,
60
+ actions_1.actions.justifyFull,
47
61
  actions_1.actions.insertLink,
48
62
  ];
49
63
  // Icons from img folder - direct require now that icons exist
@@ -52,8 +66,22 @@ function getDefaultIcon() {
52
66
  [actions_1.actions.setBold]: require('./img/bold.png'),
53
67
  [actions_1.actions.setItalic]: require('./img/italic.png'),
54
68
  [actions_1.actions.setUnderline]: require('./img/underline.png'),
69
+ [actions_1.actions.strikethrough]: require('./img/strikethrough.png'),
70
+ [actions_1.actions.removeFormat]: require('./img/remove_format.png'),
55
71
  [actions_1.actions.checkboxList]: require('./img/checkbox.png'),
72
+ [actions_1.actions.insertUnorderedList]: require('./img/ul.png'),
73
+ [actions_1.actions.insertOrderedList]: require('./img/ol.png'),
74
+ [actions_1.actions.blockquote]: require('./img/blockquote.png'),
75
+ [actions_1.actions.code]: require('./img/code.png'),
56
76
  [actions_1.actions.insertLink]: require('./img/link.png'),
77
+ [actions_1.actions.indent]: require('./img/indent.png'),
78
+ [actions_1.actions.outdent]: require('./img/outdent.png'),
79
+ [actions_1.actions.justifyLeft]: require('./img/justify_left.png'),
80
+ [actions_1.actions.justifyCenter]: require('./img/justify_center.png'),
81
+ [actions_1.actions.justifyRight]: require('./img/justify_right.png'),
82
+ [actions_1.actions.justifyFull]: require('./img/justify_full.png'),
83
+ [actions_1.actions.undo]: require('./img/undo.png'),
84
+ [actions_1.actions.redo]: require('./img/redo.png'),
57
85
  [actions_1.actions.keyboard]: require('./img/keyboard.png'),
58
86
  };
59
87
  }
@@ -127,7 +155,21 @@ function RichToolbar({ editor, getEditor, actions: actionsProp = exports.default
127
155
  case actions_1.actions.setBold:
128
156
  case actions_1.actions.setItalic:
129
157
  case actions_1.actions.setUnderline:
158
+ case actions_1.actions.strikethrough:
159
+ case actions_1.actions.removeFormat:
130
160
  case actions_1.actions.checkboxList:
161
+ case actions_1.actions.insertUnorderedList:
162
+ case actions_1.actions.insertOrderedList:
163
+ case actions_1.actions.blockquote:
164
+ case actions_1.actions.code:
165
+ case actions_1.actions.indent:
166
+ case actions_1.actions.outdent:
167
+ case actions_1.actions.justifyLeft:
168
+ case actions_1.actions.justifyCenter:
169
+ case actions_1.actions.justifyRight:
170
+ case actions_1.actions.justifyFull:
171
+ case actions_1.actions.undo:
172
+ case actions_1.actions.redo:
131
173
  (_c = editorInstance.showAndroidKeyboard) === null || _c === void 0 ? void 0 : _c.call(editorInstance);
132
174
  (_d = editorInstance.sendAction) === null || _d === void 0 ? void 0 : _d.call(editorInstance, action);
133
175
  break;
package/dist/actions.d.ts CHANGED
@@ -2,8 +2,22 @@ export declare const actions: {
2
2
  readonly setBold: "bold";
3
3
  readonly setItalic: "italic";
4
4
  readonly setUnderline: "underline";
5
+ readonly strikethrough: "strikethrough";
6
+ readonly removeFormat: "removeFormat";
5
7
  readonly checkboxList: "checkboxList";
8
+ readonly insertUnorderedList: "insertUnorderedList";
9
+ readonly insertOrderedList: "insertOrderedList";
10
+ readonly blockquote: "blockquote";
11
+ readonly code: "code";
6
12
  readonly insertLink: "link";
13
+ readonly indent: "indent";
14
+ readonly outdent: "outdent";
15
+ readonly justifyLeft: "justifyLeft";
16
+ readonly justifyCenter: "justifyCenter";
17
+ readonly justifyRight: "justifyRight";
18
+ readonly justifyFull: "justifyFull";
19
+ readonly undo: "undo";
20
+ readonly redo: "redo";
7
21
  readonly keyboard: "keyboard";
8
22
  readonly init: "init";
9
23
  };
package/dist/actions.js CHANGED
@@ -5,8 +5,22 @@ exports.actions = {
5
5
  setBold: 'bold',
6
6
  setItalic: 'italic',
7
7
  setUnderline: 'underline',
8
+ strikethrough: 'strikethrough',
9
+ removeFormat: 'removeFormat',
8
10
  checkboxList: 'checkboxList',
11
+ insertUnorderedList: 'insertUnorderedList',
12
+ insertOrderedList: 'insertOrderedList',
13
+ blockquote: 'blockquote',
14
+ code: 'code',
9
15
  insertLink: 'link',
16
+ indent: 'indent',
17
+ outdent: 'outdent',
18
+ justifyLeft: 'justifyLeft',
19
+ justifyCenter: 'justifyCenter',
20
+ justifyRight: 'justifyRight',
21
+ justifyFull: 'justifyFull',
22
+ undo: 'undo',
23
+ redo: 'redo',
10
24
  keyboard: 'keyboard',
11
- init: 'init'
25
+ init: 'init',
12
26
  };
@@ -10,11 +10,19 @@ function createHTML() {
10
10
  <head>
11
11
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
12
12
  <style>
13
- body { margin:0; font-family: system-ui; }
13
+ html, body {
14
+ margin: 0;
15
+ padding: 0;
16
+ font-family: system-ui;
17
+ min-height: 200px;
18
+ height: 100%;
19
+ }
14
20
  #editor {
15
21
  padding: 12px;
16
- min-height: 100%;
22
+ min-height: 150px;
17
23
  outline: none;
24
+ -webkit-user-select: text;
25
+ user-select: text;
18
26
  }
19
27
  [placeholder]:empty::before {
20
28
  content: attr(placeholder);
@@ -59,11 +67,48 @@ ${(0, contentCSS_1.getContentCSS)()}
59
67
  window.addEventListener('message', e => {
60
68
  const msg = JSON.parse(e.data);
61
69
  const type = msg.type;
62
-
63
- if (type === 'bold') document.execCommand('bold');
64
- else if (type === 'italic') document.execCommand('italic');
65
- else if (type === 'underline') document.execCommand('underline');
66
- else if (type === 'link') {
70
+
71
+ if (type === 'focus') {
72
+ editor.focus();
73
+ } else if (type === 'blur') {
74
+ editor.blur();
75
+ } else if (type === 'bold') {
76
+ document.execCommand('bold');
77
+ } else if (type === 'italic') {
78
+ document.execCommand('italic');
79
+ } else if (type === 'underline') {
80
+ document.execCommand('underline');
81
+ } else if (type === 'strikethrough') {
82
+ document.execCommand('strikeThrough');
83
+ } else if (type === 'removeFormat') {
84
+ document.execCommand('removeFormat');
85
+ } else if (type === 'undo') {
86
+ document.execCommand('undo');
87
+ } else if (type === 'redo') {
88
+ document.execCommand('redo');
89
+ } else if (type === 'insertUnorderedList') {
90
+ document.execCommand('insertUnorderedList');
91
+ } else if (type === 'insertOrderedList') {
92
+ document.execCommand('insertOrderedList');
93
+ } else if (type === 'checkboxList') {
94
+ document.execCommand('insertOrderedList');
95
+ } else if (type === 'indent') {
96
+ document.execCommand('indent');
97
+ } else if (type === 'outdent') {
98
+ document.execCommand('outdent');
99
+ } else if (type === 'justifyLeft') {
100
+ document.execCommand('justifyLeft');
101
+ } else if (type === 'justifyCenter') {
102
+ document.execCommand('justifyCenter');
103
+ } else if (type === 'justifyRight') {
104
+ document.execCommand('justifyRight');
105
+ } else if (type === 'justifyFull') {
106
+ document.execCommand('justifyFull');
107
+ } else if (type === 'blockquote') {
108
+ document.execCommand('formatBlock', false, 'blockquote');
109
+ } else if (type === 'code') {
110
+ document.execCommand('formatBlock', false, 'pre');
111
+ } else if (type === 'link') {
67
112
  const url = prompt('Enter link URL:');
68
113
  if (url) {
69
114
  const sel = window.getSelection();
@@ -75,19 +120,6 @@ ${(0, contentCSS_1.getContentCSS)()}
75
120
  range.insertNode(link);
76
121
  }
77
122
  }
78
- else if (type === 'checkboxList') {
79
- if (document.queryCommandState('insertOrderedList')) {
80
- document.execCommand('insertOrderedList');
81
- } else {
82
- document.execCommand('insertOrderedList');
83
- }
84
- }
85
- else if (type === 'focus') {
86
- editor.focus();
87
- }
88
- else if (type === 'blur') {
89
- editor.blur();
90
- }
91
123
  });
92
124
  </script>
93
125
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-rich-text-editor",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A rich text editor component for React Native",
5
5
  "keywords": [
6
6
  "react-native",