ds-markdown 0.1.6 → 0.1.7-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.en.md CHANGED
@@ -38,6 +38,7 @@ A React component designed specifically for modern AI applications, providing sm
38
38
  - [🎛️ Timer Mode Details](#️-timer-mode-details)
39
39
  - [💡 Practical Examples](#-practical-examples)
40
40
  - [🔧 Best Practices](#-best-practices)
41
+ - [ConfigProvider Internationalization (i18n)](<#ConfigProvider-Internationalization-(i18n)>)
41
42
 
42
43
  ---
43
44
 
@@ -1102,3 +1103,111 @@ import { MarkdownCMDRef } from 'ds-markdown';
1102
1103
  const ref = useRef<MarkdownCMDRef>(null);
1103
1104
  // Complete TypeScript type hints
1104
1105
  ```
1106
+
1107
+ ## ConfigProvider Internationalization (i18n)
1108
+
1109
+ ConfigProvider is a component provided by ds-markdown for managing internationalized text in your application.
1110
+
1111
+ ### Basic Usage
1112
+
1113
+ ```tsx
1114
+ import React from 'react';
1115
+ import { ConfigProvider } from 'ds-markdown';
1116
+ import zhCN from 'ds-markdown/i18n/zh';
1117
+
1118
+ const App: React.FC = () => {
1119
+ return (
1120
+ <ConfigProvider locale={zhCN}>
1121
+ <YourApp />
1122
+ </ConfigProvider>
1123
+ );
1124
+ };
1125
+ ```
1126
+
1127
+ ### Available Locales
1128
+
1129
+ #### Chinese (zhCN)
1130
+
1131
+ ```tsx
1132
+ import zhCN from 'ds-markdown/i18n/zh';
1133
+ ```
1134
+
1135
+ #### English (enUS)
1136
+
1137
+ ```tsx
1138
+ import enUS from 'ds-markdown/i18n/en';
1139
+ ```
1140
+
1141
+ ### Using Locale in Components
1142
+
1143
+ Use the `useLocale` hook to get the current locale:
1144
+
1145
+ ```tsx
1146
+ import React from 'react';
1147
+ import { useLocale } from 'ds-markdown';
1148
+
1149
+ const MyComponent: React.FC = () => {
1150
+ const locale = useLocale();
1151
+
1152
+ return (
1153
+ <div>
1154
+ <button>{locale.codeBlock.copy}</button>
1155
+ <span>{locale.codeBlock.copied}</span>
1156
+ <button>{locale.codeBlock.download}</button>
1157
+ </div>
1158
+ );
1159
+ };
1160
+ ```
1161
+
1162
+ ### Locale Structure
1163
+
1164
+ Currently supported locale fields:
1165
+
1166
+ ```typescript
1167
+ interface Locale {
1168
+ codeBlock: {
1169
+ copy: string;
1170
+ copied: string;
1171
+ download: string;
1172
+ };
1173
+ [key: string]: string;
1174
+ }
1175
+ ```
1176
+
1177
+ ### Full Example
1178
+
1179
+ ```tsx
1180
+ import React from 'react';
1181
+ import { ConfigProvider, useLocale } from 'ds-markdown';
1182
+ import zhCN from 'ds-markdown/i18n/zh';
1183
+
1184
+ const ExampleComponent: React.FC = () => {
1185
+ const locale = useLocale();
1186
+
1187
+ return (
1188
+ <div>
1189
+ <h2>i18n Example</h2>
1190
+ <p>Copy button: {locale.codeBlock.copy}</p>
1191
+ <p>Copied tip: {locale.codeBlock.copied}</p>
1192
+ <p>Download button: {locale.codeBlock.download}</p>
1193
+ </div>
1194
+ );
1195
+ };
1196
+
1197
+ const App: React.FC = () => {
1198
+ return (
1199
+ <ConfigProvider locale={zhCN}>
1200
+ <ExampleComponent />
1201
+ </ConfigProvider>
1202
+ );
1203
+ };
1204
+
1205
+ export default App;
1206
+ ```
1207
+
1208
+ ### Notes
1209
+
1210
+ 1. `ConfigProvider` must wrap components that use `useLocale`.
1211
+ 2. The locale object is memoized to avoid unnecessary re-renders.
1212
+ 3. You can extend the locale object with custom fields.
1213
+ 4. If `ConfigProvider` is not provided, the default locale is Chinese.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![npm version](https://img.shields.io/npm/v/ds-markdown)](https://www.npmjs.com/package/ds-markdown)
10
10
  [![npm downloads](https://img.shields.io/npm/dm/ds-markdown.svg)](https://www.npmjs.com/package/ds-markdown)
11
11
  [![bundle size](https://img.shields.io/bundlephobia/minzip/ds-markdown)](https://bundlephobia.com/package/ds-markdown)
12
- [![React](https://img.shields.io/badge/React-16.8+-blue)](https://react.dev)
12
+ [![React](https://img.shields.io/badge/React-18.0.0+-blue)](https://react.dev)
13
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
14
14
 
15
15
  [📖 在线演示](https://onshinpei.github.io/ds-markdown/)
@@ -67,6 +67,7 @@
67
67
  - [🔌 插件系统](#-插件系统)
68
68
  - [🎛️ 定时器模式详解](#️-定时器模式详解)
69
69
  - [💡 实战示例](#-实战示例)
70
+ - [多语言配置](#-多语言配置)
70
71
  - [🔧 最佳实践](#-最佳实践)
71
72
 
72
73
  ---
@@ -955,3 +956,111 @@ import { MarkdownCMDRef } from 'ds-markdown';
955
956
  const ref = useRef<MarkdownCMDRef>(null);
956
957
  // 完整的 TypeScript 类型提示
957
958
  ```
959
+
960
+ ## 多语言配置
961
+
962
+ ConfigProvider 是 ds-markdown 提供的多语言配置组件,用于管理应用中的国际化文本。
963
+
964
+ ### 基本用法
965
+
966
+ ```tsx
967
+ import React from 'react';
968
+ import { ConfigProvider } from 'ds-markdown';
969
+ import zhCN from 'ds-markdown/i18n/zh';
970
+
971
+ const App: React.FC = () => {
972
+ return (
973
+ <ConfigProvider locale={zhCN}>
974
+ <YourApp />
975
+ </ConfigProvider>
976
+ );
977
+ };
978
+ ```
979
+
980
+ ### 可用的语言包
981
+
982
+ #### 中文 (zhCN)
983
+
984
+ ```tsx
985
+ import zhCN from 'ds-markdown/i18n/zh';
986
+ ```
987
+
988
+ #### 英文 (enUS)
989
+
990
+ ```tsx
991
+ import enUS from 'ds-markdown/i18n/en';
992
+ ```
993
+
994
+ ### 在组件中使用语言包
995
+
996
+ 使用 `useLocale` hook 来获取当前的语言包:
997
+
998
+ ```tsx
999
+ import React from 'react';
1000
+ import { useLocale } from 'ds-markdown';
1001
+
1002
+ const MyComponent: React.FC = () => {
1003
+ const locale = useLocale();
1004
+
1005
+ return (
1006
+ <div>
1007
+ <button>{locale.codeBlock.copy}</button>
1008
+ <span>{locale.codeBlock.copied}</span>
1009
+ <button>{locale.codeBlock.download}</button>
1010
+ </div>
1011
+ );
1012
+ };
1013
+ ```
1014
+
1015
+ ### 语言包结构
1016
+
1017
+ 当前支持的语言包包含以下字段:
1018
+
1019
+ ```typescript
1020
+ interface Locale {
1021
+ codeBlock: {
1022
+ copy: string;
1023
+ copied: string;
1024
+ download: string;
1025
+ };
1026
+ [key: string]: string;
1027
+ }
1028
+ ```
1029
+
1030
+ ### 完整示例
1031
+
1032
+ ```tsx
1033
+ import React from 'react';
1034
+ import { ConfigProvider, useLocale } from 'ds-markdown';
1035
+ import zhCN from 'ds-markdown/i18n/zh';
1036
+
1037
+ const ExampleComponent: React.FC = () => {
1038
+ const locale = useLocale();
1039
+
1040
+ return (
1041
+ <div>
1042
+ <h2>多语言示例</h2>
1043
+ <p>复制按钮: {locale.codeBlock.copy}</p>
1044
+ <p>已复制提示: {locale.codeBlock.copied}</p>
1045
+ <p>下载按钮: {locale.codeBlock.download}</p>
1046
+ </div>
1047
+ );
1048
+ };
1049
+
1050
+ const App: React.FC = () => {
1051
+ return (
1052
+ <ConfigProvider locale={zhCN}>
1053
+ <ExampleComponent />
1054
+ </ConfigProvider>
1055
+ );
1056
+ };
1057
+
1058
+ export default App;
1059
+ ```
1060
+
1061
+ ### 注意事项
1062
+
1063
+ 1. `ConfigProvider` 必须包裹在使用 `useLocale` 的组件外层
1064
+ 2. 语言包对象会被缓存,避免不必要的重新渲染
1065
+ 3. 支持扩展自定义的语言包字段
1066
+ 4. 如果没有提供 `ConfigProvider`,会使用默认的中文语言包
@@ -0,0 +1,11 @@
1
+ declare const enUS: {
2
+ readonly codeBlock: {
3
+ readonly copy: "Copy";
4
+ readonly copied: "Copied";
5
+ readonly download: "Download";
6
+ };
7
+ };
8
+ type EnUS = typeof enUS;
9
+
10
+ export { enUS as default, enUS };
11
+ export type { EnUS };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const enUS = {
6
+ codeBlock: {
7
+ copy: 'Copy',
8
+ copied: 'Copied',
9
+ download: 'Download',
10
+ },
11
+ };
12
+
13
+ exports.default = enUS;
14
+ exports.enUS = enUS;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/i18n/en/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAa,MAAA,IAAI,GAAG;AAClB,IAAA,SAAS,EAAE;AACT,QAAA,IAAI,EAAE,MAAM;AACZ,QAAA,MAAM,EAAE,QAAQ;AAChB,QAAA,QAAQ,EAAE,UAAU;AACrB,KAAA;;;;;;"}
@@ -0,0 +1,11 @@
1
+ declare const zhCN: {
2
+ readonly codeBlock: {
3
+ readonly copy: "复制";
4
+ readonly copied: "已复制";
5
+ readonly download: "下载";
6
+ };
7
+ };
8
+ type ZhCN = typeof zhCN;
9
+
10
+ export { zhCN as default, zhCN };
11
+ export type { ZhCN };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const zhCN = {
6
+ codeBlock: {
7
+ copy: '复制',
8
+ copied: '已复制',
9
+ download: '下载',
10
+ },
11
+ };
12
+
13
+ exports.default = zhCN;
14
+ exports.zhCN = zhCN;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/i18n/zh/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAa,MAAA,IAAI,GAAG;AAClB,IAAA,SAAS,EAAE;AACT,QAAA,IAAI,EAAE,IAAI;AACV,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,QAAQ,EAAE,IAAI;AACf,KAAA;;;;;;"}
@@ -1,5 +1,5 @@
1
- import * as react from 'react';
2
- import react__default from 'react';
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
3
 
4
4
  /**
5
5
  * 回答类型,思考和回答
@@ -19,11 +19,21 @@ interface ITypedChar extends IOnTypedCharData {
19
19
  interface IBeforeTypedChar extends IOnTypedCharData {
20
20
  percent: number;
21
21
  }
22
+ interface IMarkdownThemeProps {
23
+ /** 主题 */
24
+ theme?: Theme;
25
+ /** 数学公式配置 */
26
+ math?: IMarkdownMath;
27
+ /** 代码块配置 */
28
+ codeBlock?: IMarkdownCode;
29
+ /** 插件配置 */
30
+ plugins?: IMarkdownPlugin[];
31
+ /** 回答类型 */
32
+ answerType?: 'thinking' | 'answer';
33
+ }
22
34
  interface MarkdownBaseProps {
23
35
  /** 计时类型: 支持setTimeout和requestAnimationFrame */
24
36
  timerType?: 'setTimeout' | 'requestAnimationFrame';
25
- /** 回答类型 */
26
- answerType?: 'thinking' | 'answer';
27
37
  /** 打字机效果间隔时间 */
28
38
  interval: number;
29
39
  /** 是否关闭打字机效果 */
@@ -40,21 +50,23 @@ interface MarkdownBaseProps {
40
50
  * @param index 字符索引
41
51
  */
42
52
  onTypedChar?: (data?: ITypedChar) => void;
43
- /** 主题 */
44
- theme?: Theme;
45
- /** 数学公式配置 */
46
- math?: IMarkdownMath;
47
- /** 插件配置 */
48
- plugins?: IMarkdownPlugin[];
49
53
  /** 是否自动开启打字动画 */
50
54
  autoStartTyping?: boolean;
51
55
  }
52
- interface MarkdownProps extends MarkdownBaseProps {
56
+ interface IMarkdownCode {
57
+ /** 是否显示头部操作按钮
58
+ * 如果为true,则显示头部操作按钮
59
+ * 如果为React.ReactNode,则显示自定义头部操作按钮
60
+ */
61
+ headerActions?: boolean | React.ReactNode;
62
+ }
63
+ interface MarkdownProps extends MarkdownBaseProps, IMarkdownThemeProps {
53
64
  children: string | undefined;
54
65
  }
55
66
  /** MarkdownCMD 组件不需要 children */
56
- interface MarkdownCMDProps extends MarkdownBaseProps {
67
+ interface MarkdownCMDProps extends MarkdownBaseProps, IMarkdownThemeProps {
57
68
  children?: undefined;
69
+ isInnerRender?: boolean;
58
70
  }
59
71
  interface IMarkdownPlugin {
60
72
  remarkPlugin?: unknown;
@@ -90,9 +102,29 @@ interface IEndData {
90
102
  str: string;
91
103
  }
92
104
 
93
- declare const MarkdownCMD: react.ForwardRefExoticComponent<MarkdownCMDProps & react.RefAttributes<MarkdownCMDRef>>;
105
+ declare const MarkdownCMD: React$1.ForwardRefExoticComponent<MarkdownCMDProps & React$1.RefAttributes<MarkdownCMDRef>>;
106
+
107
+ declare const _default: React__default.NamedExoticComponent<MarkdownProps & React__default.RefAttributes<MarkdownBaseRef>>;
94
108
 
95
- declare const _default: react__default.NamedExoticComponent<MarkdownProps & react__default.RefAttributes<MarkdownBaseRef>>;
109
+ interface Locale {
110
+ codeBlock: {
111
+ copy: string;
112
+ copied: string;
113
+ download: string;
114
+ [key: string]: string;
115
+ };
116
+ [key: string]: unknown;
117
+ }
118
+ interface ConfigProviderProps {
119
+ locale?: Locale;
120
+ children: React__default.ReactNode;
121
+ }
122
+ interface ConfigContextType {
123
+ locale: Locale;
124
+ }
125
+ declare const ConfigProvider: React__default.FC<ConfigProviderProps>;
126
+ declare const useConfig: () => ConfigContextType;
127
+ declare const useLocale: () => Locale;
96
128
 
97
- export { _default as Markdown, MarkdownCMD, _default as default };
98
- export type { IMarkdownMath, ITypedChar, MarkdownCMDProps, MarkdownCMDRef, MarkdownProps, MarkdownRef };
129
+ export { ConfigProvider, _default as Markdown, MarkdownCMD, _default as default, useConfig, useLocale };
130
+ export type { ConfigContextType, ConfigProviderProps, IMarkdownMath, ITypedChar, Locale, MarkdownCMDProps, MarkdownCMDRef, MarkdownProps, MarkdownRef };