@hkyhy/marsun-components-core 0.1.36 → 0.1.37

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,17 +1,17 @@
1
1
  const a = {
2
- "chat-panel": "_chat-panel_5inb6_1",
3
- "chat-panel-head": "_chat-panel-head_5inb6_9",
4
- "chat-panel-head-main": "_chat-panel-head-main_5inb6_19",
5
- "chat-panel-head-extra": "_chat-panel-head-extra_5inb6_27",
6
- "chat-panel-head-actions": "_chat-panel-head-actions_5inb6_32",
7
- "chat-panel-title": "_chat-panel-title_5inb6_60",
8
- "chat-panel-subtitle": "_chat-panel-subtitle_5inb6_68",
9
- "chat-panel-messages-wrapper": "_chat-panel-messages-wrapper_5inb6_75",
10
- "chat-panel-messages": "_chat-panel-messages_5inb6_75",
11
- "chat-panel-empty": "_chat-panel-empty_5inb6_85",
12
- "chat-panel-before-input": "_chat-panel-before-input_5inb6_92",
13
- "chat-panel-follow-up": "_chat-panel-follow-up_5inb6_98",
14
- "chat-panel-input": "_chat-panel-input_5inb6_103"
2
+ "chat-panel": "_chat-panel_1k3zt_1",
3
+ "chat-panel-head": "_chat-panel-head_1k3zt_9",
4
+ "chat-panel-head-main": "_chat-panel-head-main_1k3zt_19",
5
+ "chat-panel-head-extra": "_chat-panel-head-extra_1k3zt_27",
6
+ "chat-panel-head-actions": "_chat-panel-head-actions_1k3zt_32",
7
+ "chat-panel-title": "_chat-panel-title_1k3zt_60",
8
+ "chat-panel-subtitle": "_chat-panel-subtitle_1k3zt_68",
9
+ "chat-panel-messages-wrapper": "_chat-panel-messages-wrapper_1k3zt_75",
10
+ "chat-panel-messages": "_chat-panel-messages_1k3zt_75",
11
+ "chat-panel-empty": "_chat-panel-empty_1k3zt_86",
12
+ "chat-panel-before-input": "_chat-panel-before-input_1k3zt_93",
13
+ "chat-panel-follow-up": "_chat-panel-follow-up_1k3zt_99",
14
+ "chat-panel-input": "_chat-panel-input_1k3zt_104"
15
15
  };
