@widgetic/file-browser 0.5.44 → 0.5.45

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.
@@ -230,10 +230,10 @@
230
230
  'flex w-full items-center gap-3 rounded-xl border border-border bg-background p-2 transition-colors duration-fast',
231
231
  thumbnailOnly ? 'h-auto w-auto border-0 bg-transparent p-0' : 'h-16',
232
232
  !thumbnailOnly && !effectiveIsMobile && !isSelected
233
- ? 'hover:bg-brand-subtle group-data-[drag-hover=true]/file-tile:bg-brand-subtle has-[[data-state=open]]:bg-accent'
233
+ ? 'hover:bg-accent group-data-[drag-hover=true]/file-tile:bg-brand-subtle! has-[[data-state=open]]:bg-accent'
234
234
  : '',
235
235
  !thumbnailOnly && !effectiveIsMobile && isSelected
236
- ? 'group-data-[drag-hover=true]/file-tile:bg-brand-subtle'
236
+ ? 'group-data-[drag-hover=true]/file-tile:bg-brand-subtle!'
237
237
  : '',
238
238
  !thumbnailOnly && isSelected ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand' : '',
239
239
  !thumbnailOnly && (!isMissing || allowSelecting) ? 'cursor-pointer' : ''
@@ -75,7 +75,7 @@
75
75
  >
76
76
  <!-- Tile activation mirrors the folder thumb; keyboard users use the existing open-folder control. -->
77
77
  <div
78
- class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-all duration-fast hover:bg-brand-subtle has-[[data-state=open]]:bg-accent group-data-[folder-drop-hover=true]:bg-brand-subtle group-data-[folder-drop-hover=true]:ring-2 group-data-[folder-drop-hover=true]:ring-brand"
78
+ class="flex h-16 w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-background p-2 transition-all duration-fast hover:bg-accent has-[[data-state=open]]:bg-accent group-data-[folder-drop-hover=true]:bg-brand-subtle! group-data-[folder-drop-hover=true]:ring-2 group-data-[folder-drop-hover=true]:ring-inset group-data-[folder-drop-hover=true]:ring-brand"
79
79
  onclick={handleTileClick}
80
80
  role="presentation"
81
81
  >
@@ -37,6 +37,7 @@
37
37
  import { getFileTypeOf } from '../../utils/fileKinds';
38
38
  import { countPreviewNavigationPeers } from '../../utils/previewNavigation';
39
39
  import { toSafeFontFamilyName } from '../../utils/safeText';
40
+ import { isFileGone } from '../../utils/fileGoneProbe';
40
41
  import { previewKeyAction } from '../../utils/previewKeys';
41
42
  import { getCachedImageNaturalSize, preloadImageUrl, probeDecodedImage } from '../../utils/imagePreviewCache';
42
43
  import { IMAGE_SLOW_LOADER_DELAY_MS, imageRevealDelayMs } from '../../utils/imagePreviewVisualState';
@@ -535,14 +536,28 @@
535
536
  dispatch('fileUnavailable', { id: fileId });
536
537
  }
537
538
 
539
+ /**
540
+ * The font could not be drawn. That alone is not a reason to remove it from the list (a corrupt or unsupported font, a blocked
541
+ * request): the preview shows its error state and the file stays. It is removed only when the server confirms it is gone.
542
+ */
543
+ async function handleFontLoadFailed(failedFile: FileSystemItem) {
544
+ try {
545
+ if (await isFileGone(failedFile.url)) reportFileUnavailable(failedFile.id);
546
+ } catch (error) {
547
+ console.error('FilePreview: Could not check whether the font still exists:', failedFile.name, error);
548
+ }
549
+ }
550
+
538
551
  // Autoplay when component mounts
