@widgetic/file-browser 0.5.40 → 0.5.41
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 +108 -55
- 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 +198 -31
- package/dist/components/previews/FilePreview.svelte.d.ts +1 -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/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/uploadPanelProgress.d.ts +5 -0
- package/dist/utils/uploadPanelProgress.js +17 -0
- package/package.json +1 -1
- package/dist/components/modals/SearchModal.svelte +0 -296
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
import { fetchUserUploadsFromApi } from '../../utils/widgeticUpload';
|
|
77
77
|
import { get, writable } from 'svelte/store';
|
|
78
78
|
import { resolveFileItemUrl } from '../../utils/resolveFileUrl';
|
|
79
|
+
import { buildDeduplicatedRecentFiles } from '../../utils/recentFiles';
|
|
79
80
|
import { dev } from '$app/environment';
|
|
80
81
|
import demoContentData from '../../data/demoContent.json';
|
|
81
82
|
// import { showToast } from '../../utils/toastUtils';
|
|
@@ -102,7 +103,8 @@
|
|
|
102
103
|
createCanGoBackStore,
|
|
103
104
|
createCanGoForwardStore,
|
|
104
105
|
getStorageKey,
|
|
105
|
-
getStoredState
|
|
106
|
+
getStoredState,
|
|
107
|
+
setPersistFolderPath
|
|
106
108
|
} from '../../stores/navigationStore';
|
|
107
109
|
//
|
|
108
110
|
import { persistentSelectStore, validSelections } from '../../stores/persistentSelectStore';
|
|
@@ -117,6 +119,8 @@
|
|
|
117
119
|
import { appendNewFiles, createLibraryRoot, removeFiles, replaceFile, upsertFile } from '../../mediaLibrary/treeOps';
|
|
118
120
|
import type { MediaLibraryErrorCode, MediaLibraryProvider } from '../../mediaLibrary/types';
|
|
119
121
|
import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
|
|
122
|
+
import { escapeSelectionAction } from '../../utils/escapeSelectionAction';
|
|
123
|
+
import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
|
|
120
124
|
|
|
121
125
|
// I18N IMPORTS (the words of the File Browser, in the page's language)
|
|
122
126
|
import { provideI18n } from '../../i18n/context';
|
|
@@ -173,11 +177,23 @@
|
|
|
173
177
|
export let initialSortCriteria: 'name' | 'date' | 'size' = 'name'; // Default to date
|
|
174
178
|
// navigation settings
|
|
175
179
|
export let instanceId: string = 'default'; // Unique identifier for this file browser instance
|
|
176
|
-
|
|
180
|
+
/** Persists folder path, filter, and sort in localStorage (full-page browsers). Off in library mode. */
|
|
181
|
+
export let persistHistory = true;
|
|
182
|
+
/**
|
|
183
|
+
* Persists only the folder path in localStorage (single-file pickers). Does not save filter or sort — the control
|
|
184
|
+
* fixes the file type. Use with `persistHistory={false}` on a dedicated `instanceId`.
|
|
185
|
+
*/
|
|
186
|
+
export let rememberFolder = false;
|
|
177
187
|
export let showBreadcrumbs = true; // Whether to show breadcrumbs
|
|
178
188
|
// selection settings
|
|
179
189
|
export let allowSelecting = true; // Toggle file selection functionality by default
|
|
180
190
|
export let maxSelections: number | null = null; // null = unlimited; 1 = single-file picker
|
|
191
|
+
/** Single-file pickers (selectors) hide sort controls and keep the default name order. */
|
|
192
|
+
$: isSingleFilePicker = maxSelections === 1;
|
|
193
|
+
$: controlsShowSorting = showSorting && !isSingleFilePicker;
|
|
194
|
+
/** Fixed-type selectors never show the type filter, even if a host passes `showFilters={true}`. */
|
|
195
|
+
$: controlsShowFilters = showFilters && !(isSingleFilePicker && initialFilter !== 'all');
|
|
196
|
+
let rubberBandDragActive = false;
|
|
181
197
|
/** When set (single-file picker), disables confirm until user picks a different file. */
|
|
182
198
|
export let activeFileId: string | null = null;
|
|
183
199
|
export let showAddToEditor = false; // Toggle visibility of "Add to Editor" functionality
|
|
@@ -319,7 +335,7 @@
|
|
|
319
335
|
|
|
320
336
|
// Initialize filter with a function to check localStorage first
|
|
321
337
|
let filter: FileFilterType = (() => {
|
|
322
|
-
if (persistHistory) {
|
|
338
|
+
if (persistHistory && maxSelections !== 1) {
|
|
323
339
|
try {
|
|
324
340
|
if (isBrowser) {
|
|
325
341
|
const storedFilter = getFromStorage(FILTER_STORAGE_KEY(instanceId), null);
|
|
@@ -513,6 +529,10 @@
|
|
|
513
529
|
// The text of the confirm button: the page's label, or the message of the language in use.
|
|
514
530
|
$: addToEditorText = addToEditorLabel ?? $t('action.addToEditor');
|
|
515
531
|
|
|
532
|
+
$: shouldPersistFolderInStorage =
|
|
533
|
+
!libraryMode && (rememberFolder || (persistHistory && maxSelections !== 1));
|
|
534
|
+
$: setPersistFolderPath(instanceId, shouldPersistFolderInStorage);
|
|
535
|
+
|
|
516
536
|
// A shared browser must not show the next visitor the previous one's picks, so a library turns this off unless the
|
|
517
537
|
// host asks for it. Selecting still works; the picks just live in memory.
|
|
518
538
|
const selectionIsKept = persistSelection ?? !libraryMode;
|
|
@@ -861,7 +881,7 @@
|
|
|
861
881
|
let pathToNavigate: string[] = [];
|
|
862
882
|
|
|
863
883
|
// Check if we have a stored path to restore (a media library has no folders to go back to)
|
|
864
|
-
if (
|
|
884
|
+
if (shouldPersistFolderInStorage) {
|
|
865
885
|
const storedState = getStoredState(instanceId);
|
|
866
886
|
if (storedState) {
|
|
867
887
|
pathToNavigate = storedState.pathsArray[storedState.currentIndex] || [];
|
|
@@ -885,7 +905,7 @@
|
|
|
885
905
|
const navStartTime = performance.now();
|
|
886
906
|
|
|
887
907
|
// if there is no stored path, reset navigation to root
|
|
888
|
-
if (!
|
|
908
|
+
if (!shouldPersistFolderInStorage || pathToNavigate.length === 0) {
|
|
889
909
|
// if(showLogs) console.log('FileBrowser onMount: No valid stored path, resetting navigation to root');
|
|
890
910
|
navigationStore.reset();
|
|
891
911
|
currentFolder.set([]);
|
|
@@ -1125,7 +1145,10 @@
|
|
|
1125
1145
|
(isEmpty || hasNoMatchingFiles) && scrollAreaHeight > 0
|
|
1126
1146
|
? `min-height: ${Math.max(0, scrollAreaHeight - 24)}px;`
|
|
1127
1147
|
: '';
|
|
1128
|
-
|
|
1148
|
+
// Centred in the scroll viewport, not in the flow below folder tiles (selector empty views must not jump).
|
|
1149
|
+
$: showEmptyTypeOverlay = !isLoading && (isEmpty || hasNoMatchingFiles);
|
|
1150
|
+
$: emptyOverlayViewportHeight =
|
|
1151
|
+
scrollAreaHeight > 0 ? `${Math.max(0, scrollAreaHeight - 24)}px` : undefined;
|
|
1129
1152
|
// What an empty view says, and with which icon: a type filter that matches nothing, an empty media library,
|
|
1130
1153
|
// or an empty folder (Figma "Files / No matching files", "Empty library" and "Empty folder").
|
|
1131
1154
|
$: emptyViewMessage =
|
|
@@ -1186,16 +1209,14 @@
|
|
|
1186
1209
|
|
|
1187
1210
|
/**
|
|
1188
1211
|
* Filters and sorts current folder contents based on active filter and sort criteria.
|
|
1189
|
-
* Folders are always
|
|
1212
|
+
* Folders are always listed; files must match the filter.
|
|
1190
1213
|
*/
|
|
1191
1214
|
$: {
|
|
1192
1215
|
void $sortCriteria;
|
|
1193
1216
|
void $sortDirection;
|
|
1194
1217
|
if (filter && currentFolderContent?.children) {
|
|
1195
1218
|
filteredFiles = currentFolderContent.children.filter((item: FileSystemItem) => {
|
|
1196
|
-
if (item.type === 'folder')
|
|
1197
|
-
return true;
|
|
1198
|
-
}
|
|
1219
|
+
if (item.type === 'folder') return true;
|
|
1199
1220
|
return fileMatchesFilter(item);
|
|
1200
1221
|
});
|
|
1201
1222
|
} else {
|
|
@@ -1230,7 +1251,12 @@
|
|
|
1230
1251
|
|
|
1231
1252
|
// `$validSelections` is a store that changes whenever a selection does, so both lists follow every click, in every folder.
|
|
1232
1253
|
$: allSelectedFiles = $fileStore?.root && filter ? $validSelections(filter, getAllFiles($fileStore.root)) : [];
|
|
1233
|
-
|
|
1254
|
+
// Grid tiles and recent cards share one selection store; recent rows use the same ids as grid files when both lists show the file.
|
|
1255
|
+
$: selectionViewFiles =
|
|
1256
|
+
!isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0
|
|
1257
|
+
? [...sortedFilteredFiles, ...recentFiles]
|
|
1258
|
+
: sortedFilteredFiles;
|
|
1259
|
+
$: currentSelections = $fileStore?.root && filter ? $validSelections(filter, selectionViewFiles) : [];
|
|
1234
1260
|
|
|
1235
1261
|
function toggleFileSelection(file: FileSystemItem) {
|
|
1236
1262
|
if (!allowSelecting) return;
|
|
@@ -1340,10 +1366,11 @@
|
|
|
1340
1366
|
});
|
|
1341
1367
|
if(showLogs && showRecentFilesLogs) console.log('Files after type filtering:', typeFilteredFiles.length);
|
|
1342
1368
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1369
|
+
const result = buildDeduplicatedRecentFiles(
|
|
1370
|
+
typeFilteredFiles,
|
|
1371
|
+
(item) => getCorrectFileUrl(item),
|
|
1372
|
+
numberOfRecentFiles,
|
|
1373
|
+
);
|
|
1347
1374
|
|
|
1348
1375
|
if(showLogs && showRecentFilesLogs) console.log('Final recent files:', result.length);
|
|
1349
1376
|
return result;
|
|
@@ -1857,6 +1884,37 @@
|
|
|
1857
1884
|
handleNavigateBack();
|
|
1858
1885
|
}
|
|
1859
1886
|
|
|
1887
|
+
const clearableSelectionCount = allSelectedFiles.filter(
|
|
1888
|
+
(file) => !(maxSelections === 1 && activeFileId && file.id === activeFileId)
|
|
1889
|
+
).length;
|
|
1890
|
+
const innerEscapeHandlerOpen =
|
|
1891
|
+
filterDropdownOpen ||
|
|
1892
|
+
sortDropdownOpen ||
|
|
1893
|
+
showRenameDialog ||
|
|
1894
|
+
showNewFolderDialog ||
|
|
1895
|
+
showMoveDialog ||
|
|
1896
|
+
showDeleteConfirmation;
|
|
1897
|
+
const escapeAction = escapeSelectionAction({
|
|
1898
|
+
key: event.key,
|
|
1899
|
+
defaultPrevented: event.defaultPrevented,
|
|
1900
|
+
previewOpen: !!previewFile,
|
|
1901
|
+
designSystemModalOpen: $isModalOpen,
|
|
1902
|
+
inputFocused: !!isInputFocused(event),
|
|
1903
|
+
rubberBandDragActive,
|
|
1904
|
+
innerEscapeHandlerOpen,
|
|
1905
|
+
selectionCount: allSelectedFiles.length,
|
|
1906
|
+
clearableSelectionCount,
|
|
1907
|
+
singleFilePicker: maxSelections === 1,
|
|
1908
|
+
});
|
|
1909
|
+
if (escapeAction === 'clear-selection') {
|
|
1910
|
+
event.preventDefault();
|
|
1911
|
+
event.stopPropagation();
|
|
1912
|
+
persistentSelectStore.clearSelections(filter);
|
|
1913
|
+
selectedFiles.set([]);
|
|
1914
|
+
if (showLogs) console.log('FileBrowser: cleared selection via Escape');
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1860
1918
|
// rest of the key handlers
|
|
1861
1919
|
handleKeyboardShortcuts(event);
|
|
1862
1920
|
}
|
|
@@ -2322,7 +2380,7 @@
|
|
|
2322
2380
|
navigationStore.reset();
|
|
2323
2381
|
|
|
2324
2382
|
// Clear localStorage navigation history
|
|
2325
|
-
if (
|
|
2383
|
+
if (shouldPersistFolderInStorage) {
|
|
2326
2384
|
try {
|
|
2327
2385
|
removeFromStorage(instanceId);
|
|
2328
2386
|
if(showLogs) console.log('Cleared navigation history from localStorage');
|
|
@@ -2692,7 +2750,7 @@
|
|
|
2692
2750
|
// Update the navigation history clearing code
|
|
2693
2751
|
function clearNavigationHistory() {
|
|
2694
2752
|
// Clear localStorage navigation history
|
|
2695
|
-
if (
|
|
2753
|
+
if (shouldPersistFolderInStorage) {
|
|
2696
2754
|
try {
|
|
2697
2755
|
removeFromStorage(instanceId);
|
|
2698
2756
|
if(showLogs) console.log('Cleared navigation history from localStorage');
|
|
@@ -2715,21 +2773,7 @@
|
|
|
2715
2773
|
|
|
2716
2774
|
// Update numberOfRecentFiles based on screen width
|
|
2717
2775
|
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
|
-
|
|
2776
|
+
numberOfRecentFiles = recentFilesLimitForWidth(mainContainerWidth);
|
|
2733
2777
|
if(showLogs && showRecentFilesLogs) console.log('Updated number of recent files:', numberOfRecentFiles);
|
|
2734
2778
|
}
|
|
2735
2779
|
|
|
@@ -2819,10 +2863,10 @@ mainGridClass="app-main-grid"
|
|
|
2819
2863
|
/>
|
|
2820
2864
|
</div>
|
|
2821
2865
|
|
|
2822
|
-
{#if
|
|
2866
|
+
{#if controlsShowFilters || controlsShowSorting}
|
|
2823
2867
|
<div class="controls-container flex min-w-0 max-w-full items-center gap-2 overflow-x-auto">
|
|
2824
2868
|
|
|
2825
|
-
{#if
|
|
2869
|
+
{#if controlsShowFilters}
|
|
2826
2870
|
<div class="filter-controls-container relative z-10 flex items-center">
|
|
2827
2871
|
{#key filterMenuKey}
|
|
2828
2872
|
<DropdownMenu.Root onOpenChange={setFilterMenuOpen}>
|
|
@@ -2858,7 +2902,7 @@ mainGridClass="app-main-grid"
|
|
|
2858
2902
|
</div>
|
|
2859
2903
|
{/if}
|
|
2860
2904
|
|
|
2861
|
-
{#if
|
|
2905
|
+
{#if controlsShowSorting}
|
|
2862
2906
|
<div class="sort-controls-container flex items-center gap-2">
|
|
2863
2907
|
{#key sortMenuKey}
|
|
2864
2908
|
<DropdownMenu.Root onOpenChange={setSortMenuOpen}>
|
|
@@ -2979,13 +3023,18 @@ mainGridClass="app-main-grid"
|
|
|
2979
3023
|
{:else}
|
|
2980
3024
|
<!-- Main content container with Files Inside --> <!-- {!showAddToEditor ? 'overflow-y-auto px-6' : ''} -->
|
|
2981
3025
|
<WScrollArea class="scroll-area-container min-h-0 min-w-0 flex-1" bind:element={scrollContainer} type="always">
|
|
3026
|
+
<div
|
|
3027
|
+
class="fb-scroll-content relative w-full min-w-full self-stretch"
|
|
3028
|
+
style={emptyViewMinHeightStyle}
|
|
3029
|
+
>
|
|
2982
3030
|
<!-- 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}"
|
|
3031
|
+
<div class="main-content-container relative flex w-full min-w-0 flex-col pb-6 {contentPaddingClass}" bind:this={contentContainer}>
|
|
2984
3032
|
|
|
2985
3033
|
<!-- Drag Select for selecting files -->
|
|
2986
3034
|
{#if allowSelecting}
|
|
2987
3035
|
<DragSelect
|
|
2988
3036
|
container={contentContainer}
|
|
3037
|
+
bind:dragBandActive={rubberBandDragActive}
|
|
2989
3038
|
enabled={allowSelecting && !$isModalOpen && maxSelections !== 1}
|
|
2990
3039
|
items={[...sortedFilteredFiles, ...recentFiles]}
|
|
2991
3040
|
{scrollContainer}
|
|
@@ -3033,7 +3082,7 @@ mainGridClass="app-main-grid"
|
|
|
3033
3082
|
<!-- Item content -->
|
|
3034
3083
|
<div
|
|
3035
3084
|
data-item-id={item.id}
|
|
3036
|
-
class="item-container"
|
|
3085
|
+
class="item-container group/file-tile"
|
|
3037
3086
|
data-selected={allowSelecting && currentSelections.some(f => f.id === item.id) ? 'true' : undefined}
|
|
3038
3087
|
>
|
|
3039
3088
|
{#if item.type === 'new-folder'}
|
|
@@ -3061,17 +3110,11 @@ mainGridClass="app-main-grid"
|
|
|
3061
3110
|
</div>
|
|
3062
3111
|
</VirtualList>
|
|
3063
3112
|
|
|
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
3113
|
<!-- 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}
|
|
3114
|
+
{#if !libraryMode && !isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0 && mainContainerWidth > tabletBreakpoint}
|
|
3073
3115
|
<RecentFiles class="recent-files-container"
|
|
3074
|
-
{recentFiles}
|
|
3116
|
+
{recentFiles}
|
|
3117
|
+
visibleLimit={numberOfRecentFiles}
|
|
3075
3118
|
selectedFiles={allSelectedFiles}
|
|
3076
3119
|
currentFilter={filter}
|
|
3077
3120
|
{allowSelecting}
|
|
@@ -3083,10 +3126,8 @@ mainGridClass="app-main-grid"
|
|
|
3083
3126
|
{/if}
|
|
3084
3127
|
|
|
3085
3128
|
{: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 -->
|
|
3129
|
+
<!-- Empty view (Figma "Files / Empty folder" and "Empty library"): the "New folder" tile only; the message is in the viewport overlay below -->
|
|
3130
|
+
<div class="empty-content-container flex min-h-0 w-full flex-col gap-3">
|
|
3090
3131
|
{#if libraryCapabilities.folders}
|
|
3091
3132
|
<div
|
|
3092
3133
|
class="grid w-full"
|
|
@@ -3095,14 +3136,25 @@ mainGridClass="app-main-grid"
|
|
|
3095
3136
|
<NewFolderButton on:click={handleNewFolderClick} />
|
|
3096
3137
|
</div>
|
|
3097
3138
|
{/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
3139
|
</div>
|
|
3104
3140
|
{/if}
|
|
3105
3141
|
</div> <!-- END OF MAIN CONTENT CONTAINER -->
|
|
3142
|
+
|
|
3143
|
+
{#if showEmptyTypeOverlay}
|
|
3144
|
+
<div
|
|
3145
|
+
class="empty-type-overlay pointer-events-none absolute inset-0 z-[2] flex items-center justify-center"
|
|
3146
|
+
style:height={emptyOverlayViewportHeight}
|
|
3147
|
+
>
|
|
3148
|
+
<EmptyState
|
|
3149
|
+
class="pointer-events-auto"
|
|
3150
|
+
message={emptyViewMessage}
|
|
3151
|
+
icon={emptyViewIcon}
|
|
3152
|
+
showActions={false}
|
|
3153
|
+
height="auto"
|
|
3154
|
+
/>
|
|
3155
|
+
</div>
|
|
3156
|
+
{/if}
|
|
3157
|
+
</div> <!-- fb-scroll-content: full viewport width for the empty overlay -->
|
|
3106
3158
|
</WScrollArea>
|
|
3107
3159
|
|
|
3108
3160
|
{/if}
|
|
@@ -3183,6 +3235,7 @@ mainGridClass="app-main-grid"
|
|
|
3183
3235
|
file={previewFile}
|
|
3184
3236
|
on:close={closePreview}
|
|
3185
3237
|
{allowSelecting}
|
|
3238
|
+
{showAddToEditor}
|
|
3186
3239
|
currentFilter={filter}
|
|
3187
3240
|
currentFiles={previewSource === 'recent' ? recentFiles : currentViewFiles}
|
|
3188
3241
|
target={rootContainerClass}
|
|
@@ -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}
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
import { useI18n, type Translate } from '../../i18n';
|
|
11
11
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
12
12
|
import { FileIcon, SelectedBadge } from '../ui';
|
|
13
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
13
14
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
14
15
|
import { ThumbHashImage } from '@widgetic/design-system/components';
|
|
15
16
|
import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
|
|
16
17
|
import { browser } from '$app/environment';
|
|
18
|
+
import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
|
|
17
19
|
|
|
18
20
|
let className = '';
|
|
19
21
|
export { className as class };
|
|
@@ -24,6 +26,8 @@
|
|
|
24
26
|
export let currentFilter: FileFilterType = 'all';
|
|
25
27
|
export let allowSelecting: boolean = false;
|
|
26
28
|
export let columnWidth: number = 40;
|
|
29
|
+
/** Cap from FileBrowser so the strip matches `getRecentFiles()`. */
|
|
30
|
+
export let visibleLimit: number | undefined = undefined;
|
|
27
31
|
|
|
28
32
|
const { t } = useI18n();
|
|
29
33
|
const textDirection = useTextDirection();
|
|
@@ -41,17 +45,19 @@
|
|
|
41
45
|
if (windowWidth > DESKTOP_BREAKPOINT) {
|
|
42
46
|
const availableWidth = windowWidth;
|
|
43
47
|
gridColumns = Math.min(6, Math.floor(availableWidth / 300));
|
|
44
|
-
maxRecentFiles = gridColumns * 2;
|
|
45
48
|
} else if (windowWidth > TABLET_BREAKPOINT) {
|
|
46
49
|
gridColumns = 3;
|
|
47
|
-
maxRecentFiles = 6;
|
|
48
50
|
} else {
|
|
49
51
|
gridColumns = 2;
|
|
50
|
-
maxRecentFiles = 4;
|
|
51
52
|
}
|
|
53
|
+
maxRecentFiles = visibleLimit ?? recentFilesLimitForWidth(windowWidth);
|
|
52
54
|
if (showLogs) console.log('Responsive layout updated:', { windowWidth, gridColumns, maxRecentFiles });
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
$: if (visibleLimit !== undefined) {
|
|
58
|
+
maxRecentFiles = visibleLimit;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
// Figma Recent cards sit 24px apart (the tiles above them 16)
|
|
56
62
|
$: gridGap = 24;
|
|
57
63
|
$: numberOfColumns = gridColumns;
|
|
@@ -148,8 +154,14 @@
|
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
|
|
157
|
+
// Same ids as the grid: follow the persistent store so both strips stay in sync after rubber-band or tile selection.
|
|
158
|
+
$: selectedIdSet = new Set([
|
|
159
|
+
...($persistentSelectStore[currentFilter] ?? []),
|
|
160
|
+
...selectedFiles.map((selectedFile) => selectedFile.id)
|
|
161
|
+
]);
|
|
162
|
+
|
|
151
163
|
function isSelected(file: FileSystemItem): boolean {
|
|
152
|
-
return
|
|
164
|
+
return selectedIdSet.has(file.id);
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
function getFormattedDate(date: string | Date, translate: Translate): string {
|
|
@@ -190,14 +202,13 @@
|
|
|
190
202
|
}
|
|
191
203
|
}
|
|
192
204
|
|
|
193
|
-
function cardShellClass(file: FileSystemItem): string {
|
|
194
|
-
const selected = isSelected(file);
|
|
205
|
+
function cardShellClass(file: FileSystemItem, selected: boolean): string {
|
|
195
206
|
const interactive = !file.isMissing && !errorStates.get(file.id);
|
|
196
207
|
return [
|
|
197
208
|
'item-container group flex w-full flex-col gap-2 rounded-xl border bg-background p-2 transition-colors duration-fast',
|
|
198
209
|
selected
|
|
199
|
-
? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand'
|
|
200
|
-
: 'border-border hover:bg-accent',
|
|
210
|
+
? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand data-[drag-hover=true]:bg-brand-subtle'
|
|
211
|
+
: 'border-border hover:bg-accent data-[drag-hover=true]:bg-accent',
|
|
201
212
|
interactive ? 'cursor-pointer' : ''
|
|
202
213
|
]
|
|
203
214
|
.filter(Boolean)
|
|
@@ -216,12 +227,13 @@
|
|
|
216
227
|
style="grid-template-columns: repeat({numberOfColumns}, minmax(0, 1fr)); gap: {gridGap}px;"
|
|
217
228
|
>
|
|
218
229
|
{#each filteredRecentFiles as file (file.id)}
|
|
230
|
+
{@const fileSelected = selectedIdSet.has(file.id)}
|
|
219
231
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
220
232
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
221
233
|
<div
|
|
222
234
|
data-item-id={file.id}
|
|
223
|
-
data-selected={
|
|
224
|
-
class={cardShellClass(file)}
|
|
235
|
+
data-selected={fileSelected ? 'true' : undefined}
|
|
236
|
+
class={cardShellClass(file, fileSelected)}
|
|
225
237
|
onclick={(e) => handleRecentCardClick(e, file)}
|
|
226
238
|
>
|
|
227
239
|
<button
|
|
@@ -292,7 +304,7 @@
|
|
|
292
304
|
{getFormattedDate(file.modified || new Date(), $t)}
|
|
293
305
|
</p>
|
|
294
306
|
</div>
|
|
295
|
-
{#if allowSelecting &&
|
|
307
|
+
{#if allowSelecting && fileSelected}
|
|
296
308
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
297
309
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
298
310
|
<span data-fb-recent-badge class="shrink-0" onclick={(e) => e.stopPropagation()}>
|
|
@@ -25,6 +25,7 @@ declare const RecentFiles: $$__sveltets_2_IsomorphicComponent<{
|
|
|
25
25
|
currentFilter?: FileFilterType;
|
|
26
26
|
allowSelecting?: boolean;
|
|
27
27
|
columnWidth?: number;
|
|
28
|
+
/** Cap from FileBrowser so the strip matches `getRecentFiles()`. */ visibleLimit?: number | undefined;
|
|
28
29
|
}, {
|
|
29
30
|
fileClick: CustomEvent<any>;
|
|
30
31
|
select: CustomEvent<any>;
|