@widgetic/file-browser 0.5.46 → 0.5.48

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.
Files changed (104) hide show
  1. package/dist/actions/dragSelectedToFolder.js +104 -115
  2. package/dist/components/FolderTree.svelte.d.ts +2 -6
  3. package/dist/components/core/Dropzone.svelte +42 -2
  4. package/dist/components/core/FileBrowser.svelte +249 -32
  5. package/dist/components/core/FileUploader.svelte +134 -54
  6. package/dist/components/core/RecentFiles.svelte +74 -19
  7. package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
  8. package/dist/components/core/SearchDropdown.svelte +6 -8
  9. package/dist/components/core/UploadPanel.svelte +7 -0
  10. package/dist/components/core/UploadPanel.svelte.d.ts +4 -0
  11. package/dist/components/core/UploadRow.svelte +9 -4
  12. package/dist/components/core/UploadRow.svelte.d.ts +2 -0
  13. package/dist/components/core/dropzoneClick.d.ts +28 -0
  14. package/dist/components/core/dropzoneClick.js +32 -0
  15. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  16. package/dist/components/ui/DropdownMenu.svelte +1 -1
  17. package/dist/config.js +4 -3
  18. package/dist/i18n/context.js +2 -2
  19. package/dist/i18n/errors.js +2 -1
  20. package/dist/i18n/messages.d.ts +15 -1
  21. package/dist/i18n/messages.js +17 -3
  22. package/dist/i18n/text.js +2 -2
  23. package/dist/mediaLibrary/capabilities.js +4 -3
  24. package/dist/mediaLibrary/context.js +4 -3
  25. package/dist/mediaLibrary/errors.js +46 -35
  26. package/dist/mediaLibrary/normalize.js +45 -42
  27. package/dist/mediaLibrary/paging.js +100 -45
  28. package/dist/mediaLibrary/resolve.js +214 -95
  29. package/dist/mediaLibrary/treeOps.js +40 -20
  30. package/dist/mediaLibrary/urls.js +12 -10
  31. package/dist/mediaLibrary/widgetic.js +140 -54
  32. package/dist/stores/dragStore.js +1 -1
  33. package/dist/stores/fileStore.d.ts +1 -1
  34. package/dist/stores/fileStore.js +44 -37
  35. package/dist/stores/folderCountStore.js +12 -11
  36. package/dist/stores/missingFilesStore.js +3 -3
  37. package/dist/stores/navigationStore.d.ts +1 -1
  38. package/dist/stores/navigationStore.js +217 -178
  39. package/dist/stores/persistentSelectStore.d.ts +1 -1
  40. package/dist/stores/persistentSelectStore.js +117 -94
  41. package/dist/stores/searchStore.js +1 -1
  42. package/dist/stores/uploadApiStore.d.ts +10 -0
  43. package/dist/stores/uploadApiStore.js +7 -7
  44. package/dist/stores/viewportStore.js +4 -4
  45. package/dist/types/index.js +0 -1
  46. package/dist/utils/apiConfig.js +9 -9
  47. package/dist/utils/brandKitLibraryTree.js +57 -42
  48. package/dist/utils/dateUtils.js +11 -9
  49. package/dist/utils/deleteSelectionAction.d.ts +26 -0
  50. package/dist/utils/deleteSelectionAction.js +23 -0
  51. package/dist/utils/dragToFolder/batchMoveResult.js +114 -54
  52. package/dist/utils/dragToFolder/folderDropTarget.js +23 -17
  53. package/dist/utils/dragToFolder/springStep.js +4 -3
  54. package/dist/utils/fileGoneProbe.js +65 -16
  55. package/dist/utils/fileKinds.js +14 -13
  56. package/dist/utils/fileNames.js +7 -7
  57. package/dist/utils/fileOperations.js +440 -333
  58. package/dist/utils/fileTypes.js +19 -14
  59. package/dist/utils/fileUtils.js +85 -31
  60. package/dist/utils/folderUtils.js +5 -4
  61. package/dist/utils/gridLayout.js +7 -7
  62. package/dist/utils/imagePreviewCache.js +26 -15
  63. package/dist/utils/imagePreviewFrame.js +13 -13
  64. package/dist/utils/imagePreviewVisualState.js +5 -4
  65. package/dist/utils/imageTransform.js +27 -14
  66. package/dist/utils/itemMenuCapabilities.js +7 -7
  67. package/dist/utils/libraryTree.js +55 -39
  68. package/dist/utils/pendingUploadDeletes.d.ts +102 -0
  69. package/dist/utils/pendingUploadDeletes.js +400 -0
  70. package/dist/utils/previewKeys.js +1 -1
  71. package/dist/utils/previewListNavigation.js +13 -11
  72. package/dist/utils/previewNavigation.js +10 -7
  73. package/dist/utils/recentFiles.js +16 -6
  74. package/dist/utils/recentFilesLimit.js +2 -2
  75. package/dist/utils/removeItems.d.ts +30 -0
  76. package/dist/utils/removeItems.js +124 -0
  77. package/dist/utils/resolveFileUrl.js +6 -6
  78. package/dist/utils/safeText.js +14 -12
  79. package/dist/utils/searchDropdownPhase.d.ts +14 -3
  80. package/dist/utils/searchDropdownPhase.js +13 -9
  81. package/dist/utils/searchItems.js +30 -14
  82. package/dist/utils/searchNavigation.js +5 -5
  83. package/dist/utils/uploadAuth.d.ts +24 -0
  84. package/dist/utils/uploadAuth.js +140 -0
  85. package/dist/utils/uploadDisplayProgress.js +1 -1
  86. package/dist/utils/uploadLimits.d.ts +76 -0
  87. package/dist/utils/uploadLimits.js +242 -0
  88. package/dist/utils/uploadListReconcile.js +24 -11
  89. package/dist/utils/uploadPanelDismiss.d.ts +13 -0
  90. package/dist/utils/uploadPanelDismiss.js +11 -0
  91. package/dist/utils/uploadPanelProgress.js +4 -4
  92. package/dist/utils/uploadProgressMath.js +13 -11
  93. package/dist/utils/uploadRefusals.d.ts +42 -0
  94. package/dist/utils/uploadRefusals.js +86 -0
  95. package/dist/utils/uploadResponseMapping.js +9 -8
  96. package/dist/utils/uploadUiHelpers.js +17 -17
  97. package/dist/utils/userUploadsStorage.js +270 -133
  98. package/dist/utils/videoFrame.d.ts +23 -0
  99. package/dist/utils/videoFrame.js +26 -0
  100. package/dist/utils/widgeticDelete.js +103 -28
  101. package/dist/utils/widgeticTusUpload.js +189 -105
  102. package/dist/utils/widgeticUpload.js +133 -59
  103. package/dist/utils/xhrMultipartUpload.js +164 -116
  104. package/package.json +3 -3
