@widgetic/file-browser 0.5.17 → 0.5.18
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 +22 -8
- package/dist/components/core/FileUploader.svelte +1 -1
- package/dist/components/items/FileItem.svelte +55 -27
- package/dist/types.d.ts +1 -0
- package/dist/utils/fileUtils.d.ts +7 -0
- package/dist/utils/fileUtils.js +22 -0
- package/dist/utils/userUploadsStorage.js +1 -0
- package/dist/utils/widgeticUpload.js +28 -3
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FileSystemItem } from '../types';
|
|
2
|
-
import { IconArrowBounce } from '@widgetic/design-system/icons';
|
|
3
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> {
|
|
4
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
4
|
$$bindings?: Bindings;
|
|
@@ -24,7 +23,7 @@ declare const FolderTree: $$__sveltets_2_IsomorphicComponent<{
|
|
|
24
23
|
textClass?: string;
|
|
25
24
|
selectedIconClass?: string;
|
|
26
25
|
currentLocationClass?: string;
|
|
27
|
-
selectedIcon?:
|
|
26
|
+
selectedIcon?: any;
|
|
28
27
|
}, {
|
|
29
28
|
[evt: string]: CustomEvent<any>;
|
|
30
29
|
}, {}, {}, string>;
|
|
@@ -2668,7 +2668,14 @@
|
|
|
2668
2668
|
const { file, success } = event.detail;
|
|
2669
2669
|
|
|
2670
2670
|
if (success && file) {
|
|
2671
|
-
|
|
2671
|
+
const uploadedFile = {
|
|
2672
|
+
...file,
|
|
2673
|
+
thumbnail: file.thumbnail || file.url,
|
|
2674
|
+
mimeType:
|
|
2675
|
+
file.mimeType
|
|
2676
|
+
|| (/\.(jpe?g|png|gif|webp|heic|heif|svg)$/i.test(file.name || '') ? 'image/jpeg' : file.mimeType),
|
|
2677
|
+
};
|
|
2678
|
+
saveUserUpload(uploadedFile);
|
|
2672
2679
|
|
|
2673
2680
|
// Update the fileStore with the new file
|
|
2674
2681
|
fileStore.update(store => {
|
|
@@ -2703,7 +2710,7 @@
|
|
|
2703
2710
|
|
|
2704
2711
|
if (!isDuplicate) {
|
|
2705
2712
|
// Add the new file and maintain sorting
|
|
2706
|
-
currentFolder.children = [...currentFolder.children,
|
|
2713
|
+
currentFolder.children = [...currentFolder.children, uploadedFile].sort((a, b) => {
|
|
2707
2714
|
// Keep folders at the top
|
|
2708
2715
|
if (a.type === 'folder' && b.type !== 'folder') return -1;
|
|
2709
2716
|
if (a.type !== 'folder' && b.type === 'folder') return 1;
|
|
@@ -2738,7 +2745,7 @@
|
|
|
2738
2745
|
}
|
|
2739
2746
|
|
|
2740
2747
|
// Ensure the file appears in the virtual list by forcing an update
|
|
2741
|
-
sortedFilteredFiles = [...sortedFilteredFiles,
|
|
2748
|
+
sortedFilteredFiles = [...sortedFilteredFiles, uploadedFile].sort((a, b) => {
|
|
2742
2749
|
if (a.type === 'folder' && b.type !== 'folder') return -1;
|
|
2743
2750
|
if (a.type !== 'folder' && b.type === 'folder') return 1;
|
|
2744
2751
|
return 0;
|
|
@@ -2767,16 +2774,22 @@
|
|
|
2767
2774
|
}
|
|
2768
2775
|
} else {
|
|
2769
2776
|
// Initialize children array if it doesn't exist
|
|
2770
|
-
currentFolder.children = [
|
|
2777
|
+
currentFolder.children = [uploadedFile];
|
|
2771
2778
|
// Force a reactive update
|
|
2772
2779
|
currentFolderContent = { ...currentFolder };
|
|
2773
|
-
sortedFilteredFiles = [
|
|
2780
|
+
sortedFilteredFiles = [uploadedFile];
|
|
2774
2781
|
if(showLogs) console.log('Created new children array with file:', file.name);
|
|
2775
2782
|
}
|
|
2776
2783
|
|
|
2777
2784
|
return store;
|
|
2778
2785
|
});
|
|
2779
2786
|
persistMyUploadsTree();
|
|
2787
|
+
if (isWidgeticLibraryMode() && currentPath[0] !== 'folder_my_uploads') {
|
|
2788
|
+
const myUploadsPath = ['folder_my_uploads'];
|
|
2789
|
+
navigationStore.navigateToFolder(myUploadsPath, true);
|
|
2790
|
+
currentFolder.set(myUploadsPath);
|
|
2791
|
+
if (showLogs) console.log('[FileBrowser] Navigated into My uploads after upload');
|
|
2792
|
+
}
|
|
2780
2793
|
}
|
|
2781
2794
|
}
|
|
2782
2795
|
|
|
@@ -3679,9 +3692,10 @@ mainGridClass="app-main-grid"
|
|
|
3679
3692
|
item={{
|
|
3680
3693
|
...item,
|
|
3681
3694
|
url: getCorrectFileUrl(item),
|
|
3682
|
-
thumbnail:
|
|
3683
|
-
|
|
3684
|
-
|
|
3695
|
+
thumbnail: resolveFileItemUrl(
|
|
3696
|
+
{ ...item, url: item.thumbnail || item.url },
|
|
3697
|
+
$fileStore?.basePath ?? basePath
|
|
3698
|
+
),
|
|
3685
3699
|
}}
|
|
3686
3700
|
selected={allowSelecting && currentSelections.some(f => f.id === item.id)}
|
|
3687
3701
|
{allowSelecting}
|
|
@@ -884,7 +884,7 @@
|
|
|
884
884
|
<!-- Simple overlay to prevent interaction when panel is open and not collapsed -->
|
|
885
885
|
{#if !isUploadsDrawerCollapsed}
|
|
886
886
|
<div
|
|
887
|
-
class="uploads-overlay-bg absolute inset-0 bg-
|
|
887
|
+
class="uploads-overlay-bg absolute inset-0 bg-white/55 z-[9980]"
|
|
888
888
|
onclick={() => {
|
|
889
889
|
isUploadsDrawerCollapsed = true;
|
|
890
890
|
if(showLogs) console.log('Overlay clicked, collapsing panel');
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
// import ThumbHashImage from '../previews/ThumbHashImage.svelte';
|
|
22
22
|
|
|
23
23
|
import type { FileSystemItem } from '../../types';
|
|
24
|
-
import { getFileIcon,
|
|
24
|
+
import { getFileIcon, getItemFileType, formatFileSize } from '../../utils/fileUtils';
|
|
25
25
|
import { addMissingFile, removeMissingFile } from '../../stores/missingFilesStore';
|
|
26
26
|
import { browser } from '$app/environment';
|
|
27
27
|
import { IconTrash } from '@tabler/icons-svelte';
|
|
28
28
|
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
29
29
|
import type { FileFilterType } from '../../utils/fileTypes';
|
|
30
30
|
import { selectedFiles } from '../../stores/fileStore';
|
|
31
|
-
import {
|
|
31
|
+
import { buildTransformedUrl } from '../../utils/imageTransform';
|
|
32
32
|
import EaseOut from '@tabler/icons-svelte/icons/ease-out';
|
|
33
33
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
34
34
|
|
|
@@ -49,15 +49,17 @@
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
// Reactive declarations for file type handling
|
|
52
|
-
$: fileType =
|
|
52
|
+
$: fileType = getItemFileType(item);
|
|
53
53
|
$: isVideo = fileType === 'video';
|
|
54
54
|
$: isImage = fileType === 'image';
|
|
55
55
|
$: isAudio = fileType === 'audio';
|
|
56
|
-
// $: isDocument = fileType === 'document'; - this is not used because we don't preview documents
|
|
57
56
|
$: isSvg = fileType === 'svg';
|
|
58
57
|
$: isFont = fileType === 'font';
|
|
59
58
|
$: fileIcon = getFileIcon(item.name);
|
|
60
59
|
$: fontName = item.name.replace(/\.[^/.]+$/, '');
|
|
60
|
+
$: previewSrc = item.thumbnail || item.url || '';
|
|
61
|
+
$: isLikelyRemoteImage = !!(previewSrc && /^(https?:|blob:|data:image)/i.test(previewSrc));
|
|
62
|
+
$: showImageThumb = isImage || isSvg || (isLikelyRemoteImage && !isAudio && !isVideo && !isFont);
|
|
61
63
|
|
|
62
64
|
// State for file availability and loading
|
|
63
65
|
let isLoading = true;
|
|
@@ -77,6 +79,8 @@
|
|
|
77
79
|
let isIntersecting = false;
|
|
78
80
|
let shouldLoad = false;
|
|
79
81
|
|
|
82
|
+
$: if (previewSrc || showImageThumb) shouldLoad = true;
|
|
83
|
+
|
|
80
84
|
// Keep track of font loading state
|
|
81
85
|
let fontLoadingStarted = false;
|
|
82
86
|
let fontLoadAttempts = 0;
|
|
@@ -95,9 +99,10 @@
|
|
|
95
99
|
// Flag to determine if we should show thumbhash (only during initial load)
|
|
96
100
|
let showThumbhash = false;
|
|
97
101
|
|
|
102
|
+
// Tweened store for smooth fade-in
|
|
98
103
|
// Tweened store for smooth fade-in
|
|
99
104
|
let opacity = tweened(0, {
|
|
100
|
-
duration:
|
|
105
|
+
duration: 280,
|
|
101
106
|
easing: cubicOut
|
|
102
107
|
});
|
|
103
108
|
|
|
@@ -202,6 +207,14 @@
|
|
|
202
207
|
initialLoad = false;
|
|
203
208
|
}, 100);
|
|
204
209
|
|
|
210
|
+
// Always mount the <img> for remote/image files. Skeleton stays until onload fade-in.
|
|
211
|
+
if (previewSrc || isImage || isSvg || showImageThumb) {
|
|
212
|
+
shouldLoad = true;
|
|
213
|
+
if (!isImageCached) {
|
|
214
|
+
opacity.set(0, { duration: 0 });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
205
218
|
// Check cache status immediately for instant display
|
|
206
219
|
if (!isFont) {
|
|
207
220
|
const src = item.thumbnail || item.url;
|
|
@@ -217,9 +230,9 @@
|
|
|
217
230
|
});
|
|
218
231
|
} else {
|
|
219
232
|
showThumbhash = !!(item.thumbnail && item.hash && !thumbnailMissing);
|
|
220
|
-
|
|
233
|
+
// Keep the <img> visible — fade-from-0 never completes if onload is skipped.
|
|
234
|
+
opacity.set(1, { duration: 0 });
|
|
221
235
|
if (showThumbhash) {
|
|
222
|
-
// Just fade in the thumbhash
|
|
223
236
|
thumbhashOpacity.set(1);
|
|
224
237
|
}
|
|
225
238
|
}
|
|
@@ -269,28 +282,26 @@
|
|
|
269
282
|
});
|
|
270
283
|
|
|
271
284
|
async function checkFileExistence() {
|
|
285
|
+
if (isImage || isSvg) {
|
|
286
|
+
// HEAD probes often fail on CDN CORS; the <img> onerror path is the source of truth.
|
|
287
|
+
isLoading = false;
|
|
288
|
+
shouldLoad = true;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
272
291
|
|
|
273
292
|
if (!isFont) {
|
|
274
|
-
// Check if file from url exists
|
|
275
293
|
const imageExists = await checkFileExists(item.url, 'image');
|
|
276
|
-
|
|
277
|
-
// Check if thumbnail file exists
|
|
278
294
|
if (imageExists && item.thumbnail) {
|
|
279
295
|
await checkFileExists(item.thumbnail, 'thumbnail');
|
|
280
296
|
}
|
|
281
|
-
|
|
282
|
-
// Set isMissing to true if file does not exist
|
|
283
297
|
item.isMissing = !imageExists;
|
|
284
|
-
// console.log('FileItem checkFileExistence:', item, imageExists);
|
|
285
|
-
|
|
286
|
-
// Remove or add missing file from store depending if the image exists
|
|
287
298
|
if (imageExists) {
|
|
288
299
|
removeMissingFile(item.id);
|
|
289
300
|
} else {
|
|
290
301
|
addMissingFile(item.id);
|
|
291
302
|
}
|
|
292
303
|
}
|
|
293
|
-
|
|
304
|
+
|
|
294
305
|
isLoading = false;
|
|
295
306
|
}
|
|
296
307
|
|
|
@@ -501,14 +512,18 @@
|
|
|
501
512
|
"
|
|
502
513
|
onclick={handleIconClick}
|
|
503
514
|
aria-label="Preview {item.name}"
|
|
504
|
-
disabled={isMissing
|
|
515
|
+
disabled={isMissing}
|
|
505
516
|
>
|
|
506
|
-
<div class="w-full h-full flex items-center justify-center">
|
|
507
|
-
<!--
|
|
508
|
-
{#if
|
|
517
|
+
<div class="w-full h-full flex items-center justify-center relative">
|
|
518
|
+
<!-- Image thumbs: skeleton overlay until onload, then fade in -->
|
|
519
|
+
{#if showImageThumb && shouldLoad && !imageLoaded && !isImageCached}
|
|
520
|
+
<div class="fb-thumb-loader-ct absolute inset-0 z-20 overflow-hidden rounded-[var(--radius-large)]">
|
|
521
|
+
<LoadingSkeleton width="100%" height="100%" />
|
|
522
|
+
</div>
|
|
523
|
+
{:else if isLoading && shouldLoad && !imageLoaded && !isImageCached && !showImageThumb}
|
|
509
524
|
<LoadingSkeleton width="100%" height="100%" />
|
|
510
|
-
|
|
511
|
-
{
|
|
525
|
+
{/if}
|
|
526
|
+
{#if shouldLoad}
|
|
512
527
|
<!-- Font Icon -->
|
|
513
528
|
{#if isFont}
|
|
514
529
|
<span
|
|
@@ -526,7 +541,7 @@
|
|
|
526
541
|
/>
|
|
527
542
|
<!-- Audio or Document Icon -->
|
|
528
543
|
{:else if !imageMissing}
|
|
529
|
-
{#if isAudio || fileType === 'document'}
|
|
544
|
+
{#if isAudio || (fileType === 'document' && !showImageThumb)}
|
|
530
545
|
<img
|
|
531
546
|
src={getAssetUrl(getFileIcon(item.name))}
|
|
532
547
|
alt={isAudio ? 'Audio file' : 'Document file'}
|
|
@@ -551,14 +566,27 @@
|
|
|
551
566
|
|
|
552
567
|
<!-- Thumbnail Image -->
|
|
553
568
|
<img class="thumbnail-image w-full h-full rounded-[var(--radius-large)] object-cover absolute inset-0"
|
|
554
|
-
src={
|
|
555
|
-
srcset={buildImageSrcset(item.thumbnail, [320, 640, 960], { fit: 'cover' })}
|
|
556
|
-
sizes="(max-width: 640px) 45vw, 240px"
|
|
569
|
+
src={previewSrc}
|
|
557
570
|
alt={item.name}
|
|
571
|
+
referrerpolicy="no-referrer"
|
|
558
572
|
style="opacity: {$opacity}; z-index: 10;"
|
|
559
573
|
onerror={(e: any) => {
|
|
560
|
-
console.log(`[FileItem ${item.name}] Thumbnail error:`,
|
|
574
|
+
console.log(`[FileItem ${item.name}] Thumbnail error:`, previewSrc);
|
|
575
|
+
const imgEl = e.currentTarget as HTMLImageElement;
|
|
576
|
+
if (imgEl.srcset) {
|
|
577
|
+
imgEl.srcset = '';
|
|
578
|
+
imgEl.sizes = '';
|
|
579
|
+
imgEl.src = item.url || previewSrc;
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (item.thumbnail && item.url && previewSrc === item.thumbnail && imgEl.src !== item.url) {
|
|
583
|
+
imgEl.src = item.url;
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
561
586
|
thumbnailMissing = true;
|
|
587
|
+
imageMissing = true;
|
|
588
|
+
opacity.set(1);
|
|
589
|
+
isLoading = false;
|
|
562
590
|
}}
|
|
563
591
|
onload={handleImageLoad}
|
|
564
592
|
/>
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ export declare function formatFileSize(bytes: number): string;
|
|
|
3
3
|
export declare function getFileIcon(fileName: string): string;
|
|
4
4
|
export declare function getFileExtension(fileNameOrUrl: string): string;
|
|
5
5
|
export declare function getFileType(fileNameOrUrl: string): FileFilterType;
|
|
6
|
+
/** Prefer mime / thumbnail URL when the filename has no real image extension (e.g. IMG_8658). */
|
|
7
|
+
export declare function getItemFileType(item: {
|
|
8
|
+
name?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
thumbnail?: string;
|
|
11
|
+
mimeType?: string;
|
|
12
|
+
}): FileFilterType;
|
|
6
13
|
export declare function checkFileExists(url: string | undefined): Promise<boolean>;
|
|
7
14
|
/**
|
|
8
15
|
* Gets the correct URL for a static asset using SvelteKit's assets path
|
package/dist/utils/fileUtils.js
CHANGED
|
@@ -74,6 +74,28 @@ export function getFileType(fileNameOrUrl) {
|
|
|
74
74
|
}
|
|
75
75
|
return 'document';
|
|
76
76
|
}
|
|
77
|
+
/** Prefer mime / thumbnail URL when the filename has no real image extension (e.g. IMG_8658). */
|
|
78
|
+
export function getItemFileType(item) {
|
|
79
|
+
const mime = (item.mimeType || '').toLowerCase();
|
|
80
|
+
if (mime.startsWith('image/'))
|
|
81
|
+
return 'image';
|
|
82
|
+
if (mime.startsWith('video/'))
|
|
83
|
+
return 'video';
|
|
84
|
+
if (mime.startsWith('audio/'))
|
|
85
|
+
return 'audio';
|
|
86
|
+
const fromName = getFileType(item.name || '');
|
|
87
|
+
if (fromName !== 'document')
|
|
88
|
+
return fromName;
|
|
89
|
+
if (/IMG_\d+/i.test(item.name || ''))
|
|
90
|
+
return 'image';
|
|
91
|
+
const urlHint = item.thumbnail || item.url || '';
|
|
92
|
+
if (urlHint && (/^data:image\//i.test(urlHint) || /\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(urlHint.split(/[?#]/)[0]))) {
|
|
93
|
+
return 'image';
|
|
94
|
+
}
|
|
95
|
+
if (item.thumbnail)
|
|
96
|
+
return 'image';
|
|
97
|
+
return getFileType(urlHint || item.name || '');
|
|
98
|
+
}
|
|
77
99
|
export async function checkFileExists(url) {
|
|
78
100
|
if (!url)
|
|
79
101
|
return false;
|
|
@@ -46,8 +46,7 @@ export async function uploadToWidgeticApi(file, config, options = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
const fileName = (data.file_name || data.fileName || file.name);
|
|
48
48
|
const fileId = (data.id || `upload_${Date.now()}`);
|
|
49
|
-
|
|
50
|
-
const storedMimeType = (data.mime_type || data.mimeType || file.type) || '';
|
|
49
|
+
const storedMimeType = inferImageMime((data.mime_type || data.mimeType || file.type) || '', fileName, url);
|
|
51
50
|
return {
|
|
52
51
|
success: true,
|
|
53
52
|
file: {
|
|
@@ -58,9 +57,34 @@ export async function uploadToWidgeticApi(file, config, options = {}) {
|
|
|
58
57
|
modified: new Date().toISOString(),
|
|
59
58
|
url,
|
|
60
59
|
thumbnail: storedMimeType.startsWith('image/') ? url : undefined,
|
|
60
|
+
mimeType: storedMimeType || undefined,
|
|
61
61
|
},
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
+
function inferImageMime(mime, fileName, url) {
|
|
65
|
+
const stored = (mime || '').toLowerCase();
|
|
66
|
+
if (stored.startsWith('image/'))
|
|
67
|
+
return stored;
|
|
68
|
+
const hint = `${fileName} ${url}`.split(/[?#]/)[0];
|
|
69
|
+
if (/\.(png)(\?|$)/i.test(hint))
|
|
70
|
+
return 'image/png';
|
|
71
|
+
if (/\.(gif)(\?|$)/i.test(hint))
|
|
72
|
+
return 'image/gif';
|
|
73
|
+
if (/\.(webp)(\?|$)/i.test(hint))
|
|
74
|
+
return 'image/webp';
|
|
75
|
+
if (/\.(svg)(\?|$)/i.test(hint))
|
|
76
|
+
return 'image/svg+xml';
|
|
77
|
+
if (/\.(jpe?g|heic|heif)(\?|$)/i.test(hint))
|
|
78
|
+
return 'image/jpeg';
|
|
79
|
+
if (stored.startsWith('video/') || stored.startsWith('audio/') || stored.includes('pdf'))
|
|
80
|
+
return stored;
|
|
81
|
+
if (/\.(mp3|wav|mp4|webm|pdf|zip)(\?|$)/i.test(hint))
|
|
82
|
+
return stored;
|
|
83
|
+
// iOS-style names without a real image extension still preview via the stored URL.
|
|
84
|
+
if (url)
|
|
85
|
+
return stored || 'image/jpeg';
|
|
86
|
+
return stored;
|
|
87
|
+
}
|
|
64
88
|
/**
|
|
65
89
|
* Hydrate FileBrowser "My uploads" from GET /v1/uploads.
|
|
66
90
|
*/
|
|
@@ -90,8 +114,8 @@ export async function fetchUserUploadsFromApi(config, options = {}) {
|
|
|
90
114
|
.filter((row) => row.id && row.url)
|
|
91
115
|
.map((row) => {
|
|
92
116
|
const fileName = (row.file_name || row.fileName || 'upload');
|
|
93
|
-
const mime = (row.mime_type || row.mimeType || '');
|
|
94
117
|
const url = row.url;
|
|
118
|
+
const mime = inferImageMime((row.mime_type || row.mimeType || ''), fileName, url);
|
|
95
119
|
return {
|
|
96
120
|
id: row.id,
|
|
97
121
|
name: fileName,
|
|
@@ -100,6 +124,7 @@ export async function fetchUserUploadsFromApi(config, options = {}) {
|
|
|
100
124
|
modified: new Date().toISOString(),
|
|
101
125
|
url,
|
|
102
126
|
thumbnail: mime.startsWith('image/') ? url : undefined,
|
|
127
|
+
mimeType: mime || undefined,
|
|
103
128
|
};
|
|
104
129
|
});
|
|
105
130
|
}
|