@k3-universe/react-kit 0.0.20 → 0.0.21
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/index.js +2 -1
- package/dist/kit/components/fileuploader/FileUploader.d.ts +1 -1
- package/dist/kit/components/fileuploader/FileUploader.d.ts.map +1 -1
- package/dist/kit/components/fileuploader/types.d.ts +2 -0
- package/dist/kit/components/fileuploader/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/kit/components/fileuploader/FileUploader.tsx +46 -43
- package/src/kit/components/fileuploader/types.ts +3 -0
package/dist/index.js
CHANGED
|
@@ -31968,6 +31968,7 @@ function FileUploader({
|
|
|
31968
31968
|
onUploadSuccess,
|
|
31969
31969
|
onUploadError,
|
|
31970
31970
|
onRemove,
|
|
31971
|
+
withRetry = true,
|
|
31971
31972
|
onRetry,
|
|
31972
31973
|
onRetryAll,
|
|
31973
31974
|
multiple = true,
|
|
@@ -32279,7 +32280,7 @@ function FileUploader({
|
|
|
32279
32280
|
] })
|
|
32280
32281
|
] })
|
|
32281
32282
|
] }),
|
|
32282
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxs(
|
|
32283
|
+
withRetry && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxs(
|
|
32283
32284
|
Button$1,
|
|
32284
32285
|
{
|
|
32285
32286
|
size: "sm",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FileUploaderProps } from './types';
|
|
2
|
-
export declare function FileUploader({ value, defaultValue, onChange, uploader, onUploadSuccess, onUploadError, onRemove, onRetry, onRetryAll, multiple, maxFiles, accept, layout, disabled, withDownload, placeholder, className, }: FileUploaderProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function FileUploader({ value, defaultValue, onChange, uploader, onUploadSuccess, onUploadError, onRemove, withRetry, onRetry, onRetryAll, multiple, maxFiles, accept, layout, disabled, withDownload, placeholder, className, }: FileUploaderProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default FileUploader;
|
|
4
4
|
//# sourceMappingURL=FileUploader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUploader.d.ts","sourceRoot":"","sources":["../../../../src/kit/components/fileuploader/FileUploader.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA+C7D,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,aAAa,EACb,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAe,EACf,QAAQ,EACR,MAAM,EACN,MAAe,EACf,QAAQ,EACR,YAAmB,EACnB,WAA4D,EAC5D,SAAS,GACV,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"FileUploader.d.ts","sourceRoot":"","sources":["../../../../src/kit/components/fileuploader/FileUploader.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA+C7D,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,aAAa,EACb,QAAQ,EACR,SAAgB,EAChB,OAAO,EACP,UAAU,EACV,QAAe,EACf,QAAQ,EACR,MAAM,EACN,MAAe,EACf,QAAQ,EACR,YAAmB,EACnB,WAA4D,EAC5D,SAAS,GACV,EAAE,iBAAiB,2CAgZnB;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -39,6 +39,8 @@ export type FileUploaderProps = {
|
|
|
39
39
|
onUploadError?: (file: FileRecord, error: unknown) => void;
|
|
40
40
|
/** Called when a file is removed (useful to delete from server) */
|
|
41
41
|
onRemove?: (file: FileRecord) => void | Promise<void>;
|
|
42
|
+
/** Allow retrying errored uploads */
|
|
43
|
+
withRetry?: boolean;
|
|
42
44
|
/** Called when user retries an errored file upload */
|
|
43
45
|
onRetry?: (file: FileRecord) => void;
|
|
44
46
|
/** Called when user retries all failed uploads at once */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/kit/components/fileuploader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB;IACpB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,YAAY;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gCAAgC;IAChC,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,sDAAsD;IACtD,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,E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,CAAC,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -45,12 +45,12 @@ function isImageType(type?: string, name?: string) {
|
|
|
45
45
|
function pickIconByType(type?: string, name?: string) {
|
|
46
46
|
const t = (type || "").toLowerCase();
|
|
47
47
|
const ext = (name?.split(".").pop() || "").toLowerCase();
|
|
48
|
-
if (t.startsWith("image/") || ["png","jpg","jpeg","webp","gif","bmp","svg","heic","heif"].includes(ext)) return <ImageIcon className="h-8 w-8" />;
|
|
49
|
-
if (t.startsWith("video/") || ["mp4","mov","webm","mkv"].includes(ext)) return <Video className="h-8 w-8" />;
|
|
50
|
-
if (t.startsWith("audio/") || ["mp3","wav","aac","flac"].includes(ext)) return <Music className="h-8 w-8" />;
|
|
51
|
-
if (["zip","rar","7z","tar","gz"].includes(ext)) return <Archive className="h-8 w-8" />;
|
|
52
|
-
if (["txt","md","rtf"].includes(ext)) return <FileText className="h-8 w-8" />;
|
|
53
|
-
if (["js","ts","tsx","json","yml","yaml","xml","html","css"].includes(ext)) return <FileCode className="h-8 w-8" />;
|
|
48
|
+
if (t.startsWith("image/") || ["png", "jpg", "jpeg", "webp", "gif", "bmp", "svg", "heic", "heif"].includes(ext)) return <ImageIcon className="h-8 w-8" />;
|
|
49
|
+
if (t.startsWith("video/") || ["mp4", "mov", "webm", "mkv"].includes(ext)) return <Video className="h-8 w-8" />;
|
|
50
|
+
if (t.startsWith("audio/") || ["mp3", "wav", "aac", "flac"].includes(ext)) return <Music className="h-8 w-8" />;
|
|
51
|
+
if (["zip", "rar", "7z", "tar", "gz"].includes(ext)) return <Archive className="h-8 w-8" />;
|
|
52
|
+
if (["txt", "md", "rtf"].includes(ext)) return <FileText className="h-8 w-8" />;
|
|
53
|
+
if (["js", "ts", "tsx", "json", "yml", "yaml", "xml", "html", "css"].includes(ext)) return <FileCode className="h-8 w-8" />;
|
|
54
54
|
return <FileIcon className="h-8 w-8" />;
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -75,6 +75,7 @@ export function FileUploader({
|
|
|
75
75
|
onUploadSuccess,
|
|
76
76
|
onUploadError,
|
|
77
77
|
onRemove,
|
|
78
|
+
withRetry = true,
|
|
78
79
|
onRetry,
|
|
79
80
|
onRetryAll,
|
|
80
81
|
multiple = true,
|
|
@@ -114,7 +115,7 @@ export function FileUploader({
|
|
|
114
115
|
[onChange],
|
|
115
116
|
);
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
|
|
118
119
|
|
|
119
120
|
useEffect(() => {
|
|
120
121
|
if (isControlled && value) setFiles(value);
|
|
@@ -440,46 +441,48 @@ export function FileUploader({
|
|
|
440
441
|
</div>
|
|
441
442
|
</div>
|
|
442
443
|
</div>
|
|
443
|
-
|
|
444
|
-
<
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
444
|
+
{withRetry && (
|
|
445
|
+
<div className="flex items-center gap-2">
|
|
446
|
+
<Button
|
|
447
|
+
size="sm"
|
|
448
|
+
variant="ghost"
|
|
449
|
+
onClick={handleRetryAll}
|
|
450
|
+
disabled={
|
|
451
|
+
!!disabled || !uploader || files.every((f) => f.status !== "error" || !f.file)
|
|
452
|
+
}
|
|
453
|
+
>
|
|
454
|
+
<RotateCcw className="mr-1 h-4 w-4" /> Retry failed
|
|
455
|
+
</Button>
|
|
456
|
+
</div>
|
|
457
|
+
)}
|
|
455
458
|
</div>
|
|
456
459
|
</div>
|
|
457
460
|
|
|
458
461
|
<TooltipProvider>
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
462
|
+
<div
|
|
463
|
+
className={cn(
|
|
464
|
+
layout === "grid"
|
|
465
|
+
? "flex flex-wrap gap-3"
|
|
466
|
+
: "flex flex-col gap-2",
|
|
467
|
+
)}
|
|
468
|
+
>
|
|
469
|
+
{files.length === 0 ? (
|
|
470
|
+
<div className="text-sm text-muted-foreground">No files</div>
|
|
471
|
+
) : (
|
|
472
|
+
files.map((fr, i) => (
|
|
473
|
+
<FileItem
|
|
474
|
+
key={`${fr.name}-${i}`}
|
|
475
|
+
fr={fr}
|
|
476
|
+
idx={i}
|
|
477
|
+
layout={layout}
|
|
478
|
+
withDownload={withDownload}
|
|
479
|
+
uploaderPresent={!!uploader}
|
|
480
|
+
onRemove={onRemoveAt}
|
|
481
|
+
onRetry={onRetryAt}
|
|
482
|
+
/>
|
|
483
|
+
))
|
|
484
|
+
)}
|
|
485
|
+
</div>
|
|
483
486
|
</TooltipProvider>
|
|
484
487
|
</div>
|
|
485
488
|
);
|
|
@@ -48,6 +48,9 @@ export type FileUploaderProps = {
|
|
|
48
48
|
onUploadError?: (file: FileRecord, error: unknown) => void;
|
|
49
49
|
/** Called when a file is removed (useful to delete from server) */
|
|
50
50
|
onRemove?: (file: FileRecord) => void | Promise<void>;
|
|
51
|
+
|
|
52
|
+
/** Allow retrying errored uploads */
|
|
53
|
+
withRetry?: boolean;
|
|
51
54
|
/** Called when user retries an errored file upload */
|
|
52
55
|
onRetry?: (file: FileRecord) => void;
|
|
53
56
|
/** Called when user retries all failed uploads at once */
|