react-native-enriched 0.1.3 → 0.1.4
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.
- package/README.md +36 -648
- package/ReactNativeEnriched.podspec +1 -1
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +8 -5
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +2 -2
- package/android/src/main/new_arch/CMakeLists.txt +13 -9
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +2 -2
- package/ios/EnrichedTextInputView.mm +56 -53
- package/ios/internals/EnrichedTextInputViewShadowNode.mm +4 -1
- package/ios/styles/BlockQuoteStyle.mm +18 -23
- package/ios/styles/BoldStyle.mm +5 -2
- package/ios/styles/HeadingStyleBase.mm +37 -5
- package/ios/styles/InlineCodeStyle.mm +5 -2
- package/ios/styles/ItalicStyle.mm +5 -5
- package/ios/styles/OrderedListStyle.mm +18 -23
- package/ios/styles/StrikethroughStyle.mm +5 -2
- package/ios/styles/UnderlineStyle.mm +5 -2
- package/ios/styles/UnorderedListStyle.mm +18 -23
- package/ios/utils/OccurenceUtils.h +6 -0
- package/ios/utils/OccurenceUtils.mm +31 -0
- package/ios/utils/ParagraphAttributesUtils.h +6 -0
- package/ios/utils/ParagraphAttributesUtils.mm +67 -0
- package/ios/utils/StyleHeaders.h +2 -0
- package/ios/utils/ZeroWidthSpaceUtils.mm +14 -6
- package/package.json +4 -4
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
withInput:(EnrichedTextInputView* _Nonnull)input
|
|
10
10
|
inRange:(NSRange)range
|
|
11
11
|
withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition;
|
|
12
|
+
+ (BOOL)detect
|
|
13
|
+
:(NSAttributedStringKey _Nonnull)key
|
|
14
|
+
withInput:(EnrichedTextInputView* _Nonnull)input
|
|
15
|
+
atIndex:(NSUInteger)index
|
|
16
|
+
checkPrevious:(BOOL)check
|
|
17
|
+
withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition;
|
|
12
18
|
+ (BOOL)detectMultiple
|
|
13
19
|
:(NSArray<NSAttributedStringKey> *_Nonnull)keys
|
|
14
20
|
withInput:(EnrichedTextInputView* _Nonnull)input
|
|
@@ -19,6 +19,37 @@
|
|
|
19
19
|
return totalLength == range.length;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// checkPrevious flag is used for styles like lists or blockquotes
|
|
23
|
+
// it means that first character of paragraph will be checked instead if the detection is not in input's selected range and at the end of the input
|
|
24
|
+
+ (BOOL)detect
|
|
25
|
+
:(NSAttributedStringKey _Nonnull)key
|
|
26
|
+
withInput:(EnrichedTextInputView* _Nonnull)input
|
|
27
|
+
atIndex:(NSUInteger)index
|
|
28
|
+
checkPrevious:(BOOL)checkPrev
|
|
29
|
+
withCondition:(BOOL (NS_NOESCAPE ^_Nonnull)(id _Nullable value, NSRange range))condition
|
|
30
|
+
{
|
|
31
|
+
NSRange detectionRange = NSMakeRange(index, 0);
|
|
32
|
+
id attrValue;
|
|
33
|
+
if(NSEqualRanges(input->textView.selectedRange, detectionRange)) {
|
|
34
|
+
attrValue = input->textView.typingAttributes[key];
|
|
35
|
+
} else if(index == input->textView.textStorage.string.length) {
|
|
36
|
+
if(checkPrev) {
|
|
37
|
+
NSRange paragraphRange = [input->textView.textStorage.string paragraphRangeForRange:detectionRange];
|
|
38
|
+
if(paragraphRange.location == detectionRange.location) {
|
|
39
|
+
return NO;
|
|
40
|
+
} else {
|
|
41
|
+
return [self detect:key withInput:input inRange:NSMakeRange(paragraphRange.location, 1) withCondition:condition];
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
return NO;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
NSRange attrRange = NSMakeRange(0, 0);
|
|
48
|
+
attrValue = [input->textView.textStorage attribute:key atIndex:index effectiveRange:&attrRange];
|
|
49
|
+
}
|
|
50
|
+
return condition(attrValue, detectionRange);
|
|
51
|
+
}
|
|
52
|
+
|
|
22
53
|
+ (BOOL)detectMultiple
|
|
23
54
|
:(NSArray<NSAttributedStringKey> *_Nonnull)keys
|
|
24
55
|
withInput:(EnrichedTextInputView* _Nonnull)input
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#import "ParagraphAttributesUtils.h"
|
|
2
|
+
#import "EnrichedTextInputView.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
#import "ParagraphsUtils.h"
|
|
5
|
+
#import "TextInsertionUtils.h"
|
|
6
|
+
|
|
7
|
+
@implementation ParagraphAttributesUtils
|
|
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
|
+
// hence the solution - reset typing attributes
|
|
12
|
+
+ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text input:(id)input {
|
|
13
|
+
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
|
+
|
|
18
|
+
if(typedInput == nullptr) {
|
|
19
|
+
return NO;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// we make sure it was a backspace (text with 0 length) and it deleted something (range longer than 0)
|
|
23
|
+
if(text.length > 0 || range.length == 0) {
|
|
24
|
+
return NO;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// find a non-newline range of the paragraph
|
|
28
|
+
NSRange paragraphRange = [typedInput->textView.textStorage.string paragraphRangeForRange:range];
|
|
29
|
+
|
|
30
|
+
NSArray *paragraphs = [ParagraphsUtils getNonNewlineRangesIn:typedInput->textView range:paragraphRange];
|
|
31
|
+
if(paragraphs.count == 0) {
|
|
32
|
+
return NO;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
NSRange nonNewlineRange = [(NSValue *)paragraphs.firstObject rangeValue];
|
|
36
|
+
|
|
37
|
+
// if the backspace removes the whole content of a paragraph (possibly more but has to start where the paragraph starts), we remove the typing attributes
|
|
38
|
+
if(range.location == nonNewlineRange.location && range.length >= nonNewlineRange.length) {
|
|
39
|
+
// for lists and quotes we want to remove the characters but keep attribtues so that a zero width space appears here
|
|
40
|
+
// so we do the removing manually and reapply attributes
|
|
41
|
+
if([ulStyle detectStyle:nonNewlineRange]) {
|
|
42
|
+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
|
|
43
|
+
[ulStyle addAttributes:NSMakeRange(range.location, 0)];
|
|
44
|
+
return YES;
|
|
45
|
+
}
|
|
46
|
+
if([olStyle detectStyle:nonNewlineRange]) {
|
|
47
|
+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
|
|
48
|
+
[olStyle addAttributes:NSMakeRange(range.location, 0)];
|
|
49
|
+
return YES;
|
|
50
|
+
}
|
|
51
|
+
if([bqStyle detectStyle:nonNewlineRange]) {
|
|
52
|
+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
|
|
53
|
+
[bqStyle addAttributes:NSMakeRange(range.location, 0)];
|
|
54
|
+
return YES;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// do the replacement manually
|
|
58
|
+
[TextInsertionUtils replaceText:text at:range additionalAttributes:nullptr input:typedInput withSelection:YES];
|
|
59
|
+
// reset typing attribtues
|
|
60
|
+
typedInput->textView.typingAttributes = typedInput->defaultTypingAttributes;
|
|
61
|
+
return YES;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return NO;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@end
|
package/ios/utils/StyleHeaders.h
CHANGED
|
@@ -52,19 +52,23 @@
|
|
|
52
52
|
|
|
53
53
|
// do the removing
|
|
54
54
|
NSInteger offset = 0;
|
|
55
|
-
NSInteger
|
|
55
|
+
NSInteger postRemoveLocationOffset = 0;
|
|
56
|
+
NSInteger postRemoveLengthOffset = 0;
|
|
56
57
|
for(NSNumber *index in indexesToBeRemoved) {
|
|
57
58
|
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
|
|
58
59
|
[TextInsertionUtils replaceText:@"" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
|
|
59
60
|
offset -= 1;
|
|
60
61
|
if([index integerValue] < preRemoveSelection.location) {
|
|
61
|
-
|
|
62
|
+
postRemoveLocationOffset -= 1;
|
|
63
|
+
}
|
|
64
|
+
if([index integerValue] >= preRemoveSelection.location && [index integerValue] < NSMaxRange(preRemoveSelection)) {
|
|
65
|
+
postRemoveLengthOffset -= 1;
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
// fix the selection if needed
|
|
66
70
|
if([input->textView isFirstResponder]) {
|
|
67
|
-
input->textView.selectedRange = NSMakeRange(preRemoveSelection.location +
|
|
71
|
+
input->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveLocationOffset, preRemoveSelection.length + postRemoveLengthOffset);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
@@ -93,13 +97,17 @@
|
|
|
93
97
|
|
|
94
98
|
// do the replacing
|
|
95
99
|
NSInteger offset = 0;
|
|
96
|
-
NSInteger
|
|
100
|
+
NSInteger postAddLocationOffset = 0;
|
|
101
|
+
NSInteger postAddLengthOffset = 0;
|
|
97
102
|
for(NSNumber *index in indexesToBeInserted) {
|
|
98
103
|
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
|
|
99
104
|
[TextInsertionUtils replaceText:@"\u200B\n" at:replaceRange additionalAttributes:nullptr input:input withSelection:NO];
|
|
100
105
|
offset += 1;
|
|
101
106
|
if([index integerValue] < preAddSelection.location) {
|
|
102
|
-
|
|
107
|
+
postAddLocationOffset += 1;
|
|
108
|
+
}
|
|
109
|
+
if([index integerValue] >= preAddSelection.location && [index integerValue] < NSMaxRange(preAddSelection)) {
|
|
110
|
+
postAddLengthOffset += 1;
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
|
|
@@ -112,7 +120,7 @@
|
|
|
112
120
|
|
|
113
121
|
// fix the selection if needed
|
|
114
122
|
if([input->textView isFirstResponder]) {
|
|
115
|
-
input->textView.selectedRange = NSMakeRange(preAddSelection.location +
|
|
123
|
+
input->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddLocationOffset, preAddSelection.length + postAddLengthOffset);
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-enriched",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Rich Text Editor component for React Native",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
],
|
|
49
49
|
"repository": {
|
|
50
50
|
"type": "git",
|
|
51
|
-
"url": "git+https://github.com/software-mansion
|
|
51
|
+
"url": "git+https://github.com/software-mansion/react-native-enriched.git"
|
|
52
52
|
},
|
|
53
53
|
"author": "Software Mansion <contact@swmansion.com> (https://swmansion.com)",
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"bugs": {
|
|
56
|
-
"url": "https://github.com/software-mansion
|
|
56
|
+
"url": "https://github.com/software-mansion/react-native-enriched/issues"
|
|
57
57
|
},
|
|
58
|
-
"homepage": "https://github.com/software-mansion
|
|
58
|
+
"homepage": "https://github.com/software-mansion/react-native-enriched#readme",
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"registry": "https://registry.npmjs.org/"
|
|
61
61
|
},
|