@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.
Files changed (97) hide show
  1. package/README.md +279 -0
  2. package/dist/components/FolderTree.svelte +16 -9
  3. package/dist/components/FolderTree.svelte.d.ts +2 -6
  4. package/dist/components/core/FileBrowser.svelte +529 -127
  5. package/dist/components/core/FileBrowser.svelte.d.ts +40 -1
  6. package/dist/components/core/FileUploader.svelte +130 -57
  7. package/dist/components/core/Header.svelte +13 -2
  8. package/dist/components/core/Header.svelte.d.ts +1 -0
  9. package/dist/components/core/RecentFiles.svelte +41 -29
  10. package/dist/components/core/UploadStatus.svelte +14 -7
  11. package/dist/components/core/UploadStatusList.svelte +13 -21
  12. package/dist/components/items/FileItem.svelte +28 -15
  13. package/dist/components/items/FolderItem.svelte +13 -6
  14. package/dist/components/modals/MoveDialog.svelte +49 -38
  15. package/dist/components/modals/NewFolderButton.svelte +5 -2
  16. package/dist/components/modals/SearchModal.svelte +25 -26
  17. package/dist/components/modals/SearchModal.svelte.d.ts +1 -1
  18. package/dist/components/modals/SelectedFilesModal.svelte +23 -14
  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 +25 -9
  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 +11 -7
  28. package/dist/components/ui/ControlToolbar.svelte +50 -28
  29. package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
  30. package/dist/components/ui/DragSelect.svelte +3 -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 +16 -15
  35. package/dist/components/ui/SearchResults.svelte +9 -2
  36. package/dist/i18n/context.d.ts +28 -0
  37. package/dist/i18n/context.js +17 -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 +15 -0
  41. package/dist/i18n/index.js +18 -0
  42. package/dist/i18n/messages.d.ts +281 -0
  43. package/dist/i18n/messages.js +294 -0
  44. package/dist/i18n/text.d.ts +19 -0
  45. package/dist/i18n/text.js +35 -0
  46. package/dist/index.d.ts +3 -0
  47. package/dist/index.js +4 -0
  48. package/dist/mediaLibrary/capabilities.d.ts +22 -0
  49. package/dist/mediaLibrary/capabilities.js +42 -0
  50. package/dist/mediaLibrary/context.d.ts +17 -0
  51. package/dist/mediaLibrary/context.js +16 -0
  52. package/dist/mediaLibrary/errors.d.ts +42 -0
  53. package/dist/mediaLibrary/errors.js +114 -0
  54. package/dist/mediaLibrary/index.d.ts +10 -0
  55. package/dist/mediaLibrary/index.js +9 -0
  56. package/dist/mediaLibrary/normalize.d.ts +39 -0
  57. package/dist/mediaLibrary/normalize.js +139 -0
  58. package/dist/mediaLibrary/paging.d.ts +37 -0
  59. package/dist/mediaLibrary/paging.js +62 -0
  60. package/dist/mediaLibrary/resolve.d.ts +39 -0
  61. package/dist/mediaLibrary/resolve.js +137 -0
  62. package/dist/mediaLibrary/treeOps.d.ts +24 -0
  63. package/dist/mediaLibrary/treeOps.js +67 -0
  64. package/dist/mediaLibrary/types.d.ts +126 -0
  65. package/dist/mediaLibrary/types.js +11 -0
  66. package/dist/mediaLibrary/urls.d.ts +30 -0
  67. package/dist/mediaLibrary/urls.js +59 -0
  68. package/dist/mediaLibrary/widgetic.d.ts +39 -0
  69. package/dist/mediaLibrary/widgetic.js +89 -0
  70. package/dist/stores/fileStore.d.ts +2 -2
  71. package/dist/stores/folderCountStore.js +2 -2
  72. package/dist/stores/navigationStore.d.ts +1 -1
  73. package/dist/stores/persistentSelectStore.d.ts +11 -1
  74. package/dist/stores/persistentSelectStore.js +26 -0
  75. package/dist/utils/dateUtils.d.ts +11 -2
  76. package/dist/utils/dateUtils.js +20 -15
  77. package/dist/utils/fileKinds.d.ts +44 -0
  78. package/dist/utils/fileKinds.js +96 -0
  79. package/dist/utils/fileNames.d.ts +7 -0
  80. package/dist/utils/fileNames.js +19 -0
  81. package/dist/utils/fileOperations.js +2 -11
  82. package/dist/utils/fileTypes.d.ts +11 -2
  83. package/dist/utils/fileTypes.js +26 -14
  84. package/dist/utils/fileUtils.d.ts +8 -1
  85. package/dist/utils/fileUtils.js +22 -7
  86. package/dist/utils/folderUtils.js +3 -2
  87. package/dist/utils/previewKeys.d.ts +12 -0
  88. package/dist/utils/previewKeys.js +14 -0
  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 +5 -2
