@widgetic/file-browser 0.5.41 → 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 +239 -36
- 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 +87 -26
- package/dist/components/previews/FilePreview.svelte.d.ts +6 -3
- package/dist/components/previews/FontPreview.svelte +4 -1
- package/dist/components/previews/FontPreview.svelte.d.ts +2 -0
- 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/index.d.ts +3 -0
- package/dist/index.js +3 -0
- 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/uploadListReconcile.d.ts +11 -0
- package/dist/utils/uploadListReconcile.js +30 -0
- package/dist/utils/userUploadsStorage.d.ts +8 -0
- package/dist/utils/userUploadsStorage.js +36 -2
- package/package.json +3 -3
|
@@ -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 {
|
|
@@ -68,12 +68,15 @@
|
|
|
68
68
|
import { getFileBrowserUploadConfig, setFileBrowserUploadConfig } from '../../stores/uploadApiStore';
|
|
69
69
|
import {
|
|
70
70
|
loadUserUploads,
|
|
71
|
+
removePersistedUploads,
|
|
72
|
+
replacePersistedUploads,
|
|
71
73
|
saveUserUpload,
|
|
72
74
|
saveUserUploadsBatch,
|
|
73
75
|
saveLibraryTreeChildren,
|
|
74
76
|
createUserUploadsFileSystemRoot,
|
|
75
77
|
} from '../../utils/userUploadsStorage';
|
|
76
78
|
import { fetchUserUploadsFromApi } from '../../utils/widgeticUpload';
|
|
79
|
+
import { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from '../../utils/uploadListReconcile';
|
|
77
80
|
import { get, writable } from 'svelte/store';
|
|
78
81
|
import { resolveFileItemUrl } from '../../utils/resolveFileUrl';
|
|
79
82
|
import { buildDeduplicatedRecentFiles } from '../../utils/recentFiles';
|
|
@@ -107,7 +110,8 @@
|
|
|
107
110
|
setPersistFolderPath
|
|
108
111
|
} from '../../stores/navigationStore';
|
|
109
112
|
//
|
|
110
|
-
import { persistentSelectStore
|
|
113
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
114
|
+
import { missingFiles } from '../../stores/missingFilesStore';
|
|
111
115
|
import { isModalOpen, modalState } from '@widgetic/design-system/components/modals/modalStore';
|
|
112
116
|
|
|
113
117
|
// MEDIA LIBRARY IMPORTS (the host's own storage; see the `mediaLibrary` prop)
|
|
@@ -121,6 +125,13 @@
|
|
|
121
125
|
import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
|
|
122
126
|
import { escapeSelectionAction } from '../../utils/escapeSelectionAction';
|
|
123
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';
|
|
124
135
|
|
|
125
136
|
// I18N IMPORTS (the words of the File Browser, in the page's language)
|
|
126
137
|
import { provideI18n } from '../../i18n/context';
|
|
@@ -194,6 +205,11 @@
|
|
|
194
205
|
/** Fixed-type selectors never show the type filter, even if a host passes `showFilters={true}`. */
|
|
195
206
|
$: controlsShowFilters = showFilters && !(isSingleFilePicker && initialFilter !== 'all');
|
|
196
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;
|
|
197
213
|
/** When set (single-file picker), disables confirm until user picks a different file. */
|
|
198
214
|
export let activeFileId: string | null = null;
|
|
199
215
|
export let showAddToEditor = false; // Toggle visibility of "Add to Editor" functionality
|
|
@@ -292,6 +308,32 @@
|
|
|
292
308
|
}
|
|
293
309
|
}
|
|
294
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
|
+
|
|
295
337
|
function removeFromStorage(instanceId: string) {
|
|
296
338
|
const key = getStorageKey(instanceId);
|
|
297
339
|
|
|
@@ -768,13 +810,14 @@
|
|
|
768
810
|
let files = await loadUserUploads();
|
|
769
811
|
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
770
812
|
try {
|
|
771
|
-
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
813
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
814
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
815
|
+
});
|
|
816
|
+
files = mergeRemoteUploadList(files, remoteFiles, {
|
|
817
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
818
|
+
apiHydrationSucceeded: true,
|
|
819
|
+
});
|
|
820
|
+
await replacePersistedUploads(files);
|
|
778
821
|
if (showLogs) {
|
|
779
822
|
// console.log('[FileBrowser] Hydrated uploads from API:', remoteFiles.length);
|
|
780
823
|
}
|
|
@@ -788,7 +831,8 @@
|
|
|
788
831
|
// console.log('[FileBrowser] Widgetic library mode — user uploads only');
|
|
789
832
|
}
|
|
790
833
|
} else if (useDemoContent) {
|
|
791
|
-
|
|
834
|
+
const storedDemo = getFromStorage(demoContentKey, null) as FileSystemRoot | null;
|
|
835
|
+
data = storedDemo?.root ? storedDemo : demoContent;
|
|
792
836
|
if (!basePath.startsWith('http') && !dev) {
|
|
793
837
|
basePath = `/node_modules/@widgetic/file-browser/dist/static${basePath}`;
|
|
794
838
|
}
|
|
@@ -829,6 +873,10 @@
|
|
|
829
873
|
isLoading = false;
|
|
830
874
|
isVirtualListInitialized = true;
|
|
831
875
|
}
|
|
876
|
+
|
|
877
|
+
if (!libraryMode) {
|
|
878
|
+
void refreshUploadsFromApi();
|
|
879
|
+
}
|
|
832
880
|
});
|
|
833
881
|
|
|
834
882
|
function init() {
|
|
@@ -857,10 +905,9 @@
|
|
|
857
905
|
|
|
858
906
|
// save as demo content if not already saved (never for a media library: its files are not demo content, and
|
|
859
907
|
// the visitor's file list must not be copied into localStorage)
|
|
860
|
-
if(!libraryMode &&
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
}
|
|
908
|
+
if (!libraryMode && useDemoContent) {
|
|
909
|
+
persistDemoContentTree();
|
|
910
|
+
}
|
|
864
911
|
|
|
865
912
|
if(showLogs) console.log('FileBrowser: init data:', data);
|
|
866
913
|
|
|
@@ -943,6 +990,8 @@
|
|
|
943
990
|
window.removeEventListener('resize', handleResize);
|
|
944
991
|
window.removeEventListener('keydown', handleKeyDown);
|
|
945
992
|
window.removeEventListener('widgetic:file-browser-command', handleFileBrowserCommand);
|
|
993
|
+
selectedDragTeardown?.();
|
|
994
|
+
selectedDragTeardown = null;
|
|
946
995
|
});
|
|
947
996
|
|
|
948
997
|
// Add logging to key reactive statements
|
|
@@ -1249,14 +1298,24 @@
|
|
|
1249
1298
|
function handleFolderClick(folder: FolderItemWithCount) {
|
|
1250
1299
|
}
|
|
1251
1300
|
|
|
1252
|
-
//
|
|
1253
|
-
$:
|
|
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.
|
|
1301
|
+
// Subscribe to the persistent store directly so tile selection indicators update (Svelte 5 + derived fn pattern).
|
|
1302
|
+
$: selectedIdsForFilter = $persistentSelectStore[filter] ?? [];
|
|
1255
1303
|
$: selectionViewFiles =
|
|
1256
1304
|
!isSingleFilePicker && currentPath.length === 0 && recentFiles.length > 0
|
|
1257
1305
|
? [...sortedFilteredFiles, ...recentFiles]
|
|
1258
1306
|
: sortedFilteredFiles;
|
|
1259
|
-
$:
|
|
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
|
+
: [];
|
|
1260
1319
|
|
|
1261
1320
|
function toggleFileSelection(file: FileSystemItem) {
|
|
1262
1321
|
if (!allowSelecting) return;
|
|
@@ -1441,16 +1500,6 @@
|
|
|
1441
1500
|
const { action, item } = event.detail;
|
|
1442
1501
|
|
|
1443
1502
|
if (isFileSystemItem(item)) {
|
|
1444
|
-
// The built-in Uploads folder always stays at the root (the library is rebuilt around it on every load)
|
|
1445
|
-
if (
|
|
1446
|
-
item.id === 'folder_my_uploads' &&
|
|
1447
|
-
item.type === 'folder' &&
|
|
1448
|
-
(action === 'rename' || action === 'move' || action === 'delete')
|
|
1449
|
-
) {
|
|
1450
|
-
if (showLogs) console.log('[FileBrowser] Blocked action on built-in Uploads folder:', action);
|
|
1451
|
-
return;
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
1503
|
// Use allSelectedFiles instead of validSelectedFiles to get ALL selected files across ALL folders
|
|
1455
1504
|
const validSelectedFiles = allSelectedFiles;
|
|
1456
1505
|
// console.log('Current valid selections across all folders:', validSelectedFiles);
|
|
@@ -1672,6 +1721,8 @@
|
|
|
1672
1721
|
}
|
|
1673
1722
|
|
|
1674
1723
|
if (successCount > 0) {
|
|
1724
|
+
persistMyUploadsTree();
|
|
1725
|
+
|
|
1675
1726
|
// Show appropriate toast notification for successful deletions
|
|
1676
1727
|
let toastMessage = '';
|
|
1677
1728
|
let toastDescription = '';
|
|
@@ -1750,14 +1801,119 @@
|
|
|
1750
1801
|
// Saves the whole root of the Widgetic library (the built-in Uploads folder, the folders next to it and the files loose
|
|
1751
1802
|
// at the root), so an upload, a new folder, a rename or a move keeps its place after a reload.
|
|
1752
1803
|
function persistMyUploadsTree() {
|
|
1753
|
-
|
|
1754
|
-
if (
|
|
1804
|
+
if (libraryMode) return;
|
|
1805
|
+
if (useDemoContent) {
|
|
1806
|
+
persistDemoContentTree();
|
|
1807
|
+
broadcastFileBrowserCommand('reload-demo-tree');
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
if (!isWidgeticLibraryMode()) return;
|
|
1755
1811
|
const store = get(fileStore);
|
|
1756
1812
|
if (store.root?.children) {
|
|
1757
|
-
saveLibraryTreeChildren(store.root.children);
|
|
1813
|
+
void saveLibraryTreeChildren(store.root.children);
|
|
1814
|
+
broadcastFileBrowserCommand('refresh-uploads');
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
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
|
+
});
|
|
1758
1884
|
}
|
|
1759
1885
|
}
|
|
1760
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
|
+
|
|
1761
1917
|
function handleNewFolderLocal(folderName: string) {
|
|
1762
1918
|
const newFolder: FileSystemItem = {
|
|
1763
1919
|
id: `folder_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`,
|
|
@@ -1900,7 +2056,7 @@
|
|
|
1900
2056
|
previewOpen: !!previewFile,
|
|
1901
2057
|
designSystemModalOpen: $isModalOpen,
|
|
1902
2058
|
inputFocused: !!isInputFocused(event),
|
|
1903
|
-
rubberBandDragActive,
|
|
2059
|
+
rubberBandDragActive: rubberBandDragActive || selectedItemDragActive,
|
|
1904
2060
|
innerEscapeHandlerOpen,
|
|
1905
2061
|
selectionCount: allSelectedFiles.length,
|
|
1906
2062
|
clearableSelectionCount,
|
|
@@ -2291,15 +2447,55 @@
|
|
|
2291
2447
|
}));
|
|
2292
2448
|
}
|
|
2293
2449
|
|
|
2450
|
+
async function evictGoneUploads(uploadIds: string[]) {
|
|
2451
|
+
if (!uploadIds.length || libraryMode) return;
|
|
2452
|
+
const drop = new Set(uploadIds);
|
|
2453
|
+
await removePersistedUploads(uploadIds);
|
|
2454
|
+
fileStore.update((store) => ({ ...store, root: removeFiles(store.root, drop) }));
|
|
2455
|
+
selectedFiles.update((files) => files.filter((file) => !drop.has(file.id)));
|
|
2456
|
+
if (previewFile && drop.has(previewFile.id)) {
|
|
2457
|
+
previewFile = null;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
async function refreshUploadsFromApi() {
|
|
2462
|
+
if (libraryMode) return;
|
|
2463
|
+
const uploadConfig = getFileBrowserUploadConfig();
|
|
2464
|
+
if (!uploadConfig?.accessToken || !uploadConfig?.apiBasePath) return;
|
|
2465
|
+
try {
|
|
2466
|
+
const cached = await loadUserUploads();
|
|
2467
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
2468
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2469
|
+
});
|
|
2470
|
+
const merged = mergeRemoteUploadList(cached, remoteFiles, {
|
|
2471
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2472
|
+
apiHydrationSucceeded: true,
|
|
2473
|
+
});
|
|
2474
|
+
await replacePersistedUploads(merged);
|
|
2475
|
+
const root = await createUserUploadsFileSystemRoot(merged, $t('library.defaultLabel'));
|
|
2476
|
+
data = root;
|
|
2477
|
+
init();
|
|
2478
|
+
} catch (refreshError) {
|
|
2479
|
+
console.warn('[FileBrowser] Upload list refresh failed:', refreshError);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2294
2483
|
function handleFileBrowserCommand(event: Event) {
|
|
2295
2484
|
const detail = (event as CustomEvent).detail;
|
|
2296
|
-
if (!detail
|
|
2485
|
+
if (!detail) return;
|
|
2486
|
+
if (detail.instanceId && detail.instanceId !== instanceId && detail.instanceId !== '*') return;
|
|
2297
2487
|
if (detail.command === 'back') handleNavigateBack();
|
|
2298
2488
|
else if (detail.command === 'forward') handleNavigateForward();
|
|
2299
2489
|
else if (detail.command === 'index') {
|
|
2300
2490
|
navigateToBreadcrumb({ detail: detail.index } as CustomEvent<number>);
|
|
2301
2491
|
} else if (detail.command === 'publish') {
|
|
2302
2492
|
publishFileBrowserNav();
|
|
2493
|
+
} else if (detail.command === 'remove-upload' && typeof detail.uploadId === 'string') {
|
|
2494
|
+
void evictGoneUploads([detail.uploadId]);
|
|
2495
|
+
} else if (detail.command === 'refresh-uploads') {
|
|
2496
|
+
void refreshUploadsFromApi();
|
|
2497
|
+
} else if (detail.command === 'reload-demo-tree') {
|
|
2498
|
+
reloadDemoFromStorage();
|
|
2303
2499
|
}
|
|
2304
2500
|
}
|
|
2305
2501
|
|
|
@@ -2809,7 +3005,9 @@ mainGridClass="app-main-grid"
|
|
|
2809
3005
|
<div
|
|
2810
3006
|
bind:this={mainContainer}
|
|
2811
3007
|
bind:clientWidth={mainContainerWidth}
|
|
2812
|
-
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
|
+
: ''} {
|
|
2813
3011
|
dragActive
|
|
2814
3012
|
? (dragInvalid
|
|
2815
3013
|
? 'ring-1 ring-destructive/30'
|
|
@@ -2846,6 +3044,8 @@ mainGridClass="app-main-grid"
|
|
|
2846
3044
|
canGoForward={$canGoForwardStore}
|
|
2847
3045
|
on:toggleSelectedFiles={(e : CustomEvent) => allowSelecting && toggleModal()}
|
|
2848
3046
|
showBreadcrumbs={showBreadcrumbs && !libraryMode}
|
|
3047
|
+
enableFolderDropTargets={libraryCapabilities.folders && allowSelecting}
|
|
3048
|
+
rootDropTargetId={$fileStore.root?.id ?? 'root'}
|
|
2849
3049
|
title={libraryMode ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel')) : ''}
|
|
2850
3050
|
/>
|
|
2851
3051
|
|
|
@@ -3082,7 +3282,7 @@ mainGridClass="app-main-grid"
|
|
|
3082
3282
|
<!-- Item content -->
|
|
3083
3283
|
<div
|
|
3084
3284
|
data-item-id={item.id}
|
|
3085
|
-
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"
|
|
3086
3286
|
data-selected={allowSelecting && currentSelections.some(f => f.id === item.id) ? 'true' : undefined}
|
|
3087
3287
|
>
|
|
3088
3288
|
{#if item.type === 'new-folder'}
|
|
@@ -3241,6 +3441,7 @@ mainGridClass="app-main-grid"
|
|
|
3241
3441
|
target={rootContainerClass}
|
|
3242
3442
|
on:select={(event : any) => handleFileSelect(event.detail)}
|
|
3243
3443
|
on:navigate={handlePreviewNavigate}
|
|
3444
|
+
on:fileUnavailable={(event) => void evictGoneUploads([event.detail.id])}
|
|
3244
3445
|
/>
|
|
3245
3446
|
{/if}
|
|
3246
3447
|
|
|
@@ -3378,6 +3579,8 @@ mainGridClass="app-main-grid"
|
|
|
3378
3579
|
/>
|
|
3379
3580
|
{/if}
|
|
3380
3581
|
|
|
3582
|
+
<DragGhostStack snapshot={selectedDragSnapshot} />
|
|
3583
|
+
|
|
3381
3584
|
<!-- POP-UPS (only for an app that has no toaster of its own) -->
|
|
3382
3585
|
{#if renderToaster}
|
|
3383
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
|
>
|