@widgetic/file-browser 0.5.35 → 0.5.36

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.
Files changed (68) hide show
  1. package/README.md +1 -0
  2. package/dist/components/FolderTree.svelte +46 -97
  3. package/dist/components/FolderTree.svelte.d.ts +7 -7
  4. package/dist/components/core/Dropzone.svelte +127 -0
  5. package/dist/components/core/Dropzone.svelte.d.ts +15 -0
  6. package/dist/components/core/FileBrowser.css +11 -79
  7. package/dist/components/core/FileBrowser.svelte +277 -150
  8. package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
  9. package/dist/components/core/FileUploader.svelte +204 -418
  10. package/dist/components/core/FileUploader.svelte.d.ts +1 -0
  11. package/dist/components/core/Header.svelte +51 -68
  12. package/dist/components/core/Header.svelte.d.ts +1 -0
  13. package/dist/components/core/RecentFiles.svelte +135 -562
  14. package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
  15. package/dist/components/core/UploadPanel.svelte +169 -0
  16. package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
  17. package/dist/components/core/UploadRow.svelte +90 -0
  18. package/dist/components/core/UploadRow.svelte.d.ts +21 -0
  19. package/dist/components/core/UploadStatus.svelte +34 -128
  20. package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
  21. package/dist/components/core/UploadStatusList.svelte +61 -77
  22. package/dist/components/items/FileItem.svelte +190 -532
  23. package/dist/components/items/FileItem.svelte.d.ts +1 -1
  24. package/dist/components/items/FolderItem.svelte +46 -36
  25. package/dist/components/items/FolderItem.svelte.d.ts +1 -1
  26. package/dist/components/modals/MoveDialog.svelte +142 -281
  27. package/dist/components/modals/NewFolderButton.svelte +13 -14
  28. package/dist/components/modals/SearchModal.svelte +112 -264
  29. package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
  30. package/dist/components/modals/SelectedFilesModal.svelte +91 -167
  31. package/dist/components/previews/AudioPlayer.svelte +75 -58
  32. package/dist/components/previews/ErrorPreview.svelte +9 -6
  33. package/dist/components/previews/FilePreview.svelte +173 -53
  34. package/dist/components/previews/FontPreview.svelte +37 -54
  35. package/dist/components/previews/ImagePreview.svelte +9 -2
  36. package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
  37. package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
  38. package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
  39. package/dist/components/previews/TextPreview.svelte +32 -40
  40. package/dist/components/previews/VideoPlayer.svelte +124 -149
  41. package/dist/components/previews/WaveformVisualizer.svelte +42 -222
  42. package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
  43. package/dist/components/ui/ControlToolbar.svelte +113 -288
  44. package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
  45. package/dist/components/ui/DragSelect.svelte +41 -248
  46. package/dist/components/ui/DropdownMenu.svelte +56 -55
  47. package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
  48. package/dist/components/ui/FileIcon.svelte +168 -51
  49. package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
  50. package/dist/components/ui/FileMetadata.svelte +20 -9
  51. package/dist/components/ui/LoadingSkeleton.svelte +5 -20
  52. package/dist/components/ui/SearchResults.svelte +50 -26
  53. package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
  54. package/dist/components/ui/SelectedBadge.svelte +25 -0
  55. package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
  56. package/dist/components/ui/TileSkeleton.svelte +15 -0
  57. package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
  58. package/dist/components/ui/VirtualList.svelte +3 -0
  59. package/dist/components/ui/index.d.ts +1 -0
  60. package/dist/components/ui/index.js +1 -0
  61. package/dist/i18n/messages.d.ts +38 -25
  62. package/dist/i18n/messages.js +39 -26
  63. package/dist/stores/fileStore.d.ts +2 -2
  64. package/dist/stores/navigationStore.d.ts +1 -1
  65. package/dist/stores/persistentSelectStore.d.ts +1 -1
  66. package/dist/utils/gridLayout.d.ts +2 -0
  67. package/dist/utils/gridLayout.js +10 -0
  68. package/package.json +3 -4
@@ -1,95 +1,77 @@
1
1
  <script lang="ts">
2
2
  /**
3
- * FileItem Component
4
- * Displays individual file items with thumbnails, icons, and interaction handlers
5
- * Supports different file types (video, image, audio) with appropriate previews
6
- * Handles file existence checks and loading states
3
+ * FileItem — Figma "File Tile" (267:132): horizontal 64px tile with thumb, name, meta, item menu.
4
+ * Keeps thumbnail lazy-load, ThumbHash fade-in, missing-file detection, selection and preview hooks.
7
5
  */
8
6
 
9
- // Svelte imports
10
7
  import { createEventDispatcher, onMount } from 'svelte';
11
- import { spring, tweened } from 'svelte/motion';
8
+ import { tweened } from 'svelte/motion';
12
9
  import { cubicOut } from 'svelte/easing';
13
10
 
14
- // Design system imports
15
- import { Button, ThumbHashImage } from '@widgetic/design-system/components';
11
+ import { ThumbHashImage } from '@widgetic/design-system/components';
12
+ import { IconPlayerPlayFilled, IconTrash } from '@widgetic/design-system/icons';
16
13
  import '@widgetic/design-system/styles';