@@ -79,8 +79,8 @@
79
79
  import { getFileTypeOf } from '../../utils/fileKinds';
80
80
  import { getFolderIcon } from '../../utils/folderUtils';
81
81
  import { type FileFilterType, FILTER_OPTIONS, getAllowedFileTypes, FILE_TYPES, formatFileTypesForDisplay } from '../../utils/fileTypes';
82
- import { getPathNamesFromIds, deleteItem, renameItem, moveItem, findItemById } from '../../utils/fileOperations';
83
- import { getFileBrowserUploadConfig, setFileBrowserUploadConfig } from '../../stores/uploadApiStore';
82
+ import { getPathNamesFromIds, renameItem, moveItem, findItemById } from '../../utils/fileOperations';
83
+ import { getFileBrowserUploadConfig, setFileBrowserUploadConfig, type FileBrowserUploadConfig } from '../../stores/uploadApiStore';
84
84
  import {
85
85
  loadUserUploads,
86
86
  removePersistedUploads,
@@ -139,6 +139,15 @@
139
139
  import type { MediaLibraryErrorCode, MediaLibraryProvider } from '../../mediaLibrary/types';
140
140
  import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
141
141
  import { escapeSelectionAction } from '../../utils/escapeSelectionAction';
142
+ import { deleteSelectionAction } from '../../utils/deleteSelectionAction';
143
+ import { filesOfItems, putItemsBackInTree, removeItemsFromTree, type RemovedItem } from '../../utils/removeItems';
144
+ import {
145
+ classifyDeleteStatus,
146
+ getPendingUploadDeleteQueue,
147
+ type DeleteProcessor,
148
+ type PendingUploadDelete,
149
+ } from '../../utils/pendingUploadDeletes';
150
+ import { deleteUploadFromWidgeticApi } from '../../utils/widgeticDelete';
142
151
  import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
143
152
  import DragGhostStack from '../drag/DragGhostStack.svelte';
144
153
  import {
@@ -675,7 +684,7 @@
675
684
  }
676
685
 
677
686
  /**
678
- * Renames a file in the host's library and then in the list: the list changes only after the library said yes.
687
+ * Renames a file in the list at once and in the host's library right after; the old name comes back when the library refuses.
679
688
  * Resolves `false` when there was nothing to change; throws a MediaLibraryError when the library refuses.
680
689
  */
681
690
  async function renameInLibrary(itemId: string, newName: string): Promise<boolean> {
@@ -690,15 +699,31 @@
690
699
  const finalName = item.type === 'file' ? getRenamedFileName(item.name, typedName) : typedName;
691
700
  if (finalName === item.name) return false;
692
701
 
693
- const renamedFile = await library.rename({ id: itemId, name: finalName, signal: libraryActionsController.signal });
694
- // The File Browser was closed while the library was working: its list is no longer ours to change.
702
+ // The list shows the new name at once (the Recent files strip follows it, being built from the same list); the library is told
703
+ // in the same breath, and when it refuses the old name is put back.
704
+ const renamedLocally: FileSystemItem = { ...item, name: finalName, modified: new Date().toISOString() };
705
+ fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, renamedLocally) }));
706
+ selectedFiles.update((files) => files.map((file) => (file.id === itemId ? renamedLocally : file)));
707
+
708
+ let renamedFile: FileSystemItem | void;
709
+ try {
710
+ renamedFile = await library.rename({ id: itemId, name: finalName, signal: libraryActionsController.signal });
711
+ } catch (renameError) {
712
+ // The File Browser was closed while the library was working: its list is no longer ours to change.
713
+ if (!libraryActionsController.signal.aborted) {
714
+ fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, item) }));
715
+ selectedFiles.update((files) => files.map((file) => (file.id === itemId ? item : file)));
716
+ }
717
+ throw renameError;
718
+ }
695
719
  if (libraryActionsController.signal.aborted) return false;
