@dimah-s3/ui 1.1.1 → 1.2.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/dist/components/dimah-s3/delete/delete-button.d.ts +5 -9
- package/dist/components/dimah-s3/delete/delete-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/download/download-button.d.ts +5 -9
- package/dist/components/dimah-s3/download/download-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/download/progress-download-button.d.ts +5 -9
- package/dist/components/dimah-s3/download/progress-download-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/multi-upload-status.d.ts +5 -11
- package/dist/components/dimah-s3/upload/multi-upload-status.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/upload-button.d.ts +5 -9
- package/dist/components/dimah-s3/upload/upload-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/upload-dropzone.d.ts +5 -9
- package/dist/components/dimah-s3/upload/upload-dropzone.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/upload-status.d.ts +12 -6
- package/dist/components/dimah-s3/upload/upload-status.d.ts.map +1 -1
- package/dist/hooks/use-delete-toast.d.ts +7 -4
- package/dist/hooks/use-delete-toast.d.ts.map +1 -1
- package/dist/hooks/use-delete-ui.d.ts +16 -0
- package/dist/hooks/use-delete-ui.d.ts.map +1 -0
- package/dist/hooks/use-download-toast.d.ts +9 -13
- package/dist/hooks/use-download-toast.d.ts.map +1 -1
- package/dist/hooks/use-download-ui.d.ts +17 -0
- package/dist/hooks/use-download-ui.d.ts.map +1 -0
- package/dist/hooks/use-upload-toast.d.ts +2 -12
- package/dist/hooks/use-upload-toast.d.ts.map +1 -1
- package/dist/hooks/use-upload-ui.d.ts +13 -0
- package/dist/hooks/use-upload-ui.d.ts.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +558 -831
- package/dist/index.js.map +1 -1
- package/dist/lib/attachment-layout.d.ts +5 -2
- package/dist/lib/attachment-layout.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/components/dimah-s3/upload/upload-status-block.d.ts +0 -23
- package/dist/components/dimah-s3/upload/upload-status-block.d.ts.map +0 -1
- package/dist/components/dimah-s3/upload/upload-wired.d.ts +0 -48
- package/dist/components/dimah-s3/upload/upload-wired.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { AlertCircleIcon, PauseIcon, XIcon, LoaderIcon, DownloadIcon, Trash2Icon, CheckCircleIcon, LoaderCircleIcon,
|
|
2
|
+
import { AlertCircleIcon, PauseIcon, XIcon, CloudUpload, LoaderIcon, DownloadIcon, Trash2Icon, CheckCircleIcon, LoaderCircleIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from 'lucide-react';
|
|
3
3
|
import { useTranslations } from '@fuma-translate/react';
|
|
4
|
-
import { useFormatDimahError, formatEta, useDownload, useDelete, useMultiUpload, useUpload, formatAcceptLabels } from '@dimah-s3/react';
|
|
5
4
|
import { Button as Button$1 } from '@base-ui/react/button';
|
|
6
5
|
import { cva } from 'class-variance-authority';
|
|
7
6
|
import { cn } from 'cnfast';
|
|
8
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
8
|
import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
|
|
10
9
|
import { formatFileSize, truncateFileName, fileNameFromKey } from '@dimah-s3/core';
|
|
10
|
+
import { useFormatDimahError, formatEta, isFetchDownload, formatAcceptLabels } from '@dimah-s3/react';
|
|
11
11
|
import '@base-ui/react/merge-props';
|
|
12
12
|
import '@base-ui/react/use-render';
|
|
13
13
|
import { FileIcon, defaultStyles } from 'react-file-icon';
|
|
@@ -106,10 +106,11 @@ function TooltipContent({
|
|
|
106
106
|
// src/lib/attachment-layout.ts
|
|
107
107
|
var ATTACHMENT_ERROR_DESCRIPTION_CLASS = "overflow-visible whitespace-normal [overflow-wrap:anywhere]";
|
|
108
108
|
var ATTACHMENT_TITLE_CLASS = "max-w-[48ch] dark:shimmer-color-dimah-s3-muted-foreground";
|
|
109
|
-
function resolveStatusSlot(slot = true, node) {
|
|
109
|
+
function resolveStatusSlot(slot = true, node, wrap) {
|
|
110
110
|
if (slot === false) return null;
|
|
111
111
|
if (typeof slot === "function") return slot(node);
|
|
112
|
-
return
|
|
112
|
+
if (node == null) return null;
|
|
113
|
+
return wrap ? wrap(node) : node;
|
|
113
114
|
}
|
|
114
115
|
var attachmentVariants = cva(
|
|
115
116
|
"group/attachment relative flex w-fit max-w-full min-w-0 shrink-0 flex-wrap rounded-xl border bg-card text-card-foreground transition-colors focus-within:ring-1 focus-within:ring-ring/50 has-[>a,>button]:hover:bg-muted/50 data-[state=error]:border-destructive/30 data-[state=idle]:border-dashed",
|
|
@@ -608,104 +609,6 @@ function StatusAttachment({
|
|
|
608
609
|
}
|
|
609
610
|
);
|
|
610
611
|
}
|
|
611
|
-
function UploadStatus({
|
|
612
|
-
phase,
|
|
613
|
-
progress,
|
|
614
|
-
error,
|
|
615
|
-
fileInfo,
|
|
616
|
-
onCancel,
|
|
617
|
-
onPause,
|
|
618
|
-
size,
|
|
619
|
-
orientation,
|
|
620
|
-
className
|
|
621
|
-
}) {
|
|
622
|
-
const t = useTranslations();
|
|
623
|
-
const formatError = useFormatDimahError();
|
|
624
|
-
const errorText = error ? formatError(error) : null;
|
|
625
|
-
const layout = { size, orientation, className };
|
|
626
|
-
if (phase === "idle") return null;
|
|
627
|
-
if (phase === "uploading" && fileInfo) {
|
|
628
|
-
const eta = progress.speed && progress.total ? formatEta(progress.total - progress.loaded, progress.speed) : null;
|
|
629
|
-
return /* @__PURE__ */ jsx(
|
|
630
|
-
FileAttachment,
|
|
631
|
-
{
|
|
632
|
-
state: "uploading",
|
|
633
|
-
fileName: fileInfo.name,
|
|
634
|
-
fileSize: fileInfo.size,
|
|
635
|
-
fileType: fileInfo.type,
|
|
636
|
-
previewUrl: fileInfo.previewUrl,
|
|
637
|
-
percent: progress.percent,
|
|
638
|
-
description: eta ? `${formatFileSize(fileInfo.size)} \xB7 ${eta}` : void 0,
|
|
639
|
-
onCancel,
|
|
640
|
-
onPause,
|
|
641
|
-
...layout
|
|
642
|
-
}
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
if (phase === "success" && fileInfo) {
|
|
646
|
-
return /* @__PURE__ */ jsx(
|
|
647
|
-
FileAttachment,
|
|
648
|
-
{
|
|
649
|
-
state: "done",
|
|
650
|
-
fileName: fileInfo.name,
|
|
651
|
-
fileSize: fileInfo.size,
|
|
652
|
-
fileType: fileInfo.type,
|
|
653
|
-
previewUrl: fileInfo.previewUrl,
|
|
654
|
-
...layout
|
|
655
|
-
}
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
if (phase === "error") {
|
|
659
|
-
if (fileInfo) {
|
|
660
|
-
return /* @__PURE__ */ jsx(
|
|
661
|
-
FileAttachment,
|
|
662
|
-
{
|
|
663
|
-
state: "error",
|
|
664
|
-
fileName: fileInfo.name,
|
|
665
|
-
fileSize: fileInfo.size,
|
|
666
|
-
fileType: fileInfo.type,
|
|
667
|
-
previewUrl: fileInfo.previewUrl,
|
|
668
|
-
error: errorText,
|
|
669
|
-
...layout
|
|
670
|
-
}
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
return /* @__PURE__ */ jsx(
|
|
674
|
-
StatusAttachment,
|
|
675
|
-
{
|
|
676
|
-
state: "error",
|
|
677
|
-
title: t("Upload failed", { note: "status" }),
|
|
678
|
-
description: errorText ?? void 0,
|
|
679
|
-
...layout
|
|
680
|
-
}
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
if (phase === "validating" || phase === "presigning" || phase === "finalizing") {
|
|
684
|
-
if (fileInfo) {
|
|
685
|
-
return /* @__PURE__ */ jsx(
|
|
686
|
-
FileAttachment,
|
|
687
|
-
{
|
|
688
|
-
state: "processing",
|
|
689
|
-
fileName: fileInfo.name,
|
|
690
|
-
fileSize: fileInfo.size,
|
|
691
|
-
fileType: fileInfo.type,
|
|
692
|
-
previewUrl: fileInfo.previewUrl,
|
|
693
|
-
description: phase === "finalizing" ? t("Finishing\u2026", { note: "upload status" }) : t("Preparing\u2026", { note: "upload status" }),
|
|
694
|
-
...layout
|
|
695
|
-
}
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
return /* @__PURE__ */ jsx(
|
|
699
|
-
StatusAttachment,
|
|
700
|
-
{
|
|
701
|
-
state: "processing",
|
|
702
|
-
title: phase === "finalizing" ? t("Finishing\u2026", { note: "upload status" }) : t("Preparing\u2026", { note: "upload status" }),
|
|
703
|
-
...layout
|
|
704
|
-
}
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
return null;
|
|
708
|
-
}
|
|
709
612
|
function Progress({
|
|
710
613
|
className,
|
|
711
614
|
children,
|
|
@@ -776,29 +679,27 @@ function ProgressValue({ className, ...props }) {
|
|
|
776
679
|
);
|
|
777
680
|
}
|
|
778
681
|
function MultiUploadStatus({
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
error,
|
|
783
|
-
onCancel,
|
|
784
|
-
onPause,
|
|
785
|
-
size,
|
|
786
|
-
orientation,
|
|
682
|
+
upload,
|
|
683
|
+
attachmentSize,
|
|
684
|
+
attachmentOrientation,
|
|
787
685
|
className
|
|
788
686
|
}) {
|
|
789
687
|
const t = useTranslations();
|
|
790
688
|
const formatError = useFormatDimahError();
|
|
689
|
+
const { phase, files, progress, error } = upload;
|
|
690
|
+
const onCancel = upload.cancel;
|
|
691
|
+
const onPause = upload.resumable ? upload.detach : void 0;
|
|
791
692
|
const errorText = error ? formatError(error) : null;
|
|
792
|
-
const layout = {
|
|
693
|
+
const layout = {
|
|
694
|
+
size: attachmentSize,
|
|
695
|
+
orientation: attachmentOrientation
|
|
696
|
+
};
|
|
793
697
|
if (phase === "idle") return null;
|
|
794
698
|
if (phase === "uploading") {
|
|
795
|
-
const eta =
|
|
796
|
-
totalProgress.total - totalProgress.loaded,
|
|
797
|
-
totalProgress.speed
|
|
798
|
-
) : null;
|
|
699
|
+
const eta = progress.speed && progress.total ? formatEta(progress.total - progress.loaded, progress.speed) : null;
|
|
799
700
|
return /* @__PURE__ */ jsxs("div", { className: cn("flex w-full flex-col gap-2", className), children: [
|
|
800
701
|
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-1.5", children: [
|
|
801
|
-
/* @__PURE__ */ jsxs(Progress, { value:
|
|
702
|
+
/* @__PURE__ */ jsxs(Progress, { value: progress.percent, className: "flex-1", children: [
|
|
802
703
|
/* @__PURE__ */ jsxs(ProgressLabel, { children: [
|
|
803
704
|
t("{done}/{total} files", {
|
|
804
705
|
note: "upload progress",
|
|
@@ -898,6 +799,10 @@ function fileAttachmentState(status) {
|
|
|
898
799
|
return "error";
|
|
899
800
|
case "success":
|
|
900
801
|
return "done";
|
|
802
|
+
default: {
|
|
803
|
+
const _exhaustive = status;
|
|
804
|
+
return _exhaustive;
|
|
805
|
+
}
|
|
901
806
|
}
|
|
902
807
|
}
|
|
903
808
|
function FileList({
|
|
@@ -921,47 +826,136 @@ function FileList({
|
|
|
921
826
|
f.id
|
|
922
827
|
)) });
|
|
923
828
|
}
|
|
924
|
-
function
|
|
925
|
-
|
|
829
|
+
function UploadFileStatus({
|
|
830
|
+
phase,
|
|
831
|
+
error,
|
|
832
|
+
file,
|
|
833
|
+
onCancel,
|
|
834
|
+
onPause,
|
|
835
|
+
size,
|
|
836
|
+
orientation,
|
|
837
|
+
className
|
|
838
|
+
}) {
|
|
839
|
+
const t = useTranslations();
|
|
840
|
+
const formatError = useFormatDimahError();
|
|
841
|
+
const errorText = error ? formatError(error) : null;
|
|
926
842
|
const layout = { size, orientation, className };
|
|
927
|
-
|
|
928
|
-
|
|
843
|
+
const progress = file?.progress;
|
|
844
|
+
if (phase === "idle") return null;
|
|
845
|
+
if (phase === "uploading" && file) {
|
|
846
|
+
const eta = progress?.speed && progress.total ? formatEta(progress.total - progress.loaded, progress.speed) : null;
|
|
929
847
|
return /* @__PURE__ */ jsx(
|
|
930
|
-
|
|
848
|
+
FileAttachment,
|
|
931
849
|
{
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
850
|
+
state: "uploading",
|
|
851
|
+
fileName: file.name,
|
|
852
|
+
fileSize: file.size,
|
|
853
|
+
fileType: file.type,
|
|
854
|
+
previewUrl: file.previewUrl,
|
|
855
|
+
percent: progress?.percent,
|
|
856
|
+
description: eta ? `${formatFileSize(file.size)} \xB7 ${eta}` : void 0,
|
|
857
|
+
onCancel,
|
|
858
|
+
onPause,
|
|
938
859
|
...layout
|
|
939
860
|
}
|
|
940
861
|
);
|
|
941
862
|
}
|
|
942
|
-
if (
|
|
863
|
+
if (phase === "success" && file) {
|
|
943
864
|
return /* @__PURE__ */ jsx(
|
|
944
|
-
|
|
865
|
+
FileAttachment,
|
|
866
|
+
{
|
|
867
|
+
state: "done",
|
|
868
|
+
fileName: file.name,
|
|
869
|
+
fileSize: file.size,
|
|
870
|
+
fileType: file.type,
|
|
871
|
+
previewUrl: file.previewUrl,
|
|
872
|
+
...layout
|
|
873
|
+
}
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
if (phase === "error") {
|
|
877
|
+
if (file) {
|
|
878
|
+
return /* @__PURE__ */ jsx(
|
|
879
|
+
FileAttachment,
|
|
880
|
+
{
|
|
881
|
+
state: "error",
|
|
882
|
+
fileName: file.name,
|
|
883
|
+
fileSize: file.size,
|
|
884
|
+
fileType: file.type,
|
|
885
|
+
previewUrl: file.previewUrl,
|
|
886
|
+
error: errorText,
|
|
887
|
+
...layout
|
|
888
|
+
}
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
return /* @__PURE__ */ jsx(
|
|
892
|
+
StatusAttachment,
|
|
893
|
+
{
|
|
894
|
+
state: "error",
|
|
895
|
+
title: t("Upload failed", { note: "status" }),
|
|
896
|
+
description: errorText ?? void 0,
|
|
897
|
+
...layout
|
|
898
|
+
}
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
if (phase === "validating" || phase === "presigning" || phase === "finalizing") {
|
|
902
|
+
if (file) {
|
|
903
|
+
return /* @__PURE__ */ jsx(
|
|
904
|
+
FileAttachment,
|
|
905
|
+
{
|
|
906
|
+
state: "processing",
|
|
907
|
+
fileName: file.name,
|
|
908
|
+
fileSize: file.size,
|
|
909
|
+
fileType: file.type,
|
|
910
|
+
previewUrl: file.previewUrl,
|
|
911
|
+
description: phase === "finalizing" ? t("Finishing\u2026", { note: "upload status" }) : t("Preparing\u2026", { note: "upload status" }),
|
|
912
|
+
...layout
|
|
913
|
+
}
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
return /* @__PURE__ */ jsx(
|
|
917
|
+
StatusAttachment,
|
|
945
918
|
{
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
totalProgress: props.totalProgress,
|
|
949
|
-
error: props.error,
|
|
950
|
-
onCancel: props.onCancel,
|
|
951
|
-
onPause: props.onPause,
|
|
919
|
+
state: "processing",
|
|
920
|
+
title: phase === "finalizing" ? t("Finishing\u2026", { note: "upload status" }) : t("Preparing\u2026", { note: "upload status" }),
|
|
952
921
|
...layout
|
|
953
922
|
}
|
|
954
923
|
);
|
|
955
924
|
}
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
function UploadStatus({
|
|
928
|
+
upload,
|
|
929
|
+
attachmentSize,
|
|
930
|
+
attachmentOrientation,
|
|
931
|
+
className
|
|
932
|
+
}) {
|
|
933
|
+
const layout = {
|
|
934
|
+
size: attachmentSize,
|
|
935
|
+
orientation: attachmentOrientation,
|
|
936
|
+
className
|
|
937
|
+
};
|
|
938
|
+
const onCancel = upload.cancel;
|
|
939
|
+
const onPause = upload.resumable ? upload.detach : void 0;
|
|
940
|
+
if (upload.files.length > 1) {
|
|
941
|
+
return /* @__PURE__ */ jsx(
|
|
942
|
+
MultiUploadStatus,
|
|
943
|
+
{
|
|
944
|
+
upload,
|
|
945
|
+
attachmentSize,
|
|
946
|
+
attachmentOrientation,
|
|
947
|
+
className
|
|
948
|
+
}
|
|
949
|
+
);
|
|
950
|
+
}
|
|
956
951
|
return /* @__PURE__ */ jsx(
|
|
957
|
-
|
|
952
|
+
UploadFileStatus,
|
|
958
953
|
{
|
|
959
|
-
phase:
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
onPause: props.onPause,
|
|
954
|
+
phase: upload.phase,
|
|
955
|
+
error: upload.file?.error ?? upload.error,
|
|
956
|
+
file: upload.file,
|
|
957
|
+
onCancel,
|
|
958
|
+
onPause,
|
|
965
959
|
...layout
|
|
966
960
|
}
|
|
967
961
|
);
|
|
@@ -1148,24 +1142,22 @@ function progressNode(loaded, total) {
|
|
|
1148
1142
|
formatFileSize(total)
|
|
1149
1143
|
] });
|
|
1150
1144
|
}
|
|
1151
|
-
function useUploadToast(
|
|
1145
|
+
function useUploadToast(upload, enabled) {
|
|
1152
1146
|
const t = useTranslations();
|
|
1153
1147
|
const formatError = useFormatDimahError();
|
|
1154
1148
|
const toastIdRef = useRef(null);
|
|
1155
|
-
const prevPhaseRef = useRef(
|
|
1156
|
-
const cancelRef = useRef(
|
|
1149
|
+
const prevPhaseRef = useRef(upload.phase);
|
|
1150
|
+
const cancelRef = useRef(upload.cancel);
|
|
1157
1151
|
useLayoutEffect(() => {
|
|
1158
|
-
cancelRef.current =
|
|
1152
|
+
cancelRef.current = upload.cancel;
|
|
1159
1153
|
});
|
|
1160
|
-
const {
|
|
1154
|
+
const { phase, file, files, progress, error } = upload;
|
|
1161
1155
|
useEffect(() => {
|
|
1162
1156
|
if (prevPhaseRef.current === phase) return;
|
|
1163
1157
|
prevPhaseRef.current = phase;
|
|
1164
1158
|
if (!enabled) return;
|
|
1165
|
-
const
|
|
1166
|
-
const
|
|
1167
|
-
const file = fileInfo ?? (fileList.length === 1 ? { name: fileList[0].name, size: fileList[0].size } : null);
|
|
1168
|
-
const total = totalProgress?.total ?? 0;
|
|
1159
|
+
const isMulti = files.length > 1;
|
|
1160
|
+
const total = progress.total;
|
|
1169
1161
|
if (phase === "idle" && toastIdRef.current) {
|
|
1170
1162
|
toast.close(toastIdRef.current);
|
|
1171
1163
|
toastIdRef.current = null;
|
|
@@ -1177,7 +1169,7 @@ function useUploadToast(ctrl, enabled) {
|
|
|
1177
1169
|
type: "success",
|
|
1178
1170
|
title: t("{count} file(s) uploaded", {
|
|
1179
1171
|
note: "toast",
|
|
1180
|
-
variables: { count: String(
|
|
1172
|
+
variables: { count: String(files.length) }
|
|
1181
1173
|
}),
|
|
1182
1174
|
description: sizeNode(total)
|
|
1183
1175
|
});
|
|
@@ -1192,9 +1184,9 @@ function useUploadToast(ctrl, enabled) {
|
|
|
1192
1184
|
}
|
|
1193
1185
|
if (phase === "error") {
|
|
1194
1186
|
if (toastIdRef.current) toast.close(toastIdRef.current);
|
|
1195
|
-
if (isMulti &&
|
|
1196
|
-
const succeeded =
|
|
1197
|
-
const failed =
|
|
1187
|
+
if (isMulti && files.length > 0) {
|
|
1188
|
+
const succeeded = files.filter((f) => f.status === "success").length;
|
|
1189
|
+
const failed = files.filter((f) => f.status === "error").length;
|
|
1198
1190
|
toast.add({
|
|
1199
1191
|
type: "error",
|
|
1200
1192
|
title: t("Upload finished with errors", { note: "toast" }),
|
|
@@ -1217,42 +1209,27 @@ function useUploadToast(ctrl, enabled) {
|
|
|
1217
1209
|
toast.add({
|
|
1218
1210
|
type: "error",
|
|
1219
1211
|
title: t("Upload failed", { note: "toast" }),
|
|
1220
|
-
description: /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: error ? formatError(error) :
|
|
1212
|
+
description: /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: error ? formatError(error) : file?.error ? formatError(file.error) : t("Unknown error", { note: "fallback" }) })
|
|
1221
1213
|
});
|
|
1222
1214
|
}
|
|
1223
1215
|
toastIdRef.current = null;
|
|
1224
1216
|
}
|
|
1225
|
-
}, [
|
|
1226
|
-
enabled,
|
|
1227
|
-
phase,
|
|
1228
|
-
mode,
|
|
1229
|
-
fileInfo,
|
|
1230
|
-
files,
|
|
1231
|
-
totalProgress,
|
|
1232
|
-
error,
|
|
1233
|
-
t,
|
|
1234
|
-
formatError
|
|
1235
|
-
]);
|
|
1217
|
+
}, [enabled, phase, file, files, progress, error, t, formatError]);
|
|
1236
1218
|
useEffect(() => {
|
|
1237
1219
|
if (!enabled || phase !== "uploading") return;
|
|
1238
|
-
const
|
|
1239
|
-
const
|
|
1240
|
-
const file = fileInfo ?? (fileList.length === 1 ? { name: fileList[0].name, size: fileList[0].size } : null);
|
|
1241
|
-
const total = totalProgress ?? { loaded: 0, total: 0};
|
|
1242
|
-
const singleProgress = progress ?? (fileList.length === 1 ? fileList[0].progress : { loaded: 0});
|
|
1220
|
+
const isMulti = files.length > 1;
|
|
1221
|
+
const singleProgress = file?.progress ?? progress;
|
|
1243
1222
|
const payload = isMulti ? {
|
|
1244
1223
|
type: "loading",
|
|
1245
1224
|
timeout: 0,
|
|
1246
1225
|
title: t("Uploading {done}/{total}", {
|
|
1247
1226
|
note: "toast",
|
|
1248
1227
|
variables: {
|
|
1249
|
-
done: String(
|
|
1250
|
-
|
|
1251
|
-
),
|
|
1252
|
-
total: String(fileList.length)
|
|
1228
|
+
done: String(files.filter((f) => f.status === "success").length),
|
|
1229
|
+
total: String(files.length)
|
|
1253
1230
|
}
|
|
1254
1231
|
}),
|
|
1255
|
-
description: progressNode(
|
|
1232
|
+
description: progressNode(progress.loaded, progress.total),
|
|
1256
1233
|
actionProps: {
|
|
1257
1234
|
children: t("Cancel", { note: "toast action" }),
|
|
1258
1235
|
onClick: () => cancelRef.current()
|
|
@@ -1273,7 +1250,7 @@ function useUploadToast(ctrl, enabled) {
|
|
|
1273
1250
|
} else {
|
|
1274
1251
|
toastIdRef.current = toast.add(payload);
|
|
1275
1252
|
}
|
|
1276
|
-
}, [enabled, phase,
|
|
1253
|
+
}, [enabled, phase, file, files, progress, t]);
|
|
1277
1254
|
}
|
|
1278
1255
|
function rejectionSummary(rejections, t) {
|
|
1279
1256
|
const first = rejections[0];
|
|
@@ -1307,25 +1284,110 @@ function useFileRejectToast(fileRejections, enabled) {
|
|
|
1307
1284
|
});
|
|
1308
1285
|
}, [enabled, fileRejections, t]);
|
|
1309
1286
|
}
|
|
1310
|
-
function
|
|
1311
|
-
|
|
1287
|
+
function useUploadUi(upload, {
|
|
1288
|
+
toast: enableToast = true,
|
|
1289
|
+
attachmentSize,
|
|
1290
|
+
attachmentOrientation
|
|
1291
|
+
} = {}) {
|
|
1292
|
+
useUploadToast(upload, enableToast);
|
|
1293
|
+
useFileRejectToast(upload.fileRejections, enableToast);
|
|
1294
|
+
return {
|
|
1295
|
+
statusNode: /* @__PURE__ */ jsx(
|
|
1296
|
+
UploadStatus,
|
|
1297
|
+
{
|
|
1298
|
+
upload,
|
|
1299
|
+
attachmentSize,
|
|
1300
|
+
attachmentOrientation
|
|
1301
|
+
}
|
|
1302
|
+
)
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
function UploadButton({
|
|
1306
|
+
upload,
|
|
1307
|
+
className,
|
|
1308
|
+
label,
|
|
1309
|
+
children,
|
|
1310
|
+
disabled,
|
|
1311
|
+
tooltipText,
|
|
1312
|
+
toast: enableToast = true,
|
|
1313
|
+
status: statusSlot = true,
|
|
1314
|
+
variant = "default",
|
|
1315
|
+
size = "default",
|
|
1316
|
+
buttonClassName,
|
|
1317
|
+
attachmentSize,
|
|
1318
|
+
attachmentOrientation
|
|
1319
|
+
}) {
|
|
1320
|
+
const t = useTranslations();
|
|
1321
|
+
const isDisabled = Boolean(disabled) || upload.isPending;
|
|
1322
|
+
const { statusNode } = useUploadUi(upload, {
|
|
1323
|
+
toast: enableToast,
|
|
1324
|
+
attachmentSize,
|
|
1325
|
+
attachmentOrientation
|
|
1326
|
+
});
|
|
1327
|
+
const status = resolveStatusSlot(statusSlot, statusNode);
|
|
1328
|
+
const buttonLabel = label ?? (upload.policy.maxFiles > 1 ? t("Upload files", { note: "button" }) : t("Upload file", { note: "button" }));
|
|
1329
|
+
const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1330
|
+
/* @__PURE__ */ jsx(CloudUpload, { "data-icon": "inline-start" }),
|
|
1331
|
+
buttonLabel
|
|
1332
|
+
] });
|
|
1333
|
+
const button = /* @__PURE__ */ jsx(
|
|
1334
|
+
Button,
|
|
1335
|
+
{
|
|
1336
|
+
variant,
|
|
1337
|
+
size,
|
|
1338
|
+
className: buttonClassName,
|
|
1339
|
+
disabled: isDisabled,
|
|
1340
|
+
onClick: upload.open,
|
|
1341
|
+
children: buttonContent
|
|
1342
|
+
}
|
|
1343
|
+
);
|
|
1344
|
+
return /* @__PURE__ */ jsx(
|
|
1345
|
+
ButtonShell,
|
|
1346
|
+
{
|
|
1347
|
+
className,
|
|
1348
|
+
tooltipText,
|
|
1349
|
+
getInputProps: upload.getInputProps,
|
|
1350
|
+
button,
|
|
1351
|
+
status,
|
|
1352
|
+
inputDisabled: isDisabled
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
function ButtonShell({
|
|
1357
|
+
className,
|
|
1358
|
+
tooltipText,
|
|
1359
|
+
getInputProps,
|
|
1360
|
+
button,
|
|
1361
|
+
status,
|
|
1362
|
+
inputDisabled
|
|
1363
|
+
}) {
|
|
1364
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
|
|
1365
|
+
/* @__PURE__ */ jsxs("div", { className: "inline-flex items-center gap-2", children: [
|
|
1366
|
+
/* @__PURE__ */ jsx("input", { ...getInputProps({ disabled: inputDisabled }) }),
|
|
1367
|
+
tooltipText ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
1368
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { render: button }),
|
|
1369
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: tooltipText })
|
|
1370
|
+
] }) : button
|
|
1371
|
+
] }),
|
|
1372
|
+
status
|
|
1373
|
+
] });
|
|
1312
1374
|
}
|
|
1313
|
-
function dropzoneHints(
|
|
1314
|
-
const acceptLabels = formatAcceptLabels(
|
|
1315
|
-
const maxFiles =
|
|
1375
|
+
function dropzoneHints(policy, t) {
|
|
1376
|
+
const acceptLabels = formatAcceptLabels(policy.accept);
|
|
1377
|
+
const maxFiles = policy.maxFiles;
|
|
1316
1378
|
const limitParts = [];
|
|
1317
|
-
if (maxFiles
|
|
1379
|
+
if (maxFiles > 1) {
|
|
1318
1380
|
limitParts.push(
|
|
1319
|
-
|
|
1381
|
+
t("You can upload {count} files", {
|
|
1320
1382
|
note: "dropzone hint",
|
|
1321
1383
|
variables: { count: String(maxFiles) }
|
|
1322
1384
|
})
|
|
1323
1385
|
);
|
|
1324
1386
|
}
|
|
1325
|
-
if (
|
|
1326
|
-
const size = formatFileSize(
|
|
1387
|
+
if (policy.maxFileSize != null) {
|
|
1388
|
+
const size = formatFileSize(policy.maxFileSize);
|
|
1327
1389
|
limitParts.push(
|
|
1328
|
-
maxFiles
|
|
1390
|
+
maxFiles > 1 ? t("Each up to {size}", {
|
|
1329
1391
|
note: "dropzone hint",
|
|
1330
1392
|
variables: { size }
|
|
1331
1393
|
}) : t("Up to {size}", {
|
|
@@ -1341,453 +1403,200 @@ function dropzoneHints(options, t) {
|
|
|
1341
1403
|
}) : null;
|
|
1342
1404
|
return { limitsLine, acceptLine };
|
|
1343
1405
|
}
|
|
1344
|
-
function
|
|
1345
|
-
|
|
1346
|
-
limitsLine,
|
|
1347
|
-
acceptLine,
|
|
1348
|
-
isDisabled,
|
|
1349
|
-
children
|
|
1350
|
-
}) {
|
|
1351
|
-
if (children != null) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1352
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1353
|
-
/* @__PURE__ */ jsx(
|
|
1354
|
-
CloudUpload,
|
|
1355
|
-
{
|
|
1356
|
-
className: cn("size-6", isDisabled && "opacity-50"),
|
|
1357
|
-
strokeWidth: 1.5
|
|
1358
|
-
}
|
|
1359
|
-
),
|
|
1360
|
-
/* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-1", isDisabled && "opacity-50"), children: [
|
|
1361
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: label }),
|
|
1362
|
-
limitsLine && /* @__PURE__ */ jsx("p", { className: "text-xs text-dimah-s3-muted-foreground", children: limitsLine }),
|
|
1363
|
-
acceptLine && /* @__PURE__ */ jsx("p", { className: "text-xs text-dimah-s3-muted-foreground", children: acceptLine })
|
|
1364
|
-
] })
|
|
1365
|
-
] });
|
|
1366
|
-
}
|
|
1367
|
-
function DropzoneFrame({
|
|
1368
|
-
getRootProps,
|
|
1369
|
-
getInputProps,
|
|
1370
|
-
isDisabled,
|
|
1371
|
-
isDragReject,
|
|
1372
|
-
isDragAccept,
|
|
1373
|
-
isDragActive,
|
|
1406
|
+
function UploadDropzone({
|
|
1407
|
+
upload,
|
|
1374
1408
|
className,
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1409
|
+
label,
|
|
1410
|
+
children,
|
|
1411
|
+
disabled,
|
|
1412
|
+
toast: enableToast = true,
|
|
1413
|
+
status: statusSlot = true,
|
|
1414
|
+
attachmentSize,
|
|
1415
|
+
attachmentOrientation
|
|
1379
1416
|
}) {
|
|
1417
|
+
const t = useTranslations();
|
|
1418
|
+
const isDisabled = Boolean(disabled) || upload.isPending;
|
|
1419
|
+
const hasCustomChrome = children != null;
|
|
1420
|
+
const dropzoneLabel = label ?? t("Drag and drop files here", { note: "dropzone" });
|
|
1421
|
+
const { limitsLine, acceptLine } = dropzoneHints(upload.policy, t);
|
|
1422
|
+
const { statusNode } = useUploadUi(upload, {
|
|
1423
|
+
toast: enableToast,
|
|
1424
|
+
attachmentSize,
|
|
1425
|
+
attachmentOrientation
|
|
1426
|
+
});
|
|
1427
|
+
const status = resolveStatusSlot(statusSlot, statusNode, (node) => /* @__PURE__ */ jsx(
|
|
1428
|
+
"div",
|
|
1429
|
+
{
|
|
1430
|
+
className: hasCustomChrome ? "w-full px-3 pb-3 text-start" : "w-full text-start",
|
|
1431
|
+
children: node
|
|
1432
|
+
}
|
|
1433
|
+
));
|
|
1380
1434
|
return /* @__PURE__ */ jsxs(
|
|
1381
1435
|
"div",
|
|
1382
1436
|
{
|
|
1383
|
-
...getRootProps({
|
|
1384
|
-
"aria-label":
|
|
1437
|
+
...upload.getRootProps({
|
|
1438
|
+
"aria-label": dropzoneLabel,
|
|
1439
|
+
"aria-disabled": isDisabled || void 0,
|
|
1385
1440
|
className: cn(
|
|
1386
1441
|
"rounded-lg border-2 border-dashed transition-colors",
|
|
1387
1442
|
hasCustomChrome ? "flex flex-col items-stretch justify-stretch gap-3 p-0" : "flex flex-col items-center justify-center gap-3 p-6 text-center",
|
|
1388
|
-
isDisabled ? "cursor-not-allowed border-dimah-s3-muted-foreground/25" : "cursor-pointer border-dimah-s3-muted-foreground/25 hover:border-dimah-s3-primary/50",
|
|
1389
|
-
!isDisabled && isDragReject && "border-dimah-s3-destructive bg-dimah-s3-destructive/5",
|
|
1390
|
-
!isDisabled && isDragAccept && "border-dimah-s3-primary bg-dimah-s3-primary/5",
|
|
1391
|
-
!isDisabled && isDragActive && !isDragAccept && !isDragReject && "border-dimah-s3-primary/50",
|
|
1443
|
+
isDisabled ? "pointer-events-none cursor-not-allowed border-dimah-s3-muted-foreground/25" : "cursor-pointer border-dimah-s3-muted-foreground/25 hover:border-dimah-s3-primary/50",
|
|
1444
|
+
!isDisabled && upload.isDragReject && "border-dimah-s3-destructive bg-dimah-s3-destructive/5",
|
|
1445
|
+
!isDisabled && upload.isDragAccept && "border-dimah-s3-primary bg-dimah-s3-primary/5",
|
|
1446
|
+
!isDisabled && upload.isDragActive && !upload.isDragAccept && !upload.isDragReject && "border-dimah-s3-primary/50",
|
|
1392
1447
|
className
|
|
1393
1448
|
)
|
|
1394
1449
|
}),
|
|
1395
1450
|
children: [
|
|
1396
|
-
/* @__PURE__ */ jsx("input", { ...getInputProps() }),
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
useFileRejectToast(ctrl.fileRejections, enableToast);
|
|
1420
|
-
const statusNode = statusSlot === false ? null : /* @__PURE__ */ jsx(
|
|
1421
|
-
UploadStatusBlock,
|
|
1422
|
-
{
|
|
1423
|
-
mode: "single",
|
|
1424
|
-
phase: ctrl.phase,
|
|
1425
|
-
progress: ctrl.progress,
|
|
1426
|
-
error: ctrl.error,
|
|
1427
|
-
fileInfo: ctrl.fileInfo,
|
|
1428
|
-
onCancel: ctrl.cancel,
|
|
1429
|
-
onPause: canPause ? ctrl.detach : void 0,
|
|
1430
|
-
size: attachmentSize,
|
|
1431
|
-
orientation: attachmentOrientation
|
|
1432
|
-
}
|
|
1433
|
-
);
|
|
1434
|
-
return { statusNode, statusSlot };
|
|
1435
|
-
}
|
|
1436
|
-
function useMultiUploadUi(ctrl, {
|
|
1437
|
-
toast: enableToast = true,
|
|
1438
|
-
status: statusSlot = true,
|
|
1439
|
-
attachmentSize,
|
|
1440
|
-
attachmentOrientation,
|
|
1441
|
-
canPause
|
|
1442
|
-
}) {
|
|
1443
|
-
const toastCtrl = {
|
|
1444
|
-
mode: "multi",
|
|
1445
|
-
phase: ctrl.phase,
|
|
1446
|
-
files: ctrl.files,
|
|
1447
|
-
totalProgress: ctrl.totalProgress,
|
|
1448
|
-
error: ctrl.error,
|
|
1449
|
-
cancel: ctrl.cancel
|
|
1450
|
-
};
|
|
1451
|
-
useUploadToast(toastCtrl, enableToast);
|
|
1452
|
-
useFileRejectToast(ctrl.fileRejections, enableToast);
|
|
1453
|
-
const statusNode = statusSlot === false ? null : /* @__PURE__ */ jsx(
|
|
1454
|
-
UploadStatusBlock,
|
|
1455
|
-
{
|
|
1456
|
-
mode: "multi",
|
|
1457
|
-
phase: ctrl.phase,
|
|
1458
|
-
files: ctrl.files,
|
|
1459
|
-
totalProgress: ctrl.totalProgress,
|
|
1460
|
-
error: ctrl.error,
|
|
1461
|
-
onCancel: ctrl.cancel,
|
|
1462
|
-
onPause: canPause ? ctrl.detach : void 0,
|
|
1463
|
-
size: attachmentSize,
|
|
1464
|
-
orientation: attachmentOrientation
|
|
1451
|
+
/* @__PURE__ */ jsx("input", { ...upload.getInputProps({ disabled: isDisabled }) }),
|
|
1452
|
+
children != null ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1453
|
+
/* @__PURE__ */ jsx(
|
|
1454
|
+
CloudUpload,
|
|
1455
|
+
{
|
|
1456
|
+
className: cn("size-6", isDisabled && "opacity-50"),
|
|
1457
|
+
strokeWidth: 1.5
|
|
1458
|
+
}
|
|
1459
|
+
),
|
|
1460
|
+
/* @__PURE__ */ jsxs(
|
|
1461
|
+
"div",
|
|
1462
|
+
{
|
|
1463
|
+
className: cn("flex flex-col gap-1", isDisabled && "opacity-50"),
|
|
1464
|
+
children: [
|
|
1465
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: dropzoneLabel }),
|
|
1466
|
+
limitsLine ? /* @__PURE__ */ jsx("p", { className: "text-xs text-dimah-s3-muted-foreground", children: limitsLine }) : null,
|
|
1467
|
+
acceptLine ? /* @__PURE__ */ jsx("p", { className: "text-xs text-dimah-s3-muted-foreground", children: acceptLine }) : null
|
|
1468
|
+
]
|
|
1469
|
+
}
|
|
1470
|
+
)
|
|
1471
|
+
] }),
|
|
1472
|
+
status
|
|
1473
|
+
]
|
|
1465
1474
|
}
|
|
1466
1475
|
);
|
|
1467
|
-
return { statusNode, statusSlot };
|
|
1468
|
-
}
|
|
1469
|
-
function resolveDefaultStatus(statusSlot, statusNode, wrap) {
|
|
1470
|
-
if (typeof statusSlot === "function") return statusSlot(statusNode);
|
|
1471
|
-
const defaultStatus = statusNode == null ? null : wrap ? wrap(statusNode) : statusNode;
|
|
1472
|
-
return resolveStatusSlot(statusSlot, defaultStatus);
|
|
1473
|
-
}
|
|
1474
|
-
function buttonShell({
|
|
1475
|
-
className,
|
|
1476
|
-
tooltipText,
|
|
1477
|
-
getInputProps,
|
|
1478
|
-
button,
|
|
1479
|
-
status
|
|
1480
|
-
}) {
|
|
1481
|
-
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
|
|
1482
|
-
/* @__PURE__ */ jsxs("div", { className: "inline-flex items-center gap-2", children: [
|
|
1483
|
-
/* @__PURE__ */ jsx("input", { ...getInputProps() }),
|
|
1484
|
-
tooltipText ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
1485
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { render: button }),
|
|
1486
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: tooltipText })
|
|
1487
|
-
] }) : button
|
|
1488
|
-
] }),
|
|
1489
|
-
status
|
|
1490
|
-
] });
|
|
1491
1476
|
}
|
|
1492
|
-
function
|
|
1493
|
-
className,
|
|
1494
|
-
label,
|
|
1495
|
-
children,
|
|
1496
|
-
disabled,
|
|
1497
|
-
tooltipText,
|
|
1498
|
-
toast: enableToast = true,
|
|
1499
|
-
status: statusSlot = true,
|
|
1500
|
-
variant = "default",
|
|
1501
|
-
size = "default",
|
|
1502
|
-
buttonClassName,
|
|
1503
|
-
attachmentSize,
|
|
1504
|
-
attachmentOrientation,
|
|
1505
|
-
...options
|
|
1506
|
-
}) {
|
|
1477
|
+
function useDownloadToast(download, { enabled = true, objectKey, fileName, fileSize }) {
|
|
1507
1478
|
const t = useTranslations();
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
toast: enableToast,
|
|
1518
|
-
status: statusSlot,
|
|
1519
|
-
attachmentSize,
|
|
1520
|
-
attachmentOrientation,
|
|
1521
|
-
canPause: canPauseUpload(options.uploadStore)
|
|
1479
|
+
const formatDimahError = useFormatDimahError();
|
|
1480
|
+
const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
|
|
1481
|
+
const toastIdRef = useRef(null);
|
|
1482
|
+
const prevPhaseRef = useRef(download.phase);
|
|
1483
|
+
const cancelRef = useRef(
|
|
1484
|
+
isFetchDownload(download) ? download.cancel : void 0
|
|
1485
|
+
);
|
|
1486
|
+
useLayoutEffect(() => {
|
|
1487
|
+
cancelRef.current = isFetchDownload(download) ? download.cancel : void 0;
|
|
1522
1488
|
});
|
|
1523
|
-
const
|
|
1524
|
-
const
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
disabled: isDisabled,
|
|
1541
|
-
onClick: ctrl.open,
|
|
1542
|
-
children: buttonContent
|
|
1489
|
+
const fetchMode = isFetchDownload(download);
|
|
1490
|
+
const phase = download.phase;
|
|
1491
|
+
const error = download.error;
|
|
1492
|
+
const url = fetchMode ? null : download.url;
|
|
1493
|
+
const resolvedFileName = fetchMode ? download.fileName : null;
|
|
1494
|
+
const progress = fetchMode ? download.progress : null;
|
|
1495
|
+
const activeKey = download.objectKey;
|
|
1496
|
+
useEffect(() => {
|
|
1497
|
+
if (prevPhaseRef.current === phase) return;
|
|
1498
|
+
const prev = prevPhaseRef.current;
|
|
1499
|
+
prevPhaseRef.current = phase;
|
|
1500
|
+
if (!enabled || activeKey !== objectKey) return;
|
|
1501
|
+
const errorNode = (value) => /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: formatDimahError(value) });
|
|
1502
|
+
const closeLoading = () => {
|
|
1503
|
+
if (toastIdRef.current) {
|
|
1504
|
+
toast.close(toastIdRef.current);
|
|
1505
|
+
toastIdRef.current = null;
|
|
1543
1506
|
}
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
attachmentOrientation,
|
|
1560
|
-
...options
|
|
1561
|
-
}) {
|
|
1562
|
-
const t = useTranslations();
|
|
1563
|
-
const ctrl = useMultiUpload({
|
|
1564
|
-
...options,
|
|
1565
|
-
disabled,
|
|
1566
|
-
noDrag: true,
|
|
1567
|
-
noClick: true,
|
|
1568
|
-
noKeyboard: true
|
|
1569
|
-
});
|
|
1570
|
-
const isDisabled = disabled || ctrl.isPending;
|
|
1571
|
-
const { statusNode } = useMultiUploadUi(ctrl, {
|
|
1572
|
-
toast: enableToast,
|
|
1573
|
-
status: statusSlot,
|
|
1574
|
-
attachmentSize,
|
|
1575
|
-
attachmentOrientation,
|
|
1576
|
-
canPause: canPauseUpload(options.uploadStore)
|
|
1577
|
-
});
|
|
1578
|
-
const status = resolveStatusSlot(statusSlot, statusNode);
|
|
1579
|
-
const buttonLabel = label ?? t("Upload files", { note: "button" });
|
|
1580
|
-
const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1581
|
-
/* @__PURE__ */ jsx(CloudUpload, { "data-icon": "inline-start" }),
|
|
1582
|
-
buttonLabel
|
|
1583
|
-
] });
|
|
1584
|
-
return buttonShell({
|
|
1585
|
-
className,
|
|
1586
|
-
tooltipText,
|
|
1587
|
-
getInputProps: ctrl.getInputProps,
|
|
1588
|
-
status,
|
|
1589
|
-
button: /* @__PURE__ */ jsx(
|
|
1590
|
-
Button,
|
|
1591
|
-
{
|
|
1592
|
-
variant,
|
|
1593
|
-
size,
|
|
1594
|
-
className: buttonClassName,
|
|
1595
|
-
disabled: isDisabled,
|
|
1596
|
-
onClick: ctrl.open,
|
|
1597
|
-
children: buttonContent
|
|
1507
|
+
};
|
|
1508
|
+
if (fetchMode) {
|
|
1509
|
+
if (phase === "downloading") {
|
|
1510
|
+
closeLoading();
|
|
1511
|
+
toastIdRef.current = toast.add({
|
|
1512
|
+
type: "loading",
|
|
1513
|
+
timeout: 0,
|
|
1514
|
+
title: t("Downloading", { note: "toast" }),
|
|
1515
|
+
description: /* @__PURE__ */ jsx("span", { dir: "auto", children: /* @__PURE__ */ jsx("bdi", { children: truncateFileName(displayName) }) }),
|
|
1516
|
+
actionProps: {
|
|
1517
|
+
children: t("Cancel", { note: "toast action" }),
|
|
1518
|
+
onClick: () => cancelRef.current?.()
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
return;
|
|
1598
1522
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1523
|
+
if (phase === "success") {
|
|
1524
|
+
closeLoading();
|
|
1525
|
+
const actualName = resolvedFileName ?? displayName;
|
|
1526
|
+
toast.add({
|
|
1527
|
+
type: "success",
|
|
1528
|
+
title: t("Download complete", { note: "toast" }),
|
|
1529
|
+
description: /* @__PURE__ */ jsxs("span", { className: "block", children: [
|
|
1530
|
+
/* @__PURE__ */ jsx("bdi", { children: truncateFileName(actualName) }),
|
|
1531
|
+
fileSize != null ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1532
|
+
" ",
|
|
1533
|
+
"\xB7",
|
|
1534
|
+
" ",
|
|
1535
|
+
/* @__PURE__ */ jsx(
|
|
1536
|
+
"span",
|
|
1537
|
+
{
|
|
1538
|
+
dir: "ltr",
|
|
1539
|
+
className: "inline-block whitespace-nowrap tabular-nums",
|
|
1540
|
+
children: formatFileSize(fileSize)
|
|
1541
|
+
}
|
|
1542
|
+
)
|
|
1543
|
+
] }) : null
|
|
1544
|
+
] })
|
|
1545
|
+
});
|
|
1546
|
+
return;
|
|
1609
1547
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
disabled,
|
|
1619
|
-
toast: enableToast = true,
|
|
1620
|
-
status: statusSlot = true,
|
|
1621
|
-
attachmentSize,
|
|
1622
|
-
attachmentOrientation,
|
|
1623
|
-
...options
|
|
1624
|
-
}) {
|
|
1625
|
-
const t = useTranslations();
|
|
1626
|
-
const ctrl = useUpload({ ...options, disabled });
|
|
1627
|
-
const isDisabled = disabled || ctrl.isPending;
|
|
1628
|
-
const hasCustomChrome = children != null;
|
|
1629
|
-
const dropzoneLabel = label ?? t("Drag and drop files here", { note: "dropzone" });
|
|
1630
|
-
const { limitsLine, acceptLine } = dropzoneHints(options, t);
|
|
1631
|
-
const { statusNode } = useSingleUploadUi(ctrl, {
|
|
1632
|
-
toast: enableToast,
|
|
1633
|
-
status: statusSlot,
|
|
1634
|
-
attachmentSize,
|
|
1635
|
-
attachmentOrientation,
|
|
1636
|
-
canPause: canPauseUpload(options.uploadStore)
|
|
1637
|
-
});
|
|
1638
|
-
const status = resolveDefaultStatus(statusSlot, statusNode, (node) => /* @__PURE__ */ jsx(
|
|
1639
|
-
"div",
|
|
1640
|
-
{
|
|
1641
|
-
className: hasCustomChrome ? "w-full px-3 pb-3 text-start" : "w-full text-start",
|
|
1642
|
-
children: node
|
|
1643
|
-
}
|
|
1644
|
-
));
|
|
1645
|
-
return /* @__PURE__ */ jsx(
|
|
1646
|
-
DropzoneFrame,
|
|
1647
|
-
{
|
|
1648
|
-
getRootProps: ctrl.getRootProps,
|
|
1649
|
-
getInputProps: ctrl.getInputProps,
|
|
1650
|
-
isDisabled,
|
|
1651
|
-
isDragReject: ctrl.isDragReject,
|
|
1652
|
-
isDragAccept: ctrl.isDragAccept,
|
|
1653
|
-
isDragActive: ctrl.isDragActive,
|
|
1654
|
-
className,
|
|
1655
|
-
hasCustomChrome,
|
|
1656
|
-
ariaLabel: dropzoneLabel,
|
|
1657
|
-
chrome: /* @__PURE__ */ jsx(
|
|
1658
|
-
DropzoneChrome,
|
|
1659
|
-
{
|
|
1660
|
-
label: dropzoneLabel,
|
|
1661
|
-
limitsLine,
|
|
1662
|
-
acceptLine,
|
|
1663
|
-
isDisabled,
|
|
1664
|
-
children
|
|
1665
|
-
}
|
|
1666
|
-
),
|
|
1667
|
-
status
|
|
1668
|
-
}
|
|
1669
|
-
);
|
|
1670
|
-
}
|
|
1671
|
-
function UploadDropzoneMulti({
|
|
1672
|
-
className,
|
|
1673
|
-
label,
|
|
1674
|
-
children,
|
|
1675
|
-
disabled,
|
|
1676
|
-
toast: enableToast = true,
|
|
1677
|
-
status: statusSlot = true,
|
|
1678
|
-
attachmentSize,
|
|
1679
|
-
attachmentOrientation,
|
|
1680
|
-
...options
|
|
1681
|
-
}) {
|
|
1682
|
-
const t = useTranslations();
|
|
1683
|
-
const ctrl = useMultiUpload({ ...options, disabled });
|
|
1684
|
-
const isDisabled = disabled || ctrl.isPending;
|
|
1685
|
-
const hasCustomChrome = children != null;
|
|
1686
|
-
const dropzoneLabel = label ?? t("Drag and drop files here", { note: "dropzone" });
|
|
1687
|
-
const { limitsLine, acceptLine } = dropzoneHints(options, t);
|
|
1688
|
-
const { statusNode } = useMultiUploadUi(ctrl, {
|
|
1689
|
-
toast: enableToast,
|
|
1690
|
-
status: statusSlot,
|
|
1691
|
-
attachmentSize,
|
|
1692
|
-
attachmentOrientation,
|
|
1693
|
-
canPause: canPauseUpload(options.uploadStore)
|
|
1694
|
-
});
|
|
1695
|
-
const status = resolveDefaultStatus(statusSlot, statusNode, (node) => /* @__PURE__ */ jsx(
|
|
1696
|
-
"div",
|
|
1697
|
-
{
|
|
1698
|
-
className: hasCustomChrome ? "w-full px-3 pb-3 text-start" : "w-full text-start",
|
|
1699
|
-
children: node
|
|
1700
|
-
}
|
|
1701
|
-
));
|
|
1702
|
-
return /* @__PURE__ */ jsx(
|
|
1703
|
-
DropzoneFrame,
|
|
1704
|
-
{
|
|
1705
|
-
getRootProps: ctrl.getRootProps,
|
|
1706
|
-
getInputProps: ctrl.getInputProps,
|
|
1707
|
-
isDisabled,
|
|
1708
|
-
isDragReject: ctrl.isDragReject,
|
|
1709
|
-
isDragAccept: ctrl.isDragAccept,
|
|
1710
|
-
isDragActive: ctrl.isDragActive,
|
|
1711
|
-
className,
|
|
1712
|
-
hasCustomChrome,
|
|
1713
|
-
ariaLabel: dropzoneLabel,
|
|
1714
|
-
chrome: /* @__PURE__ */ jsx(
|
|
1715
|
-
DropzoneChrome,
|
|
1716
|
-
{
|
|
1717
|
-
label: dropzoneLabel,
|
|
1718
|
-
limitsLine,
|
|
1719
|
-
acceptLine,
|
|
1720
|
-
isDisabled,
|
|
1721
|
-
children
|
|
1722
|
-
}
|
|
1723
|
-
),
|
|
1724
|
-
status
|
|
1725
|
-
}
|
|
1726
|
-
);
|
|
1727
|
-
}
|
|
1728
|
-
function UploadDropzone({ multiple, ...props }) {
|
|
1729
|
-
const isMulti = multiple === true || (props.maxFiles ?? 1) > 1;
|
|
1730
|
-
if (isMulti) {
|
|
1731
|
-
return /* @__PURE__ */ jsx(
|
|
1732
|
-
UploadDropzoneMulti,
|
|
1733
|
-
{
|
|
1734
|
-
...props
|
|
1548
|
+
if (phase === "error") {
|
|
1549
|
+
closeLoading();
|
|
1550
|
+
toast.add({
|
|
1551
|
+
type: "error",
|
|
1552
|
+
title: t("Download failed", { note: "toast" }),
|
|
1553
|
+
description: errorNode(error)
|
|
1554
|
+
});
|
|
1555
|
+
return;
|
|
1735
1556
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1557
|
+
if (phase === "idle" && (prev === "presigning" || prev === "downloading")) {
|
|
1558
|
+
closeLoading();
|
|
1559
|
+
toast.add({
|
|
1560
|
+
type: "info",
|
|
1561
|
+
title: t("Download cancelled", { note: "toast" }),
|
|
1562
|
+
description: /* @__PURE__ */ jsx("span", { dir: "auto", children: truncateFileName(displayName) })
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
return;
|
|
1742
1566
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
cancel
|
|
1751
|
-
}) {
|
|
1752
|
-
const t = useTranslations();
|
|
1753
|
-
const formatDimahError = useFormatDimahError();
|
|
1754
|
-
const displayName = fileName ?? objectKey.split("/").pop() ?? objectKey;
|
|
1755
|
-
const toastIdRef = useRef(null);
|
|
1756
|
-
const cancelRef = useRef(cancel);
|
|
1757
|
-
useLayoutEffect(() => {
|
|
1758
|
-
cancelRef.current = cancel;
|
|
1759
|
-
});
|
|
1760
|
-
const errorNode = (error) => /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: formatDimahError(error) });
|
|
1761
|
-
const closeLoading = () => {
|
|
1762
|
-
if (toastIdRef.current) {
|
|
1763
|
-
toast.close(toastIdRef.current);
|
|
1764
|
-
toastIdRef.current = null;
|
|
1567
|
+
if (phase === "error") {
|
|
1568
|
+
toast.add({
|
|
1569
|
+
type: "error",
|
|
1570
|
+
title: t("Download failed", { note: "toast" }),
|
|
1571
|
+
description: errorNode(error)
|
|
1572
|
+
});
|
|
1573
|
+
return;
|
|
1765
1574
|
}
|
|
1766
|
-
|
|
1767
|
-
const onInitiated = () => {
|
|
1768
|
-
if (enabled) {
|
|
1575
|
+
if (prev === "presigning" && phase === "idle" && url) {
|
|
1769
1576
|
toast.add({
|
|
1770
1577
|
type: "success",
|
|
1771
1578
|
title: t("Download started", { note: "toast" })
|
|
1772
1579
|
});
|
|
1773
1580
|
}
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1581
|
+
}, [
|
|
1582
|
+
enabled,
|
|
1583
|
+
fetchMode,
|
|
1584
|
+
phase,
|
|
1585
|
+
error,
|
|
1586
|
+
url,
|
|
1587
|
+
resolvedFileName,
|
|
1588
|
+
displayName,
|
|
1589
|
+
fileSize,
|
|
1590
|
+
activeKey,
|
|
1591
|
+
objectKey,
|
|
1592
|
+
t,
|
|
1593
|
+
formatDimahError
|
|
1594
|
+
]);
|
|
1595
|
+
useEffect(() => {
|
|
1596
|
+
if (!enabled || activeKey !== objectKey || phase !== "downloading" || !progress) {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
if (!toastIdRef.current) return;
|
|
1791
1600
|
toast.update(toastIdRef.current, {
|
|
1792
1601
|
type: "loading",
|
|
1793
1602
|
timeout: 0,
|
|
@@ -1801,61 +1610,39 @@ function useDownloadToast({
|
|
|
1801
1610
|
onClick: () => cancelRef.current?.()
|
|
1802
1611
|
}
|
|
1803
1612
|
});
|
|
1804
|
-
};
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
title: t("Download failed", { note: "toast" }),
|
|
1835
|
-
description: errorNode(error)
|
|
1836
|
-
});
|
|
1837
|
-
};
|
|
1838
|
-
const onCancel = (_key) => {
|
|
1839
|
-
if (!enabled) return;
|
|
1840
|
-
closeLoading();
|
|
1841
|
-
toast.add({
|
|
1842
|
-
type: "info",
|
|
1843
|
-
title: t("Download cancelled", { note: "toast" }),
|
|
1844
|
-
description: /* @__PURE__ */ jsx("span", { dir: "auto", children: truncateFileName(displayName) })
|
|
1845
|
-
});
|
|
1846
|
-
};
|
|
1847
|
-
return {
|
|
1848
|
-
onInitiated,
|
|
1849
|
-
onDownloadStart,
|
|
1850
|
-
onProgress,
|
|
1851
|
-
onSuccess,
|
|
1852
|
-
onError,
|
|
1853
|
-
onCancel
|
|
1854
|
-
};
|
|
1613
|
+
}, [enabled, phase, progress, t, activeKey, objectKey]);
|
|
1614
|
+
}
|
|
1615
|
+
function useDownloadUi(download, {
|
|
1616
|
+
toast: enableToast = true,
|
|
1617
|
+
objectKey,
|
|
1618
|
+
fileName,
|
|
1619
|
+
fileSize,
|
|
1620
|
+
attachmentSize,
|
|
1621
|
+
attachmentOrientation
|
|
1622
|
+
}) {
|
|
1623
|
+
useDownloadToast(download, {
|
|
1624
|
+
enabled: enableToast,
|
|
1625
|
+
objectKey,
|
|
1626
|
+
fileName,
|
|
1627
|
+
fileSize
|
|
1628
|
+
});
|
|
1629
|
+
const t = useTranslations();
|
|
1630
|
+
const formatError = useFormatDimahError();
|
|
1631
|
+
const isThis = download.objectKey === objectKey;
|
|
1632
|
+
const statusNode = !isThis || download.phase !== "error" ? null : /* @__PURE__ */ jsx(
|
|
1633
|
+
StatusAttachment,
|
|
1634
|
+
{
|
|
1635
|
+
state: "error",
|
|
1636
|
+
title: t("Download failed", { note: "status" }),
|
|
1637
|
+
description: download.error ? formatError(download.error) : void 0,
|
|
1638
|
+
size: attachmentSize,
|
|
1639
|
+
orientation: attachmentOrientation
|
|
1640
|
+
}
|
|
1641
|
+
);
|
|
1642
|
+
return { statusNode };
|
|
1855
1643
|
}
|
|
1856
1644
|
function DownloadButton({
|
|
1857
|
-
|
|
1858
|
-
route,
|
|
1645
|
+
download,
|
|
1859
1646
|
objectKey,
|
|
1860
1647
|
fileName,
|
|
1861
1648
|
label,
|
|
@@ -1869,34 +1656,21 @@ function DownloadButton({
|
|
|
1869
1656
|
size = "default",
|
|
1870
1657
|
buttonClassName,
|
|
1871
1658
|
attachmentSize,
|
|
1872
|
-
attachmentOrientation
|
|
1873
|
-
beforeDownload,
|
|
1874
|
-
onInitiated,
|
|
1875
|
-
onError
|
|
1659
|
+
attachmentOrientation
|
|
1876
1660
|
}) {
|
|
1877
1661
|
const t = useTranslations();
|
|
1878
|
-
const
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1662
|
+
const isThis = download.objectKey === objectKey;
|
|
1663
|
+
const isPendingThis = download.isPending && isThis;
|
|
1664
|
+
const isDisabled = Boolean(disabled) || isPendingThis;
|
|
1665
|
+
const { statusNode } = useDownloadUi(download, {
|
|
1666
|
+
toast: enableToast,
|
|
1881
1667
|
objectKey,
|
|
1882
|
-
fileName
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
api,
|
|
1886
|
-
route,
|
|
1887
|
-
beforeDownload,
|
|
1888
|
-
onInitiated: (key) => {
|
|
1889
|
-
toastHandlers.onInitiated();
|
|
1890
|
-
onInitiated?.(key);
|
|
1891
|
-
},
|
|
1892
|
-
onError: (key, error) => {
|
|
1893
|
-
toastHandlers.onError(key, error);
|
|
1894
|
-
onError?.(key, error);
|
|
1895
|
-
}
|
|
1668
|
+
fileName,
|
|
1669
|
+
attachmentSize,
|
|
1670
|
+
attachmentOrientation
|
|
1896
1671
|
});
|
|
1897
|
-
const isPending = dl.phase === "presigning";
|
|
1898
1672
|
const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1899
|
-
|
|
1673
|
+
isPendingThis ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin", "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(DownloadIcon, { "data-icon": "inline-start" }),
|
|
1900
1674
|
label ?? t("Download", { note: "button" })
|
|
1901
1675
|
] });
|
|
1902
1676
|
const button = /* @__PURE__ */ jsx(
|
|
@@ -1905,21 +1679,11 @@ function DownloadButton({
|
|
|
1905
1679
|
variant,
|
|
1906
1680
|
size,
|
|
1907
1681
|
className: buttonClassName,
|
|
1908
|
-
disabled:
|
|
1909
|
-
onClick: () =>
|
|
1682
|
+
disabled: isDisabled,
|
|
1683
|
+
onClick: () => download.download(objectKey, fileName),
|
|
1910
1684
|
children: buttonContent
|
|
1911
1685
|
}
|
|
1912
1686
|
);
|
|
1913
|
-
const statusNode = dl.phase === "error" ? /* @__PURE__ */ jsx(
|
|
1914
|
-
StatusAttachment,
|
|
1915
|
-
{
|
|
1916
|
-
state: "error",
|
|
1917
|
-
title: t("Download failed", { note: "status" }),
|
|
1918
|
-
description: dl.error ? formatError(dl.error) : void 0,
|
|
1919
|
-
size: attachmentSize,
|
|
1920
|
-
orientation: attachmentOrientation
|
|
1921
|
-
}
|
|
1922
|
-
) : null;
|
|
1923
1687
|
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
|
|
1924
1688
|
tooltipText ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
1925
1689
|
/* @__PURE__ */ jsx(TooltipTrigger, { render: button }),
|
|
@@ -1929,8 +1693,7 @@ function DownloadButton({
|
|
|
1929
1693
|
] });
|
|
1930
1694
|
}
|
|
1931
1695
|
function ProgressDownloadButton({
|
|
1932
|
-
|
|
1933
|
-
route,
|
|
1696
|
+
download,
|
|
1934
1697
|
objectKey,
|
|
1935
1698
|
fileName,
|
|
1936
1699
|
fileSize,
|
|
@@ -1947,78 +1710,33 @@ function ProgressDownloadButton({
|
|
|
1947
1710
|
size = "default",
|
|
1948
1711
|
buttonClassName,
|
|
1949
1712
|
attachmentSize,
|
|
1950
|
-
attachmentOrientation
|
|
1951
|
-
beforeDownload,
|
|
1952
|
-
onDownloadStart,
|
|
1953
|
-
onProgress,
|
|
1954
|
-
onSuccess,
|
|
1955
|
-
onError,
|
|
1956
|
-
onCancel
|
|
1713
|
+
attachmentOrientation
|
|
1957
1714
|
}) {
|
|
1958
1715
|
const t = useTranslations();
|
|
1959
|
-
const
|
|
1960
|
-
const
|
|
1961
|
-
const
|
|
1962
|
-
|
|
1716
|
+
const isThis = download.objectKey === objectKey;
|
|
1717
|
+
const isPendingThis = download.isPending && isThis;
|
|
1718
|
+
const { statusNode } = useDownloadUi(download, {
|
|
1719
|
+
toast: enableToast,
|
|
1963
1720
|
objectKey,
|
|
1964
1721
|
fileName,
|
|
1965
1722
|
fileSize,
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
const dl = useDownload({
|
|
1969
|
-
mode: "fetch",
|
|
1970
|
-
api,
|
|
1971
|
-
route,
|
|
1972
|
-
beforeDownload,
|
|
1973
|
-
onDownloadStart: (key) => {
|
|
1974
|
-
toastHandlers.onDownloadStart();
|
|
1975
|
-
onDownloadStart?.(key);
|
|
1976
|
-
},
|
|
1977
|
-
onProgress: (key, progress) => {
|
|
1978
|
-
toastHandlers.onProgress(key, progress);
|
|
1979
|
-
onProgress?.(key, progress);
|
|
1980
|
-
},
|
|
1981
|
-
onSuccess: (key, actualFileName) => {
|
|
1982
|
-
toastHandlers.onSuccess(key, actualFileName);
|
|
1983
|
-
onSuccess?.(key, actualFileName);
|
|
1984
|
-
},
|
|
1985
|
-
onError: (key, error, phase) => {
|
|
1986
|
-
toastHandlers.onError(key, error, phase);
|
|
1987
|
-
onError?.(key, error, phase);
|
|
1988
|
-
},
|
|
1989
|
-
onCancel: (key) => {
|
|
1990
|
-
toastHandlers.onCancel(key);
|
|
1991
|
-
onCancel?.(key);
|
|
1992
|
-
}
|
|
1993
|
-
});
|
|
1994
|
-
useLayoutEffect(() => {
|
|
1995
|
-
dlRef.current = dl;
|
|
1723
|
+
attachmentSize,
|
|
1724
|
+
attachmentOrientation
|
|
1996
1725
|
});
|
|
1997
|
-
const isDownloading = dl.phase === "downloading" || dl.phase === "presigning";
|
|
1998
1726
|
const handleClick = () => {
|
|
1999
|
-
if (
|
|
2000
|
-
|
|
1727
|
+
if (isPendingThis) {
|
|
1728
|
+
download.cancel();
|
|
2001
1729
|
return;
|
|
2002
1730
|
}
|
|
2003
|
-
|
|
1731
|
+
download.download(objectKey, fileName);
|
|
2004
1732
|
};
|
|
2005
|
-
const computedPercentFromFileSize = fileSize && fileSize > 0 ? Math.min(100, Math.round(
|
|
2006
|
-
const fillPercent =
|
|
2007
|
-
const isIndeterminateFill =
|
|
1733
|
+
const computedPercentFromFileSize = fileSize && fileSize > 0 ? Math.min(100, Math.round(download.progress.loaded / fileSize * 100)) : null;
|
|
1734
|
+
const fillPercent = !isPendingThis ? null : download.phase === "presigning" ? 12 : download.progress.total > 0 ? download.progress.percent : computedPercentFromFileSize;
|
|
1735
|
+
const isIndeterminateFill = isPendingThis && fillPercent == null;
|
|
2008
1736
|
const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2009
|
-
!
|
|
2010
|
-
|
|
1737
|
+
!isPendingThis && /* @__PURE__ */ jsx(DownloadIcon, { "data-icon": "inline-start" }),
|
|
1738
|
+
isPendingThis ? formatFileSize(download.progress.loaded) : label ?? t("Download", { note: "button" })
|
|
2011
1739
|
] });
|
|
2012
|
-
const statusNode = dl.phase === "error" ? /* @__PURE__ */ jsx(
|
|
2013
|
-
StatusAttachment,
|
|
2014
|
-
{
|
|
2015
|
-
state: "error",
|
|
2016
|
-
title: t("Download failed", { note: "status" }),
|
|
2017
|
-
description: dl.error ? formatError(dl.error) : void 0,
|
|
2018
|
-
size: attachmentSize,
|
|
2019
|
-
orientation: attachmentOrientation
|
|
2020
|
-
}
|
|
2021
|
-
) : null;
|
|
2022
1740
|
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col items-center gap-2", className), children: [
|
|
2023
1741
|
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
2024
1742
|
/* @__PURE__ */ jsxs(
|
|
@@ -2038,7 +1756,7 @@ function ProgressDownloadButton({
|
|
|
2038
1756
|
}
|
|
2039
1757
|
),
|
|
2040
1758
|
children: [
|
|
2041
|
-
|
|
1759
|
+
isPendingThis && /* @__PURE__ */ jsx(
|
|
2042
1760
|
"span",
|
|
2043
1761
|
{
|
|
2044
1762
|
className: cn(
|
|
@@ -2054,7 +1772,7 @@ function ProgressDownloadButton({
|
|
|
2054
1772
|
]
|
|
2055
1773
|
}
|
|
2056
1774
|
),
|
|
2057
|
-
/* @__PURE__ */ jsx(TooltipContent, { children:
|
|
1775
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: isPendingThis ? cancelTooltipText ?? t("Cancel download", { note: "tooltip" }) : tooltipText ?? t("Download file", { note: "tooltip" }) })
|
|
2058
1776
|
] }),
|
|
2059
1777
|
resolveStatusSlot(statusSlot, statusNode)
|
|
2060
1778
|
] });
|
|
@@ -2214,36 +1932,81 @@ function AlertDialogCancel({
|
|
|
2214
1932
|
}
|
|
2215
1933
|
);
|
|
2216
1934
|
}
|
|
2217
|
-
function useDeleteToast({
|
|
2218
|
-
enabled = true,
|
|
2219
|
-
displayName
|
|
2220
|
-
}) {
|
|
1935
|
+
function useDeleteToast(del, { enabled = true, objectKey, displayName }) {
|
|
2221
1936
|
const t = useTranslations();
|
|
2222
1937
|
const formatDimahError = useFormatDimahError();
|
|
2223
|
-
const
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
1938
|
+
const prevPhaseRef = useRef(del.phase);
|
|
1939
|
+
useEffect(() => {
|
|
1940
|
+
if (prevPhaseRef.current === del.phase) return;
|
|
1941
|
+
prevPhaseRef.current = del.phase;
|
|
1942
|
+
if (!enabled || del.objectKey !== objectKey) return;
|
|
1943
|
+
if (del.phase === "success") {
|
|
1944
|
+
toast.add({
|
|
1945
|
+
type: "success",
|
|
1946
|
+
title: t("File deleted", { note: "toast" }),
|
|
1947
|
+
description: /* @__PURE__ */ jsx("span", { dir: "auto", children: truncateFileName(displayName) })
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
if (del.phase === "error") {
|
|
1951
|
+
toast.add({
|
|
1952
|
+
type: "error",
|
|
1953
|
+
title: t("Delete failed", { note: "toast" }),
|
|
1954
|
+
description: /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: formatDimahError(del.error) })
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
}, [
|
|
1958
|
+
enabled,
|
|
1959
|
+
del.phase,
|
|
1960
|
+
del.error,
|
|
1961
|
+
del.objectKey,
|
|
1962
|
+
objectKey,
|
|
1963
|
+
displayName,
|
|
1964
|
+
t,
|
|
1965
|
+
formatDimahError
|
|
1966
|
+
]);
|
|
1967
|
+
}
|
|
1968
|
+
function useDeleteUi(del, {
|
|
1969
|
+
toast: enableToast = true,
|
|
1970
|
+
objectKey,
|
|
1971
|
+
displayName,
|
|
1972
|
+
attachmentSize,
|
|
1973
|
+
attachmentOrientation
|
|
1974
|
+
}) {
|
|
1975
|
+
useDeleteToast(del, { enabled: enableToast, objectKey, displayName });
|
|
1976
|
+
const t = useTranslations();
|
|
1977
|
+
const formatError = useFormatDimahError();
|
|
1978
|
+
const isThis = del.objectKey === objectKey;
|
|
1979
|
+
if (!isThis) {
|
|
1980
|
+
return { statusNode: null };
|
|
1981
|
+
}
|
|
1982
|
+
const statusNode = del.phase === "success" ? /* @__PURE__ */ jsx(
|
|
1983
|
+
StatusAttachment,
|
|
1984
|
+
{
|
|
1985
|
+
state: "done",
|
|
1986
|
+
title: t('"{name}" deleted', {
|
|
1987
|
+
note: "status",
|
|
1988
|
+
variables: { name: truncateFileName(displayName) }
|
|
1989
|
+
}),
|
|
1990
|
+
size: attachmentSize,
|
|
1991
|
+
orientation: attachmentOrientation
|
|
1992
|
+
}
|
|
1993
|
+
) : del.phase === "error" ? /* @__PURE__ */ jsx(
|
|
1994
|
+
StatusAttachment,
|
|
1995
|
+
{
|
|
1996
|
+
state: "error",
|
|
1997
|
+
title: t("Delete failed", { note: "status" }),
|
|
1998
|
+
description: del.error ? formatError(del.error) : void 0,
|
|
1999
|
+
size: attachmentSize,
|
|
2000
|
+
orientation: attachmentOrientation
|
|
2001
|
+
}
|
|
2002
|
+
) : null;
|
|
2003
|
+
return { statusNode };
|
|
2240
2004
|
}
|
|
2241
2005
|
function isolateLtr(value) {
|
|
2242
2006
|
return `\u2066${value}\u2069`;
|
|
2243
2007
|
}
|
|
2244
2008
|
function DeleteButton({
|
|
2245
|
-
|
|
2246
|
-
route,
|
|
2009
|
+
delete: del,
|
|
2247
2010
|
objectKey,
|
|
2248
2011
|
fileName,
|
|
2249
2012
|
fileSize,
|
|
@@ -2260,37 +2023,22 @@ function DeleteButton({
|
|
|
2260
2023
|
size = "default",
|
|
2261
2024
|
buttonClassName,
|
|
2262
2025
|
attachmentSize,
|
|
2263
|
-
attachmentOrientation
|
|
2264
|
-
beforeDelete,
|
|
2265
|
-
onDeleteStart,
|
|
2266
|
-
onSuccess,
|
|
2267
|
-
onError
|
|
2026
|
+
attachmentOrientation
|
|
2268
2027
|
}) {
|
|
2269
2028
|
const t = useTranslations();
|
|
2270
|
-
const formatError = useFormatDimahError();
|
|
2271
2029
|
const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
onSuccess: (key) => {
|
|
2282
|
-
toastHandlers.onSuccess(key);
|
|
2283
|
-
onSuccess?.(key);
|
|
2284
|
-
},
|
|
2285
|
-
onError: (key, error, phase) => {
|
|
2286
|
-
toastHandlers.onError(key, error);
|
|
2287
|
-
onError?.(key, error, phase);
|
|
2288
|
-
}
|
|
2030
|
+
const isThis = del.objectKey === objectKey;
|
|
2031
|
+
const isDeletingThis = del.isDeleting && isThis;
|
|
2032
|
+
const isDisabled = Boolean(disabled) || del.isDeleting;
|
|
2033
|
+
const { statusNode } = useDeleteUi(del, {
|
|
2034
|
+
toast: enableToast,
|
|
2035
|
+
objectKey,
|
|
2036
|
+
displayName,
|
|
2037
|
+
attachmentSize,
|
|
2038
|
+
attachmentOrientation
|
|
2289
2039
|
});
|
|
2290
|
-
const isDeleting = del.phase === "deleting";
|
|
2291
|
-
const isDisabled = disabled || isDeleting;
|
|
2292
2040
|
const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2293
|
-
|
|
2041
|
+
isDeletingThis ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin", "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(Trash2Icon, { "data-icon": "inline-start" }),
|
|
2294
2042
|
label ?? t("Delete", { note: "button" })
|
|
2295
2043
|
] });
|
|
2296
2044
|
const fileLabel = fileSize != null ? `${truncateFileName(displayName)} (${formatFileSize(fileSize)})` : truncateFileName(displayName);
|
|
@@ -2301,32 +2049,11 @@ function DeleteButton({
|
|
|
2301
2049
|
variables: { name: isolateLtr(fileLabel) }
|
|
2302
2050
|
}
|
|
2303
2051
|
);
|
|
2304
|
-
const statusNode = del.phase === "success" ? /* @__PURE__ */ jsx(
|
|
2305
|
-
StatusAttachment,
|
|
2306
|
-
{
|
|
2307
|
-
state: "done",
|
|
2308
|
-
title: t('"{name}" deleted', {
|
|
2309
|
-
note: "status",
|
|
2310
|
-
variables: { name: truncateFileName(displayName) }
|
|
2311
|
-
}),
|
|
2312
|
-
size: attachmentSize,
|
|
2313
|
-
orientation: attachmentOrientation
|
|
2314
|
-
}
|
|
2315
|
-
) : del.phase === "error" ? /* @__PURE__ */ jsx(
|
|
2316
|
-
StatusAttachment,
|
|
2317
|
-
{
|
|
2318
|
-
state: "error",
|
|
2319
|
-
title: t("Delete failed", { note: "status" }),
|
|
2320
|
-
description: del.error ? formatError(del.error) : void 0,
|
|
2321
|
-
size: attachmentSize,
|
|
2322
|
-
orientation: attachmentOrientation
|
|
2323
|
-
}
|
|
2324
|
-
) : null;
|
|
2325
2052
|
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
|
|
2326
2053
|
/* @__PURE__ */ jsx("div", { className: "inline-flex items-center gap-2", children: /* @__PURE__ */ jsxs(
|
|
2327
2054
|
AlertDialog,
|
|
2328
2055
|
{
|
|
2329
|
-
open: del.
|
|
2056
|
+
open: del.isConfirming && isThis,
|
|
2330
2057
|
onOpenChange: (open) => {
|
|
2331
2058
|
if (!open) del.cancelDelete();
|
|
2332
2059
|
},
|
|
@@ -2388,6 +2115,6 @@ function DeleteButton({
|
|
|
2388
2115
|
] });
|
|
2389
2116
|
}
|
|
2390
2117
|
|
|
2391
|
-
export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone,
|
|
2118
|
+
export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone, UploadFileStatus, UploadStatus, resolveStatusSlot, toast, useDeleteToast, useDeleteUi, useDownloadToast, useDownloadUi, useFileRejectToast, useUploadToast, useUploadUi };
|
|
2392
2119
|
//# sourceMappingURL=index.js.map
|
|
2393
2120
|
//# sourceMappingURL=index.js.map
|