@widgetic/file-browser 0.5.24 → 0.5.25

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.
Files changed (97) hide show
  1. package/README.md +225 -0
  2. package/dist/components/FolderTree.svelte +4 -1
  3. package/dist/components/FolderTree.svelte.d.ts +2 -6
  4. package/dist/components/core/FileBrowser.svelte +494 -120
  5. package/dist/components/core/FileBrowser.svelte.d.ts +25 -1
  6. package/dist/components/core/FileUploader.svelte +114 -45
  7. package/dist/components/core/Header.svelte +12 -1
  8. package/dist/components/core/Header.svelte.d.ts +1 -0
  9. package/dist/components/core/RecentFiles.svelte +34 -26
  10. package/dist/components/core/UploadStatus.svelte +8 -5
  11. package/dist/components/core/UploadStatusList.svelte +13 -21
  12. package/dist/components/items/FileItem.svelte +19 -10
  13. package/dist/components/items/FolderItem.svelte +6 -3
  14. package/dist/components/modals/MoveDialog.svelte +43 -32
  15. package/dist/components/modals/NewFolderButton.svelte +5 -2
  16. package/dist/components/modals/SearchModal.svelte +16 -21
  17. package/dist/components/modals/SearchModal.svelte.d.ts +1 -1
  18. package/dist/components/modals/SelectedFilesModal.svelte +14 -9
  19. package/dist/components/modals/SelectedFilesModal.svelte.d.ts +1 -1
  20. package/dist/components/previews/AudioPlayer.svelte +5 -2
  21. package/dist/components/previews/ErrorPreview.svelte +7 -4
  22. package/dist/components/previews/ErrorPreview.svelte.d.ts +1 -1
  23. package/dist/components/previews/FilePreview.svelte +17 -7
  24. package/dist/components/previews/FontPreview.svelte +18 -9
  25. package/dist/components/previews/FontPreview.svelte.d.ts +1 -1
  26. package/dist/components/previews/TextPreview.svelte +12 -5
  27. package/dist/components/previews/VideoPlayer.svelte +8 -5
  28. package/dist/components/ui/ControlToolbar.svelte +45 -23
  29. package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
  30. package/dist/components/ui/DragSelect.svelte +2 -2
  31. package/dist/components/ui/DropdownMenu.svelte +35 -14
  32. package/dist/components/ui/FileIcon.svelte +8 -5
  33. package/dist/components/ui/FileIcon.svelte.d.ts +1 -0
  34. package/dist/components/ui/FileMetadata.svelte +12 -15
  35. package/dist/components/ui/SearchResults.svelte +4 -1
  36. package/dist/i18n/context.d.ts +38 -0
  37. package/dist/i18n/context.js +70 -0
  38. package/dist/i18n/errors.d.ts +11 -0
  39. package/dist/i18n/errors.js +19 -0
  40. package/dist/i18n/index.d.ts +11 -0
  41. package/dist/i18n/index.js +18 -0
  42. package/dist/i18n/messages.d.ts +277 -0
  43. package/dist/i18n/messages.js +290 -0
  44. package/dist/i18n/text.d.ts +19 -0
  45. package/dist/i18n/text.js +35 -0
  46. package/dist/i18n/translator.d.ts +75 -0
  47. package/dist/i18n/translator.js +317 -0
  48. package/dist/index.d.ts +3 -0
  49. package/dist/index.js +4 -0
  50. package/dist/mediaLibrary/capabilities.d.ts +22 -0
  51. package/dist/mediaLibrary/capabilities.js +42 -0
  52. package/dist/mediaLibrary/context.d.ts +17 -0
  53. package/dist/mediaLibrary/context.js +16 -0
  54. package/dist/mediaLibrary/errors.d.ts +42 -0
  55. package/dist/mediaLibrary/errors.js +114 -0
  56. package/dist/mediaLibrary/index.d.ts +10 -0
  57. package/dist/mediaLibrary/index.js +9 -0
  58. package/dist/mediaLibrary/normalize.d.ts +39 -0
  59. package/dist/mediaLibrary/normalize.js +139 -0
  60. package/dist/mediaLibrary/paging.d.ts +37 -0
  61. package/dist/mediaLibrary/paging.js +62 -0
  62. package/dist/mediaLibrary/resolve.d.ts +39 -0
  63. package/dist/mediaLibrary/resolve.js +137 -0
  64. package/dist/mediaLibrary/treeOps.d.ts +24 -0
  65. package/dist/mediaLibrary/treeOps.js +67 -0
  66. package/dist/mediaLibrary/types.d.ts +126 -0
  67. package/dist/mediaLibrary/types.js +11 -0
  68. package/dist/mediaLibrary/urls.d.ts +30 -0
  69. package/dist/mediaLibrary/urls.js +59 -0
  70. package/dist/mediaLibrary/widgetic.d.ts +39 -0
  71. package/dist/mediaLibrary/widgetic.js +89 -0
  72. package/dist/stores/fileStore.d.ts +2 -2
  73. package/dist/stores/folderCountStore.js +2 -2
  74. package/dist/stores/navigationStore.d.ts +1 -1
  75. package/dist/stores/persistentSelectStore.d.ts +11 -1
  76. package/dist/stores/persistentSelectStore.js +26 -0
  77. package/dist/utils/dateUtils.d.ts +11 -2
  78. package/dist/utils/dateUtils.js +20 -15
  79. package/dist/utils/fileKinds.d.ts +44 -0
  80. package/dist/utils/fileKinds.js +96 -0
  81. package/dist/utils/fileNames.d.ts +7 -0
  82. package/dist/utils/fileNames.js +19 -0
  83. package/dist/utils/fileOperations.js +2 -11
  84. package/dist/utils/fileTypes.d.ts +11 -2
  85. package/dist/utils/fileTypes.js +26 -14
  86. package/dist/utils/fileUtils.d.ts +8 -1
  87. package/dist/utils/fileUtils.js +22 -7
  88. package/dist/utils/folderUtils.js +3 -2
  89. package/dist/utils/safeText.d.ts +29 -0
  90. package/dist/utils/safeText.js +66 -0
  91. package/dist/utils/userUploadsStorage.d.ts +4 -1
  92. package/dist/utils/userUploadsStorage.js +5 -2
  93. package/dist/utils/widgeticTusUpload.d.ts +10 -0
  94. package/dist/utils/widgeticTusUpload.js +61 -3
  95. package/dist/utils/widgeticUpload.d.ts +3 -0
  96. package/dist/utils/widgeticUpload.js +7 -2
  97. package/package.json +4 -2
