@widgetic/file-browser 0.5.40 → 0.5.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/core/FileBrowser.svelte +157 -62
- package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
- package/dist/components/core/FileUploader.svelte +49 -15
- package/dist/components/core/RecentFiles.svelte +23 -11
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +124 -26
- package/dist/components/core/UploadPanel.svelte +1 -1
- package/dist/components/items/FileItem.svelte +12 -2
- package/dist/components/items/FolderItem.svelte +8 -1
- package/dist/components/modals/index.d.ts +0 -1
- package/dist/components/modals/index.js +0 -1
- package/dist/components/previews/FilePreview.svelte +226 -35
- package/dist/components/previews/FilePreview.svelte.d.ts +7 -3
- package/dist/components/previews/FontPreview.svelte +4 -1
- package/dist/components/previews/FontPreview.svelte.d.ts +2 -0
- package/dist/components/previews/ImagePreview.svelte +60 -31
- package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +33 -25
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
- package/dist/components/ui/DragSelect.svelte +85 -67
- package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
- package/dist/data/demoContent.json +13 -11
- package/dist/i18n/messages.d.ts +0 -1
- package/dist/i18n/messages.js +0 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/stores/navigationStore.d.ts +5 -0
- package/dist/stores/navigationStore.js +40 -67
- package/dist/utils/escapeSelectionAction.d.ts +18 -0
- package/dist/utils/escapeSelectionAction.js +18 -0
- package/dist/utils/imagePreviewCache.d.ts +16 -0
- package/dist/utils/imagePreviewCache.js +78 -0
- package/dist/utils/imagePreviewVisualState.d.ts +19 -0
- package/dist/utils/imagePreviewVisualState.js +22 -0
- package/dist/utils/menuKeydownBubble.d.ts +9 -0
- package/dist/utils/menuKeydownBubble.js +11 -0
- package/dist/utils/previewNavigation.d.ts +4 -0
- package/dist/utils/previewNavigation.js +17 -0
- package/dist/utils/recentFiles.d.ts +6 -0
- package/dist/utils/recentFiles.js +21 -0
- package/dist/utils/recentFilesLimit.d.ts +8 -0
- package/dist/utils/recentFilesLimit.js +17 -0
- package/dist/utils/searchEscapeAction.d.ts +10 -0
- package/dist/utils/searchEscapeAction.js +12 -0
- package/dist/utils/searchItems.d.ts +2 -4
- package/dist/utils/searchItems.js +12 -5
- package/dist/utils/searchNavigation.d.ts +12 -0
- package/dist/utils/searchNavigation.js +42 -0
- package/dist/utils/uploadDisplayProgress.d.ts +4 -0
- package/dist/utils/uploadDisplayProgress.js +9 -0
- package/dist/utils/uploadListReconcile.d.ts +11 -0
- package/dist/utils/uploadListReconcile.js +30 -0
- package/dist/utils/uploadPanelProgress.d.ts +5 -0
- package/dist/utils/uploadPanelProgress.js +17 -0
- package/dist/utils/userUploadsStorage.d.ts +8 -0
- package/dist/utils/userUploadsStorage.js +32 -0
- package/package.json +3 -3
- package/dist/components/modals/SearchModal.svelte +0 -296
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
|
@@ -68,14 +68,18 @@
|
|
|
68
68
|
import { getFileBrowserUploadConfig, setFileBrowserUploadConfig } from '../../stores/uploadApiStore';
|
|
69
69
|
import {
|
|
70
70
|
loadUserUploads,
|
|
71
|
+
removePersistedUploads,
|
|
72
|
+
replacePersistedUploads,
|
|
71
73
|
saveUserUpload,
|
|
72
74
|
saveUserUploadsBatch,
|
|
73
75
|
saveLibraryTreeChildren,
|
|
74
76
|
createUserUploadsFileSystemRoot,
|
|
75
77
|
} from '../../utils/userUploadsStorage';
|
|
76
78
|
import { fetchUserUploadsFromApi } from '../../utils/widgeticUpload';
|
|
79
|
+
import { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from '../../utils/uploadListReconcile';
|
|
77
80
|
import { get, writable } from 'svelte/store';
|
|
78
81
|
import { resolveFileItemUrl } from '../../utils/resolveFileUrl';
|
|
82
|
+
import { buildDeduplicatedRecentFiles } from '../../utils/recentFiles';
|
|
79
83
|
import { dev } from '$app/environment';
|
|
80
84
|
import demoContentData from '../../data/demoContent.json';
|
|
81
85
|
// import { showToast } from '../../utils/toastUtils';
|
|
@@ -102,7 +106,8 @@
|
|
|
102
106
|
createCanGoBackStore,
|
|
103
107
|
createCanGoForwardStore,
|
|
104
108
|
getStorageKey,
|
|
105
|
-
getStoredState
|
|
109
|
+
getStoredState,
|
|
110
|
+
setPersistFolderPath
|
|
106
111
|
} from '../../stores/navigationStore';
|
|
107
112
|
//
|
|
108
113
|
import { persistentSelectStore, validSelections } from '../../stores/persistentSelectStore';
|
|
@@ -117,6 +122,8 @@
|
|
|
117
122
|
import { appendNewFiles, createLibraryRoot, removeFiles, replaceFile, upsertFile } from '../../mediaLibrary/treeOps';
|
|
118
123
|
import type { MediaLibraryErrorCode, MediaLibraryProvider } from '../../mediaLibrary/types';
|
|
119
124
|
import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
|
|
125
|
+
import { escapeSelectionAction } from '../../utils/escapeSelectionAction';
|
|
126
|
+
import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
|
|
120
127
|
|
|
121
128
|
// I18N IMPORTS (the words of the File Browser, in the page's language)
|
|
122
129
|
import { provideI18n } from '../../i18n/context';
|
|
@@ -173,11 +180,23 @@
|
|
|
173
180
|
export let initialSortCriteria: 'name' | 'date' | 'size' = 'name'; // Default to date
|
|
174
181
|
// navigation settings
|
|
175
182
|
export let instanceId: string = 'default'; // Unique identifier for this file browser instance
|
|
176
|
-
|
|
183
|
+
/** Persists folder path, filter, and sort in localStorage (full-page browsers). Off in library mode. */
|
|
184
|
+
export let persistHistory = true;
|
|
185
|
+
/**
|
|
186
|
+
* Persists only the folder path in localStorage (single-file pickers). Does not save filter or sort — the control
|
|
187
|
+
* fixes the file type. Use with `persistHistory={false}` on a dedicated `instanceId`.
|
|
188
|
+
*/
|
|
189
|
+
export let rememberFolder = false;
|
|
177
190
|
export let showBreadcrumbs = true; // Whether to show breadcrumbs
|
|
178
191
|
// selection settings
|
|
179
192
|
export let allowSelecting = true; // Toggle file selection functionality by default
|
|
180
193
|
export let maxSelections: number | null = null; // null = unlimited; 1 = single-file picker
|
|
194
|
+
/** Single-file pickers (selectors) hide sort controls and keep the default name order. */
|
|
195
|
+
$: isSingleFilePicker = maxSelections === 1;
|
|
196
|
+
$: controlsShowSorting = showSorting && !isSingleFilePicker;
|
|
197
|
+
/** Fixed-type selectors never show the type filter, even if a host passes `showFilters={true}`. */
|
|
198
|
+
$: controlsShowFilters = showFilters && !(isSingleFilePicker && initialFilter !== 'all');
|
|
199
|
+
let rubberBandDragActive = false;
|
|
181
200
|
/** When set (single-file picker), disables confirm until user picks a different file. */
|
|
182
201
|
export let activeFileId: string | null = null;
|
|
183
202
|
export let showAddToEditor = false; // Toggle visibility of "Add to Editor" functionality
|
|
@@ -319,7 +338,7 @@
|
|
|
319
338
|
|
|
320
339
|
// Initialize filter with a function to check localStorage first
|
|
321
340
|
let filter: FileFilterType = (() => {
|
|
322
|
-
if (persistHistory) {
|
|
341
|
+
if (persistHistory && maxSelections !== 1) {
|
|
323
342
|
try {
|
|
324
343
|
if (isBrowser) {
|
|
325
344
|
const storedFilter = getFromStorage(FILTER_STORAGE_KEY(instanceId), null);
|
|
@@ -513,6 +532,10 @@
|
|
|
513
532
|
// The text of the confirm button: the page's label, or the message of the language in use.
|
|
514
533
|
$: addToEditorText = addToEditorLabel ?? $t('action.addToEditor');
|
|
515
534
|
|
|
535
|
+
$: shouldPersistFolderInStorage =
|
|
536
|
+
!libraryMode && (rememberFolder || (persistHistory && maxSelections !== 1));
|
|
537
|
+
$: setPersistFolderPath(instanceId, shouldPersistFolderInStorage);
|
|
538
|
+
|
|
516
539
|
// A shared browser must not show the next visitor the previous one's picks, so a library turns this off unless the
|
|
517
540
|
// host asks for it. Selecting still works; the picks just live in memory.
|
|
518
541
|
const selectionIsKept = persistSelection ?? !libraryMode;
|
|
@@ -748,13 +771,14 @@
|
|
|
748
771
|
let files = await loadUserUploads();
|
|
749
772
|
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
750
773
|
try {
|
|
751
|
-
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
774
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
775
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
776
|
+
});
|
|
777
|
+
files = mergeRemoteUploadList(files, remoteFiles, {
|
|
778
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
779
|
+
apiHydrationSucceeded: true,
|
|
780
|
+
});
|
|
781
|
+
await replacePersistedUploads(files);
|
|
758
782
|
if (showLogs) {
|
|
759
783
|
// console.log('[FileBrowser] Hydrated uploads from API:', remoteFiles.length);
|
|
760
784
|
}
|
|
@@ -861,7 +885,7 @@
|
|
|
861
885
|
let pathToNavigate: string[] = [];
|
|
862
886
|
|
|
863
887
|
// Check if we have a stored path to restore (a media library has no folders to go back to)
|
|
864
|
-
if (
|
|
888
|
+
if (shouldPersistFolderInStorage) {
|
|
865
889
|
const storedState = getStoredState(instanceId);
|
|
866
890
|
if (storedState) {
|
|
867
891
|
pathToNavigate = storedState.pathsArray[storedState.currentIndex] || [];
|
|
@@ -885,7 +909,7 @@
|
|
|
885
909
|
const navStartTime = performance.now();
|
|
886
910
|
|
|
887
911
|
// if there is no stored path, reset navigation to root
|
|
888
|
-
if (!
|
|
912
|
+
if (!shouldPersistFolderInStorage || pathToNavigate.length === 0) {
|
|
889
913
|
// if(showLogs) console.log('FileBrowser onMount: No valid stored path, resetting navigation to root');
|
|
890
914
|
navigationStore.reset();
|
|
891
915
|
currentFolder.set([]);
|
|
@@ -1125,7 +1149,10 @@
|
|
|
1125
1149
|
(isEmpty || hasNoMatchingFiles) && scrollAreaHeight > 0
|
|
1126
1150
|
? `min-height: ${Math.max(0, scrollAreaHeight - 24)}px;`
|
|
1127
1151
|
: '';
|
|
1128
|
-
|
|
1152
|
+
// Centred in the scroll viewport, not in the flow below folder tiles (selector empty views must not jump).
|
|
1153
|
+
$: showEmptyTypeOverlay = !isLoading && (isEmpty || hasNoMatchingFiles);
|
|
1154
|
+
$: emptyOverlayViewportHeight =
|
|
1155
|
+
scrollAreaHeight > 0 ? `${Math.max(0, scrollAreaHeight - 24)}px` : undefined;
|
|
1129
1156
|
// What an empty view says, and with which icon: a type filter that matches nothing, an empty media library,
|
|
1130
1157
|
// or an empty folder (Figma "Files / No matching files", "Empty library" and "Empty folder").
|
|
1131
1158
|
$: emptyViewMessage =
|
|
@@ -1186,16 +1213,14 @@
|
|
|
1186
1213
|
|
|
1187
1214
|
/**
|
|
1188
1215
|
* Filters and sorts current folder contents based on active filter and sort criteria.
|
|
1189
|
-
* Folders are always
|
|
1216
|
+
* Folders are always listed; files must match the filter.
|
|
1190
1217
|
*/
|
|
1191
1218
|
$: {
|
|
1192
1219
|
void $sortCriteria;
|
|
1193
1220
|
void $sortDirection;
|
|
1194
1221
|
if (filter && currentFolderContent?.children) {
|
|
1195
1222
|
filteredFiles = currentFolderContent.children.filter((item: FileSystemItem) => {
|
|
1196
|
-
if (item.type === 'folder')
|
|
1197
|
-
return true;
|
|
1198
|
-
}
|
|
1223
|
+
if (item.type === 'folder') return true;
|
|
1199
1224
|
return fileMatchesFilter(item);
|
|
1200
1225
|
});
|
|
1201
1226
|
} else {
|
|
@@ -1230,7 +1255,12 @@
|
|
|
1230
1255
|
|
|
1231
1256
|
// `$validSelections` is a store that changes whenever a selection does, so both lists follow every click, in every folder.
|
|
1232
1257
|
$: allSelectedFiles = $fileStore?.root && filter ? $validSelections(filter, getAllFiles($fileStore.root)) : [];
|
|
1233
|
-
|
|
1258
|
+
// Grid tiles and recent cards share one selection store; recent rows use the same ids as grid files when both lists show the file.
|
|
1259
|
+
$: selectionViewFiles =
|
|
1260
|
+
!isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0
|
|
1261
|
+
? [...sortedFilteredFiles, ...recentFiles]
|
|
1262
|
+
: sortedFilteredFiles;
|
|
1263
|
+
$: currentSelections = $fileStore?.root && filter ? $validSelections(filter, selectionViewFiles) : [];
|
|
1234
1264
|
|
|
1235
1265
|
function toggleFileSelection(file: FileSystemItem) {
|
|
1236
1266
|
if (!allowSelecting) return;
|
|
@@ -1340,10 +1370,11 @@
|
|
|
1340
1370
|
});
|
|
1341
1371
|
if(showLogs && showRecentFilesLogs) console.log('Files after type filtering:', typeFilteredFiles.length);
|
|
1342
1372
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1373
|
+
const result = buildDeduplicatedRecentFiles(
|
|
1374
|
+
typeFilteredFiles,
|
|
1375
|
+
(item) => getCorrectFileUrl(item),
|
|
1376
|
+
numberOfRecentFiles,
|
|
1377
|
+
);
|
|
1347
1378
|
|
|
1348
1379
|
if(showLogs && showRecentFilesLogs) console.log('Final recent files:', result.length);
|
|
1349
1380
|
return result;
|
|
@@ -1857,6 +1888,37 @@
|
|
|
1857
1888
|
handleNavigateBack();
|
|
1858
1889
|
}
|
|
1859
1890
|
|
|
1891
|
+
const clearableSelectionCount = allSelectedFiles.filter(
|
|
1892
|
+
(file) => !(maxSelections === 1 && activeFileId && file.id === activeFileId)
|
|
1893
|
+
).length;
|
|
1894
|
+
const innerEscapeHandlerOpen =
|
|
1895
|
+
filterDropdownOpen ||
|
|
1896
|
+
sortDropdownOpen ||
|
|
1897
|
+
showRenameDialog ||
|
|
1898
|
+
showNewFolderDialog ||
|
|
1899
|
+
showMoveDialog ||
|
|
1900
|
+
showDeleteConfirmation;
|
|
1901
|
+
const escapeAction = escapeSelectionAction({
|
|
1902
|
+
key: event.key,
|
|
1903
|
+
defaultPrevented: event.defaultPrevented,
|
|
1904
|
+
previewOpen: !!previewFile,
|
|
1905
|
+
designSystemModalOpen: $isModalOpen,
|
|
1906
|
+
inputFocused: !!isInputFocused(event),
|
|
1907
|
+
rubberBandDragActive,
|
|
1908
|
+
innerEscapeHandlerOpen,
|
|
1909
|
+
selectionCount: allSelectedFiles.length,
|
|
1910
|
+
clearableSelectionCount,
|
|
1911
|
+
singleFilePicker: maxSelections === 1,
|
|
1912
|
+
});
|
|
1913
|
+
if (escapeAction === 'clear-selection') {
|
|
1914
|
+
event.preventDefault();
|
|
1915
|
+
event.stopPropagation();
|
|
1916
|
+
persistentSelectStore.clearSelections(filter);
|
|
1917
|
+
selectedFiles.set([]);
|
|
1918
|
+
if (showLogs) console.log('FileBrowser: cleared selection via Escape');
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1860
1922
|
// rest of the key handlers
|
|
1861
1923
|
handleKeyboardShortcuts(event);
|
|
1862
1924
|
}
|
|
@@ -2233,6 +2295,39 @@
|
|
|
2233
2295
|
}));
|
|
2234
2296
|
}
|
|
2235
2297
|
|
|
2298
|
+
async function evictGoneUploads(uploadIds: string[]) {
|
|
2299
|
+
if (!uploadIds.length || libraryMode) return;
|
|
2300
|
+
const drop = new Set(uploadIds);
|
|
2301
|
+
await removePersistedUploads(uploadIds);
|
|
2302
|
+
fileStore.update((store) => ({ ...store, root: removeFiles(store.root, drop) }));
|
|
2303
|
+
selectedFiles.update((files) => files.filter((file) => !drop.has(file.id)));
|
|
2304
|
+
if (previewFile && drop.has(previewFile.id)) {
|
|
2305
|
+
previewFile = null;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
async function refreshUploadsFromApi() {
|
|
2310
|
+
if (libraryMode) return;
|
|
2311
|
+
const uploadConfig = getFileBrowserUploadConfig();
|
|
2312
|
+
if (!uploadConfig?.accessToken || !uploadConfig?.apiBasePath) return;
|
|
2313
|
+
try {
|
|
2314
|
+
const cached = await loadUserUploads();
|
|
2315
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
2316
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2317
|
+
});
|
|
2318
|
+
const merged = mergeRemoteUploadList(cached, remoteFiles, {
|
|
2319
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2320
|
+
apiHydrationSucceeded: true,
|
|
2321
|
+
});
|
|
2322
|
+
await replacePersistedUploads(merged);
|
|
2323
|
+
const root = await createUserUploadsFileSystemRoot(merged, $t('library.defaultLabel'));
|
|
2324
|
+
data = root;
|
|
2325
|
+
init();
|
|
2326
|
+
} catch (refreshError) {
|
|
2327
|
+
console.warn('[FileBrowser] Upload list refresh failed:', refreshError);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2236
2331
|
function handleFileBrowserCommand(event: Event) {
|
|
2237
2332
|
const detail = (event as CustomEvent).detail;
|
|
2238
2333
|
if (!detail || detail.instanceId !== instanceId) return;
|
|
@@ -2242,6 +2337,10 @@
|
|
|
2242
2337
|
navigateToBreadcrumb({ detail: detail.index } as CustomEvent<number>);
|
|
2243
2338
|
} else if (detail.command === 'publish') {
|
|
2244
2339
|
publishFileBrowserNav();
|
|
2340
|
+
} else if (detail.command === 'remove-upload' && typeof detail.uploadId === 'string') {
|
|
2341
|
+
void evictGoneUploads([detail.uploadId]);
|
|
2342
|
+
} else if (detail.command === 'refresh-uploads') {
|
|
2343
|
+
void refreshUploadsFromApi();
|
|
2245
2344
|
}
|
|
2246
2345
|
}
|
|
2247
2346
|
|
|
@@ -2322,7 +2421,7 @@
|
|
|
2322
2421
|
navigationStore.reset();
|
|
2323
2422
|
|
|
2324
2423
|
// Clear localStorage navigation history
|
|
2325
|
-
if (
|
|
2424
|
+
if (shouldPersistFolderInStorage) {
|
|
2326
2425
|
try {
|
|
2327
2426
|
removeFromStorage(instanceId);
|
|
2328
2427
|
if(showLogs) console.log('Cleared navigation history from localStorage');
|
|
@@ -2692,7 +2791,7 @@
|
|
|
2692
2791
|
// Update the navigation history clearing code
|
|
2693
2792
|
function clearNavigationHistory() {
|
|
2694
2793
|
// Clear localStorage navigation history
|
|
2695
|
-
if (
|
|
2794
|
+
if (shouldPersistFolderInStorage) {
|
|
2696
2795
|
try {
|
|
2697
2796
|
removeFromStorage(instanceId);
|
|
2698
2797
|
if(showLogs) console.log('Cleared navigation history from localStorage');
|
|
@@ -2715,21 +2814,7 @@
|
|
|
2715
2814
|
|
|
2716
2815
|
// Update numberOfRecentFiles based on screen width
|
|
2717
2816
|
function updateNumberOfRecentFiles() {
|
|
2718
|
-
|
|
2719
|
-
// For large desktop screens, show more files
|
|
2720
|
-
const availableWidth = mainContainerWidth;
|
|
2721
|
-
// Calculate how many columns would fit nicely
|
|
2722
|
-
const gridColumns = Math.min(6, Math.floor(availableWidth / 300));
|
|
2723
|
-
// Set max files to fill at least one row
|
|
2724
|
-
numberOfRecentFiles = gridColumns * 2; // Two rows of content
|
|
2725
|
-
} else if (mainContainerWidth > tabletBreakpoint) {
|
|
2726
|
-
// Standard desktop
|
|
2727
|
-
numberOfRecentFiles = 6; // Two rows of 3
|
|
2728
|
-
} else {
|
|
2729
|
-
// Tablet and below
|
|
2730
|
-
numberOfRecentFiles = 4; // Two rows of 2
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2817
|
+
numberOfRecentFiles = recentFilesLimitForWidth(mainContainerWidth);
|
|
2733
2818
|
if(showLogs && showRecentFilesLogs) console.log('Updated number of recent files:', numberOfRecentFiles);
|
|
2734
2819
|
}
|
|
2735
2820
|
|
|
@@ -2819,10 +2904,10 @@ mainGridClass="app-main-grid"
|
|
|
2819
2904
|
/>
|
|
2820
2905
|
</div>
|
|
2821
2906
|
|
|
2822
|
-
{#if
|
|
2907
|
+
{#if controlsShowFilters || controlsShowSorting}
|
|
2823
2908
|
<div class="controls-container flex min-w-0 max-w-full items-center gap-2 overflow-x-auto">
|
|
2824
2909
|
|
|
2825
|
-
{#if
|
|
2910
|
+
{#if controlsShowFilters}
|
|
2826
2911
|
<div class="filter-controls-container relative z-10 flex items-center">
|
|
2827
2912
|
{#key filterMenuKey}
|
|
2828
2913
|
<DropdownMenu.Root onOpenChange={setFilterMenuOpen}>
|
|
@@ -2858,7 +2943,7 @@ mainGridClass="app-main-grid"
|
|
|
2858
2943
|
</div>
|
|
2859
2944
|
{/if}
|
|
2860
2945
|
|
|
2861
|
-
{#if
|
|
2946
|
+
{#if controlsShowSorting}
|
|
2862
2947
|
<div class="sort-controls-container flex items-center gap-2">
|
|
2863
2948
|
{#key sortMenuKey}
|
|
2864
2949
|
<DropdownMenu.Root onOpenChange={setSortMenuOpen}>
|
|
@@ -2979,13 +3064,18 @@ mainGridClass="app-main-grid"
|
|
|
2979
3064
|
{:else}
|
|
2980
3065
|
<!-- Main content container with Files Inside --> <!-- {!showAddToEditor ? 'overflow-y-auto px-6' : ''} -->
|
|
2981
3066
|
<WScrollArea class="scroll-area-container min-h-0 min-w-0 flex-1" bind:element={scrollContainer} type="always">
|
|
3067
|
+
<div
|
|
3068
|
+
class="fb-scroll-content relative w-full min-w-full self-stretch"
|
|
3069
|
+
style={emptyViewMinHeightStyle}
|
|
3070
|
+
>
|
|
2982
3071
|
<!-- The padding is the same on both sides (Figma 24): the scrollbar sits in the end gutter, not on the tiles. -->
|
|
2983
|
-
<div class="main-content-container flex min-w-0 flex-col pb-6 {contentPaddingClass}"
|
|
3072
|
+
<div class="main-content-container relative flex w-full min-w-0 flex-col pb-6 {contentPaddingClass}" bind:this={contentContainer}>
|
|
2984
3073
|
|
|
2985
3074
|
<!-- Drag Select for selecting files -->
|
|
2986
3075
|
{#if allowSelecting}
|
|
2987
3076
|
<DragSelect
|
|
2988
3077
|
container={contentContainer}
|
|
3078
|
+
bind:dragBandActive={rubberBandDragActive}
|
|
2989
3079
|
enabled={allowSelecting && !$isModalOpen && maxSelections !== 1}
|
|
2990
3080
|
items={[...sortedFilteredFiles, ...recentFiles]}
|
|
2991
3081
|
{scrollContainer}
|
|
@@ -3033,7 +3123,7 @@ mainGridClass="app-main-grid"
|
|
|
3033
3123
|
<!-- Item content -->
|
|
3034
3124
|
<div
|
|
3035
3125
|
data-item-id={item.id}
|
|
3036
|
-
class="item-container"
|
|
3126
|
+
class="item-container group/file-tile"
|
|
3037
3127
|
data-selected={allowSelecting && currentSelections.some(f => f.id === item.id) ? 'true' : undefined}
|
|
3038
3128
|
>
|
|
3039
3129
|
{#if item.type === 'new-folder'}
|
|
@@ -3061,17 +3151,11 @@ mainGridClass="app-main-grid"
|
|
|
3061
3151
|
</div>
|
|
3062
3152
|
</VirtualList>
|
|
3063
3153
|
|
|
3064
|
-
{#if hasNoMatchingFiles}
|
|
3065
|
-
<!-- The folders stay on the page when a filter matches no file: the message is centred in the room under them -->
|
|
3066
|
-
<div class="no-matching-files-container flex min-h-0 w-full flex-1 items-center justify-center">
|
|
3067
|
-
<EmptyState message={emptyViewMessage} icon={emptyViewIcon} showActions={false} height="auto" />
|
|
3068
|
-
</div>
|
|
3069
|
-
{/if}
|
|
3070
|
-
|
|
3071
3154
|
<!-- Recent Files (a media library is one flat list, so they would only repeat the grid) -->
|
|
3072
|
-
{#if !libraryMode && currentPath.length === 0 && recentFiles.length > 0 && mainContainerWidth > tabletBreakpoint}
|
|
3155
|
+
{#if !libraryMode && !isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0 && mainContainerWidth > tabletBreakpoint}
|
|
3073
3156
|
<RecentFiles class="recent-files-container"
|
|
3074
|
-
{recentFiles}
|
|
3157
|
+
{recentFiles}
|
|
3158
|
+
visibleLimit={numberOfRecentFiles}
|
|
3075
3159
|
selectedFiles={allSelectedFiles}
|
|
3076
3160
|
currentFilter={filter}
|
|
3077
3161
|
{allowSelecting}
|
|
@@ -3083,10 +3167,8 @@ mainGridClass="app-main-grid"
|
|
|
3083
3167
|
{/if}
|
|
3084
3168
|
|
|
3085
3169
|
{:else}
|
|
3086
|
-
<!-- Empty view (Figma "Files / Empty folder" and "Empty library"): the "New folder" tile
|
|
3087
|
-
<div class="empty-content-container flex min-h-0 w-full flex-
|
|
3088
|
-
|
|
3089
|
-
<!-- New Folder Button -->
|
|
3170
|
+
<!-- Empty view (Figma "Files / Empty folder" and "Empty library"): the "New folder" tile only; the message is in the viewport overlay below -->
|
|
3171
|
+
<div class="empty-content-container flex min-h-0 w-full flex-col gap-3">
|
|
3090
3172
|
{#if libraryCapabilities.folders}
|
|
3091
3173
|
<div
|
|
3092
3174
|
class="grid w-full"
|
|
@@ -3095,14 +3177,25 @@ mainGridClass="app-main-grid"
|
|
|
3095
3177
|
<NewFolderButton on:click={handleNewFolderClick} />
|
|
3096
3178
|
</div>
|
|
3097
3179
|
{/if}
|
|
3098
|
-
|
|
3099
|
-
<!-- Empty State Container -->
|
|
3100
|
-
<div class="empty-state-wrapper flex min-h-0 w-full flex-1 items-center justify-center">
|
|
3101
|
-
<EmptyState message={emptyViewMessage} icon={emptyViewIcon} showActions={false} height="auto" />
|
|
3102
|
-
</div>
|
|
3103
3180
|
</div>
|
|
3104
3181
|
{/if}
|
|
3105
3182
|
</div> <!-- END OF MAIN CONTENT CONTAINER -->
|
|
3183
|
+
|
|
3184
|
+
{#if showEmptyTypeOverlay}
|
|
3185
|
+
<div
|
|
3186
|
+
class="empty-type-overlay pointer-events-none absolute inset-0 z-[2] flex items-center justify-center"
|
|
3187
|
+
style:height={emptyOverlayViewportHeight}
|
|
3188
|
+
>
|
|
3189
|
+
<EmptyState
|
|
3190
|
+
class="pointer-events-auto"
|
|
3191
|
+
message={emptyViewMessage}
|
|
3192
|
+
icon={emptyViewIcon}
|
|
3193
|
+
showActions={false}
|
|
3194
|
+
height="auto"
|
|
3195
|
+
/>
|
|
3196
|
+
</div>
|
|
3197
|
+
{/if}
|
|
3198
|
+
</div> <!-- fb-scroll-content: full viewport width for the empty overlay -->
|
|
3106
3199
|
</WScrollArea>
|
|
3107
3200
|
|
|
3108
3201
|
{/if}
|
|
@@ -3183,11 +3276,13 @@ mainGridClass="app-main-grid"
|
|
|
3183
3276
|
file={previewFile}
|
|
3184
3277
|
on:close={closePreview}
|
|
3185
3278
|
{allowSelecting}
|
|
3279
|
+
{showAddToEditor}
|
|
3186
3280
|
currentFilter={filter}
|
|
3187
3281
|
currentFiles={previewSource === 'recent' ? recentFiles : currentViewFiles}
|
|
3188
3282
|
target={rootContainerClass}
|
|
3189
3283
|
on:select={(event : any) => handleFileSelect(event.detail)}
|
|
3190
3284
|
on:navigate={handlePreviewNavigate}
|
|
3285
|
+
on:fileUnavailable={(event) => void evictGoneUploads([event.detail.id])}
|
|
3191
3286
|
/>
|
|
3192
3287
|
{/if}
|
|
3193
3288
|
|
|
@@ -44,7 +44,11 @@ declare const FileBrowser: $$__sveltets_2_IsomorphicComponent<{
|
|
|
44
44
|
initialFilter?: FileFilterType;
|
|
45
45
|
initialSortCriteria?: "name" | "date" | "size";
|
|
46
46
|
instanceId?: string;
|
|
47
|
-
persistHistory?: boolean;
|
|
47
|
+
/** Persists folder path, filter, and sort in localStorage (full-page browsers). Off in library mode. */ persistHistory?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Persists only the folder path in localStorage (single-file pickers). Does not save filter or sort — the control
|
|
50
|
+
* fixes the file type. Use with `persistHistory={false}` on a dedicated `instanceId`.
|
|
51
|
+
*/ rememberFolder?: boolean;
|
|
48
52
|
showBreadcrumbs?: boolean;
|
|
49
53
|
allowSelecting?: boolean;
|
|
50
54
|
maxSelections?: number | null;
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
import type { ThroughputSample } from '../../utils/uploadProgressMath';
|
|
40
40
|
import { overallBytesProgressRatio, ratioToPercent, UPLOAD_UI_PROGRESS_THROTTLE_MS } from '../../utils/uploadProgressMath';
|
|
41
41
|
import { buildActiveRowStatusText, formatUploadPercent, type UploadPhase, updateThroughputEstimateState } from '../../utils/uploadUiHelpers';
|
|
42
|
+
import { monotonicDisplayProgress } from '../../utils/uploadDisplayProgress';
|
|
43
|
+
import { monotonicPanelProgress, nextUploadPanelPeak } from '../../utils/uploadPanelProgress';
|
|
42
44
|
|
|
43
45
|
// The host's media library, when the File Browser was given one. It then stores the files, instead of the
|
|
44
46
|
// Widgetic upload settings.
|
|
@@ -100,6 +102,8 @@
|
|
|
100
102
|
|
|
101
103
|
let uploadItems: UploadItem[] = [];
|
|
102
104
|
let uploadInProgress = false;
|
|
105
|
+
/** Highest panel bar reading this open session has shown (prevents 100→0→100 flicker). */
|
|
106
|
+
let uploadPanelPeakProgress = 0;
|
|
103
107
|
|
|
104
108
|
// Reactive variables
|
|
105
109
|
$: allowedKinds = allowedKindsOf(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
|
|
@@ -125,7 +129,6 @@
|
|
|
125
129
|
includeComplete: true,
|
|
126
130
|
}),
|
|
127
131
|
);
|
|
128
|
-
|
|
129
132
|
$: dropzoneState = (
|
|
130
133
|
dragActive && dragInvalid
|
|
131
134
|
? 'drag-invalid'
|
|
@@ -184,7 +187,7 @@
|
|
|
184
187
|
fileName: item.file.name,
|
|
185
188
|
file: fileThumbForItem(item),
|
|
186
189
|
progress: item.displayProgress,
|
|
187
|
-
progressIndeterminate:
|
|
190
|
+
progressIndeterminate: false,
|
|
188
191
|
status: item.status,
|
|
189
192
|
statusText: statusTextForItem(item),
|
|
190
193
|
errorMessage: item.errorMessage,
|
|
@@ -224,9 +227,18 @@
|
|
|
224
227
|
|
|
225
228
|
$: panelProgressTone = (failedUploadCount > 0 ? 'destructive' : 'default') as 'default' | 'destructive';
|
|
226
229
|
$: panelProgressDone = completedUploadCount === totalUploadCount && failedUploadCount === 0;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
+
/** Finishing after 100% bytes still shows a full bar (not the empty indeterminate strip). */
|
|
231
|
+
$: panelProgressIndeterminate = false;
|
|
232
|
+
$: if (!isUploadsModalOpen) {
|
|
233
|
+
uploadPanelPeakProgress = 0;
|
|
234
|
+
} else if (overallProgress >= uploadPanelPeakProgress) {
|
|
235
|
+
uploadPanelPeakProgress = nextUploadPanelPeak(uploadPanelPeakProgress, overallProgress);
|
|
236
|
+
}
|
|
237
|
+
$: panelBarProgress = monotonicPanelProgress(
|
|
238
|
+
uploadPanelPeakProgress,
|
|
239
|
+
overallProgress,
|
|
240
|
+
panelProgressDone,
|
|
241
|
+
);
|
|
230
242
|
|
|
231
243
|
$: panelFooterDestructive = failedUploadCount > 0;
|
|
232
244
|
$: panelFooterAction =
|
|
@@ -484,10 +496,11 @@
|
|
|
484
496
|
args.phase === 'finishing' ||
|
|
485
497
|
args.rawPercent >= 100;
|
|
486
498
|
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
499
|
+
const previousProgress = item.displayProgress;
|
|
500
|
+
const displayProgress = monotonicDisplayProgress(
|
|
501
|
+
previousProgress,
|
|
502
|
+
args.phase === 'finishing' ? 100 : args.rawPercent,
|
|
503
|
+
);
|
|
491
504
|
|
|
492
505
|
uploadItems = uploadItems.map((it) =>
|
|
493
506
|
it.id === uploadId
|
|
@@ -636,7 +649,10 @@
|
|
|
636
649
|
if (it.id !== uploadId) return it;
|
|
637
650
|
const lastTick = it.lastUiTick ?? 0;
|
|
638
651
|
const shouldPaint = now - lastTick >= UPLOAD_UI_PROGRESS_THROTTLE_MS || percentage >= 100;
|
|
639
|
-
const displayProgress =
|
|
652
|
+
const displayProgress = monotonicDisplayProgress(
|
|
653
|
+
it.displayProgress,
|
|
654
|
+
percentage >= 100 ? 100 : percentage,
|
|
655
|
+
);
|
|
640
656
|
return {
|
|
641
657
|
...it,
|
|
642
658
|
uploadPhase: percentage >= 100 ? 'finishing' : 'uploading',
|
|
@@ -688,10 +704,10 @@
|
|
|
688
704
|
const lastTick = it.lastUiTick ?? 0;
|
|
689
705
|
const shouldPaint =
|
|
690
706
|
now - lastTick >= UPLOAD_UI_PROGRESS_THROTTLE_MS || percentage >= 100;
|
|
691
|
-
const displayProgress =
|
|
707
|
+
const displayProgress = monotonicDisplayProgress(it.displayProgress, percentage);
|
|
692
708
|
return {
|
|
693
709
|
...it,
|
|
694
|
-
uploadPhase: 'uploading',
|
|
710
|
+
uploadPhase: percentage >= 100 ? 'finishing' : 'uploading',
|
|
695
711
|
bytesUploaded: loaded,
|
|
696
712
|
bytesTotal: total,
|
|
697
713
|
timeRemainingSeconds: est.secondsLeft,
|
|
@@ -759,7 +775,9 @@
|
|
|
759
775
|
lastThroughputSample: est.nextSample,
|
|
760
776
|
throughputBps: est.throughputBps,
|
|
761
777
|
firstThroughputSampleAt: est.firstSampleAt,
|
|
762
|
-
...(shouldPaint
|
|
778
|
+
...(shouldPaint
|
|
779
|
+
? { displayProgress: monotonicDisplayProgress(it.displayProgress, newPercent), lastUiTick: now }
|
|
780
|
+
: {}),
|
|
763
781
|
};
|
|
764
782
|
});
|
|
765
783
|
}, 500);
|
|
@@ -947,6 +965,19 @@
|
|
|
947
965
|
throw new Error('No file provided');
|
|
948
966
|
}
|
|
949
967
|
|
|
968
|
+
let imageWidth: number | undefined;
|
|
969
|
+
let imageHeight: number | undefined;
|
|
970
|
+
if (uploadedFile.type.startsWith('image/') && typeof createImageBitmap === 'function') {
|
|
971
|
+
try {
|
|
972
|
+
const bitmap = await createImageBitmap(uploadedFile);
|
|
973
|
+
imageWidth = bitmap.width;
|
|
974
|
+
imageHeight = bitmap.height;
|
|
975
|
+
bitmap.close();
|
|
976
|
+
} catch (dimensionError) {
|
|
977
|
+
console.warn('[FileUploader] Could not read image dimensions for mock upload:', dimensionError);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
950
981
|
// Create an object URL for the file
|
|
951
982
|
const objectUrl = URL.createObjectURL(uploadedFile);
|
|
952
983
|
|
|
@@ -971,6 +1002,9 @@
|
|
|
971
1002
|
modified: new Date().toISOString(),
|
|
972
1003
|
url: objectUrl,
|
|
973
1004
|
thumbnail: thumbnailUrl || undefined,
|
|
1005
|
+
mimeType: uploadedFile.type || undefined,
|
|
1006
|
+
width: imageWidth,
|
|
1007
|
+
height: imageHeight,
|
|
974
1008
|
objectUrl, // Store the object URL for cleanup
|
|
975
1009
|
path,
|
|
976
1010
|
folderId
|
|
@@ -1122,14 +1156,14 @@
|
|
|
1122
1156
|
>
|
|
1123
1157
|
{#if isUploadsModalOpen && uploadItems.length > 0}
|
|
1124
1158
|
<!-- Figma: upload status cards sit above the drop strip, inside the modal footer. -->
|
|
1125
|
-
<div class="uploads-panel-anchor flex w-full min-w-0
|
|
1159
|
+
<div class="uploads-panel-anchor flex w-full min-w-0 flex-col items-stretch">
|
|
1126
1160
|
<UploadPanel
|
|
1127
1161
|
items={panelItems}
|
|
1128
1162
|
summaryScope={panelSummaryScope as UploadRowScope}
|
|
1129
1163
|
summaryState={panelSummaryState as UploadRowState}
|
|
1130
1164
|
summaryName={panelSummaryName}
|
|
1131
1165
|
summaryStatus={panelSummaryStatus}
|
|
1132
|
-
progressValue={
|
|
1166
|
+
progressValue={panelBarProgress}
|
|
1133
1167
|
progressIndeterminate={panelProgressIndeterminate}
|
|
1134
1168
|
progressTone={panelProgressTone}
|
|
1135
1169
|
progressDone={panelProgressDone}
|