@widgetic/file-browser 0.5.45 → 0.5.46

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.
@@ -3,6 +3,7 @@
3
3
  * Mirrors Figma "Folder Row" (274:1480) with 32px level indent and a 2px start guide line.
4
4
  */
5
5
  import type { FileSystemItem } from '../types';
6
+ import { IconArrowBounce } from '@widgetic/design-system/icons';
6
7
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
7
8
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
8
9
  $$bindings?: Bindings;
@@ -31,7 +32,7 @@ declare const FolderTree: $$__sveltets_2_IsomorphicComponent<{
31
32
  textClass?: string;
32
33
  selectedIconClass?: string;
33
34
  currentLocationClass?: string;
34
- selectedIcon?: any;
35
+ selectedIcon?: typeof IconArrowBounce;
35
36
  }, {
36
37
  [evt: string]: CustomEvent<any>;
37
38
  }, {}, {}, string>;
@@ -2,7 +2,7 @@
2
2
  Figma: Dropzone (component set 271:971, page File Browser)
3
3
  -->
4
4
  <script lang="ts">
5
- import { Button, IconButton, Tooltip } from '@widgetic/design-system/components';
5
+ import { Button, IconButton, HintTooltip } from '@widgetic/design-system/components';
6
6
  import { IconCloudUpload, IconHelp } from '@widgetic/design-system/icons';
7
7
  import { useI18n } from '../../i18n/context';
8
8
  import { splitAround } from '../../i18n/text';
@@ -128,33 +128,20 @@
128
128
  {/if}
129
129
  </div>
130
130
 
