@widgetic/file-browser 0.5.34 → 0.5.36
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 -0
- package/dist/components/FolderTree.svelte +46 -97
- package/dist/components/FolderTree.svelte.d.ts +7 -7
- package/dist/components/core/Dropzone.svelte +127 -0
- package/dist/components/core/Dropzone.svelte.d.ts +15 -0
- package/dist/components/core/FileBrowser.css +11 -79
- package/dist/components/core/FileBrowser.svelte +278 -150
- package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
- package/dist/components/core/FileUploader.svelte +204 -418
- package/dist/components/core/FileUploader.svelte.d.ts +1 -0
- package/dist/components/core/Header.svelte +49 -58
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +135 -562
- package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
- package/dist/components/core/UploadPanel.svelte +169 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
- package/dist/components/core/UploadRow.svelte +90 -0
- package/dist/components/core/UploadRow.svelte.d.ts +21 -0
- package/dist/components/core/UploadStatus.svelte +34 -128
- package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
- package/dist/components/core/UploadStatusList.svelte +61 -77
- package/dist/components/items/FileItem.svelte +190 -532
- package/dist/components/items/FileItem.svelte.d.ts +1 -1
- package/dist/components/items/FolderItem.svelte +46 -36
- package/dist/components/items/FolderItem.svelte.d.ts +1 -1
- package/dist/components/modals/MoveDialog.svelte +142 -281
- package/dist/components/modals/NewFolderButton.svelte +13 -14
- package/dist/components/modals/SearchModal.svelte +112 -264
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
- package/dist/components/modals/SelectedFilesModal.svelte +91 -167
- package/dist/components/previews/AudioPlayer.svelte +75 -58
- package/dist/components/previews/ErrorPreview.svelte +9 -6
- package/dist/components/previews/FilePreview.svelte +182 -53
- package/dist/components/previews/FontPreview.svelte +37 -54
- package/dist/components/previews/ImagePreview.svelte +9 -2
- package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
- package/dist/components/previews/TextPreview.svelte +32 -40
- package/dist/components/previews/VideoPlayer.svelte +124 -149
- package/dist/components/previews/WaveformVisualizer.svelte +42 -222
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
- package/dist/components/ui/ControlToolbar.svelte +113 -288
- package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
- package/dist/components/ui/DragSelect.svelte +41 -248
- package/dist/components/ui/DropdownMenu.svelte +56 -55
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/components/ui/FileIcon.svelte +168 -51
- package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
- package/dist/components/ui/FileMetadata.svelte +20 -9
- package/dist/components/ui/LoadingSkeleton.svelte +5 -20
- package/dist/components/ui/SearchResults.svelte +50 -26
- package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
- package/dist/components/ui/SelectedBadge.svelte +25 -0
- package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TileSkeleton.svelte +15 -0
- package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
- package/dist/components/ui/VirtualList.svelte +3 -0
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/i18n/messages.d.ts +40 -27
- package/dist/i18n/messages.js +41 -28
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/utils/gridLayout.d.ts +2 -0
- package/dist/utils/gridLayout.js +10 -0
- package/package.json +3 -4
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
const dispatch = createEventDispatcher();
|
|
7
7
|
|
|
8
8
|
// Design system imports
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
9
|
+
import { Portal } from '@widgetic/design-system/components';
|
|
10
|
+
import Dropzone from './Dropzone.svelte';
|
|
11
|
+
import UploadPanel, { type UploadPanelItem } from './UploadPanel.svelte';
|
|
12
|
+
import type { UploadRowScope, UploadRowState } from './UploadRow.svelte';
|
|
13
|
+
import type { DropzoneState } from './Dropzone.svelte';
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
// Import toast utility
|
|
@@ -25,14 +28,13 @@
|
|
|
25
28
|
import { get } from 'svelte/store';
|
|
26
29
|
import { fileBrowserUploadConfig } from '../../stores/uploadApiStore';
|
|
27
30
|
import { uploadToWidgeticApi } from '../../utils/widgeticUpload';
|
|
28
|
-
import { getAssetUrl } from '../../utils/fileUtils';
|
|
29
31
|
import { useMediaLibraryContext } from '../../mediaLibrary/context';
|
|
30
32
|
import { MediaLibraryError, isCancellation, toMediaLibraryError } from '../../mediaLibrary/errors';
|
|
31
33
|
import { useI18n } from '../../i18n/context';
|
|
32
|
-
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
33
34
|
import { messageForVisitor } from '../../i18n/errors';
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
35
|
+
import { formatFileSize } from '../../utils/fileUtils';
|
|
36
|
+
import { UPLOAD_ERROR_KEYS } from '../../i18n/messages';
|
|
37
|
+
import { kindWord } from '../../i18n/text';
|
|
36
38
|
import type { Translate } from '../../i18n/context';
|
|
37
39
|
import { translateEnglish } from '../../i18n/context';
|
|
38
40
|
|
|
@@ -42,9 +44,6 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
42
44
|
// The language of the File Browser this uploader is part of.
|
|
43
45
|
const { t, locale } = useI18n();
|
|
44
46
|
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
45
|
-
const textDirection = useTextDirection();
|
|
46
|
-
$: nameDirection = dirForUserText($textDirection);
|
|
47
|
-
|
|
48
47
|
// Component props variables
|
|
49
48
|
export let allowedTypes: string[] = [];
|
|
50
49
|
export let currentPath: string[] = [];
|
|
@@ -56,26 +55,24 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
56
55
|
export let isDraggingFolder = false;
|
|
57
56
|
export let currentFolderId: string = '';
|
|
58
57
|
export let portalTarget: HTMLElement | null = null; // Reference to parent element
|
|
58
|
+
/** Compact dropzone and panel placement. Left out, it follows the window width (768px or less). */
|
|
59
|
+
export let compact: boolean | undefined = undefined;
|
|
59
60
|
|
|
60
61
|
// Local variables
|
|
61
62
|
let uploading = false;
|
|
62
63
|
let fileInput: HTMLInputElement;
|
|
63
64
|
let uploaderRootEl: HTMLDivElement;
|
|
64
|
-
let mouseX = 0;
|
|
65
|
-
let mouseY = 0;
|
|
66
|
-
// tooltip vars
|
|
67
|
-
let showHelp = false;
|
|
68
|
-
let showCollapseTooltip = false;
|
|
69
|
-
let showCloseTooltip = false;
|
|
70
65
|
// show logs
|
|
71
66
|
let showLogs = false;
|
|
72
67
|
|
|
73
68
|
// Responsive state
|
|
74
69
|
let isSmallScreen = browser ? window.innerWidth <= 768 : false;
|
|
70
|
+
$: isCompactUploader = compact ?? isSmallScreen;
|
|
75
71
|
|
|
76
72
|
// Panel state
|
|
77
73
|
let isUploadsModalOpen = false;
|
|
78
|
-
|
|
74
|
+
// The list of a batch's files is closed until it is opened (Figma: the panel is one row, a bar and a line of text)
|
|
75
|
+
let isUploadsDrawerCollapsed = true;
|
|
79
76
|
|
|
80
77
|
// Upload tracking
|
|
81
78
|
type UploadItem = {
|
|
@@ -100,10 +97,131 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
100
97
|
: FILE_TYPES[filter as Exclude<FileFilterType, 'all'>].join(',');
|
|
101
98
|
// The kinds of file the uploader takes, as words in the visitor's language: "image, video", "any", "document".
|
|
102
99
|
$: allowedTypesDisplayText = kindsText(filter, allowedKinds, $t);
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
// With the "all" filter every kind of file is taken, and the sentences of the dropzone do not name a kind ("Upload files").
|
|
101
|
+
$: acceptsAnyKind = filter === 'all';
|
|
105
102
|
// Calculate overall progress for all uploads
|
|
106
103
|
$: overallProgress = calculateOverallProgress(uploadItems);
|
|
104
|
+
|
|
105
|
+
$: dropzoneState = (
|
|
106
|
+
dragActive && dragInvalid
|
|
107
|
+
? 'drag-invalid'
|
|
108
|
+
: dragActive && hasValidFiles
|
|
109
|
+
? 'drag-valid'
|
|
110
|
+
: 'idle'
|
|
111
|
+
) satisfies DropzoneState;
|
|
112
|
+
|
|
113
|
+
$: completedUploadCount = uploadItems.filter((item) => item.status === 'complete').length;
|
|
114
|
+
$: failedUploadCount = uploadItems.filter((item) => item.status === 'failed').length;
|
|
115
|
+
$: activeUploadCount = uploadItems.filter((item) => item.status === 'uploading').length;
|
|
116
|
+
$: totalUploadCount = uploadItems.length;
|
|
117
|
+
$: isBatchUpload = totalUploadCount > 1;
|
|
118
|
+
|
|
119
|
+
function joinMeta(left: string, right: string): string {
|
|
120
|
+
return $t('upload.rowMeta', { size: left, detail: right });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Literal catalog keys for the i18n usage audit (`UPLOAD_ERROR_KEYS` lives in `messages.ts`). */
|
|
124
|
+
const uploadErrorKeyLiterals = ['libraryError.uploadFailed', 'upload.networkError', 'action.preview'] as const;
|
|
125
|
+
void uploadErrorKeyLiterals;
|
|
126
|
+
|
|
127
|
+
function statusTextForItem(item: UploadItem): string {
|
|
128
|
+
if (item.status === 'complete') return $t('upload.complete');
|
|
129
|
+
if (item.status === 'failed') return item.errorMessage || $t('upload.failed');
|
|
130
|
+
const size = formatFileSize(item.file.size, $t, $locale);
|
|
131
|
+
if (item.timeRemaining) {
|
|
132
|
+
return $t('upload.rowMeta', {
|
|
133
|
+
size,
|
|
134
|
+
detail: $t('upload.timeLeft', { time: item.timeRemaining })
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return size;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function fileThumbForItem(item: UploadItem) {
|
|
141
|
+
return {
|
|
142
|
+
name: item.file.name,
|
|
143
|
+
url: item.previewUrl || undefined,
|
|
144
|
+
mimeType: item.file.type
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
$: panelItems = uploadItems.map(
|
|
149
|
+
(item): UploadPanelItem => ({
|
|
150
|
+
id: item.id,
|
|
151
|
+
fileName: item.file.name,
|
|
152
|
+
file: fileThumbForItem(item),
|
|
153
|
+
progress: item.progress,
|
|
154
|
+
status: item.status,
|
|
155
|
+
statusText: statusTextForItem(item),
|
|
156
|
+
errorMessage: item.errorMessage
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
$: panelSummaryScope = (isBatchUpload ? 'batch' : 'single') satisfies UploadRowScope;
|
|
161
|
+
$: panelSummaryState = (
|
|
162
|
+
activeUploadCount > 0
|
|
163
|
+
? 'uploading'
|
|
164
|
+
: failedUploadCount === totalUploadCount
|
|
165
|
+
? 'failed'
|
|
166
|
+
: completedUploadCount === totalUploadCount
|
|
167
|
+
? 'complete'
|
|
168
|
+
: failedUploadCount > 0
|
|
169
|
+
? 'failed'
|
|
170
|
+
: 'uploading'
|
|
171
|
+
) satisfies UploadRowState;
|
|
172
|
+
|
|
173
|
+
$: panelSummaryName = isBatchUpload ? '' : uploadItems[0]?.file.name ?? '';
|
|
174
|
+
|
|
175
|
+
$: panelSummaryStatus = isBatchUpload
|
|
176
|
+
? failedUploadCount > 0 && activeUploadCount === 0
|
|
177
|
+
? joinMeta(
|
|
178
|
+
$t('upload.progress', { done: completedUploadCount, total: totalUploadCount }),
|
|
179
|
+
$t('upload.failedCount', { count: failedUploadCount })
|
|
180
|
+
)
|
|
181
|
+
: $t('upload.progress', { done: completedUploadCount, total: totalUploadCount })
|
|
182
|
+
: uploadItems[0]
|
|
183
|
+
? statusTextForItem(uploadItems[0])
|
|
184
|
+
: '';
|
|
185
|
+
|
|
186
|
+
$: panelProgressTone = (failedUploadCount > 0 ? 'destructive' : 'default') as 'default' | 'destructive';
|
|
187
|
+
$: panelProgressDone = completedUploadCount === totalUploadCount && failedUploadCount === 0;
|
|
188
|
+
|
|
189
|
+
$: panelFooterDestructive = failedUploadCount > 0;
|
|
190
|
+
$: panelFooterAction =
|
|
191
|
+
failedUploadCount > 0 && activeUploadCount === 0 && completedUploadCount < totalUploadCount;
|
|
192
|
+
|
|
193
|
+
$: panelFooterText = (() => {
|
|
194
|
+
if (totalUploadCount === 0) return $t('upload.uploading');
|
|
195
|
+
if (panelFooterAction) return $t('upload.retryFailed');
|
|
196
|
+
if (totalUploadCount === 1 && activeUploadCount === 1) return $t('upload.uploading');
|
|
197
|
+
if (totalUploadCount === 1 && failedUploadCount === 1) return $t('upload.retry');
|
|
198
|
+
if (totalUploadCount === 1 && completedUploadCount === 1) return $t('upload.complete');
|
|
199
|
+
if (activeUploadCount > 0 && failedUploadCount > 0) {
|
|
200
|
+
return joinMeta(
|
|
201
|
+
$t('upload.uploadingProgress', {
|
|
202
|
+
done: completedUploadCount + activeUploadCount,
|
|
203
|
+
total: totalUploadCount
|
|
204
|
+
}),
|
|
205
|
+
$t('upload.failedCount', { count: failedUploadCount })
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (activeUploadCount > 0) {
|
|
209
|
+
return $t('upload.uploadingProgress', {
|
|
210
|
+
done: completedUploadCount + activeUploadCount,
|
|
211
|
+
total: totalUploadCount
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (failedUploadCount > 0 && completedUploadCount > 0) {
|
|
215
|
+
return joinMeta(
|
|
216
|
+
$t('upload.completeCount', { done: completedUploadCount, total: totalUploadCount }),
|
|
217
|
+
$t('upload.failedCount', { count: failedUploadCount })
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
if (completedUploadCount === totalUploadCount) {
|
|
221
|
+
return $t('upload.completeCount', { done: completedUploadCount, total: totalUploadCount });
|
|
222
|
+
}
|
|
223
|
+
return $t('upload.uploading');
|
|
224
|
+
})();
|
|
107
225
|
|
|
108
226
|
/* Reactive statements to handle uploads drawer state
|
|
109
227
|
$: {
|
|
@@ -567,7 +685,11 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
567
685
|
...item,
|
|
568
686
|
status: 'failed',
|
|
569
687
|
progress: 0,
|
|
570
|
-
errorMessage: messageForVisitor(
|
|
688
|
+
errorMessage: messageForVisitor(
|
|
689
|
+
toMediaLibraryError(error, $t(UPLOAD_ERROR_KEYS.libraryFailed), UPLOAD_ERROR_KEYS.libraryFailed),
|
|
690
|
+
$t,
|
|
691
|
+
'upload.unknownError'
|
|
692
|
+
),
|
|
571
693
|
}
|
|
572
694
|
: item
|
|
573
695
|
);
|
|
@@ -596,7 +718,6 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
596
718
|
async function handleFiles(files: FileList) {
|
|
597
719
|
// open the uploads overlay with the drawer open
|
|
598
720
|
isUploadsModalOpen = true;
|
|
599
|
-
isUploadsDrawerCollapsed = false;
|
|
600
721
|
|
|
601
722
|
// set the uploading state to true
|
|
602
723
|
uploading = true;
|
|
@@ -692,19 +813,14 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
692
813
|
}
|
|
693
814
|
}
|
|
694
815
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
mouseY = event.clientY;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
function handleMouseLeave() {
|
|
707
|
-
showHelp = false;
|
|
816
|
+
/**
|
|
817
|
+
* The remove button of a batch row: stops the files still being sent and clears the failed ones.
|
|
818
|
+
* (The files that were sent are already in the library, they have nothing left to clear.)
|
|
819
|
+
*/
|
|
820
|
+
function cancelActiveUploads() {
|
|
821
|
+
for (const item of [...uploadItems]) {
|
|
822
|
+
if (item.status === 'uploading' || item.status === 'failed') handleCancelUpload(item.id);
|
|
823
|
+
}
|
|
708
824
|
}
|
|
709
825
|
|
|
710
826
|
/** The names of the kinds of file in a list of extensions: ["image", "video"]. An extension that fits no kind stays as it is. */
|
|
@@ -780,33 +896,6 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
780
896
|
}
|
|
781
897
|
}
|
|
782
898
|
|
|
783
|
-
function handleCollapseMouseEnter(event: MouseEvent) {
|
|
784
|
-
mouseX = event.clientX;
|
|
785
|
-
mouseY = event.clientY;
|
|
786
|
-
showCollapseTooltip = true;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
function handleCollapseMouseLeave() {
|
|
790
|
-
showCollapseTooltip = false;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
function handleCloseMouseEnter(event: MouseEvent) {
|
|
794
|
-
mouseX = event.clientX;
|
|
795
|
-
mouseY = event.clientY;
|
|
796
|
-
showCloseTooltip = true;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
function handleCloseMouseLeave() {
|
|
800
|
-
showCloseTooltip = false;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// Function to handle manual close of the uploader
|
|
804
|
-
function handleManualClose() {
|
|
805
|
-
if(showLogs) console.log('Close button clicked, manually closing the uploader');
|
|
806
|
-
isUploadsModalOpen = false;
|
|
807
|
-
isUploadsDrawerCollapsed = true;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
899
|
/** After uploads finish, close the dim overlay so the file grid is usable again. */
|
|
811
900
|
function scheduleUploadDrawerDismiss() {
|
|
812
901
|
const allDone = uploadItems.every(
|
|
@@ -855,367 +944,64 @@ import { translateEnglish } from '../../i18n/context';
|
|
|
855
944
|
});
|
|
856
945
|
</script>
|
|
857
946
|
|
|
858
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
859
947
|
<div
|
|
860
|
-
class="file-uploader
|
|
948
|
+
class="file-uploader relative w-full shrink-0"
|
|
861
949
|
bind:this={uploaderRootEl}
|
|
862
950
|
>
|
|
863
|
-
|
|
864
|
-
<
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
<
|
|
887
|
-
class="
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
{:else}
|
|
916
|
-
<div class="caption text-[hsl(var(--error))]">
|
|
917
|
-
{$t('upload.invalidType', { types: allowedTypesDisplayText })}
|
|
918
|
-
</div>
|
|
919
|
-
{/if}
|
|
920
|
-
{:else if dragActive && hasValidFiles}
|
|
921
|
-
<div class="caption text-[hsl(var(--sage-green))]">
|
|
922
|
-
{$t('upload.dropActive', { types: allowedTypesDisplayText })}
|
|
923
|
-
</div>
|
|
924
|
-
{:else if isSmallScreen}
|
|
925
|
-
<!-- The sentence, with the words of it that act as the link underlined (wherever the language puts them) -->
|
|
926
|
-
{@const compactSentence = splitAround($t('upload.chooseOrDrop', { types: allowedTypesDisplayText }), $t('upload.chooseOrDropLink'))}
|
|
927
|
-
<!-- Small screen version with clickable text -->
|
|
928
|
-
<button
|
|
929
|
-
class="caption text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors"
|
|
930
|
-
onclick={() => fileInput.click()}
|
|
931
|
-
>
|
|
932
|
-
{compactSentence.before}{#if compactSentence.link}<span class="underline">{compactSentence.link}</span>{/if}{compactSentence.after}
|
|
933
|
-
</button>
|
|
934
|
-
{:else}
|
|
935
|
-
<Button
|
|
936
|
-
variant="secondary"
|
|
937
|
-
class="file-uploader-button rounded-small widgetic-radius focus:outline-none focus-visible:outline-none focus:ring-0 focus-visible:ring-0 !border-[hsl(var(--deep-forest-green))] !bg-[hsl(var(--deep-forest-green))] !text-white hover:!border-[hsl(var(--deep-forest-green))] hover:!bg-[hsl(var(--sage-green))] hover:!text-white transition-colors"
|
|
938
|
-
onclick={() => fileInput.click()}
|
|
939
|
-
>
|
|
940
|
-
{$t('upload.button', { types: allowedTypesDisplayText })}
|
|
941
|
-
</Button>
|
|
942
|
-
<div class="caption text-[hsl(var(--grey3))]">
|
|
943
|
-
{$t('upload.dragHint', { types: allowedTypesDisplayText })}
|
|
944
|
-
</div>
|
|
945
|
-
{/if}
|
|
946
|
-
</div>
|
|
947
|
-
</div>
|
|
948
|
-
|
|
949
|
-
<!-- Custom upload panel instead of Drawer -->
|
|
950
|
-
{#if isUploadsModalOpen && portalTarget}
|
|
951
|
-
<Portal target={portalTarget} class="uploads-modal widgetic-colors">
|
|
952
|
-
<!-- Simple overlay to prevent interaction when panel is open and not collapsed -->
|
|
953
|
-
{#if !isUploadsDrawerCollapsed}
|
|
954
|
-
<div
|
|
955
|
-
class="uploads-overlay-bg absolute inset-0 bg-white/55 z-[9980]"
|
|
956
|
-
onclick={() => {
|
|
957
|
-
isUploadsDrawerCollapsed = true;
|
|
958
|
-
if(showLogs) console.log('Overlay clicked, collapsing panel');
|
|
959
|
-
}}
|
|
960
|
-
aria-hidden="true"
|
|
961
|
-
></div>
|
|
962
|
-
{/if}
|
|
963
|
-
|
|
964
|
-
<!-- Uploads Drawer -->
|
|
965
|
-
<div
|
|
966
|
-
class="uploads-drawer absolute bottom-0 inset-x-0 bg-white transition-all duration-300 z-[9990] flex flex-col rounded-t-large widgetic-radius modal-shadow"
|
|
967
|
-
style="max-height: 80vh; transform: translateY({isUploadsDrawerCollapsed ? 'calc(100% - 70px)' : '0'}); border: 1px solid hsl(var(--forest-green)); border-bottom: none;"
|
|
968
|
-
>
|
|
969
|
-
<!-- Header with toggle -->
|
|
970
|
-
<div class="uploads-header flex flex-row items-center justify-between p-4">
|
|
971
|
-
<div class="uploads-header-content">
|
|
972
|
-
<h3 class="body-medium text-[hsl(var(--grey7))]">{$t('upload.panelTitle')}</h3>
|
|
973
|
-
<p class="subtext text-[hsl(var(--grey5))]">
|
|
974
|
-
{$t('upload.progress', { done: uploadItems.filter(item => item.status === 'complete').length, total: uploadItems.length })}
|
|
975
|
-
{#if uploadItems.filter(item => item.status === 'failed').length > 0}
|
|
976
|
-
<span class="ms-2 caption text-[hsl(var(--error))]">
|
|
977
|
-
{$t('upload.failedCount', { count: uploadItems.filter(item => item.status === 'failed').length })}
|
|
978
|
-
</span>
|
|
979
|
-
{/if}
|
|
980
|
-
</p>
|
|
981
|
-
</div>
|
|
982
|
-
|
|
983
|
-
<!-- Header Controls Container -->
|
|
984
|
-
<div class="uploads-header-controls">
|
|
985
|
-
<!-- Collapse/Expand button -->
|
|
986
|
-
<Tooltip.Provider>
|
|
987
|
-
<Tooltip.Root open={showCollapseTooltip}>
|
|
988
|
-
<Tooltip.Trigger class="focus:outline-none">
|
|
989
|
-
<button
|
|
990
|
-
class="collapse-button text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] p-2 rounded transition-colors"
|
|
991
|
-
onclick={toggleDrawerCollapse}
|
|
992
|
-
onmouseenter={handleCollapseMouseEnter}
|
|
993
|
-
onmousemove={handleMouseMove}
|
|
994
|
-
onmouseleave={handleCollapseMouseLeave}
|
|
995
|
-
aria-label={isUploadsDrawerCollapsed ? $t('upload.expandPanel') : $t('upload.collapsePanel')}
|
|
996
|
-
>
|
|
997
|
-
{#if isUploadsDrawerCollapsed}
|
|
998
|
-
<IconChevronUp class="h-5 w-5" />
|
|
999
|
-
{:else}
|
|
1000
|
-
<IconChevronDown class="h-5 w-5" />
|
|
1001
|
-
{/if}
|
|
1002
|
-
</button>
|
|
1003
|
-
</Tooltip.Trigger>
|
|
1004
|
-
<Tooltip.Content
|
|
1005
|
-
side={/* rtl-ok: the tooltip is put where the pointer is, by the style below */ 'left'}
|
|
1006
|
-
sideOffset={5}
|
|
1007
|
-
class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
|
|
1008
|
-
style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px; /* rtl-ok: put where the pointer is, measured from the left edge of the page */"
|
|
1009
|
-
>
|
|
1010
|
-
<p class="caption text-white">{isUploadsDrawerCollapsed ? $t('upload.expandUploader') : $t('upload.collapseUploader')}</p>
|
|
1011
|
-
</Tooltip.Content>
|
|
1012
|
-
</Tooltip.Root>
|
|
1013
|
-
</Tooltip.Provider>
|
|
1014
|
-
|
|
1015
|
-
<!-- Close Button -->
|
|
1016
|
-
<Tooltip.Provider>
|
|
1017
|
-
<Tooltip.Root open={showCloseTooltip}>
|
|
1018
|
-
<Tooltip.Trigger class="focus:outline-none">
|
|
1019
|
-
<button
|
|
1020
|
-
class="close-button text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] p-2 rounded transition-colors"
|
|
1021
|
-
onclick={handleManualClose}
|
|
1022
|
-
onmouseenter={handleCloseMouseEnter}
|
|
1023
|
-
onmousemove={handleMouseMove}
|
|
1024
|
-
onmouseleave={handleCloseMouseLeave}
|
|
1025
|
-
aria-label={$t('upload.closeUploader')}
|
|
1026
|
-
>
|
|
1027
|
-
<IconX class="h-5 w-5" />
|
|
1028
|
-
</button>
|
|
1029
|
-
</Tooltip.Trigger>
|
|
1030
|
-
<Tooltip.Content
|
|
1031
|
-
side={/* rtl-ok: the tooltip is put where the pointer is, by the style below */ 'left'}
|
|
1032
|
-
sideOffset={5}
|
|
1033
|
-
class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
|
|
1034
|
-
style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px; /* rtl-ok: put where the pointer is, measured from the left edge of the page */"
|
|
1035
|
-
>
|
|
1036
|
-
<p class="caption text-white">{$t('upload.closeUploader')}</p>
|
|
1037
|
-
</Tooltip.Content>
|
|
1038
|
-
</Tooltip.Root>
|
|
1039
|
-
</Tooltip.Provider>
|
|
1040
|
-
</div>
|
|
1041
|
-
</div>
|
|
1042
|
-
|
|
1043
|
-
<!-- Content (collapsible) -->
|
|
1044
|
-
{#if uploadItems.length > 0}
|
|
1045
|
-
<div
|
|
1046
|
-
class="uploads-drawer-content transition-all duration-300 overflow-hidden flex-grow border-t border-[hsl(var(--forest-green))]"
|
|
1047
|
-
style="max-height: {isUploadsDrawerCollapsed ? '0' : 'calc(60vh - 130px)'}; opacity: {isUploadsDrawerCollapsed ? '0' : '1'}; border-top-width: {isUploadsDrawerCollapsed ? '0' : '1px'};"
|
|
1048
|
-
>
|
|
1049
|
-
<div class="uplods-content-ct flex flex-col gap-4 p-4 overflow-y-auto" style="max-height: calc(60vh - 150px);">
|
|
1050
|
-
<!-- Overall progress bar -->
|
|
1051
|
-
<div class="uploads-overall-progress-bar w-full h-4 bg-[hsl(var(--light-green))] rounded-full overflow-hidden">
|
|
1052
|
-
<div
|
|
1053
|
-
class="progress-bar h-full bg-[hsl(var(--sage-green))]"
|
|
1054
|
-
style="width: {overallProgress}%;"
|
|
1055
|
-
></div>
|
|
1056
|
-
</div>
|
|
1057
|
-
|
|
1058
|
-
<!-- Upload items list -->
|
|
1059
|
-
<div class="uploads-items-list space-y-4 overflow-y-auto">
|
|
1060
|
-
{#each uploadItems as item (item.id)}
|
|
1061
|
-
<div class="uploads-item rounded-large p-4 flex flex-col space-y-2 {item.status === 'failed' ? 'bg-[hsl(var(--light-error))] border border-[hsl(var(--error))]' : item.status === 'complete' ? 'bg-[hsl(var(--light-green))] border border-[hsl(var(--forest-green))]' : 'border border-[hsl(var(--forest-green))]'}"
|
|
1062
|
-
>
|
|
1063
|
-
<div class="flex items-center justify-between">
|
|
1064
|
-
<div class="flex items-center gap-3 truncate">
|
|
1065
|
-
{#if item.previewUrl}
|
|
1066
|
-
<img src={item.previewUrl} alt={$t('action.preview')} class="w-[62px] h-[54px] object-cover rounded-large" />
|
|
1067
|
-
{:else}
|
|
1068
|
-
<div class="w-[62px] h-[54px] bg-[hsl(var(--grey1))] rounded-large flex items-center justify-center">
|
|
1069
|
-
<span class="text-xs">{item.file.name.split('.').pop()?.toUpperCase()}</span>
|
|
1070
|
-
</div>
|
|
1071
|
-
{/if}
|
|
1072
|
-
<div class="flex flex-col">
|
|
1073
|
-
<span dir={nameDirection} class="body-medium truncate {item.status === 'failed' ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{item.file.name}</span>
|
|
1074
|
-
<span class="subtext truncate text-[hsl(var(--grey5))]">{formatKilobytes(item.file.size, $t, $locale)}</span>
|
|
1075
|
-
</div>
|
|
1076
|
-
</div>
|
|
1077
|
-
|
|
1078
|
-
{#if item.status === 'uploading'}
|
|
1079
|
-
<button
|
|
1080
|
-
class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors"
|
|
1081
|
-
onclick={() => handleCancelUpload(item.id)}
|
|
1082
|
-
aria-label={$t('upload.cancel')}
|
|
1083
|
-
>
|
|
1084
|
-
<IconX class="h-4 w-4" />
|
|
1085
|
-
</button>
|
|
1086
|
-
{:else if item.status === 'failed'}
|
|
1087
|
-
<!-- Refresh button moved to error message section -->
|
|
1088
|
-
{:else}
|
|
1089
|
-
<div class="rounded-full w-5 h-5 bg-[hsl(var(--sage-green))] flex items-center justify-center">
|
|
1090
|
-
<img src={getAssetUrl('/icons/checked.svg')} alt={$t('upload.completedAlt')} class="w-5 h-5" />
|
|
1091
|
-
</div>
|
|
1092
|
-
{/if}
|
|
1093
|
-
</div>
|
|
1094
|
-
|
|
1095
|
-
{#if item.status === 'uploading'}
|
|
1096
|
-
<div class="w-full">
|
|
1097
|
-
<div class="w-full h-1 bg-[hsl(var(--light-green))] rounded-full overflow-hidden">
|
|
1098
|
-
<div
|
|
1099
|
-
class="h-full bg-[hsl(var(--sage-green))]"
|
|
1100
|
-
style="width: {item.progress}%;"
|
|
1101
|
-
></div>
|
|
1102
|
-
</div>
|
|
1103
|
-
<div class="flex justify-between mt-1">
|
|
1104
|
-
<span class="caption text-[hsl(var(--grey5))]">{Math.round(item.progress)}%</span>
|
|
1105
|
-
{#if item.timeRemaining}
|
|
1106
|
-
<span class="caption text-[hsl(var(--grey5))]">{item.timeRemaining}</span>
|
|
1107
|
-
{/if}
|
|
1108
|
-
</div>
|
|
1109
|
-
</div>
|
|
1110
|
-
{:else if item.status === 'failed'}
|
|
1111
|
-
<div class="flex items-center justify-between">
|
|
1112
|
-
<!-- The row says why this file failed: the API's own sentence, or the File Browser's when the request never got an answer -->
|
|
1113
|
-
<p class="caption min-w-0 break-words text-[hsl(var(--error))]">
|
|
1114
|
-
{item.errorMessage || $t(library ? 'libraryError.uploadFailed' : 'upload.networkError')}
|
|
1115
|
-
</p>
|
|
1116
|
-
<button
|
|
1117
|
-
class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors flex items-center justify-center w-5 h-5"
|
|
1118
|
-
onclick={() => handleRetryUpload(item.id)}
|
|
1119
|
-
aria-label={$t('upload.retry')}
|
|
1120
|
-
>
|
|
1121
|
-
<IconRefresh class="h-5 w-5" />
|
|
1122
|
-
</button>
|
|
1123
|
-
</div>
|
|
1124
|
-
{/if}
|
|
1125
|
-
</div>
|
|
1126
|
-
{/each}
|
|
1127
|
-
</div>
|
|
1128
|
-
</div>
|
|
951
|
+
<div class="upload-area-ct relative w-full">
|
|
952
|
+
<input
|
|
953
|
+
type="file"
|
|
954
|
+
bind:this={fileInput}
|
|
955
|
+
onchange={handleFileSelect}
|
|
956
|
+
multiple
|
|
957
|
+
class="upload-input hidden"
|
|
958
|
+
accept={acceptTypes}
|
|
959
|
+
/>
|
|
960
|
+
|
|
961
|
+
<Dropzone
|
|
962
|
+
compact={isCompactUploader}
|
|
963
|
+
state={dropzoneState as DropzoneState}
|
|
964
|
+
{isDraggingFolder}
|
|
965
|
+
{allowedTypesDisplayText}
|
|
966
|
+
{acceptsAnyKind}
|
|
967
|
+
{tooltipTypesText}
|
|
968
|
+
showInitialUploading={uploading && uploadItems.length === 0}
|
|
969
|
+
onBrowse={() => fileInput.click()}
|
|
970
|
+
/>
|
|
971
|
+
</div>
|
|
972
|
+
|
|
973
|
+
{#if isUploadsModalOpen && portalTarget && uploadItems.length > 0}
|
|
974
|
+
<Portal target={portalTarget}>
|
|
975
|
+
<div class="pointer-events-none absolute inset-0 z-[9990]">
|
|
976
|
+
<!-- Floats over the page just above the footer (the portal target), inset like the page -->
|
|
977
|
+
<div class="uploads-panel-anchor pointer-events-auto absolute bottom-full mb-4 {isCompactUploader ? 'end-4' : 'end-8'}">
|
|
978
|
+
<UploadPanel
|
|
979
|
+
items={panelItems}
|
|
980
|
+
summaryScope={panelSummaryScope as UploadRowScope}
|
|
981
|
+
summaryState={panelSummaryState as UploadRowState}
|
|
982
|
+
summaryName={panelSummaryName}
|
|
983
|
+
summaryStatus={panelSummaryStatus}
|
|
984
|
+
progressValue={overallProgress}
|
|
985
|
+
progressTone={panelProgressTone}
|
|
986
|
+
progressDone={panelProgressDone}
|
|
987
|
+
footerText={panelFooterText}
|
|
988
|
+
footerDestructive={panelFooterDestructive}
|
|
989
|
+
footerAction={panelFooterAction}
|
|
990
|
+
expanded={!isUploadsDrawerCollapsed}
|
|
991
|
+
onToggleExpand={toggleDrawerCollapse}
|
|
992
|
+
onSummaryCancel={() => {
|
|
993
|
+
if (isBatchUpload) cancelActiveUploads();
|
|
994
|
+
else if (uploadItems[0]) handleCancelUpload(uploadItems[0].id);
|
|
995
|
+
}}
|
|
996
|
+
onSummaryRetry={retryAllFailedUploads}
|
|
997
|
+
onItemCancel={handleCancelUpload}
|
|
998
|
+
onItemRetry={handleRetryUpload}
|
|
999
|
+
onFooterAction={retryAllFailedUploads}
|
|
1000
|
+
showClearCompleted={completedUploadCount > 0}
|
|
1001
|
+
onClearCompleted={clearCompletedUploads}
|
|
1002
|
+
/>
|
|
1129
1003
|
</div>
|
|
1130
|
-
|
|
1131
|
-
<!-- Footer - Always visible even when content is collapsed -->
|
|
1132
|
-
<div class="uploads-drawer-footer p-4 border-t border-[hsl(var(--forest-green))] flex justify-between mt-auto sticky bottom-0 bg-white upload-panel-footer">
|
|
1133
|
-
|
|
1134
|
-
<!-- Retry failed uploads button -->
|
|
1135
|
-
{#if uploadItems.filter(item => item.status === 'failed').length > 0}
|
|
1136
|
-
<button
|
|
1137
|
-
class="retry-failed-uploads-btn body-medium text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors underline"
|
|
1138
|
-
onclick={retryAllFailedUploads}
|
|
1139
|
-
>
|
|
1140
|
-
{$t('upload.retryFailed')}
|
|
1141
|
-
</button>
|
|
1142
|
-
{/if}
|
|
1143
|
-
|
|
1144
|
-
<!-- Clear completed uploads button -->
|
|
1145
|
-
{#if uploadItems.filter(item => item.status === 'complete').length > 0}
|
|
1146
|
-
<button
|
|
1147
|
-
class="clear-completed-uploads-btn btn-secondary h-8 px-3 text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors rounded-small"
|
|
1148
|
-
onclick={clearCompletedUploads}
|
|
1149
|
-
>
|
|
1150
|
-
{$t('upload.clearCompleted')}
|
|
1151
|
-
</button>
|
|
1152
|
-
{/if}
|
|
1153
|
-
|
|
1154
|
-
</div>
|
|
1155
|
-
|
|
1156
|
-
{/if}
|
|
1157
|
-
|
|
1158
|
-
</div>
|
|
1004
|
+
</div>
|
|
1159
1005
|
</Portal>
|
|
1160
1006
|
{/if}
|
|
1161
|
-
|
|
1162
|
-
</div>
|
|
1163
|
-
|
|
1164
|
-
<style>
|
|
1165
|
-
:global(.file-uploader button) {
|
|
1166
|
-
outline: none !important;
|
|
1167
|
-
box-shadow: none !important;
|
|
1168
|
-
--tw-ring-offset-width: 0 !important;
|
|
1169
|
-
--tw-ring-width: 0 !important;
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
:global(.file-uploader button:focus),
|
|
1173
|
-
:global(.file-uploader button:focus-visible) {
|
|
1174
|
-
outline: none !important;
|
|
1175
|
-
box-shadow: none !important;
|
|
1176
|
-
--tw-ring-offset-width: 0 !important;
|
|
1177
|
-
--tw-ring-width: 0 !important;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
/* Override button text to use subtext style */
|
|
1181
|
-
:global(.file-uploader-button) {
|
|
1182
|
-
font-family: 'Inter', sans-serif !important;
|
|
1183
|
-
font-size: 16px !important;
|
|
1184
|
-
line-height: 1.4 !important;
|
|
1185
|
-
font-weight: 400 !important;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
/* Override button text to ensure it's not bold */
|
|
1189
|
-
:global(.file-uploader-button span) {
|
|
1190
|
-
font-weight: 400 !important;
|
|
1191
|
-
font-family: 'Inter', sans-serif !important;
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
/* Make sure drawer appears on top of other elements */
|
|
1195
|
-
:global(.drawer-content) {
|
|
1196
|
-
z-index: 9999 !important;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/* Ensure the drawer content is visible */
|
|
1200
|
-
:global(.drawer) {
|
|
1201
|
-
position: relative;
|
|
1202
|
-
z-index: 9999 !important;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
/* Upload panel styles */
|
|
1206
|
-
:global(.upload-panel) {
|
|
1207
|
-
box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
|
|
1208
|
-
display: flex;
|
|
1209
|
-
flex-direction: column;
|
|
1210
|
-
border-start-start-radius: var(--radius-large);
|
|
1211
|
-
border-start-end-radius: var(--radius-large);
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/* Fix footer position */
|
|
1215
|
-
:global(.upload-panel-footer) {
|
|
1216
|
-
position: sticky;
|
|
1217
|
-
bottom: 0;
|
|
1218
|
-
background-color: white;
|
|
1219
|
-
z-index: 10;
|
|
1220
|
-
}
|
|
1221
|
-
</style>
|
|
1007
|
+
</div>
|