react-native-enriched 0.1.6 → 0.2.1

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.
Files changed (123) hide show
  1. package/README.md +4 -14
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +4 -1
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +2 -1
  4. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  5. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  6. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +0 -45
  7. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +111 -2
  8. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +9 -3
  9. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +2 -0
  10. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
  11. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
  12. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
  13. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
  14. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +42 -1
  15. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
  16. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
  17. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
  18. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +135 -9
  19. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
  20. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
  21. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
  22. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
  23. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
  24. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +13 -3
  25. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
  26. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
  27. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
  28. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
  29. package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +13 -0
  30. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +80 -9
  31. package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +1 -0
  32. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +188 -5
  33. package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +57 -30
  34. package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +91 -0
  35. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +24 -13
  36. package/android/src/main/java/com/swmansion/enriched/utils/ResourceManager.kt +26 -0
  37. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +3 -0
  38. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  39. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  40. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  41. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  42. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  43. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  44. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  45. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  46. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  47. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +12 -13
  48. package/android/src/main/res/drawable/broken_image.xml +10 -0
  49. package/ios/EnrichedTextInputView.h +27 -12
  50. package/ios/EnrichedTextInputView.mm +906 -547
  51. package/ios/attachments/ImageAttachment.h +10 -0
  52. package/ios/attachments/ImageAttachment.mm +34 -0
  53. package/ios/attachments/MediaAttachment.h +23 -0
  54. package/ios/attachments/MediaAttachment.mm +31 -0
  55. package/ios/config/InputConfig.h +12 -6
  56. package/ios/config/InputConfig.mm +71 -33
  57. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  58. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  59. package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +0 -45
  60. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +41 -4
  61. package/ios/inputParser/InputParser.h +5 -5
  62. package/ios/inputParser/InputParser.mm +867 -333
  63. package/ios/inputTextView/InputTextView.h +1 -1
  64. package/ios/inputTextView/InputTextView.mm +100 -59
  65. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  66. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -24
  67. package/ios/internals/EnrichedTextInputViewShadowNode.mm +64 -47
  68. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  69. package/ios/styles/BlockQuoteStyle.mm +192 -142
  70. package/ios/styles/BoldStyle.mm +96 -62
  71. package/ios/styles/CodeBlockStyle.mm +304 -0
  72. package/ios/styles/H1Style.mm +10 -3
  73. package/ios/styles/H2Style.mm +10 -3
  74. package/ios/styles/H3Style.mm +10 -3
  75. package/ios/styles/HeadingStyleBase.mm +129 -84
  76. package/ios/styles/ImageStyle.mm +160 -0
  77. package/ios/styles/InlineCodeStyle.mm +149 -84
  78. package/ios/styles/ItalicStyle.mm +77 -51
  79. package/ios/styles/LinkStyle.mm +353 -224
  80. package/ios/styles/MentionStyle.mm +434 -220
  81. package/ios/styles/OrderedListStyle.mm +172 -105
  82. package/ios/styles/StrikethroughStyle.mm +53 -34
  83. package/ios/styles/UnderlineStyle.mm +69 -45
  84. package/ios/styles/UnorderedListStyle.mm +170 -105
  85. package/ios/utils/BaseStyleProtocol.h +3 -2
  86. package/ios/utils/ColorExtension.mm +7 -5
  87. package/ios/utils/FontExtension.mm +42 -27
  88. package/ios/utils/ImageData.h +10 -0
  89. package/ios/utils/ImageData.mm +4 -0
  90. package/ios/utils/LayoutManagerExtension.h +1 -1
  91. package/ios/utils/LayoutManagerExtension.mm +334 -109
  92. package/ios/utils/MentionParams.h +0 -1
  93. package/ios/utils/MentionStyleProps.h +1 -1
  94. package/ios/utils/MentionStyleProps.mm +27 -20
  95. package/ios/utils/OccurenceUtils.h +42 -38
  96. package/ios/utils/OccurenceUtils.mm +177 -107
  97. package/ios/utils/ParagraphAttributesUtils.h +6 -1
  98. package/ios/utils/ParagraphAttributesUtils.mm +152 -41
  99. package/ios/utils/ParagraphsUtils.h +2 -1
  100. package/ios/utils/ParagraphsUtils.mm +40 -26
  101. package/ios/utils/StringExtension.h +1 -1
  102. package/ios/utils/StringExtension.mm +19 -16
  103. package/ios/utils/StyleHeaders.h +35 -11
  104. package/ios/utils/TextInsertionUtils.h +13 -2
  105. package/ios/utils/TextInsertionUtils.mm +38 -20
  106. package/ios/utils/WordsUtils.h +2 -1
  107. package/ios/utils/WordsUtils.mm +32 -22
  108. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  109. package/ios/utils/ZeroWidthSpaceUtils.mm +153 -75
  110. package/lib/module/EnrichedTextInput.js +41 -3
  111. package/lib/module/EnrichedTextInput.js.map +1 -1
  112. package/lib/module/EnrichedTextInputNativeComponent.ts +17 -5
  113. package/lib/module/normalizeHtmlStyle.js +0 -4
  114. package/lib/module/normalizeHtmlStyle.js.map +1 -1
  115. package/lib/typescript/src/EnrichedTextInput.d.ts +2 -5
  116. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  117. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +7 -5
  118. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  119. package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +1 -1
  120. package/package.json +8 -1
  121. package/src/EnrichedTextInput.tsx +48 -7
  122. package/src/EnrichedTextInputNativeComponent.ts +17 -5
  123. package/src/normalizeHtmlStyle.ts +0 -4
