@widgetic/file-browser 0.5.17 → 0.5.19
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 +171 -1339
- package/dist/components/core/FileUploader.svelte +5 -5
- package/dist/components/core/Header.svelte +3 -3
- package/dist/components/core/RecentFiles.svelte +7 -43
- package/dist/components/items/FileItem.svelte +57 -62
- package/dist/components/items/FileItem.svelte.d.ts +1 -0
- package/dist/components/items/FolderItem.svelte +4 -12
- package/dist/components/items/FolderItem.svelte.d.ts +1 -0
- package/dist/components/modals/MoveDialog.svelte +17 -17
- package/dist/components/modals/SearchModal.svelte +30 -41
- package/dist/components/modals/SelectedFilesModal.svelte +2 -2
- package/dist/components/previews/AudioPlayer.svelte +1 -1
- package/dist/components/previews/FilePreview.svelte +7 -7
- package/dist/components/previews/ImagePreview.svelte +13 -13
- package/dist/components/previews/VideoPlayer.svelte +1 -1
- package/dist/components/ui/DragSelect.svelte +73 -52
- package/dist/components/ui/DropdownMenu.svelte +1 -1
- package/dist/components/ui/VirtualList.svelte +20 -10
- package/dist/data/demoContent.json +1171 -0
- package/dist/stores/fileStore.js +1 -1
- package/dist/stores/persistentSelectStore.d.ts +1 -0
- package/dist/stores/persistentSelectStore.js +23 -0
- package/dist/stores/viewportStore.d.ts +5 -0
- package/dist/stores/viewportStore.js +19 -0
- package/dist/types.d.ts +1 -0
- package/dist/utils/fileOperations.js +17 -14
- package/dist/utils/fileUtils.d.ts +7 -0
- package/dist/utils/fileUtils.js +22 -0
- package/dist/utils/resolveFileUrl.js +6 -2
- package/dist/utils/userUploadsStorage.d.ts +5 -0
- package/dist/utils/userUploadsStorage.js +16 -6
- package/dist/utils/widgeticUpload.d.ts +1 -0
- package/dist/utils/widgeticUpload.js +28 -3
- package/package.json +8 -8
|
@@ -413,7 +413,7 @@
|
|
|
413
413
|
|
|
414
414
|
if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
|
|
415
415
|
if (showLogs) {
|
|
416
|
-
console.log('[FileUploader] Widgetic upload:', file.name, uploadConfig.contextType);
|
|
416
|
+
// console.log('[FileUploader] Widgetic upload:', file.name, uploadConfig.contextType);
|
|
417
417
|
}
|
|
418
418
|
response = await uploadToWidgeticApi(normalizedFile, uploadConfig, {
|
|
419
419
|
abortSignal: controller.signal,
|
|
@@ -428,7 +428,7 @@
|
|
|
428
428
|
});
|
|
429
429
|
} else {
|
|
430
430
|
if (showLogs) {
|
|
431
|
-
console.log(`[FileUploader] Mock upload ${file.name} to path: ${path}, folder: ${currentFolderId}`);
|
|
431
|
+
// console.log(`[FileUploader] Mock upload ${file.name} to path: ${path}, folder: ${currentFolderId}`);
|
|
432
432
|
}
|
|
433
433
|
|
|
434
434
|
const progressInterval = setInterval(() => {
|
|
@@ -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');
|
|
@@ -1110,7 +1110,7 @@
|
|
|
1110
1110
|
|
|
1111
1111
|
/* Override button text to use subtext style */
|
|
1112
1112
|
:global(.file-uploader-button) {
|
|
1113
|
-
font-family: '
|
|
1113
|
+
font-family: 'Inter', sans-serif !important;
|
|
1114
1114
|
font-size: 16px !important;
|
|
1115
1115
|
line-height: 1.4 !important;
|
|
1116
1116
|
font-weight: 400 !important;
|
|
@@ -1119,7 +1119,7 @@
|
|
|
1119
1119
|
/* Override button text to ensure it's not bold */
|
|
1120
1120
|
:global(.file-uploader-button span) {
|
|
1121
1121
|
font-weight: 400 !important;
|
|
1122
|
-
font-family: '
|
|
1122
|
+
font-family: 'Inter', sans-serif !important;
|
|
1123
1123
|
}
|
|
1124
1124
|
|
|
1125
1125
|
/* Make sure drawer appears on top of other elements */
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
|
|
39
39
|
function handleNavigate(index: number): void {
|
|
40
40
|
if (index === currentPath.length - 1) {
|
|
41
|
-
console.log('Already at this path level, skipping navigation');
|
|
41
|
+
// console.log('Already at this path level, skipping navigation');
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (index === -1 && currentPath.length === 0) {
|
|
46
|
-
console.log('Already at root, skipping navigation');
|
|
46
|
+
// console.log('Already at root, skipping navigation');
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
console.log('Navigating to path index:', index);
|
|
50
|
+
// console.log('Navigating to path index:', index);
|
|
51
51
|
dispatch('navigate', index);
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -250,54 +250,18 @@
|
|
|
250
250
|
const promises = recentFiles.map(async (file) => {
|
|
251
251
|
try {
|
|
252
252
|
const fileType = getFileType(file.url || file.name);
|
|
253
|
-
const isVideo = fileType === 'video';
|
|
254
|
-
const isSvg = fileType === 'svg';
|
|
255
253
|
const isFont = fileType === 'font';
|
|
256
254
|
|
|
257
|
-
//
|
|
255
|
+
// Load font for display if needed
|
|
258
256
|
if (isFont) {
|
|
259
|
-
|
|
260
|
-
cachedFonts.set(file.id,
|
|
261
|
-
|
|
262
|
-
if (isCached) {
|
|
263
|
-
// For cached fonts, ensure they're loaded for display
|
|
264
|
-
await loadFontForDisplay(file);
|
|
265
|
-
|
|
266
|
-
// Skip loading state for cached fonts
|
|
267
|
-
loadingStates.set(file.id, false);
|
|
268
|
-
errorStates.set(file.id, false);
|
|
269
|
-
file.isMissing = false;
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
257
|
+
await loadFontForDisplay(file);
|
|
258
|
+
cachedFonts.set(file.id, true);
|
|
272
259
|
}
|
|
273
260
|
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (isCached) {
|
|
280
|
-
// Skip loading state for cached SVGs
|
|
281
|
-
loadingStates.set(file.id, false);
|
|
282
|
-
errorStates.set(file.id, false);
|
|
283
|
-
file.isMissing = false;
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// For video and SVG files, only check the file existence
|
|
289
|
-
if (isVideo || isSvg) {
|
|
290
|
-
const fileExists = await checkFileExists(file.url);
|
|
291
|
-
file.isMissing = !fileExists;
|
|
292
|
-
errorStates.set(file.id, !fileExists);
|
|
293
|
-
loadingStates.set(file.id, false);
|
|
294
|
-
} else {
|
|
295
|
-
// For other files, keep existing logic
|
|
296
|
-
const exists = await checkFileExists(file.url);
|
|
297
|
-
file.isMissing = !exists;
|
|
298
|
-
errorStates.set(file.id, !exists);
|
|
299
|
-
loadingStates.set(file.id, false);
|
|
300
|
-
}
|
|
261
|
+
// Mount images/media directly without blocking HEAD request waterfalls
|
|
262
|
+
loadingStates.set(file.id, false);
|
|
263
|
+
errorStates.set(file.id, false);
|
|
264
|
+
file.isMissing = false;
|
|
301
265
|
} catch (error) {
|
|
302
266
|
if(showLogs) console.error('Error checking file:', file.name, error);
|
|
303
267
|
file.isMissing = true;
|
|
@@ -21,14 +21,15 @@
|
|
|
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 { isMobileStore } from '../../stores/viewportStore';
|
|
32
|
+
import { buildTransformedUrl } from '../../utils/imageTransform';
|
|
32
33
|
import EaseOut from '@tabler/icons-svelte/icons/ease-out';
|
|
33
34
|
import { getAssetUrl } from '../../utils/fileUtils';
|
|
34
35
|
|
|
@@ -49,15 +50,17 @@
|
|
|
49
50
|
|
|
50
51
|
|
|
51
52
|
// Reactive declarations for file type handling
|
|
52
|
-
$: fileType =
|
|
53
|
+
$: fileType = getItemFileType(item);
|
|
53
54
|
$: isVideo = fileType === 'video';
|
|
54
55
|
$: isImage = fileType === 'image';
|
|
55
56
|
$: isAudio = fileType === 'audio';
|
|
56
|
-
// $: isDocument = fileType === 'document'; - this is not used because we don't preview documents
|
|
57
57
|
$: isSvg = fileType === 'svg';
|
|
58
58
|
$: isFont = fileType === 'font';
|
|
59
59
|
$: fileIcon = getFileIcon(item.name);
|
|
60
60
|
$: fontName = item.name.replace(/\.[^/.]+$/, '');
|
|
61
|
+
$: previewSrc = item.thumbnail || item.url || '';
|
|
62
|
+
$: isLikelyRemoteImage = !!(previewSrc && /^(https?:|blob:|data:image)/i.test(previewSrc));
|
|
63
|
+
$: showImageThumb = isImage || isSvg || (isLikelyRemoteImage && !isAudio && !isVideo && !isFont);
|
|
61
64
|
|
|
62
65
|
// State for file availability and loading
|
|
63
66
|
let isLoading = true;
|
|
@@ -77,12 +80,15 @@
|
|
|
77
80
|
let isIntersecting = false;
|
|
78
81
|
let shouldLoad = false;
|
|
79
82
|
|
|
83
|
+
$: if (previewSrc || showImageThumb) shouldLoad = true;
|
|
84
|
+
|
|
80
85
|
// Keep track of font loading state
|
|
81
86
|
let fontLoadingStarted = false;
|
|
82
87
|
let fontLoadAttempts = 0;
|
|
83
88
|
const MAX_FONT_LOAD_ATTEMPTS = 3;
|
|
84
89
|
|
|
85
|
-
let isMobile
|
|
90
|
+
export let isMobile: boolean | undefined = undefined;
|
|
91
|
+
$: effectiveIsMobile = isMobile !== undefined ? isMobile : $isMobileStore;
|
|
86
92
|
|
|
87
93
|
// Add these state variables at the top with other state variables
|
|
88
94
|
let isNavigating = true;
|
|
@@ -95,15 +101,16 @@
|
|
|
95
101
|
// Flag to determine if we should show thumbhash (only during initial load)
|
|
96
102
|
let showThumbhash = false;
|
|
97
103
|
|
|
104
|
+
// Tweened store for smooth fade-in
|
|
98
105
|
// Tweened store for smooth fade-in
|
|
99
106
|
let opacity = tweened(0, {
|
|
100
|
-
duration:
|
|
107
|
+
duration: 280,
|
|
101
108
|
easing: cubicOut
|
|
102
109
|
});
|
|
103
110
|
|
|
104
111
|
// Tweened store for thumbhash fade-in
|
|
105
112
|
let thumbhashOpacity = tweened(0, {
|
|
106
|
-
duration:
|
|
113
|
+
duration: 200,
|
|
107
114
|
easing: cubicOut
|
|
108
115
|
});
|
|
109
116
|
|
|
@@ -185,10 +192,6 @@
|
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
|
|
188
|
-
function handleResize() {
|
|
189
|
-
isMobile = window.innerWidth <= 768;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
195
|
onMount(() => {
|
|
193
196
|
// console.log('FileItem mounted:', item, isMissing, imageMissing);
|
|
194
197
|
|
|
@@ -202,6 +205,14 @@
|
|
|
202
205
|
initialLoad = false;
|
|
203
206
|
}, 100);
|
|
204
207
|
|
|
208
|
+
// Always mount the <img> for remote/image files. Skeleton stays until onload fade-in.
|
|
209
|
+
if (previewSrc || isImage || isSvg || showImageThumb) {
|
|
210
|
+
shouldLoad = true;
|
|
211
|
+
if (!isImageCached) {
|
|
212
|
+
opacity.set(0, { duration: 0 });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
205
216
|
// Check cache status immediately for instant display
|
|
206
217
|
if (!isFont) {
|
|
207
218
|
const src = item.thumbnail || item.url;
|
|
@@ -217,9 +228,9 @@
|
|
|
217
228
|
});
|
|
218
229
|
} else {
|
|
219
230
|
showThumbhash = !!(item.thumbnail && item.hash && !thumbnailMissing);
|
|
220
|
-
|
|
231
|
+
// Keep the <img> visible — fade-from-0 never completes if onload is skipped.
|
|
232
|
+
opacity.set(1, { duration: 0 });
|
|
221
233
|
if (showThumbhash) {
|
|
222
|
-
// Just fade in the thumbhash
|
|
223
234
|
thumbhashOpacity.set(1);
|
|
224
235
|
}
|
|
225
236
|
}
|
|
@@ -251,47 +262,17 @@
|
|
|
251
262
|
}
|
|
252
263
|
}
|
|
253
264
|
|
|
254
|
-
window.addEventListener('resize', handleResize);
|
|
255
|
-
|
|
256
265
|
return () => {
|
|
257
266
|
if (observer) {
|
|
258
267
|
observer.disconnect();
|
|
259
268
|
}
|
|
260
|
-
if (fontFace) {
|
|
261
|
-
try {
|
|
262
|
-
document.fonts.delete(fontFace);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error('Error cleaning up font:', { error, fontName });
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
window.removeEventListener('resize', handleResize);
|
|
268
269
|
};
|
|
269
270
|
});
|
|
270
271
|
|
|
271
272
|
async function checkFileExistence() {
|
|
272
|
-
|
|
273
|
-
if (!isFont) {
|
|
274
|
-
// Check if file from url exists
|
|
275
|
-
const imageExists = await checkFileExists(item.url, 'image');
|
|
276
|
-
|
|
277
|
-
// Check if thumbnail file exists
|
|
278
|
-
if (imageExists && item.thumbnail) {
|
|
279
|
-
await checkFileExists(item.thumbnail, 'thumbnail');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Set isMissing to true if file does not exist
|
|
283
|
-
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
|
-
if (imageExists) {
|
|
288
|
-
removeMissingFile(item.id);
|
|
289
|
-
} else {
|
|
290
|
-
addMissingFile(item.id);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
273
|
+
// Mount image/thumbnail directly; onerror path is source of truth for missing items
|
|
294
274
|
isLoading = false;
|
|
275
|
+
shouldLoad = true;
|
|
295
276
|
}
|
|
296
277
|
|
|
297
278
|
/**
|
|
@@ -330,16 +311,13 @@
|
|
|
330
311
|
}
|
|
331
312
|
|
|
332
313
|
if ((isVideo || isImage || isAudio) && item.thumbnail) {
|
|
333
|
-
isImageCached = checkImageCache(item.thumbnail);
|
|
334
314
|
return item.thumbnail;
|
|
335
315
|
}
|
|
336
316
|
|
|
337
317
|
if ((isImage || isSvg || isAudio) && item.url) {
|
|
338
|
-
isImageCached = checkImageCache(item.url);
|
|
339
318
|
return item.url;
|
|
340
319
|
}
|
|
341
320
|
|
|
342
|
-
isImageCached = true;
|
|
343
321
|
return getAssetUrl(fileIcon);
|
|
344
322
|
}
|
|
345
323
|
|
|
@@ -476,8 +454,8 @@
|
|
|
476
454
|
<div
|
|
477
455
|
class="file-item-ct relative {thumbnailOnly ? '' : 'w-full'} widgetic-colors widgetic-radius group rounded-[var(--radius-large)]"
|
|
478
456
|
class:cursor-pointer={!isMissing && allowSelecting}
|
|
479
|
-
class:hover:bg-[hsl(var(--grey1))]={!
|
|
480
|
-
class:hover:bg-[hsl(var(--light-green))]={!
|
|
457
|
+
class:hover:bg-[hsl(var(--grey1))]={!effectiveIsMobile && allowSelecting && !isMissing && !selected}
|
|
458
|
+
class:hover:bg-[hsl(var(--light-green))]={!effectiveIsMobile && allowSelecting && !isMissing && selected}
|
|
481
459
|
class:bg-[hsl(var(--light-green))]={selected}
|
|
482
460
|
class:h-[54px]={!thumbnailOnly && !gridLayout}
|
|
483
461
|
class:min-h-[96px]={gridLayout && !thumbnailOnly}
|
|
@@ -501,14 +479,18 @@
|
|
|
501
479
|
"
|
|
502
480
|
onclick={handleIconClick}
|
|
503
481
|
aria-label="Preview {item.name}"
|
|
504
|
-
disabled={isMissing
|
|
482
|
+
disabled={isMissing}
|
|
505
483
|
>
|
|
506
|
-
<div class="w-full h-full flex items-center justify-center">
|
|
507
|
-
<!--
|
|
508
|
-
{#if
|
|
484
|
+
<div class="w-full h-full flex items-center justify-center relative">
|
|
485
|
+
<!-- Image thumbs: skeleton overlay until onload, then fade in -->
|
|
486
|
+
{#if showImageThumb && shouldLoad && !imageLoaded && !isImageCached}
|
|
487
|
+
<div class="fb-thumb-loader-ct absolute inset-0 z-20 overflow-hidden rounded-[var(--radius-large)]">
|
|
488
|
+
<LoadingSkeleton width="100%" height="100%" />
|
|
489
|
+
</div>
|
|
490
|
+
{:else if isLoading && shouldLoad && !imageLoaded && !isImageCached && !showImageThumb}
|
|
509
491
|
<LoadingSkeleton width="100%" height="100%" />
|
|
510
|
-
|
|
511
|
-
{
|
|
492
|
+
{/if}
|
|
493
|
+
{#if shouldLoad}
|
|
512
494
|
<!-- Font Icon -->
|
|
513
495
|
{#if isFont}
|
|
514
496
|
<span
|
|
@@ -526,7 +508,7 @@
|
|
|
526
508
|
/>
|
|
527
509
|
<!-- Audio or Document Icon -->
|
|
528
510
|
{:else if !imageMissing}
|
|
529
|
-
{#if isAudio || fileType === 'document'}
|
|
511
|
+
{#if isAudio || (fileType === 'document' && !showImageThumb)}
|
|
530
512
|
<img
|
|
531
513
|
src={getAssetUrl(getFileIcon(item.name))}
|
|
532
514
|
alt={isAudio ? 'Audio file' : 'Document file'}
|
|
@@ -551,14 +533,27 @@
|
|
|
551
533
|
|
|
552
534
|
<!-- Thumbnail Image -->
|
|
553
535
|
<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"
|
|
536
|
+
src={previewSrc}
|
|
557
537
|
alt={item.name}
|
|
538
|
+
referrerpolicy="no-referrer"
|
|
558
539
|
style="opacity: {$opacity}; z-index: 10;"
|
|
559
540
|
onerror={(e: any) => {
|
|
560
|
-
console.log(`[FileItem ${item.name}] Thumbnail error:`,
|
|
541
|
+
// console.log(`[FileItem ${item.name}] Thumbnail error:`, previewSrc);
|
|
542
|
+
const imgEl = e.currentTarget as HTMLImageElement;
|
|
543
|
+
if (imgEl.srcset) {
|
|
544
|
+
imgEl.srcset = '';
|
|
545
|
+
imgEl.sizes = '';
|
|
546
|
+
imgEl.src = item.url || previewSrc;
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (item.thumbnail && item.url && previewSrc === item.thumbnail && imgEl.src !== item.url) {
|
|
550
|
+
imgEl.src = item.url;
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
561
553
|
thumbnailMissing = true;
|
|
554
|
+
imageMissing = true;
|
|
555
|
+
opacity.set(1);
|
|
556
|
+
isLoading = false;
|
|
562
557
|
}}
|
|
563
558
|
onload={handleImageLoad}
|
|
564
559
|
/>
|
|
@@ -617,7 +612,7 @@
|
|
|
617
612
|
<div class="absolute top-[17px] right-4 z-10">
|
|
618
613
|
<button
|
|
619
614
|
class="w-5 h-5 text-[hsl(var(--error))] opacity-0 group-hover:opacity-100 transition-opacity duration-200"
|
|
620
|
-
class:!opacity-100={
|
|
615
|
+
class:!opacity-100={effectiveIsMobile}
|
|
621
616
|
onclick={(e) => {
|
|
622
617
|
e.stopPropagation();
|
|
623
618
|
dispatch('delete', { item });
|
|
@@ -22,6 +22,7 @@ declare const FileItem: $$__sveltets_2_IsomorphicComponent<{
|
|
|
22
22
|
preventFontLoad?: boolean;
|
|
23
23
|
currentFilter?: FileFilterType;
|
|
24
24
|
/** Vertical grid cell (icon above centered label). */ gridLayout?: boolean;
|
|
25
|
+
isMobile?: boolean | undefined;
|
|
25
26
|
}, {
|
|
26
27
|
delete: CustomEvent<any>;
|
|
27
28
|
click: CustomEvent<any>;
|
|
@@ -4,24 +4,16 @@
|
|
|
4
4
|
import { getFolderIcon } from '../../utils/folderUtils';
|
|
5
5
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
6
6
|
import { DropdownMenu } from '../ui';
|
|
7
|
-
import {
|
|
7
|
+
import { isMobileStore } from '../../stores/viewportStore';
|
|
8
8
|
|
|
9
9
|
export let item: FolderItemWithCount;
|
|
10
10
|
export let currentFilter: FileFilterType = 'all';
|
|
11
11
|
export let gridLayout = false;
|
|
12
|
+
export let isMobile: boolean | undefined = undefined;
|
|
12
13
|
|
|
13
14
|
const dispatch = createEventDispatcher();
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function handleResize() {
|
|
18
|
-
isMobile = window.innerWidth <= 768;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
onMount(() => {
|
|
22
|
-
window.addEventListener('resize', handleResize);
|
|
23
|
-
return () => window.removeEventListener('resize', handleResize);
|
|
24
|
-
});
|
|
16
|
+
$: effectiveIsMobile = isMobile !== undefined ? isMobile : $isMobileStore;
|
|
25
17
|
|
|
26
18
|
function handleIconClick(event: Event) {
|
|
27
19
|
event.stopPropagation();
|
|
@@ -68,7 +60,7 @@
|
|
|
68
60
|
</div>
|
|
69
61
|
|
|
70
62
|
<div
|
|
71
|
-
class="fb-folder-menu-ct opacity-0 group-hover:opacity-100 transition-opacity duration-200 w-5 h-5 {
|
|
63
|
+
class="fb-folder-menu-ct opacity-0 group-hover:opacity-100 transition-opacity duration-200 w-5 h-5 {effectiveIsMobile ? '!opacity-100' : ''} {gridLayout ? 'mt-0.5' : 'absolute right-4 top-1/2 -translate-y-1/2'}"
|
|
72
64
|
>
|
|
73
65
|
<DropdownMenu isFolder={true} on:action={handleDropdownAction} />
|
|
74
66
|
</div>
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
|
|
57
57
|
// Add a reactive statement to log when the dialog opens
|
|
58
58
|
$: if (isOpen) {
|
|
59
|
-
console.log('MoveDialog opened with:', {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
59
|
+
// console.log('MoveDialog opened with:', {
|
|
60
|
+
// sourceItems: sourceItems.map(item => ({
|
|
61
|
+
// id: item.id,
|
|
62
|
+
// name: item.name,
|
|
63
|
+
// type: item.type
|
|
64
|
+
// })),
|
|
65
|
+
// itemCount: sourceItems.length,
|
|
66
|
+
// hasFolders: sourceItems.some(item => item.type === 'folder')
|
|
67
|
+
// });
|
|
68
68
|
// Reset selection when dialog opens
|
|
69
69
|
selectedFolder = undefined;
|
|
70
70
|
}
|
|
@@ -127,11 +127,11 @@
|
|
|
127
127
|
* @param targetFolderId ID of the destination folder
|
|
128
128
|
*/
|
|
129
129
|
async function handleMove(targetFolderId: string) {
|
|
130
|
-
console.log('handleMove called with:', {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
130
|
+
// console.log('handleMove called with:', {
|
|
131
|
+
// targetFolderId,
|
|
132
|
+
// sourceItems,
|
|
133
|
+
// itemCount
|
|
134
|
+
// });
|
|
135
135
|
|
|
136
136
|
if (!targetFolderId) {
|
|
137
137
|
toast.error(
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
try {
|
|
165
|
-
const actualTargetId = targetFolderId === 'root' ? '' : targetFolderId;
|
|
165
|
+
const actualTargetId = (targetFolderId === 'root' || targetFolderId === $fileStore?.root?.id) ? '' : targetFolderId;
|
|
166
166
|
const movedItems: { id: string; name: string }[] = [];
|
|
167
167
|
|
|
168
168
|
// Helper function to find the complete path to a folder
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
|
|
190
190
|
// Get the complete path to the target folder
|
|
191
191
|
const targetPath = actualTargetId ? findFolderPath($fileStore.root, actualTargetId) : [];
|
|
192
|
-
console.log('Found target path:', targetPath);
|
|
192
|
+
// console.log('Found target path:', targetPath);
|
|
193
193
|
|
|
194
194
|
// Move all items at once
|
|
195
195
|
const results = await Promise.allSettled(
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
// Clear the item from selections
|
|
231
|
-
persistentSelectStore.
|
|
231
|
+
persistentSelectStore.removeSelection(sourceItem.id, currentFilter);
|
|
232
232
|
|
|
233
233
|
// Dispatch move event for each successful move
|
|
234
234
|
dispatch('move', {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
// Svelte imports
|
|
14
|
-
import { onMount } from 'svelte';
|
|
14
|
+
import { onMount, onDestroy } from 'svelte';
|
|
15
15
|
import { createEventDispatcher } from 'svelte';
|
|
16
16
|
const dispatch = createEventDispatcher();
|
|
17
17
|
|
|
@@ -74,18 +74,34 @@
|
|
|
74
74
|
activeIndex = index;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
78
|
+
|
|
79
|
+
onDestroy(() => {
|
|
80
|
+
if (searchDebounceTimer) {
|
|
81
|
+
clearTimeout(searchDebounceTimer);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
77
85
|
/**
|
|
78
86
|
* Reactive statement to update search results when search term changes
|
|
79
|
-
* Filters results based on current filter type and excludes root folder
|
|
87
|
+
* Filters results based on current filter type and excludes root folder.
|
|
88
|
+
* Debounced by 150ms to prevent expensive full-tree traversals on every keystroke.
|
|
80
89
|
*/
|
|
81
90
|
$: {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
const term = $searchTermStore?.trim().toLowerCase();
|
|
92
|
+
const filter = currentFilter;
|
|
93
|
+
const root = $fileStore.root;
|
|
94
|
+
|
|
95
|
+
if (searchDebounceTimer) {
|
|
96
|
+
clearTimeout(searchDebounceTimer);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (term) {
|
|
100
|
+
searchDebounceTimer = setTimeout(() => {
|
|
101
|
+
searchResults = searchFileSystem(root, term)
|
|
102
|
+
.filter(item => item.name !== 'Root' && (item.type === 'folder' || matchesFilter(item)));
|
|
103
|
+
activeIndex = 0;
|
|
104
|
+
}, 150);
|
|
89
105
|
} else {
|
|
90
106
|
searchResults = [];
|
|
91
107
|
activeIndex = -1;
|
|
@@ -168,9 +184,9 @@
|
|
|
168
184
|
* Updates current path and closes search modal
|
|
169
185
|
*/
|
|
170
186
|
function handleResultClick(item: FileSystemItem) {
|
|
171
|
-
console.log('handleResultClick called with item:', item);
|
|
187
|
+
// console.log('handleResultClick called with item:', item);
|
|
172
188
|
const idPath = findItemPath($fileStore.root, item);
|
|
173
|
-
console.log('ID Path found:', idPath);
|
|
189
|
+
// console.log('ID Path found:', idPath);
|
|
174
190
|
|
|
175
191
|
if (idPath) {
|
|
176
192
|
// Remove root ID from the beginning of the path
|
|
@@ -184,7 +200,7 @@
|
|
|
184
200
|
}, 100);
|
|
185
201
|
}
|
|
186
202
|
|
|
187
|
-
console.log('Dispatching navigate event with ID path:', folderPath);
|
|
203
|
+
// console.log('Dispatching navigate event with ID path:', folderPath);
|
|
188
204
|
dispatch('navigate', { path: folderPath });
|
|
189
205
|
} else {
|
|
190
206
|
console.error('Path not found for item:', item);
|
|
@@ -228,7 +244,7 @@
|
|
|
228
244
|
const fileType = getFileType(item.url || item.name);
|
|
229
245
|
const matches = fileType === currentFilter;
|
|
230
246
|
if (fileType === 'font') {
|
|
231
|
-
console.log('Font file found in search:', item.name, 'URL:', item.url);
|
|
247
|
+
// console.log('Font file found in search:', item.name, 'URL:', item.url);
|
|
232
248
|
}
|
|
233
249
|
// console.log('Item matches filter:', matches);
|
|
234
250
|
return matches;
|
|
@@ -308,33 +324,6 @@
|
|
|
308
324
|
// console.log('Item path for', item.name, ':', path?.join('/') || '');
|
|
309
325
|
return path ? path.join('/') : item.id; // Fallback to ID if path not found
|
|
310
326
|
}
|
|
311
|
-
|
|
312
|
-
// Add logging to the search results
|
|
313
|
-
$: {
|
|
314
|
-
if ($searchTermStore) {
|
|
315
|
-
// Make this reactive statement depend on currentFilter as well
|
|
316
|
-
searchResults = searchFileSystem($fileStore.root, $searchTermStore.toLowerCase())
|
|
317
|
-
.filter(item => item.name !== 'Root' && (item.type === 'folder' || matchesFilter(item)));
|
|
318
|
-
console.log(`Search results filtered by '${currentFilter}' type:`, searchResults.length);
|
|
319
|
-
activeIndex = 0;
|
|
320
|
-
} else {
|
|
321
|
-
searchResults = [];
|
|
322
|
-
activeIndex = -1;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Add a new reactive statement specifically for filter changes
|
|
327
|
-
$: if (currentFilter) {
|
|
328
|
-
// console.log('Filter changed to:', currentFilter);
|
|
329
|
-
// If we have an existing search term, re-filter the results
|
|
330
|
-
if ($searchTermStore) {
|
|
331
|
-
searchResults = searchFileSystem($fileStore.root, $searchTermStore.toLowerCase())
|
|
332
|
-
.filter(item => item.name !== 'Root' && (item.type === 'folder' || matchesFilter(item)));
|
|
333
|
-
console.log(`Re-filtered search results by '${currentFilter}' type:`, searchResults.length);
|
|
334
|
-
// Reset the active index when filter changes
|
|
335
|
-
activeIndex = 0;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
327
|
</script>
|
|
339
328
|
|
|
340
329
|
<!-- Search Modal Layout -->
|
|
@@ -390,7 +379,7 @@
|
|
|
390
379
|
bind:this={resultsContainer}
|
|
391
380
|
style="min-height: {scrolledAreaMaxHeight}px; padding: 0;"
|
|
392
381
|
>
|
|
393
|
-
{#each searchResults as result, index (
|
|
382
|
+
{#each searchResults as result, index (result.id || `${result.type}-${index}`)}
|
|
394
383
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
395
384
|
<div
|
|
396
385
|
class="search-result-item relative w-full mx-auto rounded-large widgetic-radius"
|
|
@@ -124,8 +124,8 @@
|
|
|
124
124
|
? idPath.slice(1, -1) // Remove root ID and file ID
|
|
125
125
|
: idPath.slice(0, -1); // Just remove file ID
|
|
126
126
|
|
|
127
|
-
console.log('Found ID path:', idPath);
|
|
128
|
-
console.log('Folder path to navigate to:', folderPath);
|
|
127
|
+
// console.log('Found ID path:', idPath);
|
|
128
|
+
// console.log('Folder path to navigate to:', folderPath);
|
|
129
129
|
|
|
130
130
|
// Close the modal first
|
|
131
131
|
dispatch('close');
|