@widgetic/file-browser 0.5.24 → 0.5.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -0
- package/dist/components/FolderTree.svelte +16 -9
- package/dist/components/FolderTree.svelte.d.ts +2 -6
- package/dist/components/core/FileBrowser.svelte +529 -127
- package/dist/components/core/FileBrowser.svelte.d.ts +40 -1
- package/dist/components/core/FileUploader.svelte +130 -57
- package/dist/components/core/Header.svelte +13 -2
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +41 -29
- package/dist/components/core/UploadStatus.svelte +14 -7
- package/dist/components/core/UploadStatusList.svelte +13 -21
- package/dist/components/items/FileItem.svelte +28 -15
- package/dist/components/items/FolderItem.svelte +13 -6
- package/dist/components/modals/MoveDialog.svelte +49 -38
- package/dist/components/modals/NewFolderButton.svelte +5 -2
- package/dist/components/modals/SearchModal.svelte +25 -26
- package/dist/components/modals/SearchModal.svelte.d.ts +1 -1
- package/dist/components/modals/SelectedFilesModal.svelte +23 -14
- 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 +25 -9
- 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 +11 -7
- package/dist/components/ui/ControlToolbar.svelte +50 -28
- package/dist/components/ui/ControlToolbar.svelte.d.ts +1 -1
- package/dist/components/ui/DragSelect.svelte +3 -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 +16 -15
- package/dist/components/ui/SearchResults.svelte +9 -2
- package/dist/i18n/context.d.ts +28 -0
- package/dist/i18n/context.js +17 -0
- package/dist/i18n/errors.d.ts +11 -0
- package/dist/i18n/errors.js +19 -0
- package/dist/i18n/index.d.ts +15 -0
- package/dist/i18n/index.js +18 -0
- package/dist/i18n/messages.d.ts +281 -0
- package/dist/i18n/messages.js +294 -0
- package/dist/i18n/text.d.ts +19 -0
- package/dist/i18n/text.js +35 -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 +2 -2
- package/dist/stores/folderCountStore.js +2 -2
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.d.ts +11 -1
- 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/previewKeys.d.ts +12 -0
- package/dist/utils/previewKeys.js +14 -0
- 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 +5 -2
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
// Design System Components imports
|
|
13
13
|
import { BaseModal, PDFViewer } from '@widgetic/design-system/components';
|
|
14
|
+
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
14
15
|
|
|
15
16
|
// Local Components imports
|
|
16
17
|
import { ImagePreview, VideoPlayer, AudioPlayer, ErrorPreview, FontPreview, TextPreview } from './';
|
|
@@ -20,12 +21,19 @@
|
|
|
20
21
|
import type { FileSystemItem } from '../../types';
|
|
21
22
|
|
|
22
23
|
// Utils
|
|
23
|
-
import {
|
|
24
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
25
|
+
import { toSafeFontFamilyName } from '../../utils/safeText';
|
|
26
|
+
import { previewKeyAction } from '../../utils/previewKeys';
|
|
24
27
|
|
|
25
28
|
// Stores
|
|
26
29
|
import { missingFiles } from '../../stores/missingFilesStore';
|
|
27
30
|
import { validSelections } from '../../stores/persistentSelectStore';
|
|
28
31
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
32
|
+
import { useI18n } from '../../i18n';
|
|
33
|
+
|
|
34
|
+
const { t } = useI18n();
|
|
35
|
+
// The reading direction the File Browser is laid out in: the arrow keys follow it.
|
|
36
|
+
const textDirection = useTextDirection();
|
|
29
37
|
|
|
30
38
|
// Component props
|
|
31
39
|
export let file: FileSystemItem;
|
|
@@ -175,7 +183,9 @@
|
|
|
175
183
|
function handleKeydown(event: KeyboardEvent) {
|
|
176
184
|
if (!open || !allowSelecting) return;
|
|
177
185
|
|
|
178
|
-
|
|
186
|
+
// The arrow keys follow the reading direction: the left arrow is "previous" in English and "next" in Arabic.
|
|
187
|
+
const keyAction = previewKeyAction(event.key, $textDirection);
|
|
188
|
+
if (keyAction === 'previous') {
|
|
179
189
|
event.preventDefault();
|
|
180
190
|
// console.log('Left arrow pressed, current index:', currentIndex);
|
|
181
191
|
const prevFile = findNextAvailableFile(currentIndex, 'prev');
|
|
@@ -183,7 +193,7 @@
|
|
|
183
193
|
// console.log('Navigating to previous file:', prevFile.name);
|
|
184
194
|
dispatch('navigate', prevFile);
|
|
185
195
|
}
|
|
186
|
-
} else if (
|
|
196
|
+
} else if (keyAction === 'next') {
|
|
187
197
|
event.preventDefault();
|
|
188
198
|
// console.log('Right arrow pressed, current index:', currentIndex);
|
|
189
199
|
const nextFile = findNextAvailableFile(currentIndex, 'next');
|
|
@@ -235,10 +245,10 @@
|
|
|
235
245
|
// when file changes, update the file type, url, and valid url
|
|
236
246
|
$: {
|
|
237
247
|
if(showLogs) console.log('FilePreview: file changed reactive statement:', file);
|
|
238
|
-
fileType =
|
|
248
|
+
fileType = getFileTypeOf(file);
|
|
239
249
|
fileUrl = file.url || '';
|
|
240
250
|
hasValidUrl = !!file.url && fileUrl.length > 0 && !$missingFiles.has(file.id);
|
|
241
|
-
fontName = file.name
|
|
251
|
+
fontName = toSafeFontFamilyName(file.name);
|
|
242
252
|
}
|
|
243
253
|
|
|
244
254
|
let videoElement: HTMLVideoElement;
|
|
@@ -314,6 +324,7 @@
|
|
|
314
324
|
class="file-preview-modal"
|
|
315
325
|
bind:open
|
|
316
326
|
title={file.name}
|
|
327
|
+
closeLabel={$t('dialog.close')}
|
|
317
328
|
width={modalDimensions.width}
|
|
318
329
|
height={modalDimensions.height}
|
|
319
330
|
{target}
|
|
@@ -336,10 +347,10 @@
|
|
|
336
347
|
allowSelecting = event.detail.allowSelecting;
|
|
337
348
|
|
|
338
349
|
// Re-trigger file type checks and URL validation
|
|
339
|
-
fileType =
|
|
350
|
+
fileType = getFileTypeOf(file);
|
|
340
351
|
fileUrl = file.url || '';
|
|
341
352
|
hasValidUrl = !!file.url && fileUrl.length > 0 && !$missingFiles.has(file.id);
|
|
342
|
-
fontName = file.name
|
|
353
|
+
fontName = toSafeFontFamilyName(file.name);
|
|
343
354
|
|
|
344
355
|
// Reset image loaded state when file changes
|
|
345
356
|
imageLoaded = false;
|
|
@@ -357,7 +368,7 @@
|
|
|
357
368
|
<FontPreview
|
|
358
369
|
src={fileUrl}
|
|
359
370
|
{fontName}
|
|
360
|
-
previewText={file.previewText ||
|
|
371
|
+
previewText={file.previewText || undefined}
|
|
361
372
|
/>
|
|
362
373
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
363
374
|
{#if fileType === 'svg'}
|
|
@@ -435,11 +446,16 @@
|
|
|
435
446
|
<PDFViewer class="fb-pdf-viewer"
|
|
436
447
|
url={fileUrl}
|
|
437
448
|
enableCacheClearing={true}
|
|
449
|
+
loadingLabel={$t('preview.pdfLoading')}
|
|
450
|
+
failedLabel={$t('preview.pdfFailed')}
|
|
451
|
+
pageLabel={$t('preview.pdfPage', { page: '{page}', total: '{total}' })}
|
|
452
|
+
previousPageLabel={$t('preview.pdfPreviousPage')}
|
|
453
|
+
nextPageLabel={$t('preview.pdfNextPage')}
|
|
438
454
|
on:error={(e) => pdfLoadError = e.detail.message || 'Error loading PDF'}
|
|
439
455
|
on:cacheCleared={() => { /* console.log('PDF cache cleared from FilePreview'); */ }}
|
|
440
456
|
/>
|
|
441
457
|
{:else}
|
|
442
|
-
<p class="no-preview-container text-center py-8">
|
|
458
|
+
<p class="no-preview-container text-center py-8">{$t('preview.unavailable')}</p>
|
|
443
459
|
{/if}
|
|
444
460
|
|
|
445
461
|
<!-- File Metadata Display -->
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
3
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
4
|
+
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
5
|
+
import { useI18n } from '../../i18n';
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n();
|
|
4
8
|
|
|
5
9
|
export let src: string;
|
|
6
10
|
export let fontName: string;
|
|
7
|
-
|
|
11
|
+
/** The sentence shown in the font. Left out, a pangram in the page's language ("The quick brown fox jumps over the lazy dog"). */
|
|
12
|
+
export let previewText: string | undefined = undefined;
|
|
8
13
|
|
|
9
14
|
let hasError = false;
|
|
10
15
|
let fontLoaded = false;
|
|
11
16
|
let fontFace: FontFace;
|
|
12
17
|
|
|
18
|
+
// The name goes inside CSS, so it is reduced to safe characters here too (it is the same name FilePreview
|
|
19
|
+
// passes in, since the reduction gives the same result when repeated).
|
|
20
|
+
$: safeFontName = toSafeFontFamilyName(fontName);
|
|
21
|
+
|
|
13
22
|
onMount(async () => {
|
|
14
23
|
try {
|
|
15
24
|
// Create a new FontFace object
|
|
16
|
-
fontFace = new FontFace(
|
|
25
|
+
fontFace = new FontFace(safeFontName, toCssUrlLiteral(src));
|
|
17
26
|
|
|
18
27
|
// Wait for the font to load
|
|
19
28
|
await fontFace.load();
|
|
@@ -36,7 +45,7 @@
|
|
|
36
45
|
<div class="flex flex-col items-center space-y-4">
|
|
37
46
|
<!-- <h3 class="text-lg font-medium text-gray-700">{fontName}</h3> -->
|
|
38
47
|
<div
|
|
39
|
-
style="font-family: '{
|
|
48
|
+
style="font-family: '{safeFontName}', sans-serif;"
|
|
40
49
|
class="text-6xl {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
|
|
41
50
|
>
|
|
42
51
|
aA
|
|
@@ -49,10 +58,10 @@
|
|
|
49
58
|
<div class="space-y-2">
|
|
50
59
|
<p class="text-sm text-gray-500">32px</p>
|
|
51
60
|
<p
|
|
52
|
-
style="font-family: '{
|
|
61
|
+
style="font-family: '{safeFontName}', sans-serif; font-size: 32px;"
|
|
53
62
|
class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
|
|
54
63
|
>
|
|
55
|
-
{previewText}
|
|
64
|
+
{previewText ?? $t('fontPreview.sample')}
|
|
56
65
|
</p>
|
|
57
66
|
</div>
|
|
58
67
|
|
|
@@ -60,10 +69,10 @@
|
|
|
60
69
|
<div class="space-y-2">
|
|
61
70
|
<p class="text-sm text-gray-500">24px</p>
|
|
62
71
|
<p
|
|
63
|
-
style="font-family: '{
|
|
72
|
+
style="font-family: '{safeFontName}', sans-serif; font-size: 24px;"
|
|
64
73
|
class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
|
|
65
74
|
>
|
|
66
|
-
{previewText}
|
|
75
|
+
{previewText ?? $t('fontPreview.sample')}
|
|
67
76
|
</p>
|
|
68
77
|
</div>
|
|
69
78
|
|
|
@@ -71,10 +80,10 @@
|
|
|
71
80
|
<div class="space-y-2">
|
|
72
81
|
<p class="text-sm text-gray-500">16px</p>
|
|
73
82
|
<p
|
|
74
|
-
style="font-family: '{
|
|
83
|
+
style="font-family: '{safeFontName}', sans-serif; font-size: 16px;"
|
|
75
84
|
class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
|
|
76
85
|
>
|
|
77
|
-
{previewText}
|
|
86
|
+
{previewText ?? $t('fontPreview.sample')}
|
|
78
87
|
</p>
|
|
79
88
|
</div>
|
|
80
89
|
</div>
|
|
@@ -14,7 +14,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
14
14
|
declare const FontPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
15
15
|
src: string;
|
|
16
16
|
fontName: string;
|
|
17
|
-
previewText?: string;
|
|
17
|
+
/** The sentence shown in the font. Left out, a pangram in the page's language ("The quick brown fox jumps over the lazy dog"). */ previewText?: string | undefined;
|
|
18
18
|
}, {
|
|
19
19
|
[evt: string]: CustomEvent<any>;
|
|
20
20
|
}, {}, {}, string>;
|
|
@@ -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,25 +178,26 @@
|
|
|
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 -->
|
|
182
185
|
<div
|
|
183
|
-
class="custom-video-controls absolute bottom-0
|
|
186
|
+
class="custom-video-controls absolute bottom-0 inset-x-0 flex flex-col transition-opacity duration-300 bg-gradient-to-t from-black/60 to-transparent p-2"
|
|
184
187
|
class:opacity-0={!showControls && isPlaying}
|
|
185
188
|
class:pointer-events-none={!showControls && isPlaying}
|
|
186
189
|
>
|
|
187
190
|
<!-- Progress bar -->
|
|
188
191
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
189
192
|
<div
|
|
193
|
+
dir="ltr"
|
|
190
194
|
class="relative h-1 w-full bg-white/30 mb-3 cursor-pointer rounded-full"
|
|
191
195
|
bind:this={progressBarContainer}
|
|
192
196
|
onmousedown={startDragging}
|
|
193
197
|
onclick={handleProgressClick}
|
|
194
198
|
>
|
|
195
199
|
<div
|
|
196
|
-
class="absolute top-0
|
|
200
|
+
class="absolute top-0 start-0 h-full bg-white rounded-full"
|
|
197
201
|
style="width: {(currentTime / duration) * 100}%"
|
|
198
202
|
></div>
|
|
199
203
|
</div>
|
|
@@ -206,7 +210,7 @@
|
|
|
206
210
|
<button
|
|
207
211
|
onclick={togglePlay}
|
|
208
212
|
class="flex items-center justify-center w-8 h-8 text-white focus:outline-none"
|
|
209
|
-
aria-label={isPlaying ?
|
|
213
|
+
aria-label={isPlaying ? $t('action.pause') : $t('action.play')}
|
|
210
214
|
>
|
|
211
215
|
{#if isPlaying}
|
|
212
216
|
<!-- Pause icon -->
|
|
@@ -233,7 +237,7 @@
|
|
|
233
237
|
<button
|
|
234
238
|
onclick={toggleMute}
|
|
235
239
|
class="flex items-center justify-center w-8 h-8 text-white focus:outline-none"
|
|
236
|
-
aria-label={isMuted ?
|
|
240
|
+
aria-label={isMuted ? $t('action.unmute') : $t('action.mute')}
|
|
237
241
|
>
|
|
238
242
|
{#if isMuted}
|
|
239
243
|
<!-- Muted icon -->
|
|
@@ -257,7 +261,7 @@
|
|
|
257
261
|
<button
|
|
258
262
|
onclick={togglePlay}
|
|
259
263
|
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=
|
|
264
|
+
aria-label={$t('action.play')}
|
|
261
265
|
>
|
|
262
266
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-10 h-10">
|
|
263
267
|
<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
|
-
<IconArrowBounce class="w-4 h-4 shrink-0" />
|
|
218
|
-
{#if !compact}
|
|
232
|
+
<IconArrowBounce class="w-4 h-4 shrink-0 rtl:-scale-x-100" />
|
|
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}
|
|
@@ -237,16 +255,16 @@
|
|
|
237
255
|
role="button"
|
|
238
256
|
tabindex="0"
|
|
239
257
|
>
|
|
240
|
-
<div class="relative h-6 flex items-center
|
|
258
|
+
<div class="relative h-6 flex items-center pe-2">
|
|
241
259
|
{#if selectedFiles.length > 0}
|
|
242
260
|
{#each selectedFiles.slice(0, 2) as file, i}
|
|
243
261
|
<div
|
|
244
262
|
class="w-6 h-6 rounded-[var(--radius-small)] border border-gray-200 bg-white overflow-hidden absolute widgetic-radius"
|
|
245
|
-
style="
|
|
263
|
+
style="inset-inline-start: {i * 12}px; z-index: {2 - i};"
|
|
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>
|
|
@@ -272,8 +290,8 @@
|
|
|
272
290
|
</div>
|
|
273
291
|
{/each}
|
|
274
292
|
{#if selectedFiles.length > 2}
|
|
275
|
-
<div class="
|
|
276
|
-
|
|
293
|
+
<div class="ms-[32px] ps-2 caption text-[hsl(var(--grey5))] widgetic-colors group-hover:text-[hsl(var(--grey7))] transition-colors duration-200">
|
|
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,15 +314,18 @@
|
|
|
296
314
|
{confirmAddLabel}
|
|
297
315
|
</Button>
|
|
298
316
|
{/if}
|
|
317
|
+
{#if capabilities.folders}
|
|
299
318
|
<Button
|
|
300
319
|
variant="ghost"
|
|
301
320
|
size="sm"
|
|
302
321
|
class="text-[hsl(var(--grey5))] h6 flex items-center gap-2 [&_svg]:size-5 widgetic-colors hover:text-[hsl(var(--grey7))] hover:bg-[hsl(var(--grey1))] transition-colors duration-200"
|
|
303
322
|
onclick={handleMove}
|
|
304
323
|
>
|
|
305
|
-
<IconArrowBounce class="w-4 h-4" />
|
|
306
|
-
|
|
324
|
+
<IconArrowBounce class="w-4 h-4 rtl:-scale-x-100" />
|
|
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') ||
|
|
@@ -665,6 +665,7 @@
|
|
|
665
665
|
|
|
666
666
|
// Apply the calculated position and dimensions
|
|
667
667
|
selectionBox.style.display = 'block';
|
|
668
|
+
// rtl-ok: the box is drawn between two pointer positions, measured from the left edge of the list
|
|
668
669
|
selectionBox.style.left = `${left}px`;
|
|
669
670
|
selectionBox.style.top = `${top}px`;
|
|
670
671
|
selectionBox.style.width = `${width}px`;
|
|
@@ -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 {
|