react-native-enriched 0.2.1 → 0.4.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.
- package/README.md +21 -16
- package/android/build.gradle +77 -72
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -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/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.cpp +276 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.h +239 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +10 -0
- package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +251 -0
- package/android/gradle.properties +5 -5
- package/android/lint.gradle +70 -0
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewPackage.kt → ReactNativeEnrichedPackage.kt} +4 -5
- package/android/src/main/java/com/swmansion/enriched/{utils → common}/AsyncDrawable.kt +50 -15
- package/android/src/main/java/com/swmansion/enriched/common/CheckboxDrawable.kt +81 -0
- package/android/src/main/java/com/swmansion/enriched/common/EnrichedConstants.kt +11 -0
- 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 +3 -2
- 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 +228 -160
- package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedSpanFactory.kt +79 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBlockQuoteSpan.kt +53 -0
- 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 +12 -14
- 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 +68 -51
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedInlineCodeSpan.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedItalicSpan.kt +12 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedLinkSpan.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt +35 -0
- package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedOrderedListSpan.kt +21 -29
- 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 +13 -17
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedBlockSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedHeadingSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedInlineSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedParagraphSpan.kt +5 -0
- 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 +2 -3
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputConnectionWrapper.kt +140 -0
- 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} +322 -157
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewLayoutManager.kt → textinput/EnrichedTextInputViewLayoutManager.kt} +4 -2
- package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewManager.kt → textinput/EnrichedTextInputViewManager.kt} +182 -66
- package/android/src/main/java/com/swmansion/enriched/{MeasurementStore.kt → textinput/MeasurementStore.kt} +75 -25
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/MentionHandler.kt +22 -12
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeHtmlEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeSelectionEvent.kt +11 -10
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeStateEvent.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeTextEvent.kt +30 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputBlurEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputFocusEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnInputKeyPressEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnLinkDetectedEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionDetectedEvent.kt +11 -10
- package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionEvent.kt +10 -9
- 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 +2 -3
- 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/textinput/spans/EnrichedSpans.kt +241 -0
- 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 +129 -57
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/InlineStyles.kt +30 -13
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ListStyles.kt +263 -0
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParagraphStyles.kt +94 -34
- package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParametrizedStyles.kt +143 -67
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSelection.kt +84 -54
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpanState.kt +304 -0
- package/android/src/main/java/com/swmansion/enriched/{utils/Utils.kt → textinput/utils/EnrichedSpannable.kt} +22 -31
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpannableStringBuilder.kt +16 -0
- 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 +56 -24
- package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedTextWatcher.kt +37 -14
- package/android/src/main/new_arch/CMakeLists.txt +7 -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/ReactNativeEnrichedSpec/conversions.h +46 -0
- package/ios/EnrichedTextInputView.h +2 -1
- package/ios/EnrichedTextInputView.mm +603 -60
- package/ios/config/InputConfig.h +28 -0
- package/ios/config/InputConfig.mm +237 -8
- package/ios/extensions/ImageExtension.h +35 -0
- package/ios/extensions/ImageExtension.mm +156 -0
- package/ios/{utils → extensions}/LayoutManagerExtension.mm +115 -95
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.cpp +276 -0
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.h +239 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +10 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +251 -0
- package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/RCTComponentViewHelpers.h +95 -0
- package/ios/inputParser/InputParser.mm +218 -18
- package/ios/inputTextView/InputTextView.mm +118 -0
- package/ios/{attachments → interfaces}/ImageAttachment.h +1 -0
- package/ios/interfaces/ImageAttachment.mm +46 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/{utils → interfaces}/MentionStyleProps.mm +2 -2
- package/ios/{utils → interfaces}/StyleHeaders.h +22 -1
- package/ios/{utils → interfaces}/StyleTypeEnum.h +4 -0
- package/ios/internals/EnrichedTextInputViewState.cpp +6 -6
- package/ios/styles/BlockQuoteStyle.mm +5 -5
- package/ios/styles/BoldStyle.mm +21 -6
- package/ios/styles/CheckboxListStyle.mm +321 -0
- package/ios/styles/CodeBlockStyle.mm +5 -5
- 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 +20 -0
- package/ios/styles/H5Style.mm +20 -0
- package/ios/styles/H6Style.mm +20 -0
- package/ios/styles/HeadingStyleBase.mm +161 -72
- package/ios/styles/ImageStyle.mm +5 -5
- package/ios/styles/InlineCodeStyle.mm +30 -19
- package/ios/styles/ItalicStyle.mm +5 -5
- package/ios/styles/LinkStyle.mm +98 -40
- package/ios/styles/MentionStyle.mm +4 -4
- package/ios/styles/OrderedListStyle.mm +5 -5
- package/ios/styles/StrikethroughStyle.mm +5 -5
- package/ios/styles/UnderlineStyle.mm +5 -5
- package/ios/styles/UnorderedListStyle.mm +5 -5
- package/ios/utils/CheckboxHitTestUtils.h +10 -0
- package/ios/utils/CheckboxHitTestUtils.mm +123 -0
- package/ios/utils/ParagraphAttributesUtils.h +4 -0
- package/ios/utils/ParagraphAttributesUtils.mm +142 -45
- package/ios/utils/ParagraphsUtils.mm +4 -4
- 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 +57 -11
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +175 -18
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +18 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
- package/lib/module/utils/nullthrows.js +9 -0
- package/lib/module/utils/nullthrows.js.map +1 -0
- package/lib/module/utils/regexParser.js +46 -0
- package/lib/module/utils/regexParser.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +20 -51
- 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} +154 -18
- 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 +4 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
- 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 +3 -0
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
- package/package.json +13 -9
- package/src/EnrichedTextInput.tsx +88 -63
- package/src/index.tsx +5 -1
- package/src/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +175 -18
- package/src/types.ts +59 -0
- package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +20 -5
- package/src/utils/nullthrows.ts +7 -0
- package/src/utils/regexParser.ts +56 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +0 -128
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +0 -102
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +0 -28
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +0 -24
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +0 -44
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +0 -23
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +0 -27
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +0 -15
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +0 -30
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +0 -42
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +0 -136
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +0 -14
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +0 -14
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +0 -4
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +0 -8
- package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +0 -172
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +0 -204
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +0 -22
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +0 -26
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +0 -26
- package/ios/attachments/ImageAttachment.mm +0 -34
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +0 -128
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +0 -102
- package/lib/module/normalizeHtmlStyle.js.map +0 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
- package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
- /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/{utils → extensions}/ColorExtension.h +0 -0
- /package/ios/{utils → extensions}/ColorExtension.mm +0 -0
- /package/ios/{utils → extensions}/FontExtension.h +0 -0
- /package/ios/{utils → extensions}/FontExtension.mm +0 -0
- /package/ios/{utils → extensions}/LayoutManagerExtension.h +0 -0
- /package/ios/{utils → extensions}/StringExtension.h +0 -0
- /package/ios/{utils → extensions}/StringExtension.mm +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
- /package/ios/{utils → interfaces}/BaseStyleProtocol.h +0 -0
- /package/ios/{utils → interfaces}/ImageData.h +0 -0
- /package/ios/{utils → interfaces}/ImageData.mm +0 -0
- /package/ios/{utils → interfaces}/LinkData.h +0 -0
- /package/ios/{utils → interfaces}/LinkData.mm +0 -0
- /package/ios/{attachments → interfaces}/MediaAttachment.h +0 -0
- /package/ios/{attachments → interfaces}/MediaAttachment.mm +0 -0
- /package/ios/{utils → interfaces}/MentionParams.h +0 -0
- /package/ios/{utils → interfaces}/MentionParams.mm +0 -0
- /package/ios/{utils → interfaces}/MentionStyleProps.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.mm +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
package/ios/styles/LinkStyle.mm
CHANGED
|
@@ -23,6 +23,49 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
23
23
|
return NO;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
+ (NSRegularExpression *)fullRegex {
|
|
27
|
+
static NSRegularExpression *regex;
|
|
28
|
+
static dispatch_once_t onceToken;
|
|
29
|
+
dispatch_once(&onceToken, ^{
|
|
30
|
+
regex =
|
|
31
|
+
[NSRegularExpression regularExpressionWithPattern:
|
|
32
|
+
@"http(s)?:\\/\\/"
|
|
33
|
+
@"www\\.[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-"
|
|
34
|
+
@"z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
35
|
+
options:0
|
|
36
|
+
error:nullptr];
|
|
37
|
+
});
|
|
38
|
+
return regex;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
+ (NSRegularExpression *)wwwRegex {
|
|
42
|
+
static NSRegularExpression *regex;
|
|
43
|
+
static dispatch_once_t onceToken;
|
|
44
|
+
dispatch_once(&onceToken, ^{
|
|
45
|
+
regex =
|
|
46
|
+
[NSRegularExpression regularExpressionWithPattern:
|
|
47
|
+
@"www\\.[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-"
|
|
48
|
+
@"z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
49
|
+
options:0
|
|
50
|
+
error:nullptr];
|
|
51
|
+
});
|
|
52
|
+
return regex;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
+ (NSRegularExpression *)bareRegex {
|
|
56
|
+
static NSRegularExpression *regex;
|
|
57
|
+
static dispatch_once_t onceToken;
|
|
58
|
+
dispatch_once(&onceToken, ^{
|
|
59
|
+
regex =
|
|
60
|
+
[NSRegularExpression regularExpressionWithPattern:
|
|
61
|
+
@"[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-z]{2,"
|
|
62
|
+
@"6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
63
|
+
options:0
|
|
64
|
+
error:nullptr];
|
|
65
|
+
});
|
|
66
|
+
return regex;
|
|
67
|
+
}
|
|
68
|
+
|
|
26
69
|
- (instancetype)initWithInput:(id)input {
|
|
27
70
|
self = [super init];
|
|
28
71
|
_input = (EnrichedTextInputView *)input;
|
|
@@ -121,7 +164,7 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
121
164
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
122
165
|
}
|
|
123
166
|
|
|
124
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
167
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
125
168
|
NSString *linkValue = (NSString *)value;
|
|
126
169
|
return linkValue != nullptr;
|
|
127
170
|
}
|
|
@@ -133,7 +176,7 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
133
176
|
withInput:_input
|
|
134
177
|
inRange:range
|
|
135
178
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
136
|
-
return [self styleCondition:value:range];
|
|
179
|
+
return [self styleCondition:value range:range];
|
|
137
180
|
}];
|
|
138
181
|
return onlyLinks ? [self isSingleLinkIn:range] : NO;
|
|
139
182
|
} else {
|
|
@@ -147,7 +190,7 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
147
190
|
withInput:_input
|
|
148
191
|
inRange:range
|
|
149
192
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
150
|
-
return [self styleCondition:value:range];
|
|
193
|
+
return [self styleCondition:value range:range];
|
|
151
194
|
}];
|
|
152
195
|
}
|
|
153
196
|
|
|
@@ -157,7 +200,7 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
157
200
|
withInput:_input
|
|
158
201
|
inRange:range
|
|
159
202
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
160
|
-
return [self styleCondition:value:range];
|
|
203
|
+
return [self styleCondition:value range:range];
|
|
161
204
|
}];
|
|
162
205
|
}
|
|
163
206
|
|
|
@@ -346,6 +389,13 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
346
389
|
|
|
347
390
|
// handles detecting and removing automatic links
|
|
348
391
|
- (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange {
|
|
392
|
+
LinkRegexConfig *linkRegexConfig = [_input->config linkRegexConfig];
|
|
393
|
+
|
|
394
|
+
// no automatic links with isDisabled
|
|
395
|
+
if (linkRegexConfig.isDisabled) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
349
399
|
InlineCodeStyle *inlineCodeStyle =
|
|
350
400
|
[_input->stylesDict objectForKey:@([InlineCodeStyle getStyleType])];
|
|
351
401
|
MentionStyle *mentionStyle =
|
|
@@ -392,42 +442,28 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
392
442
|
return;
|
|
393
443
|
}
|
|
394
444
|
|
|
395
|
-
|
|
396
|
-
regularExpressionWithPattern:@"http(s)?:\\/\\/"
|
|
397
|
-
@"www\\.[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-"
|
|
398
|
-
@"z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
399
|
-
options:0
|
|
400
|
-
error:nullptr];
|
|
401
|
-
NSRegularExpression *wwwRegex = [NSRegularExpression
|
|
402
|
-
regularExpressionWithPattern:@"www\\.[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-"
|
|
403
|
-
@"z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
404
|
-
options:0
|
|
405
|
-
error:nullptr];
|
|
406
|
-
NSRegularExpression *bareRegex = [NSRegularExpression
|
|
407
|
-
regularExpressionWithPattern:@"[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-z]{2,"
|
|
408
|
-
@"6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
|
|
409
|
-
options:0
|
|
410
|
-
error:nullptr];
|
|
445
|
+
// all conditions are met; try matching the word to a proper regex
|
|
411
446
|
|
|
412
447
|
NSString *regexPassedUrl = nullptr;
|
|
448
|
+
NSRange matchingRange = NSMakeRange(0, word.length);
|
|
413
449
|
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
} else
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
450
|
+
if (linkRegexConfig.isDefault) {
|
|
451
|
+
// use default regex
|
|
452
|
+
regexPassedUrl = [self tryMatchingDefaultLinkRegex:word
|
|
453
|
+
matchRange:matchingRange];
|
|
454
|
+
} else {
|
|
455
|
+
// use user defined regex if it exists
|
|
456
|
+
NSRegularExpression *userRegex = [_input->config parsedLinkRegex];
|
|
457
|
+
|
|
458
|
+
if (userRegex == nullptr) {
|
|
459
|
+
// fallback to default regex
|
|
460
|
+
regexPassedUrl = [self tryMatchingDefaultLinkRegex:word
|
|
461
|
+
matchRange:matchingRange];
|
|
462
|
+
} else if ([userRegex numberOfMatchesInString:word
|
|
463
|
+
options:0
|
|
464
|
+
range:matchingRange]) {
|
|
465
|
+
regexPassedUrl = word;
|
|
466
|
+
}
|
|
431
467
|
}
|
|
432
468
|
|
|
433
469
|
if (regexPassedUrl != nullptr) {
|
|
@@ -449,7 +485,29 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
449
485
|
// emit onLinkDetected if style was added
|
|
450
486
|
[_input emitOnLinkDetectedEvent:word url:regexPassedUrl range:wordRange];
|
|
451
487
|
}
|
|
488
|
+
} else if ([self anyOccurence:wordRange]) {
|
|
489
|
+
// there was some automatic link (because anyOccurence is true and we are
|
|
490
|
+
// sure there are no manual links) still, it didn't pass any regex - needs
|
|
491
|
+
// to be removed
|
|
492
|
+
[self removeAttributes:wordRange];
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
- (NSString *)tryMatchingDefaultLinkRegex:(NSString *)word
|
|
497
|
+
matchRange:(NSRange)range {
|
|
498
|
+
if ([[LinkStyle fullRegex] numberOfMatchesInString:word
|
|
499
|
+
options:0
|
|
500
|
+
range:range] ||
|
|
501
|
+
[[LinkStyle wwwRegex] numberOfMatchesInString:word
|
|
502
|
+
options:0
|
|
503
|
+
range:range] ||
|
|
504
|
+
[[LinkStyle bareRegex] numberOfMatchesInString:word
|
|
505
|
+
options:0
|
|
506
|
+
range:range]) {
|
|
507
|
+
return word;
|
|
452
508
|
}
|
|
509
|
+
|
|
510
|
+
return nullptr;
|
|
453
511
|
}
|
|
454
512
|
|
|
455
513
|
// handles refreshing manual links
|
|
@@ -556,14 +614,14 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
556
614
|
withInput:_input
|
|
557
615
|
inRange:wordRange
|
|
558
616
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
559
|
-
return [self styleCondition:value:range];
|
|
617
|
+
return [self styleCondition:value range:range];
|
|
560
618
|
}];
|
|
561
619
|
BOOL anyManual =
|
|
562
620
|
[OccurenceUtils any:ManualLinkAttributeName
|
|
563
621
|
withInput:_input
|
|
564
622
|
inRange:wordRange
|
|
565
623
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
566
|
-
return [self styleCondition:value:range];
|
|
624
|
+
return [self styleCondition:value range:range];
|
|
567
625
|
}];
|
|
568
626
|
|
|
569
627
|
// both manual and automatic links are somewhere - delete!
|
|
@@ -579,7 +637,7 @@ static NSString *const AutomaticLinkAttributeName =
|
|
|
579
637
|
withInput:_input
|
|
580
638
|
inRange:wordRange
|
|
581
639
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
582
|
-
return [self styleCondition:value:range];
|
|
640
|
+
return [self styleCondition:value range:range];
|
|
583
641
|
}];
|
|
584
642
|
|
|
585
643
|
// only one link might be present!
|
|
@@ -136,7 +136,7 @@ static NSString *const MentionAttributeName = @"MentionAttributeName";
|
|
|
136
136
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
139
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
140
140
|
MentionParams *params = (MentionParams *)value;
|
|
141
141
|
return params != nullptr;
|
|
142
142
|
}
|
|
@@ -147,7 +147,7 @@ static NSString *const MentionAttributeName = @"MentionAttributeName";
|
|
|
147
147
|
withInput:_input
|
|
148
148
|
inRange:range
|
|
149
149
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
150
|
-
return [self styleCondition:value:range];
|
|
150
|
+
return [self styleCondition:value range:range];
|
|
151
151
|
}];
|
|
152
152
|
} else {
|
|
153
153
|
return [self getMentionParamsAt:range.location] != nullptr;
|
|
@@ -159,7 +159,7 @@ static NSString *const MentionAttributeName = @"MentionAttributeName";
|
|
|
159
159
|
withInput:_input
|
|
160
160
|
inRange:range
|
|
161
161
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
162
|
-
return [self styleCondition:value:range];
|
|
162
|
+
return [self styleCondition:value range:range];
|
|
163
163
|
}];
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -168,7 +168,7 @@ static NSString *const MentionAttributeName = @"MentionAttributeName";
|
|
|
168
168
|
withInput:_input
|
|
169
169
|
inRange:range
|
|
170
170
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
171
|
-
return [self styleCondition:value:range];
|
|
171
|
+
return [self styleCondition:value range:range];
|
|
172
172
|
}];
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
return NO;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
238
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
239
239
|
NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
|
|
240
240
|
return paragraph != nullptr && paragraph.textLists.count == 1 &&
|
|
241
241
|
paragraph.textLists.firstObject.markerFormat ==
|
|
@@ -248,7 +248,7 @@
|
|
|
248
248
|
withInput:_input
|
|
249
249
|
inRange:range
|
|
250
250
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
251
|
-
return [self styleCondition:value:range];
|
|
251
|
+
return [self styleCondition:value range:range];
|
|
252
252
|
}];
|
|
253
253
|
} else {
|
|
254
254
|
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
@@ -256,7 +256,7 @@
|
|
|
256
256
|
atIndex:range.location
|
|
257
257
|
checkPrevious:YES
|
|
258
258
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
259
|
-
return [self styleCondition:value:range];
|
|
259
|
+
return [self styleCondition:value range:range];
|
|
260
260
|
}];
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
withInput:_input
|
|
267
267
|
inRange:range
|
|
268
268
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
269
|
-
return [self styleCondition:value:range];
|
|
269
|
+
return [self styleCondition:value range:range];
|
|
270
270
|
}];
|
|
271
271
|
}
|
|
272
272
|
|
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
withInput:_input
|
|
276
276
|
inRange:range
|
|
277
277
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
278
|
-
return [self styleCondition:value:range];
|
|
278
|
+
return [self styleCondition:value range:range];
|
|
279
279
|
}];
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
59
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
60
60
|
NSNumber *strikethroughStyle = (NSNumber *)value;
|
|
61
61
|
return strikethroughStyle != nullptr &&
|
|
62
62
|
[strikethroughStyle intValue] != NSUnderlineStyleNone;
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
withInput:_input
|
|
69
69
|
inRange:range
|
|
70
70
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
71
|
-
return [self styleCondition:value:range];
|
|
71
|
+
return [self styleCondition:value range:range];
|
|
72
72
|
}];
|
|
73
73
|
} else {
|
|
74
74
|
return [OccurenceUtils detect:NSStrikethroughStyleAttributeName
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
atIndex:range.location
|
|
77
77
|
checkPrevious:NO
|
|
78
78
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
79
|
-
return [self styleCondition:value:range];
|
|
79
|
+
return [self styleCondition:value range:range];
|
|
80
80
|
}];
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
withInput:_input
|
|
87
87
|
inRange:range
|
|
88
88
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
89
|
-
return [self styleCondition:value:range];
|
|
89
|
+
return [self styleCondition:value range:range];
|
|
90
90
|
}];
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
withInput:_input
|
|
96
96
|
inRange:range
|
|
97
97
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
98
|
-
return [self styleCondition:value:range];
|
|
98
|
+
return [self styleCondition:value range:range];
|
|
99
99
|
}];
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
return conflicted;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
94
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
95
95
|
NSNumber *underlineStyle = (NSNumber *)value;
|
|
96
96
|
return underlineStyle != nullptr &&
|
|
97
97
|
[underlineStyle intValue] != NSUnderlineStyleNone &&
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
withInput:_input
|
|
106
106
|
inRange:range
|
|
107
107
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
108
|
-
return [self styleCondition:value:range];
|
|
108
|
+
return [self styleCondition:value range:range];
|
|
109
109
|
}];
|
|
110
110
|
} else {
|
|
111
111
|
return [OccurenceUtils detect:NSUnderlineStyleAttributeName
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
atIndex:range.location
|
|
114
114
|
checkPrevious:NO
|
|
115
115
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
116
|
-
return [self styleCondition:value:range];
|
|
116
|
+
return [self styleCondition:value range:range];
|
|
117
117
|
}];
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
withInput:_input
|
|
124
124
|
inRange:range
|
|
125
125
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
126
|
-
return [self styleCondition:value:range];
|
|
126
|
+
return [self styleCondition:value range:range];
|
|
127
127
|
}];
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
withInput:_input
|
|
133
133
|
inRange:range
|
|
134
134
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
135
|
-
return [self styleCondition:value:range];
|
|
135
|
+
return [self styleCondition:value range:range];
|
|
136
136
|
}];
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
return NO;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
237
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
238
238
|
NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
|
|
239
239
|
return paragraph != nullptr && paragraph.textLists.count == 1 &&
|
|
240
240
|
paragraph.textLists.firstObject.markerFormat == NSTextListMarkerDisc;
|
|
@@ -246,7 +246,7 @@
|
|
|
246
246
|
withInput:_input
|
|
247
247
|
inRange:range
|
|
248
248
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
249
|
-
return [self styleCondition:value:range];
|
|
249
|
+
return [self styleCondition:value range:range];
|
|
250
250
|
}];
|
|
251
251
|
} else {
|
|
252
252
|
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
atIndex:range.location
|
|
255
255
|
checkPrevious:YES
|
|
256
256
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
257
|
-
return [self styleCondition:value:range];
|
|
257
|
+
return [self styleCondition:value range:range];
|
|
258
258
|
}];
|
|
259
259
|
}
|
|
260
260
|
}
|
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
withInput:_input
|
|
265
265
|
inRange:range
|
|
266
266
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
267
|
-
return [self styleCondition:value:range];
|
|
267
|
+
return [self styleCondition:value range:range];
|
|
268
268
|
}];
|
|
269
269
|
}
|
|
270
270
|
|
|
@@ -273,7 +273,7 @@
|
|
|
273
273
|
withInput:_input
|
|
274
274
|
inRange:range
|
|
275
275
|
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
276
|
-
return [self styleCondition:value:range];
|
|
276
|
+
return [self styleCondition:value range:range];
|
|
277
277
|
}];
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#import "CheckboxHitTestUtils.h"
|
|
2
|
+
#import "EnrichedTextInputView.h"
|
|
3
|
+
#import "InputConfig.h"
|
|
4
|
+
#import "StyleHeaders.h"
|
|
5
|
+
|
|
6
|
+
static const CGFloat kCheckboxHitSlopLeft = 8.0;
|
|
7
|
+
static const CGFloat kCheckboxHitSlopVertical = 6.0;
|
|
8
|
+
|
|
9
|
+
@implementation CheckboxHitTestUtils
|
|
10
|
+
|
|
11
|
+
// MARK: - Coordinate helpers
|
|
12
|
+
|
|
13
|
+
+ (CGPoint)containerPointFromViewPoint:(CGPoint)point
|
|
14
|
+
textView:(UITextView *)textView {
|
|
15
|
+
return CGPointMake(point.x - textView.textContainerInset.left,
|
|
16
|
+
point.y - textView.textContainerInset.top);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// MARK: - Glyph lookup
|
|
20
|
+
|
|
21
|
+
+ (NSUInteger)glyphIndexAtContainerPoint:(CGPoint)point
|
|
22
|
+
textView:(UITextView *)textView {
|
|
23
|
+
return [textView.layoutManager glyphIndexForPoint:point
|
|
24
|
+
inTextContainer:textView.textContainer
|
|
25
|
+
fractionOfDistanceThroughGlyph:nil];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// MARK: - Checkbox detection
|
|
29
|
+
|
|
30
|
+
+ (BOOL)isCheckboxGlyph:(NSUInteger)glyphIndex
|
|
31
|
+
inInput:(EnrichedTextInputView *)input {
|
|
32
|
+
UITextView *textView = input->textView;
|
|
33
|
+
NSLayoutManager *layoutManager = textView.layoutManager;
|
|
34
|
+
NSTextStorage *storage = textView.textStorage;
|
|
35
|
+
|
|
36
|
+
NSUInteger charIndex =
|
|
37
|
+
[layoutManager characterIndexForGlyphAtIndex:glyphIndex];
|
|
38
|
+
|
|
39
|
+
if (charIndex >= storage.length) {
|
|
40
|
+
return NO;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
CheckboxListStyle *checkboxListStyle =
|
|
44
|
+
(CheckboxListStyle *)
|
|
45
|
+
input->stylesDict[@([CheckboxListStyle getStyleType])];
|
|
46
|
+
|
|
47
|
+
if (!checkboxListStyle) {
|
|
48
|
+
return NO;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [checkboxListStyle detectStyle:NSMakeRange(charIndex, 0)];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MARK: - Checkbox rect
|
|
55
|
+
|
|
56
|
+
+ (CGRect)checkboxRectForGlyphIndex:(NSUInteger)glyphIndex
|
|
57
|
+
inInput:(EnrichedTextInputView *)input {
|
|
58
|
+
UITextView *textView = input->textView;
|
|
59
|
+
NSLayoutManager *layoutManager = textView.layoutManager;
|
|
60
|
+
InputConfig *config = input->config;
|
|
61
|
+
|
|
62
|
+
if (!config) {
|
|
63
|
+
return CGRectNull;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
CGRect lineRect = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex
|
|
67
|
+
effectiveRange:nil];
|
|
68
|
+
|
|
69
|
+
CGFloat originX = lineRect.origin.x + config.checkboxListMarginLeft;
|
|
70
|
+
|
|
71
|
+
CGFloat originY = lineRect.origin.y +
|
|
72
|
+
(lineRect.size.height - config.checkboxListBoxSize) / 2.0;
|
|
73
|
+
|
|
74
|
+
return CGRectMake(originX, originY, config.checkboxListBoxSize,
|
|
75
|
+
config.checkboxListBoxSize);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// MARK: - Hit rect
|
|
79
|
+
|
|
80
|
+
+ (CGRect)expandedHitRectFromCheckboxRect:(CGRect)rect {
|
|
81
|
+
if (CGRectIsNull(rect))
|
|
82
|
+
return rect;
|
|
83
|
+
|
|
84
|
+
return CGRectInset(rect, -kCheckboxHitSlopLeft, -kCheckboxHitSlopVertical);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// MARK: - Public API
|
|
88
|
+
|
|
89
|
+
+ (NSInteger)hitTestCheckboxAtPoint:(CGPoint)point
|
|
90
|
+
inInput:(EnrichedTextInputView *)input {
|
|
91
|
+
UITextView *textView = input->textView;
|
|
92
|
+
|
|
93
|
+
CGPoint containerPoint = [self containerPointFromViewPoint:point
|
|
94
|
+
textView:textView];
|
|
95
|
+
|
|
96
|
+
NSUInteger glyphIndex = [self glyphIndexAtContainerPoint:containerPoint
|
|
97
|
+
textView:textView];
|
|
98
|
+
|
|
99
|
+
if (glyphIndex == NSNotFound) {
|
|
100
|
+
return -1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (![self isCheckboxGlyph:glyphIndex inInput:input]) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
CGRect checkboxRect = [self checkboxRectForGlyphIndex:glyphIndex
|
|
108
|
+
inInput:input];
|
|
109
|
+
|
|
110
|
+
if (CGRectIsNull(checkboxRect)) {
|
|
111
|
+
return -1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
CGRect hitRect = [self expandedHitRectFromCheckboxRect:checkboxRect];
|
|
115
|
+
|
|
116
|
+
if (!CGRectContainsPoint(hitRect, containerPoint)) {
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return [textView.layoutManager characterIndexForGlyphAtIndex:glyphIndex];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@end
|
|
@@ -8,4 +8,8 @@
|
|
|
8
8
|
+ (BOOL)handleParagraphStylesMergeOnBackspace:(NSRange)range
|
|
9
9
|
replacementText:(NSString *)text
|
|
10
10
|
input:(id)input;
|
|
11
|
+
+ (BOOL)handleResetTypingAttributesOnBackspace:(NSRange)range
|
|
12
|
+
replacementText:(NSString *)text
|
|
13
|
+
input:(id)input;
|
|
14
|
+
+ (BOOL)isParagraphEmpty:(NSRange)range inString:(NSString *)string;
|
|
11
15
|
@end
|