@widgetic/file-browser 0.5.24 → 0.5.26
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 +279 -0
- package/dist/components/FolderTree.svelte +16 -9
- package/dist/components/FolderTree.svelte.d.ts +2 -6
- package/dist/components/core/FileBrowser.svelte +529 -127
- package/dist/components/core/FileBrowser.svelte.d.ts +40 -1
- package/dist/components/core/FileUploader.svelte +130 -57
- package/dist/components/core/Header.svelte +13 -2
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +41 -29
- package/dist/components/core/UploadStatus.svelte +14 -7
- package/dist/components/core/UploadStatusList.svelte +13 -21
- package/dist/components/items/FileItem.svelte +28 -15
- package/dist/components/items/FolderItem.svelte +13 -6
- package/dist/components/modals/MoveDialog.svelte +49 -38
- package/dist/components/modals/NewFolderButton.svelte +5 -2
- package/dist/components/modals/SearchModal.svelte +25 -26
- package/dist/components/modals/SearchModal.svelte.d.ts +1 -1
- package/dist/components/modals/SelectedFilesModal.svelte +23 -14
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +1 -1
- package/dist/components/previews/AudioPlayer.svelte +5 -2
- package/dist/components/previews/ErrorPreview.svelte +7 -4
- package/dist/components/previews/ErrorPreview.svelte.d.ts +1 -1
- package/dist/components/previews/FilePreview.svelte +25 -9
- package/dist/components/previews/FontPreview.svelte +18 -9
- package/dist/components/previews/FontPreview.svelte.d.ts +1 -1
- package/dist/components/previews/TextPreview.svelte +12 -5
- package/dist/components/previews/VideoPlayer.svelte +11 -7
- package/dist/components/ui/ControlToolbar.svelte +50 -28
- package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
- package/dist/components/ui/DragSelect.svelte +3 -2
- package/dist/components/ui/DropdownMenu.svelte +35 -14
- package/dist/components/ui/FileIcon.svelte +8 -5
- package/dist/components/ui/FileIcon.svelte.d.ts +1 -0
- package/dist/components/ui/FileMetadata.svelte +16 -15
- package/dist/components/ui/SearchResults.svelte +9 -2
- package/dist/i18n/context.d.ts +28 -0
- package/dist/i18n/context.js +17 -0
- package/dist/i18n/errors.d.ts +11 -0
- package/dist/i18n/errors.js +19 -0
- package/dist/i18n/index.d.ts +15 -0
- package/dist/i18n/index.js +18 -0
- package/dist/i18n/messages.d.ts +281 -0
- package/dist/i18n/messages.js +294 -0
- package/dist/i18n/text.d.ts +19 -0
- package/dist/i18n/text.js +35 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/mediaLibrary/capabilities.d.ts +22 -0
- package/dist/mediaLibrary/capabilities.js +42 -0
- package/dist/mediaLibrary/context.d.ts +17 -0
- package/dist/mediaLibrary/context.js +16 -0
- package/dist/mediaLibrary/errors.d.ts +42 -0
- package/dist/mediaLibrary/errors.js +114 -0
- package/dist/mediaLibrary/index.d.ts +10 -0
- package/dist/mediaLibrary/index.js +9 -0
- package/dist/mediaLibrary/normalize.d.ts +39 -0
- package/dist/mediaLibrary/normalize.js +139 -0
- package/dist/mediaLibrary/paging.d.ts +37 -0
- package/dist/mediaLibrary/paging.js +62 -0
- package/dist/mediaLibrary/resolve.d.ts +39 -0
- package/dist/mediaLibrary/resolve.js +137 -0
- package/dist/mediaLibrary/treeOps.d.ts +24 -0
- package/dist/mediaLibrary/treeOps.js +67 -0
- package/dist/mediaLibrary/types.d.ts +126 -0
- package/dist/mediaLibrary/types.js +11 -0
- package/dist/mediaLibrary/urls.d.ts +30 -0
- package/dist/mediaLibrary/urls.js +59 -0
- package/dist/mediaLibrary/widgetic.d.ts +39 -0
- package/dist/mediaLibrary/widgetic.js +89 -0
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/stores/folderCountStore.js +2 -2
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.d.ts +11 -1
- package/dist/stores/persistentSelectStore.js +26 -0
- package/dist/utils/dateUtils.d.ts +11 -2
- package/dist/utils/dateUtils.js +20 -15
- package/dist/utils/fileKinds.d.ts +44 -0
- package/dist/utils/fileKinds.js +96 -0
- package/dist/utils/fileNames.d.ts +7 -0
- package/dist/utils/fileNames.js +19 -0
- package/dist/utils/fileOperations.js +2 -11
- package/dist/utils/fileTypes.d.ts +11 -2
- package/dist/utils/fileTypes.js +26 -14
- package/dist/utils/fileUtils.d.ts +8 -1
- package/dist/utils/fileUtils.js +22 -7
- package/dist/utils/folderUtils.js +3 -2
- package/dist/utils/previewKeys.d.ts +12 -0
- package/dist/utils/previewKeys.js +14 -0
- package/dist/utils/safeText.d.ts +29 -0
- package/dist/utils/safeText.js +66 -0
- package/dist/utils/userUploadsStorage.d.ts +4 -1
- package/dist/utils/userUploadsStorage.js +5 -2
- package/dist/utils/widgeticTusUpload.d.ts +10 -0
- package/dist/utils/widgeticTusUpload.js +61 -3
- package/dist/utils/widgeticUpload.d.ts +3 -0
- package/dist/utils/widgeticUpload.js +7 -2
- package/package.json +5 -2
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { FileSystemItem } from '../../types';
|
|
8
8
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
9
|
-
import {
|
|
9
|
+
import { getFileIcon } from '../../utils/fileUtils';
|
|
10
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
11
|
+
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
10
12
|
import { formatRelativeDate } from '../../utils/dateUtils';
|
|
13
|
+
import { useI18n, type Translate } from '../../i18n';
|
|
14
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
11
15
|
import { DropdownMenu, FileIcon } from '../ui';
|
|
12
16
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
13
17
|
// import ThumbHashImage from '../previews/ThumbHashImage.svelte';
|
|
@@ -28,6 +32,11 @@
|
|
|
28
32
|
export let allowSelecting: boolean = false;
|
|
29
33
|
export let columnWidth: number = 40; // Default value if not provided
|
|
30
34
|
|
|
35
|
+
const { t } = useI18n();
|
|
36
|
+
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
37
|
+
const textDirection = useTextDirection();
|
|
38
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
39
|
+
|
|
31
40
|
/* STATE VARS */
|
|
32
41
|
// Responsive breakpoints from global.css
|
|
33
42
|
const DESKTOP_BREAKPOINT = 1156;
|
|
@@ -91,7 +100,7 @@
|
|
|
91
100
|
|
|
92
101
|
function shouldUseFileIcon(file: FileSystemItem): boolean {
|
|
93
102
|
if (file.isMissing || errorStates.get(file.id)) return false;
|
|
94
|
-
const fileType =
|
|
103
|
+
const fileType = getFileTypeOf(file);
|
|
95
104
|
return fileType === 'font' && !isFontCached(file);
|
|
96
105
|
}
|
|
97
106
|
|
|
@@ -130,13 +139,13 @@
|
|
|
130
139
|
* @returns Promise resolving to boolean indicating if font is cached
|
|
131
140
|
*/
|
|
132
141
|
async function checkFontCached(file: FileSystemItem): Promise<boolean> {
|
|
133
|
-
const fileType =
|
|
142
|
+
const fileType = getFileTypeOf(file);
|
|
134
143
|
if (fileType !== 'font') return false;
|
|
135
144
|
|
|
136
145
|
try {
|
|
137
146
|
// Try to check if font is in document.fonts
|
|
138
147
|
if (document.fonts) {
|
|
139
|
-
const fontName = file.name
|
|
148
|
+
const fontName = toSafeFontFamilyName(file.name); // Font name without extension, safe inside CSS
|
|
140
149
|
// Try multiple font checks to ensure accurate detection
|
|
141
150
|
const checks = [
|
|
142
151
|
document.fonts.check(`1em "${fontName}"`),
|
|
@@ -161,7 +170,7 @@
|
|
|
161
170
|
* @returns Promise resolving to boolean indicating if SVG is cached
|
|
162
171
|
*/
|
|
163
172
|
async function checkSvgCached(file: FileSystemItem): Promise<boolean> {
|
|
164
|
-
const fileType =
|
|
173
|
+
const fileType = getFileTypeOf(file);
|
|
165
174
|
if (fileType !== 'svg' || !file.url) return false;
|
|
166
175
|
|
|
167
176
|
try {
|
|
@@ -216,7 +225,9 @@
|
|
|
216
225
|
async function loadFontForDisplay(file: FileSystemItem): Promise<void> {
|
|
217
226
|
if (!file.url) return;
|
|
218
227
|
|
|
219
|
-
|
|
228
|
+
// Both the name and the address come from someone else, and this text becomes a style sheet in the page's
|
|
229
|
+
// <head>: the name is reduced to safe characters and the address is written so it cannot leave its quotes.
|
|
230
|
+
const fontName = toSafeFontFamilyName(file.name);
|
|
220
231
|
const fontId = `font-${file.id}`;
|
|
221
232
|
|
|
222
233
|
// Skip if we already added this font
|
|
@@ -229,7 +240,7 @@
|
|
|
229
240
|
style.textContent = `
|
|
230
241
|
@font-face {
|
|
231
242
|
font-family: "${fontName}";
|
|
232
|
-
src:
|
|
243
|
+
src: ${toCssUrlLiteral(file.url)} format("opentype");
|
|
233
244
|
font-weight: normal;
|
|
234
245
|
font-style: normal;
|
|
235
246
|
font-display: block;
|
|
@@ -249,7 +260,7 @@
|
|
|
249
260
|
async function checkFiles() {
|
|
250
261
|
const promises = recentFiles.map(async (file) => {
|
|
251
262
|
try {
|
|
252
|
-
const fileType =
|
|
263
|
+
const fileType = getFileTypeOf(file);
|
|
253
264
|
const isFont = fileType === 'font';
|
|
254
265
|
|
|
255
266
|
// Load font for display if needed
|
|
@@ -305,7 +316,7 @@
|
|
|
305
316
|
function getThumbnailOrIcon(file: FileSystemItem): string {
|
|
306
317
|
if (isLoading(file)) return '';
|
|
307
318
|
|
|
308
|
-
const fileType =
|
|
319
|
+
const fileType = getFileTypeOf(file);
|
|
309
320
|
const isVideo = fileType === 'video';
|
|
310
321
|
const isSvg = fileType === 'svg';
|
|
311
322
|
const isAudio = fileType === 'audio';
|
|
@@ -339,7 +350,7 @@
|
|
|
339
350
|
* @returns boolean indicating if file is media
|
|
340
351
|
*/
|
|
341
352
|
function isMediaFile(file: FileSystemItem): boolean {
|
|
342
|
-
const fileType =
|
|
353
|
+
const fileType = getFileTypeOf(file);
|
|
343
354
|
return fileType === 'video' || fileType === 'audio';
|
|
344
355
|
}
|
|
345
356
|
|
|
@@ -351,7 +362,7 @@
|
|
|
351
362
|
*/
|
|
352
363
|
function getBackgroundColor(file: FileSystemItem): string {
|
|
353
364
|
if (file.isMissing || errorStates.get(file.id)) return '#FFF5F5';
|
|
354
|
-
const fileType =
|
|
365
|
+
const fileType = getFileTypeOf(file);
|
|
355
366
|
if (fileType === 'audio') return '#A7FF68';
|
|
356
367
|
if (fileType === 'document') return '#FFDC68';
|
|
357
368
|
return 'bg-gray-100';
|
|
@@ -363,7 +374,7 @@
|
|
|
363
374
|
* @returns boolean indicating if SVG icon should be used
|
|
364
375
|
*/
|
|
365
376
|
function isSvgIcon(file: FileSystemItem): boolean {
|
|
366
|
-
const fileType =
|
|
377
|
+
const fileType = getFileTypeOf(file);
|
|
367
378
|
return fileType === 'svg';
|
|
368
379
|
}
|
|
369
380
|
|
|
@@ -407,10 +418,11 @@
|
|
|
407
418
|
/**
|
|
408
419
|
* Formats file modification date
|
|
409
420
|
* @param date Date to format
|
|
421
|
+
* @param translate The `t` of the screen, so the words follow the page's language (and the text is written again when it changes)
|
|
410
422
|
* @returns Formatted date string
|
|
411
423
|
*/
|
|
412
|
-
function getFormattedDate(date: string | Date): string {
|
|
413
|
-
return formatRelativeDate(date);
|
|
424
|
+
function getFormattedDate(date: string | Date, translate: Translate): string {
|
|
425
|
+
return formatRelativeDate(date, translate);
|
|
414
426
|
}
|
|
415
427
|
|
|
416
428
|
/**
|
|
@@ -480,7 +492,7 @@
|
|
|
480
492
|
*/
|
|
481
493
|
function isCachedFontPreview(file: FileSystemItem): boolean {
|
|
482
494
|
if (file.isMissing || errorStates.get(file.id)) return false;
|
|
483
|
-
const fileType =
|
|
495
|
+
const fileType = getFileTypeOf(file);
|
|
484
496
|
return fileType === 'font' && isFontCached(file);
|
|
485
497
|
}
|
|
486
498
|
|
|
@@ -499,7 +511,7 @@
|
|
|
499
511
|
style="{style ? style + ' ' : ''}display:flex;"
|
|
500
512
|
>
|
|
501
513
|
<!-- Section Header -->
|
|
502
|
-
<h2 class="h5 text-[hsl(var(--grey7))] mb-4">
|
|
514
|
+
<h2 class="h5 text-[hsl(var(--grey7))] mb-4">{$t('recent.title')}</h2>
|
|
503
515
|
|
|
504
516
|
<!-- Files Grid Layout - Using CSS Grid with responsive columns -->
|
|
505
517
|
<div class="grid gap-5 w-full" style="grid-template-columns: repeat({numberOfColumns}, minmax(0, 1fr));">
|
|
@@ -562,11 +574,11 @@
|
|
|
562
574
|
<div class="w-full h-full flex flex-col items-center justify-center bg-[hsl(var(--grey1))] rounded-large widgetic-radius cached-font-preview">
|
|
563
575
|
<div class="flex flex-col items-center justify-center h-full w-full">
|
|
564
576
|
<!-- Use inline style with !important to force font application -->
|
|
565
|
-
<div style="font-family: {file.name
|
|
577
|
+
<div style="font-family: '{toSafeFontFamilyName(file.name)}' !important;" class="text-8xl mb-4 text-[hsl(var(--grey7))] widgetic-colors">
|
|
566
578
|
aA
|
|
567
579
|
</div>
|
|
568
|
-
<div style="font-family: {file.name
|
|
569
|
-
|
|
580
|
+
<div style="font-family: '{toSafeFontFamilyName(file.name)}' !important;" class="text-xl text-[hsl(var(--grey7))] widgetic-colors">
|
|
581
|
+
{$t('fontPreview.sampleShort')}
|
|
570
582
|
</div>
|
|
571
583
|
</div>
|
|
572
584
|
</div>
|
|
@@ -583,14 +595,14 @@
|
|
|
583
595
|
{:else if isMediaFile(file) && file.hash && file.url}
|
|
584
596
|
<div class="absolute inset-0">
|
|
585
597
|
<ThumbHashImage
|
|
586
|
-
src={
|
|
598
|
+
src={getFileTypeOf(file) === 'video' ? (file.thumbnail || file.url) : file.url}
|
|
587
599
|
alt={file.name}
|
|
588
600
|
thumbhash={file.hash}
|
|
589
601
|
class_="w-full h-full object-cover"
|
|
590
602
|
/>
|
|
591
603
|
</div>
|
|
592
604
|
<img
|
|
593
|
-
src={
|
|
605
|
+
src={getFileTypeOf(file) === 'video' ? (file.thumbnail || '') : file.url}
|
|
594
606
|
alt={file.name}
|
|
595
607
|
class="w-full h-full absolute inset-0 object-cover fade-in"
|
|
596
608
|
onload={() => imageLoaded = true}
|
|
@@ -609,7 +621,7 @@
|
|
|
609
621
|
<!-- Play Button Overlay for Media Files -->
|
|
610
622
|
{#if isMediaFile(file) && !file.isMissing && !errorStates.get(file.id)}
|
|
611
623
|
<div class="absolute inset-0 flex items-center justify-center transition-transform duration-200 {isSelected(file) ? 'scale-[0.8]' : ''}">
|
|
612
|
-
<img src={getAssetUrl('/icons/player-play.svg')} alt=
|
|
624
|
+
<img src={getAssetUrl('/icons/player-play.svg')} alt={$t('action.play')} class="w-36 h-36" />
|
|
613
625
|
</div>
|
|
614
626
|
{/if}
|
|
615
627
|
{/if}
|
|
@@ -622,24 +634,24 @@
|
|
|
622
634
|
<div class="flex items-start justify-between mb-1">
|
|
623
635
|
<div class="flex-1 min-w-0">
|
|
624
636
|
<!-- File Name -->
|
|
625
|
-
<h3 class="body-medium text-[hsl({file.isMissing ? 'var(--error)' : 'var(--grey7)'})] truncate">
|
|
637
|
+
<h3 dir={nameDirection} class="body-medium text-[hsl({file.isMissing ? 'var(--error)' : 'var(--grey7)'})] truncate">
|
|
626
638
|
{file.name}
|
|
627
639
|
</h3>
|
|
628
640
|
|
|
629
641
|
<!-- File Modification Date -->
|
|
630
642
|
<p class="subtext text-[hsl({file.isMissing ? 'var(--error)' : 'var(--grey5)'})] truncate">
|
|
631
|
-
{getFormattedDate(file.modified || new Date())}
|
|
643
|
+
{getFormattedDate(file.modified || new Date(), $t)}
|
|
632
644
|
</p>
|
|
633
645
|
</div>
|
|
634
646
|
|
|
635
647
|
<!-- Selection Check Icon -->
|
|
636
648
|
{#if isSelected(file) && allowSelecting}
|
|
637
|
-
<div class="
|
|
638
|
-
<img src={getAssetUrl('/icons/checked.svg')} alt=
|
|
649
|
+
<div class="ms-2 mt-1 flex-shrink-0">
|
|
650
|
+
<img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.selected')} class="w-5 h-5" />
|
|
639
651
|
</div>
|
|
640
652
|
{:else if !file.isMissing && allowSelecting}
|
|
641
|
-
<div class="
|
|
642
|
-
<img src={getAssetUrl('/icons/checked.svg')} alt=
|
|
653
|
+
<div class="ms-2 mt-1 opacity-0 group-hover:opacity-20 transition-all duration-200 flex-shrink-0">
|
|
654
|
+
<img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.select')} class="w-5 h-5" />
|
|
643
655
|
</div>
|
|
644
656
|
{/if}
|
|
645
657
|
</div>
|
|
@@ -655,7 +667,7 @@
|
|
|
655
667
|
<div class="flex items-center justify-center h-[197px]">
|
|
656
668
|
<div class="flex items-center gap-2">
|
|
657
669
|
<IconExclamationCircle class="w-6 h-6 text-[hsl(var(--grey3))]" />
|
|
658
|
-
<p class="text-[hsl(var(--grey3))] subtext">
|
|
670
|
+
<p class="text-[hsl(var(--grey3))] subtext">{$t('recent.empty')}</p>
|
|
659
671
|
</div>
|
|
660
672
|
</div>
|
|
661
673
|
{/if}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
// Design system imports
|
|
3
3
|
import { IconTrash, IconRefresh } from '@widgetic/design-system/icons';
|
|
4
|
+
import { useI18n } from '../../i18n';
|
|
5
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n();
|
|
8
|
+
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
9
|
+
const textDirection = useTextDirection();
|
|
10
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
4
11
|
|
|
5
12
|
// Component props
|
|
6
13
|
export let file: File;
|
|
@@ -60,19 +67,19 @@
|
|
|
60
67
|
<!-- File info and progress -->
|
|
61
68
|
<div class="flex-grow min-w-0">
|
|
62
69
|
<div class="flex justify-between items-start">
|
|
63
|
-
<div class="truncate
|
|
64
|
-
<p class="font-medium truncate">{file.name}</p>
|
|
70
|
+
<div class="truncate pe-2">
|
|
71
|
+
<p dir={nameDirection} class="font-medium truncate">{file.name}</p>
|
|
65
72
|
<div class="flex items-center text-sm text-[hsl(var(--grey3))]">
|
|
66
73
|
{#if status === 'uploading'}
|
|
67
74
|
<span>{fileSize}</span>
|
|
68
75
|
{#if timeRemaining}
|
|
69
76
|
<span class="mx-1">•</span>
|
|
70
|
-
<span>{timeRemaining}
|
|
77
|
+
<span>{$t('upload.timeLeft', { time: timeRemaining })}</span>
|
|
71
78
|
{/if}
|
|
72
79
|
{:else if status === 'failed'}
|
|
73
80
|
<span class="text-[hsl(var(--error))]">{fileSize}</span>
|
|
74
81
|
{:else}
|
|
75
|
-
<span class="text-[hsl(var(--sage-green))]">
|
|
82
|
+
<span class="text-[hsl(var(--sage-green))]">{$t('upload.complete')}</span>
|
|
76
83
|
{/if}
|
|
77
84
|
</div>
|
|
78
85
|
</div>
|
|
@@ -83,7 +90,7 @@
|
|
|
83
90
|
<button
|
|
84
91
|
class="p-2 text-[hsl(var(--grey3))] hover:text-[hsl(var(--error))] transition-colors"
|
|
85
92
|
onclick={onCancel}
|
|
86
|
-
aria-label=
|
|
93
|
+
aria-label={$t('upload.cancel')}
|
|
87
94
|
>
|
|
88
95
|
<IconTrash class="w-5 h-5" />
|
|
89
96
|
</button>
|
|
@@ -92,14 +99,14 @@
|
|
|
92
99
|
<button
|
|
93
100
|
class="p-2 text-[hsl(var(--grey3))] hover:text-[hsl(var(--error))] transition-colors"
|
|
94
101
|
onclick={onCancel}
|
|
95
|
-
aria-label=
|
|
102
|
+
aria-label={$t('upload.removeFile')}
|
|
96
103
|
>
|
|
97
104
|
<IconTrash class="w-5 h-5" />
|
|
98
105
|
</button>
|
|
99
106
|
<button
|
|
100
107
|
class="p-2 text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors"
|
|
101
108
|
onclick={onRetry}
|
|
102
|
-
aria-label=
|
|
109
|
+
aria-label={$t('upload.retry')}
|
|
103
110
|
>
|
|
104
111
|
<IconRefresh class="w-5 h-5" />
|
|
105
112
|
</button>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import UploadStatus from './UploadStatus.svelte';
|
|
3
3
|
import { createEventDispatcher } from 'svelte';
|
|
4
|
+
import { useI18n } from '../../i18n';
|
|
5
|
+
import { formatFileSize } from '../../utils/fileUtils';
|
|
4
6
|
|
|
5
7
|
const dispatch = createEventDispatcher();
|
|
8
|
+
const { t, locale } = useI18n();
|
|
6
9
|
|
|
7
10
|
// Types
|
|
8
11
|
type UploadItem = {
|
|
@@ -21,17 +24,6 @@
|
|
|
21
24
|
export let onCancel: (id: string) => void;
|
|
22
25
|
export let onRetry: (id: string) => void;
|
|
23
26
|
|
|
24
|
-
// Helper function to format file size
|
|
25
|
-
function formatFileSize(bytes: number): string {
|
|
26
|
-
if (bytes === 0) return '0 B';
|
|
27
|
-
|
|
28
|
-
const k = 1024;
|
|
29
|
-
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
30
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
31
|
-
|
|
32
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
27
|
// Group uploads by status for better organization
|
|
36
28
|
$: completedUploads = uploads.filter(u => u.status === 'complete');
|
|
37
29
|
$: activeUploads = uploads.filter(u => u.status === 'uploading');
|
|
@@ -57,23 +49,23 @@
|
|
|
57
49
|
<div class="flex justify-between items-center mb-2">
|
|
58
50
|
<h3 class="font-medium flex items-center">
|
|
59
51
|
{#if failedCount > 0 && completedCount > 0}
|
|
60
|
-
{completedCount
|
|
52
|
+
{$t('upload.progress', { done: completedCount, total: totalUploads })}
|
|
61
53
|
{:else if uploadingCount > 0}
|
|
62
|
-
|
|
54
|
+
{$t('upload.uploadingProgress', { done: uploadingCount, total: totalUploads })}
|
|
63
55
|
{:else if completedCount === totalUploads}
|
|
64
|
-
{totalUploads}
|
|
56
|
+
{$t('upload.filesTotal', { count: totalUploads })}
|
|
65
57
|
{:else}
|
|
66
|
-
{totalUploads}
|
|
58
|
+
{$t('upload.filesTotal', { count: totalUploads })}
|
|
67
59
|
{/if}
|
|
68
60
|
</h3>
|
|
69
61
|
|
|
70
62
|
<div class="text-sm text-[hsl(var(--grey3))] flex items-center">
|
|
71
63
|
{#if failedCount > 0}
|
|
72
|
-
<span class="text-[hsl(var(--error))]">{failedCount}
|
|
64
|
+
<span class="text-[hsl(var(--error))]">{$t('upload.failedCount', { count: failedCount })}</span>
|
|
73
65
|
{:else if completedCount === totalUploads}
|
|
74
|
-
<span class="text-[hsl(var(--sage-green))]">
|
|
66
|
+
<span class="text-[hsl(var(--sage-green))]">{$t('upload.complete')}</span>
|
|
75
67
|
{:else}
|
|
76
|
-
<span>{completedCount
|
|
68
|
+
<span>{$t('upload.completeCount', { done: completedCount, total: totalUploads })}</span>
|
|
77
69
|
{/if}
|
|
78
70
|
</div>
|
|
79
71
|
</div>
|
|
@@ -94,7 +86,7 @@
|
|
|
94
86
|
class="text-[hsl(var(--deep-forest-green))] hover:underline"
|
|
95
87
|
onclick={() => failedUploads.forEach(u => onRetry(u.id))}
|
|
96
88
|
>
|
|
97
|
-
|
|
89
|
+
{$t('upload.retryFailed')}
|
|
98
90
|
</button>
|
|
99
91
|
</div>
|
|
100
92
|
{/if}
|
|
@@ -108,7 +100,7 @@
|
|
|
108
100
|
file={upload.file}
|
|
109
101
|
progress={upload.progress}
|
|
110
102
|
status={upload.status}
|
|
111
|
-
fileSize={formatFileSize(upload.file.size)}
|
|
103
|
+
fileSize={formatFileSize(upload.file.size, $t, $locale)}
|
|
112
104
|
timeRemaining={upload.timeRemaining || ''}
|
|
113
105
|
errorMessage={upload.errorMessage || ''}
|
|
114
106
|
previewUrl={upload.previewUrl}
|
|
@@ -130,7 +122,7 @@
|
|
|
130
122
|
dispatch('uploadsCleared');
|
|
131
123
|
}}
|
|
132
124
|
>
|
|
133
|
-
|
|
125
|
+
{$t('action.done')}
|
|
134
126
|
</button>
|
|
135
127
|
</div>
|
|
136
128
|
{/if}
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
|
|
23
23
|
import type { FileSystemItem } from '../../types';
|
|
24
24
|
import { getFileIcon, getItemFileType, formatFileSize } from '../../utils/fileUtils';
|
|
25
|
+
import { useI18n } from '../../i18n';
|
|
26
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
27
|
+
import { isKnownNonImageFile } from '../../utils/fileKinds';
|
|
28
|
+
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
25
29
|
import { addMissingFile, removeMissingFile } from '../../stores/missingFilesStore';
|
|
26
30
|
import { browser } from '$app/environment';
|
|
27
31
|
import { IconTrash } from '@tabler/icons-svelte';
|
|
@@ -47,6 +51,10 @@
|
|
|
47
51
|
$: isSelected = allowSelecting && selected;
|
|
48
52
|
|
|
49
53
|
const dispatch = createEventDispatcher();
|
|
54
|
+
const { t, locale } = useI18n();
|
|
55
|
+
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
56
|
+
const textDirection = useTextDirection();
|
|
57
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
50
58
|
|
|
51
59
|
|
|
52
60
|
// Reactive declarations for file type handling
|
|
@@ -57,10 +65,14 @@
|
|
|
57
65
|
$: isSvg = fileType === 'svg';
|
|
58
66
|
$: isFont = fileType === 'font';
|
|
59
67
|
$: fileIcon = getFileIcon(item.name);
|
|
60
|
-
|
|
68
|
+
// The name a font is registered and styled under; safe to put inside CSS (see safeText.ts).
|
|
69
|
+
$: fontName = toSafeFontFamilyName(item.name);
|
|
61
70
|
$: previewSrc = item.thumbnail || item.url || '';
|
|
62
71
|
$: isLikelyRemoteImage = !!(previewSrc && /^(https?:|blob:|data:image)/i.test(previewSrc));
|
|
63
|
-
|
|
72
|
+
// A PDF or a text file without a thumbnail gets the file-type icon: drawing the file itself as a picture
|
|
73
|
+
// fails and would show it as "missing", which also makes it impossible to select (see fileKinds.ts).
|
|
74
|
+
$: isKnownNonPicture = !item.thumbnail && isKnownNonImageFile(item);
|
|
75
|
+
$: showImageThumb = isImage || isSvg || (isLikelyRemoteImage && !isAudio && !isVideo && !isFont && !isKnownNonPicture);
|
|
64
76
|
|
|
65
77
|
// State for file availability and loading
|
|
66
78
|
let isLoading = true;
|
|
@@ -154,7 +166,7 @@
|
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
// Create and load the font
|
|
157
|
-
fontFace = new FontFace(fontName,
|
|
169
|
+
fontFace = new FontFace(fontName, toCssUrlLiteral(item.url ?? ''));
|
|
158
170
|
|
|
159
171
|
// Set a timeout to catch hanging loads
|
|
160
172
|
const fontLoadPromise = fontFace.load();
|
|
@@ -478,7 +490,8 @@
|
|
|
478
490
|
height: 54px;
|
|
479
491
|
"
|
|
480
492
|
onclick={handleIconClick}
|
|
481
|
-
|
|
493
|
+
data-fb-action="preview"
|
|
494
|
+
aria-label={$t('item.previewLabel', { name: item.name })}
|
|
482
495
|
disabled={isMissing}
|
|
483
496
|
>
|
|
484
497
|
<div class="w-full h-full flex items-center justify-center relative">
|
|
@@ -511,7 +524,7 @@
|
|
|
511
524
|
{#if isAudio || (fileType === 'document' && !showImageThumb)}
|
|
512
525
|
<img
|
|
513
526
|
src={getAssetUrl(getFileIcon(item.name))}
|
|
514
|
-
alt={isAudio ? '
|
|
527
|
+
alt={isAudio ? $t('item.audioFile') : $t('item.documentFile')}
|
|
515
528
|
class="audio-doc-icon-image w-full h-full rounded-[var(--radius-large)] object-contain {isImageCached ? 'no-fade' : 'fade-in'}"
|
|
516
529
|
/>
|
|
517
530
|
<!-- Image -->
|
|
@@ -575,7 +588,7 @@
|
|
|
575
588
|
<div class="play-icon-bg bg-white rounded-full p-2 shadow-lg">
|
|
576
589
|
<img
|
|
577
590
|
src={getAssetUrl('/icons/player-play.svg')}
|
|
578
|
-
alt=
|
|
591
|
+
alt={$t('action.play')}
|
|
579
592
|
class="play-icon-image w-4 h-4"
|
|
580
593
|
/>
|
|
581
594
|
</div>
|
|
@@ -588,28 +601,28 @@
|
|
|
588
601
|
<!-- Content Column -->
|
|
589
602
|
{#if !thumbnailOnly}
|
|
590
603
|
<div class="fb-file-content-ct flex flex-col justify-center min-w-0 relative w-full" class:items-center={gridLayout} class:text-center={gridLayout}>
|
|
591
|
-
<div class="widgetic-colors pointer-events-none w-full" class:
|
|
592
|
-
<h3 class="fb-file-title body-medium text-sm leading-snug line-clamp-2 break-words cursor-default" class:text-center={gridLayout} class:text-[hsl(var(--error))]={isMissing} class:text-[hsl(var(--grey7))]={!isMissing}>
|
|
604
|
+
<div class="widgetic-colors pointer-events-none w-full" class:pe-10={!gridLayout} class:px-1={gridLayout}>
|
|
605
|
+
<h3 dir={nameDirection} class="fb-file-title body-medium text-sm leading-snug line-clamp-2 break-words cursor-default" class:text-center={gridLayout} class:text-[hsl(var(--error))]={isMissing} class:text-[hsl(var(--grey7))]={!isMissing}>
|
|
593
606
|
{item.name}
|
|
594
607
|
</h3>
|
|
595
608
|
<p class="subtext cursor-default mt-0.5" class:truncate={!gridLayout} class:text-center={gridLayout} class:text-[hsl(var(--error))]={isMissing} class:text-[hsl(var(--grey5))]={!isMissing}>
|
|
596
|
-
{formatFileSize(item.size ?? 0)}
|
|
609
|
+
{formatFileSize(item.size ?? 0, $t, $locale)}
|
|
597
610
|
</p>
|
|
598
611
|
</div>
|
|
599
612
|
|
|
600
613
|
<!-- Checkbox/Actions -->
|
|
601
614
|
{#if !isMissing && allowSelecting && !selected}
|
|
602
|
-
<div class="absolute top-[17px]
|
|
603
|
-
<img src={getAssetUrl('/icons/checked.svg')} alt=
|
|
615
|
+
<div class="absolute top-[17px] end-4 z-10 opacity-0 group-hover:opacity-20 transition-all duration-200">
|
|
616
|
+
<img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.select')} class="w-5 h-5" />
|
|
604
617
|
</div>
|
|
605
618
|
{/if}
|
|
606
619
|
{#if selected}
|
|
607
|
-
<div class="absolute top-[17px]
|
|
608
|
-
<img src={getAssetUrl('/icons/checked.svg')} alt=
|
|
620
|
+
<div class="absolute top-[17px] end-4 z-10 opacity-100">
|
|
621
|
+
<img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.selected')} class="w-5 h-5" />
|
|
609
622
|
</div>
|
|
610
623
|
{/if}
|
|
611
624
|
{#if isMissing}
|
|
612
|
-
<div class="absolute top-[17px]
|
|
625
|
+
<div class="absolute top-[17px] end-4 z-10">
|
|
613
626
|
<button
|
|
614
627
|
class="w-5 h-5 text-[hsl(var(--error))] opacity-0 group-hover:opacity-100 transition-opacity duration-200"
|
|
615
628
|
class:!opacity-100={effectiveIsMobile}
|
|
@@ -617,7 +630,7 @@
|
|
|
617
630
|
e.stopPropagation();
|
|
618
631
|
dispatch('delete', { item });
|
|
619
632
|
}}
|
|
620
|
-
aria-label=
|
|
633
|
+
aria-label={$t('item.deleteMissing')}
|
|
621
634
|
>
|
|
622
635
|
<IconTrash size={20} />
|
|
623
636
|
</button>
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
6
6
|
import { DropdownMenu } from '../ui';
|
|
7
7
|
import { isMobileStore } from '../../stores/viewportStore';
|
|
8
|
+
import { useI18n } from '../../i18n';
|
|
9
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
8
10
|
|
|
9
11
|
export let item: FolderItemWithCount;
|
|
10
12
|
export let currentFilter: FileFilterType = 'all';
|
|
@@ -12,6 +14,10 @@
|
|
|
12
14
|
export let isMobile: boolean | undefined = undefined;
|
|
13
15
|
|
|
14
16
|
const dispatch = createEventDispatcher();
|
|
17
|
+
const { t } = useI18n();
|
|
18
|
+
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
19
|
+
const textDirection = useTextDirection();
|
|
20
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
15
21
|
|
|
16
22
|
$: effectiveIsMobile = isMobile !== undefined ? isMobile : $isMobileStore;
|
|
17
23
|
|
|
@@ -46,21 +52,22 @@
|
|
|
46
52
|
class="w-[62px] h-[54px] flex items-center justify-center cursor-pointer hover:opacity-80 transition-opacity shrink-0"
|
|
47
53
|
style="background-color: #FFFFFF;"
|
|
48
54
|
on:click={handleIconClick}
|
|
49
|
-
|
|
55
|
+
data-fb-action="open-folder"
|
|
56
|
+
aria-label={$t('folder.open', { name: item.name })}
|
|
50
57
|
>
|
|
51
|
-
<img src={icon} alt=
|
|
58
|
+
<img src={icon} alt={$t('item.folder')} class="w-full h-full object-contain" />
|
|
52
59
|
</button>
|
|
53
60
|
|
|
54
61
|
<div class="fb-folder-content-ct flex flex-col min-w-0 relative w-full" class:items-center={gridLayout} class:text-center={gridLayout} class:justify-between={!gridLayout} class:min-h-[54px]={!gridLayout} class:pt-[5px]={!gridLayout}>
|
|
55
|
-
<div class="w-full" class:
|
|
56
|
-
<h3 class="fb-folder-title body-medium text-[hsl(var(--grey7))] text-sm leading-snug line-clamp-2 break-words cursor-default" class:text-center={gridLayout}>{item.name}</h3>
|
|
62
|
+
<div class="w-full" class:pe-10={!gridLayout} class:px-1={gridLayout}>
|
|
63
|
+
<h3 dir={nameDirection} class="fb-folder-title body-medium text-[hsl(var(--grey7))] text-sm leading-snug line-clamp-2 break-words cursor-default" class:text-center={gridLayout}>{item.name}</h3>
|
|
57
64
|
<p class="subtext text-[hsl(var(--grey5))] cursor-default mt-0.5" class:truncate={!gridLayout} class:text-center={gridLayout}>
|
|
58
|
-
{isEmpty ? '
|
|
65
|
+
{isEmpty ? $t('folder.empty') : $t('folder.itemCount', { count: item.matchingFileCount })}
|
|
59
66
|
</p>
|
|
60
67
|
</div>
|
|
61
68
|
|
|
62
69
|
<div
|
|
63
|
-
class="fb-folder-menu-ct opacity-0 group-hover:opacity-100 transition-opacity duration-200 w-5 h-5 {effectiveIsMobile ? '!opacity-100' : ''} {gridLayout ? 'mt-0.5' : 'absolute
|
|
70
|
+
class="fb-folder-menu-ct opacity-0 group-hover:opacity-100 transition-opacity duration-200 w-5 h-5 {effectiveIsMobile ? '!opacity-100' : ''} {gridLayout ? 'mt-0.5' : 'absolute end-4 top-1/2 -translate-y-1/2'}"
|
|
64
71
|
>
|
|
65
72
|
<DropdownMenu isFolder={true} on:action={handleDropdownAction} />
|
|
66
73
|
</div>
|