@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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Svelte imports
|
|
3
3
|
import { createEventDispatcher } from 'svelte';
|
|
4
4
|
const dispatch = createEventDispatcher();
|
|
5
|
+
const { t } = useI18n();
|
|
5
6
|
|
|
6
7
|
// Design system imports
|
|
7
8
|
import { Button, toast, BaseModal, WScrollArea } from '@widgetic/design-system/components';
|
|
@@ -17,6 +18,8 @@
|
|
|
17
18
|
import { getFileType } from '../../utils/fileUtils';
|
|
18
19
|
import { moveItem, findItemById } from '../../utils/fileOperations';
|
|
19
20
|
import { ENDPOINTS, logApiRequest } from '../../utils/apiConfig';
|
|
21
|
+
import { useI18n, messageForVisitor } from '../../i18n';
|
|
22
|
+
import { MediaLibraryError } from '../../mediaLibrary/errors';
|
|
20
23
|
|
|
21
24
|
// Local stores imports
|
|
22
25
|
import { folderCounts, updateFolderCounts } from '../../stores/folderCountStore';
|
|
@@ -122,6 +125,19 @@
|
|
|
122
125
|
return getFolderIcon(folderWithCount, currentFilter);
|
|
123
126
|
}
|
|
124
127
|
|
|
128
|
+
/** A name as the dialog's title shows it: cut at 30 characters. */
|
|
129
|
+
function shortNameOf(name: string | undefined): string {
|
|
130
|
+
const text = name ?? '';
|
|
131
|
+
return text.length > 30 ? text.slice(0, 30) + '...' : text;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The headline of a failed move: about the folder when one folder was being moved, else about the items. */
|
|
135
|
+
function failedMoveTitle(): string {
|
|
136
|
+
return sourceItems.length === 1 && sourceItems[0]?.type === 'folder'
|
|
137
|
+
? $t('moveDialog.failedFolder')
|
|
138
|
+
: $t('moveDialog.failedItems');
|
|
139
|
+
}
|
|
140
|
+
|
|
125
141
|
/**
|
|
126
142
|
* Handles the move operation and triggers animations
|
|
127
143
|
* @param targetFolderId ID of the destination folder
|
|
@@ -135,11 +151,9 @@
|
|
|
135
151
|
|
|
136
152
|
if (!targetFolderId) {
|
|
137
153
|
toast.error(
|
|
138
|
-
|
|
139
|
-
? 'Failed to move folder'
|
|
140
|
-
: 'Failed to move items',
|
|
154
|
+
failedMoveTitle(),
|
|
141
155
|
{
|
|
142
|
-
description: '
|
|
156
|
+
description: $t('moveDialog.noTarget'),
|
|
143
157
|
position: 'bottom-center',
|
|
144
158
|
class: 'file-browser-sonar',
|
|
145
159
|
duration: 2000
|
|
@@ -150,9 +164,9 @@
|
|
|
150
164
|
|
|
151
165
|
if (sourceItems.length === 0) {
|
|
152
166
|
toast.error(
|
|
153
|
-
'
|
|
167
|
+
$t('moveDialog.failedItems'),
|
|
154
168
|
{
|
|
155
|
-
description: '
|
|
169
|
+
description: $t('moveDialog.noItems'),
|
|
156
170
|
position: 'bottom-center',
|
|
157
171
|
class: 'file-browser-sonar',
|
|
158
172
|
duration: 2000
|
|
@@ -243,8 +257,8 @@
|
|
|
243
257
|
if (movedItems.length > 0) {
|
|
244
258
|
// Show appropriate toast based on success/partial success
|
|
245
259
|
if (movedItems.length < sourceItems.length) {
|
|
246
|
-
toast.warning('
|
|
247
|
-
description:
|
|
260
|
+
toast.warning($t('moveDialog.partialTitle'), {
|
|
261
|
+
description: $t('moveDialog.partialDetail', { moved: movedItems.length, total: sourceItems.length }),
|
|
248
262
|
position: 'bottom-center',
|
|
249
263
|
class: 'file-browser-sonar',
|
|
250
264
|
duration: 2000
|
|
@@ -252,11 +266,11 @@
|
|
|
252
266
|
} else {
|
|
253
267
|
const isFolder = sourceItems.length === 1 && sourceItems[0].type === 'folder';
|
|
254
268
|
toast.success(
|
|
255
|
-
isFolder ?
|
|
269
|
+
isFolder ? $t('moveDialog.doneFolder') : sourceItems.length === 1 ? $t('moveDialog.doneOne') : $t('moveDialog.doneMany'),
|
|
256
270
|
{
|
|
257
271
|
description: isFolder
|
|
258
|
-
?
|
|
259
|
-
:
|
|
272
|
+
? $t('moveDialog.doneFolderDetail', { name: sourceItems[0].name })
|
|
273
|
+
: $t('moveDialog.doneItemsDetail', { count: sourceItems.length }),
|
|
260
274
|
position: 'bottom-center',
|
|
261
275
|
class: 'file-browser-sonar',
|
|
262
276
|
duration: 2000
|
|
@@ -274,15 +288,15 @@
|
|
|
274
288
|
selectedFolder = undefined;
|
|
275
289
|
isOpen = false;
|
|
276
290
|
} else {
|
|
277
|
-
|
|
291
|
+
// The File Browser's own sentence: the visitor reads it in the page's language, the console keeps the English
|
|
292
|
+
throw new MediaLibraryError('FAILED', 'No items were moved successfully', { messageKey: 'moveDialog.noneMoved' });
|
|
278
293
|
}
|
|
279
294
|
} catch (error) {
|
|
280
295
|
console.error('Error moving items:', error);
|
|
281
|
-
const isFolder = sourceItems.length === 1 && sourceItems[0].type === 'folder';
|
|
282
296
|
toast.error(
|
|
283
|
-
|
|
297
|
+
failedMoveTitle(),
|
|
284
298
|
{
|
|
285
|
-
description: error
|
|
299
|
+
description: messageForVisitor(error, $t),
|
|
286
300
|
position: 'bottom-center',
|
|
287
301
|
class: 'file-browser-sonar',
|
|
288
302
|
duration: 2000
|
|
@@ -296,11 +310,9 @@
|
|
|
296
310
|
handleMove(selectedFolder.id);
|
|
297
311
|
} else {
|
|
298
312
|
toast.error(
|
|
299
|
-
|
|
300
|
-
? 'Failed to move folder'
|
|
301
|
-
: 'Failed to move items',
|
|
313
|
+
failedMoveTitle(),
|
|
302
314
|
{
|
|
303
|
-
description: '
|
|
315
|
+
description: $t('moveDialog.pickDestination'),
|
|
304
316
|
position: 'bottom-center',
|
|
305
317
|
class: 'file-browser-sonar',
|
|
306
318
|
duration: 2000
|
|
@@ -324,17 +336,16 @@
|
|
|
324
336
|
<BaseModal class="move-modal"
|
|
325
337
|
bind:open={isOpen}
|
|
326
338
|
on:close={handleClose}
|
|
339
|
+
closeLabel={$t('dialog.close')}
|
|
327
340
|
{target}
|
|
328
341
|
width="566px"
|
|
329
342
|
height="496px"
|
|
330
343
|
titlePadding="small"
|
|
331
344
|
showScroll={false}
|
|
332
345
|
title={
|
|
333
|
-
sourceItems.length === 1
|
|
334
|
-
?
|
|
335
|
-
: sourceItems.length
|
|
336
|
-
? `Move "${sourceItems[0]?.name.length > 30 ? sourceItems[0]?.name.slice(0, 30) + '...' : sourceItems[0]?.name}"`
|
|
337
|
-
: `Move ${sourceItems.length} items`
|
|
346
|
+
sourceItems.length === 1
|
|
347
|
+
? $t('moveDialog.titleOne', { name: shortNameOf(sourceItems[0]?.name) })
|
|
348
|
+
: $t('moveDialog.titleMany', { count: sourceItems.length })
|
|
338
349
|
}
|
|
339
350
|
modalType="move"
|
|
340
351
|
modalData={{
|
|
@@ -400,7 +411,7 @@
|
|
|
400
411
|
size: 0,
|
|
401
412
|
matchingFileCount: counts.get('root') || 0
|
|
402
413
|
}, currentFilter)}
|
|
403
|
-
alt=
|
|
414
|
+
alt={$t('moveDialog.rootName')}
|
|
404
415
|
width="62"
|
|
405
416
|
height="54"
|
|
406
417
|
style="width: 62px; height: 54px; object-fit: contain;"
|
|
@@ -408,10 +419,10 @@
|
|
|
408
419
|
/>
|
|
409
420
|
</div>
|
|
410
421
|
</div>
|
|
411
|
-
<span class="body-medium truncate flex-grow text-left {immediateParentId === null ? 'text-[hsl(var(--grey3))]' : 'text-[hsl(var(--grey7))]'} {selectedFolder?.id === 'root' ? 'font-bold' : 'font-normal'}">
|
|
422
|
+
<span class="body-medium truncate flex-grow text-left {immediateParentId === null ? 'text-[hsl(var(--grey3))]' : 'text-[hsl(var(--grey7))]'} {selectedFolder?.id === 'root' ? 'font-bold' : 'font-normal'}">{$t('moveDialog.rootName')}</span>
|
|
412
423
|
<div class="flex items-center ml-auto">
|
|
413
424
|
{#if immediateParentId === null}
|
|
414
|
-
<span class="h6 text-[hsl(var(--sage-green))] relative z-10 mr-6">
|
|
425
|
+
<span class="h6 text-[hsl(var(--sage-green))] relative z-10 mr-6">{$t('folder.currentLocation')}</span>
|
|
415
426
|
{/if}
|
|
416
427
|
{#if selectedFolder?.id === 'root'}
|
|
417
428
|
<IconArrowBounce class="w-6 h-6 text-[hsl(var(--info))] mr-6" />
|
|
@@ -450,7 +461,7 @@
|
|
|
450
461
|
<!-- Results Count -->
|
|
451
462
|
<div class="results-count text-[hsl(var(--grey5))] subtext">
|
|
452
463
|
{#if selectedFolder && selectedFolder.id !== immediateParentId}
|
|
453
|
-
|
|
464
|
+
{$t('moveDialog.movingTo', { name: selectedFolder.name })}
|
|
454
465
|
{/if}
|
|
455
466
|
</div>
|
|
456
467
|
|
|
@@ -461,7 +472,7 @@
|
|
|
461
472
|
class="modal-btn-secondary !h-[34px]"
|
|
462
473
|
onclick={handleClose}
|
|
463
474
|
>
|
|
464
|
-
<span>
|
|
475
|
+
<span>{$t('action.cancel')}</span>
|
|
465
476
|
</Button>
|
|
466
477
|
|
|
467
478
|
<!-- Move Button -->
|
|
@@ -471,11 +482,11 @@
|
|
|
471
482
|
class="modal-btn-primary !h-[34px]"
|
|
472
483
|
>
|
|
473
484
|
{#if sourceItems.length === 1 && sourceItems[0]?.type === 'folder'}
|
|
474
|
-
<span>
|
|
485
|
+
<span>{$t('moveDialog.confirmFolder')}</span>
|
|
475
486
|
{:else if sourceItems.length === 1}
|
|
476
|
-
<span>
|
|
487
|
+
<span>{$t('moveDialog.confirmItem')}</span>
|
|
477
488
|
{:else}
|
|
478
|
-
<span>
|
|
489
|
+
<span>{$t('moveDialog.confirmMany', { count: sourceItems.length })}</span>
|
|
479
490
|
{/if}
|
|
480
491
|
</Button>
|
|
481
492
|
</div>
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
// Local utils imports
|
|
7
7
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
8
|
+
import { useI18n } from '../../i18n';
|
|
9
|
+
|
|
10
|
+
const { t } = useI18n();
|
|
8
11
|
|
|
9
12
|
// Event handlers
|
|
10
13
|
function handleClick() {
|
|
@@ -18,8 +21,8 @@
|
|
|
18
21
|
on:click={handleClick}
|
|
19
22
|
>
|
|
20
23
|
<div class="new-folder-icon-ct w-[62px] h-[54px] flex items-center justify-center shrink-0">
|
|
21
|
-
<img src={getAssetUrl('/icons/new-folder.svg')} alt=
|
|
24
|
+
<img src={getAssetUrl('/icons/new-folder.svg')} alt={$t('newFolder.alt')} class="w-full h-full object-contain" />
|
|
22
25
|
</div>
|
|
23
|
-
<h3 class="new-folder-label body-medium text-[hsl(var(--deep-forest-green))] text-sm text-center line-clamp-2 break-words px-1">
|
|
26
|
+
<h3 class="new-folder-label body-medium text-[hsl(var(--deep-forest-green))] text-sm text-center line-clamp-2 break-words px-1">{$t('newFolder.label')}</h3>
|
|
24
27
|
</button>
|
|
25
28
|
</div>
|
|
@@ -31,11 +31,16 @@
|
|
|
31
31
|
import type { FileSystemItem } from '../../types';
|
|
32
32
|
|
|
33
33
|
// Local utils imports
|
|
34
|
-
import {
|
|
34
|
+
import { getFileIcon } from '../../utils/fileUtils';
|
|
35
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
35
36
|
import { getFolderIcon } from '../../utils/folderUtils';
|
|
36
37
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
37
38
|
//
|
|
38
39
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
40
|
+
import { highlightMatchesAsHtml } from '../../utils/safeText';
|
|
41
|
+
import { useI18n } from '../../i18n';
|
|
42
|
+
|
|
43
|
+
const { t } = useI18n();
|
|
39
44
|
|
|
40
45
|
// Props for filtering search results
|
|
41
46
|
export let currentFilter: FileFilterType = 'all';
|
|
@@ -163,20 +168,9 @@
|
|
|
163
168
|
* @returns Safely escaped HTML string with highlighted match
|
|
164
169
|
*/
|
|
165
170
|
function highlightMatch(name: string, term: string): string {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
'&': '&',
|
|
170
|
-
'<': '<',
|
|
171
|
-
'>': '>',
|
|
172
|
-
'"': '"',
|
|
173
|
-
"'": '''
|
|
174
|
-
}[char] || char));
|
|
175
|
-
|
|
176
|
-
const escapedTerm = term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
177
|
-
const regex = new RegExp(`(${escapedTerm})`, 'gi');
|
|
178
|
-
|
|
179
|
-
return escapedName.replace(regex, '<span class="text-[hsl(var(--sage-green))]">$1</span>');
|
|
171
|
+
// The name is escaped on every path, including an empty term: it is written by someone else and is rendered
|
|
172
|
+
// with {@html}, so it must never reach the page as markup.
|
|
173
|
+
return highlightMatchesAsHtml(name, term, 'text-[hsl(var(--sage-green))]');
|
|
180
174
|
}
|
|
181
175
|
|
|
182
176
|
/**
|
|
@@ -241,7 +235,7 @@
|
|
|
241
235
|
// console.log('Checking filter for item:', item.name, 'Type:', item.type, 'Current filter:', currentFilter);
|
|
242
236
|
if (currentFilter === 'all') return true;
|
|
243
237
|
if (item.type === 'folder') return true; // Always include folders in search results
|
|
244
|
-
const fileType =
|
|
238
|
+
const fileType = getFileTypeOf(item);
|
|
245
239
|
const matches = fileType === currentFilter;
|
|
246
240
|
if (fileType === 'font') {
|
|
247
241
|
// console.log('Font file found in search:', item.name, 'URL:', item.url);
|
|
@@ -282,7 +276,7 @@
|
|
|
282
276
|
if (file.type === 'folder') {
|
|
283
277
|
return getFolderIcon(file, currentFilter);
|
|
284
278
|
}
|
|
285
|
-
const fileType =
|
|
279
|
+
const fileType = getFileTypeOf(file);
|
|
286
280
|
if ((fileType === 'image' || fileType === 'video') &&
|
|
287
281
|
!file.name.toLowerCase().endsWith('.svg') &&
|
|
288
282
|
file.thumbnail) {
|
|
@@ -330,6 +324,7 @@
|
|
|
330
324
|
<BaseModal class="search-modal"
|
|
331
325
|
bind:open
|
|
332
326
|
on:close={handleClose}
|
|
327
|
+
closeLabel={$t('dialog.close')}
|
|
333
328
|
{target}
|
|
334
329
|
width="566px"
|
|
335
330
|
height={$searchTermStore ? "auto" : "88px"}
|
|
@@ -362,7 +357,7 @@
|
|
|
362
357
|
}
|
|
363
358
|
}
|
|
364
359
|
}}
|
|
365
|
-
placeholder=
|
|
360
|
+
placeholder={$t('searchModal.placeholder')}
|
|
366
361
|
class="search-modal-input-el w-full
|
|
367
362
|
!h5 !text-[24px] !text-[hsl(var(--grey7))]
|
|
368
363
|
placeholder:!text-[24px] placeholder:!text-[hsl(var(--grey3))]
|
|
@@ -395,7 +390,7 @@
|
|
|
395
390
|
>
|
|
396
391
|
{#if result.type === 'folder'}
|
|
397
392
|
<div class="flex items-center gap-4 min-w-0 pr-12">
|
|
398
|
-
<img src={getFolderIcon(result, currentFilter)} alt=
|
|
393
|
+
<img src={getFolderIcon(result, currentFilter)} alt={$t('item.folder')} class="w-[62px] h-[54px] object-contain shrink-0" />
|
|
399
394
|
<span class="body-medium text-[hsl(var(--grey7))] truncate">{@html highlightMatch(result.name, $searchTermStore)}</span>
|
|
400
395
|
</div>
|
|
401
396
|
{:else}
|
|
@@ -418,7 +413,7 @@
|
|
|
418
413
|
<!-- Jump to Folder Icon -->
|
|
419
414
|
<img
|
|
420
415
|
src={getAssetUrl('/icons/jump-to-folder.svg')}
|
|
421
|
-
alt=
|
|
416
|
+
alt={$t('searchModal.jumpToFolder')}
|
|
422
417
|
class="jump-to-folder-icon w-6 h-6 absolute right-6 top-1/2 transform -translate-y-1/2 z-20 pointer-events-none"
|
|
423
418
|
class:active={index === activeIndex}
|
|
424
419
|
/>
|
|
@@ -429,7 +424,7 @@
|
|
|
429
424
|
<!-- End of Search Results Container -->
|
|
430
425
|
{:else if $searchTermStore}
|
|
431
426
|
<div style="height: {scrolledAreaMaxHeight}px; min-height: 70px;" class="overflow-hidden flex flex-col items-center justify-center">
|
|
432
|
-
<EmptyState class="!relative" message=
|
|
427
|
+
<EmptyState class="!relative" message={$t('searchModal.empty')} />
|
|
433
428
|
</div>
|
|
434
429
|
{/if}
|
|
435
430
|
|
|
@@ -20,12 +20,16 @@
|
|
|
20
20
|
|
|
21
21
|
// Local utils imports
|
|
22
22
|
import { getAllowedFileTypes, type FileFilterType } from '../../utils/fileTypes';
|
|
23
|
+
import { useI18n } from '../../i18n';
|
|
24
|
+
|
|
25
|
+
const { t } = useI18n();
|
|
23
26
|
|
|
24
27
|
export let open = true;
|
|
25
28
|
export let currentFilter: FileFilterType = 'all';
|
|
26
29
|
export let allFiles: FileSystemItem[] = [];
|
|
27
30
|
export let showAddToEditor = true;
|
|
28
|
-
|
|
31
|
+
/** The words of the button that sends the files on. Left out, the File Browser's own ("Add to Editor", or the page's language's). */
|
|
32
|
+
export let addToEditorLabel: string | undefined = undefined;
|
|
29
33
|
export let target: string = 'selected-files-modal'; // target for Portal
|
|
30
34
|
|
|
31
35
|
// Consts
|
|
@@ -40,8 +44,8 @@
|
|
|
40
44
|
$: allowedTypes = getAllowedFileTypes(currentFilter);
|
|
41
45
|
$: confirmAddLabel =
|
|
42
46
|
selectedFiles.length <= 1
|
|
43
|
-
? addToEditorLabel
|
|
44
|
-
:
|
|
47
|
+
? (addToEditorLabel ?? $t('action.addToEditor'))
|
|
48
|
+
: $t('selectedFiles.confirmMany', { count: selectedFiles.length });
|
|
45
49
|
|
|
46
50
|
function handleClose() {
|
|
47
51
|
open = false;
|
|
@@ -59,8 +63,8 @@
|
|
|
59
63
|
});
|
|
60
64
|
|
|
61
65
|
// Show sonar toast instead of alert
|
|
62
|
-
toast.success('
|
|
63
|
-
description:
|
|
66
|
+
toast.success($t('toast.filesAdded'), {
|
|
67
|
+
description: $t('toast.filesAddedDetail', { count: selectedFiles.length })
|
|
64
68
|
});
|
|
65
69
|
|
|
66
70
|
// Clear selections and close modal
|
|
@@ -143,7 +147,8 @@
|
|
|
143
147
|
|
|
144
148
|
<BaseModal
|
|
145
149
|
bind:open
|
|
146
|
-
title=
|
|
150
|
+
title={$t('selectedFiles.title')}
|
|
151
|
+
closeLabel={$t('dialog.close')}
|
|
147
152
|
on:close={handleClose}
|
|
148
153
|
width="566px"
|
|
149
154
|
height="496px"
|
|
@@ -163,7 +168,7 @@
|
|
|
163
168
|
|
|
164
169
|
{#if selectedFiles.length === 0}
|
|
165
170
|
<div style="height: {scrolledAreaMaxHeight}px; min-height: 70px;" class="overflow-hidden flex flex-col items-center justify-center">
|
|
166
|
-
<EmptyState class="!relative" message=
|
|
171
|
+
<EmptyState class="!relative" message={$t('selectedFiles.empty')} />
|
|
167
172
|
</div>
|
|
168
173
|
{:else}
|
|
169
174
|
<!-- Selected Files Container -->
|
|
@@ -220,7 +225,7 @@
|
|
|
220
225
|
<!-- Results Count -->
|
|
221
226
|
<div class="results-count text-[hsl(var(--grey5))] subtext">
|
|
222
227
|
{#if selectedFiles.length > 0}
|
|
223
|
-
{selectedFiles.
|
|
228
|
+
{$t('selectedFiles.count', { count: selectedFiles.length })}
|
|
224
229
|
{/if}
|
|
225
230
|
</div>
|
|
226
231
|
|
|
@@ -231,7 +236,7 @@
|
|
|
231
236
|
class="modal-btn-secondary !h-[34px]"
|
|
232
237
|
onclick={handleClose}
|
|
233
238
|
>
|
|
234
|
-
<span>
|
|
239
|
+
<span>{$t('action.cancel')}</span>
|
|
235
240
|
</Button>
|
|
236
241
|
|
|
237
242
|
<!-- Add to Editor Button -->
|
|
@@ -18,7 +18,7 @@ declare const SelectedFilesModal: $$__sveltets_2_IsomorphicComponent<{
|
|
|
18
18
|
currentFilter?: FileFilterType;
|
|
19
19
|
allFiles?: FileSystemItem[];
|
|
20
20
|
showAddToEditor?: boolean;
|
|
21
|
-
addToEditorLabel?: string;
|
|
21
|
+
/** The words of the button that sends the files on. Left out, the File Browser's own ("Add to Editor", or the page's language's). */ addToEditorLabel?: string | undefined;
|
|
22
22
|
target?: string;
|
|
23
23
|
}, {
|
|
24
24
|
close: CustomEvent<any>;
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
// Local components imports
|
|
10
10
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
11
11
|
import WaveformVisualizer from './WaveformVisualizer.svelte';
|
|
12
|
+
import { useI18n } from '../../i18n';
|
|
13
|
+
|
|
14
|
+
const { t } = useI18n();
|
|
12
15
|
|
|
13
16
|
export let src: string;
|
|
14
17
|
export let autoplay = false;
|
|
@@ -66,7 +69,7 @@
|
|
|
66
69
|
</script>
|
|
67
70
|
|
|
68
71
|
{#if hasError}
|
|
69
|
-
<ErrorPreview message=
|
|
72
|
+
<ErrorPreview message={$t('preview.audioFailed')} />
|
|
70
73
|
{:else}
|
|
71
74
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
72
75
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -111,7 +114,7 @@
|
|
|
111
114
|
onplay={handlePlay}
|
|
112
115
|
onpause={handlePause}
|
|
113
116
|
>
|
|
114
|
-
|
|
117
|
+
{$t('preview.audioUnsupported')}
|
|
115
118
|
</audio>
|
|
116
119
|
</div>
|
|
117
120
|
{/if}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
// Local utils imports
|
|
3
3
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
4
|
+
import { useI18n } from '../../i18n';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const { t } = useI18n();
|
|
7
|
+
|
|
8
|
+
// Component props: the sentence under the icon. Left out, "File not found" (in the page's language).
|
|
9
|
+
export let message: string | undefined = undefined;
|
|
7
10
|
</script>
|
|
8
11
|
|
|
9
12
|
<div class="error-preview-container flex flex-col items-center justify-center h-[60vh] space-y-4">
|
|
10
|
-
<img src={getAssetUrl('/icons/error.svg')} alt=
|
|
11
|
-
<p class="text-gray-600">{message}</p>
|
|
13
|
+
<img src={getAssetUrl('/icons/error.svg')} alt={$t('preview.errorAlt')} class="w-16 h-16" />
|
|
14
|
+
<p class="text-gray-600">{message ?? $t('preview.fileNotFound')}</p>
|
|
12
15
|
</div>
|
|
@@ -12,7 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
z_$$bindings?: Bindings;
|
|
13
13
|
}
|
|
14
14
|
declare const ErrorPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
-
message?: string;
|
|
15
|
+
message?: string | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
[evt: string]: CustomEvent<any>;
|
|
18
18
|
}, {}, {}, string>;
|
|
@@ -20,12 +20,16 @@
|
|
|
20
20
|
import type { FileSystemItem } from '../../types';
|
|
21
21
|
|
|
22
22
|
// Utils
|
|
23
|
-
import {
|
|
23
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
24
|
+
import { toSafeFontFamilyName } from '../../utils/safeText';
|
|
24
25
|
|
|
25
26
|
// Stores
|
|
26
27
|
import { missingFiles } from '../../stores/missingFilesStore';
|
|
27
28
|
import { validSelections } from '../../stores/persistentSelectStore';
|
|
28
29
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
30
|
+
import { useI18n } from '../../i18n';
|
|
31
|
+
|
|
32
|
+
const { t } = useI18n();
|
|
29
33
|
|
|
30
34
|
// Component props
|
|
31
35
|
export let file: FileSystemItem;
|
|
@@ -235,10 +239,10 @@
|
|
|
235
239
|
// when file changes, update the file type, url, and valid url
|
|
236
240
|
$: {
|
|
237
241
|
if(showLogs) console.log('FilePreview: file changed reactive statement:', file);
|
|
238
|
-
fileType =
|
|
242
|
+
fileType = getFileTypeOf(file);
|
|
239
243
|
fileUrl = file.url || '';
|
|
240
244
|
hasValidUrl = !!file.url && fileUrl.length > 0 && !$missingFiles.has(file.id);
|
|
241
|
-
fontName = file.name
|
|
245
|
+
fontName = toSafeFontFamilyName(file.name);
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
let videoElement: HTMLVideoElement;
|
|
@@ -314,6 +318,7 @@
|
|
|
314
318
|
class="file-preview-modal"
|
|
315
319
|
bind:open
|
|
316
320
|
title={file.name}
|
|
321
|
+
closeLabel={$t('dialog.close')}
|
|
317
322
|
width={modalDimensions.width}
|
|
318
323
|
height={modalDimensions.height}
|
|
319
324
|
{target}
|
|
@@ -336,10 +341,10 @@
|
|
|
336
341
|
allowSelecting = event.detail.allowSelecting;
|
|
337
342
|
|
|
338
343
|
// Re-trigger file type checks and URL validation
|
|
339
|
-
fileType =
|
|
344
|
+
fileType = getFileTypeOf(file);
|
|
340
345
|
fileUrl = file.url || '';
|
|
341
346
|
hasValidUrl = !!file.url && fileUrl.length > 0 && !$missingFiles.has(file.id);
|
|
342
|
-
fontName = file.name
|
|
347
|
+
fontName = toSafeFontFamilyName(file.name);
|
|
343
348
|
|
|
344
349
|
// Reset image loaded state when file changes
|
|
345
350
|
imageLoaded = false;
|
|
@@ -357,7 +362,7 @@
|
|
|
357
362
|
<FontPreview
|
|
358
363
|
src={fileUrl}
|
|
359
364
|
{fontName}
|
|
360
|
-
previewText={file.previewText ||
|
|
365
|
+
previewText={file.previewText || undefined}
|
|
361
366
|
/>
|
|
362
367
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
363
368
|
{#if fileType === 'svg'}
|
|
@@ -435,11 +440,16 @@
|
|
|
435
440
|
<PDFViewer class="fb-pdf-viewer"
|
|
436
441
|
url={fileUrl}
|
|
437
442
|
enableCacheClearing={true}
|
|
443
|
+
loadingLabel={$t('preview.pdfLoading')}
|
|
444
|
+
failedLabel={$t('preview.pdfFailed')}
|
|
445
|
+
pageLabel={$t('preview.pdfPage', { page: '{page}', total: '{total}' })}
|
|
446
|
+
previousPageLabel={$t('preview.pdfPreviousPage')}
|
|
447
|
+
nextPageLabel={$t('preview.pdfNextPage')}
|
|
438
448
|
on:error={(e) => pdfLoadError = e.detail.message || 'Error loading PDF'}
|
|
439
449
|
on:cacheCleared={() => { /* console.log('PDF cache cleared from FilePreview'); */ }}
|
|
440
450
|
/>
|
|
441
451
|
{:else}
|
|
442
|
-
<p class="no-preview-container text-center py-8">
|
|
452
|
+
<p class="no-preview-container text-center py-8">{$t('preview.unavailable')}</p>
|
|
443
453
|
{/if}
|
|
444
454
|
|
|
445
455
|
<!-- 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>;
|