@xiping/react-components 1.0.7 → 1.0.9
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.
|
@@ -1,75 +1,205 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as s, jsx as e, Fragment as y } from "react/jsx-runtime";
|
|
2
|
+
import { useState as x } from "react";
|
|
3
|
+
import n from "react-markdown";
|
|
2
4
|
/* empty css */
|
|
3
5
|
const q = ({
|
|
4
|
-
id:
|
|
5
|
-
content:
|
|
6
|
-
sender:
|
|
7
|
-
timestamp:
|
|
8
|
-
isThinking:
|
|
9
|
-
isLoading:
|
|
10
|
-
className:
|
|
11
|
-
style:
|
|
12
|
-
showTimestamp:
|
|
13
|
-
avatarUser:
|
|
14
|
-
avatarAssistant:
|
|
15
|
-
thinkingText:
|
|
16
|
-
customThinkingComponent:
|
|
17
|
-
customUserMessageComponent:
|
|
18
|
-
customAssistantMessageComponent:
|
|
19
|
-
parseContent:
|
|
20
|
-
parsedContent:
|
|
21
|
-
thinkContent:
|
|
22
|
-
knowledgeSources:
|
|
6
|
+
id: j,
|
|
7
|
+
content: o,
|
|
8
|
+
sender: t,
|
|
9
|
+
timestamp: d,
|
|
10
|
+
isThinking: c = !1,
|
|
11
|
+
isLoading: V = !1,
|
|
12
|
+
className: B = "",
|
|
13
|
+
style: H = {},
|
|
14
|
+
showTimestamp: h = !0,
|
|
15
|
+
avatarUser: m,
|
|
16
|
+
avatarAssistant: g,
|
|
17
|
+
thinkingText: M = "思考中...",
|
|
18
|
+
customThinkingComponent: u,
|
|
19
|
+
customUserMessageComponent: p,
|
|
20
|
+
customAssistantMessageComponent: k,
|
|
21
|
+
parseContent: W = !1,
|
|
22
|
+
parsedContent: v,
|
|
23
|
+
thinkContent: a,
|
|
24
|
+
knowledgeSources: l
|
|
23
25
|
}) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const [r, N] = x(!0), [$, w] = x("idle");
|
|
27
|
+
console.log(j, "id");
|
|
28
|
+
const f = (i) => i.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), I = async () => {
|
|
29
|
+
try {
|
|
30
|
+
await navigator.clipboard.writeText(o), w("copied"), setTimeout(() => w("idle"), 2e3);
|
|
31
|
+
} catch (i) {
|
|
32
|
+
console.error("复制失败:", i);
|
|
33
|
+
}
|
|
34
|
+
}, C = () => u || /* @__PURE__ */ s("div", { className: "message-thinking", children: [
|
|
35
|
+
/* @__PURE__ */ s("div", { className: "message-thinking-dots", children: [
|
|
27
36
|
/* @__PURE__ */ e("span", {}),
|
|
28
37
|
/* @__PURE__ */ e("span", {}),
|
|
29
38
|
/* @__PURE__ */ e("span", {})
|
|
30
39
|
] }),
|
|
31
|
-
/* @__PURE__ */ e("span", { className: "message-thinking-text", children:
|
|
32
|
-
] }),
|
|
40
|
+
/* @__PURE__ */ e("span", { className: "message-thinking-text", children: M })
|
|
41
|
+
] }), S = () => /* @__PURE__ */ e("div", { className: "message-loading", children: /* @__PURE__ */ e("div", { className: "message-loading-spinner" }) }), L = () => !l || l.length === 0 ? null : /* @__PURE__ */ s("div", { className: "message-knowledge-sources", children: [
|
|
33
42
|
/* @__PURE__ */ e("div", { className: "message-knowledge-sources-header", children: "知识来源:" }),
|
|
34
|
-
/* @__PURE__ */ e("ul", { className: "message-knowledge-sources-list", children:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
] },
|
|
38
|
-
] }),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
/* @__PURE__ */ e("ul", { className: "message-knowledge-sources-list", children: l.map((i, F) => /* @__PURE__ */ s("li", { className: "message-knowledge-source-item", children: [
|
|
44
|
+
i.url ? /* @__PURE__ */ e("a", { href: i.url, target: "_blank", rel: "noopener noreferrer", children: i.title }) : /* @__PURE__ */ e("span", { children: i.title }),
|
|
45
|
+
i.description && /* @__PURE__ */ e("div", { className: "message-knowledge-source-description", children: i.description })
|
|
46
|
+
] }, F)) })
|
|
47
|
+
] }), b = () => t === "user" ? null : /* @__PURE__ */ s(
|
|
48
|
+
"button",
|
|
49
|
+
{
|
|
50
|
+
className: "message-copy-button",
|
|
51
|
+
onClick: I,
|
|
52
|
+
"aria-label": "Copy message",
|
|
53
|
+
title: "Copy message",
|
|
54
|
+
children: [
|
|
55
|
+
/* @__PURE__ */ s(
|
|
56
|
+
"svg",
|
|
57
|
+
{
|
|
58
|
+
width: "14",
|
|
59
|
+
height: "14",
|
|
60
|
+
viewBox: "0 0 16 16",
|
|
61
|
+
fill: "none",
|
|
62
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ e(
|
|
65
|
+
"path",
|
|
66
|
+
{
|
|
67
|
+
d: "M13.3333 6H7.33333C6.59695 6 6 6.59695 6 7.33333V13.3333C6 14.0697 6.59695 14.6667 7.33333 14.6667H13.3333C14.0697 14.6667 14.6667 14.0697 14.6667 13.3333V7.33333C14.6667 6.59695 14.0697 6 13.3333 6Z",
|
|
68
|
+
stroke: "currentColor",
|
|
69
|
+
strokeWidth: "1.5",
|
|
70
|
+
strokeLinecap: "round",
|
|
71
|
+
strokeLinejoin: "round"
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
/* @__PURE__ */ e(
|
|
75
|
+
"path",
|
|
76
|
+
{
|
|
77
|
+
d: "M3.33333 10H2.66667C2.31305 10 1.97391 9.85953 1.72386 9.60948C1.47381 9.35943 1.33334 9.02029 1.33334 8.66667V2.66667C1.33334 2.31305 1.47381 1.97391 1.72386 1.72386C1.97391 1.47381 2.31305 1.33334 2.66667 1.33334H8.66667C9.02029 1.33334 9.35943 1.47381 9.60948 1.72386C9.85953 1.97391 10 2.31305 10 2.66667V3.33334",
|
|
78
|
+
stroke: "currentColor",
|
|
79
|
+
strokeWidth: "1.5",
|
|
80
|
+
strokeLinecap: "round",
|
|
81
|
+
strokeLinejoin: "round"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
$ === "copied" && /* @__PURE__ */ e("span", { className: "message-copy-tooltip", children: "Copied" })
|
|
88
|
+
]
|
|
57
89
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
d && u(),
|
|
61
|
-
N(),
|
|
62
|
-
c && /* @__PURE__ */ e("div", { className: "message-timestamp", children: o(l) })
|
|
63
|
-
] });
|
|
64
|
-
};
|
|
65
|
-
return /* @__PURE__ */ a(
|
|
90
|
+
);
|
|
91
|
+
return t === "user" && p ? p : t === "assistant" && k ? k : /* @__PURE__ */ s(
|
|
66
92
|
"div",
|
|
67
93
|
{
|
|
68
|
-
className: `message ${
|
|
69
|
-
style:
|
|
94
|
+
className: `message ${t === "user" ? "user" : "assistant"} ${B}`,
|
|
95
|
+
style: H,
|
|
70
96
|
children: [
|
|
71
|
-
/* @__PURE__ */ e("div", { className: "message-avatar", children:
|
|
72
|
-
/* @__PURE__ */ e("div", { className: "message-content", children:
|
|
97
|
+
t === "user" && m || t === "assistant" && g ? /* @__PURE__ */ e("div", { className: "message-avatar", children: t === "user" ? m : g }) : null,
|
|
98
|
+
/* @__PURE__ */ e("div", { className: "message-content", children: V ? S() : W && t === "assistant" ? /* @__PURE__ */ s(y, { children: [
|
|
99
|
+
a && /* @__PURE__ */ s("div", { className: "message-think", children: [
|
|
100
|
+
/* @__PURE__ */ s("div", { className: "message-think-header", children: [
|
|
101
|
+
"思考过程:",
|
|
102
|
+
/* @__PURE__ */ e(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
className: "message-think-toggle",
|
|
106
|
+
onClick: () => N(!r),
|
|
107
|
+
"aria-label": r ? "隐藏思考过程" : "显示思考过程",
|
|
108
|
+
children: /* @__PURE__ */ e(
|
|
109
|
+
"svg",
|
|
110
|
+
{
|
|
111
|
+
width: "12",
|
|
112
|
+
height: "12",
|
|
113
|
+
viewBox: "0 0 12 12",
|
|
114
|
+
fill: "none",
|
|
115
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
116
|
+
style: {
|
|
117
|
+
transform: r ? "rotate(180deg)" : "rotate(0deg)",
|
|
118
|
+
transition: "transform 0.3s ease"
|
|
119
|
+
},
|
|
120
|
+
children: /* @__PURE__ */ e(
|
|
121
|
+
"path",
|
|
122
|
+
{
|
|
123
|
+
d: "M2 4L6 8L10 4",
|
|
124
|
+
stroke: "currentColor",
|
|
125
|
+
strokeWidth: "1.5",
|
|
126
|
+
strokeLinecap: "round",
|
|
127
|
+
strokeLinejoin: "round"
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
] }),
|
|
135
|
+
/* @__PURE__ */ e(
|
|
136
|
+
"div",
|
|
137
|
+
{
|
|
138
|
+
className: `message-think-content ${r ? "visible" : "hidden"}`,
|
|
139
|
+
children: /* @__PURE__ */ e(n, { children: a })
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
] }),
|
|
143
|
+
c && C(),
|
|
144
|
+
v && /* @__PURE__ */ s("div", { className: "message-text-container", children: [
|
|
145
|
+
/* @__PURE__ */ e("div", { className: "message-text", children: /* @__PURE__ */ e(n, { children: v }) }),
|
|
146
|
+
b()
|
|
147
|
+
] }),
|
|
148
|
+
L(),
|
|
149
|
+
h && /* @__PURE__ */ e("div", { className: "message-timestamp", children: f(d) })
|
|
150
|
+
] }) : /* @__PURE__ */ s(y, { children: [
|
|
151
|
+
a && /* @__PURE__ */ s("div", { className: "message-think", children: [
|
|
152
|
+
/* @__PURE__ */ s("div", { className: "message-think-header", children: [
|
|
153
|
+
"思考过程:",
|
|
154
|
+
/* @__PURE__ */ e(
|
|
155
|
+
"button",
|
|
156
|
+
{
|
|
157
|
+
className: "message-think-toggle",
|
|
158
|
+
onClick: () => N(!r),
|
|
159
|
+
"aria-label": r ? "隐藏思考过程" : "显示思考过程",
|
|
160
|
+
children: /* @__PURE__ */ e(
|
|
161
|
+
"svg",
|
|
162
|
+
{
|
|
163
|
+
width: "12",
|
|
164
|
+
height: "12",
|
|
165
|
+
viewBox: "0 0 12 12",
|
|
166
|
+
fill: "none",
|
|
167
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
168
|
+
style: {
|
|
169
|
+
transform: r ? "rotate(180deg)" : "rotate(0deg)",
|
|
170
|
+
transition: "transform 0.3s ease"
|
|
171
|
+
},
|
|
172
|
+
children: /* @__PURE__ */ e(
|
|
173
|
+
"path",
|
|
174
|
+
{
|
|
175
|
+
d: "M2 4L6 8L10 4",
|
|
176
|
+
stroke: "currentColor",
|
|
177
|
+
strokeWidth: "1.5",
|
|
178
|
+
strokeLinecap: "round",
|
|
179
|
+
strokeLinejoin: "round"
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ e(
|
|
188
|
+
"div",
|
|
189
|
+
{
|
|
190
|
+
className: `message-think-content ${r ? "visible" : "hidden"}`,
|
|
191
|
+
children: /* @__PURE__ */ e(n, { children: a })
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
] }),
|
|
195
|
+
/* @__PURE__ */ s("div", { className: "message-text-container", children: [
|
|
196
|
+
/* @__PURE__ */ e("div", { className: "message-text", children: /* @__PURE__ */ e(n, { children: o }) }),
|
|
197
|
+
b()
|
|
198
|
+
] }),
|
|
199
|
+
c && C(),
|
|
200
|
+
L(),
|
|
201
|
+
h && /* @__PURE__ */ e("div", { className: "message-timestamp", children: f(d) })
|
|
202
|
+
] }) })
|
|
73
203
|
]
|
|
74
204
|
}
|
|
75
205
|
);
|