696
720
 
697
721
  // The library may answer with the file as it is now (it can change the address or the id). When it only says
698
- // "done", the file stays as it was and takes the new name.
699
- const updatedFile: FileSystemItem = renamedFile ?? { ...item, name: finalName, modified: new Date().toISOString() };
700
- fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, updatedFile) }));
701
- selectedFiles.update((files) => files.map((file) => (file.id === itemId ? updatedFile : file)));
722
+ // "done", the file keeps the name it already shows.
723
+ if (renamedFile) {
724
+ fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, renamedFile as FileSystemItem) }));
725
+ selectedFiles.update((files) => files.map((file) => (file.id === itemId ? (renamedFile as FileSystemItem) : file)));
726
+ }
702
727
  return true;
703
728
  }
704
729
 
@@ -843,6 +868,8 @@
843
868
  listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
844
869
  apiHydrationSucceeded: true,
845
870
  });
871
+ // What the visitor deleted and the API has not confirmed yet stays off the list
872
+ files = await withoutPendingDeletes(files);
846
873
  await replacePersistedUploads(files);
847
874
  data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
848
875
  basePath = '';
@@ -860,6 +887,8 @@
860
887
  data = await createUserUploadsFileSystemRoot(files, $t('library.defaultLabel'));
861
888
  basePath = '';
862
889
  }