539
552
  onMount(() => {
540
553
 
541
554
  if(showLogs) console.log('FilePreview: onMount: file:', file);
542
555
 
543
556
  if (fileType === 'font' && file.url) {
544
- void checkFileExists(file.url).then((ok) => {
545
- if (!ok) reportFileUnavailable(file.id);
557
+ // Only a server answer of 404/410 removes the font from the list; a blocked or failed request keeps it (see fileGoneProbe).
558
+ const checkedFileId = file.id;
559
+ void isFileGone(file.url).then((gone) => {
560
+ if (gone) reportFileUnavailable(checkedFileId);
546
561
  });
547
562
  }
548
563
 
@@ -556,17 +571,6 @@
556
571
  }
557
572
  });
558
573
 
559
- // Add the checkFileExists function
560
- async function checkFileExists(url: string | undefined): Promise<boolean> {
561
- if (!url) return false;
562
- try {
563
- const response = await fetch(url, { method: 'HEAD' });
564
- return response.ok;
565
- } catch (error) {
566
- return false;
567
- }
568
- }
569
-
570
574
  // Add reactive statement to check if current file is missing
571
575
  $: isMissing = $missingFiles.has(file.id);
572
576
 
@@ -751,7 +755,7 @@
751
755
  src={fileUrl}
752
756
  {fontName}
753
757
  previewText={file.previewText || undefined}
754
- on:unavailable={() => reportFileUnavailable(file.id)}
758
+ on:unavailable={() => handleFontLoadFailed(file)}
755
759
  />
756
760
  {:else if fileType === 'image' || fileType === 'svg'}
757
761
  {#if fileType === 'svg'}
@@ -622,7 +622,7 @@
622
622
  {#if enabled && container && !modalOpen}
623
623
  <div
624
624
  bind:this={selectionBox}
625
- class="selection-box pointer-events-none absolute rounded-lg border border-brand bg-brand-subtle/20"
625
+ class="selection-box pointer-events-none absolute rounded-none border border-brand bg-brand-subtle/20"
626
626
  style="display: none; position: absolute;"
627
627
  ></div>
628
628
  {/if}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Decides whether a file is really gone from its address, before the browser removes it from the list.
3
+ *
4
+ * Why this exists: the preview of a font used to ask `fetch(url, { method: 'HEAD' })` whether the file was still there, and treated any
5
+ * failure as "gone". The CDN answers HEAD without CORS headers (and its CORS rule allows GET only), so from the site the browser
6
+ * blocked every HEAD, the check read "gone", and the file was evicted from the list and from the saved copy: the font and its Recent
7
+ * card disappeared the moment it was clicked, and came back after a refresh (the API still had it).
8
+ *
9
+ * The rule now: only an answer from the server that says the file is not there (404 or 410) means gone. A request the browser
10
+ * blocked, a network error or any other status says nothing about the file, so the file stays and its preview shows the error state.
11
+ * The request is a GET for the first byte (CORS is allowed for GET) so it works across origins.
12
+ */
13
+ type FetchLike = (input: string, init?: RequestInit) => Promise<Pick<Response, 'status'>>;
14
+ /**
15
+ * `true` only when the server answered that the file does not exist; `false` for every other outcome (found, blocked, offline).
16
+ *
17
+ * @param fileUrl - The address of the file.
18
+ * @param fetchImplementation - `fetch`, replaceable in tests.
19
+ */
20
+ export declare function isFileGone(fileUrl: string | undefined, fetchImplementation?: FetchLike): Promise<boolean>;
21
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Decides whether a file is really gone from its address, before the browser removes it from the list.
3
+ *
4
+ * Why this exists: the preview of a font used to ask `fetch(url, { method: 'HEAD' })` whether the file was still there, and treated any
5
+ * failure as "gone". The CDN answers HEAD without CORS headers (and its CORS rule allows GET only), so from the site the browser
6
+ * blocked every HEAD, the check read "gone", and the file was evicted from the list and from the saved copy: the font and its Recent
7
+ * card disappeared the moment it was clicked, and came back after a refresh (the API still had it).
8
+ *
9
+ * The rule now: only an answer from the server that says the file is not there (404 or 410) means gone. A request the browser
10
+ * blocked, a network error or any other status says nothing about the file, so the file stays and its preview shows the error state.
11
+ * The request is a GET for the first byte (CORS is allowed for GET) so it works across origins.
12
+ */
13
+ /** Status codes that say the file is no longer at its address. */
14
+ const GONE_STATUS_CODES = new Set([404, 410]);
15
+ /**
16
+ * `true` only when the server answered that the file does not exist; `false` for every other outcome (found, blocked, offline).
17
+ *
18
+ * @param fileUrl - The address of the file.
19
+ * @param fetchImplementation - `fetch`, replaceable in tests.
20
+ */
21
+ export async function isFileGone(fileUrl, fetchImplementation = (input, init) => fetch(input, init)) {
22
+ // Without an address there is nothing to ask: the file is not proven gone, and nothing is removed because of it.
23
+ if (!fileUrl)
24
+ return false;
25
+ try {
26
+ const response = await fetchImplementation(fileUrl, {
27
+ method: 'GET',
28
+ headers: { Range: 'bytes=0-0' }
29
+ });
30
+ return GONE_STATUS_CODES.has(response.status);
31
+ }
32
+ catch (error) {
33
+ // A blocked or failed request is not proof: keep the file.
34
+ console.warn('[fileGoneProbe] Could not ask whether the file still exists; keeping it:', fileUrl, error);
35
+ return false;
36
+ }
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/file-browser",
3
- "version": "0.5.44",
3
+ "version": "0.5.45",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "repository": {