react-native-enriched-markdown-scaffold 1.0.2-scaffold.9 → 1.2.0-scaffold.2
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/ReactNativeEnrichedMarkdown.podspec +31 -10
- package/android/build.gradle +49 -12
- package/android/consumer-rules.pro +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +6 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +1 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +18 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +6 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/android/src/main/baseline-prof.txt +21 -22
- package/android/src/main/cpp/jni-adapter.cpp +17 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +729 -768
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +72 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +222 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +65 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt +191 -26
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +54 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/events/CodeBlockPressEvent.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/ImagePressEvent.kt +25 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LatexErrorEvent.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +101 -9
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/EditPipeline.kt +48 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/InputConnectionWrapper.kt +7 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/editing/MarkdownShortcutMatcher.kt +64 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +44 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputEventEmitter.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/markdown/math/LatexErrorReporter.kt +9 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt +5 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlankLineRenderer.kt +38 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockStyleContext.kt +2 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteRenderer.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/BlockquoteTextRenderer.kt +55 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/HighlightRenderer.kt +10 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/NodeRenderer.kt +31 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/ParagraphRenderer.kt +17 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/Renderer.kt +40 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/AdmonitionIcons.kt +62 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/BlockSegmentView.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt +401 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/CodeBlockContainerView.kt +55 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt +164 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/MarkdownSegment.kt +21 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/RenderedSegment.kt +137 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentHeightMeasurer.kt +139 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentReconciler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/{utils/common → segments}/SegmentSignature.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewCreators.kt +262 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/segments/SegmentViewFactory.kt +29 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/{views → segments}/TableContainerView.kt +100 -36
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +18 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBlockSpan.kt +3 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/HighlightSpan.kt +60 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt +15 -5
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineBackgroundGeometry.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +4 -27
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LineHeightSpan.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spoiler/SpoilerDrawUtils.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/BlockquoteStyle.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +2 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/StyleConfig.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/VideoStyle.kt +31 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/BorderStyleUtils.kt +86 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EllipsizeUtils.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/EnrichedMarkdownAncestorUtils.kt +10 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/FeatureFlags.kt +1 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/ReadableMapExtensions.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt +227 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/input/PasteTextUtils.kt +34 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +50 -28
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +16 -21
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/extensions/SpannableExtensions.kt +4 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/BlockSpacing.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/span/SpanFlags.kt +13 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/CodeBlockPressHost.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/ImagePressHost.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLongPressMovementMethod.kt +87 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/TextViewSetup.kt +79 -0
- package/android/src/main/jni/react/renderer/components/EnrichedMarkdownTextSpec/conversions.h +2 -0
- package/android/src/math/java/com/swmansion/enriched/markdown/renderer/MathInlineRenderer.kt +9 -3
- package/android/src/math/java/com/swmansion/enriched/markdown/{views → segments}/MathContainerView.kt +86 -29
- package/android/src/math/java/com/swmansion/enriched/markdown/spans/MathInlineSpan.kt +33 -7
- package/android/src/video/java/com/swmansion/enriched/markdown/segments/VideoContainerView.kt +115 -0
- package/cpp/md4c/md4c.c +343 -236
- package/cpp/md4c/md4c.h +28 -11
- package/cpp/parser/MD4CParser.cpp +266 -4
- package/cpp/parser/MD4CParser.hpp +6 -2
- package/cpp/parser/MarkdownASTNode.hpp +4 -1
- package/cpp/wasm/ASTSerializer.cpp +6 -0
- package/cpp/wasm/md4c_wasm.cpp +5 -1
- package/docs/API_REFERENCE.md +199 -12
- package/docs/BREAKING_CHANGES.md +75 -0
- package/docs/CODE_HIGHLIGHT.md +4 -0
- package/docs/COPY_OPTIONS.md +52 -9
- package/docs/ELEMENTS_STRUCTURE.md +48 -1
- package/docs/INPUT.md +60 -3
- package/docs/LATEX_MATH.md +30 -0
- package/docs/MACOS.md +1 -1
- package/docs/MENTIONS.md +2 -2
- package/docs/STYLES.md +27 -0
- package/docs/TEXT.md +8 -0
- package/docs/WEB.md +44 -10
- package/ios/EnrichedMarkdown.mm +285 -43
- package/ios/EnrichedMarkdownText.mm +185 -23
- package/ios/attachments/ENRMImageAttachment.h +17 -2
- package/ios/attachments/ENRMImageAttachment.m +26 -28
- package/ios/attachments/ENRMMathInlineAttachment+macOS.m +10 -2
- package/ios/attachments/ENRMMathInlineAttachment.h +3 -1
- package/ios/attachments/ENRMMathInlineAttachment.m +17 -1
- package/ios/attachments/ENRMMathInlineAttachmentShared.h +3 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +62 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +44 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +67 -2
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +929 -178
- package/ios/input/ENRMInputFormatter.mm +68 -12
- package/ios/input/ENRMInputFormatterStyle.mm +9 -2
- package/ios/input/ENRMInputParser.mm +18 -0
- package/ios/input/ENRMInputRemend.mm +40 -3
- package/ios/input/ENRMMarkdownShortcutMatcher.h +39 -0
- package/ios/input/ENRMMarkdownShortcutMatcher.mm +66 -0
- package/ios/input/EnrichedMarkdownTextInput.mm +129 -1
- package/ios/internals/ENRMViewFreeMeasurement.h +45 -6
- package/ios/internals/MeasurementCache.h +20 -4
- package/ios/internals/ShadowMeasurementUtils.h +2 -0
- package/ios/math/ENRMLatexErrorCoordinator.h +27 -0
- package/ios/math/ENRMLatexErrorCoordinator.mm +75 -0
- package/ios/math/ENRMLatexErrorReporting.h +13 -0
- package/ios/math/ENRMRaTeXBridge.swift +46 -3
- package/ios/parser/ENRMMarkdownParser.h +3 -0
- package/ios/parser/ENRMMarkdownParser.mm +11 -2
- package/ios/parser/MarkdownASTNode.h +8 -1
- package/ios/parser/MarkdownASTNode.m +20 -0
- package/ios/parser/MarkdownParserBridge.mm +13 -2
- package/ios/renderer/AttributedRenderer.h +13 -1
- package/ios/renderer/AttributedRenderer.m +24 -13
- package/ios/renderer/BaselineShiftTextAttributes.h +4 -0
- package/ios/renderer/BaselineShiftTextAttributes.m +4 -0
- package/ios/renderer/BlankLineRenderer.h +4 -0
- package/ios/renderer/BlankLineRenderer.m +51 -0
- package/ios/renderer/BlockquoteRenderer.m +1 -0
- package/ios/renderer/CodeBlockRenderer.m +8 -0
- package/ios/renderer/CodeRenderer.m +5 -2
- package/ios/renderer/ENRMBlockquoteTextRenderer.h +25 -0
- package/ios/renderer/ENRMBlockquoteTextRenderer.m +48 -0
- package/ios/renderer/ENRMImageRenderer.m +1 -1
- package/ios/renderer/ENRMMathInlineRenderer.m +9 -1
- package/ios/renderer/HeadingRenderer.m +1 -0
- package/ios/renderer/HighlightRenderer.m +6 -0
- package/ios/renderer/LinkRenderer.m +1 -1
- package/ios/renderer/ListItemRenderer.m +51 -2
- package/ios/renderer/ParagraphRenderer.m +10 -3
- package/ios/renderer/RenderContext.h +16 -0
- package/ios/renderer/RenderContext.m +16 -0
- package/ios/renderer/RendererFactory.m +6 -0
- package/ios/renderer/SubscriptRenderer.m +1 -0
- package/ios/renderer/SuperscriptRenderer.m +1 -0
- package/ios/segments/ENRMAdmonitionIcons.h +31 -0
- package/ios/segments/ENRMAdmonitionIcons.m +93 -0
- package/ios/segments/ENRMBlockquoteContainerView.h +90 -0
- package/ios/segments/ENRMBlockquoteContainerView.mm +551 -0
- package/ios/{views → segments}/ENRMCodeBlockContainerView.h +9 -4
- package/ios/{views → segments}/ENRMCodeBlockContainerView.m +147 -36
- package/ios/segments/ENRMContainerNodeView.h +52 -0
- package/ios/segments/ENRMContainerNodeView.mm +201 -0
- package/ios/segments/ENRMDynamicBlockProps.h +32 -0
- package/ios/segments/ENRMDynamicBlockProps.m +15 -0
- package/ios/{views → segments}/ENRMMathContainerView.h +13 -5
- package/ios/{views → segments}/ENRMMathContainerView.m +60 -9
- package/ios/segments/ENRMSVGPath.h +21 -0
- package/ios/segments/ENRMSVGPath.m +409 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.h +33 -0
- package/ios/segments/ENRMSegmentHeightMeasurer.mm +94 -0
- package/ios/segments/ENRMVideoContainerView.h +40 -0
- package/ios/segments/ENRMVideoContainerView.m +421 -0
- package/ios/{utils → segments}/RenderedMarkdownSegment.h +19 -2
- package/ios/{utils → segments}/RenderedMarkdownSegment.m +42 -1
- package/ios/segments/SegmentRenderer.h +26 -0
- package/ios/{utils → segments}/SegmentRenderer.m +46 -9
- package/ios/{views → segments}/TableContainerView.h +5 -4
- package/ios/{views → segments}/TableContainerView.m +96 -12
- package/ios/styles/StyleConfig.h +17 -0
- package/ios/styles/StyleConfig.mm +90 -0
- package/ios/utils/ENRMCodeBlockContent.mm +13 -0
- package/ios/utils/ENRMFeatureFlags.h +6 -0
- package/ios/utils/ENRMTextRenderer.h +8 -0
- package/ios/utils/ENRMTextRenderer.m +26 -10
- package/ios/utils/ENRMUIKit.h +1 -0
- package/ios/utils/FontUtils.h +2 -1
- package/ios/utils/FontUtils.m +22 -6
- package/ios/utils/LinkTapUtils.h +17 -2
- package/ios/utils/LinkTapUtils.m +44 -2
- package/ios/utils/ListMarkerDrawer.m +25 -1
- package/ios/utils/MarkdownASTSerializer.h +7 -0
- package/ios/utils/MarkdownASTSerializer.m +243 -0
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +9 -67
- package/ios/utils/MarkdownExtractor.m +6 -3
- package/ios/utils/ParagraphStyleUtils.h +25 -1
- package/ios/utils/ParagraphStyleUtils.m +51 -7
- package/ios/utils/StylePropsUtils.h +60 -1
- package/ios/utils/TextViewLayoutManager.mm +57 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +110 -4
- package/lib/module/EnrichedMarkdownTextInput.js +60 -2
- package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
- package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/lib/module/admonitionDefaults.js +34 -0
- package/lib/module/admonitionDefaults.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +84 -4
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/native/EnrichedMarkdownText.js +58 -5
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownShortcuts.js +31 -0
- package/lib/module/normalizeMarkdownShortcuts.js.map +1 -0
- package/lib/module/normalizeMarkdownStyle.js +15 -1
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +15 -1
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/styleUtils.js +15 -3
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/utils/textInputState.js +4 -3
- package/lib/module/utils/textInputState.js.map +1 -1
- package/lib/module/utils/usePressability.js +28 -0
- package/lib/module/utils/usePressability.js.map +1 -0
- package/lib/module/web/EnrichedMarkdownText.js +19 -6
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/globalStyles.js +7 -1
- package/lib/module/web/globalStyles.js.map +1 -1
- package/lib/module/web/nativeProps.js +70 -0
- package/lib/module/web/nativeProps.js.map +1 -0
- package/lib/module/web/parseMarkdown.js +5 -3
- package/lib/module/web/parseMarkdown.js.map +1 -1
- package/lib/module/web/renderers/BlockRenderers.js +164 -8
- package/lib/module/web/renderers/BlockRenderers.js.map +1 -1
- package/lib/module/web/renderers/admonitionIcons.js +34 -0
- package/lib/module/web/renderers/admonitionIcons.js.map +1 -0
- package/lib/module/web/styles.js +30 -8
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/wasm/md4c.js +0 -0
- package/lib/module/web/wasm/md4c.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +103 -3
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +27 -3
- package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +11 -0
- package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +108 -3
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/admonitionDefaults.d.ts +10 -0
- package/lib/typescript/src/admonitionDefaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +2 -2
- package/lib/typescript/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts +7 -0
- package/lib/typescript/src/normalizeMarkdownShortcuts.d.ts.map +1 -0
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +59 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +21 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +93 -8
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +25 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +33 -5
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/utils/textInputState.d.ts +5 -3
- package/lib/typescript/src/utils/textInputState.d.ts.map +1 -1
- package/lib/typescript/src/utils/usePressability.d.ts +24 -0
- package/lib/typescript/src/utils/usePressability.d.ts.map +1 -0
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/globalStyles.d.ts +1 -0
- package/lib/typescript/src/web/globalStyles.d.ts.map +1 -1
- package/lib/typescript/src/web/nativeProps.d.ts +34 -0
- package/lib/typescript/src/web/nativeProps.d.ts.map +1 -0
- package/lib/typescript/src/web/parseMarkdown.d.ts +1 -1
- package/lib/typescript/src/web/parseMarkdown.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/BlockRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts +5 -0
- package/lib/typescript/src/web/renderers/admonitionIcons.d.ts.map +1 -0
- package/lib/typescript/src/web/styles.d.ts +1 -0
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +8 -2
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/postinstall.mjs +7 -0
- package/src/EnrichedMarkdownNativeComponent.ts +110 -4
- package/src/EnrichedMarkdownTextInput.tsx +101 -4
- package/src/EnrichedMarkdownTextInputNativeComponent.ts +12 -0
- package/src/EnrichedMarkdownTextNativeComponent.ts +115 -4
- package/src/admonitionDefaults.ts +58 -0
- package/src/index.tsx +5 -0
- package/src/index.web.tsx +3 -0
- package/src/jest/index.tsx +138 -5
- package/src/native/EnrichedMarkdownText.tsx +55 -3
- package/src/normalizeMarkdownShortcuts.ts +38 -0
- package/src/normalizeMarkdownStyle.ts +17 -0
- package/src/normalizeMarkdownStyle.web.ts +17 -0
- package/src/styleUtils.ts +17 -6
- package/src/types/MarkdownStyle.ts +62 -1
- package/src/types/MarkdownStyleInternal.ts +24 -0
- package/src/types/MarkdownTextProps.ts +95 -7
- package/src/types/MarkdownTextProps.web.ts +26 -0
- package/src/types/events.ts +36 -5
- package/src/utils/textInputState.ts +5 -3
- package/src/utils/usePressability.ts +34 -0
- package/src/web/EnrichedMarkdownText.tsx +36 -3
- package/src/web/globalStyles.ts +10 -0
- package/src/web/nativeProps.ts +78 -0
- package/src/web/parseMarkdown.ts +10 -2
- package/src/web/renderers/BlockRenderers.tsx +175 -6
- package/src/web/renderers/admonitionIcons.ts +37 -0
- package/src/web/styles.ts +28 -3
- package/src/web/types.ts +12 -1
- package/src/web/wasm/md4c.js +0 -0
- package/vendor-ratex.mjs +86 -17
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/DocumentRenderer.kt +0 -16
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/RenderedSegment.kt +0 -88
- package/ios/utils/SegmentRenderer.h +0 -24
- /package/ios/{views → segments}/ENRMTableGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableGridView.m +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.h +0 -0
- /package/ios/{views → segments}/ENRMTableIOSGridView.m +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.h +0 -0
- /package/ios/{utils → segments}/SegmentReconciler.m +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.h +0 -0
- /package/ios/{utils → segments}/SegmentViewRegistry.m +0 -0
|
@@ -3,9 +3,12 @@ package com.swmansion.enriched.markdown
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Typeface
|
|
5
5
|
import android.os.Build
|
|
6
|
+
import android.text.Spannable
|
|
6
7
|
import android.text.SpannableString
|
|
8
|
+
import android.text.Spanned
|
|
7
9
|
import android.text.StaticLayout
|
|
8
10
|
import android.text.TextPaint
|
|
11
|
+
import android.text.TextUtils.TruncateAt
|
|
9
12
|
import android.util.Log
|
|
10
13
|
import androidx.emoji2.text.EmojiCompat
|
|
11
14
|
import com.facebook.react.bridge.ReadableMap
|
|
@@ -15,27 +18,31 @@ import com.facebook.yoga.YogaMeasureOutput
|
|
|
15
18
|
import com.swmansion.enriched.markdown.parser.Md4cFlags
|
|
16
19
|
import com.swmansion.enriched.markdown.parser.Parser
|
|
17
20
|
import com.swmansion.enriched.markdown.renderer.Renderer
|
|
21
|
+
import com.swmansion.enriched.markdown.segments.BlockquoteContainerView
|
|
22
|
+
import com.swmansion.enriched.markdown.segments.CodeBlockContainerView
|
|
23
|
+
import com.swmansion.enriched.markdown.segments.MarkdownSegmentRenderer
|
|
24
|
+
import com.swmansion.enriched.markdown.segments.RenderedSegment
|
|
25
|
+
import com.swmansion.enriched.markdown.segments.TableContainerView
|
|
26
|
+
import com.swmansion.enriched.markdown.segments.splitASTIntoSegments
|
|
27
|
+
import com.swmansion.enriched.markdown.spans.MarginBottomSpan
|
|
18
28
|
import com.swmansion.enriched.markdown.spans.MathMeasureRequest
|
|
19
29
|
import com.swmansion.enriched.markdown.spans.MathMetrics
|
|
20
30
|
import com.swmansion.enriched.markdown.spans.MathRenderMode
|
|
21
31
|
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
22
32
|
import com.swmansion.enriched.markdown.utils.common.BreakStrategyUtils
|
|
23
33
|
import com.swmansion.enriched.markdown.utils.common.CodeBlockStreamingMode
|
|
34
|
+
import com.swmansion.enriched.markdown.utils.common.EllipsizeUtils
|
|
24
35
|
import com.swmansion.enriched.markdown.utils.common.FeatureFlags
|
|
25
|
-
import com.swmansion.enriched.markdown.utils.common.MarkdownSegmentRenderer
|
|
26
|
-
import com.swmansion.enriched.markdown.utils.common.RenderedSegment
|
|
27
36
|
import com.swmansion.enriched.markdown.utils.common.StreamingMarkdownFilter
|
|
28
37
|
import com.swmansion.enriched.markdown.utils.common.TableStreamingMode
|
|
29
38
|
import com.swmansion.enriched.markdown.utils.common.getArrayOrNull
|
|
30
39
|
import com.swmansion.enriched.markdown.utils.common.getBooleanOrDefault
|
|
31
40
|
import com.swmansion.enriched.markdown.utils.common.getFloatOrDefault
|
|
41
|
+
import com.swmansion.enriched.markdown.utils.common.getIntOrDefault
|
|
32
42
|
import com.swmansion.enriched.markdown.utils.common.getMapOrNull
|
|
33
43
|
import com.swmansion.enriched.markdown.utils.common.getStringOrDefault
|
|
34
44
|
import com.swmansion.enriched.markdown.utils.common.parseImageRequestHeaders
|
|
35
|
-
import com.swmansion.enriched.markdown.utils.common.splitASTIntoSegments
|
|
36
45
|
import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWithPlaceholders
|
|
37
|
-
import com.swmansion.enriched.markdown.views.CodeBlockContainerView
|
|
38
|
-
import com.swmansion.enriched.markdown.views.TableContainerView
|
|
39
46
|
import java.util.concurrent.ConcurrentHashMap
|
|
40
47
|
import kotlin.math.ceil
|
|
41
48
|
|
|
@@ -71,6 +78,11 @@ object MeasurementStore {
|
|
|
71
78
|
|
|
72
79
|
private val breakStrategies = ConcurrentHashMap<Int, String>()
|
|
73
80
|
|
|
81
|
+
// The measure path and the display TextView resolve the same clamp. 0 means unlimited.
|
|
82
|
+
private val numberOfLinesByViewId = ConcurrentHashMap<Int, Int>()
|
|
83
|
+
|
|
84
|
+
private val ellipsizeModeByViewId = ConcurrentHashMap<Int, String>()
|
|
85
|
+
|
|
74
86
|
private val streamingTableModes = ConcurrentHashMap<Int, TableStreamingMode>()
|
|
75
87
|
|
|
76
88
|
private val streamingCodeBlockModes = ConcurrentHashMap<Int, CodeBlockStreamingMode>()
|
|
@@ -107,7 +119,8 @@ object MeasurementStore {
|
|
|
107
119
|
|
|
108
120
|
// AppCompatTextView draws emoji the system font lacks through EmojiCompat, which can be
|
|
109
121
|
// wider than the fallback glyph and wrap a line earlier; measure the same glyphs.
|
|
110
|
-
|
|
122
|
+
// Internal so SegmentHeightMeasurer (blockquote children) measures the same way (HWK-1415).
|
|
123
|
+
internal fun withEmojiSpans(text: CharSequence): CharSequence {
|
|
111
124
|
if (text.isEmpty() || !EmojiCompat.isConfigured()) return text
|
|
112
125
|
val emojiCompat = EmojiCompat.get()
|
|
113
126
|
if (emojiCompat.loadState != EmojiCompat.LOAD_STATE_SUCCEEDED) {
|
|
@@ -157,41 +170,69 @@ object MeasurementStore {
|
|
|
157
170
|
|
|
158
171
|
fun release(id: Int) {
|
|
159
172
|
data.remove(id)
|
|
173
|
+
numberOfLinesByViewId.remove(id)
|
|
174
|
+
ellipsizeModeByViewId.remove(id)
|
|
160
175
|
}
|
|
161
176
|
|
|
162
177
|
fun invalidate(id: Int) {
|
|
163
178
|
data.remove(id)
|
|
164
179
|
}
|
|
165
180
|
|
|
181
|
+
// Content-box width (px) the measure pass last wrapped at; the display view insets to match (#805).
|
|
182
|
+
fun contentBoxWidthPx(id: Int): Float? = data[id]?.cachedWidth
|
|
183
|
+
|
|
166
184
|
/** Main entry point for ShadowNode measurement. */
|
|
167
185
|
fun getMeasureById(
|
|
168
186
|
context: Context,
|
|
169
187
|
id: Int?,
|
|
170
188
|
width: Float,
|
|
189
|
+
widthMode: YogaMeasureMode?,
|
|
171
190
|
height: Float,
|
|
172
191
|
heightMode: YogaMeasureMode?,
|
|
173
192
|
props: ReadableMap?,
|
|
174
193
|
splitTableSegments: Boolean = false,
|
|
175
194
|
): Long {
|
|
176
|
-
// Early exit for empty markdown
|
|
195
|
+
// Early exit for empty markdown. Honor widthMode here too: empty content has
|
|
196
|
+
// zero intrinsic width, so only fill when the width is EXACTLY assigned -
|
|
197
|
+
// otherwise an empty view would claim all available horizontal space.
|
|
177
198
|
val markdown = props.getStringOrDefault("markdown", "")
|
|
178
199
|
if (markdown.isEmpty()) {
|
|
179
|
-
|
|
200
|
+
val emptyWidth = if (widthMode === YogaMeasureMode.EXACTLY) PixelUtil.toDIPFromPixel(width) else 0f
|
|
201
|
+
return YogaMeasureOutput.make(emptyWidth, 0f)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Resolve the line clamp from props here so the (background) measure pass and
|
|
205
|
+
// the (main-thread) display TextView never race on the per-viewId cache. Only
|
|
206
|
+
// overwrite when the key is present so we never clobber the view's value.
|
|
207
|
+
if (id != null && props != null) {
|
|
208
|
+
if (props.hasKey("numberOfLines")) {
|
|
209
|
+
numberOfLinesByViewId[id] = props.getDouble("numberOfLines").toInt()
|
|
210
|
+
}
|
|
211
|
+
if (props.hasKey("ellipsizeMode")) {
|
|
212
|
+
ellipsizeModeByViewId[id] = props.getString("ellipsizeMode") ?: EllipsizeUtils.DEFAULT_MODE
|
|
213
|
+
}
|
|
180
214
|
}
|
|
181
215
|
|
|
182
216
|
val size = getMeasureByIdInternal(context, id, width, props, splitTableSegments)
|
|
183
|
-
val resultHeight = YogaMeasureOutput.getHeight(size)
|
|
184
217
|
|
|
218
|
+
// Honor the Yoga width contract. When the parent assigns an exact width
|
|
219
|
+
// (flex child, alignItems: stretch, explicit width / width: "100%"), fill it
|
|
220
|
+
// instead of reporting the content's widest line, which would make the node
|
|
221
|
+
// hug its content and wrap early. Mirrors RN's TextLayoutManager.calculateWidth;
|
|
222
|
+
// iOS already does this via ENRMClampMeasuredSize.
|
|
223
|
+
val resultWidth =
|
|
224
|
+
if (widthMode === YogaMeasureMode.EXACTLY) {
|
|
225
|
+
PixelUtil.toDIPFromPixel(width)
|
|
226
|
+
} else {
|
|
227
|
+
YogaMeasureOutput.getWidth(size)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
var resultHeight = YogaMeasureOutput.getHeight(size)
|
|
185
231
|
if (heightMode === YogaMeasureMode.AT_MOST) {
|
|
186
|
-
|
|
187
|
-
val finalHeight = resultHeight.coerceAtMost(maxHeight)
|
|
188
|
-
return YogaMeasureOutput.make(
|
|
189
|
-
YogaMeasureOutput.getWidth(size),
|
|
190
|
-
finalHeight,
|
|
191
|
-
)
|
|
232
|
+
resultHeight = resultHeight.coerceAtMost(PixelUtil.toDIPFromPixel(height))
|
|
192
233
|
}
|
|
193
234
|
|
|
194
|
-
return
|
|
235
|
+
return YogaMeasureOutput.make(resultWidth, resultHeight)
|
|
195
236
|
}
|
|
196
237
|
|
|
197
238
|
fun updateFontScalingSettings(
|
|
@@ -223,6 +264,25 @@ object MeasurementStore {
|
|
|
223
264
|
|
|
224
265
|
private fun resolveBreakStrategy(viewId: Int?): Int = BreakStrategyUtils.resolveBreakStrategy(viewId?.let { breakStrategies[it] })
|
|
225
266
|
|
|
267
|
+
fun updateNumberOfLines(
|
|
268
|
+
viewId: Int,
|
|
269
|
+
numberOfLines: Int,
|
|
270
|
+
) {
|
|
271
|
+
numberOfLinesByViewId[viewId] = numberOfLines
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
fun updateEllipsizeMode(
|
|
275
|
+
viewId: Int,
|
|
276
|
+
mode: String,
|
|
277
|
+
) {
|
|
278
|
+
ellipsizeModeByViewId[viewId] = mode
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private fun resolveMaxLines(viewId: Int?): Int = viewId?.let { numberOfLinesByViewId[it] } ?: 0
|
|
282
|
+
|
|
283
|
+
private fun resolveEllipsize(viewId: Int?): TruncateAt? =
|
|
284
|
+
EllipsizeUtils.resolveTruncateAt(viewId?.let { ellipsizeModeByViewId[it] } ?: EllipsizeUtils.DEFAULT_MODE)
|
|
285
|
+
|
|
226
286
|
fun updateStreamingTableMode(
|
|
227
287
|
viewId: Int,
|
|
228
288
|
mode: TableStreamingMode,
|
|
@@ -309,6 +369,8 @@ object MeasurementStore {
|
|
|
309
369
|
result = 31 * result + maxFontSizeMultiplier.toBits()
|
|
310
370
|
result = 31 * result + allowTrailingMargin.hashCode()
|
|
311
371
|
result = 31 * result + imageRequestHeaders.hashCode()
|
|
372
|
+
result = 31 * result + props.getIntOrDefault("numberOfLines", 0)
|
|
373
|
+
result = 31 * result + props.getStringOrDefault("ellipsizeMode", EllipsizeUtils.DEFAULT_MODE).hashCode()
|
|
312
374
|
return result
|
|
313
375
|
}
|
|
314
376
|
|
|
@@ -358,7 +420,10 @@ object MeasurementStore {
|
|
|
358
420
|
subscript = props.getMapOrNull("md4cFlags").getBooleanOrDefault("subscript", false),
|
|
359
421
|
highlight = props.getMapOrNull("md4cFlags").getBooleanOrDefault("highlight", false),
|
|
360
422
|
hardSoftBreaks = props.getMapOrNull("md4cFlags").getBooleanOrDefault("hardSoftBreaks", false),
|
|
423
|
+
preserveBlankLines = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveBlankLines", false),
|
|
424
|
+
admonitions = props.getMapOrNull("md4cFlags").getBooleanOrDefault("admonitions", true),
|
|
361
425
|
)
|
|
426
|
+
val isGFM = props.getBooleanOrDefault("isGFM", false)
|
|
362
427
|
|
|
363
428
|
val fontSize = getInitialFontSize(styleMap, context, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
|
364
429
|
val propsHash = computePropsHash(props, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
|
@@ -367,7 +432,16 @@ object MeasurementStore {
|
|
|
367
432
|
measurePaint.textSize = fontSize
|
|
368
433
|
val imageRequestHeaders = parseImageRequestHeaders(props.getArrayOrNull("imageRequestHeaders"))
|
|
369
434
|
val spannable =
|
|
370
|
-
tryRenderMarkdown(
|
|
435
|
+
tryRenderMarkdown(
|
|
436
|
+
markdown,
|
|
437
|
+
styleMap,
|
|
438
|
+
context,
|
|
439
|
+
md4cFlags,
|
|
440
|
+
isGFM,
|
|
441
|
+
allowFontScaling,
|
|
442
|
+
maxFontSizeMultiplier,
|
|
443
|
+
imageRequestHeaders,
|
|
444
|
+
)
|
|
371
445
|
// Placeholders must be built with the same inlineMath.paddingVertical the real spans use,
|
|
372
446
|
// or the measured line box won't match the drawn one.
|
|
373
447
|
val inlineMathMap = styleMap.getMapOrNull("inlineMath")
|
|
@@ -458,13 +532,16 @@ object MeasurementStore {
|
|
|
458
532
|
subscript = props.getMapOrNull("md4cFlags").getBooleanOrDefault("subscript", false),
|
|
459
533
|
highlight = props.getMapOrNull("md4cFlags").getBooleanOrDefault("highlight", false),
|
|
460
534
|
hardSoftBreaks = props.getMapOrNull("md4cFlags").getBooleanOrDefault("hardSoftBreaks", false),
|
|
535
|
+
preserveBlankLines = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveBlankLines", false),
|
|
536
|
+
admonitions = props.getMapOrNull("md4cFlags").getBooleanOrDefault("admonitions", true),
|
|
461
537
|
)
|
|
538
|
+
val isGFM = props.getBooleanOrDefault("isGFM", true)
|
|
462
539
|
val allowTrailingMargin = props.getBooleanOrDefault("allowTrailingMargin", false)
|
|
463
540
|
val fontSize = getInitialFontSize(styleMap, context, allowFontScaling, fontScale, maxFontSizeMultiplier)
|
|
464
541
|
|
|
465
542
|
return try {
|
|
466
543
|
val ast =
|
|
467
|
-
Parser.shared.parseMarkdown(markdown, md4cFlags)
|
|
544
|
+
Parser.shared.parseMarkdown(markdown, md4cFlags, isGFM)
|
|
468
545
|
?: return YogaMeasureOutput.make(PixelUtil.toDIPFromPixel(width), 0f)
|
|
469
546
|
|
|
470
547
|
val style = StyleConfig(styleMap, context, allowFontScaling, maxFontSizeMultiplier)
|
|
@@ -547,6 +624,24 @@ object MeasurementStore {
|
|
|
547
624
|
totalHeightPx += style.codeBlockStyle.marginBottom
|
|
548
625
|
}
|
|
549
626
|
}
|
|
627
|
+
|
|
628
|
+
is RenderedSegment.Blockquote -> {
|
|
629
|
+
totalHeightPx += style.blockquoteStyle.marginTop
|
|
630
|
+
totalHeightPx += BlockquoteContainerView.measureBlockquoteNodeHeight(segment.node, style, context, width)
|
|
631
|
+
maxContentWidthPx = width
|
|
632
|
+
if (includeBottomMargin) {
|
|
633
|
+
totalHeightPx += style.blockquoteStyle.marginBottom
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
is RenderedSegment.Video -> {
|
|
638
|
+
totalHeightPx += style.videoStyle.marginTop
|
|
639
|
+
totalHeightPx += width / style.videoStyle.resolvedAspectRatio
|
|
640
|
+
maxContentWidthPx = width
|
|
641
|
+
if (includeBottomMargin) {
|
|
642
|
+
totalHeightPx += style.videoStyle.marginBottom
|
|
643
|
+
}
|
|
644
|
+
}
|
|
550
645
|
}
|
|
551
646
|
}
|
|
552
647
|
|
|
@@ -605,14 +700,15 @@ object MeasurementStore {
|
|
|
605
700
|
styleMap: ReadableMap?,
|
|
606
701
|
context: Context,
|
|
607
702
|
md4cFlags: Md4cFlags,
|
|
703
|
+
isGFM: Boolean,
|
|
608
704
|
allowFontScaling: Boolean,
|
|
609
705
|
maxFontSizeMultiplier: Float,
|
|
610
706
|
imageRequestHeaders: Map<String, String> = emptyMap(),
|
|
611
|
-
):
|
|
707
|
+
): Spannable? {
|
|
612
708
|
if (styleMap == null) return null
|
|
613
709
|
|
|
614
710
|
return try {
|
|
615
|
-
val ast = Parser.shared.parseMarkdown(markdown, md4cFlags) ?: return null
|
|
711
|
+
val ast = Parser.shared.parseMarkdown(markdown, md4cFlags, isGFM) ?: return null
|
|
616
712
|
val style = StyleConfig(styleMap, context, allowFontScaling, maxFontSizeMultiplier)
|
|
617
713
|
style.imageRequestHeaders = imageRequestHeaders
|
|
618
714
|
measureRenderer.configure(style, context)
|
|
@@ -685,11 +781,14 @@ object MeasurementStore {
|
|
|
685
781
|
builder.setUseLineSpacingFromFallbacks(true)
|
|
686
782
|
}
|
|
687
783
|
|
|
784
|
+
applyLineLimit(builder, viewId)
|
|
785
|
+
|
|
688
786
|
val layout = builder.build()
|
|
689
|
-
val
|
|
787
|
+
val visibleLineCount = visibleLineCount(layout, viewId)
|
|
788
|
+
val measuredHeight = truncatedHeight(layout, visibleLineCount, content)
|
|
690
789
|
|
|
691
|
-
// Calculate actual content width (widest line)
|
|
692
|
-
val measuredWidth = (0 until
|
|
790
|
+
// Calculate actual content width (widest visible line)
|
|
791
|
+
val measuredWidth = (0 until visibleLineCount).maxOfOrNull { layout.getLineWidth(it) } ?: 0f
|
|
693
792
|
|
|
694
793
|
return YogaMeasureOutput.make(
|
|
695
794
|
PixelUtil.toDIPFromPixel(ceil(measuredWidth)),
|
|
@@ -697,6 +796,69 @@ object MeasurementStore {
|
|
|
697
796
|
)
|
|
698
797
|
}
|
|
699
798
|
|
|
799
|
+
// Applies the per-view numberOfLines / ellipsizeMode clamp to a builder, matching
|
|
800
|
+
// RN's TextLayoutManager.buildLayout: only when a line limit is set.
|
|
801
|
+
private fun applyLineLimit(
|
|
802
|
+
builder: StaticLayout.Builder,
|
|
803
|
+
viewId: Int?,
|
|
804
|
+
) {
|
|
805
|
+
val maxLines = resolveMaxLines(viewId)
|
|
806
|
+
if (maxLines > 0) {
|
|
807
|
+
builder.setMaxLines(maxLines).setEllipsize(resolveEllipsize(viewId))
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
private fun visibleLineCount(
|
|
812
|
+
layout: StaticLayout,
|
|
813
|
+
viewId: Int?,
|
|
814
|
+
): Int {
|
|
815
|
+
val maxLines = resolveMaxLines(viewId)
|
|
816
|
+
return if (maxLines > 0) minOf(maxLines, layout.lineCount) else layout.lineCount
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
private fun truncatedHeight(
|
|
820
|
+
layout: StaticLayout,
|
|
821
|
+
visibleLineCount: Int,
|
|
822
|
+
text: CharSequence,
|
|
823
|
+
): Float {
|
|
824
|
+
if (visibleLineCount <= 0) return 0f
|
|
825
|
+
val lastLine = visibleLineCount - 1
|
|
826
|
+
val bottom = layout.getLineBottom(lastLine).toFloat()
|
|
827
|
+
return (bottom - measureLeakedTrailingMargin(layout, lastLine, text)).coerceAtLeast(0f)
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// When we clamp the text mid-paragraph, drop the trailing block margin that Android
|
|
831
|
+
// bakes into the truncated last line (only when content follows, like MarginBottomSpan).
|
|
832
|
+
private fun measureLeakedTrailingMargin(
|
|
833
|
+
layout: StaticLayout,
|
|
834
|
+
lastLine: Int,
|
|
835
|
+
text: CharSequence,
|
|
836
|
+
): Float {
|
|
837
|
+
val spanned = text as? Spanned ?: return 0f
|
|
838
|
+
val lineStart = layout.getLineStart(lastLine)
|
|
839
|
+
val lineEnd = layout.getLineEnd(lastLine)
|
|
840
|
+
if (lineEnd <= lineStart || lineEnd < 1 || text[lineEnd - 1] != '\n') return 0f
|
|
841
|
+
if (!hasContentAfter(text, lineEnd)) return 0f
|
|
842
|
+
val trailing =
|
|
843
|
+
spanned
|
|
844
|
+
.getSpans(lineStart, lineEnd, MarginBottomSpan::class.java)
|
|
845
|
+
.firstOrNull { spanned.getSpanEnd(it) == lineEnd } ?: return 0f
|
|
846
|
+
return trailing.marginBottom.toInt().toFloat()
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
private fun hasContentAfter(
|
|
850
|
+
text: CharSequence,
|
|
851
|
+
pos: Int,
|
|
852
|
+
): Boolean {
|
|
853
|
+
if (pos >= text.length) return false
|
|
854
|
+
if (text[pos] == '\n') {
|
|
855
|
+
val nextPos = pos + 1
|
|
856
|
+
if (nextPos >= text.length) return false
|
|
857
|
+
return text[nextPos] != '\n'
|
|
858
|
+
}
|
|
859
|
+
return true
|
|
860
|
+
}
|
|
861
|
+
|
|
700
862
|
/**
|
|
701
863
|
* Measures text and returns both the size and the layout for calculating last line descent.
|
|
702
864
|
*/
|
|
@@ -723,17 +885,20 @@ object MeasurementStore {
|
|
|
723
885
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
724
886
|
setUseLineSpacingFromFallbacks(true)
|
|
725
887
|
}
|
|
888
|
+
applyLineLimit(this, viewId)
|
|
726
889
|
}.build()
|
|
727
890
|
|
|
728
|
-
|
|
891
|
+
val visibleLineCount = visibleLineCount(layout, viewId)
|
|
892
|
+
|
|
893
|
+
// Find the widest visible line to get the actual content width
|
|
729
894
|
val maxLineWidth =
|
|
730
|
-
(0 until
|
|
895
|
+
(0 until visibleLineCount)
|
|
731
896
|
.maxOfOrNull { layout.getLineWidth(it) } ?: 0f
|
|
732
897
|
|
|
733
898
|
val size =
|
|
734
899
|
YogaMeasureOutput.make(
|
|
735
900
|
PixelUtil.toDIPFromPixel(ceil(maxLineWidth)),
|
|
736
|
-
PixelUtil.toDIPFromPixel(layout
|
|
901
|
+
PixelUtil.toDIPFromPixel(truncatedHeight(layout, visibleLineCount, content)),
|
|
737
902
|
)
|
|
738
903
|
|
|
739
904
|
return size to layout
|
|
@@ -30,4 +30,14 @@ abstract class AccessibleMarkdownTextView
|
|
|
30
30
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect)
|
|
31
31
|
accessibilityHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect)
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
override fun onDetachedFromWindow() {
|
|
35
|
+
// Before super, and here rather than in a ViewManager's
|
|
36
|
+
// onDropViewInstance: getViewTreeObserver() returns the WINDOW's observer
|
|
37
|
+
// only while the view is attached. Once detached it hands back the view's
|
|
38
|
+
// own floating observer, so a removal then would target the wrong
|
|
39
|
+
// observer and leave the listener on the window.
|
|
40
|
+
accessibilityHelper.cleanup()
|
|
41
|
+
super.onDetachedFromWindow()
|
|
42
|
+
}
|
|
33
43
|
}
|
|
@@ -2,6 +2,7 @@ package com.swmansion.enriched.markdown.accessibility
|
|
|
2
2
|
|
|
3
3
|
import android.graphics.Rect
|
|
4
4
|
import android.os.Bundle
|
|
5
|
+
import android.text.Layout
|
|
5
6
|
import android.text.Spanned
|
|
6
7
|
import android.view.View
|
|
7
8
|
import android.view.ViewTreeObserver
|
|
@@ -91,6 +92,17 @@ class MarkdownAccessibilityHelper(
|
|
|
91
92
|
observer.addOnGlobalLayoutListener(listener)
|
|
92
93
|
}
|
|
93
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Drops the pending global-layout listener, if any is still registered.
|
|
97
|
+
*
|
|
98
|
+
* Must run while the view is attached: `textView.viewTreeObserver` returns
|
|
99
|
+
* the window's observer only until detach, and the listener was merged into
|
|
100
|
+
* it from the view's floating observer when the view attached.
|
|
101
|
+
*/
|
|
102
|
+
fun cleanup() {
|
|
103
|
+
removePendingLayoutListener()
|
|
104
|
+
}
|
|
105
|
+
|
|
94
106
|
private fun removePendingLayoutListener() {
|
|
95
107
|
val listener = pendingLayoutListener ?: return
|
|
96
108
|
pendingLayoutListener = null
|
|
@@ -128,18 +140,22 @@ class MarkdownAccessibilityHelper(
|
|
|
128
140
|
if (spanned.isEmpty()) return emptyList()
|
|
129
141
|
|
|
130
142
|
val text = spanned.toString()
|
|
143
|
+
val endLimit = visibleTextLength(text.length)
|
|
131
144
|
val result = mutableListOf<AccessibilityItem>()
|
|
132
145
|
var nextId = 0
|
|
133
146
|
val semanticSpans = collectSemanticSpans(spanned)
|
|
134
147
|
|
|
135
148
|
var paraStart = 0
|
|
136
|
-
while (paraStart <
|
|
149
|
+
while (paraStart < endLimit) {
|
|
137
150
|
val newlineIdx = text.indexOf('\n', paraStart)
|
|
138
|
-
val paraEnd = if (newlineIdx == -1) text.length else newlineIdx + 1
|
|
151
|
+
val paraEnd = minOf(if (newlineIdx == -1) text.length else newlineIdx + 1, endLimit)
|
|
139
152
|
val trimmed = text.substring(paraStart, paraEnd).trim()
|
|
140
153
|
|
|
141
154
|
if (trimmed.isNotEmpty()) {
|
|
142
|
-
val spansInParagraph =
|
|
155
|
+
val spansInParagraph =
|
|
156
|
+
semanticSpans
|
|
157
|
+
.filter { it.start < paraEnd && it.end > paraStart }
|
|
158
|
+
.map { it.copy(end = minOf(it.end, endLimit)) }
|
|
143
159
|
|
|
144
160
|
if (spansInParagraph.isEmpty()) {
|
|
145
161
|
result.add(
|
|
@@ -152,7 +168,37 @@ class MarkdownAccessibilityHelper(
|
|
|
152
168
|
paraStart = paraEnd
|
|
153
169
|
}
|
|
154
170
|
|
|
155
|
-
return result.ifEmpty {
|
|
171
|
+
return result.ifEmpty {
|
|
172
|
+
val visibleText = text.substring(0, endLimit).trim()
|
|
173
|
+
if (visibleText.isEmpty()) emptyList() else listOf(AccessibilityItem(0, visibleText, 0, endLimit))
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Last line that is visible; less than lineCount - 1 when height-capped (e.g. `clip`). */
|
|
178
|
+
private fun lastVisibleLineIndex(layout: Layout): Int {
|
|
179
|
+
val maxLines = textView.maxLines.coerceAtLeast(1)
|
|
180
|
+
return (minOf(layout.lineCount, maxLines) - 1).coerceIn(0, layout.lineCount - 1)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Ellipsis-aware end offset for a visible line. */
|
|
184
|
+
private fun visibleLineEnd(
|
|
185
|
+
layout: Layout,
|
|
186
|
+
line: Int,
|
|
187
|
+
): Int {
|
|
188
|
+
val lineEnd = layout.getLineEnd(line)
|
|
189
|
+
val count = layout.getEllipsisCount(line)
|
|
190
|
+
if (count == 0) return lineEnd
|
|
191
|
+
// Only a tail ellipsis hides text up to the end of the line. Head/middle hide a prefix or an
|
|
192
|
+
// inner range, so the line end is still laid out and must stay reachable.
|
|
193
|
+
val hiddenStart = layout.getLineStart(line) + layout.getEllipsisStart(line)
|
|
194
|
+
return if (hiddenStart + count >= lineEnd) hiddenStart else lineEnd
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** End offset of the laid-out (visible) text; less than the full length when truncated. */
|
|
198
|
+
private fun visibleTextLength(fullLength: Int): Int {
|
|
199
|
+
val layout = textView.layout ?: return fullLength
|
|
200
|
+
if (layout.lineCount == 0) return fullLength
|
|
201
|
+
return minOf(fullLength, maxOf(0, visibleLineEnd(layout, lastVisibleLineIndex(layout))))
|
|
156
202
|
}
|
|
157
203
|
|
|
158
204
|
private fun collectSemanticSpans(spanned: Spanned): List<SpanRange> =
|
|
@@ -389,8 +435,10 @@ class MarkdownAccessibilityHelper(
|
|
|
389
435
|
|
|
390
436
|
private fun boundsForItem(item: AccessibilityItem): Rect {
|
|
391
437
|
val layout = textView.layout ?: return Rect()
|
|
392
|
-
|
|
393
|
-
val
|
|
438
|
+
if (layout.lineCount == 0) return Rect()
|
|
439
|
+
val maxOffset = visibleLineEnd(layout, lastVisibleLineIndex(layout))
|
|
440
|
+
val vs = item.visibleStart.coerceIn(0, maxOffset)
|
|
441
|
+
val ve = item.visibleEnd.coerceIn(vs, maxOffset)
|
|
394
442
|
|
|
395
443
|
val startLine = layout.getLineForOffset(vs)
|
|
396
444
|
val endLine = layout.getLineForOffset(maxOf(vs, ve - 1))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
class CodeBlockPressEvent(
|
|
8
|
+
surfaceId: Int,
|
|
9
|
+
viewId: Int,
|
|
10
|
+
private val code: String,
|
|
11
|
+
private val language: String,
|
|
12
|
+
) : Event<CodeBlockPressEvent>(surfaceId, viewId) {
|
|
13
|
+
override fun getEventName(): String = EVENT_NAME
|
|
14
|
+
|
|
15
|
+
override fun getEventData(): WritableMap =
|
|
16
|
+
Arguments.createMap().apply {
|
|
17
|
+
putString("code", code)
|
|
18
|
+
putString("language", language)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
companion object {
|
|
22
|
+
const val EVENT_NAME: String = "onCodeBlockPress"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
class ImagePressEvent(
|
|
8
|
+
surfaceId: Int,
|
|
9
|
+
viewId: Int,
|
|
10
|
+
private val url: String,
|
|
11
|
+
private val altText: String,
|
|
12
|
+
) : Event<ImagePressEvent>(surfaceId, viewId) {
|
|
13
|
+
override fun getEventName(): String = EVENT_NAME
|
|
14
|
+
|
|
15
|
+
override fun getEventData(): WritableMap {
|
|
16
|
+
val eventData: WritableMap = Arguments.createMap()
|
|
17
|
+
eventData.putString("url", url)
|
|
18
|
+
eventData.putString("altText", altText)
|
|
19
|
+
return eventData
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
companion object {
|
|
23
|
+
const val EVENT_NAME: String = "onImagePress"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
class LatexErrorEvent(
|
|
8
|
+
surfaceId: Int,
|
|
9
|
+
viewId: Int,
|
|
10
|
+
private val source: String,
|
|
11
|
+
private val message: String?,
|
|
12
|
+
private val displayMode: Boolean,
|
|
13
|
+
) : Event<LatexErrorEvent>(surfaceId, viewId) {
|
|
14
|
+
override fun getEventName(): String = EVENT_NAME
|
|
15
|
+
|
|
16
|
+
override fun canCoalesce(): Boolean = false
|
|
17
|
+
|
|
18
|
+
override fun getEventData(): WritableMap {
|
|
19
|
+
val eventData: WritableMap = Arguments.createMap()
|
|
20
|
+
eventData.putString("source", source)
|
|
21
|
+
eventData.putString("message", message)
|
|
22
|
+
eventData.putBoolean("displayMode", displayMode)
|
|
23
|
+
return eventData
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
const val EVENT_NAME: String = "onLatexError"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -15,6 +15,7 @@ import com.facebook.react.viewmanagers.EnrichedMarkdownTextInputManagerDelegate
|
|
|
15
15
|
import com.facebook.react.viewmanagers.EnrichedMarkdownTextInputManagerInterface
|
|
16
16
|
import com.facebook.yoga.YogaMeasureMode
|
|
17
17
|
import com.swmansion.enriched.markdown.input.autolink.LinkRegexConfig
|
|
18
|
+
import com.swmansion.enriched.markdown.input.editing.MarkdownShortcutsConfig
|
|
18
19
|
import com.swmansion.enriched.markdown.input.events.OnCaretRectChangeEvent
|
|
19
20
|
import com.swmansion.enriched.markdown.input.events.OnChangeMarkdownEvent
|
|
20
21
|
import com.swmansion.enriched.markdown.input.events.OnChangeMentionEvent
|
|
@@ -36,6 +37,7 @@ import com.swmansion.enriched.markdown.input.layout.InputMeasurementStore
|
|
|
36
37
|
import com.swmansion.enriched.markdown.input.model.StyleType
|
|
37
38
|
import com.swmansion.enriched.markdown.input.toolbar.FormatMenuConfig
|
|
38
39
|
import com.swmansion.enriched.markdown.input.toolbar.InputSelectionMenuConfig
|
|
40
|
+
import com.swmansion.enriched.markdown.utils.common.getBooleanOrDefault
|
|
39
41
|
import com.swmansion.enriched.markdown.utils.input.BorderPropsApplicator
|
|
40
42
|
import com.swmansion.enriched.markdown.utils.input.MarkdownStyleParser
|
|
41
43
|
|
|
@@ -182,6 +184,25 @@ class EnrichedMarkdownTextInputManager :
|
|
|
182
184
|
view?.blockSyntax = value
|
|
183
185
|
}
|
|
184
186
|
|
|
187
|
+
@ReactProp(name = "markdownShortcuts")
|
|
188
|
+
override fun setMarkdownShortcuts(
|
|
189
|
+
view: EnrichedMarkdownTextInputView?,
|
|
190
|
+
value: ReadableMap?,
|
|
191
|
+
) {
|
|
192
|
+
if (view == null) return
|
|
193
|
+
view.markdownShortcuts =
|
|
194
|
+
if (value == null) {
|
|
195
|
+
MarkdownShortcutsConfig()
|
|
196
|
+
} else {
|
|
197
|
+
// Guarded reads (fork convention): ReadableMap.getBoolean throws on a missing key.
|
|
198
|
+
MarkdownShortcutsConfig(
|
|
199
|
+
heading = value.getBooleanOrDefault("heading", false),
|
|
200
|
+
unorderedList = value.getBooleanOrDefault("unorderedList", false),
|
|
201
|
+
orderedList = value.getBooleanOrDefault("orderedList", false),
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
185
206
|
@ReactProp(name = "autoCapitalize")
|
|
186
207
|
override fun setAutoCapitalize(
|
|
187
208
|
view: EnrichedMarkdownTextInputView?,
|