rn-rich-text-editor 0.0.5 → 0.0.6

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.
@@ -40,74 +40,66 @@ 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,
45
43
  actions_1.actions.setBold,
46
44
  actions_1.actions.setItalic,
47
45
  actions_1.actions.setUnderline,
48
- actions_1.actions.strikethrough,
49
46
  actions_1.actions.removeFormat,
50
- actions_1.actions.insertUnorderedList,
51
- actions_1.actions.insertOrderedList,
52
- actions_1.actions.checkboxList,
53
- actions_1.actions.blockquote,
54
- actions_1.actions.code,
47
+ actions_1.actions.insertBulletsList,
55
48
  actions_1.actions.indent,
56
49
  actions_1.actions.outdent,
57
- actions_1.actions.justifyLeft,
58
- actions_1.actions.justifyCenter,
59
- actions_1.actions.justifyRight,
60
- actions_1.actions.justifyFull,
61
50
  actions_1.actions.insertLink,
62
51
  ];
63
- // Icons from img folder - direct require now that icons exist
64
52
  function getDefaultIcon() {
65
53
  return {
54
+ [actions_1.actions.insertImage]: require('./img/image.png'),
55
+ [actions_1.actions.keyboard]: require('./img/keyboard.png'),
66
56
  [actions_1.actions.setBold]: require('./img/bold.png'),
67
57
  [actions_1.actions.setItalic]: require('./img/italic.png'),
58
+ [actions_1.actions.setSubscript]: require('./img/subscript.png'),
59
+ [actions_1.actions.setSuperscript]: require('./img/superscript.png'),
60
+ [actions_1.actions.insertBulletsList]: require('./img/ul.png'),
61
+ [actions_1.actions.insertOrderedList]: require('./img/ol.png'),
62
+ [actions_1.actions.insertLink]: require('./img/link.png'),
63
+ [actions_1.actions.setStrikethrough]: require('./img/strikethrough.png'),
68
64
  [actions_1.actions.setUnderline]: require('./img/underline.png'),
69
- [actions_1.actions.strikethrough]: require('./img/strikethrough.png'),
65
+ [actions_1.actions.heading1]: require('./img/heading1.png'),
66
+ [actions_1.actions.insertVideo]: require('./img/video.png'),
70
67
  [actions_1.actions.removeFormat]: require('./img/remove_format.png'),
68
+ [actions_1.actions.undo]: require('./img/undo.png'),
69
+ [actions_1.actions.redo]: require('./img/redo.png'),
71
70
  [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'),
71
+ [actions_1.actions.table]: require('./img/table.png'),
75
72
  [actions_1.actions.code]: require('./img/code.png'),
76
- [actions_1.actions.insertLink]: require('./img/link.png'),
77
- [actions_1.actions.indent]: require('./img/indent.png'),
78
73
  [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'),
85
- [actions_1.actions.keyboard]: require('./img/keyboard.png'),
74
+ [actions_1.actions.indent]: require('./img/indent.png'),
75
+ [actions_1.actions.alignLeft]: require('./img/justify_left.png'),
76
+ [actions_1.actions.alignCenter]: require('./img/justify_center.png'),
77
+ [actions_1.actions.alignRight]: require('./img/justify_right.png'),
78
+ [actions_1.actions.alignFull]: require('./img/justify_full.png'),
79
+ [actions_1.actions.blockquote]: require('./img/blockquote.png'),
80
+ [actions_1.actions.line]: require('./img/line.png'),
81
+ [actions_1.actions.fontSize]: require('./img/fontSize.png'),
86
82
  };
87
83
  }
88
84
  const defaultIcons = getDefaultIcon();
89
- function RichToolbar({ editor, getEditor, actions: actionsProp = exports.defaultActions, disabled = false, iconTint = '#71787F', selectedIconTint, disabledIconTint, iconSize = 20, iconGap = 16, style, itemStyle, selectedButtonStyle, unselectedButtonStyle, disabledButtonStyle, iconMap, renderAction, onPressAddImage, onInsertLink, insertVideo, flatContainerStyle, horizontal = true, children, }) {
85
+ function RichToolbar({ editor: editorProp, getEditor, actions: actionsProp = exports.defaultActions, disabled = false, iconTint = '#71787F', selectedIconTint, disabledIconTint, iconSize = 20, iconGap = 16, style, itemStyle, selectedButtonStyle, unselectedButtonStyle, disabledButtonStyle, iconMap, renderAction, onPressAddImage, onInsertLink, insertVideo, flatContainerStyle, horizontal = true, children, ...restProps }) {
90
86
  const editorRef = (0, react_1.useRef)(null);
91
87
  const [items, setItems] = (0, react_1.useState)([]);
92
- const [data, setData] = (0, react_1.useState)(actionsProp.map(action => ({ action, selected: false })));
93
- const setSelectedItems = (newItems) => {
94
- setItems(prev => (prev === newItems ? prev : newItems));
95
- setData(actionsProp.map(action => ({
96
- action,
97
- selected: newItems.includes(action) || newItems.some(item => item && item === action),
98
- })));
99
- };
88
+ const data = actionsProp.map(action => ({
89
+ action,
90
+ selected: items.includes(action) || items.some(item => item && item === action),
91
+ }));
100
92
  const mount = () => {
101
93
  var _a, _b;
102
- const editorInstance = (_a = editor === null || editor === void 0 ? void 0 : editor.current) !== null && _a !== void 0 ? _a : getEditor === null || getEditor === void 0 ? void 0 : getEditor();
103
- if (!editorInstance) {
104
- if (process.env.NODE_ENV !== 'production') {
105
- console.warn('Toolbar has no editor. Please make sure the prop editor or getEditor returns a ref to the editor component.');
94
+ const editor = (_a = editorProp === null || editorProp === void 0 ? void 0 : editorProp.current) !== null && _a !== void 0 ? _a : getEditor === null || getEditor === void 0 ? void 0 : getEditor();
95
+ if (!editor) {
96
+ if (__DEV__) {
97
+ console.warn('Toolbar has no editor. Please make sure the prop getEditor or editor returns a ref to the editor component.');
106
98
  }
107
99
  }
108
100
  else {
109
- (_b = editorInstance.registerToolbar) === null || _b === void 0 ? void 0 : _b.call(editorInstance, setSelectedItems);
110
- editorRef.current = editorInstance;
101
+ (_b = editor.registerToolbar) === null || _b === void 0 ? void 0 : _b.call(editor, (selectedItems) => setItems(selectedItems));
102
+ editorRef.current = editor;
111
103
  }
112
104
  };
113
105
  (0, react_1.useEffect)(() => {
@@ -121,22 +113,22 @@ function RichToolbar({ editor, getEditor, actions: actionsProp = exports.default
121
113
  };
122
114
  const handleKeyboard = () => {
123
115
  var _a, _b;
124
- const editorInstance = editorRef.current;
125
- if (!editorInstance) {
116
+ const editor = editorRef.current;
117
+ if (!editor) {
126
118
  mount();
127
119
  return;
128
120
  }
129
- if (editorInstance.isKeyboardOpen) {
130
- (_a = editorInstance.dismissKeyboard) === null || _a === void 0 ? void 0 : _a.call(editorInstance);
121
+ if (editor.isKeyboardOpen) {
122
+ (_a = editor.dismissKeyboard) === null || _a === void 0 ? void 0 : _a.call(editor);
131
123
  }
132
124
  else {
133
- (_b = editorInstance.focusContentEditor) === null || _b === void 0 ? void 0 : _b.call(editorInstance);
125
+ (_b = editor.focusContentEditor) === null || _b === void 0 ? void 0 : _b.call(editor);
134
126
  }
135
127
  };
136
128
  const onPress = (action) => {
137
- var _a, _b, _c, _d, _e;
138
- const editorInstance = editorRef.current;
139
- if (!editorInstance) {
129
+ var _a, _b, _c, _d, _e, _f;
130
+ const editor = editorRef.current;
131
+ if (!editor) {
140
132
  mount();
141
133
  return;
142
134
  }
@@ -146,43 +138,52 @@ function RichToolbar({ editor, getEditor, actions: actionsProp = exports.default
146
138
  onInsertLink();
147
139
  return;
148
140
  }
149
- (_a = editorInstance.showAndroidKeyboard) === null || _a === void 0 ? void 0 : _a.call(editorInstance);
150
- (_b = editorInstance.sendAction) === null || _b === void 0 ? void 0 : _b.call(editorInstance, action);
141
+ (_a = editor.showAndroidKeyboard) === null || _a === void 0 ? void 0 : _a.call(editor);
142
+ (_b = editor.sendAction) === null || _b === void 0 ? void 0 : _b.call(editor, action);
143
+ break;
144
+ case actions_1.actions.insertImage:
145
+ onPressAddImage === null || onPressAddImage === void 0 ? void 0 : onPressAddImage();
146
+ break;
147
+ case actions_1.actions.insertVideo:
148
+ insertVideo === null || insertVideo === void 0 ? void 0 : insertVideo();
151
149
  break;
152
150
  case actions_1.actions.keyboard:
153
151
  handleKeyboard();
154
152
  break;
155
153
  case actions_1.actions.setBold:
156
154
  case actions_1.actions.setItalic:
157
- case actions_1.actions.setUnderline:
158
- case actions_1.actions.strikethrough:
159
- case actions_1.actions.removeFormat:
160
- case actions_1.actions.checkboxList:
161
- case actions_1.actions.insertUnorderedList:
155
+ case actions_1.actions.undo:
156
+ case actions_1.actions.redo:
157
+ case actions_1.actions.insertBulletsList:
162
158
  case actions_1.actions.insertOrderedList:
163
- case actions_1.actions.blockquote:
159
+ case actions_1.actions.checkboxList:
160
+ case actions_1.actions.setUnderline:
161
+ case actions_1.actions.heading1:
162
+ case actions_1.actions.heading2:
163
+ case actions_1.actions.heading3:
164
+ case actions_1.actions.heading4:
165
+ case actions_1.actions.heading5:
166
+ case actions_1.actions.heading6:
164
167
  case actions_1.actions.code:
168
+ case actions_1.actions.blockquote:
169
+ case actions_1.actions.line:
170
+ case actions_1.actions.setParagraph:
171
+ case actions_1.actions.removeFormat:
172
+ case actions_1.actions.alignLeft:
173
+ case actions_1.actions.alignCenter:
174
+ case actions_1.actions.alignRight:
175
+ case actions_1.actions.alignFull:
176
+ case actions_1.actions.setSubscript:
177
+ case actions_1.actions.setSuperscript:
178
+ case actions_1.actions.setStrikethrough:
179
+ case actions_1.actions.setHR:
165
180
  case actions_1.actions.indent:
166
181
  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:
173
- (_c = editorInstance.showAndroidKeyboard) === null || _c === void 0 ? void 0 : _c.call(editorInstance);
174
- (_d = editorInstance.sendAction) === null || _d === void 0 ? void 0 : _d.call(editorInstance, action);
182
+ (_c = editor.showAndroidKeyboard) === null || _c === void 0 ? void 0 : _c.call(editor);
183
+ (_d = editor.sendAction) === null || _d === void 0 ? void 0 : _d.call(editor, action);
175
184
  break;
176
185
  default:
177
- if (action === 'image' && onPressAddImage) {
178
- onPressAddImage();
179
- return;
180
- }
181
- if (action === 'video' && insertVideo) {
182
- insertVideo();
183
- return;
184
- }
185
- (_e = editorInstance.sendAction) === null || _e === void 0 ? void 0 : _e.call(editorInstance, action);
186
+ (_f = (_e = restProps)[action]) === null || _f === void 0 ? void 0 : _f.call(_e);
186
187
  break;
187
188
  }
188
189
  };
@@ -198,7 +199,7 @@ function RichToolbar({ editor, getEditor, actions: actionsProp = exports.default
198
199
  tintColor,
199
200
  height: iconSize,
200
201
  width: iconSize,
201
- } }))) : (react_1.default.createElement(react_native_1.View, { style: { padding: 4 } }))));
202
+ } }))) : null));
202
203
  };
