@fe-free/core 2.0.4 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: chat
8
+ - @fe-free/tool@2.0.5
9
+
3
10
  ## 2.0.4
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -38,7 +38,7 @@
38
38
  "remark-gfm": "^4.0.1",
39
39
  "vanilla-jsoneditor": "^0.23.1",
40
40
  "zustand": "^4.5.4",
41
- "@fe-free/tool": "2.0.4"
41
+ "@fe-free/tool": "2.0.5"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@ant-design/pro-components": "^2.8.7",
@@ -17,10 +17,10 @@ interface ChartConfig {
17
17
  }
18
18
 
19
19
  // 错误处理组件
20
- function ChatError(props: { children?: React.ReactNode }) {
20
+ function ChartError(props: { children?: React.ReactNode }) {
21
21
  const { children } = props;
22
22
  return (
23
- <div className="markdown-body-chat-block">
23
+ <div className="markdown-body-chart-block">
24
24
  <div style={{ textAlign: 'center', padding: '20px' }}>{children || '图表发生错误'}</div>
25
25
  </div>
26
26
  );
@@ -39,7 +39,7 @@ class ErrorBoundary extends React.Component {
39
39
 
40
40
  render() {
41
41
  if (this.state.hasError) {
42
- return <ChatError />;
42
+ return <ChartError />;
43
43
  }
44
44
  return this.props.children;
45
45
  }
@@ -49,8 +49,8 @@ class ErrorBoundary extends React.Component {
49
49
  function ChartContainer(props: { title: string; children: React.ReactNode }) {
50
50
  const { title, children } = props;
51
51
  return (
52
- <div className="markdown-body-chat-block">
53
- <div className="markdown-body-chat-block-title">{title}</div>
52
+ <div className="markdown-body-chart-block">
53
+ <div className="markdown-body-chart-block-title">{title}</div>
54
54
  {children}
55
55
  </div>
56
56
  );
@@ -63,14 +63,14 @@ function PieChart(props: { data: ChartData; chart: ChartConfig }) {
63
63
  const { angle_field, color_field } = chart;
64
64
 
65
65
  if (!angle_field || !color_field) {
66
- return <ChatError />;
66
+ return <ChartError />;
67
67
  }
68
68
 
69
69
  const angleIndex = columns.indexOf(angle_field);
70
70
  const colorIndex = columns.indexOf(color_field);
71
71
 
72
72
  if (angleIndex === -1 || colorIndex === -1) {
73
- return <ChatError />;
73
+ return <ChartError />;
74
74
  }
75
75
 
76
76
  // 转换数据格式为 Ant Design Charts 需要的格式
@@ -108,14 +108,14 @@ function LineChart(props: { data: ChartData; chart: ChartConfig }) {
108
108
  const { x_field, y_field } = chart;
109
109
 
110
110
  if (!x_field || !y_field) {
111
- return <ChatError />;
111
+ return <ChartError />;
112
112
  }
113
113
 
114
114
  const xIndex = columns.indexOf(x_field);
115
115
  const yIndex = columns.indexOf(y_field);
116
116
 
117
117
  if (xIndex === -1 || yIndex === -1) {
118
- return <ChatError />;
118
+ return <ChartError />;
119
119
  }
120
120
 
121
121
  // 转换数据格式为 Ant Design Charts 需要的格式
@@ -140,14 +140,14 @@ function BarChart(props: { data: ChartData; chart: ChartConfig }) {
140
140
  const { x_field, y_field } = chart;
141
141
 
142
142
  if (!x_field || !y_field) {
143
- return <ChatError />;
143
+ return <ChartError />;
144
144
  }
145
145
 
146
146
  const xIndex = columns.indexOf(x_field);
147
147
  const yIndex = columns.indexOf(y_field);
148
148
 
149
149
  if (xIndex === -1 || yIndex === -1) {
150
- return <ChatError />;
150
+ return <ChartError />;
151
151
  }
152
152
 
153
153
  // 转换数据格式为 Ant Design Charts 需要的格式
@@ -171,14 +171,14 @@ function ScatterChart(props: { data: ChartData; chart: ChartConfig }) {
171
171
  const { x_field, y_field } = chart;
172
172
 
173
173
  if (!x_field || !y_field) {
174
- return <ChatError />;
174
+ return <ChartError />;
175
175
  }
176
176
 
177
177
  const xIndex = columns.indexOf(x_field);
178
178
  const yIndex = columns.indexOf(y_field);
179
179
 
180
180
  if (xIndex === -1 || yIndex === -1) {
181
- return <ChatError />;
181
+ return <ChartError />;
182
182
  }
183
183
 
184
184
  const chartData = rows.map((row) => ({
@@ -195,24 +195,24 @@ function ScatterChart(props: { data: ChartData; chart: ChartConfig }) {
195
195
  return <Scatter {...config} />;
196
196
  }
197
197
 
198
- // 主 ChatBlock 组件
199
- function ChatBlockBase(props: any) {
198
+ // 主 ChartBlock 组件
199
+ function ChartBlockBase(props: any) {
200
200
  const { children } = props;
201
201
 
202
- const chatData = useMemo(() => {
202
+ const chartData = useMemo(() => {
203
203
  try {
204
204
  return JSON.parse(children);
205
205
  } catch (error) {
206
- console.error('Failed to parse chat data:', error);
206
+ console.error('Failed to parse chart data:', error);
207
207
  return null;
208
208
  }
209
209
  }, [children]);
210
210
 
211
- if (!chatData) {
212
- return <ChatError />;
211
+ if (!chartData) {
212
+ return <ChartError />;
213
213
  }
214
214
 
215
- const { data, chart } = chatData;
215
+ const { data, chart } = chartData;
216
216
  const { chart_type, title } = chart;
217
217
 
218
218
  switch (chart_type) {
@@ -244,18 +244,18 @@ function ChatBlockBase(props: any) {
244
244
  // 表格类型暂不处理
245
245
  return null;
246
246
  default:
247
- return <ChatError>不支持的图表类型:{chart_type}</ChatError>;
247
+ return <ChartError>不支持的图表类型:{chart_type}</ChartError>;
248
248
  }
249
249
  }
250
250
 
251
- function ChatBlock(props: any) {
251
+ function ChartBlock(props: any) {
252
252
  const { children } = props;
253
253
 
254
254
  return (
255
255
  <ErrorBoundary>
256
- <ChatBlockBase>{children}</ChatBlockBase>
256
+ <ChartBlockBase>{children}</ChartBlockBase>
257
257
  </ErrorBoundary>
258
258
  );
259
259
  }
260
260
 
261
- export { ChatBlock };
261
+ export { ChartBlock };
@@ -1,14 +1,14 @@
1
1
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
2
2
  import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
3
- import { ChatBlock } from './chat';
3
+ import { ChartBlock } from './chart';
4
4
 
5
5
  function CodeBlock(props: any) {
6
6
  const { children, className, ...rest } = props;
7
7
  const match = /language-(\w+)/.exec(props.className || '');
8
8
 
9
- // 如果是 chat 类型的代码块,使用 ChatBlock 组件
10
- if (match && match[1] === 'chat') {
11
- return <ChatBlock>{children}</ChatBlock>;
9
+ // 如果是 chart 类型的代码块,使用 ChartBlock 组件
10
+ if (match && match[1] === 'chart') {
11
+ return <ChartBlock>{children}</ChartBlock>;
12
12
  }
13
13
 
14
14
  return (
@@ -139,13 +139,13 @@ export const DeepSeekPending: Story = {
139
139
  },
140
140
  };
141
141
 
142
- export const Chat: Story = {
142
+ export const Chart: Story = {
143
143
  args: {
144
- children: `这是一个使用 @ant-design/plots 的 chat 示例
144
+ children: `这是一个使用 @ant-design/plots 的 chart 示例
145
145
 
146
146
  ## 折线图示例
147
147
 
148
- \`\`\`chat
148
+ \`\`\`chart
149
149
  {
150
150
  "data": {
151
151
  "columns": ["time", "amount"],
@@ -168,7 +168,7 @@ export const Chat: Story = {
168
168
 
169
169
  ## 柱状图示例
170
170
 
171
- \`\`\`chat
171
+ \`\`\`chart
172
172
  {
173
173
  "data": {
174
174
  "columns": ["time", "amount"],
@@ -191,7 +191,7 @@ export const Chat: Story = {
191
191
 
192
192
  ## 饼图示例
193
193
 
194
- \`\`\`chat
194
+ \`\`\`chart
195
195
  {
196
196
  "data": {
197
197
  "columns": ["category", "sales"],
@@ -213,7 +213,7 @@ export const Chat: Story = {
213
213
 
214
214
  ## 散点图示例
215
215
 
216
- \`\`\`chat
216
+ \`\`\`chart
217
217
  {
218
218
  "data": {
219
219
  "columns": ["width", "height"],
@@ -236,7 +236,7 @@ export const Chat: Story = {
236
236
 
237
237
  ### JSON 解析错误
238
238
 
239
- \`\`\`chat
239
+ \`\`\`chart
240
240
  {
241
241
  "data": {
242
242
  "columns": ["time", "amount"],
@@ -255,7 +255,7 @@ export const Chat: Story = {
255
255
 
256
256
  ### 字段不存在错误
257
257
 
258
- \`\`\`chat
258
+ \`\`\`chart
259
259
  {
260
260
  "data": {
261
261
  "columns": ["time", "amount"],
@@ -275,7 +275,7 @@ export const Chat: Story = {
275
275
 
276
276
  ### 不支持的图表类型
277
277
 
278
- \`\`\`chat
278
+ \`\`\`chart
279
279
  {
280
280
  "data": {
281
281
  "columns": ["time", "amount"],
@@ -4,16 +4,18 @@
4
4
  }
5
5
 
6
6
  .markdown-body-code-block {
7
+ margin: 0.5rem 0;
8
+
7
9
  & > div {
8
10
  margin: 0 !important;
9
11
  }
10
12
  }
11
13
 
12
- .markdown-body-chat-block {
14
+ .markdown-body-chart-block {
13
15
  background: white;
14
16
  border-radius: 6px;
15
17
 
16
- .markdown-body-chat-block-title {
18
+ .markdown-body-chart-block-title {
17
19
  font-size: 16px;
18
20
  font-weight: bold;
19
21
  margin-bottom: 10px;