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
@@ -0,0 +1,10 @@
1
+ #import "ImageData.h"
2
+ #import "MediaAttachment.h"
3
+
4
+ @interface ImageAttachment : MediaAttachment
5
+
6
+ @property(nonatomic, strong) ImageData *imageData;
7
+
8
+ - (instancetype)initWithImageData:(ImageData *)data;
9
+
10
+ @end
@@ -0,0 +1,34 @@
1
+ #import "ImageAttachment.h"
2
+
3
+ @implementation ImageAttachment
4
+
5
+ - (instancetype)initWithImageData:(ImageData *)data {
6
+ self = [super initWithURI:data.uri width:data.width height:data.height];
7
+ if (!self)
8
+ return nil;
9
+
10
+ _imageData = data;
11
+ self.image = [UIImage new];
12
+
13
+ [self loadAsync];
14
+ return self;
15
+ }
16
+
17
+ - (void)loadAsync {
18
+ NSURL *url = [NSURL URLWithString:self.uri];
19
+ if (!url)
20
+ return;
21
+
22
+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
23
+ NSData *bytes = [NSData dataWithContentsOfURL:url];
24
+ UIImage *img = bytes ? [UIImage imageWithData:bytes]
25
+ : [UIImage systemImageNamed:@"file"];
26
+
27
+ dispatch_async(dispatch_get_main_queue(), ^{
28
+ self.image = img;
29
+ [self notifyUpdate];
30
+ });
31
+ });
32
+ }
33
+
34
+ @end
@@ -0,0 +1,23 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ @class MediaAttachment;
4
+
5
+ @protocol MediaAttachmentDelegate <NSObject>
6
+ - (void)mediaAttachmentDidUpdate:(MediaAttachment *)attachment;
7
+ @end
8
+
9
+ @interface MediaAttachment : NSTextAttachment
10
+
11
+ @property(nonatomic, weak) id<MediaAttachmentDelegate> delegate;
12
+ @property(nonatomic, strong) NSString *uri;
13
+ @property(nonatomic, assign) CGFloat width;
14
+ @property(nonatomic, assign) CGFloat height;
15
+
16
+ - (instancetype)initWithURI:(NSString *)uri
17
+ width:(CGFloat)width
18
+ height:(CGFloat)height;
19
+
20
+ - (void)loadAsync;
21
+ - (void)notifyUpdate;
22
+
23
+ @end
@@ -0,0 +1,31 @@
1
+ #import "MediaAttachment.h"
2
+
3
+ @implementation MediaAttachment
4
+
5
+ - (instancetype)initWithURI:(NSString *)uri
6
+ width:(CGFloat)width
7
+ height:(CGFloat)height {
8
+ self = [super init];
9
+ if (!self)
10
+ return nil;
11
+
12
+ _uri = uri;
13
+ _width = width;
14
+ _height = height;
15
+
16
+ self.bounds = CGRectMake(0, 0, width, height);
17
+
18
+ return self;
19
+ }
20
+
21
+ - (void)loadAsync {
22
+ // no-op for base
23
+ }
24
+
25
+ - (void)notifyUpdate {
26
+ if ([self.delegate respondsToSelector:@selector(mediaAttachmentDidUpdate:)]) {
27
+ [self.delegate mediaAttachmentDidUpdate:self];
28
+ }
29
+ }
30
+
31
+ @end
@@ -1,10 +1,10 @@
1
1
  #pragma once
2
- #import <UIKit/UIKit.h>
3
- #import "TextDecorationLineEnum.h"
4
2
  #import "MentionStyleProps.h"
3
+ #import "TextDecorationLineEnum.h"
4
+ #import <UIKit/UIKit.h>
5
5
 
6
- @interface InputConfig: NSObject<NSCopying>
7
- - (instancetype) init;
6
+ @interface InputConfig : NSObject <NSCopying>
7
+ - (instancetype)init;
8
8
  - (UIColor *)primaryColor;
9
9
  - (void)setPrimaryColor:(UIColor *)newValue;