890
+ // Deletes an earlier visit did not finish (the files left the screen then, the API was not told)
891
+ resumePendingDeletes();
863
892
  if (showLogs) {
864
893
  // console.log('[FileBrowser] Widgetic library mode — user uploads only');
865
894
  }
@@ -1643,9 +1672,7 @@
1643
1672
 
1644
1673
  // Store the item's ID before resetting selection
1645
1674
  const itemId = selectedItem.id;
1646
- const oldName = selectedItem.name;
1647
- // The name the item ends up with: the dialog edits a file without its extension, which is always kept
1648
- const finalName = selectedItem.type === 'file' ? getRenamedFileName(selectedItem.name, newName.trim()) : newName.trim();
1675
+ const renamedKind = selectedItem.type;
1649
1676
 
1650
1677
  // Close the dialog and reset selection immediately to prevent UI blocking
1651
1678
  showRenameDialog = false;
@@ -1653,12 +1680,6 @@
1653
1680
 
1654
1681
  // console.log('call showToast method:', showToast);
1655
1682
 
1656
- // Show initial toast notification
1657
- showToast('success', $t('toast.rename.started', { name: oldName }), {
1658
- description: $t('toast.inBackground'),
1659
- // duration: 1500
1660
- });
1661
-
1662
1683
  // Perform the rename operation (through the host's media library when there is one)
1663
1684
  (libraryMode ? renameInLibrary(itemId, newName) : renameItem(itemId, newName))
