@widgetic/file-browser 0.5.45 → 0.5.47

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 (31) hide show
  1. package/dist/components/core/Dropzone.svelte +15 -28
  2. package/dist/components/core/FileBrowser.svelte +111 -128
  3. package/dist/components/core/FileUploader.svelte +10 -13
  4. package/dist/components/core/Header.svelte +30 -39
  5. package/dist/components/core/RecentFiles.svelte +27 -40
  6. package/dist/components/core/RecentFiles.svelte.d.ts +2 -0
  7. package/dist/components/core/SearchDropdown.svelte +88 -26
  8. package/dist/components/core/SearchDropdown.svelte.d.ts +2 -0
  9. package/dist/components/core/UploadPanel.svelte +19 -24
  10. package/dist/components/previews/FilePreview.svelte +26 -50
  11. package/dist/components/previews/PreviewHeaderBar.svelte +1 -1
  12. package/dist/i18n/messages.d.ts +2 -1
  13. package/dist/i18n/messages.js +2 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +2 -1
  16. package/dist/types.d.ts +2 -0
  17. package/dist/utils/brandKitLibraryTree.d.ts +23 -0
  18. package/dist/utils/brandKitLibraryTree.js +135 -0
  19. package/dist/utils/fileOperations.js +2 -3
  20. package/dist/utils/gridLayout.d.ts +14 -1
  21. package/dist/utils/gridLayout.js +27 -2
  22. package/dist/utils/libraryTree.js +13 -2
  23. package/dist/utils/previewListNavigation.d.ts +10 -0
  24. package/dist/utils/previewListNavigation.js +39 -0
  25. package/dist/utils/recentFilesLimit.js +2 -5
  26. package/dist/utils/searchDropdownPhase.d.ts +17 -0
  27. package/dist/utils/searchDropdownPhase.js +23 -0
  28. package/dist/utils/uploadPanelDismiss.d.ts +13 -0
  29. package/dist/utils/uploadPanelDismiss.js +11 -0
  30. package/dist/utils/widgeticUpload.js +2 -0
  31. package/package.json +1 -1
@@ -11,11 +11,12 @@
11
11
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
12
12
  import { FileIcon, SelectedBadge } from '../ui';
13
13
  import { persistentSelectStore } from '../../stores/persistentSelectStore';
14
+ import { isMobileStore } from '../../stores/viewportStore';
14
15
  import { type FileFilterType } from '../../utils/fileTypes';
15
16
  import { ThumbHashImage } from '@widgetic/design-system/components';
16
- import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
17
- import { browser } from '$app/environment';
17
+ import { IconExclamationCircle, IconPlayerPlayFilled, IconTrash } from '@widgetic/design-system/icons';
18
18
  import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
19
+ import { recentGridColumnsForWidth } from '../../utils/gridLayout';
19
20
 
20
21
  let className = '';
21
22
  export { className as class };
@@ -28,35 +29,17 @@
28
29
  export let columnWidth: number = 40;
29
30
  /** Cap from FileBrowser so the strip matches `getRecentFiles()`. */
30
31
  export let visibleLimit: number | undefined = undefined;
32
+ /** Measured width of the file browser panel (not the viewport). */
33
+ export let containerWidth: number = 0;
31
34
 
32
35
  const { t } = useI18n();
33
36
  const textDirection = useTextDirection();
34
37
  $: nameDirection = dirForUserText($textDirection);
35
38
 
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
39
  let showLogs = false;
43
40
 
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
- }
41
+ $: gridColumns = containerWidth > 0 ? recentGridColumnsForWidth(containerWidth) : 3;
42
+ $: maxRecentFiles = visibleLimit ?? (containerWidth > 0 ? recentFilesLimitForWidth(containerWidth) : 3);
60
43
 
61
44
  // Figma Recent cards sit 24px apart (the tiles above them 16)
62
45
  $: gridGap = 24;
@@ -90,8 +73,8 @@
90
73
  recentFiles.forEach((file) => {
91
74
  try {
92
75
  loadingStates.set(file.id, false);
93
- errorStates.set(file.id, false);
94
- file.isMissing = false;
76
+ // A file the list already knows to be gone stays gone: the card must not forget it and draw a picture that cannot load.
77
+ errorStates.set(file.id, Boolean(file.isMissing));
95
78
  } catch (error) {
96
79
  console.error('Error checking file:', file.name, error);
97
80
  file.isMissing = true;
@@ -168,21 +151,9 @@
168
151
  return formatRelativeDate(date, translate);
169
152
  }
170
153
 
171
- function handleResize() {
172
- windowWidth = window.innerWidth;
173
- updateResponsiveLayout();
174
- }
175
-
176
154
  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
- };
155
+ if (recentFiles.length > 0) {
156
+ checkFiles();
186
157
  }
187
158
  });
