@widgetic/file-browser 0.5.47 → 0.5.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/core/Dropzone.svelte +42 -2
- package/dist/components/core/FileBrowser.svelte +221 -13
- package/dist/components/core/FileUploader.svelte +124 -41
- package/dist/components/core/RecentFiles.svelte +54 -16
- package/dist/components/core/SearchDropdown.svelte +6 -8
- package/dist/components/core/UploadPanel.svelte +7 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
- package/dist/components/core/UploadRow.svelte +9 -4
- package/dist/components/core/UploadRow.svelte.d.ts +2 -0
- package/dist/components/core/dropzoneClick.d.ts +28 -0
- package/dist/components/core/dropzoneClick.js +31 -0
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/i18n/messages.d.ts +13 -0
- package/dist/i18n/messages.js +13 -0
- package/dist/stores/uploadApiStore.d.ts +10 -0
- package/dist/utils/deleteSelectionAction.d.ts +26 -0
- package/dist/utils/deleteSelectionAction.js +23 -0
- package/dist/utils/pendingUploadDeletes.d.ts +102 -0
- package/dist/utils/pendingUploadDeletes.js +224 -0
- package/dist/utils/removeItems.d.ts +30 -0
- package/dist/utils/removeItems.js +92 -0
- package/dist/utils/searchDropdownPhase.d.ts +14 -3
- package/dist/utils/searchDropdownPhase.js +12 -8
- package/dist/utils/uploadAuth.d.ts +24 -0
- package/dist/utils/uploadAuth.js +65 -0
- package/dist/utils/uploadLimits.d.ts +76 -0
- package/dist/utils/uploadLimits.js +170 -0
- package/dist/utils/uploadRefusals.d.ts +42 -0
- package/dist/utils/uploadRefusals.js +70 -0
- package/dist/utils/videoFrame.d.ts +23 -0
- package/dist/utils/videoFrame.js +26 -0
- package/dist/utils/widgeticDelete.js +5 -3
- package/dist/utils/widgeticUpload.js +10 -4
- 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
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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':
|
|
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
|
|
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
|
-
|
|
82
|
-
<
|
|
83
|
-
|
|
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,31 @@
|
|
|
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
|
+
const 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
|
+
const control = target?.closest?.(OWN_CLICK_SELECTOR) ?? null;
|
|
13
|
+
if (!control || control === zone)
|
|
14
|
+
return false;
|
|
15
|
+
return zone.contains(control);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The zone is only a click target while it is waiting for files: not while a file is dragged over it (the zone shows
|
|
19
|
+
* whether the drop is allowed) and not while the first upload is being set up.
|
|
20
|
+
*/
|
|
21
|
+
export function canBrowseFromZone(state, showInitialUploading) {
|
|
22
|
+
if (showInitialUploading)
|
|
23
|
+
return false;
|
|
24
|
+
return state !== 'drag-valid' && state !== 'drag-invalid';
|
|
25
|
+
}
|
|
26
|
+
/** Whether this click opens the file chooser. */
|
|
27
|
+
export function shouldBrowseFromZoneClick(input) {
|
|
28
|
+
if (!canBrowseFromZone(input.state, input.showInitialUploading))
|
|
29
|
+
return false;
|
|
30
|
+
return !isClickOnControlInsideZone(input.target, input.zone);
|
|
31
|
+
}
|
|
@@ -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
|
|
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/i18n/messages.d.ts
CHANGED
|
@@ -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";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -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',
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/** Why the Widgetic API is about to be called with a token. `expired` means the API just refused the previous one. */
|
|
2
|
+
export type UploadTokenReason = 'initial' | 'expired';
|
|
1
3
|
export type FileBrowserUploadConfig = {
|
|
2
4
|
apiBasePath: string;
|
|
3
5
|
accessToken: string;
|
|
6
|
+
/**
|
|
7
|
+
* Gives the token to call the API with, so a page whose session is renewed while the File Browser is open never
|
|
8
|
+
* sends a stale one (the `accessToken` above is only what the page held when it set the config). Called before every
|
|
9
|
+
* request, and again with `'expired'` (and the token that was refused) when the API answers 401: the request is then
|
|
10
|
+
* tried once more with the token that comes back. Same contract as `getAccessToken` of `createWidgeticMediaLibrary`.
|
|
11
|
+
* Left out, `accessToken` is used as it is.
|
|
12
|
+
*/
|
|
13
|
+
getAccessToken?: (reason: UploadTokenReason, refusedToken?: string) => Promise<string> | string;
|
|
4
14
|
contextType?: 'widget-codegen' | 'browser-ic' | 'content-property';
|
|
5
15
|
source?: string;
|
|
6
16
|
widgetId?: string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type DeleteSelectionAction = 'open-delete-dialog' | 'none';
|
|
2
|
+
export interface DeleteSelectionContext {
|
|
3
|
+
/** `KeyboardEvent.key`: "Delete", or "Backspace", which is the key a Mac keyboard labels "delete". */
|
|
4
|
+
key: string;
|
|
5
|
+
altKey: boolean;
|
|
6
|
+
shiftKey: boolean;
|
|
7
|
+
defaultPrevented: boolean;
|
|
8
|
+
/** The File Browser lets the visitor select files. */
|
|
9
|
+
allowSelecting: boolean;
|
|
10
|
+
/** The media library (or the legacy settings) offers Delete: the button of the selection bar is there. */
|
|
11
|
+
canDelete: boolean;
|
|
12
|
+
/** How many files are selected (the selection bar acts on these). */
|
|
13
|
+
selectionCount: number;
|
|
14
|
+
previewOpen: boolean;
|
|
15
|
+
designSystemModalOpen: boolean;
|
|
16
|
+
/** The visitor is typing in a field (search, a rename): the key edits the text. */
|
|
17
|
+
inputFocused: boolean;
|
|
18
|
+
/** A dialog or a dropdown of the File Browser is open (rename, new folder, move, delete, filter, sort): the key is theirs. */
|
|
19
|
+
innerUiOpen: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the Delete key (or Backspace) opens the delete dialog for the selected files. It is the same dialog the Delete
|
|
23
|
+
* button of the selection bar opens, so the keyboard and the button cannot disagree. With nothing selected the key does what
|
|
24
|
+
* it always did (Backspace goes back one folder); in a field, a dialog or the preview it is left alone.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteSelectionAction(context: DeleteSelectionContext): DeleteSelectionAction;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the Delete key (or Backspace) opens the delete dialog for the selected files. It is the same dialog the Delete
|
|
3
|
+
* button of the selection bar opens, so the keyboard and the button cannot disagree. With nothing selected the key does what
|
|
4
|
+
* it always did (Backspace goes back one folder); in a field, a dialog or the preview it is left alone.
|
|
5
|
+
*/
|
|
6
|
+
export function deleteSelectionAction(context) {
|
|
7
|
+
if (context.key !== 'Delete' && context.key !== 'Backspace')
|
|
8
|
+
return 'none';
|
|
9
|
+
if (context.defaultPrevented)
|
|
10
|
+
return 'none';
|
|
11
|
+
// Option+Delete deletes a word and Shift+Delete is the browser's own: neither is "delete the files".
|
|
12
|
+
if (context.altKey || context.shiftKey)
|
|
13
|
+
return 'none';
|
|
14
|
+
if (!context.allowSelecting || !context.canDelete)
|
|
15
|
+
return 'none';
|
|
16
|
+
if (context.selectionCount <= 0)
|
|
17
|
+
return 'none';
|
|
18
|
+
if (context.previewOpen || context.designSystemModalOpen)
|
|
19
|
+
return 'none';
|
|
20
|
+
if (context.inputFocused || context.innerUiOpen)
|
|
21
|
+
return 'none';
|
|
22
|
+
return 'open-delete-dialog';
|
|
23
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deletes the API has still to hear about.
|
|
3
|
+
*
|
|
4
|
+
* When the visitor deletes files they leave the screen at once; the API is told afterwards, in the background. This queue
|
|
5
|
+
* is what makes "afterwards" safe: every upload that was taken off the screen is written down in Dexie (the local database
|
|
6
|
+
* of `@widgetic/cache-layer`) before anything is sent, one record per upload, and is only forgotten once the API has
|
|
7
|
+
* answered. So a reload, a closed tab or a network that comes and goes neither brings the files back nor loses the delete:
|
|
8
|
+
* - the next time the File Browser opens it finishes the queue, and does not list a file whose delete is still waiting;
|
|
9
|
+
* - a network error, a 5xx or a 401 is tried again, a little later each time (1 s, 2 s, 4 s … up to a minute);
|
|
10
|
+
* - an answer that will never change (the API says "not allowed", say) ends the record and tells the File Browser, which
|
|
11
|
+
* puts the file back and says so.
|
|
12
|
+
*
|
|
13
|
+
* It keeps its own kind of record next to the others in the entity store rather than using the shared mutation outbox of the
|
|
14
|
+
* cache layer: that outbox hands every row, whatever its kind, to the one processor that drains it (the brand kit's), so a
|
|
15
|
+
* row of another kind would be read by the wrong code.
|
|
16
|
+
*/
|
|
17
|
+
/** The kind of entity the records are saved under (the key is `{owner}:fileBrowserPendingDeletes:{uploadId}`). */
|
|
18
|
+
export declare const PENDING_DELETES_KIND = "fileBrowserPendingDeletes";
|
|
19
|
+
/** After this many failed tries the API is taken to be unreachable for good, and the delete is given up. */
|
|
20
|
+
export declare const PENDING_DELETE_MAX_ATTEMPTS = 8;
|
|
21
|
+
/** How many deletes are sent at the same time. */
|
|
22
|
+
export declare const PENDING_DELETE_CONCURRENCY = 4;
|
|
23
|
+
export interface PendingUploadDelete {
|
|
24
|
+
uploadId: string;
|
|
25
|
+
/** What the visitor knew the file as, to name it if the delete cannot be done. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** How many times the API was asked and could not do it. */
|
|
28
|
+
attempts: number;
|
|
29
|
+
/** The earliest time (epoch ms) to ask again. */
|
|
30
|
+
nextAttemptAt: number;
|
|
31
|
+
createdAt: number;
|
|
32
|
+
lastError: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** Where the records are kept. Dexie in the browser; a Map when there is no owner to keep them for, and in tests. */
|
|
35
|
+
export interface PendingDeleteStore {
|
|
36
|
+
list(): Promise<PendingUploadDelete[]>;
|
|
37
|
+
put(record: PendingUploadDelete): Promise<void>;
|
|
38
|
+
remove(uploadId: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** What asking the API came to. */
|
|
41
|
+
export type DeleteAttemptResult = {
|
|
42
|
+
result: 'ok';
|
|
43
|
+
}
|
|
44
|
+
/** Worth asking again later (offline, a 5xx, a session that is being renewed). */
|
|
45
|
+
| {
|
|
46
|
+
result: 'retry';
|
|
47
|
+
message?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The answer will not change (the API refuses): give up and say so. */
|
|
50
|
+
| {
|
|
51
|
+
result: 'permanent';
|
|
52
|
+
message?: string;
|
|
53
|
+
};
|
|
54
|
+
export type DeleteProcessor = (record: PendingUploadDelete) => Promise<DeleteAttemptResult>;
|
|
55
|
+
/** Told when a record is finished one way or the other. */
|
|
56
|
+
export interface DrainHooks {
|
|
57
|
+
onDeleted?: (record: PendingUploadDelete) => void;
|
|
58
|
+
onGaveUp?: (record: PendingUploadDelete, message: string) => void;
|
|
59
|
+
}
|
|
60
|
+
/** How long to wait before asking again, after `attempts` tries have failed: 1 s, 2 s, 4 s … never more than a minute. */
|
|
61
|
+
export declare function deleteBackoffMs(attempts: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* What an HTTP answer means for a delete. 404 and 410 mean the upload is already gone, which is what was wanted. The other
|
|
64
|
+
* 4xx answers (not allowed, malformed) will not change by asking again; 401 (the session is being renewed), 408, 425, 429 and
|
|
65
|
+
* every 5xx will. No status at all is a network error: the same.
|
|
66
|
+
*/
|
|
67
|
+
export declare function classifyDeleteStatus(status: number | undefined): 'ok' | 'retry' | 'permanent';
|
|
68
|
+
export declare function createMemoryPendingDeleteStore(): PendingDeleteStore;
|
|
69
|
+
/** The records of one owner (one signed-in person), kept in Dexie through the entity store of the cache layer. */
|
|
70
|
+
export declare function createCacheLayerPendingDeleteStore(ownerId: string): PendingDeleteStore;
|
|
71
|
+
export interface PendingDeleteQueueOptions {
|
|
72
|
+
store: PendingDeleteStore;
|
|
73
|
+
now?: () => number;
|
|
74
|
+
maxAttempts?: number;
|
|
75
|
+
concurrency?: number;
|
|
76
|
+
/** Runs `callback` after `delayMs` (default: `setTimeout`). */
|
|
77
|
+
schedule?: (callback: () => void, delayMs: number) => unknown;
|
|
78
|
+
cancel?: (handle: unknown) => void;
|
|
79
|
+
}
|
|
80
|
+
export interface PendingDeleteQueue {
|
|
81
|
+
/** Writes the uploads down. Ids that are already waiting are kept as they are. */
|
|
82
|
+
enqueue(uploads: ReadonlyArray<{
|
|
83
|
+
uploadId: string;
|
|
84
|
+
name: string;
|
|
85
|
+
}>): Promise<void>;
|
|
86
|
+
/** The ids whose delete is waiting (due or not): the File Browser does not list these. */
|
|
87
|
+
pendingIds(): Promise<Set<string>>;
|
|
88
|
+
/**
|
|
89
|
+
* Sends the deletes that are due, a few at a time, until none is. Records that have to be tried again are picked up
|
|
90
|
+
* later by the queue itself (a timer), with the same `process` and `hooks`. Calls that overlap share one run.
|
|
91
|
+
*/
|
|
92
|
+
drain(process: DeleteProcessor, hooks?: DrainHooks): Promise<void>;
|
|
93
|
+
/** Stops the timer that wakes the queue (the records stay in the store). */
|
|
94
|
+
stop(): void;
|
|
95
|
+
}
|
|
96
|
+
export declare function createPendingDeleteQueue(options: PendingDeleteQueueOptions): PendingDeleteQueue;
|
|
97
|
+
/**
|
|
98
|
+
* The queue of the signed-in person (the cache owner). Without an owner there is nowhere to keep the records for the next
|
|
99
|
+
* visit, so they are kept in memory: the files still leave the screen at once and the deletes are still retried, but a reload
|
|
100
|
+
* before the API answers forgets them.
|
|
101
|
+
*/
|
|
102
|
+
export declare function getPendingUploadDeleteQueue(): PendingDeleteQueue;
|