@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
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// UTILS IMPORTS
|
|
46
|
-
import {
|
|
46
|
+
import { getFileIcon } from '../../utils/fileUtils';
|
|
47
|
+
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
47
48
|
import { getFolderIcon } from '../../utils/folderUtils';
|
|
48
49
|
import { type FileFilterType, FILTER_OPTIONS, getAllowedFileTypes, FILE_TYPES, formatFileTypesForDisplay } from '../../utils/fileTypes';
|
|
49
|
-
import { getPathNamesFromIds, deleteItem, renameItem, moveItem } from '../../utils/fileOperations';
|
|
50
|
+
import { getPathNamesFromIds, deleteItem, renameItem, moveItem, findItemById } from '../../utils/fileOperations';
|
|
50
51
|
import { getFileBrowserUploadConfig, setFileBrowserUploadConfig } from '../../stores/uploadApiStore';
|
|
51
52
|
import {
|
|
52
53
|
loadUserUploads,
|
|
@@ -90,6 +91,21 @@
|
|
|
90
91
|
import { persistentSelectStore, validSelections } from '../../stores/persistentSelectStore';
|
|
91
92
|
import { isModalOpen, modalState } from '@widgetic/design-system/components/modals/modalStore';
|
|
92
93
|
|
|
94
|
+
// MEDIA LIBRARY IMPORTS (the host's own storage; see the `mediaLibrary` prop)
|
|
95
|
+
import { provideMediaLibraryContext, type MediaLibraryContext } from '../../mediaLibrary/context';
|
|
96
|
+
import { LEGACY_CAPABILITIES, NO_CAPABILITIES } from '../../mediaLibrary/capabilities';
|
|
97
|
+
import { MediaLibraryError, isCancellation, toMediaLibraryError } from '../../mediaLibrary/errors';
|
|
98
|
+
import { loadLibraryPages } from '../../mediaLibrary/paging';
|
|
99
|
+
import { resolveMediaLibrary, type ResolvedMediaLibrary } from '../../mediaLibrary/resolve';
|
|
100
|
+
import { appendNewFiles, createLibraryRoot, removeFiles, replaceFile, upsertFile } from '../../mediaLibrary/treeOps';
|
|
101
|
+
import type { MediaLibraryErrorCode, MediaLibraryProvider } from '../../mediaLibrary/types';
|
|
102
|
+
import { getRenamedFileName } from '../../utils/fileNames';
|
|
103
|
+
|
|
104
|
+
// I18N IMPORTS (the words of the File Browser, in the page's language)
|
|
105
|
+
import { provideI18n } from '../../i18n/context';
|
|
106
|
+
import { messageForVisitor } from '../../i18n/errors';
|
|
107
|
+
import type { MessageOverrides } from '../../i18n/translator';
|
|
108
|
+
|
|
93
109
|
// logs flags
|
|
94
110
|
let showLogs = false;
|
|
95
111
|
let showRecentFilesLogs = false;
|
|
@@ -100,6 +116,21 @@
|
|
|
100
116
|
*/
|
|
101
117
|
// data props
|
|
102
118
|
export let data: any = null;
|
|
119
|
+
/**
|
|
120
|
+
* The host's own media library (a `MediaLibraryProvider`): plain functions the File Browser calls to list, upload,
|
|
121
|
+
* rename and delete the host's files. When given, the File Browser shows that one flat library instead of the
|
|
122
|
+
* Widgetic uploads or the demo content, and stores nothing about it on this device (no local cache, no saved
|
|
123
|
+
* tree, no saved selection unless `persistSelection` says so).
|
|
124
|
+
*
|
|
125
|
+
* Read once, when the File Browser is created: to show another library, create a new File Browser.
|
|
126
|
+
*/
|
|
127
|
+
export let mediaLibrary: MediaLibraryProvider | null = null;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the picked files are remembered in this browser's localStorage between visits. Default: yes, as always,
|
|
130
|
+
* except with a `mediaLibrary` (a shared browser must not show the next visitor the previous one's picks).
|
|
131
|
+
* This is a setting of the page: when two File Browsers disagree, the last one created wins.
|
|
132
|
+
*/
|
|
133
|
+
export let persistSelection: boolean | undefined = undefined;
|
|
103
134
|
// reactive statement to initialize the component if data is passed
|
|
104
135
|
$: if(data) {
|
|
105
136
|
// if(showLogs) console.log('FileBrowser: data reactive statement:', data);
|
|
@@ -131,7 +162,18 @@
|
|
|
131
162
|
/** When set (single-file picker), disables confirm until user picks a different file. */
|
|
132
163
|
export let activeFileId: string | null = null;
|
|
133
164
|
export let showAddToEditor = false; // Toggle visibility of "Add to Editor" functionality
|
|
134
|
-
|
|
165
|
+
/** The text of the button that hands the picked files to the page. Default: the message "action.addToEditor". */
|
|
166
|
+
export let addToEditorLabel: string | undefined = undefined;
|
|
167
|
+
/**
|
|
168
|
+
* The language of the File Browser: a BCP 47 tag ("de", "pt-BR"). It sets the plural rules and how numbers, dates and
|
|
169
|
+
* file sizes are written. Default "en". The words themselves come from `messages`.
|
|
170
|
+
*/
|
|
171
|
+
export let locale: string | undefined = undefined;
|
|
172
|
+
/**
|
|
173
|
+
* The page's own words: any of the keys of FILE_BROWSER_MESSAGES (see the README, "Languages"). A key left out keeps
|
|
174
|
+
* its English text. Can change while the File Browser is open.
|
|
175
|
+
*/
|
|
176
|
+
export let messages: MessageOverrides | null = null;
|
|
135
177
|
/** When false, skips bundled demo tree (use with Widgetic upload config). */
|
|
136
178
|
export let useDemoContent = true;
|
|
137
179
|
/**
|
|
@@ -345,6 +387,223 @@
|
|
|
345
387
|
// $: controlsVisible = showFilters || showSorting;
|
|
346
388
|
// console.log("File Browser component: controlsVisible", showFilters, showSorting, controlsVisible);
|
|
347
389
|
|
|
390
|
+
/**
|
|
391
|
+
* MEDIA LIBRARY (the host's own storage)
|
|
392
|
+
*
|
|
393
|
+
* With a `mediaLibrary` the File Browser shows one flat list of the host's files and calls the host's functions to
|
|
394
|
+
* list, upload, rename and delete them. Everything stays in memory: the local cache (IndexedDB) and the saved
|
|
395
|
+
* "My uploads" tree are never read or written, and the picked-file selection is only kept in localStorage when
|
|
396
|
+
* `persistSelection` asks for it.
|
|
397
|
+
*/
|
|
398
|
+
// Decided when the File Browser is created (see the `mediaLibrary` prop).
|
|
399
|
+
const libraryMode = mediaLibrary !== null && mediaLibrary !== undefined;
|
|
400
|
+
// A library supplies every file, so `data` handed in by the host is not used next to it.
|
|
401
|
+
if (libraryMode) data = null;
|
|
402
|
+
|
|
403
|
+
// The library as the File Browser uses it: every answer checked, every failure a MediaLibraryError.
|
|
404
|
+
let resolvedMediaLibrary: ResolvedMediaLibrary | null = null;
|
|
405
|
+
// Set when `mediaLibrary` is not a usable library: the screen says so instead of showing files.
|
|
406
|
+
let libraryConfigError: MediaLibraryError | null = null;
|
|
407
|
+
if (libraryMode) {
|
|
408
|
+
try {
|
|
409
|
+
resolvedMediaLibrary = resolveMediaLibrary(mediaLibrary);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
libraryConfigError = new MediaLibraryError('FAILED', error instanceof Error ? error.message : 'mediaLibrary is not a media library', { cause: error });
|
|
412
|
+
console.error('[FileBrowser] The mediaLibrary option cannot be used:', error);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// What the parts of this File Browser may offer (Rename, Delete, Upload...), shared through Svelte's context.
|
|
417
|
+
const libraryContext: MediaLibraryContext = {
|
|
418
|
+
library: resolvedMediaLibrary,
|
|
419
|
+
capabilities: !libraryMode ? LEGACY_CAPABILITIES : (resolvedMediaLibrary?.capabilities ?? NO_CAPABILITIES),
|
|
420
|
+
};
|
|
421
|
+
provideMediaLibraryContext(libraryContext);
|
|
422
|
+
const libraryCapabilities = libraryContext.capabilities;
|
|
423
|
+
|
|
424
|
+
// The language: the parts below read it from Svelte's context, and follow when the page changes `locale` or `messages`.
|
|
425
|
+
const i18n = provideI18n({ locale, messages });
|
|
426
|
+
const { t } = i18n;
|
|
427
|
+
$: i18n.update({ locale, messages });
|
|
428
|
+
// The text of the confirm button: the page's label, or the message of the language in use.
|
|
429
|
+
$: addToEditorText = addToEditorLabel ?? $t('action.addToEditor');
|
|
430
|
+
|
|
431
|
+
// A shared browser must not show the next visitor the previous one's picks, so a library turns this off unless the
|
|
432
|
+
// host asks for it. Selecting still works; the picks just live in memory.
|
|
433
|
+
const selectionIsKept = persistSelection ?? !libraryMode;
|
|
434
|
+
if (isBrowser) {
|
|
435
|
+
persistentSelectStore.configurePersistence(selectionIsKept);
|
|
436
|
+
if (!selectionIsKept) persistentSelectStore.clearSelections('all');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Loading the library: what stopped it, whether a list was already shown when it did, and whether the library
|
|
440
|
+
// has more files than were loaded.
|
|
441
|
+
let libraryLoadError: MediaLibraryError | null = null;
|
|
442
|
+
let libraryShowsPartialList = false;
|
|
443
|
+
let libraryListIsTruncated = false;
|
|
444
|
+
let libraryLoadController: AbortController | null = null;
|
|
445
|
+
// Aborted when the File Browser is closed: ends every call to the library that is still waiting, so a closed
|
|
446
|
+
// File Browser does not touch the (page-wide) file list of the next one.
|
|
447
|
+
const libraryActionsController = new AbortController();
|
|
448
|
+
|
|
449
|
+
/** Tells the host about a problem with its library, in the form `{ message, code, action }`. */
|
|
450
|
+
function reportLibraryError(error: MediaLibraryError, action: 'setup' | 'load' | 'upload' | 'rename' | 'delete') {
|
|
451
|
+
dispatch('error', { message: error.message, code: error.code, action });
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Reads the library into the grid, page by page. The first page ends the loading screen and the rest is added as
|
|
456
|
+
* it arrives. If the first page fails the screen shows the error with "Try again"; if a later page fails what was
|
|
457
|
+
* loaded stays and a notice says the list is incomplete.
|
|
458
|
+
*/
|
|
459
|
+
async function loadFromLibrary(): Promise<void> {
|
|
460
|
+
const library = resolvedMediaLibrary;
|
|
461
|
+
if (!library) return;
|
|
462
|
+
|
|
463
|
+
// A new load replaces one that is still running (the visitor pressed "Try again").
|
|
464
|
+
libraryLoadController?.abort();
|
|
465
|
+
const controller = new AbortController();
|
|
466
|
+
libraryLoadController = controller;
|
|
467
|
+
libraryLoadError = null;
|
|
468
|
+
libraryShowsPartialList = false;
|
|
469
|
+
libraryListIsTruncated = false;
|
|
470
|
+
isLoading = true;
|
|
471
|
+
|
|
472
|
+
let viewStarted = false;
|
|
473
|
+
const showLibraryFiles = (files: FileSystemItem[]) => {
|
|
474
|
+
if (controller.signal.aborted) return;
|
|
475
|
+
if (!viewStarted) {
|
|
476
|
+
viewStarted = true;
|
|
477
|
+
// `data` is what init() builds the view from; that also ends the loading screen.
|
|
478
|
+
data = { basePath: '', root: createLibraryRoot(files) };
|
|
479
|
+
} else {
|
|
480
|
+
fileStore.update((store) => ({ ...store, root: appendNewFiles(store.root, files) }));
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
const loaded = await loadLibraryPages(library, { signal: controller.signal, onPage: (files) => showLibraryFiles(files) });
|
|
486
|
+
if (controller.signal.aborted) return;
|
|
487
|
+
// An empty library never delivered a page of files.
|
|
488
|
+
if (!viewStarted) showLibraryFiles([]);
|
|
489
|
+
libraryListIsTruncated = loaded.truncated;
|
|
490
|
+
if (loaded.failure) {
|
|
491
|
+
libraryLoadError = loaded.failure;
|
|
492
|
+
libraryShowsPartialList = loaded.items.length > 0;
|
|
493
|
+
reportLibraryError(loaded.failure, 'load');
|
|
494
|
+
}
|
|
495
|
+
} catch (error) {
|
|
496
|
+
// Only a load this File Browser cancelled itself (closed, or replaced by "Try again") is silent.
|
|
497
|
+
if (controller.signal.aborted) return;
|
|
498
|
+
const failure = toMediaLibraryError(error, 'Could not load the files', 'libraryError.loadFailed');
|
|
499
|
+
console.error('[FileBrowser] Could not load the media library:', failure);
|
|
500
|
+
libraryLoadError = failure;
|
|
501
|
+
// Ends the loading screen; the error is shown instead of the grid.
|
|
502
|
+
if (!viewStarted) showLibraryFiles([]);
|
|
503
|
+
reportLibraryError(failure, 'load');
|
|
504
|
+
} finally {
|
|
505
|
+
if (libraryLoadController === controller) libraryLoadController = null;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** The "Try again" button: reads the whole library again. */
|
|
510
|
+
function reloadLibrary() {
|
|
511
|
+
void loadFromLibrary();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Renames a file in the host's library and then in the list: the list changes only after the library said yes.
|
|
516
|
+
* Resolves `false` when there was nothing to change; throws a MediaLibraryError when the library refuses.
|
|
517
|
+
*/
|
|
518
|
+
async function renameInLibrary(itemId: string, newName: string): Promise<boolean> {
|
|
519
|
+
const library = resolvedMediaLibrary;
|
|
520
|
+
if (!library?.rename) throw new MediaLibraryError('NOT_SUPPORTED', 'This media library does not allow renaming files', { messageKey: 'libraryError.renameNotAllowed' });
|
|
521
|
+
const item = findItemById(itemId);
|
|
522
|
+
if (!item) throw new MediaLibraryError('NOT_FOUND', 'The file is no longer in the list', { messageKey: 'libraryError.fileGone' });
|
|
523
|
+
|
|
524
|
+
const typedName = newName.trim();
|
|
525
|
+
if (typedName === '') return false;
|
|
526
|
+
// A file keeps its extension, as everywhere else in the File Browser.
|
|
527
|
+
const finalName = item.type === 'file' ? getRenamedFileName(item.name, typedName) : typedName;
|
|
528
|
+
if (finalName === item.name) return false;
|
|
529
|
+
|
|
530
|
+
const renamedFile = await library.rename({ id: itemId, name: finalName, signal: libraryActionsController.signal });
|
|
531
|
+
// The File Browser was closed while the library was working: its list is no longer ours to change.
|
|
532
|
+
if (libraryActionsController.signal.aborted) return false;
|
|
533
|
+
|
|
534
|
+
// The library may answer with the file as it is now (it can change the address or the id). When it only says
|
|
535
|
+
// "done", the file stays as it was and takes the new name.
|
|
536
|
+
const updatedFile: FileSystemItem = renamedFile ?? { ...item, name: finalName, modified: new Date().toISOString() };
|
|
537
|
+
fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, updatedFile) }));
|
|
538
|
+
selectedFiles.update((files) => files.map((file) => (file.id === itemId ? updatedFile : file)));
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Deletes a file in the host's library and then from the list. Resolves `true` when it is gone; throws a
|
|
544
|
+
* MediaLibraryError when the library refuses.
|
|
545
|
+
*/
|
|
546
|
+
async function deleteFromLibrary(item: FileSystemItem): Promise<boolean> {
|
|
547
|
+
const library = resolvedMediaLibrary;
|
|
548
|
+
if (!library?.remove) throw new MediaLibraryError('NOT_SUPPORTED', 'This media library does not allow deleting files', { messageKey: 'libraryError.deleteNotAllowed' });
|
|
549
|
+
|
|
550
|
+
await library.remove({ id: item.id, signal: libraryActionsController.signal });
|
|
551
|
+
// The File Browser was closed while the library was working: its list is no longer ours to change.
|
|
552
|
+
if (libraryActionsController.signal.aborted) throw new MediaLibraryError('ABORTED', 'The File Browser was closed');
|
|
553
|
+
|
|
554
|
+
fileStore.update((store) => ({ ...store, root: removeFiles(store.root, new Set([item.id])) }));
|
|
555
|
+
selectedFiles.update((files) => files.filter((file) => file.id !== item.id));
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** Shows a file the library just stored, and brings it into view. */
|
|
560
|
+
function addUploadedFileToLibraryList(file: FileSystemItem) {
|
|
561
|
+
fileStore.update((store) => ({ ...store, root: upsertFile(store.root, file) }));
|
|
562
|
+
// Wait for the grid to draw the new file, then scroll to it and flash it, as for any upload.
|
|
563
|
+
setTimeout(() => {
|
|
564
|
+
scrollItemIntoView(file.id);
|
|
565
|
+
const itemElement = findItemElement(file.id);
|
|
566
|
+
if (itemElement) {
|
|
567
|
+
itemElement.classList.add('wave-goodbye');
|
|
568
|
+
setTimeout(() => itemElement.classList.remove('wave-goodbye'), 600);
|
|
569
|
+
}
|
|
570
|
+
}, 100);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** An upload failed (the uploader already shows the failed row). Logged as always; a media library's host is told too. */
|
|
574
|
+
function handleUploadError(event: CustomEvent<{ message: string; file?: string; code?: MediaLibraryErrorCode }>) {
|
|
575
|
+
console.error('Upload error:', event.detail);
|
|
576
|
+
if (libraryMode) {
|
|
577
|
+
dispatch('error', { message: event.detail.message, code: event.detail.code ?? 'FAILED', action: 'upload', file: event.detail.file });
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Finds the element of an item inside this File Browser (also when it sits inside a shadow root). */
|
|
582
|
+
function findItemElement(itemId: string): HTMLElement | null {
|
|
583
|
+
// An id comes from the host's library and may hold any character, so it is escaped before it joins a selector.
|
|
584
|
+
const selector = `[data-item-id="${typeof CSS !== 'undefined' ? CSS.escape(itemId) : itemId.replace(/["\\]/g, '\\$&')}"]`;
|
|
585
|
+
return (mainContainer?.querySelector(selector) ?? document.querySelector(selector)) as HTMLElement | null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// A notice above the grid when the list on screen is not the whole library: a later page failed, or the library
|
|
589
|
+
// has more files than the File Browser loads.
|
|
590
|
+
let libraryNotice: { text: string; canRetry: boolean } | null = null;
|
|
591
|
+
$: libraryNotice = libraryMode && !isLoading
|
|
592
|
+
? libraryLoadError && libraryShowsPartialList
|
|
593
|
+
? { text: $t('library.partialNotice'), canRetry: true }
|
|
594
|
+
: libraryListIsTruncated
|
|
595
|
+
? { text: $t('library.truncatedNotice'), canRetry: false }
|
|
596
|
+
: null
|
|
597
|
+
: null;
|
|
598
|
+
|
|
599
|
+
// Shown instead of the grid: the library cannot be used, or its first page could not be read.
|
|
600
|
+
let libraryErrorMessage = '';
|
|
601
|
+
$: libraryErrorMessage = libraryConfigError
|
|
602
|
+
? $t('library.notSetUp')
|
|
603
|
+
: libraryLoadError && !libraryShowsPartialList
|
|
604
|
+
? messageForVisitor(libraryLoadError, $t, 'libraryError.loadFailed')
|
|
605
|
+
: '';
|
|
606
|
+
|
|
348
607
|
/**
|
|
349
608
|
* LIFE CYCLE HOOKS
|
|
350
609
|
*/
|
|
@@ -352,7 +611,8 @@
|
|
|
352
611
|
if(showLogs) console.log('FileBrowser onMount instanceId: ', instanceId);
|
|
353
612
|
// if(showLogs) console.log('FileBrowser onMount start:', performance.now() - startTime, 'ms');
|
|
354
613
|
|
|
355
|
-
|
|
614
|
+
// A media library keeps its files to itself: the local cache (IndexedDB) is never scoped, read or written for it.
|
|
615
|
+
if (enableLocalCache && !libraryMode) {
|
|
356
616
|
const existing = getFileBrowserUploadConfig();
|
|
357
617
|
if (existing?.accessToken) {
|
|
358
618
|
setFileBrowserUploadConfig({ ...existing, enableLocalCache: true });
|
|
@@ -380,9 +640,20 @@
|
|
|
380
640
|
}
|
|
381
641
|
}
|
|
382
642
|
|
|
643
|
+
// The host's media library supplies the files; nothing else is loaded.
|
|
644
|
+
if (libraryMode) {
|
|
645
|
+
basePath = '';
|
|
646
|
+
if (libraryConfigError) {
|
|
647
|
+
isLoading = false;
|
|
648
|
+
reportLibraryError(libraryConfigError, 'setup');
|
|
649
|
+
} else {
|
|
650
|
+
// Not awaited: the rest of the setup (breakpoints, listeners) does not wait for the library.
|
|
651
|
+
void loadFromLibrary();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
383
654
|
// load demo content from localStorage if no data is passed
|
|
384
655
|
// if(showLogs) console.log('FileBrowser onMount data & useDemoContent: ', data, useDemoContent);
|
|
385
|
-
if (!data) {
|
|
656
|
+
else if (!data) {
|
|
386
657
|
const uploadConfig = getFileBrowserUploadConfig();
|
|
387
658
|
const widgeticLibraryMode = Boolean(
|
|
388
659
|
uploadConfig?.accessToken && uploadConfig?.apiBasePath,
|
|
@@ -406,7 +677,7 @@
|
|
|
406
677
|
console.warn('[FileBrowser] Upload hydration failed, using local cache:', hydrateError);
|
|
407
678
|
}
|
|
408
679
|
}
|
|
409
|
-
data = await createUserUploadsFileSystemRoot(files);
|
|
680
|
+
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
410
681
|
basePath = '';
|
|
411
682
|
if (showLogs) {
|
|
412
683
|
// console.log('[FileBrowser] Widgetic library mode — user uploads only');
|
|
@@ -443,8 +714,11 @@
|
|
|
443
714
|
// Add event listener for window resize
|
|
444
715
|
window.addEventListener('resize', handleResize);
|
|
445
716
|
|
|
446
|
-
// Set up window key handler
|
|
447
|
-
|
|
717
|
+
// Set up window key handler. With a media library the File Browser sits inside the host's page, where Ctrl+A and
|
|
718
|
+
// Backspace belong to the host: it then listens only to keys pressed inside its own container.
|
|
719
|
+
if (!libraryMode) window.addEventListener('keydown', handleKeyDown);
|
|
720
|
+
window.addEventListener('widgetic:file-browser-command', handleFileBrowserCommand);
|
|
721
|
+
publishFileBrowserNav();
|
|
448
722
|
|
|
449
723
|
if (data) {
|
|
450
724
|
isLoading = false;
|
|
@@ -476,8 +750,9 @@
|
|
|
476
750
|
// set base path
|
|
477
751
|
data.basePath = basePath;
|
|
478
752
|
|
|
479
|
-
// save as demo content if not already saved
|
|
480
|
-
|
|
753
|
+
// save as demo content if not already saved (never for a media library: its files are not demo content, and
|
|
754
|
+
// the visitor's file list must not be copied into localStorage)
|
|
755
|
+
if(!libraryMode && !getFromStorage(demoContentKey, null)) {
|
|
481
756
|
// console.log('FileBrowser: saving demo content to localStorage:', data);
|
|
482
757
|
saveToStorage(demoContentKey, data);
|
|
483
758
|
}
|
|
@@ -500,8 +775,8 @@
|
|
|
500
775
|
// Store the path we want to navigate to after loading
|
|
501
776
|
let pathToNavigate: string[] = [];
|
|
502
777
|
|
|
503
|
-
// Check if we have a stored path to restore
|
|
504
|
-
if (persistHistory) {
|
|
778
|
+
// Check if we have a stored path to restore (a media library has no folders to go back to)
|
|
779
|
+
if (persistHistory && !libraryMode) {
|
|
505
780
|
const storedState = getStoredState(instanceId);
|
|
506
781
|
if (storedState) {
|
|
507
782
|
pathToNavigate = storedState.pathsArray[storedState.currentIndex] || [];
|
|
@@ -548,6 +823,11 @@
|
|
|
548
823
|
// onDestroy: cleanup event listener on component destroy
|
|
549
824
|
onDestroy(() => {
|
|
550
825
|
|
|
826
|
+
// Stop waiting for the media library. The file list is shared by the whole page, so an answer that arrives after
|
|
827
|
+
// this File Browser is gone must not be written into the list of the next one.
|
|
828
|
+
libraryLoadController?.abort();
|
|
829
|
+
libraryActionsController.abort();
|
|
830
|
+
|
|
551
831
|
// check if browser environment is available
|
|
552
832
|
if (!isBrowser) return;
|
|
553
833
|
|
|
@@ -556,6 +836,7 @@
|
|
|
556
836
|
// REMOVE EVENT LISTENERS
|
|
557
837
|
window.removeEventListener('resize', handleResize);
|
|
558
838
|
window.removeEventListener('keydown', handleKeyDown);
|
|
839
|
+
window.removeEventListener('widgetic:file-browser-command', handleFileBrowserCommand);
|
|
559
840
|
});
|
|
560
841
|
|
|
561
842
|
// Add logging to key reactive statements
|
|
@@ -728,7 +1009,7 @@
|
|
|
728
1009
|
*/
|
|
729
1010
|
function fileMatchesFilter(file: FileSystemItem): boolean {
|
|
730
1011
|
if (filter === 'all') return true;
|
|
731
|
-
return
|
|
1012
|
+
return getFileTypeOf(file) === filter;
|
|
732
1013
|
}
|
|
733
1014
|
|
|
734
1015
|
/**
|
|
@@ -757,26 +1038,21 @@
|
|
|
757
1038
|
* Syncs current path with store updates
|
|
758
1039
|
* Ensures UI stays in sync with navigation state
|
|
759
1040
|
*/
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
// Subscribe to navigation store changes
|
|
1041
|
+
// Follow the history index. A stale folder must not put the view
|
|
1042
|
+
// back on the folder we just left.
|
|
763
1043
|
$: {
|
|
764
1044
|
if ($navPathStore) {
|
|
765
|
-
|
|
766
|
-
currentPath =
|
|
767
|
-
if (JSON.stringify($currentFolder) !== JSON.stringify(
|
|
768
|
-
currentFolder.set(
|
|
1045
|
+
const livePath = pathAtHistoryIndex();
|
|
1046
|
+
currentPath = livePath;
|
|
1047
|
+
if (JSON.stringify($currentFolder) !== JSON.stringify(livePath)) {
|
|
1048
|
+
currentFolder.set(livePath);
|
|
769
1049
|
}
|
|
770
|
-
// Reset the flag after the update
|
|
771
|
-
setTimeout(() => {
|
|
772
|
-
isNavigating = false;
|
|
773
|
-
}, 0);
|
|
774
1050
|
}
|
|
775
1051
|
}
|
|
776
1052
|
|
|
777
|
-
// Only update current path when folder changes
|
|
778
1053
|
$: {
|
|
779
|
-
|
|
1054
|
+
const livePath = pathAtHistoryIndex();
|
|
1055
|
+
if ($currentFolder && JSON.stringify($currentFolder) === JSON.stringify(livePath)) {
|
|
780
1056
|
currentPath = $currentFolder;
|
|
781
1057
|
}
|
|
782
1058
|
}
|
|
@@ -943,7 +1219,7 @@
|
|
|
943
1219
|
// Filter by type
|
|
944
1220
|
const typeFilteredFiles = allFiles.filter(file => {
|
|
945
1221
|
if (filter === 'all') return true;
|
|
946
|
-
const fileType =
|
|
1222
|
+
const fileType = getFileTypeOf(file);
|
|
947
1223
|
return fileType === filter;
|
|
948
1224
|
});
|
|
949
1225
|
if(showLogs && showRecentFilesLogs) console.log('Files after type filtering:', typeFilteredFiles.length);
|
|
@@ -977,6 +1253,25 @@
|
|
|
977
1253
|
return resolveFileItemUrl(item, storeBasePath);
|
|
978
1254
|
}
|
|
979
1255
|
|
|
1256
|
+
/**
|
|
1257
|
+
* The file as the grid draws it: its address and thumbnail address resolved against the base path.
|
|
1258
|
+
* A Widgetic upload always has a picture to show, so its thumbnail defaults to the file itself.
|
|
1259
|
+
* A media library file only has a thumbnail when the library sent one. Without it the grid draws the
|
|
1260
|
+
* file-type icon (or the file itself when it is a picture) instead of loading a PDF as a picture,
|
|
1261
|
+
* which would fail and show the file as "missing".
|
|
1262
|
+
*/
|
|
1263
|
+
function toGridFileItem(item: FileSystemItem): FileSystemItem {
|
|
1264
|
+
const storeBasePath = $fileStore?.basePath ?? basePath;
|
|
1265
|
+
return {
|
|
1266
|
+
...item,
|
|
1267
|
+
url: getCorrectFileUrl(item),
|
|
1268
|
+
thumbnail:
|
|
1269
|
+
libraryMode && !item.thumbnail
|
|
1270
|
+
? undefined
|
|
1271
|
+
: resolveFileItemUrl({ ...item, url: item.thumbnail || item.url }, storeBasePath),
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
|
|
980
1275
|
/**
|
|
981
1276
|
* Type guard for FileSystemItem
|
|
982
1277
|
* Ensures safe type checking for file operations
|
|
@@ -1107,34 +1402,38 @@
|
|
|
1107
1402
|
// console.log('call showToast method:', showToast);
|
|
1108
1403
|
|
|
1109
1404
|
// Show initial toast notification
|
|
1110
|
-
showToast('success',
|
|
1111
|
-
description: '
|
|
1405
|
+
showToast('success', $t('toast.rename.started', { name: oldName }), {
|
|
1406
|
+
description: $t('toast.inBackground'),
|
|
1112
1407
|
// duration: 1500
|
|
1113
1408
|
});
|
|
1114
1409
|
|
|
1115
|
-
// Perform the rename operation
|
|
1116
|
-
renameItem(itemId, newName)
|
|
1410
|
+
// Perform the rename operation (through the host's media library when there is one)
|
|
1411
|
+
(libraryMode ? renameInLibrary(itemId, newName) : renameItem(itemId, newName))
|
|
1117
1412
|
.then(success => {
|
|
1413
|
+
// The File Browser was closed while the library was working: there is no one to tell.
|
|
1414
|
+
if (libraryMode && libraryActionsController.signal.aborted) return;
|
|
1118
1415
|
if (success) {
|
|
1119
|
-
showToast('success', '
|
|
1120
|
-
description:
|
|
1416
|
+
showToast('success', $t('toast.rename.done'), {
|
|
1417
|
+
description: $t('toast.rename.doneDetail', { oldName, newName }),
|
|
1121
1418
|
});
|
|
1122
1419
|
} else {
|
|
1123
|
-
showToast('error', '
|
|
1124
|
-
description: '
|
|
1420
|
+
showToast('error', $t('toast.rename.failed'), {
|
|
1421
|
+
description: $t('toast.rename.noChange'),
|
|
1125
1422
|
});
|
|
1126
1423
|
}
|
|
1127
1424
|
})
|
|
1128
1425
|
.catch(error => {
|
|
1426
|
+
if (libraryMode && (libraryActionsController.signal.aborted || isCancellation(error))) return;
|
|
1129
1427
|
console.error('Error during rename operation:', error);
|
|
1130
|
-
showToast('error', '
|
|
1131
|
-
description: error
|
|
1428
|
+
showToast('error', $t('toast.rename.failed'), {
|
|
1429
|
+
description: messageForVisitor(error, $t, 'toast.rename.unknownError'),
|
|
1132
1430
|
});
|
|
1431
|
+
if (libraryMode) reportLibraryError(toMediaLibraryError(error, 'Could not rename the file', 'libraryError.renameFailed'), 'rename');
|
|
1133
1432
|
});
|
|
1134
1433
|
} else {
|
|
1135
1434
|
console.error('No valid item selected for rename operation');
|
|
1136
|
-
showToast('error', '
|
|
1137
|
-
description: '
|
|
1435
|
+
showToast('error', $t('toast.rename.failed'), {
|
|
1436
|
+
description: $t('toast.rename.noItem'),
|
|
1138
1437
|
});
|
|
1139
1438
|
}
|
|
1140
1439
|
}
|
|
@@ -1161,12 +1460,13 @@
|
|
|
1161
1460
|
showDeleteConfirmation = false;
|
|
1162
1461
|
|
|
1163
1462
|
// Show initial toast notification
|
|
1164
|
-
const initialToastMessage =
|
|
1165
|
-
|
|
1166
|
-
:
|
|
1463
|
+
const initialToastMessage = $t('toast.delete.started', {
|
|
1464
|
+
count: itemsToDelete.length,
|
|
1465
|
+
name: itemsToDelete[0]?.name ?? ''
|
|
1466
|
+
});
|
|
1167
1467
|
|
|
1168
1468
|
showToast('success', initialToastMessage, {
|
|
1169
|
-
description: '
|
|
1469
|
+
description: $t('toast.inBackground'),
|
|
1170
1470
|
});
|
|
1171
1471
|
|
|
1172
1472
|
// Process deletions in the background
|
|
@@ -1175,11 +1475,13 @@
|
|
|
1175
1475
|
let successCount = 0;
|
|
1176
1476
|
const deletedItems: string[] = [];
|
|
1177
1477
|
const failedItems: string[] = [];
|
|
1478
|
+
// Why the media library refused, to tell the visitor (only a media library gives reasons)
|
|
1479
|
+
let libraryFailure: MediaLibraryError | null = null;
|
|
1178
1480
|
|
|
1179
1481
|
// Process each item for deletion
|
|
1180
1482
|
for (const item of itemsToDelete) {
|
|
1181
1483
|
try {
|
|
1182
|
-
const success = await deleteItem(item.id);
|
|
1484
|
+
const success = libraryMode ? await deleteFromLibrary(item) : await deleteItem(item.id);
|
|
1183
1485
|
if (success) {
|
|
1184
1486
|
successCount++;
|
|
1185
1487
|
deletedItems.push(item.name);
|
|
@@ -1197,8 +1499,11 @@
|
|
|
1197
1499
|
failedItems.push(item.name);
|
|
1198
1500
|
}
|
|
1199
1501
|
} catch (itemError) {
|
|
1502
|
+
// The File Browser was closed while the library was working: stop, and tell no one.
|
|
1503
|
+
if (libraryMode && (libraryActionsController.signal.aborted || isCancellation(itemError))) return;
|
|
1200
1504
|
console.error(`Error deleting ${item.name}:`, itemError);
|
|
1201
1505
|
failedItems.push(item.name);
|
|
1506
|
+
if (libraryMode) libraryFailure = toMediaLibraryError(itemError, 'Could not delete the file', 'libraryError.deleteFailed');
|
|
1202
1507
|
}
|
|
1203
1508
|
}
|
|
1204
1509
|
|
|
@@ -1211,19 +1516,19 @@
|
|
|
1211
1516
|
// Single item deletion
|
|
1212
1517
|
const isFolder = itemsToDelete.find(item => item.name === deletedItems[0])?.type === 'folder';
|
|
1213
1518
|
toastMessage = isFolder
|
|
1214
|
-
?
|
|
1215
|
-
:
|
|
1519
|
+
? $t('toast.delete.doneFolder', { name: deletedItems[0] })
|
|
1520
|
+
: $t('toast.delete.doneFile', { name: deletedItems[0] });
|
|
1216
1521
|
toastDescription = isFolder
|
|
1217
|
-
? '
|
|
1218
|
-
: '
|
|
1522
|
+
? $t('toast.delete.doneFolderDetail')
|
|
1523
|
+
: $t('toast.delete.doneFileDetail');
|
|
1219
1524
|
} else {
|
|
1220
1525
|
// Multiple item deletion
|
|
1221
|
-
toastMessage =
|
|
1222
|
-
toastDescription =
|
|
1526
|
+
toastMessage = $t('toast.delete.doneMany', { count: successCount });
|
|
1527
|
+
toastDescription = $t('toast.delete.doneManyDetail', { count: successCount });
|
|
1223
1528
|
|
|
1224
1529
|
// Add details if small number of items deleted (up to 3)
|
|
1225
1530
|
if (successCount <= 3) {
|
|
1226
|
-
toastDescription =
|
|
1531
|
+
toastDescription = $t('toast.delete.doneNames', { names: deletedItems.join($t('list.separator')) });
|
|
1227
1532
|
}
|
|
1228
1533
|
}
|
|
1229
1534
|
|
|
@@ -1235,21 +1540,23 @@
|
|
|
1235
1540
|
// Show error toast if any deletions failed
|
|
1236
1541
|
if (failedItems.length > 0) {
|
|
1237
1542
|
const errorMessage = failedItems.length === 1
|
|
1238
|
-
?
|
|
1239
|
-
:
|
|
1543
|
+
? $t('toast.delete.failedOne', { name: failedItems[0] })
|
|
1544
|
+
: $t('toast.delete.failedMany', { count: failedItems.length });
|
|
1240
1545
|
|
|
1241
1546
|
const errorDescription = failedItems.length <= 3
|
|
1242
|
-
?
|
|
1243
|
-
: '
|
|
1547
|
+
? $t('toast.delete.failedNames', { names: failedItems.join($t('list.separator')) })
|
|
1548
|
+
: $t('toast.delete.failedSome');
|
|
1244
1549
|
|
|
1245
1550
|
showToast('error', errorMessage, {
|
|
1246
|
-
|
|
1551
|
+
// A media library says why (for example "not allowed"); that is more useful than the names again.
|
|
1552
|
+
description: libraryFailure ? messageForVisitor(libraryFailure, $t) : errorDescription,
|
|
1247
1553
|
});
|
|
1554
|
+
if (libraryFailure) reportLibraryError(libraryFailure, 'delete');
|
|
1248
1555
|
}
|
|
1249
1556
|
} catch (error) {
|
|
1250
1557
|
console.error('Error deleting items:', error);
|
|
1251
|
-
showToast('error', '
|
|
1252
|
-
description: error
|
|
1558
|
+
showToast('error', $t('toast.delete.failedAll'), {
|
|
1559
|
+
description: messageForVisitor(error, $t, 'toast.unknownError'),
|
|
1253
1560
|
});
|
|
1254
1561
|
}
|
|
1255
1562
|
}, 100); // Small delay to ensure UI updates first
|
|
@@ -1260,6 +1567,22 @@
|
|
|
1260
1567
|
return Boolean(uploadConfig?.accessToken && uploadConfig?.apiBasePath) || !useDemoContent;
|
|
1261
1568
|
}
|
|
1262
1569
|
|
|
1570
|
+
// The built-in "My uploads" folder is named in the visitor's language, and follows a change of language.
|
|
1571
|
+
function nameBuiltInFolder(folderName: string) {
|
|
1572
|
+
fileStore.update((store) => {
|
|
1573
|
+
const builtInFolder = store.root?.children?.find((child) => child.type === 'folder' && child.id === 'folder_my_uploads');
|
|
1574
|
+
if (!store.root || !builtInFolder || builtInFolder.name === folderName) return store;
|
|
1575
|
+
return {
|
|
1576
|
+
...store,
|
|
1577
|
+
root: {
|
|
1578
|
+
...store.root,
|
|
1579
|
+
children: (store.root.children ?? []).map((child) => (child === builtInFolder ? { ...child, name: folderName } : child)),
|
|
1580
|
+
},
|
|
1581
|
+
};
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
$: if (!libraryMode) nameBuiltInFolder($t('library.defaultLabel'));
|
|
1585
|
+
|
|
1263
1586
|
function persistMyUploadsTree() {
|
|
1264
1587
|
const store = get(fileStore);
|
|
1265
1588
|
const myUploads = store.root?.children?.find((c) => c.id === 'folder_my_uploads');
|
|
@@ -1293,8 +1616,8 @@
|
|
|
1293
1616
|
|
|
1294
1617
|
persistMyUploadsTree();
|
|
1295
1618
|
showNewFolderDialog = false;
|
|
1296
|
-
showToast('success', '
|
|
1297
|
-
description:
|
|
1619
|
+
showToast('success', $t('toast.folder.created'), {
|
|
1620
|
+
description: $t('toast.folder.createdDetail', { name: folderName }),
|
|
1298
1621
|
});
|
|
1299
1622
|
}
|
|
1300
1623
|
|
|
@@ -1320,7 +1643,8 @@
|
|
|
1320
1643
|
|
|
1321
1644
|
if (!response.ok) {
|
|
1322
1645
|
const error = await response.json();
|
|
1323
|
-
|
|
1646
|
+
// The server's own words are shown as they are; without any, the visitor reads the File Browser's sentence in the page's language
|
|
1647
|
+
throw new MediaLibraryError('FAILED', error.message || 'Failed to create folder', error.message ? {} : { messageKey: 'toast.folder.failed' });
|
|
1324
1648
|
}
|
|
1325
1649
|
|
|
1326
1650
|
const { folder } = await response.json();
|
|
@@ -1345,13 +1669,13 @@
|
|
|
1345
1669
|
});
|
|
1346
1670
|
|
|
1347
1671
|
showNewFolderDialog = false;
|
|
1348
|
-
showToast('success', '
|
|
1349
|
-
description:
|
|
1672
|
+
showToast('success', $t('toast.folder.created'), {
|
|
1673
|
+
description: $t('toast.folder.createdDetail', { name: folderName }),
|
|
1350
1674
|
});
|
|
1351
1675
|
} catch (error) {
|
|
1352
1676
|
if(showLogs) console.error('Error creating folder:', error);
|
|
1353
|
-
showToast('error', '
|
|
1354
|
-
description: error
|
|
1677
|
+
showToast('error', $t('toast.folder.failed'), {
|
|
1678
|
+
description: messageForVisitor(error, $t, 'toast.unknownError'),
|
|
1355
1679
|
});
|
|
1356
1680
|
}
|
|
1357
1681
|
}
|
|
@@ -1385,7 +1709,7 @@
|
|
|
1385
1709
|
// });
|
|
1386
1710
|
|
|
1387
1711
|
// Backspace key handler
|
|
1388
|
-
if (event.key === 'Backspace' && currentPath.length > 0 && !isInputFocused() && !$isModalOpen) {
|
|
1712
|
+
if (event.key === 'Backspace' && currentPath.length > 0 && !isInputFocused(event) && !$isModalOpen) {
|
|
1389
1713
|
event.preventDefault();
|
|
1390
1714
|
event.stopPropagation();
|
|
1391
1715
|
|
|
@@ -1400,10 +1724,12 @@
|
|
|
1400
1724
|
/**
|
|
1401
1725
|
* Checks if an input element is currently focused
|
|
1402
1726
|
* Prevents unintended backspace navigation when typing
|
|
1727
|
+
* @param event The key event being handled. Inside a shadow root `document.activeElement` is the shadow host, not
|
|
1728
|
+
* the field being typed in, so the field is taken from the event when there is one.
|
|
1403
1729
|
* @returns boolean indicating if an input element has focus
|
|
1404
1730
|
*/
|
|
1405
|
-
function isInputFocused() {
|
|
1406
|
-
const activeElement = document.activeElement;
|
|
1731
|
+
function isInputFocused(event?: Event) {
|
|
1732
|
+
const activeElement = (event?.composedPath?.()[0] as Element | undefined) ?? document.activeElement;
|
|
1407
1733
|
return (
|
|
1408
1734
|
activeElement instanceof HTMLInputElement ||
|
|
1409
1735
|
activeElement instanceof HTMLTextAreaElement ||
|
|
@@ -1442,7 +1768,7 @@
|
|
|
1442
1768
|
if (item.type === 'folder') {
|
|
1443
1769
|
return getFolderIcon(item, filter);
|
|
1444
1770
|
}
|
|
1445
|
-
const fileType =
|
|
1771
|
+
const fileType = getFileTypeOf(item);
|
|
1446
1772
|
|
|
1447
1773
|
if (fileType === 'video' && item.url) {
|
|
1448
1774
|
// For video files, construct the thumbnail path by replacing the video extension with .png
|
|
@@ -1458,7 +1784,7 @@
|
|
|
1458
1784
|
return getFileIcon(item.name);
|
|
1459
1785
|
}
|
|
1460
1786
|
|
|
1461
|
-
$: fileTypesText = formatFileTypesForDisplay();
|
|
1787
|
+
$: fileTypesText = formatFileTypesForDisplay($t);
|
|
1462
1788
|
|
|
1463
1789
|
function handleModalClose() {
|
|
1464
1790
|
showModal = false;
|
|
@@ -1474,6 +1800,12 @@
|
|
|
1474
1800
|
*/
|
|
1475
1801
|
function handleFileUploaded(event: CustomEvent) {
|
|
1476
1802
|
const { file, success } = event.detail;
|
|
1803
|
+
|
|
1804
|
+
// A media library keeps the file itself: the list only shows what it stored. Nothing is saved on this device.
|
|
1805
|
+
if (libraryMode) {
|
|
1806
|
+
if (success && file && !libraryActionsController.signal.aborted) addUploadedFileToLibraryList(file);
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1477
1809
|
|
|
1478
1810
|
if (success && file) {
|
|
1479
1811
|
const uploadedFile = {
|
|
@@ -1569,7 +1901,7 @@
|
|
|
1569
1901
|
// Scroll to and highlight the new file after a short delay to ensure rendering
|
|
1570
1902
|
setTimeout(() => {
|
|
1571
1903
|
scrollItemIntoView(file.id);
|
|
1572
|
-
const itemElement =
|
|
1904
|
+
const itemElement = findItemElement(file.id);
|
|
1573
1905
|
if (itemElement) {
|
|
1574
1906
|
itemElement.classList.add('wave-goodbye');
|
|
1575
1907
|
setTimeout(() => {
|
|
@@ -1673,8 +2005,8 @@
|
|
|
1673
2005
|
// if(showLogs) console.log('Attempting to scroll item into view:', itemId);
|
|
1674
2006
|
|
|
1675
2007
|
requestAnimationFrame(() => {
|
|
1676
|
-
const itemElement =
|
|
1677
|
-
const scrollableArea = scrollContainer || (document.querySelector('.scroll-area-container') as HTMLElement);
|
|
2008
|
+
const itemElement = findItemElement(itemId);
|
|
2009
|
+
const scrollableArea = scrollContainer || (mainContainer?.querySelector('.scroll-area-container') as HTMLElement | null) || (document.querySelector('.scroll-area-container') as HTMLElement);
|
|
1678
2010
|
|
|
1679
2011
|
if (itemElement && scrollableArea) {
|
|
1680
2012
|
// Handle animation first if it's a goodbye animation
|
|
@@ -1741,19 +2073,41 @@
|
|
|
1741
2073
|
}
|
|
1742
2074
|
|
|
1743
2075
|
// Add these new handlers
|
|
1744
|
-
function
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
2076
|
+
function pathAtHistoryIndex(): string[] {
|
|
2077
|
+
const state = get(navigationStore);
|
|
2078
|
+
const path = state.pathsArray[state.currentIndex];
|
|
2079
|
+
return Array.isArray(path) ? path : [];
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
function publishFileBrowserNav() {
|
|
2083
|
+
if (!isBrowser) return;
|
|
2084
|
+
window.dispatchEvent(new CustomEvent('widgetic:file-browser-nav', {
|
|
2085
|
+
detail: {
|
|
2086
|
+
instanceId,
|
|
2087
|
+
currentPath,
|
|
2088
|
+
currentPathNames,
|
|
2089
|
+
canGoBack: get(canGoBackStore),
|
|
2090
|
+
canGoForward: get(canGoForwardStore),
|
|
2091
|
+
},
|
|
2092
|
+
}));
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
function handleFileBrowserCommand(event: Event) {
|
|
2096
|
+
const detail = (event as CustomEvent).detail;
|
|
2097
|
+
if (!detail || detail.instanceId !== instanceId) return;
|
|
2098
|
+
if (detail.command === 'back') handleNavigateBack();
|
|
2099
|
+
else if (detail.command === 'forward') handleNavigateForward();
|
|
2100
|
+
else if (detail.command === 'index') {
|
|
2101
|
+
navigateToBreadcrumb({ detail: detail.index } as CustomEvent<number>);
|
|
2102
|
+
} else if (detail.command === 'publish') {
|
|
2103
|
+
publishFileBrowserNav();
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
1749
2106
|
|
|
2107
|
+
function handleNavigateBack() {
|
|
1750
2108
|
if(showLogs) console.log('Handling back navigation');
|
|
1751
2109
|
navigationStore.navigateBack();
|
|
1752
|
-
const newPath =
|
|
1753
|
-
if (!Array.isArray(newPath)) {
|
|
1754
|
-
if(showLogs) console.error('Invalid path received from navigation store:', newPath);
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
2110
|
+
const newPath = pathAtHistoryIndex();
|
|
1757
2111
|
if(showLogs) console.log('Back Navigation Details:', {
|
|
1758
2112
|
from: currentPath,
|
|
1759
2113
|
to: newPath
|
|
@@ -1763,18 +2117,9 @@
|
|
|
1763
2117
|
}
|
|
1764
2118
|
|
|
1765
2119
|
function handleNavigateForward() {
|
|
1766
|
-
// if (modalOpen) {
|
|
1767
|
-
// console.log('Modal is open, skipping forward navigation');
|
|
1768
|
-
// return;
|
|
1769
|
-
// }
|
|
1770
|
-
|
|
1771
2120
|
if(showLogs) console.log('Handling forward navigation');
|
|
1772
2121
|
navigationStore.navigateForward();
|
|
1773
|
-
const newPath =
|
|
1774
|
-
if (!Array.isArray(newPath)) {
|
|
1775
|
-
if(showLogs) console.error('Invalid path received from navigation store:', newPath);
|
|
1776
|
-
return;
|
|
1777
|
-
}
|
|
2122
|
+
const newPath = pathAtHistoryIndex();
|
|
1778
2123
|
if(showLogs) console.log('Forward Navigation Details:', {
|
|
1779
2124
|
from: currentPath,
|
|
1780
2125
|
to: newPath
|
|
@@ -1805,6 +2150,7 @@
|
|
|
1805
2150
|
} else {
|
|
1806
2151
|
currentPathNames = [];
|
|
1807
2152
|
}
|
|
2153
|
+
publishFileBrowserNav();
|
|
1808
2154
|
}
|
|
1809
2155
|
|
|
1810
2156
|
// Update the deduplication function to handle items with the same name
|
|
@@ -1890,8 +2236,10 @@
|
|
|
1890
2236
|
return;
|
|
1891
2237
|
}
|
|
1892
2238
|
|
|
1893
|
-
// Focus the container when clicking anywhere inside it
|
|
1894
|
-
|
|
2239
|
+
// Focus the container when clicking anywhere inside it. Without preventScroll the browser scrolls the whole page
|
|
2240
|
+
// to bring the container into view when it is only partly visible, which moves the control under the pointer
|
|
2241
|
+
// between mousedown and mouseup (the click is lost) and scrolls a host page that embeds the File Browser.
|
|
2242
|
+
mainContainer?.focus({ preventScroll: true });
|
|
1895
2243
|
}
|
|
1896
2244
|
|
|
1897
2245
|
// Update the keyboard shortcuts handler to batch updates
|
|
@@ -1910,10 +2258,12 @@
|
|
|
1910
2258
|
if ((event.metaKey || event.ctrlKey) && event.key === 'a') {
|
|
1911
2259
|
// console.log('FileBrowser Handle CMD/CTRL + A:', event, $isModalOpen);
|
|
1912
2260
|
|
|
2261
|
+
// Typing in a field: Ctrl+A selects the field's text, as it does everywhere else.
|
|
2262
|
+
if (isInputFocused(event)) return;
|
|
2263
|
+
|
|
1913
2264
|
event.preventDefault();
|
|
1914
2265
|
event.stopPropagation();
|
|
1915
2266
|
|
|
1916
|
-
if (isInputFocused()) return;
|
|
1917
2267
|
if (maxSelections === 1) return;
|
|
1918
2268
|
|
|
1919
2269
|
// Clear any text selection
|
|
@@ -2018,14 +2368,14 @@
|
|
|
2018
2368
|
currentPath = newPath;
|
|
2019
2369
|
} else {
|
|
2020
2370
|
if(showLogs) console.error('Could not find path for folder:', targetFolderId);
|
|
2021
|
-
showToast('error', '
|
|
2022
|
-
description: '
|
|
2371
|
+
showToast('error', $t('toast.navigation.failed'), {
|
|
2372
|
+
description: $t('toast.navigation.noFolder'),
|
|
2023
2373
|
});
|
|
2024
2374
|
}
|
|
2025
2375
|
} catch (error) {
|
|
2026
2376
|
if(showLogs) console.error('Error during move navigation:', error);
|
|
2027
|
-
showToast('error', '
|
|
2028
|
-
description: '
|
|
2377
|
+
showToast('error', $t('toast.navigation.failed'), {
|
|
2378
|
+
description: $t('toast.navigation.error'),
|
|
2029
2379
|
});
|
|
2030
2380
|
}
|
|
2031
2381
|
}
|
|
@@ -2049,22 +2399,16 @@
|
|
|
2049
2399
|
}
|
|
2050
2400
|
|
|
2051
2401
|
// Add in script section after other filter-related code
|
|
2052
|
-
// Format filter type for display
|
|
2053
|
-
function formatFilterType(filterType: FileFilterType): string {
|
|
2054
|
-
if (filterType === 'all') return 'All';
|
|
2055
|
-
// Capitalize first letter
|
|
2056
|
-
return filterType.charAt(0).toUpperCase() + filterType.slice(1);
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
2402
|
// Filter options for the dropdown
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
{ value: '
|
|
2063
|
-
{ value: '
|
|
2064
|
-
{ value: '
|
|
2065
|
-
{ value: '
|
|
2066
|
-
{ value: '
|
|
2067
|
-
{ value: '
|
|
2403
|
+
let filterOptions: Array<{ value: FileFilterType; label: string }> = [];
|
|
2404
|
+
$: filterOptions = [
|
|
2405
|
+
{ value: 'all', label: $t('filterOption.all') },
|
|
2406
|
+
{ value: 'image', label: $t('filterOption.image') },
|
|
2407
|
+
{ value: 'video', label: $t('filterOption.video') },
|
|
2408
|
+
{ value: 'document', label: $t('filterOption.document') },
|
|
2409
|
+
{ value: 'audio', label: $t('filterOption.audio') },
|
|
2410
|
+
{ value: 'font', label: $t('filterOption.font') },
|
|
2411
|
+
{ value: 'svg', label: $t('filterOption.svg') }
|
|
2068
2412
|
];
|
|
2069
2413
|
|
|
2070
2414
|
// Add these state variables
|
|
@@ -2110,7 +2454,7 @@
|
|
|
2110
2454
|
|
|
2111
2455
|
// Find the files that match the new filter type
|
|
2112
2456
|
const matchingFiles = allFiles.filter(file =>
|
|
2113
|
-
|
|
2457
|
+
getFileTypeOf(file) === newFilter
|
|
2114
2458
|
);
|
|
2115
2459
|
|
|
2116
2460
|
// Get IDs of matching files that were previously selected
|
|
@@ -2138,7 +2482,7 @@
|
|
|
2138
2482
|
|
|
2139
2483
|
// Find the files that match the new filter type
|
|
2140
2484
|
const matchingFiles = allFiles.filter(file =>
|
|
2141
|
-
|
|
2485
|
+
getFileTypeOf(file) === newFilter
|
|
2142
2486
|
);
|
|
2143
2487
|
|
|
2144
2488
|
// Get selected files from the "all" filter (which should be the master list)
|
|
@@ -2304,7 +2648,8 @@ mainGridClass="app-main-grid"
|
|
|
2304
2648
|
canGoBack={$canGoBackStore}
|
|
2305
2649
|
canGoForward={$canGoForwardStore}
|
|
2306
2650
|
on:toggleSelectedFiles={(e : CustomEvent) => allowSelecting && toggleModal()}
|
|
2307
|
-
showBreadcrumbs={showBreadcrumbs}
|
|
2651
|
+
showBreadcrumbs={showBreadcrumbs && !libraryMode}
|
|
2652
|
+
title={libraryMode ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel')) : ''}
|
|
2308
2653
|
/>
|
|
2309
2654
|
|
|
2310
2655
|
<!-- FILE BROWSER CONTROLS -->
|
|
@@ -2314,7 +2659,7 @@ mainGridClass="app-main-grid"
|
|
|
2314
2659
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
2315
2660
|
<div onclick={handleSearch} class="w-full cursor-pointer">
|
|
2316
2661
|
<SearchInput
|
|
2317
|
-
placeholder=
|
|
2662
|
+
placeholder={$t('search.placeholder')}
|
|
2318
2663
|
value=""
|
|
2319
2664
|
containerClass="w-full"
|
|
2320
2665
|
onInput={() => {}}
|
|
@@ -2340,7 +2685,7 @@ mainGridClass="app-main-grid"
|
|
|
2340
2685
|
filterDropdownOpen = !filterDropdownOpen;
|
|
2341
2686
|
}}
|
|
2342
2687
|
>
|
|
2343
|
-
<span>
|
|
2688
|
+
<span>{$t('filter.by', { type: $t(`filterName.${filter}`) })}</span>
|
|
2344
2689
|
<IconAdjustmentsHorizontal class="h-5 w-5 text-[hsl(var(--grey5))] ml-1 transition-colors duration-200 group-hover:text-[hsl(var(--grey7))]" />
|
|
2345
2690
|
</button>
|
|
2346
2691
|
|
|
@@ -2380,9 +2725,9 @@ mainGridClass="app-main-grid"
|
|
|
2380
2725
|
class="bg-white border border-gray-300 rounded-md px-3 py-1.5 text-sm"
|
|
2381
2726
|
bind:value={$sortCriteria}
|
|
2382
2727
|
>
|
|
2383
|
-
<option value="name">
|
|
2384
|
-
<option value="date">
|
|
2385
|
-
<option value="size">
|
|
2728
|
+
<option value="name">{$t('sort.name')}</option>
|
|
2729
|
+
<option value="date">{$t('sort.date')}</option>
|
|
2730
|
+
<option value="size">{$t('sort.size')}</option>
|
|
2386
2731
|
</select>
|
|
2387
2732
|
|
|
2388
2733
|
<!-- Sort Direction Button -->
|
|
@@ -2401,6 +2746,16 @@ mainGridClass="app-main-grid"
|
|
|
2401
2746
|
|
|
2402
2747
|
<!-- FILE BROWSER CONTENT -->
|
|
2403
2748
|
<div class="file-browser-content flex min-h-0 flex-col grow mr-[4px] overflow-hidden relative widgetic-colors">
|
|
2749
|
+
<!-- Media library notice: the list on screen is not the whole library -->
|
|
2750
|
+
{#if libraryNotice}
|
|
2751
|
+
<div class="library-notice mx-6 mt-3 flex shrink-0 items-center justify-between gap-3 rounded-md bg-[hsl(var(--grey1))] px-3 py-2 subtext text-[hsl(var(--grey7))]" role="status">
|
|
2752
|
+
<span>{libraryNotice.text}</span>
|
|
2753
|
+
{#if libraryNotice.canRetry}
|
|
2754
|
+
<button type="button" class="library-notice-retry shrink-0 underline" onclick={reloadLibrary}>{$t('action.tryAgain')}</button>
|
|
2755
|
+
{/if}
|
|
2756
|
+
</div>
|
|
2757
|
+
{/if}
|
|
2758
|
+
|
|
2404
2759
|
<!-- Loader Container -->
|
|
2405
2760
|
{#if isLoading}
|
|
2406
2761
|
<div class="loader-container p-6">
|
|
@@ -2417,6 +2772,20 @@ mainGridClass="app-main-grid"
|
|
|
2417
2772
|
</div>
|
|
2418
2773
|
</div>
|
|
2419
2774
|
|
|
2775
|
+
<!-- Media library error: it cannot be used, or its first page could not be read -->
|
|
2776
|
+
{:else if libraryErrorMessage}
|
|
2777
|
+
<div class="library-error-container relative min-h-0 flex-1" role="alert">
|
|
2778
|
+
<div class="empty-state-wrapper w-full flex justify-center items-center">
|
|
2779
|
+
<EmptyState message={libraryErrorMessage} height="auto">
|
|
2780
|
+
<svelte:fragment slot="action">
|
|
2781
|
+
{#if !libraryConfigError}
|
|
2782
|
+
<Button variant="outline" size="sm" onclick={reloadLibrary}>{$t('action.tryAgain')}</Button>
|
|
2783
|
+
{/if}
|
|
2784
|
+
</svelte:fragment>
|
|
2785
|
+
</EmptyState>
|
|
2786
|
+
</div>
|
|
2787
|
+
</div>
|
|
2788
|
+
|
|
2420
2789
|
<!-- Files container -->
|
|
2421
2790
|
{:else}
|
|
2422
2791
|
<!-- Main content container with Files Inside --> <!-- {!showAddToEditor ? 'overflow-y-auto px-6' : ''} -->
|
|
@@ -2459,7 +2828,7 @@ mainGridClass="app-main-grid"
|
|
|
2459
2828
|
<!-- Files GRID List(VirtualList) -->
|
|
2460
2829
|
<VirtualList class="content-container grow"
|
|
2461
2830
|
{scrollContainer}
|
|
2462
|
-
items={[{ type: 'new-folder' }, ...sortedFilteredFiles]}
|
|
2831
|
+
items={libraryCapabilities.folders ? [{ type: 'new-folder' }, ...sortedFilteredFiles] : sortedFilteredFiles}
|
|
2463
2832
|
itemHeight={GRID_ITEM_HEIGHT}
|
|
2464
2833
|
columns={mainContainerWidth <= mobileBreakpoint ? 2 :
|
|
2465
2834
|
mainContainerWidth <= tabletBreakpoint ? 3 : 4}
|
|
@@ -2488,14 +2857,7 @@ mainGridClass="app-main-grid"
|
|
|
2488
2857
|
/>
|
|
2489
2858
|
{:else}
|
|
2490
2859
|
<FileItem
|
|
2491
|
-
item={
|
|
2492
|
-
...item,
|
|
2493
|
-
url: getCorrectFileUrl(item),
|
|
2494
|
-
thumbnail: resolveFileItemUrl(
|
|
2495
|
-
{ ...item, url: item.thumbnail || item.url },
|
|
2496
|
-
$fileStore?.basePath ?? basePath
|
|
2497
|
-
),
|
|
2498
|
-
}}
|
|
2860
|
+
item={toGridFileItem(item)}
|
|
2499
2861
|
selected={allowSelecting && currentSelections.some(f => f.id === item.id)}
|
|
2500
2862
|
{allowSelecting}
|
|
2501
2863
|
gridLayout={true}
|
|
@@ -2508,8 +2870,8 @@ mainGridClass="app-main-grid"
|
|
|
2508
2870
|
</div>
|
|
2509
2871
|
</VirtualList>
|
|
2510
2872
|
|
|
2511
|
-
<!-- Recent Files -->
|
|
2512
|
-
{#if currentPath.length === 0 && recentFiles.length > 0 && mainContainerWidth > tabletBreakpoint}
|
|
2873
|
+
<!-- Recent Files (a media library is one flat list, so they would only repeat the grid) -->
|
|
2874
|
+
{#if !libraryMode && currentPath.length === 0 && recentFiles.length > 0 && mainContainerWidth > tabletBreakpoint}
|
|
2513
2875
|
<RecentFiles class="recent-files-container"
|
|
2514
2876
|
{recentFiles}
|
|
2515
2877
|
selectedFiles={allSelectedFiles}
|
|
@@ -2527,14 +2889,16 @@ mainGridClass="app-main-grid"
|
|
|
2527
2889
|
<div class="empty-content-container">
|
|
2528
2890
|
|
|
2529
2891
|
<!-- New Folder Button -->
|
|
2530
|
-
|
|
2531
|
-
<
|
|
2532
|
-
|
|
2892
|
+
{#if libraryCapabilities.folders}
|
|
2893
|
+
<div class="grid grid-cols-3 gap-8 relative z-20 pointer-events-auto">
|
|
2894
|
+
<NewFolderButton on:click={handleNewFolderClick} />
|
|
2895
|
+
</div>
|
|
2896
|
+
{/if}
|
|
2533
2897
|
|
|
2534
2898
|
<!-- Empty State Container -->
|
|
2535
2899
|
<div class="empty-state-wrapper w-full flex justify-center items-center">
|
|
2536
2900
|
<EmptyState
|
|
2537
|
-
message=
|
|
2901
|
+
message={libraryMode ? (filter === 'all' ? $t('empty.library') : $t('empty.libraryFiltered')) : $t('empty.folder')}
|
|
2538
2902
|
height="auto"
|
|
2539
2903
|
>
|
|
2540
2904
|
</EmptyState>
|
|
@@ -2558,7 +2922,7 @@ mainGridClass="app-main-grid"
|
|
|
2558
2922
|
filter={filter}
|
|
2559
2923
|
allowSelecting={allowSelecting}
|
|
2560
2924
|
{showAddToEditor}
|
|
2561
|
-
{
|
|
2925
|
+
addToEditorLabel={addToEditorText}
|
|
2562
2926
|
{activeFileId}
|
|
2563
2927
|
{maxSelections}
|
|
2564
2928
|
compact={mainContainerWidth > 0 && mainContainerWidth < 700}
|
|
@@ -2575,8 +2939,8 @@ mainGridClass="app-main-grid"
|
|
|
2575
2939
|
</div>
|
|
2576
2940
|
{/if}
|
|
2577
2941
|
|
|
2578
|
-
<!-- FILE UPLOADER -->
|
|
2579
|
-
{#if !isLoading}
|
|
2942
|
+
<!-- FILE UPLOADER (a media library without upload has nothing to upload to) -->
|
|
2943
|
+
{#if !isLoading && libraryCapabilities.upload}
|
|
2580
2944
|
<div class="file-uploader-container shrink-0 bg-white border-t border-[hsl(var(--grey1))] {isTablet ? 'px-2' : 'px-6'} {isTablet ? 'py-2' : 'py-6'} error widgetic-colors">
|
|
2581
2945
|
<FileUploader
|
|
2582
2946
|
bind:this={fileUploaderComponent}
|
|
@@ -2585,7 +2949,7 @@ mainGridClass="app-main-grid"
|
|
|
2585
2949
|
{filter}
|
|
2586
2950
|
portalTarget={mainContainer}
|
|
2587
2951
|
on:fileUploaded={handleFileUploaded}
|
|
2588
|
-
on:error={
|
|
2952
|
+
on:error={handleUploadError}
|
|
2589
2953
|
bind:dragActive
|
|
2590
2954
|
bind:dragInvalid
|
|
2591
2955
|
bind:hasValidFiles
|
|
@@ -2605,7 +2969,7 @@ mainGridClass="app-main-grid"
|
|
|
2605
2969
|
target={rootContainerClass}
|
|
2606
2970
|
allFiles={getAllFiles($fileStore.root)}
|
|
2607
2971
|
{showAddToEditor}
|
|
2608
|
-
{
|
|
2972
|
+
addToEditorLabel={addToEditorText}
|
|
2609
2973
|
on:close={handleModalClose}
|
|
2610
2974
|
on:fileUploaded={handleFileUploaded}
|
|
2611
2975
|
on:navigate={handleSearchNavigate}
|
|
@@ -2642,8 +3006,19 @@ mainGridClass="app-main-grid"
|
|
|
2642
3006
|
itemName={selectedItem?.name ?? ''}
|
|
2643
3007
|
itemType={selectedItem?.type === 'folder' ? 'folder' : 'file'}
|
|
2644
3008
|
itemId={selectedItem?.id ?? ''}
|
|
2645
|
-
|
|
2646
|
-
|
|
3009
|
+
placeholder={selectedItem?.type === 'folder' ? $t('dialog.rename.folderPlaceholder') : $t('dialog.rename.filePlaceholder')}
|
|
3010
|
+
confirmLabel={$t('action.rename')}
|
|
3011
|
+
cancelLabel={$t('action.cancel')}
|
|
3012
|
+
closeLabel={$t('dialog.close')}
|
|
3013
|
+
messages={{
|
|
3014
|
+
invalidTitle: $t('dialog.rename.invalidTitle'),
|
|
3015
|
+
enterName: $t('dialog.rename.enterName'),
|
|
3016
|
+
enterDifferentName: $t('dialog.rename.enterDifferentName'),
|
|
3017
|
+
enterValidName: $t('dialog.rename.enterValidName'),
|
|
3018
|
+
tooShort: $t('dialog.rename.tooShort'),
|
|
3019
|
+
// The dialog knows its own limit: it puts the number in where {max} stands
|
|
3020
|
+
tooLong: $t('dialog.rename.tooLong', { max: '{max}' })
|
|
3021
|
+
}}
|
|
2647
3022
|
target={rootContainerClass}
|
|
2648
3023
|
shouldUseCustomRenameFunction={true}
|
|
2649
3024
|
on:rename={handleRename}
|
|
@@ -2691,7 +3066,7 @@ mainGridClass="app-main-grid"
|
|
|
2691
3066
|
|
|
2692
3067
|
// Add wave animation to all moved items
|
|
2693
3068
|
detail.movedItems.forEach((item: { id: string }) => {
|
|
2694
|
-
const itemElement =
|
|
3069
|
+
const itemElement = findItemElement(item.id);
|
|
2695
3070
|
if (itemElement) {
|
|
2696
3071
|
itemElement.classList.add('wave-goodbye');
|
|
2697
3072
|
setTimeout(() => {
|
|
@@ -2709,18 +3084,21 @@ mainGridClass="app-main-grid"
|
|
|
2709
3084
|
{#if showDeleteConfirmation}
|
|
2710
3085
|
<ActionModal
|
|
2711
3086
|
bind:isOpen={showDeleteConfirmation}
|
|
2712
|
-
title={selectedItem?.type === 'folder' ? '
|
|
3087
|
+
title={selectedItem?.type === 'folder' ? $t('dialog.delete.folderTitle') : (allSelectedFiles.length > 1 ? $t('dialog.delete.itemsTitle') : $t('dialog.delete.fileTitle'))}
|
|
2713
3088
|
message={selectedItem?.type === 'folder'
|
|
2714
|
-
?
|
|
3089
|
+
? $t('dialog.delete.folderMessage', { name: selectedItem?.name ?? '' })
|
|
2715
3090
|
: (allSelectedFiles.length > 1
|
|
2716
|
-
?
|
|
2717
|
-
:
|
|
3091
|
+
? $t('dialog.delete.itemsMessage', { count: allSelectedFiles.length })
|
|
3092
|
+
: $t('dialog.delete.fileMessage', { name: allSelectedFiles[0]?.name ?? '' }))}
|
|
2718
3093
|
items={selectedItem?.type === 'folder' ? [selectedItem] : allSelectedFiles}
|
|
2719
3094
|
target={rootContainerClass}
|
|
2720
3095
|
on:confirm={handleDelete}
|
|
2721
3096
|
on:cancel={() => {
|
|
2722
3097
|
showDeleteConfirmation = false;
|
|
2723
3098
|
}}
|
|
3099
|
+
confirmLabel={$t('action.confirm')}
|
|
3100
|
+
cancelLabel={$t('action.cancel')}
|
|
3101
|
+
closeLabel={$t('dialog.close')}
|
|
2724
3102
|
actionType="delete"
|
|
2725
3103
|
confirmVariant="attention"
|
|
2726
3104
|
modalType="delete"
|
|
@@ -2732,27 +3110,25 @@ mainGridClass="app-main-grid"
|
|
|
2732
3110
|
bind:isOpen={showNewFolderDialog}
|
|
2733
3111
|
itemType="folder"
|
|
2734
3112
|
modalType="newFolder"
|
|
2735
|
-
placeholder=
|
|
3113
|
+
placeholder={$t('dialog.newFolder.placeholder')}
|
|
2736
3114
|
target={rootContainerClass}
|
|
2737
3115
|
{currentPath}
|
|
2738
3116
|
{currentPathNames}
|
|
2739
3117
|
showTitle={false}
|
|
2740
|
-
confirmLabel=
|
|
2741
|
-
cancelLabel=
|
|
3118
|
+
confirmLabel={$t('action.create')}
|
|
3119
|
+
cancelLabel={$t('action.cancel')}
|
|
3120
|
+
closeLabel={$t('dialog.close')}
|
|
3121
|
+
messages={{
|
|
3122
|
+
invalidTitle: $t('dialog.newFolder.invalidTitle'),
|
|
3123
|
+
required: $t('dialog.newFolder.required'),
|
|
3124
|
+
invalidCharacters: $t('dialog.newFolder.invalidCharacters'),
|
|
3125
|
+
// The dialog knows its own limit: it puts the number in where {max} stands
|
|
3126
|
+
tooLong: $t('dialog.newFolder.tooLong', { max: '{max}' })
|
|
3127
|
+
}}
|
|
2742
3128
|
on:create={handleNewFolder}
|
|
2743
3129
|
on:cancel={() => { showNewFolderDialog = false; }}
|
|
2744
3130
|
/>
|
|
2745
3131
|
{/if}
|
|
2746
|
-
target={rootContainerClass}
|
|
2747
|
-
{currentPath}
|
|
2748
|
-
{currentPathNames}
|
|
2749
|
-
showTitle={false}
|
|
2750
|
-
confirmLabel="Create"
|
|
2751
|
-
cancelLabel="Cancel"
|
|
2752
|
-
on:create={handleNewFolder}
|
|
2753
|
-
on:cancel={() => { showNewFolderDialog = false; }}
|
|
2754
|
-
/>
|
|
2755
|
-
|
|
2756
3132
|
|
|
2757
3133
|
<!-- STYLES -->
|
|
2758
3134
|
<style>
|