react-native-nitro-markdown 0.7.2 → 0.8.0

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 (79) hide show
  1. package/README.md +66 -4
  2. package/ios/HybridMarkdownSession.swift +11 -4
  3. package/lib/commonjs/MarkdownContext.js +1 -3
  4. package/lib/commonjs/MarkdownContext.js.map +1 -1
  5. package/lib/commonjs/index.js +6 -0
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/markdown-stream.js +80 -29
  8. package/lib/commonjs/markdown-stream.js.map +1 -1
  9. package/lib/commonjs/markdown.js +94 -37
  10. package/lib/commonjs/markdown.js.map +1 -1
  11. package/lib/commonjs/renderers/image.js +2 -2
  12. package/lib/commonjs/renderers/image.js.map +1 -1
  13. package/lib/commonjs/renderers/math.js +6 -2
  14. package/lib/commonjs/renderers/math.js.map +1 -1
  15. package/lib/commonjs/renderers/table/index.js +4 -4
  16. package/lib/commonjs/renderers/table/index.js.map +1 -1
  17. package/lib/commonjs/renderers/table/table-utils.js +1 -1
  18. package/lib/commonjs/renderers/table/table-utils.js.map +1 -1
  19. package/lib/commonjs/utils/code-highlight.js +1 -1
  20. package/lib/commonjs/utils/code-highlight.js.map +1 -1
  21. package/lib/commonjs/utils/incremental-ast.js +24 -11
  22. package/lib/commonjs/utils/incremental-ast.js.map +1 -1
  23. package/lib/commonjs/utils/link-security.js +2 -2
  24. package/lib/commonjs/utils/link-security.js.map +1 -1
  25. package/lib/commonjs/utils/stream-timeline.js +13 -7
  26. package/lib/commonjs/utils/stream-timeline.js.map +1 -1
  27. package/lib/module/MarkdownContext.js +1 -3
  28. package/lib/module/MarkdownContext.js.map +1 -1
  29. package/lib/module/index.js +1 -1
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/module/markdown-stream.js +79 -29
  32. package/lib/module/markdown-stream.js.map +1 -1
  33. package/lib/module/markdown.js +94 -37
  34. package/lib/module/markdown.js.map +1 -1
  35. package/lib/module/renderers/image.js +2 -2
  36. package/lib/module/renderers/image.js.map +1 -1
  37. package/lib/module/renderers/math.js +6 -2
  38. package/lib/module/renderers/math.js.map +1 -1
  39. package/lib/module/renderers/table/index.js +4 -4
  40. package/lib/module/renderers/table/index.js.map +1 -1
  41. package/lib/module/renderers/table/table-utils.js +1 -1
  42. package/lib/module/renderers/table/table-utils.js.map +1 -1
  43. package/lib/module/utils/code-highlight.js +1 -1
  44. package/lib/module/utils/code-highlight.js.map +1 -1
  45. package/lib/module/utils/incremental-ast.js +24 -11
  46. package/lib/module/utils/incremental-ast.js.map +1 -1
  47. package/lib/module/utils/link-security.js +2 -2
  48. package/lib/module/utils/link-security.js.map +1 -1
  49. package/lib/module/utils/stream-timeline.js +13 -7
  50. package/lib/module/utils/stream-timeline.js.map +1 -1
  51. package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/index.d.ts +2 -2
  53. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/markdown-stream.d.ts +28 -7
  55. package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/utils/incremental-ast.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/utils/stream-timeline.d.ts.map +1 -1
  59. package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
  60. package/lib/typescript/module/index.d.ts +2 -2
  61. package/lib/typescript/module/index.d.ts.map +1 -1
  62. package/lib/typescript/module/markdown-stream.d.ts +28 -7
  63. package/lib/typescript/module/markdown-stream.d.ts.map +1 -1
  64. package/lib/typescript/module/markdown.d.ts.map +1 -1
  65. package/lib/typescript/module/utils/incremental-ast.d.ts.map +1 -1
  66. package/lib/typescript/module/utils/stream-timeline.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/src/MarkdownContext.ts +0 -2
  69. package/src/index.ts +9 -2
  70. package/src/markdown-stream.tsx +107 -31
  71. package/src/markdown.tsx +75 -41
  72. package/src/renderers/image.tsx +2 -2
  73. package/src/renderers/math.tsx +2 -2
  74. package/src/renderers/table/index.tsx +4 -4
  75. package/src/renderers/table/table-utils.ts +1 -1
  76. package/src/utils/code-highlight.ts +1 -1
  77. package/src/utils/incremental-ast.ts +25 -9
  78. package/src/utils/link-security.ts +3 -3
  79. package/src/utils/stream-timeline.ts +10 -7
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # react-native-nitro-markdown
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/react-native-nitro-markdown?color=f97316&label=npm)](https://www.npmjs.com/package/react-native-nitro-markdown)
4
+ [![npm downloads](https://img.shields.io/npm/dm/react-native-nitro-markdown?color=22c55e&label=downloads)](https://www.npmjs.com/package/react-native-nitro-markdown)
5
+ [![CI](https://github.com/JoaoPauloCMarra/react-native-nitro-markdown/actions/workflows/ci.yml/badge.svg)](https://github.com/JoaoPauloCMarra/react-native-nitro-markdown/actions/workflows/ci.yml)
4
6
  [![license](https://img.shields.io/npm/l/react-native-nitro-markdown?color=007ec6)](https://github.com/JoaoPauloCMarra/react-native-nitro-markdown/blob/main/LICENSE)
5
7
  [![React Native](https://img.shields.io/badge/react--native-%3E%3D0.75-61dafb)](https://reactnative.dev/)
6
- [![Expo](https://img.shields.io/badge/expo-SDK%2056-000020)](https://expo.dev/)
7
- [![Nitro Modules](https://img.shields.io/badge/nitro--modules-%3E%3D0.35.7-black)](https://nitro.margelo.com/)
8
+ [![Expo](https://img.shields.io/badge/expo-SDK%2056-000020)](https://docs.expo.dev/versions/v56.0.0/)
9
+ [![Nitro Modules](https://img.shields.io/badge/nitro--modules-%3E%3D0.35.7-black)](https://www.npmjs.com/package/react-native-nitro-modules)
10
+ [![TypeScript](https://img.shields.io/badge/typescript-6.0-3178c6)](https://www.typescriptlang.org/)
8
11
 
9
12
  Markdown parsing, rendering, streaming, and headless AST access for React
10
13
  Native, powered by md4c and Nitro Modules.
@@ -23,6 +26,9 @@ AST access without building your own parser pipeline.
23
26
  bun add react-native-nitro-markdown react-native-nitro-modules ratex-react-native
24
27
  ```
25
28
 
29
+ `react-native-nitro-modules` and `ratex-react-native` are peer dependencies
30
+ because parsing and math rendering use native code.
31
+
26
32
  For Expo development builds:
27
33
 
28
34
  ```sh
@@ -100,6 +106,47 @@ run correctly. `MarkdownStream` accepts the controller returned by
100
106
  `useMarkdownSession()`. Pass `session.getSession()` only when another API needs
101
107
  direct access to the native session object.
102
108
 
109
+ ### Custom stream rendering
110
+
111
+ Use `renderMarkdown` when you want `MarkdownStream` to keep the session
112
+ subscription, batching, and incremental AST updates while another component owns
113
+ the rendering. The callback receives the current text, the reusable source AST
114
+ when available, and `markdownProps` that match the built-in `Markdown`
115
+ component:
116
+
117
+ ```tsx
118
+ <MarkdownStream
119
+ session={session}
120
+ renderMarkdown={({ text, sourceAst, markdownProps }) => (
121
+ <MyMarkdownRenderer
122
+ markdown={text}
123
+ ast={sourceAst}
124
+ fallbackProps={markdownProps}
125
+ />
126
+ )}
127
+ />
128
+ ```
129
+
130
+ Use `useMarkdownStreamState` when you want the streaming state without the
131
+ `MarkdownStream` wrapper:
132
+
133
+ ```tsx
134
+ const { text, sourceAst, sourceAstStatus } = useMarkdownStreamState({
135
+ session,
136
+ updateStrategy: "raf",
137
+ });
138
+ ```
139
+
140
+ `sourceAst` is available when the stream can safely reuse Nitro's parsed AST.
141
+ When a `beforeParse` plugin is present, `sourceAstStatus` becomes `"disabled"`
142
+ and `sourceAstDisabledReason` is `"beforeParse-plugin"`. In that state,
143
+ `sourceAst` is omitted; render from `text` so the full plugin pipeline can run.
144
+
145
+ `MarkdownStream` avoids full-buffer reads on stable parent renders. It uses
146
+ native range reads for append-only updates, then falls back to a full session
147
+ read only for reset-like changes, replacements inside existing text, or native
148
+ range-read failures.
149
+
103
150
  ## Headless Parsing
104
151
 
105
152
  ```ts
@@ -151,6 +198,16 @@ already happened. `afterParse` plugins and `astTransform` still run.
151
198
  | `highlightCode` | `false` | Enables built-in syntax highlighting. |
152
199
  | `tableOptions` | Built-in defaults | Controls table measurement and minimum widths. |
153
200
 
201
+ ## Compatibility
202
+
203
+ | Dependency | Supported range or baseline |
204
+ | ---------- | --------------------------- |
205
+ | [React Native](https://reactnative.dev/) | `>=0.75.0` |
206
+ | [Nitro Modules](https://www.npmjs.com/package/react-native-nitro-modules) | `>=0.35.7` |
207
+ | [RaTeX React Native](https://www.npmjs.com/package/ratex-react-native) | `>=0.1.4` |
208
+ | [Expo](https://docs.expo.dev/versions/v56.0.0/) | SDK 56 development builds |
209
+ | [TypeScript](https://www.typescriptlang.org/) | 6.0 in this package workspace |
210
+
154
211
  ## Custom Rendering
155
212
 
156
213
  ```tsx
@@ -249,13 +306,18 @@ Main export:
249
306
  - `Markdown` for rendering complete markdown strings.
250
307
  - `MarkdownStream` for incremental rendering.
251
308
  - `MarkdownSession` and `useMarkdownSession()` for append/replace/reset flows.
309
+ - `useMarkdownStreamState()` for headless streaming text and AST state.
252
310
  - `useStream()` for timestamped stream state.
253
311
  - `defaultMarkdownTheme` and theme types.
254
312
  - Renderer components such as `Paragraph`, `Heading`, `Link`, `CodeBlock`,
255
313
  `List`, `Table`, and `Image`.
256
314
  - Types including `MarkdownNode`, `MarkdownPlugin`, `CustomRenderers`,
257
315
  `MarkdownRenderers`, `CustomRendererPropsByNode`, `ParserOptions`,
258
- `MarkdownTheme`, `MarkdownSessionController`, and `MarkdownStreamProps`.
316
+ `MarkdownTheme`, `MarkdownSessionController`, `MarkdownStreamProps`,
317
+ `MarkdownStreamRenderProps`, `MarkdownStreamState`,
318
+ `MarkdownStreamSourceAstStatus`, `MarkdownStreamSourceAstDisabledReason`,
319
+ `UseMarkdownStreamStateOptions`, `CodeHighlighter`, `HighlightedToken`,
320
+ `TokenType`, and `UrlSafetyOptions`.
259
321
 
260
322
  Headless export:
261
323
 
@@ -273,7 +335,7 @@ Headless export:
273
335
  | iOS | Native parser through Nitro and md4c. |
274
336
  | Android | Native parser through Nitro and md4c. |
275
337
  | Expo | Development builds. |
276
- | Web | Not the primary target for native parsing. |
338
+ | Web | Not supported. The parser requires Nitro Modules (JSI); there is no web entrypoint and imports on web fail deterministically. |
277
339
 
278
340
  ## Troubleshooting
279
341
 
@@ -55,6 +55,13 @@ class HybridMarkdownSession: HybridMarkdownSessionSpec {
55
55
  return (value as NSString).length
56
56
  }
57
57
 
58
+ private func clampedIndex(_ value: Double, upperBound: Int) -> Int {
59
+ if value <= 0 { return 0 }
60
+ let upper = Double(upperBound)
61
+ if value >= upper { return upperBound }
62
+ return Int(value)
63
+ }
64
+
58
65
  private func validateBufferSize(_ size: Int) throws {
59
66
  if size > Self.maxBufferSize {
60
67
  throw NSError(
@@ -120,8 +127,8 @@ class HybridMarkdownSession: HybridMarkdownSessionSpec {
120
127
 
121
128
  let text = buffer as NSString
122
129
  let length = text.length
123
- let start = max(0, min(Int(from), length))
124
- let end = max(start, min(Int(to), length))
130
+ let start = clampedIndex(from, upperBound: length)
131
+ let end = max(start, clampedIndex(to, upperBound: length))
125
132
  return text.substring(with: NSRange(location: start, length: end - start))
126
133
  }
127
134
 
@@ -179,8 +186,8 @@ class HybridMarkdownSession: HybridMarkdownSessionSpec {
179
186
  }
180
187
  let nsBuffer = NSMutableString(string: buffer)
181
188
  let length = nsBuffer.length
182
- start = max(0, min(Int(from), length))
183
- end = max(start, min(Int(to), length))
189
+ start = clampedIndex(from, upperBound: length)
190
+ end = max(start, clampedIndex(to, upperBound: length))
184
191
  try validateBufferSize(length - (end - start) + utf16Length(text))
185
192
  nsBuffer.replaceCharacters(in: NSRange(location: start, length: end - start), with: text)
186
193
  buffer = nsBuffer as String
@@ -9,9 +9,7 @@ var _theme = require("./theme.js");
9
9
  const MarkdownContext = exports.MarkdownContext = /*#__PURE__*/(0, _react.createContext)({
10
10
  renderers: {},
11
11
  theme: _theme.defaultMarkdownTheme,
12
- styles: undefined,
13
- stylingStrategy: "opinionated",
14
- onLinkPress: undefined
12
+ stylingStrategy: "opinionated"
15
13
  });
16
14
  const useMarkdownContext = () => (0, _react.useContext)(MarkdownContext);
17
15
  exports.useMarkdownContext = useMarkdownContext;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_theme","MarkdownContext","exports","createContext","renderers","theme","defaultMarkdownTheme","styles","undefined","stylingStrategy","onLinkPress","useMarkdownContext","useContext"],"sourceRoot":"../../src","sources":["MarkdownContext.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAwIO,MAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAG,IAAAE,oBAAa,EAAuB;EACjEC,SAAS,EAAE,CAAC,CAAC;EACbC,KAAK,EAAEC,2BAAoB;EAC3BC,MAAM,EAAEC,SAAS;EACjBC,eAAe,EAAE,aAAa;EAC9BC,WAAW,EAAEF;AACf,CAAC,CAAC;AAEK,MAAMG,kBAAkB,GAAGA,CAAA,KAAM,IAAAC,iBAAU,EAACX,eAAe,CAAC;AAACC,OAAA,CAAAS,kBAAA,GAAAA,kBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_theme","MarkdownContext","exports","createContext","renderers","theme","defaultMarkdownTheme","stylingStrategy","useMarkdownContext","useContext"],"sourceRoot":"../../src","sources":["MarkdownContext.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAwIO,MAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAG,IAAAE,oBAAa,EAAuB;EACjEC,SAAS,EAAE,CAAC,CAAC;EACbC,KAAK,EAAEC,2BAAoB;EAC3BC,eAAe,EAAE;AACnB,CAAC,CAAC;AAEK,MAAMC,kBAAkB,GAAGA,CAAA,KAAM,IAAAC,iBAAU,EAACR,eAAe,CAAC;AAACC,OAAA,CAAAM,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -195,6 +195,12 @@ Object.defineProperty(exports, "useMarkdownSession", {
195
195
  return _useMarkdownStream.useMarkdownSession;
196
196
  }
197
197
  });
198
+ Object.defineProperty(exports, "useMarkdownStreamState", {
199
+ enumerable: true,
200
+ get: function () {
201
+ return _markdownStream.useMarkdownStreamState;
202
+ }
203
+ });
198
204
  Object.defineProperty(exports, "useStream", {
199
205
  enumerable: true,
200
206
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"names":["_headless","require","_markdown","_markdownStream","_MarkdownContext","_theme","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_MarkdownSession","_useMarkdownStream","_codeHighlight"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAmBA,IAAAC,SAAA,GAAAD,OAAA;AASA,IAAAE,eAAA,GAAAF,OAAA;AAGA,IAAAG,gBAAA,GAAAH,OAAA;AAuBA,IAAAI,MAAA,GAAAJ,OAAA;AAYA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AACA,IAAAS,eAAA,GAAAT,OAAA;AACA,IAAAU,KAAA,GAAAV,OAAA;AACA,IAAAW,KAAA,GAAAX,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AACA,IAAAa,MAAA,GAAAb,OAAA;AACA,IAAAc,KAAA,GAAAd,OAAA;AAEA,IAAAe,gBAAA,GAAAf,OAAA;AAEA,IAAAgB,kBAAA,GAAAhB,OAAA;AAQA,IAAAiB,cAAA,GAAAjB,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_headless","require","_markdown","_markdownStream","_MarkdownContext","_theme","_heading","_paragraph","_link","_blockquote","_horizontalRule","_code","_list","_table","_image","_math","_MarkdownSession","_useMarkdownStream","_codeHighlight"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAmBA,IAAAC,SAAA,GAAAD,OAAA;AASA,IAAAE,eAAA,GAAAF,OAAA;AAUA,IAAAG,gBAAA,GAAAH,OAAA;AAuBA,IAAAI,MAAA,GAAAJ,OAAA;AAYA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AACA,IAAAS,eAAA,GAAAT,OAAA;AACA,IAAAU,KAAA,GAAAV,OAAA;AACA,IAAAW,KAAA,GAAAX,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AACA,IAAAa,MAAA,GAAAb,OAAA;AACA,IAAAc,KAAA,GAAAd,OAAA;AAEA,IAAAe,gBAAA,GAAAf,OAAA;AAEA,IAAAgB,kBAAA,GAAAhB,OAAA;AAQA,IAAAiB,cAAA,GAAAjB,OAAA","ignoreList":[]}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MarkdownStream = void 0;
7
+ exports.useMarkdownStreamState = useMarkdownStreamState;
7
8
  var _react = require("react");
8
9
  var _markdown = require("./markdown.js");
9
10
  var _useMarkdownStream = require("./use-markdown-stream.js");
@@ -22,11 +23,11 @@ const normalizeParserOptions = options => {
22
23
  if (gfm === undefined && math === undefined && html === undefined) {
23
24
  return undefined;
24
25
  }
25
- return {
26
- gfm,
27
- math,
28
- html
29
- };
26
+ const normalized = {};
27
+ if (gfm !== undefined) normalized.gfm = gfm;
28
+ if (math !== undefined) normalized.math = math;
29
+ if (html !== undefined) normalized.html = html;
30
+ return normalized;
30
31
  };
31
32
  const resolveStreamText = ({
32
33
  forceFullSync,
@@ -65,41 +66,41 @@ function warnStreamError(message, error) {
65
66
  warn.call(console, message, error);
66
67
  }
67
68
  }
68
- /**
69
- * A component that renders streaming Markdown from a MarkdownSession.
70
- * It efficiently subscribes to session updates to minimize parent re-renders.
71
- */
72
- const MarkdownStream = ({
69
+ function useMarkdownStreamState({
73
70
  session,
74
71
  updateIntervalMs = 50,
75
72
  updateStrategy = "interval",
76
73
  useTransitionUpdates = false,
77
74
  incrementalParsing = true,
78
75
  options,
79
- plugins,
80
- ...props
81
- }) => {
76
+ plugins
77
+ }) {
82
78
  const activeSession = (0, _useMarkdownStream.resolveMarkdownSession)(session);
83
79
  const parserOptionGfm = options?.gfm;
84
80
  const parserOptionMath = options?.math;
85
81
  const parserOptionHtml = options?.html;
86
- const parserOptions = (0, _react.useMemo)(() => normalizeParserOptions({
87
- gfm: parserOptionGfm,
88
- math: parserOptionMath,
82
+ const parserOptions = (0, _react.useMemo)(() => normalizeParserOptions(Object.assign({}, parserOptionGfm === undefined ? null : {
83
+ gfm: parserOptionGfm
84
+ }, parserOptionMath === undefined ? null : {
85
+ math: parserOptionMath
86
+ }, parserOptionHtml === undefined ? null : {
89
87
  html: parserOptionHtml
90
- }), [parserOptionGfm, parserOptionMath, parserOptionHtml]);
88
+ })), [parserOptionGfm, parserOptionMath, parserOptionHtml]);
91
89
  const parseText = (0, _react.useCallback)(text => (0, _incrementalAst.parseMarkdownAst)(text, parserOptions), [parserOptions]);
92
90
  const createEmptyAst = () => ({
93
91
  type: "document",
94
92
  children: []
95
93
  });
96
- const initialText = activeSession.getAllText();
97
94
  const hasBeforeParsePlugins = plugins?.some(plugin => typeof plugin.beforeParse === "function") ?? false;
98
- const [renderState, setRenderState] = (0, _react.useState)(() => ({
99
- text: initialText,
100
- ast: hasBeforeParsePlugins ? createEmptyAst() : parseText(initialText)
101
- }));
95
+ const [renderState, setRenderState] = (0, _react.useState)(() => {
96
+ const initialText = activeSession.getAllText();
97
+ return {
98
+ text: initialText,
99
+ ast: hasBeforeParsePlugins ? createEmptyAst() : parseText(initialText)
100
+ };
101
+ });
102
102
  const renderStateRef = (0, _react.useRef)(renderState);
103
+ const didMountRef = (0, _react.useRef)(false);
103
104
  const pendingUpdateRef = (0, _react.useRef)(false);
104
105
  const pendingFromRef = (0, _react.useRef)(null);
105
106
  const pendingToRef = (0, _react.useRef)(null);
@@ -118,6 +119,10 @@ const MarkdownStream = ({
118
119
  };
119
120
  }, []);
120
121
  (0, _react.useEffect)(() => {
122
+ if (!didMountRef.current) {
123
+ didMountRef.current = true;
124
+ return;
125
+ }
121
126
  const initialText = activeSession.getAllText();
122
127
  const initialState = {
123
128
  text: initialText,
@@ -163,9 +168,11 @@ const MarkdownStream = ({
163
168
  const nextAst = hasBeforeParsePlugins ? previousState.ast : (0, _incrementalAst.getNextStreamAst)({
164
169
  allowIncremental,
165
170
  nextText: latest,
166
- options: parserOptions,
167
171
  previousAst: previousState.ast,
168
- previousText: previousState.text
172
+ previousText: previousState.text,
173
+ ...(parserOptions ? {
174
+ options: parserOptions
175
+ } : {})
169
176
  });
170
177
  const nextState = {
171
178
  text: latest,
@@ -233,12 +240,56 @@ const MarkdownStream = ({
233
240
  }
234
241
  };
235
242
  }, [allowIncremental, hasBeforeParsePlugins, parserOptions, activeSession, updateIntervalMs, updateStrategy, useTransitionUpdates]);
236
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_markdown.Markdown, {
243
+ const streamState = {
244
+ text: renderState.text,
245
+ sourceAstStatus: hasBeforeParsePlugins ? "disabled" : "available"
246
+ };
247
+ if (hasBeforeParsePlugins) {
248
+ streamState.sourceAstDisabledReason = "beforeParse-plugin";
249
+ } else {
250
+ streamState.sourceAst = renderState.ast;
251
+ }
252
+ return streamState;
253
+ }
254
+ const MarkdownStream = ({
255
+ session,
256
+ updateIntervalMs = 50,
257
+ updateStrategy = "interval",
258
+ useTransitionUpdates = false,
259
+ incrementalParsing = true,
260
+ options,
261
+ plugins,
262
+ renderMarkdown,
263
+ ...props
264
+ }) => {
265
+ const streamState = useMarkdownStreamState({
266
+ session,
267
+ updateIntervalMs,
268
+ updateStrategy,
269
+ useTransitionUpdates,
270
+ incrementalParsing,
271
+ ...(options ? {
272
+ options
273
+ } : {}),
274
+ ...(plugins ? {
275
+ plugins
276
+ } : {})
277
+ });
278
+ const markdownProps = {
237
279
  ...props,
238
- options: options,
239
- plugins: plugins,
240
- sourceAst: hasBeforeParsePlugins ? undefined : renderState.ast,
241
- children: renderState.text
280
+ children: streamState.text
281
+ };
282
+ if (options) markdownProps.options = options;
283
+ if (plugins) markdownProps.plugins = plugins;
284
+ if (streamState.sourceAst) markdownProps.sourceAst = streamState.sourceAst;
285
+ if (renderMarkdown) {
286
+ return renderMarkdown({
287
+ ...streamState,
288
+ markdownProps
289
+ });
290
+ }
291
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_markdown.Markdown, {
292
+ ...markdownProps
242
293
  });
243
294
  };
244
295
  exports.MarkdownStream = MarkdownStream;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_markdown","_useMarkdownStream","_incrementalAst","_jsxRuntime","normalizeOffset","value","Number","isFinite","Math","floor","normalizeParserOptions","options","undefined","gfm","math","html","resolveStreamText","forceFullSync","pendingFrom","pendingTo","previousText","session","getAllText","length","appendedChunk","getTextRange","warnStreamError","message","error","__DEV__","warn","Reflect","get","console","call","MarkdownStream","updateIntervalMs","updateStrategy","useTransitionUpdates","incrementalParsing","plugins","props","activeSession","resolveMarkdownSession","parserOptionGfm","parserOptionMath","parserOptionHtml","parserOptions","useMemo","parseText","useCallback","text","parseMarkdownAst","createEmptyAst","type","children","initialText","hasBeforeParsePlugins","some","plugin","beforeParse","renderState","setRenderState","useState","ast","renderStateRef","useRef","pendingUpdateRef","pendingFromRef","pendingToRef","forceFullSyncRef","updateTimerRef","rafRef","mountedRef","allowIncremental","useEffect","current","initialState","flushUpdate","cancelAnimationFrame","previousState","latest","nextAst","getNextStreamAst","nextText","previousAst","nextState","startTransition","scheduleFlush","requestAnimationFrame","setTimeout","unsubscribe","addListener","from","to","nextFrom","nextTo","currentFrom","currentTo","min","max","clearTimeout","jsx","Markdown","sourceAst","exports"],"sourceRoot":"../../src","sources":["markdown-stream.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAWA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAF,OAAA;AAIA,IAAAG,eAAA,GAAAH,OAAA;AAA6E,IAAAI,WAAA,GAAAJ,OAAA;AAE7E,MAAMK,eAAe,GAAIC,KAAa,IAAoB;EACxD,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACF,KAAK,CAAC,EAAE,OAAO,IAAI;EACxC,IAAIA,KAAK,IAAI,CAAC,EAAE,OAAO,CAAC;EACxB,OAAOG,IAAI,CAACC,KAAK,CAACJ,KAAK,CAAC;AAC1B,CAAC;AAED,MAAMK,sBAAsB,GAC1BC,OAAuB,IACO;EAC9B,IAAI,CAACA,OAAO,EAAE,OAAOC,SAAS;EAE9B,MAAMC,GAAG,GAAGF,OAAO,CAACE,GAAG;EACvB,MAAMC,IAAI,GAAGH,OAAO,CAACG,IAAI;EACzB,MAAMC,IAAI,GAAGJ,OAAO,CAACI,IAAI;EAEzB,IAAIF,GAAG,KAAKD,SAAS,IAAIE,IAAI,KAAKF,SAAS,IAAIG,IAAI,KAAKH,SAAS,EAAE;IACjE,OAAOA,SAAS;EAClB;EAEA,OAAO;IAAEC,GAAG;IAAEC,IAAI;IAAEC;EAAK,CAAC;AAC5B,CAAC;AAED,MAAMC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rB,CAAC;EAEF,oBACE,IAAAnC,WAAA,CAAAmG,GAAA,EAACtG,SAAA,CAAAuG,QAAQ;IAAA,GACH9D,KAAK;IACT9B,OAAO,EAAEA,OAAQ;IACjB6B,OAAO,EAAEA,OAAQ;IACjBgE,SAAS,EAAE/C,qBAAqB,GAAG7C,SAAS,GAAGiD,WAAW,CAACG,GAAI;IAAAT,QAAA,EAE9DM,WAAW,CAACV;EAAI,CACT,CAAC;AAEf,CAAC;AAACsD,OAAA,CAAAtE,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_markdown","_useMarkdownStream","_incrementalAst","_jsxRuntime","normalizeOffset","value","Number","isFinite","Math","floor","normalizeParserOptions","options","undefined","gfm","math","html","normalized","resolveStreamText","forceFullSync","pendingFrom","pendingTo","previousText","session","getAllText","length","appendedChunk","getTextRange","warnStreamError","message","error","__DEV__","warn","Reflect","get","console","call","useMarkdownStreamState","updateIntervalMs","updateStrategy","useTransitionUpdates","incrementalParsing","plugins","activeSession","resolveMarkdownSession","parserOptionGfm","parserOptionMath","parserOptionHtml","parserOptions","useMemo","Object","assign","parseText","useCallback","text","parseMarkdownAst","createEmptyAst","type","children","hasBeforeParsePlugins","some","plugin","beforeParse","renderState","setRenderState","useState","initialText","ast","renderStateRef","useRef","didMountRef","pendingUpdateRef","pendingFromRef","pendingToRef","forceFullSyncRef","updateTimerRef","rafRef","mountedRef","allowIncremental","useEffect","current","initialState","flushUpdate","cancelAnimationFrame","previousState","latest","nextAst","getNextStreamAst","nextText","previousAst","nextState","startTransition","scheduleFlush","requestAnimationFrame","setTimeout","unsubscribe","addListener","from","to","nextFrom","nextTo","currentFrom","currentTo","min","max","clearTimeout","streamState","sourceAstStatus","sourceAstDisabledReason","sourceAst","MarkdownStream","renderMarkdown","props","markdownProps","jsx","Markdown","exports"],"sourceRoot":"../../src","sources":["markdown-stream.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAYA,IAAAC,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,SAAS;EAE1E,IAAIE,cAAc,EAAE;IAClB,OAAOA,cAAc,CAAC;MACpB,GAAGL,WAAW;MACdO;IACF,CAAC,CAAC;EACJ;EAEA,oBAAO,IAAA7G,WAAA,CAAA8G,GAAA,EAACjH,SAAA,CAAAkH,QAAQ;IAAA,GAAKF;EAAa,CAAG,CAAC;AACxC,CAAC;AAACG,OAAA,CAAAN,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -65,9 +65,12 @@ const warnInDev = (message, error) => {
65
65
  }
66
66
  };
67
67
  const cloneMarkdownNode = node => {
68
- return {
68
+ const children = node.children?.map(cloneMarkdownNode);
69
+ return children ? {
69
70
  ...node,
70
- children: node.children?.map(cloneMarkdownNode)
71
+ children
72
+ } : {
73
+ ...node
71
74
  };
72
75
  };
73
76
  const getParserOptionsKey = options => {
@@ -85,11 +88,11 @@ const normalizeParserOptions = options => {
85
88
  if (gfm === undefined && math === undefined && html === undefined) {
86
89
  return undefined;
87
90
  }
88
- return {
89
- gfm,
90
- math,
91
- html
92
- };
91
+ const normalized = {};
92
+ if (gfm !== undefined) normalized.gfm = gfm;
93
+ if (math !== undefined) normalized.math = math;
94
+ if (html !== undefined) normalized.html = html;
95
+ return normalized;
93
96
  };
94
97
  const parseWithNativeParser = (text, options) => {
95
98
  if (options) {
@@ -201,11 +204,13 @@ const Markdown = ({
201
204
  try {
202
205
  const sortedPlugins = sortPluginsByPriority(plugins);
203
206
  const markdownToParse = sourceAst ? children : applyBeforeParsePlugins(children, sortedPlugins, onErrorRef.current);
204
- const parserOptions = normalizeParserOptions({
205
- gfm: parserOptionGfm,
206
- math: parserOptionMath,
207
+ const parserOptions = normalizeParserOptions(Object.assign({}, parserOptionGfm === undefined ? null : {
208
+ gfm: parserOptionGfm
209
+ }, parserOptionMath === undefined ? null : {
210
+ math: parserOptionMath
211
+ }, parserOptionHtml === undefined ? null : {
207
212
  html: parserOptionHtml
208
- });
213
+ }));
209
214
  const shouldCloneSourceAst = sourceAst && (Boolean(astTransform) || sortedPlugins?.some(plugin => plugin.afterParse) === true);
210
215
  let parsedAst = sourceAst ? shouldCloneSourceAst ? cloneMarkdownNode(sourceAst) : sourceAst : parseCache ? getCachedParsedAst(markdownToParse, parserOptions) : parseWithNativeParser(markdownToParse, parserOptions);
211
216
  parsedAst = applyAfterParsePlugins(parsedAst, sortedPlugins, onErrorRef.current);
@@ -252,12 +257,22 @@ const Markdown = ({
252
257
  const contextValue = (0, _react.useMemo)(() => ({
253
258
  renderers,
254
259
  theme,
255
- styles: nodeStyles,
256
260
  stylingStrategy,
257
- onLinkPress,
258
- tableOptions,
259
- imageOptions,
260
- highlightCode
261
+ ...(nodeStyles ? {
262
+ styles: nodeStyles
263
+ } : {}),
264
+ ...(onLinkPress ? {
265
+ onLinkPress
266
+ } : {}),
267
+ ...(tableOptions ? {
268
+ tableOptions
269
+ } : {}),
270
+ ...(imageOptions ? {
271
+ imageOptions
272
+ } : {}),
273
+ ...(highlightCode === undefined ? {} : {
274
+ highlightCode
275
+ })
261
276
  }), [renderers, theme, nodeStyles, stylingStrategy, onLinkPress, tableOptions, imageOptions, highlightCode]);
262
277
  const topLevelBlocks = parseResult.ast?.type === "document" ? parseResult.ast.children ?? [] : parseResult.ast ? [parseResult.ast] : [];
263
278
  const shouldVirtualizeBySetting = virtualize === true || virtualize === "auto" && topLevelBlocks.length >= virtualizationMinBlocks;
@@ -396,16 +411,24 @@ const NodeRendererComponent = ({
396
411
  }),
397
412
  ...(node.type === "link" && {
398
413
  href: node.href ?? "",
399
- title: node.title
414
+ ...(node.title ? {
415
+ title: node.title
416
+ } : {})
400
417
  }),
401
418
  ...(node.type === "image" && {
402
419
  url: node.href ?? "",
403
- alt: node.alt,
404
- title: node.title
420
+ ...(node.alt ? {
421
+ alt: node.alt
422
+ } : {}),
423
+ ...(node.title ? {
424
+ title: node.title
425
+ } : {})
405
426
  }),
406
427
  ...(node.type === "code_block" && {
407
428
  content: (0, _headless.getTextContent)(node),
408
- language: node.language
429
+ ...(node.language ? {
430
+ language: node.language
431
+ } : {})
409
432
  }),
410
433
  ...(node.type === "code_inline" && {
411
434
  content: node.content ?? ""
@@ -415,7 +438,9 @@ const NodeRendererComponent = ({
415
438
  }),
416
439
  ...(node.type === "list" && {
417
440
  ordered: node.ordered ?? false,
418
- start: node.start
441
+ ...(node.start === undefined ? {} : {
442
+ start: node.start
443
+ })
419
444
  }),
420
445
  ...(node.type === "task_list_item" && {
421
446
  checked: node.checked ?? false
@@ -435,7 +460,9 @@ const NodeRendererComponent = ({
435
460
  case "heading":
436
461
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_heading.Heading, {
437
462
  level: node.level ?? 1,
438
- style: nodeStyles?.heading,
463
+ ...(nodeStyles?.heading ? {
464
+ style: nodeStyles.heading
465
+ } : {}),
439
466
  children: renderChildren(node.children, inListItem, true)
440
467
  });
441
468
  case "paragraph":
@@ -472,36 +499,54 @@ const NodeRendererComponent = ({
472
499
  case "link":
473
500
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_link.Link, {
474
501
  href: node.href ?? "",
475
- style: nodeStyles?.link,
502
+ ...(nodeStyles?.link ? {
503
+ style: nodeStyles.link
504
+ } : {}),
476
505
  children: renderChildren(node.children, inListItem, true)
477
506
  });
478
507
  case "image":
479
508
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_image.Image, {
480
509
  url: node.href ?? "",
481
- title: node.title,
482
- alt: node.alt,
483
510
  Renderer: NodeRenderer,
484
- style: nodeStyles?.image
511
+ ...(node.title ? {
512
+ title: node.title
513
+ } : {}),
514
+ ...(node.alt ? {
515
+ alt: node.alt
516
+ } : {}),
517
+ ...(nodeStyles?.image ? {
518
+ style: nodeStyles.image
519
+ } : {})
485
520
  });
486
521
  case "code_inline":
487
522
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_code.InlineCode, {
488
- style: nodeStyles?.code_inline,
523
+ ...(nodeStyles?.code_inline ? {
524
+ style: nodeStyles.code_inline
525
+ } : {}),
489
526
  children: node.content
490
527
  });
491
528
  case "code_block":
492
529
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_code.CodeBlock, {
493
- language: node.language,
494
530
  content: (0, _headless.getTextContent)(node),
495
- style: nodeStyles?.code_block
531
+ ...(node.language ? {
532
+ language: node.language
533
+ } : {}),
534
+ ...(nodeStyles?.code_block ? {
535
+ style: nodeStyles.code_block
536
+ } : {})
496
537
  });
497
538
  case "blockquote":
498
539
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockquote.Blockquote, {
499
- style: nodeStyles?.blockquote,
540
+ ...(nodeStyles?.blockquote ? {
541
+ style: nodeStyles.blockquote
542
+ } : {}),
500
543
  children: renderChildren(node.children, inListItem, false)
501
544
  });
502
545
  case "horizontal_rule":
503
546
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_horizontalRule.HorizontalRule, {
504
- style: nodeStyles?.horizontal_rule
547
+ ...(nodeStyles?.horizontal_rule ? {
548
+ style: nodeStyles.horizontal_rule
549
+ } : {})
505
550
  });
506
551
  case "line_break":
507
552
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
@@ -518,20 +563,28 @@ const NodeRendererComponent = ({
518
563
  mathContent = mathContent.replace(/^\$+|\$+$/g, "").trim();
519
564
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_math.MathInline, {
520
565
  content: mathContent,
521
- style: nodeStyles?.math_inline
566
+ ...(nodeStyles?.math_inline ? {
567
+ style: nodeStyles.math_inline
568
+ } : {})
522
569
  });
523
570
  }
524
571
  case "math_block":
525
572
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_math.MathBlock, {
526
573
  content: (0, _headless.getTextContent)(node),
527
- style: nodeStyles?.math_block
574
+ ...(nodeStyles?.math_block ? {
575
+ style: nodeStyles.math_block
576
+ } : {})
528
577
  });
529
578
  case "list":
530
579
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_list.List, {
531
580
  ordered: node.ordered ?? false,
532
- start: node.start,
533
581
  depth: depth,
534
- style: nodeStyles?.list,
582
+ ...(node.start === undefined ? {} : {
583
+ start: node.start
584
+ }),
585
+ ...(nodeStyles?.list ? {
586
+ style: nodeStyles.list
587
+ } : {}),
535
588
  children: node.children?.map((child, index) => {
536
589
  if (child.type === "task_list_item") {
537
590
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(NodeRenderer, {
@@ -561,14 +614,18 @@ const NodeRendererComponent = ({
561
614
  case "task_list_item":
562
615
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_list.TaskListItem, {
563
616
  checked: node.checked ?? false,
564
- style: nodeStyles?.task_list_item,
617
+ ...(nodeStyles?.task_list_item ? {
618
+ style: nodeStyles.task_list_item
619
+ } : {}),
565
620
  children: renderChildren(node.children, true, false)
566
621
  });
567
622
  case "table":
568
623
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_table.TableRenderer, {
569
624
  node: node,
570
625
  Renderer: NodeRenderer,
571
- style: nodeStyles?.table
626
+ ...(nodeStyles?.table ? {
627
+ style: nodeStyles.table
628
+ } : {})
572
629
  });
573
630
  case "table_head":
574
631
  case "table_body":