@widgetic/file-browser 0.5.23 → 0.5.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -4
- package/dist/components/FolderTree.svelte +4 -1
- package/dist/components/core/FileBrowser.svelte +539 -163
- package/dist/components/core/FileBrowser.svelte.d.ts +25 -1
- package/dist/components/core/FileUploader.svelte +114 -45
- package/dist/components/core/Header.svelte +12 -1
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +34 -26
- package/dist/components/core/UploadStatus.svelte +8 -5
- package/dist/components/core/UploadStatusList.svelte +13 -21
- package/dist/components/items/FileItem.svelte +19 -10
- package/dist/components/items/FolderItem.svelte +6 -3
- package/dist/components/modals/MoveDialog.svelte +43 -32
- package/dist/components/modals/NewFolderButton.svelte +5 -2
- package/dist/components/modals/SearchModal.svelte +16 -21
- package/dist/components/modals/SelectedFilesModal.svelte +14 -9
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +1 -1
- package/dist/components/previews/AudioPlayer.svelte +5 -2
- package/dist/components/previews/ErrorPreview.svelte +7 -4
- package/dist/components/previews/ErrorPreview.svelte.d.ts +1 -1
- package/dist/components/previews/FilePreview.svelte +17 -7
- package/dist/components/previews/FontPreview.svelte +18 -9
- package/dist/components/previews/FontPreview.svelte.d.ts +1 -1
- package/dist/components/previews/TextPreview.svelte +12 -5
- package/dist/components/previews/VideoPlayer.svelte +8 -5
- package/dist/components/ui/ControlToolbar.svelte +45 -23
- package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
- package/dist/components/ui/DragSelect.svelte +2 -2
- package/dist/components/ui/DropdownMenu.svelte +35 -14
- package/dist/components/ui/FileIcon.svelte +8 -5
- package/dist/components/ui/FileIcon.svelte.d.ts +1 -0
- package/dist/components/ui/FileMetadata.svelte +12 -15
- package/dist/components/ui/SearchResults.svelte +4 -1
- package/dist/i18n/context.d.ts +38 -0
- package/dist/i18n/context.js +70 -0
- package/dist/i18n/errors.d.ts +11 -0
- package/dist/i18n/errors.js +19 -0
- package/dist/i18n/index.d.ts +11 -0
- package/dist/i18n/index.js +18 -0
- package/dist/i18n/messages.d.ts +277 -0
- package/dist/i18n/messages.js +290 -0
- package/dist/i18n/text.d.ts +19 -0
- package/dist/i18n/text.js +35 -0
- package/dist/i18n/translator.d.ts +75 -0
- package/dist/i18n/translator.js +317 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/mediaLibrary/capabilities.d.ts +22 -0
- package/dist/mediaLibrary/capabilities.js +42 -0
- package/dist/mediaLibrary/context.d.ts +17 -0
- package/dist/mediaLibrary/context.js +16 -0
- package/dist/mediaLibrary/errors.d.ts +42 -0
- package/dist/mediaLibrary/errors.js +114 -0
- package/dist/mediaLibrary/index.d.ts +10 -0
- package/dist/mediaLibrary/index.js +9 -0
- package/dist/mediaLibrary/normalize.d.ts +39 -0
- package/dist/mediaLibrary/normalize.js +139 -0
- package/dist/mediaLibrary/paging.d.ts +37 -0
- package/dist/mediaLibrary/paging.js +62 -0
- package/dist/mediaLibrary/resolve.d.ts +39 -0
- package/dist/mediaLibrary/resolve.js +137 -0
- package/dist/mediaLibrary/treeOps.d.ts +24 -0
- package/dist/mediaLibrary/treeOps.js +67 -0
- package/dist/mediaLibrary/types.d.ts +126 -0
- package/dist/mediaLibrary/types.js +11 -0
- package/dist/mediaLibrary/urls.d.ts +30 -0
- package/dist/mediaLibrary/urls.js +59 -0
- package/dist/mediaLibrary/widgetic.d.ts +39 -0
- package/dist/mediaLibrary/widgetic.js +89 -0
- package/dist/stores/fileStore.d.ts +1 -1
- package/dist/stores/folderCountStore.js +2 -2
- package/dist/stores/persistentSelectStore.d.ts +10 -0
- package/dist/stores/persistentSelectStore.js +26 -0
- package/dist/utils/dateUtils.d.ts +11 -2
- package/dist/utils/dateUtils.js +20 -15
- package/dist/utils/fileKinds.d.ts +44 -0
- package/dist/utils/fileKinds.js +96 -0
- package/dist/utils/fileNames.d.ts +7 -0
- package/dist/utils/fileNames.js +19 -0
- package/dist/utils/fileOperations.js +2 -11
- package/dist/utils/fileTypes.d.ts +11 -2
- package/dist/utils/fileTypes.js +26 -14
- package/dist/utils/fileUtils.d.ts +8 -1
- package/dist/utils/fileUtils.js +22 -7
- package/dist/utils/folderUtils.js +3 -2
- package/dist/utils/safeText.d.ts +29 -0
- package/dist/utils/safeText.js +66 -0
- package/dist/utils/userUploadsStorage.d.ts +4 -1
- package/dist/utils/userUploadsStorage.js +5 -2
- package/dist/utils/widgeticTusUpload.d.ts +10 -0
- package/dist/utils/widgeticTusUpload.js +61 -3
- package/dist/utils/widgeticUpload.d.ts +3 -0
- package/dist/utils/widgeticUpload.js +7 -2
- package/package.json +7 -5
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
// Imports from Design System
|
|
6
6
|
import { WScrollArea } from '@widgetic/design-system/components';
|
|
7
|
+
import { useI18n } from '../../i18n';
|
|
8
|
+
|
|
9
|
+
const { t } = useI18n();
|
|
7
10
|
|
|
8
11
|
export let src: string;
|
|
9
12
|
|
|
@@ -12,7 +15,10 @@
|
|
|
12
15
|
|
|
13
16
|
let content: string = '';
|
|
14
17
|
let isLoading = true;
|
|
15
|
-
|
|
18
|
+
/** True when the file could not be read. */
|
|
19
|
+
let loadFailed = false;
|
|
20
|
+
/** The server's own words for why (its status text, "Not Found"), when it gave any. */
|
|
21
|
+
let failureReason = '';
|
|
16
22
|
let formattedContent: string = '';
|
|
17
23
|
let contentElement: HTMLPreElement;
|
|
18
24
|
let contentHeight = 0;
|
|
@@ -48,6 +54,7 @@
|
|
|
48
54
|
try {
|
|
49
55
|
const response = await fetch(src);
|
|
50
56
|
if (!response.ok) {
|
|
57
|
+
failureReason = response.statusText;
|
|
51
58
|
throw new Error(`Failed to load text file: ${response.statusText}`);
|
|
52
59
|
}
|
|
53
60
|
content = await response.text();
|
|
@@ -61,7 +68,7 @@
|
|
|
61
68
|
contentHeight = contentElement.scrollHeight;
|
|
62
69
|
}
|
|
63
70
|
} catch (err) {
|
|
64
|
-
|
|
71
|
+
loadFailed = true;
|
|
65
72
|
console.error('Error loading text file:', err);
|
|
66
73
|
} finally {
|
|
67
74
|
isLoading = false;
|
|
@@ -71,9 +78,9 @@
|
|
|
71
78
|
|
|
72
79
|
<div class="text-preview-container w-full h-full px-4 widgetic-colors" style="max-height: {scrolledAreaMaxHeight}px">
|
|
73
80
|
{#if isLoading}
|
|
74
|
-
<div class="text-[hsl(var(--grey5))] p-6">
|
|
75
|
-
{:else if
|
|
76
|
-
<div class="text-[hsl(var(--error))] p-6">{
|
|
81
|
+
<div class="text-[hsl(var(--grey5))] p-6">{$t('preview.loading')}</div>
|
|
82
|
+
{:else if loadFailed}
|
|
83
|
+
<div class="text-[hsl(var(--error))] p-6">{failureReason ? $t('preview.textFailedReason', { reason: failureReason }) : $t('preview.textFailed')}</div>
|
|
77
84
|
{:else}
|
|
78
85
|
<WScrollArea class="text-pre-scroll-area !h-[500px]" viewPortClass="rounded-large widgetic-radius bg-[hsl(var(--grey1))]" scrollOutside={true} type="always">
|
|
79
86
|
<pre bind:this={contentElement}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, onDestroy } from 'svelte';
|
|
3
3
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
4
|
+
import { useI18n } from '../../i18n';
|
|
5
|
+
|
|
6
|
+
const { t } = useI18n();
|
|
4
7
|
|
|
5
8
|
export let src: string;
|
|
6
9
|
export let autoplay = false;
|
|
@@ -152,7 +155,7 @@
|
|
|
152
155
|
</script>
|
|
153
156
|
|
|
154
157
|
{#if hasError}
|
|
155
|
-
<ErrorPreview message=
|
|
158
|
+
<ErrorPreview message={$t('preview.videoFailed')} />
|
|
156
159
|
{:else}
|
|
157
160
|
<!-- svelte-ignore a11y-media-has-caption -->
|
|
158
161
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
@@ -175,7 +178,7 @@
|
|
|
175
178
|
onpause={handlePause}
|
|
176
179
|
>
|
|
177
180
|
<track kind="captions" />
|
|
178
|
-
|
|
181
|
+
{$t('preview.videoUnsupported')}
|
|
179
182
|
</video>
|
|
180
183
|
|
|
181
184
|
<!-- Custom video controls -->
|
|
@@ -206,7 +209,7 @@
|
|
|
206
209
|
<button
|
|
207
210
|
onclick={togglePlay}
|
|
208
211
|
class="flex items-center justify-center w-8 h-8 text-white focus:outline-none"
|
|
209
|
-
aria-label={isPlaying ?
|
|
212
|
+
aria-label={isPlaying ? $t('action.pause') : $t('action.play')}
|
|
210
213
|
>
|
|
211
214
|
{#if isPlaying}
|
|
212
215
|
<!-- Pause icon -->
|
|
@@ -233,7 +236,7 @@
|
|
|
233
236
|
<button
|
|
234
237
|
onclick={toggleMute}
|
|
235
238
|
class="flex items-center justify-center w-8 h-8 text-white focus:outline-none"
|
|
236
|
-
aria-label={isMuted ?
|
|
239
|
+
aria-label={isMuted ? $t('action.unmute') : $t('action.mute')}
|
|
237
240
|
>
|
|
238
241
|
{#if isMuted}
|
|
239
242
|
<!-- Muted icon -->
|
|
@@ -257,7 +260,7 @@
|
|
|
257
260
|
<button
|
|
258
261
|
onclick={togglePlay}
|
|
259
262
|
class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 flex items-center justify-center w-16 h-16 bg-black/40 rounded-full text-white focus:outline-none"
|
|
260
|
-
aria-label=
|
|
263
|
+
aria-label={$t('action.play')}
|
|
261
264
|
>
|
|
262
265
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-10 h-10">
|
|
263
266
|
<path fill-rule="evenodd" d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z" clip-rule="evenodd" />
|
|
@@ -13,15 +13,24 @@
|
|
|
13
13
|
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
14
14
|
import { createEventDispatcher } from 'svelte';
|
|
15
15
|
import { toast } from '@widgetic/design-system/components';
|
|
16
|
-
import {
|
|
16
|
+
import { getFileIcon } from '../../utils/fileUtils';
|
|
17
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
18
|
+
import { toSafeFontFamilyName } from '../../utils/safeText';
|
|
17
19
|
import { fade } from 'svelte/transition';
|
|
18
20
|
import { selectedFiles as storeSelectedFiles } from '../../stores/fileStore';
|
|
21
|
+
import { useMediaLibraryContext } from '../../mediaLibrary/context';
|
|
22
|
+
import { useI18n } from '../../i18n';
|
|
23
|
+
|
|
24
|
+
const { t } = useI18n();
|
|
25
|
+
|
|
26
|
+
// Which actions the media library allows. Everything, when the File Browser works from its own settings.
|
|
27
|
+
const { capabilities } = useMediaLibraryContext();
|
|
19
28
|
|
|
20
29
|
export let selectedFiles: FileSystemItem[] = [];
|
|
21
30
|
export let currentFilter: FileFilterType;
|
|
22
31
|
export let showAddToEditor = true;
|
|
23
|
-
/** Singular label for the primary confirm action (pluralized when count > 1). */
|
|
24
|
-
export let addToEditorLabel
|
|
32
|
+
/** Singular label for the primary confirm action (pluralized when count > 1). Left out, the File Browser's own ("Add to Editor", or the page's language's). */
|
|
33
|
+
export let addToEditorLabel: string | undefined = undefined;
|
|
25
34
|
export let allowSelecting = false;
|
|
26
35
|
export let filter: FileFilterType = 'all';
|
|
27
36
|
/** When true, toolbar uses icon-only / shorter labels (narrow file-browser panel). */
|
|
@@ -54,7 +63,7 @@
|
|
|
54
63
|
|
|
55
64
|
// Function to get thumbnail or icon for a file
|
|
56
65
|
function getFilePreview(file: FileSystemItem): string {
|
|
57
|
-
const fileType =
|
|
66
|
+
const fileType = getFileTypeOf(file);
|
|
58
67
|
|
|
59
68
|
if (fileType === 'font') {
|
|
60
69
|
return 'font';
|
|
@@ -84,8 +93,8 @@
|
|
|
84
93
|
}));
|
|
85
94
|
|
|
86
95
|
// Show sonar toast instead of alert
|
|
87
|
-
toast.success('
|
|
88
|
-
description:
|
|
96
|
+
toast.success($t('toast.filesAdded'), {
|
|
97
|
+
description: $t('toast.filesAddedDetail', { count: selectedFiles.length })
|
|
89
98
|
});
|
|
90
99
|
|
|
91
100
|
// Clear selections and dispatch event
|
|
@@ -112,7 +121,8 @@
|
|
|
112
121
|
function handleDownload() {
|
|
113
122
|
const file = selectedFiles[0];
|
|
114
123
|
if (file.url) {
|
|
115
|
-
|
|
124
|
+
// noopener/noreferrer: the opened page gets no handle on this page (the file's host is not trusted).
|
|
125
|
+
window.open(file.url, '_blank', 'noopener,noreferrer');
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
|
|
@@ -120,8 +130,8 @@
|
|
|
120
130
|
$: selectedItemsCount = allowSelecting ? persistentSelectStore.getSelected(filter).length : 0;
|
|
121
131
|
$: confirmAddLabel =
|
|
122
132
|
selectedFiles.length <= 1
|
|
123
|
-
? addToEditorLabel
|
|
124
|
-
:
|
|
133
|
+
? (addToEditorLabel ?? $t('action.addToEditor'))
|
|
134
|
+
: $t('selectedFiles.confirmMany', { count: selectedFiles.length });
|
|
125
135
|
$: confirmAddDisabled =
|
|
126
136
|
maxSelections === 1 &&
|
|
127
137
|
!!activeFileId &&
|
|
@@ -146,7 +156,7 @@
|
|
|
146
156
|
>
|
|
147
157
|
{#if getFilePreview(selectedFiles[0]) === 'font'}
|
|
148
158
|
<div class="w-6 h-6 flex items-center justify-center bg-gray-100">
|
|
149
|
-
<span style="font-family: '{selectedFiles[0].name
|
|
159
|
+
<span style="font-family: '{toSafeFontFamilyName(selectedFiles[0].name)}', sans-serif;" class="text-xs text-gray-700">
|
|
150
160
|
aA
|
|
151
161
|
</span>
|
|
152
162
|
</div>
|
|
@@ -187,46 +197,54 @@
|
|
|
187
197
|
{confirmAddLabel}
|
|
188
198
|
</Button>
|
|
189
199
|
{/if}
|
|
200
|
+
{#if capabilities.rename}
|
|
190
201
|
<Button
|
|
191
202
|
variant="ghost"
|
|
192
203
|
size="sm"
|
|
193
204
|
class="text-[hsl(var(--grey5))] {compact ? 'text-xs px-1.5' : 'text-sm'} font-semibold flex items-center gap-1.5 [&_svg]:size-5 hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
194
205
|
onclick={handleRename}
|
|
195
|
-
aria-label=
|
|
206
|
+
aria-label={$t('action.rename')}
|
|
196
207
|
>
|
|
197
208
|
<IconEdit class="w-4 h-4 shrink-0" />
|
|
198
|
-
{#if !compact}
|
|
209
|
+
{#if !compact}{$t('action.rename')}{/if}
|
|
199
210
|
</Button>
|
|
211
|
+
{/if}
|
|
212
|
+
{#if capabilities.download}
|
|
200
213
|
<Button
|
|
201
214
|
variant="ghost"
|
|
202
215
|
size="sm"
|
|
203
216
|
class="text-[hsl(var(--grey5))] {compact ? 'text-xs px-1.5' : 'text-sm'} font-semibold flex items-center gap-1.5 [&_svg]:size-5 hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
204
217
|
onclick={handleDownload}
|
|
205
|
-
aria-label=
|
|
218
|
+
aria-label={$t('action.download')}
|
|
206
219
|
>
|
|
207
220
|
<IconCircleArrowDown class="w-4 h-4 shrink-0" />
|
|
208
|
-
{#if !compact}
|
|
221
|
+
{#if !compact}{$t('action.download')}{/if}
|
|
209
222
|
</Button>
|
|
223
|
+
{/if}
|
|
224
|
+
{#if capabilities.folders}
|
|
210
225
|
<Button
|
|
211
226
|
variant="ghost"
|
|
212
227
|
size="sm"
|
|
213
228
|
class="text-[hsl(var(--grey5))] {compact ? 'text-xs px-1.5' : 'text-sm'} font-semibold flex items-center gap-1.5 [&_svg]:size-5 hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
214
229
|
onclick={handleMove}
|
|
215
|
-
aria-label=
|
|
230
|
+
aria-label={$t('action.move')}
|
|
216
231
|
>
|
|
217
232
|
<IconArrowBounce class="w-4 h-4 shrink-0" />
|
|
218
|
-
{#if !compact}
|
|
233
|
+
{#if !compact}{$t('action.move')}{/if}
|
|
219
234
|
</Button>
|
|
235
|
+
{/if}
|
|
236
|
+
{#if capabilities.delete}
|
|
220
237
|
<Button
|
|
221
238
|
variant="ghost"
|
|
222
239
|
size="sm"
|
|
223
240
|
class="text-[hsl(var(--grey5))] {compact ? 'text-xs px-1.5' : 'text-sm'} font-semibold flex items-center gap-1.5 [&_svg]:size-5 hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
224
241
|
onclick={handleDelete}
|
|
225
|
-
aria-label=
|
|
242
|
+
aria-label={$t('action.delete')}
|
|
226
243
|
>
|
|
227
244
|
<IconTrash class="w-4 h-4 shrink-0" />
|
|
228
|
-
{#if !compact}
|
|
245
|
+
{#if !compact}{$t('action.delete')}{/if}
|
|
229
246
|
</Button>
|
|
247
|
+
{/if}
|
|
230
248
|
{:else}
|
|
231
249
|
<!-- Multiple files controls -->
|
|
232
250
|
{#if isWideViewport}
|
|
@@ -246,7 +264,7 @@
|
|
|
246
264
|
>
|
|
247
265
|
{#if getFilePreview(file) === 'font'}
|
|
248
266
|
<div class="w-6 h-6 flex items-center justify-center bg-gray-100">
|
|
249
|
-
<span style="font-family: '{file.name
|
|
267
|
+
<span style="font-family: '{toSafeFontFamilyName(file.name)}', sans-serif;" class="text-xs text-gray-700">
|
|
250
268
|
aA
|
|
251
269
|
</span>
|
|
252
270
|
</div>
|
|
@@ -273,7 +291,7 @@
|
|
|
273
291
|
{/each}
|
|
274
292
|
{#if selectedFiles.length > 2}
|
|
275
293
|
<div class="ml-[32px] pl-2 caption text-[hsl(var(--grey5))] widgetic-colors group-hover:text-[hsl(var(--grey7))] transition-colors duration-200">
|
|
276
|
-
|
|
294
|
+
{$t('toolbar.more', { count: selectedFiles.length - 2 })}
|
|
277
295
|
</div>
|
|
278
296
|
{:else if selectedFiles.length === 2}
|
|
279
297
|
<div class="w-[32px]"></div>
|
|
@@ -296,6 +314,7 @@
|
|
|
296
314
|
{confirmAddLabel}
|
|
297
315
|
</Button>
|
|
298
316
|
{/if}
|
|
317
|
+
{#if capabilities.folders}
|
|
299
318
|
<Button
|
|
300
319
|
variant="ghost"
|
|
301
320
|
size="sm"
|
|
@@ -303,8 +322,10 @@
|
|
|
303
322
|
onclick={handleMove}
|
|
304
323
|
>
|
|
305
324
|
<IconArrowBounce class="w-4 h-4" />
|
|
306
|
-
|
|
325
|
+
{$t('toolbar.moveMany', { count: selectedFiles.length })}
|
|
307
326
|
</Button>
|
|
327
|
+
{/if}
|
|
328
|
+
{#if capabilities.delete}
|
|
308
329
|
<Button
|
|
309
330
|
variant="ghost"
|
|
310
331
|
size="sm"
|
|
@@ -312,8 +333,9 @@
|
|
|
312
333
|
onclick={handleDelete}
|
|
313
334
|
>
|
|
314
335
|
<IconTrash class="w-4 h-4" />
|
|
315
|
-
|
|
336
|
+
{$t('toolbar.deleteMany', { count: selectedFiles.length })}
|
|
316
337
|
</Button>
|
|
338
|
+
{/if}
|
|
317
339
|
<Button
|
|
318
340
|
variant="ghost"
|
|
319
341
|
size="sm"
|
|
@@ -321,7 +343,7 @@
|
|
|
321
343
|
onclick={handleClearItems}
|
|
322
344
|
>
|
|
323
345
|
<IconCircleDashed class="w-4 h-4" />
|
|
324
|
-
|
|
346
|
+
{$t('action.clearItems')}
|
|
325
347
|
</Button>
|
|
326
348
|
{/if}
|
|
327
349
|
</div>
|
|
@@ -17,7 +17,7 @@ declare const ControlToolbar: $$__sveltets_2_IsomorphicComponent<{
|
|
|
17
17
|
selectedFiles?: FileSystemItem[];
|
|
18
18
|
currentFilter: FileFilterType;
|
|
19
19
|
showAddToEditor?: boolean;
|
|
20
|
-
/** Singular label for the primary confirm action (pluralized when count > 1). */ addToEditorLabel?: string;
|
|
20
|
+
/** Singular label for the primary confirm action (pluralized when count > 1). Left out, the File Browser's own ("Add to Editor", or the page's language's). */ addToEditorLabel?: string | undefined;
|
|
21
21
|
allowSelecting?: boolean;
|
|
22
22
|
filter?: FileFilterType;
|
|
23
23
|
/** When true, toolbar uses icon-only / shorter labels (narrow file-browser panel). */ compact?: boolean;
|
|
@@ -202,8 +202,8 @@
|
|
|
202
202
|
|
|
203
203
|
// Don't start drag if clicking on interactive elements except for preview buttons
|
|
204
204
|
const button = target.closest('button');
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
// The buttons that open a file's preview or a folder say so with a data attribute (their labels are in the page's language)
|
|
206
|
+
const isPreviewButton = button?.matches('[data-fb-action="preview"], [data-fb-action="open-folder"]') ?? false;
|
|
207
207
|
const isInteractive = (target.closest('button') && !isPreviewButton) ||
|
|
208
208
|
target.closest('input') ||
|
|
209
209
|
target.closest('a') ||
|
|
@@ -8,21 +8,37 @@
|
|
|
8
8
|
|
|
9
9
|
// Local utils imports
|
|
10
10
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
11
|
+
import { useMediaLibraryContext } from '../../mediaLibrary/context';
|
|
12
|
+
import { useI18n } from '../../i18n';
|
|
13
|
+
|
|
14
|
+
const { t } = useI18n();
|
|
11
15
|
|
|
12
16
|
// Props
|
|
13
17
|
export let isFolder: boolean;
|
|
14
18
|
export let fileUrl: string | undefined = undefined;
|
|
15
19
|
export let isMissing: boolean = false;
|
|
16
20
|
|
|
21
|
+
// Which actions the media library allows. Everything, when the File Browser works from its own settings.
|
|
22
|
+
const { capabilities } = useMediaLibraryContext();
|
|
23
|
+
|
|
24
|
+
// The actions this item gets: an action the library cannot do is not offered, rather than offered and failing.
|
|
25
|
+
$: canRename = capabilities.rename && !isMissing;
|
|
26
|
+
$: canMove = capabilities.folders && !isMissing;
|
|
27
|
+
$: canDownload = capabilities.download && !isMissing && !isFolder && !!fileUrl;
|
|
28
|
+
$: canDelete = capabilities.delete;
|
|
29
|
+
$: hasAnyAction = canRename || canMove || canDownload || canDelete;
|
|
30
|
+
|
|
17
31
|
function handleAction(action: string) {
|
|
18
32
|
if (action === 'download' && fileUrl) {
|
|
19
|
-
|
|
33
|
+
// noopener/noreferrer: the opened page gets no handle on this page (the file's host is not trusted).
|
|
34
|
+
window.open(fileUrl, '_blank', 'noopener,noreferrer');
|
|
20
35
|
} else {
|
|
21
36
|
dispatch('action', { action });
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
39
|
</script>
|
|
25
40
|
|
|
41
|
+
{#if hasAnyAction}
|
|
26
42
|
<div class="dropdown-wrapper">
|
|
27
43
|
<DropdownMenu.Root>
|
|
28
44
|
<DropdownMenu.Trigger>
|
|
@@ -31,8 +47,8 @@
|
|
|
31
47
|
class="more-options-button h-6 w-6 p-0 focus-visible:ring-0 focus-visible:ring-offset-0 hover:bg-[hsl(var(--grey1))]"
|
|
32
48
|
onclick={() => { /* console.log('Open More Options Dropdown'); */ }}
|
|
33
49
|
>
|
|
34
|
-
<span class="sr-only">
|
|
35
|
-
<img src={getAssetUrl('/icons/dots.svg')} alt=
|
|
50
|
+
<span class="sr-only">{$t('menu.open')}</span>
|
|
51
|
+
<img src={getAssetUrl('/icons/dots.svg')} alt={$t('menu.moreOptions')} class="h-4 w-4" />
|
|
36
52
|
</Button>
|
|
37
53
|
</DropdownMenu.Trigger>
|
|
38
54
|
<DropdownMenu.Content
|
|
@@ -40,25 +56,30 @@
|
|
|
40
56
|
align="end"
|
|
41
57
|
sideOffset={5}
|
|
42
58
|
>
|
|
43
|
-
{#if
|
|
59
|
+
{#if canRename}
|
|
44
60
|
<DropdownMenu.Item onclick={() => handleAction('rename')}>
|
|
45
|
-
|
|
61
|
+
{$t('action.rename')}
|
|
46
62
|
</DropdownMenu.Item>
|
|
63
|
+
{/if}
|
|
64
|
+
{#if canMove}
|
|
47
65
|
<DropdownMenu.Item onclick={() => handleAction('move')}>
|
|
48
|
-
|
|
66
|
+
{$t('action.move')}
|
|
67
|
+
</DropdownMenu.Item>
|
|
68
|
+
{/if}
|
|
69
|
+
{#if canDownload}
|
|
70
|
+
<DropdownMenu.Item onclick={() => handleAction('download')}>
|
|
71
|
+
{$t('action.download')}
|
|
72
|
+
</DropdownMenu.Item>
|
|
73
|
+
{/if}
|
|
74
|
+
{#if canDelete}
|
|
75
|
+
<DropdownMenu.Item onclick={() => handleAction('delete')}>
|
|
76
|
+
{$t('action.delete')}
|
|
49
77
|
</DropdownMenu.Item>
|
|
50
|
-
{#if !isFolder && fileUrl}
|
|
51
|
-
<DropdownMenu.Item onclick={() => handleAction('download')}>
|
|
52
|
-
Download
|
|
53
|
-
</DropdownMenu.Item>
|
|
54
|
-
{/if}
|
|
55
78
|
{/if}
|
|
56
|
-
<DropdownMenu.Item onclick={() => handleAction('delete')}>
|
|
57
|
-
Delete
|
|
58
|
-
</DropdownMenu.Item>
|
|
59
79
|
</DropdownMenu.Content>
|
|
60
80
|
</DropdownMenu.Root>
|
|
61
81
|
</div>
|
|
82
|
+
{/if}
|
|
62
83
|
|
|
63
84
|
<style>
|
|
64
85
|
.dropdown-wrapper {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { getFileIcon } from '../../utils/fileUtils';
|
|
4
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
5
|
+
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
4
6
|
|
|
5
|
-
export let file: { url?: string; name: string; thumbnail?: string };
|
|
7
|
+
export let file: { url?: string; name: string; thumbnail?: string; mimeType?: string };
|
|
6
8
|
export let size: 'sm' | 'md' | 'lg' = 'md';
|
|
7
9
|
|
|
8
10
|
let hasError = false;
|
|
9
11
|
let fontLoaded = false;
|
|
10
12
|
let fontFace: FontFace;
|
|
11
13
|
|
|
12
|
-
$: fileType =
|
|
14
|
+
$: fileType = getFileTypeOf(file);
|
|
13
15
|
$: isFont = fileType === 'font';
|
|
14
16
|
$: isSvg = fileType === 'svg';
|
|
15
|
-
|
|
17
|
+
// The name a font is registered and styled under; safe to put inside CSS (see safeText.ts).
|
|
18
|
+
$: fontName = toSafeFontFamilyName(file.name);
|
|
16
19
|
|
|
17
20
|
$: sizeClasses = {
|
|
18
21
|
sm: 'w-8 h-7',
|
|
@@ -23,7 +26,7 @@
|
|
|
23
26
|
onMount(async () => {
|
|
24
27
|
if (isFont && file.url) {
|
|
25
28
|
try {
|
|
26
|
-
fontFace = new FontFace(fontName,
|
|
29
|
+
fontFace = new FontFace(fontName, toCssUrlLiteral(file.url));
|
|
27
30
|
await fontFace.load();
|
|
28
31
|
document.fonts.add(fontFace);
|
|
29
32
|
fontLoaded = true;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { FileSystemItem } from '../../types';
|
|
3
|
-
import {
|
|
3
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
4
|
+
import { formatFileSize } from '../../utils/fileUtils';
|
|
5
|
+
import { useI18n } from '../../i18n';
|
|
6
|
+
import { kindWord } from '../../i18n/text';
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
const { t, locale } = useI18n();
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
if (bytes === 0) return '0 Bytes';
|
|
9
|
-
const k = 1024;
|
|
10
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
11
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
12
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
13
|
-
}
|
|
10
|
+
export let file: FileSystemItem;
|
|
14
11
|
|
|
15
|
-
$: fileType =
|
|
12
|
+
$: fileType = getFileTypeOf(file);
|
|
16
13
|
</script>
|
|
17
14
|
|
|
18
15
|
<div class="bg-gray-100 p-4 rounded-large widgetic-radius widgetic-colors">
|
|
19
|
-
<h3 class="text-lg subtext mb-2">
|
|
16
|
+
<h3 class="text-lg subtext mb-2">{$t('metadata.title')}</h3>
|
|
20
17
|
<ul class="space-y-2">
|
|
21
|
-
<li><strong>
|
|
22
|
-
<li><strong>
|
|
23
|
-
<li><strong>
|
|
24
|
-
<li><strong>
|
|
18
|
+
<li><strong>{$t('metadata.name')}</strong> {file.name}</li>
|
|
19
|
+
<li><strong>{$t('metadata.type')}</strong> {kindWord(fileType, $t)}</li>
|
|
20
|
+
<li><strong>{$t('metadata.size')}</strong> {file.size ? formatFileSize(file.size, $t, $locale) : $t('metadata.notAvailable')}</li>
|
|
21
|
+
<li><strong>{$t('metadata.modified')}</strong> {file.modified ? new Date(file.modified).toLocaleString($locale) : $t('metadata.notAvailable')}</li>
|
|
25
22
|
</ul>
|
|
26
23
|
</div>
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import type { FileSystemItem, FolderItemWithCount } from '../../types';
|
|
3
3
|
import { FileIcon } from './';
|
|
4
4
|
import { FolderItem } from '../items';
|
|
5
|
+
import { useI18n } from '../../i18n';
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n();
|
|
5
8
|
|
|
6
9
|
// Props
|
|
7
10
|
export let results: FileSystemItem[];
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
<!-- Display search results, showing either files or folders -->
|
|
22
25
|
<div class="space-y-2">
|
|
23
26
|
{#if results.length === 0}
|
|
24
|
-
<p class="text-center text-gray-600">
|
|
27
|
+
<p class="text-center text-gray-600">{$t('search.noResults')}</p>
|
|
25
28
|
{:else}
|
|
26
29
|
{#each results as item (item.name)}
|
|
27
30
|
{#if item.type === 'folder'}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Readable } from 'svelte/store';
|
|
2
|
+
import { type FileBrowserMessageKey } from './messages';
|
|
3
|
+
import { type MessageOverrides, type MessageValues } from './translator';
|
|
4
|
+
/** The function a screen calls to get its words: `t('upload.clear')`, `t('toast.deleted', { name })`. */
|
|
5
|
+
export type Translate = (key: FileBrowserMessageKey, values?: MessageValues) => string;
|
|
6
|
+
/**
|
|
7
|
+
* What the File Browser's parts need to speak the page's language, shared with them through Svelte's component
|
|
8
|
+
* context (the way the media library is, see `mediaLibrary/context.ts`).
|
|
9
|
+
*
|
|
10
|
+
* Both are stores, so a screen that is already open changes its words when the page calls `setLanguage()`.
|
|
11
|
+
*/
|
|
12
|
+
export interface I18nContext {
|
|
13
|
+
/** Turns a key into text. */
|
|
14
|
+
t: Readable<Translate>;
|
|
15
|
+
/** The language tag in use ("en" unless the page asked for another one that this browser knows). */
|
|
16
|
+
locale: Readable<string>;
|
|
17
|
+
}
|
|
18
|
+
/** What the page chose. Both are optional; a missing language is English. */
|
|
19
|
+
export interface I18nSettings {
|
|
20
|
+
/** A BCP 47 tag ("de", "pt-BR"): sets the plural rules and how numbers, dates and lists are written. */
|
|
21
|
+
locale?: string | null;
|
|
22
|
+
/** The page's own words: any of the catalog's keys. A key it leaves out keeps the English text. */
|
|
23
|
+
messages?: MessageOverrides | null;
|
|
24
|
+
}
|
|
25
|
+
/** The English `t`, for code that has no component around it (a helper called without a translator). */
|
|
26
|
+
export declare const translateEnglish: Translate;
|
|
27
|
+
/** What {@link provideI18n} gives back to the component that called it. */
|
|
28
|
+
export interface I18nHandle extends I18nContext {
|
|
29
|
+
/** Changes the language the parts below speak. Cheap to call on every change of the props. */
|
|
30
|
+
update(settings: I18nSettings): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Called by the File Browser while it is created, so everything inside it speaks the page's language.
|
|
34
|
+
* The context belongs to one File Browser, so two File Browsers on a page can speak two languages.
|
|
35
|
+
*/
|
|
36
|
+
export declare function provideI18n(initial: I18nSettings): I18nHandle;
|
|
37
|
+
/** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it speaks English. */
|
|
38
|
+
export declare function useI18n(): I18nContext;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { derived, readable, writable } from 'svelte/store';
|
|
3
|
+
import { FILE_BROWSER_MESSAGES } from './messages';
|
|
4
|
+
import { createTranslator, describeMessageProblem } from './translator';
|
|
5
|
+
const I18N_CONTEXT_KEY = Symbol('widgetic-file-browser-i18n');
|
|
6
|
+
/** How many different problems the console is told about, so a page that keeps changing its messages cannot fill memory. */
|
|
7
|
+
const MAX_REPORTED_PROBLEMS = 200;
|
|
8
|
+
const reportedProblems = new Set();
|
|
9
|
+
/** Says a problem with the page's messages in the console, once per page however often the language is set. */
|
|
10
|
+
function reportProblem(problem) {
|
|
11
|
+
const text = describeMessageProblem(problem);
|
|
12
|
+
if (reportedProblems.has(text) || reportedProblems.size >= MAX_REPORTED_PROBLEMS)
|
|
13
|
+
return;
|
|
14
|
+
reportedProblems.add(text);
|
|
15
|
+
console.warn(`[FileBrowser] ${text}`);
|
|
16
|
+
}
|
|
17
|
+
function translatorFor(settings) {
|
|
18
|
+
return createTranslator({
|
|
19
|
+
catalog: FILE_BROWSER_MESSAGES,
|
|
20
|
+
locale: settings.locale ?? undefined,
|
|
21
|
+
messages: settings.messages,
|
|
22
|
+
onProblem: reportProblem
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The English translator that a part of the File Browser uses when nothing above it chose a language. */
|
|
26
|
+
const ENGLISH_TRANSLATOR = translatorFor({});
|
|
27
|
+
const ENGLISH_CONTEXT = Object.freeze({
|
|
28
|
+
t: readable(ENGLISH_TRANSLATOR.t),
|
|
29
|
+
locale: readable(ENGLISH_TRANSLATOR.locale)
|
|
30
|
+
});
|
|
31
|
+
/** The English `t`, for code that has no component around it (a helper called without a translator). */
|
|
32
|
+
export const translateEnglish = ENGLISH_TRANSLATOR.t;
|
|
33
|
+
/**
|
|
34
|
+
* Called by the File Browser while it is created, so everything inside it speaks the page's language.
|
|
35
|
+
* The context belongs to one File Browser, so two File Browsers on a page can speak two languages.
|
|
36
|
+
*/
|
|
37
|
+
export function provideI18n(initial) {
|
|
38
|
+
const settings = writable(initial);
|
|
39
|
+
const translator = derived(settings, ($settings) => translatorFor($settings));
|
|
40
|
+
const t = derived(translator, ($translator) => $translator.t);
|
|
41
|
+
const locale = derived(translator, ($translator) => $translator.locale);
|
|
42
|
+
const context = { t, locale };
|
|
43
|
+
setContext(I18N_CONTEXT_KEY, context);
|
|
44
|
+
let lastSignature = signatureOf(initial);
|
|
45
|
+
return {
|
|
46
|
+
...context,
|
|
47
|
+
update(next) {
|
|
48
|
+
// Setting the same language again would rebuild every message for nothing.
|
|
49
|
+
const signature = signatureOf(next);
|
|
50
|
+
if (signature === lastSignature)
|
|
51
|
+
return;
|
|
52
|
+
lastSignature = signature;
|
|
53
|
+
settings.set(next);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Two settings are the same language when they have the same locale and the same words. */
|
|
58
|
+
function signatureOf(settings) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.stringify([settings.locale ?? null, settings.messages ?? null]);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Not serializable (a cycle, a BigInt): treat it as new every time rather than guess.
|
|
64
|
+
return `${Math.random()}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Called by a part of the File Browser while it is created. Never throws; outside a File Browser it speaks English. */
|
|
68
|
+
export function useI18n() {
|
|
69
|
+
return getContext(I18N_CONTEXT_KEY) ?? ENGLISH_CONTEXT;
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Translate } from './context';
|
|
2
|
+
import type { FileBrowserMessageKey } from './messages';
|
|
3
|
+
/**
|
|
4
|
+
* The sentence a visitor reads for a failure.
|
|
5
|
+
*
|
|
6
|
+
* - A media library's own words are shown as they are (the library knows its reasons: "File too large").
|
|
7
|
+
* - The File Browser's own sentence for a library failure is shown in the visitor's language (`messageKey`).
|
|
8
|
+
* - Any other error keeps its message, as it always has.
|
|
9
|
+
* - With nothing to say, `fallbackKey`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function messageForVisitor(error: unknown, t: Translate, fallbackKey?: FileBrowserMessageKey): string;
|