@@ -1,6 +1,9 @@
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 '@widgetic/design-system/i18n';
6
+ import { type TextDirection } from '@widgetic/design-system/components/textDirection';
4
7
  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
8
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
9
  $$bindings?: Bindings;
@@ -18,6 +21,19 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
18
21
  /**
19
22
  * COMPONENT PROPS
20
23
  */ data?: any;
24
+ /**
25
+ * The host's own media library (a `MediaLibraryProvider`): plain functions the File Browser calls to list, upload,
26
+ * rename and delete the host's files. When given, the File Browser shows that one flat library instead of the
27
+ * Widgetic uploads or the demo content, and stores nothing about it on this device (no local cache, no saved
28
+ * tree, no saved selection unless `persistSelection` says so).
29
+ *
30
+ * Read once, when the File Browser is created: to show another library, create a new File Browser.
31
+ */ mediaLibrary?: MediaLibraryProvider | null;
32
+ /**
33
+ * Whether the picked files are remembered in this browser's localStorage between visits. Default: yes, as always,
34
+ * except with a `mediaLibrary` (a shared browser must not show the next visitor the previous one's picks).
35
+ * This is a setting of the page: when two File Browsers disagree, the last one created wins.
36
+ */ persistSelection?: boolean | undefined;
21
37
  class?: string;
22
38
  style?: string;
23
39
  basePath?: string;
@@ -35,7 +51,29 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
35
51
  maxSelections?: number | null;
36
52
  /** When set (single-file picker), disables confirm until user picks a different file. */ activeFileId?: string | null;
37
53
  showAddToEditor?: boolean;
38
- addToEditorLabel?: string;
54
+ /** The text of the button that hands the picked files to the page. Default: the message "action.addToEditor". */ addToEditorLabel?: string | undefined;
55
+ /**
56
+ * The language of the File Browser: a BCP 47 tag ("de", "pt-BR"). It sets the plural rules and how numbers, dates and
57
+ * file sizes are written. Default "en". The words themselves come from `messages`.
58
+ */ locale?: string | undefined;
59
+ /**
60
+ * The page's own words: any of the keys of FILE_BROWSER_MESSAGES (see the README, "Languages"). A key left out keeps
61
+ * its English text. Can change while the File Browser is open.
62
+ */ messages?: MessageOverrides | null;
63
+ /**
64
+ * Which way the File Browser is read: "ltr" or "rtl". The page that puts it on screen sets `dir` on an element
65
+ * around it, and the browser turns the layout around. This prop says the same to the parts that wrap a library that
66
+ * writes a `dir` of its own (the scroll areas, the menus, the toaster) and to the code that follows the reading
67
+ * direction (the arrow keys of the file preview). It is NOT worked out from `locale`: a File Browser inside an editor
68
+ * that is laid out left to right can speak Arabic and still be left to right. Left out, the File Browser is read the way
69
+ * the screen around it is (a File Browser inside the composition editor turns around with it, whatever the page's
70
+ * `locale`), and left to right when nothing around it says. Can change while the File Browser is open.
71
+ */ dir?: TextDirection | undefined;
72
+ /**
73
+ * Draws the pop-ups ("Folder created", "Rename failed" ...) itself, in the language of `locale` and `messages`. They are
74
+ * shown with the design system's `showToast`, which draws into a `<ToasterModal>`: leave this false when the app around
75
+ * the File Browser already renders one (the Widgetic site does, in its layout), true when nothing does.
76
+ */ renderToaster?: boolean;
39
77
  /** When false, skips bundled demo tree (use with Widgetic upload config). */ useDemoContent?: boolean;
