@fendent/react-native-enriched 0.5.2-fork.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/LICENSE +20 -0
- package/README.md +343 -0
- package/ReactNativeEnriched.podspec +31 -0
- package/android/build.gradle +106 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +197 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +72 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.cpp +434 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.h +391 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/Props.cpp +173 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/Props.h +833 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/ShadowNodes.h +23 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/States.h +20 -0
- package/android/gradle.properties +5 -0
- package/android/lint.gradle +70 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/swmansion/enriched/ReactNativeEnrichedPackage.kt +20 -0
- package/android/src/main/java/com/swmansion/enriched/common/AsyncDrawable.kt +126 -0
- 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/common/ForceRedrawSpan.kt +14 -0
- package/android/src/main/java/com/swmansion/enriched/common/GumboNormalizer.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/common/ResourceManager.kt +26 -0
- package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedParser.java +956 -0
- 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 +92 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCodeBlockSpan.kt +81 -0
- 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/common/spans/EnrichedImageSpan.kt +184 -0
- 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 +29 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt +35 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedOrderedListSpan.kt +79 -0
- 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/common/spans/EnrichedUnorderedListSpan.kt +62 -0
- 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/common/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +4 -0
- 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/textinput/EnrichedTextInputView.kt +1120 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewLayoutManager.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt +478 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/MeasurementStore.kt +225 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/MentionHandler.kt +55 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeHtmlEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnChangeSelectionEvent.kt +30 -0
- 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/OnContextMenuItemPressEvent.kt +35 -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/textinput/events/OnMentionDetectedEvent.kt +30 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnMentionEvent.kt +34 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnPasteImagesEvent.kt +47 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnRequestHtmlResultEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnSubmitEditingEvent.kt +29 -0
- 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 +16 -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/EnrichedLineHeightSpan.kt +44 -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/textinput/styles/HtmlStyle.kt +372 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/InlineStyles.kt +164 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ListStyles.kt +263 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ParagraphStyles.kt +434 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt +394 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSelection.kt +320 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpanState.kt +310 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpannable.kt +106 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpannableStringBuilder.kt +24 -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/textinput/watchers/EnrichedSpanWatcher.kt +107 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/watchers/EnrichedTextWatcher.kt +74 -0
- package/android/src/main/new_arch/CMakeLists.txt +62 -0
- package/android/src/main/new_arch/GumboNormalizerJni.cpp +14 -0
- 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/ReactNativeEnrichedSpec/EnrichedTextInputComponentDescriptor.h +35 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputMeasurementManager.cpp +53 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputMeasurementManager.h +25 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputShadowNode.cpp +35 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputShadowNode.h +53 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputState.cpp +9 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/EnrichedTextInputState.h +24 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/conversions.h +27 -0
- package/android/src/main/res/drawable/broken_image.xml +10 -0
- package/cpp/CMakeLists.txt +50 -0
- package/cpp/GumboParser/GumboParser.h +34043 -0
- package/cpp/README.md +59 -0
- package/cpp/parser/GumboNormalizer.c +915 -0
- package/cpp/parser/GumboParser.cpp +16 -0
- package/cpp/parser/GumboParser.hpp +23 -0
- package/cpp/tests/GumboParserTest.cpp +457 -0
- package/ios/EnrichedTextInputView.h +53 -0
- package/ios/EnrichedTextInputView.mm +2360 -0
- package/ios/EnrichedTextInputViewManager.mm +13 -0
- package/ios/attributesManager/AttributesManager.h +17 -0
- package/ios/attributesManager/AttributesManager.mm +195 -0
- package/ios/config/InputConfig.h +104 -0
- package/ios/config/InputConfig.mm +664 -0
- package/ios/extensions/ColorExtension.h +7 -0
- package/ios/extensions/ColorExtension.mm +38 -0
- package/ios/extensions/FontExtension.h +11 -0
- package/ios/extensions/FontExtension.mm +72 -0
- package/ios/extensions/ImageExtension.h +34 -0
- package/ios/extensions/ImageExtension.mm +165 -0
- package/ios/extensions/LayoutManagerExtension.h +6 -0
- package/ios/extensions/LayoutManagerExtension.mm +443 -0
- package/ios/extensions/StringExtension.h +15 -0
- package/ios/extensions/StringExtension.mm +69 -0
- package/ios/generated/ReactNativeEnrichedSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/ReactNativeEnrichedSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.cpp +434 -0
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.h +391 -0
- package/ios/generated/ReactNativeEnrichedSpec/Props.cpp +173 -0
- package/ios/generated/ReactNativeEnrichedSpec/Props.h +833 -0
- package/ios/generated/ReactNativeEnrichedSpec/RCTComponentViewHelpers.h +582 -0
- package/ios/generated/ReactNativeEnrichedSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/ReactNativeEnrichedSpec/ShadowNodes.h +23 -0
- package/ios/generated/ReactNativeEnrichedSpec/States.cpp +16 -0
- package/ios/generated/ReactNativeEnrichedSpec/States.h +20 -0
- package/ios/inputParser/InputParser.h +11 -0
- package/ios/inputParser/InputParser.mm +1463 -0
- package/ios/inputTextView/InputTextView.h +6 -0
- package/ios/inputTextView/InputTextView.mm +285 -0
- package/ios/interfaces/AttributeEntry.h +9 -0
- package/ios/interfaces/AttributeEntry.mm +4 -0
- package/ios/interfaces/BaseStyleProtocol.h +17 -0
- package/ios/interfaces/ImageAttachment.h +11 -0
- package/ios/interfaces/ImageAttachment.mm +107 -0
- package/ios/interfaces/ImageData.h +10 -0
- package/ios/interfaces/ImageData.mm +4 -0
- package/ios/interfaces/LinkData.h +11 -0
- package/ios/interfaces/LinkData.mm +29 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/interfaces/MediaAttachment.h +23 -0
- package/ios/interfaces/MediaAttachment.mm +31 -0
- package/ios/interfaces/MentionParams.h +8 -0
- package/ios/interfaces/MentionParams.mm +4 -0
- package/ios/interfaces/MentionStyleProps.h +13 -0
- package/ios/interfaces/MentionStyleProps.mm +63 -0
- package/ios/interfaces/StyleBase.h +36 -0
- package/ios/interfaces/StyleBase.mm +256 -0
- package/ios/interfaces/StyleHeaders.h +102 -0
- package/ios/interfaces/StylePair.h +9 -0
- package/ios/interfaces/StylePair.mm +4 -0
- package/ios/interfaces/StyleTypeEnum.h +26 -0
- package/ios/interfaces/TextDecorationLineEnum.h +6 -0
- package/ios/interfaces/TextDecorationLineEnum.mm +4 -0
- package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +19 -0
- package/ios/internals/EnrichedTextInputViewShadowNode.h +44 -0
- package/ios/internals/EnrichedTextInputViewShadowNode.mm +103 -0
- package/ios/internals/EnrichedTextInputViewState.cpp +10 -0
- package/ios/internals/EnrichedTextInputViewState.h +22 -0
- package/ios/styles/BlockQuoteStyle.mm +55 -0
- package/ios/styles/BoldStyle.mm +37 -0
- package/ios/styles/CheckboxListStyle.mm +153 -0
- package/ios/styles/CodeBlockStyle.mm +49 -0
- package/ios/styles/H1Style.mm +20 -0
- package/ios/styles/H2Style.mm +20 -0
- package/ios/styles/H3Style.mm +20 -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 +65 -0
- package/ios/styles/ImageStyle.mm +146 -0
- package/ios/styles/InlineCodeStyle.mm +65 -0
- package/ios/styles/ItalicStyle.mm +37 -0
- package/ios/styles/LinkStyle.mm +532 -0
- package/ios/styles/MentionStyle.mm +538 -0
- package/ios/styles/OrderedListStyle.mm +86 -0
- package/ios/styles/StrikethroughStyle.mm +25 -0
- package/ios/styles/UnderlineStyle.mm +24 -0
- package/ios/styles/UnorderedListStyle.mm +86 -0
- package/ios/utils/CheckboxHitTestUtils.h +10 -0
- package/ios/utils/CheckboxHitTestUtils.mm +122 -0
- package/ios/utils/DotReplacementUtils.h +10 -0
- package/ios/utils/DotReplacementUtils.mm +68 -0
- package/ios/utils/KeyboardUtils.h +7 -0
- package/ios/utils/KeyboardUtils.mm +31 -0
- package/ios/utils/OccurenceUtils.h +44 -0
- package/ios/utils/OccurenceUtils.mm +179 -0
- package/ios/utils/ParagraphAttributesUtils.h +15 -0
- package/ios/utils/ParagraphAttributesUtils.mm +257 -0
- package/ios/utils/RangeUtils.h +12 -0
- package/ios/utils/RangeUtils.mm +183 -0
- package/ios/utils/TextBlockTapGestureRecognizer.h +17 -0
- package/ios/utils/TextBlockTapGestureRecognizer.mm +56 -0
- package/ios/utils/TextInsertionUtils.h +17 -0
- package/ios/utils/TextInsertionUtils.mm +64 -0
- package/ios/utils/WordsUtils.h +7 -0
- package/ios/utils/WordsUtils.mm +98 -0
- package/ios/utils/ZeroWidthSpaceUtils.h +9 -0
- package/ios/utils/ZeroWidthSpaceUtils.mm +270 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/native/EnrichedTextInput.js +304 -0
- package/lib/module/native/EnrichedTextInput.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/spec/EnrichedTextInputNativeComponent.ts +517 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/EnrichedTextInputDefaultProps.js +12 -0
- package/lib/module/utils/EnrichedTextInputDefaultProps.js.map +1 -0
- package/lib/module/utils/normalizeHtmlStyle.js +155 -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/package.json +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/native/EnrichedTextInput.d.ts +3 -0
- package/lib/typescript/src/native/EnrichedTextInput.d.ts.map +1 -0
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts +397 -0
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +447 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/EnrichedTextInputDefaultProps.d.ts +10 -0
- package/lib/typescript/src/utils/EnrichedTextInputDefaultProps.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 +226 -0
- package/react-native.config.js +13 -0
- package/src/index.tsx +20 -0
- package/src/native/EnrichedTextInput.tsx +370 -0
- package/src/spec/EnrichedTextInputNativeComponent.ts +517 -0
- package/src/types.ts +499 -0
- package/src/utils/EnrichedTextInputDefaultProps.ts +9 -0
- package/src/utils/normalizeHtmlStyle.ts +199 -0
- package/src/utils/nullthrows.ts +7 -0
- package/src/utils/regexParser.ts +56 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#import "WordsUtils.h"
|
|
2
|
+
|
|
3
|
+
@implementation WordsUtils
|
|
4
|
+
|
|
5
|
+
+ (NSArray<NSDictionary *> *)getAffectedWordsFromText:(NSString *)text
|
|
6
|
+
modificationRange:(NSRange)range {
|
|
7
|
+
if (text.length == 0) {
|
|
8
|
+
return [[NSArray alloc] init];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
NSInteger leftIt = range.location - 1;
|
|
12
|
+
leftIt = MIN(leftIt, NSInteger(text.length - 1));
|
|
13
|
+
if (leftIt > 0) {
|
|
14
|
+
while (leftIt >= 0) {
|
|
15
|
+
unichar charAtIndex = [text characterAtIndex:leftIt];
|
|
16
|
+
if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
|
17
|
+
characterIsMember:charAtIndex]) {
|
|
18
|
+
leftIt += 1;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
leftIt -= 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
leftIt = MAX(0, leftIt);
|
|
25
|
+
leftIt = MIN(NSInteger(text.length - 1), leftIt);
|
|
26
|
+
|
|
27
|
+
NSInteger rightIt = range.location + range.length;
|
|
28
|
+
if (rightIt < text.length - 1) {
|
|
29
|
+
while (rightIt <= text.length - 1) {
|
|
30
|
+
unichar charAtIndex = [text characterAtIndex:rightIt];
|
|
31
|
+
if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
|
32
|
+
characterIsMember:charAtIndex]) {
|
|
33
|
+
rightIt -= 1;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
rightIt += 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
rightIt = MIN(NSInteger(text.length - 1), rightIt);
|
|
40
|
+
|
|
41
|
+
if (leftIt > rightIt) {
|
|
42
|
+
return [[NSArray alloc] init];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
NSMutableArray<NSDictionary *> *separatedWords =
|
|
46
|
+
[[NSMutableArray<NSDictionary *> alloc] init];
|
|
47
|
+
NSMutableString *currentWord = [[NSMutableString alloc] init];
|
|
48
|
+
NSInteger currentRangeStart = leftIt;
|
|
49
|
+
NSInteger currentIdx = leftIt;
|
|
50
|
+
|
|
51
|
+
while (currentIdx <= rightIt) {
|
|
52
|
+
unichar charAtIndex = [text characterAtIndex:currentIdx];
|
|
53
|
+
if ([[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
|
54
|
+
characterIsMember:charAtIndex]) {
|
|
55
|
+
if (currentWord.length > 0) {
|
|
56
|
+
[separatedWords addObject:@{
|
|
57
|
+
@"word" : [currentWord copy],
|
|
58
|
+
@"range" : [NSValue
|
|
59
|
+
valueWithRange:NSMakeRange(currentRangeStart, currentWord.length)]
|
|
60
|
+
}];
|
|
61
|
+
[currentWord setString:@""];
|
|
62
|
+
}
|
|
63
|
+
currentRangeStart = currentIdx + 1;
|
|
64
|
+
} else {
|
|
65
|
+
[currentWord appendFormat:@"%C", charAtIndex];
|
|
66
|
+
}
|
|
67
|
+
currentIdx += 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (currentWord.length > 0) {
|
|
71
|
+
[separatedWords addObject:@{
|
|
72
|
+
@"word" : [currentWord copy],
|
|
73
|
+
@"range" :
|
|
74
|
+
[NSValue valueWithRange:NSMakeRange(currentRangeStart,
|
|
75
|
+
rightIt - currentRangeStart + 1)]
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return separatedWords;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
+ (NSDictionary *)getCurrentWord:(NSString *)text range:(NSRange)range {
|
|
83
|
+
// we just get current word at the cursor
|
|
84
|
+
if (range.length > 0) {
|
|
85
|
+
return nullptr;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
NSArray<NSDictionary *> *words = [WordsUtils getAffectedWordsFromText:text
|
|
89
|
+
modificationRange:range];
|
|
90
|
+
if (words != nullptr && [words count] == 1 &&
|
|
91
|
+
[words firstObject] != nullptr) {
|
|
92
|
+
return [words firstObject];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return nullptr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@end
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
#import "ZeroWidthSpaceUtils.h"
|
|
2
|
+
#import "EnrichedTextInputView.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
#import "TextInsertionUtils.h"
|
|
5
|
+
#import "UIView+React.h"
|
|
6
|
+
|
|
7
|
+
@implementation ZeroWidthSpaceUtils
|
|
8
|
+
+ (void)handleZeroWidthSpacesInInput:(id)input {
|
|
9
|
+
EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
|
|
10
|
+
if (typedInput == nullptr) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
[self removeSpacesIfNeededinInput:typedInput];
|
|
15
|
+
[self addSpacesIfNeededinInput:typedInput];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
+ (void)removeSpacesIfNeededinInput:(EnrichedTextInputView *)input {
|
|
19
|
+
NSMutableArray *indexesToBeRemoved = [[NSMutableArray alloc] init];
|
|
20
|
+
NSRange preRemoveSelection = input->textView.selectedRange;
|
|
21
|
+
|
|
22
|
+
for (int i = 0; i < input->textView.textStorage.string.length; i++) {
|
|
23
|
+
unichar character = [input->textView.textStorage.string characterAtIndex:i];
|
|
24
|
+
if (character == 0x200B) {
|
|
25
|
+
NSRange characterRange = NSMakeRange(i, 1);
|
|
26
|
+
|
|
27
|
+
NSRange paragraphRange = [input->textView.textStorage.string
|
|
28
|
+
paragraphRangeForRange:characterRange];
|
|
29
|
+
// having paragraph longer than 1 character means someone most likely
|
|
30
|
+
// added something and we probably can remove the space
|
|
31
|
+
BOOL removeSpace = paragraphRange.length > 1;
|
|
32
|
+
// exception; 2 characters paragraph with zero width space + newline
|
|
33
|
+
// here, we still need zero width space to keep the empty list items
|
|
34
|
+
if (paragraphRange.length == 2 && paragraphRange.location == i &&
|
|
35
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
36
|
+
characterIsMember:[input->textView.textStorage.string
|
|
37
|
+
characterAtIndex:i + 1]]) {
|
|
38
|
+
removeSpace = NO;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (removeSpace) {
|
|
42
|
+
[indexesToBeRemoved addObject:@(characterRange.location)];
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// zero width spaces with no needsZWS style on them get removed
|
|
47
|
+
if (![self anyZWSStylePresentInRange:characterRange input:input]) {
|
|
48
|
+
[indexesToBeRemoved addObject:@(characterRange.location)];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// do the removing
|
|
54
|
+
NSInteger offset = 0;
|
|
55
|
+
NSInteger postRemoveLocationOffset = 0;
|
|
56
|
+
NSInteger postRemoveLengthOffset = 0;
|
|
57
|
+
for (NSNumber *index in indexesToBeRemoved) {
|
|
58
|
+
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
|
|
59
|
+
[TextInsertionUtils replaceText:@""
|
|
60
|
+
at:replaceRange
|
|
61
|
+
additionalAttributes:nullptr
|
|
62
|
+
input:input
|
|
63
|
+
withSelection:NO];
|
|
64
|
+
offset -= 1;
|
|
65
|
+
if ([index integerValue] < preRemoveSelection.location) {
|
|
66
|
+
postRemoveLocationOffset -= 1;
|
|
67
|
+
}
|
|
68
|
+
if ([index integerValue] >= preRemoveSelection.location &&
|
|
69
|
+
[index integerValue] < NSMaxRange(preRemoveSelection)) {
|
|
70
|
+
postRemoveLengthOffset -= 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// fix the selection if needed
|
|
75
|
+
if ([input->textView isFirstResponder]) {
|
|
76
|
+
input->textView.selectedRange =
|
|
77
|
+
NSMakeRange(preRemoveSelection.location + postRemoveLocationOffset,
|
|
78
|
+
preRemoveSelection.length + postRemoveLengthOffset);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Collects active inline (non-paragraph) meta-attributes from the style
|
|
83
|
+
// dictionary so that ZWS characters carry the same meta-attributes that are
|
|
84
|
+
// currently active in the typing attributes. Only within the currently selected
|
|
85
|
+
// range!
|
|
86
|
+
+ (NSDictionary *)inlineMetaAttributesForInput:(EnrichedTextInputView *)input {
|
|
87
|
+
NSMutableDictionary *metaAttrs = [NSMutableDictionary new];
|
|
88
|
+
for (NSNumber *type in input->stylesDict) {
|
|
89
|
+
StyleBase *style = input->stylesDict[type];
|
|
90
|
+
if (![style isParagraph]) {
|
|
91
|
+
AttributeEntry *entry =
|
|
92
|
+
[style getEntryIfPresent:input->textView.selectedRange];
|
|
93
|
+
if (entry) {
|
|
94
|
+
metaAttrs[entry.key] = entry.value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return metaAttrs.count > 0 ? metaAttrs : nullptr;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
+ (void)addSpacesIfNeededinInput:(EnrichedTextInputView *)input {
|
|
102
|
+
NSMutableArray *indexesToBeInserted = [[NSMutableArray alloc] init];
|
|
103
|
+
NSRange preAddSelection = input->textView.selectedRange;
|
|
104
|
+
|
|
105
|
+
for (NSUInteger i = 0; i < input->textView.textStorage.string.length; i++) {
|
|
106
|
+
unichar character = [input->textView.textStorage.string characterAtIndex:i];
|
|
107
|
+
|
|
108
|
+
if ([[NSCharacterSet newlineCharacterSet] characterIsMember:character]) {
|
|
109
|
+
NSRange characterRange = NSMakeRange(i, 1);
|
|
110
|
+
NSRange paragraphRange = [input->textView.textStorage.string
|
|
111
|
+
paragraphRangeForRange:characterRange];
|
|
112
|
+
|
|
113
|
+
if (paragraphRange.length == 1) {
|
|
114
|
+
if ([self anyZWSStylePresentInRange:characterRange input:input]) {
|
|
115
|
+
// we have an empty list or quote item with no space: add it!
|
|
116
|
+
[indexesToBeInserted addObject:@(paragraphRange.location)];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
NSDictionary *metaAttrs = [self inlineMetaAttributesForInput:input];
|
|
123
|
+
|
|
124
|
+
// do the replacing
|
|
125
|
+
NSInteger offset = 0;
|
|
126
|
+
NSInteger postAddLocationOffset = 0;
|
|
127
|
+
NSInteger postAddLengthOffset = 0;
|
|
128
|
+
for (NSNumber *index in indexesToBeInserted) {
|
|
129
|
+
NSRange replaceRange = NSMakeRange([index integerValue] + offset, 1);
|
|
130
|
+
[TextInsertionUtils replaceText:@"\u200B\n"
|
|
131
|
+
at:replaceRange
|
|
132
|
+
additionalAttributes:metaAttrs
|
|
133
|
+
input:input
|
|
134
|
+
withSelection:NO];
|
|
135
|
+
offset += 1;
|
|
136
|
+
if ([index integerValue] < preAddSelection.location) {
|
|
137
|
+
postAddLocationOffset += 1;
|
|
138
|
+
}
|
|
139
|
+
if ([index integerValue] >= preAddSelection.location &&
|
|
140
|
+
[index integerValue] < NSMaxRange(preAddSelection)) {
|
|
141
|
+
postAddLengthOffset += 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// additional check for last index of the input
|
|
146
|
+
NSRange lastRange = NSMakeRange(input->textView.textStorage.string.length, 0);
|
|
147
|
+
NSRange lastParagraphRange =
|
|
148
|
+
[input->textView.textStorage.string paragraphRangeForRange:lastRange];
|
|
149
|
+
if (lastParagraphRange.length == 0 &&
|
|
150
|
+
[self anyZWSStylePresentInRange:lastRange input:input]) {
|
|
151
|
+
[TextInsertionUtils insertText:@"\u200B"
|
|
152
|
+
at:lastRange.location
|
|
153
|
+
additionalAttributes:metaAttrs
|
|
154
|
+
input:input
|
|
155
|
+
withSelection:NO];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// fix the selection if needed
|
|
159
|
+
if ([input->textView isFirstResponder]) {
|
|
160
|
+
input->textView.selectedRange =
|
|
161
|
+
NSMakeRange(preAddSelection.location + postAddLocationOffset,
|
|
162
|
+
preAddSelection.length + postAddLengthOffset);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
+ (BOOL)handleBackspaceInRange:(NSRange)range
|
|
167
|
+
replacementText:(NSString *)text
|
|
168
|
+
input:(id)input {
|
|
169
|
+
if (![text isEqualToString:@""]) {
|
|
170
|
+
return NO;
|
|
171
|
+
}
|
|
172
|
+
EnrichedTextInputView *typedInput = (EnrichedTextInputView *)input;
|
|
173
|
+
if (typedInput == nullptr) {
|
|
174
|
+
return NO;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Backspace at the very beginning of the input ({0, 0}).
|
|
178
|
+
// Nothing to delete, but if the first paragraph has a needsZWS style,
|
|
179
|
+
// remove it.
|
|
180
|
+
if (range.length == 0 && range.location == 0) {
|
|
181
|
+
NSRange firstParagraphRange = [typedInput->textView.textStorage.string
|
|
182
|
+
paragraphRangeForRange:NSMakeRange(0, 0)];
|
|
183
|
+
if ([self removeZWSStyleInRange:firstParagraphRange input:typedInput]) {
|
|
184
|
+
return YES;
|
|
185
|
+
}
|
|
186
|
+
return NO;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (range.length != 1) {
|
|
190
|
+
return NO;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
unichar character =
|
|
194
|
+
[typedInput->textView.textStorage.string characterAtIndex:range.location];
|
|
195
|
+
// zero-width space got backspaced
|
|
196
|
+
if (character == 0x200B) {
|
|
197
|
+
// in such case: remove the whole line without the endline if there is one
|
|
198
|
+
|
|
199
|
+
NSRange paragraphRange =
|
|
200
|
+
[typedInput->textView.textStorage.string paragraphRangeForRange:range];
|
|
201
|
+
NSRange removalRange = paragraphRange;
|
|
202
|
+
// if whole paragraph gets removed then 0 length for style removal
|
|
203
|
+
NSRange styleRemovalRange = NSMakeRange(paragraphRange.location, 0);
|
|
204
|
+
|
|
205
|
+
if ([[NSCharacterSet newlineCharacterSet]
|
|
206
|
+
characterIsMember:[typedInput->textView.textStorage.string
|
|
207
|
+
characterAtIndex:NSMaxRange(paragraphRange) -
|
|
208
|
+
1]]) {
|
|
209
|
+
// if endline is there, don't remove it
|
|
210
|
+
removalRange =
|
|
211
|
+
NSMakeRange(paragraphRange.location, paragraphRange.length - 1);
|
|
212
|
+
// if endline is left then 1 length for style removal
|
|
213
|
+
styleRemovalRange = NSMakeRange(paragraphRange.location, 1);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// remove the ZWS (keep the newline if present)
|
|
217
|
+
[TextInsertionUtils replaceText:@""
|
|
218
|
+
at:removalRange
|
|
219
|
+
additionalAttributes:nullptr
|
|
220
|
+
input:typedInput
|
|
221
|
+
withSelection:YES];
|
|
222
|
+
|
|
223
|
+
// and then remove associated styling
|
|
224
|
+
[self removeZWSStyleInRange:styleRemovalRange input:typedInput];
|
|
225
|
+
|
|
226
|
+
return YES;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Backspace at the start of a paragraph that has a ZWS-needing style.
|
|
230
|
+
// The character being deleted is the newline at the end of the previous
|
|
231
|
+
// paragraph. Instead of letting iOS merge the two lines, just remove the
|
|
232
|
+
// style from the current paragraph.
|
|
233
|
+
if ([[NSCharacterSet newlineCharacterSet] characterIsMember:character]) {
|
|
234
|
+
NSUInteger nextParaStart = NSMaxRange(range);
|
|
235
|
+
if (nextParaStart < typedInput->textView.textStorage.string.length) {
|
|
236
|
+
NSRange nextParagraphRange = [typedInput->textView.textStorage.string
|
|
237
|
+
paragraphRangeForRange:NSMakeRange(nextParaStart, 0)];
|
|
238
|
+
if ([self removeZWSStyleInRange:nextParagraphRange input:typedInput]) {
|
|
239
|
+
return YES;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return NO;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
+ (BOOL)anyZWSStylePresentInRange:(NSRange)range
|
|
248
|
+
input:(EnrichedTextInputView *)input {
|
|
249
|
+
for (NSNumber *type in input->stylesDict) {
|
|
250
|
+
StyleBase *style = input->stylesDict[type];
|
|
251
|
+
if ([style needsZWS] && [style detect:range]) {
|
|
252
|
+
return YES;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return NO;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
+ (BOOL)removeZWSStyleInRange:(NSRange)range
|
|
259
|
+
input:(EnrichedTextInputView *)input {
|
|
260
|
+
for (NSNumber *type in input->stylesDict) {
|
|
261
|
+
StyleBase *style = input->stylesDict[type];
|
|
262
|
+
if ([style needsZWS] && [style detect:range]) {
|
|
263
|
+
[style remove:range withDirtyRange:YES];
|
|
264
|
+
return YES;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return NO;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EnrichedTextInput"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,+BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import EnrichedTextInputNativeComponent, { Commands } from '../spec/EnrichedTextInputNativeComponent';
|
|
6
|
+
import { normalizeHtmlStyle } from "../utils/normalizeHtmlStyle.js";
|
|
7
|
+
import { toNativeRegexConfig } from "../utils/regexParser.js";
|
|
8
|
+
import { nullthrows } from "../utils/nullthrows.js";
|
|
9
|
+
import { ENRICHED_TEXT_INPUT_DEFAULT_PROPS } from "../utils/EnrichedTextInputDefaultProps.js";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const warnMentionIndicators = indicator => {
|
|
12
|
+
console.warn(`Looks like you are trying to set a "${indicator}" but it's not in the mentionIndicators prop`);
|
|
13
|
+
};
|
|
14
|
+
export const EnrichedTextInput = ({
|
|
15
|
+
ref,
|
|
16
|
+
autoFocus,
|
|
17
|
+
editable = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.editable,
|
|
18
|
+
mentionIndicators = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.mentionIndicators.slice(),
|
|
19
|
+
defaultValue,
|
|
20
|
+
placeholder,
|
|
21
|
+
placeholderTextColor,
|
|
22
|
+
cursorColor,
|
|
23
|
+
selectionColor,
|
|
24
|
+
style,
|
|
25
|
+
autoCapitalize = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.autoCapitalize,
|
|
26
|
+
htmlStyle = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.htmlStyle,
|
|
27
|
+
linkRegex: _linkRegex,
|
|
28
|
+
onFocus,
|
|
29
|
+
onBlur,
|
|
30
|
+
onChangeText,
|
|
31
|
+
onChangeHtml,
|
|
32
|
+
onChangeState,
|
|
33
|
+
onLinkDetected,
|
|
34
|
+
onMentionDetected,
|
|
35
|
+
onStartMention,
|
|
36
|
+
onChangeMention,
|
|
37
|
+
onEndMention,
|
|
38
|
+
onChangeSelection,
|
|
39
|
+
onKeyPress,
|
|
40
|
+
onSubmitEditing,
|
|
41
|
+
returnKeyType,
|
|
42
|
+
returnKeyLabel,
|
|
43
|
+
submitBehavior,
|
|
44
|
+
contextMenuItems,
|
|
45
|
+
androidExperimentalSynchronousEvents = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.androidExperimentalSynchronousEvents,
|
|
46
|
+
useHtmlNormalizer = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.useHtmlNormalizer,
|
|
47
|
+
scrollEnabled = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.scrollEnabled,
|
|
48
|
+
...rest
|
|
49
|
+
}) => {
|
|
50
|
+
const nativeRef = useRef(null);
|
|
51
|
+
const nextHtmlRequestId = useRef(1);
|
|
52
|
+
const pendingHtmlRequests = useRef(new Map());
|
|
53
|
+
|
|
54
|
+
// Store onPress callbacks in a ref so native only receives serializable data
|
|
55
|
+
const contextMenuCallbacksRef = useRef(new Map());
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const callbacksMap = new Map();
|
|
58
|
+
if (contextMenuItems) {
|
|
59
|
+
for (const item of contextMenuItems) {
|
|
60
|
+
callbacksMap.set(item.text, item.onPress);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
contextMenuCallbacksRef.current = callbacksMap;
|
|
64
|
+
}, [contextMenuItems]);
|
|
65
|
+
const nativeContextMenuItems = useMemo(() => contextMenuItems?.filter(item => item.visible !== false).map(item => ({
|
|
66
|
+
text: item.text
|
|
67
|
+
})), [contextMenuItems]);
|
|
68
|
+
const handleContextMenuItemPress = useCallback(e => {
|
|
69
|
+
const {
|
|
70
|
+
itemText,
|
|
71
|
+
selectedText,
|
|
72
|
+
selectionStart,
|
|
73
|
+
selectionEnd,
|
|
74
|
+
styleState
|
|
75
|
+
} = e.nativeEvent;
|
|
76
|
+
const callback = contextMenuCallbacksRef.current.get(itemText);
|
|
77
|
+
callback?.({
|
|
78
|
+
text: selectedText,
|
|
79
|
+
selection: {
|
|
80
|
+
start: selectionStart,
|
|
81
|
+
end: selectionEnd
|
|
82
|
+
},
|
|
83
|
+
styleState
|
|
84
|
+
});
|
|
85
|
+
}, []);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const pendingRequests = pendingHtmlRequests.current;
|
|
88
|
+
return () => {
|
|
89
|
+
pendingRequests.forEach(({
|
|
90
|
+
reject
|
|
91
|
+
}) => {
|
|
92
|
+
reject(new Error('Component unmounted'));
|
|
93
|
+
});
|
|
94
|
+
pendingRequests.clear();
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
const normalizedHtmlStyle = useMemo(() => normalizeHtmlStyle(htmlStyle, mentionIndicators), [htmlStyle, mentionIndicators]);
|
|
98
|
+
const linkRegex = useMemo(() => toNativeRegexConfig(_linkRegex), [_linkRegex]);
|
|
99
|
+
useImperativeHandle(ref, () => ({
|
|
100
|
+
measureInWindow: callback => {
|
|
101
|
+
nullthrows(nativeRef.current).measureInWindow(callback);
|
|
102
|
+
},
|
|
103
|
+
measure: callback => {
|
|
104
|
+
nullthrows(nativeRef.current).measure(callback);
|
|
105
|
+
},
|
|
106
|
+
measureLayout: (relativeToNativeComponentRef, onSuccess, onFail) => {
|
|
107
|
+
nullthrows(nativeRef.current).measureLayout(relativeToNativeComponentRef, onSuccess, onFail);
|
|
108
|
+
},
|
|
109
|
+
setNativeProps: nativeProps => {
|
|
110
|
+
nullthrows(nativeRef.current).setNativeProps(nativeProps);
|
|
111
|
+
},
|
|
112
|
+
focus: () => {
|
|
113
|
+
Commands.focus(nullthrows(nativeRef.current));
|
|
114
|
+
},
|
|
115
|
+
blur: () => {
|
|
116
|
+
Commands.blur(nullthrows(nativeRef.current));
|
|
117
|
+
},
|
|
118
|
+
setValue: value => {
|
|
119
|
+
Commands.setValue(nullthrows(nativeRef.current), value);
|
|
120
|
+
},
|
|
121
|
+
insertText: (text, start, end) => {
|
|
122
|
+
const s = start ?? -1;
|
|
123
|
+
const e = end ?? s;
|
|
124
|
+
Commands.insertText(nullthrows(nativeRef.current), text, s, e);
|
|
125
|
+
},
|
|
126
|
+
getHTML: () => {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
const requestId = nextHtmlRequestId.current++;
|
|
129
|
+
pendingHtmlRequests.current.set(requestId, {
|
|
130
|
+
resolve,
|
|
131
|
+
reject
|
|
132
|
+
});
|
|
133
|
+
Commands.requestHTML(nullthrows(nativeRef.current), requestId);
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
toggleBold: () => {
|
|
137
|
+
Commands.toggleBold(nullthrows(nativeRef.current));
|
|
138
|
+
},
|
|
139
|
+
toggleItalic: () => {
|
|
140
|
+
Commands.toggleItalic(nullthrows(nativeRef.current));
|
|
141
|
+
},
|
|
142
|
+
toggleUnderline: () => {
|
|
143
|
+
Commands.toggleUnderline(nullthrows(nativeRef.current));
|
|
144
|
+
},
|
|
145
|
+
toggleStrikeThrough: () => {
|
|
146
|
+
Commands.toggleStrikeThrough(nullthrows(nativeRef.current));
|
|
147
|
+
},
|
|
148
|
+
toggleInlineCode: () => {
|
|
149
|
+
Commands.toggleInlineCode(nullthrows(nativeRef.current));
|
|
150
|
+
},
|
|
151
|
+
toggleH1: () => {
|
|
152
|
+
Commands.toggleH1(nullthrows(nativeRef.current));
|
|
153
|
+
},
|
|
154
|
+
toggleH2: () => {
|
|
155
|
+
Commands.toggleH2(nullthrows(nativeRef.current));
|
|
156
|
+
},
|
|
157
|
+
toggleH3: () => {
|
|
158
|
+
Commands.toggleH3(nullthrows(nativeRef.current));
|
|
159
|
+
},
|
|
160
|
+
toggleH4: () => {
|
|
161
|
+
Commands.toggleH4(nullthrows(nativeRef.current));
|
|
162
|
+
},
|
|
163
|
+
toggleH5: () => {
|
|
164
|
+
Commands.toggleH5(nullthrows(nativeRef.current));
|
|
165
|
+
},
|
|
166
|
+
toggleH6: () => {
|
|
167
|
+
Commands.toggleH6(nullthrows(nativeRef.current));
|
|
168
|
+
},
|
|
169
|
+
toggleCodeBlock: () => {
|
|
170
|
+
Commands.toggleCodeBlock(nullthrows(nativeRef.current));
|
|
171
|
+
},
|
|
172
|
+
toggleBlockQuote: () => {
|
|
173
|
+
Commands.toggleBlockQuote(nullthrows(nativeRef.current));
|
|
174
|
+
},
|
|
175
|
+
toggleOrderedList: () => {
|
|
176
|
+
Commands.toggleOrderedList(nullthrows(nativeRef.current));
|
|
177
|
+
},
|
|
178
|
+
toggleUnorderedList: () => {
|
|
179
|
+
Commands.toggleUnorderedList(nullthrows(nativeRef.current));
|
|
180
|
+
},
|
|
181
|
+
toggleCheckboxList: checked => {
|
|
182
|
+
Commands.toggleCheckboxList(nullthrows(nativeRef.current), checked);
|
|
183
|
+
},
|
|
184
|
+
setLink: (start, end, text, url) => {
|
|
185
|
+
Commands.addLink(nullthrows(nativeRef.current), start, end, text, url);
|
|
186
|
+
},
|
|
187
|
+
removeLink: (start, end) => {
|
|
188
|
+
Commands.removeLink(nullthrows(nativeRef.current), start, end);
|
|
189
|
+
},
|
|
190
|
+
setImage: (uri, width, height) => {
|
|
191
|
+
Commands.addImage(nullthrows(nativeRef.current), uri, width, height);
|
|
192
|
+
},
|
|
193
|
+
setMention: (indicator, text, attributes) => {
|
|
194
|
+
// Codegen does not support objects as Commands parameters, so we stringify attributes
|
|
195
|
+
const parsedAttributes = JSON.stringify(attributes ?? {});
|
|
196
|
+
Commands.addMention(nullthrows(nativeRef.current), indicator, text, parsedAttributes);
|
|
197
|
+
},
|
|
198
|
+
startMention: indicator => {
|
|
199
|
+
if (!mentionIndicators?.includes(indicator)) {
|
|
200
|
+
warnMentionIndicators(indicator);
|
|
201
|
+
}
|
|
202
|
+
Commands.startMention(nullthrows(nativeRef.current), indicator);
|
|
203
|
+
},
|
|
204
|
+
setSelection: (start, end) => {
|
|
205
|
+
Commands.setSelection(nullthrows(nativeRef.current), start, end);
|
|
206
|
+
}
|
|
207
|
+
}));
|
|
208
|
+
const handleMentionEvent = e => {
|
|
209
|
+
const mentionText = e.nativeEvent.text;
|
|
210
|
+
const mentionIndicator = e.nativeEvent.indicator;
|
|
211
|
+
if (typeof mentionText === 'string') {
|
|
212
|
+
if (mentionText === '') {
|
|
213
|
+
onStartMention?.(mentionIndicator);
|
|
214
|
+
} else {
|
|
215
|
+
onChangeMention?.({
|
|
216
|
+
indicator: mentionIndicator,
|
|
217
|
+
text: mentionText
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
} else if (mentionText === null) {
|
|
221
|
+
onEndMention?.(mentionIndicator);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const handleLinkDetected = e => {
|
|
225
|
+
const {
|
|
226
|
+
text,
|
|
227
|
+
url,
|
|
228
|
+
start,
|
|
229
|
+
end
|
|
230
|
+
} = e.nativeEvent;
|
|
231
|
+
onLinkDetected?.({
|
|
232
|
+
text,
|
|
233
|
+
url,
|
|
234
|
+
start,
|
|
235
|
+
end
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
const handleMentionDetected = e => {
|
|
239
|
+
const {
|
|
240
|
+
text,
|
|
241
|
+
indicator,
|
|
242
|
+
payload
|
|
243
|
+
} = e.nativeEvent;
|
|
244
|
+
const attributes = JSON.parse(payload);
|
|
245
|
+
onMentionDetected?.({
|
|
246
|
+
text,
|
|
247
|
+
indicator,
|
|
248
|
+
attributes
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const handleRequestHtmlResult = e => {
|
|
252
|
+
const {
|
|
253
|
+
requestId,
|
|
254
|
+
html
|
|
255
|
+
} = e.nativeEvent;
|
|
256
|
+
const pending = pendingHtmlRequests.current.get(requestId);
|
|
257
|
+
if (!pending) return;
|
|
258
|
+
if (html === null || typeof html !== 'string') {
|
|
259
|
+
pending.reject(new Error('Failed to parse HTML'));
|
|
260
|
+
} else {
|
|
261
|
+
pending.resolve(html);
|
|
262
|
+
}
|
|
263
|
+
pendingHtmlRequests.current.delete(requestId);
|
|
264
|
+
};
|
|
265
|
+
return /*#__PURE__*/_jsx(EnrichedTextInputNativeComponent, {
|
|
266
|
+
ref: nativeRef,
|
|
267
|
+
mentionIndicators: mentionIndicators,
|
|
268
|
+
editable: editable,
|
|
269
|
+
autoFocus: autoFocus,
|
|
270
|
+
defaultValue: defaultValue,
|
|
271
|
+
placeholder: placeholder,
|
|
272
|
+
placeholderTextColor: placeholderTextColor,
|
|
273
|
+
cursorColor: cursorColor,
|
|
274
|
+
selectionColor: selectionColor,
|
|
275
|
+
style: style,
|
|
276
|
+
autoCapitalize: autoCapitalize,
|
|
277
|
+
htmlStyle: normalizedHtmlStyle,
|
|
278
|
+
linkRegex: linkRegex,
|
|
279
|
+
onInputFocus: onFocus,
|
|
280
|
+
onInputBlur: onBlur,
|
|
281
|
+
onChangeText: onChangeText,
|
|
282
|
+
onChangeHtml: onChangeHtml,
|
|
283
|
+
isOnChangeHtmlSet: onChangeHtml !== undefined,
|
|
284
|
+
isOnChangeTextSet: onChangeText !== undefined,
|
|
285
|
+
onChangeState: onChangeState,
|
|
286
|
+
onLinkDetected: handleLinkDetected,
|
|
287
|
+
onMentionDetected: handleMentionDetected,
|
|
288
|
+
onMention: handleMentionEvent,
|
|
289
|
+
onChangeSelection: onChangeSelection,
|
|
290
|
+
onRequestHtmlResult: handleRequestHtmlResult,
|
|
291
|
+
onInputKeyPress: onKeyPress,
|
|
292
|
+
contextMenuItems: nativeContextMenuItems,
|
|
293
|
+
onContextMenuItemPress: handleContextMenuItemPress,
|
|
294
|
+
onSubmitEditing: onSubmitEditing,
|
|
295
|
+
returnKeyType: returnKeyType,
|
|
296
|
+
returnKeyLabel: returnKeyLabel,
|
|
297
|
+
submitBehavior: submitBehavior,
|
|
298
|
+
androidExperimentalSynchronousEvents: androidExperimentalSynchronousEvents,
|
|
299
|
+
useHtmlNormalizer: useHtmlNormalizer,
|
|
300
|
+
scrollEnabled: scrollEnabled,
|
|
301
|
+
...rest
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
//# sourceMappingURL=EnrichedTextInput.js.map
|