@widgetic/file-browser 0.5.35 → 0.5.37
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/README.md +1 -0
- package/dist/components/FolderTree.svelte +46 -97
- package/dist/components/FolderTree.svelte.d.ts +5 -1
- package/dist/components/core/Dropzone.svelte +127 -0
- package/dist/components/core/Dropzone.svelte.d.ts +15 -0
- package/dist/components/core/FileBrowser.css +11 -79
- package/dist/components/core/FileBrowser.svelte +277 -149
- package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
- package/dist/components/core/FileUploader.svelte +204 -418
- package/dist/components/core/FileUploader.svelte.d.ts +1 -0
- package/dist/components/core/Header.svelte +51 -68
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +135 -562
- package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
- package/dist/components/core/UploadPanel.svelte +169 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
- package/dist/components/core/UploadRow.svelte +90 -0
- package/dist/components/core/UploadRow.svelte.d.ts +21 -0
- package/dist/components/core/UploadStatus.svelte +34 -128
- package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
- package/dist/components/core/UploadStatusList.svelte +61 -77
- package/dist/components/items/FileItem.svelte +190 -532
- package/dist/components/items/FileItem.svelte.d.ts +1 -1
- package/dist/components/items/FolderItem.svelte +46 -36
- package/dist/components/items/FolderItem.svelte.d.ts +1 -1
- package/dist/components/modals/MoveDialog.svelte +142 -281
- package/dist/components/modals/NewFolderButton.svelte +13 -14
- package/dist/components/modals/SearchModal.svelte +112 -264
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
- package/dist/components/modals/SelectedFilesModal.svelte +91 -167
- package/dist/components/previews/AudioPlayer.svelte +75 -58
- package/dist/components/previews/ErrorPreview.svelte +9 -6
- package/dist/components/previews/FilePreview.svelte +173 -53
- package/dist/components/previews/FontPreview.svelte +37 -54
- package/dist/components/previews/ImagePreview.svelte +9 -2
- package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
- package/dist/components/previews/TextPreview.svelte +32 -40
- package/dist/components/previews/VideoPlayer.svelte +124 -149
- package/dist/components/previews/WaveformVisualizer.svelte +42 -222
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
- package/dist/components/ui/ControlToolbar.svelte +113 -288
- package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
- package/dist/components/ui/DragSelect.svelte +41 -248
- package/dist/components/ui/DropdownMenu.svelte +56 -55
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/components/ui/FileIcon.svelte +168 -51
- package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
- package/dist/components/ui/FileMetadata.svelte +20 -9
- package/dist/components/ui/LoadingSkeleton.svelte +5 -20
- package/dist/components/ui/SearchResults.svelte +50 -26
- package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
- package/dist/components/ui/SelectedBadge.svelte +25 -0
- package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TileSkeleton.svelte +15 -0
- package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
- package/dist/components/ui/VirtualList.svelte +3 -0
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/i18n/messages.d.ts +38 -25
- package/dist/i18n/messages.js +39 -26
- package/dist/utils/gridLayout.d.ts +2 -0
- package/dist/utils/gridLayout.js +10 -0
- package/package.json +3 -4
|
@@ -1,112 +1,71 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Displays
|
|
5
|
-
* Supports file selection, preview, and dropdown actions
|
|
3
|
+
* Recent files grid — Figma "Recent Card" (267:179).
|
|
4
|
+
* Displays recently accessed files with thumbnails, preview, and selection.
|
|
6
5
|
*/
|
|
7
6
|
import type { FileSystemItem } from '../../types';
|
|
8
7
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
9
|
-
import { getFileIcon } from '../../utils/fileUtils';
|
|
10
8
|
import { getFileTypeOf } from '../../utils/fileKinds';
|
|
11
|
-
import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
|
|
12
9
|
import { formatRelativeDate } from '../../utils/dateUtils';
|
|
13
10
|
import { useI18n, type Translate } from '../../i18n';
|
|
14
11
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
15
|
-
import {
|
|
12
|
+
import { FileIcon, SelectedBadge } from '../ui';
|
|
16
13
|
import { type FileFilterType } from '../../utils/fileTypes';
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import { IconExclamationCircle } from '@widgetic/design-system/icons';
|
|
14
|
+
import { ThumbHashImage } from '@widgetic/design-system/components';
|
|
15
|
+
import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
|
|
20
16
|
import { browser } from '$app/environment';
|
|
21
|
-
import { getAssetUrl } from '../../utils/fileUtils';
|
|
22
17
|
|
|
23
|
-
/* COMPONENT PROPS */
|
|
24
18
|
let className = '';
|
|
25
19
|
export { className as class };
|
|
26
20
|
export let style: string = '';
|
|
27
|
-
//
|
|
28
21
|
export let recentFiles: FileSystemItem[] = [];
|
|
29
22
|
export let selectedFiles: FileSystemItem[] = [];
|
|
30
23
|
// svelte-ignore export_let_unused
|
|
31
24
|
export let currentFilter: FileFilterType = 'all';
|
|
32
25
|
export let allowSelecting: boolean = false;
|
|
33
|
-
export let columnWidth: number = 40;
|
|
26
|
+
export let columnWidth: number = 40;
|
|
34
27
|
|
|
35
28
|
const { t } = useI18n();
|
|
36
|
-
// The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
|
|
37
29
|
const textDirection = useTextDirection();
|
|
38
30
|
$: nameDirection = dirForUserText($textDirection);
|
|
39
31
|
|
|
40
|
-
/* STATE VARS */
|
|
41
|
-
// Responsive breakpoints from global.css
|
|
42
32
|
const DESKTOP_BREAKPOINT = 1156;
|
|
43
33
|
const TABLET_BREAKPOINT = 744;
|
|
44
|
-
const MOBILE_BREAKPOINT = 393;
|
|
45
34
|
|
|
46
|
-
// Responsive vars
|
|
47
35
|
let windowWidth = browser ? window.innerWidth : DESKTOP_BREAKPOINT;
|
|
48
|
-
let gridColumns = 3;
|
|
49
|
-
let maxRecentFiles = 3;
|
|
50
|
-
|
|
51
|
-
// Logs
|
|
36
|
+
let gridColumns = 3;
|
|
37
|
+
let maxRecentFiles = 3;
|
|
52
38
|
let showLogs = false;
|
|
53
39
|
|
|
54
|
-
/* METHODS */
|
|
55
|
-
// Update grid columns and max files based on window width
|
|
56
40
|
function updateResponsiveLayout() {
|
|
57
41
|
if (windowWidth > DESKTOP_BREAKPOINT) {
|
|
58
|
-
// For large desktop screens, show more files
|
|
59
42
|
const availableWidth = windowWidth;
|
|
60
|
-
// Calculate how many columns would fit nicely
|
|
61
43
|
gridColumns = Math.min(6, Math.floor(availableWidth / 300));
|
|
62
|
-
|
|
63
|
-
maxRecentFiles = gridColumns * 2; // Two rows of content
|
|
44
|
+
maxRecentFiles = gridColumns * 2;
|
|
64
45
|
} else if (windowWidth > TABLET_BREAKPOINT) {
|
|
65
|
-
// Standard desktop
|
|
66
46
|
gridColumns = 3;
|
|
67
|
-
maxRecentFiles = 6;
|
|
47
|
+
maxRecentFiles = 6;
|
|
68
48
|
} else {
|
|
69
|
-
// Tablet and below - we don't show recent files on these sizes
|
|
70
|
-
// but keeping the logic for completeness
|
|
71
49
|
gridColumns = 2;
|
|
72
50
|
maxRecentFiles = 4;
|
|
73
51
|
}
|
|
74
|
-
|
|
75
|
-
if(showLogs) console.log('Responsive layout updated:', { windowWidth, gridColumns, maxRecentFiles });
|
|
52
|
+
if (showLogs) console.log('Responsive layout updated:', { windowWidth, gridColumns, maxRecentFiles });
|
|
76
53
|
}
|
|
77
54
|
|
|
78
|
-
//
|
|
79
|
-
$: gridGap =
|
|
80
|
-
$: numberOfColumns = gridColumns;
|
|
81
|
-
|
|
82
|
-
// Debug log to monitor size calculations
|
|
83
|
-
$: if(showLogs) console.log('RecentFiles sizing:', { columnWidth, numberOfColumns, gridGap, maxRecentFiles });
|
|
55
|
+
// Figma Recent cards sit 24px apart (the tiles above them 16)
|
|
56
|
+
$: gridGap = 24;
|
|
57
|
+
$: numberOfColumns = gridColumns;
|
|
58
|
+
$: if (showLogs) console.log('RecentFiles sizing:', { columnWidth, numberOfColumns, gridGap, maxRecentFiles });
|
|
84
59
|
|
|
85
60
|
const dispatch = createEventDispatcher();
|
|
86
|
-
|
|
87
|
-
// Remove redundant filtering since files are already filtered by parent
|
|
88
61
|
$: filteredRecentFiles = recentFiles.slice(0, maxRecentFiles);
|
|
89
62
|
|
|
90
|
-
// File states
|
|
91
63
|
let loadingStates = new Map<string, boolean>();
|
|
92
64
|
let errorStates = new Map<string, boolean>();
|
|
93
|
-
let imageLoaded = false;
|
|
94
65
|
let loadedStates = new Map<string, boolean>();
|
|
95
66
|
|
|
96
|
-
// Add a map to track cached fonts
|
|
97
|
-
let cachedFonts = new Map<string, boolean>();
|
|
98
|
-
// Add a map to track cached SVGs
|
|
99
|
-
let cachedSvgs = new Map<string, boolean>();
|
|
100
|
-
|
|
101
|
-
function shouldUseFileIcon(file: FileSystemItem): boolean {
|
|
102
|
-
if (file.isMissing || errorStates.get(file.id)) return false;
|
|
103
|
-
const fileType = getFileTypeOf(file);
|
|
104
|
-
return fileType === 'font' && !isFontCached(file);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Initialize loading states for all files
|
|
108
67
|
$: {
|
|
109
|
-
recentFiles.forEach(file => {
|
|
68
|
+
recentFiles.forEach((file) => {
|
|
110
69
|
if (!loadingStates.has(file.id)) {
|
|
111
70
|
loadingStates.set(file.id, true);
|
|
112
71
|
errorStates.set(file.id, false);
|
|
@@ -117,344 +76,91 @@
|
|
|
117
76
|
}
|
|
118
77
|
|
|
119
78
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @returns Promise resolving to boolean indicating file existence
|
|
124
|
-
*/
|
|
125
|
-
async function checkFileExists(url: string | undefined): Promise<boolean> {
|
|
126
|
-
if (!url) return false;
|
|
127
|
-
try {
|
|
128
|
-
const response = await fetch(url, { method: 'HEAD' });
|
|
129
|
-
return response.ok;
|
|
130
|
-
} catch (error) {
|
|
131
|
-
if(showLogs) console.error('Error checking file existence:', error);
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Checks if a font is cached in the browser
|
|
138
|
-
* @param file File to check for font caching
|
|
139
|
-
* @returns Promise resolving to boolean indicating if font is cached
|
|
140
|
-
*/
|
|
141
|
-
async function checkFontCached(file: FileSystemItem): Promise<boolean> {
|
|
142
|
-
const fileType = getFileTypeOf(file);
|
|
143
|
-
if (fileType !== 'font') return false;
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
// Try to check if font is in document.fonts
|
|
147
|
-
if (document.fonts) {
|
|
148
|
-
const fontName = toSafeFontFamilyName(file.name); // Font name without extension, safe inside CSS
|
|
149
|
-
// Try multiple font checks to ensure accurate detection
|
|
150
|
-
const checks = [
|
|
151
|
-
document.fonts.check(`1em "${fontName}"`),
|
|
152
|
-
document.fonts.check(`1em '${fontName}'`)
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
const results = await Promise.all(checks);
|
|
156
|
-
const isCached = results.some(result => result === true);
|
|
157
|
-
if(showLogs) console.log(`Font ${fontName} cached status:`, isCached);
|
|
158
|
-
return isCached;
|
|
159
|
-
}
|
|
160
|
-
} catch (error) {
|
|
161
|
-
if(showLogs) console.error('Error checking font cache:', error);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Checks if an SVG file is cached in the browser
|
|
169
|
-
* @param file File to check for SVG caching
|
|
170
|
-
* @returns Promise resolving to boolean indicating if SVG is cached
|
|
79
|
+
* Marks every recent file as checked, so its card leaves the loading state.
|
|
80
|
+
* Nothing here waits for anything: a font is loaded by the FileIcon that draws it, and a picture that cannot be loaded
|
|
81
|
+
* reports itself through handleImageError. (A card that only left the loading state after an await never redrew.)
|
|
171
82
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (fileType !== 'svg' || !file.url) return false;
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
// More reliable method to check if an image is cached
|
|
178
|
-
return new Promise((resolve) => {
|
|
179
|
-
const img = new Image();
|
|
180
|
-
|
|
181
|
-
// If image loads immediately (from cache), complete will be true
|
|
182
|
-
if (img.complete) {
|
|
183
|
-
if(showLogs) console.log(`SVG ${file.name} found in cache`);
|
|
184
|
-
resolve(true);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Set up load and error handlers
|
|
189
|
-
img.onload = () => {
|
|
190
|
-
if(showLogs) console.log(`SVG ${file.name} loaded but was not cached`);
|
|
191
|
-
resolve(false);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
img.onerror = () => {
|
|
195
|
-
if(showLogs) console.error(`Error loading SVG ${file.name}`);
|
|
196
|
-
resolve(false);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// Set source to trigger load - ensure URL is a string
|
|
200
|
-
if (file.url) {
|
|
201
|
-
img.src = file.url;
|
|
202
|
-
|
|
203
|
-
// Double check for immediate completion (happens with cached images)
|
|
204
|
-
if (img.complete) {
|
|
205
|
-
if(showLogs) console.log(`SVG ${file.name} found in cache (after src set)`);
|
|
206
|
-
resolve(true);
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
// No URL available, can't check cache
|
|
210
|
-
if(showLogs) console.warn(`No URL available for SVG ${file.name}`);
|
|
211
|
-
resolve(false);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if(showLogs) console.error('Error checking SVG cache:', error);
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Explicitly loads a font file to ensure it's available for display
|
|
222
|
-
* @param file Font file to load
|
|
223
|
-
* @returns Promise resolving when loading is complete
|
|
224
|
-
*/
|
|
225
|
-
async function loadFontForDisplay(file: FileSystemItem): Promise<void> {
|
|
226
|
-
if (!file.url) return;
|
|
227
|
-
|
|
228
|
-
// Both the name and the address come from someone else, and this text becomes a style sheet in the page's
|
|
229
|
-
// <head>: the name is reduced to safe characters and the address is written so it cannot leave its quotes.
|
|
230
|
-
const fontName = toSafeFontFamilyName(file.name);
|
|
231
|
-
const fontId = `font-${file.id}`;
|
|
232
|
-
|
|
233
|
-
// Skip if we already added this font
|
|
234
|
-
if (document.getElementById(fontId)) return;
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
// Create a style element with @font-face declaration
|
|
238
|
-
const style = document.createElement('style');
|
|
239
|
-
style.id = fontId;
|
|
240
|
-
style.textContent = `
|
|
241
|
-
@font-face {
|
|
242
|
-
font-family: "${fontName}";
|
|
243
|
-
src: ${toCssUrlLiteral(file.url)} format("opentype");
|
|
244
|
-
font-weight: normal;
|
|
245
|
-
font-style: normal;
|
|
246
|
-
font-display: block;
|
|
247
|
-
}
|
|
248
|
-
`;
|
|
249
|
-
document.head.appendChild(style);
|
|
250
|
-
if(showLogs) console.log(`Added @font-face declaration for font ${fontName}`);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
if(showLogs) console.error(`Failed to load font ${fontName}:`, error);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Check existence of all files
|
|
258
|
-
* Updates loading states and missing flags for each file
|
|
259
|
-
*/
|
|
260
|
-
async function checkFiles() {
|
|
261
|
-
const promises = recentFiles.map(async (file) => {
|
|
83
|
+
function checkFiles() {
|
|
84
|
+
recentFiles.forEach((file) => {
|
|
262
85
|
try {
|
|
263
|
-
const fileType = getFileTypeOf(file);
|
|
264
|
-
const isFont = fileType === 'font';
|
|
265
|
-
|
|
266
|
-
// Load font for display if needed
|
|
267
|
-
if (isFont) {
|
|
268
|
-
await loadFontForDisplay(file);
|
|
269
|
-
cachedFonts.set(file.id, true);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Mount images/media directly without blocking HEAD request waterfalls
|
|
273
86
|
loadingStates.set(file.id, false);
|
|
274
87
|
errorStates.set(file.id, false);
|
|
275
88
|
file.isMissing = false;
|
|
276
89
|
} catch (error) {
|
|
277
|
-
|
|
90
|
+
console.error('Error checking file:', file.name, error);
|
|
278
91
|
file.isMissing = true;
|
|
279
92
|
errorStates.set(file.id, true);
|
|
280
93
|
loadingStates.set(file.id, false);
|
|
281
94
|
}
|
|
282
95
|
});
|
|
283
|
-
|
|
284
|
-
await Promise.all(promises);
|
|
285
96
|
loadingStates = loadingStates;
|
|
286
97
|
errorStates = errorStates;
|
|
287
|
-
cachedFonts = cachedFonts;
|
|
288
|
-
cachedSvgs = cachedSvgs;
|
|
289
98
|
}
|
|
290
99
|
|
|
291
|
-
/**
|
|
292
|
-
* Checks if a file is currently loading
|
|
293
|
-
* @param file File to check loading status
|
|
294
|
-
* @returns boolean indicating if file is loading
|
|
295
|
-
*/
|
|
296
100
|
function isLoading(file: FileSystemItem): boolean {
|
|
297
101
|
return loadingStates.get(file.id) || false;
|
|
298
102
|
}
|
|
299
103
|
|
|
300
|
-
/**
|
|
301
|
-
* Handles image loading errors
|
|
302
|
-
* @param file File that failed to load
|
|
303
|
-
*/
|
|
304
104
|
function handleImageError(file: FileSystemItem) {
|
|
305
105
|
errorStates.set(file.id, true);
|
|
306
106
|
errorStates = errorStates;
|
|
307
107
|
file.isMissing = true;
|
|
308
108
|
}
|
|
309
109
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
* Returns error icon for missing files
|
|
313
|
-
* @param file File to get thumbnail/icon for
|
|
314
|
-
* @returns URL to thumbnail or icon
|
|
315
|
-
*/
|
|
316
|
-
function getThumbnailOrIcon(file: FileSystemItem): string {
|
|
317
|
-
if (isLoading(file)) return '';
|
|
318
|
-
|
|
110
|
+
function shouldShowCoverImage(file: FileSystemItem): boolean {
|
|
111
|
+
if (isLoading(file) || file.isMissing || errorStates.get(file.id)) return false;
|
|
319
112
|
const fileType = getFileTypeOf(file);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (file.isMissing && !isVideo && !isSvg) {
|
|
325
|
-
return getAssetUrl('/icons/error.svg');
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (isSvg) {
|
|
329
|
-
return file.url || '';
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (fileType === 'image') {
|
|
333
|
-
return file.url || '';
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (isVideo) {
|
|
337
|
-
return file.thumbnail || '';
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (isAudio) {
|
|
341
|
-
return getAssetUrl(getFileIcon(file.name));
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return getAssetUrl(getFileIcon(file.name));
|
|
113
|
+
if (fileType === 'image') return !!file.url;
|
|
114
|
+
if (fileType === 'video') return !!(file.thumbnail || file.url);
|
|
115
|
+
return false;
|
|
345
116
|
}
|
|
346
117
|
|
|
347
|
-
|
|
348
|
-
* Checks if file is a media type (video/audio)
|
|
349
|
-
* @param file File to check
|
|
350
|
-
* @returns boolean indicating if file is media
|
|
351
|
-
*/
|
|
352
|
-
function isMediaFile(file: FileSystemItem): boolean {
|
|
118
|
+
function getCoverSrc(file: FileSystemItem): string {
|
|
353
119
|
const fileType = getFileTypeOf(file);
|
|
354
|
-
|
|
120
|
+
if (fileType === 'video') return file.thumbnail || file.url || '';
|
|
121
|
+
return file.url || '';
|
|
355
122
|
}
|
|
356
123
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
* Returns light red for missing files
|
|
360
|
-
* @param file File to get background for
|
|
361
|
-
* @returns CSS color value
|
|
362
|
-
*/
|
|
363
|
-
function getBackgroundColor(file: FileSystemItem): string {
|
|
364
|
-
if (file.isMissing || errorStates.get(file.id)) return '#FFF5F5';
|
|
365
|
-
const fileType = getFileTypeOf(file);
|
|
366
|
-
if (fileType === 'audio') return '#A7FF68';
|
|
367
|
-
if (fileType === 'document') return '#FFDC68';
|
|
368
|
-
return 'bg-gray-100';
|
|
124
|
+
function isVideoFile(file: FileSystemItem): boolean {
|
|
125
|
+
return getFileTypeOf(file) === 'video';
|
|
369
126
|
}
|
|
370
127
|
|
|
371
|
-
/**
|
|
372
|
-
* Determines if file should use SVG icon display
|
|
373
|
-
* @param file File to check
|
|
374
|
-
* @returns boolean indicating if SVG icon should be used
|
|
375
|
-
*/
|
|
376
|
-
function isSvgIcon(file: FileSystemItem): boolean {
|
|
377
|
-
const fileType = getFileTypeOf(file);
|
|
378
|
-
return fileType === 'svg';
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Handles file preview click
|
|
383
|
-
* Only triggers for non-missing files
|
|
384
|
-
* @param file File to preview
|
|
385
|
-
*/
|
|
386
128
|
function handleFileClick(file: FileSystemItem) {
|
|
387
129
|
if (!file.isMissing && !errorStates.get(file.id)) {
|
|
388
130
|
dispatch('fileClick', file);
|
|
389
131
|
}
|
|
390
132
|
}
|
|
391
133
|
|
|
392
|
-
/**
|
|
393
|
-
* Handles file selection toggle
|
|
394
|
-
* @param file File to select/deselect
|
|
395
|
-
*/
|
|
396
134
|
function handleFileSelect(file: FileSystemItem) {
|
|
397
135
|
dispatch('select', file);
|
|
398
136
|
}
|
|
399
137
|
|
|
400
|
-
/**
|
|
401
|
-
* Checks if a file is currently selected
|
|
402
|
-
* @param file File to check selection status
|
|
403
|
-
* @returns boolean indicating if file is selected
|
|
404
|
-
*/
|
|
405
138
|
function isSelected(file: FileSystemItem): boolean {
|
|
406
|
-
return selectedFiles.some(selectedFile => selectedFile.id === file.id);
|
|
139
|
+
return selectedFiles.some((selectedFile) => selectedFile.id === file.id);
|
|
407
140
|
}
|
|
408
141
|
|
|
409
|
-
/**
|
|
410
|
-
* Handles dropdown menu actions
|
|
411
|
-
* @param file File to perform action on
|
|
412
|
-
* @param action Action to perform
|
|
413
|
-
*/
|
|
414
|
-
function handleDropdownAction(file: FileSystemItem, action: string) {
|
|
415
|
-
dispatch('action', { action, item: file });
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Formats file modification date
|
|
420
|
-
* @param date Date to format
|
|
421
|
-
* @param translate The `t` of the screen, so the words follow the page's language (and the text is written again when it changes)
|
|
422
|
-
* @returns Formatted date string
|
|
423
|
-
*/
|
|
424
142
|
function getFormattedDate(date: string | Date, translate: Translate): string {
|
|
425
143
|
return formatRelativeDate(date, translate);
|
|
426
144
|
}
|
|
427
145
|
|
|
428
|
-
/**
|
|
429
|
-
* Handle window resize event
|
|
430
|
-
*/
|
|
431
146
|
function handleResize() {
|
|
432
147
|
windowWidth = window.innerWidth;
|
|
433
148
|
updateResponsiveLayout();
|
|
434
149
|
}
|
|
435
150
|
|
|
436
|
-
// Check files on mount
|
|
437
151
|
onMount(() => {
|
|
438
152
|
if (browser) {
|
|
439
|
-
// Set up resize listener
|
|
440
153
|
window.addEventListener('resize', handleResize);
|
|
441
|
-
|
|
442
|
-
// Initial layout update
|
|
443
154
|
updateResponsiveLayout();
|
|
444
|
-
|
|
445
|
-
// Check files
|
|
446
155
|
if (recentFiles.length > 0) {
|
|
447
156
|
checkFiles();
|
|
448
157
|
}
|
|
449
|
-
|
|
450
|
-
// Cleanup on component destroy
|
|
451
158
|
return () => {
|
|
452
159
|
window.removeEventListener('resize', handleResize);
|
|
453
160
|
};
|
|
454
161
|
}
|
|
455
162
|
});
|
|
456
163
|
|
|
457
|
-
// Check files when they change
|
|
458
164
|
$: {
|
|
459
165
|
if (recentFiles.length > 0) {
|
|
460
166
|
checkFiles();
|
|
@@ -463,7 +169,7 @@
|
|
|
463
169
|
|
|
464
170
|
$: {
|
|
465
171
|
if (recentFiles) {
|
|
466
|
-
recentFiles.forEach(file => {
|
|
172
|
+
recentFiles.forEach((file) => {
|
|
467
173
|
if (!loadedStates.has(file.id)) {
|
|
468
174
|
loadedStates.set(file.id, false);
|
|
469
175
|
}
|
|
@@ -471,259 +177,126 @@
|
|
|
471
177
|
}
|
|
472
178
|
}
|
|
473
179
|
|
|
474
|
-
function
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return cachedFonts.get(file.id) || false;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Determines if file is a font that should show cached preview
|
|
490
|
-
* @param file File to check
|
|
491
|
-
* @returns boolean indicating if cached font preview should be used
|
|
492
|
-
*/
|
|
493
|
-
function isCachedFontPreview(file: FileSystemItem): boolean {
|
|
494
|
-
if (file.isMissing || errorStates.get(file.id)) return false;
|
|
495
|
-
const fileType = getFileTypeOf(file);
|
|
496
|
-
return fileType === 'font' && isFontCached(file);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Checks if an SVG file is cached
|
|
501
|
-
* @param file File to check
|
|
502
|
-
* @returns boolean indicating if SVG is cached
|
|
503
|
-
*/
|
|
504
|
-
function isSvgCached(file: FileSystemItem): boolean {
|
|
505
|
-
return cachedSvgs.get(file.id) || false;
|
|
180
|
+
function cardShellClass(file: FileSystemItem): string {
|
|
181
|
+
const selected = isSelected(file);
|
|
182
|
+
return [
|
|
183
|
+
'item-container group flex w-full flex-col gap-2 rounded-xl border bg-background p-2 transition-colors duration-fast',
|
|
184
|
+
selected
|
|
185
|
+
? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand'
|
|
186
|
+
: 'border-border hover:bg-accent',
|
|
187
|
+
allowSelecting ? 'cursor-pointer' : ''
|
|
188
|
+
]
|
|
189
|
+
.filter(Boolean)
|
|
190
|
+
.join(' ');
|
|
506
191
|
}
|
|
507
192
|
</script>
|
|
508
193
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
194
|
+
<div
|
|
195
|
+
class="{className ? className + ' ' : ''}mt-6 flex flex-col"
|
|
196
|
+
style="{style ? style + ' ' : ''}"
|
|
512
197
|
>
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
198
|
+
<h2 class="mb-2 px-2 text-label text-foreground">{$t('recent.title')}</h2>
|
|
199
|
+
|
|
200
|
+
<div
|
|
201
|
+
class="grid w-full"
|
|
202
|
+
style="grid-template-columns: repeat({numberOfColumns}, minmax(0, 1fr)); gap: {gridGap}px;"
|
|
203
|
+
>
|
|
518
204
|
{#each filteredRecentFiles as file (file.id)}
|
|
519
|
-
<!--
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
205
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
206
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
207
|
+
<div
|
|
208
|
+
data-item-id={file.id}
|
|
209
|
+
data-selected={isSelected(file) ? 'true' : undefined}
|
|
210
|
+
class={cardShellClass(file)}
|
|
211
|
+
onclick={(e) => {
|
|
212
|
+
const target = e.target as HTMLElement;
|
|
213
|
+
if (!target.closest('.item-preview')) {
|
|
214
|
+
handleFileSelect(file);
|
|
215
|
+
}
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<button
|
|
219
|
+
type="button"
|
|
220
|
+
class="item-preview relative flex w-full shrink-0 items-center justify-center overflow-hidden rounded-lg bg-muted aspect-[336/190] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {file.isMissing || errorStates.get(file.id)
|
|
221
|
+
? 'cursor-default'
|
|
222
|
+
: 'cursor-pointer'}"
|
|
223
|
+
data-fb-action="preview"
|
|
224
|
+
aria-label={$t('item.previewLabel', { name: file.name })}
|
|
225
|
+
disabled={file.isMissing || errorStates.get(file.id)}
|
|
527
226
|
onclick={(e) => {
|
|
528
|
-
|
|
529
|
-
if (!
|
|
530
|
-
|
|
227
|
+
e.stopPropagation();
|
|
228
|
+
if (!file.isMissing) {
|
|
229
|
+
handleFileClick(file);
|
|
531
230
|
}
|
|
532
231
|
}}
|
|
533
232
|
>
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
handleFileClick(file);
|
|
546
|
-
}
|
|
547
|
-
}}
|
|
548
|
-
role="button"
|
|
549
|
-
tabindex="0"
|
|
550
|
-
onkeydown={(e) => {
|
|
551
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
552
|
-
e.preventDefault();
|
|
553
|
-
e.stopPropagation();
|
|
554
|
-
if (!file.isMissing) {
|
|
555
|
-
handleFileClick(file);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}}
|
|
559
|
-
>
|
|
560
|
-
{#if isLoading(file)}
|
|
561
|
-
<div class="w-full h-full flex items-center justify-center">
|
|
562
|
-
<!-- <span class="text-gray-400">Loading...</span> -->
|
|
563
|
-
</div>
|
|
564
|
-
{:else}
|
|
565
|
-
<!-- File Thumbnail/Icon -->
|
|
566
|
-
{#if shouldUseFileIcon(file)}
|
|
567
|
-
<div class="w-full h-full flex items-center justify-center bg-[hsl(var(--grey1))] rounded-large widgetic-radius preview-fade">
|
|
568
|
-
<div class="transform scale-[3]">
|
|
569
|
-
<FileIcon {file} size="lg" />
|
|
570
|
-
</div>
|
|
571
|
-
</div>
|
|
572
|
-
{:else if isCachedFontPreview(file)}
|
|
573
|
-
<!-- Display cached font with sample text - no fade animation -->
|
|
574
|
-
<div class="w-full h-full flex flex-col items-center justify-center bg-[hsl(var(--grey1))] rounded-large widgetic-radius cached-font-preview">
|
|
575
|
-
<div class="flex flex-col items-center justify-center h-full w-full">
|
|
576
|
-
<!-- Use inline style with !important to force font application -->
|
|
577
|
-
<div style="font-family: '{toSafeFontFamilyName(file.name)}' !important;" class="text-8xl mb-4 text-[hsl(var(--grey7))] widgetic-colors">
|
|
578
|
-
aA
|
|
579
|
-
</div>
|
|
580
|
-
<div style="font-family: '{toSafeFontFamilyName(file.name)}' !important;" class="text-xl text-[hsl(var(--grey7))] widgetic-colors">
|
|
581
|
-
{$t('fontPreview.sampleShort')}
|
|
582
|
-
</div>
|
|
583
|
-
</div>
|
|
584
|
-
</div>
|
|
585
|
-
{:else if isSvgIcon(file)}
|
|
586
|
-
<div class="w-full h-full flex items-center justify-center bg-[hsl(var(--grey1))] rounded-large widgetic-radius {isSvgCached(file) ? 'cached-preview' : 'preview-fade'}">
|
|
587
|
-
<div class="w-[120px] h-[120px] flex items-center justify-center">
|
|
588
|
-
<img
|
|
589
|
-
src={file.url}
|
|
590
|
-
alt={file.name}
|
|
591
|
-
class="w-full h-full object-contain"
|
|
592
|
-
/>
|
|
593
|
-
</div>
|
|
594
|
-
</div>
|
|
595
|
-
{:else if isMediaFile(file) && file.hash && file.url}
|
|
596
|
-
<div class="absolute inset-0">
|
|
597
|
-
<ThumbHashImage
|
|
598
|
-
src={getFileTypeOf(file) === 'video' ? (file.thumbnail || file.url) : file.url}
|
|
599
|
-
alt={file.name}
|
|
600
|
-
thumbhash={file.hash}
|
|
601
|
-
class_="w-full h-full object-cover"
|
|
602
|
-
/>
|
|
603
|
-
</div>
|
|
604
|
-
<img
|
|
605
|
-
src={getFileTypeOf(file) === 'video' ? (file.thumbnail || '') : file.url}
|
|
606
|
-
alt={file.name}
|
|
607
|
-
class="w-full h-full absolute inset-0 object-cover fade-in"
|
|
608
|
-
onload={() => imageLoaded = true}
|
|
609
|
-
onerror={() => handleImageError(file)}
|
|
610
|
-
/>
|
|
611
|
-
{:else}
|
|
612
|
-
<img
|
|
613
|
-
src={getThumbnailOrIcon(file)}
|
|
614
|
-
alt={file.name}
|
|
615
|
-
class="w-full h-full object-cover fade-in"
|
|
616
|
-
onload={() => imageLoaded = true}
|
|
617
|
-
onerror={() => handleImageError(file)}
|
|
618
|
-
/>
|
|
619
|
-
{/if}
|
|
620
|
-
|
|
621
|
-
<!-- Play Button Overlay for Media Files -->
|
|
622
|
-
{#if isMediaFile(file) && !file.isMissing && !errorStates.get(file.id)}
|
|
623
|
-
<div class="absolute inset-0 flex items-center justify-center transition-transform duration-200 {isSelected(file) ? 'scale-[0.8]' : ''}">
|
|
624
|
-
<img src={getAssetUrl('/icons/player-play.svg')} alt={$t('action.play')} class="w-36 h-36" />
|
|
625
|
-
</div>
|
|
626
|
-
{/if}
|
|
627
|
-
{/if}
|
|
233
|
+
{#if isLoading(file)}
|
|
234
|
+
<div class="size-full bg-muted" aria-hidden="true"></div>
|
|
235
|
+
{:else if shouldShowCoverImage(file)}
|
|
236
|
+
{#if file.hash && file.url}
|
|
237
|
+
<div class="absolute inset-0">
|
|
238
|
+
<ThumbHashImage
|
|
239
|
+
src={getCoverSrc(file)}
|
|
240
|
+
alt={file.name}
|
|
241
|
+
thumbhash={file.hash}
|
|
242
|
+
class_="size-full object-cover"
|
|
243
|
+
/>
|
|
628
244
|
</div>
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
245
|
+
{/if}
|
|
246
|
+
<img
|
|
247
|
+
src={getCoverSrc(file)}
|
|
248
|
+
alt=""
|
|
249
|
+
class="size-full object-cover"
|
|
250
|
+
onerror={() => handleImageError(file)}
|
|
251
|
+
/>
|
|
252
|
+
{#if isVideoFile(file) && !file.isMissing && !errorStates.get(file.id)}
|
|
253
|
+
<span class="pointer-events-none absolute inset-0 flex items-center justify-center">
|
|
254
|
+
<span
|
|
255
|
+
class="flex size-12 items-center justify-center rounded-full bg-foreground/60 text-background"
|
|
256
|
+
>
|
|
257
|
+
<IconPlayerPlayFilled class="size-5" aria-hidden="true" />
|
|
258
|
+
</span>
|
|
259
|
+
</span>
|
|
260
|
+
{/if}
|
|
261
|
+
{:else if file.isMissing || errorStates.get(file.id)}
|
|
262
|
+
<FileIcon kind="missing" size="lg" />
|
|
263
|
+
{:else}
|
|
264
|
+
<FileIcon {file} size="lg" />
|
|
265
|
+
{/if}
|
|
266
|
+
</button>
|
|
267
|
+
|
|
268
|
+
<div class="flex items-center gap-2 px-1 pb-1">
|
|
269
|
+
<div class="min-w-0 flex-1 text-start">
|
|
270
|
+
<h3
|
|
271
|
+
dir={nameDirection}
|
|
272
|
+
class="item-name file-name truncate text-body-medium {file.isMissing || errorStates.get(file.id)
|
|
273
|
+
? 'text-destructive'
|
|
274
|
+
: 'text-foreground'}"
|
|
275
|
+
>
|
|
276
|
+
{file.name}
|
|
277
|
+
</h3>
|
|
278
|
+
<p
|
|
279
|
+
class="truncate text-caption {file.isMissing || errorStates.get(file.id)
|
|
280
|
+
? 'text-destructive'
|
|
281
|
+
: 'text-muted-foreground'}"
|
|
282
|
+
>
|
|
283
|
+
{getFormattedDate(file.modified || new Date(), $t)}
|
|
284
|
+
</p>
|
|
659
285
|
</div>
|
|
286
|
+
{#if allowSelecting && isSelected(file)}
|
|
287
|
+
<SelectedBadge label={$t('action.selected')} />
|
|
288
|
+
{/if}
|
|
660
289
|
</div>
|
|
661
290
|
</div>
|
|
662
291
|
{/each}
|
|
663
292
|
</div>
|
|
664
293
|
|
|
665
|
-
<!-- Empty State Message -->
|
|
666
294
|
{#if filteredRecentFiles.length === 0}
|
|
667
|
-
<div class="flex items-center justify-center
|
|
295
|
+
<div class="flex h-[197px] items-center justify-center">
|
|
668
296
|
<div class="flex items-center gap-2">
|
|
669
|
-
<IconExclamationCircle class="
|
|
670
|
-
<p class="text-
|
|
297
|
+
<IconExclamationCircle class="size-6 stroke-[1.333] text-muted-foreground" aria-hidden="true" />
|
|
298
|
+
<p class="text-caption text-muted-foreground">{$t('recent.empty')}</p>
|
|
671
299
|
</div>
|
|
672
300
|
</div>
|
|
673
301
|
{/if}
|
|
674
302
|
</div>
|
|
675
|
-
|
|
676
|
-
<style>
|
|
677
|
-
:global(.item-preview:hover) {
|
|
678
|
-
opacity: 0.8;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
:global(.item-preview) {
|
|
682
|
-
transition: opacity 150ms ease-out;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
/* Add hover effect styles for drag select */
|
|
686
|
-
:global(.recent-files-container .hover-effect) {
|
|
687
|
-
background-color: hsl(var(--grey1)) !important;
|
|
688
|
-
border-radius: var(--radius-large) !important;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
.preview-fade {
|
|
692
|
-
opacity: 0;
|
|
693
|
-
animation: fadeIn 250ms ease-out forwards;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
@keyframes fadeIn {
|
|
697
|
-
from { opacity: 0; }
|
|
698
|
-
to { opacity: 1; }
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
.fade-in {
|
|
702
|
-
opacity: 0;
|
|
703
|
-
transition: opacity 250ms ease-out;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
img[src].fade-in {
|
|
707
|
-
opacity: 1;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/* Ensure cached font previews appear immediately without fading */
|
|
711
|
-
.cached-font-preview {
|
|
712
|
-
opacity: 1 !important;
|
|
713
|
-
animation: none !important;
|
|
714
|
-
transition: none !important;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/* Ensure all cached content appears immediately without fading */
|
|
718
|
-
.cached-preview {
|
|
719
|
-
opacity: 1 !important;
|
|
720
|
-
animation: none !important;
|
|
721
|
-
transition: none !important;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
/* Add specific styling for font preview text */
|
|
725
|
-
.cached-font-preview div {
|
|
726
|
-
font-weight: normal !important;
|
|
727
|
-
font-style: normal !important;
|
|
728
|
-
}
|
|
729
|
-
</style>
|