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
package/android/src/main/java/com/swmansion/enriched/markdown/segments/BlockquoteContainerView.kt
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.content.ClipData
|
|
4
|
+
import android.content.ClipboardManager
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.graphics.Canvas
|
|
7
|
+
import android.graphics.Color
|
|
8
|
+
import android.graphics.Paint
|
|
9
|
+
import android.graphics.Path
|
|
10
|
+
import android.graphics.RectF
|
|
11
|
+
import android.graphics.Typeface
|
|
12
|
+
import android.view.View
|
|
13
|
+
import androidx.core.graphics.withSave
|
|
14
|
+
import com.facebook.react.common.ReactConstants
|
|
15
|
+
import com.facebook.react.views.text.ReactTypefaceUtils.applyStyles
|
|
16
|
+
import com.swmansion.enriched.markdown.EnrichedMarkdownInternalText
|
|
17
|
+
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
18
|
+
import com.swmansion.enriched.markdown.styles.BlockquoteStyle
|
|
19
|
+
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
20
|
+
import com.swmansion.enriched.markdown.utils.common.BreakStrategyUtils
|
|
21
|
+
import com.swmansion.enriched.markdown.utils.common.serialization.MarkdownASTSerializer
|
|
22
|
+
import com.swmansion.enriched.markdown.views.ContextMenuPopup
|
|
23
|
+
import kotlin.math.ceil
|
|
24
|
+
import kotlin.math.max
|
|
25
|
+
import kotlin.math.roundToInt
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A GFM blockquote rendered as a recursive container: it splits its own AST
|
|
29
|
+
* children into segments and lays them out through the shared ContainerNodeView
|
|
30
|
+
* machinery, so a nested quote becomes another BlockquoteContainerView, a fenced
|
|
31
|
+
* code block becomes a CodeBlockContainerView, and prose collapses into a single
|
|
32
|
+
* text view. Nesting depth is automatic: each level is its own view, inset
|
|
33
|
+
* further by its padding, so onDraw only ever renders one accent bar plus the
|
|
34
|
+
* background for this single level.
|
|
35
|
+
*
|
|
36
|
+
* The content inset is applied as this view's padding (left = borderWidth +
|
|
37
|
+
* gapWidth + padding, other edges = padding), mirroring the geometry
|
|
38
|
+
* BlockquoteSpan draws for the in-text (list-nested) path; the base measure and
|
|
39
|
+
* layout already honor padding.
|
|
40
|
+
*
|
|
41
|
+
* Streaming is treated as static inside a quote (no pending-fence handling, no
|
|
42
|
+
* tail/fade animation) to keep the recursion tractable; a content change re-signs
|
|
43
|
+
* the whole container so the reconciler still reuses the outer quote view.
|
|
44
|
+
*/
|
|
45
|
+
class BlockquoteContainerView(
|
|
46
|
+
context: Context,
|
|
47
|
+
private val parentConfig: SegmentViewConfig,
|
|
48
|
+
) : ContainerNodeView(context),
|
|
49
|
+
BlockSegmentView {
|
|
50
|
+
private val blockquoteStyle: BlockquoteStyle = parentConfig.style.blockquoteStyle
|
|
51
|
+
|
|
52
|
+
private val borderWidthPx: Float = blockquoteStyle.borderWidth
|
|
53
|
+
private val paddingPx: Float = blockquoteStyle.padding
|
|
54
|
+
private val leftInset: Int = ceil(borderWidthPx + blockquoteStyle.gapWidth + paddingPx).toInt()
|
|
55
|
+
private val verticalInset: Int = ceil(paddingPx).toInt()
|
|
56
|
+
private val rightInset: Int = ceil(paddingPx).toInt()
|
|
57
|
+
|
|
58
|
+
// Set from the applied node: null for a plain quote, the admonition type
|
|
59
|
+
// ("note"/"tip"/…) otherwise. Drives the header + per-type theming.
|
|
60
|
+
private var admonitionType: String? = null
|
|
61
|
+
|
|
62
|
+
// Cached markdown source for the "Copy as Markdown" action.
|
|
63
|
+
private var cachedMarkdown: String = ""
|
|
64
|
+
|
|
65
|
+
// Cached plain text for the "Copy" action.
|
|
66
|
+
private var cachedPlainText: String = ""
|
|
67
|
+
|
|
68
|
+
private val iconSizePx: Int = ceil(blockquoteStyle.fontSize).toInt()
|
|
69
|
+
|
|
70
|
+
private val titlePaint =
|
|
71
|
+
Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
72
|
+
typeface =
|
|
73
|
+
Typeface.create(
|
|
74
|
+
applyStyles(
|
|
75
|
+
null,
|
|
76
|
+
ReactConstants.UNSET,
|
|
77
|
+
ReactConstants.UNSET,
|
|
78
|
+
blockquoteStyle.fontFamily.takeIf { it.isNotEmpty() },
|
|
79
|
+
context.assets,
|
|
80
|
+
),
|
|
81
|
+
Typeface.BOLD,
|
|
82
|
+
)
|
|
83
|
+
textSize = blockquoteStyle.fontSize
|
|
84
|
+
}
|
|
85
|
+
private val iconPaint =
|
|
86
|
+
Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
|
87
|
+
|
|
88
|
+
private fun reservedHeaderHeight(): Int = if (admonitionType != null) ceil(admonitionHeaderReservedHeight(blockquoteStyle)).toInt() else 0
|
|
89
|
+
|
|
90
|
+
// Only the outermost quote carries vertical margins; a quote nested directly
|
|
91
|
+
// inside another quote is separated by the parent's padding alone (matches the
|
|
92
|
+
// commonmark BlockquoteRenderer, which applies margins only at depth 0).
|
|
93
|
+
var nested: Boolean = false
|
|
94
|
+
|
|
95
|
+
override val segmentMarginTop: Int get() = if (nested) 0 else blockquoteStyle.marginTop.toInt()
|
|
96
|
+
override val segmentMarginBottom: Int get() = if (nested) 0 else blockquoteStyle.marginBottom.toInt()
|
|
97
|
+
|
|
98
|
+
private val backgroundPaint =
|
|
99
|
+
Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
|
100
|
+
private val borderPaint =
|
|
101
|
+
Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
102
|
+
style = Paint.Style.FILL
|
|
103
|
+
color = blockquoteStyle.borderColor
|
|
104
|
+
}
|
|
105
|
+
private val rect = RectF()
|
|
106
|
+
private val path = Path()
|
|
107
|
+
private val radiiArray = FloatArray(8)
|
|
108
|
+
|
|
109
|
+
init {
|
|
110
|
+
setWillNotDraw(false)
|
|
111
|
+
setPadding(leftInset, verticalInset, rightInset, verticalInset)
|
|
112
|
+
segmentViewFactory = ChildFactory()
|
|
113
|
+
trailingMarginEnabled = false
|
|
114
|
+
isLongClickable = true
|
|
115
|
+
setOnLongClickListener { view -> showContextMenu(view) }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fun applyBlockquoteNode(node: MarkdownASTNode) {
|
|
119
|
+
admonitionType =
|
|
120
|
+
if (node.type == MarkdownASTNode.NodeType.Admonition) {
|
|
121
|
+
node.getAttribute("admonitionType")?.takeIf { it.isNotEmpty() } ?: "note"
|
|
122
|
+
} else {
|
|
123
|
+
null
|
|
124
|
+
}
|
|
125
|
+
// Reserve the header band above the body by enlarging the top padding.
|
|
126
|
+
setPadding(leftInset, verticalInset + reservedHeaderHeight(), rightInset, verticalInset)
|
|
127
|
+
|
|
128
|
+
cachedMarkdown = MarkdownASTSerializer.serializeBlockquote(node)
|
|
129
|
+
cachedPlainText = MarkdownASTSerializer.plainText(node)
|
|
130
|
+
|
|
131
|
+
val segments = splitASTIntoSegments(node)
|
|
132
|
+
val rendered =
|
|
133
|
+
MarkdownSegmentRenderer.render(
|
|
134
|
+
segments,
|
|
135
|
+
parentConfig.style,
|
|
136
|
+
context,
|
|
137
|
+
parentConfig.onLinkPress,
|
|
138
|
+
parentConfig.onLinkLongPress,
|
|
139
|
+
blockquoteStyle,
|
|
140
|
+
onLatexError = parentConfig.onLatexError,
|
|
141
|
+
)
|
|
142
|
+
applySegments(rendered, reset = false)
|
|
143
|
+
requestLayout()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private fun showContextMenu(anchor: View): Boolean {
|
|
147
|
+
if (!parentConfig.dynamicProps.enableBlockContextMenu) return false
|
|
148
|
+
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
149
|
+
ContextMenuPopup.show(anchor, this) {
|
|
150
|
+
item(ContextMenuPopup.Icon.COPY, parentConfig.dynamicProps.copyLabel) {
|
|
151
|
+
if (cachedPlainText.isNotEmpty()) {
|
|
152
|
+
clipboard.setPrimaryClip(ClipData.newPlainText("Blockquote", cachedPlainText))
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
item(ContextMenuPopup.Icon.DOCUMENT, parentConfig.dynamicProps.copyAsMarkdownLabel) {
|
|
156
|
+
if (cachedMarkdown.isNotEmpty()) {
|
|
157
|
+
clipboard.setPrimaryClip(ClipData.newPlainText("Blockquote", cachedMarkdown))
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return true
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
override fun onMeasure(
|
|
165
|
+
widthSpec: Int,
|
|
166
|
+
heightSpec: Int,
|
|
167
|
+
) {
|
|
168
|
+
val measuredWidth = MeasureSpec.getSize(widthSpec)
|
|
169
|
+
measureSegmentChildren(measuredWidth)
|
|
170
|
+
setMeasuredDimension(measuredWidth, computeSegmentsTotalHeight())
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
override fun onLayout(
|
|
174
|
+
changed: Boolean,
|
|
175
|
+
l: Int,
|
|
176
|
+
t: Int,
|
|
177
|
+
r: Int,
|
|
178
|
+
b: Int,
|
|
179
|
+
) {
|
|
180
|
+
layoutSegments()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
override fun onDraw(canvas: Canvas) {
|
|
184
|
+
super.onDraw(canvas)
|
|
185
|
+
val radius = blockquoteStyle.borderRadius
|
|
186
|
+
val hasRadius = radius > 0f
|
|
187
|
+
|
|
188
|
+
// Admonitions theme the box with their per-type color; a plain quote keeps
|
|
189
|
+
// the base blockquote colors.
|
|
190
|
+
val type = admonitionType
|
|
191
|
+
val tint =
|
|
192
|
+
if (type != null) {
|
|
193
|
+
blockquoteStyle.admonitions[type]?.color ?: blockquoteStyle.borderColor
|
|
194
|
+
} else {
|
|
195
|
+
blockquoteStyle.borderColor
|
|
196
|
+
}
|
|
197
|
+
val bgColor =
|
|
198
|
+
if (type != null) {
|
|
199
|
+
blockquoteStyle.admonitions[type]?.backgroundColor?.takeIf { it != Color.TRANSPARENT }
|
|
200
|
+
} else {
|
|
201
|
+
blockquoteStyle.backgroundColor?.takeIf { it != Color.TRANSPARENT }
|
|
202
|
+
}
|
|
203
|
+
borderPaint.color = tint
|
|
204
|
+
|
|
205
|
+
if (hasRadius) {
|
|
206
|
+
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
|
207
|
+
radiiArray.fill(radius)
|
|
208
|
+
path.reset()
|
|
209
|
+
path.addRoundRect(rect, radiiArray, Path.Direction.CW)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (bgColor != null) {
|
|
213
|
+
backgroundPaint.color = bgColor
|
|
214
|
+
if (hasRadius) {
|
|
215
|
+
canvas.drawPath(path, backgroundPaint)
|
|
216
|
+
} else {
|
|
217
|
+
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), backgroundPaint)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Clip the accent bar to the rounded box so its top-left/bottom-left corners
|
|
222
|
+
// follow the border radius instead of poking past the background as squares.
|
|
223
|
+
if (hasRadius) {
|
|
224
|
+
canvas.withSave {
|
|
225
|
+
clipPath(path)
|
|
226
|
+
drawRect(0f, 0f, borderWidthPx, height.toFloat(), borderPaint)
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
canvas.drawRect(0f, 0f, borderWidthPx, height.toFloat(), borderPaint)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (type != null) {
|
|
233
|
+
drawAdmonitionHeader(canvas, type, tint)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Draws the admonition header (tinted octicon + capitalized title) in the band
|
|
238
|
+
// reserved at the top of the view by the enlarged top padding.
|
|
239
|
+
private fun drawAdmonitionHeader(
|
|
240
|
+
canvas: Canvas,
|
|
241
|
+
type: String,
|
|
242
|
+
tint: Int,
|
|
243
|
+
) {
|
|
244
|
+
val headerTop = verticalInset.toFloat()
|
|
245
|
+
val headerHeight = admonitionHeaderContentHeight(blockquoteStyle)
|
|
246
|
+
var titleX = leftInset.toFloat()
|
|
247
|
+
|
|
248
|
+
val iconPath = AdmonitionIcons.path(type)
|
|
249
|
+
if (iconPath != null) {
|
|
250
|
+
val scale = iconSizePx / AdmonitionIcons.VIEWBOX
|
|
251
|
+
val iconY = headerTop + (headerHeight - iconSizePx) / 2f
|
|
252
|
+
iconPaint.color = tint
|
|
253
|
+
canvas.withSave {
|
|
254
|
+
translate(leftInset.toFloat(), iconY)
|
|
255
|
+
scale(scale, scale)
|
|
256
|
+
drawPath(iconPath, iconPaint)
|
|
257
|
+
}
|
|
258
|
+
titleX = (leftInset + iconSizePx + (iconSizePx * 0.4f).roundToInt()).toFloat()
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
titlePaint.color = tint
|
|
262
|
+
val fm = titlePaint.fontMetrics
|
|
263
|
+
val baseline = headerTop + headerHeight / 2f - (fm.ascent + fm.descent) / 2f
|
|
264
|
+
canvas.drawText(AdmonitionIcons.title(type), titleX, baseline, titlePaint)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Factory for this quote's own children. It reuses the shared creators for
|
|
269
|
+
* every kind and, for a nested Blockquote, creates another
|
|
270
|
+
* BlockquoteContainerView (the recursion). Streaming is static here: no
|
|
271
|
+
* animation, no pending-fence sync.
|
|
272
|
+
*/
|
|
273
|
+
private inner class ChildFactory : SegmentViewFactory {
|
|
274
|
+
override fun matchesKind(
|
|
275
|
+
view: View,
|
|
276
|
+
segment: RenderedSegment,
|
|
277
|
+
): Boolean =
|
|
278
|
+
when (segment) {
|
|
279
|
+
is RenderedSegment.Text -> view is EnrichedMarkdownInternalText
|
|
280
|
+
is RenderedSegment.Table -> view is TableContainerView
|
|
281
|
+
is RenderedSegment.Math -> SegmentViewCreators.isMathContainerView(view)
|
|
282
|
+
is RenderedSegment.CodeBlock -> view is CodeBlockContainerView
|
|
283
|
+
is RenderedSegment.Blockquote -> view is BlockquoteContainerView
|
|
284
|
+
is RenderedSegment.Video -> SegmentViewCreators.isVideoContainerView(view)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
override fun createView(segment: RenderedSegment): View =
|
|
288
|
+
when (segment) {
|
|
289
|
+
is RenderedSegment.Text -> {
|
|
290
|
+
SegmentViewCreators.createTextView(segment, parentConfig)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
is RenderedSegment.Table -> {
|
|
294
|
+
SegmentViewCreators.createTableView(segment, parentConfig)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
is RenderedSegment.Math -> {
|
|
298
|
+
SegmentViewCreators.createMathView(segment, parentConfig)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
is RenderedSegment.CodeBlock -> {
|
|
302
|
+
SegmentViewCreators.createCodeBlockView(segment, parentConfig)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
is RenderedSegment.Blockquote -> {
|
|
306
|
+
SegmentViewCreators.createBlockquoteView(segment, parentConfig).apply { nested = true }
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
is RenderedSegment.Video -> {
|
|
310
|
+
SegmentViewCreators.createVideoView(segment, parentConfig)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
override fun updateView(
|
|
315
|
+
view: View,
|
|
316
|
+
segment: RenderedSegment,
|
|
317
|
+
) {
|
|
318
|
+
when (segment) {
|
|
319
|
+
is RenderedSegment.Text -> SegmentViewCreators.updateTextView(view as EnrichedMarkdownInternalText, segment)
|
|
320
|
+
is RenderedSegment.Table -> (view as TableContainerView).applyTableNode(segment.node)
|
|
321
|
+
is RenderedSegment.Math -> SegmentViewCreators.updateMathView(view, segment)
|
|
322
|
+
is RenderedSegment.CodeBlock -> (view as CodeBlockContainerView).applyCodeBlockNode(segment.node)
|
|
323
|
+
is RenderedSegment.Blockquote -> (view as BlockquoteContainerView).applyBlockquoteNode(segment.node)
|
|
324
|
+
is RenderedSegment.Video -> SegmentViewCreators.updateVideoView(view, segment)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
override fun animateNewView(
|
|
329
|
+
view: View,
|
|
330
|
+
segment: RenderedSegment,
|
|
331
|
+
) = Unit
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
companion object {
|
|
335
|
+
// Height of the header band (icon + title row). Shared by the instance draw
|
|
336
|
+
// path and the view-free measurement so both reserve identical space.
|
|
337
|
+
fun admonitionHeaderContentHeight(style: BlockquoteStyle): Float = ceil(max(ceil(style.fontSize), style.fontSize * 1.35f))
|
|
338
|
+
|
|
339
|
+
// Vertical space the header adds above the body (band + gap).
|
|
340
|
+
fun admonitionHeaderReservedHeight(style: BlockquoteStyle): Float =
|
|
341
|
+
admonitionHeaderContentHeight(style) + (style.fontSize * 0.4f).roundToInt()
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* View-free height of a blockquote node at the given outer content width.
|
|
345
|
+
* The children are summed at the reduced inner width (outer minus horizontal
|
|
346
|
+
* inset) and the vertical inset is added; nested quotes recurse through this
|
|
347
|
+
* same function via SegmentHeightMeasurer. Math child heights use the shared
|
|
348
|
+
* estimate to avoid a main-thread measure from the layout pass.
|
|
349
|
+
*
|
|
350
|
+
* Potential win: this runs splitASTIntoSegments + render for measurement, and
|
|
351
|
+
* applyBlockquoteNode runs them again for display, so each nesting level renders
|
|
352
|
+
* its content twice. The two passes run on different threads (this one off the
|
|
353
|
+
* main thread, view creation on it) and key off different widths, so a shared
|
|
354
|
+
* cache would need to be thread-safe and width-aware; not worth it yet, but the
|
|
355
|
+
* rendered segments could be memoized so the view path reuses this result.
|
|
356
|
+
*/
|
|
357
|
+
fun measureBlockquoteNodeHeight(
|
|
358
|
+
node: MarkdownASTNode,
|
|
359
|
+
config: StyleConfig,
|
|
360
|
+
context: Context,
|
|
361
|
+
width: Float,
|
|
362
|
+
): Float {
|
|
363
|
+
val style = config.blockquoteStyle
|
|
364
|
+
val leftInset = ceil(style.borderWidth + style.gapWidth + style.padding).toInt()
|
|
365
|
+
val rightInset = ceil(style.padding).toInt()
|
|
366
|
+
val verticalInset = ceil(style.padding).toInt()
|
|
367
|
+
val headerReserved =
|
|
368
|
+
if (node.type == MarkdownASTNode.NodeType.Admonition) {
|
|
369
|
+
ceil(admonitionHeaderReservedHeight(style))
|
|
370
|
+
} else {
|
|
371
|
+
0f
|
|
372
|
+
}
|
|
373
|
+
val innerWidth = (width - leftInset - rightInset).coerceAtLeast(1f)
|
|
374
|
+
|
|
375
|
+
val segments = splitASTIntoSegments(node)
|
|
376
|
+
val rendered = MarkdownSegmentRenderer.render(segments, config, context, null, null, style)
|
|
377
|
+
|
|
378
|
+
val fontSize = style.fontSize
|
|
379
|
+
val breakStrategy = BreakStrategyUtils.resolveBreakStrategy(null)
|
|
380
|
+
|
|
381
|
+
val childrenHeight =
|
|
382
|
+
SegmentHeightMeasurer.measureSegmentsHeight(
|
|
383
|
+
segments = rendered,
|
|
384
|
+
style = config,
|
|
385
|
+
context = context,
|
|
386
|
+
contentWidthPx = innerWidth,
|
|
387
|
+
fontSizePx = fontSize,
|
|
388
|
+
breakStrategy = breakStrategy,
|
|
389
|
+
allowTrailingMargin = false,
|
|
390
|
+
mathHeightForIndex = { estimateMathHeight(config) },
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
return childrenHeight + verticalInset * 2f + headerReserved
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private fun estimateMathHeight(config: StyleConfig): Float {
|
|
397
|
+
val estimatedHeight = config.mathStyle.fontSize * 1.4f
|
|
398
|
+
return estimatedHeight + config.mathStyle.padding * 2
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.swmansion.enriched.markdown.
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
2
|
|
|
3
3
|
import android.content.ClipData
|
|
4
4
|
import android.content.ClipboardManager
|
|
@@ -17,6 +17,8 @@ import android.text.StaticLayout
|
|
|
17
17
|
import android.text.TextPaint
|
|
18
18
|
import android.text.TextUtils
|
|
19
19
|
import android.util.TypedValue
|
|
20
|
+
import android.view.GestureDetector
|
|
21
|
+
import android.view.MotionEvent
|
|
20
22
|
import android.view.View
|
|
21
23
|
import android.widget.FrameLayout
|
|
22
24
|
import android.widget.HorizontalScrollView
|
|
@@ -31,6 +33,10 @@ import com.swmansion.enriched.markdown.utils.common.CodeBlockHighlighter
|
|
|
31
33
|
import com.swmansion.enriched.markdown.utils.common.CodeBlockNode
|
|
32
34
|
import com.swmansion.enriched.markdown.utils.text.extensions.applyCodeBlockTextStyle
|
|
33
35
|
import com.swmansion.enriched.markdown.utils.text.span.SPAN_FLAGS_EXCLUSIVE_EXCLUSIVE
|
|
36
|
+
import com.swmansion.enriched.markdown.views.BlockMenuOptions
|
|
37
|
+
import com.swmansion.enriched.markdown.views.ContextMenuPopup
|
|
38
|
+
import com.swmansion.enriched.markdown.views.CopyGlyph
|
|
39
|
+
import com.swmansion.enriched.markdown.views.blockCopyItems
|
|
34
40
|
import kotlin.math.ceil
|
|
35
41
|
|
|
36
42
|
/**
|
|
@@ -59,15 +65,14 @@ class CodeBlockContainerView(
|
|
|
59
65
|
override val segmentMarginTop: Int get() = codeBlockStyle.marginTop.toInt()
|
|
60
66
|
override val segmentMarginBottom: Int get() = codeBlockStyle.marginBottom.toInt()
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
var copyAsMarkdownLabel: String = ""
|
|
68
|
+
// Shared, runtime-mutable block props read live at use-time (menu-open, tap);
|
|
69
|
+
// the root mutates the one instance in place, so this view and any sibling
|
|
70
|
+
// created later see the same current values. See DynamicBlockProps.
|
|
71
|
+
var dynamicProps: DynamicBlockProps = DynamicBlockProps()
|
|
68
72
|
|
|
69
|
-
//
|
|
70
|
-
// control, not a context menu, and stays.
|
|
73
|
+
// Fork: hides the long-press copy menu only; the header copy button is a visible
|
|
74
|
+
// control, not a context menu, and stays. Takes precedence over
|
|
75
|
+
// dynamicProps.enableBlockContextMenu (merge decision D1).
|
|
71
76
|
var contextMenuHidden: Boolean = false
|
|
72
77
|
|
|
73
78
|
// Called instead of the menu on long press while contextMenuHidden is on, so
|
|
@@ -75,7 +80,7 @@ class CodeBlockContainerView(
|
|
|
75
80
|
var onMenuSuppressed: ((markdown: String, text: String) -> Unit)? = null
|
|
76
81
|
|
|
77
82
|
// Copy / Copy as Markdown visibility, Copy format and the header copy button.
|
|
78
|
-
// The header button always copies the raw code.
|
|
83
|
+
// The header button always copies the raw code. Labels come from dynamicProps.
|
|
79
84
|
var menuOptions: BlockMenuOptions = BlockMenuOptions()
|
|
80
85
|
set(value) {
|
|
81
86
|
field = value
|
|
@@ -83,8 +88,6 @@ class CodeBlockContainerView(
|
|
|
83
88
|
copyButton.visibility = if (value.copyButtonHidden) View.GONE else View.VISIBLE
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
var onCopyPress: ((code: String, language: String) -> Unit)? = null
|
|
87
|
-
|
|
88
91
|
private var code: String = ""
|
|
89
92
|
private var language: String? = null
|
|
90
93
|
private var fenceChar: String = "`"
|
|
@@ -141,8 +144,12 @@ class CodeBlockContainerView(
|
|
|
141
144
|
setTextColor(secondaryColor(codeBlockStyle.color))
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
// contentDescription reads the shared label live so a runtime label change is
|
|
148
|
+
// reflected for TalkBack without a push (mirrors the live block-menu reads).
|
|
144
149
|
private val copyButton =
|
|
145
|
-
AppCompatImageButton(context)
|
|
150
|
+
object : AppCompatImageButton(context) {
|
|
151
|
+
override fun getContentDescription(): CharSequence = dynamicProps.copyLabel
|
|
152
|
+
}.apply {
|
|
146
153
|
background = null
|
|
147
154
|
scaleType = ImageView.ScaleType.CENTER
|
|
148
155
|
setImageDrawable(
|
|
@@ -160,6 +167,20 @@ class CodeBlockContainerView(
|
|
|
160
167
|
strokeWidth = context.resources.displayMetrics.density
|
|
161
168
|
}
|
|
162
169
|
|
|
170
|
+
private val tapDetector =
|
|
171
|
+
GestureDetector(
|
|
172
|
+
context,
|
|
173
|
+
object : GestureDetector.SimpleOnGestureListener() {
|
|
174
|
+
override fun onDown(e: MotionEvent): Boolean = true
|
|
175
|
+
|
|
176
|
+
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
|
177
|
+
if (isPointInsideCopyButton(e.x, e.y)) return false
|
|
178
|
+
handleCodeBlockPress()
|
|
179
|
+
return false
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
|
|
163
184
|
init {
|
|
164
185
|
setWillNotDraw(false)
|
|
165
186
|
background =
|
|
@@ -264,17 +285,20 @@ class CodeBlockContainerView(
|
|
|
264
285
|
// one never does).
|
|
265
286
|
private fun showContextMenu(anchor: View): Boolean {
|
|
266
287
|
if (pending) return false
|
|
288
|
+
// contextMenuHidden wins over enableBlockContextMenu so the host still learns
|
|
289
|
+
// about the long press (onMenuSuppressed -> onSelectionChange). Decision D1.
|
|
267
290
|
if (contextMenuHidden) {
|
|
268
291
|
val onSuppressed = onMenuSuppressed ?: return false
|
|
269
292
|
onSuppressed(CodeBlockNode.fencedMarkdown(code, language, fenceChar), code)
|
|
270
293
|
return true
|
|
271
294
|
}
|
|
295
|
+
if (!dynamicProps.enableBlockContextMenu) return false
|
|
272
296
|
if (!menuOptions.hasItems) return false
|
|
273
297
|
ContextMenuPopup.show(anchor, this) {
|
|
274
298
|
blockCopyItems(
|
|
275
299
|
menuOptions,
|
|
276
|
-
copyLabel,
|
|
277
|
-
copyAsMarkdownLabel,
|
|
300
|
+
dynamicProps.copyLabel,
|
|
301
|
+
dynamicProps.copyAsMarkdownLabel,
|
|
278
302
|
markdown = { CodeBlockNode.fencedMarkdown(code, language, fenceChar) },
|
|
279
303
|
rawText = { code },
|
|
280
304
|
copyRaw = ::copyCode,
|
|
@@ -287,9 +311,24 @@ class CodeBlockContainerView(
|
|
|
287
311
|
private fun copyCode() {
|
|
288
312
|
if (pending || code.isEmpty()) return
|
|
289
313
|
copyToClipboard(code)
|
|
290
|
-
onCopyPress?.invoke(code, language ?: "")
|
|
314
|
+
dynamicProps.onCopyPress?.invoke(code, language ?: "")
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private fun handleCodeBlockPress() {
|
|
318
|
+
if (!dynamicProps.enableCodeBlockPress || pending) return
|
|
319
|
+
dynamicProps.onCodeBlockPress?.invoke(code, language ?: "")
|
|
291
320
|
}
|
|
292
321
|
|
|
322
|
+
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
323
|
+
tapDetector.onTouchEvent(ev)
|
|
324
|
+
return super.dispatchTouchEvent(ev)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private fun isPointInsideCopyButton(
|
|
328
|
+
x: Float,
|
|
329
|
+
y: Float,
|
|
330
|
+
): Boolean = x >= copyButton.left && x < copyButton.right && y >= copyButton.top && y < copyButton.bottom
|
|
331
|
+
|
|
293
332
|
private fun copyFencedMarkdown() {
|
|
294
333
|
if (code.isEmpty()) return
|
|
295
334
|
copyToClipboard(CodeBlockNode.fencedMarkdown(code, language, fenceChar))
|