@@ -1,6 +1,8 @@
1
1
  import './FileBrowser.css';
2
2
  import '@widgetic/design-system/styles';
3
3
  import { type FileFilterType } from '../../utils/fileTypes';
4
+ import type { MediaLibraryProvider } from '../../mediaLibrary/types';
5
+ import type { MessageOverrides } from '../../i18n/translator';
4
6
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
5
7
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
8
  $$bindings?: Bindings;
@@ -18,6 +20,19 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
18
20
  /**
19
21
  * COMPONENT PROPS
20
22
  */ data?: any;
23
+ /**
24
+ * The host's own media library (a `MediaLibraryProvider`): plain functions the File Browser calls to list, upload,
25
+ * rename and delete the host's files. When given, the File Browser shows that one flat library instead of the
26
+ * Widgetic uploads or the demo content, and stores nothing about it on this device (no local cache, no saved
27
+ * tree, no saved selection unless `persistSelection` says so).
28
+ *
29
+ * Read once, when the File Browser is created: to show another library, create a new File Browser.
30
+ */ mediaLibrary?: MediaLibraryProvider | null;
31
+ /**
32
+ * Whether the picked files are remembered in this browser's localStorage between visits. Default: yes, as always,
33
+ * except with a `mediaLibrary` (a shared browser must not show the next visitor the previous one's picks).
34
+ * This is a setting of the page: when two File Browsers disagree, the last one created wins.
35
+ */ persistSelection?: boolean | undefined;
21
36
  class?: string;
22
37
  style?: string;
23
38
  basePath?: string;
@@ -35,7 +50,15 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
35
50
  maxSelections?: number | null;
36
51
  /** When set (single-file picker), disables confirm until user picks a different file. */ activeFileId?: string | null;
37
52
  showAddToEditor?: boolean;