203
204
  const renderActionItem = (action, selected) => renderAction ? renderAction(action, selected) : defaultRenderAction(action, selected);
204
205
  const barStyle = [
@@ -221,3 +222,4 @@ const styles = react_native_1.StyleSheet.create({
221
222
  alignItems: 'center',
222
223
  },
223
224
  });
225
+ exports.default = RichToolbar;
package/dist/actions.d.ts CHANGED
@@ -1,23 +1,58 @@
1
1
  export declare const actions: {
2
- readonly setBold: "bold";
3
- readonly setItalic: "italic";
4
- readonly setUnderline: "underline";
5
- readonly strikethrough: "strikethrough";
6
- readonly removeFormat: "removeFormat";
7
- readonly checkboxList: "checkboxList";
8
- readonly insertUnorderedList: "insertUnorderedList";
9
- readonly insertOrderedList: "insertOrderedList";
10
- readonly blockquote: "blockquote";
11
- readonly code: "code";
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";
21
- readonly keyboard: "keyboard";
22
- readonly init: "init";
2
+ content: string;
3
+ updateHeight: string;
4
+ setBold: string;
5
+ setItalic: string;
6
+ setUnderline: string;
7
+ heading1: string;
8
+ heading2: string;
9
+ heading3: string;
10
+ heading4: string;
11
+ heading5: string;
12
+ heading6: string;
13
+ insertLine: string;
14
+ setParagraph: string;
15
+ removeFormat: string;
16
+ alignLeft: string;
17
+ alignCenter: string;
18
+ alignRight: string;
19
+ alignFull: string;
20
+ insertBulletsList: string;
21
+ insertOrderedList: string;
22
+ checkboxList: string;
23
+ insertLink: string;
24
+ insertText: string;
25
+ insertHTML: string;
26
+ insertImage: string;
27
+ insertVideo: string;
28
+ fontSize: string;
29
+ fontName: string;
30
+ setSubscript: string;
31
+ setSuperscript: string;
32
+ setStrikethrough: string;
33
+ setHR: string;
34
+ indent: string;
35
+ outdent: string;
36
+ undo: string;
37
+ redo: string;
38
+ code: string;
39
+ table: string;
40
+ line: string;
41
+ foreColor: string;
42
+ hiliteColor: string;
43
+ blockquote: string;
44
+ keyboard: string;
45
+ setTitlePlaceholder: string;
46
+ setContentPlaceholder: string;
47
+ setTitleFocusHandler: string;
48
+ setContentFocusHandler: string;
49
+ prepareInsert: string;
50
+ restoreSelection: string;
51
+ setCustomCSS: string;
52
+ setTextColor: string;
53
+ setBackgroundColor: string;
54
+ init: string;
55
+ setEditorHeight: string;
56
+ setFooterHeight: string;
57
+ setPlatform: string;
23
58
  };
