react-native-enriched 0.2.0 → 0.3.0

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 (186) hide show
  1. package/README.md +16 -17
  2. package/android/build.gradle +77 -72
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
  5. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
  6. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
  7. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
  8. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +194 -0
  9. package/android/lint.gradle +70 -0
  10. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputConnectionWrapper.kt +140 -0
  11. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +304 -83
  12. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt +3 -1
  13. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +166 -51
  14. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +1 -3
  15. package/android/src/main/java/com/swmansion/enriched/MeasurementStore.kt +70 -21
  16. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +21 -11
  17. package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +8 -9
  18. package/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt +10 -9
  19. package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +21 -0
  20. package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +9 -12
  21. package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +10 -10
  22. package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +7 -9
  23. package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +7 -9
  24. package/android/src/main/java/com/swmansion/enriched/events/OnInputKeyPressEvent.kt +27 -0
  25. package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +13 -11
  26. package/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt +10 -9
  27. package/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt +9 -8
  28. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +32 -0
  29. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +24 -5
  30. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +8 -1
  31. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +10 -2
  32. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +8 -1
  33. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +8 -1
  34. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +8 -1
  35. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +24 -0
  36. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +24 -0
  37. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +24 -0
  38. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +34 -17
  39. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +8 -1
  40. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +7 -1
  41. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +10 -4
  42. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +14 -11
  43. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +18 -11
  44. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +174 -72
  45. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +7 -1
  46. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +7 -1
  47. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +11 -5
  48. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +3 -2
  49. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +1 -2
  50. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +1 -2
  51. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +3 -2
  52. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +5 -0
  53. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -2
  54. package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +2 -1
  55. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +155 -20
  56. package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +25 -8
  57. package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +60 -20
  58. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +161 -25
  59. package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +128 -52
  60. package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +10 -7
  61. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedConstants.kt +11 -0
  62. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedEditableFactory.kt +17 -0
  63. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +136 -87
  64. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +71 -42
  65. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +183 -48
  66. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannable.kt +82 -0
  67. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannableStringBuilder.kt +15 -0
  68. package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -70
  69. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +46 -14
  70. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +34 -11
  71. package/android/src/main/new_arch/CMakeLists.txt +6 -0
  72. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  73. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  74. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  75. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  76. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  77. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  78. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  79. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  80. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  81. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +33 -14
  82. package/ios/EnrichedTextInputView.h +26 -14
  83. package/ios/EnrichedTextInputView.mm +1209 -586
  84. package/ios/config/InputConfig.h +24 -6
  85. package/ios/config/InputConfig.mm +154 -38
  86. package/ios/{utils → extensions}/ColorExtension.mm +7 -5
  87. package/ios/extensions/FontExtension.mm +106 -0
  88. package/ios/{utils → extensions}/LayoutManagerExtension.h +1 -1
  89. package/ios/extensions/LayoutManagerExtension.mm +396 -0
  90. package/ios/{utils → extensions}/StringExtension.mm +19 -16
  91. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
  92. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
  93. package/ios/generated/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
  94. package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +194 -0
  95. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +95 -0
  96. package/ios/inputParser/InputParser.h +5 -5
  97. package/ios/inputParser/InputParser.mm +864 -380
  98. package/ios/inputTextView/InputTextView.h +1 -1
  99. package/ios/inputTextView/InputTextView.mm +100 -59
  100. package/ios/{utils → interfaces}/BaseStyleProtocol.h +2 -2
  101. package/ios/interfaces/ImageAttachment.h +10 -0
  102. package/ios/interfaces/ImageAttachment.mm +36 -0
  103. package/ios/interfaces/LinkRegexConfig.h +19 -0
  104. package/ios/interfaces/LinkRegexConfig.mm +37 -0
  105. package/ios/interfaces/MediaAttachment.h +23 -0
  106. package/ios/interfaces/MediaAttachment.mm +31 -0
  107. package/ios/{utils → interfaces}/MentionParams.h +0 -1
  108. package/ios/{utils → interfaces}/MentionStyleProps.mm +27 -20
  109. package/ios/{utils → interfaces}/StyleHeaders.h +37 -15
  110. package/ios/{utils → interfaces}/StyleTypeEnum.h +3 -0
  111. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  112. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
  113. package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
  114. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  115. package/ios/styles/BlockQuoteStyle.mm +189 -118
  116. package/ios/styles/BoldStyle.mm +110 -63
  117. package/ios/styles/CodeBlockStyle.mm +204 -128
  118. package/ios/styles/H1Style.mm +10 -4
  119. package/ios/styles/H2Style.mm +10 -4
  120. package/ios/styles/H3Style.mm +10 -4
  121. package/ios/styles/H4Style.mm +17 -0
  122. package/ios/styles/H5Style.mm +17 -0
  123. package/ios/styles/H6Style.mm +17 -0
  124. package/ios/styles/HeadingStyleBase.mm +148 -86
  125. package/ios/styles/ImageStyle.mm +75 -73
  126. package/ios/styles/InlineCodeStyle.mm +162 -88
  127. package/ios/styles/ItalicStyle.mm +76 -52
  128. package/ios/styles/LinkStyle.mm +411 -232
  129. package/ios/styles/MentionStyle.mm +363 -246
  130. package/ios/styles/OrderedListStyle.mm +171 -106
  131. package/ios/styles/StrikethroughStyle.mm +52 -35
  132. package/ios/styles/UnderlineStyle.mm +68 -46
  133. package/ios/styles/UnorderedListStyle.mm +169 -106
  134. package/ios/utils/OccurenceUtils.h +42 -42
  135. package/ios/utils/OccurenceUtils.mm +142 -119
  136. package/ios/utils/ParagraphAttributesUtils.h +10 -2
  137. package/ios/utils/ParagraphAttributesUtils.mm +182 -71
  138. package/ios/utils/ParagraphsUtils.h +2 -1
  139. package/ios/utils/ParagraphsUtils.mm +41 -27
  140. package/ios/utils/TextInsertionUtils.h +13 -2
  141. package/ios/utils/TextInsertionUtils.mm +38 -20
  142. package/ios/utils/WordsUtils.h +2 -1
  143. package/ios/utils/WordsUtils.mm +32 -22
  144. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  145. package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
  146. package/lib/module/EnrichedTextInput.js +61 -2
  147. package/lib/module/EnrichedTextInput.js.map +1 -1
  148. package/lib/module/EnrichedTextInputNativeComponent.ts +149 -12
  149. package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +12 -0
  150. package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
  151. package/lib/module/utils/regexParser.js +46 -0
  152. package/lib/module/utils/regexParser.js.map +1 -0
  153. package/lib/typescript/src/EnrichedTextInput.d.ts +24 -14
  154. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  155. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +129 -12
  156. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  157. package/lib/typescript/src/index.d.ts +1 -1
  158. package/lib/typescript/src/index.d.ts.map +1 -1
  159. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
  160. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
  161. package/lib/typescript/src/utils/regexParser.d.ts +3 -0
  162. package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
  163. package/package.json +17 -6
  164. package/src/EnrichedTextInput.tsx +96 -13
  165. package/src/EnrichedTextInputNativeComponent.ts +149 -12
  166. package/src/index.tsx +2 -0
  167. package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +14 -2
  168. package/src/utils/regexParser.ts +56 -0
  169. package/ios/utils/FontExtension.mm +0 -91
  170. package/ios/utils/LayoutManagerExtension.mm +0 -286
  171. package/lib/module/normalizeHtmlStyle.js.map +0 -1
  172. package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
  173. package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
  174. package/ios/{utils → extensions}/ColorExtension.h +0 -0
  175. package/ios/{utils → extensions}/FontExtension.h +0 -0
  176. package/ios/{utils → extensions}/StringExtension.h +1 -1
  177. package/ios/{utils → interfaces}/ImageData.h +0 -0
  178. package/ios/{utils → interfaces}/ImageData.mm +0 -0
  179. package/ios/{utils → interfaces}/LinkData.h +0 -0
  180. package/ios/{utils → interfaces}/LinkData.mm +0 -0
  181. package/ios/{utils → interfaces}/MentionParams.mm +0 -0
  182. package/ios/{utils → interfaces}/MentionStyleProps.h +1 -1
  183. /package/ios/{utils → interfaces}/StylePair.h +0 -0
  184. /package/ios/{utils → interfaces}/StylePair.mm +0 -0
  185. /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
  186. /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