40
78
  /**
41
79
  * Opt-in Dexie L1 (`@widgetic/cache-layer`). Default false.
@@ -44,6 +82,7 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
44
82
  */ enableLocalCache?: boolean;
45
83
  fetchFilesData?: () => Promise<any>;
46
84
  }, {
85
+ error: CustomEvent<any>;
47
86
  select: CustomEvent<any>;
48
87
  } & {
49
88
  [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,24 @@
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 { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
33
+ import { messageForVisitor } from '../../i18n/errors';
34
+ import { formatKilobytes } from '../../utils/fileUtils';
35
+ import { kindWord, splitAround } from '../../i18n/text';
36
+ import type { Translate } from '../../i18n/context';
37
+ import { translateEnglish } from '../../i18n/context';
38
+
39
+ // The host's media library, when the File Browser was given one. It then stores the files, instead of the
40
+ // Widgetic upload settings.
41
+ const { library } = useMediaLibraryContext();
42
+ // The language of the File Browser this uploader is part of.
43
+ const { t, locale } = useI18n();
44
+ // 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);
29
47
 
30
48
  // Component props variables
31
49
  export let allowedTypes: string[] = [];
@@ -75,12 +93,13 @@
75
93
  let uploadInProgress = false;
76
94
 
77
95
  // Reactive variables
78
- $: allowedTypesText = formatAllowedTypesText(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
79
- $: tooltipTypesText = formatAllowedTypesForDisplay(filter);
96
+ $: allowedKinds = allowedKindsOf(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
97
+ $: tooltipTypesText = formatAllowedTypesForDisplay(filter, $t);
80
98
  $: acceptTypes = filter === 'all'
81
99
  ? Object.values(FILE_TYPES).flat().join(',')
82
100
  : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>].join(',');
83
- $: allowedTypesDisplayText = filter === 'all' ? 'any' : allowedTypesText;
101
+ // The kinds of file the uploader takes, as words in the visitor's language: "image, video", "any", "document".
102
+ $: allowedTypesDisplayText = kindsText(filter, allowedKinds, $t);
84
103
  $: showUploader = uploadItems.length === 0;
85
104
 
86
105
  // Calculate overall progress for all uploads
@@ -186,7 +205,7 @@
186
205
  isDraggingFolder = true;
187
206
  dragInvalid = true;
188
207
  setTimeout(() => {
189
- showToast('error', 'Folders cannot be uploaded');
208
+ showToast('error', $t('upload.foldersNotAllowed'));
190
209
  return;
191
210
  }, 0);
192
211
  return;
@@ -203,7 +222,7 @@
203
222
  isDraggingFolder = false;
204
223
  dragInvalid = true;
205
224
  setTimeout(() => {
206
- showToast('error', `Invalid file type. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.`);
225
+ showToast('error', $t('upload.invalidType', { types: allowedTypesDisplayText }));
207
226
  return;
208
227
  }, 0);
209
228
  return;
@@ -313,9 +332,9 @@
313
332
  const totalEstimatedMs = (elapsedMs / progress) * 100;
314
333
  const remainingMs = totalEstimatedMs - elapsedMs;
315
334
 
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`;
335
+ if (remainingMs < 1000) return $t('upload.time.lessThanSecond');
336
+ if (remainingMs < 60000) return $t('upload.time.seconds', { count: Math.round(remainingMs / 1000) });
337
+ return $t('upload.time.minutes', { count: Math.round(remainingMs / 60000) });
319
338
  }
320
339
 
321
340
  /**
@@ -371,7 +390,8 @@
371
390
  const fileExtension = '.' + normalizedFile.name.split('.').pop()?.toLowerCase();
372
391
  if (!acceptTypes.includes(fileExtension)) {
373
392
  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.` });
393
+ // The message of an `error` event is for the page's developer: English, whatever the visitor's language.
394
+ dispatch('error', { message: `File type not allowed: ${normalizedFile.name}. Please use ${kindsText(filter, allowedKinds, translateEnglish)} files only.` });
375
395
  return;
376
396
  }
377
397
 
@@ -394,7 +414,7 @@
394
414
  status: 'uploading',
395
415
  previewUrl,
396
416
  controller,
397
- timeRemaining: 'calculating...'
417
+ timeRemaining: $t('upload.time.calculating')
398
418
  };