38
- addToEditorLabel?: string;
53
+ /** The text of the button that hands the picked files to the page. Default: the message "action.addToEditor". */ addToEditorLabel?: string | undefined;
54
+ /**
55
+ * The language of the File Browser: a BCP 47 tag ("de", "pt-BR"). It sets the plural rules and how numbers, dates and
56
+ * file sizes are written. Default "en". The words themselves come from `messages`.
57
+ */ locale?: string | undefined;
58
+ /**
59
+ * The page's own words: any of the keys of FILE_BROWSER_MESSAGES (see the README, "Languages"). A key left out keeps
60
+ * its English text. Can change while the File Browser is open.
61
+ */ messages?: MessageOverrides | null;
39
62
  /** When false, skips bundled demo tree (use with Widgetic upload config). */ useDemoContent?: boolean;
40
63
  /**
41
64
  * Opt-in Dexie L1 (`@widgetic/cache-layer`). Default false.
@@ -44,6 +67,7 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
44
67
  */ enableLocalCache?: boolean;
45
68
  fetchFilesData?: () => Promise<any>;
46
69
  }, {
70
+ error: CustomEvent<any>;
47
71
  select: CustomEvent<any>;
48
72
  } & {
49
73
  [evt: string]: CustomEvent<any>;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  // Svelte imports
3
- import { onMount } from 'svelte';
3
+ import { onDestroy, onMount } from 'svelte';
4
4
  import { createEventDispatcher } from 'svelte';
5
5
  import { browser } from '$app/environment';
6
6
  const dispatch = createEventDispatcher();
@@ -26,6 +26,20 @@
26
26
  import { fileBrowserUploadConfig } from '../../stores/uploadApiStore';
27
27
  import { uploadToWidgeticApi } from '../../utils/widgeticUpload';
28
28
  import { getAssetUrl } from '../../utils/fileUtils';
29
+ import { useMediaLibraryContext } from '../../mediaLibrary/context';
30
+ import { MediaLibraryError, isCancellation } from '../../mediaLibrary/errors';
31
+ import { useI18n } from '../../i18n/context';
32
+ import { messageForVisitor } from '../../i18n/errors';
33
+ import { formatKilobytes } from '../../utils/fileUtils';
34
+ import { kindWord, splitAround } from '../../i18n/text';
35
+ import type { Translate } from '../../i18n/context';
36
+ import { translateEnglish } from '../../i18n/context';
37
+
38
+ // The host's media library, when the File Browser was given one. It then stores the files, instead of the
39
+ // Widgetic upload settings.
40
+ const { library } = useMediaLibraryContext();
41
+ // The language of the File Browser this uploader is part of.
42
+ const { t, locale } = useI18n();
29
43
 
30
44
  // Component props variables
31
45
  export let allowedTypes: string[] = [];
@@ -75,12 +89,13 @@
75
89
  let uploadInProgress = false;
76
90
 
77
91
  // Reactive variables
78
- $: allowedTypesText = formatAllowedTypesText(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
79
- $: tooltipTypesText = formatAllowedTypesForDisplay(filter);
92
+ $: allowedKinds = allowedKindsOf(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
93
+ $: tooltipTypesText = formatAllowedTypesForDisplay(filter, $t);
80
94
  $: acceptTypes = filter === 'all'
81
95
  ? Object.values(FILE_TYPES).flat().join(',')
82
96
  : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>].join(',');
83
- $: allowedTypesDisplayText = filter === 'all' ? 'any' : allowedTypesText;
97
+ // The kinds of file the uploader takes, as words in the visitor's language: "image, video", "any", "document".
98
+ $: allowedTypesDisplayText = kindsText(filter, allowedKinds, $t);
84
99
  $: showUploader = uploadItems.length === 0;
85
100
 
86
101
  // Calculate overall progress for all uploads
@@ -186,7 +201,7 @@
186
201
  isDraggingFolder = true;
187
202
  dragInvalid = true;
188
203
  setTimeout(() => {
189
- showToast('error', 'Folders cannot be uploaded');
204
+ showToast('error', $t('upload.foldersNotAllowed'));
190
205
  return;
191
206
  }, 0);
192
207
  return;
@@ -203,7 +218,7 @@
203
218
  isDraggingFolder = false;
204
219
  dragInvalid = true;
205
220
  setTimeout(() => {
206
- showToast('error', `Invalid file type. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.`);
221
+ showToast('error', $t('upload.invalidType', { types: allowedTypesDisplayText }));
207
222
  return;
208
223
  }, 0);
209
224
  return;
@@ -313,9 +328,9 @@
313
328
  const totalEstimatedMs = (elapsedMs / progress) * 100;
314
329
  const remainingMs = totalEstimatedMs - elapsedMs;
315
330
 
316
- if (remainingMs < 1000) return 'less than a second';
317
- if (remainingMs < 60000) return `${Math.round(remainingMs / 1000)} seconds`;
318
- return `${Math.round(remainingMs / 60000)} minutes`;
331
+ if (remainingMs < 1000) return $t('upload.time.lessThanSecond');
332
+ if (remainingMs < 60000) return $t('upload.time.seconds', { count: Math.round(remainingMs / 1000) });
333
+ return $t('upload.time.minutes', { count: Math.round(remainingMs / 60000) });
319
334
  }
320
335
 
321
336
  /**
@@ -371,7 +386,8 @@
371
386
  const fileExtension = '.' + normalizedFile.name.split('.').pop()?.toLowerCase();
372
387
  if (!acceptTypes.includes(fileExtension)) {
373
388
  console.error(`File type not allowed: ${normalizedFile.name}`);
374
- dispatch('error', { message: `File type not allowed: ${normalizedFile.name}. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.` });
389
+ // The message of an `error` event is for the page's developer: English, whatever the visitor's language.
390
+ dispatch('error', { message: `File type not allowed: ${normalizedFile.name}. Please use ${kindsText(filter, allowedKinds, translateEnglish)} files only.` });
375
391
  return;
376
392
  }
377
393
 
@@ -394,7 +410,7 @@
394
410
  status: 'uploading',
395
411
  previewUrl,
396
412
  controller,
397
- timeRemaining: 'calculating...'
413
+ timeRemaining: $t('upload.time.calculating')
398
414
  };
399
415
 
400
416
  // Add to the list of uploads
@@ -411,7 +427,32 @@
411
427
  const uploadConfig = get(fileBrowserUploadConfig);
412
428
  let response: { success: boolean; file?: any; error?: string };
413
429
 
414
- if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
430
+ if (library) {
431
+ // The host's media library stores the file. It reports progress as a number from 0 to 100, which is
432
+ // clamped here because the number comes from the host's code.
433
+ if (!library.upload) {
434
+ throw new MediaLibraryError('NOT_SUPPORTED', 'This media library does not accept uploads', { messageKey: 'libraryError.uploadNotAllowed' });
435
+ }
436
+ const storedFile = await library.upload({
437
+ file: normalizedFile,
438
+ signal: controller.signal,
439
+ onProgress: (reportedPercentage) => {
440
+ const percentage = Number.isFinite(reportedPercentage) ? Math.min(100, Math.max(0, reportedPercentage)) : 0;
441
+ const timeRemaining = estimateTimeRemaining(normalizedFile, percentage, startTime);
442
+ uploadItems = uploadItems.map((item) =>
443
+ item.id === uploadId
444
+ ? { ...item, progress: percentage, timeRemaining }
445
+ : item,
446
+ );
447
+ },
448
+ });
449
+ // A library that finishes after the visitor cancelled (or after the File Browser closed) has stored the
450
+ // file, but this screen no longer waits for it: it is not added to the list.
451
+ if (controller.signal.aborted) {
452
+ throw new MediaLibraryError('ABORTED', 'The upload was cancelled');
453
+ }
454
+ response = { success: true, file: storedFile };
455
+ } else if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
415
456
  if (showLogs) {
416
457
  // console.log('[FileUploader] Widgetic upload:', file.name, uploadConfig.contextType);
417
458
  }
@@ -506,6 +547,13 @@
506
547
  });
507
548
  }
508
549
  } catch (error) {
550
+ // A cancelled upload (the visitor pressed Cancel, which already removed its row, or the File Browser was
551
+ // closed) is not a failure: nothing to show and no error to report.
552
+ if (isCancellation(error)) {
553
+ if (showLogs) console.log(`Upload of ${file.name} was cancelled`);
554
+ return;
555
+ }
556
+
509
557
  console.error('Upload failed:', error);
510
558
 
511
559
  // Update the upload item with error status
@@ -515,13 +563,15 @@
515
563
  ...item,
516
564
  status: 'failed',
517
565
  progress: 0,
518
- errorMessage: error instanceof Error ? error.message : 'Unknown error',
566
+ errorMessage: messageForVisitor(error, $t, 'upload.unknownError'),
519
567
  }
520
568
  : item
521
569
  );
522
570
 
523
571
  dispatch('error', {
524
572
  message: error instanceof Error ? error.message : 'Unknown error',
573
+ // Which kind of failure it was, when a media library said (so the host can tell "not allowed" from "offline")
574
+ code: error instanceof MediaLibraryError ? error.code : undefined,
525
575
  file: file.name
526
576
  });
527
577
  } finally {
@@ -557,7 +607,7 @@
557
607
  const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
558
608
  if (!acceptTypes.includes(fileExtension)) {
559
609
  console.error(`File type not allowed: ${file.name}`);
560
- dispatch('error', { message: `File type not allowed: ${file.name}. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.` });
610
+ dispatch('error', { message: `File type not allowed: ${file.name}. Please use ${kindsText(filter, allowedKinds, translateEnglish)} files only.` });
561
611
  continue;
562
612
  }
563
613
 
@@ -574,8 +624,8 @@
574
624
  // Show a toast for skipped files if any
575
625
  if (skippedFiles.length > 0) {
576
626
  const message = skippedFiles.length === 1
577
- ? `Skipped duplicate file: ${skippedFiles[0]}`
578
- : `Skipped ${skippedFiles.length} duplicate files`;
627
+ ? $t('upload.skippedOne', { name: skippedFiles[0] })
628
+ : $t('upload.skippedMany', { count: skippedFiles.length });
579
629
 
580
630
  showToast('warning', message);
581
631
  }
@@ -653,8 +703,9 @@
653
703
  showHelp = false;
654
704
  }
655
705
 
656
- function formatAllowedTypesText(types: string[]): string {
657
- if (!types.length || filter === 'all') return 'any';
706
+ /** The names of the kinds of file in a list of extensions: ["image", "video"]. An extension that fits no kind stays as it is. */
707
+ function allowedKindsOf(types: string[]): string[] {
708
+ if (!types.length || filter === 'all') return ['any'];
658
709
 
659
710
  // Check if we have only SVG files
660
711
  const hasSvgOnly = types.every(type => {
@@ -662,7 +713,7 @@
662
713
  return cleanType === 'svg';
663
714
  });
664
715
 
665
- if (hasSvgOnly) return 'SVG';
716
+ if (hasSvgOnly) return ['svg'];
666
717
 
667
718
  // Check if we have only document files
668
719
  const hasDocumentsOnly = types.every(type => {
@@ -670,13 +721,13 @@
670
721
  return ['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType);
671
722
  });
672
723
 
673
- if (hasDocumentsOnly) return 'document';
724
+ if (hasDocumentsOnly) return ['document'];
674
725
 
675
726
  // Map file extensions to their categories
676
727
  const typeCategories = new Set(types.map(type => {
677
728
  const cleanType = type.replace('.', '').toLowerCase();
678
729
  if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(cleanType)) return 'image';
679
- if (cleanType === 'svg') return 'SVG';
730
+ if (cleanType === 'svg') return 'svg';
680
731
  if (['mp4', 'webm', 'mov'].includes(cleanType)) return 'video';
681
732
  if (['mp3', 'wav', 'ogg'].includes(cleanType)) return 'audio';
682
733
  if (['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType)) return 'document';
@@ -684,7 +735,13 @@
684
735
  return cleanType;
685
736
  }));
686
737
 
687
- return Array.from(typeCategories).join(', ');
738
+ return Array.from(typeCategories);
739
+ }
740
+
741
+ /** The kinds of file the uploader takes, as one phrase: "image, video", "any" or "document". */
742
+ function kindsText(forFilter: FileFilterType, kinds: string[], translate: Translate): string {
743
+ const shown = forFilter === 'all' ? ['any'] : forFilter === 'document' ? ['document'] : kinds;
744
+ return shown.map((kind) => kindWord(kind, translate)).join(translate('list.separator'));
688
745
  }
689
746
 
690
747
  // Function to retry all failed uploads
@@ -783,6 +840,15 @@
783
840
  };
784
841
  }
785
842
  });