10
10
  - (NSNumber *)primaryFontSize;
@@ -15,8 +15,8 @@
15
15
  - (void)setPrimaryFontFamily:(NSString *)newValue;
16
16
  - (UIFont *)primaryFont;
17
17
  - (UIFont *)monospacedFont;
18
- - (NSSet<NSNumber*>*)mentionIndicators;
19
- - (void)setMentionIndicators:(NSSet<NSNumber*>*)newValue;
18
+ - (NSSet<NSNumber *> *)mentionIndicators;
19
+ - (void)setMentionIndicators:(NSSet<NSNumber *> *)newValue;
20
20
  - (CGFloat)h1FontSize;
21
21
  - (void)setH1FontSize:(CGFloat)newValue;
22
22
  - (BOOL)h1Bold;
@@ -64,4 +64,10 @@
64
64
  - (void)setLinkDecorationLine:(TextDecorationLineEnum)newValue;
65
65
  - (void)setMentionStyleProps:(NSDictionary *)newValue;
66
66
  - (MentionStyleProps *)mentionStylePropsForIndicator:(NSString *)indicator;
67
+ - (UIColor *)codeBlockFgColor;
68
+ - (void)setCodeBlockFgColor:(UIColor *)newValue;
69
+ - (UIColor *)codeBlockBgColor;
70
+ - (void)setCodeBlockBgColor:(UIColor *)newValue;
71
+ - (CGFloat)codeBlockBorderRadius;
72
+ - (void)setCodeBlockBorderRadius:(CGFloat)newValue;
67
73
  @end
@@ -10,7 +10,7 @@
10
10
  UIFont *_monospacedFont;
11
11
  BOOL _primaryFontNeedsRecreation;
12
12
  BOOL _monospacedFontNeedsRecreation;
13
- NSSet<NSNumber*> *_mentionIndicators;
13
+ NSSet<NSNumber *> *_mentionIndicators;
14
14
  CGFloat _h1FontSize;
15
15
  BOOL _h1Bold;
16
16
  CGFloat _h2FontSize;
@@ -36,9 +36,14 @@
36
36
  UIColor *_linkColor;
37
37
  TextDecorationLineEnum _linkDecorationLine;
38
38
  NSDictionary *_mentionProperties;
39
+ UIColor *_codeBlockFgColor;
40
+ CGFloat _codeBlockBorderRadius;
41
+ UIColor *_codeBlockBgColor;
42
+ CGFloat _imageWidth;
43
+ CGFloat _imageHeight;
39
44
  }
40
45
 
41
- - (instancetype) init {
46
+ - (instancetype)init {
42
47
  self = [super init];
43
48
  _primaryFontNeedsRecreation = YES;
44
49
  _monospacedFontNeedsRecreation = YES;
@@ -79,6 +84,9 @@
79
84
  copy->_linkColor = [_linkColor copy];
80
85
  copy->_linkDecorationLine = [_linkDecorationLine copy];
81
86
  copy->_mentionProperties = [_mentionProperties mutableCopy];
87
+ copy->_codeBlockFgColor = [_codeBlockFgColor copy];
88
+ copy->_codeBlockBgColor = [_codeBlockBgColor copy];
89
+ copy->_codeBlockBorderRadius = _codeBlockBorderRadius;
82
90
  return copy;
83
91
  }
84
92
 
@@ -102,7 +110,9 @@
102
110
  }
103
111
 
104
112
  - (NSString *)primaryFontWeight {
105
- return _primaryFontWeight != nullptr ? _primaryFontWeight : [NSString stringWithFormat:@"%@", @(UIFontWeightRegular)];
113
+ return _primaryFontWeight != nullptr
114
+ ? _primaryFontWeight
115
+ : [NSString stringWithFormat:@"%@", @(UIFontWeightRegular)];
106
116
  }
107
117
 
108
118
  - (void)setPrimaryFontWeight:(NSString *)newValue {
@@ -122,41 +132,45 @@
122
132
  }
123
133
 
