react-native-enriched 0.3.0 → 0.4.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.
- package/README.md +6 -4
- package/android/build.gradle +3 -3
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
- package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewPackage.kt → ReactNativeEnrichedPackage.kt} +3 -2
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/AsyncDrawable.kt +40 -8
- package/android/src/main/java/com/swmansion/enriched/common/CheckboxDrawable.kt +81 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/EnrichedConstants.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/EnrichedStyle.kt +57 -0
- package/android/src/main/java/com/swmansion/enriched/{spans/utils → common}/ForceRedrawSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/ResourceManager.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{utils → common/parser}/EnrichedParser.java +126 -99
- package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedSpanFactory.kt +79 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedBlockQuoteSpan.kt +9 -13
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBoldSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCheckboxListSpan.kt +91 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedCodeBlockSpan.kt +8 -12
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH1Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH2Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH3Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH4Span.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH5Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH6Span.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedImageSpan.kt +43 -38
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedInlineCodeSpan.kt +7 -11
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedItalicSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedLinkSpan.kt +7 -11
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedMentionSpan.kt +6 -10
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedOrderedListSpan.kt +12 -21
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedStrikeThroughSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedUnderlineSpan.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedUnorderedListSpan.kt +9 -13
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedBlockSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedHeadingSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedInlineSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedParagraphSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputConnectionWrapper.kt → textinput/EnrichedTextInputConnectionWrapper.kt} +2 -2
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputSpannableFactory.kt +83 -0
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputView.kt → textinput/EnrichedTextInputView.kt} +87 -51
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewLayoutManager.kt → textinput/EnrichedTextInputViewLayoutManager.kt} +1 -1
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewManager.kt → textinput/EnrichedTextInputViewManager.kt} +24 -17
- package/android/src/main/java/com/swmansion/enriched/{MeasurementStore.kt → textinput/MeasurementStore.kt} +5 -4
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/MentionHandler.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeHtmlEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeSelectionEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeStateEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeTextEvent.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputBlurEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputFocusEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputKeyPressEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnLinkDetectedEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionDetectedEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnPasteImagesEvent.kt +47 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnRequestHtmlResultEvent.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBlockQuoteSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBoldSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCheckboxListSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCodeBlockSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH1Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH2Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH3Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH4Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH5Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH6Span.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputImageSpan.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputInlineCodeSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputItalicSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputLinkSpan.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputMentionSpan.kt +18 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputOrderedListSpan.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputStrikeThroughSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnderlineSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnorderedListSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → textinput/spans}/EnrichedSpans.kt +39 -30
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/interfaces/EnrichedInputSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/HtmlStyle.kt +58 -43
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/InlineStyles.kt +4 -4
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ListStyles.kt +77 -26
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParagraphStyles.kt +30 -25
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParametrizedStyles.kt +19 -19
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedEditableFactory.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSelection.kt +15 -14
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpanState.kt +15 -50
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannable.kt +3 -3
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannableStringBuilder.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/RichContentReceiver.kt +127 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/Utils.kt +106 -0
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedSpanWatcher.kt +10 -10
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedTextWatcher.kt +3 -3
- package/android/src/main/new_arch/CMakeLists.txt +1 -1
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.cpp +11 -0
- package/android/src/main/new_arch/ReactNativeEnrichedSpec.h +15 -0
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.h +1 -1
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.h +2 -2
- package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/conversions.h +1 -1
- package/ios/EnrichedTextInputView.h +1 -0
- package/ios/EnrichedTextInputView.mm +274 -55
- package/ios/config/InputConfig.h +10 -0
- package/ios/config/InputConfig.mm +119 -0
- package/ios/extensions/ImageExtension.h +35 -0
- package/ios/extensions/ImageExtension.mm +156 -0
- package/ios/extensions/LayoutManagerExtension.mm +115 -95
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
- package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/RCTComponentViewHelpers.h +21 -0
- package/ios/inputParser/InputParser.mm +135 -8
- package/ios/inputTextView/InputTextView.mm +118 -0
- package/ios/interfaces/ImageAttachment.h +1 -0
- package/ios/interfaces/ImageAttachment.mm +43 -4
- package/ios/interfaces/StyleHeaders.h +13 -2
- package/ios/interfaces/StyleTypeEnum.h +1 -0
- package/ios/internals/EnrichedTextInputViewState.cpp +6 -6
- package/ios/styles/CheckboxListStyle.mm +321 -0
- package/ios/styles/H1Style.mm +3 -0
- package/ios/styles/H2Style.mm +3 -0
- package/ios/styles/H3Style.mm +3 -0
- package/ios/styles/H4Style.mm +3 -0
- package/ios/styles/H5Style.mm +3 -0
- package/ios/styles/H6Style.mm +3 -0
- package/ios/styles/HeadingStyleBase.mm +150 -78
- package/ios/utils/CheckboxHitTestUtils.h +10 -0
- package/ios/utils/CheckboxHitTestUtils.mm +123 -0
- package/ios/utils/ParagraphAttributesUtils.mm +83 -53
- package/ios/utils/TextBlockTapGestureRecognizer.h +17 -0
- package/ios/utils/TextBlockTapGestureRecognizer.mm +56 -0
- package/ios/utils/ZeroWidthSpaceUtils.mm +14 -3
- package/lib/module/EnrichedTextInput.js +36 -11
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/normalizeHtmlStyle.js +6 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -1
- package/lib/module/utils/nullthrows.js +9 -0
- package/lib/module/utils/nullthrows.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +9 -49
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/{EnrichedTextInputNativeComponent.d.ts → spec/EnrichedTextInputNativeComponent.d.ts} +33 -8
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +58 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +2 -2
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -1
- package/lib/typescript/src/utils/nullthrows.d.ts +2 -0
- package/lib/typescript/src/utils/nullthrows.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +1 -1
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/EnrichedTextInput.tsx +49 -62
- package/src/index.tsx +3 -1
- package/src/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
- package/src/types.ts +59 -0
- package/src/utils/normalizeHtmlStyle.ts +8 -5
- package/src/utils/nullthrows.ts +7 -0
- package/src/utils/regexParser.ts +1 -1
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +0 -21
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +0 -17
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +0 -3
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +0 -9
- package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -21
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +0 -22
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +0 -26
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +0 -1
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputComponentDescriptor.h +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.cpp +0 -0
- /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.h +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
- /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "FontExtension.h"
|
|
3
|
+
#import "OccurenceUtils.h"
|
|
4
|
+
#import "ParagraphsUtils.h"
|
|
5
|
+
#import "StyleHeaders.h"
|
|
6
|
+
#import "TextInsertionUtils.h"
|
|
7
|
+
|
|
8
|
+
@implementation CheckboxListStyle {
|
|
9
|
+
EnrichedTextInputView *_input;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
+ (StyleType)getStyleType {
|
|
13
|
+
return CheckboxList;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
+ (BOOL)isParagraphStyle {
|
|
17
|
+
return YES;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (CGFloat)getHeadIndent {
|
|
21
|
+
return [_input->config checkboxListMarginLeft] +
|
|
22
|
+
[_input->config checkboxListGapWidth] +
|
|
23
|
+
[_input->config checkboxListBoxSize];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (instancetype)initWithInput:(id)input {
|
|
27
|
+
self = [super init];
|
|
28
|
+
_input = (EnrichedTextInputView *)input;
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (void)applyStyle:(NSRange)range {
|
|
33
|
+
// Applying a checkbox list style requires a checked value,
|
|
34
|
+
// which is why this method is not implemented.
|
|
35
|
+
// Use 'applyStyleWithCheckedValue' and provide the checked value instead.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)applyStyleWithCheckedValue:(BOOL)checked inRange:(NSRange)range {
|
|
39
|
+
BOOL isStylePresent = [self detectStyle:range];
|
|
40
|
+
if (range.length >= 1) {
|
|
41
|
+
isStylePresent ? [self removeAttributes:range]
|
|
42
|
+
: [self addAttributesWithCheckedValue:checked
|
|
43
|
+
inRange:range
|
|
44
|
+
withTypingAttr:YES];
|
|
45
|
+
} else {
|
|
46
|
+
isStylePresent
|
|
47
|
+
? [self removeTypingAttributes]
|
|
48
|
+
: [self addAttributesWithCheckedValue:checked
|
|
49
|
+
inRange:_input->textView.selectedRange
|
|
50
|
+
withTypingAttr:YES];
|
|
51
|
+
;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
- (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
|
|
56
|
+
[self addAttributesWithCheckedValue:NO
|
|
57
|
+
inRange:range
|
|
58
|
+
withTypingAttr:withTypingAttr];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
- (void)addTypingAttributes {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (void)removeAttributes:(NSRange)range {
|
|
65
|
+
NSArray *paragraphs =
|
|
66
|
+
[ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
|
|
67
|
+
range:range];
|
|
68
|
+
|
|
69
|
+
[_input->textView.textStorage beginEditing];
|
|
70
|
+
|
|
71
|
+
for (NSValue *value in paragraphs) {
|
|
72
|
+
NSRange range = [value rangeValue];
|
|
73
|
+
[_input->textView.textStorage
|
|
74
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
75
|
+
inRange:range
|
|
76
|
+
options:0
|
|
77
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
78
|
+
BOOL *_Nonnull stop) {
|
|
79
|
+
NSMutableParagraphStyle *pStyle =
|
|
80
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
81
|
+
pStyle.textLists = @[];
|
|
82
|
+
pStyle.headIndent = 0;
|
|
83
|
+
pStyle.firstLineHeadIndent = 0;
|
|
84
|
+
[_input->textView.textStorage
|
|
85
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
86
|
+
value:pStyle
|
|
87
|
+
range:range];
|
|
88
|
+
}];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[_input->textView.textStorage endEditing];
|
|
92
|
+
|
|
93
|
+
// also remove typing attributes
|
|
94
|
+
NSMutableDictionary *typingAttrs =
|
|
95
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
96
|
+
NSMutableParagraphStyle *pStyle =
|
|
97
|
+
[typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
|
|
98
|
+
pStyle.textLists = @[];
|
|
99
|
+
pStyle.headIndent = 0;
|
|
100
|
+
pStyle.firstLineHeadIndent = 0;
|
|
101
|
+
typingAttrs[NSParagraphStyleAttributeName] = pStyle;
|
|
102
|
+
_input->textView.typingAttributes = typingAttrs;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)removeTypingAttributes {
|
|
106
|
+
[self removeAttributes:_input->textView.selectedRange];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
|
|
110
|
+
if ([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
|
|
111
|
+
// backspace while the style is active
|
|
112
|
+
|
|
113
|
+
NSRange paragraphRange = [_input->textView.textStorage.string
|
|
114
|
+
paragraphRangeForRange:_input->textView.selectedRange];
|
|
115
|
+
|
|
116
|
+
if (NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
|
|
117
|
+
// a backspace on the very first input's line list point
|
|
118
|
+
// it doesn't run textVieDidChange so we need to manually remove
|
|
119
|
+
// attributes
|
|
120
|
+
[self removeAttributes:paragraphRange];
|
|
121
|
+
return YES;
|
|
122
|
+
} else if (range.location == paragraphRange.location - 1) {
|
|
123
|
+
// same case in other lines; here, the removed range location will be
|
|
124
|
+
// exactly 1 less than paragraph range location
|
|
125
|
+
[self removeAttributes:paragraphRange];
|
|
126
|
+
return YES;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return NO;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// used to make sure checkbox marker is correct when a newline is placed
|
|
133
|
+
- (BOOL)handleNewlinesInRange:(NSRange)range replacementText:(NSString *)text {
|
|
134
|
+
// in a checkbox list and a new text ends with a newline
|
|
135
|
+
if ([self detectStyle:_input->textView.selectedRange] && text.length > 0 &&
|
|
136
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
137
|
+
characterIsMember:[text characterAtIndex:text.length - 1]]) {
|
|
138
|
+
// do the replacement manually
|
|
139
|
+
[TextInsertionUtils replaceText:text
|
|
140
|
+
at:range
|
|
141
|
+
additionalAttributes:nullptr
|
|
142
|
+
input:_input
|
|
143
|
+
withSelection:YES];
|
|
144
|
+
// apply checkbox attributes to the new paragraph
|
|
145
|
+
[self addAttributes:_input->textView.selectedRange withTypingAttr:YES];
|
|
146
|
+
return YES;
|
|
147
|
+
}
|
|
148
|
+
return NO;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
- (void)toggleCheckedAt:(NSUInteger)location {
|
|
152
|
+
if (location >= _input->textView.textStorage.length) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
NSParagraphStyle *pStyle =
|
|
157
|
+
[_input->textView.textStorage attribute:NSParagraphStyleAttributeName
|
|
158
|
+
atIndex:location
|
|
159
|
+
effectiveRange:NULL];
|
|
160
|
+
NSTextList *list = pStyle.textLists.firstObject;
|
|
161
|
+
|
|
162
|
+
BOOL isCurrentlyChecked = [list.markerFormat isEqualToString:@"{checkbox:1}"];
|
|
163
|
+
|
|
164
|
+
NSString *fullText = _input->textView.textStorage.string;
|
|
165
|
+
NSRange paragraphRange =
|
|
166
|
+
[fullText paragraphRangeForRange:NSMakeRange(location, 0)];
|
|
167
|
+
|
|
168
|
+
[self addAttributesWithCheckedValue:!isCurrentlyChecked
|
|
169
|
+
inRange:paragraphRange
|
|
170
|
+
withTypingAttr:NO];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
- (void)addAttributesWithCheckedValue:(BOOL)checked
|
|
174
|
+
inRange:(NSRange)range
|
|
175
|
+
withTypingAttr:(BOOL)withTypingAttr {
|
|
176
|
+
NSString *markerFormat = checked ? @"{checkbox:1}" : @"{checkbox:0}";
|
|
177
|
+
NSTextList *checkboxMarker =
|
|
178
|
+
[[NSTextList alloc] initWithMarkerFormat:markerFormat options:0];
|
|
179
|
+
NSArray *paragraphs =
|
|
180
|
+
[ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
|
|
181
|
+
range:range];
|
|
182
|
+
// if we fill empty lines with zero width spaces, we need to offset later
|
|
183
|
+
// ranges
|
|
184
|
+
NSInteger offset = 0;
|
|
185
|
+
// needed for range adjustments
|
|
186
|
+
NSRange preModificationRange = _input->textView.selectedRange;
|
|
187
|
+
|
|
188
|
+
// let's not emit some weird selection changes or text/html changes
|
|
189
|
+
_input->blockEmitting = YES;
|
|
190
|
+
|
|
191
|
+
for (NSValue *value in paragraphs) {
|
|
192
|
+
// take previous offsets into consideration
|
|
193
|
+
NSRange fixedRange = NSMakeRange([value rangeValue].location + offset,
|
|
194
|
+
[value rangeValue].length);
|
|
195
|
+
|
|
196
|
+
// length 0 with first line, length 1 and newline with some empty lines in
|
|
197
|
+
// the middle
|
|
198
|
+
if (fixedRange.length == 0 ||
|
|
199
|
+
(fixedRange.length == 1 &&
|
|
200
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
201
|
+
characterIsMember:[_input->textView.textStorage.string
|
|
202
|
+
characterAtIndex:fixedRange.location]])) {
|
|
203
|
+
[TextInsertionUtils insertText:@"\u200B"
|
|
204
|
+
at:fixedRange.location
|
|
205
|
+
additionalAttributes:nullptr
|
|
206
|
+
input:_input
|
|
207
|
+
withSelection:NO];
|
|
208
|
+
fixedRange = NSMakeRange(fixedRange.location, fixedRange.length + 1);
|
|
209
|
+
offset += 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
[_input->textView.textStorage
|
|
213
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
214
|
+
inRange:fixedRange
|
|
215
|
+
options:0
|
|
216
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
217
|
+
BOOL *_Nonnull stop) {
|
|
218
|
+
NSMutableParagraphStyle *pStyle =
|
|
219
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
220
|
+
pStyle.textLists = @[ checkboxMarker ];
|
|
221
|
+
pStyle.headIndent = [self getHeadIndent];
|
|
222
|
+
pStyle.firstLineHeadIndent = [self getHeadIndent];
|
|
223
|
+
[_input->textView.textStorage
|
|
224
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
225
|
+
value:pStyle
|
|
226
|
+
range:range];
|
|
227
|
+
}];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// back to emitting
|
|
231
|
+
_input->blockEmitting = NO;
|
|
232
|
+
|
|
233
|
+
if (preModificationRange.length == 0) {
|
|
234
|
+
// fix selection if only one line was possibly made a list and filled with a
|
|
235
|
+
// space
|
|
236
|
+
_input->textView.selectedRange = preModificationRange;
|
|
237
|
+
} else {
|
|
238
|
+
// in other cases, fix the selection with newly made offsets
|
|
239
|
+
_input->textView.selectedRange = NSMakeRange(
|
|
240
|
+
preModificationRange.location, preModificationRange.length + offset);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// also add typing attributes
|
|
244
|
+
if (withTypingAttr) {
|
|
245
|
+
NSMutableDictionary *typingAttrs =
|
|
246
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
247
|
+
NSMutableParagraphStyle *pStyle =
|
|
248
|
+
[typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
|
|
249
|
+
pStyle.textLists = @[ checkboxMarker ];
|
|
250
|
+
pStyle.headIndent = [self getHeadIndent];
|
|
251
|
+
pStyle.firstLineHeadIndent = [self getHeadIndent];
|
|
252
|
+
typingAttrs[NSParagraphStyleAttributeName] = pStyle;
|
|
253
|
+
_input->textView.typingAttributes = typingAttrs;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
258
|
+
NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
|
|
259
|
+
return paragraph != nullptr && paragraph.textLists.count == 1 &&
|
|
260
|
+
[paragraph.textLists.firstObject.markerFormat hasPrefix:@"{checkbox"];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
- (BOOL)detectStyle:(NSRange)range {
|
|
264
|
+
if (range.length >= 1) {
|
|
265
|
+
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
266
|
+
withInput:_input
|
|
267
|
+
inRange:range
|
|
268
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
269
|
+
return [self styleCondition:value range:range];
|
|
270
|
+
}];
|
|
271
|
+
} else {
|
|
272
|
+
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
273
|
+
withInput:_input
|
|
274
|
+
atIndex:range.location
|
|
275
|
+
checkPrevious:YES
|
|
276
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
277
|
+
return [self styleCondition:value range:range];
|
|
278
|
+
}];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
- (BOOL)anyOccurence:(NSRange)range {
|
|
283
|
+
return [OccurenceUtils any:NSParagraphStyleAttributeName
|
|
284
|
+
withInput:_input
|
|
285
|
+
inRange:range
|
|
286
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
287
|
+
return [self styleCondition:value range:range];
|
|
288
|
+
}];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
- (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
|
|
292
|
+
return [OccurenceUtils all:NSParagraphStyleAttributeName
|
|
293
|
+
withInput:_input
|
|
294
|
+
inRange:range
|
|
295
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
296
|
+
return [self styleCondition:value range:range];
|
|
297
|
+
}];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
- (BOOL)getCheckboxStateAt:(NSUInteger)location {
|
|
301
|
+
if (location >= _input->textView.textStorage.length) {
|
|
302
|
+
return NO;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
NSParagraphStyle *style =
|
|
306
|
+
[_input->textView.textStorage attribute:NSParagraphStyleAttributeName
|
|
307
|
+
atIndex:location
|
|
308
|
+
effectiveRange:NULL];
|
|
309
|
+
|
|
310
|
+
if (style && style.textLists.count > 0) {
|
|
311
|
+
NSTextList *list = style.textLists.firstObject;
|
|
312
|
+
|
|
313
|
+
if ([list.markerFormat isEqualToString:@"{checkbox:1}"]) {
|
|
314
|
+
return YES;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return NO;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
@end
|
package/ios/styles/H1Style.mm
CHANGED
package/ios/styles/H2Style.mm
CHANGED
package/ios/styles/H3Style.mm
CHANGED
package/ios/styles/H4Style.mm
CHANGED
package/ios/styles/H5Style.mm
CHANGED