843
+
844
+ // With a host's media library the File Browser is a picker that comes and goes on the host's page: files still
845
+ // being sent when it closes are stopped, so a closed picker does not keep uploading.
846
+ onDestroy(() => {
847
+ if (!library) return;
848
+ for (const item of uploadItems) {
849
+ if (item.status === 'uploading') item.controller?.abort();
850
+ }
851
+ });
786
852
  </script>
787
853
 
788
854
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -840,28 +906,30 @@
840
906
 
841
907
  <div class="upload-zone w-full h-full inset-0 flex flex-col items-center justify-center p-4 space-y-2 text-center">
842
908
  {#if uploading && uploadItems.length === 0}
843
- <div class="caption text-[hsl(var(--grey3))]">Uploading...</div>
909
+ <div class="caption text-[hsl(var(--grey3))]">{$t('upload.uploading')}</div>
844
910
  {:else if dragActive && dragInvalid}
845
911
  {#if isDraggingFolder}
846
912
  <div class="caption text-[hsl(var(--error))]">
847
- Folders cannot be uploaded
913
+ {$t('upload.foldersNotAllowed')}
848
914
  </div>
849
915
  {:else}
850
916
  <div class="caption text-[hsl(var(--error))]">
851
- Invalid file type. Please use {filter === 'document' ? 'document' : allowedTypesDisplayText} files only.
917
+ {$t('upload.invalidType', { types: allowedTypesDisplayText })}
852
918
  </div>
853
919
  {/if}
854
920
  {:else if dragActive && hasValidFiles}
855
921
  <div class="caption text-[hsl(var(--sage-green))]">
856
- Drop to upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
922
+ {$t('upload.dropActive', { types: allowedTypesDisplayText })}
857
923
  </div>
858
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'))}
859
927
  <!-- Small screen version with clickable text -->
860
928
  <button
861
929
  class="caption text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors"
862
930
  onclick={() => fileInput.click()}
863
931
  >
864
- <span class="underline">Upload</span> or drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
932
+ {compactSentence.before}{#if compactSentence.link}<span class="underline">{compactSentence.link}</span>{/if}{compactSentence.after}
865
933
  </button>
866
934
  {:else}
867
935
  <Button
@@ -869,10 +937,10 @@
869
937
  class="btn-secondary rounded-small widgetic-radius focus:outline-none focus-visible:outline-none focus:ring-0 focus-visible:ring-0 hover:border-[hsl(var(--light-green))] transition-colors file-uploader-button"
870
938
  onclick={() => fileInput.click()}
871
939
  >
872
- Upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
940
+ {$t('upload.button', { types: allowedTypesDisplayText })}
873
941
  </Button>
874
942
  <div class="caption text-[hsl(var(--grey3))]">
875
- or drag and drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
943
+ {$t('upload.dragHint', { types: allowedTypesDisplayText })}
876
944
  </div>
877
945
  {/if}
878
946
  </div>
@@ -901,12 +969,12 @@
901
969
  <!-- Header with toggle -->
902
970
  <div class="uploads-header flex flex-row items-center justify-between p-4">
903
971
  <div class="uploads-header-content">
904
- <h3 class="body-medium text-[hsl(var(--grey7))]">File Upload Progress</h3>
972
+ <h3 class="body-medium text-[hsl(var(--grey7))]">{$t('upload.panelTitle')}</h3>
905
973
  <p class="subtext text-[hsl(var(--grey5))]">
906
- {uploadItems.filter(item => item.status === 'complete').length}/{uploadItems.length} files uploaded
974
+ {$t('upload.progress', { done: uploadItems.filter(item => item.status === 'complete').length, total: uploadItems.length })}
907
975
  {#if uploadItems.filter(item => item.status === 'failed').length > 0}
908
976
  <span class="ml-2 caption text-[hsl(var(--error))]">
909
- {uploadItems.filter(item => item.status === 'failed').length} failed
977
+ {$t('upload.failedCount', { count: uploadItems.filter(item => item.status === 'failed').length })}
910
978
  </span>
911
979
  {/if}
912
980
  </p>
@@ -924,7 +992,7 @@
924
992
  onmouseenter={handleCollapseMouseEnter}
925
993
  onmousemove={handleMouseMove}
926
994
  onmouseleave={handleCollapseMouseLeave}
927
- aria-label={isUploadsDrawerCollapsed ? "Expand panel" : "Collapse panel"}
995
+ aria-label={isUploadsDrawerCollapsed ? $t('upload.expandPanel') : $t('upload.collapsePanel')}
928
996
  >
929
997
  {#if isUploadsDrawerCollapsed}
930
998
  <IconChevronUp class="h-5 w-5" />
@@ -939,7 +1007,7 @@
939
1007
  class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
940
1008
  style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
941
1009
  >
942
- <p class="caption text-white">{isUploadsDrawerCollapsed ? "Expand uploader" : "Collapse uploader"}</p>
1010
+ <p class="caption text-white">{isUploadsDrawerCollapsed ? $t('upload.expandUploader') : $t('upload.collapseUploader')}</p>
943
1011
  </Tooltip.Content>
944
1012
  </Tooltip.Root>
945
1013
  </Tooltip.Provider>
@@ -954,7 +1022,7 @@
954
1022
  onmouseenter={handleCloseMouseEnter}
955
1023
  onmousemove={handleMouseMove}
956
1024
  onmouseleave={handleCloseMouseLeave}
957
- aria-label="Close uploader"
1025
+ aria-label={$t('upload.closeUploader')}
958
1026
  >
959
1027
  <IconX class="h-5 w-5" />
960
1028
  </button>
@@ -965,7 +1033,7 @@
965
1033
  class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
966
1034
  style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
967
1035
  >
968
- <p class="caption text-white">Close uploader</p>
1036
+ <p class="caption text-white">{$t('upload.closeUploader')}</p>
969
1037
  </Tooltip.Content>
970
1038
  </Tooltip.Root>
971
1039
  </Tooltip.Provider>
@@ -995,7 +1063,7 @@
995
1063
  <div class="flex items-center justify-between">
996
1064
  <div class="flex items-center gap-3 truncate">
997
1065
  {#if item.previewUrl}
998
- <img src={item.previewUrl} alt="Preview" class="w-[62px] h-[54px] object-cover rounded-large" />
1066
+ <img src={item.previewUrl} alt={$t('action.preview')} class="w-[62px] h-[54px] object-cover rounded-large" />
999
1067
  {:else}
1000
1068
  <div class="w-[62px] h-[54px] bg-[hsl(var(--grey1))] rounded-large flex items-center justify-center">
1001
1069
  <span class="text-xs">{item.file.name.split('.').pop()?.toUpperCase()}</span>
@@ -1003,7 +1071,7 @@
1003
1071
  {/if}
1004
1072
  <div class="flex flex-col">
1005
1073
  <span class="body-medium truncate {item.status === 'failed' ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{item.file.name}</span>
1006
- <span class="subtext truncate text-[hsl(var(--grey5))]">{(item.file.size / 1024).toFixed(1)} KB</span>
1074
+ <span class="subtext truncate text-[hsl(var(--grey5))]">{formatKilobytes(item.file.size, $t, $locale)}</span>
1007
1075
  </div>
1008
1076
  </div>
1009
1077
 
@@ -1011,7 +1079,7 @@
1011
1079
  <button
1012
1080
  class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors"
1013
1081
  onclick={() => handleCancelUpload(item.id)}
1014
- aria-label="Cancel upload"
1082
+ aria-label={$t('upload.cancel')}
1015
1083
  >
1016
1084
  <IconX class="h-4 w-4" />
1017
1085
  </button>
@@ -1019,7 +1087,7 @@
1019
1087
  <!-- Refresh button moved to error message section -->
1020
1088
  {:else}
1021
1089
  <div class="rounded-full w-5 h-5 bg-[hsl(var(--sage-green))] flex items-center justify-center">
1022
- <img src={getAssetUrl('/icons/checked.svg')} alt="Completed" class="w-5 h-5" />
1090
+ <img src={getAssetUrl('/icons/checked.svg')} alt={$t('upload.completedAlt')} class="w-5 h-5" />
1023
1091
  </div>
1024
1092
  {/if}
1025
1093
  </div>
@@ -1041,13 +1109,14 @@
1041
1109
  </div>
1042
1110
  {:else if item.status === 'failed'}
1043
1111
  <div class="flex items-center justify-between">
1044
- <p class="caption text-[hsl(var(--error))]">
1045
- Network error
1112
+ <!-- A media library says why its upload failed ("File too large", "Not allowed"...); Widgetic uploads keep the generic text -->
1113
+ <p class="caption min-w-0 break-words text-[hsl(var(--error))]">
1114
+ {library ? (item.errorMessage || $t('libraryError.uploadFailed')) : $t('upload.networkError')}
1046
1115
  </p>
1047
1116
  <button
1048
1117
  class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors flex items-center justify-center w-5 h-5"
1049
1118
  onclick={() => handleRetryUpload(item.id)}
1050
- aria-label="Retry upload"
1119
+ aria-label={$t('upload.retry')}
1051
1120
  >
1052
1121
  <IconRefresh class="h-5 w-5" />
1053
1122
  </button>
@@ -1068,7 +1137,7 @@
1068
1137
  class="retry-failed-uploads-btn body-medium text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors underline"
1069
1138
  onclick={retryAllFailedUploads}
1070
1139
  >
1071
- Retry failed uploads?
1140
+ {$t('upload.retryFailed')}
1072
1141
  </button>
1073
1142
  {/if}
1074
1143
 
@@ -1078,7 +1147,7 @@
1078
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"
1079
1148
  onclick={clearCompletedUploads}
1080
1149
  >
1081
- Clear completed uploads
1150
+ {$t('upload.clearCompleted')}
1082
1151
  </button>
1083
1152
  {/if}
1084
1153
 
@@ -9,6 +9,7 @@
9
9
 
10
10
  // Local stores imports
11
11
  import { fileStore } from '../../stores/fileStore';
12
+ import { useI18n } from '../../i18n';
12
13
 
13
14
  // Props with proper types
14
15
  let className = '';
@@ -23,6 +24,8 @@
23
24
  export let isLoading: boolean = false;
24
25
  export let currentPathNames: string[] = [];
25
26
  export let showBreadcrumbs: boolean = true;
27
+ /** Shown in place of the breadcrumbs when they are hidden (a library without folders has nowhere to navigate). */
28
+ export let title: string = '';
26
29
  //
27
30
  export let headerEl: any = null;
28
31
 
@@ -36,6 +39,8 @@
36
39
  }
37
40
  const dispatch = createEventDispatcher<Events>();
38
41
 
42
+ const { t } = useI18n();
43
+
39
44
  function handleNavigate(index: number): void {
40
45
  if (index === currentPath.length - 1) {
41
46
  // console.log('Already at this path level, skipping navigation');
@@ -86,7 +91,13 @@
86
91
  {onNavigate}
87
92
  {onBack}
88
93
  {onForward}
94
+ backLabel={$t('breadcrumbs.back')}
95
+ forwardLabel={$t('breadcrumbs.forward')}
96
+ rootLabel={$t('breadcrumbs.root')}
97
+ breadcrumbLabel={$t('breadcrumbs.label')}
89
98
  />
99
+ {:else if title}
100
+ <span class="header-title h6 block truncate text-[hsl(var(--grey7))]">{title}</span>
90
101
  {/if}
91
102
  </div>
92
103
 
@@ -121,7 +132,7 @@
121
132
  </Tooltip.Trigger>
122
133
  {#if showSelectedFilesTooltip}
123
134
  <Tooltip.Content side="bottom" sideOffset={6} class="bg-[hsl(var(--dark))] text-white caption px-2 py-1 rounded-md z-[200000]">
124
- Selected files
135
+ {$t('selectedFiles.title')}
125
136
  </Tooltip.Content>
126
137
  {/if}
127
138
  </Tooltip.Root>
@@ -22,6 +22,7 @@ declare const Header: $$__sveltets_2_IsomorphicComponent<{
22
22
  isLoading?: boolean;
23
23
  currentPathNames?: string[];
24
24
  showBreadcrumbs?: boolean;
25
+ /** Shown in place of the breadcrumbs when they are hidden (a library without folders has nowhere to navigate). */ title?: string;
25
26
  headerEl?: any;
26
27
  }, {
27
28
  search: CustomEvent<void>;