@@ -2,8 +2,9 @@
2
2
 
3
3
  @implementation WordsUtils
4
4
 
5
- + (NSArray<NSDictionary *> *)getAffectedWordsFromText:(NSString *)text modificationRange:(NSRange)range {
6
- if(text.length == 0) {
5
+ + (NSArray<NSDictionary *> *)getAffectedWordsFromText:(NSString *)text
6
+ modificationRange:(NSRange)range {
7
+ if (text.length == 0) {
7
8
  return [[NSArray alloc] init];
8
9
  }
9
10
 
@@ -12,7 +13,8 @@
12
13
  if (leftIt > 0) {
13
14
  while (leftIt >= 0) {
14
15
  unichar charAtIndex = [text characterAtIndex:leftIt];
15
- if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:charAtIndex]) {
16
+ if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
17
+ characterIsMember:charAtIndex]) {
16
18
  leftIt += 1;
17
19
  break;
18
20
  }
@@ -21,12 +23,13 @@
21
23
  }
22
24
  leftIt = MAX(0, leftIt);
23
25
  leftIt = MIN(NSInteger(text.length - 1), leftIt);
24
-
26
+
25
27
  NSInteger rightIt = range.location + range.length;
26
28
  if (rightIt < text.length - 1) {
27
29
  while (rightIt <= text.length - 1) {
28
30
  unichar charAtIndex = [text characterAtIndex:rightIt];
29
- if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:charAtIndex]) {
31
+ if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
32
+ characterIsMember:charAtIndex]) {
30
33
  rightIt -= 1;
31
34
  break;
32
35
  }
@@ -34,23 +37,26 @@
34
37
  }
35
38
  }
36
39
  rightIt = MIN(NSInteger(text.length - 1), rightIt);
37
-
38
- if(leftIt > rightIt) {
40
+
41
+ if (leftIt > rightIt) {
39
42
  return [[NSArray alloc] init];
40
43
  }
41
-
42
- NSMutableArray<NSDictionary *> *separatedWords = [[NSMutableArray<NSDictionary *> alloc] init];
44
+
45
+ NSMutableArray<NSDictionary *> *separatedWords =
46
+ [[NSMutableArray<NSDictionary *> alloc] init];
43
47
  NSMutableString *currentWord = [[NSMutableString alloc] init];
44
48
  NSInteger currentRangeStart = leftIt;
45
49
  NSInteger currentIdx = leftIt;
46
-
50
+
47
51
  while (currentIdx <= rightIt) {
48
52
  unichar charAtIndex = [text characterAtIndex:currentIdx];
49
- if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:charAtIndex]) {
53
+ if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
54
+ characterIsMember:charAtIndex]) {
50
55
  if (currentWord.length > 0) {
51
56
  [separatedWords addObject:@{
52
- @"word": [currentWord copy],
53
- @"range": [NSValue valueWithRange:NSMakeRange(currentRangeStart, currentWord.length)]
57
+ @"word" : [currentWord copy],
58
+ @"range" : [NSValue
59
+ valueWithRange:NSMakeRange(currentRangeStart, currentWord.length)]
54
60
  }];
55
61
  [currentWord setString:@""];
56
62
  }
@@ -60,28 +66,32 @@
60
66
  }
61
67
  currentIdx += 1;
62
68
  }
63
-
69
+
64
70
  if (currentWord.length > 0) {
65
71
  [separatedWords addObject:@{
66
- @"word": [currentWord copy],
67
- @"range": [NSValue valueWithRange:NSMakeRange(currentRangeStart, rightIt - currentRangeStart + 1)]
72
+ @"word" : [currentWord copy],
73
+ @"range" :
74
+ [NSValue valueWithRange:NSMakeRange(currentRangeStart,
75
+ rightIt - currentRangeStart + 1)]
68
76
  }];
69
77
  }
70
-
78
+
71
79
  return separatedWords;
72
80
  }
73
81
 
