@widgetic/file-browser 0.5.42 → 0.5.43
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/actions/dragSelectedToFolder.d.ts +41 -0
- package/dist/actions/dragSelectedToFolder.js +320 -0
- package/dist/components/core/FileBrowser.svelte +190 -29
- package/dist/components/core/Header.svelte +4 -0
- package/dist/components/core/Header.svelte.d.ts +2 -0
- package/dist/components/drag/DragGhostStack.svelte +69 -0
- package/dist/components/drag/DragGhostStack.svelte.d.ts +21 -0
- package/dist/components/items/FolderItem.svelte +5 -2
- package/dist/components/previews/FilePreview.svelte +59 -22
- package/dist/components/ui/DragSelect.svelte +8 -0
- package/dist/components/ui/DropdownMenu.svelte +9 -8
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/utils/dragToFolder/batchMoveResult.d.ts +18 -0
- package/dist/utils/dragToFolder/batchMoveResult.js +87 -0
- package/dist/utils/dragToFolder/folderDropTarget.d.ts +15 -0
- package/dist/utils/dragToFolder/folderDropTarget.js +71 -0
- package/dist/utils/dragToFolder/springStep.d.ts +16 -0
- package/dist/utils/dragToFolder/springStep.js +21 -0
- package/dist/utils/fileOperations.d.ts +5 -0
- package/dist/utils/fileOperations.js +72 -0
- package/dist/utils/imagePreviewFrame.d.ts +22 -0
- package/dist/utils/imagePreviewFrame.js +29 -0
- package/dist/utils/itemMenuCapabilities.d.ts +19 -0
- package/dist/utils/itemMenuCapabilities.js +13 -0
- package/dist/utils/libraryTree.d.ts +5 -2
- package/dist/utils/libraryTree.js +15 -35
- package/dist/utils/userUploadsStorage.js +4 -2
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import '@widgetic/design-system/styles';
|
|
22
22
|
|
|
23
23
|
// Design system components
|
|
24
|
-
import { Alert, Button, DebugGrid, WScrollArea, EmptyState, ErrorState, ActionModal, DropdownMenu, Tooltip, IconButton } from '@widgetic/design-system/components';
|
|
24
|
+
import { Alert, Button, DebugGrid, WScrollArea, EmptyState, ErrorState, ActionModal, DropdownMenu, Tooltip, IconButton, toast } from '@widgetic/design-system/components';
|
|
25
25
|
import {
|
|
26
26
|
IconCheck,
|
|
27
27
|
IconPhoto,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
import { gridColumnsForWidth } from '../../utils/gridLayout';
|
|
52
52
|
|
|
53
53
|
// TYPE IMPORTS
|
|
54
|
-
import type { FileSystemItem, FolderItemWithCount } from '../../types';
|
|
54
|
+
import type { FileSystemItem, FileSystemRoot, FolderItemWithCount } from '../../types';
|
|
55
55
|
|
|
56
56
|
// Define interface for navigate event detail
|
|
57
57
|
interface NavigateEventDetail {
|
|
@@ -110,7 +110,8 @@
|
|
|
110
110
|
setPersistFolderPath
|
|
111
111
|
} from '../../stores/navigationStore';
|
|
112
112
|
//
|
|
113
|
-
import { persistentSelectStore
|
|
113
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
114
|
+
import { missingFiles } from '../../stores/missingFilesStore';
|
|
114
115
|
import { isModalOpen, modalState } from '@widgetic/design-system/components/modals/modalStore';
|
|
115
116
|
|
|
116
117
|
// MEDIA LIBRARY IMPORTS (the host's own storage; see the `mediaLibrary` prop)
|
|
@@ -124,6 +125,13 @@
|
|
|
124
125
|
import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
|
|
125
126
|
import { escapeSelectionAction } from '../../utils/escapeSelectionAction';
|
|
126
127
|
import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
|
|
128
|
+
import DragGhostStack from '../drag/DragGhostStack.svelte';
|
|
129
|
+
import {
|
|
130
|
+
createDragSelectedToFolderController,
|
|
131
|
+
idleDragSnapshot,
|
|
132
|
+
type SelectedItemDragSnapshot
|
|
133
|
+
} from '../../actions/dragSelectedToFolder';
|
|
134
|
+
import { commitBatchMove } from '../../utils/dragToFolder/batchMoveResult';
|
|
127
135
|
|
|
128
136
|
// I18N IMPORTS (the words of the File Browser, in the page's language)
|
|
129
137
|
import { provideI18n } from '../../i18n/context';
|
|
@@ -197,6 +205,11 @@
|
|
|
197
205
|
/** Fixed-type selectors never show the type filter, even if a host passes `showFilters={true}`. */
|
|
198
206
|
$: controlsShowFilters = showFilters && !(isSingleFilePicker && initialFilter !== 'all');
|
|
199
207
|
let rubberBandDragActive = false;
|
|
208
|
+
let selectedDragSnapshot: SelectedItemDragSnapshot = idleDragSnapshot();
|
|
209
|
+
let selectedItemDragActive = false;
|
|
210
|
+
let selectedDragTeardown: (() => void) | null = null;
|
|
211
|
+
$: immediateParentIdForDrag =
|
|
212
|
+
currentPath.length > 0 ? currentPath[currentPath.length - 1] : null;
|
|
200
213
|
/** When set (single-file picker), disables confirm until user picks a different file. */
|
|
201
214
|
export let activeFileId: string | null = null;
|
|
202
215
|
export let showAddToEditor = false; // Toggle visibility of "Add to Editor" functionality
|
|
@@ -295,6 +308,32 @@
|
|
|
295
308
|
}
|
|
296
309
|
}
|
|
297
310
|
|
|
311
|
+
function broadcastFileBrowserCommand(command: string, extra: Record<string, unknown> = {}) {
|
|
312
|
+
if (!isBrowser) return;
|
|
313
|
+
window.dispatchEvent(
|
|
314
|
+
new CustomEvent('widgetic:file-browser-command', {
|
|
315
|
+
detail: { instanceId: '*', command, ...extra }
|
|
316
|
+
})
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function reloadDemoFromStorage() {
|
|
321
|
+
if (libraryMode || !useDemoContent) return;
|
|
322
|
+
const stored = getFromStorage(demoContentKey, null) as FileSystemRoot | null;
|
|
323
|
+
if (!stored?.root) return;
|
|
324
|
+
const payload = { ...stored, basePath: stored.basePath || basePath };
|
|
325
|
+
const dedupedData = deduplicateFileSystemItems(payload);
|
|
326
|
+
data = dedupedData;
|
|
327
|
+
fileStore.set(dedupedData);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function persistDemoContentTree() {
|
|
331
|
+
if (libraryMode || !useDemoContent) return;
|
|
332
|
+
const store = get(fileStore);
|
|
333
|
+
if (!store?.root) return;
|
|
334
|
+
saveToStorage(demoContentKey, { ...store, basePath: store.basePath ?? basePath });
|
|
335
|
+
}
|
|
336
|
+
|
|
298
337
|
function removeFromStorage(instanceId: string) {
|
|
299
338
|
const key = getStorageKey(instanceId);
|
|
300
339
|
|
|
@@ -792,7 +831,8 @@
|
|
|
792
831
|
// console.log('[FileBrowser] Widgetic library mode — user uploads only');
|
|
793
832
|
}
|
|
794
833
|
} else if (useDemoContent) {
|
|
795
|
-
|
|
834
|
+
const storedDemo = getFromStorage(demoContentKey, null) as FileSystemRoot | null;
|
|
835
|
+
data = storedDemo?.root ? storedDemo : demoContent;
|
|
796
836
|
if (!basePath.startsWith('http') && !dev) {
|
|
797
837
|
basePath = `/node_modules/@widgetic/file-browser/dist/static${basePath}`;
|
|
798
838
|
}
|
|
@@ -833,6 +873,10 @@
|
|
|
833
873
|
isLoading = false;
|
|
834
874
|
isVirtualListInitialized = true;
|
|
835
875
|
}
|
|
876
|
+
|
|
877
|
+
if (!libraryMode) {
|
|
878
|
+
void refreshUploadsFromApi();
|
|
879
|
+
}
|
|
836
880
|
});
|
|
837
881
|
|
|
838
882
|
function init() {
|
|
@@ -861,10 +905,9 @@
|
|
|
861
905
|
|
|
862
906
|
// save as demo content if not already saved (never for a media library: its files are not demo content, and
|
|
863
907
|
// the visitor's file list must not be copied into localStorage)
|
|
864
|
-
if(!libraryMode &&
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
908
|
+
if (!libraryMode && useDemoContent) {
|
|
909
|
+
persistDemoContentTree();
|
|
910
|
+
}
|
|
868
911
|
|
|
869
912
|
if(showLogs) console.log('FileBrowser: init data:', data);
|
|
870
913
|
|
|
@@ -947,6 +990,8 @@
|
|
|
947
990
|
window.removeEventListener('resize', handleResize);
|
|
948
991
|
window.removeEventListener('keydown', handleKeyDown);
|
|
949
992
|
window.removeEventListener('widgetic:file-browser-command', handleFileBrowserCommand);
|
|
993
|
+
selectedDragTeardown?.();
|
|
994
|
+
selectedDragTeardown = null;
|
|
950
995
|
});
|
|
951
996
|
|
|
952
997
|
// Add logging to key reactive statements
|
|
@@ -1253,14 +1298,24 @@
|
|
|
1253
1298
|
function handleFolderClick(folder: FolderItemWithCount) {
|
|
1254
1299
|
}
|
|
1255
1300
|
|
|
1256
|
-
//
|
|
1257
|
-
$:
|
|
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.
|
|
1301
|
+
// Subscribe to the persistent store directly so tile selection indicators update (Svelte 5 + derived fn pattern).
|
|
1302
|
+
$: selectedIdsForFilter = $persistentSelectStore[filter] ?? [];
|
|
1259
1303
|
$: selectionViewFiles =
|
|
1260
1304
|
!isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0
|
|
1261
1305
|
? [...sortedFilteredFiles, ...recentFiles]
|
|
1262
1306
|
: sortedFilteredFiles;
|
|
1263
|
-
$:
|
|
1307
|
+
$: allSelectedFiles =
|
|
1308
|
+
$fileStore?.root && filter
|
|
1309
|
+
? getAllFiles($fileStore.root).filter(
|
|
1310
|
+
(f) => selectedIdsForFilter.includes(f.id) && !$missingFiles.has(f.id)
|
|
1311
|
+
)
|
|
1312
|
+
: [];
|
|
1313
|
+
$: currentSelections =
|
|
1314
|
+
$fileStore?.root && filter
|
|
1315
|
+
? selectionViewFiles.filter(
|
|
1316
|
+
(f) => selectedIdsForFilter.includes(f.id) && !$missingFiles.has(f.id)
|
|
1317
|
+
)
|
|
1318
|
+
: [];
|
|
1264
1319
|
|
|
1265
1320
|
function toggleFileSelection(file: FileSystemItem) {
|
|
1266
1321
|
if (!allowSelecting) return;
|
|
@@ -1445,16 +1500,6 @@
|
|
|
1445
1500
|
const { action, item } = event.detail;
|
|
1446
1501
|
|
|
1447
1502
|
if (isFileSystemItem(item)) {
|
|
1448
|
-
// The built-in Uploads folder always stays at the root (the library is rebuilt around it on every load)
|
|
1449
|
-
if (
|
|
1450
|
-
item.id === 'folder_my_uploads' &&
|
|
1451
|
-
item.type === 'folder' &&
|
|
1452
|
-
(action === 'rename' || action === 'move' || action === 'delete')
|
|
1453
|
-
) {
|
|
1454
|
-
if (showLogs) console.log('[FileBrowser] Blocked action on built-in Uploads folder:', action);
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
1503
|
// Use allSelectedFiles instead of validSelectedFiles to get ALL selected files across ALL folders
|
|
1459
1504
|
const validSelectedFiles = allSelectedFiles;
|
|
1460
1505
|
// console.log('Current valid selections across all folders:', validSelectedFiles);
|
|
@@ -1676,6 +1721,8 @@
|
|
|
1676
1721
|
}
|
|
1677
1722
|
|
|
1678
1723
|
if (successCount > 0) {
|
|
1724
|
+
persistMyUploadsTree();
|
|
1725
|
+
|
|
1679
1726
|
// Show appropriate toast notification for successful deletions
|
|
1680
1727
|
let toastMessage = '';
|
|
1681
1728
|
let toastDescription = '';
|
|
@@ -1754,14 +1801,119 @@
|
|
|
1754
1801
|
// Saves the whole root of the Widgetic library (the built-in Uploads folder, the folders next to it and the files loose
|
|
1755
1802
|
// at the root), so an upload, a new folder, a rename or a move keeps its place after a reload.
|
|
1756
1803
|
function persistMyUploadsTree() {
|
|
1757
|
-
|
|
1758
|
-
if (
|
|
1804
|
+
if (libraryMode) return;
|
|
1805
|
+
if (useDemoContent) {
|
|
1806
|
+
persistDemoContentTree();
|
|
1807
|
+
broadcastFileBrowserCommand('reload-demo-tree');
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
if (!isWidgeticLibraryMode()) return;
|
|
1759
1811
|
const store = get(fileStore);
|
|
1760
1812
|
if (store.root?.children) {
|
|
1761
|
-
saveLibraryTreeChildren(store.root.children);
|
|
1813
|
+
void saveLibraryTreeChildren(store.root.children);
|
|
1814
|
+
broadcastFileBrowserCommand('refresh-uploads');
|
|
1762
1815
|
}
|
|
1763
1816
|
}
|
|
1764
1817
|
|
|
1818
|
+
function getSelectedFilesInCurrentFolder(): FileSystemItem[] {
|
|
1819
|
+
const inFolder = new Set(
|
|
1820
|
+
sortedFilteredFiles.filter((entry) => entry.type === 'file' || entry.type === 'folder').map((entry) => entry.id)
|
|
1821
|
+
);
|
|
1822
|
+
return allSelectedFiles.filter((file) => inFolder.has(file.id));
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
function prefersReducedMotion(): boolean {
|
|
1826
|
+
if (!isBrowser) return false;
|
|
1827
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
async function handleSelectedItemsDrop(targetFolderId: string, items: FileSystemItem[]) {
|
|
1831
|
+
for (const item of items) {
|
|
1832
|
+
const el = findItemElement(item.id);
|
|
1833
|
+
el?.setAttribute('data-drag-exit', 'true');
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
try {
|
|
1837
|
+
const result = await commitBatchMove({
|
|
1838
|
+
sourceItems: items,
|
|
1839
|
+
targetFolderId,
|
|
1840
|
+
localOnly: isWidgeticLibraryMode(),
|
|
1841
|
+
currentFilter: filter,
|
|
1842
|
+
navigationStoreId: instanceId
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
if (result.movedIds.length === 0) {
|
|
1846
|
+
throw new MediaLibraryError('FAILED', 'No items were moved successfully', {
|
|
1847
|
+
messageKey: 'moveDialog.noneMoved'
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
if (result.failedCount > 0) {
|
|
1852
|
+
toast.warning($t('moveDialog.partialTitle'), {
|
|
1853
|
+
description: $t('moveDialog.partialDetail', {
|
|
1854
|
+
moved: result.movedIds.length,
|
|
1855
|
+
total: items.length
|
|
1856
|
+
}),
|
|
1857
|
+
position: 'bottom-center',
|
|
1858
|
+
class: 'file-browser-sonar',
|
|
1859
|
+
duration: 2000
|
|
1860
|
+
});
|
|
1861
|
+
} else {
|
|
1862
|
+
toast.success(
|
|
1863
|
+
items.length === 1 ? $t('moveDialog.doneOne') : $t('moveDialog.doneMany'),
|
|
1864
|
+
{
|
|
1865
|
+
description: $t('moveDialog.doneItemsDetail', { count: result.movedIds.length }),
|
|
1866
|
+
position: 'bottom-center',
|
|
1867
|
+
class: 'file-browser-sonar',
|
|
1868
|
+
duration: 2000
|
|
1869
|
+
}
|
|
1870
|
+
);
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
selectedFiles.set([]);
|
|
1874
|
+
persistMyUploadsTree();
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
console.error('Drag move failed:', error);
|
|
1877
|
+
items.forEach((item) => findItemElement(item.id)?.removeAttribute('data-drag-exit'));
|
|
1878
|
+
toast.error($t('moveDialog.failedItems'), {
|
|
1879
|
+
description: messageForVisitor(error, $t),
|
|
1880
|
+
position: 'bottom-center',
|
|
1881
|
+
class: 'file-browser-sonar',
|
|
1882
|
+
duration: 2000
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
function attachSelectedDragController() {
|
|
1888
|
+
if (selectedDragTeardown || !contentContainer || !allowSelecting) return;
|
|
1889
|
+
const controller = createDragSelectedToFolderController({
|
|
1890
|
+
getContainer: () => contentContainer,
|
|
1891
|
+
getScrollContainer: () => scrollContainer,
|
|
1892
|
+
getSelectedInView: getSelectedFilesInCurrentFolder,
|
|
1893
|
+
getImmediateParentId: () => immediateParentIdForDrag,
|
|
1894
|
+
getRoot: () => $fileStore.root,
|
|
1895
|
+
isEnabled: () =>
|
|
1896
|
+
allowSelecting &&
|
|
1897
|
+
!$isModalOpen &&
|
|
1898
|
+
libraryCapabilities.folders &&
|
|
1899
|
+
!rubberBandDragActive,
|
|
1900
|
+
prefersReducedMotion,
|
|
1901
|
+
debugLog: showLogs,
|
|
1902
|
+
onSnapshot: (snap) => {
|
|
1903
|
+
selectedDragSnapshot = snap;
|
|
1904
|
+
selectedItemDragActive = snap.phase === 'dragging' || snap.phase === 'dropping';
|
|
1905
|
+
},
|
|
1906
|
+
onDrop: (targetFolderId, items) => {
|
|
1907
|
+
void handleSelectedItemsDrop(targetFolderId, items);
|
|
1908
|
+
}
|
|
1909
|
+
});
|
|
1910
|
+
selectedDragTeardown = () => controller.detach();
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
$: if (contentContainer && allowSelecting) {
|
|
1914
|
+
attachSelectedDragController();
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1765
1917
|
function handleNewFolderLocal(folderName: string) {
|
|
1766
1918
|
const newFolder: FileSystemItem = {
|
|
1767
1919
|
id: `folder_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`,
|
|
@@ -1904,7 +2056,7 @@
|
|
|
1904
2056
|
previewOpen: !!previewFile,
|
|
1905
2057
|
designSystemModalOpen: $isModalOpen,
|
|
1906
2058
|
inputFocused: !!isInputFocused(event),
|
|
1907
|
-
rubberBandDragActive,
|
|
2059
|
+
rubberBandDragActive: rubberBandDragActive || selectedItemDragActive,
|
|
1908
2060
|
innerEscapeHandlerOpen,
|
|
1909
2061
|
selectionCount: allSelectedFiles.length,
|
|
1910
2062
|
clearableSelectionCount,
|
|
@@ -2330,7 +2482,8 @@
|
|
|
2330
2482
|
|
|
2331
2483
|
function handleFileBrowserCommand(event: Event) {
|
|
2332
2484
|
const detail = (event as CustomEvent).detail;
|
|
2333
|
-
if (!detail
|
|
2485
|
+
if (!detail) return;
|
|
2486
|
+
if (detail.instanceId && detail.instanceId !== instanceId && detail.instanceId !== '*') return;
|
|
2334
2487
|
if (detail.command === 'back') handleNavigateBack();
|
|
2335
2488
|
else if (detail.command === 'forward') handleNavigateForward();
|
|
2336
2489
|
else if (detail.command === 'index') {
|
|
@@ -2341,6 +2494,8 @@
|
|
|
2341
2494
|
void evictGoneUploads([detail.uploadId]);
|
|
2342
2495
|
} else if (detail.command === 'refresh-uploads') {
|
|
2343
2496
|
void refreshUploadsFromApi();
|
|
2497
|
+
} else if (detail.command === 'reload-demo-tree') {
|
|
2498
|
+
reloadDemoFromStorage();
|
|
2344
2499
|
}
|
|
2345
2500
|
}
|
|
2346
2501
|
|
|
@@ -2850,7 +3005,9 @@ mainGridClass="app-main-grid"
|
|
|
2850
3005
|
<div
|
|
2851
3006
|
bind:this={mainContainer}
|
|
2852
3007
|
bind:clientWidth={mainContainerWidth}
|
|
2853
|
-
class="{rootContainerClass} {className ? className + ' ' : ''}flex h-full w-full flex-col overflow-hidden bg-background relative {
|
|
3008
|
+
class="{rootContainerClass} {className ? className + ' ' : ''}flex h-full w-full flex-col overflow-hidden bg-background relative {selectedItemDragActive
|
|
3009
|
+
? 'cursor-grabbing'
|
|
3010
|
+
: ''} {
|
|
2854
3011
|
dragActive
|
|
2855
3012
|
? (dragInvalid
|
|
2856
3013
|
? 'ring-1 ring-destructive/30'
|
|
@@ -2887,6 +3044,8 @@ mainGridClass="app-main-grid"
|
|
|
2887
3044
|
canGoForward={$canGoForwardStore}
|
|
2888
3045
|
on:toggleSelectedFiles={(e : CustomEvent) => allowSelecting && toggleModal()}
|
|
2889
3046
|
showBreadcrumbs={showBreadcrumbs && !libraryMode}
|
|
3047
|
+
enableFolderDropTargets={libraryCapabilities.folders && allowSelecting}
|
|
3048
|
+
rootDropTargetId={$fileStore.root?.id ?? 'root'}
|
|
2890
3049
|
title={libraryMode ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel')) : ''}
|
|
2891
3050
|
/>
|
|
2892
3051
|
|
|
@@ -3123,7 +3282,7 @@ mainGridClass="app-main-grid"
|
|
|
3123
3282
|
<!-- Item content -->
|
|
3124
3283
|
<div
|
|
3125
3284
|
data-item-id={item.id}
|
|
3126
|
-
class="item-container group/file-tile"
|
|
3285
|
+
class="item-container group/file-tile transition-opacity duration-fast data-[dragging-source=true]:opacity-40 data-[drag-exit=true]:scale-95 data-[drag-exit=true]:opacity-0"
|
|
3127
3286
|
data-selected={allowSelecting && currentSelections.some(f => f.id === item.id) ? 'true' : undefined}
|
|
3128
3287
|
>
|
|
3129
3288
|
{#if item.type === 'new-folder'}
|
|
@@ -3420,6 +3579,8 @@ mainGridClass="app-main-grid"
|
|
|
3420
3579
|
/>
|
|
3421
3580
|
{/if}
|
|
3422
3581
|
|
|
3582
|
+
<DragGhostStack snapshot={selectedDragSnapshot} />
|
|
3583
|
+
|
|
3423
3584
|
<!-- POP-UPS (only for an app that has no toaster of its own) -->
|
|
3424
3585
|
{#if renderToaster}
|
|
3425
3586
|
<ToasterModal containerAriaLabel={$t('toast.regionLabel')} closeButtonAriaLabel={$t('toast.closeLabel')} />
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
export let isLoading: boolean = false;
|
|
23
23
|
export let currentPathNames: string[] = [];
|
|
24
24
|
export let showBreadcrumbs: boolean = true;
|
|
25
|
+
export let enableFolderDropTargets = false;
|
|
26
|
+
export let rootDropTargetId = 'root';
|
|
25
27
|
/** Shown in place of the breadcrumbs when they are hidden (a library without folders has nowhere to navigate). */
|
|
26
28
|
export let title: string = '';
|
|
27
29
|
/** Compact header when the file browser container is below 700px wide. */
|
|
@@ -93,6 +95,8 @@
|
|
|
93
95
|
forwardLabel={$t('breadcrumbs.forward')}
|
|
94
96
|
rootLabel={$t('breadcrumbs.root')}
|
|
95
97
|
breadcrumbLabel={$t('breadcrumbs.label')}
|
|
98
|
+
{enableFolderDropTargets}
|
|
99
|
+
{rootDropTargetId}
|
|
96
100
|
/>
|
|
97
101
|
{:else if title}
|
|
98
102
|
<span class="header-title text-heading-section block truncate text-foreground">{title}</span>
|
|
@@ -22,6 +22,8 @@ declare const Header: $$__sveltets_2_IsomorphicComponent<{
|
|
|
22
22
|
isLoading?: boolean;
|
|
23
23
|
currentPathNames?: string[];
|
|
24
24
|
showBreadcrumbs?: boolean;
|
|
25
|
+
enableFolderDropTargets?: boolean;
|
|
26
|
+
rootDropTargetId?: string;
|
|
25
27
|
/** Shown in place of the breadcrumbs when they are hidden (a library without folders has nowhere to navigate). */ title?: string;
|
|
26
28
|
/** Compact header when the file browser container is below 700px wide. */ compact?: boolean;
|
|
27
29
|
headerEl?: any;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Floating stack of shadow tiles while dragging selected files toward a folder.
|
|
4
|
+
*/
|
|
5
|
+
import { FileIcon } from '../ui';
|
|
6
|
+
import type { SelectedItemDragSnapshot } from '../../actions/dragSelectedToFolder';
|
|
7
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
8
|
+
|
|
9
|
+
export let snapshot: SelectedItemDragSnapshot;
|
|
10
|
+
|
|
11
|
+
const textDirection = useTextDirection();
|
|
12
|
+
$: nameDirection = dirForUserText($textDirection);
|
|
13
|
+
|
|
14
|
+
type GhostLayer = SelectedItemDragSnapshot['layers'][number];
|
|
15
|
+
|
|
16
|
+
/** The transform of one tile of the stack: where it floats, tilted and scaled as the stack asks. */
|
|
17
|
+
function tileTransform(layer: GhostLayer): string {
|
|
18
|
+
return `translate3d(${layer.x + layer.offsetX}px, ${layer.y + layer.offsetY}px, 0) rotate(${layer.rotate}deg) scale(${layer.scale})`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The transform of the count badge, next to the pointer. */
|
|
22
|
+
$: badgeTransform = `translate3d(${snapshot.pointerX + 12}px, ${snapshot.pointerY - 28}px, 0)`;
|
|
23
|
+
|
|
24
|
+
$: visible = snapshot.active && snapshot.layers.length > 0;
|
|
25
|
+
$: showBadge = snapshot.totalCount > 1;
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
{#if visible}
|
|
29
|
+
<div
|
|
30
|
+
class="pointer-events-none fixed inset-0 z-[300000]"
|
|
31
|
+
aria-hidden="true"
|
|
32
|
+
data-fb-drag-ghost-root
|
|
33
|
+
>
|
|
34
|
+
{#each snapshot.layers as layer (layer.item.id)}
|
|
35
|
+
{@const thumb = layer.item.thumbnail || layer.item.url || ''}
|
|
36
|
+
<div
|
|
37
|
+
class="absolute w-[200px] will-change-transform"
|
|
38
|
+
style:transform={tileTransform(layer)}
|
|
39
|
+
style:opacity={layer.opacity}
|
|
40
|
+
>
|
|
41
|
+
<div
|
|
42
|
+
class="flex items-center gap-2 rounded-xl border border-border/80 bg-background/90 p-2 shadow-lg shadow-foreground/15 backdrop-blur-sm"
|
|
43
|
+
>
|
|
44
|
+
<div class="relative size-10 shrink-0 overflow-hidden rounded-lg bg-muted">
|
|
45
|
+
{#if thumb && /^(https?:|blob:|data:image)/i.test(thumb)}
|
|
46
|
+
<img src={thumb} alt="" class="size-full object-cover" draggable="false" />
|
|
47
|
+
{:else}
|
|
48
|
+
<div class="flex size-full items-center justify-center">
|
|
49
|
+
<FileIcon file={layer.item} size="md" />
|
|
50
|
+
</div>
|
|
51
|
+
{/if}
|
|
52
|
+
</div>
|
|
53
|
+
<p dir={nameDirection} class="min-w-0 flex-1 truncate text-caption text-foreground">
|
|
54
|
+
{layer.item.name}
|
|
55
|
+
</p>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
{/each}
|
|
59
|
+
|
|
60
|
+
{#if showBadge}
|
|
61
|
+
<div
|
|
62
|
+
class="absolute flex size-7 items-center justify-center rounded-full bg-primary text-caption font-medium text-primary-foreground shadow-md"
|
|
63
|
+
style:transform={badgeTransform}
|
|
64
|
+
>
|
|
65
|
+
{snapshot.totalCount}
|
|
66
|
+
</div>
|
|
67
|
+
{/if}
|
|
68
|
+
</div>
|
|
69
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SelectedItemDragSnapshot } from '../../actions/dragSelectedToFolder';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const DragGhostStack: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
snapshot: SelectedItemDragSnapshot;
|
|
17
|
+
}, {
|
|
18
|
+
[evt: string]: CustomEvent<any>;
|
|
19
|
+
}, {}, {}, string>;
|
|
20
|
+
type DragGhostStack = InstanceType<typeof DragGhostStack>;
|
|
21
|
+
export default DragGhostStack;
|
|
@@ -69,10 +69,13 @@
|
|
|
69
69
|
: 'opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100';
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
|
-
<div
|
|
72
|
+
<div
|
|
73
|
+
class="fb-folder-item-ct group relative w-full transition-transform duration-fast group-data-[folder-drop-hover=true]:scale-[1.02] group-data-[folder-drop-pulse=true]:scale-[0.98]"
|
|
74
|
+
data-folder-drop-target={item.id}
|
|
75
|
+
>
|
|
73
76
|
<!-- Tile activation mirrors the folder thumb; keyboard users use the existing open-folder control. -->
|
|
74
77
|
<div
|
|
75
|
-
class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-
|
|
78
|
+
class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-all duration-fast hover:bg-accent has-[[data-state=open]]:bg-accent group-data-[folder-drop-hover=true]:bg-accent group-data-[folder-drop-hover=true]:ring-2 group-data-[folder-drop-hover=true]:ring-brand"
|
|
76
79
|
onclick={handleTileClick}
|
|
77
80
|
role="presentation"
|
|
78
81
|
>
|
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
import { previewKeyAction } from '../../utils/previewKeys';
|
|
41
41
|
import { getCachedImageNaturalSize, preloadImageUrl, probeDecodedImage } from '../../utils/imagePreviewCache';
|
|
42
42
|
import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
|
|
43
|
+
import { computeImagePreviewModalFrame } from '../../utils/imagePreviewFrame';
|
|
43
44
|
|
|
44
45
|
// Stores
|
|
45
46
|
import { addMissingFile, missingFiles } from '../../stores/missingFilesStore';
|
|
46
|
-
import {
|
|
47
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
47
48
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
48
49
|
import { useI18n } from '../../i18n';
|
|
49
50
|
import { formatFileSize } from '../../utils/fileUtils';
|
|
@@ -70,6 +71,8 @@
|
|
|
70
71
|
/** Shell vertical padding (p-6 top + bottom, and the 1px border of the card on each side). */
|
|
71
72
|
const MODAL_VERTICAL_PAD = 50;
|
|
72
73
|
const TOTAL_VERTICAL_SPACE = MODAL_VERTICAL_PAD + HEADER_BLOCK;
|
|
74
|
+
/** Image cards open once at their final size (BaseModal still fades / slides in). */
|
|
75
|
+
const IMAGE_PREVIEW_ANIMATES_SIZE = false;
|
|
73
76
|
|
|
74
77
|
// STATE VARS
|
|
75
78
|
let showLogs = false;
|
|
@@ -199,7 +202,8 @@
|
|
|
199
202
|
};
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
$: isSelected =
|
|
205
|
+
$: isSelected =
|
|
206
|
+
allowSelecting && ($persistentSelectStore[currentFilter] ?? []).includes(file.id);
|
|
203
207
|
let fittedImage: { width: string; height: string } | null = null;
|
|
204
208
|
let fittedImageForId = '';
|
|
205
209
|
|
|
@@ -248,7 +252,10 @@
|
|
|
248
252
|
if (file.id !== fileId || imageRevealForId === fileId || imageBitmapReadyForId !== fileId) return;
|
|
249
253
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
250
254
|
// A card that never got a size (the picture reported none) has no move to wait for
|
|
251
|
-
const waitMs =
|
|
255
|
+
const waitMs =
|
|
256
|
+
IMAGE_PREVIEW_ANIMATES_SIZE && frameSizedForId === fileId
|
|
257
|
+
? imageRevealDelayMs(frameSizedAtMs, performance.now())
|
|
258
|
+
: 0;
|
|
252
259
|
imageRevealTimer = setTimeout(() => {
|
|
253
260
|
imageRevealTimer = undefined;
|
|
254
261
|
if (file.id !== fileId || imageBitmapReadyForId !== fileId) return;
|
|
@@ -286,19 +293,16 @@
|
|
|
286
293
|
const styles = getComputedStyle(element);
|
|
287
294
|
margin = parseInt(styles.getPropertyValue('--app-margin').trim()) || margin;
|
|
288
295
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
);
|
|
298
|
-
const next = {
|
|
299
|
-
width: `${cardWidth}px`,
|
|
300
|
-
height: `${Math.max(100, Math.round(height * scale) + TOTAL_VERTICAL_SPACE)}px`
|
|
301
|
-
};
|
|
296
|
+
const computed = computeImagePreviewModalFrame(width, height, {
|
|
297
|
+
hostWidth: frame.width,
|
|
298
|
+
hostHeight: frame.height,
|
|
299
|
+
sideMargin: margin,
|
|
300
|
+
dialogHorizontalPad: DIALOG_HORIZONTAL_PAD,
|
|
301
|
+
headerBlock: HEADER_BLOCK,
|
|
302
|
+
verticalPad: MODAL_VERTICAL_PAD,
|
|
303
|
+
minDialogWidth: MIN_IMAGE_DIALOG_WIDTH
|
|
304
|
+
});
|
|
305
|
+
const next = { width: computed.width, height: computed.height };
|
|
302
306
|
const id = file.id;
|
|
303
307
|
fittedImageForId = id;
|
|
304
308
|
fittedImage = next;
|
|
@@ -306,19 +310,47 @@
|
|
|
306
310
|
frameSizedAtMs = performance.now();
|
|
307
311
|
if (imageRevealTimer) clearTimeout(imageRevealTimer);
|
|
308
312
|
imageRevealTimer = undefined;
|
|
309
|
-
|
|
310
|
-
|
|
313
|
+
const revealNow =
|
|
314
|
+
options?.revealImmediately || !IMAGE_PREVIEW_ANIMATES_SIZE;
|
|
315
|
+
if (revealNow) {
|
|
311
316
|
imageBitmapReadyForId = id;
|
|
312
317
|
imageRevealForId = id;
|
|
313
318
|
slowLoaderForId = '';
|
|
314
319
|
return;
|
|
315
320
|
}
|
|
316
|
-
// The card eases to this size first. The picture stays hidden until it has loaded AND the card has made that move
|
|
317
|
-
// (if it loaded already, it appears when the move is over; if not, `handleImageBitmapLoaded` shows it when it arrives).
|
|
318
321
|
imageRevealForId = '';
|
|
319
322
|
revealImageWhenReady(id);
|
|
320
323
|
}
|
|
321
324
|
|
|
325
|
+
async function ensureImageFrameBeforeOpen() {
|
|
326
|
+
if (!open || fileType !== 'image' || !fileUrl || fittedImageForId === file.id) return;
|
|
327
|
+
let width = file.width;
|
|
328
|
+
let height = file.height;
|
|
329
|
+
if (!width || !height) {
|
|
330
|
+
const cached = getCachedImageNaturalSize(fileUrl) ?? probeDecodedImage(fileUrl);
|
|
331
|
+
if (cached) {
|
|
332
|
+
width = cached.width;
|
|
333
|
+
height = cached.height;
|
|
334
|
+
} else {
|
|
335
|
+
await preloadImageUrl(fileUrl);
|
|
336
|
+
const afterLoad = getCachedImageNaturalSize(fileUrl);
|
|
337
|
+
if (afterLoad) {
|
|
338
|
+
width = afterLoad.width;
|
|
339
|
+
height = afterLoad.height;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (file.id !== imageStateForFileId || fittedImageForId === file.id) return;
|
|
344
|
+
if (width && height) {
|
|
345
|
+
fitImageFrame(width, height, { revealImmediately: true });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const frame = hostFrame();
|
|
349
|
+
fitImageFrame(Math.round(frame.width * 0.55), Math.round(frame.height * 0.45), {
|
|
350
|
+
revealImmediately: true
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
322
354
|
function revealCachedImageIfReady() {
|
|
323
355
|
if (!open || fileType !== 'image' || !hasValidUrl || !fileUrl) return;
|
|
324
356
|
const id = file.id;
|
|
@@ -328,7 +360,7 @@
|
|
|
328
360
|
// The browser may still hold the picture decoded (opened before, or loaded as a neighbour): then it is shown at once
|
|
329
361
|
const cached = probeDecodedImage(fileUrl);
|
|
330
362
|
if (file.width && file.height) {
|
|
331
|
-
fitImageFrame(file.width, file.height, { revealImmediately:
|
|
363
|
+
fitImageFrame(file.width, file.height, { revealImmediately: true });
|
|
332
364
|
return;
|
|
333
365
|
}
|
|
334
366
|
if (cached) {
|
|
@@ -392,10 +424,14 @@
|
|
|
392
424
|
|
|
393
425
|
/** Size the shell from catalogued dimensions or a warm decoder cache before the bitmap loads. */
|
|
394
426
|
$: if (open && file?.id && fileUrl && fileType === 'image' && imageStateForFileId === file.id) {
|
|
427
|
+
void ensureImageFrameBeforeOpen();
|
|
395
428
|
revealCachedImageIfReady();
|
|
396
429
|
preloadNeighborPreviewImages();
|
|
397
430
|
}
|
|
398
431
|
|
|
432
|
+
$: modalPanelShown =
|
|
433
|
+
fileType !== 'image' || showsErrorState || fittedImageForId === file.id;
|
|
434
|
+
|
|
399
435
|
// The card's size. It stays BELOW the block above on purpose: that block sets `fittedImage` and `fittedImageForId`
|
|
400
436
|
// inside a function, so Svelte cannot order the two statements by their assignments. A statement placed above it reads
|
|
401
437
|
// the frame of the previous file in the same update (the small loading card) and does not run again, so a file that
|
|
@@ -651,7 +687,8 @@
|
|
|
651
687
|
ariaLabel={file.name}
|
|
652
688
|
width={modalDimensions.width}
|
|
653
689
|
height={modalDimensions.height}
|
|
654
|
-
animateSize={fileType === '
|
|
690
|
+
animateSize={fileType === 'video'}
|
|
691
|
+
shown={modalPanelShown}
|
|
655
692
|
{target}
|
|
656
693
|
showScroll={false}
|
|
657
694
|
on:close={handleClose}
|