399
419
 
400
420
  // Add to the list of uploads
@@ -411,7 +431,32 @@
411
431
  const uploadConfig = get(fileBrowserUploadConfig);
412
432
  let response: { success: boolean; file?: any; error?: string };
413
433
 
414
- if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
434
+ if (library) {
435
+ // The host's media library stores the file. It reports progress as a number from 0 to 100, which is
436
+ // clamped here because the number comes from the host's code.
437
+ if (!library.upload) {
438
+ throw new MediaLibraryError('NOT_SUPPORTED', 'This media library does not accept uploads', { messageKey: 'libraryError.uploadNotAllowed' });
439
+ }
440
+ const storedFile = await library.upload({
441
+ file: normalizedFile,
442
+ signal: controller.signal,
443
+ onProgress: (reportedPercentage) => {
444
+ const percentage = Number.isFinite(reportedPercentage) ? Math.min(100, Math.max(0, reportedPercentage)) : 0;
445
+ const timeRemaining = estimateTimeRemaining(normalizedFile, percentage, startTime);
446
+ uploadItems = uploadItems.map((item) =>
447
+ item.id === uploadId
448
+ ? { ...item, progress: percentage, timeRemaining }
449
+ : item,
450
+ );
451
+ },
452
+ });
453
+ // A library that finishes after the visitor cancelled (or after the File Browser closed) has stored the
454
+ // file, but this screen no longer waits for it: it is not added to the list.
455
+ if (controller.signal.aborted) {
456
+ throw new MediaLibraryError('ABORTED', 'The upload was cancelled');
457
+ }
458
+ response = { success: true, file: storedFile };
459
+ } else if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
415
460
  if (showLogs) {
416
461
  // console.log('[FileUploader] Widgetic upload:', file.name, uploadConfig.contextType);
417
462
  }
@@ -506,6 +551,13 @@
506
551
  });
507
552
  }
508
553
  } catch (error) {
554
+ // A cancelled upload (the visitor pressed Cancel, which already removed its row, or the File Browser was
555
+ // closed) is not a failure: nothing to show and no error to report.
556
+ if (isCancellation(error)) {
557
+ if (showLogs) console.log(`Upload of ${file.name} was cancelled`);
558
+ return;
559
+ }
560
+
509
561
  console.error('Upload failed:', error);
510
562
 
511
563
  // Update the upload item with error status
@@ -515,13 +567,15 @@
515
567
  ...item,
516
568
  status: 'failed',
517
569
  progress: 0,
518
- errorMessage: error instanceof Error ? error.message : 'Unknown error',
570
+ errorMessage: messageForVisitor(error, $t, 'upload.unknownError'),
519
571
  }
520
572
  : item
521
573
  );
522
574
 
523
575
  dispatch('error', {
524
576
  message: error instanceof Error ? error.message : 'Unknown error',
577
+ // Which kind of failure it was, when a media library said (so the host can tell "not allowed" from "offline")
578
+ code: error instanceof MediaLibraryError ? error.code : undefined,
525
579
  file: file.name
526
580
  });