188
159
 
@@ -304,6 +275,22 @@
304
275
  {getFormattedDate(file.modified || new Date(), $t)}
305
276
  </p>
306
277
  </div>
278
+ {#if file.isMissing || errorStates.get(file.id)}
279
+ <!-- The error tile of the Files list: a missing file can be deleted from here, as it can there (FileItem). -->
280
+ <button
281
+ type="button"
282
+ 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 group-focus-within:opacity-100 {$isMobileStore
283
+ ? 'opacity-100!'
284
+ : ''}"
285
+ onclick={(e) => {
286
+ e.stopPropagation();
287
+ dispatch('delete', { item: file });
288
+ }}
289
+ aria-label={$t('item.deleteMissing')}
290
+ >
291
+ <IconTrash class="size-5 stroke-[1.6]" />
292
+ </button>
293
+ {/if}
307
294
  {#if allowSelecting && fileSelected}
308
295
  <!-- svelte-ignore a11y-click-events-have-key-events -->
309
296
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -26,7 +26,9 @@ 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
  }, {
31
+ delete: CustomEvent<any>;
30
32
  fileClick: CustomEvent<any>;
31
33
  select: CustomEvent<any>;
32
34
  } & {
@@ -27,11 +27,17 @@
27
27
  searchResultIds,
28
28
  shouldResetActiveIndex
29
29
  } from '../../utils/searchNavigation';
30
+ import { previewNavigationFiles } from '../../utils/previewListNavigation';
31
+ import {
32
+ resolveSearchDropdownPhase,
33
+ shouldShowSearchEmptyState,
34
+ shouldShowSearchResultsList
35
+ } from '../../utils/searchDropdownPhase';
30
36
  import { useI18n } from '../../i18n';
31
37
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
32
38
 
33
39
  const dispatch = createEventDispatcher<{
34
- navigate: { path: string[]; preview?: FileSystemItem };
40
+ navigate: { path: string[]; preview?: FileSystemItem; previewNavigationList?: FileSystemItem[] };
35
41
  }>();
36
42
 
37
43
  const { t } = useI18n();
@@ -44,6 +50,8 @@
44
50
  /** First segment of the location line: e.g. translated `library.defaultLabel` or `breadcrumbs.root`. */
45
51
  export let rootDisplayLabel = '';
46
52
  export let showLogs = false;
53
+ /** Overrides default debounce (150ms). Harness sets `window.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS`. */
54
+ export let searchDebounceMs: number | undefined = undefined;
47
55
 
48
56
  const matchHighlightClass = 'rounded-sm bg-brand-subtle px-0.5 text-body-medium';
49
57
  const resultsScrollMaxHeightPx = 400;
@@ -67,14 +75,39 @@
67
75
 
68
76
  let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
69
77
  let debouncedResultIds = '';
78
+ let settledSearchTerm = '';
79
+ let queryInFlight = false;
80
+ let searchGeneration = 0;
70
81
  let lastPointerClientX = -1;
71
82
  let lastPointerClientY = -1;
72
83
  let keyboardNavigationActive = false;
73
84
  let keyboardNavigationClearTimer: ReturnType<typeof setTimeout> | null = null;
74
85
  const searchPageStep = 10;
75
86
 
76
- $: debouncedTermEmpty = !searchValue.trim();
77
- $: showPanel = panelOpen && !debouncedTermEmpty;
87
+ $: trimmedSearchTerm = searchValue.trim();
88
+ $: showPanel = panelOpen && !!trimmedSearchTerm;
89
+ $: searchDropdownPhase = resolveSearchDropdownPhase({
90
+ panelOpen: showPanel,
91
+ trimmedTerm: trimmedSearchTerm,
92
+ settledTerm: settledSearchTerm,
93
+ queryInFlight,
94
+ resultCount: debouncedResults.length
95
+ });
96
+ $: showSearchEmpty = shouldShowSearchEmptyState(searchDropdownPhase);
97
+ $: showResultsList = shouldShowSearchResultsList(searchDropdownPhase, debouncedResults.length);
98
+ $: showSearchLoadingRow = searchDropdownPhase === 'loading' && debouncedResults.length === 0;
99
+
100
+ function searchTiming() {
101
+ if (typeof window === 'undefined') return { debounceMs: searchDebounceMs ?? 150, slowMs: 0 };
102
+ const w = window as typeof window & {
103
+ __WIDGETIC_FB_SEARCH_DEBOUNCE_MS?: number;
104
+ __WIDGETIC_FB_SEARCH_SLOW_MS?: number;
105
+ };
106
+ return {
107
+ debounceMs: searchDebounceMs ?? w.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS ?? 150,
108
+ slowMs: w.__WIDGETIC_FB_SEARCH_SLOW_MS ?? 0
109
+ };
110
+ }
78
111
 
79
112
  function queueDebouncedSearch(term: string) {
80
113
  if (searchDebounceTimer) {
@@ -82,31 +115,47 @@
82
115
  searchDebounceTimer = null;
83
116
  }
84
117
  if (!term || !root) {
118
+ queryInFlight = false;
119
+ settledSearchTerm = term;
85
120
  debouncedResults = [];
86
121
  debouncedResultIds = '';
87
122
  activeIndex = -1;
88
123
  return;
89
124
  }
125
+ const generation = ++searchGeneration;
126
+ queryInFlight = true;
127
+ const { debounceMs, slowMs } = searchTiming();
90
128
  searchDebounceTimer = setTimeout(() => {
91
- try {
92
- const termLower = term.toLowerCase();
93
- const raw = searchFileSystem(root, termLower, currentFilter);
94
- const nextResults = filterSearchResults(raw, currentFilter);
95
- const nextIds = searchResultIds(nextResults);
96
- debouncedResults = nextResults;
97
- if (shouldResetActiveIndex(debouncedResultIds, nextIds)) {
98
- activeIndex = firstSearchIndex(nextResults.length);
99
- } else if (activeIndex >= nextResults.length) {
100
- activeIndex = lastSearchIndex(nextResults.length);
129
+ searchDebounceTimer = null;
130
+ void (async () => {
131
+ try {
132
+ if (slowMs > 0) await new Promise((resolve) => setTimeout(resolve, slowMs));
133
+ if (generation !== searchGeneration) return;
134
+ const termLower = term.toLowerCase();
135
+ const raw = searchFileSystem(root, termLower, currentFilter);
136
+ const nextResults = filterSearchResults(raw, currentFilter);
137
+ if (generation !== searchGeneration) return;
138
+ const nextIds = searchResultIds(nextResults);
139
+ debouncedResults = nextResults;
140
+ if (shouldResetActiveIndex(debouncedResultIds, nextIds)) {
141
+ activeIndex = firstSearchIndex(nextResults.length);
142
+ } else if (activeIndex >= nextResults.length) {
143
+ activeIndex = lastSearchIndex(nextResults.length);
144
+ }
145
+ debouncedResultIds = nextIds;
146
+ settledSearchTerm = term;
147
+ queryInFlight = false;
148
+ } catch (error) {
149
+ if (generation !== searchGeneration) return;
150
+ if (showLogs) console.error('[SearchDropdown] search failed:', error);
151
+ debouncedResults = [];
152
+ debouncedResultIds = '';
153
+ activeIndex = -1;
154
+ settledSearchTerm = term;
155
+ queryInFlight = false;
101
156
  }
102
- debouncedResultIds = nextIds;
103
- } catch (error) {
104
- if (showLogs) console.error('[SearchDropdown] search failed:', error);
105
- debouncedResults = [];
106
- debouncedResultIds = '';
107
- activeIndex = -1;
108
- }
109
- }, 150);
157
+ })();
158
+ }, debounceMs);
110
159
  }
