ds-markdown 0.2.3 → 0.2.4-beta.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 +8 -4
- package/dist/cjs/index.d.ts +17 -67
- package/dist/cjs/index.js +860 -834
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +17 -67
- package/dist/esm/index.js +861 -835
- package/dist/esm/index.js.map +1 -1
- package/dist/style.css +90 -90
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -353,7 +353,7 @@ import DsMarkdown, { MarkdownCMD } from 'ds-markdown';
|
|
|
353
353
|
| `autoStartTyping` | `boolean` | 是否自动开始打字动画,设为 false 时需手动触发,不支持动态修改 | `true` |
|
|
354
354
|
| `codeBlock` | `IMarkdownCode` | 代码块配置 | `{headerActions: true}` |
|
|
355
355
|
|
|
356
|
-
>
|
|
356
|
+
> 注意:打字进行中将 `disableTyping` 从 `true` 改为 `false` 只会从当前位置继续,不会回放已跳过的动画;若需从头播放,请调用实例方法 `restart()`。
|
|
357
357
|
|
|
358
358
|
### IBeforeTypedChar
|
|
359
359
|
|
|
@@ -851,16 +851,19 @@ import { MarkdownCMD, MarkdownCMDRef } from 'ds-markdown';
|
|
|
851
851
|
|
|
852
852
|
function StreamingChat() {
|
|
853
853
|
const markdownRef = useRef<MarkdownCMDRef>(null);
|
|
854
|
+
const answerRef = useRef<MarkdownCMDRef>(null);
|
|
855
|
+
const [isShowAnswer, setIsShowAnswer] = useState(false);
|
|
854
856
|
|
|
855
857
|
// 模拟 AI 流式响应
|
|
856
858
|
const simulateAIResponse = async () => {
|
|
857
859
|
markdownRef.current?.clear();
|
|
860
|
+
answerRef.current?.clear();
|
|
858
861
|
|
|
859
862
|
// 思考阶段
|
|
860
863
|
markdownRef.current?.push('🤔 正在分析您的问题...', 'thinking');
|
|
861
864
|
await delay(1000);
|
|
862
865
|
markdownRef.current?.push('\n\n✅ 分析完成,开始回答', 'thinking');
|
|
863
|
-
|
|
866
|
+
setIsShowAnswer(true);
|
|
864
867
|
// 流式回答
|
|
865
868
|
const chunks = [
|
|
866
869
|
'# React 19 新特性解析\n\n',
|
|
@@ -874,7 +877,7 @@ function StreamingChat() {
|
|
|
874
877
|
|
|
875
878
|
for (const chunk of chunks) {
|
|
876
879
|
await delay(100);
|
|
877
|
-
|
|
880
|
+
answerRef.current?.push(chunk, 'answer');
|
|
878
881
|
}
|
|
879
882
|
};
|
|
880
883
|
|
|
@@ -883,7 +886,8 @@ function StreamingChat() {
|
|
|
883
886
|
return (
|
|
884
887
|
<div className="chat-container">
|
|
885
888
|
<button onClick={simulateAIResponse}>🤖 询问 React 19 新特性</button>
|
|
886
|
-
<MarkdownCMD ref={markdownRef} interval={10} timerType="requestAnimationFrame" />
|
|
889
|
+
<MarkdownCMD answerType="thinking" ref={markdownRef} interval={10} timerType="requestAnimationFrame" />
|
|
890
|
+
{isShowAnswer && <MarkdownCMD answerType="answer" ref={answerRef} interval={10} timerType="requestAnimationFrame" />}
|
|
887
891
|
</div>
|
|
888
892
|
);
|
|
889
893
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import * as React$1 from 'react';
|
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
import { Pluggable } from 'unified';
|
|
4
4
|
import { KatexOptions } from 'katex';
|
|
5
|
+
import * as react_markdown_typer_es_defined from 'react-markdown-typer/es/defined';
|
|
6
|
+
import { MarkdownTyperBaseProps, MarkdownBaseRef } from 'react-markdown-typer/es/defined';
|
|
7
|
+
import { MarkdownTyperCMDProps } from 'react-markdown-typer';
|
|
8
|
+
export { ITypedChar } from 'react-markdown-typer';
|
|
5
9
|
|
|
6
10
|
declare namespace Mermaid {
|
|
7
11
|
/**
|
|
@@ -1521,32 +1525,7 @@ declare namespace Mermaid {
|
|
|
1521
1525
|
* 回答类型,思考和回答
|
|
1522
1526
|
*/
|
|
1523
1527
|
type AnswerType = 'answer' | 'thinking';
|
|
1524
|
-
type IntervalType = number | {
|
|
1525
|
-
/** 最大间隔 */
|
|
1526
|
-
max: number;
|
|
1527
|
-
/** 最小间隔 */
|
|
1528
|
-
min: number;
|
|
1529
|
-
/** 曲线函数自定义 */
|
|
1530
|
-
curveFn?: (x: number) => number;
|
|
1531
|
-
/** 曲线函数,如果配置了curveFn,则curve无效 */
|
|
1532
|
-
curve?: 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear' | 'step-start' | 'step-end';
|
|
1533
|
-
};
|
|
1534
1528
|
type Theme = 'light' | 'dark';
|
|
1535
|
-
interface IOnTypedCharData {
|
|
1536
|
-
currentIndex: number;
|
|
1537
|
-
currentChar: string;
|
|
1538
|
-
answerType: AnswerType;
|
|
1539
|
-
prevStr: string;
|
|
1540
|
-
}
|
|
1541
|
-
interface IStartData extends IOnTypedCharData {
|
|
1542
|
-
}
|
|
1543
|
-
interface ITypedChar extends IOnTypedCharData {
|
|
1544
|
-
percent: number;
|
|
1545
|
-
currentStr: string;
|
|
1546
|
-
}
|
|
1547
|
-
interface IBeforeTypedChar extends IOnTypedCharData {
|
|
1548
|
-
percent: number;
|
|
1549
|
-
}
|
|
1550
1529
|
interface IMarkdownThemeProps {
|
|
1551
1530
|
/** 主题 */
|
|
1552
1531
|
theme?: Theme;
|
|
@@ -1563,28 +1542,6 @@ interface IMarkdownThemeStateProps extends IMarkdownThemeProps {
|
|
|
1563
1542
|
theme: Theme;
|
|
1564
1543
|
answerType: AnswerType;
|
|
1565
1544
|
}
|
|
1566
|
-
interface MarkdownBaseProps {
|
|
1567
|
-
/** 计时类型: 支持setTimeout和requestAnimationFrame */
|
|
1568
|
-
timerType?: 'setTimeout' | 'requestAnimationFrame';
|
|
1569
|
-
/** 打字机效果间隔时间 */
|
|
1570
|
-
interval: IntervalType;
|
|
1571
|
-
/** 是否关闭打字机效果 */
|
|
1572
|
-
disableTyping?: boolean;
|
|
1573
|
-
/** 打字完成后回调, */
|
|
1574
|
-
onEnd?: (data?: IEndData) => void;
|
|
1575
|
-
/** 开始打字回调 */
|
|
1576
|
-
onStart?: (data?: IStartData) => void;
|
|
1577
|
-
/** 打字前回调 */
|
|
1578
|
-
onBeforeTypedChar?: (data?: IBeforeTypedChar) => Promise<void>;
|
|
1579
|
-
/**
|
|
1580
|
-
* 打字机打完一个字符回调
|
|
1581
|
-
* @param char 字符
|
|
1582
|
-
* @param index 字符索引
|
|
1583
|
-
*/
|
|
1584
|
-
onTypedChar?: (data?: ITypedChar) => void;
|
|
1585
|
-
/** 是否自动开启打字动画 */
|
|
1586
|
-
autoStartTyping?: boolean;
|
|
1587
|
-
}
|
|
1588
1545
|
interface IMarkdownCode {
|
|
1589
1546
|
/** 是否显示头部操作按钮
|
|
1590
1547
|
* 如果为true,则显示头部操作按钮
|
|
@@ -1592,11 +1549,11 @@ interface IMarkdownCode {
|
|
|
1592
1549
|
*/
|
|
1593
1550
|
headerActions?: boolean | React.ReactNode;
|
|
1594
1551
|
}
|
|
1595
|
-
interface MarkdownProps extends
|
|
1552
|
+
interface MarkdownProps extends MarkdownTyperBaseProps, IMarkdownThemeProps {
|
|
1596
1553
|
children: string | undefined;
|
|
1597
1554
|
}
|
|
1598
1555
|
/** MarkdownCMD 组件不需要 children */
|
|
1599
|
-
interface MarkdownCMDProps extends
|
|
1556
|
+
interface MarkdownCMDProps extends MarkdownTyperBaseProps, IMarkdownThemeProps {
|
|
1600
1557
|
children?: undefined;
|
|
1601
1558
|
isInnerRender?: boolean;
|
|
1602
1559
|
}
|
|
@@ -1613,12 +1570,6 @@ interface IMarkdownMath {
|
|
|
1613
1570
|
/** 数学公式替换函数 */
|
|
1614
1571
|
replaceMathBracket?: (value: string) => string;
|
|
1615
1572
|
}
|
|
1616
|
-
interface MarkdownBaseRef {
|
|
1617
|
-
stop: () => void;
|
|
1618
|
-
resume: () => void;
|
|
1619
|
-
start: () => void;
|
|
1620
|
-
restart: () => void;
|
|
1621
|
-
}
|
|
1622
1573
|
/** Markdown 组件的ref 类型 */
|
|
1623
1574
|
type MarkdownRef = MarkdownBaseRef;
|
|
1624
1575
|
/** MarkdownCMD 组件的 ref 类型 */
|
|
@@ -1627,15 +1578,6 @@ interface MarkdownCMDRef extends MarkdownBaseRef {
|
|
|
1627
1578
|
clear: () => void;
|
|
1628
1579
|
triggerWholeEnd: () => void;
|
|
1629
1580
|
}
|
|
1630
|
-
interface IEndData {
|
|
1631
|
-
manual: boolean;
|
|
1632
|
-
/** 回答字符串 */
|
|
1633
|
-
answerStr: string;
|
|
1634
|
-
/** 思考字符串 */
|
|
1635
|
-
thinkingStr: string;
|
|
1636
|
-
/** 打字机打过的字符串, 和answerStr 相同 */
|
|
1637
|
-
str: string;
|
|
1638
|
-
}
|
|
1639
1581
|
interface IMarkdownMermaidConfig extends Mermaid.MermaidConfig {
|
|
1640
1582
|
/** 是否显示头部操作按钮
|
|
1641
1583
|
* 如果为true,则显示头部操作按钮
|
|
@@ -1648,9 +1590,17 @@ interface IMarkdownMermaidConfig extends Mermaid.MermaidConfig {
|
|
|
1648
1590
|
interface IMarkdownKatexConfig extends KatexOptions {
|
|
1649
1591
|
}
|
|
1650
1592
|
|
|
1651
|
-
|
|
1593
|
+
interface IMarkdownCustom {
|
|
1594
|
+
answerType?: AnswerType;
|
|
1595
|
+
theme?: Theme;
|
|
1596
|
+
codeBlock?: IMarkdownCode;
|
|
1597
|
+
plugins?: IMarkdownPlugin[];
|
|
1598
|
+
math?: IMarkdownMath;
|
|
1599
|
+
isInnerRender?: boolean;
|
|
1600
|
+
}
|
|
1601
|
+
declare const MarkdownCMD: React$1.ForwardRefExoticComponent<MarkdownTyperCMDProps & IMarkdownCustom & React$1.RefAttributes<MarkdownCMDRef>>;
|
|
1652
1602
|
|
|
1653
|
-
declare const _default: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<MarkdownProps & React__default.RefAttributes<MarkdownBaseRef>>>;
|
|
1603
|
+
declare const _default: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<MarkdownProps & React__default.RefAttributes<react_markdown_typer_es_defined.MarkdownBaseRef>>>;
|
|
1654
1604
|
|
|
1655
1605
|
interface ButtonProps$1 {
|
|
1656
1606
|
className?: string;
|
|
@@ -1794,4 +1744,4 @@ declare const useLocale: () => {
|
|
|
1794
1744
|
declare const useThemeState: () => IMarkdownThemeStateProps;
|
|
1795
1745
|
|
|
1796
1746
|
export { Button, CheckMarkIcon, CodeBlockActions, CodeBlockWrap, ConfigProvider, CopyButton, CopyIcon, DownloadButton, DownloadIcon, HighlightCode, IconButton, _default as Markdown, MarkdownCMD, Segmented, SuccessButton, _default as default, useConfig, useLocale, useThemeState };
|
|
1797
|
-
export type { ConfigContextType, ConfigProviderProps, IMarkdownMath, IMarkdownMermaidConfig, IMarkdownPlugin,
|
|
1747
|
+
export type { ConfigContextType, ConfigProviderProps, IMarkdownMath, IMarkdownMermaidConfig, IMarkdownPlugin, Locale, MarkdownCMDProps, MarkdownCMDRef, MarkdownProps, MarkdownRef };
|