rn-rich-text-editor 0.0.6 → 0.0.7

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.
@@ -24,6 +24,7 @@ export interface RichTextEditorRef {
24
24
  dismissKeyboard: () => void;
25
25
  getContentHtml: () => Promise<string>;
26
26
  isKeyboardOpen: boolean;
27
+ sendAction: (action: string) => void;
27
28
  }
28
29
  export declare const RichTextEditor: any;
29
30
  export default RichTextEditor;
@@ -238,116 +238,122 @@ exports.RichTextEditor = (0, react_1.forwardRef)(function RichTextEditor({ conte
238
238
  }
239
239
  sendAction(actions_1.actions.init);
240
240
  };
241
- (0, react_1.useImperativeHandle)(ref, () => ({
242
- registerToolbar(listener) {
243
- selectionChangeListeners.current = [...selectionChangeListeners.current, listener];
244
- },
245
- setContentFocusHandler(listener) {
246
- focusListeners.current.push(listener);
247
- },
248
- setContentHTML(html) {
249
- sendAction(actions_1.actions.content, 'setHtml', html);
250
- },
251
- setPlaceholder(placeholderText) {
252
- sendAction(actions_1.actions.content, 'setPlaceholder', placeholderText);
253
- },
254
- setContentStyle(styles) {
255
- sendAction(actions_1.actions.content, 'setContentStyle', styles);
256
- },
257
- setDisable(dis) {
258
- sendAction(actions_1.actions.content, 'setDisable', !!dis);
259
- },
260
- blurContentEditor() {
261
- sendAction(actions_1.actions.content, 'blur');
262
- },
263
- focusContentEditor() {
264
- var _a, _b, _c;
265
- if (react_native_1.Platform.OS === 'android') {
266
- if (!keyOpenRef.current)
267
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
268
- (_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
269
- }
270
- sendAction(actions_1.actions.content, 'focus');
271
- },
272
- showAndroidKeyboard() {
273
- var _a, _b, _c;
274
- if (react_native_1.Platform.OS === 'android') {
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) {
241
+ (0, react_1.useImperativeHandle)(ref, () => {
242
+ const postActionToWebView = sendAction;
243
+ return {
244
+ registerToolbar(listener) {
245
+ selectionChangeListeners.current = [...selectionChangeListeners.current, listener];
246
+ },
247
+ setContentFocusHandler(listener) {
248
+ focusListeners.current.push(listener);
249
+ },
250
+ setContentHTML(html) {
251
+ sendAction(actions_1.actions.content, 'setHtml', html);
252
+ },
253
+ setPlaceholder(placeholderText) {
254
+ sendAction(actions_1.actions.content, 'setPlaceholder', placeholderText);
255
+ },
256
+ setContentStyle(styles) {
257
+ sendAction(actions_1.actions.content, 'setContentStyle', styles);
258
+ },
259
+ setDisable(dis) {
260
+ sendAction(actions_1.actions.content, 'setDisable', !!dis);
261
+ },
262
+ blurContentEditor() {
263
+ sendAction(actions_1.actions.content, 'blur');
264
+ },
265
+ focusContentEditor() {
266
+ var _a, _b, _c;
295
267
  if (react_native_1.Platform.OS === 'android') {
296
268
  if (!keyOpenRef.current)
297
269
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
298
270
  (_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
299
271
  }
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
- }));
272
+ sendAction(actions_1.actions.content, 'focus');
273
+ },
274
+ showAndroidKeyboard() {
275
+ var _a, _b, _c;
276
+ if (react_native_1.Platform.OS === 'android') {
277
+ if (!keyOpenRef.current)
278
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
279
+ (_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
280
+ }
281
+ },
282
+ insertImage(attributes, styleOpt) {
283
+ sendAction(actions_1.actions.insertImage, 'result', attributes, styleOpt);
284
+ },
285
+ insertVideo(attributes, styleOpt) {
286
+ sendAction(actions_1.actions.insertVideo, 'result', attributes, styleOpt);
287
+ },
288
+ insertText(text) {
289
+ sendAction(actions_1.actions.insertText, 'result', text);
290
+ },
291
+ insertHTML(html) {
292
+ sendAction(actions_1.actions.insertHTML, 'result', html);
293
+ },
294
+ insertLink(title, url) {
295
+ var _a, _b, _c;
296
+ if (url) {
297
+ if (react_native_1.Platform.OS === 'android') {
298
+ if (!keyOpenRef.current)
299
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
300
+ (_c = (_b = webRef.current) === null || _b === void 0 ? void 0 : _b.requestFocus) === null || _c === void 0 ? void 0 : _c.call(_b);
301
+ }
302
+ sendAction(actions_1.actions.insertLink, 'result', { title, url });
303
+ }
304
+ },
305
+ injectJavascript(script) {
306
+ var _a, _b;
307
+ return (_b = (_a = webRef.current) === null || _a === void 0 ? void 0 : _a.injectJavaScript) === null || _b === void 0 ? void 0 : _b.call(_a, script);
308
+ },
309
+ preCode(type) {
310
+ sendAction(actions_1.actions.code, 'result', type);
311
+ },
312
+ setFontSize(size) {
313
+ sendAction(actions_1.actions.fontSize, 'result', size);
314
+ },
315
+ setForeColor(color) {
316
+ sendAction(actions_1.actions.foreColor, 'result', color);
317
+ },
318
+ setHiliteColor(color) {
319
+ sendAction(actions_1.actions.hiliteColor, 'result', color);
320
+ },
321
+ setFontName(name) {
322
+ sendAction(actions_1.actions.fontName, 'result', name);
323
+ },
324
+ commandDOM(command) {
325
+ if (command)
326
+ sendAction(actions_1.actions.content, 'commandDOM', command);
327
+ },
328
+ command(command) {
329
+ if (command)
330
+ sendAction(actions_1.actions.content, 'command', command);
331
+ },
332
+ dismissKeyboard() {
333
+ if (focusRef.current)
334
+ sendAction(actions_1.actions.content, 'blur');
335
+ else
336
+ react_native_1.Keyboard.dismiss();
337
+ },
338
+ get isKeyboardOpen() {
339
+ return keyOpenRef.current;
340
+ },
341
+ getContentHtml() {
342
+ return new Promise((resolve, reject) => {
343
+ contentResolveRef.current = resolve;
344
+ contentRejectRef.current = reject;
345
+ postActionToWebView(actions_1.actions.content, 'postHtml');
346
+ pendingContentHtmlRef.current = setTimeout(() => {
347
+ if (contentRejectRef.current)
348
+ contentRejectRef.current('timeout');
349
+ }, 5000);
350
+ });
351
+ },
352
+ sendAction(action) {
353
+ postActionToWebView(action, 'result');
354
+ },
355
+ };
356
+ });
351
357
  const onViewLayout = ({ nativeEvent: { layout } }) => {
352
358
  layoutRef.current = layout;
353
359
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-rich-text-editor",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A rich text editor component for React Native",
5
5
  "keywords": [
6
6
  "react-native",