17
14
 
18
- // Local components imports
19
- import { DropdownMenu, LoadingSkeleton } from '../ui';
20
- // import { ThumbHashImage } from '../previews';
21
- // import ThumbHashImage from '../previews/ThumbHashImage.svelte';
15
+ import { DropdownMenu, FileIcon, LoadingSkeleton, SelectedBadge } from '../ui';
22
16
 
23
17
  import type { FileSystemItem } from '../../types';
24
- import { getFileIcon, getItemFileType, formatFileSize } from '../../utils/fileUtils';
18
+ import { getItemFileType, formatFileSize } from '../../utils/fileUtils';
19
+ import { formatRelativeDate } from '../../utils/dateUtils';
25
20
  import { useI18n } from '../../i18n';
26
21
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
27
22
  import { isKnownNonImageFile } from '../../utils/fileKinds';
28
- import { toCssUrlLiteral, toSafeFontFamilyName } from '../../utils/safeText';
29
- import { addMissingFile, removeMissingFile } from '../../stores/missingFilesStore';
30
- import { browser } from '$app/environment';
31
- import { IconTrash } from '@tabler/icons-svelte';
32
- import { persistentSelectStore } from '../../stores/persistentSelectStore';
23
+ import { buildTransformedUrl } from '../../utils/imageTransform';
33
24
  import type { FileFilterType } from '../../utils/fileTypes';
34
- import { selectedFiles } from '../../stores/fileStore';
35
25
  import { isMobileStore } from '../../stores/viewportStore';
36
- import { buildTransformedUrl } from '../../utils/imageTransform';
37
- import EaseOut from '@tabler/icons-svelte/icons/ease-out';
38
- import { getAssetUrl } from '../../utils/fileUtils';
39
-
40
- // Component props
26
+
41
27
  export let item: FileSystemItem;
42
28
  export let selected: boolean = false;
43
29
  export let allowSelecting: boolean = true;
44
30
  export let thumbnailOnly: boolean = false;
31
+ // svelte-ignore export_let_unused
45
32
  export let preventFontLoad: boolean = false;
46
33
  // svelte-ignore export_let_unused
47
34
  export let currentFilter: FileFilterType = 'all';
48
- /** Vertical grid cell (icon above centered label). */
35
+ /** Kept for callers; grid tiles are always the horizontal File Tile layout. */
36
+ // svelte-ignore export_let_unused
49
37
  export let gridLayout = false;
50
38
 
51
39
  $: isSelected = allowSelecting && selected;
52
40
 
53
41
  const dispatch = createEventDispatcher();
54
42
  const { t, locale } = useI18n();
55
- // The reading direction of the screen: a name a visitor wrote keeps a direction of its own on a right to left screen.
56
43
  const textDirection = useTextDirection();
57
44
  $: nameDirection = dirForUserText($textDirection);
58
-
59
45
 
60
- // Reactive declarations for file type handling
61
46
  $: fileType = getItemFileType(item);
62
47
  $: isVideo = fileType === 'video';
63
48
  $: isImage = fileType === 'image';
64
- $: isAudio = fileType === 'audio';
65
49
  $: isSvg = fileType === 'svg';
66
50
  $: isFont = fileType === 'font';
67
- $: fileIcon = getFileIcon(item.name);
68
- // The name a font is registered and styled under; safe to put inside CSS (see safeText.ts).
69
- $: fontName = toSafeFontFamilyName(item.name);
70
51
  $: previewSrc = item.thumbnail || item.url || '';
71
52
  $: isLikelyRemoteImage = !!(previewSrc && /^(https?:|blob:|data:image)/i.test(previewSrc));
72
- // A PDF or a text file without a thumbnail gets the file-type icon: drawing the file itself as a picture
73
- // fails and would show it as "missing", which also makes it impossible to select (see fileKinds.ts).
74
53
  $: isKnownNonPicture = !item.thumbnail && isKnownNonImageFile(item);
75
- // A video's own address is not a picture. Only a separate thumbnail that is an image may be drawn as one.
76
54
  $: hasPicturePoster = !!(item.thumbnail && looksLikePicture(item.thumbnail));
77
55
  let posterFailed = false;
78
- $: showImageThumb = !posterFailed && (isImage || isSvg || hasPicturePoster || (isLikelyRemoteImage && !isAudio && !isVideo && !isFont && !isKnownNonPicture));
56
+ $: showImageThumb =
57
+ !posterFailed &&
58
+ (isImage ||
59
+ isSvg ||
60
+ hasPicturePoster ||
61
+ (isLikelyRemoteImage && !isVideo && !isFont && !isKnownNonPicture));
62
+
63
+ $: metaText = item.modified
64
+ ? formatRelativeDate(item.modified, $t)
65
+ : formatFileSize(item.size ?? 0, $t, $locale);
79
66
 
80
- // State for file availability and loading
81
67
  let isLoading = true;
82
- let fontLoaded = false;
83
- let fontFace: FontFace;
84
68
  let isImageCached = false;
85
69
  let imageLoaded = false;
86
70
  let thumbnailMissing = false;
87
71
  let imageMissing = false;
88
72
  $: isMissing = !!(item.isMissing || imageMissing);
