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