@widgetic/file-browser 0.5.47 → 0.5.48

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 (102) hide show
  1. package/dist/actions/dragSelectedToFolder.js +104 -115
  2. package/dist/components/FolderTree.svelte.d.ts +4 -7
  3. package/dist/components/core/Dropzone.svelte +42 -2
  4. package/dist/components/core/FileBrowser.svelte +224 -14
  5. package/dist/components/core/FileUploader.svelte +124 -41
  6. package/dist/components/core/RecentFiles.svelte +54 -16
  7. package/dist/components/core/SearchDropdown.svelte +6 -8
  8. package/dist/components/core/UploadPanel.svelte +7 -0
  9. package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
  10. package/dist/components/core/UploadRow.svelte +9 -4
  11. package/dist/components/core/UploadRow.svelte.d.ts +2 -0
  12. package/dist/components/core/dropzoneClick.d.ts +28 -0
  13. package/dist/components/core/dropzoneClick.js +32 -0
  14. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  15. package/dist/components/ui/DropdownMenu.svelte +1 -1
  16. package/dist/config.js +4 -3
  17. package/dist/i18n/context.js +2 -2
  18. package/dist/i18n/errors.js +2 -1
  19. package/dist/i18n/messages.d.ts +13 -0
  20. package/dist/i18n/messages.js +15 -2
  21. package/dist/i18n/text.js +2 -2
  22. package/dist/mediaLibrary/capabilities.js +4 -3
  23. package/dist/mediaLibrary/context.js +4 -3
  24. package/dist/mediaLibrary/errors.js +46 -35
  25. package/dist/mediaLibrary/normalize.js +45 -42
  26. package/dist/mediaLibrary/paging.js +100 -45
  27. package/dist/mediaLibrary/resolve.js +214 -95
  28. package/dist/mediaLibrary/treeOps.js +40 -20
  29. package/dist/mediaLibrary/urls.js +12 -10
  30. package/dist/mediaLibrary/widgetic.js +140 -54
  31. package/dist/stores/dragStore.js +1 -1
  32. package/dist/stores/fileStore.d.ts +3 -3
  33. package/dist/stores/fileStore.js +44 -37
  34. package/dist/stores/folderCountStore.js +12 -11
  35. package/dist/stores/missingFilesStore.js +3 -3
  36. package/dist/stores/navigationStore.d.ts +1 -1
  37. package/dist/stores/navigationStore.js +217 -178
  38. package/dist/stores/persistentSelectStore.d.ts +1 -1
  39. package/dist/stores/persistentSelectStore.js +117 -94
  40. package/dist/stores/searchStore.js +1 -1
  41. package/dist/stores/uploadApiStore.d.ts +10 -0
  42. package/dist/stores/uploadApiStore.js +7 -7
  43. package/dist/stores/viewportStore.js +4 -4
  44. package/dist/types/index.js +0 -1
  45. package/dist/utils/apiConfig.js +9 -9
  46. package/dist/utils/brandKitLibraryTree.js +57 -42
  47. package/dist/utils/dateUtils.js +11 -9
  48. package/dist/utils/deleteSelectionAction.d.ts +26 -0
  49. package/dist/utils/deleteSelectionAction.js +23 -0
  50. package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
  51. package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
  52. package/dist/utils/dragToFolder/springStep.js +4 -3
  53. package/dist/utils/fileGoneProbe.js +65 -16
  54. package/dist/utils/fileKinds.js +14 -13
  55. package/dist/utils/fileNames.js +7 -7
  56. package/dist/utils/fileOperations.js +440 -332
  57. package/dist/utils/fileTypes.js +19 -14
  58. package/dist/utils/fileUtils.js +85 -31
  59. package/dist/utils/folderUtils.js +5 -4
  60. package/dist/utils/gridLayout.js +7 -7
  61. package/dist/utils/imagePreviewCache.js +26 -15
  62. package/dist/utils/imagePreviewFrame.js +13 -13
  63. package/dist/utils/imagePreviewVisualState.js +5 -4
  64. package/dist/utils/imageTransform.js +27 -14
  65. package/dist/utils/itemMenuCapabilities.js +7 -7
  66. package/dist/utils/libraryTree.js +55 -39
  67. package/dist/utils/pendingUploadDeletes.d.ts +102 -0
  68. package/dist/utils/pendingUploadDeletes.js +400 -0
  69. package/dist/utils/previewKeys.js +1 -1
  70. package/dist/utils/previewListNavigation.js +13 -11
  71. package/dist/utils/previewNavigation.js +10 -7
  72. package/dist/utils/recentFiles.js +16 -6
  73. package/dist/utils/recentFilesLimit.js +2 -2
  74. package/dist/utils/removeItems.d.ts +30 -0
  75. package/dist/utils/removeItems.js +124 -0
  76. package/dist/utils/resolveFileUrl.js +6 -6
  77. package/dist/utils/safeText.js +14 -12
  78. package/dist/utils/searchDropdownPhase.d.ts +14 -3
  79. package/dist/utils/searchDropdownPhase.js +13 -9
  80. package/dist/utils/searchItems.js +30 -14
  81. package/dist/utils/searchNavigation.js +5 -5
  82. package/dist/utils/uploadAuth.d.ts +24 -0
  83. package/dist/utils/uploadAuth.js +140 -0
  84. package/dist/utils/uploadDisplayProgress.js +1 -1
  85. package/dist/utils/uploadLimits.d.ts +76 -0
  86. package/dist/utils/uploadLimits.js +242 -0
  87. package/dist/utils/uploadListReconcile.js +24 -11
  88. package/dist/utils/uploadPanelDismiss.js +1 -1
  89. package/dist/utils/uploadPanelProgress.js +4 -4
  90. package/dist/utils/uploadProgressMath.js +13 -11
  91. package/dist/utils/uploadRefusals.d.ts +42 -0
  92. package/dist/utils/uploadRefusals.js +86 -0
  93. package/dist/utils/uploadResponseMapping.js +9 -8
  94. package/dist/utils/uploadUiHelpers.js +17 -17
  95. package/dist/utils/userUploadsStorage.js +270 -133
  96. package/dist/utils/videoFrame.d.ts +23 -0
  97. package/dist/utils/videoFrame.js +26 -0
  98. package/dist/utils/widgeticDelete.js +103 -28
  99. package/dist/utils/widgeticTusUpload.js +189 -105
  100. package/dist/utils/widgeticUpload.js +133 -59
  101. package/dist/utils/xhrMultipartUpload.js +164 -116
  102. package/package.json +3 -3