124
134
  - (UIFont *)primaryFont {
125
- if(_primaryFontNeedsRecreation) {
135
+ if (_primaryFontNeedsRecreation) {
126
136
  _primaryFontNeedsRecreation = NO;
127
-
137
+
128
138
  NSString *newFontWeight = [self primaryFontWeight];
129
139
  // fix RCTFontWeight conversion warnings:
130
140
  // sometimes changing font family comes with weight '0' if not specified
131
- // RCTConvert doesn't recognize this value so we just nullify it and it gets a default value
132
- if([newFontWeight isEqualToString:@"0"]) {
141
+ // RCTConvert doesn't recognize this value so we just nullify it and it gets
142
+ // a default value
143
+ if ([newFontWeight isEqualToString:@"0"]) {
133
144
  newFontWeight = nullptr;
134
145
  }
135
-
146
+
136
147
  _primaryFont = [RCTFont updateFont:nullptr
137
- withFamily:[self primaryFontFamily]
138
- size:[self primaryFontSize]
139
- weight:newFontWeight
140
- style:nullptr
141
- variant:nullptr
142
- scaleMultiplier: 1];
148
+ withFamily:[self primaryFontFamily]
149
+ size:[self primaryFontSize]
150
+ weight:newFontWeight
151
+ style:nullptr
152
+ variant:nullptr
153
+ scaleMultiplier:1];
143
154
  }
144
155
  return _primaryFont;
145
156
  }
146
157
 
147
158
  - (UIFont *)monospacedFont {
148
- if(_monospacedFontNeedsRecreation) {
159
+ if (_monospacedFontNeedsRecreation) {
149
160
  _monospacedFontNeedsRecreation = NO;
150
- _monospacedFont = [UIFont monospacedSystemFontOfSize: [[self primaryFontSize] floatValue] weight: [[self primaryFontWeight] floatValue]];
161
+ _monospacedFont = [UIFont
162
+ monospacedSystemFontOfSize:[[self primaryFontSize] floatValue]
163
+ weight:[[self primaryFontWeight] floatValue]];
151
164
  }
152
165
  return _monospacedFont;
153
166
  }
154
167
 
155
- - (NSSet<NSNumber*>*)mentionIndicators {
156
- return _mentionIndicators != nullptr ? _mentionIndicators : [[NSSet alloc] init];
168
+ - (NSSet<NSNumber *> *)mentionIndicators {
169
+ return _mentionIndicators != nullptr ? _mentionIndicators
170
+ : [[NSSet alloc] init];
157
171
  }
158
172
 
159
- - (void)setMentionIndicators:(NSSet<NSNumber*>*)newValue {
173
+ - (void)setMentionIndicators:(NSSet<NSNumber *> *)newValue {
160
174
  _mentionIndicators = newValue;
161
175
  }
162
176
 
@@ -224,7 +238,6 @@
224
238
  _blockquoteBorderWidth = newValue;
225
239
  }
226
240
 
227
-
228
241
  - (CGFloat)blockquoteGapWidth {
229
242
  return _blockquoteGapWidth;
230
243
  }
@@ -291,24 +304,25 @@
291
304
  }
292
305
 
293
306
  - (UIFont *)orderedListMarkerFont {
294
- if(_olMarkerFontNeedsRecreation) {
307
+ if (_olMarkerFontNeedsRecreation) {
295
308
  _olMarkerFontNeedsRecreation = NO;
296
-
309
+
297
310
  NSString *newFontWeight = [self orderedListMarkerFontWeight];
298
311
  // fix RCTFontWeight conversion warnings:
299
312
  // sometimes changing font family comes with weight '0' if not specified
300
- // RCTConvert doesn't recognize this value so we just nullify it and it gets a default value
301
- if([newFontWeight isEqualToString:@"0"]) {
313
+ // RCTConvert doesn't recognize this value so we just nullify it and it gets
314
+ // a default value
315
+ if ([newFontWeight isEqualToString:@"0"]) {
302
316
  newFontWeight = nullptr;
303
317
  }
304
-
318
+
305
319
  _orderedListMarkerFont = [RCTFont updateFont:nullptr
306
- withFamily:[self primaryFontFamily]
307
- size:[self primaryFontSize]
308
- weight:newFontWeight
309
- style:nullptr
310
- variant:nullptr
311
- scaleMultiplier: 1];
320
+ withFamily:[self primaryFontFamily]
321
+ size:[self primaryFontSize]
322
+ weight:newFontWeight
323
+ style:nullptr
324
+ variant:nullptr
325
+ scaleMultiplier:1];
312
326
  }
313
327
  return _orderedListMarkerFont;
314
328
  }
@@ -366,10 +380,10 @@
366
380
  }
367
381
 
368
382
  - (MentionStyleProps *)mentionStylePropsForIndicator:(NSString *)indicator {
369
- if(_mentionProperties.count == 1 && _mentionProperties[@"all"] != nullptr) {
383
+ if (_mentionProperties.count == 1 && _mentionProperties[@"all"] != nullptr) {
370
384
  // single props for all the indicators
371
385
  return _mentionProperties[@"all"];
372
- } else if(_mentionProperties[indicator] != nullptr) {
386
+ } else if (_mentionProperties[indicator] != nullptr) {
373
387
  return _mentionProperties[indicator];
374
388
  }
375
389
  MentionStyleProps *fallbackProps = [[MentionStyleProps alloc] init];
@@ -379,4 +393,28 @@
379
393
  return fallbackProps;
380
394
  }
381
395
 
396
+ - (UIColor *)codeBlockFgColor {
397
+ return _codeBlockFgColor;
398
+ }
399
+
400
+ - (void)setCodeBlockFgColor:(UIColor *)newValue {
401
+ _codeBlockFgColor = newValue;
402
+ }
403
+
404
+ - (UIColor *)codeBlockBgColor {
405
+ return _codeBlockBgColor;
406
+ }
407
+
408
+ - (void)setCodeBlockBgColor:(UIColor *)newValue {
409
+ _codeBlockBgColor = newValue;
410
+ }
411
+
412
+ - (CGFloat)codeBlockBorderRadius {
413
+ return _codeBlockBorderRadius;
414
+ }
415
+
416
+ - (void)setCodeBlockBorderRadius:(CGFloat)newValue {
417
+ _codeBlockBorderRadius = newValue;
418
+ }
419
+
382
420
  @end
@@ -115,4 +115,14 @@ payload.setProperty(runtime, "text", event.text);
115
115
  });
116
116
  }
