@zjlab-fe/data-hub-ui 0.29.0 → 0.31.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/README.md +1 -1
- package/dist/types/components/file-uploader/components/icons.d.ts +1 -0
- package/dist/types/components/file-uploader/components/uploader-file-item.d.ts +4 -0
- package/dist/types/components/file-uploader/components/uploader-progress-bar.d.ts +9 -0
- package/dist/types/components/file-uploader/components/uploader.d.ts +2 -0
- package/dist/types/components/file-uploader/context/use-upload-engine.d.ts +5 -0
- package/dist/types/components/file-uploader/demo/index.d.ts +1 -0
- package/dist/types/components/file-uploader/demo/mockApi.d.ts +37 -0
- package/dist/types/components/file-uploader/hooks/use-upload.d.ts +4 -0
- package/dist/types/components/file-uploader/index.d.ts +1 -0
- package/dist/types/components/file-uploader/types.d.ts +5 -0
- package/dist/types/components/limit-credit-modal/demo/index.d.ts +3 -0
- package/dist/types/components/limit-credit-modal/index.d.ts +9 -0
- package/dist/types/index.d.ts +2 -0
- package/es/components/file-uploader/components/icons.js +7 -4
- package/es/components/file-uploader/components/uploader-file-item.css.js +22 -0
- package/es/components/file-uploader/components/uploader-file-item.js +4 -3
- package/es/components/file-uploader/components/uploader-progress-bar.css.js +43 -0
- package/es/components/file-uploader/components/uploader-progress-bar.js +19 -0
- package/es/components/file-uploader/components/uploader.js +4 -3
- package/es/components/file-uploader/context/use-upload-engine.js +108 -131
- package/es/components/file-uploader/hooks/use-upload.js +15 -1
- package/es/components/file-uploader/utils/upload-controllers.js +43 -1
- package/es/components/limit-credit-modal/index.js +36 -0
- package/es/components/test-component/index.js +9 -0
- package/es/components/test-component/index.scss.js +7 -0
- package/es/index.js +2 -0
- package/lib/index.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,3 +3,4 @@ export declare function FileIcon(): import("react/jsx-runtime").JSX.Element;
|
|
|
3
3
|
export declare function CloseIcon(): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export declare function PauseIcon(): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export declare function ResumeIcon(): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare function RetryIcon(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -22,6 +22,8 @@ export interface UploaderFileItemClassNames {
|
|
|
22
22
|
pauseBtn?: string;
|
|
23
23
|
/** Resume button */
|
|
24
24
|
resumeBtn?: string;
|
|
25
|
+
/** Retry button */
|
|
26
|
+
retryBtn?: string;
|
|
25
27
|
/** Close/Cancel button */
|
|
26
28
|
closeBtn?: string;
|
|
27
29
|
}
|
|
@@ -39,6 +41,8 @@ interface FileItemProps {
|
|
|
39
41
|
onPause?: (id: string) => void;
|
|
40
42
|
/** Resume function passed from parent that has upload handlers */
|
|
41
43
|
onResume?: (id: string) => void;
|
|
44
|
+
/** Retry function passed from parent that has upload handlers */
|
|
45
|
+
onRetry?: (id: string) => void;
|
|
42
46
|
}
|
|
43
47
|
export declare function UploaderFileItem(props: FileItemProps): import("react/jsx-runtime").JSX.Element;
|
|
44
48
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './uploader-progress-bar.css';
|
|
2
|
+
interface UploaderProgressBarProps {
|
|
3
|
+
/** Hide when only 0 or 1 files */
|
|
4
|
+
hideWhenSingle?: boolean;
|
|
5
|
+
/** Custom class name */
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function UploaderProgressBar({ hideWhenSingle, className }: UploaderProgressBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -32,6 +32,8 @@ interface UploaderProps {
|
|
|
32
32
|
onDropZoneError?: (error: DropZoneError) => void;
|
|
33
33
|
/** custom file validation callback */
|
|
34
34
|
fileValidation?: (file: File) => boolean | Promise<boolean>;
|
|
35
|
+
/** Whether to show the multi-file progress bar at the top. Default: true */
|
|
36
|
+
showProgressBar?: boolean;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Styled File Uploader - Matches FileUploader capabilities with custom styling
|
|
@@ -19,4 +19,9 @@ export declare function useUploadEngine(): {
|
|
|
19
19
|
resumeUpload: (fileId: string) => Promise<void>;
|
|
20
20
|
/** Cancel a file upload */
|
|
21
21
|
cancelUpload: (fileId: string) => Promise<void>;
|
|
22
|
+
/** Retry a failed upload (smart retry with full retry fallback) */
|
|
23
|
+
retryUpload: (fileId: string, forceFullRetry?: boolean) => Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
retryType: "smart" | "full";
|
|
26
|
+
}>;
|
|
22
27
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo mock for file-uploader retry scenarios.
|
|
3
|
+
* Keep fail strategies out of component business handlers.
|
|
4
|
+
*
|
|
5
|
+
* Chunk PUTs are intercepted locally (no external httpbin dependency).
|
|
6
|
+
* httpbin.org currently returns 503 in many networks, which made every chunk fail.
|
|
7
|
+
*/
|
|
8
|
+
export type FailMode = 'none' | 'urlFail' | 'partialChunkFail';
|
|
9
|
+
export type DemoEventLog = {
|
|
10
|
+
time: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
/** Local mock URLs intercepted by installDemoUploadMock() */
|
|
14
|
+
declare const MOCK_UPLOAD_URL = "https://upload.mock.local/ok";
|
|
15
|
+
declare const MOCK_BAD_UPLOAD_URL = "https://upload.mock.local/fail";
|
|
16
|
+
/**
|
|
17
|
+
* Intercept XMLHttpRequest for demo mock upload URLs.
|
|
18
|
+
* The real uploader uses axios PUT; this keeps the demo offline-capable and stable.
|
|
19
|
+
*/
|
|
20
|
+
export declare function installDemoUploadMock(): () => void;
|
|
21
|
+
export declare function bumpAttemptCount(fileName: string): number;
|
|
22
|
+
export declare function resetAttemptCounts(): void;
|
|
23
|
+
export declare function createDemoUploadUrls(fileName: string, partCount: number, failMode: FailMode): {
|
|
24
|
+
success: false;
|
|
25
|
+
reason: string;
|
|
26
|
+
} | {
|
|
27
|
+
success: true;
|
|
28
|
+
uploadInfo: {
|
|
29
|
+
uploadId: string;
|
|
30
|
+
uploadUrls: {
|
|
31
|
+
partNum: number;
|
|
32
|
+
uploadUrl: string;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare function formatDemoEvent(message: string): DemoEventLog;
|
|
37
|
+
export { MOCK_UPLOAD_URL, MOCK_BAD_UPLOAD_URL };
|
|
@@ -58,6 +58,10 @@ export declare function useUpload(): {
|
|
|
58
58
|
pause: (id: string) => void;
|
|
59
59
|
resume: (id: string) => Promise<void>;
|
|
60
60
|
cancel: (id: string) => Promise<void>;
|
|
61
|
+
retry: (id: string) => Promise<{
|
|
62
|
+
success: boolean;
|
|
63
|
+
retryType: "smart" | "full";
|
|
64
|
+
}>;
|
|
61
65
|
/** Get a specific file by ID */
|
|
62
66
|
getFileById: (id: string) => UploadFile | undefined;
|
|
63
67
|
/** Files waiting to be uploaded */
|
|
@@ -3,6 +3,7 @@ export { Uploader as FileUploader } from './components/uploader';
|
|
|
3
3
|
export { UploaderDropZone } from './components/uploader-drop-zone';
|
|
4
4
|
export { UploaderFileListLayout } from './components/uploader-file-list';
|
|
5
5
|
export { UploaderFileItem } from './components/uploader-file-item';
|
|
6
|
+
export { UploaderProgressBar } from './components/uploader-progress-bar';
|
|
6
7
|
export { useUpload } from './hooks/use-upload';
|
|
7
8
|
export type { UploadFile, ChunkState, UploadHandlers, HandlerContext, CallbackResult, GetUploadUrlsResult, UploadUrl, UploadConfig, AddFilesOptions, } from './types';
|
|
8
9
|
export type { DropZoneError, UploaderDropZoneClassNames, UploaderDropZoneProps, } from './components/uploader-drop-zone';
|
|
@@ -75,6 +75,11 @@ export interface HandlerContext {
|
|
|
75
75
|
resume: (id: string) => Promise<void>;
|
|
76
76
|
/** Cancel a file upload (always fresh) */
|
|
77
77
|
cancel: (id: string) => void;
|
|
78
|
+
/** Retry a failed upload (always fresh) */
|
|
79
|
+
retry: (id: string) => Promise<{
|
|
80
|
+
success: boolean;
|
|
81
|
+
retryType: 'smart' | 'full';
|
|
82
|
+
}>;
|
|
78
83
|
/** Get a specific file by ID (always fresh) */
|
|
79
84
|
getFileById: (id: string) => UploadFile | undefined;
|
|
80
85
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export type { CorpusCardProps, ProcessTemplateListItem, ProcessTemplateLabel, La
|
|
|
41
41
|
export { default as SDKModal } from './components/SDK-modal';
|
|
42
42
|
export { default as TagView } from './components/tag-view';
|
|
43
43
|
export { default as TagGroupFilter } from './components/tag-group-filter';
|
|
44
|
+
export { default as LimitCreditModal } from './components/limit-credit-modal';
|
|
45
|
+
export type { LimitCreditModalProps } from './components/limit-credit-modal';
|
|
44
46
|
export { default as DatasetBatchAction } from './components/dataset-batch-action';
|
|
45
47
|
export type { IConfirmParam, IFieldOption, IDatasetBatchActionParams, } from './components/dataset-batch-action';
|
|
46
48
|
export { EDatasetBatchType } from './components/dataset-batch-action';
|
|
@@ -7,13 +7,16 @@ function FileIcon() {
|
|
|
7
7
|
return (jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" }) }));
|
|
8
8
|
}
|
|
9
9
|
function CloseIcon() {
|
|
10
|
-
return (jsx("svg", { viewBox: "
|
|
10
|
+
return (jsx("svg", { width: "20", height: "20", viewBox: "5 5 14 14", fill: "currentColor", children: jsx("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) }));
|
|
11
11
|
}
|
|
12
12
|
function PauseIcon() {
|
|
13
|
-
return (jsx("svg", { viewBox: "
|
|
13
|
+
return (jsx("svg", { width: "20", height: "20", viewBox: "6 5 12 14", fill: "currentColor", children: jsx("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" }) }));
|
|
14
14
|
}
|
|
15
15
|
function ResumeIcon() {
|
|
16
|
-
return (jsx("svg", { viewBox: "
|
|
16
|
+
return (jsx("svg", { width: "20", height: "20", viewBox: "8 5 11 14", fill: "currentColor", children: jsx("path", { d: "M8 5v14l11-7z" }) }));
|
|
17
|
+
}
|
|
18
|
+
function RetryIcon() {
|
|
19
|
+
return (jsx("svg", { width: "20", height: "20", viewBox: "4 4 16 16", fill: "currentColor", children: jsx("path", { d: "M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" }) }));
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
export { CloseIcon, FileIcon, PauseIcon, ResumeIcon, UploadIcon as default };
|
|
22
|
+
export { CloseIcon, FileIcon, PauseIcon, ResumeIcon, RetryIcon, UploadIcon as default };
|
|
@@ -158,6 +158,15 @@ function useStyle() {
|
|
|
158
158
|
border-radius: 0.375rem; /* 6px */
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/* Keep icon box same size as CircleProgress (20x20), not stretching to button */
|
|
162
|
+
|
|
163
|
+
.upload-action-btn svg {
|
|
164
|
+
width: 16px;
|
|
165
|
+
height: 16px;
|
|
166
|
+
display: block;
|
|
167
|
+
flex-shrink: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
161
170
|
.upload-action-btn:hover {
|
|
162
171
|
background: var(--uploader-action-hover-bg);
|
|
163
172
|
color: var(--uploader-action-hover-text);
|
|
@@ -183,6 +192,19 @@ function useStyle() {
|
|
|
183
192
|
color: var(--uploader-action-close-hover-text);
|
|
184
193
|
background: var(--uploader-action-close-hover-bg);
|
|
185
194
|
}
|
|
195
|
+
|
|
196
|
+
.upload-retry-btn {
|
|
197
|
+
opacity: 0.5;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.upload-file-item:hover .upload-retry-btn {
|
|
201
|
+
opacity: 1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.upload-retry-btn:hover {
|
|
205
|
+
color: var(--uploader-action-close-hover-text);
|
|
206
|
+
background: var(--uploader-action-close-hover-bg);
|
|
207
|
+
}
|
|
186
208
|
`;
|
|
187
209
|
document.head.appendChild(style);
|
|
188
210
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { UploadStatus } from '../constants.js';
|
|
3
3
|
import { CircleProgress } from './circle-progress.js';
|
|
4
|
-
import { FileIcon, PauseIcon, ResumeIcon, CloseIcon } from './icons.js';
|
|
4
|
+
import { FileIcon, PauseIcon, ResumeIcon, RetryIcon, CloseIcon } from './icons.js';
|
|
5
5
|
import { UploadingStatus } from './uploading-status.js';
|
|
6
6
|
import useStyle from './theme.css.js';
|
|
7
7
|
import useStyle$1 from './uploader-file-item.css.js';
|
|
@@ -9,7 +9,7 @@ import useStyle$1 from './uploader-file-item.css.js';
|
|
|
9
9
|
useStyle();
|
|
10
10
|
useStyle$1();
|
|
11
11
|
function UploaderFileItem(props) {
|
|
12
|
-
const { file, classNames, onCancel, onRemove, onPause, onResume } = props;
|
|
12
|
+
const { file, classNames, onCancel, onRemove, onPause, onResume, onRetry } = props;
|
|
13
13
|
const semanticClassNames = typeof classNames === 'function' ? classNames(props) : classNames;
|
|
14
14
|
const isFailed = file.status === UploadStatus.FAILED;
|
|
15
15
|
const isSuccess = file.status === UploadStatus.SUCCESS;
|
|
@@ -17,6 +17,7 @@ function UploaderFileItem(props) {
|
|
|
17
17
|
const isPaused = file.status === UploadStatus.PAUSED;
|
|
18
18
|
const showPause = !isSuccess && !isFailed && !isCancelled && !isPaused && onPause;
|
|
19
19
|
const showResume = isPaused && onResume;
|
|
20
|
+
const showRetry = isFailed && !!file.file && onRetry;
|
|
20
21
|
const handleClose = () => {
|
|
21
22
|
if (isFailed || isSuccess || isCancelled) {
|
|
22
23
|
onRemove === null || onRemove === void 0 ? void 0 : onRemove(file.id);
|
|
@@ -59,7 +60,7 @@ function UploaderFileItem(props) {
|
|
|
59
60
|
return 'cancelled';
|
|
60
61
|
return 'uploading';
|
|
61
62
|
};
|
|
62
|
-
return (jsxs("div", { className: `upload-file-item ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.container) || ''}`, "data-status": getStatusAttribute(), children: [jsxs("div", { className: `upload-file-info ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.info) || ''}`, children: [jsx("div", { className: `upload-file-icon ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.icon) || ''}`, children: jsx(FileIcon, {}) }), jsxs("span", { className: `upload-file-name ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.name) || ''}`, children: [file.fileName, file.relativePath && (jsx("span", { className: `upload-file-path ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.relativePath) || ''}`, children: file.relativePath }))] })] }), jsxs("div", { className: `upload-file-status ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.status) || ''}`, children: [jsx("span", { className: `upload-status-text ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.statusText) || ''}`, children: getStatusText() }), jsx("div", { className: semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.progress, children: jsx(CircleProgress, { percent: file.progress, isFailed: isFailed, isSuccess: isSuccess }) }), showPause && (jsx("button", { className: `upload-action-btn upload-pause-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.pauseBtn) || ''}`, onClick: () => onPause === null || onPause === void 0 ? void 0 : onPause(file.id), title: "\u6682\u505C\u4E0A\u4F20", children: jsx(PauseIcon, {}) })), showResume && (jsx("button", { className: `upload-action-btn upload-resume-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.resumeBtn) || ''}`, onClick: () => onResume === null || onResume === void 0 ? void 0 : onResume(file.id), title: "\u7EE7\u7EED\u4E0A\u4F20", children: jsx(ResumeIcon, {}) }))] }), jsx("button", { className: `upload-action-btn upload-close-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.closeBtn) || ''}`, onClick: handleClose, title: isFailed || isSuccess ? '移除' : '取消上传', children: jsx(CloseIcon, {}) })] }));
|
|
63
|
+
return (jsxs("div", { className: `upload-file-item ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.container) || ''}`, "data-status": getStatusAttribute(), children: [jsxs("div", { className: `upload-file-info ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.info) || ''}`, children: [jsx("div", { className: `upload-file-icon ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.icon) || ''}`, children: jsx(FileIcon, {}) }), jsxs("span", { className: `upload-file-name ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.name) || ''}`, children: [file.fileName, file.relativePath && (jsx("span", { className: `upload-file-path ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.relativePath) || ''}`, children: file.relativePath }))] })] }), jsxs("div", { className: `upload-file-status ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.status) || ''}`, children: [jsx("span", { className: `upload-status-text ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.statusText) || ''}`, children: getStatusText() }), jsx("div", { className: semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.progress, children: jsx(CircleProgress, { percent: file.progress, isFailed: isFailed, isSuccess: isSuccess }) }), showPause && (jsx("button", { className: `upload-action-btn upload-pause-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.pauseBtn) || ''}`, onClick: () => onPause === null || onPause === void 0 ? void 0 : onPause(file.id), title: "\u6682\u505C\u4E0A\u4F20", children: jsx(PauseIcon, {}) })), showResume && (jsx("button", { className: `upload-action-btn upload-resume-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.resumeBtn) || ''}`, onClick: () => onResume === null || onResume === void 0 ? void 0 : onResume(file.id), title: "\u7EE7\u7EED\u4E0A\u4F20", children: jsx(ResumeIcon, {}) })), showRetry && (jsx("button", { className: `upload-action-btn upload-retry-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.retryBtn) || ''}`, onClick: () => onRetry === null || onRetry === void 0 ? void 0 : onRetry(file.id), title: "\u91CD\u8BD5\u4E0A\u4F20", children: jsx(RetryIcon, {}) }))] }), jsx("button", { className: `upload-action-btn upload-close-btn ${(semanticClassNames === null || semanticClassNames === void 0 ? void 0 : semanticClassNames.closeBtn) || ''}`, onClick: handleClose, title: isFailed || isSuccess ? '移除' : '取消上传', children: jsx(CloseIcon, {}) })] }));
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export { UploaderFileItem };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function useStyle() {
|
|
2
|
+
var style = document.createElement('style');
|
|
3
|
+
style.textContent = `.uploader-progress-bar {
|
|
4
|
+
padding: 0.75rem 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.uploader-progress-bar-info {
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-bottom: 0.5rem;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.uploader-progress-bar-text {
|
|
15
|
+
font-size: 0.875rem;
|
|
16
|
+
color: var(--uploader-text-secondary, #64748b);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.uploader-progress-bar-percent {
|
|
20
|
+
font-size: 0.875rem;
|
|
21
|
+
font-weight: 600;
|
|
22
|
+
color: var(--uploader-text, #1e293b);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.uploader-progress-bar-track {
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 0.5rem;
|
|
28
|
+
background-color: var(--uploader-border, #e2e8f0);
|
|
29
|
+
border-radius: 9999px;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.uploader-progress-bar-fill {
|
|
34
|
+
height: 100%;
|
|
35
|
+
background: linear-gradient(90deg, #3b82f6, #60a5fa);
|
|
36
|
+
border-radius: 9999px;
|
|
37
|
+
transition: width 0.3s ease;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
document.head.appendChild(style);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { useStyle as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useUpload } from '../hooks/use-upload.js';
|
|
3
|
+
import { UploadStatus } from '../constants.js';
|
|
4
|
+
import useStyle from './uploader-progress-bar.css.js';
|
|
5
|
+
|
|
6
|
+
useStyle();
|
|
7
|
+
function UploaderProgressBar({ hideWhenSingle = true, className = '' }) {
|
|
8
|
+
const { files } = useUpload();
|
|
9
|
+
if (files.length === 0)
|
|
10
|
+
return null;
|
|
11
|
+
if (hideWhenSingle && files.length <= 1)
|
|
12
|
+
return null;
|
|
13
|
+
const completedCount = files.filter((f) => f.status === UploadStatus.SUCCESS).length;
|
|
14
|
+
const totalCount = files.length;
|
|
15
|
+
const percent = totalCount > 0 ? Math.round((completedCount / totalCount) * 100) : 0;
|
|
16
|
+
return (jsxs("div", { className: `uploader-progress-bar ${className}`, children: [jsxs("div", { className: "uploader-progress-bar-info", children: [jsxs("span", { className: "uploader-progress-bar-text", children: ["\u5DF2\u5B8C\u6210: ", completedCount, " / ", totalCount, " \u4E2A\u6587\u4EF6"] }), jsxs("span", { className: "uploader-progress-bar-percent", children: [percent, "%"] })] }), jsx("div", { className: "uploader-progress-bar-track", children: jsx("div", { className: "uploader-progress-bar-fill", style: { width: `${percent}%` } }) })] }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { UploaderProgressBar };
|
|
@@ -6,6 +6,7 @@ import { DEFAULT_MAX_FILE_SIZE } from '../constants.js';
|
|
|
6
6
|
import { UploaderDropZone } from './uploader-drop-zone.js';
|
|
7
7
|
import { UploaderFileListLayout } from './uploader-file-list.js';
|
|
8
8
|
import { UploaderFileItem } from './uploader-file-item.js';
|
|
9
|
+
import { UploaderProgressBar } from './uploader-progress-bar.js';
|
|
9
10
|
import { useUpload } from '../hooks/use-upload.js';
|
|
10
11
|
|
|
11
12
|
useStyle();
|
|
@@ -39,15 +40,15 @@ useStyle$1();
|
|
|
39
40
|
*/
|
|
40
41
|
function Uploader(props) {
|
|
41
42
|
const { handlers, runtime, dragAreaDescription = '点击或拖拽上传文件', accept = '', directory = false, maxFiles, maxSize = DEFAULT_MAX_FILE_SIZE, // 10GB default
|
|
42
|
-
classNames, onDropZoneError, fileValidation, } = props;
|
|
43
|
+
classNames, onDropZoneError, fileValidation, showProgressBar = true, } = props;
|
|
43
44
|
const SemanticClassNames = typeof classNames === 'function' ? classNames(props) : classNames;
|
|
44
|
-
const { files, addFiles, startAll, cancel, removeFile } = useUpload();
|
|
45
|
+
const { files, addFiles, startAll, cancel, removeFile, retry } = useUpload();
|
|
45
46
|
// Auto-start newly added pending files
|
|
46
47
|
useEffect(() => {
|
|
47
48
|
startAll();
|
|
48
49
|
}, [startAll]);
|
|
49
50
|
const handleAddFiles = useCallback((dropped) => addFiles(dropped, { handlers }, runtime), [addFiles, handlers, runtime]);
|
|
50
|
-
return (jsxs("div", { className: `styled-uploader-container ${(SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.container) || ''}`, children: [jsx(UploaderDropZone, { accept: accept, directory: directory, maxFiles: maxFiles, maxSize: maxSize, dragAreaDescription: dragAreaDescription, onDrop: handleAddFiles, onError: onDropZoneError, fileValidation: fileValidation, classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.dragZone }), jsx(UploaderFileListLayout, { classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.fileList, children: files.map((file) => (jsx(UploaderFileItem, { file: file, onCancel: cancel, onRemove: removeFile, classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.fileItem }, file.id))) })] }));
|
|
51
|
+
return (jsxs("div", { className: `styled-uploader-container ${(SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.container) || ''}`, children: [jsx(UploaderDropZone, { accept: accept, directory: directory, maxFiles: maxFiles, maxSize: maxSize, dragAreaDescription: dragAreaDescription, onDrop: handleAddFiles, onError: onDropZoneError, fileValidation: fileValidation, classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.dragZone }), showProgressBar && jsx(UploaderProgressBar, {}), jsx(UploaderFileListLayout, { classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.fileList, children: files.map((file) => (jsx(UploaderFileItem, { file: file, onCancel: cancel, onRemove: removeFile, onRetry: retry, classNames: SemanticClassNames === null || SemanticClassNames === void 0 ? void 0 : SemanticClassNames.fileItem }, file.id))) })] }));
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export { Uploader };
|