@@ -2,5 +2,5 @@
2
2
  #import <UIkit/UIKit.h>
3
3
 
4
4
  @interface InputTextView : UITextView
5
- @property (nonatomic, weak) id input;
5
+ @property(nonatomic, weak) id input;
6
6
  @end
@@ -1,114 +1,155 @@
1
1
  #import "InputTextView.h"
2
2
  #import "EnrichedTextInputView.h"
3
3
  #import "StringExtension.h"
4
- #import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
5
4
  #import "TextInsertionUtils.h"
5
+ #import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
6
6
 
7
7
  @implementation InputTextView
8
8
 
9
9
  - (void)copy:(id)sender {
10
10
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input;
11
- if(typedInput == nullptr) { return; }
12
-
11
+ if (typedInput == nullptr) {
12
+ return;
13
+ }
14
+
13
15
  // remove zero width spaces before copying the text
14
- NSString *plainText = [typedInput->textView.textStorage.string substringWithRange:typedInput->textView.selectedRange];
15
- NSString *fixedPlainText = [plainText stringByReplacingOccurrencesOfString:@"\u200B" withString:@""];
16
-
17
- NSString *parsedHtml = [typedInput->parser parseToHtmlFromRange:typedInput->textView.selectedRange];
18
-
19
- NSMutableAttributedString *attrStr = [[typedInput->textView.textStorage attributedSubstringFromRange:typedInput->textView.selectedRange] mutableCopy];
16
+ NSString *plainText = [typedInput->textView.textStorage.string
17
+ substringWithRange:typedInput->textView.selectedRange];
18
+ NSString *fixedPlainText =
19
+ [plainText stringByReplacingOccurrencesOfString:@"\u200B" withString:@""];
20
+
21
+ NSString *parsedHtml = [typedInput->parser
22
+ parseToHtmlFromRange:typedInput->textView.selectedRange];
23
+
24
+ NSMutableAttributedString *attrStr = [[typedInput->textView.textStorage
25
+ attributedSubstringFromRange:typedInput->textView.selectedRange]
26
+ mutableCopy];
20
27
  NSRange fullAttrStrRange = NSMakeRange(0, attrStr.length);
21
- [attrStr.mutableString replaceOccurrencesOfString:@"\u200B" withString:@"" options:0 range:fullAttrStrRange];
22
-
23
- NSData *rtfData = [attrStr dataFromRange:NSMakeRange(0, attrStr.length)
24
- documentAttributes:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType}
25
- error:nullptr
26
- ];
27
-
28
+ [attrStr.mutableString replaceOccurrencesOfString:@"\u200B"
29
+ withString:@""
30
+ options:0
31
+ range:fullAttrStrRange];
32
+
33
+ NSData *rtfData =
34
+ [attrStr dataFromRange:NSMakeRange(0, attrStr.length)
35
+ documentAttributes:@{
36
+ NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType
37
+ }
38
+ error:nullptr];
39
+
28
40
  UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
