@widgetic/file-browser 0.5.41 → 0.5.42
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/core/FileBrowser.svelte +49 -7
- package/dist/components/previews/FilePreview.svelte +28 -4
- 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/index.d.ts +3 -0
- package/dist/index.js +3 -0
- 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 +32 -0
- package/package.json +3 -3
|
@@ -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';
|
|
@@ -768,13 +771,14 @@
|
|
|
768
771
|
let files = await loadUserUploads();
|
|
769
772
|
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
770
773
|
try {
|
|
771
|
-
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
774
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
775
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
776
|
+
});
|
|
777
|
+
files = mergeRemoteUploadList(files, remoteFiles, {
|
|
778
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
779
|
+
apiHydrationSucceeded: true,
|
|
780
|
+
});
|
|
781
|
+
await replacePersistedUploads(files);
|
|
778
782
|
if (showLogs) {
|
|
779
783
|
// console.log('[FileBrowser] Hydrated uploads from API:', remoteFiles.length);
|
|
780
784
|
}
|
|
@@ -2291,6 +2295,39 @@
|
|
|
2291
2295
|
}));
|
|
2292
2296
|
}
|
|
2293
2297
|
|
|
2298
|
+
async function evictGoneUploads(uploadIds: string[]) {
|
|
2299
|
+
if (!uploadIds.length || libraryMode) return;
|
|
2300
|
+
const drop = new Set(uploadIds);
|
|
2301
|
+
await removePersistedUploads(uploadIds);
|
|
2302
|
+
fileStore.update((store) => ({ ...store, root: removeFiles(store.root, drop) }));
|
|
2303
|
+
selectedFiles.update((files) => files.filter((file) => !drop.has(file.id)));
|
|
2304
|
+
if (previewFile && drop.has(previewFile.id)) {
|
|
2305
|
+
previewFile = null;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
async function refreshUploadsFromApi() {
|
|
2310
|
+
if (libraryMode) return;
|
|
2311
|
+
const uploadConfig = getFileBrowserUploadConfig();
|
|
2312
|
+
if (!uploadConfig?.accessToken || !uploadConfig?.apiBasePath) return;
|
|
2313
|
+
try {
|
|
2314
|
+
const cached = await loadUserUploads();
|
|
2315
|
+
const remoteFiles = await fetchUserUploadsFromApi(uploadConfig, {
|
|
2316
|
+
limit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2317
|
+
});
|
|
2318
|
+
const merged = mergeRemoteUploadList(cached, remoteFiles, {
|
|
2319
|
+
listLimit: WIDGETIC_UPLOADS_LIST_LIMIT,
|
|
2320
|
+
apiHydrationSucceeded: true,
|
|
2321
|
+
});
|
|
2322
|
+
await replacePersistedUploads(merged);
|
|
2323
|
+
const root = await createUserUploadsFileSystemRoot(merged, $t('library.defaultLabel'));
|
|
2324
|
+
data = root;
|
|
2325
|
+
init();
|
|
2326
|
+
} catch (refreshError) {
|
|
2327
|
+
console.warn('[FileBrowser] Upload list refresh failed:', refreshError);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2294
2331
|
function handleFileBrowserCommand(event: Event) {
|
|
2295
2332
|
const detail = (event as CustomEvent).detail;
|
|
2296
2333
|
if (!detail || detail.instanceId !== instanceId) return;
|
|
@@ -2300,6 +2337,10 @@
|
|
|
2300
2337
|
navigateToBreadcrumb({ detail: detail.index } as CustomEvent<number>);
|
|
2301
2338
|
} else if (detail.command === 'publish') {
|
|
2302
2339
|
publishFileBrowserNav();
|
|
2340
|
+
} else if (detail.command === 'remove-upload' && typeof detail.uploadId === 'string') {
|
|
2341
|
+
void evictGoneUploads([detail.uploadId]);
|
|
2342
|
+
} else if (detail.command === 'refresh-uploads') {
|
|
2343
|
+
void refreshUploadsFromApi();
|
|
2303
2344
|
}
|
|
2304
2345
|
}
|
|
2305
2346
|
|
|
@@ -3241,6 +3282,7 @@ mainGridClass="app-main-grid"
|
|
|
3241
3282
|
target={rootContainerClass}
|
|
3242
3283
|
on:select={(event : any) => handleFileSelect(event.detail)}
|
|
3243
3284
|
on:navigate={handlePreviewNavigate}
|
|
3285
|
+
on:fileUnavailable={(event) => void evictGoneUploads([event.detail.id])}
|
|
3244
3286
|
/>
|
|
3245
3287
|
{/if}
|
|
3246
3288
|
|
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
// Svelte imports
|
|
8
8
|
import { onMount } from 'svelte';
|
|
9
9
|
import { createEventDispatcher } from 'svelte';
|
|
10
|
-
const dispatch = createEventDispatcher
|
|
10
|
+
const dispatch = createEventDispatcher<{
|
|
11
|
+
navigate: FileSystemItem;
|
|
12
|
+
select: FileSystemItem;
|
|
13
|
+
close: void;
|
|
14
|
+
fileUnavailable: { id: string };
|
|
15
|
+
}>();
|
|
11
16
|
|
|
12
17
|
// Design System Components imports
|
|
13
18
|
import { BaseModal, PDFViewer, EmptyState } from '@widgetic/design-system/components';
|
|
@@ -37,7 +42,7 @@
|
|
|
37
42
|
import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
|
|
38
43
|
|
|
39
44
|
// Stores
|
|
40
|
-
import { missingFiles } from '../../stores/missingFilesStore';
|
|
45
|
+
import { addMissingFile, missingFiles } from '../../stores/missingFilesStore';
|
|
41
46
|
import { validSelections } from '../../stores/persistentSelectStore';
|
|
42
47
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
43
48
|
import { useI18n } from '../../i18n';
|
|
@@ -485,11 +490,26 @@
|
|
|
485
490
|
$: isPDF = fileType === 'document' && file.name.toLowerCase().endsWith('.pdf');
|
|
486
491
|
$: isPreviewableText = fileType === 'document' && isPreviewableTextFile(file.name);
|
|
487
492
|
|
|
493
|
+
let reportedUnavailableForId = '';
|
|
494
|
+
|
|
495
|
+
function reportFileUnavailable(fileId: string) {
|
|
496
|
+
if (reportedUnavailableForId === fileId) return;
|
|
497
|
+
reportedUnavailableForId = fileId;
|
|
498
|
+
addMissingFile(fileId);
|
|
499
|
+
dispatch('fileUnavailable', { id: fileId });
|
|
500
|
+
}
|
|
501
|
+
|
|
488
502
|
// Autoplay when component mounts
|
|
489
503
|
onMount(() => {
|
|
490
504
|
|
|
491
505
|
if(showLogs) console.log('FilePreview: onMount: file:', file);
|
|
492
506
|
|
|
507
|
+
if (fileType === 'font' && file.url) {
|
|
508
|
+
void checkFileExists(file.url).then((ok) => {
|
|
509
|
+
if (!ok) reportFileUnavailable(file.id);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
493
513
|
// Autoplay media when component mounts
|
|
494
514
|
if (videoElement || audioElement) {
|
|
495
515
|
const mediaElement = videoElement || audioElement;
|
|
@@ -693,7 +713,8 @@
|
|
|
693
713
|
<FontPreview
|
|
694
714
|
src={fileUrl}
|
|
695
715
|
{fontName}
|
|
696
|
-
previewText={file.previewText || undefined}
|
|
716
|
+
previewText={file.previewText || undefined}
|
|
717
|
+
on:unavailable={() => reportFileUnavailable(file.id)}
|
|
697
718
|
/>
|
|
698
719
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
699
720
|
{#if fileType === 'svg'}
|
|
@@ -724,7 +745,10 @@
|
|
|
724
745
|
maxContentHeight={hostFrame().height - TOTAL_VERTICAL_SPACE - 48}
|
|
725
746
|
initiallyLoaded={imageLoaded}
|
|
726
747
|
on:load={handleImageBitmapLoaded}
|
|
727
|
-
on:error={() =>
|
|
748
|
+
on:error={() => {
|
|
749
|
+
imageFailed = true;
|
|
750
|
+
reportFileUnavailable(file.id);
|
|
751
|
+
}}
|
|
728
752
|
on:dimensions={(event) => {
|
|
729
753
|
const { width, height } = event.detail;
|
|
730
754
|
if (!width || !height) return;
|
|
@@ -22,9 +22,12 @@ declare const FilePreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
22
22
|
currentFilter?: FileFilterType;
|
|
23
23
|
target?: string;
|
|
24
24
|
}, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
close: CustomEvent<
|
|
25
|
+
navigate: CustomEvent<FileSystemItem>;
|
|
26
|
+
select: CustomEvent<FileSystemItem>;
|
|
27
|
+
close: CustomEvent<void>;
|
|
28
|
+
fileUnavailable: CustomEvent<{
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
28
31
|
} & {
|
|
29
32
|
[evt: string]: CustomEvent<any>;
|
|
30
33
|
}, {}, {}, string>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { onMount } from 'svelte';
|
|
2
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
3
3
|
import ErrorPreview from './ErrorPreview.svelte';
|
|
4
|
+
|
|
5
|
+
const dispatch = createEventDispatcher<{ unavailable: void }>();
|
|
4
6
|
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
5
7
|
import { useI18n } from '../../i18n';
|
|
6
8
|
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
} catch (error) {
|
|
28
30
|
console.error('FontPreview: Error loading font from url:', src, error);
|
|
29
31
|
hasError = true;
|
|
32
|
+
dispatch('unavailable');
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
35
|
</script>
|
|
@@ -16,6 +16,8 @@ declare const FontPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
|
16
16
|
fontName: string;
|
|
17
17
|
/** The sentence shown in the font. Left out, a pangram in the page's language ("The quick brown fox jumps over the lazy dog"). */ previewText?: string | undefined;
|
|
18
18
|
}, {
|
|
19
|
+
unavailable: CustomEvent<void>;
|
|
20
|
+
} & {
|
|
19
21
|
[evt: string]: CustomEvent<any>;
|
|
20
22
|
}, {}, {}, string>;
|
|
21
23
|
type FontPreview = InstanceType<typeof FontPreview>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export * from './components';
|
|
|
3
3
|
export * from './stores';
|
|
4
4
|
export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, type FileBrowserUploadConfig, } from './stores/uploadApiStore';
|
|
5
5
|
export * from './utils';
|
|
6
|
+
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
7
|
+
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
8
|
+
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
6
9
|
export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
|
|
7
10
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
8
11
|
export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,9 @@ export * from './stores';
|
|
|
7
7
|
export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, } from './stores/uploadApiStore';
|
|
8
8
|
// Export all utilities
|
|
9
9
|
export * from './utils';
|
|
10
|
+
export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
|
|
11
|
+
export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
|
|
12
|
+
export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
|
|
10
13
|
export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
|
|
11
14
|
// Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
|
|
12
15
|
// a page or a build step can run on its own messages.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../types';
|
|
2
|
+
/** Default page size for GET /v1/uploads (no cursor yet). */
|
|
3
|
+
export declare const WIDGETIC_UPLOADS_LIST_LIMIT = 100;
|
|
4
|
+
/**
|
|
5
|
+
* Merges a Dexie-cached upload list with a fresh API page.
|
|
6
|
+
* When the API returns fewer than `listLimit` rows, the list is treated as complete and cached-only ids are dropped.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mergeRemoteUploadList(cachedFiles: FileSystemItem[], remoteFiles: FileSystemItem[], options: {
|
|
9
|
+
listLimit?: number;
|
|
10
|
+
apiHydrationSucceeded: boolean;
|
|
11
|
+
}): FileSystemItem[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Default page size for GET /v1/uploads (no cursor yet). */
|
|
2
|
+
export const WIDGETIC_UPLOADS_LIST_LIMIT = 100;
|
|
3
|
+
/**
|
|
4
|
+
* Merges a Dexie-cached upload list with a fresh API page.
|
|
5
|
+
* When the API returns fewer than `listLimit` rows, the list is treated as complete and cached-only ids are dropped.
|
|
6
|
+
*/
|
|
7
|
+
export function mergeRemoteUploadList(cachedFiles, remoteFiles, options) {
|
|
8
|
+
if (!options.apiHydrationSucceeded) {
|
|
9
|
+
const byId = new Map(cachedFiles.map((file) => [file.id, file]));
|
|
10
|
+
for (const remoteFile of remoteFiles) {
|
|
11
|
+
byId.set(remoteFile.id, remoteFile);
|
|
12
|
+
}
|
|
13
|
+
return Array.from(byId.values());
|
|
14
|
+
}
|
|
15
|
+
const listLimit = options.listLimit ?? WIDGETIC_UPLOADS_LIST_LIMIT;
|
|
16
|
+
const remoteIds = new Set(remoteFiles.map((file) => file.id));
|
|
17
|
+
const completeList = remoteFiles.length < listLimit;
|
|
18
|
+
const byId = new Map(cachedFiles.map((file) => [file.id, file]));
|
|
19
|
+
for (const remoteFile of remoteFiles) {
|
|
20
|
+
byId.set(remoteFile.id, remoteFile);
|
|
21
|
+
}
|
|
22
|
+
if (completeList) {
|
|
23
|
+
for (const cachedId of [...byId.keys()]) {
|
|
24
|
+
if (!remoteIds.has(cachedId)) {
|
|
25
|
+
byId.delete(cachedId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return Array.from(byId.values());
|
|
30
|
+
}
|
|
@@ -12,6 +12,14 @@ export declare function saveUserUpload(file: FileSystemItem): void;
|
|
|
12
12
|
* Persist multiple uploads into L1 in a single atomic transaction.
|
|
13
13
|
* Eliminates IndexedDB race conditions and reduces write overhead when hydrating batches of files.
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* Replaces the persisted upload list in L1 (used after API hydration or session preload).
|
|
17
|
+
*/
|
|
18
|
+
export declare function replacePersistedUploads(files: FileSystemItem[]): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Removes uploads from L1 by id (after delete elsewhere or preview 404).
|
|
21
|
+
*/
|
|
22
|
+
export declare function removePersistedUploads(fileIds: ReadonlyArray<string>): Promise<void>;
|
|
15
23
|
export declare function saveUserUploadsBatch(files: FileSystemItem[]): void;
|
|
16
24
|
/**
|
|
17
25
|
* Load the saved library tree children (the children of the synthetic root) from L1, with legacy migration.
|
|
@@ -50,6 +50,38 @@ export function saveUserUpload(file) {
|
|
|
50
50
|
* Persist multiple uploads into L1 in a single atomic transaction.
|
|
51
51
|
* Eliminates IndexedDB race conditions and reduces write overhead when hydrating batches of files.
|
|
52
52
|
*/
|
|
53
|
+
/**
|
|
54
|
+
* Replaces the persisted upload list in L1 (used after API hydration or session preload).
|
|
55
|
+
*/
|
|
56
|
+
export async function replacePersistedUploads(files) {
|
|
57
|
+
const ownerId = ownerIdOrNull();
|
|
58
|
+
if (!ownerId)
|
|
59
|
+
return;
|
|
60
|
+
const uploads = files.filter((file) => file.type === 'file');
|
|
61
|
+
try {
|
|
62
|
+
await writeEntity(ownerId, UPLOADS_KIND, entityKey(), uploads);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('[userUploadsStorage] Failed to replace uploads list:', error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Removes uploads from L1 by id (after delete elsewhere or preview 404).
|
|
70
|
+
*/
|
|
71
|
+
export async function removePersistedUploads(fileIds) {
|
|
72
|
+
const ownerId = ownerIdOrNull();
|
|
73
|
+
if (!ownerId || fileIds.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
const drop = new Set(fileIds);
|
|
76
|
+
try {
|
|
77
|
+
const existing = await loadAllPersistedUploads();
|
|
78
|
+
const next = existing.filter((file) => !drop.has(file.id));
|
|
79
|
+
await writeEntity(ownerId, UPLOADS_KIND, entityKey(), next);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error('[userUploadsStorage] Failed to remove uploads from cache:', error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
53
85
|
export function saveUserUploadsBatch(files) {
|
|
54
86
|
const validFiles = files.filter((f) => f.type === 'file');
|
|
55
87
|
if (validFiles.length === 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/file-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.42",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@tailwindcss/postcss": "^4.3.0",
|
|
98
98
|
"@types/node": "^22.13.4",
|
|
99
99
|
"@widgetic/cache-layer": "^0.1.1",
|
|
100
|
-
"@widgetic/design-system": "^0.5.
|
|
100
|
+
"@widgetic/design-system": "^0.5.28",
|
|
101
101
|
"@widgetic/dev-tools": "^0.3.0",
|
|
102
102
|
"concurrently": "^9.1.2",
|
|
103
103
|
"eslint": "^9.0.0",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"peerDependencies": {
|
|
119
119
|
"@sveltejs/kit": "^2.20.7",
|
|
120
120
|
"@widgetic/cache-layer": "^0.1.1",
|
|
121
|
-
"@widgetic/design-system": ">=0.5.
|
|
121
|
+
"@widgetic/design-system": ">=0.5.28",
|
|
122
122
|
"pdfjs-dist": "^4.10.38",
|
|
123
123
|
"svelte": "^5.0.0"
|
|
124
124
|
},
|