package/dist/actions.js CHANGED
@@ -2,25 +2,60 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.actions = void 0;
4
4
  exports.actions = {
5
+ content: 'content',
6
+ updateHeight: 'UPDATE_HEIGHT',
5
7
  setBold: 'bold',
6
8
  setItalic: 'italic',
7
9
  setUnderline: 'underline',
8
- strikethrough: 'strikethrough',
10
+ heading1: 'heading1',
11
+ heading2: 'heading2',
12
+ heading3: 'heading3',
13
+ heading4: 'heading4',
14
+ heading5: 'heading5',
15
+ heading6: 'heading6',
16
+ insertLine: 'line',
17
+ setParagraph: 'paragraph',
9
18
  removeFormat: 'removeFormat',
19
+ alignLeft: 'justifyLeft',
20
+ alignCenter: 'justifyCenter',
21
+ alignRight: 'justifyRight',
22
+ alignFull: 'justifyFull',
23
+ insertBulletsList: 'unorderedList',
24
+ insertOrderedList: 'orderedList',
10
25
  checkboxList: 'checkboxList',
11
- insertUnorderedList: 'insertUnorderedList',
12
- insertOrderedList: 'insertOrderedList',
13
- blockquote: 'blockquote',
14
- code: 'code',
15
26
  insertLink: 'link',
27
+ insertText: 'text',
28
+ insertHTML: 'html',
29
+ insertImage: 'image',
30
+ insertVideo: 'video',
31
+ fontSize: 'fontSize',
32
+ fontName: 'fontName',
33
+ setSubscript: 'subscript',
34
+ setSuperscript: 'superscript',
35
+ setStrikethrough: 'strikeThrough',
36
+ setHR: 'horizontalRule',
16
37
  indent: 'indent',
17
38
  outdent: 'outdent',
18
- justifyLeft: 'justifyLeft',
19
- justifyCenter: 'justifyCenter',
20
- justifyRight: 'justifyRight',
21
- justifyFull: 'justifyFull',
22
39
  undo: 'undo',
23
40
  redo: 'redo',
41
+ code: 'code',
42
+ table: 'table',
43
+ line: 'line',
44
+ foreColor: 'foreColor',
45
+ hiliteColor: 'hiliteColor',
46
+ blockquote: 'quote',
24
47
  keyboard: 'keyboard',
48
+ setTitlePlaceholder: 'SET_TITLE_PLACEHOLDER',
49
+ setContentPlaceholder: 'SET_CONTENT_PLACEHOLDER',
50
+ setTitleFocusHandler: 'SET_TITLE_FOCUS_HANDLER',
51
+ setContentFocusHandler: 'SET_CONTENT_FOCUS_HANDLER',
52
+ prepareInsert: 'PREPARE_INSERT',
53
+ restoreSelection: 'RESTORE_SELECTION',
54
+ setCustomCSS: 'SET_CUSTOM_CSS',
55
+ setTextColor: 'SET_TEXT_COLOR',
56
+ setBackgroundColor: 'SET_BACKGROUND_COLOR',
25
57
  init: 'init',
58
+ setEditorHeight: 'SET_EDITOR_HEIGHT',
59
+ setFooterHeight: 'SET_FOOTER_HEIGHT',
60
+ setPlatform: 'SET_PLATFORM',
26
61
  };
