@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,22 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <memory>
|
|
3
|
+
|
|
4
|
+
namespace facebook::react {
|
|
5
|
+
|
|
6
|
+
class EnrichedTextInputViewState {
|
|
7
|
+
public:
|
|
8
|
+
EnrichedTextInputViewState()
|
|
9
|
+
: forceHeightRecalculationCounter_(0), componentViewRef_(nullptr) {}
|
|
10
|
+
EnrichedTextInputViewState(int counter, std::shared_ptr<void> ref) {
|
|
11
|
+
forceHeightRecalculationCounter_ = counter;
|
|
12
|
+
componentViewRef_ = ref;
|
|
13
|
+
}
|
|
14
|
+
int getForceHeightRecalculationCounter() const;
|
|
15
|
+
std::shared_ptr<void> getComponentViewRef() const;
|
|
16
|
+
|
|
17
|
+
private:
|
|
18
|
+
int forceHeightRecalculationCounter_{};
|
|
19
|
+
std::shared_ptr<void> componentViewRef_{};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#import "ColorExtension.h"
|
|
2
|
+
#import "EnrichedTextInputView.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
|
|
5
|
+
@implementation BlockQuoteStyle
|
|
6
|
+
|
|
7
|
+
+ (StyleType)getType {
|
|
8
|
+
return BlockQuote;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (NSString *)getValue {
|
|
12
|
+
return @"EnrichedBlockQuote";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (BOOL)isParagraph {
|
|
16
|
+
return YES;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (BOOL)needsZWS {
|
|
20
|
+
return YES;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)applyStyling:(NSRange)range {
|
|
24
|
+
CGFloat indent = [self.input->config blockquoteBorderWidth] +
|
|
25
|
+
[self.input->config blockquoteGapWidth];
|
|
26
|
+
[self.input->textView.textStorage
|
|
27
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
28
|
+
inRange:range
|
|
29
|
+
options:0
|
|
30
|
+
usingBlock:^(id _Nullable value, NSRange subRange,
|
|
31
|
+
BOOL *_Nonnull stop) {
|
|
32
|
+
NSMutableParagraphStyle *pStyle =
|
|
33
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
34
|
+
pStyle.headIndent = indent;
|
|
35
|
+
pStyle.firstLineHeadIndent = indent;
|
|
36
|
+
[self.input->textView.textStorage
|
|
37
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
38
|
+
value:pStyle
|
|
39
|
+
range:subRange];
|
|
40
|
+
}];
|
|
41
|
+
|
|
42
|
+
UIColor *bqColor = [self.input->config blockquoteColor];
|
|
43
|
+
[self.input->textView.textStorage addAttribute:NSForegroundColorAttributeName
|
|
44
|
+
value:bqColor
|
|
45
|
+
range:range];
|
|
46
|
+
[self.input->textView.textStorage addAttribute:NSUnderlineColorAttributeName
|
|
47
|
+
value:bqColor
|
|
48
|
+
range:range];
|
|
49
|
+
[self.input->textView.textStorage
|
|
50
|
+
addAttribute:NSStrikethroughColorAttributeName
|
|
51
|
+
value:bqColor
|
|
52
|
+
range:range];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "FontExtension.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
|
|
5
|
+
@implementation BoldStyle : StyleBase
|
|
6
|
+
|
|
7
|
+
+ (StyleType)getType {
|
|
8
|
+
return Bold;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (NSString *)getKey {
|
|
12
|
+
return @"EnrichedBold";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (BOOL)isParagraph {
|
|
16
|
+
return NO;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (void)applyStyling:(NSRange)range {
|
|
20
|
+
[self.input->textView.textStorage
|
|
21
|
+
enumerateAttribute:NSFontAttributeName
|
|
22
|
+
inRange:range
|
|
23
|
+
options:0
|
|
24
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
25
|
+
BOOL *_Nonnull stop) {
|
|
26
|
+
UIFont *font = (UIFont *)value;
|
|
27
|
+
if (font != nullptr) {
|
|
28
|
+
UIFont *newFont = [font setBold];
|
|
29
|
+
[self.input->textView.textStorage
|
|
30
|
+
addAttribute:NSFontAttributeName
|
|
31
|
+
value:newFont
|
|
32
|
+
range:range];
|
|
33
|
+
}
|
|
34
|
+
}];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "RangeUtils.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
#import "TextInsertionUtils.h"
|
|
5
|
+
|
|
6
|
+
@implementation CheckboxListStyle
|
|
7
|
+
|
|
8
|
+
+ (StyleType)getType {
|
|
9
|
+
return CheckboxList;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
- (NSString *)getValue {
|
|
13
|
+
return @"EnrichedCheckbox0";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
- (BOOL)isParagraph {
|
|
17
|
+
return YES;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (BOOL)needsZWS {
|
|
21
|
+
return YES;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (void)applyStyling:(NSRange)range {
|
|
25
|
+
CGFloat listHeadIndent = [self.input->config checkboxListMarginLeft] +
|
|
26
|
+
[self.input->config checkboxListGapWidth] +
|
|
27
|
+
[self.input->config checkboxListBoxSize];
|
|
28
|
+
|
|
29
|
+
[self.input->textView.textStorage
|
|
30
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
31
|
+
inRange:range
|
|
32
|
+
options:0
|
|
33
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
34
|
+
BOOL *_Nonnull stop) {
|
|
35
|
+
NSMutableParagraphStyle *pStyle =
|
|
36
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
37
|
+
pStyle.headIndent = listHeadIndent;
|
|
38
|
+
pStyle.firstLineHeadIndent = listHeadIndent;
|
|
39
|
+
[self.input->textView.textStorage
|
|
40
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
41
|
+
value:pStyle
|
|
42
|
+
range:range];
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (BOOL)styleCondition:(id)value range:(NSRange)range {
|
|
47
|
+
NSParagraphStyle *pStyle = (NSParagraphStyle *)value;
|
|
48
|
+
return pStyle != nullptr && pStyle.textLists.count == 1 &&
|
|
49
|
+
[pStyle.textLists.firstObject.markerFormat
|
|
50
|
+
hasPrefix:@"EnrichedCheckbox"];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)toggleWithChecked:(BOOL)checked range:(NSRange)range {
|
|
54
|
+
NSRange actualRange = [self actualUsedRange:range];
|
|
55
|
+
BOOL isPresent = [self detect:actualRange];
|
|
56
|
+
|
|
57
|
+
if (isPresent) {
|
|
58
|
+
[self remove:actualRange withDirtyRange:YES];
|
|
59
|
+
} else {
|
|
60
|
+
[self addWithChecked:checked
|
|
61
|
+
range:actualRange
|
|
62
|
+
withTyping:YES
|
|
63
|
+
withDirtyRange:YES];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)addWithChecked:(BOOL)checked
|
|
68
|
+
range:(NSRange)range
|
|
69
|
+
withTyping:(BOOL)withTyping
|
|
70
|
+
withDirtyRange:(BOOL)withDirtyRange {
|
|
71
|
+
NSString *value = checked ? @"EnrichedCheckbox1" : @"EnrichedCheckbox0";
|
|
72
|
+
[self add:range
|
|
73
|
+
withValue:value
|
|
74
|
+
withTyping:withTyping
|
|
75
|
+
withDirtyRange:withDirtyRange];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// During dirty range re-application the default add: would use getValue
|
|
79
|
+
// (EnrichedCheckbox0) and lose the checked state. Instead, read the original
|
|
80
|
+
// marker format from the saved StylePair
|
|
81
|
+
- (void)reapplyFromStylePair:(StylePair *)pair {
|
|
82
|
+
NSRange range = [pair.rangeValue rangeValue];
|
|
83
|
+
NSParagraphStyle *savedPStyle = (NSParagraphStyle *)pair.styleValue;
|
|
84
|
+
BOOL checked =
|
|
85
|
+
savedPStyle != nullptr && [savedPStyle.textLists.firstObject.markerFormat
|
|
86
|
+
isEqualToString:@"EnrichedCheckbox1"];
|
|
87
|
+
[self addWithChecked:checked range:range withTyping:NO withDirtyRange:NO];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
- (void)toggleCheckedAt:(NSUInteger)location {
|
|
91
|
+
if (location >= self.input->textView.textStorage.length) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
NSParagraphStyle *pStyle =
|
|
96
|
+
[self.input->textView.textStorage attribute:NSParagraphStyleAttributeName
|
|
97
|
+
atIndex:location
|
|
98
|
+
effectiveRange:NULL];
|
|
99
|
+
NSTextList *list = pStyle.textLists.firstObject;
|
|
100
|
+
|
|
101
|
+
BOOL isCurrentlyChecked =
|
|
102
|
+
[list.markerFormat isEqualToString:@"EnrichedCheckbox1"];
|
|
103
|
+
|
|
104
|
+
NSRange paragraphRange = [self.input->textView.textStorage.string
|
|
105
|
+
paragraphRangeForRange:NSMakeRange(location, 0)];
|
|
106
|
+
|
|
107
|
+
[self addWithChecked:!isCurrentlyChecked
|
|
108
|
+
range:paragraphRange
|
|
109
|
+
withTyping:NO
|
|
110
|
+
withDirtyRange:YES];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
- (BOOL)getCheckboxStateAt:(NSUInteger)location {
|
|
114
|
+
if (location >= self.input->textView.textStorage.length) {
|
|
115
|
+
return NO;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
NSParagraphStyle *style =
|
|
119
|
+
[self.input->textView.textStorage attribute:NSParagraphStyleAttributeName
|
|
120
|
+
atIndex:location
|
|
121
|
+
effectiveRange:NULL];
|
|
122
|
+
|
|
123
|
+
if (style && style.textLists.count > 0) {
|
|
124
|
+
NSTextList *list = style.textLists.firstObject;
|
|
125
|
+
if ([list.markerFormat isEqualToString:@"EnrichedCheckbox1"]) {
|
|
126
|
+
return YES;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return NO;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
- (BOOL)handleNewlinesInRange:(NSRange)range replacementText:(NSString *)text {
|
|
134
|
+
if ([self detect:self.input->textView.selectedRange] && text.length > 0 &&
|
|
135
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
136
|
+
characterIsMember:[text characterAtIndex:text.length - 1]]) {
|
|
137
|
+
// do the replacement manually
|
|
138
|
+
[TextInsertionUtils replaceText:text
|
|
139
|
+
at:range
|
|
140
|
+
additionalAttributes:nullptr
|
|
141
|
+
input:self.input
|
|
142
|
+
withSelection:YES];
|
|
143
|
+
// apply unchecked checkbox attributes to the new paragraph
|
|
144
|
+
[self addWithChecked:NO
|
|
145
|
+
range:self.input->textView.selectedRange
|
|
146
|
+
withTyping:YES
|
|
147
|
+
withDirtyRange:YES];
|
|
148
|
+
return YES;
|
|
149
|
+
}
|
|
150
|
+
return NO;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "FontExtension.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
|
|
5
|
+
@implementation CodeBlockStyle
|
|
6
|
+
|
|
7
|
+
+ (StyleType)getType {
|
|
8
|
+
return CodeBlock;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (NSString *)getValue {
|
|
12
|
+
return @"EnrichedCodeBlock";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (BOOL)isParagraph {
|
|
16
|
+
return YES;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (BOOL)needsZWS {
|
|
20
|
+
return YES;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)applyStyling:(NSRange)range {
|
|
24
|
+
[self.input->textView.textStorage
|
|
25
|
+
enumerateAttribute:NSFontAttributeName
|
|
26
|
+
inRange:range
|
|
27
|
+
options:0
|
|
28
|
+
usingBlock:^(id _Nullable value, NSRange subRange,
|
|
29
|
+
BOOL *_Nonnull stop) {
|
|
30
|
+
UIFont *currentFont = (UIFont *)value;
|
|
31
|
+
if (currentFont == nullptr)
|
|
32
|
+
return;
|
|
33
|
+
UIFont *monoFont = [[[self.input->config monospacedFont]
|
|
34
|
+
withFontTraits:currentFont] setSize:currentFont.pointSize];
|
|
35
|
+
if (monoFont != nullptr) {
|
|
36
|
+
[self.input->textView.textStorage
|
|
37
|
+
addAttribute:NSFontAttributeName
|
|
38
|
+
value:monoFont
|
|
39
|
+
range:subRange];
|
|
40
|
+
}
|
|
41
|
+
}];
|
|
42
|
+
|
|
43
|
+
[self.input->textView.textStorage
|
|
44
|
+
addAttribute:NSForegroundColorAttributeName
|
|
45
|
+
value:[self.input->config codeBlockFgColor]
|
|
46
|
+
range:range];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H1Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H1;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH1";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h1FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h1Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H2Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H2;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH2";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h2FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h2Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H3Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H3;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH3";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h3FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h3Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H4Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H4;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH4";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h4FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h4Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H5Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H5;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH5";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h5FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h5Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
|
+
|
|
4
|
+
@implementation H6Style
|
|
5
|
+
+ (StyleType)getType {
|
|
6
|
+
return H6;
|
|
7
|
+
}
|
|
8
|
+
- (NSString *)getValue {
|
|
9
|
+
return @"EnrichedH6";
|
|
10
|
+
}
|
|
11
|
+
- (BOOL)isParagraph {
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
- (CGFloat)getHeadingFontSize {
|
|
15
|
+
return [self.input->config h6FontSize];
|
|
16
|
+
}
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return [self.input->config h6Bold];
|
|
19
|
+
}
|
|
20
|
+
@end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "FontExtension.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
#import "TextInsertionUtils.h"
|
|
5
|
+
|
|
6
|
+
@implementation HeadingStyleBase
|
|
7
|
+
|
|
8
|
+
// mock values since H1/2/3/4/5/6 style classes are used
|
|
9
|
+
+ (StyleType)getType {
|
|
10
|
+
return None;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
- (CGFloat)getHeadingFontSize {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (BOOL)isHeadingBold {
|
|
18
|
+
return NO;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (BOOL)isParagraph {
|
|
22
|
+
return YES;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (void)applyStyling:(NSRange)range {
|
|
26
|
+
[self.input->textView.textStorage
|
|
27
|
+
enumerateAttribute:NSFontAttributeName
|
|
28
|
+
inRange:range
|
|
29
|
+
options:0
|
|
30
|
+
usingBlock:^(id _Nullable value, NSRange subRange,
|
|
31
|
+
BOOL *_Nonnull stop) {
|
|
32
|
+
UIFont *font = (UIFont *)value;
|
|
33
|
+
if (font == nullptr)
|
|
34
|
+
return;
|
|
35
|
+
UIFont *newFont = [font setSize:[self getHeadingFontSize]];
|
|
36
|
+
if ([self isHeadingBold]) {
|
|
37
|
+
newFont = [newFont setBold];
|
|
38
|
+
}
|
|
39
|
+
[self.input->textView.textStorage
|
|
40
|
+
addAttribute:NSFontAttributeName
|
|
41
|
+
value:newFont
|
|
42
|
+
range:subRange];
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// used to make sure headings dont persist after a newline is placed
|
|
47
|
+
- (BOOL)handleNewlinesInRange:(NSRange)range replacementText:(NSString *)text {
|
|
48
|
+
// in a heading and a new text ends with a newline
|
|
49
|
+
if ([self detect:self.input->textView.selectedRange] && text.length > 0 &&
|
|
50
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
51
|
+
characterIsMember:[text characterAtIndex:text.length - 1]]) {
|
|
52
|
+
// do the replacement manually
|
|
53
|
+
[TextInsertionUtils replaceText:text
|
|
54
|
+
at:range
|
|
55
|
+
additionalAttributes:nullptr
|
|
56
|
+
input:self.input
|
|
57
|
+
withSelection:YES];
|
|
58
|
+
// remove the attributes at the new selection
|
|
59
|
+
[self remove:self.input->textView.selectedRange withDirtyRange:YES];
|
|
60
|
+
return YES;
|
|
61
|
+
}
|
|
62
|
+
return NO;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "ImageAttachment.h"
|
|
3
|
+
#import "StyleHeaders.h"
|
|
4
|
+
#import "TextInsertionUtils.h"
|
|
5
|
+
|
|
6
|
+
// custom NSAttributedStringKey to differentiate the image
|
|
7
|
+
static NSString *const ImageAttributeName = @"EnrichedImage";
|
|
8
|
+
|
|
9
|
+
@implementation ImageStyle
|
|
10
|
+
|
|
11
|
+
+ (StyleType)getType {
|
|
12
|
+
return Image;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
- (NSString *)getKey {
|
|
16
|
+
return ImageAttributeName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (BOOL)isParagraph {
|
|
20
|
+
return NO;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)applyStyling:(NSRange)range {
|
|
24
|
+
// no-op for image
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (void)reapplyFromStylePair:(StylePair *)pair {
|
|
28
|
+
NSRange range = [pair.rangeValue rangeValue];
|
|
29
|
+
ImageData *imageData = (ImageData *)pair.styleValue;
|
|
30
|
+
if (imageData == nullptr || range.length == 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ImageAttachment *attachment =
|
|
35
|
+
[[ImageAttachment alloc] initWithImageData:imageData];
|
|
36
|
+
attachment.delegate = self.input;
|
|
37
|
+
|
|
38
|
+
[self.input->textView.textStorage addAttributes:@{
|
|
39
|
+
NSAttachmentAttributeName : attachment,
|
|
40
|
+
ImageAttributeName : imageData
|
|
41
|
+
}
|
|
42
|
+
range:range];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (AttributeEntry *)getEntryIfPresent:(NSRange)range {
|
|
46
|
+
return nullptr;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (void)toggle:(NSRange)range {
|
|
50
|
+
// no-op for image
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)remove:(NSRange)range withDirtyRange:(BOOL)withDirtyRange {
|
|
54
|
+
[self.input->textView.textStorage beginEditing];
|
|
55
|
+
[self.input->textView.textStorage removeAttribute:ImageAttributeName
|
|
56
|
+
range:range];
|
|
57
|
+
[self.input->textView.textStorage removeAttribute:NSAttachmentAttributeName
|
|
58
|
+
range:range];
|
|
59
|
+
[self.input->textView.textStorage endEditing];
|
|
60
|
+
|
|
61
|
+
if (withDirtyRange) {
|
|
62
|
+
[self.input->attributesManager addDirtyRange:range];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
[self removeTyping];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (void)removeTyping {
|
|
69
|
+
NSMutableDictionary *currentAttributes =
|
|
70
|
+
[self.input->textView.typingAttributes mutableCopy];
|
|
71
|
+
[currentAttributes removeObjectForKey:ImageAttributeName];
|
|
72
|
+
[currentAttributes removeObjectForKey:NSAttachmentAttributeName];
|
|
73
|
+
[self.input->attributesManager didRemoveTypingAttribute:ImageAttributeName];
|
|
74
|
+
self.input->textView.typingAttributes = currentAttributes;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
78
|
+
return [value isKindOfClass:[ImageData class]];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (ImageData *)getImageDataAt:(NSUInteger)location {
|
|
82
|
+
NSRange imageRange = NSMakeRange(0, 0);
|
|
83
|
+
NSRange inputRange = NSMakeRange(0, self.input->textView.textStorage.length);
|
|
84
|
+
|
|
85
|
+
// don't search at the very end of input
|
|
86
|
+
NSUInteger searchLocation = location;
|
|
87
|
+
if (searchLocation == self.input->textView.textStorage.length) {
|
|
88
|
+
return nullptr;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ImageData *imageData =
|
|
92
|
+
[self.input->textView.textStorage attribute:ImageAttributeName
|
|
93
|
+
atIndex:searchLocation
|
|
94
|
+
longestEffectiveRange:&imageRange
|
|
95
|
+
inRange:inputRange];
|
|
96
|
+
|
|
97
|
+
return imageData;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
- (void)addImageAtRange:(NSRange)range
|
|
101
|
+
imageData:(ImageData *)imageData
|
|
102
|
+
withSelection:(BOOL)withSelection {
|
|
103
|
+
if (!imageData)
|
|
104
|
+
return;
|
|
105
|
+
|
|
106
|
+
ImageAttachment *attachment =
|
|
107
|
+
[[ImageAttachment alloc] initWithImageData:imageData];
|
|
108
|
+
attachment.delegate = self.input;
|
|
109
|
+
|
|
110
|
+
NSDictionary *attributes =
|
|
111
|
+
@{NSAttachmentAttributeName : attachment, ImageAttributeName : imageData};
|
|
112
|
+
|
|
113
|
+
// Use the Object Replacement Character for Image.
|
|
114
|
+
// This tells TextKit "something non-text goes here".
|
|
115
|
+
NSString *placeholderChar = @"\uFFFC";
|
|
116
|
+
|
|
117
|
+
if (range.length == 0) {
|
|
118
|
+
[TextInsertionUtils insertText:placeholderChar
|
|
119
|
+
at:range.location
|
|
120
|
+
additionalAttributes:attributes
|
|
121
|
+
input:self.input
|
|
122
|
+
withSelection:withSelection];
|
|
123
|
+
} else {
|
|
124
|
+
[TextInsertionUtils replaceText:placeholderChar
|
|
125
|
+
at:range
|
|
126
|
+
additionalAttributes:attributes
|
|
127
|
+
input:self.input
|
|
128
|
+
withSelection:withSelection];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
NSRange insertedImageRange = NSMakeRange(range.location, 1);
|
|
132
|
+
[self.input->attributesManager addDirtyRange:insertedImageRange];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (void)addImage:(NSString *)uri width:(CGFloat)width height:(CGFloat)height {
|
|
136
|
+
ImageData *data = [[ImageData alloc] init];
|
|
137
|
+
data.uri = uri;
|
|
138
|
+
data.width = width;
|
|
139
|
+
data.height = height;
|
|
140
|
+
|
|
141
|
+
[self addImageAtRange:self.input->textView.selectedRange
|
|
142
|
+
imageData:data
|
|
143
|
+
withSelection:YES];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@end
|