527
581
  } finally {
@@ -557,7 +611,7 @@
557
611
  const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
558
612
  if (!acceptTypes.includes(fileExtension)) {
559
613
  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.` });
614
+ dispatch('error', { message: `File type not allowed: ${file.name}. Please use ${kindsText(filter, allowedKinds, translateEnglish)} files only.` });
561
615
  continue;
562
616
  }
563
617
 
@@ -574,8 +628,8 @@
574
628
  // Show a toast for skipped files if any
575
629
  if (skippedFiles.length > 0) {
576
630
  const message = skippedFiles.length === 1
577
- ? `Skipped duplicate file: ${skippedFiles[0]}`
578
- : `Skipped ${skippedFiles.length} duplicate files`;
631
+ ? $t('upload.skippedOne', { name: skippedFiles[0] })
632
+ : $t('upload.skippedMany', { count: skippedFiles.length });
579
633
 
580
634
  showToast('warning', message);
581
635
  }
@@ -653,8 +707,9 @@
653
707
  showHelp = false;
654
708
  }
655
709
 
656
- function formatAllowedTypesText(types: string[]): string {
657
- if (!types.length || filter === 'all') return 'any';
710
+ /** The names of the kinds of file in a list of extensions: ["image", "video"]. An extension that fits no kind stays as it is. */
711
+ function allowedKindsOf(types: string[]): string[] {
712
+ if (!types.length || filter === 'all') return ['any'];
658
713
 
659
714
  // Check if we have only SVG files
660
715
  const hasSvgOnly = types.every(type => {
@@ -662,7 +717,7 @@
662
717
  return cleanType === 'svg';
663
718
  });
664
719
 
665
- if (hasSvgOnly) return 'SVG';
720
+ if (hasSvgOnly) return ['svg'];
666
721
 
667
722
  // Check if we have only document files
668
723
  const hasDocumentsOnly = types.every(type => {
@@ -670,13 +725,13 @@
670
725
  return ['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType);
671
726
  });
672
727
 
673
- if (hasDocumentsOnly) return 'document';
728
+ if (hasDocumentsOnly) return ['document'];
674
729
 
675
730
  // Map file extensions to their categories
676
731
  const typeCategories = new Set(types.map(type => {
677
732
  const cleanType = type.replace('.', '').toLowerCase();
678
733
  if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(cleanType)) return 'image';
679
- if (cleanType === 'svg') return 'SVG';
734
+ if (cleanType === 'svg') return 'svg';
680
735
  if (['mp4', 'webm', 'mov'].includes(cleanType)) return 'video';
681
736
  if (['mp3', 'wav', 'ogg'].includes(cleanType)) return 'audio';
682
737
  if (['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType)) return 'document';
@@ -684,7 +739,13 @@
684
739
  return cleanType;
685
740
  }));
686
741
 
687
- return Array.from(typeCategories).join(', ');
742
+ return Array.from(typeCategories);
743
+ }
744
+
745
+ /** The kinds of file the uploader takes, as one phrase: "image, video", "any" or "document". */
746
+ function kindsText(forFilter: FileFilterType, kinds: string[], translate: Translate): string {
747
+ const shown = forFilter === 'all' ? ['any'] : forFilter === 'document' ? ['document'] : kinds;
748
+ return shown.map((kind) => kindWord(kind, translate)).join(translate('list.separator'));
688
749
  }
689
750
 
690
751
  // Function to retry all failed uploads
@@ -783,6 +844,15 @@
783
844
  };
784
845
  }
785
846
  });
847
+
848
+ // With a host's media library the File Browser is a picker that comes and goes on the host's page: files still
849
+ // being sent when it closes are stopped, so a closed picker does not keep uploading.
850
+ onDestroy(() => {
851
+ if (!library) return;
852
+ for (const item of uploadItems) {
853
+ if (item.status === 'uploading') item.controller?.abort();
854
+ }
855
+ });
786
856
  </script>
787
857
 
788
858
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -791,7 +861,7 @@
791
861
  bind:this={uploaderRootEl}
792
862
  >
793
863
  <!-- Add help icon with tooltip -->
794
- <div class="help-icon-container absolute {isSmallScreen ? 'top-2 right-2' : 'top-4 right-4'} z-10">
864
+ <div class="help-icon-container absolute {isSmallScreen ? 'top-2 end-2' : 'top-4 end-4'} z-10">
795
865
  <Tooltip.Provider>
796
866
  <Tooltip.Root open={showHelp}>
797
867
  <Tooltip.Trigger class="focus:outline-none focus-visible:outline-none inline-block">
@@ -805,10 +875,10 @@
805
875
  </div>
806
876
  </Tooltip.Trigger>
807
877
  <Tooltip.Content
808
- side="left"
878
+ side={/* rtl-ok: the tooltip is put where the pointer is, by the style below */ 'left'}
809
879
  sideOffset={5}
810
880
  class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md max-w-[250px] whitespace-normal break-words"
811
- style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
881
+ 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 */"
812
882
  >
813
883
  <p class="caption text-white whitespace-pre-line">{tooltipTypesText}</p>
814
884
  </Tooltip.Content>
@@ -840,28 +910,30 @@
840
910
 
841
911
  <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
912
  {#if uploading && uploadItems.length === 0}
843
- <div class="caption text-[hsl(var(--grey3))]">Uploading...</div>
913
+ <div class="caption text-[hsl(var(--grey3))]">{$t('upload.uploading')}</div>
844
914
  {:else if dragActive && dragInvalid}
845
915
  {#if isDraggingFolder}
846
916
  <div class="caption text-[hsl(var(--error))]">
847
- Folders cannot be uploaded
917
+ {$t('upload.foldersNotAllowed')}
848
918
  </div>
849
919
  {:else}
850
920
  <div class="caption text-[hsl(var(--error))]">
851
- Invalid file type. Please use {filter === 'document' ? 'document' : allowedTypesDisplayText} files only.
921
+ {$t('upload.invalidType', { types: allowedTypesDisplayText })}
852
922
  </div>
853
923
  {/if}
854
924
  {:else if dragActive && hasValidFiles}
855
925
  <div class="caption text-[hsl(var(--sage-green))]">
856
- Drop to upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
926
+ {$t('upload.dropActive', { types: allowedTypesDisplayText })}
857
927
  </div>
858
928
  {:else if isSmallScreen}
929
+ <!-- The sentence, with the words of it that act as the link underlined (wherever the language puts them) -->
930
+ {@const compactSentence = splitAround($t('upload.chooseOrDrop', { types: allowedTypesDisplayText }), $t('upload.chooseOrDropLink'))}
859
931
  <!-- Small screen version with clickable text -->
860
932
  <button
861
933
  class="caption text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors"
862
934
  onclick={() => fileInput.click()}
863
935
  >
864
- <span class="underline">Upload</span> or drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
936
+ {compactSentence.before}{#if compactSentence.link}<span class="underline">{compactSentence.link}</span>{/if}{compactSentence.after}
865
937
  </button>
866
938
  {:else}
867
939
  <Button
@@ -869,10 +941,10 @@
869
941
  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
942
  onclick={() => fileInput.click()}
871
943
  >
872
- Upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
944
+ {$t('upload.button', { types: allowedTypesDisplayText })}
873
945
  </Button>
874
946
  <div class="caption text-[hsl(var(--grey3))]">
875
- or drag and drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
947
+ {$t('upload.dragHint', { types: allowedTypesDisplayText })}
876
948
  </div>
877
949
  {/if}
878
950
  </div>
@@ -895,18 +967,18 @@
895
967
 
896
968
  <!-- Uploads Drawer -->
897
969
  <div
898
- class="uploads-drawer absolute bottom-0 left-0 right-0 bg-white transition-all duration-300 z-[9990] flex flex-col rounded-t-large widgetic-radius modal-shadow"
970
+ 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"
899
971
  style="max-height: 80vh; transform: translateY({isUploadsDrawerCollapsed ? 'calc(100% - 70px)' : '0'}); border: 1px solid hsl(var(--forest-green)); border-bottom: none;"
900
972
  >
901
973
  <!-- Header with toggle -->
902
974
  <div class="uploads-header flex flex-row items-center justify-between p-4">
903
975
  <div class="uploads-header-content">
904
- <h3 class="body-medium text-[hsl(var(--grey7))]">File Upload Progress</h3>
976
+ <h3 class="body-medium text-[hsl(var(--grey7))]">{$t('upload.panelTitle')}</h3>
905
977
  <p class="subtext text-[hsl(var(--grey5))]">
906
- {uploadItems.filter(item => item.status === 'complete').length}/{uploadItems.length} files uploaded
978
+ {$t('upload.progress', { done: uploadItems.filter(item => item.status === 'complete').length, total: uploadItems.length })}
907
979
  {#if uploadItems.filter(item => item.status === 'failed').length > 0}
908
- <span class="ml-2 caption text-[hsl(var(--error))]">
909
- {uploadItems.filter(item => item.status === 'failed').length} failed
980
+ <span class="ms-2 caption text-[hsl(var(--error))]">
981
+ {$t('upload.failedCount', { count: uploadItems.filter(item => item.status === 'failed').length })}
910
982
  </span>
911
983
  {/if}
912
984
  </p>
@@ -924,7 +996,7 @@
924
996
  onmouseenter={handleCollapseMouseEnter}
925
997
  onmousemove={handleMouseMove}
926
998
  onmouseleave={handleCollapseMouseLeave}
927
- aria-label={isUploadsDrawerCollapsed ? "Expand panel" : "Collapse panel"}
999
+ aria-label={isUploadsDrawerCollapsed ? $t('upload.expandPanel') : $t('upload.collapsePanel')}
928
1000
  >
929
1001
  {#if isUploadsDrawerCollapsed}
930
1002
  <IconChevronUp class="h-5 w-5" />
@@ -934,12 +1006,12 @@
934
1006
  </button>
935
1007
  </Tooltip.Trigger>
936
1008
  <Tooltip.Content
937
- side="left"
1009
+ side={/* rtl-ok: the tooltip is put where the pointer is, by the style below */ 'left'}
938
1010
  sideOffset={5}
939
1011
  class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
940
- style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
1012
+ 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 */"
941
1013
  >
942
- <p class="caption text-white">{isUploadsDrawerCollapsed ? "Expand uploader" : "Collapse uploader"}</p>
1014
+ <p class="caption text-white">{isUploadsDrawerCollapsed ? $t('upload.expandUploader') : $t('upload.collapseUploader')}</p>
943
1015
  </Tooltip.Content>
944
1016
  </Tooltip.Root>
945
1017
  </Tooltip.Provider>
@@ -954,18 +1026,18 @@
954
1026
  onmouseenter={handleCloseMouseEnter}
955
1027
  onmousemove={handleMouseMove}
956
1028
  onmouseleave={handleCloseMouseLeave}
957
- aria-label="Close uploader"
1029
+ aria-label={$t('upload.closeUploader')}
958
1030
  >
959
1031
  <IconX class="h-5 w-5" />
960
1032
  </button>
961
1033
  </Tooltip.Trigger>
962
1034
  <Tooltip.Content
963
- side="left"
1035
+ side={/* rtl-ok: the tooltip is put where the pointer is, by the style below */ 'left'}
964
1036
  sideOffset={5}
965
1037
  class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
966
- style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
1038
+ 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 */"
967
1039
  >
968
- <p class="caption text-white">Close uploader</p>
1040
+ <p class="caption text-white">{$t('upload.closeUploader')}</p>
969
1041
  </Tooltip.Content>
970
1042
  </Tooltip.Root>
971
1043
  </Tooltip.Provider>
@@ -995,15 +1067,15 @@
995
1067
  <div class="flex items-center justify-between">
996
1068
  <div class="flex items-center gap-3 truncate">
997
1069
  {#if item.previewUrl}
998
- <img src={item.previewUrl} alt="Preview" class="w-[62px] h-[54px] object-cover rounded-large" />
1070
+ <img src={item.previewUrl} alt={$t('action.preview')} class="w-[62px] h-[54px] object-cover rounded-large" />
999
1071
  {:else}
1000
1072
  <div class="w-[62px] h-[54px] bg-[hsl(var(--grey1))] rounded-large flex items-center justify-center">
1001
1073
  <span class="text-xs">{item.file.name.split('.').pop()?.toUpperCase()}</span>
1002
1074
  </div>
1003
1075
  {/if}
1004
1076
  <div class="flex flex-col">
1005
- <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>
1077
+ <span dir={nameDirection} class="body-medium truncate {item.status === 'failed' ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{item.file.name}</span>
1078
+ <span class="subtext truncate text-[hsl(var(--grey5))]">{formatKilobytes(item.file.size, $t, $locale)}</span>
1007
1079
  </div>
1008
1080
  </div>
1009
1081
 
@@ -1011,7 +1083,7 @@
1011
1083
  <button
1012
1084
  class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors"
1013
1085
  onclick={() => handleCancelUpload(item.id)}
1014
- aria-label="Cancel upload"
1086
+ aria-label={$t('upload.cancel')}
1015
1087
  >
1016
1088
  <IconX class="h-4 w-4" />
1017
1089
  </button>
@@ -1019,7 +1091,7 @@
1019
1091
  <!-- Refresh button moved to error message section -->
1020
1092
  {:else}
1021
1093
  <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" />
1094
+ <img src={getAssetUrl('/icons/checked.svg')} alt={$t('upload.completedAlt')} class="w-5 h-5" />
1023
1095
  </div>
1024
1096
  {/if}
1025
1097
  </div>
@@ -1041,13 +1113,14 @@
1041
1113
  </div>
1042
1114
  {:else if item.status === 'failed'}
1043
1115
  <div class="flex items-center justify-between">
1044
- <p class="caption text-[hsl(var(--error))]">
1045
- Network error
1116
+ <!-- A media library says why its upload failed ("File too large", "Not allowed"...); Widgetic uploads keep the generic text -->
1117
+ <p class="caption min-w-0 break-words text-[hsl(var(--error))]">
1118
+ {library ? (item.errorMessage || $t('libraryError.uploadFailed')) : $t('upload.networkError')}
1046
1119
  </p>
1047
1120
  <button
1048
1121
  class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors flex items-center justify-center w-5 h-5"
1049
1122
  onclick={() => handleRetryUpload(item.id)}
1050
- aria-label="Retry upload"
1123
+ aria-label={$t('upload.retry')}
1051
1124
  >
1052
1125
  <IconRefresh class="h-5 w-5" />
1053
1126
  </button>
@@ -1068,7 +1141,7 @@
1068
1141
  class="retry-failed-uploads-btn body-medium text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors underline"
1069
1142
  onclick={retryAllFailedUploads}
1070
1143
  >
1071
- Retry failed uploads?
1144
+ {$t('upload.retryFailed')}
1072
1145
  </button>
1073
1146
  {/if}
1074
1147
 
@@ -1078,7 +1151,7 @@
1078
1151
  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
1152
  onclick={clearCompletedUploads}
1080
1153
  >
1081
- Clear completed uploads
1154
+ {$t('upload.clearCompleted')}
1082
1155
  </button>
1083
1156
  {/if}
1084
1157
 
@@ -1138,8 +1211,8 @@
1138
1211
  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
1139
1212
  display: flex;
1140
1213
  flex-direction: column;
1141
- border-top-left-radius: var(--radius-large);
1142
- border-top-right-radius: var(--radius-large);
1214
+ border-start-start-radius: var(--radius-large);
1215
+ border-start-end-radius: var(--radius-large);
1143
1216
  }
1144
1217
 
1145
1218
  /* Fix footer position */
@@ -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
 
@@ -111,7 +122,7 @@
111
122
  />
112
123
  {#if selectedFilesCount > 0}
113
124
  <div
114
- class="absolute top-[-8px] left-[-8px] h-5 rounded-full bg-[hsl(var(--deep-forest-green))] flex items-center justify-center z-10"
125
+ class="absolute top-[-8px] start-[-8px] h-5 rounded-full bg-[hsl(var(--deep-forest-green))] flex items-center justify-center z-10"
115
126
  style="min-width: 20px; padding: 0 4px;"
116
127
  >
117
128
  <span class="h6 text-white leading-none mx-[1px]">{selectedFilesCount}</span>
@@ -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>;