131
- <div class="absolute end-4 top-1/2 z-[2] -translate-y-1/2">
132
- <Tooltip.Provider delayDuration={200}>
133
- <Tooltip.Root>
134
- <Tooltip.Trigger class="inline-flex">
135
- {#snippet child({ props }: { props: Record<string, unknown> })}
136
- <IconButton
137
- {...props}
138
- variant="ghost"
139
- size="default"
140
- class="size-8 text-muted-foreground hover:text-foreground"
141
- label={tooltipTypesText}
142
- >
143
- <IconHelp class="size-4 stroke-2" aria-hidden="true" />
144
- </IconButton>
145
- {/snippet}
146
- </Tooltip.Trigger>
147
- <Tooltip.Portal>
148
- <Tooltip.Content
149
- side="top"
150
- sideOffset={8}
151
- class="max-w-[250px] whitespace-pre-line break-words"
152
- >
153
- <p class="text-caption">{tooltipTypesText}</p>
154
- </Tooltip.Content>
155
- </Tooltip.Portal>
156
- </Tooltip.Root>
157
- </Tooltip.Provider>
131
+ <div class="absolute end-4 top-4 z-[2]">
132
+ <HintTooltip content={tooltipTypesText} side="top" sideOffset={8} contentClass="max-w-[250px]">
133
+ {#snippet trigger({ props })}
134
+ <IconButton
135
+ {...props}
136
+ variant="ghost"
137
+ size="default"
138
+ class="fb-dropzone-help size-8 text-muted-foreground hover:text-foreground"
139
+ label={tooltipTypesText}
140
+ >
141
+ <IconHelp class="size-4 stroke-2" aria-hidden="true" />
142
+ </IconButton>
143
+ {/snippet}
144
+ </HintTooltip>
158
145
  </div>
159
146
  </div>
160
147
 
@@ -21,7 +21,22 @@
21
21
  import '@widgetic/design-system/styles';
22
22
 
23
23
  // Design system components
24
- import { Alert, Button, DebugGrid, WScrollArea, EmptyState, ErrorState, ActionModal, DropdownMenu, Tooltip, IconButton, toast } from '@widgetic/design-system/components';
24
+ import {
25
+ Alert,
26
+ Button,
27
+ DebugGrid,
28
+ WScrollArea,
29
+ EmptyState,
30
+ ErrorState,
31
+ ActionModal,
32
+ DropdownMenu,
33
+ FilterByButton,
34
+ SortDirectionButton,
35
+ HintTooltip,
36
+ toast,
37
+ type FilterByOption,
38
+ type SortDirection
39
+ } from '@widgetic/design-system/components';
25
40
  import {
26
41
  IconCheck,
27
42
  IconPhoto,
@@ -35,8 +50,7 @@
35
50
  IconFileUnknown,
36
51
  IconInfoCircle,
37
52
  IconArrowUp,
38
- IconArrowDown,
39
- IconChevronDown
53
+ IconArrowDown
40
54
  } from '@widgetic/design-system/icons';
41
55
 
42
56
  // LOCAL COMPONENT IMPORTS
@@ -49,6 +63,7 @@
49
63
  import { VirtualList, DragSelect, ControlToolbar } from '../ui';
50
64
  import TileSkeleton from '../ui/TileSkeleton.svelte';
51
65
  import { gridColumnsForWidth } from '../../utils/gridLayout';
66
+ import { previewNavigationFiles } from '../../utils/previewListNavigation';
52
67
 
53
68
  // TYPE IMPORTS
54
69
  import type { FileSystemItem, FileSystemRoot, FolderItemWithCount } from '../../types';
@@ -432,7 +447,8 @@
432
447
  let contentContainer: HTMLElement | null = null;
433
448
 
434
449
  // Add near other state variables
435
- let previewSource: 'main' | 'recent' = 'main';
450
+ let previewSource: 'main' | 'recent' | 'search' = 'main';
451
+ let previewNavigationList: FileSystemItem[] = [];
436
452
 
437
453
  // Add near other state variables
438
454
  let tabletBreakpoint = 744; // Default value
@@ -771,7 +787,9 @@
771
787
  const token = session?.accessToken || session?.access_token;
772
788
  if (token) {
773
789
  // Scope Dexie only — do not invent an empty apiBasePath upload config.
774
- const { ensureCacheOwnerFromSessionHint, setCacheOwner } = await import('@widgetic/cache-layer');
790
+ const { ensureCacheOwnerFromSessionHint, setCacheOwner } = await import(
791
+ '@widgetic/cache-layer'
792
+ );
775
793
  ensureCacheOwnerFromSessionHint();
776
794
  const payloadPart = token.split('.')[1];
777
795
  if (payloadPart) {
@@ -1056,13 +1074,21 @@
1056
1074
 
1057
1075
  // If there's a preview item, handle it the same way for both search and selected files
1058
1076
  if (event.detail.preview) {
1077
+ const previewNavigationFromSearch = Array.isArray(event.detail.previewNavigationList)
1078
+ ? event.detail.previewNavigationList
1079
+ : [];
1080
+ previewNavigationList =
1081
+ previewNavigationFromSearch.length > 0
1082
+ ? previewNavigationFromSearch
1083
+ : previewNavigationFiles(sortedFilteredFiles);
1084
+ previewSource = previewNavigationFromSearch.length > 0 ? 'search' : 'main';
1059
1085
  // Wait for the folder content to update
1060
1086
  setTimeout(() => {
1061
1087
  const file = event.detail.preview;
1062
1088
  previewFile = file; // Open preview
1063
1089
  scrollItemIntoView(file.id); // Scroll into view
1064
1090
  }, 100);
1065
- }
1091
+ }
1066
1092
  }
1067
1093
 
1068
1094
  /**
@@ -1307,6 +1333,7 @@
1307
1333
  const file = event.detail;
1308
1334
  previewFile = file;
1309
1335
  previewSource = 'recent';
1336
+ previewNavigationList = recentFiles;
1310
1337
  // No scrolling for recent files
1311
1338
  }
1312
1339
 
@@ -1361,6 +1388,7 @@
1361
1388
  function handleFileClick(file: FileSystemItem) {
1362
1389
  previewFile = file;
1363
1390
  previewSource = 'main';
1391
+ previewNavigationList = previewNavigationFiles(sortedFilteredFiles);
1364
1392
  // Wait for the preview modal to open before scrolling
1365
1393
  setTimeout(() => {
1366
1394
  scrollItemIntoView(file.id);
@@ -1388,7 +1416,8 @@
1388
1416
  }
1389
1417
  setTimeout(() => {
1390
1418
  previewFile = null;
1391
- previewSource = 'main'; // Reset the source
1419
+ previewSource = 'main';
1420
+ previewNavigationList = [];
1392
1421
  }, 200);
1393
1422
  }
1394
1423
  }
@@ -2340,7 +2369,13 @@
2340
2369
  updateFolderCounts($fileStore.root, filter);
2341
2370
  }
2342
2371
 
2343
- $: currentViewFiles = sortedFilteredFiles.filter((item) => item?.type === 'file');
2372
+ $: currentViewFiles = previewNavigationFiles(sortedFilteredFiles);
2373
+ $: previewListForModal =
2374
+ previewSource === 'recent'
2375
+ ? recentFiles
2376
+ : previewSource === 'search' && previewNavigationList.length > 0
2377
+ ? previewNavigationList
2378
+ : currentViewFiles;
2344
2379
 
2345
2380
  // Add this reactive statement to update folderStructure
2346
2381
  $: {
@@ -2801,6 +2836,14 @@
2801
2836
  };
2802
2837
 
2803
2838
  let filterOptions: FilterOptionRow[] = [];
2839
+ $: filterByOptions = filterOptions.map(
2840
+ (option): FilterByOption => ({
2841
+ value: option.value,
2842
+ label: option.label,
2843
+ icon: option.icon as unknown as FilterByOption['icon']
2844
+ })
2845
+ );
2846
+ $: filterByLabel = $t('filter.by', { type: '\u0001' }).split('\u0001')[0].trim();
2804
2847
  $: filterOptions = [
2805
2848
  { value: 'all', label: $t('filterOption.all'), icon: IconFiles },
2806
2849
  { value: 'image', label: $t('filterOption.image'), icon: IconPhoto },
@@ -2833,6 +2876,12 @@
2833
2876
  { value: 'date', labelKey: 'sort.date' },
2834
2877
  { value: 'size', labelKey: 'sort.size' }
2835
2878
  ] as const;
2879
+ $: sortByOptions = sortOptions.map(
2880
+ (option): FilterByOption => ({
2881
+ value: option.value,
2882
+ label: $t(option.labelKey)
2883
+ })
2884
+ );
2836
2885
 
2837
2886
  // Replace the existing reactive statement for filter
2838
2887
  $: {
@@ -3048,11 +3097,11 @@ mainGridClass="app-main-grid"
3048
3097
  title={libraryMode ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel')) : ''}
3049
3098
  />
3050
3099
 
3051
- <!-- FILE BROWSER CONTROLS: Figma — full-width search, then compact filter/sort row -->
3100
+ <!-- FILE BROWSER CONTROLS: Figma — one row: search (flex-1), filter, sort, direction (291:1973) -->
3052
3101
  <div
3053
- class="file-browser-controls flex min-w-0 shrink-0 flex-col gap-2 pb-4 {controlsTopPaddingClass} {edgePaddingClass}"
3102
+ class="file-browser-controls flex min-w-0 shrink-0 flex-nowrap max-[640px]:flex-wrap items-center gap-2 pb-4 {controlsTopPaddingClass} {edgePaddingClass}"
3054
3103
  >
3055
- <div class="search-bar-container relative z-[61] w-full min-w-0">
3104
+ <div class="search-bar-container relative z-[61] min-w-0 w-full min-w-[min(100%,280px)] flex-1 basis-[280px]">
3056
3105
  <SearchDropdown
3057
3106
  root={$fileStore.root}
3058
3107
  currentFilter={filter}
@@ -3063,112 +3112,38 @@ mainGridClass="app-main-grid"
3063
3112
  </div>
3064
3113
 
3065
3114
  {#if controlsShowFilters || controlsShowSorting}
3066
- <div class="controls-container flex min-w-0 max-w-full items-center gap-2 overflow-x-auto">
3115
+ <div class="controls-container flex min-w-0 max-w-full shrink-0 flex-wrap items-center gap-2">
3067
3116
 
3068
3117
  {#if controlsShowFilters}
3069
3118
  <div class="filter-controls-container relative z-10 flex items-center">
3070
- {#key filterMenuKey}
3071
- <DropdownMenu.Root onOpenChange={setFilterMenuOpen}>
3072
- <DropdownMenu.Trigger
3073
- class="filter-button group flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-lg border border-input bg-background px-3 text-start transition-colors duration-fast hover:bg-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
3074
- >
3075
- <span class="text-body text-muted-foreground whitespace-nowrap">{$t('filter.by', { type: '\u0001' }).split('\u0001')[0].trim()}</span>
3076
- <!-- The chip is as wide as what it says (Figma: it hugs its text); it used to reserve the widest label and looked stretched. -->
3077
- <span class="whitespace-nowrap text-body-medium text-foreground">{$t(`filterOption.${filter}`)}</span>
3078
- <!-- One arrow that turns up while the menu is open, with the motion of the accordion's arrow (it used to swap two icons and jumped). -->
3079
- <IconChevronDown class="size-4 shrink-0 stroke-2 opacity-50 transition-transform duration-base group-data-[state=open]:rotate-180" aria-hidden="true" />
3080
- </DropdownMenu.Trigger>
3081
- <DropdownMenu.Content side="bottom" align="start" class="filter-dropdown w-[12.5rem] min-w-0">
3082
- {#each filterOptions as option}
3083
- {@const OptionIcon = option.icon}
3084
- <DropdownMenu.Item
3085
- class="filter-dropdown-item relative flex w-full items-center gap-2 rounded-lg px-2 py-1.5 ps-8 {filter === option.value ? 'bg-brand-subtle' : ''} data-highlighted:bg-accent"
3086
- onclick={() => handleFilterChange(option.value as FileFilterType)}
3087
- >
3088
- <!-- The check slot: only the chosen option shows the check -->
3089
- <span class="absolute start-2 flex size-4 items-center justify-center">
3090
- {#if filter === option.value}
3091
- <IconCheck class="size-4 stroke-2 text-foreground" aria-hidden="true" />
3092
- {/if}
3093
- </span>
3094
- <OptionIcon class="size-4 shrink-0 stroke-2" aria-hidden="true" />
3095
- <span class="text-body min-w-0 flex-1 truncate">{option.label}</span>
3096
- </DropdownMenu.Item>
3097
- {/each}
3098
- </DropdownMenu.Content>
3099
- </DropdownMenu.Root>
3100
- {/key}
3119
+ <FilterByButton
3120
+ class="filter-button"
3121
+ label={filterByLabel}
3122
+ options={filterByOptions}
3123
+ value={filter}
3124
+ onValueChange={(next: string) => handleFilterChange(next as FileFilterType)}
3125
+ menuClass="filter-dropdown"
3126
+ />
3101
3127
  </div>
3102
3128
  {/if}
3103
3129
 
3104
3130
  {#if controlsShowSorting}
3105
3131
  <div class="sort-controls-container flex items-center gap-2">
3106
- {#key sortMenuKey}
3107
- <DropdownMenu.Root onOpenChange={setSortMenuOpen}>
3108
- <DropdownMenu.Trigger
3109
- class="sort-button group flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-lg border border-input bg-background px-3 text-start transition-colors duration-fast hover:bg-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
3110
- >
3111
- <span class="text-body text-muted-foreground whitespace-nowrap">{$t('sort.by')}</span>
3112
- <span class="whitespace-nowrap text-body-medium text-foreground">{$t(`sort.${$sortCriteria}`)}</span>
3113
- <IconChevronDown class="size-4 shrink-0 stroke-2 opacity-50 transition-transform duration-base group-data-[state=open]:rotate-180" aria-hidden="true" />
3114
- </DropdownMenu.Trigger>
3115
- <DropdownMenu.Content side="bottom" align="start" class="sort-dropdown w-40 min-w-0">
3116
- {#each sortOptions as option}
3117
- <DropdownMenu.Item
3118
- class="sort-dropdown-item relative flex w-full items-center gap-2 rounded-lg px-2 py-1.5 ps-8 {$sortCriteria === option.value ? 'bg-brand-subtle' : ''} data-highlighted:bg-accent"
3119
- onclick={() => sortCriteria.set(option.value)}
3120
- >
3121
- <!-- The check slot: only the chosen option shows the check -->
3122
- <span class="absolute start-2 flex size-4 items-center justify-center">
3123
- {#if $sortCriteria === option.value}
3124
- <IconCheck class="size-4 stroke-2 text-foreground" aria-hidden="true" />
3125
- {/if}
3126
- </span>
3127
- <span class="text-body">{$t(option.labelKey)}</span>
3128
- </DropdownMenu.Item>
3129
- {/each}
3130
- </DropdownMenu.Content>
3131
- </DropdownMenu.Root>
3132
- {/key}
3133
-
3134
- <Tooltip.Provider delayDuration={200}>
3135
- <Tooltip.Root>
3136
- <Tooltip.Trigger class="inline-flex">
3137
- <!-- The trigger hands its props to the button itself: a button inside the trigger's own button is not valid HTML -->
3138
- {#snippet child({ props }: { props: Record<string, unknown> })}
3139
- <IconButton
3140
- {...props}
3141
- variant="outline"
3142
- size="default"
3143
- class="sort-order-button size-9"
3144
- label={$sortDirection === 'asc' ? $t('sort.orderDescending') : $t('sort.orderAscending')}
3145
- onclick={(event: MouseEvent) => {
3146
- // The trigger's own click handler closes the tooltip, so it runs too
3147
- (props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
3148
- toggleSortDirection();
3149
- }}
3150
- >
3151
- {#if $sortDirection === 'asc'}
3152
- <IconArrowUp class="size-4 stroke-2" aria-hidden="true" />
3153
- {:else}
3154
- <IconArrowDown class="size-4 stroke-2" aria-hidden="true" />
3155
- {/if}
3156
- </IconButton>
3157
- {/snippet}
3158
- </Tooltip.Trigger>
3159
- <Tooltip.Portal>
3160
- <!-- Opens above the button. The page portal paints it over the module box. -->
3161
- <Tooltip.Content
3162
- side="top"
3163
- align="end"
3164
- sideOffset={8}
3165
- class="sort-order-tooltip bg-foreground text-background z-[99999] whitespace-pre-line rounded-lg px-2 py-1 text-center text-caption"
3166
- >
3167
- {$sortDirection === 'asc' ? $t('sort.orderDescending') : $t('sort.orderAscending')}
3168
- </Tooltip.Content>
3169
- </Tooltip.Portal>
3170
- </Tooltip.Root>
3171
- </Tooltip.Provider>
3132
+ <FilterByButton
3133
+ class="sort-button"
3134
+ label={$t('sort.by')}
3135
+ options={sortByOptions}
3136
+ value={$sortCriteria}
3137
+ onValueChange={(next: string) => sortCriteria.set(next as 'name' | 'date' | 'size')}
3138
+ menuClass="sort-dropdown w-40"
3139
+ />
3140
+ <SortDirectionButton
3141
+ class="sort-order-button"
3142
+ direction={$sortDirection}
3143
+ onDirectionChange={(next: SortDirection) => sortDirection.set(next)}
3144
+ ariaLabel={$sortDirection === 'asc' ? $t('sort.orderDescending') : $t('sort.orderAscending')}
3145
+ tooltipLabel={$sortDirection === 'asc' ? $t('sort.orderDescending') : $t('sort.orderAscending')}
3146
+ />
3172
3147
  </div>
3173
3148
  {/if}
3174
3149
  </div>
@@ -3314,6 +3289,7 @@ mainGridClass="app-main-grid"
3314
3289
  <RecentFiles class="recent-files-container"
3315
3290
  {recentFiles}
3316
3291
  visibleLimit={numberOfRecentFiles}
3292
+ containerWidth={mainContainerWidth}
3317
3293
  selectedFiles={allSelectedFiles}
3318
3294
  currentFilter={filter}
3319
3295
  {allowSelecting}
@@ -3436,7 +3412,7 @@ mainGridClass="app-main-grid"
3436
3412
  {allowSelecting}
3437
3413
  {showAddToEditor}
3438
3414
  currentFilter={filter}
3439
- currentFiles={previewSource === 'recent' ? recentFiles : currentViewFiles}
3415
+ currentFiles={previewListForModal}
3440
3416
  target={rootContainerClass}
3441
3417
  on:select={(event : any) => handleFileSelect(event.detail)}
3442
3418
  on:navigate={handlePreviewNavigate}
@@ -3,7 +3,7 @@
3
3
  import { createEventDispatcher } from 'svelte';
4
4
 
5
5
  // Design system imports
6
- import { Breadcrumbs, IconButton, Badge, Tooltip } from '@widgetic/design-system/components';
6
+ import { Breadcrumbs, IconButton, Badge, HintTooltip } from '@widgetic/design-system/components';
7
7
  import { IconFiles } from '@widgetic/design-system/icons';
8
8
 
9
9
  // Local stores imports
@@ -105,45 +105,36 @@
105
105
 
106
106
  {#if showSelectedFiles && selectedFilesCount > 0}
107
107
  <div class="header-actions-container flex shrink-0 items-center">
108
- <Tooltip.Provider delayDuration={300}>
109
- <Tooltip.Root>
110
- <Tooltip.Trigger class="inline-flex">
111
- <!-- The trigger hands its props to the button itself: a button inside the trigger's own button is not valid HTML -->
112
- {#snippet child({ props }: { props: Record<string, unknown> })}
113
- <IconButton
114
- {...props}
115
- variant="outline"
116
- size="default"
117
- label={$t('selectedFiles.title')}
118
- class="selected-files-button relative"
119
- onclick={(event: MouseEvent) => {
120
- // The trigger's own click handler closes the tooltip, so it runs too
121
- (props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
122
- handleToggleSelectedFiles();
123
- }}
124
- >
125
- <IconFiles class="size-4 stroke-2" aria-hidden="true" />
126
- <Badge
127
- variant="default"
128
- class="bg-primary text-primary-foreground absolute -top-1 -end-1 flex h-4 min-w-4 items-center justify-center px-1 text-caption-medium leading-none"
129
- >
130
- {selectedFilesCount}
131
- </Badge>
132
- </IconButton>
133
- {/snippet}
134
- </Tooltip.Trigger>
135
- <Tooltip.Portal>
136
- <Tooltip.Content
137
- side="bottom"
138
- align="end"
139
- sideOffset={6}
140
- class="selected-files-tooltip bg-foreground text-background text-caption z-[200000] rounded-lg px-2 py-1"
108
+ <HintTooltip
109
+ content={$t('selectedFiles.title')}
110
+ side="bottom"
111
+ align="end"
112
+ sideOffset={6}
113
+ delayDuration={300}
114
+ contentClass="z-[200000]"
115
+ >
116
+ {#snippet trigger({ props })}
117
+ <IconButton
118
+ {...props}
119
+ variant="outline"
120
+ size="default"
121
+ label={$t('selectedFiles.title')}
122
+ class="selected-files-button relative"
123
+ onclick={(event: MouseEvent) => {
124
+ (props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
125
+ handleToggleSelectedFiles();
126
+ }}
127
+ >
128
+ <IconFiles class="size-4 stroke-2" aria-hidden="true" />
129
+ <Badge
130
+ variant="default"
131
+ class="bg-primary text-primary-foreground absolute -top-1 -end-1 flex h-4 min-w-4 items-center justify-center px-1 text-caption-medium leading-none"
141
132
  >
142
- {$t('selectedFiles.title')}
143
- </Tooltip.Content>
144
- </Tooltip.Portal>
145
- </Tooltip.Root>
146
- </Tooltip.Provider>
133
+ {selectedFilesCount}
134
+ </Badge>
135
+ </IconButton>
136
+ {/snippet}
137
+ </HintTooltip>
147
138
  </div>
148
139
  {/if}
149
140
  </header>
@@ -14,8 +14,8 @@
14
14
  import { type FileFilterType } from '../../utils/fileTypes';
15
15
  import { ThumbHashImage } from '@widgetic/design-system/components';
16
16
  import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
17
- import { browser } from '$app/environment';
18
17
  import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
18
+ import { recentGridColumnsForWidth } from '../../utils/gridLayout';
19
19
 
20
20
  let className = '';
21
21
  export { className as class };
@@ -28,35 +28,17 @@
28
28
  export let columnWidth: number = 40;
29
29
  /** Cap from FileBrowser so the strip matches `getRecentFiles()`. */
30
30
  export let visibleLimit: number | undefined = undefined;
31
+ /** Measured width of the file browser panel (not the viewport). */
32
+ export let containerWidth: number = 0;
31
33
 
32
34
  const { t } = useI18n();
33
35
  const textDirection = useTextDirection();
34
36
  $: nameDirection = dirForUserText($textDirection);
35
37
 
36
- const DESKTOP_BREAKPOINT = 1156;
37
- const TABLET_BREAKPOINT = 744;
38
-
39
- let windowWidth = browser ? window.innerWidth : DESKTOP_BREAKPOINT;
40
- let gridColumns = 3;
41
- let maxRecentFiles = 3;
42
38
  let showLogs = false;
43
39
 
44
- function updateResponsiveLayout() {
45
- if (windowWidth > DESKTOP_BREAKPOINT) {
46
- const availableWidth = windowWidth;
47
- gridColumns = Math.min(6, Math.floor(availableWidth / 300));
48
- } else if (windowWidth > TABLET_BREAKPOINT) {
49
- gridColumns = 3;
50
- } else {
51
- gridColumns = 2;
52
- }
53
- maxRecentFiles = visibleLimit ?? recentFilesLimitForWidth(windowWidth);
54
- if (showLogs) console.log('Responsive layout updated:', { windowWidth, gridColumns, maxRecentFiles });
55
- }
56
-
57
- $: if (visibleLimit !== undefined) {
58
- maxRecentFiles = visibleLimit;
59
- }
40
+ $: gridColumns = containerWidth > 0 ? recentGridColumnsForWidth(containerWidth) : 3;
41
+ $: maxRecentFiles = visibleLimit ?? (containerWidth > 0 ? recentFilesLimitForWidth(containerWidth) : 3);
60
42
 
61
43
  // Figma Recent cards sit 24px apart (the tiles above them 16)
62
44
  $: gridGap = 24;
@@ -168,21 +150,9 @@
168
150
  return formatRelativeDate(date, translate);
169
151
  }
170
152
 
171
- function handleResize() {
172
- windowWidth = window.innerWidth;
173
- updateResponsiveLayout();
174
- }
175
-
176
153
  onMount(() => {
177
- if (browser) {
178
- window.addEventListener('resize', handleResize);
179
- updateResponsiveLayout();
180
- if (recentFiles.length > 0) {
181
- checkFiles();
182
- }
183
- return () => {
184
- window.removeEventListener('resize', handleResize);
185
- };
154
+ if (recentFiles.length > 0) {
155
+ checkFiles();
186
156
  }
187
157
  });
188
158
 
@@ -26,6 +26,7 @@ declare const RecentFiles: $$__sveltets_2_IsomorphicComponent<{
26
26
  allowSelecting?: boolean;
27
27
  columnWidth?: number;
28
28
  /** Cap from FileBrowser so the strip matches `getRecentFiles()`. */ visibleLimit?: number | undefined;
29
+ /** Measured width of the file browser panel (not the viewport). */ containerWidth?: number;
29
30
  }, {
30
31
  fileClick: CustomEvent<any>;
31
32
  select: CustomEvent<any>;