react-native-enriched-markdown-scaffold 1.0.2-scaffold.9 → 1.2.0-scaffold.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +718 -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 +210 -7
- 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
|
@@ -5,31 +5,37 @@ import android.content.res.Configuration
|
|
|
5
5
|
import android.os.Build
|
|
6
6
|
import android.os.Handler
|
|
7
7
|
import android.os.Looper
|
|
8
|
-
import android.util.AttributeSet
|
|
9
8
|
import android.util.Log
|
|
10
9
|
import android.view.View
|
|
11
|
-
import android.widget.FrameLayout
|
|
12
10
|
import com.facebook.react.bridge.Arguments
|
|
13
11
|
import com.facebook.react.bridge.ReadableMap
|
|
14
12
|
import com.facebook.react.uimanager.StateWrapper
|
|
15
13
|
import com.swmansion.enriched.markdown.accessibility.AccessibilityLabels
|
|
14
|
+
import com.swmansion.enriched.markdown.math.LatexErrorReporter
|
|
16
15
|
import com.swmansion.enriched.markdown.parser.Md4cFlags
|
|
17
16
|
import com.swmansion.enriched.markdown.parser.Parser
|
|
17
|
+
import com.swmansion.enriched.markdown.segments.BlockquoteContainerView
|
|
18
|
+
import com.swmansion.enriched.markdown.segments.CodeBlockContainerView
|
|
19
|
+
import com.swmansion.enriched.markdown.segments.ContainerNodeView
|
|
20
|
+
import com.swmansion.enriched.markdown.segments.DynamicBlockProps
|
|
21
|
+
import com.swmansion.enriched.markdown.segments.MarkdownSegmentRenderer
|
|
22
|
+
import com.swmansion.enriched.markdown.segments.RenderedSegment
|
|
23
|
+
import com.swmansion.enriched.markdown.segments.SegmentViewConfig
|
|
24
|
+
import com.swmansion.enriched.markdown.segments.SegmentViewCreators
|
|
25
|
+
import com.swmansion.enriched.markdown.segments.SegmentViewFactory
|
|
26
|
+
import com.swmansion.enriched.markdown.segments.TableContainerView
|
|
27
|
+
import com.swmansion.enriched.markdown.segments.splitASTIntoSegments
|
|
18
28
|
import com.swmansion.enriched.markdown.spoiler.SpoilerOverlay
|
|
19
29
|
import com.swmansion.enriched.markdown.styles.StyleConfig
|
|
20
30
|
import com.swmansion.enriched.markdown.utils.common.BreakStrategyUtils
|
|
21
31
|
import com.swmansion.enriched.markdown.utils.common.CodeBlockStreamingMode
|
|
22
|
-
import com.swmansion.enriched.markdown.utils.common.FeatureFlags
|
|
23
|
-
import com.swmansion.enriched.markdown.utils.common.MarkdownSegmentRenderer
|
|
24
|
-
import com.swmansion.enriched.markdown.utils.common.RenderedSegment
|
|
25
|
-
import com.swmansion.enriched.markdown.utils.common.SegmentReconciler
|
|
26
32
|
import com.swmansion.enriched.markdown.utils.common.StreamingMarkdownFilter
|
|
27
33
|
import com.swmansion.enriched.markdown.utils.common.TableStreamingMode
|
|
28
34
|
import com.swmansion.enriched.markdown.utils.common.emitLinkLayout
|
|
29
35
|
import com.swmansion.enriched.markdown.utils.common.emitSelectionChange
|
|
30
36
|
import com.swmansion.enriched.markdown.utils.common.isReducedMotionEnabled
|
|
31
|
-
import com.swmansion.enriched.markdown.utils.common.splitASTIntoSegments
|
|
32
37
|
import com.swmansion.enriched.markdown.utils.text.TailFadeInAnimator
|
|
38
|
+
import com.swmansion.enriched.markdown.utils.text.view.ImagePressHost
|
|
33
39
|
import com.swmansion.enriched.markdown.utils.text.view.LinkLayoutCollector
|
|
34
40
|
import com.swmansion.enriched.markdown.utils.text.view.LinkLayoutFragment
|
|
35
41
|
import com.swmansion.enriched.markdown.utils.text.view.SelectionChangeReporter
|
|
@@ -38,584 +44,640 @@ import com.swmansion.enriched.markdown.utils.text.view.SelectionRect
|
|
|
38
44
|
import com.swmansion.enriched.markdown.utils.text.view.SelectionSnapshot
|
|
39
45
|
import com.swmansion.enriched.markdown.utils.text.view.applySelectionColors
|
|
40
46
|
import com.swmansion.enriched.markdown.utils.text.view.currentTextSelection
|
|
47
|
+
import com.swmansion.enriched.markdown.utils.text.view.emitImagePressEvent
|
|
41
48
|
import com.swmansion.enriched.markdown.views.BlockMenuOptions
|
|
42
|
-
import com.swmansion.enriched.markdown.views.BlockSegmentView
|
|
43
|
-
import com.swmansion.enriched.markdown.views.CodeBlockContainerView
|
|
44
|
-
import com.swmansion.enriched.markdown.views.TableContainerView
|
|
45
49
|
import java.util.EnumSet
|
|
46
50
|
import java.util.concurrent.ExecutorService
|
|
47
51
|
import java.util.concurrent.Executors
|
|
48
|
-
import kotlin.math.ceil
|
|
49
|
-
import kotlin.math.max
|
|
50
|
-
|
|
51
|
-
class EnrichedMarkdown
|
|
52
|
-
@JvmOverloads
|
|
53
|
-
constructor(
|
|
54
|
-
context: Context,
|
|
55
|
-
attrs: AttributeSet? = null,
|
|
56
|
-
defStyleAttr: Int = 0,
|
|
57
|
-
) : FrameLayout(context, attrs, defStyleAttr) {
|
|
58
|
-
private enum class DirtyFlag {
|
|
59
|
-
RECREATE_SEGMENTS,
|
|
60
|
-
FORCE_HEIGHT,
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private val parser = Parser.shared
|
|
64
|
-
private val mainHandler = Handler(Looper.getMainLooper())
|
|
65
|
-
private val executor: ExecutorService = Executors.newSingleThreadExecutor()
|
|
66
|
-
private val mathContainerClass: Class<*>? by lazy {
|
|
67
|
-
try {
|
|
68
|
-
Class.forName("com.swmansion.enriched.markdown.views.MathContainerView")
|
|
69
|
-
} catch (_: Exception) {
|
|
70
|
-
null
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
52
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
private var forceHeightRecalculationCounter = 0
|
|
83
|
-
|
|
84
|
-
var tableStreamingMode: TableStreamingMode = TableStreamingMode.PROGRESSIVE
|
|
85
|
-
var codeBlockStreamingMode: CodeBlockStreamingMode = CodeBlockStreamingMode.PROGRESSIVE
|
|
86
|
-
private var renderPending: Boolean = false
|
|
87
|
-
|
|
88
|
-
var currentMarkdown: String = ""
|
|
89
|
-
private set
|
|
90
|
-
|
|
91
|
-
var markdownStyle: StyleConfig? = null
|
|
92
|
-
private set
|
|
93
|
-
|
|
94
|
-
private var markdownStyleMap: ReadableMap? = null
|
|
95
|
-
private var lastKnownFontScale: Float = context.resources.configuration.fontScale
|
|
96
|
-
|
|
97
|
-
var md4cFlags: Md4cFlags = Md4cFlags.DEFAULT
|
|
98
|
-
private set
|
|
99
|
-
private var allowFontScaling: Boolean = true
|
|
100
|
-
private var maxFontSizeMultiplier: Float = 0f
|
|
101
|
-
private var allowTrailingMargin: Boolean = false
|
|
102
|
-
private var imageRequestHeaders: Map<String, String> = emptyMap()
|
|
103
|
-
private var selectable: Boolean = true
|
|
104
|
-
private var contextMenuHidden: Boolean = false
|
|
105
|
-
private var selectionColor: Int? = null
|
|
106
|
-
private var selectionHandleColor: Int? = null
|
|
107
|
-
private var selectionMenuConfig = SelectionMenuConfig()
|
|
108
|
-
private var accessibilityLabels = AccessibilityLabels()
|
|
109
|
-
private var textBreakStrategy: String = BreakStrategyUtils.DEFAULT_STRATEGY
|
|
110
|
-
private var linkLayoutEnabled = false
|
|
111
|
-
private var lastLinkLayout: List<LinkLayoutFragment>? = null
|
|
112
|
-
|
|
113
|
-
// At most one segment holds a selection; a new one clears the previous.
|
|
114
|
-
private var selectionOwner: EnrichedMarkdownInternalText? = null
|
|
115
|
-
|
|
116
|
-
// A block long-pressed while contextMenuHidden is on, reported as the selection.
|
|
117
|
-
private class ActiveBlock(
|
|
118
|
-
val view: View,
|
|
119
|
-
val source: String,
|
|
120
|
-
val markdown: String,
|
|
121
|
-
val text: String,
|
|
122
|
-
)
|
|
53
|
+
class EnrichedMarkdown(
|
|
54
|
+
context: Context,
|
|
55
|
+
) : ContainerNodeView(context),
|
|
56
|
+
ImagePressHost {
|
|
57
|
+
private enum class DirtyFlag {
|
|
58
|
+
RECREATE_SEGMENTS,
|
|
59
|
+
FORCE_HEIGHT,
|
|
60
|
+
}
|
|
123
61
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
62
|
+
private val parser = Parser.shared
|
|
63
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
64
|
+
private val executor: ExecutorService = Executors.newSingleThreadExecutor()
|
|
65
|
+
private val mathContainerClass: Class<*>? by lazy { SegmentViewCreators.mathContainerClass() }
|
|
66
|
+
private val videoContainerClass: Class<*>? by lazy { SegmentViewCreators.videoContainerClass() }
|
|
67
|
+
|
|
68
|
+
private var currentRenderId = 0L
|
|
69
|
+
private val dirtyFlags = EnumSet.noneOf(DirtyFlag::class.java)
|
|
70
|
+
var streamingAnimation: Boolean = false
|
|
71
|
+
|
|
72
|
+
// used to force a Yoga re-measure when a block image resolves its box height
|
|
73
|
+
var stateWrapper: StateWrapper? = null
|
|
74
|
+
private var forceHeightRecalculationCounter = 0
|
|
75
|
+
|
|
76
|
+
var tableStreamingMode: TableStreamingMode = TableStreamingMode.PROGRESSIVE
|
|
77
|
+
var codeBlockStreamingMode: CodeBlockStreamingMode = CodeBlockStreamingMode.PROGRESSIVE
|
|
78
|
+
private var renderPending: Boolean = false
|
|
79
|
+
|
|
80
|
+
var currentMarkdown: String = ""
|
|
81
|
+
private set
|
|
82
|
+
|
|
83
|
+
var markdownStyle: StyleConfig? = null
|
|
84
|
+
private set
|
|
85
|
+
|
|
86
|
+
private var markdownStyleMap: ReadableMap? = null
|
|
87
|
+
private var lastKnownFontScale: Float = context.resources.configuration.fontScale
|
|
88
|
+
|
|
89
|
+
var md4cFlags: Md4cFlags = Md4cFlags.DEFAULT
|
|
90
|
+
private set
|
|
91
|
+
private var isGFM: Boolean = true
|
|
92
|
+
private var allowFontScaling: Boolean = true
|
|
93
|
+
private var maxFontSizeMultiplier: Float = 0f
|
|
94
|
+
private var imageRequestHeaders: Map<String, String> = emptyMap()
|
|
95
|
+
private var selectable: Boolean = true
|
|
96
|
+
private var selectionColor: Int? = null
|
|
97
|
+
private var selectionHandleColor: Int? = null
|
|
98
|
+
private var selectionMenuConfig = SelectionMenuConfig()
|
|
99
|
+
private var accessibilityLabels = AccessibilityLabels()
|
|
100
|
+
private var textBreakStrategy: String = BreakStrategyUtils.DEFAULT_STRATEGY
|
|
101
|
+
|
|
102
|
+
// --- Fork: contextMenuHidden, onSelectionChange, renderLinkDecoration (onLinkLayout). ---
|
|
103
|
+
// P1 of the v1.1.1 merge wires these to the root's own segments only; segments nested in
|
|
104
|
+
// a BlockquoteContainerView are not reached yet (P2 / A2 moves them into
|
|
105
|
+
// DynamicBlockProps/SegmentViewConfig and walks ContainerNodeView recursively).
|
|
106
|
+
private var contextMenuHidden: Boolean = false
|
|
107
|
+
private var linkLayoutEnabled = false
|
|
108
|
+
private var lastLinkLayout: List<LinkLayoutFragment>? = null
|
|
109
|
+
|
|
110
|
+
// At most one segment holds a selection; a new one clears the previous.
|
|
111
|
+
private var selectionOwner: EnrichedMarkdownInternalText? = null
|
|
112
|
+
|
|
113
|
+
// A block long-pressed while contextMenuHidden is on, reported as the selection.
|
|
114
|
+
private class ActiveBlock(
|
|
115
|
+
val view: View,
|
|
116
|
+
val source: String,
|
|
117
|
+
val markdown: String,
|
|
118
|
+
val text: String,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
private var activeBlock: ActiveBlock? = null
|
|
122
|
+
private val selectionReporter =
|
|
123
|
+
SelectionChangeReporter(this, ::selectionSnapshot) { snapshot -> emitSelectionChange(this, snapshot) }
|
|
124
|
+
|
|
125
|
+
private var onLinkPressCallback: ((String) -> Unit)? = null
|
|
126
|
+
private var onLinkLongPressCallback: ((String) -> Unit)? = null
|
|
127
|
+
private var onTaskListItemPressCallback: ((Int, Boolean, String) -> Unit)? = null
|
|
128
|
+
private var onLatexErrorCallback: LatexErrorReporter? = null
|
|
129
|
+
|
|
130
|
+
private val reportedLatexErrors = HashSet<String>()
|
|
131
|
+
|
|
132
|
+
private val latexErrorReporter =
|
|
133
|
+
LatexErrorReporter { source, message, displayMode ->
|
|
134
|
+
val key = (if (displayMode) "B " else "I ") + source
|
|
135
|
+
if (reportedLatexErrors.add(key)) {
|
|
136
|
+
onLatexErrorCallback?.report(source, message, displayMode)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
private var contextMenuItemTexts: List<String> = emptyList()
|
|
140
|
+
var onContextMenuItemPressCallback: ((itemText: String, selectedText: String, selectionStart: Int, selectionEnd: Int) -> Unit)? = null
|
|
141
|
+
var onCopyRequestCallback: ((source: String, markdown: String, text: String, whole: Boolean) -> Unit)? = null
|
|
142
|
+
var spoilerOverlay: SpoilerOverlay = SpoilerOverlay.PARTICLES
|
|
143
|
+
set(value) {
|
|
144
|
+
if (field == value) return
|
|
145
|
+
field = value
|
|
146
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
147
|
+
it.spoilerOverlay = value
|
|
142
148
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
}
|
|
150
|
+
var enableTaskListItemToggle: Boolean = true
|
|
151
|
+
set(value) {
|
|
152
|
+
if (field == value) return
|
|
153
|
+
field = value
|
|
154
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
155
|
+
it.enableTaskListItemToggle = value
|
|
150
156
|
}
|
|
151
|
-
|
|
152
|
-
fun setMarkdownContent(markdown: String) {
|
|
153
|
-
if (currentMarkdown == markdown) return
|
|
154
|
-
currentMarkdown = markdown
|
|
155
|
-
renderPending = true
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
markdownStyleMap = style
|
|
160
|
-
val newConfig = style?.let { StyleConfig(it, context, allowFontScaling, maxFontSizeMultiplier) }
|
|
161
|
-
newConfig?.imageRequestHeaders = imageRequestHeaders
|
|
162
|
-
if (markdownStyle == newConfig) return
|
|
163
|
-
markdownStyle = newConfig
|
|
164
|
-
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
165
|
-
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
166
|
-
renderPending = true
|
|
167
|
-
}
|
|
159
|
+
private val dynamicProps = DynamicBlockProps()
|
|
168
160
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
174
|
-
renderPending = true
|
|
161
|
+
var enableBlockContextMenu: Boolean
|
|
162
|
+
get() = dynamicProps.enableBlockContextMenu
|
|
163
|
+
set(value) {
|
|
164
|
+
dynamicProps.enableBlockContextMenu = value
|
|
175
165
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
MeasurementStore.updateFontScalingSettings(id, allowFontScaling, maxFontSizeMultiplier)
|
|
181
|
-
if (renderPending) {
|
|
182
|
-
renderPending = false
|
|
183
|
-
scheduleRenderIfNeeded()
|
|
184
|
-
}
|
|
166
|
+
var enableCodeBlockPress: Boolean
|
|
167
|
+
get() = dynamicProps.enableCodeBlockPress
|
|
168
|
+
set(value) {
|
|
169
|
+
dynamicProps.enableCodeBlockPress = value
|
|
185
170
|
}
|
|
186
171
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
val newFontScale = newConfig.fontScale
|
|
191
|
-
if (newFontScale != lastKnownFontScale) {
|
|
192
|
-
lastKnownFontScale = newFontScale
|
|
193
|
-
recreateStyleConfig()
|
|
194
|
-
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
195
|
-
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
196
|
-
scheduleRenderIfNeeded()
|
|
197
|
-
}
|
|
198
|
-
}
|
|
172
|
+
init {
|
|
173
|
+
segmentViewFactory = RootFactory()
|
|
174
|
+
}
|
|
199
175
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
176
|
+
fun setMarkdownContent(markdown: String) {
|
|
177
|
+
if (currentMarkdown == markdown) return
|
|
178
|
+
currentMarkdown = markdown
|
|
179
|
+
renderPending = true
|
|
180
|
+
}
|
|
205
181
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
182
|
+
fun setMarkdownStyle(style: ReadableMap?) {
|
|
183
|
+
markdownStyleMap = style
|
|
184
|
+
val newConfig = style?.let { StyleConfig(it, context, allowFontScaling, maxFontSizeMultiplier) }
|
|
185
|
+
newConfig?.imageRequestHeaders = imageRequestHeaders
|
|
186
|
+
if (markdownStyle == newConfig) return
|
|
187
|
+
markdownStyle = newConfig
|
|
188
|
+
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
189
|
+
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
190
|
+
renderPending = true
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fun setImageRequestHeaders(headers: Map<String, String>) {
|
|
194
|
+
if (imageRequestHeaders == headers) return
|
|
195
|
+
imageRequestHeaders = headers
|
|
196
|
+
markdownStyle?.imageRequestHeaders = headers
|
|
197
|
+
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
198
|
+
renderPending = true
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
fun commitProps() {
|
|
202
|
+
MeasurementStore.updateStreamingTableMode(id, tableStreamingMode)
|
|
203
|
+
MeasurementStore.updateStreamingCodeBlockMode(id, codeBlockStreamingMode)
|
|
204
|
+
MeasurementStore.updateFontScalingSettings(id, allowFontScaling, maxFontSizeMultiplier)
|
|
205
|
+
if (renderPending) {
|
|
206
|
+
renderPending = false
|
|
207
|
+
scheduleRenderIfNeeded()
|
|
214
208
|
}
|
|
209
|
+
}
|
|
215
210
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
212
|
+
super.onConfigurationChanged(newConfig)
|
|
213
|
+
if (!allowFontScaling) return
|
|
214
|
+
val newFontScale = newConfig.fontScale
|
|
215
|
+
if (newFontScale != lastKnownFontScale) {
|
|
216
|
+
lastKnownFontScale = newFontScale
|
|
220
217
|
recreateStyleConfig()
|
|
221
218
|
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
222
219
|
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
223
|
-
|
|
220
|
+
scheduleRenderIfNeeded()
|
|
224
221
|
}
|
|
222
|
+
}
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
renderPending = true
|
|
232
|
-
}
|
|
224
|
+
fun setMd4cFlags(flags: Md4cFlags) {
|
|
225
|
+
if (md4cFlags == flags) return
|
|
226
|
+
md4cFlags = flags
|
|
227
|
+
renderPending = true
|
|
228
|
+
}
|
|
233
229
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
}
|
|
230
|
+
fun setIsGFM(value: Boolean) {
|
|
231
|
+
if (isGFM == value) return
|
|
232
|
+
isGFM = value
|
|
233
|
+
renderPending = true
|
|
234
|
+
}
|
|
241
235
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
fun setAllowFontScaling(allow: Boolean) {
|
|
237
|
+
if (allowFontScaling == allow) return
|
|
238
|
+
allowFontScaling = allow
|
|
239
|
+
MeasurementStore.updateFontScalingSettings(id, allowFontScaling, maxFontSizeMultiplier)
|
|
240
|
+
recreateStyleConfig()
|
|
241
|
+
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
242
|
+
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
243
|
+
renderPending = true
|
|
244
|
+
}
|
|
247
245
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
view is TableContainerView -> view.contextMenuHidden = contextMenuHidden
|
|
258
|
-
view is CodeBlockContainerView -> view.contextMenuHidden = contextMenuHidden
|
|
259
|
-
isMathContainerView(view) -> setMathContextMenuHidden(view)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
246
|
+
fun setMaxFontSizeMultiplier(multiplier: Float) {
|
|
247
|
+
if (maxFontSizeMultiplier == multiplier) return
|
|
248
|
+
maxFontSizeMultiplier = multiplier
|
|
249
|
+
MeasurementStore.updateFontScalingSettings(id, allowFontScaling, maxFontSizeMultiplier)
|
|
250
|
+
recreateStyleConfig()
|
|
251
|
+
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
252
|
+
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
253
|
+
renderPending = true
|
|
254
|
+
}
|
|
263
255
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
runCatching {
|
|
272
|
-
view.javaClass
|
|
273
|
-
.getMethod("setContextMenuHidden", Boolean::class.javaPrimitiveType)
|
|
274
|
-
.invoke(view, contextMenuHidden)
|
|
275
|
-
}.onFailure { Log.e(TAG, "Failed to set contextMenuHidden on math view", it) }
|
|
276
|
-
}
|
|
256
|
+
fun setAllowTrailingMargin(allow: Boolean) {
|
|
257
|
+
if (trailingMarginEnabled == allow) return
|
|
258
|
+
trailingMarginEnabled = allow
|
|
259
|
+
dirtyFlags += DirtyFlag.RECREATE_SEGMENTS
|
|
260
|
+
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
261
|
+
renderPending = true
|
|
262
|
+
}
|
|
277
263
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
264
|
+
fun setIsSelectable(value: Boolean) {
|
|
265
|
+
if (selectable == value) return
|
|
266
|
+
selectable = value
|
|
267
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
268
|
+
it.setIsSelectable(value)
|
|
282
269
|
}
|
|
270
|
+
}
|
|
283
271
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
272
|
+
fun setContextMenuHidden(value: Boolean) {
|
|
273
|
+
if (contextMenuHidden == value) return
|
|
274
|
+
contextMenuHidden = value
|
|
275
|
+
applyContextMenuHiddenToSegments()
|
|
276
|
+
}
|
|
289
277
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Fans the flag out to every segment that owns a copy menu: text segments
|
|
280
|
+
* (floating ActionMode toolbar), tables, code blocks and math blocks (all use
|
|
281
|
+
* their own long-press popup, so none is covered by the ActionMode callback).
|
|
282
|
+
*/
|
|
283
|
+
private fun applyContextMenuHiddenToSegments() {
|
|
284
|
+
segmentViews.forEach { view ->
|
|
285
|
+
when {
|
|
286
|
+
view is EnrichedMarkdownInternalText -> view.contextMenuHidden = contextMenuHidden
|
|
287
|
+
view is TableContainerView -> view.contextMenuHidden = contextMenuHidden
|
|
288
|
+
view is CodeBlockContainerView -> view.contextMenuHidden = contextMenuHidden
|
|
289
|
+
isMathContainerView(view) -> setMathContextMenuHidden(view)
|
|
299
290
|
}
|
|
300
|
-
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
301
|
-
renderPending = true
|
|
302
291
|
}
|
|
292
|
+
}
|
|
303
293
|
|
|
304
|
-
|
|
294
|
+
/**
|
|
295
|
+
* MathContainerView lives in the optional `math` source set, so it is only
|
|
296
|
+
* reachable reflectively. The Kotlin `var` compiles to a setter taking a
|
|
297
|
+
* primitive boolean — `Boolean::class.java` would resolve to
|
|
298
|
+
* `java.lang.Boolean` and silently miss.
|
|
299
|
+
*/
|
|
300
|
+
private fun setMathContextMenuHidden(view: View) {
|
|
301
|
+
runCatching {
|
|
302
|
+
view.javaClass
|
|
303
|
+
.getMethod("setContextMenuHidden", Boolean::class.javaPrimitiveType)
|
|
304
|
+
.invoke(view, contextMenuHidden)
|
|
305
|
+
}.onFailure { Log.e(TAG, "Failed to set contextMenuHidden on math view", it) }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
fun setSelectionColor(color: Int?) {
|
|
309
|
+
if (selectionColor == color) return
|
|
310
|
+
selectionColor = color
|
|
311
|
+
applySelectionColorsToSegments()
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
fun setSelectionHandleColor(color: Int?) {
|
|
315
|
+
if (selectionHandleColor == color) return
|
|
316
|
+
selectionHandleColor = color
|
|
317
|
+
applySelectionColorsToSegments()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
fun setTextBreakStrategy(strategy: String) {
|
|
321
|
+
if (textBreakStrategy == strategy) return
|
|
322
|
+
textBreakStrategy = strategy
|
|
323
|
+
MeasurementStore.updateBreakStrategy(id, strategy)
|
|
324
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
325
|
+
val resolved = BreakStrategyUtils.resolveBreakStrategy(strategy)
|
|
305
326
|
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
306
|
-
it.
|
|
327
|
+
it.breakStrategy = resolved
|
|
307
328
|
}
|
|
308
329
|
}
|
|
330
|
+
dirtyFlags += DirtyFlag.FORCE_HEIGHT
|
|
331
|
+
renderPending = true
|
|
332
|
+
}
|
|
309
333
|
|
|
310
|
-
|
|
311
|
-
|
|
334
|
+
private fun applySelectionColorsToSegments() {
|
|
335
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
336
|
+
it.applySelectionColors(selectionColor, selectionHandleColor)
|
|
312
337
|
}
|
|
338
|
+
}
|
|
313
339
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
340
|
+
fun setOnLinkPressCallback(callback: (String) -> Unit) {
|
|
341
|
+
onLinkPressCallback = callback
|
|
342
|
+
}
|
|
317
343
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
344
|
+
fun setOnLinkLongPressCallback(callback: (String) -> Unit) {
|
|
345
|
+
onLinkLongPressCallback = callback
|
|
346
|
+
}
|
|
321
347
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
348
|
+
fun setOnLatexErrorCallback(callback: LatexErrorReporter) {
|
|
349
|
+
onLatexErrorCallback = callback
|
|
350
|
+
}
|
|
325
351
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
352
|
+
override var imagePressEnabled: Boolean = false
|
|
353
|
+
private set
|
|
354
|
+
|
|
355
|
+
override fun emitOnImagePress(
|
|
356
|
+
url: String,
|
|
357
|
+
altText: String,
|
|
358
|
+
) {
|
|
359
|
+
emitImagePressEvent(url, altText)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
fun setEnableImagePress(enabled: Boolean) {
|
|
363
|
+
imagePressEnabled = enabled
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
fun setOnTaskListItemPressCallback(callback: ((taskIndex: Int, checked: Boolean, itemText: String) -> Unit)?) {
|
|
367
|
+
onTaskListItemPressCallback = callback
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
fun setOnCopyPressCallback(callback: ((code: String, language: String) -> Unit)?) {
|
|
371
|
+
dynamicProps.onCopyPress = callback
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
fun setOnCodeBlockPressCallback(callback: ((code: String, language: String) -> Unit)?) {
|
|
375
|
+
dynamicProps.onCodeBlockPress = callback
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
fun setContextMenuItems(items: List<String>) {
|
|
379
|
+
contextMenuItemTexts = items
|
|
380
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
381
|
+
it.setContextMenuItems(items, ::forwardContextMenuItemPress)
|
|
331
382
|
}
|
|
383
|
+
}
|
|
332
384
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
385
|
+
fun setSelectionMenuConfig(config: SelectionMenuConfig) {
|
|
386
|
+
if (selectionMenuConfig == config) return
|
|
387
|
+
selectionMenuConfig = config
|
|
388
|
+
dynamicProps.copyLabel = config.copyLabel
|
|
389
|
+
dynamicProps.copyAsMarkdownLabel = config.copyAsMarkdownLabel
|
|
390
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
391
|
+
it.selectionMenuConfig = config
|
|
392
|
+
}
|
|
393
|
+
// Labels are read live from dynamicProps; the per-item menu options (and the code
|
|
394
|
+
// block header copy button visibility) are still pushed to each block view.
|
|
395
|
+
pushMenuOptionsToBlockSegments()
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private fun pushMenuOptionsToBlockSegments() {
|
|
399
|
+
segmentViews.forEach { view ->
|
|
400
|
+
when {
|
|
401
|
+
view is TableContainerView -> view.menuOptions = blockMenuOptions("table")
|
|
402
|
+
view is CodeBlockContainerView -> view.menuOptions = blockMenuOptions("code")
|
|
403
|
+
isMathContainerView(view) -> setMathMenuOptions(view)
|
|
338
404
|
}
|
|
339
|
-
// Block views cache the copy labels and menu options, so re-push them on
|
|
340
|
-
// update (e.g. a language change without a remount) to avoid stale values.
|
|
341
|
-
pushCopyLabelsToBlockSegments()
|
|
342
405
|
}
|
|
406
|
+
}
|
|
343
407
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
view.copyAsMarkdownLabel = copyAsMarkdownLabel
|
|
352
|
-
view.menuOptions = blockMenuOptions("table")
|
|
353
|
-
}
|
|
408
|
+
private fun setMathMenuOptions(view: View) {
|
|
409
|
+
runCatching {
|
|
410
|
+
view.javaClass
|
|
411
|
+
.getMethod("setMenuOptions", BlockMenuOptions::class.java)
|
|
412
|
+
.invoke(view, blockMenuOptions("math"))
|
|
413
|
+
}.onFailure { Log.e(TAG, "Failed to set menuOptions on math view", it) }
|
|
414
|
+
}
|
|
354
415
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
416
|
+
/** Wires the fork's menu hooks into a freshly created (reflective) math block view. */
|
|
417
|
+
private fun configureMathView(view: View) {
|
|
418
|
+
if (!isMathContainerView(view)) return
|
|
419
|
+
setMathMenuOptions(view)
|
|
420
|
+
setMathContextMenuHidden(view)
|
|
421
|
+
val onMenuSuppressed: (String, String) -> Unit = { markdown, text ->
|
|
422
|
+
onBlockMenuSuppressed(view, "math", markdown, text)
|
|
423
|
+
}
|
|
424
|
+
runCatching {
|
|
425
|
+
view.javaClass.getMethod("setOnMenuSuppressed", Function2::class.java).invoke(view, onMenuSuppressed)
|
|
426
|
+
}.onFailure { Log.e(TAG, "Failed to set onMenuSuppressed on math view", it) }
|
|
427
|
+
}
|
|
360
428
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
.invoke(view, copyAsMarkdownLabel)
|
|
367
|
-
view.javaClass
|
|
368
|
-
.getMethod("setMenuOptions", BlockMenuOptions::class.java)
|
|
369
|
-
.invoke(view, blockMenuOptions("math"))
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
429
|
+
fun setAccessibilityLabels(labels: AccessibilityLabels) {
|
|
430
|
+
if (accessibilityLabels == labels) return
|
|
431
|
+
accessibilityLabels = labels
|
|
432
|
+
segmentViews.filterIsInstance<EnrichedMarkdownInternalText>().forEach {
|
|
433
|
+
it.accessibilityLabels = labels
|
|
374
434
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
segmentViews.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
mathContainerClass?.let { mathClass ->
|
|
386
|
-
segmentViews.filter { mathClass.isInstance(it) }.forEach { view ->
|
|
387
|
-
runCatching {
|
|
388
|
-
mathClass
|
|
389
|
-
.getMethod("setAccessibilityLabels", AccessibilityLabels::class.java)
|
|
390
|
-
.invoke(view, labels)
|
|
391
|
-
}
|
|
435
|
+
segmentViews.filterIsInstance<TableContainerView>().forEach {
|
|
436
|
+
it.accessibilityLabels = labels
|
|
437
|
+
}
|
|
438
|
+
mathContainerClass?.let { mathClass ->
|
|
439
|
+
segmentViews.filter { mathClass.isInstance(it) }.forEach { view ->
|
|
440
|
+
runCatching {
|
|
441
|
+
mathClass
|
|
442
|
+
.getMethod("setAccessibilityLabels", AccessibilityLabels::class.java)
|
|
443
|
+
.invoke(view, labels)
|
|
392
444
|
}
|
|
393
445
|
}
|
|
394
446
|
}
|
|
447
|
+
}
|
|
395
448
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
449
|
+
private fun forwardContextMenuItemPress(
|
|
450
|
+
itemText: String,
|
|
451
|
+
selectedText: String,
|
|
452
|
+
selectionStart: Int,
|
|
453
|
+
selectionEnd: Int,
|
|
454
|
+
) {
|
|
455
|
+
onContextMenuItemPressCallback?.invoke(itemText, selectedText, selectionStart, selectionEnd)
|
|
456
|
+
}
|
|
400
457
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
markdown: String,
|
|
405
|
-
text: String,
|
|
406
|
-
fullSelection: Boolean,
|
|
407
|
-
) {
|
|
408
|
-
val whole = fullSelection && segmentViews.size == 1 && currentMarkdown.isNotEmpty()
|
|
409
|
-
onCopyRequestCallback?.invoke("selection", if (whole) currentMarkdown else markdown, text, whole)
|
|
458
|
+
private fun blockMenuOptions(source: String) =
|
|
459
|
+
BlockMenuOptions.from(selectionMenuConfig) { markdown, text ->
|
|
460
|
+
onCopyRequestCallback?.invoke(source, markdown, text, true)
|
|
410
461
|
}
|
|
411
462
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
463
|
+
// Segments only see their own text, so a selection is the whole component
|
|
464
|
+
// only when it spans the sole segment; the markdown is then the original.
|
|
465
|
+
private fun forwardSegmentCopyRequest(
|
|
466
|
+
markdown: String,
|
|
467
|
+
text: String,
|
|
468
|
+
fullSelection: Boolean,
|
|
469
|
+
) {
|
|
470
|
+
val whole = fullSelection && segmentViews.size == 1 && currentMarkdown.isNotEmpty()
|
|
471
|
+
onCopyRequestCallback?.invoke("selection", if (whole) currentMarkdown else markdown, text, whole)
|
|
472
|
+
}
|
|
420
473
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
474
|
+
fun setEmitSelectionChange(enabled: Boolean) {
|
|
475
|
+
selectionReporter.enabled = enabled
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Clears the selection of every segment (and any active block) and reports `active: false`. */
|
|
479
|
+
fun clearSelection() {
|
|
480
|
+
val owner = selectionOwner
|
|
481
|
+
selectionOwner = null
|
|
482
|
+
activeBlock = null
|
|
483
|
+
owner?.clearSelection()
|
|
484
|
+
selectionReporter.flushNow()
|
|
485
|
+
}
|
|
424
486
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
487
|
+
private fun onSegmentSelectionChanged(
|
|
488
|
+
view: EnrichedMarkdownInternalText,
|
|
489
|
+
hasSelection: Boolean,
|
|
490
|
+
) {
|
|
491
|
+
if (hasSelection) {
|
|
492
|
+
// Take ownership first so the previous owner's own "cleared" callback is ignored.
|
|
493
|
+
val previous = selectionOwner
|
|
494
|
+
selectionOwner = view
|
|
429
495
|
activeBlock = null
|
|
430
|
-
|
|
431
|
-
selectionReporter.
|
|
496
|
+
if (previous !== view) previous?.clearSelection()
|
|
497
|
+
selectionReporter.schedule()
|
|
498
|
+
} else if (selectionOwner === view) {
|
|
499
|
+
selectionReporter.onSelectionChanged(false)
|
|
432
500
|
}
|
|
501
|
+
}
|
|
433
502
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
503
|
+
private fun onBlockMenuSuppressed(
|
|
504
|
+
view: View,
|
|
505
|
+
source: String,
|
|
506
|
+
markdown: String,
|
|
507
|
+
text: String,
|
|
508
|
+
) {
|
|
509
|
+
if (!selectionReporter.enabled) return
|
|
510
|
+
val previous = selectionOwner
|
|
511
|
+
selectionOwner = null
|
|
512
|
+
previous?.clearSelection()
|
|
513
|
+
activeBlock = ActiveBlock(view, source, markdown, text)
|
|
514
|
+
selectionReporter.forgetLastReported()
|
|
515
|
+
selectionReporter.flushNow()
|
|
516
|
+
}
|
|
449
517
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
518
|
+
private fun selectionSnapshot(): SelectionSnapshot {
|
|
519
|
+
activeBlock?.let { block ->
|
|
520
|
+
if (block.view.parent !== this) return SelectionSnapshot.INACTIVE
|
|
521
|
+
val rect =
|
|
522
|
+
SelectionRect.fromPx(
|
|
523
|
+
block.view.left.toFloat(),
|
|
524
|
+
block.view.top.toFloat(),
|
|
525
|
+
block.view.right.toFloat(),
|
|
526
|
+
block.view.bottom.toFloat(),
|
|
527
|
+
)
|
|
528
|
+
return SelectionSnapshot.block(block.source, block.markdown, block.text, rect)
|
|
529
|
+
}
|
|
530
|
+
val owner = selectionOwner?.takeIf { it.parent === this } ?: return SelectionSnapshot.INACTIVE
|
|
531
|
+
val selection = owner.currentTextSelection(owner.left, owner.top) ?: return SelectionSnapshot.INACTIVE
|
|
532
|
+
// Same rule as forwardSegmentCopyRequest.
|
|
533
|
+
val whole = selection.fullSelection && segmentViews.size == 1 && currentMarkdown.isNotEmpty()
|
|
534
|
+
return SelectionSnapshot(
|
|
535
|
+
active = true,
|
|
536
|
+
source = "selection",
|
|
537
|
+
text = selection.text,
|
|
538
|
+
markdown = if (whole) currentMarkdown else selection.markdown,
|
|
539
|
+
whole = whole,
|
|
540
|
+
rect = selection.rect,
|
|
541
|
+
startRect = selection.startRect,
|
|
542
|
+
endRect = selection.endRect,
|
|
543
|
+
)
|
|
544
|
+
}
|
|
464
545
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
block.view.top.toFloat(),
|
|
472
|
-
block.view.right.toFloat(),
|
|
473
|
-
block.view.bottom.toFloat(),
|
|
474
|
-
)
|
|
475
|
-
return SelectionSnapshot.block(block.source, block.markdown, block.text, rect)
|
|
476
|
-
}
|
|
477
|
-
val owner = selectionOwner?.takeIf { it.parent === this } ?: return SelectionSnapshot.INACTIVE
|
|
478
|
-
val selection = owner.currentTextSelection(owner.left, owner.top) ?: return SelectionSnapshot.INACTIVE
|
|
479
|
-
// Same rule as forwardSegmentCopyRequest.
|
|
480
|
-
val whole = selection.fullSelection && segmentViews.size == 1 && currentMarkdown.isNotEmpty()
|
|
481
|
-
return SelectionSnapshot(
|
|
482
|
-
active = true,
|
|
483
|
-
source = "selection",
|
|
484
|
-
text = selection.text,
|
|
485
|
-
markdown = if (whole) currentMarkdown else selection.markdown,
|
|
486
|
-
whole = whole,
|
|
487
|
-
rect = selection.rect,
|
|
488
|
-
startRect = selection.startRect,
|
|
489
|
-
endRect = selection.endRect,
|
|
490
|
-
)
|
|
546
|
+
private fun recreateStyleConfig() {
|
|
547
|
+
markdownStyleMap?.let {
|
|
548
|
+
markdownStyle =
|
|
549
|
+
StyleConfig(it, context, allowFontScaling, maxFontSizeMultiplier).also { config ->
|
|
550
|
+
config.imageRequestHeaders = imageRequestHeaders
|
|
551
|
+
}
|
|
491
552
|
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private fun scheduleRenderIfNeeded() {
|
|
556
|
+
if (currentMarkdown.isNotEmpty()) scheduleRender()
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
private fun scheduleRender() {
|
|
560
|
+
val style = markdownStyle ?: return
|
|
561
|
+
val markdown = currentMarkdown.takeIf { it.isNotEmpty() } ?: return
|
|
562
|
+
val isStreaming = streamingAnimation
|
|
563
|
+
val tableMode = tableStreamingMode
|
|
564
|
+
val codeBlockMode = codeBlockStreamingMode
|
|
492
565
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
566
|
+
val renderId = ++currentRenderId
|
|
567
|
+
|
|
568
|
+
executor.execute {
|
|
569
|
+
try {
|
|
570
|
+
val filtered =
|
|
571
|
+
if (isStreaming) {
|
|
572
|
+
StreamingMarkdownFilter.renderableMarkdownForStreaming(markdown, tableMode, codeBlockMode)
|
|
573
|
+
} else {
|
|
574
|
+
null
|
|
498
575
|
}
|
|
499
|
-
|
|
500
|
-
|
|
576
|
+
val renderableMarkdown = filtered?.markdown ?: markdown
|
|
577
|
+
val hasPendingCodeBlock = filtered?.endsInsideOpenCodeFence ?: false
|
|
501
578
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
579
|
+
if (renderableMarkdown.isEmpty()) {
|
|
580
|
+
postToMain(renderId) { applyRenderedSegments(emptyList(), false) }
|
|
581
|
+
return@execute
|
|
582
|
+
}
|
|
505
583
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
val isStreaming = streamingAnimation
|
|
510
|
-
val tableMode = tableStreamingMode
|
|
511
|
-
val codeBlockMode = codeBlockStreamingMode
|
|
512
|
-
|
|
513
|
-
val renderId = ++currentRenderId
|
|
514
|
-
|
|
515
|
-
executor.execute {
|
|
516
|
-
try {
|
|
517
|
-
val filtered =
|
|
518
|
-
if (isStreaming) {
|
|
519
|
-
StreamingMarkdownFilter.renderableMarkdownForStreaming(markdown, tableMode, codeBlockMode)
|
|
520
|
-
} else {
|
|
521
|
-
null
|
|
522
|
-
}
|
|
523
|
-
val renderableMarkdown = filtered?.markdown ?: markdown
|
|
524
|
-
val hasPendingCodeBlock = filtered?.endsInsideOpenCodeFence ?: false
|
|
525
|
-
|
|
526
|
-
if (renderableMarkdown.isEmpty()) {
|
|
527
|
-
postToMain(renderId) { applyRenderedSegments(emptyList(), style, false) }
|
|
584
|
+
val ast =
|
|
585
|
+
parser.parseMarkdown(renderableMarkdown, md4cFlags, isGFM) ?: run {
|
|
586
|
+
postToMain(renderId) { applyRenderedSegments(emptyList(), false) }
|
|
528
587
|
return@execute
|
|
529
588
|
}
|
|
530
589
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
postToMain(renderId) { applyRenderedSegments(renderedSegments, style, hasPendingCodeBlock) }
|
|
548
|
-
} catch (e: Exception) {
|
|
549
|
-
Log.e(TAG, "Render failed", e)
|
|
550
|
-
postToMain(renderId) { applyRenderedSegments(emptyList(), style, false) }
|
|
551
|
-
}
|
|
590
|
+
val segments = splitASTIntoSegments(ast)
|
|
591
|
+
val renderedSegments =
|
|
592
|
+
MarkdownSegmentRenderer.render(
|
|
593
|
+
segments,
|
|
594
|
+
style,
|
|
595
|
+
context,
|
|
596
|
+
onLinkPressCallback,
|
|
597
|
+
onLinkLongPressCallback,
|
|
598
|
+
onLatexError = latexErrorReporter,
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
postToMain(renderId) { applyRenderedSegments(renderedSegments, hasPendingCodeBlock) }
|
|
602
|
+
} catch (e: Exception) {
|
|
603
|
+
Log.e(TAG, "Render failed", e)
|
|
604
|
+
postToMain(renderId) { applyRenderedSegments(emptyList(), false) }
|
|
552
605
|
}
|
|
553
606
|
}
|
|
607
|
+
}
|
|
554
608
|
|
|
555
|
-
|
|
556
|
-
|
|
609
|
+
// Trailing code block whose closing fence hasn't streamed in yet, if any.
|
|
610
|
+
private var pendingCodeBlockSegment: RenderedSegment.CodeBlock? = null
|
|
557
611
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
if (hasPendingCodeBlock) renderedSegments.lastOrNull() as? RenderedSegment.CodeBlock else null
|
|
565
|
-
|
|
566
|
-
val reset = DirtyFlag.RECREATE_SEGMENTS in dirtyFlags
|
|
567
|
-
val forceHeight = DirtyFlag.FORCE_HEIGHT in dirtyFlags
|
|
568
|
-
dirtyFlags.clear()
|
|
569
|
-
|
|
570
|
-
val result =
|
|
571
|
-
SegmentReconciler.reconcile(
|
|
572
|
-
currentViews = segmentViews.toList(),
|
|
573
|
-
currentSignatures = segmentSignatures.toList(),
|
|
574
|
-
renderedSegments = renderedSegments,
|
|
575
|
-
reset = reset,
|
|
576
|
-
matchesKind = ::viewMatchesSegmentKind,
|
|
577
|
-
createView = { segment ->
|
|
578
|
-
val view = createSegmentView(segment, style)
|
|
579
|
-
animateNewView(view, segment)
|
|
580
|
-
view
|
|
581
|
-
},
|
|
582
|
-
updateView = { view, segment -> updateSegmentView(view, segment) },
|
|
583
|
-
)
|
|
612
|
+
private fun applyRenderedSegments(
|
|
613
|
+
renderedSegments: List<RenderedSegment>,
|
|
614
|
+
hasPendingCodeBlock: Boolean,
|
|
615
|
+
) {
|
|
616
|
+
pendingCodeBlockSegment =
|
|
617
|
+
if (hasPendingCodeBlock) renderedSegments.lastOrNull() as? RenderedSegment.CodeBlock else null
|
|
584
618
|
|
|
585
|
-
|
|
586
|
-
|
|
619
|
+
val reset = DirtyFlag.RECREATE_SEGMENTS in dirtyFlags
|
|
620
|
+
val forceHeight = DirtyFlag.FORCE_HEIGHT in dirtyFlags
|
|
621
|
+
dirtyFlags.clear()
|
|
587
622
|
|
|
588
|
-
|
|
589
|
-
segmentViews.addAll(result.views)
|
|
590
|
-
segmentSignatures.clear()
|
|
591
|
-
segmentSignatures.addAll(result.signatures)
|
|
623
|
+
val topologyChanged = applySegments(renderedSegments, reset)
|
|
592
624
|
|
|
593
|
-
|
|
594
|
-
|
|
625
|
+
if (selectionOwner?.let { owner -> segmentViews.none { it === owner } } == true) selectionOwner = null
|
|
626
|
+
if (activeBlock?.let { block -> segmentViews.none { it === block.view } } == true) activeBlock = null
|
|
595
627
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
628
|
+
// A just-closed block has unchanged content, so the reconciler reuses it
|
|
629
|
+
// without an update; sync pending here to trigger its deferred highlight.
|
|
630
|
+
segmentViews.forEachIndexed { index, view ->
|
|
631
|
+
if (view is CodeBlockContainerView) {
|
|
632
|
+
view.pending = pendingCodeBlockSegment != null && index == segmentViews.size - 1
|
|
602
633
|
}
|
|
634
|
+
}
|
|
603
635
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
layoutSegments()
|
|
609
|
-
val heightAfter = computeSegmentsTotalHeight()
|
|
636
|
+
if (width > 0) {
|
|
637
|
+
val heightBefore = computeSegmentsTotalHeight()
|
|
638
|
+
layoutSegmentsAndReport()
|
|
639
|
+
val heightAfter = computeSegmentsTotalHeight()
|
|
610
640
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
641
|
+
if (forceHeight || topologyChanged || heightBefore != heightAfter) {
|
|
642
|
+
MeasurementStore.invalidate(id)
|
|
643
|
+
requestLayout()
|
|
615
644
|
}
|
|
616
645
|
}
|
|
646
|
+
}
|
|
617
647
|
|
|
618
|
-
|
|
648
|
+
private fun isMathContainerView(view: View): Boolean = mathContainerClass?.isInstance(view) == true
|
|
649
|
+
|
|
650
|
+
private fun isVideoContainerView(view: View): Boolean = videoContainerClass?.isInstance(view) == true
|
|
651
|
+
|
|
652
|
+
private fun segmentViewConfig(): SegmentViewConfig =
|
|
653
|
+
SegmentViewConfig(
|
|
654
|
+
context = context,
|
|
655
|
+
style = markdownStyle!!,
|
|
656
|
+
allowFontScaling = allowFontScaling,
|
|
657
|
+
maxFontSizeMultiplier = maxFontSizeMultiplier,
|
|
658
|
+
accessibilityLabels = accessibilityLabels,
|
|
659
|
+
selectionMenuConfig = selectionMenuConfig,
|
|
660
|
+
textBreakStrategy = textBreakStrategy,
|
|
661
|
+
selectable = selectable,
|
|
662
|
+
selectionColor = selectionColor,
|
|
663
|
+
selectionHandleColor = selectionHandleColor,
|
|
664
|
+
contextMenuItemTexts = contextMenuItemTexts,
|
|
665
|
+
dynamicProps = dynamicProps,
|
|
666
|
+
onLinkPress = onLinkPressCallback,
|
|
667
|
+
onLinkLongPress = onLinkLongPressCallback,
|
|
668
|
+
onTaskListItemPress = onTaskListItemPressCallback,
|
|
669
|
+
onContextMenuItemPress = ::forwardContextMenuItemPress,
|
|
670
|
+
onLatexError = latexErrorReporter,
|
|
671
|
+
)
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Root factory: builds child views through the shared creators, then layers on
|
|
675
|
+
* root-only concerns (spoiler overlay mode, task-list toggle, streaming tail /
|
|
676
|
+
* fade-in animation, and the pending code block sync for the open trailing
|
|
677
|
+
* fence).
|
|
678
|
+
*/
|
|
679
|
+
private inner class RootFactory : SegmentViewFactory {
|
|
680
|
+
override fun matchesKind(
|
|
619
681
|
view: View,
|
|
620
682
|
segment: RenderedSegment,
|
|
621
683
|
): Boolean =
|
|
@@ -624,22 +686,55 @@ class EnrichedMarkdown
|
|
|
624
686
|
is RenderedSegment.Table -> view is TableContainerView
|
|
625
687
|
is RenderedSegment.Math -> isMathContainerView(view)
|
|
626
688
|
is RenderedSegment.CodeBlock -> view is CodeBlockContainerView
|
|
689
|
+
is RenderedSegment.Blockquote -> view is BlockquoteContainerView
|
|
690
|
+
is RenderedSegment.Video -> isVideoContainerView(view)
|
|
627
691
|
}
|
|
628
692
|
|
|
629
|
-
|
|
693
|
+
override fun createView(segment: RenderedSegment): View {
|
|
694
|
+
val config = segmentViewConfig()
|
|
695
|
+
return when (segment) {
|
|
696
|
+
is RenderedSegment.Text -> {
|
|
697
|
+
SegmentViewCreators.createTextView(segment, config).apply {
|
|
698
|
+
spoilerOverlay = this@EnrichedMarkdown.spoilerOverlay
|
|
699
|
+
enableTaskListItemToggle = this@EnrichedMarkdown.enableTaskListItemToggle
|
|
700
|
+
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
701
|
+
onCopyRequest = this@EnrichedMarkdown::forwardSegmentCopyRequest
|
|
702
|
+
onSelectionChangedCallback = this@EnrichedMarkdown::onSegmentSelectionChanged
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
is RenderedSegment.Table -> {
|
|
707
|
+
SegmentViewCreators.createTableView(segment, config).apply {
|
|
708
|
+
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
709
|
+
menuOptions = blockMenuOptions("table")
|
|
710
|
+
onMenuSuppressed = { markdown, text -> onBlockMenuSuppressed(this, "table", markdown, text) }
|
|
711
|
+
}
|
|
712
|
+
}
|
|
630
713
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
714
|
+
is RenderedSegment.Math -> {
|
|
715
|
+
SegmentViewCreators.createMathView(segment, config).also(this@EnrichedMarkdown::configureMathView)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
is RenderedSegment.CodeBlock -> {
|
|
719
|
+
SegmentViewCreators.createCodeBlockView(segment, config).apply {
|
|
720
|
+
pending = segment === pendingCodeBlockSegment
|
|
721
|
+
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
722
|
+
menuOptions = blockMenuOptions("code")
|
|
723
|
+
onMenuSuppressed = { markdown, text -> onBlockMenuSuppressed(this, "code", markdown, text) }
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
is RenderedSegment.Blockquote -> {
|
|
728
|
+
SegmentViewCreators.createBlockquoteView(segment, config)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
is RenderedSegment.Video -> {
|
|
732
|
+
SegmentViewCreators.createVideoView(segment, config)
|
|
733
|
+
}
|
|
640
734
|
}
|
|
735
|
+
}
|
|
641
736
|
|
|
642
|
-
|
|
737
|
+
override fun updateView(
|
|
643
738
|
view: View,
|
|
644
739
|
segment: RenderedSegment,
|
|
645
740
|
) {
|
|
@@ -647,9 +742,7 @@ class EnrichedMarkdown
|
|
|
647
742
|
is RenderedSegment.Text -> {
|
|
648
743
|
val textView = view as EnrichedMarkdownInternalText
|
|
649
744
|
val tailStart = textView.text?.length ?: 0
|
|
650
|
-
textView
|
|
651
|
-
textView.applyStyledText(segment.styledText)
|
|
652
|
-
segment.imageSpans.forEach { it.registerTextView(textView) }
|
|
745
|
+
SegmentViewCreators.updateTextView(textView, segment)
|
|
653
746
|
animateTextViewTail(textView, tailStart)
|
|
654
747
|
}
|
|
655
748
|
|
|
@@ -663,9 +756,7 @@ class EnrichedMarkdown
|
|
|
663
756
|
}
|
|
664
757
|
|
|
665
758
|
is RenderedSegment.Math -> {
|
|
666
|
-
|
|
667
|
-
?.getMethod("applyLatex", String::class.java)
|
|
668
|
-
?.invoke(view, segment.latex)
|
|
759
|
+
SegmentViewCreators.updateMathView(view, segment)
|
|
669
760
|
}
|
|
670
761
|
|
|
671
762
|
is RenderedSegment.CodeBlock -> {
|
|
@@ -674,281 +765,140 @@ class EnrichedMarkdown
|
|
|
674
765
|
applyCodeBlockNode(segment.node)
|
|
675
766
|
}
|
|
676
767
|
}
|
|
768
|
+
|
|
769
|
+
is RenderedSegment.Blockquote -> {
|
|
770
|
+
(view as BlockquoteContainerView).applyBlockquoteNode(segment.node)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
is RenderedSegment.Video -> {
|
|
774
|
+
SegmentViewCreators.updateVideoView(view, segment)
|
|
775
|
+
}
|
|
677
776
|
}
|
|
678
777
|
}
|
|
679
778
|
|
|
680
|
-
|
|
779
|
+
override fun animateNewView(
|
|
681
780
|
view: View,
|
|
682
781
|
segment: RenderedSegment,
|
|
683
782
|
) {
|
|
684
783
|
if (!streamingAnimation) return
|
|
685
784
|
when (segment) {
|
|
686
785
|
is RenderedSegment.Text -> animateTextViewTail(view as EnrichedMarkdownInternalText, 0)
|
|
687
|
-
is RenderedSegment.Table, is RenderedSegment.Math, is RenderedSegment.CodeBlock -> animateBlockViewFadeIn(view)
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
private fun animateTextViewTail(
|
|
692
|
-
view: EnrichedMarkdownInternalText,
|
|
693
|
-
tailStart: Int,
|
|
694
|
-
) {
|
|
695
|
-
if (!streamingAnimation) return
|
|
696
|
-
val textLength = view.text?.length ?: 0
|
|
697
|
-
if (textLength <= tailStart) return
|
|
698
|
-
TailFadeInAnimator(view).animate(tailStart, textLength)
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
private fun animateBlockViewFadeIn(view: View) {
|
|
702
|
-
if (!streamingAnimation) return
|
|
703
|
-
if (isReducedMotionEnabled(context)) return
|
|
704
|
-
view.alpha = 0f
|
|
705
|
-
view
|
|
706
|
-
.animate()
|
|
707
|
-
.alpha(1f)
|
|
708
|
-
.setDuration(BLOCK_FADE_DURATION_MS)
|
|
709
|
-
.start()
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
private fun createTextView(segment: RenderedSegment.Text) =
|
|
713
|
-
EnrichedMarkdownInternalText(context).apply {
|
|
714
|
-
spoilerOverlay = this@EnrichedMarkdown.spoilerOverlay
|
|
715
|
-
enableTaskListItemToggle = this@EnrichedMarkdown.enableTaskListItemToggle
|
|
716
|
-
selectionMenuConfig = this@EnrichedMarkdown.selectionMenuConfig
|
|
717
|
-
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
718
|
-
accessibilityLabels = this@EnrichedMarkdown.accessibilityLabels
|
|
719
|
-
setIsSelectable(selectable)
|
|
720
|
-
markdownStyle?.paragraphStyle?.fontSize?.let { setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, it) }
|
|
721
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
722
|
-
breakStrategy = BreakStrategyUtils.resolveBreakStrategy(textBreakStrategy)
|
|
723
|
-
}
|
|
724
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && segment.needsJustify) {
|
|
725
|
-
justificationMode = android.text.Layout.JUSTIFICATION_MODE_INTER_WORD
|
|
726
|
-
}
|
|
727
|
-
lastElementMarginBottom = segment.lastElementMarginBottom
|
|
728
|
-
applyStyledText(segment.styledText)
|
|
729
|
-
segment.imageSpans.forEach { it.registerTextView(this) }
|
|
730
|
-
|
|
731
|
-
onTaskListItemPressCallback = { taskIndex, checked, itemText ->
|
|
732
|
-
this@EnrichedMarkdown.onTaskListItemPressCallback?.invoke(taskIndex, checked, itemText)
|
|
733
|
-
}
|
|
734
|
-
onCopyRequest = ::forwardSegmentCopyRequest
|
|
735
|
-
onSelectionChangedCallback = ::onSegmentSelectionChanged
|
|
736
|
-
|
|
737
|
-
if (contextMenuItemTexts.isNotEmpty()) {
|
|
738
|
-
setContextMenuItems(contextMenuItemTexts, ::forwardContextMenuItemPress)
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
applySelectionColors(selectionColor, selectionHandleColor)
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
private fun createTableView(
|
|
745
|
-
segment: RenderedSegment.Table,
|
|
746
|
-
style: StyleConfig,
|
|
747
|
-
) = TableContainerView(context, style).apply {
|
|
748
|
-
allowFontScaling = this@EnrichedMarkdown.allowFontScaling
|
|
749
|
-
maxFontSizeMultiplier = this@EnrichedMarkdown.maxFontSizeMultiplier
|
|
750
|
-
accessibilityLabels = this@EnrichedMarkdown.accessibilityLabels
|
|
751
|
-
onLinkPress = onLinkPressCallback
|
|
752
|
-
onLinkLongPress = onLinkLongPressCallback
|
|
753
|
-
copyLabel = this@EnrichedMarkdown.selectionMenuConfig.copyLabel
|
|
754
|
-
copyAsMarkdownLabel = this@EnrichedMarkdown.selectionMenuConfig.copyAsMarkdownLabel
|
|
755
|
-
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
756
|
-
menuOptions = blockMenuOptions("table")
|
|
757
|
-
onMenuSuppressed = { markdown, text -> onBlockMenuSuppressed(this, "table", markdown, text) }
|
|
758
|
-
applyTableNode(segment.node)
|
|
759
|
-
}
|
|
760
786
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
contextMenuHidden = this@EnrichedMarkdown.contextMenuHidden
|
|
768
|
-
menuOptions = blockMenuOptions("code")
|
|
769
|
-
onMenuSuppressed = { markdown, text -> onBlockMenuSuppressed(this, "code", markdown, text) }
|
|
770
|
-
onCopyPress = { code, language ->
|
|
771
|
-
this@EnrichedMarkdown.onCopyPressCallback?.invoke(code, language)
|
|
772
|
-
}
|
|
773
|
-
pending = segment === pendingCodeBlockSegment
|
|
774
|
-
applyCodeBlockNode(segment.node)
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
private fun createMathView(
|
|
778
|
-
segment: RenderedSegment.Math,
|
|
779
|
-
style: StyleConfig,
|
|
780
|
-
): View {
|
|
781
|
-
val resolvedClass = mathContainerClass
|
|
782
|
-
if (!FeatureFlags.IS_MATH_ENABLED || resolvedClass == null) return View(context)
|
|
783
|
-
return try {
|
|
784
|
-
val view =
|
|
785
|
-
resolvedClass
|
|
786
|
-
.getConstructor(Context::class.java, StyleConfig::class.java)
|
|
787
|
-
.newInstance(context, style) as View
|
|
788
|
-
runCatching {
|
|
789
|
-
resolvedClass
|
|
790
|
-
.getMethod("setAccessibilityLabels", AccessibilityLabels::class.java)
|
|
791
|
-
.invoke(view, accessibilityLabels)
|
|
792
|
-
}
|
|
793
|
-
resolvedClass
|
|
794
|
-
.getMethod("setCopyLabel", String::class.java)
|
|
795
|
-
.invoke(view, selectionMenuConfig.copyLabel)
|
|
796
|
-
resolvedClass
|
|
797
|
-
.getMethod("setCopyAsMarkdownLabel", String::class.java)
|
|
798
|
-
.invoke(view, selectionMenuConfig.copyAsMarkdownLabel)
|
|
799
|
-
resolvedClass
|
|
800
|
-
.getMethod("setMenuOptions", BlockMenuOptions::class.java)
|
|
801
|
-
.invoke(view, blockMenuOptions("math"))
|
|
802
|
-
setMathContextMenuHidden(view)
|
|
803
|
-
val onMenuSuppressed: (String, String) -> Unit = { markdown, text ->
|
|
804
|
-
onBlockMenuSuppressed(view, "math", markdown, text)
|
|
805
|
-
}
|
|
806
|
-
runCatching {
|
|
807
|
-
resolvedClass.getMethod("setOnMenuSuppressed", Function2::class.java).invoke(view, onMenuSuppressed)
|
|
808
|
-
}.onFailure { Log.e(TAG, "Failed to set onMenuSuppressed on math view", it) }
|
|
809
|
-
resolvedClass.getMethod("applyLatex", String::class.java).invoke(view, segment.latex)
|
|
810
|
-
view
|
|
811
|
-
} catch (e: Exception) {
|
|
812
|
-
Log.e(TAG, "Failed to create math view", e)
|
|
813
|
-
View(context)
|
|
787
|
+
is RenderedSegment.Table,
|
|
788
|
+
is RenderedSegment.Math,
|
|
789
|
+
is RenderedSegment.CodeBlock,
|
|
790
|
+
is RenderedSegment.Blockquote,
|
|
791
|
+
is RenderedSegment.Video,
|
|
792
|
+
-> animateBlockViewFadeIn(view)
|
|
814
793
|
}
|
|
815
794
|
}
|
|
795
|
+
}
|
|
816
796
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
797
|
+
private fun animateTextViewTail(
|
|
798
|
+
view: EnrichedMarkdownInternalText,
|
|
799
|
+
tailStart: Int,
|
|
800
|
+
) {
|
|
801
|
+
if (!streamingAnimation) return
|
|
802
|
+
val textLength = view.text?.length ?: 0
|
|
803
|
+
if (textLength <= tailStart) return
|
|
804
|
+
TailFadeInAnimator(view).animate(tailStart, textLength)
|
|
805
|
+
}
|
|
825
806
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
807
|
+
private fun animateBlockViewFadeIn(view: View) {
|
|
808
|
+
if (!streamingAnimation) return
|
|
809
|
+
if (isReducedMotionEnabled(context)) return
|
|
810
|
+
view.alpha = 0f
|
|
811
|
+
view
|
|
812
|
+
.animate()
|
|
813
|
+
.alpha(1f)
|
|
814
|
+
.setDuration(BLOCK_FADE_DURATION_MS)
|
|
815
|
+
.start()
|
|
816
|
+
}
|
|
835
817
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
val wrapper = stateWrapper ?: return
|
|
843
|
-
val state = Arguments.createMap()
|
|
844
|
-
state.putInt("forceHeightRecalculationCounter", ++forceHeightRecalculationCounter)
|
|
845
|
-
wrapper.updateState(state)
|
|
818
|
+
private fun postToMain(
|
|
819
|
+
renderId: Long,
|
|
820
|
+
action: () -> Unit,
|
|
821
|
+
) {
|
|
822
|
+
mainHandler.post {
|
|
823
|
+
if (renderId == currentRenderId) action()
|
|
846
824
|
}
|
|
825
|
+
}
|
|
847
826
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (clipChildren == needsOverhang) {
|
|
858
|
-
clipChildren = !needsOverhang
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
var currentY = 0
|
|
862
|
-
val lastIndex = segmentViews.lastIndex
|
|
863
|
-
val widthSpec = MeasureSpec.makeMeasureSpec(containerWidth, MeasureSpec.EXACTLY)
|
|
864
|
-
val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
|
|
865
|
-
|
|
866
|
-
segmentViews.forEachIndexed { index, view ->
|
|
867
|
-
val segment = view as? BlockSegmentView
|
|
868
|
-
val shouldAddBottomMargin = index != lastIndex || allowTrailingMargin
|
|
869
|
-
|
|
870
|
-
currentY += segment?.segmentMarginTop ?: 0
|
|
871
|
-
|
|
872
|
-
val overhang =
|
|
873
|
-
if (view is TableContainerView) {
|
|
874
|
-
max(ceil(view.tableStyle.horizontalOverflow.toDouble()).toInt(), 0)
|
|
875
|
-
} else {
|
|
876
|
-
0
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
if (overhang > 0) {
|
|
880
|
-
val extendedWidth = containerWidth + overhang * 2
|
|
881
|
-
val extWidthSpec = MeasureSpec.makeMeasureSpec(extendedWidth, MeasureSpec.EXACTLY)
|
|
882
|
-
view.measure(extWidthSpec, heightSpec)
|
|
883
|
-
view.layout(-overhang, currentY, containerWidth + overhang, currentY + view.measuredHeight)
|
|
884
|
-
} else {
|
|
885
|
-
view.measure(widthSpec, heightSpec)
|
|
886
|
-
view.layout(0, currentY, containerWidth, currentY + view.measuredHeight)
|
|
887
|
-
}
|
|
888
|
-
currentY += view.measuredHeight
|
|
889
|
-
|
|
890
|
-
if (shouldAddBottomMargin) {
|
|
891
|
-
currentY += segment?.segmentMarginBottom ?: 0
|
|
892
|
-
}
|
|
893
|
-
}
|
|
827
|
+
override fun onLayout(
|
|
828
|
+
changed: Boolean,
|
|
829
|
+
l: Int,
|
|
830
|
+
t: Int,
|
|
831
|
+
r: Int,
|
|
832
|
+
b: Int,
|
|
833
|
+
) {
|
|
834
|
+
layoutSegmentsAndReport()
|
|
835
|
+
}
|
|
894
836
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
837
|
+
/**
|
|
838
|
+
* ContainerNodeView.layoutSegments is final, so the fork's post-layout hooks that used to
|
|
839
|
+
* sit at its end run here instead: report link rects (renderLinkDecoration) and re-read the
|
|
840
|
+
* selection, since segments may have moved or been replaced (deduplicated).
|
|
841
|
+
*/
|
|
842
|
+
private fun layoutSegmentsAndReport() {
|
|
843
|
+
layoutSegments()
|
|
844
|
+
if (width <= 0) return
|
|
845
|
+
emitLinkLayoutIfNeeded()
|
|
846
|
+
if (selectionOwner != null || activeBlock != null) selectionReporter.schedule() else selectionReporter.flushNow()
|
|
847
|
+
}
|
|
899
848
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
849
|
+
fun setEmitLinkLayout(enabled: Boolean) {
|
|
850
|
+
if (linkLayoutEnabled == enabled) return
|
|
851
|
+
linkLayoutEnabled = enabled
|
|
852
|
+
lastLinkLayout = null
|
|
853
|
+
emitLinkLayoutIfNeeded()
|
|
854
|
+
}
|
|
906
855
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
856
|
+
/**
|
|
857
|
+
* Reports link rects of every text segment (offset by the segment's position) to JS for
|
|
858
|
+
* `renderLinkDecoration`. Tables are skipped: their cells scroll horizontally, so rects would
|
|
859
|
+
* go stale. Runs after each segment layout pass; deduplicated so an unchanged layout sends nothing.
|
|
860
|
+
*
|
|
861
|
+
* P1 limitation: links inside a BlockquoteContainerView are neither reported nor counted,
|
|
862
|
+
* so linkIndex of later links is shifted. Fixed in P2 (A2) by walking containers recursively.
|
|
863
|
+
*/
|
|
864
|
+
private fun emitLinkLayoutIfNeeded() {
|
|
865
|
+
if (!linkLayoutEnabled || width <= 0) return
|
|
866
|
+
val fragments = mutableListOf<LinkLayoutFragment>()
|
|
867
|
+
var linkCount = 0
|
|
868
|
+
segmentViews.forEach { view ->
|
|
869
|
+
if (view is TableContainerView) {
|
|
870
|
+
linkCount += view.linkCount
|
|
871
|
+
return@forEach
|
|
872
|
+
}
|
|
873
|
+
if (view !is EnrichedMarkdownInternalText) return@forEach
|
|
874
|
+
val (segmentFragments, segmentLinks) = LinkLayoutCollector.collect(view, view.left, view.top, linkCount)
|
|
875
|
+
fragments += segmentFragments
|
|
876
|
+
linkCount += segmentLinks
|
|
877
|
+
}
|
|
878
|
+
if (fragments == lastLinkLayout) return
|
|
879
|
+
lastLinkLayout = fragments
|
|
880
|
+
emitLinkLayout(this, fragments)
|
|
881
|
+
}
|
|
930
882
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
val segment = view as? BlockSegmentView
|
|
936
|
-
totalHeight += segment?.segmentMarginTop ?: 0
|
|
937
|
-
totalHeight += view.measuredHeight
|
|
938
|
-
if (index != lastIndex || allowTrailingMargin) {
|
|
939
|
-
totalHeight += segment?.segmentMarginBottom ?: 0
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
return totalHeight
|
|
883
|
+
fun onImageLayoutChanged() {
|
|
884
|
+
if (width > 0) {
|
|
885
|
+
layoutSegmentsAndReport()
|
|
886
|
+
requestLayout()
|
|
943
887
|
}
|
|
888
|
+
MeasurementStore.invalidate(id)
|
|
889
|
+
val wrapper = stateWrapper ?: return
|
|
890
|
+
val state = Arguments.createMap()
|
|
891
|
+
state.putInt("forceHeightRecalculationCounter", ++forceHeightRecalculationCounter)
|
|
892
|
+
wrapper.updateState(state)
|
|
893
|
+
}
|
|
944
894
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
895
|
+
fun cleanup() {
|
|
896
|
+
selectionReporter.cancel()
|
|
897
|
+
executor.shutdownNow()
|
|
898
|
+
}
|
|
949
899
|
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
}
|
|
900
|
+
companion object {
|
|
901
|
+
private const val TAG = "EnrichedMarkdown"
|
|
902
|
+
private const val BLOCK_FADE_DURATION_MS = 200L
|
|
954
903
|
}
|
|
904
|
+
}
|