89
73
 
90
- // Track if we're currently transitioning
91
74
  let isTransitioning = false;
92
-
93
75
  let observer: IntersectionObserver;
94
76
  let itemElement: HTMLElement;
95
77
  let isIntersecting = false;
@@ -97,130 +79,28 @@
97
79
 
98
80
  $: if (previewSrc || showImageThumb) shouldLoad = true;
99
81
 
100
- // Keep track of font loading state
101
- let fontLoadingStarted = false;
102
- let fontLoadAttempts = 0;
103
- const MAX_FONT_LOAD_ATTEMPTS = 3;
104
-
105
82
  export let isMobile: boolean | undefined = undefined;
106
83
  $: effectiveIsMobile = isMobile !== undefined ? isMobile : $isMobileStore;
107
84
 
108
- // Add these state variables at the top with other state variables
109
- let isNavigating = true;
110
- let initialLoad = true;
111
-
112
- // Add at the top with other state variables
113
- let transitionCount = 0;
114
- let loadCount = 0;
115
-
116
- // Flag to determine if we should show thumbhash (only during initial load)
117
85
  let showThumbhash = false;
118
86
 
119
- // Tweened store for smooth fade-in
120
- // Tweened store for smooth fade-in
121
- let opacity = tweened(0, {
87
+ let opacity = tweened(0, {
122
88
  duration: 280,
123
- easing: cubicOut
89
+ easing: cubicOut
124
90
  });
125
91
 
126
- // Tweened store for thumbhash fade-in
127
92
  let thumbhashOpacity = tweened(0, {
128
93
  duration: 200,
129
94
  easing: cubicOut
130
95
  });
131
96
 
132
- // Track thumbhash fade-in completion
133
- let thumbhashFadedIn = false;
134
- $: {
135
- // When opacity reaches 1, mark as faded in
136
- if ($thumbhashOpacity >= 1) {
137
- thumbhashFadedIn = true;
138
- }
139
- }
140
-
141
- // Load font immediately if it's a font file
142
- $: if (isFont && item.url && !preventFontLoad && !fontLoadingStarted) {
143
- loadFont();
144
- }
145
-
146
- async function loadFont() {
147
- if (fontLoadAttempts >= MAX_FONT_LOAD_ATTEMPTS) {
148
- console.warn('Max font load attempts reached for:', fontName);
149
- return;
150
- }
151
-
152
- fontLoadingStarted = true;
153
- fontLoadAttempts++;
154
-
155
- try {
156
- // console.log('Attempting to load font:', {
157
- // attempt: fontLoadAttempts,
158
- // fontName,
159
- // url: item.url
160
- // });
161
-
162
- // First check if font is already in document.fonts
163
- const existingFont = Array.from(document.fonts).find(f => f.family === fontName);
164
- if (existingFont) {
165
- // console.log('Font already loaded in document:', fontName);
166
- fontLoaded = true;
167
- isLoading = false;
168
- return;
169
- }
170
-
171
- // Create and load the font
172
- fontFace = new FontFace(fontName, toCssUrlLiteral(item.url ?? ''));
173
-
174
- // Set a timeout to catch hanging loads
175
- const fontLoadPromise = fontFace.load();
176
- const timeoutPromise = new Promise((_, reject) => {
177
- setTimeout(() => reject(new Error('Font load timeout')), 5000);
178
- });
179
-
180
- await Promise.race([fontLoadPromise, timeoutPromise]);
181
-
182
- // If we get here, the font loaded successfully
183
- document.fonts.add(fontFace);
184
- // console.log('Font loaded and added to document:', fontName);
185
-
186
- // Double check the font is actually available
187
- await document.fonts.ready;
188
- const isFontAvailable = document.fonts.check(`12px "${fontName}"`);
189
- // console.log('Font availability check:', { fontName, isAvailable: isFontAvailable });
190
-
191
- fontLoaded = true;
192
- isLoading = false;
193
- } catch (error) {
194
- console.error('FileItem: Error loading font:', {
195
- error,
196
- fontName,
197
- url: item.url,
198
- attempt: fontLoadAttempts
199
- });
200
-
201
- // Reset flags to allow another attempt if within limits
202
- if (fontLoadAttempts < MAX_FONT_LOAD_ATTEMPTS) {
203
- fontLoadingStarted = false;
204
- // Add a small delay before retrying
205
- setTimeout(loadFont, 1000);
206
- }
207
- }
97
+ function looksLikePicture(address: string): boolean {
98
+ if (/^data:image\//i.test(address)) return true;
99
+ const path = address.split(/[?#]/)[0];
100
+ return /\.(png|jpe?g|gif|webp|avif|heic|heif)$/i.test(path);
208
101
  }
209
102
 
210
103
  onMount(() => {
211
- // console.log('FileItem mounted:', item, isMissing, imageMissing);
212
-
213
- // Start with transitions disabled
214
- isNavigating = true;
215
- initialLoad = true;
216
-
217
- // Enable transitions after a brief delay
218
- setTimeout(() => {
219
- isNavigating = false;
220
- initialLoad = false;
221
- }, 100);
222
-
223
- // Always mount the <img> for remote/image files. Skeleton stays until onload fade-in.
224
104
  if (previewSrc || isImage || isSvg || showImageThumb) {
225
105
  shouldLoad = true;
226
106
  if (!isImageCached) {
@@ -228,7 +108,6 @@
228
108
  }
229
109
  }
230
110
 
231
- // Check cache status immediately for instant display
232
111
  if (!isFont) {
233
112
  const src = item.thumbnail || item.url;
234
113
  if (src) {
@@ -243,7 +122,6 @@
243
122
  });
244
123
  } else {
245
124
  showThumbhash = !!(item.thumbnail && item.hash && !thumbnailMissing);
246
- // Keep the <img> visible — fade-from-0 never completes if onload is skipped.
247
125
  opacity.set(1, { duration: 0 });
248
126
  if (showThumbhash) {
249
127
  thumbhashOpacity.set(1);
@@ -252,195 +130,52 @@
252
130
  }
253
131
  }
254
132
 
255
- // Only set up intersection observer if image isn't cached
256
133
  if (!isImageCached) {
257
134
  observer = new IntersectionObserver(
258
135
  (entries) => {
259
- entries.forEach(entry => {
136
+ entries.forEach((entry) => {
260
137
  isIntersecting = entry.isIntersecting;
261
138
  if (isIntersecting && !shouldLoad) {
262
139
  shouldLoad = true;
263
- if (!isFont) {
264
- checkFileExistence();
265
- }
266
140
  }
267
141
  });
268
142
  },
269
- {
270
- rootMargin: '200px',
271
- threshold: 0.1
272
- }
143
+ { rootMargin: '200px', threshold: 0.1 }
273
144
  );
274
-
275
145
  if (itemElement) {
276
146
  observer.observe(itemElement);
277
147
  }
278
148
  }
279
149
 
280
150
  return () => {
281
- if (observer) {
282
- observer.disconnect();
283
- }
151
+ observer?.disconnect();
284
152
  };
285
153
  });
286
154
 
287
- async function checkFileExistence() {
288
- // Mount image/thumbnail directly; onerror path is source of truth for missing items
289
- isLoading = false;
290
- shouldLoad = true;
291
- }
292
-
293
- /**
294
- * Gets background color based on file type
295
- * @param file File to get background for
296
- * @returns CSS color value
297
- */
298
- /** True when an address is a picture the browser can draw in an img, not the file itself (an mp4, a pdf). */
299
- function looksLikePicture(address: string): boolean {
300
- if (/^data:image\//i.test(address)) return true;
301
- const path = address.split(/[?#]/)[0];
302
- return /\.(png|jpe?g|gif|webp|avif|heic|heif)$/i.test(path);
303
- }
304
-
305
- function getBackgroundColor(file: FileSystemItem): string {
306
- if (file.isMissing) return 'hsl(var(--grey1))';
307
-
308
- switch(fileType) {
309
- case 'audio':
310
- case 'video':
311
- case 'image':
312
- case 'document':
313
- // Keep grey background until thumbhash is fully faded in
314
- return (!thumbhashFadedIn && showThumbhash) ? 'hsl(var(--grey2))' : 'transparent';
315
- case 'font':
316
- return 'hsl(var(--grey1))';
317
- default:
318
- return 'hsl(var(--grey1))';
319
- }
320
- }
321
-
322
- /**
323
- * Gets the appropriate icon or thumbnail for the file
324
- * Only returns icon/thumbnail if file exists and is not loading
325
- */
326
- function getDisplayIcon(): string | null {
327
- if (isLoading && !isImageCached) {
328
- return null;
329
- }
330
-
331
- if (isMissing) {
332
- return getAssetUrl('/icons/error.svg');
333
- }
334
-
335
- if ((isVideo || isImage || isAudio) && item.thumbnail) {
336
- return item.thumbnail;
337
- }
338
-
339
- if ((isImage || isSvg || isAudio) && item.url) {
340
- return item.url;
341
- }
342
-
343
- return getAssetUrl(fileIcon);
344
- }
345
-
346
- /**
347
- * Validates file existence by performing a HEAD request
348
- * Used to show appropriate UI state for missing files
349
- * @param url File URL to check
350
- * @returns Promise resolving to boolean indicating file existence
351
- */
352
- async function checkFileExists(url: string | undefined, type: 'image' | 'thumbnail'): Promise<boolean> {
353
- if (!url) return false;
354
-
355
- const isRemoteMedia =
356
- url.startsWith('http://') ||
357
- url.startsWith('https://') ||
358
- url.startsWith('blob:') ||
359
- url.startsWith('data:');
360
-
361
- if (isRemoteMedia && isVideo && type === 'image') {
362
- return true;
363
- }
364
-
365
- if (isRemoteMedia && (isImage || isSvg || type === 'thumbnail')) {
366
- return new Promise((resolve) => {
367
- const img = new Image();
368
- img.onload = () => resolve(true);
369
- img.onerror = () => {
370
- if (type === 'thumbnail') thumbnailMissing = true;
371
- else imageMissing = true;
372
- resolve(false);
373
- };
374
- img.src = url;
375
- setTimeout(() => resolve(false), 8000);
376
- });
377
- }
378
-
379
- try {
380
- const response = await fetch(url, { method: 'HEAD' });
381
- if (!response.ok) {
382
- if (type === 'thumbnail') thumbnailMissing = true;
383
- else imageMissing = true;
384
- return false;
385
- }
386
- return true;
387
- } catch {
388
- if (type === 'thumbnail') thumbnailMissing = true;
389
- else imageMissing = true;
390
- return false;
391
- }
392
- }
393
-
394
155
  function checkImageCache(src: string): boolean {
395
156
  if (src.startsWith('/icons/') || src.includes('audio.svg') || src.includes('document.svg')) {
396
157
  return true;
397
158
  }
398
-
399
159
  const img = new Image();
400
160
  img.src = src;
401
161
  const isCached = img.complete;
402
-
403
- loadCount++;
404
- // console.log(`[FileItem ${item.name}] Cache check #${loadCount}:`, {
405
- // src,
406
- // isCached,
407
- // imageLoaded,
408
- // isLoading,
409
- // transitionCount
410
- // });
411
-
412
162
  if (isCached && !imageLoaded) {
413
163
  imageLoaded = true;
414
164
  isImageCached = true;
415
165
  }
416
-
417
166
  return isCached;
418
167
  }
419
168
 
420
169
  async function handleImageLoad() {
421
170
  if (imageLoaded || isTransitioning) return;
422
-
423
171
  isTransitioning = true;
424
172
  imageLoaded = true;
425
173
  isLoading = false;
426
-
427
- // Start fade in
428
174
  await opacity.set(1);
429
- // Only remove thumbhash after fade is complete
430
175
  showThumbhash = false;
431
176
  isTransitioning = false;
432
177
  }
433
178
 
434
- /**
435
- * Event Handlers Section
436
- * Manages user interactions with file items
437
- */
438
-
439
- /**
440
- * Handles icon/thumbnail click events
441
- * Prevents event propagation and dispatches click event if file exists
442
- * @param event Browser click event
443
- */
444
179
  function handleIconClick(event: Event) {
445
180
  event.stopPropagation();
446
181
  if (!isMissing) {
@@ -448,264 +183,187 @@
448
183
  }
449
184
  }
450
185
 
451
- /**
452
- * Handles file selection toggle
453
- * Prevents event propagation and dispatches select event if file exists
454
- * @param event Browser click event
455
- */
456
186
  function handleSelect(event: Event) {
457
187
  event.stopPropagation();
458
- if (!isMissing) {
188
+ if (!isMissing && allowSelecting) {
459
189
  dispatch('select');
460
190
  }
461
191
  }
462
192
 
463
- /**
464
- * Processes dropdown menu actions
465
- * Dispatches action events with file context
466
- * @param event CustomEvent containing the selected action
467
- */
468
193
  function handleDropdownAction(event: CustomEvent) {
469
194
  const { action } = event.detail;
470
195
  dispatch('action', { action, item });
471
196
  }
197
+
198
+ function stopMenuBubble(event: Event) {
199
+ event.stopPropagation();
200
+ }
201
+
202
+ $: tileShellClass = [
203
+ 'flex w-full items-center gap-3 rounded-xl border border-border bg-background p-2 transition-colors duration-fast',
204
+ thumbnailOnly ? 'h-auto w-auto border-0 bg-transparent p-0' : 'h-16',
205
+ !thumbnailOnly && allowSelecting && !isMissing && !effectiveIsMobile && !isSelected
206
+ ? 'hover:bg-accent has-[[data-state=open]]:bg-accent'
207
+ : '',
208
+ !thumbnailOnly && isSelected ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand' : '',
209
+ !thumbnailOnly && allowSelecting && !isMissing ? 'cursor-pointer' : ''
210
+ ]
211
+ .filter(Boolean)
212
+ .join(' ');
213
+
214
+ // The item menu shows on hover or focus, always on touch screens (no hover there), and while the menu is open
215
+ // (the menu's trigger carries data-state="open": the pointer is then over the menu, not over the tile)
216
+ $: menuVisibleClass = effectiveIsMobile
217
+ ? 'opacity-100'
218
+ : 'opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100';
472
219
  </script>
473
220
 
474
221
  <!-- svelte-ignore a11y_click_events_have_key_events -->
475
222
  <!-- svelte-ignore a11y_no_static_element_interactions -->
476
- <div
477
- class="file-item-ct relative {thumbnailOnly ? '' : 'w-full'} widgetic-colors widgetic-radius group rounded-[var(--radius-large)]"
478
- class:cursor-pointer={!isMissing && allowSelecting}
479
- class:hover:bg-[hsl(var(--grey1))]={!effectiveIsMobile && allowSelecting && !isMissing && !selected}
480
- class:hover:bg-[hsl(var(--light-green))]={!effectiveIsMobile && allowSelecting && !isMissing && selected}
481
- class:bg-[hsl(var(--light-green))]={selected}
482
- class:h-[54px]={!thumbnailOnly && !gridLayout}
483
- class:min-h-[96px]={gridLayout && !thumbnailOnly}
223
+ <div
224
+ class="file-item-ct group relative w-full"
225
+ class:w-full={!thumbnailOnly}
484
226
  bind:this={itemElement}
485
- onclick={!isMissing && allowSelecting ? handleSelect : undefined}
227
+ data-selected={isSelected ? 'true' : undefined}
228
+ onclick={!thumbnailOnly && allowSelecting && !isMissing ? handleSelect : undefined}
486
229
  >
487
- <div class="{thumbnailOnly ? '' : gridLayout ? 'flex flex-col items-center gap-1 w-full' : 'grid grid-cols-[62px_1fr] gap-4'} relative widgetic-radius">
488
- <!-- Thumbnail Column -->
489
- <div class="thumbnail-ct w-[62px] h-[54px] relative">
490
- <button
491
- class="absolute inset-0 overflow-hidden rounded-large focus:outline-none focus:ring-0 thumbnail-button
492
- {isFont ? 'bg-gray-100' : ''}
493
- {selected ? 'is-selected' : ''}
494
- {!isMissing ? 'cursor-pointer' : ''}
495
- {isNavigating || initialLoad ? 'no-transition' : ''}
496
- {!isMissing && !isNavigating ? 'can-hover' : ''}"
497
- style="
498
- background-color: {getBackgroundColor(item)};
499
- width: 62px;
500
- height: 54px;
501
- "
502
- onclick={handleIconClick}
503
- data-fb-action="preview"
504
- aria-label={$t('item.previewLabel', { name: item.name })}
505
- disabled={isMissing}
506
- >
507
- <div class="w-full h-full flex items-center justify-center relative">
508
- <!-- Image thumbs: skeleton overlay until onload, then fade in -->
509
- {#if showImageThumb && shouldLoad && !imageLoaded && !isImageCached}
510
- <div class="fb-thumb-loader-ct absolute inset-0 z-20 overflow-hidden rounded-[var(--radius-large)]">
511
- <LoadingSkeleton width="100%" height="100%" />
512
- </div>
513
- {:else if isLoading && shouldLoad && !imageLoaded && !isImageCached && !showImageThumb}
230
+ <div class={tileShellClass}>
231
+ <!-- 48×48 preview thumb (Figma File Thumb Large) -->
232
+ <button
233
+ type="button"
234
+ class="relative size-12 shrink-0 overflow-hidden rounded-lg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {isMissing
235
+ ? 'cursor-default'
236
+ : 'cursor-pointer'}"
237
+ onclick={handleIconClick}
238
+ data-fb-action="preview"
239
+ aria-label={$t('item.previewLabel', { name: item.name })}
240
+ disabled={isMissing}
241
+ >
242
+ {#if isMissing}
243
+ <FileIcon kind="missing" size="lg" />
244
+ {:else if showImageThumb && shouldLoad}
245
+ {#if !imageLoaded && !isImageCached}
246
+ <div class="absolute inset-0 z-20 overflow-hidden rounded-lg">
514
247
  <LoadingSkeleton width="100%" height="100%" />
515
- {/if}
516
- {#if shouldLoad}
517
- <!-- Font Icon -->
518
- {#if isFont}
519
- <span
520
- style="font-family: '{fontName}', sans-serif;"
521
- class="font-icon-text text-2xl text-gray-700 {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
522
- >
523
- aA
524
- </span>
525
- <!-- SVG Icon -->
526
- {:else if isSvg}
527
- <img
528
- src={getDisplayIcon()}
529
- alt=""
530
- class="svg-icon-image w-full h-full rounded-[var(--radius-large)] object-contain {isImageCached ? 'no-fade' : 'fade-in'}"
531
- />
532
- <!-- A file that is not a picture: the type icon. Drawing the file itself as an img marks it missing. -->
533
- {:else if !imageMissing}
534
- {#if !showImageThumb}
535
- <img
536
- src={getAssetUrl(getFileIcon(item.name))}
537
- alt={isAudio ? $t('item.audioFile') : isVideo ? $t('filterName.video') : $t('item.documentFile')}
538
- class="audio-doc-icon-image w-full h-full rounded-[var(--radius-large)] object-contain {isImageCached ? 'no-fade' : 'fade-in'}"
539
- />
540
- <!-- Image -->
541
- {:else}
542
- <!-- Thumbhash -->
543
- {#if showThumbhash}
544
- <div
545
- class="thumbnail-hash-ct absolute inset-0"
546
- style="opacity: {$thumbhashOpacity};"
547
- >
548
- <ThumbHashImage
549
- src={buildTransformedUrl(item.thumbnail, { width: 640, fit: 'cover' })}
550
- alt={item.name || ''}
551
- thumbhash={item.hash || ''}
552
- class_="thumbnail-hash-image w-full h-full rounded-[var(--radius-large)]"
553
- />
554
- </div>
555
- {/if}
556
-
557
- <!-- Thumbnail Image -->
558
- <img class="thumbnail-image w-full h-full rounded-[var(--radius-large)] object-cover absolute inset-0"
559
- src={previewSrc}
560
- alt={item.name}
561
- referrerpolicy="no-referrer"
562
- style="opacity: {$opacity}; z-index: 10;"
563
- onerror={(e: any) => {
564
- // console.log(`[FileItem ${item.name}] Thumbnail error:`, previewSrc);
565
- const imgEl = e.currentTarget as HTMLImageElement;
566
- if (imgEl.srcset) {
567
- imgEl.srcset = '';
568
- imgEl.sizes = '';
569
- imgEl.src = item.url || previewSrc;
570
- return;
571
- }
572
- if (item.thumbnail && item.url && previewSrc === item.thumbnail && imgEl.src !== item.url && (isImage || isSvg)) {
573
- imgEl.src = item.url;
574
- return;
575
- }
576
- // A video, a PDF or any other non-picture keeps its type icon and stays selectable.
577
- if (!isImage && !isSvg) {
578
- posterFailed = true;
579
- imageMissing = false;
580
- thumbnailMissing = true;
581
- opacity.set(1);
582
- isLoading = false;
583
- return;
584
- }
585
- thumbnailMissing = true;
586
- imageMissing = true;
587
- opacity.set(1);
588
- isLoading = false;
589
- }}
590
- onload={handleImageLoad}
591
- />
592
- {/if}
593
-
594
- <!-- Missing Icon -->
595
- {:else}
596
- <img
597
- src={getAssetUrl('/icons/error.svg')}
598
- alt=""
599
- class="missing-icon-image w-full h-full rounded-[var(--radius-large)] object-contain {isImageCached ? 'no-fade' : 'fade-in'}"
600
- />
601
- {/if}
602
- {/if}
603
-
604
- <!-- Play Icon over Thumbnail -->
605
- {#if (isVideo || isAudio) && !isMissing && shouldLoad}
606
- <div class="play-icon-ct absolute inset-0 flex items-center justify-center z-10">
607
- <div class="play-icon-bg bg-white rounded-full p-2 shadow-lg">
608
- <img
609
- src={getAssetUrl('/icons/player-play.svg')}
610
- alt={$t('action.play')}
611
- class="play-icon-image w-4 h-4"
612
- />
613
- </div>
614
- </div>
615
- {/if}
616
- </div>
617
- </button>
618
- </div>
619
-
620
- <!-- Content Column -->
621
- {#if !thumbnailOnly}
622
- <div class="fb-file-content-ct flex flex-col justify-center min-w-0 relative w-full" class:items-center={gridLayout} class:text-center={gridLayout}>
623
- <div class="widgetic-colors pointer-events-none w-full" class:pe-10={!gridLayout} class:px-1={gridLayout}>
624
- <h3 dir={nameDirection} class="fb-file-title body-medium text-sm leading-snug line-clamp-2 break-words cursor-default" class:text-center={gridLayout} class:text-[hsl(var(--error))]={isMissing} class:text-[hsl(var(--grey7))]={!isMissing}>
625
- {item.name}
626
- </h3>
627
- <p class="subtext cursor-default mt-0.5" class:truncate={!gridLayout} class:text-center={gridLayout} class:text-[hsl(var(--error))]={isMissing} class:text-[hsl(var(--grey5))]={!isMissing}>
628
- {formatFileSize(item.size ?? 0, $t, $locale)}
629
- </p>
630
- </div>
631
-
632
- <!-- Checkbox/Actions -->
633
- {#if !isMissing && allowSelecting && !selected}
634
- <div class="absolute top-[17px] end-4 z-10 opacity-0 group-hover:opacity-20 transition-all duration-200">
635
- <img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.select')} class="w-5 h-5" />
636
248
  </div>
637
249
  {/if}
638
- {#if selected}
639
- <div class="absolute top-[17px] end-4 z-10 opacity-100">
640
- <img src={getAssetUrl('/icons/checked.svg')} alt={$t('action.selected')} class="w-5 h-5" />
250
+ {#if showThumbhash}
251
+ <div class="absolute inset-0" style="opacity: {$thumbhashOpacity};">
252
+ <ThumbHashImage
253
+ src={buildTransformedUrl(item.thumbnail, { width: 640, fit: 'cover' })}
254
+ alt={item.name || ''}
255
+ thumbhash={item.hash || ''}
256
+ class_="size-full rounded-lg object-cover"
257
+ />
641
258
  </div>
642
259
  {/if}
643
- {#if isMissing}
644
- <div class="absolute top-[17px] end-4 z-10">
645
- <button
646
- class="w-5 h-5 text-[hsl(var(--error))] opacity-0 group-hover:opacity-100 transition-opacity duration-200"
647
- class:!opacity-100={effectiveIsMobile}
648
- onclick={(e) => {
649
- e.stopPropagation();
650
- dispatch('delete', { item });
651
- }}
652
- aria-label={$t('item.deleteMissing')}
653
- >
654
- <IconTrash size={20} />
655
- </button>
656
- </div>
260
+ <img
261
+ class="absolute inset-0 size-full rounded-lg object-cover"
262
+ src={previewSrc}
263
+ alt=""
264
+ referrerpolicy="no-referrer"
265
+ style="opacity: {$opacity}; z-index: 10;"
266
+ onerror={(e) => {
267
+ const imgEl = e.currentTarget as HTMLImageElement;
268
+ if (imgEl.srcset) {
269
+ imgEl.srcset = '';
270
+ imgEl.sizes = '';
271
+ imgEl.src = item.url || previewSrc;
272
+ return;
273
+ }
274
+ if (
275
+ item.thumbnail &&
276
+ item.url &&
277
+ previewSrc === item.thumbnail &&
278
+ imgEl.src !== item.url &&
279
+ (isImage || isSvg)
280
+ ) {
281
+ imgEl.src = item.url;
282
+ return;
283
+ }
284
+ if (!isImage && !isSvg) {
285
+ posterFailed = true;
286
+ imageMissing = false;
287
+ thumbnailMissing = true;
288
+ opacity.set(1);
289
+ isLoading = false;
290
+ return;
291
+ }
292
+ thumbnailMissing = true;
293
+ imageMissing = true;
294
+ opacity.set(1);
295
+ isLoading = false;
296
+ }}
297
+ onload={handleImageLoad}
298
+ />
299
+ {#if isVideo}
300
+ <span
301
+ class="pointer-events-none absolute inset-0 z-20 m-auto flex size-5 items-center justify-center rounded-full bg-foreground/60 text-primary-foreground"
302
+ >
303
+ <IconPlayerPlayFilled class="size-2.5" />
304
+ </span>
657
305
  {/if}
306
+ {:else if shouldLoad}
307
+ <FileIcon file={item} size="lg" />
308
+ {:else}
309
+ <div class="size-full rounded-lg bg-muted" aria-hidden="true"></div>
310
+ {/if}
311
+ </button>
312
+
313
+ {#if !thumbnailOnly}
314
+ <div class="flex min-h-0 min-w-0 flex-1 flex-col justify-center text-start">
315
+ <h3
316
+ dir={nameDirection}
317
+ class="file-name item-name text-body-medium truncate {isMissing
318
+ ? 'text-destructive'
319
+ : 'text-foreground'}"
320
+ >
321
+ {item.name}
322
+ </h3>
323
+ <p
324
+ class="text-caption truncate {isMissing ? 'text-destructive' : 'text-muted-foreground'}"
325
+ >
326
+ {metaText}
327
+ </p>
658
328
  </div>
329
+
330
+ {#if isSelected}
331
+ <!-- Selected (Figma File Tile, State=Selected): the check takes the place of the item menu.
332
+ The selection bar has the same actions (rename, download, move, delete) for what is selected. -->
333
+ <SelectedBadge label={$t('action.selected')} />
334
+ {:else if !isMissing}
335
+ <!-- Item menu: hover, focus-within, or always on touch screens -->
336
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
337
+ <div
338
+ class="fb-file-menu-ct shrink-0 transition-opacity duration-fast {menuVisibleClass}"
339
+ role="presentation"
340
+ onclick={stopMenuBubble}
341
+ onkeydown={stopMenuBubble}
342
+ >
343
+ <DropdownMenu
344
+ isFolder={false}
345
+ fileUrl={item.url}
346
+ isMissing={isMissing}
347
+ on:action={handleDropdownAction}
348
+ />
349
+ </div>
350
+ {/if}
351
+
352
+ {#if isMissing}
353
+ <button
354
+ type="button"
355
+ class="shrink-0 text-destructive opacity-0 transition-opacity duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background group-hover:opacity-100 {effectiveIsMobile
356
+ ? '!opacity-100'
357
+ : ''}"
358
+ onclick={(e) => {
359
+ e.stopPropagation();
360
+ dispatch('delete', { item });
361
+ }}
362
+ aria-label={$t('item.deleteMissing')}
363
+ >
364
+ <IconTrash class="size-5 stroke-[1.333]" />
365
+ </button>
366
+ {/if}
659
367
  {/if}
660
368
  </div>
661
369
  </div>
662
-
663
- <style>
664
- .thumbnail-button {
665
- transform: scale(1);
666
- transform-origin: top left;
667
- border-radius: var(--radius-large);
668
- will-change: transform;
669
- backface-visibility: hidden;
670
- -webkit-font-smoothing: antialiased;
671
- }
672
-
673
- .no-transition {
674
- transition: none !important;
675
- }
676
-
677
- .thumbnail-button.is-selected {
678
- transform: scale(0.81) translate(6px, 6px);
679
- }
680
-
681
- .thumbnail-button.can-hover:hover {
682
- opacity: 0.8;
683
- }
684
-
685
- :global(.group:hover:not(.cursor-default):not(.bg-\[hsl\(var\(--light-green\)\)\])) .thumbnail-button.can-hover:not(.is-selected),
686
- :global(.hover-effect:not(.cursor-default)) .thumbnail-button.can-hover:not(.is-selected) {
687
- transform: scale(0.81) translate(6px, 6px);
688
- }
689
-
690
- .thumbnail-button:not(.no-transition) {
691
- transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1),
692
- opacity 150ms cubic-bezier(0.4, 0, 0.2, 1),
693
- border-radius 150ms cubic-bezier(0.4, 0, 0.2, 1);
694
- }
695
-
696
- .fade-in {
697
- opacity: 0;
698
- transition: opacity 150ms ease-out;
699
- }
700
-
701
- img[src].fade-in {
702
- opacity: 1;
703
- }
704
-
705
- /* Prevent fade-in animation for cached items */
706
- .no-fade {
707
- opacity: 1 !important;
708
- animation: none !important;
709
- transition: none !important;
710
- }
711
- </style>