@aura-react-comp/x 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +80 -2
- package/esm/actions/index.d.ts +28 -0
- package/esm/actions/index.js +37 -0
- package/esm/actions/index.less +59 -0
- package/esm/attachments/index.d.ts +41 -0
- package/esm/attachments/index.js +48 -0
- package/esm/attachments/index.less +22 -0
- package/esm/bubble/index.d.ts +42 -0
- package/esm/bubble/index.js +80 -0
- package/esm/bubble/index.less +164 -0
- package/esm/code-highlighter/index.d.ts +39 -0
- package/esm/code-highlighter/index.js +165 -0
- package/esm/code-highlighter/index.less +76 -0
- package/esm/code-highlighter/prism-theme.d.ts +13 -0
- package/esm/code-highlighter/prism-theme.js +75 -0
- package/esm/conversations/index.d.ts +35 -0
- package/esm/conversations/index.js +89 -0
- package/esm/conversations/index.less +138 -0
- package/esm/file-card/index.d.ts +40 -0
- package/esm/file-card/index.js +126 -0
- package/esm/file-card/index.less +161 -0
- package/esm/folder/index.d.ts +66 -0
- package/esm/folder/index.js +345 -0
- package/esm/folder/index.less +158 -0
- package/esm/folder/tree-utils.d.ts +30 -0
- package/esm/folder/tree-utils.js +147 -0
- package/esm/folder/types.d.ts +51 -0
- package/esm/folder/types.js +1 -0
- package/esm/index.d.ts +40 -0
- package/esm/index.js +20 -0
- package/esm/markdown-content/index.d.ts +34 -0
- package/esm/markdown-content/index.js +117 -0
- package/esm/markdown-content/index.less +124 -0
- package/esm/mermaid/index.d.ts +47 -0
- package/esm/mermaid/index.js +235 -0
- package/esm/mermaid/index.less +155 -0
- package/esm/notification/index.d.ts +59 -0
- package/esm/notification/index.js +148 -0
- package/esm/prompts/index.d.ts +27 -0
- package/esm/prompts/index.js +50 -0
- package/esm/prompts/index.less +95 -0
- package/esm/sender/index.d.ts +48 -0
- package/esm/sender/index.js +88 -0
- package/esm/sender/index.less +75 -0
- package/esm/sources/index.d.ts +40 -0
- package/esm/sources/index.js +154 -0
- package/esm/sources/index.less +219 -0
- package/esm/style.css +1565 -0
- package/esm/suggestion/index.d.ts +21 -0
- package/esm/suggestion/index.js +36 -0
- package/esm/suggestion/index.less +44 -0
- package/esm/think/index.d.ts +20 -0
- package/esm/think/index.js +48 -0
- package/esm/think/index.less +92 -0
- package/esm/thought-chain/index.d.ts +34 -0
- package/esm/thought-chain/index.js +105 -0
- package/esm/thought-chain/index.less +174 -0
- package/esm/use-x-chat/index.d.ts +85 -0
- package/esm/use-x-chat/index.js +178 -0
- package/esm/use-x-stream/index.d.ts +43 -0
- package/esm/use-x-stream/index.js +112 -0
- package/esm/use-x-stream/parse-sse.d.ts +19 -0
- package/esm/use-x-stream/parse-sse.js +91 -0
- package/esm/utils/color.d.ts +9 -0
- package/esm/utils/color.js +45 -0
- package/esm/welcome/index.d.ts +22 -0
- package/esm/welcome/index.js +36 -0
- package/esm/welcome/index.less +57 -0
- package/esm/x-provider/index.d.ts +48 -0
- package/esm/x-provider/index.js +66 -0
- package/package.json +69 -3
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
/** 头部默认标题:按条数生成,无来源时不展示头部 */
|
|
7
|
+
function defaultTitle(count) {
|
|
8
|
+
return `已引用 ${count} 个来源`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sources — 来源引用。
|
|
13
|
+
*
|
|
14
|
+
* 联网搜索 / RAG 场景下展示答案引用到的数据来源:头部一行摘要 + 有序列表。
|
|
15
|
+
* 每项支持图标、标题、外链与描述;`inline` 模式改为正文中的上标序号,
|
|
16
|
+
* 悬停或聚焦时浮出详情,适合与段落混排。
|
|
17
|
+
*/
|
|
18
|
+
export const Sources = ({
|
|
19
|
+
title,
|
|
20
|
+
items,
|
|
21
|
+
expandIconPosition = 'start',
|
|
22
|
+
defaultExpanded = true,
|
|
23
|
+
expanded,
|
|
24
|
+
onExpand,
|
|
25
|
+
onClick,
|
|
26
|
+
inline = false,
|
|
27
|
+
activeKey,
|
|
28
|
+
popoverOverlayWidth = 300,
|
|
29
|
+
className,
|
|
30
|
+
style
|
|
31
|
+
}) => {
|
|
32
|
+
const [innerOpen, setInnerOpen] = useState(defaultExpanded);
|
|
33
|
+
const [hoveredKey, setHoveredKey] = useState(null);
|
|
34
|
+
const isOpenControlled = expanded !== undefined;
|
|
35
|
+
const isOpen = isOpenControlled ? expanded : innerOpen;
|
|
36
|
+
const toggle = useCallback(() => {
|
|
37
|
+
const next = !isOpen;
|
|
38
|
+
if (!isOpenControlled) setInnerOpen(next);
|
|
39
|
+
onExpand?.(next);
|
|
40
|
+
}, [isOpen, isOpenControlled, onExpand]);
|
|
41
|
+
const keyOf = (item, index) => item.key ?? index;
|
|
42
|
+
|
|
43
|
+
/** 单条来源的正文(序号 + 图标 + 标题) */
|
|
44
|
+
const renderBody = (item, index) => /*#__PURE__*/_jsxs(_Fragment, {
|
|
45
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
46
|
+
className: prefixCls('x-sources-item-index'),
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
children: index + 1
|
|
49
|
+
}), item.icon ? /*#__PURE__*/_jsx("span", {
|
|
50
|
+
className: prefixCls('x-sources-item-icon'),
|
|
51
|
+
"aria-hidden": "true",
|
|
52
|
+
children: item.icon
|
|
53
|
+
}) : null, /*#__PURE__*/_jsx("span", {
|
|
54
|
+
className: prefixCls('x-sources-item-title'),
|
|
55
|
+
children: item.title
|
|
56
|
+
})]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// 空列表渲染 null(与 Suggestion / Attachments 的约定一致)
|
|
60
|
+
if (items.length === 0) return null;
|
|
61
|
+
if (inline) {
|
|
62
|
+
return /*#__PURE__*/_jsx("span", {
|
|
63
|
+
className: classNames(prefixCls('x-sources'), prefixCls('x-sources--inline'), className),
|
|
64
|
+
style: style,
|
|
65
|
+
children: items.map((item, index) => {
|
|
66
|
+
const key = keyOf(item, index);
|
|
67
|
+
const active = activeKey !== undefined ? activeKey === key : hoveredKey === key;
|
|
68
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
69
|
+
className: prefixCls('x-sources-inline-wrap'),
|
|
70
|
+
onMouseEnter: () => setHoveredKey(key),
|
|
71
|
+
onMouseLeave: () => setHoveredKey(null),
|
|
72
|
+
children: [/*#__PURE__*/_jsx("button", {
|
|
73
|
+
type: "button",
|
|
74
|
+
className: classNames(prefixCls('x-sources-inline-chip'), active && prefixCls('x-sources-inline-chip--active')),
|
|
75
|
+
"aria-expanded": active,
|
|
76
|
+
onFocus: () => setHoveredKey(key),
|
|
77
|
+
onBlur: () => setHoveredKey(null),
|
|
78
|
+
onClick: () => onClick?.(item),
|
|
79
|
+
onKeyDown: event => {
|
|
80
|
+
if (event.key === 'Escape') setHoveredKey(null);
|
|
81
|
+
},
|
|
82
|
+
children: index + 1
|
|
83
|
+
}), active ? /*#__PURE__*/_jsxs("span", {
|
|
84
|
+
role: "tooltip",
|
|
85
|
+
className: prefixCls('x-sources-popover'),
|
|
86
|
+
style: {
|
|
87
|
+
width: popoverOverlayWidth
|
|
88
|
+
},
|
|
89
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
90
|
+
className: prefixCls('x-sources-popover-title'),
|
|
91
|
+
children: item.title
|
|
92
|
+
}), item.description ? /*#__PURE__*/_jsx("span", {
|
|
93
|
+
className: prefixCls('x-sources-popover-desc'),
|
|
94
|
+
children: item.description
|
|
95
|
+
}) : null, item.url ? /*#__PURE__*/_jsx("a", {
|
|
96
|
+
className: prefixCls('x-sources-popover-url'),
|
|
97
|
+
href: item.url,
|
|
98
|
+
target: "_blank",
|
|
99
|
+
rel: "noreferrer",
|
|
100
|
+
children: item.url
|
|
101
|
+
}) : null]
|
|
102
|
+
}) : null]
|
|
103
|
+
}, key);
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
108
|
+
className: classNames(prefixCls('x-sources'), className),
|
|
109
|
+
style: style,
|
|
110
|
+
children: [/*#__PURE__*/_jsxs("button", {
|
|
111
|
+
type: "button",
|
|
112
|
+
className: classNames(prefixCls('x-sources-header'), prefixCls(`x-sources-header--${expandIconPosition}`)),
|
|
113
|
+
onClick: toggle,
|
|
114
|
+
"aria-expanded": isOpen,
|
|
115
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
116
|
+
className: prefixCls('x-sources-caret'),
|
|
117
|
+
"aria-hidden": "true",
|
|
118
|
+
children: isOpen ? '▾' : '▸'
|
|
119
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
120
|
+
className: prefixCls('x-sources-title'),
|
|
121
|
+
children: title ?? defaultTitle(items.length)
|
|
122
|
+
})]
|
|
123
|
+
}), isOpen ? /*#__PURE__*/_jsx("ol", {
|
|
124
|
+
className: prefixCls('x-sources-list'),
|
|
125
|
+
children: items.map((item, index) => {
|
|
126
|
+
const key = keyOf(item, index);
|
|
127
|
+
const body = renderBody(item, index);
|
|
128
|
+
return /*#__PURE__*/_jsxs("li", {
|
|
129
|
+
className: prefixCls('x-sources-item'),
|
|
130
|
+
children: [item.url ? /*#__PURE__*/_jsx("a", {
|
|
131
|
+
className: prefixCls('x-sources-item-main'),
|
|
132
|
+
href: item.url,
|
|
133
|
+
target: "_blank",
|
|
134
|
+
rel: "noreferrer",
|
|
135
|
+
onClick: () => onClick?.(item),
|
|
136
|
+
children: body
|
|
137
|
+
}) : onClick ? /*#__PURE__*/_jsx("button", {
|
|
138
|
+
type: "button",
|
|
139
|
+
className: prefixCls('x-sources-item-main'),
|
|
140
|
+
onClick: () => onClick(item),
|
|
141
|
+
children: body
|
|
142
|
+
}) : /*#__PURE__*/_jsx("span", {
|
|
143
|
+
className: prefixCls('x-sources-item-main'),
|
|
144
|
+
children: body
|
|
145
|
+
}), item.description ? /*#__PURE__*/_jsx("div", {
|
|
146
|
+
className: prefixCls('x-sources-item-desc'),
|
|
147
|
+
children: item.description
|
|
148
|
+
}) : null]
|
|
149
|
+
}, key);
|
|
150
|
+
})
|
|
151
|
+
}) : null]
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
Sources.displayName = 'Sources';
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* Sources — 来源引用(头部摘要 + 有序列表 / 行内上标) */
|
|
2
|
+
|
|
3
|
+
.aura-x-sources {
|
|
4
|
+
border: 1px solid var(--aura-x-bubble-border);
|
|
5
|
+
border-radius: var(--aura-radius-md);
|
|
6
|
+
background: var(--aura-x-bubble-ai-bg);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* ===== 头部 ===== */
|
|
10
|
+
|
|
11
|
+
.aura-x-sources-header {
|
|
12
|
+
display: flex;
|
|
13
|
+
gap: var(--aura-spacing-2);
|
|
14
|
+
align-items: center;
|
|
15
|
+
width: 100%;
|
|
16
|
+
padding: var(--aura-spacing-2) var(--aura-spacing-3);
|
|
17
|
+
border: none;
|
|
18
|
+
border-radius: var(--aura-radius-md);
|
|
19
|
+
background: transparent;
|
|
20
|
+
color: var(--aura-text-secondary);
|
|
21
|
+
font-size: var(--aura-font-size-sm);
|
|
22
|
+
text-align: left;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
transition: background var(--aura-duration-fast) var(--aura-easing);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.aura-x-sources-header:hover {
|
|
28
|
+
background: var(--aura-x-accent-soft);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.aura-x-sources-header:focus-visible {
|
|
32
|
+
outline: none;
|
|
33
|
+
box-shadow: var(--aura-x-focus-ring);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.aura-x-sources-title {
|
|
37
|
+
flex: 1;
|
|
38
|
+
min-width: 0;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
color: var(--aura-text);
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
text-overflow: ellipsis;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.aura-x-sources-caret {
|
|
47
|
+
flex: none;
|
|
48
|
+
font-size: 10px;
|
|
49
|
+
line-height: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* 折叠图标置于标题之后(右侧) */
|
|
53
|
+
.aura-x-sources-header--end .aura-x-sources-caret {
|
|
54
|
+
order: 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* ===== 有序列表 ===== */
|
|
58
|
+
|
|
59
|
+
.aura-x-sources-list {
|
|
60
|
+
margin: 0;
|
|
61
|
+
padding: 0 var(--aura-spacing-3) var(--aura-spacing-2);
|
|
62
|
+
list-style: none;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.aura-x-sources-item {
|
|
66
|
+
padding: var(--aura-spacing-1) 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.aura-x-sources-item + .aura-x-sources-item {
|
|
70
|
+
border-top: 1px dashed var(--aura-border);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.aura-x-sources-item-main {
|
|
74
|
+
display: flex;
|
|
75
|
+
gap: var(--aura-spacing-2);
|
|
76
|
+
align-items: center;
|
|
77
|
+
width: 100%;
|
|
78
|
+
padding: var(--aura-spacing-1) 0;
|
|
79
|
+
border: none;
|
|
80
|
+
border-radius: var(--aura-radius-sm);
|
|
81
|
+
background: transparent;
|
|
82
|
+
color: var(--aura-text);
|
|
83
|
+
font-size: var(--aura-font-size-sm);
|
|
84
|
+
text-align: left;
|
|
85
|
+
text-decoration: none;
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
a.aura-x-sources-item-main:hover .aura-x-sources-item-title,
|
|
90
|
+
button.aura-x-sources-item-main:hover .aura-x-sources-item-title {
|
|
91
|
+
color: var(--aura-x-accent);
|
|
92
|
+
text-decoration: underline;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.aura-x-sources-item-main:focus-visible {
|
|
96
|
+
outline: none;
|
|
97
|
+
box-shadow: var(--aura-x-focus-ring);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.aura-x-sources-item-index {
|
|
101
|
+
flex: none;
|
|
102
|
+
display: inline-flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
min-width: 16px;
|
|
106
|
+
height: 16px;
|
|
107
|
+
padding: 0 var(--aura-spacing-1);
|
|
108
|
+
border-radius: var(--aura-radius-sm);
|
|
109
|
+
background: var(--aura-x-accent-soft);
|
|
110
|
+
color: var(--aura-x-accent);
|
|
111
|
+
font-size: var(--aura-font-size-xs);
|
|
112
|
+
line-height: 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.aura-x-sources-item-icon {
|
|
116
|
+
flex: none;
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
color: var(--aura-text-secondary);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.aura-x-sources-item-icon > svg {
|
|
122
|
+
width: 14px;
|
|
123
|
+
height: 14px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.aura-x-sources-item-title {
|
|
127
|
+
flex: 1;
|
|
128
|
+
min-width: 0;
|
|
129
|
+
overflow: hidden;
|
|
130
|
+
white-space: nowrap;
|
|
131
|
+
text-overflow: ellipsis;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.aura-x-sources-item-desc {
|
|
135
|
+
padding-left: 24px;
|
|
136
|
+
color: var(--aura-text-secondary);
|
|
137
|
+
font-size: var(--aura-font-size-xs);
|
|
138
|
+
line-height: 1.6;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* ===== 行内模式 ===== */
|
|
142
|
+
|
|
143
|
+
.aura-x-sources--inline {
|
|
144
|
+
display: inline-flex;
|
|
145
|
+
gap: var(--aura-spacing-1);
|
|
146
|
+
align-items: center;
|
|
147
|
+
border: none;
|
|
148
|
+
background: transparent;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.aura-x-sources-inline-wrap {
|
|
152
|
+
position: relative;
|
|
153
|
+
display: inline-flex;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.aura-x-sources-inline-chip {
|
|
157
|
+
display: inline-flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
min-width: 16px;
|
|
161
|
+
height: 16px;
|
|
162
|
+
padding: 0 var(--aura-spacing-1);
|
|
163
|
+
border: none;
|
|
164
|
+
border-radius: var(--aura-radius-sm);
|
|
165
|
+
background: var(--aura-x-accent-soft);
|
|
166
|
+
color: var(--aura-x-accent);
|
|
167
|
+
font-size: 10px;
|
|
168
|
+
line-height: 1;
|
|
169
|
+
cursor: pointer;
|
|
170
|
+
transition:
|
|
171
|
+
background var(--aura-duration-fast) var(--aura-easing),
|
|
172
|
+
color var(--aura-duration-fast) var(--aura-easing);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.aura-x-sources-inline-chip--active,
|
|
176
|
+
.aura-x-sources-inline-chip:hover {
|
|
177
|
+
background: var(--aura-x-accent-gradient);
|
|
178
|
+
color: var(--aura-text-inverse);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.aura-x-sources-inline-chip:focus-visible {
|
|
182
|
+
outline: none;
|
|
183
|
+
box-shadow: var(--aura-x-focus-ring);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.aura-x-sources-popover {
|
|
187
|
+
position: absolute;
|
|
188
|
+
bottom: calc(100% + var(--aura-spacing-1));
|
|
189
|
+
left: 0;
|
|
190
|
+
z-index: 20;
|
|
191
|
+
display: flex;
|
|
192
|
+
flex-direction: column;
|
|
193
|
+
gap: var(--aura-spacing-1);
|
|
194
|
+
max-width: 320px;
|
|
195
|
+
padding: var(--aura-spacing-2) var(--aura-spacing-3);
|
|
196
|
+
border: 1px solid var(--aura-x-bubble-border);
|
|
197
|
+
border-radius: var(--aura-radius-md);
|
|
198
|
+
background: var(--aura-bg);
|
|
199
|
+
box-shadow: var(--aura-x-glow);
|
|
200
|
+
text-align: left;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.aura-x-sources-popover-title {
|
|
204
|
+
color: var(--aura-text);
|
|
205
|
+
font-size: var(--aura-font-size-sm);
|
|
206
|
+
font-weight: 600;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.aura-x-sources-popover-desc {
|
|
210
|
+
color: var(--aura-text-secondary);
|
|
211
|
+
font-size: var(--aura-font-size-xs);
|
|
212
|
+
line-height: 1.6;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.aura-x-sources-popover-url {
|
|
216
|
+
color: var(--aura-x-accent);
|
|
217
|
+
font-size: var(--aura-font-size-xs);
|
|
218
|
+
word-break: break-all;
|
|
219
|
+
}
|