16
16
  export {
17
17
  a as default
@@ -1,265 +1,316 @@
1
- import { jsx as a, jsxs as m, Fragment as ie } from "react/jsx-runtime";
2
- import { User as ne, Bot as ae, BookOpen as oe } from "../../../../Icons/index.js";
3
- import re from "../ChatWidgetBlock/index.js";
4
- import { message as U, Avatar as me, Typography as ce } from "antd";
1
+ import { jsx as o, jsxs as g, Fragment as le } from "react/jsx-runtime";
2
+ import { User as ge, Bot as de, BookOpen as ue } from "../../../../Icons/index.js";
3
+ import pe from "../ChatWidgetBlock/index.js";
4
+ import { message as x, Avatar as he, Typography as fe } from "antd";
5
5
  import i from "classnames";
6
- import { useState as b, useMemo as c, useEffect as D, useCallback as d } from "react";
7
- import ge from "../CitationMarkdownContent/index.js";
8
- import le, { createUserMessageActions as de, createAssistantMessageActions as ue } from "../MessageActions/index.js";
9
- import he from "../ThinkingSection/index.js";
10
- import s from "./style.module.scss.js";
11
- import { parseAssistantContent as pe, normalizeDisplayText as F } from "../../utils/messageContent.js";
12
- import { useTypewriter as M } from "../../hooks/useTypewriter.js";
13
- import { countUniqueCitedSources as fe } from "../../utils/citationContent.js";
14
- const { Text: ke } = ce, Le = ({
6
+ import { useState as C, useMemo as d, useEffect as H, useCallback as h } from "react";
7
+ import ye from "../CitationMarkdownContent/index.js";
8
+ import we, { createUserMessageActions as be, createAssistantMessageActions as ke } from "../MessageActions/index.js";
9
+ import ve from "../ThinkingSection/index.js";
10
+ import n from "./style.module.scss.js";
11
+ import { parseAssistantContent as Te, normalizeDisplayText as J } from "../../utils/messageContent.js";
12
+ import { useTypewriter as K } from "../../hooks/useTypewriter.js";
13
+ import { countUniqueCitedSources as xe } from "../../utils/citationContent.js";
14
+ const { Text: Ce } = fe, Ve = ({
15
15
  message: e,
16
- onCitationClick: g,
17
- onTypingChange: u,
18
- onEditMessage: l,
19
- onResendMessage: L,
20
- onMessageFeedback: v,
21
- editDisabled: G,
22
- feedbackDisabled: T
16
+ onCitationClick: u,
17
+ onTypingChange: f,
18
+ onEditMessage: p,
19
+ onResendMessage: z,
20
+ onMessageFeedback: N,
21
+ editDisabled: Q,
22
+ feedbackDisabled: A
23
23
  }) => {
24
- const n = e.role === "user", [P, h] = b(!1), [N, p] = b(e.content), [x, V] = b(!1), [A, C] = b(e.thumbup), t = c(
25
- () => pe(e.content, !!e.streaming),
24
+ const a = e.role === "user", [E, y] = C(!1), [S, w] = C(e.content), [B, L] = C(!1), [W, I] = C(e.thumbup), t = d(
25
+ () => Te(e.content, !!e.streaming),
26
26
  [e.content, e.streaming]
27
- ), H = !!e.streaming && t.isThinking, { displayed: J, isTyping: K } = M(
27
+ ), X = !!e.streaming && t.isThinking, { displayed: Y, isTyping: Z } = K(
28
28
  t.thinking,
29
- H
30
- ), Q = t.isThinking ? J : t.thinking, { displayed: W, isTyping: f } = M(
29
+ X
30
+ ), _ = t.isThinking ? Y : t.thinking, { displayed: V, isTyping: b } = K(
31
31
  t.answer,
32
32
  !!e.streaming
33
- ), r = c(() => e.citations ?? [], [e.citations]), j = c(
33
+ ), m = d(() => e.citations ?? [], [e.citations]), j = d(
34
34
  () => Array.isArray(e.widgets) ? e.widgets : [],
35
35
  [e.widgets]
36
- ), k = c(
36
+ ), k = d(
37
37
  () => `${t.thinking}
38
38
  ${t.answer}`,
39
39
  [t.thinking, t.answer]
40
- ), w = c(
41
- () => fe(k, r.length),
42
- [k, r.length]
43
- ), R = c(() => r.length === 0 ? "" : w > 0 && w < r.length ? `检索 ${r.length} 个来源 · 正文引用 ${w} 处` : `引用了 ${r.length} 个来源`, [r.length, w]), y = t.isThinking && K;
44
- D(() => {
45
- n || u == null || u(f || y);
46
- }, [n, f, y, u]), D(() => {
47
- C(e.thumbup);
40
+ ), v = d(
41
+ () => xe(k, m.length),
42
+ [k, m.length]
43
+ ), $ = d(() => m.length === 0 ? "" : v > 0 && v < m.length ? `检索 ${m.length} 个来源 · 正文引用 ${v} 处` : `引用了 ${m.length} 个来源`, [m.length, v]), T = t.isThinking && Z;
44
+ H(() => {
45
+ a || f == null || f(b || T);
46
+ }, [a, b, T, f]), H(() => {
47
+ I(e.thumbup);
48
48
  }, [e.id, e.thumbup]);
49
- const S = F(W).trim().length > 0, B = !n && j.length > 0, X = (e.streaming || f) && S, O = f || y, q = !!e.streaming || O, Y = d(() => {
50
- !r.length || !g || g(r);
51
- }, [r, g]), z = d(async (o) => {
52
- if (o.trim())
49
+ const O = J(V).trim().length > 0, P = !a && j.length > 0, ee = (e.streaming || b) && O, R = b || T, q = !!e.streaming || R, te = h(() => {
50
+ !m.length || !u || u(m);
51
+ }, [m, u]), D = h(async (s) => {
52
+ if (!s.trim()) return;
53
+ const U = async () => {
54
+ var r;
55
+ if (!((r = navigator.clipboard) != null && r.readText)) return null;
53
56
  try {
54
- await navigator.clipboard.writeText(o), U.success("已复制");
57
+ return await navigator.clipboard.readText();
55
58
  } catch {
56
- U.error("复制失败");
59
+ return null;
57
60
  }
58
- }, []), E = F(t.answer), Z = !n && !e.streaming && !O && E.trim().length > 0, _ = d(() => {
59
- h(!1), p(e.content);
60
- }, [e.content]), $ = d(() => {
61
- const o = N.trim();
62
- !o || o === e.content.trim() || !l || (l(e.id, o), h(!1));
63
- }, [N, e.content, e.id, l]), I = d(
64
- async (o) => {
65
- if (!(x || T) && A !== o) {
66
- if (v) {
67
- V(!0);
61
+ }, me = async () => {
62
+ if (!navigator.clipboard) return !1;
63
+ if (typeof ClipboardItem < "u" && typeof navigator.clipboard.write == "function")
64
+ try {
65
+ const c = new ClipboardItem({
66
+ "text/plain": Promise.resolve(new Blob([s], { type: "text/plain" }))
67
+ });
68
+ await navigator.clipboard.write([c]);
69
+ const l = await U();
70
+ if (l === null || l === s) return !0;
71
+ if (l === "") return !1;
72
+ } catch {
73
+ }
74
+ if (typeof navigator.clipboard.writeText != "function") return !1;
75
+ await navigator.clipboard.writeText(s);
76
+ const r = await U();
77
+ return r === "" ? !1 : r === null || r === s;
78
+ }, ce = () => {
79
+ const r = document.createElement("div");
80
+ r.textContent = s, r.setAttribute("contenteditable", "true"), r.style.cssText = "position:fixed;top:0;left:0;width:2px;height:2px;padding:0;margin:0;border:none;outline:none;opacity:0.01;overflow:hidden;z-index:2147483647;white-space:pre;user-select:text;-webkit-user-select:text;", document.body.appendChild(r);
81
+ const c = window.getSelection(), l = document.createRange();
82
+ l.selectNodeContents(r), c == null || c.removeAllRanges(), c == null || c.addRange(l), r.focus();
83
+ let G = !1;
84
+ try {
85
+ G = document.execCommand("copy");
86
+ } finally {
87
+ c == null || c.removeAllRanges(), document.body.removeChild(r);
88
+ }
89
+ return G;
90
+ };
91
+ try {
92
+ if (await me()) {
93
+ x.success("已复制");
94
+ return;
95
+ }
96
+ } catch {
97
+ }
98
+ try {
99
+ if (ce()) {
100
+ const r = await U();
101
+ if (r === null || r === s) {
102
+ x.success("已复制");
103
+ return;
104
+ }
105
+ }
106
+ } catch {
107
+ }
108
+ x.error("复制失败,请手动选择文本复制");
109
+ }, []), F = J(t.answer), ne = !a && !e.streaming && !R && F.trim().length > 0, se = h(() => {
110
+ y(!1), w(e.content);
111
+ }, [e.content]), ie = h(() => {
112
+ const s = S.trim();
113
+ !s || s === e.content.trim() || !p || (p(e.id, s), y(!1));
114
+ }, [S, e.content, e.id, p]), M = h(
115
+ async (s) => {
116
+ if (!(B || A) && W !== s) {
117
+ if (N) {
118
+ L(!0);
68
119
  try {
69
- await v(e.id, o), C(o);
120
+ await N(e.id, s), I(s);
70
121
  } catch {
71
122
  } finally {
72
- V(!1);
123
+ L(!1);
73
124
  }
74
125
  return;
75
126
  }
76
- C(o), U.success("感谢反馈");
127
+ I(s), x.success("感谢反馈");
77
128
  }
78
129
  },
79
- [T, x, A, e.id, v]
80
- ), ee = n ? de({
81
- onEdit: l ? () => {
82
- p(e.content), h(!0);
130
+ [A, B, W, e.id, N]
131
+ ), ae = a ? be({
132
+ onEdit: p ? () => {
133
+ w(e.content), y(!0);
83
134
  } : void 0,
84
- onCopy: () => z(e.content),
85
- onResend: L ? () => L(e.content) : void 0,
86
- editDisabled: G
87
- }) : ue({
135
+ onCopy: () => D(e.content),
136
+ onResend: z ? () => z(e.content) : void 0,
137
+ editDisabled: Q
138
+ }) : ke({
88
139
  onLike: () => {
89
- I(!0);
140
+ M(!0);
90
141
  },
91
142
  onDislike: () => {
92
- I(!1);
143
+ M(!1);
93
144
  },
94
- onCopy: () => z(E),
95
- thumbup: A,
96
- feedbackDisabled: T || x
97
- }), te = l ? {
98
- open: P,
99
- value: N,
145
+ onCopy: () => D(F),
146
+ thumbup: W,
147
+ feedbackDisabled: A || B
148
+ }), re = p ? {
149
+ open: E,
150
+ value: S,
100
151
  originalContent: e.content,
101
- onOpenChange: (o) => {
102
- h(o), o || p(e.content);
152
+ onOpenChange: (s) => {
153
+ y(s), s || w(e.content);
103
154
  },
104
- onChange: p,
105
- onConfirm: $,
106
- onCancel: _
107
- } : void 0, se = /* @__PURE__ */ a(
155
+ onChange: w,
156
+ onConfirm: ie,
157
+ onCancel: se
158
+ } : void 0, oe = /* @__PURE__ */ o(
108
159
  "div",
109
160
  {
110
161
  className: i(
111
162
  "message-item-message-user-bubble",
112
- s["message-item-message-user-bubble"],
163
+ n["message-item-message-user-bubble"],
113
164
  "bg-primary"
114
165
  ),
115
- children: /* @__PURE__ */ a(
166
+ children: /* @__PURE__ */ o(
116
167
  "span",
117
168
  {
118
169
  className: i(
119
170
  "message-item-message-user-bubble-text",
120
- s["message-item-message-user-bubble-text"]
171
+ n["message-item-message-user-bubble-text"]
121
172
  ),
122
173
  children: e.content
123
174
  }
124
175
  )
125
176
  }
126
177
  );
127
- return /* @__PURE__ */ m(
178
+ return /* @__PURE__ */ g(
128
179
  "div",
129
180
  {
130
181
  className: i(
131
182
  "group",
132
183
  "message-row",
133
- s["message-item-message-row"],
134
- n && "message-item-message-row-reverse",
135
- n && s["message-item-message-row-reverse"]
184
+ n["message-item-message-row"],
185
+ a && "message-item-message-row-reverse",
186
+ a && n["message-item-message-row-reverse"]
136
187
  ),
137
188
  children: [
138
- /* @__PURE__ */ a(
139
- me,
189
+ /* @__PURE__ */ o(
190
+ he,
140
191
  {
141
192
  size: 34,
142
- icon: n ? /* @__PURE__ */ a(ne, {}) : /* @__PURE__ */ a(ae, {}),
193
+ icon: a ? /* @__PURE__ */ o(ge, {}) : /* @__PURE__ */ o(de, {}),
143
194
  className: i(
144
195
  "message-item-message-avatar",
145
- s["message-item-message-avatar"],
146
- !n && "message-item-message-avatar-assistant",
147
- !n && s["message-item-message-avatar-assistant"]
196
+ n["message-item-message-avatar"],
197
+ !a && "message-item-message-avatar-assistant",
198
+ !a && n["message-item-message-avatar-assistant"]
148
199
  ),
149
- style: n ? {} : { color: "var(--primary-color)" }
200
+ style: a ? {} : { color: "var(--primary-color)" }
150
201
  }
151
202
  ),
152
- /* @__PURE__ */ m(
203
+ /* @__PURE__ */ g(
153
204
  "div",
154
205
  {
155
206
  className: i(
156
207
  "message-item-message-content",
157
- s["message-item-message-content"],
158
- n ? i(
208
+ n["message-item-message-content"],
209
+ a ? i(
159
210
  "message-item-message-content-user",
160
- s["message-item-message-content-user"]
211
+ n["message-item-message-content-user"]
161
212
  ) : i(
162
213
  "message-item-message-content-assistant",
163
- s["message-item-message-content-assistant"]
214
+ n["message-item-message-content-assistant"]
164
215
  )
165
216
  ),
166
217
  children: [
167
- /* @__PURE__ */ a(
218
+ /* @__PURE__ */ o(
168
219
  "div",
169
220
  {
170
- className: n ? void 0 : i(
221
+ className: a ? void 0 : i(
171
222
  "message-item-message-assistant-bubble",
172
- s["message-item-message-assistant-bubble"]
223
+ n["message-item-message-assistant-bubble"]
173
224
  ),
174
- children: n ? se : e.streaming && !t.thinking && !t.isThinking && !S && !B ? /* @__PURE__ */ m(
225
+ children: a ? oe : e.streaming && !t.thinking && !t.isThinking && !O && !P ? /* @__PURE__ */ g(
175
226
  "div",
176
227
  {
177
228
  className: i(
178
229
  "message-item-message-loading-dots",
179
- s["message-item-message-loading-dots"]
230
+ n["message-item-message-loading-dots"]
180
231
  ),
181
232
  children: [
182
- /* @__PURE__ */ a(
233
+ /* @__PURE__ */ o(
183
234
  "span",
184
235
  {
185
236
  className: i(
186
237
  "message-item-message-loading-dot",
187
- s["message-item-message-loading-dot"]
238
+ n["message-item-message-loading-dot"]
188
239
  )
189
240
  }
190
241
  ),
191
- /* @__PURE__ */ a(
242
+ /* @__PURE__ */ o(
192
243
  "span",
193
244
  {
194
245
  className: i(
195
246
  "message-item-message-loading-dot",
196
- s["message-item-message-loading-dot"]
247
+ n["message-item-message-loading-dot"]
197
248
  )
198
249
  }
199
250
  ),
200
- /* @__PURE__ */ a(
251
+ /* @__PURE__ */ o(
201
252
  "span",
202
253
  {
203
254
  className: i(
204
255
  "message-item-message-loading-dot",
205
- s["message-item-message-loading-dot"]
256
+ n["message-item-message-loading-dot"]
206
257
  )
207
258
  }
208
259
  )
209
260
  ]
210
261
  }
211
- ) : /* @__PURE__ */ m(ie, { children: [
212
- (t.thinking || t.isThinking) && /* @__PURE__ */ a(
213
- he,
262
+ ) : /* @__PURE__ */ g(le, { children: [
263
+ (t.thinking || t.isThinking) && /* @__PURE__ */ o(
264
+ ve,
214
265
  {
215
- thinking: Q,
266
+ thinking: _,
216
267
  isThinking: t.isThinking,
217
- isTyping: y,
218
- citations: r,
268
+ isTyping: T,
269
+ citations: m,
219
270
  citationSourceContent: k,
220
- onCitationClick: g,
271
+ onCitationClick: u,
221
272
  deferMermaid: q
222
273
  }
223
274
  ),
224
- B ? /* @__PURE__ */ a(
225
- re,
275
+ P ? /* @__PURE__ */ o(
276
+ pe,
226
277
  {
227
278
  widgets: j,
228
279
  compact: !0,
229
280
  leading: !0,
230
281
  className: i(
231
- (t.thinking || t.isThinking) && s["message-item-message-widgets-after-thinking"]
282
+ (t.thinking || t.isThinking) && n["message-item-message-widgets-after-thinking"]
232
283
  )
233
284
  }
234
285
  ) : null,
235
- S && /* @__PURE__ */ m(
286
+ O && /* @__PURE__ */ g(
236
287
  "div",
237
288
  {
238
289
  className: i(
239
290
  "markdown-preview",
240
291
  "message-answer-markdown",
241
- s["message-item-message-answer-markdown"],
292
+ n["message-item-message-answer-markdown"],
242
293
  (t.thinking || t.isThinking) && "message-answer-markdown-spaced",
243
- (t.thinking || t.isThinking) && s["message-item-message-answer-markdown-spaced"],
244
- B && s["message-item-message-answer-markdown-after-widgets"]
294
+ (t.thinking || t.isThinking) && n["message-item-message-answer-markdown-spaced"],
295
+ P && n["message-item-message-answer-markdown-after-widgets"]
245
296
  ),
246
297
  children: [
247
- /* @__PURE__ */ a(
248
- ge,
298
+ /* @__PURE__ */ o(
299
+ ye,
249
300
  {
250
- content: W,
251
- citations: r,
301
+ content: V,
302
+ citations: m,
252
303
  citationSourceContent: k,
253
- onCitationClick: g,
304
+ onCitationClick: u,
254
305
  deferMermaid: q
255
306
  }
256
307
  ),
257
- X && /* @__PURE__ */ a(
308
+ ee && /* @__PURE__ */ o(
258
309
  "span",
259
310
  {
260
311
  className: i(
261
312
  "message-item-message-typing-cursor",
262
- s["message-item-message-typing-cursor"]
313
+ n["message-item-message-typing-cursor"]
263
314
  )
264
315
  }
265
316
  )
@@ -269,44 +320,44 @@ ${t.answer}`,
269
320
  ] })
270
321
  }
271
322
  ),
272
- (n || Z) && /* @__PURE__ */ a(
273
- le,
323
+ (a || ne) && /* @__PURE__ */ o(
324
+ we,
274
325
  {
275
- items: ee,
276
- align: n ? "right" : "left",
277
- editPopover: te,
278
- actionsVisible: P
326
+ items: ae,
327
+ align: a ? "right" : "left",
328
+ editPopover: re,
329
+ actionsVisible: E
279
330
  }
280
331
  ),
281
- !n && r.length > 0 && !O && /* @__PURE__ */ m(
332
+ !a && m.length > 0 && !R && /* @__PURE__ */ g(
282
333
  "button",
283
334
  {
284
335
  type: "button",
285
- onClick: Y,
336
+ onClick: te,
286
337
  className: i(
287
338
  "message-item-citation-summary-button",
288
- s["message-item-citation-summary-button"]
339
+ n["message-item-citation-summary-button"]
289
340
  ),
290
341
  children: [
291
- /* @__PURE__ */ a(
292
- oe,
342
+ /* @__PURE__ */ o(
343
+ ue,
293
344
  {
294
345
  className: i(
295
346
  "text-primary",
296
347
  "citation-summary-icon",
297
- s["message-item-citation-summary-icon"]
348
+ n["message-item-citation-summary-icon"]
298
349
  )
299
350
  }
300
351
  ),
301
- /* @__PURE__ */ a(
302
- ke,
352
+ /* @__PURE__ */ o(
353
+ Ce,
303
354
  {
304
355
  className: i(
305
356
  "text-primary",
306
357
  "citation-summary-text",
307
- s["message-item-citation-summary-text"]
358
+ n["message-item-citation-summary-text"]
308
359
  ),
309
- children: R
360
+ children: $
310
361
  }
311
362
  )
312
363
  ]
@@ -320,6 +371,6 @@ ${t.answer}`,
320
371
  );
321
372
  };
322
373
  export {
323
- Le as default
374
+ Ve as default
324
375
  };
325
376
  //# sourceMappingURL=index.js.map