111
160
 
112
161
  $: {
@@ -181,7 +230,13 @@
181
230
  if (item.type === 'file') {
182
231
  folderPath.pop();
183
232
  }
184
- dispatch('navigate', { path: folderPath, ...(item.type === 'file' ? { preview: item } : {}) });
233
+ const previewNavigationList = previewNavigationFiles(debouncedResults);
234
+ dispatch('navigate', {
235
+ path: folderPath,
236
+ ...(item.type === 'file'
237
+ ? { preview: item, previewNavigationList }
238
+ : {})
239
+ });
185
240
  } catch (error) {
186
241
  if (showLogs) console.error('[SearchDropdown] openResult failed:', error);
187
242
  }
@@ -206,6 +261,9 @@
206
261
  searchValue = '';
207
262
  debouncedResults = [];
208
263
  debouncedResultIds = '';
264
+ settledSearchTerm = '';
265
+ queryInFlight = false;
266
+ searchGeneration += 1;
209
267
  activeIndex = -1;
210
268
  panelOpen = false;
211
269
  searchInputElement?.focus();
@@ -343,9 +401,9 @@
343
401
  id={listboxId}
344
402
  role="listbox"
345
403
  aria-label={$t('search.placeholder')}
346
- class="bg-popover text-popover-foreground border-border absolute start-0 top-full z-[60] mt-1 w-full overflow-hidden rounded-xl border shadow-md outline-hidden"
404
+ class="bg-popover text-popover-foreground border-border absolute start-0 top-full z-[60] mt-1 w-full overflow-hidden rounded-xl border border-border p-1 shadow-md outline-hidden"
347
405
  >
