rn-rich-text-editor 0.0.8 → 0.0.10
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.
- package/package.json +13 -9
- package/src/RichEditor.js +501 -0
- package/src/RichToolbar.js +293 -0
- package/src/actions.js +58 -0
- package/{dist → src}/editor/contentCSS.js +5 -5
- package/{dist → src}/editor/createHTML.js +58 -12
- package/src/index.d.ts +152 -0
- package/src/index.js +5 -0
- package/src/messages.js +17 -0
- package/dist/RichEditor.d.ts +0 -160
- package/dist/RichEditor.js +0 -429
- package/dist/RichToolbar.d.ts +0 -33
- package/dist/RichToolbar.js +0 -225
- package/dist/actions.d.ts +0 -58
- package/dist/actions.js +0 -61
- package/dist/editor/contentCSS.d.ts +0 -1
- package/dist/editor/createHTML.d.ts +0 -3
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -17
- package/dist/messages.d.ts +0 -17
- package/dist/messages.js +0 -20
- /package/{dist → src}/img/blockquote.png +0 -0
- /package/{dist → src}/img/blockquote@2x.png +0 -0
- /package/{dist → src}/img/blockquote@3x.png +0 -0
- /package/{dist → src}/img/bold.png +0 -0
- /package/{dist → src}/img/bold@2x.png +0 -0
- /package/{dist → src}/img/bold@3x.png +0 -0
- /package/{dist → src}/img/checkbox.png +0 -0
- /package/{dist → src}/img/checkbox@2x.png +0 -0
- /package/{dist → src}/img/checkbox@3x.png +0 -0
- /package/{dist → src}/img/code.png +0 -0
- /package/{dist → src}/img/code@2x.png +0 -0
- /package/{dist → src}/img/code@3x.png +0 -0
- /package/{dist → src}/img/fontSize.png +0 -0
- /package/{dist → src}/img/fontSize@2x.png +0 -0
- /package/{dist → src}/img/fontSize@3x.png +0 -0
- /package/{dist → src}/img/heading1.png +0 -0
- /package/{dist → src}/img/image.png +0 -0
- /package/{dist → src}/img/image@2x.png +0 -0
- /package/{dist → src}/img/image@3x.png +0 -0
- /package/{dist → src}/img/indent.png +0 -0
- /package/{dist → src}/img/indent@2x.png +0 -0
- /package/{dist → src}/img/indent@3x.png +0 -0
- /package/{dist → src}/img/italic.png +0 -0
- /package/{dist → src}/img/italic@2x.png +0 -0
- /package/{dist → src}/img/italic@3x.png +0 -0
- /package/{dist → src}/img/justify_center.png +0 -0
- /package/{dist → src}/img/justify_center@2x.png +0 -0
- /package/{dist → src}/img/justify_center@3x.png +0 -0
- /package/{dist → src}/img/justify_full.png +0 -0
- /package/{dist → src}/img/justify_full@2x.png +0 -0
- /package/{dist → src}/img/justify_full@3x.png +0 -0
- /package/{dist → src}/img/justify_left.png +0 -0
- /package/{dist → src}/img/justify_left@2x.png +0 -0
- /package/{dist → src}/img/justify_left@3x.png +0 -0
- /package/{dist → src}/img/justify_right.png +0 -0
- /package/{dist → src}/img/justify_right@2x.png +0 -0
- /package/{dist → src}/img/justify_right@3x.png +0 -0
- /package/{dist → src}/img/keyboard.png +0 -0
- /package/{dist → src}/img/keyboard@2x.png +0 -0
- /package/{dist → src}/img/keyboard@3x.png +0 -0
- /package/{dist → src}/img/line.png +0 -0
- /package/{dist → src}/img/line@2x.png +0 -0
- /package/{dist → src}/img/line@3x.png +0 -0
- /package/{dist → src}/img/link.png +0 -0
- /package/{dist → src}/img/link@2x.png +0 -0
- /package/{dist → src}/img/link@3x.png +0 -0
- /package/{dist → src}/img/ol.png +0 -0
- /package/{dist → src}/img/ol@2x.png +0 -0
- /package/{dist → src}/img/ol@3x.png +0 -0
- /package/{dist → src}/img/outdent.png +0 -0
- /package/{dist → src}/img/outdent@2x.png +0 -0
- /package/{dist → src}/img/outdent@3x.png +0 -0
- /package/{dist → src}/img/redo.png +0 -0
- /package/{dist → src}/img/redo@2x.png +0 -0
- /package/{dist → src}/img/redo@3x.png +0 -0
- /package/{dist → src}/img/remove_format.png +0 -0
- /package/{dist → src}/img/remove_format@2x.png +0 -0
- /package/{dist → src}/img/remove_format@3x.png +0 -0
- /package/{dist → src}/img/strikethrough.png +0 -0
- /package/{dist → src}/img/strikethrough@2x.png +0 -0
- /package/{dist → src}/img/strikethrough@3x.png +0 -0
- /package/{dist → src}/img/subscript.png +0 -0
- /package/{dist → src}/img/subscript@2x.png +0 -0
- /package/{dist → src}/img/subscript@3x.png +0 -0
- /package/{dist → src}/img/superscript.png +0 -0
- /package/{dist → src}/img/superscript@2x.png +0 -0
- /package/{dist → src}/img/superscript@3x.png +0 -0
- /package/{dist → src}/img/table.png +0 -0
- /package/{dist → src}/img/table@2x.png +0 -0
- /package/{dist → src}/img/table@3x.png +0 -0
- /package/{dist → src}/img/ul.png +0 -0
- /package/{dist → src}/img/ul@2x.png +0 -0
- /package/{dist → src}/img/ul@3x.png +0 -0
- /package/{dist → src}/img/underline.png +0 -0
- /package/{dist → src}/img/underline@2x.png +0 -0
- /package/{dist → src}/img/underline@3x.png +0 -0
- /package/{dist → src}/img/undo.png +0 -0
- /package/{dist → src}/img/undo@2x.png +0 -0
- /package/{dist → src}/img/undo@3x.png +0 -0
- /package/{dist → src}/img/video.png +0 -0
- /package/{dist → src}/img/video@2x.png +0 -0
- /package/{dist → src}/img/video@3x.png +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-rich-text-editor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "A rich text editor component for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -14,22 +14,26 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/vishaal2002/rn-rich-text-editor.git"
|
|
16
16
|
},
|
|
17
|
-
"main": "
|
|
18
|
-
"types": "
|
|
17
|
+
"main": "src/index.js",
|
|
18
|
+
"types": "src/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./src/index.d.ts",
|
|
22
|
+
"import": "./src/index.js",
|
|
23
|
+
"require": "./src/index.js",
|
|
24
|
+
"default": "./src/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
19
27
|
"files": [
|
|
20
|
-
"
|
|
28
|
+
"src",
|
|
21
29
|
"package.json"
|
|
22
30
|
],
|
|
23
31
|
"scripts": {
|
|
24
|
-
"build": "
|
|
25
|
-
"watch": "tsc -w"
|
|
32
|
+
"build": "echo 'No build required — package uses src/ directly'"
|
|
26
33
|
},
|
|
27
34
|
"peerDependencies": {
|
|
28
35
|
"react": "*",
|
|
29
36
|
"react-native": "*",
|
|
30
37
|
"react-native-webview": "*"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"typescript": "^5.9.3"
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { WebView } from 'react-native-webview';
|
|
3
|
+
import { actions } from './actions';
|
|
4
|
+
import { messages } from './messages';
|
|
5
|
+
import { Keyboard, Platform, StyleSheet, TextInput, View, Linking } from 'react-native';
|
|
6
|
+
import { createHTML } from './editor/createHTML';
|
|
7
|
+
|
|
8
|
+
const PlatformIOS = Platform.OS === 'ios';
|
|
9
|
+
|
|
10
|
+
export default class RichTextEditor extends Component {
|
|
11
|
+
static defaultProps = {
|
|
12
|
+
contentInset: {},
|
|
13
|
+
style: {},
|
|
14
|
+
placeholder: '',
|
|
15
|
+
initialContentHTML: '',
|
|
16
|
+
initialFocus: false,
|
|
17
|
+
disabled: false,
|
|
18
|
+
useContainer: true,
|
|
19
|
+
pasteAsPlainText: false,
|
|
20
|
+
autoCapitalize: 'off',
|
|
21
|
+
defaultParagraphSeparator: 'div',
|
|
22
|
+
editorInitializedCallback: () => {},
|
|
23
|
+
initialHeight: 0,
|
|
24
|
+
dataDetectorTypes: ['none'],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
constructor(props) {
|
|
28
|
+
super(props);
|
|
29
|
+
let that = this;
|
|
30
|
+
that.renderWebView = that.renderWebView.bind(that);
|
|
31
|
+
that.onMessage = that.onMessage.bind(that);
|
|
32
|
+
that.sendAction = that.sendAction.bind(that);
|
|
33
|
+
that.registerToolbar = that.registerToolbar.bind(that);
|
|
34
|
+
that._onKeyboardWillShow = that._onKeyboardWillShow.bind(that);
|
|
35
|
+
that._onKeyboardWillHide = that._onKeyboardWillHide.bind(that);
|
|
36
|
+
that.init = that.init.bind(that);
|
|
37
|
+
that.setRef = that.setRef.bind(that);
|
|
38
|
+
that.onViewLayout = that.onViewLayout.bind(that);
|
|
39
|
+
that.unmount = false;
|
|
40
|
+
that._keyOpen = false;
|
|
41
|
+
that._focus = false;
|
|
42
|
+
that.layout = {};
|
|
43
|
+
that.selectionChangeListeners = [];
|
|
44
|
+
const {
|
|
45
|
+
editorStyle: {
|
|
46
|
+
backgroundColor,
|
|
47
|
+
color,
|
|
48
|
+
placeholderColor,
|
|
49
|
+
initialCSSText,
|
|
50
|
+
cssText,
|
|
51
|
+
contentCSSText,
|
|
52
|
+
caretColor,
|
|
53
|
+
} = {},
|
|
54
|
+
html,
|
|
55
|
+
pasteAsPlainText,
|
|
56
|
+
onPaste,
|
|
57
|
+
onKeyUp,
|
|
58
|
+
onKeyDown,
|
|
59
|
+
onInput,
|
|
60
|
+
enterKeyHint,
|
|
61
|
+
autoCapitalize,
|
|
62
|
+
autoCorrect,
|
|
63
|
+
defaultParagraphSeparator,
|
|
64
|
+
firstFocusEnd,
|
|
65
|
+
useContainer,
|
|
66
|
+
initialHeight,
|
|
67
|
+
initialFocus,
|
|
68
|
+
disabled,
|
|
69
|
+
styleWithCSS,
|
|
70
|
+
useCharacter,
|
|
71
|
+
defaultHttps,
|
|
72
|
+
} = props;
|
|
73
|
+
that.state = {
|
|
74
|
+
html: {
|
|
75
|
+
html:
|
|
76
|
+
html ||
|
|
77
|
+
createHTML({
|
|
78
|
+
backgroundColor,
|
|
79
|
+
color,
|
|
80
|
+
caretColor,
|
|
81
|
+
placeholderColor,
|
|
82
|
+
initialCSSText,
|
|
83
|
+
cssText,
|
|
84
|
+
contentCSSText,
|
|
85
|
+
pasteAsPlainText,
|
|
86
|
+
pasteListener: !!onPaste,
|
|
87
|
+
keyUpListener: !!onKeyUp,
|
|
88
|
+
keyDownListener: !!onKeyDown,
|
|
89
|
+
inputListener: !!onInput,
|
|
90
|
+
enterKeyHint,
|
|
91
|
+
autoCapitalize,
|
|
92
|
+
autoCorrect,
|
|
93
|
+
initialFocus: initialFocus && !disabled,
|
|
94
|
+
defaultParagraphSeparator,
|
|
95
|
+
firstFocusEnd,
|
|
96
|
+
useContainer,
|
|
97
|
+
styleWithCSS,
|
|
98
|
+
useCharacter,
|
|
99
|
+
defaultHttps,
|
|
100
|
+
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
keyboardHeight: 0,
|
|
104
|
+
height: initialHeight,
|
|
105
|
+
};
|
|
106
|
+
that.focusListeners = [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
componentDidMount() {
|
|
110
|
+
this.unmount = false;
|
|
111
|
+
if (PlatformIOS) {
|
|
112
|
+
this.keyboardEventListeners = [
|
|
113
|
+
Keyboard.addListener('keyboardWillShow', this._onKeyboardWillShow),
|
|
114
|
+
Keyboard.addListener('keyboardWillHide', this._onKeyboardWillHide),
|
|
115
|
+
];
|
|
116
|
+
} else {
|
|
117
|
+
this.keyboardEventListeners = [
|
|
118
|
+
Keyboard.addListener('keyboardDidShow', this._onKeyboardWillShow),
|
|
119
|
+
Keyboard.addListener('keyboardDidHide', this._onKeyboardWillHide),
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
componentWillUnmount() {
|
|
125
|
+
this.unmount = true;
|
|
126
|
+
this.keyboardEventListeners.forEach(eventListener => eventListener.remove());
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_onKeyboardWillShow(event) {
|
|
130
|
+
this._keyOpen = true;
|
|
131
|
+
// console.log('!!!!', event);
|
|
132
|
+
/*const newKeyboardHeight = event.endCoordinates.height;
|
|
133
|
+
if (this.state.keyboardHeight === newKeyboardHeight) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (newKeyboardHeight) {
|
|
137
|
+
this.setEditorAvailableHeightBasedOnKeyboardHeight(newKeyboardHeight);
|
|
138
|
+
}
|
|
139
|
+
this.setState({keyboardHeight: newKeyboardHeight});*/
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
_onKeyboardWillHide(event) {
|
|
143
|
+
this._keyOpen = false;
|
|
144
|
+
// this.setState({keyboardHeight: 0});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*setEditorAvailableHeightBasedOnKeyboardHeight(keyboardHeight) {
|
|
148
|
+
const {top = 0, bottom = 0} = this.props.contentInset;
|
|
149
|
+
const {marginTop = 0, marginBottom = 0} = this.props.style;
|
|
150
|
+
const spacing = marginTop + marginBottom + top + bottom;
|
|
151
|
+
|
|
152
|
+
const editorAvailableHeight = Dimensions.get('window').height - keyboardHeight - spacing;
|
|
153
|
+
// this.setEditorHeight(editorAvailableHeight);
|
|
154
|
+
}*/
|
|
155
|
+
|
|
156
|
+
onMessage(event) {
|
|
157
|
+
const that = this;
|
|
158
|
+
const { onFocus, onBlur, onChange, onPaste, onKeyUp, onKeyDown, onInput, onMessage, onCursorPosition, onLink } =
|
|
159
|
+
that.props;
|
|
160
|
+
try {
|
|
161
|
+
const message = JSON.parse(event.nativeEvent.data);
|
|
162
|
+
const data = message.data;
|
|
163
|
+
switch (message.type) {
|
|
164
|
+
case messages.CONTENT_HTML_RESPONSE:
|
|
165
|
+
if (that.contentResolve) {
|
|
166
|
+
that.contentResolve(message.data);
|
|
167
|
+
that.contentResolve = undefined;
|
|
168
|
+
that.contentReject = undefined;
|
|
169
|
+
if (that.pendingContentHtml) {
|
|
170
|
+
clearTimeout(that.pendingContentHtml);
|
|
171
|
+
that.pendingContentHtml = undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
case messages.LINK_TOUCHED:
|
|
176
|
+
onLink?.(data);
|
|
177
|
+
break;
|
|
178
|
+
case messages.LOG:
|
|
179
|
+
console.log('FROM EDIT:', ...data);
|
|
180
|
+
break;
|
|
181
|
+
case messages.SELECTION_CHANGE:
|
|
182
|
+
const items = message.data;
|
|
183
|
+
that.selectionChangeListeners.map(listener => {
|
|
184
|
+
listener(items);
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
case messages.CONTENT_FOCUSED:
|
|
188
|
+
that._focus = true;
|
|
189
|
+
that.focusListeners.map(da => da()); // Subsequent versions will be deleted
|
|
190
|
+
onFocus?.();
|
|
191
|
+
break;
|
|
192
|
+
case messages.CONTENT_BLUR:
|
|
193
|
+
that._focus = false;
|
|
194
|
+
onBlur?.();
|
|
195
|
+
break;
|
|
196
|
+
case messages.CONTENT_CHANGE:
|
|
197
|
+
onChange?.(data);
|
|
198
|
+
break;
|
|
199
|
+
case messages.CONTENT_PASTED:
|
|
200
|
+
onPaste?.(data);
|
|
201
|
+
break;
|
|
202
|
+
case messages.CONTENT_KEYUP:
|
|
203
|
+
onKeyUp?.(data);
|
|
204
|
+
break;
|
|
205
|
+
case messages.CONTENT_KEYDOWN:
|
|
206
|
+
onKeyDown?.(data);
|
|
207
|
+
break;
|
|
208
|
+
case messages.ON_INPUT:
|
|
209
|
+
onInput?.(data);
|
|
210
|
+
break;
|
|
211
|
+
case messages.OFFSET_HEIGHT:
|
|
212
|
+
that.setWebHeight(data);
|
|
213
|
+
break;
|
|
214
|
+
case messages.OFFSET_Y:
|
|
215
|
+
let offsetY = Number.parseInt(Number.parseInt(data) + that.layout.y || 0);
|
|
216
|
+
offsetY > 0 && onCursorPosition(offsetY);
|
|
217
|
+
break;
|
|
218
|
+
default:
|
|
219
|
+
onMessage?.(message);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
//alert('NON JSON MESSAGE');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
setWebHeight(height) {
|
|
228
|
+
const { onHeightChange, useContainer, initialHeight } = this.props;
|
|
229
|
+
if (height !== this.state.height) {
|
|
230
|
+
const maxHeight = Math.max(height, initialHeight);
|
|
231
|
+
if (!this.unmount && useContainer && maxHeight >= initialHeight) {
|
|
232
|
+
this.setState({ height: maxHeight });
|
|
233
|
+
}
|
|
234
|
+
onHeightChange && onHeightChange(height);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @param {String} type
|
|
240
|
+
* @param {String} action
|
|
241
|
+
* @param {any} data
|
|
242
|
+
* @param [options]
|
|
243
|
+
* @private
|
|
244
|
+
*/
|
|
245
|
+
sendAction(type, action, data, options) {
|
|
246
|
+
let jsonString = JSON.stringify({ type, name: action, data, options });
|
|
247
|
+
if (!this.unmount && this.webviewBridge) {
|
|
248
|
+
this.webviewBridge.postMessage(jsonString);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
253
|
+
const { editorStyle, disabled, placeholder } = this.props;
|
|
254
|
+
if (prevProps.editorStyle !== editorStyle) {
|
|
255
|
+
editorStyle && this.setContentStyle(editorStyle);
|
|
256
|
+
}
|
|
257
|
+
if (disabled !== prevProps.disabled) {
|
|
258
|
+
this.setDisable(disabled);
|
|
259
|
+
}
|
|
260
|
+
if (placeholder !== prevProps.placeholder) {
|
|
261
|
+
this.setPlaceholder(placeholder);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
setRef(ref) {
|
|
266
|
+
this.webviewBridge = ref;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
renderWebView() {
|
|
270
|
+
let that = this;
|
|
271
|
+
const { html, editorStyle, useContainer, style, onLink, dataDetectorTypes, ...rest } = that.props;
|
|
272
|
+
const { html: viewHTML } = that.state;
|
|
273
|
+
return (
|
|
274
|
+
<>
|
|
275
|
+
<WebView
|
|
276
|
+
useWebKit={true}
|
|
277
|
+
scrollEnabled={false}
|
|
278
|
+
hideKeyboardAccessoryView={true}
|
|
279
|
+
keyboardDisplayRequiresUserAction={false}
|
|
280
|
+
nestedScrollEnabled={!useContainer}
|
|
281
|
+
style={[styles.webview, style]}
|
|
282
|
+
{...rest}
|
|
283
|
+
ref={that.setRef}
|
|
284
|
+
onMessage={that.onMessage}
|
|
285
|
+
originWhitelist={['*']}
|
|
286
|
+
dataDetectorTypes={dataDetectorTypes}
|
|
287
|
+
domStorageEnabled={false}
|
|
288
|
+
bounces={false}
|
|
289
|
+
javaScriptEnabled={true}
|
|
290
|
+
source={viewHTML}
|
|
291
|
+
onLoad={that.init}
|
|
292
|
+
onShouldStartLoadWithRequest={event => {
|
|
293
|
+
if (event.url !== 'about:blank') {
|
|
294
|
+
this.webviewBridge?.stopLoading();
|
|
295
|
+
Linking?.openURL(event.url);
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}}
|
|
300
|
+
/>
|
|
301
|
+
{Platform.OS === 'android' && <TextInput ref={ref => (that._input = ref)} style={styles._input} />}
|
|
302
|
+
</>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
onViewLayout({ nativeEvent: { layout } }) {
|
|
307
|
+
// const {x, y, width, height} = layout;
|
|
308
|
+
this.layout = layout;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
render() {
|
|
312
|
+
let { height } = this.state;
|
|
313
|
+
|
|
314
|
+
// useContainer is an optional prop with default value of true
|
|
315
|
+
// If set to true, it will use a View wrapper with styles and height.
|
|
316
|
+
// If set to false, it will not use a View wrapper
|
|
317
|
+
const { useContainer, style } = this.props;
|
|
318
|
+
return useContainer ? (
|
|
319
|
+
<View style={[style, { height }]} onLayout={this.onViewLayout}>
|
|
320
|
+
{this.renderWebView()}
|
|
321
|
+
</View>
|
|
322
|
+
) : (
|
|
323
|
+
this.renderWebView()
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
//-------------------------------------------------------------------------------
|
|
328
|
+
//--------------- Public API
|
|
329
|
+
|
|
330
|
+
registerToolbar(listener) {
|
|
331
|
+
this.selectionChangeListeners = [...this.selectionChangeListeners, listener];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Subsequent versions will be deleted, please use onFocus
|
|
336
|
+
* @deprecated remove
|
|
337
|
+
* @param listener
|
|
338
|
+
*/
|
|
339
|
+
setContentFocusHandler(listener) {
|
|
340
|
+
this.focusListeners.push(listener);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
setContentHTML(html) {
|
|
344
|
+
this.sendAction(actions.content, 'setHtml', html);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
setPlaceholder(placeholder) {
|
|
348
|
+
this.sendAction(actions.content, 'setPlaceholder', placeholder);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
setContentStyle(styles) {
|
|
352
|
+
this.sendAction(actions.content, 'setContentStyle', styles);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
setDisable(dis) {
|
|
356
|
+
this.sendAction(actions.content, 'setDisable', !!dis);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
blurContentEditor() {
|
|
360
|
+
this.sendAction(actions.content, 'blur');
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
focusContentEditor() {
|
|
364
|
+
this.showAndroidKeyboard();
|
|
365
|
+
this.sendAction(actions.content, 'focus');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* open android keyboard
|
|
370
|
+
* @platform android
|
|
371
|
+
*/
|
|
372
|
+
showAndroidKeyboard() {
|
|
373
|
+
let that = this;
|
|
374
|
+
if (Platform.OS === 'android') {
|
|
375
|
+
!that._keyOpen && that._input.focus();
|
|
376
|
+
that.webviewBridge?.requestFocus?.();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @param attributes
|
|
382
|
+
* @param [style]
|
|
383
|
+
*/
|
|
384
|
+
insertImage(attributes, style) {
|
|
385
|
+
this.sendAction(actions.insertImage, 'result', attributes, style);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @param attributes
|
|
390
|
+
* @param [style]
|
|
391
|
+
*/
|
|
392
|
+
insertVideo(attributes, style) {
|
|
393
|
+
this.sendAction(actions.insertVideo, 'result', attributes, style);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
insertText(text) {
|
|
397
|
+
this.sendAction(actions.insertText, 'result', text);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
insertHTML(html) {
|
|
401
|
+
this.sendAction(actions.insertHTML, 'result', html);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
insertLink(title, url) {
|
|
405
|
+
if (url) {
|
|
406
|
+
this.showAndroidKeyboard();
|
|
407
|
+
this.sendAction(actions.insertLink, 'result', { title, url });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
injectJavascript(script) {
|
|
412
|
+
return this.webviewBridge.injectJavaScript(script);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
preCode(type) {
|
|
416
|
+
this.sendAction(actions.code, 'result', type);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
setFontSize(size) {
|
|
420
|
+
this.sendAction(actions.fontSize, 'result', size);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
setForeColor(color) {
|
|
424
|
+
this.sendAction(actions.foreColor, 'result', color);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
setHiliteColor(color) {
|
|
428
|
+
this.sendAction(actions.hiliteColor, 'result', color);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
setFontName(name) {
|
|
432
|
+
this.sendAction(actions.fontName, 'result', name);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
commandDOM(command) {
|
|
436
|
+
if (command) {
|
|
437
|
+
this.sendAction(actions.content, 'commandDOM', command);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
command(command) {
|
|
442
|
+
if (command) {
|
|
443
|
+
this.sendAction(actions.content, 'command', command);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
dismissKeyboard() {
|
|
448
|
+
this._focus ? this.blurContentEditor() : Keyboard.dismiss();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
get isKeyboardOpen() {
|
|
452
|
+
return this._keyOpen;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
init() {
|
|
456
|
+
let that = this;
|
|
457
|
+
const { initialFocus, initialContentHTML, placeholder, editorInitializedCallback, disabled } = that.props;
|
|
458
|
+
initialContentHTML && that.setContentHTML(initialContentHTML);
|
|
459
|
+
placeholder && that.setPlaceholder(placeholder);
|
|
460
|
+
that.setDisable(disabled);
|
|
461
|
+
editorInitializedCallback();
|
|
462
|
+
|
|
463
|
+
// initial request focus
|
|
464
|
+
initialFocus && !disabled && that.focusContentEditor();
|
|
465
|
+
// no visible ?
|
|
466
|
+
that.sendAction(actions.init);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* @deprecated please use onChange
|
|
471
|
+
* @returns {Promise}
|
|
472
|
+
*/
|
|
473
|
+
async getContentHtml() {
|
|
474
|
+
return new Promise((resolve, reject) => {
|
|
475
|
+
this.contentResolve = resolve;
|
|
476
|
+
this.contentReject = reject;
|
|
477
|
+
this.sendAction(actions.content, 'postHtml');
|
|
478
|
+
|
|
479
|
+
this.pendingContentHtml = setTimeout(() => {
|
|
480
|
+
if (this.contentReject) {
|
|
481
|
+
this.contentReject('timeout');
|
|
482
|
+
}
|
|
483
|
+
}, 5000);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const styles = StyleSheet.create({
|
|
489
|
+
_input: {
|
|
490
|
+
position: 'absolute',
|
|
491
|
+
width: 1,
|
|
492
|
+
height: 1,
|
|
493
|
+
zIndex: -999,
|
|
494
|
+
bottom: -999,
|
|
495
|
+
left: -999,
|
|
496
|
+
},
|
|
497
|
+
|
|
498
|
+
webview: {
|
|
499
|
+
backgroundColor: 'transparent',
|
|
500
|
+
},
|
|
501
|
+
});
|