@incremark/react 0.3.3 → 0.3.5
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.en.md +2 -2
- package/README.md +11 -18
- package/dist/index.d.ts +13 -22
- package/dist/index.js +60 -76
- package/package.json +6 -6
package/README.en.md
CHANGED
|
@@ -17,7 +17,7 @@ React 18+ integration library for Incremark, providing high-performance streamin
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
pnpm add @incremark/
|
|
20
|
+
pnpm add @incremark/react @incremark/theme
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Quick Start
|
|
@@ -27,7 +27,7 @@ pnpm add @incremark/core @incremark/react
|
|
|
27
27
|
```tsx
|
|
28
28
|
import { useState } from 'react'
|
|
29
29
|
import { IncremarkContent } from '@incremark/react'
|
|
30
|
-
import '@incremark/
|
|
30
|
+
import '@incremark/theme/styles.css'
|
|
31
31
|
|
|
32
32
|
function App() {
|
|
33
33
|
const [content, setContent] = useState('')
|
package/README.md
CHANGED
|
@@ -15,44 +15,37 @@ Incremark 的 React 18+ 集成库。
|
|
|
15
15
|
## 安装
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
pnpm add @incremark/
|
|
18
|
+
pnpm add @incremark/react @incremark/theme
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## 快速开始
|
|
22
22
|
|
|
23
|
-
**1. 引入样式**
|
|
24
|
-
|
|
25
23
|
```tsx
|
|
26
|
-
import '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
**2. 在组件中使用**
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
import { useIncremark, Incremark } from '@incremark/react'
|
|
33
|
-
import '@incremark/react/styles.css'
|
|
24
|
+
import { useState } from 'react'
|
|
25
|
+
import { IncremarkContent } from '@incremark/react'
|
|
26
|
+
import '@incremark/theme/styles.css'
|
|
34
27
|
|
|
35
28
|
function App() {
|
|
36
|
-
const
|
|
29
|
+
const [content, setContent] = useState('')
|
|
30
|
+
const [isFinished, setIsFinished] = useState(false)
|
|
37
31
|
|
|
38
32
|
async function handleStream(stream: ReadableStream) {
|
|
39
|
-
reset()
|
|
40
33
|
const reader = stream.getReader()
|
|
41
34
|
const decoder = new TextDecoder()
|
|
42
|
-
|
|
35
|
+
|
|
43
36
|
while (true) {
|
|
44
37
|
const { done, value } = await reader.read()
|
|
45
38
|
if (done) break
|
|
46
|
-
|
|
39
|
+
setContent(prev => prev + decoder.decode(value))
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
|
|
42
|
+
setIsFinished(true)
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
return (
|
|
53
46
|
<>
|
|
54
47
|
<button onClick={() => handleStream(stream)}>开始</button>
|
|
55
|
-
<
|
|
48
|
+
<IncremarkContent content={content} isFinished={isFinished} />
|
|
56
49
|
</>
|
|
57
50
|
)
|
|
58
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ export { AnimationEffect, BlockTransformer, DisplayBlock, IncrementalUpdate, Par
|
|
|
3
3
|
import React$1, { ReactNode, ComponentType } from 'react';
|
|
4
4
|
import { Definition, FootnoteDefinition, RootContent, PhrasingContent } from 'mdast';
|
|
5
5
|
export { Blockquote, Code, Definition, FootnoteDefinition, HTML, Heading, Image, ImageReference, InlineCode, Link, LinkReference, List, ListItem, Root as MdastRoot, Paragraph, Parent, PhrasingContent, Table, TableCell, Text, ThematicBreak } from 'mdast';
|
|
6
|
-
import
|
|
7
|
-
import { DevToolsOptions } from '@incremark/devtools';
|
|
6
|
+
import { IncremarkDevTools } from '@incremark/devtools';
|
|
8
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
9
8
|
import { IncremarkLocale } from '@incremark/shared';
|
|
10
9
|
export { IncremarkLocale, en, zhCN } from '@incremark/shared';
|
|
@@ -211,25 +210,6 @@ declare function useIncremark(options?: UseIncremarkOptions): {
|
|
|
211
210
|
};
|
|
212
211
|
type UseIncremarkReturn = ReturnType<typeof useIncremark>;
|
|
213
212
|
|
|
214
|
-
interface UseDevToolsOptions extends DevToolsOptions {
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* React DevTools 一行接入
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```tsx
|
|
221
|
-
* import { useIncremark, useDevTools } from '@incremark/react'
|
|
222
|
-
*
|
|
223
|
-
* function App() {
|
|
224
|
-
* const incremark = useIncremark()
|
|
225
|
-
* useDevTools(incremark) // 就这一行!
|
|
226
|
-
*
|
|
227
|
-
* return <div>...</div>
|
|
228
|
-
* }
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
declare function useDevTools(incremark: UseIncremarkReturn, options?: UseDevToolsOptions): _incremark_devtools.IncremarkDevTools | null;
|
|
232
|
-
|
|
233
213
|
interface UseBlockTransformerOptions extends Omit<TransformerOptions, 'onChange'> {
|
|
234
214
|
}
|
|
235
215
|
interface UseBlockTransformerReturn<T = unknown> {
|
|
@@ -344,6 +324,12 @@ interface IncremarkContentProps {
|
|
|
344
324
|
incremarkOptions?: UseIncremarkOptions;
|
|
345
325
|
pendingClass?: string;
|
|
346
326
|
showBlockStatus?: boolean;
|
|
327
|
+
/** DevTools 实例,传入后组件会自动注册 parser */
|
|
328
|
+
devtools?: IncremarkDevTools;
|
|
329
|
+
/** DevTools 中显示的 parser ID,默认自动生成 */
|
|
330
|
+
devtoolsId?: string;
|
|
331
|
+
/** DevTools 中显示的 parser 标签,默认使用 ID */
|
|
332
|
+
devtoolsLabel?: string;
|
|
347
333
|
}
|
|
348
334
|
|
|
349
335
|
/**
|
|
@@ -420,6 +406,11 @@ declare const Incremark: React$1.FC<IncremarkProps>;
|
|
|
420
406
|
*
|
|
421
407
|
* // 增量更新内容
|
|
422
408
|
* <IncremarkContent content={partialContent} isFinished={false} />
|
|
409
|
+
*
|
|
410
|
+
* // 使用 DevTools
|
|
411
|
+
* const devtools = createDevTools()
|
|
412
|
+
* devtools.mount()
|
|
413
|
+
* <IncremarkContent content={content} devtools={devtools} devtoolsId="msg-1" />
|
|
423
414
|
* ```
|
|
424
415
|
*/
|
|
425
416
|
declare const IncremarkContent: React$1.FC<IncremarkContentProps>;
|
|
@@ -644,4 +635,4 @@ interface ThemeProviderProps {
|
|
|
644
635
|
*/
|
|
645
636
|
declare const ThemeProvider: React$1.FC<ThemeProviderProps>;
|
|
646
637
|
|
|
647
|
-
export { AutoScrollContainer, type AutoScrollContainerProps, type AutoScrollContainerRef, ConfigProvider, type DefinitionsContextValue, DefinitionsProvider, type DefinitionsProviderProps, type HtmlElementNode, Incremark, IncremarkContainerProvider, type IncremarkContainerProviderProps, IncremarkContent, type IncremarkContentProps, IncremarkFootnotes, IncremarkHtmlElement, type IncremarkHtmlElementProps, IncremarkInline, type IncremarkInlineProps, type IncremarkProps, IncremarkRenderer, type IncremarkRendererProps, ThemeProvider, type ThemeProviderProps, type TypewriterControls, type TypewriterOptions, type UseBlockTransformerOptions, type UseBlockTransformerReturn, type
|
|
638
|
+
export { AutoScrollContainer, type AutoScrollContainerProps, type AutoScrollContainerRef, ConfigProvider, type DefinitionsContextValue, DefinitionsProvider, type DefinitionsProviderProps, type HtmlElementNode, Incremark, IncremarkContainerProvider, type IncremarkContainerProviderProps, IncremarkContent, type IncremarkContentProps, IncremarkFootnotes, IncremarkHtmlElement, type IncremarkHtmlElementProps, IncremarkInline, type IncremarkInlineProps, type IncremarkProps, IncremarkRenderer, type IncremarkRendererProps, ThemeProvider, type ThemeProviderProps, type TypewriterControls, type TypewriterOptions, type UseBlockTransformerOptions, type UseBlockTransformerReturn, type UseIncremarkOptions, type UseIncremarkReturn, type UseLocaleReturn, useBlockTransformer, useDefinitions, useIncremark, useLocale };
|
package/dist/index.js
CHANGED
|
@@ -496,40 +496,8 @@ function useIncremark(options = {}) {
|
|
|
496
496
|
};
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
// src/hooks/useDevTools.ts
|
|
500
|
-
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
501
|
-
import { createDevTools } from "@incremark/devtools";
|
|
502
|
-
function useDevTools(incremark, options = {}) {
|
|
503
|
-
const devtoolsRef = useRef3(null);
|
|
504
|
-
const optionsRef = useRef3(options);
|
|
505
|
-
useEffect3(() => {
|
|
506
|
-
const devtools = createDevTools(optionsRef.current);
|
|
507
|
-
devtoolsRef.current = devtools;
|
|
508
|
-
incremark.parser.setOnChange((state) => {
|
|
509
|
-
const blocks = [
|
|
510
|
-
...state.completedBlocks,
|
|
511
|
-
...state.pendingBlocks
|
|
512
|
-
];
|
|
513
|
-
devtools.update({
|
|
514
|
-
blocks,
|
|
515
|
-
completedBlocks: state.completedBlocks,
|
|
516
|
-
pendingBlocks: state.pendingBlocks,
|
|
517
|
-
markdown: state.markdown,
|
|
518
|
-
ast: state.ast,
|
|
519
|
-
isLoading: state.pendingBlocks.length > 0
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
devtools.mount();
|
|
523
|
-
return () => {
|
|
524
|
-
devtools.unmount();
|
|
525
|
-
incremark.parser.setOnChange(void 0);
|
|
526
|
-
};
|
|
527
|
-
}, [incremark.parser]);
|
|
528
|
-
return devtoolsRef.current;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
499
|
// src/hooks/useBlockTransformer.ts
|
|
532
|
-
import { useState as useState4, useCallback as useCallback4, useRef as
|
|
500
|
+
import { useState as useState4, useCallback as useCallback4, useRef as useRef3, useEffect as useEffect3 } from "react";
|
|
533
501
|
import {
|
|
534
502
|
createBlockTransformer as createBlockTransformer2
|
|
535
503
|
} from "@incremark/core";
|
|
@@ -538,7 +506,7 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
538
506
|
const [isProcessing, setIsProcessing] = useState4(false);
|
|
539
507
|
const [isPaused, setIsPaused] = useState4(false);
|
|
540
508
|
const [effect, setEffect] = useState4(options.effect ?? "none");
|
|
541
|
-
const transformerRef =
|
|
509
|
+
const transformerRef = useRef3(null);
|
|
542
510
|
if (!transformerRef.current) {
|
|
543
511
|
transformerRef.current = createBlockTransformer2({
|
|
544
512
|
...options,
|
|
@@ -550,7 +518,7 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
550
518
|
});
|
|
551
519
|
}
|
|
552
520
|
const transformer = transformerRef.current;
|
|
553
|
-
|
|
521
|
+
useEffect3(() => {
|
|
554
522
|
transformer.push(sourceBlocks);
|
|
555
523
|
const currentDisplaying = displayBlocks.find((b) => !b.isDisplayComplete);
|
|
556
524
|
if (currentDisplaying) {
|
|
@@ -560,7 +528,7 @@ function useBlockTransformer(sourceBlocks, options = {}) {
|
|
|
560
528
|
}
|
|
561
529
|
}
|
|
562
530
|
}, [sourceBlocks, transformer]);
|
|
563
|
-
|
|
531
|
+
useEffect3(() => {
|
|
564
532
|
return () => {
|
|
565
533
|
transformer.destroy();
|
|
566
534
|
};
|
|
@@ -795,7 +763,7 @@ var IncremarkHtmlElement = ({ node }) => {
|
|
|
795
763
|
};
|
|
796
764
|
|
|
797
765
|
// src/components/IncremarkMath.tsx
|
|
798
|
-
import { useState as useState5, useEffect as
|
|
766
|
+
import { useState as useState5, useEffect as useEffect4, useRef as useRef4, useCallback as useCallback5 } from "react";
|
|
799
767
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
800
768
|
var IncremarkMath = ({
|
|
801
769
|
node,
|
|
@@ -803,8 +771,8 @@ var IncremarkMath = ({
|
|
|
803
771
|
}) => {
|
|
804
772
|
const [renderedHtml, setRenderedHtml] = useState5("");
|
|
805
773
|
const [isLoading, setIsLoading] = useState5(false);
|
|
806
|
-
const katexRef =
|
|
807
|
-
const renderTimerRef =
|
|
774
|
+
const katexRef = useRef4(null);
|
|
775
|
+
const renderTimerRef = useRef4(null);
|
|
808
776
|
const isInline = node.type === "inlineMath";
|
|
809
777
|
const formula = node.value;
|
|
810
778
|
const doRender = useCallback5(async () => {
|
|
@@ -840,10 +808,10 @@ var IncremarkMath = ({
|
|
|
840
808
|
doRender();
|
|
841
809
|
}, renderDelay);
|
|
842
810
|
}, [formula, renderDelay, doRender]);
|
|
843
|
-
|
|
811
|
+
useEffect4(() => {
|
|
844
812
|
scheduleRender();
|
|
845
813
|
}, [scheduleRender]);
|
|
846
|
-
|
|
814
|
+
useEffect4(() => {
|
|
847
815
|
return () => {
|
|
848
816
|
if (renderTimerRef.current) {
|
|
849
817
|
clearTimeout(renderTimerRef.current);
|
|
@@ -1002,7 +970,7 @@ var IncremarkParagraph = ({ node }) => {
|
|
|
1002
970
|
import React9 from "react";
|
|
1003
971
|
|
|
1004
972
|
// src/components/IncremarkCodeMermaid.tsx
|
|
1005
|
-
import { useState as useState6, useEffect as
|
|
973
|
+
import { useState as useState6, useEffect as useEffect5, useRef as useRef5, useCallback as useCallback6 } from "react";
|
|
1006
974
|
import { GravityMermaid, LucideCode, LucideEye, LucideCopy, LucideCopyCheck } from "@incremark/icons";
|
|
1007
975
|
import { isClipboardAvailable } from "@incremark/shared";
|
|
1008
976
|
|
|
@@ -1034,9 +1002,9 @@ var IncremarkCodeMermaid = ({
|
|
|
1034
1002
|
const [mermaidSvg, setMermaidSvg] = useState6("");
|
|
1035
1003
|
const [mermaidLoading, setMermaidLoading] = useState6(false);
|
|
1036
1004
|
const [mermaidViewMode, setMermaidViewMode] = useState6("preview");
|
|
1037
|
-
const mermaidRef =
|
|
1038
|
-
const mermaidTimerRef =
|
|
1039
|
-
const copyTimeoutRef =
|
|
1005
|
+
const mermaidRef = useRef5(null);
|
|
1006
|
+
const mermaidTimerRef = useRef5(null);
|
|
1007
|
+
const copyTimeoutRef = useRef5(null);
|
|
1040
1008
|
const code = node.value;
|
|
1041
1009
|
const toggleMermaidView = useCallback6(() => {
|
|
1042
1010
|
setMermaidViewMode((prev) => prev === "preview" ? "source" : "preview");
|
|
@@ -1086,10 +1054,10 @@ var IncremarkCodeMermaid = ({
|
|
|
1086
1054
|
doRenderMermaid();
|
|
1087
1055
|
}, mermaidDelay);
|
|
1088
1056
|
}, [code, mermaidDelay, doRenderMermaid]);
|
|
1089
|
-
|
|
1057
|
+
useEffect5(() => {
|
|
1090
1058
|
scheduleRenderMermaid();
|
|
1091
1059
|
}, [scheduleRenderMermaid]);
|
|
1092
|
-
|
|
1060
|
+
useEffect5(() => {
|
|
1093
1061
|
return () => {
|
|
1094
1062
|
if (mermaidTimerRef.current) {
|
|
1095
1063
|
clearTimeout(mermaidTimerRef.current);
|
|
@@ -1136,7 +1104,7 @@ var IncremarkCodeMermaid = ({
|
|
|
1136
1104
|
};
|
|
1137
1105
|
|
|
1138
1106
|
// src/components/IncremarkCodeDefault.tsx
|
|
1139
|
-
import { useState as useState8, useEffect as
|
|
1107
|
+
import { useState as useState8, useEffect as useEffect7, useCallback as useCallback7, useRef as useRef7, useMemo as useMemo5 } from "react";
|
|
1140
1108
|
import { LucideCopy as LucideCopy2, LucideCopyCheck as LucideCopyCheck2 } from "@incremark/icons";
|
|
1141
1109
|
import { isClipboardAvailable as isClipboardAvailable2 } from "@incremark/shared";
|
|
1142
1110
|
|
|
@@ -1899,14 +1867,14 @@ function getTokenStyleObject(token) {
|
|
|
1899
1867
|
}
|
|
1900
1868
|
|
|
1901
1869
|
// src/components/CachedCodeRenderer.tsx
|
|
1902
|
-
import { useEffect as
|
|
1870
|
+
import { useEffect as useEffect6, useRef as useRef6, useState as useState7, forwardRef, useImperativeHandle } from "react";
|
|
1903
1871
|
import { CodeToTokenTransformStream } from "shiki-stream";
|
|
1904
1872
|
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1905
1873
|
var CachedCodeRenderer = forwardRef(
|
|
1906
1874
|
function CachedCodeRenderer2({ code, lang, theme, highlighter, onStreamStart, onStreamEnd, onStreamError }, ref) {
|
|
1907
1875
|
const [hasStreamError, setHasStreamError] = useState7(false);
|
|
1908
1876
|
const [tokens, setTokens] = useState7([]);
|
|
1909
|
-
const streamRef =
|
|
1877
|
+
const streamRef = useRef6({
|
|
1910
1878
|
controller: null,
|
|
1911
1879
|
index: 0,
|
|
1912
1880
|
initialized: false,
|
|
@@ -1919,7 +1887,7 @@ var CachedCodeRenderer = forwardRef(
|
|
|
1919
1887
|
streamRef.current.index = 0;
|
|
1920
1888
|
}
|
|
1921
1889
|
}));
|
|
1922
|
-
|
|
1890
|
+
useEffect6(() => {
|
|
1923
1891
|
if (streamRef.current.initialized) return;
|
|
1924
1892
|
streamRef.current.initialized = true;
|
|
1925
1893
|
const textStream = new ReadableStream({
|
|
@@ -1973,7 +1941,7 @@ var CachedCodeRenderer = forwardRef(
|
|
|
1973
1941
|
});
|
|
1974
1942
|
streamRef.current.streamConsumed = true;
|
|
1975
1943
|
}, []);
|
|
1976
|
-
|
|
1944
|
+
useEffect6(() => {
|
|
1977
1945
|
const { controller, index } = streamRef.current;
|
|
1978
1946
|
if (!controller || hasStreamError) return;
|
|
1979
1947
|
if (code.length > index) {
|
|
@@ -2032,7 +2000,7 @@ var IncremarkCodeDefault = ({
|
|
|
2032
2000
|
const shouldEnableHighlight = useMemo5(() => {
|
|
2033
2001
|
return !disableHighlight && code && code.length > 0;
|
|
2034
2002
|
}, [disableHighlight, code]);
|
|
2035
|
-
|
|
2003
|
+
useEffect7(() => {
|
|
2036
2004
|
const loadLanguageIfNeeded = async () => {
|
|
2037
2005
|
if (!shouldEnableHighlight) {
|
|
2038
2006
|
return;
|
|
@@ -2063,7 +2031,7 @@ var IncremarkCodeDefault = ({
|
|
|
2063
2031
|
};
|
|
2064
2032
|
loadLanguageIfNeeded();
|
|
2065
2033
|
}, [highlighterInfo, language, shouldEnableHighlight, initHighlighter]);
|
|
2066
|
-
const copyTimeoutRef =
|
|
2034
|
+
const copyTimeoutRef = useRef7(null);
|
|
2067
2035
|
const copyCode = useCallback7(async () => {
|
|
2068
2036
|
if (!isClipboardAvailable2()) return;
|
|
2069
2037
|
try {
|
|
@@ -2076,7 +2044,7 @@ var IncremarkCodeDefault = ({
|
|
|
2076
2044
|
} catch {
|
|
2077
2045
|
}
|
|
2078
2046
|
}, [code]);
|
|
2079
|
-
|
|
2047
|
+
useEffect7(() => {
|
|
2080
2048
|
return () => {
|
|
2081
2049
|
if (copyTimeoutRef.current) {
|
|
2082
2050
|
clearTimeout(copyTimeoutRef.current);
|
|
@@ -2497,7 +2465,8 @@ var IncremarkInternal = ({
|
|
|
2497
2465
|
};
|
|
2498
2466
|
|
|
2499
2467
|
// src/components/IncremarkContent.tsx
|
|
2500
|
-
import { useEffect as
|
|
2468
|
+
import { useEffect as useEffect8, useRef as useRef8, useMemo as useMemo6, useCallback as useCallback8 } from "react";
|
|
2469
|
+
import { generateParserId } from "@incremark/shared";
|
|
2501
2470
|
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2502
2471
|
var IncremarkContent = (props) => {
|
|
2503
2472
|
const {
|
|
@@ -2510,18 +2479,34 @@ var IncremarkContent = (props) => {
|
|
|
2510
2479
|
isFinished = false,
|
|
2511
2480
|
incremarkOptions,
|
|
2512
2481
|
showBlockStatus,
|
|
2513
|
-
pendingClass
|
|
2482
|
+
pendingClass,
|
|
2483
|
+
devtools,
|
|
2484
|
+
devtoolsId,
|
|
2485
|
+
devtoolsLabel
|
|
2514
2486
|
} = props;
|
|
2515
|
-
const initialOptionsRef =
|
|
2487
|
+
const initialOptionsRef = useRef8({
|
|
2516
2488
|
gfm: true,
|
|
2517
2489
|
htmlTree: true,
|
|
2518
2490
|
containers: true,
|
|
2519
2491
|
math: true,
|
|
2520
2492
|
...incremarkOptions
|
|
2521
2493
|
});
|
|
2522
|
-
const
|
|
2523
|
-
const
|
|
2524
|
-
|
|
2494
|
+
const incremark = useIncremark(initialOptionsRef.current);
|
|
2495
|
+
const { blocks, append, finalize, render, reset, updateOptions, isDisplayComplete, markdown, typewriter, _definitionsContextValue, parser } = incremark;
|
|
2496
|
+
const parserIdRef = useRef8(devtoolsId || generateParserId());
|
|
2497
|
+
useEffect8(() => {
|
|
2498
|
+
if (devtools) {
|
|
2499
|
+
devtools.register(parser, {
|
|
2500
|
+
id: parserIdRef.current,
|
|
2501
|
+
label: devtoolsLabel || parserIdRef.current
|
|
2502
|
+
});
|
|
2503
|
+
return () => {
|
|
2504
|
+
devtools.unregister(parserIdRef.current);
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
}, [devtools, parser, devtoolsLabel]);
|
|
2508
|
+
const prevOptionsRef = useRef8(incremarkOptions);
|
|
2509
|
+
useEffect8(() => {
|
|
2525
2510
|
const prev = prevOptionsRef.current;
|
|
2526
2511
|
const current = incremarkOptions;
|
|
2527
2512
|
if (prev === current) return;
|
|
@@ -2544,8 +2529,8 @@ var IncremarkContent = (props) => {
|
|
|
2544
2529
|
}
|
|
2545
2530
|
}, [incremarkOptions, updateOptions, typewriter]);
|
|
2546
2531
|
const isStreamMode = useMemo6(() => typeof stream === "function", [stream]);
|
|
2547
|
-
const prevContentRef =
|
|
2548
|
-
const isStreamingRef =
|
|
2532
|
+
const prevContentRef = useRef8(void 0);
|
|
2533
|
+
const isStreamingRef = useRef8(false);
|
|
2549
2534
|
const handleStreamInput = useCallback8(async () => {
|
|
2550
2535
|
if (!stream || isStreamingRef.current) return;
|
|
2551
2536
|
isStreamingRef.current = true;
|
|
@@ -2576,7 +2561,7 @@ var IncremarkContent = (props) => {
|
|
|
2576
2561
|
render(newContent);
|
|
2577
2562
|
}
|
|
2578
2563
|
}, [append, render, reset]);
|
|
2579
|
-
|
|
2564
|
+
useEffect8(() => {
|
|
2580
2565
|
if (isStreamMode) {
|
|
2581
2566
|
handleStreamInput();
|
|
2582
2567
|
} else {
|
|
@@ -2584,7 +2569,7 @@ var IncremarkContent = (props) => {
|
|
|
2584
2569
|
}
|
|
2585
2570
|
prevContentRef.current = content;
|
|
2586
2571
|
}, [content, isStreamMode, handleStreamInput, handleContentInput]);
|
|
2587
|
-
|
|
2572
|
+
useEffect8(() => {
|
|
2588
2573
|
if (isFinished && content === markdown) {
|
|
2589
2574
|
finalize();
|
|
2590
2575
|
}
|
|
@@ -2606,8 +2591,8 @@ var IncremarkContent = (props) => {
|
|
|
2606
2591
|
|
|
2607
2592
|
// src/components/AutoScrollContainer.tsx
|
|
2608
2593
|
import {
|
|
2609
|
-
useRef as
|
|
2610
|
-
useEffect as
|
|
2594
|
+
useRef as useRef9,
|
|
2595
|
+
useEffect as useEffect9,
|
|
2611
2596
|
useCallback as useCallback9,
|
|
2612
2597
|
useState as useState9,
|
|
2613
2598
|
forwardRef as forwardRef2,
|
|
@@ -2623,10 +2608,10 @@ var AutoScrollContainer = forwardRef2(
|
|
|
2623
2608
|
style,
|
|
2624
2609
|
className
|
|
2625
2610
|
}, ref) => {
|
|
2626
|
-
const containerRef =
|
|
2611
|
+
const containerRef = useRef9(null);
|
|
2627
2612
|
const [isUserScrolledUp, setIsUserScrolledUp] = useState9(false);
|
|
2628
|
-
const lastScrollTopRef =
|
|
2629
|
-
const lastScrollHeightRef =
|
|
2613
|
+
const lastScrollTopRef = useRef9(0);
|
|
2614
|
+
const lastScrollHeightRef = useRef9(0);
|
|
2630
2615
|
const isNearBottom = useCallback9(() => {
|
|
2631
2616
|
const container = containerRef.current;
|
|
2632
2617
|
if (!container) return true;
|
|
@@ -2672,14 +2657,14 @@ var AutoScrollContainer = forwardRef2(
|
|
|
2672
2657
|
lastScrollTopRef.current = scrollTop;
|
|
2673
2658
|
lastScrollHeightRef.current = scrollHeight;
|
|
2674
2659
|
}, [isNearBottom]);
|
|
2675
|
-
|
|
2660
|
+
useEffect9(() => {
|
|
2676
2661
|
const container = containerRef.current;
|
|
2677
2662
|
if (container) {
|
|
2678
2663
|
lastScrollTopRef.current = container.scrollTop;
|
|
2679
2664
|
lastScrollHeightRef.current = container.scrollHeight;
|
|
2680
2665
|
}
|
|
2681
2666
|
}, []);
|
|
2682
|
-
|
|
2667
|
+
useEffect9(() => {
|
|
2683
2668
|
const container = containerRef.current;
|
|
2684
2669
|
if (!container || !enabled) return;
|
|
2685
2670
|
const observer = new MutationObserver(() => {
|
|
@@ -2726,7 +2711,7 @@ var AutoScrollContainer = forwardRef2(
|
|
|
2726
2711
|
AutoScrollContainer.displayName = "AutoScrollContainer";
|
|
2727
2712
|
|
|
2728
2713
|
// src/ThemeProvider.tsx
|
|
2729
|
-
import { useEffect as
|
|
2714
|
+
import { useEffect as useEffect10, useRef as useRef10 } from "react";
|
|
2730
2715
|
import { applyTheme } from "@incremark/theme";
|
|
2731
2716
|
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
2732
2717
|
var ThemeProvider = ({
|
|
@@ -2734,8 +2719,8 @@ var ThemeProvider = ({
|
|
|
2734
2719
|
children,
|
|
2735
2720
|
className = ""
|
|
2736
2721
|
}) => {
|
|
2737
|
-
const containerRef =
|
|
2738
|
-
|
|
2722
|
+
const containerRef = useRef10(null);
|
|
2723
|
+
useEffect10(() => {
|
|
2739
2724
|
if (containerRef.current) {
|
|
2740
2725
|
applyTheme(containerRef.current, theme);
|
|
2741
2726
|
}
|
|
@@ -2800,7 +2785,6 @@ export {
|
|
|
2800
2785
|
thematicBreakPlugin,
|
|
2801
2786
|
useBlockTransformer,
|
|
2802
2787
|
useDefinitions,
|
|
2803
|
-
useDevTools,
|
|
2804
2788
|
useIncremark,
|
|
2805
2789
|
useLocale,
|
|
2806
2790
|
zhCNShared as zhCN
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@incremark/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "High-performance streaming markdown renderer for React ecosystem.",
|
|
6
6
|
"type": "module",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"mermaid": "^10.0.0 || ^11.0.0",
|
|
22
22
|
"katex": "^0.16.0",
|
|
23
23
|
"react": ">=18.0.0",
|
|
24
|
-
"@incremark/core": "0.3.
|
|
24
|
+
"@incremark/core": "0.3.5"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@antfu/utils": "^9.3.0",
|
|
28
28
|
"shiki": "^3.20.0",
|
|
29
29
|
"shiki-stream": "^0.1.4",
|
|
30
|
-
"@incremark/devtools": "0.3.
|
|
31
|
-
"@incremark/
|
|
32
|
-
"@incremark/
|
|
33
|
-
"@incremark/
|
|
30
|
+
"@incremark/devtools": "0.3.5",
|
|
31
|
+
"@incremark/shared": "0.3.5",
|
|
32
|
+
"@incremark/icons": "0.3.5",
|
|
33
|
+
"@incremark/theme": "0.3.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@shikijs/core": "^3.21.0",
|