@widgetic/file-browser 0.5.42 → 0.5.44
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 +210 -50
- 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/FileItem.svelte +8 -7
- 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/i18n/messages.d.ts +1 -1
- package/dist/i18n/messages.js +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 +89 -17
- 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 +13 -5
- package/dist/utils/libraryTree.js +41 -47
- package/dist/utils/userUploadsStorage.js +6 -6
- package/dist/utils/widgeticDelete.d.ts +14 -0
- package/dist/utils/widgeticDelete.js +52 -0
- 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
|
|
|
@@ -732,7 +771,8 @@
|
|
|
732
771
|
const token = session?.accessToken || session?.access_token;
|
|
733
772
|
if (token) {
|
|
734
773
|
// Scope Dexie only — do not invent an empty apiBasePath upload config.
|
|
735
|
-
const { setCacheOwner } = await import('@widgetic/cache-layer');
|
|
774
|
+
const { ensureCacheOwnerFromSessionHint, setCacheOwner } = await import('@widgetic/cache-layer');
|
|
775
|
+
ensureCacheOwnerFromSessionHint();
|
|
736
776
|
const payloadPart = token.split('.')[1];
|
|
737
777
|
if (payloadPart) {
|
|
738
778
|
const normalized = payloadPart.replace(/-/g, '+').replace(/_/g, '/');
|
|
@@ -769,6 +809,13 @@
|
|
|
769
809
|
|
|
770
810
|
if (widgeticLibraryMode || !useDemoContent) {
|
|
771
811
|
let files = await loadUserUploads();
|
|
812
|
+
const cachedCount = files.length;
|
|
813
|
+
if (cachedCount > 0) {
|
|
814
|
+
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
815
|
+
basePath = '';
|
|
816
|
+
isLoading = false;
|
|
817
|
+
isVirtualListInitialized = true;
|
|
818
|
+
}
|
|
772
819
|
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
773
820
|
try {
|
|
774
821
|
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
@@ -779,20 +826,28 @@
|
|
|
779
826
|
apiHydrationSucceeded: true,
|
|
780
827
|
});
|
|
781
828
|
await replacePersistedUploads(files);
|
|
829
|
+
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
830
|
+
basePath = '';
|
|
782
831
|
if (showLogs) {
|
|
783
832
|
// console.log('[FileBrowser] Hydrated uploads from API:', remoteFiles.length);
|
|
784
833
|
}
|
|
785
834
|
} catch (hydrateError) {
|
|
786
835
|
console.warn('[FileBrowser] Upload hydration failed, using local cache:', hydrateError);
|
|
836
|
+
if (!data) {
|
|
837
|
+
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
838
|
+
basePath = '';
|
|
839
|
+
}
|
|
787
840
|
}
|
|
841
|
+
} else if (!data) {
|
|
842
|
+
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
843
|
+
basePath = '';
|
|
788
844
|
}
|
|
789
|
-
data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
|
|
790
|
-
basePath = '';
|
|
791
845
|
if (showLogs) {
|
|
792
846
|
// console.log('[FileBrowser] Widgetic library mode — user uploads only');
|
|
793
847
|
}
|
|
794
848
|
} else if (useDemoContent) {
|
|
795
|
-
|
|
849
|
+
const storedDemo = getFromStorage(demoContentKey, null) as FileSystemRoot | null;
|
|
850
|
+
data = storedDemo?.root ? storedDemo : demoContent;
|
|
796
851
|
if (!basePath.startsWith('http') && !dev) {
|
|
797
852
|
basePath = `/node_modules/@widgetic/file-browser/dist/static${basePath}`;
|
|
798
853
|
}
|
|
@@ -833,6 +888,10 @@
|
|
|
833
888
|
isLoading = false;
|
|
834
889
|
isVirtualListInitialized = true;
|
|
835
890
|
}
|
|
891
|
+
|
|
892
|
+
if (!libraryMode) {
|
|
893
|
+
void refreshUploadsFromApi();
|
|
894
|
+
}
|
|
836
895
|
});
|
|
837
896
|
|
|
838
897
|
function init() {
|
|
@@ -861,10 +920,9 @@
|
|
|
861
920
|
|
|
862
921
|
// save as demo content if not already saved (never for a media library: its files are not demo content, and
|
|
863
922
|
// the visitor's file list must not be copied into localStorage)
|
|
864
|
-
if(!libraryMode &&
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
923
|
+
if (!libraryMode && useDemoContent) {
|
|
924
|
+
persistDemoContentTree();
|
|
925
|
+
}
|
|
868
926
|
|
|
869
927
|
if(showLogs) console.log('FileBrowser: init data:', data);
|
|
870
928
|
|
|
@@ -947,6 +1005,8 @@
|
|
|
947
1005
|
window.removeEventListener('resize', handleResize);
|
|
948
1006
|
window.removeEventListener('keydown', handleKeyDown);
|
|
949
1007
|
window.removeEventListener('widgetic:file-browser-command', handleFileBrowserCommand);
|
|
1008
|
+
selectedDragTeardown?.();
|
|
1009
|
+
selectedDragTeardown = null;
|
|
950
1010
|
});
|
|
951
1011
|
|
|
952
1012
|
// Add logging to key reactive statements
|
|
@@ -1253,14 +1313,24 @@
|
|
|
1253
1313
|
function handleFolderClick(folder: FolderItemWithCount) {
|
|
1254
1314
|
}
|
|
1255
1315
|
|
|
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.
|
|
1316
|
+
// Subscribe to the persistent store directly so tile selection indicators update (Svelte 5 + derived fn pattern).
|
|
1317
|
+
$: selectedIdsForFilter = $persistentSelectStore[filter] ?? [];
|
|
1259
1318
|
$: selectionViewFiles =
|
|
1260
1319
|
!isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0
|
|
1261
1320
|
? [...sortedFilteredFiles, ...recentFiles]
|
|
1262
1321
|
: sortedFilteredFiles;
|
|
1263
|
-
$:
|
|
1322
|
+
$: allSelectedFiles =
|
|
1323
|
+
$fileStore?.root && filter
|
|
1324
|
+
? getAllFiles($fileStore.root).filter(
|
|
1325
|
+
(f) => selectedIdsForFilter.includes(f.id) && !$missingFiles.has(f.id)
|
|
1326
|
+
)
|
|
1327
|
+
: [];
|
|
1328
|
+
$: currentSelections =
|
|
1329
|
+
$fileStore?.root && filter
|
|
1330
|
+
? selectionViewFiles.filter(
|
|
1331
|
+
(f) => selectedIdsForFilter.includes(f.id) && !$missingFiles.has(f.id)
|
|
1332
|
+
)
|
|
1333
|
+
: [];
|
|
1264
1334
|
|
|
1265
1335
|
function toggleFileSelection(file: FileSystemItem) {
|
|
1266
1336
|
if (!allowSelecting) return;
|
|
@@ -1445,16 +1515,6 @@
|
|
|
1445
1515
|
const { action, item } = event.detail;
|
|
1446
1516
|
|
|
1447
1517
|
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
1518
|
// Use allSelectedFiles instead of validSelectedFiles to get ALL selected files across ALL folders
|
|
1459
1519
|
const validSelectedFiles = allSelectedFiles;
|
|
1460
1520
|
// console.log('Current valid selections across all folders:', validSelectedFiles);
|
|
@@ -1634,7 +1694,7 @@
|
|
|
1634
1694
|
});
|
|
1635
1695
|
|
|
1636
1696
|
showToast('success', initialToastMessage, {
|
|
1637
|
-
description: $t('toast.inBackground'),
|
|
1697
|
+
description: libraryMode ? $t('toast.inBackground') : undefined,
|
|
1638
1698
|
});
|
|
1639
1699
|
|
|
1640
1700
|
// Process deletions in the background
|
|
@@ -1676,6 +1736,8 @@
|
|
|
1676
1736
|
}
|
|
1677
1737
|
|
|
1678
1738
|
if (successCount > 0) {
|
|
1739
|
+
persistMyUploadsTree();
|
|
1740
|
+
|
|
1679
1741
|
// Show appropriate toast notification for successful deletions
|
|
1680
1742
|
let toastMessage = '';
|
|
1681
1743
|
let toastDescription = '';
|
|
@@ -1735,33 +1797,122 @@
|
|
|
1735
1797
|
return Boolean(uploadConfig?.accessToken && uploadConfig?.apiBasePath) || !useDemoContent;
|
|
1736
1798
|
}
|
|
1737
1799
|
|
|
1738
|
-
//
|
|
1739
|
-
function nameBuiltInFolder(folderName: string) {
|
|
1740
|
-
fileStore.update((store) => {
|
|
1741
|
-
const builtInFolder = store.root?.children?.find((child) => child.type === 'folder' && child.id === 'folder_my_uploads');
|
|
1742
|
-
if (!store.root || !builtInFolder || builtInFolder.name === folderName) return store;
|
|
1743
|
-
return {
|
|
1744
|
-
...store,
|
|
1745
|
-
root: {
|
|
1746
|
-
...store.root,
|
|
1747
|
-
children: (store.root.children ?? []).map((child) => (child === builtInFolder ? { ...child, name: folderName } : child)),
|
|
1748
|
-
},
|
|
1749
|
-
};
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1752
|
-
$: if (!libraryMode) nameBuiltInFolder($t('library.defaultLabel'));
|
|
1753
|
-
|
|
1754
|
-
// Saves the whole root of the Widgetic library (the built-in Uploads folder, the folders next to it and the files loose
|
|
1800
|
+
// Saves the whole root of the Widgetic library (user folders and loose files at the root), so an upload, a new folder,
|
|
1755
1801
|
// at the root), so an upload, a new folder, a rename or a move keeps its place after a reload.
|
|
1756
1802
|
function persistMyUploadsTree() {
|
|
1757
|
-
|
|
1758
|
-
if (
|
|
1803
|
+
if (libraryMode) return;
|
|
1804
|
+
if (useDemoContent) {
|
|
1805
|
+
persistDemoContentTree();
|
|
1806
|
+
broadcastFileBrowserCommand('reload-demo-tree');
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
if (!isWidgeticLibraryMode()) return;
|
|
1759
1810
|
const store = get(fileStore);
|
|
1760
1811
|
if (store.root?.children) {
|
|
1761
|
-
saveLibraryTreeChildren(store.root.children);
|
|
1812
|
+
void saveLibraryTreeChildren(store.root.children);
|
|
1813
|
+
broadcastFileBrowserCommand('refresh-uploads');
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
function getSelectedFilesInCurrentFolder(): FileSystemItem[] {
|
|
1818
|
+
const inFolder = new Set(
|
|
1819
|
+
sortedFilteredFiles.filter((entry) => entry.type === 'file' || entry.type === 'folder').map((entry) => entry.id)
|
|
1820
|
+
);
|
|
1821
|
+
return allSelectedFiles.filter((file) => inFolder.has(file.id));
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
function prefersReducedMotion(): boolean {
|
|
1825
|
+
if (!isBrowser) return false;
|
|
1826
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
async function handleSelectedItemsDrop(targetFolderId: string, items: FileSystemItem[]) {
|
|
1830
|
+
for (const item of items) {
|
|
1831
|
+
const el = findItemElement(item.id);
|
|
1832
|
+
el?.setAttribute('data-drag-exit', 'true');
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
try {
|
|
1836
|
+
const result = await commitBatchMove({
|
|
1837
|
+
sourceItems: items,
|
|
1838
|
+
targetFolderId,
|
|
1839
|
+
localOnly: isWidgeticLibraryMode(),
|
|
1840
|
+
currentFilter: filter,
|
|
1841
|
+
navigationStoreId: instanceId
|
|
1842
|
+
});
|
|
1843
|
+
|
|
1844
|
+
if (result.movedIds.length === 0) {
|
|
1845
|
+
throw new MediaLibraryError('FAILED', 'No items were moved successfully', {
|
|
1846
|
+
messageKey: 'moveDialog.noneMoved'
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
if (result.failedCount > 0) {
|
|
1851
|
+
toast.warning($t('moveDialog.partialTitle'), {
|
|
1852
|
+
description: $t('moveDialog.partialDetail', {
|
|
1853
|
+
moved: result.movedIds.length,
|
|
1854
|
+
total: items.length
|
|
1855
|
+
}),
|
|
1856
|
+
position: 'bottom-center',
|
|
1857
|
+
class: 'file-browser-sonar',
|
|
1858
|
+
duration: 2000
|
|
1859
|
+
});
|
|
1860
|
+
} else {
|
|
1861
|
+
toast.success(
|
|
1862
|
+
items.length === 1 ? $t('moveDialog.doneOne') : $t('moveDialog.doneMany'),
|
|
1863
|
+
{
|
|
1864
|
+
description: $t('moveDialog.doneItemsDetail', { count: result.movedIds.length }),
|
|
1865
|
+
position: 'bottom-center',
|
|
1866
|
+
class: 'file-browser-sonar',
|
|
1867
|
+
duration: 2000
|
|
1868
|
+
}
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
selectedFiles.set([]);
|
|
1873
|
+
persistMyUploadsTree();
|
|
1874
|
+
} catch (error) {
|
|
1875
|
+
console.error('Drag move failed:', error);
|
|
1876
|
+
items.forEach((item) => findItemElement(item.id)?.removeAttribute('data-drag-exit'));
|
|
1877
|
+
toast.error($t('moveDialog.failedItems'), {
|
|
1878
|
+
description: messageForVisitor(error, $t),
|
|
1879
|
+
position: 'bottom-center',
|
|
1880
|
+
class: 'file-browser-sonar',
|
|
1881
|
+
duration: 2000
|
|
1882
|
+
});
|
|
1762
1883
|
}
|
|
1763
1884
|
}
|
|
1764
1885
|
|
|
1886
|
+
function attachSelectedDragController() {
|
|
1887
|
+
if (selectedDragTeardown || !contentContainer || !allowSelecting) return;
|
|
1888
|
+
const controller = createDragSelectedToFolderController({
|
|
1889
|
+
getContainer: () => contentContainer,
|
|
1890
|
+
getScrollContainer: () => scrollContainer,
|
|
1891
|
+
getSelectedInView: getSelectedFilesInCurrentFolder,
|
|
1892
|
+
getImmediateParentId: () => immediateParentIdForDrag,
|
|
1893
|
+
getRoot: () => $fileStore.root,
|
|
1894
|
+
isEnabled: () =>
|
|
1895
|
+
allowSelecting &&
|
|
1896
|
+
!$isModalOpen &&
|
|
1897
|
+
libraryCapabilities.folders &&
|
|
1898
|
+
!rubberBandDragActive,
|
|
1899
|
+
prefersReducedMotion,
|
|
1900
|
+
debugLog: showLogs,
|
|
1901
|
+
onSnapshot: (snap) => {
|
|
1902
|
+
selectedDragSnapshot = snap;
|
|
1903
|
+
selectedItemDragActive = snap.phase === 'dragging' || snap.phase === 'dropping';
|
|
1904
|
+
},
|
|
1905
|
+
onDrop: (targetFolderId, items) => {
|
|
1906
|
+
void handleSelectedItemsDrop(targetFolderId, items);
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
selectedDragTeardown = () => controller.detach();
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
$: if (contentContainer && allowSelecting) {
|
|
1913
|
+
attachSelectedDragController();
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1765
1916
|
function handleNewFolderLocal(folderName: string) {
|
|
1766
1917
|
const newFolder: FileSystemItem = {
|
|
1767
1918
|
id: `folder_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`,
|
|
@@ -1904,7 +2055,7 @@
|
|
|
1904
2055
|
previewOpen: !!previewFile,
|
|
1905
2056
|
designSystemModalOpen: $isModalOpen,
|
|
1906
2057
|
inputFocused: !!isInputFocused(event),
|
|
1907
|
-
rubberBandDragActive,
|
|
2058
|
+
rubberBandDragActive: rubberBandDragActive || selectedItemDragActive,
|
|
1908
2059
|
innerEscapeHandlerOpen,
|
|
1909
2060
|
selectionCount: allSelectedFiles.length,
|
|
1910
2061
|
clearableSelectionCount,
|
|
@@ -2330,7 +2481,8 @@
|
|
|
2330
2481
|
|
|
2331
2482
|
function handleFileBrowserCommand(event: Event) {
|
|
2332
2483
|
const detail = (event as CustomEvent).detail;
|
|
2333
|
-
if (!detail
|
|
2484
|
+
if (!detail) return;
|
|
2485
|
+
if (detail.instanceId && detail.instanceId !== instanceId && detail.instanceId !== '*') return;
|
|
2334
2486
|
if (detail.command === 'back') handleNavigateBack();
|
|
2335
2487
|
else if (detail.command === 'forward') handleNavigateForward();
|
|
2336
2488
|
else if (detail.command === 'index') {
|
|
@@ -2341,6 +2493,8 @@
|
|
|
2341
2493
|
void evictGoneUploads([detail.uploadId]);
|
|
2342
2494
|
} else if (detail.command === 'refresh-uploads') {
|
|
2343
2495
|
void refreshUploadsFromApi();
|
|
2496
|
+
} else if (detail.command === 'reload-demo-tree') {
|
|
2497
|
+
reloadDemoFromStorage();
|
|
2344
2498
|
}
|
|
2345
2499
|
}
|
|
2346
2500
|
|
|
@@ -2850,7 +3004,9 @@ mainGridClass="app-main-grid"
|
|
|
2850
3004
|
<div
|
|
2851
3005
|
bind:this={mainContainer}
|
|
2852
3006
|
bind:clientWidth={mainContainerWidth}
|
|
2853
|
-
class="{rootContainerClass} {className ? className + ' ' : ''}flex h-full w-full flex-col overflow-hidden bg-background relative {
|
|
3007
|
+
class="{rootContainerClass} {className ? className + ' ' : ''}flex h-full w-full flex-col overflow-hidden bg-background relative {selectedItemDragActive
|
|
3008
|
+
? 'cursor-grabbing'
|
|
3009
|
+
: ''} {
|
|
2854
3010
|
dragActive
|
|
2855
3011
|
? (dragInvalid
|
|
2856
3012
|
? 'ring-1 ring-destructive/30'
|
|
@@ -2887,6 +3043,8 @@ mainGridClass="app-main-grid"
|
|
|
2887
3043
|
canGoForward={$canGoForwardStore}
|
|
2888
3044
|
on:toggleSelectedFiles={(e : CustomEvent) => allowSelecting && toggleModal()}
|
|
2889
3045
|
showBreadcrumbs={showBreadcrumbs && !libraryMode}
|
|
3046
|
+
enableFolderDropTargets={libraryCapabilities.folders && allowSelecting}
|
|
3047
|
+
rootDropTargetId={$fileStore.root?.id ?? 'root'}
|
|
2890
3048
|
title={libraryMode ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel')) : ''}
|
|
2891
3049
|
/>
|
|
2892
3050
|
|
|
@@ -3123,7 +3281,7 @@ mainGridClass="app-main-grid"
|
|
|
3123
3281
|
<!-- Item content -->
|
|
3124
3282
|
<div
|
|
3125
3283
|
data-item-id={item.id}
|
|
3126
|
-
class="item-container group/file-tile"
|
|
3284
|
+
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
3285
|
data-selected={allowSelecting && currentSelections.some(f => f.id === item.id) ? 'true' : undefined}
|
|
3128
3286
|
>
|
|
3129
3287
|
{#if item.type === 'new-folder'}
|
|
@@ -3420,6 +3578,8 @@ mainGridClass="app-main-grid"
|
|
|
3420
3578
|
/>
|
|
3421
3579
|
{/if}
|
|
3422
3580
|
|
|
3581
|
+
<DragGhostStack snapshot={selectedDragSnapshot} />
|
|
3582
|
+
|
|
3423
3583
|
<!-- POP-UPS (only for an app that has no toaster of its own) -->
|
|
3424
3584
|
{#if renderToaster}
|
|
3425
3585
|
<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;
|
|
@@ -194,14 +194,15 @@
|
|
|
194
194
|
|
|
195
195
|
function handleSelect(event: Event) {
|
|
196
196
|
event.stopPropagation();
|
|
197
|
-
if (
|
|
197
|
+
if (allowSelecting) {
|
|
198
198
|
dispatch('select');
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/** Pointer on the tile (not the preview button or item menu): same as the preview button — select in selection mode, else open preview. */
|
|
203
203
|
function handleTileClick(event: MouseEvent) {
|
|
204
|
-
if (thumbnailOnly ||
|
|
204
|
+
if (thumbnailOnly || isFromMenuOrThumbControl(event)) return;
|
|
205
|
+
if (isMissing && !allowSelecting) return;
|
|
205
206
|
event.preventDefault();
|
|
206
207
|
if (allowSelecting) {
|
|
207
208
|
handleSelect(event);
|
|
@@ -228,14 +229,14 @@
|
|
|
228
229
|
$: tileShellClass = [
|
|
229
230
|
'flex w-full items-center gap-3 rounded-xl border border-border bg-background p-2 transition-colors duration-fast',
|
|
230
231
|
thumbnailOnly ? 'h-auto w-auto border-0 bg-transparent p-0' : 'h-16',
|
|
231
|
-
!thumbnailOnly &&
|
|
232
|
-
? 'hover:bg-
|
|
232
|
+
!thumbnailOnly && !effectiveIsMobile && !isSelected
|
|
233
|
+
? 'hover:bg-brand-subtle group-data-[drag-hover=true]/file-tile:bg-brand-subtle has-[[data-state=open]]:bg-accent'
|
|
233
234
|
: '',
|
|
234
|
-
!thumbnailOnly &&
|
|
235
|
+
!thumbnailOnly && !effectiveIsMobile && isSelected
|
|
235
236
|
? 'group-data-[drag-hover=true]/file-tile:bg-brand-subtle'
|
|
236
237
|
: '',
|
|
237
238
|
!thumbnailOnly && isSelected ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand' : '',
|
|
238
|
-
!thumbnailOnly && !isMissing ? 'cursor-pointer' : ''
|
|
239
|
+
!thumbnailOnly && (!isMissing || allowSelecting) ? 'cursor-pointer' : ''
|
|
239
240
|
]
|
|
240
241
|
.filter(Boolean)
|
|
241
242
|
.join(' ');
|
|
@@ -258,7 +259,7 @@
|
|
|
258
259
|
<!-- Whole tile activates like the preview thumb; preview button remains the keyboard focus target. -->
|
|
259
260
|
<div
|
|
260
261
|
class={tileShellClass}
|
|
261
|
-
onclick={!thumbnailOnly
|
|
262
|
+
onclick={!thumbnailOnly ? handleTileClick : undefined}
|
|
262
263
|
role="presentation"
|
|
263
264
|
>
|
|
264
265
|
<!-- 48×48 preview thumb (Figma File Thumb Large) -->
|
|
@@ -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-brand-subtle has-[[data-state=open]]:bg-accent group-data-[folder-drop-hover=true]:bg-brand-subtle 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
|
>
|