@@ -3,23 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContentCSS = getContentCSS;
4
4
  function getContentCSS() {
5
5
  return `
6
- <style>
7
- img, video {
8
- max-width: 100%;
9
- display: block;
10
- margin: 12px auto;
11
- }
12
- blockquote {
13
- border-left: 4px solid #ddd;
14
- padding-left: 12px;
15
- margin: 12px 0;
16
- }
17
- pre {
18
- background: #f4f4f4;
19
- padding: 10px;
20
- border-radius: 6px;
21
- font-family: monospace;
22
- }
23
- </style>
24
- `;
6
+ <style>
7
+ video {max-width: 98%;margin-left:auto;margin-right:auto;display: block;}
8
+ img {max-width: 98%;vertical-align: middle;}
9
+ table {width: 100% !important;}
10
+ table td {width: inherit;}
11
+ table span { font-size: 12px !important; }
12
+ .x-todo li {list-style:none;}
13
+ .x-todo-box {position: relative; left: -24px;}
14
+ .x-todo-box input{position: absolute;}
15
+ blockquote{border-left: 6px solid #ddd;padding: 5px 0 5px 10px;margin: 15px 0 15px 15px;}
16
+ hr{display: block;height: 0; border: 0;border-top: 1px solid #ccc; margin: 15px 0; padding: 0;}
17
+ pre{padding: 10px 5px 10px 10px;margin: 15px 0;display: block;line-height: 18px;background: #F0F0F0;border-radius: 6px;font-size: 13px; font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace; word-break: break-all; word-wrap: break-word;overflow-x: auto;}
18
+ pre code {display: block;font-size: inherit;white-space: pre-wrap;color: inherit;}
19
+ </style>
20
+ `;
25
21
  }
@@ -1,3 +1,3 @@
1
- export declare function createHTML(): {
2
- html: string;
3
- };
1
+ declare function createHTML(options?: {}): string;
2
+ declare const HTML: string;
3
+ export { HTML, createHTML };