117
117
 
118
+
119
+ void EnrichedTextInputViewEventEmitter::onRequestHtmlResult(OnRequestHtmlResult event) const {
120
+ dispatchEvent("requestHtmlResult", [event=std::move(event)](jsi::Runtime &runtime) {
121
+ auto payload = jsi::Object(runtime);
122
+ payload.setProperty(runtime, "requestId", event.requestId);
123
+ payload.setProperty(runtime, "html", jsi::valueFromDynamic(runtime, event.html));
124
+ return payload;
125
+ });
126
+ }
127
+
118
128
  } // namespace facebook::react
@@ -74,6 +74,11 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
74
74
  int end;
75
75
  std::string text;
76
76
  };
77
+
78
+ struct OnRequestHtmlResult {
79
+ int requestId;
80
+ folly::dynamic html;
81
+ };
77
82
  void onInputFocus(OnInputFocus value) const;
78
83
 
79
84
  void onInputBlur(OnInputBlur value) const;
@@ -91,5 +96,7 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
91
96
  void onMention(OnMention value) const;
92
97
 
93
98
  void onChangeSelection(OnChangeSelection value) const;
99
+
100
+ void onRequestHtmlResult(OnRequestHtmlResult value) const;
94
101
  };
95
102
  } // namespace facebook::react
@@ -309,45 +309,6 @@ static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleAStru
309
309
  }
310
310
  #endif
311
311
 
