@widgetic/file-browser 0.5.46 → 0.5.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/FolderTree.svelte.d.ts +1 -2
- package/dist/components/core/FileBrowser.svelte +29 -22
- package/dist/components/core/FileUploader.svelte +10 -13
- package/dist/components/core/RecentFiles.svelte +20 -3
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/i18n/messages.d.ts +2 -1
- package/dist/i18n/messages.js +2 -1
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/utils/fileOperations.js +2 -3
- package/dist/utils/uploadPanelDismiss.d.ts +13 -0
- package/dist/utils/uploadPanelDismiss.js +11 -0
- package/package.json +1 -1
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Mirrors Figma "Folder Row" (274:1480) with 32px level indent and a 2px start guide line.
|
|
4
4
|
*/
|
|
5
5
|
import type { FileSystemItem } from '../types';
|
|
6
|
-
import { IconArrowBounce } from '@widgetic/design-system/icons';
|
|
7
6
|
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> {
|
|
8
7
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
9
8
|
$$bindings?: Bindings;
|
|
@@ -32,7 +31,7 @@ declare const FolderTree: $$__sveltets_2_IsomorphicComponent<{
|
|
|
32
31
|
textClass?: string;
|
|
33
32
|
selectedIconClass?: string;
|
|
34
33
|
currentLocationClass?: string;
|
|
35
|
-
selectedIcon?:
|
|
34
|
+
selectedIcon?: any;
|
|
36
35
|
}, {
|
|
37
36
|
[evt: string]: CustomEvent<any>;
|
|
38
37
|
}, {}, {}, string>;
|
|
@@ -675,7 +675,7 @@
|
|
|
675
675
|
}
|
|
676
676
|
|
|
677
677
|
/**
|
|
678
|
-
* Renames a file in the host's library
|
|
678
|
+
* 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
679
|
* Resolves `false` when there was nothing to change; throws a MediaLibraryError when the library refuses.
|
|
680
680
|
*/
|
|
681
681
|
async function renameInLibrary(itemId: string, newName: string): Promise<boolean> {
|
|
@@ -690,15 +690,31 @@
|
|
|
690
690
|
const finalName = item.type === 'file' ? getRenamedFileName(item.name, typedName) : typedName;
|
|
691
691
|
if (finalName === item.name) return false;
|
|
692
692
|
|
|
693
|
-
|
|
694
|
-
//
|
|
693
|
+
// The list shows the new name at once (the Recent files strip follows it, being built from the same list); the library is told
|
|
694
|
+
// in the same breath, and when it refuses the old name is put back.
|
|
695
|
+
const renamedLocally: FileSystemItem = { ...item, name: finalName, modified: new Date().toISOString() };
|
|
696
|
+
fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, renamedLocally) }));
|
|
697
|
+
selectedFiles.update((files) => files.map((file) => (file.id === itemId ? renamedLocally : file)));
|
|
698
|
+
|
|
699
|
+
let renamedFile: FileSystemItem | void;
|
|
700
|
+
try {
|
|
701
|
+
renamedFile = await library.rename({ id: itemId, name: finalName, signal: libraryActionsController.signal });
|
|
702
|
+
} catch (renameError) {
|
|
703
|
+
// The File Browser was closed while the library was working: its list is no longer ours to change.
|
|
704
|
+
if (!libraryActionsController.signal.aborted) {
|
|
705
|
+
fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, item) }));
|
|
706
|
+
selectedFiles.update((files) => files.map((file) => (file.id === itemId ? item : file)));
|
|
707
|
+
}
|
|
708
|
+
throw renameError;
|
|
709
|
+
}
|
|
695
710
|
if (libraryActionsController.signal.aborted) return false;
|
|
696
711
|
|
|
697
712
|
// 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
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
713
|
+
// "done", the file keeps the name it already shows.
|
|
714
|
+
if (renamedFile) {
|
|
715
|
+
fileStore.update((store) => ({ ...store, root: replaceFile(store.root, itemId, renamedFile as FileSystemItem) }));
|
|
716
|
+
selectedFiles.update((files) => files.map((file) => (file.id === itemId ? (renamedFile as FileSystemItem) : file)));
|
|
717
|
+
}
|
|
702
718
|
return true;
|
|
703
719
|
}
|
|
704
720
|
|
|
@@ -787,9 +803,7 @@
|
|
|
787
803
|
const token = session?.accessToken || session?.access_token;
|
|
788
804
|
if (token) {
|
|
789
805
|
// Scope Dexie only — do not invent an empty apiBasePath upload config.
|
|
790
|
-
const { ensureCacheOwnerFromSessionHint, setCacheOwner } = await import(
|
|
791
|
-
'@widgetic/cache-layer'
|
|
792
|
-
);
|
|
806
|
+
const { ensureCacheOwnerFromSessionHint, setCacheOwner } = await import('@widgetic/cache-layer');
|
|
793
807
|
ensureCacheOwnerFromSessionHint();
|
|
794
808
|
const payloadPart = token.split('.')[1];
|
|
795
809
|
if (payloadPart) {
|
|
@@ -1643,9 +1657,7 @@
|
|
|
1643
1657
|
|
|
1644
1658
|
// Store the item's ID before resetting selection
|
|
1645
1659
|
const itemId = selectedItem.id;
|
|
1646
|
-
const
|
|
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();
|
|
1660
|
+
const renamedKind = selectedItem.type;
|
|
1649
1661
|
|
|
1650
1662
|
// Close the dialog and reset selection immediately to prevent UI blocking
|
|
1651
1663
|
showRenameDialog = false;
|
|
@@ -1653,12 +1665,6 @@
|
|
|
1653
1665
|
|
|
1654
1666
|
// console.log('call showToast method:', showToast);
|
|
1655
1667
|
|
|
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
1668
|
// Perform the rename operation (through the host's media library when there is one)
|
|
1663
1669
|
(libraryMode ? renameInLibrary(itemId, newName) : renameItem(itemId, newName))
|
|
1664
1670
|
.then(success => {
|
|
@@ -1667,9 +1673,9 @@
|
|
|
1667
1673
|
if (success) {
|
|
1668
1674
|
// The new name is part of the saved tree of the Widgetic library
|
|
1669
1675
|
persistMyUploadsTree();
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1676
|
+
// Just the fact, with nothing about the background: the new name is already on the screen.
|
|
1677
|
+
if (renamedKind === 'folder') showToast('success', $t('toast.rename.folderDone'));
|
|
1678
|
+
else showToast('success', $t('toast.rename.done'));
|
|
1673
1679
|
} else {
|
|
1674
1680
|
showToast('error', $t('toast.rename.failed'), {
|
|
1675
1681
|
description: $t('toast.rename.noChange'),
|
|
@@ -3297,6 +3303,7 @@ mainGridClass="app-main-grid"
|
|
|
3297
3303
|
on:fileClick={handleRecentFileClick}
|
|
3298
3304
|
on:select={handleRecentFileSelect}
|
|
3299
3305
|
on:action={handleRecentFileAction}
|
|
3306
|
+
on:delete={handleDelete}
|
|
3300
3307
|
/>
|
|
3301
3308
|
{/if}
|
|
3302
3309
|
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
import { buildActiveRowStatusText, formatUploadPercent, type UploadPhase, updateThroughputEstimateState } from '../../utils/uploadUiHelpers';
|
|
42
42
|
import { monotonicDisplayProgress } from '../../utils/uploadDisplayProgress';
|
|
43
43
|
import { monotonicPanelProgress, nextUploadPanelPeak } from '../../utils/uploadPanelProgress';
|
|
44
|
+
import { shouldDismissUploadPanel } from '../../utils/uploadPanelDismiss';
|
|
44
45
|
|
|
45
46
|
// The host's media library, when the File Browser was given one. It then stores the files, instead of the
|
|
46
47
|
// Widgetic upload settings.
|
|
@@ -1102,23 +1103,19 @@
|
|
|
1102
1103
|
}
|
|
1103
1104
|
}
|
|
1104
1105
|
|
|
1105
|
-
/**
|
|
1106
|
+
/**
|
|
1107
|
+
* After uploads finish, close the dim overlay so the file grid is usable again.
|
|
1108
|
+
* Only when every file went through: a batch with a failed file keeps the panel open, so the person sees which ones failed
|
|
1109
|
+
* and can ask for another try (the summary and footer retry buttons, or the retry of a single file).
|
|
1110
|
+
*/
|
|
1106
1111
|
function scheduleUploadDrawerDismiss() {
|
|
1107
|
-
|
|
1108
|
-
(item) => item.status === 'complete' || item.status === 'failed',
|
|
1109
|
-
);
|
|
1110
|
-
if (!allDone) return;
|
|
1112
|
+
if (!shouldDismissUploadPanel(uploadItems)) return;
|
|
1111
1113
|
setTimeout(() => {
|
|
1112
|
-
|
|
1113
|
-
(item) => item.status === 'complete' || item.status === 'failed',
|
|
1114
|
-
);
|
|
1115
|
-
if (!stillDone) return;
|
|
1114
|
+
if (!shouldDismissUploadPanel(uploadItems)) return;
|
|
1116
1115
|
isUploadsModalOpen = false;
|
|
1117
1116
|
isUploadsDrawerCollapsed = true;
|
|
1118
|
-
uploadItems =
|
|
1119
|
-
|
|
1120
|
-
dispatch('uploadsCleared');
|
|
1121
|
-
}
|
|
1117
|
+
uploadItems = [];
|
|
1118
|
+
dispatch('uploadsCleared');
|
|
1122
1119
|
}, 600);
|
|
1123
1120
|
}
|
|
1124
1121
|
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
12
12
|
import { FileIcon, SelectedBadge } from '../ui';
|
|
13
13
|
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
14
|
+
import { isMobileStore } from '../../stores/viewportStore';
|
|
14
15
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
15
16
|
import { ThumbHashImage } from '@widgetic/design-system/components';
|
|
16
|
-
import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
|
|
17
|
+
import { IconExclamationCircle, IconPlayerPlayFilled, IconTrash } from '@widgetic/design-system/icons';
|
|
17
18
|
import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
|
|
18
19
|
import { recentGridColumnsForWidth } from '../../utils/gridLayout';
|
|
19
20
|
|
|
@@ -72,8 +73,8 @@
|
|
|
72
73
|
recentFiles.forEach((file) => {
|
|
73
74
|
try {
|
|
74
75
|
loadingStates.set(file.id, false);
|
|
75
|
-
|
|
76
|
-
file.isMissing
|
|
76
|
+
// A file the list already knows to be gone stays gone: the card must not forget it and draw a picture that cannot load.
|
|
77
|
+
errorStates.set(file.id, Boolean(file.isMissing));
|
|
77
78
|
} catch (error) {
|
|
78
79
|
console.error('Error checking file:', file.name, error);
|
|
79
80
|
file.isMissing = true;
|
|
@@ -274,6 +275,22 @@
|
|
|
274
275
|
{getFormattedDate(file.modified || new Date(), $t)}
|
|
275
276
|
</p>
|
|
276
277
|
</div>
|
|
278
|
+
{#if file.isMissing || errorStates.get(file.id)}
|
|
279
|
+
<!-- The error tile of the Files list: a missing file can be deleted from here, as it can there (FileItem). -->
|
|
280
|
+
<button
|
|
281
|
+
type="button"
|
|
282
|
+
class="shrink-0 text-destructive opacity-0 transition-opacity duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background group-hover:opacity-100 group-focus-within:opacity-100 {$isMobileStore
|
|
283
|
+
? 'opacity-100!'
|
|
284
|
+
: ''}"
|
|
285
|
+
onclick={(e) => {
|
|
286
|
+
e.stopPropagation();
|
|
287
|
+
dispatch('delete', { item: file });
|
|
288
|
+
}}
|
|
289
|
+
aria-label={$t('item.deleteMissing')}
|
|
290
|
+
>
|
|
291
|
+
<IconTrash class="size-5 stroke-[1.6]" />
|
|
292
|
+
</button>
|
|
293
|
+
{/if}
|
|
277
294
|
{#if allowSelecting && fileSelected}
|
|
278
295
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
279
296
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
@@ -28,6 +28,7 @@ declare const RecentFiles: $$__sveltets_2_IsomorphicComponent<{
|
|
|
28
28
|
/** Cap from FileBrowser so the strip matches `getRecentFiles()`. */ visibleLimit?: number | undefined;
|
|
29
29
|
/** Measured width of the file browser panel (not the viewport). */ containerWidth?: number;
|
|
30
30
|
}, {
|
|
31
|
+
delete: CustomEvent<any>;
|
|
31
32
|
fileClick: CustomEvent<any>;
|
|
32
33
|
select: CustomEvent<any>;
|
|
33
34
|
} & {
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -183,7 +183,8 @@ export declare const FILE_BROWSER_MESSAGES: {
|
|
|
183
183
|
/** What a screen reader says for the X that closes a window. */
|
|
184
184
|
readonly 'dialog.close': "Close modal";
|
|
185
185
|
readonly 'toast.rename.started': "Renaming \"{name}\"…";
|
|
186
|
-
readonly 'toast.rename.done': "
|
|
186
|
+
readonly 'toast.rename.done': "File renamed";
|
|
187
|
+
readonly 'toast.rename.folderDone': "Folder renamed";
|
|
187
188
|
readonly 'toast.rename.doneDetail': "Successfully renamed \"{oldName}\" to \"{newName}\"";
|
|
188
189
|
readonly 'toast.rename.failed': "Rename failed";
|
|
189
190
|
readonly 'toast.rename.noChange': "No changes were made";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -192,7 +192,8 @@ export const FILE_BROWSER_MESSAGES = {
|
|
|
192
192
|
'dialog.close': 'Close modal',
|
|
193
193
|
// ===== Messages that pop up after an action =====
|
|
194
194
|
'toast.rename.started': 'Renaming "{name}"…',
|
|
195
|
-
'toast.rename.done': '
|
|
195
|
+
'toast.rename.done': 'File renamed',
|
|
196
|
+
'toast.rename.folderDone': 'Folder renamed',
|
|
196
197
|
'toast.rename.doneDetail': 'Successfully renamed "{oldName}" to "{newName}"',
|
|
197
198
|
'toast.rename.failed': 'Rename failed',
|
|
198
199
|
'toast.rename.noChange': 'No changes were made',
|
|
@@ -5,8 +5,8 @@ export declare const fileStore: {
|
|
|
5
5
|
update: (this: void, updater: import("svelte/store").Updater<FileSystemRoot>) => void;
|
|
6
6
|
};
|
|
7
7
|
export declare const currentFolder: import("svelte/store").Writable<string[]>;
|
|
8
|
-
export declare const sortCriteria: import("svelte/store").Writable<"name" | "
|
|
9
|
-
export declare const sortDirection: import("svelte/store").Writable<"
|
|
8
|
+
export declare const sortCriteria: import("svelte/store").Writable<"name" | "size" | "date">;
|
|
9
|
+
export declare const sortDirection: import("svelte/store").Writable<"desc" | "asc">;
|
|
10
10
|
export declare const selectedFiles: import("svelte/store").Writable<FileSystemItem[]>;
|
|
11
11
|
export declare const fileFilter: import("svelte/store").Writable<string[]>;
|
|
12
12
|
/**
|
|
@@ -105,7 +105,8 @@ export async function renameItem(itemId, newName) {
|
|
|
105
105
|
let currentSortDirection = 'asc';
|
|
106
106
|
sortCriteria.subscribe(value => currentSortCriteria = value)();
|
|
107
107
|
sortDirection.subscribe(value => currentSortDirection = value)();
|
|
108
|
-
//
|
|
108
|
+
// The new name is shown at once: there is no server behind this list to wait for (the saved tree, in the local cache, is
|
|
109
|
+
// written by the caller right after), so the old one-second pause of the mock only made the rename feel slow.
|
|
109
110
|
const response = await mockRenameAPI(itemId, finalName);
|
|
110
111
|
if (!response.success) {
|
|
111
112
|
throw new Error(response.error || 'Failed to rename item on server');
|
|
@@ -222,8 +223,6 @@ export async function renameItem(itemId, newName) {
|
|
|
222
223
|
// Mock API function for rename
|
|
223
224
|
async function mockRenameAPI(itemId, newName) {
|
|
224
225
|
try {
|
|
225
|
-
// Simulate network delay
|
|
226
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
227
226
|
// Check if the item exists in the file structure before proceeding
|
|
228
227
|
const item = findItemById(itemId);
|
|
229
228
|
if (!item) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the upload panel may close by itself.
|
|
3
|
+
*
|
|
4
|
+
* The panel (the dim overlay with the list of the batch) closes shortly after the last file went through, so the file grid is usable
|
|
5
|
+
* again. A batch in which a file failed does not close: the person has to see which files failed and be able to ask for another try
|
|
6
|
+
* (the retry of the summary and of the footer, or of a single row). A file still waiting or sending keeps it open as well.
|
|
7
|
+
*/
|
|
8
|
+
/** The part of an upload row that decides this. */
|
|
9
|
+
export interface UploadPanelItemLike {
|
|
10
|
+
status: string;
|
|
11
|
+
}
|
|
12
|
+
/** Whether every file of the batch went through, which is the only case in which the panel closes on its own. */
|
|
13
|
+
export declare function shouldDismissUploadPanel(items: readonly UploadPanelItemLike[]): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the upload panel may close by itself.
|
|
3
|
+
*
|
|
4
|
+
* The panel (the dim overlay with the list of the batch) closes shortly after the last file went through, so the file grid is usable
|
|
5
|
+
* again. A batch in which a file failed does not close: the person has to see which files failed and be able to ask for another try
|
|
6
|
+
* (the retry of the summary and of the footer, or of a single row). A file still waiting or sending keeps it open as well.
|
|
7
|
+
*/
|
|
8
|
+
/** Whether every file of the batch went through, which is the only case in which the panel closes on its own. */
|
|
9
|
+
export function shouldDismissUploadPanel(items) {
|
|
10
|
+
return items.length > 0 && items.every((item) => item.status === 'complete');
|
|
11
|
+
}
|