348
- {#if debouncedResults.length > 0}
406
+ {#if showResultsList}
349
407
  <WScrollArea
350
408
  class="search-dropdown-scroll w-full"
351
409
  style="max-height: {resultsScrollMaxHeightPx}px;"
@@ -400,8 +458,12 @@
400
458
  {/each}
401
459
  </div>
402
460
  </WScrollArea>
403
- {:else}
404
- <div class="flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
461
+ {:else if showSearchLoadingRow}
462
+ <div class="search-dropdown-loading flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
463
+ <p class="text-caption text-muted-foreground">{$t('preview.loading')}</p>
464
+ </div>
465
+ {:else if showSearchEmpty}
466
+ <div class="search-dropdown-empty flex min-h-[200px] flex-col items-center justify-center px-6 py-8">
405
467
  <EmptyState message={$t('searchModal.empty')} />
406
468
  </div>
407
469
  {/if}
@@ -18,10 +18,12 @@ declare const SearchDropdown: $$__sveltets_2_IsomorphicComponent<{
18
18
  /** Tree root (Widgetic file store). */ root?: FileSystemItem | null;
19
19
  /** First segment of the location line: e.g. translated `library.defaultLabel` or `breadcrumbs.root`. */ rootDisplayLabel?: string;
20
20
  showLogs?: boolean;
21
+ /** Overrides default debounce (150ms). Harness sets `window.__WIDGETIC_FB_SEARCH_DEBOUNCE_MS`. */ searchDebounceMs?: number | undefined;
21
22
  }, {
22
23
  navigate: CustomEvent<{
23
24
  path: string[];
24
25
  preview?: FileSystemItem;
26
+ previewNavigationList?: FileSystemItem[];
25
27
  }>;
26
28
  } & {
27
29
  [evt: string]: CustomEvent<any>;
@@ -3,7 +3,7 @@
3
3
  -->
4
4
  <script lang="ts">
5
5
  import UploadRow, { type UploadRowScope, type UploadRowState } from './UploadRow.svelte';
6
- import { IconButton, Progress, Tooltip } from '@widgetic/design-system/components';
6
+ import { IconButton, Progress, HintTooltip } from '@widgetic/design-system/components';
7
7
  import { IconChevronDown } from '@widgetic/design-system/icons';
8
8
  import { useI18n } from '../../i18n/context';
9
9
 
@@ -93,29 +93,24 @@
93
93
  </div>
94
94
  {#if items.length > 1}
95
95
  <div class="flex shrink-0 items-center">
96
- <Tooltip.Provider delayDuration={200}>
97
- <Tooltip.Root>
98
- <Tooltip.Trigger class="inline-flex">
99
- {#snippet child({ props }: { props: Record<string, unknown> })}
100
- <IconButton
101
- {...props}
102
- variant="ghost"
103
- size="default"
104
- label={expanded ? $t('upload.collapsePanel') : $t('upload.expandPanel')}
105
- onclick={onToggleExpand}
106
- >
107
- <!-- Down while the panel is open (it collapses), up while it is collapsed (it expands): one arrow that turns, with the motion of the accordion's arrow -->
108
- <IconChevronDown class="size-4 stroke-2 transition-transform duration-base {expanded ? '' : 'rotate-180'}" aria-hidden="true" />
109
- </IconButton>
110
- {/snippet}
111
- </Tooltip.Trigger>
112
- <Tooltip.Portal>
113
- <Tooltip.Content side="top" sideOffset={6} class="z-[99999]">
114
- <p class="text-caption">{expanded ? $t('upload.collapseUploader') : $t('upload.expandUploader')}</p>
115
- </Tooltip.Content>
116
- </Tooltip.Portal>
117
- </Tooltip.Root>
118
- </Tooltip.Provider>
96
+ <HintTooltip
97
+ content={expanded ? $t('upload.collapseUploader') : $t('upload.expandUploader')}
98
+ side="top"
99
+ sideOffset={6}
100
+ contentClass="z-[99999]"
101
+ >
102
+ {#snippet trigger({ props })}
103
+ <IconButton
104
+ {...props}
105
+ variant="ghost"
106
+ size="default"
107
+ label={expanded ? $t('upload.collapsePanel') : $t('upload.expandPanel')}
108
+ onclick={onToggleExpand}
109
+ >
110
+ <IconChevronDown class="size-4 stroke-2 transition-transform duration-base {expanded ? '' : 'rotate-180'}" aria-hidden="true" />
111
+ </IconButton>
112
+ {/snippet}
113
+ </HintTooltip>
119
114
  </div>
120
115
  {/if}
121
116
  </div>
@@ -35,7 +35,10 @@
35
35
 
36
36
  // Utils
37
37
  import { getFileTypeOf } from '../../utils/fileKinds';
38
- import { countPreviewNavigationPeers } from '../../utils/previewNavigation';
38
+ import {
39
+ hasPreviewNavigation,
40
+ stepPreviewNavigation
41
+ } from '../../utils/previewListNavigation';
39
42
  import { toSafeFontFamilyName } from '../../utils/safeText';
40
43
  import { isFileGone } from '../../utils/fileGoneProbe';
41
44
  import { previewKeyAction } from '../../utils/previewKeys';
@@ -372,7 +375,7 @@
372
375
  function preloadNeighborPreviewImages() {
373
376
  if (!open || fileType !== 'image') return;
374
377
  for (const direction of ['prev', 'next'] as const) {
375
- const neighbor = findNextAvailableFile(currentIndex, direction);
378
+ const neighbor = findNextAvailableFile(direction);
376
379
  if (!neighbor?.url) continue;
377
380
  if (getFileTypeOf(neighbor) !== 'image') continue;
378
381
  void preloadImageUrl(neighbor.url);
@@ -381,38 +384,11 @@
381
384
 
382
385
  $: currentIndex = currentFiles.findIndex((f: FileSystemItem) => f.id === file.id);
383
386
 
384
- function findNextAvailableFile(startIndex: number, direction: 'next' | 'prev'): FileSystemItem | null {
385
- // console.log('Finding next available file from index:', startIndex, 'direction:', direction);
386
- let index = startIndex;
387
- const totalFiles = currentFiles.length;
388
-
389
- // Check up to one full cycle through the files
390
- for (let i = 0; i < totalFiles; i++) {
391
- if (direction === 'next') {
392
- index = (index + 1) % totalFiles;
393
- } else {
394
- index = index > 0 ? index - 1 : totalFiles - 1;
395
- }
396
-
397
- const candidateFile = currentFiles[index];
398
- if(showLogs) console.log('Checking file:', {
399
- index,
400
- name: candidateFile.name,
401
- isMissing: $missingFiles.has(candidateFile.id)
402
- });
403
-
404
- if (candidateFile.id !== file.id && !$missingFiles.has(candidateFile.id)) {
405
- if(showLogs) console.log('Found available file:', candidateFile.name);
406
- return candidateFile;
407
- }
408
- }
409
- if(showLogs) console.log('No available files found');
410
- return null;
387
+ function findNextAvailableFile(direction: 'next' | 'prev'): FileSystemItem | null {
388
+ return stepPreviewNavigation(currentFiles, file.id, direction, $missingFiles);
411
389
  }
412
390
 
413
- $: showNavigation =
414
- allowSelecting &&
415
- countPreviewNavigationPeers(currentFiles, file, $missingFiles) > 0;
391
+ $: showNavigation = hasPreviewNavigation(currentFiles, $missingFiles);
416
392
 
417
393
  // A new file starts with its own reveal state: nothing shown, nothing loaded, a fresh slow-loader clock. This block sits
418
394
  // ABOVE the one that sizes the card on purpose, and that one reads `imageStateForFileId`, so when the file changes the reset
@@ -445,27 +421,27 @@
445
421
  ? fittedImage
446
422
  : getModalDimensions(fileType);
447
423
 
424
+ function isTypingTarget(target: EventTarget | null): boolean {
425
+ if (!(target instanceof HTMLElement)) return false;
426
+ const tag = target.tagName;
427
+ if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
428
+ return target.isContentEditable;
429
+ }
430
+
448
431
  function handleKeydown(event: KeyboardEvent) {
449
- if (!open || !allowSelecting || !showNavigation) return;
450
-
432
+ if (!open || !showNavigation) return;
433
+ if (isTypingTarget(event.target)) return;
434
+
451
435
  // The arrow keys follow the reading direction: the left arrow is "previous" in English and "next" in Arabic.
452
436
  const keyAction = previewKeyAction(event.key, $textDirection);
453
437
  if (keyAction === 'previous') {
454
438
  event.preventDefault();
455
- // console.log('Left arrow pressed, current index:', currentIndex);
456
- const prevFile = findNextAvailableFile(currentIndex, 'prev');
457
- if (prevFile) {
458
- // console.log('Navigating to previous file:', prevFile.name);
459
- dispatch('navigate', prevFile);
460
- }
439
+ const prevFile = findNextAvailableFile('prev');
440
+ if (prevFile) dispatch('navigate', prevFile);
461
441
  } else if (keyAction === 'next') {
462
442
  event.preventDefault();
463
- // console.log('Right arrow pressed, current index:', currentIndex);
464
- const nextFile = findNextAvailableFile(currentIndex, 'next');
465
- if (nextFile) {
466
- // console.log('Navigating to next file:', nextFile.name);
467
- dispatch('navigate', nextFile);
468
- }
443
+ const nextFile = findNextAvailableFile('next');
444
+ if (nextFile) dispatch('navigate', nextFile);
469
445
  }
470
446
  }
471
447
 
@@ -654,8 +630,8 @@
654
630
  !pdfLoadError &&
655
631
  !(fileType === 'image' && imageRevealForId !== file.id);
656
632
 
657
- $: canGoPrevious = showNavigation && findNextAvailableFile(currentIndex, 'prev') !== null;
658
- $: canGoNext = showNavigation && findNextAvailableFile(currentIndex, 'next') !== null;
633
+ $: canGoPrevious = showNavigation && findNextAvailableFile('prev') !== null;
634
+ $: canGoNext = showNavigation && findNextAvailableFile('next') !== null;
659
635
 
660
636
  // The spinner: only for a picture that is STILL loading after `IMAGE_SLOW_LOADER_DELAY_MS` (the timer of the file that is
661
637
  // open sets `slowLoaderForId`), never for one that was cached or arrived sooner, and never over an error card.
@@ -666,12 +642,12 @@
666
642
  !showsErrorState;
667
643
 
668
644
  function goPreviousFile() {
669
- const prevFile = findNextAvailableFile(currentIndex, 'prev');
645
+ const prevFile = findNextAvailableFile('prev');
670
646
  if (prevFile) dispatch('navigate', prevFile);
671
647
  }
672
648
 
673
649
  function goNextFile() {
674
- const nextFile = findNextAvailableFile(currentIndex, 'next');
650
+ const nextFile = findNextAvailableFile('next');
675
651
  if (nextFile) dispatch('navigate', nextFile);
676
652
  }
677
653
 
@@ -39,7 +39,7 @@
39
39
  {/if}
40
40
  </div>
41
41
 
42
- {#if allowSelecting && (showNavigation || showSelectInPreview)}
42
+ {#if showNavigation || (allowSelecting && showSelectInPreview)}
43
43
  <div class="flex shrink-0 items-center gap-1">
44
44
  {#if showNavigation}
45
45
  <IconButton
@@ -183,7 +183,8 @@ export declare const FILE_BROWSER_MESSAGES: {
183
183
  /** What a screen reader says for the X that closes a window. */
184
184
  readonly 'dialog.close': "Close modal";
185
185
  readonly 'toast.rename.started': "Renaming \"{name}\"…";
186
- readonly 'toast.rename.done': "Item renamed";
186
+ readonly 'toast.rename.done': "File renamed";
187
+ readonly 'toast.rename.folderDone': "Folder renamed";
187
188
  readonly 'toast.rename.doneDetail': "Successfully renamed \"{oldName}\" to \"{newName}\"";
188
189
  readonly 'toast.rename.failed': "Rename failed";
189
190
  readonly 'toast.rename.noChange': "No changes were made";
@@ -192,7 +192,8 @@ export const FILE_BROWSER_MESSAGES = {
192
192
  'dialog.close': 'Close modal',
193
193
  // ===== Messages that pop up after an action =====
194
194
  'toast.rename.started': 'Renaming "{name}"…',
195
- 'toast.rename.done': 'Item renamed',
195
+ 'toast.rename.done': 'File renamed',
196
+ 'toast.rename.folderDone': 'Folder renamed',
196
197
  'toast.rename.doneDetail': 'Successfully renamed "{oldName}" to "{newName}"',
197
198
  'toast.rename.failed': 'Rename failed',
198
199
  'toast.rename.noChange': 'No changes were made',
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUplo
5
5
  export * from './utils';
6
6
  export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
7
7
  export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
8
- export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
8
+ export { loadLibraryTreeChildren, removePersistedUploads, replacePersistedUploads, saveLibraryTreeChildren, saveUserUpload, loadUserUploads } from './utils/userUploadsStorage';
9
+ export { BRAND_KIT_FONTS_FOLDER, BRAND_KIT_LOGOS_FOLDER, BRAND_KIT_ROOT_NAME, brandLogoFolderPath, fontFamilyFolderPath, placeBrandKitFileInTree, removeBrandKitFileFromTree, resolveCollisionFileName, treeContainsUploadId } from './utils/brandKitLibraryTree';
9
10
  export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
10
11
  export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
11
12
  export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
package/dist/index.js CHANGED
@@ -9,7 +9,8 @@ export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUplo
9
9
  export * from './utils';
10
10
  export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
11
11
  export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
12
- export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
12
+ export { loadLibraryTreeChildren, removePersistedUploads, replacePersistedUploads, saveLibraryTreeChildren, saveUserUpload, loadUserUploads } from './utils/userUploadsStorage';
13
+ export { BRAND_KIT_FONTS_FOLDER, BRAND_KIT_LOGOS_FOLDER, BRAND_KIT_ROOT_NAME, brandLogoFolderPath, fontFamilyFolderPath, placeBrandKitFileInTree, removeBrandKitFileFromTree, resolveCollisionFileName, treeContainsUploadId } from './utils/brandKitLibraryTree';
13
14
  export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
14
15
  // Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
15
16
  // a page or a build step can run on its own messages.
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface FileSystemItem {
14
14
  matchingFileCount?: number;
15
15
  hash?: string;
16
16
  mimeType?: string;
17
+ /** Server-owned library folder path (`Brand kit/Fonts/Inter`). */
18
+ libraryFolderPath?: string;
17
19
  }
18
20
  export type FileSystemRoot = {
19
21
  basePath: string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Places brand-kit upload ids into the Widgetic library tree with stable folder names.
3
+ */
4
+ import type { FileSystemItem } from '../types';
5
+ export declare const BRAND_KIT_ROOT_NAME = "Brand kit";
6
+ export declare const BRAND_KIT_FONTS_FOLDER = "Fonts";
7
+ export declare const BRAND_KIT_LOGOS_FOLDER = "Logos";
8
+ /** `name (2).ext` when another file in the folder already uses `name.ext`. */
9
+ export declare function resolveCollisionFileName(desiredName: string, takenLower: Set<string>): string;
10
+ export declare function fontFamilyFolderPath(family: string): string[];
11
+ export declare function brandLogoFolderPath(): string[];
12
+ /**
13
+ * Moves or inserts a file into the tree under `folderPath`, setting `name` to `displayName` (collision suffix applied).
14
+ */
15
+ export declare function placeBrandKitFileInTree(rootChildren: FileSystemItem[] | null | undefined, input: {
16
+ uploadId: string;
17
+ displayName: string;
18
+ folderPath: string[];
19
+ file?: Partial<FileSystemItem>;
20
+ }): FileSystemItem[];
21
+ /** Removes a file id wherever it sits in the tree (optimistic delete). */
22
+ export declare function removeBrandKitFileFromTree(rootChildren: FileSystemItem[] | null, uploadId: string): FileSystemItem[];
23
+ export declare function treeContainsUploadId(rootChildren: FileSystemItem[] | null, uploadId: string): boolean;