@incremark/react 0.2.6 → 0.3.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.en.md +216 -47
- package/dist/index.d.ts +99 -28
- package/dist/index.js +594 -243
- package/package.json +19 -6
package/README.en.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
# @incremark/react
|
|
2
2
|
|
|
3
|
-
React 18+ integration for Incremark.
|
|
3
|
+
React 18+ integration library for Incremark, providing high-performance streaming Markdown rendering components.
|
|
4
4
|
|
|
5
5
|
**[🇨🇳 中文](./README.md)** | 🇺🇸 English
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Core Advantages
|
|
8
8
|
|
|
9
|
-
- 📦 **Out of the Box** - Provides `
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
9
|
+
- 📦 **Out of the Box** - Provides `IncremarkContent` component and `useIncremark` hook
|
|
10
|
+
- ⚡ **Extreme Performance** - Incremental parsing with O(n) complexity, dual-engine support
|
|
11
|
+
- ⌨️ **Typewriter Effect** - Built-in animation effects (fade-in, typing)
|
|
12
|
+
- 🎨 **Highly Customizable** - Custom components, code blocks, containers
|
|
13
|
+
- 🎯 **Theme System** - Built-in ThemeProvider with light/dark themes
|
|
14
|
+
- 📜 **Auto Scroll** - Built-in AutoScrollContainer component
|
|
15
|
+
- 🔧 **DevTools** - Built-in developer debugging tools
|
|
13
16
|
|
|
14
17
|
## Installation
|
|
15
18
|
|
|
@@ -19,20 +22,63 @@ pnpm add @incremark/core @incremark/react
|
|
|
19
22
|
|
|
20
23
|
## Quick Start
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
### Recommended: IncremarkContent Component
|
|
23
26
|
|
|
24
27
|
```tsx
|
|
28
|
+
import { useState } from 'react'
|
|
29
|
+
import { IncremarkContent } from '@incremark/react'
|
|
25
30
|
import '@incremark/react/styles.css'
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
const [content, setContent] = useState('')
|
|
34
|
+
const [isFinished, setIsFinished] = useState(false)
|
|
35
|
+
|
|
36
|
+
// Handle AI streaming output
|
|
37
|
+
async function handleStream(stream: ReadableStream) {
|
|
38
|
+
setContent('')
|
|
39
|
+
setIsFinished(false)
|
|
40
|
+
|
|
41
|
+
const reader = stream.getReader()
|
|
42
|
+
const decoder = new TextDecoder()
|
|
43
|
+
|
|
44
|
+
while (true) {
|
|
45
|
+
const { done, value } = await reader.read()
|
|
46
|
+
if (done) break
|
|
47
|
+
setContent(prev => prev + decoder.decode(value))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setIsFinished(true)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<button onClick={() => handleStream(stream)}>Start</button>
|
|
56
|
+
<IncremarkContent
|
|
57
|
+
content={content}
|
|
58
|
+
isFinished={isFinished}
|
|
59
|
+
incremarkOptions={{
|
|
60
|
+
gfm: true,
|
|
61
|
+
math: true,
|
|
62
|
+
containers: true,
|
|
63
|
+
htmlTree: true
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
</>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
26
69
|
```
|
|
27
70
|
|
|
28
|
-
|
|
71
|
+
### Advanced: useIncremark Hook
|
|
29
72
|
|
|
30
73
|
```tsx
|
|
31
74
|
import { useIncremark, Incremark } from '@incremark/react'
|
|
32
75
|
import '@incremark/react/styles.css'
|
|
33
76
|
|
|
34
77
|
function App() {
|
|
35
|
-
const { blocks, append, finalize, reset } = useIncremark({
|
|
78
|
+
const { blocks, append, finalize, reset } = useIncremark({
|
|
79
|
+
gfm: true,
|
|
80
|
+
math: true
|
|
81
|
+
})
|
|
36
82
|
|
|
37
83
|
async function handleStream(stream: ReadableStream) {
|
|
38
84
|
reset()
|
|
@@ -57,64 +103,170 @@ function App() {
|
|
|
57
103
|
}
|
|
58
104
|
```
|
|
59
105
|
|
|
60
|
-
##
|
|
61
|
-
|
|
62
|
-
|
|
106
|
+
## IncremarkContent Component
|
|
107
|
+
|
|
108
|
+
Declarative all-in-one component, recommended for most scenarios.
|
|
109
|
+
|
|
110
|
+
### Props
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
interface IncremarkContentProps {
|
|
114
|
+
// Input (choose one)
|
|
115
|
+
content?: string // Accumulated Markdown string
|
|
116
|
+
stream?: () => AsyncGenerator<string> // Async generator function
|
|
117
|
+
|
|
118
|
+
// Status
|
|
119
|
+
isFinished?: boolean // Stream finished flag (required for content mode)
|
|
120
|
+
|
|
121
|
+
// Configuration
|
|
122
|
+
incremarkOptions?: {
|
|
123
|
+
gfm?: boolean // GFM support
|
|
124
|
+
math?: boolean // Math formulas
|
|
125
|
+
htmlTree?: boolean // HTML structured parsing
|
|
126
|
+
containers?: boolean // ::: container syntax
|
|
127
|
+
typewriter?: { // Typewriter effect
|
|
128
|
+
enabled?: boolean
|
|
129
|
+
charsPerTick?: number | [number, number]
|
|
130
|
+
tickInterval?: number
|
|
131
|
+
effect?: 'none' | 'fade-in' | 'typing'
|
|
132
|
+
cursor?: string
|
|
133
|
+
}
|
|
134
|
+
}
|
|
63
135
|
|
|
64
|
-
|
|
136
|
+
// Custom rendering
|
|
137
|
+
components?: ComponentMap // Custom components
|
|
138
|
+
customContainers?: Record<string, ComponentType> // Custom containers
|
|
139
|
+
customCodeBlocks?: Record<string, ComponentType> // Custom code blocks
|
|
140
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig>
|
|
65
141
|
|
|
66
|
-
|
|
142
|
+
// Styling
|
|
143
|
+
showBlockStatus?: boolean // Show block status border
|
|
144
|
+
pendingClass?: string // CSS class for pending blocks
|
|
145
|
+
}
|
|
146
|
+
```
|
|
67
147
|
|
|
68
|
-
|
|
69
|
-
|----------|------|-------------|
|
|
70
|
-
| `markdown` | `string` | Complete Markdown |
|
|
71
|
-
| `blocks` | `Block[]` | All blocks |
|
|
72
|
-
| `completedBlocks` | `Block[]` | Completed blocks |
|
|
73
|
-
| `pendingBlocks` | `Block[]` | Pending blocks |
|
|
74
|
-
| `append` | `Function` | Append content |
|
|
75
|
-
| `finalize` | `Function` | Complete parsing |
|
|
76
|
-
| `reset` | `Function` | Reset state |
|
|
77
|
-
| `render` | `Function` | Render once (reset + append + finalize) |
|
|
148
|
+
### Example: Enable Typewriter Effect
|
|
78
149
|
|
|
79
|
-
|
|
150
|
+
```tsx
|
|
151
|
+
<IncremarkContent
|
|
152
|
+
content={content}
|
|
153
|
+
isFinished={isFinished}
|
|
154
|
+
incremarkOptions={{
|
|
155
|
+
gfm: true,
|
|
156
|
+
typewriter: {
|
|
157
|
+
enabled: true,
|
|
158
|
+
charsPerTick: [1, 3],
|
|
159
|
+
tickInterval: 30,
|
|
160
|
+
effect: 'fade-in'
|
|
161
|
+
}
|
|
162
|
+
}}
|
|
163
|
+
/>
|
|
164
|
+
```
|
|
80
165
|
|
|
81
|
-
|
|
166
|
+
### Example: Custom Components
|
|
82
167
|
|
|
83
168
|
```tsx
|
|
84
|
-
|
|
85
|
-
|
|
169
|
+
import CustomHeading from './CustomHeading'
|
|
170
|
+
import WarningContainer from './WarningContainer'
|
|
171
|
+
import EchartsCodeBlock from './EchartsCodeBlock'
|
|
172
|
+
|
|
173
|
+
<IncremarkContent
|
|
174
|
+
content={content}
|
|
175
|
+
isFinished={isFinished}
|
|
176
|
+
components={{ heading: CustomHeading }}
|
|
177
|
+
customContainers={{ warning: WarningContainer }}
|
|
178
|
+
customCodeBlocks={{ echarts: EchartsCodeBlock }}
|
|
179
|
+
codeBlockConfigs={{ echarts: { takeOver: true } }}
|
|
180
|
+
/>
|
|
86
181
|
```
|
|
87
182
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Render component.
|
|
183
|
+
## Theme System
|
|
91
184
|
|
|
92
185
|
```tsx
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
186
|
+
import { ThemeProvider, IncremarkContent } from '@incremark/react'
|
|
187
|
+
|
|
188
|
+
// Built-in theme
|
|
189
|
+
<ThemeProvider theme="dark">
|
|
190
|
+
<IncremarkContent content={content} isFinished={isFinished} />
|
|
191
|
+
</ThemeProvider>
|
|
192
|
+
|
|
193
|
+
// Custom theme
|
|
194
|
+
<ThemeProvider theme={{ color: { brand: { primary: '#8b5cf6' } } }}>
|
|
195
|
+
<IncremarkContent content={content} isFinished={isFinished} />
|
|
196
|
+
</ThemeProvider>
|
|
97
197
|
```
|
|
98
198
|
|
|
99
|
-
##
|
|
199
|
+
## Auto Scroll
|
|
100
200
|
|
|
101
201
|
```tsx
|
|
102
|
-
import {
|
|
103
|
-
import
|
|
202
|
+
import { useRef, useState } from 'react'
|
|
203
|
+
import { AutoScrollContainer, IncremarkContent, type AutoScrollContainerRef } from '@incremark/react'
|
|
104
204
|
|
|
105
205
|
function App() {
|
|
106
|
-
const
|
|
107
|
-
|
|
206
|
+
const scrollRef = useRef<AutoScrollContainerRef>(null)
|
|
207
|
+
const [autoScrollEnabled, setAutoScrollEnabled] = useState(true)
|
|
208
|
+
|
|
108
209
|
return (
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
210
|
+
<div>
|
|
211
|
+
<AutoScrollContainer
|
|
212
|
+
ref={scrollRef}
|
|
213
|
+
enabled={autoScrollEnabled}
|
|
214
|
+
threshold={50}
|
|
215
|
+
behavior="smooth"
|
|
216
|
+
>
|
|
217
|
+
<IncremarkContent content={content} isFinished={isFinished} />
|
|
218
|
+
</AutoScrollContainer>
|
|
219
|
+
|
|
220
|
+
<button onClick={() => scrollRef.current?.scrollToBottom()}>
|
|
221
|
+
Scroll to Bottom
|
|
222
|
+
</button>
|
|
223
|
+
</div>
|
|
113
224
|
)
|
|
114
225
|
}
|
|
115
226
|
```
|
|
116
227
|
|
|
117
|
-
##
|
|
228
|
+
## useIncremark API
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
const {
|
|
232
|
+
// State
|
|
233
|
+
markdown, // string - Complete Markdown
|
|
234
|
+
blocks, // Block[] - All blocks
|
|
235
|
+
completedBlocks, // Block[] - Completed blocks
|
|
236
|
+
pendingBlocks, // Block[] - Pending blocks
|
|
237
|
+
isLoading, // boolean - Is loading
|
|
238
|
+
isDisplayComplete, // boolean - Is display complete
|
|
239
|
+
|
|
240
|
+
// Methods
|
|
241
|
+
append, // (chunk: string) => IncrementalUpdate
|
|
242
|
+
finalize, // () => IncrementalUpdate
|
|
243
|
+
reset, // () => void
|
|
244
|
+
render, // (content: string) => IncrementalUpdate
|
|
245
|
+
|
|
246
|
+
// Typewriter controls
|
|
247
|
+
typewriter: {
|
|
248
|
+
enabled, // boolean - Is enabled
|
|
249
|
+
isProcessing, // boolean - Is processing
|
|
250
|
+
skip, // () => void - Skip animation
|
|
251
|
+
setOptions // (options) => void - Update config
|
|
252
|
+
}
|
|
253
|
+
} = useIncremark(options)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## DevTools
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import { useIncremark, useDevTools, Incremark } from '@incremark/react'
|
|
260
|
+
|
|
261
|
+
function App() {
|
|
262
|
+
const incremark = useIncremark()
|
|
263
|
+
useDevTools(incremark)
|
|
264
|
+
|
|
265
|
+
return <Incremark blocks={incremark.blocks} />
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## React Query Integration
|
|
118
270
|
|
|
119
271
|
```tsx
|
|
120
272
|
import { useQuery } from '@tanstack/react-query'
|
|
@@ -127,7 +279,7 @@ function StreamingContent() {
|
|
|
127
279
|
queryKey: ['chat'],
|
|
128
280
|
queryFn: async () => {
|
|
129
281
|
reset()
|
|
130
|
-
// ... streaming
|
|
282
|
+
// ... streaming logic
|
|
131
283
|
finalize()
|
|
132
284
|
return null
|
|
133
285
|
},
|
|
@@ -143,7 +295,24 @@ function StreamingContent() {
|
|
|
143
295
|
}
|
|
144
296
|
```
|
|
145
297
|
|
|
298
|
+
## Math Formula Support
|
|
299
|
+
|
|
300
|
+
Built-in support, just enable `math: true`:
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
<IncremarkContent
|
|
304
|
+
content={content}
|
|
305
|
+
isFinished={isFinished}
|
|
306
|
+
incremarkOptions={{ math: true }}
|
|
307
|
+
/>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Import KaTeX styles:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import 'katex/dist/katex.min.css'
|
|
314
|
+
```
|
|
315
|
+
|
|
146
316
|
## License
|
|
147
317
|
|
|
148
318
|
MIT
|
|
149
|
-
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ParserOptions, AnimationEffect, TransformerPlugin, ParsedBlock, Root, IncrementalUpdate, IncremarkParser, SourceBlock, TransformerOptions, DisplayBlock, BlockTransformer } from '@incremark/core';
|
|
2
2
|
export { AnimationEffect, BlockTransformer, DisplayBlock, IncrementalUpdate, ParsedBlock, ParserOptions, Root, RootContent, SourceBlock, TransformerOptions, TransformerPlugin, TransformerState, allPlugins, cloneNode, codeBlockPlugin, countChars, createBlockTransformer, createPlugin, defaultPlugins, imagePlugin, mathPlugin, mermaidPlugin, sliceAst, thematicBreakPlugin } from '@incremark/core';
|
|
3
|
-
import React, { ReactNode } from 'react';
|
|
3
|
+
import React$1, { ReactNode, ComponentType } from 'react';
|
|
4
4
|
import { Definition, FootnoteDefinition, RootContent, PhrasingContent } from 'mdast';
|
|
5
5
|
import * as _incremark_devtools from '@incremark/devtools';
|
|
6
6
|
import { DevToolsOptions } from '@incremark/devtools';
|
|
7
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
|
+
import { IncremarkLocale } from '@incremark/shared';
|
|
9
|
+
export { IncremarkLocale, en, zhCN } from '@incremark/shared';
|
|
7
10
|
import { DesignTokens } from '@incremark/theme';
|
|
8
11
|
export { DesignTokens, applyTheme, darkTheme, defaultTheme, generateCSSVars, mergeTheme } from '@incremark/theme';
|
|
9
12
|
|
|
@@ -69,7 +72,7 @@ interface DefinitionsProviderProps {
|
|
|
69
72
|
* }
|
|
70
73
|
* ```
|
|
71
74
|
*/
|
|
72
|
-
declare const DefinitionsProvider: React.FC<DefinitionsProviderProps>;
|
|
75
|
+
declare const DefinitionsProvider: React$1.FC<DefinitionsProviderProps>;
|
|
73
76
|
/**
|
|
74
77
|
* useDefinitions Hook
|
|
75
78
|
*
|
|
@@ -111,10 +114,9 @@ interface UseIncremarkOptions extends ParserOptions {
|
|
|
111
114
|
/** 打字机配置,传入即创建 transformer(可通过 enabled 控制是否启用) */
|
|
112
115
|
typewriter?: TypewriterOptions;
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
stableId: string;
|
|
117
|
+
type RenderableBlock = ParsedBlock & {
|
|
116
118
|
isLastPending?: boolean;
|
|
117
|
-
}
|
|
119
|
+
};
|
|
118
120
|
/** 打字机控制对象 */
|
|
119
121
|
interface TypewriterControls {
|
|
120
122
|
/** 是否启用 */
|
|
@@ -175,7 +177,7 @@ declare function useIncremark(options?: UseIncremarkOptions): {
|
|
|
175
177
|
/** 当前完整的 AST */
|
|
176
178
|
ast: Root;
|
|
177
179
|
/** 用于渲染的 blocks(根据打字机设置自动处理) */
|
|
178
|
-
blocks:
|
|
180
|
+
blocks: RenderableBlock[];
|
|
179
181
|
/** 是否正在加载 */
|
|
180
182
|
isLoading: boolean;
|
|
181
183
|
/** 是否已完成(finalize) */
|
|
@@ -294,10 +296,50 @@ interface UseBlockTransformerReturn<T = unknown> {
|
|
|
294
296
|
*/
|
|
295
297
|
declare function useBlockTransformer<T = unknown>(sourceBlocks: SourceBlock<T>[], options?: UseBlockTransformerOptions): UseBlockTransformerReturn<T>;
|
|
296
298
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
299
|
+
/**
|
|
300
|
+
* React 国际化 Hook
|
|
301
|
+
*/
|
|
302
|
+
interface UseLocaleReturn {
|
|
303
|
+
/** 翻译函数 */
|
|
304
|
+
t: (key: string) => string;
|
|
300
305
|
}
|
|
306
|
+
declare function useLocale(): UseLocaleReturn;
|
|
307
|
+
|
|
308
|
+
type ComponentMap = Partial<Record<string, ComponentType<{
|
|
309
|
+
node: any;
|
|
310
|
+
}>>>;
|
|
311
|
+
/**
|
|
312
|
+
* 代码块配置
|
|
313
|
+
*/
|
|
314
|
+
interface CodeBlockConfig$1 {
|
|
315
|
+
/** 是否从一开始就接管渲染,而不是等到 completed 状态 */
|
|
316
|
+
takeOver?: boolean;
|
|
317
|
+
}
|
|
318
|
+
interface IncremarkContentProps {
|
|
319
|
+
stream?: () => AsyncGenerator<string>;
|
|
320
|
+
content?: string;
|
|
321
|
+
components?: ComponentMap;
|
|
322
|
+
/** 自定义容器组件映射,key 为容器名称(如 'warning', 'info') */
|
|
323
|
+
customContainers?: Record<string, ComponentType<{
|
|
324
|
+
name: string;
|
|
325
|
+
options?: Record<string, any>;
|
|
326
|
+
children?: React.ReactNode;
|
|
327
|
+
}>>;
|
|
328
|
+
/** 自定义代码块组件映射,key 为代码语言名称(如 'echart', 'mermaid') */
|
|
329
|
+
customCodeBlocks?: Record<string, ComponentType<{
|
|
330
|
+
codeStr: string;
|
|
331
|
+
lang?: string;
|
|
332
|
+
completed?: boolean;
|
|
333
|
+
takeOver?: boolean;
|
|
334
|
+
}>>;
|
|
335
|
+
/** 代码块配置映射,key 为代码语言名称 */
|
|
336
|
+
codeBlockConfigs?: Record<string, CodeBlockConfig$1>;
|
|
337
|
+
isFinished?: boolean;
|
|
338
|
+
incremarkOptions?: UseIncremarkOptions;
|
|
339
|
+
pendingClass?: string;
|
|
340
|
+
showBlockStatus?: boolean;
|
|
341
|
+
}
|
|
342
|
+
|
|
301
343
|
/**
|
|
302
344
|
* 代码块配置
|
|
303
345
|
*/
|
|
@@ -307,22 +349,22 @@ interface CodeBlockConfig {
|
|
|
307
349
|
}
|
|
308
350
|
interface IncremarkProps {
|
|
309
351
|
/** 要渲染的块列表 */
|
|
310
|
-
blocks?:
|
|
352
|
+
blocks?: RenderableBlock[];
|
|
311
353
|
/** 内容是否完全显示完成(用于控制脚注等需要在内容完全显示后才出现的元素)
|
|
312
354
|
* 如果传入了 incremark,则会自动使用 incremark.isDisplayComplete,此 prop 被忽略 */
|
|
313
355
|
isDisplayComplete?: boolean;
|
|
314
356
|
/** 自定义组件映射 */
|
|
315
|
-
components?: Partial<Record<string, React.ComponentType<{
|
|
357
|
+
components?: Partial<Record<string, React$1.ComponentType<{
|
|
316
358
|
node: any;
|
|
317
359
|
}>>>;
|
|
318
360
|
/** 自定义容器组件映射,key 为容器名称(如 'warning', 'info') */
|
|
319
|
-
customContainers?: Record<string, React.ComponentType<{
|
|
361
|
+
customContainers?: Record<string, React$1.ComponentType<{
|
|
320
362
|
name: string;
|
|
321
363
|
options?: Record<string, any>;
|
|
322
|
-
children?: React.ReactNode;
|
|
364
|
+
children?: React$1.ReactNode;
|
|
323
365
|
}>>;
|
|
324
366
|
/** 自定义代码块组件映射,key 为代码语言名称(如 'echart', 'mermaid') */
|
|
325
|
-
customCodeBlocks?: Record<string, React.ComponentType<{
|
|
367
|
+
customCodeBlocks?: Record<string, React$1.ComponentType<{
|
|
326
368
|
codeStr: string;
|
|
327
369
|
lang?: string | undefined;
|
|
328
370
|
completed?: boolean | undefined;
|
|
@@ -334,6 +376,10 @@ interface IncremarkProps {
|
|
|
334
376
|
showBlockStatus?: boolean;
|
|
335
377
|
/** 自定义类名 */
|
|
336
378
|
className?: string;
|
|
379
|
+
/** 待处理块的样式类名 */
|
|
380
|
+
pendingClass?: string;
|
|
381
|
+
/** 已完成块的样式类名 */
|
|
382
|
+
completedClass?: string;
|
|
337
383
|
/** 可选:useIncremark 返回的对象(用于自动提供 context) */
|
|
338
384
|
incremark?: UseIncremarkReturn;
|
|
339
385
|
}
|
|
@@ -351,7 +397,26 @@ interface IncremarkProps {
|
|
|
351
397
|
* }
|
|
352
398
|
* ```
|
|
353
399
|
*/
|
|
354
|
-
declare const Incremark: React.FC<IncremarkProps>;
|
|
400
|
+
declare const Incremark: React$1.FC<IncremarkProps>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* IncremarkContent 组件
|
|
404
|
+
*
|
|
405
|
+
* 提供开箱即用的 Markdown 渲染体验,自动处理流式内容和普通内容
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```tsx
|
|
409
|
+
* // 普通内容
|
|
410
|
+
* <IncremarkContent content={markdownString} />
|
|
411
|
+
*
|
|
412
|
+
* // 流式内容
|
|
413
|
+
* <IncremarkContent stream={() => streamGenerator()} />
|
|
414
|
+
*
|
|
415
|
+
* // 增量更新内容
|
|
416
|
+
* <IncremarkContent content={partialContent} isFinished={false} />
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
declare const IncremarkContent: React$1.FC<IncremarkContentProps>;
|
|
355
420
|
|
|
356
421
|
/**
|
|
357
422
|
* 容器节点类型定义
|
|
@@ -366,15 +431,15 @@ interface ContainerNode {
|
|
|
366
431
|
|
|
367
432
|
interface IncremarkRendererProps {
|
|
368
433
|
node: RootContent | ContainerNode;
|
|
369
|
-
components?: Partial<Record<string, React.ComponentType<{
|
|
434
|
+
components?: Partial<Record<string, React$1.ComponentType<{
|
|
370
435
|
node: any;
|
|
371
436
|
}>>>;
|
|
372
|
-
customContainers?: Record<string, React.ComponentType<{
|
|
437
|
+
customContainers?: Record<string, React$1.ComponentType<{
|
|
373
438
|
name: string;
|
|
374
439
|
options?: Record<string, any>;
|
|
375
440
|
children?: ReactNode;
|
|
376
441
|
}>>;
|
|
377
|
-
customCodeBlocks?: Record<string, React.ComponentType<{
|
|
442
|
+
customCodeBlocks?: Record<string, React$1.ComponentType<{
|
|
378
443
|
codeStr: string;
|
|
379
444
|
lang?: string;
|
|
380
445
|
completed?: boolean;
|
|
@@ -388,11 +453,11 @@ interface IncremarkRendererProps {
|
|
|
388
453
|
/**
|
|
389
454
|
* 渲染单个 AST 节点
|
|
390
455
|
*/
|
|
391
|
-
declare const IncremarkRenderer: React.FC<IncremarkRendererProps>;
|
|
456
|
+
declare const IncremarkRenderer: React$1.FC<IncremarkRendererProps>;
|
|
392
457
|
|
|
393
458
|
interface AutoScrollContainerProps {
|
|
394
459
|
/** 子元素 */
|
|
395
|
-
children: React.ReactNode;
|
|
460
|
+
children: React$1.ReactNode;
|
|
396
461
|
/** 是否启用自动滚动 */
|
|
397
462
|
enabled?: boolean;
|
|
398
463
|
/** 触发自动滚动的底部阈值(像素) */
|
|
@@ -400,7 +465,7 @@ interface AutoScrollContainerProps {
|
|
|
400
465
|
/** 滚动行为 */
|
|
401
466
|
behavior?: ScrollBehavior;
|
|
402
467
|
/** 容器样式 */
|
|
403
|
-
style?: React.CSSProperties;
|
|
468
|
+
style?: React$1.CSSProperties;
|
|
404
469
|
/** 容器类名 */
|
|
405
470
|
className?: string;
|
|
406
471
|
}
|
|
@@ -430,7 +495,7 @@ interface AutoScrollContainerRef {
|
|
|
430
495
|
* scrollRef.current?.scrollToBottom()
|
|
431
496
|
* ```
|
|
432
497
|
*/
|
|
433
|
-
declare const AutoScrollContainer: React.ForwardRefExoticComponent<AutoScrollContainerProps & React.RefAttributes<AutoScrollContainerRef>>;
|
|
498
|
+
declare const AutoScrollContainer: React$1.ForwardRefExoticComponent<AutoScrollContainerProps & React$1.RefAttributes<AutoScrollContainerRef>>;
|
|
434
499
|
|
|
435
500
|
interface IncremarkInlineProps {
|
|
436
501
|
nodes: PhrasingContent[];
|
|
@@ -450,7 +515,7 @@ interface IncremarkInlineProps {
|
|
|
450
515
|
*
|
|
451
516
|
* 注意:此组件与 Vue 版本保持完全一致的逻辑和结构
|
|
452
517
|
*/
|
|
453
|
-
declare const IncremarkInline: React.FC<IncremarkInlineProps>;
|
|
518
|
+
declare const IncremarkInline: React$1.FC<IncremarkInlineProps>;
|
|
454
519
|
|
|
455
520
|
/**
|
|
456
521
|
* HtmlElementNode 类型定义(与 @incremark/core 中的定义一致)
|
|
@@ -474,7 +539,7 @@ interface IncremarkHtmlElementProps {
|
|
|
474
539
|
*
|
|
475
540
|
* 渲染结构化的 HTML 元素节点
|
|
476
541
|
*/
|
|
477
|
-
declare const IncremarkHtmlElement: React.FC<IncremarkHtmlElementProps>;
|
|
542
|
+
declare const IncremarkHtmlElement: React$1.FC<IncremarkHtmlElementProps>;
|
|
478
543
|
|
|
479
544
|
/**
|
|
480
545
|
* 脚注列表组件
|
|
@@ -501,7 +566,7 @@ declare const IncremarkHtmlElement: React.FC<IncremarkHtmlElementProps>;
|
|
|
501
566
|
* <IncremarkFootnotes />
|
|
502
567
|
* ```
|
|
503
568
|
*/
|
|
504
|
-
declare const IncremarkFootnotes: React.FC;
|
|
569
|
+
declare const IncremarkFootnotes: React$1.FC;
|
|
505
570
|
|
|
506
571
|
/**
|
|
507
572
|
* @file IncremarkContainerProvider - Incremark 容器级 Provider
|
|
@@ -533,7 +598,13 @@ interface IncremarkContainerProviderProps {
|
|
|
533
598
|
* @param props - 组件参数
|
|
534
599
|
* @returns ReactElement
|
|
535
600
|
*/
|
|
536
|
-
declare const IncremarkContainerProvider: React.FC<IncremarkContainerProviderProps>;
|
|
601
|
+
declare const IncremarkContainerProvider: React$1.FC<IncremarkContainerProviderProps>;
|
|
602
|
+
|
|
603
|
+
interface ConfigProviderProps {
|
|
604
|
+
children: ReactNode;
|
|
605
|
+
locale?: IncremarkLocale;
|
|
606
|
+
}
|
|
607
|
+
declare function ConfigProvider({ children, locale }: ConfigProviderProps): react_jsx_runtime.JSX.Element;
|
|
537
608
|
|
|
538
609
|
interface ThemeProviderProps {
|
|
539
610
|
/** 主题配置,可以是:
|
|
@@ -565,6 +636,6 @@ interface ThemeProviderProps {
|
|
|
565
636
|
* </ThemeProvider>
|
|
566
637
|
* ```
|
|
567
638
|
*/
|
|
568
|
-
declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
639
|
+
declare const ThemeProvider: React$1.FC<ThemeProviderProps>;
|
|
569
640
|
|
|
570
|
-
export { AutoScrollContainer, type AutoScrollContainerProps, type AutoScrollContainerRef, type DefinitionsContextValue, DefinitionsProvider, type DefinitionsProviderProps, type HtmlElementNode, Incremark, IncremarkContainerProvider, type IncremarkContainerProviderProps, IncremarkFootnotes, IncremarkHtmlElement, type IncremarkHtmlElementProps, IncremarkInline, type IncremarkInlineProps, type IncremarkProps, IncremarkRenderer, type IncremarkRendererProps, ThemeProvider, type ThemeProviderProps, type TypewriterControls, type TypewriterOptions, type UseBlockTransformerOptions, type UseBlockTransformerReturn, type UseDevToolsOptions, type UseIncremarkOptions, type UseIncremarkReturn, useBlockTransformer, useDefinitions, useDevTools, useIncremark };
|
|
641
|
+
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 UseDevToolsOptions, type UseIncremarkOptions, type UseIncremarkReturn, type UseLocaleReturn, useBlockTransformer, useDefinitions, useDevTools, useIncremark, useLocale };
|