react-native-nitro-markdown 0.6.1 → 0.7.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.
- package/README.md +77 -8
- package/android/gradle.properties +2 -2
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +21 -3
- package/ios/HybridMarkdownSession.swift +53 -3
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/headless.js +0 -4
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown-stream.js +40 -15
- package/lib/commonjs/markdown-stream.js.map +1 -1
- package/lib/commonjs/markdown.js +4 -3
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/heading.js +1 -0
- package/lib/commonjs/renderers/heading.js.map +1 -1
- package/lib/commonjs/renderers/image.js +22 -8
- package/lib/commonjs/renderers/image.js.map +1 -1
- package/lib/commonjs/renderers/link.js +1 -1
- package/lib/commonjs/renderers/link.js.map +1 -1
- package/lib/commonjs/renderers/list.js +4 -0
- package/lib/commonjs/renderers/list.js.map +1 -1
- package/lib/commonjs/renderers/math.js +0 -1
- package/lib/commonjs/renderers/math.js.map +1 -1
- package/lib/commonjs/use-markdown-stream.js +9 -1
- package/lib/commonjs/use-markdown-stream.js.map +1 -1
- package/lib/commonjs/utils/link-security.js +42 -5
- package/lib/commonjs/utils/link-security.js.map +1 -1
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/headless.js +0 -4
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown-stream.js +40 -15
- package/lib/module/markdown-stream.js.map +1 -1
- package/lib/module/markdown.js +4 -3
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/heading.js +1 -0
- package/lib/module/renderers/heading.js.map +1 -1
- package/lib/module/renderers/image.js +22 -8
- package/lib/module/renderers/image.js.map +1 -1
- package/lib/module/renderers/link.js +1 -1
- package/lib/module/renderers/link.js.map +1 -1
- package/lib/module/renderers/list.js +4 -0
- package/lib/module/renderers/list.js.map +1 -1
- package/lib/module/renderers/math.js +0 -1
- package/lib/module/renderers/math.js.map +1 -1
- package/lib/module/use-markdown-stream.js +9 -1
- package/lib/module/use-markdown-stream.js.map +1 -1
- package/lib/module/utils/link-security.js +40 -4
- package/lib/module/utils/link-security.js.map +1 -1
- package/lib/typescript/commonjs/MarkdownContext.d.ts +44 -7
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +6 -3
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -3
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +12 -11
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/link-security.d.ts +5 -0
- package/lib/typescript/commonjs/utils/link-security.d.ts.map +1 -1
- package/lib/typescript/module/MarkdownContext.d.ts +44 -7
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +6 -3
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -3
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown-stream.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +12 -11
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/module/renderers/image.d.ts.map +1 -1
- package/lib/typescript/module/renderers/link.d.ts.map +1 -1
- package/lib/typescript/module/renderers/list.d.ts.map +1 -1
- package/lib/typescript/module/renderers/math.d.ts.map +1 -1
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -1
- package/lib/typescript/module/utils/link-security.d.ts +5 -0
- package/lib/typescript/module/utils/link-security.d.ts.map +1 -1
- package/package.json +5 -5
- package/react-native-nitro-markdown.podspec +1 -1
- package/src/MarkdownContext.ts +51 -11
- package/src/headless.ts +35 -34
- package/src/index.ts +14 -1
- package/src/markdown-stream.tsx +49 -17
- package/src/markdown.tsx +20 -13
- package/src/renderers/heading.tsx +5 -1
- package/src/renderers/image.tsx +31 -9
- package/src/renderers/link.tsx +5 -2
- package/src/renderers/list.tsx +5 -1
- package/src/renderers/math.tsx +0 -1
- package/src/use-markdown-stream.ts +9 -1
- package/src/utils/link-security.ts +68 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { MarkdownParserModule, parseMarkdown, parseMarkdownWithOptions, extractPlainText, extractPlainTextWithOptions, getTextContent, getFlattenedText, stripSourceOffsets, } from "./headless";
|
|
2
|
-
export type { MarkdownNode, ParserOptions, MarkdownParser } from "./headless";
|
|
2
|
+
export type { MarkdownNode, MarkdownNodeType, HeadingLevel, TableCellAlign, ParserOptions, MarkdownParser, } from "./headless";
|
|
3
3
|
export { Markdown } from "./markdown";
|
|
4
|
-
export type { MarkdownProps, AstTransform, MarkdownPlugin, MarkdownVirtualizationOptions, } from "./markdown";
|
|
4
|
+
export type { MarkdownProps, AstTransform, MarkdownPlugin, MarkdownErrorPhase, MarkdownParseCompleteResult, MarkdownVirtualizationOptions, } from "./markdown";
|
|
5
5
|
export { MarkdownStream } from "./markdown-stream";
|
|
6
6
|
export type { MarkdownStreamProps } from "./markdown-stream";
|
|
7
7
|
export { useMarkdownContext, MarkdownContext } from "./MarkdownContext";
|
|
8
|
-
export type { CustomRenderer, CustomRenderers, CustomRendererProps, NodeRendererProps, BaseCustomRendererProps, EnhancedRendererProps, HeadingRendererProps, LinkRendererProps, ImageRendererProps, CodeBlockRendererProps, InlineCodeRendererProps, ListRendererProps, TaskListItemRendererProps, LinkPressHandler, MarkdownContextValue, } from "./MarkdownContext";
|
|
8
|
+
export type { CustomRenderer, CustomRenderers, CustomRendererProps, NodeRendererProps, BaseCustomRendererProps, EnhancedRendererProps, HeadingRendererProps, LinkRendererProps, ImageRendererProps, CodeBlockRendererProps, InlineCodeRendererProps, ListRendererProps, TaskListItemRendererProps, MathRendererProps, LinkPressHandler, MarkdownContextValue, CustomRendererPropsByNode, TableOptions, } from "./MarkdownContext";
|
|
9
9
|
export { defaultMarkdownTheme, minimalMarkdownTheme, mergeThemes, } from "./theme";
|
|
10
10
|
export type { MarkdownTheme, PartialMarkdownTheme, NodeStyleOverrides, StylingStrategy, } from "./theme";
|
|
11
11
|
export { Heading } from "./renderers/heading";
|
|
@@ -23,4 +23,5 @@ export type { MarkdownSession } from "./MarkdownSession";
|
|
|
23
23
|
export { useMarkdownSession, useStream } from "./use-markdown-stream";
|
|
24
24
|
export type { HighlightedToken, TokenType, CodeHighlighter, } from "./utils/code-highlight";
|
|
25
25
|
export { defaultHighlighter } from "./utils/code-highlight";
|
|
26
|
+
export type { UrlSafetyOptions } from "./utils/link-security";
|
|
26
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,gBAAgB,EAChB,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,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EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEtE,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/markdown-stream.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,EAAE,EACR,MAAM,OAAO,CAAC;AAEf,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/markdown-stream.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,EAAE,EACR,MAAM,OAAO,CAAC;AAEf,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AA2DrE,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,eAAe,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC;IACpC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,GAAG,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CAgMlD,CAAC"}
|
|
@@ -2,9 +2,10 @@ import { type FC } from "react";
|
|
|
2
2
|
import { type FlatListProps, type StyleProp, type ViewStyle } from "react-native";
|
|
3
3
|
import { type MarkdownNode } from "./headless";
|
|
4
4
|
import type { ParserOptions } from "./Markdown.nitro";
|
|
5
|
-
import { type CustomRenderers, type LinkPressHandler } from "./MarkdownContext";
|
|
5
|
+
import { type CustomRenderers, type LinkPressHandler, type TableOptions } from "./MarkdownContext";
|
|
6
6
|
import { type PartialMarkdownTheme, type NodeStyleOverrides, type StylingStrategy } from "./theme";
|
|
7
7
|
import type { CodeHighlighter } from "./utils/code-highlight";
|
|
8
|
+
import type { UrlSafetyOptions } from "./utils/link-security";
|
|
8
9
|
export type AstTransform = (ast: MarkdownNode) => MarkdownNode;
|
|
9
10
|
export type MarkdownVirtualizationOptions = Pick<FlatListProps<MarkdownNode>, "initialNumToRender" | "maxToRenderPerBatch" | "windowSize" | "updateCellsBatchingPeriod" | "removeClippedSubviews">;
|
|
10
11
|
export type MarkdownPlugin = {
|
|
@@ -30,6 +31,12 @@ export type MarkdownPlugin = {
|
|
|
30
31
|
*/
|
|
31
32
|
afterParse?: AstTransform;
|
|
32
33
|
};
|
|
34
|
+
export type MarkdownErrorPhase = "parse" | "before-plugin" | "after-plugin";
|
|
35
|
+
export type MarkdownParseCompleteResult = {
|
|
36
|
+
raw: string;
|
|
37
|
+
ast: MarkdownNode;
|
|
38
|
+
text: string;
|
|
39
|
+
};
|
|
33
40
|
export type MarkdownProps = {
|
|
34
41
|
/**
|
|
35
42
|
* The markdown string to parse and render.
|
|
@@ -71,18 +78,14 @@ export type MarkdownProps = {
|
|
|
71
78
|
/**
|
|
72
79
|
* Callback fired when parsing completes.
|
|
73
80
|
*/
|
|
74
|
-
onParseComplete?: (result:
|
|
75
|
-
raw: string;
|
|
76
|
-
ast: MarkdownNode;
|
|
77
|
-
text: string;
|
|
78
|
-
}) => void;
|
|
81
|
+
onParseComplete?: (result: MarkdownParseCompleteResult) => void;
|
|
79
82
|
/**
|
|
80
83
|
* Called when a parse error or plugin error occurs.
|
|
81
84
|
* @param error - The thrown error.
|
|
82
85
|
* @param phase - Where the error occurred.
|
|
83
86
|
* @param pluginName - The plugin name, if applicable.
|
|
84
87
|
*/
|
|
85
|
-
onError?: (error: Error, phase:
|
|
88
|
+
onError?: (error: Error, phase: MarkdownErrorPhase, pluginName?: string) => void;
|
|
86
89
|
/**
|
|
87
90
|
* Custom renderers for specific markdown node types.
|
|
88
91
|
* Each renderer receives { node, children, Renderer } plus type-specific props.
|
|
@@ -138,10 +141,8 @@ export type MarkdownProps = {
|
|
|
138
141
|
/**
|
|
139
142
|
* Optional configuration for the table renderer.
|
|
140
143
|
*/
|
|
141
|
-
tableOptions?:
|
|
142
|
-
|
|
143
|
-
measurementStabilizeMs?: number;
|
|
144
|
-
};
|
|
144
|
+
tableOptions?: TableOptions;
|
|
145
|
+
imageOptions?: UrlSafetyOptions;
|
|
145
146
|
/**
|
|
146
147
|
* Enable built-in syntax highlighting for code blocks.
|
|
147
148
|
* Pass `true` to use the built-in tokenizer, or a custom highlighter function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,EAAE,E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;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;;OAEG;IACH,cAAc,CAAC,EAAE,6BAA6B,CAAC;IAC/C;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CA4MtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/renderers/heading.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAK1E,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAYF,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/renderers/heading.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAK1E,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAYF,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,CAmBpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/renderers/image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAO,EAML,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/renderers/image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAO,EAML,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAkB5D,KAAK,UAAU,GAAG;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,UAAU,CA6MhC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/renderers/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAOtB,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/renderers/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAOtB,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAgD9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/renderers/list.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKhF,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAQ9B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAoBtC,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/renderers/list.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKhF,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAQ9B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAoBtC,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAyB9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../src/renderers/math.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAA4B,MAAM,OAAO,CAAC;AAE1D,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../../src/renderers/math.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAA4B,MAAM,OAAO,CAAC;AAE1D,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AA0BtB,KAAK,eAAe,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AA6MF,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CA6B1C,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAuCxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/use-markdown-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAO1D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,wBAAgB,kBAAkB;;;;;;
|
|
1
|
+
{"version":3,"file":"use-markdown-stream.d.ts","sourceRoot":"","sources":["../../../src/use-markdown-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAO1D,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,wBAAgB,kBAAkB;;;;;;6BAiCY,MAAM;kBAMjB,MAAM;oBAIJ,MAAM,MAAM,MAAM,QAAQ,MAAM;EAcpE;AAED,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;0BAgBzC,MAAM;;;;;;6BA1CoB,MAAM;kBAMjB,MAAM;oBAIJ,MAAM,MAAM,MAAM,QAAQ,MAAM;EAqDpE"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type UrlSafetyOptions = {
|
|
2
|
+
allowedProtocols?: readonly string[];
|
|
3
|
+
allowedHosts?: readonly string[];
|
|
4
|
+
};
|
|
1
5
|
export declare const normalizeLinkHref: (href: string) => string | null;
|
|
2
6
|
export declare const getAllowedExternalHref: (href: string) => string | null;
|
|
7
|
+
export declare const getAllowedImageHref: (href: string, options?: UrlSafetyOptions) => string | null;
|
|
3
8
|
//# sourceMappingURL=link-security.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-security.d.ts","sourceRoot":"","sources":["../../../../src/utils/link-security.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link-security.d.ts","sourceRoot":"","sources":["../../../../src/utils/link-security.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAIzD,CAAC;AA0BF,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAU9D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,MAAM,MAAM,EACZ,UAAU,gBAAgB,KACzB,MAAM,GAAG,IAwBX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "High-performance Markdown parser for React Native using Nitro Modules and md4c",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -93,17 +93,17 @@
|
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@size-limit/preset-small-lib": "^11.0.0",
|
|
96
|
-
"@types/react": "~19.2.
|
|
96
|
+
"@types/react": "~19.2.15",
|
|
97
97
|
"@types/react-test-renderer": "^19.1.0",
|
|
98
98
|
"react-native-builder-bob": "^0.41.0",
|
|
99
|
-
"react-test-renderer": "19.2.
|
|
99
|
+
"react-test-renderer": "19.2.3",
|
|
100
100
|
"size-limit": "^11.0.0",
|
|
101
|
-
"typescript": "
|
|
101
|
+
"typescript": "~6.0.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"react": "*",
|
|
105
105
|
"react-native": ">=0.75.0",
|
|
106
|
-
"react-native-nitro-modules": ">=0.35.
|
|
106
|
+
"react-native-nitro-modules": ">=0.35.7",
|
|
107
107
|
"ratex-react-native": ">=0.1.4"
|
|
108
108
|
},
|
|
109
109
|
"codegenConfig": {
|
|
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package["license"]
|
|
11
11
|
s.authors = package["author"]
|
|
12
12
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
13
|
+
s.platforms = { :ios => "16.4" }
|
|
14
14
|
s.source = { :git => "https://github.com/JoaoPauloCMarra/react-native-nitro-markdown.git", :tag => "v#{s.version}" }
|
|
15
15
|
s.module_name = "NitroMarkdown"
|
|
16
16
|
|
package/src/MarkdownContext.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type StylingStrategy,
|
|
13
13
|
} from "./theme";
|
|
14
14
|
import type { CodeHighlighter } from "./utils/code-highlight";
|
|
15
|
+
import type { UrlSafetyOptions } from "./utils/link-security";
|
|
15
16
|
|
|
16
17
|
export type NodeRendererProps = {
|
|
17
18
|
node: MarkdownNode;
|
|
@@ -72,19 +73,60 @@ export type TaskListItemRendererProps = {
|
|
|
72
73
|
checked: boolean;
|
|
73
74
|
} & BaseCustomRendererProps;
|
|
74
75
|
|
|
75
|
-
export type
|
|
76
|
+
export type MathRendererProps = {
|
|
77
|
+
content: string;
|
|
78
|
+
} & BaseCustomRendererProps;
|
|
79
|
+
|
|
80
|
+
export type CustomRendererProps = EnhancedRendererProps;
|
|
76
81
|
|
|
77
82
|
export type LinkPressHandler = (
|
|
78
83
|
href: string,
|
|
79
84
|
) => void | boolean | Promise<void | boolean>;
|
|
80
85
|
|
|
81
|
-
export type CustomRenderer
|
|
82
|
-
|
|
83
|
-
) => ReactNode | undefined;
|
|
86
|
+
export type CustomRenderer<
|
|
87
|
+
Props extends EnhancedRendererProps = EnhancedRendererProps,
|
|
88
|
+
> = (props: Props) => ReactNode | undefined;
|
|
89
|
+
|
|
90
|
+
export type CustomRendererPropsByNode = {
|
|
91
|
+
document: CustomRendererProps;
|
|
92
|
+
heading: HeadingRendererProps;
|
|
93
|
+
paragraph: CustomRendererProps;
|
|
94
|
+
text: CustomRendererProps;
|
|
95
|
+
bold: CustomRendererProps;
|
|
96
|
+
italic: CustomRendererProps;
|
|
97
|
+
strikethrough: CustomRendererProps;
|
|
98
|
+
link: LinkRendererProps;
|
|
99
|
+
image: ImageRendererProps;
|
|
100
|
+
code_inline: InlineCodeRendererProps;
|
|
101
|
+
code_block: CodeBlockRendererProps;
|
|
102
|
+
blockquote: CustomRendererProps;
|
|
103
|
+
horizontal_rule: CustomRendererProps;
|
|
104
|
+
line_break: CustomRendererProps;
|
|
105
|
+
soft_break: CustomRendererProps;
|
|
106
|
+
table: CustomRendererProps;
|
|
107
|
+
table_head: CustomRendererProps;
|
|
108
|
+
table_body: CustomRendererProps;
|
|
109
|
+
table_row: CustomRendererProps;
|
|
110
|
+
table_cell: CustomRendererProps;
|
|
111
|
+
list: ListRendererProps;
|
|
112
|
+
list_item: CustomRendererProps;
|
|
113
|
+
task_list_item: TaskListItemRendererProps;
|
|
114
|
+
math_inline: MathRendererProps;
|
|
115
|
+
math_block: MathRendererProps;
|
|
116
|
+
html_block: CustomRendererProps;
|
|
117
|
+
html_inline: CustomRendererProps;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type CustomRenderers = Partial<{
|
|
121
|
+
[Type in MarkdownNode["type"]]: CustomRenderer<
|
|
122
|
+
CustomRendererPropsByNode[Type]
|
|
123
|
+
>;
|
|
124
|
+
}>;
|
|
84
125
|
|
|
85
|
-
export type
|
|
86
|
-
|
|
87
|
-
|
|
126
|
+
export type TableOptions = {
|
|
127
|
+
minColumnWidth?: number;
|
|
128
|
+
measurementStabilizeMs?: number;
|
|
129
|
+
};
|
|
88
130
|
|
|
89
131
|
export type MarkdownContextValue = {
|
|
90
132
|
renderers: CustomRenderers;
|
|
@@ -93,10 +135,8 @@ export type MarkdownContextValue = {
|
|
|
93
135
|
stylingStrategy: StylingStrategy;
|
|
94
136
|
onLinkPress?: LinkPressHandler;
|
|
95
137
|
highlightCode?: boolean | CodeHighlighter;
|
|
96
|
-
tableOptions?:
|
|
97
|
-
|
|
98
|
-
measurementStabilizeMs?: number;
|
|
99
|
-
};
|
|
138
|
+
tableOptions?: TableOptions;
|
|
139
|
+
imageOptions?: UrlSafetyOptions;
|
|
100
140
|
};
|
|
101
141
|
|
|
102
142
|
export const MarkdownContext = createContext<MarkdownContextValue>({
|
package/src/headless.ts
CHANGED
|
@@ -15,44 +15,49 @@ import type { MarkdownParser, ParserOptions } from "./Markdown.nitro";
|
|
|
15
15
|
|
|
16
16
|
export type { ParserOptions } from "./Markdown.nitro";
|
|
17
17
|
|
|
18
|
+
export type MarkdownNodeType =
|
|
19
|
+
| "document"
|
|
20
|
+
| "heading"
|
|
21
|
+
| "paragraph"
|
|
22
|
+
| "text"
|
|
23
|
+
| "bold"
|
|
24
|
+
| "italic"
|
|
25
|
+
| "strikethrough"
|
|
26
|
+
| "link"
|
|
27
|
+
| "image"
|
|
28
|
+
| "code_inline"
|
|
29
|
+
| "code_block"
|
|
30
|
+
| "blockquote"
|
|
31
|
+
| "horizontal_rule"
|
|
32
|
+
| "line_break"
|
|
33
|
+
| "soft_break"
|
|
34
|
+
| "table"
|
|
35
|
+
| "table_head"
|
|
36
|
+
| "table_body"
|
|
37
|
+
| "table_row"
|
|
38
|
+
| "table_cell"
|
|
39
|
+
| "list"
|
|
40
|
+
| "list_item"
|
|
41
|
+
| "task_list_item"
|
|
42
|
+
| "math_inline"
|
|
43
|
+
| "math_block"
|
|
44
|
+
| "html_block"
|
|
45
|
+
| "html_inline";
|
|
46
|
+
|
|
47
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
48
|
+
export type TableCellAlign = "left" | "center" | "right";
|
|
49
|
+
|
|
18
50
|
/**
|
|
19
51
|
* Represents a node in the Markdown AST (Abstract Syntax Tree).
|
|
20
52
|
* Each node has a type and optional properties depending on the node type.
|
|
21
53
|
*/
|
|
22
54
|
export type MarkdownNode = {
|
|
23
55
|
/** The type of markdown element this node represents. Used to decide how to render the node. */
|
|
24
|
-
type:
|
|
25
|
-
| "document"
|
|
26
|
-
| "heading"
|
|
27
|
-
| "paragraph"
|
|
28
|
-
| "text"
|
|
29
|
-
| "bold"
|
|
30
|
-
| "italic"
|
|
31
|
-
| "strikethrough"
|
|
32
|
-
| "link"
|
|
33
|
-
| "image"
|
|
34
|
-
| "code_inline"
|
|
35
|
-
| "code_block"
|
|
36
|
-
| "blockquote"
|
|
37
|
-
| "horizontal_rule"
|
|
38
|
-
| "line_break"
|
|
39
|
-
| "soft_break"
|
|
40
|
-
| "table"
|
|
41
|
-
| "table_head"
|
|
42
|
-
| "table_body"
|
|
43
|
-
| "table_row"
|
|
44
|
-
| "table_cell"
|
|
45
|
-
| "list"
|
|
46
|
-
| "list_item"
|
|
47
|
-
| "task_list_item"
|
|
48
|
-
| "math_inline"
|
|
49
|
-
| "math_block"
|
|
50
|
-
| "html_block"
|
|
51
|
-
| "html_inline";
|
|
56
|
+
type: MarkdownNodeType;
|
|
52
57
|
/** Text content for text, code, and similar nodes. */
|
|
53
58
|
content?: string;
|
|
54
59
|
/** Heading level (1-6) for heading nodes. */
|
|
55
|
-
level?:
|
|
60
|
+
level?: HeadingLevel;
|
|
56
61
|
/** URL for link and image nodes. */
|
|
57
62
|
href?: string;
|
|
58
63
|
/** Title attribute for link and image nodes. */
|
|
@@ -70,7 +75,7 @@ export type MarkdownNode = {
|
|
|
70
75
|
/** Whether a table cell is part of the header row. */
|
|
71
76
|
isHeader?: boolean;
|
|
72
77
|
/** Text alignment for table cells: 'left', 'center', or 'right'. */
|
|
73
|
-
align?:
|
|
78
|
+
align?: TableCellAlign;
|
|
74
79
|
/** Source start offset in original markdown text (when provided by native parser). */
|
|
75
80
|
beg?: number;
|
|
76
81
|
/** Source end offset in original markdown text (when provided by native parser). */
|
|
@@ -86,7 +91,6 @@ const createEmptyDocument = (): MarkdownNode => ({
|
|
|
86
91
|
|
|
87
92
|
function reportNativeParserFailure(methodName: string, error?: unknown): void {
|
|
88
93
|
if (__DEV__) {
|
|
89
|
-
// eslint-disable-next-line no-console
|
|
90
94
|
console.error(
|
|
91
95
|
`[NitroMarkdown] ${methodName}: native parser failed.`,
|
|
92
96
|
error,
|
|
@@ -100,7 +104,6 @@ try {
|
|
|
100
104
|
NitroModules.createHybridObject<MarkdownParser>("MarkdownParser");
|
|
101
105
|
} catch (e) {
|
|
102
106
|
if (__DEV__) {
|
|
103
|
-
// eslint-disable-next-line no-console
|
|
104
107
|
console.error("[NitroMarkdown] Failed to create native MarkdownParser:", e);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
@@ -143,7 +146,6 @@ export function parseMarkdown(
|
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
if (__DEV__) {
|
|
146
|
-
// eslint-disable-next-line no-console
|
|
147
149
|
console.error(
|
|
148
150
|
"[NitroMarkdown] parseMarkdown: native parser unavailable — check installation.",
|
|
149
151
|
);
|
|
@@ -175,7 +177,6 @@ export function parseMarkdownWithOptions(
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
if (__DEV__) {
|
|
178
|
-
// eslint-disable-next-line no-console
|
|
179
180
|
console.error(
|
|
180
181
|
"[NitroMarkdown] parseMarkdownWithOptions: native parser unavailable — check installation.",
|
|
181
182
|
);
|
package/src/index.ts
CHANGED
|
@@ -8,13 +8,22 @@ export {
|
|
|
8
8
|
getFlattenedText,
|
|
9
9
|
stripSourceOffsets,
|
|
10
10
|
} from "./headless";
|
|
11
|
-
export type {
|
|
11
|
+
export type {
|
|
12
|
+
MarkdownNode,
|
|
13
|
+
MarkdownNodeType,
|
|
14
|
+
HeadingLevel,
|
|
15
|
+
TableCellAlign,
|
|
16
|
+
ParserOptions,
|
|
17
|
+
MarkdownParser,
|
|
18
|
+
} from "./headless";
|
|
12
19
|
|
|
13
20
|
export { Markdown } from "./markdown";
|
|
14
21
|
export type {
|
|
15
22
|
MarkdownProps,
|
|
16
23
|
AstTransform,
|
|
17
24
|
MarkdownPlugin,
|
|
25
|
+
MarkdownErrorPhase,
|
|
26
|
+
MarkdownParseCompleteResult,
|
|
18
27
|
MarkdownVirtualizationOptions,
|
|
19
28
|
} from "./markdown";
|
|
20
29
|
export { MarkdownStream } from "./markdown-stream";
|
|
@@ -35,8 +44,11 @@ export type {
|
|
|
35
44
|
InlineCodeRendererProps,
|
|
36
45
|
ListRendererProps,
|
|
37
46
|
TaskListItemRendererProps,
|
|
47
|
+
MathRendererProps,
|
|
38
48
|
LinkPressHandler,
|
|
39
49
|
MarkdownContextValue,
|
|
50
|
+
CustomRendererPropsByNode,
|
|
51
|
+
TableOptions,
|
|
40
52
|
} from "./MarkdownContext";
|
|
41
53
|
|
|
42
54
|
export {
|
|
@@ -72,3 +84,4 @@ export type {
|
|
|
72
84
|
CodeHighlighter,
|
|
73
85
|
} from "./utils/code-highlight";
|
|
74
86
|
export { defaultHighlighter } from "./utils/code-highlight";
|
|
87
|
+
export type { UrlSafetyOptions } from "./utils/link-security";
|
package/src/markdown-stream.tsx
CHANGED
|
@@ -58,6 +58,15 @@ const resolveStreamText = ({
|
|
|
58
58
|
return session.getAllText();
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
function warnStreamError(message: string, error: unknown): void {
|
|
62
|
+
if (!__DEV__) return;
|
|
63
|
+
|
|
64
|
+
const warn = Reflect.get(console, "warn");
|
|
65
|
+
if (typeof warn === "function") {
|
|
66
|
+
warn.call(console, message, error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
export type MarkdownStreamProps = {
|
|
62
71
|
/**
|
|
63
72
|
* The active MarkdownSession to stream content from.
|
|
@@ -124,12 +133,20 @@ export const MarkdownStream: FC<MarkdownStreamProps> = ({
|
|
|
124
133
|
const forceFullSyncRef = useRef(false);
|
|
125
134
|
const updateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
126
135
|
const rafRef = useRef<number | null>(null);
|
|
136
|
+
const mountedRef = useRef(true);
|
|
127
137
|
const allowIncremental = incrementalParsing && !hasBeforeParsePlugins;
|
|
128
138
|
|
|
129
139
|
useEffect(() => {
|
|
130
140
|
renderStateRef.current = renderState;
|
|
131
141
|
}, [renderState]);
|
|
132
142
|
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
mountedRef.current = true;
|
|
145
|
+
return () => {
|
|
146
|
+
mountedRef.current = false;
|
|
147
|
+
};
|
|
148
|
+
}, []);
|
|
149
|
+
|
|
133
150
|
useEffect(() => {
|
|
134
151
|
const initialText = session.getAllText();
|
|
135
152
|
const initialState = {
|
|
@@ -185,9 +202,11 @@ export const MarkdownStream: FC<MarkdownStreamProps> = ({
|
|
|
185
202
|
ast: nextAst,
|
|
186
203
|
};
|
|
187
204
|
renderStateRef.current = nextState;
|
|
205
|
+
if (!mountedRef.current) return;
|
|
188
206
|
|
|
189
207
|
if (useTransitionUpdates) {
|
|
190
208
|
startTransition(() => {
|
|
209
|
+
if (!mountedRef.current) return;
|
|
191
210
|
setRenderState(nextState);
|
|
192
211
|
});
|
|
193
212
|
} else {
|
|
@@ -208,28 +227,41 @@ export const MarkdownStream: FC<MarkdownStreamProps> = ({
|
|
|
208
227
|
}
|
|
209
228
|
};
|
|
210
229
|
|
|
211
|
-
|
|
212
|
-
const nextFrom = normalizeOffset(from);
|
|
213
|
-
const nextTo = normalizeOffset(to);
|
|
230
|
+
let unsubscribe: (() => void) | null = null;
|
|
214
231
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
const currentTo = pendingToRef.current;
|
|
232
|
+
try {
|
|
233
|
+
unsubscribe = session.addListener((from, to) => {
|
|
234
|
+
const nextFrom = normalizeOffset(from);
|
|
235
|
+
const nextTo = normalizeOffset(to);
|
|
220
236
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
if (nextFrom === null || nextTo === null || nextTo < nextFrom) {
|
|
238
|
+
forceFullSyncRef.current = true;
|
|
239
|
+
} else {
|
|
240
|
+
const currentFrom = pendingFromRef.current;
|
|
241
|
+
const currentTo = pendingToRef.current;
|
|
226
242
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
243
|
+
pendingFromRef.current =
|
|
244
|
+
currentFrom === null ? nextFrom : Math.min(currentFrom, nextFrom);
|
|
245
|
+
pendingToRef.current =
|
|
246
|
+
currentTo === null ? nextTo : Math.max(currentTo, nextTo);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
pendingUpdateRef.current = true;
|
|
250
|
+
scheduleFlush();
|
|
251
|
+
});
|
|
252
|
+
} catch (error) {
|
|
253
|
+
warnStreamError("[NitroMarkdown] Failed to subscribe to stream:", error);
|
|
254
|
+
}
|
|
230
255
|
|
|
231
256
|
return () => {
|
|
232
|
-
|
|
257
|
+
try {
|
|
258
|
+
unsubscribe?.();
|
|
259
|
+
} catch (error) {
|
|
260
|
+
warnStreamError(
|
|
261
|
+
"[NitroMarkdown] Failed to unsubscribe from stream:",
|
|
262
|
+
error,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
233
265
|
if (updateTimerRef.current) {
|
|
234
266
|
clearTimeout(updateTimerRef.current);
|
|
235
267
|
updateTimerRef.current = null;
|