@ai-group/chat-sdk 3.6.2 → 3.6.4
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/dist/cjs/components/FileGallery/index.d.ts +0 -30
- package/dist/cjs/components/FileGallery/index.js +287 -209
- package/dist/cjs/components/FileGallery/index.js.map +2 -2
- package/dist/cjs/components/FileGallery/styles.d.ts +5 -0
- package/dist/cjs/components/FileGallery/styles.js +106 -0
- package/dist/cjs/components/FileGallery/styles.js.map +2 -2
- package/dist/cjs/components/XAdkProvider/compound/Sender.js +3 -2
- package/dist/cjs/components/XAdkProvider/compound/Sender.js.map +2 -2
- package/dist/cjs/components/XAdkSender/index.js +1 -0
- package/dist/cjs/components/XAdkSender/index.js.map +2 -2
- package/dist/cjs/hooks/useADKChat.js +365 -167
- package/dist/cjs/hooks/useADKChat.js.map +3 -3
- package/dist/cjs/hooks/useAgentGenerator.js +4 -3
- package/dist/cjs/hooks/useAgentGenerator.js.map +2 -2
- package/dist/cjs/types/FileGallery.d.ts +41 -0
- package/dist/cjs/types/FileGallery.js.map +1 -1
- package/dist/cjs/types/XAdkProvider.d.ts +4 -0
- package/dist/cjs/types/XAdkProvider.js.map +1 -1
- package/dist/cjs/types/XAiProvider.d.ts +13 -46
- package/dist/cjs/types/XAiProvider.js +2 -25
- package/dist/cjs/types/XAiProvider.js.map +3 -3
- package/dist/esm/components/FileGallery/index.d.ts +0 -30
- package/dist/esm/components/FileGallery/index.js +362 -364
- package/dist/esm/components/FileGallery/index.js.map +1 -1
- package/dist/esm/components/FileGallery/styles.d.ts +5 -0
- package/dist/esm/components/FileGallery/styles.js +10 -2
- package/dist/esm/components/FileGallery/styles.js.map +1 -1
- package/dist/esm/components/XAdkProvider/compound/Sender.js +5 -3
- package/dist/esm/components/XAdkProvider/compound/Sender.js.map +1 -1
- package/dist/esm/components/XAdkSender/index.js +1 -0
- package/dist/esm/components/XAdkSender/index.js.map +1 -1
- package/dist/esm/hooks/useADKChat.js +314 -133
- package/dist/esm/hooks/useADKChat.js.map +1 -1
- package/dist/esm/hooks/useAgentGenerator.js +4 -3
- package/dist/esm/hooks/useAgentGenerator.js.map +1 -1
- package/dist/esm/types/FileGallery.d.ts +41 -0
- package/dist/esm/types/FileGallery.js.map +1 -1
- package/dist/esm/types/XAdkProvider.d.ts +4 -0
- package/dist/esm/types/XAdkProvider.js.map +1 -1
- package/dist/esm/types/XAiProvider.d.ts +13 -46
- package/dist/esm/types/XAiProvider.js +7 -39
- package/dist/esm/types/XAiProvider.js.map +1 -1
- package/dist/umd/chat-sdk.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,34 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { FileGalleryProps } from "../../types";
|
|
3
|
-
/**
|
|
4
|
-
* FileGallery - 单文件展示组件
|
|
5
|
-
*
|
|
6
|
-
* 功能特性:
|
|
7
|
-
* - 📁 支持多种文件类型展示 (图片、音频、视频、文档等)
|
|
8
|
-
* - 🖼️ 图片支持预览和缩略图
|
|
9
|
-
* - 🎵 音频文件支持内联播放
|
|
10
|
-
* - 🎬 视频文件支持内联播放
|
|
11
|
-
* - 📊 显示文件大小、类型图标
|
|
12
|
-
* - 🗑️ 支持删除操作
|
|
13
|
-
* - 📤 支持上传进度显示
|
|
14
|
-
* - 🎨 支持卡片内部布局控制(align:图标和信息的排列方式)
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // XAdkSender 场景 - 可删除的本地文件
|
|
18
|
-
* {files.map(file => (
|
|
19
|
-
* <FileGallery
|
|
20
|
-
* key={file.id}
|
|
21
|
-
* file={file}
|
|
22
|
-
* removable
|
|
23
|
-
* onRemove={handleRemove}
|
|
24
|
-
* />
|
|
25
|
-
* ))}
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* // XadkChatbot 场景 - 只读的远程文件
|
|
29
|
-
* {files.map(file => (
|
|
30
|
-
* <FileGallery key={file.id} file={file} />
|
|
31
|
-
* ))}
|
|
32
|
-
*/
|
|
33
3
|
declare const FileGallery: React.FC<FileGalleryProps>;
|
|
34
4
|
export default FileGallery;
|
|
@@ -27,90 +27,82 @@ var import_antd = require("antd");
|
|
|
27
27
|
var import_icons = require("@ant-design/icons");
|
|
28
28
|
var import_styles = require("./styles");
|
|
29
29
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
-
var getFileName = (file) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var getFileSize = (file) => {
|
|
34
|
-
return file.size || 0;
|
|
35
|
-
};
|
|
36
|
-
var getMimeType = (file) => {
|
|
37
|
-
return file.mimeType || file.type || "";
|
|
38
|
-
};
|
|
30
|
+
var getFileName = (file) => file.displayName || file.name || "";
|
|
31
|
+
var getFileSize = (file) => file.size || 0;
|
|
32
|
+
var getMimeType = (file) => file.mimeType || file.type || "";
|
|
39
33
|
var getFileUrl = (file) => {
|
|
40
34
|
var _a, _b;
|
|
41
35
|
return file.fileUri || ((_a = file.response) == null ? void 0 : _a.fileUrl) || ((_b = file.response) == null ? void 0 : _b.tempUrl) || file.tempUrl || "";
|
|
42
36
|
};
|
|
43
|
-
var getFileId = (file) =>
|
|
44
|
-
return file.id || file.uid || "";
|
|
45
|
-
};
|
|
46
|
-
var isImageFile = (file) => {
|
|
47
|
-
const mimeType = getMimeType(file);
|
|
48
|
-
if (mimeType && mimeType.startsWith("image/"))
|
|
49
|
-
return true;
|
|
50
|
-
const fileName = getFileName(file);
|
|
51
|
-
if (fileName && fileName.match(/\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i))
|
|
52
|
-
return true;
|
|
53
|
-
const url = getFileUrl(file);
|
|
54
|
-
if (url && url.match(/\.(jpg|jpeg|png|gif|webp|bmp|svg)(\?.*)?$/i))
|
|
55
|
-
return true;
|
|
56
|
-
return false;
|
|
57
|
-
};
|
|
58
|
-
var isAudioFile = (file) => {
|
|
59
|
-
const mimeType = getMimeType(file);
|
|
60
|
-
if (mimeType && mimeType.startsWith("audio/"))
|
|
61
|
-
return true;
|
|
62
|
-
const fileName = getFileName(file);
|
|
63
|
-
return !!(fileName == null ? void 0 : fileName.match(/\.(mp3|wav|m4a|aac|ogg|flac)$/i));
|
|
64
|
-
};
|
|
65
|
-
var isVideoFile = (file) => {
|
|
66
|
-
const mimeType = getMimeType(file);
|
|
67
|
-
if (mimeType && mimeType.startsWith("video/"))
|
|
68
|
-
return true;
|
|
69
|
-
const fileName = getFileName(file);
|
|
70
|
-
return !!(fileName == null ? void 0 : fileName.match(/\.(mp4|mov|webm|mkv|avi)$/i));
|
|
71
|
-
};
|
|
72
|
-
var isZipFile = (file) => {
|
|
73
|
-
const fileName = getFileName(file);
|
|
74
|
-
return !!(fileName == null ? void 0 : fileName.match(/\.(zip|rar|7z|tar|gz|bz2|xz|tgz)$/i));
|
|
75
|
-
};
|
|
76
|
-
var isMarkdownFile = (file) => {
|
|
77
|
-
const fileName = getFileName(file);
|
|
78
|
-
return !!(fileName == null ? void 0 : fileName.match(/\.(md|markdown)$/i));
|
|
79
|
-
};
|
|
37
|
+
var getFileId = (file) => file.id || file.uid || "";
|
|
80
38
|
var getFileExtension = (filename) => {
|
|
81
39
|
const ext = filename.split(".").pop();
|
|
82
40
|
return ext ? ext.toLowerCase() : "";
|
|
83
41
|
};
|
|
84
|
-
var
|
|
42
|
+
var IMAGE_EXTS = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg"];
|
|
43
|
+
var AUDIO_EXTS = ["mp3", "wav", "m4a", "aac", "ogg", "flac"];
|
|
44
|
+
var VIDEO_EXTS = ["mp4", "mov", "webm", "mkv", "avi"];
|
|
45
|
+
var inferFileType = (file) => {
|
|
46
|
+
const mimeType = getMimeType(file);
|
|
47
|
+
if (mimeType.startsWith("image/"))
|
|
48
|
+
return "image";
|
|
49
|
+
if (mimeType.startsWith("audio/"))
|
|
50
|
+
return "audio";
|
|
51
|
+
if (mimeType.startsWith("video/"))
|
|
52
|
+
return "video";
|
|
85
53
|
const ext = getFileExtension(getFileName(file));
|
|
86
|
-
if (ext
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.VideoCameraOutlined, {}), color: "#fa8c16" };
|
|
103
|
-
}
|
|
104
|
-
if (["zip", "rar", "7z", "tar", "gz", "bz2", "xz", "tgz"].includes(ext)) {
|
|
105
|
-
return { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileZipOutlined, {}), color: "#eb2f96" };
|
|
106
|
-
}
|
|
107
|
-
if (["md", "markdown"].includes(ext)) {
|
|
108
|
-
return { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileMarkdownOutlined, {}), color: "#13c2c2" };
|
|
109
|
-
}
|
|
110
|
-
if (isImageFile(file)) {
|
|
111
|
-
return { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileImageOutlined, {}), color: "#8c8c8c" };
|
|
54
|
+
if (IMAGE_EXTS.includes(ext))
|
|
55
|
+
return "image";
|
|
56
|
+
if (AUDIO_EXTS.includes(ext))
|
|
57
|
+
return "audio";
|
|
58
|
+
if (VIDEO_EXTS.includes(ext))
|
|
59
|
+
return "video";
|
|
60
|
+
const url = getFileUrl(file);
|
|
61
|
+
const urlExtMatch = url.match(/\.(\w+)(\?.*)?$/);
|
|
62
|
+
if (urlExtMatch) {
|
|
63
|
+
const urlExt = urlExtMatch[1].toLowerCase();
|
|
64
|
+
if (IMAGE_EXTS.includes(urlExt))
|
|
65
|
+
return "image";
|
|
66
|
+
if (AUDIO_EXTS.includes(urlExt))
|
|
67
|
+
return "audio";
|
|
68
|
+
if (VIDEO_EXTS.includes(urlExt))
|
|
69
|
+
return "video";
|
|
112
70
|
}
|
|
113
|
-
return
|
|
71
|
+
return "file";
|
|
72
|
+
};
|
|
73
|
+
var getFileIconType = (file) => {
|
|
74
|
+
const ext = getFileExtension(getFileName(file));
|
|
75
|
+
if (ext === "pdf")
|
|
76
|
+
return "pdf";
|
|
77
|
+
if (["doc", "docx"].includes(ext))
|
|
78
|
+
return "word";
|
|
79
|
+
if (["xls", "xlsx", "csv"].includes(ext))
|
|
80
|
+
return "excel";
|
|
81
|
+
if (["ppt", "pptx"].includes(ext))
|
|
82
|
+
return "ppt";
|
|
83
|
+
if (AUDIO_EXTS.includes(ext))
|
|
84
|
+
return "audio";
|
|
85
|
+
if (VIDEO_EXTS.includes(ext))
|
|
86
|
+
return "video";
|
|
87
|
+
if (["zip", "rar", "7z", "tar", "gz", "bz2", "xz", "tgz"].includes(ext))
|
|
88
|
+
return "zip";
|
|
89
|
+
if (["md", "markdown"].includes(ext))
|
|
90
|
+
return "markdown";
|
|
91
|
+
if (IMAGE_EXTS.includes(ext))
|
|
92
|
+
return "image";
|
|
93
|
+
return "default";
|
|
94
|
+
};
|
|
95
|
+
var DEFAULT_ICON_MAP = {
|
|
96
|
+
pdf: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FilePdfOutlined, {}), color: "#ff4d4f" },
|
|
97
|
+
word: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileWordOutlined, {}), color: "#1677ff" },
|
|
98
|
+
excel: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileExcelOutlined, {}), color: "#22b35e" },
|
|
99
|
+
ppt: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FilePptOutlined, {}), color: "#ff6e31" },
|
|
100
|
+
audio: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.AudioOutlined, {}), color: "#722ed1" },
|
|
101
|
+
video: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.VideoCameraOutlined, {}), color: "#fa8c16" },
|
|
102
|
+
zip: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileZipOutlined, {}), color: "#eb2f96" },
|
|
103
|
+
markdown: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileMarkdownOutlined, {}), color: "#13c2c2" },
|
|
104
|
+
image: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileImageOutlined, {}), color: "#8c8c8c" },
|
|
105
|
+
default: { icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.FileOutlined, {}), color: "#8c8c8c" }
|
|
114
106
|
};
|
|
115
107
|
var formatFileSize = (bytes) => {
|
|
116
108
|
if (bytes < 1024)
|
|
@@ -119,7 +111,54 @@ var formatFileSize = (bytes) => {
|
|
|
119
111
|
return (bytes / 1024).toFixed(1) + " KB";
|
|
120
112
|
return (bytes / (1024 * 1024)).toFixed(1) + " MB";
|
|
121
113
|
};
|
|
122
|
-
var
|
|
114
|
+
var FALLBACK_IMAGE = "data:image/png;base64,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";
|
|
115
|
+
var ImageWithLoading = ({
|
|
116
|
+
src,
|
|
117
|
+
alt,
|
|
118
|
+
width,
|
|
119
|
+
height,
|
|
120
|
+
loading,
|
|
121
|
+
preview,
|
|
122
|
+
fallback,
|
|
123
|
+
displayMode,
|
|
124
|
+
styles
|
|
125
|
+
}) => {
|
|
126
|
+
const [loadState, setLoadState] = (0, import_react.useState)("loading");
|
|
127
|
+
(0, import_react.useEffect)(() => {
|
|
128
|
+
setLoadState("loading");
|
|
129
|
+
}, [src]);
|
|
130
|
+
const modeClass = displayMode === "full" ? styles.imageFullMode : displayMode === "preview" ? styles.imagePreviewMode : styles.imageThumbnail;
|
|
131
|
+
const containerStyle = {};
|
|
132
|
+
if (width)
|
|
133
|
+
containerStyle.width = typeof width === "number" ? `${width}px` : width;
|
|
134
|
+
if (height)
|
|
135
|
+
containerStyle.height = typeof height === "number" ? `${height}px` : height;
|
|
136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: modeClass, style: containerStyle, children: [
|
|
137
|
+
loadState === "loading" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.imageLoadingSkeleton, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PictureOutlined, { style: { fontSize: 20, color: "#d9d9d9" } }) }),
|
|
138
|
+
loadState === "error" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.imageErrorFallback, children: [
|
|
139
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PictureOutlined, {}),
|
|
140
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "加载失败" })
|
|
141
|
+
] }),
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
+
import_antd.Image,
|
|
144
|
+
{
|
|
145
|
+
src,
|
|
146
|
+
alt,
|
|
147
|
+
fallback,
|
|
148
|
+
preview,
|
|
149
|
+
loading,
|
|
150
|
+
style: {
|
|
151
|
+
display: loadState === "error" ? "none" : "block",
|
|
152
|
+
opacity: loadState === "loading" ? 0 : 1,
|
|
153
|
+
transition: "opacity 0.3s ease",
|
|
154
|
+
...displayMode === "thumbnail" ? { width: "100%", height: "100%", objectFit: "cover" } : { maxWidth: "100%", objectFit: "contain" }
|
|
155
|
+
},
|
|
156
|
+
onLoad: () => setLoadState("loaded"),
|
|
157
|
+
onError: () => setLoadState("error")
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
] });
|
|
161
|
+
};
|
|
123
162
|
var FileGallery = ({
|
|
124
163
|
file,
|
|
125
164
|
align = "left",
|
|
@@ -128,8 +167,26 @@ var FileGallery = ({
|
|
|
128
167
|
},
|
|
129
168
|
className,
|
|
130
169
|
style,
|
|
131
|
-
onClick
|
|
170
|
+
onClick,
|
|
171
|
+
type: customType,
|
|
172
|
+
// 图片相关
|
|
173
|
+
imageDisplayMode = "thumbnail",
|
|
174
|
+
imageWidth,
|
|
175
|
+
imageHeight,
|
|
176
|
+
imageLoading = "eager",
|
|
177
|
+
imageAlt,
|
|
178
|
+
// 音视频相关
|
|
179
|
+
mediaAutoPlay = false,
|
|
180
|
+
mediaLoop = false,
|
|
181
|
+
mediaMuted = false,
|
|
182
|
+
mediaPoster,
|
|
183
|
+
videoProps,
|
|
184
|
+
audioProps,
|
|
185
|
+
// 自定义图标
|
|
186
|
+
iconMap,
|
|
187
|
+
customIcon
|
|
132
188
|
}) => {
|
|
189
|
+
const styles = (0, import_styles.useStyles)();
|
|
133
190
|
const [objectUrl, setObjectUrl] = (0, import_react.useState)("");
|
|
134
191
|
(0, import_react.useEffect)(() => {
|
|
135
192
|
if (!(file == null ? void 0 : file.file))
|
|
@@ -140,16 +197,47 @@ var FileGallery = ({
|
|
|
140
197
|
}, [file == null ? void 0 : file.file]);
|
|
141
198
|
if (!file)
|
|
142
199
|
return null;
|
|
143
|
-
const isImage = isImageFile(file);
|
|
144
|
-
const isAudio = isAudioFile(file);
|
|
145
|
-
const isVideo = isVideoFile(file);
|
|
146
|
-
const isZip = isZipFile(file);
|
|
147
|
-
const isMarkdown = isMarkdownFile(file);
|
|
148
200
|
const fileName = getFileName(file);
|
|
149
201
|
const fileSize = getFileSize(file);
|
|
150
202
|
const fileId = getFileId(file);
|
|
151
203
|
const url = getFileUrl(file) || objectUrl;
|
|
152
|
-
|
|
204
|
+
const fileType = (0, import_react.useMemo)(
|
|
205
|
+
() => customType || inferFileType(file),
|
|
206
|
+
[customType, file]
|
|
207
|
+
);
|
|
208
|
+
const getIcon = (iconType) => {
|
|
209
|
+
if (customIcon)
|
|
210
|
+
return { icon: customIcon, color: "inherit" };
|
|
211
|
+
if (iconMap == null ? void 0 : iconMap[iconType])
|
|
212
|
+
return { icon: iconMap[iconType], color: "inherit" };
|
|
213
|
+
return DEFAULT_ICON_MAP[iconType];
|
|
214
|
+
};
|
|
215
|
+
const renderRemoveBtn = () => removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
216
|
+
"button",
|
|
217
|
+
{
|
|
218
|
+
className: styles.fileRemoveBtn,
|
|
219
|
+
onClick: (e) => {
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
onRemove(fileId);
|
|
222
|
+
},
|
|
223
|
+
disabled: file.status === "uploading",
|
|
224
|
+
"aria-label": "删除文件",
|
|
225
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseOutlined, {})
|
|
226
|
+
}
|
|
227
|
+
) : null;
|
|
228
|
+
const renderUploadOverlay = () => file.status === "uploading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.imageOverlay, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
229
|
+
import_antd.Progress,
|
|
230
|
+
{
|
|
231
|
+
type: "circle",
|
|
232
|
+
percent: file.progress,
|
|
233
|
+
size: 30,
|
|
234
|
+
strokeColor: "#1677ff"
|
|
235
|
+
}
|
|
236
|
+
) }) : null;
|
|
237
|
+
const renderFileCard = () => {
|
|
238
|
+
const iconType = getFileIconType(file);
|
|
239
|
+
const { icon, color } = getIcon(iconType);
|
|
240
|
+
const isExternalUrl = url && url.startsWith("http");
|
|
153
241
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
154
242
|
"div",
|
|
155
243
|
{
|
|
@@ -157,168 +245,158 @@ var FileGallery = ({
|
|
|
157
245
|
style: { ...style, cursor: onClick ? "pointer" : void 0 },
|
|
158
246
|
onClick: () => onClick == null ? void 0 : onClick(file),
|
|
159
247
|
children: [
|
|
160
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
161
|
-
|
|
162
|
-
|
|
248
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileIcon, style: { color }, children: icon }),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.fileInfo, children: [
|
|
250
|
+
isExternalUrl && !onClick ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
251
|
+
"a",
|
|
163
252
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
253
|
+
href: url,
|
|
254
|
+
target: "_blank",
|
|
255
|
+
rel: "noopener noreferrer",
|
|
256
|
+
className: styles.fileLink,
|
|
257
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName.length > 15 ? `${fileName.substring(0, 15)}...` : fileName }) })
|
|
168
258
|
}
|
|
169
|
-
),
|
|
170
|
-
file.status === "uploading"
|
|
259
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName.length > 15 ? `${fileName.substring(0, 15)}...` : fileName }) }),
|
|
260
|
+
file.status === "uploading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
171
261
|
import_antd.Progress,
|
|
172
262
|
{
|
|
173
|
-
type: "circle",
|
|
174
263
|
percent: file.progress,
|
|
175
|
-
size:
|
|
176
|
-
|
|
264
|
+
size: "small",
|
|
265
|
+
showInfo: false,
|
|
266
|
+
strokeColor: "#1677ff",
|
|
267
|
+
className: styles.progress
|
|
177
268
|
}
|
|
178
|
-
) })
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
269
|
+
) : fileSize > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileSize, children: formatFileSize(fileSize) }),
|
|
270
|
+
file.status === "error" && file.errorMessage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
271
|
+
"div",
|
|
272
|
+
{
|
|
273
|
+
style: { fontSize: "11px", color: "#ff4d4f", marginTop: "2px" },
|
|
274
|
+
children: file.errorMessage
|
|
275
|
+
}
|
|
276
|
+
)
|
|
183
277
|
] }),
|
|
184
|
-
|
|
185
|
-
"button",
|
|
186
|
-
{
|
|
187
|
-
className: styles.fileRemoveBtn,
|
|
188
|
-
onClick: () => onRemove(fileId),
|
|
189
|
-
disabled: file.status === "uploading",
|
|
190
|
-
"aria-label": "删除文件",
|
|
191
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseOutlined, {})
|
|
192
|
-
}
|
|
193
|
-
)
|
|
278
|
+
renderRemoveBtn()
|
|
194
279
|
]
|
|
195
280
|
}
|
|
196
281
|
);
|
|
197
|
-
}
|
|
198
|
-
if (
|
|
282
|
+
};
|
|
283
|
+
if (fileType === "image") {
|
|
284
|
+
if (imageDisplayMode === "full" || imageDisplayMode === "preview") {
|
|
285
|
+
const containerStyle = { ...style };
|
|
286
|
+
if (imageWidth)
|
|
287
|
+
containerStyle.width = typeof imageWidth === "number" ? `${imageWidth}px` : imageWidth;
|
|
288
|
+
if (imageHeight)
|
|
289
|
+
containerStyle.height = typeof imageHeight === "number" ? `${imageHeight}px` : imageHeight;
|
|
290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
291
|
+
"div",
|
|
292
|
+
{
|
|
293
|
+
className: `${imageDisplayMode === "full" ? styles.imageFullMode : styles.imagePreviewMode} ${className || ""}`,
|
|
294
|
+
style: containerStyle,
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
|
+
ImageWithLoading,
|
|
298
|
+
{
|
|
299
|
+
src: url,
|
|
300
|
+
alt: imageAlt || fileName,
|
|
301
|
+
displayMode: imageDisplayMode,
|
|
302
|
+
loading: imageLoading,
|
|
303
|
+
preview: onClick ? false : { src: url },
|
|
304
|
+
fallback: FALLBACK_IMAGE,
|
|
305
|
+
styles
|
|
306
|
+
}
|
|
307
|
+
),
|
|
308
|
+
renderUploadOverlay(),
|
|
309
|
+
renderRemoveBtn()
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
}
|
|
199
314
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
200
315
|
"div",
|
|
201
316
|
{
|
|
202
317
|
className: `${styles.fileCard} ${align === "right" ? "align-right" : ""} ${className || ""}`,
|
|
203
|
-
style,
|
|
318
|
+
style: { ...style, cursor: onClick ? "pointer" : void 0 },
|
|
319
|
+
onClick: () => onClick == null ? void 0 : onClick(file),
|
|
204
320
|
children: [
|
|
205
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
206
|
-
|
|
207
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName }) }),
|
|
208
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
209
|
-
"audio",
|
|
210
|
-
{
|
|
211
|
-
src: url,
|
|
212
|
-
controls: true,
|
|
213
|
-
className: styles.mediaWrapper,
|
|
214
|
-
style: { width: "100%", height: 28 }
|
|
215
|
-
}
|
|
216
|
-
)
|
|
217
|
-
] }),
|
|
218
|
-
removable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
219
|
-
"button",
|
|
321
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
322
|
+
ImageWithLoading,
|
|
220
323
|
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
324
|
+
src: url,
|
|
325
|
+
alt: imageAlt || fileName,
|
|
326
|
+
width: imageWidth,
|
|
327
|
+
height: imageHeight,
|
|
328
|
+
displayMode: "thumbnail",
|
|
329
|
+
loading: imageLoading,
|
|
330
|
+
preview: onClick ? false : { src: url },
|
|
331
|
+
fallback: FALLBACK_IMAGE,
|
|
332
|
+
styles
|
|
226
333
|
}
|
|
227
|
-
)
|
|
334
|
+
),
|
|
335
|
+
renderUploadOverlay(),
|
|
336
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.fileInfo, children: [
|
|
337
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName.length > 15 ? `${fileName.substring(0, 15)}...` : fileName }) }),
|
|
338
|
+
Number(file == null ? void 0 : file.size) > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileSize, children: formatFileSize(fileSize) })
|
|
339
|
+
] }),
|
|
340
|
+
renderRemoveBtn()
|
|
228
341
|
]
|
|
229
342
|
}
|
|
230
343
|
);
|
|
231
344
|
}
|
|
232
|
-
if (
|
|
345
|
+
if (fileType === "audio") {
|
|
233
346
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
234
347
|
"div",
|
|
235
348
|
{
|
|
236
|
-
className:
|
|
237
|
-
style,
|
|
349
|
+
className: `file-gallery-audio ${className || ""}`,
|
|
350
|
+
style: { position: "relative", width: 268, ...style },
|
|
238
351
|
children: [
|
|
239
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
240
|
-
|
|
241
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName }) }),
|
|
242
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
243
|
-
"video",
|
|
244
|
-
{
|
|
245
|
-
src: url,
|
|
246
|
-
controls: true,
|
|
247
|
-
className: styles.mediaWrapper,
|
|
248
|
-
style: { width: "100%", height: 40 }
|
|
249
|
-
}
|
|
250
|
-
)
|
|
251
|
-
] }),
|
|
252
|
-
removable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
253
|
-
"button",
|
|
352
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
353
|
+
"audio",
|
|
254
354
|
{
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
355
|
+
src: url,
|
|
356
|
+
controls: true,
|
|
357
|
+
autoPlay: mediaAutoPlay,
|
|
358
|
+
loop: mediaLoop,
|
|
359
|
+
muted: mediaMuted,
|
|
360
|
+
style: { width: "100%" },
|
|
361
|
+
...audioProps
|
|
260
362
|
}
|
|
261
|
-
)
|
|
363
|
+
),
|
|
364
|
+
renderRemoveBtn()
|
|
262
365
|
]
|
|
263
366
|
}
|
|
264
367
|
);
|
|
265
368
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileIcon, style: { color }, children: icon }),
|
|
276
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.fileInfo, children: [
|
|
277
|
-
isExternalUrl && !onClick ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
278
|
-
"a",
|
|
279
|
-
{
|
|
280
|
-
href: url,
|
|
281
|
-
target: "_blank",
|
|
282
|
-
rel: "noopener noreferrer",
|
|
283
|
-
className: styles.fileLink,
|
|
284
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName.length > 15 ? `${fileName.substring(0, 15)}...` : fileName }) })
|
|
285
|
-
}
|
|
286
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileName, children: fileName.length > 15 ? `${fileName.substring(0, 15)}...` : fileName }) }),
|
|
287
|
-
file.status === "uploading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
288
|
-
import_antd.Progress,
|
|
289
|
-
{
|
|
290
|
-
percent: file.progress,
|
|
291
|
-
size: "small",
|
|
292
|
-
showInfo: false,
|
|
293
|
-
strokeColor: "#1677ff",
|
|
294
|
-
className: styles.progress
|
|
295
|
-
}
|
|
296
|
-
) : fileSize > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.fileSize, children: formatFileSize(fileSize) }),
|
|
297
|
-
file.status === "error" && file.errorMessage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
298
|
-
"div",
|
|
369
|
+
if (fileType === "video") {
|
|
370
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
371
|
+
"div",
|
|
372
|
+
{
|
|
373
|
+
className: `file-gallery-video ${className || ""}`,
|
|
374
|
+
style: { position: "relative", width: 268, ...style },
|
|
375
|
+
children: [
|
|
376
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
377
|
+
"video",
|
|
299
378
|
{
|
|
379
|
+
src: url,
|
|
380
|
+
controls: true,
|
|
381
|
+
autoPlay: mediaAutoPlay,
|
|
382
|
+
loop: mediaLoop,
|
|
383
|
+
muted: mediaMuted,
|
|
384
|
+
poster: mediaPoster,
|
|
300
385
|
style: {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
386
|
+
width: "100%",
|
|
387
|
+
aspectRatio: "16 / 9",
|
|
388
|
+
borderRadius: 8,
|
|
389
|
+
background: "#000"
|
|
304
390
|
},
|
|
305
|
-
|
|
391
|
+
...videoProps
|
|
306
392
|
}
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
disabled: file.status === "uploading",
|
|
315
|
-
"aria-label": "删除文件",
|
|
316
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseOutlined, {})
|
|
317
|
-
}
|
|
318
|
-
)
|
|
319
|
-
]
|
|
320
|
-
}
|
|
321
|
-
);
|
|
393
|
+
),
|
|
394
|
+
renderRemoveBtn()
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
return renderFileCard();
|
|
322
400
|
};
|
|
323
401
|
var FileGallery_default = FileGallery;
|
|
324
402
|
//# sourceMappingURL=index.js.map
|