react-native-enriched 0.2.0 → 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 (107) hide show
  1. package/README.md +1 -5
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
  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/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +92 -0
  7. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +6 -0
  8. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
  9. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
  10. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
  11. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
  12. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +6 -0
  13. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
  14. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
  15. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
  16. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +5 -0
  17. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
  18. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
  19. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
  20. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
  21. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
  22. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +9 -3
  23. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
  24. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
  25. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
  26. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
  27. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +78 -0
  28. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +80 -4
  29. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +8 -0
  30. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  31. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  32. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  33. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  34. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  35. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  36. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  37. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  38. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  39. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +12 -13
  40. package/ios/EnrichedTextInputView.h +25 -13
  41. package/ios/EnrichedTextInputView.mm +872 -581
  42. package/ios/attachments/ImageAttachment.h +10 -0
  43. package/ios/attachments/ImageAttachment.mm +34 -0
  44. package/ios/attachments/MediaAttachment.h +23 -0
  45. package/ios/attachments/MediaAttachment.mm +31 -0
  46. package/ios/config/InputConfig.h +6 -6
  47. package/ios/config/InputConfig.mm +39 -33
  48. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  49. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  50. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +21 -0
  51. package/ios/inputParser/InputParser.h +5 -5
  52. package/ios/inputParser/InputParser.mm +789 -378
  53. package/ios/inputTextView/InputTextView.h +1 -1
  54. package/ios/inputTextView/InputTextView.mm +100 -59
  55. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  56. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
  57. package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
  58. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  59. package/ios/styles/BlockQuoteStyle.mm +189 -118
  60. package/ios/styles/BoldStyle.mm +95 -63
  61. package/ios/styles/CodeBlockStyle.mm +204 -128
  62. package/ios/styles/H1Style.mm +10 -4
  63. package/ios/styles/H2Style.mm +10 -4
  64. package/ios/styles/H3Style.mm +10 -4
  65. package/ios/styles/HeadingStyleBase.mm +129 -84
  66. package/ios/styles/ImageStyle.mm +75 -73
  67. package/ios/styles/InlineCodeStyle.mm +148 -85
  68. package/ios/styles/ItalicStyle.mm +76 -52
  69. package/ios/styles/LinkStyle.mm +348 -227
  70. package/ios/styles/MentionStyle.mm +363 -246
  71. package/ios/styles/OrderedListStyle.mm +171 -106
  72. package/ios/styles/StrikethroughStyle.mm +52 -35
  73. package/ios/styles/UnderlineStyle.mm +68 -46
  74. package/ios/styles/UnorderedListStyle.mm +169 -106
  75. package/ios/utils/BaseStyleProtocol.h +2 -2
  76. package/ios/utils/ColorExtension.mm +7 -5
  77. package/ios/utils/FontExtension.mm +42 -27
  78. package/ios/utils/LayoutManagerExtension.h +1 -1
  79. package/ios/utils/LayoutManagerExtension.mm +280 -170
  80. package/ios/utils/MentionParams.h +0 -1
  81. package/ios/utils/MentionStyleProps.h +1 -1
  82. package/ios/utils/MentionStyleProps.mm +27 -20
  83. package/ios/utils/OccurenceUtils.h +42 -42
  84. package/ios/utils/OccurenceUtils.mm +142 -119
  85. package/ios/utils/ParagraphAttributesUtils.h +6 -2
  86. package/ios/utils/ParagraphAttributesUtils.mm +115 -71
  87. package/ios/utils/ParagraphsUtils.h +2 -1
  88. package/ios/utils/ParagraphsUtils.mm +40 -26
  89. package/ios/utils/StringExtension.h +1 -1
  90. package/ios/utils/StringExtension.mm +19 -16
  91. package/ios/utils/StyleHeaders.h +27 -15
  92. package/ios/utils/TextInsertionUtils.h +13 -2
  93. package/ios/utils/TextInsertionUtils.mm +38 -20
  94. package/ios/utils/WordsUtils.h +2 -1
  95. package/ios/utils/WordsUtils.mm +32 -22
  96. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  97. package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
  98. package/lib/module/EnrichedTextInput.js +39 -1
  99. package/lib/module/EnrichedTextInput.js.map +1 -1
  100. package/lib/module/EnrichedTextInputNativeComponent.ts +11 -0
  101. package/lib/typescript/src/EnrichedTextInput.d.ts +1 -0
  102. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  103. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +6 -0
  104. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  105. package/package.json +8 -1
  106. package/src/EnrichedTextInput.tsx +45 -0
  107. package/src/EnrichedTextInputNativeComponent.ts +11 -0