74
82
  + (NSDictionary *)getCurrentWord:(NSString *)text range:(NSRange)range {
75
83
  // we just get current word at the cursor
76
- if(range.length > 0) {
84
+ if (range.length > 0) {
77
85
  return nullptr;
78
86
  }
79
-
80
- NSArray<NSDictionary *> *words = [WordsUtils getAffectedWordsFromText:text modificationRange:range];
81
- if(words != nullptr && [words count] == 1 && [words firstObject] != nullptr) {
87
+
88
+ NSArray<NSDictionary *> *words = [WordsUtils getAffectedWordsFromText:text
89
+ modificationRange:range];
90
+ if (words != nullptr && [words count] == 1 &&
91
+ [words firstObject] != nullptr) {
82
92
  return [words firstObject];
83
93
  }
84
-
94
+
85
95
  return nullptr;
86
96
  }
87
97
 
@@ -3,5 +3,7 @@
3
3
 
4
4
  @interface ZeroWidthSpaceUtils : NSObject
5
5
  + (void)handleZeroWidthSpacesInInput:(id)input;
6
- + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input;
6
+ + (BOOL)handleBackspaceInRange:(NSRange)range
7
+ replacementText:(NSString *)text
8
+ input:(id)input;
7
9
  @end
@@ -7,8 +7,10 @@
7
7
  @implementation ZeroWidthSpaceUtils
8
8
  + (void)handleZeroWidthSpacesInInput:(id)input {
9
9
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
10
- if(typedInput == nullptr) { return; }
11
-
10
+ if (typedInput == nullptr) {
11
+ return;
12
+ }
13
+
12
14
  [self removeSpacesIfNeededinInput:typedInput];
13
15
  [self addSpacesIfNeededinInput:typedInput];
14
16
  }
@@ -17,154 +19,230 @@
17
19
  NSMutableArray *indexesToBeRemoved = [[NSMutableArray alloc] init];
18
20
  NSRange preRemoveSelection = input->textView.selectedRange;
19
21
 
20
- for(int i = 0; i < input->textView.textStorage.string.length; i++) {
22
+ for (int i = 0; i < input->textView.textStorage.string.length; i++) {
21
23
  unichar character = [input->textView.textStorage.string characterAtIndex:i];
22
- if(character == 0x200B) {
24
+ if (character == 0x200B) {
23
25
  NSRange characterRange = NSMakeRange(i, 1);
24
-
25
- NSRange paragraphRange = [input->textView.textStorage.string paragraphRangeForRange:characterRange];
26
- // having paragraph longer than 1 character means someone most likely added something and we probably can remove the space
26
+
27
+ NSRange paragraphRange = [input->textView.textStorage.string
28
+ paragraphRangeForRange:characterRange];
29
+ // having paragraph longer than 1 character means someone most likely
30
+ // added something and we probably can remove the space
27
31
  BOOL removeSpace = paragraphRange.length > 1;
28
32
  // exception; 2 characters paragraph with zero width space + newline
29
33
  // here, we still need zero width space to keep the empty list items
30
- if(paragraphRange.length == 2 &&
31
- paragraphRange.location == i &&
32
- [[NSCharacterSet newlineCharacterSet] characterIsMember:[input->textView.textStorage.string characterAtIndex:i+1]]
33
- ) {
34
+ if (paragraphRange.length == 2 && paragraphRange.location == i &&
35
+ [[NSCharacterSet newlineCharacterSet]
36
+ characterIsMember:[input->textView.textStorage.string
37
+ characterAtIndex:i + 1]]) {
34
38
  removeSpace = NO;
35
39
  }
36
-
37
- if(removeSpace) {
40
+
41
+ if (removeSpace) {
38
42
  [indexesToBeRemoved addObject:@(characterRange.location)];
39
43
  continue;
40
44
  }
41
-
42
- UnorderedListStyle *ulStyle = input->stylesDict[@([UnorderedListStyle getStyleType])];
43
- OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])];
44
- BlockQuoteStyle *bqStyle = input->stylesDict[@([BlockQuoteStyle getStyleType])];
45
-
46
- // zero width spaces with no lists/blockquote styles on them get removed
47
- if(![ulStyle detectStyle:characterRange] && ![olStyle detectStyle:characterRange] && ![bqStyle detectStyle:characterRange]) {
45
+
46
+ UnorderedListStyle *ulStyle =
47
+ input->stylesDict[@([UnorderedListStyle getStyleType])];
48
+ OrderedListStyle *olStyle =
49
+ input->stylesDict[@([OrderedListStyle getStyleType])];
50
+ BlockQuoteStyle *bqStyle =
51
+ input->stylesDict[@([BlockQuoteStyle getStyleType])];
52
+ CodeBlockStyle *cbStyle =
53
+ input->stylesDict[@([CodeBlockStyle getStyleType])];
54
+
55
+ // zero width spaces with no lists/blockquotes/codeblocks on them get
56
+ // removed
57
+ if (![ulStyle detectStyle:characterRange] &&
58
+ ![olStyle detectStyle:characterRange] &&
59
+ ![bqStyle detectStyle:characterRange] &&
60
+ ![cbStyle detectStyle:characterRange]) {
48
61
  [indexesToBeRemoved addObject:@(characterRange.location)];
49
62
  }
50
63
  }
51
64
  }
52
-
65
+
53
66
  // do the removing
54
67
  NSInteger offset = 0;
55
68
  NSInteger postRemoveLocationOffset = 0;
56
69
  NSInteger postRemoveLengthOffset = 0;
57
- for(NSNumber *index in indexesToBeRemoved) {
70
+ for (NSNumber *index in indexesToBeRemoved) {
58
71
  NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
59
- [TextInsertionUtils replaceText:@"" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
72
+ [TextInsertionUtils replaceText:@""
73
+ at:replaceRange
74
+ additionalAttributes:nullptr
75
+ input:input
76
+ withSelection:NO];
60
77
  offset -= 1;
61
- if([index integerValue] < preRemoveSelection.location) {
78
+ if ([index integerValue] < preRemoveSelection.location) {
62
79
  postRemoveLocationOffset -= 1;
63
80
  }
64
- if([index integerValue] >= preRemoveSelection.location && [index integerValue] < NSMaxRange(preRemoveSelection)) {
81
+ if ([index integerValue] >= preRemoveSelection.location &&
82
+ [index integerValue] < NSMaxRange(preRemoveSelection)) {
65
83
  postRemoveLengthOffset -= 1;
66
84
  }
67
85
  }
68
-
86
+
69
87
  // fix the selection if needed
70
- if([input->textView isFirstResponder]) {
71
- input->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveLocationOffset, preRemoveSelection.length + postRemoveLengthOffset);
88
+ if ([input->textView isFirstResponder]) {
89
+ input->textView.selectedRange =
90
+ NSMakeRange(preRemoveSelection.location + postRemoveLocationOffset,
91
+ preRemoveSelection.length + postRemoveLengthOffset);
72
92
  }
73
93
  }
74
94
 
75
95
  + (void)addSpacesIfNeededinInput:(EnrichedTextInputView *)input {
76
- UnorderedListStyle *ulStyle = input->stylesDict[@([UnorderedListStyle getStyleType])];
77
- OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])];
78
- BlockQuoteStyle *bqStyle = input->stylesDict[@([BlockQuoteStyle getStyleType])];
96
+ UnorderedListStyle *ulStyle =
97
+ input->stylesDict[@([UnorderedListStyle getStyleType])];
98
+ OrderedListStyle *olStyle =
99
+ input->stylesDict[@([OrderedListStyle getStyleType])];
100
+ BlockQuoteStyle *bqStyle =
101
+ input->stylesDict[@([BlockQuoteStyle getStyleType])];
102
+ CodeBlockStyle *cbStyle = input->stylesDict[@([CodeBlockStyle getStyleType])];
79
103
  NSMutableArray *indexesToBeInserted = [[NSMutableArray alloc] init];
80
104
  NSRange preAddSelection = input->textView.selectedRange;
81
-
82
- for(int i = 0; i < input->textView.textStorage.string.length; i++) {
105
+
106
+ for (int i = 0; i < input->textView.textStorage.string.length; i++) {
83
107
  unichar character = [input->textView.textStorage.string characterAtIndex:i];
84
-
85
- if([[NSCharacterSet newlineCharacterSet] characterIsMember:character]) {
108
+
109
+ if ([[NSCharacterSet newlineCharacterSet] characterIsMember:character]) {
86
110
  NSRange characterRange = NSMakeRange(i, 1);
87
- NSRange paragraphRange = [input->textView.textStorage.string paragraphRangeForRange:characterRange];
88
-
89
- if(paragraphRange.length == 1) {
90
- if([ulStyle detectStyle:characterRange] || [olStyle detectStyle:characterRange] || [bqStyle detectStyle:characterRange]) {
111
+ NSRange paragraphRange = [input->textView.textStorage.string
112
+ paragraphRangeForRange:characterRange];
113
+
114
+ if (paragraphRange.length == 1) {
115
+ if ([ulStyle detectStyle:characterRange] ||
116
+ [olStyle detectStyle:characterRange] ||
117
+ [bqStyle detectStyle:characterRange] ||
118
+ [cbStyle detectStyle:characterRange]) {
91
119
  // we have an empty list or quote item with no space: add it!
92
120
  [indexesToBeInserted addObject:@(paragraphRange.location)];
93
121
  }
94
122
  }
95
123
  }
96
124
  }
97
-
125
+
98
126
  // do the replacing
99
127
  NSInteger offset = 0;
100
128
  NSInteger postAddLocationOffset = 0;
101
129
  NSInteger postAddLengthOffset = 0;
102
- for(NSNumber *index in indexesToBeInserted) {
130
+ for (NSNumber *index in indexesToBeInserted) {
103
131
  NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
104
- [TextInsertionUtils replaceText:@"\u200B\n" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
132
+ [TextInsertionUtils replaceText:@"\u200B\n"
133
+ at:replaceRange
134
+ additionalAttributes:nullptr
135
+ input:input
136
+ withSelection:NO];
105
137
  offset += 1;
106
- if([index integerValue] < preAddSelection.location) {
138
+ if ([index integerValue] < preAddSelection.location) {
107
139
  postAddLocationOffset += 1;
108
140
  }
109
- if([index integerValue] >= preAddSelection.location && [index integerValue] < NSMaxRange(preAddSelection)) {
141
+ if ([index integerValue] >= preAddSelection.location &&
142
+ [index integerValue] < NSMaxRange(preAddSelection)) {
110
143
  postAddLengthOffset += 1;
111
144
  }
112
145
  }
113
-
146
+
114
147
  // additional check for last index of the input
115
148
  NSRange lastRange = NSMakeRange(input->textView.textStorage.string.length, 0);
116
- NSRange lastParagraphRange = [input->textView.textStorage.string paragraphRangeForRange:lastRange];
117
- if(lastParagraphRange.length == 0 && ([ulStyle detectStyle:lastRange] || [olStyle detectStyle:lastRange] || [bqStyle detectStyle:lastRange])) {
118
- [TextInsertionUtils insertText:@"\u200B" at:lastRange.location additionalAttributes:nullptr input:input withSelection:NO];
149
+ NSRange lastParagraphRange =
150
+ [input->textView.textStorage.string paragraphRangeForRange:lastRange];
151
+ if (lastParagraphRange.length == 0 &&
152
+ ([ulStyle detectStyle:lastRange] || [olStyle detectStyle:lastRange] ||
153
+ [bqStyle detectStyle:lastRange] || [cbStyle detectStyle:lastRange])) {
154
+ [TextInsertionUtils insertText:@"\u200B"
155
+ at:lastRange.location
156
+ additionalAttributes:nullptr
157
+ input:input
158
+ withSelection:NO];
119
159
  }
120
-
160
+
121
161
  // fix the selection if needed
122
- if([input->textView isFirstResponder]) {
123
- input->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddLocationOffset, preAddSelection.length + postAddLengthOffset);
162
+ if ([input->textView isFirstResponder]) {
163
+ input->textView.selectedRange =
164
+ NSMakeRange(preAddSelection.location + postAddLocationOffset,
165
+ preAddSelection.length + postAddLengthOffset);
124
166
  }
125
167
  }
126
168
 
127
- + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input {
128
- if(range.length != 1 || ![text isEqualToString:@""]) { return NO; }
169
+ + (BOOL)handleBackspaceInRange:(NSRange)range
170
+ replacementText:(NSString *)text
171
+ input:(id)input {
172
+ if (range.length != 1 || ![text isEqualToString:@""]) {
173
+ return NO;
174
+ }
129
175
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
130
- if(typedInput == nullptr) { return NO; }
131
-
132
- unichar character = [typedInput->textView.textStorage.string characterAtIndex:range.location];
176
+ if (typedInput == nullptr) {
177
+ return NO;
178
+ }
179
+
180
+ unichar character =
181
+ [typedInput->textView.textStorage.string characterAtIndex:range.location];
133
182
  // zero-width space got backspaced
134
- if(character == 0x200B) {
183
+ if (character == 0x200B) {
135
184
  // in such case: remove the whole line without the endline if there is one
136
-
137
- NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range];
185
+
186
+ NSRange paragraphRange =
187
+ [typedInput->textView.textStorage.string paragraphRangeForRange:range];
138
188
  NSRange removalRange = paragraphRange;
139
189
  // if whole paragraph gets removed then 0 length for style removal
140
190
  NSRange styleRemovalRange = NSMakeRange(paragraphRange.location, 0);
141
-
142
- if([[NSCharacterSet newlineCharacterSet] characterIsMember:[typedInput->textView.textStorage.string characterAtIndex:NSMaxRange(paragraphRange) - 1]]) {
191
+
192
+ if ([[NSCharacterSet newlineCharacterSet]
193
+ characterIsMember:[typedInput->textView.textStorage.string
194
+ characterAtIndex:NSMaxRange(paragraphRange) -
195
+ 1]]) {
143
196
  // if endline is there, don't remove it
144
- removalRange = NSMakeRange(paragraphRange.location, paragraphRange.length - 1);
197
+ removalRange =
198
+ NSMakeRange(paragraphRange.location, paragraphRange.length - 1);
145
199
  // if endline is left then 1 length for style removal
146
200
  styleRemovalRange = NSMakeRange(paragraphRange.location, 1);
147
201
  }
148
-
149
- [TextInsertionUtils replaceText:@"" at:removalRange additionalAttributes:nullptr input:typedInput withSelection:YES];
150
-
202
+
151
203
  // and then remove associated styling
152
-
153
- UnorderedListStyle *ulStyle = typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
154
- OrderedListStyle *olStyle = typedInput->stylesDict[@([OrderedListStyle getStyleType])];
155
- BlockQuoteStyle *bqStyle = typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
156
-
157
- if([ulStyle detectStyle:styleRemovalRange]) {
204
+
205
+ UnorderedListStyle *ulStyle =
206
+ typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
207
+ OrderedListStyle *olStyle =
208
+ typedInput->stylesDict[@([OrderedListStyle getStyleType])];
209
+ BlockQuoteStyle *bqStyle =
210
+ typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
211
+ CodeBlockStyle *cbStyle =
212
+ typedInput->stylesDict[@([CodeBlockStyle getStyleType])];
213
+
214
+ if ([cbStyle detectStyle:removalRange]) {
215
+ // code blocks are being handled differently; we want to remove previous
216
+ // newline if there is a one
217
+ if (range.location > 0) {
218
+ removalRange =
219
+ NSMakeRange(removalRange.location - 1, removalRange.length + 1);
220
+ }
221
+ [TextInsertionUtils replaceText:@""
222
+ at:removalRange
223
+ additionalAttributes:nullptr
224
+ input:typedInput
225
+ withSelection:YES];
226
+ return YES;
227
+ }
228
+
229
+ [TextInsertionUtils replaceText:@""
230
+ at:removalRange
231
+ additionalAttributes:nullptr
232
+ input:typedInput
233
+ withSelection:YES];
234
+
235
+ if ([ulStyle detectStyle:styleRemovalRange]) {
158
236
  [ulStyle removeAttributes:styleRemovalRange];
159
- } else if([olStyle detectStyle:styleRemovalRange]) {
237
+ } else if ([olStyle detectStyle:styleRemovalRange]) {
160
238
  [olStyle removeAttributes:styleRemovalRange];
161
- } else if([bqStyle detectStyle:styleRemovalRange]) {
239
+ } else if ([bqStyle detectStyle:styleRemovalRange]) {
162
240
  [bqStyle removeAttributes:styleRemovalRange];
163
241
  }
164
-
242
+
165
243
  return YES;
166
244
  }
167
245
  return NO;
168
246
  }
169
- @end
170
247
 
248
+ @end
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { useImperativeHandle, useMemo, useRef } from 'react';
3
+ import { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
4
4
  import EnrichedTextInputNativeComponent, { Commands } from './EnrichedTextInputNativeComponent';
5
5
  import { normalizeHtmlStyle } from "./normalizeHtmlStyle.js";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -42,6 +42,19 @@ export const EnrichedTextInput = ({
42
42
  ...rest
43
43
  }) => {
44
44
  const nativeRef = useRef(null);
45
+ const nextHtmlRequestId = useRef(1);
46
+ const pendingHtmlRequests = useRef(new Map());
47
+ useEffect(() => {
48
+ const pendingRequests = pendingHtmlRequests.current;
49
+ return () => {
50
+ pendingRequests.forEach(({
51
+ reject
52
+ }) => {
53
+ reject(new Error('Component unmounted'));
54
+ });
55
+ pendingRequests.clear();
56
+ };
57
+ }, []);
45
58
  const normalizedHtmlStyle = useMemo(() => normalizeHtmlStyle(htmlStyle, mentionIndicators), [htmlStyle, mentionIndicators]);
46
59
  useImperativeHandle(ref, () => ({
47
60
  measureInWindow: callback => {
@@ -65,6 +78,16 @@ export const EnrichedTextInput = ({
65
78
  setValue: value => {
66
79
  Commands.setValue(nullthrows(nativeRef.current), value);
67
80
  },
81
+ getHTML: () => {
82
+ return new Promise((resolve, reject) => {
83
+ const requestId = nextHtmlRequestId.current++;
84
+ pendingHtmlRequests.current.set(requestId, {
85
+ resolve,
86
+ reject
87
+ });
88
+ Commands.requestHTML(nullthrows(nativeRef.current), requestId);
89
+ });
90
+ },
68
91
  toggleBold: () => {
69
92
  Commands.toggleBold(nullthrows(nativeRef.current));
70
93
  },
@@ -104,8 +127,8 @@ export const EnrichedTextInput = ({
104
127
  setLink: (start, end, text, url) => {
105
128
  Commands.addLink(nullthrows(nativeRef.current), start, end, text, url);
106
129
  },
107
- setImage: uri => {
108
- Commands.addImage(nullthrows(nativeRef.current), uri);
130
+ setImage: (uri, width, height) => {
131
+ Commands.addImage(nullthrows(nativeRef.current), uri, width, height);
109
132
  },
110
133
  setMention: (indicator, text, attributes) => {
111
134
  // Codegen does not support objects as Commands parameters, so we stringify attributes
@@ -162,6 +185,20 @@ export const EnrichedTextInput = ({
162
185
  attributes
163
186
  });
164
187
  };
188
+ const handleRequestHtmlResult = e => {
189
+ const {
190
+ requestId,
191
+ html
192
+ } = e.nativeEvent;
193
+ const pending = pendingHtmlRequests.current.get(requestId);
194
+ if (!pending) return;
195
+ if (html === null || typeof html !== 'string') {
196
+ pending.reject(new Error('Failed to parse HTML'));
197
+ } else {
198
+ pending.resolve(html);
199
+ }
200
+ pendingHtmlRequests.current.delete(requestId);
201
+ };
165
202
  return /*#__PURE__*/_jsx(EnrichedTextInputNativeComponent, {
166
203
  ref: nativeRef,
167
204
  mentionIndicators: mentionIndicators,
@@ -185,6 +222,7 @@ export const EnrichedTextInput = ({
185
222
  onMentionDetected: handleMentionDetected,
186
223
  onMention: handleMentionEvent,
187
224
  onChangeSelection: onChangeSelection,
225
+ onRequestHtmlResult: handleRequestHtmlResult,
188
226
  androidExperimentalSynchronousEvents: androidExperimentalSynchronousEvents,
189
227
  scrollEnabled: scrollEnabled,
190
228
  ...rest
@@ -1 +1 @@
1
- {"version":3,"names":["useImperativeHandle","useMemo","useRef","EnrichedTextInputNativeComponent","Commands","normalizeHtmlStyle","jsx","_jsx","nullthrows","value","Error","warnAboutMissconfiguredMentions","indicator","console","warn","EnrichedTextInput","ref","autoFocus","editable","mentionIndicators","defaultValue","placeholder","placeholderTextColor","cursorColor","selectionColor","style","autoCapitalize","htmlStyle","onFocus","onBlur","onChangeText","onChangeHtml","onChangeState","onLinkDetected","onMentionDetected","onStartMention","onChangeMention","onEndMention","onChangeSelection","androidExperimentalSynchronousEvents","scrollEnabled","rest","nativeRef","normalizedHtmlStyle","measureInWindow","callback","current","measure","measureLayout","relativeToNativeComponentRef","onSuccess","onFail","setNativeProps","nativeProps","focus","blur","setValue","toggleBold","toggleItalic","toggleUnderline","toggleStrikeThrough","toggleInlineCode","toggleH1","toggleH2","toggleH3","toggleCodeBlock","toggleBlockQuote","toggleOrderedList","toggleUnorderedList","setLink","start","end","text","url","addLink","setImage","uri","addImage","setMention","attributes","parsedAttributes","JSON","stringify","addMention","startMention","includes","handleMentionEvent","e","mentionText","nativeEvent","mentionIndicator","handleLinkDetected","handleMentionDetected","payload","parse","onInputFocus","onInputBlur","isOnChangeHtmlSet","undefined","onMention"],"sourceRoot":"../../src","sources":["EnrichedTextInput.tsx"],"mappings":";;AAAA,SAGEA,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACD,OAAO;AACd,OAAOC,gCAAgC,IACrCC,QAAQ,QAWH,oCAAoC;AAa3C,SAASC,kBAAkB,QAAQ,yBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA0H1D,MAAMC,UAAU,GAAQC,KAA2B,IAAQ;EACzD,IAAIA,KAAK,IAAI,IAAI,EAAE;IACjB,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;EACvD;EAEA,OAAOD,KAAK;AACd,CAAC;AAED,MAAME,+BAA+B,GAAIC,SAAiB,IAAK;EAC7DC,OAAO,CAACC,IAAI,CACV,uCAAuCF,SAAS,8CAClD,CAAC;AACH,CAAC;AAID,OAAO,MAAMG,iB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AAC,GAAGN,CAAC,CAACE,WAAW;IAClD,MAAMV,UAAU,GAAGE,IAAI,CAACa,KAAK,CAACD,OAAO,CAA2B;IAChE3D,iBAAiB,GAAG;MAAEsC,IAAI;MAAE5D,SAAS;MAAEmE;IAAW,CAAC,CAAC;EACtD,CAAC;EAED,oBACExE,IAAA,CAACJ,gCAAgC;IAC/Ba,GAAG,EAAE0B,SAAU;IACfvB,iBAAiB,EAAEA,iBAAkB;IACrCD,QAAQ,EAAEA,QAAS;IACnBD,SAAS,EAAEA,SAAU;IACrBG,YAAY,EAAEA,YAAa;IAC3BC,WAAW,EAAEA,WAAY;IACzBC,oBAAoB,EAAEA,oBAAqB;IAC3CC,WAAW,EAAEA,WAAY;IACzBC,cAAc,EAAEA,cAAe;IAC/BC,KAAK,EAAEA,KAAM;IACbC,cAAc,EAAEA,cAAe;IAC/BC,SAAS,EAAEgB,mBAAoB;IAC/BoD,YAAY,EAAEnE,OAAQ;IACtBoE,WAAW,EAAEnE,MAAO;IACpBC,YAAY,EAAEA,YAAa;IAC3BC,YAAY,EAAEA,YAAa;IAC3BkE,iBAAiB,EAAElE,YAAY,KAAKmE,SAAU;IAC9ClE,aAAa,EAAEA,aAAc;IAC7BC,cAAc,EAAE0D,kBAAmB;IACnCzD,iBAAiB,EAAE0D,qBAAsB;IACzCO,SAAS,EAAEb,kBAAmB;IAC9BhD,iBAAiB,EAAEA,iBAAkB;IACrCC,oCAAoC,EAClCA,oCACD;IACDC,aAAa,EAAEA,aAAc;IAAA,GACzBC;EAAI,CACT,CAAC;AAEN,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useImperativeHandle","useMemo","useRef","EnrichedTextInputNativeComponent","Commands","normalizeHtmlStyle","jsx","_jsx","nullthrows","value","Error","warnAboutMissconfiguredMentions","indicator","console","warn","EnrichedTextInput","ref","autoFocus","editable","mentionIndicators","defaultValue","placeholder","placeholderTextColor","cursorColor","selectionColor","style","autoCapitalize","htmlStyle","onFocus","onBlur","onChangeText","onChangeHtml","onChangeState","onLinkDetected","onMentionDetected","onStartMention","onChangeMention","onEndMention","onChangeSelection","androidExperimentalSynchronousEvents","scrollEnabled","rest","nativeRef","nextHtmlRequestId","pendingHtmlRequests","Map","pendingRequests","current","forEach","reject","clear","normalizedHtmlStyle","measureInWindow","callback","measure","measureLayout","relativeToNativeComponentRef","onSuccess","onFail","setNativeProps","nativeProps","focus","blur","setValue","getHTML","Promise","resolve","requestId","set","requestHTML","toggleBold","toggleItalic","toggleUnderline","toggleStrikeThrough","toggleInlineCode","toggleH1","toggleH2","toggleH3","toggleCodeBlock","toggleBlockQuote","toggleOrderedList","toggleUnorderedList","setLink","start","end","text","url","addLink","setImage","uri","width","height","addImage","setMention","attributes","parsedAttributes","JSON","stringify","addMention","startMention","includes","handleMentionEvent","e","mentionText","nativeEvent","mentionIndicator","handleLinkDetected","handleMentionDetected","payload","parse","handleRequestHtmlResult","html","pending","get","delete","onInputFocus","onInputBlur","isOnChangeHtmlSet","undefined","onMention","onRequestHtmlResult"],"sourceRoot":"../../src","sources":["EnrichedTextInput.tsx"],"mappings":";;AAAA,SAGEA,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACD,OAAO;AACd,OAAOC,gCAAgC,IACrCC,QAAQ,QAYH,oCAAoC;AAa3C,SAASC,kBAAkB,QAAQ,yBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAuH1D,MAAMC,UAAU,GAAQC,KAA2B,IAAQ;EACzD,IAAIA,KAAK,IAAI,IAAI,EAAE;IACjB,MAAM,IAAIC,KAAK,CAAC,oCAAoC,CAAC;EACvD;EAEA,OAAOD,KAAK;AACd,CAAC;AAED,MAAME,+BAA+B,GAAIC,SAAiB,IAAK;EAC7DC,OAAO,CAACC,IAAI,CACV,uCAAuCF,SAAS,8CAClD,CAAC;AACH,CAAC;AASD,OAAO,MAAMG,iBAAiB,GAAGA,CAAC;EAChCC,GAAG;EACHC,SAAS;EACTC,QAAQ,GAAG,IAAI;E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AEd,IAAID,IAAI,KAAK,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC7CC,OAAO,CAAC/D,MAAM,CAAC,IAAIvC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACnD,CAAC,MAAM;MACLsG,OAAO,CAAC9C,OAAO,CAAC6C,IAAI,CAAC;IACvB;IAEAnE,mBAAmB,CAACG,OAAO,CAACmE,MAAM,CAAC/C,SAAS,CAAC;EAC/C,CAAC;EAED,oBACE5D,IAAA,CAACJ,gCAAgC;IAC/Ba,GAAG,EAAE0B,SAAU;IACfvB,iBAAiB,EAAEA,iBAAkB;IACrCD,QAAQ,EAAEA,QAAS;IACnBD,SAAS,EAAEA,SAAU;IACrBG,YAAY,EAAEA,YAAa;IAC3BC,WAAW,EAAEA,WAAY;IACzBC,oBAAoB,EAAEA,oBAAqB;IAC3CC,WAAW,EAAEA,WAAY;IACzBC,cAAc,EAAEA,cAAe;IAC/BC,KAAK,EAAEA,KAAM;IACbC,cAAc,EAAEA,cAAe;IAC/BC,SAAS,EAAEwB,mBAAoB;IAC/BgE,YAAY,EAAEvF,OAAQ;IACtBwF,WAAW,EAAEvF,MAAO;IACpBC,YAAY,EAAEA,YAAa;IAC3BC,YAAY,EAAEA,YAAa;IAC3BsF,iBAAiB,EAAEtF,YAAY,KAAKuF,SAAU;IAC9CtF,aAAa,EAAEA,aAAc;IAC7BC,cAAc,EAAEyE,kBAAmB;IACnCxE,iBAAiB,EAAEyE,qBAAsB;IACzCY,SAAS,EAAElB,kBAAmB;IAC9B/D,iBAAiB,EAAEA,iBAAkB;IACrCkF,mBAAmB,EAAEV,uBAAwB;IAC7CvE,oCAAoC,EAClCA,oCACD;IACDC,aAAa,EAAEA,aAAc;IAAA,GACzBC;EAAI,CACT,CAAC;AAEN,CAAC","ignoreList":[]}
@@ -64,6 +64,11 @@ export interface OnChangeSelectionEvent {
64
64
  text: string;
65
65
  }
66
66
 
67
+ export interface OnRequestHtmlResultEvent {
68
+ requestId: Int32;
69
+ html: UnsafeMixed;
70
+ }
71
+
67
72
  export interface MentionStyleProperties {
68
73
  color?: ColorValue;
69
74
  backgroundColor?: ColorValue;
@@ -105,10 +110,6 @@ export interface HtmlStyleInternal {
105
110
  // This is a workaround for the fact that codegen does not support Records.
106
111
  // On native Android side this will become a ReadableMap, on native iOS we can work with a folly::dynamic object.
107
112
  mention?: UnsafeMixed;
108
- img?: {
109
- width?: Float;
110
- height?: Float;
111
- };
112
113
  ol?: {
113
114
  gapWidth?: Float;
114
115
  marginLeft?: Float;
@@ -147,6 +148,7 @@ export interface NativeProps extends ViewProps {
147
148
  onMentionDetected?: DirectEventHandler<OnMentionDetectedInternal>;
148
149
  onMention?: DirectEventHandler<OnMentionEvent>;
149
150
  onChangeSelection?: DirectEventHandler<OnChangeSelectionEvent>;
151
+ onRequestHtmlResult?: DirectEventHandler<OnRequestHtmlResultEvent>;
150
152
 
151
153
  // Style related props - used for generating proper setters in component's manager
152
154
  // These should not be passed as regular props
@@ -191,7 +193,12 @@ interface NativeCommands {
191
193
  text: string,
192
194
  url: string
193
195
  ) => void;
194
- addImage: (viewRef: React.ElementRef<ComponentType>, uri: string) => void;
196
+ addImage: (
197
+ viewRef: React.ElementRef<ComponentType>,
198
+ uri: string,
199
+ width: Float,
200
+ height: Float
201
+ ) => void;
195
202
  startMention: (
196
203
  viewRef: React.ElementRef<ComponentType>,
197
204
  indicator: string
@@ -202,6 +209,10 @@ interface NativeCommands {
202
209
  text: string,
203
210
  payload: string
204
211
  ) => void;
212
+ requestHTML: (
213
+ viewRef: React.ElementRef<ComponentType>,
214
+ requestId: Int32
215
+ ) => void;
205
216
  }
206
217
 
207
218
  export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
@@ -228,6 +239,7 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
228
239
  'addImage',
229
240
  'startMention',
230
241
  'addMention',
242
+ 'requestHTML',
231
243
  ],
232
244
  });
233
245
 
@@ -38,10 +38,6 @@ const defaultStyle = {
38
38
  backgroundColor: 'yellow',
39
39
  textDecorationLine: 'underline'
40
40
  },
41
- img: {
42
- width: 80,
43
- height: 80
44
- },
45
41
  ol: {
46
42
  gapWidth: 16,
47
43
  marginLeft: 16,