29
- [pasteboard setItems:@[@{
30
- UTTypeUTF8PlainText.identifier : fixedPlainText,
31
- UTTypeHTML.identifier : parsedHtml,
32
- UTTypeRTF.identifier : rtfData
33
- }]];
41
+ [pasteboard setItems:@[ @{
42
+ UTTypeUTF8PlainText.identifier : fixedPlainText,
43
+ UTTypeHTML.identifier : parsedHtml,
44
+ UTTypeRTF.identifier : rtfData
45
+ } ]];
34
46
  }
35
47
 
36
48
  - (void)paste:(id)sender {
37
49
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input;
38
- if(typedInput == nullptr) { return; }
50
+ if (typedInput == nullptr) {
51
+ return;
52
+ }
39
53
 
40
54
  UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
41
55
  NSArray<NSString *> *pasteboardTypes = pasteboard.pasteboardTypes;
42
56
  NSRange currentRange = typedInput->textView.selectedRange;
43
-
44
- if([pasteboardTypes containsObject:UTTypeHTML.identifier]) {
57
+
58
+ if ([pasteboardTypes containsObject:UTTypeHTML.identifier]) {
45
59
  // we try processing the html contents
46
-
60
+
47
61
  NSString *htmlString;
48
62
  id htmlValue = [pasteboard valueForPasteboardType:UTTypeHTML.identifier];
49
-
50
- if([htmlValue isKindOfClass:[NSData class]]) {
51
- htmlString = [[NSString alloc]initWithData:htmlValue encoding:NSUTF8StringEncoding];
52
- } else if([htmlValue isKindOfClass:[NSString class]]) {
63
+
64
+ if ([htmlValue isKindOfClass:[NSData class]]) {
65
+ htmlString = [[NSString alloc] initWithData:htmlValue
66
+ encoding:NSUTF8StringEncoding];
67
+ } else if ([htmlValue isKindOfClass:[NSString class]]) {
53
68
  htmlString = htmlValue;
54
69
  }
55
-
70
+
56
71
  // validate the html
57
- NSString *initiallyProcessedHtml = [typedInput->parser initiallyProcessHtml:htmlString];
58
-
59
- if(initiallyProcessedHtml != nullptr) {
72
+ NSString *initiallyProcessedHtml =
73
+ [typedInput->parser initiallyProcessHtml:htmlString];
74
+
75
+ if (initiallyProcessedHtml != nullptr) {
60
76
  // valid html, let's apply it
61
77
  currentRange.length > 0
62
- ? [typedInput->parser replaceFromHtml:initiallyProcessedHtml range:currentRange]
63
- : [typedInput->parser insertFromHtml:initiallyProcessedHtml location:currentRange.location];
78
+ ? [typedInput->parser replaceFromHtml:initiallyProcessedHtml
79
+ range:currentRange]
80
+ : [typedInput->parser insertFromHtml:initiallyProcessedHtml
81
+ location:currentRange.location];
64
82
  } else {
65
83
  // fall back to plain text, otherwise do nothing
66
- [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange input:typedInput];
84
+ [self tryHandlingPlainTextItemsIn:pasteboard
85
+ range:currentRange
86
+ input:typedInput];
67
87
  }
68
88
  } else {
69
- [self tryHandlingPlainTextItemsIn:pasteboard range:currentRange input:typedInput];
89
+ [self tryHandlingPlainTextItemsIn:pasteboard
90
+ range:currentRange
91
+ input:typedInput];
70
92
  }
71
-
93
+
72
94
  [typedInput anyTextMayHaveBeenModified];
73
95
  }
74
96
 
75
- - (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard range:(NSRange)range input:(EnrichedTextInputView *)input {
97
+ - (void)tryHandlingPlainTextItemsIn:(UIPasteboard *)pasteboard
98
+ range:(NSRange)range
99
+ input:(EnrichedTextInputView *)input {
76
100
  NSArray *existingTypes = pasteboard.pasteboardTypes;
77
- NSArray *handledTypes = @[UTTypeUTF8PlainText.identifier, UTTypePlainText.identifier, UTTypeURL.identifier];
101
+ NSArray *handledTypes = @[
102
+ UTTypeUTF8PlainText.identifier, UTTypePlainText.identifier,
103
+ UTTypeURL.identifier
104
+ ];
78
105
  NSString *plainText;
79
-
80
- for(NSString *type in handledTypes) {
81
- if(![existingTypes containsObject:type]) {
106
+
107
+ for (NSString *type in handledTypes) {
108
+ if (![existingTypes containsObject:type]) {
82
109
  continue;
83
110
  }
84
-
111
+
85
112
  id value = [pasteboard valueForPasteboardType:type];
86
-
87
- if([value isKindOfClass:[NSData class]]) {
88
- plainText = [[NSString alloc]initWithData:value encoding:NSUTF8StringEncoding];
89
- } else if([value isKindOfClass:[NSString class]]) {
113
+
114
+ if ([value isKindOfClass:[NSData class]]) {
115
+ plainText = [[NSString alloc] initWithData:value
116
+ encoding:NSUTF8StringEncoding];
117
+ } else if ([value isKindOfClass:[NSString class]]) {
90
118
  plainText = (NSString *)value;
91
- } else if([value isKindOfClass:[NSURL class]]) {
119
+ } else if ([value isKindOfClass:[NSURL class]]) {
92
120
  plainText = [(NSURL *)value absoluteString];
93
121
  }
94
122
  }
95
-
96
- if(!plainText) {
123
+
124
+ if (!plainText) {
97
125
  return;
98
126
  }
99
-
100
- range.length > 0
101
- ? [TextInsertionUtils replaceText:plainText at:range additionalAttributes:nullptr input:input withSelection:YES]
102
- : [TextInsertionUtils insertText:plainText at:range.location additionalAttributes:nullptr input:input withSelection:YES];
127
+
128
+ range.length > 0 ? [TextInsertionUtils replaceText:plainText
129
+ at:range
130
+ additionalAttributes:nullptr
131
+ input:input
132
+ withSelection:YES]
133
+ : [TextInsertionUtils insertText:plainText
134
+ at:range.location
135
+ additionalAttributes:nullptr
136
+ input:input
137
+ withSelection:YES];
103
138
  }
104
139
 
105
140
  - (void)cut:(id)sender {
106
141
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)_input;
107
- if(typedInput == nullptr) { return; }
108
-
142
+ if (typedInput == nullptr) {
143
+ return;
144
+ }
145
+
109
146
  [self copy:sender];
110
- [TextInsertionUtils replaceText:@"" at:typedInput->textView.selectedRange additionalAttributes:nullptr input:typedInput withSelection:YES];
111
-
147
+ [TextInsertionUtils replaceText:@""
148
+ at:typedInput->textView.selectedRange
149
+ additionalAttributes:nullptr
150
+ input:typedInput
151
+ withSelection:YES];
152
+
112
153
  [typedInput anyTextMayHaveBeenModified];
113
154
  }
114
155
 
@@ -1,13 +1,13 @@
1
1
  #pragma once
2
- #import "StyleTypeEnum.h"
3
2
  #import "StylePair.h"
3
+ #import "StyleTypeEnum.h"
4
4
 
5
5
  @protocol BaseStyleProtocol <NSObject>
6
6
  + (StyleType)getStyleType;
7
7
  + (BOOL)isParagraphStyle;
8
8
  - (instancetype _Nonnull)initWithInput:(id _Nonnull)input;
9
9
  - (void)applyStyle:(NSRange)range;
10
- - (void)addAttributes:(NSRange)range;
10
+ - (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr;
11
11
  - (void)removeAttributes:(NSRange)range;
12
12
  - (void)addTypingAttributes;
13
13
  - (void)removeTypingAttributes;
@@ -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,36 @@
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
+ self.image = [UIImage systemImageNamed:@"file"];
21
+ return;
22
+ }
23
+
24
+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
25
+ NSData *bytes = [NSData dataWithContentsOfURL:url];
26
+ UIImage *img = bytes ? [UIImage imageWithData:bytes]
27
+ : [UIImage systemImageNamed:@"file"];
28
+
29
+ dispatch_async(dispatch_get_main_queue(), ^{
30
+ self.image = img;
31
+ [self notifyUpdate];
32
+ });
33
+ });
34
+ }
35
+
36
+ @end
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+ #import <ReactNativeEnriched/Props.h>
3
+ #import <UIKit/UIKit.h>
4
+
5
+ using namespace facebook::react;
6
+
7
+ @interface LinkRegexConfig : NSObject
8
+
9
+ @property NSString *pattern;
10
+ @property BOOL caseInsensitive;
11
+ @property BOOL dotAll;
12
+ @property BOOL isDisabled;
13
+ @property BOOL isDefault;
14
+
15
+ - (instancetype)initWithLinkRegexProp:
16
+ (EnrichedTextInputViewLinkRegexStruct)prop;
17
+ - (BOOL)isEqualToConfig:(LinkRegexConfig *)otherObj;
18
+
19
+ @end
@@ -0,0 +1,37 @@
1
+ #import "LinkRegexConfig.h"
2
+ #import "StringExtension.h"
3
+
4
+ @implementation LinkRegexConfig
5
+
6
+ - (instancetype)initWithLinkRegexProp:
7
+ (EnrichedTextInputViewLinkRegexStruct)prop {
8
+ if (!self)
9
+ return nil;
10
+
11
+ _pattern = [NSString fromCppString:prop.pattern];
12
+ _caseInsensitive = prop.caseInsensitive;
13
+ _dotAll = prop.dotAll;
14
+ _isDefault = prop.isDefault;
15
+ _isDisabled = prop.isDisabled;
16
+
17
+ return self;
18
+ }
19
+
20
+ - (id)copyWithZone:(NSZone *)zone {
21
+ LinkRegexConfig *copy = [[[self class] allocWithZone:zone] init];
22
+ copy->_pattern = [_pattern copy];
23
+ copy->_caseInsensitive = _caseInsensitive;
24
+ copy->_dotAll = _dotAll;
25
+ copy->_isDefault = _isDefault;
26
+ copy->_isDisabled = _isDisabled;
27
+ return copy;
28
+ }
29
+
30
+ - (BOOL)isEqualToConfig:(LinkRegexConfig *)otherObj {
31
+ return [_pattern isEqualToString:otherObj.pattern] &&
32
+ _caseInsensitive == otherObj.caseInsensitive &&
33
+ _dotAll == otherObj.dotAll && _isDefault == otherObj.isDefault &&
34
+ _isDisabled == otherObj.isDisabled;
35
+ }
36
+
37
+ @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
@@ -6,4 +6,3 @@
6
6
  @property NSString *indicator;
7
7
  @property NSString *attributes;
8
8
  @end
9
-
@@ -1,56 +1,63 @@
1
1
  #import "MentionStyleProps.h"
2
- #import <React/RCTConversions.h>
3
2
  #import "StringExtension.h"
3
+ #import <React/RCTConversions.h>
4
4
 
5
5
  @implementation MentionStyleProps
6
6
 
7
- + (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic:(folly::dynamic)folly {
7
+ + (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic:
8
+ (folly::dynamic)folly {
8
9
  MentionStyleProps *nativeProps = [[MentionStyleProps alloc] init];
9
-
10
- if(folly["color"].isNumber()) {
11
- facebook::react::SharedColor color = facebook::react::SharedColor(facebook::react::Color(folly["color"].asInt()));
10
+
11
+ if (folly["color"].isNumber()) {
12
+ facebook::react::SharedColor color = facebook::react::SharedColor(
13
+ facebook::react::Color(int32_t(folly["color"].asInt())));
12
14
  nativeProps.color = RCTUIColorFromSharedColor(color);
13
15
  } else {
14
16
  nativeProps.color = [UIColor blueColor];
15
17
  }
16
-
17
- if(folly["backgroundColor"].isNumber()) {
18
- facebook::react::SharedColor bgColor = facebook::react::SharedColor(facebook::react::Color(folly["backgroundColor"].asInt()));
18
+
19
+ if (folly["backgroundColor"].isNumber()) {
20
+ facebook::react::SharedColor bgColor = facebook::react::SharedColor(
21
+ facebook::react::Color(int32_t(folly["backgroundColor"].asInt())));
19
22
  nativeProps.backgroundColor = RCTUIColorFromSharedColor(bgColor);
20
23
  } else {
21
24
  nativeProps.backgroundColor = [UIColor yellowColor];
22
25
  }
23
-
24
- if(folly["textDecorationLine"].isString()) {
26
+
27
+ if (folly["textDecorationLine"].isString()) {
25
28
  std::string textDecorationLine = folly["textDecorationLine"].asString();
26
- nativeProps.decorationLine = [[NSString fromCppString:textDecorationLine] isEqualToString:DecorationUnderline] ? DecorationUnderline : DecorationNone;
29
+ nativeProps.decorationLine = [[NSString fromCppString:textDecorationLine]
30
+ isEqualToString:DecorationUnderline]
31
+ ? DecorationUnderline
32
+ : DecorationNone;
27
33
  } else {
28
34
  nativeProps.decorationLine = DecorationUnderline;
29
35
  }
30
-
36
+
31
37
  return nativeProps;
32
38
  }
33
39
 
34
40
  + (NSDictionary *)getSinglePropsFromFollyDynamic:(folly::dynamic)folly {
35
- MentionStyleProps *nativeProps = [MentionStyleProps getSingleMentionStylePropsFromFollyDynamic:folly];
41
+ MentionStyleProps *nativeProps =
42
+ [MentionStyleProps getSingleMentionStylePropsFromFollyDynamic:folly];
36
43
  // the single props need to be somehow distinguishable in config
37
- NSDictionary *dict = @{@"all": nativeProps};
44
+ NSDictionary *dict = @{@"all" : nativeProps};
38
45
  return dict;
39
46
  }
40
47
 
41
48
  + (NSDictionary *)getComplexPropsFromFollyDynamic:(folly::dynamic)folly {
42
49
  NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
43
-
44
- for(const auto& obj: folly.items()) {
45
- if(obj.first.isString() && obj.second.isObject()) {
50
+
51
+ for (const auto &obj : folly.items()) {
52
+ if (obj.first.isString() && obj.second.isObject()) {
46
53
  std::string key = obj.first.asString();
47
- MentionStyleProps *props = [MentionStyleProps getSingleMentionStylePropsFromFollyDynamic:obj.second];
54
+ MentionStyleProps *props = [MentionStyleProps
55
+ getSingleMentionStylePropsFromFollyDynamic:obj.second];
48
56
  dict[[NSString fromCppString:key]] = props;
49
57
  }
50
58
  }
51
-
59
+
52
60
  return dict;
53
61
  }
54
62
 
55
63
  @end
56
-
@@ -1,8 +1,8 @@
1
1
  #pragma once
2
2
  #import "BaseStyleProtocol.h"
3
+ #import "ImageData.h"
3
4
  #import "LinkData.h"
4
5
  #import "MentionParams.h"
5
- #import "ImageData.h"
6
6
 
7
7
  @interface BoldStyle : NSObject <BaseStyleProtocol>
8
8
  @end
@@ -21,35 +21,44 @@
21
21
  @end
22
22
 
23
23
  @interface LinkStyle : NSObject <BaseStyleProtocol>
24
- - (void)addLink:(NSString*)text url:(NSString*)url range:(NSRange)range manual:(BOOL)manual;
24
+ - (void)addLink:(NSString *)text
25
+ url:(NSString *)url
26
+ range:(NSRange)range
27
+ manual:(BOOL)manual
28
+ withSelection:(BOOL)withSelection;
25
29
  - (LinkData *)getLinkDataAt:(NSUInteger)location;
26
30
  - (NSRange)getFullLinkRangeAt:(NSUInteger)location;
27
31
  - (void)manageLinkTypingAttributes;
28
32
  - (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange;
29
33
  - (void)handleManualLinks:(NSString *)word inRange:(NSRange)wordRange;
30
- - (BOOL)handleLeadingLinkReplacement:(NSRange)range replacementText:(NSString *)text;
34
+ - (BOOL)handleLeadingLinkReplacement:(NSRange)range
35
+ replacementText:(NSString *)text;
31
36
  @end
32
37
 
33
- @interface MentionStyle : NSObject<BaseStyleProtocol>
34
- - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSString *)attributes;
38
+ @interface MentionStyle : NSObject <BaseStyleProtocol>
39
+ - (void)addMention:(NSString *)indicator
40
+ text:(NSString *)text
41
+ attributes:(NSString *)attributes;
35
42
  - (void)addMentionAtRange:(NSRange)range params:(MentionParams *)params;
36
43
  - (void)startMentionWithIndicator:(NSString *)indicator;
37
44
  - (void)handleExistingMentions;
38
45
  - (void)manageMentionEditing;
39
46
  - (void)manageMentionTypingAttributes;
40
- - (BOOL)handleLeadingMentionReplacement:(NSRange)range replacementText:(NSString *)text;
47
+ - (BOOL)handleLeadingMentionReplacement:(NSRange)range
48
+ replacementText:(NSString *)text;
41
49
  - (MentionParams *)getMentionParamsAt:(NSUInteger)location;
42
50
  - (NSRange)getFullMentionRangeAt:(NSUInteger)location;
43
51
  - (NSValue *)getActiveMentionRange;
44
52
  @end
45
53
 
46
- @interface HeadingStyleBase : NSObject<BaseStyleProtocol> {
54
+ @interface HeadingStyleBase : NSObject <BaseStyleProtocol> {
47
55
  id input;
48
56
  }
49
57
  - (CGFloat)getHeadingFontSize;
50
58
  - (BOOL)isHeadingBold;
51
59
  - (BOOL)handleNewlinesInRange:(NSRange)range replacementText:(NSString *)text;
52
60
  - (void)handleImproperHeadings;
61
+ @property(nonatomic, assign) CGFloat lastAppliedFontSize;
53
62
  @end
54
63
 
55
64
  @interface H1Style : HeadingStyleBase
@@ -61,28 +70,41 @@
61
70
  @interface H3Style : HeadingStyleBase
62
71
  @end
63
72
 
64
- @interface UnorderedListStyle : NSObject<BaseStyleProtocol>
73
+ @interface H4Style : HeadingStyleBase
74
+ @end
75
+
76
+ @interface H5Style : HeadingStyleBase
77
+ @end
78
+
79
+ @interface H6Style : HeadingStyleBase
80
+ @end
81
+
82
+ @interface UnorderedListStyle : NSObject <BaseStyleProtocol>
65
83
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
66
- - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text;
84
+ - (BOOL)tryHandlingListShorcutInRange:(NSRange)range
85
+ replacementText:(NSString *)text;
67
86
  @end
68
87
 
69
- @interface OrderedListStyle : NSObject<BaseStyleProtocol>
88
+ @interface OrderedListStyle : NSObject <BaseStyleProtocol>
70
89
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
71
- - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text;
90
+ - (BOOL)tryHandlingListShorcutInRange:(NSRange)range
91
+ replacementText:(NSString *)text;
72
92
  @end
73
93
 
74
- @interface BlockQuoteStyle : NSObject<BaseStyleProtocol>
94
+ @interface BlockQuoteStyle : NSObject <BaseStyleProtocol>
75
95
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
76
96
  - (void)manageBlockquoteColor;
77
97
  @end
78
98
 
79
- @interface CodeBlockStyle : NSObject<BaseStyleProtocol>
99
+ @interface CodeBlockStyle : NSObject <BaseStyleProtocol>
80
100
  - (void)manageCodeBlockFontAndColor;
81
101
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
82
102
  @end
83
103
 
84
- @interface ImageStyle : NSObject<BaseStyleProtocol>
104
+ @interface ImageStyle : NSObject <BaseStyleProtocol>
85
105
  - (void)addImage:(NSString *)uri width:(CGFloat)width height:(CGFloat)height;
86
- - (void)addImageAtRange:(NSRange)range imageData:(ImageData *)imageData withSelection:(BOOL)withSelection;
106
+ - (void)addImageAtRange:(NSRange)range
107
+ imageData:(ImageData *)imageData
108
+ withSelection:(BOOL)withSelection;
87
109
  - (ImageData *)getImageDataAt:(NSUInteger)location;
88
110
  @end
@@ -10,6 +10,9 @@ typedef NS_ENUM(NSInteger, StyleType) {
10
10
  H1,
11
11
  H2,
12
12
  H3,
13
+ H4,
14
+ H5,
15
+ H6,
13
16
  Link,
14
17
  Mention,
15
18
  Image,
@@ -1,17 +1,19 @@
1
1
  #pragma once
2
- #include <react/debug/react_native_assert.h>
2
+ #include <ReactNativeEnriched/EnrichedTextInputViewShadowNode.h>
3
3
  #include <ReactNativeEnriched/Props.h>
4
+ #include <react/debug/react_native_assert.h>
4
5
  #include <react/renderer/core/ConcreteComponentDescriptor.h>
5
- #include <ReactNativeEnriched/EnrichedTextInputViewShadowNode.h>
6
6
 
7
7
  namespace facebook::react {
8
- class EnrichedTextInputViewComponentDescriptor final : public ConcreteComponentDescriptor<EnrichedTextInputViewShadowNode> {
9
- public:
10
- using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
11
- void adopt(ShadowNode &shadowNode) const override {
12
- react_native_assert(dynamic_cast<EnrichedTextInputViewShadowNode *>(&shadowNode));
13
- ConcreteComponentDescriptor::adopt(shadowNode);
14
- }
8
+ class EnrichedTextInputViewComponentDescriptor final
9
+ : public ConcreteComponentDescriptor<EnrichedTextInputViewShadowNode> {
10
+ public:
11
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
12
+ void adopt(ShadowNode &shadowNode) const override {
13
+ react_native_assert(
14
+ dynamic_cast<EnrichedTextInputViewShadowNode *>(&shadowNode));
15
+ ConcreteComponentDescriptor::adopt(shadowNode);
16
+ }
15
17
  };
16
18
 
17
19
  } // namespace facebook::react