@@ -17,6 +17,7 @@
17
17
  import { IconExclamationCircle, IconPlayerPlayFilled, IconTrash } from '@widgetic/design-system/icons';
18
18
  import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
19
19
  import { recentGridColumnsForWidth } from '../../utils/gridLayout';
20
+ import { drawsVideoFrame, videoFrameSrc } from '../../utils/videoFrame';
20
21
 
21
22
  let className = '';
22
23
  export { className as class };
@@ -96,6 +97,18 @@
96
97
  file.isMissing = true;
97
98
  }
98
99
 
100
+ /**
101
+ * Videos whose first frame could not be read. This is not "the file is missing": the same file may be a codec this
102
+ * browser does not play, and the preview or the download still work. The card shows the icon of the file instead.
103
+ */
104
+ let videoFrameFailedIds = new Set<string>();
105
+
106
+ function handleVideoFrameError(file: FileSystemItem) {
107
+ if (videoFrameFailedIds.has(file.id)) return;
108
+ console.warn(`[RecentFiles] No first frame for the video ${file.name}; showing its icon instead`);
109
+ videoFrameFailedIds = new Set(videoFrameFailedIds).add(file.id);
110
+ }
111
+
99
112
  function shouldShowCoverImage(file: FileSystemItem): boolean {
100
113
  if (isLoading(file) || file.isMissing || errorStates.get(file.id)) return false;
101
114
  const fileType = getFileTypeOf(file);
@@ -225,23 +238,48 @@
225
238
  {#if isLoading(file)}
226
239
  <div class="size-full bg-muted" aria-hidden="true"></div>
227
240
  {:else if shouldShowCoverImage(file)}
228
- {#if file.hash && file.url}
229
- <div class="absolute inset-0">
230
- <ThumbHashImage
231
- src={getCoverSrc(file)}
232
- alt={file.name}
233
- thumbhash={file.hash}
234
- class_="size-full object-cover"
235
- />
236
- </div>
241
+ {#if isVideoFile(file) && drawsVideoFrame(file)}
242
+ {#if videoFrameFailedIds.has(file.id)}
243
+ <!-- The browser could not read a frame (a codec it does not play): the icon of the file, not a broken picture. -->
244
+ <FileIcon {file} size="lg" />
245
+ {:else}
246
+ <!-- No thumbnail came with the video: its first frame is the cover (only the metadata of the file is loaded). -->
247
+ <!-- svelte-ignore a11y_media_has_caption -->
248
+ <video
249
+ src={videoFrameSrc(file.url ?? '')}
250
+ class="pointer-events-none size-full object-cover opacity-0 transition-opacity duration-fast data-[ready=true]:opacity-100"
251
+ muted
252
+ playsinline
253
+ preload="metadata"
254
+ disablepictureinpicture
255
+ disableremoteplayback
256
+ tabindex="-1"
257
+ aria-hidden="true"
258
+ onloadeddata={(event) => {
259
+ event.currentTarget.dataset.ready = 'true';
260
+ }}
261
+ onerror={() => handleVideoFrameError(file)}
262
+ ></video>
263
+ {/if}
264
+ {:else}
265
+ {#if file.hash && file.url}
266
+ <div class="absolute inset-0">
267
+ <ThumbHashImage
268
+ src={getCoverSrc(file)}
269
+ alt={file.name}
270
+ thumbhash={file.hash}
271
+ class_="size-full object-cover"
272
+ />
273
+ </div>
274
+ {/if}
275
+ <img
276
+ src={getCoverSrc(file)}
277
+ alt=""
278
+ class="size-full object-cover"
279
+ onerror={() => handleImageError(file)}
280
+ />
237
281
  {/if}
238
- <img
239
- src={getCoverSrc(file)}
240
- alt=""
241
- class="size-full object-cover"
242
- onerror={() => handleImageError(file)}
243
- />
244
- {#if isVideoFile(file) && !file.isMissing && !errorStates.get(file.id)}
282
+ {#if isVideoFile(file) && !file.isMissing && !errorStates.get(file.id) && !videoFrameFailedIds.has(file.id)}
245
283
  <span class="pointer-events-none absolute inset-0 flex items-center justify-center">
246
284
  <span
247
285
  class="flex size-12 items-center justify-center rounded-full bg-foreground/60 text-background"
@@ -31,6 +31,7 @@
31
31
  import {
32
32
  resolveSearchDropdownPhase,
33
33
  shouldShowSearchEmptyState,
34
+ shouldShowSearchPanel,
34
35
  shouldShowSearchResultsList
35
36
  } from '../../utils/searchDropdownPhase';
36
37
  import { useI18n } from '../../i18n';
@@ -95,7 +96,8 @@
95
96
  });
96
97
  $: showSearchEmpty = shouldShowSearchEmptyState(searchDropdownPhase);
97
98
  $: showResultsList = shouldShowSearchResultsList(searchDropdownPhase, debouncedResults.length);
98
- $: showSearchLoadingRow = searchDropdownPhase === 'loading' && debouncedResults.length === 0;
99
+ /** The card under the field: drawn for a list or for "nothing found", never as a loading state (see searchDropdownPhase.ts). */
100
+ $: showSearchPanel = shouldShowSearchPanel(searchDropdownPhase);
99
101
 
100
102
  function searchTiming() {
101
103
  if (typeof window === 'undefined') return { debounceMs: searchDebounceMs ?? 150, slowMs: 0 };
@@ -364,7 +366,7 @@
364
366
  });
365
367
 
366
368
  $: ariaActivedescendant =
367
- showPanel && activeIndex >= 0 ? `file-browser-search-opt-${uid}-${activeIndex}` : undefined;
369
+ showSearchPanel && activeIndex >= 0 ? `file-browser-search-opt-${uid}-${activeIndex}` : undefined;
368
370
 
369
371
  /** The field is the textbox of a combobox whose listbox is the panel under it (the Search Field takes these as they are). */
370
372
  $: comboboxAttributes = {
@@ -372,7 +374,7 @@
372
374
  role: 'combobox',
373
375
  'aria-haspopup': 'listbox',
374
376
  'aria-autocomplete': 'list',
375
- 'aria-expanded': showPanel,
377
+ 'aria-expanded': showSearchPanel,
376
378
  'aria-controls': listboxId,
377
379
  'aria-activedescendant': ariaActivedescendant,
378
380
  autocomplete: 'off',
@@ -396,7 +398,7 @@
396
398
  onClear={handleClear}
397
399
  />
398
400
 
399
- {#if showPanel}
401
+ {#if showSearchPanel}
400
402
  <div
401
403
  id={listboxId}
402
404
  role="listbox"
@@ -458,10 +460,6 @@
458
460
  {/each}
459
461
  </div>
460
462
  </WScrollArea>
461
- {:else if showSearchLoadingRow}
462
- <div class="search-dropdown-loading flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
463
- <p class="text-caption text-muted-foreground">{$t('preview.loading')}</p>
464
- </div>
465
463
  {:else if showSearchEmpty}
466
464
  <div class="search-dropdown-empty flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
467
465
  <EmptyState message={$t('searchModal.empty')} />
@@ -17,6 +17,8 @@
17
17
  status: UploadRowState;
18
18
  statusText: string;
19
19
  errorMessage?: string;
20
+ /** False when trying again cannot help (the API refuses the file's type or size): its row has no retry button. Default: true. */
21
+ canRetry?: boolean;
20
22
  };
21
23
 
22
24
  interface Props {
@@ -39,6 +41,8 @@
39
41
  onItemRetry?: (id: string) => void;
40
42
  onFooterAction?: () => void;
41
43
  footerAction?: boolean;
44
+ /** False when no failed file can be retried: the summary row has no retry button. Default: true. */
45
+ summaryCanRetry?: boolean;
42
46
  showClearCompleted?: boolean;
43
47
  onClearCompleted?: () => void;
44
48
  }
@@ -63,6 +67,7 @@
63
67
  onItemRetry,
64
68
  onFooterAction,
65
69
  footerAction = false,
70
+ summaryCanRetry = true,
66
71
  showClearCompleted = false,
67
72
  onClearCompleted
68
73
  }: Props = $props();
@@ -89,6 +94,7 @@
89
94
  batchCount={items.length}
90
95
  onCancel={onSummaryCancel}
91
96
  onRetry={onSummaryRetry}
97
+ canRetry={summaryCanRetry}
92
98
  />
93
99
  </div>
94
100
  {#if items.length > 1}
@@ -165,6 +171,7 @@
165
171
  progressIndeterminate={item.status === 'uploading' ? item.progressIndeterminate : false}
166
172
  onCancel={() => onItemCancel?.(item.id)}
167
173
  onRetry={() => onItemRetry?.(item.id)}
174
+ canRetry={item.canRetry !== false}
168
175
  />
169
176
  </div>
170
177
  {/each}
@@ -14,6 +14,8 @@ export type UploadPanelItem = {
14
14
  status: UploadRowState;
15
15
  statusText: string;
16
16
  errorMessage?: string;
17
+ /** False when trying again cannot help (the API refuses the file's type or size): its row has no retry button. Default: true. */
18
+ canRetry?: boolean;
17
19
  };
18
20
  interface Props {
19
21
  items: UploadPanelItem[];
@@ -35,6 +37,8 @@ interface Props {
35
37
  onItemRetry?: (id: string) => void;
36
38
  onFooterAction?: () => void;
37
39
  footerAction?: boolean;
40
+ /** False when no failed file can be retried: the summary row has no retry button. Default: true. */
41
+ summaryCanRetry?: boolean;
38
42
  showClearCompleted?: boolean;
39
43
  onClearCompleted?: () => void;
40
44
  }
@@ -24,6 +24,8 @@
24
24
  progressIndeterminate?: boolean;
25
25
  onCancel?: () => void;
26
26
  onRetry?: () => void;
27
+ /** False when a failed upload cannot be fixed by trying again (the file's type or size is refused): no retry button. */
28
+ canRetry?: boolean;
27
29
  }
28
30
 
29
31
  let {
@@ -36,7 +38,8 @@
36
38
  progressValue,
37
39
  progressIndeterminate = false,
38
40
  onCancel,
39
- onRetry
41
+ onRetry,
42
+ canRetry = true
40
43
  }: Props = $props();
41
44
 
42
45
  const { t } = useI18n();
@@ -78,9 +81,11 @@
78
81
  <IconX class="size-4 stroke-2" aria-hidden="true" />
79
82
  </IconButton>
80
83
  {:else if state === 'failed'}
81
- <IconButton variant="ghost" size="default" label={$t('upload.retry')} onclick={() => onRetry?.()}>
82
- <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
83
- </IconButton>
84
+ {#if canRetry}
85
+ <IconButton variant="ghost" size="default" label={$t('upload.retry')} onclick={() => onRetry?.()}>
86
+ <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
87
+ </IconButton>
88
+ {/if}
84
89
  <IconButton variant="ghost" size="default" label={$t('upload.removeFile')} onclick={() => onCancel?.()}>
85
90
  <IconX class="size-4 stroke-2" aria-hidden="true" />
86
91
  </IconButton>
@@ -18,6 +18,8 @@ interface Props {
18
18
  progressIndeterminate?: boolean;
19
19
  onCancel?: () => void;
20
20
  onRetry?: () => void;
21
+ /** False when a failed upload cannot be fixed by trying again (the file's type or size is refused): no retry button. */
22
+ canRetry?: boolean;
21
23
  }
22
24
  declare const UploadRow: import("svelte").Component<Props, {}, "">;
23
25
  type UploadRow = ReturnType<typeof UploadRow>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Which clicks inside the drop zone open the file chooser.
3
+ *
4
+ * The whole zone is a target, not only the "Upload files" button: a click on the empty part, the dashed outline or the
5
+ * hint text opens the chooser as well. A click that lands on a control inside the zone (the button itself, the "?" help
6
+ * button) belongs to that control and is left alone, otherwise the chooser would open twice, or open from the help icon.
7
+ */
8
+ type ClickTarget = {
9
+ closest?: (selector: string) => unknown;
10
+ } | null | undefined;
11
+ type ClickZone = {
12
+ contains: (node: never) => boolean;
13
+ };
14
+ /** Whether the click landed on a control that sits inside the zone (not on the zone itself). */
15
+ export declare function isClickOnControlInsideZone(target: ClickTarget, zone: ClickZone): boolean;
16
+ /**
17
+ * The zone is only a click target while it is waiting for files: not while a file is dragged over it (the zone shows
18
+ * whether the drop is allowed) and not while the first upload is being set up.
19
+ */
20
+ export declare function canBrowseFromZone(state: string, showInitialUploading: boolean): boolean;
21
+ /** Whether this click opens the file chooser. */
22
+ export declare function shouldBrowseFromZoneClick(input: {
23
+ target: ClickTarget;
24
+ zone: ClickZone;
25
+ state: string;
26
+ showInitialUploading: boolean;
27
+ }): boolean;
28
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Which clicks inside the drop zone open the file chooser.
3
+ *
4
+ * The whole zone is a target, not only the "Upload files" button: a click on the empty part, the dashed outline or the
5
+ * hint text opens the chooser as well. A click that lands on a control inside the zone (the button itself, the "?" help
6
+ * button) belongs to that control and is left alone, otherwise the chooser would open twice, or open from the help icon.
7
+ */
8
+ /** Anything inside the zone that handles its own click. */
9
+ var OWN_CLICK_SELECTOR = 'button, a, input, select, textarea, [role="button"]';
10
+ /** Whether the click landed on a control that sits inside the zone (not on the zone itself). */
11
+ export function isClickOnControlInsideZone(target, zone) {
12
+ var _a, _b;
13
+ var control = (_b = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, OWN_CLICK_SELECTOR)) !== null && _b !== void 0 ? _b : null;
14
+ if (!control || control === zone)
15
+ return false;
16
+ return zone.contains(control);
17
+ }
18
+ /**
19
+ * The zone is only a click target while it is waiting for files: not while a file is dragged over it (the zone shows
20
+ * whether the drop is allowed) and not while the first upload is being set up.
21
+ */
22
+ export function canBrowseFromZone(state, showInitialUploading) {
23
+ if (showInitialUploading)
24
+ return false;
25
+ return state !== 'drag-valid' && state !== 'drag-invalid';
26
+ }
27
+ /** Whether this click opens the file chooser. */
28
+ export function shouldBrowseFromZoneClick(input) {
29
+ if (!canBrowseFromZone(input.state, input.showInitialUploading))
30
+ return false;
31
+ return !isClickOnControlInsideZone(input.target, input.zone);
32
+ }
@@ -22,8 +22,8 @@ declare const FilePreview: $$__sveltets_2_IsomorphicComponent<{
22
22
  currentFilter?: FileFilterType;
23
23
  target?: string;
24
24
  }, {
25
- navigate: CustomEvent<FileSystemItem>;
26
- select: CustomEvent<FileSystemItem>;
25
+ navigate: FileSystemItem;
26
+ select: FileSystemItem;
27
27
  close: CustomEvent<void>;
28
28
  fileUnavailable: CustomEvent<{
29
29
  id: string;
@@ -54,7 +54,7 @@
54
54
  <IconDots class="size-4 stroke-2" aria-hidden="true" />
55
55
  <span class="sr-only">{$t('menu.moreOptions')}</span>
56
56
  </DropdownMenu.Trigger>
57
- <DropdownMenu.Content class="more-options-content w-[200px]" align="end" sideOffset={4}>
57
+ <DropdownMenu.Content class="more-options-content" align="end" sideOffset={4}>
58
58
  {#if canRename}
59
59
  <DropdownMenu.Item onclick={() => handleAction('rename')}>
60
60
  <IconPencil class="stroke-2" />
package/dist/config.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // File Browser Configuration
2
2
  // Reads from environment variables with sensible defaults
3
- const env = process.env;
4
- export const config = {
3
+ var _a;
4
+ var env = process.env;
5
+ export var config = {
5
6
  // Parse comma-separated origins or use defaults for development
6
- ALLOWED_ORIGINS: env.PUBLIC_ALLOWED_ORIGINS?.split(',') || [
7
+ ALLOWED_ORIGINS: ((_a = env.PUBLIC_ALLOWED_ORIGINS) === null || _a === void 0 ? void 0 : _a.split(',')) || [
7
8
  'http://localhost:5173', // Main site dev
8
9
  'http://localhost:3000', // API Gateway
9
10
  'http://localhost:5174', // Alternative dev port
@@ -1,9 +1,9 @@
1
1
  import { createI18n } from '@widgetic/design-system/i18n';
2
2
  import { FILE_BROWSER_MESSAGES } from './messages';
3
3
  /** The File Browser's words. Problems with the page's messages are said in the console as `[FileBrowser] …`. */
4
- const fileBrowserI18n = createI18n({ catalog: FILE_BROWSER_MESSAGES, label: 'FileBrowser' });
4
+ var fileBrowserI18n = createI18n({ catalog: FILE_BROWSER_MESSAGES, label: 'FileBrowser' });
5
5
  /** The English `t`, for code that has no component around it (a helper called without a translator). */
6
- export const translateEnglish = fileBrowserI18n.translateEnglish;
6
+ export var translateEnglish = fileBrowserI18n.translateEnglish;
7
7
  /**
8
8
  * Called by the File Browser while it is created, so everything inside it speaks the page's language.
9
9
  * The context belongs to one File Browser, so two File Browsers on a page can speak two languages.
@@ -7,7 +7,8 @@ import { MediaLibraryError } from '../mediaLibrary/errors';
7
7
  * - Any other error keeps its message, as it always has.
8
8
  * - With nothing to say, `fallbackKey`.
9
9
  */
10
- export function messageForVisitor(error, t, fallbackKey = 'toast.unknownError') {
10
+ export function messageForVisitor(error, t, fallbackKey) {
11
+ if (fallbackKey === void 0) { fallbackKey = 'toast.unknownError'; }
11
12
  if (error instanceof MediaLibraryError) {
12
13
  if (error.messageKey !== undefined)
13
14
  return t(error.messageKey, error.messageValues);
@@ -110,6 +110,17 @@ export declare const FILE_BROWSER_MESSAGES: {
110
110
  readonly 'upload.uploading': "Uploading…";
111
111
  readonly 'upload.foldersNotAllowed': "Folders cannot be uploaded";
112
112
  readonly 'upload.invalidType': "Invalid file type. Please use {types} files only.";
113
+ /** A file left out before it was sent, with the reason: {name} is the file's name, {reason} one of the "upload.refused…" reasons below. */
114
+ readonly 'upload.refusedOne': "\"{name}\" was not uploaded: {reason}";
115
+ /** Several files left out for the same reason. */
116
+ readonly 'upload.refusedMany': "{count, plural, one {# file was not uploaded} other {# files were not uploaded}}: {reason}";
117
+ /** {type} is the extensions of the files left out (".otf, .woff"), or their MIME type when a name has no extension. */
118
+ readonly 'upload.refusedType': "{type} files are not supported";
119
+ readonly 'upload.refusedTypeUnknown': "this type of file is not supported";
120
+ /** {limit} is the biggest size taken, in megabytes. */
121
+ readonly 'upload.refusedTooLarge': "larger than {limit} MB";
122
+ /** The session ended and could not be renewed: nothing can be sent until the visitor signs in again. */
123
+ readonly 'upload.sessionExpired': "Your session has expired. Sign in again to upload files.";
113
124
  readonly 'upload.dropActive': "Drop to upload {types} files";
114
125
  /** The four sentences of the dropzone when every kind of file is taken: they do not name a kind (Figma "Upload files"). */
115
126
  readonly 'upload.dropActiveAny': "Drop to upload files";
@@ -203,6 +214,8 @@ export declare const FILE_BROWSER_MESSAGES: {
203
214
  readonly 'toast.delete.failedNames': "Failed to delete: {names}";
204
215
  readonly 'toast.delete.failedSome': "Some items could not be deleted";
205
216
  readonly 'toast.delete.failedAll': "Failed to delete items";
217
+ /** The API refused, so the files are listed again: the second line of the "Failed to delete" toast. */
218
+ readonly 'toast.delete.putBack': "{count, plural, one {The file is back in your library} other {The files are back in your library}}";
206
219
  readonly 'toast.folder.created': "Folder created";
207
220
  readonly 'toast.folder.createdDetail': "Created folder \"{name}\"";
208
221
  readonly 'toast.folder.failed': "Failed to create folder";
@@ -9,7 +9,7 @@
9
9
  * Keys are grouped by where the words appear. A key that is left out of a page's `messages` keeps the English text
10
10
  * below, so a language can be added a screen at a time.
11
11
  */
12
- export const FILE_BROWSER_MESSAGES = {
12
+ export var FILE_BROWSER_MESSAGES = {
13
13
  // ===== Words that appear in several places =====
14
14
  'action.cancel': 'Cancel',
15
15
  'action.create': 'Create',
@@ -117,6 +117,17 @@ export const FILE_BROWSER_MESSAGES = {
117
117
  'upload.uploading': 'Uploading…',
118
118
  'upload.foldersNotAllowed': 'Folders cannot be uploaded',
119
119
  'upload.invalidType': 'Invalid file type. Please use {types} files only.',
120
+ /** A file left out before it was sent, with the reason: {name} is the file's name, {reason} one of the "upload.refused…" reasons below. */
121
+ 'upload.refusedOne': '"{name}" was not uploaded: {reason}',
122
+ /** Several files left out for the same reason. */
123
+ 'upload.refusedMany': '{count, plural, one {# file was not uploaded} other {# files were not uploaded}}: {reason}',
124
+ /** {type} is the extensions of the files left out (".otf, .woff"), or their MIME type when a name has no extension. */
125
+ 'upload.refusedType': '{type} files are not supported',
126
+ 'upload.refusedTypeUnknown': 'this type of file is not supported',
127
+ /** {limit} is the biggest size taken, in megabytes. */
128
+ 'upload.refusedTooLarge': 'larger than {limit} MB',
129
+ /** The session ended and could not be renewed: nothing can be sent until the visitor signs in again. */
130
+ 'upload.sessionExpired': 'Your session has expired. Sign in again to upload files.',
120
131
  'upload.dropActive': 'Drop to upload {types} files',
121
132
  /** The four sentences of the dropzone when every kind of file is taken: they do not name a kind (Figma "Upload files"). */
122
133
  'upload.dropActiveAny': 'Drop to upload files',
@@ -212,6 +223,8 @@ export const FILE_BROWSER_MESSAGES = {
212
223
  'toast.delete.failedNames': 'Failed to delete: {names}',
213
224
  'toast.delete.failedSome': 'Some items could not be deleted',
214
225
  'toast.delete.failedAll': 'Failed to delete items',
226
+ /** The API refused, so the files are listed again: the second line of the "Failed to delete" toast. */
227
+ 'toast.delete.putBack': '{count, plural, one {The file is back in your library} other {The files are back in your library}}',
215
228
  'toast.folder.created': 'Folder created',
216
229
  'toast.folder.createdDetail': 'Created folder "{name}"',
217
230
  'toast.folder.failed': 'Failed to create folder',
@@ -310,7 +323,7 @@ export const FILE_BROWSER_MESSAGES = {
310
323
  'date.overAYearAgo': 'Over a year ago',
311
324
  };
312
325
  /** Catalog keys referenced from Svelte without string literals in templates (i18n audit). */
313
- export const UPLOAD_ERROR_KEYS = {
326
+ export var UPLOAD_ERROR_KEYS = {
314
327
  libraryFailed: 'libraryError.uploadFailed',
315
328
  network: 'upload.networkError'
316
329
  };
package/dist/i18n/text.js CHANGED
@@ -4,10 +4,10 @@
4
4
  * sentence does not contain gives the sentence whole, with nothing underlined.
5
5
  */
6
6
  export function splitAround(sentence, link) {
7
- const index = link === '' ? -1 : sentence.indexOf(link);
7
+ var index = link === '' ? -1 : sentence.indexOf(link);
8
8
  if (index < 0)
9
9
  return { before: sentence, link: '', after: '' };
10
- return { before: sentence.slice(0, index), link, after: sentence.slice(index + link.length) };
10
+ return { before: sentence.slice(0, index), link: link, after: sentence.slice(index + link.length) };
11
11
  }
12
12
  /**
13
13
  * The word for a kind of file ("image", "document", "SVG") in the page's language, for a sentence like "Upload image
@@ -2,7 +2,7 @@
2
2
  * What the File Browser offers when it was not given a media library: everything it has always offered. The Widgetic
3
3
  * site and the editor use it this way, so they behave exactly as before.
4
4
  */
5
- export const LEGACY_CAPABILITIES = Object.freeze({
5
+ export var LEGACY_CAPABILITIES = Object.freeze({
6
6
  upload: true,
7
7
  rename: true,
8
8
  delete: true,
@@ -13,7 +13,7 @@ export const LEGACY_CAPABILITIES = Object.freeze({
13
13
  * What the File Browser offers when the media library it was given cannot be used: nothing, so no button leads to
14
14
  * something that cannot work. (The screen says what is wrong.)
15
15
  */
16
- export const NO_CAPABILITIES = Object.freeze({
16
+ export var NO_CAPABILITIES = Object.freeze({
17
17
  upload: false,
18
18
  rename: false,
19
19
  delete: false,
@@ -31,7 +31,8 @@ export const NO_CAPABILITIES = Object.freeze({
31
31
  * visitor's work. (Folders need a library that has folders of its own; the contract does not have them yet.)
32
32
  */
33
33
  export function capabilitiesOf(provider) {
34
- const declared = provider.capabilities ?? {};
34
+ var _a;
35
+ var declared = (_a = provider.capabilities) !== null && _a !== void 0 ? _a : {};
35
36
  return {
36
37
  upload: typeof provider.upload === 'function' && declared.upload !== false,
37
38
  rename: typeof provider.rename === 'function' && declared.rename !== false,
@@ -1,8 +1,8 @@
1
1
  import { getContext, setContext } from 'svelte';
2
2
  import { LEGACY_CAPABILITIES } from './capabilities';
3
- const MEDIA_LIBRARY_CONTEXT_KEY = Symbol('widgetic-file-browser-media-library');
3
+ var MEDIA_LIBRARY_CONTEXT_KEY = Symbol('widgetic-file-browser-media-library');
4
4
  /** What a part of the File Browser sees when no library was supplied: the way it has always worked. */
5
- const LEGACY_CONTEXT = Object.freeze({
5
+ var LEGACY_CONTEXT = Object.freeze({
6
6
  library: null,
7
7
  capabilities: LEGACY_CAPABILITIES
8
8
  });
@@ -12,5 +12,6 @@ export function provideMediaLibraryContext(context) {
12
12
  }
13
13
  /** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it reads as legacy. */
14
14
  export function useMediaLibraryContext() {
15
- return getContext(MEDIA_LIBRARY_CONTEXT_KEY) ?? LEGACY_CONTEXT;
15
+ var _a;
16
+ return (_a = getContext(MEDIA_LIBRARY_CONTEXT_KEY)) !== null && _a !== void 0 ? _a : LEGACY_CONTEXT;
16
17
  }
@@ -1,32 +1,41 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
1
16
  /** The longest message taken from a library's own error. Longer ones are cut so a toast stays readable. */
2
- const MAX_MESSAGE_LENGTH = 300;
17
+ var MAX_MESSAGE_LENGTH = 300;
3
18
  /** What Chrome, Firefox, Safari and React Native write in the TypeError of a `fetch` that could not reach the server. */
4
- const BROWSER_NETWORK_FAILURE_TEXT = /failed to fetch|networkerror|network request failed|load failed/i;
19
+ var BROWSER_NETWORK_FAILURE_TEXT = /failed to fetch|networkerror|network request failed|load failed/i;
5
20
  /** A failed call to a media library, with a reason the File Browser can act on. */
6
- export class MediaLibraryError extends Error {
7
- code;
8
- /** The HTTP status behind the failure, when there was one. */
9
- status;
10
- /**
11
- * The catalog message that says the same thing in the visitor's language. Set when `message` is the File Browser's
12
- * own English text (not one the library wrote): the visitor then reads the translation, while the `error` event and
13
- * the console keep the English `message`. Absent when the library supplied the text, which is shown as it is.
14
- */
15
- messageKey;
16
- /** The values the message at `messageKey` asks for (a size limit, a count), when it asks for any. */
17
- messageValues;
18
- constructor(code, message, options = {}) {
19
- super(message);
20
- this.name = 'MediaLibraryError';
21
- this.code = code;
22
- this.status = options.status;
23
- this.messageKey = options.messageKey;
24
- this.messageValues = options.messageValues;
21
+ var MediaLibraryError = /** @class */ (function (_super) {
22
+ __extends(MediaLibraryError, _super);
23
+ function MediaLibraryError(code, message, options) {
24
+ if (options === void 0) { options = {}; }
25
+ var _this = _super.call(this, message) || this;
26
+ _this.name = 'MediaLibraryError';
27
+ _this.code = code;
28
+ _this.status = options.status;
29
+ _this.messageKey = options.messageKey;
30
+ _this.messageValues = options.messageValues;
25
31
  if (options.cause !== undefined) {
26
- this.cause = options.cause;
32
+ _this.cause = options.cause;
27
33
  }
34
+ return _this;
28
35
  }
29
- }
36
+ return MediaLibraryError;
37
+ }(Error));
38
+ export { MediaLibraryError };
30
39
  /** The error code that fits an HTTP status. */
31
40
  export function codeForHttpStatus(status) {
32
41
  if (status === 401)
@@ -52,10 +61,12 @@ export function isCancellation(error) {
52
61
  }
53
62
  /** The HTTP status a thrown value carries, if it carries one in any of the usual places. */
54
63
  function statusOf(error) {
64
+ var _a;
55
65
  if (error === null || typeof error !== 'object')
56
66
  return undefined;
57
- const candidate = error;
58
- for (const value of [candidate.status, candidate.statusCode, candidate.response?.status]) {
67
+ var candidate = error;
68
+ for (var _i = 0, _b = [candidate.status, candidate.statusCode, (_a = candidate.response) === null || _a === void 0 ? void 0 : _a.status]; _i < _b.length; _i++) {
69
+ var value = _b[_i];
59
70
  if (typeof value === 'number' && Number.isInteger(value) && value >= 100 && value <= 599)
60
71
  return value;
61
72
  }
@@ -65,10 +76,10 @@ function statusOf(error) {
65
76
  function ownTextOf(text) {
66
77
  if (typeof text !== 'string')
67
78
  return null;
68
- const trimmed = text.trim();
79
+ var trimmed = text.trim();
69
80
  if (trimmed === '')
70
81
  return null;
71
- return trimmed.length > MAX_MESSAGE_LENGTH ? `${trimmed.slice(0, MAX_MESSAGE_LENGTH)}…` : trimmed;
82
+ return trimmed.length > MAX_MESSAGE_LENGTH ? "".concat(trimmed.slice(0, MAX_MESSAGE_LENGTH), "\u2026") : trimmed;
72
83
  }
73
84
  /**
74
85
  * Turns whatever a library's function threw (or rejected with) into a {@link MediaLibraryError}.
@@ -83,30 +94,30 @@ export function toMediaLibraryError(error, fallbackMessage, fallbackKey) {
83
94
  if (isAbortError(error)) {
84
95
  return new MediaLibraryError('ABORTED', 'The request was cancelled', { cause: error });
85
96
  }
86
- const status = statusOf(error);
87
- const ownText = ownTextOf(typeof error === 'string'
97
+ var status = statusOf(error);
98
+ var ownText = ownTextOf(typeof error === 'string'
88
99
  ? error
89
100
  : error !== null && typeof error === 'object'
90
101
  ? error.message
91
102
  : undefined);
92
- const message = ownText ?? fallbackMessage;
103
+ var message = ownText !== null && ownText !== void 0 ? ownText : fallbackMessage;
93
104
  // Only the File Browser's own words are translated; what the library wrote is shown as it is.
94
- const messageKey = ownText === null ? fallbackKey : undefined;
105
+ var messageKey = ownText === null ? fallbackKey : undefined;
95
106
  if (status !== undefined) {
96
- return new MediaLibraryError(codeForHttpStatus(status), message, { status, cause: error, messageKey });
107
+ return new MediaLibraryError(codeForHttpStatus(status), message, { status: status, cause: error, messageKey: messageKey });
97
108
  }
98
109
  // `fetch` rejects with a TypeError when the server cannot be reached at all. The browser's own text for it
99
110
  // ("Failed to fetch") is English whatever the visitor's language, so the visitor reads our sentence instead; the
100
111
  // host's `error` event still carries what the browser said. A TypeError the library threw with words of its own
101
112
  // is not a network failure, and its words are shown.
102
113
  if (error instanceof TypeError) {
103
- const isBrowserNetworkText = ownText !== null && BROWSER_NETWORK_FAILURE_TEXT.test(ownText);
104
- return new MediaLibraryError('NETWORK', ownText ?? 'Could not reach the media library', {
114
+ var isBrowserNetworkText = ownText !== null && BROWSER_NETWORK_FAILURE_TEXT.test(ownText);
115
+ return new MediaLibraryError('NETWORK', ownText !== null && ownText !== void 0 ? ownText : 'Could not reach the media library', {
105
116
  cause: error,
106
117
  messageKey: ownText === null || isBrowserNetworkText ? 'libraryError.unreachable' : undefined
107
118
  });
108
119
  }
109
- return new MediaLibraryError('FAILED', message, { cause: error, messageKey });
120
+ return new MediaLibraryError('FAILED', message, { cause: error, messageKey: messageKey });
110
121
  }
111
122
  /** True when the failure means the credentials were refused, so refreshing them and trying again may help. */
112
123
  export function isUnauthorized(error) {