rn-rich-text-editor 0.0.6 → 0.0.8
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/dist/RichEditor.d.ts +159 -29
- package/dist/RichEditor.js +311 -269
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/package.json +1 -1
package/dist/RichEditor.d.ts
CHANGED
|
@@ -1,30 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import { WebView } from 'react-native-webview';
|
|
3
|
+
import { TextInput } from 'react-native';
|
|
4
|
+
export interface RichTextEditorProps {
|
|
5
|
+
contentInset?: object;
|
|
6
|
+
style?: object;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
initialContentHTML?: string;
|
|
9
|
+
initialFocus?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
useContainer?: boolean;
|
|
12
|
+
pasteAsPlainText?: boolean;
|
|
13
|
+
autoCapitalize?: string;
|
|
14
|
+
defaultParagraphSeparator?: string;
|
|
15
|
+
editorInitializedCallback?: () => void;
|
|
16
|
+
initialHeight?: number;
|
|
17
|
+
dataDetectorTypes?: string[];
|
|
18
|
+
editorStyle?: {
|
|
19
|
+
backgroundColor?: string;
|
|
20
|
+
color?: string;
|
|
21
|
+
placeholderColor?: string;
|
|
22
|
+
initialCSSText?: string;
|
|
23
|
+
cssText?: string;
|
|
24
|
+
contentCSSText?: string;
|
|
25
|
+
caretColor?: string;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
html?: string | {
|
|
29
|
+
html: string;
|
|
30
|
+
};
|
|
31
|
+
onFocus?: () => void;
|
|
32
|
+
onBlur?: () => void;
|
|
33
|
+
onChange?: (data: string) => void;
|
|
34
|
+
onPaste?: (data: any) => void;
|
|
35
|
+
onKeyUp?: (data: any) => void;
|
|
36
|
+
onKeyDown?: (data: any) => void;
|
|
37
|
+
onInput?: (data: any) => void;
|
|
38
|
+
onMessage?: (message: any) => void;
|
|
39
|
+
onCursorPosition?: (offsetY: number) => void;
|
|
40
|
+
onLink?: (data: any) => void;
|
|
41
|
+
onHeightChange?: (height: number) => void;
|
|
42
|
+
[key: string]: any;
|
|
27
43
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
interface RichTextEditorState {
|
|
45
|
+
html: {
|
|
46
|
+
html: string;
|
|
47
|
+
};
|
|
48
|
+
keyboardHeight: number;
|
|
49
|
+
height: number;
|
|
50
|
+
}
|
|
51
|
+
export default class RichTextEditor extends Component<RichTextEditorProps, RichTextEditorState> {
|
|
52
|
+
readonly props: RichTextEditorProps;
|
|
53
|
+
state: RichTextEditorState;
|
|
54
|
+
setState: Component<RichTextEditorProps, RichTextEditorState>['setState'];
|
|
55
|
+
webviewBridge: WebView | null;
|
|
56
|
+
_input: TextInput | null;
|
|
57
|
+
layout: {
|
|
58
|
+
x?: number;
|
|
59
|
+
y?: number;
|
|
60
|
+
width?: number;
|
|
61
|
+
height?: number;
|
|
62
|
+
};
|
|
63
|
+
unmount: boolean;
|
|
64
|
+
_keyOpen: boolean;
|
|
65
|
+
_focus: boolean;
|
|
66
|
+
selectionChangeListeners: Array<(items: string[]) => void>;
|
|
67
|
+
focusListeners: Array<() => void>;
|
|
68
|
+
contentResolve?: (value: string) => void;
|
|
69
|
+
contentReject?: (reason?: any) => void;
|
|
70
|
+
pendingContentHtml?: ReturnType<typeof setTimeout>;
|
|
71
|
+
keyboardEventListeners: Array<{
|
|
72
|
+
remove: () => void;
|
|
73
|
+
}>;
|
|
74
|
+
static defaultProps: {
|
|
75
|
+
contentInset: {};
|
|
76
|
+
style: {};
|
|
77
|
+
placeholder: string;
|
|
78
|
+
initialContentHTML: string;
|
|
79
|
+
initialFocus: boolean;
|
|
80
|
+
disabled: boolean;
|
|
81
|
+
useContainer: boolean;
|
|
82
|
+
pasteAsPlainText: boolean;
|
|
83
|
+
autoCapitalize: string;
|
|
84
|
+
defaultParagraphSeparator: string;
|
|
85
|
+
editorInitializedCallback: () => void;
|
|
86
|
+
initialHeight: number;
|
|
87
|
+
dataDetectorTypes: string[];
|
|
88
|
+
};
|
|
89
|
+
constructor(props: RichTextEditorProps);
|
|
90
|
+
componentDidMount(): void;
|
|
91
|
+
componentWillUnmount(): void;
|
|
92
|
+
_onKeyboardWillShow(event: any): void;
|
|
93
|
+
_onKeyboardWillHide(event: any): void;
|
|
94
|
+
onMessage(event: any): void;
|
|
95
|
+
setWebHeight(height: any): void;
|
|
96
|
+
/**
|
|
97
|
+
* @param type - Action type (or single toolbar action name when called with 1 arg)
|
|
98
|
+
* @param action - Optional action name (e.g. 'result', 'setHtml')
|
|
99
|
+
* @param data - Optional payload
|
|
100
|
+
* @param options - Optional options
|
|
101
|
+
*/
|
|
102
|
+
sendAction(type: string, action?: string, data?: any, options?: any): void;
|
|
103
|
+
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void;
|
|
104
|
+
setRef(ref: WebView | null): void;
|
|
105
|
+
renderWebView(): any;
|
|
106
|
+
onViewLayout({ nativeEvent: { layout } }: {
|
|
107
|
+
nativeEvent: {
|
|
108
|
+
layout: any;
|
|
109
|
+
};
|
|
110
|
+
}): void;
|
|
111
|
+
render(): any;
|
|
112
|
+
registerToolbar(listener: any): void;
|
|
113
|
+
/**
|
|
114
|
+
* Subsequent versions will be deleted, please use onFocus
|
|
115
|
+
* @deprecated remove
|
|
116
|
+
* @param listener
|
|
117
|
+
*/
|
|
118
|
+
setContentFocusHandler(listener: any): void;
|
|
119
|
+
setContentHTML(html: any): void;
|
|
120
|
+
setPlaceholder(placeholder: any): void;
|
|
121
|
+
setContentStyle(styles: any): void;
|
|
122
|
+
setDisable(dis: any): void;
|
|
123
|
+
blurContentEditor(): void;
|
|
124
|
+
focusContentEditor(): void;
|
|
125
|
+
/**
|
|
126
|
+
* open android keyboard
|
|
127
|
+
* @platform android
|
|
128
|
+
*/
|
|
129
|
+
showAndroidKeyboard(): void;
|
|
130
|
+
/**
|
|
131
|
+
* @param attributes
|
|
132
|
+
* @param [style]
|
|
133
|
+
*/
|
|
134
|
+
insertImage(attributes: any, style: any): void;
|
|
135
|
+
/**
|
|
136
|
+
* @param attributes
|
|
137
|
+
* @param [style]
|
|
138
|
+
*/
|
|
139
|
+
insertVideo(attributes: any, style: any): void;
|
|
140
|
+
insertText(text: any): void;
|
|
141
|
+
insertHTML(html: any): void;
|
|
142
|
+
insertLink(title: any, url: any): void;
|
|
143
|
+
injectJavascript(script: string): void;
|
|
144
|
+
preCode(type: any): void;
|
|
145
|
+
setFontSize(size: any): void;
|
|
146
|
+
setForeColor(color: any): void;
|
|
147
|
+
setHiliteColor(color: any): void;
|
|
148
|
+
setFontName(name: any): void;
|
|
149
|
+
commandDOM(command: any): void;
|
|
150
|
+
command(command: any): void;
|
|
151
|
+
dismissKeyboard(): void;
|
|
152
|
+
get isKeyboardOpen(): boolean;
|
|
153
|
+
init(): void;
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated please use onChange
|
|
156
|
+
* @returns {Promise}
|
|
157
|
+
*/
|
|
158
|
+
getContentHtml(): Promise<unknown>;
|
|
159
|
+
}
|
|
160
|
+
export {};
|
package/dist/RichEditor.js
CHANGED
|
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.RichEditor = exports.RichTextEditor = void 0;
|
|
37
36
|
const react_1 = __importStar(require("react"));
|
|
38
37
|
const react_native_webview_1 = require("react-native-webview");
|
|
39
38
|
const actions_1 = require("./actions");
|
|
@@ -41,126 +40,107 @@ const messages_1 = require("./messages");
|
|
|
41
40
|
const react_native_1 = require("react-native");
|
|
42
41
|
const createHTML_1 = require("./editor/createHTML");
|
|
43
42
|
const PlatformIOS = react_native_1.Platform.OS === 'ios';
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
defaultHttps: rest.defaultHttps,
|
|
102
|
-
})), []);
|
|
103
|
-
const [height, setHeight] = (0, react_1.useState)(initialHeight);
|
|
104
|
-
(0, react_1.useEffect)(() => {
|
|
105
|
-
unmountRef.current = false;
|
|
106
|
-
const keyboardShow = () => {
|
|
107
|
-
keyOpenRef.current = true;
|
|
108
|
-
};
|
|
109
|
-
const keyboardHide = () => {
|
|
110
|
-
keyOpenRef.current = false;
|
|
43
|
+
class RichTextEditor extends react_1.Component {
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.webviewBridge = null;
|
|
47
|
+
this._input = null;
|
|
48
|
+
this.layout = {};
|
|
49
|
+
this.unmount = false;
|
|
50
|
+
this._keyOpen = false;
|
|
51
|
+
this._focus = false;
|
|
52
|
+
this.selectionChangeListeners = [];
|
|
53
|
+
this.focusListeners = [];
|
|
54
|
+
this.keyboardEventListeners = [];
|
|
55
|
+
const that = this;
|
|
56
|
+
that.renderWebView = that.renderWebView.bind(that);
|
|
57
|
+
that.onMessage = that.onMessage.bind(that);
|
|
58
|
+
that.sendAction = that.sendAction.bind(that);
|
|
59
|
+
that.registerToolbar = that.registerToolbar.bind(that);
|
|
60
|
+
that._onKeyboardWillShow = that._onKeyboardWillShow.bind(that);
|
|
61
|
+
that._onKeyboardWillHide = that._onKeyboardWillHide.bind(that);
|
|
62
|
+
that.init = that.init.bind(that);
|
|
63
|
+
that.setRef = that.setRef.bind(that);
|
|
64
|
+
that.onViewLayout = that.onViewLayout.bind(that);
|
|
65
|
+
that.unmount = false;
|
|
66
|
+
that._keyOpen = false;
|
|
67
|
+
that._focus = false;
|
|
68
|
+
that.layout = {};
|
|
69
|
+
that.selectionChangeListeners = [];
|
|
70
|
+
const { editorStyle: { backgroundColor, color, placeholderColor, initialCSSText, cssText, contentCSSText, caretColor, } = {}, html, pasteAsPlainText, onPaste, onKeyUp, onKeyDown, onInput, enterKeyHint, autoCapitalize, autoCorrect, defaultParagraphSeparator, firstFocusEnd, useContainer, initialHeight, initialFocus, disabled, styleWithCSS, useCharacter, defaultHttps, } = props;
|
|
71
|
+
const htmlString = (typeof html === 'string' ? html : (html && typeof html === 'object' && 'html' in html ? html.html : undefined)) ||
|
|
72
|
+
(0, createHTML_1.createHTML)({
|
|
73
|
+
backgroundColor,
|
|
74
|
+
color,
|
|
75
|
+
caretColor,
|
|
76
|
+
placeholderColor,
|
|
77
|
+
initialCSSText,
|
|
78
|
+
cssText,
|
|
79
|
+
contentCSSText,
|
|
80
|
+
pasteAsPlainText,
|
|
81
|
+
pasteListener: !!onPaste,
|
|
82
|
+
keyUpListener: !!onKeyUp,
|
|
83
|
+
keyDownListener: !!onKeyDown,
|
|
84
|
+
inputListener: !!onInput,
|
|
85
|
+
enterKeyHint,
|
|
86
|
+
autoCapitalize,
|
|
87
|
+
autoCorrect,
|
|
88
|
+
initialFocus: initialFocus && !disabled,
|
|
89
|
+
defaultParagraphSeparator,
|
|
90
|
+
firstFocusEnd,
|
|
91
|
+
useContainer,
|
|
92
|
+
styleWithCSS,
|
|
93
|
+
useCharacter,
|
|
94
|
+
defaultHttps,
|
|
95
|
+
});
|
|
96
|
+
that.state = {
|
|
97
|
+
html: { html: htmlString },
|
|
98
|
+
keyboardHeight: 0,
|
|
99
|
+
height: (initialHeight !== null && initialHeight !== void 0 ? initialHeight : 0),
|
|
111
100
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
react_native_1.Keyboard.addListener('
|
|
119
|
-
react_native_1.Keyboard.addListener('
|
|
101
|
+
that.focusListeners = [];
|
|
102
|
+
}
|
|
103
|
+
componentDidMount() {
|
|
104
|
+
this.unmount = false;
|
|
105
|
+
if (PlatformIOS) {
|
|
106
|
+
this.keyboardEventListeners = [
|
|
107
|
+
react_native_1.Keyboard.addListener('keyboardWillShow', this._onKeyboardWillShow),
|
|
108
|
+
react_native_1.Keyboard.addListener('keyboardWillHide', this._onKeyboardWillHide),
|
|
120
109
|
];
|
|
121
|
-
return () => {
|
|
122
|
-
unmountRef.current = true;
|
|
123
|
-
listeners.forEach(l => l.remove());
|
|
124
|
-
};
|
|
125
|
-
}, []);
|
|
126
|
-
(0, react_1.useEffect)(() => {
|
|
127
|
-
if (editorStyle) {
|
|
128
|
-
sendAction(actions_1.actions.content, 'setContentStyle', editorStyle);
|
|
129
|
-
}
|
|
130
|
-
}, [editorStyle]);
|
|
131
|
-
(0, react_1.useEffect)(() => {
|
|
132
|
-
sendAction(actions_1.actions.content, 'setDisable', !!disabled);
|
|
133
|
-
}, [disabled]);
|
|
134
|
-
(0, react_1.useEffect)(() => {
|
|
135
|
-
sendAction(actions_1.actions.content, 'setPlaceholder', placeholder);
|
|
136
|
-
}, [placeholder]);
|
|
137
|
-
function sendAction(type, action, data, options) {
|
|
138
|
-
var _a, _b;
|
|
139
|
-
const jsonString = JSON.stringify({ type, name: action, data, options });
|
|
140
|
-
if (unmountRef.current || !webRef.current)
|
|
141
|
-
return;
|
|
142
|
-
const webRefAny = webRef.current;
|
|
143
|
-
if (typeof webRefAny.postMessage === 'function') {
|
|
144
|
-
webRefAny.postMessage(jsonString);
|
|
145
110
|
}
|
|
146
111
|
else {
|
|
147
|
-
|
|
112
|
+
this.keyboardEventListeners = [
|
|
113
|
+
react_native_1.Keyboard.addListener('keyboardDidShow', this._onKeyboardWillShow),
|
|
114
|
+
react_native_1.Keyboard.addListener('keyboardDidHide', this._onKeyboardWillHide),
|
|
115
|
+
];
|
|
148
116
|
}
|
|
149
117
|
}
|
|
150
|
-
|
|
151
|
-
|
|
118
|
+
componentWillUnmount() {
|
|
119
|
+
this.unmount = true;
|
|
120
|
+
this.keyboardEventListeners.forEach(eventListener => eventListener.remove());
|
|
121
|
+
}
|
|
122
|
+
_onKeyboardWillShow(event) {
|
|
123
|
+
this._keyOpen = true;
|
|
124
|
+
}
|
|
125
|
+
_onKeyboardWillHide(event) {
|
|
126
|
+
this._keyOpen = false;
|
|
127
|
+
}
|
|
128
|
+
onMessage(event) {
|
|
129
|
+
var _a;
|
|
130
|
+
const that = this;
|
|
131
|
+
const { onFocus, onBlur, onChange, onPaste, onKeyUp, onKeyDown, onInput, onMessage, onCursorPosition, onLink } = that.props;
|
|
152
132
|
try {
|
|
153
133
|
const message = JSON.parse(event.nativeEvent.data);
|
|
154
134
|
const data = message.data;
|
|
155
135
|
switch (message.type) {
|
|
156
136
|
case messages_1.messages.CONTENT_HTML_RESPONSE:
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
clearTimeout(
|
|
163
|
-
|
|
137
|
+
if (that.contentResolve) {
|
|
138
|
+
that.contentResolve(message.data);
|
|
139
|
+
that.contentResolve = undefined;
|
|
140
|
+
that.contentReject = undefined;
|
|
141
|
+
if (that.pendingContentHtml) {
|
|
142
|
+
clearTimeout(that.pendingContentHtml);
|
|
143
|
+
that.pendingContentHtml = undefined;
|
|
164
144
|
}
|
|
165
145
|
}
|
|
166
146
|
break;
|
|
@@ -171,15 +151,18 @@ exports.RichTextEditor = (0, react_1.forwardRef)(function RichTextEditor({ conte
|
|
|
171
151
|
console.log('FROM EDIT:', ...data);
|
|
172
152
|
break;
|
|
173
153
|
case messages_1.messages.SELECTION_CHANGE:
|
|
174
|
-
|
|
154
|
+
const items = message.data;
|
|
155
|
+
that.selectionChangeListeners.map(listener => {
|
|
156
|
+
listener(items);
|
|
157
|
+
});
|
|
175
158
|
break;
|
|
176
159
|
case messages_1.messages.CONTENT_FOCUSED:
|
|
177
|
-
|
|
178
|
-
focusListeners.
|
|
160
|
+
that._focus = true;
|
|
161
|
+
that.focusListeners.map(da => da()); // Subsequent versions will be deleted
|
|
179
162
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
180
163
|
break;
|
|
181
164
|
case messages_1.messages.CONTENT_BLUR:
|
|
182
|
-
|
|
165
|
+
that._focus = false;
|
|
183
166
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
184
167
|
break;
|
|
185
168
|
case messages_1.messages.CONTENT_CHANGE:
|
|
@@ -198,179 +181,239 @@ exports.RichTextEditor = (0, react_1.forwardRef)(function RichTextEditor({ conte
|
|
|
198
181
|
onInput === null || onInput === void 0 ? void 0 : onInput(data);
|
|
199
182
|
break;
|
|
200
183
|
case messages_1.messages.OFFSET_HEIGHT:
|
|
201
|
-
|
|
202
|
-
const maxHeight = Math.max(data, initialHeight);
|
|
203
|
-
if (!unmountRef.current && useContainer && maxHeight >= initialHeight) {
|
|
204
|
-
setHeight(maxHeight);
|
|
205
|
-
}
|
|
206
|
-
onHeightChange === null || onHeightChange === void 0 ? void 0 : onHeightChange(data);
|
|
207
|
-
}
|
|
184
|
+
that.setWebHeight(data);
|
|
208
185
|
break;
|
|
209
|
-
case messages_1.messages.OFFSET_Y:
|
|
210
|
-
const offsetY = Number(Number(data) + ((
|
|
186
|
+
case messages_1.messages.OFFSET_Y: {
|
|
187
|
+
const offsetY = Number(Number(data) + ((_a = that.layout.y) !== null && _a !== void 0 ? _a : 0));
|
|
211
188
|
if (offsetY > 0)
|
|
212
189
|
onCursorPosition === null || onCursorPosition === void 0 ? void 0 : onCursorPosition(offsetY);
|
|
213
190
|
break;
|
|
191
|
+
}
|
|
214
192
|
default:
|
|
215
193
|
onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
|
|
216
194
|
break;
|
|
217
195
|
}
|
|
218
196
|
}
|
|
219
|
-
catch (
|
|
220
|
-
//
|
|
197
|
+
catch (_b) {
|
|
198
|
+
//alert('NON JSON MESSAGE');
|
|
221
199
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
sendAction(actions_1.actions.content, 'setDisable', !!disabled);
|
|
230
|
-
editorInitializedCallback();
|
|
231
|
-
if (initialFocus && !disabled) {
|
|
232
|
-
if (react_native_1.Platform.OS === 'android') {
|
|
233
|
-
if (!keyOpenRef.current)
|
|
234
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
235
|
-
(_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
200
|
+
}
|
|
201
|
+
setWebHeight(height) {
|
|
202
|
+
const { onHeightChange, useContainer, initialHeight } = this.props;
|
|
203
|
+
if (height !== this.state.height) {
|
|
204
|
+
const maxHeight = Math.max(height, initialHeight);
|
|
205
|
+
if (!this.unmount && useContainer && maxHeight >= initialHeight) {
|
|
206
|
+
this.setState({ height: maxHeight });
|
|
236
207
|
}
|
|
237
|
-
|
|
208
|
+
onHeightChange && onHeightChange(height);
|
|
238
209
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (!keyOpenRef.current)
|
|
276
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
277
|
-
(_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
insertImage(attributes, styleOpt) {
|
|
281
|
-
sendAction(actions_1.actions.insertImage, 'result', attributes, styleOpt);
|
|
282
|
-
},
|
|
283
|
-
insertVideo(attributes, styleOpt) {
|
|
284
|
-
sendAction(actions_1.actions.insertVideo, 'result', attributes, styleOpt);
|
|
285
|
-
},
|
|
286
|
-
insertText(text) {
|
|
287
|
-
sendAction(actions_1.actions.insertText, 'result', text);
|
|
288
|
-
},
|
|
289
|
-
insertHTML(html) {
|
|
290
|
-
sendAction(actions_1.actions.insertHTML, 'result', html);
|
|
291
|
-
},
|
|
292
|
-
insertLink(title, url) {
|
|
293
|
-
var _a, _b, _c;
|
|
294
|
-
if (url) {
|
|
295
|
-
if (react_native_1.Platform.OS === 'android') {
|
|
296
|
-
if (!keyOpenRef.current)
|
|
297
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
298
|
-
(_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
299
|
-
}
|
|
300
|
-
sendAction(actions_1.actions.insertLink, 'result', { title, url });
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
injectJavascript(script) {
|
|
304
|
-
var _a, _b;
|
|
305
|
-
return (_b = (_a = webRef.current) === null || _a === void 0 ? void 0 : _a.injectJavaScript) === null || _b === void 0 ? void 0 : _b.call(_a, script);
|
|
306
|
-
},
|
|
307
|
-
preCode(type) {
|
|
308
|
-
sendAction(actions_1.actions.code, 'result', type);
|
|
309
|
-
},
|
|
310
|
-
setFontSize(size) {
|
|
311
|
-
sendAction(actions_1.actions.fontSize, 'result', size);
|
|
312
|
-
},
|
|
313
|
-
setForeColor(color) {
|
|
314
|
-
sendAction(actions_1.actions.foreColor, 'result', color);
|
|
315
|
-
},
|
|
316
|
-
setHiliteColor(color) {
|
|
317
|
-
sendAction(actions_1.actions.hiliteColor, 'result', color);
|
|
318
|
-
},
|
|
319
|
-
setFontName(name) {
|
|
320
|
-
sendAction(actions_1.actions.fontName, 'result', name);
|
|
321
|
-
},
|
|
322
|
-
commandDOM(command) {
|
|
323
|
-
if (command)
|
|
324
|
-
sendAction(actions_1.actions.content, 'commandDOM', command);
|
|
325
|
-
},
|
|
326
|
-
command(command) {
|
|
327
|
-
if (command)
|
|
328
|
-
sendAction(actions_1.actions.content, 'command', command);
|
|
329
|
-
},
|
|
330
|
-
dismissKeyboard() {
|
|
331
|
-
if (focusRef.current)
|
|
332
|
-
sendAction(actions_1.actions.content, 'blur');
|
|
333
|
-
else
|
|
334
|
-
react_native_1.Keyboard.dismiss();
|
|
335
|
-
},
|
|
336
|
-
get isKeyboardOpen() {
|
|
337
|
-
return keyOpenRef.current;
|
|
338
|
-
},
|
|
339
|
-
getContentHtml() {
|
|
340
|
-
return new Promise((resolve, reject) => {
|
|
341
|
-
contentResolveRef.current = resolve;
|
|
342
|
-
contentRejectRef.current = reject;
|
|
343
|
-
sendAction(actions_1.actions.content, 'postHtml');
|
|
344
|
-
pendingContentHtmlRef.current = setTimeout(() => {
|
|
345
|
-
if (contentRejectRef.current)
|
|
346
|
-
contentRejectRef.current('timeout');
|
|
347
|
-
}, 5000);
|
|
348
|
-
});
|
|
349
|
-
},
|
|
350
|
-
}));
|
|
351
|
-
const onViewLayout = ({ nativeEvent: { layout } }) => {
|
|
352
|
-
layoutRef.current = layout;
|
|
353
|
-
};
|
|
354
|
-
const renderWebView = () => {
|
|
355
|
-
var _a;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @param type - Action type (or single toolbar action name when called with 1 arg)
|
|
213
|
+
* @param action - Optional action name (e.g. 'result', 'setHtml')
|
|
214
|
+
* @param data - Optional payload
|
|
215
|
+
* @param options - Optional options
|
|
216
|
+
*/
|
|
217
|
+
sendAction(type, action, data, options) {
|
|
218
|
+
// Toolbar calls sendAction(action) with one arg; forward as type + 'result'
|
|
219
|
+
const name = arguments.length === 1 ? 'result' : action;
|
|
220
|
+
const payload = arguments.length === 1 ? undefined : data;
|
|
221
|
+
const opts = arguments.length === 1 ? undefined : options;
|
|
222
|
+
const jsonString = JSON.stringify({ type, name, data: payload, options: opts });
|
|
223
|
+
if (!this.unmount && this.webviewBridge) {
|
|
224
|
+
this.webviewBridge.postMessage(jsonString);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
228
|
+
const { editorStyle, disabled, placeholder } = this.props;
|
|
229
|
+
if (prevProps.editorStyle !== editorStyle) {
|
|
230
|
+
editorStyle && this.setContentStyle(editorStyle);
|
|
231
|
+
}
|
|
232
|
+
if (disabled !== prevProps.disabled) {
|
|
233
|
+
this.setDisable(disabled);
|
|
234
|
+
}
|
|
235
|
+
if (placeholder !== prevProps.placeholder) {
|
|
236
|
+
this.setPlaceholder(placeholder);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
setRef(ref) {
|
|
240
|
+
this.webviewBridge = ref;
|
|
241
|
+
}
|
|
242
|
+
renderWebView() {
|
|
243
|
+
const that = this;
|
|
244
|
+
const { html: _html, editorStyle, useContainer, style, onLink, dataDetectorTypes, ...rest } = that.props;
|
|
245
|
+
const { html: viewHTML } = that.state;
|
|
356
246
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
357
|
-
react_1.default.createElement(react_native_webview_1.WebView, {
|
|
358
|
-
var _a
|
|
247
|
+
react_1.default.createElement(react_native_webview_1.WebView, { useWebKit: true, scrollEnabled: false, hideKeyboardAccessoryView: true, keyboardDisplayRequiresUserAction: false, nestedScrollEnabled: !useContainer, style: [styles.webview, style], ...rest, ref: that.setRef, onMessage: that.onMessage, originWhitelist: ['*'], dataDetectorTypes: dataDetectorTypes, domStorageEnabled: false, bounces: false, javaScriptEnabled: true, source: viewHTML, onLoad: that.init, onShouldStartLoadWithRequest: event => {
|
|
248
|
+
var _a;
|
|
359
249
|
if (event.url !== 'about:blank') {
|
|
360
|
-
(
|
|
361
|
-
|
|
250
|
+
(_a = this.webviewBridge) === null || _a === void 0 ? void 0 : _a.stopLoading();
|
|
251
|
+
react_native_1.Linking === null || react_native_1.Linking === void 0 ? void 0 : react_native_1.Linking.openURL(event.url);
|
|
362
252
|
return false;
|
|
363
253
|
}
|
|
364
254
|
return true;
|
|
365
255
|
} }),
|
|
366
|
-
react_native_1.Platform.OS === 'android' && react_1.default.createElement(react_native_1.TextInput, { ref:
|
|
367
|
-
};
|
|
368
|
-
if (useContainer) {
|
|
369
|
-
return (react_1.default.createElement(react_native_1.View, { style: [style, { height }], onLayout: onViewLayout }, renderWebView()));
|
|
256
|
+
react_native_1.Platform.OS === 'android' && react_1.default.createElement(react_native_1.TextInput, { ref: ref => (that._input = ref), style: styles._input })));
|
|
370
257
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
258
|
+
onViewLayout({ nativeEvent: { layout } }) {
|
|
259
|
+
this.layout = layout;
|
|
260
|
+
}
|
|
261
|
+
render() {
|
|
262
|
+
let { height } = this.state;
|
|
263
|
+
// useContainer is an optional prop with default value of true
|
|
264
|
+
// If set to true, it will use a View wrapper with styles and height.
|
|
265
|
+
// If set to false, it will not use a View wrapper
|
|
266
|
+
const { useContainer, style } = this.props;
|
|
267
|
+
return useContainer ? (react_1.default.createElement(react_native_1.View, { style: [style, { height }], onLayout: this.onViewLayout }, this.renderWebView())) : (this.renderWebView());
|
|
268
|
+
}
|
|
269
|
+
registerToolbar(listener) {
|
|
270
|
+
this.selectionChangeListeners = [...this.selectionChangeListeners, listener];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Subsequent versions will be deleted, please use onFocus
|
|
274
|
+
* @deprecated remove
|
|
275
|
+
* @param listener
|
|
276
|
+
*/
|
|
277
|
+
setContentFocusHandler(listener) {
|
|
278
|
+
this.focusListeners.push(listener);
|
|
279
|
+
}
|
|
280
|
+
setContentHTML(html) {
|
|
281
|
+
this.sendAction(actions_1.actions.content, 'setHtml', html);
|
|
282
|
+
}
|
|
283
|
+
setPlaceholder(placeholder) {
|
|
284
|
+
this.sendAction(actions_1.actions.content, 'setPlaceholder', placeholder);
|
|
285
|
+
}
|
|
286
|
+
setContentStyle(styles) {
|
|
287
|
+
this.sendAction(actions_1.actions.content, 'setContentStyle', styles);
|
|
288
|
+
}
|
|
289
|
+
setDisable(dis) {
|
|
290
|
+
this.sendAction(actions_1.actions.content, 'setDisable', !!dis);
|
|
291
|
+
}
|
|
292
|
+
blurContentEditor() {
|
|
293
|
+
this.sendAction(actions_1.actions.content, 'blur');
|
|
294
|
+
}
|
|
295
|
+
focusContentEditor() {
|
|
296
|
+
this.showAndroidKeyboard();
|
|
297
|
+
this.sendAction(actions_1.actions.content, 'focus');
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* open android keyboard
|
|
301
|
+
* @platform android
|
|
302
|
+
*/
|
|
303
|
+
showAndroidKeyboard() {
|
|
304
|
+
var _a, _b;
|
|
305
|
+
let that = this;
|
|
306
|
+
if (react_native_1.Platform.OS === 'android') {
|
|
307
|
+
!that._keyOpen && that._input.focus();
|
|
308
|
+
(_b = (_a = that.webviewBridge) === null || _a === void 0 ? void 0 : _a.requestFocus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @param attributes
|
|
313
|
+
* @param [style]
|
|
314
|
+
*/
|
|
315
|
+
insertImage(attributes, style) {
|
|
316
|
+
this.sendAction(actions_1.actions.insertImage, 'result', attributes, style);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @param attributes
|
|
320
|
+
* @param [style]
|
|
321
|
+
*/
|
|
322
|
+
insertVideo(attributes, style) {
|
|
323
|
+
this.sendAction(actions_1.actions.insertVideo, 'result', attributes, style);
|
|
324
|
+
}
|
|
325
|
+
insertText(text) {
|
|
326
|
+
this.sendAction(actions_1.actions.insertText, 'result', text);
|
|
327
|
+
}
|
|
328
|
+
insertHTML(html) {
|
|
329
|
+
this.sendAction(actions_1.actions.insertHTML, 'result', html);
|
|
330
|
+
}
|
|
331
|
+
insertLink(title, url) {
|
|
332
|
+
if (url) {
|
|
333
|
+
this.showAndroidKeyboard();
|
|
334
|
+
this.sendAction(actions_1.actions.insertLink, 'result', { title, url });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
injectJavascript(script) {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
return (_b = (_a = this.webviewBridge) === null || _a === void 0 ? void 0 : _a.injectJavaScript) === null || _b === void 0 ? void 0 : _b.call(_a, script);
|
|
340
|
+
}
|
|
341
|
+
preCode(type) {
|
|
342
|
+
this.sendAction(actions_1.actions.code, 'result', type);
|
|
343
|
+
}
|
|
344
|
+
setFontSize(size) {
|
|
345
|
+
this.sendAction(actions_1.actions.fontSize, 'result', size);
|
|
346
|
+
}
|
|
347
|
+
setForeColor(color) {
|
|
348
|
+
this.sendAction(actions_1.actions.foreColor, 'result', color);
|
|
349
|
+
}
|
|
350
|
+
setHiliteColor(color) {
|
|
351
|
+
this.sendAction(actions_1.actions.hiliteColor, 'result', color);
|
|
352
|
+
}
|
|
353
|
+
setFontName(name) {
|
|
354
|
+
this.sendAction(actions_1.actions.fontName, 'result', name);
|
|
355
|
+
}
|
|
356
|
+
commandDOM(command) {
|
|
357
|
+
if (command) {
|
|
358
|
+
this.sendAction(actions_1.actions.content, 'commandDOM', command);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
command(command) {
|
|
362
|
+
if (command) {
|
|
363
|
+
this.sendAction(actions_1.actions.content, 'command', command);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
dismissKeyboard() {
|
|
367
|
+
this._focus ? this.blurContentEditor() : react_native_1.Keyboard.dismiss();
|
|
368
|
+
}
|
|
369
|
+
get isKeyboardOpen() {
|
|
370
|
+
return this._keyOpen;
|
|
371
|
+
}
|
|
372
|
+
init() {
|
|
373
|
+
let that = this;
|
|
374
|
+
const { initialFocus, initialContentHTML, placeholder, editorInitializedCallback, disabled } = that.props;
|
|
375
|
+
initialContentHTML && that.setContentHTML(initialContentHTML);
|
|
376
|
+
placeholder && that.setPlaceholder(placeholder);
|
|
377
|
+
that.setDisable(disabled);
|
|
378
|
+
editorInitializedCallback();
|
|
379
|
+
// initial request focus
|
|
380
|
+
initialFocus && !disabled && that.focusContentEditor();
|
|
381
|
+
// no visible ?
|
|
382
|
+
that.sendAction(actions_1.actions.init);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @deprecated please use onChange
|
|
386
|
+
* @returns {Promise}
|
|
387
|
+
*/
|
|
388
|
+
async getContentHtml() {
|
|
389
|
+
return new Promise((resolve, reject) => {
|
|
390
|
+
this.contentResolve = resolve;
|
|
391
|
+
this.contentReject = reject;
|
|
392
|
+
this.sendAction(actions_1.actions.content, 'postHtml');
|
|
393
|
+
this.pendingContentHtml = setTimeout(() => {
|
|
394
|
+
if (this.contentReject) {
|
|
395
|
+
this.contentReject('timeout');
|
|
396
|
+
}
|
|
397
|
+
}, 5000);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
RichTextEditor.defaultProps = {
|
|
402
|
+
contentInset: {},
|
|
403
|
+
style: {},
|
|
404
|
+
placeholder: '',
|
|
405
|
+
initialContentHTML: '',
|
|
406
|
+
initialFocus: false,
|
|
407
|
+
disabled: false,
|
|
408
|
+
useContainer: true,
|
|
409
|
+
pasteAsPlainText: false,
|
|
410
|
+
autoCapitalize: 'off',
|
|
411
|
+
defaultParagraphSeparator: 'div',
|
|
412
|
+
editorInitializedCallback: () => { },
|
|
413
|
+
initialHeight: 0,
|
|
414
|
+
dataDetectorTypes: ['none'],
|
|
415
|
+
};
|
|
416
|
+
exports.default = RichTextEditor;
|
|
374
417
|
const styles = react_native_1.StyleSheet.create({
|
|
375
418
|
_input: {
|
|
376
419
|
position: 'absolute',
|
|
@@ -384,4 +427,3 @@ const styles = react_native_1.StyleSheet.create({
|
|
|
384
427
|
backgroundColor: 'transparent',
|
|
385
428
|
},
|
|
386
429
|
});
|
|
387
|
-
exports.default = exports.RichTextEditor;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContentCSS = exports.createHTML = exports.actions = exports.defaultActions = exports.RichToolbar = exports.
|
|
6
|
+
exports.getContentCSS = exports.createHTML = exports.actions = exports.defaultActions = exports.RichToolbar = exports.RichTextEditor = void 0;
|
|
4
7
|
var RichEditor_1 = require("./RichEditor");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "RichTextEditor", { enumerable: true, get: function () { return __importDefault(RichEditor_1).default; } });
|
|
6
9
|
var RichToolbar_1 = require("./RichToolbar");
|
|
7
10
|
Object.defineProperty(exports, "RichToolbar", { enumerable: true, get: function () { return RichToolbar_1.RichToolbar; } });
|
|
8
11
|
Object.defineProperty(exports, "defaultActions", { enumerable: true, get: function () { return RichToolbar_1.defaultActions; } });
|