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
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.os.Build
|
|
5
|
+
import android.text.Layout
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import android.util.TypedValue
|
|
8
|
+
import android.view.View
|
|
9
|
+
import com.swmansion.enriched.markdown.EnrichedMarkdownInternalText
|
|
10
|
+
import com.swmansion.enriched.markdown.accessibility.AccessibilityLabels
|
|
11
|
+
import com.swmansion.enriched.markdown.math.LatexErrorReporter
|
|
12
|
+
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
13
|
+
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
14
|
+
import com.swmansion.enriched.markdown.utils.common.BreakStrategyUtils
|
|
15
|
+
import com.swmansion.enriched.markdown.utils.common.FeatureFlags
|
|
16
|
+
import com.swmansion.enriched.markdown.utils.text.view.SelectionMenuConfig
|
|
17
|
+
import com.swmansion.enriched.markdown.utils.text.view.applySelectionColors
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Runtime-mutable block props that a prop update can flip WITHOUT recreating the
|
|
21
|
+
* segment tree (the reconcile path, reset = false): the block context-menu gate,
|
|
22
|
+
* the code-block tap gate, the copy menu labels, and the copy/tap callbacks.
|
|
23
|
+
*
|
|
24
|
+
* The root owns one instance and mutates it in place; every view down the tree
|
|
25
|
+
* holds the same reference (SegmentViewConfig.dynamicProps) and reads a field at use-time
|
|
26
|
+
* (menu-open, tap). That single shared box is the source of truth, so a view
|
|
27
|
+
* created after a toggle (e.g. a code block added to a blockquote once
|
|
28
|
+
* onCodeBlockPress is on) is born current instead of from a stale snapshot, and
|
|
29
|
+
* no per-toggle push into existing views is needed. See issues #768 and #822.
|
|
30
|
+
*
|
|
31
|
+
* Only props read at interaction-time, with no layout/draw dependency, belong
|
|
32
|
+
* here; anything that rebuilds the tree on change stays an immutable field on
|
|
33
|
+
* SegmentViewConfig, where a snapshot can never go stale.
|
|
34
|
+
*/
|
|
35
|
+
class DynamicBlockProps {
|
|
36
|
+
var enableBlockContextMenu: Boolean = true
|
|
37
|
+
var enableCodeBlockPress: Boolean = false
|
|
38
|
+
var copyLabel: String = ""
|
|
39
|
+
var copyAsMarkdownLabel: String = ""
|
|
40
|
+
var onCopyPress: ((code: String, language: String) -> Unit)? = null
|
|
41
|
+
var onCodeBlockPress: ((code: String, language: String) -> Unit)? = null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Configuration shared by every ContainerNodeView's SegmentViewFactory so that
|
|
46
|
+
* Text / Table / Math / CodeBlock / Blockquote child views are constructed the
|
|
47
|
+
* same way regardless of the host (root document or nested blockquote).
|
|
48
|
+
*
|
|
49
|
+
* The root supplies the full wiring; a nested blockquote supplies the subset it
|
|
50
|
+
* needs (styling, link/copy callbacks, accessibility labels) and treats
|
|
51
|
+
* streaming as static.
|
|
52
|
+
*
|
|
53
|
+
* Everything here is a fixed-for-the-view's-life value: changing any of it
|
|
54
|
+
* recreates the tree (see EnrichedMarkdown.setMarkdownStyle et al.), so a
|
|
55
|
+
* snapshot never goes stale. The runtime-mutable block props live in [dynamicProps].
|
|
56
|
+
*/
|
|
57
|
+
data class SegmentViewConfig(
|
|
58
|
+
val context: Context,
|
|
59
|
+
val style: StyleConfig,
|
|
60
|
+
val allowFontScaling: Boolean,
|
|
61
|
+
val maxFontSizeMultiplier: Float,
|
|
62
|
+
val accessibilityLabels: AccessibilityLabels,
|
|
63
|
+
val selectionMenuConfig: SelectionMenuConfig,
|
|
64
|
+
val textBreakStrategy: String,
|
|
65
|
+
val selectable: Boolean,
|
|
66
|
+
val selectionColor: Int?,
|
|
67
|
+
val selectionHandleColor: Int?,
|
|
68
|
+
val contextMenuItemTexts: List<String>,
|
|
69
|
+
val dynamicProps: DynamicBlockProps,
|
|
70
|
+
val onLinkPress: ((String) -> Unit)?,
|
|
71
|
+
val onLinkLongPress: ((String) -> Unit)?,
|
|
72
|
+
val onTaskListItemPress: ((taskIndex: Int, checked: Boolean, itemText: String) -> Unit)?,
|
|
73
|
+
val onContextMenuItemPress: ((itemText: String, selectedText: String, selectionStart: Int, selectionEnd: Int) -> Unit)?,
|
|
74
|
+
val onLatexError: LatexErrorReporter? = null,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Pure per-kind child view creators used by both the root and nested factories.
|
|
79
|
+
* Kept free of host-only concerns (streaming tail animation, pending fence
|
|
80
|
+
* handling, spoiler overlay mode, task-list toggle) so the root can add those on
|
|
81
|
+
* top while nested blockquotes reuse the exact same construction.
|
|
82
|
+
*/
|
|
83
|
+
object SegmentViewCreators {
|
|
84
|
+
private const val TAG = "SegmentViewCreators"
|
|
85
|
+
|
|
86
|
+
fun createTextView(
|
|
87
|
+
segment: RenderedSegment.Text,
|
|
88
|
+
config: SegmentViewConfig,
|
|
89
|
+
): EnrichedMarkdownInternalText =
|
|
90
|
+
EnrichedMarkdownInternalText(config.context).apply {
|
|
91
|
+
selectionMenuConfig = config.selectionMenuConfig
|
|
92
|
+
accessibilityLabels = config.accessibilityLabels
|
|
93
|
+
setIsSelectable(config.selectable)
|
|
94
|
+
setTextSize(TypedValue.COMPLEX_UNIT_PX, config.style.paragraphStyle.fontSize)
|
|
95
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
96
|
+
breakStrategy = BreakStrategyUtils.resolveBreakStrategy(config.textBreakStrategy)
|
|
97
|
+
}
|
|
98
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && segment.needsJustify) {
|
|
99
|
+
justificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD
|
|
100
|
+
}
|
|
101
|
+
lastElementMarginBottom = segment.lastElementMarginBottom
|
|
102
|
+
applyStyledText(segment.styledText)
|
|
103
|
+
segment.imageSpans.forEach { it.registerTextView(this) }
|
|
104
|
+
|
|
105
|
+
onTaskListItemPressCallback = { taskIndex, checked, itemText ->
|
|
106
|
+
config.onTaskListItemPress?.invoke(taskIndex, checked, itemText)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (config.contextMenuItemTexts.isNotEmpty()) {
|
|
110
|
+
val onPress = config.onContextMenuItemPress
|
|
111
|
+
if (onPress != null) {
|
|
112
|
+
setContextMenuItems(config.contextMenuItemTexts) { itemText, selectedText, start, end ->
|
|
113
|
+
onPress(itemText, selectedText, start, end)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
applySelectionColors(config.selectionColor, config.selectionHandleColor)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fun updateTextView(
|
|
122
|
+
view: EnrichedMarkdownInternalText,
|
|
123
|
+
segment: RenderedSegment.Text,
|
|
124
|
+
) {
|
|
125
|
+
view.lastElementMarginBottom = segment.lastElementMarginBottom
|
|
126
|
+
view.applyStyledText(segment.styledText)
|
|
127
|
+
segment.imageSpans.forEach { it.registerTextView(view) }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fun createTableView(
|
|
131
|
+
segment: RenderedSegment.Table,
|
|
132
|
+
config: SegmentViewConfig,
|
|
133
|
+
) = TableContainerView(config.context, config.style).apply {
|
|
134
|
+
dynamicProps = config.dynamicProps
|
|
135
|
+
allowFontScaling = config.allowFontScaling
|
|
136
|
+
maxFontSizeMultiplier = config.maxFontSizeMultiplier
|
|
137
|
+
accessibilityLabels = config.accessibilityLabels
|
|
138
|
+
onLinkPress = config.onLinkPress
|
|
139
|
+
onLinkLongPress = config.onLinkLongPress
|
|
140
|
+
applyTableNode(segment.node)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
fun createCodeBlockView(
|
|
144
|
+
segment: RenderedSegment.CodeBlock,
|
|
145
|
+
config: SegmentViewConfig,
|
|
146
|
+
) = CodeBlockContainerView(config.context, config.style).apply {
|
|
147
|
+
dynamicProps = config.dynamicProps
|
|
148
|
+
applyCodeBlockNode(segment.node)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Availability is fixed at build time (the math source set is compiled in or not), so the
|
|
152
|
+
// reflective lookup - including the ClassNotFoundException when math is disabled - is resolved
|
|
153
|
+
// once instead of on every reconcile via isMathContainerView/matchesKind.
|
|
154
|
+
private val cachedMathContainerClass: Class<*>? by lazy {
|
|
155
|
+
try {
|
|
156
|
+
Class.forName("com.swmansion.enriched.markdown.segments.MathContainerView")
|
|
157
|
+
} catch (_: Exception) {
|
|
158
|
+
null
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fun mathContainerClass(): Class<*>? = cachedMathContainerClass
|
|
163
|
+
|
|
164
|
+
fun isMathContainerView(view: View): Boolean = cachedMathContainerClass?.isInstance(view) == true
|
|
165
|
+
|
|
166
|
+
fun createMathView(
|
|
167
|
+
segment: RenderedSegment.Math,
|
|
168
|
+
config: SegmentViewConfig,
|
|
169
|
+
): View {
|
|
170
|
+
val resolvedClass = mathContainerClass()
|
|
171
|
+
if (!FeatureFlags.IS_MATH_ENABLED || resolvedClass == null) return View(config.context)
|
|
172
|
+
return try {
|
|
173
|
+
val view =
|
|
174
|
+
resolvedClass
|
|
175
|
+
.getConstructor(Context::class.java, StyleConfig::class.java)
|
|
176
|
+
.newInstance(config.context, config.style) as View
|
|
177
|
+
runCatching {
|
|
178
|
+
resolvedClass
|
|
179
|
+
.getMethod("setAccessibilityLabels", AccessibilityLabels::class.java)
|
|
180
|
+
.invoke(view, config.accessibilityLabels)
|
|
181
|
+
}
|
|
182
|
+
resolvedClass
|
|
183
|
+
.getMethod("setDynamicProps", DynamicBlockProps::class.java)
|
|
184
|
+
.invoke(view, config.dynamicProps)
|
|
185
|
+
runCatching {
|
|
186
|
+
resolvedClass
|
|
187
|
+
.getMethod("setOnLatexError", LatexErrorReporter::class.java)
|
|
188
|
+
.invoke(view, config.onLatexError)
|
|
189
|
+
}
|
|
190
|
+
resolvedClass.getMethod("setHighlighted", Boolean::class.javaPrimitiveType).invoke(view, segment.highlighted)
|
|
191
|
+
resolvedClass.getMethod("applyLatex", String::class.java).invoke(view, segment.latex)
|
|
192
|
+
view
|
|
193
|
+
} catch (e: Exception) {
|
|
194
|
+
Log.e(TAG, "Failed to create math view", e)
|
|
195
|
+
View(config.context)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fun updateMathView(
|
|
200
|
+
view: View,
|
|
201
|
+
segment: RenderedSegment.Math,
|
|
202
|
+
) {
|
|
203
|
+
mathContainerClass()
|
|
204
|
+
?.getMethod("setHighlighted", Boolean::class.javaPrimitiveType)
|
|
205
|
+
?.invoke(view, segment.highlighted)
|
|
206
|
+
mathContainerClass()
|
|
207
|
+
?.getMethod("applyLatex", String::class.java)
|
|
208
|
+
?.invoke(view, segment.latex)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
fun createBlockquoteView(
|
|
212
|
+
segment: RenderedSegment.Blockquote,
|
|
213
|
+
config: SegmentViewConfig,
|
|
214
|
+
) = BlockquoteContainerView(config.context, config).apply {
|
|
215
|
+
applyBlockquoteNode(segment.node)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private val cachedVideoContainerClass: Class<*>? by lazy {
|
|
219
|
+
try {
|
|
220
|
+
Class.forName("com.swmansion.enriched.markdown.segments.VideoContainerView")
|
|
221
|
+
} catch (_: Exception) {
|
|
222
|
+
null
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fun videoContainerClass(): Class<*>? = cachedVideoContainerClass
|
|
227
|
+
|
|
228
|
+
fun isVideoContainerView(view: View): Boolean = cachedVideoContainerClass?.isInstance(view) == true
|
|
229
|
+
|
|
230
|
+
fun createVideoView(
|
|
231
|
+
segment: RenderedSegment.Video,
|
|
232
|
+
config: SegmentViewConfig,
|
|
233
|
+
): View {
|
|
234
|
+
val resolvedClass = videoContainerClass()
|
|
235
|
+
if (!FeatureFlags.IS_VIDEO_ENABLED || resolvedClass == null) return View(config.context)
|
|
236
|
+
return try {
|
|
237
|
+
val view =
|
|
238
|
+
resolvedClass
|
|
239
|
+
.getConstructor(Context::class.java, StyleConfig::class.java)
|
|
240
|
+
.newInstance(config.context, config.style) as View
|
|
241
|
+
resolvedClass
|
|
242
|
+
.getMethod("setDynamicProps", DynamicBlockProps::class.java)
|
|
243
|
+
.invoke(view, config.dynamicProps)
|
|
244
|
+
resolvedClass
|
|
245
|
+
.getMethod("applyVideoNode", MarkdownASTNode::class.java)
|
|
246
|
+
.invoke(view, segment.node)
|
|
247
|
+
view
|
|
248
|
+
} catch (e: Exception) {
|
|
249
|
+
Log.e(TAG, "Failed to create video view", e)
|
|
250
|
+
View(config.context)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
fun updateVideoView(
|
|
255
|
+
view: View,
|
|
256
|
+
segment: RenderedSegment.Video,
|
|
257
|
+
) {
|
|
258
|
+
videoContainerClass()
|
|
259
|
+
?.getMethod("applyVideoNode", MarkdownASTNode::class.java)
|
|
260
|
+
?.invoke(view, segment.node)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.swmansion.enriched.markdown.segments
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Per-kind view work seam used by ContainerNodeView to build and reconcile
|
|
7
|
+
* child views from RenderedSegment data. The root document and every
|
|
8
|
+
* BlockquoteContainerView supply their own implementation so the reconcile /
|
|
9
|
+
* layout loop can stay identical while the actual child view construction
|
|
10
|
+
* (callbacks, styling, accessibility) varies per host.
|
|
11
|
+
*/
|
|
12
|
+
interface SegmentViewFactory {
|
|
13
|
+
fun matchesKind(
|
|
14
|
+
view: View,
|
|
15
|
+
segment: RenderedSegment,
|
|
16
|
+
): Boolean
|
|
17
|
+
|
|
18
|
+
fun createView(segment: RenderedSegment): View
|
|
19
|
+
|
|
20
|
+
fun updateView(
|
|
21
|
+
view: View,
|
|
22
|
+
segment: RenderedSegment,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
fun animateNewView(
|
|
26
|
+
view: View,
|
|
27
|
+
segment: RenderedSegment,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -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
|
|
@@ -9,7 +9,8 @@ import android.graphics.Path
|
|
|
9
9
|
import android.graphics.RectF
|
|
10
10
|
import android.graphics.Typeface
|
|
11
11
|
import android.text.Layout
|
|
12
|
-
import android.text.
|
|
12
|
+
import android.text.Spannable
|
|
13
|
+
import android.text.Spanned
|
|
13
14
|
import android.text.StaticLayout
|
|
14
15
|
import android.text.TextPaint
|
|
15
16
|
import android.text.style.AlignmentSpan
|
|
@@ -24,9 +25,11 @@ import com.swmansion.enriched.markdown.accessibility.AccessibilityLabels
|
|
|
24
25
|
import com.swmansion.enriched.markdown.parser.MarkdownASTNode
|
|
25
26
|
import com.swmansion.enriched.markdown.parser.MarkdownASTNode.NodeType
|
|
26
27
|
import com.swmansion.enriched.markdown.renderer.Renderer
|
|
28
|
+
import com.swmansion.enriched.markdown.spans.ImageSpan
|
|
27
29
|
import com.swmansion.enriched.markdown.spans.LinkChipBackgroundSpan
|
|
28
30
|
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
29
31
|
import com.swmansion.enriched.markdown.styles.TableStyle
|
|
32
|
+
import com.swmansion.enriched.markdown.utils.common.findEnrichedMarkdownAncestor
|
|
30
33
|
import com.swmansion.enriched.markdown.utils.common.layout.isLayoutRTL
|
|
31
34
|
import com.swmansion.enriched.markdown.utils.common.serialization.MarkdownASTSerializer
|
|
32
35
|
import com.swmansion.enriched.markdown.utils.text.conversion.HTMLGenerator
|
|
@@ -34,7 +37,9 @@ import com.swmansion.enriched.markdown.utils.text.extensions.replaceMathSpansWit
|
|
|
34
37
|
import com.swmansion.enriched.markdown.utils.text.view.LinkLongPressMovementMethod
|
|
35
38
|
import com.swmansion.enriched.markdown.utils.text.view.cancelJSTouchForLinkTap
|
|
36
39
|
import com.swmansion.enriched.markdown.utils.text.view.reallowParentInterceptIfLinkReleased
|
|
40
|
+
import com.swmansion.enriched.markdown.views.BlockMenuOptions
|
|
37
41
|
import com.swmansion.enriched.markdown.views.ContextMenuPopup
|
|
42
|
+
import com.swmansion.enriched.markdown.views.blockCopyItems
|
|
38
43
|
import kotlin.math.ceil
|
|
39
44
|
import kotlin.math.max
|
|
40
45
|
import kotlin.math.min
|
|
@@ -62,8 +67,11 @@ class TableContainerView(
|
|
|
62
67
|
if (rowCount > 0) renderGrid()
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
var
|
|
70
|
+
// Runtime-mutable block props read live at menu-open. See DynamicBlockProps.
|
|
71
|
+
var dynamicProps: DynamicBlockProps = DynamicBlockProps()
|
|
72
|
+
|
|
73
|
+
// Fork: per-item menu options (BlockMenuOptions) and contextMenuHidden. Labels come
|
|
74
|
+
// from dynamicProps. contextMenuHidden wins over enableBlockContextMenu (decision D1).
|
|
67
75
|
var contextMenuHidden: Boolean = false
|
|
68
76
|
var menuOptions: BlockMenuOptions = BlockMenuOptions()
|
|
69
77
|
|
|
@@ -171,12 +179,12 @@ class TableContainerView(
|
|
|
171
179
|
node: MarkdownASTNode,
|
|
172
180
|
isHeader: Boolean,
|
|
173
181
|
alignment: Layout.Alignment,
|
|
174
|
-
):
|
|
175
|
-
val
|
|
182
|
+
): Spannable {
|
|
183
|
+
val paragraph = MarkdownASTNode(NodeType.Paragraph, children = node.children)
|
|
176
184
|
val cellParagraphStyle = styleConfig.tableCellParagraphStyle(tableStyle, isHeader)
|
|
177
185
|
return styleConfig
|
|
178
186
|
.withParagraphOverride(cellParagraphStyle) {
|
|
179
|
-
Renderer().apply { configure(styleConfig, context) }.
|
|
187
|
+
Renderer().apply { configure(styleConfig, context) }.renderContent(listOf(paragraph), onLinkPress, onLinkLongPress)
|
|
180
188
|
}.apply {
|
|
181
189
|
if (isNotEmpty()) {
|
|
182
190
|
if (isHeader) setSpan(HeaderTypefaceSpan(styleConfig.tableHeaderTypeface ?: Typeface.DEFAULT_BOLD), 0, length, 33)
|
|
@@ -227,10 +235,7 @@ class TableContainerView(
|
|
|
227
235
|
val cellBg =
|
|
228
236
|
CellBackgroundView(context).apply {
|
|
229
237
|
configure(rowBg, tableStyle.borderColor, tableStyle.borderWidth)
|
|
230
|
-
setOnLongClickListener { view ->
|
|
231
|
-
showContextMenu(view)
|
|
232
|
-
true
|
|
233
|
-
}
|
|
238
|
+
setOnLongClickListener { view -> showContextMenu(view) }
|
|
234
239
|
importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
|
235
240
|
}
|
|
236
241
|
|
|
@@ -308,10 +313,7 @@ class TableContainerView(
|
|
|
308
313
|
Layout.Alignment.ALIGN_OPPOSITE -> Gravity.END
|
|
309
314
|
else -> Gravity.START
|
|
310
315
|
}
|
|
311
|
-
setOnLongClickListener { view ->
|
|
312
|
-
showContextMenu(view)
|
|
313
|
-
true
|
|
314
|
-
}
|
|
316
|
+
setOnLongClickListener { view -> showContextMenu(view) }
|
|
315
317
|
}
|
|
316
318
|
val horizontalPadding = tableStyle.cellPaddingHorizontal
|
|
317
319
|
val verticalPadding = tableStyle.cellPaddingVertical
|
|
@@ -325,6 +327,37 @@ class TableContainerView(
|
|
|
325
327
|
topMargin = ceil(verticalPadding).toInt()
|
|
326
328
|
},
|
|
327
329
|
)
|
|
330
|
+
|
|
331
|
+
data.attributedText
|
|
332
|
+
.getSpans(0, data.attributedText.length, ImageSpan::class.java)
|
|
333
|
+
.forEach { span -> span.registerTextView(cellTextView) { scheduleImageRemeasure() } }
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private var imageRemeasurePending = false
|
|
337
|
+
|
|
338
|
+
private fun scheduleImageRemeasure() {
|
|
339
|
+
if (imageRemeasurePending) return
|
|
340
|
+
imageRemeasurePending = true
|
|
341
|
+
post {
|
|
342
|
+
imageRemeasurePending = false
|
|
343
|
+
remeasureForImageLoad()
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private fun remeasureForImageLoad() {
|
|
348
|
+
if (rows.isEmpty()) return
|
|
349
|
+
val (widths, heights) =
|
|
350
|
+
computeTableDimensions(rows.map { row -> row.map { it.attributedText } }, styleConfig, context)
|
|
351
|
+
if (widths == columnWidths && heights == rowHeights) return
|
|
352
|
+
|
|
353
|
+
columnWidths = widths
|
|
354
|
+
rowHeights = heights
|
|
355
|
+
totalTableWidth = columnWidths.sum() + tableStyle.borderWidth
|
|
356
|
+
totalTableHeight = rowHeights.sum() + tableStyle.borderWidth
|
|
357
|
+
renderGrid()
|
|
358
|
+
requestLayout()
|
|
359
|
+
|
|
360
|
+
findEnrichedMarkdownAncestor()?.onImageLayoutChanged()
|
|
328
361
|
}
|
|
329
362
|
|
|
330
363
|
override fun onMeasure(
|
|
@@ -381,28 +414,40 @@ class TableContainerView(
|
|
|
381
414
|
}
|
|
382
415
|
}
|
|
383
416
|
|
|
384
|
-
private fun showContextMenu(anchor: View) {
|
|
417
|
+
private fun showContextMenu(anchor: View): Boolean {
|
|
385
418
|
if (contextMenuHidden) {
|
|
386
|
-
onMenuSuppressed
|
|
387
|
-
|
|
419
|
+
val onSuppressed = onMenuSuppressed ?: return false
|
|
420
|
+
onSuppressed(tableMarkdown, buildPlainText())
|
|
421
|
+
return true
|
|
388
422
|
}
|
|
423
|
+
if (!dynamicProps.enableBlockContextMenu) return false
|
|
424
|
+
if (!menuOptions.hasItems) return false
|
|
389
425
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
390
426
|
ContextMenuPopup.show(anchor, this) {
|
|
391
|
-
blockCopyItems(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
427
|
+
blockCopyItems(
|
|
428
|
+
menuOptions,
|
|
429
|
+
dynamicProps.copyLabel,
|
|
430
|
+
dynamicProps.copyAsMarkdownLabel,
|
|
431
|
+
markdown = { tableMarkdown },
|
|
432
|
+
rawText = ::buildPlainText,
|
|
433
|
+
copyRaw = {
|
|
434
|
+
val plainText = buildPlainText()
|
|
435
|
+
if (plainText.isNotEmpty()) {
|
|
436
|
+
val displayMetrics = context.resources.displayMetrics
|
|
437
|
+
val tableRows =
|
|
438
|
+
rows.map { row ->
|
|
439
|
+
row.map { cell -> Triple(cell.attributedText as CharSequence, cell.isHeader, cell.alignment) }
|
|
440
|
+
}
|
|
441
|
+
val html = HTMLGenerator.generateTableHTML(tableRows, styleConfig, displayMetrics.scaledDensity, displayMetrics.density)
|
|
442
|
+
clipboard.setPrimaryClip(ClipData.newHtmlText("Table", plainText, html))
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
copyMarkdown = {
|
|
446
|
+
if (tableMarkdown.isNotEmpty()) clipboard.setPrimaryClip(ClipData.newPlainText("Table", tableMarkdown))
|
|
447
|
+
},
|
|
448
|
+
)
|
|
405
449
|
}
|
|
450
|
+
return true
|
|
406
451
|
}
|
|
407
452
|
|
|
408
453
|
private fun buildPlainText(): String = rows.joinToString("\n") { row -> row.joinToString("\t") { it.plainText } }
|
|
@@ -437,6 +482,22 @@ class TableContainerView(
|
|
|
437
482
|
}
|
|
438
483
|
}
|
|
439
484
|
|
|
485
|
+
private fun prepareImageSpansForMeasurement(
|
|
486
|
+
text: CharSequence,
|
|
487
|
+
widthPx: Int,
|
|
488
|
+
) {
|
|
489
|
+
if (widthPx <= 1) return
|
|
490
|
+
val spanned = text as? Spanned ?: return
|
|
491
|
+
spanned
|
|
492
|
+
.getSpans(0, spanned.length, ImageSpan::class.java)
|
|
493
|
+
.forEach { it.prepareForMeasurement(spanned, widthPx) }
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private fun cellHasBlockImage(text: CharSequence): Boolean {
|
|
497
|
+
val spanned = text as? Spanned ?: return false
|
|
498
|
+
return spanned.getSpans(0, spanned.length, ImageSpan::class.java).any { !it.isInline }
|
|
499
|
+
}
|
|
500
|
+
|
|
440
501
|
private fun computeTableDimensions(
|
|
441
502
|
texts: List<List<CharSequence>>,
|
|
442
503
|
config: StyleConfig,
|
|
@@ -461,8 +522,9 @@ class TableContainerView(
|
|
|
461
522
|
.setIncludePad(false)
|
|
462
523
|
.build()
|
|
463
524
|
val textWidth: Float = (0 until layout.lineCount).maxOfOrNull { line -> layout.getLineWidth(line) } ?: 0f
|
|
525
|
+
val effectiveWidth = if (cellHasBlockImage(cellText)) maxColumnWidth else ceil(textWidth)
|
|
464
526
|
columnWidths[colIndex] =
|
|
465
|
-
max(columnWidths[colIndex], min(max(
|
|
527
|
+
max(columnWidths[colIndex], min(max(effectiveWidth + horizontalPadding, minColumnWidth), maxColumnWidth + horizontalPadding))
|
|
466
528
|
}
|
|
467
529
|
}
|
|
468
530
|
|
|
@@ -470,6 +532,8 @@ class TableContainerView(
|
|
|
470
532
|
texts.map { row ->
|
|
471
533
|
row
|
|
472
534
|
.mapIndexed { colIndex, cellText ->
|
|
535
|
+
val contentWidth = (columnWidths[colIndex] - horizontalPadding).toInt().coerceAtLeast(1)
|
|
536
|
+
prepareImageSpansForMeasurement(cellText, contentWidth)
|
|
473
537
|
val layout =
|
|
474
538
|
StaticLayout.Builder
|
|
475
539
|
.obtain(
|
|
@@ -477,7 +541,7 @@ class TableContainerView(
|
|
|
477
541
|
0,
|
|
478
542
|
cellText.length,
|
|
479
543
|
paint,
|
|
480
|
-
|
|
544
|
+
contentWidth,
|
|
481
545
|
).setIncludePad(false)
|
|
482
546
|
.build()
|
|
483
547
|
ceil(layout.height.toFloat()) + verticalPadding
|
|
@@ -504,7 +568,7 @@ class TableContainerView(
|
|
|
504
568
|
config.withParagraphOverride(cellParagraphStyle) {
|
|
505
569
|
Renderer()
|
|
506
570
|
.apply { configure(config, context) }
|
|
507
|
-
.
|
|
571
|
+
.renderContent(listOf(paragraph), null, null)
|
|
508
572
|
}
|
|
509
573
|
styledText.replaceMathSpansWithPlaceholders(context, config.inlineMathStyle.boxPaddingVertical)
|
|
510
574
|
if (isHeader && styledText.isNotEmpty()) {
|
|
@@ -612,7 +676,7 @@ class TableContainerView(
|
|
|
612
676
|
}
|
|
613
677
|
|
|
614
678
|
private data class TableCellData(
|
|
615
|
-
val attributedText:
|
|
679
|
+
val attributedText: Spannable,
|
|
616
680
|
val plainText: String,
|
|
617
681
|
val markdownText: String,
|
|
618
682
|
val isHeader: Boolean,
|
|
@@ -6,6 +6,7 @@ import android.graphics.Path
|
|
|
6
6
|
import android.graphics.RectF
|
|
7
7
|
import android.text.Spanned
|
|
8
8
|
import android.text.style.LineBackgroundSpan
|
|
9
|
+
import com.swmansion.enriched.markdown.spoiler.isConcealedBySpoiler
|
|
9
10
|
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
10
11
|
import kotlin.math.max
|
|
11
12
|
import kotlin.math.min
|
|
@@ -50,15 +51,29 @@ class CodeBackgroundSpan(
|
|
|
50
51
|
val spanEnd = text.getSpanEnd(this)
|
|
51
52
|
if (spanStart !in 0 until spanEnd) return
|
|
52
53
|
|
|
54
|
+
// The spoiler overlay only covers the text's glyph box, so a background drawn to the line's bounds
|
|
55
|
+
// would outline the hidden code around it.
|
|
56
|
+
if (text.isConcealedBySpoiler(maxOf(spanStart, start), minOf(spanEnd, end))) return
|
|
57
|
+
|
|
53
58
|
// 1. Determine relative positioning
|
|
54
59
|
val isFirst = spanStart >= start
|
|
55
60
|
val isLast = spanEnd <= end
|
|
56
61
|
|
|
57
62
|
// 2. Calculate coordinates
|
|
58
63
|
val finalBottom = adjustBottomForMargin(text, end, bottom)
|
|
59
|
-
val leadingMargin = leadingMarginAt(text, start)
|
|
60
|
-
val startX =
|
|
61
|
-
|
|
64
|
+
val leadingMargin = InlineBackgroundGeometry.leadingMarginAt(text, start)
|
|
65
|
+
val startX =
|
|
66
|
+
if (isFirst) {
|
|
67
|
+
InlineBackgroundGeometry.horizontalOffset(text, start, end, spanStart, p, leadingMargin) + left
|
|
68
|
+
} else {
|
|
69
|
+
left.toFloat() + leadingMargin
|
|
70
|
+
}
|
|
71
|
+
val endX =
|
|
72
|
+
if (isLast) {
|
|
73
|
+
InlineBackgroundGeometry.horizontalOffset(text, start, end, spanEnd, p, leadingMargin) + left
|
|
74
|
+
} else {
|
|
75
|
+
right.toFloat()
|
|
76
|
+
}
|
|
62
77
|
|
|
63
78
|
rect.set(min(startX, endX), top.toFloat(), max(startX, endX), finalBottom.toFloat())
|
|
64
79
|
|
|
@@ -70,15 +85,6 @@ class CodeBackgroundSpan(
|
|
|
70
85
|
drawShapes(canvas, isFirst, isLast)
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
private fun getHorizontalOffset(
|
|
74
|
-
text: CharSequence,
|
|
75
|
-
lineStart: Int,
|
|
76
|
-
lineEnd: Int,
|
|
77
|
-
index: Int,
|
|
78
|
-
paint: Paint,
|
|
79
|
-
leadingMargin: Int,
|
|
80
|
-
): Float = InlineChipPainter.horizontalOffset(text, lineStart, lineEnd, index, paint, leadingMargin)
|
|
81
|
-
|
|
82
88
|
private fun drawShapes(
|
|
83
89
|
canvas: Canvas,
|
|
84
90
|
isFirst: Boolean,
|
|
@@ -97,11 +103,6 @@ class CodeBackgroundSpan(
|
|
|
97
103
|
)
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
private fun leadingMarginAt(
|
|
101
|
-
text: Spanned,
|
|
102
|
-
lineStart: Int,
|
|
103
|
-
): Int = InlineChipPainter.leadingMarginAt(text, lineStart)
|
|
104
|
-
|
|
105
106
|
private fun adjustBottomForMargin(
|
|
106
107
|
text: Spanned,
|
|
107
108
|
lineEnd: Int,
|
|
@@ -28,6 +28,9 @@ class CodeBlockSpan(
|
|
|
28
28
|
private val context: Context,
|
|
29
29
|
private val styleCache: SpanStyleCache,
|
|
30
30
|
private val leadingIndent: Int = 0,
|
|
31
|
+
// Recovered by a tap on this span for onCodeBlockPress; unused by drawing.
|
|
32
|
+
val code: String = "",
|
|
33
|
+
val language: String = "",
|
|
31
34
|
) : MetricAffectingSpan(),
|
|
32
35
|
LineBackgroundSpan,
|
|
33
36
|
LeadingMarginSpan {
|