312
- struct EnrichedTextInputViewHtmlStyleImgStruct {
313
- Float width{0.0};
314
- Float height{0.0};
315
-
316
- #ifdef RN_SERIALIZABLE_STATE
317
- bool operator==(const EnrichedTextInputViewHtmlStyleImgStruct&) const = default;
318
-
319
- folly::dynamic toDynamic() const {
320
- folly::dynamic result = folly::dynamic::object();
321
- result["width"] = width;
322
- result["height"] = height;
323
- return result;
324
- }
325
- #endif
326
- };
327
-
328
- static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewHtmlStyleImgStruct &result) {
329
- auto map = (std::unordered_map<std::string, RawValue>)value;
330
-
331
- auto tmp_width = map.find("width");
332
- if (tmp_width != map.end()) {
333
- fromRawValue(context, tmp_width->second, result.width);
334
- }
335
- auto tmp_height = map.find("height");
336
- if (tmp_height != map.end()) {
337
- fromRawValue(context, tmp_height->second, result.height);
338
- }
339
- }
340
-
341
- static inline std::string toString(const EnrichedTextInputViewHtmlStyleImgStruct &value) {
342
- return "[Object EnrichedTextInputViewHtmlStyleImgStruct]";
343
- }
344
-
345
- #ifdef RN_SERIALIZABLE_STATE
346
- static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleImgStruct &value) {
347
- return value.toDynamic();
348
- }
349
- #endif
350
-
351
312
  struct EnrichedTextInputViewHtmlStyleOlStruct {
352
313
  Float gapWidth{0.0};
353
314
  Float marginLeft{0.0};
@@ -459,7 +420,6 @@ struct EnrichedTextInputViewHtmlStyleStruct {
459
420
  EnrichedTextInputViewHtmlStyleCodeStruct code{};
460
421
  EnrichedTextInputViewHtmlStyleAStruct a{};
461
422
  folly::dynamic mention{};
462
- EnrichedTextInputViewHtmlStyleImgStruct img{};
463
423
  EnrichedTextInputViewHtmlStyleOlStruct ol{};
464
424
  EnrichedTextInputViewHtmlStyleUlStruct ul{};
465
425
 
@@ -476,7 +436,6 @@ struct EnrichedTextInputViewHtmlStyleStruct {
476
436
  result["code"] = ::facebook::react::toDynamic(code);
477
437
  result["a"] = ::facebook::react::toDynamic(a);
478
438
  result["mention"] = mention;
479
- result["img"] = ::facebook::react::toDynamic(img);
480
439
  result["ol"] = ::facebook::react::toDynamic(ol);
481
440
  result["ul"] = ::facebook::react::toDynamic(ul);
482
441
  return result;
@@ -519,10 +478,6 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
519
478
  if (tmp_mention != map.end()) {
520
479
  fromRawValue(context, tmp_mention->second, result.mention);
521
480
  }
522
- auto tmp_img = map.find("img");
523
- if (tmp_img != map.end()) {
524
- fromRawValue(context, tmp_img->second, result.img);
525
- }
526
481
  auto tmp_ol = map.find("ol");
527
482
  if (tmp_ol != map.end()) {
528
483
  fromRawValue(context, tmp_ol->second, result.ol);
@@ -30,9 +30,10 @@ NS_ASSUME_NONNULL_BEGIN
30
30
  - (void)toggleOrderedList;
31
31
  - (void)toggleUnorderedList;
32
32
  - (void)addLink:(NSInteger)start end:(NSInteger)end text:(NSString *)text url:(NSString *)url;
33
- - (void)addImage:(NSString *)uri;
33
+ - (void)addImage:(NSString *)uri width:(float)width height:(float)height;
34
34
  - (void)startMention:(NSString *)indicator;
35
35
  - (void)addMention:(NSString *)indicator text:(NSString *)text payload:(NSString *)payload;
36
+ - (void)requestHTML:(NSInteger)requestId;
36
37
  @end
37
38
 
38
39
  RCT_EXTERN inline void RCTEnrichedTextInputViewHandleCommand(
@@ -302,8 +303,8 @@ NSObject *arg3 = args[3];
302
303
 
303
304
  if ([commandName isEqualToString:@"addImage"]) {
304
305
  #if RCT_DEBUG
305
- if ([args count] != 1) {
306
- RCTLogError(@"%@ command %@ received %d arguments, expected %d.", @"EnrichedTextInputView", commandName, (int)[args count], 1);
306
+ if ([args count] != 3) {
307
+ RCTLogError(@"%@ command %@ received %d arguments, expected %d.", @"EnrichedTextInputView", commandName, (int)[args count], 3);
307
308
  return;
308
309
  }
309
310
  #endif
@@ -316,7 +317,23 @@ if ([commandName isEqualToString:@"addImage"]) {
316
317
  #endif
317
318
  NSString * uri = (NSString *)arg0;
318
319
 
319
- [componentView addImage:uri];
320
+ NSObject *arg1 = args[1];
321
+ #if RCT_DEBUG
322
+ if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSNumber class], @"float", @"EnrichedTextInputView", commandName, @"2nd")) {
323
+ return;
324
+ }
325
+ #endif
326
+ float width = [(NSNumber *)arg1 floatValue];
327
+
328
+ NSObject *arg2 = args[2];
329
+ #if RCT_DEBUG
330
+ if (!RCTValidateTypeOfViewCommandArgument(arg2, [NSNumber class], @"float", @"EnrichedTextInputView", commandName, @"3rd")) {
331
+ return;
332
+ }
333
+ #endif
334
+ float height = [(NSNumber *)arg2 floatValue];
335
+
336
+ [componentView addImage:uri width:width height:height];
320
337
  return;
321
338
  }
322
339
 
@@ -376,6 +393,26 @@ NSObject *arg2 = args[2];
376
393
  return;
377
394
  }
378
395
 
396
+ if ([commandName isEqualToString:@"requestHTML"]) {
397
+ #if RCT_DEBUG
398
+ if ([args count] != 1) {
399
+ RCTLogError(@"%@ command %@ received %d arguments, expected %d.", @"EnrichedTextInputView", commandName, (int)[args count], 1);
400
+ return;
401
+ }
402
+ #endif
403
+
404
+ NSObject *arg0 = args[0];
405
+ #if RCT_DEBUG
406
+ if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"number", @"EnrichedTextInputView", commandName, @"1st")) {
407
+ return;
408
+ }
409
+ #endif
410
+ NSInteger requestId = [(NSNumber *)arg0 intValue];
411
+
412
+ [componentView requestHTML:requestId];
413
+ return;
414
+ }
415
+
379
416
  #if RCT_DEBUG
380
417
  RCTLogError(@"%@ received command %@, which is not a supported command.", @"EnrichedTextInputView", commandName);
381
418
  #endif
@@ -3,9 +3,9 @@
3
3
 
4
4
  @interface InputParser : NSObject
5
5
  - (instancetype _Nonnull)initWithInput:(id _Nonnull)input;
6
- - (NSString * _Nonnull)parseToHtmlFromRange:(NSRange)range;
7
- - (void)replaceWholeFromHtml:(NSString * _Nonnull)html;
8
- - (void)replaceFromHtml:(NSString * _Nonnull)html range:(NSRange)range;
9
- - (void)insertFromHtml:(NSString * _Nonnull)html location:(NSInteger)location;
10
- - (NSString * _Nullable)initiallyProcessHtml:(NSString * _Nonnull)html;
6
+ - (NSString *_Nonnull)parseToHtmlFromRange:(NSRange)range;
7
+ - (void)replaceWholeFromHtml:(NSString *_Nonnull)html;
8
+ - (void)replaceFromHtml:(NSString *_Nonnull)html range:(NSRange)range;
9
+ - (void)insertFromHtml:(NSString *_Nonnull)html location:(NSInteger)location;
10
+ - (NSString *_Nullable)initiallyProcessHtml:(NSString *_Nonnull)html;
11
11
  @end