@@ -1,59 +1,84 @@
1
1
  #import "ParagraphAttributesUtils.h"
2
2
  #import "EnrichedTextInputView.h"
3
- #import "StyleHeaders.h"
4
3
  #import "ParagraphsUtils.h"
4
+ #import "StyleHeaders.h"
5
5
  #import "TextInsertionUtils.h"
6
6
 
7
7
  @implementation ParagraphAttributesUtils
8
8
 
9
- // if the user backspaces the last character in a line, the iOS applies typing attributes from the previous line
10
- // in the case of some paragraph styles it works especially bad when a list point just appears
11
- // this method handles that case differently with or without present paragraph styles
12
- + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input {
9
+ // if the user backspaces the last character in a line, the iOS applies typing
10
+ // attributes from the previous line in the case of some paragraph styles it
11
+ // works especially bad when a list point just appears this method handles that
12
+ // case differently with or without present paragraph styles
13
+ + (BOOL)handleBackspaceInRange:(NSRange)range
14
+ replacementText:(NSString *)text
15
+ input:(id)input {
13
16
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
14
- UnorderedListStyle *ulStyle = typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
15
- OrderedListStyle *olStyle = typedInput->stylesDict[@([OrderedListStyle getStyleType])];
16
- BlockQuoteStyle *bqStyle = typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
17
- CodeBlockStyle *cbStyle = typedInput->stylesDict[@([CodeBlockStyle getStyleType])];
18
-
19
- if(typedInput == nullptr) {
17
+ UnorderedListStyle *ulStyle =
18
+ typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
19
+ OrderedListStyle *olStyle =
20
+ typedInput->stylesDict[@([OrderedListStyle getStyleType])];
21
+ BlockQuoteStyle *bqStyle =
22
+ typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
23
+ CodeBlockStyle *cbStyle =
24
+ typedInput->stylesDict[@([CodeBlockStyle getStyleType])];
25
+
26
+ if (typedInput == nullptr) {
20
27
  return NO;
21
28
  }
22
-
23
- // we make sure it was a backspace (text with 0 length) and it deleted something (range longer than 0)
24
- if(text.length > 0 || range.length == 0) {
29
+
30
+ // we make sure it was a backspace (text with 0 length) and it deleted
31
+ // something (range longer than 0)
32
+ if (text.length > 0 || range.length == 0) {
25
33
  return NO;
26
34
  }
27
-
35
+
28
36
  // find a non-newline range of the paragraph
29
- NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range];
30
-
31
- NSArray *paragraphs = [ParagraphsUtils getNonNewlineRangesIn:typedInput->textView range:paragraphRange];
32
- if(paragraphs.count == 0) {
37
+ NSRange paragraphRange =
38
+ [typedInput->textView.textStorage.string paragraphRangeForRange:range];
39
+
40
+ NSArray *paragraphs =
41
+ [ParagraphsUtils getNonNewlineRangesIn:typedInput->textView
42
+ range:paragraphRange];
43
+ if (paragraphs.count == 0) {
33
44
  return NO;
34
45
  }
35
-
46
+
36
47
  NSRange nonNewlineRange = [(NSValue *)paragraphs.firstObject rangeValue];
37
-
38
- // the backspace removes the whole content of a paragraph (possibly more but has to start where the paragraph starts)
39
- if(range.location == nonNewlineRange.location && range.length >= nonNewlineRange.length) {
40
-
48
+
49
+ // the backspace removes the whole content of a paragraph (possibly more but
50
+ // has to start where the paragraph starts)
51
+ if (range.location == nonNewlineRange.location &&
52
+ range.length >= nonNewlineRange.length) {
53
+
41
54
  // for lists, quotes and codeblocks present we do the following:
42
55
  // - manually do the removing
43
- // - reset typing attribtues so that the previous line styles don't get applied
44
- // - reapply the paragraph style that was present so that a zero width space appears here
45
- NSArray *handledStyles = @[ulStyle, olStyle, bqStyle, cbStyle];
46
- for(id<BaseStyleProtocol> style in handledStyles) {
47
- if([style detectStyle:nonNewlineRange]) {
48
- [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
49
- typedInput->textView.typingAttributes = typedInput->defaultTypingAttributes;
50
- [style addAttributes:NSMakeRange(range.location, 0)];
56
+ // - reset typing attribtues so that the previous line styles don't get
57
+ // applied
58
+ // - reapply the paragraph style that was present so that a zero width space
59
+ // appears here
60
+ NSArray *handledStyles = @[ ulStyle, olStyle, bqStyle, cbStyle ];
61
+ for (id<BaseStyleProtocol> style in handledStyles) {
62
+ if ([style detectStyle:nonNewlineRange]) {
63
+ [TextInsertionUtils replaceText:text
64
+ at:range
65
+ additionalAttributes:nullptr
66
+ input:typedInput
67
+ withSelection:YES];
68
+ typedInput->textView.typingAttributes =
69
+ typedInput->defaultTypingAttributes;
70
+ [style addAttributes:NSMakeRange(range.location, 0) withTypingAttr:YES];
51
71
  return YES;
52
72
  }
53
73
  }
54
-
55
- // otherwise (no paragraph styles present), we just do the replacement manually and reset typing attribtues
56
- [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
74
+
75
+ // otherwise (no paragraph styles present), we just do the replacement
76
+ // manually and reset typing attribtues
77
+ [TextInsertionUtils replaceText:text
78
+ at:range
79
+ additionalAttributes:nullptr
80
+ input:typedInput
81
+ withSelection:YES];
57
82
  typedInput->textView.typingAttributes = typedInput->defaultTypingAttributes;
58
83
  return YES;
59
84
  }
@@ -62,72 +87,91 @@
62
87
  }
63
88
 
64
89
  /**
65
- * Handles the specific case of backspacing a newline character, which results in merging two paragraphs.
90
+ * Handles the specific case of backspacing a newline character, which results
91
+ * in merging two paragraphs.
66
92
  *
67
93
  * THE PROBLEM:
68
- * When merging a bottom paragraph (Source) into a top paragraph (Destination), the bottom paragraph
69
- * normally brings all its attributes with it. If the top paragraph is a restrictive style (like a CodeBlock),
70
- * and the bottom paragraph contains a conflicting style (like an H1 Header), a standard merge would
94
+ * When merging a bottom paragraph (Source) into a top paragraph (Destination),
95
+ * the bottom paragraph normally brings all its attributes with it. If the top
96
+ * paragraph is a restrictive style (like a CodeBlock), and the bottom paragraph
97
+ * contains a conflicting style (like an H1 Header), a standard merge would
71
98
  * create an invalid state (e.g., a CodeBlock that is also a Header).
72
99
  *
73
100
  * THE SOLUTION:
74
- * 1. Identifies the dominant style of the paragraph ABOVE the deleted newline (`leftParagraphStyle`).
75
- * 2. Checks the paragraph BELOW the newline (`rightRange`) for any styles that conflict with or are blocked by the top style.
76
- * 3. Explicitly removes those forbidden styles from the bottom paragraph *before* the merge occurs.
101
+ * 1. Identifies the dominant style of the paragraph ABOVE the deleted newline
102
+ * (`leftParagraphStyle`).
103
+ * 2. Checks the paragraph BELOW the newline (`rightRange`) for any styles that
104
+ * conflict with or are blocked by the top style.
105
+ * 3. Explicitly removes those forbidden styles from the bottom paragraph
106
+ * *before* the merge occurs.
77
107
  * 4. Performs the merge (deletes the newline).
78
108
  *
79
109
  * @return YES if the newline backspace was handled and sanitized; NO otherwise.
80
110
  */
81
- + (BOOL)handleNewlineBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input {
111
+ + (BOOL)handleParagraphStylesMergeOnBackspace:(NSRange)range
112
+ replacementText:(NSString *)text
113
+ input:(id)input {
82
114
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
83
- if(typedInput == nullptr) {
115
+ if (typedInput == nullptr) {
84
116
  return NO;
85
117
  }
86
-
87
- if(text.length == 0 && range.length == 1 &&
88
- [[NSCharacterSet newlineCharacterSet] characterIsMember:[typedInput->textView.textStorage.string characterAtIndex:range.location]]) {
89
- NSRange leftRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range];
90
-
118
+
119
+ if (text.length == 0) {
120
+ NSRange leftRange = [typedInput->textView.textStorage.string
121
+ paragraphRangeForRange:NSMakeRange(range.location, 0)];
122
+
91
123
  id<BaseStyleProtocol> leftParagraphStyle = nullptr;
92
124
  for (NSNumber *key in typedInput->stylesDict) {
93
125
  id<BaseStyleProtocol> style = typedInput->stylesDict[key];
94
- if([[style class] isParagraphStyle] && [style detectStyle:leftRange]) {
126
+ if ([[style class] isParagraphStyle] && [style detectStyle:leftRange]) {
95
127
  leftParagraphStyle = style;
96
128
  }
97
129
  }
98
-
99
- if(leftParagraphStyle == nullptr) {
130
+
131
+ if (leftParagraphStyle == nullptr) {
100
132
  return NO;
101
133
  }
102
-
134
+
103
135
  // index out of bounds
104
- if(range.location + 1 >= typedInput->textView.textStorage.string.length) {
136
+ NSUInteger rightRangeStart = range.location + range.length;
137
+ if (rightRangeStart >= typedInput->textView.textStorage.string.length) {
105
138
  return NO;
106
139
  }
107
-
108
- NSRange rightRange = [typedInput->textView.textStorage.string paragraphRangeForRange:NSMakeRange(range.location + 1, 1)];
109
-
140
+
141
+ NSRange rightRange = [typedInput->textView.textStorage.string
142
+ paragraphRangeForRange:NSMakeRange(rightRangeStart, 1)];
143
+
110
144
  StyleType type = [[leftParagraphStyle class] getStyleType];
111
-
112
- NSArray *conflictingStyles = [typedInput getPresentStyleTypesFrom:typedInput->conflictingStyles[@(type)] range:rightRange];
113
- NSArray *blockingStyles = [typedInput getPresentStyleTypesFrom:typedInput->blockingStyles[@(type)] range:rightRange];
114
- NSArray *allToBeRemoved = [conflictingStyles arrayByAddingObjectsFromArray:blockingStyles];
115
-
116
- for(NSNumber *style in allToBeRemoved) {
145
+
146
+ NSArray *conflictingStyles = [typedInput
147
+ getPresentStyleTypesFrom:typedInput->conflictingStyles[@(type)]
148
+ range:rightRange];
149
+ NSArray *blockingStyles =
150
+ [typedInput getPresentStyleTypesFrom:typedInput->blockingStyles[@(type)]
151
+ range:rightRange];
152
+ NSArray *allToBeRemoved =
153
+ [conflictingStyles arrayByAddingObjectsFromArray:blockingStyles];
154
+
155
+ for (NSNumber *style in allToBeRemoved) {
117
156
  id<BaseStyleProtocol> styleClass = typedInput->stylesDict[style];
118
-
157
+
119
158
  // for ranges, we need to remove each occurence
120
- NSArray<StylePair *> *allOccurences = [styleClass findAllOccurences:rightRange];
121
-
122
- for(StylePair* pair in allOccurences) {
123
- [styleClass removeAttributes: [pair.rangeValue rangeValue]];
159
+ NSArray<StylePair *> *allOccurences =
160
+ [styleClass findAllOccurences:rightRange];
161
+
162
+ for (StylePair *pair in allOccurences) {
163
+ [styleClass removeAttributes:[pair.rangeValue rangeValue]];
124
164
  }
125
165
  }
126
-
127
- [TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
166
+
167
+ [TextInsertionUtils replaceText:text
168
+ at:range
169
+ additionalAttributes:nullptr
170
+ input:typedInput
171
+ withSelection:YES];
128
172
  return YES;
129
173
  }
130
-
174
+
131
175
  return NO;
132
176
  }
133
177
 
@@ -2,6 +2,7 @@
2
2
  #import <UIKit/UIKit.h>
3
3
 
4
4
  @interface ParagraphsUtils : NSObject
5
- + (NSArray *)getSeparateParagraphsRangesIn:(UITextView *)textView range:(NSRange)range;
5
+ + (NSArray *)getSeparateParagraphsRangesIn:(UITextView *)textView
6
+ range:(NSRange)range;
6
7
  + (NSArray *)getNonNewlineRangesIn:(UITextView *)textView range:(NSRange)range;
7
8
  @end
@@ -2,52 +2,66 @@
2
2
 
3
3
  @implementation ParagraphsUtils
4
4
 
5
- + (NSArray *)getSeparateParagraphsRangesIn:(UITextView *)textView range:(NSRange)range {
5
+ + (NSArray *)getSeparateParagraphsRangesIn:(UITextView *)textView
6
+ range:(NSRange)range {
6
7
  // just in case, get full paragraphs range
7
- NSRange fullRange = [textView.textStorage.string paragraphRangeForRange:range];
8
-
8
+ NSRange fullRange =
9
+ [textView.textStorage.string paragraphRangeForRange:range];
10
+
9
11
  // we are in an empty paragraph
10
- if(fullRange.length == 0) {
11
- return @[[NSValue valueWithRange:fullRange]];
12
+ if (fullRange.length == 0) {
13
+ return @[ [NSValue valueWithRange:fullRange] ];
12
14
  }
13
-
15
+
14
16
  NSMutableArray *results = [[NSMutableArray alloc] init];
15
-
17
+
16
18
  NSInteger lastStart = fullRange.location;
17
- for(int i = fullRange.location; i < fullRange.location + fullRange.length; i++) {
19
+ for (int i = fullRange.location; i < fullRange.location + fullRange.length;
20
+ i++) {
18
21
  unichar currentChar = [textView.textStorage.string characterAtIndex:i];
19
- if([[NSCharacterSet newlineCharacterSet] characterIsMember:currentChar]) {
20
- NSRange paragraphRange = [textView.textStorage.string paragraphRangeForRange:NSMakeRange(lastStart, i - lastStart)];
21
- [results addObject: [NSValue valueWithRange:paragraphRange]];
22
- lastStart = i+1;
22
+ if ([[NSCharacterSet newlineCharacterSet] characterIsMember:currentChar]) {
23
+ NSRange paragraphRange = [textView.textStorage.string
24
+ paragraphRangeForRange:NSMakeRange(lastStart, i - lastStart)];
25
+ [results addObject:[NSValue valueWithRange:paragraphRange]];
26
+ lastStart = i + 1;
23
27
  }
24
28
  }
25
-
26
- if(lastStart < fullRange.location + fullRange.length) {
27
- NSRange paragraphRange = [textView.textStorage.string paragraphRangeForRange:NSMakeRange(lastStart, fullRange.location + fullRange.length - lastStart)];
28
- [results addObject: [NSValue valueWithRange:paragraphRange]];
29
+
30
+ if (lastStart < fullRange.location + fullRange.length) {
31
+ NSRange paragraphRange = [textView.textStorage.string
32
+ paragraphRangeForRange:NSMakeRange(lastStart, fullRange.location +
33
+ fullRange.length -
34
+ lastStart)];
35
+ [results addObject:[NSValue valueWithRange:paragraphRange]];
29
36
  }
30
-
37
+
31
38
  return results;
32
39
  }
33
40
 
34
41
  + (NSArray *)getNonNewlineRangesIn:(UITextView *)textView range:(NSRange)range {
35
42
  NSMutableArray *nonNewlineRanges = [[NSMutableArray alloc] init];
36
43
  int lastRangeLocation = range.location;
37
-
38
- for(int i = range.location; i < range.location + range.length; i++) {
44
+
45
+ for (int i = range.location; i < range.location + range.length; i++) {
39
46
  unichar currentChar = [textView.textStorage.string characterAtIndex:i];
40
- if([[NSCharacterSet newlineCharacterSet] characterIsMember:currentChar]) {
41
- if(i - lastRangeLocation > 0) {
42
- [nonNewlineRanges addObject:[NSValue valueWithRange:NSMakeRange(lastRangeLocation, i - lastRangeLocation)]];
47
+ if ([[NSCharacterSet newlineCharacterSet] characterIsMember:currentChar]) {
48
+ if (i - lastRangeLocation > 0) {
49
+ [nonNewlineRanges
50
+ addObject:[NSValue
51
+ valueWithRange:NSMakeRange(lastRangeLocation,
52
+ i - lastRangeLocation)]];
43
53
  }
44
- lastRangeLocation = i+1;
54
+ lastRangeLocation = i + 1;
45
55
  }
46
56
  }
47
- if(lastRangeLocation < range.location + range.length) {
48
- [nonNewlineRanges addObject:[NSValue valueWithRange:NSMakeRange(lastRangeLocation, range.location + range.length - lastRangeLocation)]];
57
+ if (lastRangeLocation < range.location + range.length) {
58
+ [nonNewlineRanges
59
+ addObject:[NSValue
60
+ valueWithRange:NSMakeRange(lastRangeLocation,
61
+ range.location + range.length -
62
+ lastRangeLocation)]];
49
63
  }
50
-
64
+
51
65
  return nonNewlineRanges;
52
66
  }
53
67
 
@@ -1,5 +1,5 @@
1
- #import <UIKit/UIKit.h>
2
1
  #include "string"
2
+ #import <UIKit/UIKit.h>
3
3
  #pragma once
4
4
 
5
5
  @interface NSString (StringExtension)
@@ -13,41 +13,44 @@
13
13
  + (NSString *)stringByEscapingHtml:(NSString *)html {
14
14
  NSMutableString *escaped = [html mutableCopy];
15
15
  NSDictionary *escapeMap = @{
16
- @"&": @"&amp;",
17
- @"<": @"&lt;",
18
- @">": @"&gt;",
16
+ @"&" : @"&amp;",
17
+ @"<" : @"&lt;",
18
+ @">" : @"&gt;",
19
19
  };
20
-
21
- for(NSString *key in escapeMap) {
22
- [escaped replaceOccurrencesOfString:key withString:escapeMap[key] options:NSLiteralSearch range:NSMakeRange(0, escaped.length)];
20
+
21
+ for (NSString *key in escapeMap) {
22
+ [escaped replaceOccurrencesOfString:key
23
+ withString:escapeMap[key]
24
+ options:NSLiteralSearch
25
+ range:NSMakeRange(0, escaped.length)];
23
26
  }
24
27
  return escaped;
25
28
  }
26
29
 
27
30
  + (NSDictionary *)getEscapedCharactersInfoFrom:(NSString *)text {
28
31
  NSDictionary *unescapeMap = @{
29
- @"&amp;": @"&",
30
- @"&lt;": @"<",
31
- @"&gt;": @">",
32
+ @"&amp;" : @"&",
33
+ @"&lt;" : @"<",
34
+ @"&gt;" : @">",
32
35
  };
33
-
36
+
34
37
  NSMutableDictionary *results = [[NSMutableDictionary alloc] init];
35
-
36
- for(NSString *key in unescapeMap) {
38
+
39
+ for (NSString *key in unescapeMap) {
37
40
  NSRange searchRange = NSMakeRange(0, text.length);
38
41
  NSRange foundRange;
39
42
 
40
- while(searchRange.location < text.length) {
43
+ while (searchRange.location < text.length) {
41
44
  foundRange = [text rangeOfString:key options:0 range:searchRange];
42
- if(foundRange.location == NSNotFound) {
45
+ if (foundRange.location == NSNotFound) {
43
46
  break;
44
47
  }
45
- results[@(foundRange.location)] = @[key, unescapeMap[key]];
48
+ results[@(foundRange.location)] = @[ key, unescapeMap[key] ];
46
49
  searchRange.location = foundRange.location + foundRange.length;
47
50
  searchRange.length = text.length - searchRange.location;
48
51
  }
49
52
  }
50
-
53
+
51
54
  return results;
52
55
  }
53
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,29 +21,37 @@
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;
@@ -61,28 +69,32 @@
61
69
  @interface H3Style : HeadingStyleBase
62
70
  @end
63
71
 
64
- @interface UnorderedListStyle : NSObject<BaseStyleProtocol>
72
+ @interface UnorderedListStyle : NSObject <BaseStyleProtocol>
65
73
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
66
- - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text;
74
+ - (BOOL)tryHandlingListShorcutInRange:(NSRange)range
75
+ replacementText:(NSString *)text;
67
76
  @end
68
77
 
69
- @interface OrderedListStyle : NSObject<BaseStyleProtocol>
78
+ @interface OrderedListStyle : NSObject <BaseStyleProtocol>
70
79
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
71
- - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text;
80
+ - (BOOL)tryHandlingListShorcutInRange:(NSRange)range
81
+ replacementText:(NSString *)text;
72
82
  @end
73
83
 
74
- @interface BlockQuoteStyle : NSObject<BaseStyleProtocol>
84
+ @interface BlockQuoteStyle : NSObject <BaseStyleProtocol>
75
85
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
76
86
  - (void)manageBlockquoteColor;
77
87
  @end
78
88
 
79
- @interface CodeBlockStyle : NSObject<BaseStyleProtocol>
89
+ @interface CodeBlockStyle : NSObject <BaseStyleProtocol>
80
90
  - (void)manageCodeBlockFontAndColor;
81
91
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text;
82
92
  @end
83
93
 
84
- @interface ImageStyle : NSObject<BaseStyleProtocol>
94
+ @interface ImageStyle : NSObject <BaseStyleProtocol>
85
95
  - (void)addImage:(NSString *)uri width:(CGFloat)width height:(CGFloat)height;
86
- - (void)addImageAtRange:(NSRange)range imageData:(ImageData *)imageData withSelection:(BOOL)withSelection;
96
+ - (void)addImageAtRange:(NSRange)range
97
+ imageData:(ImageData *)imageData
98
+ withSelection:(BOOL)withSelection;
87
99
  - (ImageData *)getImageDataAt:(NSUInteger)location;
88
100
  @end
@@ -1,6 +1,17 @@
1
1
  #import <UIKit/UIKit.h>
2
2
 
3
3
  @interface TextInsertionUtils : NSObject
4
- + (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary<NSAttributedStringKey, id>*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection;
5
- + (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary<NSAttributedStringKey, id>*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection;;
4
+ + (void)insertText:(NSString *)text
5
+ at:(NSInteger)index
6
+ additionalAttributes:
7
+ (NSDictionary<NSAttributedStringKey, id> *)additionalAttrs
8
+ input:(id)input
9
+ withSelection:(BOOL)withSelection;
10
+ + (void)replaceText:(NSString *)text
11
+ at:(NSRange)range
12
+ additionalAttributes:
13
+ (NSDictionary<NSAttributedStringKey, id> *)additionalAttrs
14
+ input:(id)input
15
+ withSelection:(BOOL)withSelection;
16
+ ;
6
17
  @end
@@ -1,24 +1,33 @@
1
1
  #import "TextInsertionUtils.h"
2
- #import "UIView+React.h"
3
2
  #import "EnrichedTextInputView.h"
3
+ #import "UIView+React.h"
4
4
 
5
5
  @implementation TextInsertionUtils
6
- + (void)insertText:(NSString*)text at:(NSInteger)index additionalAttributes:(NSDictionary<NSAttributedStringKey, id>*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection {
6
+ + (void)insertText:(NSString *)text
7
+ at:(NSInteger)index
8
+ additionalAttributes:
9
+ (NSDictionary<NSAttributedStringKey, id> *)additionalAttrs
10
+ input:(id)input
11
+ withSelection:(BOOL)withSelection {
7
12
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
8
- if(typedInput == nullptr) { return; }
9
-
13
+ if (typedInput == nullptr) {
14
+ return;
15
+ }
16
+
10
17
  UITextView *textView = typedInput->textView;
11
18
 
12
- NSMutableDictionary<NSAttributedStringKey, id> *copiedAttrs = [textView.typingAttributes mutableCopy];
13
- if(additionalAttrs != nullptr) {
14
- [copiedAttrs addEntriesFromDictionary: additionalAttrs];
19
+ NSMutableDictionary<NSAttributedStringKey, id> *copiedAttrs =
20
+ [textView.typingAttributes mutableCopy];
21
+ if (additionalAttrs != nullptr) {
22
+ [copiedAttrs addEntriesFromDictionary:additionalAttrs];
15
23
  }
16
-
17
- NSAttributedString *newAttrStr = [[NSAttributedString alloc] initWithString:text attributes:copiedAttrs];
24
+
25
+ NSAttributedString *newAttrStr =
26
+ [[NSAttributedString alloc] initWithString:text attributes:copiedAttrs];
18
27
  [textView.textStorage insertAttributedString:newAttrStr atIndex:index];
19
-
20
- if(withSelection) {
21
- if(![textView isFirstResponder]) {
28
+
29
+ if (withSelection) {
30
+ if (![textView isFirstResponder]) {
22
31
  [textView reactFocus];
23
32
  }
24
33
  textView.selectedRange = NSMakeRange(index + text.length, 0);
@@ -26,19 +35,28 @@
26
35
  typedInput->recentlyChangedRange = NSMakeRange(index, text.length);
27
36
  }
28
37
 
29
- + (void)replaceText:(NSString*)text at:(NSRange)range additionalAttributes:(NSDictionary<NSAttributedStringKey, id>*)additionalAttrs input:(id)input withSelection:(BOOL)withSelection {
38
+ + (void)replaceText:(NSString *)text
39
+ at:(NSRange)range
40
+ additionalAttributes:
41
+ (NSDictionary<NSAttributedStringKey, id> *)additionalAttrs
42
+ input:(id)input
43
+ withSelection:(BOOL)withSelection {
30
44
  EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
31
- if(typedInput == nullptr) { return; }
32
-
45
+ if (typedInput == nullptr) {
46
+ return;
47
+ }
48
+
33
49
  UITextView *textView = typedInput->textView;
34
50
 
35
51
  [textView.textStorage replaceCharactersInRange:range withString:text];
36
- if(additionalAttrs != nullptr) {
37
- [textView.textStorage addAttributes:additionalAttrs range:NSMakeRange(range.location, [text length])];
52
+ if (additionalAttrs != nullptr) {
53
+ [textView.textStorage
54
+ addAttributes:additionalAttrs
55
+ range:NSMakeRange(range.location, [text length])];
38
56
  }
39
-
40
- if(withSelection) {
41
- if(![textView isFirstResponder]) {
57
+
58
+ if (withSelection) {
59
+ if (![textView isFirstResponder]) {
42
60
  [textView reactFocus];
43
61
  }
44
62
  textView.selectedRange = NSMakeRange(range.location + text.length, 0);
@@ -1,6 +1,7 @@
1
1
  #import <UIKit/UIKit.h>
2
2
 
3
3
  @interface WordsUtils : NSObject
4
- + (NSArray<NSDictionary *> *)getAffectedWordsFromText:(NSString *)text modificationRange:(NSRange)range;
4
+ + (NSArray<NSDictionary *> *)getAffectedWordsFromText:(NSString *)text
5
+ modificationRange:(NSRange)range;
5
6
  + (NSDictionary *)getCurrentWord:(NSString *)text range:(NSRange)range;
6
7
  @end