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
@@ -0,0 +1,56 @@
1
+ import type { LinkNativeRegex } from '../EnrichedTextInputNativeComponent';
2
+
3
+ const DISABLED_REGEX: LinkNativeRegex = {
4
+ pattern: '',
5
+ caseInsensitive: false,
6
+ dotAll: false,
7
+ isDisabled: true,
8
+ isDefault: false,
9
+ };
10
+
11
+ const DEFAULT_REGEX: LinkNativeRegex = {
12
+ pattern: '',
13
+ caseInsensitive: false,
14
+ dotAll: false,
15
+ isDisabled: false,
16
+ isDefault: true,
17
+ };
18
+
19
+ export const toNativeRegexConfig = (
20
+ regex: RegExp | undefined | null
21
+ ): LinkNativeRegex => {
22
+ if (regex === null) {
23
+ return DISABLED_REGEX;
24
+ }
25
+
26
+ if (regex === undefined) {
27
+ return DEFAULT_REGEX;
28
+ }
29
+
30
+ const source = regex.source;
31
+
32
+ // iOS fails on variable-width lookbehinds like (?<=a+)
33
+ const hasLookbehind = source.includes('(?<=') || source.includes('(?<!');
34
+
35
+ if (hasLookbehind) {
36
+ // Basic detection for quantifiers inside a group
37
+ const lookbehindContent = source.match(/\(\?<[=!](.*?)\)/)?.[1] || '';
38
+ if (/[*+{]/.test(lookbehindContent)) {
39
+ if (__DEV__) {
40
+ console.error(
41
+ 'Variable-width lookbehinds are not supported. Using default link regex.'
42
+ );
43
+ }
44
+
45
+ return DEFAULT_REGEX;
46
+ }
47
+ }
48
+
49
+ return {
50
+ pattern: source,
51
+ caseInsensitive: regex.ignoreCase,
52
+ dotAll: regex.dotAll,
53
+ isDisabled: false,
54
+ isDefault: false,
55
+ };
56
+ };
@@ -1,91 +0,0 @@
1
- #import "FontExtension.h"
2
- #import <React/RCTLog.h>
3
-
4
- @implementation UIFont (FontExtension)
5
-
6
- - (BOOL)isBold {
7
- return (self.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) == UIFontDescriptorTraitBold;
8
- }
9
-
10
- - (UIFont *)setBold {
11
- if([self isBold]) {
12
- return self;
13
- }
14
- UIFontDescriptorSymbolicTraits newTraits = (self.fontDescriptor.symbolicTraits | UIFontDescriptorTraitBold);
15
- UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
16
- if(fontDescriptor != nullptr) {
17
- return [UIFont fontWithDescriptor:fontDescriptor size:0];
18
- } else {
19
- RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply bold trait to the font.");
20
- return self;
21
- }
22
- }
23
-
24
- - (UIFont *)removeBold {
25
- if(![self isBold]) {
26
- return self;
27
- }
28
- UIFontDescriptorSymbolicTraits newTraits = (self.fontDescriptor.symbolicTraits ^ UIFontDescriptorTraitBold);
29
- UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
30
- if(fontDescriptor != nullptr) {
31
- return [UIFont fontWithDescriptor:fontDescriptor size:0];
32
- } else {
33
- RCTLogWarn(@"[EnrichedTextInput]: Couldn't remove bold trait from the font.");
34
- return self;
35
- }
36
- }
37
-
38
- - (BOOL)isItalic {
39
- return (self.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) == UIFontDescriptorTraitItalic;
40
- }
41
-
42
- - (UIFont *)setItalic {
43
- if([self isItalic]) {
44
- return self;
45
- }
46
- UIFontDescriptorSymbolicTraits newTraits = (self.fontDescriptor.symbolicTraits | UIFontDescriptorTraitItalic);
47
- UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
48
- if(fontDescriptor != nullptr) {
49
- return [UIFont fontWithDescriptor:fontDescriptor size:0];
50
- } else {
51
- RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply italic trait to the font.");
52
- return self;
53
- }
54
- }
55
-
56
- - (UIFont *)removeItalic {
57
- if(![self isItalic]) {
58
- return self;
59
- }
60
- UIFontDescriptorSymbolicTraits newTraits = (self.fontDescriptor.symbolicTraits ^ UIFontDescriptorTraitItalic);
61
- UIFontDescriptor *fontDescriptor = [self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
62
- if(fontDescriptor != nullptr) {
63
- return [UIFont fontWithDescriptor:fontDescriptor size:0];
64
- } else {
65
- RCTLogWarn(@"[EnrichedTextInput]: Couldn't remove italic trait from the font.");
66
- return self;
67
- }
68
- }
69
-
70
- - (UIFont *)withFontTraits:(UIFont *)from {
71
- UIFont* newFont = self;
72
- if([from isBold]) {
73
- newFont = [newFont setBold];
74
- }
75
- if([from isItalic]) {
76
- newFont = [newFont setItalic];
77
- }
78
- return newFont;
79
- }
80
-
81
- - (UIFont *)setSize:(CGFloat)size {
82
- UIFontDescriptor *newFontDescriptor = [self.fontDescriptor fontDescriptorWithSize:size];
83
- if(newFontDescriptor != nullptr) {
84
- return [UIFont fontWithDescriptor:newFontDescriptor size:0];
85
- } else {
86
- RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply heading style to the font.");
87
- return self;
88
- }
89
- }
90
-
91
- @end
@@ -1,286 +0,0 @@
1
- #import "LayoutManagerExtension.h"
2
- #import <objc/runtime.h>
3
- #import "EnrichedTextInputView.h"
4
- #import "StyleHeaders.h"
5
- #import "ParagraphsUtils.h"
6
- #import "ColorExtension.h"
7
-
8
- @implementation NSLayoutManager (LayoutManagerExtension)
9
-
10
- static void const *kInputKey = &kInputKey;
11
-
12
- - (id)input {
13
- return objc_getAssociatedObject(self, kInputKey);
14
- }
15
-
16
- - (void)setInput:(id)value {
17
- objc_setAssociatedObject(
18
- self,
19
- kInputKey,
20
- value,
21
- OBJC_ASSOCIATION_RETAIN_NONATOMIC
22
- );
23
- }
24
-
25
- + (void)load {
26
- static dispatch_once_t onceToken;
27
- dispatch_once(&onceToken, ^{
28
- Class myClass = [NSLayoutManager class];
29
- SEL originalSelector = @selector(drawBackgroundForGlyphRange:atPoint:);
30
- SEL swizzledSelector = @selector(my_drawBackgroundForGlyphRange:atPoint:);
31
- Method originalMethod = class_getInstanceMethod(myClass, originalSelector);
32
- Method swizzledMethod = class_getInstanceMethod(myClass, swizzledSelector);
33
-
34
- BOOL didAddMethod = class_addMethod(myClass, originalSelector,
35
- method_getImplementation(swizzledMethod),
36
- method_getTypeEncoding(swizzledMethod)
37
- );
38
-
39
- if(didAddMethod) {
40
- class_replaceMethod(myClass, swizzledSelector,
41
- method_getImplementation(originalMethod),
42
- method_getTypeEncoding(originalMethod)
43
- );
44
- } else {
45
- method_exchangeImplementations(originalMethod, swizzledMethod);
46
- }
47
- });
48
- }
49
-
50
- - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange atPoint:(CGPoint)origin {
51
- [self my_drawBackgroundForGlyphRange:glyphRange atPoint:origin];
52
-
53
- EnrichedTextInputView *typedInput = (EnrichedTextInputView *)self.input;
54
- if(typedInput == nullptr) { return; }
55
-
56
- NSRange inputRange = NSMakeRange(0, typedInput->textView.textStorage.length);
57
-
58
- [self drawBlockQuotes:typedInput origin:origin inputRange:inputRange];
59
- [self drawLists:typedInput origin:origin inputRange:inputRange];
60
- [self drawCodeBlocks:typedInput origin:origin inputRange:inputRange];
61
- }
62
-
63
- - (void)drawCodeBlocks:(EnrichedTextInputView *)typedInput origin:(CGPoint)origin inputRange:(NSRange)inputRange
64
- {
65
- CodeBlockStyle *codeBlockStyle = typedInput->stylesDict[@([CodeBlockStyle getStyleType])];
66
- if(codeBlockStyle == nullptr) { return; }
67
-
68
- NSArray<StylePair *> *allCodeBlocks = [codeBlockStyle findAllOccurences:inputRange];
69
- NSArray<StylePair *> *mergedCodeBlocks = [self mergeContiguousStylePairs:allCodeBlocks];
70
- UIColor *bgColor = [[typedInput->config codeBlockBgColor] colorWithAlphaIfNotTransparent:0.4];
71
- CGFloat radius = [typedInput->config codeBlockBorderRadius];
72
- [bgColor setFill];
73
-
74
- for (StylePair *pair in mergedCodeBlocks) {
75
- NSRange blockCharacterRange = [pair.rangeValue rangeValue];
76
- if (blockCharacterRange.length == 0) continue;
77
-
78
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:typedInput->textView range:blockCharacterRange];
79
- if (paragraphs.count == 0) continue;
80
-
81
- NSRange firstParagraphRange = [((NSValue *)[paragraphs firstObject]) rangeValue];
82
- NSRange lastParagraphRange = [((NSValue *)[paragraphs lastObject]) rangeValue];
83
-
84
- for (NSValue *paragraphValue in paragraphs) {
85
- NSRange paragraphCharacterRange = [paragraphValue rangeValue];
86
-
87
- BOOL isFirstParagraph = NSEqualRanges(paragraphCharacterRange, firstParagraphRange);
88
- BOOL isLastParagraph = NSEqualRanges(paragraphCharacterRange, lastParagraphRange);
89
-
90
- NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:paragraphCharacterRange actualCharacterRange:NULL];
91
-
92
- __block BOOL isFirstLineOfParagraph = YES;
93
-
94
- [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange
95
- usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
96
-
97
- CGRect lineBgRect = rect;
98
- lineBgRect.origin.x = origin.x;
99
- lineBgRect.origin.y += origin.y;
100
- lineBgRect.size.width = textContainer.size.width;
101
-
102
- UIRectCorner cornersForThisLine = 0;
103
-
104
- if (isFirstParagraph && isFirstLineOfParagraph) {
105
- cornersForThisLine = UIRectCornerTopLeft | UIRectCornerTopRight;
106
- }
107
-
108
- BOOL isLastLineOfParagraph = (NSMaxRange(glyphRange) >= NSMaxRange(paragraphGlyphRange));
109
-
110
- if (isLastParagraph && isLastLineOfParagraph) {
111
- cornersForThisLine = cornersForThisLine | UIRectCornerBottomLeft | UIRectCornerBottomRight;
112
- }
113
-
114
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lineBgRect
115
- byRoundingCorners:cornersForThisLine
116
- cornerRadii:CGSizeMake(radius, radius)];
117
- [path fill];
118
-
119
- isFirstLineOfParagraph = NO;
120
- }];
121
- }
122
- }
123
- }
124
-
125
- - (NSArray<StylePair *> *)mergeContiguousStylePairs:(NSArray<StylePair *> *)pairs
126
- {
127
- if (pairs.count == 0) {
128
- return @[];
129
- }
130
-
131
- NSMutableArray<StylePair *> *mergedPairs = [[NSMutableArray alloc] init];
132
- StylePair *currentPair = pairs[0];
133
- NSRange currentRange = [currentPair.rangeValue rangeValue];
134
- for (NSUInteger i = 1; i < pairs.count; i++) {
135
- StylePair *nextPair = pairs[i];
136
- NSRange nextRange = [nextPair.rangeValue rangeValue];
137
-
138
- // The Gap Check:
139
- // NSMaxRange(currentRange) is where the current block ends.
140
- // nextRange.location is where the next block starts.
141
- if (NSMaxRange(currentRange) == nextRange.location) {
142
- // They touch perfectly (no gap). Merge them.
143
- currentRange.length += nextRange.length;
144
- } else {
145
- // There is a gap (indices don't match).
146
- // 1. Save the finished block.
147
- StylePair *mergedPair = [[StylePair alloc] init];
148
- mergedPair.rangeValue = [NSValue valueWithRange:currentRange];
149
- mergedPair.styleValue = currentPair.styleValue;
150
- [mergedPairs addObject:mergedPair];
151
-
152
- // 2. Start a brand new block.
153
- currentPair = nextPair;
154
- currentRange = nextRange;
155
- }
156
- }
157
-
158
- // Add the final block
159
- StylePair *lastPair = [[StylePair alloc] init];
160
- lastPair.rangeValue = [NSValue valueWithRange:currentRange];
161
- lastPair.styleValue = currentPair.styleValue;
162
- [mergedPairs addObject:lastPair];
163
-
164
- return mergedPairs;
165
- }
166
-
167
- - (void)drawBlockQuotes:(EnrichedTextInputView *)typedInput origin:(CGPoint)origin inputRange:(NSRange)inputRange
168
- {
169
- BlockQuoteStyle *bqStyle = typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
170
- if(bqStyle == nullptr) { return; }
171
-
172
- // it isn't the most performant but we have to check for all the blockquotes each time and redraw them
173
- NSArray *allBlockquotes = [bqStyle findAllOccurences:inputRange];
174
-
175
- for(StylePair *pair in allBlockquotes) {
176
- NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:[pair.rangeValue rangeValue]];
177
- NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:paragraphRange actualCharacterRange:nullptr];
178
- [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange
179
- usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
180
- CGFloat paddingLeft = origin.x;
181
- CGFloat paddingTop = origin.y;
182
- CGFloat x = paddingLeft;
183
- CGFloat y = paddingTop + rect.origin.y;
184
- CGFloat width = [typedInput->config blockquoteBorderWidth];
185
- CGFloat height = rect.size.height;
186
-
187
- CGRect lineRect = CGRectMake(x, y, width, height);
188
- [[typedInput->config blockquoteBorderColor] setFill];
189
- UIRectFill(lineRect);
190
- }
191
- ];
192
- }
193
- }
194
-
195
- - (void)drawLists:(EnrichedTextInputView *)typedInput origin:(CGPoint)origin inputRange:(NSRange)inputRange
196
- {
197
- UnorderedListStyle *ulStyle = typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
198
- OrderedListStyle *olStyle = typedInput->stylesDict[@([OrderedListStyle getStyleType])];
199
- if(ulStyle == nullptr || olStyle == nullptr) { return; }
200
-
201
- // also not the most performant but we redraw all the lists
202
- NSMutableArray *allLists = [[NSMutableArray alloc] init];
203
- [allLists addObjectsFromArray:[ulStyle findAllOccurences:inputRange]];
204
- [allLists addObjectsFromArray:[olStyle findAllOccurences:inputRange]];
205
-
206
- for(StylePair *pair in allLists) {
207
- NSParagraphStyle *pStyle = (NSParagraphStyle *)pair.styleValue;
208
- NSDictionary *markerAttributes = @{
209
- NSFontAttributeName: [typedInput->config orderedListMarkerFont],
210
- NSForegroundColorAttributeName: [typedInput->config orderedListMarkerColor]
211
- };
212
-
213
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:typedInput->textView range:[pair.rangeValue rangeValue]];
214
-
215
- for(NSValue *paragraph in paragraphs) {
216
- NSRange paragraphGlyphRange = [self glyphRangeForCharacterRange:[paragraph rangeValue] actualCharacterRange:nullptr];
217
-
218
- [self enumerateLineFragmentsForGlyphRange:paragraphGlyphRange
219
- usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *container, NSRange lineGlyphRange, BOOL *stop) {
220
- NSString *marker = [self markerForList:pStyle.textLists.firstObject charIndex:[self characterIndexForGlyphAtIndex:lineGlyphRange.location] input:typedInput];
221
-
222
- if(pStyle.textLists.firstObject.markerFormat == NSTextListMarkerDecimal) {
223
- CGFloat gapWidth = [typedInput->config orderedListGapWidth];
224
- CGFloat markerWidth = [marker sizeWithAttributes:markerAttributes].width;
225
- CGFloat markerX = usedRect.origin.x - gapWidth - markerWidth/2;
226
-
227
- [marker drawAtPoint:CGPointMake(markerX, usedRect.origin.y + origin.y) withAttributes:markerAttributes];
228
- } else {
229
- CGFloat gapWidth = [typedInput->config unorderedListGapWidth];
230
- CGFloat bulletSize = [typedInput->config unorderedListBulletSize];
231
- CGFloat bulletX = usedRect.origin.x - gapWidth - bulletSize/2;
232
- CGFloat centerY = CGRectGetMidY(usedRect);
233
-
234
- CGContextRef context = UIGraphicsGetCurrentContext();
235
- CGContextSaveGState(context); {
236
- [[typedInput->config unorderedListBulletColor] setFill];
237
- CGContextAddArc(context, bulletX, centerY, bulletSize/2, 0, 2 * M_PI, YES);
238
- CGContextFillPath(context);
239
- }
240
- CGContextRestoreGState(context);
241
- }
242
- // only first line of a list gets its marker drawn
243
- *stop = YES;
244
- }
245
- ];
246
- }
247
- }
248
- }
249
-
250
- - (NSString *)markerForList:(NSTextList *)list charIndex:(NSUInteger)index input:(EnrichedTextInputView *)input {
251
- if(list.markerFormat == NSTextListMarkerDecimal) {
252
- NSString *fullText = input->textView.textStorage.string;
253
- NSInteger itemNumber = 1;
254
-
255
- NSRange currentParagraph = [fullText paragraphRangeForRange:NSMakeRange(index, 0)];
256
- if(currentParagraph.location > 0) {
257
- OrderedListStyle *olStyle = input->stylesDict[@([OrderedListStyle getStyleType])];
258
-
259
- NSInteger prevParagraphsCount = 0;
260
- NSInteger recentParagraphLocation = [fullText paragraphRangeForRange:NSMakeRange(currentParagraph.location - 1, 0)].location;
261
-
262
- // seek for previous lists
263
- while(true) {
264
- if([olStyle detectStyle:NSMakeRange(recentParagraphLocation, 0)]) {
265
- prevParagraphsCount += 1;
266
-
267
- if(recentParagraphLocation > 0) {
268
- recentParagraphLocation = [fullText paragraphRangeForRange:NSMakeRange(recentParagraphLocation - 1, 0)].location;
269
- } else {
270
- break;
271
- }
272
- } else {
273
- break;
274
- }
275
- }
276
-
277
- itemNumber = prevParagraphsCount + 1;
278
- }
279
-
280
- return [NSString stringWithFormat:@"%ld.", (long)(itemNumber)];
281
- } else {
282
- return @"•";
283
- }
284
- }
285
-
286
- @end
@@ -1 +0,0 @@
1
- {"version":3,"names":["processColor","defaultStyle","h1","fontSize","bold","h2","h3","blockquote","borderColor","borderWidth","gapWidth","color","undefined","codeblock","borderRadius","backgroundColor","code","a","textDecorationLine","mention","ol","marginLeft","markerFontWeight","markerColor","ul","bulletColor","bulletSize","isMentionStyleRecord","mentionStyle","Array","isArray","keys","Object","length","every","key","convertToHtmlStyleInternal","style","mentionIndicators","mentionStyles","forEach","indicator","default","String","olStyles","assignDefaultValues","merged","parseStyle","name","value","endsWith","parseColors","finalStyle","tagName","tagStyle","entries","tagStyles","styleName","styleValue","normalizeHtmlStyle","converted","withDefaults"],"sourceRoot":"../../src","sources":["normalizeHtmlStyle.ts"],"mappings":";;AACA,SAA0BA,YAAY,QAAQ,cAAc;AAM5D,MAAMC,YAAiC,GAAG;EACxCC,EAAE,EAAE;IACFC,QAAQ,EAAE,EAAE;IACZC,IAAI,EAAE;EACR,CAAC;EACDC,EAAE,EAAE;IACFF,QAAQ,EAAE,EAAE;IACZC,IAAI,EAAE;EACR,CAAC;EACDE,EAAE,EAAE;IACFH,QAAQ,EAAE,EAAE;IACZC,IAAI,EAAE;EACR,CAAC;EACDG,UAAU,EAAE;IACVC,WAAW,EAAE,UAAU;IACvBC,WAAW,EAAE,CAAC;IACdC,QAAQ,EAAE,EAAE;IACZC,KAAK,EAAEC;EACT,CAAC;EACDC,SAAS,EAAE;IACTF,KAAK,EAAE,OAAO;IACdG,YAAY,EAAE,CAAC;IACfC,eAAe,EAAE;EACnB,CAAC;EACDC,IAAI,EAAE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SAAS,CAAC;EACnD,OAAOT,WAAW,CAACU,YAAY,CAAC;AAClC,CAAC","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- import type { HtmlStyle } from './EnrichedTextInput';
2
- import type { HtmlStyleInternal } from './EnrichedTextInputNativeComponent';
3
- export declare const normalizeHtmlStyle: (style: HtmlStyle, mentionIndicators: string[]) => HtmlStyleInternal;
4
- //# sourceMappingURL=normalizeHtmlStyle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeHtmlStyle.d.ts","sourceRoot":"","sources":["../../../src/normalizeHtmlStyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AA2K5C,eAAO,MAAM,kBAAkB,GAC7B,OAAO,SAAS,EAChB,mBAAmB,MAAM,EAAE,KAC1B,iBAIF,CAAC"}
File without changes
File without changes
@@ -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)
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
- #import <UIKit/UIKit.h>
3
2
  #import "TextDecorationLineEnum.h"
4
3
  #import "string"
4
+ #import <UIKit/UIKit.h>
5
5
  #import <folly/dynamic.h>
6
6
 
7
7
  @interface MentionStyleProps : NSObject
File without changes
File without changes