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