1664
1685
  .then(success => {
@@ -1667,9 +1688,9 @@
1667
1688
  if (success) {
1668
1689
  // The new name is part of the saved tree of the Widgetic library
1669
1690
  persistMyUploadsTree();
1670
- showToast('success', $t('toast.rename.done'), {
1671
- description: $t('toast.rename.doneDetail', { oldName, newName: finalName }),
1672
- });
1691
+ // Just the fact, with nothing about the background: the new name is already on the screen.
1692
+ if (renamedKind === 'folder') showToast('success', $t('toast.rename.folderDone'));
1693
+ else showToast('success', $t('toast.rename.done'));
1673
1694
  } else {
1674
1695
  showToast('error', $t('toast.rename.failed'), {
1675
1696
  description: $t('toast.rename.noChange'),
@@ -1715,6 +1736,13 @@
1715
1736
  selectedItem = null;
1716
1737
  itemsPendingDeletion = [];
1717
1738
  showDeleteConfirmation = false;
1739
+
1740
+ // The Widgetic library (and the demo content) never makes the visitor wait: everything chosen leaves the screen in
1741
+ // one step, and the API is told in the background. A host's media library keeps its own, slower way below.
1742
+ if (!libraryMode) {
1743
+ deleteInTheBackground(itemsToDelete);
1744
+ return;
1745
+ }
1718
1746
 
1719
1747
  // Show initial toast notification
1720
1748
  const initialToastMessage = $t('toast.delete.started', {
@@ -1738,7 +1766,7 @@
1738
1766
  // Process each item for deletion
1739
1767
  for (const item of itemsToDelete) {
1740
1768
  try {
1741
- const success = libraryMode ? await deleteFromLibrary(item) : await deleteItem(item.id);
1769
+ const success = await deleteFromLibrary(item);
1742
1770
  if (success) {
1743
1771
  successCount++;
1744
1772
  deletedItems.push(item.name);
@@ -1821,6 +1849,166 @@
1821
1849
  }, 100); // Small delay to ensure UI updates first
1822
1850
  }
1823
1851
 
1852
+ /**
1853
+ * Opens the delete dialog for everything that is selected: what the Delete button of the selection bar does, and what
1854
+ * the Delete key does when files are selected.
1855
+ */
1856
+ function openDeleteDialogForSelection() {
1857
+ selectedItem = null;
1858
+ // The selection bar acts on everything selected
1859
+ itemsPendingDeletion = [...allSelectedFiles];
1860
+ showDeleteConfirmation = true;
1861
+ }
1862
+
1863
+ // What is needed to put an upload back if the API refuses to delete it: where it sat, by upload id. It is kept while this
1864
+ // File Browser lives; after a reload the next list from the API shows the file again, which comes to the same thing.
1865
+ const takenOffScreen = new Map<string, RemovedItem>();
1866
+ // The uploads the API refused, gathered for a moment so that one toast tells about all of them.
1867
+ let refusedDeleteNames: string[] = [];
1868
+ let refusedDeleteTimer: ReturnType<typeof setTimeout> | null = null;
1869
+
1870
+ /**
1871
+ * Deletes without making the visitor wait (the Widgetic library and the demo content). Every file and folder chosen leaves
1872
+ * the screen in one step and the toast says so. The API is told afterwards, through a queue that is written down in Dexie
1873
+ * first (see pendingUploadDeletes.ts), so a reload or a bad network neither brings the files back nor loses the delete.
1874
+ * When the API refuses for good, the file is put back and the visitor is told.
1875
+ */
1876
+ function deleteInTheBackground(itemsToDelete: FileSystemItem[]) {
1877
+ try {
1878
+ let removedEntries: RemovedItem[] = [];
1879
+ fileStore.update((store) => {
1880
+ const result = removeItemsFromTree(store.root, new Set(itemsToDelete.map((item) => item.id)));
1881
+ removedEntries = result.removed;
1882
+ return { ...store, root: result.root };
1883
+ });
1884
+
1885
+ const removedFiles = filesOfItems(removedEntries.map((entry) => entry.item));
1886
+ const removedFileIds = new Set(removedFiles.map((file) => file.id));
1887
+
1888
+ // Nothing that was removed stays selected, previewed or listed in the local copy
1889
+ removedFileIds.forEach((fileId) => persistentSelectStore.removeSelection(fileId, filter));
1890
+ selectedFiles.update((files) => files.filter((file) => !removedFileIds.has(file.id)));
1891
+ if (previewFile && removedFileIds.has(previewFile.id)) previewFile = null;
1892
+ for (const entry of removedEntries) {
1893
+ if (entry.item.type === 'folder') {
1894
+ // The folder is gone: the view goes back to the root, as it always did after a folder was deleted
1895
+ navigationStore.cleanupPaths(entry.item.id);
1896
+ currentFolder.set([]);
1897
+ currentPath = [];
1898
+ }
1899
+ }
1900
+ persistMyUploadsTree();
1901
+ void removePersistedUploads([...removedFileIds]);
1902
+
1903
+ // The visitor's answer is the screen: just the fact, with nothing about the background
1904
+ if (itemsToDelete.length === 1) {
1905
+ const [onlyItem] = itemsToDelete;
1906
+ showToast(
1907
+ 'success',
1908
+ onlyItem.type === 'folder'
1909
+ ? $t('toast.delete.doneFolder', { name: onlyItem.name })
1910
+ : $t('toast.delete.doneFile', { name: onlyItem.name }),
1911
+ );
1912
+ } else {
1913
+ showToast('success', $t('toast.delete.doneMany', { count: itemsToDelete.length }));
1914
+ }
1915
+
1916
+ // The API: only the Widgetic library has one (the demo content has nobody to tell)
1917
+ const uploadConfig = getFileBrowserUploadConfig();
1918
+ if (!uploadConfig?.accessToken || !uploadConfig.apiBasePath || removedFiles.length === 0) return;
1919
+
1920
+ // Where each upload goes back to if it must: a file that was chosen, where it sat; a file of a folder, the root
1921
+ for (const entry of removedEntries) {
1922
+ if (entry.item.type === 'file') {
1923
+ takenOffScreen.set(entry.item.id, entry);
1924
+ } else {
1925
+ for (const file of filesOfItems([entry.item])) takenOffScreen.set(file.id, { item: file, parentId: null, index: 0 });
1926
+ }
1927
+ }
1928
+ void getPendingUploadDeleteQueue()
1929
+ .enqueue(removedFiles.map((file) => ({ uploadId: file.id, name: file.name })))
1930
+ .then(() => startPendingDeletes(uploadConfig));
1931
+ } catch (error) {
1932
+ console.error('Error deleting items:', error);
1933
+ showToast('error', $t('toast.delete.failedAll'), {
1934
+ description: messageForVisitor(error, $t, 'toast.unknownError'),
1935
+ });
1936
+ }
1937
+ }
1938
+
1939
+ /** How the API is asked to delete one upload: with the settings of the page, and a renewed session when it comes to that. */
1940
+ function deleteProcessorFor(uploadConfig: FileBrowserUploadConfig): DeleteProcessor {
1941
+ return async (record) => {
1942
+ try {
1943
+ await deleteUploadFromWidgeticApi(uploadConfig, record.uploadId);
1944
+ return { result: 'ok' };
1945
+ } catch (error) {
1946
+ const status = error instanceof MediaLibraryError ? error.status : undefined;
1947
+ const message = error instanceof Error ? error.message : String(error);
1948
+ const verdict = classifyDeleteStatus(status);
1949
+ return verdict === 'ok' ? { result: 'ok' } : { result: verdict, message };
1950
+ }
1951
+ };
1952
+ }
1953
+
1954
+ /** Sends the deletes that are written down: the ones just chosen, and the ones an earlier visit did not finish. */
1955
+ function startPendingDeletes(uploadConfig: FileBrowserUploadConfig) {
1956
+ void getPendingUploadDeleteQueue().drain(deleteProcessorFor(uploadConfig), {
1957
+ onDeleted: (record) => {
1958
+ takenOffScreen.delete(record.uploadId);
1959
+ },
1960
+ onGaveUp: (record, message) => putBackRefusedUpload(record, message),
1961
+ });
1962
+ }
1963
+
1964
+ /** Finishes the deletes an earlier visit left in the queue: the files were taken off the screen then, the API was not told. */
1965
+ function resumePendingDeletes() {
1966
+ const uploadConfig = getFileBrowserUploadConfig();
1967
+ if (libraryMode || !uploadConfig?.accessToken || !uploadConfig.apiBasePath) return;
1968
+ startPendingDeletes(uploadConfig);
1969
+ }
1970
+
1971
+ /** The API refused for good (or could not be reached for a long time): the file is still in the library, so it comes back. */
1972
+ function putBackRefusedUpload(record: PendingUploadDelete, message: string) {
1973
+ const entry = takenOffScreen.get(record.uploadId);
1974
+ takenOffScreen.delete(record.uploadId);
1975
+ if (entry) {
1976
+ fileStore.update((store) => ({ ...store, root: putItemsBackInTree(store.root, [entry]) }));
1977
+ saveUserUploadsBatch([entry.item]);
1978
+ persistMyUploadsTree();
1979
+ } else {
1980
+ // This visit never took it off the screen (a reload came in between): the list from the API has it
1981
+ void refreshUploadsFromApi();
1982
+ }
1983
+
1984
+ refusedDeleteNames.push(record.name);
1985
+ if (refusedDeleteTimer) clearTimeout(refusedDeleteTimer);
1986
+ refusedDeleteTimer = setTimeout(() => {
1987
+ const names = refusedDeleteNames;
1988
+ refusedDeleteNames = [];
1989
+ refusedDeleteTimer = null;
1990
+ showToast(
1991
+ 'error',
1992
+ names.length === 1
1993
+ ? $t('toast.delete.failedOne', { name: names[0] })
1994
+ : $t('toast.delete.failedMany', { count: names.length }),
1995
+ { description: $t('toast.delete.putBack', { count: names.length }) },
1996
+ );
1997
+ }, 400);
1998
+ if (showLogs) console.log(`[FileBrowser] ${record.name} put back: ${message}`);
1999
+ }
2000
+
2001
+ /** Uploads whose delete is waiting in the queue are not listed: they were taken off the screen, and the API catches up. */
2002
+ async function withoutPendingDeletes(files: FileSystemItem[]): Promise<FileSystemItem[]> {
2003
+ try {
2004
+ const pendingIds = await getPendingUploadDeleteQueue().pendingIds();
2005
+ return pendingIds.size === 0 ? files : files.filter((file) => !pendingIds.has(file.id));
2006
+ } catch (error) {
2007
+ console.warn('[FileBrowser] Could not read the queue of deletes:', error);
2008
+ return files;
2009
+ }
2010
+ }
2011
+
1824
2012
  function isWidgeticLibraryMode(): boolean {
1825
2013
  const uploadConfig = getFileBrowserUploadConfig();
1826
2014
  return Boolean(uploadConfig?.accessToken && uploadConfig?.apiBasePath) || !useDemoContent;
@@ -2059,6 +2247,37 @@
2059
2247
  // modalOpen: $isModalOpen
2060
2248
  // });
2061
2249
 
2250
+ // Delete (or Backspace, which a Mac keyboard labels "delete") with files selected opens the same delete dialog as the
2251
+ // Delete button of the selection bar. It comes before the Backspace handler below, which goes back one folder when
2252
+ // nothing is selected.
2253
+ if (
2254
+ deleteSelectionAction({
2255
+ key: event.key,
2256
+ altKey: event.altKey,
2257
+ shiftKey: event.shiftKey,
2258
+ defaultPrevented: event.defaultPrevented,
2259
+ allowSelecting,
2260
+ canDelete: libraryCapabilities.delete,
2261
+ selectionCount: allSelectedFiles.length,
2262
+ previewOpen: !!previewFile,
2263
+ designSystemModalOpen: $isModalOpen,
2264
+ inputFocused: !!isInputFocused(event),
2265
+ innerUiOpen:
2266
+ filterDropdownOpen ||
2267
+ sortDropdownOpen ||
2268
+ showModal ||
2269
+ showRenameDialog ||
2270
+ showNewFolderDialog ||
2271
+ showMoveDialog ||
2272
+ showDeleteConfirmation,
2273
+ }) === 'open-delete-dialog'
2274
+ ) {
2275
+ event.preventDefault();
2276
+ event.stopPropagation();
2277
+ openDeleteDialogForSelection();
2278
+ return;
2279
+ }
2280
+
2062
2281
  // Backspace key handler
2063
2282
  if (event.key === 'Backspace' && currentPath.length > 0 && !isInputFocused(event) && !$isModalOpen) {
2064
2283
  event.preventDefault();
@@ -2501,10 +2720,12 @@
2501
2720
  const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
2502
2721
  limit: WIDGETIC_UPLOADS_LIST_LIMIT,
2503
2722
  });
2504
- const merged = mergeRemoteUploadList(cached, remoteFiles, {
2505
- listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
2506
- apiHydrationSucceeded: true,
2507
- });
2723
+ const merged = await withoutPendingDeletes(
2724
+ mergeRemoteUploadList(cached, remoteFiles, {
2725
+ listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
2726
+ apiHydrationSucceeded: true,
2727
+ }),
2728
+ );
2508
2729
  await replacePersistedUploads(merged);
2509
2730
  const root = await createUserUploadsFileSystemRoot(merged, $t('library.defaultLabel'));
2510
2731
  data = root;
@@ -3297,6 +3518,7 @@ mainGridClass="app-main-grid"
3297
3518
  on:fileClick={handleRecentFileClick}
3298
3519
  on:select={handleRecentFileSelect}
3299
3520
  on:action={handleRecentFileAction}
3521
+ on:delete={handleDelete}
3300
3522
  />
3301
3523
  {/if}
3302
3524
 
@@ -3355,12 +3577,7 @@ mainGridClass="app-main-grid"
3355
3577
  compact={isCompactLayout}
3356
3578
  on:send={sendToEditor}
3357
3579
  on:move={(e : any) => handleItemAction(new CustomEvent('action', { detail: { action: 'move', item: e.detail.items[0] } }))}
3358
- on:delete={(e : any) => {
3359
- selectedItem = null;
3360
- // The selection bar acts on everything selected
3361
- itemsPendingDeletion = [...allSelectedFiles];
3362
- showDeleteConfirmation = true;
3363
- }}
3580
+ on:delete={openDeleteDialogForSelection}
3364
3581
  on:rename={(e : any) => handleItemAction(new CustomEvent('action', { detail: { action: 'rename', item: e.detail.item } }))}
3365
3582
  />
3366
3583
  </div>